its-magic 0.1.2-42 → 0.1.2-48

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.
@@ -1,934 +1,1004 @@
1
- # /auto — full orchestration specification (reference)
2
-
3
- > **US-0080 / DEC-0062**: Expanded contract for `/auto`. The slim `.cursor/commands/auto.md` is the default injected surface; load this file when full prose, tables, and step detail are required.
4
-
5
- ## Subagents
6
- - curator
7
- - tech-lead
8
-
9
- ## Execution model
10
- - `/auto` is a **spawn-only orchestrator**: it schedules materialization, spawns
11
- fresh **phase-role** subagents, and verifies phase boundaries—it **must not**
12
- execute lifecycle phase work, perform phase-role duties, or author **phase
13
- deliverables** in the orchestrator context.
14
- - For each phase, **spawn a fresh subagent** for that phase’s canonical role;
15
- phase output must arrive only via artifacts and handoff files (no in-turn
16
- orchestrator execution of that phase).
17
- - Phase context transfer happens only through artifacts and handoff files.
18
- - Scope is process/workflow orchestration only. Do not claim runtime product
19
- orchestration changes.
20
- - **Bug-queue mode** (**`US-0087`**) uses the same **spawn-only** model: schedule
21
- materialization and spawn phase-role subagents per bug segment — **never** in-turn
22
- **`execute`**, **`qa`**, or other lifecycle work in the orchestrator context.
23
- Missing spawn → **`AUTO_ORCHESTRATOR_PHASE_EXECUTION`** (**`BUG-0006`**,
24
- **`US-0069`**, **`DEC-0051`**).
25
-
26
- ## Spawn-boundary integrity (BUG-0006 / US-0080)
27
-
28
- This gate is **orthogonal** to per-phase isolation (**DEC-0029**, see
29
- `decisions/DEC-0029.md`) and strict runtime proof (**DEC-0038**, see
30
- `decisions/DEC-0038.md`): satisfying one does not excuse skipping the others.
31
-
32
- - **Forbidden**: using the orchestrator context to **perform** a lifecycle phase
33
- instead of **spawning** the required role subagent (for example in-turn
34
- **`architecture`**, **`execute`**, or **`qa`** work attributed to the
35
- orchestrator).
36
- - **Fail fast** with **`AUTO_ORCHESTRATOR_PHASE_EXECUTION`**. **Remediation**:
37
- stop; spawn a **fresh** subagent for the canonical **`phase_id`** and **`role`**
38
- per the phase→role matrix (**DEC-0051**); continue only through artifacts and
39
- handoffs. **Do not** overload **`PHASE_CONTEXT_ISOLATION_VIOLATION`** or
40
- **`RUNTIME_PROOF_*`** for a spawn-boundary violation—those address wrong-writer
41
- isolation breaks and attestation failures, not missing spawn.
42
-
43
- ## Per-phase isolation enforcement (US-0048 / DEC-0029)
44
-
45
- `/auto` must enforce fresh-context isolation as a fail-closed contract:
46
-
47
- - `/auto` must not write phase deliverables itself. If phase work is performed in
48
- the orchestrator context, stop immediately with reason code
49
- `PHASE_CONTEXT_ISOLATION_VIOLATION`.
50
- - Each spawned phase must write isolation evidence with required fields
51
- (`phase_id`, `role`, `fresh_context_marker`, `timestamp`, `evidence_ref`) to
52
- the canonical evidence store (`docs/engineering/state.md`) before `/auto`
53
- proceeds to the next phase.
54
- - `/auto` must fail closed when evidence is missing/invalid/stale (see reason
55
- codes below). No silent continuation.
56
-
57
- Reason codes (deterministic):
58
- - `PHASE_CONTEXT_ISOLATION_MISSING`
59
- - `PHASE_CONTEXT_ISOLATION_VIOLATION`
60
- - `ISOLATION_EVIDENCE_STALE`
61
- - `ISOLATION_EVIDENCE_INVALID`
62
-
63
- ## Strict runtime proof enforcement (US-0056 / DEC-0038)
64
-
65
- `/auto` must enforce strict runtime attestation in addition to artifact-level
66
- isolation evidence:
67
-
68
- - Each completed phase must provide a runtime attestation tuple linked to the
69
- phase checkpoint evidence:
70
- - `orchestrator_run_id`
71
- - `runtime_proof_id`
72
- - `phase_id`
73
- - `role`
74
- - `proof_issued_at` (ISO UTC / RFC3339)
75
- - `proof_ttl_seconds`
76
- - `proof_hash`
77
- - `runtime_proof_id` must be unique per phase run; reused proof IDs are invalid.
78
- - Proof freshness must be validated against `proof_issued_at` + TTL policy.
79
- - Proof linkage must be deterministic and auditable to checkpoint evidence refs.
80
- - Fail closed on any strict-proof violation; no silent continuation.
81
-
82
- Strict-proof reason codes:
83
- - `RUNTIME_PROOF_MISSING`
84
- - `RUNTIME_PROOF_INVALID`
85
- - `RUNTIME_PROOF_REUSED`
86
- - `RUNTIME_PROOF_STALE`
87
- - `RUNTIME_PROOF_AMBIGUOUS_LINK`
88
-
89
- ## Strict phase role enforcement (US-0069 / DEC-0051)
90
-
91
- `/auto` must enforce a deterministic **phase→role contract** with **preflight
92
- admission** before each phase spawn, **fail-closed checkpoint validation** after
93
- each phase completes, and **aligned strict-proof `role`** values. Post-hoc
94
- isolation markers alone are insufficient.
95
-
96
- ### Canonical phase→role matrix (fixed defaults)
97
-
98
- | phase_id | Allowed roles | Default when no valid alternate policy |
99
- |----------|-----------------|----------------------------------------|
100
- | `intake` | `po` | `po` |
101
- | `discovery` | `po` | `po` |
102
- | `research` | `po`, `tech-lead` | `tech-lead` |
103
- | `architecture` | `tech-lead` | `tech-lead` |
104
- | `sprint-plan` | `tech-lead` | `tech-lead` |
105
- | `plan-verify` | `qa`, `tech-lead` | `qa` |
106
- | `execute` | `dev` (override path only) | `dev` |
107
- | `qa` | `qa` | `qa` |
108
- | `verify-work` | `qa` | `qa` |
109
- | `release` | `release` | `release` |
110
- | `refresh-context` | `curator`, `po` | `curator` |
111
-
112
- ### Alternate-role scratchpad policy (single-valued resolution)
113
-
114
- Resolve **exactly one** expected role for phases with alternates using merged
115
- scratchpad (active + `.cursor/scratchpad.local.md`; template parity on install):
116
-
117
- - `AUTO_ROLE_RESEARCH`: `po` \| `tech-lead` — when **unset or empty**, default
118
- `tech-lead`; when set to any other value, fail closed with diagnostics (no
119
- unrelated-role fallback).
120
- - `AUTO_ROLE_PLAN_VERIFY`: `qa` \| `tech-lead` — when **unset or empty**,
121
- default `qa`; otherwise only `qa` or `tech-lead` allowed (else fail closed).
122
- - `AUTO_ROLE_REFRESH_CONTEXT`: `curator` \| `po` — when **unset or empty**,
123
- default `curator`; otherwise only `curator` or `po` allowed (else fail closed).
124
-
125
- ### Preflight capability gate (before spawn)
126
-
127
- Before spawning phase work, `/auto` must:
128
-
129
- 1. Resolve `phase_id` → expected canonical `role` (matrix + policy keys above).
130
- 2. For `execute`, apply **default deny**: expected role is `dev` unless **both**
131
- `AUTO_EXECUTE_ROLE_OVERRIDE=allowed_non_dev_execute` **and**
132
- `EXECUTE_OVERRIDE_GOVERNANCE_REF` point to a **parseable** approved exception
133
- record (for example `DEC-xxxx` or a documented anchor in
134
- `docs/engineering/state.md`).
135
- 3. Evaluate **role capability availability** for that boundary (subagent/tooling
136
- can satisfy the resolved role).
137
- 4. On missing capability: stop with `PHASE_ROLE_CAPABILITY_MISSING` including
138
- `phase_id`, expected role, observed capability result, and remediation. **Do
139
- not** spawn under a substitute unrelated role.
140
-
141
- ### Post-completion boundary validation
142
-
143
- When a phase completes, before advancing:
144
-
145
- - Isolation evidence `role` must equal the **same** preflight-resolved expected
146
- role for that `phase_id`. Else stop with `PHASE_ROLE_MISMATCH`.
147
- - Strict-proof tuple `role` must equal isolation `role` and the expected role.
148
- - `proof_hash` must be SHA-256 over canonical sorted-key JSON of
149
- `orchestrator_run_id`, `runtime_proof_id`, `phase_id`, `role`,
150
- `proof_issued_at`, `proof_ttl_seconds` (`DEC-0038` / architecture US-0069).
151
-
152
- ### Resume / `start-from` parity
153
-
154
- Every `/auto` invocation (explicit `start-from`, `resume_brief`, or conservative
155
- `state.md` fallback) must **recompute** policy resolution and preflight from
156
- scratch; stale continuation artifacts must not bypass the gate.
157
-
158
- ### Role-enforcement reason codes (deterministic)
159
-
160
- - `PHASE_ROLE_CAPABILITY_MISSING`
161
- - `PHASE_ROLE_MISMATCH`
162
-
163
- ## Configurable phase selection policy (US-0070 / DEC-0052)
164
-
165
- `/auto` must treat the **resolved phase plan** as a first-class, fail-closed
166
- schedule: a single ordered subset of canonical phases computed from merged
167
- scratchpad (active + `.cursor/scratchpad.local.md`; template parity on install),
168
- **before** resume/`start-from` intersection and **before** any phase spawn.
169
-
170
- ### Canonical lifecycle order (baseline `full` plan)
171
-
172
- Unless narrowed by policy, the canonical ordered phase list is:
173
-
174
- `intake` → `discovery` → `research` → `architecture` → `sprint-plan` →
175
- `plan-verify` → `execute` → `qa` → `verify-work` → `release` →
176
- `refresh-context`
177
-
178
- When `SECURITY_REVIEW=1`, insert `/security-review` in **design** mode
179
- immediately after `architecture` and before `sprint-plan`, and in **code** mode
180
- immediately after `execute` and before `qa`, as documented in **Steps** below.
181
- Record these inserts in `resolved_phase_plan` breadcrumbs using the same
182
- deterministic labels the orchestrator already uses for security boundaries.
183
-
184
- ### Scratchpad selectors (exactly one active policy mode)
185
-
186
- At most one of the following may be materially active after merge. If two or
187
- more non-default selectors conflict, fail closed with `PHASE_POLICY_CONFLICT`
188
- and **do not** materialize a plan:
189
-
190
- - `AUTO_PHASE_PLAN=full` — full canonical lifecycle (including security-review
191
- inserts when enabled). Default when unset and no other selector is set.
192
- - `AUTO_PHASE_EXCLUDE=<csv>` — start from `full`, remove listed phase IDs
193
- (validate each token; unknown id → `PHASE_PLAN_UNKNOWN_PHASE`).
194
- - `AUTO_PHASE_INCLUDE=<csv>` — schedule **only** listed ids, then **re-sort**
195
- into canonical lifecycle order. Unknown id → `PHASE_PLAN_UNKNOWN_PHASE`.
196
- Empty result after parsing → `PHASE_PLAN_EMPTY_INCLUDE`.
197
- - `AUTO_PHASE_PROFILE=<name>` — expand a **named profile** from the registry
198
- below. Unknown profile → `PHASE_PLAN_UNKNOWN_PROFILE`.
199
-
200
- **Conflict rule**: `AUTO_PHASE_PLAN` is default-only when it is unset, empty, or
201
- exactly `full`. Any explicit non-`full` `AUTO_PHASE_PLAN` value is invalid
202
- (fail closed with `PHASE_PLAN_INVALID_AUTO_PHASE_PLAN`) — use `INCLUDE` /
203
- `EXCLUDE` / `PROFILE` instead.
204
-
205
- ### Profile registry (baseline)
206
-
207
- - `default` — equivalent to `full` (optional explicit alias; same behavior as
208
- unset policy).
209
-
210
- **High-risk profile sketch** (illustrative; `R-0049`): `profile_high_risk_dev_fast`
211
- may only be selected when **both** hold: `AUTO_PHASE_PROFILE=profile_high_risk_dev_fast`
212
- and `AUTO_PHASE_HIGH_RISK_ACK=<operator_token>` matches the profile spec
213
- version documented in `decisions/DEC-0052.md` / research `R-0049`. Missing ack →
214
- `PHASE_PLAN_HIGH_RISK_ACK_REQUIRED`. High-risk profiles may define **narrower**
215
- reinstatement rules **only** as documented for that profile; default profile
216
- behavior applies otherwise.
217
-
218
- ### Plan materialization pipeline (evaluation order)
219
-
220
- On every `/auto` entry (including resume, backlog-drain, bug-queue, bulk execute, and
221
- team-mode runs), **recompute** from merged scratchpad:
222
-
223
- 1. Parse merged scratchpad policy inputs for phase selection + `SECURITY_REVIEW`.
224
- 2. Detect active policy mode; on conflict → `PHASE_POLICY_CONFLICT` (no plan).
225
- 3. Expand mode to a **candidate** ordered phase list in canonical order.
226
- 4. Apply **non-skippable reinstatement** for the **default profile** (and for
227
- any profile that does not explicitly document a narrower exception with ack):
228
- - **Safety gates**: always reinstate if removed: `qa`, `verify-work`,
229
- `release`.
230
- - **Evidence-chain closure**: if the candidate retains any phase from
231
- `execute` onward (`execute`, optional `security-review-code`, `qa`,
232
- `verify-work`, `release`, `refresh-context`), reinstate (if removed) the
233
- contiguous canonical prefix from `intake` through `plan-verify` so later
234
- gates retain valid upstream isolation + strict-proof chain semantics.
235
- - When `SECURITY_REVIEW=1`, reinstate the corresponding `security-review-*`
236
- insert when the adjacent retained phases would otherwise violate the
237
- documented security boundary contract.
238
- Record each reinstatement in breadcrumbs with reason `non_skippable_gate`
239
- (or a more specific documented code).
240
- 5. Record **operator-visible plan breadcrumbs** to `docs/engineering/state.md`
241
- **before** first spawn (append-bottom per `DEC-0040`):
242
- - `phase_policy_mode` (`full|exclude|include|profile`)
243
- - `resolved_phase_plan` (ordered `phase_id` list)
244
- - `skipped_phases` (id + reason: `policy_exclude`, `non_skippable_gate`,
245
- `default_full_plan`, etc.)
246
- - `orchestrator_run_id` (when known for this run)
247
- 6. **Do not** silently revive phases omitted by policy on continuation: every
248
- entry re-reads scratchpad bytes and recomputes the plan class.
249
-
250
- ### `start-from` and resume intersection with the resolved plan
251
-
252
- After computing the **resolved phase plan**, resolve the **nominal** start
253
- phase using **Deterministic resume-source precedence** (explicit `start-from`
254
- → **`bug-target=`** argv (when present) → merged scratchpad → `resume_brief` →
255
- `state` fallback → fail-fast).
256
-
257
- Then **intersect**:
258
-
259
- - Keep phases that appear in the resolved plan **in plan order**, starting at
260
- the first plan phase whose canonical position is **at or after** the nominal
261
- anchor phase (canonical order matches the baseline list above, including
262
- security inserts when enabled).
263
- - If the intersection is empty, fail closed with
264
- `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION` and diagnostics listing
265
- `resolved_phase_plan` vs `requested_start_phase` / resume inference.
266
-
267
- ### Compatibility with `US-0069` / `DEC-0051`
268
-
269
- - Role resolution and preflight apply **only** to phases present in the
270
- intersected schedule. Skipping `research` does **not** change the expected
271
- role for `architecture` or any other retained phase.
272
- - Skipped phases produce **no** spawn and **no** alternate-role substitution
273
- for a different phase.
274
-
275
- ### Phase-plan reason codes (deterministic)
276
-
277
- Add to operator diagnostics and breadcrumb records:
278
-
279
- - `PHASE_POLICY_CONFLICT`
280
- - `PHASE_PLAN_UNKNOWN_PHASE`
281
- - `PHASE_PLAN_EMPTY_INCLUDE`
282
- - `PHASE_PLAN_UNKNOWN_PROFILE`
283
- - `PHASE_PLAN_INVALID_AUTO_PHASE_PLAN`
284
- - `PHASE_PLAN_HIGH_RISK_ACK_REQUIRED`
285
- - `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`
286
-
287
- ### Phase boundary operator visibility (AC-10)
288
-
289
- At each phase boundary (after completing a scheduled phase), record a compact
290
- **phase boundary status** entry (for example in `docs/engineering/state.md`
291
- continuation breadcrumbs) including:
292
-
293
- - `resolved_phase_plan` snapshot (or stable hash pointer to the run’s plan record)
294
- - `skipped_phases` summary (id + reason code)
295
- - `phase_boundary` (completed `phase_id`)
296
- - `next_scheduled_phase` (or `none` when complete/stopped)
297
-
298
- **`US-0087` bug-queue extensions** (when bug scheduler is active or segment is
299
- bug-scoped; see **`architecture.md`** **`# US-0087`**):
300
-
301
- - `segment_work_item_kind` (`story|bug`)
302
- - `active_bug_id` (`BUG-####` or `(none)`)
303
- - `bug_queue_position` (1-based into **OPEN** ordering for `all-open`, or `(none)`)
304
- - `bug_queue_remaining` (integer or `(none)`)
305
- - `backlog_drain_active` (boolean — story **`AUTO_BACKLOG_DRAIN`** drives **this** run)
306
- - `bug_queue_active` (boolean — bug scheduler drives **this** run)
307
-
308
- **Invariant**: `backlog_drain_active` and `bug_queue_active` must **not** both be
309
- true for the same materialized run (scheduler mutex).
310
-
311
- ## Inputs
312
- - Merged scratchpad policy (`US-0073` / `DEC-0055`): resolve flags from **local >
313
- materialized `.cursor/scratchpad.md` > `.cursor/scratchpad.local.example.md`**
314
- (installers materialize baseline when missing; missing required keys after merge
315
- must fail closed with `[SCRATCHPAD_MERGE_ERROR]` diagnostics, not silent defaults).
316
- - `AUTO_FLOW_MODE` and `PHASE_MODE` from merged scratchpad
317
- - `AUTO_IMPLEMENTATION_LOOP`, `AUTO_LOOP_MAX_CYCLES` from merged scratchpad
318
- - `AUTO_PAUSE_REQUEST`, `AUTO_PAUSE_POLICY` from merged scratchpad
319
- - `SECURITY_REVIEW`, `COMPLIANCE_PROFILES` from merged scratchpad
320
- - `AUTO_EXECUTE_BULK`, `AUTO_EXECUTE_MAX_ITEMS`, `AUTO_EXECUTE_ON_BLOCK`,
321
- `AUTO_EXECUTE_SELECTION`, `AUTO_TEAM_SCOPE_ENFORCE` from merged scratchpad
322
- - `AUTO_ROLE_RESEARCH`, `AUTO_ROLE_PLAN_VERIFY`, `AUTO_ROLE_REFRESH_CONTEXT`,
323
- `AUTO_EXECUTE_ROLE_OVERRIDE`, `EXECUTE_OVERRIDE_GOVERNANCE_REF` from merged
324
- scratchpad (US-0069 / DEC-0051)
325
- - `AUTO_PHASE_PLAN`, `AUTO_PHASE_EXCLUDE`, `AUTO_PHASE_INCLUDE`,
326
- `AUTO_PHASE_PROFILE`, `AUTO_PHASE_HIGH_RISK_ACK` from merged scratchpad
327
- (US-0070 / DEC-0052)
328
- - `TEAM_MODE`, `TEAM_MEMBER`, `ACTIVE_TASK_IDS` from merged scratchpad context
329
- - Current product and engineering docs
330
- - Optional explicit argument: `start-from=<phase>`
331
- - Optional explicit argument: **`bug-target=BUG-####`** or **`bug-target=all-open`**
332
- (**`US-0087`**; parsed before merged scratchpad scheduler keys)
333
- - Optional explicit argument: `--execute-bulk` (one-run explicit override)
334
- - `AUTO_BUG_QUEUE`, `AUTO_BUG_TARGET`, `AUTO_BUG_MAX_ITEMS`, `AUTO_BUG_ON_BLOCK`
335
- from merged scratchpad (**`US-0087`**)
336
- - Resume-source artifacts:
337
- - `handoffs/resume_brief.md`
338
- - `docs/engineering/state.md`
339
-
340
- ## Automation remote routing contract (US-0086)
341
-
342
- This contract is deterministic and default-off. It composes with `US-0064`,
343
- `DEC-0070`, `US-0085`, and `DEC-0071`.
344
-
345
- Automation profile controls (merged scratchpad):
346
-
347
- - `AUTO_REMOTE_AUTOMATION_PROFILE`: `off|deterministic_v1`
348
- - `AUTO_REMOTE_ENVIRONMENT_LABEL`: `local|docker|ssh` (names-only evidence)
349
- - `REMOTE_EXECUTION`: `0|1` (remote config validation gate from `US-0084`)
350
- - `REMOTE_CONFIG`: canonical remote config path
351
-
352
- Mode split:
353
-
354
- - `AUTO_REMOTE_AUTOMATION_PROFILE=off` -> preserve manual/local behavior; no
355
- silent remote reroute.
356
- - `AUTO_REMOTE_AUTOMATION_PROFILE=deterministic_v1` -> routing policy may resolve
357
- Docker/SSH/local targets for automation workflows.
358
-
359
- NL intent resolution (v1 literal):
360
-
361
- - Parse only the exact phrase `start container <target_id>`.
362
- - Resolve `<target_id>` against canonical enabled `targets[].id`.
363
- - Unknown id -> fail closed `REMOTE_TARGET_UNKNOWN`.
364
- - Known but disabled id -> fail closed `REMOTE_TARGET_DISABLED`.
365
-
366
- Routing precedence when profile is enabled:
367
-
368
- 1. Explicit NL intent target (`start container <target_id>`).
369
- 2. Canonical target validation (`targets[].id`, enabled state).
370
- 3. Heuristic fallback (documented file-class matrix).
371
- 4. Local default when no remote target is selected.
372
-
373
- Fail-closed reason codes (locked by `architecture.md` `# US-0086`):
374
-
375
- - `REMOTE_AUTOMATION_MODE_OFF`
376
- - `REMOTE_TARGET_UNKNOWN`
377
- - `REMOTE_TARGET_DISABLED`
378
- - `REMOTE_TARGET_UNROUTABLE`
379
-
380
- Evidence tuple contract for execute/qa/release handoffs and `state.md`:
381
-
382
- - `target_id`
383
- - `environment_label`
384
- - `automation_profile`
385
- - `routing_source` (`explicit_intent|heuristic_fallback|local_default`)
386
- - `secret_surface=names_only`
387
-
388
- Security continuity:
389
-
390
- - Automation must not read `.env` directly.
391
- - Output remains names-only; do not print secret values in logs, handoffs, or
392
- state artifacts.
393
-
394
- ## Canonical status contract (US-0045)
395
-
396
- - Story status authority is `docs/product/backlog.md` only.
397
- - `docs/product/acceptance.md` and `docs/engineering/state.md` are derived views.
398
- - `/auto` must not infer implementation readiness from non-canonical status
399
- artifacts when they conflict with backlog status.
400
-
401
- ## Outputs (artifacts)
402
- - Updated phase artifacts for each step
403
- - `docs/engineering/state.md`
404
- - `handoffs/resume_brief.md` if stopped
405
- - `sprints/S0001/qa-findings.md` and `handoffs/qa_to_dev.md` when loop finds issues
406
- - Deterministic continuation breadcrumbs in relevant artifacts
407
-
408
- ## Stop conditions
409
-
410
- Deterministic stop reasons for continuous and looping runs (aligned with
411
- **Deterministic stop matrix (US-0088)** above):
412
-
413
- - `completed` — all intersected phases finished; segment done.
414
- - `decision_gate` — decision gate triggered; non-suppressible.
415
- - `missing_input` — missing critical input; non-suppressible.
416
- - `pause_request` — `AUTO_PAUSE_REQUEST=1` reached at a safe boundary; non-suppressible.
417
- - `loop_max` — `AUTO_LOOP_MAX_CYCLES` reached with unresolved defects; non-suppressible.
418
- - `error` — runtime or configuration error; non-suppressible.
419
- - `blocked` — sync/scope gate or external blocker; non-suppressible.
420
-
421
- ## Optional backlog-drain mode (US-0044 / DEC-0022)
422
-
423
- `/auto` supports an optional multi-story backlog-drain mode. Default behavior
424
- remains unchanged unless explicitly enabled.
425
-
426
- Canonical controls from `.cursor/scratchpad.md`:
427
- - `AUTO_BACKLOG_DRAIN`: `0|1` (default `0`)
428
- - `AUTO_BACKLOG_MAX_STORIES`: integer `>=1` (default `1`)
429
- - `AUTO_BACKLOG_ON_BLOCK`: `stop|skip` (default `stop`)
430
- - `AUTO_STORY_SELECTION`: `priority_then_backlog_order` (default)
431
-
432
- Deterministic behavior when enabled (`AUTO_BACKLOG_DRAIN=1`):
433
- - Select next eligible OPEN story via `AUTO_STORY_SELECTION`.
434
- - **Advance through multiple phases** of the resolved lifecycle per story
435
- (**reference Step 5**) — the orchestrator does not stop after one phase
436
- unless a deterministic stop condition fires (see **Deterministic stop matrix
437
- (US-0088)**).
438
- - After each story's terminal boundary (`refresh-context` completion or policy
439
- stop), **recompute the materialized phase plan** by reloading merged
440
- scratchpad phase-selection inputs at the story boundary (**US-0044** /
441
- **US-0088**). The next eligible OPEN story starts with a fresh plan class —
442
- no silent revival of omitted phases from the prior story's plan.
443
- - Continue to next eligible OPEN story until:
444
- - `AUTO_BACKLOG_MAX_STORIES` limit reached (`BACKLOG_MAX_STORIES_REACHED`), or
445
- - no eligible stories remain, or
446
- - stop condition / decision gate occurs.
447
- - On blocked story:
448
- - `AUTO_BACKLOG_ON_BLOCK=stop` → stop immediately.
449
- - `AUTO_BACKLOG_ON_BLOCK=skip` → record skip reason and continue to next story.
450
- - Track `backlog_drain_stories_remaining_budget` across boundaries; notify
451
- operator on segment handoff / drain advance (non-routine, non-suppressible
452
- even when `AUTO_QUIET=1`).
453
-
454
- Default-safe behavior:
455
- - With `AUTO_BACKLOG_DRAIN=0`, preserve existing single-segment continuation.
456
-
457
- ## Optional bug-queue mode (US-0087)
458
-
459
- `/auto` supports an optional, **default-off** bug-queue scheduler for **OPEN**
460
- defects in **`docs/product/backlog.md`** **`## Bug issues (canonical)`**,
461
- orthogonal to story-only **`AUTO_BACKLOG_DRAIN`** (**`US-0044`** / **`DEC-0022`**).
462
- Bug-queue mode is **spawn-only** — same **`AUTO_ORCHESTRATOR_PHASE_EXECUTION`**
463
- contract as other phases (**`BUG-0006`**, **`US-0069`** / **`DEC-0051`**).
464
-
465
- ### Canonical argv literals (AC-1)
466
-
467
- Exact tokens (**no aliases** in v1; contract-tested):
468
-
469
- - **`bug-target=BUG-####`** — single **OPEN** bug (example: **`bug-target=BUG-0007`**).
470
- - **`bug-target=all-open`** — deterministic **OPEN**-only queue.
471
-
472
- ### Scratchpad keys (merged; `template/` parity)
473
-
474
- Default-off when unset (see **`architecture.md`** **`# US-0087`**):
475
-
476
- - **`AUTO_BUG_QUEUE`**: `0|1`
477
- - **`AUTO_BUG_TARGET`**: `all-open` | **`BUG-####`** — required when **`AUTO_BUG_QUEUE=1`**
478
- unless **`bug-target=`** argv supplies the target for this invocation.
479
- - **`AUTO_BUG_MAX_ITEMS`**: non-negative integer — optional cap on bugs consumed per
480
- orchestrator run for **`all-open`**; **`0`** or unset = no cap beyond queue length.
481
- - **`AUTO_BUG_ON_BLOCK`**: `stop|skip` — queue behavior when a bug segment stops at a
482
- pause/stop boundary.
483
-
484
- ### Scheduler mutex and argv precedence (AC-3)
485
-
486
- **One active scheduler** per materialized run:
487
-
488
- - If merged scratchpad has **`AUTO_BACKLOG_DRAIN=1`** **and** **`AUTO_BUG_QUEUE=1`**
489
- **and** this invocation has **no** explicit **`bug-target=`** argv token → fail
490
- closed with **`[AUTO_RESUME_ERROR] AUTO_SCHEDULER_CONFLICT: ...`**.
491
- - When **`bug-target=`** argv is present, it **selects** the bug scheduler for this
492
- run; **`AUTO_BACKLOG_DRAIN`** must **not** drive story selection for the same
493
- materialized run (story drain keys ignored for scheduler selection; record
494
- **`backlog_drain_active=false`**, **`bug_queue_active=true`** in **AC-10** for
495
- that run).
496
-
497
- **Parsing order** before nominal resume resolution: **`start-from`** → **`bug-target=`**
498
- argv → merged scratchpad (**`AUTO_BACKLOG_DRAIN`**, **`AUTO_BUG_*`**) →
499
- **`resume_brief.md`** → **`state.md`** fallback (**`architecture.md`** **`# US-0087`**).
500
-
501
- ### OPEN queue semantics (AC-4)
502
-
503
- - **OPEN** rows only in the canonical bug section — exclude **DONE** and non-matching ids.
504
- - **Ordering**: ascending **numeric** sort on **`BUG-####`** (stable document-order
505
- tie-break if needed).
506
- - **`AUTO_BUG_MAX_ITEMS`**: when set to positive integer *N*, consume at most *N*
507
- bugs from the head of the ordered queue this run; record **`bug_queue_remaining`**
508
- for operator visibility.
509
- - **Empty queue** when **`bug-target=all-open`** (or equivalent) and zero **OPEN**
510
- bugs → **`[AUTO_RESUME_ERROR] AUTO_BUG_QUEUE_EMPTY: ...`** (or equivalent
511
- deterministic envelope).
512
-
513
- ### Fail-closed reason codes (AC-1, AC-4, AC-8)
514
-
515
- | Code | When |
516
- |------|------|
517
- | **`AUTO_BUG_QUEUE_EMPTY`** | **`all-open`** and zero **OPEN** bugs. |
518
- | **`AUTO_BUG_TARGET_UNKNOWN`** | Malformed id / pattern, or id missing from canonical bug section. |
519
- | **`AUTO_BUG_TARGET_NOT_OPEN`** | Known id, status not **OPEN**. |
520
- | **`AUTO_SCHEDULER_CONFLICT`** | **`AUTO_BACKLOG_DRAIN=1`** ∧ **`AUTO_BUG_QUEUE=1`** without **`bug-target=`** argv. |
521
-
522
- Do **not** overload **`PHASE_POLICY_CONFLICT`** or backlog-drain codes for these.
523
-
524
- ### Bug segment fields: `resume_brief.md` + `state.md` (`DEC-0069` / AC-5)
525
-
526
- Default: **paired** refresh at segment boundaries — update **`handoffs/resume_brief.md`**
527
- **and** append **`docs/engineering/state.md`** breadcrumbs together so continuation
528
- without **`start-from`** avoids false **`RESUME_BRIEF_STALE`**.
529
-
530
- | Field | Purpose |
531
- |-------|---------|
532
- | **`bug_id`** | Active **`BUG-####`** for this segment (**OPEN**), or **`(none)`**. |
533
- | **`bug_queue_position`** | 1-based index into **OPEN** ordering for **`all-open`**; else **`(none)`**. |
534
- | **`bug_queue_remaining`** | Count of **OPEN** bugs after current position; **`(none)`** when not queue-scoped. |
535
- | **`intended_resume_phase`** | Next phase for this segment (align with **`next_scheduled_phase`** on `state.md`). |
536
-
537
- Mirror the **AC-10** tuple (`segment_work_item_kind`, `active_bug_id`,
538
- `backlog_drain_active`, `bug_queue_active`, etc.) in both surfaces per
539
- **`architecture.md`** **`# US-0087`**.
540
-
541
- ## Optional bulk execute mode (US-0047 / DEC-0024)
542
-
543
- `/auto` supports an explicit bulk execute orchestration mode for continuous
544
- planned-item delivery. Default behavior remains unchanged unless explicitly
545
- enabled.
546
-
547
- Canonical controls from `.cursor/scratchpad.md`:
548
- - `AUTO_EXECUTE_BULK`: `0|1` (default `0`)
549
- - `AUTO_EXECUTE_MAX_ITEMS`: integer `>=1` (default `1`)
550
- - `AUTO_EXECUTE_ON_BLOCK`: `stop|skip` (default `stop`)
551
- - `AUTO_EXECUTE_SELECTION`: `planned_then_priority` (default)
552
- - `AUTO_TEAM_SCOPE_ENFORCE`: `0|1` (default `1`)
553
-
554
- Explicit activation contract:
555
- - Bulk execute mode is activated when either:
556
- - explicit argument `--execute-bulk` is present for this run, or
557
- - `AUTO_EXECUTE_BULK=1` in scratchpad.
558
- - Without explicit activation, preserve current non-bulk continuation behavior.
559
-
560
- Deterministic behavior when enabled:
561
- - Select next eligible planned work item via `AUTO_EXECUTE_SELECTION`.
562
- - Process each item with strict isolation:
563
- - fresh subagent per phase boundary
564
- - fresh subagent per execute<->QA loop cycle
565
- - Apply bounded stop criteria:
566
- - stop at `AUTO_EXECUTE_MAX_ITEMS`, or
567
- - stop/skip on blocked item per policy, or
568
- - stop when no eligible items remain.
569
-
570
- Team mode guardrails (`TEAM_MODE=1`):
571
- - Snapshot and record team context inputs:
572
- - `TEAM_MODE`, `TEAM_MEMBER`, `ACTIVE_TASK_IDS`
573
- - If `AUTO_TEAM_SCOPE_ENFORCE=1`, only tasks in current member scope are
574
- executable.
575
- - Out-of-scope tasks must be deterministically handled with no writes:
576
- - `stop` policy -> `EXEC_TEAM_SCOPE_BLOCKED`
577
- - `skip` policy -> `EXEC_TEAM_SCOPE_SKIPPED`
578
-
579
- ## Sync policy contract (US-0038 / DEC-0018)
580
-
581
- `/auto` may evaluate sync eligibility only at phase-completion boundaries.
582
- It remains process-level guidance (no runtime git orchestrator changes).
583
-
584
- Canonical policy controls from `.cursor/scratchpad.md`:
585
- - `SYNC_POLICY_MODE`:
586
- `disabled|manual|by_phase|by_milestone|custom_phase_list`
587
- - `SYNC_CUSTOM_PHASES`: comma-separated canonical phase IDs for
588
- `custom_phase_list` mode
589
- - `ALLOW_AUTO_PUSH`: `0|1`
590
- - `AUTO_PUSH_BRANCH_ALLOWLIST`: comma-separated branches/patterns
591
-
592
- Deterministic policy semantics:
593
- - `disabled`: skip sync evaluation entirely (`SYNC_DISABLED`).
594
- - `manual`: no auto-sync attempts (`MANUAL_MODE_NO_AUTO`).
595
- - `by_phase`: evaluate at every phase completion boundary.
596
- - `by_milestone`: evaluate only at milestone completion boundary.
597
- - `custom_phase_list`: evaluate only when completed phase is listed.
598
- - Unset/invalid mode fails closed to `manual`.
599
-
600
- Guarded auto-push eligibility chain (all required):
601
- 1. Boundary is eligible for configured mode.
602
- 2. `ALLOW_AUTO_PUSH=1`.
603
- 3. QA-first safety passes (feature work cannot auto-push before QA pass;
604
- manual user-invoked sync remains allowed).
605
- 4. No unresolved blocking QA findings / critical unresolved issues.
606
- 5. Branch safety passes: protected/default branches are denied by default unless
607
- explicitly allowlisted.
608
- 6. Mandatory pre-push checks pass:
609
- - `TEST_COMMAND` is required
610
- - optional `LINT_COMMAND` / `TYPECHECK_COMMAND` run only when configured
611
- - failures or timeout result in `no_push`
612
-
613
- If any condition fails, verdict is deterministic `no_push` with reason code.
614
-
615
- Reason-code baseline:
616
- - `SYNC_DISABLED`
617
- - `MANUAL_MODE_NO_AUTO`
618
- - `SYNC_TRIGGER_NOT_ELIGIBLE`
619
- - `AUTO_PUSH_NOT_ENABLED`
620
- - `PRE_QA_AUTOPUSH_FORBIDDEN`
621
- - `BLOCKING_QA_FINDINGS`
622
- - `BRANCH_NOT_ALLOWLISTED`
623
- - `TEST_COMMAND_MISSING`
624
- - `TEST_FAILED`
625
- - `TEST_TIMEOUT`
626
- - `OPTIONAL_CHECK_FAILED`
627
- - `SYNC_PUSHED`
628
- - `BACKLOG_DRAIN_DISABLED`
629
- - `BACKLOG_STORY_BLOCKED_STOP`
630
- - `BACKLOG_STORY_BLOCKED_SKIPPED`
631
- - `BACKLOG_MAX_STORIES_REACHED`
632
- - `BACKLOG_NO_ELIGIBLE_STORIES`
633
- - `EXEC_BULK_DISABLED`
634
- - `EXEC_BULK_ITEM_BLOCKED_STOP`
635
- - `EXEC_BULK_ITEM_BLOCKED_SKIPPED`
636
- - `EXEC_BULK_MAX_ITEMS_REACHED`
637
- - `EXEC_BULK_NO_ELIGIBLE_ITEMS`
638
- - `EXEC_TEAM_SCOPE_BLOCKED`
639
- - `EXEC_TEAM_SCOPE_SKIPPED`
640
- - `RUNTIME_PROOF_MISSING`
641
- - `RUNTIME_PROOF_INVALID`
642
- - `RUNTIME_PROOF_REUSED`
643
- - `RUNTIME_PROOF_STALE`
644
- - `RUNTIME_PROOF_AMBIGUOUS_LINK`
645
- - `PHASE_ROLE_CAPABILITY_MISSING`
646
- - `PHASE_ROLE_MISMATCH`
647
- - `PHASE_POLICY_CONFLICT`
648
- - `PHASE_PLAN_UNKNOWN_PHASE`
649
- - `PHASE_PLAN_EMPTY_INCLUDE`
650
- - `PHASE_PLAN_UNKNOWN_PROFILE`
651
- - `PHASE_PLAN_INVALID_AUTO_PHASE_PLAN`
652
- - `PHASE_PLAN_HIGH_RISK_ACK_REQUIRED`
653
- - `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`
654
-
655
- ## Canonical `start-from` contract
656
-
657
- - Accepted canonical phase IDs:
658
- - `intake`
659
- - `discovery`
660
- - `research`
661
- - `architecture`
662
- - `sprint-plan`
663
- - `plan-verify`
664
- - `execute`
665
- - `qa`
666
- - `verify-work`
667
- - `release`
668
- - `refresh-context`
669
- - Only canonical IDs are accepted. Alias values (for example `sprint_plan`,
670
- `verifywork`) are invalid and must fail fast.
671
-
672
- ## Deterministic resume-source precedence
673
-
674
- Resolve nominal start phase and scheduler inputs in strict order (**`US-0087`**
675
- extends ordering vs legacy two-step resume):
676
-
677
- 1. Explicit `/auto start-from=<phase>`
678
- 2. Explicit **`bug-target=`** argv token when present (`bug-target=BUG-####` or
679
- `bug-target=all-open`) — parsed **before** merged scratchpad scheduler keys;
680
- selects bug scheduler for this run when applicable.
681
- 3. Merged scratchpad (**`US-0073`** / **`DEC-0055`**) — `AUTO_BACKLOG_DRAIN`,
682
- **`AUTO_BUG_QUEUE`**, **`AUTO_BUG_TARGET`**, related flags.
683
- 4. `handoffs/resume_brief.md`
684
- 5. Conservative `docs/engineering/state.md` fallback
685
- 6. Fail fast on ambiguity/conflict/unrecoverable inputs (including
686
- **`AUTO_SCHEDULER_CONFLICT`** when **`AUTO_BACKLOG_DRAIN=1`** ∧
687
- **`AUTO_BUG_QUEUE=1`** without **`bug-target=`** argv).
688
-
689
- Deterministic precedence behavior:
690
- - If explicit `start-from` is valid, it wins for the **nominal start phase** anchor;
691
- scheduler mutex (**`AUTO_SCHEDULER_CONFLICT`**) is still evaluated when scratchpad
692
- enables both drains without **`bug-target=`** argv resolution.
693
- - **`bug-target=`** argv when present overrides conflicting scratchpad scheduler
694
- selection for **this** run (bug queue active; story drain inactive for scheduling).
695
- - `state.md` fallback applies only per the ordered chain above when higher-priority
696
- sources do not supply a trustworthy anchor.
697
- - If `resume_brief.md` is present but stale or unparseable, fail fast instead
698
- of silently falling back.
699
-
700
- ## Conflict and stale/unparseable policy
701
-
702
- - Explicit valid override always wins and is logged as override.
703
- - **`AUTO_BACKLOG_DRAIN=1`** and **`AUTO_BUG_QUEUE=1`** together without explicit
704
- **`bug-target=`** argv → **`AUTO_SCHEDULER_CONFLICT`** (fail fast; do not pick a
705
- silent default scheduler).
706
- - No override + `resume_brief` conflicts with `state` inference: fail fast.
707
- - `resume_brief` exists but stale: fail fast.
708
- - `resume_brief` exists but unparseable: fail fast.
709
- - `state` fallback yields multiple candidate phases: fail fast.
710
- - `state` fallback yields no trustworthy boundary: fail fast.
711
-
712
- ## Fail-fast error code contract
713
-
714
- All resume-resolution failures must use:
715
-
716
- `[AUTO_RESUME_ERROR] <code>: <summary>. Source=<source>. Fix: <action>.`
717
-
718
- Required codes:
719
- - `INVALID_START_FROM`
720
- - `RESUME_BRIEF_MISSING`
721
- - `RESUME_BRIEF_STALE`
722
- - `RESUME_BRIEF_UNPARSEABLE`
723
- - `RESUME_STATE_CONFLICT`
724
- - `STATE_PHASE_AMBIGUOUS`
725
- - `STATE_PHASE_UNRECOVERABLE`
726
-
727
- Bug-queue extensions (**`US-0087`**; use the same **`[AUTO_RESUME_ERROR]`** envelope
728
- for resolver/materialization failures):
729
-
730
- - `AUTO_SCHEDULER_CONFLICT`
731
- - `AUTO_BUG_QUEUE_EMPTY`
732
- - `AUTO_BUG_TARGET_UNKNOWN`
733
- - `AUTO_BUG_TARGET_NOT_OPEN`
734
-
735
- ## Continuous multi-phase execution (US-0088)
736
-
737
- A single `/auto` orchestrated run (or a **documented equivalent outer driver** —
738
- see **AC-1 equivalence** below) advances through **all phases** in the
739
- **intersected resolved schedule** (**Step 5** below — cross-anchor:
740
- **"reference Step 5"**) until a **deterministic stop condition** fires. The
741
- orchestrator does **not** stop after spawning one phase unless the stop matrix
742
- requires it.
743
-
744
- ### Outer-driver equivalence (AC-1, Option B)
745
-
746
- When a single Cursor `/auto` invocation cannot schedule multiple fresh subagent
747
- turns (product/runtime constraint), a **documented outer driver** (operator
748
- script or manual re-invocation with `start-from` / refreshed `resume_brief`) is
749
- **deterministically equivalent** provided all of the following hold:
750
-
751
- - Same intersected phase order as a single-invocation run.
752
- - Same per-phase isolation evidence (**DEC-0029**) + strict-proof attestation
753
- (**DEC-0038**).
754
- - Same deterministic stop reasons and stop matrix evaluation.
755
- - Same `resume_brief` + `state.md` refresh at every materialized phase boundary.
756
- - Operators must follow the runbook recipe
757
- (**`docs/engineering/runbook.md`** § Continuous `/auto` + backlog drain).
758
-
759
- ### Deterministic stop matrix (US-0088)
760
-
761
- | Condition | Behavior | Operator notify (AC-2) |
762
- |-----------|----------|------------------------|
763
- | Next phase exists, no hard stop | **Continue** — preflight US-0069, spawn next phase | Quiet OK when `AUTO_QUIET=1` |
764
- | `decision_gate` | **Stop** until resolved | **Always** (non-suppressible) |
765
- | `error` / missing critical input | **Stop** | **Always** (non-suppressible) |
766
- | `AUTO_PAUSE_REQUEST` / `pause` | **Stop** at safe boundary | **Always** (non-suppressible) |
767
- | `AUTO_LOOP_MAX_CYCLES` / `loop_max` | **Stop** | **Always** (non-suppressible) |
768
- | `blocked` (sync/scope gate) | **Stop** | **Always** (non-suppressible) |
769
- | US lifecycle DONE / sprint segment complete | **Stop** segment; `AUTO_BACKLOG_DRAIN=1` may advance to next OPEN story (recompute phase plan — **Step 5**) | Notify on segment handoff (non-routine) |
770
- | `BACKLOG_MAX_STORIES_REACHED` | **Stop** | **Always** (non-suppressible) |
771
-
772
- `stop_reason` vocabulary: `completed`, `decision_gate`, `missing_input`,
773
- `pause_request`, `loop_max`, `error`, `blocked`.
774
-
775
- ### `AUTO_QUIET` vs `TOKEN_PROFILE` (US-0088 / AC-2)
776
-
777
- | Key | Values | Role |
778
- |-----|--------|------|
779
- | `AUTO_QUIET` | `0` \| `1` (default `0`) | `1` = suppress routine per-phase success chatter; must **not** suppress `decision_gate`, errors, pause, `loop_max`, `blocked`, or missing inputs. |
780
- | `TOKEN_PROFILE` | `lean` \| `balanced` \| `full` | Unchanged — **DEC-0035** / **US-0080**; **orthogonal** to `AUTO_QUIET`. |
781
-
782
- ## Steps
783
- 1. Read automation flags from merged scratchpad and **materialize the resolved
784
- phase plan** per **Configurable phase selection policy (US-0070 / DEC-0052)**:
785
- detect exactly-one policy mode, expand, apply non-skippable reinstatement,
786
- validate tokens/profile/ack requirements, and append plan breadcrumbs
787
- (`phase_policy_mode`, `resolved_phase_plan`, `skipped_phases` + reasons) to
788
- `docs/engineering/state.md` **before** any phase spawn. On failure, emit
789
- deterministic phase-plan reason codes and stop (no partial schedule).
790
- 2. Parse optional `start-from=<phase>` and validate canonical phase ID rules.
791
- Parse optional **`bug-target=`** argv literals (**`US-0087`**) and evaluate
792
- **scheduler mutex** (`AUTO_SCHEDULER_CONFLICT` when **`AUTO_BACKLOG_DRAIN=1`**
793
- **`AUTO_BUG_QUEUE=1`** without **`bug-target=`** argv).
794
- Parse optional `--execute-bulk` and treat it as explicit one-run override.
795
- 3. Resolve **nominal** start phase using deterministic precedence:
796
- - explicit `start-from` **`bug-target=`** argv (when present) merged scratchpad
797
- resume brief state fallback fail-fast.
798
- - Emit `[AUTO_RESUME_ERROR] ...` message on resolver failure.
799
- 3a. **Intersect** the nominal start anchor with the resolved phase plan (plan
800
- order preserved; drop scheduled phases strictly before the anchor in canonical
801
- order). **Empty intersection** → fail fast with
802
- `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION` and diagnostics listing
803
- `resolved_phase_plan` vs `requested_start_phase` / inferred resume anchor.
804
- Set the executable schedule to this intersection.
805
- 4. Record continuation breadcrumb metadata in `docs/engineering/state.md`:
806
- - `invocation_mode=auto`
807
- - `requested_start_from`
808
- - `resolved_start_phase` (first phase of the intersected schedule)
809
- - `resolution_source` (`argument|resume_brief|state_fallback`)
810
- - `resolution_status` (`resolved|fail-fast`)
811
- - `timestamp`
812
- 5. **(reference Step 5continuous multi-phase spawn)** Spawn a fresh subagent
813
- for each remaining phase in **the intersected resolved schedule order** (not
814
- the full canonical list when phases are omitted), starting at
815
- `resolved_start_phase`, and **advance through all subsequent phases** until a
816
- **deterministic stop condition** fires (see **Deterministic stop matrix
817
- (US-0088)** above). The orchestrator does **not** stop after a single phase
818
- spawn unless the stop matrix requires it; outer-driver equivalence applies
819
- when a single invocation cannot schedule multiple subagent turns (see
820
- **Outer-driver equivalence (AC-1, Option B)** above):
821
- default full path:
822
- intake -> discovery -> research -> architecture -> sprint plan ->
823
- plan verify -> execute -> QA -> verify work -> release -> refresh context.
824
- If `SECURITY_REVIEW=1`, run `/security-review` in a fresh security subagent:
825
- - in `design` mode immediately after architecture and before sprint plan,
826
- - in `code` mode immediately after execute and before QA.
827
- If `SECURITY_REVIEW=0` (default), skip both checks with zero overhead.
828
- - If `AUTO_BACKLOG_DRAIN=1`, repeat story lifecycle for next eligible OPEN
829
- story using deterministic selection policy until bounded stop criteria.
830
- **Reload merged scratchpad phase-selection inputs and recompute the phase
831
- plan at each story boundary** (same policy class as single-segment runs).
832
- - If bug-queue mode is active (**`bug-target=`** argv or **`AUTO_BUG_QUEUE=1`**
833
- with resolved target), iterate **OPEN** bugs per **Optional bug-queue mode
834
- (US-0087)** ascending numeric **`BUG-####`** order, **`AUTO_BUG_MAX_ITEMS`**
835
- cap, **`AUTO_BUG_ON_BLOCK`** stop/skip running the same **resolved phase plan**
836
- per bug segment with fresh spawns only. **Reload scratchpad and revalidate
837
- mutex at each bug boundary.** Empty **OPEN** queue → **`AUTO_BUG_QUEUE_EMPTY`**.
838
- - If bulk execute mode is active (`--execute-bulk` or
839
- `AUTO_EXECUTE_BULK=1`), iterate eligible planned items using
840
- `AUTO_EXECUTE_SELECTION` with bounded item count
841
- (`AUTO_EXECUTE_MAX_ITEMS`) and deterministic block/skip semantics.
842
- **Reload merged scratchpad phase-selection inputs and recompute the phase
843
- plan at each item boundary** (no silent revival of omitted phases).
844
- - In team mode with enforcement enabled, run pre-mutation scope checks against
845
- `TEAM_MEMBER` and `ACTIVE_TASK_IDS`; out-of-scope tasks produce deterministic
846
- reason codes and no writes.
847
- - **US-0069 / DEC-0051**: Before each phase spawn, resolve the single-valued
848
- expected role (matrix + `AUTO_ROLE_RESEARCH`, `AUTO_ROLE_PLAN_VERIFY`,
849
- `AUTO_ROLE_REFRESH_CONTEXT`), enforce execute default deny / override
850
- contract, and run the preflight capability gate; on failure stop with
851
- `PHASE_ROLE_CAPABILITY_MISSING` (no unrelated-role spawn).
852
- - **US-0069 / DEC-0051**: After each phase completes, validate isolation
853
- `role` and strict-proof `role` against the preflight-resolved expected
854
- role; on conflict stop with `PHASE_ROLE_MISMATCH`.
855
- 6. Pass only the phase input files and current objective to each spawned
856
- subagent. Do not pass prior conversational reasoning as phase context.
857
- 7. If `AUTO_IMPLEMENTATION_LOOP=1`, alternate fresh subagents for execute and QA
858
- (`dev`, then `qa`, then new `dev`, then new `qa`) until no blocking findings
859
- or `AUTO_LOOP_MAX_CYCLES` is reached.
860
- - After each cycle, verify that both phases wrote new isolation evidence
861
- entries (distinct `fresh_context_marker` per phase per cycle).
862
- 8. If `AUTO_PAUSE_REQUEST=1`, stop at the next safe boundary
863
- (`AUTO_PAUSE_POLICY`) and spawn `/pause` in a fresh curator subagent.
864
- 9. Preserve existing stop conditions and gates without bypass:
865
- - decision gate
866
- - missing critical input
867
- - pause request at safe boundary
868
- - loop max cycles reached
869
- 10. On stop (or completion), write breadcrumbs:
870
- - `stop_reason` (`completed|decision_gate|missing_input|pause_request|loop_max`)
871
- - `stop_phase`
872
- - `timestamp`
873
- 11. If stopped before completion, update `handoffs/resume_brief.md` with the
874
- intended next phase and stop metadata.
875
- 11a. At each phase boundary, verify isolation evidence exists for the completed
876
- phase in `docs/engineering/state.md` and includes all required fields. If
877
- missing/invalid/stale, stop with the appropriate reason code and remediation
878
- guidance (run the phase again in a fresh subagent context and write new
879
- evidence). Append **phase boundary status** per **Configurable phase
880
- selection policy (US-0070 / DEC-0052)** (selected/skipped summary + next
881
- scheduled phase).
882
- 11b. At each phase boundary, verify strict runtime attestation tuple exists and
883
- is valid for the completed phase (`orchestrator_run_id`,
884
- `runtime_proof_id`, `phase_id`, `role`, `proof_issued_at`,
885
- `proof_ttl_seconds`, `proof_hash`).
886
- - Missing tuple: `RUNTIME_PROOF_MISSING`
887
- - Invalid schema/hash/linkage: `RUNTIME_PROOF_INVALID`
888
- - Reused `runtime_proof_id`: `RUNTIME_PROOF_REUSED`
889
- - Expired proof TTL / stale proof: `RUNTIME_PROOF_STALE`
890
- - Ambiguous proof-to-checkpoint linkage: `RUNTIME_PROOF_AMBIGUOUS_LINK`
891
- - Remediation: rerun affected phase in fresh subagent context, write new
892
- strict-proof tuple + checkpoint evidence, then continue.
893
- 12. At each phase boundary, evaluate sync policy only when mode requires it and
894
- record a deterministic sync verdict entry with:
895
- - `phase_boundary`
896
- - `policy_mode`
897
- - `trigger_source` (`manual|auto`)
898
- - `branch`
899
- - `checks` (`test|lint|typecheck`: `pass|fail|skipped`)
900
- - `qa_status_snapshot`
901
- - `push_decision` (`pushed|blocked|not_eligible`)
902
- - `reason_code`
903
- - `evidence_refs`
904
- 13. When backlog-drain mode, bug-queue mode, or bulk execute mode is enabled,
905
- append per-item run summary entries:
906
- - `item_id`
907
- - `item_kind` (`story|sprint|bug`)
908
- - `story_id`
909
- - `bug_id` (when `item_kind=bug`)
910
- - `sprint_id`
911
- - `story_start_phase`
912
- - `story_stop_phase`
913
- - `story_outcome` (`released|blocked|skipped`)
914
- - `story_reason_code`
915
- - `team_context_snapshot` (`TEAM_MODE`, `TEAM_MEMBER`, `ACTIVE_TASK_IDS`)
916
- - `timestamp`
917
-
918
- ## Backward compatibility
919
-
920
- - Manual and interactive workflows remain unchanged by default.
921
- - `/resume` remains valid for context loading and guided continuation.
922
- - Deterministic precedence and fail-fast behavior apply when `/auto` continuation
923
- is invoked.
924
-
925
- ## Deterministic artifact ordering guard (US-0058 / DEC-0040)
926
-
927
- - When `/auto` coordinates phases that write mutable artifacts, each phase must
928
- follow `docs/engineering/artifact-ordering-policy.md`.
929
- - Ordering policies are mandatory:
930
- - `state.md`: append-bottom
931
- - `backlog.md` / `acceptance.md`: sorted-canonical
932
- - release/handoff surfaces: policy-specific (prepend/append) as documented.
933
- - If a required placement anchor is missing or ambiguous, fail closed with
934
- `ARTIFACT_ORDERING_ANCHOR_AMBIGUOUS` and do not continue.
1
+ # /auto — full orchestration specification (reference)
2
+
3
+ > **US-0080 / DEC-0062**: Expanded contract for `/auto`. The slim `.cursor/commands/auto.md` is the default injected surface; load this file when full prose, tables, and step detail are required.
4
+
5
+ ## Subagents
6
+ - curator
7
+ - tech-lead
8
+
9
+ ## Execution model
10
+ - `/auto` is a **spawn-only orchestrator**: it schedules materialization, spawns
11
+ fresh **phase-role** subagents, and verifies phase boundaries—it **must not**
12
+ execute lifecycle phase work, perform phase-role duties, or author **phase
13
+ deliverables** in the orchestrator context.
14
+ - For each phase, **spawn a fresh subagent** for that phase’s canonical role;
15
+ phase output must arrive only via artifacts and handoff files (no in-turn
16
+ orchestrator execution of that phase).
17
+ - Phase context transfer happens only through artifacts and handoff files.
18
+ - Scope is process/workflow orchestration only. Do not claim runtime product
19
+ orchestration changes.
20
+ - **Bug-queue mode** (**`US-0087`**) uses the same **spawn-only** model: schedule
21
+ materialization and spawn phase-role subagents per bug segment — **never** in-turn
22
+ **`execute`**, **`qa`**, or other lifecycle work in the orchestrator context.
23
+ Missing spawn → **`AUTO_ORCHESTRATOR_PHASE_EXECUTION`** (**`BUG-0006`**,
24
+ **`US-0069`**, **`DEC-0051`**).
25
+
26
+ ## Spawn-boundary integrity (BUG-0006 / US-0080)
27
+
28
+ This gate is **orthogonal** to per-phase isolation (**DEC-0029**, see
29
+ `decisions/DEC-0029.md`) and strict runtime proof (**DEC-0038**, see
30
+ `decisions/DEC-0038.md`): satisfying one does not excuse skipping the others.
31
+
32
+ - **Forbidden**: using the orchestrator context to **perform** a lifecycle phase
33
+ instead of **spawning** the required role subagent (for example in-turn
34
+ **`architecture`**, **`execute`**, or **`qa`** work attributed to the
35
+ orchestrator).
36
+ - **Fail fast** with **`AUTO_ORCHESTRATOR_PHASE_EXECUTION`**. **Remediation**:
37
+ stop; spawn a **fresh** subagent for the canonical **`phase_id`** and **`role`**
38
+ per the phase→role matrix (**DEC-0051**); continue only through artifacts and
39
+ handoffs. **Do not** overload **`PHASE_CONTEXT_ISOLATION_VIOLATION`** or
40
+ **`RUNTIME_PROOF_*`** for a spawn-boundary violation—those address wrong-writer
41
+ isolation breaks and attestation failures, not missing spawn.
42
+
43
+ ## Per-phase isolation enforcement (US-0048 / DEC-0029)
44
+
45
+ `/auto` must enforce fresh-context isolation as a fail-closed contract:
46
+
47
+ - `/auto` must not write phase deliverables itself. If phase work is performed in
48
+ the orchestrator context, stop immediately with reason code
49
+ `PHASE_CONTEXT_ISOLATION_VIOLATION`.
50
+ - Each spawned phase must write isolation evidence with required fields
51
+ (`phase_id`, `role`, `fresh_context_marker`, `timestamp`, `evidence_ref`) to
52
+ the canonical evidence store (`docs/engineering/state.md`) before `/auto`
53
+ proceeds to the next phase.
54
+ - `/auto` must fail closed when evidence is missing/invalid/stale (see reason
55
+ codes below). No silent continuation.
56
+
57
+ Reason codes (deterministic):
58
+ - `PHASE_CONTEXT_ISOLATION_MISSING`
59
+ - `PHASE_CONTEXT_ISOLATION_VIOLATION`
60
+ - `ISOLATION_EVIDENCE_STALE`
61
+ - `ISOLATION_EVIDENCE_INVALID`
62
+
63
+ ## Strict runtime proof enforcement (US-0056 / DEC-0038)
64
+
65
+ `/auto` must enforce strict runtime attestation in addition to artifact-level
66
+ isolation evidence:
67
+
68
+ - Each completed phase must provide a runtime attestation tuple linked to the
69
+ phase checkpoint evidence:
70
+ - `orchestrator_run_id`
71
+ - `runtime_proof_id`
72
+ - `phase_id`
73
+ - `role`
74
+ - `proof_issued_at` (ISO UTC / RFC3339)
75
+ - `proof_ttl_seconds`
76
+ - `proof_hash`
77
+ - `runtime_proof_id` must be unique per phase run; reused proof IDs are invalid.
78
+ - Proof freshness must be validated against `proof_issued_at` + TTL policy.
79
+ - Proof linkage must be deterministic and auditable to checkpoint evidence refs.
80
+ - Fail closed on any strict-proof violation; no silent continuation.
81
+
82
+ Strict-proof reason codes:
83
+ - `RUNTIME_PROOF_MISSING`
84
+ - `RUNTIME_PROOF_INVALID`
85
+ - `RUNTIME_PROOF_REUSED`
86
+ - `RUNTIME_PROOF_STALE`
87
+ - `RUNTIME_PROOF_AMBIGUOUS_LINK`
88
+
89
+ ## Strict phase role enforcement (US-0069 / DEC-0051)
90
+
91
+ `/auto` must enforce a deterministic **phase→role contract** with **preflight
92
+ admission** before each phase spawn, **fail-closed checkpoint validation** after
93
+ each phase completes, and **aligned strict-proof `role`** values. Post-hoc
94
+ isolation markers alone are insufficient.
95
+
96
+ ### Canonical phase→role matrix (fixed defaults)
97
+
98
+ | phase_id | Allowed roles | Default when no valid alternate policy |
99
+ |----------|-----------------|----------------------------------------|
100
+ | `intake` | `po` | `po` |
101
+ | `discovery` | `po` | `po` |
102
+ | `research` | `po`, `tech-lead` | `tech-lead` |
103
+ | `architecture` | `tech-lead` | `tech-lead` |
104
+ | `sprint-plan` | `tech-lead` | `tech-lead` |
105
+ | `plan-verify` | `qa`, `tech-lead` | `qa` |
106
+ | `execute` | `dev` (override path only) | `dev` |
107
+ | `qa` | `qa` | `qa` |
108
+ | `verify-work` | `qa` | `qa` |
109
+ | `release` | `release` | `release` |
110
+ | `refresh-context` | `curator`, `po` | `curator` |
111
+
112
+ ### Alternate-role scratchpad policy (single-valued resolution)
113
+
114
+ Resolve **exactly one** expected role for phases with alternates using merged
115
+ scratchpad (active + `.cursor/scratchpad.local.md`; template parity on install):
116
+
117
+ - `AUTO_ROLE_RESEARCH`: `po` \| `tech-lead` — when **unset or empty**, default
118
+ `tech-lead`; when set to any other value, fail closed with diagnostics (no
119
+ unrelated-role fallback).
120
+ - `AUTO_ROLE_PLAN_VERIFY`: `qa` \| `tech-lead` — when **unset or empty**,
121
+ default `qa`; otherwise only `qa` or `tech-lead` allowed (else fail closed).
122
+ - `AUTO_ROLE_REFRESH_CONTEXT`: `curator` \| `po` — when **unset or empty**,
123
+ default `curator`; otherwise only `curator` or `po` allowed (else fail closed).
124
+
125
+ ### Preflight capability gate (before spawn)
126
+
127
+ Before spawning phase work, `/auto` must:
128
+
129
+ 1. Resolve `phase_id` → expected canonical `role` (matrix + policy keys above).
130
+ 2. For `execute`, apply **default deny**: expected role is `dev` unless **both**
131
+ `AUTO_EXECUTE_ROLE_OVERRIDE=allowed_non_dev_execute` **and**
132
+ `EXECUTE_OVERRIDE_GOVERNANCE_REF` point to a **parseable** approved exception
133
+ record (for example `DEC-xxxx` or a documented anchor in
134
+ `docs/engineering/state.md`).
135
+ 3. Evaluate **role capability availability** for that boundary (subagent/tooling
136
+ can satisfy the resolved role).
137
+ 4. On missing capability: stop with `PHASE_ROLE_CAPABILITY_MISSING` including
138
+ `phase_id`, expected role, observed capability result, and remediation. **Do
139
+ not** spawn under a substitute unrelated role.
140
+
141
+ ### Post-completion boundary validation
142
+
143
+ When a phase completes, before advancing:
144
+
145
+ - Isolation evidence `role` must equal the **same** preflight-resolved expected
146
+ role for that `phase_id`. Else stop with `PHASE_ROLE_MISMATCH`.
147
+ - Strict-proof tuple `role` must equal isolation `role` and the expected role.
148
+ - `proof_hash` must be SHA-256 over canonical sorted-key JSON of
149
+ `orchestrator_run_id`, `runtime_proof_id`, `phase_id`, `role`,
150
+ `proof_issued_at`, `proof_ttl_seconds` (`DEC-0038` / architecture US-0069).
151
+
152
+ ### Resume / `start-from` parity
153
+
154
+ Every `/auto` invocation (explicit `start-from`, `resume_brief`, or conservative
155
+ `state.md` fallback) must **recompute** policy resolution and preflight from
156
+ scratch; stale continuation artifacts must not bypass the gate.
157
+
158
+ ### Role-enforcement reason codes (deterministic)
159
+
160
+ - `PHASE_ROLE_CAPABILITY_MISSING`
161
+ - `PHASE_ROLE_MISMATCH`
162
+
163
+ ## Configurable phase selection policy (US-0070 / DEC-0052)
164
+
165
+ `/auto` must treat the **resolved phase plan** as a first-class, fail-closed
166
+ schedule: a single ordered subset of canonical phases computed from merged
167
+ scratchpad (active + `.cursor/scratchpad.local.md`; template parity on install),
168
+ **before** resume/`start-from` intersection and **before** any phase spawn.
169
+
170
+ ### Canonical lifecycle order (baseline `full` plan)
171
+
172
+ Unless narrowed by policy, the canonical ordered phase list is:
173
+
174
+ `intake` → `discovery` → `research` → `architecture` → `sprint-plan` →
175
+ `plan-verify` → `execute` → `qa` → `verify-work` → `release` →
176
+ `refresh-context`
177
+
178
+ When `SECURITY_REVIEW=1`, insert `/security-review` in **design** mode
179
+ immediately after `architecture` and before `sprint-plan`, and in **code** mode
180
+ immediately after `execute` and before `qa`, as documented in **Steps** below.
181
+ Record these inserts in `resolved_phase_plan` breadcrumbs using the same
182
+ deterministic labels the orchestrator already uses for security boundaries.
183
+
184
+ ### Scratchpad selectors (exactly one active policy mode)
185
+
186
+ At most one of the following may be materially active after merge. If two or
187
+ more non-default selectors conflict, fail closed with `PHASE_POLICY_CONFLICT`
188
+ and **do not** materialize a plan:
189
+
190
+ - `AUTO_PHASE_PLAN=full` — full canonical lifecycle (including security-review
191
+ inserts when enabled). Default when unset and no other selector is set.
192
+ - `AUTO_PHASE_EXCLUDE=<csv>` — start from `full`, remove listed phase IDs
193
+ (validate each token; unknown id → `PHASE_PLAN_UNKNOWN_PHASE`).
194
+ - `AUTO_PHASE_INCLUDE=<csv>` — schedule **only** listed ids, then **re-sort**
195
+ into canonical lifecycle order. Unknown id → `PHASE_PLAN_UNKNOWN_PHASE`.
196
+ Empty result after parsing → `PHASE_PLAN_EMPTY_INCLUDE`.
197
+ - `AUTO_PHASE_PROFILE=<name>` — expand a **named profile** from the registry
198
+ below. Unknown profile → `PHASE_PLAN_UNKNOWN_PROFILE`.
199
+
200
+ **Conflict rule**: `AUTO_PHASE_PLAN` is default-only when it is unset, empty, or
201
+ exactly `full`. Any explicit non-`full` `AUTO_PHASE_PLAN` value is invalid
202
+ (fail closed with `PHASE_PLAN_INVALID_AUTO_PHASE_PLAN`) — use `INCLUDE` /
203
+ `EXCLUDE` / `PROFILE` instead.
204
+
205
+ ### Profile registry (baseline)
206
+
207
+ - `default` — equivalent to `full` (optional explicit alias; same behavior as
208
+ unset policy).
209
+
210
+ **High-risk profile sketch** (illustrative; `R-0049`): `profile_high_risk_dev_fast`
211
+ may only be selected when **both** hold: `AUTO_PHASE_PROFILE=profile_high_risk_dev_fast`
212
+ and `AUTO_PHASE_HIGH_RISK_ACK=<operator_token>` matches the profile spec
213
+ version documented in `decisions/DEC-0052.md` / research `R-0049`. Missing ack →
214
+ `PHASE_PLAN_HIGH_RISK_ACK_REQUIRED`. High-risk profiles may define **narrower**
215
+ reinstatement rules **only** as documented for that profile; default profile
216
+ behavior applies otherwise.
217
+
218
+ ### Plan materialization pipeline (evaluation order)
219
+
220
+ On every `/auto` entry (including resume, backlog-drain, bug-queue, bulk execute, and
221
+ team-mode runs), **recompute** from merged scratchpad:
222
+
223
+ 1. Parse merged scratchpad policy inputs for phase selection + `SECURITY_REVIEW`.
224
+ 2. Detect active policy mode; on conflict → `PHASE_POLICY_CONFLICT` (no plan).
225
+ 3. Expand mode to a **candidate** ordered phase list in canonical order.
226
+ 4. Apply **non-skippable reinstatement** for the **default profile** (and for
227
+ any profile that does not explicitly document a narrower exception with ack):
228
+ - **Safety gates**: always reinstate if removed: `qa`, `verify-work`,
229
+ `release`.
230
+ - **Evidence-chain closure**: if the candidate retains any phase from
231
+ `execute` onward (`execute`, optional `security-review-code`, `qa`,
232
+ `verify-work`, `release`, `refresh-context`), reinstate (if removed) the
233
+ contiguous canonical prefix from `intake` through `plan-verify` so later
234
+ gates retain valid upstream isolation + strict-proof chain semantics.
235
+ - When `SECURITY_REVIEW=1`, reinstate the corresponding `security-review-*`
236
+ insert when the adjacent retained phases would otherwise violate the
237
+ documented security boundary contract.
238
+ Record each reinstatement in breadcrumbs with reason `non_skippable_gate`
239
+ (or a more specific documented code).
240
+ 5. Record **operator-visible plan breadcrumbs** to `docs/engineering/state.md`
241
+ **before** first spawn (append-bottom per `DEC-0040`):
242
+ - `phase_policy_mode` (`full|exclude|include|profile`)
243
+ - `resolved_phase_plan` (ordered `phase_id` list)
244
+ - `skipped_phases` (id + reason: `policy_exclude`, `non_skippable_gate`,
245
+ `default_full_plan`, etc.)
246
+ - `orchestrator_run_id` (when known for this run)
247
+ 6. **Do not** silently revive phases omitted by policy on continuation: every
248
+ entry re-reads scratchpad bytes and recomputes the plan class.
249
+
250
+ ### `start-from` and resume intersection with the resolved plan
251
+
252
+ After computing the **resolved phase plan**, resolve the **nominal** start
253
+ phase using **Deterministic resume-source precedence** (explicit `start-from`
254
+ → **`bug-target=`** argv (when present) → merged scratchpad → `resume_brief` →
255
+ `state` fallback → fail-fast).
256
+
257
+ Then **intersect**:
258
+
259
+ - Keep phases that appear in the resolved plan **in plan order**, starting at
260
+ the first plan phase whose canonical position is **at or after** the nominal
261
+ anchor phase (canonical order matches the baseline list above, including
262
+ security inserts when enabled).
263
+ - If the intersection is empty, fail closed with
264
+ `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION` and diagnostics listing
265
+ `resolved_phase_plan` vs `requested_start_phase` / resume inference.
266
+
267
+ ### Compatibility with `US-0069` / `DEC-0051`
268
+
269
+ - Role resolution and preflight apply **only** to phases present in the
270
+ intersected schedule. Skipping `research` does **not** change the expected
271
+ role for `architecture` or any other retained phase.
272
+ - Skipped phases produce **no** spawn and **no** alternate-role substitution
273
+ for a different phase.
274
+
275
+ ### Phase-plan reason codes (deterministic)
276
+
277
+ Add to operator diagnostics and breadcrumb records:
278
+
279
+ - `PHASE_POLICY_CONFLICT`
280
+ - `PHASE_PLAN_UNKNOWN_PHASE`
281
+ - `PHASE_PLAN_EMPTY_INCLUDE`
282
+ - `PHASE_PLAN_UNKNOWN_PROFILE`
283
+ - `PHASE_PLAN_INVALID_AUTO_PHASE_PLAN`
284
+ - `PHASE_PLAN_HIGH_RISK_ACK_REQUIRED`
285
+ - `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`
286
+
287
+ ### Phase boundary operator visibility (AC-10)
288
+
289
+ At each phase boundary (after completing a scheduled phase), record a compact
290
+ **phase boundary status** entry (for example in `docs/engineering/state.md`
291
+ continuation breadcrumbs) including:
292
+
293
+ - `resolved_phase_plan` snapshot (or stable hash pointer to the run’s plan record)
294
+ - `skipped_phases` summary (id + reason code)
295
+ - `phase_boundary` (completed `phase_id`)
296
+ - `next_scheduled_phase` (or `none` when complete/stopped)
297
+
298
+ **`US-0087` bug-queue extensions** (when bug scheduler is active or segment is
299
+ bug-scoped; see **`architecture.md`** **`# US-0087`**):
300
+
301
+ - `segment_work_item_kind` (`story|bug`)
302
+ - `active_bug_id` (`BUG-####` or `(none)`)
303
+ - `bug_queue_position` (1-based into **OPEN** ordering for `all-open`, or `(none)`)
304
+ - `bug_queue_remaining` (integer or `(none)`)
305
+ - `backlog_drain_active` (boolean — story **`AUTO_BACKLOG_DRAIN`** drives **this** run)
306
+ - `bug_queue_active` (boolean — bug scheduler drives **this** run)
307
+
308
+ **Invariant**: `backlog_drain_active` and `bug_queue_active` must **not** both be
309
+ true for the same materialized run (scheduler mutex).
310
+
311
+ ## Inputs
312
+ - Merged scratchpad policy (`US-0073` / `DEC-0055`): resolve flags from **local >
313
+ materialized `.cursor/scratchpad.md` > `.cursor/scratchpad.local.example.md`**
314
+ (installers materialize baseline when missing; missing required keys after merge
315
+ must fail closed with `[SCRATCHPAD_MERGE_ERROR]` diagnostics, not silent defaults).
316
+ - `AUTO_FLOW_MODE` and `PHASE_MODE` from merged scratchpad
317
+ - `AUTO_IMPLEMENTATION_LOOP`, `AUTO_LOOP_MAX_CYCLES` from merged scratchpad
318
+ - `AUTO_PAUSE_REQUEST`, `AUTO_PAUSE_POLICY` from merged scratchpad
319
+ - `SECURITY_REVIEW`, `COMPLIANCE_PROFILES` from merged scratchpad
320
+ - `AUTO_EXECUTE_BULK`, `AUTO_EXECUTE_MAX_ITEMS`, `AUTO_EXECUTE_ON_BLOCK`,
321
+ `AUTO_EXECUTE_SELECTION`, `AUTO_TEAM_SCOPE_ENFORCE` from merged scratchpad
322
+ - `AUTO_ROLE_RESEARCH`, `AUTO_ROLE_PLAN_VERIFY`, `AUTO_ROLE_REFRESH_CONTEXT`,
323
+ `AUTO_EXECUTE_ROLE_OVERRIDE`, `EXECUTE_OVERRIDE_GOVERNANCE_REF` from merged
324
+ scratchpad (US-0069 / DEC-0051)
325
+ - `AUTO_PHASE_PLAN`, `AUTO_PHASE_EXCLUDE`, `AUTO_PHASE_INCLUDE`,
326
+ `AUTO_PHASE_PROFILE`, `AUTO_PHASE_HIGH_RISK_ACK` from merged scratchpad
327
+ (US-0070 / DEC-0052)
328
+ - `TEAM_MODE`, `TEAM_MEMBER`, `ACTIVE_TASK_IDS` from merged scratchpad context
329
+ - Current product and engineering docs
330
+ - Optional explicit argument: `start-from=<phase>`
331
+ - Optional explicit argument: **`bug-target=BUG-####`** or **`bug-target=all-open`**
332
+ (**`US-0087`**; parsed before merged scratchpad scheduler keys)
333
+ - Optional explicit argument: `--execute-bulk` (one-run explicit override)
334
+ - `AUTO_BUG_QUEUE`, `AUTO_BUG_TARGET`, `AUTO_BUG_MAX_ITEMS`, `AUTO_BUG_ON_BLOCK`
335
+ from merged scratchpad (**`US-0087`**)
336
+ - Resume-source artifacts:
337
+ - `handoffs/resume_brief.md`
338
+ - `docs/engineering/state.md`
339
+
340
+ ## Automation remote routing contract (US-0086)
341
+
342
+ This contract is deterministic and default-off. It composes with `US-0064`,
343
+ `DEC-0070`, `US-0085`, and `DEC-0071`.
344
+
345
+ Automation profile controls (merged scratchpad):
346
+
347
+ - `AUTO_REMOTE_AUTOMATION_PROFILE`: `off|deterministic_v1`
348
+ - `AUTO_REMOTE_ENVIRONMENT_LABEL`: `local|docker|ssh` (names-only evidence)
349
+ - `REMOTE_EXECUTION`: `0|1` (remote config validation gate from `US-0084`)
350
+ - `REMOTE_CONFIG`: canonical remote config path
351
+
352
+ Mode split:
353
+
354
+ - `AUTO_REMOTE_AUTOMATION_PROFILE=off` -> preserve manual/local behavior; no
355
+ silent remote reroute.
356
+ - `AUTO_REMOTE_AUTOMATION_PROFILE=deterministic_v1` -> routing policy may resolve
357
+ Docker/SSH/local targets for automation workflows.
358
+
359
+ NL intent resolution (v1 literal):
360
+
361
+ - Parse only the exact phrase `start container <target_id>`.
362
+ - Resolve `<target_id>` against canonical enabled `targets[].id`.
363
+ - Unknown id -> fail closed `REMOTE_TARGET_UNKNOWN`.
364
+ - Known but disabled id -> fail closed `REMOTE_TARGET_DISABLED`.
365
+
366
+ Routing precedence when profile is enabled:
367
+
368
+ 1. Explicit NL intent target (`start container <target_id>`).
369
+ 2. Canonical target validation (`targets[].id`, enabled state).
370
+ 3. Heuristic fallback (documented file-class matrix).
371
+ 4. Local default when no remote target is selected.
372
+
373
+ Fail-closed reason codes (locked by `architecture.md` `# US-0086`):
374
+
375
+ - `REMOTE_AUTOMATION_MODE_OFF`
376
+ - `REMOTE_TARGET_UNKNOWN`
377
+ - `REMOTE_TARGET_DISABLED`
378
+ - `REMOTE_TARGET_UNROUTABLE`
379
+
380
+ Evidence tuple contract for execute/qa/release handoffs and `state.md`:
381
+
382
+ - `target_id`
383
+ - `environment_label`
384
+ - `automation_profile`
385
+ - `routing_source` (`explicit_intent|heuristic_fallback|local_default`)
386
+ - `secret_surface=names_only`
387
+
388
+ Security continuity:
389
+
390
+ - Automation must not read `.env` directly.
391
+ - Output remains names-only; do not print secret values in logs, handoffs, or
392
+ state artifacts.
393
+
394
+ ## Canonical status contract (US-0045)
395
+
396
+ - Story status authority is `docs/product/backlog.md` only.
397
+ - `docs/product/acceptance.md` and `docs/engineering/state.md` are derived views.
398
+ - `/auto` must not infer implementation readiness from non-canonical status
399
+ artifacts when they conflict with backlog status.
400
+
401
+ ## Outputs (artifacts)
402
+ - Updated phase artifacts for each step
403
+ - `docs/engineering/state.md`
404
+ - `handoffs/resume_brief.md` if stopped
405
+ - `sprints/S0001/qa-findings.md` and `handoffs/qa_to_dev.md` when loop finds issues
406
+ - Deterministic continuation breadcrumbs in relevant artifacts
407
+
408
+ ## Stop conditions
409
+
410
+ Deterministic stop reasons for continuous and looping runs (aligned with
411
+ **Deterministic stop matrix (US-0088)** above):
412
+
413
+ - `completed` — all intersected phases finished; segment done.
414
+ - `decision_gate` — decision gate triggered; non-suppressible.
415
+ - `missing_input` — missing critical input; non-suppressible.
416
+ - `pause_request` — `AUTO_PAUSE_REQUEST=1` reached at a safe boundary; non-suppressible.
417
+ - `loop_max` — `AUTO_LOOP_MAX_CYCLES` reached with unresolved defects; non-suppressible.
418
+ - `error` — runtime or configuration error; non-suppressible.
419
+ - `blocked` — sync/scope gate or external blocker; non-suppressible.
420
+
421
+ ## Optional backlog-drain mode (US-0044 / DEC-0022)
422
+
423
+ `/auto` supports an optional multi-story backlog-drain mode. Default behavior
424
+ remains unchanged unless explicitly enabled.
425
+
426
+ Canonical controls from `.cursor/scratchpad.md`:
427
+ - `AUTO_BACKLOG_DRAIN`: `0|1` (default `0`)
428
+ - `AUTO_BACKLOG_MAX_STORIES`: integer `>=1` (default `1`)
429
+ - `AUTO_BACKLOG_ON_BLOCK`: `stop|skip` (default `stop`)
430
+ - `AUTO_STORY_SELECTION`: `priority_then_backlog_order` (default)
431
+
432
+ Deterministic behavior when enabled (`AUTO_BACKLOG_DRAIN=1`):
433
+ - Select next eligible OPEN story via `AUTO_STORY_SELECTION`.
434
+ - **Advance through multiple phases** of the resolved lifecycle per story
435
+ (**reference Step 5**) — the orchestrator does not stop after one phase
436
+ unless a deterministic stop condition fires (see **Deterministic stop matrix
437
+ (US-0088)**).
438
+ - After each story's terminal boundary (`refresh-context` completion or policy
439
+ stop), **recompute the materialized phase plan** by reloading merged
440
+ scratchpad phase-selection inputs at the story boundary (**US-0044** /
441
+ **US-0088**). The next eligible OPEN story starts with a fresh plan class —
442
+ no silent revival of omitted phases from the prior story's plan.
443
+ - Continue to next eligible OPEN story until:
444
+ - `AUTO_BACKLOG_MAX_STORIES` limit reached (`BACKLOG_MAX_STORIES_REACHED`), or
445
+ - no eligible stories remain, or
446
+ - stop condition / decision gate occurs.
447
+ - On blocked story:
448
+ - `AUTO_BACKLOG_ON_BLOCK=stop` → stop immediately.
449
+ - `AUTO_BACKLOG_ON_BLOCK=skip` → record skip reason and continue to next story.
450
+ - Track `backlog_drain_stories_remaining_budget` across boundaries; notify
451
+ operator on segment handoff / drain advance (non-routine, non-suppressible
452
+ even when `AUTO_QUIET=1`).
453
+
454
+ Default-safe behavior:
455
+ - With `AUTO_BACKLOG_DRAIN=0`, preserve existing single-segment continuation.
456
+
457
+ ## Optional bug-queue mode (US-0087)
458
+
459
+ `/auto` supports an optional, **default-off** bug-queue scheduler for **OPEN**
460
+ defects in **`docs/product/backlog.md`** **`## Bug issues (canonical)`**,
461
+ orthogonal to story-only **`AUTO_BACKLOG_DRAIN`** (**`US-0044`** / **`DEC-0022`**).
462
+ Bug-queue mode is **spawn-only** — same **`AUTO_ORCHESTRATOR_PHASE_EXECUTION`**
463
+ contract as other phases (**`BUG-0006`**, **`US-0069`** / **`DEC-0051`**).
464
+
465
+ ### Canonical argv literals (AC-1)
466
+
467
+ Exact tokens (**no aliases** in v1; contract-tested):
468
+
469
+ - **`bug-target=BUG-####`** — single **OPEN** bug (example: **`bug-target=BUG-0007`**).
470
+ - **`bug-target=all-open`** — deterministic **OPEN**-only queue.
471
+
472
+ ### Scratchpad keys (merged; `template/` parity)
473
+
474
+ Default-off when unset (see **`architecture.md`** **`# US-0087`**):
475
+
476
+ - **`AUTO_BUG_QUEUE`**: `0|1`
477
+ - **`AUTO_BUG_TARGET`**: `all-open` | **`BUG-####`** — required when **`AUTO_BUG_QUEUE=1`**
478
+ unless **`bug-target=`** argv supplies the target for this invocation.
479
+ - **`AUTO_BUG_MAX_ITEMS`**: non-negative integer — optional cap on bugs consumed per
480
+ orchestrator run for **`all-open`**; **`0`** or unset = no cap beyond queue length.
481
+ - **`AUTO_BUG_ON_BLOCK`**: `stop|skip` — queue behavior when a bug segment stops at a
482
+ pause/stop boundary.
483
+
484
+ ### Scheduler mutex and argv precedence (AC-3)
485
+
486
+ **One active scheduler** per materialized run:
487
+
488
+ - If merged scratchpad has **`AUTO_BACKLOG_DRAIN=1`** **and** **`AUTO_BUG_QUEUE=1`**
489
+ **and** this invocation has **no** explicit **`bug-target=`** argv token → fail
490
+ closed with **`[AUTO_RESUME_ERROR] AUTO_SCHEDULER_CONFLICT: ...`**.
491
+ - When **`bug-target=`** argv is present, it **selects** the bug scheduler for this
492
+ run; **`AUTO_BACKLOG_DRAIN`** must **not** drive story selection for the same
493
+ materialized run (story drain keys ignored for scheduler selection; record
494
+ **`backlog_drain_active=false`**, **`bug_queue_active=true`** in **AC-10** for
495
+ that run).
496
+
497
+ **Parsing order** before nominal resume resolution: **`start-from`** → **`bug-target=`**
498
+ argv → merged scratchpad (**`AUTO_BACKLOG_DRAIN`**, **`AUTO_BUG_*`**) →
499
+ **`resume_brief.md`** → **`state.md`** fallback (**`architecture.md`** **`# US-0087`**).
500
+
501
+ ### OPEN queue semantics (AC-4)
502
+
503
+ - **OPEN** rows only in the canonical bug section — exclude **DONE** and non-matching ids.
504
+ - **Ordering**: ascending **numeric** sort on **`BUG-####`** (stable document-order
505
+ tie-break if needed).
506
+ - **`AUTO_BUG_MAX_ITEMS`**: when set to positive integer *N*, consume at most *N*
507
+ bugs from the head of the ordered queue this run; record **`bug_queue_remaining`**
508
+ for operator visibility.
509
+ - **Empty queue** when **`bug-target=all-open`** (or equivalent) and zero **OPEN**
510
+ bugs → **`[AUTO_RESUME_ERROR] AUTO_BUG_QUEUE_EMPTY: ...`** (or equivalent
511
+ deterministic envelope).
512
+
513
+ ### Fail-closed reason codes (AC-1, AC-4, AC-8)
514
+
515
+ | Code | When |
516
+ |------|------|
517
+ | **`AUTO_BUG_QUEUE_EMPTY`** | **`all-open`** and zero **OPEN** bugs. |
518
+ | **`AUTO_BUG_TARGET_UNKNOWN`** | Malformed id / pattern, or id missing from canonical bug section. |
519
+ | **`AUTO_BUG_TARGET_NOT_OPEN`** | Known id, status not **OPEN**. |
520
+ | **`AUTO_SCHEDULER_CONFLICT`** | **`AUTO_BACKLOG_DRAIN=1`** ∧ **`AUTO_BUG_QUEUE=1`** without **`bug-target=`** argv. |
521
+
522
+ Do **not** overload **`PHASE_POLICY_CONFLICT`** or backlog-drain codes for these.
523
+
524
+ ### Bug segment fields: `resume_brief.md` + `state.md` (`DEC-0069` / AC-5)
525
+
526
+ Default: **paired** refresh at segment boundaries — update **`handoffs/resume_brief.md`**
527
+ **and** append **`docs/engineering/state.md`** breadcrumbs together so continuation
528
+ without **`start-from`** avoids false **`RESUME_BRIEF_STALE`**.
529
+
530
+ | Field | Purpose |
531
+ |-------|---------|
532
+ | **`bug_id`** | Active **`BUG-####`** for this segment (**OPEN**), or **`(none)`**. |
533
+ | **`bug_queue_position`** | 1-based index into **OPEN** ordering for **`all-open`**; else **`(none)`**. |
534
+ | **`bug_queue_remaining`** | Count of **OPEN** bugs after current position; **`(none)`** when not queue-scoped. |
535
+ | **`intended_resume_phase`** | Next phase for this segment (align with **`next_scheduled_phase`** on `state.md`). |
536
+
537
+ Mirror the **AC-10** tuple (`segment_work_item_kind`, `active_bug_id`,
538
+ `backlog_drain_active`, `bug_queue_active`, etc.) in both surfaces per
539
+ **`architecture.md`** **`# US-0087`**.
540
+
541
+ ## Optional bulk execute mode (US-0047 / DEC-0024)
542
+
543
+ `/auto` supports an explicit bulk execute orchestration mode for continuous
544
+ planned-item delivery. Default behavior remains unchanged unless explicitly
545
+ enabled.
546
+
547
+ Canonical controls from `.cursor/scratchpad.md`:
548
+ - `AUTO_EXECUTE_BULK`: `0|1` (default `0`)
549
+ - `AUTO_EXECUTE_MAX_ITEMS`: integer `>=1` (default `1`)
550
+ - `AUTO_EXECUTE_ON_BLOCK`: `stop|skip` (default `stop`)
551
+ - `AUTO_EXECUTE_SELECTION`: `planned_then_priority` (default)
552
+ - `AUTO_TEAM_SCOPE_ENFORCE`: `0|1` (default `1`)
553
+
554
+ Explicit activation contract:
555
+ - Bulk execute mode is activated when either:
556
+ - explicit argument `--execute-bulk` is present for this run, or
557
+ - `AUTO_EXECUTE_BULK=1` in scratchpad.
558
+ - Without explicit activation, preserve current non-bulk continuation behavior.
559
+
560
+ Deterministic behavior when enabled:
561
+ - Select next eligible planned work item via `AUTO_EXECUTE_SELECTION`.
562
+ - Process each item with strict isolation:
563
+ - fresh subagent per phase boundary
564
+ - fresh subagent per execute<->QA loop cycle
565
+ - Apply bounded stop criteria:
566
+ - stop at `AUTO_EXECUTE_MAX_ITEMS`, or
567
+ - stop/skip on blocked item per policy, or
568
+ - stop when no eligible items remain.
569
+
570
+ Team mode guardrails (`TEAM_MODE=1`):
571
+ - Snapshot and record team context inputs:
572
+ - `TEAM_MODE`, `TEAM_MEMBER`, `ACTIVE_TASK_IDS`
573
+ - If `AUTO_TEAM_SCOPE_ENFORCE=1`, only tasks in current member scope are
574
+ executable.
575
+ - Out-of-scope tasks must be deterministically handled with no writes:
576
+ - `stop` policy -> `EXEC_TEAM_SCOPE_BLOCKED`
577
+ - `skip` policy -> `EXEC_TEAM_SCOPE_SKIPPED`
578
+
579
+ ## Sync policy contract (US-0038 / DEC-0018)
580
+
581
+ `/auto` may evaluate sync eligibility only at phase-completion boundaries.
582
+ It remains process-level guidance (no runtime git orchestrator changes).
583
+
584
+ Canonical policy controls from `.cursor/scratchpad.md`:
585
+ - `SYNC_POLICY_MODE`:
586
+ `disabled|manual|by_phase|by_milestone|custom_phase_list`
587
+ - `SYNC_CUSTOM_PHASES`: comma-separated canonical phase IDs for
588
+ `custom_phase_list` mode
589
+ - `ALLOW_AUTO_PUSH`: `0|1`
590
+ - `AUTO_PUSH_BRANCH_ALLOWLIST`: comma-separated branches/patterns
591
+
592
+ Deterministic policy semantics:
593
+ - `disabled`: skip sync evaluation entirely (`SYNC_DISABLED`).
594
+ - `manual`: no auto-sync attempts (`MANUAL_MODE_NO_AUTO`).
595
+ - `by_phase`: evaluate at every phase completion boundary.
596
+ - `by_milestone`: evaluate only at milestone completion boundary.
597
+ - `custom_phase_list`: evaluate only when completed phase is listed.
598
+ - Unset/invalid mode fails closed to `manual`.
599
+
600
+ Guarded auto-push eligibility chain (all required):
601
+ 1. Boundary is eligible for configured mode.
602
+ 2. `ALLOW_AUTO_PUSH=1`.
603
+ 3. QA-first safety passes (feature work cannot auto-push before QA pass;
604
+ manual user-invoked sync remains allowed).
605
+ 4. No unresolved blocking QA findings / critical unresolved issues.
606
+ 5. Branch safety passes: protected/default branches are denied by default unless
607
+ explicitly allowlisted.
608
+ 6. Mandatory pre-push checks pass:
609
+ - `TEST_COMMAND` is required
610
+ - optional `LINT_COMMAND` / `TYPECHECK_COMMAND` run only when configured
611
+ - failures or timeout result in `no_push`
612
+
613
+ If any condition fails, verdict is deterministic `no_push` with reason code.
614
+
615
+ Reason-code baseline:
616
+ - `SYNC_DISABLED`
617
+ - `MANUAL_MODE_NO_AUTO`
618
+ - `SYNC_TRIGGER_NOT_ELIGIBLE`
619
+ - `AUTO_PUSH_NOT_ENABLED`
620
+ - `PRE_QA_AUTOPUSH_FORBIDDEN`
621
+ - `BLOCKING_QA_FINDINGS`
622
+ - `BRANCH_NOT_ALLOWLISTED`
623
+ - `TEST_COMMAND_MISSING`
624
+ - `TEST_FAILED`
625
+ - `TEST_TIMEOUT`
626
+ - `OPTIONAL_CHECK_FAILED`
627
+ - `SYNC_PUSHED`
628
+ - `BACKLOG_DRAIN_DISABLED`
629
+ - `BACKLOG_STORY_BLOCKED_STOP`
630
+ - `BACKLOG_STORY_BLOCKED_SKIPPED`
631
+ - `BACKLOG_MAX_STORIES_REACHED`
632
+ - `BACKLOG_NO_ELIGIBLE_STORIES`
633
+ - `EXEC_BULK_DISABLED`
634
+ - `EXEC_BULK_ITEM_BLOCKED_STOP`
635
+ - `EXEC_BULK_ITEM_BLOCKED_SKIPPED`
636
+ - `EXEC_BULK_MAX_ITEMS_REACHED`
637
+ - `EXEC_BULK_NO_ELIGIBLE_ITEMS`
638
+ - `EXEC_TEAM_SCOPE_BLOCKED`
639
+ - `EXEC_TEAM_SCOPE_SKIPPED`
640
+ - `RUNTIME_PROOF_MISSING`
641
+ - `RUNTIME_PROOF_INVALID`
642
+ - `RUNTIME_PROOF_REUSED`
643
+ - `RUNTIME_PROOF_STALE`
644
+ - `RUNTIME_PROOF_AMBIGUOUS_LINK`
645
+ - `PHASE_ROLE_CAPABILITY_MISSING`
646
+ - `PHASE_ROLE_MISMATCH`
647
+ - `PHASE_POLICY_CONFLICT`
648
+ - `PHASE_PLAN_UNKNOWN_PHASE`
649
+ - `PHASE_PLAN_EMPTY_INCLUDE`
650
+ - `PHASE_PLAN_UNKNOWN_PROFILE`
651
+ - `PHASE_PLAN_INVALID_AUTO_PHASE_PLAN`
652
+ - `PHASE_PLAN_HIGH_RISK_ACK_REQUIRED`
653
+ - `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION`
654
+
655
+ ## Canonical `start-from` contract
656
+
657
+ - Accepted canonical phase IDs:
658
+ - `intake`
659
+ - `discovery`
660
+ - `research`
661
+ - `architecture`
662
+ - `sprint-plan`
663
+ - `plan-verify`
664
+ - `execute`
665
+ - `qa`
666
+ - `verify-work`
667
+ - `release`
668
+ - `refresh-context`
669
+ - Only canonical IDs are accepted. Alias values (for example `sprint_plan`,
670
+ `verifywork`) are invalid and must fail fast.
671
+
672
+ ## Deterministic resume-source precedence
673
+
674
+ Resolve nominal start phase and scheduler inputs in strict order (**`US-0087`**
675
+ extends ordering vs legacy two-step resume):
676
+
677
+ 1. Explicit `/auto start-from=<phase>`
678
+ 2. Explicit **`bug-target=`** argv token when present (`bug-target=BUG-####` or
679
+ `bug-target=all-open`) — parsed **before** merged scratchpad scheduler keys;
680
+ selects bug scheduler for this run when applicable.
681
+ 3. Merged scratchpad (**`US-0073`** / **`DEC-0055`**) — `AUTO_BACKLOG_DRAIN`,
682
+ **`AUTO_BUG_QUEUE`**, **`AUTO_BUG_TARGET`**, related flags.
683
+ 4. `handoffs/resume_brief.md`
684
+ 5. Conservative `docs/engineering/state.md` fallback
685
+ 6. Fail fast on ambiguity/conflict/unrecoverable inputs (including
686
+ **`AUTO_SCHEDULER_CONFLICT`** when **`AUTO_BACKLOG_DRAIN=1`** ∧
687
+ **`AUTO_BUG_QUEUE=1`** without **`bug-target=`** argv).
688
+
689
+ Deterministic precedence behavior:
690
+ - If explicit `start-from` is valid, it wins for the **nominal start phase** anchor;
691
+ scheduler mutex (**`AUTO_SCHEDULER_CONFLICT`**) is still evaluated when scratchpad
692
+ enables both drains without **`bug-target=`** argv resolution.
693
+ - **`bug-target=`** argv when present overrides conflicting scratchpad scheduler
694
+ selection for **this** run (bug queue active; story drain inactive for scheduling).
695
+ - `state.md` fallback applies only per the ordered chain above when higher-priority
696
+ sources do not supply a trustworthy anchor.
697
+ - If `resume_brief.md` is present but stale or unparseable, fail fast instead
698
+ of silently falling back.
699
+
700
+ ## Conflict and stale/unparseable policy
701
+
702
+ - Explicit valid override always wins and is logged as override.
703
+ - **`AUTO_BACKLOG_DRAIN=1`** and **`AUTO_BUG_QUEUE=1`** together without explicit
704
+ **`bug-target=`** argv → **`AUTO_SCHEDULER_CONFLICT`** (fail fast; do not pick a
705
+ silent default scheduler).
706
+ - No override + `resume_brief` conflicts with `state` inference: fail fast.
707
+ - `resume_brief` exists but stale: fail fast.
708
+ - `resume_brief` exists but unparseable: fail fast.
709
+ - `state` fallback yields multiple candidate phases: fail fast.
710
+ - `state` fallback yields no trustworthy boundary: fail fast.
711
+
712
+ ## Fail-fast error code contract
713
+
714
+ All resume-resolution failures must use:
715
+
716
+ `[AUTO_RESUME_ERROR] <code>: <summary>. Source=<source>. Fix: <action>.`
717
+
718
+ Required codes:
719
+ - `INVALID_START_FROM`
720
+ - `RESUME_BRIEF_MISSING`
721
+ - `RESUME_BRIEF_STALE`
722
+ - `RESUME_BRIEF_UNPARSEABLE`
723
+ - `RESUME_STATE_CONFLICT`
724
+ - `STATE_PHASE_AMBIGUOUS`
725
+ - `STATE_PHASE_UNRECOVERABLE`
726
+
727
+ Bug-queue extensions (**`US-0087`**; use the same **`[AUTO_RESUME_ERROR]`** envelope
728
+ for resolver/materialization failures):
729
+
730
+ - `AUTO_SCHEDULER_CONFLICT`
731
+ - `AUTO_BUG_QUEUE_EMPTY`
732
+ - `AUTO_BUG_TARGET_UNKNOWN`
733
+ - `AUTO_BUG_TARGET_NOT_OPEN`
734
+
735
+ ## Continuous multi-phase execution (US-0088)
736
+
737
+ A single `/auto` orchestrated run (or a **documented equivalent outer driver** —
738
+ see **AC-1 equivalence** below) advances through **all phases** in the
739
+ **intersected resolved schedule** (**Step 5** below — cross-anchor:
740
+ **"reference Step 5"**) until a **deterministic stop condition** fires. The
741
+ orchestrator does **not** stop after spawning one phase unless the stop matrix
742
+ requires it.
743
+
744
+ ### Outer-driver equivalence (AC-1, Option B)
745
+
746
+ When a single Cursor `/auto` invocation cannot schedule multiple fresh subagent
747
+ turns (product/runtime constraint), a **documented outer driver** (operator
748
+ script or manual re-invocation with `start-from` / refreshed `resume_brief`) is
749
+ **deterministically equivalent** provided all of the following hold:
750
+
751
+ - Same intersected phase order as a single-invocation run.
752
+ - Same per-phase isolation evidence (**DEC-0029**) + strict-proof attestation
753
+ (**DEC-0038**).
754
+ - Same deterministic stop reasons and stop matrix evaluation.
755
+ - Same `resume_brief` + `state.md` refresh at every materialized phase boundary.
756
+ - Operators must follow the runbook recipe
757
+ (**`docs/engineering/runbook.md`** § Continuous `/auto` + backlog drain).
758
+
759
+ ### Deterministic stop matrix (US-0088)
760
+
761
+ | Condition | Behavior | Operator notify (AC-2) |
762
+ |-----------|----------|------------------------|
763
+ | Next phase exists, no hard stop | **Continue** — preflight US-0069, spawn next phase | Quiet OK when `AUTO_QUIET=1` |
764
+ | `decision_gate` | **Stop** until resolved | **Always** (non-suppressible) |
765
+ | `error` / missing critical input | **Stop** | **Always** (non-suppressible) |
766
+ | `AUTO_PAUSE_REQUEST` / `pause` | **Stop** at safe boundary | **Always** (non-suppressible) |
767
+ | `AUTO_LOOP_MAX_CYCLES` / `loop_max` | **Stop** | **Always** (non-suppressible) |
768
+ | `blocked` (sync/scope gate) | **Stop** | **Always** (non-suppressible) |
769
+ | US lifecycle DONE / sprint segment complete | **Stop** segment; `AUTO_BACKLOG_DRAIN=1` may advance to next OPEN story (recompute phase plan — **Step 5**) | Notify on segment handoff (non-routine) |
770
+ | `BACKLOG_MAX_STORIES_REACHED` | **Stop** | **Always** (non-suppressible) |
771
+
772
+ `stop_reason` vocabulary: `completed`, `decision_gate`, `missing_input`,
773
+ `pause_request`, `loop_max`, `error`, `blocked`.
774
+
775
+ ### Full-autonomy stop matrix (US-0092)
776
+
777
+ **`AUTO_FLOW_MODE=full_autonomy`** enables **`scripts/auto_outer_driver.py`**
778
+ (spawn-only outer driver). **TOKEN_PROFILE controls context breadth / token cost only**
779
+ never automation level, drain, or outer-driver invocation.
780
+
781
+ | Condition | US-0088 | `full_autonomy` delta | Operator notify |
782
+ |-----------|---------|------------------------|-----------------|
783
+ | Next phase, no hard stop | Continue inner `/auto` | Outer driver **re-invokes** when Cursor ends turn early | Quiet OK when `AUTO_QUIET=1` |
784
+ | `decision_gate` | Hard stop | **No change hard** | Always |
785
+ | Unrecoverable `error` | Hard stop | **No change — hard** | Always |
786
+ | Critical `missing_input` | Hard stop | **No change — hard** | Always |
787
+ | Transient `missing_input` (recoverable) | Hard stop | **Relaxable** — bounded block-retry | Notify on cap |
788
+ | `pause_request` | Hard stop | **No change hard** | Always |
789
+ | `loop_max` | Hard stop | **No change — hard** | Always |
790
+ | `blocked` transient/sync | Hard stop | **Relaxable** when recoverable | Notify on cap |
791
+ | `blocked` — isolation/strict-proof/ownership | Hard stop | **No change — hard** | Always |
792
+ | UAT/QA fail | Hard stop (operator) | **Relaxable** when `AUTO_IMPLEMENTATION_LOOP=1` | Notify on cap |
793
+ | Segment complete + `AUTO_BACKLOG_DRAIN=1` | Advance (may need manual re-`/auto`) | **Drain-advance-without-pause** — immediate next item | Segment handoff notify |
794
+ | `BACKLOG_MAX_STORIES_REACHED` | Hard stop | **No change — hard** | Always |
795
+ | `AUTO_SCHEDULER_CONFLICT` | Hard stop | **No change hard** | Always |
796
+ | `RELEASE_PUBLISH_MODE=auto` | Explicit opt-in | **No change hard default-off** | Always on publish |
797
+ | Security deny (`.env`, intake mutation) | Hard deny | **No change — hard** | Always |
798
+
799
+ **Drain-advance-without-pause**: outer driver schedules next OPEN story/bug immediately;
800
+ paired **`resume_brief`** + **`state.md`** refresh per **DEC-0069** at every boundary.
801
+
802
+ ### Block-retry ledger + cap interaction (US-0092)
803
+
804
+ Append-only **`handoffs/auto_block_retry/<orchestrator_run_id>.jsonl`** names-only;
805
+ no secrets. Cap interaction:
806
+
807
+ | Cap | Scope |
808
+ |-----|-------|
809
+ | `AUTO_LOOP_MAX_CYCLES` | Outer-driver `/auto` invocations (incl. drain advances) |
810
+ | `AUTO_IMPLEMENTATION_LOOP` | Inner `execute`↔`qa`↔`verify-work` when `1` |
811
+ | `AUTO_BLOCK_RETRY_MAX` | Per `(story_id, stop_reason)` recoverable retries |
812
+ | `AUTO_BACKLOG_MAX_STORIES` | Drain breadth outer driver exit **4** |
813
+
814
+ Cap exhaustion exit **6** `BLOCK_RETRY_CAP_EXHAUSTED`. Ordering: outer driver checks
815
+ `AUTO_LOOP_MAX_CYCLES` first; orchestrator checks `AUTO_IMPLEMENTATION_LOOP` +
816
+ `AUTO_BLOCK_RETRY_MAX` before scheduling remediation.
817
+
818
+ ### `AUTO_QUIET` vs `TOKEN_PROFILE` (US-0088 / AC-2)
819
+
820
+ | Key | Values | Role |
821
+ |-----|--------|------|
822
+ | `AUTO_QUIET` | `0` \| `1` (default `0`) | `1` = suppress routine per-phase success chatter; must **not** suppress `decision_gate`, errors, pause, `loop_max`, `blocked`, or missing inputs. |
823
+ | `TOKEN_PROFILE` | `lean` \| `balanced` \| `full` | **TOKEN_PROFILE controls context breadth / token cost only** — **DEC-0035** / **US-0080** / **US-0092**; **orthogonal** to `AUTO_QUIET`, drain, and outer-driver invocation. |
824
+
825
+ ### `TOKEN_PROFILE` × `CAVEMAN_MODE` non-substitution (US-0089 / DEC-0072 §1)
826
+
827
+ `TOKEN_PROFILE` controls context breadth. `CAVEMAN_MODE` controls reply voice. Neither substitutes for the other; setting one does not change the other. Combine freely.
828
+
829
+ `CAVEMAN_MODE` and `CAVEMAN_LEVEL` live in `.cursor/scratchpad.md` (default
830
+ `CAVEMAN_MODE=0`, `CAVEMAN_LEVEL=` empty). `CAVEMAN_COMPRESS_INPUT` and
831
+ `CAVEMAN_FILE_SCOPE` are reserved for **US-0090** and remain **documented
832
+ no-ops** in US-0089. The literal-region invariant, the five canonical
833
+ operator toggle phrases (`caveman on`, `caveman off`, `stop caveman`,
834
+ `normal mode`, `caveman: lite|full|ultra`), and the `CAVEMAN_LEVEL_UNKNOWN`
835
+ fail-closed contract live in `.cursor/rules/caveman.mdc`. Default-off is
836
+ enforced by the `test_caveman_default_off_*` subtests in
837
+ `tests/auto_command_contract_test.py` (**DEC-0072** §6).
838
+
839
+ ### `TOKEN_PROFILE` × `CAVEMAN_MODE` × `CAVEMAN_COMPRESS_INPUT` non-substitution (US-0090 / DEC-0073 §1)
840
+
841
+ `TOKEN_PROFILE` controls context breadth. `CAVEMAN_MODE` controls reply voice. `CAVEMAN_COMPRESS_INPUT` controls input-side file compression. All three axes are orthogonal: setting one does not change the others, and none substitutes for another.
842
+
843
+ `CAVEMAN_COMPRESS_INPUT` and `CAVEMAN_FILE_SCOPE` live in
844
+ `.cursor/scratchpad.md` (defaults: `CAVEMAN_COMPRESS_INPUT=0`,
845
+ `CAVEMAN_FILE_SCOPE=` empty). Activation also requires the operator to
846
+ invoke `scripts/caveman_compress_input.py --write`; absent any of the three
847
+ conditions the script is a no-op and the fail-closed reason codes from
848
+ **DEC-0073** §7 apply. Default-off is enforced by the
849
+ `test_caveman_compress_input_*` subtests in
850
+ `tests/auto_command_contract_test.py` (**DEC-0073** §11).
851
+
852
+ ## Steps
853
+ 1. Read automation flags from merged scratchpad and **materialize the resolved
854
+ phase plan** per **Configurable phase selection policy (US-0070 / DEC-0052)**:
855
+ detect exactly-one policy mode, expand, apply non-skippable reinstatement,
856
+ validate tokens/profile/ack requirements, and append plan breadcrumbs
857
+ (`phase_policy_mode`, `resolved_phase_plan`, `skipped_phases` + reasons) to
858
+ `docs/engineering/state.md` **before** any phase spawn. On failure, emit
859
+ deterministic phase-plan reason codes and stop (no partial schedule).
860
+ 2. Parse optional `start-from=<phase>` and validate canonical phase ID rules.
861
+ Parse optional **`bug-target=`** argv literals (**`US-0087`**) and evaluate
862
+ **scheduler mutex** (`AUTO_SCHEDULER_CONFLICT` when **`AUTO_BACKLOG_DRAIN=1`**
863
+ **`AUTO_BUG_QUEUE=1`** without **`bug-target=`** argv).
864
+ Parse optional `--execute-bulk` and treat it as explicit one-run override.
865
+ 3. Resolve **nominal** start phase using deterministic precedence:
866
+ - explicit `start-from` → **`bug-target=`** argv (when present) → merged scratchpad
867
+ resume brief state fallback → fail-fast.
868
+ - Emit `[AUTO_RESUME_ERROR] ...` message on resolver failure.
869
+ 3a. **Intersect** the nominal start anchor with the resolved phase plan (plan
870
+ order preserved; drop scheduled phases strictly before the anchor in canonical
871
+ order). **Empty intersection** → fail fast with
872
+ `START_FROM_PHASE_PLAN_EMPTY_INTERSECTION` and diagnostics listing
873
+ `resolved_phase_plan` vs `requested_start_phase` / inferred resume anchor.
874
+ Set the executable schedule to this intersection.
875
+ 4. Record continuation breadcrumb metadata in `docs/engineering/state.md`:
876
+ - `invocation_mode=auto`
877
+ - `requested_start_from`
878
+ - `resolved_start_phase` (first phase of the intersected schedule)
879
+ - `resolution_source` (`argument|resume_brief|state_fallback`)
880
+ - `resolution_status` (`resolved|fail-fast`)
881
+ - `timestamp`
882
+ 5. **(reference Step 5 continuous multi-phase spawn)** Spawn a fresh subagent
883
+ for each remaining phase in **the intersected resolved schedule order** (not
884
+ the full canonical list when phases are omitted), starting at
885
+ `resolved_start_phase`, and **advance through all subsequent phases** until a
886
+ **deterministic stop condition** fires (see **Deterministic stop matrix
887
+ (US-0088)** above). The orchestrator does **not** stop after a single phase
888
+ spawn unless the stop matrix requires it; outer-driver equivalence applies
889
+ when a single invocation cannot schedule multiple subagent turns (see
890
+ **Outer-driver equivalence (AC-1, Option B)** above):
891
+ default full path:
892
+ intake -> discovery -> research -> architecture -> sprint plan ->
893
+ plan verify -> execute -> QA -> verify work -> release -> refresh context.
894
+ If `SECURITY_REVIEW=1`, run `/security-review` in a fresh security subagent:
895
+ - in `design` mode immediately after architecture and before sprint plan,
896
+ - in `code` mode immediately after execute and before QA.
897
+ If `SECURITY_REVIEW=0` (default), skip both checks with zero overhead.
898
+ - If `AUTO_BACKLOG_DRAIN=1`, repeat story lifecycle for next eligible OPEN
899
+ story using deterministic selection policy until bounded stop criteria.
900
+ **Reload merged scratchpad phase-selection inputs and recompute the phase
901
+ plan at each story boundary** (same policy class as single-segment runs).
902
+ - If bug-queue mode is active (**`bug-target=`** argv or **`AUTO_BUG_QUEUE=1`**
903
+ with resolved target), iterate **OPEN** bugs per **Optional bug-queue mode
904
+ (US-0087)** ascending numeric **`BUG-####`** order, **`AUTO_BUG_MAX_ITEMS`**
905
+ cap, **`AUTO_BUG_ON_BLOCK`** stop/skip running the same **resolved phase plan**
906
+ per bug segment with fresh spawns only. **Reload scratchpad and revalidate
907
+ mutex at each bug boundary.** Empty **OPEN** queue → **`AUTO_BUG_QUEUE_EMPTY`**.
908
+ - If bulk execute mode is active (`--execute-bulk` or
909
+ `AUTO_EXECUTE_BULK=1`), iterate eligible planned items using
910
+ `AUTO_EXECUTE_SELECTION` with bounded item count
911
+ (`AUTO_EXECUTE_MAX_ITEMS`) and deterministic block/skip semantics.
912
+ **Reload merged scratchpad phase-selection inputs and recompute the phase
913
+ plan at each item boundary** (no silent revival of omitted phases).
914
+ - In team mode with enforcement enabled, run pre-mutation scope checks against
915
+ `TEAM_MEMBER` and `ACTIVE_TASK_IDS`; out-of-scope tasks produce deterministic
916
+ reason codes and no writes.
917
+ - **US-0069 / DEC-0051**: Before each phase spawn, resolve the single-valued
918
+ expected role (matrix + `AUTO_ROLE_RESEARCH`, `AUTO_ROLE_PLAN_VERIFY`,
919
+ `AUTO_ROLE_REFRESH_CONTEXT`), enforce execute default deny / override
920
+ contract, and run the preflight capability gate; on failure stop with
921
+ `PHASE_ROLE_CAPABILITY_MISSING` (no unrelated-role spawn).
922
+ - **US-0069 / DEC-0051**: After each phase completes, validate isolation
923
+ `role` and strict-proof `role` against the preflight-resolved expected
924
+ role; on conflict stop with `PHASE_ROLE_MISMATCH`.
925
+ 6. Pass only the phase input files and current objective to each spawned
926
+ subagent. Do not pass prior conversational reasoning as phase context.
927
+ 7. If `AUTO_IMPLEMENTATION_LOOP=1`, alternate fresh subagents for execute and QA
928
+ (`dev`, then `qa`, then new `dev`, then new `qa`) until no blocking findings
929
+ or `AUTO_LOOP_MAX_CYCLES` is reached.
930
+ - After each cycle, verify that both phases wrote new isolation evidence
931
+ entries (distinct `fresh_context_marker` per phase per cycle).
932
+ 8. If `AUTO_PAUSE_REQUEST=1`, stop at the next safe boundary
933
+ (`AUTO_PAUSE_POLICY`) and spawn `/pause` in a fresh curator subagent.
934
+ 9. Preserve existing stop conditions and gates without bypass:
935
+ - decision gate
936
+ - missing critical input
937
+ - pause request at safe boundary
938
+ - loop max cycles reached
939
+ 10. On stop (or completion), write breadcrumbs:
940
+ - `stop_reason` (`completed|decision_gate|missing_input|pause_request|loop_max`)
941
+ - `stop_phase`
942
+ - `timestamp`
943
+ 11. If stopped before completion, update `handoffs/resume_brief.md` with the
944
+ intended next phase and stop metadata.
945
+ 11a. At each phase boundary, verify isolation evidence exists for the completed
946
+ phase in `docs/engineering/state.md` and includes all required fields. If
947
+ missing/invalid/stale, stop with the appropriate reason code and remediation
948
+ guidance (run the phase again in a fresh subagent context and write new
949
+ evidence). Append **phase boundary status** per **Configurable phase
950
+ selection policy (US-0070 / DEC-0052)** (selected/skipped summary + next
951
+ scheduled phase).
952
+ 11b. At each phase boundary, verify strict runtime attestation tuple exists and
953
+ is valid for the completed phase (`orchestrator_run_id`,
954
+ `runtime_proof_id`, `phase_id`, `role`, `proof_issued_at`,
955
+ `proof_ttl_seconds`, `proof_hash`).
956
+ - Missing tuple: `RUNTIME_PROOF_MISSING`
957
+ - Invalid schema/hash/linkage: `RUNTIME_PROOF_INVALID`
958
+ - Reused `runtime_proof_id`: `RUNTIME_PROOF_REUSED`
959
+ - Expired proof TTL / stale proof: `RUNTIME_PROOF_STALE`
960
+ - Ambiguous proof-to-checkpoint linkage: `RUNTIME_PROOF_AMBIGUOUS_LINK`
961
+ - Remediation: rerun affected phase in fresh subagent context, write new
962
+ strict-proof tuple + checkpoint evidence, then continue.
963
+ 12. At each phase boundary, evaluate sync policy only when mode requires it and
964
+ record a deterministic sync verdict entry with:
965
+ - `phase_boundary`
966
+ - `policy_mode`
967
+ - `trigger_source` (`manual|auto`)
968
+ - `branch`
969
+ - `checks` (`test|lint|typecheck`: `pass|fail|skipped`)
970
+ - `qa_status_snapshot`
971
+ - `push_decision` (`pushed|blocked|not_eligible`)
972
+ - `reason_code`
973
+ - `evidence_refs`
974
+ 13. When backlog-drain mode, bug-queue mode, or bulk execute mode is enabled,
975
+ append per-item run summary entries:
976
+ - `item_id`
977
+ - `item_kind` (`story|sprint|bug`)
978
+ - `story_id`
979
+ - `bug_id` (when `item_kind=bug`)
980
+ - `sprint_id`
981
+ - `story_start_phase`
982
+ - `story_stop_phase`
983
+ - `story_outcome` (`released|blocked|skipped`)
984
+ - `story_reason_code`
985
+ - `team_context_snapshot` (`TEAM_MODE`, `TEAM_MEMBER`, `ACTIVE_TASK_IDS`)
986
+ - `timestamp`
987
+
988
+ ## Backward compatibility
989
+
990
+ - Manual and interactive workflows remain unchanged by default.
991
+ - `/resume` remains valid for context loading and guided continuation.
992
+ - Deterministic precedence and fail-fast behavior apply when `/auto` continuation
993
+ is invoked.
994
+
995
+ ## Deterministic artifact ordering guard (US-0058 / DEC-0040)
996
+
997
+ - When `/auto` coordinates phases that write mutable artifacts, each phase must
998
+ follow `docs/engineering/artifact-ordering-policy.md`.
999
+ - Ordering policies are mandatory:
1000
+ - `state.md`: append-bottom
1001
+ - `backlog.md` / `acceptance.md`: sorted-canonical
1002
+ - release/handoff surfaces: policy-specific (prepend/append) as documented.
1003
+ - If a required placement anchor is missing or ambiguous, fail closed with
1004
+ `ARTIFACT_ORDERING_ANCHOR_AMBIGUOUS` and do not continue.