mandrel 2.9.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.agents/agents/.markdownlint.json +4 -0
  2. package/.agents/agents/acceptance-critic.md +30 -5
  3. package/.agents/agents/auditor.md +36 -19
  4. package/.agents/agents/plan-critic.md +31 -5
  5. package/.agents/agents/story-worker.md +91 -100
  6. package/.agents/docs/configuration.md +39 -25
  7. package/.agents/docs/execution-reference.md +13 -0
  8. package/.agents/docs/workflows.md +1 -1
  9. package/.agents/instructions.md +131 -265
  10. package/.agents/rules/git-conventions.md +47 -83
  11. package/.agents/rules/orchestration-error-handling.md +28 -0
  12. package/.agents/schemas/agentrc.schema.json +36 -9
  13. package/.agents/schemas/validation-evidence.schema.json +3 -1
  14. package/.agents/scripts/acceptance-eval.js +10 -6
  15. package/.agents/scripts/apply-quality-bootstrap.js +1 -1
  16. package/.agents/scripts/check-test-temp-hygiene.js +438 -0
  17. package/.agents/scripts/deliver-recover.js +23 -6
  18. package/.agents/scripts/lib/audit-suite/index.js +5 -0
  19. package/.agents/scripts/lib/audit-suite/lens-diff-floor.js +179 -0
  20. package/.agents/scripts/lib/audit-suite/selector.js +1 -1
  21. package/.agents/scripts/lib/baselines/env-overrides.js +33 -0
  22. package/.agents/scripts/lib/baselines/git-base.js +0 -0
  23. package/.agents/scripts/lib/baselines/preview-gates.js +5 -0
  24. package/.agents/scripts/lib/config/gates/maintainability.schema.js +10 -1
  25. package/.agents/scripts/lib/config/quality.js +13 -0
  26. package/.agents/scripts/lib/config/temp-paths.js +121 -1
  27. package/.agents/scripts/lib/config-settings-schema-delivery.js +30 -0
  28. package/.agents/scripts/lib/config-settings-schema.js +12 -16
  29. package/.agents/scripts/lib/observability/metrics-ledger.js +217 -0
  30. package/.agents/scripts/lib/observability/runtime-friction.js +7 -0
  31. package/.agents/scripts/lib/orchestration/ceremony-routing.js +45 -0
  32. package/.agents/scripts/lib/orchestration/check-baselines/phases/evaluate.js +97 -4
  33. package/.agents/scripts/lib/orchestration/check-baselines/phases/parse-args.js +7 -0
  34. package/.agents/scripts/lib/orchestration/complexity-gate.js +533 -93
  35. package/.agents/scripts/lib/orchestration/deliver-recover.js +137 -10
  36. package/.agents/scripts/lib/orchestration/merge-block-class.js +36 -15
  37. package/.agents/scripts/lib/orchestration/merge-poll.js +213 -0
  38. package/.agents/scripts/lib/orchestration/plan-context.js +119 -3
  39. package/.agents/scripts/lib/orchestration/plan-critic-conditions.js +182 -9
  40. package/.agents/scripts/lib/orchestration/plan-critics-evaluate.js +29 -2
  41. package/.agents/scripts/lib/orchestration/plan-metrics.js +31 -82
  42. package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +153 -2
  43. package/.agents/scripts/lib/orchestration/plan-persist/story-ops.js +221 -14
  44. package/.agents/scripts/lib/orchestration/resolve-stories.js +12 -1
  45. package/.agents/scripts/lib/orchestration/review-depth.js +9 -4
  46. package/.agents/scripts/lib/orchestration/review-providers/native.js +34 -16
  47. package/.agents/scripts/lib/orchestration/single-story-close/phases/code-review.js +8 -3
  48. package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +230 -79
  49. package/.agents/scripts/lib/orchestration/spec-budget.js +78 -0
  50. package/.agents/scripts/lib/orchestration/story-body-gate.js +72 -0
  51. package/.agents/scripts/lib/orchestration/story-close/phases/local-lens-review.js +89 -1
  52. package/.agents/scripts/lib/orchestration/story-close/phases/review-core.js +73 -0
  53. package/.agents/scripts/lib/orchestration/ticket-validator-conflicts.js +6 -0
  54. package/.agents/scripts/lib/orchestration/ticket-validator.js +18 -62
  55. package/.agents/scripts/lib/templates/decomposer-prompts.js +13 -6
  56. package/.agents/scripts/lib/test-env.js +65 -0
  57. package/.agents/scripts/plan-context.js +84 -9
  58. package/.agents/scripts/plan-critics.js +115 -3
  59. package/.agents/scripts/plan-persist.js +11 -1
  60. package/.agents/scripts/plan-run-epilogue.js +1 -1
  61. package/.agents/scripts/resolve-stories.js +2 -0
  62. package/.agents/scripts/single-story-confirm-merge.js +65 -5
  63. package/.agents/scripts/stories-wave-tick.js +1 -1
  64. package/.agents/workflows/deliver.md +88 -230
  65. package/.agents/workflows/helpers/acceptance-self-eval.md +16 -5
  66. package/.agents/workflows/helpers/deliver-reference.md +171 -0
  67. package/.agents/workflows/helpers/deliver-story-reference.md +223 -0
  68. package/.agents/workflows/helpers/deliver-story.md +115 -432
  69. package/.agents/workflows/helpers/plan-reference.md +246 -0
  70. package/.agents/workflows/plan.md +108 -304
  71. package/docs/CHANGELOG.md +46 -0
  72. package/lib/cli/registry.js +31 -14
  73. package/lib/migrations/index.js +2 -0
  74. package/lib/migrations/steps/2.11.0-retire-max-seed-words.js +92 -0
  75. package/package.json +1 -1
