@code-yeongyu/senpi-codemode 2026.11.15-4 → 2026.11.17-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +1 -1
- package/package.json +5 -5
- package/src/bridges/schema-bridge.ts +5 -1
- package/src/extension/eval-notifier.ts +6 -2
- package/src/extension/kernel-preludes.ts +9 -3
- package/src/extension/reachable-tools.ts +5 -0
- package/src/extension/runtime-factory.ts +11 -1
- package/src/index.ts +36 -6
- package/src/kernels/js/worker-shell-capture.js +18 -7
- package/src/prompt/eval-prompt-template.ts +3 -2
- package/src/prompt/eval-prompt.ts +3 -0
- package/src/tool/call-capture.ts +21 -0
- package/src/tool/cell-handler.ts +24 -2
- package/src/tool/eval-tool-options.ts +2 -0
- package/src/tool/eval-tool.ts +1 -0
- package/src/tool/nested-tool-call.ts +8 -1
- package/src/tool/render-detail.ts +6 -2
- package/src/tool/render-result.ts +4 -3
- package/src/tool/tool-result-marshal.ts +5 -0
- package/src/tool/tool-widgets.ts +137 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2026.11.17-2] - 2026-11-17
|
|
4
|
+
|
|
5
|
+
### Breaking Changes
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- 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)).
|
|
14
|
+
- 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)).
|
|
15
|
+
|
|
16
|
+
### Removed
|
|
17
|
+
|
|
18
|
+
## [2026.11.17] - 2026-11-17
|
|
19
|
+
|
|
20
|
+
### Breaking Changes
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Eval kernels and their children get the same withheld view of declared credentials as the bash tool ([#6828](https://github.com/code-yeongyu/senpi/pull/6828))
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- `Bun.spawn` with `null` options or `env: null` inside an eval kernel keeps the pinned worker environment ([#6830](https://github.com/code-yeongyu/senpi/pull/6830))
|
|
31
|
+
- The eval description names every eval-only tool, and the `tool_schema()` prelude entry documents its `{ tools: [...] }` result ([#6887](https://github.com/code-yeongyu/senpi/pull/6887))
|
|
32
|
+
|
|
33
|
+
### Removed
|
|
34
|
+
|
|
3
35
|
## [2026.11.15-4] - 2026-11-15
|
|
4
36
|
|
|
5
37
|
### Breaking Changes
|
package/README.md
CHANGED
|
@@ -380,7 +380,7 @@ options object and asynchronous helpers are `await`-able.
|
|
|
380
380
|
| `env(key?, value?)` | Reads all kernel environment values, one value, or sets one value. Includes the session's `PI_*` values (see [Session environment](#session-environment)). |
|
|
381
381
|
| `tool.<name>(args)` | Invokes an active Senpi tool through the normal `pi.executeTool` pipeline and returns `{ text, images?, details?, hasError? }` in every kernel; image blocks arrive as `images[i] = { mimeType, dataBase64 }`. |
|
|
382
382
|
| `packages.install(manager, requirements, {timeout?})` (js, py) | The `%pip install` (py, manager `"pip"`) or `%bun add` / `%npm add` (js, `"bun"` / `"npm"`) installer as a call: same session environment, receipt (`py`: manager, mode, root, revision, requested, resolved, changed; `js`: installer, mode, revision, added, shadowed), cancellation by `stop` and `environment_install_*` codes; `timeout` defaults to 600 seconds and fails with `environment_install_timeout`. Python: `packages.install("pip", [...], timeout=...)`. |
|
|
383
|
-
| `tool_schema(name?)` | Returns a tool
|
|
383
|
+
| `tool_schema(name?)` | Returns `{ name, description, parameters }` for a tool without calling it; omit `name` to get `{ tools: [every tool name] }`. Five virtual entries document codemode itself on demand and are never listed: `eval:wait`, `eval:helpers`, `eval:kernel-tools`, `eval:environments` (the `%pip`, `%bun`/`%npm`, `%environment` and `%load` magics, their results and error codes) and `eval:isolation` (`isolate: true` cells, their limits and error codes). |
|
|
384
384
|
| `require(specifier)`, `createRequire(path)` (js) | CommonJS loading inside a cell, resolved like `import`: builtins (with or without `node:`), relative files and JSON from the cell's directory, bare packages from the session's project and then its managed package environment (`%bun add`/`%npm add`). A missing module raises the runtime's own `MODULE_NOT_FOUND` error. Like Node's `require`, it carries `require.resolve` (the same lookup the call uses, so both name the same copy; builtins resolve to the runtime's own id), `require.resolve.paths` and `require.cache` (the runtime's CommonJS cache). |
|
|
385
385
|
| `tool(fn, metadata?)` (js) | Registers a named function as a kernel tool for in-process children. `metadata.name` registers it under that name instead of the function's; arguments are still passed in the function's parameter order. |
|
|
386
386
|
| `tool.defined()` / `tool.undefine(name)` (js) | List the kernel tools this kernel defines (sorted), and remove one (`true` if it existed). A descriptor taken before `undefine` can no longer be invoked. Both names are reserved: a kernel tool can't be registered as `defined` or `undefine` (`reserved_tool_name`), and a host tool with either name is shadowed in the `tool` namespace, so it can't be called from a JavaScript cell. |
|
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.17-2",
|
|
4
4
|
"description": "Source-only senpi extension package for codemode evaluation tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/parser": "8.0.4",
|
|
36
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.
|
|
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.17-2",
|
|
37
|
+
"@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.17-2",
|
|
38
38
|
"quickjs-wasi": "3.6.2",
|
|
39
39
|
"typebox": "1.3.34"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@code-yeongyu/senpi": "2026.11.
|
|
42
|
+
"@code-yeongyu/senpi": "2026.11.17-2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@code-yeongyu/senpi": "2026.11.
|
|
45
|
+
"@code-yeongyu/senpi": "2026.11.17-2"
|
|
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";
|
|
@@ -14,8 +14,12 @@ export interface EvalSchemaToolInfo {
|
|
|
14
14
|
readonly name: string;
|
|
15
15
|
readonly description?: string | undefined;
|
|
16
16
|
readonly exposure?: string | undefined;
|
|
17
|
+
readonly evalOnly?: boolean | undefined;
|
|
17
18
|
readonly parameters?: unknown;
|
|
18
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"];
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
export interface RunEvalSchemaOptions {
|
|
@@ -21,6 +21,8 @@ export interface EvalNotifierDeps {
|
|
|
21
21
|
) => void;
|
|
22
22
|
readonly getContext: () => ExtensionContext | undefined;
|
|
23
23
|
readonly getMode: () => EvalNotifyMode;
|
|
24
|
+
/** On a hand (`pi.isLoopRemote()`), the loop that receives a notice applies the session guards, not this side. */
|
|
25
|
+
readonly loopRemote?: () => boolean;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
/** Session-scoped completion injector with the same no-spin guards as terminal notifications. */
|
|
@@ -40,8 +42,10 @@ export class EvalNotifier implements EvalDetachedCellNotifier {
|
|
|
40
42
|
notify(cells: readonly EvalDetachedCellNotification[]): void {
|
|
41
43
|
const mode = this.#deps.getMode();
|
|
42
44
|
if (mode === "off") return;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
if (this.#deps.loopRemote?.() !== true) {
|
|
46
|
+
const ctx = this.#deps.getContext();
|
|
47
|
+
if (ctx === undefined || NON_INTERACTIVE_MODES.has(ctx.mode) || ctx.model === undefined) return;
|
|
48
|
+
}
|
|
45
49
|
const pending = cells.filter((cell) => !this.#notified.has(cell.cellId));
|
|
46
50
|
if (pending.length === 0) return;
|
|
47
51
|
for (const cell of pending) this.#notified.add(cell.cellId);
|
|
@@ -14,9 +14,15 @@ export function activeKernelPreludes(pi: ToolRegistry): readonly KernelPreludeCo
|
|
|
14
14
|
return pi.getAllTools().flatMap((tool) => (tool.kernelPrelude && active.has(tool.name) ? [tool.kernelPrelude] : []));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Identity of the registry-derived parts of the eval description (contribution doc lines and the eval-only tool
|
|
19
|
+
* names); the eval tool re-registers only when it changes.
|
|
20
|
+
*/
|
|
21
|
+
export function evalDescriptionKey(
|
|
22
|
+
preludes: readonly KernelPreludeContribution[],
|
|
23
|
+
evalOnlyTools: readonly string[],
|
|
24
|
+
): string {
|
|
25
|
+
return JSON.stringify([preludes.map((prelude) => prelude.documentation), evalOnlyTools]);
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
/**
|
|
@@ -19,6 +19,11 @@ export function reachableToolNames(pi: ReachableToolRegistry): Set<string> {
|
|
|
19
19
|
return names;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/** The tools the session withholds from the model and routes through eval only, in registration order (senpi#6886). */
|
|
23
|
+
export function evalOnlyToolNames(pi: ReachableToolRegistry): string[] {
|
|
24
|
+
return registeredTools(pi).flatMap((tool) => (tool.evalOnly === true ? [tool.name] : []));
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
// The loader's registry methods throw until the runtime binds (the dedupe probe in
|
|
23
28
|
// coding-agent's codemode-builtin-dedupe.test.ts registers eval before that point); an
|
|
24
29
|
// unreadable registry adds nothing, like promptKernelPreludes.
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type ExtensionContext,
|
|
4
4
|
readKillGuardSetting,
|
|
5
5
|
withBundledBunCommands,
|
|
6
|
+
withCredentialProxy,
|
|
6
7
|
} from "@code-yeongyu/senpi";
|
|
7
8
|
import type { AgentExecuteTool } from "../bridges/agent-bridge.ts";
|
|
8
9
|
import type { EvalSchemaToolInfo } from "../bridges/schema-bridge.ts";
|
|
@@ -100,7 +101,7 @@ export async function createRuntime(
|
|
|
100
101
|
// The kill guard's runtime layer (senpi#5349): kernels and their children get the shims first on PATH and
|
|
101
102
|
// bash's BASH_ENV wrapper, as the bash tool does.
|
|
102
103
|
const killGuardEnv = killGuard ? activeKillGuardEnvironment({ ...process.env, ...pathEntry }) : {};
|
|
103
|
-
const sessionEnv = { ...sessionEnvironmentFrom(ctx), ...pathEntry, ...killGuardEnv };
|
|
104
|
+
const sessionEnv = { ...sessionEnvironmentFrom(ctx), ...pathEntry, ...killGuardEnv, ...withheldCredentialEntries() };
|
|
104
105
|
const configuredPoolWidth = settings.parallelPoolWidth;
|
|
105
106
|
const parallelPoolWidth = Number.isFinite(configuredPoolWidth) ? Math.max(1, Math.trunc(configuredPoolWidth)) : 1;
|
|
106
107
|
const pythonEnvironments =
|
|
@@ -194,6 +195,15 @@ function bundledBunPathEntry(): Record<string, string> {
|
|
|
194
195
|
return value === undefined ? {} : { [pathKey]: value };
|
|
195
196
|
}
|
|
196
197
|
|
|
198
|
+
// senpi#6820: kernels and their children get the bash tool's view of declared credentials (a placeholder plus the
|
|
199
|
+
// proxy route). The session environment overrides each kernel's inherited environment, so the value never reaches one.
|
|
200
|
+
function withheldCredentialEntries(): Record<string, string> {
|
|
201
|
+
const entries: Record<string, string> = {};
|
|
202
|
+
for (const [name, value] of Object.entries(withCredentialProxy(process.env)))
|
|
203
|
+
if (value !== undefined && value !== process.env[name]) entries[name] = value;
|
|
204
|
+
return entries;
|
|
205
|
+
}
|
|
206
|
+
|
|
197
207
|
function sessionIdFrom(event: unknown): string {
|
|
198
208
|
if (typeof event === "object" && event !== null && "sessionId" in event && typeof event.sessionId === "string") {
|
|
199
209
|
return event.sessionId;
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,8 @@ import { type EvalNotificationContent, EvalNotifier } from "./extension/eval-not
|
|
|
15
15
|
import { EVAL_CELLS_STATUS_KEY } from "./extension/eval-status.ts";
|
|
16
16
|
import { EvalStatusTicker } from "./extension/eval-status-ticker.ts";
|
|
17
17
|
import { hostLine, modelIdFrom } from "./extension/host-facts.ts";
|
|
18
|
-
import { activeKernelPreludes,
|
|
18
|
+
import { activeKernelPreludes, evalDescriptionKey, promptKernelPreludes } from "./extension/kernel-preludes.ts";
|
|
19
|
+
import { evalOnlyToolNames } from "./extension/reachable-tools.ts";
|
|
19
20
|
import { registerRemovedToolHints } from "./extension/removed-tool-hints.ts";
|
|
20
21
|
import {
|
|
21
22
|
createExecuteTool,
|
|
@@ -39,6 +40,7 @@ import {
|
|
|
39
40
|
} from "./tool/eval-execution-event.ts";
|
|
40
41
|
import { createEvalTool } from "./tool/eval-tool.ts";
|
|
41
42
|
import { renderEvalCall, renderEvalResult } from "./tool/render.ts";
|
|
43
|
+
import type { NestedToolRenderers } from "./tool/tool-widgets.ts";
|
|
42
44
|
|
|
43
45
|
// session_before_switch / session_before_fork are veto points another extension can cancel, so they never
|
|
44
46
|
// tear the runtime down; a switch or fork that goes ahead emits session_shutdown before the old session ends.
|
|
@@ -61,6 +63,8 @@ export interface CodemodeExtensionAPI {
|
|
|
61
63
|
message: { customType: string; content: EvalNotificationContent; display: boolean },
|
|
62
64
|
options?: { triggerTurn?: boolean; deliverAs?: "steer" | "followUp" | "nextTurn" },
|
|
63
65
|
): void;
|
|
66
|
+
/** True on a hand whose loop runs elsewhere (senpi H3); a host without it is never one. */
|
|
67
|
+
isLoopRemote?(): boolean;
|
|
64
68
|
/** Optional host event bus; a host without one turns extension event emission into a harmless no-op. */
|
|
65
69
|
events?: { emit(name: string, data: unknown): void };
|
|
66
70
|
/** Optional host RPC surface for forwarding extension-owned events to connected clients. */
|
|
@@ -79,6 +83,25 @@ export interface SenpiCodemodeOptions {
|
|
|
79
83
|
readonly now?: () => number;
|
|
80
84
|
}
|
|
81
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
|
+
|
|
82
105
|
/** Whether the session registry holds `monitor`; false when the runtime cannot be read yet. */
|
|
83
106
|
function monitorIsRegistered(pi: CodemodeExtensionAPI): boolean {
|
|
84
107
|
try {
|
|
@@ -91,7 +114,11 @@ function monitorIsRegistered(pi: CodemodeExtensionAPI): boolean {
|
|
|
91
114
|
export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCodemodeOptions = {}): void {
|
|
92
115
|
const manager = new SessionManagerProxy();
|
|
93
116
|
const complete = options.complete ?? ((request, ctx) => createCompletionHandler()(ctx)(request));
|
|
94
|
-
const renderers = {
|
|
117
|
+
const renderers = {
|
|
118
|
+
renderCall: renderEvalCall,
|
|
119
|
+
renderResult: (...[result, options, theme, context]: Parameters<typeof renderEvalResult>) =>
|
|
120
|
+
renderEvalResult(result, options, theme, context, registeredRenderers(pi)),
|
|
121
|
+
};
|
|
95
122
|
const bunSkillPath = activeBunSkillPath();
|
|
96
123
|
let activeRuntime: SessionRuntime | undefined;
|
|
97
124
|
let activeModelId: string | undefined;
|
|
@@ -99,11 +126,12 @@ export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCo
|
|
|
99
126
|
let activeCells: EvalDetachedCellManager | undefined;
|
|
100
127
|
let activeHandles: HandleRegistry | undefined;
|
|
101
128
|
registerEvalCellsRpc(pi.rpc, () => activeCells);
|
|
102
|
-
let
|
|
129
|
+
let promptDocsKey = "";
|
|
103
130
|
const notifier = new EvalNotifier({
|
|
104
131
|
sendMessage: (message, notifyOptions) => pi.sendMessage(message, notifyOptions),
|
|
105
132
|
getContext: () => activeContext,
|
|
106
133
|
getMode: () => "wake",
|
|
134
|
+
loopRemote: () => pi.isLoopRemote?.() === true,
|
|
107
135
|
});
|
|
108
136
|
const statusTicker = new EvalStatusTicker({
|
|
109
137
|
...(options.now === undefined ? {} : { now: options.now }),
|
|
@@ -146,7 +174,8 @@ export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCo
|
|
|
146
174
|
// a tool we cannot confirm"; session_start / model_select re-register once it is live.
|
|
147
175
|
const monitor = monitorIsRegistered(pi);
|
|
148
176
|
const preludes = promptKernelPreludes(pi);
|
|
149
|
-
|
|
177
|
+
const evalOnlyTools = evalOnlyToolNames(pi);
|
|
178
|
+
promptDocsKey = evalDescriptionKey(preludes, evalOnlyTools);
|
|
150
179
|
pi.registerTool(
|
|
151
180
|
withStartRecovery(
|
|
152
181
|
recovery,
|
|
@@ -176,6 +205,7 @@ export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCo
|
|
|
176
205
|
runtimes: runtime.runtimes,
|
|
177
206
|
kernelPreludes: () => activeKernelPreludes(pi),
|
|
178
207
|
promptKernelPreludes: preludes,
|
|
208
|
+
evalOnlyTools,
|
|
179
209
|
...(bunSkillPath === undefined ? {} : { bunSkillPath }),
|
|
180
210
|
...(modelId === undefined ? {} : { modelId }),
|
|
181
211
|
}),
|
|
@@ -287,13 +317,13 @@ export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCo
|
|
|
287
317
|
if (cellManager === undefined || handles === undefined) return;
|
|
288
318
|
registerEvalForRuntime(runtime, modelId, cellManager, handles);
|
|
289
319
|
});
|
|
290
|
-
// Tool activation has no event of its own; the next turn re-documents a changed contribution set.
|
|
320
|
+
// Tool activation has no event of its own; the next turn re-documents a changed contribution or eval-only set.
|
|
291
321
|
pi.on("turn_start", async () => {
|
|
292
322
|
const runtime = activeRuntime;
|
|
293
323
|
const cellManager = activeCells;
|
|
294
324
|
const handles = activeHandles;
|
|
295
325
|
if (runtime === undefined || cellManager === undefined || handles === undefined) return;
|
|
296
|
-
if (
|
|
326
|
+
if (evalDescriptionKey(promptKernelPreludes(pi), evalOnlyToolNames(pi)) === promptDocsKey) return;
|
|
297
327
|
registerEvalForRuntime(runtime, activeModelId, cellManager, handles);
|
|
298
328
|
});
|
|
299
329
|
}
|
|
@@ -172,12 +172,12 @@ function capturedSpawnSync(originalSpawnSync, pinEnv, guard) {
|
|
|
172
172
|
if (!pinEnv) return originalSpawnSync(...args);
|
|
173
173
|
const [first, second] = args;
|
|
174
174
|
if (Array.isArray(first)) {
|
|
175
|
-
const spawnOptions = second
|
|
176
|
-
if (
|
|
175
|
+
const spawnOptions = second ?? {};
|
|
176
|
+
if (typeof spawnOptions !== "object" || spawnOptions.env != null)
|
|
177
177
|
return originalSpawnSync(...args);
|
|
178
178
|
return originalSpawnSync(first, { ...spawnOptions, env: { ...process.env } });
|
|
179
179
|
}
|
|
180
|
-
if (first !== null && typeof first === "object" && first.env
|
|
180
|
+
if (first !== null && typeof first === "object" && first.env == null)
|
|
181
181
|
return originalSpawnSync({ ...first, env: { ...process.env } });
|
|
182
182
|
return originalSpawnSync(...args);
|
|
183
183
|
};
|
|
@@ -192,19 +192,30 @@ function capturedSpawn(originalSpawn, options, pinEnv, guard) {
|
|
|
192
192
|
return (...args) => {
|
|
193
193
|
assertCellLive();
|
|
194
194
|
judgeSpawn(guard, args[0]);
|
|
195
|
-
if (!options.isActive()) return originalSpawn(...args);
|
|
196
195
|
const [first, second] = args;
|
|
196
|
+
// The pinned environment applies whether or not a cell is running: a spawn from a timer or callback after its cell
|
|
197
|
+
// settled would otherwise inherit the OS environ, which still holds withheld credentials (senpi#6820).
|
|
198
|
+
if (!options.isActive()) {
|
|
199
|
+
if (!pinEnv) return originalSpawn(...args);
|
|
200
|
+
if (Array.isArray(first)) {
|
|
201
|
+
const spawnOptions = second ?? {};
|
|
202
|
+
return spawnOptions.env == null ? originalSpawn(first, { ...spawnOptions, env: { ...process.env } }) : originalSpawn(...args);
|
|
203
|
+
}
|
|
204
|
+
return first !== null && typeof first === "object" && first.env == null
|
|
205
|
+
? originalSpawn({ ...first, env: { ...process.env } })
|
|
206
|
+
: originalSpawn(...args);
|
|
207
|
+
}
|
|
197
208
|
let child;
|
|
198
209
|
if (Array.isArray(first)) {
|
|
199
|
-
const spawnOptions = second
|
|
200
|
-
const effective = pinEnv && spawnOptions.env
|
|
210
|
+
const spawnOptions = second ?? {};
|
|
211
|
+
const effective = pinEnv && spawnOptions.env == null ? { ...spawnOptions, env: { ...process.env } } : spawnOptions;
|
|
201
212
|
child = needsStderrCapture(effective)
|
|
202
213
|
? drainStderr(originalSpawn(first, { ...effective, stderr: "pipe" }), options.emitText)
|
|
203
214
|
: effective === spawnOptions
|
|
204
215
|
? originalSpawn(...args)
|
|
205
216
|
: originalSpawn(first, effective);
|
|
206
217
|
} else {
|
|
207
|
-
const effective = pinEnv && first !== null && typeof first === "object" && first.env
|
|
218
|
+
const effective = pinEnv && first !== null && typeof first === "object" && first.env == null ? { ...first, env: { ...process.env } } : first;
|
|
208
219
|
child = needsStderrCapture(effective)
|
|
209
220
|
? drainStderr(originalSpawn({ ...effective, stderr: "pipe" }), options.emitText)
|
|
210
221
|
: effective === first
|
|
@@ -52,8 +52,9 @@ env(key?=None, value?=None) → str | None | dict
|
|
|
52
52
|
Task/agent output by id. Reads immediately: running tasks return their status; \`format\` \`"raw"\` = full, \`"tail"\` = trailing.
|
|
53
53
|
{{/if}}tool.<name>(args) → { text, images?, details?, hasError? }
|
|
54
54
|
Invoke any session tool; image results (e.g. \`tool.read\` on a png) arrive in \`images[i]\` as { mimeType, dataBase64 }.
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
{{#if evalOnlyTools}} Eval-only tools (absent from your direct tool list, reachable only here): {{evalOnlyTools}}.
|
|
56
|
+
{{/if}}tool_schema(name?) → dict
|
|
57
|
+
{ name, description, parameters } of a tool; omit \`name\` → { tools: [every tool name] }; a failed \`tool.<name>()\` call also returns the expected parameters.
|
|
57
58
|
completion(prompt, model?="default", system?=None, schema?=None) → str | dict
|
|
58
59
|
Oneshot, stateless. \`model\`: \`"smol"\` fast | \`"default"\` session | \`"slow"\` most capable. \`schema\` (JSON-Schema) → parsed structured output.
|
|
59
60
|
{{#if spawns}}agent(prompt, agent?="{{spawnDefaultAgent}}", model?=None, label?=None, schema?=None, isolated?=None, apply?=None, merge?=None, handle?=False) → str | dict
|
|
@@ -40,6 +40,8 @@ export interface EvalPromptOptions {
|
|
|
40
40
|
readonly maxDetachedCells?: number;
|
|
41
41
|
/** Active tools' kernel globals; each documentation line joins the prelude helper list. */
|
|
42
42
|
readonly kernelPreludes?: readonly KernelPreludeContribution[];
|
|
43
|
+
/** Tools withheld from the model's direct list and reachable only as `tool.<name>(...)` in a cell (senpi#6886). */
|
|
44
|
+
readonly evalOnlyTools?: readonly string[];
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
/** Prompt dialect for the eval-first batching emphasis. */
|
|
@@ -113,6 +115,7 @@ export function buildEvalPrompt(
|
|
|
113
115
|
runBudgetSeconds: String(options.runBudgetSeconds ?? DEFAULT_RUN_BUDGET_SECONDS),
|
|
114
116
|
maxDetachedCells: String(options.maxDetachedCells ?? DEFAULT_MAX_DETACHED_CELLS),
|
|
115
117
|
kernelPreludeDocs: (options.kernelPreludes ?? []).map((prelude) => prelude.documentation).join("\n"),
|
|
118
|
+
evalOnlyTools: (options.evalOnlyTools ?? []).join(", "),
|
|
116
119
|
};
|
|
117
120
|
const rendered = renderTemplate(EVAL_PROMPT_TEMPLATE, context)
|
|
118
121
|
.replace(/\n{3,}/g, "\n\n")
|
package/src/tool/call-capture.ts
CHANGED
|
@@ -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;
|
package/src/tool/cell-handler.ts
CHANGED
|
@@ -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
|
-
() =>
|
|
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(
|
|
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);
|
|
@@ -77,6 +77,8 @@ export interface CreateEvalToolOptions {
|
|
|
77
77
|
readonly jsEnvironments?: JsEnvironments;
|
|
78
78
|
/** Contributions whose documentation lines the description lists; snapshot taken when the tool is (re)registered. */
|
|
79
79
|
readonly promptKernelPreludes?: readonly KernelPreludeContribution[];
|
|
80
|
+
/** Tools the session reaches only through eval; the description names them. Snapshot taken at (re)registration. */
|
|
81
|
+
readonly evalOnlyTools?: readonly string[];
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
export interface EvalCellInvocation {
|
package/src/tool/eval-tool.ts
CHANGED
|
@@ -67,6 +67,7 @@ export function createEvalTool(options: CreateEvalToolOptions) {
|
|
|
67
67
|
...(options.runtimes?.js === undefined ? {} : { jsRuntime: options.runtimes.js }),
|
|
68
68
|
...(options.bunSkillPath === undefined ? {} : { bunSkillPath: options.bunSkillPath }),
|
|
69
69
|
...(options.promptKernelPreludes === undefined ? {} : { kernelPreludes: options.promptKernelPreludes }),
|
|
70
|
+
...(options.evalOnlyTools === undefined ? {} : { evalOnlyTools: options.evalOnlyTools }),
|
|
70
71
|
});
|
|
71
72
|
const languages = enabledLanguageList(options.enabledLanguages);
|
|
72
73
|
registerEvalArgumentValidator(parameters, languages);
|
|
@@ -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(
|
|
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
|
}
|
package/src/tool/tool-widgets.ts
CHANGED
|
@@ -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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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));
|