opencastle 1.4.1 → 1.4.3

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 (120) hide show
  1. package/dist/cli/adapters/adapter-contract.test.js +85 -2
  2. package/dist/cli/adapters/adapter-contract.test.js.map +1 -1
  3. package/dist/cli/adapters/antigravity.d.ts +5 -4
  4. package/dist/cli/adapters/antigravity.d.ts.map +1 -1
  5. package/dist/cli/adapters/antigravity.js +5 -4
  6. package/dist/cli/adapters/antigravity.js.map +1 -1
  7. package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
  8. package/dist/cli/adapters/rules-dir-base.js +25 -19
  9. package/dist/cli/adapters/rules-dir-base.js.map +1 -1
  10. package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
  11. package/dist/cli/adapters/single-file-base.js +10 -7
  12. package/dist/cli/adapters/single-file-base.js.map +1 -1
  13. package/dist/cli/adapters/vscode.d.ts.map +1 -1
  14. package/dist/cli/adapters/vscode.js +11 -5
  15. package/dist/cli/adapters/vscode.js.map +1 -1
  16. package/dist/cli/adapters/workflows.d.ts +33 -0
  17. package/dist/cli/adapters/workflows.d.ts.map +1 -0
  18. package/dist/cli/adapters/workflows.js +58 -0
  19. package/dist/cli/adapters/workflows.js.map +1 -0
  20. package/dist/cli/adapters/workflows.test.d.ts +2 -0
  21. package/dist/cli/adapters/workflows.test.d.ts.map +1 -0
  22. package/dist/cli/adapters/workflows.test.js +62 -0
  23. package/dist/cli/adapters/workflows.test.js.map +1 -0
  24. package/dist/cli/convoy/spec-types.d.ts +15 -0
  25. package/dist/cli/convoy/spec-types.d.ts.map +1 -1
  26. package/dist/cli/docs-accuracy.test.js +3 -3
  27. package/dist/cli/docs-accuracy.test.js.map +1 -1
  28. package/dist/cli/explain.d.ts.map +1 -1
  29. package/dist/cli/explain.js +3 -1
  30. package/dist/cli/explain.js.map +1 -1
  31. package/dist/cli/pipeline.d.ts.map +1 -1
  32. package/dist/cli/pipeline.flow.test.js +134 -27
  33. package/dist/cli/pipeline.flow.test.js.map +1 -1
  34. package/dist/cli/pipeline.js +113 -34
  35. package/dist/cli/pipeline.js.map +1 -1
  36. package/dist/cli/plan.d.ts +22 -0
  37. package/dist/cli/plan.d.ts.map +1 -1
  38. package/dist/cli/plan.js +43 -6
  39. package/dist/cli/plan.js.map +1 -1
  40. package/dist/cli/run/adapters/claude.d.ts +13 -0
  41. package/dist/cli/run/adapters/claude.d.ts.map +1 -1
  42. package/dist/cli/run/adapters/claude.js +30 -1
  43. package/dist/cli/run/adapters/claude.js.map +1 -1
  44. package/dist/cli/run/adapters/claude.test.js +34 -1
  45. package/dist/cli/run/adapters/claude.test.js.map +1 -1
  46. package/dist/cli/run/adapters/codex.d.ts.map +1 -1
  47. package/dist/cli/run/adapters/codex.js +4 -0
  48. package/dist/cli/run/adapters/codex.js.map +1 -1
  49. package/dist/cli/run/adapters/codex.test.js +8 -0
  50. package/dist/cli/run/adapters/codex.test.js.map +1 -1
  51. package/dist/cli/run/adapters/copilot.d.ts.map +1 -1
  52. package/dist/cli/run/adapters/copilot.js +4 -1
  53. package/dist/cli/run/adapters/copilot.js.map +1 -1
  54. package/dist/cli/run/adapters/copilot.test.js +9 -0
  55. package/dist/cli/run/adapters/copilot.test.js.map +1 -1
  56. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts +2 -0
  57. package/dist/cli/run/adapters/stub-cli.test-helper.d.ts.map +1 -1
  58. package/dist/cli/run/adapters/stub-cli.test-helper.js +16 -1
  59. package/dist/cli/run/adapters/stub-cli.test-helper.js.map +1 -1
  60. package/dist/cli/run/platform.d.ts +12 -0
  61. package/dist/cli/run/platform.d.ts.map +1 -1
  62. package/dist/cli/run/platform.js +49 -0
  63. package/dist/cli/run/platform.js.map +1 -1
  64. package/dist/cli/run/platform.test.js +21 -1
  65. package/dist/cli/run/platform.test.js.map +1 -1
  66. package/package.json +1 -1
  67. package/src/cli/adapters/adapter-contract.test.ts +89 -2
  68. package/src/cli/adapters/antigravity.ts +5 -4
  69. package/src/cli/adapters/rules-dir-base.ts +30 -19
  70. package/src/cli/adapters/single-file-base.ts +10 -6
  71. package/src/cli/adapters/vscode.ts +11 -4
  72. package/src/cli/adapters/workflows.test.ts +70 -0
  73. package/src/cli/adapters/workflows.ts +62 -0
  74. package/src/cli/convoy/spec-types.ts +15 -0
  75. package/src/cli/docs-accuracy.test.ts +3 -3
  76. package/src/cli/explain.ts +3 -1
  77. package/src/cli/pipeline.flow.test.ts +143 -28
  78. package/src/cli/pipeline.ts +141 -34
  79. package/src/cli/plan.ts +51 -6
  80. package/src/cli/run/adapters/claude.test.ts +39 -1
  81. package/src/cli/run/adapters/claude.ts +27 -1
  82. package/src/cli/run/adapters/codex.test.ts +9 -0
  83. package/src/cli/run/adapters/codex.ts +3 -0
  84. package/src/cli/run/adapters/copilot.test.ts +11 -0
  85. package/src/cli/run/adapters/copilot.ts +3 -1
  86. package/src/cli/run/adapters/stub-cli.test-helper.ts +16 -1
  87. package/src/cli/run/platform.test.ts +23 -1
  88. package/src/cli/run/platform.ts +50 -0
  89. package/src/orchestrator/agent-workflows/README.md +2 -0
  90. package/src/orchestrator/agent-workflows/bug-fix.md +3 -3
  91. package/src/orchestrator/agent-workflows/data-pipeline.md +2 -2
  92. package/src/orchestrator/agent-workflows/database-migration.md +2 -2
  93. package/src/orchestrator/agent-workflows/feature-implementation.md +2 -2
  94. package/src/orchestrator/agent-workflows/performance-optimization.md +3 -3
  95. package/src/orchestrator/agent-workflows/refactoring.md +2 -2
  96. package/src/orchestrator/agent-workflows/schema-changes.md +2 -2
  97. package/src/orchestrator/agent-workflows/security-audit.md +2 -2
  98. package/src/orchestrator/agents/architect.agent.md +1 -1
  99. package/src/orchestrator/agents/content-engineer.agent.md +1 -1
  100. package/src/orchestrator/agents/data-engineer.agent.md +1 -1
  101. package/src/orchestrator/agents/developer.agent.md +1 -1
  102. package/src/orchestrator/agents/devops-expert.agent.md +1 -1
  103. package/src/orchestrator/agents/performance-expert.agent.md +1 -1
  104. package/src/orchestrator/agents/researcher.agent.md +1 -1
  105. package/src/orchestrator/agents/security-expert.agent.md +1 -1
  106. package/src/orchestrator/agents/team-lead.agent.md +3 -4
  107. package/src/orchestrator/agents/testing-expert.agent.md +1 -1
  108. package/src/orchestrator/agents/ui-ux-expert.agent.md +1 -1
  109. package/src/orchestrator/agents/writer.agent.md +1 -1
  110. package/src/orchestrator/instructions/general.instructions.md +2 -2
  111. package/src/orchestrator/plugins/chrome-devtools/skills/browser-testing/SKILL.md +1 -1
  112. package/src/orchestrator/plugins/nx/skills/nx-workspace/SKILL.md +1 -1
  113. package/src/orchestrator/prompts/brainstorm.prompt.md +1 -1
  114. package/src/orchestrator/prompts/bug-fix.prompt.md +3 -3
  115. package/src/orchestrator/prompts/implement-feature.prompt.md +2 -2
  116. package/src/orchestrator/prompts/quick-refinement.prompt.md +2 -2
  117. package/src/orchestrator/skills/api-patterns/SKILL.md +1 -1
  118. package/src/orchestrator/skills/deployment-infrastructure/SKILL.md +1 -1
  119. package/src/orchestrator/skills/team-lead-reference/SKILL.md +11 -11
  120. package/src/orchestrator/skills/validation-gates/SKILL.md +1 -1
