mandrel 2.70.0 → 2.71.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.
Files changed (64) hide show
  1. package/.agents/README.md +8 -9
  2. package/.agents/agents/acceptance-critic.md +1 -0
  3. package/.agents/agents/auditor.md +1 -0
  4. package/.agents/agents/plan-critic.md +1 -0
  5. package/.agents/agents/story-worker.md +63 -64
  6. package/.agents/docs/agentrc-reference.json +2 -1
  7. package/.agents/docs/configuration.md +7 -8
  8. package/.agents/rules/git-conventions-reference.md +2 -2
  9. package/.agents/schemas/agentrc.schema.json +19 -2
  10. package/.agents/scripts/acceptance-eval.js +194 -15
  11. package/.agents/scripts/deliver-run.js +92 -43
  12. package/.agents/scripts/lib/audit-suite/index.js +1 -1
  13. package/.agents/scripts/lib/audit-suite/story-checklist.js +65 -0
  14. package/.agents/scripts/lib/audit-to-stories/audit-label-taxonomy.js +2 -2
  15. package/.agents/scripts/lib/bootstrap/issue-forms-template.js +1 -1
  16. package/.agents/scripts/lib/cli-args.js +22 -0
  17. package/.agents/scripts/lib/close-validation/gates.js +17 -3
  18. package/.agents/scripts/lib/config/agent-models.js +117 -0
  19. package/.agents/scripts/lib/config-settings-schema-delivery.js +13 -1
  20. package/.agents/scripts/lib/config-settings-schema-quality.js +1 -1
  21. package/.agents/scripts/lib/generated/agentrc-validator.js +1 -1
  22. package/.agents/scripts/lib/git/sync-from-base.js +89 -17
  23. package/.agents/scripts/lib/label-taxonomy.js +13 -3
  24. package/.agents/scripts/lib/notifications/notifier.js +11 -15
  25. package/.agents/scripts/lib/observability/close-telemetry.js +19 -3
  26. package/.agents/scripts/lib/observability/source-classifier.js +1 -0
  27. package/.agents/scripts/lib/orchestration/code-review.js +2 -2
  28. package/.agents/scripts/lib/orchestration/file-assumptions.js +45 -11
  29. package/.agents/scripts/lib/orchestration/plan-context.js +17 -10
  30. package/.agents/scripts/lib/orchestration/plan-persist/changes-repair.js +130 -24
  31. package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +19 -16
  32. package/.agents/scripts/lib/orchestration/plan-persist/story-ops.js +1 -0
  33. package/.agents/scripts/lib/orchestration/plan-persist/summary.js +4 -3
  34. package/.agents/scripts/lib/orchestration/resolve-stories.js +10 -2
  35. package/.agents/scripts/lib/orchestration/review-providers/native.js +5 -165
  36. package/.agents/scripts/lib/orchestration/single-story-close/failed-terminal.js +14 -2
  37. package/.agents/scripts/lib/orchestration/single-story-close/phases/base-sync.js +151 -56
  38. package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +4 -0
  39. package/.agents/scripts/lib/orchestration/single-story-close/phases/options.js +20 -4
  40. package/.agents/scripts/lib/orchestration/single-story-close/runner.js +26 -17
  41. package/.agents/scripts/lib/orchestration/story-handoff.js +849 -0
  42. package/.agents/scripts/lib/orchestration/story-init-result.js +83 -0
  43. package/.agents/scripts/lib/orchestration/task-body-validator.js +35 -5
  44. package/.agents/scripts/lib/orchestration/ticket-validator-sizing.js +1 -1
  45. package/.agents/scripts/lib/orchestration/ticket-validator.js +20 -2
  46. package/.agents/scripts/lib/single-story/confirm-merge.js +44 -7
  47. package/.agents/scripts/lib/story-body/story-body.js +40 -5
  48. package/.agents/scripts/lib/templates/decomposer-prompts.js +33 -36
  49. package/.agents/scripts/single-story-close.js +8 -0
  50. package/.agents/scripts/single-story-init.js +17 -32
  51. package/.agents/scripts/story-handoff.js +112 -0
  52. package/.agents/scripts/sync-claude-agents.js +58 -27
  53. package/.agents/workflows/helpers/acceptance-self-eval.md +24 -18
  54. package/.agents/workflows/helpers/code-review.md +3 -3
  55. package/.agents/workflows/helpers/deliver-digest.md +79 -80
  56. package/.agents/workflows/helpers/deliver-light.md +9 -7
  57. package/.agents/workflows/helpers/deliver-reference.md +38 -22
  58. package/.agents/workflows/helpers/deliver-story-reference.md +11 -9
  59. package/.agents/workflows/helpers/deliver-story.md +30 -23
  60. package/.agents/workflows/helpers/plan-reference.md +24 -9
  61. package/docs/CHANGELOG.md +19 -0
  62. package/lib/cli/registry.js +7 -0
  63. package/package.json +4 -3
  64. package/.agents/scripts/lib/orchestration/review-providers/scoped-lint.js +0 -272
