@holmes-lab/holmes-kit 0.39.0 → 0.40.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/CHANGELOG.md +578 -6
- package/README.md +120 -41
- package/dist/.build-id +1 -1
- package/dist/holmes/admission/core/admission-policy.d.ts +37 -0
- package/dist/holmes/admission/core/admission-policy.js +147 -0
- package/dist/holmes/admission/core/bounded-reader.d.ts +56 -0
- package/dist/holmes/admission/core/bounded-reader.js +135 -0
- package/dist/holmes/admission/core/change-classifier.d.ts +34 -0
- package/dist/holmes/admission/core/change-classifier.js +278 -0
- package/dist/holmes/admission/core/config-loader.d.ts +30 -0
- package/dist/holmes/admission/core/config-loader.js +145 -0
- package/dist/holmes/admission/core/event-judgement.d.ts +37 -0
- package/dist/holmes/admission/core/event-judgement.js +251 -0
- package/dist/holmes/admission/core/path-rules.d.ts +35 -0
- package/dist/holmes/admission/core/path-rules.js +88 -0
- package/dist/holmes/admission/core/pin.d.ts +7 -0
- package/dist/holmes/admission/core/pin.js +29 -0
- package/dist/holmes/admission/core/ports.d.ts +48 -0
- package/dist/holmes/admission/core/ports.js +11 -0
- package/dist/holmes/admission/core/range-resolver.d.ts +32 -0
- package/dist/holmes/admission/core/range-resolver.js +51 -0
- package/dist/holmes/admission/core/self-containment.d.ts +1 -0
- package/dist/holmes/admission/core/self-containment.js +125 -0
- package/dist/holmes/admission/core/signature-source.d.ts +9 -0
- package/dist/holmes/admission/core/signature-source.js +4 -0
- package/dist/holmes/admission/core/transition-planner.d.ts +15 -0
- package/dist/holmes/admission/core/transition-planner.js +14 -0
- package/dist/holmes/admission/core/verdict.d.ts +38 -0
- package/dist/holmes/admission/core/verdict.js +17 -0
- package/dist/holmes/admission/core/wiring.d.ts +44 -0
- package/dist/holmes/admission/core/wiring.js +618 -0
- package/dist/holmes/admission/forge/git-object-port.d.ts +4 -0
- package/dist/holmes/admission/forge/git-object-port.js +132 -0
- package/dist/holmes/assoc/assoc-arm.d.ts +1 -1
- package/dist/holmes/assoc/assoc-arm.js +1 -1
- package/dist/holmes/cli/agents.d.ts +8 -0
- package/dist/holmes/cli/agents.js +9 -5
- package/dist/holmes/cli/approve-cli.d.ts +2 -0
- package/dist/holmes/cli/approve-cli.js +392 -0
- package/dist/holmes/cli/approve-ref.d.ts +13 -7
- package/dist/holmes/cli/approve-ref.js +30 -10
- package/dist/holmes/cli/approve-status.d.ts +26 -2
- package/dist/holmes/cli/approve-status.js +98 -18
- package/dist/holmes/cli/approve-watch.d.ts +5 -0
- package/dist/holmes/cli/approve-watch.js +10 -5
- package/dist/holmes/cli/approve.d.ts +49 -13
- package/dist/holmes/cli/approve.js +249 -67
- package/dist/holmes/cli/attest.js +2 -1
- package/dist/holmes/cli/autonomy.d.ts +4 -1
- package/dist/holmes/cli/autonomy.js +17 -10
- package/dist/holmes/cli/codex-oracle.d.ts +11 -0
- package/dist/holmes/cli/codex-oracle.js +5 -1
- package/dist/holmes/cli/codex-toml.d.ts +10 -0
- package/dist/holmes/cli/codex-toml.js +36 -2
- package/dist/holmes/cli/doctor-boundary.d.ts +76 -0
- package/dist/holmes/cli/doctor-boundary.js +308 -0
- package/dist/holmes/cli/doctor-locks.d.ts +15 -0
- package/dist/holmes/cli/doctor-locks.js +119 -0
- package/dist/holmes/cli/doctor.d.ts +2 -0
- package/dist/holmes/cli/doctor.js +34 -5
- package/dist/holmes/cli/flags.d.ts +23 -0
- package/dist/holmes/cli/flags.js +89 -0
- package/dist/holmes/cli/index.d.ts +5 -1
- package/dist/holmes/cli/index.js +226 -442
- package/dist/holmes/cli/init.js +33 -0
- package/dist/holmes/cli/interactive-prompt.d.ts +39 -2
- package/dist/holmes/cli/interactive-prompt.js +98 -16
- package/dist/holmes/cli/lock-recover.d.ts +5 -0
- package/dist/holmes/cli/lock-recover.js +126 -0
- package/dist/holmes/cli/mcp-processes.js +1 -1
- package/dist/holmes/cli/release-docs.js +1 -1
- package/dist/holmes/cli/run-exec.d.ts +141 -0
- package/dist/holmes/cli/run-exec.js +1435 -0
- package/dist/holmes/cli/run-provision.d.ts +3 -1
- package/dist/holmes/cli/run-provision.js +255 -44
- package/dist/holmes/cli/run-wiring.d.ts +69 -0
- package/dist/holmes/cli/run-wiring.js +270 -0
- package/dist/holmes/cli/run.d.ts +21 -0
- package/dist/holmes/cli/run.js +341 -92
- package/dist/holmes/cli/runtime-binding-approval.js +32 -19
- package/dist/holmes/cli/screen-safe.d.ts +3 -92
- package/dist/holmes/cli/screen-safe.js +18 -756
- package/dist/holmes/config/config.d.ts +19 -0
- package/dist/holmes/config/config.js +18 -3
- package/dist/holmes/cpg/foundation/language-matrix.js +2 -2
- package/dist/holmes/cpg/import-resolver.js +1 -1
- package/dist/holmes/governance/approval-decisions.d.ts +47 -0
- package/dist/holmes/governance/approval-decisions.js +29 -0
- package/dist/holmes/governance/approval-grants.d.ts +220 -1
- package/dist/holmes/governance/approval-grants.js +612 -33
- package/dist/holmes/governance/approval-queue.d.ts +26 -0
- package/dist/holmes/governance/approval-queue.js +109 -11
- package/dist/holmes/governance/approval-spend.d.ts +95 -0
- package/dist/holmes/governance/approval-spend.js +191 -0
- package/dist/holmes/governance/autonomous-shell.d.ts +61 -0
- package/dist/holmes/governance/autonomous-shell.js +332 -0
- package/dist/holmes/governance/autonomy.d.ts +12 -0
- package/dist/holmes/governance/autonomy.js +51 -15
- package/dist/holmes/governance/constitution.d.ts +5 -0
- package/dist/holmes/governance/constitution.js +32 -12
- package/dist/holmes/governance/full-autonomy.d.ts +10 -0
- package/dist/holmes/governance/full-autonomy.js +103 -7
- package/dist/holmes/governance/harness-catalog.d.ts +103 -0
- package/dist/holmes/governance/harness-catalog.js +348 -0
- package/dist/holmes/governance/human-channel.d.ts +38 -0
- package/dist/holmes/governance/human-channel.js +49 -0
- package/dist/holmes/governance/install-manifest.d.ts +22 -0
- package/dist/holmes/governance/install-manifest.js +160 -0
- package/dist/holmes/governance/ledger-rechain.js +2 -0
- package/dist/holmes/governance/ledger-store.conformance.d.ts +7 -1
- package/dist/holmes/governance/ledger-store.conformance.js +66 -0
- package/dist/holmes/governance/ledger-store.d.ts +88 -11
- package/dist/holmes/governance/ledger-store.js +186 -8
- package/dist/holmes/governance/provenance-chain.d.ts +16 -4
- package/dist/holmes/governance/provenance-chain.js +19 -4
- package/dist/holmes/governance/provenance-ledger.d.ts +6 -3
- package/dist/holmes/governance/provenance-ledger.js +53 -18
- package/dist/holmes/governance/push-gate-runner.d.ts +2 -0
- package/dist/holmes/governance/push-gate-runner.js +50 -9
- package/dist/holmes/governance/push-gate.d.ts +13 -2
- package/dist/holmes/governance/push-gate.js +106 -14
- package/dist/holmes/governance/recorded-pairs.d.ts +96 -0
- package/dist/holmes/governance/recorded-pairs.js +522 -0
- package/dist/holmes/governance/replica-id.d.ts +1 -1
- package/dist/holmes/governance/replica-id.js +1 -1
- package/dist/holmes/governance/spec-seam.d.ts +59 -0
- package/dist/holmes/governance/spec-seam.js +587 -0
- package/dist/holmes/governance/spend-kinds.d.ts +16 -0
- package/dist/holmes/governance/spend-kinds.js +18 -0
- package/dist/holmes/guardrail/advisory-line.d.ts +102 -0
- package/dist/holmes/guardrail/advisory-line.js +718 -0
- package/dist/holmes/guardrail/decision-ledger.d.ts +2 -1
- package/dist/holmes/guardrail/decision-ledger.js +2 -1
- package/dist/holmes/guardrail/impact-gate.d.ts +7 -0
- package/dist/holmes/guardrail/impact-gate.js +33 -6
- package/dist/holmes/guardrail/line-continuation.d.ts +8 -0
- package/dist/holmes/guardrail/line-continuation.js +39 -0
- package/dist/holmes/guardrail/operator-person.d.ts +28 -4
- package/dist/holmes/guardrail/operator-person.js +57 -11
- package/dist/holmes/guardrail/refusal-codes.d.ts +8 -3
- package/dist/holmes/guardrail/refusal-codes.js +64 -10
- package/dist/holmes/guardrail/risk-classifier.d.ts +15 -9
- package/dist/holmes/guardrail/risk-classifier.js +228 -16
- package/dist/holmes/guardrail/risk-gate.d.ts +2 -8
- package/dist/holmes/guardrail/risk-gate.js +7 -34
- package/dist/holmes/guardrail/risk-types.d.ts +10 -0
- package/dist/holmes/guardrail/run-plan-scope.js +3 -1
- package/dist/holmes/guardrail/run-refusals.js +24 -8
- package/dist/holmes/guardrail/run-stages.d.ts +5 -0
- package/dist/holmes/guardrail/run-stages.js +25 -5
- package/dist/holmes/guardrail/scope-judgment.js +1 -1
- package/dist/holmes/guardrail/shell-words.js +24 -3
- package/dist/holmes/guardrail/unresolved-write.d.ts +40 -0
- package/dist/holmes/guardrail/unresolved-write.js +556 -0
- package/dist/holmes/guardrail/write-target.d.ts +3 -0
- package/dist/holmes/guardrail/write-target.js +26 -5
- package/dist/holmes/hooks/pre-tool-use.d.ts +116 -1
- package/dist/holmes/hooks/pre-tool-use.js +1176 -170
- package/dist/holmes/hooks/rtm-refresh-child.d.ts +1 -1
- package/dist/holmes/hooks/rtm-refresh-child.js +1 -1
- package/dist/holmes/hooks/session-start.js +17 -1
- package/dist/holmes/hooks/stop.d.ts +23 -0
- package/dist/holmes/hooks/stop.js +86 -33
- package/dist/holmes/mcp/approval-adapters.js +3 -1
- package/dist/holmes/mcp/approval-commit.js +3 -2
- package/dist/holmes/mcp/approval-policy.d.ts +2 -1
- package/dist/holmes/mcp/approval-policy.js +3 -1
- package/dist/holmes/mcp/handlers/adoption.d.ts +1 -1
- package/dist/holmes/mcp/handlers/approval-ask.d.ts +3 -0
- package/dist/holmes/mcp/handlers/approval-ask.js +18 -7
- package/dist/holmes/mcp/handlers/entity-integration.d.ts +3 -3
- package/dist/holmes/mcp/handlers/entity-integration.js +29 -11
- package/dist/holmes/mcp/handlers/entity-renumber.d.ts +4 -4
- package/dist/holmes/mcp/handlers/entity-renumber.js +29 -11
- package/dist/holmes/mcp/handlers/entity-store.d.ts +2 -2
- package/dist/holmes/mcp/handlers/entity-store.js +133 -59
- package/dist/holmes/mcp/handlers/maintenance-analysis.d.ts +13 -0
- package/dist/holmes/mcp/handlers/maintenance-analysis.js +59 -2
- package/dist/holmes/mcp/handlers/operator-inspection.d.ts +9 -5
- package/dist/holmes/mcp/handlers/operator-inspection.js +79 -16
- package/dist/holmes/mcp/handlers/phase-queries.d.ts +1 -1
- package/dist/holmes/mcp/handlers/requirement-triage.d.ts +4 -4
- package/dist/holmes/mcp/handlers/review-evidence.d.ts +2 -2
- package/dist/holmes/mcp/handlers/review-evidence.js +35 -11
- package/dist/holmes/mcp/handlers/review-queries.d.ts +5 -0
- package/dist/holmes/mcp/handlers/review-queries.js +8 -1
- package/dist/holmes/mcp/handlers/review-verdict.d.ts +3 -0
- package/dist/holmes/mcp/handlers/review-verdict.js +10 -3
- package/dist/holmes/mcp/handlers/risk-assessment.d.ts +7 -2
- package/dist/holmes/mcp/handlers/risk-assessment.js +34 -12
- package/dist/holmes/mcp/handlers/runtime-binding-tool.d.ts +2 -2
- package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +6 -1
- package/dist/holmes/mcp/handlers/slice-orchestration.js +14 -1
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +15 -3
- package/dist/holmes/mcp/handlers/spec-approval.js +32 -5
- package/dist/holmes/mcp/handlers/spec-authoring.d.ts +2 -2
- package/dist/holmes/mcp/handlers/spec-authoring.js +19 -2
- package/dist/holmes/mcp/handlers/spec-lifecycle.d.ts +11 -38
- package/dist/holmes/mcp/handlers/spec-lifecycle.js +441 -94
- package/dist/holmes/mcp/handlers/spec-queries.d.ts +2 -2
- package/dist/holmes/mcp/handlers/taint-screening.d.ts +1 -1
- package/dist/holmes/mcp/handlers/taint-screening.js +2 -2
- package/dist/holmes/mcp/handlers/test-execution.d.ts +471 -4
- package/dist/holmes/mcp/handlers/test-execution.js +199 -21
- package/dist/holmes/mcp/handlers/workspace-queries.d.ts +2 -2
- package/dist/holmes/mcp/handlers.d.ts +557 -82
- package/dist/holmes/mcp/handlers.js +74 -23
- package/dist/holmes/mcp/harness-attestation.d.ts +78 -5
- package/dist/holmes/mcp/harness-attestation.js +325 -53
- package/dist/holmes/mcp/maintenance-analyze.d.ts +6 -1
- package/dist/holmes/mcp/maintenance-analyze.js +13 -11
- package/dist/holmes/mcp/maintenance-evidence.d.ts +9 -0
- package/dist/holmes/mcp/maintenance-evidence.js +35 -3
- package/dist/holmes/mcp/requirement-triage-evidence.js +22 -13
- package/dist/holmes/mcp/server-staleness.js +1 -1
- package/dist/holmes/mcp/server.js +9 -8
- package/dist/holmes/mcp/spec-id-guard.js +1 -1
- package/dist/holmes/mcp/tool-schemas.d.ts +13 -0
- package/dist/holmes/mcp/tool-schemas.js +42 -9
- package/dist/holmes/project/act-root.d.ts +19 -0
- package/dist/holmes/project/act-root.js +100 -0
- package/dist/holmes/project/baseline.d.ts +15 -2
- package/dist/holmes/project/baseline.js +14 -8
- package/dist/holmes/project/bounded-group.d.ts +47 -0
- package/dist/holmes/project/bounded-group.js +140 -0
- package/dist/holmes/project/bounded-io.d.ts +51 -2
- package/dist/holmes/project/bounded-io.js +140 -6
- package/dist/holmes/project/change-source.d.ts +4 -0
- package/dist/holmes/project/change-source.js +14 -6
- package/dist/holmes/project/instance-id.d.ts +10 -0
- package/dist/holmes/project/instance-id.js +233 -0
- package/dist/holmes/project/machine-identity.d.ts +25 -0
- package/dist/holmes/project/machine-identity.js +133 -0
- package/dist/holmes/project/owned-lock.d.ts +84 -0
- package/dist/holmes/project/owned-lock.js +263 -0
- package/dist/holmes/project/plain-lock-fs.d.ts +2 -0
- package/dist/holmes/project/plain-lock-fs.js +126 -0
- package/dist/holmes/project/request-lock.d.ts +85 -0
- package/dist/holmes/project/request-lock.js +459 -0
- package/dist/holmes/project/root.d.ts +12 -4
- package/dist/holmes/project/root.js +29 -8
- package/dist/holmes/project/run-records.d.ts +19 -0
- package/dist/holmes/project/run-records.js +94 -12
- package/dist/holmes/project/screen-text.d.ts +94 -0
- package/dist/holmes/project/screen-text.js +763 -0
- package/dist/holmes/project/spend-lock.d.ts +82 -0
- package/dist/holmes/project/spend-lock.js +413 -0
- package/dist/holmes/refresh/freshness-coordinator.d.ts +1 -1
- package/dist/holmes/refresh/freshness-coordinator.js +1 -1
- package/dist/holmes/review/condition-hunk-replay.js +4 -2
- package/dist/holmes/review/confidence-calibration.d.ts +1 -1
- package/dist/holmes/review/confidence-calibration.js +1 -1
- package/dist/holmes/review/content-verify.js +1 -1
- package/dist/holmes/review/evidence-mode.d.ts +21 -0
- package/dist/holmes/review/evidence-mode.js +33 -0
- package/dist/holmes/review/head-worktree.d.ts +55 -0
- package/dist/holmes/review/head-worktree.js +329 -0
- package/dist/holmes/review/hop-ablation.d.ts +4 -4
- package/dist/holmes/review/hop-ablation.js +5 -5
- package/dist/holmes/review/mrp.js +13 -3
- package/dist/holmes/review/point-in-time-replay.js +12 -3
- package/dist/holmes/review/rank-diagnosis.d.ts +2 -2
- package/dist/holmes/review/rank-diagnosis.js +1 -1
- package/dist/holmes/review/replay-corpus.d.ts +10 -4
- package/dist/holmes/review/replay-corpus.js +25 -9
- package/dist/holmes/review/requirement-triage.js +2 -2
- package/dist/holmes/review/run-provenance.d.ts +45 -0
- package/dist/holmes/review/run-provenance.js +314 -0
- package/dist/holmes/review/semantic-arm.d.ts +3 -3
- package/dist/holmes/review/semantic-arm.js +3 -3
- package/dist/holmes/review/test-evidence.d.ts +174 -0
- package/dist/holmes/review/test-evidence.js +330 -2
- package/dist/holmes/review/test-outcomes.js +3 -1
- package/dist/holmes/review/test-reports.d.ts +94 -0
- package/dist/holmes/review/test-reports.js +382 -0
- package/dist/holmes/review/test-runner.d.ts +180 -58
- package/dist/holmes/review/test-runner.js +560 -324
- package/dist/holmes/review/test-selection-breadth.js +2 -2
- package/dist/holmes/review/test-units.d.ts +159 -0
- package/dist/holmes/review/test-units.js +814 -0
- package/dist/holmes/review/verdicts.d.ts +105 -8
- package/dist/holmes/review/verdicts.js +640 -36
- package/dist/holmes/rtm/anchor-census.d.ts +9 -0
- package/dist/holmes/rtm/anchor-census.js +151 -0
- package/dist/holmes/rtm/anchor-ids.d.ts +25 -1
- package/dist/holmes/rtm/anchor-ids.js +45 -2
- package/dist/holmes/rtm/comment-ranges.d.ts +2 -0
- package/dist/holmes/rtm/comment-ranges.js +104 -0
- package/dist/holmes/rtm/counted-tests.d.ts +1 -0
- package/dist/holmes/rtm/counted-tests.js +63 -0
- package/dist/holmes/rtm/impact-advisory.d.ts +1 -1
- package/dist/holmes/rtm/known-defects.js +1 -1
- package/dist/holmes/rtm/localize.js +1 -1
- package/dist/holmes/rtm/taint-benchmark.d.ts +1 -1
- package/dist/holmes/rtm/taint-vocabulary.d.ts +1 -1
- package/dist/holmes/rtm/test-scope.d.ts +31 -0
- package/dist/holmes/rtm/test-scope.js +166 -5
- package/dist/holmes/rtm/trace-gaps.js +1 -1
- package/dist/holmes/runtime/dispatch.d.ts +10 -0
- package/dist/holmes/runtime/dispatch.js +12 -1
- package/dist/holmes/semantic/cloud-usage.d.ts +1 -1
- package/dist/holmes/semantic/cloud-usage.js +1 -1
- package/dist/holmes/semantic/unreadable-paths.d.ts +1 -1
- package/dist/holmes/semantic/unreadable-paths.js +1 -1
- package/dist/holmes/spec/approval-blockers.js +1 -1
- package/dist/holmes/spec/entity-store.d.ts +6 -1
- package/dist/holmes/spec/entity-store.js +16 -2
- package/dist/holmes/spec/entity-transaction.d.ts +7 -2
- package/dist/holmes/spec/entity-transaction.js +87 -170
- package/dist/holmes/spec/spec-store.d.ts +12 -6
- package/dist/holmes/spec/spec-store.js +4 -2
- package/dist/holmes/spec/spec-types.js +1 -1
- package/dist/holmes/spec/succession-guard.d.ts +56 -0
- package/dist/holmes/spec/succession-guard.js +187 -0
- package/dist/holmes/spec/succession.d.ts +70 -0
- package/dist/holmes/spec/succession.js +171 -0
- package/dist/holmes/spec/transition-policy.d.ts +2 -2
- package/docs/install-guide.md +9 -3
- package/docs/language-support.md +78 -0
- package/package.json +4 -3
- package/playbooks/author-slice/PLAYBOOK.md +1 -1
- package/playbooks/promote-slice/PLAYBOOK.md +5 -1
- package/playbooks/publish/PLAYBOOK.md +47 -34
- package/dist/holmes/review/manual-baseline.d.ts +0 -209
- package/dist/holmes/review/manual-baseline.js +0 -2847
|
@@ -33,16 +33,56 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.MemoryLedgerStore = exports.FileLedgerStore = exports.LedgerConflictRefusal = void 0;
|
|
36
|
+
exports.MemoryLedgerStore = exports.FileLedgerStore = exports.LedgerConflictRefusal = exports.LATE_CHAIN_READ_MS = exports.SpendKindMismatch = exports.NONCE_REVOKED = void 0;
|
|
37
37
|
exports.writerChainFile = writerChainFile;
|
|
38
38
|
exports.ledgerConflictReason = ledgerConflictReason;
|
|
39
|
+
exports.nonceRevokedIn = nonceRevokedIn;
|
|
39
40
|
exports.nonceConsumedIn = nonceConsumedIn;
|
|
40
|
-
// @implements A-SPEC-150, A-SPEC-624
|
|
41
|
+
// @implements A-SPEC-150, A-SPEC-624, A-SPEC-245.10, A-SPEC-245.11, A-SPEC-245.12, A-SPEC-794.4, A-SPEC-794.5
|
|
41
42
|
// @implements A-SPEC-643
|
|
42
|
-
// @implements A-SPEC-642
|
|
43
|
+
// @implements A-SPEC-642, A-SPEC-245.9, A-SPEC-245.16
|
|
44
|
+
// @implements A-SPEC-792.26
|
|
43
45
|
const provenance_chain_1 = require("./provenance-chain");
|
|
44
46
|
const provenance_ledger_1 = require("./provenance-ledger");
|
|
47
|
+
const spend_kinds_1 = require("./spend-kinds");
|
|
48
|
+
const fs = __importStar(require("node:fs"));
|
|
45
49
|
const path = __importStar(require("node:path"));
|
|
50
|
+
/** The ledger kind of a revocation (A-SPEC-245.9, H-2), in the grant namespace (A-SPEC-794.4). */
|
|
51
|
+
exports.NONCE_REVOKED = (0, spend_kinds_1.revokeKind)('grant');
|
|
52
|
+
/**
|
|
53
|
+
* @implements A-SPEC-794.5 — the port binds a row's kind to the namespace it judges: a spend judged in one namespace
|
|
54
|
+
* and written under another kind would be invisible to that namespace's readers, so it is refused before anything is
|
|
55
|
+
* written.
|
|
56
|
+
*/
|
|
57
|
+
class SpendKindMismatch extends Error {
|
|
58
|
+
expected;
|
|
59
|
+
actual;
|
|
60
|
+
constructor(expected, actual) {
|
|
61
|
+
super(`a spend port row has kind ${JSON.stringify(actual)} where its namespace writes ${JSON.stringify(expected)}; nothing was written`);
|
|
62
|
+
this.expected = expected;
|
|
63
|
+
this.actual = actual;
|
|
64
|
+
this.name = 'SpendKindMismatch';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.SpendKindMismatch = SpendKindMismatch;
|
|
68
|
+
function assertKinds(rows, expected) {
|
|
69
|
+
for (const r of rows)
|
|
70
|
+
if (r.kind !== expected)
|
|
71
|
+
throw new SpendKindMismatch(expected, String(r.kind));
|
|
72
|
+
}
|
|
73
|
+
/** The least time a late chain gets to be read, even when the spend's budget is spent (reviewer A, L1). */
|
|
74
|
+
exports.LATE_CHAIN_READ_MS = 500;
|
|
75
|
+
/** The fingerprints a set of spend rows carries, and the count of their spends a ledger holds. */
|
|
76
|
+
function spendFingerprints(rows) { return [...new Set(rows.flatMap((r) => r.inputs ?? []))]; }
|
|
77
|
+
function spendsOf(events, fps, ns = 'grant') {
|
|
78
|
+
return events.filter((e) => e.kind === (0, spend_kinds_1.spendKind)(ns) && (e.inputs ?? []).some((i) => fps.includes(i))).length;
|
|
79
|
+
}
|
|
80
|
+
function conflictRow(fps, answer, why) {
|
|
81
|
+
const summary = answer === 'conflict'
|
|
82
|
+
? 'a spend of the same approval appeared on a chain begun after the last look'
|
|
83
|
+
: 'a chain begun after the last look could not be read, so the spend is not confirmed single';
|
|
84
|
+
return { ts: new Date().toISOString(), actor: 'holmes-kit', kind: 'spend-conflict-detected', summary, inputs: fps, rationale: why };
|
|
85
|
+
}
|
|
46
86
|
/**
|
|
47
87
|
* @implements A-SPEC-643
|
|
48
88
|
* The chain file THIS process writes: `provenance.<replica>.jsonl`, resolved exactly as every other
|
|
@@ -76,7 +116,10 @@ function ledgerConflictReason(dir) {
|
|
|
76
116
|
return null;
|
|
77
117
|
const d = pending[0];
|
|
78
118
|
const replicas = [...new Set(d.events.map((e) => e.replicaId ?? 'legacy'))].join(', ');
|
|
79
|
-
return
|
|
119
|
+
return (d.kind === 'revoked-and-consumed'
|
|
120
|
+
// @implements A-SPEC-245.9 (N10)
|
|
121
|
+
? `the merged ledger holds an unreconciled revocation that was also spent: single-use approval ${d.nonce} was revoked and consumed on replicas ${replicas}`
|
|
122
|
+
: `the merged ledger holds an unreconciled cross-replica double-spend: single-use approval ${d.nonce} was consumed on replicas ${replicas}`)
|
|
80
123
|
+ ` — approvals, applies and recoveries are refused until an operator reconciles it (ledger_reconcile { nonce: "${d.nonce}" })`
|
|
81
124
|
+ (pending.length > 1 ? `; ${pending.length - 1} more pending` : '');
|
|
82
125
|
}
|
|
@@ -126,10 +169,124 @@ class FileLedgerStore {
|
|
|
126
169
|
append(body) {
|
|
127
170
|
return this.inner.append(body);
|
|
128
171
|
}
|
|
129
|
-
isNonceConsumed(nonce) { return this.inner.isNonceConsumed(nonce); }
|
|
172
|
+
isNonceConsumed(nonce, ns = 'grant') { return this.inner.isNonceConsumed(nonce, ns); }
|
|
130
173
|
doubleSpends() { return this.inner.doubleSpends(); }
|
|
174
|
+
/**
|
|
175
|
+
* @implements A-SPEC-245.10, A-SPEC-245.11, A-SPEC-245.12 — the spend port on files: append the spend rows to this
|
|
176
|
+
* writer's chain while holding every replica chain's append lock, taken in sorted path order within the deadline.
|
|
177
|
+
* The chains are enumerated with their lock directories (M-a): a chain whose first append is in progress has a lock
|
|
178
|
+
* and no file yet, and is waited for. This writer's own chain is included even when absent. If a chain appears
|
|
179
|
+
* while the locks are taken, they are released and taken again. The spent check runs inside all the locks. After
|
|
180
|
+
* the append, still holding them, chains begun since are waited for (at least LATE_CHAIN_READ_MS) and read (W2).
|
|
181
|
+
* Throws the lock layer's error when the deadline passes before the append.
|
|
182
|
+
*/
|
|
183
|
+
appendIfUnspent(spends, deadline, ns = 'grant') {
|
|
184
|
+
const rows = spends.map((s) => s.row);
|
|
185
|
+
assertKinds(rows, (0, spend_kinds_1.spendKind)(ns));
|
|
186
|
+
const fps = spendFingerprints(rows);
|
|
187
|
+
// the merged ledger as it is inside the locks; the raw nonce is asked, so a row written before fingerprints counts
|
|
188
|
+
// A-SPEC-245.16 (item 1): and no nonce revoked on any chain — a revocation between an act's claim and its spend
|
|
189
|
+
// refuses the spend here, under the same locks, whatever the caller judged before
|
|
190
|
+
const check = () => {
|
|
191
|
+
const merged = new FileLedgerStore(this.dir, this.givenId);
|
|
192
|
+
if (spends.some((s) => merged.isNonceConsumed(s.nonce, ns)))
|
|
193
|
+
return 'spent';
|
|
194
|
+
const events = merged.loadAll();
|
|
195
|
+
return spends.some((s) => nonceRevokedIn(events, s.nonce, ns)) ? 'revoked' : 'ok';
|
|
196
|
+
};
|
|
197
|
+
return this.underEveryChainLock(deadline, ({ chain, files, enumerate, holding }) => {
|
|
198
|
+
const judged = check();
|
|
199
|
+
if (judged !== 'ok')
|
|
200
|
+
return judged;
|
|
201
|
+
for (const row of rows)
|
|
202
|
+
chain.appendInsideLock(row);
|
|
203
|
+
// W2: a chain an older writer began after the last enumeration was not excluded. Wait for each such chain's
|
|
204
|
+
// lock, then count the spends of these fingerprints: more than this append's own is a double spend.
|
|
205
|
+
const late = enumerate().filter((f) => !files.includes(f));
|
|
206
|
+
if (late.length === 0)
|
|
207
|
+
return 'appended';
|
|
208
|
+
let verdict;
|
|
209
|
+
let why;
|
|
210
|
+
try {
|
|
211
|
+
const found = holding(late, () => spendsOf(new FileLedgerStore(this.dir, this.givenId).loadAll(), fps, ns), Math.max(deadline, Date.now() + exports.LATE_CHAIN_READ_MS));
|
|
212
|
+
verdict = found > rows.length ? 'conflict' : 'appended';
|
|
213
|
+
why = `${found} spend row(s) of these fingerprints across the merged ledger, ${rows.length} of them this append's; chains begun after the enumeration: ${late.map((f) => path.basename(f)).join(', ')}`;
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
verdict = 'unconfirmed';
|
|
217
|
+
why = `chains begun after the enumeration could not be read within the budget (${e.message})`;
|
|
218
|
+
}
|
|
219
|
+
if (verdict !== 'appended')
|
|
220
|
+
chain.appendInsideLock(conflictRow(fps, verdict, why));
|
|
221
|
+
return verdict;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* @implements A-SPEC-245.9 (1b-3, M-10) — revocation on files: under every replica chain's append lock, a nonce
|
|
226
|
+
* spent on any chain answers `spent`, one already revoked answers `revoked-already`, and otherwise the revocation row
|
|
227
|
+
* is appended (`revoked`). A spend that appears later on a chain begun after the enumeration is N10's report.
|
|
228
|
+
*/
|
|
229
|
+
appendRevocationIfUnspent(nonce, row, deadline, ns = 'grant') {
|
|
230
|
+
assertKinds([row], (0, spend_kinds_1.revokeKind)(ns));
|
|
231
|
+
return this.underEveryChainLock(deadline, ({ chain }) => {
|
|
232
|
+
const merged = new FileLedgerStore(this.dir, this.givenId);
|
|
233
|
+
if (merged.isNonceConsumed(nonce, ns))
|
|
234
|
+
return 'spent';
|
|
235
|
+
if (nonceRevokedIn(merged.loadAll(), nonce, ns))
|
|
236
|
+
return 'revoked-already';
|
|
237
|
+
chain.appendInsideLock(row);
|
|
238
|
+
return 'revoked';
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Run `body` holding every replica chain's append lock, taken in sorted path order within `deadline` (A-SPEC-245.10,
|
|
243
|
+
* 245.11): the chains are enumerated with their lock directories, this writer's own chain is included even when
|
|
244
|
+
* absent, and a chain that appears while the locks are taken starts the round again. Throws the lock layer's error
|
|
245
|
+
* when the deadline passes first.
|
|
246
|
+
*/
|
|
247
|
+
underEveryChainLock(deadline, body) {
|
|
248
|
+
const lockLayer = require('./ledger-lock');
|
|
249
|
+
const { ProvenanceChain } = require('./provenance-chain');
|
|
250
|
+
const own = this.inner.currentFile();
|
|
251
|
+
const enumerate = () => {
|
|
252
|
+
let names = [];
|
|
253
|
+
try {
|
|
254
|
+
names = fs.readdirSync(this.dir);
|
|
255
|
+
}
|
|
256
|
+
catch { /* no ledger yet */ }
|
|
257
|
+
const files = names.filter((n) => (0, provenance_ledger_1.isLedgerFilename)(n)).map((n) => path.join(this.dir, n));
|
|
258
|
+
const locked = names.filter((n) => /^provenance(\.[^.]+)?\.jsonl\.lock$/.test(n)).map((n) => path.join(this.dir, n.slice(0, -'.lock'.length)));
|
|
259
|
+
return [...new Set([...files, ...locked, own])].sort();
|
|
260
|
+
};
|
|
261
|
+
/** Run `then` holding each of `files`' locks in order, until `until`. */
|
|
262
|
+
const holding = (files, then, until = deadline) => {
|
|
263
|
+
const hold = (i) => (i === files.length ? then()
|
|
264
|
+
: lockLayer.withLedgerLock(files[i], () => hold(i + 1), { acquireMs: Math.max(1, until - Date.now()) }));
|
|
265
|
+
return hold(0);
|
|
266
|
+
};
|
|
267
|
+
for (;;) {
|
|
268
|
+
const files = enumerate();
|
|
269
|
+
const RETRY = Symbol('retry');
|
|
270
|
+
const r = holding(files, () => {
|
|
271
|
+
// a chain that appeared while the locks were taken is not held: start over with it
|
|
272
|
+
if (enumerate().some((f) => !files.includes(f)))
|
|
273
|
+
return RETRY;
|
|
274
|
+
return body({ chain: new ProvenanceChain(own), files, enumerate, holding });
|
|
275
|
+
});
|
|
276
|
+
if (r !== RETRY)
|
|
277
|
+
return r;
|
|
278
|
+
if (Date.now() >= deadline)
|
|
279
|
+
throw new lockLayer.LedgerLockError('could not hold every replica chain lock within the budget: chains kept appearing');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
131
282
|
}
|
|
132
283
|
exports.FileLedgerStore = FileLedgerStore;
|
|
284
|
+
/** @implements A-SPEC-245.9 (1b-3) — whether a ledger holds a revocation of `nonce` (its fingerprint, or the raw value). */
|
|
285
|
+
function nonceRevokedIn(events, nonce, ns = 'grant') {
|
|
286
|
+
const { nonceFingerprint } = require('./provenance-chain');
|
|
287
|
+
const fp = nonceFingerprint(nonce);
|
|
288
|
+
return events.some((e) => e.kind === (0, spend_kinds_1.revokeKind)(ns) && ((e.inputs ?? []).includes(fp) || (e.inputs ?? []).includes(nonce)));
|
|
289
|
+
}
|
|
133
290
|
/**
|
|
134
291
|
* In-memory adapter — the instrument that makes the contract testable.
|
|
135
292
|
*
|
|
@@ -167,22 +324,43 @@ class MemoryLedgerStore {
|
|
|
167
324
|
}
|
|
168
325
|
append(body) {
|
|
169
326
|
const chain = this.byReplica.get(this.id) ?? [];
|
|
170
|
-
const evt = (0, provenance_chain_1.chainNext)(chain, body, process.env.HOLMES_LEDGER_KEY || undefined);
|
|
327
|
+
const evt = (0, provenance_chain_1.chainNext)(chain, (0, provenance_chain_1.writtenBody)(body), process.env.HOLMES_LEDGER_KEY || undefined); // A-SPEC-792.26 — the same seam
|
|
171
328
|
// Push onto a copy-then-set so an earlier event object is never mutated in place — append-only
|
|
172
329
|
// has to hold for the objects a caller already read, not just for the array.
|
|
173
330
|
this.byReplica.set(this.id, [...chain, evt]);
|
|
174
331
|
return evt;
|
|
175
332
|
}
|
|
176
|
-
isNonceConsumed(nonce) {
|
|
333
|
+
isNonceConsumed(nonce, ns = 'grant') {
|
|
177
334
|
// @implements A-SPEC-191 §13 — the fingerprint form is what writers record now (§11c). An
|
|
178
335
|
// adapter that only knew the raw value would report 'not consumed' for every real consumption,
|
|
179
336
|
// and the conformance suite would still pass because it wrote raw values itself.
|
|
180
337
|
const { nonceFingerprint } = require('./provenance-chain');
|
|
181
338
|
const fp = nonceFingerprint(nonce);
|
|
182
|
-
return this.loadAll().some((e) => e.kind ===
|
|
339
|
+
return this.loadAll().some((e) => e.kind === (0, spend_kinds_1.spendKind)(ns)
|
|
183
340
|
&& ((e.inputs ?? []).includes(nonce) || (e.inputs ?? []).includes(fp)));
|
|
184
341
|
}
|
|
185
342
|
doubleSpends() { return (0, provenance_ledger_1.unreconciledDoubleSpends)(this.loadAll()); }
|
|
343
|
+
/** One process, no other writer to exclude: check, then append (A-SPEC-245.12, the spend port's in-memory form). */
|
|
344
|
+
appendIfUnspent(spends, _deadline, ns = 'grant') {
|
|
345
|
+
assertKinds(spends.map((s) => s.row), (0, spend_kinds_1.spendKind)(ns));
|
|
346
|
+
if (spends.some((s) => this.isNonceConsumed(s.nonce, ns)))
|
|
347
|
+
return 'spent';
|
|
348
|
+
if (spends.some((s) => nonceRevokedIn(this.loadAll(), s.nonce, ns)))
|
|
349
|
+
return 'revoked'; // A-SPEC-245.16
|
|
350
|
+
for (const s of spends)
|
|
351
|
+
this.append(s.row);
|
|
352
|
+
return 'appended';
|
|
353
|
+
}
|
|
354
|
+
/** @implements A-SPEC-245.9 (1b-3, M-10) — the revocation port's in-memory form: check, then append. */
|
|
355
|
+
appendRevocationIfUnspent(nonce, row, _deadline, ns = 'grant') {
|
|
356
|
+
assertKinds([row], (0, spend_kinds_1.revokeKind)(ns));
|
|
357
|
+
if (this.isNonceConsumed(nonce, ns))
|
|
358
|
+
return 'spent';
|
|
359
|
+
if (nonceRevokedIn(this.loadAll(), nonce, ns))
|
|
360
|
+
return 'revoked-already';
|
|
361
|
+
this.append(row);
|
|
362
|
+
return 'revoked';
|
|
363
|
+
}
|
|
186
364
|
}
|
|
187
365
|
exports.MemoryLedgerStore = MemoryLedgerStore;
|
|
188
366
|
// @implements A-SPEC-574.3
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ExecutionContext } from '../project/execution-context';
|
|
2
2
|
import { LockOptions } from './ledger-lock';
|
|
3
|
+
import { LedgerActor } from './human-channel';
|
|
3
4
|
/**
|
|
4
5
|
* N3 — Decision PROVENANCE chain (target-architecture §7-N N3): "누가·언제·왜"의 완전 인과 재구성.
|
|
5
6
|
*
|
|
@@ -32,6 +33,17 @@ export interface ProvenanceEvent {
|
|
|
32
33
|
hash: string;
|
|
33
34
|
}
|
|
34
35
|
type ProvenanceBody = Omit<ProvenanceEvent, 'prevHash' | 'hash'>;
|
|
36
|
+
/** @implements A-SPEC-792.26 — what a writer hands the chain: its actor may be a minted person-channel actor. */
|
|
37
|
+
export type AppendBody = Omit<ProvenanceBody, 'seq' | 'actor'> & {
|
|
38
|
+
actor: LedgerActor;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* @implements A-SPEC-792.26 — the write seam: the actor and its authorization reference are judged here, so no row
|
|
42
|
+
* claims a person channel unless the mint made its actor (an environment approval saying elicitation:claude is
|
|
43
|
+
* written as unattested:elicitation:claude). Re-chaining (ledger-rechain) re-writes recorded events verbatim and does
|
|
44
|
+
* not come through here.
|
|
45
|
+
*/
|
|
46
|
+
export declare function writtenBody(body: AppendBody): Omit<ProvenanceBody, 'seq'>;
|
|
35
47
|
export declare const GENESIS = "GENESIS";
|
|
36
48
|
/** Ordered-key serialization so identical bodies always produce identical bytes (hash stability). */
|
|
37
49
|
export declare function canonicalize(b: ProvenanceBody): string;
|
|
@@ -63,7 +75,7 @@ export declare function verifyChain(chain: ProvenanceEvent[], key?: string): {
|
|
|
63
75
|
* #1 — the raw token in an audit file meant any local reader could harvest live gate-unlock
|
|
64
76
|
* credentials).
|
|
65
77
|
*/
|
|
66
|
-
export declare function authorizationRef(actor:
|
|
78
|
+
export declare function authorizationRef(actor: LedgerActor, token: string): string;
|
|
67
79
|
/**
|
|
68
80
|
* Redact a tool's target before it enters the audit trail.
|
|
69
81
|
*
|
|
@@ -137,13 +149,13 @@ export declare class ProvenanceChain {
|
|
|
137
149
|
* The read-and-write span runs under exclusion. Measured without it: two processes read the same
|
|
138
150
|
* tail, both wrote events claiming the same `seq`, and `verify()` then reported `ok:false` —
|
|
139
151
|
* tampering that never happened, 17 times out of 20. */
|
|
140
|
-
append(body:
|
|
152
|
+
append(body: AppendBody): ProvenanceEvent;
|
|
141
153
|
/**
|
|
142
154
|
* Append assuming exclusion is ALREADY held. Only for callers running inside `withLedgerLock` on
|
|
143
155
|
* this same file — `consumeNonceExclusively` needs the read and the write in one hold, and calling
|
|
144
156
|
* `append()` from there would deadlock against its own budget.
|
|
145
157
|
*/
|
|
146
|
-
appendInsideLock(body:
|
|
158
|
+
appendInsideLock(body: AppendBody): ProvenanceEvent;
|
|
147
159
|
/** The append itself, assuming exclusion is already held. Only callers INSIDE a hold may use it. */
|
|
148
160
|
private appendUnlocked;
|
|
149
161
|
/**
|
|
@@ -179,7 +191,7 @@ export declare const PROVENANCE_FILE: string;
|
|
|
179
191
|
* decision, not this function's: an authorization gate must deny, while a record-keeping append must
|
|
180
192
|
* not flip a decision that was already made.
|
|
181
193
|
*/
|
|
182
|
-
export declare function consumeNonceExclusively(nonce: string, ledgerFile: string, body:
|
|
194
|
+
export declare function consumeNonceExclusively(nonce: string, ledgerFile: string, body: AppendBody, opts: LockOptions & {
|
|
183
195
|
/**
|
|
184
196
|
* @implements A-SPEC-574.3
|
|
185
197
|
* Whether this nonce was already consumed, ACROSS every replica chain (A-SPEC-148's rule).
|
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.PROVENANCE_FILE = exports.ProvenanceChain = exports.GENESIS = void 0;
|
|
37
|
+
exports.writtenBody = writtenBody;
|
|
37
38
|
exports.canonicalize = canonicalize;
|
|
38
39
|
exports.computeHash = computeHash;
|
|
39
40
|
exports.chainNext = chainNext;
|
|
@@ -50,13 +51,24 @@ exports.keyedSelfConsistent = keyedSelfConsistent;
|
|
|
50
51
|
exports.bodyCanon = bodyCanon;
|
|
51
52
|
exports.parseLedgerLines = parseLedgerLines;
|
|
52
53
|
exports.consumeNonceExclusively = consumeNonceExclusively;
|
|
53
|
-
// @implements A-SPEC-125.2, A-SPEC-624, A-SPEC-734
|
|
54
|
+
// @implements A-SPEC-125.2, A-SPEC-624, A-SPEC-734, A-SPEC-794.46
|
|
54
55
|
const execution_context_1 = require("../project/execution-context");
|
|
55
56
|
const crypto = __importStar(require("node:crypto"));
|
|
56
57
|
const fs = __importStar(require("node:fs"));
|
|
57
58
|
const path = __importStar(require("node:path"));
|
|
58
59
|
const ledger_lock_1 = require("./ledger-lock");
|
|
59
60
|
const bounded_io_1 = require("../project/bounded-io");
|
|
61
|
+
const human_channel_1 = require("./human-channel");
|
|
62
|
+
/**
|
|
63
|
+
* @implements A-SPEC-792.26 — the write seam: the actor and its authorization reference are judged here, so no row
|
|
64
|
+
* claims a person channel unless the mint made its actor (an environment approval saying elicitation:claude is
|
|
65
|
+
* written as unattested:elicitation:claude). Re-chaining (ledger-rechain) re-writes recorded events verbatim and does
|
|
66
|
+
* not come through here.
|
|
67
|
+
*/
|
|
68
|
+
function writtenBody(body) {
|
|
69
|
+
const authorization = (0, human_channel_1.ledgerAuthorization)(body.authorization, body.actor);
|
|
70
|
+
return { ...body, actor: (0, human_channel_1.ledgerActor)(body.actor), ...(authorization !== undefined ? { authorization } : {}) };
|
|
71
|
+
}
|
|
60
72
|
exports.GENESIS = 'GENESIS';
|
|
61
73
|
/** Ordered-key serialization so identical bodies always produce identical bytes (hash stability). */
|
|
62
74
|
function canonicalize(b) {
|
|
@@ -149,7 +161,7 @@ function verifyChain(chain, key) {
|
|
|
149
161
|
* credentials).
|
|
150
162
|
*/
|
|
151
163
|
function authorizationRef(actor, token) {
|
|
152
|
-
return `${actor}:${crypto.createHash('sha256').update(token).digest('hex').slice(0, 12)}`;
|
|
164
|
+
return `${(0, human_channel_1.ledgerActor)(actor)}:${crypto.createHash('sha256').update(token).digest('hex').slice(0, 12)}`;
|
|
153
165
|
}
|
|
154
166
|
/**
|
|
155
167
|
* Redact a tool's target before it enters the audit trail.
|
|
@@ -383,7 +395,7 @@ class ProvenanceChain {
|
|
|
383
395
|
/** The append itself, assuming exclusion is already held. Only callers INSIDE a hold may use it. */
|
|
384
396
|
appendUnlocked(body) {
|
|
385
397
|
const chain = this.load();
|
|
386
|
-
const evt = chainNext(chain, body, process.env.HOLMES_LEDGER_KEY || undefined);
|
|
398
|
+
const evt = chainNext(chain, writtenBody(body), process.env.HOLMES_LEDGER_KEY || undefined);
|
|
387
399
|
fs.mkdirSync(path.dirname(this.file), { recursive: true });
|
|
388
400
|
fs.appendFileSync(this.file, JSON.stringify(evt) + '\n', 'utf8');
|
|
389
401
|
return evt;
|
|
@@ -435,7 +447,10 @@ function consumeNonceExclusively(nonce, ledgerFile, body, opts) {
|
|
|
435
447
|
// @implements A-SPEC-148
|
|
436
448
|
// The spent-check spans EVERY replica chain, not just the file being written. Judging from one
|
|
437
449
|
// chain alone would let a single-use approval be spent once per replica, resurrecting REQ-141's
|
|
438
|
-
// double-spend along a new axis. NAMED LIMIT:
|
|
450
|
+
// double-spend along a new axis. NAMED LIMIT: this lock is one chain's, and since the replica split
|
|
451
|
+
// two writers with different replica ids hold different locks, so even on one machine both can pass
|
|
452
|
+
// (A-SPEC-245.8 corrects the earlier "within one machine the lock makes this exact"; the workspace
|
|
453
|
+
// spend lock of approval-spend.ts covers the callers moved there, A-SPEC-245.9). And
|
|
439
454
|
// across machines there is no shared filesystem to lock, so two machines racing the same nonce
|
|
440
455
|
// can both pass and the duplicate is DETECTED afterwards in the merged ledger rather than
|
|
441
456
|
// prevented. Preventing it needs a shared authority, which is out of this slice's scope.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProvenanceChain, ProvenanceEvent } from './provenance-chain';
|
|
2
|
+
import { type SpendNamespace } from './spend-kinds';
|
|
2
3
|
/**
|
|
3
4
|
* The ledger as a SET of per-replica chains, read together and written one at a time.
|
|
4
5
|
*
|
|
@@ -34,6 +35,8 @@ export interface DoubleSpend {
|
|
|
34
35
|
hash: string;
|
|
35
36
|
ts: string;
|
|
36
37
|
}[];
|
|
38
|
+
/** @implements A-SPEC-245.9 (N10) — a nonce one clone revoked and another consumed; absent for a double spend. */
|
|
39
|
+
kind?: 'revoked-and-consumed';
|
|
37
40
|
}
|
|
38
41
|
/** A-SPEC-642 — the event kind an operator's reconciliation appends. */
|
|
39
42
|
export declare const DOUBLE_SPEND_RECONCILED = "nonce-double-spend-reconciled";
|
|
@@ -46,7 +49,7 @@ export declare const DOUBLE_SPEND_RECONCILED = "nonce-double-spend-reconciled";
|
|
|
46
49
|
* nonce input AND `event:<hash>` for every member — a later consumption of the same nonce is a new
|
|
47
50
|
* event the old reconciliation never saw, so the group is open again.
|
|
48
51
|
*/
|
|
49
|
-
export declare function unreconciledDoubleSpends(events: LedgerEvent[]): DoubleSpend[];
|
|
52
|
+
export declare function unreconciledDoubleSpends(events: LedgerEvent[], ns?: SpendNamespace): DoubleSpend[];
|
|
50
53
|
export interface LedgerVerifyResult {
|
|
51
54
|
ok: boolean;
|
|
52
55
|
/** Per-chain failures, naming the replica so a report is actionable rather than merely alarming. */
|
|
@@ -55,7 +58,7 @@ export interface LedgerVerifyResult {
|
|
|
55
58
|
file: string;
|
|
56
59
|
detail?: string;
|
|
57
60
|
brokenAt?: number;
|
|
58
|
-
kind?: 'chain' | 'double-spend';
|
|
61
|
+
kind?: 'chain' | 'double-spend' | 'revoked-and-consumed';
|
|
59
62
|
nonce?: string;
|
|
60
63
|
events?: DoubleSpend['events'];
|
|
61
64
|
}[];
|
|
@@ -133,5 +136,5 @@ export declare class ProvenanceLedger {
|
|
|
133
136
|
* per replica, which would resurrect REQ-141's double-spend along a new axis. The question is only
|
|
134
137
|
* meaningful across the whole set.
|
|
135
138
|
*/
|
|
136
|
-
isNonceConsumed(nonce: string): boolean;
|
|
139
|
+
isNonceConsumed(nonce: string, ns?: SpendNamespace): boolean;
|
|
137
140
|
}
|
|
@@ -37,13 +37,15 @@ exports.ProvenanceLedger = exports.DOUBLE_SPEND_RECONCILED = void 0;
|
|
|
37
37
|
exports.unreconciledDoubleSpends = unreconciledDoubleSpends;
|
|
38
38
|
exports.isLedgerFilename = isLedgerFilename;
|
|
39
39
|
// @implements A-SPEC-206, A-SPEC-624
|
|
40
|
-
// @implements A-SPEC-642
|
|
40
|
+
// @implements A-SPEC-642, A-SPEC-245.9, A-SPEC-245.16
|
|
41
41
|
const execution_context_1 = require("../project/execution-context");
|
|
42
42
|
// @implements A-SPEC-148
|
|
43
43
|
const fs = __importStar(require("node:fs"));
|
|
44
44
|
const path = __importStar(require("node:path"));
|
|
45
45
|
const provenance_chain_1 = require("./provenance-chain");
|
|
46
46
|
const replica_id_1 = require("./replica-id");
|
|
47
|
+
// @implements A-SPEC-794.4 — the spend and revoke kinds come from the one namespace table
|
|
48
|
+
const spend_kinds_1 = require("./spend-kinds");
|
|
47
49
|
/** A-SPEC-642 — the event kind an operator's reconciliation appends. */
|
|
48
50
|
exports.DOUBLE_SPEND_RECONCILED = 'nonce-double-spend-reconciled';
|
|
49
51
|
/**
|
|
@@ -55,28 +57,57 @@ exports.DOUBLE_SPEND_RECONCILED = 'nonce-double-spend-reconciled';
|
|
|
55
57
|
* nonce input AND `event:<hash>` for every member — a later consumption of the same nonce is a new
|
|
56
58
|
* event the old reconciliation never saw, so the group is open again.
|
|
57
59
|
*/
|
|
58
|
-
function unreconciledDoubleSpends(events) {
|
|
60
|
+
function unreconciledDoubleSpends(events, ns = 'grant') {
|
|
61
|
+
// @implements A-SPEC-245.9 (N4) — grouped by the canonical fingerprint: every input but an event: reference is
|
|
62
|
+
// normalised, so a row written before fingerprints (the raw nonce) and a fingerprint row of the same nonce are one
|
|
63
|
+
// group; a reconciliation's inputs are normalised the same way, so one that named the raw nonce still closes it
|
|
59
64
|
const groups = new Map();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
const revocations = new Map();
|
|
66
|
+
// the name a group is reported by: the input its rows wrote when they all wrote one, else the fingerprint — so a
|
|
67
|
+
// group that was reported (and reconciled) by its raw input before N4 keeps that name
|
|
68
|
+
const written = new Map();
|
|
69
|
+
const add = (into, e) => {
|
|
70
|
+
for (const raw of new Set(e.inputs ?? [])) {
|
|
71
|
+
const input = canonicalInput(raw);
|
|
72
|
+
const list = into.get(input) ?? [];
|
|
73
|
+
if (list.some((x) => x.hash === e.hash && x.replicaId === e.replicaId))
|
|
74
|
+
continue; // one row, two spellings
|
|
65
75
|
list.push({ replicaId: e.replicaId, seq: e.seq, hash: e.hash, ts: e.ts });
|
|
66
|
-
|
|
76
|
+
into.set(input, list);
|
|
77
|
+
written.set(input, (written.get(input) ?? new Set()).add(raw));
|
|
67
78
|
}
|
|
79
|
+
};
|
|
80
|
+
const nameOf = (key) => { const w = written.get(key); return w && w.size === 1 ? [...w][0] : key; };
|
|
81
|
+
for (const e of events) {
|
|
82
|
+
if (e.kind === (0, spend_kinds_1.spendKind)(ns))
|
|
83
|
+
add(groups, e);
|
|
84
|
+
else if (e.kind === (0, spend_kinds_1.revokeKind)(ns))
|
|
85
|
+
add(revocations, e);
|
|
68
86
|
}
|
|
69
|
-
const reconciliations = events.filter((e) => e.kind === exports.DOUBLE_SPEND_RECONCILED).map((e) => new Set(e.inputs ?? []));
|
|
87
|
+
const reconciliations = events.filter((e) => e.kind === exports.DOUBLE_SPEND_RECONCILED).map((e) => new Set((e.inputs ?? []).map(canonicalInput)));
|
|
88
|
+
const covered = (nonce, list) => reconciliations.some((inputs) => inputs.has(nonce) && list.every((ev) => inputs.has('event:' + ev.hash)));
|
|
70
89
|
const out = [];
|
|
71
90
|
for (const [nonce, list] of groups) {
|
|
72
|
-
if (list.length
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
if (list.length >= 2 && !covered(nonce, list))
|
|
92
|
+
out.push({ nonce: nameOf(nonce), events: list });
|
|
93
|
+
// @implements A-SPEC-245.9 (N10) — revoked on one clone and consumed on another: refused like a double spend,
|
|
94
|
+
// cleared by the reconcile row naming the nonce and every revoking and consuming event
|
|
95
|
+
// @implements A-SPEC-245.16 (item 2) — whatever the spend count: a double spend's reconcile, which names only the
|
|
96
|
+
// spends, does not close the revocation that was overrun
|
|
97
|
+
const revoked = revocations.get(nonce);
|
|
98
|
+
if (revoked) {
|
|
99
|
+
const all = [...revoked, ...list];
|
|
100
|
+
if (!covered(nonce, all))
|
|
101
|
+
out.push({ nonce: nameOf(nonce), events: all, kind: 'revoked-and-consumed' });
|
|
102
|
+
}
|
|
77
103
|
}
|
|
78
104
|
return out.sort((a, b) => (a.nonce < b.nonce ? -1 : a.nonce > b.nonce ? 1 : 0));
|
|
79
105
|
}
|
|
106
|
+
const FINGERPRINT_INPUT = /^nonce:[0-9a-f]{12}$/;
|
|
107
|
+
/** @implements A-SPEC-245.9 (N4) — an input as grouping reads it: a fingerprint, or an event: reference as it is. */
|
|
108
|
+
function canonicalInput(input) {
|
|
109
|
+
return input.startsWith('event:') || FINGERPRINT_INPUT.test(input) ? input : (0, provenance_chain_1.nonceFingerprint)(input);
|
|
110
|
+
}
|
|
80
111
|
const LEGACY = 'provenance.jsonl';
|
|
81
112
|
const REPLICA_FILE = /^provenance\.([^.]+)\.jsonl$/;
|
|
82
113
|
/**
|
|
@@ -248,8 +279,12 @@ class ProvenanceLedger {
|
|
|
248
279
|
// end "at seq undefined" with no act that could ever clear it.
|
|
249
280
|
for (const d of unreconciledDoubleSpends(this.loadAll())) {
|
|
250
281
|
const replicas = [...new Set(d.events.map((e) => e.replicaId ?? 'legacy'))].join(', ');
|
|
251
|
-
broken.push(
|
|
252
|
-
|
|
282
|
+
broken.push(d.kind === 'revoked-and-consumed'
|
|
283
|
+
// @implements A-SPEC-245.9 (N10)
|
|
284
|
+
? { replicaId: null, file: '(cross-replica)', kind: 'revoked-and-consumed', nonce: d.nonce, events: d.events,
|
|
285
|
+
detail: `single-use nonce ${d.nonce} was revoked and also consumed across replicas (${replicas}) — the act it allowed ran after its revocation; reconcile with ledger_reconcile` }
|
|
286
|
+
: { replicaId: null, file: '(cross-replica)', kind: 'double-spend', nonce: d.nonce, events: d.events,
|
|
287
|
+
detail: `single-use nonce ${d.nonce} spent ${d.events.length} times across replicas (${replicas}) — REQ-141 double-spend; reconcile with ledger_reconcile` });
|
|
253
288
|
}
|
|
254
289
|
return { ok: broken.length === 0, broken };
|
|
255
290
|
}
|
|
@@ -276,11 +311,11 @@ class ProvenanceLedger {
|
|
|
276
311
|
* per replica, which would resurrect REQ-141's double-spend along a new axis. The question is only
|
|
277
312
|
* meaningful across the whole set.
|
|
278
313
|
*/
|
|
279
|
-
isNonceConsumed(nonce) {
|
|
314
|
+
isNonceConsumed(nonce, ns = 'grant') {
|
|
280
315
|
// @implements A-SPEC-191 §11 — fingerprint OR raw value: records written before nonces stopped
|
|
281
316
|
// travelling in the clear must keep denying their replays.
|
|
282
317
|
const fp = (0, provenance_chain_1.nonceFingerprint)(nonce);
|
|
283
|
-
return this.loadAll().some((e) => e.kind ===
|
|
318
|
+
return this.loadAll().some((e) => e.kind === (0, spend_kinds_1.spendKind)(ns)
|
|
284
319
|
&& ((e.inputs ?? []).includes(nonce) || (e.inputs ?? []).includes(fp)));
|
|
285
320
|
}
|
|
286
321
|
}
|
|
@@ -19,5 +19,7 @@ export interface PrePushIo {
|
|
|
19
19
|
* gate stays fail-open on collection errors, H-SPEC-509).
|
|
20
20
|
*/
|
|
21
21
|
export declare function runPushReviewRefusal(cwd: string, env: NodeJS.ProcessEnv, sha: string): string | null;
|
|
22
|
+
/** @implements A-SPEC-128.8 — the ledger of pushes allowed without evidence (D3); appended, never read by the gate. */
|
|
23
|
+
export declare const NO_EVIDENCE_PUSHES_FILE: string;
|
|
22
24
|
/** Exit code of the hook: 0 = push proceeds, 1 = refused. */
|
|
23
25
|
export declare function runPrePush(io: PrePushIo): 0 | 1;
|
|
@@ -33,10 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.NO_EVIDENCE_PUSHES_FILE = void 0;
|
|
36
37
|
exports.effectiveHooksDir = effectiveHooksDir;
|
|
37
38
|
exports.runPushReviewRefusal = runPushReviewRefusal;
|
|
38
39
|
exports.runPrePush = runPrePush;
|
|
39
|
-
// @implements A-SPEC-509.1, A-SPEC-734, A-SPEC-102.4, A-SPEC-774.21
|
|
40
|
+
// @implements A-SPEC-509.1, A-SPEC-734, A-SPEC-102.4, A-SPEC-774.21, A-SPEC-102.12, A-SPEC-128.3, A-SPEC-128.4, A-SPEC-128.5, A-SPEC-128.7, A-SPEC-128.8, A-SPEC-128.9
|
|
40
41
|
/**
|
|
41
42
|
* The push gate's IMPURE half: collect (stdin lines, git facts, the evidence ledger) and hand
|
|
42
43
|
* everything to the pure judgePush. Any collection failure ALLOWS — this gate safens the default
|
|
@@ -86,26 +87,47 @@ function runPushReviewRefusal(cwd, env, sha) {
|
|
|
86
87
|
if (!mode.id)
|
|
87
88
|
return cannot('the run has no id');
|
|
88
89
|
const { listRuns, mainCheckoutOf } = require('../project/run-records');
|
|
90
|
+
// A-SPEC-102.32 — non-strict: a forged pointer finds no run record and an unreadable one throws; both refuse, named
|
|
89
91
|
const rec = listRuns(mainCheckoutOf(cwd)).find((r) => r.run_id === mode.id);
|
|
90
92
|
if (!rec)
|
|
91
93
|
return cannot(`no run record for ${mode.id}`);
|
|
92
|
-
|
|
94
|
+
// @implements A-SPEC-102.12 — from the task's review base when the run declared one.
|
|
95
|
+
const { reviewBaseOf } = require('../guardrail/run-stages');
|
|
96
|
+
const base = reviewBaseOf(rec);
|
|
97
|
+
if (base === null)
|
|
93
98
|
return cannot('run record carries no base');
|
|
94
|
-
if (
|
|
99
|
+
if (base === sha)
|
|
95
100
|
return null;
|
|
96
101
|
const { gateRange } = require('../review/verdicts');
|
|
97
|
-
const g = gateRange(rec.worktree,
|
|
102
|
+
const g = gateRange(rec.worktree, base, sha, {});
|
|
98
103
|
if (g.ok)
|
|
99
104
|
return null;
|
|
100
|
-
return `[Holmes-Kit push gate] the run's commits ${
|
|
101
|
-
+ `holmes-kit review record --base ${
|
|
105
|
+
return `[Holmes-Kit push gate] the run's commits ${base}..${sha} are not reviewed (${g.reasons.join('; ')}) — an independent reviewer records a verdict with `
|
|
106
|
+
+ `holmes-kit review record --base ${base} --head ${sha} --verdict pass`
|
|
102
107
|
// @implements A-SPEC-102.9 — a person in the session answers the same verdict in the form.
|
|
103
|
-
+ ` (a person in the session: review_verdict with base ${
|
|
108
|
+
+ ` (a person in the session: review_verdict with base ${base}, head ${sha})`;
|
|
104
109
|
}
|
|
105
110
|
catch (e) {
|
|
106
111
|
return cannot(e instanceof Error ? e.message : String(e));
|
|
107
112
|
}
|
|
108
113
|
}
|
|
114
|
+
/** @implements A-SPEC-128.8 — the ledger of pushes allowed without evidence (D3); appended, never read by the gate. */
|
|
115
|
+
exports.NO_EVIDENCE_PUSHES_FILE = path.join('.ax', 'ledger', 'no-evidence-pushes.jsonl');
|
|
116
|
+
/**
|
|
117
|
+
* @implements A-SPEC-128.9 — E2: the line is `{ts, head, reason: 'no-tests'}`. False when it could not be written, so the
|
|
118
|
+
* hook can say so; the record is observation and never changes the verdict.
|
|
119
|
+
*/
|
|
120
|
+
function recordNoEvidencePush(cwd, head) {
|
|
121
|
+
try {
|
|
122
|
+
const file = path.join(cwd, exports.NO_EVIDENCE_PUSHES_FILE);
|
|
123
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
124
|
+
fs.appendFileSync(file, JSON.stringify({ ts: new Date().toISOString(), head, reason: 'no-tests' }) + '\n', 'utf8');
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
109
131
|
/** Exit code of the hook: 0 = push proceeds, 1 = refused. */
|
|
110
132
|
function runPrePush(io) {
|
|
111
133
|
try {
|
|
@@ -115,7 +137,13 @@ function runPrePush(io) {
|
|
|
115
137
|
const hasGovernance = fs.existsSync(path.join(io.cwd, '.ax'));
|
|
116
138
|
if (!hasGovernance)
|
|
117
139
|
return 0; // un-adopted: silent
|
|
118
|
-
|
|
140
|
+
// @implements A-SPEC-128.5 — an existing test-evidence file that is not a record is 'unreadable', never absent
|
|
141
|
+
const full = (0, test_evidence_1.testEvidenceState)(io.cwd);
|
|
142
|
+
const evidence = full.state === 'unreadable' ? 'unreadable' : full.evidence ?? null;
|
|
143
|
+
// @implements A-SPEC-128.3 — read only when there is no full ledger; the judgement stays in judgePush
|
|
144
|
+
// @implements A-SPEC-128.4 — an existing file that is not a record is passed as 'unreadable', never as absent
|
|
145
|
+
const scoped = evidence ? null : (0, test_evidence_1.scopedEvidenceState)(io.cwd);
|
|
146
|
+
const scopedEvidence = !scoped || scoped.state === 'absent' ? null : scoped.state === 'unreadable' ? 'unreadable' : scoped.evidence ?? null;
|
|
119
147
|
let refused = false;
|
|
120
148
|
for (const line of lines) {
|
|
121
149
|
let claimCommits = [];
|
|
@@ -130,9 +158,22 @@ function runPrePush(io) {
|
|
|
130
158
|
});
|
|
131
159
|
}
|
|
132
160
|
catch { /* claim surfacing is optional — judgment inputs stay deterministic */ }
|
|
133
|
-
|
|
161
|
+
// @implements A-SPEC-128.7 — an exception INSIDE the judgement is not a collection failure: the gate could not judge
|
|
162
|
+
// the records it read, so it refuses, naming the exception (a malformed record threw here and the hook exited 0)
|
|
163
|
+
let v;
|
|
164
|
+
try {
|
|
165
|
+
v = (0, push_gate_1.judgePush)({ pushedHead: line.localSha, evidence, hasGovernance, claimCommits, scopedEvidence });
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
v = { allow: false, notices: [], reason: `[Holmes-Kit push 게이트] 원장 기록을 판정하지 못했습니다(${e instanceof Error ? e.message : String(e)}) — 기록을 새로 쓰십시오. 복구: 현재 HEAD에서 ${push_gate_1.FULL_RUN_CALL}를 실행한 뒤 다시 push하십시오. 의도적 우회는 git push --no-verify.` };
|
|
169
|
+
}
|
|
134
170
|
for (const n of v.notices)
|
|
135
171
|
io.write(n + '\n');
|
|
172
|
+
// @implements A-SPEC-128.8 — D3: a push allowed without evidence is a line in the ledger, not only a notice
|
|
173
|
+
// @implements A-SPEC-128.9 — a ledger line that could not be written is said, not swallowed
|
|
174
|
+
if (v.allow && v.noEvidencePush && !recordNoEvidencePush(io.cwd, line.localSha)) {
|
|
175
|
+
io.write(`[Holmes-Kit] 증빙 없는 push를 원장(${exports.NO_EVIDENCE_PUSHES_FILE})에 기록하지 못했습니다\n`);
|
|
176
|
+
}
|
|
136
177
|
if (!v.allow) {
|
|
137
178
|
io.write((v.reason ?? '[Holmes-Kit push 게이트] 거부') + '\n');
|
|
138
179
|
refused = true;
|