@mindfoldhq/trellis 0.6.0-beta.6 → 0.6.0-beta.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.
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +8 -108
- package/dist/commands/update.js.map +1 -1
- package/dist/configurators/codex.d.ts.map +1 -1
- package/dist/configurators/codex.js +5 -3
- package/dist/configurators/codex.js.map +1 -1
- package/dist/configurators/shared.js +4 -4
- package/dist/configurators/shared.js.map +1 -1
- package/dist/migrations/manifests/0.5.12.json +9 -0
- package/dist/migrations/manifests/0.6.0-beta.7.json +9 -0
- package/dist/migrations/manifests/0.6.0-beta.8.json +9 -0
- package/dist/templates/claude/agents/trellis-check.md +2 -2
- package/dist/templates/claude/agents/trellis-implement.md +8 -7
- package/dist/templates/codebuddy/agents/trellis-check.md +2 -2
- package/dist/templates/codebuddy/agents/trellis-implement.md +8 -7
- package/dist/templates/codex/agents/trellis-check.toml +4 -4
- package/dist/templates/codex/agents/trellis-implement.toml +4 -4
- package/dist/templates/codex/hooks/session-start.py +183 -119
- package/dist/templates/codex/skills/before-dev/SKILL.md +12 -6
- package/dist/templates/codex/skills/brainstorm/SKILL.md +113 -51
- package/dist/templates/codex/skills/check/SKILL.md +86 -18
- package/dist/templates/codex/skills/start/SKILL.md +33 -323
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-context-loading.md +7 -4
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-spec-structure.md +1 -1
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-workflow.md +3 -2
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/context-injection.md +5 -5
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/spec-system.md +1 -1
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/task-system.md +8 -6
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +5 -4
- package/dist/templates/common/commands/continue.md +6 -5
- package/dist/templates/common/commands/start.md +7 -6
- package/dist/templates/common/skills/before-dev.md +12 -6
- package/dist/templates/common/skills/brainstorm.md +56 -42
- package/dist/templates/common/skills/check.md +7 -1
- package/dist/templates/copilot/hooks/session-start.py +183 -90
- package/dist/templates/copilot/prompts/before-dev.prompt.md +12 -6
- package/dist/templates/copilot/prompts/brainstorm.prompt.md +146 -84
- package/dist/templates/copilot/prompts/check.prompt.md +86 -18
- package/dist/templates/copilot/prompts/parallel.prompt.md +16 -8
- package/dist/templates/copilot/prompts/start.prompt.md +33 -367
- package/dist/templates/cursor/agents/trellis-check.md +2 -2
- package/dist/templates/cursor/agents/trellis-implement.md +8 -7
- package/dist/templates/droid/droids/trellis-check.md +2 -2
- package/dist/templates/droid/droids/trellis-implement.md +8 -7
- package/dist/templates/gemini/agents/trellis-implement.md +7 -6
- package/dist/templates/kiro/agents/trellis-check.json +1 -1
- package/dist/templates/kiro/agents/trellis-implement.json +1 -1
- package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +29 -0
- package/dist/templates/opencode/agents/trellis-check.md +2 -2
- package/dist/templates/opencode/agents/trellis-implement.md +9 -8
- package/dist/templates/opencode/lib/session-utils.js +212 -123
- package/dist/templates/opencode/plugins/inject-subagent-context.js +23 -7
- package/dist/templates/opencode/plugins/inject-workflow-state.js +1 -4
- package/dist/templates/pi/extensions/trellis/index.ts.txt +7 -5
- package/dist/templates/qoder/agents/trellis-implement.md +7 -6
- package/dist/templates/shared-hooks/inject-subagent-context.py +36 -14
- package/dist/templates/shared-hooks/inject-workflow-state.py +18 -42
- package/dist/templates/shared-hooks/session-start.py +197 -163
- package/dist/templates/trellis/scripts/common/task_context.py +3 -3
- package/dist/templates/trellis/scripts/common/task_store.py +39 -7
- package/dist/templates/trellis/scripts/common/workflow_phase.py +7 -10
- package/dist/templates/trellis/scripts/task.py +3 -3
- package/dist/templates/trellis/workflow.md +98 -98
- package/package.json +1 -1
|
@@ -20,8 +20,8 @@ You are already the `trellis-check` sub-agent that the main session dispatched.
|
|
|
20
20
|
|
|
21
21
|
Look for the `<!-- trellis-hook-injected -->` marker in your input above.
|
|
22
22
|
|
|
23
|
-
- **If the marker is present**:
|
|
24
|
-
- **If the marker is absent**: hook injection didn't fire (Windows + Claude Code, `--continue` resume, fork distribution, hooks disabled, etc.). Find the active task path from your dispatch prompt's first line `Active task: <path>`, then Read `<task-path>/prd.md`
|
|
23
|
+
- **If the marker is present**: task artifacts, spec, and research files have already been auto-loaded for you above. Proceed with the check work directly.
|
|
24
|
+
- **If the marker is absent**: hook injection didn't fire (Windows + Claude Code, `--continue` resume, fork distribution, hooks disabled, etc.). Find the active task path from your dispatch prompt's first line `Active task: <path>`, then Read `<task-path>/check.jsonl`, each listed file, `<task-path>/prd.md`, `<task-path>/design.md` if present, and `<task-path>/implement.md` if present before doing the work.
|
|
25
25
|
|
|
26
26
|
## Context
|
|
27
27
|
|
|
@@ -21,7 +21,7 @@ You are already the `trellis-implement` sub-agent that the main session dispatch
|
|
|
21
21
|
Look for the `<!-- trellis-hook-injected -->` marker in your input above.
|
|
22
22
|
|
|
23
23
|
- **If the marker is present**: prd / spec / research files have already been auto-loaded for you above. Proceed with the implementation work directly.
|
|
24
|
-
- **If the marker is absent**: hook injection didn't fire (Windows + Claude Code, `--continue` resume, fork distribution, hooks disabled, etc.). Find the active task path from your dispatch prompt's first line `Active task: <path>`, then Read `<task-path>/prd.md`, `<task-path>/
|
|
24
|
+
- **If the marker is absent**: hook injection didn't fire (Windows + Claude Code, `--continue` resume, fork distribution, hooks disabled, etc.). Find the active task path from your dispatch prompt's first line `Active task: <path>`, then Read `<task-path>/implement.jsonl`, each listed file, `<task-path>/prd.md`, `<task-path>/design.md` if present, and `<task-path>/implement.md` if present before doing the work.
|
|
25
25
|
|
|
26
26
|
## Context
|
|
27
27
|
|
|
@@ -29,13 +29,14 @@ Before implementing, read:
|
|
|
29
29
|
- `.trellis/workflow.md` - Project workflow
|
|
30
30
|
- `.trellis/spec/` - Development guidelines
|
|
31
31
|
- Task `prd.md` - Requirements document
|
|
32
|
-
- Task `
|
|
32
|
+
- Task `design.md` - Technical design (if exists)
|
|
33
|
+
- Task `implement.md` - Execution plan (if exists)
|
|
33
34
|
|
|
34
35
|
## Core Responsibilities
|
|
35
36
|
|
|
36
37
|
1. **Understand specs** - Read relevant spec files in `.trellis/spec/`
|
|
37
|
-
2. **Understand
|
|
38
|
-
3. **Implement features** - Write code following specs and
|
|
38
|
+
2. **Understand task artifacts** - Read prd.md, design.md if present, and implement.md if present
|
|
39
|
+
3. **Implement features** - Write code following specs and task artifacts
|
|
39
40
|
4. **Self-check** - Ensure code quality
|
|
40
41
|
5. **Report results** - Report completion status
|
|
41
42
|
|
|
@@ -60,15 +61,15 @@ Read relevant specs based on task type:
|
|
|
60
61
|
|
|
61
62
|
### 2. Understand Requirements
|
|
62
63
|
|
|
63
|
-
Read the task's prd.md and
|
|
64
|
+
Read the task's prd.md, design.md if present, and implement.md if present:
|
|
64
65
|
|
|
65
66
|
- What are the core requirements
|
|
66
67
|
- Key points of technical design
|
|
67
|
-
-
|
|
68
|
+
- Implementation order, validation commands, and rollback points
|
|
68
69
|
|
|
69
70
|
### 3. Implement Features
|
|
70
71
|
|
|
71
|
-
- Write code following specs and
|
|
72
|
+
- Write code following specs and task artifacts
|
|
72
73
|
- Follow existing code patterns
|
|
73
74
|
- Only do what's required, no over-engineering
|
|
74
75
|
|
|
@@ -20,8 +20,8 @@ You are already the `trellis-check` sub-agent that the main session dispatched.
|
|
|
20
20
|
|
|
21
21
|
Look for the `<!-- trellis-hook-injected -->` marker in your input above.
|
|
22
22
|
|
|
23
|
-
- **If the marker is present**:
|
|
24
|
-
- **If the marker is absent**: hook injection didn't fire (Windows + Claude Code, `--continue` resume, fork distribution, hooks disabled, etc.). Find the active task path from your dispatch prompt's first line `Active task: <path>`, then Read `<task-path>/prd.md`
|
|
23
|
+
- **If the marker is present**: task artifacts, spec, and research files have already been auto-loaded for you above. Proceed with the check work directly.
|
|
24
|
+
- **If the marker is absent**: hook injection didn't fire (Windows + Claude Code, `--continue` resume, fork distribution, hooks disabled, etc.). Find the active task path from your dispatch prompt's first line `Active task: <path>`, then Read `<task-path>/check.jsonl`, each listed file, `<task-path>/prd.md`, `<task-path>/design.md` if present, and `<task-path>/implement.md` if present before doing the work.
|
|
25
25
|
|
|
26
26
|
## Context
|
|
27
27
|
|
|
@@ -21,7 +21,7 @@ You are already the `trellis-implement` sub-agent that the main session dispatch
|
|
|
21
21
|
Look for the `<!-- trellis-hook-injected -->` marker in your input above.
|
|
22
22
|
|
|
23
23
|
- **If the marker is present**: prd / spec / research files have already been auto-loaded for you above. Proceed with the implementation work directly.
|
|
24
|
-
- **If the marker is absent**: hook injection didn't fire (Windows + Claude Code, `--continue` resume, fork distribution, hooks disabled, etc.). Find the active task path from your dispatch prompt's first line `Active task: <path>`, then Read `<task-path>/prd.md`, `<task-path>/
|
|
24
|
+
- **If the marker is absent**: hook injection didn't fire (Windows + Claude Code, `--continue` resume, fork distribution, hooks disabled, etc.). Find the active task path from your dispatch prompt's first line `Active task: <path>`, then Read `<task-path>/implement.jsonl`, each listed file, `<task-path>/prd.md`, `<task-path>/design.md` if present, and `<task-path>/implement.md` if present before doing the work.
|
|
25
25
|
|
|
26
26
|
## Context
|
|
27
27
|
|
|
@@ -29,13 +29,14 @@ Before implementing, read:
|
|
|
29
29
|
- `.trellis/workflow.md` - Project workflow
|
|
30
30
|
- `.trellis/spec/` - Development guidelines
|
|
31
31
|
- Task `prd.md` - Requirements document
|
|
32
|
-
- Task `
|
|
32
|
+
- Task `design.md` - Technical design (if exists)
|
|
33
|
+
- Task `implement.md` - Execution plan (if exists)
|
|
33
34
|
|
|
34
35
|
## Core Responsibilities
|
|
35
36
|
|
|
36
37
|
1. **Understand specs** - Read relevant spec files in `.trellis/spec/`
|
|
37
|
-
2. **Understand
|
|
38
|
-
3. **Implement features** - Write code following specs and
|
|
38
|
+
2. **Understand task artifacts** - Read prd.md, design.md if present, and implement.md if present
|
|
39
|
+
3. **Implement features** - Write code following specs and task artifacts
|
|
39
40
|
4. **Self-check** - Ensure code quality
|
|
40
41
|
5. **Report results** - Report completion status
|
|
41
42
|
|
|
@@ -60,15 +61,15 @@ Read relevant specs based on task type:
|
|
|
60
61
|
|
|
61
62
|
### 2. Understand Requirements
|
|
62
63
|
|
|
63
|
-
Read the task's prd.md and
|
|
64
|
+
Read the task's prd.md, design.md if present, and implement.md if present:
|
|
64
65
|
|
|
65
66
|
- What are the core requirements
|
|
66
67
|
- Key points of technical design
|
|
67
|
-
-
|
|
68
|
+
- Implementation order, validation commands, and rollback points
|
|
68
69
|
|
|
69
70
|
### 3. Implement Features
|
|
70
71
|
|
|
71
|
-
- Write code following specs and
|
|
72
|
+
- Write code following specs and task artifacts
|
|
72
73
|
- Follow existing code patterns
|
|
73
74
|
- Only do what's required, no over-engineering
|
|
74
75
|
|
|
@@ -26,12 +26,12 @@ Try in order — stop at the first one that yields a task path:
|
|
|
26
26
|
|
|
27
27
|
### Step 2: Load task context from the resolved path
|
|
28
28
|
|
|
29
|
-
1. Read
|
|
30
|
-
2. Read
|
|
31
|
-
3. For each entry in the JSONL, Read its `file` path — these are the dev specs you must follow.
|
|
29
|
+
1. Read `<task-path>/check.jsonl` — JSONL list of spec/research files relevant to this agent.
|
|
30
|
+
2. For each entry in the JSONL, Read its `file` path — these are the specs and research notes you must follow.
|
|
32
31
|
**Skip rows without a `"file"` field** (e.g. `{"_example": "..."}` seed rows left over from `task.py create` before the curator ran).
|
|
32
|
+
3. Read the task's `prd.md` (requirements), then `design.md` if present (technical design), then `implement.md` if present (execution plan).
|
|
33
33
|
|
|
34
|
-
If `check.jsonl` has no curated entries (only a seed row, or the file is missing), fall back to: read
|
|
34
|
+
If `check.jsonl` has no curated entries (only a seed row, or the file is missing), fall back to: read the task artifacts, list available specs with `python3 ./.trellis/scripts/get_context.py --mode packages`, and pick the specs that match the task domain yourself. Do NOT block on the missing jsonl — lightweight tasks may be PRD-only, while complex tasks may also include `design.md` and `implement.md`.
|
|
35
35
|
|
|
36
36
|
If the resolved task path has no `prd.md`, ask the user what to work on; do NOT proceed without context.
|
|
37
37
|
|
|
@@ -26,12 +26,12 @@ Try in order — stop at the first one that yields a task path:
|
|
|
26
26
|
|
|
27
27
|
### Step 2: Load task context from the resolved path
|
|
28
28
|
|
|
29
|
-
1. Read
|
|
30
|
-
2. Read
|
|
31
|
-
3. For each entry in the JSONL, Read its `file` path — these are the dev specs you must follow.
|
|
29
|
+
1. Read `<task-path>/implement.jsonl` — JSONL list of spec/research files relevant to this agent.
|
|
30
|
+
2. For each entry in the JSONL, Read its `file` path — these are the specs and research notes you must follow.
|
|
32
31
|
**Skip rows without a `"file"` field** (e.g. `{"_example": "..."}` seed rows left over from `task.py create` before the curator ran).
|
|
32
|
+
3. Read the task's `prd.md` (requirements), then `design.md` if present (technical design), then `implement.md` if present (execution plan).
|
|
33
33
|
|
|
34
|
-
If `implement.jsonl` has no curated entries (only a seed row, or the file is missing), fall back to: read
|
|
34
|
+
If `implement.jsonl` has no curated entries (only a seed row, or the file is missing), fall back to: read the task artifacts, list available specs with `python3 ./.trellis/scripts/get_context.py --mode packages`, and pick the specs that match the task domain yourself. Do NOT block on the missing jsonl — lightweight tasks may be PRD-only, while complex tasks may also include `design.md` and `implement.md`.
|
|
35
35
|
|
|
36
36
|
If the resolved task path has no `prd.md`, ask the user what to work on; do NOT proceed without context.
|
|
37
37
|
|
|
@@ -75,23 +75,6 @@ Trellis SessionStart 已注入:workflow、当前任务状态、开发者身份
|
|
|
75
75
|
Then continue directly with the user's request. This notice is one-shot: do not repeat it after the first assistant reply in the same session.
|
|
76
76
|
</first-reply-notice>"""
|
|
77
77
|
|
|
78
|
-
SUB_AGENT_NOTICE = """<sub-agent-notice>
|
|
79
|
-
SUB-AGENT NOTICE - READ FIRST IF SPAWNED VIA spawn_agent
|
|
80
|
-
|
|
81
|
-
If your parent session spawned you via spawn_agent with an explicit task
|
|
82
|
-
message above this hook output, that message is your only job.
|
|
83
|
-
- Execute the parent message exactly as written, then return.
|
|
84
|
-
- Ignore all Trellis workflow guidance below this notice.
|
|
85
|
-
- Do NOT call task.py start, task.py add-context, or task.py archive.
|
|
86
|
-
- Do NOT call wait_agent or spawn_agent.
|
|
87
|
-
- Do NOT modify .trellis/tasks/* or any other file unless the parent message
|
|
88
|
-
explicitly asks for that.
|
|
89
|
-
|
|
90
|
-
If you are the main interactive Codex session and the user is typing at the
|
|
91
|
-
terminal with no parent agent, use the workflow guidance below normally.
|
|
92
|
-
</sub-agent-notice>"""
|
|
93
|
-
|
|
94
|
-
|
|
95
78
|
def should_skip_injection() -> bool:
|
|
96
79
|
if os.environ.get("TRELLIS_HOOKS") == "0":
|
|
97
80
|
return True
|
|
@@ -218,12 +201,19 @@ def _resolve_task_dir(trellis_dir: Path, task_ref: str) -> Path:
|
|
|
218
201
|
def _get_task_status(trellis_dir: Path, hook_input: dict) -> str:
|
|
219
202
|
active = _resolve_active_task(trellis_dir, hook_input)
|
|
220
203
|
if not active.task_path:
|
|
221
|
-
return
|
|
204
|
+
return (
|
|
205
|
+
"Status: NO ACTIVE TASK\n"
|
|
206
|
+
"Next: Classify the current turn and ask for task-creation consent "
|
|
207
|
+
"before creating any Trellis task."
|
|
208
|
+
)
|
|
222
209
|
|
|
223
210
|
task_ref = active.task_path
|
|
224
211
|
task_dir = _resolve_task_dir(trellis_dir, task_ref)
|
|
225
212
|
if active.stale or not task_dir.is_dir():
|
|
226
|
-
return
|
|
213
|
+
return (
|
|
214
|
+
f"Status: STALE POINTER\nTask: {task_ref}\n"
|
|
215
|
+
"Next: Task directory not found. Run: python3 ./.trellis/scripts/task.py finish"
|
|
216
|
+
)
|
|
227
217
|
|
|
228
218
|
task_json_path = task_dir / "task.json"
|
|
229
219
|
task_data: dict = {}
|
|
@@ -237,40 +227,170 @@ def _get_task_status(trellis_dir: Path, hook_input: dict) -> str:
|
|
|
237
227
|
task_status = task_data.get("status", "unknown")
|
|
238
228
|
|
|
239
229
|
if task_status == "completed":
|
|
240
|
-
return
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if jsonl_path.is_file() and _has_curated_jsonl_entry(jsonl_path):
|
|
246
|
-
has_context = True
|
|
247
|
-
break
|
|
230
|
+
return (
|
|
231
|
+
f"Status: COMPLETED\nTask: {task_title}\n"
|
|
232
|
+
f"Next: Archive with `python3 ./.trellis/scripts/task.py archive {task_dir.name}` "
|
|
233
|
+
"or start a new task."
|
|
234
|
+
)
|
|
248
235
|
|
|
249
236
|
has_prd = (task_dir / "prd.md").is_file()
|
|
237
|
+
has_design = (task_dir / "design.md").is_file()
|
|
238
|
+
has_implement = (task_dir / "implement.md").is_file()
|
|
239
|
+
present = [
|
|
240
|
+
name
|
|
241
|
+
for name in ("prd.md", "design.md", "implement.md", "implement.jsonl", "check.jsonl")
|
|
242
|
+
if (task_dir / name).is_file()
|
|
243
|
+
]
|
|
244
|
+
present_line = ", ".join(present) if present else "none"
|
|
250
245
|
|
|
251
246
|
if not has_prd:
|
|
252
|
-
return
|
|
247
|
+
return (
|
|
248
|
+
f"Status: PLANNING\nTask: {task_title}\nPresent: {present_line}\n"
|
|
249
|
+
"Next: Load trellis-brainstorm and write prd.md. Stay in planning."
|
|
250
|
+
)
|
|
253
251
|
|
|
254
|
-
if
|
|
255
|
-
|
|
252
|
+
if task_status == "planning":
|
|
253
|
+
if has_design and has_implement:
|
|
254
|
+
next_action = "Review planning artifacts with the user before `task.py start`."
|
|
255
|
+
else:
|
|
256
|
+
next_action = (
|
|
257
|
+
"Lightweight task can ask for start review with PRD-only; "
|
|
258
|
+
"complex task must add design.md and implement.md before `task.py start`."
|
|
259
|
+
)
|
|
260
|
+
return (
|
|
261
|
+
f"Status: PLANNING\nTask: {task_title}\nPresent: {present_line}\n"
|
|
262
|
+
f"Next: {next_action}"
|
|
263
|
+
)
|
|
256
264
|
|
|
257
265
|
return (
|
|
258
|
-
f"Status:
|
|
259
|
-
|
|
260
|
-
"
|
|
261
|
-
"For agent-capable platforms, the default is to NOT edit code in the main session. "
|
|
262
|
-
"After implementation, dispatch `trellis-check` per Phase 2.2 before reporting completion.\n"
|
|
263
|
-
"Sub-agent self-exemption: if you are reading this as a `trellis-implement` or "
|
|
264
|
-
"`trellis-check` sub-agent (your own role / agent name reflects that), this dispatch "
|
|
265
|
-
"instruction does NOT apply to you — you are already the dispatched sub-agent. "
|
|
266
|
-
"Implement / check directly without spawning another sub-agent of the same kind.\n"
|
|
267
|
-
"User override (per-turn escape hatch): if the user's CURRENT message explicitly tells the "
|
|
268
|
-
"main session to handle it directly (\"你直接改\" / \"别派 sub-agent\" / \"main session 写就行\" / "
|
|
269
|
-
"\"do it inline\" / \"不用 sub-agent\"), honor it for this turn and edit code directly. "
|
|
270
|
-
"Per-turn only; do NOT invent an override the user did not say."
|
|
266
|
+
f"Status: {task_status.upper()}\nTask: {task_title}\nPresent: {present_line}\n"
|
|
267
|
+
"Next: Follow the matching per-turn workflow-state. Context order is jsonl entries, "
|
|
268
|
+
"prd.md, design.md if present, implement.md if present."
|
|
271
269
|
)
|
|
272
270
|
|
|
273
271
|
|
|
272
|
+
def _run_git(repo_root: Path, args: list[str]) -> str:
|
|
273
|
+
try:
|
|
274
|
+
result = subprocess.run(
|
|
275
|
+
["git", *args],
|
|
276
|
+
capture_output=True,
|
|
277
|
+
text=True,
|
|
278
|
+
encoding="utf-8",
|
|
279
|
+
errors="replace",
|
|
280
|
+
timeout=3,
|
|
281
|
+
cwd=str(repo_root),
|
|
282
|
+
)
|
|
283
|
+
except (subprocess.TimeoutExpired, FileNotFoundError, PermissionError):
|
|
284
|
+
return ""
|
|
285
|
+
if result.returncode != 0:
|
|
286
|
+
return ""
|
|
287
|
+
return result.stdout.strip()
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _format_git_state(repo_root: Path) -> str:
|
|
291
|
+
branch = _run_git(repo_root, ["branch", "--show-current"]) or "(detached)"
|
|
292
|
+
dirty_lines = [
|
|
293
|
+
line for line in _run_git(repo_root, ["status", "--porcelain"]).splitlines()
|
|
294
|
+
if line.strip()
|
|
295
|
+
]
|
|
296
|
+
dirty_text = "clean" if not dirty_lines else f"dirty {len(dirty_lines)} paths"
|
|
297
|
+
return f"Git: branch {branch}; {dirty_text}."
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def _repo_relative(repo_root: Path, path: Path) -> str:
|
|
301
|
+
try:
|
|
302
|
+
return path.relative_to(repo_root).as_posix()
|
|
303
|
+
except ValueError:
|
|
304
|
+
return str(path)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def _collect_spec_index_paths(trellis_dir: Path) -> list[str]:
|
|
308
|
+
paths: list[str] = []
|
|
309
|
+
guides_index = trellis_dir / "spec" / "guides" / "index.md"
|
|
310
|
+
if guides_index.is_file():
|
|
311
|
+
paths.append(".trellis/spec/guides/index.md")
|
|
312
|
+
|
|
313
|
+
spec_dir = trellis_dir / "spec"
|
|
314
|
+
if not spec_dir.is_dir():
|
|
315
|
+
return paths
|
|
316
|
+
|
|
317
|
+
for sub in sorted(spec_dir.iterdir()):
|
|
318
|
+
if not sub.is_dir() or sub.name.startswith(".") or sub.name == "guides":
|
|
319
|
+
continue
|
|
320
|
+
index_file = sub / "index.md"
|
|
321
|
+
if index_file.is_file():
|
|
322
|
+
paths.append(f".trellis/spec/{sub.name}/index.md")
|
|
323
|
+
continue
|
|
324
|
+
for nested in sorted(sub.iterdir()):
|
|
325
|
+
if not nested.is_dir():
|
|
326
|
+
continue
|
|
327
|
+
nested_index = nested / "index.md"
|
|
328
|
+
if nested_index.is_file():
|
|
329
|
+
paths.append(f".trellis/spec/{sub.name}/{nested.name}/index.md")
|
|
330
|
+
|
|
331
|
+
return paths
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def _build_compact_current_state(
|
|
335
|
+
trellis_dir: Path,
|
|
336
|
+
hook_input: dict,
|
|
337
|
+
spec_index_paths: list[str],
|
|
338
|
+
) -> str:
|
|
339
|
+
repo_root = trellis_dir.parent
|
|
340
|
+
lines: list[str] = []
|
|
341
|
+
|
|
342
|
+
try:
|
|
343
|
+
from common.paths import get_active_journal_file, get_developer, get_tasks_dir, count_lines # type: ignore[import-not-found]
|
|
344
|
+
from common.tasks import iter_active_tasks # type: ignore[import-not-found]
|
|
345
|
+
except Exception:
|
|
346
|
+
get_active_journal_file = None # type: ignore[assignment]
|
|
347
|
+
get_developer = None # type: ignore[assignment]
|
|
348
|
+
get_tasks_dir = None # type: ignore[assignment]
|
|
349
|
+
count_lines = None # type: ignore[assignment]
|
|
350
|
+
iter_active_tasks = None # type: ignore[assignment]
|
|
351
|
+
|
|
352
|
+
developer = get_developer(repo_root) if get_developer else None
|
|
353
|
+
lines.append(f"Developer: {developer or '(not initialized)'}")
|
|
354
|
+
lines.append(_format_git_state(repo_root))
|
|
355
|
+
|
|
356
|
+
active = _resolve_active_task(trellis_dir, hook_input)
|
|
357
|
+
if active.task_path:
|
|
358
|
+
task_dir = _resolve_task_dir(trellis_dir, active.task_path)
|
|
359
|
+
status = "unknown"
|
|
360
|
+
task_json = task_dir / "task.json"
|
|
361
|
+
if task_json.is_file():
|
|
362
|
+
try:
|
|
363
|
+
data = json.loads(task_json.read_text(encoding="utf-8"))
|
|
364
|
+
if isinstance(data, dict):
|
|
365
|
+
status = str(data.get("status") or "unknown")
|
|
366
|
+
except (json.JSONDecodeError, OSError):
|
|
367
|
+
pass
|
|
368
|
+
lines.append(f"Current task: {_repo_relative(repo_root, task_dir)}; status={status}.")
|
|
369
|
+
else:
|
|
370
|
+
lines.append("Current task: none.")
|
|
371
|
+
|
|
372
|
+
if get_tasks_dir and iter_active_tasks:
|
|
373
|
+
try:
|
|
374
|
+
task_count = sum(1 for _ in iter_active_tasks(get_tasks_dir(repo_root)))
|
|
375
|
+
lines.append(
|
|
376
|
+
f"Active tasks: {task_count} total. Use `python3 ./.trellis/scripts/task.py list --mine` only if needed."
|
|
377
|
+
)
|
|
378
|
+
except Exception:
|
|
379
|
+
pass
|
|
380
|
+
|
|
381
|
+
if get_active_journal_file and count_lines:
|
|
382
|
+
journal = get_active_journal_file(repo_root)
|
|
383
|
+
if journal:
|
|
384
|
+
lines.append(
|
|
385
|
+
f"Journal: {_repo_relative(repo_root, journal)}, {count_lines(journal)} / 2000 lines."
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
if spec_index_paths:
|
|
389
|
+
lines.append(f"Spec indexes: {len(spec_index_paths)} available.")
|
|
390
|
+
|
|
391
|
+
return "\n".join(lines)
|
|
392
|
+
|
|
393
|
+
|
|
274
394
|
def _extract_range(content: str, start_header: str, end_header: str) -> str:
|
|
275
395
|
"""Extract lines starting at `## start_header` up to (but excluding) `## end_header`."""
|
|
276
396
|
lines = content.splitlines()
|
|
@@ -298,33 +418,25 @@ _BREADCRUMB_TAG_RE = re.compile(
|
|
|
298
418
|
|
|
299
419
|
|
|
300
420
|
def _strip_breadcrumb_tag_blocks(content: str) -> str:
|
|
301
|
-
|
|
421
|
+
stripped = _BREADCRUMB_TAG_RE.sub("", content)
|
|
422
|
+
stripped = re.sub(r"<!--.*?-->", "", stripped, flags=re.DOTALL)
|
|
423
|
+
stripped = re.sub(r"^\[(?!/?workflow-state:)/?[^\]\n]+\]\s*\n?", "", stripped, flags=re.MULTILINE)
|
|
424
|
+
return re.sub(r"\n{3,}", "\n\n", stripped).strip()
|
|
302
425
|
|
|
303
426
|
|
|
304
427
|
def _build_workflow_toc(workflow_path: Path) -> str:
|
|
305
|
-
"""Inject
|
|
306
|
-
|
|
307
|
-
Since v0.5.0-rc.0 the [workflow-state:STATUS] breadcrumb tag blocks
|
|
308
|
-
live inside ## Phase Index. They're consumed by inject-workflow-state.py
|
|
309
|
-
on each UserPromptSubmit, so strip them from the session-start payload
|
|
310
|
-
to avoid duplicating context.
|
|
311
|
-
"""
|
|
428
|
+
"""Inject only the compact Phase Index summary for SessionStart."""
|
|
312
429
|
content = read_file(workflow_path)
|
|
313
430
|
if not content:
|
|
314
431
|
return "No workflow.md found"
|
|
315
432
|
|
|
316
433
|
out_lines = [
|
|
317
|
-
"# Development Workflow
|
|
318
|
-
"Full guide: .trellis/workflow.md
|
|
434
|
+
"# Development Workflow - Session Summary",
|
|
435
|
+
"Full guide: .trellis/workflow.md. Step detail: `python3 ./.trellis/scripts/get_context.py --mode phase --step <X.Y>`.",
|
|
319
436
|
"",
|
|
320
|
-
"## Table of Contents",
|
|
321
437
|
]
|
|
322
|
-
for line in content.splitlines():
|
|
323
|
-
if line.startswith("## "):
|
|
324
|
-
out_lines.append(line)
|
|
325
|
-
out_lines += ["", "---", ""]
|
|
326
438
|
|
|
327
|
-
phases = _extract_range(content, "Phase Index", "
|
|
439
|
+
phases = _extract_range(content, "Phase Index", "Phase 1: Plan")
|
|
328
440
|
if phases:
|
|
329
441
|
out_lines.append(_strip_breadcrumb_tag_blocks(phases).rstrip())
|
|
330
442
|
|
|
@@ -348,16 +460,12 @@ def main() -> None:
|
|
|
348
460
|
configure_project_encoding(project_dir)
|
|
349
461
|
|
|
350
462
|
trellis_dir = project_dir / ".trellis"
|
|
351
|
-
|
|
463
|
+
spec_index_paths = _collect_spec_index_paths(trellis_dir)
|
|
352
464
|
|
|
353
465
|
output = StringIO()
|
|
354
466
|
|
|
355
|
-
output.write(SUB_AGENT_NOTICE)
|
|
356
|
-
output.write("\n\n")
|
|
357
|
-
|
|
358
467
|
output.write("""<session-context>
|
|
359
|
-
|
|
360
|
-
Read and follow all instructions below carefully.
|
|
468
|
+
Trellis compact SessionStart context. Use it to orient the session; load details on demand.
|
|
361
469
|
</session-context>
|
|
362
470
|
|
|
363
471
|
""")
|
|
@@ -365,65 +473,23 @@ Read and follow all instructions below carefully.
|
|
|
365
473
|
output.write("\n\n")
|
|
366
474
|
|
|
367
475
|
output.write("<current-state>\n")
|
|
368
|
-
|
|
369
|
-
output.write(run_script(context_script, context_key))
|
|
476
|
+
output.write(_build_compact_current_state(trellis_dir, hook_input, spec_index_paths))
|
|
370
477
|
output.write("\n</current-state>\n\n")
|
|
371
478
|
|
|
372
|
-
output.write("<workflow>\n")
|
|
479
|
+
output.write("<trellis-workflow>\n")
|
|
373
480
|
output.write(_build_workflow_toc(trellis_dir / "workflow.md"))
|
|
374
|
-
output.write("\n</workflow>\n\n")
|
|
481
|
+
output.write("\n</trellis-workflow>\n\n")
|
|
375
482
|
|
|
376
483
|
output.write("<guidelines>\n")
|
|
377
484
|
output.write(
|
|
378
|
-
"
|
|
379
|
-
"
|
|
380
|
-
"
|
|
381
|
-
"- If you're spawning an implement/check sub-agent, context is injected "
|
|
382
|
-
"automatically via `{task}/implement.jsonl` / `check.jsonl`. You do NOT "
|
|
383
|
-
"need to read these indexes yourself.\n"
|
|
384
|
-
"- For agent-capable platforms, the default is to dispatch "
|
|
385
|
-
"`trellis-implement` and `trellis-check` (so JSONL context is loaded by "
|
|
386
|
-
"the sub-agents) rather than editing code in the main session. "
|
|
387
|
-
"Honor a per-turn user override only if the user's current message "
|
|
388
|
-
"explicitly opts out (see <task-status> below for override phrases).\n"
|
|
389
|
-
"- Sub-agent self-exemption: if you are reading this as a `trellis-implement` "
|
|
390
|
-
"or `trellis-check` sub-agent, the \"dispatch trellis-implement / trellis-check\" "
|
|
391
|
-
"rule above does NOT apply to you — you are already the dispatched sub-agent. "
|
|
392
|
-
"Do NOT spawn another sub-agent of the same kind; implement / check directly.\n\n"
|
|
485
|
+
"Task context order for implementation/check: jsonl entries -> `prd.md` -> "
|
|
486
|
+
"`design.md if present` -> `implement.md if present`. Missing optional artifacts "
|
|
487
|
+
"are skipped for lightweight tasks.\n\n"
|
|
393
488
|
)
|
|
394
489
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
output.write("## guides (inlined — cross-package thinking guides)\n")
|
|
399
|
-
output.write(read_file(guides_index))
|
|
400
|
-
output.write("\n\n")
|
|
401
|
-
|
|
402
|
-
# Other indexes — paths only
|
|
403
|
-
paths: list[str] = []
|
|
404
|
-
spec_dir = trellis_dir / "spec"
|
|
405
|
-
if spec_dir.is_dir():
|
|
406
|
-
for sub in sorted(spec_dir.iterdir()):
|
|
407
|
-
if not sub.is_dir() or sub.name.startswith("."):
|
|
408
|
-
continue
|
|
409
|
-
if sub.name == "guides":
|
|
410
|
-
continue
|
|
411
|
-
index_file = sub / "index.md"
|
|
412
|
-
if index_file.is_file():
|
|
413
|
-
paths.append(f".trellis/spec/{sub.name}/index.md")
|
|
414
|
-
else:
|
|
415
|
-
for nested in sorted(sub.iterdir()):
|
|
416
|
-
if not nested.is_dir():
|
|
417
|
-
continue
|
|
418
|
-
nested_index = nested / "index.md"
|
|
419
|
-
if nested_index.is_file():
|
|
420
|
-
paths.append(
|
|
421
|
-
f".trellis/spec/{sub.name}/{nested.name}/index.md"
|
|
422
|
-
)
|
|
423
|
-
|
|
424
|
-
if paths:
|
|
425
|
-
output.write("## Available spec indexes (read on demand)\n")
|
|
426
|
-
for p in paths:
|
|
490
|
+
if spec_index_paths:
|
|
491
|
+
output.write("## Available indexes (read on demand)\n")
|
|
492
|
+
for p in spec_index_paths:
|
|
427
493
|
output.write(f"- {p}\n")
|
|
428
494
|
output.write("\n")
|
|
429
495
|
|
|
@@ -437,9 +503,7 @@ Read and follow all instructions below carefully.
|
|
|
437
503
|
output.write(f"<task-status>\n{task_status}\n</task-status>\n\n")
|
|
438
504
|
|
|
439
505
|
output.write("""<ready>
|
|
440
|
-
Context loaded.
|
|
441
|
-
When the user sends the first message, follow <task-status> and the workflow guide.
|
|
442
|
-
If a task is READY, execute its Next required action without asking whether to continue.
|
|
506
|
+
Context loaded. Follow <task-status>. Load workflow/spec/task details only when needed.
|
|
443
507
|
</ready>""")
|
|
444
508
|
|
|
445
509
|
context = output.getvalue()
|
|
@@ -7,28 +7,34 @@ Read the relevant development guidelines before starting your task.
|
|
|
7
7
|
|
|
8
8
|
Execute these steps:
|
|
9
9
|
|
|
10
|
-
1. **
|
|
10
|
+
1. **Read current task artifacts**:
|
|
11
|
+
- `prd.md` for requirements and acceptance criteria
|
|
12
|
+
- `design.md` if present for technical design
|
|
13
|
+
- `implement.md` if present for execution order and validation plan
|
|
14
|
+
|
|
15
|
+
2. **Discover packages and their spec layers**:
|
|
11
16
|
```bash
|
|
12
17
|
python3 ./.trellis/scripts/get_context.py --mode packages
|
|
13
18
|
```
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
3. **Identify which specs apply** to your task based on:
|
|
16
21
|
- Which package you're modifying (e.g., `cli/`, `docs-site/`)
|
|
17
22
|
- What type of work (backend, frontend, unit-test, docs, etc.)
|
|
23
|
+
- Any spec/research paths referenced by the task artifacts
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
4. **Read the spec index** for each relevant module:
|
|
20
26
|
```bash
|
|
21
27
|
cat .trellis/spec/<package>/<layer>/index.md
|
|
22
28
|
```
|
|
23
29
|
Follow the **"Pre-Development Checklist"** section in the index.
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
5. **Read the specific guideline files** listed in the Pre-Development Checklist that are relevant to your task. The index is NOT the goal — it points you to the actual guideline files (e.g., `error-handling.md`, `conventions.md`, `mock-strategies.md`). Read those files to understand the coding standards and patterns.
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
6. **Always read shared guides**:
|
|
28
34
|
```bash
|
|
29
35
|
cat .trellis/spec/guides/index.md
|
|
30
36
|
```
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
7. Understand the coding standards and patterns you need to follow, then proceed with your development plan.
|
|
33
39
|
|
|
34
40
|
This step is **mandatory** before writing any code.
|