@@ -18,7 +18,7 @@
18
18
  * @see .agents/schemas/acceptance-eval-verdict.schema.json
19
19
  */
20
20
 
21
- import { readFileSync } from 'node:fs';
21
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
22
22
  import path from 'node:path';
23
23
  import { fileURLToPath } from 'node:url';
24
24
  import { parseArgs } from 'node:util';
@@ -26,8 +26,12 @@ import { parseArgs } from 'node:util';
26
26
  import Ajv2020 from 'ajv/dist/2020.js';
27
27
  import addFormats from 'ajv-formats';
28
28
 
29
+ import { deriveCeremony } from './ceremony-derive.js';
29
30
  import { runAsCli } from './lib/cli-utils.js';
31
+ import { getDeliveryRouting } from './lib/config/delivery-routing.js';
32
+ import { resolvedTempRoot } from './lib/config/temp-paths.js';
30
33
  import { getAcceptanceEval, resolveConfig } from './lib/config-resolver.js';
34
+ import { gitSpawn } from './lib/git-utils.js';
31
35
  import { Logger } from './lib/Logger.js';
32
36
  import { appendSignal } from './lib/observability/signals-writer.js';
33
37
  import {
@@ -101,12 +105,16 @@ function parseCliArgs(argv) {
101
105
  verdict: { type: 'string' },
102
106
  'expected-criteria': { type: 'string' },
103
107
  'no-signal': { type: 'boolean', default: false },
108
+ init: { type: 'boolean', default: false },
109
+ cwd: { type: 'string' },
104
110
  },
105
111
  strict: false,
106
112
  });
107
113
  const storyId = Number.parseInt(values.story ?? '', 10);
