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,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const assert = require('node:assert/strict');
4
- const crypto = require('node:crypto');
5
4
  const fs = require('node:fs');
6
5
  const os = require('node:os');
7
6
  const path = require('node:path');
@@ -11,8 +10,7 @@ const { createV2Driver } = require('./lib/opencode-v2-driver');
11
10
 
12
11
  const ROOT = path.resolve(__dirname, '..');
13
12
  const STOP_GATE = path.join(ROOT, 'hooks/scripts/workflow-stop-gate.js');
14
- const PILOT = path.join(ROOT, 'hooks/scripts/lib/doc-reconciliation-pilot.js');
15
- const savedEnv = Object.fromEntries(['HOME', 'HARNESS_STATE_HOME', 'HARNESS_WORKSPACE_ROOT', 'HARNESS_DOC_RECONCILIATION_PILOT'].map(key => [key, process.env[key]]));
13
+ const savedEnv = Object.fromEntries(['HOME', 'USERPROFILE', 'HARNESS_STATE_HOME', 'HARNESS_WORKSPACE_ROOT', 'HARNESS_DOC_RECONCILIATION_PILOT', 'HARNESS_TELEMETRY'].map(key => [key, process.env[key]]));
16
14
 
17
15
  function git(cwd, args) {
18
16
  const env = { ...process.env, GIT_AUTHOR_NAME: 'Harness test', GIT_AUTHOR_EMAIL: 'harness@example.invalid', GIT_COMMITTER_NAME: 'Harness test', GIT_COMMITTER_EMAIL: 'harness@example.invalid' };
@@ -88,7 +86,6 @@ function seedWorkflow(rootOrFixture, sessionId) {
88
86
  { id: 'verify-doc', stepType: 'verification', summary: 'Verify the governed retry change', acceptance: 'the objective checks are recorded' },
89
87
  ]), plan, plan.strategy, 'fixture workflow for the OpenCode reconciliation path');
90
88
  obligations.materializeExecutionObligations(context, plan);
91
- require(PILOT).captureBaseline(context);
92
89
  require(path.join(ROOT, 'hooks/scripts/lib/workflow-runtime.js')).saveWorkflow(context);
93
90
  return { sessionDir, payload };
94
91
  }
@@ -107,13 +104,15 @@ function writeEditState(sessionDir, values) {
107
104
  }));
108
105
  }
109
106
 
