Skip to content

refactor(daemon): inline the touch sub-switch into the interaction dispatcher - #2302

Merged
thymikee merged 6 commits into
mainfrom
claude/daemon-inline-touch-switch
Sep 5, 2026
Merged

refactor(daemon): inline the touch sub-switch into the interaction dispatcher#2302
thymikee merged 6 commits into
mainfrom
claude/daemon-inline-touch-switch

Conversation

@thymikee

@thymikee thymikee commented Sep 5, 2026

Copy link
Copy Markdown
Member

Summary

interaction-touch.ts was a 31-line pass-through: a second command-name switch that only
re-dispatched press/click/longpress/hover/fill to the same handlers
handleInteractionCommands already pulled in. Inlined those five cases into the existing
switch in src/daemon/interaction/internal/interaction.ts and deleted interaction-touch.ts.
No client-, operator-, or command-author-visible behavior change — this only removes one
indirection hop on the press/click/longpress/hover/fill dispatch path (−1 hop).

Review follow-ups landed in the same branch:

  • The ADR-0011 responseData guard scanned files by an interaction-touch*.ts name prefix,
    which stopped covering the switch once it moved into interaction.ts. The dispatcher is now
    held to a structural rule instead: the guard parses interaction.ts with oxc-parser and
    requires every press/click/longpress/hover/fill case to be exactly one
    return await <handler>(...) whose callee is imported from an interaction-touch*.ts module.
    Nothing can be constructed in the switch at all, so a nested switch, a local responseData,
    an inline literal or a foreign callee all fail. The guard's own tests plant each of those
    shapes in an inline dispatcher source and assert the exact violation.
  • docs/adr/0019-end-state-hop-trace.md traced both files this PR merges by name and pinned
    itself as unaffected by this PR. Merged the corresponding table rows, renumbered the
    remaining hops, and updated every downstream count/range reference in that doc and in
    docs/adr/0019-request-bound-platform-runtime.md.

Validation

