harness-everything 0.41.3 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,8 +15,8 @@
15
15
  // qualification object ({ source: 'fake-test-fixture', faked: true }) is a
16
16
  // test-only construct for mechanism tests; production passes no
17
17
  // qualification and stays gated.
18
- // - Unsupported hosts (opencode/codex) never borrow the Claude exit mapping:
19
- // both seam methods report `unavailable` with diagnostics.
18
+ // - The Claude provider accepts only Claude. OpenCode has a separate
19
+ // fail-closed mapping and never borrows Claude's exit or reviewer rules.
20
20
  // - Exit mapping (owner decision row 1): for a given `tool_use_id`, a captured
21
21
  // `PostToolUse` with `interrupted === false` and no `PostToolUseFailure`
22
22
  // arrival maps to exit 0. This is a named mapping of the host's own
@@ -37,6 +37,10 @@ const path = require('path');
37
37
 
38
38
  const HOST_ID = 'claude-code';
39
39
  const CAPTURE_RECORD_VERSION = 'claude-capture-record/1';
40
+ const OPENCODE_HOST_ID = 'opencode';
41
+ const OPENCODE_CAPTURE_RECORD_VERSION = 'opencode-capture-record/1';
42
+ const OPENCODE_CAPTURE_FILE = 'opencode-captures.jsonl';
43
+ const OPENCODE_CAPTURE_LIMIT_BYTES = 4 * 1024 * 1024;
40
44
  const QUALIFICATION_EXPORT_SCHEMA = 'harness.doc-reconciliation.qualification.v1';
41
45
  const HEX64 = /^[0-9a-f]{64}$/;
42
46
  const PRE_CAPTURE_TOOLS = ['Bash', 'PowerShell', 'Task', 'Agent'];
