@sema-agent/core 7.65.0 → 7.66.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +269 -0
  2. package/dist/agents/delegation-registry-seat.d.ts +15 -0
  3. package/dist/agents/delegation-registry-seat.js +13 -0
  4. package/dist/agents/org-delivery-gate.d.ts +8 -1
  5. package/dist/agents/org-delivery-gate.js +9 -3
  6. package/dist/agents/peer-session-drain.d.ts +51 -12
  7. package/dist/agents/peer-session-drain.js +44 -31
  8. package/dist/agents/read-inbox-tool.d.ts +6 -2
  9. package/dist/agents/read-inbox-tool.js +18 -5
  10. package/dist/agents/subagent.d.ts +3 -1
  11. package/dist/agents/subagent.js +79 -75
  12. package/dist/brain/reasoning.d.ts +2 -0
  13. package/dist/brain/reasoning.js +1 -0
  14. package/dist/core/allow-entry.d.ts +9 -0
  15. package/dist/core/allow-entry.js +7 -1
  16. package/dist/core/ask-origin.d.ts +23 -3
  17. package/dist/core/ask-origin.js +11 -1
  18. package/dist/core/engine-notice.d.ts +3 -3
  19. package/dist/core/governance-codes.js +1 -0
  20. package/dist/core/human-input-projection.d.ts +9 -0
  21. package/dist/core/human-input-projection.js +13 -0
  22. package/dist/core/input-author.d.ts +66 -6
  23. package/dist/core/input-author.js +21 -3
  24. package/dist/core/memory-engine/consolidation.d.ts +23 -9
  25. package/dist/core/memory-engine/consolidation.js +30 -5
  26. package/dist/core/memory-engine/control-plane-adoption.d.ts +11 -10
  27. package/dist/core/memory-engine/control-plane-adoption.js +54 -29
  28. package/dist/core/memory-engine/delegation-settlement.d.ts +18 -12
  29. package/dist/core/memory-engine/delegation-settlement.js +36 -26
  30. package/dist/core/memory-engine/engine.d.ts +17 -6
  31. package/dist/core/memory-engine/engine.js +78 -35
  32. package/dist/core/memory-engine/file-backend.d.ts +4 -1
  33. package/dist/core/memory-engine/file-backend.js +5 -1
  34. package/dist/core/memory-engine/index.d.ts +2 -2
  35. package/dist/core/memory-engine/index.js +2 -2
  36. package/dist/core/memory-engine/layout.d.ts +57 -36
  37. package/dist/core/memory-engine/layout.js +109 -134
  38. package/dist/core/memory-engine/memory-backend-contract.js +7 -7
  39. package/dist/core/memory-engine/memory-deployment.d.ts +3 -2
  40. package/dist/core/memory-engine/memory-deployment.js +6 -3
  41. package/dist/core/memory-engine/origin-clearance.d.ts +43 -15
  42. package/dist/core/memory-engine/origin-clearance.js +143 -55
  43. package/dist/core/model-receipt.d.ts +2 -1
  44. package/dist/core/model-receipt.js +5 -0
  45. package/dist/core/mods/dollar.d.ts +12 -0
  46. package/dist/core/mods/kernel/dispatch.d.ts +3 -1
  47. package/dist/core/mods/kernel/dispatch.js +5 -2
  48. package/dist/core/mods/kernel/events.d.ts +3 -1
  49. package/dist/core/mods/kernel/events.js +2 -2
  50. package/dist/core/mods/prompt-submit.d.ts +4 -0
  51. package/dist/core/mods/prompt-submit.js +24 -0
  52. package/dist/core/mods/stations.d.ts +23 -4
  53. package/dist/core/mods/stations.js +14 -7
  54. package/dist/core/retired-host-table-account.d.ts +19 -0
  55. package/dist/core/retired-host-table-account.js +28 -0
  56. package/dist/core/retired-tool-name-account.d.ts +60 -0
  57. package/dist/core/retired-tool-name-account.js +32 -0
  58. package/dist/core/roles.d.ts +3 -1
  59. package/dist/core/roles.js +5 -2
  60. package/dist/core/runner/compact-session.js +2 -1
  61. package/dist/core/runner/contracts.d.ts +1 -1
  62. package/dist/core/runner/gate-exit.js +9 -2
  63. package/dist/core/runner/memory-consolidation-driver.js +2 -2
  64. package/dist/core/runner/prepare-config-doors.js +1 -1
  65. package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
  66. package/dist/core/runner/prepare-delegation-surface.js +5 -3
  67. package/dist/core/runner/prepare-inherited-gate.js +2 -0
  68. package/dist/core/runner/prepare-memory.js +26 -5
  69. package/dist/core/runner/prepare-park-ask.d.ts +2 -0
  70. package/dist/core/runner/prepare-park-ask.js +3 -1
  71. package/dist/core/runner/prepare-policy-chain.js +2 -1
  72. package/dist/core/runner/prepare-project-context.js +2 -2
  73. package/dist/core/runner/prepare-question-face.d.ts +2 -2
  74. package/dist/core/runner/prepare-task.d.ts +5 -1
  75. package/dist/core/runner/prepare-task.js +5 -4
  76. package/dist/core/runner/prepare-wiring-manifest.js +5 -4
  77. package/dist/core/runner/prompt-suggestions.js +1 -1
  78. package/dist/core/runner/run-identity-wiring.js +2 -2
  79. package/dist/core/runner/run-leg.js +3 -3
  80. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  81. package/dist/core/runner/run-notification-lane.js +2 -2
  82. package/dist/core/runner/runtask.js +6 -3
  83. package/dist/core/runner/steer-admission.d.ts +11 -2
  84. package/dist/core/runner/stream-steer-verb.d.ts +5 -2
  85. package/dist/core/runner/stream-steer-verb.js +67 -14
  86. package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -27
  87. package/dist/core/runner/sub-agent-deny-lists.js +22 -33
  88. package/dist/core/runner-deps.d.ts +4 -4
  89. package/dist/core/shell-run-candidates.js +3 -3
  90. package/dist/core/side-query.js +1 -1
  91. package/dist/core/skill-grant.d.ts +7 -0
  92. package/dist/core/skill-grant.js +14 -5
  93. package/dist/core/task-event.d.ts +14 -0
  94. package/dist/core/tool-policy.js +2 -3
  95. package/dist/core/tool-spec.d.ts +13 -3
  96. package/dist/core/user-attachment.d.ts +5 -1
  97. package/dist/core/user-attachment.js +11 -5
  98. package/dist/engine/harness/agent-harness.d.ts +19 -11
  99. package/dist/engine/harness/agent-harness.js +7 -4
  100. package/dist/engine/llm/types.d.ts +22 -10
  101. package/dist/index.d.ts +4 -2
  102. package/dist/index.js +3 -1
  103. package/dist/shell/lex.d.ts +50 -15
  104. package/dist/shell/lex.js +43 -9
  105. package/dist/tools/fs/fs-bash.js +3 -3
  106. package/dist/tools/fs/removal-targets.d.ts +8 -2
  107. package/dist/tools/fs/removal-targets.js +31 -4
  108. package/dist/tools/fs/shell-read-argv.js +7 -1
  109. package/dist/tools/fs/shell-read-bindings.d.ts +21 -5
  110. package/dist/tools/fs/shell-read-bindings.js +130 -44
  111. package/dist/tools/fs/shell-read-plan.js +95 -29
  112. package/dist/tools/fs/shell-read-sourced.d.ts +25 -0
  113. package/dist/tools/fs/shell-read-sourced.js +119 -0
  114. package/dist/tools/fs/shell-read-word.d.ts +2 -2
  115. package/dist/tools/fs/shell-read-word.js +4 -5
  116. package/dist/tools/fs/shell-read-workdir.d.ts +19 -3
  117. package/dist/tools/fs/shell-read-workdir.js +60 -15
  118. package/dist/tools/fs/shell-reentry-text.d.ts +10 -2
  119. package/dist/tools/fs/shell-reentry-text.js +11 -4
  120. package/package.json +2 -2
  121. package/test/export-surface.snapshot.json +13 -7
  122. package/wire-changes/core-stores-sql@7.66.0.json +30 -0
  123. package/wire-changes/core-stores-sql@7.66.1.json +30 -0
  124. package/wire-changes/core@7.66.0.json +1218 -0
  125. package/wire-changes/core@7.66.1.json +46 -0
  126. package/wire-changes/mods-kernel@7.66.0.json +65 -0
  127. package/wire-changes/mods-kernel@7.66.1.json +30 -0
  128. package/wire-changes/primitives@7.66.0.json +30 -0
  129. package/wire-changes/primitives@7.66.1.json +30 -0
