@sabaiway/agent-workflow-kit 23.11.0 → 24.0.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 (159) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +4 -4
  3. package/SKILL.md +1 -1
  4. package/bridges/codex-cli-bridge/SKILL.md +7 -2
  5. package/bridges/codex-cli-bridge/bin/codex-exec-jev.test.mjs +11 -6
  6. package/bridges/codex-cli-bridge/bin/codex-exec.sh +72 -33
  7. package/bridges/codex-cli-bridge/bin/codex-exec.test.mjs +111 -3
  8. package/bridges/codex-cli-bridge/bin/codex-fixtures-harness.test.mjs +16 -1
  9. package/bridges/codex-cli-bridge/bin/codex-model-posture.test.mjs +5 -3
  10. package/bridges/codex-cli-bridge/bin/codex-review.sh +1 -1
  11. package/bridges/codex-cli-bridge/capability.json +2 -2
  12. package/capability.json +1 -1
  13. package/package.json +1 -1
  14. package/references/advisor-writers.md +2 -0
  15. package/references/agents/author.md +21 -0
  16. package/references/agents/executor.md +12 -6
  17. package/references/contracts.md +4 -4
  18. package/references/hooks/gate-approve.mjs +7 -8
  19. package/references/hooks/stage-write-guard.mjs +314 -0
  20. package/references/modes/agents.md +6 -4
  21. package/references/modes/bootstrap.md +1 -1
  22. package/references/modes/control-bytes.md +38 -32
  23. package/references/modes/flow-writer.md +10 -2
  24. package/references/modes/hook.md +4 -1
  25. package/references/modes/now.md +1 -1
  26. package/references/modes/procedures.md +49 -10
  27. package/references/modes/recipes.md +7 -7
  28. package/references/modes/recommendations.md +5 -4
  29. package/references/modes/robustness-brief.md +9 -8
  30. package/references/modes/set-recipe.md +1 -1
  31. package/references/modes/state-block-guard.md +4 -3
  32. package/references/modes/status.md +1 -1
  33. package/references/modes/upgrade.md +1 -1
  34. package/references/modes/worktrees.md +28 -5
  35. package/references/rules/story-sessions.md +2 -2
  36. package/references/scripts/archives/archive-caps.mjs +1 -1
  37. package/references/scripts/archives/archive-changelog.mjs +8 -8
  38. package/references/scripts/archives/archive-decisions.mjs +7 -7
  39. package/references/scripts/archives/archive-issues.mjs +5 -5
  40. package/references/scripts/archives/rotation-conservation.mjs +2 -1
  41. package/references/scripts/docs-size/check-docs-size.mjs +15 -15
  42. package/references/scripts/family.json +2 -0
  43. package/references/scripts/gates/kit-command-gates.mjs +7 -8
  44. package/references/scripts/gates/migrate-gates.mjs +10 -10
  45. package/references/scripts/git-hooks/install-git-hooks.mjs +13 -13
  46. package/references/scripts/run.mjs +1 -2
  47. package/references/scripts/shared/index.mjs +2 -0
  48. package/references/scripts/shared/locations.mjs +103 -0
  49. package/references/scripts/spec-schema/spec-schema.mjs +2 -1
  50. package/references/templates/orchestration.json +1 -1
  51. package/tools/ack-store.mjs +2 -1
  52. package/tools/advisor-matrix.mjs +2 -1
  53. package/tools/advisor-skip/index.mjs +73 -0
  54. package/tools/apply-danger-check.mjs +20 -6
  55. package/tools/atomic-write.mjs +3 -2
  56. package/tools/attribution.mjs +2 -1
  57. package/tools/autonomy-config.mjs +2 -1
  58. package/tools/bridge-wiring.mjs +13 -11
  59. package/tools/carriers.mjs +54 -14
  60. package/tools/cheap-agents-read.mjs +28 -7
  61. package/tools/cheap-agents.mjs +15 -10
  62. package/tools/checker-gates-read.mjs +6 -5
  63. package/tools/commands.mjs +2 -2
  64. package/tools/control-bytes.mjs +43 -20
  65. package/tools/coverage-declared/config.mjs +2 -1
  66. package/tools/coverage-producer.mjs +10 -9
  67. package/tools/delegation.mjs +7 -6
  68. package/tools/detect-backends.mjs +1 -1
  69. package/tools/dispatch-baseline.mjs +2 -1
  70. package/tools/distribution-files/scripts.mjs +4 -4
  71. package/tools/doc-parity/index.mjs +46 -0
  72. package/tools/doc-parity.mjs +27 -47
  73. package/tools/ensure-configs.mjs +2 -2
  74. package/tools/ensure-ops.mjs +24 -24
  75. package/tools/ensure-specs.mjs +7 -7
  76. package/tools/epic-shape-cli.mjs +2 -2
  77. package/tools/epic-shape-ledger.mjs +5 -5
  78. package/tools/epic-shape.mjs +5 -3
  79. package/tools/epic-store.mjs +2 -1
  80. package/tools/family-members.mjs +7 -5
  81. package/tools/family-registry.mjs +36 -30
  82. package/tools/feedback-record-cli.mjs +4 -5
  83. package/tools/flow-writer.mjs +26 -15
  84. package/tools/gate-hook.mjs +33 -28
  85. package/tools/gates-declaration.mjs +2 -1
  86. package/tools/gates-init.mjs +6 -5
  87. package/tools/git-hooks.mjs +64 -41
  88. package/tools/grounding.mjs +3 -2
  89. package/tools/hide-footprint.mjs +2 -1
  90. package/tools/hook-writer/index.mjs +147 -0
  91. package/tools/init-preflight.mjs +5 -4
  92. package/tools/init-project.mjs +12 -11
  93. package/tools/inject-methodology.mjs +3 -2
  94. package/tools/jev-guide.mjs +2 -2
  95. package/tools/known-footprint.mjs +27 -25
  96. package/tools/mcp-registration.mjs +6 -5
  97. package/tools/migration-blocks.mjs +2 -1
  98. package/tools/migration-notes.mjs +2 -2
  99. package/tools/node-evidence.mjs +4 -4
  100. package/tools/now-facts.mjs +5 -5
  101. package/tools/now-status.mjs +1 -5
  102. package/tools/orchestration-config.mjs +2 -1
  103. package/tools/orchestration-readme.mjs +7 -2
  104. package/tools/plan-approval/cli.mjs +45 -0
  105. package/tools/plan-approval/entries.mjs +109 -0
  106. package/tools/plan-approval/index.mjs +2 -0
  107. package/tools/plan-approval/record.mjs +198 -0
  108. package/tools/plan-files.mjs +6 -4
  109. package/tools/plan-shape-cli.mjs +10 -64
  110. package/tools/plan-shape-facts.mjs +240 -83
  111. package/tools/plan-shape.mjs +173 -160
  112. package/tools/plan-structure/cli.mjs +79 -0
  113. package/tools/plan-structure/index.mjs +67 -0
  114. package/tools/procedures.mjs +21 -17
  115. package/tools/profile-gaps.mjs +4 -6
  116. package/tools/project-rules/rules-priors.mjs +2 -0
  117. package/tools/project-rules/themes.mjs +6 -4
  118. package/tools/recipes.mjs +44 -29
  119. package/tools/recommendations.mjs +90 -39
  120. package/tools/reference-profile.mjs +2 -2
  121. package/tools/release-scan/index.mjs +30 -0
  122. package/tools/release-scan.mjs +46 -25
  123. package/tools/renderers.mjs +14 -8
  124. package/tools/repo-lex.mjs +84 -0
  125. package/tools/robustness-brief.mjs +14 -11
  126. package/tools/sandbox-masks.mjs +6 -4
  127. package/tools/satellite-locator.mjs +3 -2
  128. package/tools/script-priors.mjs +3 -2
  129. package/tools/session-close-check.mjs +71 -15
  130. package/tools/set-flow.mjs +2 -2
  131. package/tools/set-recipe.mjs +17 -9
  132. package/tools/source-size/help.mjs +4 -4
  133. package/tools/source-size/layout.mjs +2 -1
  134. package/tools/source-size/piles.mjs +2 -2
  135. package/tools/source-size-config.mjs +3 -3
  136. package/tools/source-size-refusal.mjs +4 -3
  137. package/tools/source-size-report.mjs +41 -13
  138. package/tools/spec-check-cli.mjs +159 -21
  139. package/tools/spec-check-ops.mjs +74 -5
  140. package/tools/spec-check.mjs +54 -45
  141. package/tools/spec-coverage-cli.mjs +3 -2
  142. package/tools/stage-render/cli.mjs +231 -0
  143. package/tools/stage-render/index.mjs +340 -0
  144. package/tools/stage-render/stages.json +115 -0
  145. package/tools/stage-write-guard/cli.mjs +64 -0
  146. package/tools/stage-write-guard/index.mjs +56 -0
  147. package/tools/state-block-hook.mjs +38 -163
  148. package/tools/task-brief.mjs +8 -13
  149. package/tools/task-thread.mjs +3 -1
  150. package/tools/tier-guide-facts.mjs +23 -9
  151. package/tools/tier-preview.mjs +15 -19
  152. package/tools/transition/index.mjs +10 -9
  153. package/tools/uninstall.mjs +26 -12
  154. package/tools/vehicle-settings.mjs +2 -1
  155. package/tools/velocity-profile.mjs +5 -6
  156. package/tools/view-model.mjs +7 -4
  157. package/tools/worktree-prompt.mjs +7 -3
  158. package/tools/worktrees.mjs +235 -159
  159. package/tools/write-lanes.mjs +20 -14
