Skip to content

Commit bb23711

Browse files
authored
docs: simplify and reconcile AGENTS guide (#35)
1 parent 8e88eb5 commit bb23711

1 file changed

Lines changed: 56 additions & 82 deletions

File tree

AGENTS.md

Lines changed: 56 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,63 @@
22

33
Minimal operating guide for AI coding agents in this repo.
44

5-
## Objective
6-
5+
## Before Implementing
6+
- State assumptions explicitly. If uncertain, ask.
7+
- If multiple interpretations exist, present them - don't pick silently.
8+
- If a simpler approach exists, say so. Push back when warranted.
9+
10+
## Code Changes
11+
- Minimum code that solves the problem. No speculative features.
12+
- No abstractions for single-use code.
13+
- Surgical edits: touch only what the task requires.
14+
- Match existing style, even if you'd do it differently.
15+
- Remove imports/variables YOUR changes made unused; don't touch pre-existing dead code.
16+
17+
## Verification
18+
- Transform tasks into verifiable goals with clear success criteria.
19+
- For multi-step tasks, state a brief plan with verification checkpoints.
20+
21+
## Scope
722
- Solve issues with the smallest context read.
8-
- Keep changes scoped to one module family.
23+
- Keep changes scoped to one command family or module group.
924
- Preserve daemon session semantics and platform behavior.
25+
- Read at most 3 files first:
26+
- the owning handler/module
27+
- one shared helper used by that handler
28+
- one downstream platform file if needed
29+
- Expand only when contracts cross module boundaries.
30+
- Do not read both iOS and Android paths unless the issue is explicitly cross-platform.
31+
32+
## Routing
33+
- Keep `src/daemon.ts` as a thin router.
34+
- Put command logic in handler modules:
35+
- session/apps/appstate/open/close/replay: `src/daemon/handlers/session.ts`
36+
- click/fill/get/is: `src/daemon/handlers/interaction.ts`
37+
- snapshot/wait/alert/settings: `src/daemon/handlers/snapshot.ts`
38+
- find: `src/daemon/handlers/find.ts`
39+
- record/trace: `src/daemon/handlers/record-trace.ts`
40+
- Generic passthrough (press/scroll/type) is daemon fallback only after handlers return null.
1041

1142
## Hard Rules
1243

1344
- Use `runCmd`/`runCmdSync` from `src/utils/exec.ts` for process execution.
1445
- Use daemon session flow for interactions (`open` before interactions, `close` after).
1546
- Do not remove shared snapshot/session model behavior without full migration.
1647
- If Swift runner code changes, run `pnpm build:xcuitest`.
17-
- Do not add command logic to `daemon.ts` — it is a thin router. Use handler modules.
1848
- Use `inferFillText` and `uniqueStrings` from `src/daemon/action-utils.ts`. Do not duplicate.
1949
- Use `evaluateIsPredicate` from `src/daemon/is-predicates.ts` for assertion logic. Do not inline.
2050

21-
## Architecture In One Screen
22-
23-
1. CLI parse + formatting:
24-
- `src/bin.ts`
25-
- `src/cli.ts`
26-
- `src/utils/args.ts`
27-
2. Daemon client transport:
28-
- `src/daemon-client.ts`
29-
3. Daemon server bootstrap/router:
30-
- `src/daemon.ts` — thin router only, delegates to handler modules
31-
4. Daemon command families:
32-
- session/apps/appstate/open/close/replay: `src/daemon/handlers/session.ts`
33-
- click/fill/get/is: `src/daemon/handlers/interaction.ts`
34-
- snapshot/wait/alert/settings: `src/daemon/handlers/snapshot.ts`
35-
- semantic find actions: `src/daemon/handlers/find.ts`
36-
- record/trace: `src/daemon/handlers/record-trace.ts`
37-
5. Daemon shared domain:
38-
- session state + logs: `src/daemon/session-store.ts`
39-
- selector DSL (parse, resolve, build): `src/daemon/selectors.ts`
40-
- `is` predicate evaluation: `src/daemon/is-predicates.ts`
41-
- shared action helpers (inferFillText, uniqueStrings): `src/daemon/action-utils.ts`
42-
- snapshot tree shaping + label resolution: `src/daemon/snapshot-processing.ts`
43-
- handler context helpers: `src/daemon/context.ts`, `src/daemon/device-ready.ts`, `src/daemon/app-state.ts`
44-
6. Platform dispatch/backends:
45-
- dispatcher: `src/core/dispatch.ts`
46-
- capabilities: `src/core/capabilities.ts`
47-
- iOS: `src/platforms/ios/*`, `ios-runner/*`
48-
- Android: `src/platforms/android/*`
49-
50-
## First-Read Protocol (Strict)
51-
52-
1. Identify command family from failing behavior.
53-
2. Read at most 3 files first:
54-
- the owning handler/module
55-
- one shared helper used by that handler
56-
- one downstream platform file if needed
57-
3. Expand only when contract crosses module boundaries.
58-
59-
Do not read both iOS and Android paths unless issue is explicitly cross-platform.
60-
61-
## Command Family Ownership
62-
63-
- `session list`, `devices`, `apps`, `appstate`, `open`, `close`, `replay`:
64-
- `src/daemon/handlers/session.ts`
65-
- `click`, `fill`, `get`, `is`:
66-
- `src/daemon/handlers/interaction.ts`
67-
- `snapshot`, `wait`, `alert`, `settings`:
68-
- `src/daemon/handlers/snapshot.ts`
69-
- `find ...`:
70-
- `src/daemon/handlers/find.ts`
71-
- `record start|stop`, `trace start|stop`:
72-
- `src/daemon/handlers/record-trace.ts`
73-
- Generic passthrough (press, scroll, type, etc.):
74-
- `src/daemon.ts` (fallback after all handlers return null)
51+
## Key Files
52+
- CLI parse + formatting: `src/bin.ts`, `src/cli.ts`, `src/utils/args.ts`
53+
- Daemon client transport: `src/daemon-client.ts`
54+
- Daemon state/store: `src/daemon/session-store.ts`
55+
- Selector DSL and matching: `src/daemon/selectors.ts`
56+
- `is` predicate evaluation: `src/daemon/is-predicates.ts`
57+
- Shared action helpers: `src/daemon/action-utils.ts`
58+
- Snapshot shaping + labels: `src/daemon/snapshot-processing.ts`
59+
- Handler context helpers: `src/daemon/context.ts`, `src/daemon/device-ready.ts`, `src/daemon/app-state.ts`
60+
- Dispatcher and capability source of truth: `src/core/dispatch.ts`, `src/core/capabilities.ts`
61+
- Platform backends: `src/platforms/ios/*`, `ios-runner/*`, `src/platforms/android/*`
7562

7663
## Capability Source Of Truth
7764

@@ -80,29 +67,20 @@ Do not read both iOS and Android paths unless issue is explicitly cross-platform
8067

8168
## Selector System Rules
8269

83-
All interaction commands (`click`, `fill`, `get`, `is`) and `wait` accept selectors in addition to `@ref`.
84-
The selector pipeline is: **parse → resolve → act → record selectorChain → heal on replay**.
85-
86-
- Selector DSL lives in `src/daemon/selectors.ts`. Do not duplicate parsing/matching logic elsewhere.
87-
- `buildSelectorChainForNode` generates fallback chains stored in action results. Always call it after resolving a node for an interaction — it powers replay healing.
88-
- When adding a new interaction command that targets a UI element: support both `@ref` and selector input, record `selectorChain`, and update replay healing (`healReplayAction` + `collectReplaySelectorCandidates` in `session.ts`).
89-
- When adding a new selector key: update `SelectorKey` type, `ALL_KEYS`/`TEXT_KEYS`/`BOOLEAN_KEYS` sets, `matchesTerm`, and `isSelectorToken` — all in `selectors.ts`.
90-
- When adding a new `is` predicate: update `IsPredicate` type and `evaluateIsPredicate` in `is-predicates.ts`, not in the handler.
91-
- `daemon.ts` must stay a thin router. Do not add command logic there — use the appropriate handler module.
92-
93-
## Testing Strategy
94-
95-
### Test placement policy
70+
- Interaction commands (`click`, `fill`, `get`, `is`) and `wait` accept selectors and `@ref`.
71+
- Pipeline is: **parse -> resolve -> act -> record selectorChain -> heal on replay**.
72+
- Keep selector parsing/matching in `src/daemon/selectors.ts`.
73+
- Call `buildSelectorChainForNode` after resolving an interaction target.
74+
- New element-targeting interactions must support selector input and `@ref`, record `selectorChain`, and hook replay healing (`healReplayAction` + `collectReplaySelectorCandidates` in `session.ts`).
75+
- New selector key updates stay centralized in `selectors.ts` (`SelectorKey`, key sets, matcher, token checks).
76+
- New `is` predicates belong in `evaluateIsPredicate` (`src/daemon/is-predicates.ts`), not handler code.
9677

78+
## Testing
9779
- Unit tests are colocated with source files under `src/**`.
9880
- Use `__tests__` folders colocated with the related source folder.
9981
- The `test/**` tree is integration-only (including smoke integration tests).
10082
- Example: tests for `src/daemon/selectors.ts` go in `src/daemon/__tests__/selectors.test.ts`.
101-
102-
Add/extend colocated unit tests in the same PR for touched module logic.
103-
104-
### Verification matrix
105-
83+
- Add/extend colocated unit tests in the same PR for touched module logic.
10684
- Any TS change:
10785
- `pnpm typecheck`
10886
- Daemon handler/shared module change:
@@ -114,13 +92,9 @@ Add/extend colocated unit tests in the same PR for touched module logic.
11492
Run integration tests when behavior crosses platform boundaries:
11593
- `pnpm test:integration`
11694

117-
## Productivity Measurement
118-
95+
## Measurement
11996
- Use `docs/daemon-refactor-impact.md`.
120-
- Track:
121-
- files touched per fix
122-
- cycle time
123-
- iOS/Android regressions
97+
- Track files touched per fix, cycle time, and iOS/Android regressions.
12498

12599
## Local Commands
126100

0 commit comments

Comments
 (0)