Skip to content

Commit 0da105e

Browse files
authored
docs: simplify agent context and resolve conflicting guidance (#2287)
* docs: clarify agent task scope and validation * docs: remove redundant and conflicting agent guidance
1 parent 35362fe commit 0da105e

7 files changed

Lines changed: 163 additions & 239 deletions

File tree

AGENTS.md

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
`agent-device` is a CLI and daemon for automating Apple, Android, HarmonyOS, Vega, Linux, and web
44
targets. A long-lived daemon owns sessions; registry-derived commands route to platform runtimes.
55

6-
This file contains repository-specific traps and invariants that are expensive to rediscover. Load
7-
task procedures only when needed:
6+
## Task routing
7+
8+
Load only the procedures relevant to the task:
89

910
| When the task involves | Read |
1011
| --- | --- |
@@ -14,35 +15,28 @@ task procedures only when needed:
1415
| Selector capture, polling, or interaction fast paths | `docs/agents/selector-capture.md` |
1516
| Adding or changing a CLI flag | `docs/agents/cli-flags.md` |
1617
| Opening or reviewing a PR | `docs/agents/pull-requests.md` |
17-
| Running against a real device | `docs/agents/device-verification.md` |
18+
| Apple runner changes or manual device verification | `docs/agents/device-verification.md` |
1819
| Writing issues or PRDs, and triage labels | `docs/agents/issue-tracker.md`, `docs/agents/triage-labels.md` |
1920
| Web backend setup or diagnostics | `docs/agents/web-backend.md` |
2021

21-
Versioned CLI help is the source of truth for command behavior. Start with `agent-device help
22-
workflow`, then the relevant topic help.
22+
Versioned CLI help owns command semantics. Read the relevant topic when behavior is unclear;
23+
normal app-driving startup follows the skill's routing card.
2324

2425
## Incident-derived principles
2526

26-
- Guarantees erode at path boundaries. Classify every interaction dispatch path in
27-
`packages/contracts/src/interaction-guarantees.ts`; a registry claim is not proof that the native
28-
implementation satisfies the guarantee's definition.
27+
- Classify interaction dispatch paths in `packages/contracts/src/interaction-guarantees.ts` and
28+
verify each claim against the native implementation.
2929
- Delegation on error proves no success-path parity. A fast path may succeed on a candidate the
3030
shared rules would refuse.
31-
- Prove that a code path can fire before measuring it. An A/B test with an unreachable arm is two
32-
green runs without evidence.
33-
- A green regression test counts only after it has been observed red against the pre-fix code. Plant
34-
a violation for new structural gates and verify the gate names the invariant.
35-
- Repair recurring failures at their owning interface with types, a registry, or one construction
36-
path. A custom guard that reconstructs another source of truth needs redesign, not another
37-
exception.
38-
- Treat explanatory implementation comments as a failed design review. Do not narrate control flow,
39-
preserve review history, or justify a workaround in code. Express the invariant through names,
40-
types, module boundaries, and tests; put history in the PR or an ADR. Allow only public API docs,
41-
tool directives, and a brief citation to an external constraint that cannot be encoded.
42-
- Key behavior on typed reasons and details, never error text. Existing message sniffs are owned debt
43-
and must not be copied.
44-
- Snapshot output is the token budget: do not add per-node metadata when response-level metadata can
45-
be emitted once. Append warnings through the shared response builder; never replace prior warnings.
31+
- Prove both paths are reachable before measuring a fast path against its baseline.
32+
- Repair recurring failures at the owning type, registry, or construction path; do not add guards
33+
that reconstruct another source of truth.
34+
- Keep control-flow narration and review history out of implementation comments. Encode invariants
35+
in names, types, boundaries, and tests; reserve comments for public API docs, tool directives,
36+
and non-obvious constraints that cannot be encoded.
37+
- Key behavior on typed reasons and details, never error text; do not copy existing message sniffs.
38+
- Keep metadata at response level when it applies to the whole snapshot. Append warnings through
39+
the shared response builder; never replace prior warnings.
4640
- Before preserving a compatibility shape, run `git tag --contains <commit>`. Unreleased API has no
4741
external compatibility obligation.
4842

@@ -66,10 +60,10 @@ and progress in `@agent-device/capture-kit` (`request-cancel`, `request-progress
6660
contracts in `@agent-device/contracts`; CLI flags in `src/commands/cli-grammar`; cross-surface schema
6761
composition in `src/cli-schema`.
6862

69-
The enforced registries are self-declaring. A failing completeness, parity, coverage, timeout,
70-
layering, or construction gate means the new cell or path is unclassified; do not suppress or
71-
allowlist it. Interaction responses are built only through `buildInteractionResponseData`, and
72-
cross-language rules change through golden tables under `contracts/fixtures/`.
63+
Resolve registry completeness failures at the missing declaration. Diagnose other gate failures
64+
at their reported invariant; do not suppress them or add an allowlist to get a pass. Build interaction
65+
responses through `buildInteractionResponseData`; change cross-language rules through golden tables
66+
under `contracts/fixtures/`.
7367

7468
## Hard repository rules
7569

@@ -78,9 +72,9 @@ cross-language rules change through golden tables under `contracts/fixtures/`.
7872
- Apple target changes keep the kernel device model, runtime-fact admission, dispatch resolution,
7973
Apple discovery, and xctestrun preparation in sync.
8074
- iOS simulator-set scoping must never hide the host macOS desktop target.
81-
- Skills may carry a minimal start/routing card; command semantics belong in versioned CLI help.
82-
- Do not add compatibility or fallback behavior without explicit approval. Complete migrations and
83-
remove superseded paths.
75+
- Skills stay minimal routing cards.
76+
- Add compatibility or fallback behavior only when explicitly requested or approved. Otherwise,
77+
complete the migration and remove superseded paths.
8478
- Keep changes within one command family or module group unless the task explicitly crosses a
8579
boundary. Platform-neutral work does not license inspecting every platform implementation.
8680

@@ -93,7 +87,6 @@ cross-language rules change through golden tables under `contracts/fixtures/`.
9387
- Tests mirror source topology one-to-one. Split a source module and its test together; do not add to
9488
the legacy `interaction.test.ts` or platform `index.test.ts` aggregations. Pure moves carry their
9589
tests unchanged; rename-only hunks owe no new coverage.
96-
- Shared fixtures are named exports in a sibling fixture module, not repeated inline literals.
9790
- `src/daemon/handlers/session.ts` is already over budget; extract the relevant platform-specific
9891
concept before adding behavior.
9992

@@ -103,30 +96,14 @@ cross-language rules change through golden tables under `contracts/fixtures/`.
10396
repository-wide, not path-scoped.
10497
- A fresh worktree requires `pnpm install --frozen-lockfile && pnpm build`. Until then package and
10598
optional-peer resolution may point at another checkout and produce false failures.
106-
- Source-checkout daemon state is worktree-scoped, but devices are not. Use `pnpm daemon:state-dir`
107-
to inspect it and different devices for concurrent worktrees.
108-
- Run one full gate per host at a time. Subprocess-backed tests under concurrent worktrees produce
109-
timeout-shaped contention failures.
110-
- Before pushing, run `pnpm check:affected --run && git push`. Use `pnpm check` for broad refactors.
111-
GitHub remains authoritative for native, device, provider, and full-coverage lanes.
99+
- Parallel work needs disjoint edit ownership and distinct devices. Run one full gate per host;
100+
concurrent subprocess-backed suites can produce contention timeouts.
112101
- The layering scan reads tracked files only. Stage a new module before trusting its result.
113102
- Fallow baselines are path-keyed. Move the matching baseline entry when renaming a file; never bulk
114103
regenerate baselines to accept unrelated findings.
115-
- The first Node process after a newly signed Apple runner launches may block during Gatekeeper
116-
verification. Warm it with a throwaway `node -e 0` before measuring.
117-
- `DEVICE_IN_USE` has two flavors. "already in use by session X" is this daemon — follow its
118-
`close --session` hint. "owned by session X in workspace Y" is another worktree's device
119-
claim — non-retriable; run the error's `device status`/`device release --stale` recovery,
120-
never PID hunting.
121-
- A changing timeout failure set that passes in isolation is host contention. Reproduce the same
122-
test on `origin/main` under the same load before treating it as a regression.
123104

124105
## Runtime and diagnostics seams
125106

126-
The OS-neutral Apple runner lives under `packages/platform-apple/src/runner/`. For connection errors,
127-
retry policy, or command typing, start at `runner-contract.ts`; transport stays below session/client
128-
behavior, and xctestrun build/cache logic stays outside request execution.
129-
130107
Diagnostics use `@agent-device/capture-kit/diagnostics`. Request diagnostics belong in the session request log;
131108
session artifact paths come from `src/daemon/session-store.ts`. App/device logs remain in `app.log`;
132109
Apple runner and xcodebuild output remains in `runner.log`.
@@ -150,11 +127,8 @@ translate through the interaction root frame. Prefer selector or ref tests over
150127

151128
## Documentation ownership
152129

153-
Before adding guidance, decide whether the command surface, CLI grammar/help, MCP projection, daemon
154-
runtime, ADR, or task procedure owns it. Link to executable registries instead of copying their
155-
contents. Keep a sentence in this file only when no gate, lint rule, versioned help, ADR, or
156-
decision-site comment can own it. `CONTEXT.md` is glossary-only: no implementation paths,
157-
architecture decisions, migration state, or workflows.
130+
Keep this file to repository traps and routing. Put task procedures in `docs/agents/`, decisions in
131+
ADRs, and command semantics in versioned help. Link to executable registries instead of duplicating
132+
their rules. `CONTEXT.md` is glossary-only: no implementation paths, decisions, or migration status.
158133

159-
Behavior changes update their owning help/metadata and user docs. In the final summary,
160-
state whether docs or skills changed and why.
134+
Behavior changes update owning help/metadata and user docs. Report docs or skill changes when relevant.

docs/agents/cli-flags.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Adding a CLI Flag
22

3-
A new flag touches only the layers that need to understand it. Stop at the layer where it stops
4-
mattering — threading it further is the common failure, not stopping too early.
3+
Thread a flag only through the layers that consume it:
54

65
1. `packages/contracts/src/cli-flags.ts`: add to `CliFlags`; add the definition to the matching
76
`src/commands/cli-grammar/flag-definitions-*.ts` owner and the relevant group in `flag-groups.ts`
87
(for example `SNAPSHOT_FLAGS`). Then update the command family metadata/schema that exposes the
98
flag; find the owner with
109
`rg -n "<command>|supportedFlags|allowedFlags" src/commands src/cli-schema src/cli/parser`. For
11-
schema-only CLI commands (`cdp`, `auth`, `connect`, `proxy`, `react-devtools`, `web`) the owner is
12-
`SCHEMA_ONLY_CLI_COMMAND_SCHEMAS` in `src/cli-schema/command-overrides.ts`. New flags are
13-
operator-only by default. Add a flag to `PROJECT_CONFIG_FLAG_KEYS` in
10+
schema-only CLI commands, the owner is `SCHEMA_ONLY_CLI_COMMAND_SCHEMAS` in
11+
`src/cli-schema/command-overrides.ts`. New flags are operator-only by default. Add a flag to `PROJECT_CONFIG_FLAG_KEYS` in
1412
`src/cli-schema/cli-config.ts` only when repository control is safe; this positive allowlist is
1513
the completeness gate.
1614
2. `src/commands/cli-grammar/*`: read the CLI flag into command input.

docs/agents/device-verification.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# Manual Device Verification
22

3-
Read this before running `agent-device` by hand against a simulator, emulator, or physical device.
3+
Read this for Apple runner changes or manual `agent-device` runs on simulators, emulators, or
4+
physical devices. Live verification steps apply when exercising a device-facing path.
45

5-
## Before the run: defeat staleness
6-
7-
Dev-loop staleness has three layers, and each produces a convincing false negative.
6+
## Build freshness
87

98
- After changing runtime code reached through `bin/agent-device.mjs` or the daemon: `pnpm build`,
109
then `pnpm clean:daemon` — the daemon does not self-reload.
1110
- Before any Android verification from source: `pnpm build`, `pnpm build:android`, `pnpm clean:daemon`.
1211
`build:android` refreshes and verifies both bundled Android helper artifacts for the current
1312
package version.
14-
- `shutdown` deliberately HANDS OFF a healthy simulator runner. The adopted runner keeps serving the
15-
old Swift binary until you kill its process or the source fingerprint changes, so "my change did
16-
nothing" measured against an adopted runner is a classic false negative. If Swift runner code
17-
changed, run `pnpm build:xcuitest`.
13+
- `shutdown` hands off a healthy simulator runner; a new daemon may adopt the old binary. After
14+
Swift runner changes, run `pnpm build:xcuitest` before verification. Use the session cleanup
15+
procedure below if ownership is stuck.
1816

1917
## Prove the path under test was actually active
2018

@@ -25,19 +23,30 @@ Dev-loop staleness has three layers, and each produces a convincing false negati
2523
simulator, physical-device, Metro/dev-client, and app-surface steps. An already-installed
2624
`com.callstack.agentdevicelab` is not sufficient — the README's Metro/dev-build and `snapshot -i`
2725
checks must prove the expected app surface is running.
28-
- For Android RN/Expo/dev-client apps on any local Metro port, `adb reverse tcp:<port> tcp:<port>` is
29-
harmless and should be run before opening the app or URL.
26+
- For Android RN/Expo/dev-client apps that use local Metro, configure
27+
`adb reverse tcp:<port> tcp:<port>` for the app's Metro port before opening the app or URL.
3028

31-
## Session hygiene
29+
## Worktree ownership and runner diagnostics
30+
31+
- Source-checkout daemon state is worktree-scoped, but devices are not. Use `pnpm daemon:state-dir`
32+
to inspect it and different devices for concurrent worktrees.
33+
- The first Node process after a newly signed Apple runner launches may block during Gatekeeper
34+
verification. Warm it with a throwaway `node -e 0` before measuring.
35+
- `DEVICE_IN_USE` has two flavors. "already in use by session X" is this daemon — follow its
36+
`close --session` hint. "owned by session X in workspace Y" is another worktree's device
37+
claim — non-retriable; run the error's `device status`/`device release --stale` recovery,
38+
never PID hunting.
3239

33-
Every manually opened session is a resource that must be closed — including exploratory sessions and
34-
failed verification attempts.
40+
The OS-neutral Apple runner lives under `packages/platform-apple/src/runner/`. For connection errors,
41+
retry policy, or command typing, start at `runner-contract.ts`; transport stays below session/client
42+
behavior, and xctestrun build/cache logic stays outside request execution.
43+
44+
## Session hygiene
3545

36-
- Every `agent-device open` needs a matching `close` with the same `--session`, `--platform`,
37-
`--udid`, and `--state-dir` before the agent finishes.
46+
- Close manually opened sessions, including failed verification attempts, using their original
47+
`--session`, `--platform`, `--udid`, and `--state-dir` values.
3848
- Use a purpose-specific session name for experiments, and an isolated `--state-dir` under
3949
`/private/tmp` when you need cleanup isolation beyond the current worktree's default daemon.
40-
- Track opened sessions in working notes; close each one before the final response.
4150
- If `close` is blocked or ownership looks stuck, inspect it with
4251
`agent-device device status --stale` (daemonless), stop the owning daemon with
4352
`agent-device daemon stop --state-dir <dir>` (add `--clean` to remove retained runners), and
@@ -48,8 +57,7 @@ failed verification attempts.
4857

4958
## Sandboxed environments
5059

51-
Start the daemon outside the sandbox with escalation. The daemon binds localhost, and sandboxed runs
52-
fail before any product code executes, with `listen EPERM: operation not permitted 127.0.0.1` or
53-
repeated `Failed to start daemon`/metadata cleanup messages. Those are not agent-device regressions —
54-
rerun with escalation. Unit tests, typecheck, lint, and build can stay sandboxed unless they need
55-
devices or listener access.
60+
The daemon binds localhost. If the sandbox rejects the listener with `listen EPERM`, rerun with
61+
host access when permitted. Generic `Failed to start daemon` or cleanup errors alone do not prove a
62+
sandbox cause; inspect the underlying failure. Run other checks in the sandbox unless their tools
63+
require host access.

docs/agents/domain.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
# Domain Docs
22

3-
Single-context repo. Before architecture, diagnosis, TDD, triage, PRD, or roadmap work, read
4-
`CONTEXT.md` for domain vocabulary and the relevant ADRs in `docs/adr/`. Selector-capture work also
5-
reads `docs/agents/selector-capture.md`.
6-
7-
Use `CONTEXT.md` vocabulary in issue titles, refactor proposals, test names, and architecture notes.
8-
If a proposed change contradicts an ADR, say so explicitly and explain why the decision should be
9-
reopened.
10-
11-
`AGENTS.md` routes to the rest of this directory by task type.
3+
Use `CONTEXT.md` for domain vocabulary and `docs/adr/README.md` to locate decisions relevant to the
4+
change. A proposed ADR contradiction requires an explicit decision update.
125

136
## Test-harness vocabulary
147

0 commit comments

Comments
 (0)