@@ -9,7 +9,7 @@ import { join, dirname, resolve } from 'node:path';
9
9
  import { fileURLToPath } from 'node:url';
10
10
  import { spawnSync, execFile } from 'node:child_process';
11
11
  import { createHash } from 'node:crypto';
12
- import { makeFixtureRepo } from './codex-fixtures-harness.test.mjs';
12
+ import { composeApprovalBlock, makeFixtureRepo, writeStubCheck } from './codex-fixtures-harness.test.mjs';
13
13
 
14
14
  const HERE = dirname(fileURLToPath(import.meta.url));
15
15
  const WRAPPER = join(HERE, 'codex-exec.sh');
@@ -1088,6 +1088,13 @@ describe('codex-exec.sh — --help contract (manifest-pinned)', { concurrency: 2
1088
1088
  assert.equal(norm(helpSection(help, 'Notes:').join(' ')), norm(EXEC_CONTRACT.notes.join(' ')));
1089
1089
  });
1090
1090
 
1091
+ it('Receipt names the aw-plan-approval stop: a nonced run without a matching approval refuses pre-spend', async () => {
1092
+ const receipt = norm(helpSection(runHelp('--help').stdout, 'Receipt:').join(' '));
1093
+ const sentence = receipt.split(/(?<=\.)\s+/).find((part) => part.includes('aw-plan-approval'));
1094
+ assert.ok(sentence, 'the Receipt section names the aw-plan-approval stop');
1095
+ for (const word of [/nonce/i, /approval/i, /match/i, /pre-spend/i]) assert.match(sentence, word);
1096
+ });
1097
+
1091
1098
  it('--help after the -- separator is passthrough payload, never intercepted', async () => {
1092
1099
  const sb = makeSandbox();
1093
1100
  const r = await run(sb, { args: ['-', '--', '--help'], input: 'go' });
@@ -1740,7 +1747,11 @@ const readReceipt = (dir, nonce) => JSON.parse(readFileSync(join(dir, receiptNam
1740
1747
  // A dispatch file carrying exactly ONE top-level contract block — the same shape `dispatch open
1741
1748
  // --contract` parses, so the digest the wrapper computes here is the digest the ledger recorded.
1742
1749
  const CONTRACT_FENCE = '```';
1743
- const writeContract = (sb, nonce, over = {}) => {
1750
+ const APPROVED_PLAN = 'docs/plans/approved-plan.md';
1751
+ const APPROVAL = createHash('sha256').update('the approved essence').digest('hex');
1752
+ const approvalOf = (sb, over = {}) => ({ plan: APPROVED_PLAN, approval: APPROVAL, ...over, check: over.check ?? writeStubCheck(sb.root) });
1753
+ const approvalBlockFor = (sb, over = {}) => composeApprovalBlock(approvalOf(sb, over));
1754
+ const writeContract = (sb, nonce, over = {}, approvalBlock = approvalBlockFor(sb)) => {
1744
1755
  const contract = {
1745
1756
  schema: 1,
1746
1757
  nonce,
@@ -1754,7 +1765,7 @@ const writeContract = (sb, nonce, over = {}) => {
1754
1765
  };
1755
1766
  const rel = `${nonce}-dispatch.md`;
1756
1767
  writeFileSync(join(sb.repo, rel),
1757
- `# sub-task\n\n${CONTRACT_FENCE}aw-dispatch-contract\n${JSON.stringify(contract, null, 2)}\n${CONTRACT_FENCE}\n`);
1768
+ `# sub-task\n\n${CONTRACT_FENCE}aw-dispatch-contract\n${JSON.stringify(contract, null, 2)}\n${CONTRACT_FENCE}\n${approvalBlock}`);
1758
1769
  return rel;
1759
1770
  };
1760
1771
 
@@ -2050,6 +2061,103 @@ describe('codex-exec.sh — the pre-spend reservation (D1/D8)', { concurrency: 2
2050
2061
  });
2051
2062
  });
2052
2063
 
2064
+ const APPROVAL_MODES = [
2065
+ { label: 'fresh', args: (file) => ['--nonce', 'appr', file] },
2066
+ { label: '--resume <id>', args: (file) => ['--resume', 'sess-xyz', '--nonce', 'appr', file] },
2067
+ { label: '--resume-last', args: (file) => ['--resume-last', '--nonce', 'appr', file] },
2068
+ ];
2069
+ const fenceApproval = (body) => `${CONTRACT_FENCE}aw-plan-approval\n${body}\n${CONTRACT_FENCE}\n`;
2070
+ const runApproval = async (blockFor, mode) => {
2071
+ const sb = makeSandbox();
2072
+ writeFileSync(join(sb.repo, '.codex-last-session'), 'sess-from-sidecar\n');
2073
+ const r = await run(sb, { args: mode.args(writeContract(sb, 'appr', {}, blockFor(sb))) });
2074
+ const callsFile = join(sb.root, 'check-calls.jsonl');
2075
+ const calls = existsSync(callsFile) ? readFileSync(callsFile, 'utf8').split('\n').filter(Boolean).map((line) => JSON.parse(line)) : [];
2076
+ const artifacts = execArtifacts(storeDirOf(sb));
2077
+ const receipt = artifacts.includes(receiptName('appr')) ? readReceipt(storeDirOf(sb), 'appr') : null;
2078
+ rmSync(sb.root, { recursive: true, force: true });
2079
+ return { ...r, calls, artifacts, receipt };
2080
+ };
2081
+ const REFUSED_APPROVALS = [
2082
+ ['an absent block', () => ''],
2083
+ ['a doubled block', (sb) => approvalBlockFor(sb) + approvalBlockFor(sb)],
2084
+ ['a block with an extra key', (sb) => fenceApproval(JSON.stringify({ ...approvalOf(sb), extra: 'x' }))],
2085
+ ['a block without check', () => fenceApproval(JSON.stringify({ plan: APPROVED_PLAN, approval: APPROVAL }))],
2086
+ ['a block holding an array', (sb) => fenceApproval(JSON.stringify([approvalOf(sb)]))],
2087
+ ['a block that is no JSON', () => fenceApproval(`plan: ${APPROVED_PLAN}`)],
2088
+ ['an approval of 63 hex', (sb) => approvalBlockFor(sb, { approval: APPROVAL.slice(1) })],
2089
+ ['an upper-case approval', (sb) => approvalBlockFor(sb, { approval: APPROVAL.toUpperCase() })],
2090
+ ['an approval that is not hex', (sb) => approvalBlockFor(sb, { approval: 'g'.repeat(64) })],
2091
+ ['a plan starting with -', (sb) => approvalBlockFor(sb, { plan: `-${APPROVED_PLAN}` })],
2092
+ ['an empty plan', (sb) => approvalBlockFor(sb, { plan: '' })],
2093
+ ['a relative check path', (sb) => {
2094
+ writeStubCheck(sb.repo);
2095
+ return approvalBlockFor(sb, { check: join('tools', 'plan-approval', 'cli.mjs') });
2096
+ }],
2097
+ ['a check path that does not exist', (sb) => approvalBlockFor(sb, { check: join(sb.root, 'absent', 'tools', 'plan-approval', 'cli.mjs') })],
2098
+ ['a check path that is a directory', (sb) => {
2099
+ const folder = join(sb.root, 'folder', 'tools', 'plan-approval', 'cli.mjs');
2100
+ mkdirSync(folder, { recursive: true });
2101
+ return approvalBlockFor(sb, { check: folder });
2102
+ }],
2103
+ ['a check file not named cli.mjs', (sb) => {
2104
+ const other = join(sb.root, 'tools', 'plan-approval', 'check.mjs');
2105
+ cpSync(writeStubCheck(sb.root), other);
2106
+ return approvalBlockFor(sb, { check: other });
2107
+ }],
2108
+ ['a check that exits non-zero', (sb) => approvalBlockFor(sb, { check: writeStubCheck(sb.root, { status: 1 }) })],
2109
+ ['a block standing only inside another fence', (sb) => `${CONTRACT_FENCE}\`md\n${approvalBlockFor(sb)}${CONTRACT_FENCE}\`\n`],
2110
+ ];
2111
+
2112
+ describe('codex-exec.sh — a nonced run checks the plan approval — spec:plan-approval/S8', { concurrency: 2 }, () => {
2113
+ for (const [label, blockFor] of REFUSED_APPROVALS) {
2114
+ it(`${label}: exit 2 before any reservation or spend, fresh, --resume and --resume-last`, async () => {
2115
+ for (const mode of APPROVAL_MODES) {
2116
+ const r = await runApproval(blockFor, mode);
2117
+ assert.equal(r.status, 2, `${mode.label}: ${r.stderr}`);
2118
+ assert.equal(r.argv, '', `${mode.label}: the fake CLI was never started`);
2119
+ assert.deepEqual(r.artifacts, [], `${mode.label}: nothing was reserved`);
2120
+ }
2121
+ });
2122
+ }
2123
+
2124
+ it('a check that exits 0 lets every mode proceed, called as check <plan> --digest <approval>, the contract digest unchanged', async () => {
2125
+ const digests = [];
2126
+ for (const [index, mode] of APPROVAL_MODES.entries()) {
2127
+ const plan = `docs/plans/approved-${index}.md`;
2128
+ const approval = createHash('sha256').update(plan).digest('hex');
2129
+ const r = await runApproval((sb) => approvalBlockFor(sb, { plan, approval }), mode);
2130
+ assert.equal(r.status, 0, `${mode.label}: ${r.stderr}`);
2131
+ assert.deepEqual(r.calls, [['check', plan, '--digest', approval]], `${mode.label}: the check ran once on the block's plan and approval`);
2132
+ assert.match(r.argv, /(^|\n)exec(\n|$)/, `${mode.label}: codex exec was reached`);
2133
+ assert.equal(r.receipt?.state, 'terminal', `${mode.label}: the run published its terminal receipt`);
2134
+ digests.push(r.receipt.contractDigest);
2135
+ }
2136
+ assert.equal(new Set(digests).size, 1, 'the approval block never enters the contract digest');
2137
+ });
2138
+
2139
+ it('a nonce-less run is byte-unchanged and needs no node', async () => {
2140
+ const sb = makeSandbox();
2141
+ const refusing = writeStubCheck(join(sb.root, 'refusing'), { status: 1 });
2142
+ const file = writeContract(sb, 'plain', {}, approvalBlockFor(sb, { check: refusing }));
2143
+ const withNode = await run(sb, { args: [file] });
2144
+ clearCaptures(sb);
2145
+ const withoutNode = await run(sb, { args: [file], path: `${sb.bin}:${farmFor(['node'])}` });
2146
+ const checked = existsSync(join(sb.root, 'refusing', 'check-calls.jsonl'));
2147
+ const prompt = readFileSync(join(sb.repo, file), 'utf8');
2148
+ const artifacts = execArtifacts(storeDirOf(sb));
2149
+ rmSync(sb.root, { recursive: true, force: true });
2150
+ for (const r of [withNode, withoutNode]) {
2151
+ assert.equal(r.status, 0, r.stderr);
2152
+ assert.ok(r.capStdin.includes(prompt.trimEnd()), 'the prompt reaches codex byte for byte');
2153
+ }
2154
+ assert.equal(withoutNode.stdout, withNode.stdout);
2155
+ assert.equal(withoutNode.capStdin, withNode.capStdin);
2156
+ assert.equal(checked, false, 'a nonce-less run never runs the check');
2157
+ assert.deepEqual(artifacts, []);
2158
+ });
2159
+ });
2160
+
2053
2161
  describe('codex-exec.sh — the fail-closed terminal receipt (D1/D3/3.1.d)', { concurrency: 2 }, () => {
2054
2162
  it('a SUCCESSFUL run publishes a complete report and a terminal receipt that describes it', async () => {
2055
2163
  const sb = makeSandbox();
@@ -1,6 +1,6 @@
1
1
  import { after } from 'node:test';
2
2
  import { spawnSync } from 'node:child_process';
3
- import { existsSync, lstatSync, mkdirSync, mkdtempSync, realpathSync, rmSync } from 'node:fs';
3
+ import { existsSync, lstatSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
4
4
  import { tmpdir } from 'node:os';
5
5
  import { dirname, isAbsolute, join, relative, sep } from 'node:path';
6
6
  import { fileURLToPath, pathToFileURL } from 'node:url';
@@ -16,6 +16,21 @@ const isInside = (parent, path) => {
16
16
  };
17
17
  const runGit = (args, cwd, env) => spawnSync('git', args, { cwd, env: stripGitEnv(env), encoding: 'utf8' });
18
18
 
19
+ export const writeStubCheck = (dir, { status = 0 } = {}) => {
20
+ const folder = join(dir, 'tools', 'plan-approval');
21
+ mkdirSync(folder, { recursive: true });
22
+ const check = join(folder, 'cli.mjs');
23
+ writeFileSync(check, [
24
+ "import { appendFileSync } from 'node:fs';",
25
+ `appendFileSync(${JSON.stringify(join(dir, 'check-calls.jsonl'))}, JSON.stringify(process.argv.slice(2)) + '\\n');`,
26
+ `process.exit(${JSON.stringify(status)});`,
27
+ '',
28
+ ].join('\n'));
29
+ return check;
30
+ };
31
+
32
+ export const composeApprovalBlock = ({ plan, approval, check }) => ['```aw-plan-approval', JSON.stringify({ plan, approval, check }), '```', ''].join('\n');
33
+
19
34
  export const makeFixtureRepo = (run, dir, initArgs = []) => {
20
35
  run(['init', ...initArgs, dir]);
21
36
  run(['-C', dir, 'config', 'maintenance.auto', 'false']);
@@ -4,7 +4,7 @@ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, cpSync
4
4
  import { join, dirname, resolve } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { spawnSync } from 'node:child_process';
7
- import { makeFixtureRepo, openSuiteScopes } from './codex-fixtures-harness.test.mjs';
7
+ import { composeApprovalBlock, makeFixtureRepo, openSuiteScopes, writeStubCheck } from './codex-fixtures-harness.test.mjs';
8
8
 
9
9
  const HERE = dirname(fileURLToPath(import.meta.url));
10
10
  const EXEC = join(HERE, 'codex-exec.sh');
@@ -212,6 +212,8 @@ describe('a one-off is refused pre-spend unless it is a probe — spec:bridge-mo
212
212
  });
213
213
 
214
214
  const CONTRACT = '# dispatch\n\n```aw-dispatch-contract\n{"nonce":"n1","scope":"probe"}\n```\n';
215
+ const writeApprovedTask = (sb) => writeFileSync(join(sb.repo, 'task.md'), CONTRACT
216
+ + composeApprovalBlock({ plan: 'docs/plans/approved-plan.md', approval: 'c'.repeat(64), check: writeStubCheck(sb.home) }));
215
217
  describe('a nonced probe one-off is refused; a probe review keeps its nonce — spec:bridge-model/S6', () => {
216
218
  const nonced = [
217
219
  ['AW_DISPATCH_NONCE', ['task.md'], { AW_DISPATCH_NONCE: 'n1' }],
@@ -221,7 +223,7 @@ describe('a nonced probe one-off is refused; a probe review keeps its nonce —
221
223
  for (const [label, args, env] of nonced) {
222
224
  it(`${label}: a probe one-off is refused before any reservation`, () => {
223
225
  const sb = sandbox({ settings: HOST_SETTING });
224
- writeFileSync(join(sb.repo, 'task.md'), CONTRACT);
226
+ writeApprovedTask(sb);
225
227
  const r = drive(sb, [EXEC, args], { ...env, CODEX_PROBE: '1', CODEX_MODEL: MANIFEST.posture.model });
226
228
  assertRefusedUnspent(r);
227
229
  assert.match(r.stderr, /cannot carry a dispatch nonce/);
@@ -230,7 +232,7 @@ describe('a nonced probe one-off is refused; a probe review keeps its nonce —
230
232
  }
231
233
  it('a nonced probe on the host posture runs and mints its receipt', () => {
232
234
  const sb = sandbox({ settings: HOST_SETTING });
233
- writeFileSync(join(sb.repo, 'task.md'), CONTRACT);
235
+ writeApprovedTask(sb);
234
236
  const r = drive(sb, [EXEC, ['--nonce', 'n1', 'task.md']], { CODEX_PROBE: '1' });
235
237
  assertRan(r, 'gpt-6-luna', 'medium');
236
238
  const receipt = JSON.parse(readFileSync(join(sb.repo, '.git', 'agent-workflow-exec-receipt-5-codex-n1.json'), 'utf8'));
@@ -416,7 +416,7 @@ aw_scrub_billing_keys() {
416
416
  # Review-receipt identity (AD-038). AW_BRIDGE_VERSION mirrors this bridge's SKILL.md/capability.json
417
417
  # version (drift-guarded by codex-review.test.mjs against capability.json).
418
418
  AW_RECEIPT_BACKEND="codex"
419
- AW_BRIDGE_VERSION="6.1.0" # aw-version-anchor
419
+ AW_BRIDGE_VERSION="7.0.0" # aw-version-anchor
420
420
  # Generous hard cap for a slow review at the host posture's effort (subscription latency varies).
421
421
  CODEX_HARD_TIMEOUT="${CODEX_HARD_TIMEOUT:-1800}"
422
422
  # Above this assembled-payload size (bytes), the diff goes via a git-dir-local temp
@@ -3,7 +3,7 @@
3
3
  "schema": 1,
4
4
  "name": "codex-cli-bridge",
5
5
  "kind": "execution-backend",
6
- "version": "6.1.0",
6
+ "version": "7.0.0",
7
7
  "posture": { "model": "gpt-6.2-sol", "effort": "high", "tier": null },
8
8
  "provides": ["execute", "review"],
9
9
  "roles": {
@@ -21,7 +21,7 @@
21
21
  "codex-exec --resume-last [--nonce <n>] <plan-file|->",
22
22
  "codex-exec --resume <session-id> [--nonce <n>] <plan-file|->"
23
23
  ],
24
- "receipt": "side effect — a NONCED run mints ONE exec receipt beside the delegation store: the dispatch nonce seam is the AW_DISPATCH_NONCE environment value or its plain-argument equivalent --nonce <n>, recognised ONLY before the prompt operand (after the operand or a literal '--' it is passthrough payload, never a flag), under the safe grammar [A-Za-z0-9._-]{1,64} — anything else, a duplicate, or a flag disagreeing with a non-empty env value refuses PRE-SPEND. The store directory resolves exactly as the kit's delegation store does: the dirname of an ABSOLUTE AW_DELEGATION_STORE (a relative one, or one ending in a path separator, refuses), else the git common dir. The artifact is agent-workflow-exec-receipt-<backendLength>-<backend>-<nonce>.json in two states: 'reserved' is written atomically and NO-CLOBBER immediately before the CLI runs — that write IS the nonce reservation, so a second dispatch on the same nonce, or an already-taken report name, refuses BEFORE any spend — and 'terminal' replaces it in place at exit. A nonced run also refuses pre-spend when no timeout/gtimeout binary can cap it (an accounted dispatch that cannot be capped can never honour the terminal-exit rule; a nonce-LESS run still warns and runs uncapped), when node is missing (the mint core), and when the prompt rides on stdin instead of a contract FILE — contractDigest is computed BY THIS WRAPPER from the dispatch file it was actually handed, so the kit can refuse a run that executed a different contract than the one it opened. That digest is taken from the SAME bytes already read as the prompt, never a second open of the path: two reads leave a window in which the file can be swapped, and the run would then execute one contract while its receipt claimed the digest of another. The header's own nonce must EQUAL the dispatch nonce — 'dispatch open' copies the nonce FROM the header, so a disagreeing --nonce could only reserve an identity no return would ever absorb, and it refuses pre-spend. A contract file edited BETWEEN 'dispatch open' and the run is caught at ABSORB by the contractDigest comparison, not pre-spend: the wrapper never reads the ledger, and that boundary is what the whole lane rests on. At exit the wrapper FIRST re-reads its reservation and verifies its own opaque owner token — a foreign owner refuses having published NOTHING, neither report nor receipt — THEN writes the delegate's final message atomically to agent-workflow-exec-report-<backendLength>-<backend>-<nonce>.txt, THEN re-verifies the owner and REPLACES the reservation with the terminal receipt {schema, kind, state, backend, nonce, owner, contractDigest, wrapperVersion, posture {model, effort, tier}, capS, killGraceS, sessionId, exitStatus, outcome, reportDigest, reportLength, timestamp}: the report is complete on disk before any artifact says the run arrived. capS and killGraceS are the cap the run ACTUALLY applied. outcome is the wrapper's own SUBSET of the ledger's vocabulary — exit 0 with a session id -> success, exit 0 without one -> missing-identity, ANY nonzero exit including the timeout codes 124 and 137 -> transport-failure; every orchestrator judgment is recorded at absorb time, never claimed here. The session id is captured BEFORE outcome branching, so a FAILED run records one too; in resume mode it is the validated resume id. FAIL-CLOSED, deliberately NOT the review lane's warn-only receipt: a publication that cannot complete exits nonzero with a DISTINCT status, and the message states only what the run can still prove. 70: the reservation could not be verified BEFORE any publication — NOTHING was published, not the report and not the receipt, and because the artifact found there belongs to another run it is never a '--no-receipt' source. 71: a publication stopped after that point — either the report write failed (nothing beyond the reservation was published; the '--no-receipt' absorb then records reportLength 0, ineligible by the name empty-report) or the report IS on disk and the terminal receipt was not completed (the absorb reads it, report-if-present). The post-report lane never claims the reservation still stands, because after that point its fate is no longer something this run observed. Every lane names the tree as partial/dirtied rather than untouched. A nonce-LESS invocation is byte-unchanged: no reservation, no receipt, no artifact, and it needs no node.",
24
+ "receipt": "side effect — a NONCED run mints ONE exec receipt beside the delegation store: the dispatch nonce seam is the AW_DISPATCH_NONCE environment value or its plain-argument equivalent --nonce <n>, recognised ONLY before the prompt operand (after the operand or a literal '--' it is passthrough payload, never a flag), under the safe grammar [A-Za-z0-9._-]{1,64} — anything else, a duplicate, or a flag disagreeing with a non-empty env value refuses PRE-SPEND. The store directory resolves exactly as the kit's delegation store does: the dirname of an ABSOLUTE AW_DELEGATION_STORE (a relative one, or one ending in a path separator, refuses), else the git common dir. The artifact is agent-workflow-exec-receipt-<backendLength>-<backend>-<nonce>.json in two states: 'reserved' is written atomically and NO-CLOBBER immediately before the CLI runs — that write IS the nonce reservation, so a second dispatch on the same nonce, or an already-taken report name, refuses BEFORE any spend — and 'terminal' replaces it in place at exit. A nonced run also refuses pre-spend when no timeout/gtimeout binary can cap it (an accounted dispatch that cannot be capped can never honour the terminal-exit rule; a nonce-LESS run still warns and runs uncapped), when node is missing (the mint core), and when the prompt rides on stdin instead of a contract FILE — contractDigest is computed BY THIS WRAPPER from the dispatch file it was actually handed, so the kit can refuse a run that executed a different contract than the one it opened. That digest is taken from the SAME bytes already read as the prompt, never a second open of the path: two reads leave a window in which the file can be swapped, and the run would then execute one contract while its receipt claimed the digest of another. The header's own nonce must EQUAL the dispatch nonce — 'dispatch open' copies the nonce FROM the header, so a disagreeing --nonce could only reserve an identity no return would ever absorb, and it refuses pre-spend. A contract file edited BETWEEN 'dispatch open' and the run is caught at ABSORB by the contractDigest comparison, not pre-spend: the wrapper never reads the ledger, and that boundary is what the whole lane rests on. At exit the wrapper FIRST re-reads its reservation and verifies its own opaque owner token — a foreign owner refuses having published NOTHING, neither report nor receipt — THEN writes the delegate's final message atomically to agent-workflow-exec-report-<backendLength>-<backend>-<nonce>.txt, THEN re-verifies the owner and REPLACES the reservation with the terminal receipt {schema, kind, state, backend, nonce, owner, contractDigest, wrapperVersion, posture {model, effort, tier}, capS, killGraceS, sessionId, exitStatus, outcome, reportDigest, reportLength, timestamp}: the report is complete on disk before any artifact says the run arrived. capS and killGraceS are the cap the run ACTUALLY applied. outcome is the wrapper's own SUBSET of the ledger's vocabulary — exit 0 with a session id -> success, exit 0 without one -> missing-identity, ANY nonzero exit including the timeout codes 124 and 137 -> transport-failure; every orchestrator judgment is recorded at absorb time, never claimed here. The session id is captured BEFORE outcome branching, so a FAILED run records one too; in resume mode it is the validated resume id. FAIL-CLOSED, deliberately NOT the review lane's warn-only receipt: a publication that cannot complete exits nonzero with a DISTINCT status, and the message states only what the run can still prove. 70: the reservation could not be verified BEFORE any publication — NOTHING was published, not the report and not the receipt, and because the artifact found there belongs to another run it is never a '--no-receipt' source. 71: a publication stopped after that point — either the report write failed (nothing beyond the reservation was published; the '--no-receipt' absorb then records reportLength 0, ineligible by the name empty-report) or the report IS on disk and the terminal receipt was not completed (the absorb reads it, report-if-present). The post-report lane never claims the reservation still stands, because after that point its fate is no longer something this run observed. Every lane names the tree as partial/dirtied rather than untouched. A nonced run also refuses pre-spend, reserving nothing, unless its contract file carries exactly one top-level aw-plan-approval block of exactly plan, approval and check whose check (the kit's tools/plan-approval/cli.mjs check <plan> --digest <approval>) exits 0, so a nonced run never starts unless the approval record matches the block's own plan and approval; the kit's tools/stage-render/cli.mjs --dispatch <plan> prints that block. A nonce-LESS invocation is byte-unchanged: no reservation, no receipt, no artifact, and it needs no node.",
25
25
  "passthrough": {
26
26
  "policy": "guarded",
27
27
  "blocked": ["-c*", "--config*", "-s*", "--sandbox*", "--dangerously-bypass-approvals-and-sandbox", "--dangerously-bypass-hook-trust", "--full-auto", "--oss", "--local-provider*", "-p*", "--profile*", "-m*", "--model*", "-o*", "--output-last-message*", "--json*", "--color*", "--output-schema*", "--ephemeral*"],
package/capability.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schema": 1,
4
4
  "name": "agent-workflow-kit",
5
5
  "kind": "composition-root",
6
- "version": "23.11.0",
6
+ "version": "24.0.0",
7
7
  "provides": [],
8
8
  "roles": {},
9
9
  "detect": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sabaiway/agent-workflow-kit",
3
- "version": "23.11.0",
3
+ "version": "24.0.0",
4
4
  "description": "Portable, cross-agent memory & workflow for AI coding agents — Claude Code, Codex, Cursor, Devin Desktop. One command deploys an AGENTS.md entry point + docs/ai context with cap/archive/index enforcement into any repo.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -33,6 +33,8 @@
33
33
  | read-lane | chat | gate-hook.mjs |
34
34
  | state-block | harness | state-block-hook.mjs |
35
35
  | state-block.not-current | kit | state-block-hook.mjs |
36
+ | stage-guard | harness | stage-write-guard/cli.mjs |
37
+ | stage-guard.not-current | kit | stage-write-guard/cli.mjs |
36
38
  | mcp-channel | harness | mcp.mjs |
37
39
  | mcp-channel.differing | harness | mcp.mjs |
38
40
  | agents | harness | cheap-agents.mjs |
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: author
3
+ description: Drafts ONE bounded authoring slice on behalf of the orchestrator — a plan, a contract, an epic or a fold of a round's findings; only the files the brief names, with no shell.
4
+ model: opus
5
+ effort: high
6
+ tools: Read, Grep, Glob, Write, Edit
7
+ ---
8
+
9
+ You are the AUTHOR vehicle. The orchestrator owns the review and the commit; you own
10
+ one authoring slice and nothing else.
11
+
12
+ - **One slice, the named files only.** Draft a plan, a contract, an epic or a fold of a round's
13
+ findings. Write only the files the brief names. You write no code file and no test file.
14
+ - **Read before you edit.** Read the plan, the governing contracts and the project rules the brief
15
+ names first.
16
+ - **You never commit.** You run no git command. You have no shell, so you run no command at all.
17
+ - **A red line STOPS you.** An approval ask, a need for the network or a credential, a file outside
18
+ your slice, or a finding that the brief itself is wrong: you stop and report it. You never
19
+ improvise around it and never widen your own scope to repair it.
20
+ - **Your final message IS the return value.** The exact paths you wrote and anything left undone
21
+ with the reason. The orchestrator reviews every returned draft as its own.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: executor
3
- description: Executes ONE bounded slice — an execution, authoring, or write-capable routine slice — on behalf of the orchestrator; only the files the brief names, their suites, and a return block. Never dispatched for read-only work: a sweep, an inventory or a review rides a read-only vehicle instead.
3
+ description: Executes ONE bounded slice — an execution or write-capable routine slice — on behalf of the orchestrator; only the files the brief names, their suites, and a return block. Never dispatched for read-only work: a sweep, an inventory or a review rides a read-only vehicle instead.
4
4
  model: opus
5
5
  effort: high
6
6
  ---
@@ -14,12 +14,19 @@ plan, the review and the commit; you own ONE slice of it, end to end, and nothin
14
14
  not a decision you get to make.
15
15
  - **Read before you edit.** The plan, the governing contract and the project rules the brief names
16
16
  are read first. An edit written before them is guesswork wearing the shape of work.
17
+ - **A code or test slice runs only on an approved plan.** It runs only from a brief carrying the
18
+ dispatch part the renderer printed (`tools/stage-render/cli.mjs --dispatch <plan>`, its
19
+ ` ```aw-plan-approval ` block). Before any write you run that part's check command for the
20
+ block's `plan` and `approval`, and you stop on any exit but 0, on a brief whose plan is not the
21
+ block's `plan`, and on a file to write that neither an approved row nor a valid amendment entry
22
+ of that plan covers, a sweep's concrete paths included. A routine or task slice that names the
23
+ kit command generating each file and hand-writes no source or test file is outside this stop.
17
24
  - **You never commit, and you never touch what governs you.** No git write at all: no `add`,
18
- `commit`, `push`, `stash`, `reset`, `checkout`, `tag`, no history rewrite. You never edit the plan
25
+ `commit`, `push`, `stash`, `reset`, `checkout`, `tag`, `worktree`, no history rewrite. You never edit the plan
19
26
  or the contract under `docs/ai/specs/` that governs YOUR OWN slice, the ADR, the changelog, the
20
27
  handover documents or `docs/ai/source-size.json` — those are the orchestrator's, and the
21
- orchestrator is the only one who commits. A plan draft, a contract draft or a regenerated document
22
- that the brief names as your DELIVERABLE (an authoring or a routine slice) is a named file like
28
+ orchestrator is the only one who commits. A regenerated document
29
+ that the brief names as your DELIVERABLE (a routine slice) is a named file like
23
30
  any other.
24
31
  - **You run the suites and report what they printed.** The brief maps every file you touch to the
25
32
  exact test files and commands to run; where it does not, run the paired `<name>.test.mjs` when one
@@ -28,8 +35,7 @@ plan, the review and the commit; you own ONE slice of it, end to end, and nothin
28
35
  return block. A failing
29
36
  test is reported as failing; papering over it, skipping it, or weakening an assertion to reach
30
37
  green is the worst thing you can do here.
31
- - **You stay inside the budget the brief states.** Every file keeps to the line cap it names. A
32
- comment exists only where the code truly cannot carry the fact. No attribution of any kind — to
38
+ - A comment exists only where the code truly cannot carry the fact. No attribution of any kind — to
33
39
  an agent, a model or a tool — anywhere: code, comments, messages, documents. The project's
34
40
  language and encoding rules come from its `AGENTS.md` and the brief — never assume English or ASCII.
35
41
  - **A red line STOPS you.** An approval ask, a need for the network or a credential, a file outside
@@ -96,12 +96,12 @@ On `upgrade`, a pre-1.2.0 deployment with no block gets one (the agent asks, def
96
96
  Every name the kit bundles and writes over on an upgrade is the kit's, and an edit there is never a
97
97
  customization: every kit script, the kit folder `scripts/agent-workflow/` whole, the spec layer's
98
98
  files and the command `scripts/agent-workflow/run.mjs` in it, the hook installer set, the kit rules
99
- files `docs/ai/rules/<theme>.md` and the kit agent files (the five the kit bundles for
100
- `.claude/agents/` — `changelog-skeleton.md`, `executor.md`,
99
+ files `docs/ai/rules/<theme>.md` and the kit agent files (the names the kit bundles for
100
+ `.claude/agents/` — `author.md`, `changelog-skeleton.md`, `executor.md`,
101
101
  `gate-triage.md`, `mechanical-sweep.md`, `review-lens.md` — and each configured
102
102
  `review-lens-<model>-<effort>.md`) and, within a hook you wired, the kit hook files
103
- `.claude/hooks/agent-workflow-gates.mjs` and `.claude/hooks/state-block-guard.mjs` are written over
104
- by the next upgrade with no question and no copy kept.
103
+ `.claude/hooks/agent-workflow-gates.mjs`, `.claude/hooks/state-block-guard.mjs` and
104
+ `.claude/hooks/stage-write-guard.mjs` are written over by the next upgrade with no question and no copy kept.
105
105
  Also the kit's: the vendor skill copy the kit installs into the three agent skill roots
106
106
  when it matches a pin the kit shipped, written with no question beside a copy at a kit pin;
107
107
  a copy matching none is the user's, left and named. Also the kit's: the kit block of `AGENTS.md`, between its two
@@ -4,9 +4,8 @@
4
4
  // <project>/.claude/hooks/agent-workflow-gates.mjs and wired as a `PreToolUse` "Bash" hook in
5
5
  // .claude/settings.json.
6
6
  //
7
- // SELF-CONTAINED by contract: the placed copy must run on machines without the kit — no kit
8
- // imports, dependency-free, Node >= 22, no side effects on import.
9
- // SEEDED_READONLY_CORE and RESIDUAL_FORMS are the generated region scripts/sync-mirrors.mjs writes from velocity-profile.mjs.
7
+ // SELF-CONTAINED by contract: no kit imports, dependency-free, Node >= 22, no side effects on import.
8
+ // GATES_REL, LANES_REL, SEEDED_READONLY_CORE and RESIDUAL_FORMS are generated by scripts/sync-mirrors.mjs from velocity-profile.mjs and shared/locations.mjs.
10
9
  //
11
10
  // It reads <project root>/docs/ai/gates.json LIVE on every invocation (AD-035: one declaration,
12
11
  // two consumers — editing gates.json never requires re-wiring) and, for the opt-in read-lane
@@ -87,10 +86,6 @@ import { fileURLToPath } from 'node:url';
87
86
 
88
87
  export const HOOK_EVENT_NAME = 'PreToolUse';
89
88
  export const BASH_TOOL_NAME = 'Bash';
90
- export const GATES_REL = 'docs/ai/gates.json';
91
- // The opt-in read-lane toggle (rung c) — a SEPARATE kit-owned strict-JSON file (AD-055 Part II);
92
- // gates.json's schema/validators/template are untouched by design.
93
- export const LANES_REL = 'docs/ai/lanes.json';
94
89
  export const READ_LANE_KEY = 'readLane';
95
90
  export const PROJECT_DIR_ENV = 'CLAUDE_PROJECT_DIR';
96
91
  export const DECISION_ALLOW = 'allow';
@@ -99,7 +94,11 @@ export const DECISION_ASK = 'ask';
99
94
  // fenced closed by default. The residual guard (b) is NOT mode-fenced: an `ask` never loosens.
100
95
  export const ALLOW_PERMISSION_MODES = Object.freeze(['default', 'acceptEdits']);
101
96
 
102
- // generated from agent-workflow-kit/tools/velocity-profile.mjs by scripts/sync-mirrors.mjs; do not edit
97
+ // The opt-in read-lane toggle (rung c) — a SEPARATE kit-owned strict-JSON file (AD-055 Part II);
98
+ // gates.json's schema/validators/template are untouched by design.
99
+ // generated from agent-workflow-kit/tools/velocity-profile.mjs and agent-workflow-memory/references/scripts/shared/locations.mjs by scripts/sync-mirrors.mjs; do not edit
100
+ export const GATES_REL = "docs/ai/gates.json";
101
+ export const LANES_REL = "docs/ai/lanes.json";
103
102
  export const SEEDED_READONLY_CORE = Object.freeze([
104
103
  "Bash(git status:*)",
105
104
  "Bash(git diff:*)",