Skip to content

refactor(daemon): establish the interaction application facade #2177

Description

@thymikee

Parent: #2132

Blocked by: #2166 (merged). This interaction slice is file-disjoint from the lifecycle chain and may run in parallel with its first child, but only one full host gate at a time.

Outcome

Establish one interaction application facade and move the shared execution/finalization boundary out of handlers before moving leaf command implementations. This child must shrink broad SessionState/SessionStore authority; a directory-only move is insufficient.

Exact production scope

Move/refactor these shared modules under src/daemon/interaction/internal/:

  • src/daemon/handlers/interaction-common.ts
  • src/daemon/handlers/interaction-runtime.ts
  • src/daemon/handlers/interaction-snapshot.ts
  • src/daemon/handlers/interaction-flags.ts
  • src/daemon/handlers/interaction-read.ts
  • src/daemon/handlers/interaction-ref-policy.ts
  • src/daemon/handlers/interaction-recorded-input.ts
  • src/daemon/handlers/interaction-ambiguity-publication.ts

Add src/daemon/interaction/index.ts as the only external facade. Its initial exports are the named interaction route input plus the exact shared operations genuinely consumed by src/daemon/generic-settle.ts, src/daemon/selector-runtime.ts, and src/daemon/selector-runtime-backend.ts. Update those three consumers to the facade; none may deep-import internals.

Keep src/daemon/handlers/interaction.ts and leaf interaction-touch-* / interaction-gesture.ts route code in place for this child, consuming the facade. Do not move find yet.

Authority contract

Replace broad shared finalization inputs with named operations around existing owners: action recording, snapshot publication, ref-frame expiry, deferred-outcome marking, script-recording query, and gesture visualization. Foreign writes remain in session-snapshot.ts, ref-frame.ts, interaction-outcome-policy.ts, deferred-interaction-outcome.ts, and script-publication owners.

The retained read surface must be explicit and no broader than current behavior: device, surface, appBundleId, trace, snapshot, snapshotGeneration, lease, and screenRecording where genuinely required. No anonymous Pick<SessionState>, copied record, or broad store capability.

Behavior and structural proof

Move the one-to-one shared tests, including interaction-common, flags, ref-policy, ambiguity publication, snapshot-scope/target-evidence, response-construction guard, and settle tests. Characterize action/result recording, parameterized fill, target evidence, deferred retry marking, snapshot replacement, settle flag errors, and selector-runtime read behavior before movement.

Plant: handler deep-import of interaction/internal, internal import of handlers, a non-owner write to each deferred outcome field, and a direct deep import from each of the three external consumers. Observe the named red failures before final green.

Shrink and validation

The deletion argument is removal of repeated broad context/store threading across touch, gesture, type, settle, and selector reads. Report gross and move-adjusted production LOC; stop if production grows after discounting moves. Run focused interaction/deferred tests, R7/session-state tests, layering/fallow checks, and pnpm check:affected --run after staging.

Preserve ADR 0011/0012/0014/0019 semantics, lazy route loading, typed errors, wire response construction, and recording behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions