@code-yeongyu/senpi-codemode 2026.11.19 → 2026.11.21-2

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,92 @@
1
1
  # Changelog
2
2
 
3
+ ## [2026.11.21-2] - 2026-11-21
4
+
5
+ ### Breaking Changes
6
+
7
+ ### Added
8
+
9
+ ### Changed
10
+
11
+ ### Fixed
12
+
13
+ ### Removed
14
+
15
+ ## [2026.11.21] - 2026-11-21
16
+
17
+ ### Breaking Changes
18
+
19
+ ### Added
20
+
21
+ ### Changed
22
+
23
+ ### Fixed
24
+
25
+ ### Removed
26
+
27
+ ## [2026.11.20] - 2026-11-20
28
+
29
+ ### Breaking Changes
30
+
31
+ ### Added
32
+
33
+ ### Changed
34
+
35
+ ### Fixed
36
+
37
+ ### Removed
38
+
39
+ ## [2026.11.19-5] - 2026-11-19
40
+
41
+ ### Breaking Changes
42
+
43
+ ### Added
44
+
45
+ ### Changed
46
+
47
+ ### Fixed
48
+
49
+ ### Removed
50
+
51
+ ## [2026.11.19-4] - 2026-11-19
52
+
53
+ ### Breaking Changes
54
+
55
+ ### Added
56
+
57
+ ### Changed
58
+
59
+ ### Fixed
60
+
61
+ ### Removed
62
+
63
+ ## [2026.11.19-3] - 2026-11-19
64
+
65
+ ### Breaking Changes
66
+
67
+ ### Added
68
+
69
+ ### Changed
70
+
71
+ ### Fixed
72
+
73
+ - The eval tool description names the eval-only tools in its first lines, so a host that cuts long tool descriptions still shows them ([#7032](https://github.com/code-yeongyu/senpi/pull/7032))
74
+ - Eval kernels (Python, Ruby, Julia, JavaScript in both isolation modes), their children and `%pip` installs no longer inherit the RPC host's identity or launch-default client capabilities, and a `new Bun.$.Shell()` in a cell starts from the kernel's env view ([#7037](https://github.com/code-yeongyu/senpi/pull/7037))
75
+
76
+ ### Removed
77
+
78
+ ## [2026.11.19-2] - 2026-11-19
79
+
80
+ ### Breaking Changes
81
+
82
+ ### Added
83
+
84
+ ### Changed
85
+
86
+ ### Fixed
87
+
88
+ ### Removed
89
+
3
90
  ## [2026.11.19] - 2026-11-19
4
91
 
5
92
  ### Breaking Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-codemode",
3
- "version": "2026.11.19",
3
+ "version": "2026.11.21-2",
4
4
  "description": "Source-only senpi extension package for codemode evaluation tools",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -33,16 +33,16 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@babel/parser": "8.0.4",
36
- "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.19",
37
- "@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.19",
36
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.21-2",
37
+ "@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.21-2",
38
38
  "quickjs-wasi": "3.6.2",
39
39
  "typebox": "1.3.34"
40
40
  },
41
41
  "peerDependencies": {
42
- "@code-yeongyu/senpi": "2026.11.19"
42
+ "@code-yeongyu/senpi": "2026.11.21-2"
43
43
  },
44
44
  "devDependencies": {
45
- "@code-yeongyu/senpi": "2026.11.19"
45
+ "@code-yeongyu/senpi": "2026.11.21-2"
46
46
  },
47
47
  "keywords": [
48
48
  "senpi",
@@ -41,6 +41,9 @@ const hostToKernelMessageSchema = Type.Union([
41
41
  sessionId: Type.String({ minLength: 1 }),
42
42
  connection: connectionConfigSchema,
43
43
  sessionEnv: Type.Optional(Type.Record(Type.String(), Type.String())),
44
+ /** Worker-thread JS kernels: host names the worker's env copy drops, and values it sets (senpi#5635). */
45
+ removedEnv: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
46
+ inheritedSet: Type.Optional(Type.Record(Type.String(), Type.String())),
44
47
  kernelGeneration: Type.Optional(Type.Integer({ minimum: 1 })),
45
48
  hostToolNames: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
46
49
  foreignLanguageNames: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
@@ -45,6 +45,7 @@ export async function installPythonPackages(input: {
45
45
  readonly cwd: string;
46
46
  readonly signal: AbortSignal;
47
47
  readonly onOutput?: (stream: "stdout" | "stderr", data: string) => void;
48
+ readonly inheritedEnv?: () => Readonly<Record<string, string | undefined>>;
48
49
  }): Promise<InstallReceipt> {
49
50
  const requested =
50
51
  typeof input.requirements === "string"
@@ -60,6 +61,7 @@ export async function installPythonPackages(input: {
60
61
  args: requested,
61
62
  cwd: input.cwd,
62
63
  signal: input.signal,
64
+ ...(input.inheritedEnv === undefined ? {} : { inheritedEnv: input.inheritedEnv }),
63
65
  onOutput: (stream, data) => {
64
66
  if (stream === "stdout") stdout += data;
65
67
  input.onOutput?.(stream, data);
@@ -173,9 +173,9 @@ export function normalizePipInstall(args: readonly string[]): string[] {
173
173
  * pip's environment with every PIP_* variable removed and its config file pointed at nothing: `--isolated`
174
174
  * alone still honours PIP_CONFIG_FILE, and a configured target, root or prefix would install outside the revision.
175
175
  */
176
- export function isolatedPipEnv(): NodeJS.ProcessEnv {
176
+ export function isolatedPipEnv(base: Readonly<Record<string, string | undefined>> = process.env): NodeJS.ProcessEnv {
177
177
  const env: NodeJS.ProcessEnv = {};
178
- for (const [key, value] of Object.entries(process.env)) {
178
+ for (const [key, value] of Object.entries(base)) {
179
179
  if (!key.toUpperCase().startsWith("PIP_")) env[key] = value;
180
180
  }
181
181
  // pip skips every config file when PIP_CONFIG_FILE equals Python's os.devnull: "nul" on Windows, not Node's "\\\\.\\nul".
@@ -189,6 +189,7 @@ export async function runPipInstall(input: {
189
189
  readonly cwd: string;
190
190
  readonly signal: AbortSignal;
191
191
  readonly onOutput?: (stream: "stdout" | "stderr", data: string) => void;
192
+ readonly inheritedEnv?: () => Readonly<Record<string, string | undefined>>;
192
193
  }): Promise<void> {
193
194
  const argv = [
194
195
  "-m",
@@ -219,7 +220,7 @@ export async function runPipInstall(input: {
219
220
  stdio: ["ignore", "pipe", "pipe"],
220
221
  // senpi#3965: python/pip is a console-subsystem exe on Windows.
221
222
  windowsHide: true,
222
- env: { ...isolatedPipEnv(), TMPDIR: scratch, TEMP: scratch, TMP: scratch },
223
+ env: { ...isolatedPipEnv(input.inheritedEnv?.()), TMPDIR: scratch, TEMP: scratch, TMP: scratch },
223
224
  });
224
225
  let termination: Promise<void> | undefined;
225
226
  let stderrTail = "";
@@ -15,6 +15,8 @@ export interface PythonEnvironmentsOptions {
15
15
  readonly cwd: string;
16
16
  readonly interpreter: string;
17
17
  readonly settings: Pick<ResolvedCodemodeSettings, "environments">;
18
+ /** The host env pip inherits, without the RPC host's supervisor hand-off (senpi#5635); defaults to process.env. */
19
+ readonly inheritedEnv?: () => Readonly<Record<string, string | undefined>>;
18
20
  }
19
21
 
20
22
  export class PythonEnvironments {
@@ -67,6 +69,7 @@ export class PythonEnvironments {
67
69
  cwd: this.#options.cwd,
68
70
  signal,
69
71
  ...(onOutput === undefined ? {} : { onOutput }),
72
+ ...(this.#options.inheritedEnv === undefined ? {} : { inheritedEnv: this.#options.inheritedEnv }),
70
73
  });
71
74
  if (this.#mode === mode) this.#currentBase = base;
72
75
  return receipt;
@@ -7,8 +7,8 @@ import { PythonKernel } from "../kernels/py/kernel.ts";
7
7
  import type { PeerKernelToolsDescribe } from "../kernels/py/kernel-tools-host.ts";
8
8
  import { defaultSpawn } from "../kernels/py/process.ts";
9
9
  import { RubyKernel } from "../kernels/rb/kernel.ts";
10
- import type { SessionEnvironment } from "../kernels/session-env.ts";
11
10
  import type { AttestKernelSpawn } from "../kernels/shared/session-spawn-attestation.ts";
11
+ import type { InheritedEnvironment, SessionEnvironment } from "../kernels/session-env.ts";
12
12
  import { spawnSubprocess } from "../kernels/shared/subprocess-process.ts";
13
13
  import type { EvalKernel, EvalLanguage } from "../tool/types.ts";
14
14
  import { type KernelMemoryReading, kernelRegistry, type RegisteredKernelSource } from "./kernel-registry.ts";
@@ -27,6 +27,7 @@ export interface SubprocessKernelStart {
27
27
  readonly cwd: string;
28
28
  readonly sessionEnv?: SessionEnvironment;
29
29
  readonly attestSpawn?: AttestKernelSpawn;
30
+ readonly inheritedEnv?: InheritedEnvironment;
30
31
  readonly connection: BridgeConnectionConfig;
31
32
  readonly onMessage: (message: KernelToHostMessage) => void;
32
33
  };
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  activeKillGuardEnvironment,
3
+ childEnvironmentOf,
3
4
  type ExtensionContext,
4
5
  readKillGuardSetting,
5
6
  withBundledBunCommands,
@@ -102,6 +103,8 @@ export async function createRuntime(
102
103
  // bash's BASH_ENV wrapper, as the bash tool does.
103
104
  const killGuardEnv = killGuard ? activeKillGuardEnvironment({ ...process.env, ...pathEntry }) : {};
104
105
  const sessionEnv = { ...sessionEnvironmentFrom(ctx), ...pathEntry, ...killGuardEnv, ...withheldCredentialEntries() };
106
+ // Kernels and their children never see the RPC host's supervisor hand-off (senpi#5635).
107
+ const inheritedEnv = () => childEnvironmentOf(process.env);
105
108
  const configuredPoolWidth = settings.parallelPoolWidth;
106
109
  const parallelPoolWidth = Number.isFinite(configuredPoolWidth) ? Math.max(1, Math.trunc(configuredPoolWidth)) : 1;
107
110
  const pythonEnvironments =
@@ -111,6 +114,7 @@ export async function createRuntime(
111
114
  cwd: ctx.cwd,
112
115
  interpreter: availability.py.detected.path,
113
116
  settings,
117
+ inheritedEnv,
114
118
  })
115
119
  : undefined;
116
120
  const manager = await create({
@@ -118,6 +122,7 @@ export async function createRuntime(
118
122
  ownerSessionId: ctx.sessionManager.getSessionId(),
119
123
  cwd: ctx.cwd,
120
124
  sessionEnv,
125
+ inheritedEnv,
121
126
  killGuard,
122
127
  settings,
123
128
  availability,
@@ -147,7 +152,7 @@ export async function createRuntime(
147
152
  artifactsDir: artifacts.dir,
148
153
  cwd: ctx.cwd,
149
154
  runtime: jsRuntimeInfo().name,
150
- env: { ...process.env, ...sessionEnv },
155
+ env: { ...inheritedEnv(), ...sessionEnv },
151
156
  settings,
152
157
  }),
153
158
  ...(pythonEnvironments === undefined ? {} : { pythonEnvironments }),
@@ -5,7 +5,7 @@ import type { CodemodeSettings } from "../config/settings.ts";
5
5
  import type { PackagesInstallEnvironments } from "../environments/packages-install.ts";
6
6
  import type { HandleRegistry } from "../handles/handle-registry.ts";
7
7
  import type { InterpreterAvailability } from "../interpreters/detect.ts";
8
- import type { SessionEnvironment } from "../kernels/session-env.ts";
8
+ import type { InheritedEnvironment, SessionEnvironment } from "../kernels/session-env.ts";
9
9
  import type { EvalKernelManager, ExecuteTool } from "../tool/types.ts";
10
10
 
11
11
  export interface CodemodeSessionManager extends EvalKernelManager {
@@ -38,6 +38,8 @@ export interface CreateCodemodeSessionManagerOptions {
38
38
  readonly artifactsDir?: string;
39
39
  /** Per-session PI_* values exposed to every kernel and the children it spawns. */
40
40
  readonly sessionEnv?: SessionEnvironment;
41
+ /** The host environment kernel children inherit, without the RPC host's supervisor hand-off (senpi#5635); defaults to process.env. */
42
+ readonly inheritedEnv?: InheritedEnvironment;
41
43
  /** The kill guard is on (`terminal.killGuard` in user settings): kernels judge signals before they leave a cell. */
42
44
  readonly killGuard?: boolean;
43
45
  readonly executeTool: ExecuteTool;
@@ -316,6 +316,7 @@ class DefaultCodemodeSessionManager implements CodemodeSessionManager {
316
316
  : {}),
317
317
  ...(resolveKernelToolsEnabled(this.#options.settings) ? {} : { kernelToolsEnabled: false }),
318
318
  ...(this.#options.sessionEnv ? { sessionEnv: this.#options.sessionEnv } : {}),
319
+ ...(this.#options.inheritedEnv ? { inheritedEnv: this.#options.inheritedEnv } : {}),
319
320
  ...(this.#options.killGuard === true
320
321
  ? { killGuard: { moduleUrl: KILL_GUARD_MODULE_URL, agentPid: process.pid } }
321
322
  : {}),
@@ -342,6 +343,7 @@ class DefaultCodemodeSessionManager implements CodemodeSessionManager {
342
343
  cwd: this.#options.cwd,
343
344
  ...(sessionEnv ? { sessionEnv } : {}),
344
345
  ...attestation,
346
+ ...(this.#options.inheritedEnv ? { inheritedEnv: this.#options.inheritedEnv } : {}),
345
347
  ...(this.#options.killGuard === true ? { killGuard: { protectedPids: killGuardProtectedPids() } } : {}),
346
348
  connection,
347
349
  onMessage,
@@ -1,6 +1,6 @@
1
1
  import { join } from "node:path";
2
2
  import type { BridgeConnectionConfig, KernelToHostMessage } from "../../bridge/protocol.ts";
3
- import type { SessionEnvironment } from "../session-env.ts";
3
+ import type { InheritedEnvironment, SessionEnvironment } from "../session-env.ts";
4
4
  import type { KernelLifecycle } from "../shared/kernel-death.ts";
5
5
  import type { InvocationPermissions } from "../shared/invocation-authority.ts";
6
6
  import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
@@ -17,6 +17,8 @@ export interface JuliaKernelStartOptions extends KernelLifecycle {
17
17
  readonly sessionEnv?: SessionEnvironment;
18
18
  /** Attests the interpreter process to the session it runs for (senpi#6972). */
19
19
  readonly attestSpawn?: AttestKernelSpawn;
20
+ /** The host environment kernel children inherit, without the RPC host's supervisor hand-off (senpi#5635); defaults to process.env. */
21
+ readonly inheritedEnv?: InheritedEnvironment;
20
22
  readonly command?: string;
21
23
  readonly spawn?: SubprocessSpawn;
22
24
  readonly onMessage?: (message: KernelToHostMessage) => void;
@@ -56,6 +58,7 @@ export class JuliaKernel extends SubprocessKernel {
56
58
  sessionId: options.sessionId,
57
59
  sessionEnv: options.sessionEnv,
58
60
  ...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
61
+ inheritedEnv: options.inheritedEnv,
59
62
  connection: options.connection,
60
63
  spawn: options.spawn,
61
64
  onMessage: options.onMessage,
@@ -1,7 +1,7 @@
1
1
  import type { KernelMemoryThresholds } from "../../bridge/memory-protocol.ts";
2
2
  import type { KernelToHostMessage } from "../../bridge/protocol.ts";
3
3
  import type { EvalKernelRunInput } from "../../tool/types.ts";
4
- import type { SessionEnvironment } from "../session-env.ts";
4
+ import type { InheritedEnvironment, SessionEnvironment } from "../session-env.ts";
5
5
  import type { InvocationPermissions } from "../shared/invocation-authority.ts";
6
6
  import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
7
7
  import type { JavaScriptInterruptBounds } from "./interrupt-bounds.ts";
@@ -64,6 +64,8 @@ export interface JavaScriptKernelOptions {
64
64
  readonly workerEntryUrl?: URL;
65
65
  /** Per-session PI_* values applied to the worker environment before the first cell runs. */
66
66
  readonly sessionEnv?: SessionEnvironment;
67
+ /** The host environment kernel children inherit, without the RPC host's supervisor hand-off (senpi#5635); defaults to process.env. */
68
+ readonly inheritedEnv?: InheritedEnvironment;
67
69
  /** Opt-in child-process kernel; absent keeps the worker-thread kernel. */
68
70
  readonly isolation?: "process";
69
71
  /** Resolution root for the process-mode runtime (bun, then node); `""` names a machine with none on PATH. */
@@ -48,6 +48,8 @@ export interface JavaScriptProcessWorkerOptions {
48
48
  readonly env?: NodeJS.ProcessEnv;
49
49
  /** Attests the kernel process to the session it runs for (senpi#6972). */
50
50
  readonly attestSpawn?: AttestKernelSpawn;
51
+ /** The host environment the child inherits, without the RPC host's supervisor hand-off (senpi#5635). */
52
+ readonly inheritedEnv?: () => Readonly<Record<string, string | undefined>>;
51
53
  readonly spawn?: (
52
54
  command: string,
53
55
  args: readonly string[],
@@ -126,7 +128,7 @@ export function spawnProcessWorker(url: URL, options: JavaScriptProcessWorkerOpt
126
128
  const isBun = runtimeNameOf(command) === "bun";
127
129
  const args = isBun ? [fileURLToPath(url)] : ["--experimental-strip-types", fileURLToPath(url)];
128
130
  const env: NodeJS.ProcessEnv = {
129
- ...process.env,
131
+ ...(options.inheritedEnv?.() ?? process.env),
130
132
  ...options.env,
131
133
  SENPI_CODEMODE_PROCESS_CWD: options.cwd,
132
134
  SENPI_CODEMODE_PROCESS_POOL_WIDTH: String(options.parallelPoolWidth),
@@ -180,7 +180,7 @@ export function createWorkerCore(transport, options) {
180
180
  });
181
181
  return;
182
182
  }
183
- applySessionEnvironment(message.sessionEnv);
183
+ applySessionEnvironment(message.sessionEnv, message.removedEnv, message.inheritedSet);
184
184
  installSessionCwd(options.cwd, options.cwdInstallOptions);
185
185
  installKernelWebView(requestWebViewPort);
186
186
  installPackageResolver();
@@ -263,14 +263,16 @@ function durationMs(startedAtMs) {
263
263
  return Math.max(0, Math.round(performance.now() - startedAtMs));
264
264
  }
265
265
 
266
- function applySessionEnvironment(sessionEnv) {
266
+ // removedEnv/inheritedSet: the RPC host's supervisor hand-off this thread's env copy must not keep, and the origin
267
+ // attribution it carries instead (senpi#5635). Deleted like an unprovided session key, so the pin below covers them.
268
+ function applySessionEnvironment(sessionEnv, removedEnv = [], inheritedSet = {}) {
267
269
  const provided = new Set(Object.keys(sessionEnv ?? {}));
268
270
  const deleted = [];
269
- for (const key of SESSION_ENVIRONMENT_KEYS) {
271
+ for (const key of [...SESSION_ENVIRONMENT_KEYS, ...removedEnv]) {
270
272
  if (key in process.env && !provided.has(key)) deleted.push(key);
271
273
  delete process.env[key];
272
274
  }
273
- const applied = Object.entries(sessionEnv ?? {});
275
+ const applied = [...Object.entries(inheritedSet), ...Object.entries(sessionEnv ?? {})];
274
276
  for (const [key, value] of applied) process.env[key] = value;
275
277
  // A worker's process.env is its own view: Bun.$ and node:child_process read it, but Bun.spawn
276
278
  // without an explicit env inherits the OS environ, which also still holds deleted keys because
@@ -29,7 +29,7 @@ export function installShellCapture(options) {
29
29
  // environment view mirrors the bash tool, which always spawns with an explicit env.
30
30
  originalShell.env({ ...process.env });
31
31
  }
32
- bun.$ = capturedShell(originalShell, options, guard);
32
+ bun.$ = capturedShell(originalShell, options, guard, originalShell.escape, pinEnv);
33
33
  bun.spawn = capturedSpawn(originalSpawn, options, pinEnv, guard);
34
34
  if (originalSpawnSync !== null) bun.spawnSync = capturedSpawnSync(originalSpawnSync, pinEnv, guard);
35
35
  const restoreChildProcessNotice = noticeChildProcessGroupSignals(options.emitText, options.isActive);
@@ -48,7 +48,7 @@ function isBunRuntime(bun) {
48
48
  return bun !== null && typeof bun === "object" && typeof bun.$ === "function" && typeof bun.spawn === "function";
49
49
  }
50
50
 
51
- function capturedShell(originalShell, options, guard, escape = originalShell.escape) {
51
+ function capturedShell(originalShell, options, guard, escape = originalShell.escape, pinEnv = false) {
52
52
  const shell = (strings, ...expressions) => {
53
53
  assertCellLive();
54
54
  guard?.command(renderShellTemplate(strings, expressions, escape), "bun");
@@ -58,7 +58,8 @@ function capturedShell(originalShell, options, guard, escape = originalShell.esc
58
58
  return captureShellPromise(promise, options);
59
59
  };
60
60
  copyShellKeys(shell, originalShell);
61
- if (typeof originalShell.Shell === "function") shell.Shell = capturedShellClass(originalShell.Shell, options, guard, escape);
61
+ if (typeof originalShell.Shell === "function")
62
+ shell.Shell = capturedShellClass(originalShell.Shell, options, guard, escape, pinEnv);
62
63
  for (const method of SHELL_CONFIG_METHODS) {
63
64
  shell[method] = (...args) => {
64
65
  originalShell[method](...args);
@@ -80,10 +81,13 @@ function copyShellKeys(target, source) {
80
81
  }
81
82
 
82
83
  // `new Bun.$.Shell()` builds an independent `$` with its own env and cwd; each instance is judged and captured
83
- // exactly like `Bun.$` itself, so it is no way around the kill guard.
84
- function capturedShellClass(OriginalShell, options, guard, escape) {
84
+ // exactly like `Bun.$` itself, so it is no way around the kill guard. While pinning, an instance starts from the
85
+ // worker's env view like the global `$` (senpi#5635); a later `.env()` on it still replaces that.
86
+ function capturedShellClass(OriginalShell, options, guard, escape, pinEnv) {
85
87
  return function Shell(...args) {
86
- return capturedShell(new OriginalShell(...args), options, guard, escape);
88
+ const instance = new OriginalShell(...args);
89
+ if (pinEnv && typeof instance.env === "function") instance.env({ ...process.env });
90
+ return capturedShell(instance, options, guard, escape, pinEnv);
87
91
  };
88
92
  }
89
93
 
@@ -3,6 +3,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
3
3
  import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
4
4
  import { createInlineWorker, type WorkerLike } from "./inline-worker.ts";
5
5
  import { retireWorker } from "./interrupt-bounds.ts";
6
+ import { inheritedEnvironmentDelta } from "../session-env.ts";
6
7
  import { resolveKernelToolNameSource } from "./kernel-contract.ts";
7
8
  import type { KernelPermissionHost } from "./permission-host.ts";
8
9
  import { type JavaScriptKernelOptions, localBridgeConnection } from "./local-module-loader.ts";
@@ -79,6 +80,7 @@ function spawnWorker(options: JavaScriptKernelOptions, permissions?: KernelPermi
79
80
  cwd: options.cwd,
80
81
  parallelPoolWidth: options.parallelPoolWidth,
81
82
  ...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
83
+ ...(options.inheritedEnv === undefined ? {} : { inheritedEnv: options.inheritedEnv }),
82
84
  ...(options.processCommandPath === undefined ? {} : { searchPath: options.processCommandPath }),
83
85
  ...(options.processExecPath === undefined ? {} : { execPath: options.processExecPath }),
84
86
  });
@@ -106,6 +108,12 @@ async function initializeWorker(worker: WorkerLike, hooks: WorkerStartupHooks, s
106
108
  hostToolNames: resolveKernelToolNameSource(options.hostToolNames),
107
109
  foreignLanguageNames: resolveKernelToolNameSource(options.foreignLanguageNames),
108
110
  ...(options.sessionEnv === undefined ? {} : { sessionEnv: options.sessionEnv }),
111
+ // A worker thread's process.env starts as a copy of the host's, so it is told what to drop and set. That includes
112
+ // the inline fallback, which is a worker thread too. A process kernel already starts from the scrubbed env
113
+ // (senpi#5635, senpi#5653).
114
+ ...(worker.mode !== "process" && options.inheritedEnv !== undefined
115
+ ? inheritedEnvironmentDelta(process.env, options.inheritedEnv())
116
+ : {}),
109
117
  ...(options.memory === undefined ? {} : { memory: options.memory }),
110
118
  ...(options.kernelToolsEnabled === false ? { kernelToolsDisabled: true } : {}),
111
119
  ...(options.killGuard === undefined
@@ -1,7 +1,7 @@
1
1
  import type { KernelMemoryThresholds } from "../../bridge/memory-protocol.ts";
2
2
  import type { BridgeConnectionConfig, KernelToHostMessage } from "../../bridge/protocol.ts";
3
3
  import type { EvalKernelRunInput } from "../../tool/types.ts";
4
- import type { SessionEnvironment } from "../session-env.ts";
4
+ import type { InheritedEnvironment, SessionEnvironment } from "../session-env.ts";
5
5
  import type { KernelLifecycle } from "../shared/kernel-death.ts";
6
6
  import type { InvocationPermissions } from "../shared/invocation-authority.ts";
7
7
  import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
@@ -23,6 +23,8 @@ export interface PythonKernelStartOptions extends KernelLifecycle {
23
23
  readonly sessionEnv?: SessionEnvironment;
24
24
  /** Attests the interpreter process to the session it runs for (senpi#6972). */
25
25
  readonly attestSpawn?: AttestKernelSpawn;
26
+ /** The host environment kernel children inherit, without the RPC host's supervisor hand-off (senpi#5635); defaults to process.env. */
27
+ readonly inheritedEnv?: InheritedEnvironment;
26
28
  /** The kill guard (senpi#5349): the host's protected pids; absent = the guard is off for this kernel. */
27
29
  readonly killGuard?: { readonly protectedPids: readonly number[] };
28
30
  /** How long a starting interpreter may show no stage change, output or CPU use before startup fails. */
@@ -9,7 +9,7 @@ import {
9
9
  isKernelToHostMessage,
10
10
  type KernelToHostMessage,
11
11
  } from "../../bridge/protocol.ts";
12
- import { applySessionEnvironment, type SessionEnvironment } from "../session-env.ts";
12
+ import { applySessionEnvironment, type InheritedEnvironment, type SessionEnvironment } from "../session-env.ts";
13
13
  import type { KernelPreludePlan } from "../shared/kernel-prelude-plan.ts";
14
14
  import { type AttestKernelSpawn, attestKernelChild } from "../shared/session-spawn-attestation.ts";
15
15
  import { readKernelCpuTime } from "../shared/process-cpu.ts";
@@ -53,6 +53,8 @@ export interface PythonTransportOptions {
53
53
  readonly sessionEnv?: SessionEnvironment;
54
54
  /** Attests the interpreter process to the session it runs for (senpi#6972). */
55
55
  readonly attestSpawn?: AttestKernelSpawn;
56
+ /** The host environment kernel children inherit, without the RPC host's supervisor hand-off (senpi#5635); defaults to process.env. */
57
+ readonly inheritedEnv?: InheritedEnvironment;
56
58
  /** The kill guard (senpi#5349): the host's protected pids; absent = the guard is off for this kernel. */
57
59
  readonly killGuard?: { readonly protectedPids: readonly number[] };
58
60
  readonly startupTimeoutMs: number;
@@ -134,7 +136,7 @@ export class PythonKernelTransport {
134
136
  args: [...invocation.args, "-u", scriptPath],
135
137
  cwd: options.cwd,
136
138
  env: {
137
- ...applySessionEnvironment(process.env, options.sessionEnv),
139
+ ...applySessionEnvironment(options.inheritedEnv?.() ?? process.env, options.sessionEnv),
138
140
  ...options.env,
139
141
  PYTHONUNBUFFERED: "1",
140
142
  PYTHONIOENCODING: "utf-8",
@@ -1,6 +1,6 @@
1
1
  import { join } from "node:path";
2
2
  import type { BridgeConnectionConfig, KernelToHostMessage } from "../../bridge/protocol.ts";
3
- import type { SessionEnvironment } from "../session-env.ts";
3
+ import type { InheritedEnvironment, SessionEnvironment } from "../session-env.ts";
4
4
  import type { KernelLifecycle } from "../shared/kernel-death.ts";
5
5
  import type { InvocationPermissions } from "../shared/invocation-authority.ts";
6
6
  import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
@@ -17,6 +17,8 @@ export interface RubyKernelStartOptions extends KernelLifecycle {
17
17
  readonly sessionEnv?: SessionEnvironment;
18
18
  /** Attests the interpreter process to the session it runs for (senpi#6972). */
19
19
  readonly attestSpawn?: AttestKernelSpawn;
20
+ /** The host environment kernel children inherit, without the RPC host's supervisor hand-off (senpi#5635); defaults to process.env. */
21
+ readonly inheritedEnv?: InheritedEnvironment;
20
22
  readonly command?: string;
21
23
  readonly spawn?: SubprocessSpawn;
22
24
  readonly onMessage?: (message: KernelToHostMessage) => void;
@@ -45,6 +47,7 @@ export class RubyKernel extends SubprocessKernel {
45
47
  sessionId: options.sessionId,
46
48
  sessionEnv: options.sessionEnv,
47
49
  ...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
50
+ inheritedEnv: options.inheritedEnv,
48
51
  connection: options.connection,
49
52
  spawn: options.spawn,
50
53
  onMessage: options.onMessage,
@@ -20,6 +20,30 @@ export const SESSION_ENVIRONMENT_KEYS = [
20
20
  "OMO_BROWSER_ENGINE",
21
21
  ] as const;
22
22
 
23
+ /**
24
+ * The environment a kernel and its children inherit from the host: `process.env` without the RPC host's
25
+ * supervisor hand-off, plus the origin attribution (senpi#5635). Computed once by the extension through
26
+ * `childEnvironmentOf` at each spawn, so a restarted kernel sees the host env as it is then; kernels
27
+ * default to `process.env` when none is given.
28
+ */
29
+ export type InheritedEnvironment = () => Readonly<Record<string, string | undefined>>;
30
+
31
+ /**
32
+ * How `inherited` differs from `base`: the names it drops and the values it sets. The worker-thread kernel
33
+ * gets these instead of an env, because its `process.env` starts as a copy of the host's.
34
+ */
35
+ export function inheritedEnvironmentDelta(
36
+ base: Readonly<Record<string, string | undefined>>,
37
+ inherited: Readonly<Record<string, string | undefined>>,
38
+ ): { removedEnv: string[]; inheritedSet: Record<string, string> } {
39
+ const removedEnv = Object.keys(base).filter((name) => !Object.hasOwn(inherited, name));
40
+ const inheritedSet: Record<string, string> = {};
41
+ for (const [name, value] of Object.entries(inherited)) {
42
+ if (value !== undefined && base[name] !== value) inheritedSet[name] = value;
43
+ }
44
+ return { removedEnv, inheritedSet };
45
+ }
46
+
23
47
  /** Resolved per-session values for {@link SESSION_ENVIRONMENT_KEYS}; absent keys stay unset. */
24
48
  export type SessionEnvironment = Readonly<Record<string, string>>;
25
49
 
@@ -1,7 +1,7 @@
1
1
  import type { KernelMemoryThresholds } from "../../bridge/memory-protocol.ts";
2
2
  import type { BridgeConnectionConfig, KernelToHostMessage } from "../../bridge/protocol.ts";
3
3
  import type { EvalKernelRunInput, EvalLanguage } from "../../tool/types.ts";
4
- import type { SessionEnvironment } from "../session-env.ts";
4
+ import type { InheritedEnvironment, SessionEnvironment } from "../session-env.ts";
5
5
  import type { KernelLifecycle } from "./kernel-death.ts";
6
6
  import type { FootprintReader } from "./kernel-memory-host.ts";
7
7
  import type { SubprocessSpawn } from "./subprocess-process.ts";
@@ -30,6 +30,8 @@ export interface SubprocessKernelOptions extends KernelLifecycle {
30
30
  readonly sessionEnv?: SessionEnvironment;
31
31
  /** Attests the interpreter process to the session it runs for (senpi#6972). */
32
32
  readonly attestSpawn?: AttestKernelSpawn;
33
+ /** The host environment kernel children inherit, without the RPC host's supervisor hand-off (senpi#5635); defaults to process.env. */
34
+ readonly inheritedEnv?: InheritedEnvironment;
33
35
  readonly sessionId: string;
34
36
  readonly connection: BridgeConnectionConfig;
35
37
  readonly spawn?: SubprocessSpawn;
@@ -225,8 +225,11 @@ export class SubprocessKernel {
225
225
  ...this.options,
226
226
  env:
227
227
  this.options.env ??
228
- (this.options.sessionEnv
229
- ? applySessionEnvironment(globalThis.process.env, this.options.sessionEnv)
228
+ (this.options.sessionEnv || this.options.inheritedEnv
229
+ ? applySessionEnvironment(
230
+ this.options.inheritedEnv?.() ?? globalThis.process.env,
231
+ this.options.sessionEnv,
232
+ )
230
233
  : undefined),
231
234
  });
232
235
  attestKernelChild(this.options.attestSpawn, child);
@@ -1,5 +1,7 @@
1
1
  export const EVAL_PROMPT_TEMPLATE = `Run one step of code in a persistent kernel.
2
-
2
+ {{#if evalOnlyTools}}
3
+ Eval-only tools (absent from your direct tool list, reachable only here): {{evalOnlyTools}}. Call them inside a cell as \`tool.<name>(args)\`.
4
+ {{/if}}
3
5
  <instruction>
4
6
  **One eval call = one cell = one logical step.** Top-level names persist per language across eval calls{{#if spawns}}, tool calls and \`task\` subagents{{else}} and tool calls{{/if}}: define helpers and clients once and reuse them instead of re-importing or re-reading. For large text, use bounded chunks or write it to a file and read it with offsets; treat truncation notices as incomplete data and follow the full-output path. Rebuild state only after \`reset\`, a kernel restart, or a \`NameError\`/\`ReferenceError\`, and check a sentinel variable first so a re-run cannot duplicate side effects.
5
7
 
@@ -52,8 +54,7 @@ env(key?=None, value?=None) → str | None | dict
52
54
  Task/agent output by id. Reads immediately: running tasks return their status; \`format\` \`"raw"\` = full, \`"tail"\` = trailing.
53
55
  {{/if}}tool.<name>(args) → { text, images?, details?, hasError? }
54
56
  Invoke any session tool; image results (e.g. \`tool.read\` on a png) arrive in \`images[i]\` as { mimeType, dataBase64 }.
55
- {{#if evalOnlyTools}} Eval-only tools (absent from your direct tool list, reachable only here): {{evalOnlyTools}}.
56
- {{/if}}tool_schema(name?) → dict
57
+ tool_schema(name?) → dict
57
58
  { name, description, parameters } of a tool; omit \`name\` → { tools: [every tool name] }; a failed \`tool.<name>()\` call also returns the expected parameters.
58
59
  completion(prompt, model?="default", system?=None, schema?=None) → str | dict
59
60
  Oneshot, stateless. \`model\`: \`"smol"\` fast | \`"default"\` session | \`"slow"\` most capable. \`schema\` (JSON-Schema) → parsed structured output.