@code-yeongyu/senpi-codemode 2026.11.17 → 2026.11.18
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 +27 -0
- package/package.json +5 -5
- package/src/bridges/schema-bridge.ts +4 -1
- package/src/index.ts +25 -1
- package/src/tool/call-capture.ts +21 -0
- package/src/tool/cell-handler.ts +24 -2
- 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,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2026.11.18] - 2026-11-18
|
|
4
|
+
|
|
5
|
+
### Breaking Changes
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
### Removed
|
|
14
|
+
|
|
15
|
+
## [2026.11.17-2] - 2026-11-17
|
|
16
|
+
|
|
17
|
+
### Breaking Changes
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- 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)).
|
|
26
|
+
- 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)).
|
|
27
|
+
|
|
28
|
+
### Removed
|
|
29
|
+
|
|
3
30
|
## [2026.11.17] - 2026-11-17
|
|
4
31
|
|
|
5
32
|
### 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.18",
|
|
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.18",
|
|
37
|
+
"@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.18",
|
|
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.18"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@code-yeongyu/senpi": "2026.11.
|
|
45
|
+
"@code-yeongyu/senpi": "2026.11.18"
|
|
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 {
|
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 = {
|
|
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;
|
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);
|
|
@@ -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));
|