@deepagents/context 3.1.0 → 4.1.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/README.md +57 -19
- package/dist/browser.js +48 -64
- package/dist/browser.js.map +3 -3
- package/dist/index.js +2004 -1479
- package/dist/index.js.map +4 -4
- package/dist/lib/agent.d.ts.map +1 -1
- package/dist/lib/chain-summary.d.ts.map +1 -1
- package/dist/lib/engine.d.ts +3 -3
- package/dist/lib/engine.d.ts.map +1 -1
- package/dist/lib/fragments/message/user.d.ts +51 -92
- package/dist/lib/fragments/message/user.d.ts.map +1 -1
- package/dist/lib/sandbox/agent-os-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/apple-container-sandbox-errors.d.ts +44 -0
- package/dist/lib/sandbox/apple-container-sandbox-errors.d.ts.map +1 -0
- package/dist/lib/sandbox/apple-container-sandbox.d.ts +122 -0
- package/dist/lib/sandbox/apple-container-sandbox.d.ts.map +1 -0
- package/dist/lib/sandbox/bash-tool.d.ts +9 -28
- package/dist/lib/sandbox/bash-tool.d.ts.map +1 -1
- package/dist/lib/sandbox/cli-process.d.ts +24 -0
- package/dist/lib/sandbox/cli-process.d.ts.map +1 -0
- package/dist/lib/sandbox/container-engine.d.ts +149 -0
- package/dist/lib/sandbox/container-engine.d.ts.map +1 -0
- package/dist/lib/sandbox/container-sandbox-errors.d.ts +10 -0
- package/dist/lib/sandbox/container-sandbox-errors.d.ts.map +1 -0
- package/dist/lib/sandbox/container-sandbox.d.ts +90 -0
- package/dist/lib/sandbox/container-sandbox.d.ts.map +1 -0
- package/dist/lib/sandbox/daytona-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/docker-sandbox-errors.d.ts +2 -2
- package/dist/lib/sandbox/docker-sandbox-errors.d.ts.map +1 -1
- package/dist/lib/sandbox/docker-sandbox.d.ts +122 -189
- package/dist/lib/sandbox/docker-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/index.d.ts +6 -1
- package/dist/lib/sandbox/index.d.ts.map +1 -1
- package/dist/lib/sandbox/installers/bin.d.ts.map +1 -1
- package/dist/lib/sandbox/installers/index.d.ts +7 -7
- package/dist/lib/sandbox/installers/index.d.ts.map +1 -1
- package/dist/lib/sandbox/installers/installer.d.ts +0 -5
- package/dist/lib/sandbox/installers/installer.d.ts.map +1 -1
- package/dist/lib/sandbox/installers/url-binary.d.ts.map +1 -1
- package/dist/lib/sandbox/shell-quote.d.ts +10 -0
- package/dist/lib/sandbox/shell-quote.d.ts.map +1 -0
- package/dist/lib/sandbox/strace/file-change.d.ts +21 -0
- package/dist/lib/sandbox/strace/file-change.d.ts.map +1 -0
- package/dist/lib/sandbox/strace/file-changes.d.ts +66 -0
- package/dist/lib/sandbox/strace/file-changes.d.ts.map +1 -0
- package/dist/lib/sandbox/strace/index.d.ts +74 -0
- package/dist/lib/sandbox/strace/index.d.ts.map +1 -0
- package/dist/lib/sandbox/strace/index.js +296 -0
- package/dist/lib/sandbox/strace/index.js.map +7 -0
- package/dist/lib/sandbox/types.d.ts +9 -4
- package/dist/lib/sandbox/types.d.ts.map +1 -1
- package/dist/lib/sandbox/virtual-sandbox.d.ts.map +1 -1
- package/dist/lib/save/save-pipeline.d.ts +1 -13
- package/dist/lib/save/save-pipeline.d.ts.map +1 -1
- package/dist/lib/skills/skill-reminder.d.ts +2 -2
- package/dist/lib/skills/skill-reminder.d.ts.map +1 -1
- package/package.json +9 -3
- package/dist/lib/sandbox/file-changes.d.ts +0 -83
- package/dist/lib/sandbox/file-changes.d.ts.map +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { FileChange } from './file-change.ts';
|
|
2
|
+
export type { FileChange, FileChangeOp } from './file-change.ts';
|
|
3
|
+
export type StraceUnavailableReason = 'ptrace-blocked' | 'strace-missing' | 'trace-unparseable';
|
|
4
|
+
/**
|
|
5
|
+
* Thrown by {@link selfTestStrace} when per-command strace tracking cannot be
|
|
6
|
+
* used. `reason` lets callers branch (fix-image vs fix-caps vs fix-arch). This
|
|
7
|
+
* is a hard failure by design — there is no silent degrade to the snapshot
|
|
8
|
+
* observer.
|
|
9
|
+
*/
|
|
10
|
+
export declare class StraceUnavailableError extends Error {
|
|
11
|
+
readonly reason: StraceUnavailableReason;
|
|
12
|
+
readonly diagnostics: string;
|
|
13
|
+
constructor(reason: StraceUnavailableReason, diagnostics: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Wraps `command` so its filesystem syscalls are traced to `traceFile`. Both
|
|
17
|
+
* the inner command and this wrapper are re-parsed by a shell (`sh -c`), so the
|
|
18
|
+
* single-quoting via {@link shellQuote} composes with the backend's own
|
|
19
|
+
* `sh -c`. strace propagates the traced command's exit code. The `mkdir -p`
|
|
20
|
+
* runs before strace (so it isn't traced) and self-heals the trace dir per
|
|
21
|
+
* command — if it ever disappears mid-session, the next command recreates it
|
|
22
|
+
* rather than strace failing to open `-o` and skipping the command entirely.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildStraceCommand(command: string, traceFile: string, traceDir: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Like {@link buildStraceCommand}, but dumps the (base64) trace inline on stdout
|
|
27
|
+
* after `sentinel`, then exits with the traced command's code. This lets one
|
|
28
|
+
* `executeCommand` round-trip carry both the command output and its trace — no
|
|
29
|
+
* second `readFile` exec to pull the trace out of the container. Pair with
|
|
30
|
+
* {@link splitTracedOutput}. `sentinel` must be unguessable (a UUID) so the
|
|
31
|
+
* command's own stdout cannot contain it. `base64` keeps the trace stream-safe
|
|
32
|
+
* and its stderr is dropped so a missing trace (strace failed) doesn't leak into
|
|
33
|
+
* the command's stderr.
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildTracedCommand(command: string, traceFile: string, traceDir: string, sentinel: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Split {@link buildTracedCommand} output into the command's own stdout and its
|
|
38
|
+
* decoded strace trace. A missing sentinel (strace produced nothing) yields an
|
|
39
|
+
* empty trace so the caller degrades to "no changes".
|
|
40
|
+
*/
|
|
41
|
+
export declare function splitTracedOutput(stdout: string, sentinel: string): {
|
|
42
|
+
stdout: string;
|
|
43
|
+
trace: string;
|
|
44
|
+
};
|
|
45
|
+
export interface ParseStraceOptions {
|
|
46
|
+
include: string[];
|
|
47
|
+
exclude?: string[];
|
|
48
|
+
traceFile?: string;
|
|
49
|
+
traceDir?: string;
|
|
50
|
+
}
|
|
51
|
+
/** A path is tracked when it matches an `include` glob and no `exclude` glob. */
|
|
52
|
+
export declare function matchesGlobs(path: string, include: string[], exclude?: string[]): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Parse one command's strace output into a coarse `FileChange[]`. Failed
|
|
55
|
+
* syscalls are skipped; paths are filtered to `destination`; the trace file and
|
|
56
|
+
* `/proc`,`/sys`,`/dev` are excluded. Per-path final state collapses repeated
|
|
57
|
+
* writes to one `write`; a path written then deleted within the command is
|
|
58
|
+
* treated as transient and dropped.
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseStraceTrace(raw: string, options: ParseStraceOptions): FileChange[];
|
|
61
|
+
/**
|
|
62
|
+
* One-time probe at sandbox setup. Runs a known create/write/rename sequence
|
|
63
|
+
* under strace on the host and asserts the trace is clean and parseable. Throws
|
|
64
|
+
* {@link StraceUnavailableError} (hard-fail) when ptrace is blocked, strace is
|
|
65
|
+
* absent, or the trace is garbled (e.g. amd64 under Rosetta).
|
|
66
|
+
*
|
|
67
|
+
* "strace works here" is an invariant of the (image + host kernel + seccomp/caps)
|
|
68
|
+
* — constant across every tool call and chat turn in a given container — so this
|
|
69
|
+
* is the consumer's once-per-container responsibility (e.g. a daemon boot gate
|
|
70
|
+
* running as PID 1 inside the container), NOT a per-tool cost. `createBashTool` /
|
|
71
|
+
* `withStraceFileChanges` no longer call it.
|
|
72
|
+
*/
|
|
73
|
+
export declare function selfTestStrace(): Promise<void>;
|
|
74
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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O,CAKT;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,kBAAkB,GAC1B,UAAU,EAAE,CAiGd;AA6BD;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAqDpD"}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// packages/context/src/lib/sandbox/strace/index.ts
|
|
2
|
+
import spawn from "nano-spawn";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { readFile, rm } from "node:fs/promises";
|
|
5
|
+
import { posix } from "node:path";
|
|
6
|
+
|
|
7
|
+
// packages/context/src/lib/sandbox/shell-quote.ts
|
|
8
|
+
function shellQuote(s) {
|
|
9
|
+
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// packages/context/src/lib/sandbox/strace/index.ts
|
|
13
|
+
var REASON_HINT = {
|
|
14
|
+
"ptrace-blocked": "ptrace is denied by the sandbox runtime. Modern Docker permits it by default; on a hardened host, relax the runtime seccomp/ptrace policy (allow the ptrace syscall, or add the SYS_PTRACE capability).",
|
|
15
|
+
"strace-missing": "strace is not installed in the sandbox image. Bake `strace` into the image.",
|
|
16
|
+
"trace-unparseable": "strace ran but its output is unusable \u2014 the sandbox is likely running under emulation (e.g. amd64 via Rosetta). Use a native-architecture sandbox."
|
|
17
|
+
};
|
|
18
|
+
var StraceUnavailableError = class extends Error {
|
|
19
|
+
reason;
|
|
20
|
+
diagnostics;
|
|
21
|
+
constructor(reason, diagnostics) {
|
|
22
|
+
super(
|
|
23
|
+
`strace file-change tracking unavailable (${reason}): ${REASON_HINT[reason]}`
|
|
24
|
+
);
|
|
25
|
+
this.name = "StraceUnavailableError";
|
|
26
|
+
this.reason = reason;
|
|
27
|
+
this.diagnostics = diagnostics;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var STRACE_FLAGS = "-f -y -qq -e trace=%file,write,pwrite64,writev";
|
|
31
|
+
function buildStraceCommand(command, traceFile, traceDir) {
|
|
32
|
+
return `mkdir -p ${shellQuote(traceDir)} 2>/dev/null; strace ${STRACE_FLAGS} -o ${shellQuote(traceFile)} -- sh -c ${shellQuote(command)}`;
|
|
33
|
+
}
|
|
34
|
+
function buildTracedCommand(command, traceFile, traceDir, sentinel) {
|
|
35
|
+
return `mkdir -p ${shellQuote(traceDir)} 2>/dev/null; strace ${STRACE_FLAGS} -o ${shellQuote(traceFile)} -- sh -c ${shellQuote(command)}; __dat_rc=$?; printf '\\n%s\\n' ${shellQuote(sentinel)}; base64 ${shellQuote(traceFile)} 2>/dev/null; rm -f ${shellQuote(traceFile)} 2>/dev/null; exit $__dat_rc`;
|
|
36
|
+
}
|
|
37
|
+
function splitTracedOutput(stdout, sentinel) {
|
|
38
|
+
const marker = `
|
|
39
|
+
${sentinel}
|
|
40
|
+
`;
|
|
41
|
+
const at = stdout.indexOf(marker);
|
|
42
|
+
if (at === -1) return { stdout, trace: "" };
|
|
43
|
+
const base64 = stdout.slice(at + marker.length);
|
|
44
|
+
return {
|
|
45
|
+
stdout: stdout.slice(0, at),
|
|
46
|
+
trace: base64 ? Buffer.from(base64, "base64").toString("utf8") : ""
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var CREATE_OR_TRUNC_FLAGS = /O_(CREAT|TRUNC)/;
|
|
50
|
+
var RENAME_SYSCALLS = /* @__PURE__ */ new Set(["rename", "renameat", "renameat2"]);
|
|
51
|
+
var DELETE_SYSCALLS = /* @__PURE__ */ new Set(["unlink", "unlinkat", "rmdir"]);
|
|
52
|
+
var MKDIR_SYSCALLS = /* @__PURE__ */ new Set(["mkdir", "mkdirat"]);
|
|
53
|
+
var LINK_SYSCALLS = /* @__PURE__ */ new Set(["link", "linkat", "symlink", "symlinkat"]);
|
|
54
|
+
var OPEN_SYSCALLS = /* @__PURE__ */ new Set(["open", "openat", "openat2", "creat"]);
|
|
55
|
+
var WRITE_SYSCALLS = /* @__PURE__ */ new Set([
|
|
56
|
+
"write",
|
|
57
|
+
"pwrite64",
|
|
58
|
+
"pwrite",
|
|
59
|
+
"writev",
|
|
60
|
+
"pwritev2"
|
|
61
|
+
]);
|
|
62
|
+
var TRUNCATE_SYSCALLS = /* @__PURE__ */ new Set(["truncate", "ftruncate"]);
|
|
63
|
+
function stitchLines(raw) {
|
|
64
|
+
const pending = /* @__PURE__ */ new Map();
|
|
65
|
+
const out = [];
|
|
66
|
+
for (const original of raw.split("\n")) {
|
|
67
|
+
const line = original.trimEnd();
|
|
68
|
+
if (!line) continue;
|
|
69
|
+
const pid = line.match(/^\s*(\d+)\s+/)?.[1] ?? "0";
|
|
70
|
+
if (/<unfinished \.\.\.>\s*$/.test(line)) {
|
|
71
|
+
pending.set(pid, line.replace(/<unfinished \.\.\.>\s*$/, ""));
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const resumed = line.match(/<\.\.\.\s+\S+\s+resumed>(.*)$/);
|
|
75
|
+
if (resumed) {
|
|
76
|
+
const head = pending.get(pid);
|
|
77
|
+
pending.delete(pid);
|
|
78
|
+
if (head !== void 0) out.push(head + resumed[1]);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
out.push(line);
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
function parseCall(line) {
|
|
86
|
+
const m = line.match(
|
|
87
|
+
/^\s*(?:\d+\s+)?([a-z_][a-z0-9_]*)\((.*)\)\s*=\s*(.+?)\s*$/
|
|
88
|
+
);
|
|
89
|
+
if (!m) return null;
|
|
90
|
+
const [, syscall, args, rest] = m;
|
|
91
|
+
const errnoMatch = rest.match(/^(-?\d+)\s+([A-Z][A-Z0-9_]*)/);
|
|
92
|
+
if (errnoMatch) {
|
|
93
|
+
return { syscall, args, retval: errnoMatch[1], errno: errnoMatch[2] };
|
|
94
|
+
}
|
|
95
|
+
return { syscall, args, retval: rest.split(/\s+/)[0] };
|
|
96
|
+
}
|
|
97
|
+
var STRACE_ESCAPE = {
|
|
98
|
+
n: 10,
|
|
99
|
+
t: 9,
|
|
100
|
+
r: 13,
|
|
101
|
+
v: 11,
|
|
102
|
+
f: 12,
|
|
103
|
+
'"': 34,
|
|
104
|
+
"\\": 92
|
|
105
|
+
};
|
|
106
|
+
function decodeStraceString(s) {
|
|
107
|
+
const bytes = [];
|
|
108
|
+
for (let i = 0; i < s.length; ) {
|
|
109
|
+
if (s[i] === "\\" && i + 1 < s.length) {
|
|
110
|
+
const octal = s.slice(i + 1, i + 4).match(/^[0-7]{1,3}/)?.[0];
|
|
111
|
+
if (octal) {
|
|
112
|
+
bytes.push(parseInt(octal, 8) & 255);
|
|
113
|
+
i += 1 + octal.length;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const mapped = STRACE_ESCAPE[s[i + 1]];
|
|
117
|
+
bytes.push(mapped ?? s.charCodeAt(i + 1));
|
|
118
|
+
i += 2;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const code = s.charCodeAt(i);
|
|
122
|
+
if (code < 128) bytes.push(code);
|
|
123
|
+
else for (const b of Buffer.from(s[i], "utf8")) bytes.push(b);
|
|
124
|
+
i += 1;
|
|
125
|
+
}
|
|
126
|
+
return Buffer.from(bytes).toString("utf8");
|
|
127
|
+
}
|
|
128
|
+
function quotedStrings(args) {
|
|
129
|
+
const out = [];
|
|
130
|
+
const re = /"((?:[^"\\]|\\.)*)"/g;
|
|
131
|
+
let m;
|
|
132
|
+
while ((m = re.exec(args)) !== null) {
|
|
133
|
+
out.push(decodeStraceString(m[1]));
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
function dirfdPath(args) {
|
|
138
|
+
return args.match(/^\s*(?:AT_FDCWD|-?\d+)<([^>]*)>/)?.[1] ?? "/";
|
|
139
|
+
}
|
|
140
|
+
function fdPath(args) {
|
|
141
|
+
return args.match(/^\s*-?\d+<([^>]*)>/)?.[1] ?? null;
|
|
142
|
+
}
|
|
143
|
+
function openFlags(args) {
|
|
144
|
+
return args.match(/\bO_[A-Z_]+(?:\|O_[A-Z_]+)*/)?.[0] ?? "";
|
|
145
|
+
}
|
|
146
|
+
function matchesGlobs(path, include, exclude) {
|
|
147
|
+
return include.some((glob) => posix.matchesGlob(path, glob)) && !exclude?.some((glob) => posix.matchesGlob(path, glob));
|
|
148
|
+
}
|
|
149
|
+
function parseStraceTrace(raw, options) {
|
|
150
|
+
const { include, exclude, traceDir, traceFile } = options;
|
|
151
|
+
const now = Date.now();
|
|
152
|
+
const state = /* @__PURE__ */ new Map();
|
|
153
|
+
const renames = [];
|
|
154
|
+
const resolve = (dir, p) => posix.normalize(p.startsWith("/") ? p : posix.join(dir, p));
|
|
155
|
+
const write = (path) => {
|
|
156
|
+
state.set(path, "write");
|
|
157
|
+
};
|
|
158
|
+
const remove = (path) => {
|
|
159
|
+
if (state.get(path) === "write") state.delete(path);
|
|
160
|
+
else state.set(path, "delete");
|
|
161
|
+
};
|
|
162
|
+
for (const line of stitchLines(raw)) {
|
|
163
|
+
const call = parseCall(line);
|
|
164
|
+
if (!call || call.errno || call.retval === "-1") continue;
|
|
165
|
+
const { syscall, args } = call;
|
|
166
|
+
const dir = dirfdPath(args);
|
|
167
|
+
if (RENAME_SYSCALLS.has(syscall)) {
|
|
168
|
+
const strings = quotedStrings(args);
|
|
169
|
+
if (strings.length < 2) continue;
|
|
170
|
+
const from = resolve(dir, strings[0]);
|
|
171
|
+
const to = resolve(dir, strings[strings.length - 1]);
|
|
172
|
+
state.delete(from);
|
|
173
|
+
renames.push({ from, to });
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (DELETE_SYSCALLS.has(syscall)) {
|
|
177
|
+
const strings = quotedStrings(args);
|
|
178
|
+
if (strings.length) remove(resolve(dir, strings[0]));
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (MKDIR_SYSCALLS.has(syscall)) {
|
|
182
|
+
const strings = quotedStrings(args);
|
|
183
|
+
if (strings.length) write(resolve(dir, strings[0]));
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (LINK_SYSCALLS.has(syscall)) {
|
|
187
|
+
const strings = quotedStrings(args);
|
|
188
|
+
if (strings.length) write(resolve(dir, strings[strings.length - 1]));
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (OPEN_SYSCALLS.has(syscall)) {
|
|
192
|
+
if (!CREATE_OR_TRUNC_FLAGS.test(openFlags(args))) continue;
|
|
193
|
+
const strings = quotedStrings(args);
|
|
194
|
+
if (strings.length) write(resolve(dir, strings[0]));
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (WRITE_SYSCALLS.has(syscall)) {
|
|
198
|
+
const p = fdPath(args);
|
|
199
|
+
if (p && Number(call.retval) > 0) write(posix.normalize(p));
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (TRUNCATE_SYSCALLS.has(syscall)) {
|
|
203
|
+
const p = fdPath(args) ?? quotedStrings(args)[0];
|
|
204
|
+
if (p) write(resolve(dir, p));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const keep = (path) => {
|
|
208
|
+
if (traceFile && path === traceFile) return false;
|
|
209
|
+
if (traceDir && (path === traceDir || path.startsWith(`${traceDir}/`))) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
if (/^\/(proc|sys|dev)(\/|$)/.test(path)) return false;
|
|
213
|
+
return matchesGlobs(path, include, exclude);
|
|
214
|
+
};
|
|
215
|
+
const changes = [];
|
|
216
|
+
const emittedRenameTargets = /* @__PURE__ */ new Set();
|
|
217
|
+
for (const { from, to } of renames) {
|
|
218
|
+
if (!keep(to)) continue;
|
|
219
|
+
if (state.get(to) === "delete") continue;
|
|
220
|
+
changes.push({ op: "rename", path: to, from, timestamp: now });
|
|
221
|
+
emittedRenameTargets.add(to);
|
|
222
|
+
}
|
|
223
|
+
const tail = [];
|
|
224
|
+
for (const [path, op] of state) {
|
|
225
|
+
if (emittedRenameTargets.has(path)) continue;
|
|
226
|
+
if (keep(path)) tail.push({ op, path, timestamp: now });
|
|
227
|
+
}
|
|
228
|
+
tail.sort((a, b) => {
|
|
229
|
+
if (a.path < b.path) return -1;
|
|
230
|
+
if (a.path > b.path) return 1;
|
|
231
|
+
return 0;
|
|
232
|
+
});
|
|
233
|
+
changes.push(...tail);
|
|
234
|
+
return changes;
|
|
235
|
+
}
|
|
236
|
+
var PTRACE_DENIED = /strace:[^\n]*(?:PTRACE_TRACEME|ptrace|Operation not permitted|EPERM)/i;
|
|
237
|
+
var STRACE_MISSING = /strace:?\s+(?:command\s+)?not found/i;
|
|
238
|
+
async function runOnHost(command) {
|
|
239
|
+
try {
|
|
240
|
+
const { stderr } = await spawn("sh", ["-c", command]);
|
|
241
|
+
return { exitCode: 0, stderr };
|
|
242
|
+
} catch (error) {
|
|
243
|
+
const e = error;
|
|
244
|
+
return { exitCode: e.exitCode ?? 1, stderr: e.stderr };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function selfTestStrace() {
|
|
248
|
+
const probeDir = `/tmp/dat-strace-${randomUUID()}`;
|
|
249
|
+
const traceFile = `/tmp/dat-strace-${randomUUID()}.trace`;
|
|
250
|
+
const q = shellQuote;
|
|
251
|
+
const sequence = `mkdir -p ${q(probeDir)} && echo hi > ${q(`${probeDir}/a.txt`)} && mv ${q(`${probeDir}/a.txt`)} ${q(`${probeDir}/b.txt`)} && echo more > ${q(`${probeDir}/c.txt`)}`;
|
|
252
|
+
const wrapped = buildStraceCommand(sequence, traceFile, "/tmp");
|
|
253
|
+
try {
|
|
254
|
+
const result = await runOnHost(wrapped);
|
|
255
|
+
const raw = await readFile(traceFile, "utf8").catch(() => "");
|
|
256
|
+
const diagnostics = `exit=${result.exitCode}
|
|
257
|
+
stderr=${result.stderr}
|
|
258
|
+
trace[0:600]=${raw.slice(0, 600)}`;
|
|
259
|
+
if (PTRACE_DENIED.test(result.stderr)) {
|
|
260
|
+
throw new StraceUnavailableError("ptrace-blocked", diagnostics);
|
|
261
|
+
}
|
|
262
|
+
if (!raw || result.exitCode === 127 || STRACE_MISSING.test(result.stderr)) {
|
|
263
|
+
throw new StraceUnavailableError("strace-missing", diagnostics);
|
|
264
|
+
}
|
|
265
|
+
const changes = parseStraceTrace(raw, {
|
|
266
|
+
include: [probeDir, `${probeDir}/**`],
|
|
267
|
+
traceFile
|
|
268
|
+
});
|
|
269
|
+
const hasRealFdPath = raw.includes(`<${probeDir}/`);
|
|
270
|
+
const hasRename = changes.some(
|
|
271
|
+
(c) => c.op === "rename" && c.from === `${probeDir}/a.txt` && c.path === `${probeDir}/b.txt`
|
|
272
|
+
);
|
|
273
|
+
const hasWrite = changes.some((c) => c.op === "write");
|
|
274
|
+
const allUnderDir = changes.every(
|
|
275
|
+
(c) => c.path === probeDir || c.path.startsWith(`${probeDir}/`)
|
|
276
|
+
);
|
|
277
|
+
if (!hasRealFdPath || !hasRename || !hasWrite || !allUnderDir) {
|
|
278
|
+
throw new StraceUnavailableError("trace-unparseable", diagnostics);
|
|
279
|
+
}
|
|
280
|
+
} finally {
|
|
281
|
+
await Promise.allSettled([
|
|
282
|
+
rm(probeDir, { recursive: true, force: true }),
|
|
283
|
+
rm(traceFile, { force: true })
|
|
284
|
+
]);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
export {
|
|
288
|
+
StraceUnavailableError,
|
|
289
|
+
buildStraceCommand,
|
|
290
|
+
buildTracedCommand,
|
|
291
|
+
matchesGlobs,
|
|
292
|
+
parseStraceTrace,
|
|
293
|
+
selfTestStrace,
|
|
294
|
+
splitTracedOutput
|
|
295
|
+
};
|
|
296
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/lib/sandbox/strace/index.ts", "../../../../src/lib/sandbox/shell-quote.ts"],
|
|
4
|
+
"sourcesContent": ["import spawn, { type SubprocessError } from 'nano-spawn';\nimport { randomUUID } from 'node:crypto';\nimport { readFile, rm } from 'node:fs/promises';\nimport { posix } from 'node:path';\n\nimport { shellQuote } from '../shell-quote.ts';\nimport type { FileChange } from './file-change.ts';\n\nexport type { FileChange, FileChangeOp } from './file-change.ts';\n\nexport type StraceUnavailableReason =\n | 'ptrace-blocked'\n | 'strace-missing'\n | 'trace-unparseable';\n\nconst REASON_HINT: Record<StraceUnavailableReason, string> = {\n 'ptrace-blocked':\n 'ptrace is denied by the sandbox runtime. Modern Docker permits it by default; on a hardened host, relax the runtime seccomp/ptrace policy (allow the ptrace syscall, or add the SYS_PTRACE capability).',\n 'strace-missing':\n 'strace is not installed in the sandbox image. Bake `strace` into the image.',\n 'trace-unparseable':\n 'strace ran but its output is unusable \u2014 the sandbox is likely running under emulation (e.g. amd64 via Rosetta). Use a native-architecture sandbox.',\n};\n\n/**\n * Thrown by {@link selfTestStrace} when per-command strace tracking cannot be\n * used. `reason` lets callers branch (fix-image vs fix-caps vs fix-arch). This\n * is a hard failure by design \u2014 there is no silent degrade to the snapshot\n * observer.\n */\nexport class StraceUnavailableError extends Error {\n readonly reason: StraceUnavailableReason;\n readonly diagnostics: string;\n\n constructor(reason: StraceUnavailableReason, diagnostics: string) {\n super(\n `strace file-change tracking unavailable (${reason}): ${REASON_HINT[reason]}`,\n );\n this.name = 'StraceUnavailableError';\n this.reason = reason;\n this.diagnostics = diagnostics;\n }\n}\n\nconst STRACE_FLAGS = '-f -y -qq -e trace=%file,write,pwrite64,writev';\n\n/**\n * Wraps `command` so its filesystem syscalls are traced to `traceFile`. Both\n * the inner command and this wrapper are re-parsed by a shell (`sh -c`), so the\n * single-quoting via {@link shellQuote} composes with the backend's own\n * `sh -c`. strace propagates the traced command's exit code. The `mkdir -p`\n * runs before strace (so it isn't traced) and self-heals the trace dir per\n * command \u2014 if it ever disappears mid-session, the next command recreates it\n * rather than strace failing to open `-o` and skipping the command entirely.\n */\nexport function buildStraceCommand(\n command: string,\n traceFile: string,\n traceDir: string,\n): string {\n return (\n `mkdir -p ${shellQuote(traceDir)} 2>/dev/null; ` +\n `strace ${STRACE_FLAGS} -o ${shellQuote(traceFile)} -- sh -c ${shellQuote(command)}`\n );\n}\n\n/**\n * Like {@link buildStraceCommand}, but dumps the (base64) trace inline on stdout\n * after `sentinel`, then exits with the traced command's code. This lets one\n * `executeCommand` round-trip carry both the command output and its trace \u2014 no\n * second `readFile` exec to pull the trace out of the container. Pair with\n * {@link splitTracedOutput}. `sentinel` must be unguessable (a UUID) so the\n * command's own stdout cannot contain it. `base64` keeps the trace stream-safe\n * and its stderr is dropped so a missing trace (strace failed) doesn't leak into\n * the command's stderr.\n */\nexport function buildTracedCommand(\n command: string,\n traceFile: string,\n traceDir: string,\n sentinel: string,\n): string {\n return (\n `mkdir -p ${shellQuote(traceDir)} 2>/dev/null; ` +\n `strace ${STRACE_FLAGS} -o ${shellQuote(traceFile)} -- sh -c ${shellQuote(command)}; ` +\n `__dat_rc=$?; ` +\n `printf '\\\\n%s\\\\n' ${shellQuote(sentinel)}; ` +\n `base64 ${shellQuote(traceFile)} 2>/dev/null; ` +\n `rm -f ${shellQuote(traceFile)} 2>/dev/null; ` +\n `exit $__dat_rc`\n );\n}\n\n/**\n * Split {@link buildTracedCommand} output into the command's own stdout and its\n * decoded strace trace. A missing sentinel (strace produced nothing) yields an\n * empty trace so the caller degrades to \"no changes\".\n */\nexport function splitTracedOutput(\n stdout: string,\n sentinel: string,\n): { stdout: string; trace: string } {\n const marker = `\\n${sentinel}\\n`;\n const at = stdout.indexOf(marker);\n if (at === -1) return { stdout, trace: '' };\n const base64 = stdout.slice(at + marker.length);\n return {\n stdout: stdout.slice(0, at),\n trace: base64 ? Buffer.from(base64, 'base64').toString('utf8') : '',\n };\n}\n\n// An open is a definite write only when it creates or truncates. Bare\n// O_WRONLY/O_RDWR/O_APPEND opens are NOT assumed to mutate \u2014 a real write()\n// syscall confirms them \u2014 so read-only-via-O_RDWR (sqlite SELECT, an editor\n// that opens then quits) doesn't produce a phantom `write`.\nconst CREATE_OR_TRUNC_FLAGS = /O_(CREAT|TRUNC)/;\nconst RENAME_SYSCALLS = new Set(['rename', 'renameat', 'renameat2']);\nconst DELETE_SYSCALLS = new Set(['unlink', 'unlinkat', 'rmdir']);\nconst MKDIR_SYSCALLS = new Set(['mkdir', 'mkdirat']);\nconst LINK_SYSCALLS = new Set(['link', 'linkat', 'symlink', 'symlinkat']);\nconst OPEN_SYSCALLS = new Set(['open', 'openat', 'openat2', 'creat']);\nconst WRITE_SYSCALLS = new Set([\n 'write',\n 'pwrite64',\n 'pwrite',\n 'writev',\n 'pwritev2',\n]);\nconst TRUNCATE_SYSCALLS = new Set(['truncate', 'ftruncate']);\n\ninterface ParsedCall {\n syscall: string;\n args: string;\n retval: string;\n errno?: string;\n}\n\n/** Reassemble `<unfinished \u2026>` / `<\u2026 resumed>` syscall splits per PID. */\nfunction stitchLines(raw: string): string[] {\n const pending = new Map<string, string>();\n const out: string[] = [];\n for (const original of raw.split('\\n')) {\n const line = original.trimEnd();\n if (!line) continue;\n const pid = line.match(/^\\s*(\\d+)\\s+/)?.[1] ?? '0';\n if (/<unfinished \\.\\.\\.>\\s*$/.test(line)) {\n pending.set(pid, line.replace(/<unfinished \\.\\.\\.>\\s*$/, ''));\n continue;\n }\n const resumed = line.match(/<\\.\\.\\.\\s+\\S+\\s+resumed>(.*)$/);\n if (resumed) {\n const head = pending.get(pid);\n pending.delete(pid);\n if (head !== undefined) out.push(head + resumed[1]);\n continue;\n }\n out.push(line);\n }\n return out;\n}\n\nfunction parseCall(line: string): ParsedCall | null {\n const m = line.match(\n /^\\s*(?:\\d+\\s+)?([a-z_][a-z0-9_]*)\\((.*)\\)\\s*=\\s*(.+?)\\s*$/,\n );\n if (!m) return null;\n const [, syscall, args, rest] = m;\n const errnoMatch = rest.match(/^(-?\\d+)\\s+([A-Z][A-Z0-9_]*)/);\n if (errnoMatch) {\n return { syscall, args, retval: errnoMatch[1], errno: errnoMatch[2] };\n }\n return { syscall, args, retval: rest.split(/\\s+/)[0] };\n}\n\nconst STRACE_ESCAPE: Record<string, number> = {\n n: 0x0a,\n t: 0x09,\n r: 0x0d,\n v: 0x0b,\n f: 0x0c,\n '\"': 0x22,\n '\\\\': 0x5c,\n};\n\n/**\n * Decode one strace-rendered string. strace emits printable ASCII verbatim and\n * non-printable / non-ASCII bytes as octal `\\NNN`, plus a few `\\x` escapes. We\n * reconstruct the raw byte sequence and decode it as UTF-8 so multi-byte\n * filenames (e.g. `caf\u00E9.txt` \u2192 `\\303\\251`) round-trip instead of being mangled.\n */\nfunction decodeStraceString(s: string): string {\n const bytes: number[] = [];\n for (let i = 0; i < s.length; ) {\n if (s[i] === '\\\\' && i + 1 < s.length) {\n const octal = s.slice(i + 1, i + 4).match(/^[0-7]{1,3}/)?.[0];\n if (octal) {\n bytes.push(parseInt(octal, 8) & 0xff);\n i += 1 + octal.length;\n continue;\n }\n const mapped = STRACE_ESCAPE[s[i + 1]];\n bytes.push(mapped ?? s.charCodeAt(i + 1));\n i += 2;\n continue;\n }\n const code = s.charCodeAt(i);\n if (code < 0x80) bytes.push(code);\n else for (const b of Buffer.from(s[i], 'utf8')) bytes.push(b);\n i += 1;\n }\n return Buffer.from(bytes).toString('utf8');\n}\n\nfunction quotedStrings(args: string): string[] {\n const out: string[] = [];\n const re = /\"((?:[^\"\\\\]|\\\\.)*)\"/g;\n let m: RegExpExecArray | null;\n while ((m = re.exec(args)) !== null) {\n out.push(decodeStraceString(m[1]));\n }\n return out;\n}\n\n/** Directory path annotated on the leading dirfd (`AT_FDCWD</cwd>` / `7</dir>`). */\nfunction dirfdPath(args: string): string {\n return args.match(/^\\s*(?:AT_FDCWD|-?\\d+)<([^>]*)>/)?.[1] ?? '/';\n}\n\n/** Path annotated on the leading fd argument (`-y` output), for write syscalls. */\nfunction fdPath(args: string): string | null {\n return args.match(/^\\s*-?\\d+<([^>]*)>/)?.[1] ?? null;\n}\n\nfunction openFlags(args: string): string {\n return args.match(/\\bO_[A-Z_]+(?:\\|O_[A-Z_]+)*/)?.[0] ?? '';\n}\n\nexport interface ParseStraceOptions {\n include: string[];\n exclude?: string[];\n traceFile?: string;\n traceDir?: string;\n}\n\n/** A path is tracked when it matches an `include` glob and no `exclude` glob. */\nexport function matchesGlobs(\n path: string,\n include: string[],\n exclude?: string[],\n): boolean {\n return (\n include.some((glob) => posix.matchesGlob(path, glob)) &&\n !exclude?.some((glob) => posix.matchesGlob(path, glob))\n );\n}\n\n/**\n * Parse one command's strace output into a coarse `FileChange[]`. Failed\n * syscalls are skipped; paths are filtered to `destination`; the trace file and\n * `/proc`,`/sys`,`/dev` are excluded. Per-path final state collapses repeated\n * writes to one `write`; a path written then deleted within the command is\n * treated as transient and dropped.\n */\nexport function parseStraceTrace(\n raw: string,\n options: ParseStraceOptions,\n): FileChange[] {\n const { include, exclude, traceDir, traceFile } = options;\n const now = Date.now();\n\n const state = new Map<string, 'write' | 'delete'>();\n const renames: Array<{ from: string; to: string }> = [];\n\n const resolve = (dir: string, p: string): string =>\n posix.normalize(p.startsWith('/') ? p : posix.join(dir, p));\n\n const write = (path: string) => {\n state.set(path, 'write');\n };\n const remove = (path: string) => {\n if (state.get(path) === 'write') state.delete(path);\n else state.set(path, 'delete');\n };\n\n for (const line of stitchLines(raw)) {\n const call = parseCall(line);\n if (!call || call.errno || call.retval === '-1') continue;\n const { syscall, args } = call;\n const dir = dirfdPath(args);\n\n if (RENAME_SYSCALLS.has(syscall)) {\n const strings = quotedStrings(args);\n if (strings.length < 2) continue;\n const from = resolve(dir, strings[0]);\n const to = resolve(dir, strings[strings.length - 1]);\n state.delete(from);\n renames.push({ from, to });\n continue;\n }\n if (DELETE_SYSCALLS.has(syscall)) {\n const strings = quotedStrings(args);\n if (strings.length) remove(resolve(dir, strings[0]));\n continue;\n }\n if (MKDIR_SYSCALLS.has(syscall)) {\n const strings = quotedStrings(args);\n if (strings.length) write(resolve(dir, strings[0]));\n continue;\n }\n if (LINK_SYSCALLS.has(syscall)) {\n const strings = quotedStrings(args);\n if (strings.length) write(resolve(dir, strings[strings.length - 1]));\n continue;\n }\n if (OPEN_SYSCALLS.has(syscall)) {\n if (!CREATE_OR_TRUNC_FLAGS.test(openFlags(args))) continue;\n const strings = quotedStrings(args);\n if (strings.length) write(resolve(dir, strings[0]));\n continue;\n }\n if (WRITE_SYSCALLS.has(syscall)) {\n const p = fdPath(args);\n if (p && Number(call.retval) > 0) write(posix.normalize(p));\n continue;\n }\n if (TRUNCATE_SYSCALLS.has(syscall)) {\n const p = fdPath(args) ?? quotedStrings(args)[0];\n if (p) write(resolve(dir, p));\n }\n }\n\n const keep = (path: string): boolean => {\n if (traceFile && path === traceFile) return false;\n if (traceDir && (path === traceDir || path.startsWith(`${traceDir}/`))) {\n return false;\n }\n if (/^\\/(proc|sys|dev)(\\/|$)/.test(path)) return false;\n return matchesGlobs(path, include, exclude);\n };\n\n const changes: FileChange[] = [];\n const emittedRenameTargets = new Set<string>();\n for (const { from, to } of renames) {\n if (!keep(to)) continue;\n // A later delete of the target supersedes the rename (the tail emits the\n // delete); otherwise the rename entry already represents the target's final\n // state, so the tail must NOT also emit a `write` for it (would duplicate).\n if (state.get(to) === 'delete') continue;\n changes.push({ op: 'rename', path: to, from, timestamp: now });\n emittedRenameTargets.add(to);\n }\n const tail: FileChange[] = [];\n for (const [path, op] of state) {\n if (emittedRenameTargets.has(path)) continue;\n if (keep(path)) tail.push({ op, path, timestamp: now });\n }\n tail.sort((a, b) => {\n if (a.path < b.path) return -1;\n if (a.path > b.path) return 1;\n return 0;\n });\n changes.push(...tail);\n return changes;\n}\n\n// strace prints its own failures to stderr prefixed `strace: `. Anchor on that\n// so a benign command whose output merely contains \"Operation not permitted\" or\n// \"not found\" is not misclassified as a tracer failure.\nconst PTRACE_DENIED =\n /strace:[^\\n]*(?:PTRACE_TRACEME|ptrace|Operation not permitted|EPERM)/i;\nconst STRACE_MISSING = /strace:?\\s+(?:command\\s+)?not found/i;\n\n/**\n * Run `command` on the host via `sh -c`, flattening nano-spawn's\n * throw-on-nonzero contract into `{ exitCode, stderr }`. The probe must read\n * both even on failure \u2014 a missing strace exits 127, a blocked ptrace exits\n * non-zero with its diagnosis on stderr \u2014 which nano-spawn surfaces by rejecting\n * with a {@link SubprocessError} (its `exitCode` is undefined only when the\n * process never started or a signal killed it, hence the `?? 1`).\n */\nasync function runOnHost(\n command: string,\n): Promise<{ exitCode: number; stderr: string }> {\n try {\n const { stderr } = await spawn('sh', ['-c', command]);\n return { exitCode: 0, stderr };\n } catch (error) {\n const e = error as SubprocessError;\n return { exitCode: e.exitCode ?? 1, stderr: e.stderr };\n }\n}\n\n/**\n * One-time probe at sandbox setup. Runs a known create/write/rename sequence\n * under strace on the host and asserts the trace is clean and parseable. Throws\n * {@link StraceUnavailableError} (hard-fail) when ptrace is blocked, strace is\n * absent, or the trace is garbled (e.g. amd64 under Rosetta).\n *\n * \"strace works here\" is an invariant of the (image + host kernel + seccomp/caps)\n * \u2014 constant across every tool call and chat turn in a given container \u2014 so this\n * is the consumer's once-per-container responsibility (e.g. a daemon boot gate\n * running as PID 1 inside the container), NOT a per-tool cost. `createBashTool` /\n * `withStraceFileChanges` no longer call it.\n */\nexport async function selfTestStrace(): Promise<void> {\n const probeDir = `/tmp/dat-strace-${randomUUID()}`;\n const traceFile = `/tmp/dat-strace-${randomUUID()}.trace`;\n const q = shellQuote;\n const sequence =\n `mkdir -p ${q(probeDir)} && ` +\n `echo hi > ${q(`${probeDir}/a.txt`)} && ` +\n `mv ${q(`${probeDir}/a.txt`)} ${q(`${probeDir}/b.txt`)} && ` +\n `echo more > ${q(`${probeDir}/c.txt`)}`;\n const wrapped = buildStraceCommand(sequence, traceFile, '/tmp');\n\n try {\n const result = await runOnHost(wrapped);\n const raw = await readFile(traceFile, 'utf8').catch(() => '');\n\n const diagnostics = `exit=${result.exitCode}\\nstderr=${result.stderr}\\ntrace[0:600]=${raw.slice(0, 600)}`;\n\n // Order matters: a ptrace block makes strace error on stderr AND emit no\n // trace, so check the ptrace signal (stderr only) before the empty-trace\n // strace-missing check, or a blocked ptrace would be mislabelled.\n if (PTRACE_DENIED.test(result.stderr)) {\n throw new StraceUnavailableError('ptrace-blocked', diagnostics);\n }\n if (!raw || result.exitCode === 127 || STRACE_MISSING.test(result.stderr)) {\n throw new StraceUnavailableError('strace-missing', diagnostics);\n }\n\n // Scope to the probe dir; the exact-path `traceFile` exclusion drops the\n // sibling trace file that lives under /tmp alongside it.\n const changes = parseStraceTrace(raw, {\n include: [probeDir, `${probeDir}/**`],\n traceFile,\n });\n const hasRealFdPath = raw.includes(`<${probeDir}/`);\n const hasRename = changes.some(\n (c) =>\n c.op === 'rename' &&\n c.from === `${probeDir}/a.txt` &&\n c.path === `${probeDir}/b.txt`,\n );\n const hasWrite = changes.some((c) => c.op === 'write');\n const allUnderDir = changes.every(\n (c) => c.path === probeDir || c.path.startsWith(`${probeDir}/`),\n );\n if (!hasRealFdPath || !hasRename || !hasWrite || !allUnderDir) {\n throw new StraceUnavailableError('trace-unparseable', diagnostics);\n }\n } finally {\n await Promise.allSettled([\n rm(probeDir, { recursive: true, force: true }),\n rm(traceFile, { force: true }),\n ]);\n }\n}\n", "/**\n * POSIX shell single-quote escape: wrap in `'...'`, replace any embedded\n * `'` with `'\\''`. Safe for arbitrary content inside `sh -c`.\n *\n * Lives in its own zero-import module so lean consumers such as the\n * `./sandbox/strace` leaf entry can use it without dragging in the\n * installer/runtime surface.\n */\nexport function shellQuote(s: string): string {\n return `'${s.replace(/'/g, `'\\\\''`)}'`;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,WAAqC;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,UAAU,UAAU;AAC7B,SAAS,aAAa;;;ACKf,SAAS,WAAW,GAAmB;AAC5C,SAAO,IAAI,EAAE,QAAQ,MAAM,OAAO,CAAC;AACrC;;;ADKA,IAAM,cAAuD;AAAA,EAC3D,kBACE;AAAA,EAC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AE;AACA,UAAM,QAAQ,WAAW;AAAA,MACvB,GAAG,UAAU,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,MAC7C,GAAG,WAAW,EAAE,OAAO,KAAK,CAAC;AAAA,IAC/B,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -35,13 +35,18 @@ export interface SandboxProcess {
|
|
|
35
35
|
* no-op `dispose()`.
|
|
36
36
|
*
|
|
37
37
|
* `spawn` is optional: only backends that can honestly expose unbuffered
|
|
38
|
-
* stdio (e.g.
|
|
39
|
-
* `if (!sandbox.spawn) ...` — no silent fallback that
|
|
40
|
-
* and flushes on completion.
|
|
38
|
+
* stdio (e.g. Docker or Apple Container sandboxes) implement it. Callers
|
|
39
|
+
* feature-detect with `if (!sandbox.spawn) ...` — no silent fallback that
|
|
40
|
+
* aggregates output and flushes on completion.
|
|
41
41
|
*/
|
|
42
|
-
export interface DisposableSandbox extends Omit<UpstreamSandbox, 'executeCommand'
|
|
42
|
+
export interface DisposableSandbox extends Omit<UpstreamSandbox, 'executeCommand'>, AsyncDisposable {
|
|
43
43
|
executeCommand(command: string, options?: ExecuteCommandOptions): Promise<CommandResult>;
|
|
44
44
|
spawn?(command: string, options?: SpawnOptions): SandboxProcess;
|
|
45
|
+
/**
|
|
46
|
+
* Release the backend's external resources. Called explicitly, or
|
|
47
|
+
* automatically at scope exit via `await using` — every backend also
|
|
48
|
+
* implements `[Symbol.asyncDispose]`, which delegates here.
|
|
49
|
+
*/
|
|
45
50
|
dispose(): Promise<void>;
|
|
46
51
|
}
|
|
47
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,OAAO,IAAI,eAAe,EAC3B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AAM,GAAG,OAAO,GAAG,SAAS,CAC7B;IACC,+DAA+D;IAC/D,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG;QAAE,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC;IACtE,OAAO,EAAE,iBAAiB,CAAC;CAC5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-sandbox.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/virtual-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAEvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,WAAW,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"virtual-sandbox.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/virtual-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAEvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,WAAW,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,iBAAiB,CAAC,CA0C5B"}
|
|
@@ -1,34 +1,22 @@
|
|
|
1
|
-
import type { ChainSummary } from '../chain-summary.ts';
|
|
2
1
|
import type { ContextFragment } from '../fragments.ts';
|
|
3
|
-
import { type BaseWhenCtx } from '../fragments/message/user.ts';
|
|
4
2
|
import type { ContextStore } from '../store/store.ts';
|
|
5
3
|
export interface SavePipelineEngine {
|
|
6
4
|
readonly store: ContextStore;
|
|
7
5
|
readonly chatId: string;
|
|
8
|
-
readonly branchName: string;
|
|
9
6
|
getActiveBranch(): {
|
|
10
7
|
id: string;
|
|
11
8
|
headMessageId: string | null;
|
|
12
9
|
};
|
|
13
10
|
commitHead(headMessageId: string): Promise<void>;
|
|
14
11
|
rewindForUpdate(parentId: string): Promise<void>;
|
|
15
|
-
getChainSummary(): Promise<ChainSummary>;
|
|
16
|
-
buildBaseWhenCtx(chain: ChainSummary): BaseWhenCtx;
|
|
17
12
|
}
|
|
18
13
|
export interface SaveResult {
|
|
19
14
|
headMessageId: string | undefined;
|
|
20
15
|
}
|
|
21
16
|
export declare class SavePipeline {
|
|
22
17
|
#private;
|
|
23
|
-
constructor(engine: SavePipelineEngine, pending: ContextFragment[]
|
|
18
|
+
constructor(engine: SavePipelineEngine, pending: ContextFragment[]);
|
|
24
19
|
applyUpdateBranching(shouldBranch: boolean): Promise<this>;
|
|
25
|
-
/**
|
|
26
|
-
* Fold any fired `target: 'user'` conditional reminders into the last pending
|
|
27
|
-
* user message. `steer` reminders fire mid-loop via the engine's prepareStep
|
|
28
|
-
* hook and `tool-output` reminders wrap at tool-execution time, so neither is
|
|
29
|
-
* handled here — the save pipeline only carries user-message reminders.
|
|
30
|
-
*/
|
|
31
|
-
evaluateUserReminders(): Promise<this>;
|
|
32
20
|
persist(): Promise<SaveResult>;
|
|
33
21
|
}
|
|
34
22
|
//# sourceMappingURL=save-pipeline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-pipeline.d.ts","sourceRoot":"","sources":["../../../src/lib/save/save-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"save-pipeline.d.ts","sourceRoot":"","sources":["../../../src/lib/save/save-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,mBAAmB,CAAC;AAEnE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,eAAe,IAAI;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAChE,UAAU,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,qBAAa,YAAY;;gBAKX,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,eAAe,EAAE;IAK5D,oBAAoB,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB1D,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;CA6CrC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ContextFragment } from '../fragments.ts';
|
|
2
2
|
import { type ClassifierOptions, type IClassifier } from '../fragments/reminders/classifier.ts';
|
|
3
3
|
import type { SkillMetadata } from './types.ts';
|
|
4
|
-
export declare function skillsReminder(skillsOrClassifier: SkillMetadata[] | IClassifier<SkillMetadata>, options?: ClassifierOptions):
|
|
4
|
+
export declare function skillsReminder(skillsOrClassifier: SkillMetadata[] | IClassifier<SkillMetadata>, options?: ClassifierOptions): ContextFragment;
|
|
5
5
|
//# sourceMappingURL=skill-reminder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skill-reminder.d.ts","sourceRoot":"","sources":["../../../src/lib/skills/skill-reminder.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"skill-reminder.d.ts","sourceRoot":"","sources":["../../../src/lib/skills/skill-reminder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,WAAW,EACjB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAYhD,wBAAgB,cAAc,CAC5B,kBAAkB,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC,aAAa,CAAC,EAChE,OAAO,CAAC,EAAE,iBAAiB,GAC1B,eAAe,CAajB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepagents/context",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,6 +31,11 @@
|
|
|
31
31
|
"types": "./dist/lib/tracing/index.d.ts",
|
|
32
32
|
"import": "./dist/lib/tracing/index.js",
|
|
33
33
|
"default": "./dist/lib/tracing/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./sandbox/strace": {
|
|
36
|
+
"types": "./dist/lib/sandbox/strace/index.d.ts",
|
|
37
|
+
"import": "./dist/lib/sandbox/strace/index.js",
|
|
38
|
+
"default": "./dist/lib/sandbox/strace/index.js"
|
|
34
39
|
}
|
|
35
40
|
},
|
|
36
41
|
"files": [
|
|
@@ -44,7 +49,7 @@
|
|
|
44
49
|
"dependencies": {
|
|
45
50
|
"@ai-sdk/groq": "^3.0.36",
|
|
46
51
|
"@ai-sdk/provider": "^3.0.10",
|
|
47
|
-
"@deepagents/agent": "
|
|
52
|
+
"@deepagents/agent": "4.1.0",
|
|
48
53
|
"ai": "^6.0.174",
|
|
49
54
|
"bash-tool": "^1.3.16",
|
|
50
55
|
"chalk": "^5.6.0",
|
|
@@ -56,7 +61,8 @@
|
|
|
56
61
|
"stringcase": "^4.3.1",
|
|
57
62
|
"tiny-tfidf": "^1.0.0",
|
|
58
63
|
"yaml": "^2.8.0",
|
|
59
|
-
"zod": "^3.25.76 || ^4.0.0"
|
|
64
|
+
"zod": "^3.25.76 || ^4.0.0",
|
|
65
|
+
"@ai-sdk/openai": "^3.0.54"
|
|
60
66
|
},
|
|
61
67
|
"devDependencies": {
|
|
62
68
|
"@daytona/sdk": "^0.175.0",
|