harness-everything 1.2.2 → 1.3.1

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 (147) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +29 -0
  4. package/ci/archive/325-prep/README.md +9 -2
  5. package/ci/archive/325-prep/doc-reconciliation-red.js +34 -8
  6. package/ci/fixtures/468-dispatch/agy-quota-PROVENANCE.md +19 -0
  7. package/ci/fixtures/468-dispatch/agy-quota-direct-individual.stderr +2 -0
  8. package/ci/fixtures/468-dispatch/agy-quota-direct-third-party.stderr +2 -0
  9. package/ci/fixtures/468-dispatch/agy-quota-exec-individual.log +3 -0
  10. package/ci/fixtures/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
  11. package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
  12. package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
  13. package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
  14. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  15. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
  16. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  17. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
  18. package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
  19. package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
  20. package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
  21. package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
  22. package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
  23. package/ci/fixtures/stop/fail-session-writes.js +109 -0
  24. package/ci/fixtures/workflow-contract/cases.json +3355 -0
  25. package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
  26. package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
  27. package/ci/mechanism-2an-workflow-replay.test.js +324 -0
  28. package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
  29. package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
  30. package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
  31. package/ci/mechanism-325-3b-preparation.test.js +208 -49
  32. package/ci/mechanism-325-3b-s1-review.test.js +20 -828
  33. package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
  34. package/ci/mechanism-325-f3-derived-views.test.js +140 -0
  35. package/ci/mechanism-341-opencode-lane.test.js +164 -284
  36. package/ci/mechanism-35-verification-contract.test.js +246 -0
  37. package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
  38. package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
  39. package/ci/mechanism-397-opencode-observations.test.js +151 -18
  40. package/ci/mechanism-468-dispatch-cli.test.js +1496 -4
  41. package/ci/mechanism-548-bigint-identity.test.js +531 -0
  42. package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
  43. package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
  44. package/ci/mechanism-553-p3-plan-start.test.js +212 -0
  45. package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
  46. package/ci/mechanism-553-stop.test.js +427 -0
  47. package/ci/mechanism-553-t2a-derive.test.js +110 -0
  48. package/ci/mechanism-553-t2c-derive.test.js +94 -0
  49. package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
  50. package/ci/mechanism-error-ledger-oracle.test.js +786 -3
  51. package/ci/mechanism-error-ledger-scan.test.js +981 -0
  52. package/ci/mechanism-outline-sanitizer.test.js +0 -8
  53. package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
  54. package/ci/mechanism-prb-outline-review.test.js +101 -3283
  55. package/ci/mechanism-report-writer.test.js +45 -0
  56. package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
  57. package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
  58. package/docs/doc-workflow-reconciliation.md +17 -2
  59. package/docs/document-lifecycle.md +6 -2
  60. package/docs/error-handling/details/c8-dispatch-cli.md +109 -13
  61. package/docs/platform-capabilities.md +35 -5
  62. package/error-ledger-bootstrap/SKILL.md +1 -1
  63. package/error-ledger-bootstrap/references/workflow.md +42 -7
  64. package/error-ledger-bootstrap/scripts/promote.js +8 -6
  65. package/error-ledger-bootstrap/scripts/scan.js +525 -12
  66. package/hooks/hooks.json +0 -46
  67. package/hooks/scripts/lib/workflow-obligations.js +0 -55
  68. package/hooks/scripts/state-persist.js +7 -95
  69. package/hooks/scripts/workflow-disposition.js +0 -2
  70. package/hooks/scripts/workflow-stop-gate.js +17 -30
  71. package/opencode-plugin/index.mjs +6 -70
  72. package/opencode-plugin/plugin.json +1 -1
  73. package/package.json +1 -1
  74. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  75. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  76. package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +0 -55
  77. package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
  78. package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
  79. package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
  80. package/plugins/harness-everything/plugin.json +1 -1
  81. package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +1 -1
  82. package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +42 -7
  83. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +8 -6
  84. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +525 -12
  85. package/sbom.cdx.json +7 -7
  86. package/scripts/dispatch.js +499 -87
  87. package/scripts/error-ledger-oracle.js +521 -27
  88. package/scripts/errors-sync.js +4 -3
  89. package/scripts/report-writer.js +4 -3
  90. package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
  91. package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
  92. package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
  93. package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
  94. package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
  95. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
  96. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
  97. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
  98. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
  99. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
  100. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
  101. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
  102. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
  103. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
  104. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
  105. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
  106. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
  107. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
  108. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
  109. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
  110. package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
  111. package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
  112. package/ci/lib/doc-reconciliation-file-spy.js +0 -23
  113. package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
  114. package/ci/lib/doc-reconciliation-replay.js +0 -104
  115. package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
  116. package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
  117. package/ci/mechanism-325-3b-s1.test.js +0 -188
  118. package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
  119. package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
  120. package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
  121. package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
  122. package/ci/mechanism-325-f4-invariants.test.js +0 -606
  123. package/ci/mechanism-325-f4-projections.test.js +0 -392
  124. package/ci/mechanism-325-f4-qualification.test.js +0 -228
  125. package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
  126. package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
  127. package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  128. package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  129. package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  130. package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  131. package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  132. package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  133. package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  134. package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  135. package/hooks/scripts/w6-state-operations.js +0 -239
  136. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  137. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  138. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  139. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  140. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  141. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  142. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  143. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  144. package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
  145. package/scripts/system-one-eval-laya.js +0 -112
  146. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
  147. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
