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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +14 -0
- package/behavioral-evals/ledger-pairs/README.md +53 -0
- package/behavioral-evals/ledger-pairs/arm.js +359 -0
- package/behavioral-evals/ledger-pairs/fixture.js +138 -0
- package/behavioral-evals/ledger-pairs/preflight.js +96 -0
- package/behavioral-evals/ledger-pairs/score.js +155 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/README.md +108 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-baseline/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-1-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-baseline/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-2-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-baseline/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-3-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-baseline/arm-result.json +28 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/agy/pair-4-treatment/arm-result.json +35 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-baseline/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-1-treatment/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-baseline/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-2-treatment/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-baseline/arm-result.json +49 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-3-treatment/arm-result.json +49 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-baseline/arm-result.json +49 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-plan.json +13 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/codex/pair-4-treatment/arm-result.json +56 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-baseline/receipt.jsonl +17 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/arm-result.json +41 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-1-treatment/receipt.jsonl +58 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/arm-result.json +50 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-baseline/receipt.jsonl +101 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-2-treatment/receipt.jsonl +29 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-baseline/receipt.jsonl +23 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/arm-result.json +34 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-3-treatment/receipt.jsonl +24 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/arm-result.json +47 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-baseline/receipt.jsonl +69 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-plan.json +14 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/arm-result.json +44 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/opencode/pair-4-treatment/receipt.jsonl +65 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/run-order.sh +18 -0
- package/benchmarks/results/live-host/ledger-pairs-2026-11-28/score.json +1032 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/README.md +50 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/collect-rerun.txt +3 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/export-report.json +22 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/host-version.txt +1 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-1.json +18 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/import-report-2.json +18 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/labels-observed-excerpt.jsonl +2 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/observations-index-excerpt.json +26 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-397-turn-export/plugin-load-lines.txt +1 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/README.md +46 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/observations-index-excerpt.json +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/plugin-load-lines.txt +2 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/run-marks.txt +6 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-probe.js +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-28-450-steering-trace/steering-trace.jsonl +167 -0
- package/ci/archive/325-prep/README.md +9 -2
- package/ci/archive/325-prep/doc-reconciliation-red.js +34 -8
- 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-332-fable-directive.test.js +180 -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-552-ledger-pairs.test.js +159 -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-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/router-workflow-plan.test.js +61 -21
- 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/platform-capabilities.md +63 -16
- package/docs/platform-compatibility.json +5 -5
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/routing-keywords.json +0 -2
- package/harness-everything/scripts/tier-router.js +105 -11
- 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/rules/AGENTS.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/routing-keywords.json +0 -2
- package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +105 -11
- package/sbom.cdx.json +7 -7
- 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,336 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const crypto = require('crypto');
|
|
4
|
-
|
|
5
|
-
// Both layouts are shipped by plugin:sync. Resolve modules at import, never during a decision.
|
|
6
|
-
function runtimeModule(name) {
|
|
7
|
-
try { return require('../../../harness-everything/scripts/' + name); }
|
|
8
|
-
catch (error) {
|
|
9
|
-
if (error.code !== 'MODULE_NOT_FOUND' || !error.message.startsWith("Cannot find module '../../../harness-everything/scripts/" + name + "'")) throw error;
|
|
10
|
-
return require('../../../skills/harness-everything/scripts/' + name);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
const { checkDocObligations } = runtimeModule('doc-evidence.js');
|
|
14
|
-
const { deriveDocFacts, deriveDocObligations } = runtimeModule('doc-obligations.js');
|
|
15
|
-
const { validateDocsConfig } = runtimeModule('project-docs-resolver.js');
|
|
16
|
-
const text = value => typeof value === 'string' && value.trim().length > 0;
|
|
17
|
-
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
18
|
-
const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
19
|
-
const bytes = value => Buffer.isBuffer(value) ? Buffer.from(value)
|
|
20
|
-
: value && value.type === 'Buffer' && Array.isArray(value.data) ? Buffer.from(value.data)
|
|
21
|
-
: (() => { throw new Error('inventory-unsupported'); })();
|
|
22
|
-
function canonical(value) {
|
|
23
|
-
if (Buffer.isBuffer(value)) return { type: 'Buffer', data: [...value] };
|
|
24
|
-
if (Array.isArray(value)) return value.map(canonical);
|
|
25
|
-
if (!record(value)) return value;
|
|
26
|
-
return Object.fromEntries(Object.keys(value).sort(compare).map(key => [key, canonical(value[key])]));
|
|
27
|
-
}
|
|
28
|
-
const stable = value => JSON.stringify(canonical(value));
|
|
29
|
-
const clone = value => JSON.parse(stable(value));
|
|
30
|
-
const sha = value => crypto.createHash('sha256').update(value).digest('hex');
|
|
31
|
-
const frame = value => { const b = Buffer.isBuffer(value) ? value : Buffer.from(String(value)); return Buffer.concat([Buffer.from(b.length + ':'), b]); };
|
|
32
|
-
const hashFrames = values => sha(Buffer.concat(values.map(frame)));
|
|
33
|
-
const structuredDigest = (domain, value) => hashFrames([domain, stable(value)]);
|
|
34
|
-
const identityFields = ['workspaceId', 'sessionId', 'workflowId', 'workflowRevision', 'taskId', 'taskScopeDigest', 'baselineDigest', 'candidateDigest', 'configDigest', 'prdRoot'];
|
|
35
|
-
const validIdentity = id => record(id) && ['workspaceId', 'sessionId', 'workflowId', 'taskId'].every(key => text(id[key]))
|
|
36
|
-
&& Number.isInteger(id.workflowRevision) && id.workflowRevision >= 0 && id.prdRoot === 'docs/prd/'
|
|
37
|
-
&& ['taskScopeDigest', 'baselineDigest', 'candidateDigest', 'configDigest'].every(key => /^[a-f0-9]{64}$/.test(id[key] || ''));
|
|
38
|
-
const sameIdentity = (a, b) => validIdentity(a) && validIdentity(b) && identityFields.every(key => a[key] === b[key]);
|
|
39
|
-
const diagnostic = (code, context = {}) => ({ code, message: code.replace(/-/g, ' '), ...context });
|
|
40
|
-
const pathCompare = (a, b) => Buffer.compare(Buffer.from(a.path), Buffer.from(b.path));
|
|
41
|
-
const codedError = code => Object.assign(new Error(code), { code });
|
|
42
|
-
const PROJECT_CONFIG_PATH = '.agents/harness-everything/project-docs.json';
|
|
43
|
-
const DEPENDENCY_ARTIFACT_ROOTS = new Set(['node_modules', '.husky/_']);
|
|
44
|
-
const DEPENDENCY_POLICY_VERSION = 'dependency-artifact-scope/1';
|
|
45
|
-
// The derive contract (doc-obligations.js) decides applicability from governed/legacy documents, derived
|
|
46
|
-
// outputs and code/REQ-test paths. Records outside them cannot affect document obligations.
|
|
47
|
-
// shortcut: mirrors derive path rules, update them together until a shared classifier is exposed.
|
|
48
|
-
const CODE_EXTENSION = /\.(?:c|cc|cpp|h|hpp|m|mm|go|rs|java|kt|swift|js|jsx|mjs|cjs|ts|tsx|py|rb|php|sh|ps1|sql)$/i;
|
|
49
|
-
const TEST_PATH = /(?:^|\/)(?:test|tests|__tests__|spec)(?:\/|$)|(?:^|\/)[^/]*(?:\.test|\.spec)\.[^/]+$/i;
|
|
50
|
-
// Glob semantics of the derive contract: '**' crosses directories, '*' stays inside one segment.
|
|
51
|
-
function globToRegExp(glob) {
|
|
52
|
-
const source = String(glob).replace(/\\/g, '/').replace(/^\.\//, '');
|
|
53
|
-
let pattern = '^';
|
|
54
|
-
for (let index = 0; index < source.length; index++) {
|
|
55
|
-
const char = source[index];
|
|
56
|
-
if (char === '*' && source[index + 1] === '*') {
|
|
57
|
-
if (source[index + 2] === '/') { pattern += '(?:[\\s\\S]*/)?'; index += 2; }
|
|
58
|
-
else { pattern += '[\\s\\S]*'; index += 1; }
|
|
59
|
-
} else if (char === '*') pattern += '[^/]*';
|
|
60
|
-
else pattern += char.replace(/[|\\{}()[\]^$+?.]/g, '\\$&');
|
|
61
|
-
}
|
|
62
|
-
return new RegExp(`${pattern}$`);
|
|
63
|
-
}
|
|
64
|
-
// Semantic relevance of a path under the derive contract; null means the path cannot change applicability.
|
|
65
|
-
function semanticRelevance(path, config) {
|
|
66
|
-
const governed = Array.isArray(config && config.governed) ? config.governed : [];
|
|
67
|
-
const legacy = Array.isArray(config && config.legacy) ? config.legacy : [];
|
|
68
|
-
const derived = Array.isArray(config && config.derived) ? config.derived : [];
|
|
69
|
-
const matches = globs => globs.some(glob => typeof glob === 'string' && globToRegExp(glob).test(path));
|
|
70
|
-
if (governed.some(entry => entry && typeof entry.path === 'string' && matches([entry.path]))) return 'document';
|
|
71
|
-
if (matches(legacy)) return 'document';
|
|
72
|
-
if (derived.some(entry => entry && typeof entry.path === 'string'
|
|
73
|
-
&& (matches([entry.path]) || matches([entry.source, ...(Array.isArray(entry.sources) ? entry.sources : [])])))) return 'derived';
|
|
74
|
-
if (CODE_EXTENSION.test(path)) return 'code';
|
|
75
|
-
if (TEST_PATH.test(path)) return 'test';
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
// The derive contract reads the frontmatter of every captured file, so a record that opens a frontmatter
|
|
79
|
-
// block is observed by it even when the record's bytes cannot be decoded. Match TextDecoder's BOM handling.
|
|
80
|
-
function opensFrontmatter(stored) {
|
|
81
|
-
return stored.subarray(0, 11).toString('utf8').replace(/^\uFEFF/, '').split('\n')[0].replace(/\r$/, '') === '---';
|
|
82
|
-
}
|
|
83
|
-
// A whole-project inventory keeps every stored byte in the identity framing. Semantic derivation converts only
|
|
84
|
-
// records it can decode; a record the derive contract can observe (governed/derived/code/test path or a
|
|
85
|
-
// frontmatter document) fails closed instead of being silently dropped.
|
|
86
|
-
function deriveFiles(records, config, options = {}) {
|
|
87
|
-
const files = {};
|
|
88
|
-
for (const item of records || []) {
|
|
89
|
-
if (!record(item) || item.presence !== 'present') continue;
|
|
90
|
-
// The unchanged derive API uses ordinary object maps, whose __proto__ setter drops this path.
|
|
91
|
-
if (item.path === '__proto__') throw codedError('inventory-unsupported');
|
|
92
|
-
const stored = bytes(item.storedBytes);
|
|
93
|
-
if (options.strict && (item.digest !== sha(stored) || item.type !== 'file' || !['100644', '100755'].includes(item.mode))) {
|
|
94
|
-
throw codedError('invalid-input');
|
|
95
|
-
}
|
|
96
|
-
let content;
|
|
97
|
-
try { content = new TextDecoder('utf-8', { fatal: true }).decode(stored); }
|
|
98
|
-
catch {
|
|
99
|
-
if (semanticRelevance(item.path, config) || opensFrontmatter(stored)) throw codedError('inventory-unsupported');
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
files[item.path] = content;
|
|
103
|
-
}
|
|
104
|
-
return files;
|
|
105
|
-
}
|
|
106
|
-
const identityTupleFields = ['workspaceId', 'sessionId', 'workflowId', 'workflowRevision', 'taskId'];
|
|
107
|
-
// The captured origin context is the snapshot's only origin-correlated identity: every field it carries must be
|
|
108
|
-
// the identity the snapshot claims, the captured plan must agree with both, and the captured host must be the
|
|
109
|
-
// host the captured config was selected for (PR #353 review P1).
|
|
110
|
-
function originBound(snapshot) {
|
|
111
|
-
const context = snapshot.originContext;
|
|
112
|
-
const id = snapshot.identity;
|
|
113
|
-
if (!record(context) || !validIdentity(id)) return false;
|
|
114
|
-
for (const key of identityTupleFields) if (context[key] !== id[key]) return false;
|
|
115
|
-
const plan = snapshot.taskSemantics;
|
|
116
|
-
if (!record(plan) || !record(plan.workflow) || !record(plan.task)) return false;
|
|
117
|
-
if (plan.workflow.workflowId !== id.workflowId || plan.workflow.workflowRevision !== id.workflowRevision
|
|
118
|
-
|| plan.workflow.sessionId !== id.sessionId || plan.task.taskId !== id.taskId) return false;
|
|
119
|
-
if (plan.prdRoot !== id.prdRoot || plan.configDigest !== id.configDigest) return false;
|
|
120
|
-
const captured = context.activeHost === undefined || context.activeHost === null ? null : context.activeHost;
|
|
121
|
-
const selected = snapshot.config && snapshot.config.capture ? snapshot.config.capture.activeHost : null;
|
|
122
|
-
const chosen = selected === undefined || selected === null ? null : selected;
|
|
123
|
-
if (captured === null && chosen === null) return true;
|
|
124
|
-
return stable(captured) === stable(chosen);
|
|
125
|
-
}
|
|
126
|
-
// The captured config bytes must be the bytes the captured inventory holds for the same path; otherwise the
|
|
127
|
-
// config digest binds a parsed value that the whole-project capture contradicts (the producer's own rule).
|
|
128
|
-
function configBytesBound(snapshot) {
|
|
129
|
-
const sources = snapshot.config && snapshot.config.capture ? snapshot.config.capture.sources : null;
|
|
130
|
-
if (!Array.isArray(sources)) return false;
|
|
131
|
-
const records = Array.isArray(snapshot.candidate.records) ? snapshot.candidate.records : [];
|
|
132
|
-
for (const source of sources) {
|
|
133
|
-
const file = records.find(item => item && item.path === source.path && item.presence === 'present');
|
|
134
|
-
if (source.presence === 'present' ? !file || !bytes(source.bytes).equals(bytes(file.storedBytes)) : Boolean(file)) return false;
|
|
135
|
-
}
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
function snapshotDigest(kind, baseline, coverage, records) {
|
|
139
|
-
const fields = ['doc-snapshot-v1', kind, baseline.commit, baseline.treeRef, structuredDigest('doc-coverage-v1', coverage), String(records.length)];
|
|
140
|
-
for (const item of [...records].sort(pathCompare)) fields.push(item.path, item.presence, item.type, item.mode, bytes(item.storedBytes));
|
|
141
|
-
return hashFrames(fields);
|
|
142
|
-
}
|
|
143
|
-
function pathUnderDependencyRoot(relative, root) {
|
|
144
|
-
const candidate = String(relative).replace(/\\/g, '/').normalize('NFC').toLowerCase();
|
|
145
|
-
const prefix = root.normalize('NFC').toLowerCase();
|
|
146
|
-
return candidate === prefix || candidate.startsWith(`${prefix}/`);
|
|
147
|
-
}
|
|
148
|
-
function projectConfigFromStoredBytes(value) {
|
|
149
|
-
try {
|
|
150
|
-
const config = JSON.parse(bytes(value).toString('utf8'));
|
|
151
|
-
return validateDocsConfig(config).valid ? config : null;
|
|
152
|
-
} catch { return null; }
|
|
153
|
-
}
|
|
154
|
-
function validCoverage(snapshot) {
|
|
155
|
-
const coverage = snapshot.candidate?.coverage;
|
|
156
|
-
if (!record(coverage) || !Array.isArray(coverage.excluded) || !record(coverage.scope)) return false;
|
|
157
|
-
if (coverage.kind === 'whole-project') {
|
|
158
|
-
return Object.keys(coverage).sort(compare).join('\0') === ['excluded', 'kind', 'scope'].sort(compare).join('\0')
|
|
159
|
-
&& stable(coverage.excluded) === stable(['.git']);
|
|
160
|
-
}
|
|
161
|
-
const fields = ['dependencyArtifactRoots', 'excluded', 'excludedRootStates', 'guardOutcomes', 'kind', 'policySource', 'policyVersion', 'scope'];
|
|
162
|
-
if (coverage.kind !== 'project-with-dependency-artifact-exclusions'
|
|
163
|
-
|| Object.keys(coverage).sort(compare).join('\0') !== fields.sort(compare).join('\0')
|
|
164
|
-
|| coverage.policyVersion !== DEPENDENCY_POLICY_VERSION || !record(coverage.policySource)
|
|
165
|
-
|| Object.keys(coverage.policySource).sort(compare).join('\0') !== ['baselineCommit', 'path', 'storedBytesDigest'].sort(compare).join('\0')
|
|
166
|
-
|| coverage.policySource.path !== PROJECT_CONFIG_PATH || coverage.policySource.baselineCommit !== snapshot.baseline.commit
|
|
167
|
-
|| !/^[a-f0-9]{64}$/.test(coverage.policySource.storedBytesDigest || '')
|
|
168
|
-
|| !Array.isArray(coverage.dependencyArtifactRoots) || !coverage.dependencyArtifactRoots.length
|
|
169
|
-
|| coverage.dependencyArtifactRoots.some(root => !DEPENDENCY_ARTIFACT_ROOTS.has(root))
|
|
170
|
-
|| stable(coverage.dependencyArtifactRoots) !== stable([...coverage.dependencyArtifactRoots].sort())
|
|
171
|
-
|| new Set(coverage.dependencyArtifactRoots).size !== coverage.dependencyArtifactRoots.length
|
|
172
|
-
|| stable(coverage.excluded) !== stable(['.git', ...coverage.dependencyArtifactRoots])) return false;
|
|
173
|
-
const roots = coverage.dependencyArtifactRoots;
|
|
174
|
-
const baselinePolicy = snapshot.baseline.records.find(item => item.path === PROJECT_CONFIG_PATH && item.presence === 'present');
|
|
175
|
-
const candidatePolicy = snapshot.config.capture.sources.find(item => item.path === PROJECT_CONFIG_PATH && item.presence === 'present');
|
|
176
|
-
if (!baselinePolicy || !candidatePolicy || sha(bytes(baselinePolicy.storedBytes)) !== coverage.policySource.storedBytesDigest) return false;
|
|
177
|
-
const baseConfig = projectConfigFromStoredBytes(baselinePolicy.storedBytes);
|
|
178
|
-
const candidateConfig = projectConfigFromStoredBytes(candidatePolicy.bytes);
|
|
179
|
-
const baseRoots = baseConfig?.inventory?.dependencyArtifactRoots;
|
|
180
|
-
const candidateRoots = candidateConfig?.inventory?.dependencyArtifactRoots;
|
|
181
|
-
if (!Array.isArray(baseRoots) || !Array.isArray(candidateRoots)
|
|
182
|
-
|| stable([...baseRoots].sort()) !== stable([...candidateRoots].sort())
|
|
183
|
-
|| stable([...baseRoots].sort()) !== stable(roots)) return false;
|
|
184
|
-
if ([...snapshot.baseline.records, ...snapshot.candidate.records].some(item => roots.some(root => pathUnderDependencyRoot(item.path, root)))) return false;
|
|
185
|
-
if (!Array.isArray(coverage.excludedRootStates) || coverage.excludedRootStates.length !== roots.length
|
|
186
|
-
|| coverage.excludedRootStates.some((item, index) => !record(item) || item.path !== roots[index]
|
|
187
|
-
|| !['absent', 'present-directory'].includes(item.presence)
|
|
188
|
-
|| Object.keys(item).sort(compare).join('\0') !== ['path', 'presence'].sort(compare).join('\0'))) return false;
|
|
189
|
-
const guards = ['baseline-paths', 'index-paths', 'config-sources', 'config-selectors', 'task-inputs', 'excluded-root-types'];
|
|
190
|
-
return Array.isArray(coverage.guardOutcomes) && coverage.guardOutcomes.length === guards.length
|
|
191
|
-
&& coverage.guardOutcomes.every((item, index) => record(item) && item.guard === guards[index] && item.state === 'clear'
|
|
192
|
-
&& text(item.reason) && (index !== guards.length - 1 || stable(item.roots) === stable(coverage.excludedRootStates)));
|
|
193
|
-
}
|
|
194
|
-
function configDigest(config) {
|
|
195
|
-
const sources = [...config.capture.sources].sort(pathCompare);
|
|
196
|
-
const fields = ['doc-config-v1', stable({ activeHost: config.capture.activeHost, selectionInputs: config.capture.selectionInputs, resolution: config.resolution }), String(sources.length)];
|
|
197
|
-
for (const source of sources) fields.push(source.path, source.presence, bytes(source.bytes));
|
|
198
|
-
return hashFrames(fields);
|
|
199
|
-
}
|
|
200
|
-
function validateSnapshot(snapshot) {
|
|
201
|
-
const errors = [];
|
|
202
|
-
try {
|
|
203
|
-
if (!validIdentity(snapshot.identity) || !record(snapshot.facts) || !Array.isArray(snapshot.obligations)) throw new Error('invalid-input');
|
|
204
|
-
if (!validCoverage(snapshot)) errors.push(diagnostic('inventory-unsupported'));
|
|
205
|
-
// Roots are canonicalized at capture; keep reconciliation detached and free of filesystem reads.
|
|
206
|
-
const context = snapshot.originContext;
|
|
207
|
-
if (!record(context) || !record(context.baseline) || !text(context.workspaceRoot)
|
|
208
|
-
|| context.baseline.commit !== snapshot.baseline.commit || context.baseline.root !== context.workspaceRoot) {
|
|
209
|
-
errors.push(diagnostic('baseline-unavailable'));
|
|
210
|
-
}
|
|
211
|
-
// The captured origin identity, the captured plan and the selected host must be the identity the snapshot
|
|
212
|
-
// claims; otherwise the provider half and the event half of the trust contract stay disconnected.
|
|
213
|
-
if (!originBound(snapshot)) errors.push(diagnostic('identity-mismatch'));
|
|
214
|
-
if (snapshotDigest('baseline', snapshot.baseline, snapshot.candidate.coverage, snapshot.baseline.records) !== snapshot.identity.baselineDigest
|
|
215
|
-
|| snapshotDigest('candidate', snapshot.baseline, snapshot.candidate.coverage, snapshot.candidate.records) !== snapshot.identity.candidateDigest
|
|
216
|
-
|| snapshot.baseline.digest !== snapshot.identity.baselineDigest || snapshot.candidate.digest !== snapshot.identity.candidateDigest) errors.push(diagnostic('identity-mismatch'));
|
|
217
|
-
if (configDigest(snapshot.config) !== snapshot.identity.configDigest || snapshot.config.digest !== snapshot.identity.configDigest) errors.push(diagnostic('config-capture-mismatch'));
|
|
218
|
-
if (!configBytesBound(snapshot)) errors.push(diagnostic('config-capture-mismatch'));
|
|
219
|
-
if (structuredDigest('doc-task-scope-v1', snapshot.taskSemantics) !== snapshot.identity.taskScopeDigest) errors.push(diagnostic('identity-mismatch'));
|
|
220
|
-
const config = snapshot.config.resolution.config;
|
|
221
|
-
const derived = deriveDocFacts({ base: { files: deriveFiles(snapshot.baseline.records, config, { strict: true }) },
|
|
222
|
-
candidate: { files: deriveFiles(snapshot.candidate.records, config, { strict: true }) }, config });
|
|
223
|
-
if (stable(derived.facts) !== stable(snapshot.facts)
|
|
224
|
-
|| stable(deriveDocObligations(derived.facts)) !== stable(snapshot.obligations)) errors.push(diagnostic('identity-mismatch'));
|
|
225
|
-
for (const obligation of snapshot.obligations) {
|
|
226
|
-
const reason = snapshot.derivationReasons && snapshot.derivationReasons[obligation.id];
|
|
227
|
-
if (obligation.strength === 'MUST' && obligation.applicability === 'N/A'
|
|
228
|
-
&& (!reason || reason.applicability !== 'N/A' || !text(reason.reason) || !Array.isArray(reason.factRefs) || !reason.factRefs.length)) {
|
|
229
|
-
errors.push(diagnostic('na-reason-missing', { obligationId: obligation.id }));
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
} catch (error) {
|
|
233
|
-
const code = error && ['invalid-input', 'inventory-incomplete', 'inventory-unsupported'].includes(error.message)
|
|
234
|
-
? error.message : 'invalid-input';
|
|
235
|
-
errors.push(diagnostic(code));
|
|
236
|
-
}
|
|
237
|
-
return errors;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function reconcileDocResults(input = {}) {
|
|
241
|
-
const { snapshot, accepted, checkerOutput, mode = 'verification' } = record(input) ? input : {};
|
|
242
|
-
const diagnostics = [];
|
|
243
|
-
const unsatisfied = [];
|
|
244
|
-
const results = Array.isArray(checkerOutput && checkerOutput.results) ? checkerOutput.results : [];
|
|
245
|
-
const base = { decision: 'unresolved', eligible: false, expectedMustIds: [], checkedMustIds: [], results, unsatisfied, diagnostics };
|
|
246
|
-
if (!record(snapshot) || !record(accepted) || !record(checkerOutput) || !Array.isArray(checkerOutput.results)
|
|
247
|
-
|| !results.every(record) || !Array.isArray(checkerOutput.diagnostics) || !checkerOutput.diagnostics.every(record)
|
|
248
|
-
|| !['verification', 'review'].includes(mode)
|
|
249
|
-
|| !['ready', 'unresolved', 'unavailable'].includes(accepted.state)
|
|
250
|
-
|| !Array.isArray(accepted.diagnostics) || !accepted.diagnostics.every(record)
|
|
251
|
-
|| !Array.isArray(accepted.rejected) || !accepted.rejected.every(record) || !record(accepted.acceptedIndex)) {
|
|
252
|
-
diagnostics.push(diagnostic('invalid-input'));
|
|
253
|
-
return base;
|
|
254
|
-
}
|
|
255
|
-
diagnostics.push(...validateSnapshot(snapshot));
|
|
256
|
-
if (!Array.isArray(snapshot.obligations) || !snapshot.obligations.every(o => record(o) && record(o.scope) && Array.isArray(o.scope.paths))) return base;
|
|
257
|
-
const expected = snapshot.obligations.filter(o => o.strength === 'MUST' && o.applicability !== 'N/A');
|
|
258
|
-
base.expectedMustIds = expected.map(o => o.id).sort(compare);
|
|
259
|
-
const selected = mode === 'review' ? expected.filter(o => o.capability === 'quality-review') : expected;
|
|
260
|
-
base.checkedMustIds = selected.map(o => o.id).sort(compare);
|
|
261
|
-
const fail = (code, obligationId, state = 'pending') => {
|
|
262
|
-
diagnostics.push(diagnostic(code, obligationId ? { obligationId } : {}));
|
|
263
|
-
if (obligationId) unsatisfied.push({ obligationId, state, reasonCode: code });
|
|
264
|
-
};
|
|
265
|
-
if (diagnostics.length) return base;
|
|
266
|
-
const capturedArtifacts = Object.fromEntries(snapshot.candidate.records.filter(r => r.presence === 'present').map(r => [r.path, { digest: r.digest }]));
|
|
267
|
-
const capturedBaseline = { digest: snapshot.identity.baselineDigest,
|
|
268
|
-
artifacts: Object.fromEntries(snapshot.baseline.records.filter(r => r.presence === 'present').map(r => [r.path, { digest: r.digest }])) };
|
|
269
|
-
if (stable(accepted.checkerInputs?.artifacts) !== stable(capturedArtifacts)
|
|
270
|
-
|| stable(accepted.checkerInputs?.baseline) !== stable(capturedBaseline)
|
|
271
|
-
|| stable(accepted.checkerInputs?.obligations) !== stable(snapshot.obligations)) fail('artifact-mismatch');
|
|
272
|
-
if (!sameIdentity(snapshot.identity, accepted.identity) || stable(snapshot.originContext) !== stable(accepted.originContext)) fail('identity-mismatch');
|
|
273
|
-
if (snapshot.identity.configDigest !== accepted.identity?.configDigest) fail('config-capture-mismatch');
|
|
274
|
-
for (const item of [...(accepted.diagnostics || []), ...(accepted.rejected || [])]) {
|
|
275
|
-
diagnostics.push(item);
|
|
276
|
-
// Only rejected evidence for a checked expected MUST, or a global origin/identity fault, gates credit;
|
|
277
|
-
// a rejected SHOULD or N/A event stays a visible diagnostic (PR #353 review P2).
|
|
278
|
-
if (!item.obligationId || selected.some(o => o.id === item.obligationId)) {
|
|
279
|
-
unsatisfied.push({ obligationId: item.obligationId || 'origin', state: item.code === 'origin-unavailable' ? 'unavailable' : 'pending', reasonCode: item.code });
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (accepted.state === 'unavailable') fail('origin-unavailable');
|
|
283
|
-
if (checkerOutput?.unavailable) fail('checker-unavailable');
|
|
284
|
-
const known = new Set(snapshot.obligations.map(o => o.id));
|
|
285
|
-
for (const result of results) if (!known.has(result.obligationId)) fail('result-misattributed', result.obligationId);
|
|
286
|
-
for (const obligation of selected) {
|
|
287
|
-
const id = obligation.id;
|
|
288
|
-
if (obligation.applicability === 'unknown') { fail('unknown-applicability', id, 'unknown'); continue; }
|
|
289
|
-
const matches = results.filter(r => r.obligationId === id);
|
|
290
|
-
if (matches.length !== 1) { fail(matches.length ? 'result-duplicate' : 'result-missing', id); continue; }
|
|
291
|
-
const result = matches[0];
|
|
292
|
-
if (result.observation !== 'observed' || result.outcome !== 'pass') {
|
|
293
|
-
const hasAccepted = Object.values(accepted.acceptedIndex || {}).some(item => item.obligationId === id);
|
|
294
|
-
fail(hasAccepted ? 'result-not-pass' : 'result-missing', id);
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
const artifactDigest = obligation.scope.paths.length
|
|
298
|
-
? obligation.scope.paths.map(p => `${p}=${capturedArtifacts[p]?.digest || 'missing'}`).join('|')
|
|
299
|
-
: snapshot.identity.baselineDigest;
|
|
300
|
-
if (result.baseDigest !== snapshot.identity.baselineDigest || result.artifactDigest !== artifactDigest) fail('result-misattributed', id);
|
|
301
|
-
if (!Array.isArray(result.recordRefs) || !result.recordRefs.length) { fail('result-untrusted', id); continue; }
|
|
302
|
-
for (const ref of result.recordRefs) {
|
|
303
|
-
const item = accepted.acceptedIndex?.[ref];
|
|
304
|
-
if (!item || item.obligationId !== id || !sameIdentity(item.identity, snapshot.identity)
|
|
305
|
-
|| !text(item.originRef) || stable(item.paths) !== stable(obligation.scope.paths)
|
|
306
|
-
|| item.artifactBinding !== snapshot.identity.candidateDigest) fail('result-untrusted', id);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
// Validation failures must never be hidden by a cached report or a passing result subset.
|
|
310
|
-
// Global faults and diagnostics for a checked expected MUST block; SHOULD/N/A diagnostics stay visible only.
|
|
311
|
-
const blocking = diagnostics.filter(item => !item.obligationId || selected.some(o => o.id === item.obligationId));
|
|
312
|
-
// Checker diagnostics stay visible; eligibility is decided from the expected MUST set above.
|
|
313
|
-
// In particular, later verifier diagnostics cannot stall an independent review.
|
|
314
|
-
if (Array.isArray(checkerOutput.diagnostics)) diagnostics.push(...checkerOutput.diagnostics);
|
|
315
|
-
if (blocking.length || unsatisfied.length) {
|
|
316
|
-
if (blocking.some(d => ['origin-unavailable', 'checker-unavailable'].includes(d.code))) base.decision = 'unavailable';
|
|
317
|
-
return base;
|
|
318
|
-
}
|
|
319
|
-
if (!selected.length) { base.decision = 'legacy'; diagnostics.push(diagnostic('no-document-musts')); return base; }
|
|
320
|
-
base.decision = 'eligible';
|
|
321
|
-
base.eligible = true;
|
|
322
|
-
return base;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
function checkAcceptedDocEvidence(input = {}) {
|
|
326
|
-
const { snapshot, accepted, mode = 'verification' } = record(input) ? input : {};
|
|
327
|
-
let checkerOutput;
|
|
328
|
-
try {
|
|
329
|
-
if (!accepted?.checkerInputs || !snapshot) throw new Error('invalid-input');
|
|
330
|
-
checkerOutput = checkDocObligations({ ...accepted.checkerInputs, obligations: snapshot.obligations });
|
|
331
|
-
} catch { checkerOutput = { results: [], diagnostics: [], unavailable: true }; }
|
|
332
|
-
return reconcileDocResults({ snapshot, accepted, checkerOutput, mode });
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
module.exports = { checkAcceptedDocEvidence, reconcileDocResults,
|
|
336
|
-
_internals: { runtimeModule, text, record, bytes, stable, clone, sha, structuredDigest, snapshotDigest, configDigest, sameIdentity, diagnostic, validateSnapshot, compare, deriveFiles, semanticRelevance, originBound, configBytesBound } };
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const { execFileSync } = require('child_process');
|
|
5
|
-
const { _internals: U } = require('./doc-reconciliation-core');
|
|
6
|
-
const { key } = require('./workflow-isolation');
|
|
7
|
-
|
|
8
|
-
// Directory identity as in the producer: native realpath (Windows 8.3 names), case-insensitive on Windows.
|
|
9
|
-
function samePath(a, b) {
|
|
10
|
-
try {
|
|
11
|
-
fs.statSync(a);
|
|
12
|
-
fs.statSync(b);
|
|
13
|
-
return key(a) === key(b);
|
|
14
|
-
} catch { return false; }
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function artifactsFor(records) {
|
|
18
|
-
return Object.fromEntries(records.filter(item => item.presence === 'present').map(item => [item.path, { digest: item.digest }]));
|
|
19
|
-
}
|
|
20
|
-
function prdDigest(artifacts) {
|
|
21
|
-
return U.sha(JSON.stringify(Object.keys(artifacts).filter(p => p.startsWith('docs/prd/')).sort().map(p => [p, artifacts[p].digest])));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function git(root, args, binary = false) {
|
|
25
|
-
const env = { ...process.env };
|
|
26
|
-
for (const key of Object.keys(env)) if (key.startsWith('GIT_')) delete env[key];
|
|
27
|
-
return execFileSync('git', ['-C', root, ...args], { env, encoding: binary ? null : 'utf8',
|
|
28
|
-
timeout: 10000, maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function shaBytes(value) { return U.sha(Buffer.from(value)); }
|
|
32
|
-
|
|
33
|
-
function outlineEventValid({ event, snapshot, paths, artifacts, baselineArtifacts } = {}) {
|
|
34
|
-
let stage = 'envelope';
|
|
35
|
-
try {
|
|
36
|
-
const evidence = event?.outlineEvidence;
|
|
37
|
-
const root = snapshot.originContext.workspaceRoot;
|
|
38
|
-
const baseline = snapshot.originContext.baseline;
|
|
39
|
-
if (snapshot.originContext.activeHost !== 'claude-code' || !U.record(evidence)
|
|
40
|
-
|| evidence.schema !== 'harness.outline-confirmation.v1' || evidence.state !== 'validated'
|
|
41
|
-
|| evidence.baselineCommit !== baseline?.commit || evidence.taskId !== snapshot.identity.taskId
|
|
42
|
-
|| !/^[0-9a-f]{40,64}$/.test(String(evidence.outlineCommit || ''))
|
|
43
|
-
|| !/^[0-9a-f]{40,64}$/.test(String(evidence.draftCommit || ''))
|
|
44
|
-
|| !/^[0-9a-f]{40,64}$/.test(String(evidence.mergedCommit || ''))
|
|
45
|
-
|| !/^[0-9a-f]{64}$/.test(String(evidence.handoffDigest || ''))
|
|
46
|
-
|| !/^[0-9a-f]{64}$/.test(String(evidence.reviewCaptureDigest || ''))
|
|
47
|
-
|| !/^[0-9a-f]{64}$/.test(String(evidence.reviewDigest || ''))
|
|
48
|
-
|| !/^[0-9a-f]{64}$/.test(String(evidence.seamDigest || ''))
|
|
49
|
-
|| !/^[0-9a-f]{64}$/.test(String(evidence.dispatchInputDigest || ''))
|
|
50
|
-
|| !/^[0-9a-f]{64}$/.test(String(evidence.writerLeaseDigest || ''))
|
|
51
|
-
|| !/^[0-9a-f]{64}$/.test(String(evidence.inventoryPinDigest || ''))
|
|
52
|
-
|| !/^[0-9a-f]{64}$/.test(String(evidence.inventoryArtifactDigest || ''))
|
|
53
|
-
|| !Array.isArray(evidence.targetPaths) || U.stable(evidence.targetPaths) !== U.stable(paths)
|
|
54
|
-
|| !U.record(evidence.outlineArtifactDigests) || !U.record(evidence.draftArtifactDigests)
|
|
55
|
-
|| !U.record(evidence.outlineBlobOids) || !U.record(evidence.draftBlobOids)
|
|
56
|
-
|| U.stable(Object.keys(evidence.outlineArtifactDigests).sort()) !== U.stable(paths)
|
|
57
|
-
|| U.stable(Object.keys(evidence.draftArtifactDigests).sort()) !== U.stable(paths)
|
|
58
|
-
|| U.stable(Object.keys(evidence.outlineBlobOids).sort()) !== U.stable(paths)
|
|
59
|
-
|| U.stable(Object.keys(evidence.draftBlobOids).sort()) !== U.stable(paths)
|
|
60
|
-
|| !U.record(event.draftArtifactDigests) || U.stable(Object.keys(event.draftArtifactDigests).sort()) !== U.stable(paths)
|
|
61
|
-
|| U.stable(event.draftArtifactDigests) !== U.stable(evidence.draftArtifactDigests)
|
|
62
|
-
|| !U.record(event.reviewedArtifactDigests)
|
|
63
|
-
|| !paths.every(p => /^[0-9a-f]{64}$/.test(String(evidence.outlineArtifactDigests[p] || ''))
|
|
64
|
-
&& /^[0-9a-f]{64}$/.test(String(evidence.draftArtifactDigests[p] || ''))
|
|
65
|
-
&& /^[0-9a-f]{40,64}$/.test(String(evidence.outlineBlobOids[p] || ''))
|
|
66
|
-
&& /^[0-9a-f]{40,64}$/.test(String(evidence.draftBlobOids[p] || ''))
|
|
67
|
-
&& artifacts[p]?.digest === evidence.draftArtifactDigests[p])
|
|
68
|
-
|| !/^[0-9a-f]{40,64}$/.test(String(evidence.baselineCommit || ''))
|
|
69
|
-
|| !/^[0-9a-f]{40,64}$/.test(String(evidence.outlineTree || ''))
|
|
70
|
-
|| !/^[0-9a-f]{40,64}$/.test(String(evidence.draftTree || ''))
|
|
71
|
-
|| !U.text(evidence.coordinatorPrincipal) || !U.text(evidence.reviewerPrincipal) || !U.text(evidence.workerPrincipal)
|
|
72
|
-
|| evidence.reviewerPrincipal === evidence.coordinatorPrincipal || evidence.reviewerPrincipal === evidence.workerPrincipal
|
|
73
|
-
|| evidence.ancestry !== 'strict-descendant' || evidence.outlineCommit === evidence.draftCommit) return stage;
|
|
74
|
-
|
|
75
|
-
stage = 'reviewed-object-binding';
|
|
76
|
-
const pinPath = Object.keys(event.reviewedArtifactDigests).filter(p => p.startsWith('doc-reconciliation/outline-confirmation/inventory/'));
|
|
77
|
-
if (pinPath.length !== 1 || event.reviewedArtifactDigests[pinPath[0]] !== evidence.inventoryArtifactDigest
|
|
78
|
-
|| Object.keys(event.reviewedArtifactDigests).length !== paths.length + 1
|
|
79
|
-
|| !paths.every(p => event.reviewedArtifactDigests[p] === evidence.outlineArtifactDigests[p])) return stage;
|
|
80
|
-
|
|
81
|
-
stage = 'current-commit-binding';
|
|
82
|
-
const head = git(root, ['rev-parse', '--verify', 'HEAD^{commit}']).trim();
|
|
83
|
-
const tree = git(root, ['rev-parse', '--verify', 'HEAD^{tree}']).trim();
|
|
84
|
-
if (head !== evidence.mergedCommit || tree !== evidence.draftTree) return stage;
|
|
85
|
-
const verified = commit => git(root, ['rev-parse', '--verify', `${commit}^{commit}`]).trim() === commit;
|
|
86
|
-
if (![evidence.baselineCommit, evidence.outlineCommit, evidence.draftCommit, evidence.mergedCommit].every(verified)) return 'git-object-missing';
|
|
87
|
-
if (evidence.baselineCommit === evidence.outlineCommit) return 'B-to-O-ancestry';
|
|
88
|
-
stage = 'B-to-O-ancestry';
|
|
89
|
-
try { git(root, ['merge-base', '--is-ancestor', evidence.baselineCommit, evidence.outlineCommit]); }
|
|
90
|
-
catch { return stage; }
|
|
91
|
-
stage = 'O-to-D-ancestry';
|
|
92
|
-
try { git(root, ['merge-base', '--is-ancestor', evidence.outlineCommit, evidence.draftCommit]); }
|
|
93
|
-
catch { return stage; }
|
|
94
|
-
stage = 'merge-correspondence';
|
|
95
|
-
if (evidence.mergeCorrespondence === null) {
|
|
96
|
-
if (evidence.draftCommit !== evidence.mergedCommit) return stage;
|
|
97
|
-
} else {
|
|
98
|
-
const merge = evidence.mergeCorrespondence;
|
|
99
|
-
if (!U.record(merge) || !['accepted', 'changed'].includes(merge.state)
|
|
100
|
-
|| merge.draftCommit !== evidence.draftCommit || merge.mergedCommit !== evidence.mergedCommit
|
|
101
|
-
|| U.stable(merge.targetPaths) !== U.stable(paths) || !U.record(merge.targetBlobs)) return stage;
|
|
102
|
-
for (const p of paths) {
|
|
103
|
-
const draftOid = git(root, ['rev-parse', `${evidence.draftCommit}:${p}`]).trim();
|
|
104
|
-
const mergedOid = git(root, ['rev-parse', `${evidence.mergedCommit}:${p}`]).trim();
|
|
105
|
-
if (merge.targetBlobs[p]?.draft !== draftOid || merge.targetBlobs[p]?.merged !== mergedOid
|
|
106
|
-
|| (merge.state === 'accepted' && draftOid !== mergedOid)
|
|
107
|
-
|| (merge.state === 'changed' && draftOid === mergedOid)) return stage;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
stage = 'target-object-binding';
|
|
111
|
-
for (const p of paths) {
|
|
112
|
-
const atBase = git(root, ['ls-tree', '-r', '--name-only', evidence.baselineCommit, '--', p]).trim().split('\n').filter(Boolean);
|
|
113
|
-
if (atBase.includes(p)) return 'target-existed-at-B';
|
|
114
|
-
if (git(root, ['rev-parse', `${evidence.outlineCommit}:${p}`]).trim() !== evidence.outlineBlobOids[p]
|
|
115
|
-
|| git(root, ['rev-parse', `${evidence.mergedCommit}:${p}`]).trim() !== evidence.draftBlobOids[p]) return stage;
|
|
116
|
-
const outlineBytes = git(root, ['show', `${evidence.outlineCommit}:${p}`], true);
|
|
117
|
-
const draftBytes = git(root, ['show', `${evidence.mergedCommit}:${p}`], true);
|
|
118
|
-
if (shaBytes(outlineBytes) !== evidence.outlineArtifactDigests[p]
|
|
119
|
-
|| shaBytes(draftBytes) !== evidence.draftArtifactDigests[p]
|
|
120
|
-
|| shaBytes(draftBytes) !== artifacts[p]?.digest) return 'candidate-artifact-binding';
|
|
121
|
-
}
|
|
122
|
-
return true;
|
|
123
|
-
} catch { return 'git-verification-failed'; }
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function acceptDocEvents(input = {}, dependencies = {}) {
|
|
127
|
-
const { snapshot, eventRefs } = U.record(input) ? input : {};
|
|
128
|
-
const originProvider = dependencies?.originProvider;
|
|
129
|
-
const diagnostics = [];
|
|
130
|
-
const rejected = [];
|
|
131
|
-
const acceptedIndex = Object.create(null);
|
|
132
|
-
const empty = { state: 'unavailable', checkerInputs: null, acceptedIndex, rejected, diagnostics };
|
|
133
|
-
try {
|
|
134
|
-
if (!snapshot || !Array.isArray(eventRefs) || !eventRefs.every(U.text)) {
|
|
135
|
-
diagnostics.push(U.diagnostic('invalid-input'));
|
|
136
|
-
return empty;
|
|
137
|
-
}
|
|
138
|
-
diagnostics.push(...U.validateSnapshot(snapshot));
|
|
139
|
-
if (diagnostics.length) return { ...empty, state: 'unresolved' };
|
|
140
|
-
const artifacts = artifactsFor(snapshot.candidate.records);
|
|
141
|
-
const baselineArtifacts = artifactsFor(snapshot.baseline.records);
|
|
142
|
-
const checkerInputs = { obligations: U.clone(snapshot.obligations), artifacts,
|
|
143
|
-
baseline: { digest: snapshot.identity.baselineDigest, artifacts: baselineArtifacts }, executionRecords: [], reviewRecords: [] };
|
|
144
|
-
const out = { state: 'ready', identity: U.clone(snapshot.identity), originContext: U.clone(snapshot.originContext), checkerInputs, acceptedIndex, rejected, diagnostics };
|
|
145
|
-
if (!originProvider || typeof originProvider.resolveEvent !== 'function' || typeof originProvider.resolveContext !== 'function') {
|
|
146
|
-
diagnostics.push(U.diagnostic('origin-unavailable'));
|
|
147
|
-
out.state = 'unavailable';
|
|
148
|
-
return out;
|
|
149
|
-
}
|
|
150
|
-
const contextResponse = originProvider.resolveContext({ workspaceRoot: snapshot.originContext.workspaceRoot, workflowId: snapshot.identity.workflowId, sessionId: snapshot.identity.sessionId });
|
|
151
|
-
if (contextResponse?.status !== 'accepted' || !U.text(contextResponse.originRef)) {
|
|
152
|
-
diagnostics.push(U.diagnostic(contextResponse?.status === 'rejected' ? 'origin-untrusted' : 'origin-unavailable'));
|
|
153
|
-
out.state = 'unavailable';
|
|
154
|
-
return out;
|
|
155
|
-
}
|
|
156
|
-
if (contextResponse.originRef !== snapshot.originContext.originRef) diagnostics.push(U.diagnostic('identity-mismatch'));
|
|
157
|
-
const context = contextResponse.context;
|
|
158
|
-
for (const key of ['workspaceId', 'sessionId', 'workflowId', 'workflowRevision', 'taskId', 'principals', 'activeHost', 'baselineReference']) {
|
|
159
|
-
if (U.stable(context?.[key]) !== U.stable(snapshot.originContext[key])) diagnostics.push(U.diagnostic('identity-mismatch'));
|
|
160
|
-
}
|
|
161
|
-
// The concrete workflow-start pin and worktree bound at capture must still be what the provider issues;
|
|
162
|
-
// a different pin under the same baselineReference is not the captured baseline (PR #353 review P1).
|
|
163
|
-
const pin = snapshot.originContext.baseline;
|
|
164
|
-
if (!U.record(context?.baseline) || !U.record(pin) || context.baseline.commit !== pin.commit
|
|
165
|
-
|| !U.text(context.baseline.root) || !samePath(context.baseline.root, pin.root)) diagnostics.push(U.diagnostic('baseline-unavailable'));
|
|
166
|
-
if (context?.workspaceRoot !== undefined && !(U.text(context.workspaceRoot) && samePath(context.workspaceRoot, snapshot.originContext.workspaceRoot))) {
|
|
167
|
-
diagnostics.push(U.diagnostic('identity-mismatch'));
|
|
168
|
-
}
|
|
169
|
-
const seenIds = new Set();
|
|
170
|
-
const seenCapabilities = new Set();
|
|
171
|
-
for (const reference of eventRefs) {
|
|
172
|
-
let response;
|
|
173
|
-
try { response = originProvider.resolveEvent({ reference, identity: U.clone(snapshot.identity) }); }
|
|
174
|
-
catch { response = { status: 'unavailable' }; }
|
|
175
|
-
if (response?.status !== 'accepted') {
|
|
176
|
-
const supplied = Array.isArray(response?.diagnostics) ? response.diagnostics : [];
|
|
177
|
-
rejected.push(...(supplied.length ? U.clone(supplied) : [U.diagnostic(response?.status === 'rejected' ? 'origin-untrusted' : 'origin-unavailable', { reference })]));
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
const event = U.clone(response.event);
|
|
181
|
-
const obligation = snapshot.obligations.find(o => o.capability === event?.capability);
|
|
182
|
-
const obligationId = obligation?.id;
|
|
183
|
-
const problems = [];
|
|
184
|
-
const reject = code => problems.push(U.diagnostic(code, { reference, ...(obligationId ? { obligationId } : {}) }));
|
|
185
|
-
if (!U.record(event) || !['eventId', 'producerId', 'originRef', 'principalId', 'provenance', 'capability'].every(k => U.text(event[k]))
|
|
186
|
-
|| !U.text(response.originRef) || event.originRef !== response.originRef || !['execution', 'verification', 'review'].includes(event.kind)) reject('event-invalid');
|
|
187
|
-
if (!U.sameIdentity(event?.identity, snapshot.identity)) {
|
|
188
|
-
reject('identity-mismatch');
|
|
189
|
-
if (event?.identity?.configDigest !== snapshot.identity.configDigest) reject('config-capture-mismatch');
|
|
190
|
-
}
|
|
191
|
-
if (!obligation) reject('capability-mismatch');
|
|
192
|
-
if (seenIds.has(event?.eventId)) reject('event-duplicate');
|
|
193
|
-
if (seenCapabilities.has(event?.capability)) reject('event-conflict');
|
|
194
|
-
seenIds.add(event?.eventId);
|
|
195
|
-
seenCapabilities.add(event?.capability);
|
|
196
|
-
const paths = obligation?.scope?.paths || [];
|
|
197
|
-
if (!Array.isArray(event?.paths) || U.stable([...event.paths].sort()) !== U.stable([...paths].sort())) reject('scope-mismatch');
|
|
198
|
-
const outlineCapability = event?.capability === 'outline-confirmation';
|
|
199
|
-
const digests = event?.kind === 'review' ? event.reviewedArtifactDigests : event?.artifactDigests;
|
|
200
|
-
if (outlineCapability) {
|
|
201
|
-
const outlineValidation = outlineEventValid({ event, snapshot, paths, artifacts, baselineArtifacts });
|
|
202
|
-
if (outlineValidation !== true) reject(`outline-${outlineValidation || 'evidence-invalid'}`);
|
|
203
|
-
} else if (!U.record(digests)) reject('artifact-mismatch');
|
|
204
|
-
else {
|
|
205
|
-
for (const p of paths) {
|
|
206
|
-
if (artifacts[p] && digests[p] !== artifacts[p].digest) reject('artifact-mismatch');
|
|
207
|
-
if (!artifacts[p] && (!baselineArtifacts[p] || event.baselineArtifacts?.[p] !== baselineArtifacts[p].digest || Object.hasOwn(digests, p))) reject('artifact-mismatch');
|
|
208
|
-
}
|
|
209
|
-
// Supplied extra digests must also describe this capture, never another tree.
|
|
210
|
-
for (const p of Object.keys(digests)) if (!artifacts[p] || digests[p] !== artifacts[p].digest) reject('artifact-mismatch');
|
|
211
|
-
}
|
|
212
|
-
if (event?.capability === 'conflict-check') {
|
|
213
|
-
const binding = event.corpusBinding;
|
|
214
|
-
const identity = snapshot.identity;
|
|
215
|
-
const expectedPaths = U.runtimeModule('doc-lifecycle.js').documentCorpusPaths(
|
|
216
|
-
snapshot.candidate.records, snapshot.config.resolution.config
|
|
217
|
-
);
|
|
218
|
-
if (!U.record(binding) || binding.complete !== true || !Array.isArray(binding.paths)
|
|
219
|
-
|| U.stable(binding.paths) !== U.stable(expectedPaths) || !U.record(binding.digests)
|
|
220
|
-
|| U.stable(Object.keys(binding.digests).sort()) !== U.stable(expectedPaths)
|
|
221
|
-
|| !expectedPaths.every(p => artifacts[p] && binding.digests[p] === artifacts[p].digest)) reject('corpus-mismatch');
|
|
222
|
-
if (binding?.baselineDigest !== identity.baselineDigest || binding?.candidateDigest !== identity.candidateDigest
|
|
223
|
-
|| binding?.configIdentityDigest !== identity.configDigest
|
|
224
|
-
|| binding?.baseCommit !== snapshot.originContext.baseline.commit) reject('snapshot-changed');
|
|
225
|
-
const configSource = snapshot.config.capture.sources.find(source => source.path === binding?.config?.path);
|
|
226
|
-
if (!configSource || configSource.presence !== 'present'
|
|
227
|
-
|| U.sha(U.bytes(configSource.bytes)) !== binding?.config?.digest) reject('config-capture-mismatch');
|
|
228
|
-
}
|
|
229
|
-
if (event?.capability === 'derived-regenerate') {
|
|
230
|
-
const binding = event.derivedBinding;
|
|
231
|
-
const corpus = binding?.sourceCorpus;
|
|
232
|
-
const expectedPaths = U.runtimeModule('doc-lifecycle.js').documentCorpusPaths(
|
|
233
|
-
snapshot.candidate.records, snapshot.config.resolution.config
|
|
234
|
-
);
|
|
235
|
-
if (!U.record(binding) || binding.view !== paths[0] || !U.record(corpus) || corpus.complete !== true
|
|
236
|
-
|| !Array.isArray(corpus.paths) || U.stable(corpus.paths) !== U.stable(expectedPaths)
|
|
237
|
-
|| !U.record(corpus.digests) || U.stable(Object.keys(corpus.digests).sort()) !== U.stable(expectedPaths)
|
|
238
|
-
|| !expectedPaths.every(p => artifacts[p] && corpus.digests[p] === artifacts[p].digest)) reject('corpus-mismatch');
|
|
239
|
-
if (binding?.baselineDigest !== snapshot.identity.baselineDigest
|
|
240
|
-
|| binding?.candidateDigest !== snapshot.identity.candidateDigest
|
|
241
|
-
|| binding?.configIdentityDigest !== snapshot.identity.configDigest) reject('snapshot-changed');
|
|
242
|
-
const configSource = snapshot.config.capture.sources.find(source => source.path === binding?.config?.path);
|
|
243
|
-
if (!configSource || configSource.presence !== 'present'
|
|
244
|
-
|| U.sha(U.bytes(configSource.bytes)) !== binding?.config?.digest) reject('config-capture-mismatch');
|
|
245
|
-
const generated = binding?.generation?.outputDigest;
|
|
246
|
-
const target = binding?.comparison?.targetDigest;
|
|
247
|
-
if (binding?.generation?.state !== 'pass' || binding?.comparison?.state !== 'equal'
|
|
248
|
-
|| !U.text(generated) || generated !== target || !artifacts[binding.view]
|
|
249
|
-
|| artifacts[binding.view].digest !== target) reject('derived-binding-mismatch');
|
|
250
|
-
}
|
|
251
|
-
if (event?.kind === 'review') {
|
|
252
|
-
if (event.verdict !== 'approve' || !U.text(event.summary)) reject('event-invalid');
|
|
253
|
-
const principals = context?.principals;
|
|
254
|
-
const independent = principals && [principals.author, ...(principals.executors || [])];
|
|
255
|
-
if (!independent || independent.includes(event.principalId) || !Array.isArray(event.independentOf)
|
|
256
|
-
|| !independent.every(p => event.independentOf.includes(p))) reject('review-not-independent');
|
|
257
|
-
} else {
|
|
258
|
-
if (!U.text(event?.command) || !Array.isArray(event?.argv) || !event.argv.length || !event.argv.every(U.text)
|
|
259
|
-
|| !U.text(event.cwd) || !Number.isInteger(event.exitCode) || event.exitCode !== 0 || event.signal !== null
|
|
260
|
-
|| !U.text(event.toolCorrelationId) || response.correlation?.toolCorrelationId !== event.toolCorrelationId
|
|
261
|
-
|| !U.text(event.resultRef)) reject('event-invalid');
|
|
262
|
-
if (!U.sameIdentity(event?.startIdentity, snapshot.identity) || !U.sameIdentity(event?.endIdentity, snapshot.identity)) reject('snapshot-changed');
|
|
263
|
-
// Provider acceptance covers command semantics; the adapter additionally rejects command/argv substitution.
|
|
264
|
-
if (Array.isArray(event?.argv) && event.command !== event.argv.join(' ')) reject('capability-mismatch');
|
|
265
|
-
if (!context?.principals?.executors?.includes(event?.principalId)) reject('origin-untrusted');
|
|
266
|
-
}
|
|
267
|
-
if (problems.length) { rejected.push(...problems); continue; }
|
|
268
|
-
const adapted = { id: reference, obligationId,
|
|
269
|
-
kind: outlineCapability ? 'outline-confirmation' : event.kind === 'review' ? 'review' : 'execution',
|
|
270
|
-
paths: [...paths], provenance: event.provenance, baseDigest: snapshot.identity.baselineDigest,
|
|
271
|
-
artifactDigests: U.clone(outlineCapability ? event.draftArtifactDigests : digests),
|
|
272
|
-
...(event.baselineArtifacts ? { baselineArtifacts: U.clone(event.baselineArtifacts) } : {}) };
|
|
273
|
-
if (outlineCapability) Object.assign(adapted, { outlineEvidence: U.clone(event.outlineEvidence) });
|
|
274
|
-
else if (event.kind === 'review') Object.assign(adapted, { verdict: event.verdict, summary: event.summary });
|
|
275
|
-
else Object.assign(adapted, { command: event.command, exitCode: event.exitCode });
|
|
276
|
-
if (event.capability === 'conflict-check') {
|
|
277
|
-
adapted.candidatePrdSet = { digest: prdDigest(artifacts), complete: true, paths: Object.keys(artifacts).filter(p => p.startsWith('docs/prd/')).sort() };
|
|
278
|
-
}
|
|
279
|
-
(event.kind === 'review' ? checkerInputs.reviewRecords : checkerInputs.executionRecords).push(adapted);
|
|
280
|
-
acceptedIndex[reference] = { reference, eventId: event.eventId, obligationId, capability: event.capability,
|
|
281
|
-
paths: [...paths], identity: U.clone(event.identity), originRef: response.originRef, artifactBinding: snapshot.identity.candidateDigest,
|
|
282
|
-
artifactDigests: U.clone(outlineCapability ? event.draftArtifactDigests : digests),
|
|
283
|
-
...(outlineCapability ? { reviewedArtifactDigests: U.clone(event.reviewedArtifactDigests) } : {}), event };
|
|
284
|
-
}
|
|
285
|
-
if (diagnostics.length || rejected.length) out.state = 'unresolved';
|
|
286
|
-
return out;
|
|
287
|
-
} catch {
|
|
288
|
-
diagnostics.push(U.diagnostic('invalid-input'));
|
|
289
|
-
return empty;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
module.exports = { acceptDocEvents };
|