@@ -0,0 +1,119 @@
1
+ import { ANSI_C_ESCAPES, argvOf, lexShell, literalTextOf } from "../../shell/lex.js";
2
+ import { readProgramPosition } from "./bash-program-position.js";
3
+ const SOURCE_WORDS = new Set([".", "source"]);
4
+ const SPLICE_DEPTH_MAX = 4;
5
+ function sameFileSpelling(a, b) {
6
+ const strip = (s) => s.replace(/^(?:\.\/)+/, "");
7
+ return a.length > 0 && b.length > 0 && strip(a) === strip(b);
8
+ }
9
+ const PRINTF_ESCAPES = Object.fromEntries(["n", "t", "\\", '"', "a", "b", "f", "r", "v", "e", "E"].map((k) => [k, ANSI_C_ESCAPES[k]]));
10
+ function printfFormatText(format) {
11
+ const escapes = PRINTF_ESCAPES;
12
+ let out = "";
13
+ for (let i = 0; i < format.length; i++) {
14
+ const ch = format[i];
15
+ if (ch === "%") {
16
+ if (format[i + 1] === "%") {
17
+ out += "%";
18
+ i++;
19
+ continue;
20
+ }
21
+ return undefined;
22
+ }
23
+ if (ch === "\\") {
24
+ const e = format[i + 1];
25
+ if (e === undefined || !(e in escapes))
26
+ return undefined;
27
+ out += escapes[e];
28
+ i++;
29
+ continue;
30
+ }
31
+ out += ch;
32
+ }
33
+ return out;
34
+ }
35
+ function writtenLiteralOf(segment) {
36
+ const redirects = segment.tokens.filter((t) => t.kind === "redirect");
37
+ if (redirects.length !== 1 || segment.tokens.some((t) => t.kind === "heredoc" || t.kind === "group"))
38
+ return undefined;
39
+ const r = redirects[0];
40
+ if (r.kind !== "redirect" || r.op !== ">" || (r.fd ?? 1) !== 1 || r.target === undefined)
41
+ return undefined;
42
+ const file = literalTextOf(r.target.pieces);
43
+ if (file === undefined)
44
+ return undefined;
45
+ const argv = argvOf(segment);
46
+ const pos = readProgramPosition(argv);
47
+ if (pos.program === undefined || pos.refusal !== undefined || pos.launchers.length > 0 || pos.assignments.length > 0 || pos.controlWords.length > 0)
48
+ return undefined;
49
+ const words = argv.slice(pos.program.index + 1).map((w) => literalTextOf(w.pieces));
50
+ if (words.some((w) => w === undefined))
51
+ return undefined;
52
+ const literal = words;
53
+ if (pos.program.basename === "printf") {
54
+ if (literal.length !== 1)
55
+ return undefined;
56
+ const text = printfFormatText(literal[0]);
57
+ return text === undefined ? undefined : { file, text };
58
+ }
59
+ if (pos.program.basename === "echo") {
60
+ let noNewline = false;
61
+ let k = 0;
62
+ for (; k < literal.length && /^-[neE]+$/.test(literal[k]); k++) {
63
+ if (literal[k].includes("e"))
64
+ return undefined;
65
+ if (literal[k].includes("n"))
66
+ noNewline = true;
67
+ }
68
+ const rest = literal.slice(k);
69
+ if (rest.some((w) => w.includes("\\")))
70
+ return undefined;
71
+ return { file, text: rest.join(" ") + (noNewline ? "" : "\n") };
72
+ }
73
+ return undefined;
74
+ }
75
+ function sourcedFileOf(argv) {
76
+ const pos = readProgramPosition(argv);
77
+ if (pos.program === undefined || !SOURCE_WORDS.has(pos.program.basename) || pos.refusal !== undefined || pos.launchers.length > 0 || pos.assignments.length > 0)
78
+ return undefined;
79
+ const rest = argv.slice(pos.program.index + 1);
80
+ const at = rest.findIndex((w) => !w.folded.startsWith("-") || w.folded === "-");
81
+ if (at < 0 || rest.length !== at + 1)
82
+ return undefined;
83
+ return literalTextOf(rest[at].pieces);
84
+ }
85
+ export function inlineSourcedLiterals(lexed) {
86
+ let segments = lexed.segments;
87
+ for (let depth = 0; depth < SPLICE_DEPTH_MAX; depth++) {
88
+ let spliced = false;
89
+ const out = [];
90
+ for (let si = 0; si < segments.length; si++) {
91
+ const segment = segments[si];
92
+ const file = sourcedFileOf(argvOf(segment));
93
+ if (file === undefined || segment.connector === "|" || segment.sourced === true || segment.tokens.some((t) => t.kind !== "word")) {
94
+ out.push(segment);
95
+ continue;
96
+ }
97
+ const prev = out[out.length - 1];
98
+ const written = prev === undefined || prev.connector === "|" ? undefined : writtenLiteralOf(prev);
99
+ const conditional = prev !== undefined && (prev.connector === "||" || segment.connector === "||" || (prev.connector === "&&" && segment.connector !== "&&"));
100
+ const text = written !== undefined && !conditional && sameFileSpelling(written.file, file) ? written.text : undefined;
101
+ if (text === undefined) {
102
+ out.push(segment);
103
+ continue;
104
+ }
105
+ const inner = lexShell(text);
106
+ if ("parseFailure" in inner || inner.segments.length === 0) {
107
+ out.push(segment);
108
+ continue;
109
+ }
110
+ inner.segments.forEach((s, k) => out.push(k === 0 ? { ...s, connector: segment.connector, spliced: true } : { ...s, spliced: true }));
111
+ out.push({ ...segment, connector: ";", spliced: true, sourced: true });
112
+ spliced = true;
113
+ }
114
+ segments = out;
115
+ if (!spliced)
116
+ break;
117
+ }
118
+ return segments === lexed.segments ? lexed : { segments, substitutions: segments.flatMap((s) => s.substitutions) };
119
+ }
@@ -118,8 +118,8 @@ export declare function spelledWithHome(spelled: string, raw: string, home: stri
118
118
  * redirection target or a here-document delimiter stands (`pack@(age.json)`, `<<@(x)`). After `shopt -s extglob`
119
119
  * bash expands the pattern (or reads another delimiter) where the lexer reads a split word, so what the text opens is
120
120
  * not what the plan names: the whole text asks, and a deny hit anywhere still refuses. `globs: false` = the text is an
121
- * arithmetic expression (`$((2*(3+4)))`), which bash evaluates and never globs. A compound assignment's value is no
122
- * such word — the assignment reads nothing — unless the unread value may run something ({@link compoundValueHidesRun}). */
121
+ * arithmetic expression (`$((2*(3+4)))`), which bash evaluates and never globs. An assignment word is read as the words it
122
+ * stores ({@link assignedWords}): a compound value's elements each as the scalar assignment of the same text. */
123
123
  export declare function unreadableSentenceOf(lexed: LexedCommand, text: string, globs?: boolean): string | undefined;
124
124
  /** The mark a settled value carries: `"glob"` when an unquoted pathname-expansion character survives in it. */
125
125
  export declare function globMark(glob: boolean): WordExpands;
@@ -1,4 +1,4 @@
1
- import { argvOf, compoundValueHidesRun, lexShell, literalTildeSpelling, UNRESOLVED_SENTENCE } from "../../shell/lex.js";
1
+ import { argvOf, assignedWords, lexShell, literalTildeSpelling, UNRESOLVED_SENTENCE } from "../../shell/lex.js";
2
2
  import { expansionInWord, extglobOpenerIn, globInWord, homeExpansionOf } from "./bash-readonly-classifier.js";
3
3
  import { floorOf, judgedSpellingOf, namesIn, wordFloorValues, wordValues } from "./shell-read-bindings.js";
4
4
  import { READINGS_MAX } from "./shell-read-brace.js";
@@ -151,10 +151,9 @@ export function unreadableSentenceOf(lexed, text, globs = true) {
151
151
  for (const segment of lexed.segments) {
152
152
  for (const token of segment.tokens) {
153
153
  const word = token.kind === "word" ? token : token.kind === "redirect" ? token.target : undefined;
154
- if (word?.unresolved === "compound_array_value" && word.assignment?.form === "compound" && !compoundValueHidesRun(word))
155
- continue;
156
- if (word?.unresolved !== undefined)
157
- return UNRESOLVED_SENTENCE[word.unresolved];
154
+ for (const stored of word === undefined ? [] : assignedWords(word))
155
+ if (stored.unresolved !== undefined)
156
+ return UNRESOLVED_SENTENCE[stored.unresolved];
158
157
  }
159
158
  }
160
159
  return globs && extglobOpenerIn(lexed, text) ? "an extended pattern (`?(…)` `*(…)` `+(…)` `@(…)` `!(…)`) is one this reader does not expand" : undefined;
@@ -16,6 +16,7 @@ import type { BindingTable, WorkingDirectoryState } from "./shell-read-bindings.
16
16
  import type { Read } from "./shell-read-word.js";
17
17
  import { type LexedSegment, type LexedWord } from "../../shell/lex.js";
18
18
  import { type FunctionCall } from "./shell-read-functions.js";
19
+ import { type StdinText } from "./shell-reentry-text.js";
19
20
  /** A working directory the shell could be standing in, with the latest move this candidate assumes did NOT run
20
21
  * (`skippedCd`), and what the shell holds there: `pwd` — what `PWD` spells (absent: not the base's spelling — a physical
21
22
  * move, or a start the plan does not place), `old` — what `OLDPWD` holds (absent: what the shell inherited, unknown),
@@ -176,9 +177,11 @@ export interface TextMoves {
176
177
  readonly mayMove: readonly boolean[];
177
178
  /** Segment `si` may call a function (read before the walk, to bound where bodies run). */
178
179
  readonly mayCallAt: readonly boolean[];
179
- /** Segment `si` may run a function body where it stands ({@link segmentRunsBody}): it may call one, hands a code body to run
180
- * later, runs text the plan does not read, or hands a shell a text that may (a substitution). */
180
+ /** Segment `si` may run a function body ({@link segmentRunsBody}): it may call one, hands a code body to run later, runs text
181
+ * the plan does not read, or hands a shell a text that may (a substitution). */
181
182
  readonly runsBodyAt: readonly boolean[];
183
+ /** WHERE segment `si` runs a body ({@link BodyRuns}): where it stands, and the texts it hands someone that call one there. */
184
+ readonly bodyRunsAt: readonly BodyRuns[];
182
185
  readonly bodiesAt: readonly (readonly string[])[];
183
186
  readonly physicalAt: readonly boolean[];
184
187
  readonly cdableFrom: number;
@@ -190,7 +193,20 @@ export interface TextMoves {
190
193
  /** The segment runs a body that may move the base where the walk cannot follow it: a call when a body may move or whose body is not read, a code body that may move or call one. */
191
194
  losesBaseAt(si: number, table: BindingTable): boolean;
192
195
  }
196
+ /** Where a segment runs a function body: `here` — where it stands (it calls one, hands a code body to run later, runs text the
197
+ * plan does not read, or hands someone a text the lexer cannot read) — and `texts`: each text it hands someone that calls one,
198
+ * run where THAT text's own walk stands at its call (`bash -c 'cd .. && f'` runs `f` in the parent directory). `in`:
199
+ * who runs the text — this shell (a literal `eval` text), a subshell of it at the segment's place (a substitution, an
200
+ * evaluated subscript), or a child shell (its literal text, with the functions this shell exported to it: `functions`). */
201
+ export interface BodyRuns {
202
+ readonly here: boolean;
203
+ readonly texts: readonly {
204
+ readonly text: string;
205
+ readonly in: "shell" | "subshell" | "child";
206
+ readonly functions: ReadonlySet<string>;
207
+ }[];
208
+ }
193
209
  export declare function textMovesOf(defined: ReadonlySet<string>, segments: readonly LexedSegment[], argvs: readonly (readonly LexedWord[])[], inFunctionBody: (si: number) => boolean, inherited?: {
194
210
  readonly functions: ReadonlySet<string>;
195
211
  readonly unread: ReadonlySet<string>;
196
- }): TextMoves;
212
+ }, exportedInherited?: ReadonlySet<string>, fedAt?: (si: number) => readonly StdinText[]): TextMoves;
@@ -1,10 +1,11 @@
1
- import { argvOf, expansionsInHeredocBody, lexShell } from "../../shell/lex.js";
1
+ import { argvOf, descriptorNameWords, expansionsInHeredocBody, lexShell } from "../../shell/lex.js";
2
2
  import { shellWordsOf } from "../../shell/shell-words.js";