110
- async function withV2DocFixture(fn) {
111
- const d = await createV2Driver();
112
- const pilotSaved = Object.fromEntries(['HARNESS_WORKSPACE_ROOT', 'HARNESS_DOC_RECONCILIATION_PILOT'].map(key => [key, process.env[key]]));
107
+ async function withV2DocFixture(fn, options = {}) {
108
+ const d = await createV2Driver(options);
109
+ const pilotSaved = Object.fromEntries(['HARNESS_WORKSPACE_ROOT', 'HARNESS_DOC_RECONCILIATION_PILOT', 'HARNESS_TELEMETRY'].map(key => [key, process.env[key]]));
113
110
  try {
114
111
  initWorkspace(d.workspace);
115
112
  process.env.HARNESS_WORKSPACE_ROOT = d.workspace;
116
- process.env.HARNESS_DOC_RECONCILIATION_PILOT = '1';
113
+ process.env.HARNESS_TELEMETRY = 'local';
114
+ if (options.pilotFlag === undefined) delete process.env.HARNESS_DOC_RECONCILIATION_PILOT;
115
+ else process.env.HARNESS_DOC_RECONCILIATION_PILOT = options.pilotFlag;
117
116
  return await fn(d);
118
117
  } finally {
119
118
  for (const [key, value] of Object.entries(pilotSaved)) {
@@ -124,10 +123,19 @@ async function withV2DocFixture(fn) {
124
123
  }
125
124
  }
126
125
 
127
- function canonicalJson(value) {
128
- if (Array.isArray(value)) return value.map(canonicalJson);
129
- if (value && typeof value === 'object') return Object.fromEntries(Object.keys(value).sort().map(key => [key, canonicalJson(value[key])]));
130
- return value;
126
+ function readJson(file) {
127
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
128
+ }
129
+
130
+ function readTelemetryEvents(sessionDir) {
131
+ const file = path.join(path.dirname(path.dirname(sessionDir)), 'telemetry', 'events.jsonl');
132
+ if (!fs.existsSync(file)) return [];
133
+ return fs.readFileSync(file, 'utf8').trim().split(/\r?\n/).filter(Boolean).map(line => JSON.parse(line));
134
+ }
135
+
136
+ function readObservationRecords(observationsDir) {
137
+ const file = path.join(observationsDir, 'observations-index.json');
138
+ return fs.existsSync(file) ? readJson(file).records : [];
131
139
  }
132
140
 
133
141
  function restoreEnv() {
@@ -137,306 +145,178 @@ function restoreEnv() {
137
145
  }
138
146
  }
139
147
 
140
- test('existing Stop consumer writes a refused report without qualification', () => {
141
- const fixture = makeFixture();
142
- try {
143
- const control = seedWorkflow(fixture, 'stop-positive-control');
144
- const result = runJson(STOP_GATE, fixture.root, control.payload);
145
- const reportPath = path.join(control.sessionDir, 'doc-reconciliation-pilot.json');
146
- const report = fs.existsSync(reportPath) ? JSON.parse(fs.readFileSync(reportPath, 'utf8')) : null;
147
- assert.equal(result.status, 0, result.stderr);
148
- assert.equal(report?.pilotStatus, 'unresolved');
149
- assert.equal(report?.pilotCredit, false);
150
- assert.ok(report?.diagnostics?.length, 'existing consumer must retain a refusal diagnostic');
151
- } finally {
152
- fixture.cleanup();
153
- restoreEnv();
148
+ test('existing Stop consumer runs ordinary workflow Stop without writing an E1 pilot report', () => {
149
+ for (const [label, pilotFlag] of [['pilot-1', '1'], ['pilot-unset', undefined]]) {
150
+ const fixture = makeFixture();
151
+ try {
152
+ if (pilotFlag === undefined) delete process.env.HARNESS_DOC_RECONCILIATION_PILOT;
153
+ else process.env.HARNESS_DOC_RECONCILIATION_PILOT = pilotFlag;
154
+ const control = seedWorkflow(fixture, `stop-positive-control-${label}`);
155
+ const result = runJson(STOP_GATE, fixture.root, control.payload);
156
+ const reportPath = path.join(control.sessionDir, 'doc-reconciliation-pilot.json');
157
+ const workflow = readJson(path.join(control.sessionDir, 'workflow-run.json'));
158
+ assert.equal(result.status, 0, `${label}: ${result.stderr}`);
159
+ assert.match(result.stderr, /\[Workflow Reminder\] Unresolved workflow evidence:/, `${label}: ordinary Stop reminder still fires`);
160
+ assert.ok(Array.isArray(workflow.unresolved) && workflow.unresolved.length > 0, `${label}: ordinary Stop records unresolved obligations`);
161
+ assert.equal(fs.existsSync(reportPath), false, `${label}: Stop must not write doc-reconciliation-pilot.json`);
162
+ } finally {
163
+ fixture.cleanup();
164
+ restoreEnv();
165
+ }
154
166
  }
155
167
  });
156
168
 
157
- test('OpenCode capture → idle Stop whole path is refused without live qualification', async () => {
158
- const findings = [];
159
- const pilot = require(PILOT);
160
- const originalAssess = pilot.assess;
161
- const assessmentSessions = [];
162
- pilot.assess = function (context, ...args) {
163
- assessmentSessions.push(context?.sessionId);
164
- return originalAssess.call(this, context, ...args);
165
- };
166
- try {
169
+ test('V2 execute.after writes no E1 journal while ordinary telemetry, edit, observation, and Stop remain active', async () => {
170
+ for (const [label, pilotFlag] of [['pilot-1', '1'], ['pilot-unset', undefined]]) {
167
171
  await withV2DocFixture(async d => {
168
- const sessionId = 'native-v2-whole-path';
172
+ const sessionId = `native-v2-unhooked-${label}`;
169
173
  const { sessionDir } = seedWorkflow(d.workspace, sessionId);
170
- const nativeResult = { output: 'private-result-body', metadata: { exit: 0 } };
171
- await d.toolHook('execute.after')({
172
- tool: 'edit', sessionID: sessionId, id: 'call-1', messageID: 'message-1',
173
- status: 'completed', result: nativeResult,
174
- input: { filePath: path.join(d.workspace, 'docs/adr/GRPH-001.md') },
174
+ const observationsDir = process.env.HARNESS_OBSERVATIONS_DIR;
175
+
176
+ await d.sessionHook('prompt')({
177
+ sessionID: sessionId,
178
+ messageID: `turn-${label}`,
179
+ prompt: { text: 'update retry doc and verify' },
175
180
  });
176
- await d.toolHook('execute.after')({
177
- tool: 'bash', sessionID: sessionId, id: 'call-2', messageID: 'message-2',
178
- status: 'completed', error: { name: 'NativeError', message: 'native command error', code: 'NATIVE_FAILURE' },
181
+
182
+ const skillEvent = { tool: 'skill', sessionID: sessionId, id: 'call-skill', messageID: 'msg-skill', input: { skill: 'tdd' } };
183
+ await d.toolHook('execute.before')(skillEvent);
184
+ await d.toolHook('execute.after')({ ...skillEvent, status: 'completed', result: { output: 'loaded' } });
185
+
186
+ const editEvent = {
187
+ tool: 'edit', sessionID: sessionId, id: 'call-edit', messageID: 'msg-edit',
188
+ input: { filePath: path.join(d.workspace, 'docs/adr/GRPH-001.md') },
189
+ };
190
+ await d.toolHook('execute.before')(editEvent);
191
+ await d.toolHook('execute.after')({ ...editEvent, status: 'completed', result: { output: 'ok', metadata: { exit: 0 } } });
192
+
193
+ const bashEvent = {
194
+ tool: 'bash', sessionID: sessionId, id: 'call-bash', messageID: 'msg-bash',
179
195
  input: { command: 'doc-check' },
196
+ };
197
+ await d.toolHook('execute.before')(bashEvent);
198
+ await d.toolHook('execute.after')({
199
+ ...bashEvent, status: 'completed',
200
+ error: { name: 'NativeError', message: 'native command error', code: 'NATIVE_FAILURE' },
180
201
  });
181
202
 
203
+ // Path-specific sentinel: E1 host capture journal must not be created.
182
204
  const journal = path.join(sessionDir, 'opencode-captures.jsonl');
183
- let records = [];
184
- if (fs.existsSync(journal)) {
185
- const lines = fs.readFileSync(journal, 'utf8').trim().split(/\r?\n/);
186
- records = lines.map(line => JSON.parse(line));
187
- }
188
- const canonical = JSON.stringify(canonicalJson(nativeResult));
189
- const record = records[0];
190
- const errorRecord = records[1];
191
- if (records.length !== 2 || !record || record.hostId !== 'opencode' || record.session_id !== sessionId || record.call_id !== 'call-1' ||
192
- record.message_id !== 'message-1' || record.status !== 'completed' || record.exit !== 0 ||
193
- record.cwd !== undefined || record.result_digest !== crypto.createHash('sha256').update(canonical).digest('hex') ||
194
- record.result_bytes !== Buffer.byteLength(canonical) || fs.readFileSync(journal, 'utf8').includes('private-result-body')) {
195
- findings.push(`native result was not retained as one host-labelled digest-only record: ${JSON.stringify(record)}`);
196
- }
197
- if (!errorRecord || errorRecord.hostId !== 'opencode' || errorRecord.call_id !== 'call-2' ||
198
- errorRecord.error?.name !== 'NativeError' || errorRecord.error?.message !== 'native command error' ||
199
- errorRecord.error?.code !== 'NATIVE_FAILURE' || errorRecord.exit === 0) {
200
- findings.push(`native error was not preserved as failure without fabricated exit zero: ${JSON.stringify(errorRecord)}`);
201
- }
202
-
203
- const reportPath = path.join(sessionDir, 'doc-reconciliation-pilot.json');
205
+ assert.equal(fs.existsSync(journal), false, `${label}: V2 execute.after must not write opencode-captures.jsonl`);
206
+
207
+ // Positive controls: ordinary edit state, compliance, and telemetry remain active.
208
+ const editState = readJson(path.join(sessionDir, 'edit-state.json'));
209
+ const compliance = readJson(path.join(sessionDir, 'compliance.json'));
210
+ assert.equal(editState.verificationPending, true, `${label}: edit marks verificationPending`);
211
+ assert.equal(editState.editsSinceVerification, 1, `${label}: edit increments editsSinceVerification`);
212
+ assert.equal(compliance.totalEdits, 1, `${label}: compliance records totalEdits`);
213
+ const preIdleTelemetry = readTelemetryEvents(sessionDir).map(item => item.event);
214
+ assert.ok(preIdleTelemetry.includes('skill.invoke'), `${label}: telemetry records skill.invoke`);
215
+ assert.ok(preIdleTelemetry.includes('skill.loaded'), `${label}: telemetry records skill.loaded`);
216
+ assert.ok(preIdleTelemetry.includes('tool.observed'), `${label}: telemetry records tool.observed`);
217
+
218
+ // Completion triggers ordinary verification, observation closure, telemetry close, and Stop without E1 report.
219
+ const workflowFile = path.join(sessionDir, 'workflow-run.json');
204
220
  d.emit('session.execution.succeeded', sessionId);
205
221
  await d.waitFor(
206
- () => assessmentSessions.filter(id => id === sessionId).length === 1 && fs.existsSync(reportPath),
207
- { label: 'V2 completion Stop assessment and pilot report', timeoutMs: 8000 },
222
+ () => readObservationRecords(observationsDir).length === 1
223
+ && readJson(path.join(sessionDir, 'edit-state.json')).verificationPending === false
224
+ && Array.isArray(readJson(workflowFile).unresolved)
225
+ && readJson(workflowFile).unresolved.length > 0,
226
+ { label: `${label}: observation, verification, and ordinary Stop completion`, timeoutMs: 8000 },
208
227
  );
209
- const report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
210
- if (assessmentSessions.filter(id => id === sessionId).length !== 1) {
211
- findings.push(`idle Stop dispatch count=${assessmentSessions.filter(id => id === sessionId).length}, expected exactly one`);
212
- }
213
- if (!report || report.pilotCredit !== false || report.pilotStatus !== 'unresolved' || !report.diagnostics?.length) {
214
- findings.push(`idle did not write the actual refused/unavailable report: ${JSON.stringify(report)}`);
215
- }
216
- assert.deepEqual(findings, []);
217
- });
218
- } finally {
219
- pilot.assess = originalAssess;
228
+
229
+ const [obsRecord] = readObservationRecords(observationsDir);
230
+ assert.equal(obsRecord.host, 'opencode', `${label}: observation host is opencode`);
231
+ assert.equal(obsRecord.writer.sessionId, sessionId, `${label}: observation session matches`);
232
+ assert.equal(obsRecord.behavior.filesWritten, 1, `${label}: observation counted the edit`);
233
+ const postIdleTelemetry = readTelemetryEvents(sessionDir).map(item => item.event);
234
+ assert.ok(postIdleTelemetry.includes('skill.complete'), `${label}: telemetry closes active skill on idle`);
235
+ assert.equal(fs.existsSync(journal), false, `${label}: opencode-captures.jsonl remains absent after idle`);
236
+ assert.equal(fs.existsSync(path.join(sessionDir, 'doc-reconciliation-pilot.json')), false, `${label}: no E1 pilot report after idle`);
237
+ }, { observations: 'on', pilotFlag });
220
238
  }
221
239
  });
222
240
 
223
- test('session idle dispatches the real consumer once across every existing early return', async () => {
224
- const findings = [];
225
- const pilot = require(PILOT);
226
- const originalAssess = pilot.assess;
227
- const assessmentSessions = [];
228
- pilot.assess = function (context, ...args) {
229
- assessmentSessions.push(context?.sessionId);
230
- return originalAssess.call(this, context, ...args);
231
- };
232
- try {
233
- await withV2DocFixture(async d => {
234
- const cases = [
235
- ['follow-up-pending', { followUpPending: true }],
236
- ['follow-up-delivery-pending', { followUpDeliveryPending: true, followUpMessage: 'deliver once' }],
237
- ['no-verification-pending', { verificationPending: false, editsSinceVerification: 0 }],
238
- ['verification-succeeds', { verificationPending: true, editsSinceVerification: 1 }],
239
- ];
240
- for (const [suffix, state] of cases) {
241
- const sessionId = `idle-${suffix}`;
242
- const { sessionDir } = seedWorkflow(d.workspace, sessionId);
243
- writeEditState(sessionDir, state);
244
- const reportPath = path.join(sessionDir, 'doc-reconciliation-pilot.json');
245
- d.emit('session.execution.succeeded', sessionId);
246
- await d.waitFor(
247
- () => assessmentSessions.filter(id => id === sessionId).length === 1 && fs.existsSync(reportPath),
248
- { label: `${suffix} V2 completion Stop assessment`, timeoutMs: 8000 },
249
- );
250
- const report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
251
- if (assessmentSessions.filter(id => id === sessionId).length !== 1) {
252
- findings.push(`${suffix}: consumer assessment count=${assessmentSessions.filter(id => id === sessionId).length}, expected exactly one`);
253
- }
254
- if (!report || report.pilotCredit !== false || report.pilotStatus !== 'unresolved') {
255
- findings.push(`${suffix}: expected one refused/unavailable report, received ${JSON.stringify(report)}`);
256
- }
257
- }
258
- const cleanupSession = 'idle-no-verification-pending';
259
- d.emit('session.execution.succeeded', cleanupSession);
241
+ test('session idle finally releases the controller across all four early returns and completes ordinary Stop/verification/reminder paths', async () => {
242
+ await withV2DocFixture(async d => {
243
+ const cases = [
244
+ ['follow-up-pending', { followUpPending: true }],
245
+ ['follow-up-delivery-pending', { followUpDeliveryPending: true, followUpMessage: 'deliver once' }],
246
+ ['no-verification-pending', { verificationPending: false, editsSinceVerification: 0 }],
247
+ ['verification-succeeds', { verificationPending: true, editsSinceVerification: 1 }],
248
+ ];
249
+ for (const [suffix, state] of cases) {
250
+ const sessionId = `idle-${suffix}`;
251
+ const { sessionDir } = seedWorkflow(d.workspace, sessionId);
252
+ const workflowFile = path.join(sessionDir, 'workflow-run.json');
253
+ const editStateFile = path.join(sessionDir, 'edit-state.json');
254
+ writeEditState(sessionDir, state);
255
+
256
+ const promptsBefore = d.prompts.length;
257
+ d.emit('session.execution.succeeded', sessionId);
260
258
  await d.waitFor(
261
- () => assessmentSessions.filter(id => id === cleanupSession).length === 2,
262
- { label: 'second V2 completion Stop assessment after cleanup' },
259
+ () => Array.isArray(readJson(workflowFile).unresolved) && readJson(workflowFile).unresolved.length > 0,
260
+ { label: `${suffix}: ordinary Stop ran on first idle`, timeoutMs: 8000 },
263
261
  );
264
- if (assessmentSessions.filter(id => id === cleanupSession).length !== 2) {
265
- findings.push(`finally did not release the per-session idle guard for a second event: ${assessmentSessions.filter(id => id === cleanupSession).length} assessments`);
262
+
263
+ const afterFirst = readJson(editStateFile);
264
+ if (suffix === 'follow-up-pending') {
265
+ assert.equal(d.prompts.length, promptsBefore, `${suffix}: no duplicate prompt sent`);
266
+ } else if (suffix === 'follow-up-delivery-pending') {
267
+ assert.equal(d.prompts.length, promptsBefore + 1, `${suffix}: pending reminder prompt delivered`);
268
+ assert.equal(d.prompts.at(-1).sessionID, sessionId);
269
+ assert.equal(d.prompts.at(-1).text, 'deliver once');
270
+ assert.equal(afterFirst.followUpPending, true);
271
+ assert.equal(afterFirst.followUpDeliveryPending, false);
272
+ } else if (suffix === 'no-verification-pending') {
273
+ assert.equal(d.prompts.length, promptsBefore, `${suffix}: no prompt sent without pending verification`);
274
+ } else if (suffix === 'verification-succeeds') {
275
+ assert.equal(afterFirst.verificationPending, false, `${suffix}: passing verification clears verificationPending`);
276
+ assert.equal(afterFirst.editsSinceVerification, 0, `${suffix}: passing verification resets editsSinceVerification`);
277
+ assert.equal(readJson(path.join(sessionDir, 'compliance.json')).verifiedEdits, 1, `${suffix}: compliance increments verifiedEdits`);
266
278
  }
267
- assert.deepEqual(findings, []);
268
- });
269
- } finally {
270
- pilot.assess = originalAssess;
271
- }
279
+
280
+ assert.equal(fs.existsSync(path.join(sessionDir, 'doc-reconciliation-pilot.json')), false, `${suffix}: no E1 pilot report`);
281
+ assert.equal(fs.existsSync(path.join(sessionDir, 'opencode-captures.jsonl')), false, `${suffix}: no E1 capture journal`);
282
+
283
+ // Prove finally released the per-session controller: clear workflow.unresolved and fire a second idle.
284
+ const wf = readJson(workflowFile);
285
+ wf.unresolved = [];
286
+ fs.writeFileSync(workflowFile, JSON.stringify(wf, null, 2));
287
+ d.emit('session.execution.succeeded', sessionId);
288
+ await d.waitFor(
289
+ () => Array.isArray(readJson(workflowFile).unresolved) && readJson(workflowFile).unresolved.length > 0,
290
+ { label: `${suffix}: second idle runs after finally releases controller`, timeoutMs: 8000 },
291
+ );
292
+ }
293
+ }, { pilotFlag: '1' });
272
294
  });
273
295
 
274
- test('V1/no-status, pilot-OFF, no-workflow, and Claude host controls stay fail-closed', async () => {
296
+ test('pilot flag values and no-workflow stay unhooked and fail-closed', async () => {
275
297
  await withV2DocFixture(async d => {
276
- const positiveSession = 'v2-positive-control';
277
- const { sessionDir: positiveDir } = seedWorkflow(d.workspace, positiveSession);
278
- await d.toolHook('execute.after')({
279
- tool: 'edit', sessionID: positiveSession, id: 'pos-call', status: 'completed',
280
- result: { output: 'ok', metadata: { exit: 0 } },
281
- input: { filePath: path.join(d.workspace, 'docs/adr/GRPH-001.md') },
282
- });
283
- assert.equal(fs.existsSync(path.join(positiveDir, 'opencode-captures.jsonl')), true, 'positive control: V2 execute.after with status creates a native capture');
284
- const positiveReport = path.join(positiveDir, 'doc-reconciliation-pilot.json');
285
- d.emit('session.execution.succeeded', positiveSession);
286
- await d.waitFor(() => fs.existsSync(positiveReport), { label: 'positive control pilot report', timeoutMs: 8000 });
287
-
288
- const v1Session = 'v1-no-status';
289
- const { sessionDir: v1Dir } = seedWorkflow(d.workspace, v1Session);
290
- await d.toolHook('execute.after')({
291
- tool: 'edit', sessionID: v1Session, id: 'v1-call', input: { filePath: path.join(d.workspace, 'docs/adr/GRPH-001.md') },
292
- });
293
- await d.settled({ quietMs: 100 });
294
- assert.equal(fs.existsSync(path.join(v1Dir, 'opencode-captures.jsonl')), false, 'V1/no-status output must not create a native capture');
298
+ for (const [label, pilotFlag] of [['pilot-1', '1'], ['pilot-0', '0'], ['pilot-unset', undefined]]) {
299
+ if (pilotFlag === undefined) delete process.env.HARNESS_DOC_RECONCILIATION_PILOT;
300
+ else process.env.HARNESS_DOC_RECONCILIATION_PILOT = pilotFlag;
301
+ const sessionId = `flag-control-${label}`;
302
+ const { sessionDir } = seedWorkflow(d.workspace, sessionId);
303
+ await d.toolHook('execute.after')({
304
+ tool: 'edit', sessionID: sessionId, id: `call-${label}`, status: 'completed',
305
+ result: { output: 'ok', metadata: { exit: 0 } },
306
+ input: { filePath: path.join(d.workspace, 'docs/adr/GRPH-001.md') },
307
+ });
308
+ assert.equal(fs.existsSync(path.join(sessionDir, 'edit-state.json')), true, `${label}: positive control edit-state written`);
309
+ assert.equal(fs.existsSync(path.join(sessionDir, 'opencode-captures.jsonl')), false, `${label}: V2 execute.after must not write opencode-captures.jsonl`);
310
+ }
295
311
 
296
312
  const noWorkflow = 'no-workflow';
297
313
  const { getSessionDir } = require(path.join(ROOT, 'hooks/scripts/lib/harness-state.js'));
298
314
  const noWorkflowDir = getSessionDir(d.workspace, noWorkflow, { session_id: noWorkflow, cwd: d.workspace, host_id: 'opencode' });
315
+ process.env.HARNESS_DOC_RECONCILIATION_PILOT = '1';
299
316
  d.emit('session.execution.succeeded', noWorkflow);
300
317
  await d.settled({ quietMs: 150 });
301
318
  assert.equal(fs.existsSync(path.join(noWorkflowDir, 'doc-reconciliation-pilot.json')), false, 'no workflow must not write a pilot report');
302
-
303
- const offSession = 'pilot-off';
304
- const { sessionDir: offDir } = seedWorkflow(d.workspace, offSession);
305
- process.env.HARNESS_DOC_RECONCILIATION_PILOT = '0';
306
- d.emit('session.execution.succeeded', offSession);
307
- await d.settled({ quietMs: 150 });
308
- assert.equal(fs.existsSync(path.join(offDir, 'doc-reconciliation-pilot.json')), false, 'pilot OFF must not write a reconciliation report');
309
-
310
- const { createClaudeOriginProvider } = require(path.join(ROOT, 'hooks/scripts/lib/doc-reconciliation-provider.js'));
311
- const claudeProvider = createClaudeOriginProvider({ hostId: 'opencode', sessionId: 'native-host-control' });
312
- const claudeContext = claudeProvider.resolveContext({ workspaceRoot: d.workspace });
313
- assert.equal(claudeContext.status, 'unavailable', 'OpenCode must not enter through Claude provider semantics');
314
- assert.ok(claudeContext.diagnostics.some(item => item.code === 'unsupported-host'));
315
- });
319
+ assert.equal(fs.existsSync(path.join(noWorkflowDir, 'workflow-run.json')), false, 'no workflow must not create a workflow file');
320
+ }, { pilotFlag: '1' });
316
321
  });
317
322
 
318
- const OPENCODE_SESSION = 'provider-session';
319
- const OPENCODE_QUALIFICATION = {
320
- source: 'fake-test-fixture', faked: true, toolUseIdPopulated: true, agentIdPopulated: true,
321
- };
322
-
323
- function opencodeCapture(overrides = {}) {
324
- return {
325
- schema: 'opencode-capture-record/1', hostId: 'opencode', session_id: OPENCODE_SESSION,
326
- call_id: 'provider-call', tool: 'bash', command: 'npm test', cwd: ROOT,
327
- status: 'completed', exit: 0, result_digest: 'a'.repeat(64), result_bytes: 1,
328
- observedIdentity: { workflowId: 'provider-workflow', workflowRevision: 3, baselinePin: null },
329
- ...overrides,
330
- };
331
- }
332
-
333
- function opencodeProvider(captures, overrides = {}) {
334
- const { createOpencodeOriginProvider } = require(path.join(ROOT, 'hooks/scripts/lib/doc-reconciliation-provider.js'));
335
- return createOpencodeOriginProvider({
336
- hostId: 'opencode', sessionId: OPENCODE_SESSION, workspaceRoot: ROOT,
337
- workflowId: 'provider-workflow', workflowRevision: 3, taskId: 'provider-task',
338
- principals: { author: 'provider-author', executors: ['provider-executor'] },
339
- qualification: OPENCODE_QUALIFICATION, captures,
340
- ...overrides,
341
- });
342
- }
343
-
344
- function diagnosticCode(result) { return result.diagnostics?.[0]?.code; }
345
-
346
- test('fake-DI OpenCode origin accepts the complete native execution record shape', () => {
347
- const provider = opencodeProvider([opencodeCapture({ unrecognizedPrivateField: 'must-not-leak' })]);
348
- const context = provider.resolveContext({ workspaceRoot: ROOT });
349
- const result = provider.resolveEvent({
350
- reference: 'provider-call',
351
- identity: { workspaceId: 'ws-provider', sessionId: OPENCODE_SESSION, workflowId: 'provider-workflow', workflowRevision: 3 },
352
- });
353
- assert.equal(context.status, 'accepted');
354
- assert.match(context.originRef, /^origin:\/\/opencode\//);
355
- assert.equal(context.context.activeHost, 'opencode');
356
- assert.equal(result.status, 'accepted');
357
- assert.equal(result.originRef, context.originRef);
358
- assert.equal(result.event.originRef, context.originRef);
359
- assert.deepEqual(Object.keys(result.event).sort(), [
360
- 'argv', 'artifactDigests', 'captured', 'capability', 'command', 'cwd', 'endIdentity', 'eventId',
361
- 'exitCode', 'identity', 'kind', 'originRef', 'paths', 'principalId', 'producerId', 'provenance', 'resultRef',
362
- 'signal', 'startIdentity', 'toolCorrelationId',
363
- ].sort());
364
- assert.equal(result.event.producerId, 'opencode-origin-provider');
365
- assert.equal(result.event.capability, 'shell-command');
366
- assert.equal(result.event.kind, 'execution');
367
- assert.equal(result.event.exitCode, 0);
368
- assert.equal(result.event.cwd, ROOT);
369
- assert.equal(result.event.toolCorrelationId, 'provider-call');
370
- assert.equal(result.event.captured.responseDigest, 'a'.repeat(64));
371
- assert.deepEqual(result.correlation, { toolCorrelationId: 'provider-call', resultRef: result.event.resultRef });
372
-
373
- const emptyResultDigest = crypto.createHash('sha256').update('').digest('hex');
374
- const minimum = opencodeProvider([opencodeCapture({ call_id: 'empty-result', result_digest: emptyResultDigest, result_bytes: 0 })])
375
- .resolveEvent({ reference: 'empty-result', identity: { workflowId: 'provider-workflow' } });
376
- assert.equal(minimum.status, 'accepted', 'zero result bytes are the valid minimum boundary');
377
- assert.equal(minimum.event.captured.responseDigest, emptyResultDigest);
378
- });
379
-
380
- test('production OpenCode qualification remains unmet with otherwise valid origin input', () => {
381
- const provider = opencodeProvider([opencodeCapture()], { qualification: undefined });
382
- const context = provider.resolveContext({ workspaceRoot: ROOT });
383
- const result = provider.resolveEvent({ reference: 'provider-call', identity: { workflowId: 'provider-workflow' } });
384
- assert.equal(context.status, 'unavailable');
385
- assert.equal(diagnosticCode(context), 'live-gate-unmet');
386
- assert.equal(result.status, 'unavailable');
387
- assert.equal(diagnosticCode(result), 'live-gate-unmet');
388
- });
389
-
390
- test('OpenCode provider rejects native error, incomplete outcome, and missing cwd', () => {
391
- const cases = [
392
- ['native-error', { error: { name: 'Error', message: 'failed' } }, 'failure-not-credited', 'provider-call'],
393
- ['missing-status', { status: undefined }, 'outcome-ambiguous', 'provider-call'],
394
- ['empty-status', { status: '' }, 'outcome-ambiguous', 'provider-call'],
395
- ['null-status', { status: null }, 'outcome-ambiguous', 'provider-call'],
396
- ['wrong-type-status', { status: 1 }, 'outcome-ambiguous', 'provider-call'],
397
- ['ambiguous-status', { status: 'running' }, 'outcome-ambiguous', 'provider-call'],
398
- ['missing-process-exit', { exit: undefined }, 'outcome-ambiguous', 'provider-call'],
399
- ['negative-result-bytes', { result_bytes: -1 }, 'stdout-withheld', 'provider-call'],
400
- ['missing-doc-check-cwd', { cwd: undefined, command: 'node harness-everything/scripts/doc-check.js' }, 'unregistered-command', 'provider-call#doc-lint'],
401
- ];
402
- for (const [name, changes, expected, reference] of cases) {
403
- const result = opencodeProvider([opencodeCapture(changes)]).resolveEvent({ reference, identity: { workflowId: 'provider-workflow' } });
404
- assert.equal(result.status, 'rejected', `${name}: ${JSON.stringify(result)}`);
405
- assert.equal(diagnosticCode(result), expected, name);
406
- }
407
- });
408
-
409
- test('OpenCode provider rejects malformed references and unsupported host input', () => {
410
- const invalidReference = opencodeProvider([opencodeCapture()]).resolveEvent({ reference: '' });
411
- assert.equal(invalidReference.status, 'unavailable');
412
- assert.equal(diagnosticCode(invalidReference), 'invalid-input');
413
-
414
- const unsupportedContext = opencodeProvider([], { hostId: 'codex' }).resolveContext({ workspaceRoot: ROOT });
415
- assert.equal(unsupportedContext.status, 'unavailable');
416
- assert.equal(diagnosticCode(unsupportedContext), 'unsupported-host');
417
-
418
- const unsupportedEvent = opencodeProvider([], { hostId: 'claude-code' }).resolveEvent({ reference: 'provider-call' });
419
- assert.equal(unsupportedEvent.status, 'unavailable');
420
- assert.equal(diagnosticCode(unsupportedEvent), 'unsupported-host');
421
- });
422
-
423
- test('OpenCode provider rejects stale, replayed, and Claude-origin records', () => {
424
- const identity = { workflowId: 'provider-workflow', workflowRevision: 3 };
425
- const stale = opencodeCapture({ observedIdentity: { workflowId: 'provider-workflow', workflowRevision: 2, baselinePin: null } });
426
- assert.equal(diagnosticCode(opencodeProvider([stale]).resolveEvent({ reference: stale.call_id, identity })), 'identity-mismatch');
427
-
428
- const first = opencodeCapture({ call_id: 'first-call' });
429
- const replay = opencodeCapture({ call_id: 'replayed-call' });
430
- const replayProvider = opencodeProvider([first, replay]);
431
- assert.equal(diagnosticCode(replayProvider.resolveEvent({ reference: replay.call_id, identity })), 'replayed-record');
432
-
433
- const claudeRecord = opencodeCapture({ hostId: 'claude-code' });
434
- assert.equal(diagnosticCode(opencodeProvider([claudeRecord]).resolveEvent({ reference: claudeRecord.call_id, identity })), 'record-origin-mismatch');
435
- });
436
-
437
- test('OpenCode quality-review record is refused when reviewer equals the author', () => {
438
- const record = opencodeCapture({ agent_id: 'provider-author' });
439
- const result = opencodeProvider([record]).resolveEvent({ reference: `${record.call_id}#quality-review` });
440
- assert.equal(result.status, 'rejected');
441
- assert.equal(diagnosticCode(result), 'reviewer-not-independent');
442
- });