@sema-agent/core 7.68.5 → 7.68.7
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 +55 -0
- package/dist/core/allow-entry.d.ts +2 -2
- package/dist/core/allow-entry.js +6 -5
- package/dist/core/ask-headline.d.ts +2 -2
- package/dist/core/ask-origin.d.ts +31 -31
- package/dist/core/ask-origin.js +20 -13
- package/dist/core/permission-rule-model.js +3 -2
- package/dist/core/shell-read-silence.d.ts +2 -1
- package/dist/core/tool-policy.d.ts +4 -1
- package/dist/core/tool-policy.js +2 -2
- package/dist/shell/lex.d.ts +27 -4
- package/dist/shell/lex.js +128 -56
- package/dist/tools/fs/bash-readonly-classifier.js +7 -3
- package/dist/tools/fs/fs-bash.js +4 -4
- package/dist/tools/fs/removal-targets.d.ts +5 -4
- package/dist/tools/fs/removal-targets.js +14 -14
- package/dist/tools/fs/safety.d.ts +23 -4
- package/dist/tools/fs/safety.js +38 -1
- package/dist/tools/fs/shell-read-plan.d.ts +8 -2
- package/dist/tools/fs/shell-read-plan.js +16 -6
- package/dist/tools/fs/shell-read-sourced.js +3 -2
- package/package.json +2 -2
- package/wire-changes/core-stores-sql@7.68.6.json +39 -0
- package/wire-changes/core-stores-sql@7.68.7.json +39 -0
- package/wire-changes/core@7.68.6.json +125 -0
- package/wire-changes/core@7.68.7.json +140 -0
- package/wire-changes/mods-kernel@7.68.6.json +39 -0
- package/wire-changes/mods-kernel@7.68.7.json +39 -0
- package/wire-changes/primitives@7.68.6.json +39 -0
- package/wire-changes/primitives@7.68.7.json +39 -0
- package/wire-changes/wiki-gate@7.68.6.json +39 -0
- package/wire-changes/wiki-gate@7.68.7.json +39 -0
package/dist/shell/lex.js
CHANGED
|
@@ -164,14 +164,17 @@ function documentLine(text, p, joined) {
|
|
|
164
164
|
}
|
|
165
165
|
return { line, nl };
|
|
166
166
|
}
|
|
167
|
-
function heredocBodies(text, from, headers, closer) {
|
|
167
|
+
function heredocBodies(text, from, headers, closer, toEnd = false) {
|
|
168
168
|
const bodies = [];
|
|
169
169
|
let p = from;
|
|
170
170
|
for (const h of headers) {
|
|
171
171
|
const lines = [];
|
|
172
172
|
for (;;) {
|
|
173
|
-
if (p > text.length)
|
|
173
|
+
if (p > text.length) {
|
|
174
|
+
if (toEnd)
|
|
175
|
+
break;
|
|
174
176
|
return "unterminated";
|
|
177
|
+
}
|
|
175
178
|
const { line, nl } = documentLine(text, p, !h.quoted);
|
|
176
179
|
if (closer !== undefined && text.slice(p, nl < 0 ? text.length : nl + 1).includes("\\\n"))
|
|
177
180
|
return "ambiguous";
|
|
@@ -182,8 +185,14 @@ function heredocBodies(text, from, headers, closer) {
|
|
|
182
185
|
}
|
|
183
186
|
if (closer !== undefined && compared.startsWith(h.delimiter) && (closer === ")" ? compared.indexOf(")", h.delimiter.length) >= 0 : /^[ \t]*\}/.test(compared.slice(h.delimiter.length))))
|
|
184
187
|
return "ambiguous";
|
|
185
|
-
if (nl < 0)
|
|
186
|
-
|
|
188
|
+
if (nl < 0) {
|
|
189
|
+
if (!toEnd)
|
|
190
|
+
return "unterminated";
|
|
191
|
+
if (p < text.length)
|
|
192
|
+
lines.push(line);
|
|
193
|
+
p = text.length + 1;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
187
196
|
lines.push(line);
|
|
188
197
|
p = nl + 1;
|
|
189
198
|
}
|
|
@@ -642,58 +651,56 @@ export function expansionsInHeredocBody(body) {
|
|
|
642
651
|
}
|
|
643
652
|
function expansionsInBody(body) {
|
|
644
653
|
const out = [];
|
|
645
|
-
const push = (x, start, last) => (out.push({ ...x, span: [start, last + 1] }), last);
|
|
646
654
|
for (let i = 0; i < body.length; i++) {
|
|
647
|
-
|
|
648
|
-
if (ch === "\\") {
|
|
655
|
+
if (body[i] === "\\") {
|
|
649
656
|
i++;
|
|
650
657
|
continue;
|
|
651
658
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
i = push({ expansion: { kind: "command", yields: "one", body: tick.body } }, i, tick.close);
|
|
657
|
-
continue;
|
|
658
|
-
}
|
|
659
|
-
if (ch !== "$")
|
|
659
|
+
const at = bodyExpansionAt(body, i);
|
|
660
|
+
if (at === undefined)
|
|
661
|
+
return undefined;
|
|
662
|
+
if (at === null)
|
|
660
663
|
continue;
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
664
|
+
out.push({ ...at.found, span: [i, at.last + 1] });
|
|
665
|
+
i = at.last;
|
|
666
|
+
}
|
|
667
|
+
return out;
|
|
668
|
+
}
|
|
669
|
+
function bodyExpansionAt(body, i) {
|
|
670
|
+
const ch = body[i];
|
|
671
|
+
if (ch === "`") {
|
|
672
|
+
const tick = backtickBody(body, i);
|
|
673
|
+
return tick === undefined ? undefined : { found: { expansion: { kind: "command", yields: "one", body: tick.body } }, last: tick.close };
|
|
674
|
+
}
|
|
675
|
+
if (ch !== "$")
|
|
676
|
+
return null;
|
|
677
|
+
const open = body[i + 1];
|
|
678
|
+
if (open === "(") {
|
|
679
|
+
const close = substitutionBodyEnd(body, i + 1, true, 0, "document");
|
|
680
|
+
if (typeof close !== "object" || !("end" in close))
|
|
681
|
+
return undefined;
|
|
682
|
+
return { found: { expansion: { kind: close.arithmetic ? "arithmetic" : "command", yields: "one", body: body.slice(i + 2, close.end - 1) } }, last: close.end - 1 };
|
|
683
|
+
}
|
|
684
|
+
if (open === "[") {
|
|
685
|
+
const end = bracketExpansionEnd(body, i + 1);
|
|
686
|
+
return end === undefined ? undefined : { found: { expansion: { kind: "arithmetic", yields: "one", body: body.slice(i + 2, end - 1) } }, last: end - 1 };
|
|
687
|
+
}
|
|
688
|
+
if (open === "{") {
|
|
689
|
+
if (opensCurrentShellSubstitution(body, i + 1)) {
|
|
690
|
+
const run = currentShellSubstitutionEnd(body, i + 1, 1);
|
|
691
|
+
if (typeof run !== "object" || !("end" in run))
|
|
684
692
|
return undefined;
|
|
685
|
-
|
|
686
|
-
const name = EXPANSION_NAME.exec(text)?.[1];
|
|
687
|
-
i = push({ expansion: { kind: "parameter", yields: "one", body: text, ...(name !== undefined ? { name } : {}) }, ...(UNREADABLE_EXPANSION_TEXT.test(text) ? { unresolved: "parameter_text" } : {}) }, i, end - 1);
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
const head = BARE_PARAMETER.exec(body.slice(i + 1, i + 65))?.[0];
|
|
691
|
-
if (head === undefined)
|
|
692
|
-
continue;
|
|
693
|
-
i = push({ expansion: { kind: "parameter", yields: "one", name: head } }, i, i + head.length);
|
|
693
|
+
return { found: { expansion: { kind: "command", yields: "one", body: body.slice(run.from, run.end - 1) }, currentShell: true }, last: run.end - 1 };
|
|
694
694
|
}
|
|
695
|
+
const end = braceExpansionEnd(body, i + 1);
|
|
696
|
+
if (end === undefined)
|
|
697
|
+
return undefined;
|
|
698
|
+
const text = body.slice(i + 2, end - 1);
|
|
699
|
+
const name = EXPANSION_NAME.exec(text)?.[1];
|
|
700
|
+
return { found: { expansion: { kind: "parameter", yields: "one", body: text, ...(name !== undefined ? { name } : {}) }, ...(UNREADABLE_EXPANSION_TEXT.test(text) ? { unresolved: "parameter_text" } : {}) }, last: end - 1 };
|
|
695
701
|
}
|
|
696
|
-
|
|
702
|
+
const head = BARE_PARAMETER.exec(body.slice(i + 1, i + 65))?.[0];
|
|
703
|
+
return head === undefined ? null : { found: { expansion: { kind: "parameter", yields: "one", name: head } }, last: i + head.length };
|
|
697
704
|
}
|
|
698
705
|
export function substitutionsInHeredocBody(body) {
|
|
699
706
|
const all = expansionsInHeredocBody(body);
|
|
@@ -712,10 +719,14 @@ export function heredocBodyHidesRun(body) {
|
|
|
712
719
|
}
|
|
713
720
|
const SUBSTITUTION_OPENER = /\$\(|`|<\(|>\(|\$\[/;
|
|
714
721
|
export function parameterArithmeticTexts(body) {
|
|
722
|
+
const { subscript, offset } = parameterBodyParts(body);
|
|
723
|
+
return { ...(subscript !== undefined ? { subscript } : {}), ...(offset !== undefined ? { offset } : {}) };
|
|
724
|
+
}
|
|
725
|
+
function parameterBodyParts(body) {
|
|
715
726
|
const text = body.replace(/\\\n/g, "");
|
|
716
727
|
const head = PARAMETER_HEAD.exec(text);
|
|
717
728
|
if (head === null)
|
|
718
|
-
return {};
|
|
729
|
+
return { operand: text };
|
|
719
730
|
let rest = text.slice(head[0].length);
|
|
720
731
|
let subscript;
|
|
721
732
|
if (rest.startsWith("[")) {
|
|
@@ -724,7 +735,56 @@ export function parameterArithmeticTexts(body) {
|
|
|
724
735
|
rest = close < 0 ? "" : rest.slice(close + 1);
|
|
725
736
|
}
|
|
726
737
|
const offset = /^:(?![-=+?])(.*)$/s.exec(rest)?.[1];
|
|
727
|
-
return { ...(subscript !== undefined ? { subscript } : {}), ...(offset !== undefined ? { offset } : {}) };
|
|
738
|
+
return { ...(subscript !== undefined ? { subscript } : {}), ...(offset !== undefined ? { offset } : rest !== "" ? { operand: rest } : {}) };
|
|
739
|
+
}
|
|
740
|
+
export function parameterOperandLines(body, quoted) {
|
|
741
|
+
const operand = parameterBodyParts(body).operand;
|
|
742
|
+
return operand === undefined || !/[$`<>]/.test(operand) ? [] : whileReading(operand, () => operandLines(operand, quoted));
|
|
743
|
+
}
|
|
744
|
+
function operandLines(text, quoted) {
|
|
745
|
+
const lines = [];
|
|
746
|
+
let inDouble = false;
|
|
747
|
+
for (let k = 0; k < text.length; k++) {
|
|
748
|
+
const ch = text[k];
|
|
749
|
+
if (ch === "\\") {
|
|
750
|
+
k++;
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
const bare = !quoted && !inDouble;
|
|
754
|
+
if (bare && ch === "'") {
|
|
755
|
+
const close = text.indexOf("'", k + 1);
|
|
756
|
+
if (close < 0)
|
|
757
|
+
break;
|
|
758
|
+
k = close;
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
if (!quoted && ch === '"') {
|
|
762
|
+
inDouble = !inDouble;
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
if (bare && (ch === "<" || ch === ">") && text[k + 1] === "(") {
|
|
766
|
+
const close = substitutionBodyEnd(text, k + 1, false, 0, "process");
|
|
767
|
+
if (typeof close !== "object" || !("end" in close))
|
|
768
|
+
break;
|
|
769
|
+
lines.push(text.slice(k + 2, close.end - 1));
|
|
770
|
+
k = close.end - 1;
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
const at = bodyExpansionAt(text, k);
|
|
774
|
+
if (at === undefined)
|
|
775
|
+
break;
|
|
776
|
+
if (at === null)
|
|
777
|
+
continue;
|
|
778
|
+
const e = at.found.expansion;
|
|
779
|
+
if (e.kind === "command")
|
|
780
|
+
lines.push(e.body ?? "");
|
|
781
|
+
else if (e.kind === "arithmetic")
|
|
782
|
+
lines.push(...operandLines(e.body ?? "", true));
|
|
783
|
+
else if (e.kind === "parameter" && e.body !== undefined)
|
|
784
|
+
lines.push(...operandLines(e.body, quoted || inDouble));
|
|
785
|
+
k = at.last;
|
|
786
|
+
}
|
|
787
|
+
return lines;
|
|
728
788
|
}
|
|
729
789
|
function bodyEvaluatesText(body) {
|
|
730
790
|
const { subscript, offset } = parameterArithmeticTexts(body);
|
|
@@ -746,8 +806,8 @@ function joinRuns(parts) {
|
|
|
746
806
|
return { lines: parts.flatMap((p) => p.lines), hidden: parts.some((p) => p.hidden) };
|
|
747
807
|
}
|
|
748
808
|
const runsAny = (r) => r.hidden || r.lines.length > 0;
|
|
749
|
-
export function expansionRunsOf(e) {
|
|
750
|
-
const inner = joinRuns((e.inner ?? []).map(expansionRunsOf));
|
|
809
|
+
export function expansionRunsOf(e, quoted = true) {
|
|
810
|
+
const inner = joinRuns((e.inner ?? []).map((x) => expansionRunsOf(x, quoted)));
|
|
751
811
|
if (e.kind === "command" || e.kind === "process")
|
|
752
812
|
return joinRuns([e.body === undefined ? HIDDEN_RUNS : { lines: [e.body], hidden: false }, inner]);
|
|
753
813
|
const body = e.body?.replace(/\\\n/g, "");
|
|
@@ -756,7 +816,8 @@ export function expansionRunsOf(e) {
|
|
|
756
816
|
if (e.kind === "arithmetic")
|
|
757
817
|
return joinRuns([arithmeticTextRunsOf(body), inner]);
|
|
758
818
|
const hidden = SUBSTITUTION_OPENER.test(body) || (e.kind === "parameter" && (bodyEvaluatesText(body) || parameterRereadsValue(body))) || nestedBodyEvaluatesText(body);
|
|
759
|
-
|
|
819
|
+
const operand = e.kind === "parameter" && hidden ? parameterOperandLines(body, quoted) : undefined;
|
|
820
|
+
return hidden ? joinRuns([HIDDEN_RUNS, { lines: operand ?? [], hidden: false }, inner]) : inner;
|
|
760
821
|
}
|
|
761
822
|
export function arithmeticTextRunsOf(text) {
|
|
762
823
|
if (arithmeticTextIsPlain(text))
|
|
@@ -804,7 +865,7 @@ export function subscriptHidesRun(w) {
|
|
|
804
865
|
return w.assignment?.subscript !== undefined && !arithmeticTextIsPlain(w.assignment.subscript.raw);
|
|
805
866
|
}
|
|
806
867
|
export function wordRunsOf(w) {
|
|
807
|
-
return joinRuns(assignedWords(w).flatMap((e) => [e.assignment?.form === "compound" || subscriptHidesRun(e) ? HIDDEN_RUNS : NO_RUNS, ...e.expansions.flatMap((p) => (p.expansion !== undefined ? [expansionRunsOf(p.expansion)] : []))]));
|
|
868
|
+
return joinRuns(assignedWords(w).flatMap((e) => [e.assignment?.form === "compound" || subscriptHidesRun(e) ? HIDDEN_RUNS : NO_RUNS, ...e.expansions.flatMap((p) => (p.expansion !== undefined ? [expansionRunsOf(p.expansion, p.quotedBy !== undefined)] : []))]));
|
|
808
869
|
}
|
|
809
870
|
export function wordHidesRun(w) {
|
|
810
871
|
return runsAny(wordRunsOf(w));
|
|
@@ -1411,11 +1472,22 @@ function scanText(source, connectorsAreText, segments, level, list) {
|
|
|
1411
1472
|
if (read === "ambiguous")
|
|
1412
1473
|
return fail("undelimited_substitution_heredoc", from);
|
|
1413
1474
|
if (typeof read !== "object")
|
|
1414
|
-
return
|
|
1475
|
+
return unterminatedHeredocs(from, true);
|
|
1415
1476
|
pendingHeredocs.forEach((h, k) => { h.token.body = read.bodies[k]; });
|
|
1416
1477
|
pendingHeredocs.length = 0;
|
|
1417
1478
|
return read.resume;
|
|
1418
1479
|
};
|
|
1480
|
+
const unterminatedHeredocs = (from, lineBroken) => {
|
|
1481
|
+
const read = list === undefined ? heredocBodies(source, from, pendingHeredocs, undefined, true) : undefined;
|
|
1482
|
+
if (typeof read === "object") {
|
|
1483
|
+
pendingHeredocs.forEach((h, k) => { h.token.body = read.bodies[k]; });
|
|
1484
|
+
if (lineBroken)
|
|
1485
|
+
current().start = source.length;
|
|
1486
|
+
else
|
|
1487
|
+
segments.push({ start: source.length, end: source.length, connector: "\n", tokens: [], substitutions: [] });
|
|
1488
|
+
}
|
|
1489
|
+
return fail("unterminated_heredoc", from);
|
|
1490
|
+
};
|
|
1419
1491
|
for (let i = list?.from ?? 0; i < source.length; i++) {
|
|
1420
1492
|
if (!inSingle) {
|
|
1421
1493
|
const j = past(source, i);
|
|
@@ -1777,7 +1849,7 @@ function scanText(source, connectorsAreText, segments, level, list) {
|
|
|
1777
1849
|
if (tail !== undefined)
|
|
1778
1850
|
return tail;
|
|
1779
1851
|
if (pendingHeredocs.length > 0)
|
|
1780
|
-
return
|
|
1852
|
+
return unterminatedHeredocs(source.length, false);
|
|
1781
1853
|
const out = segments.map((s) => segmentView(source, s));
|
|
1782
1854
|
return { command: { segments: out, substitutions: out.flatMap((s) => s.substitutions) } };
|
|
1783
1855
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { anchorSpelling, isAbsoluteForFamily, isBlockedDevicePath, isShellRootedSpellingUnmapped, nativeUncSpellingOf, normalizeAbsPathLexically, win32NamespaceScreen, pathFamilyOf } from "./safety.js";
|
|
1
|
+
import { anchorSpelling, isAbsoluteForFamily, isBlockedDevicePath, isShellRootedSpellingUnmapped, nativeUncSpellingOf, normalizeAbsPathLexically, shellAnchoredSpellingOf, shellDriveSpellingOf, win32NamespaceScreen, pathFamilyOf } from "./safety.js";
|
|
2
2
|
import { PARSE_FAILURE_SENTENCE, UNRESOLVED_SENTENCE, argvOf, expansionHidesRun, lexShell, literalTildeSpelling, } from "../../shell/lex.js";
|
|
3
3
|
import { shellWordsOf } from "../../shell/shell-words.js";
|
|
4
4
|
import { textBindsHome } from "./shell-read-bindings.js";
|
|
@@ -219,13 +219,17 @@ export function resolveOperandSpellings(base, operand, homeDir) {
|
|
|
219
219
|
const family = base === undefined ? undefined : pathFamilyOf({ root: base });
|
|
220
220
|
if (!win32NamespaceScreen(raw, family).ok)
|
|
221
221
|
return undefined;
|
|
222
|
+
const shellAnchored = (anchored) => spellingsOf(shellAnchoredSpellingOf(family, anchored) ?? anchored);
|
|
222
223
|
if (isAbsoluteForFamily(family ?? "own", raw))
|
|
223
|
-
return spellingsOf(nativeUncSpellingOf(family, raw));
|
|
224
|
+
return raw === operand ? spellingsOf(nativeUncSpellingOf(family, raw)) : shellAnchored(nativeUncSpellingOf(family, raw));
|
|
225
|
+
const drive = shellDriveSpellingOf(family, raw);
|
|
226
|
+
if (drive !== undefined)
|
|
227
|
+
return spellingsOf(drive);
|
|
224
228
|
if (base === undefined || family === undefined || !isAbsoluteForFamily(family, base))
|
|
225
229
|
return undefined;
|
|
226
230
|
if (isShellRootedSpellingUnmapped(family, raw))
|
|
227
231
|
return undefined;
|
|
228
|
-
return
|
|
232
|
+
return shellAnchored(anchorSpelling(family, base, raw));
|
|
229
233
|
}
|
|
230
234
|
function spellingsOf(absolute) {
|
|
231
235
|
const folded = normalizeAbsPathLexically(absolute);
|
package/dist/tools/fs/fs-bash.js
CHANGED
|
@@ -6,7 +6,7 @@ import { RollingTailBuffer } from "../../core/exec-output-tail.js";
|
|
|
6
6
|
import { createBackgroundOutputFile, envDeclaresRetain, hasBackgroundShell, retainsBackgroundProcesses } from "../../core/background-shell.js";
|
|
7
7
|
import { delimitUntrusted } from "../../core/untrusted-text.js";
|
|
8
8
|
import { resolveImageProcessor } from "../../core/image-downsample.js";
|
|
9
|
-
import { withinAnyRoot } from "./safety.js";
|
|
9
|
+
import { shellDriveSpellingOf, withinAnyRoot } from "./safety.js";
|
|
10
10
|
import { admitImageBytes, sniffImageMime } from "../../core/image-admission.js";
|
|
11
11
|
import { isDeadCwd, diagnoseDeadCwd } from "./dead-cwd.js";
|
|
12
12
|
import { boundaryIsTheSandbox, hasDestroy, isIsolated } from "../../core/remote-env.js";
|
|
@@ -432,11 +432,11 @@ async function runShell(env, cwd, toolName, command, timeoutSec, caps, signal, c
|
|
|
432
432
|
if (epilogue.cwd !== undefined) {
|
|
433
433
|
const captured = epilogue.cwd.trim();
|
|
434
434
|
const windowsWorld = /^[A-Za-z]:[\\/]/.test(cwdRef.current);
|
|
435
|
-
const
|
|
435
|
+
const drive = windowsWorld ? shellDriveSpellingOf("win", captured) : undefined;
|
|
436
436
|
if (/^[A-Za-z]:[\\/]/.test(captured))
|
|
437
437
|
cwdRef.current = captured;
|
|
438
|
-
else if (
|
|
439
|
-
cwdRef.current =
|
|
438
|
+
else if (drive !== undefined)
|
|
439
|
+
cwdRef.current = drive;
|
|
440
440
|
else if (captured.startsWith("/") && !windowsWorld)
|
|
441
441
|
cwdRef.current = captured;
|
|
442
442
|
}
|
|
@@ -48,7 +48,7 @@ export declare function dangerousRemovalOf(path: string, seat: RemovalSeat, rm?:
|
|
|
48
48
|
* (`rewritten`), the operands of a removal its argv stream fills in (`stream`), or an operand relative to the directory a
|
|
49
49
|
* launcher option moved the removal into (`relocated`); or a shell handed text the engine cannot read
|
|
50
50
|
* (`unverifiable_shell_text`) — a text a program produces (`produced`: what a pipe or a `<(…)` carries, an argv a stream
|
|
51
|
-
* fills in, a substitution), a text nobody read (`unread`: one the lexer could not read
|
|
51
|
+
* fills in, a substitution), a text nobody read (`unread`: one the lexer could not read, all of it or the rest from where it stopped, {@link unreadPlan}), or a
|
|
52
52
|
* segment whose program the walk could not name (`position`, {@link programUnread}: the program-position reader's own refusal
|
|
53
53
|
* of the segment's argv, the reading the planner declined it by). */
|
|
54
54
|
export type RemovalFinding = (DangerousRemoval & {
|
|
@@ -98,7 +98,8 @@ export declare const KNOWN_SAFE_ROOTS: readonly string[];
|
|
|
98
98
|
* name the table settles is its value, so `D=./build; rm -rf "$D/../build"` is judged
|
|
99
99
|
* where it lands, as `rm -rf ./build` is. A shell handed a text the engine cannot read — one a program produces
|
|
100
100
|
* ({@link runtimeScriptOf}), or one nobody read ({@link unreadPlan}, {@link programUnread}) — is an unreadable text of its
|
|
101
|
-
* own.
|
|
101
|
+
* own. Text nobody read never stands in for the text that was read: what the lexer read in full before it stopped is judged
|
|
102
|
+
* as any text's (bash runs those lines), beside the finding of the rest. The read-face copy of an operand is not judged: it follows a link the removal does not follow.
|
|
102
103
|
*/
|
|
103
104
|
export declare function removalFindingsOf(established: EstablishedPlan, seat: RemovalSeat, safeRoots?: readonly string[], enclosingRelocated?: boolean, apart?: boolean): RemovalFinding[];
|
|
104
105
|
/** Does the removal program refuse this operand by its own first step — its last path component is `.` or `..`, trailing
|
|
@@ -130,8 +131,8 @@ export interface RemovalGuardSeat {
|
|
|
130
131
|
/**
|
|
131
132
|
* The removal guard's READING of one command — undefined when no segment of it (nested shell text included) runs a
|
|
132
133
|
* removal program or hands a shell a script built when it runs, and every text in it was read, so a command that removes
|
|
133
|
-
* nothing costs the gate no suspension (a text the lexer could not read is not one:
|
|
134
|
-
* syntax error,
|
|
134
|
+
* nothing costs the gate no suspension (a text the lexer could not read to its end is not one: the rest is a finding of its
|
|
135
|
+
* own, and the lines before its syntax error, which bash runs, are judged as any). Otherwise `judge` establishes the plan the read
|
|
135
136
|
* station plans (the same planner, the same value table, the same write-target reading) lexically against the request's
|
|
136
137
|
* `cwd` and the seat's home, and — where an environment is seated — through its resolver too, and returns what either
|
|
137
138
|
* establishment finds ({@link removalFindingsOf}: the protected-location word first, then the unverifiable target, then the
|
|
@@ -114,8 +114,10 @@ function selectsOptions(row, args, shellChooses, ...wanted) {
|
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOTS, enclosingRelocated = false, apart = false) {
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
const unread = unreadPlan(established.plan) ? [{ guard: "unverifiable_shell_text", program: "bash", text: established.plan.unreadable, source: "unread" }] : [];
|
|
118
|
+
return [...unread, ...segmentFindingsOf(established, seat, safeRoots, enclosingRelocated, apart)];
|
|
119
|
+
}
|
|
120
|
+
function segmentFindingsOf(established, seat, safeRoots, enclosingRelocated, apart) {
|
|
119
121
|
const out = [];
|
|
120
122
|
const safe = new Set(safeRoots);
|
|
121
123
|
for (const segment of established.plan.segments) {
|
|
@@ -163,13 +165,11 @@ export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOT
|
|
|
163
165
|
}
|
|
164
166
|
const handedRelocated = enclosingRelocated || position.baseMovedAt.length > 0;
|
|
165
167
|
for (const nested of segment.nested) {
|
|
166
|
-
if (unreadPlan(nested))
|
|
168
|
+
if (unreadPlan(nested))
|
|
167
169
|
out.push({ guard: "unverifiable_shell_text", program: program ?? segment.text.trim(), text: segment.text.trim(), source: "unread" });
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
170
|
const sub = established.nested.get(nested);
|
|
171
171
|
if (sub !== undefined)
|
|
172
|
-
out.push(...
|
|
172
|
+
out.push(...segmentFindingsOf(sub, seat, safeRoots, handedRelocated, true));
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
return out;
|
|
@@ -203,7 +203,7 @@ function runtimeScriptOf(segment) {
|
|
|
203
203
|
const text = texts.find((t) => t?.includes(MARK) === true);
|
|
204
204
|
return text === undefined ? undefined : text.split(MARK).join("");
|
|
205
205
|
}
|
|
206
|
-
const unreadPlan = (plan) => plan.unreadable !== undefined && plan.segments.length === 0;
|
|
206
|
+
const unreadPlan = (plan) => plan.unreadable !== undefined && (plan.unreadTail !== undefined || plan.segments.length === 0);
|
|
207
207
|
const programUnread = (s) => s.declines.includes("unreadable_program_position");
|
|
208
208
|
const programNameUnsettled = (s) => s.verb !== undefined && s.reads.some((c) => c.provenance === "program_path" && c.expands === "unresolvable");
|
|
209
209
|
const RM_REMOVAL_ROW = programRow("rm");
|
|
@@ -234,18 +234,18 @@ const REMOVAL_GUARD_SENTENCE = {
|
|
|
234
234
|
},
|
|
235
235
|
},
|
|
236
236
|
unverifiable_delete: {
|
|
237
|
-
card: (row) => `
|
|
237
|
+
card: (row) => `This delete could not be checked first: ${row}. Writing the exact path into the command (or setting the variable to a literal path in the same command, e.g. \`DIR=/exact/path; rm -rf "$DIR"\`) lets the engine check it.`,
|
|
238
238
|
rows: {
|
|
239
|
-
rewritten: (f) => `\`${f.program}\`
|
|
240
|
-
stream: (f) => `\`${f.program}\`
|
|
241
|
-
relocated: (f) => `\`${f.program}\`
|
|
239
|
+
rewritten: (f) => `\`${f.program}\` deletes ${inlineUntrusted(f.operand, 200)} recursively and by force, and the shell fills that path in from a value this command does not set (a name with no value here or one set in a form the engine cannot read, a substitution, a parameter operator)`,
|
|
240
|
+
stream: (f) => `\`${f.program}\` deletes recursively and by force the paths named by the input it is fed (${inlineUntrusted(f.operand, 200)})`,
|
|
241
|
+
relocated: (f) => `\`${f.program}\` deletes ${inlineUntrusted(f.operand, 200)} recursively and by force, relative to a directory a launcher option moved it into, which this command does not say`,
|
|
242
242
|
},
|
|
243
243
|
},
|
|
244
244
|
unverifiable_shell_text: {
|
|
245
|
-
card: (row) => `
|
|
245
|
+
card: (row) => `This command could not be checked first: ${row}.`,
|
|
246
246
|
rows: {
|
|
247
|
-
produced: (f) => `\`${f.program}\` runs shell text that is
|
|
248
|
-
unread: (f) => `\`${f.program}\` runs shell text
|
|
247
|
+
produced: (f) => `\`${f.program}\` runs shell text that is only put together when the command runs (${inlineUntrusted(f.text, 200)}), so the engine cannot read it beforehand — writing that text into the command itself (a \`-c\` string, a here-document or a here-string) lets the engine read it`,
|
|
248
|
+
unread: (f) => `\`${f.program}\` runs shell text the engine cannot read (${inlineUntrusted(f.text, 200)})`,
|
|
249
249
|
position: (f) => inlineUntrusted(programPositionRefusalSentence(f.refusal), 400),
|
|
250
250
|
},
|
|
251
251
|
},
|
|
@@ -377,10 +377,29 @@ export declare function spellingOfIdentity(identity: PathIdentity, family: PathF
|
|
|
377
377
|
export declare function carriesDotSegment(spelled: string, family: PathFamily | undefined): boolean;
|
|
378
378
|
/** A model-spelled path bounded for error text (the spelling is unbounded input). */
|
|
379
379
|
export declare function clipSpelling(spelled: string): string;
|
|
380
|
-
/**
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
380
|
+
/**
|
|
381
|
+
* The SHELL's spelling of a drive on a win tree. The win32 adapter runs Git for Windows bash (the MSYS line — the only
|
|
382
|
+
* shells its discovery answers there), which names drive X's root `/x`, either case. A `/`-rooted spelling is read the way
|
|
383
|
+
* that shell reads it: a leading run of three or more `/` is one `/` (exactly two name a UNC or a server there); a backslash
|
|
384
|
+
* separates too; the first segment, ONE ASCII letter, is that drive: `/c/rest` and `/C/rest` ⇒ `C:\rest`, `/c` ⇒ `C:\`. A `..`
|
|
385
|
+
* inside the drive is kept (the walk resolves a link before it steps up, as for every spelling); a `..` that climbs above the
|
|
386
|
+
* drive's root reaches the emulation's own root `/`, so such a spelling is folded first, as a POSIX path (`/c/../d/f` is `/d/f`).
|
|
387
|
+
* `undefined` for every other spelling — the emulation's own tree (`/etc`, `/tmp`, `/cygdrive/…`), a UNC, a backslash-rooted
|
|
388
|
+
* one (Win32's current-drive form) — and on any tree that is not win, where `/c/x` is an ordinary path. The family is the
|
|
389
|
+
* tree's, never the spelling's. The ONE reading of that shell's drive spelling: the shell operand resolver (with
|
|
390
|
+
* {@link shellAnchoredSpellingOf}), the tracked working directory the shell reports, and {@link isShellRootedSpellingUnmapped}.
|
|
391
|
+
*/
|
|
392
|
+
export declare function shellDriveSpellingOf(family: PathFamily | undefined, spelled: string): string | undefined;
|
|
393
|
+
/** A drive path the SHELL anchored itself — a relative operand joined to its working directory, a `~` word to its home — is
|
|
394
|
+
* walked in that shell's namespace: where a `..` climbs above the drive's root it reaches the emulation's root, so the path is
|
|
395
|
+
* read as {@link shellDriveSpellingOf} reads `/x/…` (`C:\proj\..\..\d\f` ⇒ `D:\f`, not the Win32 clamp's `C:\d\f`). `undefined`
|
|
396
|
+
* where no `..` climbs above the drive's root, where the climb lands in the emulation's own tree (`C:\proj\..\..\etc` is `/etc`
|
|
397
|
+
* there, a place only that shell knows — the anchored, clamped reading stands, as before), and for any other spelling or family. */
|
|
398
|
+
export declare function shellAnchoredSpellingOf(family: PathFamily | undefined, anchored: string): string | undefined;
|
|
399
|
+
/** A ROOTED (not qualified) spelling handed to the SHELL on a win tree (`/etc`, `/cygdrive/d/x`, `\\x`) that is not the
|
|
400
|
+
* shell's drive spelling ({@link shellDriveSpellingOf}) is the shell's to map — the win32 adapter runs Git Bash, where
|
|
401
|
+
* `/etc` is the MSYS root, not the cwd's drive root — so no lexical reader may resolve it (fail-closed: the operand is
|
|
402
|
+
* unresolvable). The ONE statement of that rule, for every shell-facing resolver. */
|
|
384
403
|
export declare function isShellRootedSpellingUnmapped(family: PathFamily | undefined, spelled: string): boolean;
|
|
385
404
|
/** The win family's native spelling of a UNC written with any leading-separator mix (`//host/share/x`, `\\/host/…`
|
|
386
405
|
* ⇒ `\\\\host\\share\\x`), for a lexical normalizer that recognises the backslash form only; every other spelling is
|
package/dist/tools/fs/safety.js
CHANGED
|
@@ -402,8 +402,45 @@ export function carriesDotSegment(spelled, family) {
|
|
|
402
402
|
export function clipSpelling(spelled) {
|
|
403
403
|
return spelled.length > 512 ? `${spelled.slice(0, 512)}…` : spelled;
|
|
404
404
|
}
|
|
405
|
+
export function shellDriveSpellingOf(family, spelled) {
|
|
406
|
+
const lead = /^\/*/.exec(spelled)[0].length;
|
|
407
|
+
if (family !== "win" || lead === 0 || lead === 2 || spelled[lead] === "\\")
|
|
408
|
+
return undefined;
|
|
409
|
+
const folded = [];
|
|
410
|
+
const kept = [];
|
|
411
|
+
let leftTheDrive = false;
|
|
412
|
+
for (const seg of spelled.slice(lead).split(/[\\/]+/)) {
|
|
413
|
+
if (seg === "" || seg === ".")
|
|
414
|
+
continue;
|
|
415
|
+
kept.push(seg);
|
|
416
|
+
if (seg !== "..")
|
|
417
|
+
folded.push(seg);
|
|
418
|
+
else if (folded.length <= 1)
|
|
419
|
+
(leftTheDrive = true), folded.pop();
|
|
420
|
+
else
|
|
421
|
+
folded.pop();
|
|
422
|
+
}
|
|
423
|
+
const read = leftTheDrive ? folded : kept;
|
|
424
|
+
const drive = read[0];
|
|
425
|
+
return drive !== undefined && /^[A-Za-z]$/.test(drive) ? `${drive.toUpperCase()}:\\${read.slice(1).join("\\")}` : undefined;
|
|
426
|
+
}
|
|
427
|
+
export function shellAnchoredSpellingOf(family, anchored) {
|
|
428
|
+
const m = family === "win" ? /^([A-Za-z]):[\\/]([\s\S]*)$/.exec(anchored) : null;
|
|
429
|
+
if (m === null)
|
|
430
|
+
return undefined;
|
|
431
|
+
let depth = 0;
|
|
432
|
+
for (const seg of m[2].split(/[\\/]+/)) {
|
|
433
|
+
if (seg === "" || seg === ".")
|
|
434
|
+
continue;
|
|
435
|
+
if (seg !== "..")
|
|
436
|
+
depth++;
|
|
437
|
+
else if (--depth < 0)
|
|
438
|
+
return shellDriveSpellingOf(family, `/${m[1]}/${m[2]}`);
|
|
439
|
+
}
|
|
440
|
+
return undefined;
|
|
441
|
+
}
|
|
405
442
|
export function isShellRootedSpellingUnmapped(family, spelled) {
|
|
406
|
-
return family === "win" && (spelled.startsWith("/") || spelled.startsWith("\\"));
|
|
443
|
+
return family === "win" && (spelled.startsWith("/") || spelled.startsWith("\\")) && shellDriveSpellingOf(family, spelled) === undefined;
|
|
407
444
|
}
|
|
408
445
|
export function nativeUncSpellingOf(family, spelled) {
|
|
409
446
|
return family === "win" && isUncSpelling(spelled) ? `\\\\${spelled.slice(2).replace(/\//g, "\\")}` : spelled;
|
|
@@ -170,9 +170,15 @@ export interface ShellReadSegment {
|
|
|
170
170
|
}
|
|
171
171
|
export interface ShellReadPlan {
|
|
172
172
|
readonly segments: readonly ShellReadSegment[];
|
|
173
|
-
/**
|
|
174
|
-
*
|
|
173
|
+
/** Some of the text could not be read, in words: the lexer stopped before its end (an unterminated construct, see
|
|
174
|
+
* {@link unreadTail}), the text is nested past the bound, or a word's value is one the text does not hold. UNCONDITIONAL
|
|
175
|
+
* fail-closed for the consumer: a quote-blind re-read yields more words, never zero, so this is not "no candidates" —
|
|
176
|
+
* and never a reason to skip the segments the plan does hold: each of them is judged as any text's. */
|
|
175
177
|
readonly unreadable?: string;
|
|
178
|
+
/** The lexer stopped before the text's end: this is the text from the segment it stopped in to the end, which nobody read
|
|
179
|
+
* (empty where an unterminated here-document took the text to its end). The segments before it are the ones it read in
|
|
180
|
+
* full ({@link LexParseFailure.readBefore}) — runs, since bash runs every complete line before the one it cannot parse. */
|
|
181
|
+
readonly unreadTail?: string;
|
|
176
182
|
/** Shape facts the same lex produced, for the shape consumers; the read judgment does not read them. */
|
|
177
183
|
readonly shape: {
|
|
178
184
|
readonly grouped: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assignedWords, expansionsInHeredocBody, descriptorNameWords, lexShell, PARSE_FAILURE_SENTENCE, substitutionsInHeredocBody, literalTextOf, literalTildeSpelling, parameterRereadsValue, UNRESOLVED_SENTENCE, } from "../../shell/lex.js";
|
|
1
|
+
import { assignedWords, expansionsInHeredocBody, descriptorNameWords, lexShell, PARSE_FAILURE_SENTENCE, substitutionsInHeredocBody, literalTextOf, literalTildeSpelling, parameterOperandLines, parameterRereadsValue, UNRESOLVED_SENTENCE, } from "../../shell/lex.js";
|
|
2
2
|
import { programTextOf, readOfText, readsOf, rewritten, segmentReadingsOf, settledFieldsOf, spelledWithHome, unreadableSentenceOf } from "./shell-read-word.js";
|
|
3
3
|
import { braceWordListsOf } from "./shell-read-brace.js";
|
|
4
4
|
import { assignmentArithmetic, bare, listedVerbCandidates, pathSubcommandOf, programTextSentence, pushAssignment, roleReads, subscriptOnly, unlistedWords } from "./shell-read-argv.js";
|
|
@@ -40,10 +40,11 @@ function planText(command, decl, depth, start, from) {
|
|
|
40
40
|
if (depth > NESTING_MAX)
|
|
41
41
|
return { plan: { segments: [], unreadable: `command text nested more than ${NESTING_MAX} levels deep`, shape }, end: "unmodelled", physical: false, reached: none };
|
|
42
42
|
const lexedAsWritten = lexShell(command);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const lexed = inlineSourcedLiterals(lexedAsWritten);
|
|
46
|
-
const
|
|
43
|
+
const failed = "parseFailure" in lexedAsWritten ? lexedAsWritten : undefined;
|
|
44
|
+
const readBefore = failed?.readBefore.slice(0, -1) ?? [];
|
|
45
|
+
const lexed = inlineSourcedLiterals("parseFailure" in lexedAsWritten ? { segments: readBefore, substitutions: readBefore.flatMap((s) => s.substitutions) } : lexedAsWritten);
|
|
46
|
+
const unreadTail = failed?.readBefore.at(-1)?.text;
|
|
47
|
+
const unreadable = failed !== undefined ? PARSE_FAILURE_SENTENCE[failed.parseFailure.reason] : unreadableSentenceOf(lexed, command);
|
|
47
48
|
const projected = projectSegments(lexed.segments);
|
|
48
49
|
const exportedFunctions = inheritedFunctionsOf(projected, start?.exportedFunctions), exportedNames = new Set(exportedFunctions.keys());
|
|
49
50
|
const loopShapes = projected.map((p) => loopShapeOf(p));
|
|
@@ -400,7 +401,7 @@ function planText(command, decl, depth, start, from) {
|
|
|
400
401
|
}
|
|
401
402
|
}
|
|
402
403
|
const reached = workdir.lost ? new Set([...workdir.reached, ...(workdir.floorBases ?? [])]) : workdir.reached;
|
|
403
|
-
return { plan: { segments, shape, ...(unreadable !== undefined ? { unreadable } : {}) }, end: workdir.end(), physical: workdir.mayBePhysical, reached, ...(workdir.unsettled ? { unsettled: true } : {}), callers: callersOut };
|
|
404
|
+
return { plan: { segments, shape, ...(unreadable !== undefined ? { unreadable } : {}), ...(unreadTail !== undefined ? { unreadTail } : {}) }, end: unreadTail !== undefined ? "unmodelled" : workdir.end(), physical: workdir.mayBePhysical, reached, ...(workdir.unsettled ? { unsettled: true } : {}), callers: callersOut };
|
|
404
405
|
}
|
|
405
406
|
function loopShapeOf(p) {
|
|
406
407
|
if (p.argv[0] === undefined)
|
|
@@ -514,6 +515,15 @@ function segmentFactsRead(segment, p, decl, table, nestedPlan, fed, toks, inheri
|
|
|
514
515
|
expandedText(expansionsInHeredocBody(t.body), "a here-document body carries a substitution this lexer cannot delimit");
|
|
515
516
|
for (const e of expansionsOf(segment))
|
|
516
517
|
parameter(e);
|
|
518
|
+
for (const t of segment.tokens) {
|
|
519
|
+
const words = t.kind === "word" ? assignedWords(t) : t.kind === "redirect" && t.target !== undefined ? [t.target] : [];
|
|
520
|
+
for (const q of words.flatMap((w) => w.pieces)) {
|
|
521
|
+
for (const e of q.expansion !== undefined ? enclosedToo(q.expansion) : [])
|
|
522
|
+
if (e.kind === "parameter" && e.body !== undefined)
|
|
523
|
+
for (const line of parameterOperandLines(e.body, q.quotedBy !== undefined))
|
|
524
|
+
substitute(line, false);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
517
527
|
const shellSide = new Set(nested);
|
|
518
528
|
if (isArithmeticCommand(segment))
|
|
519
529
|
ctx.reentered.push(...arithmeticSubstitutions(p.argv.map((w) => w.folded).join(" "), table));
|
|
@@ -120,11 +120,12 @@ export function inlineSourcedLiterals(lexed) {
|
|
|
120
120
|
continue;
|
|
121
121
|
}
|
|
122
122
|
const inner = lexShell(text);
|
|
123
|
-
|
|
123
|
+
const read = "parseFailure" in inner ? inner.readBefore.slice(0, -1) : inner.segments;
|
|
124
|
+
if (read.length === 0) {
|
|
124
125
|
out.push(segment);
|
|
125
126
|
continue;
|
|
126
127
|
}
|
|
127
|
-
|
|
128
|
+
read.forEach((s, k) => out.push(k === 0 ? { ...s, connector: segment.connector, spliced: true } : { ...s, spliced: true }));
|
|
128
129
|
out.push({ ...segment, connector: ";", spliced: true, sourced: true });
|
|
129
130
|
spliced = true;
|
|
130
131
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sema-agent/core",
|
|
3
|
-
"version": "7.68.
|
|
3
|
+
"version": "7.68.7",
|
|
4
4
|
"description": "Stateless, task-oriented AI agent core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "BUSL-1.1",
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
"dependencies": {
|
|
134
134
|
"@modelcontextprotocol/client": "2.4.0",
|
|
135
135
|
"@modelcontextprotocol/core": "2.4.0",
|
|
136
|
-
"@sema-agent/primitives": "7.68.
|
|
136
|
+
"@sema-agent/primitives": "7.68.7",
|
|
137
137
|
"typebox": "1.1.39",
|
|
138
138
|
"undici": "7.30.2"
|
|
139
139
|
},
|