3
3
  import { resolveOperandLexically, resolveOperandSpellings } from "./bash-readonly-classifier.js";
4
4
  import { readProgramPosition } from "./bash-program-position.js";
5
- import { valueOf } from "./shell-read-bindings.js";
5
+ import { arithmeticSubstitutions, exportedFunctionNames, isArithmeticCommand, substitutionBodies, valueOf } from "./shell-read-bindings.js";
6
+ import { programRow, readArgRoles } from "./program-read-model.js";
6
7
  import { evalDefinedFunctions, functionCallOf } from "./shell-read-functions.js";
7
- import { codeBodies } from "./shell-reentry-text.js";
8
+ import { codeBodies, literalEvalText, reentersShell, reentryText, stdinTextsOf } from "./shell-reentry-text.js";
8
9
  import { isAbsoluteForFamily } from "./safety.js";
9
10
  import { walkFromStart } from "./shell-read-start.js";
10
11
  const TEXT_RUNNING_PROGRAMS = new Set(["eval", "source", "."]);
@@ -324,40 +325,84 @@ export function segmentMayMove(argv, functions) {
324
325
  const word = argv[pos.program.index];
325
326
  return shellWordsOf("base_mover").has(pos.program.basename) || TEXT_RUNNING_PROGRAMS.has(pos.program.basename) || functionCallOf(argv, functions) !== undefined || word.pieces.some((p) => p.expansion !== undefined || p.literal === undefined);
326
327
  }
