@holmes-lab/holmes-kit 0.39.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 +344 -6
- package/README.md +54 -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 +202 -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.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 +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 +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 +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/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 +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 +105 -1
- package/dist/holmes/hooks/pre-tool-use.js +1134 -167
- 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/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/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-queries.d.ts +2 -2
- package/dist/holmes/mcp/handlers.d.ts +89 -79
- package/dist/holmes/mcp/handlers.js +69 -22
- 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.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 +29 -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/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 +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 +45 -33
- package/dist/holmes/review/manual-baseline.d.ts +0 -209
- package/dist/holmes/review/manual-baseline.js +0 -2847
|
@@ -40,12 +40,13 @@ exports.fullProfileGate = fullProfileGate;
|
|
|
40
40
|
exports.runAutonomyFull = runAutonomyFull;
|
|
41
41
|
exports.autonomyPostureLine = autonomyPostureLine;
|
|
42
42
|
exports.runAutonomy = runAutonomy;
|
|
43
|
-
// @implements A-SPEC-553.1, A-SPEC-553.2, A-SPEC-771, A-SPEC-718.7, A-SPEC-792.3, A-SPEC-792.7
|
|
43
|
+
// @implements A-SPEC-794.58, A-SPEC-794.57, A-SPEC-794.55, A-SPEC-553.1, A-SPEC-553.2, A-SPEC-771, A-SPEC-718.7, A-SPEC-792.3, A-SPEC-792.7, A-SPEC-245.9, A-SPEC-794.35
|
|
44
44
|
const fs = __importStar(require("node:fs"));
|
|
45
45
|
const full_autonomy_1 = require("../governance/full-autonomy");
|
|
46
46
|
const autonomy_1 = require("../governance/autonomy");
|
|
47
47
|
const path = __importStar(require("node:path"));
|
|
48
48
|
const risk_gate_1 = require("../guardrail/risk-gate");
|
|
49
|
+
const human_channel_1 = require("../governance/human-channel");
|
|
49
50
|
const autonomy_2 = require("../governance/autonomy");
|
|
50
51
|
const delegation_1 = require("../governance/delegation");
|
|
51
52
|
const PROJECT_DEFAULT_ON = 'autonomous spec approval: ON (project default, .mcp.json) — governance-critical still ask you. '
|
|
@@ -137,7 +138,7 @@ function fullProfileGate(input, deps) {
|
|
|
137
138
|
if (why === null)
|
|
138
139
|
return { proceed: true };
|
|
139
140
|
const title = `full autonomy for ${input.scope} (${action.subject})`;
|
|
140
|
-
deps.enqueue(input.askRoot, { ...action, why: `
|
|
141
|
+
deps.enqueue(input.askRoot, { ...action, why: `under ${input.scope}, ${autonomy_1.FULL_PROFILE_MEANING} (${action.subject})`, title });
|
|
141
142
|
const id = (0, approval_queue_1.approvalRequestId)(action.kind, action.target);
|
|
142
143
|
return { proceed: false, id, message: `${why}${(0, approval_queue_1.pendingRequestLine)(id, action.kind, input.askRoot, title, input.scope)}` };
|
|
143
144
|
}
|
|
@@ -157,12 +158,15 @@ function runAutonomyFull(home, args, io) {
|
|
|
157
158
|
if (!fs.statSync(scope).isDirectory())
|
|
158
159
|
return { ok: false, exitCode: 2, message: `--scope ${args.scope} is not a directory` };
|
|
159
160
|
const flags = args.flags ?? { push: false, publish: false, architecture: true };
|
|
161
|
+
io.beforeWrite?.(); // A-SPEC-245.9 (1b-1) — the grant's spend, after every refusal and before the profile is written
|
|
160
162
|
(0, full_autonomy_1.addFullProfileEntry)(home, { scope, flags, issuedAt: io.now, issuedBy: io.actor });
|
|
161
|
-
return { ok: true, exitCode: 0, message: `full autonomy: ON for ${scope} (${fullProfileSubject(flags)}) —
|
|
163
|
+
return { ok: true, exitCode: 0, message: `full autonomy: ON for ${scope} (${fullProfileSubject(flags)}) — ${autonomy_1.FULL_PROFILE_MEANING}` };
|
|
162
164
|
}
|
|
165
|
+
/** The posture line when no envelope is on (A-SPEC-794.57: replaced beside a full profile). */
|
|
166
|
+
const POSTURE_OFF = 'autonomous spec approval: OFF — no spec approval is self-driven; each waits for a grant (holmes-kit autonomy on to self-drive this session)';
|
|
163
167
|
/** @implements A-SPEC-718.7 — the posture `autonomy status` reports, never coloured by the caller's own environment. */
|
|
164
|
-
function autonomyPostureLine(root, now) {
|
|
165
|
-
return runAutonomy(root, 'status', undefined, { now, isTTY: false, env: {} }).message;
|
|
168
|
+
function autonomyPostureLine(root, now, postureOnly = false) {
|
|
169
|
+
return runAutonomy(root, 'status', undefined, { now, isTTY: false, env: {}, postureOnly }).message;
|
|
166
170
|
}
|
|
167
171
|
/**
|
|
168
172
|
* The `holmes-kit autonomy status|on|off|delegate|revoke-delegation` core. Pure over injected io (clock/TTY/approval/
|
|
@@ -178,7 +182,9 @@ function runAutonomy(root, sub, forStr, io, extra = {}) {
|
|
|
178
182
|
const full = io.postureOnly ? '' : (0, autonomy_1.fullAutonomyLine)(root, io.home);
|
|
179
183
|
if (full !== '') {
|
|
180
184
|
const rest = runAutonomy(root, sub, forStr, { ...io, postureOnly: true }, extra);
|
|
181
|
-
|
|
185
|
+
// A-SPEC-794.57 — OFF beside a full profile does not mean each spec waits: the profile decides seals in its scope
|
|
186
|
+
const posture = rest.message.startsWith(POSTURE_OFF) ? 'autonomous spec approval: OFF — the full profile above decides spec seals in its scope' : rest.message;
|
|
187
|
+
return { ...rest, message: `${full}\n${posture}` };
|
|
182
188
|
}
|
|
183
189
|
// @implements A-SPEC-771 — an active run delegation is reported beside whichever posture is on.
|
|
184
190
|
const delegationLine = delegationStatusLine(root, io.now);
|
|
@@ -201,7 +207,7 @@ function runAutonomy(root, sub, forStr, io, extra = {}) {
|
|
|
201
207
|
}
|
|
202
208
|
if (delegationLine !== null)
|
|
203
209
|
return { ok: true, exitCode: 0, message: `autonomous spec approval: ON (run delegation) — ${delegationLine}` };
|
|
204
|
-
return { ok: true, exitCode: 0, message:
|
|
210
|
+
return { ok: true, exitCode: 0, message: POSTURE_OFF };
|
|
205
211
|
}
|
|
206
212
|
if (sub === 'off') {
|
|
207
213
|
// @implements A-SPEC-558.1 — `off` is the emergency de-escalation control; it must fail CLOSED.
|
|
@@ -245,7 +251,7 @@ function runAutonomy(root, sub, forStr, io, extra = {}) {
|
|
|
245
251
|
return { ok: false, exitCode: 1, message: 'session autonomy ended, but autonomous spec approval is still ON: the project default in .mcp.json '
|
|
246
252
|
+ '(HOLMES_AUTONOMOUS_APPROVAL) keeps it on — remove it from .mcp.json (or holmes-kit init --no-autonomy) to turn it off.' };
|
|
247
253
|
}
|
|
248
|
-
return { ok: true, exitCode: 0, message: 'autonomous spec approval: OFF —
|
|
254
|
+
return { ok: true, exitCode: 0, message: 'autonomous spec approval: OFF — no spec approval is self-driven again; each waits for a grant' };
|
|
249
255
|
}
|
|
250
256
|
// @implements A-SPEC-771 — revoking needs no proof (de-escalation is always free), like `off`.
|
|
251
257
|
if (sub === 'revoke-delegation') {
|
|
@@ -263,7 +269,7 @@ function runAutonomy(root, sub, forStr, io, extra = {}) {
|
|
|
263
269
|
if (mins === null)
|
|
264
270
|
return { ok: false, exitCode: 2, message: '--for must look like 2h, 90m or 7d (1 minute .. 7 days)' };
|
|
265
271
|
const expires = new Date(Date.parse(io.now) + mins * 60_000).toISOString();
|
|
266
|
-
const grantedBy = io.approval?.actor ?? 'operator(tty)';
|
|
272
|
+
const grantedBy = (0, human_channel_1.ledgerActor)(io.approval?.actor ?? 'operator(tty)'); // @implements A-SPEC-792.26
|
|
267
273
|
if (sub === 'delegate') {
|
|
268
274
|
// @implements A-SPEC-771 — the document names the run, the resolved workspace, the covered grader rules, the
|
|
269
275
|
// expiry and the declared limits; a NEVER or unknown rule is refused before anything is written.
|
|
@@ -311,6 +317,7 @@ function runAutonomy(root, sub, forStr, io, extra = {}) {
|
|
|
311
317
|
return { ok: true, exitCode: 0, message: `run delegation: run ${run} until ${expires} — covers ${allow.join(', ')} in ${workspace}.\n`
|
|
312
318
|
+ `Hitl specs whose only reason is a covered rule seal on their own and the ledger names the run and the rule; ${DELEGATION_HOST_NOTE}. End early: holmes-kit autonomy revoke-delegation.` };
|
|
313
319
|
}
|
|
320
|
+
io.beforeWrite?.(); // A-SPEC-245.9 (1b-1) — the grant's spend, after every refusal and before the marker is written
|
|
314
321
|
try {
|
|
315
322
|
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
|
316
323
|
fs.writeFileSync(markerPath, JSON.stringify({ enabled: true, expires, grantedBy, rationale: `session autonomy for ${mins}m` }, null, 2) + '\n');
|
|
@@ -328,5 +335,5 @@ function runAutonomy(root, sub, forStr, io, extra = {}) {
|
|
|
328
335
|
return { ok: true, exitCode: 0, message: `autonomous spec approval: ON for this session, until ${expires}.\n`
|
|
329
336
|
+ 'Low-risk specs self-approve; governance-critical, high-risk and irreversible still ask you. End early: holmes-kit autonomy off.' };
|
|
330
337
|
}
|
|
331
|
-
return { ok: false, exitCode: 2, message: 'usage: holmes-kit autonomy [status|on [--for 2h]|off|delegate --run <id> --allow <rule[,rule]> [--for 2h] [--limit k=v]… [--rationale <text>]|revoke-delegation]' };
|
|
338
|
+
return { ok: false, exitCode: 2, message: 'usage: holmes-kit autonomy [status|on [--for 2h]|off|delegate --run <id> --allow <rule[,rule]> [--for 2h] [--limit k=v]… [--rationale <text>]|revoke-delegation|full --scope <path> [--allow-push] [--allow-publish] [--no-architecture]|full --revoke [<scope>]]' };
|
|
332
339
|
}
|
|
@@ -186,6 +186,17 @@ export declare function isHolmesPreToolCommand(command: string | undefined): boo
|
|
|
186
186
|
* Only the Holmes group's own `pre_tool_use:<i>:<j>` counts; case-insensitive on Windows.
|
|
187
187
|
*/
|
|
188
188
|
export declare function holmesPreToolDisabled(configText: string | null, hooksText: string | null, hooksPath: string): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* The layers Codex reads besides the user file: `.codex/config.toml` from `cwd` up to the root.
|
|
191
|
+
* @implements A-SPEC-774.38 — exported for run start's codex checks.
|
|
192
|
+
*/
|
|
193
|
+
export declare function projectLayers(cwd: string, userFile?: string | null): {
|
|
194
|
+
docs: Array<{
|
|
195
|
+
file: string;
|
|
196
|
+
doc: Record<string, unknown>;
|
|
197
|
+
}>;
|
|
198
|
+
bad: string | null;
|
|
199
|
+
};
|
|
189
200
|
/** The first `codex` on PATH (PATHEXT on Windows), unless the oracle is switched off. */
|
|
190
201
|
export declare function findCodex(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): FoundCodex;
|
|
191
202
|
/** The worker source, for tests that drive it directly (A-SPEC-738 round 4: its signal handling). */
|
|
@@ -49,6 +49,7 @@ exports.tableRedirection = tableRedirection;
|
|
|
49
49
|
exports.layerFileNamed = layerFileNamed;
|
|
50
50
|
exports.isHolmesPreToolCommand = isHolmesPreToolCommand;
|
|
51
51
|
exports.holmesPreToolDisabled = holmesPreToolDisabled;
|
|
52
|
+
exports.projectLayers = projectLayers;
|
|
52
53
|
exports.findCodex = findCodex;
|
|
53
54
|
exports.askCodex = askCodex;
|
|
54
55
|
// @implements A-SPEC-738
|
|
@@ -794,7 +795,10 @@ function holmesPreToolDisabled(configText, hooksText, hooksPath) {
|
|
|
794
795
|
const wanted = new Set(indices.flatMap((ix) => [`${hooksPath}:pre_tool_use:${ix}`, `${real}:pre_tool_use:${ix}`, `${realNative}:pre_tool_use:${ix}`]).map(norm));
|
|
795
796
|
return Object.entries(st).some(([k, v]) => wanted.has(norm(k)) && typeof v === 'object' && v !== null && v.enabled === false);
|
|
796
797
|
}
|
|
797
|
-
/**
|
|
798
|
+
/**
|
|
799
|
+
* The layers Codex reads besides the user file: `.codex/config.toml` from `cwd` up to the root.
|
|
800
|
+
* @implements A-SPEC-774.38 — exported for run start's codex checks.
|
|
801
|
+
*/
|
|
798
802
|
function projectLayers(cwd, userFile = null) {
|
|
799
803
|
const docs = [];
|
|
800
804
|
let bad = null;
|
|
@@ -9,6 +9,16 @@ export declare function parseCodexConfig(raw: string): {
|
|
|
9
9
|
reason: string;
|
|
10
10
|
};
|
|
11
11
|
/** @implements A-SPEC-727 (round 10) — whether the holmes-kit table sets `enabled = false`. */
|
|
12
|
+
/**
|
|
13
|
+
* @implements A-SPEC-774.46 — whether a parsed Codex config turns hooks off: `features.hooks` is the canonical key and
|
|
14
|
+
* `features.codex_hooks` its old name (codex 0.163's alias table). run start and doctor both read it here.
|
|
15
|
+
*/
|
|
16
|
+
export declare function codexHooksFeatureOff(doc: unknown): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* @implements A-SPEC-774.46 — the `[mcp_servers.holmes-kit]` table Codex assembles from `docs` in load order (user first,
|
|
19
|
+
* then each project layer from the root down): a later key replaces an earlier one, nested tables merge by key.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mergedHolmesTable(docs: unknown[]): Record<string, unknown> | null;
|
|
12
22
|
export declare function codexHolmesDisabled(raw: string): boolean;
|
|
13
23
|
/** Why Codex cannot load this config, or null when it parses. */
|
|
14
24
|
/**
|
|
@@ -35,6 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.CODEX_TABLE = void 0;
|
|
37
37
|
exports.parseCodexConfig = parseCodexConfig;
|
|
38
|
+
exports.codexHooksFeatureOff = codexHooksFeatureOff;
|
|
39
|
+
exports.mergedHolmesTable = mergedHolmesTable;
|
|
38
40
|
exports.codexHolmesDisabled = codexHolmesDisabled;
|
|
39
41
|
exports.readCodexConfigBytes = readCodexConfigBytes;
|
|
40
42
|
exports.codexConfigLoadProblem = codexConfigLoadProblem;
|
|
@@ -50,7 +52,7 @@ exports.mentionsHolmes = mentionsHolmes;
|
|
|
50
52
|
exports.unownedHolmesShape = unownedHolmesShape;
|
|
51
53
|
exports.readCodexFixedSpecs = readCodexFixedSpecs;
|
|
52
54
|
exports.invalidTomlEscape = invalidTomlEscape;
|
|
53
|
-
// @implements A-SPEC-733, A-SPEC-731, A-SPEC-721, A-SPEC-769.22
|
|
55
|
+
// @implements A-SPEC-733, A-SPEC-731, A-SPEC-721, A-SPEC-769.22, A-SPEC-794.58
|
|
54
56
|
// @implements A-SPEC-266
|
|
55
57
|
// Codex reads default MCP servers from `$CODEX_HOME/config.toml` (normally
|
|
56
58
|
// `~/.codex/config.toml`), not from a repository-local `.codex/config.toml`. This module owns only
|
|
@@ -132,6 +134,38 @@ function impossibleDateLiteral(text) {
|
|
|
132
134
|
return null;
|
|
133
135
|
}
|
|
134
136
|
/** @implements A-SPEC-727 (round 10) — whether the holmes-kit table sets `enabled = false`. */
|
|
137
|
+
/**
|
|
138
|
+
* @implements A-SPEC-774.46 — whether a parsed Codex config turns hooks off: `features.hooks` is the canonical key and
|
|
139
|
+
* `features.codex_hooks` its old name (codex 0.163's alias table). run start and doctor both read it here.
|
|
140
|
+
*/
|
|
141
|
+
function codexHooksFeatureOff(doc) {
|
|
142
|
+
const features = doc?.features;
|
|
143
|
+
if (!isTable(features))
|
|
144
|
+
return false;
|
|
145
|
+
const f = features;
|
|
146
|
+
return f.hooks === false || f.codex_hooks === false;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @implements A-SPEC-774.46 — the `[mcp_servers.holmes-kit]` table Codex assembles from `docs` in load order (user first,
|
|
150
|
+
* then each project layer from the root down): a later key replaces an earlier one, nested tables merge by key.
|
|
151
|
+
*/
|
|
152
|
+
function mergedHolmesTable(docs) {
|
|
153
|
+
const merge = (a, b) => {
|
|
154
|
+
const out = { ...a };
|
|
155
|
+
for (const [k, v] of Object.entries(b)) {
|
|
156
|
+
const prev = out[k];
|
|
157
|
+
out[k] = isTable(v) && isTable(prev) ? merge(prev, v) : v;
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
};
|
|
161
|
+
let merged = null;
|
|
162
|
+
for (const doc of docs) {
|
|
163
|
+
const entry = doc && typeof doc === 'object' ? holmesEntryOf(doc) : null;
|
|
164
|
+
if (entry !== null)
|
|
165
|
+
merged = merge(merged ?? {}, entry);
|
|
166
|
+
}
|
|
167
|
+
return merged;
|
|
168
|
+
}
|
|
135
169
|
function codexHolmesDisabled(raw) {
|
|
136
170
|
const p = parseCodexConfig(raw);
|
|
137
171
|
if (!p.ok)
|
|
@@ -750,7 +784,7 @@ function firstInvalidEscape(s) {
|
|
|
750
784
|
}
|
|
751
785
|
// @implements A-SPEC-585 — strict: only the escapes TOML defines. Anything else THROWS, so the
|
|
752
786
|
// caller answers "unreadable" — an unknown escape used to fold to its bare letter and turned
|
|
753
|
-
// `C:\
|
|
787
|
+
// `C:\workspace\…` into `C:workspace…` (measured on every Windows checkout).
|
|
754
788
|
function unescapeToml(s) {
|
|
755
789
|
const bad = firstInvalidEscape(s);
|
|
756
790
|
if (bad !== null)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Check } from './doctor-check';
|
|
2
|
+
export type Tri = true | false | 'unknown';
|
|
3
|
+
export interface ForgeFacts {
|
|
4
|
+
config: Tri;
|
|
5
|
+
appId: number | null;
|
|
6
|
+
workflow: Tri;
|
|
7
|
+
selfHosted: Tri;
|
|
8
|
+
rulesets: Tri;
|
|
9
|
+
prOnly: Tri;
|
|
10
|
+
requiredWorkflow: {
|
|
11
|
+
sha: string;
|
|
12
|
+
} | null | 'unknown';
|
|
13
|
+
nonFastForward: Tri;
|
|
14
|
+
deletion: Tri;
|
|
15
|
+
environment: Tri;
|
|
16
|
+
checkRun: Tri;
|
|
17
|
+
rateLimit: Tri;
|
|
18
|
+
scopes: string[] | 'unknown';
|
|
19
|
+
admin: Tri;
|
|
20
|
+
githubToken: boolean;
|
|
21
|
+
ghToken?: boolean;
|
|
22
|
+
ghEnterpriseToken?: boolean;
|
|
23
|
+
credentialHelper: boolean;
|
|
24
|
+
pin: {
|
|
25
|
+
classifier?: string;
|
|
26
|
+
} | null;
|
|
27
|
+
installedVersion: string;
|
|
28
|
+
}
|
|
29
|
+
/** @implements A-SPEC-792.48 (M4) — a governed target the diagnosis cannot read: named, never silent. */
|
|
30
|
+
export interface ForgeSkip {
|
|
31
|
+
skip: 'no-remote' | 'unsupported';
|
|
32
|
+
}
|
|
33
|
+
export interface ForgeResponse {
|
|
34
|
+
status: number;
|
|
35
|
+
headers: Record<string, string>;
|
|
36
|
+
body: unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface ForgeDeps {
|
|
39
|
+
/** One `gh api` call; null when gh is missing, unauthenticated, out of budget or did not answer in time. */
|
|
40
|
+
api: (apiPath: string) => ForgeResponse | null;
|
|
41
|
+
/** One git call in the target; its stdout, or null on any failure. */
|
|
42
|
+
git: (args: string[]) => string | null;
|
|
43
|
+
env: NodeJS.ProcessEnv;
|
|
44
|
+
installedVersion: string;
|
|
45
|
+
}
|
|
46
|
+
/** The detector's fixed names (A-SPEC-792.37 §3). */
|
|
47
|
+
export declare const DETECTOR_WORKFLOW = ".github/workflows/holmes-admission.yml";
|
|
48
|
+
export declare const DETECTOR_ENVIRONMENT = "holmes-admission";
|
|
49
|
+
export declare const DETECTOR_CHECK = "holmes-admission";
|
|
50
|
+
/** @implements A-SPEC-792.48 (M6) — one call's bound and the whole reading's budget. */
|
|
51
|
+
export declare const API_TIMEOUT_MS = 8000;
|
|
52
|
+
export declare const FORGE_BUDGET_MS = 10000;
|
|
53
|
+
/** Facts for a governed target, a named skip where it cannot be read, or null where the diagnosis does not apply. */
|
|
54
|
+
export declare function readForgeFacts(target: string, deps: ForgeDeps): ForgeFacts | ForgeSkip | null;
|
|
55
|
+
/** @implements A-SPEC-792.48 (M4) — the line for a diagnosis that threw. */
|
|
56
|
+
export declare function diagnosisFailedCheck(): Check;
|
|
57
|
+
/** The diagnosis lines. Pure: the facts (or the skip) in, the lines out. */
|
|
58
|
+
export declare function boundaryChecks(input: ForgeFacts | ForgeSkip): Check[];
|
|
59
|
+
type SpawnLike = (cmd: string, args: string[], opts: {
|
|
60
|
+
encoding: 'utf8';
|
|
61
|
+
timeout: number;
|
|
62
|
+
stdio: ['ignore', 'pipe', 'ignore'];
|
|
63
|
+
windowsHide: boolean;
|
|
64
|
+
env: NodeJS.ProcessEnv;
|
|
65
|
+
}) => {
|
|
66
|
+
error?: Error;
|
|
67
|
+
stdout?: string | null;
|
|
68
|
+
status: number | null;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The real reader: `gh api -i`, each call bounded and all of them under one budget; after the first timeout or once the
|
|
72
|
+
* budget is spent, every further call is unknown without spawning (A-SPEC-792.48 M6). Git runs through the shared
|
|
73
|
+
* sanitised environment.
|
|
74
|
+
*/
|
|
75
|
+
export declare function realForgeDeps(target: string, installedVersion: string, spawn?: SpawnLike, now?: () => number): ForgeDeps;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FORGE_BUDGET_MS = exports.API_TIMEOUT_MS = exports.DETECTOR_CHECK = exports.DETECTOR_ENVIRONMENT = exports.DETECTOR_WORKFLOW = void 0;
|
|
37
|
+
exports.readForgeFacts = readForgeFacts;
|
|
38
|
+
exports.diagnosisFailedCheck = diagnosisFailedCheck;
|
|
39
|
+
exports.boundaryChecks = boundaryChecks;
|
|
40
|
+
exports.realForgeDeps = realForgeDeps;
|
|
41
|
+
// @implements A-SPEC-792.46, A-SPEC-792.48
|
|
42
|
+
/**
|
|
43
|
+
* The server detector's boundary conditions, diagnosed honestly (slice 3 of A-SPEC-792.37). `readForgeFacts` reads the
|
|
44
|
+
* forge through `gh api` (at most six calls, one budget) and the default branch's files through git; `boundaryChecks`
|
|
45
|
+
* judges those facts and nothing else. No line claims a boundary; a fact that was not confirmed is "unknown" and never
|
|
46
|
+
* becomes PASS (A-SPEC-792.48); no credential value is ever read into the facts.
|
|
47
|
+
*/
|
|
48
|
+
const node_child_process_1 = require("node:child_process");
|
|
49
|
+
const fs = __importStar(require("node:fs"));
|
|
50
|
+
const path = __importStar(require("node:path"));
|
|
51
|
+
/** The detector's fixed names (A-SPEC-792.37 §3). */
|
|
52
|
+
exports.DETECTOR_WORKFLOW = '.github/workflows/holmes-admission.yml';
|
|
53
|
+
exports.DETECTOR_ENVIRONMENT = 'holmes-admission';
|
|
54
|
+
exports.DETECTOR_CHECK = 'holmes-admission';
|
|
55
|
+
/** @implements A-SPEC-792.48 (M6) — one call's bound and the whole reading's budget. */
|
|
56
|
+
exports.API_TIMEOUT_MS = 8_000;
|
|
57
|
+
exports.FORGE_BUDGET_MS = 10_000;
|
|
58
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
59
|
+
const json = (text) => { if (text === null)
|
|
60
|
+
return null; try {
|
|
61
|
+
return JSON.parse(text);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
} };
|
|
66
|
+
const ok = (r) => r !== null && r.status >= 200 && r.status < 300;
|
|
67
|
+
const statusOf = (r) => (r === null ? null : r.status);
|
|
68
|
+
/**
|
|
69
|
+
* @implements A-SPEC-792.48 (M1) — a 2xx whose body has the expected shape is a fact; a 404 is "absent" only where the
|
|
70
|
+
* caller says it means that; every other answer (403, 429, a timeout, a malformed body) is unknown.
|
|
71
|
+
*/
|
|
72
|
+
const triOf = (r, shape, present, absentOn404 = false) => ok(r) ? (shape(r.body) ? present(r.body) : 'unknown') : absentOn404 && statusOf(r) === 404 ? false : 'unknown';
|
|
73
|
+
/** @implements A-SPEC-792.48 (M2) — GitHub-hosted labels only. */
|
|
74
|
+
const HOSTED = /^(ubuntu|windows|macos)-[A-Za-z0-9._-]+$/;
|
|
75
|
+
function runnerOf(workflow) {
|
|
76
|
+
const labels = [];
|
|
77
|
+
for (const raw of workflow.split(/\r?\n/)) {
|
|
78
|
+
const line = raw.replace(/\s+#.*$/, '');
|
|
79
|
+
if (/^\s*#/.test(raw))
|
|
80
|
+
continue;
|
|
81
|
+
const m = /^\s*runs-on:\s*(.+?)\s*$/.exec(line);
|
|
82
|
+
if (!m)
|
|
83
|
+
continue;
|
|
84
|
+
const value = m[1];
|
|
85
|
+
labels.push(value.startsWith('[') ? value.replace(/^\[|\]$/g, '').split(',').map((s) => s.trim().replace(/^['"]|['"]$/g, '')) : [value.replace(/^['"]|['"]$/g, '')]);
|
|
86
|
+
}
|
|
87
|
+
if (labels.length === 0)
|
|
88
|
+
return 'unknown';
|
|
89
|
+
if (labels.some((ls) => ls.includes('self-hosted')))
|
|
90
|
+
return true;
|
|
91
|
+
return labels.every((ls) => ls.length === 1 && HOSTED.test(ls[0])) ? false : 'unknown';
|
|
92
|
+
}
|
|
93
|
+
/** @implements A-SPEC-792.48 (M4, low) — `origin`, or the only remote; the host must be exactly github.com. */
|
|
94
|
+
function githubRemote(deps) {
|
|
95
|
+
const names = (deps.git(['remote']) ?? '').split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
|
|
96
|
+
const name = names.includes('origin') ? 'origin' : names.length === 1 ? names[0] : null;
|
|
97
|
+
if (name === null)
|
|
98
|
+
return { skip: 'no-remote' };
|
|
99
|
+
const url = (deps.git(['remote', 'get-url', name]) ?? '').trim();
|
|
100
|
+
if (url === '')
|
|
101
|
+
return { skip: 'no-remote' };
|
|
102
|
+
const ssh = /^(?:[^@/\s]+@)?github\.com:([^/\s]+)\/([^/\s]+?)(?:\.git)?$/i.exec(url); // A-SPEC-792.49: host in any case
|
|
103
|
+
if (ssh)
|
|
104
|
+
return { owner: ssh[1], repo: ssh[2] };
|
|
105
|
+
try {
|
|
106
|
+
const u = new URL(url);
|
|
107
|
+
const parts = u.pathname.replace(/^\/+/, '').replace(/\.git$/, '').split('/');
|
|
108
|
+
if (u.hostname.toLowerCase() === 'github.com' && parts.length === 2 && parts[0] && parts[1])
|
|
109
|
+
return { owner: parts[0], repo: parts[1] };
|
|
110
|
+
}
|
|
111
|
+
catch { /* not a URL */ }
|
|
112
|
+
return { skip: 'unsupported' };
|
|
113
|
+
}
|
|
114
|
+
/** Facts for a governed target, a named skip where it cannot be read, or null where the diagnosis does not apply. */
|
|
115
|
+
function readForgeFacts(target, deps) {
|
|
116
|
+
if (!fs.existsSync(path.join(target, '.ax')))
|
|
117
|
+
return null;
|
|
118
|
+
const remote = githubRemote(deps);
|
|
119
|
+
if ('skip' in remote)
|
|
120
|
+
return remote;
|
|
121
|
+
const repo = `repos/${remote.owner}/${remote.repo}`;
|
|
122
|
+
const repoInfo = deps.api(repo);
|
|
123
|
+
const repoBody = ok(repoInfo) && isObj(repoInfo.body) ? repoInfo.body : null;
|
|
124
|
+
const repoId = repoBody && typeof repoBody.id === 'number' ? repoBody.id : null;
|
|
125
|
+
const admin = repoBody && isObj(repoBody.permissions) && typeof repoBody.permissions.admin === 'boolean'
|
|
126
|
+
? repoBody.permissions.admin : 'unknown';
|
|
127
|
+
const branch = repoBody && typeof repoBody.default_branch === 'string'
|
|
128
|
+
? repoBody.default_branch
|
|
129
|
+
: (deps.git(['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']) ?? 'origin/main').trim().replace(/^origin\//, '');
|
|
130
|
+
// A-SPEC-792.48 (low) — a file is absent only when the branch's commit reads and the file does not
|
|
131
|
+
const branchReadable = deps.git(['rev-parse', '--verify', '--quiet', `origin/${branch}^{commit}`]) !== null;
|
|
132
|
+
const show = (file) => (branchReadable ? deps.git(['show', `origin/${branch}:${file}`]) : null);
|
|
133
|
+
const configText = show('.github/holmes/admission.json');
|
|
134
|
+
const config = json(configText);
|
|
135
|
+
const appId = isObj(config) && typeof config.appId === 'number' ? config.appId : null;
|
|
136
|
+
const workflowText = show(exports.DETECTOR_WORKFLOW);
|
|
137
|
+
const pinRaw = json(show('.github/holmes/verifier.json'));
|
|
138
|
+
const pin = isObj(pinRaw) ? (typeof pinRaw.classifier === 'string' ? { classifier: pinRaw.classifier } : {}) : null;
|
|
139
|
+
const rules = deps.api(`${repo}/rules/branches/${encodeURIComponent(branch)}`);
|
|
140
|
+
const rulesRead = ok(rules) && Array.isArray(rules.body);
|
|
141
|
+
const ruleList = rulesRead ? rules.body.filter(isObj) : [];
|
|
142
|
+
const hasRule = (type) => (rulesRead ? ruleList.some((r) => r.type === type) : 'unknown');
|
|
143
|
+
// A-SPEC-792.48 (H1) — the pinned workflow must be the detector's, in this repository
|
|
144
|
+
const pinned = ruleList.filter((r) => r.type === 'workflows' && isObj(r.parameters) && Array.isArray(r.parameters.workflows))
|
|
145
|
+
.flatMap((r) => r.parameters.workflows.filter(isObj))
|
|
146
|
+
.find((w) => w.path === exports.DETECTOR_WORKFLOW && typeof w.sha === 'string' && repoId !== null && w.repository_id === repoId);
|
|
147
|
+
const env = deps.api(`${repo}/environments/${exports.DETECTOR_ENVIRONMENT}/deployment-branch-policies`);
|
|
148
|
+
const checkRuns = appId === null ? null : deps.api(`${repo}/commits/${encodeURIComponent(branch)}/check-runs?check_name=${exports.DETECTOR_CHECK}`);
|
|
149
|
+
const rate = deps.api('rate_limit');
|
|
150
|
+
const user = deps.api('user');
|
|
151
|
+
const scopesHeader = ok(user) ? Object.entries(user.headers).find(([k]) => k.toLowerCase() === 'x-oauth-scopes')?.[1] : undefined;
|
|
152
|
+
const present = (k) => typeof deps.env[k] === 'string' && deps.env[k] !== '';
|
|
153
|
+
return {
|
|
154
|
+
config: !branchReadable ? 'unknown' : configText === null ? false : appId !== null ? true : 'unknown',
|
|
155
|
+
appId,
|
|
156
|
+
workflow: !branchReadable ? 'unknown' : workflowText !== null,
|
|
157
|
+
selfHosted: workflowText === null ? 'unknown' : runnerOf(workflowText),
|
|
158
|
+
rulesets: rulesRead ? true : 'unknown',
|
|
159
|
+
prOnly: hasRule('pull_request'),
|
|
160
|
+
requiredWorkflow: !rulesRead || repoId === null ? 'unknown' : pinned ? { sha: String(pinned.sha) } : null,
|
|
161
|
+
nonFastForward: hasRule('non_fast_forward'),
|
|
162
|
+
deletion: hasRule('deletion'),
|
|
163
|
+
environment: triOf(env, (b) => isObj(b) && Array.isArray(b.branch_policies), (b) => b.branch_policies.length === 1 && isObj(b.branch_policies[0])
|
|
164
|
+
&& (b.branch_policies[0].name === branch), true),
|
|
165
|
+
// A-SPEC-792.49 — "missing" only when the configuration is absent; a broken one leaves the check run unknown
|
|
166
|
+
checkRun: appId === null ? (configText === null && branchReadable ? false : 'unknown')
|
|
167
|
+
: triOf(checkRuns, (b) => isObj(b) && Array.isArray(b.check_runs), (b) => b.check_runs.some((c) => isObj(c) && isObj(c.app) && c.app.id === appId)),
|
|
168
|
+
rateLimit: triOf(rate, (b) => isObj(b) && isObj(b.resources) && isObj(b.resources.core) && typeof b.resources.core.remaining === 'number', (b) => Number((b.resources.core.remaining)) > 0),
|
|
169
|
+
scopes: typeof scopesHeader === 'string' ? scopesHeader.split(',').map((s) => s.trim()).filter(Boolean) : 'unknown',
|
|
170
|
+
admin,
|
|
171
|
+
// presence only: no value is read into the facts
|
|
172
|
+
githubToken: present('GITHUB_TOKEN'), ghToken: present('GH_TOKEN'), ghEnterpriseToken: present('GH_ENTERPRISE_TOKEN'),
|
|
173
|
+
credentialHelper: (deps.git(['config', '--get-all', 'credential.helper']) ?? '').trim() !== ''
|
|
174
|
+
|| (deps.git(['config', '--get-all', 'credential.https://github.com.helper']) ?? '').trim() !== '',
|
|
175
|
+
pin,
|
|
176
|
+
installedVersion: deps.installedVersion,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const ADMIN_SCOPE = /^(admin:|delete_repo$|site_admin$)/;
|
|
180
|
+
const TAIL = 'The local checks (the spec seam, the push gate, the autonomous-shell provers) are early warning. App key copy: unverifiable — doctor has no way to rule out a local copy.';
|
|
181
|
+
const FIX = 'The owner creates the GitHub App, its environment holmes-admission and .github/holmes/admission.json; Holmes does not create them.';
|
|
182
|
+
const SKIP_DETAIL = {
|
|
183
|
+
'no-remote': 'no detector: no remote',
|
|
184
|
+
unsupported: 'no detector: unsupported forge (only github.com is read)',
|
|
185
|
+
};
|
|
186
|
+
/** @implements A-SPEC-792.48 (M4) — the line for a diagnosis that threw. */
|
|
187
|
+
function diagnosisFailedCheck() {
|
|
188
|
+
return { name: 'server detector', level: 'WARN', detail: `no detector: diagnosis failed (unknown). ${TAIL}` };
|
|
189
|
+
}
|
|
190
|
+
/** The diagnosis lines. Pure: the facts (or the skip) in, the lines out. */
|
|
191
|
+
function boundaryChecks(input) {
|
|
192
|
+
if ('skip' in input)
|
|
193
|
+
return [{ name: 'server detector', level: 'WARN', detail: `${SKIP_DETAIL[input.skip]}. ${TAIL}` }];
|
|
194
|
+
const f = input;
|
|
195
|
+
const out = [];
|
|
196
|
+
const conditions = [
|
|
197
|
+
['the configuration (.github/holmes/admission.json)', f.config],
|
|
198
|
+
[`the detector workflow (${exports.DETECTOR_WORKFLOW})`, f.workflow],
|
|
199
|
+
['rulesets on this plan', f.rulesets],
|
|
200
|
+
[`the environment ${exports.DETECTOR_ENVIRONMENT} limited to the default branch`, f.environment],
|
|
201
|
+
['a check run from the configured App', f.checkRun],
|
|
202
|
+
['rate limit left (quota)', f.rateLimit],
|
|
203
|
+
[f.selfHosted === true ? 'a hosted runner (the workflow uses a self-hosted label)' : 'a hosted runner (labels not recognised as GitHub-hosted)',
|
|
204
|
+
f.selfHosted === 'unknown' ? 'unknown' : !f.selfHosted],
|
|
205
|
+
];
|
|
206
|
+
const missing = conditions.filter(([, v]) => v === false).map(([n]) => n);
|
|
207
|
+
const unknown = conditions.filter(([, v]) => v === 'unknown').map(([n]) => n.replace(/ \(labels not recognised as GitHub-hosted\)$/, ''));
|
|
208
|
+
out.push(missing.length === 0 && unknown.length === 0
|
|
209
|
+
? { name: 'server detector', level: 'PASS', detail: `present, report-only — detection, not a boundary. ${TAIL}` }
|
|
210
|
+
: {
|
|
211
|
+
name: 'server detector', level: 'WARN',
|
|
212
|
+
detail: `no detector: ${[missing.length ? `missing ${missing.join(', ')}` : '', unknown.length ? `unknown ${unknown.join(', ')}` : ''].filter(Boolean).join('; ')}. ${TAIL}`,
|
|
213
|
+
fix: FIX,
|
|
214
|
+
});
|
|
215
|
+
const required = f.requiredWorkflow !== null && f.requiredWorkflow !== 'unknown' ? f.requiredWorkflow : null;
|
|
216
|
+
out.push(f.prOnly === true && required
|
|
217
|
+
? { name: 'detector definition', level: 'PASS', detail: `a pull-request rule and the detector as a required workflow pinned at ${required.sha} are present (bypass actors not read)` }
|
|
218
|
+
: {
|
|
219
|
+
name: 'detector definition', level: 'WARN',
|
|
220
|
+
detail: 'detector definition changeable; App key reachable from pushed definitions — '
|
|
221
|
+
+ `${f.prOnly === true ? '' : f.prOnly === 'unknown' ? 'pull-request-only rule unknown; ' : 'no pull-request-only rule; '}`
|
|
222
|
+
+ `${required ? '' : f.requiredWorkflow === 'unknown' ? 'required workflow unknown; ' : 'the detector is not a required workflow; '}`
|
|
223
|
+
+ 'write access is enough to change or cancel the detector and to post a report under its identity',
|
|
224
|
+
});
|
|
225
|
+
const history = [
|
|
226
|
+
f.nonFastForward === false ? 'force push allowed' : f.nonFastForward === 'unknown' ? 'force push rule unknown' : '',
|
|
227
|
+
f.deletion === false ? 'deletion allowed' : f.deletion === 'unknown' ? 'deletion rule unknown' : '',
|
|
228
|
+
].filter(Boolean);
|
|
229
|
+
out.push(history.length === 0
|
|
230
|
+
? { name: 'protected branch history', level: 'PASS', detail: 'force-push and deletion rules present on the default branch (bypass actors and classic branch protection not read)' }
|
|
231
|
+
: { name: 'protected branch history', level: 'WARN', detail: `${history.join('; ')} — the stateless detector judges a rewrite or a re-creation only as its report describes (${f.rulesets === true ? 'rulesets read' : 'rulesets not read'}; bypass actors and classic branch protection not read)` });
|
|
232
|
+
const adminScope = f.scopes !== 'unknown' && f.scopes.some((s) => ADMIN_SCOPE.test(s));
|
|
233
|
+
const sources = [
|
|
234
|
+
`gh token scopes: ${f.scopes === 'unknown' ? 'unknown' : f.scopes.length ? f.scopes.join(', ') : 'none'}`,
|
|
235
|
+
`repository admin permission: ${f.admin === 'unknown' ? 'unknown' : f.admin ? 'yes' : 'no'}`,
|
|
236
|
+
`GITHUB_TOKEN ${f.githubToken ? 'present' : 'absent'}`,
|
|
237
|
+
`GH_TOKEN ${f.ghToken ? 'present' : 'absent'}`,
|
|
238
|
+
`GH_ENTERPRISE_TOKEN ${f.ghEnterpriseToken ? 'present' : 'absent'}`,
|
|
239
|
+
`credential helper ${f.credentialHelper ? 'present' : 'absent'}`,
|
|
240
|
+
'other sources unverified',
|
|
241
|
+
].join('; ');
|
|
242
|
+
out.push(f.admin === true || adminScope
|
|
243
|
+
? { name: 'forge credentials', level: 'WARN', detail: `same-uid forge admin — ${sources}` }
|
|
244
|
+
// A-SPEC-792.48 (H2), A-SPEC-792.49 — PASS only when the admin permission was read as false and the scopes show no
|
|
245
|
+
// admin: a classic `repo` scope says nothing about an admin role
|
|
246
|
+
: f.admin !== false
|
|
247
|
+
? { name: 'forge credentials', level: 'WARN', detail: `admin status unknown — ${sources}` }
|
|
248
|
+
: { name: 'forge credentials', level: 'PASS', detail: `checked: ${sources}` });
|
|
249
|
+
if (f.pin !== null) {
|
|
250
|
+
out.push(f.pin.classifier === undefined
|
|
251
|
+
? { name: 'verifier version', level: 'WARN', detail: `the verifier pin has no classifier field; installed Holmes ${f.installedVersion}` }
|
|
252
|
+
: f.pin.classifier === f.installedVersion
|
|
253
|
+
? { name: 'verifier version', level: 'PASS', detail: `the verifier pin's classifier ${f.pin.classifier} matches the installed Holmes` }
|
|
254
|
+
: { name: 'verifier version', level: 'WARN', detail: `the verifier pin's classifier is ${f.pin.classifier}, installed Holmes is ${f.installedVersion}` });
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The real reader: `gh api -i`, each call bounded and all of them under one budget; after the first timeout or once the
|
|
260
|
+
* budget is spent, every further call is unknown without spawning (A-SPEC-792.48 M6). Git runs through the shared
|
|
261
|
+
* sanitised environment.
|
|
262
|
+
*/
|
|
263
|
+
function realForgeDeps(target, installedVersion, spawn = node_child_process_1.spawnSync, now = Date.now) {
|
|
264
|
+
const { gitOnce } = require('../project/bounded-io');
|
|
265
|
+
const deadline = now() + exports.FORGE_BUDGET_MS;
|
|
266
|
+
let stopped = false;
|
|
267
|
+
return {
|
|
268
|
+
api: (apiPath) => {
|
|
269
|
+
const left = deadline - now();
|
|
270
|
+
if (stopped || left <= 0)
|
|
271
|
+
return null;
|
|
272
|
+
// gh runs in the environment the token lines report on, so a GH_TOKEN named present is the one gh reads
|
|
273
|
+
const r = spawn('gh', ['api', '-i', apiPath], { encoding: 'utf8', timeout: Math.min(exports.API_TIMEOUT_MS, left), stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true, env: process.env });
|
|
274
|
+
if (r.error) {
|
|
275
|
+
if (r.error.code === 'ETIMEDOUT')
|
|
276
|
+
stopped = true;
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
if (typeof r.stdout !== 'string' || r.stdout === '')
|
|
280
|
+
return null;
|
|
281
|
+
const [head, ...rest] = r.stdout.split(/\r?\n\r?\n/);
|
|
282
|
+
const lines = head.split(/\r?\n/);
|
|
283
|
+
const status = Number(/^HTTP\/[\d.]+\s+(\d{3})/.exec(lines[0] ?? '')?.[1]);
|
|
284
|
+
if (!Number.isFinite(status))
|
|
285
|
+
return null;
|
|
286
|
+
const headers = {};
|
|
287
|
+
for (const l of lines.slice(1)) {
|
|
288
|
+
const i = l.indexOf(':');
|
|
289
|
+
if (i > 0)
|
|
290
|
+
headers[l.slice(0, i).trim()] = l.slice(i + 1).trim();
|
|
291
|
+
}
|
|
292
|
+
let body = null;
|
|
293
|
+
try {
|
|
294
|
+
body = JSON.parse(rest.join('\n\n'));
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
body = null;
|
|
298
|
+
}
|
|
299
|
+
return { status, headers, body };
|
|
300
|
+
},
|
|
301
|
+
git: (args) => {
|
|
302
|
+
const r = gitOnce(target, args, 'repo', { cwd: target });
|
|
303
|
+
return r.status === 0 && typeof r.stdout === 'string' ? r.stdout : null;
|
|
304
|
+
},
|
|
305
|
+
env: process.env,
|
|
306
|
+
installedVersion,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Check } from './doctor-check';
|
|
2
|
+
/** The paths that must never be synchronised: a lock or claim copied to another clone would hold or recover there. */
|
|
3
|
+
export declare const SPEND_LOCK_PATHS: string[];
|
|
4
|
+
export interface LockCheckDeps {
|
|
5
|
+
/** Which of `paths` git does not ignore; null when this is not a git working tree or git cannot answer. */
|
|
6
|
+
notIgnored: (root: string, paths: string[]) => string[] | null;
|
|
7
|
+
hostId: () => string | null;
|
|
8
|
+
now: () => number;
|
|
9
|
+
}
|
|
10
|
+
export declare function spendLockChecks(root: string, deps?: LockCheckDeps): Check[];
|
|
11
|
+
/**
|
|
12
|
+
* A-SPEC-794.6: one WARN per held request lock, with its age, and the operator's route once it is held longer than 4x
|
|
13
|
+
* its bound. Nothing is printed when no request lock is held.
|
|
14
|
+
*/
|
|
15
|
+
export declare function requestLockChecks(root: string, now?: () => number): Check[];
|