harness-everything 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +29 -0
- package/ci/archive/325-prep/README.md +9 -2
- package/ci/archive/325-prep/doc-reconciliation-red.js +34 -8
- package/ci/fixtures/468-dispatch/agy-quota-PROVENANCE.md +19 -0
- package/ci/fixtures/468-dispatch/agy-quota-direct-individual.stderr +2 -0
- package/ci/fixtures/468-dispatch/agy-quota-direct-third-party.stderr +2 -0
- package/ci/fixtures/468-dispatch/agy-quota-exec-individual.log +3 -0
- package/ci/fixtures/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
- package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
- package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
- package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
- package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
- package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
- package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
- package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
- package/ci/fixtures/stop/fail-session-writes.js +109 -0
- package/ci/fixtures/workflow-contract/cases.json +3355 -0
- package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
- package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
- package/ci/mechanism-2an-workflow-replay.test.js +324 -0
- package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
- package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
- package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
- package/ci/mechanism-325-3b-preparation.test.js +208 -49
- package/ci/mechanism-325-3b-s1-review.test.js +20 -828
- package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
- package/ci/mechanism-325-f3-derived-views.test.js +140 -0
- package/ci/mechanism-341-opencode-lane.test.js +164 -284
- package/ci/mechanism-35-verification-contract.test.js +246 -0
- package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
- package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
- package/ci/mechanism-397-opencode-observations.test.js +151 -18
- package/ci/mechanism-468-dispatch-cli.test.js +1496 -4
- package/ci/mechanism-548-bigint-identity.test.js +531 -0
- package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
- package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
- package/ci/mechanism-553-p3-plan-start.test.js +212 -0
- package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
- package/ci/mechanism-553-stop.test.js +427 -0
- package/ci/mechanism-553-t2a-derive.test.js +110 -0
- package/ci/mechanism-553-t2c-derive.test.js +94 -0
- package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
- package/ci/mechanism-error-ledger-oracle.test.js +786 -3
- package/ci/mechanism-error-ledger-scan.test.js +981 -0
- package/ci/mechanism-outline-sanitizer.test.js +0 -8
- package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
- package/ci/mechanism-prb-outline-review.test.js +101 -3283
- package/ci/mechanism-report-writer.test.js +45 -0
- package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
- package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
- package/docs/doc-workflow-reconciliation.md +17 -2
- package/docs/document-lifecycle.md +6 -2
- package/docs/error-handling/details/c8-dispatch-cli.md +109 -13
- package/docs/platform-capabilities.md +35 -5
- package/error-ledger-bootstrap/SKILL.md +1 -1
- package/error-ledger-bootstrap/references/workflow.md +42 -7
- package/error-ledger-bootstrap/scripts/promote.js +8 -6
- package/error-ledger-bootstrap/scripts/scan.js +525 -12
- package/hooks/hooks.json +0 -46
- package/hooks/scripts/lib/workflow-obligations.js +0 -55
- package/hooks/scripts/state-persist.js +7 -95
- package/hooks/scripts/workflow-disposition.js +0 -2
- package/hooks/scripts/workflow-stop-gate.js +17 -30
- package/opencode-plugin/index.mjs +6 -70
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +0 -55
- package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
- package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
- package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +1 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +42 -7
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +8 -6
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +525 -12
- package/sbom.cdx.json +7 -7
- package/scripts/dispatch.js +499 -87
- package/scripts/error-ledger-oracle.js +521 -27
- package/scripts/errors-sync.js +4 -3
- package/scripts/report-writer.js +4 -3
- package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
- package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
- package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
- package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
- package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
- package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
- package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
- package/ci/lib/doc-reconciliation-file-spy.js +0 -23
- package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
- package/ci/lib/doc-reconciliation-replay.js +0 -104
- package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
- package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
- package/ci/mechanism-325-3b-s1.test.js +0 -188
- package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
- package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
- package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
- package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
- package/ci/mechanism-325-f4-invariants.test.js +0 -606
- package/ci/mechanism-325-f4-projections.test.js +0 -392
- package/ci/mechanism-325-f4-qualification.test.js +0 -228
- package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
- package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
- package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
- package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
- package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
- package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
- package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
- package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
- package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
- package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
- package/hooks/scripts/w6-state-operations.js +0 -239
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
- package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
- package/scripts/system-one-eval-laya.js +0 -112
- /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
- /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"schema": "harness.doc-reconciliation.qualification.v1",
|
|
3
|
-
"host": "claude-code",
|
|
4
|
-
"hostVersion": "2.1.308",
|
|
5
|
-
"captureRecordVersion": "claude-capture-record/1",
|
|
6
|
-
"run": "Run 2b",
|
|
7
|
-
"payloadKinds": {
|
|
8
|
-
"PostToolUse": [
|
|
9
|
-
"agent_id",
|
|
10
|
-
"interrupted",
|
|
11
|
-
"tool_use_id"
|
|
12
|
-
],
|
|
13
|
-
"PreToolUse": [
|
|
14
|
-
"agent_id",
|
|
15
|
-
"tool_use_id"
|
|
16
|
-
],
|
|
17
|
-
"SubagentStart": [
|
|
18
|
-
"agent_id"
|
|
19
|
-
],
|
|
20
|
-
"SubagentStop": [
|
|
21
|
-
"agent_id"
|
|
22
|
-
]
|
|
23
|
-
},
|
|
24
|
-
"correlation": {
|
|
25
|
-
"preToPostByToolUseId": true,
|
|
26
|
-
"interruptedExplicit": true,
|
|
27
|
-
"subagentStartStopSameAgent": true,
|
|
28
|
-
"agentResultAliasCorrelated": true
|
|
29
|
-
},
|
|
30
|
-
"sanitizedCapture": {
|
|
31
|
-
"file": "doc-reconciliation-capture.sanitized.jsonl",
|
|
32
|
-
"sha256": "db4d8c85d2ba0fd06f53f455f31b125dd194e9a22cb337687bc0e295a16f02e5"
|
|
33
|
-
},
|
|
34
|
-
"outlineDispatchCapture": {
|
|
35
|
-
"mapping": {
|
|
36
|
-
"version": "claude-outline-dispatch-mapping/2",
|
|
37
|
-
"promptField": "tool_input.prompt",
|
|
38
|
-
"dispatchKey": "session_id+tool_use_id",
|
|
39
|
-
"runInBackgroundField": "tool_input.run_in_background",
|
|
40
|
-
"isolationPresenceField": "tool_input.isolation",
|
|
41
|
-
"resultAgentIdField": "tool_response.agentId",
|
|
42
|
-
"resultStatusField": "tool_response.status",
|
|
43
|
-
"workerStartEvent": "SubagentStart",
|
|
44
|
-
"workerStopEvent": "SubagentStop",
|
|
45
|
-
"workerIdentity": "session_id+agent_id",
|
|
46
|
-
"workerRootField": "cwd"
|
|
47
|
-
},
|
|
48
|
-
"file": "doc-reconciliation-outline-capture.sanitized.jsonl",
|
|
49
|
-
"sha256": "6feb440af12aaf878a0bed5cb750f29e27d271a9add93001e151746980230b7f",
|
|
50
|
-
"hostVersion": "2.1.312",
|
|
51
|
-
"run": "run8",
|
|
52
|
-
"baseline": "1bd0f805031c5577a6e7f72a9bc5b41618b71fc1"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const crypto = require('crypto');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const { getWorkspaceRoot, getSessionDir } = require('./lib/harness-state');
|
|
8
|
-
const { canonical } = require('./lib/workflow-isolation');
|
|
9
|
-
|
|
10
|
-
const INVENTORY_FILE = 'doc-reconciliation/outline-confirmation/inventory';
|
|
11
|
-
const APPROVED_INVENTORY = 'benchmarks/results/live-host/claude-341-outline-dispatch-2026-10-28/inventory/2741bd4514d2cd68f57d93a2b3ce94cbe597ca62d30e26f0ca58e882df5b03c6.md';
|
|
12
|
-
|
|
13
|
-
function git(root, args, buffer = false) {
|
|
14
|
-
const { execFileSync } = require('child_process');
|
|
15
|
-
return execFileSync('git', ['-C', root, ...args], { encoding: buffer ? null : 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function readJson(file) { return JSON.parse(fs.readFileSync(file, 'utf8')); }
|
|
19
|
-
function sha(bytes) { return crypto.createHash('sha256').update(bytes).digest('hex'); }
|
|
20
|
-
function jsonBytes(value) { return Buffer.from(JSON.stringify(value, null, 2) + '\n'); }
|
|
21
|
-
function same(left, right) { return JSON.stringify(left) === JSON.stringify(right); }
|
|
22
|
-
|
|
23
|
-
function safeStatePath(sessionDir, relative, allowMissing = false) {
|
|
24
|
-
const sessionRoot = fs.realpathSync.native(sessionDir);
|
|
25
|
-
if (path.isAbsolute(relative) || relative.split(/[\\/]/).some(part => !part || part === '.' || part === '..')) {
|
|
26
|
-
throw new Error('invalid-state-destination');
|
|
27
|
-
}
|
|
28
|
-
const destination = path.resolve(sessionRoot, relative);
|
|
29
|
-
const within = path.relative(sessionRoot, destination);
|
|
30
|
-
if (!within || within.startsWith('..' + path.sep) || within === '..' || path.isAbsolute(within)) throw new Error('state-destination-escape');
|
|
31
|
-
let cursor = sessionRoot;
|
|
32
|
-
const parts = relative.split(/[\\/]/);
|
|
33
|
-
for (let index = 0; index < parts.length; index += 1) {
|
|
34
|
-
cursor = path.join(cursor, parts[index]);
|
|
35
|
-
try {
|
|
36
|
-
const stat = fs.lstatSync(cursor);
|
|
37
|
-
if (stat.isSymbolicLink() || (index < parts.length - 1 && !stat.isDirectory())
|
|
38
|
-
|| (index === parts.length - 1 && !stat.isFile())) throw new Error('state-destination-not-regular');
|
|
39
|
-
} catch (error) {
|
|
40
|
-
if (error.code !== 'ENOENT') throw error;
|
|
41
|
-
if (!allowMissing) throw error;
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const parent = path.dirname(destination);
|
|
46
|
-
if (fs.existsSync(parent) && fs.realpathSync.native(parent) !== path.resolve(sessionRoot, path.dirname(relative))) {
|
|
47
|
-
throw new Error('state-destination-parent-alias');
|
|
48
|
-
}
|
|
49
|
-
return destination;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function writeNewStateFile(sessionDir, relative, bytes) {
|
|
53
|
-
const file = safeStatePath(sessionDir, relative, true);
|
|
54
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
55
|
-
safeStatePath(sessionDir, relative, true);
|
|
56
|
-
fs.writeFileSync(file, bytes, { flag: 'wx' });
|
|
57
|
-
if (fs.realpathSync.native(path.dirname(file)) !== path.resolve(fs.realpathSync.native(sessionDir), path.dirname(relative))) {
|
|
58
|
-
throw new Error('state-destination-parent-alias');
|
|
59
|
-
}
|
|
60
|
-
return file;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function loadProvider() { return require('./lib/doc-reconciliation-provider'); }
|
|
64
|
-
|
|
65
|
-
function hostInvocation(sessionId, operation) {
|
|
66
|
-
const root = canonical(getWorkspaceRoot());
|
|
67
|
-
const sessionDir = getSessionDir(root, sessionId);
|
|
68
|
-
const provider = loadProvider();
|
|
69
|
-
const captures = provider.readCaptureView(sessionDir);
|
|
70
|
-
if (captures.tampered) throw new Error('capture-view-tampered');
|
|
71
|
-
const script = fs.realpathSync.native(__filename);
|
|
72
|
-
const matched = captures.records.filter(record => {
|
|
73
|
-
if (!record || record.event !== 'PreToolUse' || record.tool_name !== 'Bash'
|
|
74
|
-
|| record.session_id !== sessionId || record.agent_id !== undefined || !record.tool_use_id) return false;
|
|
75
|
-
let cwd;
|
|
76
|
-
try { cwd = canonical(record.cwd); } catch { return false; }
|
|
77
|
-
if (cwd !== root) return false;
|
|
78
|
-
const parsed = provider._internals.safeTokenize(record.command);
|
|
79
|
-
if (!parsed.ok || parsed.tokens.length !== 5 || !['node', 'nodejs'].includes(parsed.tokens[0])) return false;
|
|
80
|
-
let invoked;
|
|
81
|
-
try { invoked = fs.realpathSync.native(path.resolve(cwd, parsed.tokens[1])); } catch { return false; }
|
|
82
|
-
return invoked === script && parsed.tokens[2] === operation
|
|
83
|
-
&& parsed.tokens[3] === '--session-id' && parsed.tokens[4] === sessionId;
|
|
84
|
-
});
|
|
85
|
-
if (matched.length !== 1) throw new Error('unique-correlated-pre-invocation-required');
|
|
86
|
-
const pre = matched[0];
|
|
87
|
-
if (captures.records.some(record => record && record.ref !== pre.ref && record.session_id === sessionId
|
|
88
|
-
&& record.tool_use_id === pre.tool_use_id && ['PostToolUse', 'PostToolUseFailure'].includes(record.event))) {
|
|
89
|
-
throw new Error('operation-already-completed');
|
|
90
|
-
}
|
|
91
|
-
return { root, sessionDir, provider, captures: captures.records, pre };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function loadRow17State(root, sessionDir) {
|
|
95
|
-
const workflow = readJson(path.join(sessionDir, 'workflow-run.json'));
|
|
96
|
-
const task = workflow.docReconciliationTask;
|
|
97
|
-
const baseline = workflow.docReconciliationBaseline;
|
|
98
|
-
if (workflow.strategy !== 'iterative-single' || workflow.state !== 'running' || !Number.isInteger(workflow.revision)
|
|
99
|
-
|| !task || task.schema !== 'harness.doc-reconciliation-task-pin.v1'
|
|
100
|
-
|| !same(task.requirementIds, ['adr-evid', 'verify-row17']) || task.taskId !== 'task-adr-evid+verify-row17'
|
|
101
|
-
|| task.sessionId !== workflow.sessionId || task.workflowId !== workflow.workflowId
|
|
102
|
-
|| !baseline || canonical(baseline.root) !== root || task.baselineRoot !== baseline.root
|
|
103
|
-
|| task.baselineCommit !== baseline.commit) throw new Error('row17-task-pin-invalid');
|
|
104
|
-
return { workflow, task, baseline };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function inventoryBytes(provider) {
|
|
108
|
-
const source = path.resolve(__dirname, '..', '..', APPROVED_INVENTORY);
|
|
109
|
-
if (fs.existsSync(source)) return fs.readFileSync(source);
|
|
110
|
-
const capture = path.join(__dirname, 'lib/doc-reconciliation-outline-capture.sanitized.jsonl');
|
|
111
|
-
for (const line of fs.readFileSync(capture, 'utf8').split(/\r?\n/)) {
|
|
112
|
-
if (!line) continue;
|
|
113
|
-
const record = JSON.parse(line);
|
|
114
|
-
const candidates = [record.tool_response?.content?.[0]?.text, record.tool_response?.file?.content, record.tool_response?.stdout];
|
|
115
|
-
for (const value of candidates) {
|
|
116
|
-
if (typeof value === 'string' && sha(Buffer.from(value)) === provider._internals.OUTLINE_INVENTORY_PIN.sha256) {
|
|
117
|
-
return Buffer.from(value);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
throw new Error('pinned-inventory-bytes-unavailable');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function inventory({ sessionId }) {
|
|
125
|
-
const context = hostInvocation(sessionId, 'inventory');
|
|
126
|
-
const { root, sessionDir, provider } = context;
|
|
127
|
-
const { workflow, task, baseline } = loadRow17State(root, sessionDir);
|
|
128
|
-
const head = git(root, ['rev-parse', '--verify', 'HEAD^{commit}']).trim();
|
|
129
|
-
const tree = git(root, ['rev-parse', '--verify', 'HEAD^{tree}']).trim();
|
|
130
|
-
if (head !== baseline.commit || tree !== baseline.tree || git(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all'], true).length) {
|
|
131
|
-
throw new Error('inventory-must-run-on-clean-baseline');
|
|
132
|
-
}
|
|
133
|
-
const expectedPin = provider._internals.OUTLINE_INVENTORY_PIN;
|
|
134
|
-
const bytes = inventoryBytes(provider);
|
|
135
|
-
const validated = provider._internals.validateOutlineInventoryPin({ bytes, pin: expectedPin, expectedPin });
|
|
136
|
-
const row = provider._internals.resolveInventoryRow({ parsed: validated.parsed, pin: expectedPin }, '17');
|
|
137
|
-
if (sha(bytes) !== expectedPin.sha256 || validated.state !== 'accepted' || row.state !== 'accepted' || row.row.domain !== 'EVID'
|
|
138
|
-
|| expectedPin.rowDomainMappings[0].approvalRef !== 'https://github.com/dyphn1/Harness-everything/issues/325#issuecomment-6706805112') {
|
|
139
|
-
throw new Error('pinned-row17-inventory-invalid');
|
|
140
|
-
}
|
|
141
|
-
const inventoryRelative = `${INVENTORY_FILE}/${path.posix.basename(expectedPin.retainedArtifactPath)}`;
|
|
142
|
-
const pinRelative = `${INVENTORY_FILE}/inventory-pin.json`;
|
|
143
|
-
writeNewStateFile(sessionDir, inventoryRelative, bytes);
|
|
144
|
-
writeNewStateFile(sessionDir, pinRelative, jsonBytes(expectedPin));
|
|
145
|
-
return { operation: 'inventory', workflowId: workflow.workflowId, revision: workflow.revision, taskId: task.taskId,
|
|
146
|
-
destinations: [inventoryRelative, pinRelative], sha256: expectedPin.sha256 };
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function seal({ sessionId }) {
|
|
150
|
-
const context = hostInvocation(sessionId, 'seal');
|
|
151
|
-
const { root, sessionDir, provider, captures } = context;
|
|
152
|
-
const { workflow, task, baseline } = loadRow17State(root, sessionDir);
|
|
153
|
-
const head = git(root, ['rev-parse', '--verify', 'HEAD^{commit}']).trim();
|
|
154
|
-
const tree = git(root, ['rev-parse', '--verify', 'HEAD^{tree}']).trim();
|
|
155
|
-
if (head === baseline.commit || git(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all'], true).length
|
|
156
|
-
|| git(root, ['merge-base', '--is-ancestor', baseline.commit, head]) !== '') throw new Error('seal-requires-clean-b-to-o-outline');
|
|
157
|
-
const expectedPin = provider._internals.OUTLINE_INVENTORY_PIN;
|
|
158
|
-
const inventoryRoot = path.join(sessionDir, INVENTORY_FILE);
|
|
159
|
-
const pinFile = path.join(inventoryRoot, 'inventory-pin.json');
|
|
160
|
-
const pinBytes = fs.readFileSync(pinFile);
|
|
161
|
-
const pin = JSON.parse(pinBytes.toString('utf8'));
|
|
162
|
-
const bytes = fs.readFileSync(path.join(inventoryRoot, path.posix.basename(expectedPin.retainedArtifactPath)));
|
|
163
|
-
const inventory = provider._internals.validateOutlineInventoryPin({ bytes, pin, expectedPin });
|
|
164
|
-
if (inventory.state !== 'accepted' || sha(pinBytes) !== sha(jsonBytes(expectedPin))) throw new Error('pinned-inventory-not-installed');
|
|
165
|
-
const inventoryPath = `doc-reconciliation/outline-confirmation/inventory/${path.posix.basename(expectedPin.retainedArtifactPath)}`;
|
|
166
|
-
const reviewEvents = captures.filter(record => record && record.event === 'SubagentStop' && record.agent_type === 'reviewer'
|
|
167
|
-
&& record.reviewVerdict === 'approve' && record.reviewSummary);
|
|
168
|
-
const candidates = reviewEvents.filter(review => {
|
|
169
|
-
const targets = Object.keys(review.reviewedArtifactDigests || {}).filter(relative => relative !== inventoryPath);
|
|
170
|
-
return targets.length === 1 && review.reviewedArtifactDigests[inventoryPath] === sha(bytes);
|
|
171
|
-
});
|
|
172
|
-
if (candidates.length !== 1) throw new Error('unique-approved-outline-review-required');
|
|
173
|
-
const review = candidates[0];
|
|
174
|
-
const targetPaths = Object.keys(review.reviewedArtifactDigests).filter(relative => relative !== inventoryPath);
|
|
175
|
-
const target = targetPaths[0];
|
|
176
|
-
const targetBytes = git(root, ['show', `${head}:${target}`], true);
|
|
177
|
-
const citation = provider._internals.parseOutlineCitation(targetBytes, target);
|
|
178
|
-
const row = provider._internals.resolveInventoryRow(inventory, citation.rowId);
|
|
179
|
-
const targetBlob = git(root, ['rev-parse', `${head}:${target}`]).trim();
|
|
180
|
-
if (citation.state !== 'accepted' || citation.rowId !== '17' || citation.domain !== 'EVID'
|
|
181
|
-
|| row.state !== 'accepted' || row.row.domain !== 'EVID'
|
|
182
|
-
|| review.reviewedArtifactDigests[target] !== sha(targetBytes)) throw new Error('approved-outline-does-not-match-pinned-row17');
|
|
183
|
-
const start = captures.filter(record => record && record.event === 'SubagentStart' && record.agent_id === review.agent_id);
|
|
184
|
-
const launch = captures.filter(record => record && record.event === 'PostToolUse' && ['Task', 'Agent'].includes(record.tool_name)
|
|
185
|
-
&& record.agent_id === review.agent_id);
|
|
186
|
-
if (start.length !== 1 || launch.length !== 1 || captures.indexOf(start[0]) >= captures.indexOf(review)
|
|
187
|
-
|| captures.indexOf(launch[0]) >= captures.indexOf(review)
|
|
188
|
-
|| start[0].outlineIdentity?.state !== 'accepted'
|
|
189
|
-
|| start[0].outlineIdentity.identity.outlineCommit !== head || start[0].outlineIdentity.identity.outlineTree !== tree
|
|
190
|
-
|| !provider.reviewRecordIndependent(review, captures, { author: sessionId,
|
|
191
|
-
executors: provider.journalExecutors(captures, sessionId) })) throw new Error('outline-review-lifecycle-or-identity-invalid');
|
|
192
|
-
const outlineDigests = { [target]: sha(targetBytes) };
|
|
193
|
-
const attemptId = 'attempt-' + sha(review.ref).slice(0, 16);
|
|
194
|
-
const attemptRelative = `doc-reconciliation/outline-confirmation/${task.taskId}/attempts/${attemptId}`;
|
|
195
|
-
const attemptDir = path.join(sessionDir, attemptRelative);
|
|
196
|
-
const lease = { schema: 'harness.outline-writer-lease.v1', id: 'lease-' + sha(review.ref).slice(0, 16),
|
|
197
|
-
taskId: task.taskId, attemptId, principalId: sessionId, root, exclusive: true, active: true };
|
|
198
|
-
const leaseRelative = `${attemptRelative}/writer-lease.json`;
|
|
199
|
-
const leaseBytes = jsonBytes(lease);
|
|
200
|
-
const leaseDigest = sha(leaseBytes);
|
|
201
|
-
const reviewDigest = provider._internals.captureDigest(review);
|
|
202
|
-
const handoff = {
|
|
203
|
-
schema: 'harness.outline-handoff.v1', handoffId: 'handoff-' + sha(review.ref).slice(0, 16),
|
|
204
|
-
taskId: task.taskId, attemptId, supersedesAttemptId: null, workspaceId: task.workspaceId,
|
|
205
|
-
workflowId: workflow.workflowId, workflowRevision: workflow.revision, sessionId, hostId: 'claude-code',
|
|
206
|
-
baseline: { root: baseline.root, commit: baseline.commit, tree: baseline.tree, configDigest: task.configDigest },
|
|
207
|
-
configDigest: task.configDigest, targetPaths, draftWorktreeRoot: root,
|
|
208
|
-
outline: { commit: head, tree, targetBlobs: { [target]: { blobOid: targetBlob, storedBytesSha256: sha(targetBytes) } } },
|
|
209
|
-
inventory: { ...expectedPin, rowId: '17', domain: 'EVID', targetPaths },
|
|
210
|
-
reviewCaptureRef: review.ref, reviewCaptureDigest: reviewDigest, reviewDigest: review.reviewDigest,
|
|
211
|
-
coordinatorPrincipal: sessionId, writerLeaseId: lease.id, writerLeaseDigest: leaseDigest,
|
|
212
|
-
draftDispatchToken: crypto.randomBytes(24).toString('hex'),
|
|
213
|
-
};
|
|
214
|
-
const validatedReview = provider._internals.validateOutlineReview({ handoff, attemptDir, captures, targetPaths,
|
|
215
|
-
outlineDigests, inventory, sessionId });
|
|
216
|
-
if (validatedReview.state !== 'accepted') throw new Error(validatedReview.reason || 'outline-review-invalid');
|
|
217
|
-
const handoffRelative = `${attemptRelative}/handoff.json`;
|
|
218
|
-
fs.mkdirSync(attemptDir, { recursive: true });
|
|
219
|
-
writeNewStateFile(sessionDir, leaseRelative, leaseBytes);
|
|
220
|
-
writeNewStateFile(sessionDir, handoffRelative, jsonBytes(handoff));
|
|
221
|
-
return { operation: 'seal', workflowId: workflow.workflowId, revision: workflow.revision, taskId: task.taskId,
|
|
222
|
-
attemptId, destinations: [leaseRelative, handoffRelative], handoff };
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function main(argv) {
|
|
226
|
-
const [operation, flag, sessionId, extra] = argv;
|
|
227
|
-
if (!['inventory', 'seal'].includes(operation) || flag !== '--session-id' || !sessionId || extra !== undefined) {
|
|
228
|
-
throw new Error('Usage: w6-state-operations.js <inventory|seal> --session-id <id>');
|
|
229
|
-
}
|
|
230
|
-
const result = operation === 'inventory' ? inventory({ sessionId }) : seal({ sessionId });
|
|
231
|
-
process.stdout.write(JSON.stringify(result) + '\n');
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (require.main === module) {
|
|
235
|
-
try { main(process.argv.slice(2)); }
|
|
236
|
-
catch (error) { console.error('[W6 State Operation] ' + error.message); process.exitCode = 2; }
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
module.exports = { main };
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
// Research evaluation driver for the fine-tuned Laya bridge (#255 Phase 3).
|
|
4
|
-
// It does NOT touch provider.js/resident.js (still cua-only): it starts the
|
|
5
|
-
// laya resident server itself, scores cases through it, and feeds the
|
|
6
|
-
// production decide()/evaluate() machinery. Usage:
|
|
7
|
-
// score <cases.json> <manifest.json> <records.json> [workdir]
|
|
8
|
-
// report <corpus.json> <records.json> <report.json> [--secondary-threshold T]
|
|
9
|
-
// cases.json: { cases: [{ id, baseline, request }] } (request = holdout-style,
|
|
10
|
-
// context + 13 catalog options). records.json matches evaluate() input.
|
|
11
|
-
const fs = require('node:fs');
|
|
12
|
-
const path = require('node:path');
|
|
13
|
-
const net = require('node:net');
|
|
14
|
-
const { spawn } = require('node:child_process');
|
|
15
|
-
const { performance } = require('node:perf_hooks');
|
|
16
|
-
const { evaluate } = require('../harness-everything/scripts/system-one/evaluate');
|
|
17
|
-
const { decide } = require('../harness-everything/scripts/system-one/contract');
|
|
18
|
-
const { decisionPolicy } = require('../harness-everything/scripts/system-one/provider');
|
|
19
|
-
|
|
20
|
-
const ADAPTER = path.join(__dirname, '..', 'harness-everything', 'scripts', 'system-one', 'laya_adapter.py');
|
|
21
|
-
const CALL_TIMEOUT_MS = 30000;
|
|
22
|
-
|
|
23
|
-
function send(port, token, message) {
|
|
24
|
-
return new Promise(resolve => {
|
|
25
|
-
const socket = net.connect({ port, host: '127.0.0.1' });
|
|
26
|
-
const chunks = [];
|
|
27
|
-
const done = value => { socket.destroy(); resolve(value); };
|
|
28
|
-
const timer = setTimeout(() => done({ ok: false, reason: 'timeout' }), CALL_TIMEOUT_MS);
|
|
29
|
-
socket.on('connect', () => socket.end(`${JSON.stringify({ token, ...message })}\n`));
|
|
30
|
-
socket.on('data', c => chunks.push(c));
|
|
31
|
-
socket.on('end', () => { clearTimeout(timer);
|
|
32
|
-
try { done(JSON.parse(Buffer.concat(chunks).toString('utf8'))); }
|
|
33
|
-
catch (_) { done({ ok: false, reason: 'bad-reply' }); } });
|
|
34
|
-
socket.on('error', () => { clearTimeout(timer); done({ ok: false, reason: 'io' }); });
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function withServer(python, manifest, workdir, fn) {
|
|
39
|
-
const manifestJson = JSON.stringify(manifest);
|
|
40
|
-
const state = path.join(workdir, 'laya-research-state.json');
|
|
41
|
-
const lock = path.join(workdir, 'laya-research-state.starting');
|
|
42
|
-
for (const f of [state, lock]) try { fs.unlinkSync(f); } catch (_) { /* fresh */ }
|
|
43
|
-
const child = spawn(python, [ADAPTER, '--serve', manifestJson, state, lock], { stdio: 'ignore' });
|
|
44
|
-
const deadline = Date.now() + 120000;
|
|
45
|
-
let info = null;
|
|
46
|
-
while (Date.now() < deadline) {
|
|
47
|
-
try { info = JSON.parse(fs.readFileSync(state, 'utf8')); if (info.port && info.token) break; } catch (_) { /* starting */ }
|
|
48
|
-
if (child.exitCode !== null) throw new Error(`server exited during startup (code ${child.exitCode})`);
|
|
49
|
-
await new Promise(r => setTimeout(r, 200));
|
|
50
|
-
info = null;
|
|
51
|
-
}
|
|
52
|
-
if (!info) { child.kill('SIGKILL'); throw new Error('server did not become ready'); }
|
|
53
|
-
try {
|
|
54
|
-
return await fn(info);
|
|
55
|
-
} finally {
|
|
56
|
-
try { await send(info.port, info.token, { op: 'shutdown' }); } catch (_) { /* exiting */ }
|
|
57
|
-
child.kill('SIGKILL');
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function score(casesPath, manifestPath, recordsPath, workdir) {
|
|
62
|
-
const { cases } = JSON.parse(fs.readFileSync(casesPath, 'utf8'));
|
|
63
|
-
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
64
|
-
const policy = decisionPolicy(manifest.acceptance);
|
|
65
|
-
const records = await withServer(manifest.python, manifest, workdir, async info => {
|
|
66
|
-
const out = [];
|
|
67
|
-
for (const c of cases) {
|
|
68
|
-
const runs = [];
|
|
69
|
-
for (let i = 0; i < 2; i++) {
|
|
70
|
-
const start = performance.now();
|
|
71
|
-
const reply = await send(info.port, info.token, { op: 'score', request: c.request });
|
|
72
|
-
const latencyMs = performance.now() - start;
|
|
73
|
-
let decision;
|
|
74
|
-
let scores = null;
|
|
75
|
-
if (reply.ok) {
|
|
76
|
-
decision = decide(c.request, reply.response, policy);
|
|
77
|
-
if (decision.selectedId === 'unclassified') {
|
|
78
|
-
decision = { ...decision, status: 'abstain', reason: 'unclassified', selectedId: null };
|
|
79
|
-
}
|
|
80
|
-
if (['accepted', 'abstain'].includes(decision.status)) scores = reply.response.scores.map(s => s.probability);
|
|
81
|
-
} else {
|
|
82
|
-
decision = { status: 'unavailable', reason: reply.reason };
|
|
83
|
-
}
|
|
84
|
-
runs.push({ decision, scores, latencyMs, coldStart: false });
|
|
85
|
-
}
|
|
86
|
-
out.push({ id: c.id, baseline: c.baseline, runs });
|
|
87
|
-
}
|
|
88
|
-
return out;
|
|
89
|
-
});
|
|
90
|
-
fs.writeFileSync(recordsPath, `${JSON.stringify(records)}\n`);
|
|
91
|
-
console.log(JSON.stringify({ cases: records.length }));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function report(corpusPath, recordsPath, reportPath, secondaryThreshold) {
|
|
95
|
-
const corpus = JSON.parse(fs.readFileSync(corpusPath, 'utf8'));
|
|
96
|
-
const records = JSON.parse(fs.readFileSync(recordsPath, 'utf8'));
|
|
97
|
-
const result = evaluate(corpus, records, null, { secondaryThreshold });
|
|
98
|
-
fs.writeFileSync(reportPath, `${JSON.stringify(result, null, 2)}\n`);
|
|
99
|
-
console.log(JSON.stringify({ cases: result.cases, coverage: result.model.coverage,
|
|
100
|
-
acceptedPrecision: result.model.acceptedPrecision, rolloutReady: result.rolloutReady }));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function main() {
|
|
104
|
-
const [mode, a, b, c, d] = process.argv.slice(2);
|
|
105
|
-
if (mode === 'score' && a && b && c) return score(a, b, c, d || fs.mkdtempSync('/tmp/laya-eval-'));
|
|
106
|
-
if (mode === 'report' && a && b && c) {
|
|
107
|
-
const t = d === undefined ? undefined : Number((d.match(/^--secondary-threshold=(.+)$/) || [])[1]);
|
|
108
|
-
return report(a, b, c, t);
|
|
109
|
-
}
|
|
110
|
-
throw new Error('usage: system-one-eval-laya.js (score <cases> <manifest> <records> [workdir] | report <corpus> <records> <report> [--secondary-threshold=T])');
|
|
111
|
-
}
|
|
112
|
-
main().catch(err => { console.error(`laya research eval failed: ${err.message}`); process.exitCode = 1; });
|
|
File without changes
|
|
File without changes
|