harness-everything 0.50.0 → 0.52.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 (97) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.github/workflows/ci.yml +23 -0
  4. package/CHANGELOG.md +174 -115
  5. package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-a-evid-001.md +123 -0
  6. package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-b-route-001.md +130 -0
  7. package/ci/mechanism-2am-observations-session-import.test.js +4 -1
  8. package/ci/mechanism-34-observations.test.js +127 -23
  9. package/ci/mechanism-349-ci-change-scope.test.js +260 -0
  10. package/ci/mechanism-handoff-file.test.js +121 -0
  11. package/ci/mechanism-prb-outline-review.test.js +783 -107
  12. package/ci/mechanism-system-one-contract.test.js +9 -2
  13. package/ci/mechanism-system-one-curves.test.js +206 -0
  14. package/ci/mechanism-system-one-cycle.test.js +585 -0
  15. package/ci/mechanism-system-one-evaluation.test.js +32 -5
  16. package/ci/mechanism-system-one-handoff-input.test.js +208 -0
  17. package/ci/mechanism-system-one-install.test.js +202 -77
  18. package/ci/mechanism-system-one-live.test.js +361 -0
  19. package/ci/mechanism-system-one-relevance.test.js +11 -1
  20. package/ci/mechanism-system-one-train.test.js +136 -53
  21. package/ci/release-unreleased-heading.test.js +24 -0
  22. package/ci/system-one-adapter-test.py +331 -0
  23. package/ci/system-one-train-test.py +116 -24
  24. package/docs/adr/EVID-001.md +123 -0
  25. package/docs/adr/ROUTE-001-error-lesson-delivery.md +305 -0
  26. package/docs/doc-workflow-reconciliation.md +29 -16
  27. package/docs/governed-index.md +2 -0
  28. package/docs/platform-capabilities.md +2 -0
  29. package/docs/routing.md +2 -2
  30. package/docs/system-one-cycle.md +68 -0
  31. package/docs/system-one-observations.md +9 -8
  32. package/docs/system-one-routing.md +163 -115
  33. package/docs/system-one-suggestion-gates.md +6 -8
  34. package/docs/system-one-training.md +44 -7
  35. package/docs/workflow-runtime.md +19 -0
  36. package/harness-everything/SKILL.md +1 -1
  37. package/harness-everything/scripts/kernel-router.js +2 -1
  38. package/harness-everything/scripts/system-one/contract.js +19 -15
  39. package/harness-everything/scripts/system-one/cua_adapter.py +211 -17
  40. package/harness-everything/scripts/system-one/evaluate.js +4 -9
  41. package/harness-everything/scripts/system-one/handoff-input.js +76 -0
  42. package/harness-everything/scripts/system-one/install.js +281 -113
  43. package/harness-everything/scripts/system-one/manifest.js +58 -0
  44. package/harness-everything/scripts/system-one/provider.js +96 -2
  45. package/harness-everything/scripts/system-one/resident.js +47 -1
  46. package/harness-everything/scripts/system-one/router.js +80 -1
  47. package/harness-everything/scripts/tier-router.js +21 -6
  48. package/hooks/scripts/lib/doc-reconciliation-pilot.js +12 -0
  49. package/hooks/scripts/lib/doc-reconciliation-provider.js +575 -12
  50. package/hooks/scripts/lib/observations.js +43 -4
  51. package/hooks/scripts/lib/workflow-obligations.js +8 -4
  52. package/hooks/scripts/state-persist.js +26 -7
  53. package/hooks/scripts/w6-state-operations.js +239 -0
  54. package/opencode-plugin/plugin.json +1 -1
  55. package/package.json +2 -2
  56. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  57. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +12 -0
  58. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +575 -12
  59. package/plugins/harness-everything/hooks/scripts/lib/observations.js +43 -4
  60. package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +8 -4
  61. package/plugins/harness-everything/hooks/scripts/state-persist.js +26 -7
  62. package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +239 -0
  63. package/plugins/harness-everything/plugin.json +1 -1
  64. package/plugins/harness-everything/scripts/handoff-file.js +223 -0
  65. package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
  66. package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +2 -1
  67. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/contract.js +19 -15
  68. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +211 -17
  69. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/evaluate.js +4 -9
  70. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/handoff-input.js +76 -0
  71. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +281 -113
  72. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/manifest.js +58 -0
  73. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +96 -2
  74. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/resident.js +47 -1
  75. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/router.js +80 -1
  76. package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +21 -6
  77. package/sbom.cdx.json +7 -7
  78. package/scripts/ci-change-scope.js +59 -0
  79. package/scripts/handoff-file.js +223 -0
  80. package/scripts/sync-openai-plugin.js +4 -0
  81. package/scripts/system-one-calibrate.js +108 -41
  82. package/scripts/system-one-curves.js +332 -0
  83. package/scripts/system-one-cycle/adjudication-input.js +65 -0
  84. package/scripts/system-one-cycle/build.js +165 -0
  85. package/scripts/system-one-cycle/collect.js +50 -0
  86. package/scripts/system-one-cycle/common.js +137 -0
  87. package/scripts/system-one-cycle/engines.js +62 -0
  88. package/scripts/system-one-cycle/evaluate.js +70 -0
  89. package/scripts/system-one-cycle/judge.js +106 -0
  90. package/scripts/system-one-cycle/label.js +59 -0
  91. package/scripts/system-one-cycle/package.js +173 -0
  92. package/scripts/system-one-cycle/score.py +111 -0
  93. package/scripts/system-one-cycle/train.js +136 -0
  94. package/scripts/system-one-cycle.js +131 -0
  95. package/scripts/system-one-observations-export.js +29 -6
  96. package/scripts/system-one-observations-review.js +4 -5
  97. package/scripts/system-one-train.py +117 -61