@@ -3,7 +3,7 @@ import { existsSync, readFileSync, writeFileSync, readdirSync } from 'node:fs'
3
3
  import { join } from 'node:path'
4
4
  import type { Task } from '../../convoy/spec-types.js'
5
5
  import { installStubCli, type StubCli } from './stub-cli.test-helper.js'
6
- import { execute, isAvailable, kill, parseClaudeOutput } from './claude.js'
6
+ import { claudeSessionArgs, execute, isAvailable, kill, parseClaudeOutput } from './claude.js'
7
7
 
8
8
  const posix = process.platform !== 'win32'
9
9
 
@@ -182,6 +182,44 @@ describe.skipIf(!posix)('claude adapter — against a stub `claude`', () => {
182
182
  expect(argv).not.toContain('plan')
183
183
  })
184
184
 
185
+ /** What `claude --help` lists for these flags in a version that has them. */
186
+ const HELP = [
187
+ ' --effort <level> Effort level for the current session',
188
+ ' --strict-mcp-config Only use MCP servers from --mcp-config',
189
+ ' --disable-slash-commands Disable all skills',
190
+ ' --tools <tools...> Specify the list of available tools',
191
+ ].join('\n')
192
+
193
+ it('asks for less effort and a lean session when this version has the flags', async () => {
194
+ stub.help(HELP)
195
+ await execute(makeTask(), { cwd: stub.work, permissionMode: 'plan', effort: 'low', lean: true, model: 'sonnet' })
196
+ const argv = stub.argv()
197
+ expect(argv[argv.indexOf('--effort') + 1]).toBe('low')
198
+ expect(argv).toContain('--strict-mcp-config')
199
+ expect(argv).toContain('--disable-slash-commands')
200
+ expect(argv[argv.indexOf('--tools') + 1]).toBe('Read,Grep,Glob')
201
+ expect(argv[argv.indexOf('--model') + 1]).toBe('sonnet')
202
+ })
203
+
204
+ it('leaves out a flag an older version does not list, rather than fail the session', async () => {
205
+ stub.help(' --model <model> Model for the current session')
206
+ const result = await execute(makeTask(), { cwd: stub.work, effort: 'low', lean: true })
207
+ expect(result.success).toBe(true)
208
+ expect(stub.argv().filter((a) => /^--(effort|strict-mcp-config|disable-slash-commands|tools)$/.test(a))).toEqual([])
209
+ })
210
+
211
+ it('passes none of them to a worker that asks for neither', async () => {
212
+ stub.help(HELP)
213
+ await execute(makeTask(), { cwd: stub.work })
214
+ expect(stub.argv().filter((a) => /^--(effort|strict-mcp-config|disable-slash-commands|tools)$/.test(a))).toEqual([])
215
+ })
216
+
217
+ it('matches a flag by its whole name', () => {
218
+ expect(claudeSessionArgs({ effort: 'medium' }, ' --effort <level> x')).toEqual(['--effort', 'medium'])
219
+ expect(claudeSessionArgs({ effort: 'medium' }, ' --effortless x')).toEqual([])
220
+ expect(claudeSessionArgs({ lean: true }, ' --tools-extra x')).toEqual([])
221
+ })
222
+
185
223
  it('does not cap turns: the timeout bounds a session', async () => {
186
224
  await execute(makeTask(), { cwd: stub.work })
187
225
  expect(stub.argv()).not.toContain('--max-turns')
@@ -1,5 +1,5 @@
1
1
  import type { Task, ExecuteOptions, ExecuteResult, TokenUsage } from '../../convoy/spec-types.js'
2
- import { commandExists } from '../platform.js'
2
+ import { commandExists, helpText } from '../platform.js'
3
3
  import { runAgent, stopTask, promptOf, interruptedMessage, OUTPUT_LIMIT } from './agent-process.js'
4
4
 
5
5
  /**
@@ -134,11 +134,37 @@ export function claudePermissionArgs(mode: ExecuteOptions['permissionMode']): st
134
134
  return ['--permission-mode', mode ?? 'acceptEdits']
135
135
  }
136
136
 
137
+ /** The tools a lean session keeps: reading files, nothing else. */
138
+ export const LEAN_TOOLS = 'Read,Grep,Glob'
139
+
140
+ /**
141
+ * The flags that make a session cheaper and faster, each passed only when the
142
+ * installed Claude Code lists it in `--help`: a version without one fails the
143
+ * whole session on the unknown flag.
144
+ *
145
+ * A lean session starts no MCP server, loads no skill or command, and keeps
146
+ * only the tools that read files. Measured on a planning step it cost less than
147
+ * half as much — the skills, MCP tool schemas and sub-agent definitions no
148
+ * longer went into its context — and it could not wander into a web search.
149
+ */
150
+ export function claudeSessionArgs(options: Pick<ExecuteOptions, 'effort' | 'lean'>, help: string): string[] {
151
+ const has = (flag: string) => new RegExp(`(^|\\s)${flag}(\\s|,|=|$)`, 'm').test(help)
152
+ const args: string[] = []
153
+ if (options.effort && has('--effort')) args.push('--effort', options.effort)
154
+ if (options.lean) {
155
+ if (has('--strict-mcp-config')) args.push('--strict-mcp-config')
156
+ if (has('--disable-slash-commands')) args.push('--disable-slash-commands')
157
+ if (has('--tools')) args.push('--tools', LEAN_TOOLS)
158
+ }
159
+ return args
160
+ }
161
+
137
162
  export async function execute(task: Task, options: ExecuteOptions = {}): Promise<ExecuteResult> {
138
163
  // A worker has no terminal, so a permission prompt is a refusal it cannot
139
164
  // answer: without a mode it tries to write, is denied, and exits 0 having
140
165
  // written nothing. `acceptEdits` is the least that lets it do the work.
141
166
  const args = ['-p', '--output-format', 'json', ...claudePermissionArgs(options.permissionMode)]
167
+ if (options.effort || options.lean) args.push(...claudeSessionArgs(options, await helpText('claude')))
142
168
  if (options.model) args.push('--model', options.model)
143
169
  // No --max-turns: the task's timeout bounds a session, and a turn cap only
144
170
  // cut long tasks short with a result that looked like an ordinary failure.
@@ -125,6 +125,15 @@ describe.skipIf(!posix)('codex adapter — against a stub `codex`', () => {
125
125
  expect(argv[argv.indexOf('-m') + 1]).toBe('gpt-5.1-codex')
126
126
  })
127
127
 
128
+ it('sets the reasoning effort as a config override, quoted as TOML', async () => {
129
+ await execute(makeTask(), { cwd: stub.work })
130
+ expect(stub.argv()).not.toContain('-c')
131
+ await execute(makeTask(), { cwd: stub.work, effort: 'medium' })
132
+ const argv = stub.argv()
133
+ expect(argv[argv.indexOf('-c') + 1]).toBe('model_reasoning_effort="medium"')
134
+ expect(argv.at(-1)).toBe('-')
135
+ })
136
+
128
137
  it('reports the failure messages on a non-zero exit', async () => {
129
138
  process.env.STUB_EXIT = '1'
130
139
  delete process.env.STUB_LAST_MESSAGE
@@ -119,6 +119,9 @@ export async function execute(task: Task, options: ExecuteOptions = {}): Promise
119
119
  '-o', lastMessagePath,
120
120
  ]
121
121
  if (options.model) args.push('-m', options.model)
122
+ // A config override, which every `codex exec` takes; the value is TOML, so
123
+ // the string is quoted. No shell is involved, so the quotes reach codex.
124
+ if (options.effort) args.push('-c', `model_reasoning_effort="${options.effort}"`)
122
125
  args.push('-') // the prompt, from stdin
123
126
 
124
127
  try {
@@ -124,6 +124,17 @@ describe.skipIf(!posix)('copilot adapter — against a stub `copilot`', () => {
124
124
  expect(argv[argv.indexOf('--model') + 1]).toBe('gpt-5.2')
125
125
  })
126
126
 
127
+ it('asks for less effort only when this version has --effort', async () => {
128
+ stub.help(' --effort, --reasoning-effort <level> Set the reasoning effort level')
129
+ await execute(makeTask(), { cwd: stub.work, effort: 'low' })
130
+ const argv = stub.argv()
131
+ expect(argv[argv.indexOf('--effort') + 1]).toBe('low')
132
+
133
+ stub.help(' --model <model> Set the AI model to use')
134
+ await execute(makeTask(), { cwd: stub.work, effort: 'low' })
135
+ expect(stub.argv()).not.toContain('--effort')
136
+ })
137
+
127
138
  it('lets Copilot load the project\'s MCP config from an untrusted worktree', async () => {
128
139
  const script = join(stub.bin, 'copilot')
129
140
  writeFileSync(script, readFileSync(script, 'utf8').replace('pwd > "$log/cwd"', 'pwd > "$log/cwd"; printf %s "$GITHUB_COPILOT_PROMPT_MODE_WORKSPACE_MCP" > "$log/mcp"'))
@@ -1,5 +1,5 @@
1
1
  import type { Task, ExecuteOptions, ExecuteResult } from '../../convoy/spec-types.js'
2
- import { commandExists } from '../platform.js'
2
+ import { commandExists, helpText } from '../platform.js'
3
3
  import { copilotPermissionArgs } from './permission-modes.js'
4
4
  import { runAgent, stopTask, promptOf, interruptedMessage, OUTPUT_LIMIT } from './agent-process.js'
5
5
 
@@ -91,6 +91,8 @@ export function parseCopilotOutput(stdout: string): ParsedCopilot {
91
91
  export async function execute(task: Task, options: ExecuteOptions = {}): Promise<ExecuteResult> {
92
92
  const args = ['--output-format', 'json', '--no-ask-user', '--no-auto-update']
93
93
  if (options.model) args.push('--model', options.model)
94
+ // Only when this version has it: an unknown flag fails the session.
95
+ if (options.effort && /(^|\s)--effort[\s,]/m.test(await helpText('copilot'))) args.push('--effort', options.effort)
94
96
  args.push(...copilotPermissionArgs(options.permissionMode))
95
97
 
96
98
  const exit = await runAgent(task, {
@@ -1,6 +1,7 @@
1
1
  import { mkdtempSync, mkdirSync, writeFileSync, chmodSync, readFileSync, rmSync, realpathSync, existsSync } from 'node:fs'
2
2
  import { tmpdir } from 'node:os'
3
3
  import { join, delimiter } from 'node:path'
4
+ import { forgetHelpText } from '../platform.js'
4
5
 
5
6
  /**
6
7
  * A stand-in agent CLI for adapter tests: a POSIX shell script put on a
@@ -10,6 +11,9 @@ import { join, delimiter } from 'node:path'
10
11
  */
11
12
 
12
13
  const SCRIPT = `#!/bin/sh
14
+ # The adapters read --help to learn which flags this version has. It is
15
+ # answered here and not recorded, so argv is still the session's.
16
+ if [ "$1" = "--help" ]; then printf '%s\\n' "$STUB_HELP"; exit 0; fi
13
17
  log="$STUB_LOG"
14
18
  pwd > "$log/cwd"
15
19
  : > "$log/argv"
@@ -37,6 +41,8 @@ export interface StubCli {
37
41
  work: string
38
42
  /** What the stub prints on stdout (and stderr) next time it runs. */
39
43
  respond(stdout: string, stderr?: string): void
44
+ /** What it prints for `--help`; nothing until set. */
45
+ help(text: string): void
40
46
  argv(): string[]
41
47
  cwd(): string
42
48
  stdin(): string
@@ -59,7 +65,9 @@ export function installStubCli(...names: string[]): StubCli {
59
65
  writeFileSync(join(bin, name), SCRIPT)
60
66
  chmodSync(join(bin, name), 0o755)
61
67
  }
62
- const saved = { PATH: process.env.PATH, STUB_LOG: process.env.STUB_LOG }
68
+ const saved = { PATH: process.env.PATH, STUB_LOG: process.env.STUB_LOG, STUB_HELP: process.env.STUB_HELP }
69
+ delete process.env.STUB_HELP
70
+ forgetHelpText()
63
71
  process.env.PATH = [bin, '/usr/bin', '/bin'].join(delimiter)
64
72
  process.env.STUB_LOG = log
65
73
  const read = (f: string) => (existsSync(join(log, f)) ? readFileSync(join(log, f), 'utf8') : '')
@@ -67,6 +75,10 @@ export function installStubCli(...names: string[]): StubCli {
67
75
  bin,
68
76
  log,
69
77
  work,
78
+ help(text) {
79
+ process.env.STUB_HELP = text
80
+ forgetHelpText()
81
+ },
70
82
  respond(stdout, stderr) {
71
83
  writeFileSync(join(log, 'stdout.txt'), stdout)
72
84
  if (stderr !== undefined) writeFileSync(join(log, 'stderr.txt'), stderr)
@@ -78,6 +90,9 @@ export function installStubCli(...names: string[]): StubCli {
78
90
  process.env.PATH = saved.PATH
79
91
  if (saved.STUB_LOG === undefined) delete process.env.STUB_LOG
80
92
  else process.env.STUB_LOG = saved.STUB_LOG
93
+ if (saved.STUB_HELP === undefined) delete process.env.STUB_HELP
94
+ else process.env.STUB_HELP = saved.STUB_HELP
95
+ forgetHelpText()
81
96
  delete process.env.STUB_EXIT
82
97
  delete process.env.STUB_LAST_MESSAGE
83
98
  delete process.env.STUB_SLEEP
@@ -2,7 +2,7 @@ import { mkdtempSync, writeFileSync, chmodSync, rmSync, existsSync } from 'node:
2
2
  import { tmpdir } from 'node:os'
3
3
  import { join } from 'node:path'
4
4
  import { describe, it, expect, afterEach } from 'vitest'
5
- import { resolveCommand, commandExists, quoteForCmd, runShell, spawnCommand, killTree } from './platform.js'
5
+ import { resolveCommand, commandExists, quoteForCmd, runShell, spawnCommand, killTree, helpText, forgetHelpText } from './platform.js'
6
6
 
7
7
  const posix = process.platform !== 'win32'
8
8
 
@@ -26,6 +26,28 @@ describe('finding a command without `which`', () => {
26
26
  })
27
27
  })
28
28
 
29
+ describe('reading a CLI\'s --help', () => {
30
+ afterEach(() => forgetHelpText())
31
+
32
+ it('is empty for a command that is not there, and asks only once', async () => {
33
+ const missing = 'opencastle-no-such-cli-' + process.pid
34
+ expect(await helpText(missing)).toBe('')
35
+ expect(helpText(missing)).toBe(helpText(missing))
36
+ })
37
+
38
+ it.skipIf(!posix)('reads what the command prints', async () => {
39
+ const dir = mkdtempSync(join(tmpdir(), 'oc-help-'))
40
+ const cli = join(dir, 'fake-cli')
41
+ writeFileSync(cli, '#!/bin/sh\necho " --effort <level> Effort"\n')
42
+ chmodSync(cli, 0o755)
43
+ try {
44
+ expect(await helpText(cli)).toContain('--effort <level>')
45
+ } finally {
46
+ rmSync(dir, { recursive: true, force: true })
47
+ }
48
+ })
49
+ })
50
+
29
51
  describe('quoting for cmd.exe', () => {
30
52
  // The same output cross-spawn produces for these inputs.
31
53
  it('quotes and caret-escapes metacharacters', () => {
@@ -130,6 +130,56 @@ export function killTree(pid: number | undefined, graceMs = 5000): void {
130
130
  timer.unref()
131
131
  }
132
132
 
133
+ /** Help text by the resolved path of the command that printed it. */
134
+ const helpCache = new Map<string, Promise<string>>()
135
+
136
+ /**
137
+ * What `<command> --help` prints, read once per process.
138
+ *
139
+ * An agent CLI fails a whole session on a flag it does not know, and the flags
140
+ * that make a session faster arrive release by release. An adapter passes one
141
+ * only when the installed version lists it. Keyed by the path the command
142
+ * resolves to, so a different install on PATH is asked again. Empty when the
143
+ * command cannot be run or does not answer within `timeoutMs`.
144
+ */
145
+ export function helpText(command: string, timeoutMs = 10_000): Promise<string> {
146
+ const key = resolveCommand(command) ?? command
147
+ const known = helpCache.get(key)
148
+ if (known) return known
149
+ const asked = new Promise<string>((done) => {
150
+ let out = ''
151
+ let child: ChildProcess
152
+ try {
153
+ child = spawnCommand(command, ['--help'], { stdio: ['ignore', 'pipe', 'pipe'] })
154
+ } catch {
155
+ done('')
156
+ return
157
+ }
158
+ const timer = setTimeout(() => {
159
+ killTree(child.pid, 0)
160
+ done(out)
161
+ }, timeoutMs)
162
+ timer.unref()
163
+ child.stdout?.on('data', (d) => (out += String(d)))
164
+ child.stderr?.on('data', (d) => (out += String(d)))
165
+ child.on('error', () => {
166
+ clearTimeout(timer)
167
+ done('')
168
+ })
169
+ child.on('close', () => {
170
+ clearTimeout(timer)
171
+ done(out)
172
+ })
173
+ })
174
+ helpCache.set(key, asked)
175
+ return asked
176
+ }
177
+
178
+ /** Forget every help text read so far — for tests that swap a CLI. */
179
+ export function forgetHelpText(): void {
180
+ helpCache.clear()
181
+ }
182
+
133
183
  export interface ShellResult {
134
184
  code: number
135
185
  stdout: string
@@ -22,3 +22,5 @@ Declarative workflow templates for common orchestration patterns. Inspired by Sa
22
22
  | [Schema Changes](schema-changes.md) | CMS schema modifications, query updates, content model changes |
23
23
  | [Database Migration](database-migration.md) | Database migrations, RLS policies, type generation, rollback |
24
24
  | [Refactoring](refactoring.md) | Safe code refactoring with baseline metrics and behavior preservation |
25
+
26
+ Every template ends by pointing at [the shared delivery phase](shared-delivery-phase.md). The compiler replaces that pointer with the phase itself, so each installed template is complete and the phase is not installed on its own.
@@ -18,7 +18,7 @@ Phase 5: Delivery (direct, Team Lead)
18
18
 
19
19
  ## Branch & Delivery Strategy
20
20
 
21
- Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ownership** rules in `team-lead.agent.md`. Branch naming: `fix/<ticket-id>-<short-description>`.
21
+ The Team Lead creates the branch before any delegation and delivers it as the Delivery phase below describes. Branch naming: `fix/<ticket-id>-<short-description>`.
22
22
 
23
23
  ---
24
24
 
@@ -46,7 +46,7 @@ Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ow
46
46
  - [ ] Bug **confirmed reproduced** with screenshot evidence (or documented as non-reproducible with investigation notes)
47
47
  - [ ] Severity assessed
48
48
  - [ ] Tracker issue created with reproduction steps and screenshot
49
- - [ ] Affected apps identified (see `project.instructions.md` for inventory)
49
+ - [ ] Affected apps identified (see `.opencastle/project.instructions.md` for inventory)
50
50
 
51
51
  ---
52
52
 
@@ -119,7 +119,7 @@ Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ow
119
119
  - [ ] No regressions introduced
120
120
  - [ ] Tracker issue moved to Done
121
121
  - [ ] Known issues updated (if applicable)
122
- - [ ] Delivery Outcome completed (see `general.instructions.md`) — branch pushed, PR opened (not merged), tracker linked
122
+ - [ ] Delivery phase completed — branch pushed, PR opened (not merged), tracker linked
123
123
 
124
124
  ---
125
125
 
@@ -21,7 +21,7 @@ Phase 6: Delivery (direct, Team Lead)
21
21
 
22
22
  ## Branch & Delivery Strategy
23
23
 
24
- Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ownership** rules in `team-lead.agent.md`. Branch naming: `feat/<ticket-id>-<short-description>`. Only code changes are committed — NDJSON data files in `tmp/` are NOT committed to Git.
24
+ The Team Lead creates the branch before any delegation and delivers it as the Delivery phase below describes. Branch naming: `feat/<ticket-id>-<short-description>`. Only code changes are committed — NDJSON data files in `tmp/` are NOT committed to Git.
25
25
 
26
26
  ---
27
27
 
@@ -137,7 +137,7 @@ Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ow
137
137
  - [ ] Import statistics logged
138
138
  - [ ] <0.1% failure rate
139
139
  - [ ] Output contract returned
140
- - [ ] Delivery Outcome completed (see `general.instructions.md`) — branch pushed, PR opened (not merged), tracker linked
140
+ - [ ] Delivery phase completed — branch pushed, PR opened (not merged), tracker linked
141
141
 
142
142
  ---
143
143
 
@@ -21,7 +21,7 @@ Phase 6: Delivery (direct, Team Lead)
21
21
 
22
22
  ## Branch & Delivery Strategy
23
23
 
24
- Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ownership** rules in `team-lead.agent.md`. Branch naming: `feat/<ticket-id>-<short-description>` or `fix/<ticket-id>-<short-description>`.
24
+ The Team Lead creates the branch before any delegation and delivers it as the Delivery phase below describes. Branch naming: `feat/<ticket-id>-<short-description>` or `fix/<ticket-id>-<short-description>`.
25
25
 
26
26
  ---
27
27
 
@@ -150,7 +150,7 @@ Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ow
150
150
  - [ ] Panel review passed (if auth/RLS changes)
151
151
  - [ ] Rollback procedure documented
152
152
  - [ ] Tracker issue moved to Done
153
- - [ ] Delivery Outcome completed (see `general.instructions.md`) — branch pushed, PR opened (not merged), tracker linked
153
+ - [ ] Delivery phase completed — branch pushed, PR opened (not merged), tracker linked
154
154
 
155
155
  ---
156
156
 
@@ -128,7 +128,7 @@ If there are no open questions, explicitly state: "No open questions — plan is
128
128
 
129
129
  ### Typical Partitions
130
130
 
131
- > For project-specific paths, see `project.instructions.md` and the relevant `stack/` customization files.
131
+ > For project-specific paths, see `.opencastle/project.instructions.md` and the relevant `.opencastle/stack/` files.
132
132
 
133
133
  | Track | Agent | Files | Purpose |
134
134
  |-------|-------|-------|----------|
@@ -221,7 +221,7 @@ If there are no open questions, explicitly state: "No open questions — plan is
221
221
  - [ ] Full build passes
222
222
  - [ ] **Final smoke test passed** — complete user flow verified end-to-end
223
223
  - [ ] Roadmap updated
224
- - [ ] Delivery Outcome completed (see `general.instructions.md`) — branch pushed, PR opened (not merged), tracker linked
224
+ - [ ] Delivery phase completed — branch pushed, PR opened (not merged), tracker linked
225
225
 
226
226
  ---
227
227
 
@@ -18,7 +18,7 @@ Phase 5: Delivery (direct, Team Lead)
18
18
 
19
19
  ## Branch & Delivery Strategy
20
20
 
21
- Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ownership** rules in `team-lead.agent.md`. Branch naming: `perf/<ticket-id>-<short-description>` or `feat/<ticket-id>-<short-description>`.
21
+ The Team Lead creates the branch before any delegation and delivers it as the Delivery phase below describes. Branch naming: `perf/<ticket-id>-<short-description>` or `feat/<ticket-id>-<short-description>`.
22
22
 
23
23
  ---
24
24
 
@@ -38,7 +38,7 @@ Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ow
38
38
 
39
39
  ### Key Pages to Measure
40
40
 
41
- > See `project.instructions.md` for the app inventory and key routes. Prioritize pages with the most traffic and the most complex rendering.
41
+ > See `.opencastle/project.instructions.md` for the app inventory and key routes. Prioritize pages with the most traffic and the most complex rendering.
42
42
 
43
43
  ### Exit Criteria
44
44
 
@@ -116,7 +116,7 @@ Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ow
116
116
  - [ ] No functional regressions
117
117
  - [ ] Results documented in tracker issue
118
118
  - [ ] Roadmap updated
119
- - [ ] Delivery Outcome completed (see `general.instructions.md`) — branch pushed, PR opened (not merged), tracker linked
119
+ - [ ] Delivery phase completed — branch pushed, PR opened (not merged), tracker linked
120
120
 
121
121
  ---
122
122
 
@@ -19,7 +19,7 @@ Phase 6: Delivery (direct, Team Lead)
19
19
 
20
20
  ## Branch & Delivery Strategy
21
21
 
22
- Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ownership** rules in `team-lead.agent.md`. Branch naming: `refactor/<ticket-id>-<short-description>`.
22
+ The Team Lead creates the branch before any delegation and delivers it as the Delivery phase below describes. Branch naming: `refactor/<ticket-id>-<short-description>`.
23
23
 
24
24
  ---
25
25
 
@@ -133,7 +133,7 @@ The refactoring agent owns only the scoped files. No changes outside the partiti
133
133
  ### Exit Criteria
134
134
 
135
135
  - [ ] Panel PASS (2/3 majority)
136
- - [ ] Delivery Outcome completed (see `general.instructions.md`) — branch pushed, PR opened (not merged), tracker linked
136
+ - [ ] Delivery phase completed — branch pushed, PR opened (not merged), tracker linked
137
137
 
138
138
  ---
139
139
 
@@ -21,7 +21,7 @@ Phase 6: Delivery (direct, Team Lead)
21
21
 
22
22
  ## Branch & Delivery Strategy
23
23
 
24
- Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ownership** rules in `team-lead.agent.md`. Branch naming: `feat/<ticket-id>-<short-description>` or `chore/<ticket-id>-<short-description>`.
24
+ The Team Lead creates the branch before any delegation and delivers it as the Delivery phase below describes. Branch naming: `feat/<ticket-id>-<short-description>` or `chore/<ticket-id>-<short-description>`.
25
25
 
26
26
  ---
27
27
 
@@ -155,7 +155,7 @@ Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ow
155
155
  - [ ] Both apps verified (if shared code changed)
156
156
  - [ ] Data model documentation updated (if applicable)
157
157
  - [ ] Tracker issue moved to Done
158
- - [ ] Delivery Outcome completed (see `general.instructions.md`) — branch pushed, PR opened (not merged), tracker linked
158
+ - [ ] Delivery phase completed — branch pushed, PR opened (not merged), tracker linked
159
159
 
160
160
  ---
161
161
 
@@ -19,7 +19,7 @@ Phase 6: Delivery (direct, Team Lead)
19
19
 
20
20
  ## Branch & Delivery Strategy
21
21
 
22
- Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ownership** rules in `team-lead.agent.md`. Branch naming: `fix/<ticket-id>-<short-description>` for remediations.
22
+ The Team Lead creates the branch before any delegation and delivers it as the Delivery phase below describes. Branch naming: `fix/<ticket-id>-<short-description>` for remediations.
23
23
 
24
24
  ---
25
25
 
@@ -139,7 +139,7 @@ Follow the **Delivery Outcome** in `general.instructions.md` and the **Branch Ow
139
139
  - [ ] Panel review passed (if applicable)
140
140
  - [ ] Known issues updated for accepted risks
141
141
  - [ ] All tracker issues updated
142
- - [ ] Delivery Outcome completed (see `general.instructions.md`) — branch pushed, PR opened (not merged), tracker linked
142
+ - [ ] Delivery phase completed — branch pushed, PR opened (not merged), tracker linked
143
143
 
144
144
  ---
145
145
 
@@ -14,7 +14,7 @@ architecture, performance at scale, i18n, monetization.
14
14
 
15
15
  ## Skills
16
16
 
17
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
17
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
18
18
 
19
19
  ## Rules
20
20
 
@@ -12,7 +12,7 @@ CMS schema design, content queries and modeling, releases, studio customization.
12
12
 
13
13
  ## Skills
14
14
 
15
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
15
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
16
16
 
17
17
  ## Rules
18
18
 
@@ -13,7 +13,7 @@ policies that guard them, and the pipelines that fill them.
13
13
 
14
14
  ## Skills
15
15
 
16
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
16
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
17
17
 
18
18
  ## Rules — schema and migrations
19
19
 
@@ -13,7 +13,7 @@ feature implementation.
13
13
 
14
14
  ## Skills
15
15
 
16
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
16
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
17
17
 
18
18
  ## Rules
19
19
 
@@ -13,7 +13,7 @@ pre-release verification, changelogs.
13
13
 
14
14
  ## Skills
15
15
 
16
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
16
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
17
17
 
18
18
  ## Rules — deployment
19
19
 
@@ -12,7 +12,7 @@ Frontend, backend, and build performance.
12
12
 
13
13
  ## Skills
14
14
 
15
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
15
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
16
16
 
17
17
  ## Rules
18
18
 
@@ -12,7 +12,7 @@ Codebase exploration: find information, map patterns, report back.
12
12
 
13
13
  ## Skills
14
14
 
15
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
15
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
16
16
 
17
17
  ## Rules
18
18
 
@@ -13,7 +13,7 @@ API security, vulnerability management.
13
13
 
14
14
  ## Skills
15
15
 
16
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
16
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
17
17
 
18
18
  ## Rules
19
19
 
@@ -43,7 +43,6 @@ Load on-demand **only when the phase is reached**.
43
43
  | **agent-hooks** | Step 3 — delegation prompt templates |
44
44
  | **task-management** | Step 2 — tracker conventions |
45
45
  | **decomposition** | Step 2–3 — dependency resolution, delegation specs |
46
- | **agent-routing** | Step 2 — task-to-agent routing, anti-patterns |
47
46
  | **orchestration-protocols** | Step 4+ — steering, background agents, health-checks, escalation |
48
47
  | **context-map** | Step 2, 5+ files affected |
49
48
  | **validation-gates** | Step 4 — deterministic checks, browser testing, regression |
@@ -55,7 +54,7 @@ Load on-demand **only when the phase is reached**.
55
54
 
56
55
  Developer | UI/UX Expert | Content Engineer | Data Engineer | Testing Expert | Security Expert | Performance Expert | DevOps & Release | Architect | Writer | Researcher | Reviewer.
57
56
 
58
- > **⛔ Developer is LAST resort.** Load **agent-routing** before assigning. Decompose multi-domain tasks across agent boundaries.
57
+ > **⛔ Developer is LAST resort.** Route each task by the **Best For** column of `.opencastle/agents/agent-registry.md` before assigning. Decompose multi-domain tasks across agent boundaries.
59
58
 
60
59
  ## Delegation
61
60
 
@@ -63,7 +62,7 @@ Developer | UI/UX Expert | Content Engineer | Data Engineer | Testing Expert | S
63
62
 
64
63
  **⛔ Hard gates:**
65
64
  - Log delegation record immediately after each return/spawn — **observability-logging** (`--mechanism sub-agent` or `--mechanism background`).
66
- - `model` and `tier` from agent registry only.
65
+ - `tier` from the agent registry only; `model` is the one the assistant actually ran, when it says.
67
66
  - Empty/off-topic: retry max 3 → DLQ. Log failures (`--outcome failed`).
68
67
 
69
68
  **Partitioning:** Parallel agents never touch the same files. **Budget:** Target 5–7/session; 8 → warn; 9 → checkpoint; 10+ → STOP. **Pre-Delegation:** (1) Tracker issue, (2) clean partition, (3) dependencies Done, (4) file paths + criteria, (5) self-improvement reminder.
@@ -86,7 +85,7 @@ Developer | UI/UX Expert | Content Engineer | Data Engineer | Testing Expert | S
86
85
 
87
86
  **Step 4 — Execute:** Per task: move → In Progress → delegate → log delegation ⛔ → monitor → verify (partition, lint/test/build, fast review PASS, UI browser-verified, high-stakes → panel, issues tracked, lessons captured) → log review ⛔ → Done. FAIL → re-delegate (max 3 → DLQ). Auto-PASS: research/docs-only, or ≤10 lines/≤2 files with gates passing.
88
87
 
89
- **Step 5 — Deliver:** See [shared-delivery-phase.md](../agent-workflows/shared-delivery-phase.md). Verify all Done → build/lint/test → commit feature branch → `GH_PAGER=cat gh pr create` — do NOT merge → link PR → clean checkpoint → call **Reviewer**.
88
+ **Step 5 — Deliver:** Follow the workflow template's Delivery phase. Verify all Done → build/lint/test → commit feature branch → `GH_PAGER=cat gh pr create` — do NOT merge → link PR → clean checkpoint → call **Reviewer**.
90
89
 
91
90
  **On Resume:** Read `SESSION-CHECKPOINT.md`. Check `AGENT-FAILURES.md`, `DISPUTES.md`. List In Progress / Todo → continue.
92
91
 
@@ -12,7 +12,7 @@ Browser validation of UI changes; E2E and integration suites.
12
12
 
13
13
  ## Skills
14
14
 
15
- Resolve skills via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
15
+ Resolve skills via `.opencastle/agents/skill-matrix.json`.
16
16
 
17
17
  ## Rules
18
18
 
@@ -12,7 +12,7 @@ Accessible, consistent UI components built against the project design system.
12
12
 
13
13
  ## Skills
14
14
 
15
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
15
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
16
16
 
17
17
  ## Rules
18
18
 
@@ -15,7 +15,7 @@ is worse than no doc.
15
15
 
16
16
  ## Skills
17
17
 
18
- Resolve skills (slots, direct) via [skill-matrix.json](.opencastle/agents/skill-matrix.json).
18
+ Resolve skills (slots, direct) via `.opencastle/agents/skill-matrix.json`.
19
19
 
20
20
  ## Hard limits
21
21