@@ -1,8 +1,11 @@
1
1
  # Agent Execution Protocol
2
2
 
3
- You operate under the Agent Execution Protocol — this central instruction set
4
- governs your behavior, constraints, and operational context, and you MUST
5
- strictly adhere to it.
3
+ You operate under the Agent Execution Protocol — this instruction set
4
+ governs your behavior and constraints; you MUST strictly adhere to it.
5
+ It is a lean always-on spine: procedural detail lives in the on-demand
6
+ tier (§ 1.F rules,
7
+ [`docs/execution-reference.md`](docs/execution-reference.md), skills)
8
+ and is read when the task engages it.
6
9
 
7
10
  ---
8
11
 
@@ -10,333 +13,196 @@ strictly adhere to it.
10
13
 
11
14
  ### A. Role Framing
12
15
 
13
- Behavioral constraints come from this file, always-on / on-demand rules, and
14
- skills there are no persona packs and no `persona::*` labels. Role-scoped
15
- spawn contexts (when used) live under `.agents/agents/` via
16
- `delivery.routing.roleScopedAgents`; QA auth identities (`qa.personas`) are a
17
- separate fixture concept. If a user says "act as [role]", apply the matching
18
- skill / workflow guidance (QA skills for verification, the security skill for
19
- threat modeling) rather than looking for a persona file.
16
+ No persona packs, no `persona::*` labels constraints come from this
17
+ file, the rules, and skills. Role-scoped spawn contexts live under
18
+ `.agents/agents/` (`delivery.routing.roleScopedAgents`); `qa.personas`
19
+ are a separate fixture concept. "Act as [role]" = apply the matching
20
+ skill / workflow guidance.
20
21
 
21
22
  ### B. Skill Activation
22
23
 
23
- The skill library is **two-tier**: **`core/`** universal, process-driven
24
- skills (`core/debugging-and-error-recovery`, `core/code-review-and-quality`,
25
- `core/security-and-hardening`); check for one first (the **test-first**
26
- discipline lives in [`rules/testing-standards.md`](rules/testing-standards.md),
27
- not a skill). **`stack/`** tech-stack-specific skills (`stack/qa/playwright`,
28
- `stack/qa/vitest`); apply when the project uses that technology, else use the
29
- § 1.C live-docs lookup.
30
-
31
- When a task engages a domain or technology, you MUST read the corresponding
32
- `.agents/skills/[tier]/[category]/[skill-name]/SKILL.md` and apply its
33
- constraints — the **Policy Capsule** (the whole cost of activation) on
34
- engagement, a `reference.md` section or `examples/` only when the task needs it
35
- (§ 1.F's read-when-relevant split). When unsure which applies, match the task
36
- against the one-line `description` in each skill's frontmatter (catalogued in
37
- `.agents/skills/skills.index.json`). Skills compose (`idea-refinement` →
38
- `/plan` → test-first implementation → `code-review-and-quality`); not every
39
- task needs every skill. The always-on operating posture is governed by § 3–4
40
- and § 1.I.
24
+ When a task engages a domain or technology, you MUST read the matching
25
+ `.agents/skills/[tier]/[category]/[skill-name]/SKILL.md` — tiers
26
+ **`core/`** (universal process; test-first discipline lives in
27
+ [`rules/testing-standards.md`](rules/testing-standards.md)) and
28
+ **`stack/`** (tech-specific) and apply its constraints: the **Policy
29
+ Capsule** on engagement; `reference.md` / `examples/` only when needed.
30
+ Unsure? Match against the `description`s in
31
+ `.agents/skills/skills.index.json`.
41
32
 
