harness-everything 0.51.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 (83) 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 +34 -0
  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-system-one-contract.test.js +9 -2
  12. package/ci/mechanism-system-one-curves.test.js +206 -0
  13. package/ci/mechanism-system-one-cycle.test.js +585 -0
  14. package/ci/mechanism-system-one-evaluation.test.js +32 -5
  15. package/ci/mechanism-system-one-handoff-input.test.js +208 -0
  16. package/ci/mechanism-system-one-install.test.js +202 -77
  17. package/ci/mechanism-system-one-live.test.js +361 -0
  18. package/ci/mechanism-system-one-relevance.test.js +11 -1
  19. package/ci/mechanism-system-one-train.test.js +136 -53
  20. package/ci/system-one-adapter-test.py +331 -0
  21. package/ci/system-one-train-test.py +116 -24
  22. package/docs/adr/EVID-001.md +123 -0
  23. package/docs/adr/ROUTE-001-error-lesson-delivery.md +305 -0
  24. package/docs/governed-index.md +2 -0
  25. package/docs/routing.md +2 -2
  26. package/docs/system-one-cycle.md +68 -0
  27. package/docs/system-one-observations.md +9 -8
  28. package/docs/system-one-routing.md +163 -115
  29. package/docs/system-one-suggestion-gates.md +6 -8
  30. package/docs/system-one-training.md +44 -7
  31. package/docs/workflow-runtime.md +19 -0
  32. package/harness-everything/SKILL.md +1 -1
  33. package/harness-everything/scripts/kernel-router.js +2 -1
  34. package/harness-everything/scripts/system-one/contract.js +19 -15
  35. package/harness-everything/scripts/system-one/cua_adapter.py +211 -17
  36. package/harness-everything/scripts/system-one/evaluate.js +4 -9
  37. package/harness-everything/scripts/system-one/handoff-input.js +76 -0
  38. package/harness-everything/scripts/system-one/install.js +281 -113
  39. package/harness-everything/scripts/system-one/manifest.js +58 -0
  40. package/harness-everything/scripts/system-one/provider.js +96 -2
  41. package/harness-everything/scripts/system-one/resident.js +47 -1
  42. package/harness-everything/scripts/system-one/router.js +80 -1
  43. package/harness-everything/scripts/tier-router.js +21 -6
  44. package/hooks/scripts/lib/observations.js +43 -4
  45. package/opencode-plugin/plugin.json +1 -1
  46. package/package.json +1 -1
  47. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  48. package/plugins/harness-everything/hooks/scripts/lib/observations.js +43 -4
  49. package/plugins/harness-everything/plugin.json +1 -1
  50. package/plugins/harness-everything/scripts/handoff-file.js +223 -0
  51. package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
  52. package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +2 -1
  53. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/contract.js +19 -15
  54. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +211 -17
  55. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/evaluate.js +4 -9
  56. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/handoff-input.js +76 -0
  57. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +281 -113
  58. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/manifest.js +58 -0
  59. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +96 -2
  60. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/resident.js +47 -1
  61. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/router.js +80 -1
  62. package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +21 -6
  63. package/sbom.cdx.json +7 -7
  64. package/scripts/ci-change-scope.js +59 -0
  65. package/scripts/handoff-file.js +223 -0
  66. package/scripts/sync-openai-plugin.js +4 -0
  67. package/scripts/system-one-calibrate.js +108 -41
  68. package/scripts/system-one-curves.js +332 -0
  69. package/scripts/system-one-cycle/adjudication-input.js +65 -0
  70. package/scripts/system-one-cycle/build.js +165 -0
  71. package/scripts/system-one-cycle/collect.js +50 -0
  72. package/scripts/system-one-cycle/common.js +137 -0
  73. package/scripts/system-one-cycle/engines.js +62 -0
  74. package/scripts/system-one-cycle/evaluate.js +70 -0
  75. package/scripts/system-one-cycle/judge.js +106 -0
  76. package/scripts/system-one-cycle/label.js +59 -0
  77. package/scripts/system-one-cycle/package.js +173 -0
  78. package/scripts/system-one-cycle/score.py +111 -0
  79. package/scripts/system-one-cycle/train.js +136 -0
  80. package/scripts/system-one-cycle.js +131 -0
  81. package/scripts/system-one-observations-export.js +29 -6
  82. package/scripts/system-one-observations-review.js +4 -5
  83. package/scripts/system-one-train.py +117 -61
