@code-yeongyu/senpi-codemode 2026.11.17 → 2026.11.18-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 CHANGED
@@ -1,5 +1,60 @@
1
1
  # Changelog
2
2
 
3
+ ## [2026.11.18-3] - 2026-11-18
4
+
5
+ ### Breaking Changes
6
+
7
+ ### Added
8
+
9
+ ### Changed
10
+
11
+ ### Fixed
12
+
13
+ ### Removed
14
+
15
+ ## [2026.11.18-2] - 2026-11-18
16
+
17
+ ### Breaking Changes
18
+
19
+ ### Added
20
+
21
+ - 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))
22
+
23
+ ### Changed
24
+
25
+ ### Fixed
26
+
27
+ - 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))
28
+
29
+ ### Removed
30
+
31
+ ## [2026.11.18] - 2026-11-18
32
+
33
+ ### Breaking Changes
34
+
35
+ ### Added
36
+
37
+ ### Changed
38
+
39
+ ### Fixed
40
+
41
+ ### Removed
42
+
43
+ ## [2026.11.17-2] - 2026-11-17
44
+
45
+ ### Breaking Changes
46
+
47
+ ### Added
48
+
49
+ ### Changed
50
+
51
+ ### Fixed
52
+
53
+ - A `tool.<name>()` call inside an eval cell is drawn with the tool's own call and result rows when the tool has them, instead of its raw arguments and result JSON ([#6903](https://github.com/code-yeongyu/senpi/pull/6903)).
54
+ - A `tool.<name>()` call inside an eval cell whose result reports `isError: true` is shown and passed to the cell as a failure, not a success ([#6906](https://github.com/code-yeongyu/senpi/pull/6906)).
55
+
56
+ ### Removed
57
+
3
58
  ## [2026.11.17] - 2026-11-17
4
59
 
5
60
  ### Breaking Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-codemode",
3
- "version": "2026.11.17",
3
+ "version": "2026.11.18-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.17",
37
- "@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.17",
36
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.18-3",
37
+ "@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.18-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.17"
42
+ "@code-yeongyu/senpi": "2026.11.18-3"
43
43
  },
44
44
  "devDependencies": {
45
- "@code-yeongyu/senpi": "2026.11.17"
45
+ "@code-yeongyu/senpi": "2026.11.18-3"
46
46
  },
47
47
  "keywords": [
48
48
  "senpi",
@@ -1,4 +1,4 @@
1
- import type { KernelPreludeContribution } from "@code-yeongyu/senpi";
1
+ import type { KernelPreludeContribution, ToolDefinition } from "@code-yeongyu/senpi";
2
2
  import { type Static, Type } from "typebox";
3
3
  import { Check, Errors } from "typebox/value";
4
4
  import { virtualEvalSchema } from "./eval-virtual-schemas.ts";
@@ -17,6 +17,9 @@ export interface EvalSchemaToolInfo {
17
17
  readonly evalOnly?: boolean | undefined;
18
18
  readonly parameters?: unknown;
19
19
  readonly kernelPrelude?: KernelPreludeContribution | undefined;
20
+ /** The tool's own row renderers: a nested `tool.<name>()` call in a cell is drawn with them when present. */
21
+ readonly renderCall?: ToolDefinition["renderCall"];
22
+ readonly renderResult?: ToolDefinition["renderResult"];
20
23
  }
21
24
 
22
25
  export interface RunEvalSchemaOptions {
@@ -8,6 +8,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
10
  import type { SessionEnvironment } from "../kernels/session-env.ts";
11
+ import type { AttestKernelSpawn } from "../kernels/shared/session-spawn-attestation.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,7 @@ export interface SubprocessKernelStart {
25
26
  readonly sessionId: string;
26
27
  readonly cwd: string;
27
28
  readonly sessionEnv?: SessionEnvironment;
29
+ readonly attestSpawn?: AttestKernelSpawn;
28
30
  readonly connection: BridgeConnectionConfig;
29
31
  readonly onMessage: (message: KernelToHostMessage) => void;
30
32
  };
@@ -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,6 +309,7 @@ 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 } }
@@ -333,6 +341,7 @@ class DefaultCodemodeSessionManager implements CodemodeSessionManager {
333
341
  sessionId: this.#options.sessionId,
334
342
  cwd: this.#options.cwd,
335
343
  ...(sessionEnv ? { sessionEnv } : {}),
344
+ ...attestation,
336
345
  ...(this.#options.killGuard === true ? { killGuard: { protectedPids: killGuardProtectedPids() } } : {}),
337
346
  connection,
338
347
  onMessage,
package/src/index.ts CHANGED
@@ -40,6 +40,7 @@ import {
40
40
  } from "./tool/eval-execution-event.ts";
41
41
  import { createEvalTool } from "./tool/eval-tool.ts";
42
42
  import { renderEvalCall, renderEvalResult } from "./tool/render.ts";
43
+ import type { NestedToolRenderers } from "./tool/tool-widgets.ts";
43
44
 
44
45
  // session_before_switch / session_before_fork are veto points another extension can cancel, so they never
45
46
  // tear the runtime down; a switch or fork that goes ahead emits session_shutdown before the old session ends.
@@ -82,6 +83,25 @@ export interface SenpiCodemodeOptions {
82
83
  readonly now?: () => number;
83
84
  }
84
85
 
86
+ /**
87
+ * The row renderers registered tools bring, so a nested `tool.<name>()` call in a cell is drawn like its direct row
88
+ * (oh-my-openagent#12994). The registry is read once per eval result render, on the first lookup, not per nested call
89
+ * and frame; nothing while the runtime cannot be read yet.
90
+ */
91
+ function registeredRenderers(pi: CodemodeExtensionAPI): (toolName: string) => NestedToolRenderers | undefined {
92
+ let byName: ReadonlyMap<string, NestedToolRenderers> | undefined;
93
+ return (toolName) => {
94
+ if (byName === undefined) {
95
+ try {
96
+ byName = new Map(pi.getAllTools().map((tool) => [tool.name, tool]));
97
+ } catch {
98
+ return undefined;
99
+ }
100
+ }
101
+ return byName.get(toolName);
102
+ };
103
+ }
104
+
85
105
  /** Whether the session registry holds `monitor`; false when the runtime cannot be read yet. */
86
106
  function monitorIsRegistered(pi: CodemodeExtensionAPI): boolean {
87
107
  try {
@@ -94,7 +114,11 @@ function monitorIsRegistered(pi: CodemodeExtensionAPI): boolean {
94
114
  export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCodemodeOptions = {}): void {
95
115
  const manager = new SessionManagerProxy();
96
116
  const complete = options.complete ?? ((request, ctx) => createCompletionHandler()(ctx)(request));
97
- const renderers = { renderCall: renderEvalCall, renderResult: renderEvalResult };
117
+ const renderers = {
118
+ renderCall: renderEvalCall,
119
+ renderResult: (...[result, options, theme, context]: Parameters<typeof renderEvalResult>) =>
120
+ renderEvalResult(result, options, theme, context, registeredRenderers(pi)),
121
+ };
98
122
  const bunSkillPath = activeBunSkillPath();
99
123
  let activeRuntime: SessionRuntime | undefined;
100
124
  let activeModelId: string | undefined;
@@ -3,6 +3,7 @@ import type { BridgeConnectionConfig, KernelToHostMessage } from "../../bridge/p
3
3
  import type { 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,8 @@ 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;
17
20
  readonly command?: string;
18
21
  readonly spawn?: SubprocessSpawn;
19
22
  readonly onMessage?: (message: KernelToHostMessage) => void;
@@ -52,6 +55,7 @@ export class JuliaKernel extends SubprocessKernel {
52
55
  cwd: options.cwd,
53
56
  sessionId: options.sessionId,
54
57
  sessionEnv: options.sessionEnv,
58
+ ...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
55
59
  connection: options.connection,
56
60
  spawn: options.spawn,
57
61
  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,
@@ -3,6 +3,7 @@ import type { KernelToHostMessage } from "../../bridge/protocol.ts";
3
3
  import type { EvalKernelRunInput } from "../../tool/types.ts";
4
4
  import type { 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,6 +57,8 @@ 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;
@@ -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,8 @@ 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;
48
51
  readonly spawn?: (
49
52
  command: string,
50
53
  args: readonly string[],
@@ -132,6 +135,7 @@ export function spawnProcessWorker(url: URL, options: JavaScriptProcessWorkerOpt
132
135
  options.spawn === undefined
133
136
  ? spawnSubprocess(undefined, { command, args, cwd: options.cwd, env })
134
137
  : options.spawn(command, args, { cwd: options.cwd, env });
138
+ attestKernelChild(options.attestSpawn, child);
135
139
  const messageHandlers = new Set<(message: KernelToHostMessage) => void>();
136
140
  const errorHandlers = new Set<(error: Error) => void>();
137
141
  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 Set<number>();
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") this.#pids.add(pid);
20
- else if (event.state === "exited") this.#pids.delete(pid);
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.
@@ -78,6 +78,7 @@ function spawnWorker(options: JavaScriptKernelOptions, permissions?: KernelPermi
78
78
  return spawnProcessWorker(url, {
79
79
  cwd: options.cwd,
80
80
  parallelPoolWidth: options.parallelPoolWidth,
81
+ ...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
81
82
  ...(options.processCommandPath === undefined ? {} : { searchPath: options.processCommandPath }),
82
83
  ...(options.processExecPath === undefined ? {} : { execPath: options.processExecPath }),
83
84
  });
@@ -4,6 +4,7 @@ import type { EvalKernelRunInput } from "../../tool/types.ts";
4
4
  import type { 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,8 @@ 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;
23
26
  /** The kill guard (senpi#5349): the host's protected pids; absent = the guard is off for this kernel. */
24
27
  readonly killGuard?: { readonly protectedPids: readonly number[] };
25
28
  /** How long a starting interpreter may show no stage change, output or CPU use before startup fails. */
@@ -11,6 +11,7 @@ import {
11
11
  } from "../../bridge/protocol.ts";
12
12
  import { applySessionEnvironment, 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,8 @@ 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;
53
56
  /** The kill guard (senpi#5349): the host's protected pids; absent = the guard is off for this kernel. */
54
57
  readonly killGuard?: { readonly protectedPids: readonly number[] };
55
58
  readonly startupTimeoutMs: number;
@@ -141,6 +144,7 @@ export class PythonKernelTransport {
141
144
  },
142
145
  };
143
146
  const child = (options.spawnProcess ?? defaultSpawn)(spawnOptions);
147
+ attestKernelChild(options.attestSpawn, child);
144
148
  const transport = new PythonKernelTransport(options, child);
145
149
  try {
146
150
  await transport.#initialize();
@@ -3,6 +3,7 @@ import type { BridgeConnectionConfig, KernelToHostMessage } from "../../bridge/p
3
3
  import type { 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,8 @@ 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;
17
20
  readonly command?: string;
18
21
  readonly spawn?: SubprocessSpawn;
19
22
  readonly onMessage?: (message: KernelToHostMessage) => void;
@@ -41,6 +44,7 @@ export class RubyKernel extends SubprocessKernel {
41
44
  cwd: options.cwd,
42
45
  sessionId: options.sessionId,
43
46
  sessionEnv: options.sessionEnv,
47
+ ...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
44
48
  connection: options.connection,
45
49
  spawn: options.spawn,
46
50
  onMessage: options.onMessage,
@@ -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
+ }
@@ -7,6 +7,7 @@ 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,8 @@ 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;
30
33
  readonly sessionId: string;
31
34
  readonly connection: BridgeConnectionConfig;
32
35
  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 {
@@ -228,6 +229,7 @@ export class SubprocessKernel {
228
229
  ? applySessionEnvironment(globalThis.process.env, this.options.sessionEnv)
229
230
  : undefined),
230
231
  });
232
+ attestKernelChild(this.options.attestSpawn, child);
231
233
  const process = new SubprocessProcess(child, {
232
234
  onLine: (source, line) => this.handleLine(source, line),
233
235
  onStderr: (source, data) => this.handleMessage(source, { type: "text", stream: "stderr", data }),
@@ -12,6 +12,8 @@ const MAX_ARGUMENT_ENTRIES = 32;
12
12
  const MAX_ARGUMENT_DEPTH = 6;
13
13
  const MAX_SERIALIZED_ARGUMENT_LENGTH = 4096;
14
14
  const MAX_RESULT_PREVIEW_CODE_POINTS = 160;
15
+ /** The serialized size above which a nested result's details are not kept for its renderer (the eval result persists them). */
16
+ const MAX_CAPTURED_DETAILS_CHARACTERS = 16_384;
15
17
 
16
18
  type BoundedValue = {
17
19
  readonly value: unknown;
@@ -124,6 +126,7 @@ export function recordToolCall(
124
126
  capture: ToolCallCapture,
125
127
  resultPreview: string | undefined,
126
128
  error: string | undefined,
129
+ details?: unknown,
127
130
  ): void {
128
131
  const completedAt = Date.now();
129
132
  settleToolCallMetric(capture.metric, ok, completedAt);
@@ -144,9 +147,27 @@ export function recordToolCall(
144
147
  args: capture.args,
145
148
  ...(capture.argsTruncated === true ? { argsTruncated: true } : {}),
146
149
  ...(resultPreview === undefined ? {} : { resultPreview }),
150
+ ...(details === undefined ? {} : { details }),
147
151
  });
148
152
  }
149
153
 
154
+ /**
155
+ * A plain JSON copy of a nested result's details for the tool's own renderResult, or undefined when there are none, they
156
+ * are not JSON, or they serialize past MAX_CAPTURED_DETAILS_CHARACTERS: the summary then keeps only its text preview.
157
+ */
158
+ export function toolCallResultDetails(result: AgentToolResult<unknown>): unknown {
159
+ if (result.details === undefined) return undefined;
160
+ let serialized: string | undefined;
161
+ try {
162
+ serialized = JSON.stringify(result.details);
163
+ } catch {
164
+ return undefined;
165
+ }
166
+ if (serialized === undefined || serialized.length > MAX_CAPTURED_DETAILS_CHARACTERS) return undefined;
167
+ const copy: unknown = JSON.parse(serialized);
168
+ return copy;
169
+ }
170
+
150
171
  export function toolCallResultPreview(result: AgentToolResult<unknown>): string | undefined {
151
172
  for (const part of result.content) {
152
173
  if (part.type !== "text") continue;
@@ -26,6 +26,7 @@ import type { EvalImageResizer } from "./image.ts";
26
26
  import { type ResolvedToolReply, runNestedTool } from "./nested-tool-call.ts";
27
27
  import type { CellToolUpdateSink } from "./nested-tool-output.ts";
28
28
  import { upsertStatusEvent } from "./status-events.ts";
29
+ import { isCoreWidgetName } from "./tool-widgets.ts";
29
30
  import type { EvalKernel, EvalStatusEvent, EvalToolDetails } from "./types.ts";
30
31
 
31
32
  export type { CellState } from "./cell-runtime.ts";
@@ -191,7 +192,14 @@ export class CellHandler {
191
192
  }
192
193
  await this.#deliverToolReply(
193
194
  message,
194
- () => runNestedTool(this.#runtime.executeTool, message, this.#state.signal, this.#resultBuilder),
195
+ () =>
196
+ runNestedTool(
197
+ this.#runtime.executeTool,
198
+ message,
199
+ this.#state.signal,
200
+ this.#resultBuilder,
201
+ this.#drawsOwnRow(message.toolName),
202
+ ),
195
203
  capture,
196
204
  );
197
205
  }
@@ -204,7 +212,14 @@ export class CellHandler {
204
212
  try {
205
213
  const reply = await resolve();
206
214
  if (!this.#state.active) return;
207
- recordToolCall(this.#state.toolCalls, reply.toolCallOk, capture, reply.resultPreview, reply.errorText);
215
+ recordToolCall(
216
+ this.#state.toolCalls,
217
+ reply.toolCallOk,
218
+ capture,
219
+ reply.resultPreview,
220
+ reply.errorText,
221
+ reply.details,
222
+ );
208
223
  this.#kernel.deliverToolReply({ type: "tool-reply", callId: message.callId, ok: true, value: reply.value });
209
224
  } catch (error) {
210
225
  if (!this.#state.active) return;
@@ -231,6 +246,13 @@ export class CellHandler {
231
246
  return this.#runtime.listTools?.().find((tool) => tool.name === toolName)?.parameters;
232
247
  }
233
248
 
249
+ /** True when the tool draws its own result row, so its nested call keeps the details that row is drawn from. */
250
+ #drawsOwnRow(toolName: string): boolean {
251
+ // The six core tools are drawn by codemode's own widgets, which never read the kept details.
252
+ if (isCoreWidgetName(toolName)) return false;
253
+ return this.#runtime.listTools?.().find((tool) => tool.name === toolName)?.renderResult !== undefined;
254
+ }
255
+
234
256
  #recordStatus(event: EvalStatusEvent): void {
235
257
  if (!this.#runtime.settings.statusEvents) return;
236
258
  upsertStatusEvent(this.#state.statusEvents, event);
@@ -1,7 +1,7 @@
1
1
  import { sanitizeTerminalLabel } from "@code-yeongyu/senpi";
2
2
  import type { KernelToHostMessage } from "../bridge/protocol.ts";
3
3
  import type { AgentExecuteTool } from "../bridges/agent-bridge.ts";
4
- import { capCodePoints, toolCallResultPreview } from "./call-capture.ts";
4
+ import { capCodePoints, toolCallResultDetails, toolCallResultPreview } from "./call-capture.ts";
5
5
  import type { CellResultBuilder } from "./cell-runtime.ts";
6
6
  import { marshalToolResult, toolResultIsError } from "./image.ts";
7
7
 
@@ -10,6 +10,8 @@ export type ResolvedToolReply = {
10
10
  readonly toolCallOk: boolean;
11
11
  readonly resultPreview?: string;
12
12
  readonly errorText?: string;
13
+ /** The result's details, kept only for a tool whose own renderResult draws its nested row. */
14
+ readonly details?: unknown;
13
15
  };
14
16
 
15
17
  /** Runs an ordinary host tool for a JS cell; its partial results stream into the cell's live update (#6167). */
@@ -18,18 +20,22 @@ export async function runNestedTool(
18
20
  message: Extract<KernelToHostMessage, { type: "tool-call" }>,
19
21
  signal: AbortSignal,
20
22
  live: CellResultBuilder,
23
+ keepDetails = false,
21
24
  ): Promise<ResolvedToolReply> {
22
25
  const result = await executeTool(message.toolName, message.args, {
23
26
  signal,
24
27
  onUpdate: (partial) => live.nestedToolUpdate(message.callId, partial),
25
28
  }).finally(() => live.dropNestedTool(message.callId));
26
29
  const toolCallOk = !toolResultIsError(result);
30
+ const details = keepDetails ? toolCallResultDetails(result) : undefined;
31
+ const kept = details === undefined ? {} : { details };
27
32
  if (toolCallOk) {
28
33
  const resultPreview = toolCallResultPreview(result);
29
34
  return {
30
35
  value: marshalToolResult(result),
31
36
  toolCallOk,
32
37
  ...(resultPreview === undefined ? {} : { resultPreview }),
38
+ ...kept,
33
39
  };
34
40
  }
35
41
  let errorText: string | undefined;
@@ -42,5 +48,6 @@ export async function runNestedTool(
42
48
  value: marshalToolResult(result),
43
49
  toolCallOk,
44
50
  ...(errorText === undefined ? {} : { errorText }),
51
+ ...kept,
45
52
  };
46
53
  }
@@ -27,7 +27,7 @@ import {
27
27
  TOOL_CALL_PREVIEW_COUNT,
28
28
  } from "./render-blocks.ts";
29
29
  import { renderCell } from "./render-cell.ts";
30
- import { renderToolCallWidget } from "./tool-widgets.ts";
30
+ import { type NestedToolRenderers, renderToolCallWidget } from "./tool-widgets.ts";
31
31
  import type { EvalResultDetails, EvalToolDetails, EvalToolRequest } from "./types.ts";
32
32
 
33
33
  type ToolCallRow = {
@@ -182,6 +182,7 @@ export function nestedToolCallBlock(
182
182
  theme: Theme | undefined,
183
183
  cwd: string,
184
184
  expanded: boolean,
185
+ renderers?: (toolName: string) => NestedToolRenderers | undefined,
185
186
  ): RenderBlock | undefined {
186
187
  const toolCalls = details?.toolCalls;
187
188
  if (theme === undefined || toolCalls === undefined || !toolCalls.some((call) => call.args !== undefined)) {
@@ -207,7 +208,10 @@ export function nestedToolCallBlock(
207
208
  };
208
209
  for (const [index, call] of retainedCalls.entries()) {
209
210
  if (call.args !== undefined) {
210
- appendLines(lines, renderToolCallWidget(call, { cwd, theme, expanded, width }));
211
+ appendLines(
212
+ lines,
213
+ renderToolCallWidget(call, { cwd, theme, expanded, width, ...(renderers ? { renderers } : {}) }),
214
+ );
211
215
  } else {
212
216
  appendLines(lines, renderToolCall(retainedRows[index], legacyBlock, width));
213
217
  }
@@ -20,7 +20,7 @@ import { nestedToolCallBlock, renderDetailedLines, renderJsonOutputs, toolCallRo
20
20
  import { hasLiveCell } from "./render-live.ts";
21
21
  import { formatThroughputBadge, renderStatusEvents } from "./render-status.ts";
22
22
  import { formatRuntimeBadge } from "./runtime-label.ts";
23
- import { formatDuration } from "./tool-widgets.ts";
23
+ import { formatDuration, type NestedToolRenderers } from "./tool-widgets.ts";
24
24
  import type { EvalResultDetails, EvalStatusEvent, EvalToolDetails } from "./types.ts";
25
25
 
26
26
  function textOutput(result: AgentToolResult<EvalResultDetails>, showImageFallback: boolean): string {
@@ -88,6 +88,7 @@ export function renderEvalResult(
88
88
  options: ToolRenderResultOptions,
89
89
  theme: Theme | undefined,
90
90
  context: ResultRenderContext,
91
+ renderers?: (toolName: string) => NestedToolRenderers | undefined,
91
92
  ): EvalRenderComponent {
92
93
  const component = componentFor(context);
93
94
  const details = result.details;
@@ -124,7 +125,7 @@ export function renderEvalResult(
124
125
  },
125
126
  ];
126
127
  const calls = toolCallRows(details);
127
- const nestedCalls = nestedToolCallBlock(details, theme, context.cwd, expanded);
128
+ const nestedCalls = nestedToolCallBlock(details, theme, context.cwd, expanded, renderers);
128
129
  if (calls.length > 0)
129
130
  blocks.push({ kind: "blank" }, nestedCalls ?? { kind: "toolCalls", calls, expanded, theme });
130
131
  component.setBlocks(blocks);
@@ -195,7 +196,7 @@ export function renderEvalResult(
195
196
  );
196
197
  }
197
198
  const calls = toolCallRows(details);
198
- const nestedCalls = nestedToolCallBlock(details, theme, context.cwd, expanded);
199
+ const nestedCalls = nestedToolCallBlock(details, theme, context.cwd, expanded, renderers);
199
200
  if (calls.length > 0) blocks.push({ kind: "blank" }, nestedCalls ?? { kind: "toolCalls", calls, expanded, theme });
200
201
  component.setBlocks(blocks);
201
202
  return component;
@@ -17,7 +17,12 @@ export function marshalToolResult(result: AgentToolResult<unknown>) {
17
17
  return images.length === 0 && details === undefined && !hasError ? { text } : { text, details, images, hasError };
18
18
  }
19
19
 
20
+ /**
21
+ * Whether a nested tool call failed: the result's own `isError` (the documented way to fail without throwing,
22
+ * senpi#6904), or `details.isError` from tools that still report it there.
23
+ */
20
24
  export function toolResultIsError(result: AgentToolResult<unknown>): boolean {
25
+ if (result.isError === true) return true;
21
26
  const details = result.details;
22
27
  return typeof details === "object" && details !== null && "isError" in details && details.isError === true;
23
28
  }
@@ -20,8 +20,16 @@ export interface WidgetOptions {
20
20
  readonly theme: Theme | undefined;
21
21
  readonly expanded: boolean;
22
22
  readonly width: number;
23
+ /** The registered tool's own row renderers, by tool name; a tool without them keeps the generic row. */
24
+ readonly renderers?: (toolName: string) => NestedToolRenderers | undefined;
23
25
  }
24
26
 
27
+ /** What a registered tool brings to draw its own nested row. */
28
+ export type NestedToolRenderers = {
29
+ readonly renderCall?: ToolDefinition["renderCall"];
30
+ readonly renderResult?: ToolDefinition["renderResult"];
31
+ };
32
+
25
33
  type AnyToolDef<TParams extends TSchema, TDetails, TState> = ToolDefinition<TParams, TDetails, TState>;
26
34
  type RenderCallOf<TParams extends TSchema, TDetails, TState> = NonNullable<
27
35
  AnyToolDef<TParams, TDetails, TState>["renderCall"]
@@ -37,6 +45,7 @@ type CoreWidgets = Readonly<Record<CoreWidgetName, CoreWidgetRenderer>>;
37
45
 
38
46
  const MIN_RENDERER_WIDTH = 20;
39
47
  const MAX_RENDERER_LINES = 5;
48
+ const MAX_EXPANDED_RESULT_LINES = 40;
40
49
  const MAX_FALLBACK_ARGUMENT_CODE_POINTS = 120;
41
50
  const MAX_COLLAPSED_ERROR_CODE_POINTS = 512;
42
51
  const MAX_COLLAPSED_ERROR_LINES = 4;
@@ -128,12 +137,123 @@ function renderWith<TParams extends TSchema, TDetails, TState>(
128
137
 
129
138
  try {
130
139
  const component: Component<TParams, TDetails, TState> = renderCall(preparedArgs, theme, context);
131
- const renderedLines = component.render(innerWidth).map((line) => line.trimEnd());
132
- const retainedLines = renderedLines.slice(0, MAX_RENDERER_LINES);
133
- if (renderedLines.length > retainedLines.length) {
134
- retainedLines.push(style(theme, "muted", WIDGET_TRUNCATION_MARKER));
135
- }
136
- return indent(retainedLines);
140
+ return cappedLines(component, innerWidth, MAX_RENDERER_LINES, theme);
141
+ } catch {
142
+ return undefined;
143
+ }
144
+ }
145
+
146
+ /** A renderer's lines, cut to `maxLines` with a marker, indented under the call. */
147
+ function cappedLines(
148
+ component: { render(width: number): string[] },
149
+ innerWidth: number,
150
+ maxLines: number,
151
+ theme: Theme,
152
+ ): string[] {
153
+ const renderedLines = component.render(innerWidth).map((line) => line.trimEnd());
154
+ const retainedLines = renderedLines.slice(0, maxLines);
155
+ if (renderedLines.length > retainedLines.length) {
156
+ retainedLines.push(style(theme, "muted", WIDGET_TRUNCATION_MARKER));
157
+ }
158
+ return indent(retainedLines);
159
+ }
160
+
161
+ type OwnRenderContext = Parameters<NonNullable<ToolDefinition["renderCall"]>>[2];
162
+ type OwnComponent = ReturnType<NonNullable<ToolDefinition["renderCall"]>>;
163
+
164
+ /**
165
+ * What a tool's own renderers keep between the frames that redraw one nested call: their `state` and the components
166
+ * they returned, as the TUI keeps them for a direct row. Without it every frame handed a renderer fresh state, and one
167
+ * that prefetches (the edit row's diff read) started that work again on every frame. Keyed by the summary object, so a
168
+ * call's entry goes away with the eval result that holds it.
169
+ */
170
+ type OwnRowMemory = { readonly state: Record<string, unknown>; call?: OwnComponent; result?: OwnComponent };
171
+ const ownRowMemory = new WeakMap<EvalToolCallSummary, OwnRowMemory>();
172
+
173
+ function ownRowMemoryOf(summary: EvalToolCallSummary): OwnRowMemory {
174
+ let memory = ownRowMemory.get(summary);
175
+ if (memory === undefined) {
176
+ memory = { state: {} };
177
+ ownRowMemory.set(summary, memory);
178
+ }
179
+ return memory;
180
+ }
181
+
182
+ function ownRenderContext(
183
+ summary: EvalToolCallSummary,
184
+ options: WidgetOptions,
185
+ hasResult: boolean,
186
+ memory: OwnRowMemory,
187
+ ): OwnRenderContext {
188
+ return {
189
+ args: summary.args,
190
+ toolCallId: summary.callId ?? summary.name,
191
+ invalidate: () => {},
192
+ lastComponent: hasResult ? memory.result : memory.call,
193
+ state: memory.state,
194
+ cwd: options.cwd,
195
+ executionStarted: true,
196
+ argsComplete: true,
197
+ isPartial: false,
198
+ expanded: options.expanded,
199
+ showImages: false,
200
+ isError: !summary.ok,
201
+ hasResult,
202
+ };
203
+ }
204
+
205
+ /**
206
+ * The call line a registered tool draws for itself, as its direct row would. Its renderer already takes partial
207
+ * arguments (the TUI calls it while they stream), so only truncated captures, a narrow width or a throwing renderer
208
+ * fall back to the generic row.
209
+ */
210
+ function renderOwnCall(
211
+ own: NestedToolRenderers,
212
+ summary: EvalToolCallSummary,
213
+ options: WidgetOptions,
214
+ ): string[] | undefined {
215
+ const theme = options.theme;
216
+ const innerWidth = options.width - 2;
217
+ if (own.renderCall === undefined || theme === undefined || innerWidth < MIN_RENDERER_WIDTH || summary.argsTruncated)
218
+ return undefined;
219
+ try {
220
+ const memory = ownRowMemoryOf(summary);
221
+ memory.call = own.renderCall(summary.args, theme, ownRenderContext(summary, options, false, memory));
222
+ return cappedLines(memory.call, innerWidth, MAX_RENDERER_LINES, theme);
223
+ } catch {
224
+ return undefined;
225
+ }
226
+ }
227
+
228
+ /** The result a registered tool draws for itself from the details its nested call kept; undefined keeps the preview. */
229
+ function renderOwnResult(
230
+ own: NestedToolRenderers,
231
+ summary: EvalToolCallSummary,
232
+ options: WidgetOptions,
233
+ ): string[] | undefined {
234
+ const theme = options.theme;
235
+ const innerWidth = options.width - 2;
236
+ if (
237
+ own.renderResult === undefined ||
238
+ summary.details === undefined ||
239
+ theme === undefined ||
240
+ innerWidth < MIN_RENDERER_WIDTH
241
+ )
242
+ return undefined;
243
+ try {
244
+ const memory = ownRowMemoryOf(summary);
245
+ memory.result = own.renderResult(
246
+ { content: [{ type: "text", text: summary.resultPreview ?? summary.error ?? "" }], details: summary.details },
247
+ { expanded: options.expanded, isPartial: false },
248
+ theme,
249
+ ownRenderContext(summary, options, true, memory),
250
+ );
251
+ return cappedLines(
252
+ memory.result,
253
+ innerWidth,
254
+ options.expanded ? MAX_EXPANDED_RESULT_LINES : MAX_RENDERER_LINES,
255
+ theme,
256
+ );
137
257
  } catch {
138
258
  return undefined;
139
259
  }
@@ -185,7 +305,7 @@ function coreWidgetsFor(cwd: string): CoreWidgets {
185
305
  return widgets;
186
306
  }
187
307
 
188
- function isCoreWidgetName(name: string): name is CoreWidgetName {
308
+ export function isCoreWidgetName(name: string): name is CoreWidgetName {
189
309
  switch (name) {
190
310
  case "bash":
191
311
  case "read":
@@ -260,12 +380,18 @@ function renderError(error: string, options: WidgetOptions, width: number): stri
260
380
  */
261
381
  export function renderToolCallWidget(summary: EvalToolCallSummary, options: WidgetOptions): string[] {
262
382
  const innerWidth = Math.max(1, options.width - 2);
263
- const coreLines = isCoreWidgetName(summary.name)
383
+ const own = isCoreWidgetName(summary.name) ? undefined : options.renderers?.(summary.name);
384
+ const callLines = isCoreWidgetName(summary.name)
264
385
  ? coreWidgetsFor(options.cwd)[summary.name](summary, options)
265
- : undefined;
266
- const lines = coreLines ?? renderFallback(summary, innerWidth);
386
+ : own === undefined
387
+ ? undefined
388
+ : renderOwnCall(own, summary, options);
389
+ const lines = callLines ?? renderFallback(summary, innerWidth);
267
390
  lines.push(...renderStatus(summary, options, innerWidth));
268
- if (summary.ok && summary.resultPreview !== undefined) {
391
+ const resultLines = own === undefined ? undefined : renderOwnResult(own, summary, options);
392
+ if (resultLines !== undefined) {
393
+ lines.push(...resultLines);
394
+ } else if (summary.ok && summary.resultPreview !== undefined) {
269
395
  lines.push(...renderPreview(summary.resultPreview, options, innerWidth));
270
396
  } else if (!summary.ok && summary.error !== undefined) {
271
397
  lines.push(...renderError(summary.error, options, innerWidth));