@sema-agent/core 7.64.0 → 7.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +571 -0
- package/dist/agents/delegation-registry-seat.d.ts +15 -0
- package/dist/agents/delegation-registry-seat.js +13 -0
- package/dist/agents/org-delivery-gate.d.ts +8 -1
- package/dist/agents/org-delivery-gate.js +9 -3
- package/dist/agents/peer-held-queue.js +1 -1
- package/dist/agents/peer-idle.js +1 -1
- package/dist/agents/peer-session-drain.d.ts +51 -12
- package/dist/agents/peer-session-drain.js +47 -34
- package/dist/agents/read-inbox-tool.d.ts +6 -2
- package/dist/agents/read-inbox-tool.js +18 -5
- package/dist/agents/subagent.d.ts +3 -1
- package/dist/agents/subagent.js +84 -77
- package/dist/brain/reasoning.d.ts +2 -0
- package/dist/brain/reasoning.js +1 -0
- package/dist/core/allow-entry.d.ts +9 -0
- package/dist/core/allow-entry.js +7 -1
- package/dist/core/ask-origin.d.ts +23 -3
- package/dist/core/ask-origin.js +11 -1
- package/dist/core/auto-promote.d.ts +3 -2
- package/dist/core/background-agent-store.d.ts +7 -0
- package/dist/core/checkpoint-store.d.ts +2 -3
- package/dist/core/context-settings.d.ts +1 -2
- package/dist/core/context-settings.js +1 -1
- package/dist/core/engine-attestation.d.ts +2 -2
- package/dist/core/engine-notice.d.ts +13 -1
- package/dist/core/engine-notice.js +3 -1
- package/dist/core/file-history-store.d.ts +2 -2
- package/dist/core/file-history-store.js +0 -4
- package/dist/core/gate-fold.js +3 -1
- package/dist/core/governance-codes.d.ts +6 -4
- package/dist/core/governance-codes.js +5 -3
- package/dist/core/human-input-projection.d.ts +9 -0
- package/dist/core/human-input-projection.js +13 -0
- package/dist/core/input-author.d.ts +66 -6
- package/dist/core/input-author.js +21 -3
- package/dist/core/leg-identity.d.ts +18 -2
- package/dist/core/leg-identity.js +5 -7
- package/dist/core/mailbox-store.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.d.ts +30 -10
- package/dist/core/memory-engine/consolidation.js +41 -6
- package/dist/core/memory-engine/control-objects.d.ts +36 -3
- package/dist/core/memory-engine/control-objects.js +134 -12
- package/dist/core/memory-engine/control-plane-adoption.d.ts +13 -9
- package/dist/core/memory-engine/control-plane-adoption.js +58 -31
- package/dist/core/memory-engine/delegation-settlement.d.ts +75 -52
- package/dist/core/memory-engine/delegation-settlement.js +211 -228
- package/dist/core/memory-engine/dual-root.d.ts +3 -2
- package/dist/core/memory-engine/dual-root.js +5 -1
- package/dist/core/memory-engine/engine.d.ts +33 -16
- package/dist/core/memory-engine/engine.js +213 -177
- package/dist/core/memory-engine/file-backend.d.ts +21 -12
- package/dist/core/memory-engine/file-backend.js +58 -104
- package/dist/core/memory-engine/index.d.ts +2 -2
- package/dist/core/memory-engine/index.js +2 -2
- package/dist/core/memory-engine/layout.d.ts +184 -83
- package/dist/core/memory-engine/layout.js +267 -172
- package/dist/core/memory-engine/memory-age.d.ts +12 -0
- package/dist/core/memory-engine/memory-age.js +17 -0
- package/dist/core/memory-engine/memory-backend-contract.js +12 -11
- package/dist/core/memory-engine/memory-deployment.d.ts +4 -3
- package/dist/core/memory-engine/memory-deployment.js +6 -3
- package/dist/core/memory-engine/origin-clearance.d.ts +43 -15
- package/dist/core/memory-engine/origin-clearance.js +142 -58
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +7 -7
- package/dist/core/memory-engine/types.d.ts +16 -10
- package/dist/core/memory-vector.d.ts +6 -14
- package/dist/core/memory.d.ts +0 -462
- package/dist/core/memory.js +0 -333
- package/dist/core/model-receipt.d.ts +2 -1
- package/dist/core/model-receipt.js +5 -0
- package/dist/core/mods/dollar.d.ts +12 -0
- package/dist/core/mods/kernel/dispatch.d.ts +3 -1
- package/dist/core/mods/kernel/dispatch.js +5 -2
- package/dist/core/mods/kernel/events.d.ts +3 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/prompt-submit.d.ts +4 -0
- package/dist/core/mods/prompt-submit.js +24 -0
- package/dist/core/mods/stations.d.ts +23 -4
- package/dist/core/mods/stations.js +14 -7
- package/dist/core/permission-rule-consent.d.ts +49 -18
- package/dist/core/permission-rule-consent.js +59 -38
- package/dist/core/permission-rule-store.d.ts +24 -14
- package/dist/core/retention.d.ts +2 -7
- package/dist/core/retention.js +0 -1
- package/dist/core/retired-host-table-account.d.ts +19 -0
- package/dist/core/retired-host-table-account.js +28 -0
- package/dist/core/retired-tool-name-account.d.ts +60 -0
- package/dist/core/retired-tool-name-account.js +32 -0
- package/dist/core/roles.d.ts +3 -1
- package/dist/core/roles.js +5 -2
- package/dist/core/runner/classifier-ladder.d.ts +3 -1
- package/dist/core/runner/classifier-ladder.js +2 -2
- package/dist/core/runner/compact-session.js +2 -1
- package/dist/core/runner/contracts.d.ts +9 -9
- package/dist/core/runner/delegation-owner.d.ts +0 -8
- package/dist/core/runner/delegation-owner.js +1 -3
- package/dist/core/runner/gate-exit.js +9 -2
- package/dist/core/runner/memory-consolidation-driver.js +2 -2
- package/dist/core/runner/prepare-config-doors.js +1 -1
- package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
- package/dist/core/runner/prepare-delegation-surface.js +5 -3
- package/dist/core/runner/prepare-gate-stations.d.ts +8 -5
- package/dist/core/runner/prepare-gate-stations.js +13 -5
- package/dist/core/runner/prepare-inherited-gate.js +2 -0
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.js +35 -14
- package/dist/core/runner/prepare-policy-chain.js +12 -3
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-task.d.ts +9 -1
- package/dist/core/runner/prepare-task.js +6 -5
- package/dist/core/runner/prepare-wiring-manifest.js +5 -4
- package/dist/core/runner/prompt-suggestions.js +1 -1
- package/dist/core/runner/run-identity-wiring.js +2 -2
- package/dist/core/runner/run-leg.js +3 -3
- package/dist/core/runner/run-notification-lane.d.ts +3 -0
- package/dist/core/runner/run-notification-lane.js +2 -2
- package/dist/core/runner/runtask.js +6 -3
- package/dist/core/runner/steer-admission.d.ts +11 -2
- package/dist/core/runner/stream-steer-verb.d.ts +5 -2
- package/dist/core/runner/stream-steer-verb.js +67 -14
- package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -8
- package/dist/core/runner/sub-agent-deny-lists.js +22 -8
- package/dist/core/runner-deps.d.ts +4 -4
- package/dist/core/secret-env.d.ts +2 -2
- package/dist/core/secret-env.js +6 -20
- package/dist/core/session-store.d.ts +6 -6
- package/dist/core/session-store.js +3 -3
- package/dist/core/shell-run-candidates.js +3 -3
- package/dist/core/side-query.js +1 -1
- package/dist/core/skill-grant.d.ts +7 -0
- package/dist/core/skill-grant.js +14 -5
- package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
- package/dist/core/task-event.d.ts +14 -0
- package/dist/core/task-notification.d.ts +35 -8
- package/dist/core/task-notification.js +31 -13
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +4 -0
- package/dist/core/tool-errors.d.ts +3 -3
- package/dist/core/tool-policy.js +2 -3
- package/dist/core/tool-spec.d.ts +20 -10
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +11 -5
- package/dist/core/write-protect.d.ts +16 -0
- package/dist/core/write-protect.js +10 -0
- package/dist/engine/harness/agent-harness.d.ts +19 -11
- package/dist/engine/harness/agent-harness.js +7 -4
- package/dist/engine/llm/types.d.ts +22 -10
- package/dist/engine/session/repo-utils.d.ts +14 -4
- package/dist/engine/session/repo-utils.js +5 -4
- package/dist/index.d.ts +10 -8
- package/dist/index.js +9 -7
- package/dist/prompts/default.d.ts +1 -2
- package/dist/scenarios/full-body.d.ts +1 -1
- package/dist/shell/lex.d.ts +50 -15
- package/dist/shell/lex.js +43 -9
- package/dist/stores/file/adoption/adopt.d.ts +1 -1
- package/dist/stores/file/index.d.ts +1 -15
- package/dist/stores/file/index.js +1 -15
- package/dist/stores/file/permission-rule-store.d.ts +12 -1
- package/dist/stores/file/permission-rule-store.js +31 -4
- package/dist/stores/file/session-store.js +1 -1
- package/dist/tools/fs/fs-bash.js +3 -3
- package/dist/tools/fs/removal-targets.d.ts +8 -2
- package/dist/tools/fs/removal-targets.js +31 -4
- package/dist/tools/fs/shell-read-argv.js +7 -1
- package/dist/tools/fs/shell-read-bindings.d.ts +21 -5
- package/dist/tools/fs/shell-read-bindings.js +130 -44
- package/dist/tools/fs/shell-read-plan.js +95 -29
- package/dist/tools/fs/shell-read-sourced.d.ts +25 -0
- package/dist/tools/fs/shell-read-sourced.js +119 -0
- package/dist/tools/fs/shell-read-word.d.ts +2 -2
- package/dist/tools/fs/shell-read-word.js +4 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +19 -3
- package/dist/tools/fs/shell-read-workdir.js +60 -15
- package/dist/tools/fs/shell-reentry-text.d.ts +10 -2
- package/dist/tools/fs/shell-reentry-text.js +11 -4
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +21 -79
- package/wire-changes/core-stores-sql@7.65.0.json +30 -0
- package/wire-changes/core-stores-sql@7.66.0.json +30 -0
- package/wire-changes/core@7.65.0.json +1650 -0
- package/wire-changes/core@7.66.0.json +1218 -0
- package/wire-changes/mods-kernel@7.65.0.json +30 -0
- package/wire-changes/mods-kernel@7.66.0.json +65 -0
- package/wire-changes/primitives@7.65.0.json +337 -0
- package/wire-changes/primitives@7.66.0.json +30 -0
- package/dist/core/memory-recall.d.ts +0 -208
- package/dist/core/memory-recall.js +0 -136
- package/dist/stores/file/memory-store.d.ts +0 -124
- package/dist/stores/file/memory-store.js +0 -353
|
@@ -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.
|
|
122
|
-
*
|
|
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,
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
|
180
|
-
*
|
|
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
|
-
|
|
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
|
|
333
|
-
|
|
334
|
-
|
|
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
|
|
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
|
|
348
|
+
return unread;
|
|
343
349
|
const texts = [...segment.substitutions, ...heredocs.flatMap((b) => (b ?? []).flatMap((x) => (x.expansion.kind === "command" ? [x.expansion.body ?? ""] : [])))];
|
|
344
|
-
|
|
350
|
+
let unreadable = false;
|
|
351
|
+
const handed = [];
|
|
352
|
+
const hand = (text, by, fns) => {
|
|
345
353
|
const lexed = lexShell(text);
|
|
346
|
-
|
|
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:
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "7.66.0",
|
|
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.
|
|
127
|
+
"@sema-agent/primitives": "7.66.0",
|
|
128
128
|
"typebox": "1.1.39",
|
|
129
129
|
"undici": "7.30.0"
|
|
130
130
|
},
|