@mindfoldhq/trellis 0.6.0-beta.8 → 0.6.0-beta.9
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/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +23 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +2 -2
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/upgrade.d.ts +28 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +84 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/migrations/manifests/0.5.13.json +9 -0
- package/dist/migrations/manifests/0.6.0-beta.9.json +9 -0
- package/dist/templates/claude/settings.json +4 -4
- package/dist/templates/codebuddy/settings.json +4 -4
- package/dist/templates/codex/hooks.json +1 -1
- package/dist/templates/codex/skills/brainstorm/SKILL.md +69 -519
- package/dist/templates/common/skills/brainstorm.md +68 -518
- package/dist/templates/copilot/hooks/session-start.py +12 -11
- package/dist/templates/copilot/hooks.json +2 -2
- package/dist/templates/copilot/prompts/brainstorm.prompt.md +69 -519
- package/dist/templates/cursor/hooks.json +2 -2
- package/dist/templates/droid/settings.json +4 -4
- package/dist/templates/gemini/settings.json +2 -2
- package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +45 -10
- package/dist/templates/markdown/spec/guides/cross-platform-thinking-guide.md.txt +10 -4
- package/dist/templates/opencode/lib/trellis-context.js +73 -11
- package/dist/templates/opencode/plugins/inject-subagent-context.js +112 -26
- package/dist/templates/opencode/plugins/inject-workflow-state.js +8 -1
- package/dist/templates/opencode/plugins/session-start.js +9 -1
- package/dist/templates/qoder/settings.json +4 -4
- package/dist/templates/trellis/scripts/common/session_context.py +215 -138
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
9
|
"command": "{{PYTHON_CMD}} .gemini/hooks/session-start.py",
|
|
10
|
-
"timeout":
|
|
10
|
+
"timeout": 30000
|
|
11
11
|
}
|
|
12
12
|
]
|
|
13
13
|
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
{
|
|
20
20
|
"type": "command",
|
|
21
21
|
"command": "{{PYTHON_CMD}} .gemini/hooks/inject-workflow-state.py",
|
|
22
|
-
"timeout":
|
|
22
|
+
"timeout": 15000
|
|
23
23
|
}
|
|
24
24
|
]
|
|
25
25
|
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
**Most bugs happen at layer boundaries**, not within layers.
|
|
10
10
|
|
|
11
11
|
Common cross-layer bugs:
|
|
12
|
+
|
|
12
13
|
- API returns format A, frontend expects format B
|
|
13
14
|
- Database stores X, service transforms to Y, but loses data
|
|
14
15
|
- Multiple layers implement the same logic differently
|
|
@@ -26,22 +27,24 @@ Source → Transform → Store → Retrieve → Transform → Display
|
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
For each arrow, ask:
|
|
30
|
+
|
|
29
31
|
- What format is the data in?
|
|
30
32
|
- What could go wrong?
|
|
31
33
|
- Who is responsible for validation?
|
|
32
34
|
|
|
33
35
|
### Step 2: Identify Boundaries
|
|
34
36
|
|
|
35
|
-
| Boundary
|
|
36
|
-
|
|
37
|
-
| API ↔ Service
|
|
38
|
-
| Service ↔ Database
|
|
39
|
-
| Backend ↔ Frontend
|
|
40
|
-
| Component ↔ Component | Props shape changes
|
|
37
|
+
| Boundary | Common Issues |
|
|
38
|
+
| --------------------- | --------------------------------- |
|
|
39
|
+
| API ↔ Service | Type mismatches, missing fields |
|
|
40
|
+
| Service ↔ Database | Format conversions, null handling |
|
|
41
|
+
| Backend ↔ Frontend | Serialization, date formats |
|
|
42
|
+
| Component ↔ Component | Props shape changes |
|
|
41
43
|
|
|
42
44
|
### Step 3: Define Contracts
|
|
43
45
|
|
|
44
46
|
For each boundary:
|
|
47
|
+
|
|
45
48
|
- What is the exact input format?
|
|
46
49
|
- What is the exact output format?
|
|
47
50
|
- What errors can occur?
|
|
@@ -73,12 +76,14 @@ For each boundary:
|
|
|
73
76
|
## Checklist for Cross-Layer Features
|
|
74
77
|
|
|
75
78
|
Before implementation:
|
|
79
|
+
|
|
76
80
|
- [ ] Mapped the complete data flow
|
|
77
81
|
- [ ] Identified all layer boundaries
|
|
78
82
|
- [ ] Defined format at each boundary
|
|
79
83
|
- [ ] Decided where validation happens
|
|
80
84
|
|
|
81
85
|
After implementation:
|
|
86
|
+
|
|
82
87
|
- [ ] Tested with edge cases (null, empty, invalid)
|
|
83
88
|
- [ ] Verified error handling at each boundary
|
|
84
89
|
- [ ] Checked data survives round-trip
|
|
@@ -110,15 +115,42 @@ against both fresh init and upgrade paths.
|
|
|
110
115
|
### Checklist: After Modifying A Runtime-Parsed Template
|
|
111
116
|
|
|
112
117
|
- [ ] Identify every runtime parser that reads the template, not just the file
|
|
113
|
-
|
|
118
|
+
writer that installs it
|
|
114
119
|
- [ ] Check whether relevant syntax lives outside obvious managed regions
|
|
115
|
-
|
|
120
|
+
such as tag blocks
|
|
116
121
|
- [ ] Verify fresh `init` output and a versioned `update` scenario that writes
|
|
117
|
-
|
|
122
|
+
the older `.trellis/.version`
|
|
118
123
|
- [ ] Add an upgrade regression using an older pristine template fixture, then
|
|
119
|
-
|
|
124
|
+
assert the installed file reaches the current packaged shape
|
|
120
125
|
- [ ] Update the backend spec that owns the runtime contract
|
|
121
126
|
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Versioned Documentation Boundary
|
|
130
|
+
|
|
131
|
+
Versioned documentation is a cross-layer boundary: source paths, `docs.json`
|
|
132
|
+
version routing, and the rendered version selector must all describe the same
|
|
133
|
+
release line.
|
|
134
|
+
|
|
135
|
+
### Checklist: Before Editing Versioned Docs
|
|
136
|
+
|
|
137
|
+
- [ ] Identify the target release line: stable, beta, or RC
|
|
138
|
+
- [ ] Verify the edited MDX path matches that line:
|
|
139
|
+
- stable: `docs-site/{start,advanced,...}` and `docs-site/zh/{start,advanced,...}`
|
|
140
|
+
- beta: `docs-site/beta/**` and `docs-site/zh/beta/**`
|
|
141
|
+
- RC: `docs-site/rc/**` and `docs-site/zh/rc/**`
|
|
142
|
+
- [ ] Verify `docs.json` navigation points the version label to the same paths
|
|
143
|
+
- [ ] Grep the opposite tree for release-line-specific terms before committing
|
|
144
|
+
- [ ] Treat beta content appearing under root release paths as a source-path bug,
|
|
145
|
+
not a rendering bug
|
|
146
|
+
|
|
147
|
+
**Real-world example**: A beta-only task workflow change documented
|
|
148
|
+
`prd.md` + `design.md` + `implement.md`, task-creation consent, and Codex
|
|
149
|
+
mode banners under root `start/` and `advanced/` paths. The docs site then
|
|
150
|
+
served 0.6 beta behavior under the Release selector. The fix was to restore root
|
|
151
|
+
release docs, move the 0.6 content to `beta/` and `zh/beta/`, and add a grep
|
|
152
|
+
audit for beta markers against the root release tree.
|
|
153
|
+
|
|
122
154
|
**Real-world example**: Codex inline mode changed workflow platform markers from
|
|
123
155
|
`[Codex]` / `[Kilo, Antigravity, Windsurf]` to `[codex-sub-agent]` /
|
|
124
156
|
`[codex-inline, Kilo, Antigravity, Windsurf]`. Fresh init was correct, but
|
|
@@ -134,6 +166,7 @@ could return empty Phase 2.1 detail.
|
|
|
134
166
|
When a CLI auto-detects a mode by probing a remote resource (e.g., checking if `index.json` exists to decide marketplace vs direct download):
|
|
135
167
|
|
|
136
168
|
### Before implementing:
|
|
169
|
+
|
|
137
170
|
- [ ] Probe runs in **ALL** code paths that use the result (interactive, `-y`, `--flag` combos)
|
|
138
171
|
- [ ] 404 vs transient error are distinguished — don't treat both as "not found"
|
|
139
172
|
- [ ] Transient errors **abort or retry**, never silently switch modes
|
|
@@ -141,6 +174,7 @@ When a CLI auto-detects a mode by probing a remote resource (e.g., checking if `
|
|
|
141
174
|
- [ ] **Shortcut paths** (e.g., `--template` skipping picker) must have the same error-handling quality as the probed path — check that downstream functions don't call catch-all wrappers
|
|
142
175
|
|
|
143
176
|
### After implementing:
|
|
177
|
+
|
|
144
178
|
- [ ] Trace every path from probe result to the mode-decision branch — no fallthrough
|
|
145
179
|
- [ ] External format contracts (giget URI, raw URLs) are tested or at least documented as comments
|
|
146
180
|
- [ ] Metadata reads consume a complete response or use a streaming parser — never parse a fixed-size prefix as full JSON
|
|
@@ -156,6 +190,7 @@ When a CLI auto-detects a mode by probing a remote resource (e.g., checking if `
|
|
|
156
190
|
## When to Create Flow Documentation
|
|
157
191
|
|
|
158
192
|
Create detailed flow docs when:
|
|
193
|
+
|
|
159
194
|
- Feature spans 3+ layers
|
|
160
195
|
- Multiple teams are involved
|
|
161
196
|
- Data format is complex
|
|
@@ -215,20 +215,26 @@ home = Path.home()
|
|
|
215
215
|
```
|
|
216
216
|
|
|
217
217
|
**Rule 2**: When injecting environment variables into shell commands, generate
|
|
218
|
-
the prefix for the actual
|
|
219
|
-
AI tool "Bash" surfaces on Windows may execute through
|
|
218
|
+
the prefix for the actual shell that will parse the command. Do not choose
|
|
219
|
+
syntax from OS alone. AI tool "Bash" surfaces on Windows may execute through
|
|
220
|
+
PowerShell, Git Bash, MSYS2, or another POSIX-like shell.
|
|
220
221
|
|
|
221
222
|
```javascript
|
|
222
223
|
// BAD - breaks when the host shell is PowerShell
|
|
223
224
|
command = `export TRELLIS_CONTEXT_ID=${shellQuote(contextKey)}; ${command}`;
|
|
224
225
|
|
|
225
|
-
// GOOD - shell-aware command prefix
|
|
226
|
-
const prefix = process.platform === "win32"
|
|
226
|
+
// GOOD - shell-dialect-aware command prefix
|
|
227
|
+
const prefix = process.platform === "win32" && !isWindowsPosixShell(process.env)
|
|
227
228
|
? `$env:TRELLIS_CONTEXT_ID = ${powershellQuote(contextKey)}; `
|
|
228
229
|
: `export TRELLIS_CONTEXT_ID=${shellQuote(contextKey)}; `;
|
|
229
230
|
command = `${prefix}${command}`;
|
|
230
231
|
```
|
|
231
232
|
|
|
233
|
+
On Windows, treat `MSYSTEM`, `MINGW_PREFIX`, `OSTYPE=msys|mingw|cygwin`,
|
|
234
|
+
`SHELL=...bash`, or a platform-specific Git Bash setting as POSIX-shell
|
|
235
|
+
signals. Keep PowerShell as the Windows default when there is no POSIX-shell
|
|
236
|
+
signal.
|
|
237
|
+
|
|
232
238
|
Also make duplicate-injection detection shell-aware. A guard that only matches
|
|
233
239
|
`export VAR=` will miss PowerShell's `$env:VAR = ...` form and can wrap an
|
|
234
240
|
already-correct command a second time.
|
|
@@ -63,6 +63,21 @@ function buildContextKey(platformName, kind, value) {
|
|
|
63
63
|
return safeValue ? `${platformName}_${safeValue}` : `${platformName}_${hashValue(value)}`
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
// Matches `trellis-implement`, `trellis-check`, `trellis-research` exactly.
|
|
67
|
+
// Used by chat.message plugins to skip injection inside Trellis sub-agent turns.
|
|
68
|
+
const TRELLIS_SUBAGENT_RE = /^trellis-(implement|check|research)$/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Return true when the OpenCode `chat.message` input represents a Trellis
|
|
72
|
+
* sub-agent turn. `input.agent` is set by OpenCode when a Task tool spawns a
|
|
73
|
+
* child session with a custom agent (see `packages/opencode/src/tool/task.ts`).
|
|
74
|
+
*/
|
|
75
|
+
export function isTrellisSubagent(input) {
|
|
76
|
+
if (!input || typeof input !== "object") return false
|
|
77
|
+
const agent = typeof input.agent === "string" ? input.agent.trim() : ""
|
|
78
|
+
return TRELLIS_SUBAGENT_RE.test(agent)
|
|
79
|
+
}
|
|
80
|
+
|
|
66
81
|
/**
|
|
67
82
|
* Trellis Context Manager
|
|
68
83
|
*/
|
|
@@ -116,27 +131,74 @@ export class TrellisContext {
|
|
|
116
131
|
|
|
117
132
|
/**
|
|
118
133
|
* Get active task from session runtime context.
|
|
134
|
+
*
|
|
135
|
+
* Resolution order (mirrors Python `active_task.resolve_active_task`):
|
|
136
|
+
* 1. Lookup the runtime file for the input-derived context key.
|
|
137
|
+
* 2. If that misses and exactly one session runtime file exists locally,
|
|
138
|
+
* use it (`_resolveSingleSessionFallback`). Refuses to guess when 0 or
|
|
139
|
+
* ≥2 files exist so multi-window isolation holds.
|
|
119
140
|
*/
|
|
120
141
|
getActiveTask(platformInput = null) {
|
|
121
142
|
const contextKey = this.getContextKey(platformInput)
|
|
122
|
-
if (
|
|
123
|
-
|
|
143
|
+
if (contextKey) {
|
|
144
|
+
const context = this.readContext(contextKey)
|
|
145
|
+
const taskRef = this.normalizeTaskRef(context?.current_task || "")
|
|
146
|
+
if (taskRef) {
|
|
147
|
+
const taskDir = this.resolveTaskDir(taskRef)
|
|
148
|
+
return {
|
|
149
|
+
taskPath: taskRef,
|
|
150
|
+
source: `session:${contextKey}`,
|
|
151
|
+
stale: !taskDir || !existsSync(taskDir),
|
|
152
|
+
}
|
|
153
|
+
}
|
|
124
154
|
}
|
|
125
155
|
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const taskDir = this.resolveTaskDir(taskRef)
|
|
130
|
-
return {
|
|
131
|
-
taskPath: taskRef,
|
|
132
|
-
source: `session:${contextKey}`,
|
|
133
|
-
stale: !taskDir || !existsSync(taskDir),
|
|
134
|
-
}
|
|
156
|
+
const fallback = this._resolveSingleSessionFallback()
|
|
157
|
+
if (fallback) {
|
|
158
|
+
return fallback
|
|
135
159
|
}
|
|
136
160
|
|
|
137
161
|
return { taskPath: null, source: "none", stale: false }
|
|
138
162
|
}
|
|
139
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Mirror of Python `_resolve_single_session_fallback`. Returns the task
|
|
166
|
+
* pointed at by the sole session runtime file when exactly one exists,
|
|
167
|
+
* else null.
|
|
168
|
+
*/
|
|
169
|
+
_resolveSingleSessionFallback() {
|
|
170
|
+
const sessionsDir = join(this.directory, ".trellis", ".runtime", "sessions")
|
|
171
|
+
if (!existsSync(sessionsDir)) return null
|
|
172
|
+
|
|
173
|
+
let files
|
|
174
|
+
try {
|
|
175
|
+
files = readdirSync(sessionsDir)
|
|
176
|
+
.filter(name => name.endsWith(".json"))
|
|
177
|
+
.sort()
|
|
178
|
+
} catch {
|
|
179
|
+
return null
|
|
180
|
+
}
|
|
181
|
+
if (files.length !== 1) return null
|
|
182
|
+
|
|
183
|
+
const sessionFile = join(sessionsDir, files[0])
|
|
184
|
+
let context
|
|
185
|
+
try {
|
|
186
|
+
context = JSON.parse(readFileSync(sessionFile, "utf-8"))
|
|
187
|
+
} catch {
|
|
188
|
+
return null
|
|
189
|
+
}
|
|
190
|
+
const taskRef = this.normalizeTaskRef(context?.current_task || "")
|
|
191
|
+
if (!taskRef) return null
|
|
192
|
+
|
|
193
|
+
const taskDir = this.resolveTaskDir(taskRef)
|
|
194
|
+
const fallbackKey = files[0].replace(/\.json$/, "")
|
|
195
|
+
return {
|
|
196
|
+
taskPath: taskRef,
|
|
197
|
+
source: `session-fallback:${fallbackKey}`,
|
|
198
|
+
stale: !taskDir || !existsSync(taskDir),
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
140
202
|
getCurrentTask(platformInput = null) {
|
|
141
203
|
return this.getActiveTask(platformInput).taskPath
|
|
142
204
|
}
|
|
@@ -14,29 +14,44 @@ import { TrellisContext, debugLog } from "../lib/trellis-context.js"
|
|
|
14
14
|
const AGENTS_ALL = ["implement", "check", "research"]
|
|
15
15
|
const AGENTS_REQUIRE_TASK = ["implement", "check"]
|
|
16
16
|
|
|
17
|
+
// Match `Active task: <path>` on the first non-empty line of the dispatch
|
|
18
|
+
// prompt. Mirrors the contract in workflow.md's [workflow-state:in_progress]
|
|
19
|
+
// breadcrumb so multi-window users can disambiguate which task is targeted.
|
|
20
|
+
const ACTIVE_TASK_HINT_RE = /^\s*Active task:\s*(\S+)\s*$/m
|
|
21
|
+
|
|
22
|
+
function extractActiveTaskHint(prompt) {
|
|
23
|
+
if (typeof prompt !== "string" || !prompt) return null
|
|
24
|
+
const match = prompt.match(ACTIVE_TASK_HINT_RE)
|
|
25
|
+
return match ? match[1].trim() : null
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
/**
|
|
18
|
-
* Get context for implement agent
|
|
29
|
+
* Get context for implement agent. `taskDir` may be relative
|
|
30
|
+
* (`.trellis/tasks/foo`) or absolute; both are resolved via
|
|
31
|
+
* `ctx.resolveTaskDir`.
|
|
19
32
|
*/
|
|
20
33
|
function getImplementContext(ctx, taskDir) {
|
|
21
34
|
const parts = []
|
|
35
|
+
const taskDirFull = ctx.resolveTaskDir(taskDir)
|
|
36
|
+
if (!taskDirFull) return ""
|
|
22
37
|
|
|
23
|
-
const jsonlPath = join(
|
|
38
|
+
const jsonlPath = join(taskDirFull, "implement.jsonl")
|
|
24
39
|
const entries = ctx.readJsonlWithFiles(jsonlPath)
|
|
25
40
|
if (entries.length > 0) {
|
|
26
41
|
parts.push(ctx.buildContextFromEntries(entries))
|
|
27
42
|
}
|
|
28
43
|
|
|
29
|
-
const prd = ctx.
|
|
44
|
+
const prd = ctx.readFile(join(taskDirFull, "prd.md"))
|
|
30
45
|
if (prd) {
|
|
31
46
|
parts.push(`=== ${taskDir}/prd.md (Requirements) ===\n${prd}`)
|
|
32
47
|
}
|
|
33
48
|
|
|
34
|
-
const design = ctx.
|
|
49
|
+
const design = ctx.readFile(join(taskDirFull, "design.md"))
|
|
35
50
|
if (design) {
|
|
36
51
|
parts.push(`=== ${taskDir}/design.md (Technical Design) ===\n${design}`)
|
|
37
52
|
}
|
|
38
53
|
|
|
39
|
-
const implementPlan = ctx.
|
|
54
|
+
const implementPlan = ctx.readFile(join(taskDirFull, "implement.md"))
|
|
40
55
|
if (implementPlan) {
|
|
41
56
|
parts.push(`=== ${taskDir}/implement.md (Execution Plan) ===\n${implementPlan}`)
|
|
42
57
|
}
|
|
@@ -45,28 +60,30 @@ function getImplementContext(ctx, taskDir) {
|
|
|
45
60
|
}
|
|
46
61
|
|
|
47
62
|
/**
|
|
48
|
-
* Get context for check agent
|
|
63
|
+
* Get context for check agent. `taskDir` may be relative or absolute.
|
|
49
64
|
*/
|
|
50
65
|
function getCheckContext(ctx, taskDir) {
|
|
51
66
|
const parts = []
|
|
67
|
+
const taskDirFull = ctx.resolveTaskDir(taskDir)
|
|
68
|
+
if (!taskDirFull) return ""
|
|
52
69
|
|
|
53
|
-
const jsonlPath = join(
|
|
70
|
+
const jsonlPath = join(taskDirFull, "check.jsonl")
|
|
54
71
|
const entries = ctx.readJsonlWithFiles(jsonlPath)
|
|
55
72
|
if (entries.length > 0) {
|
|
56
73
|
parts.push(ctx.buildContextFromEntries(entries))
|
|
57
74
|
}
|
|
58
75
|
|
|
59
|
-
const prd = ctx.
|
|
76
|
+
const prd = ctx.readFile(join(taskDirFull, "prd.md"))
|
|
60
77
|
if (prd) {
|
|
61
78
|
parts.push(`=== ${taskDir}/prd.md (Requirements) ===\n${prd}`)
|
|
62
79
|
}
|
|
63
80
|
|
|
64
|
-
const design = ctx.
|
|
81
|
+
const design = ctx.readFile(join(taskDirFull, "design.md"))
|
|
65
82
|
if (design) {
|
|
66
83
|
parts.push(`=== ${taskDir}/design.md (Technical Design) ===\n${design}`)
|
|
67
84
|
}
|
|
68
85
|
|
|
69
|
-
const implementPlan = ctx.
|
|
86
|
+
const implementPlan = ctx.readFile(join(taskDirFull, "implement.md"))
|
|
70
87
|
if (implementPlan) {
|
|
71
88
|
parts.push(`=== ${taskDir}/implement.md (Execution Plan) ===\n${implementPlan}`)
|
|
72
89
|
}
|
|
@@ -143,7 +160,8 @@ function getResearchContext(ctx) {
|
|
|
143
160
|
*/
|
|
144
161
|
function buildPrompt(agentType, originalPrompt, context, isFinish = false) {
|
|
145
162
|
const templates = {
|
|
146
|
-
implement:
|
|
163
|
+
implement: `<!-- trellis-hook-injected -->
|
|
164
|
+
# Implement Agent Task
|
|
147
165
|
|
|
148
166
|
You are the Implement Agent in the Multi-Agent Pipeline.
|
|
149
167
|
|
|
@@ -172,7 +190,8 @@ ${originalPrompt}
|
|
|
172
190
|
- Follow all dev specs injected above
|
|
173
191
|
- Report list of modified/created files when done`,
|
|
174
192
|
|
|
175
|
-
check: isFinish ?
|
|
193
|
+
check: isFinish ? `<!-- trellis-hook-injected -->
|
|
194
|
+
# Finish Agent Task
|
|
176
195
|
|
|
177
196
|
You are performing the final check before creating a PR.
|
|
178
197
|
|
|
@@ -207,7 +226,8 @@ ${originalPrompt}
|
|
|
207
226
|
- If critical CODE issues found, report them clearly (fix specs, not code)
|
|
208
227
|
- Verify all acceptance criteria in prd.md are met
|
|
209
228
|
- Verify design.md and implement.md constraints when those files are present` :
|
|
210
|
-
|
|
229
|
+
`<!-- trellis-hook-injected -->
|
|
230
|
+
# Check Agent Task
|
|
211
231
|
|
|
212
232
|
You are the Check Agent in the Multi-Agent Pipeline.
|
|
213
233
|
|
|
@@ -235,7 +255,8 @@ ${originalPrompt}
|
|
|
235
255
|
- Fix issues yourself, don't just report
|
|
236
256
|
- Must execute complete checklist`,
|
|
237
257
|
|
|
238
|
-
research:
|
|
258
|
+
research: `<!-- trellis-hook-injected -->
|
|
259
|
+
# Research Agent Task
|
|
239
260
|
|
|
240
261
|
You are the Research Agent in the Multi-Agent Pipeline.
|
|
241
262
|
|
|
@@ -280,9 +301,29 @@ function powershellQuote(value) {
|
|
|
280
301
|
return `'${String(value).replace(/'/g, "''")}'`
|
|
281
302
|
}
|
|
282
303
|
|
|
283
|
-
function
|
|
284
|
-
|
|
285
|
-
|
|
304
|
+
function envValue(env, key) {
|
|
305
|
+
const value = env?.[key]
|
|
306
|
+
return typeof value === "string" && value.trim() ? value.trim() : null
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function shellBasename(value) {
|
|
310
|
+
return value.replace(/\\/g, "/").split("/").pop()?.toLowerCase() || ""
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function isWindowsPosixShell(env = process.env) {
|
|
314
|
+
if (envValue(env, "MSYSTEM")) return true
|
|
315
|
+
if (envValue(env, "MINGW_PREFIX")) return true
|
|
316
|
+
if (envValue(env, "OPENCODE_GIT_BASH_PATH")) return true
|
|
317
|
+
|
|
318
|
+
const ostype = envValue(env, "OSTYPE")?.toLowerCase() || ""
|
|
319
|
+
if (/(msys|mingw|cygwin)/.test(ostype)) return true
|
|
320
|
+
|
|
321
|
+
const shell = shellBasename(envValue(env, "SHELL") || "")
|
|
322
|
+
return /^(bash|sh|zsh)(\.exe)?$/.test(shell)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function buildTrellisContextPrefix(contextKey, hostPlatform = process.platform, env = process.env) {
|
|
326
|
+
if (hostPlatform === "win32" && !isWindowsPosixShell(env)) {
|
|
286
327
|
return `$env:TRELLIS_CONTEXT_ID = ${powershellQuote(contextKey)}; `
|
|
287
328
|
}
|
|
288
329
|
|
|
@@ -301,7 +342,7 @@ function commandStartsWithTrellisContext(command) {
|
|
|
301
342
|
return (
|
|
302
343
|
/^TRELLIS_CONTEXT_ID\s*=/.test(firstCommand) ||
|
|
303
344
|
/^export\s+TRELLIS_CONTEXT_ID\s*=/.test(firstCommand) ||
|
|
304
|
-
/^env\s+(?:[
|
|
345
|
+
/^env\s+(?:(?:-\S+|[A-Za-z_][A-Za-z0-9_]*=\S*)\s+)*TRELLIS_CONTEXT_ID\s*=/.test(firstCommand) ||
|
|
305
346
|
/^\$env:TRELLIS_CONTEXT_ID\s*=/i.test(firstCommand)
|
|
306
347
|
)
|
|
307
348
|
}
|
|
@@ -310,7 +351,7 @@ function commandStartsWithTrellisContext(command) {
|
|
|
310
351
|
* OpenCode TUI may not expose OPENCODE_RUN_ID to Bash. The plugin hook still
|
|
311
352
|
* receives session identity, so inject it into Bash commands before execution.
|
|
312
353
|
*/
|
|
313
|
-
function injectTrellisContextIntoBash(ctx, input, output, hostPlatform) {
|
|
354
|
+
function injectTrellisContextIntoBash(ctx, input, output, hostPlatform, env) {
|
|
314
355
|
const args = output?.args
|
|
315
356
|
const commandKey = getBashCommandKey(args)
|
|
316
357
|
if (!commandKey) return false
|
|
@@ -322,7 +363,7 @@ function injectTrellisContextIntoBash(ctx, input, output, hostPlatform) {
|
|
|
322
363
|
const contextKey = ctx.getContextKey(input)
|
|
323
364
|
if (!contextKey) return false
|
|
324
365
|
|
|
325
|
-
args[commandKey] = `${buildTrellisContextPrefix(contextKey, hostPlatform)}${command}`
|
|
366
|
+
args[commandKey] = `${buildTrellisContextPrefix(contextKey, hostPlatform, env)}${command}`
|
|
326
367
|
return true
|
|
327
368
|
}
|
|
328
369
|
|
|
@@ -331,7 +372,7 @@ function injectTrellisContextIntoBash(ctx, input, output, hostPlatform) {
|
|
|
331
372
|
// (packages/opencode/src/plugin/index.ts — `for ([_, fn] of Object.entries(mod)) await fn(input)`);
|
|
332
373
|
// the previous `{ id, server }` object shape failed with
|
|
333
374
|
// `TypeError: fn is not a function` in 1.2.x.
|
|
334
|
-
export default async ({ directory, platform: hostPlatform = process.platform }) => {
|
|
375
|
+
export default async ({ directory, platform: hostPlatform = process.platform, env = process.env }) => {
|
|
335
376
|
const ctx = new TrellisContext(directory)
|
|
336
377
|
debugLog("inject", "Plugin loaded, directory:", directory)
|
|
337
378
|
|
|
@@ -345,7 +386,7 @@ export default async ({ directory, platform: hostPlatform = process.platform })
|
|
|
345
386
|
|
|
346
387
|
const toolName = input?.tool?.toLowerCase()
|
|
347
388
|
if (toolName === "bash") {
|
|
348
|
-
if (injectTrellisContextIntoBash(ctx, input, output, hostPlatform)) {
|
|
389
|
+
if (injectTrellisContextIntoBash(ctx, input, output, hostPlatform, env)) {
|
|
349
390
|
debugLog("inject", "Injected TRELLIS_CONTEXT_ID into Bash command")
|
|
350
391
|
}
|
|
351
392
|
return
|
|
@@ -370,8 +411,53 @@ export default async ({ directory, platform: hostPlatform = process.platform })
|
|
|
370
411
|
return
|
|
371
412
|
}
|
|
372
413
|
|
|
373
|
-
// Resolve active task
|
|
374
|
-
|
|
414
|
+
// Resolve active task in this priority order (only later steps
|
|
415
|
+
// run when earlier ones miss):
|
|
416
|
+
// 1. Exact session runtime context lookup for input.sessionID
|
|
417
|
+
// 2. `Active task: <path>` hint in the dispatch prompt
|
|
418
|
+
// (explicit per-dispatch override — beats single-session
|
|
419
|
+
// inference so multi-window users can disambiguate)
|
|
420
|
+
// 3. Single-session fallback — only when exactly 1 session
|
|
421
|
+
// runtime file exists locally
|
|
422
|
+
let taskDir = null
|
|
423
|
+
let taskSource = null
|
|
424
|
+
|
|
425
|
+
const contextKey = ctx.getContextKey(input)
|
|
426
|
+
if (contextKey) {
|
|
427
|
+
const context = ctx.readContext(contextKey)
|
|
428
|
+
const exactRef = ctx.normalizeTaskRef(context?.current_task || "")
|
|
429
|
+
if (exactRef) {
|
|
430
|
+
taskDir = exactRef
|
|
431
|
+
taskSource = `session:${contextKey}`
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (!taskDir) {
|
|
436
|
+
const hintRef = extractActiveTaskHint(originalPrompt)
|
|
437
|
+
if (hintRef) {
|
|
438
|
+
const hintNormalized = ctx.normalizeTaskRef(hintRef)
|
|
439
|
+
if (hintNormalized) {
|
|
440
|
+
const hintDir = ctx.resolveTaskDir(hintNormalized)
|
|
441
|
+
if (hintDir && existsSync(hintDir)) {
|
|
442
|
+
taskDir = hintNormalized
|
|
443
|
+
taskSource = "prompt-hint"
|
|
444
|
+
debugLog("inject", "Resolved task from Active task: hint:", hintNormalized)
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (!taskDir) {
|
|
451
|
+
const fallback = ctx._resolveSingleSessionFallback()
|
|
452
|
+
if (fallback?.taskPath) {
|
|
453
|
+
const fallbackDir = ctx.resolveTaskDir(fallback.taskPath)
|
|
454
|
+
if (fallbackDir && existsSync(fallbackDir)) {
|
|
455
|
+
taskDir = fallback.taskPath
|
|
456
|
+
taskSource = fallback.source
|
|
457
|
+
debugLog("inject", "Resolved task via single-session fallback:", taskDir, "source:", taskSource)
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
375
461
|
|
|
376
462
|
// Agents requiring task directory
|
|
377
463
|
if (AGENTS_REQUIRE_TASK.includes(subagentType)) {
|
|
@@ -380,8 +466,8 @@ export default async ({ directory, platform: hostPlatform = process.platform })
|
|
|
380
466
|
debugLog("inject", "Skipping - no current task")
|
|
381
467
|
return
|
|
382
468
|
}
|
|
383
|
-
const taskDirFull =
|
|
384
|
-
if (!existsSync(taskDirFull)) {
|
|
469
|
+
const taskDirFull = ctx.resolveTaskDir(taskDir)
|
|
470
|
+
if (!taskDirFull || !existsSync(taskDirFull)) {
|
|
385
471
|
debugLog("inject", "Skipping - task directory not found")
|
|
386
472
|
return
|
|
387
473
|
}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
import { existsSync, readFileSync } from "fs"
|
|
27
27
|
import { join } from "path"
|
|
28
|
-
import { TrellisContext, debugLog } from "../lib/trellis-context.js"
|
|
28
|
+
import { TrellisContext, debugLog, isTrellisSubagent } from "../lib/trellis-context.js"
|
|
29
29
|
|
|
30
30
|
// Supports STATUS values with letters, digits, underscores, hyphens
|
|
31
31
|
// (so "in-review" / "blocked-by-team" work alongside "in_progress").
|
|
@@ -108,6 +108,13 @@ export default async ({ directory }) => {
|
|
|
108
108
|
// so it persists in conversation history.
|
|
109
109
|
"chat.message": async (input, output) => {
|
|
110
110
|
try {
|
|
111
|
+
// Skip Trellis sub-agent turns — the per-turn breadcrumb is for the
|
|
112
|
+
// main session only; sub-agent context comes from the parent's
|
|
113
|
+
// tool.execute.before injection.
|
|
114
|
+
if (isTrellisSubagent(input)) {
|
|
115
|
+
debugLog("workflow-state", "Skipping trellis subagent turn:", input?.agent)
|
|
116
|
+
return
|
|
117
|
+
}
|
|
111
118
|
if (process.env.TRELLIS_HOOKS === "0" || process.env.TRELLIS_DISABLE_HOOKS === "1") {
|
|
112
119
|
return
|
|
113
120
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Uses OpenCode's chat.message hook directly so the context persists in history.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { TrellisContext, contextCollector, debugLog } from "../lib/trellis-context.js"
|
|
9
|
+
import { TrellisContext, contextCollector, debugLog, isTrellisSubagent } from "../lib/trellis-context.js"
|
|
10
10
|
import {
|
|
11
11
|
buildSessionContext,
|
|
12
12
|
hasPersistedInjectedContext,
|
|
@@ -43,6 +43,14 @@ export default async ({ directory, client }) => {
|
|
|
43
43
|
const agent = input.agent || "unknown"
|
|
44
44
|
debugLog("session", "chat.message called, sessionID:", sessionID, "agent:", agent)
|
|
45
45
|
|
|
46
|
+
// Skip Trellis sub-agent turns — sub-agent context is injected by
|
|
47
|
+
// `inject-subagent-context.js` on the parent's tool.execute.before;
|
|
48
|
+
// re-injecting the main-session SessionStart here would drown that.
|
|
49
|
+
if (isTrellisSubagent(input)) {
|
|
50
|
+
debugLog("session", "Skipping trellis subagent turn:", agent)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
46
54
|
if (process.env.TRELLIS_HOOKS === "0" || process.env.TRELLIS_DISABLE_HOOKS === "1") {
|
|
47
55
|
debugLog("session", "Skipping - TRELLIS_HOOKS disabled")
|
|
48
56
|
return
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
9
|
"command": "{{PYTHON_CMD}} .qoder/hooks/session-start.py",
|
|
10
|
-
"timeout":
|
|
10
|
+
"timeout": 30
|
|
11
11
|
}
|
|
12
12
|
]
|
|
13
13
|
},
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
{
|
|
18
18
|
"type": "command",
|
|
19
19
|
"command": "{{PYTHON_CMD}} .qoder/hooks/session-start.py",
|
|
20
|
-
"timeout":
|
|
20
|
+
"timeout": 30
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
23
|
},
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
{
|
|
28
28
|
"type": "command",
|
|
29
29
|
"command": "{{PYTHON_CMD}} .qoder/hooks/session-start.py",
|
|
30
|
-
"timeout":
|
|
30
|
+
"timeout": 30
|
|
31
31
|
}
|
|
32
32
|
]
|
|
33
33
|
}
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
{
|
|
39
39
|
"type": "command",
|
|
40
40
|
"command": "{{PYTHON_CMD}} .qoder/hooks/inject-workflow-state.py",
|
|
41
|
-
"timeout":
|
|
41
|
+
"timeout": 15
|
|
42
42
|
}
|
|
43
43
|
]
|
|
44
44
|
}
|