@@ -0,0 +1,260 @@
1
+ 'use strict';
2
+
3
+ const assert = require('node:assert/strict');
4
+ const fs = require('node:fs');
5
+ const os = require('node:os');
6
+ const path = require('node:path');
7
+ const { execFileSync, spawnSync } = require('node:child_process');
8
+ const yaml = require('js-yaml');
9
+ const { test } = require('node:test');
10
+ const { classifyPaths, classifyChangeSet } = require('../scripts/ci-change-scope');
11
+
12
+ const ROOT = path.resolve(__dirname, '..');
13
+ const SCRIPT = path.join(ROOT, 'scripts', 'ci-change-scope.js');
14
+ const BASELINE_SHA = '71a8706061f2fdec657b1c2b348571aa6c40e877';
15
+ const CHANGE_SCOPE_JOB = 'ci-change-scope';
16
+ const SELF_REGRESSION_IF = "${{ !cancelled() && (needs.ci-change-scope.result != 'success' || needs.ci-change-scope.outputs.scope != 'docs-only') }}";
17
+
18
+ function nulPaths(paths) {
19
+ return paths.length ? Buffer.from(`${paths.join('\0')}\0`) : Buffer.alloc(0);
20
+ }
21
+
22
+ function runGit(cwd, args) {
23
+ return execFileSync('git', ['-C', cwd, ...args], {
24
+ env: { ...process.env, GIT_CONFIG_NOSYSTEM: '1', GIT_TERMINAL_PROMPT: '0' },
25
+ });
26
+ }
27
+
28
+ function gitText(cwd, ...args) {
29
+ return runGit(cwd, args).toString('utf8').trim();
30
+ }
31
+
32
+ function gitDiffPaths(cwd, base, head) {
33
+ const mergeBase = gitText(cwd, 'merge-base', base, head);
34
+ const bytes = runGit(cwd, ['diff', '--no-renames', '--name-only', '-z', mergeBase, head]);
35
+ return bytes.toString('utf8').slice(0, -1).split('\0');
36
+ }
37
+
38
+ function runClassifier(event, base, head, cwd = ROOT) {
39
+ const result = spawnSync(process.execPath, [SCRIPT, event, base, head], { cwd, encoding: 'utf8' });
40
+ assert.equal(result.status, 0, result.stderr);
41
+ assert.equal(result.stderr, '');
42
+ return result.stdout.trim();
43
+ }
44
+
45
+ function baselineFile(file) {
46
+ // Pin the pre-change tree; GitHub's pull_request HEAD is the candidate merge ref.
47
+ return execFileSync('git', ['show', `${BASELINE_SHA}:${file}`], { cwd: ROOT, encoding: 'utf8' });
48
+ }
49
+
50
+ // This models the condition's truth table, not GitHub's scheduler.
51
+ function shouldRunSelfRegression(workflowCancelled, result, scope) {
52
+ return !workflowCancelled && (result !== 'success' || scope !== 'docs-only');
53
+ }
54
+
55
+ test('each owner-approved path class and their combination classify as docs-only', () => {
56
+ for (const file of [
57
+ 'docs/guide.md',
58
+ 'benchmarks/results/run/README.md',
59
+ '.agents/harness-everything/errors/E-0001-example.md',
60
+ 'CHANGELOG.md',
61
+ ]) {
62
+ assert.equal(classifyPaths(nulPaths([file])), 'docs-only', file);
63
+ }
64
+ assert.equal(classifyPaths(nulPaths([
65
+ 'docs/guide.md',
66
+ 'benchmarks/results/run/README.md',
67
+ '.agents/harness-everything/errors/E-0001-example.md',
68
+ 'CHANGELOG.md',
69
+ ])), 'docs-only', 'all four approved classes remain eligible together');
70
+ assert.equal(classifyPaths(nulPaths(['docs/space and\nnewline.md'])), 'docs-only', 'NUL framing preserves spaces and newlines');
71
+ });
72
+
73
+ test('empty, mixed, look-alike, malformed, and non-allowlisted paths run full regression', () => {
74
+ for (const paths of [
75
+ [],
76
+ ['src/change.js'],
77
+ ['docs/guide.md', 'src/change.js'],
78
+ ['docs-extra/guide.md'],
79
+ ['docs/../hooks/change.js'],
80
+ ['CHANGELOG.md.js'],
81
+ ['docs\\guide.md'],
82
+ ['.github/workflows/ci.yml'],
83
+ ['scripts/ci-change-scope.js'],
84
+ ['docs//guide.md'],
85
+ ['/docs/guide.md'],
86
+ ['docs/./guide.md'],
87
+ ]) {
88
+ assert.equal(classifyPaths(nulPaths(paths)), 'full', JSON.stringify(paths));
89
+ }
90
+
91
+ for (const malformed of [
92
+ Buffer.from('docs/guide.md'),
93
+ Buffer.from('docs/guide.md\0\0'),
94
+ Buffer.from('docs/../hooks/change.js\0'),
95
+ Buffer.from([0x64, 0x6f, 0x63, 0x73, 0x2f, 0xff, 0x00]),
96
+ ]) {
97
+ assert.equal(classifyPaths(malformed), 'full', 'uncertain path records fail toward regression');
98
+ }
99
+ });
100
+
101
+ test('non-PR events and Git failures, including partial diff output, classify as full', () => {
102
+ let gitCalls = 0;
103
+ const unusedGit = () => { gitCalls += 1; throw new Error('must not inspect a non-PR diff'); };
104
+ assert.equal(classifyChangeSet('push', 'a'.repeat(40), 'b'.repeat(40), { runGit: unusedGit }), 'full');
105
+ assert.equal(classifyChangeSet('workflow_dispatch', 'a'.repeat(40), 'b'.repeat(40), { runGit: unusedGit }), 'full');
106
+ assert.equal(gitCalls, 0);
107
+
108
+ const fakeGit = bytes => (_args, _options) => {
109
+ if (_args[0] === 'merge-base') return Buffer.from(`${'a'.repeat(40)}\n`);
110
+ return bytes;
111
+ };
112
+ assert.equal(classifyChangeSet('pull_request', 'b'.repeat(40), 'c'.repeat(40), {
113
+ runGit: fakeGit(nulPaths(['docs/guide.md'])),
114
+ }), 'docs-only');
115
+
116
+ const partialError = new Error('git diff failed after writing bytes');
117
+ partialError.stdout = nulPaths(['docs/guide.md']);
118
+ const partialGit = (_args) => {
119
+ if (_args[0] === 'merge-base') return Buffer.from(`${'a'.repeat(40)}\n`);
120
+ throw partialError;
121
+ };
122
+ assert.equal(classifyChangeSet('pull_request', 'b'.repeat(40), 'c'.repeat(40), { runGit: partialGit }), 'full');
123
+ assert.equal(classifyChangeSet('pull_request', '', 'c'.repeat(40), { runGit: unusedGit }), 'full');
124
+ assert.equal(classifyChangeSet('pull_request', 'b'.repeat(40), 'c'.repeat(40), {
125
+ runGit: fakeGit(Buffer.from('docs/guide.md')),
126
+ }), 'full', 'a diff without its final NUL is malformed');
127
+ });
128
+
129
+ test('real Git merge-base diff includes earlier code, deletions, both rename endpoints, and unusual filenames', () => {
130
+ const repo = fs.mkdtempSync(path.join(os.tmpdir(), 'ci-change-scope-'));
131
+ const write = (relative, content) => {
132
+ const file = path.join(repo, relative);
133
+ fs.mkdirSync(path.dirname(file), { recursive: true });
134
+ fs.writeFileSync(file, content);
135
+ };
136
+ const commit = message => {
137
+ runGit(repo, ['add', '--all']);
138
+ runGit(repo, ['commit', '-m', message]);
139
+ return gitText(repo, 'rev-parse', 'HEAD');
140
+ };
141
+
142
+ try {
143
+ runGit(repo, ['init', '-q']);
144
+ runGit(repo, ['config', 'user.name', 'CI Scope Test']);
145
+ runGit(repo, ['config', 'user.email', 'ci-scope@example.invalid']);
146
+ write('docs/delete.md', 'remove me');
147
+ write('docs/move-to-code.md', 'move');
148
+ write('src/move-to-docs.js', 'move');
149
+ write('src/stable.js', 'stable');
150
+ const base = commit('base');
151
+
152
+ fs.rmSync(path.join(repo, 'docs/delete.md'));
153
+ const deleted = commit('delete approved documentation');
154
+ assert.deepEqual(gitDiffPaths(repo, base, deleted), ['docs/delete.md']);
155
+ assert.equal(runClassifier('pull_request', base, deleted, repo), 'docs-only');
156
+
157
+ write('src/earlier-code.js', 'code');
158
+ commit('add code first');
159
+ write('docs/final-doc.md', 'docs after code');
160
+ const docsAfterCode = commit('add docs later');
161
+ assert.ok(gitDiffPaths(repo, base, docsAfterCode).includes('src/earlier-code.js'));
162
+ assert.equal(runClassifier('pull_request', base, docsAfterCode, repo), 'full', 'base…head includes code from an earlier commit');
163
+
164
+ runGit(repo, ['mv', 'docs/move-to-code.md', 'src/moved-from-docs.md']);
165
+ runGit(repo, ['mv', 'src/move-to-docs.js', 'docs/moved-from-code.js']);
166
+ const renamed = commit('rename across the allowlist boundary both ways');
167
+ const renamePaths = gitDiffPaths(repo, base, renamed);
168
+ for (const file of [
169
+ 'docs/move-to-code.md', 'src/moved-from-docs.md',
170
+ 'src/move-to-docs.js', 'docs/moved-from-code.js',
171
+ ]) assert.ok(renamePaths.includes(file), `--no-renames reports ${file}`);
172
+ assert.equal(runClassifier('pull_request', base, renamed, repo), 'full');
173
+
174
+ const unusual = process.platform === 'win32' ? 'docs/space and name.md' : 'docs/space and\nnewline.md';
175
+ write(unusual, 'valid Git filename');
176
+ const unusualHead = commit('add unusual documentation filename');
177
+ assert.deepEqual(gitDiffPaths(repo, renamed, unusualHead), [unusual]);
178
+ assert.equal(runClassifier('pull_request', renamed, unusualHead, repo), 'docs-only');
179
+ assert.equal(runClassifier('push', renamed, unusualHead, repo), 'full');
180
+ } finally {
181
+ fs.rmSync(repo, { recursive: true, force: true });
182
+ }
183
+ });
184
+
185
+ test('the workflow gates only self-regression and fails open on every uncertain dependency/output state', () => {
186
+ const workflowFile = '.github/workflows/ci.yml';
187
+ const workflowText = fs.readFileSync(path.join(ROOT, workflowFile), 'utf8');
188
+ const beforeText = baselineFile(workflowFile);
189
+ const workflow = yaml.load(workflowText);
190
+ const before = yaml.load(beforeText);
191
+
192
+ assert.equal(workflow.name, before.name);
193
+ assert.deepEqual(workflow.on, before.on, 'push, pull_request, and reusable-workflow triggers stay unchanged');
194
+ assert.deepEqual(workflow.permissions, before.permissions);
195
+ assert.deepEqual(workflow.concurrency, before.concurrency);
196
+ assert.deepEqual(
197
+ Object.keys(workflow.jobs).sort(),
198
+ [...Object.keys(before.jobs), CHANGE_SCOPE_JOB].sort(),
199
+ 'only the classifier job is added; existing job ids remain present',
200
+ );
201
+ for (const [jobId, original] of Object.entries(before.jobs)) {
202
+ const current = workflow.jobs[jobId];
203
+ if (jobId === 'self-regression') {
204
+ const { if: _condition, needs: _needs, ...unchanged } = current;
205
+ assert.deepEqual(unchanged, original, 'self-regression name, matrix, steps, and runtime stay unchanged');
206
+ } else {
207
+ assert.deepEqual(current, original, `${jobId} stays unchanged`);
208
+ }
209
+ }
210
+
211
+ const classifier = workflow.jobs[CHANGE_SCOPE_JOB];
212
+ assert.equal(classifier.if, "${{ github.event_name == 'pull_request' }}");
213
+ assert.deepEqual(classifier.outputs, { scope: '${{ steps.scope.outputs.scope }}' });
214
+ const checkout = classifier.steps.find(step => step.uses === 'actions/checkout@v7');
215
+ assert.equal(checkout.with['fetch-depth'], 0, 'the classifier has complete Git history');
216
+ const node = classifier.steps.find(step => step.uses === 'actions/setup-node@v7');
217
+ assert.equal(node.with['node-version'], 24);
218
+ const scope = classifier.steps.find(step => step.id === 'scope');
219
+ assert.equal(scope.env.GITHUB_EVENT_NAME, undefined, 'the runner-provided GITHUB_EVENT_NAME is not overwritten');
220
+ assert.equal(scope.env.PR_BASE_SHA, '${{ github.event.pull_request.base.sha }}');
221
+ assert.equal(scope.env.PR_HEAD_SHA, '${{ github.event.pull_request.head.sha }}');
222
+ assert.match(scope.run, /node scripts\/ci-change-scope\.js "\$GITHUB_EVENT_NAME" "\$PR_BASE_SHA" "\$PR_HEAD_SHA"/);
223
+ assert.match(scope.run, /printf 'scope=%s\\n' "\$scope" >> "\$GITHUB_OUTPUT"/);
224
+ const selfRegressionIf = workflow.jobs['self-regression'].if;
225
+ assert.ok(selfRegressionIf.includes('!cancelled()'), 'workflow cancellation must disable self-regression');
226
+ assert.ok(!selfRegressionIf.includes('always()'), 'always() keeps self-regression eligible during cancellation');
227
+ assert.equal(selfRegressionIf, SELF_REGRESSION_IF, 'the full fallback predicate stays exact');
228
+ assert.deepEqual(workflow.jobs['self-regression'].needs, [CHANGE_SCOPE_JOB]);
229
+
230
+ const gateCases = [
231
+ ['successful docs-only classifier', false, 'success', 'docs-only', false],
232
+ ['successful full classifier', false, 'success', 'full', true],
233
+ ['partial producer output then failure', false, 'failure', 'docs-only', true],
234
+ ['missing job output', false, 'success', undefined, true],
235
+ ['malformed job output', false, 'success', 'docs_only', true],
236
+ ['failed classifier dependency', false, 'failure', undefined, true],
237
+ ['failed classifier with full output', false, 'failure', 'full', true],
238
+ ['skipped classifier dependency', false, 'skipped', undefined, true],
239
+ ['cancelled classifier dependency while workflow continues', false, 'cancelled', 'docs-only', true],
240
+ ['cancelled workflow with successful docs-only classifier', true, 'success', 'docs-only', false],
241
+ ['cancelled workflow with failed classifier', true, 'failure', 'full', false],
242
+ ];
243
+ for (const [label, workflowCancelled, result, output, expected] of gateCases) {
244
+ assert.equal(shouldRunSelfRegression(workflowCancelled, result, output), expected, label);
245
+ }
246
+
247
+ const releaseFile = '.github/workflows/release.yml';
248
+ const governanceFile = '.github/workflows/doc-governance.yml';
249
+ assert.equal(fs.readFileSync(path.join(ROOT, releaseFile), 'utf8'), baselineFile(releaseFile));
250
+ assert.equal(fs.readFileSync(path.join(ROOT, governanceFile), 'utf8'), baselineFile(governanceFile));
251
+ const release = yaml.load(fs.readFileSync(path.join(ROOT, releaseFile), 'utf8'));
252
+ assert.deepEqual(release.on.push.branches, ['main']);
253
+ assert.ok(Object.hasOwn(release.on, 'workflow_dispatch'));
254
+ assert.equal(release.jobs.gate.uses, './.github/workflows/ci.yml');
255
+ assert.equal(classifyChangeSet('push', 'a'.repeat(40), 'b'.repeat(40), { runGit: unusedGitForWorkflow }), 'full');
256
+ });
257
+
258
+ function unusedGitForWorkflow() {
259
+ throw new Error('the release caller is a push/dispatch, so no PR diff may authorize a skip');
260
+ }
@@ -0,0 +1,121 @@
1
+ 'use strict';
2
+
3
+ // Component tests for the script-generated hand-off file (#233 / #409 L0).
4
+ // The generator writes a Markdown work order whose first bytes are a short YAML
5
+ // header; these tests pin the round-trip and the three rejection paths.
6
+
7
+ const assert = require('node:assert');
8
+ const { test } = require('node:test');
9
+ const { execFileSync } = require('node:child_process');
10
+ const fs = require('node:fs');
11
+ const os = require('node:os');
12
+ const path = require('node:path');
13
+
14
+ const SCRIPT = path.join(__dirname, '..', 'scripts', 'handoff-file.js');
15
+ const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-handoff-'));
16
+
17
+ function run(args) {
18
+ return execFileSync(process.execPath, [SCRIPT, ...args], { encoding: 'utf8' });
19
+ }
20
+
21
+ function expectFailure(args) {
22
+ try {
23
+ run(args);
24
+ } catch (err) {
25
+ return String(err.stderr || err.message);
26
+ }
27
+ throw new Error(`expected failure for: ${args.join(' ')}`);
28
+ }
29
+
30
+ test('new writes a header that header round-trips back', () => {
31
+ const out = path.join(tempRoot, 'roundtrip.md');
32
+ run([
33
+ 'new',
34
+ '--kind', 'implement',
35
+ '--title', 'Cache fix',
36
+ '--summary', 'Keep the read cache warm across restarts',
37
+ '--out', out,
38
+ '--writes', 'a.js,b.js',
39
+ '--gate', 'node --test passes',
40
+ '--report', 'reports/R.md',
41
+ ]);
42
+ assert.deepStrictEqual(JSON.parse(run(['header', out])), {
43
+ 'harness-handoff': 1,
44
+ kind: 'implement',
45
+ title: 'Cache fix',
46
+ summary: 'Keep the read cache warm across restarts',
47
+ writes: ['a.js', 'b.js'],
48
+ gate: 'node --test passes',
49
+ report: 'reports/R.md',
50
+ });
51
+ const body = fs.readFileSync(out, 'utf8');
52
+ for (const section of ['## Scope anchor', '## Task', '## Write-set', '## Verification', '## Report']) {
53
+ assert.ok(body.includes(section), `body is missing ${section}`);
54
+ }
55
+ assert.ok(body.trimEnd().endsWith('-->'), 'body should end with the pending status comment');
56
+ assert.strictEqual(run(['check', out]).trim().endsWith('ok (kind=implement)'), true);
57
+ });
58
+
59
+ test('a summary longer than 200 characters is rejected', () => {
60
+ const out = path.join(tempRoot, 'long-summary.md');
61
+ const stderr = expectFailure([
62
+ 'new',
63
+ '--kind', 'test',
64
+ '--title', 'Too long',
65
+ '--summary', 'a'.repeat(201),
66
+ '--out', out,
67
+ ]);
68
+ assert.match(stderr, /200 characters/);
69
+ assert.strictEqual(fs.existsSync(out), false);
70
+ });
71
+
72
+ test('a file without a header is rejected', () => {
73
+ const out = path.join(tempRoot, 'no-header.md');
74
+ fs.writeFileSync(out, '# Just prose\n', 'utf8');
75
+ assert.match(expectFailure(['header', out]), /no handoff header/);
76
+ assert.match(expectFailure(['check', out]), /no handoff header/);
77
+ });
78
+
79
+ test('a header larger than 2 KB is rejected', () => {
80
+ const out = path.join(tempRoot, 'too-large.md');
81
+ fs.writeFileSync(out, `---\nharness-handoff: 1\nkind: implement\ntitle: "${'a'.repeat(3000)}"\n---\n`, 'utf8');
82
+ assert.match(expectFailure(['header', out]), /exceeds 2048 bytes/);
83
+ assert.match(expectFailure(['check', out]), /exceeds 2048 bytes/);
84
+ });
85
+
86
+ test('values containing ":" and "#" survive the round-trip', () => {
87
+ const out = path.join(tempRoot, 'punct.md');
88
+ run([
89
+ 'new',
90
+ '--kind', 'question',
91
+ '--title', 'Fix: cache #1',
92
+ '--summary', 'Why: it drops keys #2',
93
+ '--out', out,
94
+ '--gate', 'reviewer #A signs off: yes',
95
+ ]);
96
+ const header = JSON.parse(run(['header', out]));
97
+ assert.strictEqual(header.title, 'Fix: cache #1');
98
+ assert.strictEqual(header.summary, 'Why: it drops keys #2');
99
+ assert.strictEqual(header.gate, 'reviewer #A signs off: yes');
100
+ });
101
+
102
+ test('new refuses a header it would write larger than 2 KB', () => {
103
+ const out = path.join(tempRoot, 'new-too-large.md');
104
+ const stderr = expectFailure([
105
+ 'new',
106
+ '--kind', 'implement',
107
+ '--title', 'a'.repeat(3000),
108
+ '--summary', 'S',
109
+ '--out', out,
110
+ ]);
111
+ assert.match(stderr, /exceeds 2048 bytes/);
112
+ assert.strictEqual(fs.existsSync(out), false);
113
+ });
114
+
115
+ test('an unknown key is rejected', () => {
116
+ const out = path.join(tempRoot, 'unknown-key.md');
117
+ run(['new', '--kind', 'design', '--title', 'T', '--summary', 'S', '--out', out]);
118
+ const body = fs.readFileSync(out, 'utf8').replace('summary: S', 'summary: S\nmystery: 7');
119
+ fs.writeFileSync(out, body, 'utf8');
120
+ assert.match(expectFailure(['check', out]), /unknown header key/);
121
+ });