108
114
  return {
109
115
  storyId: Number.isInteger(storyId) && storyId > 0 ? storyId : null,
116
+ init: values.init === true,
117
+ cwd: values.cwd ?? null,
110
118
  verdictPath: values.verdict ?? null,
111
119
  expectedCriteria: values['expected-criteria'] ?? null,
112
120
  emitSignal: values['no-signal'] !== true,
@@ -119,14 +127,13 @@ const MERGE_CONTRACT =
119
127
  'before scoring.';
120
128
 
121
129
  /**
122
- * The Story body's `acceptance[]` count; any failure yields `null`, never a
123
- * manufactured count.
130
+ * The Story body's `acceptance[]` items, in order; any failure yields `null`.
124
131
  *
125
132
  * @param {{ storyId: number, config: object }} args
126
133
  * @param {{ createProviderFn?: typeof createProvider, parseBodyFn?: typeof parseStoryBody }} [deps]
127
- * @returns {Promise<number|null>}
134
+ * @returns {Promise<string[]|null>}
128
135
  */
129
- export async function readStoryAcceptanceCount(
136
+ export async function readStoryAcceptance(
130
137
  { storyId, config },
131
138
  { createProviderFn = createProvider, parseBodyFn = parseStoryBody } = {},
132
139
  ) {
@@ -136,13 +143,155 @@ export async function readStoryAcceptanceCount(
136
143
  if (body === null) return null;
137
144
  const acceptance = parseBodyFn(body)?.body?.acceptance;
138
145
  return Array.isArray(acceptance) && acceptance.length > 0
139
- ? acceptance.length
146
+ ? acceptance
140
147
  : null;
141
148
  } catch {
142
149
  return null;
143
150
  }
144
151
  }
145
152
 
153
+ /**
154
+ * The Story body's `acceptance[]` count; any failure yields `null`, never a
155
+ * manufactured count.
156
+ *
157
+ * @param {{ storyId: number, config: object }} args
158
+ * @param {Parameters<typeof readStoryAcceptance>[1]} [deps]
159
+ * @returns {Promise<number|null>}
160
+ */
161
+ export async function readStoryAcceptanceCount(args, deps) {
162
+ const acceptance = await readStoryAcceptance(args, deps);
163
+ return acceptance ? acceptance.length : null;
164
+ }
165
+
166
+ /**
167
+ * The `--init` skeleton: one record per `acceptance[]` item, in order, with
168
+ * `index` and `criterion` filled and `verdict` / `evidence` left empty for
169
+ * the verdict owner. Deliberately schema-invalid until filled.
170
+ *
171
+ * @param {{ storyId: number, acceptance: string[], round: number, commitSha: string|null }} args
172
+ * @returns {object}
173
+ */
174
+ export function buildVerdictSkeleton({
175
+ storyId,
176
+ acceptance,
177
+ round,
178
+ commitSha,
179
+ }) {
180
+ return {
181
+ storyId,
182
+ schemaVersion: 1,
183
+ round,
184
+ commitSha,
185
+ criteria: acceptance.map((criterion, index) => ({
186
+ index,
187
+ criterion,
188
+ verdict: '',
189
+ evidence: '',
190
+ })),
191
+ };
192
+ }
193
+
194
+ /**
195
+ * Indices of records still carrying the skeleton's empty `verdict` or
196
+ * `evidence`.
197
+ *
198
+ * @param {unknown} verdict
199
+ * @returns {number[]}
200
+ */
201
+ export function findUnfilledCriteria(verdict) {
202
+ const criteria = Array.isArray(verdict?.criteria) ? verdict.criteria : [];
203
+ const blank = (v) => typeof v !== 'string' || v.trim().length === 0;
204
+ return criteria
205
+ .map((c, i) =>
206
+ blank(c?.verdict) || blank(c?.evidence) ? (c?.index ?? i) : null,
207
+ )
208
+ .filter((i) => i !== null);
209
+ }
210
+
211
+ /**
212
+ * Refuse a verdict with unfilled records before schema validation or
213
+ * scoring, so the mistake costs no round.
214
+ *
215
+ * @param {unknown} verdict
216
+ * @returns {void}
217
+ */
218
+ export function assertVerdictFilled(verdict) {
219
+ const unfilled = findUnfilledCriteria(verdict);
220
+ if (unfilled.length === 0) return;
221
+ throw new Error(
222
+ `acceptance-eval: verdict record(s) at index ${unfilled.join(', ')} are unfilled — ` +
223
+ 'every record needs a verdict (met|partial|unmet) and evidence before scoring. No round was consumed.',
224
+ );
225
+ }
226
+
227
+ /** @param {string} cwd @returns {string|null} */
228
+ function readHeadSha(cwd) {
229
+ const res = gitSpawn(cwd, 'rev-parse', 'HEAD');
230
+ const sha = res.status === 0 ? `${res.stdout ?? ''}`.trim() : '';
231
+ return /^[0-9a-f]{7,64}$/.test(sha) ? sha : null;
232
+ }
233
+
234
+ /**
235
+ * `--init`: derive the change set and verdict owner with ceremony-derive's
236
+ * own function, write the skeleton under `<tempRoot>/scratch/story-<id>/`,
237
+ * and return what the owner needs to fill it.
238
+ *
239
+ * @param {{ storyId: number, cwd: string, config: object }} input
240
+ * @param {{
241
+ * readAcceptanceImpl?: typeof readStoryAcceptance,
242
+ * deriveCeremonyImpl?: typeof deriveCeremony,
243
+ * resolveRoundImpl?: typeof resolveAcceptanceEvalRound,
244
+ * readHeadImpl?: typeof readHeadSha,
245
+ * writeFileImpl?: (file: string, text: string) => void,
246
+ * }} [deps]
247
+ * @returns {Promise<{ verdictPath: string, files: string[]|null, verdictOwner: string, round: number, criteria: number }>}
248
+ */
249
+ export async function initVerdictSkeleton({ storyId, cwd, config }, deps = {}) {
250
+ const {
251
+ readAcceptanceImpl = readStoryAcceptance,
252
+ deriveCeremonyImpl = deriveCeremony,
253
+ resolveRoundImpl = resolveAcceptanceEvalRound,
254
+ readHeadImpl = readHeadSha,
255
+ writeFileImpl = (file, text) => {
256
+ mkdirSync(path.dirname(file), { recursive: true });
257
+ writeFileSync(file, text, 'utf8');
258
+ },
259
+ } = deps;
260
+ const acceptance = await readAcceptanceImpl({ storyId, config });
261
+ if (!acceptance) {
262
+ throw new Error(
263
+ `acceptance-eval --init: Story #${storyId}'s acceptance[] could not be read — no skeleton written.`,
264
+ );
265
+ }
266
+ const ceremony = deriveCeremonyImpl({
267
+ storyId,
268
+ baseRef: config?.project?.baseBranch ?? 'main',
269
+ cwd,
270
+ ceremonyProfile: getDeliveryRouting(config).ceremonyProfile,
271
+ });
272
+ const { round } = resolveRoundImpl({ epicId: null, storyId, config });
273
+ const skeleton = buildVerdictSkeleton({
274
+ storyId,
275
+ acceptance,
276
+ round,
277
+ commitSha: readHeadImpl(cwd),
278
+ });
279
+ const verdictPath = path.join(
280
+ resolvedTempRoot(config),
281
+ 'scratch',
282
+ `story-${storyId}`,
283
+ `acceptance-verdict-round-${round}.json`,
284
+ );
285
+ writeFileImpl(verdictPath, `${JSON.stringify(skeleton, null, 2)}\n`);
286
+ return {
287
+ verdictPath,
288
+ files: ceremony.files,
289
+ verdictOwner: ceremony.verdictOwner,
290
+ round,
291
+ criteria: acceptance.length,
292
+ };
293
+ }
294
+
146
295
  /**
147
296
  * The derived count wins; a disagreeing flag is a wiring error and throws.
148
297
  *
@@ -354,6 +503,31 @@ export async function runAcceptanceEval(
354
503
  return { envelope, exitCode };
355
504
  }
356
505
 
506
+ /** @param {number|null} storyId */
507
+ function requireStoryId(storyId) {
508
+ if (storyId) return;
509
+ throw new Error(
510
+ 'Usage: node acceptance-eval.js --story <id> --verdict <path> [--expected-criteria <n>] [--no-signal]',
511
+ );
512
+ }
513
+
514
+ /**
515
+ * `--init`: write the skeleton and print its summary; scores nothing.
516
+ *
517
+ * @param {{ storyId: number, cwd: string|null, resolveConfigImpl: typeof resolveConfig, logger: { info: Function }, deps: { initSkeletonImpl?: typeof initVerdictSkeleton } }} args
518
+ * @returns {Promise<object>}
519
+ */
520
+ async function runInitCli({ storyId, cwd, resolveConfigImpl, logger, deps }) {
521
+ const workCwd = path.resolve(cwd ?? process.cwd());
522
+ const skeleton = await (deps.initSkeletonImpl ?? initVerdictSkeleton)({
523
+ storyId,
524
+ cwd: workCwd,
525
+ config: resolveConfigImpl({ cwd: workCwd }),
526
+ });
527
+ logger.info(JSON.stringify(skeleton));
528
+ return skeleton;
529
+ }
530
+
357
531
  /**
358
532
  * CLI core: argv → verdict → validation → coverage → decision → envelope.
359
533
  *
@@ -364,9 +538,10 @@ export async function runAcceptanceEval(
364
538
  * validateVerdictImpl?: typeof validateVerdict,
365
539
  * runAcceptanceEvalImpl?: typeof runAcceptanceEval,
366
540
  * readAcceptanceCountImpl?: typeof readStoryAcceptanceCount,
541
+ * initSkeletonImpl?: typeof initVerdictSkeleton,
367
542
  * logger?: { info: Function, warn?: Function },
368
543
  * }} [deps]
369
- * @returns {Promise<object>} the emitted envelope.
544
+ * @returns {Promise<object>} the emitted envelope (the skeleton summary under `--init`).
370
545
  */
371
546
  export async function runAcceptanceEvalCli(
372
547
  argv = process.argv.slice(2),
@@ -380,15 +555,13 @@ export async function runAcceptanceEvalCli(
380
555
  readAcceptanceCountImpl = readStoryAcceptanceCount,
381
556
  logger = Logger,
382
557
  } = deps;
383
- const { storyId, verdictPath, expectedCriteria, emitSignal } =
558
+ const { storyId, init, cwd, verdictPath, expectedCriteria, emitSignal } =
384
559
  parseCliArgs(argv);
385
560
  const flagged = resolveExpectedCriteria(expectedCriteria);
386
561
 
387
- if (!storyId) {
388
- throw new Error(
389
- 'Usage: node acceptance-eval.js --story <id> --verdict <path> [--expected-criteria <n>] [--no-signal]',
390
- );
391
- }
562
+ requireStoryId(storyId);
563
+ if (init)
564
+ return runInitCli({ storyId, cwd, resolveConfigImpl, logger, deps });
392
565
  if (!verdictPath) {
393
566
  throw new Error('acceptance-eval: --verdict <path> is required.');
394
567
  }
@@ -415,6 +588,7 @@ export async function runAcceptanceEvalCli(
415
588
  );
416
589
  }
417
590
 
591
+ assertVerdictFilled(parsed);
418
592
  const verdict = validateVerdictImpl(parsed);
419
593
 
420
594
  const config = resolveConfigImpl();
@@ -470,11 +644,16 @@ runAsCli(import.meta.url, main, {
470
644
  source: 'acceptance-eval',
471
645
  usage: {
472
646
  invocation:
473
- 'node .agents/scripts/acceptance-eval.js --story <id> --verdict <path> [--expected-criteria <n>] [--no-signal]',
647
+ 'node .agents/scripts/acceptance-eval.js --story <id> (--init [--cwd <workCwd>] | --verdict <path> [--expected-criteria <n>] [--no-signal])',
474
648
  summary:
475
- "Score an authored acceptance verdict against the Story's acceptance[] criteria and emit the bounded loop's proceed / redraft / block decision.",
649
+ "Score an authored acceptance verdict against the Story's acceptance[] criteria and emit the bounded loop's proceed / redraft / block decision; --init writes the verdict skeleton to fill first.",
476
650
  flags: [
477
651
  ['--story <id>', 'GitHub issue number of the Story (required).'],
652
+ [
653
+ '--init',
654
+ 'Write the verdict skeleton (one empty record per acceptance[] item, the next round, HEAD) under <tempRoot>/scratch/story-<id>/ and print its path, the derived change set `files` and the `verdictOwner`. Scoring a skeleton with an unfilled record is refused without consuming a round.',
655
+ ],
656
+ ['--cwd <workCwd>', 'Worktree the --init change set is derived in.'],
478
657
  ['--verdict <path>', 'Path to the authored verdict JSON (required).'],
479
658
  [
480
659
  '--expected-criteria <n>',
@@ -12,12 +12,12 @@ import { createHash } from 'node:crypto';
12
12
  import fs from 'node:fs';
13
13
  import path from 'node:path';
14
14
  import { parseArgs } from 'node:util';
15
- import { buildDispatchChecklist } from './lib/audit-suite/index.js';
15
+ import { buildStoryChecklist } from './lib/audit-suite/index.js';
16
16
  import { runAsCli } from './lib/cli-utils.js';
17
+ import { resolveStoryWorkerModel } from './lib/config/agent-models.js';
17
18
  import { getPaths, resolveConfig } from './lib/config-resolver.js';
18
19
  import { Logger } from './lib/Logger.js';
19
20
  import { ensureDocsDigest } from './lib/orchestration/docs-digest.js';
20
- import { parse as parseStoryBody } from './lib/story-body/story-body.js';
21
21
  import { expandIdList } from './lib/util/parse-id-list.js';
22
22
  import { runProbedStoriesWaveTick } from './stories-wave-tick.js';
23
23
 
@@ -122,20 +122,68 @@ function writeLedger(
122
122
  /**
123
123
  * `--merge-watch-mode async` is a run-topology call close cannot make: with
124
124
  * siblings, sync closes serialize every merge wait; alone, sync lands fastest.
125
- * @param {{ storyId: number, mainRepo: string, storyCount: number }} args
125
+ * `--worker-model` rides only a multi-Story close — a one-Story run is inline.
126
+ * @param {{ storyId: number, mainRepo: string, storyCount: number,
127
+ * workerModel?: string|null }} args
126
128
  * @returns {string}
127
129
  */
128
- export function renderCloseCommand({ storyId, mainRepo, storyCount }) {
130
+ export function renderCloseCommand({
131
+ storyId,
132
+ mainRepo,
133
+ storyCount,
134
+ workerModel,
135
+ }) {
129
136
  const parts = [
130
137
  'node',
131
138
  path.join(mainRepo, '.agents', 'scripts', 'single-story-close.js'),
132
139
  `--story ${storyId}`,
133
140
  `--cwd ${mainRepo}`,
134
141
  ];
135
- if (storyCount > 1) parts.push('--merge-watch-mode async');
142
+ if (storyCount > 1) parts.push(...multiStoryCloseFlags(workerModel));
136
143
  return parts.join(' ');
137
144
  }
138
145
 
146
+ /**
147
+ * @param {string|null|undefined} workerModel
148
+ * @returns {string[]}
149
+ */
150
+ function multiStoryCloseFlags(workerModel) {
151
+ const flags = ['--merge-watch-mode async'];
152
+ if (workerModel) flags.push(`--worker-model ${workerModel}`);
153
+ return flags;
154
+ }
155
+
156
+ /** The planner handoff sections the dispatch prompt embeds verbatim. */
157
+ const EMBEDDED_SECTIONS = Object.freeze(['Context', 'References']);
158
+
159
+ /**
160
+ * Each of the Story body's `## Context` / `## References` sections, verbatim
161
+ * (heading included, trailing blank lines trimmed), in that order; an absent
162
+ * or empty section is omitted.
163
+ *
164
+ * @param {string} body
165
+ * @returns {string[]}
166
+ */
167
+ export function extractBodySections(body) {
168
+ const lines = `${body ?? ''}`.split(/\r?\n/);
169
+ return EMBEDDED_SECTIONS.map((heading) => {
170
+ const start = lines.findIndex((l) => l.trim() === `## ${heading}`);
171
+ if (start === -1) return null;
172
+ const rest = lines.slice(start + 1);
173
+ const end = rest.findIndex((l) => /^##\s/.test(l));
174
+ const content = (end === -1 ? rest : rest.slice(0, end)).join('\n').trim();
175
+ return content.length > 0 ? `## ${heading}\n\n${content}` : null;
176
+ }).filter(Boolean);
177
+ }
178
+
179
+ /**
180
+ * @param {string[]} [sections]
181
+ * @returns {string[]} each section followed by a blank line.
182
+ */
183
+ function embeddedSectionLines(sections = []) {
184
+ return sections.flatMap((section) => [section, '']);
185
+ }
186
+
139
187
  /**
140
188
  * The whole spawn payload for one ready Story.
141
189
  * @param {object} args
@@ -143,6 +191,7 @@ export function renderCloseCommand({ storyId, mainRepo, storyCount }) {
143
191
  * @param {string} args.mainRepo
144
192
  * @param {string|null} args.docsDigestPath
145
193
  * @param {string|null} args.checklistPath
194
+ * @param {string[]} [args.bodySections] - verbatim `## Context` / `## References`.
146
195
  * @returns {string}
147
196
  */
148
197
  export function renderDispatchPrompt({
@@ -150,26 +199,27 @@ export function renderDispatchPrompt({
150
199
  mainRepo,
151
200
  docsDigestPath,
152
201
  checklistPath,
202
+ bodySections,
153
203
  }) {
154
204
  const lines = [
155
205
  `# Deliver Story #${storyId}`,
156
206
  '',
157
207
  `Main checkout: \`${mainRepo}\`.`,
158
208
  '',
159
- `You own Steps 0 through 2.5 of \`.agents/workflows/helpers/deliver-story.md\`.`,
160
- 'The orchestrator owns Step 3 (close): do not open a PR, do not run',
161
- '`single-story-close.js`, and do not compose a terminal envelope.',
209
+ 'Your `story-worker` boot context carries every worker MUST. You own init',
210
+ 'through the pushed branch; the orchestrator owns close: do not open a PR,',
211
+ 'do not run `single-story-close.js`, and do not compose a terminal envelope.',
162
212
  '',
163
213
  '## Reads',
164
214
  '',
165
- '1. `.agents/workflows/helpers/deliver-digest.md` — once, first.',
166
- '2. `.agents/workflows/helpers/deliver-story.md` — the steps.',
167
- `3. The Story body (\`gh issue view ${storyId}\`) — its \`## Spec\`,`,
215
+ `1. The Story body (\`gh issue view ${storyId}\`) — its \`## Spec\`,`,
168
216
  ' `acceptance[]` and `verify[]` are the contract.',
217
+ '2. The write-time checklist below, when one matched.',
169
218
  '',
170
219
  `- Docs digest: ${docsDigestPath ? `\`${docsDigestPath}\`` : 'none (project.docsContextFiles is unset) — no mandatory docs read'}`,
171
220
  `- Write-time checklist: ${checklistPath ? `\`${checklistPath}\`` : 'none matched this footprint — the maker-blind close-scope pass still covers it'}`,
172
221
  '',
222
+ ...embeddedSectionLines(bodySections),
173
223
  '## Worktree',
174
224
  '',
175
225
  'Initialize from the main checkout, synchronously, at the maximum Bash',
@@ -184,23 +234,27 @@ export function renderDispatchPrompt({
184
234
  'scope those tools. `remoteVerified: false` → flip `agent::blocked` quoting',
185
235
  '`remoteProbe.detail` and stop.',
186
236
  '',
187
- '## Change-set discipline',
237
+ '## Tail',
188
238
  '',
189
- 'Derive the change set, the level and the ceremony with **one** call, and',
190
- 'hand that one list to the verdict owner — never let a critic re-run its',
191
- 'own `git diff`:',
239
+ 'Once the implementation is committed, write the verdict skeleton — it',
240
+ 'prints the one change set (`files`) and the `verdictOwner`; hand that list',
241
+ 'to the owner and never let a critic re-run its own `git diff` — then fill',
242
+ 'and score it:',
192
243
  '',
193
244
  '```bash',
194
- `node ${path.join(mainRepo, '.agents', 'scripts', 'ceremony-derive.js')} --story ${storyId} --cwd <workCwd>`,
245
+ `node ${path.join(mainRepo, '.agents', 'scripts', 'acceptance-eval.js')} --story ${storyId} --init --cwd <workCwd>`,
195
246
  '```',
196
247
  '',
197
- '## Hand-off',
248
+ 'On `proceed`, run the one handoff command. `fix-required` → fix, commit,',
249
+ 're-run it; `blocked` → it already flipped `agent::blocked`, exit non-zero:',
198
250
  '',
199
- 'Run the bounded acceptance self-eval (digest § 4), the one credited suite',
200
- 'run (digest § 5), then push `story-' + storyId + '` to `origin` and',
201
- 'confirm the remote ref moved. Return: Story id, `workCwd`, branch, pushed',
202
- 'head SHA, the self-eval verdict, and the `verify[]` evidence. Say the',
203
- 'branch is pushed and unclosed.',
251
+ '```bash',
252
+ `node ${path.join(mainRepo, '.agents', 'scripts', 'story-handoff.js')} --story ${storyId} --cwd <workCwd>`,
253
+ '```',
254
+ '',
255
+ 'Return its `ready` envelope (Story id, `workCwd`, branch, pushed head SHA,',
256
+ 'review tally) plus the self-eval verdict and the `verify[]` evidence. Say',
257
+ 'the branch is pushed and unclosed.',
204
258
  '',
205
259
  ];
206
260
  return lines.join('\n');
@@ -213,33 +267,21 @@ export function renderDispatchPrompt({
213
267
  * @param {string} args.runTempDir
214
268
  * @param {string} args.mainRepo
215
269
  * @param {string|null} args.docsDigestPath
270
+ * @param {object} [args.config]
216
271
  * @param {object} [deps]
217
272
  * @returns {{ id: number, promptPath: string }}
218
273
  */
219
274
  function buildDispatchEntry(
220
- { storyId, body, runTempDir, mainRepo, docsDigestPath },
221
- {
222
- buildChecklistFn = buildDispatchChecklist,
223
- writeFileFn = fs.writeFileSync,
224
- } = {},
275
+ { storyId, body, runTempDir, mainRepo, docsDigestPath, config },
276
+ { buildChecklistFn, writeFileFn = fs.writeFileSync } = {},
225
277
  ) {
226
- let changes = [];
227
- let references = [];
228
- try {
229
- // Path entries live on `.body`, not at the top level of the parse result.
230
- const { body: parsed } = parseStoryBody(body ?? '');
231
- changes = parsed?.changes ?? [];
232
- references = parsed?.references ?? [];
233
- } catch {
234
- // Costs the checklist, never the dispatch: the worker reads the body itself.
235
- changes = [];
236
- references = [];
237
- }
238
- const { checklistPath } = buildChecklistFn({
278
+ // The same Story-scoped path single-story-init returns in its envelope.
279
+ const { checklistPath } = buildStoryChecklist({
239
280
  storyId,
240
- changes,
241
- references,
242
- runTempDir,
281
+ body,
282
+ config,
283
+ // `undefined` falls through to the helper's own default builder.
284
+ buildChecklistFn,
243
285
  });
244
286
  const promptPath = path.join(runTempDir, `dispatch-${storyId}.md`);
245
287
  writeFileFn(
@@ -249,6 +291,7 @@ function buildDispatchEntry(
249
291
  mainRepo,
250
292
  docsDigestPath,
251
293
  checklistPath,
294
+ bodySections: extractBodySections(body),
252
295
  }),
253
296
  'utf8',
254
297
  );
@@ -418,6 +461,10 @@ export async function runDeliverRunBeat(
418
461
  : [];
419
462
 
420
463
  const readyIds = Array.isArray(tick.ready) ? tick.ready : [];
464
+ const workerModel = resolveStoryWorkerModel(
465
+ { config: resolved, mainRepo },
466
+ entryDeps,
467
+ );
421
468
  const digest = await ensureDocsDigestFn({
422
469
  docsContextFiles: resolved?.project?.docsContextFiles,
423
470
  docsRoot: getPaths(resolved).docsRoot,
@@ -436,6 +483,7 @@ export async function runDeliverRunBeat(
436
483
  runTempDir,
437
484
  mainRepo,
438
485
  docsDigestPath,
486
+ config: resolved,
439
487
  },
440
488
  entryDeps,
441
489
  ),
@@ -459,6 +507,7 @@ export async function runDeliverRunBeat(
459
507
  storyId,
460
508
  mainRepo,
461
509
  storyCount: ids.length,
510
+ workerModel,
462
511
  }),
463
512
  })),
464
513
  done: tick.epilogueDue === true,
@@ -6,7 +6,6 @@ export {
6
6
  matchLocalLenses,
7
7
  readAuditRules,
8
8
  } from './checklist-threading.js';
9
- export { buildDispatchChecklist } from './dispatch-checklist.js';
10
9
  export {
11
10
  LENS_TIERS,
12
11
  matchesAnyFilePattern,
@@ -14,3 +13,4 @@ export {
14
13
  resolveLensTier,
15
14
  selectAudits,
16
15
  } from './selector.js';
16
+ export { buildStoryChecklist } from './story-checklist.js';
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The one write-time checklist call both delivery paths make —
3
+ * `single-story-init.js` (every path, a one-Story inline run included) and
4
+ * `deliver-run.js` (the multi-Story dispatch prompt) — so both name the SAME
5
+ * Story-scoped path under `<tempRoot>/standalone/stories/story-<id>/`.
6
+ */
7
+
8
+ import { storyTempDir } from '../config/temp-paths.js';
9
+ import { parse as parseStoryBody } from '../story-body/story-body.js';
10
+ import { buildDispatchChecklist } from './dispatch-checklist.js';
11
+
12
+ /**
13
+ * `changes[]` + `references[]` off the Story body; an unparseable body is an
14
+ * empty footprint.
15
+ *
16
+ * @param {string} body
17
+ * @returns {{ changes: unknown[], references: unknown[] }}
18
+ */
19
+ function footprintOf(body) {
20
+ try {
21
+ // Path entries live on `.body`, not at the top level of the parse result.
22
+ const { body: parsed } = parseStoryBody(body ?? '');
23
+ return {
24
+ changes: parsed?.changes ?? [],
25
+ references: parsed?.references ?? [],
26
+ };
27
+ } catch {
28
+ return { changes: [], references: [] };
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Never throws: a builder failure costs the checklist (`checklistPath: null`),
34
+ * never the caller.
35
+ *
36
+ * @param {object} args
37
+ * @param {number} args.storyId
38
+ * @param {string} [args.body]
39
+ * @param {object} [args.config]
40
+ * @param {(tag: string, msg: string) => void} [args.progress]
41
+ * @param {typeof buildDispatchChecklist} [args.buildChecklistFn]
42
+ * @returns {{ checklistPath: string|null }}
43
+ */
44
+ export function buildStoryChecklist({
45
+ storyId,
46
+ body,
47
+ config,
48
+ progress = () => {},
49
+ buildChecklistFn = buildDispatchChecklist,
50
+ }) {
51
+ try {
52
+ const { checklistPath } = buildChecklistFn({
53
+ storyId,
54
+ ...footprintOf(body),
55
+ runTempDir: storyTempDir(null, storyId, config),
56
+ });
57
+ return { checklistPath: checklistPath ?? null };
58
+ } catch (err) {
59
+ progress(
60
+ 'CHECKLIST',
61
+ `⚠ write-time checklist skipped: ${err?.message ?? err}`,
62
+ );
63
+ return { checklistPath: null };
64
+ }
65
+ }
@@ -11,6 +11,7 @@ import {
11
11
  RISK_LABELS,
12
12
  TYPE_LABELS,
13
13
  } from '../label-constants.js';
14
+ import { labelDescription } from '../label-taxonomy.js';
14
15
  import { AUDIT_LENSES, auditLabelsForFindings } from './audit-lenses.js';
15
16
 
16
17
  /** A lens absent here falls back to {@link DEFAULT_LENS_META}. */
@@ -106,8 +107,7 @@ const AUDIT_STORY_AXIS_LABELS = Object.freeze([
106
107
  {
107
108
  name: AGENT_LABELS.READY,
108
109
  color: hex(LABEL_COLORS.AGENT),
109
- description:
110
- 'Parking state — frozen dispatch manifest exists; awaiting local /mandrel-deliver',
110
+ description: labelDescription(AGENT_LABELS.READY),
111
111
  },
112
112
  {
113
113
  name: RISK_LABELS.HIGH,
@@ -183,7 +183,7 @@ body:
183
183
  value: |
184
184
  Fill the fields below. They serialize to the canonical Story body
185
185
  the framework parses — keep each section's content under its own
186
- heading. Machine-managed sections (dispatch manifest, lifecycle
186
+ heading. Machine-managed sections (the plan summary, lifecycle
187
187
  transitions) are added by the runtime; you do not author them here.
188
188
  ${fieldBlocks}
189
189
  ${renderDependsOnBlock()}