@code-yeongyu/senpi-codemode 2026.11.4-2 → 2026.11.6-1

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
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## [2026.11.6-1] - 2026-11-06
4
+
5
+ ### Breaking Changes
6
+
7
+ ### Added
8
+
9
+ ### Changed
10
+
11
+ - The JavaScript `eval` kernel runs in its own process by default when senpi's executable is `bun` on macOS or Linux, so a crash on the kernel (Bun 1.4.4 `Worker` threads can corrupt the JavaScriptCore heap and kill the host with `SIGBUS`/`SIGTRAP`) settles the cell with the signal and the session survives; a Node.js host, a compiled binary and a Windows bun host keep the worker thread, and `isolation.js` / `SENPI_CODEMODE_JS_ISOLATION` still win on every host ([#6094](https://github.com/code-yeongyu/senpi/issues/6094), [#6095](https://github.com/code-yeongyu/senpi/pull/6095))
12
+
13
+ ### Fixed
14
+
15
+ - The bundled `bun` skill's capability map now gives `--retry=<N>` and `--compile --bytecode --bytecode-order=<profile>` in forms bun accepts, its shell-trap fix spawns with `env: process.env`, and the references it points to now cover IPC, `stripANSI`, `inspect.table`, hashing, UUID v7, semver, `deepEquals`, gzip/zstd and `which` ([#6008](https://github.com/code-yeongyu/senpi/issues/6008))
16
+ - On Windows, the JavaScript eval kernels opt every process they start out of EcoQoS power throttling, as senpi does, so commands run from eval code are not held to a few percent of a core; `SENPI_KEEP_POWER_THROTTLING=1` keeps Windows' default ([#6131](https://github.com/code-yeongyu/senpi/pull/6131))
17
+
18
+ ### Removed
19
+
20
+ ## [2026.11.5-1] - 2026-11-05
21
+
22
+ ### Breaking Changes
23
+
24
+ ### Added
25
+
26
+ ### Changed
27
+
28
+ ### Fixed
29
+
30
+ ### Removed
31
+
3
32
  ## [2026.11.4-2] - 2026-11-04
4
33
 
5
34
  ### Breaking Changes
package/README.md CHANGED
@@ -61,13 +61,29 @@ schema; it is not an installation failure.
61
61
 
62
62
  ### JavaScript process isolation
63
63
 
