Tracked by #713.
Background
src/tools/native-input-backend.ts combines multiple concrete backends, routing policy, process-wide caches, Flutter resolver logic, and test reset hooks. This makes headless input behavior harder to change safely.
Objective
Separate native input backend implementations and routing policy into focused modules with explicit dependencies.
Scope
- Create shared backend interfaces.
- Move each concrete backend to its own module.
- Move resolver/caching logic into an injectable resolver class.
- Keep existing exported helper API during migration.
Target files and paths
src/tools/native-input-backend.ts
- new
src/input/backend.ts
- new
src/input/simctl-backend.ts
- new
src/input/applescript-backend.ts
- new
src/input/webkit-backend.ts
- new
src/input/flutter-resolver.ts
- new
src/input/backend-resolver.ts
tests/unit/native-input-backend.test.ts
Implementation steps
- Define
InputBackend and backend kind types.
- Move Simctl backend without changing behavior.
- Move AppleScript backend and keep opt-in guard.
- Move WebKit backend and shared DOM input scripts if available.
- Move resolver state from module globals into an instance.
- Keep compatibility exports and migrate callers gradually.
Acceptance criteria
Verification
npm run lint -- --quiet
npm test -- --runInBand tests/unit/native-input-backend.test.ts
- Manual smoke for at least one WebKit input and one native-app input path.
Dependencies / recommended order
Run after process-spawn optimization or as preparation for it. Split by backend if review size grows.
Risks and cautions
- Do not promote experimental backends.
- Do not change fallback semantics while moving files.
- Avoid changing public tool behavior in refactor PRs.
Non-goals
- Do not solve SimulatorKit research issues.
- Do not remove AppleScript fallback.
- Do not redesign app interaction tool schemas.
Ambiguity reducers
- “Concrete backend” means a class that sends input through one mechanism.
- “Resolver” means policy that chooses a backend for a requested operation and context.
- Module globals should be replaced only where an equivalent instance-owned state is available.
Validity review
Proceed as a P2 maintainability item. It is valid because native input is a strategic product surface.
Implementation detail refinements
- Keep compatibility exports until all callers migrate.
- Use one PR per backend extraction if necessary.
- Document fallback order in tests rather than relying on comments only.
Verification checklist reinforcement
Tracked by #713.
Background
src/tools/native-input-backend.tscombines multiple concrete backends, routing policy, process-wide caches, Flutter resolver logic, and test reset hooks. This makes headless input behavior harder to change safely.Objective
Separate native input backend implementations and routing policy into focused modules with explicit dependencies.
Scope
Target files and paths
src/tools/native-input-backend.tssrc/input/backend.tssrc/input/simctl-backend.tssrc/input/applescript-backend.tssrc/input/webkit-backend.tssrc/input/flutter-resolver.tssrc/input/backend-resolver.tstests/unit/native-input-backend.test.tsImplementation steps
InputBackendand backend kind types.Acceptance criteria
Verification
npm run lint -- --quietnpm test -- --runInBand tests/unit/native-input-backend.test.tsDependencies / recommended order
Run after process-spawn optimization or as preparation for it. Split by backend if review size grows.
Risks and cautions
Non-goals
Ambiguity reducers
Validity review
Proceed as a P2 maintainability item. It is valid because native input is a strategic product surface.
Implementation detail refinements
Verification checklist reinforcement