@code-yeongyu/senpi-codemode 2026.11.18 → 2026.11.19-3
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 +67 -0
- package/package.json +5 -5
- package/src/bridge/protocol.ts +3 -0
- package/src/environments/py-environment.ts +2 -0
- package/src/environments/py-installer.ts +4 -3
- package/src/environments/python-environments.ts +3 -0
- package/src/extension/kernel-registration.ts +4 -1
- package/src/extension/runtime-factory.ts +6 -1
- package/src/extension/session-manager-contract.ts +3 -1
- package/src/extension/session-manager.ts +11 -0
- package/src/kernels/jl/kernel.ts +8 -1
- package/src/kernels/js/context-manager.ts +1 -1
- package/src/kernels/js/kernel-contract.ts +6 -1
- package/src/kernels/js/process-worker.ts +7 -1
- package/src/kernels/js/worker-children.ts +14 -5
- package/src/kernels/js/worker-core.js +6 -4
- package/src/kernels/js/worker-shell-capture.js +10 -6
- package/src/kernels/js/worker-startup.ts +9 -0
- package/src/kernels/py/kernel-contract.ts +6 -1
- package/src/kernels/py/transport.ts +8 -2
- package/src/kernels/rb/kernel.ts +8 -1
- package/src/kernels/session-env.ts +24 -0
- package/src/kernels/shared/session-spawn-attestation.ts +21 -0
- package/src/kernels/shared/subprocess-contract.ts +6 -1
- package/src/kernels/shared/subprocess-kernel.ts +7 -2
- package/src/prompt/eval-prompt-template.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,72 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2026.11.19-3] - 2026-11-19
|
|
4
|
+
|
|
5
|
+
### Breaking Changes
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- 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))
|
|
14
|
+
- 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))
|
|
15
|
+
|
|
16
|
+
### Removed
|
|
17
|
+
|
|
18
|
+
## [2026.11.19-2] - 2026-11-19
|
|
19
|
+
|
|
20
|
+
### Breaking Changes
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
### Removed
|
|
29
|
+
|
|
30
|
+
## [2026.11.19] - 2026-11-19
|
|
31
|
+
|
|
32
|
+
### Breaking Changes
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
40
|
+
### Removed
|
|
41
|
+
|
|
42
|
+
## [2026.11.18-3] - 2026-11-18
|
|
43
|
+
|
|
44
|
+
### Breaking Changes
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
|
|
52
|
+
### Removed
|
|
53
|
+
|
|
54
|
+
## [2026.11.18-2] - 2026-11-18
|
|
55
|
+
|
|
56
|
+
### Breaking Changes
|
|
57
|
+
|
|
58
|
+
### Added
|
|
59
|
+
|
|
60
|
+
- Eval kernels attest the processes they run for a session: a python, ruby or julia kernel, or a process-isolated JavaScript kernel, is recorded for its session, so every command it starts (a `Bun.$` command included) resolves to that session; a worker-thread JavaScript kernel attests the `Bun.spawn` children it reports. A `Bun.$` command of a worker-thread kernel is not attested ([#6978](https://github.com/code-yeongyu/senpi/pull/6978))
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
|
|
64
|
+
### Fixed
|
|
65
|
+
|
|
66
|
+
- Eval kernel modules no longer load the senpi host package: the extension hands each kernel the session-bound spawn attestation, so a kernel module loads on its own again (a process-isolated JavaScript kernel resolving its runtime under plain Node, the compiled python host on Windows) ([#6996](https://github.com/code-yeongyu/senpi/pull/6996))
|
|
67
|
+
|
|
68
|
+
### Removed
|
|
69
|
+
|
|
3
70
|
## [2026.11.18] - 2026-11-18
|
|
4
71
|
|
|
5
72
|
### Breaking Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi-codemode",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.19-3",
|
|
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.
|
|
37
|
-
"@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.
|
|
36
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.19-3",
|
|
37
|
+
"@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.19-3",
|
|
38
38
|
"quickjs-wasi": "3.6.2",
|
|
39
39
|
"typebox": "1.3.34"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@code-yeongyu/senpi": "2026.11.
|
|
42
|
+
"@code-yeongyu/senpi": "2026.11.19-3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@code-yeongyu/senpi": "2026.11.
|
|
45
|
+
"@code-yeongyu/senpi": "2026.11.19-3"
|
|
46
46
|
},
|
|
47
47
|
"keywords": [
|
|
48
48
|
"senpi",
|
package/src/bridge/protocol.ts
CHANGED
|
@@ -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(
|
|
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,7 +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 {
|
|
10
|
+
import type { AttestKernelSpawn } from "../kernels/shared/session-spawn-attestation.ts";
|
|
11
|
+
import type { InheritedEnvironment, SessionEnvironment } from "../kernels/session-env.ts";
|
|
11
12
|
import { spawnSubprocess } from "../kernels/shared/subprocess-process.ts";
|
|
12
13
|
import type { EvalKernel, EvalLanguage } from "../tool/types.ts";
|
|
13
14
|
import { type KernelMemoryReading, kernelRegistry, type RegisteredKernelSource } from "./kernel-registry.ts";
|
|
@@ -25,6 +26,8 @@ export interface SubprocessKernelStart {
|
|
|
25
26
|
readonly sessionId: string;
|
|
26
27
|
readonly cwd: string;
|
|
27
28
|
readonly sessionEnv?: SessionEnvironment;
|
|
29
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
30
|
+
readonly inheritedEnv?: InheritedEnvironment;
|
|
28
31
|
readonly connection: BridgeConnectionConfig;
|
|
29
32
|
readonly onMessage: (message: KernelToHostMessage) => void;
|
|
30
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: { ...
|
|
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;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import type { ExtensionContext } from "@code-yeongyu/senpi";
|
|
3
3
|
import {
|
|
4
|
+
attestSessionSpawn,
|
|
4
5
|
decideKillGuardRequest,
|
|
5
6
|
KILL_GUARD_MODULE_URL,
|
|
6
7
|
killGuardProtectedPids,
|
|
@@ -290,6 +291,12 @@ class DefaultCodemodeSessionManager implements CodemodeSessionManager {
|
|
|
290
291
|
const localRoots =
|
|
291
292
|
this.#options.localRoots ??
|
|
292
293
|
(this.#options.artifactsDir ? { local: join(this.#options.artifactsDir, "local") } : undefined);
|
|
294
|
+
// senpi#6972: the kernels attest their processes to the session id the host gave them, never one a cell sets.
|
|
295
|
+
const attestedSessionId = this.#options.sessionEnv?.PI_SESSION_ID;
|
|
296
|
+
const attestation =
|
|
297
|
+
attestedSessionId === undefined
|
|
298
|
+
? {}
|
|
299
|
+
: { attestSpawn: (pid: number) => attestSessionSpawn(attestedSessionId, pid) };
|
|
293
300
|
if (language === "js") {
|
|
294
301
|
const memoryThresholds = resolveKernelMemoryThresholds(this.#options.settings.memory);
|
|
295
302
|
const processIsolation = resolveJsIsolation(this.#options.settings) === "process";
|
|
@@ -302,12 +309,14 @@ class DefaultCodemodeSessionManager implements CodemodeSessionManager {
|
|
|
302
309
|
foreignLanguageNames: () => this.#foreignKernelToolNames(),
|
|
303
310
|
memory: memoryThresholds,
|
|
304
311
|
collectOrphanedChildren,
|
|
312
|
+
...attestation,
|
|
305
313
|
...(processIsolation ? { isolation: "process" as const } : {}),
|
|
306
314
|
...(processIsolation && memoryThresholds !== undefined
|
|
307
315
|
? { processMemory: { thresholds: memoryThresholds, readFootprint: readProcessFootprint } }
|
|
308
316
|
: {}),
|
|
309
317
|
...(resolveKernelToolsEnabled(this.#options.settings) ? {} : { kernelToolsEnabled: false }),
|
|
310
318
|
...(this.#options.sessionEnv ? { sessionEnv: this.#options.sessionEnv } : {}),
|
|
319
|
+
...(this.#options.inheritedEnv ? { inheritedEnv: this.#options.inheritedEnv } : {}),
|
|
311
320
|
...(this.#options.killGuard === true
|
|
312
321
|
? { killGuard: { moduleUrl: KILL_GUARD_MODULE_URL, agentPid: process.pid } }
|
|
313
322
|
: {}),
|
|
@@ -333,6 +342,8 @@ class DefaultCodemodeSessionManager implements CodemodeSessionManager {
|
|
|
333
342
|
sessionId: this.#options.sessionId,
|
|
334
343
|
cwd: this.#options.cwd,
|
|
335
344
|
...(sessionEnv ? { sessionEnv } : {}),
|
|
345
|
+
...attestation,
|
|
346
|
+
...(this.#options.inheritedEnv ? { inheritedEnv: this.#options.inheritedEnv } : {}),
|
|
336
347
|
...(this.#options.killGuard === true ? { killGuard: { protectedPids: killGuardProtectedPids() } } : {}),
|
|
337
348
|
connection,
|
|
338
349
|
onMessage,
|
package/src/kernels/jl/kernel.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
6
7
|
import { readProcessGroupCpuTime } from "../shared/process-group-cpu.ts";
|
|
7
8
|
import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
|
|
8
9
|
import { SubprocessKernel, type SubprocessKernelMemory, type SubprocessSpawn } from "../shared/subprocess-kernel.ts";
|
|
@@ -14,6 +15,10 @@ export interface JuliaKernelStartOptions extends KernelLifecycle {
|
|
|
14
15
|
readonly connection: BridgeConnectionConfig;
|
|
15
16
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
16
17
|
readonly sessionEnv?: SessionEnvironment;
|
|
18
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
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;
|
|
17
22
|
readonly command?: string;
|
|
18
23
|
readonly spawn?: SubprocessSpawn;
|
|
19
24
|
readonly onMessage?: (message: KernelToHostMessage) => void;
|
|
@@ -52,6 +57,8 @@ export class JuliaKernel extends SubprocessKernel {
|
|
|
52
57
|
cwd: options.cwd,
|
|
53
58
|
sessionId: options.sessionId,
|
|
54
59
|
sessionEnv: options.sessionEnv,
|
|
60
|
+
...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
|
|
61
|
+
inheritedEnv: options.inheritedEnv,
|
|
55
62
|
connection: options.connection,
|
|
56
63
|
spawn: options.spawn,
|
|
57
64
|
onMessage: options.onMessage,
|
|
@@ -86,7 +86,7 @@ export class JavaScriptKernel {
|
|
|
86
86
|
clearToolCalls: () => this.#toolCalls.clear(),
|
|
87
87
|
});
|
|
88
88
|
this.#memory = new JavaScriptKernelMemory(options, () => this.#slot.processPid);
|
|
89
|
-
this.#children = new WorkerChildren(options.collectOrphanedChildren);
|
|
89
|
+
this.#children = new WorkerChildren(options.collectOrphanedChildren, options.attestSpawn);
|
|
90
90
|
this.#moduleLoader = new LocalModuleLoader(options);
|
|
91
91
|
this.#slot = new WorkerSlot(
|
|
92
92
|
options,
|
|
@@ -1,8 +1,9 @@
|
|
|
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
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
6
7
|
import type { JavaScriptInterruptBounds } from "./interrupt-bounds.ts";
|
|
7
8
|
import type { CellDecision, CellOperation, CellRule } from "./permission-slots.mjs";
|
|
8
9
|
|
|
@@ -56,11 +57,15 @@ export interface JavaScriptKernelOptions {
|
|
|
56
57
|
* wait on them. Absent, they stay zombies until the host's child reaper or process exit collects them.
|
|
57
58
|
*/
|
|
58
59
|
readonly collectOrphanedChildren?: (pids: readonly number[]) => Promise<unknown>;
|
|
60
|
+
/** Attests the kernel process and each child it reports to the session (senpi#6972); absent, none is recorded. */
|
|
61
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
59
62
|
readonly parallelPoolWidth: number;
|
|
60
63
|
readonly onMessage?: (message: KernelToHostMessage) => void;
|
|
61
64
|
readonly workerEntryUrl?: URL;
|
|
62
65
|
/** Per-session PI_* values applied to the worker environment before the first cell runs. */
|
|
63
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;
|
|
64
69
|
/** Opt-in child-process kernel; absent keeps the worker-thread kernel. */
|
|
65
70
|
readonly isolation?: "process";
|
|
66
71
|
/** Resolution root for the process-mode runtime (bun, then node); `""` names a machine with none on PATH. */
|
|
@@ -7,6 +7,7 @@ import type { KernelToHostMessage } from "../../bridge/protocol.ts";
|
|
|
7
7
|
import { isKernelToHostMessage, parseBridgeJsonLine, validateBridgeMessage } from "../../bridge/protocol.ts";
|
|
8
8
|
import type { EvalRuntimeInfo } from "../../tool/types.ts";
|
|
9
9
|
import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
|
|
10
|
+
import { type AttestKernelSpawn, attestKernelChild } from "../shared/session-spawn-attestation.ts";
|
|
10
11
|
import { type SubprocessLike, SubprocessProcess, spawnSubprocess } from "../shared/subprocess-process.ts";
|
|
11
12
|
import type { WorkerLike } from "./inline-worker.ts";
|
|
12
13
|
import { runtimeNameOf } from "./runtime-name.ts";
|
|
@@ -45,6 +46,10 @@ export interface JavaScriptProcessWorkerOptions {
|
|
|
45
46
|
readonly searchPath?: string;
|
|
46
47
|
readonly execPath?: string;
|
|
47
48
|
readonly env?: NodeJS.ProcessEnv;
|
|
49
|
+
/** Attests the kernel process to the session it runs for (senpi#6972). */
|
|
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>>;
|
|
48
53
|
readonly spawn?: (
|
|
49
54
|
command: string,
|
|
50
55
|
args: readonly string[],
|
|
@@ -123,7 +128,7 @@ export function spawnProcessWorker(url: URL, options: JavaScriptProcessWorkerOpt
|
|
|
123
128
|
const isBun = runtimeNameOf(command) === "bun";
|
|
124
129
|
const args = isBun ? [fileURLToPath(url)] : ["--experimental-strip-types", fileURLToPath(url)];
|
|
125
130
|
const env: NodeJS.ProcessEnv = {
|
|
126
|
-
...process.env,
|
|
131
|
+
...(options.inheritedEnv?.() ?? process.env),
|
|
127
132
|
...options.env,
|
|
128
133
|
SENPI_CODEMODE_PROCESS_CWD: options.cwd,
|
|
129
134
|
SENPI_CODEMODE_PROCESS_POOL_WIDTH: String(options.parallelPoolWidth),
|
|
@@ -132,6 +137,7 @@ export function spawnProcessWorker(url: URL, options: JavaScriptProcessWorkerOpt
|
|
|
132
137
|
options.spawn === undefined
|
|
133
138
|
? spawnSubprocess(undefined, { command, args, cwd: options.cwd, env })
|
|
134
139
|
: options.spawn(command, args, { cwd: options.cwd, env });
|
|
140
|
+
attestKernelChild(options.attestSpawn, child);
|
|
135
141
|
const messageHandlers = new Set<(message: KernelToHostMessage) => void>();
|
|
136
142
|
const errorHandlers = new Set<(error: Error) => void>();
|
|
137
143
|
const frameToken = randomBytes(16).toString("hex");
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { EvalStatusEvent } from "../../bridge/protocol.ts";
|
|
2
|
+
import type { SessionSpawnAttestation } from "@code-yeongyu/senpi";
|
|
3
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
2
4
|
import { terminateProcessTrees } from "./process-tree-host.ts";
|
|
3
5
|
|
|
4
6
|
/** How long a lost worker's children get to honour SIGTERM before the host sends SIGKILL. */
|
|
@@ -6,18 +8,24 @@ const WORKER_LOSS_CHILD_GRACE_MS = 1_000;
|
|
|
6
8
|
|
|
7
9
|
/** Live cell children the worker reported; retired by the host when the worker itself is lost. */
|
|
8
10
|
export class WorkerChildren {
|
|
9
|
-
readonly #pids = new
|
|
11
|
+
readonly #pids = new Map<number, SessionSpawnAttestation | undefined>();
|
|
10
12
|
readonly #collectOrphanedChildren: ((pids: readonly number[]) => Promise<unknown>) | undefined;
|
|
13
|
+
readonly #attest: AttestKernelSpawn | undefined;
|
|
11
14
|
|
|
12
|
-
constructor(collectOrphanedChildren?: (pids: readonly number[]) => Promise<unknown
|
|
15
|
+
constructor(collectOrphanedChildren?: (pids: readonly number[]) => Promise<unknown>, attest?: AttestKernelSpawn) {
|
|
13
16
|
this.#collectOrphanedChildren = collectOrphanedChildren;
|
|
17
|
+
this.#attest = attest;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
track(event: EvalStatusEvent): void {
|
|
17
21
|
const pid = event.pid;
|
|
18
22
|
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return;
|
|
19
|
-
if (event.state === "spawned")
|
|
20
|
-
|
|
23
|
+
if (event.state === "spawned") {
|
|
24
|
+
if (!this.#pids.has(pid)) this.#pids.set(pid, this.#attest?.(pid));
|
|
25
|
+
} else if (event.state === "exited") {
|
|
26
|
+
void this.#pids.get(pid)?.release();
|
|
27
|
+
this.#pids.delete(pid);
|
|
28
|
+
}
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
/**
|
|
@@ -26,7 +34,8 @@ export class WorkerChildren {
|
|
|
26
34
|
*/
|
|
27
35
|
async retire(): Promise<void> {
|
|
28
36
|
if (this.#pids.size === 0) return;
|
|
29
|
-
const pids = [...this.#pids];
|
|
37
|
+
const pids = [...this.#pids.keys()];
|
|
38
|
+
for (const attestation of this.#pids.values()) void attestation?.release();
|
|
30
39
|
this.#pids.clear();
|
|
31
40
|
await terminateProcessTrees(pids, { graceMs: WORKER_LOSS_CHILD_GRACE_MS, ownerPid: process.pid });
|
|
32
41
|
// The worker that owned these children and their exit watchers is gone, so nothing else will wait on them.
|
|
@@ -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
|
-
|
|
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")
|
|
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
|
-
|
|
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
|
-
|
|
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";
|
|
@@ -78,6 +79,8 @@ function spawnWorker(options: JavaScriptKernelOptions, permissions?: KernelPermi
|
|
|
78
79
|
return spawnProcessWorker(url, {
|
|
79
80
|
cwd: options.cwd,
|
|
80
81
|
parallelPoolWidth: options.parallelPoolWidth,
|
|
82
|
+
...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
|
|
83
|
+
...(options.inheritedEnv === undefined ? {} : { inheritedEnv: options.inheritedEnv }),
|
|
81
84
|
...(options.processCommandPath === undefined ? {} : { searchPath: options.processCommandPath }),
|
|
82
85
|
...(options.processExecPath === undefined ? {} : { execPath: options.processExecPath }),
|
|
83
86
|
});
|
|
@@ -105,6 +108,12 @@ async function initializeWorker(worker: WorkerLike, hooks: WorkerStartupHooks, s
|
|
|
105
108
|
hostToolNames: resolveKernelToolNameSource(options.hostToolNames),
|
|
106
109
|
foreignLanguageNames: resolveKernelToolNameSource(options.foreignLanguageNames),
|
|
107
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
|
+
: {}),
|
|
108
117
|
...(options.memory === undefined ? {} : { memory: options.memory }),
|
|
109
118
|
...(options.kernelToolsEnabled === false ? { kernelToolsDisabled: true } : {}),
|
|
110
119
|
...(options.killGuard === undefined
|
|
@@ -1,9 +1,10 @@
|
|
|
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
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
7
8
|
import type { CellDecider, RevocationFailedEvent } from "../js/kernel-contract.ts";
|
|
8
9
|
import type { PeerKernelToolsDescribe } from "./kernel-tools-host.ts";
|
|
9
10
|
import type { KernelSpawnProcess, KillProcessGroup } from "./process.ts";
|
|
@@ -20,6 +21,10 @@ export interface PythonKernelStartOptions extends KernelLifecycle {
|
|
|
20
21
|
readonly env?: NodeJS.ProcessEnv;
|
|
21
22
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
22
23
|
readonly sessionEnv?: SessionEnvironment;
|
|
24
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
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;
|
|
23
28
|
/** The kill guard (senpi#5349): the host's protected pids; absent = the guard is off for this kernel. */
|
|
24
29
|
readonly killGuard?: { readonly protectedPids: readonly number[] };
|
|
25
30
|
/** How long a starting interpreter may show no stage change, output or CPU use before startup fails. */
|
|
@@ -9,8 +9,9 @@ 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
|
+
import { type AttestKernelSpawn, attestKernelChild } from "../shared/session-spawn-attestation.ts";
|
|
14
15
|
import { readKernelCpuTime } from "../shared/process-cpu.ts";
|
|
15
16
|
import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
|
|
16
17
|
import {
|
|
@@ -50,6 +51,10 @@ export interface PythonTransportOptions {
|
|
|
50
51
|
readonly env?: NodeJS.ProcessEnv;
|
|
51
52
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
52
53
|
readonly sessionEnv?: SessionEnvironment;
|
|
54
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
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;
|
|
53
58
|
/** The kill guard (senpi#5349): the host's protected pids; absent = the guard is off for this kernel. */
|
|
54
59
|
readonly killGuard?: { readonly protectedPids: readonly number[] };
|
|
55
60
|
readonly startupTimeoutMs: number;
|
|
@@ -131,7 +136,7 @@ export class PythonKernelTransport {
|
|
|
131
136
|
args: [...invocation.args, "-u", scriptPath],
|
|
132
137
|
cwd: options.cwd,
|
|
133
138
|
env: {
|
|
134
|
-
...applySessionEnvironment(process.env, options.sessionEnv),
|
|
139
|
+
...applySessionEnvironment(options.inheritedEnv?.() ?? process.env, options.sessionEnv),
|
|
135
140
|
...options.env,
|
|
136
141
|
PYTHONUNBUFFERED: "1",
|
|
137
142
|
PYTHONIOENCODING: "utf-8",
|
|
@@ -141,6 +146,7 @@ export class PythonKernelTransport {
|
|
|
141
146
|
},
|
|
142
147
|
};
|
|
143
148
|
const child = (options.spawnProcess ?? defaultSpawn)(spawnOptions);
|
|
149
|
+
attestKernelChild(options.attestSpawn, child);
|
|
144
150
|
const transport = new PythonKernelTransport(options, child);
|
|
145
151
|
try {
|
|
146
152
|
await transport.#initialize();
|
package/src/kernels/rb/kernel.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
6
7
|
import { readProcessGroupCpuTime } from "../shared/process-group-cpu.ts";
|
|
7
8
|
import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
|
|
8
9
|
import { SubprocessKernel, type SubprocessKernelMemory, type SubprocessSpawn } from "../shared/subprocess-kernel.ts";
|
|
@@ -14,6 +15,10 @@ export interface RubyKernelStartOptions extends KernelLifecycle {
|
|
|
14
15
|
readonly connection: BridgeConnectionConfig;
|
|
15
16
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
16
17
|
readonly sessionEnv?: SessionEnvironment;
|
|
18
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
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;
|
|
17
22
|
readonly command?: string;
|
|
18
23
|
readonly spawn?: SubprocessSpawn;
|
|
19
24
|
readonly onMessage?: (message: KernelToHostMessage) => void;
|
|
@@ -41,6 +46,8 @@ export class RubyKernel extends SubprocessKernel {
|
|
|
41
46
|
cwd: options.cwd,
|
|
42
47
|
sessionId: options.sessionId,
|
|
43
48
|
sessionEnv: options.sessionEnv,
|
|
49
|
+
...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
|
|
50
|
+
inheritedEnv: options.inheritedEnv,
|
|
44
51
|
connection: options.connection,
|
|
45
52
|
spawn: options.spawn,
|
|
46
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
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SessionSpawnAttestation } from "@code-yeongyu/senpi";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attests a process this host spawned for a kernel to the session it runs for (senpi#6972): a kernel process, so every
|
|
5
|
+
* descendant (a `Bun.$` command, a python subprocess) resolves to that session, or a child the worker kernel reported.
|
|
6
|
+
*
|
|
7
|
+
* The extension injects it, bound to the session's own id, as it injects `collectOrphanedChildren`: a kernel module
|
|
8
|
+
* never loads the host runtime itself, so it stays loadable on its own (plain Node ESM, a compiled python host).
|
|
9
|
+
* Absent, nothing is recorded.
|
|
10
|
+
*/
|
|
11
|
+
export type AttestKernelSpawn = (pid: number) => SessionSpawnAttestation;
|
|
12
|
+
|
|
13
|
+
/** Attests a spawned kernel child through `attest` and releases the record when the child exits. */
|
|
14
|
+
export function attestKernelChild(
|
|
15
|
+
attest: AttestKernelSpawn | undefined,
|
|
16
|
+
child: { readonly pid?: number; once(event: "exit", listener: () => void): unknown },
|
|
17
|
+
): void {
|
|
18
|
+
if (attest === undefined || child.pid === undefined) return;
|
|
19
|
+
const attestation = attest(child.pid);
|
|
20
|
+
child.once("exit", () => void attestation.release());
|
|
21
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
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";
|
|
8
8
|
import type { SubprocessStartupOptions } from "./subprocess-startup.ts";
|
|
9
9
|
import type { InvocationPermissions } from "./invocation-authority.ts";
|
|
10
|
+
import type { AttestKernelSpawn } from "./session-spawn-attestation.ts";
|
|
10
11
|
|
|
11
12
|
export type KernelRunInput = EvalKernelRunInput;
|
|
12
13
|
|
|
@@ -27,6 +28,10 @@ export interface SubprocessKernelOptions extends KernelLifecycle {
|
|
|
27
28
|
readonly env?: NodeJS.ProcessEnv;
|
|
28
29
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
29
30
|
readonly sessionEnv?: SessionEnvironment;
|
|
31
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
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;
|
|
30
35
|
readonly sessionId: string;
|
|
31
36
|
readonly connection: BridgeConnectionConfig;
|
|
32
37
|
readonly spawn?: SubprocessSpawn;
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
settlePendingRun,
|
|
26
26
|
timeoutResult,
|
|
27
27
|
} from "./subprocess-run.ts";
|
|
28
|
+
import { attestKernelChild } from "./session-spawn-attestation.ts";
|
|
28
29
|
import { SubprocessStartupWatchdog } from "./subprocess-startup.ts";
|
|
29
30
|
|
|
30
31
|
export type {
|
|
@@ -224,10 +225,14 @@ export class SubprocessKernel {
|
|
|
224
225
|
...this.options,
|
|
225
226
|
env:
|
|
226
227
|
this.options.env ??
|
|
227
|
-
(this.options.sessionEnv
|
|
228
|
-
? applySessionEnvironment(
|
|
228
|
+
(this.options.sessionEnv || this.options.inheritedEnv
|
|
229
|
+
? applySessionEnvironment(
|
|
230
|
+
this.options.inheritedEnv?.() ?? globalThis.process.env,
|
|
231
|
+
this.options.sessionEnv,
|
|
232
|
+
)
|
|
229
233
|
: undefined),
|
|
230
234
|
});
|
|
235
|
+
attestKernelChild(this.options.attestSpawn, child);
|
|
231
236
|
const process = new SubprocessProcess(child, {
|
|
232
237
|
onLine: (source, line) => this.handleLine(source, line),
|
|
233
238
|
onStderr: (source, data) => this.handleMessage(source, { type: "text", stream: "stderr", data }),
|
|
@@ -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
|
-
|
|
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.
|