Skip to content

Commit 837d94f

Browse files
committed
chore: streamline AGENTS onboarding and testing matrix
1 parent e638e0a commit 837d94f

1 file changed

Lines changed: 92 additions & 84 deletions

File tree

AGENTS.md

Lines changed: 92 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,32 @@
22

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

5-
## Before Implementing
5+
## First 60 Seconds
6+
- Classify task type:
7+
- Info-only (triage/review/questions/docs guidance): no code edits and no test runs unless explicitly requested.
8+
- Code change: make minimal scoped edits and run only required checks from **Testing Matrix**.
69
- 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-
## Docs & Skills
22-
- For every behavior or CLI surface change, evaluate whether docs/skills updates are required.
23-
- Update `README.md` and relevant `website/docs/**` pages when command behavior, flags, aliases, or workflows change.
24-
- Update relevant `skills/**/SKILL.md` guidance when usage examples or workflow recommendations change.
25-
- In final summaries, explicitly state whether docs/skills were updated; if not, state why no updates were needed.
10+
- Read at most 3 files first:
11+
- owning handler/module
12+
- one shared helper used by that handler
13+
- one downstream platform file if needed
14+
- Define verifiable success criteria before editing.
15+
- Decide docs/skills impact up front.
2616

2717
## Scope
2818
- Solve issues with the smallest context read.
2919
- Keep changes scoped to one command family or module group.
3020
- Preserve daemon session semantics and platform behavior.
31-
- Read at most 3 files first:
32-
- the owning handler/module
33-
- one shared helper used by that handler
34-
- one downstream platform file if needed
3521
- Expand only when contracts cross module boundaries.
36-
- Do not read both iOS and Android paths unless the issue is explicitly cross-platform.
22+
- Do not read both iOS and Android paths unless explicitly cross-platform.
23+
- If requested fix expands beyond one command family/module group, stop and confirm before broadening scope.
24+
25+
## Code Changes
26+
- Minimum code that solves the problem. No speculative features.
27+
- No abstractions for single-use code.
28+
- Surgical edits only.
29+
- Match existing style.
30+
- Remove imports/variables YOUR changes made unused; do not clean unrelated dead code.
3731

3832
## Routing
3933
- Keep `src/daemon.ts` as a thin router.
@@ -45,28 +39,78 @@ Minimal operating guide for AI coding agents in this repo.
4539
- record/trace: `src/daemon/handlers/record-trace.ts`
4640
- Generic passthrough (press/scroll/type) is daemon fallback only after handlers return null.
4741

48-
## Hard Rules
42+
## Command Family Lookup
43+
- `logs`: `src/daemon/handlers/session.ts` -> `src/daemon/app-log.ts` -> `src/daemon/handlers/__tests__/session.test.ts`
44+
- `open/close/replay/apps/appstate`: `src/daemon/handlers/session.ts` -> `src/daemon/session-store.ts` -> `src/daemon/handlers/__tests__/session.test.ts`
45+
- `click/fill/get/is`: `src/daemon/handlers/interaction.ts` -> `src/daemon/selectors.ts` -> `src/daemon/handlers/__tests__/interaction.test.ts`
46+
- `snapshot/wait/settings/alert`: `src/daemon/handlers/snapshot.ts` -> `src/daemon/snapshot-processing.ts` -> `src/daemon/handlers/__tests__/snapshot-handler.test.ts`
47+
- `record/trace`: `src/daemon/handlers/record-trace.ts` -> `src/platforms/ios/runner-client.ts` -> `src/daemon/handlers/__tests__/record-trace.test.ts`
4948

49+
## Hard Rules
5050
- Use `runCmd`/`runCmdSync` from `src/utils/exec.ts` for process execution.
5151
- Use daemon session flow for interactions (`open` before interactions, `close` after).
5252
- Do not remove shared snapshot/session model behavior without full migration.
53+
- Command/device support must come from `src/core/capabilities.ts`.
5354
- If Swift runner code changes, run `pnpm build:xcuitest`.
54-
- Use `inferFillText` and `uniqueStrings` from `src/daemon/action-utils.ts`. Do not duplicate.
55-
- Use `evaluateIsPredicate` from `src/daemon/is-predicates.ts` for assertion logic. Do not inline.
55+
- Use `inferFillText` and `uniqueStrings` from `src/daemon/action-utils.ts`.
56+
- Use `evaluateIsPredicate` from `src/daemon/is-predicates.ts` for assertion logic.
57+
58+
## Logs Contract
59+
- Logs backend/source of truth is `src/daemon/app-log.ts`.
60+
- `session.ts` should orchestrate only (start/stop/path/doctor/mark), not duplicate backend logic.
61+
- Preserve external grep/tail workflow in docs/skills.
5662

