harness-everything 1.3.0 → 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 (125) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +6 -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/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
  7. package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
  8. package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
  9. package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
  10. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  11. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
  12. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  13. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
  14. package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
  15. package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
  16. package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
  17. package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
  18. package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
  19. package/ci/fixtures/stop/fail-session-writes.js +109 -0
  20. package/ci/fixtures/workflow-contract/cases.json +3355 -0
  21. package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
  22. package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
  23. package/ci/mechanism-2an-workflow-replay.test.js +324 -0
  24. package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
  25. package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
  26. package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
  27. package/ci/mechanism-325-3b-preparation.test.js +208 -49
  28. package/ci/mechanism-325-3b-s1-review.test.js +20 -828
  29. package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
  30. package/ci/mechanism-325-f3-derived-views.test.js +140 -0
  31. package/ci/mechanism-341-opencode-lane.test.js +164 -284
  32. package/ci/mechanism-35-verification-contract.test.js +246 -0
  33. package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
  34. package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
  35. package/ci/mechanism-397-opencode-observations.test.js +151 -18
  36. package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
  37. package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
  38. package/ci/mechanism-553-p3-plan-start.test.js +212 -0
  39. package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
  40. package/ci/mechanism-553-stop.test.js +427 -0
  41. package/ci/mechanism-553-t2a-derive.test.js +110 -0
  42. package/ci/mechanism-553-t2c-derive.test.js +94 -0
  43. package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
  44. package/ci/mechanism-outline-sanitizer.test.js +0 -8
  45. package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
  46. package/ci/mechanism-prb-outline-review.test.js +101 -3283
  47. package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
  48. package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
  49. package/docs/doc-workflow-reconciliation.md +17 -2
  50. package/docs/document-lifecycle.md +6 -2
  51. package/docs/platform-capabilities.md +35 -5
  52. package/hooks/hooks.json +0 -46
  53. package/hooks/scripts/lib/workflow-obligations.js +0 -55
  54. package/hooks/scripts/state-persist.js +7 -95
  55. package/hooks/scripts/workflow-disposition.js +0 -2
  56. package/hooks/scripts/workflow-stop-gate.js +17 -30
  57. package/opencode-plugin/index.mjs +6 -70
  58. package/opencode-plugin/plugin.json +1 -1
  59. package/package.json +1 -1
  60. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  61. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  62. package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +0 -55
  63. package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
  64. package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
  65. package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
  66. package/plugins/harness-everything/plugin.json +1 -1
  67. package/sbom.cdx.json +7 -7
  68. package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
  69. package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
  70. package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
  71. package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
  72. package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
  73. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
  74. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
  75. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
  76. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
  77. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
  78. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
  79. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
  80. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
  81. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
  82. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
  83. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
  84. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
  85. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
  86. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
  87. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
  88. package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
  89. package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
  90. package/ci/lib/doc-reconciliation-file-spy.js +0 -23
  91. package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
  92. package/ci/lib/doc-reconciliation-replay.js +0 -104
  93. package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
  94. package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
  95. package/ci/mechanism-325-3b-s1.test.js +0 -188
  96. package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
  97. package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
  98. package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
  99. package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
  100. package/ci/mechanism-325-f4-invariants.test.js +0 -606
  101. package/ci/mechanism-325-f4-projections.test.js +0 -392
  102. package/ci/mechanism-325-f4-qualification.test.js +0 -228
  103. package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
  104. package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
  105. package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  106. package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  107. package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  108. package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  109. package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  110. package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  111. package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  112. package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  113. package/hooks/scripts/w6-state-operations.js +0 -239
  114. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  115. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  116. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  117. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  118. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  119. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  120. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  121. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  122. package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
  123. package/scripts/system-one-eval-laya.js +0 -112
  124. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
  125. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