Tested at de5036093f (structural guard), 0b982bfcc0 (oxfmt only) and 31af37752b (folds the delegation check under fallow's complexity threshold, then merges main for the #2310 size-report schema) on top of 292c0edb220e50f5f34f9436c777fafad631eba0.

  • npx vitest run src/daemon/interaction/internal/__tests__/ — 30 files, 197 passed
  • npx tsc -p tsconfig.json --noEmit — clean
  • npx oxlint on the changed test file — clean
  • Planted red (de5036093f): gave press a nested switch followed by a hand-rolled
    responseData in the real interaction.ts; the guard failed with
    case 'press': the case body is not exactly one return await (...)``, then passed clean after
    reverting. The same shape, an inline response literal, a non-touch callee and a removed
    command are pinned as permanent inline planted-red cases in the guard test (7 tests green).
  • Full affected gate: green at 292c0ed (check:affected; format, lint, typecheck, layering, fallow, build, vitest-related)

…spatcher

interaction-touch.ts was a 31-line pass-through re-switching on
press/click/longpress/hover/fill only to call the same five handlers
handleInteractionCommands already imports transitively. Inline the five
cases into the existing switch and delete the file, dropping one hop
from the press/click/longpress/hover/fill dispatch path.

Point the response-construction-guard sentinel at
interaction-touch-press.ts (a file that still exists) so it keeps
watching for a hand-rolled responseData branch across the touch
handler set.
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
Installed (including dependencies) 4.44 MB 4.44 MB -88 B
Package (unpacked) 4.44 MB 4.44 MB -88 B
Package (download) 1.32 MB 1.32 MB -13 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 26.7 ms 27.9 ms +1.2 ms
CLI --help 80.7 ms 82.2 ms +1.5 ms

PR review findings on #2302:

- The ADR-0011 responseData guard scanned files by an
  interaction-touch*.ts name prefix, which stopped covering the touch
  dispatch switch once it moved into interaction.ts. Added a targeted
  second check that extracts the press/click/longpress/hover/fill case
  bodies from interaction.ts and scans them for hand-rolled
  responseData, without widening the whole-file scan onto
  interaction.ts (which also hosts the unrelated `type` command's
  legitimate local responseData construction). Planted red: reverted
  one switch case to a hand-rolled responseData construction twice
  (press, then click) and reran
  `npx vitest run src/daemon/interaction/internal/__tests__/interaction-response-construction-guard.test.ts`;
  both times the new test failed with the expected
  "Hand-rolled interaction responseData found in the touch dispatch
  switch" message, then passed clean again after reverting.

- docs/adr/0019-end-state-hop-trace.md pinned itself to a commit and
  claimed the press/Android route was untouched by this PR, but the
  PR's whole point is merging two of that table's traced files
  (interaction.ts, interaction-touch.ts). Merged the corresponding
  table rows, renumbered the remaining hops, updated the file/class
  summary counts and every downstream hop-range reference in the same
  doc, and did the same for the one line in
  docs/adr/0019-request-bound-platform-runtime.md that also cited the
  now-stale 24-hop figure.
@thymikee

thymikee commented Sep 5, 2026

Copy link
Copy Markdown
Member Author

Sentinel review at 292c0ed.

P2: the new case-body regex stops at the first nested case/default, so a hand-rolled responseData after a nested switch in press is invisible to the construction guard; the previous whole-file scan caught it. The delegation move itself is behavior-preserving, but the filename exception plus copied command list weakens the invariant. Keep construction enforcement at the owning typed/delegation boundary or reuse structural parsing instead of formatting-sensitive case extraction. Plant a nested switch followed by hand-rolled responseData and prove the gate rejects it before restoring. Hold readiness until this is resolved.

The ADR-0011 guard extracted each touch case body with a regex that stopped
at the first nested case/default, so a hand-rolled responseData placed after
a nested switch was invisible. Parse interaction.ts with oxc-parser instead
and require every press/click/longpress/hover/fill case to be exactly one
return await <handler>(...) where the handler is imported from an
interaction-touch*.ts module. Inline planted-red cases cover the nested-switch
shape, an inline literal, a foreign callee, and a missing command.
@thymikee

thymikee commented Sep 5, 2026

Copy link
Copy Markdown
Member Author

Addressed in de50360. The case-body regex is gone; the guard now parses interaction.ts with oxc-parser and requires each touch case to be exactly one return await <handler>(...) whose callee is imported from an interaction-touch*.ts module, so construction enforcement stays at the delegation boundary and nothing formatting-sensitive remains. Planted the nested-switch-then-hand-rolled-responseData shape in the real press case: the guard rejected it (case 'press': the case body is not exactly one return statement); reverted. That shape plus an inline literal, a foreign callee and a missing command are pinned as inline planted-red cases in the test itself.

* origin/main:
  perf: bundle runtime dependencies and report full install size (#2310)
  ci: avoid unrelated Apple runner cache invalidation (#2303)
  fix(web): preserve the backend ref so snapshot refs match actionable refs (#2283)
  test(daemon): session-open-url-prewarm through the request seam (#2304)
  test(daemon): session-devices-batch-runtime through the request seam (#2305)
  chore(gates): layering baselines ratchet against merge-base (#2299)
  test(daemon): one typed conformance helper for the daemon runtime suites (#2298)
  chore(layering): derive the contracts export inventory from package.json (#2297)
  perf: bundle tar-stream to reduce install footprint (#2286)
@thymikee

thymikee commented Sep 5, 2026

Copy link
Copy Markdown
Member Author

Sentinel review at 0b982bf: The nested-switch enforcement hole is fixed by the AST delegation check, independently reviewed. One actionable gate failure remains: delegationOf at interaction-response-construction-guard.test.ts:105 is 11 cyclomatic / 9 cognitive and fails Fallow in Compatibility & Provenance (job101366047914). Simplify/split the owning AST shape checks without raising the baseline, retain the planted negatives, and rerun the gate. Size also fails from incompatible base-report js.rawBytes; device CI must clear separately. No readiness label.

@thymikee
thymikee merged commit f1d4efe into main Sep 5, 2026
18 checks passed
@thymikee
thymikee deleted the claude/daemon-inline-touch-switch branch September 5, 2026 20:41
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-09-05 20:41 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant