harness-everything 1.3.0 → 1.3.2

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 (216) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/AGENTS.md +1 -1
  4. package/CHANGELOG.md +14 -0
  5. package/behavioral-evals/ledger-pairs/README.md +53 -0
  6. package/behavioral-evals/ledger-pairs/arm.js +359 -0
  7. package/behavioral-evals/ledger-pairs/fixture.js +138 -0
  8. package/behavioral-evals/ledger-pairs/preflight.js +96 -0
  9. package/behavioral-evals/ledger-pairs/score.js +155 -0
  10. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/README.md +108 -0
  11. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-plan.json +14 -0
  12. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-result.json +35 -0
  13. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-plan.json +14 -0
  14. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-result.json +35 -0
  15. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-plan.json +14 -0
  16. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-result.json +35 -0
  17. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-plan.json +14 -0
  18. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-result.json +35 -0
  19. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-plan.json +14 -0
  20. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-result.json +35 -0
  21. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-plan.json +14 -0
  22. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-result.json +35 -0
  23. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-plan.json +14 -0
  24. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-result.json +28 -0
  25. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-plan.json +14 -0
  26. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-result.json +35 -0
  27. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-plan.json +13 -0
  28. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-result.json +56 -0
  29. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-plan.json +13 -0
  30. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-result.json +56 -0
  31. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-plan.json +13 -0
  32. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-result.json +56 -0
  33. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-plan.json +13 -0
  34. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-result.json +56 -0
  35. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-plan.json +13 -0
  36. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-result.json +49 -0
  37. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-plan.json +13 -0
  38. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-result.json +49 -0
  39. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-plan.json +13 -0
  40. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-result.json +49 -0
  41. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-plan.json +13 -0
  42. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-result.json +56 -0
  43. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-plan.json +14 -0
  44. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-result.json +44 -0
  45. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/receipt.jsonl +17 -0
  46. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-plan.json +14 -0
  47. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-result.json +41 -0
  48. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/receipt.jsonl +58 -0
  49. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-plan.json +14 -0
  50. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-result.json +50 -0
  51. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/receipt.jsonl +101 -0
  52. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-plan.json +14 -0
  53. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-result.json +44 -0
  54. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/receipt.jsonl +29 -0
  55. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-plan.json +14 -0
  56. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-result.json +44 -0
  57. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/receipt.jsonl +23 -0
  58. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-plan.json +14 -0
  59. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-result.json +34 -0
  60. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/receipt.jsonl +24 -0
  61. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-plan.json +14 -0
  62. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-result.json +47 -0
  63. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/receipt.jsonl +69 -0
  64. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-plan.json +14 -0
  65. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-result.json +44 -0
  66. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/receipt.jsonl +65 -0
  67. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/run-order.sh +18 -0
  68. package/benchmarks/results/live-host/ledger-pairs-2026-11-28/score.json +1032 -0
  69. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/README.md +50 -0
  70. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/collect-rerun.txt +3 -0
  71. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/export-report.json +22 -0
  72. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/host-version.txt +1 -0
  73. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-1.json +18 -0
  74. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-2.json +18 -0
  75. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/labels-observed-excerpt.jsonl +2 -0
  76. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/observations-index-excerpt.json +26 -0
  77. package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/plugin-load-lines.txt +1 -0
  78. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/README.md +46 -0
  79. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/observations-index-excerpt.json +16 -0
  80. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/plugin-load-lines.txt +2 -0
  81. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/run-marks.txt +6 -0
  82. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-probe.js +16 -0
  83. package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-trace.jsonl +167 -0
  84. package/ci/archive/325-prep/README.md +9 -2
  85. package/ci/archive/325-prep/doc-reconciliation-red.js +34 -8
  86. package/ci/fixtures/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
  87. package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
  88. package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
  89. package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
  90. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  91. package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
  92. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
  93. package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
  94. package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
  95. package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
  96. package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
  97. package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
  98. package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
  99. package/ci/fixtures/stop/fail-session-writes.js +109 -0
  100. package/ci/fixtures/workflow-contract/cases.json +3355 -0
  101. package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
  102. package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
  103. package/ci/mechanism-2an-workflow-replay.test.js +324 -0
  104. package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
  105. package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
  106. package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
  107. package/ci/mechanism-325-3b-preparation.test.js +208 -49
  108. package/ci/mechanism-325-3b-s1-review.test.js +20 -828
  109. package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
  110. package/ci/mechanism-325-f3-derived-views.test.js +140 -0
  111. package/ci/mechanism-332-fable-directive.test.js +180 -0
  112. package/ci/mechanism-341-opencode-lane.test.js +164 -284
  113. package/ci/mechanism-35-verification-contract.test.js +246 -0
  114. package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
  115. package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
  116. package/ci/mechanism-397-opencode-observations.test.js +151 -18
  117. package/ci/mechanism-552-ledger-pairs.test.js +159 -0
  118. package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
  119. package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
  120. package/ci/mechanism-553-p3-plan-start.test.js +212 -0
  121. package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
  122. package/ci/mechanism-553-stop.test.js +427 -0
  123. package/ci/mechanism-553-t2a-derive.test.js +110 -0
  124. package/ci/mechanism-553-t2c-derive.test.js +94 -0
  125. package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
  126. package/ci/mechanism-outline-sanitizer.test.js +0 -8
  127. package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
  128. package/ci/mechanism-prb-outline-review.test.js +101 -3283
  129. package/ci/router-workflow-plan.test.js +61 -21
  130. package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
  131. package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
  132. package/docs/doc-workflow-reconciliation.md +17 -2
  133. package/docs/document-lifecycle.md +6 -2
  134. package/docs/platform-capabilities.md +63 -16
  135. package/docs/platform-compatibility.json +5 -5
  136. package/harness-everything/SKILL.md +1 -1
  137. package/harness-everything/scripts/routing-keywords.json +0 -2
  138. package/harness-everything/scripts/tier-router.js +105 -11
  139. package/hooks/hooks.json +0 -46
  140. package/hooks/scripts/lib/workflow-obligations.js +0 -55
  141. package/hooks/scripts/state-persist.js +7 -95
  142. package/hooks/scripts/workflow-disposition.js +0 -2
  143. package/hooks/scripts/workflow-stop-gate.js +17 -30
  144. package/opencode-plugin/index.mjs +6 -70
  145. package/opencode-plugin/plugin.json +1 -1
  146. package/package.json +1 -1
  147. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  148. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  149. package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +0 -55
  150. package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
  151. package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
  152. package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
  153. package/plugins/harness-everything/plugin.json +1 -1
  154. package/plugins/harness-everything/rules/AGENTS.md +1 -1
  155. package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
  156. package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +0 -2
  157. package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +105 -11
  158. package/sbom.cdx.json +7 -7
  159. package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
  160. package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
  161. package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
  162. package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
  163. package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
  164. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
  165. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
  166. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
  167. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
  168. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
  169. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
  170. package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
  171. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
  172. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
  173. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
  174. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
  175. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
  176. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
  177. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
  178. package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
  179. package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
  180. package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
  181. package/ci/lib/doc-reconciliation-file-spy.js +0 -23
  182. package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
  183. package/ci/lib/doc-reconciliation-replay.js +0 -104
  184. package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
  185. package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
  186. package/ci/mechanism-325-3b-s1.test.js +0 -188
  187. package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
  188. package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
  189. package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
  190. package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
  191. package/ci/mechanism-325-f4-invariants.test.js +0 -606
  192. package/ci/mechanism-325-f4-projections.test.js +0 -392
  193. package/ci/mechanism-325-f4-qualification.test.js +0 -228
  194. package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
  195. package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
  196. package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  197. package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  198. package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  199. package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  200. package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  201. package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  202. package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  203. package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  204. package/hooks/scripts/w6-state-operations.js +0 -239
  205. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
  206. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
  207. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
  208. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
  209. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
  210. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
  211. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
  212. package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
  213. package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
  214. package/scripts/system-one-eval-laya.js +0 -112
  215. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
  216. /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