@@ -1,26 +0,0 @@
1
- {"run":"1","source":"wrapper-stdin","wrapperLabel":"PreToolUse","event":"PreToolUse","tool_use_id":"<tool-use-1>","payload":{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_use_id":"<tool-use-1>","session_id":"<session-1>","prompt_id":"<prompt-1>","tool_input_command":"node <scratch>/plugin/harness-everything/scripts/doc-check.js check --workspace <scratch>/project --config .agents/harness-everything/project-docs.json --changed-path docs/a.md","cwd":"<scratch>/project","transcript_path":"<home-path>"}}
2
- {"run":"2a","source":"wrapper-stdin","wrapperLabel":"PreToolUse","event":"PreToolUse","tool_use_id":"<tool-use-2>","payload":{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_use_id":"<tool-use-2>","session_id":"<session-2>","prompt_id":"<prompt-2>","tool_input_command":"node <scratch>/plugin/harness-everything/scripts/doc-check.js check --workspace <scratch>/project --config .agents/harness-everything/project-docs.json --changed-path docs/a.md","cwd":"<scratch>/project","transcript_path":"<home-path>"}}
3
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"PreToolUse","event":"PreToolUse","tool_use_id":"<tool-use-3>","payload":{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_use_id":"<tool-use-3>","session_id":"<session-3>","prompt_id":"<prompt-3>","tool_input_command":"node \"<scratch>/plugin/harness-everything/scripts/doc-check.js\" check --workspace <scratch>/project --config .agents/harness-everything/project-docs.json --changed-path docs/a.md","cwd":"<scratch>/project","transcript_path":"<home-path>"}}
4
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"PostToolUse","event":"PostToolUse","tool_use_id":"<tool-use-3>","interrupted":false,"payload":{"hook_event_name":"PostToolUse","tool_name":"Bash","tool_use_id":"<tool-use-3>","session_id":"<session-3>","prompt_id":"<prompt-3>","tool_input_command":"node \"<scratch>/plugin/harness-everything/scripts/doc-check.js\" check --workspace <scratch>/project --config .agents/harness-everything/project-docs.json --changed-path docs/a.md","cwd":"<scratch>/project","transcript_path":"<home-path>","tool_response":{"keys":["interrupted","isImage","noOutputExpected","stderr","stdout"],"interrupted":false,"digest":"sha256:22cd89eb079e65f996432f65cfd9bed1a29366def8f3f8af9af94c26c60bd1f5"}}}
5
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"PreToolUse","event":"PreToolUse","tool_use_id":"<tool-use-4>","payload":{"hook_event_name":"PreToolUse","tool_name":"Agent","tool_use_id":"<tool-use-4>","session_id":"<session-3>","prompt_id":"<prompt-3>","cwd":"<scratch>/project","transcript_path":"<home-path>"}}
6
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"SubagentStart","event":"SubagentStart","agent_id":"<agent-1>","payload":{"hook_event_name":"SubagentStart","session_id":"<session-3>","prompt_id":"<prompt-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","cwd":"<scratch>/project","transcript_path":"<home-path>"}}
7
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"PreToolUse","event":"PreToolUse","tool_use_id":"<tool-use-5>","agent_id":"<agent-1>","payload":{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_use_id":"<tool-use-5>","session_id":"<session-3>","prompt_id":"<prompt-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","tool_input_command":"cat docs/a.md && git diff docs/a.md && shasum -a 256 docs/a.md","cwd":"<scratch>/project","transcript_path":"<home-path>"}}
8
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"PreToolUse","event":"PreToolUse","tool_use_id":"<tool-use-6>","agent_id":"<agent-1>","payload":{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_use_id":"<tool-use-6>","session_id":"<session-3>","prompt_id":"<prompt-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","tool_input_command":"git diff docs/a.md","cwd":"<scratch>/project","transcript_path":"<home-path>"}}
9
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"PostToolUse","event":"PostToolUse","tool_use_id":"<tool-use-6>","agent_id":"<agent-1>","interrupted":false,"payload":{"hook_event_name":"PostToolUse","tool_name":"Bash","tool_use_id":"<tool-use-6>","session_id":"<session-3>","prompt_id":"<prompt-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","tool_input_command":"git diff docs/a.md","cwd":"<scratch>/project","transcript_path":"<home-path>","tool_response":{"keys":["interrupted","isImage","noOutputExpected","stderr","stdout"],"interrupted":false,"digest":"sha256:5ff449b9366059bd45c22c411728c93b8c4b5d5a083f1243c7882279b8b2e656"}}}
10
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"PreToolUse","event":"PreToolUse","tool_use_id":"<tool-use-7>","agent_id":"<agent-1>","payload":{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_use_id":"<tool-use-7>","session_id":"<session-3>","prompt_id":"<prompt-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","tool_input_command":"ls docs; grep -rni retr . --include=*.md","cwd":"<scratch>/project","transcript_path":"<home-path>"}}
11
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"PostToolUse","event":"PostToolUse","tool_use_id":"<tool-use-7>","agent_id":"<agent-1>","interrupted":false,"payload":{"hook_event_name":"PostToolUse","tool_name":"Bash","tool_use_id":"<tool-use-7>","session_id":"<session-3>","prompt_id":"<prompt-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","tool_input_command":"ls docs; grep -rni retr . --include=*.md","cwd":"<scratch>/project","transcript_path":"<home-path>","tool_response":{"keys":["interrupted","isImage","noOutputExpected","returnCodeInterpretation","stderr","stdout"],"interrupted":false,"digest":"sha256:f4f1baf50b0770a29763b15493f7c7f315321f5c2c92b5288b18d20c3480f97a"}}}
12
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"SubagentStop","event":"SubagentStop","agent_id":"<agent-1>","payload":{"hook_event_name":"SubagentStop","session_id":"<session-3>","prompt_id":"<prompt-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","cwd":"<scratch>/project","transcript_path":"<home-path>","agent_transcript_path":"<home-path>","last_assistant_message":"Review verdict: approve\n\nSummary: The only change to `docs/a.md` is \"retries once\" becoming \"retries twice\". The front matter is intact, and the link to `b.md` resolves because that file exists. Nothing else in the repo mentions retries, so I found no contradiction. I could not check the \"twice\" claim against the code, since this repo has no code or other source for it. I also couldn't compute a SHA-256, because the shell blocked `shasum`.\n\nReviewed artifact digest: `<scratch>/project/docs/a.md`, the working-tree version, uncommitted on top of baseline 8648a71. The identifying content is the diff hunk `@@ -3,4 +3,4 @@`, with the blob change `0936062..3bea475`. The body line is \"The checkout retries twice. See [b](b.md).\""}}
13
- {"run":"2b","source":"wrapper-stdin","wrapperLabel":"PostToolUse","event":"PostToolUse","tool_use_id":"<tool-use-4>","payload":{"hook_event_name":"PostToolUse","tool_name":"Agent","tool_use_id":"<tool-use-4>","session_id":"<session-3>","prompt_id":"<prompt-3>","cwd":"<scratch>/project","transcript_path":"<home-path>","tool_response":{"keys":["agentId","agentType","canContinueAgent","content","harnessNoteCount","harnessSectionHash","harnessTailCount","prompt","resolvedModel","status","toolStats","totalDurationMs","totalTokens","totalToolUseCount","usage"],"status":"completed","agentId":"<agent-1>","digest":"sha256:f035f2ed002f3dc6827f3109a8fdbc99ae439472bc504fc4d460b5bf0ac4204e"}}}
14
- {"run":"1","source":"journal-record","event":"PreToolUse","tool_use_id":"<tool-use-1>","record":{"captureId":"<capture-1>","event":"PreToolUse","tool_use_id":"<tool-use-1>","session_id":"<session-1>","command":"node <scratch>/plugin/harness-everything/scripts/doc-check.js check --workspace <scratch>/project --config .agents/harness-everything/project-docs.json --changed-path docs/a.md","cwd":"<scratch>/project","responseDigest":"eb045d78d273107348b0300c01d29b7552d622abbc6faf81b3ec55359aa9950c"}}
15
- {"run":"1","source":"journal-record","event":"PreToolUse","tool_use_id":"<tool-use-1>","record":{"captureId":"<capture-2>","event":"PreToolUse","tool_use_id":"<tool-use-1>","session_id":"<session-1>","command":"node <scratch>/plugin/harness-everything/scripts/doc-check.js check --workspace <scratch>/project --config .agents/harness-everything/project-docs.json --changed-path docs/a.md","cwd":"<scratch>/project","responseDigest":"eb045d78d273107348b0300c01d29b7552d622abbc6faf81b3ec55359aa9950c"}}
16
- {"run":"2b","source":"journal-record","event":"PreToolUse","tool_use_id":"<tool-use-3>","record":{"captureId":"<capture-3>","event":"PreToolUse","tool_use_id":"<tool-use-3>","session_id":"<session-3>","command":"node \"<scratch>/plugin/harness-everything/scripts/doc-check.js\" check --workspace <scratch>/project --config .agents/harness-everything/project-docs.json --changed-path docs/a.md","cwd":"<scratch>/project","responseDigest":"eb045d78d273107348b0300c01d29b7552d622abbc6faf81b3ec55359aa9950c"}}
17
- {"run":"2b","source":"journal-record","event":"PostToolUse","tool_use_id":"<tool-use-3>","interrupted":false,"record":{"captureId":"<capture-4>","event":"PostToolUse","tool_use_id":"<tool-use-3>","session_id":"<session-3>","command":"node \"<scratch>/plugin/harness-everything/scripts/doc-check.js\" check --workspace <scratch>/project --config .agents/harness-everything/project-docs.json --changed-path docs/a.md","cwd":"<scratch>/project","interrupted":false,"responseDigest":"80ccfae628fb7127a06592ddb8439b864093a34d1b11007d5b137fbc6f95fcef"}}
18
- {"run":"2b","source":"journal-record","event":"PreToolUse","tool_use_id":"<tool-use-4>","record":{"captureId":"<capture-5>","event":"PreToolUse","tool_use_id":"<tool-use-4>","session_id":"<session-3>","cwd":"<scratch>/project","responseDigest":"eb045d78d273107348b0300c01d29b7552d622abbc6faf81b3ec55359aa9950c"}}
19
- {"run":"2b","source":"journal-record","event":"SubagentStart","agent_id":"<agent-1>","record":{"captureId":"<capture-6>","event":"SubagentStart","session_id":"<session-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","cwd":"<scratch>/project","responseDigest":"eb045d78d273107348b0300c01d29b7552d622abbc6faf81b3ec55359aa9950c"}}
20
- {"run":"2b","source":"journal-record","event":"PreToolUse","tool_use_id":"<tool-use-5>","agent_id":"<agent-1>","record":{"captureId":"<capture-7>","event":"PreToolUse","tool_use_id":"<tool-use-5>","session_id":"<session-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","command":"cat docs/a.md && git diff docs/a.md && shasum -a 256 docs/a.md","cwd":"<scratch>/project","responseDigest":"eb045d78d273107348b0300c01d29b7552d622abbc6faf81b3ec55359aa9950c"}}
21
- {"run":"2b","source":"journal-record","event":"PreToolUse","tool_use_id":"<tool-use-6>","agent_id":"<agent-1>","record":{"captureId":"<capture-8>","event":"PreToolUse","tool_use_id":"<tool-use-6>","session_id":"<session-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","command":"git diff docs/a.md","cwd":"<scratch>/project","responseDigest":"eb045d78d273107348b0300c01d29b7552d622abbc6faf81b3ec55359aa9950c"}}
22
- {"run":"2b","source":"journal-record","event":"PostToolUse","tool_use_id":"<tool-use-6>","agent_id":"<agent-1>","interrupted":false,"record":{"captureId":"<capture-9>","event":"PostToolUse","tool_use_id":"<tool-use-6>","session_id":"<session-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","command":"git diff docs/a.md","cwd":"<scratch>/project","interrupted":false,"responseDigest":"f8770735e00cf9d10b07d43d91379c17ab2ca5444610dd3d5944b52912d13369"}}
23
- {"run":"2b","source":"journal-record","event":"PreToolUse","tool_use_id":"<tool-use-7>","agent_id":"<agent-1>","record":{"captureId":"<capture-10>","event":"PreToolUse","tool_use_id":"<tool-use-7>","session_id":"<session-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","command":"ls docs; grep -rni retr . --include=*.md","cwd":"<scratch>/project","responseDigest":"eb045d78d273107348b0300c01d29b7552d622abbc6faf81b3ec55359aa9950c"}}
24
- {"run":"2b","source":"journal-record","event":"PostToolUse","tool_use_id":"<tool-use-7>","agent_id":"<agent-1>","interrupted":false,"record":{"captureId":"<capture-11>","event":"PostToolUse","tool_use_id":"<tool-use-7>","session_id":"<session-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","command":"ls docs; grep -rni retr . --include=*.md","cwd":"<scratch>/project","interrupted":false,"responseDigest":"4a1d1e23f6b3c88bbc86f5960e2492acc61d65201a9cea4863610c068beb907c"}}
25
- {"run":"2b","source":"journal-record","event":"SubagentStop","agent_id":"<agent-1>","record":{"captureId":"<capture-12>","event":"SubagentStop","session_id":"<session-3>","agent_id":"<agent-1>","agent_type":"doc-reviewer","cwd":"<scratch>/project","reviewVerdict":"approve","reviewSummary":"Summary: The only change to `docs/a.md` is \"retries once\" becoming \"retries twice\". The front matter is intact, and the link to `b.md` resolves because that file exists. Nothing else in the repo mentions retries, so I found no contradiction. I could not check the \"twice\" claim against the code, since this repo has no code or other source for it. I also couldn't compute a SHA-256, because the shell blocked `shasum`.\n\n\nReviewed artifact digest: `<scratch>/project/docs/a.md`, the working-tree version, uncommitted on top of baseline 8648a71. The identifying content is the diff hunk `@@ -3,4 +3,4 @@`, with the blob change `0936062..3bea475`. The body line is \"The checkout retries twice. See [b](b.md).\"","responseDigest":"eb045d78d273107348b0300c01d29b7552d622abbc6faf81b3ec55359aa9950c"}}
26
- {"run":"2b","source":"journal-record","event":"PostToolUse","tool_use_id":"<tool-use-4>","agent_id":"<agent-1>","record":{"captureId":"<capture-13>","event":"PostToolUse","tool_use_id":"<tool-use-4>","session_id":"<session-3>","agent_id":"<agent-1>","cwd":"<scratch>/project","responseDigest":"51be05fc9c852f14829a9e01ccd0b2d9d743e0d16c237de69db752d100fad0dc"}}
@@ -1,336 +0,0 @@
1
- 'use strict';
2
-
3
- const crypto = require('crypto');
4
-
5
- // Both layouts are shipped by plugin:sync. Resolve modules at import, never during a decision.
6
- function runtimeModule(name) {
7
- try { return require('../../../harness-everything/scripts/' + name); }
8
- catch (error) {
9
- if (error.code !== 'MODULE_NOT_FOUND' || !error.message.startsWith("Cannot find module '../../../harness-everything/scripts/" + name + "'")) throw error;
10
- return require('../../../skills/harness-everything/scripts/' + name);
11
- }
12
- }
13
- const { checkDocObligations } = runtimeModule('doc-evidence.js');
14
- const { deriveDocFacts, deriveDocObligations } = runtimeModule('doc-obligations.js');
15
- const { validateDocsConfig } = runtimeModule('project-docs-resolver.js');
16
- const text = value => typeof value === 'string' && value.trim().length > 0;
17
- const record = value => value !== null && typeof value === 'object' && !Array.isArray(value);
18
- const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
19
- const bytes = value => Buffer.isBuffer(value) ? Buffer.from(value)
20
- : value && value.type === 'Buffer' && Array.isArray(value.data) ? Buffer.from(value.data)
21
- : (() => { throw new Error('inventory-unsupported'); })();
22
- function canonical(value) {
23
- if (Buffer.isBuffer(value)) return { type: 'Buffer', data: [...value] };
24
- if (Array.isArray(value)) return value.map(canonical);
25
- if (!record(value)) return value;
26
- return Object.fromEntries(Object.keys(value).sort(compare).map(key => [key, canonical(value[key])]));
27
- }
28
- const stable = value => JSON.stringify(canonical(value));
29
- const clone = value => JSON.parse(stable(value));
30
- const sha = value => crypto.createHash('sha256').update(value).digest('hex');
31
- const frame = value => { const b = Buffer.isBuffer(value) ? value : Buffer.from(String(value)); return Buffer.concat([Buffer.from(b.length + ':'), b]); };
32
- const hashFrames = values => sha(Buffer.concat(values.map(frame)));
33
- const structuredDigest = (domain, value) => hashFrames([domain, stable(value)]);
34
- const identityFields = ['workspaceId', 'sessionId', 'workflowId', 'workflowRevision', 'taskId', 'taskScopeDigest', 'baselineDigest', 'candidateDigest', 'configDigest', 'prdRoot'];
35
- const validIdentity = id => record(id) && ['workspaceId', 'sessionId', 'workflowId', 'taskId'].every(key => text(id[key]))
36
- && Number.isInteger(id.workflowRevision) && id.workflowRevision >= 0 && id.prdRoot === 'docs/prd/'
37
- && ['taskScopeDigest', 'baselineDigest', 'candidateDigest', 'configDigest'].every(key => /^[a-f0-9]{64}$/.test(id[key] || ''));
38
- const sameIdentity = (a, b) => validIdentity(a) && validIdentity(b) && identityFields.every(key => a[key] === b[key]);
39
- const diagnostic = (code, context = {}) => ({ code, message: code.replace(/-/g, ' '), ...context });
40
- const pathCompare = (a, b) => Buffer.compare(Buffer.from(a.path), Buffer.from(b.path));
41
- const codedError = code => Object.assign(new Error(code), { code });
42
- const PROJECT_CONFIG_PATH = '.agents/harness-everything/project-docs.json';
43
- const DEPENDENCY_ARTIFACT_ROOTS = new Set(['node_modules', '.husky/_']);
44
- const DEPENDENCY_POLICY_VERSION = 'dependency-artifact-scope/1';
45
- // The derive contract (doc-obligations.js) decides applicability from governed/legacy documents, derived
46
- // outputs and code/REQ-test paths. Records outside them cannot affect document obligations.
47
- // shortcut: mirrors derive path rules, update them together until a shared classifier is exposed.
48
- const CODE_EXTENSION = /\.(?:c|cc|cpp|h|hpp|m|mm|go|rs|java|kt|swift|js|jsx|mjs|cjs|ts|tsx|py|rb|php|sh|ps1|sql)$/i;
49
- const TEST_PATH = /(?:^|\/)(?:test|tests|__tests__|spec)(?:\/|$)|(?:^|\/)[^/]*(?:\.test|\.spec)\.[^/]+$/i;
50
- // Glob semantics of the derive contract: '**' crosses directories, '*' stays inside one segment.
51
- function globToRegExp(glob) {
52
- const source = String(glob).replace(/\\/g, '/').replace(/^\.\//, '');
53
- let pattern = '^';
54
- for (let index = 0; index < source.length; index++) {
55
- const char = source[index];
56
- if (char === '*' && source[index + 1] === '*') {
57
- if (source[index + 2] === '/') { pattern += '(?:[\\s\\S]*/)?'; index += 2; }
58
- else { pattern += '[\\s\\S]*'; index += 1; }
59
- } else if (char === '*') pattern += '[^/]*';
60
- else pattern += char.replace(/[|\\{}()[\]^$+?.]/g, '\\$&');
61
- }
62
- return new RegExp(`${pattern}$`);
63
- }
64
- // Semantic relevance of a path under the derive contract; null means the path cannot change applicability.
65
- function semanticRelevance(path, config) {
66
- const governed = Array.isArray(config && config.governed) ? config.governed : [];
67
- const legacy = Array.isArray(config && config.legacy) ? config.legacy : [];
68
- const derived = Array.isArray(config && config.derived) ? config.derived : [];
69
- const matches = globs => globs.some(glob => typeof glob === 'string' && globToRegExp(glob).test(path));
70
- if (governed.some(entry => entry && typeof entry.path === 'string' && matches([entry.path]))) return 'document';
71
- if (matches(legacy)) return 'document';
72
- if (derived.some(entry => entry && typeof entry.path === 'string'
73
- && (matches([entry.path]) || matches([entry.source, ...(Array.isArray(entry.sources) ? entry.sources : [])])))) return 'derived';
74
- if (CODE_EXTENSION.test(path)) return 'code';
75
- if (TEST_PATH.test(path)) return 'test';
76
- return null;
77
- }
78
- // The derive contract reads the frontmatter of every captured file, so a record that opens a frontmatter
79
- // block is observed by it even when the record's bytes cannot be decoded. Match TextDecoder's BOM handling.
80
- function opensFrontmatter(stored) {
81
- return stored.subarray(0, 11).toString('utf8').replace(/^\uFEFF/, '').split('\n')[0].replace(/\r$/, '') === '---';
82
- }
83
- // A whole-project inventory keeps every stored byte in the identity framing. Semantic derivation converts only
84
- // records it can decode; a record the derive contract can observe (governed/derived/code/test path or a
85
- // frontmatter document) fails closed instead of being silently dropped.
86
- function deriveFiles(records, config, options = {}) {
87
- const files = {};
88
- for (const item of records || []) {
89
- if (!record(item) || item.presence !== 'present') continue;
90
- // The unchanged derive API uses ordinary object maps, whose __proto__ setter drops this path.
91
- if (item.path === '__proto__') throw codedError('inventory-unsupported');
92
- const stored = bytes(item.storedBytes);
93
- if (options.strict && (item.digest !== sha(stored) || item.type !== 'file' || !['100644', '100755'].includes(item.mode))) {
94
- throw codedError('invalid-input');
95
- }
96
- let content;
97
- try { content = new TextDecoder('utf-8', { fatal: true }).decode(stored); }
98
- catch {
99
- if (semanticRelevance(item.path, config) || opensFrontmatter(stored)) throw codedError('inventory-unsupported');
100
- continue;
101
- }
102
- files[item.path] = content;
103
- }
104
- return files;
105
- }
106
- const identityTupleFields = ['workspaceId', 'sessionId', 'workflowId', 'workflowRevision', 'taskId'];
107
- // The captured origin context is the snapshot's only origin-correlated identity: every field it carries must be
108
- // the identity the snapshot claims, the captured plan must agree with both, and the captured host must be the
109
- // host the captured config was selected for (PR #353 review P1).
110
- function originBound(snapshot) {
111
- const context = snapshot.originContext;
112
- const id = snapshot.identity;
113
- if (!record(context) || !validIdentity(id)) return false;
114
- for (const key of identityTupleFields) if (context[key] !== id[key]) return false;
115
- const plan = snapshot.taskSemantics;
116
- if (!record(plan) || !record(plan.workflow) || !record(plan.task)) return false;
117
- if (plan.workflow.workflowId !== id.workflowId || plan.workflow.workflowRevision !== id.workflowRevision
118
- || plan.workflow.sessionId !== id.sessionId || plan.task.taskId !== id.taskId) return false;
119
- if (plan.prdRoot !== id.prdRoot || plan.configDigest !== id.configDigest) return false;
120
- const captured = context.activeHost === undefined || context.activeHost === null ? null : context.activeHost;
121
- const selected = snapshot.config && snapshot.config.capture ? snapshot.config.capture.activeHost : null;
122
- const chosen = selected === undefined || selected === null ? null : selected;
123
- if (captured === null && chosen === null) return true;
124
- return stable(captured) === stable(chosen);
125
- }
126
- // The captured config bytes must be the bytes the captured inventory holds for the same path; otherwise the
127
- // config digest binds a parsed value that the whole-project capture contradicts (the producer's own rule).
128
- function configBytesBound(snapshot) {
129
- const sources = snapshot.config && snapshot.config.capture ? snapshot.config.capture.sources : null;
130
- if (!Array.isArray(sources)) return false;
131
- const records = Array.isArray(snapshot.candidate.records) ? snapshot.candidate.records : [];
132
- for (const source of sources) {
133
- const file = records.find(item => item && item.path === source.path && item.presence === 'present');
134
- if (source.presence === 'present' ? !file || !bytes(source.bytes).equals(bytes(file.storedBytes)) : Boolean(file)) return false;
135
- }
136
- return true;
137
- }
138
- function snapshotDigest(kind, baseline, coverage, records) {
139
- const fields = ['doc-snapshot-v1', kind, baseline.commit, baseline.treeRef, structuredDigest('doc-coverage-v1', coverage), String(records.length)];
140
- for (const item of [...records].sort(pathCompare)) fields.push(item.path, item.presence, item.type, item.mode, bytes(item.storedBytes));
141
- return hashFrames(fields);
142
- }
143
- function pathUnderDependencyRoot(relative, root) {
144
- const candidate = String(relative).replace(/\\/g, '/').normalize('NFC').toLowerCase();
145
- const prefix = root.normalize('NFC').toLowerCase();
146
- return candidate === prefix || candidate.startsWith(`${prefix}/`);
147
- }
148
- function projectConfigFromStoredBytes(value) {
149
- try {
150
- const config = JSON.parse(bytes(value).toString('utf8'));
151
- return validateDocsConfig(config).valid ? config : null;
152
- } catch { return null; }
153
- }
154
- function validCoverage(snapshot) {
155
- const coverage = snapshot.candidate?.coverage;
156
- if (!record(coverage) || !Array.isArray(coverage.excluded) || !record(coverage.scope)) return false;
157
- if (coverage.kind === 'whole-project') {
158
- return Object.keys(coverage).sort(compare).join('\0') === ['excluded', 'kind', 'scope'].sort(compare).join('\0')
159
- && stable(coverage.excluded) === stable(['.git']);
160
- }
161
- const fields = ['dependencyArtifactRoots', 'excluded', 'excludedRootStates', 'guardOutcomes', 'kind', 'policySource', 'policyVersion', 'scope'];
162
- if (coverage.kind !== 'project-with-dependency-artifact-exclusions'
163
- || Object.keys(coverage).sort(compare).join('\0') !== fields.sort(compare).join('\0')
164
- || coverage.policyVersion !== DEPENDENCY_POLICY_VERSION || !record(coverage.policySource)
165
- || Object.keys(coverage.policySource).sort(compare).join('\0') !== ['baselineCommit', 'path', 'storedBytesDigest'].sort(compare).join('\0')
166
- || coverage.policySource.path !== PROJECT_CONFIG_PATH || coverage.policySource.baselineCommit !== snapshot.baseline.commit
167
- || !/^[a-f0-9]{64}$/.test(coverage.policySource.storedBytesDigest || '')
168
- || !Array.isArray(coverage.dependencyArtifactRoots) || !coverage.dependencyArtifactRoots.length
169
- || coverage.dependencyArtifactRoots.some(root => !DEPENDENCY_ARTIFACT_ROOTS.has(root))
170
- || stable(coverage.dependencyArtifactRoots) !== stable([...coverage.dependencyArtifactRoots].sort())
171
- || new Set(coverage.dependencyArtifactRoots).size !== coverage.dependencyArtifactRoots.length
172
- || stable(coverage.excluded) !== stable(['.git', ...coverage.dependencyArtifactRoots])) return false;
173
- const roots = coverage.dependencyArtifactRoots;
174
- const baselinePolicy = snapshot.baseline.records.find(item => item.path === PROJECT_CONFIG_PATH && item.presence === 'present');
175
- const candidatePolicy = snapshot.config.capture.sources.find(item => item.path === PROJECT_CONFIG_PATH && item.presence === 'present');
176
- if (!baselinePolicy || !candidatePolicy || sha(bytes(baselinePolicy.storedBytes)) !== coverage.policySource.storedBytesDigest) return false;
177
- const baseConfig = projectConfigFromStoredBytes(baselinePolicy.storedBytes);
178
- const candidateConfig = projectConfigFromStoredBytes(candidatePolicy.bytes);
179
- const baseRoots = baseConfig?.inventory?.dependencyArtifactRoots;
180
- const candidateRoots = candidateConfig?.inventory?.dependencyArtifactRoots;
181
- if (!Array.isArray(baseRoots) || !Array.isArray(candidateRoots)
182
- || stable([...baseRoots].sort()) !== stable([...candidateRoots].sort())
183
- || stable([...baseRoots].sort()) !== stable(roots)) return false;
184
- if ([...snapshot.baseline.records, ...snapshot.candidate.records].some(item => roots.some(root => pathUnderDependencyRoot(item.path, root)))) return false;
185
- if (!Array.isArray(coverage.excludedRootStates) || coverage.excludedRootStates.length !== roots.length
186
- || coverage.excludedRootStates.some((item, index) => !record(item) || item.path !== roots[index]
187
- || !['absent', 'present-directory'].includes(item.presence)
188
- || Object.keys(item).sort(compare).join('\0') !== ['path', 'presence'].sort(compare).join('\0'))) return false;
189
- const guards = ['baseline-paths', 'index-paths', 'config-sources', 'config-selectors', 'task-inputs', 'excluded-root-types'];
190
- return Array.isArray(coverage.guardOutcomes) && coverage.guardOutcomes.length === guards.length
191
- && coverage.guardOutcomes.every((item, index) => record(item) && item.guard === guards[index] && item.state === 'clear'
192
- && text(item.reason) && (index !== guards.length - 1 || stable(item.roots) === stable(coverage.excludedRootStates)));
193
- }
194
- function configDigest(config) {
195
- const sources = [...config.capture.sources].sort(pathCompare);
196
- const fields = ['doc-config-v1', stable({ activeHost: config.capture.activeHost, selectionInputs: config.capture.selectionInputs, resolution: config.resolution }), String(sources.length)];
197
- for (const source of sources) fields.push(source.path, source.presence, bytes(source.bytes));
198
- return hashFrames(fields);
199
- }
200
- function validateSnapshot(snapshot) {
201
- const errors = [];
202
- try {
203
- if (!validIdentity(snapshot.identity) || !record(snapshot.facts) || !Array.isArray(snapshot.obligations)) throw new Error('invalid-input');
204
- if (!validCoverage(snapshot)) errors.push(diagnostic('inventory-unsupported'));
205
- // Roots are canonicalized at capture; keep reconciliation detached and free of filesystem reads.
206
- const context = snapshot.originContext;
207
- if (!record(context) || !record(context.baseline) || !text(context.workspaceRoot)
208
- || context.baseline.commit !== snapshot.baseline.commit || context.baseline.root !== context.workspaceRoot) {
209
- errors.push(diagnostic('baseline-unavailable'));
210
- }
211
- // The captured origin identity, the captured plan and the selected host must be the identity the snapshot
212
- // claims; otherwise the provider half and the event half of the trust contract stay disconnected.
213
- if (!originBound(snapshot)) errors.push(diagnostic('identity-mismatch'));
214
- if (snapshotDigest('baseline', snapshot.baseline, snapshot.candidate.coverage, snapshot.baseline.records) !== snapshot.identity.baselineDigest
215
- || snapshotDigest('candidate', snapshot.baseline, snapshot.candidate.coverage, snapshot.candidate.records) !== snapshot.identity.candidateDigest
216
- || snapshot.baseline.digest !== snapshot.identity.baselineDigest || snapshot.candidate.digest !== snapshot.identity.candidateDigest) errors.push(diagnostic('identity-mismatch'));
217
- if (configDigest(snapshot.config) !== snapshot.identity.configDigest || snapshot.config.digest !== snapshot.identity.configDigest) errors.push(diagnostic('config-capture-mismatch'));
218
- if (!configBytesBound(snapshot)) errors.push(diagnostic('config-capture-mismatch'));
219
- if (structuredDigest('doc-task-scope-v1', snapshot.taskSemantics) !== snapshot.identity.taskScopeDigest) errors.push(diagnostic('identity-mismatch'));
220
- const config = snapshot.config.resolution.config;
221
- const derived = deriveDocFacts({ base: { files: deriveFiles(snapshot.baseline.records, config, { strict: true }) },
222
- candidate: { files: deriveFiles(snapshot.candidate.records, config, { strict: true }) }, config });
223
- if (stable(derived.facts) !== stable(snapshot.facts)
224
- || stable(deriveDocObligations(derived.facts)) !== stable(snapshot.obligations)) errors.push(diagnostic('identity-mismatch'));
225
- for (const obligation of snapshot.obligations) {
226
- const reason = snapshot.derivationReasons && snapshot.derivationReasons[obligation.id];
227
- if (obligation.strength === 'MUST' && obligation.applicability === 'N/A'
228
- && (!reason || reason.applicability !== 'N/A' || !text(reason.reason) || !Array.isArray(reason.factRefs) || !reason.factRefs.length)) {
229
- errors.push(diagnostic('na-reason-missing', { obligationId: obligation.id }));
230
- }
231
- }
232
- } catch (error) {
233
- const code = error && ['invalid-input', 'inventory-incomplete', 'inventory-unsupported'].includes(error.message)
234
- ? error.message : 'invalid-input';
235
- errors.push(diagnostic(code));
236
- }
237
- return errors;
238
- }
239
-
240
- function reconcileDocResults(input = {}) {
241
- const { snapshot, accepted, checkerOutput, mode = 'verification' } = record(input) ? input : {};
242
- const diagnostics = [];
243
- const unsatisfied = [];
244
- const results = Array.isArray(checkerOutput && checkerOutput.results) ? checkerOutput.results : [];
245
- const base = { decision: 'unresolved', eligible: false, expectedMustIds: [], checkedMustIds: [], results, unsatisfied, diagnostics };
246
- if (!record(snapshot) || !record(accepted) || !record(checkerOutput) || !Array.isArray(checkerOutput.results)
247
- || !results.every(record) || !Array.isArray(checkerOutput.diagnostics) || !checkerOutput.diagnostics.every(record)
248
- || !['verification', 'review'].includes(mode)
249
- || !['ready', 'unresolved', 'unavailable'].includes(accepted.state)
250
- || !Array.isArray(accepted.diagnostics) || !accepted.diagnostics.every(record)
251
- || !Array.isArray(accepted.rejected) || !accepted.rejected.every(record) || !record(accepted.acceptedIndex)) {
252
- diagnostics.push(diagnostic('invalid-input'));
253
- return base;
254
- }
255
- diagnostics.push(...validateSnapshot(snapshot));
256
- if (!Array.isArray(snapshot.obligations) || !snapshot.obligations.every(o => record(o) && record(o.scope) && Array.isArray(o.scope.paths))) return base;
257
- const expected = snapshot.obligations.filter(o => o.strength === 'MUST' && o.applicability !== 'N/A');
258
- base.expectedMustIds = expected.map(o => o.id).sort(compare);
259
- const selected = mode === 'review' ? expected.filter(o => o.capability === 'quality-review') : expected;
260
- base.checkedMustIds = selected.map(o => o.id).sort(compare);
261
- const fail = (code, obligationId, state = 'pending') => {
262
- diagnostics.push(diagnostic(code, obligationId ? { obligationId } : {}));
263
- if (obligationId) unsatisfied.push({ obligationId, state, reasonCode: code });
264
- };
265
- if (diagnostics.length) return base;
266
- const capturedArtifacts = Object.fromEntries(snapshot.candidate.records.filter(r => r.presence === 'present').map(r => [r.path, { digest: r.digest }]));
267
- const capturedBaseline = { digest: snapshot.identity.baselineDigest,
268
- artifacts: Object.fromEntries(snapshot.baseline.records.filter(r => r.presence === 'present').map(r => [r.path, { digest: r.digest }])) };
269
- if (stable(accepted.checkerInputs?.artifacts) !== stable(capturedArtifacts)
270
- || stable(accepted.checkerInputs?.baseline) !== stable(capturedBaseline)
271
- || stable(accepted.checkerInputs?.obligations) !== stable(snapshot.obligations)) fail('artifact-mismatch');
272
- if (!sameIdentity(snapshot.identity, accepted.identity) || stable(snapshot.originContext) !== stable(accepted.originContext)) fail('identity-mismatch');
273
- if (snapshot.identity.configDigest !== accepted.identity?.configDigest) fail('config-capture-mismatch');
274
- for (const item of [...(accepted.diagnostics || []), ...(accepted.rejected || [])]) {
275
- diagnostics.push(item);
276
- // Only rejected evidence for a checked expected MUST, or a global origin/identity fault, gates credit;
277
- // a rejected SHOULD or N/A event stays a visible diagnostic (PR #353 review P2).
278
- if (!item.obligationId || selected.some(o => o.id === item.obligationId)) {
279
- unsatisfied.push({ obligationId: item.obligationId || 'origin', state: item.code === 'origin-unavailable' ? 'unavailable' : 'pending', reasonCode: item.code });
280
- }
281
- }
282
- if (accepted.state === 'unavailable') fail('origin-unavailable');
283
- if (checkerOutput?.unavailable) fail('checker-unavailable');
284
- const known = new Set(snapshot.obligations.map(o => o.id));
285
- for (const result of results) if (!known.has(result.obligationId)) fail('result-misattributed', result.obligationId);
286
- for (const obligation of selected) {
287
- const id = obligation.id;
288
- if (obligation.applicability === 'unknown') { fail('unknown-applicability', id, 'unknown'); continue; }
289
- const matches = results.filter(r => r.obligationId === id);
290
- if (matches.length !== 1) { fail(matches.length ? 'result-duplicate' : 'result-missing', id); continue; }
291
- const result = matches[0];
292
- if (result.observation !== 'observed' || result.outcome !== 'pass') {
293
- const hasAccepted = Object.values(accepted.acceptedIndex || {}).some(item => item.obligationId === id);
294
- fail(hasAccepted ? 'result-not-pass' : 'result-missing', id);
295
- continue;
296
- }
297
- const artifactDigest = obligation.scope.paths.length
298
- ? obligation.scope.paths.map(p => `${p}=${capturedArtifacts[p]?.digest || 'missing'}`).join('|')
299
- : snapshot.identity.baselineDigest;
300
- if (result.baseDigest !== snapshot.identity.baselineDigest || result.artifactDigest !== artifactDigest) fail('result-misattributed', id);
301
- if (!Array.isArray(result.recordRefs) || !result.recordRefs.length) { fail('result-untrusted', id); continue; }
302
- for (const ref of result.recordRefs) {
303
- const item = accepted.acceptedIndex?.[ref];
304
- if (!item || item.obligationId !== id || !sameIdentity(item.identity, snapshot.identity)
305
- || !text(item.originRef) || stable(item.paths) !== stable(obligation.scope.paths)
306
- || item.artifactBinding !== snapshot.identity.candidateDigest) fail('result-untrusted', id);
307
- }
308
- }
309
- // Validation failures must never be hidden by a cached report or a passing result subset.
310
- // Global faults and diagnostics for a checked expected MUST block; SHOULD/N/A diagnostics stay visible only.
311
- const blocking = diagnostics.filter(item => !item.obligationId || selected.some(o => o.id === item.obligationId));
312
- // Checker diagnostics stay visible; eligibility is decided from the expected MUST set above.
313
- // In particular, later verifier diagnostics cannot stall an independent review.
314
- if (Array.isArray(checkerOutput.diagnostics)) diagnostics.push(...checkerOutput.diagnostics);
315
- if (blocking.length || unsatisfied.length) {
316
- if (blocking.some(d => ['origin-unavailable', 'checker-unavailable'].includes(d.code))) base.decision = 'unavailable';
317
- return base;
318
- }
319
- if (!selected.length) { base.decision = 'legacy'; diagnostics.push(diagnostic('no-document-musts')); return base; }
320
- base.decision = 'eligible';
321
- base.eligible = true;
322
- return base;
323
- }
324
-
325
- function checkAcceptedDocEvidence(input = {}) {
326
- const { snapshot, accepted, mode = 'verification' } = record(input) ? input : {};
327
- let checkerOutput;
328
- try {
329
- if (!accepted?.checkerInputs || !snapshot) throw new Error('invalid-input');
330
- checkerOutput = checkDocObligations({ ...accepted.checkerInputs, obligations: snapshot.obligations });
331
- } catch { checkerOutput = { results: [], diagnostics: [], unavailable: true }; }
332
- return reconcileDocResults({ snapshot, accepted, checkerOutput, mode });
333
- }
334
-
335
- module.exports = { checkAcceptedDocEvidence, reconcileDocResults,
336
- _internals: { runtimeModule, text, record, bytes, stable, clone, sha, structuredDigest, snapshotDigest, configDigest, sameIdentity, diagnostic, validateSnapshot, compare, deriveFiles, semanticRelevance, originBound, configBytesBound } };