@@ -12,30 +12,34 @@ const { spawnSync, execFileSync } = require('child_process');
12
12
  const ROOT = path.resolve(__dirname, '..');
13
13
  const lib = require(path.join(ROOT, 'hooks/scripts/lib/observations.js'));
14
14
  const HOOK = path.join(ROOT, 'hooks/scripts/observation-hook.js');
15
+ const ROUTER = path.join(ROOT, 'harness-everything/scripts/kernel-router.js');
15
16
  const EXPORTER = path.join(ROOT, 'scripts/system-one-observations-export.js');
16
17
  const REVIEW = path.join(ROOT, 'scripts/system-one-observations-review.js');
18
+ const { getWorkspaceKey } = require(path.join(ROOT, 'scripts/lib/workspace.js'));
17
19
  let failures = 0;
18
20
  function test(name, fn) {
19
21
  try { fn(); console.log(` PASS ${name}`); } catch (error) { failures++; console.error(` FAIL ${name}\n ${error.stack.split('\n').slice(0, 3).join('\n ')}`); }
20
22
  }
21
23
 
22
- const LABEL = '<!-- harness-label {"v":1,"validity":"actionable","contextDependent":false,"tier":"tier2","intents":["fix","test"],"workflow":"iterative-single","skills":["tdd"]} -->';
24
+ const LABEL = '<!-- harness-label {"v":1,"validity":"actionable","tier":"tier2","intents":["fix","test"],"workflow":"iterative-single","skills":["tdd"]} -->';
25
+ const LEGACY_LABEL = '<!-- harness-label {"v":1,"validity":"actionable","contextDependent":false,"tier":"tier2","intents":["fix","test"],"workflow":"iterative-single","skills":["tdd"]} -->';
23
26
 
24
27
  test('label line parses and validates', () => {
25
28
  const parsed = lib.parseLabelLine(`Done.\n\n${LABEL}\n`);
26
- assert.deepStrictEqual(parsed.label, { v: 1, validity: 'actionable', contextDependent: false, tier: 'tier2',
29
+ assert.deepStrictEqual(parsed.label, { v: 1, validity: 'actionable', tier: 'tier2',
27
30
  intents: ['fix', 'test'], workflow: 'iterative-single', skills: ['tdd'] });
31
+ assert.deepStrictEqual(lib.parseLabelLine(LEGACY_LABEL).label, parsed.label, 'legacy field is accepted but ignored');
28
32
  assert.strictEqual(lib.parseLabelLine('no label here').label, null);
29
33
  assert.strictEqual(lib.parseLabelLine('no label here').reason, 'label-missing');
30
34
  assert.strictEqual(lib.parseLabelLine('<!-- harness-label {bad json} -->').reason, 'label-unparseable');
31
- const unknown = lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"actionable","contextDependent":false,"tier":"tier9","intents":[],"workflow":null,"skills":[]} -->');
35
+ const unknown = lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"actionable","tier":"tier9","intents":[],"workflow":null,"skills":[]} -->');
32
36
  assert.strictEqual(unknown.label, null);
33
37
  assert.strictEqual(unknown.reason, 'label-invalid');
34
- const tooMany = lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"actionable","contextDependent":false,"tier":null,"intents":["fix","test","docs","plan"],"workflow":null,"skills":[]} -->');
38
+ const tooMany = lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"actionable","tier":null,"intents":["fix","test","docs","plan"],"workflow":null,"skills":[]} -->');
35
39
  assert.strictEqual(tooMany.reason, 'label-invalid', 'at most three intents');
36
40
  const two = lib.parseLabelLine(`${LABEL.replace('tier2', 'tier1')}\nmore\n${LABEL}`);
37
41
  assert.strictEqual(two.label.tier, 'tier2', 'the last label line wins');
38
- const invalid = lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"invalid","contextDependent":true,"tier":null,"intents":[],"workflow":null,"skills":[]} -->');
42
+ const invalid = lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"invalid","tier":null,"intents":[],"workflow":null,"skills":[]} -->');
39
43
  assert.strictEqual(invalid.label.validity, 'invalid');
