@0perator/operator 0.1.153 → 0.1.155

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/CHANGELOG.md CHANGED
@@ -4,6 +4,32 @@ Operator is AXE's terminal coding agent (npm `@0perator/operator`), running on A
4
4
  Newest first. Every release bumps `src/cli.tsx` VERSION + `package.json`, adds an entry here, and ships to
5
5
  npm + both git remotes (memjar/kode, axetechnologies/kode). Test counts are the full suite at that release.
6
6
 
7
+ ## 0.1.155 — 2026-09-29 — sandbox: Linux bubblewrap parity (sandboxed-exec Phase 2)
8
+ - `KODE_SANDBOX=workspace|strict` now sandboxes shell execution on **Linux** (bubblewrap), not just macOS
9
+ (seatbelt). `hasSandboxExec()` is darwin-only, so on the Linux fleet (jl2/jl3/AXeServer/droplets)
10
+ `wrapShell` fell through to plain bash — the modes were a **silent no-op** there. New `hasBubblewrap()`
11
+ (Linux-only) + `bwrapArgs(mode)` map the SAME `DENY_WRITE`/`SECRET_READ` lists + allow-roots to bwrap
12
+ bind-mount namespaces (protected paths → `--ro-bind`, secrets → `--tmpfs`/`/dev/null` mask, strict →
13
+ whole-FS `--ro-bind / /` + writable allow-roots + `--unshare-net`). `wrapShell`/`wrapInteractiveShell`
14
+ try seatbelt → bwrap → plain bash; **macOS behavior unchanged** (seatbelt still wins). Absent on thin
15
+ images (Alpine) → falls back to plain bash, JS write-guards still apply. **Runtime-validated on a real
16
+ Linux node** (Ubuntu 24.04, bubblewrap 0.9.0, canary-only, pkg purged): strict masks secret reads + cuts
17
+ network + confines writes; workspace allows network but keeps secret masking + protected-path read-only.
18
+ Design + validation: `_ai-docs/architecture/sandboxed-code-execution.md`; decision:
19
+ `_ai-docs/decisions/2026-09-29-linux-bubblewrap.md`. Suite 703 green (+4).
20
+
21
+ ## 0.1.154 — 2026-09-29 — engine: per-session persistent shell (sandboxed-exec Phase 1)
22
+ - The `bash`/`shell_exec` persistent shell is now **per session**, not one process-wide singleton. Before, the
23
+ foreground and every background sub-agent shared ONE bash: a sub-agent's `cd`/`export` corrupted the
24
+ foreground's cwd/env (and vice versa — proven live on JL1), and every command head-of-line-blocked every other
25
+ session on the one FIFO. Now the `Executor` carries a stable per-session `shellKey` (the session's `sessionId`,
26
+ else a unique `exec-N` fallback so two keyless lanes never collide) through tool execution via an
27
+ `AsyncLocalStorage`; the registry keys `ShellSession` by it, and a sub-agent disposes its shell on completion.
28
+ Default (`KODE_SANDBOX=off`) behavior is **byte-identical** — this is the correctness fix + prerequisite for
29
+ the sandboxed-exec tiers, no sandbox change yet. Design + JL1 validation:
30
+ `_ai-docs/architecture/sandboxed-code-execution.md`; decision: `_ai-docs/decisions/2026-09-29-per-session-shell.md`.
31
+ Suite 699 green (+5). Also: releases now publish to **npmjs** (private) instead of pkg.axe.onl (`publishConfig`).
32
+
7
33
  ## 0.1.153 — 2026-09-29 — speed: KV prefix-cache reuse (`cache_prompt: true`) — fixes slow compaction
8
34
  - Every Aurora request now sends `cache_prompt: true`. Without it the single-slot llama.cpp server RE-PREFILLED
9
35
  the whole growing prefix (system + tools + history) each round, and re-prefilled the full evicted span on every
@@ -324,6 +324,12 @@ export class BackgroundAgents {
324
324
  this.onDone(info, `[${id} error: ${e instanceof Error ? e.message : String(e)}]`);
325
325
  }
326
326
  finally {
327
+ // Kill this sub-agent's own persistent shell so its bash doesn't linger for the whole parent
328
+ // session (each session now gets its OWN shell; without this they'd accumulate). Best-effort.
329
+ try {
330
+ session.disposeShell();
331
+ }
332
+ catch { /* shell may never have started */ }
327
333
  // This agent set itself idle/stopped above, freeing a slot — promote the next queued agent.
328
334
  this.pump();
329
335
  }
