@holmes-lab/holmes-kit 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +370 -6
- package/README.md +58 -40
- 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 +50 -13
- package/dist/holmes/cli/approve.js +260 -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 +45 -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 +206 -424
- package/dist/holmes/cli/init.js +33 -0
- 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.d.ts +32 -0
- package/dist/holmes/cli/mcp-processes.js +132 -0
- 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 +8 -0
- package/dist/holmes/cli/run-provision.js +325 -0
- 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 +26 -0
- package/dist/holmes/cli/run.js +364 -83
- 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 +2 -0
- package/dist/holmes/config/config.js +5 -2
- 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 +31 -0
- package/dist/holmes/governance/approval-queue.js +122 -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 +5 -0
- package/dist/holmes/governance/autonomy.js +16 -11
- 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.js +11 -7
- 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/governance/tool-actions.js +2 -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 +1 -0
- package/dist/holmes/guardrail/impact-gate.js +1 -1
- 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 +70 -10
- package/dist/holmes/guardrail/risk-classifier.d.ts +15 -9
- package/dist/holmes/guardrail/risk-classifier.js +245 -15
- 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.d.ts +6 -1
- package/dist/holmes/guardrail/run-refusals.js +36 -14
- package/dist/holmes/guardrail/run-stages.d.ts +10 -0
- package/dist/holmes/guardrail/run-stages.js +46 -6
- 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 +105 -1
- package/dist/holmes/hooks/pre-tool-use.js +1167 -168
- 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.d.ts +5 -0
- package/dist/holmes/hooks/session-start.js +29 -1
- package/dist/holmes/hooks/stop.d.ts +23 -0
- package/dist/holmes/hooks/stop.js +88 -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 +14 -0
- package/dist/holmes/mcp/handlers/approval-ask.js +31 -6
- 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/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 +1 -1
- package/dist/holmes/mcp/handlers/workspace-preflight.d.ts +5 -0
- package/dist/holmes/mcp/handlers/workspace-preflight.js +10 -2
- package/dist/holmes/mcp/handlers/workspace-queries.d.ts +2 -2
- package/dist/holmes/mcp/handlers.d.ts +99 -79
- package/dist/holmes/mcp/handlers.js +93 -25
- 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 +1 -1
- package/dist/holmes/mcp/maintenance-analyze.js +9 -9
- package/dist/holmes/mcp/maintenance-evidence.js +31 -2
- package/dist/holmes/mcp/requirement-triage-evidence.js +22 -13
- package/dist/holmes/mcp/server-staleness.d.ts +43 -0
- package/dist/holmes/mcp/server-staleness.js +158 -0
- package/dist/holmes/mcp/server.js +34 -9
- 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 -2
- package/dist/holmes/project/act-root.d.ts +19 -0
- package/dist/holmes/project/act-root.js +100 -0
- package/dist/holmes/project/baseline.js +4 -3
- 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 +50 -2
- package/dist/holmes/project/bounded-io.js +138 -6
- package/dist/holmes/project/change-source.js +2 -2
- 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 +26 -7
- 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/project/workspace-preflight.d.ts +5 -0
- package/dist/holmes/project/workspace-preflight.js +24 -1
- 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/hop-ablation.d.ts +4 -4
- package/dist/holmes/review/hop-ablation.js +5 -5
- 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/semantic-arm.d.ts +3 -3
- package/dist/holmes/review/semantic-arm.js +3 -3
- package/dist/holmes/review/test-outcomes.js +3 -1
- package/dist/holmes/review/test-runner.d.ts +11 -0
- package/dist/holmes/review/test-runner.js +31 -10
- package/dist/holmes/review/test-selection-breadth.js +2 -2
- package/dist/holmes/review/verdicts.d.ts +109 -7
- package/dist/holmes/review/verdicts.js +653 -34
- 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 +45 -33
- package/dist/holmes/review/manual-baseline.d.ts +0 -209
- package/dist/holmes/review/manual-baseline.js +0 -2847
|
@@ -35,8 +35,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.createSpecLifecycleHandlers = createSpecLifecycleHandlers;
|
|
37
37
|
// @implements A-SPEC-770.12, A-SPEC-628, A-SPEC-627.1, A-SPEC-621, A-SPEC-100.2, A-SPEC-128, A-SPEC-151, A-SPEC-222, A-SPEC-538.1, A-SPEC-255, A-SPEC-133, A-SPEC-188, A-SPEC-189, A-SPEC-244, A-SPEC-245
|
|
38
|
-
// @implements A-SPEC-638
|
|
38
|
+
// @implements A-SPEC-638, A-SPEC-222.3, A-SPEC-222.5, A-SPEC-245.9, A-SPEC-245.15
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const os = __importStar(require("node:os"));
|
|
39
41
|
const path = __importStar(require("node:path"));
|
|
42
|
+
const full_autonomy_1 = require("../../governance/full-autonomy");
|
|
43
|
+
const autonomy_1 = require("../../governance/autonomy");
|
|
44
|
+
const succession_1 = require("../../spec/succession"); // @implements A-SPEC-222.6, A-SPEC-222.7, A-SPEC-222.8, A-SPEC-222.9
|
|
45
|
+
const recorded_pairs_1 = require("../../governance/recorded-pairs");
|
|
46
|
+
const counted_tests_1 = require("../../rtm/counted-tests");
|
|
47
|
+
const anchor_census_1 = require("../../rtm/anchor-census"); // @implements A-SPEC-222.7
|
|
40
48
|
const spec_store_1 = require("../../spec/spec-store");
|
|
41
49
|
const transition_policy_1 = require("../../spec/transition-policy");
|
|
42
50
|
const entity_store_1 = require("../../spec/entity-store");
|
|
@@ -49,6 +57,117 @@ const approval_grants_1 = require("../../governance/approval-grants");
|
|
|
49
57
|
const renumber_1 = require("../../spec/renumber");
|
|
50
58
|
const id_collision_1 = require("../../spec/id-collision");
|
|
51
59
|
const remote_spec_refs_1 = require("../../spec/remote-spec-refs");
|
|
60
|
+
/**
|
|
61
|
+
* @implements A-SPEC-222.5 — the machine conditions that stand in for a person when a sealed spec is retired in favour
|
|
62
|
+
* of a sealed successor (AU1-a). Every spec of the chain is judged; the first failed condition is the answer.
|
|
63
|
+
*/
|
|
64
|
+
function autonomousRetireVerdict(chain, all, projectRoot, { recorded, approved }) {
|
|
65
|
+
const ids = new Set(chain.map((c) => c.id));
|
|
66
|
+
if (ids.size !== chain.length)
|
|
67
|
+
return { ok: false, reason: 'the chain names a spec twice' };
|
|
68
|
+
const mapped = new Map(chain.map((c) => [c.id, c.supersededBy]));
|
|
69
|
+
const find = (id) => all.find((s) => s.id === id);
|
|
70
|
+
// @implements A-SPEC-222.9 — SD1 4/5: one judge over the trusted record, one test counter
|
|
71
|
+
const judge = new succession_1.SuccessionJudge({ specs: all, recorded, approved, counted: (0, counted_tests_1.countedTests)(projectRoot) }); // A-SPEC-222.10 H-B
|
|
72
|
+
const plan = [];
|
|
73
|
+
for (const c of chain) {
|
|
74
|
+
const x = find(c.id);
|
|
75
|
+
// @implements A-SPEC-222.7 — L1: X's seal is recomputed, not taken from the digest string's presence
|
|
76
|
+
if (!x || !(0, succession_1.sealHolds)(x))
|
|
77
|
+
return { ok: false, reason: `${c.id} is not a sealed spec` };
|
|
78
|
+
if (c.supersededBy === c.id)
|
|
79
|
+
return { ok: false, reason: `${c.id} cannot succeed itself` };
|
|
80
|
+
if (mapped.has(c.supersededBy))
|
|
81
|
+
return { ok: false, reason: `${c.supersededBy} is itself retired in the same act` };
|
|
82
|
+
const y = find(c.supersededBy);
|
|
83
|
+
if (x.type === 'A-SPEC') {
|
|
84
|
+
// 1, 5 and lineage: one judgment with the gate's anchor move and the after-the-fact record (A-SPEC-222.6)
|
|
85
|
+
const why = judge.aspec(x, c.supersededBy);
|
|
86
|
+
if (why !== null)
|
|
87
|
+
return { ok: false, reason: why };
|
|
88
|
+
// 2. anchored nowhere the code gate governs (A-SPEC-222.7 H3); what cannot be read goes to a person
|
|
89
|
+
const census = (0, anchor_census_1.anchorCensus)(projectRoot, x.id);
|
|
90
|
+
if (census.at.length > 0)
|
|
91
|
+
return { ok: false, reason: `${x.id} is still anchored at ${census.at.slice(0, 5).join(', ')}` };
|
|
92
|
+
if (census.unreadable.length > 0 || census.truncated) {
|
|
93
|
+
return { ok: false, reason: `the anchor census could not read ${census.truncated ? 'the whole tree' : census.unreadable.slice(0, 5).join(', ')}, so ${x.id} is not proven unanchored` };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (x.type === 'T-SPEC') {
|
|
97
|
+
// 1, 2 and 5: Y sealed, and every A-SPEC X covered is covered by Y with counted tests (A-SPEC-222.7 H1, H2b)
|
|
98
|
+
const why = judge.tspec(x, c.supersededBy, mapped);
|
|
99
|
+
if (why !== null)
|
|
100
|
+
return { ok: false, reason: why };
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return { ok: false, reason: `${x.type} is not retired autonomously` };
|
|
104
|
+
}
|
|
105
|
+
// 3. no approved dependent outside the chain
|
|
106
|
+
const held = all.filter((s) => s.status === 'approved' && s.dependsOn.includes(x.id) && !ids.has(s.id)).map((s) => s.id);
|
|
107
|
+
if (held.length > 0)
|
|
108
|
+
return { ok: false, reason: `approved ${held.join(', ')} depend on ${x.id}` };
|
|
109
|
+
// @implements A-SPEC-222.7 — M2: nor the standing successor of a retired spec (its record would name a retired
|
|
110
|
+
// spec); with the lock this is what refuses the second of two chained calls
|
|
111
|
+
const standing = all.filter((s) => s.status === 'outdated' && String(s.frontmatter.superseded_by ?? '').trim() === x.id).map((s) => s.id);
|
|
112
|
+
if (standing.length > 0)
|
|
113
|
+
return { ok: false, reason: `${x.id} is the recorded successor of retired ${standing.join(', ')}` };
|
|
114
|
+
// 4. not human-held; a T-SPEC takes the highest grade of the A-SPECs it covers (A-SPEC-222.7 M3)
|
|
115
|
+
for (const g of [x, ...(x.type === 'T-SPEC' ? x.dependsOn.map(find).filter((s) => !!s && s.type === 'A-SPEC') : [])]) {
|
|
116
|
+
const grade = (0, autonomy_1.specApprovalAutonomyReason)(g, (id) => find(id) ?? null);
|
|
117
|
+
if (grade !== null)
|
|
118
|
+
return { ok: false, reason: `${g.id} is graded for a person (${grade})` };
|
|
119
|
+
}
|
|
120
|
+
plan.push({ x, y: y });
|
|
121
|
+
}
|
|
122
|
+
return { ok: true, plan };
|
|
123
|
+
}
|
|
124
|
+
/** @implements A-SPEC-222.7 — M2: one retirement judges and writes at a time, in this process and across processes. */
|
|
125
|
+
let retireQueue = Promise.resolve();
|
|
126
|
+
async function underRetireLock(projectRoot, act) {
|
|
127
|
+
const run = retireQueue.then(async () => {
|
|
128
|
+
const lock = path.join(projectRoot, '.ax', 'state', 'spec-retire.lock');
|
|
129
|
+
fs.mkdirSync(path.dirname(lock), { recursive: true });
|
|
130
|
+
// @implements A-SPEC-222.8 — N4: judged with lstat; a directory or a link at the lock path is refused at once and
|
|
131
|
+
// never reclaimed, a stale regular file is reclaimed, and every wait is bounded (no path spins)
|
|
132
|
+
const until = Date.now() + 5_000;
|
|
133
|
+
for (;;) {
|
|
134
|
+
try {
|
|
135
|
+
fs.closeSync(fs.openSync(lock, 'wx'));
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
catch { /* held, or not a file: judged below */ }
|
|
139
|
+
let st = null;
|
|
140
|
+
try {
|
|
141
|
+
st = fs.lstatSync(lock);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
st = null;
|
|
145
|
+
}
|
|
146
|
+
if (st !== null && !st.isFile())
|
|
147
|
+
return { ok: false, reason: `the retirement lock path ${lock} is a ${st.isDirectory() ? 'directory' : 'link'}, not a lock file — remove it by hand; it is not reclaimed` };
|
|
148
|
+
if (st !== null && Date.now() - st.mtimeMs > 30_000) {
|
|
149
|
+
try {
|
|
150
|
+
fs.rmSync(lock, { force: true });
|
|
151
|
+
}
|
|
152
|
+
catch { /* judged on the next round */ }
|
|
153
|
+
}
|
|
154
|
+
if (Date.now() > until)
|
|
155
|
+
return { ok: false, reason: 'another spec_retire holds the retirement lock — retry after it ends' };
|
|
156
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
return await act();
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
try {
|
|
163
|
+
fs.rmSync(lock, { force: true });
|
|
164
|
+
}
|
|
165
|
+
catch { /* best effort */ }
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
retireQueue = run.catch(() => undefined);
|
|
169
|
+
return run;
|
|
170
|
+
}
|
|
52
171
|
function createSpecLifecycleHandlers(context) {
|
|
53
172
|
const { store, resolveLedgerRoot } = context;
|
|
54
173
|
const renumberRun = (specsRoot, a, journaled) => {
|
|
@@ -236,7 +355,108 @@ function createSpecLifecycleHandlers(context) {
|
|
|
236
355
|
// Idempotent, and it writes NOTHING on the second call: overwriting the first retirement's
|
|
237
356
|
// reason would make the record graffiti rather than history.
|
|
238
357
|
if (spec.status === 'outdated') {
|
|
239
|
-
|
|
358
|
+
const y = typeof a.supersededBy === 'string' ? a.supersededBy.trim() : '';
|
|
359
|
+
if (!y)
|
|
360
|
+
return { ok: true, retired: false, id: a.id, dependents: [], reason: `${a.id}은(는) 이미 outdated 입니다` };
|
|
361
|
+
// @implements A-SPEC-222.4 — superseded_by recorded after the fact (the 774.77 case retired with none), so the
|
|
362
|
+
// anchor move the code gate allows has a successor to move to. Nothing else about the retired spec changes.
|
|
363
|
+
// @implements A-SPEC-222.6 — F3: the record names who may stand in for X, so it takes what 222.5's retirement takes:
|
|
364
|
+
// a full profile, a directive, and a sealed successor of X's kind, lineage and coverage. A recorded successor that
|
|
365
|
+
// no longer qualifies (unsealed, say) may be replaced; a qualifying one may not.
|
|
366
|
+
const directive = typeof a.directive === 'string' ? a.directive.trim() : '';
|
|
367
|
+
const sr = store.specsRoot;
|
|
368
|
+
let scope = null;
|
|
369
|
+
if (typeof sr === 'string') {
|
|
370
|
+
try {
|
|
371
|
+
const s = (0, full_autonomy_1.readFullProfile)(context.fullAutonomyHome?.() ?? os.homedir(), path.resolve(sr, '..', '..'));
|
|
372
|
+
scope = s.active ? s.entry.scope : null;
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
scope = null;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (scope === null || !directive || typeof sr !== 'string') {
|
|
379
|
+
return { ok: false, reason: `${a.id}의 후속 사후 기록은 full 자율 프로필과 감독 지시(directive)가 있어야 합니다 — 아무것도 쓰지 않았습니다.` };
|
|
380
|
+
}
|
|
381
|
+
// @implements A-SPEC-222.8 — L-a: the same directive check as the retirement
|
|
382
|
+
if (directive.length > 500 || /[\u0000-\u001f\u007f]/.test(directive))
|
|
383
|
+
return { ok: false, reason: 'the directive is longer than 500 characters or holds a control character — nothing was written' };
|
|
384
|
+
const projectRoot = path.resolve(sr, '..', '..');
|
|
385
|
+
const dest = resolveLedgerRoot(a.root);
|
|
386
|
+
if (!dest.ok)
|
|
387
|
+
return { ok: false, reason: dest.reason };
|
|
388
|
+
// @implements A-SPEC-222.8 — L-d: under the retirement lock, judged on a fresh read
|
|
389
|
+
const done = await underRetireLock(projectRoot, async () => {
|
|
390
|
+
const now = await store.read(a.id);
|
|
391
|
+
if (!now)
|
|
392
|
+
return { ok: false, reason: `spec ${a.id} not found` };
|
|
393
|
+
const fresh = (await store.list()).map((s) => (s.id === a.id ? now.spec : s));
|
|
394
|
+
const x = now.spec;
|
|
395
|
+
const fm = x.frontmatter;
|
|
396
|
+
const had = String(fm.superseded_by ?? '').trim();
|
|
397
|
+
const book = new ledger_store_1.FileLedgerStore(path.join(dest.root, '.ax', 'ledger'));
|
|
398
|
+
// @implements A-SPEC-222.9 — H1: the record is the trusted events', read through the one port
|
|
399
|
+
const { recorded, approved } = (0, recorded_pairs_1.recordedPairsPort)(dest.root);
|
|
400
|
+
// N2: a record counts only as the ledger has it; the same Y unrecorded is recorded now, which is no overwrite
|
|
401
|
+
if (had === y && recorded(a.id, y))
|
|
402
|
+
return { ok: true, noop: true };
|
|
403
|
+
// @implements A-SPEC-222.9 — SD1 4: the A and T judgments read the record the same way (L11)
|
|
404
|
+
const succession = new succession_1.SuccessionJudge({ specs: fresh, recorded, approved, counted: (0, counted_tests_1.countedTests)(projectRoot) });
|
|
405
|
+
const judge = (yId) => (x.type !== 'T-SPEC' ? succession.aspec(x, yId) : succession.tspec(x, yId));
|
|
406
|
+
if (had && had !== y && recorded(a.id, had) && judge(had) === null) {
|
|
407
|
+
return { ok: false, reason: `${a.id}에는 이미 자격을 갖춘 superseded_by: ${had} 가 있습니다 — 덮어쓰지 않습니다.` };
|
|
408
|
+
}
|
|
409
|
+
const why = judge(y);
|
|
410
|
+
if (why !== null)
|
|
411
|
+
return { ok: false, reason: `${y}은(는) ${a.id}의 후속이 될 수 없습니다 — ${why}. 아무것도 쓰지 않았습니다.` };
|
|
412
|
+
try {
|
|
413
|
+
await store.write({ ...x, frontmatter: { ...fm, superseded_by: y } }, { expectedVersion: now.version });
|
|
414
|
+
}
|
|
415
|
+
catch (e) {
|
|
416
|
+
if (e instanceof spec_store_1.SpecVersionConflictError)
|
|
417
|
+
return { ok: false, reason: `기록 진행 중 ${a.id}이(가) 바뀌었습니다 — 확인 후 다시 시도하십시오. 이번 호출은 아무것도 쓰지 않았습니다.` };
|
|
418
|
+
throw e;
|
|
419
|
+
}
|
|
420
|
+
const ys = fresh.find((s) => s.id === y);
|
|
421
|
+
book.append({
|
|
422
|
+
ts: new Date().toISOString(), actor: `full-autonomy:${scope}`, kind: 'spec-superseded',
|
|
423
|
+
summary: `recorded ${y} as the successor of retired ${a.id}${had && had !== y ? ` (replacing ${had})` : ''}`.slice(0, 200),
|
|
424
|
+
inputs: [a.id, `superseded-by:${y}`, `successor-digest:${String(ys.frontmatter.approved_digest)}`, `directive:${directive}`, 'autonomous'],
|
|
425
|
+
rationale: 'superseded_by recorded on an already-outdated spec under full autonomy (A-SPEC-222.4, A-SPEC-222.6, A-SPEC-222.8)',
|
|
426
|
+
});
|
|
427
|
+
return { ok: true, noop: false };
|
|
428
|
+
});
|
|
429
|
+
if (!done.ok)
|
|
430
|
+
return { ok: false, reason: done.reason };
|
|
431
|
+
return { ok: true, retired: false, id: a.id, dependents: [], supersededBy: y, ...(done.noop ? { reason: `${a.id}의 superseded_by는 이미 ${y}(으)로 기록돼 있습니다` } : {}) };
|
|
432
|
+
}
|
|
433
|
+
// @implements A-SPEC-222.3 — an A-SPEC still anchored in code is not retired: the code gate refuses every write to
|
|
434
|
+
// a file anchored to an unapproved spec, the one that moves the anchor included (2026-10-25: run-exec.ts was
|
|
435
|
+
// locked by one leftover A-SPEC-774.77 comment until the owner changed it by hand). Checked before the approval
|
|
436
|
+
// step, so a refusal writes nothing and spends nothing.
|
|
437
|
+
const specsRoot = store.specsRoot;
|
|
438
|
+
if (spec.type === 'A-SPEC' && typeof specsRoot === 'string') {
|
|
439
|
+
// @implements A-SPEC-222.7 — H3: read over every file the code gate governs; what cannot be read is no proof
|
|
440
|
+
const census = (0, anchor_census_1.anchorCensus)(path.resolve(specsRoot, '..', '..'), a.id);
|
|
441
|
+
if (census.at.length === 0 && (census.unreadable.length > 0 || census.truncated)) {
|
|
442
|
+
// @implements A-SPEC-222.11 — the skipped archives are named beside the files that refuse
|
|
443
|
+
const skippedNote = census.skipped.length > 0 ? ` (선언된 바이너리 파일 ${census.skipped.length}개는 건너뛰었습니다: ${census.skipped.slice(0, 3).join(', ')}${census.skipped.length > 3 ? ' …' : ''})` : '';
|
|
444
|
+
return { ok: false, unreadable: census.unreadable, skipped: census.skipped, reason: `${a.id}이(가) 코드에 앵커되지 않았음을 증명할 수 없습니다 — 앵커 판독이 ${census.truncated ? '트리 전체를' : census.unreadable.slice(0, 5).join(', ')}을(를) 읽지 못했습니다${skippedNote}. 읽을 수 있게 한 뒤 다시 폐기하십시오.` };
|
|
445
|
+
}
|
|
446
|
+
const anchoredAt = census.at;
|
|
447
|
+
if (anchoredAt.length > 0) {
|
|
448
|
+
const successor = String(spec.frontmatter.superseded_by ?? '').trim();
|
|
449
|
+
const successorOk = successor !== '' && all.some((s) => s.id === successor && s.type === 'A-SPEC' && s.status === 'approved');
|
|
450
|
+
const shown = anchoredAt.slice(0, 20).join(', ') + (anchoredAt.length > 20 ? ` … (+${anchoredAt.length - 20})` : '');
|
|
451
|
+
return {
|
|
452
|
+
ok: false,
|
|
453
|
+
anchoredAt,
|
|
454
|
+
reason: `${a.id}은(는) 아직 코드가 앵커하고 있어 폐기하지 않습니다 — ${shown}.`
|
|
455
|
+
+ ' 폐기된 스펙에 앵커된 파일은 코드 게이트가 모든 편집을 거부하므로(앵커를 옮기는 편집 포함) 다시 고칠 수 없게 됩니다.'
|
|
456
|
+
+ (successorOk ? ` 먼저 각 앵커를 승인된 후속 스펙 ${successor}(으)로 옮긴 뒤 다시 폐기하십시오.`
|
|
457
|
+
: ' 먼저 각 앵커를 그 코드를 이제 맡는 승인된 A-SPEC으로 옮긴 뒤 다시 폐기하십시오(superseded_by에 후속을 적으면 이 안내가 그것을 가리킵니다).'),
|
|
458
|
+
};
|
|
459
|
+
}
|
|
240
460
|
}
|
|
241
461
|
const approvalRaw = process.env.HOLMES_APPROVAL;
|
|
242
462
|
let approval;
|
|
@@ -249,52 +469,147 @@ function createSpecLifecycleHandlers(context) {
|
|
|
249
469
|
const retireResolved = context.resolveHandlerApproval(a.root, approval, { kind: 'spec-approve', target: a.id }, new Date().toISOString());
|
|
250
470
|
const covered = retireResolved !== undefined;
|
|
251
471
|
const sealed = typeof spec.frontmatter.approved_digest === 'string';
|
|
472
|
+
// @implements A-SPEC-222.5 — under a full profile, a directive and a sealed successor stand in for the person
|
|
473
|
+
// when every machine condition holds; otherwise the act takes today's path, with the failed condition named.
|
|
474
|
+
let autonomousRefused;
|
|
475
|
+
const succ = typeof a.supersededBy === 'string' ? a.supersededBy.trim() : '';
|
|
476
|
+
const directive = typeof a.directive === 'string' ? a.directive.trim() : '';
|
|
477
|
+
// @implements A-SPEC-222.7 — L2: a directive is a bounded reference, not a channel
|
|
478
|
+
const directiveBad = directive !== '' && (directive.length > 500 || /[\u0000-\u001f\u007f]/.test(directive));
|
|
479
|
+
if (sealed && !covered && succ && directive && typeof specsRoot === 'string') {
|
|
480
|
+
const projectRoot = path.resolve(specsRoot, '..', '..');
|
|
481
|
+
let scope = null;
|
|
482
|
+
try {
|
|
483
|
+
const s = (0, full_autonomy_1.readFullProfile)(context.fullAutonomyHome?.() ?? os.homedir(), projectRoot);
|
|
484
|
+
scope = s.active ? s.entry.scope : null;
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
scope = null;
|
|
488
|
+
}
|
|
489
|
+
if (scope !== null && directiveBad)
|
|
490
|
+
autonomousRefused = 'the directive is longer than 500 characters or holds a control character';
|
|
491
|
+
else if (scope !== null) {
|
|
492
|
+
const also = (Array.isArray(a.also) ? a.also : []).map((c) => ({ id: String(c?.id ?? '').trim(), supersededBy: String(c?.supersededBy ?? '').trim() }));
|
|
493
|
+
const chain = [{ id: a.id, supersededBy: succ }, ...also];
|
|
494
|
+
// @implements A-SPEC-222.7 — M2: judged and written on one read, under one lock; a chain is written whole or not at all
|
|
495
|
+
const done = await underRetireLock(projectRoot, async () => {
|
|
496
|
+
const fresh = await store.list();
|
|
497
|
+
const reads = new Map();
|
|
498
|
+
for (const c of chain) {
|
|
499
|
+
const r = await store.read(c.id);
|
|
500
|
+
if (r)
|
|
501
|
+
reads.set(c.id, { spec: r.spec, version: r.version });
|
|
502
|
+
}
|
|
503
|
+
const judged = fresh.map((s) => reads.get(s.id)?.spec ?? s);
|
|
504
|
+
const dest = resolveLedgerRoot(a.root);
|
|
505
|
+
if (!dest.ok)
|
|
506
|
+
return { ok: false, reason: dest.reason, hard: true };
|
|
507
|
+
// @implements A-SPEC-222.8 — N2: a recorded superseded_by counts only as the ledger has it
|
|
508
|
+
const verdict = autonomousRetireVerdict(chain, judged, projectRoot, (0, recorded_pairs_1.recordedPairsPort)(dest.root)); // A-SPEC-222.9, A-SPEC-222.10
|
|
509
|
+
if (!verdict.ok)
|
|
510
|
+
return verdict;
|
|
511
|
+
const written = [];
|
|
512
|
+
for (const p of verdict.plan) {
|
|
513
|
+
try {
|
|
514
|
+
const v = await store.write({ ...p.x, status: 'outdated', frontmatter: { ...p.x.frontmatter, superseded_by: p.y.id } }, { expectedVersion: reads.get(p.x.id).version });
|
|
515
|
+
written.push({ before: p.x, version: v });
|
|
516
|
+
}
|
|
517
|
+
catch (e) {
|
|
518
|
+
const failed = [];
|
|
519
|
+
for (const w of written.reverse()) {
|
|
520
|
+
try {
|
|
521
|
+
const now = await store.read(w.before.id);
|
|
522
|
+
await store.write(w.before, { expectedVersion: now?.version });
|
|
523
|
+
}
|
|
524
|
+
catch {
|
|
525
|
+
failed.push(w.before.id);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (failed.length > 0) {
|
|
529
|
+
new ledger_store_1.FileLedgerStore(path.join(dest.root, '.ax', 'ledger')).append({
|
|
530
|
+
ts: new Date().toISOString(), actor: `full-autonomy:${scope}`, kind: 'spec-retire-partial',
|
|
531
|
+
summary: `an autonomous retirement chain failed at ${p.x.id}; ${failed.join(', ')} stayed retired`.slice(0, 200), inputs: [p.x.id, ...failed],
|
|
532
|
+
rationale: 'the chain write failed and its restore failed too (A-SPEC-222.7)',
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
return { ok: false, reason: `폐기 체인이 ${p.x.id}에서 실패했습니다(${e instanceof Error ? e.message : String(e)})${failed.length ? ` — ${failed.join(', ')}은(는) 되돌리지 못했습니다` : ' — 앞서 쓴 것은 되돌렸습니다'}.`, hard: true };
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
for (const p of verdict.plan) {
|
|
539
|
+
new ledger_store_1.FileLedgerStore(path.join(dest.root, '.ax', 'ledger')).append({
|
|
540
|
+
ts: new Date().toISOString(), actor: `full-autonomy:${scope}`, kind: 'spec-retired',
|
|
541
|
+
summary: `retired ${p.x.id}, superseded by ${p.y.id}, under full autonomy`.slice(0, 200),
|
|
542
|
+
inputs: [p.x.id, `superseded-by:${p.y.id}`, `successor-digest:${String(p.y.frontmatter.approved_digest)}`, `directive:${directive}`, 'autonomous'],
|
|
543
|
+
rationale: `autonomous retirement: every machine condition of A-SPEC-222.5 and A-SPEC-222.7 held (directive ${directive})`.slice(0, 300),
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
return { ok: true, plan: verdict.plan };
|
|
547
|
+
});
|
|
548
|
+
if (done.ok)
|
|
549
|
+
return { ok: true, retired: true, autonomous: true, id: a.id, chain: done.plan.map((p) => p.x.id), dependents: [] };
|
|
550
|
+
if (done.hard)
|
|
551
|
+
return { ok: false, reason: done.reason };
|
|
552
|
+
autonomousRefused = done.reason;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
252
555
|
if (sealed && !covered) {
|
|
253
556
|
return {
|
|
254
557
|
ok: false,
|
|
255
|
-
|
|
558
|
+
...(autonomousRefused ? { autonomousRefused } : {}),
|
|
559
|
+
reason: (autonomousRefused ? `자율 폐기 조건 불충족(${autonomousRefused}) — ` : '')
|
|
560
|
+
+ `${a.id}은(는) 봉인된 문서입니다 — 폐기는 이 행위를 덮는 유효한 대역외 HOLMES_APPROVAL 이 필요합니다.`
|
|
256
561
|
+ ' 코드 게이트를 막고 있는 approved T-SPEC 을 폐기하면 그 게이트가 열리므로, 폐기가 승인 우회 경로가 되지 않도록 fail-closed 로 막습니다.'
|
|
257
562
|
+ ' (범위를 쓰면 kind "spec-approve")'
|
|
258
563
|
+ context.refusalQueueHint(a.root, { kind: 'spec-approve', target: a.id, why: '봉인된 스펙의 폐기', title: spec.title }),
|
|
259
564
|
};
|
|
260
565
|
}
|
|
261
|
-
// @implements A-SPEC-245 — a grant that authorized breaking a seal is
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
566
|
+
// @implements A-SPEC-245, A-SPEC-245.1, A-SPEC-245.2 — a grant that authorized breaking a seal is claimed for the act
|
|
567
|
+
// and spent only by the write it authorized: a refusal (an approved dependent, the ledger destination, a version
|
|
568
|
+
// conflict) or a throw returns it, and a second act on the same grant loses the claim
|
|
569
|
+
const grantFor = sealed && retireResolved?.root ? retireResolved : undefined;
|
|
570
|
+
// L1: the ledger names the approval that authorized the act, a grant's included
|
|
571
|
+
const acting = sealed ? (retireResolved?.approval ?? approval) : approval;
|
|
572
|
+
let retireSpent = false; // A-SPEC-245.15 (item 2): once spent, the grant is committed whatever follows
|
|
573
|
+
return (0, approval_grants_1.withGrant)(grantFor?.root ?? a.root ?? '', grantFor, async () => {
|
|
574
|
+
const prepared = (0, transition_policy_1.prepareLifecycleSpec)(spec, all, 'retire', a.reason);
|
|
575
|
+
if (!prepared.ok)
|
|
576
|
+
return prepared;
|
|
577
|
+
const { dependents, candidate } = prepared;
|
|
578
|
+
// Destination BEFORE the write, the order A-SPEC-188 fixed for spec_approve: a resolution
|
|
579
|
+
// failure must leave nothing behind.
|
|
580
|
+
const dest = resolveLedgerRoot(a.root);
|
|
581
|
+
if (!dest.ok)
|
|
582
|
+
return { ok: false, reason: dest.reason };
|
|
583
|
+
const ledgerRoot = dest.root;
|
|
584
|
+
// Blank is omitted, never written: `retired_reason: ""` asserts a ground that does not exist,
|
|
585
|
+
// the same rule `legacy_status` follows. A document already carrying `superseded_by` has
|
|
586
|
+
// answered "why" already and is not asked twice.
|
|
587
|
+
const reason = typeof a.reason === 'string' ? a.reason.trim() : '';
|
|
588
|
+
try {
|
|
589
|
+
// @implements A-SPEC-245.9 (1b-1) — the grant is spent once across replicas in the store's beforePublish
|
|
590
|
+
await store.write(candidate, { expectedVersion: cur.version, beforePublish: (0, approval_grants_1.grantSpend)(grantFor, `spec-retire ${a.id}`, () => { retireSpent = true; }) });
|
|
591
|
+
}
|
|
592
|
+
catch (e) {
|
|
593
|
+
if (e instanceof spec_store_1.SpecVersionConflictError) {
|
|
594
|
+
return { ok: false, reason: `폐기 진행 중 ${a.id}이(가) 바뀌었습니다 — 확인 후 다시 시도하십시오. 이번 폐기는 아무것도 쓰지 않았습니다.` };
|
|
595
|
+
}
|
|
596
|
+
if (e instanceof approval_grants_1.GrantSpendRefusal)
|
|
597
|
+
return { ok: false, code: 'grant-spend-refused', reason: `${a.id} was not retired: ${e.message}` };
|
|
598
|
+
throw e;
|
|
285
599
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
600
|
+
new ledger_store_1.FileLedgerStore(path.join(ledgerRoot, '.ax', 'ledger')).append({
|
|
601
|
+
ts: new Date().toISOString(),
|
|
602
|
+
actor: acting?.actor ?? 'unattributed',
|
|
603
|
+
kind: 'spec-retired',
|
|
604
|
+
summary: `retired ${a.id}${reason ? ` — ${reason}` : ''}`,
|
|
605
|
+
// @implements A-SPEC-222.8 — N2: a person's retirement records the successor the retired spec named
|
|
606
|
+
inputs: [a.id, ...(String(spec.frontmatter.superseded_by ?? '').trim()
|
|
607
|
+
? [`superseded-by:${String(spec.frontmatter.superseded_by).trim()}`] : [])],
|
|
608
|
+
rationale: reason || (acting?.rationale ?? 'retired'),
|
|
609
|
+
...(acting ? { authorization: (0, provenance_chain_1.authorizationRef)(acting.actor, acting.token) } : {}),
|
|
610
|
+
});
|
|
611
|
+
return { ok: true, retired: true, id: a.id, dependents: dependents.map((s) => s.id) };
|
|
612
|
+
}, (r) => r.ok === true || retireSpent, () => ({ ok: false, code: 'grant-in-use', reason: `the approval grant for retiring ${a.id} is in use by another act — nothing was written; retry, or ask for a new approval` }), () => (retireSpent ? 'commit' : 'release'));
|
|
298
613
|
},
|
|
299
614
|
/**
|
|
300
615
|
* @implements A-SPEC-700.2
|
|
@@ -345,34 +660,61 @@ function createSpecLifecycleHandlers(context) {
|
|
|
345
660
|
reason: `spec_reconcile apply rewrites approved documents and source anchors — it requires one approval covering { kind: "config-write", target: "${plan.target}" }.`
|
|
346
661
|
+ context.refusalQueueHint(a.root, { ...action, why: `번호 충돌 수습: ${plan.moves.map((m) => `${m.from}→${m.to}`).join(', ')}` }),
|
|
347
662
|
};
|
|
348
|
-
// @implements A-SPEC-245 —
|
|
349
|
-
|
|
350
|
-
|
|
663
|
+
// @implements A-SPEC-245, A-SPEC-245.1, A-SPEC-245.2, A-SPEC-245.4 — the moves run inside the grant's claim (a
|
|
664
|
+
// second act on it loses the claim)
|
|
665
|
+
// @implements A-SPEC-245.15 (item 2) — the grant is spent before the first move, so once the spend is recorded it
|
|
666
|
+
// is committed whatever follows, a first move that fails included; only a refused spend returns it
|
|
351
667
|
const moved = [];
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
//
|
|
355
|
-
|
|
668
|
+
let reconcileSpent = false;
|
|
669
|
+
return (0, approval_grants_1.withGrantSync)(resolved.root ?? '', resolved.root ? resolved : undefined, () => {
|
|
670
|
+
// @implements A-SPEC-245.9 (1b-1) — the grant is spent once across replicas before the first move, inside the
|
|
671
|
+
// entity-store hold (entity-store lock → spend lock); the spend lock is held for the spend, not for the moves
|
|
356
672
|
try {
|
|
357
|
-
|
|
673
|
+
(0, approval_grants_1.grantSpend)(resolved.root ? resolved : undefined, `spec-reconcile ${plan.target}`, () => { reconcileSpent = true; })?.();
|
|
358
674
|
}
|
|
359
|
-
catch (
|
|
360
|
-
|
|
675
|
+
catch (e) {
|
|
676
|
+
if (e instanceof approval_grants_1.GrantSpendRefusal)
|
|
677
|
+
return { ok: false, code: 'grant-spend-refused', reason: `nothing moved: ${e.message}`, moved: [], remaining: plan.moves };
|
|
678
|
+
throw e;
|
|
361
679
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
680
|
+
for (const move of plan.moves) {
|
|
681
|
+
// A throw mid-move (disk, permissions) is reported like a refusal: the caller must learn
|
|
682
|
+
// which families DID move, or the only way to find out is to read the tree.
|
|
683
|
+
let result;
|
|
684
|
+
try {
|
|
685
|
+
result = renumberRun(specsRoot, { oldBase: move.from, newBase: move.to, dryRun: false }, journaled);
|
|
686
|
+
}
|
|
687
|
+
catch (error) {
|
|
688
|
+
result = { ok: false, reason: String(error instanceof Error ? error.message : error).split('\n')[0] };
|
|
689
|
+
}
|
|
690
|
+
// Finished moves stay finished and no longer collide, so planning again yields the rest.
|
|
691
|
+
if (!result.ok) {
|
|
692
|
+
const remaining = plan.moves.slice(moved.length);
|
|
693
|
+
if (moved.length === 0)
|
|
694
|
+
return { ok: false, reason: `move ${move.from} → ${move.to} stopped: ${result.reason}`, moved, remaining };
|
|
695
|
+
// @implements A-SPEC-245.2 (M3) — the grant was spent by the moves that finished; they are recorded
|
|
696
|
+
new ledger_store_1.FileLedgerStore(path.join(path.resolve(specsRoot, '..', '..'), '.ax', 'ledger')).append({
|
|
697
|
+
ts: new Date().toISOString(),
|
|
698
|
+
actor: resolved.approval.actor ?? 'spec_reconcile',
|
|
699
|
+
kind: 'spec-reconcile-partial',
|
|
700
|
+
summary: `reconciled ${moved.length} of ${plan.moves.length} base(s), then stopped at ${move.from}->${move.to}: ${String(result.reason).slice(0, 80)}`.slice(0, 200),
|
|
701
|
+
inputs: [plan.target, ...moved.map((m) => `${m.from}->${m.to}`), ...remaining.map((m) => `remaining:${m.from}->${m.to}`)],
|
|
702
|
+
authorization: (0, provenance_chain_1.authorizationRef)(resolved.approval.actor, resolved.approval.token),
|
|
703
|
+
});
|
|
704
|
+
return { ok: false, reason: `move ${move.from} → ${move.to} stopped: ${result.reason}`, moved, remaining };
|
|
705
|
+
}
|
|
706
|
+
moved.push({ from: move.from, to: move.to, specs: result.movedSpecs ?? 0 });
|
|
707
|
+
}
|
|
708
|
+
new ledger_store_1.FileLedgerStore(path.join(path.resolve(specsRoot, '..', '..'), '.ax', 'ledger')).append({
|
|
709
|
+
ts: new Date().toISOString(),
|
|
710
|
+
actor: 'spec_reconcile',
|
|
711
|
+
kind: 'spec-reconciled',
|
|
712
|
+
summary: `reconciled ${moved.length} base(s) against ${plan.remoteRefs.join(', ')}: ${moved.map((m) => `${m.from}->${m.to}`).join(', ')}; approved by ${resolved.approval.actor ?? 'unknown'}`,
|
|
713
|
+
inputs: [plan.target, ...moved.map((m) => `${m.from}->${m.to}`), ...plan.remoteRefs],
|
|
714
|
+
authorization: (0, provenance_chain_1.authorizationRef)(resolved.approval.actor, resolved.approval.token),
|
|
715
|
+
});
|
|
716
|
+
return { ok: true, operation: 'apply', moved, approveOrder: plan.approveOrder, proseCandidates: plan.proseCandidates };
|
|
717
|
+
}, () => moved.length > 0 || reconcileSpent, () => ({ ok: false, code: 'grant-in-use', reason: 'the approval grant for this reconcile is in use by another act — nothing moved; retry, or ask for a new approval' }), () => (moved.length > 0 || reconcileSpent ? 'commit' : 'release'));
|
|
376
718
|
};
|
|
377
719
|
let bound;
|
|
378
720
|
try {
|
|
@@ -487,38 +829,43 @@ function createSpecLifecycleHandlers(context) {
|
|
|
487
829
|
+ context.refusalQueueHint(a.root, { kind: 'spec-approve', target: a.id, why: '봉인된 스펙의 해제', title: spec.title }),
|
|
488
830
|
};
|
|
489
831
|
}
|
|
490
|
-
// @implements A-SPEC-245 —
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
if (e instanceof spec_store_1.SpecVersionConflictError) {
|
|
508
|
-
return { ok: false, reason: `봉인 해제 진행 중 ${a.id}이(가) 바뀌었습니다 — 확인 후 다시 시도하십시오. 이번 해제는 아무것도 쓰지 않았습니다.` };
|
|
832
|
+
// @implements A-SPEC-245, A-SPEC-245.1, A-SPEC-245.2 — the act runs inside the grant's claim: spent by the write it
|
|
833
|
+
// authorized, returned by a refusal or a throw; the ledger names the approval that authorized it (L1)
|
|
834
|
+
const acting = resolved.approval;
|
|
835
|
+
let unsealSpent = false; // A-SPEC-245.15 (item 2)
|
|
836
|
+
return (0, approval_grants_1.withGrant)(resolved.root ?? a.root ?? '', resolved.root ? resolved : undefined, async () => {
|
|
837
|
+
const prepared = (0, transition_policy_1.prepareLifecycleSpec)(spec, all, 'unseal');
|
|
838
|
+
if (!prepared.ok)
|
|
839
|
+
return prepared;
|
|
840
|
+
const { dependents, candidate } = prepared;
|
|
841
|
+
// Destination BEFORE the write (A-SPEC-188 order): a resolution failure leaves nothing behind.
|
|
842
|
+
const dest = resolveLedgerRoot(a.root);
|
|
843
|
+
if (!dest.ok)
|
|
844
|
+
return { ok: false, reason: dest.reason };
|
|
845
|
+
const ledgerRoot = dest.root;
|
|
846
|
+
try {
|
|
847
|
+
// @implements A-SPEC-245.9 (1b-1) — the grant is spent once across replicas in the store's beforePublish
|
|
848
|
+
await store.write(candidate, { expectedVersion: cur.version, beforePublish: (0, approval_grants_1.grantSpend)(resolved.root ? resolved : undefined, `spec-unseal ${a.id}`, () => { unsealSpent = true; }) });
|
|
509
849
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
850
|
+
catch (e) {
|
|
851
|
+
if (e instanceof spec_store_1.SpecVersionConflictError) {
|
|
852
|
+
return { ok: false, reason: `봉인 해제 진행 중 ${a.id}이(가) 바뀌었습니다 — 확인 후 다시 시도하십시오. 이번 해제는 아무것도 쓰지 않았습니다.` };
|
|
853
|
+
}
|
|
854
|
+
if (e instanceof approval_grants_1.GrantSpendRefusal)
|
|
855
|
+
return { ok: false, code: 'grant-spend-refused', reason: `${a.id} was not unsealed: ${e.message}` };
|
|
856
|
+
throw e;
|
|
857
|
+
}
|
|
858
|
+
new ledger_store_1.FileLedgerStore(path.join(ledgerRoot, '.ax', 'ledger')).append({
|
|
859
|
+
ts: new Date().toISOString(),
|
|
860
|
+
actor: acting.actor ?? 'unattributed',
|
|
861
|
+
kind: 'spec-unsealed',
|
|
862
|
+
summary: `unsealed ${a.id}`,
|
|
863
|
+
inputs: [a.id],
|
|
864
|
+
rationale: acting.rationale ?? 'unsealed',
|
|
865
|
+
authorization: (0, provenance_chain_1.authorizationRef)(acting.actor, acting.token),
|
|
866
|
+
});
|
|
867
|
+
return { ok: true, unsealed: true, id: a.id, dependents: dependents.map((s) => s.id) };
|
|
868
|
+
}, (r) => r.ok === true || unsealSpent, () => ({ ok: false, code: 'grant-in-use', reason: `the approval grant for un-sealing ${a.id} is in use by another act — nothing was written; retry, or ask for a new approval` }), () => (unsealSpent ? 'commit' : 'release'));
|
|
522
869
|
},
|
|
523
870
|
};
|
|
524
871
|
}
|
|
@@ -50,14 +50,14 @@ export declare function createSpecQueryHandlers(context: SpecQueryContext): {
|
|
|
50
50
|
chainTotal: number;
|
|
51
51
|
note: string;
|
|
52
52
|
ok?: undefined;
|
|
53
|
-
reason?: undefined;
|
|
53
|
+
readonly reason?: undefined;
|
|
54
54
|
} | {
|
|
55
55
|
next: import("../../spec/spec-types").SpecType | null;
|
|
56
56
|
actions: NextAction[];
|
|
57
57
|
actionsTotal: number;
|
|
58
58
|
note: string;
|
|
59
59
|
ok?: undefined;
|
|
60
|
-
reason?: undefined;
|
|
60
|
+
readonly reason?: undefined;
|
|
61
61
|
chain?: undefined;
|
|
62
62
|
chainTotal?: undefined;
|
|
63
63
|
}>;
|