42
33
  ### C. Proactive Documentation
43
34
 
44
- You MUST use the host's best live-documentation mechanism (a docs MCP server
45
- such as Context7, an IDE-native lookup, or equivalent) proactively to prevent
46
- hallucination: for any code involving third-party libraries, fetch the latest
47
- official docs **before** writing code do not ask permission. If none exists,
48
- fall back to (1) in-repo docs and the package's bundled `README.md` /
49
- `CHANGELOG.md`, then (2) the host's web fetch/search; note which channel you
50
- used so reviewers can spot stale references.
35
+ For any code involving third-party libraries, fetch the latest official
36
+ docs **before** writing code via the host's best live-documentation
37
+ mechanism (docs MCP server, IDE lookup) do not ask permission.
38
+ Fallbacks: (1) in-repo docs and the package's bundled README/CHANGELOG,
39
+ (2) web fetch/search. Note the channel you used.
51
40
 
52
41
  ### D. Error Handling & Degradation
53
42
 
54
- If any protocol file (Persona, Skill, or rule) cannot be loaded, you MUST
55
- alert the user using the following warning format before proceeding:
56
-
57
- > ⚠️ **Agent Protocol Warning**
58
- >
59
- > - **Missing:** `[file or tool]`
60
- > - **Impact:** [Description]
61
- > - **Fallback:** [Description]
62
-
63
- State mutations (label transitions, cascade completion, structured comments)
64
- are performed via the in-repo CLI scripts under `.agents/scripts/`
65
- (`update-ticket-state.js`, `post-structured-comment.js`, …). Use those
66
- directly — there is no separate state-mutation MCP server to degrade from.
43
+ If a protocol file cannot be loaded, alert the user before proceeding
44
+ with a `⚠️ **Agent Protocol Warning**` block naming **Missing**,
45
+ **Impact**, and **Fallback**. State mutations go through the in-repo CLI
46
+ scripts under `.agents/scripts/` there is no state-mutation MCP server
47
+ to degrade from.
67
48
 
68
49
  ### E. Local Overrides
69
50
 
