@holmes-lab/holmes-kit 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +370 -6
- package/README.md +58 -40
- package/dist/.build-id +1 -1
- package/dist/holmes/admission/core/admission-policy.d.ts +37 -0
- package/dist/holmes/admission/core/admission-policy.js +147 -0
- package/dist/holmes/admission/core/bounded-reader.d.ts +56 -0
- package/dist/holmes/admission/core/bounded-reader.js +135 -0
- package/dist/holmes/admission/core/change-classifier.d.ts +34 -0
- package/dist/holmes/admission/core/change-classifier.js +278 -0
- package/dist/holmes/admission/core/config-loader.d.ts +30 -0
- package/dist/holmes/admission/core/config-loader.js +145 -0
- package/dist/holmes/admission/core/event-judgement.d.ts +37 -0
- package/dist/holmes/admission/core/event-judgement.js +251 -0
- package/dist/holmes/admission/core/path-rules.d.ts +35 -0
- package/dist/holmes/admission/core/path-rules.js +88 -0
- package/dist/holmes/admission/core/pin.d.ts +7 -0
- package/dist/holmes/admission/core/pin.js +29 -0
- package/dist/holmes/admission/core/ports.d.ts +48 -0
- package/dist/holmes/admission/core/ports.js +11 -0
- package/dist/holmes/admission/core/range-resolver.d.ts +32 -0
- package/dist/holmes/admission/core/range-resolver.js +51 -0
- package/dist/holmes/admission/core/self-containment.d.ts +1 -0
- package/dist/holmes/admission/core/self-containment.js +125 -0
- package/dist/holmes/admission/core/signature-source.d.ts +9 -0
- package/dist/holmes/admission/core/signature-source.js +4 -0
- package/dist/holmes/admission/core/transition-planner.d.ts +15 -0
- package/dist/holmes/admission/core/transition-planner.js +14 -0
- package/dist/holmes/admission/core/verdict.d.ts +38 -0
- package/dist/holmes/admission/core/verdict.js +17 -0
- package/dist/holmes/admission/core/wiring.d.ts +44 -0
- package/dist/holmes/admission/core/wiring.js +618 -0
- package/dist/holmes/admission/forge/git-object-port.d.ts +4 -0
- package/dist/holmes/admission/forge/git-object-port.js +132 -0
- package/dist/holmes/assoc/assoc-arm.d.ts +1 -1
- package/dist/holmes/assoc/assoc-arm.js +1 -1
- package/dist/holmes/cli/agents.d.ts +8 -0
- package/dist/holmes/cli/agents.js +9 -5
- package/dist/holmes/cli/approve-cli.d.ts +2 -0
- package/dist/holmes/cli/approve-cli.js +392 -0
- package/dist/holmes/cli/approve-ref.d.ts +13 -7
- package/dist/holmes/cli/approve-ref.js +30 -10
- package/dist/holmes/cli/approve-status.d.ts +26 -2
- package/dist/holmes/cli/approve-status.js +98 -18
- package/dist/holmes/cli/approve-watch.d.ts +5 -0
- package/dist/holmes/cli/approve-watch.js +10 -5
- package/dist/holmes/cli/approve.d.ts +50 -13
- package/dist/holmes/cli/approve.js +260 -67
- package/dist/holmes/cli/attest.js +2 -1
- package/dist/holmes/cli/autonomy.d.ts +4 -1
- package/dist/holmes/cli/autonomy.js +17 -10
- package/dist/holmes/cli/codex-oracle.d.ts +11 -0
- package/dist/holmes/cli/codex-oracle.js +5 -1
- package/dist/holmes/cli/codex-toml.d.ts +10 -0
- package/dist/holmes/cli/codex-toml.js +36 -2
- package/dist/holmes/cli/doctor-boundary.d.ts +76 -0
- package/dist/holmes/cli/doctor-boundary.js +308 -0
- package/dist/holmes/cli/doctor-locks.d.ts +15 -0
- package/dist/holmes/cli/doctor-locks.js +119 -0
- package/dist/holmes/cli/doctor.d.ts +2 -0
- package/dist/holmes/cli/doctor.js +45 -5
- package/dist/holmes/cli/flags.d.ts +23 -0
- package/dist/holmes/cli/flags.js +89 -0
- package/dist/holmes/cli/index.d.ts +5 -1
- package/dist/holmes/cli/index.js +206 -424
- package/dist/holmes/cli/init.js +33 -0
- package/dist/holmes/cli/lock-recover.d.ts +5 -0
- package/dist/holmes/cli/lock-recover.js +126 -0
- package/dist/holmes/cli/mcp-processes.d.ts +32 -0
- package/dist/holmes/cli/mcp-processes.js +132 -0
- package/dist/holmes/cli/release-docs.js +1 -1
- package/dist/holmes/cli/run-exec.d.ts +141 -0
- package/dist/holmes/cli/run-exec.js +1435 -0
- package/dist/holmes/cli/run-provision.d.ts +8 -0
- package/dist/holmes/cli/run-provision.js +325 -0
- package/dist/holmes/cli/run-wiring.d.ts +69 -0
- package/dist/holmes/cli/run-wiring.js +270 -0
- package/dist/holmes/cli/run.d.ts +26 -0
- package/dist/holmes/cli/run.js +364 -83
- package/dist/holmes/cli/runtime-binding-approval.js +32 -19
- package/dist/holmes/cli/screen-safe.d.ts +3 -92
- package/dist/holmes/cli/screen-safe.js +18 -756
- package/dist/holmes/config/config.d.ts +2 -0
- package/dist/holmes/config/config.js +5 -2
- package/dist/holmes/cpg/foundation/language-matrix.js +2 -2
- package/dist/holmes/cpg/import-resolver.js +1 -1
- package/dist/holmes/governance/approval-decisions.d.ts +47 -0
- package/dist/holmes/governance/approval-decisions.js +29 -0
- package/dist/holmes/governance/approval-grants.d.ts +220 -1
- package/dist/holmes/governance/approval-grants.js +612 -33
- package/dist/holmes/governance/approval-queue.d.ts +31 -0
- package/dist/holmes/governance/approval-queue.js +122 -11
- package/dist/holmes/governance/approval-spend.d.ts +95 -0
- package/dist/holmes/governance/approval-spend.js +191 -0
- package/dist/holmes/governance/autonomous-shell.d.ts +61 -0
- package/dist/holmes/governance/autonomous-shell.js +332 -0
- package/dist/holmes/governance/autonomy.d.ts +5 -0
- package/dist/holmes/governance/autonomy.js +16 -11
- package/dist/holmes/governance/constitution.d.ts +5 -0
- package/dist/holmes/governance/constitution.js +32 -12
- package/dist/holmes/governance/full-autonomy.d.ts +10 -0
- package/dist/holmes/governance/full-autonomy.js +103 -7
- package/dist/holmes/governance/harness-catalog.d.ts +103 -0
- package/dist/holmes/governance/harness-catalog.js +348 -0
- package/dist/holmes/governance/human-channel.d.ts +38 -0
- package/dist/holmes/governance/human-channel.js +49 -0
- package/dist/holmes/governance/install-manifest.d.ts +22 -0
- package/dist/holmes/governance/install-manifest.js +160 -0
- package/dist/holmes/governance/ledger-rechain.js +2 -0
- package/dist/holmes/governance/ledger-store.conformance.d.ts +7 -1
- package/dist/holmes/governance/ledger-store.conformance.js +66 -0
- package/dist/holmes/governance/ledger-store.d.ts +88 -11
- package/dist/holmes/governance/ledger-store.js +186 -8
- package/dist/holmes/governance/provenance-chain.d.ts +16 -4
- package/dist/holmes/governance/provenance-chain.js +19 -4
- package/dist/holmes/governance/provenance-ledger.d.ts +6 -3
- package/dist/holmes/governance/provenance-ledger.js +53 -18
- package/dist/holmes/governance/push-gate-runner.js +11 -7
- package/dist/holmes/governance/recorded-pairs.d.ts +96 -0
- package/dist/holmes/governance/recorded-pairs.js +522 -0
- package/dist/holmes/governance/replica-id.d.ts +1 -1
- package/dist/holmes/governance/replica-id.js +1 -1
- package/dist/holmes/governance/spec-seam.d.ts +59 -0
- package/dist/holmes/governance/spec-seam.js +587 -0
- package/dist/holmes/governance/spend-kinds.d.ts +16 -0
- package/dist/holmes/governance/spend-kinds.js +18 -0
- package/dist/holmes/governance/tool-actions.js +2 -0
- package/dist/holmes/guardrail/decision-ledger.d.ts +2 -1
- package/dist/holmes/guardrail/decision-ledger.js +2 -1
- package/dist/holmes/guardrail/impact-gate.d.ts +1 -0
- package/dist/holmes/guardrail/impact-gate.js +1 -1
- package/dist/holmes/guardrail/line-continuation.d.ts +8 -0
- package/dist/holmes/guardrail/line-continuation.js +39 -0
- package/dist/holmes/guardrail/operator-person.d.ts +28 -4
- package/dist/holmes/guardrail/operator-person.js +57 -11
- package/dist/holmes/guardrail/refusal-codes.d.ts +8 -3
- package/dist/holmes/guardrail/refusal-codes.js +70 -10
- package/dist/holmes/guardrail/risk-classifier.d.ts +15 -9
- package/dist/holmes/guardrail/risk-classifier.js +245 -15
- package/dist/holmes/guardrail/risk-gate.d.ts +2 -8
- package/dist/holmes/guardrail/risk-gate.js +7 -34
- package/dist/holmes/guardrail/risk-types.d.ts +10 -0
- package/dist/holmes/guardrail/run-plan-scope.js +3 -1
- package/dist/holmes/guardrail/run-refusals.d.ts +6 -1
- package/dist/holmes/guardrail/run-refusals.js +36 -14
- package/dist/holmes/guardrail/run-stages.d.ts +10 -0
- package/dist/holmes/guardrail/run-stages.js +46 -6
- package/dist/holmes/guardrail/scope-judgment.js +1 -1
- package/dist/holmes/guardrail/shell-words.js +24 -3
- package/dist/holmes/guardrail/unresolved-write.d.ts +40 -0
- package/dist/holmes/guardrail/unresolved-write.js +556 -0
- package/dist/holmes/guardrail/write-target.d.ts +3 -0
- package/dist/holmes/guardrail/write-target.js +26 -5
- package/dist/holmes/hooks/pre-tool-use.d.ts +105 -1
- package/dist/holmes/hooks/pre-tool-use.js +1167 -168
- package/dist/holmes/hooks/rtm-refresh-child.d.ts +1 -1
- package/dist/holmes/hooks/rtm-refresh-child.js +1 -1
- package/dist/holmes/hooks/session-start.d.ts +5 -0
- package/dist/holmes/hooks/session-start.js +29 -1
- package/dist/holmes/hooks/stop.d.ts +23 -0
- package/dist/holmes/hooks/stop.js +88 -33
- package/dist/holmes/mcp/approval-adapters.js +3 -1
- package/dist/holmes/mcp/approval-commit.js +3 -2
- package/dist/holmes/mcp/approval-policy.d.ts +2 -1
- package/dist/holmes/mcp/approval-policy.js +3 -1
- package/dist/holmes/mcp/handlers/adoption.d.ts +1 -1
- package/dist/holmes/mcp/handlers/approval-ask.d.ts +14 -0
- package/dist/holmes/mcp/handlers/approval-ask.js +31 -6
- package/dist/holmes/mcp/handlers/entity-integration.d.ts +3 -3
- package/dist/holmes/mcp/handlers/entity-integration.js +29 -11
- package/dist/holmes/mcp/handlers/entity-renumber.d.ts +4 -4
- package/dist/holmes/mcp/handlers/entity-renumber.js +29 -11
- package/dist/holmes/mcp/handlers/entity-store.d.ts +2 -2
- package/dist/holmes/mcp/handlers/entity-store.js +133 -59
- package/dist/holmes/mcp/handlers/operator-inspection.d.ts +9 -5
- package/dist/holmes/mcp/handlers/operator-inspection.js +79 -16
- package/dist/holmes/mcp/handlers/phase-queries.d.ts +1 -1
- package/dist/holmes/mcp/handlers/requirement-triage.d.ts +4 -4
- package/dist/holmes/mcp/handlers/review-evidence.d.ts +2 -2
- package/dist/holmes/mcp/handlers/review-evidence.js +35 -11
- package/dist/holmes/mcp/handlers/review-queries.d.ts +5 -0
- package/dist/holmes/mcp/handlers/review-queries.js +8 -1
- package/dist/holmes/mcp/handlers/review-verdict.d.ts +3 -0
- package/dist/holmes/mcp/handlers/review-verdict.js +10 -3
- package/dist/holmes/mcp/handlers/risk-assessment.d.ts +7 -2
- package/dist/holmes/mcp/handlers/risk-assessment.js +34 -12
- package/dist/holmes/mcp/handlers/runtime-binding-tool.d.ts +2 -2
- package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +6 -1
- package/dist/holmes/mcp/handlers/slice-orchestration.js +14 -1
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +15 -3
- package/dist/holmes/mcp/handlers/spec-approval.js +32 -5
- package/dist/holmes/mcp/handlers/spec-authoring.d.ts +2 -2
- package/dist/holmes/mcp/handlers/spec-authoring.js +19 -2
- package/dist/holmes/mcp/handlers/spec-lifecycle.d.ts +11 -38
- package/dist/holmes/mcp/handlers/spec-lifecycle.js +441 -94
- package/dist/holmes/mcp/handlers/spec-queries.d.ts +2 -2
- package/dist/holmes/mcp/handlers/taint-screening.d.ts +1 -1
- package/dist/holmes/mcp/handlers/taint-screening.js +2 -2
- package/dist/holmes/mcp/handlers/test-execution.d.ts +1 -1
- package/dist/holmes/mcp/handlers/workspace-preflight.d.ts +5 -0
- package/dist/holmes/mcp/handlers/workspace-preflight.js +10 -2
- package/dist/holmes/mcp/handlers/workspace-queries.d.ts +2 -2
- package/dist/holmes/mcp/handlers.d.ts +99 -79
- package/dist/holmes/mcp/handlers.js +93 -25
- package/dist/holmes/mcp/harness-attestation.d.ts +78 -5
- package/dist/holmes/mcp/harness-attestation.js +325 -53
- package/dist/holmes/mcp/maintenance-analyze.d.ts +1 -1
- package/dist/holmes/mcp/maintenance-analyze.js +9 -9
- package/dist/holmes/mcp/maintenance-evidence.js +31 -2
- package/dist/holmes/mcp/requirement-triage-evidence.js +22 -13
- package/dist/holmes/mcp/server-staleness.d.ts +43 -0
- package/dist/holmes/mcp/server-staleness.js +158 -0
- package/dist/holmes/mcp/server.js +34 -9
- package/dist/holmes/mcp/spec-id-guard.js +1 -1
- package/dist/holmes/mcp/tool-schemas.d.ts +13 -0
- package/dist/holmes/mcp/tool-schemas.js +42 -2
- package/dist/holmes/project/act-root.d.ts +19 -0
- package/dist/holmes/project/act-root.js +100 -0
- package/dist/holmes/project/baseline.js +4 -3
- package/dist/holmes/project/bounded-group.d.ts +47 -0
- package/dist/holmes/project/bounded-group.js +140 -0
- package/dist/holmes/project/bounded-io.d.ts +50 -2
- package/dist/holmes/project/bounded-io.js +138 -6
- package/dist/holmes/project/change-source.js +2 -2
- package/dist/holmes/project/instance-id.d.ts +10 -0
- package/dist/holmes/project/instance-id.js +233 -0
- package/dist/holmes/project/machine-identity.d.ts +25 -0
- package/dist/holmes/project/machine-identity.js +133 -0
- package/dist/holmes/project/owned-lock.d.ts +84 -0
- package/dist/holmes/project/owned-lock.js +263 -0
- package/dist/holmes/project/plain-lock-fs.d.ts +2 -0
- package/dist/holmes/project/plain-lock-fs.js +126 -0
- package/dist/holmes/project/request-lock.d.ts +85 -0
- package/dist/holmes/project/request-lock.js +459 -0
- package/dist/holmes/project/root.d.ts +12 -4
- package/dist/holmes/project/root.js +26 -7
- package/dist/holmes/project/run-records.d.ts +19 -0
- package/dist/holmes/project/run-records.js +94 -12
- package/dist/holmes/project/screen-text.d.ts +94 -0
- package/dist/holmes/project/screen-text.js +763 -0
- package/dist/holmes/project/spend-lock.d.ts +82 -0
- package/dist/holmes/project/spend-lock.js +413 -0
- package/dist/holmes/project/workspace-preflight.d.ts +5 -0
- package/dist/holmes/project/workspace-preflight.js +24 -1
- package/dist/holmes/refresh/freshness-coordinator.d.ts +1 -1
- package/dist/holmes/refresh/freshness-coordinator.js +1 -1
- package/dist/holmes/review/condition-hunk-replay.js +4 -2
- package/dist/holmes/review/confidence-calibration.d.ts +1 -1
- package/dist/holmes/review/confidence-calibration.js +1 -1
- package/dist/holmes/review/content-verify.js +1 -1
- package/dist/holmes/review/hop-ablation.d.ts +4 -4
- package/dist/holmes/review/hop-ablation.js +5 -5
- package/dist/holmes/review/point-in-time-replay.js +12 -3
- package/dist/holmes/review/rank-diagnosis.d.ts +2 -2
- package/dist/holmes/review/rank-diagnosis.js +1 -1
- package/dist/holmes/review/replay-corpus.d.ts +10 -4
- package/dist/holmes/review/replay-corpus.js +25 -9
- package/dist/holmes/review/requirement-triage.js +2 -2
- package/dist/holmes/review/semantic-arm.d.ts +3 -3
- package/dist/holmes/review/semantic-arm.js +3 -3
- package/dist/holmes/review/test-outcomes.js +3 -1
- package/dist/holmes/review/test-runner.d.ts +11 -0
- package/dist/holmes/review/test-runner.js +31 -10
- package/dist/holmes/review/test-selection-breadth.js +2 -2
- package/dist/holmes/review/verdicts.d.ts +109 -7
- package/dist/holmes/review/verdicts.js +653 -34
- package/dist/holmes/rtm/anchor-census.d.ts +9 -0
- package/dist/holmes/rtm/anchor-census.js +151 -0
- package/dist/holmes/rtm/anchor-ids.d.ts +25 -1
- package/dist/holmes/rtm/anchor-ids.js +45 -2
- package/dist/holmes/rtm/comment-ranges.d.ts +2 -0
- package/dist/holmes/rtm/comment-ranges.js +104 -0
- package/dist/holmes/rtm/counted-tests.d.ts +1 -0
- package/dist/holmes/rtm/counted-tests.js +63 -0
- package/dist/holmes/rtm/impact-advisory.d.ts +1 -1
- package/dist/holmes/rtm/known-defects.js +1 -1
- package/dist/holmes/rtm/localize.js +1 -1
- package/dist/holmes/rtm/taint-benchmark.d.ts +1 -1
- package/dist/holmes/rtm/taint-vocabulary.d.ts +1 -1
- package/dist/holmes/rtm/test-scope.d.ts +31 -0
- package/dist/holmes/rtm/test-scope.js +166 -5
- package/dist/holmes/rtm/trace-gaps.js +1 -1
- package/dist/holmes/runtime/dispatch.d.ts +10 -0
- package/dist/holmes/runtime/dispatch.js +12 -1
- package/dist/holmes/semantic/cloud-usage.d.ts +1 -1
- package/dist/holmes/semantic/cloud-usage.js +1 -1
- package/dist/holmes/semantic/unreadable-paths.d.ts +1 -1
- package/dist/holmes/semantic/unreadable-paths.js +1 -1
- package/dist/holmes/spec/approval-blockers.js +1 -1
- package/dist/holmes/spec/entity-store.d.ts +6 -1
- package/dist/holmes/spec/entity-store.js +16 -2
- package/dist/holmes/spec/entity-transaction.d.ts +7 -2
- package/dist/holmes/spec/entity-transaction.js +87 -170
- package/dist/holmes/spec/spec-store.d.ts +12 -6
- package/dist/holmes/spec/spec-store.js +4 -2
- package/dist/holmes/spec/spec-types.js +1 -1
- package/dist/holmes/spec/succession-guard.d.ts +56 -0
- package/dist/holmes/spec/succession-guard.js +187 -0
- package/dist/holmes/spec/succession.d.ts +70 -0
- package/dist/holmes/spec/succession.js +171 -0
- package/dist/holmes/spec/transition-policy.d.ts +2 -2
- package/docs/install-guide.md +9 -3
- package/docs/language-support.md +78 -0
- package/package.json +4 -3
- package/playbooks/author-slice/PLAYBOOK.md +1 -1
- package/playbooks/promote-slice/PLAYBOOK.md +5 -1
- package/playbooks/publish/PLAYBOOK.md +45 -33
- package/dist/holmes/review/manual-baseline.d.ts +0 -209
- package/dist/holmes/review/manual-baseline.js +0 -2847
|
@@ -0,0 +1,556 @@
|
|
|
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.STORE_WHOLE_REASON = exports.STORE_BUILT_REASON = exports.storePathBuiltText = exports.KEYWORD = void 0;
|
|
37
|
+
exports.commandText = commandText;
|
|
38
|
+
exports.readableText = readableText;
|
|
39
|
+
exports.cwdInStore = cwdInStore;
|
|
40
|
+
exports.storePathBuiltJudgement = storePathBuiltJudgement;
|
|
41
|
+
// @implements A-SPEC-794.33, A-SPEC-794.34, A-SPEC-794.35, A-SPEC-794.36, A-SPEC-794.37, A-SPEC-794.38, A-SPEC-794.39, A-SPEC-794.40, A-SPEC-794.42, A-SPEC-794.43, A-SPEC-794.45, A-SPEC-794.49, A-SPEC-794.50, A-SPEC-794.54
|
|
42
|
+
/**
|
|
43
|
+
* A-SPEC-794.38 — which part of a shell command can carry a governance-store path that is built while the command runs.
|
|
44
|
+
*
|
|
45
|
+
* The classifier's not-a-read rule judged a command only when a protected store path was spelled out in its text. This
|
|
46
|
+
* module says when a store path is built at run time and which pipelines it can reach; the existing rule decides read or
|
|
47
|
+
* write over those pipelines only. It parses no write.
|
|
48
|
+
*
|
|
49
|
+
* Removing comments and here-document bodies is an optimisation for commands this scan reads with certainty: whatever it
|
|
50
|
+
* cannot read that way is judged whole, which errs toward refusal (`StoreBuilt` says what "whole" holds).
|
|
51
|
+
*
|
|
52
|
+
* Not a security boundary against the same user's agent shell (A-SPEC-794.38 Limits).
|
|
53
|
+
*/
|
|
54
|
+
const path = __importStar(require("node:path"));
|
|
55
|
+
const write_target_1 = require("./write-target");
|
|
56
|
+
/** Where `<<` and ` #` need not be a here-document or a comment: this scan does not read these constructs. */
|
|
57
|
+
const NOT_READ = /\(\(|\$\[|\[\[|(?:^|[\s;&|(])let\s/;
|
|
58
|
+
const LOOKS_LIKE_DATA = /<<|\s#/;
|
|
59
|
+
/** What runs text: a body or a comment beside one may be a program. A shell by any path, or a program named by its path. */
|
|
60
|
+
const RUNS_TEXT = /(?:^|[\s;&|(`"'=/])(?:(?:ba|z|da|k)?sh|eval|source|xargs|exec)(?=$|[\s;&|)`"'])|(?:^|[;&|(\n])[ \t]*(?:\.[ \t]|[^\s;&|()=]*\/)|(?:^|[\s;&|(])(?:function\s+[\w-]+|[\w-]+\s*\(\s*\))/m;
|
|
61
|
+
/** A delimiter is a whole shell word: this follows it, or it was not read. */
|
|
62
|
+
const AFTER_DELIMITER = /^(?:$|[\s;&|<>)])/;
|
|
63
|
+
/**
|
|
64
|
+
* The command without comments and here-document bodies, at every depth of `$(…)`; an expanding body keeps its expansions.
|
|
65
|
+
* Clears `st.certain` on anything it cannot read as the shell does; the text is then not to be used.
|
|
66
|
+
*/
|
|
67
|
+
function withoutData(s, st, start = 0, closer = null) {
|
|
68
|
+
let out = '';
|
|
69
|
+
let i = start;
|
|
70
|
+
let depth = 0;
|
|
71
|
+
let pending = [];
|
|
72
|
+
const nested = (open) => {
|
|
73
|
+
const r = withoutData(s, st, open, ')');
|
|
74
|
+
out += s.slice(i, open) + r.out + ')';
|
|
75
|
+
i = r.end;
|
|
76
|
+
};
|
|
77
|
+
const unit = () => { const e = unitEnd(s, i); out += s.slice(i, e); i = e; };
|
|
78
|
+
const done = (end) => { if (pending.length > 0)
|
|
79
|
+
st.certain = false; return { out, end }; };
|
|
80
|
+
while (i < s.length) {
|
|
81
|
+
const ch = s[i];
|
|
82
|
+
if (ch === '\\' || ch === "'" || (ch === '$' && (s[i + 1] === "'" || s[i + 1] === '{'))) {
|
|
83
|
+
unit();
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (ch === '"') {
|
|
87
|
+
out += ch;
|
|
88
|
+
i++;
|
|
89
|
+
while (i < s.length && s[i] !== '"') {
|
|
90
|
+
if (s[i] === '\\') {
|
|
91
|
+
out += s.slice(i, i + 2);
|
|
92
|
+
i += 2;
|
|
93
|
+
}
|
|
94
|
+
else if (s[i] === '$' && s[i + 1] === '(')
|
|
95
|
+
nested(i + 2);
|
|
96
|
+
else if (s[i] === '$' && s[i + 1] === '{') {
|
|
97
|
+
// Inside double quotes the shell reads a quote in `${…}` by context
|
|
98
|
+
const e = unitEnd(s, i);
|
|
99
|
+
if (/['"]/.test(s.slice(i, e)))
|
|
100
|
+
st.certain = false;
|
|
101
|
+
out += s.slice(i, e);
|
|
102
|
+
i = e;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
out += s[i];
|
|
106
|
+
i++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (i < s.length) {
|
|
110
|
+
out += '"';
|
|
111
|
+
i++;
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if ((ch === '$' || ch === '<' || ch === '>') && s[i + 1] === '(') {
|
|
116
|
+
nested(i + 2);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (ch === '`') {
|
|
120
|
+
let e = i + 1;
|
|
121
|
+
while (e < s.length && s[e] !== '`')
|
|
122
|
+
e += s[e] === '\\' ? 2 : 1;
|
|
123
|
+
out += `\`${withoutData(s.slice(i + 1, e), st).out}\``;
|
|
124
|
+
i = e + 1;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (ch === '#' && (i === start || /[\s;&|(]/.test(s[i - 1]))) {
|
|
128
|
+
while (i < s.length && s[i] !== '\n')
|
|
129
|
+
i++;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (s.startsWith('<<<', i)) {
|
|
133
|
+
out += '<<<';
|
|
134
|
+
i += 3;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (s.startsWith('<<', i)) {
|
|
138
|
+
const m = (0, write_target_1.heredocAt)(s, i);
|
|
139
|
+
if (m && AFTER_DELIMITER.test(s.slice(i + m[0].length, i + m[0].length + 1))) {
|
|
140
|
+
pending.push({ tag: (0, write_target_1.heredocDelimiter)(m), dash: m[0][2] === '-', literal: m[1] !== undefined || m[0].includes('\\') });
|
|
141
|
+
i += m[0].length;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
st.certain = false;
|
|
145
|
+
}
|
|
146
|
+
if (ch === '\n' && pending.length > 0) {
|
|
147
|
+
out += '\n';
|
|
148
|
+
i++;
|
|
149
|
+
for (const h of pending) {
|
|
150
|
+
const lines = [];
|
|
151
|
+
let closed = false;
|
|
152
|
+
while (i < s.length && !closed) {
|
|
153
|
+
const e = s.indexOf('\n', i);
|
|
154
|
+
const line = s.slice(i, e < 0 ? s.length : e);
|
|
155
|
+
i = e < 0 ? s.length : e + 1;
|
|
156
|
+
if ((h.dash ? line.replace(/^\t+/, '') : line) === h.tag)
|
|
157
|
+
closed = true;
|
|
158
|
+
else
|
|
159
|
+
lines.push(line);
|
|
160
|
+
}
|
|
161
|
+
if (!closed)
|
|
162
|
+
st.certain = false;
|
|
163
|
+
if (!h.literal)
|
|
164
|
+
out += expansionsOf(lines.join('\n'), true).map((x) => `: ${x}\n`).join('');
|
|
165
|
+
}
|
|
166
|
+
pending = [];
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (closer !== null) {
|
|
170
|
+
if (ch === '(')
|
|
171
|
+
depth++;
|
|
172
|
+
else if (ch === ')') {
|
|
173
|
+
if (depth === 0)
|
|
174
|
+
return done(i + 1);
|
|
175
|
+
depth--;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
out += ch;
|
|
179
|
+
i++;
|
|
180
|
+
}
|
|
181
|
+
return done(i);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* `$'…'` as plain single quotes, so the classifier's splitter, which does not know it, sees where it ends. Transitional
|
|
185
|
+
* debt (A-SPEC-794.40 Limits): the fault is the splitter's, and this rewrites the caller's input. Top level only.
|
|
186
|
+
*/
|
|
187
|
+
function plainAnsiQuotes(s) {
|
|
188
|
+
if (!s.includes("$'"))
|
|
189
|
+
return s;
|
|
190
|
+
let out = '';
|
|
191
|
+
for (let i = 0, e = 0; i < s.length; i = e) {
|
|
192
|
+
e = unitEnd(s, i);
|
|
193
|
+
out += s[i] === '$' && s[i + 1] === "'" ? `'${s.slice(i + 2, e - 1).replace(/\\[\\']/g, '')}'` : s.slice(i, e);
|
|
194
|
+
}
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The text the rule reads. Data goes only when the whole command was read with certainty and nothing in it runs text;
|
|
199
|
+
* otherwise `whole`: no splitter can be trusted on text not read with certainty, so all of it is judged, comments and
|
|
200
|
+
* bodies included, with `$'…'` made plain.
|
|
201
|
+
*/
|
|
202
|
+
function commandText(raw) {
|
|
203
|
+
const st = { certain: true };
|
|
204
|
+
const { out } = withoutData(raw, st);
|
|
205
|
+
// In what stays: a `((` in a body is the body's own text, and the `<<` of a real `((1<<k))` keeps its `((` before it
|
|
206
|
+
const kept = st.certain && !(NOT_READ.test(out) && LOOKS_LIKE_DATA.test(raw)) && (out === raw || !RUNS_TEXT.test(out));
|
|
207
|
+
return { text: plainAnsiQuotes(kept ? out : raw), whole: !kept };
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* A-SPEC-794.54 — `commandText` for a reader that has no bound of its own: past the length bound, or when the reader
|
|
211
|
+
* overflows, the whole text as written, comments and bodies included.
|
|
212
|
+
*/
|
|
213
|
+
function readableText(raw) {
|
|
214
|
+
if (raw.length > MAX_CHARS)
|
|
215
|
+
return raw;
|
|
216
|
+
try {
|
|
217
|
+
return commandText(raw).text;
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return raw;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The index just past the unit at `i`: an escape, a quoted run, an expansion, or one character. In double quotes (`inDq`)
|
|
225
|
+
* a single quote and `$'` are plain characters.
|
|
226
|
+
*/
|
|
227
|
+
function unitEnd(s, i, inDq = false) {
|
|
228
|
+
const ch = s[i];
|
|
229
|
+
if (ch === '\\')
|
|
230
|
+
return i + 2;
|
|
231
|
+
if (inDq && ch === "'")
|
|
232
|
+
return i + 1;
|
|
233
|
+
if (ch === "'") {
|
|
234
|
+
const c = s.indexOf("'", i + 1);
|
|
235
|
+
return c < 0 ? s.length : c + 1;
|
|
236
|
+
}
|
|
237
|
+
if (!inDq && ch === '$' && s[i + 1] === "'") {
|
|
238
|
+
let j = i + 2;
|
|
239
|
+
while (j < s.length && s[j] !== "'")
|
|
240
|
+
j += s[j] === '\\' ? 2 : 1;
|
|
241
|
+
return j + 1;
|
|
242
|
+
}
|
|
243
|
+
if (ch === '"') {
|
|
244
|
+
let j = i + 1;
|
|
245
|
+
while (j < s.length && s[j] !== '"')
|
|
246
|
+
j = unitEnd(s, j, true);
|
|
247
|
+
return j + 1;
|
|
248
|
+
}
|
|
249
|
+
if (ch === '`') {
|
|
250
|
+
let j = i + 1;
|
|
251
|
+
while (j < s.length && s[j] !== '`')
|
|
252
|
+
j += s[j] === '\\' ? 2 : 1;
|
|
253
|
+
return j + 1;
|
|
254
|
+
}
|
|
255
|
+
if ((ch === '$' || ch === '<' || ch === '>') && s[i + 1] === '(')
|
|
256
|
+
return bracketEnd(s, i + 2, '(', ')');
|
|
257
|
+
if (ch === '$' && s[i + 1] === '{')
|
|
258
|
+
return bracketEnd(s, i + 2, '{', '}');
|
|
259
|
+
return i + 1;
|
|
260
|
+
}
|
|
261
|
+
function bracketEnd(s, start, open, close) {
|
|
262
|
+
let depth = 0;
|
|
263
|
+
let j = start;
|
|
264
|
+
while (j < s.length) {
|
|
265
|
+
if (s[j] === open)
|
|
266
|
+
depth++;
|
|
267
|
+
else if (s[j] === close) {
|
|
268
|
+
if (depth === 0)
|
|
269
|
+
return j + 1;
|
|
270
|
+
depth--;
|
|
271
|
+
}
|
|
272
|
+
j = unitEnd(s, j);
|
|
273
|
+
}
|
|
274
|
+
return j;
|
|
275
|
+
}
|
|
276
|
+
/** Every outermost expansion the shell would run: never one in single quotes, and never an escaped one. A body reads as double quotes do. */
|
|
277
|
+
function expansionsOf(s, inBody = false) {
|
|
278
|
+
const found = [];
|
|
279
|
+
const isExpansion = (i) => s[i] === '`' || ((s[i] === '$' || s[i] === '<' || s[i] === '>') && s[i + 1] === '(') || (s[i] === '$' && s[i + 1] === '{');
|
|
280
|
+
const walk = (from, to, inDq) => {
|
|
281
|
+
let i = from;
|
|
282
|
+
while (i < to) {
|
|
283
|
+
const e = unitEnd(s, i, inDq);
|
|
284
|
+
if (s[i] === '"' && !inDq)
|
|
285
|
+
walk(i + 1, e - 1, true);
|
|
286
|
+
else if (isExpansion(i))
|
|
287
|
+
found.push(s.slice(i, e));
|
|
288
|
+
i = e;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
walk(0, s.length, inBody);
|
|
292
|
+
return found;
|
|
293
|
+
}
|
|
294
|
+
/** True when a word spells the store, `/`, and then an expansion: the shell completes a store path at run time. */
|
|
295
|
+
function completesStorePath(word) {
|
|
296
|
+
let literal = '';
|
|
297
|
+
const walk = (from, to, inDq) => {
|
|
298
|
+
let i = from;
|
|
299
|
+
while (i < to) {
|
|
300
|
+
const e = unitEnd(word, i, inDq);
|
|
301
|
+
const ch = word[i];
|
|
302
|
+
if (ch === '"' && !inDq) {
|
|
303
|
+
if (walk(i + 1, e - 1, true))
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
else if (ch === "'" && !inDq)
|
|
307
|
+
literal += word.slice(i + 1, e - 1);
|
|
308
|
+
else if (ch === '\\')
|
|
309
|
+
literal += word.slice(i + 1, e);
|
|
310
|
+
else if (ch === '`' || ch === '$') {
|
|
311
|
+
if (/(?:^|[^\w.-])\.ax\//i.test(literal))
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
else
|
|
315
|
+
literal += word.slice(i, e);
|
|
316
|
+
i = e;
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
319
|
+
};
|
|
320
|
+
return walk(0, word.length, false);
|
|
321
|
+
}
|
|
322
|
+
/** The words of a clause, each as written. */
|
|
323
|
+
function wordsOf(clause) {
|
|
324
|
+
const words = [];
|
|
325
|
+
let i = 0;
|
|
326
|
+
while (i < clause.length) {
|
|
327
|
+
while (i < clause.length && /\s/.test(clause[i]))
|
|
328
|
+
i++;
|
|
329
|
+
const start = i;
|
|
330
|
+
while (i < clause.length && !/\s/.test(clause[i]))
|
|
331
|
+
i = unitEnd(clause, i);
|
|
332
|
+
if (i > start)
|
|
333
|
+
words.push(clause.slice(start, i));
|
|
334
|
+
}
|
|
335
|
+
return words;
|
|
336
|
+
}
|
|
337
|
+
/** The stages of a pipeline, split at `|` outside quotes and expansions. */
|
|
338
|
+
function stagesOf(pipeline) {
|
|
339
|
+
const out = [];
|
|
340
|
+
let cur = 0;
|
|
341
|
+
let i = 0;
|
|
342
|
+
while (i < pipeline.length) {
|
|
343
|
+
if (pipeline[i] === '|') {
|
|
344
|
+
out.push(pipeline.slice(cur, i));
|
|
345
|
+
i++;
|
|
346
|
+
if (pipeline[i] === '&')
|
|
347
|
+
i++;
|
|
348
|
+
cur = i;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
i = unitEnd(pipeline, i);
|
|
352
|
+
}
|
|
353
|
+
out.push(pipeline.slice(cur));
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
/** The store's name as a path segment: `.axios`, `foo.ax` and `.ax.json` are other names. */
|
|
357
|
+
const namesStore = (text) => (0, write_target_1.mentionsAxSpelling)(text.replace(/[\w-]\.ax\b|\.ax[\w.-]+/g, ''));
|
|
358
|
+
exports.KEYWORD = /^(?:do|then|else|elif|if|while|until|!|\{|\(|time)$/;
|
|
359
|
+
const ASSIGNMENT = /^[A-Za-z_]\w*(?:\[[^\]]*\])?\+?=/;
|
|
360
|
+
const DECLARES = /^(?:export|declare|typeset|local|readonly|env)$/;
|
|
361
|
+
const INNER_SHELL = /^(?:ba|z|da|k)?sh$/;
|
|
362
|
+
const READS_INPUT = /^(?:read|mapfile|readarray)$/;
|
|
363
|
+
/** A clause's words from its command word on: compound keywords and a leading `(` gone. */
|
|
364
|
+
function commandWords(stage) {
|
|
365
|
+
const words = wordsOf(stage.trim());
|
|
366
|
+
while (words.length > 0 && exports.KEYWORD.test(words[0]))
|
|
367
|
+
words.shift();
|
|
368
|
+
if (words[0]?.startsWith('('))
|
|
369
|
+
words[0] = words[0].slice(1);
|
|
370
|
+
return words;
|
|
371
|
+
}
|
|
372
|
+
/** The text a stage binds to a name or a position, or null. Words after the command word bind nothing. */
|
|
373
|
+
function boundValue(stage) {
|
|
374
|
+
const words = commandWords(stage);
|
|
375
|
+
const values = [];
|
|
376
|
+
let k = 0;
|
|
377
|
+
while (k < words.length && ASSIGNMENT.test(words[k])) {
|
|
378
|
+
values.push(words[k].slice(words[k].indexOf('=') + 1));
|
|
379
|
+
k++;
|
|
380
|
+
}
|
|
381
|
+
const cmd = words[k];
|
|
382
|
+
if (cmd !== undefined && DECLARES.test(cmd)) {
|
|
383
|
+
for (const w of words.slice(k + 1))
|
|
384
|
+
if (ASSIGNMENT.test(w))
|
|
385
|
+
values.push(w.slice(w.indexOf('=') + 1));
|
|
386
|
+
return values.length > 0 ? values.join(' ') : null;
|
|
387
|
+
}
|
|
388
|
+
if (cmd === 'for' || cmd === 'select' || cmd === 'set' || cmd === 'getopts' || (cmd !== undefined && READS_INPUT.test(cmd)))
|
|
389
|
+
return words.slice(k + 1).join(' ');
|
|
390
|
+
if (cmd === 'printf' && words[k + 1] === '-v')
|
|
391
|
+
return words.slice(k + 2).join(' ');
|
|
392
|
+
return values.length > 0 ? values.join(' ') : null;
|
|
393
|
+
}
|
|
394
|
+
/** The program a stage hands to a shell, with its arguments, or null. */
|
|
395
|
+
function innerProgram(stage) {
|
|
396
|
+
const words = commandWords(stage);
|
|
397
|
+
let k = 0;
|
|
398
|
+
while (k < words.length && ASSIGNMENT.test(words[k]))
|
|
399
|
+
k++;
|
|
400
|
+
const cmd = words[k];
|
|
401
|
+
const unquote = (w) => w.replace(/^(['"])([\s\S]*)\1$/, '$2');
|
|
402
|
+
if (cmd === 'eval')
|
|
403
|
+
return { program: words.slice(k + 1).map(unquote).join(' '), args: '' };
|
|
404
|
+
if (cmd === undefined || !INNER_SHELL.test(cmd))
|
|
405
|
+
return null;
|
|
406
|
+
const c = words.findIndex((w, n) => n > k && /^-\w*c$/.test(w));
|
|
407
|
+
return c < 0 || words[c + 1] === undefined ? null : { program: unquote(words[c + 1]), args: words.slice(c + 2).join(' ') };
|
|
408
|
+
}
|
|
409
|
+
/** True when `cwd` is the project's store or inside it, judged against the project root (never a parent's name). */
|
|
410
|
+
function cwdInStore(cwd, root) {
|
|
411
|
+
if (typeof cwd !== 'string' || cwd === '' || typeof root !== 'string' || root === '')
|
|
412
|
+
return false;
|
|
413
|
+
return /^\.ax(?:[\\/]|$)/i.test(path.relative(path.resolve(root), path.resolve(cwd)));
|
|
414
|
+
}
|
|
415
|
+
const DEFINES_FUNCTION = /^(?:function\s+([A-Za-z_][\w-]*)|([A-Za-z_][\w-]*)\s*\(\s*\))/;
|
|
416
|
+
const CHANGES_DIR = new Set(['cd', 'pushd', 'popd']);
|
|
417
|
+
const changesDir = (stage) => {
|
|
418
|
+
const w = commandWords(stage);
|
|
419
|
+
while (w.length > 1 && /^(?:builtin|command|eval)$/.test(w[0]))
|
|
420
|
+
w.shift();
|
|
421
|
+
return w[0] !== undefined && CHANGES_DIR.has(w[0]);
|
|
422
|
+
};
|
|
423
|
+
/** A pipeline that opens or closes a compound command: the rule reads the compound whole. */
|
|
424
|
+
const COMPOUND = /^(?:do|done|then|else|elif|fi|esac|for|while|until|if|case|select|\{|\})(?:\s|$)/;
|
|
425
|
+
/** The name positional parameters count under. */
|
|
426
|
+
const POSITIONAL = '#positional';
|
|
427
|
+
/** The names a stage binds. */
|
|
428
|
+
function boundNames(stage) {
|
|
429
|
+
const words = commandWords(stage);
|
|
430
|
+
const names = [];
|
|
431
|
+
let k = 0;
|
|
432
|
+
const nameOf = (w) => w.slice(0, /[[+=]/.exec(w)?.index ?? w.length);
|
|
433
|
+
while (k < words.length && ASSIGNMENT.test(words[k]))
|
|
434
|
+
names.push(nameOf(words[k++]));
|
|
435
|
+
const cmd = words[k];
|
|
436
|
+
if (cmd === undefined)
|
|
437
|
+
return names;
|
|
438
|
+
if (DECLARES.test(cmd)) {
|
|
439
|
+
for (const w of words.slice(k + 1))
|
|
440
|
+
if (ASSIGNMENT.test(w))
|
|
441
|
+
names.push(nameOf(w));
|
|
442
|
+
}
|
|
443
|
+
else if (cmd === 'for' || cmd === 'select') {
|
|
444
|
+
if (words[k + 1] !== undefined)
|
|
445
|
+
names.push(words[k + 1]);
|
|
446
|
+
}
|
|
447
|
+
else if (READS_INPUT.test(cmd) || cmd === 'getopts') {
|
|
448
|
+
for (const w of words.slice(k + 1))
|
|
449
|
+
if (/^[A-Za-z_]\w*$/.test(w))
|
|
450
|
+
names.push(w);
|
|
451
|
+
}
|
|
452
|
+
else if (cmd === 'printf' && words[k + 1] === '-v' && words[k + 2] !== undefined)
|
|
453
|
+
names.push(words[k + 2]);
|
|
454
|
+
else if (cmd === 'set')
|
|
455
|
+
names.push(POSITIONAL);
|
|
456
|
+
return names;
|
|
457
|
+
}
|
|
458
|
+
/** The names a text expands; no text ever reaches a regular expression. */
|
|
459
|
+
const namesExpanded = (text) => {
|
|
460
|
+
const names = [...text.matchAll(/\$\{?[#!]?([A-Za-z_]\w*)/g)].map((m) => m[1]);
|
|
461
|
+
return /\$(?:[0-9@*]|\{[0-9@*])/.test(text) ? [...names, POSITIONAL] : names;
|
|
462
|
+
};
|
|
463
|
+
/** Hands a bound name to child processes: they read it without any `$` the text shows. */
|
|
464
|
+
const EXPORTS = /^(?:export|declare\s+-\w*x|typeset\s+-\w*x)\b/;
|
|
465
|
+
/** The scan's bounds (A-SPEC-794.38, 794.39): past one, the command is judged whole. */
|
|
466
|
+
const MAX_CHARS = 200_000;
|
|
467
|
+
const MAX_STAGES = 2_000;
|
|
468
|
+
const MAX_INNER = 16;
|
|
469
|
+
/**
|
|
470
|
+
* The text the not-a-read rule judges when a store path is built while the command runs, or null when none is: the
|
|
471
|
+
* pipelines such a path can reach, followed through the names that carry it. `pipelines` is the classifier's splitter,
|
|
472
|
+
* which keeps a pipeline whole (null when a quote is left open: the command is then one pipeline).
|
|
473
|
+
*/
|
|
474
|
+
function storePathBuiltJudgement(command, cwd, root, pipelines) {
|
|
475
|
+
const raw = String(command ?? '');
|
|
476
|
+
const asWritten = () => (cwdInStore(cwd, root) || namesStore(raw) ? { text: raw, whole: true } : null);
|
|
477
|
+
if (raw.length > MAX_CHARS)
|
|
478
|
+
return asWritten();
|
|
479
|
+
try {
|
|
480
|
+
return builtText(raw, cwd, root, pipelines, 0);
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
// A scan that overflowed read nothing with certainty
|
|
484
|
+
return asWritten();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
/** The text alone: what the predicate's own cases read. */
|
|
488
|
+
const storePathBuiltText = (command, cwd, root, pipelines) => storePathBuiltJudgement(command, cwd, root, pipelines)?.text ?? null;
|
|
489
|
+
exports.storePathBuiltText = storePathBuiltText;
|
|
490
|
+
function builtText(raw, cwd, root, pipelines, depth) {
|
|
491
|
+
const { text, whole } = commandText(raw);
|
|
492
|
+
const inStore = cwdInStore(cwd, root);
|
|
493
|
+
if (!inStore && !namesStore(text))
|
|
494
|
+
return null;
|
|
495
|
+
if (whole || depth > MAX_INNER)
|
|
496
|
+
return { text, whole: true };
|
|
497
|
+
const parts = (pipelines(text) ?? [text]).map((p) => p.trim()).filter((p) => p !== '');
|
|
498
|
+
const stages = parts.flatMap(stagesOf);
|
|
499
|
+
if (stages.length > MAX_STAGES)
|
|
500
|
+
return { text, whole: true };
|
|
501
|
+
const fns = new Set();
|
|
502
|
+
for (const p of parts) {
|
|
503
|
+
const m = DEFINES_FUNCTION.exec(p);
|
|
504
|
+
if (m)
|
|
505
|
+
fns.add(m[1] ?? m[2]);
|
|
506
|
+
}
|
|
507
|
+
const pipelineReadsStore = (stage) => READS_INPUT.test(commandWords(stage)[0] ?? '') && parts.some((p) => p.includes(stage) && namesStore(p));
|
|
508
|
+
const inner = stages.some((s) => {
|
|
509
|
+
const i = innerProgram(s);
|
|
510
|
+
if (i === null)
|
|
511
|
+
return false;
|
|
512
|
+
return builtText(i.program, null, null, pipelines, depth + 1) !== null || (namesStore(`${i.program} ${i.args}`) && /\$/.test(i.program));
|
|
513
|
+
});
|
|
514
|
+
const built = inner
|
|
515
|
+
|| stages.some((s) => { const v = boundValue(s); return (v !== null && namesStore(v)) || pipelineReadsStore(s); })
|
|
516
|
+
|| expansionsOf(text).some((e) => namesStore(e))
|
|
517
|
+
|| stages.some((s) => wordsOf(s).some(completesStorePath))
|
|
518
|
+
|| stages.some((s) => { const w = commandWords(s); return w[0] !== undefined && fns.has(w[0]) && namesStore(s); })
|
|
519
|
+
|| parts.some((p) => changesDir(p) && namesStore(p))
|
|
520
|
+
// A-SPEC-794.36 — inside the store a binding builds a path only when a value is expanded
|
|
521
|
+
|| (inStore && /[$`]/.test(text) && stages.some((s) => boundValue(s) !== null));
|
|
522
|
+
if (!built)
|
|
523
|
+
return null;
|
|
524
|
+
// The names that carry the path: bound from the store, or from a name that already carries it (inside the store: all).
|
|
525
|
+
const carried = new Set();
|
|
526
|
+
const carries = (names) => names.some((n) => carried.has(n));
|
|
527
|
+
const bindings = stages.flatMap((s) => {
|
|
528
|
+
const v = boundValue(s);
|
|
529
|
+
return v === null ? [] : [{ from: inStore || namesStore(v) || pipelineReadsStore(s), uses: namesExpanded(v), names: boundNames(s) }];
|
|
530
|
+
});
|
|
531
|
+
for (let grew = true; grew;) {
|
|
532
|
+
grew = false;
|
|
533
|
+
for (const b of bindings) {
|
|
534
|
+
if (b.from || carries(b.uses)) {
|
|
535
|
+
for (const n of b.names)
|
|
536
|
+
if (!carried.has(n)) {
|
|
537
|
+
carried.add(n);
|
|
538
|
+
grew = true;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (inner || fns.size > 0)
|
|
544
|
+
carried.add(POSITIONAL);
|
|
545
|
+
let everyLater = false;
|
|
546
|
+
return { whole: false, text: parts.filter((p) => {
|
|
547
|
+
const names = boundNames(p);
|
|
548
|
+
if (changesDir(p) || /\$\{!/.test(p) || (EXPORTS.test(p) && carries(names)))
|
|
549
|
+
everyLater = true;
|
|
550
|
+
return everyLater || namesStore(p) || COMPOUND.test(p) || carries(namesExpanded(p)) || carries(names) || (inStore && expansionsOf(p).length > 0);
|
|
551
|
+
}).join('\n') };
|
|
552
|
+
}
|
|
553
|
+
/** The refusal: what was judged, and the next act. */
|
|
554
|
+
exports.STORE_BUILT_REASON = 'shell command can write a .ax governance path it builds while it runs, and is not recognisably read-only — write with literal paths (a protected .ax path asks for an approval), or read with one read command and literal paths';
|
|
555
|
+
/** A-SPEC-794.40 — the command need not build anything: nothing here says it does, and the way through comes first. */
|
|
556
|
+
exports.STORE_WHOLE_REASON = 'shell command names .ax or runs inside it, and could not be read with certainty (a construct or a here-document this gate does not read, text that may run, or a very long command), so it was judged whole and is not recognisably read-only — remove the .ax mention, or split the command into separate calls, and it is judged again; a write to a protected .ax path with literal paths asks for an approval';
|
|
@@ -381,6 +381,9 @@ export interface ShellSegment {
|
|
|
381
381
|
* stages: it neither joins nor ends the parent's pipeline. */
|
|
382
382
|
nested?: true;
|
|
383
383
|
}
|
|
384
|
+
/** @implements A-SPEC-794.40 — the here-document word at `at`, or null; the sticky regular expression's state stays here. */
|
|
385
|
+
export declare const heredocAt: (s: string, at: number) => RegExpExecArray | null;
|
|
386
|
+
export declare const heredocDelimiter: (m: RegExpExecArray) => string;
|
|
384
387
|
/**
|
|
385
388
|
* @implements A-SPEC-728 (round 17)
|
|
386
389
|
* One shell word of a `cd`, reduced: adjacent quoted pieces join, a backslash escape drops. `null`
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.AX_CLIMB_BASES_MAX = exports.WIRING_FILE_NAMES = exports.PROJECT_CAPS_LABEL = exports.WIRING_DIR_NAMES = exports.GOVERNANCE_STORE_LABEL = exports.AX_PROTECTED_CHILDREN = exports.PATCH_TARGETS_MAX = exports.PATH_FIELDS = exports.READ_ONLY_TOOLS = void 0;
|
|
36
|
+
exports.heredocDelimiter = exports.heredocAt = exports.AX_CLIMB_BASES_MAX = exports.WIRING_FILE_NAMES = exports.PROJECT_CAPS_LABEL = exports.WIRING_DIR_NAMES = exports.GOVERNANCE_STORE_LABEL = exports.AX_PROTECTED_CHILDREN = exports.PATCH_TARGETS_MAX = exports.PATH_FIELDS = exports.READ_ONLY_TOOLS = void 0;
|
|
37
37
|
exports.absoluteKindOf = absoluteKindOf;
|
|
38
38
|
exports.foldsCaseBySyntax = foldsCaseBySyntax;
|
|
39
39
|
exports.writesFiles = writesFiles;
|
|
@@ -73,7 +73,7 @@ exports.commandBases = commandBases;
|
|
|
73
73
|
exports.shellSegments = shellSegments;
|
|
74
74
|
exports.resolvesInside = resolvesInside;
|
|
75
75
|
exports.foreignMcpPaths = foreignMcpPaths;
|
|
76
|
-
// @implements A-SPEC-728, A-SPEC-733, A-SPEC-163, A-SPEC-627, A-SPEC-768.2, A-SPEC-768.3, A-SPEC-163.8, A-SPEC-476.3, A-SPEC-476.7, A-SPEC-792.3
|
|
76
|
+
// @implements A-SPEC-728, A-SPEC-733, A-SPEC-163, A-SPEC-627, A-SPEC-768.2, A-SPEC-768.3, A-SPEC-163.8, A-SPEC-476.3, A-SPEC-476.7, A-SPEC-792.3, A-SPEC-794.38, A-SPEC-794.40
|
|
77
77
|
const fs = __importStar(require("node:fs"));
|
|
78
78
|
const path = __importStar(require("node:path"));
|
|
79
79
|
const os = __importStar(require("node:os"));
|
|
@@ -813,8 +813,14 @@ function expandHomeSpelling(raw, env = process.env, home = os.homedir()) {
|
|
|
813
813
|
s = s.replace(/\$\{HOME(?::?[-=?][^}]*)?\}|\$HOME\b/g, () => home);
|
|
814
814
|
if (env.CODEX_HOME)
|
|
815
815
|
s = s.replace(/\$\{CODEX_HOME(?::?[-=?][^}]*)?\}|\$CODEX_HOME\b/g, () => env.CODEX_HOME);
|
|
816
|
+
// @implements A-SPEC-792.39 — git's user config home, unset meaning `~/.config`.
|
|
817
|
+
s = s.replace(/\$\{XDG_CONFIG_HOME(?::?[-=?][^}]*)?\}|\$XDG_CONFIG_HOME\b/g, () => gitConfigHome(env, home));
|
|
816
818
|
return s.includes('$') ? null : s;
|
|
817
819
|
}
|
|
820
|
+
/** The directory git reads its user `git/config` and `git/attributes` from: `$XDG_CONFIG_HOME`, else `~/.config`. */
|
|
821
|
+
function gitConfigHome(env, home) {
|
|
822
|
+
return env.XDG_CONFIG_HOME && path.isAbsolute(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path.join(home, '.config');
|
|
823
|
+
}
|
|
818
824
|
/** The Codex homes whose config.toml/hooks.json Codex may load: `$CODEX_HOME` and the default `~/.codex`. */
|
|
819
825
|
function codexHomes(env, home) {
|
|
820
826
|
const out = [path.join(home, '.codex')];
|
|
@@ -866,6 +872,9 @@ function wiringDirs(root, env, home) {
|
|
|
866
872
|
// @implements A-SPEC-792.3 — the full autonomy profile: written by the operator CLI only; ~/.holmes itself is not
|
|
867
873
|
// wiring (its update cache and runtime copies keep their own rules).
|
|
868
874
|
{ dir: path.join(home, '.holmes'), name: /^full-autonomy\.json$/i, known: ['full-autonomy.json'], label: () => '~/.holmes/full-autonomy.json', dirIsWiring: false },
|
|
875
|
+
// @implements A-SPEC-792.39 — the user's global git config and attributes name programs every git child runs.
|
|
876
|
+
{ dir: home, name: /^\.gitconfig$/i, known: ['.gitconfig'], label: () => '~/.gitconfig', dirIsWiring: false },
|
|
877
|
+
{ dir: path.join(gitConfigHome(env, home), 'git'), name: /^(?:config|attributes)$/i, known: ['config', 'attributes'], label: (n) => `$XDG_CONFIG_HOME/git/${n}`, dirIsWiring: false },
|
|
869
878
|
];
|
|
870
879
|
if (root !== null) {
|
|
871
880
|
out.push({ dir: path.join(root, '.claude'), name: SETTINGS_NAME, known: ['settings.json', 'settings.local.json'], label: (n) => `.claude/${n}`, dirIsWiring: true }, { dir: root, name: /^\.mcp\.json$/i, known: ['.mcp.json'], label: () => '.mcp.json', dirIsWiring: false }, ...(capsOutOfScope ? [] : [{ dir: root, name: /^ax\.config\.json$/i, known: [exports.PROJECT_CAPS_LABEL], label: () => exports.PROJECT_CAPS_LABEL, dirIsWiring: false }]), { dir: path.join(root, '.agents'), name: /^(?:hooks|mcp_config)\.json$/i, known: ['hooks.json', 'mcp_config.json'], label: (n) => `.agents/${n}`, dirIsWiring: true }, { dir: path.join(root, '.codex'), name: /^(?:config\.toml|mcp_config\.json)$/i, known: ['config.toml', 'mcp_config.json'], label: (n) => `.codex/${n}`, dirIsWiring: true },
|
|
@@ -1519,13 +1528,26 @@ function protectedKindOf(root, raw) {
|
|
|
1519
1528
|
if (target === dir || target.startsWith(dir + '/'))
|
|
1520
1529
|
return d;
|
|
1521
1530
|
}
|
|
1531
|
+
// @implements A-SPEC-792.34 — what git runs: its config, info (attributes, excludes), hooks, and any .gitattributes
|
|
1532
|
+
for (const d of GIT_EXEC_SURFACE) {
|
|
1533
|
+
const dir = foldSep(pp.join(base, d)).toLowerCase();
|
|
1534
|
+
if (target === dir || target.startsWith(dir + '/'))
|
|
1535
|
+
return d;
|
|
1536
|
+
}
|
|
1537
|
+
if (target.split('/').pop() === '.gitattributes')
|
|
1538
|
+
return '.gitattributes';
|
|
1522
1539
|
return null;
|
|
1523
1540
|
}
|
|
1541
|
+
const GIT_EXEC_SURFACE = [path.join('.git', 'config'), path.join('.git', 'info'), path.join('.git', 'hooks')];
|
|
1524
1542
|
// @implements A-SPEC-728 (round 4) — sticky: matched AT each `<<` (a `.slice(k)` per `<<` was
|
|
1525
1543
|
// quadratic: 10 s on 50 000 of them). The delimiter is any shell word — `\EOF`, `1`, `EOF-X` —
|
|
1526
1544
|
// or a quoted one; the body ends at a line equal to it.
|
|
1527
1545
|
const HEREDOC_RE = /<<-?[ \t]*(?:(['"])([^'"\n]+)\1|\\?([^\s;&|<>()'"`$\\]+))/y;
|
|
1546
|
+
/** @implements A-SPEC-794.40 — the here-document word at `at`, or null; the sticky regular expression's state stays here. */
|
|
1547
|
+
const heredocAt = (s, at) => { HEREDOC_RE.lastIndex = at; return HEREDOC_RE.exec(s); };
|
|
1548
|
+
exports.heredocAt = heredocAt;
|
|
1528
1549
|
const heredocDelimiter = (m) => m[2] ?? m[3];
|
|
1550
|
+
exports.heredocDelimiter = heredocDelimiter;
|
|
1529
1551
|
const SHELL_STDIN_RE = /(?:^|[\s;|&(])(?:sh|bash|zsh|dash|ksh)\b[^<\n]*<</;
|
|
1530
1552
|
// @implements A-SPEC-728 (round 3) — a heredoc whose body an INTERPRETER reads is a program, not data.
|
|
1531
1553
|
const INTERP_STDIN_RE = /(?:^|[\s;|&(])(?:node|nodejs|python[0-9.]*|ruby|perl|php|deno|bun)\b[^<\n]*<</;
|
|
@@ -1568,8 +1590,7 @@ function unquotedHeredoc(line, st) {
|
|
|
1568
1590
|
continue;
|
|
1569
1591
|
} // `<<<` here-string
|
|
1570
1592
|
if (ch === '<' && line[k + 1] === '<' && found === null) {
|
|
1571
|
-
|
|
1572
|
-
const m = HEREDOC_RE.exec(line);
|
|
1593
|
+
const m = (0, exports.heredocAt)(line, k);
|
|
1573
1594
|
if (m) {
|
|
1574
1595
|
found = m;
|
|
1575
1596
|
k += m[0].length - 1;
|
|
@@ -2935,7 +2956,7 @@ function shellSegments(command, startBase, depth = 0, opts = {}) {
|
|
|
2935
2956
|
cur.push(line);
|
|
2936
2957
|
flush();
|
|
2937
2958
|
const body = [];
|
|
2938
|
-
const delim = heredocDelimiter(hd);
|
|
2959
|
+
const delim = (0, exports.heredocDelimiter)(hd);
|
|
2939
2960
|
for (i++; i < lines.length && lines[i].replace(/^\t+/, '') !== delim; i++)
|
|
2940
2961
|
body.push(lines[i]);
|
|
2941
2962
|
pieces.push({ text: body.join('\n'), kind: SHELL_STDIN_RE.test(line) ? 'prog' : INTERP_STDIN_RE.test(line) ? 'interp' : 'data' });
|