agent-templates 0.2.1 → 0.3.0

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/CLAUDE.md CHANGED
@@ -48,12 +48,13 @@ patterns/three-agent-architect-builder-reviewer/
48
48
  ├── INSTALL.md # how to drop the scaffold into a target repo
49
49
  ├── claude-md-snippet.md # block to append to the target repo's CLAUDE.md
50
50
  └── .claude/
51
- ├── settings.json # PreToolUse write guard wiring
51
+ ├── settings.json # PreToolUse write guard + deterministic-script allowlist
52
52
  ├── hooks/
53
53
  │ └── guard-main-session-writes.mjs
54
54
  ├── scripts/
55
55
  │ ├── publish-tickets.mjs
56
- └── milestone-dag.mjs
56
+ ├── milestone-dag.mjs
57
+ │ └── deliver-ticket.mjs
57
58
  ├── workflows/
58
59
  │ ├── run-milestone.js
59
60
  │ ├── start-all.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-templates",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Catalog of multi-agent development architecture patterns - design write-ups plus drop-in scaffolding (agents, slash commands, workflows, templates).",
5
5
  "license": "MIT",
6
6
  "author": "Horace Hou",
@@ -152,6 +152,8 @@ Install steps and usage modes: [scaffold/INSTALL.md](scaffold/INSTALL.md). Front
152
152
  | 2026-07-17 | Gate 1 made concrete: `/start-milestone` = the human start signal → tickets auto-published as tracker issues (`publish-tickets.mjs`, adapted from fx-eye-tracking `create-issues.mjs`; `[<id>]` title prefix as dedupe key; smoke-tested dry-run/no-CLI/usage paths) → deterministic milestone runner (`run-milestone.js` Workflow script: stage order, reviewer freshness, bounce cap, merge policy in code). Added `templates/ticket.template.md` (adapted from fx ticket discipline). Recorded the Bash guard boundary as a known pitfall. Clarified `ultracode`: a session setting (`xhigh` + automatic workflow orchestration), not a model effort level — role efforts unchanged. | Maintainer direction (Horace Hou), 2026-07-17. fx-eye-tracking conventions read the same day (read-only). Workflow tool, `.claude/workflows/`, and `ultracode` semantics verified against live docs (workflows, claude-directory, model-config — record in `scaffold/INSTALL.md`). | Horace Hou (direction) / Claude Fable 5 (write-up) |
