@holmes-lab/holmes-kit 0.39.0 → 0.40.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +578 -6
- package/README.md +120 -41
- package/dist/.build-id +1 -1
- package/dist/holmes/admission/core/admission-policy.d.ts +37 -0
- package/dist/holmes/admission/core/admission-policy.js +147 -0
- package/dist/holmes/admission/core/bounded-reader.d.ts +56 -0
- package/dist/holmes/admission/core/bounded-reader.js +135 -0
- package/dist/holmes/admission/core/change-classifier.d.ts +34 -0
- package/dist/holmes/admission/core/change-classifier.js +278 -0
- package/dist/holmes/admission/core/config-loader.d.ts +30 -0
- package/dist/holmes/admission/core/config-loader.js +145 -0
- package/dist/holmes/admission/core/event-judgement.d.ts +37 -0
- package/dist/holmes/admission/core/event-judgement.js +251 -0
- package/dist/holmes/admission/core/path-rules.d.ts +35 -0
- package/dist/holmes/admission/core/path-rules.js +88 -0
- package/dist/holmes/admission/core/pin.d.ts +7 -0
- package/dist/holmes/admission/core/pin.js +29 -0
- package/dist/holmes/admission/core/ports.d.ts +48 -0
- package/dist/holmes/admission/core/ports.js +11 -0
- package/dist/holmes/admission/core/range-resolver.d.ts +32 -0
- package/dist/holmes/admission/core/range-resolver.js +51 -0
- package/dist/holmes/admission/core/self-containment.d.ts +1 -0
- package/dist/holmes/admission/core/self-containment.js +125 -0
- package/dist/holmes/admission/core/signature-source.d.ts +9 -0
- package/dist/holmes/admission/core/signature-source.js +4 -0
- package/dist/holmes/admission/core/transition-planner.d.ts +15 -0
- package/dist/holmes/admission/core/transition-planner.js +14 -0
- package/dist/holmes/admission/core/verdict.d.ts +38 -0
- package/dist/holmes/admission/core/verdict.js +17 -0
- package/dist/holmes/admission/core/wiring.d.ts +44 -0
- package/dist/holmes/admission/core/wiring.js +618 -0
- package/dist/holmes/admission/forge/git-object-port.d.ts +4 -0
- package/dist/holmes/admission/forge/git-object-port.js +132 -0
- package/dist/holmes/assoc/assoc-arm.d.ts +1 -1
- package/dist/holmes/assoc/assoc-arm.js +1 -1
- package/dist/holmes/cli/agents.d.ts +8 -0
- package/dist/holmes/cli/agents.js +9 -5
- package/dist/holmes/cli/approve-cli.d.ts +2 -0
- package/dist/holmes/cli/approve-cli.js +392 -0
- package/dist/holmes/cli/approve-ref.d.ts +13 -7
- package/dist/holmes/cli/approve-ref.js +30 -10
- package/dist/holmes/cli/approve-status.d.ts +26 -2
- package/dist/holmes/cli/approve-status.js +98 -18
- package/dist/holmes/cli/approve-watch.d.ts +5 -0
- package/dist/holmes/cli/approve-watch.js +10 -5
- package/dist/holmes/cli/approve.d.ts +49 -13
- package/dist/holmes/cli/approve.js +249 -67
- package/dist/holmes/cli/attest.js +2 -1
- package/dist/holmes/cli/autonomy.d.ts +4 -1
- package/dist/holmes/cli/autonomy.js +17 -10
- package/dist/holmes/cli/codex-oracle.d.ts +11 -0
- package/dist/holmes/cli/codex-oracle.js +5 -1
- package/dist/holmes/cli/codex-toml.d.ts +10 -0
- package/dist/holmes/cli/codex-toml.js +36 -2
- package/dist/holmes/cli/doctor-boundary.d.ts +76 -0
- package/dist/holmes/cli/doctor-boundary.js +308 -0
- package/dist/holmes/cli/doctor-locks.d.ts +15 -0
- package/dist/holmes/cli/doctor-locks.js +119 -0
- package/dist/holmes/cli/doctor.d.ts +2 -0
- package/dist/holmes/cli/doctor.js +34 -5
- package/dist/holmes/cli/flags.d.ts +23 -0
- package/dist/holmes/cli/flags.js +89 -0
- package/dist/holmes/cli/index.d.ts +5 -1
- package/dist/holmes/cli/index.js +226 -442
- package/dist/holmes/cli/init.js +33 -0
- package/dist/holmes/cli/interactive-prompt.d.ts +39 -2
- package/dist/holmes/cli/interactive-prompt.js +98 -16
- package/dist/holmes/cli/lock-recover.d.ts +5 -0
- package/dist/holmes/cli/lock-recover.js +126 -0
- package/dist/holmes/cli/mcp-processes.js +1 -1
- package/dist/holmes/cli/release-docs.js +1 -1
- package/dist/holmes/cli/run-exec.d.ts +141 -0
- package/dist/holmes/cli/run-exec.js +1435 -0
- package/dist/holmes/cli/run-provision.d.ts +3 -1
- package/dist/holmes/cli/run-provision.js +255 -44
- package/dist/holmes/cli/run-wiring.d.ts +69 -0
- package/dist/holmes/cli/run-wiring.js +270 -0
- package/dist/holmes/cli/run.d.ts +21 -0
- package/dist/holmes/cli/run.js +341 -92
- package/dist/holmes/cli/runtime-binding-approval.js +32 -19
- package/dist/holmes/cli/screen-safe.d.ts +3 -92
- package/dist/holmes/cli/screen-safe.js +18 -756
- package/dist/holmes/config/config.d.ts +19 -0
- package/dist/holmes/config/config.js +18 -3
- package/dist/holmes/cpg/foundation/language-matrix.js +2 -2
- package/dist/holmes/cpg/import-resolver.js +1 -1
- package/dist/holmes/governance/approval-decisions.d.ts +47 -0
- package/dist/holmes/governance/approval-decisions.js +29 -0
- package/dist/holmes/governance/approval-grants.d.ts +220 -1
- package/dist/holmes/governance/approval-grants.js +612 -33
- package/dist/holmes/governance/approval-queue.d.ts +26 -0
- package/dist/holmes/governance/approval-queue.js +109 -11
- package/dist/holmes/governance/approval-spend.d.ts +95 -0
- package/dist/holmes/governance/approval-spend.js +191 -0
- package/dist/holmes/governance/autonomous-shell.d.ts +61 -0
- package/dist/holmes/governance/autonomous-shell.js +332 -0
- package/dist/holmes/governance/autonomy.d.ts +12 -0
- package/dist/holmes/governance/autonomy.js +51 -15
- package/dist/holmes/governance/constitution.d.ts +5 -0
- package/dist/holmes/governance/constitution.js +32 -12
- package/dist/holmes/governance/full-autonomy.d.ts +10 -0
- package/dist/holmes/governance/full-autonomy.js +103 -7
- package/dist/holmes/governance/harness-catalog.d.ts +103 -0
- package/dist/holmes/governance/harness-catalog.js +348 -0
- package/dist/holmes/governance/human-channel.d.ts +38 -0
- package/dist/holmes/governance/human-channel.js +49 -0
- package/dist/holmes/governance/install-manifest.d.ts +22 -0
- package/dist/holmes/governance/install-manifest.js +160 -0
- package/dist/holmes/governance/ledger-rechain.js +2 -0
- package/dist/holmes/governance/ledger-store.conformance.d.ts +7 -1
- package/dist/holmes/governance/ledger-store.conformance.js +66 -0
- package/dist/holmes/governance/ledger-store.d.ts +88 -11
- package/dist/holmes/governance/ledger-store.js +186 -8
- package/dist/holmes/governance/provenance-chain.d.ts +16 -4
- package/dist/holmes/governance/provenance-chain.js +19 -4
- package/dist/holmes/governance/provenance-ledger.d.ts +6 -3
- package/dist/holmes/governance/provenance-ledger.js +53 -18
- package/dist/holmes/governance/push-gate-runner.d.ts +2 -0
- package/dist/holmes/governance/push-gate-runner.js +50 -9
- package/dist/holmes/governance/push-gate.d.ts +13 -2
- package/dist/holmes/governance/push-gate.js +106 -14
- package/dist/holmes/governance/recorded-pairs.d.ts +96 -0
- package/dist/holmes/governance/recorded-pairs.js +522 -0
- package/dist/holmes/governance/replica-id.d.ts +1 -1
- package/dist/holmes/governance/replica-id.js +1 -1
- package/dist/holmes/governance/spec-seam.d.ts +59 -0
- package/dist/holmes/governance/spec-seam.js +587 -0
- package/dist/holmes/governance/spend-kinds.d.ts +16 -0
- package/dist/holmes/governance/spend-kinds.js +18 -0
- package/dist/holmes/guardrail/advisory-line.d.ts +102 -0
- package/dist/holmes/guardrail/advisory-line.js +718 -0
- package/dist/holmes/guardrail/decision-ledger.d.ts +2 -1
- package/dist/holmes/guardrail/decision-ledger.js +2 -1
- package/dist/holmes/guardrail/impact-gate.d.ts +7 -0
- package/dist/holmes/guardrail/impact-gate.js +33 -6
- package/dist/holmes/guardrail/line-continuation.d.ts +8 -0
- package/dist/holmes/guardrail/line-continuation.js +39 -0
- package/dist/holmes/guardrail/operator-person.d.ts +28 -4
- package/dist/holmes/guardrail/operator-person.js +57 -11
- package/dist/holmes/guardrail/refusal-codes.d.ts +8 -3
- package/dist/holmes/guardrail/refusal-codes.js +64 -10
- package/dist/holmes/guardrail/risk-classifier.d.ts +15 -9
- package/dist/holmes/guardrail/risk-classifier.js +228 -16
- package/dist/holmes/guardrail/risk-gate.d.ts +2 -8
- package/dist/holmes/guardrail/risk-gate.js +7 -34
- package/dist/holmes/guardrail/risk-types.d.ts +10 -0
- package/dist/holmes/guardrail/run-plan-scope.js +3 -1
- package/dist/holmes/guardrail/run-refusals.js +24 -8
- package/dist/holmes/guardrail/run-stages.d.ts +5 -0
- package/dist/holmes/guardrail/run-stages.js +25 -5
- package/dist/holmes/guardrail/scope-judgment.js +1 -1
- package/dist/holmes/guardrail/shell-words.js +24 -3
- package/dist/holmes/guardrail/unresolved-write.d.ts +40 -0
- package/dist/holmes/guardrail/unresolved-write.js +556 -0
- package/dist/holmes/guardrail/write-target.d.ts +3 -0
- package/dist/holmes/guardrail/write-target.js +26 -5
- package/dist/holmes/hooks/pre-tool-use.d.ts +116 -1
- package/dist/holmes/hooks/pre-tool-use.js +1176 -170
- package/dist/holmes/hooks/rtm-refresh-child.d.ts +1 -1
- package/dist/holmes/hooks/rtm-refresh-child.js +1 -1
- package/dist/holmes/hooks/session-start.js +17 -1
- package/dist/holmes/hooks/stop.d.ts +23 -0
- package/dist/holmes/hooks/stop.js +86 -33
- package/dist/holmes/mcp/approval-adapters.js +3 -1
- package/dist/holmes/mcp/approval-commit.js +3 -2
- package/dist/holmes/mcp/approval-policy.d.ts +2 -1
- package/dist/holmes/mcp/approval-policy.js +3 -1
- package/dist/holmes/mcp/handlers/adoption.d.ts +1 -1
- package/dist/holmes/mcp/handlers/approval-ask.d.ts +3 -0
- package/dist/holmes/mcp/handlers/approval-ask.js +18 -7
- package/dist/holmes/mcp/handlers/entity-integration.d.ts +3 -3
- package/dist/holmes/mcp/handlers/entity-integration.js +29 -11
- package/dist/holmes/mcp/handlers/entity-renumber.d.ts +4 -4
- package/dist/holmes/mcp/handlers/entity-renumber.js +29 -11
- package/dist/holmes/mcp/handlers/entity-store.d.ts +2 -2
- package/dist/holmes/mcp/handlers/entity-store.js +133 -59
- package/dist/holmes/mcp/handlers/maintenance-analysis.d.ts +13 -0
- package/dist/holmes/mcp/handlers/maintenance-analysis.js +59 -2
- package/dist/holmes/mcp/handlers/operator-inspection.d.ts +9 -5
- package/dist/holmes/mcp/handlers/operator-inspection.js +79 -16
- package/dist/holmes/mcp/handlers/phase-queries.d.ts +1 -1
- package/dist/holmes/mcp/handlers/requirement-triage.d.ts +4 -4
- package/dist/holmes/mcp/handlers/review-evidence.d.ts +2 -2
- package/dist/holmes/mcp/handlers/review-evidence.js +35 -11
- package/dist/holmes/mcp/handlers/review-queries.d.ts +5 -0
- package/dist/holmes/mcp/handlers/review-queries.js +8 -1
- package/dist/holmes/mcp/handlers/review-verdict.d.ts +3 -0
- package/dist/holmes/mcp/handlers/review-verdict.js +10 -3
- package/dist/holmes/mcp/handlers/risk-assessment.d.ts +7 -2
- package/dist/holmes/mcp/handlers/risk-assessment.js +34 -12
- package/dist/holmes/mcp/handlers/runtime-binding-tool.d.ts +2 -2
- package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +6 -1
- package/dist/holmes/mcp/handlers/slice-orchestration.js +14 -1
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +15 -3
- package/dist/holmes/mcp/handlers/spec-approval.js +32 -5
- package/dist/holmes/mcp/handlers/spec-authoring.d.ts +2 -2
- package/dist/holmes/mcp/handlers/spec-authoring.js +19 -2
- package/dist/holmes/mcp/handlers/spec-lifecycle.d.ts +11 -38
- package/dist/holmes/mcp/handlers/spec-lifecycle.js +441 -94
- package/dist/holmes/mcp/handlers/spec-queries.d.ts +2 -2
- package/dist/holmes/mcp/handlers/taint-screening.d.ts +1 -1
- package/dist/holmes/mcp/handlers/taint-screening.js +2 -2
- package/dist/holmes/mcp/handlers/test-execution.d.ts +471 -4
- package/dist/holmes/mcp/handlers/test-execution.js +199 -21
- package/dist/holmes/mcp/handlers/workspace-queries.d.ts +2 -2
- package/dist/holmes/mcp/handlers.d.ts +557 -82
- package/dist/holmes/mcp/handlers.js +74 -23
- package/dist/holmes/mcp/harness-attestation.d.ts +78 -5
- package/dist/holmes/mcp/harness-attestation.js +325 -53
- package/dist/holmes/mcp/maintenance-analyze.d.ts +6 -1
- package/dist/holmes/mcp/maintenance-analyze.js +13 -11
- package/dist/holmes/mcp/maintenance-evidence.d.ts +9 -0
- package/dist/holmes/mcp/maintenance-evidence.js +35 -3
- package/dist/holmes/mcp/requirement-triage-evidence.js +22 -13
- package/dist/holmes/mcp/server-staleness.js +1 -1
- package/dist/holmes/mcp/server.js +9 -8
- package/dist/holmes/mcp/spec-id-guard.js +1 -1
- package/dist/holmes/mcp/tool-schemas.d.ts +13 -0
- package/dist/holmes/mcp/tool-schemas.js +42 -9
- package/dist/holmes/project/act-root.d.ts +19 -0
- package/dist/holmes/project/act-root.js +100 -0
- package/dist/holmes/project/baseline.d.ts +15 -2
- package/dist/holmes/project/baseline.js +14 -8
- package/dist/holmes/project/bounded-group.d.ts +47 -0
- package/dist/holmes/project/bounded-group.js +140 -0
- package/dist/holmes/project/bounded-io.d.ts +51 -2
- package/dist/holmes/project/bounded-io.js +140 -6
- package/dist/holmes/project/change-source.d.ts +4 -0
- package/dist/holmes/project/change-source.js +14 -6
- package/dist/holmes/project/instance-id.d.ts +10 -0
- package/dist/holmes/project/instance-id.js +233 -0
- package/dist/holmes/project/machine-identity.d.ts +25 -0
- package/dist/holmes/project/machine-identity.js +133 -0
- package/dist/holmes/project/owned-lock.d.ts +84 -0
- package/dist/holmes/project/owned-lock.js +263 -0
- package/dist/holmes/project/plain-lock-fs.d.ts +2 -0
- package/dist/holmes/project/plain-lock-fs.js +126 -0
- package/dist/holmes/project/request-lock.d.ts +85 -0
- package/dist/holmes/project/request-lock.js +459 -0
- package/dist/holmes/project/root.d.ts +12 -4
- package/dist/holmes/project/root.js +29 -8
- package/dist/holmes/project/run-records.d.ts +19 -0
- package/dist/holmes/project/run-records.js +94 -12
- package/dist/holmes/project/screen-text.d.ts +94 -0
- package/dist/holmes/project/screen-text.js +763 -0
- package/dist/holmes/project/spend-lock.d.ts +82 -0
- package/dist/holmes/project/spend-lock.js +413 -0
- package/dist/holmes/refresh/freshness-coordinator.d.ts +1 -1
- package/dist/holmes/refresh/freshness-coordinator.js +1 -1
- package/dist/holmes/review/condition-hunk-replay.js +4 -2
- package/dist/holmes/review/confidence-calibration.d.ts +1 -1
- package/dist/holmes/review/confidence-calibration.js +1 -1
- package/dist/holmes/review/content-verify.js +1 -1
- package/dist/holmes/review/evidence-mode.d.ts +21 -0
- package/dist/holmes/review/evidence-mode.js +33 -0
- package/dist/holmes/review/head-worktree.d.ts +55 -0
- package/dist/holmes/review/head-worktree.js +329 -0
- package/dist/holmes/review/hop-ablation.d.ts +4 -4
- package/dist/holmes/review/hop-ablation.js +5 -5
- package/dist/holmes/review/mrp.js +13 -3
- package/dist/holmes/review/point-in-time-replay.js +12 -3
- package/dist/holmes/review/rank-diagnosis.d.ts +2 -2
- package/dist/holmes/review/rank-diagnosis.js +1 -1
- package/dist/holmes/review/replay-corpus.d.ts +10 -4
- package/dist/holmes/review/replay-corpus.js +25 -9
- package/dist/holmes/review/requirement-triage.js +2 -2
- package/dist/holmes/review/run-provenance.d.ts +45 -0
- package/dist/holmes/review/run-provenance.js +314 -0
- package/dist/holmes/review/semantic-arm.d.ts +3 -3
- package/dist/holmes/review/semantic-arm.js +3 -3
- package/dist/holmes/review/test-evidence.d.ts +174 -0
- package/dist/holmes/review/test-evidence.js +330 -2
- package/dist/holmes/review/test-outcomes.js +3 -1
- package/dist/holmes/review/test-reports.d.ts +94 -0
- package/dist/holmes/review/test-reports.js +382 -0
- package/dist/holmes/review/test-runner.d.ts +180 -58
- package/dist/holmes/review/test-runner.js +560 -324
- package/dist/holmes/review/test-selection-breadth.js +2 -2
- package/dist/holmes/review/test-units.d.ts +159 -0
- package/dist/holmes/review/test-units.js +814 -0
- package/dist/holmes/review/verdicts.d.ts +105 -8
- package/dist/holmes/review/verdicts.js +640 -36
- package/dist/holmes/rtm/anchor-census.d.ts +9 -0
- package/dist/holmes/rtm/anchor-census.js +151 -0
- package/dist/holmes/rtm/anchor-ids.d.ts +25 -1
- package/dist/holmes/rtm/anchor-ids.js +45 -2
- package/dist/holmes/rtm/comment-ranges.d.ts +2 -0
- package/dist/holmes/rtm/comment-ranges.js +104 -0
- package/dist/holmes/rtm/counted-tests.d.ts +1 -0
- package/dist/holmes/rtm/counted-tests.js +63 -0
- package/dist/holmes/rtm/impact-advisory.d.ts +1 -1
- package/dist/holmes/rtm/known-defects.js +1 -1
- package/dist/holmes/rtm/localize.js +1 -1
- package/dist/holmes/rtm/taint-benchmark.d.ts +1 -1
- package/dist/holmes/rtm/taint-vocabulary.d.ts +1 -1
- package/dist/holmes/rtm/test-scope.d.ts +31 -0
- package/dist/holmes/rtm/test-scope.js +166 -5
- package/dist/holmes/rtm/trace-gaps.js +1 -1
- package/dist/holmes/runtime/dispatch.d.ts +10 -0
- package/dist/holmes/runtime/dispatch.js +12 -1
- package/dist/holmes/semantic/cloud-usage.d.ts +1 -1
- package/dist/holmes/semantic/cloud-usage.js +1 -1
- package/dist/holmes/semantic/unreadable-paths.d.ts +1 -1
- package/dist/holmes/semantic/unreadable-paths.js +1 -1
- package/dist/holmes/spec/approval-blockers.js +1 -1
- package/dist/holmes/spec/entity-store.d.ts +6 -1
- package/dist/holmes/spec/entity-store.js +16 -2
- package/dist/holmes/spec/entity-transaction.d.ts +7 -2
- package/dist/holmes/spec/entity-transaction.js +87 -170
- package/dist/holmes/spec/spec-store.d.ts +12 -6
- package/dist/holmes/spec/spec-store.js +4 -2
- package/dist/holmes/spec/spec-types.js +1 -1
- package/dist/holmes/spec/succession-guard.d.ts +56 -0
- package/dist/holmes/spec/succession-guard.js +187 -0
- package/dist/holmes/spec/succession.d.ts +70 -0
- package/dist/holmes/spec/succession.js +171 -0
- package/dist/holmes/spec/transition-policy.d.ts +2 -2
- package/docs/install-guide.md +9 -3
- package/docs/language-support.md +78 -0
- package/package.json +4 -3
- package/playbooks/author-slice/PLAYBOOK.md +1 -1
- package/playbooks/promote-slice/PLAYBOOK.md +5 -1
- package/playbooks/publish/PLAYBOOK.md +47 -34
- package/dist/holmes/review/manual-baseline.d.ts +0 -209
- package/dist/holmes/review/manual-baseline.js +0 -2847
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validPackagePath = validPackagePath;
|
|
4
|
+
exports.canonicalHookCommand = canonicalHookCommand;
|
|
5
|
+
exports.tomlKeys = tomlKeys;
|
|
6
|
+
exports.tomlRead = tomlRead;
|
|
7
|
+
exports.tomlStructureBreach = tomlStructureBreach;
|
|
8
|
+
exports.canonicalWiring = canonicalWiring;
|
|
9
|
+
// @implements A-SPEC-792.50
|
|
10
|
+
/**
|
|
11
|
+
* The canonical harness wiring (A-SPEC-792.50; the thirteenth review's decision, written as a closed grammar because
|
|
12
|
+
* `init` writes each install's absolute path). The wiring is never interpreted: no path, expansion or shell word is
|
|
13
|
+
* resolved. A file is canonical or it names its breach.
|
|
14
|
+
*
|
|
15
|
+
* - "Names holmes" is matched without case, anywhere in a key, a command, an argument, an environment key or value.
|
|
16
|
+
* - A hook command that names holmes is exactly `node "<P>/dist/holmes/hooks/<name>.js"`.
|
|
17
|
+
* - An MCP entry that names holmes has `command: node`, one allowed argument, an environment within the allowed keys
|
|
18
|
+
* and values, and no other key.
|
|
19
|
+
* - Every environment map, anywhere, holds no `HOLMES_*` key outside a canonical holmes MCP entry, and no
|
|
20
|
+
* `CLAUDE_PROJECT_DIR` key at all; no string assigns either.
|
|
21
|
+
* - `.codex/config.toml` is read twice (review A-C1): by lines, with `\u`/`\U` escapes, quoted keys and quoted table
|
|
22
|
+
* headers refused outright; then by a small TOML key tokenizer kept here in core (no parser is on the core's import
|
|
23
|
+
* whitelist), whose key paths may name holmes only inside the canonical holmes block.
|
|
24
|
+
* - Other files under the wiring prefixes (`.holmes/codex-plugin/**`, `.agents/plugins/**`) that are not JSON are
|
|
25
|
+
* non-canonical when they name `HOLMES_` or `CLAUDE_PROJECT_DIR`.
|
|
26
|
+
*/
|
|
27
|
+
const config_loader_1 = require("./config-loader");
|
|
28
|
+
const path_rules_1 = require("./path-rules");
|
|
29
|
+
/**
|
|
30
|
+
* "Names holmes" is judged on the folded text (review 11:19 M-1): APFS opens `holmeſ` as `holmes`, which `/holmes/i`
|
|
31
|
+
* missed. A function, not an object dressed as a RegExp (review 12:32 design).
|
|
32
|
+
*/
|
|
33
|
+
function namesHolmes(s) { return (0, path_rules_1.fold)(textOf(s)).includes('holmes'); }
|
|
34
|
+
/**
|
|
35
|
+
* @implements A-SPEC-792.50 (review 00:3x L1) — a parsed value as text, without `String()`: the strict parser builds
|
|
36
|
+
* objects with no prototype, and `String()` of one threw a TypeError, so the judgement closed with "the grammar threw"
|
|
37
|
+
* instead of naming the breach. An object is read as its JSON text; a holmes-named entry is then judged by its grammar.
|
|
38
|
+
*/
|
|
39
|
+
function textOf(v) {
|
|
40
|
+
if (typeof v === 'string')
|
|
41
|
+
return v;
|
|
42
|
+
if (typeof v === 'object' && v !== null)
|
|
43
|
+
return JSON.stringify(v) ?? '';
|
|
44
|
+
return String(v);
|
|
45
|
+
}
|
|
46
|
+
/** The canonical wiring's deepest key path is 5 segments and its deepest JSON 5 levels: past these bounds is not canonical. */
|
|
47
|
+
const MAX_KEY_SEGMENTS = 8;
|
|
48
|
+
const MAX_JSON_DEPTH = 64;
|
|
49
|
+
/** An own key of a fixed table (review 11:19 H2): `toString` and `__proto__` are not keys of ENV_VALUES. */
|
|
50
|
+
const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
51
|
+
const P_CHARS = /^[A-Za-z0-9/\\:._@+ -]+$/;
|
|
52
|
+
const HOOK = /^node "(.+)[\\/]dist[\\/]holmes[\\/]hooks[\\/](pre-tool-use|stop|session-start)\.js"$/;
|
|
53
|
+
const ENV_VALUES = {
|
|
54
|
+
HOLMES_SPECS: ['.ax/specs'], HOLMES_MCP_AUTORELOAD: ['0', '1'], HOLMES_AUTONOMOUS_APPROVAL: ['0', '1'],
|
|
55
|
+
};
|
|
56
|
+
const ENV_ORDER = ['HOLMES_SPECS', 'HOLMES_MCP_AUTORELOAD', 'HOLMES_AUTONOMOUS_APPROVAL'];
|
|
57
|
+
const MARKETPLACE_ENTRY = JSON.stringify({ name: 'holmes-kit', source: { source: 'local', path: './.holmes/codex-plugin/holmes-kit' },
|
|
58
|
+
policy: { installation: 'AVAILABLE', authentication: 'ON_INSTALL' }, category: 'Developer Tools' });
|
|
59
|
+
/** The package path: absolute, ending in @holmes-lab/holmes-kit, no special character, no `..` segment. */
|
|
60
|
+
function validPackagePath(p) {
|
|
61
|
+
return P_CHARS.test(p) && (p.startsWith('/') || /^[A-Za-z]:\\/.test(p))
|
|
62
|
+
&& (p.endsWith('/@holmes-lab/holmes-kit') || p.endsWith('\\@holmes-lab\\holmes-kit'))
|
|
63
|
+
&& !p.split(/[\\/]/).includes('..');
|
|
64
|
+
}
|
|
65
|
+
function canonicalHookCommand(command) {
|
|
66
|
+
const m = HOOK.exec(command);
|
|
67
|
+
return m !== null && validPackagePath(m[1]);
|
|
68
|
+
}
|
|
69
|
+
function allowedMcpArg(arg, ctx) {
|
|
70
|
+
if (typeof arg !== 'string')
|
|
71
|
+
return false;
|
|
72
|
+
if (arg === 'bin/holmes-mcp.js')
|
|
73
|
+
return ctx.devForm;
|
|
74
|
+
const m = /^(.+)[\\/](?:dist[\\/]holmes[\\/]mcp[\\/]server|bin[\\/]holmes-mcp)\.js$/.exec(arg);
|
|
75
|
+
return m !== null && validPackagePath(m[1]);
|
|
76
|
+
}
|
|
77
|
+
const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
78
|
+
/** A holmes MCP entry's own breach, or null when it is canonical. */
|
|
79
|
+
function mcpEntryBreach(name, entry, ctx) {
|
|
80
|
+
if (!isObject(entry))
|
|
81
|
+
return `MCP entry ${name} is not an object`;
|
|
82
|
+
const extra = Object.keys(entry).filter((k) => !['command', 'args', 'env', 'type'].includes(k));
|
|
83
|
+
if (extra.length > 0)
|
|
84
|
+
return `MCP entry ${name} has ${extra.join(', ')}`;
|
|
85
|
+
if (entry.type !== undefined && entry.type !== 'stdio')
|
|
86
|
+
return `MCP entry ${name} has type ${textOf(entry.type)}`;
|
|
87
|
+
if (entry.command !== 'node')
|
|
88
|
+
return `MCP entry ${name} does not run node`;
|
|
89
|
+
if (!Array.isArray(entry.args) || entry.args.length !== 1 || !allowedMcpArg(entry.args[0], ctx))
|
|
90
|
+
return `MCP entry ${name} has arguments outside the grammar`;
|
|
91
|
+
if (entry.env !== undefined) {
|
|
92
|
+
if (!isObject(entry.env))
|
|
93
|
+
return `MCP entry ${name} has an env that is not a map`;
|
|
94
|
+
for (const [k, v] of Object.entries(entry.env)) {
|
|
95
|
+
if (!hasOwn(ENV_VALUES, k) || typeof v !== 'string' || !ENV_VALUES[k].includes(v))
|
|
96
|
+
return `MCP entry ${name} sets ${k}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Walk a JSON document: environment keys anywhere, assignments in strings, and every `command` that names holmes.
|
|
103
|
+
* @implements A-SPEC-792.50 (review 12:32 N2) — by an explicit stack, in the order the recursion visited, and past
|
|
104
|
+
* MAX_JSON_DEPTH levels a breach: objects nested below the parser's own limit overflowed the recursive walk.
|
|
105
|
+
*/
|
|
106
|
+
function walkBreach(doc, holmesEnvAt) {
|
|
107
|
+
const pathOf = (c) => {
|
|
108
|
+
const out = [];
|
|
109
|
+
for (let x = c; x !== undefined && x.key !== undefined; x = x.parent)
|
|
110
|
+
out.push(x.key);
|
|
111
|
+
return out.reverse();
|
|
112
|
+
};
|
|
113
|
+
const stack = [];
|
|
114
|
+
const enter = (c) => {
|
|
115
|
+
const { v, key } = c;
|
|
116
|
+
if (c.member && key !== undefined) {
|
|
117
|
+
// an object member is judged by its key and value against its parent's path
|
|
118
|
+
if (/^claude_project_dir$/i.test(key))
|
|
119
|
+
return `CLAUDE_PROJECT_DIR at ${pathOf(c).join('.')}`;
|
|
120
|
+
// the path is compared as an array (review N-L2): a key spelled `mcpServers.holmes-kit` is not two segments
|
|
121
|
+
if (/^holmes_/i.test(key) && !holmesEnvAt.has(JSON.stringify(c.parent ? pathOf(c.parent) : [])))
|
|
122
|
+
return `${key} at ${pathOf(c).join('.')}`;
|
|
123
|
+
if (key === 'command' && typeof v === 'string' && namesHolmes(v) && !canonicalHookCommand(v)) {
|
|
124
|
+
const parent = c.parent ? pathOf(c.parent) : [];
|
|
125
|
+
if (!(parent.length >= 2 && parent[0] === 'mcpServers'))
|
|
126
|
+
return `hook command outside the grammar at ${pathOf(c).join('.')}`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// @implements A-SPEC-792.50 (review 00:3x M1) — every string, an array element included: `args` tokens and an `sh -c`
|
|
130
|
+
// string assigned CLAUDE_PROJECT_DIR and passed, while the same text as an object member value was a breach
|
|
131
|
+
if (key !== undefined && typeof v === 'string' && /(?:holmes_[a-z_]*|claude_project_dir)\s*=/i.test(v))
|
|
132
|
+
return `an environment assignment naming holmes or the project directory at ${pathOf(c).join('.')}`;
|
|
133
|
+
if (Array.isArray(v))
|
|
134
|
+
c.size = v.length;
|
|
135
|
+
else if (isObject(v)) {
|
|
136
|
+
c.keys = Object.keys(v);
|
|
137
|
+
c.size = c.keys.length;
|
|
138
|
+
}
|
|
139
|
+
if (c.size === 0)
|
|
140
|
+
return null;
|
|
141
|
+
if (c.depth >= MAX_JSON_DEPTH)
|
|
142
|
+
return `JSON nested deeper than ${MAX_JSON_DEPTH} levels at ${pathOf(c).slice(0, 6).join('.')}…`;
|
|
143
|
+
stack.push(c);
|
|
144
|
+
return null;
|
|
145
|
+
};
|
|
146
|
+
const first = enter({ v: doc, member: false, depth: 0, size: 0, next: 0 });
|
|
147
|
+
if (first !== null)
|
|
148
|
+
return first;
|
|
149
|
+
while (stack.length > 0) {
|
|
150
|
+
const top = stack[stack.length - 1];
|
|
151
|
+
if (top.next >= top.size) {
|
|
152
|
+
stack.pop();
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const i = top.next++;
|
|
156
|
+
const child = top.keys
|
|
157
|
+
? { v: top.v[top.keys[i]], key: top.keys[i], member: true, parent: top, depth: top.depth + 1, size: 0, next: 0 }
|
|
158
|
+
: { v: top.v[i], key: String(i), member: false, parent: top, depth: top.depth + 1, size: 0, next: 0 };
|
|
159
|
+
const b = enter(child);
|
|
160
|
+
if (b !== null)
|
|
161
|
+
return b;
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
function jsonBreach(path, text, ctx) {
|
|
166
|
+
let doc;
|
|
167
|
+
try {
|
|
168
|
+
doc = (0, config_loader_1.parseStrictJson)(text);
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
return `${path} does not parse (${e.message})`;
|
|
172
|
+
}
|
|
173
|
+
const holmesEnvAt = new Set();
|
|
174
|
+
if (isObject(doc) && isObject(doc.mcpServers)) {
|
|
175
|
+
for (const [name, entry] of Object.entries(doc.mcpServers)) {
|
|
176
|
+
const e = isObject(entry) ? entry : {};
|
|
177
|
+
const names = namesHolmes(name) || namesHolmes(e.command ?? '')
|
|
178
|
+
|| (Array.isArray(e.args) && e.args.some((a) => namesHolmes(a)))
|
|
179
|
+
|| (isObject(e.env) && Object.entries(e.env).some(([k, v]) => namesHolmes(k) || namesHolmes(v)));
|
|
180
|
+
if (!names)
|
|
181
|
+
continue;
|
|
182
|
+
const b = mcpEntryBreach(name, entry, ctx);
|
|
183
|
+
if (b)
|
|
184
|
+
return b;
|
|
185
|
+
holmesEnvAt.add(JSON.stringify(['mcpServers', name, 'env']));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const f = (0, path_rules_1.fold)(path);
|
|
189
|
+
if (f.endsWith('marketplace.json') && isObject(doc) && Array.isArray(doc.plugins)) {
|
|
190
|
+
for (const p of doc.plugins) {
|
|
191
|
+
if (namesHolmes(JSON.stringify(p)) && JSON.stringify(p) !== MARKETPLACE_ENTRY)
|
|
192
|
+
return 'the marketplace holmes-kit entry is not the one init writes';
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return walkBreach(doc, holmesEnvAt);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Every key path a TOML document defines — table headers, array-of-tables headers, dotted keys and inline-table keys —
|
|
199
|
+
* by a small tokenizer that keeps no values. Strings (basic, literal, multi-line) are read so that their contents are
|
|
200
|
+
* never taken for keys. Throws SyntaxError on anything it cannot read.
|
|
201
|
+
*/
|
|
202
|
+
function tomlKeys(text) {
|
|
203
|
+
return tomlRead(text).keys.map(({ path, quoted }) => ({ path, quoted }));
|
|
204
|
+
}
|
|
205
|
+
/** The tokenizer's whole reading: keys with their lines, and string values with the path they are the value of. */
|
|
206
|
+
function tomlRead(text) {
|
|
207
|
+
const out = [];
|
|
208
|
+
const strings = [];
|
|
209
|
+
const n = text.length;
|
|
210
|
+
let i = 0;
|
|
211
|
+
let table = { path: [], quoted: false };
|
|
212
|
+
// review 11:19 H1: the line of an offset by binary search over the line starts, built once (counting from the start
|
|
213
|
+
// for every key was quadratic: 98 s on a 1 MiB file)
|
|
214
|
+
const starts = [0];
|
|
215
|
+
for (let j = 0; j < n; j++)
|
|
216
|
+
if (text[j] === '\n')
|
|
217
|
+
starts.push(j + 1);
|
|
218
|
+
const lineAt = (offset) => {
|
|
219
|
+
let lo = 0, hi = starts.length - 1;
|
|
220
|
+
while (lo < hi) {
|
|
221
|
+
const mid = (lo + hi + 1) >> 1;
|
|
222
|
+
if (starts[mid] <= offset)
|
|
223
|
+
lo = mid;
|
|
224
|
+
else
|
|
225
|
+
hi = mid - 1;
|
|
226
|
+
}
|
|
227
|
+
return lo;
|
|
228
|
+
};
|
|
229
|
+
const err = (m) => { throw new SyntaxError(`TOML ${m} at offset ${i}`); };
|
|
230
|
+
const ws = () => { while (i < n && (text[i] === ' ' || text[i] === '\t'))
|
|
231
|
+
i++; };
|
|
232
|
+
const comment = () => { if (text[i] === '#')
|
|
233
|
+
while (i < n && text[i] !== '\n')
|
|
234
|
+
i++; };
|
|
235
|
+
const blank = () => {
|
|
236
|
+
for (;;) {
|
|
237
|
+
ws();
|
|
238
|
+
comment();
|
|
239
|
+
if (text[i] === '\n') {
|
|
240
|
+
i++;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (text[i] === '\r' && text[i + 1] === '\n') {
|
|
244
|
+
i += 2;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
const endOfLine = () => { ws(); comment(); if (i < n && text[i] !== '\n' && !(text[i] === '\r' && text[i + 1] === '\n'))
|
|
251
|
+
err('trailing text'); };
|
|
252
|
+
const escape = () => {
|
|
253
|
+
i++;
|
|
254
|
+
const c = text[i++];
|
|
255
|
+
const simple = { b: '\b', t: '\t', n: '\n', f: '\f', r: '\r', '"': '"', '\\': '\\' };
|
|
256
|
+
if (c in simple)
|
|
257
|
+
return simple[c];
|
|
258
|
+
if (c === 'u' || c === 'U') {
|
|
259
|
+
const len = c === 'u' ? 4 : 8;
|
|
260
|
+
const hex = text.slice(i, i + len);
|
|
261
|
+
if (!/^[0-9A-Fa-f]+$/.test(hex) || hex.length !== len)
|
|
262
|
+
err('bad escape');
|
|
263
|
+
i += len;
|
|
264
|
+
return String.fromCodePoint(parseInt(hex, 16));
|
|
265
|
+
}
|
|
266
|
+
return err('bad escape');
|
|
267
|
+
};
|
|
268
|
+
const basic = () => {
|
|
269
|
+
if (text.startsWith('"""', i)) {
|
|
270
|
+
i += 3;
|
|
271
|
+
let s = '';
|
|
272
|
+
while (i < n && !text.startsWith('"""', i)) {
|
|
273
|
+
if (text[i] === '\\') {
|
|
274
|
+
if (/^\\[ \t]*\r?\n/.test(text.slice(i, i + 64))) {
|
|
275
|
+
i++;
|
|
276
|
+
while (i < n && /[ \t\r\n]/.test(text[i]))
|
|
277
|
+
i++;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
s += escape();
|
|
281
|
+
}
|
|
282
|
+
else
|
|
283
|
+
s += text[i++];
|
|
284
|
+
}
|
|
285
|
+
if (i >= n)
|
|
286
|
+
err('unterminated string');
|
|
287
|
+
i += 3;
|
|
288
|
+
while (text[i] === '"') {
|
|
289
|
+
s += '"';
|
|
290
|
+
i++;
|
|
291
|
+
}
|
|
292
|
+
return s;
|
|
293
|
+
}
|
|
294
|
+
i++;
|
|
295
|
+
let s = '';
|
|
296
|
+
while (i < n && text[i] !== '"') {
|
|
297
|
+
if (text[i] === '\n')
|
|
298
|
+
err('newline in string');
|
|
299
|
+
s += text[i] === '\\' ? escape() : text[i++];
|
|
300
|
+
}
|
|
301
|
+
if (i >= n)
|
|
302
|
+
err('unterminated string');
|
|
303
|
+
i++;
|
|
304
|
+
return s;
|
|
305
|
+
};
|
|
306
|
+
const literal = () => {
|
|
307
|
+
const multi = text.startsWith("'''", i);
|
|
308
|
+
const close = multi ? "'''" : "'";
|
|
309
|
+
i += close.length;
|
|
310
|
+
const end = text.indexOf(close, i);
|
|
311
|
+
if (end < 0)
|
|
312
|
+
err('unterminated string');
|
|
313
|
+
const s = text.slice(i, end);
|
|
314
|
+
if (!multi && s.includes('\n'))
|
|
315
|
+
err('newline in string');
|
|
316
|
+
i = end + close.length;
|
|
317
|
+
if (multi)
|
|
318
|
+
while (text[i] === "'")
|
|
319
|
+
i++;
|
|
320
|
+
return s;
|
|
321
|
+
};
|
|
322
|
+
const key = () => {
|
|
323
|
+
const path = [];
|
|
324
|
+
let quoted = false;
|
|
325
|
+
for (;;) {
|
|
326
|
+
ws();
|
|
327
|
+
if (text[i] === '"') {
|
|
328
|
+
if (text.startsWith('"""', i))
|
|
329
|
+
err('multi-line key');
|
|
330
|
+
path.push(basic());
|
|
331
|
+
quoted = true;
|
|
332
|
+
}
|
|
333
|
+
else if (text[i] === "'") {
|
|
334
|
+
if (text.startsWith("'''", i))
|
|
335
|
+
err('multi-line key');
|
|
336
|
+
path.push(literal());
|
|
337
|
+
quoted = true;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
const m = /^[A-Za-z0-9_-]+/.exec(text.slice(i, i + 256));
|
|
341
|
+
if (!m)
|
|
342
|
+
err('bad key');
|
|
343
|
+
path.push(m[0]);
|
|
344
|
+
i += m[0].length;
|
|
345
|
+
}
|
|
346
|
+
if (path.length > MAX_KEY_SEGMENTS)
|
|
347
|
+
err(`key path longer than ${MAX_KEY_SEGMENTS} segments`);
|
|
348
|
+
ws();
|
|
349
|
+
if (text[i] === '.') {
|
|
350
|
+
i++;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
return { path, quoted };
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
const value = (prefix) => {
|
|
357
|
+
ws();
|
|
358
|
+
const c = text[i];
|
|
359
|
+
if (c === '"') {
|
|
360
|
+
strings.push({ path: prefix.path, value: basic() });
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (c === "'") {
|
|
364
|
+
strings.push({ path: prefix.path, value: literal() });
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (c === '[') {
|
|
368
|
+
i++;
|
|
369
|
+
for (;;) {
|
|
370
|
+
blank();
|
|
371
|
+
if (text[i] === ']') {
|
|
372
|
+
i++;
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
value(prefix);
|
|
376
|
+
blank();
|
|
377
|
+
if (text[i] === ',') {
|
|
378
|
+
i++;
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (text[i] === ']') {
|
|
382
|
+
i++;
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
err('bad array');
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (c === '{') {
|
|
389
|
+
i++;
|
|
390
|
+
ws();
|
|
391
|
+
if (text[i] === '}') {
|
|
392
|
+
i++;
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
for (;;) {
|
|
396
|
+
const at = i;
|
|
397
|
+
const k = key();
|
|
398
|
+
if (text[i] !== '=')
|
|
399
|
+
err('expected =');
|
|
400
|
+
i++;
|
|
401
|
+
if (prefix.path.length + k.path.length > MAX_KEY_SEGMENTS)
|
|
402
|
+
err(`key path longer than ${MAX_KEY_SEGMENTS} segments`);
|
|
403
|
+
const full = { path: [...prefix.path, ...k.path], quoted: prefix.quoted || k.quoted };
|
|
404
|
+
out.push({ ...full, line: lineAt(at) });
|
|
405
|
+
value(full);
|
|
406
|
+
ws();
|
|
407
|
+
if (text[i] === ',') {
|
|
408
|
+
i++;
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
if (text[i] === '}') {
|
|
412
|
+
i++;
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
err('bad inline table');
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const m = /^[^\s,\]}#]+/.exec(text.slice(i, i + 256));
|
|
419
|
+
if (!m)
|
|
420
|
+
err('bad value');
|
|
421
|
+
i += m[0].length;
|
|
422
|
+
};
|
|
423
|
+
for (;;) {
|
|
424
|
+
blank();
|
|
425
|
+
if (i >= n)
|
|
426
|
+
break;
|
|
427
|
+
if (text[i] === '[') {
|
|
428
|
+
const at = i;
|
|
429
|
+
const arrayOfTables = text[i + 1] === '[';
|
|
430
|
+
i += arrayOfTables ? 2 : 1;
|
|
431
|
+
table = key();
|
|
432
|
+
if (text[i] !== ']' || (arrayOfTables && text[i + 1] !== ']'))
|
|
433
|
+
err('bad table header');
|
|
434
|
+
i += arrayOfTables ? 2 : 1;
|
|
435
|
+
out.push({ ...table, line: lineAt(at) });
|
|
436
|
+
endOfLine();
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
const at = i;
|
|
440
|
+
const k = key();
|
|
441
|
+
if (text[i] !== '=')
|
|
442
|
+
err('expected =');
|
|
443
|
+
i++;
|
|
444
|
+
// @implements A-SPEC-792.50 (review 12:32 N1) — the bound is checked before the copy: one long header copied into
|
|
445
|
+
// every key below it was quadratic and exhausted the heap, which no try catches
|
|
446
|
+
if (table.path.length + k.path.length > MAX_KEY_SEGMENTS)
|
|
447
|
+
err(`key path longer than ${MAX_KEY_SEGMENTS} segments`);
|
|
448
|
+
const full = { path: [...table.path, ...k.path], quoted: table.quoted || k.quoted };
|
|
449
|
+
out.push({ ...full, line: lineAt(at) });
|
|
450
|
+
value(full);
|
|
451
|
+
endOfLine();
|
|
452
|
+
}
|
|
453
|
+
return { keys: out, strings };
|
|
454
|
+
}
|
|
455
|
+
/** Whether a TOML key path may name holmes: only the canonical holmes block's own keys. */
|
|
456
|
+
function holmesKeyAllowed(path) {
|
|
457
|
+
if (path[0] !== 'mcp_servers' || path[1] !== 'holmes-kit')
|
|
458
|
+
return false;
|
|
459
|
+
const rest = path.slice(2);
|
|
460
|
+
if (rest.length === 0)
|
|
461
|
+
return true;
|
|
462
|
+
if (rest.length === 1)
|
|
463
|
+
return ['command', 'args', 'env', 'required', 'tools'].includes(rest[0]);
|
|
464
|
+
if (rest[0] === 'env')
|
|
465
|
+
return rest.length === 2 && hasOwn(ENV_VALUES, rest[1]);
|
|
466
|
+
if (rest[0] === 'tools')
|
|
467
|
+
return rest.length === 2 || (rest.length === 3 && rest[2] === 'approval_mode');
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
const TOML_VALUE_ARG = /^args = \["([^"]*)"\]$/;
|
|
471
|
+
function tomlBreach(text, ctx) {
|
|
472
|
+
if (/\\[uU]/.test(text))
|
|
473
|
+
return 'a \\u or \\U escape in config.toml';
|
|
474
|
+
// @implements A-SPEC-792.50 (review N-C1) — a multi-line string can hide a line from the line reading
|
|
475
|
+
if (/'''|"""/.test(text))
|
|
476
|
+
return 'a multi-line string in config.toml';
|
|
477
|
+
let zone = 'none';
|
|
478
|
+
let seenMain = false;
|
|
479
|
+
let order = 0; // command 1, args 2, env 3, required 4
|
|
480
|
+
let has = { command: false, args: false, required: false };
|
|
481
|
+
const holmesLines = new Set(); // the lines the line reading puts in the holmes block or its tools tables
|
|
482
|
+
const lines = text.replace(/\r\n/g, '\n').split('\n');
|
|
483
|
+
for (let no = 0; no < lines.length; no++) {
|
|
484
|
+
const line = lines[no].trim();
|
|
485
|
+
const header = line.startsWith('[');
|
|
486
|
+
if (header ? line === '[mcp_servers.holmes-kit]' || /^\[mcp_servers\.holmes-kit\.tools\.[A-Za-z0-9_]+\]$/.test(line)
|
|
487
|
+
: line !== '' && !line.startsWith('#') && (zone === 'main' || zone === 'tool'))
|
|
488
|
+
holmesLines.add(no);
|
|
489
|
+
if (/claude_project_dir/i.test(line))
|
|
490
|
+
return 'CLAUDE_PROJECT_DIR in config.toml';
|
|
491
|
+
if (line === '')
|
|
492
|
+
continue;
|
|
493
|
+
if (line.startsWith('[')) {
|
|
494
|
+
if (/["']/.test(line))
|
|
495
|
+
return `a quoted table header: ${line}`;
|
|
496
|
+
if (line === '[mcp_servers.holmes-kit]') {
|
|
497
|
+
if (seenMain)
|
|
498
|
+
return 'a second holmes table';
|
|
499
|
+
seenMain = true;
|
|
500
|
+
zone = 'main';
|
|
501
|
+
order = 0;
|
|
502
|
+
has = { command: false, args: false, required: false };
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
if (/^\[mcp_servers\.holmes-kit\.tools\.[A-Za-z0-9_]+\]$/.test(line)) {
|
|
506
|
+
zone = 'tool';
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (namesHolmes(line))
|
|
510
|
+
return `a holmes table outside the grammar: ${line}`;
|
|
511
|
+
zone = 'other';
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
if (line.startsWith('#')) {
|
|
515
|
+
if (zone !== 'main' && zone !== 'tool' && namesHolmes(line))
|
|
516
|
+
return 'a line naming holmes outside the holmes block';
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (/^["']/.test(line))
|
|
520
|
+
return `a quoted key: ${line}`;
|
|
521
|
+
if (zone === 'main') {
|
|
522
|
+
let at = 0;
|
|
523
|
+
if (line === 'command = "node"') {
|
|
524
|
+
at = 1;
|
|
525
|
+
has.command = true;
|
|
526
|
+
}
|
|
527
|
+
else if (TOML_VALUE_ARG.test(line)) {
|
|
528
|
+
if (!allowedMcpArg(TOML_VALUE_ARG.exec(line)[1], ctx))
|
|
529
|
+
return 'the holmes args are outside the grammar';
|
|
530
|
+
at = 2;
|
|
531
|
+
has.args = true;
|
|
532
|
+
}
|
|
533
|
+
else if (line.startsWith('env = {')) {
|
|
534
|
+
const m = /^env = \{(.*)\}$/.exec(line);
|
|
535
|
+
if (!m)
|
|
536
|
+
return 'the holmes env is outside the grammar';
|
|
537
|
+
const pairs = m[1].split(',').map((s) => s.trim()).filter(Boolean).map((s) => /^([A-Z_]+) = "([^"]*)"$/.exec(s));
|
|
538
|
+
if (pairs.some((p) => p === null))
|
|
539
|
+
return 'the holmes env is outside the grammar';
|
|
540
|
+
let last = -1;
|
|
541
|
+
for (const p of pairs) {
|
|
542
|
+
const idx = ENV_ORDER.indexOf(p[1]);
|
|
543
|
+
if (idx <= last || !ENV_VALUES[p[1]].includes(p[2]))
|
|
544
|
+
return `the holmes env sets ${p[1]}`;
|
|
545
|
+
last = idx;
|
|
546
|
+
}
|
|
547
|
+
at = 3;
|
|
548
|
+
}
|
|
549
|
+
else if (line === 'required = true') {
|
|
550
|
+
at = 4;
|
|
551
|
+
has.required = true;
|
|
552
|
+
}
|
|
553
|
+
else
|
|
554
|
+
return `a line outside the grammar in the holmes block: ${line}`;
|
|
555
|
+
if (at <= order)
|
|
556
|
+
return 'the holmes block keys are out of order';
|
|
557
|
+
order = at;
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
if (zone === 'tool') {
|
|
561
|
+
if (line !== 'approval_mode = "approve"')
|
|
562
|
+
return `a tool table line outside the grammar: ${line}`;
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (namesHolmes(line))
|
|
566
|
+
return 'a line naming holmes outside the holmes block';
|
|
567
|
+
}
|
|
568
|
+
if (seenMain && !(has.command && has.args && has.required))
|
|
569
|
+
return 'the holmes block lacks command, args or required = true';
|
|
570
|
+
// the structure, as a TOML reader sees it
|
|
571
|
+
let read;
|
|
572
|
+
try {
|
|
573
|
+
read = tomlRead(text);
|
|
574
|
+
}
|
|
575
|
+
catch (e) {
|
|
576
|
+
return `config.toml does not parse (${e.message})`;
|
|
577
|
+
}
|
|
578
|
+
return tomlStructureBreach(read, holmesLines);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* @implements A-SPEC-792.50 (review N-C1) — the second reading's judgement, given the tokenizer's reading and the lines
|
|
582
|
+
* the line reading put in the holmes block. Each check here also has a line-reading counterpart, so through
|
|
583
|
+
* `canonicalWiring` it answers only what the first reading missed; it is exported so each check is tested on its own.
|
|
584
|
+
*/
|
|
585
|
+
function tomlStructureBreach(read, holmesLines) {
|
|
586
|
+
const inHolmes = (p) => p[0] === 'mcp_servers' && p[1] === 'holmes-kit';
|
|
587
|
+
for (const k of read.keys) {
|
|
588
|
+
if (k.quoted)
|
|
589
|
+
return `a quoted key: ${k.path.join('.')}`;
|
|
590
|
+
if (k.path.some((s) => /^claude_project_dir$/i.test(s)))
|
|
591
|
+
return `CLAUDE_PROJECT_DIR at ${k.path.join('.')}`;
|
|
592
|
+
if (k.path.some((s) => namesHolmes(s)) && !holmesKeyAllowed(k.path))
|
|
593
|
+
return `a key naming holmes outside the holmes block: ${k.path.join('.')}`;
|
|
594
|
+
// @implements A-SPEC-792.50 (review N-C1) — zone agreement: both readings put each key in the same block
|
|
595
|
+
if (inHolmes(k.path) !== holmesLines.has(k.line))
|
|
596
|
+
return `the line reading and the TOML reading disagree on line ${k.line + 1}`;
|
|
597
|
+
}
|
|
598
|
+
// @implements A-SPEC-792.50 (review N-C1) — value position: a string naming holmes stands only as the holmes args or
|
|
599
|
+
// the value of an allowed env key of the holmes block
|
|
600
|
+
for (const s of read.strings) {
|
|
601
|
+
if (!namesHolmes(s.value))
|
|
602
|
+
continue;
|
|
603
|
+
const p = s.path;
|
|
604
|
+
const ok = inHolmes(p) && ((p.length === 3 && p[2] === 'args') || (p.length === 4 && p[2] === 'env' && hasOwn(ENV_VALUES, p[3])));
|
|
605
|
+
if (!ok)
|
|
606
|
+
return `a string naming holmes at ${p.join('.')}`;
|
|
607
|
+
}
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
/** Whether a wiring file's bytes are canonical. */
|
|
611
|
+
function canonicalWiring(path, bytes, ctx) {
|
|
612
|
+
const text = bytes.toString('utf8');
|
|
613
|
+
const f = (0, path_rules_1.fold)(path);
|
|
614
|
+
const breach = f === '.codex/config.toml' ? tomlBreach(text, ctx)
|
|
615
|
+
: f.endsWith('.json') ? jsonBreach(path, text, ctx)
|
|
616
|
+
: (/holmes_|claude_project_dir/i.test(text) ? `${path} names a HOLMES_ or CLAUDE_PROJECT_DIR variable` : null);
|
|
617
|
+
return breach === null ? { ok: true } : { ok: false, breach };
|
|
618
|
+
}
|