@sema-agent/core 7.68.6 → 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 CHANGED
@@ -1,3 +1,29 @@
1
+ ## 7.68.7 — 2026-11-18
2
+
3
+ ### On a Windows tree the shell read station reads Git Bash's drive spelling (`/c/…`) as the drive path it names — reads, writes, `cd` targets and the removal guard (#4854; a narrowing on Windows hosts; widening: one, below — reads the engine places inside the root, open to veto; no API change)
4
+
5
+ - **Who.** Hosts whose execution environment is a Windows tree (a drive or UNC root) running the win32 adapter's shell, Git for Windows / MSYS2 bash, which names drive X's root `/x`. A POSIX tree is unchanged: `/c/x` there is an ordinary path.
6
+ - **Before (measured on a win-family environment double over a real Runner; the evaluation repo reported measuring the read row on a Windows host, engine 7.68.5; no real-host record here).** The station read the listed drive-spelled operands on a Windows tree as "cannot be placed", so `/c/Users/<u>/…` met no home-anchored or rooted deny row: `cat /c/Users/<u>/<deny-listed file>` — also `/C/…`, a pattern, `/c/../c/…`, double- or single-quoted — ran unasked under `bypassPermissions` and elsewhere were asked or refused as "where this command reads could not be established". `rm -rf /c/proj` (the task root), `rm -rf /c` (the drive root) and `rm -rf /c/Users/<u>` (the home) ran under `bypassPermissions` with no removal question (the target was not placed, so the removal guard had nothing to judge); a redirection or copy onto a protected or deny-listed file, and `cd /c/… && <relative read>`, likewise. A person's rule `Read(//c/…)` and the built-in rows matched anywhere (`.ssh`, …) already refused.
7
+ - **Now.** On a Windows tree a `/`-rooted operand is folded as that shell folds it (`..` at `/x` climbs to the emulation's own root) and a single-letter first segment is that drive: `/c/rest` and `/C/rest` ⇒ `C:\rest`, `/c` ⇒ `C:\`; three or more leading slashes read as one (`///c/rest` ⇒ `C:\rest`, refused as its twin where it was unplaced before), two are a UNC as before. Read at the one operand resolver, so every shell station — reads, writes, redirections, `cd` targets, the removal guard — judges it as its `C:/…` twin, on every mode and every deny-row source (built-in, the deployment's home-anchored and rooted rows, a person's rule). The tracked working directory reads the shell's `/c/…` pwd through the same reading (its spelling is now `C:\…`, measured; it was `c:/…`, by reading the code).
8
+ - **The widening — open to veto.** A read the engine places inside the root, written in the drive spelling, is now that in-root read, as its `C:/…` twin already was. Measured against 7.68.6 on the win-family double, default read face, root `C:\work\repo`, with four such reads (`cat /c/work/repo/src/a.txt`, the same upper-cased, `cat /c/work/repo/../repo/sub/b.txt`, `ls /c/work/repo`): under `default`, `acceptEdits` and `plan` with a person they were asked and now run unasked; under `default` with nobody to ask, `auto` and `dontAsk` they were refused (`read_unestablished`; `dontAsk` by its mode) and now run; under `bypassPermissions` they ran and still run. Two consequences of that one reading are not right, each its own known limit: a host whose shell is not of the MSYS line interprets the same text outside the root by those tools' documented conventions (Cygwin: `c` under its installation root; cmd / PowerShell / busybox-w32: `\c\…` on the current drive; not measured here) — KL-4854-b; and a read that passes a link inside the root and then climbs with `..` past the drive's root back into the root is judged as the in-root file while the review double models Git Bash resolving the link first and opening a path under the drive's root, outside the root (the real-shell destination was not measured here) — it was asked or refused as above and now runs unasked on every seat — KL-4854-d. Nothing else got looser: over 102 drive-spelled reads, writes, redirections, removals and link forms × 8 seats (the review measurement against 7.68.6), no write, no removal and no read the engine places outside the root lost a question or a refusal on any seat; the open read face was not measured.
9
+ - **Unchanged.** A `cd` to the drive spelling mints no directory rule and no stored directory rule covers it (refusal-only; the same on 7.68.6, measured). The following `/`-rooted spellings stay unplaced as before — the emulation's own tree (`/etc`, `/usr`, `/bin`, `/opt`, `/home`, `/tmp`, `/proc`, `/dev`), another layer's drive form (`/cygdrive/x/…`, `/mnt/x/…`), a fold out of the drive (`/c/../etc/…`), a multi-letter head (`/cc/…`), the rule grammar's `/C:/…`, Win32's backslash root (`\c\…`), a bare `//c`; a full UNC spelling (`//c/Users/x/f`) keeps its UNC anchor as before, placed as a UNC path, not as drive `c` — KL-4854-a. A directory link inside the root that names the drive's root is modeled in the review double as letting Git Bash climb past that root with `..`, which the station folds as text (the real-shell destination was not measured here): such a read or removal runs under `bypassPermissions` on 7.68.6 and on this release alike, and is asked or refused elsewhere on both — not fixed here, KL-4854-d. Not measured on this release, and untouched by its diff: the structured file tools (by Node on Windows' documented convention, `/c/x` is the current drive's `\c\x` (not measured here), and they read it so).
10
+ - **Not in range.** A path built inside another interpreter's text (`powershell -Command "…"`, `python -c "…"`) — KL-4854-c.
11
+ - **Pins.** `test/backlog4854-win-drive-prefix.test.ts` — the one resolver's readings on a win tree and on a POSIX tree; reads (the reported spellings × six modes × four deny-row sources, through a link inside the root, after a `cd`), the in-root read, the removal guard (the drive root, the task root and the home in every mode; five more spellings of the task root), writes (a redirection, a copy target, the write-protection table), the tracked working directory, the `cd` member, what stays unplaced, the in-root read judged by the shell double for a shell outside the MSYS line (its actual path follows documented convention, not measured here; KL-4854-b), and a POSIX tree (`/c/…` an ordinary path, its `cd` member as before). One earlier cell re-pinned: `test/path-identity-family-matrix.test.ts` (`/d/private.txt` under a win root resolves to `D:\private.txt` now; it was unresolved).
12
+ - **Consumers.** A probe that pinned the "could not be established" card for a drive-spelled operand on a Windows host now meets the `C:/…` spelling's verdict (`read_path_denied`, the removal question, the write-protection question): re-pin to it. A probe that pinned an in-root drive-spelled read as asked or refused now sees it run.
13
+
14
+ ### What the engine can read of a command is judged as itself; what it cannot read is the ordinary question beside it, never instead of it — a removal or deny-listed read written plainly before text the engine cannot parse is stopped again, and a command written in a parameter expansion's operand is read (#4862; a narrowing of 7.68.6, and of a gap older than it; hard-breaking: none; open to veto @server @cli @test for the one stricter-than-the-shell cell below)
15
+
16
+ - **What 7.68.6 let through.** 7.68.6 made a shell text the engine cannot read an ordinary question (`bypassPermissions` releases it; auto's classifier, a stored rule, a pre-approval, a class table and a host's blanket `onAsk: "allow"` can answer it, subject to the read-face distinctions below). Where a command's text could not be parsed to its end, the engine read none of it, so a removal or read written plainly BEFORE the unparseable part became that question too: `rm -rf ~; cat <<EOF⏎x` (a here-document never closed), `rm -rf /usr⏎echo 'x` (the next line never closes its quote), `rm -rf ~; echo $(case x in x) y;; esac)`, `rm -rf /; cat <<EOF⏎x`, a workspace removal before `⏎echo "x`, and `cat .env` / `cat ~/.npmrc` before such a tail ran under `bypassPermissions` and the blanket answer on both read faces; on the open face they also ran under auto's classifier, a stored rule / pre-approval / class table in `default`, `acceptEdits` or `plan`, and a stored rule / pre-approval in `dontAsk` (25/50 arms per text in the review leg's raw cells; its “hole arms 44/50” also counts ordinary questions). On the narrowed face, `default`, `acceptEdits`, `plan` and `auto` still asked with `probe`, even with a stored rule, pre-approval or class table; `dontAsk` refused (7.68.5: a person, with the real-approval bit, or refused). Bash 3.2 / 5.2 runs the measured complete line before the one it cannot parse, and bash 3.2 / 5.2, dash, zsh and ksh run the measured unterminated here-documents with their bodies taken to the end of the text (`DESIGN-4862.md` §2 S02, S01/S05/S06/S34; `local-shells.out`, same rows). The 7.68.6 notes' sentence "the same removal or read written plainly (`rm -rf /usr`, `rm -rf ~`, `cat .env`) is still stopped in every mode" did not hold for these texts. From this release it holds for a removal or read written before the point where the lexer stops; it still does not hold for one written after a construct the lexer itself cannot read past although bash 5.2 can in the review leg's measured forms (KL-4862-e).
17
+ - **And a gap older than 7.68.6.** A command written in a parameter expansion's operand — `echo "${X:-$(cat .env)}"`, `${X-…}`, `${X:=…}`, `${X:+…}`, `${X:?…}`, `${X#…}`, `${X%…}`, `${X/…/…}`, a backquote or (outside double quotes) a `<(…)` there — was never read: the engine saw one word it could not read, an ordinary question, so the read or the removal inside ran wherever that question was answered (the review leg measured the `${X:-$(cat .env)}`, `${X:-$(rm -rf ~)}` and `${X#$(rm -rf /usr)}` operand forms running under `bypassPermissions` on both read faces on 7.68.5 and 7.68.6: `table-a.txt`).
18
+ - **Now.** The segments the lexer read in full before it stopped go through every judge — a protected-location removal is a person's (`dangerous_delete`, the bit) in every mode, or refused without a question (`dontAsk` and the blanket-answer arm), a deny-listed read is refused, a write-protected target and the read roots are judged — and the text from where it stopped stays the one ordinary question beside them. An unterminated here-document is read as the measured shells read it (`DESIGN-4862.md` §2 S01/S05/S06/S34; `local-shells.out`), so a shell or `xargs` fed one (`bash <<EOF⏎rm -rf ~`) is judged on that body. The substitutions written in an operand are planned as any substitution is; the operand is read as the shell quotes it — outside double quotes a single-quoted part (`${X:-'$(cmd)'}`) runs nothing and is not read as running, inside them (`"${X:-'$(cmd)'}"`) it runs and is read (`DESIGN-4862.md` §2 S23/S24; `local-shells.out`); the inner-double-quote variant (`${X:-"'$(cmd)'"}`) is also read (pinned; shell execution not measured here); a substitution that cannot be delimited there keeps the ones read before it, and the expansion itself stays the ordinary question. A literal written to a file and then sourced splices what the lexer read of it. Each of the nine forms first measured reads, in every mode × answerer × read face, as the same sentence without its tail (pinned); kin whose statement alone is an ordinary question are pinned only as “not looser”, and the wider gate matrix excepts the rule lane's length bound (KL-4862-c: a person's deny rule becomes a question with the real-approval bit, refused where nobody may be asked).
19
+ - **Net, for a reader coming from 7.68.5.** 7.68.6's widening stays: a text the engine cannot read, and a delete whose target is hidden from it — a stream (`echo /usr | xargs rm -rf`), a substitution's output (`rm -rf "$(printf /usr)"`), a script put together when the command runs (`printf 'rm -rf /usr\n' | bash`, `bash -c "$(echo rm -rf ~)"`, `printf 'cat .env\n' | bash`) — is an ordinary question (cell for cell as 7.68.6, pinned). What is written plainly before the point where the lexer stops, and what is written in an operand, is judged at least as strictly as the same statement written alone (pinned, except KL-4862-c: past the rule lane's length bound, a person's deny rule becomes a question with the real-approval bit instead of the refusal; kin whose statement alone is an ordinary question require only “not looser”); the text from that point on is the unread part, the ordinary question as on 7.68.6, and a statement written there runs wherever that question is answered (KL-4862-d, KL-4862-e).
20
+ - **Stricter than the shell — open to veto.** Every statement read in full before the stop is judged as one that MAY run. A quote left open on the SAME line stops bash before any of that line runs, so `cat .env; echo "x` is now refused although bash would have refused the whole line (7.68.6: released; nothing was read). The same holds for the measured `&&`-and-newline and unclosed `for` body in bash 3.2 / 5.2 and dash (`DESIGN-4862.md` §2 S07/S08; `local-shells.out`; KL-4862-a). A person's deny / ask rule now also reaches the command of a segment that owns an unterminated here-document and a command written in an operand (it answered "the call could not be read" there before: a question with the bit, not the rule's own answer).
21
+ - **Not changed.** Class words, class order, which classes carry `requiresRealApproval`, the ordinary question's row; the exports and the closed sets (one optional member is added to the exported type `ShellReadPlan`: `unreadTail`). A text with no readable part (`echo 'x`, `cat <<EOF⏎x`), a removal whose own segment never closes its quote (`rm -rf ~ 'x`: bash runs none of it), and the hidden forms above read cell for cell as on 7.68.6.
22
+ - **Who needs it / who it harms / the compensation.** Needed by runs under `bypassPermissions` or the blanket answer on either face, and on the open face under auto's classifier, a stored rule / pre-approval / class table in `default`, `acceptEdits` or `plan`, or a stored rule / pre-approval in `dontAsk`: the measured typo'd quote or unclosed here-document after `rm -rf ~` or `cat .env` let the statement run; on the narrowed face the other answerers still met `probe` (a question, or refusal in `dontAsk`). Harmed: a model that writes a deny-listed read before a same-line syntax error now gets a refusal instead of a shell error; the corrected text is refused as well (pinned for the gate matrix's statements), so none of those measured statements that could run is lost there. Compensation: none needed for those measured statements.
23
+ - **Pins.** `test/backlog4862-readable-part.test.ts` — the shell facts (bash), the lexer's and the planner's reading, a gate matrix (7 statements a readable command has refused or forcibly asked × 14 tails × 11 arms: never looser than the statement alone except KL-4862-c, the rule lane's length bound, where a person's deny rule is a question with the real-approval bit instead of the refusal), the nine forms and six of their kin × 50 arms (equal to the statement alone for the nine and kin whose statement alone is refused or a person's; only “not looser” for kin whose statement alone is an ordinary question), 20 operand spellings × 3 statements × 11 arms (the operand's own quoting among them), 18 forms that must not move × 11 arms (equal, cell for cell, to their reading measured before this change).
24
+ - **Consumers.** @server @cli: a black-box cell that pinned 7.68.6's release of `rm -rf ~; cat <<EOF` / `cat .env⏎echo 'x` reads the 7.68.5 answer again (a person with the bit / refused); `echo "${X:-$(cat .env)}"` is newly refused, stricter than 7.68.5 as well as 7.68.6 (it ran under `bypassPermissions` on both); the hidden forms (`… | xargs rm -rf`, `printf … | bash`, `rm "$(printf …)"`, `bash -c "$(echo rm ~)"`) do not move. @test: the forms, expected readings and error codes are in this release's receipt.
25
+ - **Known limits.** KL-4862-a (statements the shell does not reach, judged as runs), KL-4862-b (a host shell that is zsh or ksh), KL-4862-c (the rule lane's length bound), KL-4862-d (where the lexer itself stops early inside a loop or an operand), KL-4862-e (a statement written after a construct the lexer cannot read past but the shell can — not judged, as on 7.68.6: under `bypassPermissions` or a blanket allow it runs unasked on both faces; auto's classifier and a stored rule / pre-approval / class table clear it on the open face (the latter three in `default`, `acceptEdits` and `plan`; only a stored rule / pre-approval in `dontAsk`); on the narrowed face those other answerers still meet `probe`, and `default` with no answerer still asks).
26
+
1
27
  ## 7.68.6 — 2026-11-17
2
28
 
3
29
  ### What the engine cannot read or verify is an ordinary question, in every mode: a shell text it cannot read and a recursive delete whose target it cannot verify no longer stop `bypassPermissions`; their own class no longer keeps them from the auto-mode classifier or an allow rule; `echo $(( $(date -u +%s) + 3000 ))` runs under `bypassPermissions` with no card on either read face (#4784; the owner's direct ruling — a widening; what it lets run without a question is listed below, open to veto @cli @server @test; narrowing: one, below, open to veto @server — an approver's edit on resume, KL-4784-f; hard-breaking: none)
@@ -11,7 +11,7 @@ import { INLINE_TRUNCATION_MARK, inlineUntrusted, UNRENDERABLE_CHAR_CLASS } from
11
11
  import { catalogRuleFaceOf, catalogToolNames, hostTargetOf, isShellFaceToolName, pathTargetOf, protectivePathTargetOf } from "./tool-registry.js";
12
12
  import { HOST_UNREADABLE_SENTENCE, hostPatternAdmits, readHostPattern, spelledHostPattern } from "./host-target.js";
13
13
  import { heldBy, heldValues, wireOf } from "./tool-name-readings.js";
14
- import { carriesDotSegment, isAbsoluteForFamily, isIdentityDir, isPathIdentity, isShellRootedSpellingUnmapped, isUncIdentity, pathFamilyOf, pathIdentityOf } from "../tools/fs/safety.js";
14
+ import { carriesDotSegment, isAbsoluteForFamily, isIdentityDir, isPathIdentity, isShellRootedSpellingUnmapped, isUncIdentity, pathFamilyOf, pathIdentityOf, shellDriveSpellingOf } from "../tools/fs/safety.js";
15
15
  import { bindPathRules, judgeRuleRows, rowsWhereTheyLead } from "./path-rule-binding.js";
16
16
  import { readShellCommand } from "./shell-run-candidates.js";
17
17
  import { lineDescriptorsOfText, readOnlyLineObjection, readOnlyShellVerdict } from "./read-only-shell.js";
@@ -1330,7 +1330,8 @@ function resolveCdSegmentDirectories(segments, cwd) {
1330
1330
  if (!priorCd && movesShellCursor(segment))
1331
1331
  priorCd = true;
1332
1332
  const bases = basesOfCwd(cwd);
1333
- return dir === undefined || isShellRootedSpellingUnmapped(pathFamilyOf(bases), dir) ? undefined : directoryIdentityOf(dir, bases);
1333
+ const family = pathFamilyOf(bases);
1334
+ return dir === undefined || isShellRootedSpellingUnmapped(family, dir) || shellDriveSpellingOf(family, dir) !== undefined ? undefined : directoryIdentityOf(dir, bases);
1334
1335
  });
1335
1336
  }
1336
1337
  export function scopeCoversCwd(scope, cwd, sessionId, identity) {
@@ -244,7 +244,12 @@ export interface LexParseFailure {
244
244
  };
245
245
  /** The segments the walk read before it stopped, the last one holding the tokens it had read when it stopped. Bash runs
246
246
  * each complete line before it parses the next one (`rm -r x` on line 1 runs although line 2 never closes its quote),
247
- * so a reader asking what the text MAY run reads these as runs; a reader asking what the text DOES reads the failure. */
247
+ * so a reader asking what the text MAY run reads these as runs; a reader asking what the text DOES reads the failure.
248
+ * Every segment before the last is such a run — the read station's planner and the deny lanes read the same ones. A
249
+ * here-document the text never terminates is read as the shells read it, to the end of the text: the segment owning it
250
+ * holds that body, and the last segment is an empty one at the text's end. Which of these runs a shell reaches is not
251
+ * decided here (a quote left open on the SAME line stops bash before any of that line runs; zsh parses the whole text
252
+ * first): the reading is of what MAY run. */
248
253
  readonly readBefore: readonly LexedSegment[];
249
254
  }
250
255
  /** A command: its segments, or the one reason it has none. */
@@ -319,6 +324,19 @@ export declare function parameterArithmeticTexts(body: string): {
319
324
  readonly subscript?: string;
320
325
  readonly offset?: string;
321
326
  };
327
+ /**
328
+ * The command lines a parameter expansion's OPERAND runs (`${X:-$(cmd)}` when X is unset or empty, `${X:+$(cmd)}` when it is
329
+ * set, `${X#$(cmd)}` always; measured on bash 3.2 and 5.2, dash, zsh): the command and process substitutions written in it,
330
+ * and those of the arithmetic and parameter expansions written in it — read as the shell expands the operand, left to right.
331
+ * In double quotes (`quoted`) a single quote is an ordinary character there and `<(` is text (`"${X:-'$(cmd)'}"` runs cmd);
332
+ * outside them a single-quoted run is text, a double-quoted run inside the operand reads as in double quotes, and
333
+ * `<(…)` / `>(…)` are process substitutions (`${X:-'$(cmd)'}` runs nothing, `${X:-"'$(cmd)'"}` runs cmd). A substitution's
334
+ * own text is never rewritten (`${X:-$(cat '.env')}` reads `cat '.env'`). A subscript and a substring offset are not operand
335
+ * text ({@link parameterArithmeticTexts}: the evaluator's). The walk stops at an expansion it cannot delimit and keeps what it
336
+ * read before it: the word itself stays unread either way (its braces carry `$`, {@link UNREADABLE_EXPANSION_TEXT}). The
337
+ * one reading of what an operand runs: the deny lanes' lines ({@link expansionRunsOf}) and the read station's nested plans.
338
+ */
339
+ export declare function parameterOperandLines(body: string, quoted: boolean): readonly string[];
322
340
  /** What evaluating an expansion (a word's, a here-document body's) runs, as far as its text shows it. `lines`: the command
323
341
  * lines its substitutions run, each a command line of its own — a command or process substitution's body, the list of
324
342
  * `${ …; }`, and the substitutions an arithmetic text holds (bash expands that text as double-quoted text first:
@@ -326,13 +344,18 @@ export declare function parameterArithmeticTexts(body: string): {
326
344
  * ALSO run a program no line shows — the arithmetic evaluator evaluates a NAME recursively (`a='x[$(…)]'; $((a))`), so
327
345
  * arithmetic text that names a variable or carries a `$` may, and so may a parameter expansion's subscript or substring
328
346
  * offset (its own or one nested in its text, `${x:-${a[i]}}`), a value it re-reads (`${!R}`, `${P@P}`), and a parameter,
329
- * brace or glob text that carries a substitution opener (a parameter's operand is word grammar this lexer does not read).
330
- * The one reading of what an expansion runs: {@link expansionHidesRun} is its boolean face. */
347
+ * brace or glob text that carries a substitution opener. A parameter's operand is word grammar this lexer does not read as
348
+ * words, but the substitutions written in it run (`${X:-$(cmd)}` runs cmd when X is unset, `${X#$(cmd)}` always; measured on
349
+ * bash 3.2 and 5.2, dash, zsh): they are its lines ({@link parameterOperandLines}, the reading the read station's planner
350
+ * takes of the same operand), and the expansion stays hidden — whether the operand is expanded, and what it yields, the
351
+ * text does not say. The one reading of what an expansion runs: {@link expansionHidesRun} is its boolean face. */
331
352
  export interface ExpansionRuns {
332
353
  readonly lines: readonly string[];
333
354
  readonly hidden: boolean;
334
355
  }
335
- export declare function expansionRunsOf(e: WordExpansion): ExpansionRuns;
356
+ /** `quoted`: the expansion stands in double quotes (a here-document body and an arithmetic text expand as such) — how its
357
+ * operand's quotes read ({@link parameterOperandLines}). */
358
+ export declare function expansionRunsOf(e: WordExpansion, quoted?: boolean): ExpansionRuns;
336
359
  /** An arithmetic text's runs: none when it is plain ({@link arithmeticTextIsPlain}); else hidden (the evaluator may run
337
360
  * what a value names), with the lines of the substitutions it holds, read as double-quoted text
338
361
  * ({@link expansionsInHeredocBody}: quotes are ordinary characters there). */
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
- return "unterminated";
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
- const ch = body[i];
648
- if (ch === "\\") {
655
+ if (body[i] === "\\") {
649
656
  i++;
650
657
  continue;
651
658
  }
652
- if (ch === "`") {
653
- const tick = backtickBody(body, i);
654
- if (tick === undefined)
655
- return undefined;
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
- const open = body[i + 1];
662
- if (open === "(") {
663
- const close = substitutionBodyEnd(body, i + 1, true, 0, "document");
664
- if (typeof close !== "object" || !("end" in close))
665
- return undefined;
666
- i = push({ expansion: { kind: close.arithmetic ? "arithmetic" : "command", yields: "one", body: body.slice(i + 2, close.end - 1) } }, i, close.end - 1);
667
- }
668
- else if (open === "[") {
669
- const end = bracketExpansionEnd(body, i + 1);
670
- if (end === undefined)
671
- return undefined;
672
- i = push({ expansion: { kind: "arithmetic", yields: "one", body: body.slice(i + 2, end - 1) } }, i, end - 1);
673
- }
674
- else if (open === "{") {
675
- if (opensCurrentShellSubstitution(body, i + 1)) {
676
- const run = currentShellSubstitutionEnd(body, i + 1, 1);
677
- if (typeof run !== "object" || !("end" in run))
678
- return undefined;
679
- i = push({ expansion: { kind: "command", yields: "one", body: body.slice(run.from, run.end - 1) }, currentShell: true }, i, run.end - 1);
680
- continue;
681
- }
682
- const end = braceExpansionEnd(body, i + 1);
683
- if (end === undefined)
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
- const text = body.slice(i + 2, end - 1);
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
- return out;
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
- return hidden ? joinRuns([HIDDEN_RUNS, inner]) : inner;
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 fail("unterminated_heredoc", from);
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 fail("unterminated_heredoc", source.length);
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 spellingsOf(anchorSpelling(family, base, raw));
232
+ return shellAnchored(anchorSpelling(family, base, raw));
229
233
  }
230
234
  function spellingsOf(absolute) {
231
235
  const folded = normalizeAbsPathLexically(absolute);
@@ -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 msys = /^\/([A-Za-z])(\/.*)?$/.exec(captured);
435
+ const drive = windowsWorld ? shellDriveSpellingOf("win", captured) : undefined;
436
436
  if (/^[A-Za-z]:[\\/]/.test(captured))
437
437
  cwdRef.current = captured;
438
- else if (windowsWorld && msys)
439
- cwdRef.current = `${msys[1]}:${msys[2] ?? "/"}`;
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 at all, {@link unreadPlan}), or a
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. The read-face copy of an operand is not judged: it follows a link the removal does not follow.
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: bash may run the lines before its
134
- * syntax error, and the guard reads no prefix of it). Otherwise `judge` establishes the plan the read
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
- if (unreadPlan(established.plan))
118
- return [{ guard: "unverifiable_shell_text", program: "bash", text: established.plan.unreadable, source: "unread" }];
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(...removalFindingsOf(sub, seat, safeRoots, handedRelocated, true));
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");
@@ -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
- /** A ROOTED (not qualified) spelling handed to the SHELL on a win tree (`/d/x`, `/etc`, `\\x`) is the shell's to
381
- * map — the win32 adapter runs Git Bash, where `/d/x` is drive D and `/etc` the MSYS root, neither the cwd's
382
- * drive root — so no lexical reader may resolve it (fail-closed: the operand is unresolvable, the cd mints
383
- * nothing). The ONE statement of that rule, for every shell-facing resolver. */
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
@@ -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
- /** The lexer refused the whole text (an unterminated construct, nesting past the bound). UNCONDITIONAL
174
- * fail-closed for the consumer: a quote-blind re-read yields more words, never zero, so this is not "no candidates". */
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
- if ("parseFailure" in lexedAsWritten)
44
- return { plan: { segments: [], unreadable: PARSE_FAILURE_SENTENCE[lexedAsWritten.parseFailure.reason], shape }, end: "unmodelled", physical: false, reached: none };
45
- const lexed = inlineSourcedLiterals(lexedAsWritten);
46
- const unreadable = unreadableSentenceOf(lexed, command);
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
- if ("parseFailure" in inner || inner.segments.length === 0) {
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
- inner.segments.forEach((s, k) => out.push(k === 0 ? { ...s, connector: segment.connector, spliced: true } : { ...s, spliced: true }));
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.6",
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.6",
136
+ "@sema-agent/primitives": "7.68.7",
137
137
  "typebox": "1.1.39",
138
138
  "undici": "7.30.2"
139
139
  },
@@ -0,0 +1,39 @@
1
+ {
2
+ "repo": "core",
3
+ "package": "@sema-agent/core-stores-sql",
4
+ "version": "7.68.7",
5
+ "from": "3ff2e275b59a02a98f8bf01f237114e9d69e3564",
6
+ "to": "v7.68.7",
7
+ "added": [],
8
+ "removed": [],
9
+ "changed": [],
10
+ "subpaths": [],
11
+ "subpathsUnread": [
12
+ "from",
13
+ "to"
14
+ ],
15
+ "narrowed": [],
16
+ "faces": {
17
+ "open": [],
18
+ "source": null
19
+ },
20
+ "closedSetMembers": [],
21
+ "closedSetsUnreadable": [],
22
+ "typeKeys": [],
23
+ "typeKeysUnreadableArms": [],
24
+ "typeKeysFlattenedCount": 3,
25
+ "signatures": [],
26
+ "versionLiterals": [],
27
+ "declarationMoves": [],
28
+ "mintMoves": [],
29
+ "criteriaObserves": [],
30
+ "consumersHint": {
31
+ "cli": [],
32
+ "server": [],
33
+ "sdk": [],
34
+ "note": "scanned cli@df9465c17 server@e07c1cd1c sdk@3724afe — a name listed is MENTIONED there today, which is evidence of consumption, not proof of it"
35
+ },
36
+ "breakingCount": 0,
37
+ "breakingItems": [],
38
+ "toResolvedAt": "9b95ae51a6785402c198355687168e5d0d912e65"
39
+ }
@@ -0,0 +1,140 @@
1
+ {
2
+ "repo": "core",
3
+ "version": "7.68.7",
4
+ "from": "3ff2e275b59a02a98f8bf01f237114e9d69e3564",
5
+ "to": "v7.68.7",
6
+ "added": [],
7
+ "removed": [],
8
+ "changed": [],
9
+ "subpaths": [],
10
+ "narrowed": [
11
+ {
12
+ "id": "F1",
13
+ "source": "behaviorFlips.summary",
14
+ "text": "#4862 (narrowing of 7.68.6): in a command text the lexer cannot read to its end, every statement it read in full before it stopped is judged as itself — a protected-location removal is a person's with `requiresRealApproval`, a deny-listed read is refused, a write-protected target and the read roots are judged — and the rest of the text is the ordinary question beside that verdict. An unterminated here-document is read as the measured shells read it (`DESIGN-4862.md` §2 S01/S05/S06/S34; `local-shells.out`): its body runs to the end of the text."
15
+ },
16
+ {
17
+ "id": "F2",
18
+ "source": "behaviorFlips.summary",
19
+ "text": "#4862 (narrowing; a gap older than 7.68.6): a command written in a parameter expansion's operand (`${X:-$(…)}`, `${X#$(…)}`, a backquote there, `<(…)` outside double quotes) is planned as any substitution is, the operand read as the shell quotes it."
20
+ },
21
+ {
22
+ "id": "F5",
23
+ "source": "behaviorFlips.summary",
24
+ "text": "#4854 (narrowing on Windows hosts): on a Windows-family tree a `/`-rooted shell operand is folded as Git Bash folds it and a single-letter first segment is that drive (`/c/rest`, `/C/rest` ⇒ `C:\\rest`; three or more leading slashes read as one), so reads, writes, redirections, `cd` targets and the removal guard judge it as its `C:/…` twin; the tracked working directory reads the shell's `/c/…` pwd the same way."
25
+ }
26
+ ],
27
+ "faces": {
28
+ "open": [
29
+ "TRACE_EVENT_KINDS",
30
+ "TraceEvent"
31
+ ],
32
+ "source": "src/core/contract-faces.ts"
33
+ },
34
+ "closedSetMembers": [],
35
+ "closedSetsUnreadable": [],
36
+ "typeKeys": [
37
+ {
38
+ "type": "ShellReadPlan",
39
+ "at": [
40
+ "src/tools/fs/shell-read-plan.ts:269"
41
+ ],
42
+ "added": [
43
+ "unreadTail"
44
+ ],
45
+ "addedDetail": [
46
+ {
47
+ "key": "unreadTail",
48
+ "optional": true
49
+ }
50
+ ],
51
+ "addedRequired": [],
52
+ "removed": [],
53
+ "madeRequired": [],
54
+ "madeOptional": [],
55
+ "retyped": [],
56
+ "breaking": false,
57
+ "criteriaCovered": true
58
+ }
59
+ ],
60
+ "typeKeysUnreadableArms": [],
61
+ "typeKeysFlattenedCount": 305,
62
+ "signatures": [],
63
+ "versionLiterals": [],
64
+ "declarationMoves": [],
65
+ "mintMoves": [],
66
+ "criteriaObserves": [
67
+ {
68
+ "kind": "taskEventField",
69
+ "name": "tool_end.gate",
70
+ "assertions": [
71
+ "G2.a",
72
+ "G3.a",
73
+ "G3.b",
74
+ "G4.a",
75
+ "G5.a",
76
+ "G6.a"
77
+ ]
78
+ },
79
+ {
80
+ "kind": "typeMember",
81
+ "name": "AskRequest.askClass",
82
+ "assertions": [
83
+ "G1.a",
84
+ "G4.a",
85
+ "G6.a"
86
+ ]
87
+ },
88
+ {
89
+ "kind": "typeMember",
90
+ "name": "AskRequest.requiresRealApproval",
91
+ "assertions": [
92
+ "G1.a",
93
+ "G6.a"
94
+ ]
95
+ },
96
+ {
97
+ "kind": "typeMember",
98
+ "name": "RunnerDeps.readFace",
99
+ "assertions": [
100
+ "G1.a"
101
+ ]
102
+ },
103
+ {
104
+ "kind": "typeMember",
105
+ "name": "ShellReadPlan.unreadTail",
106
+ "assertions": [
107
+ "G2.a"
108
+ ]
109
+ },
110
+ {
111
+ "kind": "typeMember",
112
+ "name": "TaskSpec.permissionMode",
113
+ "assertions": [
114
+ "G1.a",
115
+ "G3.a",
116
+ "G5.a"
117
+ ]
118
+ },
119
+ {
120
+ "kind": "typeMember",
121
+ "name": "TaskSpec.readDenyPatterns",
122
+ "assertions": [
123
+ "G2.a",
124
+ "G3.b",
125
+ "G4.a"
126
+ ]
127
+ }
128
+ ],
129
+ "consumersHint": {
130
+ "cli": [
131
+ "ShellReadPlan"
132
+ ],
133
+ "server": [],
134
+ "sdk": [],
135
+ "note": "scanned cli@df9465c17 server@e07c1cd1c sdk@3724afe — a name listed is MENTIONED there today, which is evidence of consumption, not proof of it. Ledger files (**/docs/core-consumption/**, **/docs/wire-consumption/**, **/*LEDGER*.json) are not evidence of use — server: 1 name(s) matched ONLY in bookkeeping files and were set aside (ShellReadPlan)"
136
+ },
137
+ "breakingCount": 0,
138
+ "breakingItems": [],
139
+ "toResolvedAt": "9b95ae51a6785402c198355687168e5d0d912e65"
140
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "repo": "core",
3
+ "package": "@sema-agent/mods-kernel",
4
+ "version": "7.68.7",
5
+ "from": "3ff2e275b59a02a98f8bf01f237114e9d69e3564",
6
+ "to": "v7.68.7",
7
+ "added": [],
8
+ "removed": [],
9
+ "changed": [],
10
+ "subpaths": [],
11
+ "subpathsUnread": [
12
+ "from",
13
+ "to"
14
+ ],
15
+ "narrowed": [],
16
+ "faces": {
17
+ "open": [],
18
+ "source": null
19
+ },
20
+ "closedSetMembers": [],
21
+ "closedSetsUnreadable": [],
22
+ "typeKeys": [],
23
+ "typeKeysUnreadableArms": [],
24
+ "typeKeysFlattenedCount": 1,
25
+ "signatures": [],
26
+ "versionLiterals": [],
27
+ "declarationMoves": [],
28
+ "mintMoves": [],
29
+ "criteriaObserves": [],
30
+ "consumersHint": {
31
+ "cli": [],
32
+ "server": [],
33
+ "sdk": [],
34
+ "note": "scanned cli@df9465c17 server@e07c1cd1c sdk@3724afe — a name listed is MENTIONED there today, which is evidence of consumption, not proof of it"
35
+ },
36
+ "breakingCount": 0,
37
+ "breakingItems": [],
38
+ "toResolvedAt": "9b95ae51a6785402c198355687168e5d0d912e65"
39
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "repo": "core",
3
+ "package": "@sema-agent/primitives",
4
+ "version": "7.68.7",
5
+ "from": "3ff2e275b59a02a98f8bf01f237114e9d69e3564",
6
+ "to": "v7.68.7",
7
+ "added": [],
8
+ "removed": [],
9
+ "changed": [],
10
+ "subpaths": [],
11
+ "subpathsUnread": [
12
+ "from",
13
+ "to"
14
+ ],
15
+ "narrowed": [],
16
+ "faces": {
17
+ "open": [],
18
+ "source": null
19
+ },
20
+ "closedSetMembers": [],
21
+ "closedSetsUnreadable": [],
22
+ "typeKeys": [],
23
+ "typeKeysUnreadableArms": [],
24
+ "typeKeysFlattenedCount": 7,
25
+ "signatures": [],
26
+ "versionLiterals": [],
27
+ "declarationMoves": [],
28
+ "mintMoves": [],
29
+ "criteriaObserves": [],
30
+ "consumersHint": {
31
+ "cli": [],
32
+ "server": [],
33
+ "sdk": [],
34
+ "note": "scanned cli@df9465c17 server@e07c1cd1c sdk@3724afe — a name listed is MENTIONED there today, which is evidence of consumption, not proof of it"
35
+ },
36
+ "breakingCount": 0,
37
+ "breakingItems": [],
38
+ "toResolvedAt": "9b95ae51a6785402c198355687168e5d0d912e65"
39
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "repo": "core",
3
+ "package": "@sema-agent/wiki-gate",
4
+ "version": "7.68.7",
5
+ "from": "3ff2e275b59a02a98f8bf01f237114e9d69e3564",
6
+ "to": "v7.68.7",
7
+ "added": [],
8
+ "removed": [],
9
+ "changed": [],
10
+ "subpaths": [],
11
+ "subpathsUnread": [
12
+ "from",
13
+ "to"
14
+ ],
15
+ "narrowed": [],
16
+ "faces": {
17
+ "open": [],
18
+ "source": null
19
+ },
20
+ "closedSetMembers": [],
21
+ "closedSetsUnreadable": [],
22
+ "typeKeys": [],
23
+ "typeKeysUnreadableArms": [],
24
+ "typeKeysFlattenedCount": 5,
25
+ "signatures": [],
26
+ "versionLiterals": [],
27
+ "declarationMoves": [],
28
+ "mintMoves": [],
29
+ "criteriaObserves": [],
30
+ "consumersHint": {
31
+ "cli": [],
32
+ "server": [],
33
+ "sdk": [],
34
+ "note": "scanned cli@df9465c17 server@e07c1cd1c sdk@3724afe — a name listed is MENTIONED there today, which is evidence of consumption, not proof of it"
35
+ },
36
+ "breakingCount": 0,
37
+ "breakingItems": [],
38
+ "toResolvedAt": "9b95ae51a6785402c198355687168e5d0d912e65"
39
+ }