Skip to content

refactor: extract daemon selector capture runtime#859

Merged
thymikee merged 1 commit into
mainfrom
refactor/daemon-selector-capture-runtime
Jun 24, 2026
Merged

refactor: extract daemon selector capture runtime#859
thymikee merged 1 commit into
mainfrom
refactor/daemon-selector-capture-runtime

Conversation

@thymikee

@thymikee thymikee commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

Rebased onto latest main after selector capture policy landed there. This PR now extracts daemon selector runtime backend construction into src/daemon/selector-runtime-backend.ts while leaving dispatch, direct iOS selector fast paths, response shaping, and recording/result handling in selector-runtime.ts.

Before/after LOC: selector-runtime.ts 788 -> 536; selector-runtime-backend.ts 0 -> 252. Files touched: 2.

Scope checks: PR diff is only src/daemon/selector-runtime.ts and src/daemon/selector-runtime-backend.ts; no src/commands/interaction/runtime/* changes; no src/compat/maestro/* changes; Maestro target/ranking/visibility logic untouched. The latest main src/daemon/selector-capture-runtime.ts is preserved and reused by the backend.

Validation

Focused guard suite passed: ./node_modules/.bin/vitest run src/daemon/handlers/tests/find.test.ts src/daemon/handlers/tests/snapshot-handler.test.ts src/daemon/handlers/tests/snapshot-scoped-refs.test.ts src/daemon/handlers/tests/interaction.test.ts src/compat/maestro/tests/runtime-interactions.test.ts src/compat/maestro/tests/runtime-targets.test.ts (6 files, 167 tests).

Fallow passed locally after rebasing: ./node_modules/.bin/fallow audit --base origin/main.

Static checks passed directly: ./node_modules/.bin/oxlint . --deny-warnings and ./node_modules/.bin/tsc -p tsconfig.json.

Format passed via the repo formatter binary: ./node_modules/.bin/oxfmt --write src/daemon/selector-runtime.ts src/daemon/selector-runtime-backend.ts.

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 1.3 MB 1.3 MB +303 B
JS gzip 430.2 kB 430.3 kB +105 B
npm tarball 566.4 kB 566.5 kB +111 B
npm unpacked 1.9 MB 1.9 MB +303 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 25.6 ms 25.9 ms +0.3 ms
CLI --help 45.1 ms 46.0 ms +1.0 ms

Top changed chunks:

Chunk Raw diff Gzip diff
dist/src/selector-runtime.js +303 B +105 B

@thymikee

Copy link
Copy Markdown
Member Author

Critical review blockers before merge:

  1. The PR diff includes .worktreeinclude, which is unrelated to the daemon selector capture extraction. Please remove it from the branch so the PR scope is limited to the selector runtime extraction files.

  2. CI is failing Fallow Code Quality. The job reports src/daemon/selector-capture-runtime.ts:190 findText HIGH with cyclomatic 16 / CRAP 71.3. Please split findText into smaller private helpers while preserving the current ordering and behavior: macOS non-app surface snapshot lookup, Apple runner findText, then snapshot fallback.

The extraction direction is good, but these are scope/quality blockers.

@thymikee

Copy link
Copy Markdown
Member Author

CI is blocked on Fallow Code Quality. The failing finding is src/daemon/selector-capture-runtime.ts:190 findText HIGH with cyclomatic 16 / CRAP 71.3.

The rest of the checks are green. Please address the Fallow finding before re-review; I am holding off on reviewer scheduling while the required check is red.

@thymikee thymikee force-pushed the refactor/daemon-selector-capture-runtime branch from 41e19d9 to 4f4af6d Compare June 24, 2026 15:10
@thymikee

Copy link
Copy Markdown
Member Author

Heads-up on overlap with #857: both PRs add a new file at the same path src/daemon/selector-capture-runtime.ts but with different contents and exports — this PR exports createSelectorRuntimeForDevice / createSelectorRuntime / SelectorRuntimeParams (a wholesale move of the runtime+backend), while #857 exports createSelectorCaptureRuntime (a shared capture/cache policy). Both branch independently off main, so whichever lands second hits an add/add conflict on the new file plus overlapping edits in selector-runtime.ts. They're also different end-states: this PR is a low-risk structural extraction that leaves the cache/recovery/session-write logic duplicated between find.ts and the selector backend; #857 unifies that policy and shares it with find.ts (removes the duplication) at the cost of touching behavior-sensitive code. Recommend deciding direction before merging either — e.g. land this mechanical extraction first, then redo #857's unification on top (it'd shrink), or pick #857 for the dedup and close this.

Review notes on this PR in isolation:

  • The findText decomposition (2nd commit) is behavior-preserving: branch precedence (macos-non-app → Apple runner → wait-snapshot) is intact, and the !== null sentinel correctly distinguishes "branch handled, returned false" from "branch not applicable".
  • The rest is a verbatim move; caching/session-write semantics unchanged. No circular import (new file doesn't import selector-runtime.ts); all re-imports are used.
  • Minor: the filename says "capture-runtime" but the module now owns the whole selector runtime (backend incl. findText/readText), not just snapshot capture — consider selector-runtime-backend or similar.

@thymikee thymikee force-pushed the refactor/daemon-selector-capture-runtime branch from 46523a1 to 10eec69 Compare June 24, 2026 15:37
@thymikee thymikee merged commit c9748a9 into main Jun 24, 2026
20 checks passed
@thymikee thymikee deleted the refactor/daemon-selector-capture-runtime branch June 24, 2026 15:53
@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-06-24 15:54 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