64
- By default the JavaScript kernel runs as a worker thread on the host's own
65
- runtime (`isolation.js: "worker"`). Setting `isolation.js: "process"` (or
66
- `SENPI_CODEMODE_JS_ISOLATION=process`, which wins over the file) runs each
67
- JavaScript kernel in its own subprocess instead, so a kernel crash (a native
68
- `SIGSEGV`, an out-of-memory, `process.exit`, an uncaught error) cannot take down
69
- the host session. The next cell runs on a replacement child, and its result
70
- carries the restart notice and names the crash.
64
+ The JavaScript kernel runs either as a worker thread on the host's own runtime
65
+ (`isolation.js: "worker"`) or in its own subprocess (`isolation.js: "process"`),
66
+ where a kernel crash (a native `SIGSEGV` or `SIGBUS`, an out-of-memory,
67
+ `process.exit`, an uncaught error) cannot take down the host session. The next
68
+ cell runs on a replacement child, and its result carries the restart notice and
69
+ names the crash. Without a setting, the default follows the host's executable:
70
+
71
+ - A macOS or Linux host whose executable is `bun` (an npm or bun install of
72
+ senpi or omo run through `bun`) defaults to `"process"`. A Bun 1.4.4 `Worker`
73
+ thread can corrupt the JavaScriptCore heap and kill the whole host with
74
+ `SIGBUS` or `SIGTRAP` (open upstream class; the symptom behind omo#12369),
75
+ and a kernel in its own process cannot.
76
+ - A Node.js host and a compiled binary (the desktop engine) default to
77
+ `"worker"`. A compiled executable cannot run the kernel child itself, so
78
+ process mode there needs a `bun` or `node` on `PATH`, which only an explicit
79
+ setting asks for.
80
+ - A Windows bun host also defaults to `"worker"`: the crash evidence is
81
+ macOS, and the process kernel's Windows channel is not covered by CI, so
82
+ there the mode stays opt-in.
83
+
84
+ `SENPI_CODEMODE_JS_ISOLATION` wins over the file, and the file wins over the
85
+ host default, in both directions: `isolation.js: "worker"` restores the thread
86
+ on a bun host.
71
87
 
72
88
  **Trust model.** Process mode isolates crashes, not hostile code. A cell runs in
73
89
  the same process that talks to the host, so it can reach everything that process
@@ -121,7 +137,7 @@ How it works:
121
137
  runtime (`Install bun or node, or use isolation.js: "worker"`). The result's
122
138
  memory reading is the child's process footprint.
123
139
 
124
- The default stays `"worker"`, and worker-mode behaviour is unchanged.
140
+ Worker-mode behaviour is unchanged.
125
141
 
126
142
  To run the `environments` suites with bun children (the runtime the product
127
143
  uses), run them under bun: `SENPI_CODEMODE_JS_ISOLATION=process bunx --bun vitest
@@ -328,7 +344,7 @@ Configuration is loaded in this order:
328
344
  | `environments.autoProvision` | `true` | Lets installs provision a managed environment. `false` makes installs refuse with `environment_installer_unavailable`. |
329
345
  | `environments.js.installer` | `auto` | Installer for the managed JavaScript environment: `auto`, `bun` or `npm`. |
330
346
  | `environments.py.installer` | `pip` | Installer for the managed Python environment. |
331
- | `isolation.js` | `worker` | JavaScript kernel isolation: `worker` (today's worker thread) or `process`. Env override: `SENPI_CODEMODE_JS_ISOLATION`. |
347
+ | `isolation.js` | `process` on a macOS or Linux host whose executable is `bun`, else `worker` | JavaScript kernel isolation: `worker` (a worker thread) or `process` (its own subprocess; a kernel crash cannot kill the session). Env override: `SENPI_CODEMODE_JS_ISOLATION`. |
332
348
  | `sandbox.enabled` | `false` | Allows sandbox cells. While `false` the sandbox option is neither accepted nor advertised. |
333
349
  | `sandbox.memoryMb` | `64` | Memory cap (MiB) for a sandbox cell. Env override: `SENPI_CODEMODE_SANDBOX_MEMORY_MB` (a positive integer wins). |
334
350
  | `sandbox.timeoutSeconds` | `300` | Time limit for a sandbox cell. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-codemode",
3
- "version": "2026.11.4-2",
3
+ "version": "2026.11.6-1",
4
4
  "description": "Source-only senpi extension package for codemode evaluation tools",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -33,15 +33,15 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@babel/parser": "8.0.4",
36
- "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.4-2",
36
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.6-1",
37
37
  "quickjs-wasi": "3.6.2",
38
38
  "typebox": "1.3.34"
39
39
  },
40
40
  "peerDependencies": {
41
- "@code-yeongyu/senpi": "2026.11.4-2"
41
+ "@code-yeongyu/senpi": "2026.11.6-1"
42
42
  },
43
43
  "devDependencies": {
44
- "@code-yeongyu/senpi": "2026.11.4-2"
44
+ "@code-yeongyu/senpi": "2026.11.6-1"
45
45
  },
46
46
  "keywords": [
47
47
  "senpi",
@@ -1,5 +1,6 @@
1
1
  import type { Static } from "typebox";
2
2
  import { Type } from "typebox";
3
+ import { runtimeNameOf } from "../kernels/js/runtime-name.ts";
3
4
 
4
5
  type Environment = Readonly<Record<string, string | undefined>>;
5
6
 
@@ -51,6 +52,33 @@ export type CodemodeFeatureSettings = Static<typeof featureSettingsSchema>;
51
52
 
52
53
  export type JsIsolation = "worker" | "process";
53
54
 
55
+ /** The host as the JavaScript kernel's default isolation sees it: what its own executable is, and on which platform. */
56
+ export interface JsIsolationHost {
57
+ /** "bun" or "node" when the host's executable is that runtime; undefined for a compiled binary. */
58
+ readonly executable: "bun" | "node" | undefined;
59
+ readonly platform: NodeJS.Platform;
60
+ }
61
+
62
+ export function currentJsIsolationHost(
63
+ execPath: string = process.execPath,
64
+ platform: NodeJS.Platform = process.platform,
65
+ ): JsIsolationHost {
66
+ return { executable: runtimeNameOf(execPath), platform };
67
+ }
68
+
69
+ /**
70
+ * Without a setting, a POSIX host whose executable is bun runs the kernel in its own process: a Bun 1.4.4 Worker thread
71
+ * can corrupt the JavaScriptCore heap and take the whole host down with it (SIGBUS/SIGTRAP on macOS, the open upstream
72
+ * class behind omo#12369), and a kernel process cannot. A Node.js host keeps the worker thread, and so does a compiled
73
+ * binary: its executable cannot run process-entry.js, so process mode there needs a bun or node on PATH, which only an
74
+ * explicit setting asks for. A Windows bun host keeps the worker thread too: the crash evidence is macOS, and the
75
+ * process kernel's Windows channel (no libc, cell output shares the frame channel) has no CI coverage, so there the
76
+ * mode stays opt-in.
77
+ */
78
+ export function defaultJsIsolation(host: JsIsolationHost): JsIsolation {
79
+ return host.executable === "bun" && host.platform !== "win32" ? "process" : "worker";
80
+ }
81
+
54
82
  export interface ResolvedSandbox {
55
83
  readonly enabled: boolean;
56
84
  readonly memoryMb: number;
@@ -74,11 +102,15 @@ export function pickFeatureSettings(input: CodemodeFeatureSettings): CodemodeFea
74
102
  };
75
103
  }
76
104
 
77
- /** The environment wins over the file; an unknown value is ignored. Default: today's worker-thread kernel. */
78
- export function resolveJsIsolation(settings: CodemodeFeatureSettings, env: Environment = process.env): JsIsolation {
105
+ /** The environment wins over the file, the file over the host default; an unknown value is ignored. */
106
+ export function resolveJsIsolation(
107
+ settings: CodemodeFeatureSettings,
108
+ env: Environment = process.env,
109
+ host: JsIsolationHost = currentJsIsolationHost(),
110
+ ): JsIsolation {
79
111
  const fromEnv = env[JS_ISOLATION_ENVIRONMENT_FLAG];
80
112
  if (fromEnv === "worker" || fromEnv === "process") return fromEnv;
81
- return settings.isolation?.js ?? "worker";
113
+ return settings.isolation?.js ?? defaultJsIsolation(host);
82
114
  }
83
115
 
84
116
  /** Off by default; the environment's memory cap wins over the file when it is a positive integer. */
@@ -1 +1,2 @@
1
+ import "./power-throttling-startup.js";
1
2
  import "./interpose.js";
@@ -1 +1,2 @@
1
+ import "./power-throttling-startup.js";
1
2
  import "./interpose.js";
@@ -0,0 +1,4 @@
1
+ // senpi#6125: imported first by every eval kernel entry, before interpose.js captures the launchers.
2
+ import { installKernelPowerThrottlingOptOut } from "./power-throttling.js";
3
+
4
+ installKernelPowerThrottlingOptOut();
@@ -0,0 +1,18 @@
1
+ export interface KernelPowerThrottling {
2
+ OpenProcess(access: number, inherit: number, pid: number): unknown;
3
+ SetProcessInformation(handle: unknown, infoClass: number, info: Uint8Array, length: number): number;
4
+ CloseHandle(handle: unknown): number;
5
+ }
6
+
7
+ export type KernelPowerThrottlingInstall =
8
+ | { status: "skipped"; reason: "not-windows" | "opted-out" | "no-ffi" }
9
+ | { status: "installed"; self: boolean; restore(): void };
10
+
11
+ export function installKernelPowerThrottlingOptOut(options?: {
12
+ platform?: NodeJS.Platform;
13
+ env?: NodeJS.ProcessEnv;
14
+ pid?: number;
15
+ load?: (platform: NodeJS.Platform) => KernelPowerThrottling | undefined;
16
+ childProcessPrototype?: { spawn(...args: unknown[]): unknown; pid?: number };
17
+ bun?: { spawn(...args: unknown[]): { pid?: number } };
18
+ }): KernelPowerThrottlingInstall;
@@ -0,0 +1,91 @@
1
+ // senpi#6125: the eval kernel's realms opt their children out of Windows EcoQoS throttling, as senpi's own entries do
2
+ // (packages/coding-agent/src/core/windows-power-throttling.ts). Plain JS (with power-throttling.d.ts) because the worker
3
+ // and process kernel entries import it before interpose.js captures the launchers. The policy is per process and not
4
+ // inherited, and the launcher patch is per JavaScript realm, so each kernel realm installs its own. A no-op off Windows,
5
+ // without bun:ffi, or with SENPI_KEEP_POWER_THROTTLING=1; off Windows it imports nothing, so the interposition that
6
+ // follows sees the same module graph as before.
7
+ const PROCESS_POWER_THROTTLING_CLASS = 4;
8
+ const PROCESS_SET_INFORMATION = 0x0200;
9
+
10
+ function optOutState() {
11
+ const info = new Uint8Array(12);
12
+ const view = new DataView(info.buffer);
13
+ view.setUint32(0, 1, true);
14
+ view.setUint32(4, 1, true);
15
+ return info;
16
+ }
17
+
18
+ function loadKernel32PowerThrottling(platform = process.platform) {
19
+ if (platform !== "win32") return undefined;
20
+ const ffi = process.getBuiltinModule("bun:ffi");
21
+ if (ffi === undefined) return undefined;
22
+ let lib;
23
+ try {
24
+ lib = ffi.dlopen("kernel32.dll", {
25
+ OpenProcess: { args: ["u32", "i32", "u32"], returns: "ptr" },
26
+ SetProcessInformation: { args: ["ptr", "i32", "ptr", "u32"], returns: "i32" },
27
+ CloseHandle: { args: ["ptr"], returns: "i32" },
28
+ });
29
+ } catch {
30
+ // A kernel32 without these exports (pre-Windows 8): keep Windows' default policy rather than fail the kernel.
31
+ return undefined;
32
+ }
33
+ return {
34
+ OpenProcess: (access, inherit, pid) => lib.symbols.OpenProcess(access, inherit, pid),
35
+ SetProcessInformation: (handle, infoClass, info, length) =>
36
+ Number(lib.symbols.SetProcessInformation(handle, infoClass, ffi.ptr(info), length)),
37
+ CloseHandle: (handle) => Number(lib.symbols.CloseHandle(handle)),
38
+ };
39
+ }
40
+
41
+ function disableExecutionSpeedThrottling(kernel, pid) {
42
+ try {
43
+ const handle = kernel.OpenProcess(PROCESS_SET_INFORMATION, 0, pid);
44
+ if (!handle) return false;
45
+ try {
46
+ const info = optOutState();
47
+ return kernel.SetProcessInformation(handle, PROCESS_POWER_THROTTLING_CLASS, info, info.byteLength) !== 0;
48
+ } finally {
49
+ kernel.CloseHandle(handle);
50
+ }
51
+ } catch {
52
+ // The child is already running: an FFI failure must never turn its launch into an exception.
53
+ return false;
54
+ }
55
+ }
56
+
57
+ export function installKernelPowerThrottlingOptOut(options = {}) {
58
+ const platform = options.platform ?? process.platform;
59
+ if (platform !== "win32") return { status: "skipped", reason: "not-windows" };
60
+ if ((options.env ?? process.env).SENPI_KEEP_POWER_THROTTLING === "1") return { status: "skipped", reason: "opted-out" };
61
+ const kernel = (options.load ?? loadKernel32PowerThrottling)(platform);
62
+ if (kernel === undefined) return { status: "skipped", reason: "no-ffi" };
63
+ const self = disableExecutionSpeedThrottling(kernel, options.pid ?? process.pid);
64
+ const proto = options.childProcessPrototype ?? process.getBuiltinModule("node:child_process").ChildProcess.prototype;
65
+ const bun = options.bun ?? globalThis.Bun;
66
+ const optOut = (pid) => {
67
+ if (typeof pid === "number" && pid > 0) disableExecutionSpeedThrottling(kernel, pid);
68
+ };
69
+ const originalSpawn = proto.spawn;
70
+ proto.spawn = function (...args) {
71
+ const result = originalSpawn.apply(this, args);
72
+ optOut(this.pid);
73
+ return result;
74
+ };
75
+ const originalBunSpawn = bun?.spawn;
76
+ if (originalBunSpawn !== undefined) {
77
+ bun.spawn = function (...args) {
78
+ const subprocess = originalBunSpawn.apply(this, args);
79
+ optOut(subprocess.pid);
80
+ return subprocess;
81
+ };
82
+ }
83
+ return {
84
+ status: "installed",
85
+ self,
86
+ restore: () => {
87
+ proto.spawn = originalSpawn;
88
+ if (originalBunSpawn !== undefined) bun.spawn = originalBunSpawn;
89
+ },
90
+ };
91
+ }
@@ -14,6 +14,7 @@
14
14
  // Lifetime: the kernel exits the moment its control channel reaches end-of-file (the host closed it, exited or was
15
15
  // killed). A watchdog thread also checks the parent pid and kills this process when the host is gone, so a cell
16
16
  // that never yields (a busy loop, a blocking call) cannot keep the kernel alive past its host.
17
+ import "./power-throttling-startup.js";
17
18
  import { closeSync, createReadStream, openSync, writeSync } from "node:fs";
18
19
  import { createRequire } from "node:module";
19
20
  import { createInterface } from "node:readline";
@@ -1,7 +1,7 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
  import { randomBytes } from "node:crypto";
3
3
  import { accessSync, constants } from "node:fs";
4
- import { basename, dirname, join } from "node:path";
4
+ import { dirname, join } from "node:path";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import type { KernelToHostMessage } from "../../bridge/protocol.ts";
7
7
  import { isKernelToHostMessage, parseBridgeJsonLine, validateBridgeMessage } from "../../bridge/protocol.ts";
@@ -9,8 +9,11 @@ import type { EvalRuntimeInfo } from "../../tool/types.ts";
9
9
  import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
10
10
  import { type SubprocessLike, SubprocessProcess, spawnSubprocess } from "../shared/subprocess-process.ts";
11
11
  import type { WorkerLike } from "./inline-worker.ts";
12
+ import { runtimeNameOf } from "./runtime-name.ts";
12
13
  import { JavaScriptWorkerExitedError } from "./worker-host.ts";
13
14
 
15
+ export { runtimeNameOf } from "./runtime-name.ts";
16
+
14
17
  const PROCESS_CLOSE_GRACE_MS = 2_000;
15
18
 
16
19
  export interface JavaScriptProcessEntryUrlOptions extends CodemodeRuntimeAssetEnvironment {
@@ -99,12 +102,6 @@ export function processRuntimeInfo(searchPath: string | undefined): EvalRuntimeI
99
102
  return { name, version, path: command, isolation: "process" };
100
103
  }
101
104
 
102
- /** "bun" or "node" from an executable path; undefined for anything else (a compiled senpi binary, for one). */
103
- export function runtimeNameOf(command: string): "bun" | "node" | undefined {
104
- const name = basename(command).replace(/\.(exe|cmd|bat)$/i, "");
105
- return name === "bun" || name === "node" ? name : undefined;
106
- }
107
-
108
105
  function isExecutable(path: string): boolean {
109
106
  try {
110
107
  accessSync(path, constants.X_OK);
@@ -0,0 +1,7 @@
1
+ import { basename } from "node:path";
2
+
3
+ /** "bun" or "node" from an executable path; undefined for anything else (a compiled senpi binary, for one). */
4
+ export function runtimeNameOf(command: string): "bun" | "node" | undefined {
5
+ const name = basename(command).replace(/\.(exe|cmd|bat)$/i, "");
6
+ return name === "bun" || name === "node" ? name : undefined;
7
+ }
@@ -1 +1,2 @@
1
+ import "./power-throttling-startup.js";
1
2
  import "./interpose.js";
@@ -21,12 +21,12 @@ GPT eval: batch a step's independent tool calls in one cell with \`tool.<name>(a
21
21
  - Write real code around the calls - loops, branches, joins, a try/except per risky item - and keep every failed or missing item in the result verbatim; re-read truncated output before deciding.
22
22
  {{#if monitor}}- Long-running build, test run, deploy, or watch work starts with \`tool.monitor({ command, filter })\`, with the decisive-line filter inside the same cell; keep working until its event wakes the turn.{{/if}}{{/if}}
23
23
  {{#if hostLine}}
24
- Host: {{hostLine}}. Cells execute here. Size \`parallel(thunks)\` pools to its cores; \`tool.<name>()\` shell commands must fit this platform, even when the code you are writing targets another machine.
24
+ Host: {{hostLine}}. Cells execute here. \`parallel(thunks)\` runs through a fixed-width pool (the codemode \`parallelPoolWidth\` setting, default 4) whatever the core count; \`tool.<name>()\` shell commands must fit this platform, even when the code you are writing targets another machine.
25
25
  {{/if}}
26
26
 
27
27
  \`language\`: {{#if py}}\`"py"\` IPython kernel{{/if}}{{#ifAll py js}}, {{/ifAll}}{{#if js}}\`"js"\` persistent JavaScript VM{{/if}}{{#if rb}}{{#ifAny py js}}, {{/ifAny}}\`"rb"\` persistent Ruby kernel{{/if}}{{#if jl}}{{#ifAny py js rb}}, {{/ifAny}}\`"jl"\` persistent Julia kernel{{/if}}.
28
28
 
29
- A cell that outlives the foreground window detaches and keeps running; further cells on the same language queue behind it in submission order on the same kernel (state is shared, execution is serial) while other languages run at once, up to {{maxDetachedCells}} background cells per session; each detached cell completes as one notification. Do not re-run a detached or queued cell; read, cancel or enumerate them with \`eval({ action: "peek" | "stop", cell_id })\` / \`eval({ action: "list" })\`; list shows live and recently settled cells across languages without consuming notifications. Its own execution time is capped at {{runBudgetSeconds}}s (queue time and time inside host tool calls are not charged; the hard limit stays wall-clock from submission; raise \`timeout\` only for a declared long run), and a killed js cell that cannot settle restarts its kernel with every global lost.
29
+ A cell still running when the call stops waiting for it (the detach point in the parameter schema) detaches and keeps running; further cells on the same language queue behind it in submission order on the same kernel (state is shared, execution is serial) while other languages run at once, up to {{maxDetachedCells}} background cells per session (at that cap, a further cell that cannot detach is cancelled when its foreground window ends, so stop or await a live cell first); each detached cell completes as one notification. Do not re-run a detached or queued cell; read, cancel or enumerate them with \`eval({ action: "peek" | "stop", cell_id })\` / \`eval({ action: "list" })\`; list shows live and recently settled cells across languages without consuming notifications. Its own execution time is capped at {{runBudgetSeconds}}s (queue time and time inside host tool calls are not charged; the hard limit stays wall-clock from submission; raise \`timeout\` only for a declared long run), and a killed js cell that cannot settle restarts its kernel with every global lost.
30
30
 
31
31
  {{#if py}}Python runs on a live event loop: use top-level \`await\`; \`asyncio.run(…)\` raises.{{/if}}
32
32
  {{#if js}}{{#if jsBun}}JS runs in-process on Bun {{jsVersion}}: top-level \`await\`/\`return\` work; \`Bun.*\` builtins available, including \`new Bun.WebView()\`, a headless browser (navigate/click/evaluate/screenshot) to reach for before \`curl\` or a browser CLI when a page needs JS, a login, or a screenshot. Shell out through \`Bun.$\` or \`Bun.spawn\`, never \`Bun.spawnSync\`: a synchronous child blocks the worker and cannot be interrupted.{{#if bunSkillPath}} Before a cell that installs a package, spawns a process, server or PTY, runs tests, or starts a long run, read the bun skill at {{bunSkillPath}}: its builtins replace the npm packages you would otherwise install, and it lists the Bun.$ / Bun.spawn / bun test traps that cost past sessions hours.{{/if}}{{else}}JS runs under Node.js worker: top-level \`await\`/\`return\` work; \`fetch\`/\`Buffer\` available.{{/if}}{{/if}}
@@ -29,9 +29,9 @@ Bun 1.4.0 (Aug 2026) through 1.4.4 (Oct 2026) ships builtins and CLIs that repla
29
29
  | Serve a static dir (ETag/Range/304 handled) | `Bun.serve({ routes: { "/x/*": { dir } } })` | express.static, serve-static, sirv | http-networking |
30
30
  | HTTP/2 + HTTP/3 server; fetch protocol/compress/proxy; per-client pools | `http2: true`, `http3: true`, `fetch(url, { protocol, compress, proxy })`, `new Bun.FetchSession()` | undici Agent | http-networking |
31
31
  | Stream a download to disk; replay a request as curl | `Bun.write(path, await fetch(url))`, `BUN_CONFIG_VERBOSE_FETCH=curl` | pipeline + createWriteStream | http-networking |
32
- | Tests across CPU workers / CI shards / changed files / flaky retry | `bun test --parallel --shard=1/3 --changed=main --retry` | jest/vitest infra | test |
32
+ | Tests across CPU workers / CI shards / changed files / flaky retry | `bun test --parallel --shard=1/3 --changed=main --retry=3` | jest/vitest infra | test |
33
33
  | Kill "passes alone, fails in suite" bugs; hunt flakes | `bun test --isolate`, `--rerun-each N`, `--only-failures` | vitest default behavior | test |
34
- | Single-file executables with embedded assets and profile-guided startup; feature flags; in-memory bundling; metafile; React Compiler | `bun build --compile --asset ./public --bytecode-order`, `bun:bundle feature()`, `files:{}`, `metafile: true`, `--react-compiler` | pkg hacks, esbuild define/plugins, babel-plugin-react-compiler | build |
34
+ | Single-file executables with embedded assets and profile-guided startup; feature flags; in-memory bundling; metafile; React Compiler | `bun build --compile --bytecode --bytecode-order=<profile> --asset ./public`, `bun:bundle feature()`, `files:{}`, `metafile: true`, `--react-compiler` | pkg hacks, esbuild define/plugins, babel-plugin-react-compiler | build |
35
35
  | Diff package versions, fix vulns, dedupe/prune, licenses, explain a dep | `bun pm diff`, `bun audit fix`, `bun dedupe`, `bun prune`, `bun pm licenses`, `bun why` | npm-diff, npm audit fix, npm ls | install |
36
36
  | Offline / cached installs; Docker layers; CI cache; 7x faster CI | `bun install --offline\|--prefer-offline`, `bun pm fetch`, `bun pm cache pack\|unpack`, `linker = "isolated"` | pnpm store | install |
37
37
  | Profile CPU/heap/bundle as grep-able Markdown | `bun --cpu-prof-md`, `--heap-prof-md`, `bun build --metafile-md` | Chrome DevTools round-trip | dev-tooling |
@@ -143,6 +143,24 @@ Docs: <https://bun.com/docs/runtime/utils>
143
143
  Bun.stringWidth("\x1b[32mgreen\x1b[0m e\u0301"); // terminal columns, ANSI + grapheme aware
144
144
  Bun.sliceAnsi(str, 0, 20); // slice by columns, preserving ANSI codes
145
145
  Bun.wrapAnsi(str, 80); // wrap by columns
146
+ Bun.stripANSI("\x1b[31mred\x1b[0m"); // "red"
147
+ Bun.inspect.table([{ a: 1, b: 2 }]); // box-drawn table string, like console.table
148
+ ```
149
+
150
+ ## Hashing, ids, versions, equality, compression, PATH lookup
151
+
152
+ Docs: <https://bun.com/docs/runtime/utils>, <https://bun.com/docs/runtime/hashing>
153
+
154
+ ```ts
155
+ Bun.hash("data"); // fast non-crypto hash (wyhash), returns a bigint
156
+ new Bun.CryptoHasher("sha256").update(buf).digest("hex");
157
+ await Bun.password.hash(pw); await Bun.password.verify(pw, hash); // argon2id by default
158
+ Bun.randomUUIDv7(); // time-ordered UUID string
159
+ Bun.semver.satisfies("1.4.4", "^1.4.0"); Bun.semver.order("1.4.3", "1.4.4"); // true; -1
160
+ Bun.deepEquals(a, b); // structural equality (third arg true = strict)
161
+ Bun.gzipSync(bytes); Bun.gunzipSync(gz);
162
+ Bun.zstdCompressSync(bytes); Bun.zstdDecompressSync(z);
163
+ Bun.which("gh"); // absolute path or null
146
164
  ```
147
165
 
148
166
  ## Databases and object storage
@@ -16,7 +16,7 @@ await $`bun run build`.cwd("/repo").env({ ...process.env, CI: "1" });
16
16
  | Trap | What happens | Fix |
17
17
  |---|---|---|
18
18
  | `${"a b c"}` | ONE argv entry — vitest reported "No test files found" with rc 0 and the gate looked green (2026-09-21) | pass an array: `${["a", "b", "c"]}` spreads into separate args |
19
- | `$?`, `$VAR`, `for … done`, `$(…)` | `$` is escaped to a literal; unsupported syntax is a PARSE error (nothing runs) or a silent `command not found` with rc 0 (2026-10-10, 10-22) | run real bash: `Bun.spawn(["bash", "-c", script])` or `` $`bash -c ${script}` `` |
19
+ | `$?`, `$VAR`, `for … done`, `$(…)` | `$` is escaped to a literal; unsupported syntax is a PARSE error (nothing runs) or a silent `command not found` with rc 0 (2026-10-10, 10-22) | run real bash: `Bun.spawn(["bash", "-c", script], { env: process.env, stdin: "ignore" })` or `` $`bash -c ${script}` `` |
20
20
  | `VAR=x cmd` prefix | not applied to a directly executed binary — `` $`HOME=/x printenv HOME` `` prints the real HOME; only `sh -c` sees it (2026-10-25) | `.env({ ... })`, or `Bun.spawn(cmd, { env })` |
21
21
  | `ssh host <<'EOF' … EOF` | the heredoc body ran on the LOCAL host (2026-10-23) | `Bun.spawn(["ssh", host, "bash -s"], { stdin: new Blob([script]) })`, or scp a script file |
22
22
  | Globs in `${...}` | literal since 1.4.0; only patterns written in the template expand | write the pattern in the template |
@@ -43,6 +43,7 @@ proc.resourceUsage(); // { maxRSS, cpuTime: { user, system } } — measure, do n
43
43
  - Re-spawning Bun: use `process.execPath`, never `"bun"` from PATH — a mise shim refused a temp HOME, a stray 1.4.0 shim in `~/.bun/install/global/node_modules/.bin` hung rpc tests, and after a reboot PATH resolved `bun` to a vite-plus shim with shim recursion; the `bun test vX.Y.Z` header line is the tell (2026-09-28, 10-26, 10-29). Inside a compiled binary `bun` can be the binary itself — see [build](build.md).
44
44
  - `proc.signalCode` is set when a signal is SENT, not when the child exits: a child ignoring SIGTERM keeps running while `signalCode === "SIGTERM"`; await `proc.exited` with a deadline, then `proc.kill("SIGKILL")` (2026-10-02).
45
45
  - **The js eval kernel SIGKILLs every `Bun.spawn` child when its cell settles** — four Chromium launches in a row died 0.05-9 s after the launching cell completed, and a child parked in `globalThis` does not survive (2026-09-16/10-17). Anything that must outlive a cell (browser, daemon, dev server, `ssh` running a remote job, a `git commit` with slow hooks) starts through `tool.monitor({ command })` or `tool.bash({ run_in_background: true })`; keep only its id/pid in `globalThis`. Conversely `bun --no-orphans script.ts` makes a script exit when its parent dies and SIGKILL every descendant on exit. A stopped long `Bun.$` cell restarts the whole kernel and loses every global; keep helpers in an importable file and restore with `Object.assign(globalThis, await import(path))` (2026-10-02).
46
+ - IPC with a Bun child: `Bun.spawn([process.execPath, "child.ts"], { env: process.env, ipc(message, child) {} })`, then `child.send(value)`; the child uses `process.send(value)` and `process.on("message", fn)` (structured-clone values; measured on 1.4.4).
46
47
  - PTY: `Bun.spawn(["bash"], { terminal: { cols, rows, data(term, chunk) {} } })` then `proc.terminal.write()/resize()` — replaces node-pty and the macOS `script -q /dev/null` trick.
47
48
  - `Bun.spawnSync` blocks the kernel thread and cannot be interrupted: never in an eval cell. `maxBuffer` kills a chatty sync child.
48
49
  - `signal: AbortSignal.timeout(ms)` works for `fetch` and `spawn` alike (`killSignal` picks the signal).