@zenera/cli 1.1.55 → 1.1.57

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/batch.d.ts CHANGED
@@ -34,6 +34,8 @@ export interface BatchOptions {
34
34
  image?: string;
35
35
  readOnly?: boolean;
36
36
  keys?: boolean;
37
+ /** `--podman`: ignore a plugin that provides the sandbox */
38
+ sandboxPlugins?: boolean;
37
39
  yes?: boolean;
38
40
  /** `--as`: who every item acts for */
39
41
  user?: RunIdentity;
@@ -44,9 +46,9 @@ export interface BatchOptions {
44
46
  export type MemoryMode = 'read-only' | 'copied' | 'none';
45
47
  export declare function runBatch(opts: BatchOptions): Promise<void>;
46
48
  /**
47
- * The most containers one item can start: one shared by the agents on the
48
- * project's sandbox block, one more for each agent with a block of its own.
49
- * A project that does not load is each item's to report, so it counts none.
49
+ * The containers one item can start: one, shared by every agent, when any
50
+ * agent can reach a shell, and none otherwise. A project that does not load
51
+ * is each item's to report, so it counts none.
50
52
  */
51
53
  export declare function containersPerItem(dir: string): number;
52
54
  /**
package/dist/batch.js CHANGED
@@ -170,9 +170,9 @@ export async function runBatch(opts) {
170
170
  // One item
171
171
  // ---------------------------------------------------------------------------
172
172
  /**
173
- * The most containers one item can start: one shared by the agents on the
174
- * project's sandbox block, one more for each agent with a block of its own.
175
- * A project that does not load is each item's to report, so it counts none.
173
+ * The containers one item can start: one, shared by every agent, when any
174
+ * agent can reach a shell, and none otherwise. A project that does not load
175
+ * is each item's to report, so it counts none.
176
176
  */
177
177
  export function containersPerItem(dir) {
178
178
  let read;
@@ -183,7 +183,7 @@ export function containersPerItem(dir) {
183
183
  return 0;
184
184
  }
185
185
  const tools = availableTools(read.root, read.config);
186
- const shells = read.config.agents.filter((a) => {
186
+ const shell = read.config.agents.some((a) => {
187
187
  try {
188
188
  return selectTools(tools, [...(a.tools ?? [])], { where: a.name }).some((t) => t.group === SANDBOX_GROUP);
189
189
  }
@@ -191,8 +191,7 @@ export function containersPerItem(dir) {
191
191
  return false;
192
192
  }
193
193
  });
194
- const own = shells.filter((a) => a.sandbox).length;
195
- return own + (shells.length > own ? 1 : 0);
194
+ return shell ? 1 : 0;
196
195
  }
197
196
  /**
198
197
  * A failure is data. One item that asks something the model cannot answer must
@@ -222,6 +221,7 @@ async function runItem(item, ctx) {
222
221
  memoryDir: ctx.memory,
223
222
  memoryReadOnly: ctx.memoryReadOnly,
224
223
  keys: ctx.opts.keys,
224
+ sandboxPlugins: ctx.opts.sandboxPlugins,
225
225
  user: ctx.opts.user,
226
226
  yes: true,
227
227
  // The project's own problems are the batch's, not each item's.
@@ -1,5 +1,5 @@
1
1
  import { display, KeyStore, listRuns, listSessions, loadProjectEnv, newestRun, readRunMeta, requireSession, runPaths, runPathsAt, sessionIds, sessionPaths, } from '@zenera/engine';
2
- import { assertState, buildRunReport, FilePayloadStore, isMemory, memoryDir, MemoryStore, PayloadResolver, projectRegistry, readProjectConfig, renderReportHtml, SANDBOX_MOUNT, text, } from '@zenera/neo';
2
+ import { assertState, buildRunReport, FilePayloadStore, isMemory, memoryDir, MemoryStore, PayloadResolver, projectRegistry, readProjectConfig, renderReportHtml, WORKSPACE_MOUNT, text, } from '@zenera/neo';
3
3
  import { spawn } from 'node:child_process';
4
4
  import { existsSync } from 'node:fs';
5
5
  import { readFile, writeFile } from 'node:fs/promises';
@@ -654,7 +654,7 @@ async function rebuild(session, run, store) {
654
654
  title: run.id,
655
655
  memory: store,
656
656
  // The run never recorded a `workdir:`, so the default name is the guess.
657
- mounts: workspace ? [{ at: SANDBOX_MOUNT, href: pathToFileURL(workspace).href }] : [],
657
+ mounts: workspace ? [{ at: WORKSPACE_MOUNT, href: pathToFileURL(workspace).href }] : [],
658
658
  });
659
659
  await writeFile(run.report, renderReportHtml(report), 'utf8');
660
660
  }
@@ -983,7 +983,7 @@ function textLast(rows, texts) {
983
983
  : Infinity;
984
984
  return table(rows.map((r, i) => [...r, clip(texts[i] ?? '', room)]));
985
985
  }
986
- /** The stored `/memory/<id>.<ext>` is the agent's mount path; a terminal needs the host one. */
986
+ /** The stored `/memory/<id>.<ext>` names the file, not where it is; a terminal needs the host path. */
987
987
  function onHost(o, n) {
988
988
  return n.file ? { ...n, file: { ...n.file, path: hostPath(o.dir, n.file) } } : n;
989
989
  }
@@ -1,5 +1,5 @@
1
1
  import * as Projects from '@zenera/engine';
2
- import { display } from '@zenera/engine';
2
+ import { display, PODMAN_PROVIDER } from '@zenera/engine';
3
3
  import { identityFromEnv, usageByModel } from '@zenera/neo';
4
4
  import { writeFile } from 'node:fs/promises';
5
5
  import { resolve } from 'node:path';
@@ -41,6 +41,8 @@ export const run = {
41
41
  ' --image <ref> Use this container image to run commands in.',
42
42
  ' --read-only Take away every tool that can write.',
43
43
  ' --no-keys Do not pass API keys into the container.',
44
+ ' --podman Run commands in podman on this machine, even when a',
45
+ ' plugin in $ZEN_PLUGINS provides the sandbox.',
44
46
  ' --as <user> Act for this user: what `current_user` answers and $ZEN_USER_ID',
45
47
  ' holds. An email also sets $ZEN_USER_EMAIL. For trying',
46
48
  ' a project; the Zenera app passes the signed-in user.',
@@ -132,6 +134,7 @@ export const run = {
132
134
  model: { type: 'string' },
133
135
  image: { type: 'string' },
134
136
  'no-keys': { type: 'boolean' },
137
+ podman: { type: 'boolean' },
135
138
  as: { type: 'string' },
136
139
  'read-only': { type: 'boolean' },
137
140
  yes: { type: 'boolean' },
@@ -205,6 +208,7 @@ export const run = {
205
208
  memoryDir: request?.memory ?? (values.memory ? resolve(ctx.cwd, values.memory) : undefined),
206
209
  memoryReadOnly: values['memory-read-only'],
207
210
  keys: values['no-keys'] ? false : undefined,
211
+ sandboxPlugins: values.podman ? false : undefined,
208
212
  user: asUser(values.as),
209
213
  yes: values.yes || ctx.json,
210
214
  disposable: values.disposable,
@@ -306,6 +310,7 @@ async function batch(ctx, values, rest, piped) {
306
310
  image: values.image,
307
311
  readOnly: values['read-only'],
308
312
  keys: values['no-keys'] ? false : undefined,
313
+ sandboxPlugins: values.podman ? false : undefined,
309
314
  user: asUser(values.as),
310
315
  yes: values.yes,
311
316
  out: values.out,
@@ -341,6 +346,11 @@ async function once(engine, input, values, asJson, cwd, where) {
341
346
  `${dim(engine.session.id)}`);
342
347
  note(dim(`${where.freshWorkspace ? 'new directory' : 'workspace'} ` +
343
348
  `${display(engine.workspace, cwd)}`));
349
+ // Only when it is not the default, which is the one case worth a line:
350
+ // a plugin moved the commands, and the files with them, elsewhere.
351
+ if (engine.sandbox.provider !== PODMAN_PROVIDER) {
352
+ note(dim(`sandbox ${engine.sandbox.provider}`));
353
+ }
344
354
  }
345
355
  let outcome;
346
356
  try {
@@ -1,4 +1,4 @@
1
- import { current as currentProject, dirSize, isProjectDir, open as openProject, Registry, resolveBuild, sessionIds, } from '@zenera/engine';
1
+ import { current as currentProject, dirSize, isProjectDir, machineSandboxProvider, open as openProject, Registry, resolveBuild, sessionIds, } from '@zenera/engine';
2
2
  import { readProjectConfig, sandboxLimits, } from '@zenera/neo';
3
3
  import { parse } from "../args.js";
4
4
  import { engineDisk, ensurePodmanReady, idleContainers, ownedContainers, podmanStatus, removeContainers, sessionOwners, } from "../podman.js";
@@ -48,6 +48,8 @@ export const sandbox = {
48
48
  ' what happens with --json or when output is not a terminal.',
49
49
  ' --interval <seconds> With top: how often the live screen refreshes (default 2).',
50
50
  ' --brief With top: the figures without the notes explaining them.',
51
+ ' --podman Podman on this machine, even when a plugin in',
52
+ ' $ZEN_PLUGINS provides the sandbox.',
51
53
  '',
52
54
  'Without --project this is the project you are standing in, and standing',
53
55
  'nowhere is an answer: `status` then reports the engine and every container',
@@ -55,6 +57,9 @@ export const sandbox = {
55
57
  '',
56
58
  'None of this is required. A run does all of it on its own, the first',
57
59
  'time an agent that can reach a shell is about to start one.',
60
+ '',
61
+ 'When a plugin provides the sandbox, `status` and `clean` ask it instead,',
62
+ 'and the podman-only subcommands say so.',
58
63
  ],
59
64
  run: async (ctx) => {
60
65
  const { values, positionals } = parse(ctx.args, {
@@ -66,6 +71,7 @@ export const sandbox = {
66
71
  interval: { type: 'string' },
67
72
  brief: { type: 'boolean' },
68
73
  theme: { type: 'string' },
74
+ podman: { type: 'boolean' },
69
75
  }, USAGE);
70
76
  const what = positionals[0] ?? 'status';
71
77
  if (!SUBCOMMANDS.includes(what)) {
@@ -78,6 +84,17 @@ export const sandbox = {
78
84
  // project they do not use would be reading something for nothing.
79
85
  const scoped = what === 'status' || what === 'up' || what === 'pull';
80
86
  const found = scoped ? await projectSandbox(ctx.cwd, values) : undefined;
87
+ if (!values.podman) {
88
+ const remote = await machineSandboxProvider({ dir: found?.dir ?? ctx.cwd, name: found?.name ?? 'machine' }, undefined, { warn: (m) => note(yellow(m)) });
89
+ if (remote) {
90
+ try {
91
+ return await elsewhere(what, remote.provider, ctx.json, values);
92
+ }
93
+ finally {
94
+ await Promise.resolve(remote.plugin.close?.()).catch(() => undefined);
95
+ }
96
+ }
97
+ }
81
98
  const image = values.image ?? found?.image;
82
99
  const build = values.image ? undefined : found?.build;
83
100
  switch (what) {
@@ -99,6 +116,37 @@ export const sandbox = {
99
116
  }
100
117
  },
101
118
  };
119
+ /**
120
+ * The subcommands, when a plugin runs the sandboxes somewhere else: the two it
121
+ * can answer are asked of it, and the rest are about a podman that is not the
122
+ * one in use, so they say that rather than quietly reporting on it.
123
+ */
124
+ async function elsewhere(what, provider, asJson, values) {
125
+ if (what === 'status') {
126
+ const report = provider.status ? await provider.status() : undefined;
127
+ if (asJson) {
128
+ json({ provider: provider.describe, ...(report ?? {}) });
129
+ return;
130
+ }
131
+ write(`${bold('sandbox')} ${provider.describe}`);
132
+ for (const line of report?.lines ?? [dim('it has nothing more to say')]) {
133
+ write(`${INDENT}${line}`);
134
+ }
135
+ return;
136
+ }
137
+ if (what === 'clean' && provider.clean) {
138
+ const removed = await provider.clean({ all: !(values.idle || values.stopped) });
139
+ if (asJson) {
140
+ json({ provider: provider.describe, removed });
141
+ return;
142
+ }
143
+ write(removed.length
144
+ ? `removed ${count(removed.length, 'sandbox')}`
145
+ : dim('nothing to remove'));
146
+ return;
147
+ }
148
+ throw usageError(`sandboxes run on ${provider.describe}, so \`zen sandbox ${what}\` has nothing to do here`, 'pass --podman to manage podman on this machine anyway');
149
+ }
102
150
  /**
103
151
  * Which project this is about: the flag, or the directory the command was run
104
152
  * in. It deliberately never asks. `zen sandbox status` run from anywhere at
@@ -122,7 +170,7 @@ async function projectSandbox(cwd, values) {
122
170
  name: found.name,
123
171
  image: build?.tag ?? config.sandbox?.image,
124
172
  build,
125
- limits: widest(config),
173
+ limits: sandboxLimits(config.sandbox),
126
174
  };
127
175
  }
128
176
  catch {
@@ -237,22 +285,6 @@ const PAINT = {
237
285
  function ansi(line) {
238
286
  return line.map((s) => PAINT[s.tone ?? 'plain'](s.text)).join('');
239
287
  }
240
- /**
241
- * The hungriest container this project can start. An agent may override the
242
- * project's `sandbox:` block, and it is the largest of them that decides
243
- * whether a batch fits — reporting the project's own figure would understate
244
- * the machine by however much an agent asked for on top.
245
- *
246
- * The overrides are merged onto the project's block rather than read alone,
247
- * because that is what `SandboxPool.for` does when it builds the container: an
248
- * agent that names only `memory:` still runs with the project's `cpus:`.
249
- */
250
- function widest(config) {
251
- const base = config.sandbox ?? {};
252
- return config.agents
253
- .map((a) => sandboxLimits(a.sandbox ? { ...base, ...a.sandbox } : base))
254
- .reduce((most, one) => (one.memory > most.memory ? one : most), sandboxLimits(base));
255
- }
256
288
  /**
257
289
  * How many containers of this size the engine could hold at once.
258
290
  *
package/dist/podman.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { type ResolvedBuild } from '@zenera/engine';
2
- import { runProcess } from '@zenera/neo';
1
+ import { runProcess, type BuildSpec, type PrepareOptions } from '@zenera/neo';
3
2
  import { CliError } from './term.ts';
4
3
  export interface PodmanOptions {
5
4
  /** the image the project needs on disk before the first run */
6
5
  image?: string;
7
6
  /** a Dockerfile to build into `image`, instead of a registry to pull it from */
8
- build?: ResolvedBuild;
7
+ build?: BuildSpec;
9
8
  /** build even when the tag is already on disk; `zen sandbox pull` */
10
9
  rebuild?: boolean;
11
10
  /** machine size, when one has to be created */
@@ -47,6 +46,27 @@ export interface PodmanStatus {
47
46
  imagePresent?: boolean;
48
47
  }
49
48
  export declare function ensurePodmanReady(opts?: PodmanOptions): Promise<void>;
49
+ /**
50
+ * How a terminal watches a pull or a build: the sandbox's own lines, dimmed,
51
+ * and a spinner over each slow step.
52
+ */
53
+ export declare function terminalProgress(): Pick<PrepareOptions, 'onProgress' | 'slow'>;
54
+ /**
55
+ * The image step on its own, in a terminal's words: what `ensurePodmanReady`
56
+ * ends with, and what `zen init` and `zen sandbox pull` ask for directly. A
57
+ * Dockerfile that does not build is a `BuildError`; everything else the engine
58
+ * says is a sandbox error.
59
+ */
60
+ export declare function ensureImage(target: {
61
+ image: string;
62
+ build?: BuildSpec;
63
+ }, opts?: {
64
+ engine?: string;
65
+ exec?: typeof runProcess;
66
+ force?: boolean;
67
+ }): Promise<void>;
68
+ /** A sandbox's failure, as the CLI reports it. */
69
+ export declare function asCliError(err: unknown): unknown;
50
70
  /**
51
71
  * The machine's forwarded endpoint as a URI this client accepts, or nothing
52
72
  * when there is no machine to ask.
package/dist/podman.js CHANGED
@@ -1,15 +1,13 @@
1
- import { isBusy, isProjectDir, Registry, sessionIds, sessionsDir, } from '@zenera/engine';
2
- import { pidAlive, runProcess, SandboxError } from '@zenera/neo';
1
+ import { isBusy, isProjectDir, Registry, sessionIds, sessionsDir } from '@zenera/engine';
2
+ import { ensurePodmanImage, isImageBuildError, pidAlive, runProcess, SandboxError, } from '@zenera/neo';
3
3
  import { readdirSync, readFileSync, statSync } from 'node:fs';
4
4
  import { homedir, platform } from 'node:os';
5
5
  import { join } from 'node:path';
6
6
  import { CliError, confirm, dim, EXIT, isInteractive, note, progress } from "./term.js";
7
7
  const DEFAULT_MACHINE_CPUS = 2;
8
8
  const DEFAULT_MACHINE_MEMORY = 2048;
9
- /** Starting a virtual machine and pulling an image are both slow on purpose. */
9
+ /** Starting a virtual machine is slow on purpose. */
10
10
  const SLOW_MS = 600_000;
11
- /** ...and a build from a cold cache is slower than either. */
12
- const BUILD_MS = 900_000;
13
11
  // One process asks once. Several agents starting containers in the same run
14
12
  // must not each decide to boot a virtual machine.
15
13
  const settled = new Map();
@@ -75,20 +73,42 @@ async function preflight(opts) {
75
73
  }
76
74
  // 4. The image, so the first command is not a five-minute pull that looks
77
75
  // like a hung model.
78
- if (opts.build) {
79
- await build(engine, opts.build, run, opts.rebuild);
80
- }
81
- else if (opts.image) {
82
- const present = await call(['image', 'exists', opts.image], 30_000);
83
- if (present.code !== 0) {
84
- note(dim(`pulling ${opts.image} — this happens once`));
85
- const pulled = await stream(engine, ['pull', opts.image], run, 'pulling');
86
- if (pulled.code !== 0) {
87
- throw sandboxError(`could not pull ${opts.image}`, first(pulled) || 'check the image name and your network');
88
- }
89
- }
76
+ if (opts.image) {
77
+ await ensureImage({ image: opts.image, build: opts.build }, { engine, exec: run, force: opts.rebuild });
78
+ }
79
+ }
80
+ /**
81
+ * How a terminal watches a pull or a build: the sandbox's own lines, dimmed,
82
+ * and a spinner over each slow step.
83
+ */
84
+ export function terminalProgress() {
85
+ return { onProgress: (line) => note(dim(line)), slow: ticking };
86
+ }
87
+ /**
88
+ * The image step on its own, in a terminal's words: what `ensurePodmanReady`
89
+ * ends with, and what `zen init` and `zen sandbox pull` ask for directly. A
90
+ * Dockerfile that does not build is a `BuildError`; everything else the engine
91
+ * says is a sandbox error.
92
+ */
93
+ export async function ensureImage(target, opts = {}) {
94
+ try {
95
+ await ensurePodmanImage(target, { engine: opts.engine, exec: opts.exec }, { ...terminalProgress(), force: opts.force });
96
+ }
97
+ catch (err) {
98
+ throw asCliError(err);
90
99
  }
91
100
  }
101
+ /** A sandbox's failure, as the CLI reports it. */
102
+ export function asCliError(err) {
103
+ if (isImageBuildError(err)) {
104
+ return new BuildError(err.message, EXIT.sandbox, err.hint);
105
+ }
106
+ // By name too, for a sandbox a plugin built against its own copy of the package.
107
+ if (err instanceof SandboxError || (err instanceof Error && err.name === 'SandboxError')) {
108
+ return new CliError(err.message, EXIT.sandbox, err.hint);
109
+ }
110
+ return err;
111
+ }
92
112
  // ---------------------------------------------------------------------------
93
113
  // Installing
94
114
  // ---------------------------------------------------------------------------
@@ -335,32 +355,6 @@ async function connectionOf(engine, exec) {
335
355
  */
336
356
  export class BuildError extends CliError {
337
357
  }
338
- /**
339
- * Builds the project's Dockerfile under its tag, unless that tag is already on
340
- * disk.
341
- *
342
- * Skipping is safe here in a way it would not be for an ordinary tag, because
343
- * this one is a hash of the Dockerfile and its context: the image existing
344
- * *means* the content is unchanged. What it does not cover is a moved base
345
- * image — `podman build` defaults to `--pull=missing` and reuses whatever
346
- * `FROM node:24` resolved to last time — so `zen sandbox pull` forces the
347
- * build, and `--pull` is where that would be fixed if it ever needs to be.
348
- */
349
- async function build(engine, spec, run, force = false) {
350
- if (!force) {
351
- const present = await run(engine, ['image', 'exists', spec.tag], { timeoutMs: 30_000 });
352
- if (present.code === 0) {
353
- return;
354
- }
355
- }
356
- note(dim(`${force ? 'rebuilding' : 'building'} the sandbox image from ${spec.dockerfile}`));
357
- note(dim(' the agent runs its commands inside a container, so the image is needed first'));
358
- note(dim(' this takes a few minutes; later runs reuse it'));
359
- const built = await stream(engine, ['build', '--tag', spec.tag, '--file', spec.dockerfile, spec.context], run, 'building the sandbox image', BUILD_MS);
360
- if (built.code !== 0) {
361
- throw new BuildError(`could not build ${spec.dockerfile}`, EXIT.sandbox, last(built) || 'run the build by hand to see what the engine says');
362
- }
363
- }
364
358
  // ---------------------------------------------------------------------------
365
359
  // Reporting
366
360
  // ---------------------------------------------------------------------------
@@ -690,11 +684,6 @@ function elapsed(ms) {
690
684
  function first(res) {
691
685
  return (res.stderr.trim() || res.stdout.trim()).split('\n')[0] ?? '';
692
686
  }
693
- /** A build says what went wrong on its last line, not its first. */
694
- function last(res) {
695
- const lines = (res.stderr.trim() || res.stdout.trim()).split('\n').filter((l) => l.trim());
696
- return lines.slice(-2).join(' — ');
697
- }
698
687
  function sandboxError(message, hint) {
699
688
  return new CliError(message, EXIT.sandbox, hint);
700
689
  }
package/dist/sandbox.d.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  import type { SandboxSetup } from '@zenera/engine';
2
- /** The engine's preflight on a terminal: podman is offered for install and started if needed. */
2
+ /**
3
+ * The engine's preflight on a terminal. For podman: the engine is offered for
4
+ * install and started if needed, and its lock table checked. For any sandbox:
5
+ * its image is pulled or built now, with progress, rather than silently at the
6
+ * first command of the turn.
7
+ */
3
8
  export declare function preflight(setup: SandboxSetup, yes?: boolean): Promise<void>;
4
9
  //# sourceMappingURL=sandbox.d.ts.map
package/dist/sandbox.js CHANGED
@@ -1,24 +1,29 @@
1
- import { assertLocks, ensurePodmanReady } from "./podman.js";
1
+ import { PodmanSandbox } from '@zenera/neo';
2
+ import { asCliError, assertLocks, ensurePodmanReady, terminalProgress } from "./podman.js";
2
3
  /**
3
4
  * Images this process has already settled. A batch opens the same project
4
- * dozens of times at once, and without this each one shells out to podman and
5
- * the concurrent copies race each other to pull the very same image.
5
+ * dozens of times at once, and without this each one asks podman for its
6
+ * machine and its locks all over again.
6
7
  */
7
8
  const READY = new Set();
8
- /** The engine's preflight on a terminal: podman is offered for install and started if needed. */
9
+ /**
10
+ * The engine's preflight on a terminal. For podman: the engine is offered for
11
+ * install and started if needed, and its lock table checked. For any sandbox:
12
+ * its image is pulled or built now, with progress, rather than silently at the
13
+ * first command of the turn.
14
+ */
9
15
  export async function preflight(setup, yes) {
10
- if (READY.has(setup.image)) {
11
- return;
16
+ if (setup.sandbox instanceof PodmanSandbox && !READY.has(setup.image)) {
17
+ await ensurePodmanReady({ cpus: setup.spec.cpus, memory: setup.spec.memory, yes });
18
+ // A resumed session restarts its own stopped container, which needs no lock.
19
+ await assertLocks(1, { reuses: setup.sandbox.name });
20
+ READY.add(setup.image);
21
+ }
22
+ try {
23
+ await setup.sandbox.prepare(terminalProgress());
24
+ }
25
+ catch (err) {
26
+ throw asCliError(err);
12
27
  }
13
- await ensurePodmanReady({
14
- image: setup.image,
15
- build: setup.build,
16
- cpus: setup.spec.cpus,
17
- memory: setup.spec.memory,
18
- yes,
19
- });
20
- // A resumed session restarts its own stopped container, which needs no lock.
21
- await assertLocks(1, { reuses: setup.pool.for().name });
22
- READY.add(setup.image);
23
28
  }
24
29
  //# sourceMappingURL=sandbox.js.map
package/dist/validate.js CHANGED
@@ -1,5 +1,5 @@
1
- import { SHAPES, auditModels, credentialFor, envNames, form, machinePluginTools, PLUGINS_ENV, resolveBuild, } from '@zenera/engine';
2
- import { EXA_GROUP, FileSkillProvider, SANDBOX_MOUNT, Sandbox, exaTools, fileTools, frontmatter, projectRegistry, readProjectConfig, sandboxTools, selectTools, toList, } from '@zenera/neo';
1
+ import { SHAPES, auditModels, credentialFor, envNames, form, machinePluginTools, machineSandboxProvider, PLUGINS_ENV, resolveBuild, } from '@zenera/engine';
2
+ import { EXA_GROUP, FileSkillProvider, isImageBuildError, PodmanSandbox, WORKSPACE_MOUNT, exaTools, fileTools, frontmatter, projectRegistry, readProjectConfig, sandboxTools, selectTools, toList, } from '@zenera/neo';
3
3
  import { existsSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync, } from 'node:fs';
4
4
  import { tmpdir } from 'node:os';
5
5
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
@@ -447,7 +447,7 @@ export async function validateProject(opts) {
447
447
  await askModels(resolved.targets, asking, add);
448
448
  }
449
449
  if (opts.sandbox?.enabled && sandboxSummary(config, agents).used) {
450
- probed = await probeSandbox(config, build, opts.sandbox, add);
450
+ probed = await probeSandbox({ dir: root, name: name ?? basename(root) }, config, build, opts.sandbox, add);
451
451
  }
452
452
  return done();
453
453
  }
@@ -625,9 +625,9 @@ export function availableTools(root, config) {
625
625
  return [
626
626
  ...fileTools({
627
627
  root,
628
- mount: config.sandbox?.workdir ?? SANDBOX_MOUNT,
628
+ mount: config.sandbox?.workdir ?? WORKSPACE_MOUNT,
629
629
  }),
630
- ...sandboxTools({ root, key: 'check' }),
630
+ ...sandboxTools(new PodmanSandbox({ root, key: 'check' })),
631
631
  ...exaTools(),
632
632
  ];
633
633
  }
@@ -1395,15 +1395,73 @@ export function repinDockerfile(root) {
1395
1395
  /** Written by the smoke test and read back, to prove the mount is real. */
1396
1396
  const SMOKE = 'zen-check';
1397
1397
  /**
1398
- * Builds the image and runs one command in it.
1398
+ * Builds the image and runs one command in it — in podman here, or wherever the
1399
+ * plugin that provides the sandbox puts it.
1399
1400
  *
1400
- * The container is given a temporary directory rather than anybody's
1401
- * workspace: this is a check, and a check that can write to the work is not
1402
- * one. `persist` is off, so closing it removes it — a `zen check` that left a
1401
+ * The sandbox is given a temporary directory rather than anybody's workspace:
1402
+ * this is a check, and a check that can write to the work is not one.
1403
+ * `persist` is off, so closing it removes it — a `zen check` that left a
1403
1404
  * container behind would be a slow leak nobody attributed to it.
1404
1405
  */
1405
- async function probeSandbox(config, build, opts, add) {
1406
+ async function probeSandbox(project, config, build, opts, add) {
1406
1407
  const image = build?.tag ?? config.sandbox?.image;
1408
+ const spec = {
1409
+ key: 'check',
1410
+ image: config.sandbox?.image,
1411
+ build: build ? { dockerfile: build.dockerfile, context: build.context } : undefined,
1412
+ cpus: config.sandbox?.cpus,
1413
+ memory: config.sandbox?.memory,
1414
+ network: config.sandbox?.network,
1415
+ workdir: config.sandbox?.workdir,
1416
+ user: config.sandbox?.user,
1417
+ // Not the project's: a check forwards no host values, and keeping the
1418
+ // container is the caller's choice about their work, not about this.
1419
+ env: {},
1420
+ persist: false,
1421
+ };
1422
+ const unbuilt = (err) => {
1423
+ const rel = config.sandbox?.build?.dockerfile ?? 'the Dockerfile';
1424
+ add({
1425
+ severity: 'error',
1426
+ code: 'sandbox.build',
1427
+ where: 'sandbox.build.dockerfile',
1428
+ message: `${rel} does not build: ${err.hint ?? reason(err)}`,
1429
+ fix: 'run the build by hand to see the whole log',
1430
+ });
1431
+ return false;
1432
+ };
1433
+ const found = await machineSandboxProvider(project, config.sandbox, {
1434
+ warn: (message) => add({ severity: 'warning', code: 'plugins.load', where: PLUGINS_ENV, message }),
1435
+ });
1436
+ if (found) {
1437
+ const { provider, plugin } = found;
1438
+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'zen-check-')));
1439
+ try {
1440
+ const box = provider.newSandbox({ ...spec, root });
1441
+ opts.onProgress?.(`checking the sandbox on ${provider.describe}`);
1442
+ try {
1443
+ await box.prepare({ onProgress: opts.onProgress });
1444
+ }
1445
+ catch (err) {
1446
+ if (isImageBuildError(err)) {
1447
+ return unbuilt(err);
1448
+ }
1449
+ add({
1450
+ severity: 'error',
1451
+ code: 'sandbox.unreachable',
1452
+ where: PLUGINS_ENV,
1453
+ message: `${provider.describe} could not prepare the sandbox: ${reason(err)}`,
1454
+ fix: `check the service, or pass --no-sandbox to skip this`,
1455
+ });
1456
+ return false;
1457
+ }
1458
+ return await smoke(box, image ?? provider.describe, opts, add);
1459
+ }
1460
+ finally {
1461
+ await Promise.resolve(plugin.close?.()).catch(() => undefined);
1462
+ rmSync(root, { recursive: true, force: true });
1463
+ }
1464
+ }
1407
1465
  const engine = opts.engine ?? 'podman';
1408
1466
  // The pre-flight narrates the build and the pull itself, so this only has
1409
1467
  // to cover the silence before it: installing, and starting a machine.
@@ -1413,15 +1471,7 @@ async function probeSandbox(config, build, opts, add) {
1413
1471
  }
1414
1472
  catch (err) {
1415
1473
  if (err instanceof BuildError) {
1416
- const rel = config.sandbox?.build?.dockerfile ?? 'the Dockerfile';
1417
- add({
1418
- severity: 'error',
1419
- code: 'sandbox.build',
1420
- where: 'sandbox.build.dockerfile',
1421
- message: `${rel} does not build: ${err.hint ?? reason(err)}`,
1422
- fix: 'run the build by hand to see the whole log',
1423
- });
1424
- return false;
1474
+ return unbuilt(err);
1425
1475
  }
1426
1476
  // A laptop with no container engine is not a broken project, and this
1427
1477
  // report is most valuable on exactly that laptop.
@@ -1435,23 +1485,17 @@ async function probeSandbox(config, build, opts, add) {
1435
1485
  return false;
1436
1486
  }
1437
1487
  const root = realpathSync(mkdtempSync(join(tmpdir(), 'zen-check-')));
1438
- const box = new Sandbox({
1439
- root,
1440
- key: 'check',
1441
- image,
1442
- cpus: config.sandbox?.cpus,
1443
- memory: config.sandbox?.memory,
1444
- network: config.sandbox?.network,
1445
- workdir: config.sandbox?.workdir,
1446
- user: config.sandbox?.user,
1447
- engine,
1448
- exec: opts.exec,
1449
- // Not the project's: a check forwards no host values, and keeping the
1450
- // container is the caller's choice about their work, not about this.
1451
- env: {},
1452
- persist: false,
1453
- });
1454
- opts.onProgress?.(`starting ${image ?? 'the container'}`);
1488
+ try {
1489
+ const box = new PodmanSandbox({ ...spec, root }, { engine, exec: opts.exec });
1490
+ return await smoke(box, image ?? 'the container', opts, add);
1491
+ }
1492
+ finally {
1493
+ rmSync(root, { recursive: true, force: true });
1494
+ }
1495
+ }
1496
+ /** Writes a file in the sandbox's workspace and reads it back, then closes it. */
1497
+ async function smoke(box, image, opts, add) {
1498
+ opts.onProgress?.(`starting ${image}`);
1455
1499
  try {
1456
1500
  const res = await box.exec([
1457
1501
  `printf '%s\\n' ${SMOKE} > ${SMOKE}.txt`,
@@ -1483,8 +1527,7 @@ async function probeSandbox(config, build, opts, add) {
1483
1527
  return false;
1484
1528
  }
1485
1529
  finally {
1486
- await box.dispose().catch(() => undefined);
1487
- rmSync(root, { recursive: true, force: true });
1530
+ await box.close().catch(() => undefined);
1488
1531
  }
1489
1532
  }
1490
1533
  function reason(err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenera/cli",
3
- "version": "1.1.55",
3
+ "version": "1.1.57",
4
4
  "description": "Command-line front end for @zenera/neo: agentic projects you can run, share and commit.",
5
5
  "keywords": [
6
6
  "agents",
@@ -54,9 +54,9 @@
54
54
  "@google/genai": "^2.30.0",
55
55
  "@inkjs/ui": "^2.0.0",
56
56
  "@openrouter/sdk": "^1.4.25",
57
- "@zenera/engine": "^1.1.55",
58
- "@zenera/neo": "^1.1.55",
59
- "@zenera/view": "^1.1.55",
57
+ "@zenera/engine": "^1.1.57",
58
+ "@zenera/neo": "^1.1.57",
59
+ "@zenera/view": "^1.1.57",
60
60
  "google-auth-library": "^10.0.0",
61
61
  "ink": "^7.1.1",
62
62
  "openai": "^6.0.0",
@@ -128,9 +128,9 @@ reports the first as `memory.uninstructed` and the second as `rules.stale` -
128
128
  by bytes, so trailing whitespace inside a table, invisible on screen, is caught
129
129
  too - and `zen check --fix` repairs both.
130
130
 
131
- Nothing else tells a running agent how the store works, so without it nothing
132
- forbids an agent from pointing `grep` or `cat` at `/memory` - a read that
133
- bypasses the audience mask and serves superseded nodes as current. Leave the
131
+ Nothing else tells a running agent how the store works, so without it an agent
132
+ guesses at paths for remembered files instead of copying them into the workspace
133
+ with `memory_copy_file`, and treats a stale recollection as current. Leave the
134
134
  file untouched and put this project's own memory policy in a second topic file,
135
135
  `agents/memory-policy-instructions.md`, which is read straight after it: then
136
136
  `zen check --fix` can replace the first after any upgrade without losing
@@ -381,10 +381,10 @@ it. Its entire world is the tools it was granted (§3.5) and four paths:
381
381
  | `/workspace` | the session's workspace - the work itself | read/write; `zen run --read-only` withholds the writes |
382
382
  | `/assets` | `assets/`, reference material - §3.11 | read-only |
383
383
  | `/skills` | the whole skill catalog - §3.4.1 | read-only |
384
- | `/memory` | files carried by remembered nodes - §5.3 | read-only, and only when `memory:` is configured |
385
384
 
386
385
  Commands run inside the container `sandbox:` describes (§3.7): the same
387
- `/workspace`, and whatever the image ships.
386
+ `/workspace`, and whatever the image ships. Remembered files are not mounted
387
+ anywhere: an agent copies one into `/workspace` with `memory_copy_file` (§5.3).
388
388
 
389
389
  Everything else in the project directory is **invisible at run time** -
390
390
  `agents.yaml`, `agents/instructions.md`, `agents/prompts/`, `agents/skills/`
@@ -413,8 +413,9 @@ Run this over every `agents/*instructions.md`, every `agents/prompts/*.md` and
413
413
  every `agents/skills/*/SKILL.md` after editing any of them. Every path-shaped
414
414
  token in those files is read by a model as an instruction to open something:
415
415
 
416
- - [ ] Every absolute path begins `/workspace`, `/assets`, `/skills` or
417
- `/memory`. Nothing else exists.
416
+ - [ ] Every absolute path begins `/workspace`, `/assets` or `/skills`. Nothing
417
+ else exists - remembered files included; they reach the workspace through
418
+ `memory_copy_file`.
418
419
  - [ ] No project file is named: `agents.yaml`, `agents/instructions.md`,
419
420
  `agents/prompts/…`, `agents/skills/…`, `sandbox/Dockerfile`, `.env`,
420
421
  `.github/…`, `sessions/…`, `SPECIFICATION.md`, `README.md`, `docs/…`.
@@ -426,8 +427,8 @@ token in those files is read by a model as an instruction to open something:
426
427
  - [ ] A skill referring to its own sibling file writes the full
427
428
  `/skills/<name>/` prefix, not `./rates.csv`: the body is rendered into a
428
429
  prompt, not executed from its folder.
429
- - [ ] `/memory` is named only in prompts for agents that have `memory:` (§5.3),
430
- and `/assets` only where an `assets/` directory exists.
430
+ - [ ] `memory_copy_file` is named only in prompts for agents that have
431
+ `memory:` (§5.3), and `/assets` only where an `assets/` directory exists.
431
432
  - [ ] The agent holding the prompt has the tool the path implies - `read_file`
432
433
  to open one, `sandbox:*` to run one (§3.4.1).
433
434
  - [ ] Every instruction that opens a file states what to do when it is not there
@@ -1031,22 +1032,9 @@ prompt is executed on every run, by an agent that is root in a filesystem that
1031
1032
  is about to be thrown away.
1032
1033
 
1033
1034
  Agents share one container, because they share the workspace and a hand-off is
1034
- meant to be continuous. An agent that needs something else says so and gets its
1035
- own, with its block merged over the top-level one:
1036
-
1037
- ```yaml
1038
- sandbox:
1039
- image: docker.io/library/python:3.14-slim-bookworm
1040
-
1041
- agents:
1042
- - name: builder
1043
- tools: [files:*, sandbox:*]
1044
- sandbox:
1045
- image: docker.io/library/node:22-bookworm-slim
1046
- memory: 8192
1047
- - name: analyst
1048
- tools: [files:*, sandbox:*] # shares the project's container
1049
- ```
1035
+ meant to be continuous. There is one `sandbox:` block, at the top level; an
1036
+ agent cannot have its own (`agents[].sandbox` fails to load). A tool one agent
1037
+ needs goes into the project's image, so every agent has it.
1050
1038
 
1051
1039
  **Write `persist: true` unless you have a reason not to.** By default the
1052
1040
  container is _removed_ when the session closes, and only two paths survive it:
@@ -1407,7 +1395,7 @@ zen check --fix
1407
1395
 
1408
1396
  It is what tells the agent that the store is reached only through the tools, that
1409
1397
  `memory_search` clips a node's text and `memory_load` reads it whole, that a
1410
- remembered file's path comes from `memory_load` and not from listing `/memory`,
1398
+ remembered file is run by copying it into the workspace with `memory_copy_file`,
1411
1399
  what a node must carry to be worth having, and that a correction is a
1412
1400
  `SUPERSEDES` edge rather than an edit. It is its own file rather than a section of
1413
1401
  `agents/instructions.md` because it arrives with the `memory:` block and leaves
@@ -1431,7 +1419,7 @@ persist. Anything authoritative - a rate, a policy clause, a procedure - belongs
1431
1419
  in a skill, where it is versioned and reviewable.
1432
1420
 
1433
1421
  The full treatment - kinds and relations, how ranking and stitching spend their
1434
- budget, remembered files under `/memory`, audience design, and how to put memory
1422
+ budget, remembered files and `memory_copy_file`, audience design, and how to put memory
1435
1423
  in front of a `zen rag` index - is in the `zen-memory` skill.
1436
1424
 
1437
1425
  ### 5.4 Cache discipline
@@ -1979,8 +1967,7 @@ Before finishing any change here:
1979
1967
  candidates; these are the judgements to make about each one)**
1980
1968
 
1981
1969
  - [ ] Every absolute path in `agents/*instructions.md`, `agents/prompts/*.md` and
1982
- `agents/skills/*/SKILL.md` is under `/workspace`, `/assets`, `/skills` or
1983
- `/memory`
1970
+ `agents/skills/*/SKILL.md` is under `/workspace`, `/assets` or `/skills`
1984
1971
  - [ ] No prompt or skill names a project file - `agents.yaml`, a prompt path, a
1985
1972
  skill's repository path, `sandbox/Dockerfile`, `.env`, `sessions/`
1986
1973
  - [ ] No `../`, `~`, or host path; nothing assumes the workspace is the project
@@ -2089,7 +2076,7 @@ candidates; these are the judgements to make about each one)**
2089
2076
  | Fails only on genuinely hard cases | Promote that agent's tier, or split the hard path out |
2090
2077
  | Shows no reasoning while it works | Turn summaries on for that model - §7.6 |
2091
2078
  | Forgets across conversations | Continue the session rather than starting a new one |
2092
- | Greps `/memory` or queries `memory.db` | `agents/memory-instructions.md` is missing the block - §5.3 |
2079
+ | Guesses a path for a remembered file | `agents/memory-instructions.md` is missing the block - §5.3 |
2093
2080
  | Recalls a note it cannot check or continue | Same block: it is what requires provenance on every node - §5.3 |
2094
2081
  | Breaks at load with a named path | Read the message - it names the exact key |
2095
2082
 
@@ -268,7 +268,8 @@ steps 2-3. Otherwise work through these with node ids:
268
268
  memory (`--dir <memory dir>`). Today's results are only a findability
269
269
  probe: memory may have changed since the run. Do not claim a hit was
270
270
  available then, or memory was empty then, without historical evidence.
271
- 5. **Wrong channel.** Any `run_command` or file tool touching `/memory` breaks
271
+ 5. **Wrong channel.** A remembered file is reached only by `memory_copy_file`;
272
+ a `run_command` or file tool guessing a path for one breaks
272
273
  `agents/memory-instructions.md`.
273
274
 
274
275
  ### Memory - saved correctly
@@ -9,26 +9,27 @@ answers once on stdout and exits.
9
9
 
10
10
  ## Options
11
11
 
12
- | Flag | What it does |
13
- | ----------------------- | -------------------------------------------------------- |
14
- | `--project <name\|dir>` | Which project. Inferred from the directory otherwise |
15
- | `--session <id>` | Continue a particular session |
16
- | `--new` | Start a new session rather than continuing one |
17
- | `--input <file>` | Read the whole request from JSON; `-` is stdin |
18
- | `--workspace <dir>` | What the agent may read and write |
19
- | `--here` | `--workspace` with the directory you are in |
20
- | `--memory <dir>` | Where the agents remember into, instead of the project's |
21
- | `--memory-read-only` | Recall from it; write nothing back |
22
- | `--model <ref>` | Override the default model for this run |
23
- | `--image <ref>` | Override the container image commands run in |
24
- | `--read-only` | Withhold every tool that can write |
25
- | `--as <user>` | Act for this user - see below |
26
- | `--plain` | Never open the TUI; a prompt is then required |
27
- | `--theme <dark\|light>` | Palette for the TUI; `auto` detects. `$ZENERA_THEME` |
28
- | `--out <file>` | Put the answer in this file instead of on stdout |
29
- | `--batch-dir <dir>` | Where a batch's runs live. `<project>/batches/<stamp>` |
30
- | `--concurrency <n>` | How many of a batch run at once. Default 16, most 32 |
31
- | `--yes` | Say yes to the workspace and install questions |
12
+ | Flag | What it does |
13
+ | ----------------------- | --------------------------------------------------------- |
14
+ | `--project <name\|dir>` | Which project. Inferred from the directory otherwise |
15
+ | `--session <id>` | Continue a particular session |
16
+ | `--new` | Start a new session rather than continuing one |
17
+ | `--input <file>` | Read the whole request from JSON; `-` is stdin |
18
+ | `--workspace <dir>` | What the agent may read and write |
19
+ | `--here` | `--workspace` with the directory you are in |
20
+ | `--memory <dir>` | Where the agents remember into, instead of the project's |
21
+ | `--memory-read-only` | Recall from it; write nothing back |
22
+ | `--model <ref>` | Override the default model for this run |
23
+ | `--image <ref>` | Override the container image commands run in |
24
+ | `--podman` | Podman here, even when a `ZEN_PLUGINS` plugin provides it |
25
+ | `--read-only` | Withhold every tool that can write |
26
+ | `--as <user>` | Act for this user - see below |
27
+ | `--plain` | Never open the TUI; a prompt is then required |
28
+ | `--theme <dark\|light>` | Palette for the TUI; `auto` detects. `$ZENERA_THEME` |
29
+ | `--out <file>` | Put the answer in this file instead of on stdout |
30
+ | `--batch-dir <dir>` | Where a batch's runs live. `<project>/batches/<stamp>` |
31
+ | `--concurrency <n>` | How many of a batch run at once. Default 16, most 32 |
32
+ | `--yes` | Say yes to the workspace and install questions |
32
33
 
33
34
  Flags always beat the file: the repository states intent, the invocation
34
35
  overrides it.
@@ -25,6 +25,7 @@ doing it deliberately - before a demo, in CI, or when diagnosing.
25
25
  | `--once` | `top`: print one report instead of the live screen |
26
26
  | `--interval <seconds>` | `top`: how often the live screen refreshes (default 2) |
27
27
  | `--brief` | `top`: the figures without the notes saying what they mean |
28
+ | `--podman` | Podman here, even when a plugin provides the sandbox |
28
29
 
29
30
  `top` draws a live screen only when a person is at a terminal. From an agent,
30
31
  a script or with `--json` it measures twice a second apart (cpu needs an
@@ -38,6 +39,11 @@ The engine is Podman. On macOS a machine has to exist and be running; `up`
38
39
  offers to install and start one, and its size follows the project's `cpus` and
39
40
  `memory`.
40
41
 
42
+ A plugin named in `$ZEN_PLUGINS` can run sandboxes somewhere else - a sandbox
43
+ service. Then `zen run` and `zen check` use it, the line under the session says
44
+ `sandbox <where>`, `status` and `clean` ask the service, and `top`, `up`, `pull`
45
+ and `disk` say they are about podman only. `--podman` goes back to this machine.
46
+
41
47
  ## Configuring it - `sandbox:` in `agents.yaml`
42
48
 
43
49
  Top level, and again per agent, where an agent's block is merged over the base.
@@ -177,8 +177,9 @@ a file short.
177
177
  ## Paths
178
178
 
179
179
  Every path-shaped token in these files is read by a model as an instruction to
180
- open something, and a running agent sees four: `/workspace`, `/assets`,
181
- `/skills`, `/memory`. The sweep is in the `zen-review` skill:
180
+ open something, and a running agent sees three: `/workspace`, `/assets`,
181
+ `/skills`. Remembered files are not mounted; `memory_copy_file` brings one into
182
+ `/workspace`. The sweep is in the `zen-review` skill:
182
183
 
183
184
  ```sh
184
185
  .github/skills/zen-review/scripts/check-paths.sh
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: zen-memory
3
- description: Agent memory in Zenera projects - the `memory:` block and per-agent `access`/`sees`/`writes`/`autoRecall`, the five `memory_*` tools (when to use `memory_grep` instead of `memory_search`), kinds, relations and how recall ranks, inspecting a graph with `zen memory`, designing a memory strategy, `agents/memory-instructions.md` vs `agents/memory-policy-instructions.md`, remembering files under `/memory`, and putting memory in front of a `zen rag` index.
3
+ description: Agent memory in Zenera projects - the `memory:` block and per-agent `access`/`sees`/`writes`/`autoRecall`, the six `memory_*` tools (when to use `memory_grep` instead of `memory_search`), kinds, relations and how recall ranks, inspecting a graph with `zen memory`, designing a memory strategy, `agents/memory-instructions.md` vs `agents/memory-policy-instructions.md`, remembering files and copying them back with `memory_copy_file`, and putting memory in front of a `zen rag` index.
4
4
  user-invocable: false
5
5
  ---
6
6
 
@@ -120,8 +120,8 @@ are the same result - and the second is what you need when the question is
120
120
  whether a host, a flag or a command was already written down. Grep reads the
121
121
  text, the metadata and the bytes of remembered files, applies the mask, leaves
122
122
  out superseded nodes unless asked, and names any file it could not read. It is
123
- also what an agent is supposed to reach for instead of running a shell `grep`
124
- over `/memory`, which the house rules forbid.
123
+ also what an agent is supposed to reach for instead of looking for the files
124
+ some other way: they are never mounted, so the tools are the only way in.
125
125
 
126
126
  It is not a diagnostic instrument, though - it is ordinary retrieval, and an
127
127
  agent is expected to reach for it mid-run as readily as for search. The line
@@ -160,7 +160,7 @@ later.
160
160
  | `plan` | an approach that worked, worth reusing on a similar request |
161
161
  | `fact` | a durable truth about the environment or the domain |
162
162
  | `snippet` | a short piece of code or configuration, too small to be a file |
163
- | `file` | an artifact kept whole under `/memory` and re-runnable |
163
+ | `file` | an artifact kept whole, to copy back and run again |
164
164
  | `operation` | an external call that was made - an endpoint, command or query |
165
165
  | `preference` | a standing instruction from the user that applies to every run |
166
166
 
@@ -225,8 +225,9 @@ below.
225
225
 
226
226
  Several runs may read and write one memory at once, and a run killed mid-write
227
227
  leaves the last commit intact. It is committed with the project - everything
228
- but `memory.db-wal`/`memory.db-shm`, which are runtime state. Only `files/` is
229
- mounted, **read-only**, at `/memory` in the agent's namespace. A memory from an
228
+ but `memory.db-wal`/`memory.db-shm`, which are runtime state. Nothing here is
229
+ mounted into the sandbox: a remembered file reaches the workspace only as a copy
230
+ made by `memory_copy_file`. A memory from an
230
231
  older `zen` (`graph.json`, `vectors.f32`) is refused until converted once with
231
232
  `zen memory migrate`.
232
233
 
@@ -386,18 +387,16 @@ a `file` argument on a node instead, and copies the **bytes** out:
386
387
  ```
387
388
 
388
389
  The path is the one the **file tools** use, resolved the same way. The copy
389
- lands at `<project>/memory/files/<id>.<ext>` and appears to the agent as:
390
-
391
- ```
392
- /memory/01JD9Q7X8N2K4M6P8R0T2V4W6Y.py
393
- ```
390
+ lands at `<project>/memory/files/<id>.<ext>`, and the agent knows it by that
391
+ name - `01JD9Q7X8N2K4M6P8R0T2V4W6Y.py` - and by its node id. It is not on any
392
+ path the agent can open.
394
393
 
395
394
  | Rule | Value |
396
395
  | --------- | ---------------------------------------------------------------- |
397
396
  | Size cap | 2 MiB. Over it, keep the artifact and commit a `snippet` instead |
398
397
  | Inlined | under 32 KiB - `memory_load` returns the contents |
399
- | Larger | `memory_load` returns the path; open or run it |
400
- | Mount | `/memory`, **read-only** |
398
+ | Larger | `memory_load` returns the name; `memory_copy_file` to open it |
399
+ | Mount | none - `memory_copy_file` copies into `/workspace` |
401
400
  | Extension | preserved, because it decides how the file runs and renders |
402
401
 
403
402
  ### The agent has to be able to write the file first
@@ -415,7 +414,7 @@ text no matter how much the memory design leans on `file` nodes.
415
414
  | Neither | No. Everything worth keeping has to fit on one line of `text` |
416
415
 
417
416
  The workspace is the only tree that round-trips, because it is the only
418
- writable one. `/assets`, `/skills` and `/memory` resolve as well - they are
417
+ writable one. `/assets` and `/skills` resolve as well - they are
419
418
  mounts the file tools know by name - but they are **read-only**, so nothing can
420
419
  be put there to be remembered. Every other absolute path is real to
421
420
  `run_command` and outside the workspace root, so a file written to `/tmp` comes
@@ -434,10 +433,13 @@ context ever uses workspace vocabulary and the model has no reason to prefer
434
433
  `/workspace` over `/tmp`. Either give it the file tools, or say in its prompt
435
434
  that work it means to keep goes in `/workspace`.
436
435
 
437
- Reusing one is the point of keeping it:
436
+ Reusing one is the point of keeping it. `memory_copy_file` needs only `read`
437
+ access, puts the file at `/workspace/<id>.<ext>` unless given a `to`, and will
438
+ not replace an existing file without `overwrite`:
438
439
 
439
440
  ```
440
- run_command python3 /memory/01JD9Q7X8N2K4M6P8R0T2V4W6Y.py
441
+ memory_copy_file { "id": "01JD9Q7X8N2K4M6P8R0T2V4W6Y" } → /workspace/01JD9Q7X8N2K4M6P8R0T2V4W6Y.py
442
+ run_command python3 01JD9Q7X8N2K4M6P8R0T2V4W6Y.py
441
443
  ```
442
444
 
443
445
  Which means the file has to be **self-contained**. A script that reads
@@ -445,10 +447,10 @@ Which means the file has to be **self-contained**. A script that reads
445
447
  that takes its inputs as arguments will. If it needs a credential, it should
446
448
  read it from the environment and say so in the node text.
447
449
 
448
- Nothing writes to `/memory` through the file tools, so every file under it has a
449
- node explaining what it is and the graph cannot acquire orphans. To change a
450
- remembered file: copy it into the workspace, edit it there, commit the new one
451
- and link it with `SUPERSEDES` to the old.
450
+ Only a commit puts a file in the store, so every file there has a node
451
+ explaining what it is and the graph cannot acquire orphans. The copy in the
452
+ workspace is the agent's to edit. To change a remembered file: copy it, edit the
453
+ copy, commit the new one and link it with `SUPERSEDES` to the old.
452
454
 
453
455
  The node text describes and locates; the file carries the content. Reach for a
454
456
  node with no file only when the whole of what you know fits on one line.
@@ -559,7 +561,8 @@ gets whether it loads the skill or not.
559
561
 
560
562
  **Every project that enables memory carries `agents/memory-instructions.md`**,
561
563
  as shipped by `zen`. That file is how the agent is told to use the store: read
562
- and search it only through the tools, never through `/memory` itself, and what a
564
+ and search it only through the tools, copy a file out with `memory_copy_file`
565
+ before running it, and what a
563
566
  node must carry to still be worth having.
564
567
 
565
568
  `zen init` writes it, because the projects it scaffolds have memory on from the
@@ -778,7 +781,7 @@ agents:
778
781
  | Vectors fewer than nodes | Some nodes were committed with no embedder; they are only reachable by term overlap |
779
782
  | The graph fills with restated requests | The commit rule is not in a prompt or skill. State the "would a later run redo this" test |
780
783
  | Runs do real work and the graph stays empty | The agent is bound `read`, or nothing names the moments: empty recall then work, before an answer, a handoff or a fork's return |
781
- | An agent greps `/memory` or queries `memory.db` | The house-rules block is missing from `agents/memory-instructions.md` - the system prompt never forbids it |
784
+ | An agent guesses a path for a remembered file | The house-rules block is missing from `agents/memory-instructions.md` - nothing tells it to use `memory_copy_file` |
782
785
  | A recalled fact cannot be checked or continued | Nodes were committed with no provenance. The block's "say where it came from" rule is what prevents it |
783
786
  | Recall returns pointers and the run re-reads it all | Content was committed as `text` alone. A node's text describes and locates; the content belongs in a file |
784
787
  | A wrong memory keeps coming back | It was edited instead of superseded, or superseded in the wrong direction - the **new** node is the source |
@@ -78,10 +78,10 @@ the sandbox pin. Finish setup and all edits before saving the final receipt.
78
78
 
79
79
  ### `check-paths.sh` - the §2.5 sweep
80
80
 
81
- A running agent's whole world is four paths: `/workspace`, `/assets`, `/skills`
82
- and `/memory`. Every path-shaped token in `agents/*instructions.md`,
81
+ A running agent's whole world is three paths: `/workspace`, `/assets` and
82
+ `/skills`. Every path-shaped token in `agents/*instructions.md`,
83
83
  `agents/prompts/*.md` and a skill's markdown is read by a model as an
84
- instruction to open something, so anything outside those four is an instruction
84
+ instruction to open something, so anything outside those three is an instruction
85
85
  to open a file that is not there.
86
86
 
87
87
  ```sh
@@ -6,7 +6,7 @@
6
6
  # check-paths.sh each candidate, with the file and line it is on
7
7
  # check-paths.sh raw the tokens alone, unfiltered — the sweep itself
8
8
  #
9
- # A running agent sees four paths: /workspace, /assets, /skills and /memory.
9
+ # A running agent sees three paths: /workspace, /assets and /skills.
10
10
  # Everything else printed here is either noise this script has not learned yet
11
11
  # or an instruction to open a file that is not there. There is no third case,
12
12
  # which is why this exits non-zero whenever it prints one: the list is meant to
@@ -24,9 +24,9 @@ cd "$(dirname "$0")/../../../.."
24
24
  # stray `/examples.md`, and that fragment is noise on every run of every project.
25
25
  TOKEN='[~.]?/?[A-Za-z0-9_.-]*(/[A-Za-z0-9_.*-]+)+'
26
26
 
27
- # The four mounts, and only those: a token under one of them is a path that
27
+ # The three mounts, and only those: a token under one of them is a path that
28
28
  # resolves.
29
- MOUNTS='^/(workspace|assets|skills|memory)(/|$)'
29
+ MOUNTS='^/(workspace|assets|skills)(/|$)'
30
30
 
31
31
  # English that happens to contain a slash, and the placeholder paths of a
32
32
  # worked example. Add to this rather than teaching a reviewer to skip the same
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: zen-sandbox
3
- description: 'How the container sandbox works, when and how to configure it in `agents.yaml` (`sandbox:` and `agents[].sandbox`), the four `sandbox:*` tools, mount layout (/workspace, $HOME, /tmp, /run/zenera/keys), lifecycle and persistence (`persist: true`), credential forwarding by name, resource ceilings (cpus, memory, pids), standard vs strict hardening profiles, path rules, and debugging container issues with `zen sandbox`. Refers to `zen-cli` (`.github/skills/zen-cli/references/sandbox.md`).'
3
+ description: 'How the container sandbox works, when and how to configure it in `agents.yaml` (the project's `sandbox:` block, one container per session), the four `sandbox:*` tools, mount layout (/workspace, $HOME, /tmp, /run/zenera/keys), lifecycle and persistence (`persist: true`), credential forwarding by name, resource ceilings (cpus, memory, pids), standard vs strict hardening profiles, path rules, and debugging container issues with `zen sandbox`. Refers to `zen-cli` (`.github/skills/zen-cli/references/sandbox.md`).'
4
4
  user-invocable: false
5
5
  ---
6
6
 
@@ -95,7 +95,6 @@ Inside the container, paths are isolated to designated mount points:
95
95
  | `/workspace` | Session workspace | read-write* | The work itself. Changes survive session completion. |
96
96
  | `/home/agent` | `.data/sandbox/home` | read-write | User home (`$HOME`). Persists across sessions. |
97
97
  | `/tmp` | In-memory / host tmpfs | read-write | Ephemeral scratch; holds `/tmp/zenera-jobs`. |
98
- | `/memory` | Session memory directory | read-only | Generated memory files (when `memory:` is enabled). |
99
98
  | `/assets` | Project assets directory | read-only | Reference assets declared in `SPECIFICATION.md`. |
100
99
  | `/skills` | Project skills directory | read-only | Custom skill files available to agents. |
101
100
  | `/run/zenera/keys` | Keychain / temp directory | read-only | Forwarded file credentials (e.g. Vertex service keys). |
@@ -138,7 +137,7 @@ zn-<key>-<digest>
138
137
 
139
138
  ## 5. Configuring `sandbox:` in `agents.yaml`
140
139
 
141
- Configured at the top level and optionally overridden per agent under `agents[].sandbox`:
140
+ Configured once, at the top level. Every agent in a session shares the one container; `agents[].sandbox` was removed and fails to load:
142
141
 
143
142
  ```yaml
144
143
  sandbox:
@@ -151,15 +150,6 @@ sandbox:
151
150
  hardening: standard
152
151
  env: [HTTPS_PROXY, NO_PROXY]
153
152
  keys: true
154
-
155
- agents:
156
- - name: builder
157
- # Inherits base sandbox configuration
158
-
159
- - name: isolated-runner
160
- sandbox:
161
- hardening: strict
162
- network: none
163
153
  ```
164
154
 
165
155
  ### Configuration Fields
@@ -247,11 +237,10 @@ Every container runs with baseline safety controls:
247
237
 
248
238
  ---
249
239
 
250
- ## 8. Multi-Agent Sandboxes (`SandboxPool`)
240
+ ## 8. One Sandbox per Session
251
241
 
252
- - Two agents with identical sandbox configurations share the **same container**.
253
- - Two agents with different images or configurations receive separate containers.
254
- - The `sandbox:*` tool definitions remain uniform across the session; when an agent calls a tool, the pool routes the call to that specific agent's container at invocation time.
242
+ - Every agent in a session runs in the **same container** and sees the same `/workspace`.
243
+ - A tool only one agent needs still goes in the project's image; there is no per-agent sandbox.
255
244
 
256
245
  ---
257
246
 
@@ -603,8 +603,9 @@
603
603
  "oneOf": [{ "type": "boolean" }, { "$ref": "#/$defs/memoryBinding" }]
604
604
  },
605
605
  "sandbox": {
606
- "description": "Overrides on the project's sandbox. An agent that overrides nothing shares the container with everyone else; one that names its own image gets its own.",
607
- "$ref": "#/$defs/sandbox"
606
+ "description": "Removed: a session has one sandbox, the project's, shared by every agent.",
607
+ "deprecationMessage": "Per-agent sandboxes were removed — move these settings to the project's top-level `sandbox:`.",
608
+ "not": {}
608
609
  },
609
610
  "default": {
610
611
  "description": "The entry point, when no top-level `default:` names one.",
@@ -87,7 +87,8 @@ Use `copy_file` to duplicate a file, never `read_file` + `write_file`. The bytes
87
87
  conversation, so there is no size cap and binaries arrive intact.
88
88
 
89
89
  - The source may be in a read-only mount; only the destination must be writable.
90
- This is how something under `/assets`, `/skills` or `/memory` reaches `/workspace`.
90
+ This is how something under `/assets` or `/skills` reaches `/workspace`. Remembered
91
+ files are not mounted; `memory_copy_file` brings one into the workspace.
91
92
  - Set `overwrite: true` only when intentionally replacing an existing destination.
92
93
  - Copying a directory and its contents requires `recursive: true`.
93
94
 
@@ -103,6 +104,6 @@ All file operations are confined to mounted trees:
103
104
 
104
105
  - `/workspace`: The primary writable directory for the project. Paths inside the workspace
105
106
  (such as `/workspace/src/main.ts`) are where project files reside.
106
- - `/assets`, `/skills`, `/memory`: Read-only mounts. You may read, list, and search them,
107
+ - `/assets`, `/skills`: Read-only mounts. You may read, list, and search them,
107
108
  but you cannot write, move, or delete files inside them.
108
109
  - Any attempt to reach outside these mounts fails with a containment error.
@@ -71,9 +71,10 @@ above produced it, `←informed` means it informed the line above.
71
71
  background. A `+` reference points to an id already shown above.
72
72
 
73
73
  Node text is clipped to 160 characters. A file node adds one line with its
74
- `/memory/<id>.<ext>` path, size, and use count. Use `memory_load` to obtain the
75
- complete node and its usable path. Touch only paths returned by a `memory_*`
76
- tool.
74
+ `<id>.<ext>` name, size, and use count. Use `memory_load` to obtain the
75
+ complete node; a small file comes back inline. To open or run a remembered
76
+ file, copy it into the workspace with `memory_copy_file`, then use the path it
77
+ returns. Remembered files are not on any mounted path.
77
78
 
78
79
  Direct store access is prohibited because it bypasses audience controls, may
79
80
  serve superseded nodes, does not record use, and can race with another writer.
@@ -93,7 +94,7 @@ inputs, outputs, and credentials handling.
93
94
  ### Keep memory out of ordinary answers
94
95
 
95
96
  Report findings and checkable sources, not the mechanism that found them. Do
96
- not expose `/memory` paths, node ids, or say that something was recalled or
97
+ not expose remembered file names, node ids, or say that something was recalled or
97
98
  remembered. The exception is a request about the store itself, where ids and
98
99
  memory state are the subject.
99
100
 
@@ -208,8 +209,9 @@ of living project files.
208
209
 
209
210
  Put provenance in the file itself as a short header. Make executable artifacts
210
211
  self-contained, take request-specific values as arguments, read credentials
211
- from the environment, and accept an output path under `/workspace`. The
212
- `/memory` mount is read-only.
212
+ from the environment, and accept an output path under `/workspace`. A later run
213
+ reaches the script only through `memory_copy_file`, so it must not depend on
214
+ where it was stored.
213
215
 
214
216
  Commit a script only after it ran successfully against the intended environment
215
217
  and produced verified output. Commit its invocation and operations, not its
@@ -18,8 +18,34 @@ COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
18
18
  RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
19
19
  && ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
20
20
 
21
- # Keep the heavyweight provider SDKs cached when the pinned CLI release changes.
22
- RUN npm install -g @anthropic-ai/sdk @google/genai @openrouter/sdk openai
21
+ # Keep the third-party dependencies of @zenera/{cli,engine,neo,rag,view} cached
22
+ # when the pinned CLI release changes. Keep in sync with their package.json files.
23
+ RUN npm install -g \
24
+ "@anthropic-ai/sdk@^0.120.0" \
25
+ "@apidevtools/swagger-parser@^12.0.0" \
26
+ "@google/genai@^2.30.0" \
27
+ "@inkjs/ui@^2.0.0" \
28
+ "@lancedb/lancedb@^0.38.0" \
29
+ "@openrouter/sdk@^1.4.25" \
30
+ "@types/hast@^3.0.5" \
31
+ "google-auth-library@^10.0.0" \
32
+ "graphology@^0.26.0" \
33
+ "ink@^7.1.1" \
34
+ "lowlight@^3.3.0" \
35
+ "mermaid@^12.2.0" \
36
+ "openai@^6.0.0" \
37
+ "react@^19.2.8" \
38
+ "rehype-sanitize@^6.0.0" \
39
+ "rehype-slug@^6.0.0" \
40
+ "remark-frontmatter@^5.0.0" \
41
+ "remark-gfm@^4.0.1" \
42
+ "remark-parse@^11.0.0" \
43
+ "remark-rehype@^11.1.2" \
44
+ "unified@^11.0.5" \
45
+ "yaml@^2.9.1" \
46
+ "yauzl@^3.4.0" \
47
+ "yazl@^3.3.1" \
48
+ "zod@^4.6.7"
23
49
 
24
50
  # Pinned to the `zen` that wrote this file, so the tools in the container are
25
51
  # the ones the session outside it was built by. Bump both together.