70
- If a `.agents/instructions.local.md` or `.agentrc.local.json` is present, you
71
- MUST load it — the config resolver deep-merges `.agentrc.local.json` over
72
- `.agentrc.json` (local wins; absent is a no-op). Do not modify these files
73
- unless requested.
74
-
75
- **Durable slash commands.** Any `.md` at `.agents/local/workflows/<name>.md` is
76
- projected into `.claude/commands/<name>.md` by `sync-claude-commands.js` as
77
- `/<name>`. The `.agents/local/` subtree is exempt from `mandrel sync`'s prune
78
- pass, so these commands survive `npm install` / `mandrel sync` / `mandrel
79
- update`; a core payload command of the same basename wins (local ignored with a
80
- `shadowed` warning).
51
+ If `.agents/instructions.local.md` or `.agentrc.local.json` is present,
52
+ you MUST load it — the resolver deep-merges `.agentrc.local.json` over
53
+ `.agentrc.json` (local wins; absent is a no-op). Do not modify these
54
+ files unless requested. Durable local slash commands:
55
+ [`docs/execution-reference.md`](docs/execution-reference.md#durable-local-slash-commands).
81
56
 
82
57
  ### F. Modular Global Rules
83
58
 
84
- `.agents/rules/` splits into an **always-on core** (loaded with this file) and
85
- an **on-demand set** (read only when the task engages it, so a generic task —
86
- and every subagent it spawns — does not re-pay their bytes), the same
87
- read-when-relevant pattern skills use 1.B).
88
-
89
- - **Always-on core**: [`security-baseline.md`](rules/security-baseline.md)
90
- (inviolable security MUSTs) and
91
- [`git-conventions.md`](rules/git-conventions.md) (branch shapes,
92
- commit-subject format, `refs #`, push/hygiene MUSTs).
93
- - **On-demand** read **before** the matching work; each opens with a one-line
94
- "this rule applies when…" scope header:
95
- [`git-conventions-reference.md`](rules/git-conventions-reference.md)
96
- (git-history mechanics),
97
- [`shell-conventions.md`](rules/shell-conventions.md) (shell chains,
98
- cross-platform strings),
99
- [`testing-standards.md`](rules/testing-standards.md) (authoring or
100
- restructuring tests),
101
- [`orchestration-error-handling.md`](rules/orchestration-error-handling.md)
102
- (scripts under `.agents/scripts/**`),
103
- [`ci-remediation.md`](rules/ci-remediation.md) (a red or slow CI check), and
104
- [`api-conventions.md`](rules/api-conventions.md) /
105
- [`gherkin-standards.md`](rules/gherkin-standards.md) /
106
- [`changelog-style.md`](rules/changelog-style.md) /
107
- [`test-seams.md`](rules/test-seams.md) (API, Gherkin, changelog, test-seam
108
- work).
109
-
110
- Read the rule when unsure — cheaper than shipping a MUST violation; loading it
111
- on demand does not lower its authority (§ 1.K).
59
+ `.agents/rules/` splits into an **always-on core**
60
+ [`security-baseline.md`](rules/security-baseline.md) (inviolable security
61
+ MUSTs) and [`git-conventions.md`](rules/git-conventions.md) (branch
62
+ shapes, commit subjects, push/hygiene MUSTs) — and an **on-demand set**,
63
+ read **before** the matching work (each opens with a one-line "applies
64
+ when…" scope header): `git-conventions-reference.md`,
65
+ `shell-conventions.md`, `testing-standards.md`,
66
+ `orchestration-error-handling.md` (scripts under `.agents/scripts/**`),
67
+ `ci-remediation.md`, `api-conventions.md`, `gherkin-standards.md`,
68
+ `changelog-style.md`, `test-seams.md`. Read when unsure (on-demand
69
+ loading does not lower a rule's authority § 1.K).
112
70
 
113
71
  ### G. Structured Configuration
114
72
 
115
- Refer to `.agentrc.json` for operational limits (auto-run permissions, etc.).
116
- Project technology choices (database, ORM, API framework, auth, validation,
117
- paths) are intentionally kept out of it — read the Tech Stack inventory:
118
- `docs/tech-stack.md` when present, otherwise the **Tech Stack** section of
119
- `docs/architecture.md`.
73
+ `.agentrc.json` holds operational limits. Project technology choices
74
+ are deliberately kept out of it read `docs/tech-stack.md` when
75
+ present, else the **Tech Stack** section of `docs/architecture.md`.
120
76
 
121
77
  ### H. Observability & Friction Telemetry
122
78
 
123
- You MUST log telemetry about operational difficulty or automation
124
- opportunities. Friction is a **local NDJSON signal**: `diagnose-friction.js`
125
- appends a `kind: friction` record to the per-run/per-Story `signals.ndjson`
126
- stream (not posted to the ticket; the retro phase surfaces the aggregate).
127
-
128
- - **Command**:
129
- `node .agents/scripts/diagnose-friction.js --story [STORY_ID] --cmd [FAILED_COMMAND]`
130
- - **When to fire**: after repeated tool-validation errors, an unrecoverable
131
- command failure, ambiguity needing self-correction, or repetitive boilerplate
132
- a workflow/skill could simplify.
133
-
134
- Schema, stream path, the never-silently-dropped guarantee, and the
135
- `AGENT_LOG_LEVEL` (`silent`/`info`/`verbose`) emission table are reference
136
- detail — see [`docs/execution-reference.md`](docs/execution-reference.md#friction-telemetry).
79
+ You MUST log operational friction (repeated tool errors, unrecoverable
80
+ command failures, self-corrected ambiguity, automatable boilerplate):
81
+ `node .agents/scripts/diagnose-friction.js --story [STORY_ID] --cmd [FAILED_COMMAND]`
82
+ a **local NDJSON signal** (not posted to the ticket). Schema and the
83
+ `AGENT_LOG_LEVEL` table:
84
+ [`docs/execution-reference.md`](docs/execution-reference.md#friction-telemetry).
137
85
 
138
86
  ### I. Anti-Thrashing Protocol
139
87
 
140
- You MUST proactively identify when you are "thrashing" or stuck in an
141
- infinite loop, and you MUST stop, summarize the blockers, and present a
142
- **Re-Plan** (or yield to the user) before consuming more tokens on a failing
143
- strategy. The cues are qualitative there are no numeric thresholds; the call
144
- is yours to make.
145
-
146
- - **Failure cluster** — several tool calls in a row returning same-shape
147
- errors with the same remediation. Stop.
148
- - **Research drift** — several reads deep with nothing written and the reads no
149
- longer narrowing the problem. Stop and plan with what you have.
150
- - **Same fix, same failure** — the same kind of fix applied more than once for
151
- one error class with no change in the failure mode. Stop; the diagnosis is
152
- wrong.
153
-
154
- When you stop, summarize in one paragraph what you tried, what recurred, and
155
- what you would test next, then Re-Plan or hand back — do not paper over the
156
- loop with another just-in-case retry.
88
+ You MUST recognize thrashing and stop **before** spending more tokens
89
+ on a failing strategy cues: a **failure cluster** (same-shape tool
90
+ errors in a row), **research drift** (reads no longer narrowing the
91
+ problem), **same fix, same failure** (the diagnosis is wrong). On stop:
92
+ summarize what you tried and what recurred, then **Re-Plan** or yield —
93
+ never another just-in-case retry.
157
94
 
158
95
  ### J. HITL Blocker Escalation (Safe Execution)
159
96
 
160
- Before any task, you MUST check the ticket labels for high-risk operations.
161
-
162
- - **`risk::high` is metadata**: treat it as planning/audit signal only. It
163
- does **not** create an automatic runtime pause.
164
- - **Single runtime pause point**: `agent::blocked` is the authoritative HITL
165
- gate. When execution encounters an unresolvable blocker or an unsafe
166
- destructive action without explicit authorization, transition to
167
- `agent::blocked`, summarize the blocker, and wait for operator resume.
168
- - **Resume contract**: continue only after the operator explicitly unblocks
169
- (`agent::executing` or equivalent workflow instruction).
170
- - **High-risk heuristic**: use `planning.riskHeuristics` from
171
- `.agentrc.json` to decide when to escalate via `agent::blocked`. Typical
172
- triggers include destructive/irreversible data mutations, shared
173
- auth/security changes, CI/CD gate changes, monorepo-wide rewrites, and
174
- destructive schema migrations.
97
+ Check ticket labels before any task. `risk::high` is planning/audit
98
+ metadata only — no automatic runtime pause. The single runtime pause
99
+ point is **`agent::blocked`**: on an unresolvable blocker or an unsafe
100
+ destructive action without explicit authorization, transition to
101
+ `agent::blocked`, summarize the blocker, and wait for operator resume
102
+ (`agent::executing` or equivalent); escalate per
103
+ `planning.riskHeuristics` in `.agentrc.json`.
175
104
 
176
105
  ### K. Precedence & Conflict Resolution
177
106
 
178
- The governance documents you load are layered. When two of them conflict,
179
- resolve by this **total ordering** (higher wins):
180
-
181
- 1. **Local overrides** — `.agents/instructions.local.md` / `.agentrc.local.json`
182
- 1.E).
183
- 2. **This file** `.agents/instructions.md`.
184
- 3. **Global rules** — `.agents/rules/*.md` (§ 1.F).
185
- 4. **Skills** — `.agents/skills/**/SKILL.md` (§ 1.B).
186
-
187
- Two carve-outs refine the ordering:
188
-
189
- - **More specific wins within a tier.** When two documents in the **same**
190
- tier overlap, the narrower, more-specific statement governs the broader one
191
- (e.g. a stack-specific skill refines a general core skill; a per-rule
192
- statement refines a cross-rule one).
193
- - **`rules/security-baseline.md` is inviolable.** No skill or local override
194
- may relax a security MUST. A security constraint that conflicts with any
195
- lower-tier guidance — or with a local override — always wins, regardless of
196
- its tier position above.
107
+ Conflicts resolve by this total ordering (higher wins): **1.** local
108
+ overrides 1.E) **2.** this file → **3.** global rules (§ 1.F)
109
+ **4.** skills (§ 1.B). Carve-outs: within a tier, the narrower statement
110
+ governs; and **`rules/security-baseline.md` is inviolable** — no skill or
111
+ local override may relax a security MUST, and a security constraint
112
+ always wins regardless of tier.
197
113
 
198
114
  ---
199
115
 
200
116
  ## 2. FinOps & Token Budgeting (Economic Guardrails)
201
117
 
202
- Mandrel does **not** enforce live LLM spend and has no operator-tunable context
203
- budget; your host runtime owns session quota. It does bound fixed framework
204
- ceilings the `/plan` context envelope and plan-time Story sizing — which
205
- **fail closed** with a message naming what to trim. Constants and trim options:
118
+ Mandrel does not enforce live LLM spend; your host owns session quota.
119
+ Fixed framework ceilings (the `/plan` context envelope, plan-time Story
120
+ sizing) **fail closed** naming what to trim:
206
121
  [`docs/execution-reference.md`](docs/execution-reference.md#finops--token-budgeting-economic-guardrails).
207
122
 
208
123
  ---
209
124
 
210
125
  ## 3. Core Philosophy
211
126
 
212
- 1. **Context First:** Before proposing any solution, understand the
213
- repository's tech stack, historical context, and structure.
214
- - **Digest-first Reading (Story #4433).** **Never ingest the whole
215
- `project.docsContextFiles` set up front.** Read the **docs digest** — a
216
- compact outline (path, byte size, heading outline with line numbers, and
217
- the first paragraph under each `##`) — decide which docs bear on the task,
218
- then **pull the full file on demand**, jumping to the section at the line
219
- number the digest names. This is a hard cutover: no read-every-file branch
220
- survives. When no digest exists for the task — an ad hoc task,
221
- `project.docsContextFiles` unset, or a null `docsDigestPath` there is
222
- **no mandatory docs read**: read a full doc only when the task's own
223
- context points you at one.
224
- - **Conditional Reads**: When the task touches UI copy, layout, or
225
- routing and the corresponding file is present in the project, also
226
- read `docs/style-guide.md` and `docs/web-routes.md`. Skip both when
227
- absent or unrelated to the task — they are not part of the universal
228
- mandatory set.
229
- - **Story Context**: Additionally, read the current Story's body — the
230
- inline `## Spec` plus its `acceptance[]` / `verify[]` entries — and
231
- the task-specific instructions.
232
- - **Optimization**: For large projects, prioritize targeted retrieval
233
- (semantic code search or focused text search) to isolate specific
234
- schemas or decisions before reading broad files.
235
- 2. **Plan First:** For non-trivial tasks (3+ steps or architectural
236
- decisions), update the Story's `## Spec` via `/plan` before touching code.
237
- 3. **Artifacts over Chat:** Write log files for test/build/debug output rather
238
- than pasting large blocks in chat.
239
- 4. **Idempotency:** Scripts and commands must be safe to run repeatedly.
240
- 5. **Security First:** Never hardcode secrets; use environment variables and
241
- secret scanning.
127
+ 1. **Context First.** **Digest-first reading (Story #4433):** never
128
+ ingest the whole `project.docsContextFiles` set up front — read the
129
+ docs digest and pull files on demand at the section it names. No
130
+ digest (ad hoc task, `docsContextFiles` unset, null `docsDigestPath`)
131
+ **no mandatory docs read**. A task touching UI copy, layout, or
132
+ routing also reads `docs/style-guide.md` / `docs/web-routes.md` when
133
+ present. Always read the current Story's body (`## Spec` +
134
+ `acceptance[]` / `verify[]`); prefer targeted retrieval over broad
135
+ reads.
136
+ 2. **Plan First.** For non-trivial tasks (3+ steps or architectural
137
+ decisions), update the Story's `## Spec` via `/plan` before code.
138
+ 3. **Artifacts over Chat.** Write test/build/debug output to log
139
+ files, not into chat.
140
+ 4. **Idempotency.** Scripts must be safe to run repeatedly.
141
+ 5. **Security First.** Never hardcode secrets; use environment variables
142
+ and secret scanning.
242
143
 
243
144
  ---
244
145
 
245
146
  ## 4. Execution & Quality Discipline
246
147
 
247
- - **Re-Plan on Failure:** If a strategy fails, **STOP** and re-plan
248
- immediately. Do not repeat a broken approach.
249
- - **Subagent Strategy:** Each spawn re-pays the full always-loaded context, so
250
- treat it as a cost decision. Prefer an **inline search** (grep, a targeted
251
- read) for small or localized lookups; reach for a subagent **only when the
252
- work justifies replicating context** a broad multi-file investigation, a
253
- parallel exploration front, or an isolated task that would crowd the main
254
- window. One objective per subagent; prefer a cheaper/faster host capability
255
- for mechanical or read-only spawns and keep implementation/design on the
256
- default. **Depth compounds the cost** sub-agents carry the `Agent` tool and
257
- nest further, and **every** level re-pays the context, so weigh the whole
258
- subtree's cost and stay within the supported depth envelope.
259
- - **Anti-Laziness:** NEVER use placeholder comments like
260
- `// ... existing code ...`, `/* rest of file */`, or
261
- `// implementation here`. You MUST output the ENTIRE file or the ENTIRE
262
- complete function so it can be safely written to disk.
263
- - **No Dead Code:** Remove unused imports, commented-out code, and dead
264
- branches before finalizing a file.
265
- - **Lint Compliance:** Adhere strictly to project linters and formatters;
266
- language/stack-specific quality rules live in their `stack/` skills and
267
- `.agents/rules/` files — apply them when the skill is activated.
268
- - **Verification:** Include explicit verification steps in every plan.
148
+ - **Re-Plan on Failure.** If a strategy fails, STOP and re-plan.
149
+ - **Subagent Strategy.** Each spawn re-pays the full always-loaded
150
+ context a cost decision. Prefer inline search for small lookups;
151
+ spawn only when the work justifies replicating context. One objective
152
+ per subagent; depth compounds the cost (every nested level re-pays).
153
+ - **Anti-Laziness / No Dead Code.** NEVER use placeholder comments like
154
+ `// ... existing code ...` output the ENTIRE file or complete
155
+ function; remove unused imports, commented-out code, and dead branches
156
+ before finalizing.
157
+ - **Lint Compliance.** Adhere strictly to project linters and
158
+ formatters.
159
+ - **Verification.** Include explicit verification steps in every plan.
269
160
 
270
161
  ---
271
162
 
272
163
  ## 5. Git & Story Protocol (Strict Standards)
273
164
 
274
- To maintain a clean and readable repository history, you MUST follow these
275
- strict conventions for all Story-related Git operations. See
276
- [`.agents/rules/git-conventions.md`](rules/git-conventions.md) for the full
277
- canonical reference.
278
-
279
- ### A. Branch Naming
280
-
281
- The canonical branch shape (`story-<storyId>` seeded and maintained by
282
- `single-story-init.js`, PR to `main`) and the commit-subject contract are
283
- owned by [`rules/git-conventions.md`](rules/git-conventions.md).
165
+ [`rules/git-conventions.md`](rules/git-conventions.md) is the canonical
166
+ reference: `story-<storyId>` branches seeded by `single-story-init.js`,
167
+ every Story reaching `main` via its own PR
168
+ (`helpers/deliver-story` / `single-story-close.js`).
284
169
 
285
170
  ### B. Status Tracking & Commit Standards
286
171
 
287
- Administrative state mutations in the v5 model are performed via GitHub
288
- labels. Do NOT manually update issue descriptions or status fields unless
172
+ State mutations are GitHub labels (`agent::ready`, `agent::executing`,
173
+ `agent::done`) via
174
+ `node .agents/scripts/update-ticket-state.js --ticket [ID] --state [STATUS]`.
175
+ Do NOT manually update issue descriptions or status fields unless
289
176
  prompted.
290
177
 
291
- - **Sync Tool**:
292
- `node .agents/scripts/update-ticket-state.js --ticket [ID] --state [STATUS]`
293
- - **Status Labels**: `agent::ready`, `agent::executing`, `agent::done`.
294
-
295
- ### C. History Hygiene
296
-
297
- Every Story reaches `main` via its own PR, opened by `helpers/deliver-story` /
298
- `single-story-close.js`; the history model is owned by
299
- [`rules/git-conventions.md`](rules/git-conventions.md).
300
-
301
178
  ### D. Ticket hierarchy (Story-only)
302
179
 
303
- v2 collapses the ticket model to **Story**: acceptance criteria and verify
304
- steps live inline (`acceptance[]` / `verify[]`) and the folded Tech Spec in
305
- `## Spec` (over-budget Specs fail closed — split or tighten; never write under
306
- `docs/`). Optional `depends_on` edges order rare multi-Story runs, resolved by
307
- `/deliver` from live state across plan runs and over time.
308
-
309
- - `/plan` emits one or more `type::story` issues (default N=1); there is no
310
- batch label — `/deliver` takes ids and discovers the graph.
311
- - Each Story is executed by `helpers/deliver-story` (from
312
- [`/deliver`](workflows/deliver.md)); the agent authors commit subjects
313
- directly per [`rules/git-conventions.md`](rules/git-conventions.md),
314
- referencing the Story via `(refs #<storyId>)`.
315
- - There is no `type::epic` / `type::task` label or Epic issue form; an Epic is
316
- at most an optional untyped human umbrella issue outside orchestration, and
317
- `/deliver` refuses tickets carrying an `Epic: #N` footer.
180
+ The v2 ticket model is Story-only: `acceptance[]` / `verify[]` live
181
+ inline plus the folded Tech Spec in `## Spec` (over-budget Specs fail
182
+ closed — split or tighten; never write Specs under `docs/`). Optional
183
+ `depends_on` edges order rare multi-Story runs, resolved by `/deliver`
184
+ from live state; the `plan-run::<id>` label is filter metadata only.
185
+ Commit subjects reference the Story via `(refs #<storyId>)`. There is no
186
+ `type::epic` / `type::task` label; `/deliver` refuses tickets carrying an
187
+ `Epic: #N` footer.
318
188
 
319
189
  ---
320
190
 
321
191
  ## 6. Workspace & File Hygiene (Temporary Files)
322
192
 
323
- All temporary files, scratch scripts, and intermediate outputs MUST live in the
324
- workspace-root `/temp/` directory, which is gitignored — do NOT commit anything
325
- under it.
193
+ All temporary files, scratch scripts, and intermediate outputs MUST
194
+ live in the gitignored workspace-root `/temp/` directory — do NOT commit
195
+ anything under it.
326
196
 
327
197
  ---
328
198
 
329
199
  ## 7. Complexity-Aware Execution
330
200
 
331
- `/plan` sizes each Story as a **capability slice a frontier model delivers and
332
- self-verifies in one pass** — a broad footprint is normal when the change is
333
- cohesive (the backstop is `DEFAULT_MODEL_CAPACITY` in `ticket-validator-sizing.js`,
334
- a framework constant). Do not re-slice a capability-sized Story into per-module
335
- fragments just because it touches many files.
336
-
337
- ### A. When You See `⚠️ COMPLEXITY WARNING`
338
-
339
- On a complexity warning or out-of-scope task: **plan first** (a numbered list of
340
- cohesive sub-steps — one coherent change each, not one file each — in a
341
- `<!-- DECOMPOSITION -->` block), **commit incrementally** after each sub-step,
342
- and **fail fast** — STOP and report if any sub-step fails validation.
201
+ `/plan` sizes each Story as a **capability slice a frontier model
202
+ delivers and self-verifies in one pass** — a broad footprint is normal
203
+ when the change is cohesive (backstop: `DEFAULT_MODEL_CAPACITY` in
204
+ `ticket-validator-sizing.js`); do not re-slice it into per-module
205
+ fragments. On a `⚠️ COMPLEXITY WARNING` or out-of-scope task: **plan
206
+ first** (numbered cohesive sub-steps in a `<!-- DECOMPOSITION -->`
207
+ block), **commit incrementally** per sub-step, and **fail fast** — STOP
208
+ and report if any sub-step fails validation.