@blxzer/cursor-trellis 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +170 -103
  2. package/README.md +27 -4
  3. package/dist/cli/index.d.ts.map +1 -1
  4. package/dist/cli/index.js +18 -0
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/commands/init.d.ts.map +1 -1
  7. package/dist/commands/init.js +8 -1
  8. package/dist/commands/init.js.map +1 -1
  9. package/dist/commands/update.d.ts.map +1 -1
  10. package/dist/commands/update.js +6 -1
  11. package/dist/commands/update.js.map +1 -1
  12. package/dist/commands/validate-rules.d.ts +6 -0
  13. package/dist/commands/validate-rules.d.ts.map +1 -0
  14. package/dist/commands/validate-rules.js +33 -0
  15. package/dist/commands/validate-rules.js.map +1 -0
  16. package/dist/configurators/cursor2plus-local.d.ts.map +1 -1
  17. package/dist/configurators/cursor2plus-local.js +2 -1
  18. package/dist/configurators/cursor2plus-local.js.map +1 -1
  19. package/dist/configurators/workflow.d.ts.map +1 -1
  20. package/dist/configurators/workflow.js +8 -2
  21. package/dist/configurators/workflow.js.map +1 -1
  22. package/dist/migrations/manifests/0.2.2.json +9 -0
  23. package/dist/migrations/manifests/0.2.4.json +9 -0
  24. package/dist/migrations/manifests/0.2.5.json +9 -0
  25. package/dist/migrations/manifests/0.2.6.json +9 -0
  26. package/dist/migrations/manifests/0.2.7.json +9 -0
  27. package/dist/migrations/manifests/0.2.8.json +9 -0
  28. package/dist/templates/common/bundled-skills/trellis-cursor2plus-setup/SKILL.md +2 -2
  29. package/dist/templates/common/commands/finish-work.md +12 -0
  30. package/dist/templates/common/skills/brainstorm.md +164 -163
  31. package/dist/templates/common/skills/check.md +4 -0
  32. package/dist/templates/cursor/agents/trellis-check.md +32 -0
  33. package/dist/templates/cursor/agents/trellis-implement.md +11 -0
  34. package/dist/templates/cursor/agents/trellis-research.md +29 -0
  35. package/dist/templates/cursor/fixtures/expected-rules.d.ts +14 -0
  36. package/dist/templates/cursor/fixtures/expected-rules.d.ts.map +1 -0
  37. package/dist/templates/cursor/fixtures/expected-rules.js +26 -0
  38. package/dist/templates/cursor/fixtures/expected-rules.js.map +1 -0
  39. package/dist/templates/cursor/rules/trellis-subagent-dispatch.mdc +34 -0
  40. package/dist/templates/markdown/index.d.ts +1 -0
  41. package/dist/templates/markdown/index.d.ts.map +1 -1
  42. package/dist/templates/markdown/index.js +1 -0
  43. package/dist/templates/markdown/index.js.map +1 -1
  44. package/dist/templates/markdown/spec/guides/execution-strategy.md.txt +43 -0
  45. package/dist/templates/markdown/spec/guides/index.md.txt +102 -101
  46. package/dist/templates/trellis/config/execution-strategy-rules.json +31 -0
  47. package/dist/templates/trellis/index.d.ts +2 -0
  48. package/dist/templates/trellis/index.d.ts.map +1 -1
  49. package/dist/templates/trellis/index.js +3 -0
  50. package/dist/templates/trellis/index.js.map +1 -1
  51. package/dist/templates/trellis/local/README.md +61 -37
  52. package/dist/templates/trellis/local/index.d.ts +1 -0
  53. package/dist/templates/trellis/local/index.d.ts.map +1 -1
  54. package/dist/templates/trellis/local/index.js +1 -0
  55. package/dist/templates/trellis/local/index.js.map +1 -1
  56. package/dist/templates/trellis/local/patch_wpelc8.py +162 -38
  57. package/dist/templates/trellis/local/smoke.py +94 -0
  58. package/dist/templates/trellis/scripts/common/codebase_retrieval_router.py +2 -2
  59. package/dist/templates/trellis/scripts/common/cursor_retrieval_env.py +16 -2
  60. package/dist/templates/trellis/scripts/common/execution_strategy.py +268 -0
  61. package/dist/templates/trellis/scripts/common/retrieval_agent_instructions.py +26 -7
  62. package/dist/templates/trellis/scripts/common/semantic_plan_gate.py +18 -4
  63. package/dist/templates/trellis/scripts/common/task_store.py +1594 -1565
  64. package/dist/templates/trellis/scripts/task.py +918 -877
  65. package/dist/templates/trellis/workflow.md +805 -800
  66. package/dist/utils/codebase-retrieval-router.js +2 -2
  67. package/dist/utils/codebase-retrieval-router.js.map +1 -1
  68. package/dist/utils/cursor-retrieval-env.d.ts +2 -0
  69. package/dist/utils/cursor-retrieval-env.d.ts.map +1 -1
  70. package/dist/utils/cursor-retrieval-env.js +11 -2
  71. package/dist/utils/cursor-retrieval-env.js.map +1 -1
  72. package/dist/utils/mirror-check.d.ts +22 -0
  73. package/dist/utils/mirror-check.d.ts.map +1 -0
  74. package/dist/utils/mirror-check.js +90 -0
  75. package/dist/utils/mirror-check.js.map +1 -0
  76. package/dist/utils/normalize-text.d.ts +7 -0
  77. package/dist/utils/normalize-text.d.ts.map +1 -0
  78. package/dist/utils/normalize-text.js +16 -0
  79. package/dist/utils/normalize-text.js.map +1 -0
  80. package/dist/utils/retrieval-agent-instructions.d.ts.map +1 -1
  81. package/dist/utils/retrieval-agent-instructions.js +14 -7
  82. package/dist/utils/retrieval-agent-instructions.js.map +1 -1
  83. package/dist/utils/retrieval-execution-telemetry.d.ts +12 -3
  84. package/dist/utils/retrieval-execution-telemetry.d.ts.map +1 -1
  85. package/dist/utils/retrieval-execution-telemetry.js +37 -1
  86. package/dist/utils/retrieval-execution-telemetry.js.map +1 -1
  87. package/dist/utils/retrieval-tool-classification.d.ts +2 -0
  88. package/dist/utils/retrieval-tool-classification.d.ts.map +1 -1
  89. package/dist/utils/retrieval-tool-classification.js +13 -0
  90. package/dist/utils/retrieval-tool-classification.js.map +1 -1
  91. package/dist/utils/semantic-plan-gate.d.ts.map +1 -1
  92. package/dist/utils/semantic-plan-gate.js +11 -4
  93. package/dist/utils/semantic-plan-gate.js.map +1 -1
  94. package/dist/utils/validate-rules.d.ts +21 -0
  95. package/dist/utils/validate-rules.d.ts.map +1 -0
  96. package/dist/utils/validate-rules.js +88 -0
  97. package/dist/utils/validate-rules.js.map +1 -0
  98. package/package.json +3 -2