@@ -6,7 +6,6 @@ const fs = require('node:fs');
6
6
  const os = require('node:os');
7
7
  const path = require('node:path');
8
8
  const { spawnSync } = require('node:child_process');
9
- const { _internals: providerInternals } = require('../hooks/scripts/lib/doc-reconciliation-provider');
10
9
 
11
10
  const ROOT = path.resolve(__dirname, '..');
12
11
  const SANITIZER = path.join(ROOT, 'benchmarks/results/live-host/claude-341-outline-dispatch-2026-10-28/sanitize-outline-capture.js');
@@ -66,13 +65,6 @@ try {
66
65
  assert.ok(mapped.every(token => token.length > 0 && !/\s/.test(token)), 'synthetic marker tokens must be nonempty and whitespace-free');
67
66
  assert.equal(mapped[0], mapped[1], 'equal originals must map to equal placeholders');
68
67
  assert.notEqual(mapped[0], mapped[2], 'different originals must map to distinct placeholders');
69
- for (const record of records) {
70
- for (const value of [record.tool_input?.prompt, record.tool_response?.stdout].filter(Boolean)) {
71
- for (const line of value.split(/\r?\n/).filter(line => line.startsWith('HARNESS_OUTLINE_DISPATCH_V1 '))) {
72
- assert.ok(providerInternals.parseOutlineDispatchPrompt(line), 'sanitized marker must retain the production parser grammar');
73
- }
74
- }
75
- }
76
68
  console.log('PASS sanitizer replaces repeated and overlapping marker tokens in nested exported strings');
77
69
  } finally {
78
70
  fs.rmSync(dir, { recursive: true, force: true });
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- // PR-A RED/GREEN contract for the full-corpus conflict-check producer.
4
+ // PR-A conflict-check CLI contract (T2-C #553: decoupled from E1 pilot/provider/adapter;
5
+ // runs all surviving CLI, lifecycle collection, and 3a evidence waiver controls on both
6
+ // source and packaged legs).
5
7
  const assert = require('node:assert/strict');
6
8
  const crypto = require('node:crypto');
7
9
  const fs = require('node:fs');
@@ -10,20 +12,10 @@ const path = require('node:path');
10
12
  const { execFileSync, spawnSync } = require('node:child_process');
11
13
 
12
14
  const ROOT = path.resolve(__dirname, '..');
13
- const DOC_CHECK = path.join(ROOT, 'harness-everything', 'scripts', 'doc-check.js');
14
- const PROVIDER = require(path.join(ROOT, 'hooks', 'scripts', 'lib', 'doc-reconciliation-provider.js'));
15
- const PILOT = require(path.join(ROOT, 'hooks', 'scripts', 'lib', 'doc-reconciliation-pilot.js'));
16
- const PRODUCER = require(path.join(ROOT, 'hooks', 'scripts', 'lib', 'doc-reconciliation-producer.js'));
17
- const EVENTS = require(path.join(ROOT, 'hooks', 'scripts', 'lib', 'doc-reconciliation-events.js'));
18
- const EVIDENCE = require(path.join(ROOT, 'harness-everything', 'scripts', 'doc-evidence.js'));
19
- const LIFECYCLE = require(path.join(ROOT, 'harness-everything', 'scripts', 'doc-lifecycle.js'));
20
- const REQUIREMENTS = [
21
- { id: 'req-docs', stepType: 'doc-change', summary: 'Update the ADR', acceptance: 'the normative change is reviewed' },
22
- { id: 'req-verify', stepType: 'verification', summary: 'Verify the ADR', acceptance: 'full-corpus conflict evidence is recorded' },
15
+ const LEGS = [
16
+ { name: 'source', dir: path.join(ROOT, 'harness-everything', 'scripts') },
17
+ { name: 'packaged', dir: path.join(ROOT, 'plugins', 'harness-everything', 'skills', 'harness-everything', 'scripts') },
23
18
  ];
24
- const PILOT_CONFIG_TEXT = JSON.stringify({
25
- governed: [{ path: 'docs/current/**', role: 'adr' }], legacy: [], domains: ['GRPH'],
26
- }, null, 2) + '\n';
27
19
  const CONFIG = '.agents/harness-everything/project-docs.json';
28
20
  const CONFIG_TEXT = JSON.stringify({
29
21
  governed: [{ path: 'docs/current/**', role: 'reference' }],
@@ -45,9 +37,6 @@ function git(root, args) {
45
37
  function reference(id, extra = '') {
46
38
  return `---\nrole: reference\nstatus: active\nid: ${id}\n${extra}---\n\n# ${id}\n\nA governed document.\n`;
47
39
  }
48
- function adr(id, body) {
49
- return `---\nid: ${id}\nrole: adr\nstatus: accepted\n---\n\n# ${id}\n\n## Decision\n\n${body}\n`;
50
- }
51
40
  function workspace(files, configText = CONFIG_TEXT) {
52
41
  const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'pra-conflict-check-')));
53
42
  roots.push(root);
@@ -58,8 +47,8 @@ function workspace(files, configText = CONFIG_TEXT) {
58
47
  git(root, ['-c', 'user.name=Harness Test', '-c', 'user.email=harness@example.invalid', '-c', 'commit.gpgsign=false', 'commit', '-q', '-m', 'baseline']);
59
48
  return { root, base: git(root, ['rev-parse', 'HEAD']) };
60
49
  }
61
- function runCheck(root, base, changed = ['docs/current/a.md'], extra = []) {
62
- return spawnSync(process.execPath, [DOC_CHECK, 'check', '--workspace', root, '--config', CONFIG,
50
+ function runCheck(leg, root, base, changed = ['docs/current/a.md'], extra = []) {
51
+ return spawnSync(process.execPath, [path.join(leg.dir, 'doc-check.js'), 'check', '--workspace', root, '--config', CONFIG,
63
52
  ...changed.flatMap(item => ['--changed-path', item]), '--base', base, ...extra],
64
53
  { cwd: root, encoding: 'utf8' });
65
54
  }
@@ -68,122 +57,25 @@ function report(result) {
68
57
  }
69
58
  function sha(text) { return crypto.createHash('sha256').update(text).digest('hex'); }
70
59
 
71
- function seedPilotScenario() {
72
- const baselineDoc = adr('GRPH-001', 'Checkout retries once.');
73
- const { root, base } = workspace({
74
- 'docs/current/a.md': baselineDoc,
75
- 'docs/current/b.md': adr('GRPH-002', 'The receipt is durable.'),
76
- }, PILOT_CONFIG_TEXT);
77
- write(root, 'docs/current/a.md', adr('GRPH-001', 'Checkout retries twice.'));
78
- const sessionId = 'pra-session';
79
- const workflowId = 'pra-workflow';
80
- const sessionDir = path.join(root, '.harness-session');
81
- fs.mkdirSync(sessionDir, { recursive: true });
82
- const plan = { strategySelection: 'selected', tier: 'tier2', strategy: 'iterative-single' };
83
- const context = {
84
- sessionId, sessionDir, root,
85
- workflow: { workflowId, revision: 1, state: 'pending', strategy: 'iterative-single', workflowPlan: plan },
86
- };
87
- const obligations = require(path.join(ROOT, 'hooks', 'scripts', 'lib', 'workflow-obligations.js'));
88
- obligations.initializePlanningContract(context, plan);
89
- obligations.recordPlanning(context, JSON.stringify(REQUIREMENTS), plan, 'iterative-single', 'one bounded documentation verification path');
90
- obligations.materializeExecutionObligations(context, plan);
91
- const loaded = obligations.loadObligationSet(context, plan);
92
- if (!loaded.set) throw new Error(`pilot fixture failed to load obligations: ${loaded.error}`);
93
- const previousPilot = process.env.HARNESS_DOC_RECONCILIATION_PILOT;
94
- process.env.HARNESS_DOC_RECONCILIATION_PILOT = '1';
95
- try { PILOT.captureBaseline(context); }
96
- finally {
97
- if (previousPilot === undefined) delete process.env.HARNESS_DOC_RECONCILIATION_PILOT;
98
- else process.env.HARNESS_DOC_RECONCILIATION_PILOT = previousPilot;
99
- }
100
- write(sessionDir, 'workflow-run.json', JSON.stringify({ workflowId, revision: 1, docReconciliationBaseline: context.workflow.docReconciliationBaseline }));
101
- return { root, base, context, plan, set: loaded.set, sessionId, workflowId, sessionDir };
102
- }
103
-
104
- function addHostCapture(scenario, payload, eventName = 'PostToolUse') {
105
- const capture = PROVIDER.buildCaptureRecord(payload, eventName, scenario.root);
106
- if (!capture) throw new Error(`capture builder did not accept ${eventName}`);
107
- capture.observedIdentity = PROVIDER.observedIdentityFor(scenario.sessionDir);
108
- PROVIDER.writeImmutableEvent(scenario.sessionDir, capture);
109
- PROVIDER.rebuildJournalView(scenario.sessionDir);
110
- return capture;
111
- }
112
-
113
- function addAssessmentCapture(scenario, changed = ['docs/current/a.md'], beforeCapture = null) {
114
- const args = [DOC_CHECK, 'check', '--workspace', scenario.root, '--config', CONFIG,
115
- ...changed.flatMap(item => ['--changed-path', item]), '--base', scenario.base, '--conflict-assessment'];
116
- const result = spawnSync(process.execPath, args, { cwd: scenario.root, encoding: 'utf8' });
117
- if (result.status !== 0) throw new Error(`fixture assessment failed with ${result.status}: ${report(result)?.conflictAssessment?.reason || result.stderr}`);
118
- if (beforeCapture) beforeCapture();
119
- const command = ['node', ...args].join(' ');
120
- return { result, capture: addHostCapture(scenario, {
121
- cwd: scenario.root, session_id: scenario.sessionId, tool_name: 'Bash', tool_use_id: 'check-1',
122
- tool_input: { command }, tool_response: { stdout: result.stdout, interrupted: false },
123
- }) };
124
- }
125
-
126
- function addReviewCapture(scenario) {
127
- const reviewer = 'independent-reviewer';
128
- addHostCapture(scenario, {
129
- cwd: scenario.root, session_id: scenario.sessionId, tool_name: 'Task', tool_use_id: 'review-task',
130
- tool_input: { description: 'Read-only ADR review' }, tool_response: { agentId: reviewer, interrupted: false },
131
- });
132
- const digest = sha(fs.readFileSync(path.join(scenario.root, 'docs/current/a.md')));
133
- addHostCapture(scenario, {
134
- cwd: scenario.root, session_id: scenario.sessionId, tool_use_id: 'review-stop', agent_id: reviewer, agent_type: 'general-purpose',
135
- last_assistant_message: `Review verdict: approve\nThe updated ADR is clear.\nReviewed artifact: docs/current/a.md sha256:${digest}`,
136
- }, 'SubagentStop');
137
- }
138
-
139
- function testOrigin(scenario, captures = PROVIDER.readCaptureView(scenario.sessionDir).records) {
140
- return PROVIDER.createClaudeOriginProvider({
141
- hostId: 'claude-code', sessionId: scenario.sessionId, workspaceRoot: scenario.root,
142
- workflowId: scenario.workflowId, workflowRevision: 1,
143
- taskId: `task-${REQUIREMENTS.map(item => item.id).join('+')}`,
144
- principals: { author: scenario.sessionId, executors: [scenario.sessionId] },
145
- baseline: scenario.context.workflow.docReconciliationBaseline,
146
- captures,
147
- qualification: { source: 'fake-test-fixture', faked: true, ref: 'pra-fixture', toolUseIdPopulated: true, agentIdPopulated: true },
148
- });
149
- }
150
-
151
- function providerIdentity(scenario) {
152
- return {
153
- workspaceId: 'pra-workspace', sessionId: scenario.sessionId, workflowId: scenario.workflowId,
154
- workflowRevision: 1, taskId: `task-${REQUIREMENTS.map(item => item.id).join('+')}`,
155
- taskScopeDigest: '1'.repeat(64), baselineDigest: '2'.repeat(64), candidateDigest: '3'.repeat(64),
156
- configDigest: '4'.repeat(64), prdRoot: 'docs/prd/',
157
- };
158
- }
159
-
160
- function produceSnapshot(scenario, origin = testOrigin(scenario)) {
161
- const result = PRODUCER.produceDocSnapshot({
162
- workspaceRoot: scenario.root, baseline: scenario.context.workflow.docReconciliationBaseline,
163
- workflow: { workflowId: scenario.workflowId, workflowRevision: 1, sessionId: scenario.sessionId },
164
- task: { taskId: `task-${REQUIREMENTS.map(item => item.id).join('+')}`, requirements: REQUIREMENTS },
165
- scope: { prdRoot: 'docs/prd/' }, activeHost: 'claude-code', prdRoot: 'docs/prd/',
166
- }, { originProvider: origin });
167
- if (result.state !== 'ready' || !result.snapshot) throw new Error(`pilot snapshot unavailable: ${JSON.stringify(result.diagnostics)}`);
168
- return result.snapshot;
169
- }
170
-
171
60
  let passed = 0;
172
61
  let failed = 0;
173
62
  function check(id, fn) {
174
63
  try { fn(); passed += 1; console.log(`PASS ${id}`); }
175
64
  catch (error) { failed += 1; console.error(`FAIL ${id} — ${error.message.split('\n')[0]}`); }
176
65
  }
66
+ function checkPerLeg(id, fn) {
67
+ for (const leg of LEGS) check(`${id} [${leg.name}]`, () => fn(leg));
68
+ }
177
69
 
178
70
  try {
179
- check('F1 full clean corpus emits a bound conflict-check projection', () => {
71
+ checkPerLeg('F1 full clean corpus emits a bound conflict-check projection', leg => {
180
72
  const docs = {
181
73
  'docs/current/a.md': reference('GRPH-001'),
182
74
  'docs/current/b.md': reference('GRPH-002'),
183
75
  'docs/legacy/LEG-001.md': reference('LEG-001'),
184
76
  };
185
77
  const { root, base } = workspace(docs);
186
- const result = runCheck(root, base, ['docs/current/a.md'], ['--conflict-assessment']);
78
+ const result = runCheck(leg, root, base, ['docs/current/a.md'], ['--conflict-assessment']);
187
79
  const out = report(result);
188
80
  assert.equal(result.status, 0, `expected clean assessment exit 0, got ${result.status}: ${out?.lint?.error || result.stderr}`);
189
81
  assert.equal(out.mode, 'conflict-assessment');
@@ -196,77 +88,60 @@ try {
196
88
  assert.equal(out.capabilities['conflict-check'].corpus.baseCommit, base);
197
89
  });
198
90
 
199
- check('F2 plain changed-path check cannot produce conflict-check credit for unchanged conflicts', () => {
91
+ checkPerLeg('F2 plain changed-path check cannot produce conflict-check credit for unchanged conflicts', leg => {
200
92
  const { root, base } = workspace({
201
93
  'docs/current/a.md': reference('GRPH-001', 'conflicts_with: [GRPH-002]\n'),
202
94
  'docs/current/b.md': reference('GRPH-002'),
203
95
  'docs/current/probe.md': reference('GRPH-003'),
204
96
  });
205
- const result = runCheck(root, base, ['docs/current/probe.md']);
97
+ const result = runCheck(leg, root, base, ['docs/current/probe.md']);
206
98
  const out = report(result);
207
99
  assert.equal(result.status, 0, `unchanged conflict must stay a warning in plain check, got ${result.status}`);
208
100
  assert.equal(out.capabilities['doc-lint'].state, 'pass');
209
101
  assert.equal(out.capabilities['link-check'].state, 'pass');
210
102
  assert.equal(out.capabilities['conflict-check'], undefined);
211
- const command = `node ${DOC_CHECK} check --workspace ${root} --config ${CONFIG} --changed-path docs/current/probe.md --base ${base}`;
212
- const invocation = PROVIDER.resolveDocCheckInvocation(command, root);
213
- assert.equal(invocation.kind, 'accepted');
214
- assert.notEqual(invocation.conflictAssessment, true);
215
103
  });
216
104
 
217
- check('F3 full assessment rejects recorded conflicts on unchanged files', () => {
105
+ checkPerLeg('F3 full assessment rejects recorded conflicts on unchanged files', leg => {
218
106
  const { root, base } = workspace({
219
107
  'docs/current/a.md': reference('GRPH-001', 'conflicts_with: [GRPH-002]\n'),
220
108
  'docs/current/b.md': reference('GRPH-002'),
221
109
  'docs/current/probe.md': reference('GRPH-003'),
222
110
  });
223
- const result = runCheck(root, base, ['docs/current/probe.md'], ['--conflict-assessment']);
111
+ const result = runCheck(leg, root, base, ['docs/current/probe.md'], ['--conflict-assessment']);
224
112
  const out = report(result);
225
113
  assert.equal(result.status, 1, `full lint should reject recorded conflict, got ${result.status}`);
226
114
  assert.ok(out.lint.diagnostics.some(item => item.code === 'recorded-conflict'));
227
115
  assert.notEqual(out.capabilities?.['conflict-check']?.state, 'pass');
228
116
  });
229
117
 
230
- check('assessment flag is structurally parsed and accepted by the provider', () => {
231
- const { root, base } = workspace({ 'docs/current/a.md': reference('GRPH-001') });
232
- const command = `node ${DOC_CHECK} check --workspace ${root} --config ${CONFIG} --changed-path docs/current/a.md --base ${base} --conflict-assessment`;
233
- const invocation = PROVIDER.resolveDocCheckInvocation(command, root);
234
- assert.equal(invocation.kind, 'accepted', `provider rejected structured assessment argv: ${invocation.reason}`);
235
- assert.equal(invocation.conflictAssessment, true);
236
- assert.equal(invocation.base, base);
237
- });
238
-
239
- check('duplicate assessment flag is rejected as a duplicate', () => {
118
+ checkPerLeg('duplicate assessment flag is rejected as a duplicate', leg => {
240
119
  const { root, base } = workspace({ 'docs/current/a.md': reference('GRPH-001') });
241
- const result = runCheck(root, base, ['docs/current/a.md'], ['--conflict-assessment', '--conflict-assessment']);
120
+ const result = runCheck(leg, root, base, ['docs/current/a.md'], ['--conflict-assessment', '--conflict-assessment']);
242
121
  const out = report(result);
243
122
  assert.equal(result.status, 2);
244
123
  assert.match(out.lint.error, /repeated argument: --conflict-assessment/);
245
124
  });
246
125
 
247
- check('assessment mode requires its baseline pin', () => {
126
+ checkPerLeg('assessment mode requires its baseline pin', leg => {
248
127
  const { root, base } = workspace({ 'docs/current/a.md': reference('GRPH-001') });
249
- const args = [DOC_CHECK, 'check', '--workspace', root, '--config', CONFIG, '--changed-path', 'docs/current/a.md', '--conflict-assessment'];
128
+ const args = [path.join(leg.dir, 'doc-check.js'), 'check', '--workspace', root, '--config', CONFIG, '--changed-path', 'docs/current/a.md', '--conflict-assessment'];
250
129
  const result = spawnSync(process.execPath, args, { cwd: root, encoding: 'utf8' });
251
130
  assert.equal(result.status, 2);
252
131
  assert.match(report(result).lint.error, /--conflict-assessment requires --base/);
253
- const command = `node ${DOC_CHECK} check --workspace ${root} --config ${CONFIG} --changed-path docs/current/a.md --conflict-assessment`;
254
- assert.equal(PROVIDER.resolveDocCheckInvocation(command, root).reason, 'conflict-assessment-base-required');
255
- const unpinned = runCheck(root, 'HEAD', ['docs/current/a.md'], ['--conflict-assessment']);
132
+ const unpinned = runCheck(leg, root, 'HEAD', ['docs/current/a.md'], ['--conflict-assessment']);
256
133
  assert.equal(report(unpinned).conflictAssessment.state, 'unavailable');
257
134
  assert.equal(report(unpinned).conflictAssessment.reason, 'base-not-pinned');
258
- const movingBaseCommand = `node ${DOC_CHECK} check --workspace ${root} --config ${CONFIG} --changed-path docs/current/a.md --base HEAD --conflict-assessment`;
259
- assert.equal(PROVIDER.resolveDocCheckInvocation(movingBaseCommand, root).reason, 'conflict-assessment-base-unpinned');
260
135
  assert.ok(base);
261
136
  });
262
137
 
263
- check('F4 full graph resolves cross-domain legacy targets and rejects unresolved references', () => {
138
+ checkPerLeg('F4 full graph resolves cross-domain legacy targets and rejects unresolved references', leg => {
264
139
  const crossDomain = workspace({
265
140
  'docs/current/a.md': reference('GRPH-001', 'conflicts_with: [legacy:LEG-001]\n'),
266
141
  'docs/legacy/LEG-001.md': reference('LEG-001'),
267
142
  'docs/current/probe.md': reference('GRPH-003'),
268
143
  });
269
- const crossResult = runCheck(crossDomain.root, crossDomain.base, ['docs/current/probe.md'], ['--conflict-assessment']);
144
+ const crossResult = runCheck(leg, crossDomain.root, crossDomain.base, ['docs/current/probe.md'], ['--conflict-assessment']);
270
145
  const crossOut = report(crossResult);
271
146
  assert.equal(crossResult.status, 1);
272
147
  assert.ok(crossOut.lint.diagnostics.some(item => item.code === 'recorded-conflict' && item.path === 'docs/current/a.md'), JSON.stringify(crossOut.lint.diagnostics));
@@ -276,93 +151,33 @@ try {
276
151
  'docs/current/a.md': reference('GRPH-001', 'conflicts_with: [LEG-404]\n'),
277
152
  'docs/current/probe.md': reference('GRPH-003'),
278
153
  });
279
- const unresolvedResult = runCheck(unresolved.root, unresolved.base, ['docs/current/probe.md'], ['--conflict-assessment']);
154
+ const unresolvedResult = runCheck(leg, unresolved.root, unresolved.base, ['docs/current/probe.md'], ['--conflict-assessment']);
280
155
  const unresolvedOut = report(unresolvedResult);
281
156
  assert.equal(unresolvedResult.status, 1);
282
157
  assert.ok(unresolvedOut.lint.diagnostics.some(item => item.code === 'unresolved-ref'), JSON.stringify(unresolvedOut.lint.diagnostics));
283
158
  assert.notEqual(unresolvedOut.capabilities?.['conflict-check']?.state, 'pass');
284
159
  });
285
160
 
286
- check('omitted corpus and stale base stay unavailable', () => {
161
+ checkPerLeg('omitted corpus and stale base stay unavailable', leg => {
287
162
  const config = JSON.stringify({ governed: [
288
163
  { path: 'docs/current/a.md', role: 'reference' },
289
164
  { path: 'docs/current/missing.md', role: 'reference' },
290
165
  ], legacy: [], domains: ['GRPH'] }, null, 2) + '\n';
291
166
  const omitted = workspace({ 'docs/current/a.md': reference('GRPH-001') }, config);
292
- const incomplete = report(runCheck(omitted.root, omitted.base, ['docs/current/a.md'], ['--conflict-assessment']));
167
+ const incomplete = report(runCheck(leg, omitted.root, omitted.base, ['docs/current/a.md'], ['--conflict-assessment']));
293
168
  assert.equal(incomplete.conflictAssessment.state, 'unavailable');
294
169
  assert.equal(incomplete.conflictAssessment.reason, 'corpus-incomplete');
295
170
  assert.notEqual(incomplete.capabilities?.['conflict-check']?.state, 'pass');
296
171
 
297
172
  const clean = workspace({ 'docs/current/a.md': reference('GRPH-001') });
298
- const stale = report(runCheck(clean.root, 'deadbeef', ['docs/current/a.md'], ['--conflict-assessment']));
173
+ const stale = report(runCheck(leg, clean.root, 'deadbeef', ['docs/current/a.md'], ['--conflict-assessment']));
299
174
  assert.notEqual(stale?.capabilities?.['conflict-check']?.state, 'pass');
300
175
  });
301
176
 
302
- check('mode-looking argument text is not parsed as an assessment flag', () => {
303
- const { root, base } = workspace({ 'docs/current/a.md': reference('GRPH-001') });
304
- const command = `node ${DOC_CHECK} check --workspace ${root} --config ${CONFIG} --changed-path "docs/current/a.md --conflict-assessment" --base ${base}`;
305
- const invocation = PROVIDER.resolveDocCheckInvocation(command, root);
306
- assert.equal(invocation.kind, 'accepted');
307
- assert.notEqual(invocation.conflictAssessment, true);
308
- });
309
-
310
- check('end-to-end pilot discovers conflict-check from real capture records', () => {
311
- const previous = process.env.HARNESS_DOC_RECONCILIATION_PILOT;
312
- process.env.HARNESS_DOC_RECONCILIATION_PILOT = '1';
313
- try {
314
- const scenario = seedPilotScenario();
315
- const { capture } = addAssessmentCapture(scenario);
316
- addReviewCapture(scenario);
317
- const result = PILOT.assess(scenario.context, scenario.set, { originProvider: testOrigin(scenario) });
318
- assert.equal(result.withhold, false, JSON.stringify(result.report));
319
- assert.equal(result.report.pilotCredit, true);
320
- assert.ok(result.report.creditedCapabilities.includes('conflict-check'), JSON.stringify(result.report));
321
- assert.ok(result.report.acceptedRefs.includes(`${capture.ref}#conflict-check`), JSON.stringify(result.report.acceptedRefs));
322
- } finally {
323
- if (previous === undefined) delete process.env.HARNESS_DOC_RECONCILIATION_PILOT;
324
- else process.env.HARNESS_DOC_RECONCILIATION_PILOT = previous;
325
- }
326
- });
327
-
328
- check('capture rejects corpus or config changes between check and PostToolUse', () => {
329
- const corpusChanged = seedPilotScenario();
330
- const changedRun = addAssessmentCapture(corpusChanged, ['docs/current/a.md'], () => {
331
- write(corpusChanged.root, 'docs/current/b.md', adr('GRPH-002', 'The receipt is now archived.'));
332
- });
333
- const corpusOrigin = testOrigin(corpusChanged);
334
- const corpusResult = corpusOrigin.resolveEvent({
335
- reference: `${changedRun.capture.ref}#conflict-check`, identity: providerIdentity(corpusChanged),
336
- });
337
- assert.equal(corpusResult.status, 'rejected');
338
- assert.ok(corpusResult.diagnostics.some(item => item.code === 'corpus-changed-after-check'));
339
-
340
- const configChanged = seedPilotScenario();
341
- const configRun = addAssessmentCapture(configChanged, ['docs/current/a.md'], () => {
342
- fs.appendFileSync(path.join(configChanged.root, CONFIG), '\n');
343
- });
344
- const configOrigin = testOrigin(configChanged);
345
- const configResult = configOrigin.resolveEvent({
346
- reference: `${configRun.capture.ref}#conflict-check`, identity: providerIdentity(configChanged),
347
- });
348
- assert.equal(configResult.status, 'rejected');
349
- assert.ok(configResult.diagnostics.some(item => item.code === 'config-changed-after-check'));
350
- });
351
-
352
- check('corpus changes after capture are rejected against the later snapshot', () => {
353
- const scenario = seedPilotScenario();
354
- const { capture } = addAssessmentCapture(scenario);
355
- const origin = testOrigin(scenario);
356
- write(scenario.root, 'docs/current/b.md', adr('GRPH-002', 'The receipt is now archived.'));
357
- const snapshot = produceSnapshot(scenario, origin);
358
- const accepted = EVENTS.acceptDocEvents({ snapshot, eventRefs: [`${capture.ref}#conflict-check`] }, { originProvider: origin });
359
- assert.equal(accepted.state, 'unresolved');
360
- assert.ok(accepted.rejected.some(item => item.code === 'corpus-mismatch'));
361
- });
362
-
363
- check('symlink skips and unreadable corpus files mark the full collection incomplete', () => {
177
+ checkPerLeg('symlink skips and unreadable corpus files mark the full collection incomplete', leg => {
178
+ const lifecycle = require(path.join(leg.dir, 'doc-lifecycle.js'));
364
179
  const { root } = workspace({ 'docs/current/a.md': reference('GRPH-001') });
365
- const external = path.join(os.tmpdir(), `pra-outside-${process.pid}.md`);
180
+ const external = path.join(os.tmpdir(), `pra-outside-${process.pid}-${leg.name}.md`);
366
181
  write(root, 'docs/current/skipped.md', reference('GRPH-002'));
367
182
  fs.writeFileSync(external, reference('GRPH-003'));
368
183
  let linked = false;
@@ -375,9 +190,9 @@ try {
375
190
  }
376
191
  try {
377
192
  if (linked) {
378
- const result = report(runCheck(root, git(root, ['rev-parse', 'HEAD']), ['docs/current/a.md'], ['--conflict-assessment']));
379
- assert.equal(result.conflictAssessment.state, 'unavailable');
380
- assert.equal(result.conflictAssessment.reason, 'corpus-incomplete');
193
+ const result = report(runCheck(leg, root, git(root, ['rev-parse', 'HEAD']), ['docs/current/a.md'], ['--conflict-assessment']));
194
+ assert.equal(result.conflictAssessment.state, 'unavailable');
195
+ assert.equal(result.conflictAssessment.reason, 'corpus-incomplete');
381
196
  }
382
197
  } finally {
383
198
  fs.rmSync(external, { force: true });
@@ -395,100 +210,18 @@ try {
395
210
  return originalRead.call(this, file, ...args);
396
211
  };
397
212
  try {
398
- LIFECYCLE.collectDocs(root, { governed: [{ path: 'docs/current/**', role: 'reference' }], legacy: [] }, coverage);
213
+ lifecycle.collectDocs(root, { governed: [{ path: 'docs/current/**', role: 'reference' }], legacy: [] }, coverage);
399
214
  } finally { fs.readFileSync = originalRead; }
400
215
  assert.equal(coverage.complete, false);
401
216
  assert.ok(coverage.skipped.some(item => item.path === 'docs/current/a.md' && item.reason === 'unreadable-file'));
402
217
  });
403
218
 
404
- check('provider requires the assessment stdout schema as well as the argv mode', () => {
405
- const scenario = seedPilotScenario();
406
- const command = `node ${DOC_CHECK} check --workspace ${scenario.root} --config ${CONFIG} --changed-path docs/current/a.md --base ${scenario.base} --conflict-assessment`;
407
- const capture = addHostCapture(scenario, {
408
- cwd: scenario.root, session_id: scenario.sessionId, tool_name: 'Bash', tool_use_id: 'forged-mode',
409
- tool_input: { command }, tool_response: { interrupted: false, stdout: JSON.stringify({
410
- schema: 'forged', mode: 'conflict-assessment', lint: { exit: 0 },
411
- capabilities: { 'conflict-check': { state: 'pass', checkedPaths: ['docs/current/a.md'] } },
412
- }) },
413
- });
414
- const response = testOrigin(scenario).resolveEvent({
415
- reference: `${capture.ref}#conflict-check`, identity: providerIdentity(scenario),
416
- });
417
- assert.equal(response.status, 'rejected');
418
- assert.ok(response.diagnostics.some(item => item.code === 'check-not-passed'));
419
- });
420
-
421
- check('snapshot adapter rejects wrong scope, corpus, config, and base bindings', () => {
422
- const scenario = seedPilotScenario();
423
- const { capture } = addAssessmentCapture(scenario);
424
- const origin = testOrigin(scenario);
425
- const snapshot = produceSnapshot(scenario, origin);
426
- const reference = `${capture.ref}#conflict-check`;
427
- const accept = mutate => EVENTS.acceptDocEvents({ snapshot, eventRefs: [reference] }, {
428
- originProvider: {
429
- resolveContext: request => origin.resolveContext(request),
430
- resolveEvent: request => {
431
- const response = origin.resolveEvent(request);
432
- if (response.status !== 'accepted') return response;
433
- const event = JSON.parse(JSON.stringify(response.event));
434
- mutate(event);
435
- return { ...response, event };
436
- },
437
- },
438
- });
439
-
440
- const good = EVENTS.acceptDocEvents({ snapshot, eventRefs: [reference] }, { originProvider: origin });
441
- assert.equal(good.state, 'ready', JSON.stringify(good.rejected));
442
- for (const [name, mutate, expected] of [
443
- ['scope', event => { event.paths = ['docs/current/b.md']; }, 'scope-mismatch'],
444
- ['corpus', event => { event.corpusBinding.paths.pop(); }, 'corpus-mismatch'],
445
- ['config', event => { event.corpusBinding.config.digest = '0'.repeat(64); }, 'config-capture-mismatch'],
446
- ['base', event => { event.corpusBinding.baseCommit = '0'.repeat(40); }, 'snapshot-changed'],
447
- ]) {
448
- const output = accept(mutate);
449
- assert.equal(output.state, 'unresolved', `${name}: ${JSON.stringify(output.rejected)}`);
450
- assert.ok(output.rejected.some(item => item.code === expected), `${name}: ${JSON.stringify(output.rejected)}`);
451
- }
452
- });
453
-
454
- check('provider keeps replay, interruption, failure, and digest-pin controls', () => {
455
- const scenario = seedPilotScenario();
456
- const { capture } = addAssessmentCapture(scenario);
457
- const identity = providerIdentity(scenario);
458
- const duplicate = JSON.parse(JSON.stringify(capture));
459
- duplicate.ref = 'replayed-capture';
460
- const replay = testOrigin(scenario, [capture, duplicate]).resolveEvent({
461
- reference: 'replayed-capture#conflict-check', identity,
462
- });
463
- assert.ok(replay.diagnostics.some(item => item.code === 'replayed-record'));
464
-
465
- const interruptedCapture = { ...capture, interrupted: true };
466
- const interrupted = testOrigin(scenario, [interruptedCapture]).resolveEvent({
467
- reference: `${capture.ref}#conflict-check`, identity,
468
- });
469
- assert.ok(interrupted.diagnostics.some(item => item.code === 'interrupted-not-credited'));
470
-
471
- addHostCapture(scenario, {
472
- cwd: scenario.root, session_id: scenario.sessionId, tool_name: 'Bash', tool_use_id: capture.tool_use_id,
473
- tool_input: { command: capture.command }, error: 'Exit code 1',
474
- }, 'PostToolUseFailure');
475
- const failedInvocation = testOrigin(scenario).resolveEvent({
476
- reference: `${capture.ref}#conflict-check`, identity,
477
- });
478
- assert.ok(failedInvocation.diagnostics.some(item => item.code === 'failure-invalidates-mapping'));
479
-
480
- const stalePinCapture = { ...capture, implementationDigest: '0'.repeat(64) };
481
- const stalePin = testOrigin(scenario, [stalePinCapture]).resolveEvent({
482
- reference: `${capture.ref}#conflict-check`, identity,
483
- });
484
- assert.ok(stalePin.diagnostics.some(item => item.code === 'implementation-digest-mismatch'));
485
- });
486
-
487
- check('a waiver without a successful complete assessment cannot PASS conflict-check', () => {
219
+ checkPerLeg('a waiver without a successful complete assessment cannot PASS conflict-check', leg => {
220
+ const evidence = require(path.join(leg.dir, 'doc-evidence.js'));
488
221
  const scope = ['docs/current/a.md'];
489
222
  const digest = 'a'.repeat(64);
490
223
  const baselineDigest = 'b'.repeat(64);
491
- const output = EVIDENCE.checkDocObligations({
224
+ const output = evidence.checkDocObligations({
492
225
  obligations: [{ id: 'conflict-check', capability: 'conflict-check', strength: 'MUST', applicability: 'applicable', scope: { paths: scope } }],
493
226
  artifacts: { [scope[0]]: { digest } }, baseline: { digest: baselineDigest, artifacts: {} }, executionRecords: [],
494
227
  reviewRecords: [{ id: 'waiver-1', obligationId: 'conflict-check', kind: 'waiver', reason: 'assessment was complete',