@zenera/cli 1.1.56 → 1.1.58

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;
package/dist/batch.js CHANGED
@@ -221,6 +221,7 @@ async function runItem(item, ctx) {
221
221
  memoryDir: ctx.memory,
222
222
  memoryReadOnly: ctx.memoryReadOnly,
223
223
  keys: ctx.opts.keys,
224
+ sandboxPlugins: ctx.opts.sandboxPlugins,
224
225
  user: ctx.opts.user,
225
226
  yes: true,
226
227
  // The project's own problems are the batch's, not each item's.
@@ -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
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.sandbox.name });
22
- READY.add(setup.image);
23
28
  }
24
29
  //# sourceMappingURL=sandbox.js.map
package/dist/tui/links.js CHANGED
@@ -1,15 +1,20 @@
1
- import { statSync } from 'node:fs';
1
+ import { realpathSync, statSync } from 'node:fs';
2
+ import { basename, dirname, join, sep } from 'node:path';
2
3
  import { pathToFileURL } from 'node:url';
3
4
  /** Exactly the trees the file tools reach, under the same containment rule. */
4
5
  export function mountsOf(files) {
5
6
  const names = [...(files.mount ? [files.mount] : []), ...files.mounts.map((m) => m.at)];
7
+ // A link is drawn while the text is, so this answers synchronously — the
8
+ // terminal is on this machine, so its disk can be asked directly — and a
9
+ // symlink out of a tree is no more a link than it is a file the tools reach.
10
+ const trees = [files.root, ...files.mounts.map((m) => m.host)].map(real);
6
11
  const resolve = (path) => {
7
- try {
8
- return files.within(path);
9
- }
10
- catch {
12
+ const host = files.hostOf(path);
13
+ if (!host) {
11
14
  return undefined;
12
15
  }
16
+ const at = real(host);
17
+ return trees.some((t) => at === t || at.startsWith(t + sep)) ? at : undefined;
13
18
  };
14
19
  return {
15
20
  names: names.sort((a, b) => b.length - a.length),
@@ -20,6 +25,24 @@ export function mountsOf(files) {
20
25
  },
21
26
  };
22
27
  }
28
+ /** The path with the symlinks in its existing part resolved, the rest appended. */
29
+ function real(path) {
30
+ const missing = [];
31
+ let at = path;
32
+ for (;;) {
33
+ try {
34
+ return join(realpathSync(at), ...missing.reverse());
35
+ }
36
+ catch {
37
+ const up = dirname(at);
38
+ if (up === at) {
39
+ return path;
40
+ }
41
+ missing.push(basename(at));
42
+ at = up;
43
+ }
44
+ }
45
+ }
23
46
  const FILE = 'file://';
24
47
  /** Prose punctuation that ends a sentence, not a path. */
25
48
  const TRAILING = /[.,;:!?'"]+$/;
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, PodmanSandbox, WORKSPACE_MOUNT, 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
  }
@@ -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,21 +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 PodmanSandbox({
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
- // Not the project's: a check forwards no host values, and keeping the
1448
- // container is the caller's choice about their work, not about this.
1449
- env: {},
1450
- persist: false,
1451
- }, { engine, exec: opts.exec });
1452
- 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}`);
1453
1499
  try {
1454
1500
  const res = await box.exec([
1455
1501
  `printf '%s\\n' ${SMOKE} > ${SMOKE}.txt`,
@@ -1482,7 +1528,6 @@ async function probeSandbox(config, build, opts, add) {
1482
1528
  }
1483
1529
  finally {
1484
1530
  await box.close().catch(() => undefined);
1485
- rmSync(root, { recursive: true, force: true });
1486
1531
  }
1487
1532
  }
1488
1533
  function reason(err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenera/cli",
3
- "version": "1.1.56",
3
+ "version": "1.1.58",
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.56",
58
- "@zenera/neo": "^1.1.56",
59
- "@zenera/view": "^1.1.56",
57
+ "@zenera/engine": "^1.1.58",
58
+ "@zenera/neo": "^1.1.58",
59
+ "@zenera/view": "^1.1.58",
60
60
  "google-auth-library": "^10.0.0",
61
61
  "ink": "^7.1.1",
62
62
  "openai": "^6.0.0",
@@ -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.