40
44
  });
41
45
 
@@ -112,8 +116,11 @@ function sandbox() {
112
116
  const repo = path.join(dir, 'repo');
113
117
  fs.mkdirSync(repo);
114
118
  execFileSync('git', ['init', '-q', repo]);
115
- const env = { ...process.env, HARNESS_OBSERVATIONS_DIR: store, HARNESS_STATE_ROOT: path.join(dir, 'state') };
119
+ const env = { ...process.env, HARNESS_OBSERVATIONS_DIR: store, HARNESS_STATE_ROOT: path.join(dir, 'state'),
120
+ HARNESS_STATE_HOME: path.join(dir, 'harness-state') };
116
121
  delete env.HARNESS_OBSERVATIONS;
122
+ delete env.HARNESS_SYSTEM_ONE_MODE;
123
+ delete env.HARNESS_ROUTER_CONTRACT_PATH;
117
124
  // Fixtures choose their own host; never inherit the invoking agent's.
118
125
  for (const key of ['CLAUDE_PLUGIN_ROOT', 'CLAUDECODE', 'CLAUDE_CODE_ENTRYPOINT', 'CLAUDE', 'CODEX_HOME', 'CODEX_THREAD_ID']) delete env[key];
119
126
  return { dir, store, repo, env };
@@ -126,6 +133,32 @@ function hook(env, payload) {
126
133
  return r;
127
134
  }
128
135
 
136
+ function routeWorkflow(s, sessionId, systemOne) {
137
+ const routed = spawnSync(process.execPath, [ROUTER], {
138
+ input: JSON.stringify({ session_id: sessionId, cwd: s.repo, prompt: 'update the observation fixture' }),
139
+ env: s.env, cwd: ROOT, encoding: 'utf8', timeout: 15000,
140
+ });
141
+ assert.strictEqual(routed.status, 0, `router exit ${routed.status}: ${routed.stderr}`);
142
+ const file = path.join(s.env.HARNESS_STATE_HOME, 'workspaces', getWorkspaceKey(s.repo), 'state',
143
+ 'sessions', sessionId, 'workflow-run.json');
144
+ assert(fs.existsSync(file), 'the router persists workflow-run.json');
145
+ const run = JSON.parse(fs.readFileSync(file, 'utf8'));
146
+ assert(run.workflowPlan && typeof run.workflowPlan === 'object', 'the router writes a workflowPlan object');
147
+ if (systemOne !== undefined) {
148
+ run.workflowPlan.systemOne = systemOne;
149
+ fs.writeFileSync(file, JSON.stringify(run));
150
+ }
151
+ return file;
152
+ }
153
+
154
+ function observeWithRouter(s, sessionId, systemOne, label = LABEL) {
155
+ routeWorkflow(s, sessionId, systemOne);
156
+ const base = { session_id: sessionId, cwd: s.repo };
157
+ hook(s.env, { ...base, hook_event_name: 'UserPromptSubmit', prompt: 'capture observation metadata' });
158
+ hook(s.env, { ...base, hook_event_name: 'Stop', last_assistant_message: `done\n${label}` });
159
+ return records(s.store).find(record => record.writer.sessionId === sessionId);
160
+ }
161
+
129
162
  function records(store) {
130
163
  const file = path.join(store, 'observations-index.json');
131
164
  if (!fs.existsSync(file)) return [];
@@ -169,7 +202,7 @@ test('second turn keeps the previous final message; missing label is recorded, n
169
202
  hook(s.env, { ...base, hook_event_name: 'UserPromptSubmit', prompt: 'run the tests' });
170
203
  hook(s.env, { ...base, hook_event_name: 'Stop', last_assistant_message: 'All 12 tests pass. Want me to commit?' });
171
204
  hook(s.env, { ...base, hook_event_name: 'UserPromptSubmit', prompt: 'yes' });
172
- hook(s.env, { ...base, hook_event_name: 'Stop', last_assistant_message: `Committed.\n${LABEL.replace('"actionable","contextDependent":false', '"invalid","contextDependent":true')}` });
205
+ hook(s.env, { ...base, hook_event_name: 'Stop', last_assistant_message: `Committed.\n${LABEL.replace('"actionable"', '"invalid"')}` });
173
206
  const recs = records(s.store);
174
207
  assert.strictEqual(recs.length, 2);
175
208
  assert.strictEqual(recs[0].selfReport, null);
@@ -177,7 +210,7 @@ test('second turn keeps the previous final message; missing label is recorded, n
177
210
  const text = JSON.parse(fs.readFileSync(path.join(s.store, 'text', `${recs[1].contentSha256}.json`), 'utf8'));
178
211
  assert.strictEqual(text.prompt, 'yes');
179
212
  assert(text.previous.includes('Want me to commit?'));
180
- assert.strictEqual(recs[1].selfReport.contextDependent, true);
213
+ assert.strictEqual(recs[1].selfReport.validity, 'invalid');
181
214
  });
182
215
 
183
216
  test('Codex turn: final message from the rollout transcript, apply_patch counted', () => {
@@ -227,7 +260,7 @@ function writeFixtureStore(s) {
227
260
  { sid: 'e1', prompt: 'git status', label: LABEL.replace('"tier2"', '"tier1"'), tools: [] },
228
261
  { sid: 'e2', prompt: 'fix the flaky parser test', label: LABEL, tools: [['Edit', 'a.js'], ['Edit', 'b.js']] },
229
262
  { sid: 'e3', prompt: 'add a csv export command', label: LABEL.replace('"tier2"', '"tier3"').replace('["fix","test"]', '["feature"]'), tools: [['Edit', 'c.js']] },
230
- { sid: 'e4', prompt: 'go', label: LABEL.replace('"actionable","contextDependent":false', '"invalid","contextDependent":true'), tools: [] },
263
+ { sid: 'e4', prompt: 'go', label: LABEL.replace('"actionable"', '"invalid"'), tools: [] },
231
264
  ];
232
265
  for (const t of turns) {
233
266
  hook(s.env, { ...base, session_id: t.sid, hook_event_name: 'UserPromptSubmit', prompt: t.prompt });
@@ -261,6 +294,73 @@ test('exporter derives labels, splits by time and reports agreement', () => {
261
294
  assert(!fs.readFileSync(path.join(out, 'export-report.json'), 'utf8').includes('parser'), 'the report holds no text');
262
295
  });
263
296
 
297
+ test('router System One state is copied, bounded and fail-open', () => {
298
+ const absent = sandbox();
299
+ const absentRecord = observeWithRouter(absent, 'system-one-absent', undefined);
300
+ assert.strictEqual(absentRecord.router.systemOne, null, 'an ordinary router artifact has no System One field');
301
+
302
+ const bounded = sandbox();
303
+ const scoredIntents = Object.fromEntries(Array.from({ length: 14 }, (_, index) => [`intent-${index}`, index === 0 ? -1 : index === 1 ? 0.5 : 2]));
304
+ const oversized = {
305
+ version: 'v'.repeat(70), sha256: '0123456789abcdef', mode: 'live',
306
+ validity: { invalid: 1.5, ignored: 0.75 }, intents: scoredIntents,
307
+ tier: { tier1: -1, tier2: 0.4, tier3: 2, ignored: 0.75 },
308
+ decision: { validity: 'actionable', intents: ['d'.repeat(70), ...Array.from({ length: 13 }, (_, index) => `decision-${index}`)], tier: 'tier2', ignored: 'drop' },
309
+ ignored: 'drop',
310
+ };
311
+ const boundedRecord = observeWithRouter(bounded, 'system-one-oversized', oversized);
312
+ assert.deepStrictEqual(boundedRecord.router.systemOne, {
313
+ version: 'v'.repeat(64), sha256: '0123456789abcdef', mode: 'live',
314
+ validity: { invalid: 1 },
315
+ intents: Object.fromEntries(Array.from({ length: 12 }, (_, index) => [`intent-${index}`, index === 0 ? 0 : index === 1 ? 0.5 : 1])),
316
+ tier: { tier1: 0, tier2: 0.4, tier3: 1 },
317
+ decision: { validity: 'actionable', intents: ['d'.repeat(64), ...Array.from({ length: 11 }, (_, index) => `decision-${index}`)], tier: 'tier2' },
318
+ });
319
+
320
+ const malformed = sandbox();
321
+ const malformedRecord = observeWithRouter(malformed, 'system-one-malformed', {
322
+ version: 'bad', sha256: 'bad-hash', mode: 'shadow', validity: { invalid: '0.4' },
323
+ intents: null, tier: null, decision: { validity: 'maybe', intents: [], tier: 'tier9' },
324
+ });
325
+ assert.strictEqual(malformedRecord.router.systemOne, null, 'malformed router output is ignored without blocking the turn');
326
+ });
327
+
328
+ test('export includes only System One decision data and reports tier agreement per version', () => {
329
+ const s = sandbox();
330
+ const rows = [
331
+ { sid: 'system-one-a1', version: 'checkpoint-a', decisionTier: 'tier1', selfTier: 'tier1' },
332
+ { sid: 'system-one-a2', version: 'checkpoint-a', decisionTier: 'tier3', selfTier: 'tier2' },
333
+ { sid: 'system-one-b1', version: 'checkpoint-b', decisionTier: 'tier2', selfTier: 'tier2' },
334
+ { sid: 'system-one-none', version: null, decisionTier: null, selfTier: 'tier2' },
335
+ ];
336
+ const ids = new Map();
337
+ for (const item of rows) {
338
+ const systemOne = item.version === null ? undefined : {
339
+ version: item.version, sha256: '0123456789abcdef', mode: 'live',
340
+ validity: { invalid: 0.918273645 }, intents: null, tier: null,
341
+ decision: { validity: 'actionable', intents: ['feature'], tier: item.decisionTier },
342
+ };
343
+ const label = LABEL.replace('"tier2"', `"${item.selfTier}"`);
344
+ ids.set(item.sid, observeWithRouter(s, item.sid, systemOne, label).id);
345
+ }
346
+ const out = path.join(s.dir, 'system-one-export');
347
+ const exported = spawnSync(process.execPath, [EXPORTER, '--store', s.store, '--out', out], { encoding: 'utf8', env: s.env });
348
+ assert.strictEqual(exported.status, 0, exported.stderr);
349
+ const labels = fs.readFileSync(path.join(out, 'labels-observed.jsonl'), 'utf8').trim().split('\n').map(JSON.parse);
350
+ const byId = Object.fromEntries(labels.map(label => [label.id, label]));
351
+ assert.deepStrictEqual(byId[ids.get('system-one-a1')].systemOne, {
352
+ version: 'checkpoint-a', sha256: '0123456789abcdef', mode: 'live',
353
+ decision: { validity: 'actionable', intents: ['feature'], tier: 'tier1' },
354
+ });
355
+ assert.strictEqual(byId[ids.get('system-one-none')].systemOne, null);
356
+ assert(!fs.readFileSync(path.join(out, 'labels-observed.jsonl'), 'utf8').includes('0.918273645'), 'probability scores stay private');
357
+ const report = JSON.parse(fs.readFileSync(path.join(out, 'export-report.json'), 'utf8'));
358
+ assert.deepStrictEqual(report.systemOne.versions, {
359
+ 'checkpoint-a': { rows: 2, tierAgreement: { matches: 1, comparisons: 2, rate: 0.5 } },
360
+ 'checkpoint-b': { rows: 1, tierAgreement: { matches: 1, comparisons: 1, rate: 1 } },
361
+ });
362
+ });
363
+
264
364
  test('exporter can select post-cutoff rows with self-reported labels for training', () => {
265
365
  const s = sandbox();
266
366
  writeFixtureStore(s);
@@ -446,14 +546,18 @@ test('failed tool attempts are not counted as writes or loads', () => {
446
546
  assert.deepStrictEqual(lib.contradictions(r.selfReport, r.behavior), []);
447
547
  });
448
548
 
449
- test('owner review overrides context dependence, explicit false included', () => {
549
+ test('legacy context fields are ignored by export and review', () => {
450
550
  const s = sandbox();
451
551
  const base = { cwd: s.repo };
452
552
  hook(s.env, { ...base, session_id: 'cd-1', hook_event_name: 'UserPromptSubmit', prompt: 'continue' });
453
- hook(s.env, { ...base, session_id: 'cd-1', hook_event_name: 'Stop', last_assistant_message: `ok\n${LABEL.replace('"contextDependent":false', '"contextDependent":true')}` });
553
+ hook(s.env, { ...base, session_id: 'cd-1', hook_event_name: 'Stop', last_assistant_message: `ok\n${LEGACY_LABEL}` });
454
554
  hook(s.env, { ...base, session_id: 'cd-2', hook_event_name: 'UserPromptSubmit', prompt: 'rename foo to bar in util.js' });
455
555
  hook(s.env, { ...base, session_id: 'cd-2', hook_event_name: 'Stop', last_assistant_message: 'no label' });
456
556
  const [a, b] = records(s.store);
557
+ const indexPath = path.join(s.store, 'observations-index.json');
558
+ const index = JSON.parse(fs.readFileSync(indexPath, 'utf8'));
559
+ index.records.find(record => record.id === a.id).selfReport.contextDependent = true;
560
+ fs.writeFileSync(indexPath, JSON.stringify(index));
457
561
  const review = path.join(s.dir, 'decisions.json');
458
562
  fs.writeFileSync(review, JSON.stringify({ schemaVersion: 1, review: 'harness-observation-review', decisions: [
459
563
  { id: a.id, contextDependent: false }, { id: b.id, validity: 'actionable', contextDependent: false, tier: 'tier2' }] }));
@@ -461,15 +565,12 @@ test('owner review overrides context dependence, explicit false included', () =>
461
565
  const e = spawnSync('node', [EXPORTER, '--store', s.store, '--out', out, '--owner-review', review], { encoding: 'utf8', env: s.env });
462
566
  assert.strictEqual(e.status, 0, e.stderr);
463
567
  const labels = fs.readFileSync(path.join(out, 'labels-observed.jsonl'), 'utf8').trim().split('\n').map(JSON.parse);
464
- assert.strictEqual(labels.find(l => l.id === a.id).contextDependent, false);
465
- assert.deepStrictEqual((({ validity, contextDependent, tier }) => ({ validity, contextDependent, tier }))(labels.find(l => l.id === b.id)),
466
- { validity: 'actionable', contextDependent: false, tier: 'tier2' });
467
- fs.writeFileSync(review, JSON.stringify({ schemaVersion: 1, review: 'harness-observation-review', decisions: [{ id: a.id, contextDependent: 'no' }] }));
468
- const bad = spawnSync('node', [EXPORTER, '--store', s.store, '--out', out, '--owner-review', review], { encoding: 'utf8', env: s.env });
469
- assert.notStrictEqual(bad.status, 0, 'invalid owner decisions are rejected');
568
+ assert(!Object.hasOwn(labels.find(l => l.id === a.id), 'contextDependent'));
569
+ assert.deepStrictEqual((({ validity, tier }) => ({ validity, tier }))(labels.find(l => l.id === b.id)),
570
+ { validity: 'actionable', tier: 'tier2' });
470
571
  const html = path.join(s.dir, 'review.html');
471
572
  assert.strictEqual(spawnSync('node', [REVIEW, '--store', s.store, '--out', html], { encoding: 'utf8', env: s.env }).status, 0);
472
- assert(fs.readFileSync(html, 'utf8').includes('contextDependent'), 'the review page records context dependence');
573
+ assert(!fs.readFileSync(html, 'utf8').includes('contextDependent'), 'the review page no longer collects the removed field');
473
574
  });
474
575
 
475
576
  function agePending(store, sessionId, days) {
@@ -539,6 +640,8 @@ test('the label contract is the router output\'s last section and covers every t
539
640
  const last = sections[sections.length - 1];
540
641
  assert(/^=> TURN LABEL LINE/.test(last) && last.includes('harness-label'), 'the label contract is printed last');
541
642
  assert(/EVERY TURN/.test(last) && /null only when validity is invalid/.test(last));
643
+ assert(/cannot be understood from its own text and needs conversation context/.test(last));
644
+ assert(/agent-written dispatches and worker instructions are ordinary prompts/.test(last));
542
645
  const status = sections.find(x => x.startsWith('=> USER-VISIBLE HARNESS STATUS CONTRACT'));
543
646
  assert(status && !status.includes('harness-label'), 'not scoped under the non-trivial Harness Status contract');
544
647
  assert(/^14\. \*\*The turn label line is mandatory on every turn/m.test(fs.readFileSync(path.join(ROOT, 'AGENTS.md'), 'utf8')));
@@ -554,7 +657,7 @@ test('router/self agreement counts only turns where the router chose a tier', ()
554
657
  return { id: `r${k}`, source: 'observation', status: 'active', observedAt: new Date(now - (3 - k) * 1000).toISOString(),
555
658
  validUntil: new Date(now + 86400000).toISOString(), contentSha256: sha, host: 'claude', turn: 1, writer: { sessionId: `s${k}` },
556
659
  router: { tier: router }, behavior: lib.emptyBehavior(),
557
- selfReport: { v: 1, validity: 'actionable', contextDependent: false, tier: self, intents: [], workflow: null, skills: [] } };
660
+ selfReport: { v: 1, validity: 'actionable', tier: self, intents: [], workflow: null, skills: [] } };
558
661
  });
559
662
  fs.writeFileSync(path.join(s.store, 'observations-index.json'), JSON.stringify({ schemaVersion: 1, records: recs }));
560
663
  const out = path.join(s.dir, 'export');
@@ -565,16 +668,16 @@ test('router/self agreement counts only turns where the router chose a tier', ()
565
668
  });
566
669
 
567
670
  test('label slips seen live: unknown intents dropped, unterminated final line accepted', () => {
568
- const unknown = lib.parseLabelLine('ok\n<!-- harness-label {"v":1,"validity":"actionable","contextDependent":false,"tier":"tier1","intents":["lookup","git"],"workflow":null,"skills":[]} -->');
671
+ const unknown = lib.parseLabelLine('ok\n<!-- harness-label {"v":1,"validity":"actionable","tier":"tier1","intents":["lookup","git"],"workflow":null,"skills":[]} -->');
569
672
  assert.strictEqual(unknown.reason, null);
570
673
  assert.deepStrictEqual(unknown.label.intents, ['git']);
571
674
  assert.deepStrictEqual(unknown.label.unknownIntents, ['lookup']);
572
- const open = lib.parseLabelLine('M README.md\n\n<!-- harness-label {"v":1,"validity":"actionable","contextDependent":false,"tier":"tier1","intents":["git"],"workflow":null,"skills":[]}');
675
+ const open = lib.parseLabelLine('M README.md\n\n<!-- harness-label {"v":1,"validity":"actionable","tier":"tier1","intents":["git"],"workflow":null,"skills":[]}');
573
676
  assert.strictEqual(open.reason, null, 'a final label line missing its closing --> is accepted');
574
677
  assert.strictEqual(open.label.tier, 'tier1');
575
- const middle = lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"actionable","contextDependent":false,"tier":"tier1","intents":[],"workflow":null,"skills":[]}\nmore text');
678
+ const middle = lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"actionable","tier":"tier1","intents":[],"workflow":null,"skills":[]}\nmore text');
576
679
  assert.strictEqual(middle.label, null, 'an unterminated line is accepted only at the end');
577
- assert.strictEqual(lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"actionable","contextDependent":false,"tier":"tier9","intents":[],"workflow":null,"skills":[]} -->').reason, 'label-invalid');
680
+ assert.strictEqual(lib.parseLabelLine('<!-- harness-label {"v":1,"validity":"actionable","tier":"tier9","intents":[],"workflow":null,"skills":[]} -->').reason, 'label-invalid');
578
681
  });
579
682
 
580
683
  test('Codex router hook returns its contract as JSON additionalContext', () => {
@@ -604,6 +707,7 @@ test('hooks are registered for both hosts and the contract asks for the label li
604
707
  }
605
708
  const router = spawnSync('node', [path.join(ROOT, 'harness-everything/scripts/kernel-router.js'), 'refactor the logger module across the repo'], { encoding: 'utf8' });
606
709
  assert(router.stdout.includes('harness-label'), 'the router contract asks for the label line');
710
+ assert(!router.stdout.includes('contextDependent'), 'the router template omits the removed field');
607
711
  assert(fs.readFileSync(path.join(ROOT, 'AGENTS.md'), 'utf8').includes('harness-label'));
608
712
  assert(fs.readFileSync(path.join(ROOT, 'PRIVACY.md'), 'utf8').includes('HARNESS_OBSERVATIONS=off'));
609
713
  const telemetry = fs.readFileSync(path.join(ROOT, 'hooks/scripts/lib/telemetry.js'), 'utf8');
@@ -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
+ }