327
- function segmentRunsBody(segment, argv, functions) {
328
+ const runsAny = (r) => r.here || r.texts.length > 0;
329
+ function segmentRunsBody(segment, argv, functions, exported = functions, fed = []) {
330
+ const HERE = { here: true, texts: [] };
328
331
  const pos = readProgramPosition(argv);
329
332
  const word = pos.program === undefined ? undefined : argv[pos.program.index];
330
333
  const p = programOf(argv);
331
334
  if (functionCallOf(argv, functions) !== undefined || (p !== undefined && codeBodies(p.name, p.args).length > 0))
332
- return true;
333
- if (word !== undefined && (TEXT_RUNNING_PROGRAMS.has(pos.program.basename) || word.pieces.some((q) => q.expansion !== undefined || q.literal === undefined)))
334
- return true;
335
+ return HERE;
336
+ const evalText = pos.program?.basename === "eval" ? literalEvalText(argv.slice(pos.program.index + 1)) : undefined;
337
+ const own = evalText === undefined || "parseFailure" in lexShell(evalText) ? [] : [{ text: evalText, in: "shell", functions }];
338
+ if (word !== undefined && own.length === 0 && (TEXT_RUNNING_PROGRAMS.has(pos.program.basename) || word.pieces.some((q) => q.expansion !== undefined || q.literal === undefined)))
339
+ return HERE;
335
340
  if (functions.size === 0)
336
- return false;
341
+ return { here: false, texts: own };
337
342
  const words = segment.tokens.flatMap((t) => (t.kind === "word" ? [t] : t.kind === "redirect" && t.target !== undefined ? [t.target] : []));
343
+ const unread = { here: true, texts: own };
338
344
  if (words.some((w) => w.unresolved === "parameter_text"))
339
- return true;
345
+ return unread;
340
346
  const heredocs = segment.tokens.flatMap((t) => (t.kind === "heredoc" && !t.quoted ? [expansionsInHeredocBody(t.body)] : []));
341
347
  if (heredocs.some((b) => b === undefined || b.some((x) => x.unresolved !== undefined)))
342
- return true;
348
+ return unread;
343
349
  const texts = [...segment.substitutions, ...heredocs.flatMap((b) => (b ?? []).flatMap((x) => (x.expansion.kind === "command" ? [x.expansion.body ?? ""] : [])))];
344
- return texts.some((text) => {
350
+ let unreadable = false;
351
+ const handed = [];
352
+ const hand = (text, by, fns) => {
345
353
  const lexed = lexShell(text);
346
- return "parseFailure" in lexed || lexed.segments.some((s) => segmentRunsBody(s, argvOf(s), functions));
347
- });
354
+ if ("parseFailure" in lexed)
355
+ unreadable = true;
356
+ else if (lexed.segments.some((s) => runsAny(segmentRunsBody(s, argvOf(s), fns, exported))))
357
+ handed.push({ text, in: by, functions: fns });
358
+ };
359
+ const row = p === undefined ? undefined : programRow(p.name);
360
+ const evaluated = argv.flatMap((w) => (w.assignment?.subscript !== undefined ? [`[${w.assignment.subscript.folded}]`] : []));
361
+ if (row !== undefined && p !== undefined) {
362
+ for (const e of readArgRoles(row, p.args)) {
363
+ const role = e.kind === "value" || e.kind === "operand" ? e.role : e.kind === "option" && typeof e.reading === "object" ? e.reading.role : undefined;
364
+ const text = e.kind === "option" && typeof e.reading === "object" ? e.reading.attached : p.args[e.at];
365
+ if (role?.kind === "program-text" && role.language === "arithmetic" && e.kind !== "end-of-options" && e.kind !== "dash-word-operand") {
366
+ evaluated.push(`[${text}]`);
367
+ continue;
368
+ }
369
+ if (role?.kind !== "binds-name" || role.asWritten === true)
370
+ continue;
371
+ const at = text.indexOf("[");
372
+ if (at >= 0)
373
+ evaluated.push(text.slice(at));
374
+ }
375
+ }
376
+ if (isArithmeticCommand(segment))
377
+ evaluated.push(`[${argv.map((w) => w.raw).join(" ")}]`);
378
+ for (const t of [...evaluated.flatMap((t) => arithmeticSubstitutions(t, undefined)), ...evaluated.flatMap((t) => substitutionBodies(t))])
379
+ hand(t, "subshell", functions);
380
+ const stdin = stdinTextsOf(segment, fed);
381
+ const named = descriptorNameWords(segment);
382
+ const readings = [{ program: p, last: stdin.at(-1) }, ...(named.size > 0 ? [{ program: programOf(argv.filter((w) => !named.has(w))), last: stdin.filter((t) => t.allocated !== true).at(-1) }] : [])];
383
+ const children = new Set(readings.flatMap(({ program, last }) => (program !== undefined && !TEXT_RUNNING_PROGRAMS.has(program.name) && reentersShell(program.name, program.args) ? [reentryText(program.name, program.args, last?.literal ?? last?.printed)] : [])));
384
+ if (exported.size > 0)
385
+ for (const child of children)
386
+ if (child !== undefined)
387
+ hand(child, "child", exported);
388
+ for (const text of texts)
389
+ hand(text, "subshell", functions);
390
+ return { here: unreadable, texts: [...own, ...handed] };
348
391
  }
349
- export function textMovesOf(defined, segments, argvs, inFunctionBody, inherited) {
392
+ export function textMovesOf(defined, segments, argvs, inFunctionBody, inherited, exportedInherited = new Set(), fedAt) {
350
393
  const unread = new Set([...evalDefinedFunctions(argvs), ...(inherited?.unread ?? [])]);
351
394
  const functions = new Set([...defined, ...unread, ...(inherited?.functions ?? [])]);
352
395
  const programs = argvs.map(programOf);
396
+ const exportedAt = (si) => new Set([...exportedInherited, ...argvs.slice(0, si).flatMap(exportedFunctionNames)].filter((n) => functions.has(n)));
353
397
  const mayMove = argvs.map((argv) => segmentMayMove(argv, functions));
354
398
  const bodyMoves = mayMove.some((m, si) => m && inFunctionBody(si));
355
399
  const bodiesAt = programs.map((p) => (p === undefined ? [] : codeBodies(p.name, p.args)));
356
400
  const mayCallAt = argvs.map((argv) => functionCallOf(argv, functions) !== undefined);
357
401
  const callAt = (si, table) => functionCallOf(argvs[si], functions, (name) => table.functionState(name));
358
402
  const callsUnread = (si, table) => functionCallOf(argvs[si], unread, (name) => table.functionState(name)) !== undefined;
403
+ const bodyRunsAt = argvs.map((argv, si) => segmentRunsBody(segments[si], argv, functions, exportedAt(si), fedAt?.(si) ?? []));
359
404
  return {
360
- functions, unread, mayMove, mayCallAt, runsBodyAt: argvs.map((argv, si) => segmentRunsBody(segments[si], argv, functions)), bodiesAt, bodyMoves, callAt, callsUnread,
405
+ functions, unread, mayMove, mayCallAt, runsBodyAt: bodyRunsAt.map(runsAny), bodyRunsAt, bodiesAt, bodyMoves, callAt, callsUnread,
361
406
  physicalAt: programs.map(setsPhysical),
362
407
  cdableFrom: programs.findIndex((p) => p?.name === "shopt" && p.args.includes("-s") && p.args.includes("cdable_vars")),
363
408
  losesBaseAt: (si, table) => (callAt(si, table) !== undefined && bodyMoves) || callsUnread(si, table) || bodiesAt[si].some((b) => bodyMoves || textMayMove(b, functions)),
@@ -36,6 +36,10 @@ export declare function reentersShell(basename: string, args: readonly string[])
36
36
  * the argv names no text and the program runs its standard input ({@link scriptSourceOf}: the row runs it unnamed, or
37
37
  * the script file named is standard input), the text is `stdin` — one text that may arrive there, as the caller spells it. */
38
38
  export declare function reentryText(basename: string, args: readonly string[], stdin?: string): string | undefined;
39
+ /** The text a literal `eval` runs: its words' literal values joined ({@link reentryText}); `undefined` where a word expands or
40
+ * there is none. The walk's one reading of a literal `eval` — its move ({@link import("./shell-read-workdir.js").BaseShift}) and
41
+ * where the bodies it calls run. */
42
+ export declare function literalEvalText(words: readonly LexedWord[]): string | undefined;
39
43
  /** One argument of the argv a launcher hands the SHELL it runs: a word of the command line passed on as it stands (`at`,
40
44
  * its argv index; `from` — only the word's characters from there on, an option value attached to its option word), a word
41
45
  * of the launcher's own (`fixed`: the `-c` in front of a text it builds), or a text it builds from several words
@@ -143,6 +147,9 @@ export interface StdinText {
143
147
  readonly from: string;
144
148
  readonly literal?: string;
145
149
  readonly printed?: string;
150
+ /** Opened on a `{NAME}` descriptor ({@link import("../../shell/lex.js").LexedRedirect.allocated}): standard input to bash 3.2
151
+ * only — bash ≥ 4.1 puts it on a descriptor of its own and leaves standard input what it was. */
152
+ readonly allocated?: true;
146
153
  }
147
154
  /** The text a producer's words say it prints ({@link printedText}): one simple command — no redirection, here-document or
148
155
  * group — whose program word and every argument are literal, run by a printer row. `undefined` for any other producer. The
@@ -155,9 +162,10 @@ export declare function pipedTextOf(producer: LexedSegment): StdinText;
155
162
  /** The text a word that is one process substitution prints, where its body is one literal printer ({@link printedBy}):
156
163
  * `<(printf 'X')` — a script file a shell is handed, or the file its standard input is redirected from. */
157
164
  export declare function printedByProcess(word: LexedWord): string | undefined;
158
- /** What may arrive on a segment's standard input: each here-document (its descriptor is not read: every one counts) —
165
+ /** What may arrive on a segment's standard input: each here-document opened on descriptor 0 (one on another descriptor, `3<<EOF`, is not standard input) —
159
166
  * its body, literal when quoted or when nothing in it expands — each here-string (literal when its word is), `<` file
160
167
  * or `<&` descriptor written to no other descriptor, and what it inherits (`fed`: the pipe it is reached through, the
161
168
  * pipe or the input of the group it stands in, the input of the shell running its text) unless one of those three
162
- * replaces it. */
169
+ * replaces it. One opened on a `{NAME}` descriptor is in the list (bash 3.2 reads it on 0) and replaces nothing (bash ≥ 4.1
170
+ * does not): both readings ({@link StdinText.allocated}). */
163
171
  export declare function stdinTextsOf(segment: LexedSegment, fed: readonly StdinText[]): StdinText[];
@@ -94,6 +94,10 @@ export function reentryText(basename, args, stdin) {
94
94
  const source = scriptSourceOf(row, args);
95
95
  return (r.stdin === "script" && source.stdin) || (source.file !== undefined && namesStandardInput(args[source.file])) ? stdin : undefined;
96
96
  }
97
+ export function literalEvalText(words) {
98
+ const values = words.map((w) => literalTextOf(w.pieces));
99
+ return values.every((v) => v !== undefined) ? reentryText("eval", values) : undefined;
100
+ }
97
101
  function argvText(row, at, args) {
98
102
  if (at === "words")
99
103
  return args.length === 0 ? undefined : args.join(" ");
@@ -265,15 +269,18 @@ export function stdinTextsOf(segment, fed) {
265
269
  const out = [];
266
270
  let replacesPipe = false;
267
271
  for (const t of segment.tokens) {
268
- if (t.kind === "heredoc") {
272
+ const onAllocated = (t.kind === "heredoc" || t.kind === "redirect") && t.allocated === true;
273
+ const allocated = onAllocated ? { allocated: true } : {};
274
+ if (t.kind === "heredoc" && (t.fd ?? 0) === 0) {
269
275
  const literal = t.quoted ? t.body : literalHeredocBody(t.body);
270
- out.push(literal === undefined ? { from: t.body } : { from: t.body, literal });
276
+ out.push(literal === undefined ? { from: t.body, ...allocated } : { from: t.body, literal, ...allocated });
271
277
  }
272
278
  else if (t.kind === "redirect" && (t.fd ?? 0) === 0 && (t.op === "<<<" || t.op === "<" || t.op === "<>" || (t.op === "<&" && t.dup !== "-"))) {
273
279
  const literal = t.op === "<<<" && t.target !== undefined ? literalTextOf(t.target.pieces) : undefined;
274
280
  const printed = t.op === "<" && t.target !== undefined ? printedByProcess(t.target) : undefined;
275
- out.push({ from: `${t.op}${t.target?.raw ?? t.dup ?? ""}`, ...(literal !== undefined ? { literal } : {}), ...(printed !== undefined ? { printed } : {}) });
276
- replacesPipe = true;
281
+ out.push({ from: `${t.op}${t.target?.raw ?? t.dup ?? ""}`, ...(literal !== undefined ? { literal } : {}), ...(printed !== undefined ? { printed } : {}), ...allocated });
282
+ if (!onAllocated)
283
+ replacesPipe = true;
277
284
  }
278
285
  }
279
286
  return replacesPipe ? out : [...fed, ...out];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sema-agent/core",
3
- "version": "7.65.0",
3
+ "version": "7.66.1",
4
4
  "description": "Stateless, task-oriented AI agent core",
5
5
  "type": "module",
6
6
  "license": "BUSL-1.1",
@@ -124,7 +124,7 @@
124
124
  "dependencies": {
125
125
  "@modelcontextprotocol/client": "2.4.0",
126
126
  "@modelcontextprotocol/core": "2.4.0",
127
- "@sema-agent/primitives": "7.65.0",
127
+ "@sema-agent/primitives": "7.66.1",
128
128
  "typebox": "1.1.39",
129
129
  "undici": "7.30.0"
130
130
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "_comment": "design/87 L3 — frozen public export surface of src/index.ts (name -> kind). DO NOT edit by hand to silence a red test. A removed/changed entry = a BREAKING change: name every removed entry in the CHANGELOG's BREAKING lines (what was removed / who is hurt / what to read instead) and update this fixture in the SAME commit. Regenerate via REGEN in test/export-surface.test.ts.",
3
3
  "_tierComment": "#435 v1 — machine-readable layering of the public surface: stable = demonstrated by README.md / src/examples; internal = an `Internal`-marked name or a runner/engine deep-subtree declaration (the model seam src/engine/llm is excluded — it is the BYOM contract, not an engine internal); advanced = a supported export the front door does not walk you through. THIS IS AN INITIAL HEURISTIC, derived mechanically and expected to be refined ticket by ticket: no human reviewed these 1700+ entries one by one, and nothing here claims otherwise. Known bias: a short or English-word export name (ok, err, Result, Usage) can match ordinary prose in README.md and land `stable` on a coincidence. Every export MUST carry a tier — a new export with no row fails the gate in export-surface.test.ts.",
4
- "count": 3158,
4
+ "count": 3161,
5
5
  "exports": {
6
6
  "A2ATaskState": "type",
7
7
  "A2ATaskStateReversal": "type",
@@ -707,6 +707,7 @@
707
707
  "HOST_DECIDERS": "variable",
708
708
  "HOST_FORMS": "variable",
709
709
  "HOST_ROLES": "variable",
710
+ "HOST_UNREADABLE_SENTENCE": "variable",
710
711
  "HandbackState": "type",
711
712
  "HandsBandOptions": "interface",
712
713
  "HarvestRejection": "interface",
@@ -726,6 +727,8 @@
726
727
  "HostFloorDeclaration": "interface",
727
728
  "HostFloorPosture": "interface",
728
729
  "HostFloorReach": "type",
730
+ "HostReading": "type",
731
+ "HostUnreadableReason": "type",
729
732
  "HumanInputAttachment": "interface",
730
733
  "HumanInputDelivery": "type",
731
734
  "HumanInputEvent": "type",
@@ -1406,6 +1409,7 @@
1406
1409
  "PromptSectionEntry": "interface",
1407
1410
  "PromptSourceState": "type",
1408
1411
  "PromptSourceStateStore": "interface",
1412
+ "PromptSubmitAnswer": "type",
1409
1413
  "PromptTrait": "type",
1410
1414
  "PromptTraitBundle": "type",
1411
1415
  "PromptTraitCondition": "interface",
@@ -2574,6 +2578,7 @@
2574
2578
  "headerOwnershipCollision": "function",
2575
2579
  "hostChildEnv": "function",
2576
2580
  "hostChildEnvProblem": "function",
2581
+ "hostOfUrl": "function",
2577
2582
  "hostSeatOfRequests": "function",
2578
2583
  "htmlToText": "function",
2579
2584
  "incarnationCell": "function",
@@ -2687,7 +2692,6 @@
2687
2692
  "listAdoptionQuarantine": "function",
2688
2693
  "listOrphanSessionTrees": "function",
2689
2694
  "listPeerHeldQueues": "function",
2690
- "listSessionCaptureOptOut": "function",
2691
2695
  "listWorkflowRuns": "function",
2692
2696
  "llmPlanDistiller": "function",
2693
2697
  "loadModPackage": "function",
@@ -2707,7 +2711,6 @@
2707
2711
  "mailboxReplayDigests": "function",
2708
2712
  "mailboxStoreContract": "function",
2709
2713
  "mailboxTombstonedRecipientContract": "function",
2710
- "markSessionCaptureOptOut": "function",
2711
2714
  "markTruncated": "function",
2712
2715
  "materializeA2aTools": "function",
2713
2716
  "materializeEntriesToFiles": "function",
@@ -2896,7 +2899,6 @@
2896
2899
  "readRuleOffer2": "function",
2897
2900
  "readRuleOffers": "function",
2898
2901
  "readRuleOwner": "function",
2899
- "readSessionCaptureOptOut": "function",
2900
2902
  "readSessionListQuery": "function",
2901
2903
  "readSessionRulesShape": "function",
2902
2904
  "readShellCommand": "function",
@@ -2996,6 +2998,7 @@
2996
2998
  "resumeGateMatches": "function",
2997
2999
  "resumeStartupCauseOf": "function",
2998
3000
  "resumeWithVerification": "function",
3001
+ "retiredToolNameAccount": "function",
2999
3002
  "retryBackoffMs": "function",
3000
3003
  "riskSeverity": "function",
3001
3004
  "rosterCanPersistMemory": "function",
@@ -3867,6 +3870,7 @@
3867
3870
  "HOST_DECIDERS": "advanced",
3868
3871
  "HOST_FORMS": "advanced",
3869
3872
  "HOST_ROLES": "advanced",
3873
+ "HOST_UNREADABLE_SENTENCE": "advanced",
3870
3874
  "HandbackState": "advanced",
3871
3875
  "HandsBandOptions": "stable",
3872
3876
  "HarvestRejection": "advanced",
@@ -3886,6 +3890,8 @@
3886
3890
  "HostFloorDeclaration": "advanced",
3887
3891
  "HostFloorPosture": "advanced",
3888
3892
  "HostFloorReach": "advanced",
3893
+ "HostReading": "advanced",
3894
+ "HostUnreadableReason": "advanced",
3889
3895
  "HumanInputAttachment": "advanced",
3890
3896
  "HumanInputDelivery": "advanced",
3891
3897
  "HumanInputEvent": "advanced",
@@ -4566,6 +4572,7 @@
4566
4572
  "PromptSectionEntry": "advanced",
4567
4573
  "PromptSourceState": "advanced",
4568
4574
  "PromptSourceStateStore": "advanced",
4575
+ "PromptSubmitAnswer": "advanced",
4569
4576
  "PromptTrait": "advanced",
4570
4577
  "PromptTraitBundle": "advanced",
4571
4578
  "PromptTraitCondition": "advanced",
@@ -5734,6 +5741,7 @@
5734
5741
  "headerOwnershipCollision": "advanced",
5735
5742
  "hostChildEnv": "advanced",
5736
5743
  "hostChildEnvProblem": "advanced",
5744
+ "hostOfUrl": "advanced",
5737
5745
  "hostSeatOfRequests": "advanced",
5738
5746
  "htmlToText": "advanced",
5739
5747
  "incarnationCell": "internal",
@@ -5847,7 +5855,6 @@
5847
5855
  "listAdoptionQuarantine": "advanced",
5848
5856
  "listOrphanSessionTrees": "advanced",
5849
5857
  "listPeerHeldQueues": "advanced",
5850
- "listSessionCaptureOptOut": "advanced",
5851
5858
  "listWorkflowRuns": "advanced",
5852
5859
  "llmPlanDistiller": "advanced",
5853
5860
  "loadModPackage": "advanced",
@@ -5867,7 +5874,6 @@
5867
5874
  "mailboxReplayDigests": "advanced",
5868
5875
  "mailboxStoreContract": "advanced",
5869
5876
  "mailboxTombstonedRecipientContract": "advanced",
5870
- "markSessionCaptureOptOut": "advanced",
5871
5877
  "markTruncated": "advanced",
5872
5878
  "materializeA2aTools": "advanced",
5873
5879
  "materializeEntriesToFiles": "advanced",
@@ -6056,7 +6062,6 @@
6056
6062
  "readRuleOffer2": "advanced",
6057
6063
  "readRuleOffers": "advanced",
6058
6064
  "readRuleOwner": "advanced",
6059
- "readSessionCaptureOptOut": "advanced",
6060
6065
  "readSessionListQuery": "advanced",
6061
6066
  "readSessionRulesShape": "advanced",
6062
6067
  "readShellCommand": "advanced",
@@ -6156,6 +6161,7 @@
6156
6161
  "resumeGateMatches": "advanced",
6157
6162
  "resumeStartupCauseOf": "advanced",
6158
6163
  "resumeWithVerification": "advanced",
6164
+ "retiredToolNameAccount": "advanced",
6159
6165
  "retryBackoffMs": "advanced",
6160
6166
  "riskSeverity": "advanced",
6161
6167
  "rosterCanPersistMemory": "advanced",
@@ -0,0 +1,30 @@
1
+ {
2
+ "repo": "core",
3
+ "package": "@sema-agent/core-stores-sql",
4
+ "version": "7.66.0",
5
+ "from": "5ab3f8045ee0d9965d58344531544df295422b69",
6
+ "to": "v7.66.0",
7
+ "added": [],
8
+ "removed": [],
9
+ "changed": [],
10
+ "narrowed": [],
11
+ "closedSetMembers": [],
12
+ "closedSetsUnreadable": [],
13
+ "typeKeys": [],
14
+ "typeKeysUnreadableArms": [],
15
+ "typeKeysFlattenedCount": 3,
16
+ "signatures": [],
17
+ "versionLiterals": [],
18
+ "declarationMoves": [],
19
+ "mintMoves": [],
20
+ "criteriaObserves": [],
21
+ "consumersHint": {
22
+ "cli": [],
23
+ "server": [],
24
+ "sdk": [],
25
+ "note": "scanned cli@8be0ba57 server@c672157c sdk@562bd88 — a name listed is MENTIONED there today, which is evidence of consumption, not proof of it"
26
+ },
27
+ "breakingCount": 0,
28
+ "breakingItems": [],
29
+ "toResolvedAt": "02bd57209b405a0597ae8d62d52e0829fcc87a90"
30
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "repo": "core",
3
+ "package": "@sema-agent/core-stores-sql",
4
+ "version": "7.66.1",
5
+ "from": "221be44613c0641e31654fcf2a9768c68f49f288",
6
+ "to": "v7.66.1",
7
+ "added": [],
8
+ "removed": [],
9
+ "changed": [],
10
+ "narrowed": [],
11
+ "closedSetMembers": [],
12
+ "closedSetsUnreadable": [],
13
+ "typeKeys": [],
14
+ "typeKeysUnreadableArms": [],
15
+ "typeKeysFlattenedCount": 3,
16
+ "signatures": [],
17
+ "versionLiterals": [],
18
+ "declarationMoves": [],
19
+ "mintMoves": [],
20
+ "criteriaObserves": [],
21
+ "consumersHint": {
22
+ "cli": [],
23
+ "server": [],
24
+ "sdk": [],
25
+ "note": "scanned cli@650de0c6 server@a66aafbdd sdk@80381f2 — a name listed is MENTIONED there today, which is evidence of consumption, not proof of it"
26
+ },
27
+ "breakingCount": 0,
28
+ "breakingItems": [],
29
+ "toResolvedAt": "c5d0a1676c4d47fbb8091833735be247d862a2de"
30
+ }