@zenera/neo 1.1.54 → 1.1.56
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/kernel.d.ts +11 -1
- package/dist/kernel.js +24 -1
- package/dist/memory/files.d.ts +37 -3
- package/dist/memory/files.js +26 -14
- package/dist/memory/graph.d.ts +22 -0
- package/dist/memory/graph.js +72 -7
- package/dist/memory/grep.js +3 -2
- package/dist/memory/index.d.ts +17 -4
- package/dist/memory/index.js +112 -31
- package/dist/memory/merge.js +29 -17
- package/dist/memory/migrate.d.ts +14 -0
- package/dist/memory/migrate.js +112 -0
- package/dist/memory/render.js +2 -1
- package/dist/memory/store.d.ts +36 -27
- package/dist/memory/store.js +409 -126
- package/dist/memory/tools.js +70 -9
- package/dist/memory/types.d.ts +1 -1
- package/dist/memory/types.js +1 -1
- package/dist/project/config.d.ts +1 -24
- package/dist/project/config.js +9 -4
- package/dist/project/load.d.ts +6 -8
- package/dist/project/load.js +3 -4
- package/dist/runner.d.ts +23 -6
- package/dist/runner.js +72 -8
- package/dist/services.d.ts +8 -6
- package/dist/services.js +7 -6
- package/dist/state.d.ts +8 -2
- package/dist/tools/files.d.ts +28 -37
- package/dist/tools/files.js +106 -84
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/sandbox.d.ts +2 -269
- package/dist/tools/sandbox.js +10 -741
- package/dist/types.d.ts +42 -0
- package/dist/types.js +22 -0
- package/package.json +2 -1
- package/dist/tools/workspace.d.ts +0 -79
- package/dist/tools/workspace.js +0 -1470
package/dist/tools/sandbox.d.ts
CHANGED
|
@@ -1,273 +1,6 @@
|
|
|
1
1
|
import { type AnyTool } from '../types.ts';
|
|
2
|
-
|
|
3
|
-
export declare const SANDBOX_MOUNT = "/workspace";
|
|
4
|
-
/** The image a project gets when it does not name one. */
|
|
5
|
-
export declare const DEFAULT_SANDBOX_IMAGE = "docker.io/library/python:3.14-slim-bookworm";
|
|
2
|
+
import { type Sandbox } from '@zenera/sandbox';
|
|
6
3
|
/** The family name config selects the whole set by: `tools: [sandbox:*]`. */
|
|
7
4
|
export declare const SANDBOX_GROUP = "sandbox";
|
|
8
|
-
|
|
9
|
-
* Everything about a container that an author can state, and that two agents
|
|
10
|
-
* can therefore disagree about. Two specs that are equal share a container;
|
|
11
|
-
* two that differ get one each, because the identity of a container here *is*
|
|
12
|
-
* its configuration.
|
|
13
|
-
*/
|
|
14
|
-
export interface SandboxSpec {
|
|
15
|
-
/** the base image commands run in */
|
|
16
|
-
image?: string;
|
|
17
|
-
/** fractional cores, as podman's `--cpus` */
|
|
18
|
-
cpus?: number;
|
|
19
|
-
/** MiB, as podman's `--memory` */
|
|
20
|
-
memory?: number;
|
|
21
|
-
network?: SandboxNetwork;
|
|
22
|
-
/** where the workspace is mounted, and the default cwd */
|
|
23
|
-
workdir?: string;
|
|
24
|
-
/** default seconds a single command may take */
|
|
25
|
-
timeout?: number;
|
|
26
|
-
/** how much of the host the container is allowed to be; `standard` by default */
|
|
27
|
-
hardening?: SandboxHardening;
|
|
28
|
-
/** uid, name, or `uid:gid`; unset means the image's own user */
|
|
29
|
-
user?: string;
|
|
30
|
-
/** keep the container between sessions rather than removing it */
|
|
31
|
-
persist?: boolean;
|
|
32
|
-
/** environment inside the container — resolved values, never a passthrough */
|
|
33
|
-
env?: Record<string, string>;
|
|
34
|
-
/**
|
|
35
|
-
* Variables forwarded from this process by *name*, for credentials.
|
|
36
|
-
*
|
|
37
|
-
* Separate from `env` for two reasons, both about the value never being
|
|
38
|
-
* written down. `--env NAME` without an `=` tells podman to read the value
|
|
39
|
-
* out of its own environment, so the secret never appears on a command
|
|
40
|
-
* line, in `ps`, or in `podman inspect`. And the container's identity is
|
|
41
|
-
* computed from the names alone, so rotating a key does not abandon a
|
|
42
|
-
* persisted container's filesystem.
|
|
43
|
-
*/
|
|
44
|
-
secrets?: readonly string[];
|
|
45
|
-
}
|
|
46
|
-
export type SandboxNetwork = 'bridge' | 'none' | 'host';
|
|
47
|
-
/**
|
|
48
|
-
* Two postures, because they cannot both be the default.
|
|
49
|
-
*
|
|
50
|
-
* `standard` is the one this tool was built around: a container with an init,
|
|
51
|
-
* a pid ceiling and `no-new-privileges`, running an image the agent can still
|
|
52
|
-
* install into. Installing a package is the ordinary use of a shell, so the
|
|
53
|
-
* capabilities stay and the root filesystem stays writable.
|
|
54
|
-
*
|
|
55
|
-
* `strict` is for running code nobody has read. Every capability is dropped,
|
|
56
|
-
* the root filesystem is read-only, the only writable temporary space is an
|
|
57
|
-
* in-memory `/tmp` with `noexec,nosuid,nodev`, the process runs as the host's
|
|
58
|
-
* own unprivileged uid rather than as container root, and the network is off
|
|
59
|
-
* unless the project turns it back on. What that costs is exactly what it
|
|
60
|
-
* removes: `apt`, `pip` and anything else that writes outside the mounts stop
|
|
61
|
-
* working, so a strict project bakes its dependencies into the image instead.
|
|
62
|
-
*
|
|
63
|
-
* What it does *not* do is make the bind mounts go away. `/workspace` is the
|
|
64
|
-
* work itself and stays writable — the profile shrinks the blast radius of a
|
|
65
|
-
* command, it does not pretend the agent has nothing to edit.
|
|
66
|
-
*/
|
|
67
|
-
export type SandboxHardening = 'standard' | 'strict';
|
|
68
|
-
export interface SandboxMount {
|
|
69
|
-
/** absolute host path */
|
|
70
|
-
host: string;
|
|
71
|
-
/** absolute path inside the container */
|
|
72
|
-
at: string;
|
|
73
|
-
readOnly?: boolean;
|
|
74
|
-
}
|
|
75
|
-
export interface SandboxOptions extends SandboxSpec {
|
|
76
|
-
/** host directory mounted at `workdir` */
|
|
77
|
-
root: string;
|
|
78
|
-
/**
|
|
79
|
-
* Stable name for whatever owns this sandbox — a session id, typically.
|
|
80
|
-
* It prefixes the container name, so a crashed process leaves something a
|
|
81
|
-
* human can recognise rather than a hash.
|
|
82
|
-
*/
|
|
83
|
-
key: string;
|
|
84
|
-
/** refuse to mount the workspace writable */
|
|
85
|
-
readOnly?: boolean;
|
|
86
|
-
/** extra bind mounts; the host side must already exist */
|
|
87
|
-
mounts?: readonly SandboxMount[];
|
|
88
|
-
/**
|
|
89
|
-
* Environment set on every command rather than on the container: values
|
|
90
|
-
* that belong to the run, not to the box — the user it is acting for.
|
|
91
|
-
*
|
|
92
|
-
* `env` is fixed when the container is created, and a container is kept
|
|
93
|
-
* between sessions and shared between agents; a run's values written there
|
|
94
|
-
* would still be answering for whoever came before. Not part of the
|
|
95
|
-
* container's name either, for the same reason in reverse: a new user is
|
|
96
|
-
* not a new machine. Plain values on podman's command line, so nothing
|
|
97
|
-
* secret goes here — that is what `secrets` is for.
|
|
98
|
-
*/
|
|
99
|
-
execEnv?: Record<string, string>;
|
|
100
|
-
/**
|
|
101
|
-
* Directories put in front of a path-like variable for every command —
|
|
102
|
-
* `PYTHONPATH`, say — keeping whatever the image already set behind them.
|
|
103
|
-
* `--env` could only replace the image's value, and an image that relies on
|
|
104
|
-
* its own `PYTHONPATH` would break on the first `python`.
|
|
105
|
-
*/
|
|
106
|
-
execPaths?: Record<string, readonly string[]>;
|
|
107
|
-
/** the container engine binary */
|
|
108
|
-
engine?: string;
|
|
109
|
-
/** how processes are spawned — the seam tests replace */
|
|
110
|
-
exec?: Runner;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Per-agent overrides on top of one base spec. An agent that overrides nothing
|
|
114
|
-
* shares the base container; an agent that names a different image gets its
|
|
115
|
-
* own, and two agents that name the *same* different image share that.
|
|
116
|
-
*/
|
|
117
|
-
export interface SandboxPoolOptions extends SandboxOptions {
|
|
118
|
-
agents?: Record<string, SandboxSpec>;
|
|
119
|
-
}
|
|
120
|
-
/** A failure the caller can do something about — a missing engine, usually. */
|
|
121
|
-
export declare class SandboxError extends Error {
|
|
122
|
-
readonly hint?: string;
|
|
123
|
-
constructor(message: string, hint?: string);
|
|
124
|
-
}
|
|
125
|
-
export interface ProcOptions {
|
|
126
|
-
/** written to stdin, which is then closed */
|
|
127
|
-
input?: string;
|
|
128
|
-
timeoutMs?: number;
|
|
129
|
-
signal?: AbortSignal;
|
|
130
|
-
/** per stream */
|
|
131
|
-
maxBytes?: number;
|
|
132
|
-
}
|
|
133
|
-
export interface ProcResult {
|
|
134
|
-
code: number;
|
|
135
|
-
stdout: string;
|
|
136
|
-
stderr: string;
|
|
137
|
-
truncated: boolean;
|
|
138
|
-
timedOut: boolean;
|
|
139
|
-
}
|
|
140
|
-
export type Runner = (bin: string, args: readonly string[], opts?: ProcOptions) => Promise<ProcResult>;
|
|
141
|
-
export declare const runProcess: Runner;
|
|
142
|
-
/**
|
|
143
|
-
* `run`, retried while the engine could not be reached at all.
|
|
144
|
-
*
|
|
145
|
-
* Empty stdout is the guard that keeps this from retrying real work: a command
|
|
146
|
-
* that produced output ran, whatever its stderr says afterwards. The wait is
|
|
147
|
-
* jittered because the burst being backed off from is N clients arriving
|
|
148
|
-
* together, and a fixed delay would only reassemble it.
|
|
149
|
-
*/
|
|
150
|
-
export declare function resilient(run: Runner, attempts?: number): Runner;
|
|
151
|
-
interface Resolved extends Required<Omit<SandboxSpec, 'user'>> {
|
|
152
|
-
user?: string;
|
|
153
|
-
root: string;
|
|
154
|
-
key: string;
|
|
155
|
-
readOnly: boolean;
|
|
156
|
-
mounts: readonly SandboxMount[];
|
|
157
|
-
engine: string;
|
|
158
|
-
execEnv: Record<string, string>;
|
|
159
|
-
execPaths: Record<string, readonly string[]>;
|
|
160
|
-
explicitCpus?: boolean;
|
|
161
|
-
explicitMemory?: boolean;
|
|
162
|
-
}
|
|
163
|
-
export interface ExecOptions {
|
|
164
|
-
cwd?: string;
|
|
165
|
-
/** seconds; the spec's default otherwise */
|
|
166
|
-
timeout?: number;
|
|
167
|
-
signal?: AbortSignal;
|
|
168
|
-
}
|
|
169
|
-
export interface ExecResult {
|
|
170
|
-
exit_code: number;
|
|
171
|
-
stdout: string;
|
|
172
|
-
stderr: string;
|
|
173
|
-
truncated?: boolean;
|
|
174
|
-
timed_out?: boolean;
|
|
175
|
-
duration_ms: number;
|
|
176
|
-
out_of_memory?: OutOfMemory;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Why a command was killed for memory, which is a different question from
|
|
180
|
-
* whether it was. A container that overran its own `--memory` will do it again
|
|
181
|
-
* however long anyone waits; one the kernel sacrificed for a neighbour may
|
|
182
|
-
* simply succeed later. Exit code 137 is all either of them says.
|
|
183
|
-
*/
|
|
184
|
-
export interface OutOfMemory {
|
|
185
|
-
/** what this container was allowed */
|
|
186
|
-
limit_mib: number;
|
|
187
|
-
/** high-water mark for the container's whole life, not for this command */
|
|
188
|
-
peak_mib?: number;
|
|
189
|
-
/** false when the limit itself is the problem, so an unchanged rerun ends the same way */
|
|
190
|
-
retryable: boolean;
|
|
191
|
-
hint: string;
|
|
192
|
-
}
|
|
193
|
-
interface Job {
|
|
194
|
-
id: string;
|
|
195
|
-
command: string;
|
|
196
|
-
cwd: string;
|
|
197
|
-
startedAt: number;
|
|
198
|
-
/** worked out once, because a log is read many times and the evidence is consumed */
|
|
199
|
-
oom?: OutOfMemory;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* The container, started when it is first needed and not before. A project
|
|
203
|
-
* whose agents never shell out never pays for an image pull, and a session
|
|
204
|
-
* that only ever asks a question never leaves anything behind.
|
|
205
|
-
*/
|
|
206
|
-
export declare class Sandbox {
|
|
207
|
-
#private;
|
|
208
|
-
readonly name: string;
|
|
209
|
-
readonly spec: Resolved;
|
|
210
|
-
constructor(opts: SandboxOptions);
|
|
211
|
-
/** Whether anything was actually started — `dispose` is free when not. */
|
|
212
|
-
get started(): boolean;
|
|
213
|
-
/**
|
|
214
|
-
* Idempotent, and single-flight: several tool calls in one batch all await
|
|
215
|
-
* the same start rather than racing to create the same container.
|
|
216
|
-
*/
|
|
217
|
-
start(): Promise<void>;
|
|
218
|
-
/**
|
|
219
|
-
* Runs one command and waits for it. The script goes down stdin, so no part
|
|
220
|
-
* of it is ever parsed by a shell on this side of the container.
|
|
221
|
-
*/
|
|
222
|
-
exec(command: string, opts?: ExecOptions): Promise<ExecResult>;
|
|
223
|
-
/**
|
|
224
|
-
* Starts a command and returns. The wrapper writes the log and the exit
|
|
225
|
-
* code to files the container owns, which is what makes the job readable
|
|
226
|
-
* after the `exec` that started it has long returned.
|
|
227
|
-
*/
|
|
228
|
-
startJob(command: string, opts?: ExecOptions): Promise<Job>;
|
|
229
|
-
/** A window of a job's log, plus whether it is still going. */
|
|
230
|
-
readJob(id: string, from?: number): Promise<unknown>;
|
|
231
|
-
/** Signals a job's whole process group, so its children go too. */
|
|
232
|
-
stopJob(id: string): Promise<unknown>;
|
|
233
|
-
/**
|
|
234
|
-
* Stops a persisted container and removes an ephemeral one. Stopping
|
|
235
|
-
* rather than removing is what makes `persist` mean anything: a stopped
|
|
236
|
-
* container costs disk, a running one costs the machine's whole budget.
|
|
237
|
-
*/
|
|
238
|
-
dispose(): Promise<void>;
|
|
239
|
-
/**
|
|
240
|
-
* A path inside the container, contained to the working directory. Purely
|
|
241
|
-
* lexical, and correctly so: this is the container's path space, not this
|
|
242
|
-
* machine's, and there is nothing here to resolve a symlink against.
|
|
243
|
-
*/
|
|
244
|
-
inside(path?: string): string;
|
|
245
|
-
}
|
|
246
|
-
export interface SandboxLimits {
|
|
247
|
-
/** MiB */
|
|
248
|
-
memory: number;
|
|
249
|
-
/** fractional cores */
|
|
250
|
-
cpus: number;
|
|
251
|
-
hardening: SandboxHardening;
|
|
252
|
-
/** whether the numbers above were written down, or are this profile's defaults */
|
|
253
|
-
declared: boolean;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* What a spec's ceilings come to, for a report that has no container to ask.
|
|
257
|
-
*
|
|
258
|
-
* It exists so `zen sandbox status` cannot disagree with what a run actually
|
|
259
|
-
* applies: the defaults are stated once, here and in `resolveSpec`, and
|
|
260
|
-
* nothing outside this module repeats them.
|
|
261
|
-
*/
|
|
262
|
-
export declare function sandboxLimits(spec?: Pick<SandboxSpec, 'cpus' | 'memory' | 'hardening'>): SandboxLimits;
|
|
263
|
-
export declare class SandboxPool {
|
|
264
|
-
#private;
|
|
265
|
-
constructor(opts: SandboxPoolOptions);
|
|
266
|
-
for(agent?: string): Sandbox;
|
|
267
|
-
/** The containers that were actually started, for a status line. */
|
|
268
|
-
get running(): readonly Sandbox[];
|
|
269
|
-
dispose(): Promise<void>;
|
|
270
|
-
}
|
|
271
|
-
export declare function sandboxTools<TCtx = unknown>(opts: SandboxPoolOptions | SandboxPool): AnyTool<TCtx>[];
|
|
272
|
-
export {};
|
|
5
|
+
export declare function sandboxTools<TCtx = unknown>(sandbox: Sandbox): AnyTool<TCtx>[];
|
|
273
6
|
//# sourceMappingURL=sandbox.d.ts.map
|