package/dist/session.js CHANGED
@@ -14,7 +14,7 @@ import { AuroraRouter } from "./router/router.js";
14
14
  import { operatorAgentPersona } from "./config/operator-harness.js";
15
15
  import { modelRegistry, findModel, selectModel, endpointBase, DEFAULT_MODEL_ID } from "./router/models.js";
16
16
  import { Executor } from "./tools/executor.js";
17
- import { toSchemas, registry } from "./tools/registry.js";
17
+ import { toSchemas, registry, disposeShellSessionKey } from "./tools/registry.js";
18
18
  import { MemoryStore } from "./memory/index.js";
19
19
  import { McpHub, withMcp } from "./mcp/index.js";
20
20
  import { withPermissions, PermissionPolicy } from "./permissions/index.js";
@@ -190,6 +190,7 @@ export class Session {
190
190
  moaConfig;
191
191
  modelId = DEFAULT_MODEL_ID; // active /model selection
192
192
  executor;
193
+ shellKey; // this session's persistent-shell key (see disposeShell)
193
194
  localSchemas;
194
195
  hub;
195
196
  tools;
@@ -237,7 +238,8 @@ export class Session {
237
238
  if (cfg.askUser)
238
239
  reg.set("ask_user", makeAskTool(cfg.askUser));
239
240
  }
240
- this.executor = new Executor(reg, cfg.cwd);
241
+ this.executor = new Executor(reg, cfg.cwd, cfg.sessionId);
242
+ this.shellKey = this.executor.shellKey; // for disposeShell() on teardown
241
243
  this.localSchemas = toSchemas(reg);
242
244
  this.inner = cfg.router ?? new AuroraRouter();
243
245
  this.router = engineRouter(this.inner);
@@ -548,9 +550,17 @@ export class Session {
548
550
  mcpServers() {
549
551
  return this.hub?.serversWithTools() ?? [];
550
552
  }
551
- /** Tear down session resources (kills any spawned stdio MCP servers). Call on shell exit. */
553
+ /** Tear down session resources (kills any spawned stdio MCP servers + this session's persistent
554
+ * shell). Call on shell exit. */
552
555
  shutdown() {
553
556
  this.hub?.shutdown();
557
+ this.disposeShell();
558
+ }
559
+ /** Kill just this session's persistent shell — call when a background sub-agent finishes so its
560
+ * bash doesn't linger for the whole parent session. Safe to call more than once; a no-op if the
561
+ * shell was never started. Does NOT touch the shared MCP hub (a sub-agent may share it). */
562
+ disposeShell() {
563
+ disposeShellSessionKey(this.shellKey);
554
564
  }
555
565
  /** Store a durable memory note (for /remember and end-of-session capture). Best-effort. */
556
566
  remember(text, tags) {
@@ -10,6 +10,7 @@
10
10
  // doesn't bleed across turns)
11
11
  import { isAbsolute, join } from "node:path";
12
12
  import { registry } from "./registry.js";
13
+ import { shellKeyStore } from "./shell-context.js";
13
14
  // Re-exported for back-compat (existing importers reach it via executor.js) — moved to its own
14
15
  // file since it's a pure helper with no node deps; see result-cap.ts for why that separation matters.
15
16
  import { capToolResult } from "./result-cap.js";
@@ -38,14 +39,25 @@ export function rootArgs(name, args, root) {
38
39
  const LOOP_GUARD_THRESHOLD = 5; // must match agent.ts LOOP_GUARD_LIMIT so this secondary guard never fires first
39
40
  import { MUTATING_TOOLS } from "./mutating.js"; // single source of truth (see tools/mutating.ts) — a workspace edit ⇒ prior identical-call counts are stale
40
41
  const LOOP_GUARD_EXEMPT = new Set(["agent_status", "bash_output"]); // poll/status tools — repeated calls are legit, never guarded
42
+ // Unique fallback id per Executor instance, so two sessions with no sessionId and no root (the
43
+ // foreground and a read-only sub-agent lane) still get DISTINCT shell keys. One Executor lives for
44
+ // its session's whole lifetime (the Session is constructed once and reused across turns), so this id
45
+ // is stable across a session's turns — the persistent shell survives, keyed per session, not shared.
46
+ let _execSeq = 0;
41
47
  export class Executor {
42
48
  reg;
43
49
  root;
50
+ /** Stable per-session key for this Executor's persistent shell (see shell-context.ts). A caller-
51
+ * supplied id (the Session's sessionId) when present, else a unique per-instance fallback. */
52
+ shellKey;
44
53
  /** @param root optional working directory to root every tool call under (a background agent's isolated
45
- * worktree) — so its file/shell mutations never touch the shared process cwd. Undefined = shared cwd. */
46
- constructor(reg = registry, root) {
54
+ * worktree) — so its file/shell mutations never touch the shared process cwd. Undefined = shared cwd.
55
+ * @param shellKey stable session id used to key this session's persistent shell; falls back to a
56
+ * unique per-instance id so distinct sessions never share (and corrupt) one shell. */
57
+ constructor(reg = registry, root, shellKey) {
47
58
  this.reg = reg;
48
59
  this.root = root;
60
+ this.shellKey = shellKey || `exec-${++_execSeq}`;
49
61
  }
50
62
  seen = new Map();
51
63
  resetTurn() {
@@ -65,7 +77,9 @@ export class Executor {
65
77
  if (!tool)
66
78
  return `error: unknown tool "${name}"`;
67
79
  try {
68
- const out = capToolResult(await tool.run(args));
80
+ // Run the tool inside THIS session's shell-key context so a persistent-shell tool (bash) picks
81
+ // this session's own ShellSession, not a process-wide singleton shared with other sub-agents.
82
+ const out = capToolResult(await shellKeyStore.run(this.shellKey, () => tool.run(args)));
69
83
  // A file edit changed the workspace, so prior identical-call counts are stale — re-running the same
70
84
  // test/build after an edit is verify-after-fix iteration, not a loop. Clear so repeats start fresh.
71
85
  if (MUTATING_TOOLS.has(name))
@@ -15,26 +15,44 @@ import { ensureSearxng, noteSearxngUsed } from "./searxng.js";
15
15
  function str(v, fallback = "") {
16
16
  return v === undefined || v === null ? fallback : String(v);
17
17
  }
18
- // One persistent shell per Operator process (frontier-grade: cwd/env/venv persist across calls,
19
- // like a real terminal — so the model sources a venv or `cd`s ONCE, not on every call). Lazily
20
- // created; survives for the process lifetime.
21
- let _shellSession = null;
18
+ // One persistent shell PER SESSION (frontier-grade: cwd/env/venv persist across calls, like a real
19
+ // terminal — so the model sources a venv or `cd`s ONCE, not on every call). Keyed by the session's
20
+ // shell key (Executor.shellKey, carried through shellKeyStore) so the foreground and each background
21
+ // sub-agent get their OWN bash — previously a single process-wide shell was shared by all, and a
22
+ // sub-agent's `cd`/`export` corrupted the foreground's cwd/env (and every command head-of-line-blocked
23
+ // every other session on one FIFO). Lazily created per key; each survives until its session disposes.
24
+ const _shells = new Map();
22
25
  async function getShellSession() {
23
- if (!_shellSession) {
24
- // Variable specifier (nodeImport), not a string literal: keeps shell-session.ts — which loads
25
- // node:child_process — OUT of the platform:neutral (mobile/JSCore) bundle's static graph. The
26
- // `as typeof import(...)` is a TYPE-ONLY annotation (erased at build), so it restores the real
27
- // types without reintroducing a static specifier esbuild would follow.
26
+ // Variable specifier (nodeImport), not a string literal: keeps these node-only modules
27
+ // (shell-context → node:async_hooks, shell-session → node:child_process) OUT of the
28
+ // platform:neutral (mobile/JSCore) bundle's static graph. The `as typeof import(...)` is a
29
+ // TYPE-ONLY annotation (erased at build), so it restores the real types without reintroducing a
30
+ // static specifier esbuild would follow.
31
+ const { shellKeyStore, DEFAULT_SHELL_KEY } = (await nodeImport("./shell-context.js"));
32
+ const key = shellKeyStore.getStore() ?? DEFAULT_SHELL_KEY;
33
+ let sess = _shells.get(key);
34
+ if (!sess) {
28
35
  const { ShellSession } = (await nodeImport("./shell-session.js"));
29
- _shellSession = new ShellSession();
36
+ sess = new ShellSession();
37
+ _shells.set(key, sess);
30
38
  }
31
- return _shellSession;
39
+ return sess;
32
40
  }
33
- /** Kill the persistent shell (and its process group) on process shutdown so it never orphans.
34
- * Wired into the CLI's exit/SIGTERM handlers — no-op if a shell was never started. */
41
+ /** Kill EVERY persistent shell (and their process groups) on process shutdown so none orphan.
42
+ * Wired into the CLI's exit/SIGTERM handlers — no-op if no shell was ever started. */
35
43
  export function disposeShellSession() {
36
- _shellSession?.dispose();
37
- _shellSession = null;
44
+ for (const sess of _shells.values())
45
+ sess.dispose();
46
+ _shells.clear();
47
+ }
48
+ /** Kill one session's persistent shell by its key (Session.disposeShell → here on sub-agent
49
+ * completion) so a long foreground session spawning many sub-agents doesn't leak idle bash processes. */
50
+ export function disposeShellSessionKey(key) {
51
+ const sess = _shells.get(key);
52
+ if (sess) {
53
+ sess.dispose();
54
+ _shells.delete(key);
55
+ }
38
56
  }
39
57
  async function shellExec(args) {
40
58
  const command = str(args.command);
@@ -179,6 +179,40 @@ export function seatbeltProfile(mode) {
179
179
  }
180
180
  return `(version 1)(allow default)(deny file-write* ${denySub} ${denyFiles})${denyRead}`;
181
181
  }
182
+ /** Bubblewrap (bwrap) argv enforcing the SAME intent as seatbeltProfile(), for the Linux fleet where
183
+ * macOS sandbox-exec doesn't exist — hasSandboxExec() hardcodes false off-darwin, so KODE_SANDBOX=
184
+ * workspace|strict was a silent no-op on Linux (jl2/jl3/AXeServer) until this. bwrap is namespace /
185
+ * bind-mount based, not a rule profile, so the same denylists map to mounts (bwrap applies them
186
+ * left-to-right, later wins): protected write-paths are re-bound read-only, secret paths are masked
187
+ * (empty tmpfs / /dev/null so reads can't exfil), and strict makes the whole FS read-only except the
188
+ * allow-roots and cuts the network. Returns the args BEFORE the `/bin/bash …` argv. Exported for unit
189
+ * tests. NOTE: kernel enforcement must be validated on a real Linux node — untestable on macOS/JL1. */
190
+ export function bwrapArgs(mode) {
191
+ const a = [];
192
+ if (mode === "strict") {
193
+ a.push("--ro-bind", "/", "/"); // whole FS read-only …
194
+ a.push("--proc", "/proc", "--dev", "/dev");
195
+ for (const root of allowedWriteRoots())
196
+ a.push("--bind-try", root, root); // … except the allow-roots
197
+ a.push("--unshare-net"); // strict: no network
198
+ }
199
+ else {
200
+ a.push("--bind", "/", "/"); // workspace: FS writable …
201
+ a.push("--proc", "/proc", "--dev", "/dev");
202
+ for (const d of DENY_WRITE_SUBPATHS)
203
+ a.push("--ro-bind-try", resolve(d), resolve(d)); // … protected dirs read-only
204
+ for (const f of DENY_WRITE_FILES)
205
+ a.push("--ro-bind-try", "/dev/null", resolve(f)); // protected files masked
206
+ }
207
+ // Read-containment (BOTH modes): mask secret dirs with an empty tmpfs, secret files with /dev/null,
208
+ // so a shell command can't read + exfil credentials. Placed last so it wins over the writable binds.
209
+ for (const d of SECRET_READ_SUBPATHS)
210
+ a.push("--tmpfs", resolve(d));
211
+ for (const f of SECRET_READ_FILES)
212
+ a.push("--ro-bind", "/dev/null", resolve(f));
213
+ a.push("--die-with-parent");
214
+ return a;
215
+ }
182
216
  let _sbExec = null; // cache: is sandbox-exec present on this host?
183
217
  async function hasSandboxExec() {
184
218
  if (_sbExec !== null)
@@ -194,13 +228,31 @@ async function hasSandboxExec() {
194
228
  return (_sbExec = false);
195
229
  }
196
230
  }
231
+ let _bwrap = null; // cache: is bubblewrap (bwrap) present on this Linux host?
232
+ async function hasBubblewrap() {
233
+ if (_bwrap !== null)
234
+ return _bwrap;
235
+ if (process.platform !== "linux")
236
+ return (_bwrap = false); // Linux-only; macOS uses sandbox-exec above
237
+ try {
238
+ const { execFile } = await import("node:child_process");
239
+ await new Promise((res, rej) => execFile("bwrap", ["--version"], (e) => (e ? rej(e) : res())));
240
+ return (_bwrap = true);
241
+ }
242
+ catch {
243
+ return (_bwrap = false); // absent (e.g. Alpine/thin images) → fall back to plain bash; JS guards still apply
244
+ }
245
+ }
197
246
  /** Wrap a shell command for `execFile` under the OS sandbox. Returns the argv to run: under an active
198
247
  * sandbox on macOS it's `sandbox-exec -p <profile> /bin/bash -c <command>`; otherwise the plain bash
199
248
  * invocation (the JS write-guards still protect the file tools). */
200
249
  export async function wrapShell(command) {
201
250
  const mode = sandboxMode();
202
- if (mode !== "off" && (await hasSandboxExec())) {
203
- return { file: "/usr/bin/sandbox-exec", args: ["-p", seatbeltProfile(mode), "/bin/bash", "-c", command] };
251
+ if (mode !== "off") {
252
+ if (await hasSandboxExec())
253
+ return { file: "/usr/bin/sandbox-exec", args: ["-p", seatbeltProfile(mode), "/bin/bash", "-c", command] };
254
+ if (await hasBubblewrap())
255
+ return { file: "bwrap", args: [...bwrapArgs(mode), "/bin/bash", "-c", command] };
204
256
  }
205
257
  return { file: "/bin/bash", args: ["-c", command] };
206
258
  }
@@ -210,8 +262,11 @@ export async function wrapShell(command) {
210
262
  * noise; the session drives framing itself with a sentinel. */
211
263
  export async function wrapInteractiveShell() {
212
264
  const mode = sandboxMode();
213
- if (mode !== "off" && (await hasSandboxExec())) {
214
- return { file: "/usr/bin/sandbox-exec", args: ["-p", seatbeltProfile(mode), "/bin/bash", "-s"] };
265
+ if (mode !== "off") {
266
+ if (await hasSandboxExec())
267
+ return { file: "/usr/bin/sandbox-exec", args: ["-p", seatbeltProfile(mode), "/bin/bash", "-s"] };
268
+ if (await hasBubblewrap())
269
+ return { file: "bwrap", args: [...bwrapArgs(mode), "/bin/bash", "-s"] };
215
270
  }
216
271
  return { file: "/bin/bash", args: ["-s"] };
217
272
  }
@@ -0,0 +1,17 @@
1
+ // node-only: carries the active session's shell key through async tool execution, so the
2
+ // persistent-shell tool (bash/shell_exec → getShellSession) resolves a PER-SESSION shell instead of
3
+ // one process-wide singleton. Before this, the foreground and every background sub-agent shared ONE
4
+ // bash process: a sub-agent's `cd`/`export` corrupted the foreground's cwd/env (and vice versa), and
5
+ // one slow command head-of-line-blocked all of them on the single FIFO. AsyncLocalStorage isolates
6
+ // the key per Executor.execute() call, so concurrent executions never read each other's key.
7
+ //
8
+ // Kept in its own module (not registry.ts, which is ALSO bundled platform:neutral for tool SCHEMAS)
9
+ // so registry.ts can pull it via the lazy nodeImport() path and keep node:async_hooks out of the
10
+ // neutral (mobile/JSCore) graph; the node-only executor.ts imports it statically.
11
+ import { AsyncLocalStorage } from "node:async_hooks";
12
+ /** Fallback key when a shell tool runs outside any Executor context (should not happen in normal
13
+ * flow — getShellSession is only reached via shellExec — but a stable default keeps it correct). */
14
+ export const DEFAULT_SHELL_KEY = "__main__";
15
+ /** The current session's shell key. Set by Executor.execute() around each tool.run; read by
16
+ * getShellSession() to pick this session's own ShellSession from the per-key map. */
17
+ export const shellKeyStore = new AsyncLocalStorage();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.153",
3
+ "version": "0.1.155",
4
4
  "description": "Operator (KODE) — TypeScript + Ink terminal coding agent. Full-frame render, single-engine core shared across CLI/web/mobile; runs against a local Aurora model.",
5
5
  "type": "module",
6
6
  "bin": {