@@ -1,482 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const crypto = require('crypto');
6
- const { execFileSync } = require('child_process');
7
- const { atomicWriteJson } = require('./fable-contracts');
8
- const { canonical, key } = require('./workflow-isolation');
9
-
10
- const enabled = () => process.env.HARNESS_DOC_RECONCILIATION_PILOT === '1';
11
- const text = value => typeof value === 'string' && value.trim().length > 0;
12
-
13
- function git(root, args) {
14
- const env = { ...process.env };
15
- for (const key of Object.keys(env)) if (key.startsWith('GIT_')) delete env[key];
16
- try {
17
- return execFileSync('git', ['-C', root, ...args], {
18
- env, encoding: 'utf8', timeout: 10000, maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'],
19
- });
20
- } catch (cause) {
21
- throw new Error('baseline-unavailable', { cause });
22
- }
23
- }
24
-
25
- function runtimeModule(name) {
26
- for (const relative of ['../../../harness-everything/scripts', '../../../skills/harness-everything/scripts']) {
27
- const file = path.resolve(__dirname, relative, name + '.js');
28
- if (fs.existsSync(file)) return require(file);
29
- }
30
- throw new Error('document runtime unavailable');
31
- }
32
-
33
- // Only capture at plan/start. A later credit assessment must never advance the baseline to HEAD.
34
- function captureBaseline(context) {
35
- if (!enabled()) return;
36
- try {
37
- if (!context.workflow.docReconciliationBaseline) {
38
- const root = canonical(git(context.root, ['rev-parse', '--show-toplevel']).trim());
39
- const commit = git(root, ['rev-parse', '--verify', 'HEAD^{commit}']).trim();
40
- const tree = git(root, ['rev-parse', '--verify', `${commit}^{tree}`]).trim();
41
- context.workflow.docReconciliationBaseline = { root, commit, tree };
42
- } else if (!context.workflow.docReconciliationBaseline.tree) {
43
- const pin = context.workflow.docReconciliationBaseline;
44
- pin.tree = git(pin.root, ['rev-parse', '--verify', `${pin.commit}^{tree}`]).trim();
45
- }
46
- if (!context.workflow.docReconciliationTask) {
47
- const plan = context.workflow.pendingPlan || context.workflow.workflowPlan;
48
- // workflow-obligations is a hook-lib sibling in every layout, not a skill runtime script.
49
- const loaded = plan && require('./workflow-obligations').loadObligationSet(context, plan);
50
- const requirementIds = loaded?.set?.requirements?.map(item => item.id);
51
- if (Array.isArray(requirementIds) && requirementIds.length && requirementIds.every(id => typeof id === 'string' && id)) {
52
- const baseline = context.workflow.docReconciliationBaseline;
53
- const resolver = runtimeModule('project-docs-resolver');
54
- const configSources = configSourcePaths(resolver).map(relative => {
55
- const bytes = bytesAtBaseline(baseline.root, baseline.commit, relative);
56
- return [relative, bytes === null ? null : crypto.createHash('sha256').update(bytes).digest('hex')];
57
- });
58
- const hash = value => crypto.createHash('sha256').update(JSON.stringify(value)).digest('hex');
59
- const workspaceId = 'ws-' + hash({ workspaceRoot: canonical(baseline.root) });
60
- context.workflow.docReconciliationTask = {
61
- schema: 'harness.doc-reconciliation-task-pin.v1',
62
- taskId: `task-${requirementIds.join('+')}`, requirementIds,
63
- requirementDigest: hash(requirementIds), sessionId: context.sessionId,
64
- workflowId: context.workflow.workflowId, workspaceId,
65
- baselineCommit: baseline.commit, baselineRoot: baseline.root,
66
- configDigest: hash(configSources),
67
- };
68
- }
69
- }
70
- } catch {
71
- // Absence is intentionally retained; credit assessment will fail closed.
72
- }
73
- }
74
-
75
- // PR #351 review P1 (config authority): derivation runs on the current config, so a candidate
76
- // config edit could de-scope a baseline-governed path. Every resolver-selectable config source —
77
- // `.agents/harness-everything/project-docs.json` and each host `<home>/harness-everything/manifest.json`
78
- // for the resolver's PLATFORM_HOMES — is byte-compared at the recorded baseline commit and in the
79
- // working tree. An edit, an addition or a removal all fail closed before derivation; absence of a
80
- // source on either side is allowed and only a difference is fatal.
81
- const PROJECT_DOCS_CONFIG_RELPATH = '.agents/harness-everything/project-docs.json';
82
-
83
- function configSourcePaths(resolver) {
84
- return [
85
- PROJECT_DOCS_CONFIG_RELPATH,
86
- ...(resolver.PLATFORM_HOMES || []).map(home => `${home}/harness-everything/manifest.json`),
87
- ];
88
- }
89
-
90
- function bytesAtBaseline(root, commit, relative) {
91
- const listed = git(root, ['ls-tree', '-r', '--name-only', '-z', commit, '--', relative]);
92
- if (!listed.split('\0').includes(relative)) return null; // absent at the baseline is allowed
93
- return git(root, ['show', `${commit}:${relative}`]); // other Git failures stay baseline-unavailable
94
- }
95
-
96
- function bytesInTree(root, relative) {
97
- try {
98
- return fs.readFileSync(path.join(root, relative), 'utf8');
99
- } catch (error) {
100
- if (error.code === 'ENOENT') return null; // absent in the working tree is allowed
101
- throw error;
102
- }
103
- }
104
-
105
- function assertConfigScopeUnchanged(root, baseline, resolver) {
106
- for (const relative of configSourcePaths(resolver)) {
107
- if (bytesAtBaseline(root, baseline.commit, relative) !== bytesInTree(root, relative)) {
108
- throw new Error('config-scope-changed');
109
- }
110
- }
111
- }
112
-
113
- function collect(context) {
114
- const baseline = context.workflow.docReconciliationBaseline;
115
- if (!baseline) throw new Error('baseline-unavailable');
116
- const root = canonical(git(context.root, ['rev-parse', '--show-toplevel']).trim());
117
- if (!text(baseline.root) || key(root) !== key(baseline.root)
118
- || !/^[0-9a-f]{40,64}$/.test(baseline.commit)) throw new Error('baseline-unavailable');
119
- const resolver = runtimeModule('project-docs-resolver');
120
- const resolved = resolver.resolveDocsConfig(root);
121
- if (!['project', 'host'].includes(resolved.status)) throw new Error('config-unavailable');
122
- assertConfigScopeUnchanged(root, baseline, resolver);
123
- const { readGitBaseInventory, scanWorkspaceFiles } = runtimeModule('doc-lifecycle');
124
- // Broaden artifact discovery only, never the config passed to obligation derivation. Code/REQ-test
125
- // facts require baseline bytes outside governed document globs as well.
126
- const base = readGitBaseInventory(root, baseline.commit, { governed: [{ path: '**/*', role: 'reference' }] });
127
- const basePaths = git(root, ['ls-tree', '-r', '--name-only', '-z', baseline.commit]).split('\0').filter(Boolean);
128
- if (!base.available) throw new Error('baseline-unavailable');
129
- if (base.files.length !== basePaths.length) throw new Error('scope-unavailable');
130
- const paths = [...new Set(git(root, ['ls-files', '-c', '-o', '--exclude-standard', '-z']).split('\0').filter(Boolean))];
131
- const existing = paths.filter(relative => {
132
- try {
133
- if (!fs.lstatSync(path.join(root, relative)).isFile()) throw new Error('scope-unavailable');
134
- return true;
135
- } catch (error) {
136
- if (error.code === 'ENOENT') return false; // tracked deletion
137
- throw error;
138
- }
139
- });
140
- const candidate = scanWorkspaceFiles(root, { paths: existing });
141
- if (candidate.length !== existing.length) throw new Error('scope-unavailable');
142
- const snapshots = files => ({ files: Object.fromEntries(files.map(item => [item.path, item.bytes.toString('utf8')])) });
143
- const { deriveDocFacts, deriveDocObligations } = runtimeModule('doc-obligations');
144
- const { facts } = deriveDocFacts({ base: snapshots(base.files), candidate: snapshots(candidate), config: resolved.config, inventory: { complete: true } });
145
- return deriveDocObligations(facts).filter(item => item.strength === 'MUST' && item.applicability !== 'N/A');
146
- }
147
-
148
- // S2b credit chain (F4): produce the snapshot, accept the origin-provider events, and check them against the expected
149
- // MUSTs. Credit only when the core marks the evidence eligible. Production has no qualification, so it stays withheld.
150
- function creditChain(context, set, dependencies = {}) {
151
- const hostId = activeHostFor(context);
152
- const providerModule = require('./doc-reconciliation-provider');
153
- const captureView = hostId === 'opencode' ? providerModule.readOpencodeCaptureView(context.sessionDir)
154
- : hostId === 'claude-code' ? providerModule.readCaptureView(context.sessionDir)
155
- : { records: [], tampered: false };
156
- if (captureView.tampered) {
157
- return { eligible: false, outlineEvidence: { outcome: 'none', observation: 'unresolved', reason: 'journal-tampered' },
158
- diagnostics: [{ code: 'journal-tampered', message: 'the capture journal no longer matches its immutable event records' }] };
159
- }
160
- if (!['claude-code', 'opencode'].includes(hostId)) {
161
- return { eligible: false, outlineEvidence: { outcome: 'none', observation: 'unresolved', reason: 'unsupported-host' },
162
- diagnostics: [{ code: 'unsupported-host', message: `no document origin provider is registered for ${String(hostId)}` }] };
163
- }
164
- const { produceDocSnapshot } = require('./doc-reconciliation-producer');
165
- const { acceptDocEvents } = require('./doc-reconciliation-events');
166
- const { checkAcceptedDocEvidence } = require('./doc-reconciliation-core');
167
- const baseline = context.workflow.docReconciliationBaseline;
168
- const requirements = Array.isArray(set?.requirements) ? set.requirements : [];
169
- const requirementIds = requirements.map(item => item.id);
170
- const derivedTaskId = `task-${requirementIds.join('+') || 'none'}`;
171
- const taskBinding = context.workflow.docReconciliationTask || null;
172
- const taskId = taskBinding?.taskId || derivedTaskId;
173
- if (taskBinding && (taskBinding.taskId !== derivedTaskId || taskBinding.workflowId !== context.workflow.workflowId
174
- || taskBinding.sessionId !== context.sessionId || taskBinding.baselineCommit !== baseline?.commit
175
- || !text(taskBinding.baselineRoot) || !text(baseline?.root)
176
- || key(taskBinding.baselineRoot) !== key(baseline.root)
177
- || taskBinding.requirementDigest !== crypto.createHash('sha256').update(JSON.stringify(requirementIds)).digest('hex')) ) {
178
- return { eligible: false, outlineEvidence: { outcome: 'none', observation: 'unresolved', reason: 'task-binding-mismatch' },
179
- diagnostics: [{ code: 'task-binding-mismatch', message: 'the requirement set or original B differs from the task pin' }] };
180
- }
181
- const sessionId = context.sessionId;
182
- const { createClaudeOriginProvider, createOpencodeOriginProvider, journalExecutors } = providerModule;
183
- const captures = captureView.records;
184
- const principals = hostId === 'opencode'
185
- ? { author: sessionId, executors: [sessionId] }
186
- : { author: sessionId, executors: journalExecutors(captures, sessionId) };
187
- const createOriginProvider = hostId === 'opencode' ? createOpencodeOriginProvider : createClaudeOriginProvider;
188
- const providerInput = {
189
- hostId,
190
- sessionId,
191
- workspaceRoot: context.root,
192
- workflowId: context.workflow.workflowId,
193
- workflowRevision: context.workflow.revision,
194
- taskId,
195
- sessionDir: context.sessionDir,
196
- taskBinding,
197
- principals,
198
- baseline,
199
- captures,
200
- allowInFlightW6ToolUseId: dependencies.allowInFlightW6ToolUseId || null,
201
- };
202
- const originProvider = dependencies.originProvider || createOriginProvider(providerInput);
203
- const produced = produceDocSnapshot({
204
- workspaceRoot: context.root,
205
- baseline,
206
- workflow: { workflowId: context.workflow.workflowId, sessionId, workflowRevision: context.workflow.revision },
207
- task: { taskId, requirements },
208
- scope: { prdRoot: 'docs/prd/' },
209
- activeHost: hostId,
210
- prdRoot: 'docs/prd/',
211
- }, { originProvider });
212
- if (produced.state !== 'ready' || !produced.snapshot) return {
213
- eligible: false,
214
- outlineEvidence: { outcome: 'none', observation: 'unresolved', reason: produced.diagnostics?.[0]?.code || 'snapshot-unavailable' },
215
- diagnostics: produced.diagnostics || [],
216
- unsatisfied: [],
217
- };
218
- const eventRefs = captureReferences(context);
219
- const accepted = acceptDocEvents({ snapshot: produced.snapshot, eventRefs }, { originProvider });
220
- const checked = checkAcceptedDocEvidence({ snapshot: produced.snapshot, accepted, mode: 'verification' });
221
- // Credit covers only the expected MUSTs that were both accepted and satisfied (passing, observed). N/A never counts.
222
- const passing = new Set((checked.results || []).filter(r => r.observation === 'observed' && r.outcome === 'pass').map(r => r.obligationId));
223
- const expected = new Set(checked.checkedMustIds || []);
224
- const satisfied = produced.snapshot.obligations.filter(o => o.strength === 'MUST' && o.applicability !== 'N/A' && expected.has(o.id) && passing.has(o.id));
225
- const outlineObligation = produced.snapshot.obligations.find(item => item.capability === 'outline-confirmation');
226
- const outlineResult = outlineObligation && (checked.results || []).find(item => item.obligationId === outlineObligation.id);
227
- const outlineRefs = Object.entries(accepted.acceptedIndex || {}).filter(([, item]) => item.capability === 'outline-confirmation').map(([ref]) => ref);
228
- const outlineEvidence = {
229
- status: outlineResult?.observation === 'observed' && outlineResult?.outcome === 'pass' ? 'pass' : 'unresolved',
230
- outcome: outlineResult?.outcome || 'none',
231
- observation: outlineResult?.observation || 'unresolved',
232
- recordRefs: outlineResult?.recordRefs || [],
233
- acceptedRefs: outlineRefs,
234
- diagnostics: [...(accepted.diagnostics || []), ...(accepted.rejected || []), ...(checked.diagnostics || [])]
235
- .filter(item => !item?.obligationId || item.obligationId === outlineObligation?.id),
236
- };
237
- return {
238
- eligible: checked.eligible === true,
239
- capabilities: checked.eligible === true ? [...new Set(satisfied.map(o => o.capability))] : [],
240
- satisfiedObligationIds: satisfied.map(o => o.id),
241
- unsatisfied: checked.unsatisfied || [],
242
- acceptedRefs: Object.keys(accepted.acceptedIndex || {}),
243
- outlineEvidence,
244
- diagnostics: [...(accepted.diagnostics || []), ...(checked.diagnostics || [])],
245
- rejected: accepted.rejected || [],
246
- };
247
- }
248
-
249
- // Report diagnostics are objects with the obligation they concern (F12); a global fault has obligationId null.
250
- function diagnosticOf(item) {
251
- if (item && typeof item === 'object') return { ...item, code: item.code || 'unknown', obligationId: item.obligationId ?? null };
252
- return { code: String(item), obligationId: null };
253
- }
254
-
255
- // Review-mode refusal (F4 I2a): with the pilot ON in a supported (non-Fable) workflow, a review step PASS needs an
256
- // independent quality-review record. The provider's own independence rules decide it: a host agent_id that differs from
257
- // the author session, an explicit approve verdict, a non-empty summary and the bound final-artifact digest.
258
- function reviewRequired(set) {
259
- return enabled() && set?.stepBindingsEnabled === true && !String(set?.strategy || '').startsWith('fable-');
260
- }
261
-
262
- // The review step is independent of credit qualification: the step records host-observed independence, while document
263
- // credit itself still needs the validated qualification (assess).
264
- function independentReviewAccepted(context) {
265
- if (activeHostFor(context) !== 'claude-code') return false;
266
- const { reviewRecordIndependent, journalExecutors } = require('./doc-reconciliation-provider');
267
- const view = require('./doc-reconciliation-provider').readCaptureView(context.sessionDir);
268
- if (view.tampered) return false;
269
- const captures = view.records;
270
- const principals = { author: context.sessionId, executors: journalExecutors(captures, context.sessionId) };
271
- const pin = context.workflow.docReconciliationBaseline;
272
- return captures.some(item => recordOf(item) && item.session_id === context.sessionId
273
- && recordOf(item.observedIdentity) && item.observedIdentity.workflowId === context.workflow.workflowId
274
- && item.observedIdentity.workflowRevision === context.workflow.revision
275
- && (!pin || (recordOf(item.observedIdentity.baselinePin) && item.observedIdentity.baselinePin.commit === pin.commit))
276
- && reviewRecordIndependent(item, captures, principals));
277
- }
278
-
279
- function recordOf(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); }
280
-
281
- function activeHostFor(context) {
282
- return context.activeHost === undefined || context.activeHost === null ? 'claude-code' : context.activeHost;
283
- }
284
-
285
- // The session capture records are the only host-event source. A missing journal means no events; a journal that no longer
286
- // equals its immutable event files is tampered and yields no events, so the chain withholds.
287
- function readCaptures(context) {
288
- const provider = require('./doc-reconciliation-provider');
289
- const hostId = activeHostFor(context);
290
- if (hostId === 'opencode') return provider.readOpencodeCaptureView(context.sessionDir).records;
291
- if (hostId === 'claude-code') return provider.readCaptureView(context.sessionDir).records;
292
- return [];
293
- }
294
-
295
- // Only explicit PostToolUse doc-check candidates are offered; ordinary Edit or Agent results are not (R3-01).
296
- const docCheckCandidate = item => item.event === 'PostToolUse'
297
- && require('./doc-reconciliation-provider').resolveDocCheckInvocation(item.command, item.cwd).kind !== 'not-candidate';
298
-
299
- function outlineReviewCaptureRefs(sessionDir, taskId) {
300
- const refs = new Set();
301
- if (!text(taskId)) return refs;
302
- const attempts = path.join(sessionDir, 'doc-reconciliation', 'outline-confirmation', taskId, 'attempts');
303
- try {
304
- for (const entry of fs.readdirSync(attempts, { withFileTypes: true })) {
305
- if (!entry.isDirectory()) continue;
306
- try {
307
- const handoff = JSON.parse(fs.readFileSync(path.join(attempts, entry.name, 'handoff.json'), 'utf8'));
308
- if (handoff.taskId === taskId && typeof handoff.reviewCaptureRef === 'string') refs.add(handoff.reviewCaptureRef);
309
- } catch { /* malformed handoff cannot add review credit */ }
310
- }
311
- } catch { /* no attempts yet */ }
312
- return refs;
313
- }
314
-
315
- function outlineDispatchReferences(captures, taskId, sessionDir) {
316
- if (!text(taskId)) return [];
317
- const candidates = (Array.isArray(captures) ? captures : []).filter(item => recordOf(item)
318
- && item.event === 'PreToolUse' && ['Task', 'Agent'].includes(item.tool_name)
319
- && text(item.ref) && item.outlineDispatch?.taskId === taskId && text(item.outlineDispatch.attemptId));
320
- if (!candidates.length) return [];
321
- if (text(sessionDir)) {
322
- const provider = require('./doc-reconciliation-provider');
323
- const attemptIds = [...new Set(candidates.map(item => item.outlineDispatch.attemptId))];
324
- const resolved = attemptIds.map(attemptId => ({ attemptId,
325
- attempt: provider._internals.resolveOutlineAttempt({ sessionDir, taskId, attemptId }) }));
326
- const current = resolved.filter(item => item.attempt.state === 'accepted');
327
- if (current.length === 1) {
328
- const dispatches = candidates.filter(item => item.outlineDispatch.attemptId === current[0].attemptId);
329
- return dispatches.length ? [`${dispatches[0].ref}#outline-confirmation`] : [];
330
- }
331
- if (current.length > 1 || attemptIds.length > 1) return [];
332
- }
333
- const tuples = [...new Set(candidates.map(item => `${item.outlineDispatch.attemptId}\0${item.tool_use_id || ''}\0${item.outlineDispatch.dispatchInputDigest || ''}`))];
334
- if (tuples.length > 1 && !candidates.some(item => item.outlineDispatch.state === 'unresolved')) return [];
335
- return [`${candidates[0].ref}#outline-confirmation`];
336
- }
337
-
338
- function captureReferences(context) {
339
- const captures = readCaptures(context);
340
- if (activeHostFor(context) === 'opencode') {
341
- return captures.filter(item => typeof item?.call_id === 'string' && item.call_id.trim())
342
- .flatMap(item => ['doc-lint', 'link-check'].map(capability => `${item.call_id}#${capability}`));
343
- }
344
- const candidates = captures
345
- .filter(item => item && typeof item.ref === 'string' && (item.event === 'SubagentStop' || docCheckCandidate(item)))
346
- .filter(item => item.event !== 'SubagentStop');
347
- const taskId = context.workflow.docReconciliationTask?.taskId;
348
- const outlineReviews = outlineReviewCaptureRefs(context.sessionDir, taskId);
349
- const reviews = captures.filter(item => item && typeof item.ref === 'string' && item.event === 'SubagentStop'
350
- && ['approve', 'reject'].includes(item.reviewVerdict) && !outlineReviews.has(item.ref));
351
- const references = [];
352
- for (const [index, capability] of ['doc-lint', 'link-check'].entries()) {
353
- const ordered = index ? candidates.slice(1).concat(candidates.slice(0, 1)) : candidates;
354
- references.push(...ordered.map(item => `${item.ref}#${capability}`));
355
- }
356
- const provider = require('./doc-reconciliation-provider');
357
- references.push(...candidates.filter(item => provider.resolveDocCheckInvocation(item.command, item.cwd).conflictAssessment === true)
358
- .map(item => `${item.ref}#conflict-check`));
359
- references.push(...candidates.filter(item => provider.resolveDocCheckInvocation(item.command, item.cwd).derivedView)
360
- .map(item => `${item.ref}#derived-regenerate`));
361
- references.push(...outlineDispatchReferences(captures, taskId, context.sessionDir));
362
- // The adapter accepts one event per capability; rotating candidate order lets separate valid runs fill each capability.
363
- return [...references, ...reviews.map(item => `${item.ref}#quality-review`)];
364
- }
365
-
366
- // R3-02: verification recorded before an installed-runtime change is withdrawn once the live doc-check leaves the pin.
367
- // Capture time sees the pristine runtime, so only assessment can catch a later change. Scoped to sessions that ran a doc-check.
368
- function withdrawChangedRuntimeVerification(context) {
369
- try {
370
- const provider = require('./doc-reconciliation-provider');
371
- const installed = provider.installedDocCheck();
372
- if (!installed || provider.fileDigest(installed) === provider.SHIPPED_DOC_CHECK_DIGEST) return;
373
- if (!readCaptures(context).some(item => {
374
- if (!item || item.event !== 'PostToolUse') return false;
375
- const invocation = provider.resolveDocCheckInvocation(item.command, item.cwd);
376
- return invocation.kind === 'accepted' || invocation.reason === 'implementation-pin-mismatch';
377
- })) return;
378
- const file = path.join(context.sessionDir, 'handoff-state.json');
379
- const handoff = JSON.parse(fs.readFileSync(file, 'utf8'));
380
- const genericAt = handoff.lastGenericVerifyAt;
381
- const hasGeneric = typeof genericAt === 'number' && Number.isFinite(genericAt);
382
- const hasDoc = typeof handoff.lastDocVerifyAt === 'number' && Number.isFinite(handoff.lastDocVerifyAt);
383
- if (!hasGeneric && !hasDoc && handoff.lastVerifyAt === undefined) return;
384
- delete handoff.lastDocVerifyAt;
385
- delete handoff.lastDocVerifyExitCode;
386
- if (hasGeneric) {
387
- handoff.lastVerifyAt = genericAt;
388
- if (Object.prototype.hasOwnProperty.call(handoff, 'lastGenericVerifyExitCode')) {
389
- handoff.lastVerifyExitCode = handoff.lastGenericVerifyExitCode;
390
- } else {
391
- delete handoff.lastVerifyExitCode;
392
- }
393
- } else {
394
- // Older aggregate-only state has unknown ownership; do not preserve it as unaffected evidence.
395
- delete handoff.lastVerifyAt;
396
- delete handoff.lastVerifyExitCode;
397
- }
398
- atomicWriteJson(file, handoff);
399
- } catch { /* fail-open: no handoff state yet, or nothing to withdraw */ }
400
- }
401
-
402
- // Assessment is deliberately negative-credit only in S1. Unsupported topologies never enter
403
- // generic step reconciliation, and failures (including report persistence) never escape to Stop.
404
- function assess(context, set, dependencies = {}) {
405
- if (!enabled()) return { withhold: false };
406
- withdrawChangedRuntimeVerification(context);
407
- const report = {
408
- schemaVersion: 1, reportOrigin: 'runtime', pilotStatus: 'unavailable', pilotCredit: false,
409
- identity: null, expectedMustIds: [], results: [], unsatisfied: [], diagnostics: [],
410
- outlineEvidence: { status: 'unresolved', outcome: 'none', observation: 'unresolved', acceptedRefs: [], recordRefs: [], diagnostics: [] },
411
- };
412
- const supported = set?.stepBindingsEnabled === true && !String(context.workflow.strategy || '').startsWith('fable-');
413
- let withhold = false;
414
- if (!supported) report.diagnostics.push('unsupported-workflow');
415
- else {
416
- try {
417
- const musts = collect(context);
418
- withhold = musts.length > 0;
419
- report.pilotStatus = 'unresolved';
420
- report.expectedMustIds = musts.map(item => item.id);
421
- report.unsatisfied = musts.map(item => ({
422
- obligationId: item.id, state: item.applicability === 'unknown' ? 'unknown' : 'pending',
423
- reasonCode: item.applicability === 'unknown' ? 'unknown-applicability' : 'producer-unavailable',
424
- }));
425
- if (!withhold) report.diagnostics.push('trusted-non-document-scope');
426
- const hasOutlineCapture = captureReferences(context).some(reference => reference.endsWith('#outline-confirmation'));
427
- if (withhold || hasOutlineCapture) {
428
- let chain;
429
- try { chain = creditChain(context, set, dependencies); }
430
- catch (error) { chain = { eligible: false, outlineEvidence: { status: 'unresolved', outcome: 'none',
431
- observation: 'unresolved', reason: 'collector-unavailable', acceptedRefs: [], recordRefs: [], diagnostics: [] },
432
- diagnostics: [{ code: 'collector-unavailable', message: String(error.message) }] }; }
433
- report.outlineEvidence = chain.outlineEvidence || report.outlineEvidence;
434
- report.acceptedRefs = chain.acceptedRefs || [];
435
- report.diagnostics.push(...(chain.diagnostics || []));
436
- if (withhold) {
437
- // The unsatisfied list is rewritten from the chain: a MUST that the chain did not satisfy stays listed (F3).
438
- const satisfied = new Set(chain.satisfiedObligationIds || []);
439
- report.unsatisfied = [
440
- ...musts.filter(item => !satisfied.has(item.id)).map(item => ({
441
- obligationId: item.id, state: item.applicability === 'unknown' ? 'unknown' : 'pending',
442
- reasonCode: item.applicability === 'unknown' ? 'unknown-applicability' : 'producer-unavailable',
443
- })),
444
- ...(chain.unsatisfied || []),
445
- ];
446
- report.creditedCapabilities = chain.eligible === true ? chain.capabilities : [];
447
- // Credit needs an empty unsatisfied list across both sources and at least one satisfied capability.
448
- withhold = !(chain.eligible === true && report.unsatisfied.length === 0 && report.creditedCapabilities.length > 0);
449
- report.pilotCredit = !withhold;
450
- report.pilotStatus = report.pilotCredit ? 'credited' : 'unresolved';
451
- }
452
- }
453
- } catch (error) {
454
- withhold = true;
455
- const reason = ['baseline-unavailable', 'config-unavailable', 'scope-unavailable', 'config-scope-changed'].includes(error.message)
456
- ? error.message : 'collector-unavailable';
457
- report.diagnostics.push(reason);
458
- report.unsatisfied.push({ obligationId: 'doc-change:scope', state: 'unavailable', reasonCode: reason });
459
- }
460
- }
461
- if (!withhold && dependencies.allowInFlightW6ToolUseId) {
462
- report.pilotCredit = false;
463
- report.pilotStatus = 'pending';
464
- report.creditedCapabilities = [];
465
- report.acceptedRefs = [];
466
- report.outlineEvidence = { status: 'pending', outcome: 'none', observation: 'pending',
467
- acceptedRefs: [], recordRefs: [], diagnostics: [{ code: 'state-operation-in-flight',
468
- message: 'the verification state operation has not completed its host result', obligationId: null }] };
469
- report.diagnostics.push({ code: 'state-operation-in-flight',
470
- message: 'the verification state operation has not completed its host result', obligationId: null });
471
- }
472
- report.diagnostics = report.diagnostics.map(diagnosticOf);
473
- try { atomicWriteJson(path.join(context.sessionDir, 'doc-reconciliation-pilot.json'), report); }
474
- catch {
475
- if (supported) withhold = true;
476
- console.error('[Workflow Reminder] Document pilot report unavailable; no document verification credit.');
477
- }
478
- return { withhold, report };
479
- }
480
-
481
- module.exports = { enabled, captureBaseline, assess, reviewRequired, independentReviewAccepted,
482
- _internals: { captureReferences, outlineDispatchReferences, outlineReviewCaptureRefs } };