@sema-agent/core 7.61.0 → 7.63.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 +840 -0
- package/dist/agents/cascade.d.ts +11 -3
- package/dist/agents/cascade.js +1 -1
- package/dist/agents/peer-held-queue.d.ts +27 -4
- package/dist/agents/peer-held-queue.js +81 -36
- package/dist/agents/peer-session-drain.js +13 -3
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.d.ts +6 -1
- package/dist/agents/subagent.js +143 -58
- package/dist/agents/suspend-guard.d.ts +38 -16
- package/dist/agents/suspend-guard.js +9 -4
- package/dist/agents/verify.js +4 -3
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-features.d.ts +722 -0
- package/dist/core/checkpoint-features.js +98 -0
- package/dist/core/checkpoint-queries.d.ts +47 -4
- package/dist/core/checkpoint-queries.js +36 -16
- package/dist/core/checkpoint-requirements.d.ts +12 -5
- package/dist/core/checkpoint-requirements.js +11 -5
- package/dist/core/checkpoint-row-verdict.d.ts +110 -0
- package/dist/core/checkpoint-row-verdict.js +245 -0
- package/dist/core/checkpoint-store.d.ts +76 -753
- package/dist/core/checkpoint-store.js +83 -144
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/engine-attestation.d.ts +1 -1
- package/dist/core/engine-notice.d.ts +38 -7
- package/dist/core/engine-notice.js +9 -2
- package/dist/core/gate-fold.js +2 -2
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +9 -3
- package/dist/core/governance-codes.js +16 -3
- package/dist/core/hooks.d.ts +13 -0
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +1 -1
- package/dist/core/locked-config.d.ts +2 -2
- package/dist/core/mcp-host-seat.js +6 -1
- package/dist/core/memory-engine/consolidation-driver.d.ts +33 -18
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +73 -10
- package/dist/core/memory-engine/consolidation.js +167 -11
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +37 -35
- package/dist/core/memory-engine/delegation-settlement.js +53 -59
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +9 -5
- package/dist/core/memory-engine/engine.d.ts +98 -35
- package/dist/core/memory-engine/engine.js +477 -380
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +29 -3
- package/dist/core/memory-engine/file-backend.js +66 -35
- package/dist/core/memory-engine/index.d.ts +7 -7
- package/dist/core/memory-engine/index.js +6 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +121 -45
- package/dist/core/memory-engine/layout.js +252 -102
- package/dist/core/memory-engine/memory-backend-contract.d.ts +19 -1
- package/dist/core/memory-engine/memory-backend-contract.js +320 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +31 -8
- package/dist/core/memory-engine/memory-deployment.js +26 -12
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +3 -1
- package/dist/core/memory-engine/session-write-home.js +1 -1
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +118 -19
- package/dist/core/memory-engine/types.js +1 -0
- package/dist/core/memory-vector.d.ts +1 -1
- package/dist/core/memory.d.ts +10 -10
- package/dist/core/memory.js +15 -6
- package/dist/core/mode-policy.js +1 -1
- package/dist/core/mods/classic-events.d.ts +9 -1
- package/dist/core/mods/dollar.d.ts +32 -1
- package/dist/core/mods/dollar.js +13 -1
- package/dist/core/mods/kernel/events.d.ts +11 -3
- package/dist/core/mods/kernel/events.js +13 -10
- package/dist/core/mods/lifecycle-stations.d.ts +36 -4
- package/dist/core/mods/lifecycle-stations.js +44 -9
- package/dist/core/mods/session-append.d.ts +4 -1
- package/dist/core/mods/session-append.js +7 -0
- package/dist/core/mods/session-receive.js +12 -15
- package/dist/core/mods/stations.d.ts +70 -6
- package/dist/core/mods/stations.js +144 -1
- package/dist/core/own-property-receipt.d.ts +7 -0
- package/dist/core/own-property-receipt.js +3 -0
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/permission-rule-consent.d.ts +10 -3
- package/dist/core/permission-rule-consent.js +37 -24
- package/dist/core/permission-rule-store.d.ts +35 -1
- package/dist/core/permission-rule-store.js +27 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/read-root-candidate.js +1 -1
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/resume-startup-cause.d.ts +5 -4
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/compact-session.js +5 -2
- package/dist/core/runner/contracts.d.ts +36 -17
- package/dist/core/runner/delegation-owner.d.ts +43 -0
- package/dist/core/runner/delegation-owner.js +59 -0
- package/dist/core/runner/gate-exit.js +2 -2
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
- package/dist/core/runner/lineage-reroot-view.js +108 -0
- package/dist/core/runner/memory-consolidation-driver.d.ts +6 -3
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/permission-rule-lanes.d.ts +2 -1
- package/dist/core/runner/permission-rule-lanes.js +2 -2
- package/dist/core/runner/person-path-rows.d.ts +23 -3
- package/dist/core/runner/person-path-rows.js +31 -4
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
- package/dist/core/runner/prepare-ask-lane.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +6 -3
- package/dist/core/runner/prepare-config-doors.d.ts +6 -6
- package/dist/core/runner/prepare-config-doors.js +3 -4
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-hands-readface.d.ts +3 -2
- package/dist/core/runner/prepare-hands-readface.js +32 -10
- package/dist/core/runner/prepare-inherited-gate.d.ts +12 -8
- package/dist/core/runner/prepare-inherited-gate.js +14 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +3 -2
- package/dist/core/runner/prepare-memory.js +28 -20
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-task.js +22 -16
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/resume-admission.d.ts +3 -3
- package/dist/core/runner/resume-admission.js +6 -3
- package/dist/core/runner/resume-apply.d.ts +4 -0
- package/dist/core/runner/resume-apply.js +11 -4
- package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
- package/dist/core/runner/resume-checkpoint-screen.js +4 -84
- package/dist/core/runner/run-git-lane.d.ts +2 -0
- package/dist/core/runner/run-git-lane.js +4 -1
- package/dist/core/runner/run-harness-handlers.d.ts +2 -0
- package/dist/core/runner/run-harness-handlers.js +3 -2
- package/dist/core/runner/run-leg.js +25 -8
- package/dist/core/runner/run-settle-and-teardown.js +6 -4
- package/dist/core/runner/run-stop-and-final-verify.js +2 -1
- package/dist/core/runner/run-turn-boundary.js +7 -4
- package/dist/core/runner/runtask.js +6 -6
- package/dist/core/runner/steering-preview.d.ts +9 -0
- package/dist/core/runner/steering-preview.js +5 -0
- package/dist/core/runner/stream-steer-verb.js +8 -0
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner/tool-face-overlay.js +2 -0
- package/dist/core/runner/turn-attachments.d.ts +5 -0
- package/dist/core/runner/turn-attachments.js +1 -1
- package/dist/core/runner-deps.d.ts +8 -4
- package/dist/core/secret-env.d.ts +9 -6
- package/dist/core/secret-env.js +41 -22
- package/dist/core/session-checkout.d.ts +108 -0
- package/dist/core/session-checkout.js +485 -0
- package/dist/core/session-store.d.ts +13 -5
- package/dist/core/session-store.js +28 -4
- package/dist/core/session.d.ts +29 -5
- package/dist/core/session.js +3 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +6 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +73 -6
- package/dist/core/store-contracts/session-store-contract.js +61 -8
- package/dist/core/task-event.d.ts +28 -1
- package/dist/core/task-notification.d.ts +9 -1
- package/dist/core/task-notification.js +8 -1
- package/dist/core/task-registry-agent.d.ts +40 -8
- package/dist/core/task-registry-agent.js +57 -24
- package/dist/core/task-registry-shared.d.ts +33 -11
- package/dist/core/task-registry-workflow.js +4 -3
- package/dist/core/task-registry.d.ts +27 -10
- package/dist/core/task-registry.js +19 -13
- package/dist/core/task-result.d.ts +5 -5
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +21 -1
- package/dist/core/terminal-cause.d.ts +6 -6
- package/dist/core/tool-face.d.ts +6 -2
- package/dist/core/tool-face.js +1 -1
- package/dist/core/tool-policy.d.ts +16 -13
- package/dist/core/tool-policy.js +11 -10
- package/dist/core/tool-roster.d.ts +4 -4
- package/dist/core/tool-spec.d.ts +42 -19
- package/dist/core/types.d.ts +2 -2
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
- package/dist/engine/execution-env/node-execution-env.js +12 -5
- package/dist/engine/harness/types.d.ts +77 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/parent-chain-guard.d.ts +3 -3
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/path-to-root.d.ts +18 -3
- package/dist/engine/session/path-to-root.js +15 -1
- package/dist/engine/session/repo-utils.d.ts +12 -1
- package/dist/engine/session/repo-utils.js +41 -0
- package/dist/engine/session/session.d.ts +24 -1
- package/dist/engine/session/session.js +46 -2
- package/dist/engine/session/storage-base.d.ts +20 -0
- package/dist/engine/session/storage-base.js +28 -9
- package/dist/index.d.ts +16 -12
- package/dist/index.js +11 -8
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/orchestration/run-workflow-tool.d.ts +7 -1
- package/dist/orchestration/run-workflow-tool.js +28 -11
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow.d.ts +6 -0
- package/dist/orchestration/workflow.js +5 -8
- package/dist/stores/file/checkpoint-store.d.ts +2 -0
- package/dist/stores/file/checkpoint-store.js +7 -6
- package/dist/stores/file/fs-atomic.d.ts +0 -22
- package/dist/stores/file/fs-atomic.js +0 -17
- package/dist/stores/file/index.d.ts +2 -9
- package/dist/stores/file/index.js +2 -4
- package/dist/stores/file/session-store.d.ts +13 -7
- package/dist/stores/file/session-store.js +42 -18
- package/dist/tools/fs/bash-program-position.d.ts +3 -2
- package/dist/tools/fs/bash-program-position.js +10 -10
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +13 -1
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/removal-targets.js +5 -5
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +11 -2
- package/dist/tools/fs/shell-read-argv.js +45 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +20 -2
- package/dist/tools/fs/shell-read-bindings.js +153 -69
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.js +29 -11
- package/dist/tools/fs/shell-read-establish.js +43 -22
- package/dist/tools/fs/shell-read-functions.js +2 -2
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
- package/dist/tools/fs/shell-read-object-path.js +119 -0
- package/dist/tools/fs/shell-read-plan.d.ts +18 -0
- package/dist/tools/fs/shell-read-plan.js +217 -104
- package/dist/tools/fs/shell-read-start.d.ts +76 -13
- package/dist/tools/fs/shell-read-start.js +97 -17
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +54 -14
- package/dist/tools/fs/shell-read-workdir.js +103 -19
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +93 -43
- package/wire-changes/core-stores-sql@7.62.0.json +30 -0
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core@7.62.0.json +2181 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/mods-kernel@7.62.0.json +42 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/primitives@7.62.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/dist/core/consolidate-scope.d.ts +0 -93
- package/dist/core/consolidate-scope.js +0 -98
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
- package/dist/core/runner/memory-consolidation.d.ts +0 -109
- package/dist/core/runner/memory-consolidation.js +0 -251
|
@@ -3,6 +3,7 @@ import { shellWordsOf } from "../../shell/shell-words.js";
|
|
|
3
3
|
import { isShellSyntaxWord, LOOP_LIST_HEADS, readProgramPosition } from "./bash-program-position.js";
|
|
4
4
|
import { declaredAttributes, programRow, readArgRoles } from "./program-read-model.js";
|
|
5
5
|
import { codeBodies } from "./shell-reentry-text.js";
|
|
6
|
+
import { braceWordListsOf } from "./shell-read-brace.js";
|
|
6
7
|
import { BUILTIN_ENABLED, BUILTINS_ALL, ENABLE_BUILTIN, builtinKey, chainAvailability, enableBindings, isBuiltinKey, isDisabledValue, speaksFor } from "./shell-read-builtins.js";
|
|
7
8
|
export function judgedSpellingOf(v) {
|
|
8
9
|
if (v.glob !== true)
|
|
@@ -89,11 +90,14 @@ export function inheritedExportedFunctions(names) {
|
|
|
89
90
|
}
|
|
90
91
|
const ATTRIBUTE_KINDS = { integer: "integer", transformed: "transformed", frozen: "frozen" };
|
|
91
92
|
const EVERY_ATTRIBUTE = Object.values(ATTRIBUTE_KINDS).map((kind) => ({ kind }));
|
|
92
|
-
export function
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
export function projectSegments(segments) {
|
|
94
|
+
const { dropped, arms } = segmentStructure(segments);
|
|
95
|
+
return segments.map((segment, si) => projectSegment(segment, dropped[si], arms[si]));
|
|
96
|
+
}
|
|
97
|
+
function projectSegment(segment, dropped, arm) {
|
|
98
|
+
let grouped = segment.tokens.some((t) => t.kind === "group");
|
|
99
|
+
const defines = dropped.heads.flat();
|
|
100
|
+
const tokens = dropped.tokens.slice(arm.own.size === 0 ? 0 : Math.max(...arm.own) + 1);
|
|
97
101
|
const words = tokens.filter((t) => {
|
|
98
102
|
if (t.kind !== "word")
|
|
99
103
|
return false;
|
|
@@ -127,31 +131,96 @@ export function dropDefinitionHeads(tokens) {
|
|
|
127
131
|
}
|
|
128
132
|
return heads;
|
|
129
133
|
}
|
|
130
|
-
function
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
tokens.splice(0, end + 1);
|
|
134
|
+
function withoutDefinitionHeads(segment) {
|
|
135
|
+
const tokens = [...segment.tokens];
|
|
136
|
+
return { tokens, heads: dropDefinitionHeads(tokens) };
|
|
134
137
|
}
|
|
135
|
-
function
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
138
|
+
function segmentStructure(segments) {
|
|
139
|
+
const dropped = segments.map((segment) => withoutDefinitionHeads(segment));
|
|
140
|
+
const tokens = dropped.map((d) => d.tokens);
|
|
141
|
+
const operands = operandsOf(tokens, segments.map((segment) => isArithmeticCommand(segment)));
|
|
142
|
+
return { dropped, operands, arms: caseWordsOf(tokens, segments.map((s) => s.connector), operands) };
|
|
143
|
+
}
|
|
144
|
+
function operandsOf(segments, arithmetic) {
|
|
145
|
+
let conditional = false;
|
|
146
|
+
let parens = 0;
|
|
147
|
+
return segments.map((tokens, si) => {
|
|
148
|
+
const out = new Set();
|
|
149
|
+
tokens.forEach((t, k) => {
|
|
150
|
+
if (parens === 0 && !conditional) {
|
|
151
|
+
if (t.kind === "word" && t.atCommandPosition && t.raw === "[[")
|
|
152
|
+
conditional = true;
|
|
153
|
+
else if (t.kind === "group" && t.op === "(" && ((k === 0 && arithmetic[si] === true) || extglobParen(tokens, k))) {
|
|
154
|
+
parens = 1;
|
|
155
|
+
out.add(k);
|
|
156
|
+
}
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (parens === 0 && t.kind === "word" && t.raw === "]]") {
|
|
160
|
+
conditional = false;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
out.add(k);
|
|
164
|
+
if (parens > 0 && t.kind === "group")
|
|
165
|
+
parens += t.op === "(" ? 1 : -1;
|
|
166
|
+
});
|
|
167
|
+
return out;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function caseWordsOf(segments, connectors, operands) {
|
|
171
|
+
const frames = [];
|
|
172
|
+
const toPattern = (f) => { f.state = "pattern"; f.started = false; };
|
|
173
|
+
return segments.map((tokens, si) => {
|
|
174
|
+
const top = frames[frames.length - 1];
|
|
175
|
+
const next = connectors[si + 1];
|
|
176
|
+
if (top?.state === "arm" && tokens.length === 0 && connectors[si] === ";" && (next === ";" || next === "&"))
|
|
177
|
+
toPattern(top);
|
|
178
|
+
const own = new Set();
|
|
179
|
+
let end = -1;
|
|
180
|
+
tokens.forEach((t, k) => {
|
|
181
|
+
if (operands[si].has(k))
|
|
182
|
+
return;
|
|
183
|
+
const f = frames[frames.length - 1];
|
|
184
|
+
if (f === undefined || f.state === "arm") {
|
|
185
|
+
const keyword = t.kind === "word" && t.atCommandPosition && t.raw === t.folded ? t.folded : undefined;
|
|
186
|
+
if (keyword === "case")
|
|
187
|
+
frames.push({ state: "subject", started: false });
|
|
188
|
+
else if (keyword === "esac" && f !== undefined)
|
|
189
|
+
frames.pop();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (f.state === "subject") {
|
|
193
|
+
if (t.kind === "word") {
|
|
194
|
+
own.add(k);
|
|
195
|
+
f.state = "in";
|
|
196
|
+
}
|
|
197
|
+
else
|
|
198
|
+
frames.pop();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (f.state === "in") {
|
|
202
|
+
if (t.kind === "word" && t.raw === "in") {
|
|
203
|
+
own.add(k);
|
|
204
|
+
toPattern(f);
|
|
205
|
+
}
|
|
206
|
+
else
|
|
207
|
+
frames.pop();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (!f.started && t.kind === "word" && t.raw === "esac") {
|
|
211
|
+
frames.pop();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
own.add(k);
|
|
215
|
+
if (t.kind === "group" && t.op === ")") {
|
|
216
|
+
end = k;
|
|
217
|
+
f.state = "arm";
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
f.started = true;
|
|
221
|
+
});
|
|
222
|
+
return { own, end };
|
|
223
|
+
});
|
|
155
224
|
}
|
|
156
225
|
function extglobParen(tokens, at) {
|
|
157
226
|
const before = tokens[at - 1];
|
|
@@ -174,9 +243,11 @@ function blockStructure(segments) {
|
|
|
174
243
|
while (frames.length > 0 && frames[frames.length - 1].opened && depth <= frames[frames.length - 1].body.base)
|
|
175
244
|
frames.pop();
|
|
176
245
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const heads =
|
|
246
|
+
const { dropped, operands, arms } = segmentStructure(segments);
|
|
247
|
+
return segments.map((segment, si) => {
|
|
248
|
+
const { tokens, heads } = dropped[si];
|
|
249
|
+
const arm = arms[si];
|
|
250
|
+
const operand = operands[si];
|
|
180
251
|
const defs = [];
|
|
181
252
|
const startBodies = (k) => {
|
|
182
253
|
for (const name of heads[k]) {
|
|
@@ -186,40 +257,32 @@ function blockStructure(segments) {
|
|
|
186
257
|
}
|
|
187
258
|
};
|
|
188
259
|
const arithmetic = isArithmeticCommand(segment);
|
|
189
|
-
const patternEnd = casePatternEnd(tokens);
|
|
190
|
-
const skipped = new Set();
|
|
191
|
-
const open = [];
|
|
192
260
|
let lowest = depth;
|
|
193
261
|
let words;
|
|
194
262
|
let subshells;
|
|
195
263
|
let body;
|
|
264
|
+
let within = [];
|
|
196
265
|
const switches = [];
|
|
197
266
|
const innermost = () => [...frames].reverse().find((f) => f.opened)?.body;
|
|
267
|
+
const openBodies = () => frames.filter((f) => f.opened).map((f) => f.body.id);
|
|
268
|
+
const place = () => { words ??= depth; subshells ??= [...subshellStack]; body = innermost(); within = openBodies(); };
|
|
198
269
|
const visit = (t, k) => {
|
|
270
|
+
if (arm.own.has(k)) {
|
|
271
|
+
if (k === arm.end)
|
|
272
|
+
switches.push(depth);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (operand.has(k)) {
|
|
276
|
+
if (t.kind === "word")
|
|
277
|
+
place();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
199
280
|
if (t.kind === "group") {
|
|
200
|
-
if (arithmetic || skipped.has(k))
|
|
201
|
-
return;
|
|
202
281
|
if (t.op === "(") {
|
|
203
|
-
if (extglobParen(tokens, k)) {
|
|
204
|
-
skipped.add(k);
|
|
205
|
-
open.push(-1);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
open.push(k);
|
|
209
|
-
if (k <= patternEnd)
|
|
210
|
-
return;
|
|
211
282
|
deeper();
|
|
212
283
|
subshellStack.push(subshellIds++);
|
|
213
284
|
return;
|
|
214
285
|
}
|
|
215
|
-
const from = open.pop();
|
|
216
|
-
if (from === -1)
|
|
217
|
-
return;
|
|
218
|
-
if (k <= patternEnd) {
|
|
219
|
-
if (k === patternEnd)
|
|
220
|
-
switches.push(depth);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
286
|
shallower();
|
|
224
287
|
subshellStack.pop();
|
|
225
288
|
lowest = Math.min(lowest, depth);
|
|
@@ -236,11 +299,8 @@ function blockStructure(segments) {
|
|
|
236
299
|
}
|
|
237
300
|
else if (keyword !== undefined && SWITCHING_WORDS.has(keyword))
|
|
238
301
|
switches.push(depth);
|
|
239
|
-
else
|
|
240
|
-
|
|
241
|
-
subshells ??= [...subshellStack];
|
|
242
|
-
body = innermost();
|
|
243
|
-
}
|
|
302
|
+
else
|
|
303
|
+
place();
|
|
244
304
|
};
|
|
245
305
|
tokens.forEach((t, k) => {
|
|
246
306
|
startBodies(k);
|
|
@@ -257,8 +317,10 @@ function blockStructure(segments) {
|
|
|
257
317
|
else
|
|
258
318
|
f.flat = true;
|
|
259
319
|
}
|
|
260
|
-
if (settled && t.kind === "word")
|
|
320
|
+
if (settled && t.kind === "word") {
|
|
261
321
|
body = innermost();
|
|
322
|
+
within = openBodies();
|
|
323
|
+
}
|
|
262
324
|
const top = frames[frames.length - 1];
|
|
263
325
|
if (top?.parens !== undefined && t.kind === "group") {
|
|
264
326
|
top.parens += t.op === "(" ? 1 : -1;
|
|
@@ -272,7 +334,7 @@ function blockStructure(segments) {
|
|
|
272
334
|
while (frames.length > 0 && frames[frames.length - 1].flat === true)
|
|
273
335
|
frames.pop();
|
|
274
336
|
startBodies(tokens.length);
|
|
275
|
-
return { words: words ?? depth, after: depth, lowest, switches, subshells: subshells ?? [...subshellStack], defs, ...(body !== undefined ? { body } : {}) };
|
|
337
|
+
return { words: words ?? depth, after: depth, lowest, switches, subshells: subshells ?? [...subshellStack], defs, placed: words !== undefined, within, ...(body !== undefined ? { body } : {}) };
|
|
276
338
|
});
|
|
277
339
|
}
|
|
278
340
|
const READABLE_VALUE = /^[^\\~()]*$/;
|
|
@@ -528,7 +590,7 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
|
|
|
528
590
|
let state = "unknown";
|
|
529
591
|
if (ITERATING_HEADS.has(headWord) && inAt === loopAt + 2 && argv.length > loopAt + 3) {
|
|
530
592
|
const values = [];
|
|
531
|
-
for (const w of argv.slice(loopAt + 3)) {
|
|
593
|
+
for (const w of new Map(braceWordListsOf(argv.slice(loopAt + 3)).flat().map((x) => [x.raw, x])).values()) {
|
|
532
594
|
const v = readValue(w, false, overlay);
|
|
533
595
|
if (v === "unknown") {
|
|
534
596
|
values.length = 0;
|
|
@@ -547,13 +609,13 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
|
|
|
547
609
|
const pos = readProgramPosition(argv);
|
|
548
610
|
const program = pos.program;
|
|
549
611
|
const row = program === undefined ? undefined : programRow(program.basename);
|
|
550
|
-
const statement =
|
|
612
|
+
const statement = assignsAsStatement(pos);
|
|
551
613
|
for (const k of pos.assignments) {
|
|
552
614
|
const a = argv[k].assignment;
|
|
553
615
|
if (a === undefined)
|
|
554
616
|
continue;
|
|
555
617
|
if (statement)
|
|
556
|
-
bind({ name: a.name, state: assignedState(a, readValue, overlay), ...(a
|
|
618
|
+
bind({ name: a.name, state: assignedState(a, readValue, overlay), ...(bindsArrayElement(a) ? { floor: arrayElementFloor(a, readValue, overlay) } : {}) });
|
|
557
619
|
else if (program !== undefined && SPECIAL_BUILTINS.has(program.basename))
|
|
558
620
|
bind({ name: a.name, state: assignedState(a, readValue, overlay), prefix: true });
|
|
559
621
|
}
|
|
@@ -607,8 +669,8 @@ export function bindingEffectOf(segment, argv, shape, readValue, shadow, availab
|
|
|
607
669
|
if (name === undefined)
|
|
608
670
|
continue;
|
|
609
671
|
const refused = attributes.some((x) => x.name === undefined || x.name === name);
|
|
610
|
-
if (a
|
|
611
|
-
bind({ name, state: "unknown", floor:
|
|
672
|
+
if (a !== undefined && bindsArrayElement(a))
|
|
673
|
+
bind({ name, state: "unknown", floor: arrayElementFloor(a, readValue, expanded) });
|
|
612
674
|
else if (a === undefined || !storesText || refused)
|
|
613
675
|
kill(name);
|
|
614
676
|
else
|
|
@@ -686,8 +748,15 @@ function compoundElementWords(raw) {
|
|
|
686
748
|
return [prefix === undefined ? element : value, ...(folded !== undefined ? [{ pieces: element.pieces, folded: element.folded.slice(folded.length), tail: true }] : [])].filter((w) => w !== undefined);
|
|
687
749
|
});
|
|
688
750
|
}
|
|
689
|
-
function
|
|
690
|
-
return
|
|
751
|
+
export function bindsArrayElement(a) {
|
|
752
|
+
return a.form === "compound" || a.subscript !== undefined;
|
|
753
|
+
}
|
|
754
|
+
export function assignsAsStatement(pos) {
|
|
755
|
+
return pos.program === undefined && pos.launchers.length === 0 && pos.refusal === undefined;
|
|
756
|
+
}
|
|
757
|
+
function arrayElementFloor(a, readValue, overlay) {
|
|
758
|
+
const words = a.form === "compound" ? compoundElementWords(a.value.raw) : [{ pieces: a.value.pieces, folded: a.value.folded }];
|
|
759
|
+
return words.flatMap((w) => {
|
|
691
760
|
const v = w.tail === true ? "unknown" : readValue(w, true, overlay);
|
|
692
761
|
if (v !== "unknown")
|
|
693
762
|
return v.map(floorOf);
|
|
@@ -725,8 +794,9 @@ export function namesBoundIn(text, depth = 0) {
|
|
|
725
794
|
return "all";
|
|
726
795
|
const names = new Set();
|
|
727
796
|
const nothing = () => "unknown";
|
|
728
|
-
|
|
729
|
-
|
|
797
|
+
const projected = projectSegments(lexed.segments);
|
|
798
|
+
for (const [si, segment] of lexed.segments.entries()) {
|
|
799
|
+
const p = projected[si];
|
|
730
800
|
const effect = bindingEffectOf(segment, p.argv, p, nothing);
|
|
731
801
|
if (effect.all === "unknown")
|
|
732
802
|
return "all";
|
|
@@ -909,9 +979,23 @@ export class BindingThread {
|
|
|
909
979
|
const own = this.standingOf(at, b.name).body;
|
|
910
980
|
return own !== undefined && b.scope !== "local" ? own : undefined;
|
|
911
981
|
}
|
|
982
|
+
reaches(at, j) {
|
|
983
|
+
if (j !== undefined && !this.blocks[j].placed)
|
|
984
|
+
return true;
|
|
985
|
+
const s = this.standingOf(at);
|
|
986
|
+
const reader = j === undefined ? undefined : this.blocks[j];
|
|
987
|
+
if (s.body !== undefined && !(reader?.within ?? []).includes(s.body.id))
|
|
988
|
+
return false;
|
|
989
|
+
if (j !== at && this.ownSubshellAt(at, s))
|
|
990
|
+
return false;
|
|
991
|
+
return s.subshells.every((id) => (reader?.subshells ?? []).includes(id));
|
|
992
|
+
}
|
|
912
993
|
inFunctionBody(at) {
|
|
913
994
|
return this.blocks[at].body !== undefined;
|
|
914
995
|
}
|
|
996
|
+
bodyOf(at) {
|
|
997
|
+
return this.blocks[at].body?.id;
|
|
998
|
+
}
|
|
915
999
|
runsApart(at) {
|
|
916
1000
|
return this.blocks[at].subshells.length > 0 || this.ownSubshell[at] === true || this.blocks[at].body !== undefined;
|
|
917
1001
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brace expansion: the words bash makes of ONE word before any other expansion, in bash's order. A leaf (it reads the lexer
|
|
3
|
+
* only) so that every reader of the words a command runs with reads the same expansion — the plan's words of a simple
|
|
4
|
+
* command (shell-read-plan.ts, both faces) and the words a `for` list binds its variable to (shell-read-bindings.ts).
|
|
5
|
+
*/
|
|
6
|
+
import { type LexedWord } from "../../shell/lex.js";
|
|
7
|
+
/** How many readings one segment is read in — every combination of one value for each name its words may hold several
|
|
8
|
+
* values of — before the reader stops claiming to know those names; and how many words one word's braces may make before
|
|
9
|
+
* the reader stops reading them (the word then stays the word it is). */
|
|
10
|
+
export declare const READINGS_MAX = 64;
|
|
11
|
+
/** The bash releases whose brace expansion makes different words of one text: 3.2 (macOS's `/bin/bash`) and every release
|
|
12
|
+
* from 4.0 on, which pads a sequence written with a leading zero and reads a sequence's step (measured on 3.2.57 and 5.3.15).
|
|
13
|
+
* Which one runs a command is not in the text. */
|
|
14
|
+
export type BashRelease = "3.2" | "4+";
|
|
15
|
+
/** The words a list of words makes under each bash release the text may meet ({@link braceWordsOf}): one list where every
|
|
16
|
+
* release makes the same words, one per release where they differ — the command is then read once per list, as a word
|
|
17
|
+
* whose names hold several values is (`readInSeveral`), and a `for` list binds its variable to every list's words. */
|
|
18
|
+
export declare function braceWordListsOf(words: readonly LexedWord[]): readonly (readonly LexedWord[])[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { argvOf, lexShell } from "../../shell/lex.js";
|
|
2
|
+
export const READINGS_MAX = 64;
|
|
3
|
+
const BASH_RELEASES = ["3.2", "4+"];
|
|
4
|
+
export function braceWordListsOf(words) {
|
|
5
|
+
const lists = BASH_RELEASES.map((release) => words.flatMap((w) => braceWordsOf(w, release)));
|
|
6
|
+
const key = (list) => list.map((w) => w.raw).join("\u0000");
|
|
7
|
+
return lists.filter((list, i) => lists.findIndex((other) => key(other) === key(list)) === i);
|
|
8
|
+
}
|
|
9
|
+
function braceWordsOf(word, release) {
|
|
10
|
+
if (!word.pieces.some((p) => p.expansion?.kind === "brace"))
|
|
11
|
+
return [word];
|
|
12
|
+
const expand = (text) => {
|
|
13
|
+
const w = argumentLexOf(text);
|
|
14
|
+
if (w === undefined || w.unresolved !== undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
const list = w.pieces.map((p) => ({ p, alternatives: p.expansion?.kind === "brace" ? braceAlternativesOf(p.expansion.body ?? "", release) : undefined })).find((x) => x.alternatives !== undefined);
|
|
17
|
+
if (list === undefined)
|
|
18
|
+
return [w];
|
|
19
|
+
const made = [];
|
|
20
|
+
const [from, to] = [list.p.span[0] - 2, list.p.span[1] - 2];
|
|
21
|
+
for (const alternative of list.alternatives) {
|
|
22
|
+
const next = `${text.slice(0, from)}${alternative}${text.slice(to)}`;
|
|
23
|
+
if (next === "")
|
|
24
|
+
continue;
|
|
25
|
+
const words = expand(next);
|
|
26
|
+
if (words === undefined)
|
|
27
|
+
return undefined;
|
|
28
|
+
made.push(...words);
|
|
29
|
+
if (made.length > READINGS_MAX)
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return made;
|
|
33
|
+
};
|
|
34
|
+
const words = expand(word.raw);
|
|
35
|
+
return words === undefined || (words.length === 1 && words[0].raw === word.raw) ? [word] : words;
|
|
36
|
+
}
|
|
37
|
+
function argumentLexOf(text) {
|
|
38
|
+
const lexed = lexShell(`: ${text}`);
|
|
39
|
+
const words = "parseFailure" in lexed || lexed.segments.length !== 1 ? undefined : argvOf(lexed.segments[0]);
|
|
40
|
+
return words?.length === 2 && words[1].raw === text ? words[1] : undefined;
|
|
41
|
+
}
|
|
42
|
+
function braceAlternativesOf(body, release) {
|
|
43
|
+
const lexed = lexShell(`""${body}`);
|
|
44
|
+
const words = "parseFailure" in lexed || lexed.segments.length !== 1 ? undefined : argvOf(lexed.segments[0]);
|
|
45
|
+
if (words?.length !== 1)
|
|
46
|
+
return undefined;
|
|
47
|
+
const cuts = [];
|
|
48
|
+
for (const p of words[0].pieces)
|
|
49
|
+
if (p.quotedBy === undefined && p.literal !== undefined)
|
|
50
|
+
for (let i = p.literal.indexOf(","); i >= 0; i = p.literal.indexOf(",", i + 1))
|
|
51
|
+
cuts.push(p.span[0] - 2 + i);
|
|
52
|
+
if (cuts.length === 0)
|
|
53
|
+
return sequenceAlternativesOf(body, release);
|
|
54
|
+
return [...cuts, body.length].map((cut, k) => body.slice(k === 0 ? 0 : cuts[k - 1] + 1, cut));
|
|
55
|
+
}
|
|
56
|
+
function sequenceAlternativesOf(body, release) {
|
|
57
|
+
const m = /^([+-]?\d+|[A-Za-z])\.\.([+-]?\d+|[A-Za-z])(?:\.\.([+-]?\d+))?$/.exec(body);
|
|
58
|
+
if (m === null)
|
|
59
|
+
return undefined;
|
|
60
|
+
const [lhs, rhs, step] = [m[1], m[2], m[3]];
|
|
61
|
+
const letter = (t) => /^[A-Za-z]$/.test(t);
|
|
62
|
+
if (letter(lhs) !== letter(rhs))
|
|
63
|
+
return undefined;
|
|
64
|
+
if (step !== undefined && release === "3.2")
|
|
65
|
+
return [`\\{${body}\\}`];
|
|
66
|
+
const [from, to] = letter(lhs) ? [lhs.charCodeAt(0), rhs.charCodeAt(0)] : [Number(lhs), Number(rhs)];
|
|
67
|
+
const incr = Math.abs(step === undefined ? 1 : Number(step)) || 1;
|
|
68
|
+
if (![from, to, incr].every(Number.isSafeInteger) || Math.abs(to - from) / incr >= READINGS_MAX)
|
|
69
|
+
return undefined;
|
|
70
|
+
const terms = [];
|
|
71
|
+
for (let v = from; from <= to ? v <= to : v >= to; v += from <= to ? incr : -incr)
|
|
72
|
+
terms.push(v);
|
|
73
|
+
if (letter(lhs)) {
|
|
74
|
+
const chars = terms.map((c) => String.fromCharCode(c));
|
|
75
|
+
return chars.every(letter) ? chars : undefined;
|
|
76
|
+
}
|
|
77
|
+
const width = release === "3.2" || ![lhs, rhs].some((t) => /^-?0\d/.test(t)) ? 0 : Math.max(lhs.length, rhs.length);
|
|
78
|
+
return terms.map((v) => (width === 0 ? String(v) : v < 0 ? `-${String(-v).padStart(width - 1, "0")}` : String(v).padStart(width, "0")));
|
|
79
|
+
}
|
|
@@ -12,7 +12,7 @@ import { declaredReadDenyHomes, homeViewsAt } from "./read-deny-home.js";
|
|
|
12
12
|
import { anyOptionWord, programArgs } from "./shell-read-write-targets.js";
|
|
13
13
|
import { shellReadFaceWords } from "./shell-read-face.js";
|
|
14
14
|
import { passesUnasked } from "./shell-read-device.js";
|
|
15
|
-
import { programRow, selectedOptions } from "./program-read-model.js";
|
|
15
|
+
import { operandWriterNames, programKeyOf, programRow, selectedOptions } from "./program-read-model.js";
|
|
16
16
|
import { refusedByRemoval, SHELL_REMOVAL_COMMANDS } from "./removal-targets.js";
|
|
17
17
|
import { allFindings, anyFaceGuards, decideShellRead, denyRowAtOrBelow, foldShellReadFindings, judgeEstablishedPlan, readRootGrantCandidateOf, stationGuards, writeFaceGuards, } from "./shell-read-judge.js";
|
|
18
18
|
import { seatOf } from "../../core/tool-name-readings.js";
|
|
@@ -57,7 +57,7 @@ function runOrderOf(judged) {
|
|
|
57
57
|
return { runs, plans, concurrent };
|
|
58
58
|
}
|
|
59
59
|
function lineOrderPlaced(runs, concurrent) {
|
|
60
|
-
const reshapes = (s) => RESHAPES_TREE.has(s.segment.verb?.basename ?? "");
|
|
60
|
+
const reshapes = (s) => RESHAPES_TREE.has(programKeyOf(s.segment.verb?.basename ?? ""));
|
|
61
61
|
const writes = (s) => s.findings.some((f) => f.read.candidate.face === "write");
|
|
62
62
|
const stepsUp = (s) => s.findings.some((f) => f.read.candidate.spelled.split(/[\\/]/).includes(".."));
|
|
63
63
|
return runs.every((later, j) => runs.every((earlier, i) => i === j || (i > j && !concurrent) || (!reshapes(earlier) && !(writes(earlier) && stepsUp(later)))));
|
|
@@ -68,7 +68,7 @@ function writesPlacedOf(judged, boundary) {
|
|
|
68
68
|
return false;
|
|
69
69
|
const { runs, plans, concurrent } = runOrderOf(judged);
|
|
70
70
|
const placed = (s) => {
|
|
71
|
-
const verb = s.segment.verb?.basename ?? "";
|
|
71
|
+
const verb = programKeyOf(s.segment.verb?.basename ?? "");
|
|
72
72
|
if (s.segment.reentry === "shell" || s.segment.unreadProgramText !== undefined)
|
|
73
73
|
return false;
|
|
74
74
|
if (UNPLACED_OPTIONS[verb]?.(programArgs(s.segment).map((w) => w.spelled)) === true)
|
|
@@ -95,7 +95,7 @@ function unplacedOptionsOf(judged) {
|
|
|
95
95
|
const nested = s.nested.map(unplacedOptionsOf).find((u) => u !== undefined);
|
|
96
96
|
if (nested !== undefined)
|
|
97
97
|
return nested;
|
|
98
|
-
const verb = s.segment.verb
|
|
98
|
+
const verb = s.segment.verb === undefined ? undefined : programKeyOf(s.segment.verb.basename);
|
|
99
99
|
if ((verb === "cp" || verb === "mv") && anyOptionWord(programArgs(s.segment).map((w) => w.spelled)))
|
|
100
100
|
return { program: verb };
|
|
101
101
|
}
|
|
@@ -302,16 +302,33 @@ function refusalOf(tool, fold, boundary, paths) {
|
|
|
302
302
|
if (fold.finding === "deny_hit" && w?.deny !== undefined) {
|
|
303
303
|
const target = w.read.target ?? w.deny.matchedView;
|
|
304
304
|
const write = w.deny.face === "write";
|
|
305
|
-
const core = readDenySentence({ target, pattern: w.deny.pattern, matchedView: w.deny.matchedView, ...(write ? { face: "write" } : {}) });
|
|
306
|
-
const
|
|
305
|
+
const core = readDenySentence({ target, pattern: w.deny.pattern, matchedView: w.deny.matchedView, ...(write ? { face: "write" } : {}), ...(w.deny.readRow === true ? { readRow: true } : {}) });
|
|
306
|
+
const through = deniedThrough(w.read, boundary);
|
|
307
|
+
const sentence = `Error (${tool}): ${core} ${write ? writeDenyRefusalNote() : DENY_REFUSAL_NOTE}${through !== undefined ? ` ${DENIED_THROUGH_NOTE[through]}` : ""}`;
|
|
307
308
|
return { sentence, ...(write ? {} : { details: violationDetails({ code: "read_path_denied", message: sentence, target, pattern: w.deny.pattern }) }) };
|
|
308
309
|
}
|
|
309
310
|
const account = findingAccount(fold, boundary);
|
|
310
311
|
const sentence = `Error (${tool}): ${account}. ${BASH_READONLY_CONFINEMENT_NOTE}`;
|
|
311
312
|
return { sentence, details: findingDetails(fold.finding, paths) };
|
|
312
313
|
}
|
|
313
|
-
const
|
|
314
|
-
"
|
|
314
|
+
const DENIED_THROUGH_NOTE = {
|
|
315
|
+
home: "The word was judged as spelled with the environment's declared home: the command may rebind HOME before it, or hands " +
|
|
316
|
+
"the program a literal ~ it may expand itself — the shell may open another file, and a deny row is refused wherever the command may read it.",
|
|
317
|
+
floor: "The working directory at this word is not settled — a move before it may fail or is one this boundary does not follow — " +
|
|
318
|
+
"so the word was also judged where the command stood before that move (a bare cd stands it in the declared home).",
|
|
319
|
+
};
|
|
320
|
+
function deniedThrough(read, boundary) {
|
|
321
|
+
if (read.established === "unestablishable" && read.candidate.bases === "unmodelled")
|
|
322
|
+
return "floor";
|
|
323
|
+
const home = boundary.homeDir;
|
|
324
|
+
if (read.candidate.denyOnly === true && home !== undefined && withinAnyRoot([home], read.candidate.spelled) && /~|HOME/.test(read.candidate.raw))
|
|
325
|
+
return "home";
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
function writeDenyRefusalNote() {
|
|
329
|
+
const names = operandWriterNames();
|
|
330
|
+
return `The boundary judges this command's write targets — its output redirections and the operands of ${names.slice(0, -1).join(", ")} and ${names.at(-1)} — against the write deny list; a denied write is refused here rather than escalated.`;
|
|
331
|
+
}
|
|
315
332
|
const DENY_REFUSAL_NOTE = "The read boundary judges the paths this command names — as written and, where a filesystem can be consulted, where " +
|
|
316
333
|
"they resolve and what a pattern among them matches — and refuses a deny-listed one here rather than escalating it; " +
|
|
317
334
|
"a file the command reaches without naming it is judged only where a segment deny row (built in, or the deployment's " +
|
|
@@ -343,8 +360,9 @@ function verdictOf(tool, seat, fold, judged, boundary) {
|
|
|
343
360
|
...(grant !== undefined ? { readRootCandidate: { dir: grant.dir, ...(grant.covers !== undefined ? { covers: grant.covers } : {}), clearsThisAsk: true } } : {}),
|
|
344
361
|
};
|
|
345
362
|
}
|
|
346
|
-
function declarationsOf(boundary, readers, cdPath) {
|
|
347
|
-
|
|
363
|
+
function declarationsOf(boundary, readers, cdPath, receivedEnvNames) {
|
|
364
|
+
const names = Array.isArray(receivedEnvNames) && receivedEnvNames.every((n) => typeof n === "string") ? { receivedEnvNames: receivedEnvNames } : {};
|
|
365
|
+
return { readers, cwd: boundary.cwd ?? boundary.roots[0] ?? "", roots: boundary.roots, cdPath, ...names, ...(boundary.homeDir !== undefined ? { homeDir: boundary.homeDir } : {}), ...(boundary.face !== undefined ? { face: boundary.face } : {}) };
|
|
348
366
|
}
|
|
349
367
|
function judgePlan(plan, established, boundary) {
|
|
350
368
|
return judgeEstablishedPlan(plan, established.reads, boundary, (n) => {
|
|
@@ -381,7 +399,7 @@ async function applyAlsoInside(judged, boundary) {
|
|
|
381
399
|
return rewrite(judged);
|
|
382
400
|
}
|
|
383
401
|
async function runShellReadStation(tool, command, declared, seat, readers, establisher, env, signal) {
|
|
384
|
-
const plan = planShellReads(command, declarationsOf(declared, readers, env.cdPath));
|
|
402
|
+
const plan = planShellReads(command, declarationsOf(declared, readers, env.cdPath, env.receivedEnvNames));
|
|
385
403
|
const door = observeEnvironment(env);
|
|
386
404
|
const established = await establisher.establish(plan, declared, signal, door);
|
|
387
405
|
const boundary = { ...declared, roots: established.roots };
|
|
@@ -7,6 +7,7 @@ import { movedReads, withHomeViews } from "./shell-read-identity.js";
|
|
|
7
7
|
import { passesUnasked } from "./shell-read-device.js";
|
|
8
8
|
import { compileFsGlob, fsGlobClass } from "./fs-glob.js";
|
|
9
9
|
import { chainHopsOrNone, leafChainMayHold, symlinkChainHops } from "../../core/path-identity.js";
|
|
10
|
+
import { everyAncestor, repositoryTopOf } from "./shell-read-object-path.js";
|
|
10
11
|
const GLOB_METACHAR_RE = /[*?[]/;
|
|
11
12
|
export const MAX_GLOB_DIRS = 256;
|
|
12
13
|
export const MAX_GLOB_MATCHES = 8192;
|
|
@@ -92,28 +93,33 @@ function pathSegmentsFrom(p, from, posix = false) {
|
|
|
92
93
|
function basesFor(candidate, boundary) {
|
|
93
94
|
if (candidate.bases === "unmodelled")
|
|
94
95
|
return "unmodelled";
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return [boundary.cwd ?? boundary.roots[0] ?? ""];
|
|
96
|
+
const bases = candidate.bases.length > 0 ? candidate.bases : [boundary.cwd ?? boundary.roots[0] ?? ""];
|
|
97
|
+
return candidate.repositoryTop !== undefined ? everyAncestor(bases) : bases;
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
function placedSpellings(spelled, bases, homeDir) {
|
|
100
|
+
const out = [];
|
|
101
|
+
for (const base of bases) {
|
|
102
|
+
const at = resolveOperandSpellings(base === "" ? undefined : base, spelled, homeDir);
|
|
103
|
+
if (at === undefined)
|
|
104
|
+
continue;
|
|
105
|
+
out.push(at.folded);
|
|
106
|
+
if (at.spelled !== undefined)
|
|
107
|
+
out.push(at.spelled);
|
|
102
108
|
}
|
|
103
|
-
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
function lexicalReadsOf(candidate, boundary, placed) {
|
|
112
|
+
const rewritten = candidate.expands === "unresolvable" ? `"${candidate.raw}" is rewritten by the shell before the program sees it` : undefined;
|
|
113
|
+
const bases = placed ?? basesFor(candidate, boundary);
|
|
104
114
|
if (bases === "unmodelled") {
|
|
105
|
-
const
|
|
106
|
-
const spellings = [candidate.spelled];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
continue;
|
|
111
|
-
spellings.push(viaFloor.folded);
|
|
112
|
-
if (viaFloor.spelled !== undefined)
|
|
113
|
-
spellings.push(viaFloor.spelled);
|
|
114
|
-
}
|
|
115
|
-
return [{ candidate, established: "unestablishable", spellings, cause: `"${candidate.raw}" is relative to a working directory this command's text does not settle` }];
|
|
115
|
+
const floorsAt = candidate.floorBases ?? [boundary.cwd ?? boundary.roots[0] ?? ""];
|
|
116
|
+
const spellings = [candidate.spelled, ...placedSpellings(candidate.spelled, floorsAt.filter((f) => f !== ""), boundary.homeDir)];
|
|
117
|
+
const anywhereAbove = candidate.repositoryTop !== undefined || candidate.unsettledStart === true;
|
|
118
|
+
const ancestorViews = anywhereAbove ? [...new Set(placedSpellings(candidate.spelled, everyAncestor(floorsAt.filter((f) => f !== "")), boundary.homeDir))].filter((v) => !spellings.includes(v)) : [];
|
|
119
|
+
return [{ candidate, established: "unestablishable", spellings, ...(ancestorViews.length > 0 ? { ancestorViews } : {}), cause: rewritten ?? `"${candidate.raw}" is relative to a working directory this command's text does not settle` }];
|
|
116
120
|
}
|
|
121
|
+
if (rewritten !== undefined)
|
|
122
|
+
return [{ candidate, established: "unestablishable", spellings: [...new Set([candidate.spelled, ...placedSpellings(candidate.spelled, bases, boundary.homeDir)])], cause: rewritten }];
|
|
117
123
|
const out = [];
|
|
118
124
|
const seen = new Set();
|
|
119
125
|
for (const base of bases) {
|
|
@@ -173,8 +179,10 @@ function writtenByText(plan, boundary) {
|
|
|
173
179
|
return { targets, unplaced };
|
|
174
180
|
}
|
|
175
181
|
function unfollowedBackupReads(j, boundary, cause) {
|
|
176
|
-
const
|
|
177
|
-
const
|
|
182
|
+
const named = sedBackupNames(j.followed.operand.spelled, j.followed.suffix).flatMap((name) => lexicalReadsOf({ ...j.candidate, spelled: name }, boundary));
|
|
183
|
+
const spellings = named.flatMap((r) => [...(r.target !== undefined ? [r.target] : []), ...r.spellings]);
|
|
184
|
+
const ancestorViews = [...new Set(named.flatMap((r) => r.ancestorViews ?? []))];
|
|
185
|
+
const read = { candidate: j.candidate, established: "unestablishable", spellings: [...new Set(spellings)], ...(ancestorViews.length > 0 ? { ancestorViews } : {}), cause };
|
|
178
186
|
return (j.seats ?? ["landing"]).map((seat) => writtenAt(read, j, seat));
|
|
179
187
|
}
|
|
180
188
|
function writtenAt(read, j, seat) {
|
|
@@ -226,6 +234,18 @@ function establishLegOver(seen, readRoots) {
|
|
|
226
234
|
const SEP = family === "posix" ? /\// : /[\\/]/;
|
|
227
235
|
const TRAILING_SEP = family === "posix" ? /\/+$/ : /[\\/]+$/;
|
|
228
236
|
const joinUnder = (dir, name) => `${dir.replace(TRAILING_SEP, "")}/${name}`;
|
|
237
|
+
const tops = new Map();
|
|
238
|
+
const atRepositoryTops = async (starts, signal) => {
|
|
239
|
+
const out = new Set();
|
|
240
|
+
for (const start of starts) {
|
|
241
|
+
if (!tops.has(start))
|
|
242
|
+
tops.set(start, repositoryTopOf(env, start, family, signal));
|
|
243
|
+
const top = await tops.get(start);
|
|
244
|
+
for (const b of top !== undefined ? [top] : everyAncestor([start]))
|
|
245
|
+
out.add(b);
|
|
246
|
+
}
|
|
247
|
+
return [...out];
|
|
248
|
+
};
|
|
229
249
|
const resolveWithoutParentSteps = async (p, signal, writeTarget = false, linkHops = WRITE_LINK_HOPS) => {
|
|
230
250
|
const parts = p.split(SEP);
|
|
231
251
|
const tail = [];
|
|
@@ -521,7 +541,8 @@ function establishLegOver(seen, readRoots) {
|
|
|
521
541
|
const node = await rootKindOf(read.target, signal);
|
|
522
542
|
out.push({ ...read, ...(node !== undefined ? { node } : {}) });
|
|
523
543
|
};
|
|
524
|
-
|
|
544
|
+
const placed = candidate.repositoryTop === "discovered" && candidate.bases !== "unmodelled" && candidate.bases.length > 0 ? await atRepositoryTops(candidate.bases, signal) : undefined;
|
|
545
|
+
for (const [i, lexical] of lexicalReadsOf(candidate, boundary, placed).entries()) {
|
|
525
546
|
if (lexical.established !== "lexical" || passesUnasked(candidate)) {
|
|
526
547
|
out.push(writtenAt(lexical, writtenSeats, writtenSeats.written.includes("landing") ? "landing" : "entry"));
|
|
527
548
|
continue;
|
|
@@ -531,7 +552,7 @@ function establishLegOver(seen, readRoots) {
|
|
|
531
552
|
const walked = spellings.find((s) => s !== folded) ?? folded;
|
|
532
553
|
if (candidate.expands === "glob") {
|
|
533
554
|
let matched = false;
|
|
534
|
-
for (const p of candidate.pattern === undefined ? spellings : lexicalReadsOf({ ...candidate, spelled: candidate.pattern }, boundary)[i]?.spellings ?? spellings) {
|
|
555
|
+
for (const p of candidate.pattern === undefined ? spellings : lexicalReadsOf({ ...candidate, spelled: candidate.pattern }, boundary, placed)[i]?.spellings ?? spellings) {
|
|
535
556
|
const expanded = await expandGlobCandidate(p, roots, signal);
|
|
536
557
|
if (expanded !== undefined && "unverifiable" in expanded) {
|
|
537
558
|
out.push({ candidate, established: "unestablishable", spellings, origin: folded, cause: expanded.unverifiable });
|