@@ -1,800 +1,805 @@
1
- # Development Workflow
2
-
3
- ---
4
-
5
- ## Core Principles
6
-
7
- 1. **Plan before code** — figure out what to do before you start
8
- 2. **Specs injected, not remembered** — guidelines are injected via hook/skill, not recalled from memory
9
- 3. **Persist everything** — research, decisions, and lessons all go to files; conversations get compacted, files don't
10
- 4. **Incremental development** — one task at a time
11
- 5. **Capture learnings** — after each task, review and write new knowledge back to spec
12
-
13
- ---
14
-
15
- ## Trellis System
16
-
17
- ### Developer Identity
18
-
19
- On first use, initialize your identity:
20
-
21
- ```bash
22
- python3 ./.trellis/scripts/init_developer.py <your-name>
23
- ```
24
-
25
- Creates `.trellis/.developer` (gitignored) + `.trellis/workspace/<your-name>/`.
26
-
27
- ### Spec System
28
-
29
- `.trellis/spec/` holds coding guidelines organized by package and layer.
30
-
31
- - `.trellis/spec/<package>/<layer>/index.md` — entry point with **Pre-Development Checklist** + **Quality Check**. Actual guidelines live in the `.md` files it points to.
32
- - `.trellis/spec/guides/index.md` — cross-package thinking guides.
33
-
34
- ```bash
35
- python3 ./.trellis/scripts/get_context.py --mode packages # list packages / layers
36
- ```
37
-
38
- **When to update spec**: new pattern/convention found · bug-fix prevention to codify · new technical decision.
39
-
40
- ### Task System
41
-
42
- Every task has its own directory under `.trellis/tasks/{MM-DD-name}/` holding `task.json`, `prd.md`, optional `design.md`, optional `implement.md`, optional `research/`, and context manifests (`implement.jsonl`, `check.jsonl`) for Cursor (sub-agent dispatch).
43
-
44
- ```bash
45
- # Task lifecycle
46
- python3 ./.trellis/scripts/task.py create "<title>" [--slug <name>] [--parent <dir>]
47
- python3 ./.trellis/scripts/task.py dashboard # show Task Dashboard without mutating state
48
- python3 ./.trellis/scripts/task.py select <name> # select task for this live session
49
- python3 ./.trellis/scripts/task.py selected --source # show selected task and source
50
- python3 ./.trellis/scripts/task.py start-execution <name> --check
51
- python3 ./.trellis/scripts/task.py start-execution <name> --approved
52
- python3 ./.trellis/scripts/task.py exit # clear selected task without changing status
53
- python3 ./.trellis/scripts/task.py archive <name> # move to archive/{year-month}/
54
- python3 ./.trellis/scripts/task.py list [--mine] [--status <s>]
55
- python3 ./.trellis/scripts/task.py list-archive
56
- python3 ./.trellis/scripts/task.py add-subtask <parent> <child>
57
- python3 ./.trellis/scripts/task.py set-child-state <parent> <child> review --evidence verify.md
58
- python3 ./.trellis/scripts/task.py prepare-child-worktree <parent> <child> --branch <child-branch>
59
- python3 ./.trellis/scripts/task.py integrate-child <parent> <child> accepted --evidence handoff.md --ref <child-ref>
60
-
61
- # Code-spec context (injected into implement/check agents via JSONL).
62
- # `implement.jsonl` / `check.jsonl` are seeded on `task create` for sub-agent-capable
63
- # platforms; the AI curates real spec + research entries during planning when needed.
64
- python3 ./.trellis/scripts/task.py add-context <name> <action> <file> <reason>
65
- python3 ./.trellis/scripts/task.py list-context <name> [action]
66
- python3 ./.trellis/scripts/task.py validate <name>
67
-
68
- # Task metadata
69
- python3 ./.trellis/scripts/task.py set-branch <name> <branch>
70
- python3 ./.trellis/scripts/task.py set-base-branch <name> <branch> # PR target
71
- python3 ./.trellis/scripts/task.py set-scope <name> <scope>
72
-
73
- # Hierarchy (parent/child)
74
- python3 ./.trellis/scripts/task.py add-subtask <parent> <child>
75
- python3 ./.trellis/scripts/task.py remove-subtask <parent> <child>
76
-
77
- # PR creation
78
- python3 ./.trellis/scripts/task.py create-pr [name] [--dry-run]
79
- ```
80
-
81
- > Run `python3 ./.trellis/scripts/task.py --help` to see the authoritative, up-to-date list.
82
-
83
- **Selected-task mechanism**: entering a Trellis project activates framework context, but every new live session starts with `Selected task: none`. `task.py create` creates artifacts only. `task.py select <task>` writes a per-session `selected_task` pointer without changing `task.json.status`. `task.py selected --source` reports that pointer. `task.py exit` clears it without changing status. `task.py start-execution <task> --check` verifies execution readiness without mutation; `task.py start-execution <task> --approved` is the explicit execution boundary and may flip `planning` to `in_progress`. `task.py archive <task>` writes `status=completed`, moves the directory to `archive/`, and deletes runtime session files that still point at the archived task.
84
-
85
- ### Workspace System
86
-
87
- Records every AI session for cross-session tracking under `.trellis/workspace/<developer>/`.
88
-
89
- - `journal-N.md` — session log. **Max 2000 lines per file**; a new `journal-(N+1).md` is auto-created when exceeded.
90
- - `index.md` — personal index (total sessions, last active).
91
-
92
- ```bash
93
- python3 ./.trellis/scripts/add_session.py --title "Title" --commit "hash" --summary "Summary"
94
- ```
95
-
96
- ### Context Script
97
-
98
- ```bash
99
- python3 ./.trellis/scripts/get_context.py # full session runtime
100
- python3 ./.trellis/scripts/get_context.py --mode packages # available packages + spec layers
101
- python3 ./.trellis/scripts/get_context.py --mode phase --step <X.Y> # detailed guide for a workflow step
102
- python3 ./.trellis/scripts/get_context.py --mode retrieval-pack --json --input <evidence.json> # score collected evidence (not default --json)
103
- ```
104
-
105
- **Evidence scoring:** default `--json` returns `retrievalGuide` only. After collecting artifact search, session memory, smart-search manifests under `{TASK}/research/smart-search/`, or codebase candidates, run **`--mode retrieval-pack`** with `--input` or stdin JSON. See `research/evidence-scoring-integration.md` in the active task or archived `06-15-child-phase2-evidence-scoring`.
106
-
107
- **Research-end hook (Cursor `stop`):** when the selected task has `{TASK}/research/*.md` or `research/smart-search/`, `.cursor/hooks/research-end-retrieval-pack.py` may write `{TASK}/research/retrieval-pack-latest.json` via `get_context --mode retrieval-pack`. Default session JSON is unchanged; use the file when closing research or before Phase 3.1.
108
-
109
- **Retrieval daily guide:** `.trellis/spec/guides/retrieval-daily-guide.md` — when to use rg, codegraph, fast-context-mcp, smart-search-cli (and Cursor web fallback), artifact/session memory, codebase router (suggest-only), and explicit retrieval-pack scoring.
110
-
111
- **Cursor subagent dispatch:** `.trellis/spec/guides/cursor-subagent-policy.md` — `trellis-research` / `trellis-implement` / `trellis-check`; Parent child default **Task** `trellis-implement` from Parent session (`generate-child-prompt --mode subagent`). **Cursor++ BYOK:** per-type models via `.trellis/local/cursor2plus/` + user/project JSON maps (not committed slugs). **Native Cursor API:** frontmatter `model:` on agents still works. PRD Grill stays in `trellis-brainstorm`, not a subagent. **Cursor++:** compatible v0.0.11+ (SubAgent readonly bug fixed).
112
-
113
- ---
114
-
115
- <!--
116
- WORKFLOW-STATE BREADCRUMB CONTRACT (read this before editing the tag blocks below)
117
-
118
- The [workflow-state:STATUS] blocks embedded in the ## Phase Index section
119
- below are the SINGLE source of truth for the per-turn `<workflow-state>`
120
- breadcrumb that Cursor's UserPromptSubmit hook reads. inject-workflow-state.py
121
- only parses them — there is no
122
- fallback dict baked into the scripts after v0.5.0-rc.0.
123
-
124
- STATUS charset: [A-Za-z0-9_-]+. When the hook can't find a tag, it
125
- degrades to a generic "Refer to workflow.md for current step." line —
126
- intentionally visible so users notice and fix a broken workflow.md.
127
-
128
- INVARIANT (test/regression.test.ts):
129
- Every workflow-walkthrough step marked `[required · once]` must have a
130
- matching enforcement line in its phase's [workflow-state:*] block. The
131
- breadcrumb is the only per-turn channel; if a mandatory step isn't
132
- mentioned there, the AI silently skips it (Phase 1 planning gate
133
- skip and Phase 3.4 commit skip both manifested via this gap).
134
-
135
- TAG ↔ PHASE scoping:
136
- [workflow-state:no_task] → framework active, selected task none; before Phase 1
137
- [workflow-state:planning] → all of Phase 1 (status='planning')
138
- [workflow-state:in_progress] → Phase 2 + Phase 3.1-3.4
139
- (status stays 'in_progress' from
140
- start-execution --approved until task.py archive)
141
- [workflow-state:completed] → currently DEAD: cmd_archive flips
142
- status and moves the dir in the same
143
- call, so the resolver loses the
144
- pointer (block kept for a future
145
- explicit in_progress→completed
146
- transition)
147
-
148
- Editing checklist:
149
- - When you change a [workflow-state:STATUS] block, also check the
150
- matching phase's `[required · once]` walkthrough steps for sync
151
- - Run `trellis update` after editing to push the new bodies to
152
- downstream user projects (block-level managed replacement)
153
- - Full runtime contract:
154
- .trellis/spec/cli/backend/workflow-state-contract.md
155
- -->
156
-
157
- ## Phase Index
158
-
159
- ```
160
- Phase 1: Plan → classify, get task-creation consent, then write planning artifacts
161
- Phase 2: Execute → implement only after task status is in_progress
162
- Phase 3: Finish → verify, record learning decision, commit, and guarded archive
163
- ```
164
-
165
- ### Request Triage (mandatory before any work)
166
-
167
- **Every turn that could produce work must be classified before acting.** This is a hard gate, not a suggestion. Resolve the request against the Task Ladder decision tree below, then emit the classification mark. If you cannot classify, you have not understood the request — ask a clarifying question instead of starting work.
168
-
169
- Decision tree (first match wins):
170
-
171
- 1. **No durable project change** (conversation, status, explanation, read-only lookup, tiny one-turn action) → `No Task`.
172
- 2. **Underspecified small request, no task yet** (needs focused clarification or decision pressure before work exists) → `Micro-Grill` (load `trellis-micro-grill`).
173
- 3. **Low-risk durable work, narrow scope, local validation, no shared contract** → `Lite Task`.
174
- 4. **Durable code/template/runtime/workflow/cross-file behavior, or framework semantics** → `Full Task`.
175
- 5. **Multiple independent deliverables, staged/parallel execution, or final integration authority** → `Parent Task / Child Tasks`.
176
-
177
- Classification mark (R2 — visible audit trail). Start your reply with one line in this exact shape:
178
-
179
- ```
180
- [Triage: <Mode>] <one-sentence reason citing the trigger signal>
181
- ```
182
-
183
- - `<Mode>` ∈ `No Task | Micro-Grill | Lite | Full | Parent`.
184
- - The reason must reference the trigger signal from the Task Ladder table (e.g. "cross-file workflow change", "read-only explanation"). Vague reasons like "looks complex" are not acceptable.
185
- - For `No Task` turns the mark is still required — it is how the user audits that you actually classified rather than skipped.
186
-
187
- Consent gate. After classifying into any mode that creates a task, ask the user for task-creation consent before creating any Trellis artifact. User approval to create a task is **not** approval to start implementation — planning still happens first. If the user declines a task for a simple request, skip Trellis for this session.
188
-
189
- Selected-task continuity. When a `selected_task` already exists, do not rerun global classification on every follow-up; continue inside the selected task unless a strong conflict exists (explicit exit/switch/create language, out-of-scope request, different artifact/archive target, new independent deliverable, contract-changing request, or evidence pollution risk).
190
-
191
- ### Task Ladder And Routing
192
-
193
- Classify by risk and persistence, not raw effort size. A short change to durable framework semantics can require a Full Task; a long conversation can remain No Task when it leaves no durable project state.
194
-
195
- | Mode | Use when | Trigger signals | Durable artifacts |
196
- | --- | --- | --- | --- |
197
- | No Task | Conversation, status, explanation, read-only lookup, or a tiny one-turn action with no durable project change. | explain / status / lookup / read-only / one-liner | None. No archive unless upgraded. |
198
- | Micro-Grill | The user needs focused clarification, decision pressure, or a small requirement interrogation before deciding whether work exists. | small + underspecified / "depends" / needs clarification / decision tree first | Usually none. Upgrade before durable edits, validation, gates, or archive evidence. |
199
- | Lite Task | Low-risk durable work with narrow scope, local validation, and no shared contract change. | low-risk / single file / local validation / no contract / narrow scope | `task.json`, `prd.md`, `verify.md`, and archive evidence. |
200
- | Full Task | Durable code, template, runtime, workflow, or cross-file behavior where design, execution strategy, validation, or reviewer gates matter. | cross-file / framework semantics / contract change / template / runtime / workflow / multi-file behavior | `prd.md`, `design.md`, `implement.md`, `verify.md`, Development Strategy Contract, `verification_profile`, `quality_gates`, and archive evidence. |
201
- | Parent Task / Child Tasks | One request contains independent deliverables, staged execution, parallel execution, or final integration authority that must be owned by a Parent. | multiple independent deliverables / staged / parallel / integration authority | Parent `task-map.md`, Child task artifacts, Child handoff evidence, Parent final integration evidence. |
202
-
203
- Default Trellis framework semantics, task model, platform adapters, MCP/capability setup, runtime integration, retrieval/graph tooling, Parent/Child orchestration, and quality-gate work to Full Task or higher.
204
-
205
- When `Selected task: none`, enter repo-first routing: read local instructions/workflow evidence, run `task.py dashboard` when useful, classify the request on the ladder, and ask for task-creation consent before creating artifacts. Do not auto-select an existing task.
206
-
207
- When a `selected_task` already exists, do not rerun global classification on every follow-up. Continue inside the selected task unless a strong conflict exists: explicit exit/switch/create language, an out-of-scope request, a different task artifact or archive target, a new independent deliverable, a contract-changing request, or evidence pollution risk. A contract-changing request under `selected_task` routes to that selected task's Planning flow unless the user explicitly switches or creates another task.
208
-
209
- ### Upgrade / Downgrade Rules
210
-
211
- - No Task -> Micro-Grill when the turn needs structured clarification or a decision tree before work can be safely classified.
212
- - Micro-Grill -> Lite/Full when the outcome needs persistent task artifacts, repo edits, validation evidence, quality gates, or archive.
213
- - Lite -> Full when scope touches shared contracts, multi-file behavior, framework semantics, platform/runtime/capability assumptions, `verification_profile`, `quality_gates`, or rollback-sensitive validation.
214
- - Full -> Parent/Child only when the work has independent deliverables, staged execution, parallel execution, or Parent-controlled final integration needs.
215
-
216
- Before executing an upgrade that creates artifacts, changes task mode, adds gates, changes `verification_profile` or capabilities, or changes approval requirements, get explicit user confirmation. Every downgrade needs explicit user confirmation because it reduces artifact, gate, validation, or approval rigor.
217
-
218
- ### Task Ladder quick routing
219
-
220
- | Situation | Action |
221
- |-----------|--------|
222
- | No selected task + small unclear ask | `trellis-micro-grill` |
223
- | No selected task + need dashboard | `trellis-start` |
224
- | Selected task + resume step | `trellis-continue` |
225
- | Planning / PRD | `trellis-brainstorm` |
226
- | Parent with parallel children | `generate-child-prompt --mode subagent`; writable Agent; see `.trellis/spec/guides/cursor-subagent-policy.md` |
227
-
228
- Details: archived `06-15-child-phase3-task-ladder` → `research/task-ladder-iteration.md`.
229
-
230
- ### Planning Artifacts
231
-
232
- - `prd.md` — requirements, constraints, and acceptance criteria. Do not put technical design or execution checklists here.
233
- - `design.md` — technical design for complex tasks: boundaries, contracts, data flow, tradeoffs, compatibility, rollout / rollback shape.
234
- - `implement.md` — execution plan for complex tasks: ordered checklist, Development Strategy Contract, validation commands, review gates, and rollback points.
235
- - `implement.jsonl` / `check.jsonl` — spec and research manifests for sub-agent context. They do not replace `implement.md`.
236
- - `verification_profile` / `quality_gates` — gate policy belongs in task artifacts and `task.json`; `task.json.quality_gate_results` is compact machine-checkable state, not human review prose.
237
- - Lightweight tasks may be PRD-only. Complex tasks must have `prd.md`, `design.md`, and `implement.md` before `task.py start-execution --check`.
238
- - `start-execution` planning gates (`requirements-review`, `architecture-review` when enabled) auto-record on `--approved` when artifacts pass CLI checks; use `record-gate` only as a manual override.
239
-
240
- ### Parent / Child Task Trees
241
-
242
- Use a parent task when one user request contains several independently verifiable deliverables. The parent task owns the source requirement set, the task map, cross-child acceptance criteria, and final integration review; it normally should not be the implementation target unless it also has direct work.
243
-
244
- Use child tasks for deliverables that can be planned, implemented, checked, and archived independently. Parent/child structure is not a dependency system: if one child must wait for another, write that ordering in the child `prd.md` / `implement.md` and keep each child's acceptance criteria testable.
245
-
246
- Create new children with `task.py create "<title>" --slug <name> --parent <parent-dir>`. Link existing tasks with `task.py add-subtask <parent> <child>`, and unlink mistakes with `task.py remove-subtask <parent> <child>`.
247
-
248
- Child Workers report only Child-owned progress states with `task.py set-child-state`: `open`, `working`, `blocked`, or `review`. Parent-controlled setup and decisions use `task.py prepare-child-worktree` and `task.py integrate-child`: `changes`, `accepted`, `integrating`, `integrated`, or `cancelled`. Parent integration requires reviewed evidence, Child `verify.md` / `handoff.md`, and a short `--ref` for accepted/integrating/integrated states. Default Parent `merge_limit: 1` blocks more than one Child from being `integrating` at the same time.
249
-
250
- Integration is Parent/Child-only. Ordinary Lite and Full Tasks skip Integration and go from Verification / Review to Archive / Learning checks. A Child can provide evidence and request review, but cannot mark itself `changes`, `accepted`, `integrating`, `integrated`, or `cancelled`; only the Parent has integration authority. Parent integration is serial Git-ref integration by default: Child worktrees are prepared explicitly, Child decisions carry refs, `integrate-child ... integrated --execute-merge` runs an explicit no-commit merge when requested, and every decision respects `merge_limit: 1` and writes conflicts, merge decisions, and acceptance rationale to `task-map.md` Event Log.
251
-
252
- ### Parent reviewer orchestration (inline or optional subagent)
253
-
254
- Parent sessions can productize child dispatch and review without a new agent runtime:
255
-
256
- ```bash
257
- python3 ./.trellis/scripts/task.py parent-status <parent-task>
258
- python3 ./.trellis/scripts/task.py generate-child-prompt <parent-task> <child-task> --mode inline
259
- python3 ./.trellis/scripts/task.py review-child <parent-task> <child-task> --check --decision accept --ref <child-ref>
260
- python3 ./.trellis/scripts/task.py review-child <parent-task> <child-task> --decision accept --ref <child-ref>
261
- python3 ./.trellis/scripts/task.py review-child <parent-task> <child-task> --decision integrate-through --ref <child-ref>
262
- ```
263
-
264
- - `generate-child-prompt` reads parent `task-map.md` for `depends_on` and `touches`, child artifacts, and optional parent `child-prompts.md`. Use `--mode subagent` only as a delivery hint when the platform can spawn subagents; inline mode remains the portable default.
265
- - `review-child` summarizes child `verify.md` / `handoff.md`, appends notes to parent `verify.md`, and can advance `accepted` / `integrating` / `integrated` in one flow (`--decision integrate-through`) while still using the same Stage 0 integration guards as `integrate-child`.
266
- - Reviewer quality gates are **not** auto-recorded. CLI enforces them at transition boundaries:
267
- - **Full Child accept / integrate-through**: requires substantive `verify.md` evidence and `child-review/code-review` (plus configured architecture gates) before Parent marks the Child `accepted`.
268
- - **Parent archive**: requires every structural Child `integrated` or `cancelled`, substantive Parent integration evidence, and `parent-integrated/integration-review`.
269
- - **Lite closeout**: explicit no-gate chain; archive still requires validation, acceptance, and durable-learning evidence in `verify.md`.
270
- - **`record-gate`**: rejects PASS/SKIPPED when transition evidence is missing or placeholder-only.
271
-
272
- <!-- Per-turn breadcrumb: shown when no task is selected (before Phase 1) -->
273
-
274
- [workflow-state:no_task]
275
- Trellis framework active. Selected task: none. Use `task.py dashboard` for routing; do not auto-select an existing task.
276
- MANDATORY TRIAGE (hard gate, not optional): every work-capable turn must be classified FIRST, before any action, into No Task / Micro-Grill / Lite Task / Full Task / Parent Task — see "Request Triage" in workflow.md for the decision tree. Emit the classification as the first line of your reply: `[Triage: <Mode>] <one-sentence reason citing the trigger signal>`. If you cannot classify, you have not understood the request — ask a clarifying question instead of starting work.
277
- After classifying into any mode that creates a task, ask the user for task-creation consent before creating any Trellis artifact. User consent to create a task is NOT consent to start implementation — planning still happens first.
278
- Underspecified small request with no task: load `trellis-micro-grill` before creating artifacts or upgrading the ladder.
279
- Framework refresh with no selected task: load `trellis-start` once; after the user selects a task, use `trellis-continue` for step-level resume—not `trellis-start`.
280
- [/workflow-state:no_task]
281
-
282
- ### Phase 1: Plan
283
- - 1.0 Create task `[required · once]` (only after task-creation consent)
284
- - 1.1 Requirement exploration `[required · repeatable]` (`prd.md`; complex tasks also need `design.md` + `implement.md`)
285
- - 1.2 Research `[optional · repeatable]`
286
- - 1.3 Configure context `[conditional · once]` — Cursor
287
- - 1.4 Execution gate `[required · once]` (`task.py start-execution <task> --check`, explicit approval, then `--approved`; status → in_progress)
288
- - 1.5 Completion criteria
289
-
290
- <!-- Per-turn breadcrumb: shown throughout Phase 1 (status='planning') -->
291
-
292
- [workflow-state:planning]
293
- Load `trellis-brainstorm`; stay in planning.
294
- Lightweight: `prd.md` can be enough. Complex: finish `prd.md`, `design.md`, and `implement.md`; run `task.py start-execution <task> --check`, report PASS with task plus current contract/fingerprint context, and ask for explicit execution approval before `--approved`.
295
- Multi-deliverable scope: consider a parent task plus independently verifiable child tasks; dependencies must be written in child artifacts, not implied by tree position.
296
- Sub-agent mode: curate `implement.jsonl` and `check.jsonl` as spec/research manifests before start.
297
- [/workflow-state:planning]
298
-
299
- ### Phase 2: Execute
300
- - 2.1 Implement `[required · repeatable]`
301
- - 2.2 Quality check `[required · repeatable]`
302
- - 2.3 Rollback `[on demand]`
303
-
304
- <!-- Per-turn breadcrumb: shown while status='in_progress'.
305
- Scope: all of Phase 2 + Phase 3.1-3.4 (status stays 'in_progress' from
306
- start-execution --approved until task.py archive; only archive flips it). The body
307
- therefore must cover every required step from implementation through
308
- commit, including Phase 3.3 learning decision and Phase 3.4 commit. -->
309
-
310
- [workflow-state:in_progress]
311
- Tools: `trellis-implement` / `trellis-research` are sub-agent types only (Task/Agent tool, NOT Skill; there is no skill by these names). `trellis-update-spec` is a skill for durable learning only. `trellis-check` exists as both; prefer the Agent form when verifying after code changes.
312
- Flow: `trellis-implement` -> `trellis-check` -> validation/evidence in `verify.md` -> learning decision -> commit (Phase 3.4) -> `task.py archive <task> --check` -> `/trellis:finish-work`.
313
- Execution boundary: implement only inside approved `prd.md`, `design.md`, `implement.md`, and Development Strategy Contract; stop and Return-to-Planning for scope, contract, gate, capability/runtime, Parent `contract_epoch`, Child boundary, selected-task fit, or non-implementation reviewer-gate changes.
314
- Main-session default: dispatch implement/check sub-agents. Sub-agent self-exemption: if already running as `trellis-implement`, do NOT spawn another `trellis-implement` or `trellis-check`; if already running as `trellis-check`, do NOT spawn another `trellis-check` or `trellis-implement`. Dispatch is main session only.
315
- Dispatch prompt starts with `Selected task: <task path from task.py selected>`. Read context: jsonl entries -> `prd.md` -> `design.md if present` -> `implement.md if present`.
316
- [/workflow-state:in_progress]
317
-
318
- ### Phase 3: Finish
319
- - 3.1 Quality verification `[required · repeatable]`
320
- - 3.2 Debug retrospective `[on demand]`
321
- - 3.3 Learning decision `[required · once]`
322
- - 3.4 Commit changes `[required · once]`
323
- - 3.5 Wrap-up reminder
324
-
325
- <!-- Per-turn breadcrumb: shown while status='completed'.
326
- Currently DEAD in normal flow: cmd_archive writes status='completed' in
327
- the same call that moves the task dir to archive/, so the selected-task
328
- resolver loses the pointer and the hook never fires on archived tasks.
329
- Block preserved for a future status-transition redesign (e.g. an
330
- explicit in_progress→completed command). Edit through the same spec
331
- channel as the live blocks. -->
332
-
333
- [workflow-state:completed]
334
- Code committed. Run `/trellis:finish-work`; if dirty, return to Phase 3.4 first.
335
- [/workflow-state:completed]
336
-
337
- ### Rules
338
-
339
- 1. Identify which Phase you're in, then continue from the next step there
340
- 2. Run steps in order inside each Phase; `[required]` steps can't be skipped
341
- 3. Phases can roll back (e.g., Execute reveals a prd defect → return to Plan to fix, then re-enter Execute)
342
- 4. Steps tagged `[once]` are skipped if the output already exists; don't re-run
343
- 5. Artifact presence informs the next step; missing `design.md` / `implement.md` is valid for lightweight tasks and incomplete planning for complex tasks.
344
- 6. Return-to-Planning triggers must refresh affected artifacts, gates, fingerprints, and explicit execution approval before Execution resumes.
345
-
346
- ### Active Task Routing
347
-
348
- When a user request matches one of these intents inside a selected task, route first, then load the detailed phase step if needed.
349
-
350
-
351
- - Planning or unclear requirements -> `trellis-brainstorm`.
352
- - `in_progress` implementation/check -> dispatch `trellis-implement` / `trellis-check`.
353
- - Repeated debugging -> `trellis-break-loop`; spec updates -> `trellis-update-spec`.
354
-
355
-
356
-
357
- ### Guardrails
358
-
359
- - Task creation approval is not implementation approval; implementation waits for passing `task.py start-execution <task> --check`, explicit user execution approval, and `task.py start-execution <task> --approved`.
360
- - Planning stops at `task.py start-execution <task> --check` plus an explicit execution-approval request. Planning may not perform implementation edits, mutate execution status, start child execution, integrate children, archive, or claim completion.
361
- - Ordinary conversational confirmations such as "confirm", "agree", "ok", or "start" are not execution authorization unless they answer the explicit execution-approval prompt after a passing `--check`.
362
- - PRD-only is valid for lightweight tasks; complex tasks need `design.md` + `implement.md`.
363
- - Planning must be persisted to task artifacts; checks must run before reporting completion.
364
- - `verify.md` is the human-readable evidence center. `task.json.quality_gate_results` stores compact machine-checkable gate summaries and references only.
365
-
366
- ### Return-to-Planning
367
-
368
- Return to Planning when continued execution would change the approved contract: PRD scope or acceptance criteria, design boundary, dependency, rollback, or validation strategy, Development Strategy Contract, `quality_gates`, `verification_profile`, capability/runtime assumptions, Parent `contract_epoch`, Child boundary, selected-task fit, or a non-implementation reviewer-gate root cause.
369
-
370
- When returning to Planning, update the affected planning artifacts, refresh gate records or fingerprints that depend on them, rerun `task.py start-execution <task> --check`, report the new task and contract/fingerprint context, and ask for explicit execution approval again before `--approved`.
371
-
372
- Implementation defects inside the already approved contract route back to Execution, not Planning. Validation environment blockers stay in Verification / Review until the environment or evidence path is resolved. Repeated same-issue review/gate loops require escalation to the user instead of silent retries.
373
-
374
- ### Loading Step Detail
375
-
376
- At each step, run this to fetch detailed guidance:
377
-
378
- ```bash
379
- python3 ./.trellis/scripts/get_context.py --mode phase --step <step>
380
- # e.g. python3 ./.trellis/scripts/get_context.py --mode phase --step 1.1
381
- ```
382
-
383
- ---
384
-
385
- ## Phase 1: Plan
386
-
387
- Goal: classify the request, get task-creation consent when a task is needed, and produce the planning artifacts required before implementation.
388
-
389
- #### 1.0 Create task `[required · once]`
390
-
391
- Create the task directory only after task-creation consent. The command sets status to `planning`, writes `task.json`, and creates a default `prd.md`. It does not select the task, start execution, or approve execution:
392
-
393
- ```bash
394
- python3 ./.trellis/scripts/task.py create "<task title>" --slug <name>
395
- ```
396
-
397
- `--slug` is the human-readable name only. Do **not** include the `MM-DD-` date prefix; `task.py create` adds that prefix automatically.
398
-
399
- For task trees, create the parent task first and then create each child with `--parent <parent-dir>`. Do not start the parent just because children exist; start the child that owns the next independently verifiable deliverable.
400
-
401
- After creation, select the task only when the user has chosen it for this live session:
402
-
403
- ```bash
404
- python3 ./.trellis/scripts/task.py select <task-dir>
405
- ```
406
-
407
- After selection, the per-turn breadcrumb switches to `[workflow-state:planning]`, telling the AI to stay in planning.
408
-
409
- Run only `create` and, when appropriate, `select` here. Do not run `start-execution --approved` until step 1.4 passes its non-mutating `--check` and the user gives explicit execution approval.
410
-
411
- Skip when the user has already explicitly selected an appropriate task with `python3 ./.trellis/scripts/task.py select <task>`.
412
-
413
- #### 1.1 Requirement exploration `[required · repeatable]`
414
-
415
- Load the `trellis-brainstorm` skill and explore requirements interactively with the user per the skill's guidance.
416
-
417
- The brainstorm skill will guide you to:
418
- - Ask one question at a time
419
- - Prefer researching over asking the user
420
- - Prefer offering options over open-ended questions
421
- - Update `prd.md` immediately after each user answer
422
- - Split large scopes into a parent task plus child tasks when the deliverables can be verified independently
423
- - Keep `prd.md` focused on requirements and acceptance criteria
424
- - For complex tasks, produce `design.md` and `implement.md` before implementation starts
425
-
426
- When considering a parent/child split:
427
- - Use a parent task when one request contains several independently verifiable deliverables.
428
- - Parent tasks own source requirements, child-task mapping, cross-child acceptance criteria, and final integration review.
429
- - Child tasks own actual deliverables that can be planned, implemented, checked, and archived independently.
430
- - Parent/child structure is not a dependency system. If child B depends on child A, write that ordering in child B's `prd.md` / `implement.md`.
431
- - Start the child task that owns the next deliverable. Do not start the parent unless the parent itself has direct implementation work.
432
-
433
- Return to this step whenever requirements change and revise the relevant artifact.
434
-
435
- #### 1.2 Research `[optional · repeatable]`
436
-
437
- Research can happen at any time during requirement exploration. It isn't limited to local code you can use any available tool (MCP servers, skills, web search, etc.) to look up external information, including third-party library docs, industry practices, API references, etc.
438
-
439
-
440
- Spawn the research sub-agent:
441
-
442
- - **Agent type**: `trellis-research`
443
- - **Task description**: Research <specific question>
444
- - **Key requirement**: Research output MUST be persisted to `{TASK_DIR}/research/`
445
-
446
-
447
-
448
- **Retrieval during research**:
449
- - Use `python3 ./.trellis/scripts/search_artifacts.py --query "<topic>" --json` to find durable Trellis specs, prior tasks, research, verification notes, and workspace journals before re-discovering framework context.
450
- - Use `codebase-retrieval` evidence levels for source-code questions: adapter output is candidate evidence until current source, Git, or validation confirms it.
451
- - Persist useful exploratory retrieval chains, adapter availability, and competing hypotheses under `{TASK_DIR}/research/`.
452
-
453
- **Research artifact conventions**:
454
- - One file per research topic (e.g. `research/auth-library-comparison.md`)
455
- - Record third-party library usage examples, API references, version constraints in files
456
- - Note relevant spec file paths you discovered for later reference
457
- - Optional reusable-research frontmatter can make findings easier to rediscover:
458
- ```markdown
459
- ---
460
- doc_type: research
461
- status: active
462
- confidence: medium
463
- scope: authentication
464
- related_files:
465
- - src/auth/login.ts
466
- ---
467
- ```
468
- - Recommended reusable-research sections: Quick Answer, Key Evidence, Details, Risks / Open Questions, Next Steps
469
- - Evidence claims should include file paths, commands, URLs, or validation output when available
470
-
471
- Brainstorm and research can interleave freely — pause to research a technical question, then return to talk with the user.
472
-
473
- **Key principle**: Research output must be written to files, not left only in the chat. Conversations get compacted; files don't.
474
-
475
- #### 1.3 Configure context `[required · once]`
476
-
477
-
478
- Curate `implement.jsonl` and `check.jsonl` so the Phase 2 sub-agents get the right spec/research context. These files were seeded on `task create` with a single self-describing `_example` line; your job here is to fill in real entries.
479
-
480
- **Location**: `{TASK_DIR}/implement.jsonl` and `{TASK_DIR}/check.jsonl` (already exist).
481
-
482
- **Format**: one JSON object per line `{"file": "<path>", "reason": "<why>"}`. Paths are repo-root relative.
483
-
484
- **What to put in**:
485
- - **Spec files** — `.trellis/spec/<package>/<layer>/index.md` and any specific guideline files (`error-handling.md`, `conventions.md`, etc.) relevant to this task
486
- - **Research files** — `{TASK_DIR}/research/*.md` that the sub-agent will need to consult
487
-
488
- **What NOT to put in**:
489
- - Code files (`src/**`, `packages/**/*.ts`, etc.) those are read by the sub-agent during implementation, not pre-registered here
490
- - Files you're about to modify same reason
491
-
492
- **Split between the two files**:
493
- - `implement.jsonl` specs + research the implement sub-agent needs to write code correctly
494
- - `check.jsonl` specs for the check sub-agent (quality guidelines, check conventions, same research if needed)
495
-
496
- These manifests do not replace `implement.md`. `implement.md` is the human-readable execution plan for a complex task; jsonl files only list context files to inject or load.
497
-
498
- **How to discover relevant specs**:
499
-
500
- ```bash
501
- python3 ./.trellis/scripts/get_context.py --mode packages
502
- ```
503
-
504
- Lists every package + its spec layers with paths. Pick the entries that match this task's domain.
505
-
506
- Use artifact search when prior task/research evidence is likely relevant:
507
-
508
- ```bash
509
- python3 ./.trellis/scripts/search_artifacts.py --query "<topic>" --json
510
- ```
511
-
512
- Add any reusable `{TASK_DIR}/research/*.md` files you discovered when sub-agents need them.
513
-
514
- **How to append entries**:
515
-
516
- Either edit the jsonl file directly in your editor, or use:
517
-
518
- ```bash
519
- python3 ./.trellis/scripts/task.py add-context "$TASK_DIR" implement "<path>" "<reason>"
520
- python3 ./.trellis/scripts/task.py add-context "$TASK_DIR" check "<path>" "<reason>"
521
- ```
522
-
523
- Delete the seed `_example` line once real entries exist (optional — it's skipped automatically by consumers).
524
-
525
- Skip when: `implement.jsonl` and `check.jsonl` have agent-curated entries (the seed row alone doesn't count).
526
-
527
-
528
-
529
- #### 1.4 Execution gate `[required · once]`
530
-
531
- After artifact review, run the non-mutating execution preflight:
532
-
533
- ```bash
534
- python3 ./.trellis/scripts/task.py start-execution <task-dir> --check
535
- ```
536
-
537
- For lightweight tasks, `prd.md` can be enough. For complex tasks, `prd.md`, `design.md`, and `implement.md` must exist and be reviewed before execution approval. On Cursor (sub-agent dispatch), curate jsonl manifests when extra spec or research context is needed; seed-only manifests are tolerated by consumers.
538
-
539
- If `--check` passes, report that artifact gates are ready and include the task name/path plus current contract/fingerprint context. Then ask the user for explicit execution approval and state that approval permits `task.py start-execution <task-dir> --approved`. Ordinary agreement such as "confirm", "agree", "ok", or "start" before this preflight is not execution approval.
540
-
541
- Only after the user approves execution in that context, run:
542
-
543
- ```bash
544
- python3 ./.trellis/scripts/task.py start-execution <task-dir> --approved
545
- ```
546
-
547
- After this command succeeds, the breadcrumb switches to `[workflow-state:in_progress]`, and the rest of Phase 2 / 3 follows.
548
-
549
- #### 1.5 Completion criteria
550
-
551
- | Condition | Required |
552
- |------|:---:|
553
- | `prd.md` exists | ✅ |
554
- | `task.py start-execution <task> --check` passes | ✅ |
555
- | User explicitly approves execution after the passing preflight is reported | |
556
- | `task.py start-execution <task> --approved` has been run (status = in_progress) | ✅ |
557
- | `research/` has artifacts (complex tasks) | recommended |
558
- | `design.md` exists (complex tasks) | ✅ |
559
- | `implement.md` exists (complex tasks) | ✅ |
560
-
561
-
562
- | `implement.jsonl` / `check.jsonl` curated when extra spec or research context is needed | recommended |
563
-
564
-
565
- ---
566
-
567
- ## Phase 2: Execute
568
-
569
- Goal: turn reviewed planning artifacts into code that passes quality checks.
570
-
571
- Execution is bounded by the approved `prd.md`, `design.md`, `implement.md`, and Development Strategy Contract. Follow the contract's `execution_mode`, `verification_profile`, and `quality_gates`; do not global-reclassify the request, auto-switch selected tasks, auto-create new task scope, or edit planning artifacts to change scope, design, or contract while pretending execution is still approved.
572
-
573
- Stop Execution and Return-to-Planning for PRD scope/acceptance changes, design boundary/dependency/rollback/validation changes, Development Strategy Contract changes, quality gate changes, capability/runtime assumption changes, Parent `contract_epoch` changes, Child boundary changes, selected-task scope mismatch, or non-implementation reviewer-gate failures. Refresh gates/fingerprints and get explicit approval before continuing.
574
-
575
- Implementation defects inside the approved contract remain Execution work: fix them in Phase 2, update `verify.md` evidence, and re-run validation without changing the approved contract.
576
-
577
- #### 2.1 Implement `[required · repeatable]`
578
-
579
- Use retrieval layers before and during implementation when context is incomplete:
580
- - `python3 ./.trellis/scripts/search_artifacts.py --query "<topic>" --json` for durable Trellis specs, prior task artifacts, research, verification notes, and journals.
581
- - `codebase-retrieval` evidence levels for source claims: candidate -> corroborated candidate -> verified claim; unresolved or unavailable adapters must be reported instead of treated as proof.
582
- - Record exploratory chains in `{TASK_DIR}/research/` and final source/Git/test proof in `verify.md`.
583
-
584
-
585
- Spawn the implement sub-agent (Full / Parent Cursor):
586
-
587
- - **Agent type**: `trellis-implement`
588
- - **Orchestrator contract**: After `start-execution --approved`, the main session assembles the full dispatch prompt via Trellis scripts (CLI Layer 2), then calls `Task(subagent_type=trellis-implement, prompt=<assembled>)`. Do **not** rely on the preToolUse hook alone for context on Cursor — see `cursor-context-injection-guide.md`.
589
- - **Dispatch prompt guard**: Tell the spawned agent it is already the `trellis-implement` sub-agent and must implement directly, not spawn another `trellis-implement` / `trellis-check`.
590
-
591
- Context embedded in the dispatch prompt includes `implement.jsonl` references, `prd.md`, `design.md` if present, and `implement.md` if present.
592
-
593
- #### 2.2 Quality check `[required · repeatable]`
594
-
595
-
596
- Spawn the check sub-agent (Full / Parent — Cursor):
597
-
598
- - **Agent type**: `trellis-check`
599
- - **Orchestrator contract**: Assemble the full dispatch prompt via Trellis scripts (CLI Layer 2) before `Task(subagent_type=trellis-check, prompt=<assembled>)`. Hook-only injection is best-effort on Cursor.
600
- - **Dispatch prompt guard**: Tell the spawned agent it is already the `trellis-check` sub-agent and must review/fix only inside the approved contract, not spawn another `trellis-check` / `trellis-implement`.
601
-
602
- The check agent's job:
603
- - Review code changes against specs
604
- - Review code changes against `prd.md`, `design.md` if present, and `implement.md` if present
605
- - Fix implementation defects only when they stay inside the approved contract
606
- - Route requirement, design, contract, scope, gate, capability, runtime, Parent `contract_epoch`, or Child boundary defects to Return-to-Planning
607
- - Run lint and typecheck to verify
608
-
609
-
610
-
611
- #### 2.3 Rollback `[on demand]`
612
-
613
- - `check` reveals a PRD, design, contract, scope, gate, capability/runtime, Parent `contract_epoch`, or Child boundary defect → Return-to-Planning, refresh gates/fingerprints, and get explicit approval again
614
- - Implementation went wrong → revert code, redo 2.1
615
- - Need more research → research (same as Phase 1.2), write findings into `research/`
616
-
617
- ---
618
-
619
- ## Phase 3: Finish
620
-
621
- Goal: ensure code quality, capture lessons, record the work.
622
-
623
- #### Evidence scoring (retrieval-pack, explicit)
624
-
625
- For **complex** tasks, optionally before 3.1 when you have collected retrieval evidence JSON (e.g. after Phase 1.2 smart-search manifests in `{TASK}/research/smart-search/`):
626
-
627
- `python3 ./.trellis/scripts/get_context.py --mode retrieval-pack --json --input <path-to-evidence.json>`
628
-
629
- Use `contextPack.selected` / `scoredEvidence` to order citations in `verify.md`. Do **not** expect scoring in default `get_context --json`.
630
-
631
- #### 3.1 Quality verification `[required · repeatable]`
632
-
633
- Verification / Review is evidence and judgment, not a hidden implementation loop. Load the `trellis-check` skill or agent and do a final review:
634
- - Spec compliance
635
- - lint / type-check / tests
636
- - Cross-layer consistency (when changes span layers)
637
- - Retrieval evidence: final claims must cite current source, Git, or validation proof; unresolved adapter or artifact-search gaps belong in `verify.md`
638
- - Reviewer gate evidence via `task.py record-gate <task> <transition> <gate> <PASS|FAIL|SKIPPED>` when a configured gate applies
639
- - Human-readable validation, review, and acceptance evidence in `verify.md`
640
-
641
- Do not silently implement fixes, expand scope, or edit planning artifacts during Verification / Review. Review-found implementation defects inside the approved contract route back to Execution. Requirement, design, contract, scope, gate-configuration, capability/runtime, Parent `contract_epoch`, or Child boundary defects route back to Planning. Validation environment blockers stay in Verification / Review with explicit blocker evidence.
642
-
643
- `verify.md` is the evidence center for humans. `task.json.quality_gate_results` should contain only compact machine-checkable results, fingerprints, timestamps, reviewer ids, evidence references, and root-cause metadata.
644
-
645
- #### 3.2 Debug retrospective `[on demand]`
646
-
647
- If this task involved repeated debugging (the same issue was fixed multiple times), load the `trellis-break-loop` skill to:
648
- - Classify the root cause
649
- - Explain why earlier fixes failed
650
- - Propose prevention
651
-
652
- The goal is to capture debugging lessons so the same class of issue doesn't recur.
653
-
654
- #### 3.3 Learning decision `[required · once]`
655
-
656
- Review whether this task produced durable learning worth recording:
657
- - repeated failure loops or debugging lessons;
658
- - requirement drift, architecture decisions, reusable conventions, or toolchain pitfalls;
659
- - new project-local patterns that should affect future work.
660
-
661
- If durable learning exists, load `trellis-update-spec` and update `.trellis/spec/` or write a focused `retrospective.md`, then link that evidence from `verify.md`.
662
-
663
- If no durable learning exists, write an explicit `No durable learning` decision in `verify.md`. Do not run a spec update only to satisfy ceremony.
664
-
665
- Before archive, `verify.md` must contain validation evidence, final acceptance evidence, gate/review references when applicable, and the durable-learning decision. Parent tasks with children must also include final integration evidence.
666
-
667
- #### 3.4 Commit changes `[required · once]`
668
-
669
- The AI drives a batched commit of this task's code changes so `/finish-work` can run cleanly afterwards. Goal: produce work commits FIRST, then bookkeeping (archive + journal) commits land after — never interleaved.
670
-
671
- **Step-by-step**:
672
-
673
- 1. **Inspect dirty state**:
674
- ```bash
675
- git status --porcelain
676
- ```
677
- Snapshot every dirty path. If the working tree is clean, skip to 3.5.
678
-
679
- 2. **Learn commit style** from recent history (so drafted messages blend in):
680
- ```bash
681
- git log --oneline -5
682
- ```
683
- Note the prefix convention (`feat:` / `fix:` / `chore:` / `docs:` ...), language (中文/English), and length style.
684
-
685
- 3. **Classify dirty files into two groups**:
686
- - **AI-edited this session** — files you wrote/edited via Edit/Write/Bash tool calls in this session. You know what changed and why.
687
- - **Unrecognized** — dirty files you did NOT touch this session (could be the user's manual edits, leftover WIP from a previous session, or unrelated work). Do NOT silently include these.
688
-
689
- 4. **Draft a commit plan**. Group AI-edited files into logical commits (1 commit per coherent change unit, not 1 commit per file). Each entry: `<commit message>` + file list. List unrecognized files separately at the bottom.
690
-
691
- 5. **Present the plan once, ask for one-shot confirmation**. Format:
692
- ```
693
- Proposed commits (in order):
694
- 1. <message>
695
- - <file>
696
- - <file>
697
- 2. <message>
698
- - <file>
699
-
700
- Unrecognized dirty files (NOT in any commit — confirm include/exclude):
701
- - <file>
702
- - <file>
703
-
704
- Reply 'ok' / '行' to execute. Reply with edits, or '我自己来' / 'manual' to abort.
705
- ```
706
-
707
- 6. **On confirmation**: run `git add <files>` + `git commit -m "<msg>"` for each batch in order. Do not amend. Do not push.
708
-
709
- 7. **On rejection** (user replies "不行" / "我自己来" / "manual" / any pushback on the plan): stop. Do not attempt a second plan. The user will commit by hand; you skip ahead to 3.5 once they confirm.
710
-
711
- **Rules**:
712
- - No `git commit --amend` anywhere three-stage three-commit flow (work commits archive commit journal commit).
713
- - Never push to remote in this step.
714
- - If the user wants different message wording but accepts the file grouping, edit the message and re-confirm once but if they reject the grouping, exit to manual mode.
715
- - The batched plan is one prompt; do not prompt per commit.
716
-
717
- #### 3.5 Archive / Learning
718
-
719
- Run `task.py archive <task> --check` before the real archive. The check must pass without moving files, changing status, clearing selected-task state, staging or committing, or running hooks.
720
-
721
- Real completion is only `task.py archive <task>`. It writes `status=completed`, moves the task to `archive/<YYYY-MM>/`, clears selected-task pointers for that task, and runs archive hooks. Passing validation, user acceptance, reviewer gates, or writing `verify.md` alone does not complete the task.
722
-
723
- Archive readiness by mode:
724
-
725
- | Mode | Archive readiness |
726
- |---|---|
727
- | No Task | No archive; upgrade to a durable task mode before archive is possible. |
728
- | Micro-Grill | No archive unless upgraded into Lite, Full, or Parent/Child. |
729
- | Lite | Explicit no-gate chain. `verify.md` has substantive validation, final acceptance, and durable-learning decision evidence. |
730
- | Full | Lite evidence plus required completion gates (`full-task-complete/*`), substantive check/change-set evidence, fresh fingerprints, and no unresolved required `FAIL` gates. |
731
- | Child | Lite or Full evidence (by child profile). Full Children require `child-review` gates before Parent `accepted`. Parent task-map marks the Child `integrated` or `cancelled`; integrated Children include `handoff.md`. |
732
- | Parent | Archive evidence plus every Child `integrated` or `cancelled`, substantive final integration evidence, and `parent-integrated/integration-review`. |
733
-
734
- Archive / Learning is terminal. After archive, do not silently mutate archived task artifacts; follow-up work requires a new task unless the user explicitly approves an archive amendment.
735
-
736
- If archive is not being run in this session, report the passing or failing archive check and the remaining evidence gaps.
737
-
738
- ---
739
-
740
- ## Customizing Trellis (for forks)
741
-
742
- This section is for developers who want to modify the Trellis workflow itself. All customization is done by editing this file; the scripts are parsers only.
743
-
744
- ### Changing what a step means
745
-
746
- Edit the corresponding step's walkthrough body in the Phase 1 / 2 / 3 sections above. Critical invariants:
747
- - No selected task must use framework/dashboard routing, then triage and ask for task-creation consent before creating a Trellis task.
748
- - Planning must distinguish lightweight PRD-only tasks from complex tasks that require `prd.md`, `design.md`, and `implement.md` before start.
749
- - Every required execution path must keep the Phase 3.4 commit reminder reachable before `/trellis:finish-work`.
750
-
751
- All tag blocks live in the `## Phase Index` section above, immediately after each phase summary:
752
-
753
- | Scope | Corresponding tag |
754
- |---|---|
755
- | No selected task (before Phase 1) | `[workflow-state:no_task]` (after the Phase Index ASCII art) |
756
- | All of Phase 1 (task created ready for implementation) | `[workflow-state:planning]` (after Phase 1 summary) |
757
- | Phase 2 + Phase 3.1–3.4 (implementation + check + wrap-up) | `[workflow-state:in_progress]` (after Phase 2 summary) |
758
- | After Phase 3.5 (archived) | `[workflow-state:completed]` (after Phase 3 summary; **currently DEAD**) |
759
-
760
- ### Changing the per-turn prompt text
761
-
762
- Directly edit the body of the corresponding `[workflow-state:STATUS]` block. After editing, run `trellis update` (if you're a template maintainer) or restart your AI session (if you're customizing your own project) — no script changes required.
763
-
764
- ### Adding a custom status
765
-
766
- Add a new block:
767
-
768
- ```
769
- [workflow-state:my-status]
770
- your per-turn prompt text
771
- [/workflow-state:my-status]
772
- ```
773
-
774
- Constraints:
775
- - STATUS charset: `[A-Za-z0-9_-]+` (underscores and hyphens allowed, e.g. `in-review`, `blocked-by-team`)
776
- - A lifecycle hook must write `task.json.status` to your custom value, otherwise the tag is never read
777
- - Lifecycle hooks live in `task.json.hooks.after_*` and bind to one of `after_create / after_start / after_finish / after_archive`
778
-
779
- ### Adding a lifecycle hook
780
-
781
- Add a `hooks` field to your `task.json`:
782
-
783
- ```json
784
- {
785
- "hooks": {
786
- "after_archive": [
787
- "your-script-or-command-here"
788
- ]
789
- }
790
- }
791
- ```
792
-
793
- Supported events: `after_create / after_start / after_archive`. Use `after_archive` for "task is done" notifications. Historical `after_finish` hooks are not part of the selected-task workflow because `task.py finish` no longer exists.
794
-
795
- ### Full contract
796
-
797
- For the workflow state machine's runtime contract, the locations of all status writers, pseudo-statuses (`no_task` / `stale_<source_type>`), the hook reachability matrix, and other deep details, see:
798
-
799
- - `.trellis/spec/cli/backend/workflow-state-contract.md` — runtime contract + writer table + test invariants
800
- - `.trellis/scripts/inject-workflow-state.py` — actual parser (reads workflow.md only, no embedded text)
1
+ # Development Workflow
2
+
3
+ ---
4
+
5
+ ## Core Principles
6
+
7
+ 1. **Plan before code** — figure out what to do before you start
8
+ 2. **Specs injected, not remembered** — guidelines are injected via hook/skill, not recalled from memory
9
+ 3. **Persist everything** — research, decisions, and lessons all go to files; conversations get compacted, files don't
10
+ 4. **Incremental development** — one task at a time
11
+ 5. **Capture learnings** — after each task, review and write new knowledge back to spec
12
+
13
+ ---
14
+
15
+ ## Trellis System
16
+
17
+ ### Developer Identity
18
+
19
+ On first use, initialize your identity:
20
+
21
+ ```bash
22
+ python3 ./.trellis/scripts/init_developer.py <your-name>
23
+ ```
24
+
25
+ Creates `.trellis/.developer` (gitignored) + `.trellis/workspace/<your-name>/`.
26
+
27
+ ### Spec System
28
+
29
+ `.trellis/spec/` holds coding guidelines organized by package and layer.
30
+
31
+ - `.trellis/spec/<package>/<layer>/index.md` — entry point with **Pre-Development Checklist** + **Quality Check**. Actual guidelines live in the `.md` files it points to.
32
+ - `.trellis/spec/guides/index.md` — cross-package thinking guides.
33
+
34
+ ```bash
35
+ python3 ./.trellis/scripts/get_context.py --mode packages # list packages / layers
36
+ ```
37
+
38
+ **When to update spec**: new pattern/convention found · bug-fix prevention to codify · new technical decision.
39
+
40
+ ### Task System
41
+
42
+ Every task has its own directory under `.trellis/tasks/{MM-DD-name}/` holding `task.json`, `prd.md`, optional `design.md`, optional `implement.md`, optional `research/`, and context manifests (`implement.jsonl`, `check.jsonl`) for Cursor (sub-agent dispatch).
43
+
44
+ ```bash
45
+ # Task lifecycle
46
+ python3 ./.trellis/scripts/task.py create "<title>" [--slug <name>] [--parent <dir>]
47
+ python3 ./.trellis/scripts/task.py dashboard # show Task Dashboard without mutating state
48
+ python3 ./.trellis/scripts/task.py select <name> # select task for this live session
49
+ python3 ./.trellis/scripts/task.py selected --source # show selected task and source
50
+ python3 ./.trellis/scripts/task.py start-execution <name> --check
51
+ python3 ./.trellis/scripts/task.py start-execution <name> --approved
52
+ python3 ./.trellis/scripts/task.py exit # clear selected task without changing status
53
+ python3 ./.trellis/scripts/task.py archive <name> # move to archive/{year-month}/
54
+ python3 ./.trellis/scripts/task.py list [--mine] [--status <s>]
55
+ python3 ./.trellis/scripts/task.py list-archive
56
+ python3 ./.trellis/scripts/task.py add-subtask <parent> <child>
57
+ python3 ./.trellis/scripts/task.py set-child-state <parent> <child> review --evidence verify.md
58
+ python3 ./.trellis/scripts/task.py prepare-child-worktree <parent> <child> --branch <child-branch>
59
+ python3 ./.trellis/scripts/task.py integrate-child <parent> <child> accepted --evidence handoff.md --ref <child-ref>
60
+
61
+ # Code-spec context (injected into implement/check agents via JSONL).
62
+ # `implement.jsonl` / `check.jsonl` are seeded on `task create` for sub-agent-capable
63
+ # platforms; the AI curates real spec + research entries during planning when needed.
64
+ python3 ./.trellis/scripts/task.py add-context <name> <action> <file> <reason>
65
+ python3 ./.trellis/scripts/task.py list-context <name> [action]
66
+ python3 ./.trellis/scripts/task.py validate <name>
67
+
68
+ # Task metadata
69
+ python3 ./.trellis/scripts/task.py set-branch <name> <branch>
70
+ python3 ./.trellis/scripts/task.py set-base-branch <name> <branch> # PR target
71
+ python3 ./.trellis/scripts/task.py set-scope <name> <scope>
72
+
73
+ # Hierarchy (parent/child)
74
+ python3 ./.trellis/scripts/task.py add-subtask <parent> <child>
75
+ python3 ./.trellis/scripts/task.py remove-subtask <parent> <child>
76
+
77
+ # PR creation
78
+ python3 ./.trellis/scripts/task.py create-pr [name] [--dry-run]
79
+ ```
80
+
81
+ > Run `python3 ./.trellis/scripts/task.py --help` to see the authoritative, up-to-date list.
82
+
83
+ **Selected-task mechanism**: entering a Trellis project activates framework context, but every new live session starts with `Selected task: none`. `task.py create` creates artifacts only. `task.py select <task>` writes a per-session `selected_task` pointer without changing `task.json.status`. `task.py selected --source` reports that pointer. `task.py exit` clears it without changing status. `task.py start-execution <task> --check` verifies execution readiness without mutation; `task.py start-execution <task> --approved` is the explicit execution boundary and may flip `planning` to `in_progress`. `task.py archive <task>` writes `status=completed`, moves the directory to `archive/`, and deletes runtime session files that still point at the archived task.
84
+
85
+ ### Workspace System
86
+
87
+ Records every AI session for cross-session tracking under `.trellis/workspace/<developer>/`.
88
+
89
+ - `journal-N.md` — session log. **Max 2000 lines per file**; a new `journal-(N+1).md` is auto-created when exceeded.
90
+ - `index.md` — personal index (total sessions, last active).
91
+
92
+ ```bash
93
+ python3 ./.trellis/scripts/add_session.py --title "Title" --commit "hash" --summary "Summary"
94
+ ```
95
+
96
+ ### Context Script
97
+
98
+ ```bash
99
+ python3 ./.trellis/scripts/get_context.py # full session runtime
100
+ python3 ./.trellis/scripts/get_context.py --mode packages # available packages + spec layers
101
+ python3 ./.trellis/scripts/get_context.py --mode phase --step <X.Y> # detailed guide for a workflow step
102
+ python3 ./.trellis/scripts/get_context.py --mode retrieval-pack --json --input <evidence.json> # score collected evidence (not default --json)
103
+ ```
104
+
105
+ **Evidence scoring:** default `--json` returns `retrievalGuide` only. After collecting artifact search, session memory, smart-search manifests under `{TASK}/research/smart-search/`, or codebase candidates, run **`--mode retrieval-pack`** with `--input` or stdin JSON. See `research/evidence-scoring-integration.md` in the active task or archived `06-15-child-phase2-evidence-scoring`.
106
+
107
+ **Research-end hook (Cursor `stop`):** when the selected task has `{TASK}/research/*.md` or `research/smart-search/`, `.cursor/hooks/research-end-retrieval-pack.py` may write `{TASK}/research/retrieval-pack-latest.json` via `get_context --mode retrieval-pack`. Default session JSON is unchanged; use the file when closing research or before Phase 3.1.
108
+
109
+ **Retrieval daily guide:** `.trellis/spec/guides/retrieval-daily-guide.md` — when to use rg, codegraph, fast-context-mcp, smart-search-cli (and Cursor web fallback), artifact/session memory, codebase router (suggest-only), and explicit retrieval-pack scoring.
110
+
111
+ **Cursor subagent dispatch:** `.trellis/spec/guides/cursor-subagent-policy.md` — `trellis-research` / `trellis-implement` / `trellis-check`; Parent child default **Task** `trellis-implement` from Parent session (`generate-child-prompt --mode subagent`). **Cursor++ BYOK:** per-type models via `.trellis/local/cursor2plus/` + user/project JSON maps (not committed slugs). **Native Cursor API:** frontmatter `model:` on agents still works. PRD Grill stays in `trellis-brainstorm`, not a subagent. **Cursor++:** compatible v0.0.11+ (SubAgent readonly bug fixed).
112
+
113
+ ---
114
+
115
+ <!--
116
+ WORKFLOW-STATE BREADCRUMB CONTRACT (read this before editing the tag blocks below)
117
+
118
+ The [workflow-state:STATUS] blocks embedded in the ## Phase Index section
119
+ below are the SINGLE source of truth for the per-turn `<workflow-state>`
120
+ breadcrumb that Cursor's UserPromptSubmit hook reads. inject-workflow-state.py
121
+ only parses them — there is no
122
+ fallback dict baked into the scripts after v0.5.0-rc.0.
123
+
124
+ STATUS charset: [A-Za-z0-9_-]+. When the hook can't find a tag, it
125
+ degrades to a generic "Refer to workflow.md for current step." line —
126
+ intentionally visible so users notice and fix a broken workflow.md.
127
+
128
+ INVARIANT (test/regression.test.ts):
129
+ Every workflow-walkthrough step marked `[required · once]` must have a
130
+ matching enforcement line in its phase's [workflow-state:*] block. The
131
+ breadcrumb is the only per-turn channel; if a mandatory step isn't
132
+ mentioned there, the AI silently skips it (Phase 1 planning gate
133
+ skip and Phase 3.4 commit skip both manifested via this gap).
134
+
135
+ TAG ↔ PHASE scoping:
136
+ [workflow-state:no_task] → framework active, selected task none; before Phase 1
137
+ [workflow-state:planning] → all of Phase 1 (status='planning')
138
+ [workflow-state:in_progress] → Phase 2 + Phase 3.1-3.4
139
+ (status stays 'in_progress' from
140
+ start-execution --approved until task.py archive)
141
+ [workflow-state:completed] → currently DEAD: cmd_archive flips
142
+ status and moves the dir in the same
143
+ call, so the resolver loses the
144
+ pointer (block kept for a future
145
+ explicit in_progress→completed
146
+ transition)
147
+
148
+ Editing checklist:
149
+ - When you change a [workflow-state:STATUS] block, also check the
150
+ matching phase's `[required · once]` walkthrough steps for sync
151
+ - Run `trellis update` after editing to push the new bodies to
152
+ downstream user projects (block-level managed replacement)
153
+ - Full runtime contract:
154
+ .trellis/spec/cli/backend/workflow-state-contract.md
155
+ -->
156
+
157
+ ## Phase Index
158
+
159
+ ```
160
+ Phase 1: Plan → classify, get task-creation consent, then write planning artifacts
161
+ Phase 2: Execute → implement only after task status is in_progress
162
+ Phase 3: Finish → verify, record learning decision, commit, and guarded archive
163
+ ```
164
+
165
+ ### Request Triage (mandatory before any work)
166
+
167
+ **Every turn that could produce work must be classified before acting.** This is a hard gate, not a suggestion. Resolve the request against the Task Ladder decision tree below, then emit the classification mark. If you cannot classify, you have not understood the request — ask a clarifying question instead of starting work.
168
+
169
+ Decision tree (first match wins):
170
+
171
+ 1. **No durable project change** (conversation, status, explanation, read-only lookup, tiny one-turn action) → `No Task`.
172
+ 2. **Underspecified small request, no task yet** (needs focused clarification or decision pressure before work exists) → `Micro-Grill` (load `trellis-micro-grill`).
173
+ 3. **Low-risk durable work, narrow scope, local validation, no shared contract** → `Lite Task`.
174
+ 4. **Durable code/template/runtime/workflow/cross-file behavior, or framework semantics** → `Full Task`.
175
+ 5. **Multiple independent deliverables, staged/parallel execution, or final integration authority** → `Parent Task / Child Tasks`.
176
+
177
+ Classification mark (R2 — visible audit trail). Start your reply with one line in this exact shape:
178
+
179
+ ```
180
+ [Triage: <Mode>] <one-sentence reason citing the trigger signal>
181
+ ```
182
+
183
+ - `<Mode>` ∈ `No Task | Micro-Grill | Lite | Full | Parent`.
184
+ - The reason must reference the trigger signal from the Task Ladder table (e.g. "cross-file workflow change", "read-only explanation"). Vague reasons like "looks complex" are not acceptable.
185
+ - For `No Task` turns the mark is still required — it is how the user audits that you actually classified rather than skipped.
186
+
187
+ Consent gate. After classifying into any mode that creates a task, ask the user for task-creation consent before creating any Trellis artifact. User approval to create a task is **not** approval to start implementation — planning still happens first. If the user declines a task for a simple request, skip Trellis for this session.
188
+
189
+ Selected-task continuity. When a `selected_task` already exists, do not rerun global classification on every follow-up; continue inside the selected task unless a strong conflict exists (explicit exit/switch/create language, out-of-scope request, different artifact/archive target, new independent deliverable, contract-changing request, or evidence pollution risk).
190
+
191
+ ### Task Ladder And Routing
192
+
193
+ Classify by risk and persistence, not raw effort size. A short change to durable framework semantics can require a Full Task; a long conversation can remain No Task when it leaves no durable project state.
194
+
195
+ | Mode | Use when | Trigger signals | Durable artifacts |
196
+ | --- | --- | --- | --- |
197
+ | No Task | Conversation, status, explanation, read-only lookup, or a tiny one-turn action with no durable project change. | explain / status / lookup / read-only / one-liner | None. No archive unless upgraded. |
198
+ | Micro-Grill | The user needs focused clarification, decision pressure, or a small requirement interrogation before deciding whether work exists. | small + underspecified / "depends" / needs clarification / decision tree first | Usually none. Upgrade before durable edits, validation, gates, or archive evidence. |
199
+ | Lite Task | Low-risk durable work with narrow scope, local validation, and no shared contract change. | low-risk / single file / local validation / no contract / narrow scope | `task.json`, `prd.md`, `verify.md`, and archive evidence. |
200
+ | Full Task | Durable code, template, runtime, workflow, or cross-file behavior where design, execution strategy, validation, or reviewer gates matter. | cross-file / framework semantics / contract change / template / runtime / workflow / multi-file behavior | `prd.md`, `design.md`, `implement.md`, `verify.md`, Development Strategy Contract, `verification_profile`, `quality_gates`, and archive evidence. |
201
+ | Parent Task / Child Tasks | One request contains independent deliverables, staged execution, parallel execution, or final integration authority that must be owned by a Parent. | multiple independent deliverables / staged / parallel / integration authority | Parent `task-map.md`, Child task artifacts, Child handoff evidence, Parent final integration evidence. |
202
+
203
+ Default Trellis framework semantics, task model, platform adapters, MCP/capability setup, runtime integration, retrieval/graph tooling, Parent/Child orchestration, and quality-gate work to Full Task or higher.
204
+
205
+ When `Selected task: none`, enter repo-first routing: read local instructions/workflow evidence, run `task.py dashboard` when useful, classify the request on the ladder, and ask for task-creation consent before creating artifacts. Do not auto-select an existing task.
206
+
207
+ When a `selected_task` already exists, do not rerun global classification on every follow-up. Continue inside the selected task unless a strong conflict exists: explicit exit/switch/create language, an out-of-scope request, a different task artifact or archive target, a new independent deliverable, a contract-changing request, or evidence pollution risk. A contract-changing request under `selected_task` routes to that selected task's Planning flow unless the user explicitly switches or creates another task.
208
+
209
+ ### Upgrade / Downgrade Rules
210
+
211
+ - No Task -> Micro-Grill when the turn needs structured clarification or a decision tree before work can be safely classified.
212
+ - Micro-Grill -> Lite/Full when the outcome needs persistent task artifacts, repo edits, validation evidence, quality gates, or archive.
213
+ - Lite -> Full when scope touches shared contracts, multi-file behavior, framework semantics, platform/runtime/capability assumptions, `verification_profile`, `quality_gates`, or rollback-sensitive validation.
214
+ - Full -> Parent/Child only when the work has independent deliverables, staged execution, parallel execution, or Parent-controlled final integration needs.
215
+
216
+ Before executing an upgrade that creates artifacts, changes task mode, adds gates, changes `verification_profile` or capabilities, or changes approval requirements, get explicit user confirmation. Every downgrade needs explicit user confirmation because it reduces artifact, gate, validation, or approval rigor.
217
+
218
+ ### Task Ladder quick routing
219
+
220
+ | Situation | Action |
221
+ |-----------|--------|
222
+ | No selected task + small unclear ask | `trellis-micro-grill` |
223
+ | No selected task + need dashboard | `trellis-start` |
224
+ | Selected task + resume step | `trellis-continue` |
225
+ | Planning / PRD | `trellis-brainstorm` |
226
+ | Parent with parallel children | `generate-child-prompt --mode subagent`; writable Agent; see `.trellis/spec/guides/cursor-subagent-policy.md` |
227
+
228
+ Details: archived `06-15-child-phase3-task-ladder` → `research/task-ladder-iteration.md`.
229
+
230
+ ### Planning Artifacts
231
+
232
+ - `prd.md` — requirements, constraints, and acceptance criteria. Do not put technical design or execution checklists here.
233
+ - `design.md` — technical design for complex tasks: boundaries, contracts, data flow, tradeoffs, compatibility, rollout / rollback shape.
234
+ - `implement.md` — execution plan for complex tasks: ordered checklist, Development Strategy Contract, validation commands, review gates, and rollback points.
235
+ - `implement.jsonl` / `check.jsonl` — spec and research manifests for sub-agent context. They do not replace `implement.md`.
236
+ - `verification_profile` / `quality_gates` — gate policy belongs in task artifacts and `task.json`; `task.json.quality_gate_results` is compact machine-checkable state, not human review prose.
237
+ - Lightweight tasks may be PRD-only. Complex tasks must have `prd.md`, `design.md`, and `implement.md` before `task.py start-execution --check`.
238
+ - `start-execution` planning gates (`requirements-review`, `architecture-review` when enabled) auto-record on `--approved` when artifacts pass CLI checks; use `record-gate` only as a manual override.
239
+
240
+ ### Parent / Child Task Trees
241
+
242
+ Use a parent task when one user request contains several independently verifiable deliverables. The parent task owns the source requirement set, the task map, cross-child acceptance criteria, and final integration review; it normally should not be the implementation target unless it also has direct work.
243
+
244
+ Use child tasks for deliverables that can be planned, implemented, checked, and archived independently. Parent/child structure is not a dependency system: if one child must wait for another, write that ordering in the child `prd.md` / `implement.md` and keep each child's acceptance criteria testable.
245
+
246
+ Create new children with `task.py create "<title>" --slug <name> --parent <parent-dir>`. Link existing tasks with `task.py add-subtask <parent> <child>`, and unlink mistakes with `task.py remove-subtask <parent> <child>`.
247
+
248
+ Child Workers report only Child-owned progress states with `task.py set-child-state`: `open`, `working`, `blocked`, or `review`. Parent-controlled setup and decisions use `task.py prepare-child-worktree` and `task.py integrate-child`: `changes`, `accepted`, `integrating`, `integrated`, or `cancelled`. Parent integration requires reviewed evidence, Child `verify.md` / `handoff.md`, and a short `--ref` for accepted/integrating/integrated states. Default Parent `merge_limit: 1` blocks more than one Child from being `integrating` at the same time.
249
+
250
+ Integration is Parent/Child-only. Ordinary Lite and Full Tasks skip Integration and go from Verification / Review to Archive / Learning checks. A Child can provide evidence and request review, but cannot mark itself `changes`, `accepted`, `integrating`, `integrated`, or `cancelled`; only the Parent has integration authority. Parent integration is serial Git-ref integration by default: Child worktrees are prepared explicitly, Child decisions carry refs, `integrate-child ... integrated --execute-merge` runs an explicit no-commit merge when requested, and every decision respects `merge_limit: 1` and writes conflicts, merge decisions, and acceptance rationale to `task-map.md` Event Log.
251
+
252
+ ### Parent reviewer orchestration (inline or optional subagent)
253
+
254
+ Parent sessions can productize child dispatch and review without a new agent runtime:
255
+
256
+ ```bash
257
+ python3 ./.trellis/scripts/task.py parent-status <parent-task>
258
+ python3 ./.trellis/scripts/task.py generate-child-prompt <parent-task> <child-task> --mode inline
259
+ python3 ./.trellis/scripts/task.py review-child <parent-task> <child-task> --check --decision accept --ref <child-ref>
260
+ python3 ./.trellis/scripts/task.py review-child <parent-task> <child-task> --decision accept --ref <child-ref>
261
+ python3 ./.trellis/scripts/task.py review-child <parent-task> <child-task> --decision integrate-through --ref <child-ref>
262
+ ```
263
+
264
+ - `generate-child-prompt` reads parent `task-map.md` for `depends_on` and `touches`, child artifacts, and optional parent `child-prompts.md`. Use `--mode subagent` only as a delivery hint when the platform can spawn subagents; inline mode remains the portable default.
265
+ - `review-child` summarizes child `verify.md` / `handoff.md`, appends notes to parent `verify.md`, and can advance `accepted` / `integrating` / `integrated` in one flow (`--decision integrate-through`) while still using the same Stage 0 integration guards as `integrate-child`.
266
+ - Reviewer quality gates are **not** auto-recorded. CLI enforces them at transition boundaries:
267
+ - **Full Child accept / integrate-through**: requires substantive `verify.md` evidence and `child-review/code-review` (plus configured architecture gates) before Parent marks the Child `accepted`.
268
+ - **Parent archive**: requires every structural Child `integrated` or `cancelled`, substantive Parent integration evidence, and `parent-integrated/integration-review`.
269
+ - **Lite closeout**: explicit no-gate chain; archive still requires validation, acceptance, and durable-learning evidence in `verify.md`.
270
+ - **`record-gate`**: rejects PASS/SKIPPED when transition evidence is missing or placeholder-only.
271
+
272
+ <!-- Per-turn breadcrumb: shown when no task is selected (before Phase 1) -->
273
+
274
+ [workflow-state:no_task]
275
+ Trellis framework active. Selected task: none. Use `task.py dashboard` for routing; do not auto-select an existing task.
276
+ MANDATORY TRIAGE (hard gate, not optional): every work-capable turn must be classified FIRST, before any action, into No Task / Micro-Grill / Lite Task / Full Task / Parent Task — see "Request Triage" in workflow.md for the decision tree. Emit the classification as the first line of your reply: `[Triage: <Mode>] <one-sentence reason citing the trigger signal>`. If you cannot classify, you have not understood the request — ask a clarifying question instead of starting work.
277
+ After classifying into any mode that creates a task, ask the user for task-creation consent before creating any Trellis artifact. User consent to create a task is NOT consent to start implementation — planning still happens first.
278
+ Underspecified small request with no task: load `trellis-micro-grill` before creating artifacts or upgrading the ladder.
279
+ Framework refresh with no selected task: load `trellis-start` once; after the user selects a task, use `trellis-continue` for step-level resume—not `trellis-start`.
280
+ [/workflow-state:no_task]
281
+
282
+ ### Phase 1: Plan
283
+ - 1.0 Create task `[required · once]` (only after task-creation consent)
284
+ - 1.1 Requirement exploration `[required · repeatable]` (`prd.md`; complex tasks also need `design.md` + `implement.md`)
285
+ - 1.2 Research `[optional · repeatable]`
286
+ - 1.3 Configure context `[conditional · once]` — Cursor
287
+ - 1.4 Execution gate `[required · once]` (`task.py start-execution <task> --check`, explicit approval, then `--approved`; status → in_progress)
288
+ - 1.5 Completion criteria
289
+
290
+ <!-- Per-turn breadcrumb: shown throughout Phase 1 (status='planning') -->
291
+
292
+ [workflow-state:planning]
293
+ Load `trellis-brainstorm`; stay in planning.
294
+ Lightweight: `prd.md` can be enough. Complex: finish `prd.md`, `design.md`, and `implement.md`; run `task.py start-execution <task> --check`, report PASS with task plus current contract/fingerprint context, and ask for explicit execution approval before `--approved`.
295
+ Multi-deliverable scope: consider a parent task plus independently verifiable child tasks; dependencies must be written in child artifacts, not implied by tree position.
296
+ Sub-agent mode: curate `implement.jsonl` and `check.jsonl` as spec/research manifests before start.
297
+ [/workflow-state:planning]
298
+
299
+ ### Phase 2: Execute
300
+ - 2.1 Implement `[required · repeatable]`
301
+ - 2.2 Quality check `[required · repeatable]`
302
+ - 2.3 Rollback `[on demand]`
303
+
304
+ <!-- Per-turn breadcrumb: shown while status='in_progress'.
305
+ Scope: all of Phase 2 + Phase 3.1-3.4 (status stays 'in_progress' from
306
+ start-execution --approved until task.py archive; only archive flips it). The body
307
+ therefore must cover every required step from implementation through
308
+ commit, including Phase 3.3 learning decision and Phase 3.4 commit. -->
309
+
310
+ [workflow-state:in_progress]
311
+ Tools: `trellis-implement` / `trellis-research` are sub-agent types only (Task/Agent tool, NOT Skill; there is no skill by these names). `trellis-update-spec` is a skill for durable learning only. `trellis-check` exists as both; prefer the Agent form when verifying after code changes when `execution_mode: worker`.
312
+ Execution boundary: implement only inside approved `prd.md`, `design.md`, `implement.md`, and Development Strategy Contract; stop and Return-to-Planning for scope, contract, gate, capability/runtime, Parent `contract_epoch`, Child boundary, selected-task fit, or non-implementation reviewer-gate changes.
313
+ Follow the approved contract's `execution_mode` for Phase 2 (see Phase 2.1 / 2.2):
314
+ - `inline` main session implements and checks (use `trellis-check` skill or inline review); do NOT spawn `trellis-implement` / `trellis-check` agents unless you explicitly re-negotiate the contract.
315
+ - `worker` main session dispatches `trellis-implement` then `trellis-check` agents (CLI Layer 2 dispatch prompt + `Task`).
316
+ - `child-task` — Child session or Parent orchestration per `task-map.md`; main session does not replace Child delivery.
317
+ Flow after implementation path: validation/evidence in `verify.md` -> learning decision -> commit (Phase 3.4) -> `task.py archive <task> --check` -> `/trellis:finish-work`.
318
+ Sub-agent self-exemption: if already running as `trellis-implement`, do NOT spawn another `trellis-implement` or `trellis-check`; if already running as `trellis-check`, do NOT spawn another `trellis-check` or `trellis-implement`. Dispatch is main session only.
319
+ Dispatch prompt starts with `Selected task: <task path from task.py selected>`. Read context: jsonl entries -> `prd.md` -> `design.md if present` -> `implement.md if present`.
320
+ [/workflow-state:in_progress]
321
+
322
+ ### Phase 3: Finish
323
+ - 3.1 Quality verification `[required · repeatable]`
324
+ - 3.2 Debug retrospective `[on demand]`
325
+ - 3.3 Learning decision `[required · once]`
326
+ - 3.4 Commit changes `[required · once]`
327
+ - 3.5 Wrap-up reminder
328
+
329
+ <!-- Per-turn breadcrumb: shown while status='completed'.
330
+ Currently DEAD in normal flow: cmd_archive writes status='completed' in
331
+ the same call that moves the task dir to archive/, so the selected-task
332
+ resolver loses the pointer and the hook never fires on archived tasks.
333
+ Block preserved for a future status-transition redesign (e.g. an
334
+ explicit in_progress→completed command). Edit through the same spec
335
+ channel as the live blocks. -->
336
+
337
+ [workflow-state:completed]
338
+ Code committed. Run `/trellis:finish-work`; if dirty, return to Phase 3.4 first.
339
+ [/workflow-state:completed]
340
+
341
+ ### Rules
342
+
343
+ 1. Identify which Phase you're in, then continue from the next step there
344
+ 2. Run steps in order inside each Phase; `[required]` steps can't be skipped
345
+ 3. Phases can roll back (e.g., Execute reveals a prd defect → return to Plan to fix, then re-enter Execute)
346
+ 4. Steps tagged `[once]` are skipped if the output already exists; don't re-run
347
+ 5. Artifact presence informs the next step; missing `design.md` / `implement.md` is valid for lightweight tasks and incomplete planning for complex tasks.
348
+ 6. Return-to-Planning triggers must refresh affected artifacts, gates, fingerprints, and explicit execution approval before Execution resumes.
349
+
350
+ ### Active Task Routing
351
+
352
+ When a user request matches one of these intents inside a selected task, route first, then load the detailed phase step if needed.
353
+
354
+
355
+ - Planning or unclear requirements -> `trellis-brainstorm`.
356
+ - `in_progress` implementation/check -> if contract `execution_mode: worker`, dispatch `trellis-implement` / `trellis-check`; if `inline`, main session; if `child-task`, Child/Parent orchestration.
357
+ - Repeated debugging -> `trellis-break-loop`; spec updates -> `trellis-update-spec`.
358
+
359
+
360
+
361
+ ### Guardrails
362
+
363
+ - Task creation approval is not implementation approval; implementation waits for passing `task.py start-execution <task> --check`, explicit user execution approval, and `task.py start-execution <task> --approved`.
364
+ - Planning stops at `task.py start-execution <task> --check` plus an explicit execution-approval request. Planning may not perform implementation edits, mutate execution status, start child execution, integrate children, archive, or claim completion.
365
+ - Ordinary conversational confirmations such as "confirm", "agree", "ok", or "start" are not execution authorization unless they answer the explicit execution-approval prompt after a passing `--check`.
366
+ - PRD-only is valid for lightweight tasks; complex tasks need `design.md` + `implement.md`.
367
+ - Planning must be persisted to task artifacts; checks must run before reporting completion.
368
+ - `verify.md` is the human-readable evidence center. `task.json.quality_gate_results` stores compact machine-checkable gate summaries and references only.
369
+
370
+ ### Return-to-Planning
371
+
372
+ Return to Planning when continued execution would change the approved contract: PRD scope or acceptance criteria, design boundary, dependency, rollback, or validation strategy, Development Strategy Contract, `quality_gates`, `verification_profile`, capability/runtime assumptions, Parent `contract_epoch`, Child boundary, selected-task fit, or a non-implementation reviewer-gate root cause.
373
+
374
+ When returning to Planning, update the affected planning artifacts, refresh gate records or fingerprints that depend on them, rerun `task.py start-execution <task> --check`, report the new task and contract/fingerprint context, and ask for explicit execution approval again before `--approved`.
375
+
376
+ Implementation defects inside the already approved contract route back to Execution, not Planning. Validation environment blockers stay in Verification / Review until the environment or evidence path is resolved. Repeated same-issue review/gate loops require escalation to the user instead of silent retries.
377
+
378
+ ### Loading Step Detail
379
+
380
+ At each step, run this to fetch detailed guidance:
381
+
382
+ ```bash
383
+ python3 ./.trellis/scripts/get_context.py --mode phase --step <step>
384
+ # e.g. python3 ./.trellis/scripts/get_context.py --mode phase --step 1.1
385
+ ```
386
+
387
+ ---
388
+
389
+ ## Phase 1: Plan
390
+
391
+ Goal: classify the request, get task-creation consent when a task is needed, and produce the planning artifacts required before implementation.
392
+
393
+ #### 1.0 Create task `[required · once]`
394
+
395
+ Create the task directory only after task-creation consent. The command sets status to `planning`, writes `task.json`, and creates a default `prd.md`. It does not select the task, start execution, or approve execution:
396
+
397
+ ```bash
398
+ python3 ./.trellis/scripts/task.py create "<task title>" --slug <name>
399
+ ```
400
+
401
+ `--slug` is the human-readable name only. Do **not** include the `MM-DD-` date prefix; `task.py create` adds that prefix automatically.
402
+
403
+ For task trees, create the parent task first and then create each child with `--parent <parent-dir>`. Do not start the parent just because children exist; start the child that owns the next independently verifiable deliverable.
404
+
405
+ After creation, select the task only when the user has chosen it for this live session:
406
+
407
+ ```bash
408
+ python3 ./.trellis/scripts/task.py select <task-dir>
409
+ ```
410
+
411
+ After selection, the per-turn breadcrumb switches to `[workflow-state:planning]`, telling the AI to stay in planning.
412
+
413
+ Run only `create` and, when appropriate, `select` here. Do not run `start-execution --approved` until step 1.4 passes its non-mutating `--check` and the user gives explicit execution approval.
414
+
415
+ Skip when the user has already explicitly selected an appropriate task with `python3 ./.trellis/scripts/task.py select <task>`.
416
+
417
+ #### 1.1 Requirement exploration `[required · repeatable]`
418
+
419
+ Load the `trellis-brainstorm` skill and explore requirements interactively with the user per the skill's guidance.
420
+
421
+ The brainstorm skill will guide you to:
422
+ - Ask one question at a time
423
+ - Prefer researching over asking the user
424
+ - Prefer offering options over open-ended questions
425
+ - Update `prd.md` immediately after each user answer
426
+ - Split large scopes into a parent task plus child tasks when the deliverables can be verified independently
427
+ - Keep `prd.md` focused on requirements and acceptance criteria
428
+ - For complex tasks, produce `design.md` and `implement.md` before implementation starts
429
+
430
+ When considering a parent/child split:
431
+ - Use a parent task when one request contains several independently verifiable deliverables.
432
+ - Parent tasks own source requirements, child-task mapping, cross-child acceptance criteria, and final integration review.
433
+ - Child tasks own actual deliverables that can be planned, implemented, checked, and archived independently.
434
+ - Parent/child structure is not a dependency system. If child B depends on child A, write that ordering in child B's `prd.md` / `implement.md`.
435
+ - Start the child task that owns the next deliverable. Do not start the parent unless the parent itself has direct implementation work.
436
+
437
+ Return to this step whenever requirements change and revise the relevant artifact.
438
+
439
+ #### 1.2 Research `[optional · repeatable]`
440
+
441
+ Research can happen at any time during requirement exploration. It isn't limited to local code — you can use any available tool (MCP servers, skills, web search, etc.) to look up external information, including third-party library docs, industry practices, API references, etc.
442
+
443
+
444
+ Spawn the research sub-agent:
445
+
446
+ - **Agent type**: `trellis-research`
447
+ - **Task description**: Research <specific question>
448
+ - **Key requirement**: Research output MUST be persisted to `{TASK_DIR}/research/`
449
+
450
+
451
+
452
+ **Retrieval during research**:
453
+ - Use `python3 ./.trellis/scripts/search_artifacts.py --query "<topic>" --json` to find durable Trellis specs, prior tasks, research, verification notes, and workspace journals before re-discovering framework context.
454
+ - Use `codebase-retrieval` evidence levels for source-code questions: adapter output is candidate evidence until current source, Git, or validation confirms it.
455
+ - Persist useful exploratory retrieval chains, adapter availability, and competing hypotheses under `{TASK_DIR}/research/`.
456
+
457
+ **Research artifact conventions**:
458
+ - One file per research topic (e.g. `research/auth-library-comparison.md`)
459
+ - Record third-party library usage examples, API references, version constraints in files
460
+ - Note relevant spec file paths you discovered for later reference
461
+ - Optional reusable-research frontmatter can make findings easier to rediscover:
462
+ ```markdown
463
+ ---
464
+ doc_type: research
465
+ status: active
466
+ confidence: medium
467
+ scope: authentication
468
+ related_files:
469
+ - src/auth/login.ts
470
+ ---
471
+ ```
472
+ - Recommended reusable-research sections: Quick Answer, Key Evidence, Details, Risks / Open Questions, Next Steps
473
+ - Evidence claims should include file paths, commands, URLs, or validation output when available
474
+
475
+ Brainstorm and research can interleave freely — pause to research a technical question, then return to talk with the user.
476
+
477
+ **Key principle**: Research output must be written to files, not left only in the chat. Conversations get compacted; files don't.
478
+
479
+ #### 1.3 Configure context `[required · once]`
480
+
481
+
482
+ Curate `implement.jsonl` and `check.jsonl` so the Phase 2 sub-agents get the right spec/research context. These files were seeded on `task create` with a single self-describing `_example` line; your job here is to fill in real entries.
483
+
484
+ **Location**: `{TASK_DIR}/implement.jsonl` and `{TASK_DIR}/check.jsonl` (already exist).
485
+
486
+ **Format**: one JSON object per line — `{"file": "<path>", "reason": "<why>"}`. Paths are repo-root relative.
487
+
488
+ **What to put in**:
489
+ - **Spec files** `.trellis/spec/<package>/<layer>/index.md` and any specific guideline files (`error-handling.md`, `conventions.md`, etc.) relevant to this task
490
+ - **Research files** `{TASK_DIR}/research/*.md` that the sub-agent will need to consult
491
+
492
+ **What NOT to put in**:
493
+ - Code files (`src/**`, `packages/**/*.ts`, etc.) those are read by the sub-agent during implementation, not pre-registered here
494
+ - Files you're about to modify same reason
495
+
496
+ **Split between the two files**:
497
+ - `implement.jsonl` → specs + research the implement sub-agent needs to write code correctly
498
+ - `check.jsonl` specs for the check sub-agent (quality guidelines, check conventions, same research if needed)
499
+
500
+ These manifests do not replace `implement.md`. `implement.md` is the human-readable execution plan for a complex task; jsonl files only list context files to inject or load.
501
+
502
+ **How to discover relevant specs**:
503
+
504
+ ```bash
505
+ python3 ./.trellis/scripts/get_context.py --mode packages
506
+ ```
507
+
508
+ Lists every package + its spec layers with paths. Pick the entries that match this task's domain.
509
+
510
+ Use artifact search when prior task/research evidence is likely relevant:
511
+
512
+ ```bash
513
+ python3 ./.trellis/scripts/search_artifacts.py --query "<topic>" --json
514
+ ```
515
+
516
+ Add any reusable `{TASK_DIR}/research/*.md` files you discovered when sub-agents need them.
517
+
518
+ **How to append entries**:
519
+
520
+ Either edit the jsonl file directly in your editor, or use:
521
+
522
+ ```bash
523
+ python3 ./.trellis/scripts/task.py add-context "$TASK_DIR" implement "<path>" "<reason>"
524
+ python3 ./.trellis/scripts/task.py add-context "$TASK_DIR" check "<path>" "<reason>"
525
+ ```
526
+
527
+ Delete the seed `_example` line once real entries exist (optional — it's skipped automatically by consumers).
528
+
529
+ Skip when: `implement.jsonl` and `check.jsonl` have agent-curated entries (the seed row alone doesn't count).
530
+
531
+
532
+
533
+ #### 1.4 Execution gate `[required · once]`
534
+
535
+ After artifact review, run the non-mutating execution preflight:
536
+
537
+ ```bash
538
+ python3 ./.trellis/scripts/task.py start-execution <task-dir> --check
539
+ ```
540
+
541
+ For lightweight tasks, `prd.md` can be enough. For complex tasks, `prd.md`, `design.md`, and `implement.md` must exist and be reviewed before execution approval. On Cursor (sub-agent dispatch), curate jsonl manifests when extra spec or research context is needed; seed-only manifests are tolerated by consumers.
542
+
543
+ If `--check` passes, report that artifact gates are ready and include the task name/path plus current contract/fingerprint context. Then ask the user for explicit execution approval and state that approval permits `task.py start-execution <task-dir> --approved`. Ordinary agreement such as "confirm", "agree", "ok", or "start" before this preflight is not execution approval.
544
+
545
+ Only after the user approves execution in that context, run:
546
+
547
+ ```bash
548
+ python3 ./.trellis/scripts/task.py start-execution <task-dir> --approved
549
+ ```
550
+
551
+ After this command succeeds, the breadcrumb switches to `[workflow-state:in_progress]`, and the rest of Phase 2 / 3 follows.
552
+
553
+ #### 1.5 Completion criteria
554
+
555
+ | Condition | Required |
556
+ |------|:---:|
557
+ | `prd.md` exists | |
558
+ | `task.py start-execution <task> --check` passes | ✅ |
559
+ | User explicitly approves execution after the passing preflight is reported | ✅ |
560
+ | `task.py start-execution <task> --approved` has been run (status = in_progress) | ✅ |
561
+ | `research/` has artifacts (complex tasks) | recommended |
562
+ | `design.md` exists (complex tasks) | |
563
+ | `implement.md` exists (complex tasks) | ✅ |
564
+
565
+
566
+ | `implement.jsonl` / `check.jsonl` curated when extra spec or research context is needed | recommended |
567
+
568
+
569
+ ---
570
+
571
+ ## Phase 2: Execute
572
+
573
+ Goal: turn reviewed planning artifacts into code that passes quality checks.
574
+
575
+ Execution is bounded by the approved `prd.md`, `design.md`, `implement.md`, and Development Strategy Contract. Follow the contract's `execution_mode`, `verification_profile`, and `quality_gates`; do not global-reclassify the request, auto-switch selected tasks, auto-create new task scope, or edit planning artifacts to change scope, design, or contract while pretending execution is still approved.
576
+
577
+ Stop Execution and Return-to-Planning for PRD scope/acceptance changes, design boundary/dependency/rollback/validation changes, Development Strategy Contract changes, quality gate changes, capability/runtime assumption changes, Parent `contract_epoch` changes, Child boundary changes, selected-task scope mismatch, or non-implementation reviewer-gate failures. Refresh gates/fingerprints and get explicit approval before continuing.
578
+
579
+ Implementation defects inside the approved contract remain Execution work: fix them in Phase 2, update `verify.md` evidence, and re-run validation without changing the approved contract.
580
+
581
+ #### 2.1 Implement `[required · repeatable]`
582
+
583
+ Use retrieval layers before and during implementation when context is incomplete:
584
+ - `python3 ./.trellis/scripts/search_artifacts.py --query "<topic>" --json` for durable Trellis specs, prior task artifacts, research, verification notes, and journals.
585
+ - `codebase-retrieval` evidence levels for source claims: candidate -> corroborated candidate -> verified claim; unresolved or unavailable adapters must be reported instead of treated as proof.
586
+ - Record exploratory chains in `{TASK_DIR}/research/` and final source/Git/test proof in `verify.md`.
587
+
588
+
589
+ Read `execution_mode` from the approved Development Strategy Contract in `implement.md`:
590
+
591
+ | `execution_mode` | Phase 2.1 implement |
592
+ | --- | --- |
593
+ | `inline` | Main session implements directly in the approved contract. |
594
+ | `worker` | Spawn **`trellis-implement`** (Cursor): after `start-execution --approved`, assemble dispatch prompt via CLI Layer 2, then `Task(subagent_type=trellis-implement, prompt=<assembled>)`. Do **not** rely on preToolUse hook alone — see `cursor-context-injection-guide.md`. Tell the spawned agent it is already `trellis-implement` and must not spawn another `trellis-implement` / `trellis-check`. |
595
+ | `child-task` | Child worker session (or Parent `generate-child-prompt`); isolation per contract (`git-worktree` → `prepare-child-worktree` when applicable). |
596
+
597
+ Context for worker dispatch includes `implement.jsonl` references, `prd.md`, `design.md` if present, and `implement.md` if present.
598
+
599
+ #### 2.2 Quality check `[required · repeatable]`
600
+
601
+ | `execution_mode` | Phase 2.2 check |
602
+ | --- | --- |
603
+ | `inline` | Main session: `trellis-check` **skill** or inline review; record evidence in `verify.md`. |
604
+ | `worker` | Spawn **`trellis-check`** agent: CLI Layer 2 dispatch prompt, then `Task(subagent_type=trellis-check, prompt=<assembled>)`. Agent may fix defects inside the approved contract; must not spawn another check/implement agent. |
605
+ | `child-task` | Child delivers `verify.md` / handoff; Parent reviews via `review-child` when applicable. |
606
+
607
+ The check agent's job:
608
+ - Review code changes against specs
609
+ - Review code changes against `prd.md`, `design.md` if present, and `implement.md` if present
610
+ - Fix implementation defects only when they stay inside the approved contract
611
+ - Route requirement, design, contract, scope, gate, capability, runtime, Parent `contract_epoch`, or Child boundary defects to Return-to-Planning
612
+ - Run lint and typecheck to verify
613
+
614
+
615
+
616
+ #### 2.3 Rollback `[on demand]`
617
+
618
+ - `check` reveals a PRD, design, contract, scope, gate, capability/runtime, Parent `contract_epoch`, or Child boundary defect → Return-to-Planning, refresh gates/fingerprints, and get explicit approval again
619
+ - Implementation went wrong → revert code, redo 2.1
620
+ - Need more research → research (same as Phase 1.2), write findings into `research/`
621
+
622
+ ---
623
+
624
+ ## Phase 3: Finish
625
+
626
+ Goal: ensure code quality, capture lessons, record the work.
627
+
628
+ #### Evidence scoring (retrieval-pack, explicit)
629
+
630
+ For **complex** tasks, optionally before 3.1 when you have collected retrieval evidence JSON (e.g. after Phase 1.2 smart-search manifests in `{TASK}/research/smart-search/`):
631
+
632
+ `python3 ./.trellis/scripts/get_context.py --mode retrieval-pack --json --input <path-to-evidence.json>`
633
+
634
+ Use `contextPack.selected` / `scoredEvidence` to order citations in `verify.md`. Do **not** expect scoring in default `get_context --json`.
635
+
636
+ #### 3.1 Quality verification `[required · repeatable]`
637
+
638
+ Verification / Review is evidence and judgment, not a hidden implementation loop. Load the `trellis-check` skill or agent and do a final review:
639
+ - Spec compliance
640
+ - lint / type-check / tests
641
+ - Cross-layer consistency (when changes span layers)
642
+ - Retrieval evidence: final claims must cite current source, Git, or validation proof; unresolved adapter or artifact-search gaps belong in `verify.md`
643
+ - Reviewer gate evidence via `task.py record-gate <task> <transition> <gate> <PASS|FAIL|SKIPPED>` when a configured gate applies
644
+ - Human-readable validation, review, and acceptance evidence in `verify.md`
645
+
646
+ Do not silently implement fixes, expand scope, or edit planning artifacts during Verification / Review. Review-found implementation defects inside the approved contract route back to Execution. Requirement, design, contract, scope, gate-configuration, capability/runtime, Parent `contract_epoch`, or Child boundary defects route back to Planning. Validation environment blockers stay in Verification / Review with explicit blocker evidence.
647
+
648
+ `verify.md` is the evidence center for humans. `task.json.quality_gate_results` should contain only compact machine-checkable results, fingerprints, timestamps, reviewer ids, evidence references, and root-cause metadata.
649
+
650
+ #### 3.2 Debug retrospective `[on demand]`
651
+
652
+ If this task involved repeated debugging (the same issue was fixed multiple times), load the `trellis-break-loop` skill to:
653
+ - Classify the root cause
654
+ - Explain why earlier fixes failed
655
+ - Propose prevention
656
+
657
+ The goal is to capture debugging lessons so the same class of issue doesn't recur.
658
+
659
+ #### 3.3 Learning decision `[required · once]`
660
+
661
+ Review whether this task produced durable learning worth recording:
662
+ - repeated failure loops or debugging lessons;
663
+ - requirement drift, architecture decisions, reusable conventions, or toolchain pitfalls;
664
+ - new project-local patterns that should affect future work.
665
+
666
+ If durable learning exists, load `trellis-update-spec` and update `.trellis/spec/` or write a focused `retrospective.md`, then link that evidence from `verify.md`.
667
+
668
+ If no durable learning exists, write an explicit `No durable learning` decision in `verify.md`. Do not run a spec update only to satisfy ceremony.
669
+
670
+ Before archive, `verify.md` must contain validation evidence, final acceptance evidence, gate/review references when applicable, and the durable-learning decision. Parent tasks with children must also include final integration evidence.
671
+
672
+ #### 3.4 Commit changes `[required · once]`
673
+
674
+ The AI drives a batched commit of this task's code changes so `/finish-work` can run cleanly afterwards. Goal: produce work commits FIRST, then bookkeeping (archive + journal) commits land after — never interleaved.
675
+
676
+ **Step-by-step**:
677
+
678
+ 1. **Inspect dirty state**:
679
+ ```bash
680
+ git status --porcelain
681
+ ```
682
+ Snapshot every dirty path. If the working tree is clean, skip to 3.5.
683
+
684
+ 2. **Learn commit style** from recent history (so drafted messages blend in):
685
+ ```bash
686
+ git log --oneline -5
687
+ ```
688
+ Note the prefix convention (`feat:` / `fix:` / `chore:` / `docs:` ...), language (中文/English), and length style.
689
+
690
+ 3. **Classify dirty files into two groups**:
691
+ - **AI-edited this session** files you wrote/edited via Edit/Write/Bash tool calls in this session. You know what changed and why.
692
+ - **Unrecognized** — dirty files you did NOT touch this session (could be the user's manual edits, leftover WIP from a previous session, or unrelated work). Do NOT silently include these.
693
+
694
+ 4. **Draft a commit plan**. Group AI-edited files into logical commits (1 commit per coherent change unit, not 1 commit per file). Each entry: `<commit message>` + file list. List unrecognized files separately at the bottom.
695
+
696
+ 5. **Present the plan once, ask for one-shot confirmation**. Format:
697
+ ```
698
+ Proposed commits (in order):
699
+ 1. <message>
700
+ - <file>
701
+ - <file>
702
+ 2. <message>
703
+ - <file>
704
+
705
+ Unrecognized dirty files (NOT in any commit — confirm include/exclude):
706
+ - <file>
707
+ - <file>
708
+
709
+ Reply 'ok' / '行' to execute. Reply with edits, or '我自己来' / 'manual' to abort.
710
+ ```
711
+
712
+ 6. **On confirmation**: run `git add <files>` + `git commit -m "<msg>"` for each batch in order. Do not amend. Do not push.
713
+
714
+ 7. **On rejection** (user replies "不行" / "我自己来" / "manual" / any pushback on the plan): stop. Do not attempt a second plan. The user will commit by hand; you skip ahead to 3.5 once they confirm.
715
+
716
+ **Rules**:
717
+ - No `git commit --amend` anywhere — three-stage three-commit flow (work commits → archive commit → journal commit).
718
+ - Never push to remote in this step.
719
+ - If the user wants different message wording but accepts the file grouping, edit the message and re-confirm once but if they reject the grouping, exit to manual mode.
720
+ - The batched plan is one prompt; do not prompt per commit.
721
+
722
+ #### 3.5 Archive / Learning
723
+
724
+ Run `task.py archive <task> --check` before the real archive. The check must pass without moving files, changing status, clearing selected-task state, staging or committing, or running hooks.
725
+
726
+ Real completion is only `task.py archive <task>`. It writes `status=completed`, moves the task to `archive/<YYYY-MM>/`, clears selected-task pointers for that task, and runs archive hooks. Passing validation, user acceptance, reviewer gates, or writing `verify.md` alone does not complete the task.
727
+
728
+ Archive readiness by mode:
729
+
730
+ | Mode | Archive readiness |
731
+ |---|---|
732
+ | No Task | No archive; upgrade to a durable task mode before archive is possible. |
733
+ | Micro-Grill | No archive unless upgraded into Lite, Full, or Parent/Child. |
734
+ | Lite | Explicit no-gate chain. `verify.md` has substantive validation, final acceptance, and durable-learning decision evidence. |
735
+ | Full | Lite evidence plus required completion gates (`full-task-complete/*`), substantive check/change-set evidence, fresh fingerprints, and no unresolved required `FAIL` gates. |
736
+ | Child | Lite or Full evidence (by child profile). Full Children require `child-review` gates before Parent `accepted`. Parent task-map marks the Child `integrated` or `cancelled`; integrated Children include `handoff.md`. |
737
+ | Parent | Archive evidence plus every Child `integrated` or `cancelled`, substantive final integration evidence, and `parent-integrated/integration-review`. |
738
+
739
+ Archive / Learning is terminal. After archive, do not silently mutate archived task artifacts; follow-up work requires a new task unless the user explicitly approves an archive amendment.
740
+
741
+ If archive is not being run in this session, report the passing or failing archive check and the remaining evidence gaps.
742
+
743
+ ---
744
+
745
+ ## Customizing Trellis (for forks)
746
+
747
+ This section is for developers who want to modify the Trellis workflow itself. All customization is done by editing this file; the scripts are parsers only.
748
+
749
+ ### Changing what a step means
750
+
751
+ Edit the corresponding step's walkthrough body in the Phase 1 / 2 / 3 sections above. Critical invariants:
752
+ - No selected task must use framework/dashboard routing, then triage and ask for task-creation consent before creating a Trellis task.
753
+ - Planning must distinguish lightweight PRD-only tasks from complex tasks that require `prd.md`, `design.md`, and `implement.md` before start.
754
+ - Every required execution path must keep the Phase 3.4 commit reminder reachable before `/trellis:finish-work`.
755
+
756
+ All tag blocks live in the `## Phase Index` section above, immediately after each phase summary:
757
+
758
+ | Scope | Corresponding tag |
759
+ |---|---|
760
+ | No selected task (before Phase 1) | `[workflow-state:no_task]` (after the Phase Index ASCII art) |
761
+ | All of Phase 1 (task created → ready for implementation) | `[workflow-state:planning]` (after Phase 1 summary) |
762
+ | Phase 2 + Phase 3.1–3.4 (implementation + check + wrap-up) | `[workflow-state:in_progress]` (after Phase 2 summary) |
763
+ | After Phase 3.5 (archived) | `[workflow-state:completed]` (after Phase 3 summary; **currently DEAD**) |
764
+
765
+ ### Changing the per-turn prompt text
766
+
767
+ Directly edit the body of the corresponding `[workflow-state:STATUS]` block. After editing, run `trellis update` (if you're a template maintainer) or restart your AI session (if you're customizing your own project) — no script changes required.
768
+
769
+ ### Adding a custom status
770
+
771
+ Add a new block:
772
+
773
+ ```
774
+ [workflow-state:my-status]
775
+ your per-turn prompt text
776
+ [/workflow-state:my-status]
777
+ ```
778
+
779
+ Constraints:
780
+ - STATUS charset: `[A-Za-z0-9_-]+` (underscores and hyphens allowed, e.g. `in-review`, `blocked-by-team`)
781
+ - A lifecycle hook must write `task.json.status` to your custom value, otherwise the tag is never read
782
+ - Lifecycle hooks live in `task.json.hooks.after_*` and bind to one of `after_create / after_start / after_finish / after_archive`
783
+
784
+ ### Adding a lifecycle hook
785
+
786
+ Add a `hooks` field to your `task.json`:
787
+
788
+ ```json
789
+ {
790
+ "hooks": {
791
+ "after_archive": [
792
+ "your-script-or-command-here"
793
+ ]
794
+ }
795
+ }
796
+ ```
797
+
798
+ Supported events: `after_create / after_start / after_archive`. Use `after_archive` for "task is done" notifications. Historical `after_finish` hooks are not part of the selected-task workflow because `task.py finish` no longer exists.
799
+
800
+ ### Full contract
801
+
802
+ For the workflow state machine's runtime contract, the locations of all status writers, pseudo-statuses (`no_task` / `stale_<source_type>`), the hook reachability matrix, and other deep details, see:
803
+
804
+ - `.trellis/spec/cli/backend/workflow-state-contract.md` — runtime contract + writer table + test invariants
805
+ - `.trellis/scripts/inject-workflow-state.py` — actual parser (reads workflow.md only, no embedded text)