@@ -522,10 +526,14 @@ function observedCorrelation(records) {
522
526
 
523
527
  // Validates the qualification export against the sanitized capture it names: schema, host, capture-record version, the
524
528
  // capture's digest, and every claimed kind, field and correlation. Returns null when valid, else the reason.
525
- function validateQualificationExport() {
529
+ function validateQualificationExport(expectedHost = HOST_ID) {
526
530
  const exported = JSON.parse(fs.readFileSync(path.join(__dirname, EXPORT_FILE), 'utf8'));
527
531
  if (!recordOf(exported) || exported.schema !== QUALIFICATION_EXPORT_SCHEMA) return 'qualification export schema is not recognized';
528
- if (exported.host !== HOST_ID || !textOf(exported.hostVersion)) return 'qualification export host or host version is missing';
532
+ if (!textOf(exported.hostVersion)) return 'qualification export host or host version is missing';
533
+ if (exported.host !== expectedHost) {
534
+ if (expectedHost === HOST_ID) return 'qualification export host or host version is missing';
535
+ return 'qualification export host does not match the selected provider';
536
+ }
529
537
  if (exported.captureRecordVersion !== CAPTURE_RECORD_VERSION) return 'qualification export capture record version is not supported';
530
538
  const source = recordOf(exported.sanitizedCapture) ? exported.sanitizedCapture : {};
531
539
  // The sanitized capture is a sibling of the export, so source and packaged copies resolve it the same way.
@@ -547,7 +555,7 @@ function validateQualificationExport() {
547
555
  return null;
548
556
  }
549
557
 
550
- function evaluateQualification(input) {
558
+ function evaluateQualification(input, expectedHost = HOST_ID) {
551
559
  if (recordOf(input) && input.qualification !== undefined && input.qualification !== null) {
552
560
  const supplied = input.qualification;
553
561
  // Test-only DI path: an explicitly fake qualification object. Anything else
@@ -567,7 +575,7 @@ function evaluateQualification(input) {
567
575
  // against the sanitized capture it names. Nothing is read from the environment, capture flags or ancestor directories.
568
576
  let reason = null;
569
577
  try {
570
- reason = validateQualificationExport();
578
+ reason = validateQualificationExport(expectedHost);
571
579
  } catch (error) {
572
580
  reason = `qualification evidence could not be read (${error.code || 'error'})`;
573
581
  }
@@ -582,11 +590,11 @@ function evaluateQualification(input) {
582
590
 
583
591
  // ---- Shared provider state ------------------------------------------------------
584
592
 
585
- function supportedHostCheck(input) {
586
- if (recordOf(input) && input.hostId === HOST_ID) return null;
593
+ function supportedHostCheck(input, expectedHost = HOST_ID) {
594
+ if ([HOST_ID, OPENCODE_HOST_ID].includes(expectedHost) && recordOf(input) && input.hostId === expectedHost) return null;
587
595
  const host = recordOf(input) && typeof input.hostId === 'string' ? input.hostId : 'unknown';
588
596
  return diagnostic('unsupported-host', {
589
- reason: `unsupported host ${host} has no supported capture implementation; OpenCode/Codex must not borrow the Claude exit mapping`,
597
+ reason: `unsupported host ${host} has no matching capture implementation; hosts must not borrow another host's exit mapping`,
590
598
  });
591
599
  }
592
600
 
@@ -892,6 +900,127 @@ const createClaudeOriginProvider = input => {
892
900
  return { resolveContext, resolveEvent };
893
901
  };
894
902
 
903
+ function opencodeContentSignature(cap) {
904
+ return captureJson({
905
+ hostId: cap.hostId,
906
+ tool: cap.tool === undefined ? null : cap.tool,
907
+ command: cap.command === undefined ? null : cap.command,
908
+ cwd: cap.cwd === undefined ? null : cap.cwd,
909
+ status: cap.status === undefined ? null : cap.status,
910
+ exit: cap.exit === undefined ? null : cap.exit,
911
+ resultDigest: cap.result_digest === undefined ? null : cap.result_digest,
912
+ error: cap.error === undefined ? null : cap.error,
913
+ });
914
+ }
915
+
916
+ const createOpencodeOriginProvider = input => {
917
+ const safeInput = recordOf(input) ? input : {};
918
+
919
+ function resolveContext(request) {
920
+ const hostFail = supportedHostCheck(safeInput, OPENCODE_HOST_ID);
921
+ if (hostFail) return { status: 'unavailable', diagnostics: [hostFail] };
922
+ const qualification = evaluateQualification(safeInput, OPENCODE_HOST_ID);
923
+ if (!qualification.open) return { status: 'unavailable', diagnostics: [qualification.fail] };
924
+ const workspaceRoot = textOf(safeInput.workspaceRoot) ? safeInput.workspaceRoot : (recordOf(request) && textOf(request.workspaceRoot) ? request.workspaceRoot : '');
925
+ const sessionId = textOf(safeInput.sessionId) ? safeInput.sessionId : '';
926
+ const workflowId = textOf(safeInput.workflowId) ? safeInput.workflowId : '';
927
+ const workflowRevision = Number.isInteger(safeInput.workflowRevision) ? safeInput.workflowRevision : null;
928
+ const taskId = textOf(safeInput.taskId) ? safeInput.taskId : '';
929
+ if (!workspaceRoot || !sessionId || !workflowId || workflowRevision === null || !taskId) {
930
+ return { status: 'unavailable', diagnostics: [diagnostic('invalid-input', { reason: 'OpenCode origin requires the recorded workspace, session, workflow, revision and task identity' })] };
931
+ }
932
+ const suppliedPrincipals = recordOf(safeInput.principals) ? safeInput.principals : {};
933
+ const author = textOf(suppliedPrincipals.author) ? suppliedPrincipals.author : sessionId;
934
+ const executors = Array.isArray(suppliedPrincipals.executors) ? suppliedPrincipals.executors.filter(textOf) : [sessionId];
935
+ const originRef = 'origin://opencode/' + digestText(captureJson({
936
+ hostId: OPENCODE_HOST_ID, sessionId, workspaceRoot, taskId, workflowId, workflowRevision,
937
+ author, executors, qualificationSource: qualification.source,
938
+ }));
939
+ return {
940
+ status: 'accepted', originRef,
941
+ context: {
942
+ workspaceId: 'ws-' + digestText(captureJson({ workspaceRoot })), sessionId, workflowId, workflowRevision, taskId,
943
+ principals: { author, executors: executors.slice() }, activeHost: OPENCODE_HOST_ID,
944
+ baselineReference: `retained-live-capture:opencode-341:${digestText(originRef)}`,
945
+ ...(recordOf(safeInput.baseline) && textOf(safeInput.baseline.commit) && textOf(safeInput.baseline.root)
946
+ ? { baseline: { commit: safeInput.baseline.commit, root: safeInput.baseline.root } } : {}),
947
+ workspaceRoot,
948
+ },
949
+ };
950
+ }
951
+
952
+ function resolveEvent(request) {
953
+ if (!recordOf(request) || !textOf(request.reference)) return unavailable('invalid-input', 'resolveEvent requires a nonempty event reference');
954
+ const hostFail = supportedHostCheck(safeInput, OPENCODE_HOST_ID);
955
+ if (hostFail) return { status: 'unavailable', diagnostics: [hostFail] };
956
+ const qualification = evaluateQualification(safeInput, OPENCODE_HOST_ID);
957
+ if (!qualification.open) return { status: 'unavailable', diagnostics: [qualification.fail] };
958
+ const [captureRef, capability] = String(request.reference).split('#');
959
+ const captures = Array.isArray(safeInput.captures) ? safeInput.captures : [];
960
+ const matches = captures.map((item, index) => ({ item, index })).filter(({ item }) => recordOf(item) && item.call_id === captureRef);
961
+ if (!matches.length) return unavailable('origin-unavailable', `no captured OpenCode event is retained for reference ${request.reference}`);
962
+ if (matches.length > 1) return rejected('replayed-record', 'multiple OpenCode records share this call id');
963
+ const { item: cap, index } = matches[0];
964
+ if (cap.hostId !== OPENCODE_HOST_ID || cap.schema !== OPENCODE_CAPTURE_RECORD_VERSION
965
+ || cap.session_id !== safeInput.sessionId) {
966
+ return rejected('record-origin-mismatch', 'the capture host and session must match this OpenCode provider invocation');
967
+ }
968
+ const observed = cap.observedIdentity;
969
+ const pin = recordOf(safeInput.baseline) ? safeInput.baseline : null;
970
+ if (!recordOf(observed)) return rejected('identity-missing', 'OpenCode capture lacks workflow identity observed at capture time');
971
+ const sameWorkflow = observed.workflowId === safeInput.workflowId && observed.workflowRevision === safeInput.workflowRevision;
972
+ const samePin = !pin || (recordOf(observed.baselinePin) && observed.baselinePin.commit === pin.commit && observed.baselinePin.root === pin.root);
973
+ if (!sameWorkflow || !samePin) return rejected('identity-mismatch', 'the observed workflow revision or baseline pin differs from the current one; stale evidence loses credit');
974
+ const signature = opencodeContentSignature(cap);
975
+ const firstOccurrence = captures.findIndex(item => recordOf(item) && opencodeContentSignature(item) === signature);
976
+ if (firstOccurrence !== index) return rejected('replayed-record', `identical OpenCode tool content already recorded (first occurrence index ${firstOccurrence})`);
977
+ if (cap.error !== undefined && cap.error !== null) return rejected('failure-not-credited', 'the native tool event carries an error');
978
+ if (typeof cap.status !== 'string' || !cap.status) return rejected('outcome-ambiguous', 'the native tool status is missing');
979
+ if (cap.status !== 'completed') return rejected(cap.status === 'error' ? 'failure-not-credited' : 'outcome-ambiguous', `native tool status ${cap.status} does not prove completion`);
980
+ const processTool = ['bash', 'shell', 'powershell', 'cmd'].includes(String(cap.tool).toLowerCase());
981
+ if (processTool && !Number.isInteger(cap.exit)) return rejected('outcome-ambiguous', 'a process result without a numeric native exit is ambiguous');
982
+ if (processTool && cap.exit !== 0) return rejected('failure-not-credited', `the native process exit was ${cap.exit}`);
983
+ if (!/^[0-9a-f]{64}$/.test(String(cap.result_digest || '')) || !Number.isInteger(cap.result_bytes) || cap.result_bytes < 0) {
984
+ return rejected('stdout-withheld', 'the native result digest and byte count are absent');
985
+ }
986
+ const author = recordOf(safeInput.principals) && textOf(safeInput.principals.author) ? safeInput.principals.author : safeInput.sessionId;
987
+ if (capability === 'quality-review') {
988
+ if (!textOf(cap.agent_id)) return rejected('reviewer-principal-missing', 'OpenCode supplied no host-issued reviewer identity');
989
+ if (cap.agent_id === author) return rejected('reviewer-not-independent', 'the reviewer identity equals the author session principal');
990
+ return rejected('reviewer-principal-missing', 'OpenCode supplied no host-issued independent-review record');
991
+ }
992
+ if (capability) {
993
+ if (!['doc-lint', 'link-check'].includes(capability)) return rejected('capability-mismatch', `OpenCode cannot supply capability ${capability}`);
994
+ if (!textOf(cap.command)) return rejected('command-missing', 'the native record has no command for a registered doc-check');
995
+ if (!textOf(cap.cwd)) return rejected('unregistered-command', 'the host omitted per-tool cwd, so the doc-check invocation cannot be validated');
996
+ const registered = resolveDocCheckInvocation(cap.command, cap.cwd);
997
+ if (registered.kind !== 'accepted') return rejected('unregistered-command', `doc-check invocation rejected (${registered.reason}); no credit`);
998
+ return rejected('stdout-withheld', 'the OpenCode result body is retained only as a digest and cannot prove doc-check output');
999
+ }
1000
+ if (!textOf(cap.command)) return rejected('command-missing', 'captured OpenCode record has no retained process command');
1001
+ if (!textOf(cap.cwd)) return rejected('outcome-ambiguous', 'the host omitted per-tool cwd');
1002
+ if (!processTool) return rejected('capture-event-unsupported', `tool ${String(cap.tool)} has no OpenCode process mapping`);
1003
+ if (!recordOf(request.identity)) return rejected('identity-missing', 'execution evidence needs a snapshot identity');
1004
+ const contextResponse = resolveContext(request);
1005
+ if (contextResponse.status !== 'accepted') return unavailable('origin-unavailable', 'origin context did not resolve');
1006
+ const identity = JSON.parse(JSON.stringify(request.identity));
1007
+ const resultRef = `opencode-result/${cap.call_id}/${cap.result_digest}`;
1008
+ const event = {
1009
+ eventId: 'opencode-exec-' + digestText(signature + ':execution'),
1010
+ producerId: 'opencode-origin-provider', originRef: contextResponse.originRef,
1011
+ principalId: cap.session_id, provenance: 'opencode-capture:' + cap.call_id,
1012
+ capability: 'shell-command', kind: 'execution', command: cap.command, argv: [cap.command], cwd: cap.cwd,
1013
+ exitCode: cap.exit, signal: null, toolCorrelationId: cap.call_id, resultRef,
1014
+ identity, startIdentity: identity, endIdentity: identity,
1015
+ paths: [], artifactDigests: {}, captured: { responseRef: resultRef, responseDigest: cap.result_digest },
1016
+ };
1017
+ return { status: 'accepted', originRef: contextResponse.originRef, event,
1018
+ correlation: { toolCorrelationId: cap.call_id, resultRef } };
1019
+ }
1020
+
1021
+ return { resolveContext, resolveEvent };
1022
+ };
1023
+
895
1024
  // ---- Capture record builder (consumed by state-persist.js) ----------------------
896
1025
 
897
1026
  // Builds the retained capture record for a Claude hook payload. The field names
@@ -1028,6 +1157,24 @@ function readCaptureView(sessionDir) {
1028
1157
  return { records: view, tampered: false };
1029
1158
  }
1030
1159
 
1160
+ function readOpencodeCaptureView(sessionDir) {
1161
+ const file = path.join(sessionDir, OPENCODE_CAPTURE_FILE);
1162
+ try {
1163
+ if (fs.statSync(file).size > OPENCODE_CAPTURE_LIMIT_BYTES) return { records: [], tampered: true };
1164
+ const text = fs.readFileSync(file, 'utf8');
1165
+ const records = text.split(/\r?\n/).filter(Boolean).map(line => JSON.parse(line));
1166
+ if (!records.every(item => recordOf(item) && item.schema === OPENCODE_CAPTURE_RECORD_VERSION
1167
+ && item.hostId === OPENCODE_HOST_ID && textOf(item.session_id) && textOf(item.call_id)
1168
+ && textOf(item.tool) && Object.prototype.hasOwnProperty.call(item, 'status'))) {
1169
+ return { records: [], tampered: true };
1170
+ }
1171
+ return { records, tampered: false };
1172
+ } catch (error) {
1173
+ if (error.code === 'ENOENT') return { records: [], tampered: false };
1174
+ return { records: [], tampered: true };
1175
+ }
1176
+ }
1177
+
1031
1178
  // Observation-time identity: the workflow and pin the host event was captured under. Absent before a workflow starts.
1032
1179
  function observedIdentityFor(sessionDir) {
1033
1180
  try {
@@ -1053,7 +1200,8 @@ function reviewRecordIndependent(cap, captures, principals) {
1053
1200
  }
1054
1201
 
1055
1202
  // Keep the old state-persist seam as an alias; it points at the single resolver above.
1056
- module.exports = { createClaudeOriginProvider, buildCaptureRecord, resolveDocCheckInvocation,
1203
+ module.exports = { createClaudeOriginProvider, createOpencodeOriginProvider, buildCaptureRecord, resolveDocCheckInvocation,
1057
1204
  registeredInstalledCheck: resolveDocCheckInvocation, installedDocCheck,
1058
1205
  fileDigest, SHIPPED_DOC_CHECK_DIGEST, trustRisk, journalExecutors, reviewRecordIndependent,
1059
- writeImmutableEvent, rebuildJournalView, readCaptureView, observedIdentityFor, _internals: { captureJson, captureDigest, digestText, canonicalCapture } };
1206
+ writeImmutableEvent, rebuildJournalView, readCaptureView, readOpencodeCaptureView, observedIdentityFor,
1207
+ _internals: { captureJson, captureDigest, digestText, canonicalCapture } };
@@ -14,6 +14,7 @@ function decide(payload) {
14
14
  try {
15
15
  const { planningUnresolved, unresolvedObligations } = require('./lib/workflow-obligations');
16
16
  const context = loadWorkflow(payload);
17
+ context.activeHost = payload && typeof payload.host_id === 'string' ? payload.host_id : undefined;
17
18
  const { workflow, sessionDir } = context;
18
19
  if (!workflow || workflow.state === 'deferred') return;
19
20
  const handoffFile = path.join(sessionDir, 'handoff-state.json');
@@ -93,4 +94,6 @@ function decide(payload) {
93
94
  } catch (error) { warn(error && error.message ? error.message : String(error)); }
94
95
  }
95
96
 
96
- readHookInput(decide);
97
+ if (require.main === module) readHookInput(decide);
98
+
99
+ module.exports = { decide };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "harness-everything",
4
- "version": "0.41.3",
4
+ "version": "0.42.0",
5
5
  "description": "Invariant-first engineering harness for routing, verification, and failure recovery while preserving agent autonomy.",
6
6
  "author": {
7
7
  "name": "Miya Daniel",
package/sbom.cdx.json CHANGED
@@ -2,23 +2,23 @@
2
2
  "$schema": "https://cyclonedx.org/schema/bom-1.7.schema.json",
3
3
  "bomFormat": "CycloneDX",
4
4
  "specVersion": "1.7",
5
- "serialNumber": "urn:uuid:e4948d5f-cae4-5b4e-84bc-19997b97c420",
5
+ "serialNumber": "urn:uuid:72e1dfda-07d6-5dc0-a4a1-3cc122ec6c96",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-10-25T06:53:03.342Z",
8
+ "timestamp": "2026-10-25T08:17:49.469Z",
9
9
  "tools": [
10
10
  {
11
11
  "vendor": "Harness Everything",
12
12
  "name": "generate-sbom.js",
13
- "version": "0.41.3"
13
+ "version": "0.42.0"
14
14
  }
15
15
  ],
16
16
  "component": {
17
17
  "type": "application",
18
- "bom-ref": "pkg:npm/harness-everything@0.41.3",
18
+ "bom-ref": "pkg:npm/harness-everything@0.42.0",
19
19
  "name": "harness-everything",
20
- "version": "0.41.3",
21
- "purl": "pkg:npm/harness-everything@0.41.3"
20
+ "version": "0.42.0",
21
+ "purl": "pkg:npm/harness-everything@0.42.0"
22
22
  }
23
23
  },
24
24
  "components": [
@@ -2033,7 +2033,7 @@
2033
2033
  ]
2034
2034
  },
2035
2035
  {
2036
- "ref": "pkg:npm/harness-everything@0.41.3",
2036
+ "ref": "pkg:npm/harness-everything@0.42.0",
2037
2037
  "dependsOn": [
2038
2038
  "pkg:npm/%40commitlint/cli@19.8.1",
2039
2039
  "pkg:npm/%40commitlint/config-conventional@19.8.1",