5763
## Diagnostics & Errors
64+
- Diagnostics source of truth: `src/utils/diagnostics.ts`
65+
- `withDiagnosticsScope`, `emitDiagnostic`, `withDiagnosticTimer`, `flushDiagnosticsToSessionFile`
66+
- Do not add ad-hoc stderr/file logging where diagnostics helpers apply.
67+
- Normalize user-facing failures via `src/utils/errors.ts` (`normalizeError`).
68+
- Failure payload contract: `code`, `message`, `hint`, `diagnosticId`, `logPath`, `details`.
69+
- Preserve `hint`, `diagnosticId`, `logPath` when wrapping/rethrowing errors.
70+
- `--debug` is canonical; `--verbose` is backward-compatible alias.
71+
- Keep redaction centralized in diagnostics helpers.
72+
73+
## Selector System Rules
74+
- Interaction commands (`click`, `fill`, `get`, `is`) and `wait` accept selectors and `@ref`.
75+
- Pipeline: **parse -> resolve -> act -> record selectorChain -> heal on replay**.
76+
- Keep selector parsing/matching in `src/daemon/selectors.ts`.
77+
- Call `buildSelectorChainForNode` after resolving target nodes.
78+
- New element-targeting interactions must support selector + `@ref`, record `selectorChain`, and hook replay healing (`healReplayAction` + `collectReplaySelectorCandidates` in `session.ts`).
79+
- New selector keys remain centralized in `selectors.ts`.
80+
- New `is` predicates belong in `evaluateIsPredicate`.
81+
82+
## Testing Matrix
83+
- Docs/skills only: no tests required.
84+
- Non-TS, no behavior impact: no tests unless requested.
85+
- Any TS change: `pnpm typecheck`.
86+
- Daemon handler/shared module change: `pnpm test:unit` and `pnpm test:smoke`.
87+
- iOS runner/Swift change: `pnpm build:xcuitest`.
88+
- Cross-platform behavior change: run `pnpm test:integration`.
89+
90+
## Token Guardrails
91+
- Do not read unrelated files once owning module is identified.
92+
- Do not run integration tests by default.
93+
- Do not inspect both iOS and Android codepaths unless task requires both.
94+
- Keep PR summaries short and scoped.
95+
96+
## Common Mistakes
97+
- Adding command logic to `src/daemon.ts` instead of handlers.
98+
- Adding capability checks outside `src/core/capabilities.ts`.
99+
- Inlining `is` predicate logic in handlers.
100+
- Returning non-normalized user-facing errors.
101+
- Duplicating logs backend logic in handlers instead of `src/daemon/app-log.ts`.
102+
103+
## Docs & Skills
104+
- For behavior/CLI surface changes, evaluate docs/skills updates.
105+
- Update `README.md` and relevant `website/docs/**` pages for command behavior/flags/aliases/workflows.
106+
- Update relevant `skills/**/SKILL.md` when usage examples/workflow recommendations change.
107+
- In final summaries, state whether docs/skills were updated; if not, explain why.
58108

59-
- Use `src/utils/diagnostics.ts` as the diagnostics source of truth:
60-
- `withDiagnosticsScope`
61-
- `emitDiagnostic`
62-
- `withDiagnosticTimer`
63-
- `flushDiagnosticsToSessionFile`
64-
- Do not add ad-hoc stderr/file logging in handlers/platform modules when diagnostics helpers can be used.
65-
- Normalize user-facing failures through `src/utils/errors.ts` (`normalizeError`).
66-
- Failure payload contract should include: `code`, `message`, `hint`, `diagnosticId`, `logPath`, `details`.
67-
- When wrapping/rethrowing daemon errors (batch/replay/handler wrappers), preserve `hint`, `diagnosticId`, and `logPath` from inner errors.
68-
- `--debug` is canonical; `--verbose` remains backward-compatible alias.
69-
- Keep redaction centralized in `src/utils/diagnostics.ts`; do not duplicate redaction logic in handlers/CLI.
109+
## When Blocked
110+
- If blocked by network/device/auth/permissions, stop and report:
111+
- blocker
112+
- why it blocks completion
113+
- exact next command/action needed to unblock
70114