153
153
  | 2026-07-18 | **`/start-all` shipped** (catalog issue #20; maintainer-decided semantics: failed module blocks dependents, independent branches continue in `autonomous`, any non-CLEAR stops everything in `supervised`, no cost cap, resume via closed-issue filtering): deterministic DAG script (`milestone-dag.mjs`, ticket `blocked_by` as ground truth, cycles/dangling refs are hard errors) + `start-all` workflow composing `run-milestone` per module + `/start-all` command. 19 new E2E checks (DAG fixtures incl. cycle; module-policy scenarios via stubbed child workflows). Per-ticket stages unchanged. | Maintainer answers on issue #20, 2026-07-18. | Horace Hou (decisions) / Claude Fable 5 (build) |
154
154
  | 2026-07-18 | **First field bug fixed** (catalog issue #21, reported from Ruihang2017/Groundwork through the upstream feedback channel): CRLF-rewritten workflow scripts are rejected by the Workflow tool on Windows. Fix: repo-wide `.gitattributes` (`eol=lf`), working tree renormalized (67 files), `adopt.mjs` installs all text as LF, E2E `\r` guards added. Recorded as the pattern's first true `[internal]` pitfall observation. | Field report (Horace Hou via Groundwork), 2026-07-18. | Horace Hou (report) / Claude Fable 5 (fix) |
155
+ | 2026-07-19 | **Delivery made deterministic** (catalog issue #26, field report: harness safety classifiers blocked the agent-run deliver stage 3/3 after journaled CLEARs): new `.claude/scripts/deliver-ticket.mjs` — clean-tree guard, `--no-ff` merge (idempotent on re-runs, conflicts abort clean), push, tracker close with post-close verification (`--issue` or `[<id>]` title-prefix lookup), deterministic DoD, `DELIVER-SUMMARY-JSON` contract; run-milestone's deliver agent reduced to executing that one command and relaying its summary; `settings.json` gained explicit allow rules for the three deterministic scripts. E2E: new suite-deliver (12 scenarios on real temp git repos + fake CLIs). The tracker close only happens after merge AND push actually landed — a closed issue is what resume filtering treats as delivered, so closing on a failed delivery would silently drop the ticket. One DoD item relocated: the post-merge test run executes deterministically when `testCmd` is supplied (workflow arg, forwarded as `--test-cmd`; `/start-all` passes it through) and otherwise stays with `/verify-delivery` — builder and reviewer both already ran tests on the branch. Per-ticket stages before deliver, and the model/effort table, unchanged. | Field report (Horace Hou via Groundwork), 2026-07-18; fix direction proposed in the issue itself. | Horace Hou (report) / Claude Fable 5 (fix) |
156
+ | 2026-07-19 | **Field bug #3 fixed** (catalog issue #27, reported from Ruihang2017/Groundwork2): `/start-all` step 3 never stated that `modules[].tickets` elements must be `{id, path, issue}` objects joined from two sources (DAG plan order + per-module `PUBLISH-SUMMARY-JSON`) — the DAG JSON alone emits bare id strings, which run-milestone's validator rejects. Command doc now names the exact shape and the join; `/start-milestone` already documented it. (The issue's other defect — stringified Workflow `args` — was already fixed under #23 / v0.2.1.) | Field report (Horace Hou via Groundwork2), 2026-07-18. | Horace Hou (report) / Claude Fable 5 (fix) |
155
157
  | 2026-07-18 | **Field bug #2 fixed** (catalog issue #23, same reporter channel): (a) #21's install-time LF fix did not survive target-side git checkouts — `adopt.mjs` now installs/appends a target-repo `.gitattributes` pinning `.claude/workflows/*.js` + `.claude/scripts/*.mjs` to `eol=lf` (marker-checked, append-once); (b) Workflow `args` can arrive JSON-stringified — all three workflow scripts gained the `typeof args === 'string' ? JSON.parse(args) : (args \|\| {})` shim. Both recorded as §4 pitfalls; E2E extended (stringified-args runner + start-all scenarios; `.gitattributes` install/append/idempotency). Per-ticket stages and model/effort table unchanged. | Field report (Horace Hou via Groundwork), 2026-07-18. | Horace Hou (report) / Claude Fable 5 (fix) |
156
158
  | 2026-07-17 | **Catalog site**: claymorphic GitHub Pages page generated from pattern data (`scripts/build-site.mjs` — parses pattern README metadata/§1/§3 + package.json; live npm-version fetch with build-time fallback; deployed via `gh-pages` branch). Style spec + generated-not-handwritten rationale in catalog issue #17. | Maintainer direction (Horace Hou) with reference designs, 2026-07-17. | Horace Hou (direction) / Claude Fable 5 (build) |
157
159
  | 2026-07-17 | **Released**: catalog published to public npm as `agent-templates` under MIT (maintainer decisions: MIT + personal ownership + publish, 2026-07-17 — catalog issue #15). README carries the scaffold-output attribution carve-out. Adoption command is now `npx agent-templates@latest adopt …`. | Maintainer decision (Horace Hou), 2026-07-17. | Horace Hou (decision) / Claude Fable 5 (release) |
@@ -8,8 +8,8 @@ Arguments: `$ARGUMENTS` — optional mode override (else the repo's declared Ope
8
8
  Typing this command is the human Gate 1 sign-off **for the whole PRD** — every module, in dependency order. Prefer `/start-milestone` per module when you still want module-boundary checkpoints. Execute in order:
9
9
 
10
10
  1. **Compute the plan.** Run `node .claude/scripts/milestone-dag.mjs` and show its output (module order, per-module dependencies). STOP on any error — a dangling `blocked_by` or a cycle is a spec defect for the Architect/human, not something to patch here.
11
- 2. **Publish all tickets.** For each module in DAG order: `node .claude/scripts/publish-tickets.mjs docs/prd/<module>` (dry-run, then `--create`; STOP on `error` entries). Then, per module, **filter out tickets whose issues are already closed** (closed = delivered by an earlier run — this makes `/start-all` re-runs resume: fully-closed modules pass an empty ticket list and are marked already-complete).
12
- 3. **Launch the driver.** Call the **Workflow** tool with `name: "start-all"` and `args: { modules: [{name, dependsOn, tickets}] in DAG order, mode, defaultBranch, platform }`. This command's instruction is your authorization to use the Workflow tool. Failure policy is enforced in the workflow: failed modules block their dependents; independent branches continue in `autonomous`; anything short of a CLEAR stops everything in `supervised`.
11
+ 2. **Publish all tickets.** For each module in DAG order: `node .claude/scripts/publish-tickets.mjs docs/prd/<module>` (dry-run, then `--create`; STOP on `error` entries). Keep each module's `PUBLISH-SUMMARY-JSON` line — step 3 needs it. Then, per module, **filter out tickets whose issues are already closed** (closed = delivered by an earlier run — this makes `/start-all` re-runs resume: fully-closed modules pass an empty ticket list and are marked already-complete).
12
+ 3. **Launch the driver.** Call the **Workflow** tool with `name: "start-all"` and `args: { modules: [{name, dependsOn, tickets}] in DAG order, mode, defaultBranch, platform }`. Each element of `tickets` MUST be an object `{id, path, issue}` — the exact shape run-milestone validates (issue #27; bare id strings fail). Build it by joining the two step outputs per module: ticket ids and their order come from the DAG plan (step 1), `path` and `issue` come from that module's `PUBLISH-SUMMARY-JSON` (step 2), matched by `id`. Add `testCmd` (the repo's test command, if its CLAUDE.md declares one) so the deterministic deliver script re-runs tests on the merged default branch as part of DoD. This command's instruction is your authorization to use the Workflow tool. Failure policy is enforced in the workflow: failed modules block their dependents; independent branches continue in `autonomous`; anything short of a CLEAR stops everything in `supervised`.
13
13
  4. **Relay the final report verbatim** — per module: `completed` / `already-complete` / `paused-for-merge` (supervised: tell the human to merge, then re-run this command) / `failed` (with the failing ticket + stage) / `skipped-dependency` / `not-started`. Escalations inside a module carry through from run-milestone unchanged.
14
14
 
15
15
  While the workflow runs you are an observer. Do not do stage work in parallel, do not "help" a slow stage, do not edit files.
@@ -9,7 +9,7 @@ Typing this command **is** the human Gate 1 sign-off: the sub-PRD and tickets ar
9
9
 
10
10
  1. **Verify Gate 1 inputs.** `MODULE/README.md` (the sub-PRD) exists and `MODULE/tickets/*.md` is non-empty; every ticket has the required frontmatter (see `templates/ticket.template.md`). Anything missing → STOP and list exactly what is missing. Do not fix it yourself — that is Architect-stage work.
11
11
  2. **Publish tickets as tracker issues.** Run `node .claude/scripts/publish-tickets.mjs MODULE` (dry-run) and show the mapping. If the summary contains `error` entries → STOP and report them. Otherwise re-run with `--create` (idempotent — the `[<id>]` title prefix dedupes, so re-running is safe), and again STOP on any `error` entries.
12
- 3. **Launch the pipeline.** Parse the final `PUBLISH-SUMMARY-JSON` line into `tickets: [{id, path, issue}]`. **Filter out tickets whose issue is already closed** (check via `gh`/`glab` — closed means delivered by an earlier run; this filter is what makes re-runs after supervised pauses or crashes safe). Determine the Operating mode, then call the **Workflow** tool with `name: "run-milestone"` and `args: { tickets, mode, defaultBranch, platform }`. This command's instruction is your authorization to use the Workflow tool.
12
+ 3. **Launch the pipeline.** Parse the final `PUBLISH-SUMMARY-JSON` line into `tickets: [{id, path, issue}]`. **Filter out tickets whose issue is already closed** (check via `gh`/`glab` — closed means delivered by an earlier run; this filter is what makes re-runs after supervised pauses or crashes safe). Determine the Operating mode, then call the **Workflow** tool with `name: "run-milestone"` and `args: { tickets, mode, defaultBranch, platform }` — plus `testCmd` (the repo's test command, if its CLAUDE.md declares one) so the deterministic deliver script re-runs tests on the merged default branch as part of DoD. This command's instruction is your authorization to use the Workflow tool.
13
13
  4. **Relay the final report verbatim** — per ticket: `delivered` · `awaiting-human-merge` · `escalated` (stage `review`, `reviewer-failed`, or `bounce-fix-build`) · `failed` · `delivery-incomplete`, plus `notStarted` when the run stopped early. Escalated and failed items go to the human; do not fix them inline (the write guard will hold you to that). In `supervised` mode the run stops after each CLEAR verdict — tell the human to merge, then re-run this command to continue.
14
14
 
15
15
  While the workflow runs you are an observer. Do not do stage work in parallel, do not "help" a slow stage, do not edit files.
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/env node
2
+ // deliver-ticket.mjs — the ONLY sanctioned delivery path for the three-agent
3
+ // pattern (catalog issue #26). Delivery used to be a generic LLM agent prompted
4
+ // to merge + close + verify; harness safety classifiers repeatedly blocked that
5
+ // agent even after a journaled CLEAR (3/3 in one field session), stranding
6
+ // CLEAR-verdict tickets. Like issue creation (publish-tickets.mjs), delivery is
7
+ // now deterministic: the merge policy stays mechanically checkable and the only
8
+ // permission surface is this one command.
9
+ //
10
+ // Usage:
11
+ // node .claude/scripts/deliver-ticket.mjs --id <ticket-id> --branch <branch>
12
+ // [--default-branch main] [--issue <n>] [--platform gh|glab]
13
+ // [--test-cmd "<command>"]
14
+ //
15
+ // Does, in order (every step lands in the summary):
16
+ // 1. refuses to run on a dirty working tree
17
+ // 2. checks out <default-branch>; merges <branch> with --no-ff (an
18
+ // already-merged branch is recognized and succeeds idempotently);
19
+ // a conflict aborts the merge and leaves the tree clean
20
+ // 3. pushes <default-branch> to origin (required only when origin exists)
21
+ // 4. closes the tracker issue (--issue <n>, else looked up by the "[<id>]"
22
+ // title prefix) and VERIFIES it is actually closed afterwards
23
+ // 5. deterministic DoD: plan file exists (docs/plans/<id>.md), merged,
24
+ // pushed, issue closed, plus --test-cmd green when supplied (post-merge
25
+ // test runs otherwise stay with /verify-delivery)
26
+ //
27
+ // Last line of stdout is machine-readable for run-milestone:
28
+ // DELIVER-SUMMARY-JSON: {"id","branch","merged","issueClosed","dodPassed","checks":{...},"notes"}
29
+ // Exit codes: 0 = definitive summary printed (flags may still be false);
30
+ // 1 = bad invocation or unexpected internal error.
31
+
32
+ import { execFileSync, spawnSync } from 'node:child_process'
33
+ import { existsSync } from 'node:fs'
34
+ import { join } from 'node:path'
35
+
36
+ const argv = process.argv.slice(2)
37
+ const opt = (name) => {
38
+ const i = argv.indexOf('--' + name)
39
+ if (i === -1) return ''
40
+ const v = argv[i + 1]
41
+ return v && !v.startsWith('--') ? v : ''
42
+ }
43
+
44
+ const ID = opt('id')
45
+ const BRANCH = opt('branch')
46
+ const DEFAULT_BRANCH = opt('default-branch') || 'main'
47
+ const ISSUE_ARG = opt('issue')
48
+ const PLATFORM = opt('platform') || 'gh'
49
+ const TEST_CMD = opt('test-cmd')
50
+
51
+ if (!ID || !BRANCH) {
52
+ console.error('usage: node deliver-ticket.mjs --id <ticket-id> --branch <branch> [--default-branch main] [--issue <n>] [--platform gh|glab] [--test-cmd "<command>"]')
53
+ process.exit(1)
54
+ }
55
+ if (!/^[A-Za-z0-9._-]+$/.test(ID)) {
56
+ console.error(`invalid --id (allowed: letters, digits, . _ -): ${ID}`)
57
+ process.exit(1)
58
+ }
59
+ if (!/^[A-Za-z0-9/._-]+$/.test(BRANCH) || !/^[A-Za-z0-9/._-]+$/.test(DEFAULT_BRANCH)) {
60
+ console.error('invalid --branch / --default-branch (allowed: letters, digits, / . _ -)')
61
+ process.exit(1)
62
+ }
63
+ if (BRANCH === DEFAULT_BRANCH) {
64
+ console.error(`--branch must differ from --default-branch (got ${BRANCH} for both) — nothing to deliver`)
65
+ process.exit(1)
66
+ }
67
+ if (PLATFORM !== 'gh' && PLATFORM !== 'glab') {
68
+ console.error(`unknown platform: ${PLATFORM} (expected gh or glab)`)
69
+ process.exit(1)
70
+ }
71
+
72
+ const run = (bin, args, opts = {}) => execFileSync(bin, args, { encoding: 'utf8', ...opts })
73
+ const git = (args, opts = {}) => run('git', args, opts)
74
+ const errText = (e) => String((e && (e.stderr || e.stdout || e.message)) || e).trim()
75
+ const firstLine = (s) => String(s).trim().split('\n')[0]
76
+ const lastLine = (s) => String(s).trim().split('\n').filter(Boolean).pop() || ''
77
+ const tryGit = (args) => {
78
+ try { return { ok: true, out: git(args, { stdio: ['ignore', 'pipe', 'pipe'] }) } } catch (e) { return { ok: false, out: errText(e) } }
79
+ }
80
+
81
+ // GH_BIN / GLAB_BIN env overrides (same mechanism as publish-tickets.mjs) for
82
+ // non-PATH binaries and test doubles, e.g. GH_BIN="node tools/fake-gh.mjs".
83
+ const cli = (args, opts = {}) => {
84
+ const raw = PLATFORM === 'gh' ? process.env.GH_BIN || 'gh' : process.env.GLAB_BIN || 'glab'
85
+ const parts = raw.split(' ')
86
+ return run(parts[0], [...parts.slice(1), ...args], opts)
87
+ }
88
+
89
+ const checks = { planExists: false, alreadyMerged: false, merged: false, pushRequired: false, pushed: false, issueClosed: false, testsPassed: null }
90
+ const notes = []
91
+ const note = (line) => { notes.push(line); console.log(' (note) ' + line) }
92
+
93
+ const finish = (code) => {
94
+ const dodPassed =
95
+ checks.planExists &&
96
+ checks.merged &&
97
+ checks.issueClosed &&
98
+ (!checks.pushRequired || checks.pushed) &&
99
+ (TEST_CMD ? checks.testsPassed === true : true)
100
+ const summary = { id: ID, branch: BRANCH, merged: checks.merged, issueClosed: checks.issueClosed, dodPassed, checks, notes: notes.join('; ') }
101
+ console.log('DELIVER-SUMMARY-JSON: ' + JSON.stringify(summary))
102
+ process.exit(code)
103
+ }
104
+
105
+ try {
106
+ // 0. operate from the repo root regardless of cwd (plan path + command shape)
107
+ process.chdir(git(['rev-parse', '--show-toplevel']).trim())
108
+
109
+ // 1. clean tree — merging over uncommitted work is never sanctioned
110
+ if (git(['status', '--porcelain']).trim()) {
111
+ note('working tree not clean — refusing to merge')
112
+ finish(0)
113
+ }
114
+
115
+ // 2. refs must exist
116
+ for (const ref of [BRANCH, DEFAULT_BRANCH]) {
117
+ if (!tryGit(['rev-parse', '--verify', '--quiet', ref]).ok) {
118
+ note(`ref not found: ${ref}`)
119
+ finish(0)
120
+ }
121
+ }
122
+
123
+ // 3. merge --no-ff into the default branch (idempotent on re-runs)
124
+ git(['checkout', DEFAULT_BRANCH], { stdio: ['ignore', 'pipe', 'pipe'] })
125
+ if (tryGit(['merge-base', '--is-ancestor', BRANCH, 'HEAD']).ok) {
126
+ checks.alreadyMerged = true
127
+ checks.merged = true
128
+ console.log(`= merged ${BRANCH} is already contained in ${DEFAULT_BRANCH}`)
129
+ } else {
130
+ const m = tryGit(['merge', '--no-ff', '--no-edit', '-m', `merge: [${ID}] ${BRANCH} -> ${DEFAULT_BRANCH} (pipeline CLEAR)`, BRANCH])
131
+ if (m.ok) {
132
+ checks.merged = true
133
+ console.log(`+ merged ${BRANCH} -> ${DEFAULT_BRANCH} (--no-ff)`)
134
+ } else {
135
+ tryGit(['merge', '--abort'])
136
+ note(`merge failed (aborted, tree left clean): ${firstLine(m.out)}`)
137
+ }
138
+ }
139
+
140
+ // 4. push (only meaningful when an origin remote exists)
141
+ checks.pushRequired = tryGit(['remote', 'get-url', 'origin']).ok
142
+ if (checks.merged && checks.pushRequired) {
143
+ const p = tryGit(['push', 'origin', DEFAULT_BRANCH])
144
+ if (p.ok) {
145
+ checks.pushed = true
146
+ console.log(`+ pushed ${DEFAULT_BRANCH} -> origin`)
147
+ } else {
148
+ note(`push failed: ${lastLine(p.out)}`)
149
+ }
150
+ }
151
+
152
+ // 5. close the tracker issue and verify the transition (never assume auto-close).
153
+ // ONLY after the work actually landed: a closed issue is what resume filtering
154
+ // treats as "delivered by an earlier run", so closing on a failed merge/push
155
+ // would silently drop the ticket from every future run.
156
+ const landed = checks.merged && (!checks.pushRequired || checks.pushed)
157
+ let issueNum = ISSUE_ARG ? Number(ISSUE_ARG) : null
158
+ if (issueNum !== null && (!Number.isInteger(issueNum) || issueNum < 1)) {
159
+ note(`invalid --issue value: ${ISSUE_ARG}`)
160
+ issueNum = null
161
+ }
162
+ if (!landed) {
163
+ note('skipping tracker close — merge/push did not complete, ticket is NOT delivered')
164
+ } else {
165
+ if (!issueNum) {
166
+ // fall back to the "[<id>]" title-prefix convention (publish-tickets.mjs key)
167
+ try {
168
+ if (PLATFORM === 'gh') {
169
+ const list = JSON.parse(cli(['issue', 'list', '--state', 'all', '--limit', '1000', '--json', 'number,title']))
170
+ const hit = list.find((i) => String(i.title).startsWith(`[${ID}]`))
171
+ if (hit) issueNum = hit.number
172
+ } else {
173
+ const text = cli(['issue', 'list', '--all'])
174
+ const line = text.split('\n').find((l) => l.includes(`[${ID}]`))
175
+ const m = line && line.match(/#(\d+)\b/)
176
+ if (m) issueNum = Number(m[1])
177
+ }
178
+ } catch (e) {
179
+ note(`issue lookup failed: ${firstLine(errText(e))}`)
180
+ }
181
+ }
182
+ if (!issueNum) {
183
+ note(`no tracker issue found for [${ID}]`)
184
+ } else {
185
+ try {
186
+ cli(['issue', 'close', String(issueNum), ...(PLATFORM === 'gh' ? ['--comment', `Delivered: ${BRANCH} merged to ${DEFAULT_BRANCH} (run-milestone, CLEAR verdict).`] : [])])
187
+ } catch (e) {
188
+ note(`issue close command failed: ${firstLine(errText(e))}`) // verification below still decides
189
+ }
190
+ try {
191
+ if (PLATFORM === 'gh') {
192
+ const view = JSON.parse(cli(['issue', 'view', String(issueNum), '--json', 'state']))
193
+ checks.issueClosed = String(view.state).toUpperCase() === 'CLOSED'
194
+ } else {
195
+ // text scrape (older glab has no JSON): only trust a "closed" in the header lines
196
+ checks.issueClosed = cli(['issue', 'view', String(issueNum)]).split('\n').slice(0, 5).some((l) => /\bclosed\b/i.test(l))
197
+ }
198
+ console.log((checks.issueClosed ? '+ closed ' : ' (note) NOT closed: ') + `issue #${issueNum}`)
199
+ if (!checks.issueClosed) notes.push(`issue #${issueNum} still open after close attempt`)
200
+ } catch (e) {
201
+ note(`issue state verification failed: ${firstLine(errText(e))}`)
202
+ }
203
+ }
204
+ }
205
+
206
+ // 6. deterministic DoD inputs
207
+ checks.planExists = existsSync(join('docs', 'plans', `${ID}.md`))
208
+ if (!checks.planExists) note(`plan file missing: docs/plans/${ID}.md`)
209
+ if (TEST_CMD) {
210
+ const t = spawnSync(TEST_CMD, { shell: true, encoding: 'utf8' })
211
+ checks.testsPassed = t.status === 0
212
+ if (!checks.testsPassed) note(`--test-cmd failed (exit ${t.status}): ${String(t.stdout || t.stderr || '').trim().split('\n').slice(-3).join(' | ')}`)
213
+ }
214
+
215
+ finish(0)
216
+ } catch (e) {
217
+ note(`unexpected error: ${firstLine(errText(e))}`)
218
+ finish(1)
219
+ }
@@ -1,4 +1,11 @@
1
1
  {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(node .claude/scripts/milestone-dag.mjs:*)",
5
+ "Bash(node .claude/scripts/publish-tickets.mjs:*)",
6
+ "Bash(node .claude/scripts/deliver-ticket.mjs:*)"
7
+ ]
8
+ },
2
9
  "hooks": {
3
10
  "PreToolUse": [
4
11
  {
@@ -13,7 +13,9 @@ export const meta = {
13
13
  // defaultBranch: 'main', // optional, default 'main'
14
14
  // maxBounces: 2, // optional, default 2
15
15
  // continueOnFailure: false, // optional; default fail-fast (tickets may depend on earlier ones)
16
- // platform: 'gh' | 'glab' // tracker CLI for the deliver step, default 'gh'
16
+ // platform: 'gh' | 'glab', // tracker CLI for the deliver step, default 'gh'
17
+ // testCmd: 'npm test' // optional; forwarded to deliver-ticket.mjs --test-cmd so the
18
+ // // deterministic DoD re-runs tests on the merged default branch
17
19
  // }
18
20
  //
19
21
  // Guarantees encoded below (each one exists because prose alone failed before):
@@ -36,10 +38,17 @@ for (const t of cfg.tickets) {
36
38
  if (!t || typeof t.id !== 'string' || !t.id || typeof t.path !== 'string' || !t.path) {
37
39
  throw new Error('every ticket needs a non-empty string id and path; got: ' + JSON.stringify(t))
38
40
  }
41
+ // the id is composed into branch names and the deliver command — keep it boring
42
+ if (!/^[A-Za-z0-9._-]+$/.test(t.id)) {
43
+ throw new Error('ticket id must match [A-Za-z0-9._-]+; got: ' + t.id)
44
+ }
39
45
  }
40
46
  if (cfg.mode !== 'supervised' && cfg.mode !== 'autonomous') {
41
47
  throw new Error("args.mode must be 'supervised' or 'autonomous'")
42
48
  }
49
+ if (cfg.testCmd !== undefined && (typeof cfg.testCmd !== 'string' || !cfg.testCmd || cfg.testCmd.includes('"'))) {
50
+ throw new Error('args.testCmd must be a non-empty string without double quotes when provided')
51
+ }
43
52
  if (!Number.isInteger(cfg.maxBounces) || cfg.maxBounces < 0) {
44
53
  throw new Error('args.maxBounces must be an integer >= 0')
45
54
  }
@@ -194,15 +203,21 @@ for (const t of cfg.tickets) {
194
203
  continue
195
204
  }
196
205
 
197
- log('[' + t.id + '] deliver: merge + close issue + DoD')
206
+ log('[' + t.id + '] deliver: merge + close issue + DoD (deterministic script)')
207
+ // Delivery is a deterministic script, not agent judgment (catalog issue #26):
208
+ // harness safety classifiers blocked agent-run merges even after a journaled
209
+ // CLEAR. The agent below only executes the sanctioned command and relays its
210
+ // machine-readable summary — same discipline as publish-tickets.mjs for issues.
211
+ const deliverCmd = 'node .claude/scripts/deliver-ticket.mjs --id ' + t.id + ' --branch ' + branch +
212
+ ' --default-branch ' + cfg.defaultBranch + ' --platform ' + cfg.platform + (t.issue ? ' --issue ' + t.issue : '') +
213
+ (cfg.testCmd ? ' --test-cmd "' + cfg.testCmd + '"' : '')
198
214
  const delivery = await agent(
199
215
  'Delivery step (autonomous mode — pre-authorized by the human Gate 1 start signal). ' +
200
- 'Merge branch ' + branch + ' into ' + cfg.defaultBranch + ' with --no-ff and push. ' +
201
- 'Close tracker issue ' + (t.issue ? '#' + t.issue : 'for ticket ' + t.id + ' (find it by its "[' + t.id + ']" title prefix)') +
202
- ' via ' + cfg.platform + ' and verify it is ACTUALLY closed afterwards. ' +
203
- 'Then run the Definition-of-Done checks from .claude/commands/verify-delivery.md for ticket ' + t.id +
204
- ' (plan exists; tests green on the merged ' + cfg.defaultBranch + ' — run them yourself; CLEAR verdict recorded; merged to ' + cfg.defaultBranch + '; issue closed; writeback done). ' +
205
- 'Never report an item you did not check. Return merged, issueClosed, dodPassed, notes.',
216
+ 'Delivery is DETERMINISTIC: from the repo root, run EXACTLY this command and let it do all git and tracker work: ' +
217
+ deliverCmd + ' the script is the only sanctioned delivery path; do not merge, push, close issues, or retry pieces yourself. ' +
218
+ 'Parse the DELIVER-SUMMARY-JSON line it prints last and return merged, issueClosed, dodPassed EXACTLY as reported there, ' +
219
+ 'with notes = its notes field plus anything unusual you observed. ' +
220
+ 'If the command cannot run or prints no DELIVER-SUMMARY-JSON, return all three as false with the output tail in notes.',
206
221
  { label: 'deliver:' + t.id, phase: P, schema: DELIVERY }
207
222
  )
208
223
  // Delivered requires ALL THREE flags — a hallucinated dodPassed alone must not count.
@@ -13,7 +13,8 @@ export const meta = {
13
13
  // // so an [] tickets list means "module already complete" (resume semantics)
14
14
  // mode: 'supervised' | 'autonomous',
15
15
  // defaultBranch: 'main', // optional
16
- // platform: 'gh' | 'glab' // optional, default 'gh'
16
+ // platform: 'gh' | 'glab', // optional, default 'gh'
17
+ // testCmd: 'npm test' // optional; passed through to run-milestone (deliver DoD test run)
17
18
  // }
18
19
  //
19
20
  // Failure policy (maintainer decisions, catalog issue #20, 2026-07-18):
@@ -38,6 +39,9 @@ if (cfg.mode !== 'supervised' && cfg.mode !== 'autonomous') {
38
39
  throw new Error("args.mode must be 'supervised' or 'autonomous'")
39
40
  }
40
41
  if (cfg.platform !== 'gh' && cfg.platform !== 'glab') throw new Error("args.platform must be 'gh' or 'glab'")
42
+ if (cfg.testCmd !== undefined && (typeof cfg.testCmd !== 'string' || !cfg.testCmd || cfg.testCmd.includes('"'))) {
43
+ throw new Error('args.testCmd must be a non-empty string without double quotes when provided')
44
+ }
41
45
 
42
46
  const state = {} // name -> 'completed' | 'failed' | 'skipped' | 'paused'
43
47
  const results = []
@@ -75,6 +79,7 @@ for (const m of cfg.modules) {
75
79
  mode: cfg.mode,
76
80
  defaultBranch: cfg.defaultBranch,
77
81
  platform: cfg.platform,
82
+ ...(cfg.testCmd ? { testCmd: cfg.testCmd } : {}),
78
83
  })
79
84
  } catch (e) {
80
85
  err = e && e.message ? e.message : String(e)
@@ -8,10 +8,10 @@ From a checkout of the catalog: `node scripts/adopt.mjs three-agent-architect-bu
8
8
 
9
9
  ## Steps
10
10
 
11
- 1. Copy `.claude/` from this scaffold into the target repo root. If the target already has `.claude/settings.json`, merge the `hooks.PreToolUse` entry instead of overwriting.
11
+ 1. Copy `.claude/` from this scaffold into the target repo root. If the target already has `.claude/settings.json`, merge the `hooks.PreToolUse` entry and the `permissions.allow` list instead of overwriting.
12
12
  2. Install the catalog's **universal templates** (shared by all patterns — source of truth is the catalog root, not this scaffold): `templates/ticket.template.md` → the target repo's `templates/`; the platform half of `templates/tracker/` → `.github/` (ISSUE_TEMPLATE/ + PULL_REQUEST_TEMPLATE.md) or `.gitlab/` (issue_templates/ + merge_request_templates/). Then fill the PR/MR template's **Constraint check** section with the target repo's CLAUDE.md non-negotiables. Hand-written issues and pipeline PRs now share one format that triage can convert and reviewers can verify.
13
13
  3. The write-guard hook needs Node.js ≥ 18 on PATH. It denies main-session Edit/Write with a dispatch instruction; subagent writes pass. Override switch for human-approved out-of-pipeline edits: create `.claude/allow-main-writes`, delete it afterwards — and add that path to `.gitignore`.
14
- 4. The tracker steps (`publish-tickets.mjs`, the deliver stage, `/verify-delivery`, the nightly sweep) need the platform CLI installed and authenticated: `gh` (GitHub) or `glab` (GitLab). The publish script autodetects the platform from the origin remote; override with `--platform gh|glab` (test doubles / non-PATH binaries: `GH_BIN` / `GLAB_BIN` env overrides).
14
+ 4. The tracker steps (`publish-tickets.mjs`, `deliver-ticket.mjs`, `/verify-delivery`, the nightly sweep) need the platform CLI installed and authenticated: `gh` (GitHub) or `glab` (GitLab). The publish script autodetects the platform from the origin remote; override with `--platform gh|glab` (test doubles / non-PATH binaries: `GH_BIN` / `GLAB_BIN` env overrides). Delivery (merge `--no-ff` + push + verified issue close + deterministic DoD) is `deliver-ticket.mjs` — never an agent improvising git/tracker writes; `settings.json` carries explicit allow rules for the three deterministic scripts so unattended runs do not stall waiting for interactive approval (catalog issue #26).
15
15
  5. Append the content of `claude-md-snippet.md` to the target repo's `CLAUDE.md`, and set the **Operating mode** line (`supervised` for a fresh adoption; `autonomous` is the target).
16
16
  6. Ensure the docs layout the pipeline assumes exists: `docs/PRD.md`, `docs/prd/<module>/README.md` (the sub-PRD — `/start-milestone` hard-requires it), `docs/prd/<module>/tickets/` (author tickets from `templates/ticket.template.md`), `docs/adr/`, and an empty `docs/plans/`.
17
17
  7. Check the pattern entry's expiry (README metadata table). If expired, re-verify the model/effort table against current official docs before adopting — do not copy an expired recommendation into a new project.