@deepagents/context 6.1.0 → 7.0.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 +29 -3
- package/dist/browser.js +9 -2
- package/dist/browser.js.map +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1411 -514
- package/dist/index.js.map +4 -4
- package/dist/lib/agent.d.ts +78 -37
- package/dist/lib/agent.d.ts.map +1 -1
- package/dist/lib/chat.d.ts +17 -18
- package/dist/lib/chat.d.ts.map +1 -1
- package/dist/lib/engine.d.ts.map +1 -1
- package/dist/lib/fragments/plan-shared.d.ts +46 -0
- package/dist/lib/fragments/plan-shared.d.ts.map +1 -0
- package/dist/lib/fragments/plan.d.ts.map +1 -1
- package/dist/lib/fragments/socratic-inquiry.d.ts +4 -0
- package/dist/lib/fragments/socratic-inquiry.d.ts.map +1 -0
- package/dist/lib/fragments/socratic-plan.d.ts +13 -0
- package/dist/lib/fragments/socratic-plan.d.ts.map +1 -0
- package/dist/lib/fragments/socratic.d.ts +2 -5
- package/dist/lib/fragments/socratic.d.ts.map +1 -1
- package/dist/lib/sandbox/agent-os-sandbox.d.ts +1 -1
- package/dist/lib/sandbox/agent-os-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/apple-container-sandbox.d.ts +3 -3
- package/dist/lib/sandbox/apple-container-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/bash-tool.d.ts +1 -1
- package/dist/lib/sandbox/bash-tool.d.ts.map +1 -1
- package/dist/lib/sandbox/cli-process.d.ts +6 -0
- package/dist/lib/sandbox/cli-process.d.ts.map +1 -1
- package/dist/lib/sandbox/container-engine.d.ts +1 -0
- package/dist/lib/sandbox/container-engine.d.ts.map +1 -1
- package/dist/lib/sandbox/container-sandbox.d.ts +1 -0
- package/dist/lib/sandbox/container-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/daytona-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/docker-sandbox.d.ts +10 -3
- package/dist/lib/sandbox/docker-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/index.d.ts +1 -0
- package/dist/lib/sandbox/index.d.ts.map +1 -1
- package/dist/lib/sandbox/microsandbox-sandbox.d.ts +13 -17
- package/dist/lib/sandbox/microsandbox-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/read-file-tool/binary.d.ts +13 -0
- package/dist/lib/sandbox/read-file-tool/binary.d.ts.map +1 -0
- package/dist/lib/sandbox/read-file-tool/format.d.ts +17 -0
- package/dist/lib/sandbox/read-file-tool/format.d.ts.map +1 -0
- package/dist/lib/sandbox/read-file-tool/image.d.ts +4 -0
- package/dist/lib/sandbox/read-file-tool/image.d.ts.map +1 -0
- package/dist/lib/sandbox/read-file-tool/index.d.ts +6 -0
- package/dist/lib/sandbox/read-file-tool/index.d.ts.map +1 -0
- package/dist/lib/sandbox/read-file-tool/ooxml.d.ts +4 -0
- package/dist/lib/sandbox/read-file-tool/ooxml.d.ts.map +1 -0
- package/dist/lib/sandbox/read-file-tool/pdf.d.ts +4 -0
- package/dist/lib/sandbox/read-file-tool/pdf.d.ts.map +1 -0
- package/dist/lib/sandbox/read-file-tool/text.d.ts +10 -0
- package/dist/lib/sandbox/read-file-tool/text.d.ts.map +1 -0
- package/dist/lib/sandbox/read-file.d.ts +8 -0
- package/dist/lib/sandbox/read-file.d.ts.map +1 -0
- package/dist/lib/sandbox/shell-quote.d.ts +1 -1
- package/dist/lib/sandbox/strace/index.d.ts +3 -3
- package/dist/lib/sandbox/strace/index.d.ts.map +1 -1
- package/dist/lib/sandbox/strace/index.js +2 -2
- package/dist/lib/sandbox/strace/index.js.map +2 -2
- package/dist/lib/sandbox/types.d.ts +24 -5
- package/dist/lib/sandbox/types.d.ts.map +1 -1
- package/dist/lib/sandbox/virtual-sandbox.d.ts.map +1 -1
- package/dist/lib/stream-buffer.d.ts +1 -1
- package/dist/lib/stream-buffer.d.ts.map +1 -1
- package/dist/lib/telemetry/console-telemetry.d.ts +0 -1
- package/dist/lib/telemetry/console-telemetry.d.ts.map +1 -1
- package/dist/lib/telemetry/file/file-telemetry.d.ts +5 -3
- package/dist/lib/telemetry/file/file-telemetry.d.ts.map +1 -1
- package/dist/lib/telemetry/file/index.js +16 -11
- package/dist/lib/telemetry/file/index.js.map +2 -2
- package/dist/lib/telemetry/index.js +3 -4
- package/dist/lib/telemetry/index.js.map +2 -2
- package/dist/lib/telemetry/safe-serialize.d.ts +2 -2
- package/dist/lib/telemetry/safe-serialize.d.ts.map +1 -1
- package/dist/lib/tracing/index.js +4 -4
- package/dist/lib/tracing/index.js.map +2 -2
- package/package.json +9 -8
|
@@ -84,6 +84,8 @@ export interface DockerNetwork {
|
|
|
84
84
|
export interface DockerCommonOptions extends CommonSandboxOptions {
|
|
85
85
|
volumes?: SandboxVolume[];
|
|
86
86
|
resources?: DockerResources;
|
|
87
|
+
/** Per-command timeout in milliseconds for `executeCommand` and `spawn`. */
|
|
88
|
+
commandTimeout?: number;
|
|
87
89
|
/**
|
|
88
90
|
* `--platform` (e.g. `'linux/amd64'`) — emulated when it differs from the host
|
|
89
91
|
* arch. For the Dockerfile strategy it also applies to `docker build` and is
|
|
@@ -124,7 +126,7 @@ export interface DockerCommonOptions extends CommonSandboxOptions {
|
|
|
124
126
|
entrypoint?: string;
|
|
125
127
|
}
|
|
126
128
|
export interface RuntimeSandboxOptions extends DockerCommonOptions {
|
|
127
|
-
/** Docker image to use (default: `'
|
|
129
|
+
/** Docker image to use (default: `'bash:5.3-alpine3.24'`). */
|
|
128
130
|
image?: string;
|
|
129
131
|
/**
|
|
130
132
|
* Ordered list of installers run after the container starts. Use
|
|
@@ -149,6 +151,8 @@ export interface ComposeSandboxOptions {
|
|
|
149
151
|
compose: string;
|
|
150
152
|
service: string;
|
|
151
153
|
resources?: DockerResources;
|
|
154
|
+
/** Per-command timeout in milliseconds for `executeCommand` and `spawn`. */
|
|
155
|
+
commandTimeout?: number;
|
|
152
156
|
}
|
|
153
157
|
export type DockerSandboxOptions = RuntimeSandboxOptions | DockerfileSandboxOptions | ComposeSandboxOptions;
|
|
154
158
|
export declare function isDockerfileOptions(opts: DockerSandboxOptions): opts is DockerfileSandboxOptions;
|
|
@@ -158,6 +162,7 @@ export interface ComposeStrategyArgs {
|
|
|
158
162
|
compose: string;
|
|
159
163
|
service: string;
|
|
160
164
|
resources?: DockerResources;
|
|
165
|
+
commandTimeout?: number;
|
|
161
166
|
}
|
|
162
167
|
/**
|
|
163
168
|
* Manages multi-container environments via `docker compose`. Docker-only — not
|
|
@@ -168,6 +173,7 @@ export declare class ComposeStrategy extends ContainerSandboxStrategy {
|
|
|
168
173
|
private projectName;
|
|
169
174
|
private composeFile;
|
|
170
175
|
private service;
|
|
176
|
+
private commandTimeout?;
|
|
171
177
|
constructor(args: ComposeStrategyArgs);
|
|
172
178
|
private computeProjectName;
|
|
173
179
|
protected getImage(): Promise<string>;
|
|
@@ -176,6 +182,7 @@ export declare class ComposeStrategy extends ContainerSandboxStrategy {
|
|
|
176
182
|
protected configure(): Promise<void>;
|
|
177
183
|
protected exec(command: string, options?: ExecuteCommandOptions): Promise<CommandResult>;
|
|
178
184
|
protected spawnProcess(command: string, options?: SpawnOptions): SandboxProcess;
|
|
185
|
+
private execArgs;
|
|
179
186
|
protected stopContainer(_containerId: string): Promise<void>;
|
|
180
187
|
}
|
|
181
188
|
/**
|
|
@@ -186,7 +193,7 @@ export declare class ComposeStrategy extends ContainerSandboxStrategy {
|
|
|
186
193
|
* import { createDockerSandbox, pkg, urlBinary, npm } from '@deepagents/context';
|
|
187
194
|
*
|
|
188
195
|
* const sandbox = await createDockerSandbox({
|
|
189
|
-
* image: '
|
|
196
|
+
* image: 'bash:5.3-alpine3.24',
|
|
190
197
|
* installers: [
|
|
191
198
|
* pkg(['curl', 'jq']),
|
|
192
199
|
* urlBinary({ name: 'presenterm', url: {...} }),
|
|
@@ -199,7 +206,7 @@ export declare class ComposeStrategy extends ContainerSandboxStrategy {
|
|
|
199
206
|
* ```ts
|
|
200
207
|
* const sandbox = await createDockerSandbox({
|
|
201
208
|
* dockerfile: `
|
|
202
|
-
* FROM
|
|
209
|
+
* FROM bash:5.3-alpine3.24
|
|
203
210
|
* RUN apk add --no-cache curl jq
|
|
204
211
|
* `,
|
|
205
212
|
* });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docker-sandbox.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/docker-sandbox.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"docker-sandbox.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/docker-sandbox.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EAGf,gBAAgB,EAChB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,wBAAwB,EAGzB,MAAM,wBAAwB,CAAC;AAYhC,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,aAAa,IAAI,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACvE,YAAY,EACV,iBAAiB,IAAI,gBAAgB,EACrC,kBAAkB,IAAI,iBAAiB,EACvC,aAAa,IAAI,mBAAmB,GACrC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD;;;;OAIG;IACH,UAAU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AAE,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC,GAC7C,OAAO,CAAC,CAAC,CAAC,CAOZ"}
|
|
@@ -12,6 +12,7 @@ export * from './strace/file-changes.ts';
|
|
|
12
12
|
export * from './gcs.ts';
|
|
13
13
|
export * from './installers/index.ts';
|
|
14
14
|
export * from './microsandbox-sandbox.ts';
|
|
15
|
+
export * from './read-file.ts';
|
|
15
16
|
export * from './shell-quote.ts';
|
|
16
17
|
export * from './subcommand.ts';
|
|
17
18
|
export * from './types.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC"}
|
|
@@ -3,24 +3,16 @@ import type { DisposableSandbox, SandboxReadinessOptions } from './types.ts';
|
|
|
3
3
|
export declare const MICROSANDBOX_DEFAULT_DESTINATION = "/workspace";
|
|
4
4
|
export interface MicrosandboxSandboxOptions extends SandboxReadinessOptions {
|
|
5
5
|
/**
|
|
6
|
-
* Stable sandbox name. When provided,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Stable sandbox name. When provided, the SDK connects to the running
|
|
7
|
+
* sandbox of this name, resumes it if stopped (rootfs state intact), or
|
|
8
|
+
* creates it. `dispose()` follows SDK lifecycle ownership and never removes
|
|
9
|
+
* a named sandbox. Configure the builder with `detached(true)` when the
|
|
10
|
+
* sandbox must outlive the client that creates or resumes it.
|
|
11
11
|
*
|
|
12
12
|
* When omitted, an ephemeral sandbox with a generated name is created and
|
|
13
13
|
* fully removed on `dispose()`.
|
|
14
14
|
*/
|
|
15
15
|
name?: string;
|
|
16
|
-
/** OCI image to boot (default `'alpine'`). Ignored when attaching. */
|
|
17
|
-
image?: string;
|
|
18
|
-
/** Number of virtual CPUs. */
|
|
19
|
-
cpus?: number;
|
|
20
|
-
/** Memory in MiB. */
|
|
21
|
-
memory?: number;
|
|
22
|
-
/** Environment variables baked into the sandbox at boot. */
|
|
23
|
-
env?: Record<string, string>;
|
|
24
16
|
/**
|
|
25
17
|
* Default working directory, created at boot (default `'/workspace'`).
|
|
26
18
|
* Microsandbox images default to `/`, and common images ship no
|
|
@@ -36,10 +28,14 @@ export interface MicrosandboxSandboxOptions extends SandboxReadinessOptions {
|
|
|
36
28
|
/** Per-command timeout in milliseconds for `executeCommand`. */
|
|
37
29
|
commandTimeout?: number;
|
|
38
30
|
/**
|
|
39
|
-
*
|
|
40
|
-
* (
|
|
41
|
-
*
|
|
42
|
-
*
|
|
31
|
+
* Fluent access to the SDK builder for everything the factory does not
|
|
32
|
+
* own: image (default `'bash:5.3-alpine3.24'`), cpus, memory, env,
|
|
33
|
+
* volumes, network policy, secrets, user, idle timeout, ….
|
|
34
|
+
*
|
|
35
|
+
* The factory applies its own setters after this callback — `workdir`,
|
|
36
|
+
* the persistence implied by `name`, and the required Bash shell — so
|
|
37
|
+
* `configure` cannot change what the lifecycle logic relies on. Runs on
|
|
38
|
+
* every connect; existing sandbox configuration wins when connecting.
|
|
43
39
|
*/
|
|
44
40
|
configure?: (builder: SandboxBuilder) => SandboxBuilder;
|
|
45
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"microsandbox-sandbox.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/microsandbox-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,cAAc,
|
|
1
|
+
{"version":3,"file":"microsandbox-sandbox.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/microsandbox-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,cAAc,EACf,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAEV,iBAAiB,EAIjB,uBAAuB,EAExB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,gCAAgC,eAAe,CAAC;AAU7D,MAAM,WAAW,0BAA2B,SAAQ,uBAAuB;IACzE;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,cAAc,CAAC;CACzD;AAED;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAK3C;AAED,qBAAa,6BAA8B,SAAQ,wBAAwB;gBAC7D,KAAK,CAAC,EAAE,KAAK;CAO1B;AAED,qBAAa,yBAA0B,SAAQ,wBAAwB;gBACzD,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI3C;AAED,qBAAa,wBAAyB,SAAQ,wBAAwB;gBACxD,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,iBAAiB,CAAC,CAgE5B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bytes no earlier format claimed but that are not text either: stills the
|
|
3
|
+
* model cannot view (HEIC), video, audio, or anything with a NUL byte up
|
|
4
|
+
* front. Refusing here keeps decoded garbage out of the prompt and tells the
|
|
5
|
+
* model how to turn the file into something readFile does render.
|
|
6
|
+
*/
|
|
7
|
+
export declare const binaryFileFormat: {
|
|
8
|
+
read({ bytes, path: filePath, options }: import("./format.ts").FileFormatInput): {
|
|
9
|
+
type: "error-text";
|
|
10
|
+
value: string;
|
|
11
|
+
} | undefined;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=binary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/read-file-tool/binary.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;;;;CAcP,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ToolResultOutput } from '@ai-sdk/provider-utils';
|
|
2
|
+
import type { ToolExecutionOptions } from 'ai';
|
|
3
|
+
import type { ReadFileToolInput } from '../types.ts';
|
|
4
|
+
export interface FileFormatInput extends ReadFileToolInput {
|
|
5
|
+
bytes: Uint8Array;
|
|
6
|
+
options: ToolExecutionOptions<Record<string, unknown>>;
|
|
7
|
+
}
|
|
8
|
+
export interface FileFormat {
|
|
9
|
+
read(input: FileFormatInput): ToolResultOutput | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare function formatBytes(bytes: number): string;
|
|
12
|
+
export declare function attachment(input: FileFormatInput, { label, maxBytes, mediaType, }: {
|
|
13
|
+
label: string;
|
|
14
|
+
maxBytes: number;
|
|
15
|
+
mediaType: string;
|
|
16
|
+
}): ToolResultOutput;
|
|
17
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/read-file-tool/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,IAAI,CAAC;AAG/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACxD,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,oBAAoB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACxD;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,GAAG,SAAS,CAAC;CAC5D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,UAAU,CACxB,KAAK,EAAE,eAAe,EACtB,EACE,KAAK,EACL,QAAQ,EACR,SAAS,GACV,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,GACA,gBAAgB,CAsBlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/read-file-tool/image.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,eAAe;;CAcN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/read-file-tool/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAgCnE,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,WAAW,GACZ,EAAE;IACD,OAAO,EAAE,iBAAiB,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;CACrB,GAAG,YAAY,CA6Bf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ooxml.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/read-file-tool/ooxml.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,eAAe;;CAYN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/read-file-tool/pdf.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa;;CAaJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/read-file-tool/text.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc;;;;;;;;CA6BL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReadFileContent, ReadFileEncoding, ReadFileOptions } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Shape the bytes a backend read into what `Sandbox.readFile` promised for
|
|
4
|
+
* `options.encoding`. Every backend reads bytes and ends here, so this is the
|
|
5
|
+
* one place the conditional return type is asserted.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readFileContent<Encoding extends ReadFileEncoding>(bytes: Uint8Array, options: ReadFileOptions<Encoding> | undefined): ReadFileContent<Encoding>;
|
|
8
|
+
//# sourceMappingURL=read-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/read-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,EAChB,MAAM,YAAY,CAAC;AAIpB;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAS,gBAAgB,EAC/D,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG,SAAS,GAC7C,eAAe,CAAC,QAAQ,CAAC,CAI3B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* POSIX shell single-quote escape: wrap in `'...'`, replace any embedded
|
|
3
|
-
* `'` with `'\''`. Safe for arbitrary content
|
|
3
|
+
* `'` with `'\''`. Safe for arbitrary content as one shell word.
|
|
4
4
|
*
|
|
5
5
|
* Lives in its own zero-import module so lean consumers such as the
|
|
6
6
|
* `./sandbox/strace` leaf entry can use it without dragging in the
|
|
@@ -14,9 +14,9 @@ export declare class StraceUnavailableError extends Error {
|
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Wraps `command` so its filesystem syscalls are traced to `traceFile`. Both
|
|
17
|
-
* the inner command and this wrapper are
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* the inner command and this wrapper are parsed by Bash, so the single-quoting
|
|
18
|
+
* via {@link shellQuote} composes with the backend's own `bash -lc`. strace
|
|
19
|
+
* propagates the traced command's exit code. The `mkdir -p`
|
|
20
20
|
* runs before strace (so it isn't traced) and self-heals the trace dir per
|
|
21
21
|
* command — if it ever disappears mid-session, the next command recreates it
|
|
22
22
|
* rather than strace failing to open `-o` and skipping the command entirely.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/strace/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEjE,MAAM,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/sandbox/strace/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEjE,MAAM,MAAM,uBAAuB,GACjC,gBAAgB,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;AAW5D;;;;;GAKG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAEjB,MAAM,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM;CAQjE;AAID;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,MAAM,CAKR;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,MAAM,CAUR;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CASnC;AAgID,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,MAAM,EAAE,GACjB,OAAO,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"}
|
|
@@ -29,10 +29,10 @@ var StraceUnavailableError = class extends Error {
|
|
|
29
29
|
};
|
|
30
30
|
var STRACE_FLAGS = "-f -y -qq -e trace=%file,write,pwrite64,writev";
|
|
31
31
|
function buildStraceCommand(command, traceFile, traceDir) {
|
|
32
|
-
return `mkdir -p ${shellQuote(traceDir)} 2>/dev/null; strace ${STRACE_FLAGS} -o ${shellQuote(traceFile)} --
|
|
32
|
+
return `mkdir -p ${shellQuote(traceDir)} 2>/dev/null; strace ${STRACE_FLAGS} -o ${shellQuote(traceFile)} -- bash -lc ${shellQuote(command)}`;
|
|
33
33
|
}
|
|
34
34
|
function buildTracedCommand(command, traceFile, traceDir, sentinel) {
|
|
35
|
-
return `mkdir -p ${shellQuote(traceDir)} 2>/dev/null; strace ${STRACE_FLAGS} -o ${shellQuote(traceFile)} --
|
|
35
|
+
return `mkdir -p ${shellQuote(traceDir)} 2>/dev/null; strace ${STRACE_FLAGS} -o ${shellQuote(traceFile)} -- bash -lc ${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
36
|
}
|
|
37
37
|
function splitTracedOutput(stdout, sentinel) {
|
|
38
38
|
const marker = `
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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;;;
|
|
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' | 'strace-missing' | '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 parsed by Bash, so the single-quoting\n * via {@link shellQuote} composes with the backend's own `bash -lc`. strace\n * 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)} -- bash -lc ${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)} -- bash -lc ${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 as one shell word.\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;;;ADGA,IAAM,cAAuD;AAAA,EAC3D,kBACE;AAAA,EACF,kBACE;AAAA,EACF,qBACE;AACJ;AAQO,IAAM,yBAAN,cAAqC,MAAM;AAAA,EACvC;AAAA,EACA;AAAA,EAET,YAAY,QAAiC,aAAqB;AAChE;AAAA,MACE,4CAA4C,MAAM,MAAM,YAAY,MAAM,CAAC;AAAA,IAC7E;AACA,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,cAAc;AAAA,EACrB;AACF;AAEA,IAAM,eAAe;AAWd,SAAS,mBACd,SACA,WACA,UACQ;AACR,SACE,YAAY,WAAW,QAAQ,CAAC,wBACtB,YAAY,OAAO,WAAW,SAAS,CAAC,gBAAgB,WAAW,OAAO,CAAC;AAEzF;AAYO,SAAS,mBACd,SACA,WACA,UACA,UACQ;AACR,SACE,YAAY,WAAW,QAAQ,CAAC,wBACtB,YAAY,OAAO,WAAW,SAAS,CAAC,gBAAgB,WAAW,OAAO,CAAC,oCAEhE,WAAW,QAAQ,CAAC,YAC/B,WAAW,SAAS,CAAC,uBACtB,WAAW,SAAS,CAAC;AAGlC;AAOO,SAAS,kBACd,QACA,UACmC;AACnC,QAAM,SAAS;AAAA,EAAK,QAAQ;AAAA;AAC5B,QAAM,KAAK,OAAO,QAAQ,MAAM;AAChC,MAAI,OAAO,GAAI,QAAO,EAAE,QAAQ,OAAO,GAAG;AAC1C,QAAM,SAAS,OAAO,MAAM,KAAK,OAAO,MAAM;AAC9C,SAAO;AAAA,IACL,QAAQ,OAAO,MAAM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AAE,SAAS,GAAG,QAAQ;AAAA,IAC1B;AACA,UAAM,WAAW,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO,OAAO;AACrD,UAAM,cAAc,QAAQ;AAAA,MAC1B,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,KAAK,WAAW,GAAG,QAAQ,GAAG;AAAA,IAChE;AACA,QAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,YAAY,CAAC,aAAa;AAC7D,YAAM,IAAI,uBAAuB,qBAAqB,WAAW;AAAA,IACnE;AAAA,EACF,UAAE;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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ToolResultOutput } from '@ai-sdk/provider-utils';
|
|
1
2
|
import type { Tool } from 'ai';
|
|
2
3
|
export interface CommandResult {
|
|
3
4
|
stdout: string;
|
|
@@ -18,13 +19,29 @@ export interface CommandResult {
|
|
|
18
19
|
export interface ExecuteCommandOptions {
|
|
19
20
|
signal?: AbortSignal;
|
|
20
21
|
}
|
|
22
|
+
export type ReadFileEncoding = 'utf-8' | 'binary';
|
|
23
|
+
export interface ReadFileOptions<Encoding extends ReadFileEncoding = 'utf-8'> {
|
|
24
|
+
/** `'utf-8'` (default) decodes text; `'binary'` returns the raw bytes. */
|
|
25
|
+
encoding?: Encoding;
|
|
26
|
+
}
|
|
27
|
+
export type ReadFileContent<Encoding extends ReadFileEncoding> = Encoding extends 'binary' ? Uint8Array : string;
|
|
21
28
|
export interface Sandbox {
|
|
29
|
+
/**
|
|
30
|
+
* Execute `command` with Bash semantics. Process-backed implementations must
|
|
31
|
+
* invoke `bash -lc` directly and fail clearly when Bash is unavailable.
|
|
32
|
+
*/
|
|
22
33
|
executeCommand(command: string, options?: ExecuteCommandOptions): Promise<CommandResult>;
|
|
23
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Read the file at `path` as UTF-8 text, or as raw bytes with
|
|
36
|
+
* `{ encoding: 'binary' }`. Rejects when nothing readable is at `path`.
|
|
37
|
+
*/
|
|
38
|
+
readFile<Encoding extends ReadFileEncoding = 'utf-8'>(path: string, options?: ReadFileOptions<Encoding>): Promise<ReadFileContent<Encoding>>;
|
|
24
39
|
writeFiles(files: Array<{
|
|
25
40
|
path: string;
|
|
26
41
|
content: string | Buffer;
|
|
27
42
|
}>): Promise<void>;
|
|
43
|
+
/** Whether a file or directory exists at `path`; resolves `false` (never rejects) when missing. */
|
|
44
|
+
exists(path: string): Promise<boolean>;
|
|
28
45
|
}
|
|
29
46
|
export interface SpawnOptions {
|
|
30
47
|
signal?: AbortSignal;
|
|
@@ -56,6 +73,7 @@ export interface SandboxProcess {
|
|
|
56
73
|
* aggregates output and flushes on completion.
|
|
57
74
|
*/
|
|
58
75
|
export interface DisposableSandbox extends Sandbox, AsyncDisposable {
|
|
76
|
+
/** Spawn `command` with the same Bash contract as {@link Sandbox.executeCommand}. */
|
|
59
77
|
spawn?(command: string, options?: SpawnOptions): SandboxProcess;
|
|
60
78
|
/**
|
|
61
79
|
* Release the backend's external resources. Called explicitly, or
|
|
@@ -94,9 +112,10 @@ export interface BashToolInput {
|
|
|
94
112
|
export type BashToolResult = CommandResult;
|
|
95
113
|
export interface ReadFileToolInput {
|
|
96
114
|
path: string;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
115
|
+
/** 1-based line number to start at for text files. */
|
|
116
|
+
offset?: number;
|
|
117
|
+
/** Number of text lines to return from `offset`. */
|
|
118
|
+
limit?: number;
|
|
100
119
|
}
|
|
101
120
|
export interface WriteFileToolInput {
|
|
102
121
|
path: string;
|
|
@@ -138,7 +157,7 @@ export interface CreateBashToolOptions {
|
|
|
138
157
|
experimentalTeeTransform?: boolean;
|
|
139
158
|
}
|
|
140
159
|
export type WrappedBashTool = Tool<BashToolInput, BashToolResult>;
|
|
141
|
-
export type ReadFileTool = Tool<ReadFileToolInput,
|
|
160
|
+
export type ReadFileTool = Tool<ReadFileToolInput, ToolResultOutput>;
|
|
142
161
|
export type WriteFileTool = Tool<WriteFileToolInput, WriteFileToolResult>;
|
|
143
162
|
export interface BashToolkit {
|
|
144
163
|
bash: WrappedBashTool;
|
|
@@ -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;AAE/B,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,KAAK,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,OAAO;IACtB,cAAc,CACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,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AM,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;AACrE,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,CAAC;AAE1E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE;QACL,IAAI,EAAE,eAAe,CAAC;QACtB,QAAQ,EAAE,YAAY,CAAC;QACvB,SAAS,EAAE,aAAa,CAAC;KAC1B,CAAC;IACF,OAAO,EAAE,iBAAiB,CAAC;CAC5B;AAED,8EAA8E;AAC9E,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-sandbox.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/virtual-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,WAAW,EACjB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"virtual-sandbox.d.ts","sourceRoot":"","sources":["../../../src/lib/sandbox/virtual-sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,WAAW,EACjB,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE7E,MAAM,WAAW,2BAA4B,SAAQ,uBAAuB;IAC1E,EAAE,EAAE,WAAW,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IACvC,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,iBAAiB,CAAC,CA2D5B"}
|
|
@@ -6,7 +6,7 @@ export interface PersistedWriterOptions {
|
|
|
6
6
|
streamId: string;
|
|
7
7
|
/**
|
|
8
8
|
* How chunks are persisted relative to the stream:
|
|
9
|
-
* - 'buffered' (default): batch up to `flushSize` chunks
|
|
9
|
+
* - 'buffered' (default): batch up to `flushSize` chunks; data events flush promptly
|
|
10
10
|
* - 'immediate': persist each chunk before forwarding (higher latency, no data loss)
|
|
11
11
|
*/
|
|
12
12
|
strategy?: 'buffered' | 'immediate';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-buffer.d.ts","sourceRoot":"","sources":["../../src/lib/stream-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,IAAI,CAAC;AAEhD,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAK7E,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;IACpC,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,qBAAqB,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"stream-buffer.d.ts","sourceRoot":"","sources":["../../src/lib/stream-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,IAAI,CAAC;AAEhD,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAK7E,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;IACpC,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,qBAAqB,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,eAAe,CAAC,CAmG1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console-telemetry.d.ts","sourceRoot":"","sources":["../../../src/lib/telemetry/console-telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAQpC,MAAM,WAAW,uBAAuB;IACtC,
|
|
1
|
+
{"version":3,"file":"console-telemetry.d.ts","sourceRoot":"","sources":["../../../src/lib/telemetry/console-telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAQpC,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC;CACzC;AAED,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,uBAA4B,GACpC,SAAS,CAYX"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Telemetry } from 'ai';
|
|
2
2
|
export interface FileTelemetryOptions {
|
|
3
3
|
path: string;
|
|
4
|
-
includeTimestamp?: boolean;
|
|
5
|
-
append?: boolean;
|
|
6
4
|
onWriteError?: (error: unknown) => void | PromiseLike<void>;
|
|
7
5
|
}
|
|
8
|
-
export declare function createFileTelemetry(options: FileTelemetryOptions): Telemetry
|
|
6
|
+
export declare function createFileTelemetry(options: FileTelemetryOptions): Telemetry & {
|
|
7
|
+
readonly traces: {
|
|
8
|
+
readonly path: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
9
11
|
//# sourceMappingURL=file-telemetry.d.ts.map
|