71115
## Key Files
72116
- CLI parse + formatting: `src/bin.ts`, `src/cli.ts`, `src/utils/args.ts`
@@ -77,53 +121,17 @@ Minimal operating guide for AI coding agents in this repo.
77121
- Shared action helpers: `src/daemon/action-utils.ts`
78122
- Snapshot shaping + labels: `src/daemon/snapshot-processing.ts`
79123
- Handler context helpers: `src/daemon/context.ts`, `src/daemon/device-ready.ts`
80-
- Dispatcher and capability source of truth: `src/core/dispatch.ts`, `src/core/capabilities.ts`
124+
- Dispatcher + capability map: `src/core/dispatch.ts`, `src/core/capabilities.ts`
81125
- Platform backends: `src/platforms/ios/*`, `ios-runner/*`, `src/platforms/android/*`
82126

83-
## Capability Source Of Truth
84-
85-
- Command/device support must come from `src/core/capabilities.ts`.
86-
- Do not scatter new support checks across handlers.
87-
88-
## Selector System Rules
89-
90-
- Interaction commands (`click`, `fill`, `get`, `is`) and `wait` accept selectors and `@ref`.
91-
- Pipeline is: **parse -> resolve -> act -> record selectorChain -> heal on replay**.
92-
- Keep selector parsing/matching in `src/daemon/selectors.ts`.
93-
- Call `buildSelectorChainForNode` after resolving an interaction target.
94-
- New element-targeting interactions must support selector input and `@ref`, record `selectorChain`, and hook replay healing (`healReplayAction` + `collectReplaySelectorCandidates` in `session.ts`).
95-
- New selector key updates stay centralized in `selectors.ts` (`SelectorKey`, key sets, matcher, token checks).
96-
- New `is` predicates belong in `evaluateIsPredicate` (`src/daemon/is-predicates.ts`), not handler code.
97-
98-
## Testing
99-
- Unit tests are colocated with source files under `src/**`.
100-
- Use `__tests__` folders colocated with the related source folder.
101-
- The `test/**` tree is integration-only (including smoke integration tests).
102-
- Example: tests for `src/daemon/selectors.ts` go in `src/daemon/__tests__/selectors.test.ts`.
103-
- Add/extend colocated unit tests in the same PR for touched module logic.
104-
- Any TS change:
105-
- `pnpm typecheck`
106-
- Daemon handler/shared module change:
107-
- `pnpm test:unit`
108-
- `pnpm test:smoke`
109-
- iOS runner/Swift change:
110-
- `pnpm build:xcuitest`
111-
112-
Run integration tests when behavior crosses platform boundaries:
113-
- `pnpm test:integration`
114-
115-
## Measurement
116-
- Track files touched per fix, cycle time, and iOS/Android regressions.
117-
118-
## Local Commands
119-
120-
- Run CLI: `pnpm ad <command>`
121-
- For verification commands, use the **Testing** section above.
122-
123127
## Pull Requests
124-
- Before opening PR: ensure no conflict markers and no unmerged paths.
125-
- Run required checks for touched scope (at minimum `pnpm typecheck`; plus test commands from **Testing** above).
128+
- Before opening PR: ensure no conflict markers/unmerged paths.
129+
- Run required checks for touched scope from **Testing Matrix**.
126130
- PR body must be short and include:
127-
- `## Summary` with key behavior changes
131+
- `## Summary`
128132
- `## Validation` with exact commands run
129-
- Call out known gaps or follow-ups explicitly; do not hide failing checks.
133+
- Call out known gaps/follow-ups explicitly.
134+
- Include touched-file count and note if scope expanded beyond initial command family.
135+
136+
## Priority Order
137+
- When guidance conflicts, apply in this order: **Hard Rules -> Scope -> Testing Matrix -> style/preferences**.

0 commit comments

Comments
 (0)