lsd-pi 1.3.2 → 1.3.6
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/dist/resources/extensions/browser-tools/tools/codegen.js +5 -5
- package/dist/resources/extensions/browser-tools/tools/navigation.js +107 -178
- package/dist/resources/extensions/browser-tools/tools/network-mock.js +112 -167
- package/dist/resources/extensions/browser-tools/tools/pages.js +182 -234
- package/dist/resources/extensions/browser-tools/tools/refs.js +202 -461
- package/dist/resources/extensions/browser-tools/tools/session.js +176 -323
- package/dist/resources/extensions/browser-tools/tools/state-persistence.js +91 -154
- package/dist/resources/extensions/browser-tools/utils.js +1 -1
- package/dist/resources/extensions/slash-commands/extension-manifest.json +2 -2
- package/dist/resources/extensions/slash-commands/fast.js +73 -0
- package/dist/resources/extensions/slash-commands/index.js +2 -0
- package/dist/resources/extensions/slash-commands/plan.js +37 -12
- package/dist/resources/extensions/subagent/background-job-manager.js +13 -0
- package/dist/resources/extensions/subagent/in-process-runner.js +387 -0
- package/dist/resources/extensions/subagent/index.js +278 -626
- package/dist/resources/extensions/subagent/legacy-runner.js +503 -0
- package/dist/resources/extensions/voice/index.js +96 -36
- package/dist/resources/extensions/voice/push-to-talk.js +26 -0
- package/package.json +1 -1
- package/packages/pi-agent-core/dist/agent.d.ts +19 -0
- package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent.js +16 -0
- package/packages/pi-agent-core/dist/agent.js.map +1 -1
- package/packages/pi-agent-core/src/agent.ts +32 -2
- package/packages/pi-ai/dist/providers/openai-codex-responses.d.ts +34 -1
- package/packages/pi-ai/dist/providers/openai-codex-responses.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/openai-codex-responses.js +32 -4
- package/packages/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
- package/packages/pi-ai/dist/providers/openai-codex-responses.test.js +127 -16
- package/packages/pi-ai/dist/providers/openai-codex-responses.test.js.map +1 -1
- package/packages/pi-ai/dist/providers/openai-responses.d.ts +8 -1
- package/packages/pi-ai/dist/providers/openai-responses.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/openai-responses.fast-mode.test.d.ts +2 -0
- package/packages/pi-ai/dist/providers/openai-responses.fast-mode.test.d.ts.map +1 -0
- package/packages/pi-ai/dist/providers/openai-responses.fast-mode.test.js +67 -0
- package/packages/pi-ai/dist/providers/openai-responses.fast-mode.test.js.map +1 -0
- package/packages/pi-ai/dist/providers/openai-responses.js +21 -3
- package/packages/pi-ai/dist/providers/openai-responses.js.map +1 -1
- package/packages/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/simple-options.js +2 -0
- package/packages/pi-ai/dist/providers/simple-options.js.map +1 -1
- package/packages/pi-ai/dist/types.d.ts +5 -0
- package/packages/pi-ai/dist/types.d.ts.map +1 -1
- package/packages/pi-ai/dist/types.js.map +1 -1
- package/packages/pi-ai/src/providers/openai-codex-responses.test.ts +143 -20
- package/packages/pi-ai/src/providers/openai-codex-responses.ts +47 -4
- package/packages/pi-ai/src/providers/openai-responses.fast-mode.test.ts +73 -0
- package/packages/pi-ai/src/providers/openai-responses.ts +26 -3
- package/packages/pi-ai/src/providers/simple-options.ts +2 -0
- package/packages/pi-ai/src/types.ts +5 -0
- package/packages/pi-coding-agent/dist/core/keybindings.d.ts +1 -1
- package/packages/pi-coding-agent/dist/core/keybindings.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/keybindings.js +2 -0
- package/packages/pi-coding-agent/dist/core/keybindings.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.js +4 -2
- package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +6 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.fast-mode.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.fast-mode.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.fast-mode.test.js +35 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.fast-mode.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.js +12 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/slash-commands.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/slash-commands.js +1 -0
- package/packages/pi-coding-agent/dist/core/slash-commands.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.js +6 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/tool-priority.d.ts +4 -0
- package/packages/pi-coding-agent/dist/core/tool-priority.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/tool-priority.js +18 -0
- package/packages/pi-coding-agent/dist/core/tool-priority.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/tool-priority.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/tool-priority.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/tool-priority.test.js +27 -0
- package/packages/pi-coding-agent/dist/core/tool-priority.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-summary-line.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-summary-line.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-summary-line.test.js +26 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-summary-line.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.d.ts +45 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.js +314 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.test.js +122 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/btw-overlay.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js +7 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.d.ts +4 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.js +26 -2
- package/packages/pi-coding-agent/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +6 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +18 -4
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-summary-line.d.ts +13 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-summary-line.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-summary-line.js +49 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-summary-line.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.js +197 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +97 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js +7 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.d.ts +3 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-state.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +4 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +35 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js +41 -0
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js.map +1 -1
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/core/keybindings.ts +4 -1
- package/packages/pi-coding-agent/src/core/sdk.ts +4 -2
- package/packages/pi-coding-agent/src/core/settings-manager.fast-mode.test.ts +46 -0
- package/packages/pi-coding-agent/src/core/settings-manager.ts +18 -0
- package/packages/pi-coding-agent/src/core/slash-commands.ts +1 -0
- package/packages/pi-coding-agent/src/core/system-prompt.ts +6 -1
- package/packages/pi-coding-agent/src/core/tool-priority.test.ts +30 -0
- package/packages/pi-coding-agent/src/core/tool-priority.ts +17 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/tool-summary-line.test.ts +31 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/btw-overlay.test.ts +172 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/btw-overlay.ts +402 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/footer.ts +8 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/settings-selector.ts +32 -2
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +1154 -1136
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-summary-line.ts +64 -0
- package/packages/pi-coding-agent/src/modes/interactive/controllers/__tests__/chat-controller.collapsed-tool-summary.test.ts +228 -0
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +494 -398
- package/packages/pi-coding-agent/src/modes/interactive/controllers/input-controller.ts +7 -0
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode-state.ts +3 -0
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +38 -0
- package/packages/pi-coding-agent/src/modes/interactive/slash-command-handlers.ts +60 -1
- package/pkg/package.json +1 -1
- package/src/resources/extensions/browser-tools/tools/codegen.ts +5 -5
- package/src/resources/extensions/browser-tools/tools/navigation.ts +118 -196
- package/src/resources/extensions/browser-tools/tools/network-mock.ts +114 -205
- package/src/resources/extensions/browser-tools/tools/pages.ts +183 -237
- package/src/resources/extensions/browser-tools/tools/refs.ts +193 -507
- package/src/resources/extensions/browser-tools/tools/session.ts +182 -321
- package/src/resources/extensions/browser-tools/tools/state-persistence.ts +94 -172
- package/src/resources/extensions/browser-tools/utils.ts +1 -1
- package/src/resources/extensions/slash-commands/extension-manifest.json +2 -2
- package/src/resources/extensions/slash-commands/fast.ts +89 -0
- package/src/resources/extensions/slash-commands/index.ts +2 -0
- package/src/resources/extensions/slash-commands/plan.ts +42 -12
- package/src/resources/extensions/subagent/background-job-manager.ts +28 -0
- package/src/resources/extensions/subagent/in-process-runner.ts +534 -0
- package/src/resources/extensions/subagent/index.ts +489 -799
- package/src/resources/extensions/subagent/legacy-runner.ts +607 -0
- package/src/resources/extensions/voice/index.ts +308 -238
- package/src/resources/extensions/voice/push-to-talk.ts +42 -0
- package/src/resources/extensions/voice/tests/push-to-talk.test.ts +109 -0
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Box,
|
|
3
|
+
Container,
|
|
4
|
+
getCapabilities,
|
|
5
|
+
Image,
|
|
6
|
+
imageFallback,
|
|
7
|
+
Spacer,
|
|
8
|
+
Text,
|
|
9
|
+
type TUI,
|
|
10
|
+
truncateToWidth,
|
|
11
11
|
} from "@gsd/pi-tui";
|
|
12
12
|
import stripAnsi from "strip-ansi";
|
|
13
13
|
import type { ToolDefinition } from "../../../core/extensions/types.js";
|
|
14
14
|
import { computeEditDiff, type EditDiffError, type EditDiffResult } from "../../../core/tools/edit-diff.js";
|
|
15
15
|
import { allTools } from "../../../core/tools/index.js";
|
|
16
|
+
import { shouldCollapse } from "../../../core/tool-priority.js";
|
|
16
17
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from "../../../core/tools/truncate.js";
|
|
17
18
|
import { convertToPng } from "../../../utils/image-convert.js";
|
|
18
19
|
import { sanitizeBinaryOutput } from "../../../utils/shell.js";
|
|
@@ -41,7 +42,7 @@ const WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;
|
|
|
41
42
|
* Replace tabs with spaces for consistent rendering
|
|
42
43
|
*/
|
|
43
44
|
function replaceTabs(text: string): string {
|
|
44
|
-
|
|
45
|
+
return text.replace(/\t/g, " ");
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
/**
|
|
@@ -49,14 +50,14 @@ function replaceTabs(text: string): string {
|
|
|
49
50
|
* Keep tool arguments unchanged, sanitize only display text.
|
|
50
51
|
*/
|
|
51
52
|
function normalizeDisplayText(text: string): string {
|
|
52
|
-
|
|
53
|
+
return text.replace(/\r/g, "");
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/** Safely coerce value to string for display. Returns null if invalid type. */
|
|
56
57
|
function str(value: unknown): string | null {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
if (typeof value === "string") return value;
|
|
59
|
+
if (value == null) return "";
|
|
60
|
+
return null; // Invalid type
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
/**
|
|
@@ -64,1138 +65,1155 @@ function str(value: unknown): string | null {
|
|
|
64
65
|
* that the agent process cannot resolve (sudo blocked, EPERM on root-owned files, etc.).
|
|
65
66
|
*/
|
|
66
67
|
function isBashPrivilegeError(output: string, command: string): boolean {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
// Already handled by OS sandbox-policy path
|
|
69
|
+
if (/sandbox blocked this operation/i.test(output)) return false;
|
|
70
|
+
// sudo explicitly rejected by OS
|
|
71
|
+
if (/sudo.*operation not permitted/i.test(output)) return true;
|
|
72
|
+
if (/command exited with code 126/i.test(output) && /sudo/i.test(output)) return true;
|
|
73
|
+
// npm / other tools hitting root-owned cache files
|
|
74
|
+
if (/cache folder contains root-owned files/i.test(output)) return true;
|
|
75
|
+
// Generic EPERM when command involves sudo
|
|
76
|
+
if (/EPERM|operation not permitted/i.test(output) && /sudo/i.test(command)) return true;
|
|
77
|
+
// Permission denied when command involves sudo
|
|
78
|
+
if (/permission denied/i.test(output) && /sudo/i.test(command)) return true;
|
|
79
|
+
return false;
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
export interface ToolExecutionOptions {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
showImages?: boolean; // default: true (only used if terminal supports images)
|
|
84
|
+
renderMode?: "minimal" | "normal";
|
|
85
|
+
editorScheme?: EditorScheme; // URI scheme for Cmd+click file links (default: "auto")
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
type WriteHighlightCache = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
rawPath: string | null;
|
|
90
|
+
lang: string;
|
|
91
|
+
rawContent: string;
|
|
92
|
+
normalizedLines: string[];
|
|
93
|
+
highlightedLines: string[];
|
|
93
94
|
};
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
97
|
* Component that renders a tool call with its result (updateable)
|
|
97
98
|
*/
|
|
98
99
|
export class ToolExecutionComponent extends Container {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
100
|
+
private contentBox: Box; // Used for custom tools and bash visual truncation
|
|
101
|
+
private contentText: Text; // For built-in tools (with its own padding/bg)
|
|
102
|
+
private imageComponents: Image[] = [];
|
|
103
|
+
private imageSpacers: Spacer[] = [];
|
|
104
|
+
private toolName: string;
|
|
105
|
+
private args: any;
|
|
106
|
+
private expanded = false;
|
|
107
|
+
private renderMode: "minimal" | "normal";
|
|
108
|
+
private showImages: boolean;
|
|
109
|
+
private editorScheme: EditorScheme;
|
|
110
|
+
private isPartial = true;
|
|
111
|
+
private toolDefinition?: ToolDefinition;
|
|
112
|
+
private ui: TUI;
|
|
113
|
+
private cwd: string;
|
|
114
|
+
private result?: {
|
|
115
|
+
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
|
|
116
|
+
isError: boolean;
|
|
117
|
+
details?: any;
|
|
118
|
+
};
|
|
119
|
+
// Cached edit diff preview (computed when args arrive, before tool executes)
|
|
120
|
+
private editDiffPreview?: EditDiffResult | EditDiffError;
|
|
121
|
+
private editDiffArgsKey?: string; // Track which args the preview is for
|
|
122
|
+
// Cached converted images for Kitty protocol (which requires PNG), keyed by index
|
|
123
|
+
private convertedImages: Map<number, { data: string; mimeType: string }> = new Map();
|
|
124
|
+
// Incremental syntax highlighting cache for write tool call args
|
|
125
|
+
private writeHighlightCache?: WriteHighlightCache;
|
|
126
|
+
// When true, this component intentionally renders no lines
|
|
127
|
+
private hideComponent = false;
|
|
128
|
+
private manuallyHidden = false;
|
|
129
|
+
private startTime = Date.now();
|
|
130
|
+
|
|
131
|
+
// Tool status spinner state
|
|
132
|
+
private spinnerTimer: NodeJS.Timeout | null = null;
|
|
133
|
+
private spinnerFrame = 0;
|
|
134
|
+
|
|
135
|
+
constructor(
|
|
136
|
+
toolName: string,
|
|
137
|
+
args: any,
|
|
138
|
+
options: ToolExecutionOptions = {},
|
|
139
|
+
toolDefinition: ToolDefinition | undefined,
|
|
140
|
+
ui: TUI,
|
|
141
|
+
cwd: string = process.cwd(),
|
|
142
|
+
) {
|
|
143
|
+
super();
|
|
144
|
+
this.toolName = toolName;
|
|
145
|
+
this.args = args;
|
|
146
|
+
this.showImages = options.showImages ?? true;
|
|
147
|
+
this.renderMode = options.renderMode ?? "normal";
|
|
148
|
+
this.editorScheme = options.editorScheme ?? "auto";
|
|
149
|
+
this.toolDefinition = toolDefinition;
|
|
150
|
+
this.ui = ui;
|
|
151
|
+
this.cwd = cwd;
|
|
152
|
+
|
|
153
|
+
// Always create both - contentBox for custom tools/bash, contentText for other built-ins
|
|
154
|
+
this.contentBox = new Box(1, 0, (text: string) => theme.bg("toolPendingBg", text));
|
|
155
|
+
this.contentText = new Text("", 1, 0, (text: string) => theme.bg("toolPendingBg", text));
|
|
156
|
+
|
|
157
|
+
// Use contentBox for bash (visual truncation) or custom tools with custom renderers
|
|
158
|
+
// Use contentText for built-in tools (including overrides without custom renderers)
|
|
159
|
+
if (toolName === "bash" || (toolDefinition && !this.shouldUseBuiltInRenderer())) {
|
|
160
|
+
this.addChild(this.contentBox);
|
|
161
|
+
} else {
|
|
162
|
+
this.addChild(this.contentText);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
this.updateDisplay();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Check if we should use built-in rendering for this tool.
|
|
170
|
+
* Returns true if the tool name is a built-in AND either there's no toolDefinition
|
|
171
|
+
* or the toolDefinition doesn't provide custom renderers.
|
|
172
|
+
*/
|
|
173
|
+
private shouldUseBuiltInRenderer(): boolean {
|
|
174
|
+
const isBuiltInName = this.toolName in allTools;
|
|
175
|
+
const hasCustomRenderers = this.toolDefinition?.renderCall || this.toolDefinition?.renderResult;
|
|
176
|
+
return isBuiltInName && !hasCustomRenderers;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
updateArgs(args: any): void {
|
|
180
|
+
this.args = args;
|
|
181
|
+
if (this.toolName === "write" && this.isPartial) {
|
|
182
|
+
this.updateWriteHighlightCacheIncremental();
|
|
183
|
+
}
|
|
184
|
+
this.updateDisplay();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private highlightSingleLine(line: string, lang: string): string {
|
|
188
|
+
const highlighted = highlightCode(line, lang);
|
|
189
|
+
return highlighted[0] ?? "";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {
|
|
193
|
+
const prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);
|
|
194
|
+
if (prefixCount === 0) return;
|
|
195
|
+
|
|
196
|
+
const prefixSource = cache.normalizedLines.slice(0, prefixCount).join("\n");
|
|
197
|
+
const prefixHighlighted = highlightCode(prefixSource, cache.lang);
|
|
198
|
+
for (let i = 0; i < prefixCount; i++) {
|
|
199
|
+
cache.highlightedLines[i] =
|
|
200
|
+
prefixHighlighted[i] ?? this.highlightSingleLine(cache.normalizedLines[i] ?? "", cache.lang);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): void {
|
|
205
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
206
|
+
if (!lang) {
|
|
207
|
+
this.writeHighlightCache = undefined;
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const displayContent = normalizeDisplayText(fileContent);
|
|
212
|
+
const normalized = replaceTabs(displayContent);
|
|
213
|
+
this.writeHighlightCache = {
|
|
214
|
+
rawPath,
|
|
215
|
+
lang,
|
|
216
|
+
rawContent: fileContent,
|
|
217
|
+
normalizedLines: normalized.split("\n"),
|
|
218
|
+
highlightedLines: highlightCode(normalized, lang),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private updateWriteHighlightCacheIncremental(): void {
|
|
223
|
+
const rawPath = str(this.args?.file_path ?? this.args?.path);
|
|
224
|
+
const fileContent = str(this.args?.content);
|
|
225
|
+
if (rawPath === null || fileContent === null) {
|
|
226
|
+
this.writeHighlightCache = undefined;
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
231
|
+
if (!lang) {
|
|
232
|
+
this.writeHighlightCache = undefined;
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (!this.writeHighlightCache) {
|
|
237
|
+
this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const cache = this.writeHighlightCache;
|
|
242
|
+
if (cache.lang !== lang || cache.rawPath !== rawPath) {
|
|
243
|
+
this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (!fileContent.startsWith(cache.rawContent)) {
|
|
248
|
+
this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (fileContent.length === cache.rawContent.length) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const deltaRaw = fileContent.slice(cache.rawContent.length);
|
|
257
|
+
const deltaDisplay = normalizeDisplayText(deltaRaw);
|
|
258
|
+
const deltaNormalized = replaceTabs(deltaDisplay);
|
|
259
|
+
cache.rawContent = fileContent;
|
|
260
|
+
|
|
261
|
+
if (cache.normalizedLines.length === 0) {
|
|
262
|
+
cache.normalizedLines.push("");
|
|
263
|
+
cache.highlightedLines.push("");
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const segments = deltaNormalized.split("\n");
|
|
267
|
+
const lastIndex = cache.normalizedLines.length - 1;
|
|
268
|
+
cache.normalizedLines[lastIndex] += segments[0];
|
|
269
|
+
cache.highlightedLines[lastIndex] = this.highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);
|
|
270
|
+
|
|
271
|
+
for (let i = 1; i < segments.length; i++) {
|
|
272
|
+
cache.normalizedLines.push(segments[i]);
|
|
273
|
+
cache.highlightedLines.push(this.highlightSingleLine(segments[i], cache.lang));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
this.refreshWriteHighlightPrefix(cache);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Signal that args are complete (tool is about to execute).
|
|
281
|
+
* This triggers diff computation for edit tool.
|
|
282
|
+
*/
|
|
283
|
+
setArgsComplete(): void {
|
|
284
|
+
if (this.toolName === "write") {
|
|
285
|
+
const rawPath = str(this.args?.file_path ?? this.args?.path);
|
|
286
|
+
const fileContent = str(this.args?.content);
|
|
287
|
+
if (rawPath !== null && fileContent !== null) {
|
|
288
|
+
this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
this.maybeComputeEditDiff();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Compute edit diff preview when we have complete args.
|
|
296
|
+
* This runs async and updates display when done.
|
|
297
|
+
*/
|
|
298
|
+
private maybeComputeEditDiff(): void {
|
|
299
|
+
if (this.toolName !== "edit") return;
|
|
300
|
+
|
|
301
|
+
const path = this.args?.path;
|
|
302
|
+
const oldText = this.args?.oldText;
|
|
303
|
+
const newText = this.args?.newText;
|
|
304
|
+
|
|
305
|
+
// Need all three params to compute diff
|
|
306
|
+
if (!path || oldText === undefined || newText === undefined) return;
|
|
307
|
+
|
|
308
|
+
// Create a key to track which args this computation is for
|
|
309
|
+
const argsKey = JSON.stringify({ path, oldText, newText });
|
|
310
|
+
|
|
311
|
+
// Skip if we already computed for these exact args
|
|
312
|
+
if (this.editDiffArgsKey === argsKey) return;
|
|
313
|
+
|
|
314
|
+
this.editDiffArgsKey = argsKey;
|
|
315
|
+
|
|
316
|
+
// Compute diff async
|
|
317
|
+
computeEditDiff(path, oldText, newText, this.cwd).then((result) => {
|
|
318
|
+
// Only update if args haven't changed since we started
|
|
319
|
+
if (this.editDiffArgsKey === argsKey) {
|
|
320
|
+
this.editDiffPreview = result;
|
|
321
|
+
this.updateDisplay();
|
|
322
|
+
this.ui.requestRender();
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
updateResult(
|
|
328
|
+
result: {
|
|
329
|
+
content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;
|
|
330
|
+
details?: any;
|
|
331
|
+
isError: boolean;
|
|
332
|
+
},
|
|
333
|
+
isPartial = false,
|
|
334
|
+
): void {
|
|
335
|
+
this.result = result;
|
|
336
|
+
this.isPartial = isPartial;
|
|
337
|
+
|
|
338
|
+
if (this.toolName === "write" && !isPartial) {
|
|
339
|
+
const rawPath = str(this.args?.file_path ?? this.args?.path);
|
|
340
|
+
const fileContent = str(this.args?.content);
|
|
341
|
+
if (rawPath !== null && fileContent !== null) {
|
|
342
|
+
this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
this.updateDisplay();
|
|
346
|
+
// Convert non-PNG images to PNG for Kitty protocol (async)
|
|
347
|
+
this.maybeConvertImagesForKitty();
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Convert non-PNG images to PNG for Kitty graphics protocol.
|
|
352
|
+
* Kitty requires PNG format (f=100), so JPEG/GIF/WebP won't display.
|
|
353
|
+
*/
|
|
354
|
+
private maybeConvertImagesForKitty(): void {
|
|
355
|
+
const caps = getCapabilities();
|
|
356
|
+
// Only needed for Kitty protocol
|
|
357
|
+
if (caps.images !== "kitty") return;
|
|
358
|
+
if (!this.result) return;
|
|
359
|
+
|
|
360
|
+
const imageBlocks = this.result.content?.filter((c: any) => c.type === "image") || [];
|
|
361
|
+
|
|
362
|
+
for (let i = 0; i < imageBlocks.length; i++) {
|
|
363
|
+
const img = imageBlocks[i];
|
|
364
|
+
if (!img.data || !img.mimeType) continue;
|
|
365
|
+
// Skip if already PNG or already converted
|
|
366
|
+
if (img.mimeType === "image/png") continue;
|
|
367
|
+
if (this.convertedImages.has(i)) continue;
|
|
368
|
+
|
|
369
|
+
// Convert async
|
|
370
|
+
const index = i;
|
|
371
|
+
convertToPng(img.data, img.mimeType).then((converted) => {
|
|
372
|
+
if (converted) {
|
|
373
|
+
this.convertedImages.set(index, converted);
|
|
374
|
+
this.updateDisplay();
|
|
375
|
+
this.ui.requestRender();
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
setExpanded(expanded: boolean): void {
|
|
382
|
+
this.expanded = expanded;
|
|
383
|
+
this.updateDisplay();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
setHidden(hidden: boolean): void {
|
|
387
|
+
this.manuallyHidden = hidden;
|
|
388
|
+
this.updateDisplay();
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
isHidden(): boolean {
|
|
392
|
+
return this.hideComponent;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
getElapsed(): number {
|
|
396
|
+
return Date.now() - this.startTime;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
shouldHideWhenCollapsed(): boolean {
|
|
400
|
+
return !this.isPartial && shouldCollapse(this.toolName, this.result?.isError ?? false);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
setRenderMode(mode: "minimal" | "normal"): void {
|
|
404
|
+
if (this.renderMode !== mode) {
|
|
405
|
+
this.renderMode = mode;
|
|
406
|
+
this.updateDisplay();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
setEditorScheme(scheme: EditorScheme): void {
|
|
411
|
+
this.editorScheme = scheme;
|
|
412
|
+
this.updateDisplay();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
setShowImages(show: boolean): void {
|
|
416
|
+
this.showImages = show;
|
|
417
|
+
this.updateDisplay();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
dispose(): void {
|
|
421
|
+
if (this.spinnerTimer) {
|
|
422
|
+
clearInterval(this.spinnerTimer);
|
|
423
|
+
this.spinnerTimer = null;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
override invalidate(): void {
|
|
428
|
+
super.invalidate();
|
|
429
|
+
this.updateDisplay();
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
override render(width: number): string[] {
|
|
433
|
+
if (this.hideComponent) {
|
|
434
|
+
return [];
|
|
435
|
+
}
|
|
436
|
+
return [...super.render(width), ""];
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
private updateDisplay(): void {
|
|
440
|
+
// Status indicator with circle
|
|
441
|
+
let statusIndicator = "";
|
|
442
|
+
let statusColor = "";
|
|
443
|
+
|
|
444
|
+
if (this.isPartial) {
|
|
445
|
+
// Loading spinner - start timer on first partial render
|
|
446
|
+
if (!this.spinnerTimer) {
|
|
447
|
+
this.spinnerTimer = setInterval(() => {
|
|
448
|
+
this.spinnerFrame = (this.spinnerFrame + 1) % SPINNER_FRAMES.length;
|
|
449
|
+
this.updateDisplay();
|
|
450
|
+
this.ui.requestRender();
|
|
451
|
+
}, SPINNER_INTERVAL_MS);
|
|
452
|
+
}
|
|
453
|
+
statusIndicator = SPINNER_FRAMES[this.spinnerFrame];
|
|
454
|
+
} else {
|
|
455
|
+
// Stop spinner when no longer partial
|
|
456
|
+
if (this.spinnerTimer) {
|
|
457
|
+
clearInterval(this.spinnerTimer);
|
|
458
|
+
this.spinnerTimer = null;
|
|
459
|
+
}
|
|
460
|
+
if (this.result?.isError) {
|
|
461
|
+
// Failed - red circle
|
|
462
|
+
statusIndicator = theme.fg("error", "●");
|
|
463
|
+
statusColor = "error";
|
|
464
|
+
} else {
|
|
465
|
+
// Success - green circle
|
|
466
|
+
statusIndicator = theme.fg("success", "●");
|
|
467
|
+
statusColor = "success";
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const useBuiltInRenderer = this.shouldUseBuiltInRenderer();
|
|
472
|
+
let customRendererHasContent = false;
|
|
473
|
+
|
|
474
|
+
// Use built-in rendering for built-in tools (or overrides without custom renderers)
|
|
475
|
+
if (useBuiltInRenderer) {
|
|
476
|
+
if (this.toolName === "bash") {
|
|
477
|
+
// Bash uses Box with visual line truncation - no background
|
|
478
|
+
this.contentBox.setBgFn((text: string) => text);
|
|
479
|
+
this.contentBox.clear();
|
|
480
|
+
this.renderBashContent(statusIndicator);
|
|
481
|
+
} else {
|
|
482
|
+
// Other built-in tools: use Text directly with caching - no background
|
|
483
|
+
this.contentText.setCustomBgFn((text: string) => text);
|
|
484
|
+
this.contentText.setText(this.formatToolExecution(statusIndicator));
|
|
485
|
+
}
|
|
486
|
+
} else if (this.toolDefinition) {
|
|
487
|
+
// Custom tools use Box for flexible component rendering - no background
|
|
488
|
+
this.contentBox.setBgFn((text: string) => text);
|
|
489
|
+
this.contentBox.clear();
|
|
490
|
+
|
|
491
|
+
// Render call component
|
|
492
|
+
if (this.toolDefinition.renderCall) {
|
|
493
|
+
try {
|
|
494
|
+
const callComponent = this.toolDefinition.renderCall(this.args, theme, { statusIndicator });
|
|
495
|
+
if (callComponent !== undefined) {
|
|
496
|
+
this.contentBox.addChild(callComponent);
|
|
497
|
+
customRendererHasContent = true;
|
|
498
|
+
}
|
|
499
|
+
} catch {
|
|
500
|
+
// Fall back to default on error
|
|
501
|
+
this.contentBox.addChild(new Text(theme.fg("toolTitle", theme.bold(this.toolName)), 0, 0));
|
|
502
|
+
customRendererHasContent = true;
|
|
503
|
+
}
|
|
504
|
+
} else {
|
|
505
|
+
// No custom renderCall, show tool name
|
|
506
|
+
this.contentBox.addChild(new Text(theme.fg("toolTitle", theme.bold(this.toolName)), 0, 0));
|
|
507
|
+
customRendererHasContent = true;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Render result component if we have a result
|
|
511
|
+
if (this.result && this.toolDefinition.renderResult) {
|
|
512
|
+
try {
|
|
513
|
+
if (this.shouldHideCollapsedPreview()) {
|
|
514
|
+
const output = this.getTextOutput();
|
|
515
|
+
const hasDetails = output.trim().length > 0 || this.imageComponents.length > 0 || this.result.details !== undefined;
|
|
516
|
+
const collapsedHint = this.collapsedHintWithPrefix("\n");
|
|
517
|
+
if (hasDetails && collapsedHint) {
|
|
518
|
+
this.contentBox.addChild(new Text(collapsedHint, 0, 0));
|
|
519
|
+
customRendererHasContent = true;
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
const resultComponent = this.toolDefinition.renderResult(
|
|
523
|
+
{ content: this.result.content as any, details: this.result.details },
|
|
524
|
+
{ expanded: this.expanded, isPartial: this.isPartial },
|
|
525
|
+
theme,
|
|
526
|
+
);
|
|
527
|
+
if (resultComponent !== undefined) {
|
|
528
|
+
this.contentBox.addChild(resultComponent);
|
|
529
|
+
customRendererHasContent = true;
|
|
530
|
+
// bg_shell: show /bg hint after start/list/digest actions
|
|
531
|
+
if (this.toolName === 'bg_shell' && this.result && !this.isPartial) {
|
|
532
|
+
const details = this.result.details as Record<string, unknown> | undefined;
|
|
533
|
+
const action = details?.action as string | undefined;
|
|
534
|
+
if (action === 'start' || action === 'list' || action === 'digest') {
|
|
535
|
+
this.contentBox.addChild(new Text(
|
|
536
|
+
'\n' + theme.fg('muted', 'Tip: run /bg to manage background processes'),
|
|
537
|
+
0, 0,
|
|
538
|
+
));
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
} catch {
|
|
544
|
+
// Fall back to showing raw output on error
|
|
545
|
+
const output = this.getTextOutput();
|
|
546
|
+
if (output) {
|
|
547
|
+
this.contentBox.addChild(new Text(theme.fg("toolOutput", output), 0, 0));
|
|
548
|
+
customRendererHasContent = true;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
} else if (this.result) {
|
|
552
|
+
// Has result but no custom renderResult
|
|
553
|
+
const output = this.getTextOutput();
|
|
554
|
+
if (output) {
|
|
555
|
+
if (this.shouldHideCollapsedPreview()) {
|
|
556
|
+
const collapsedHint = this.collapsedHintWithPrefix("\n");
|
|
557
|
+
if (collapsedHint) {
|
|
558
|
+
this.contentBox.addChild(new Text(collapsedHint, 0, 0));
|
|
559
|
+
}
|
|
560
|
+
} else {
|
|
561
|
+
this.contentBox.addChild(new Text(theme.fg("toolOutput", output), 0, 0));
|
|
562
|
+
}
|
|
563
|
+
customRendererHasContent = true;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
} else {
|
|
567
|
+
// Unknown tool with no registered definition - show generic fallback
|
|
568
|
+
this.contentText.setCustomBgFn((text: string) => text);
|
|
569
|
+
this.contentText.setText(this.formatToolExecution(statusIndicator));
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// Handle images (same for both custom and built-in)
|
|
573
|
+
for (const img of this.imageComponents) {
|
|
574
|
+
this.removeChild(img);
|
|
575
|
+
}
|
|
576
|
+
this.imageComponents = [];
|
|
577
|
+
for (const spacer of this.imageSpacers) {
|
|
578
|
+
this.removeChild(spacer);
|
|
579
|
+
}
|
|
580
|
+
this.imageSpacers = [];
|
|
581
|
+
|
|
582
|
+
if (this.result) {
|
|
583
|
+
const imageBlocks = this.result.content?.filter((c: any) => c.type === "image") || [];
|
|
584
|
+
const caps = getCapabilities();
|
|
585
|
+
|
|
586
|
+
for (let i = 0; i < imageBlocks.length; i++) {
|
|
587
|
+
const img = imageBlocks[i];
|
|
588
|
+
if (caps.images && this.showImages && img.data && img.mimeType) {
|
|
589
|
+
// Use converted PNG for Kitty protocol if available
|
|
590
|
+
const converted = this.convertedImages.get(i);
|
|
591
|
+
const imageData = converted?.data ?? img.data;
|
|
592
|
+
const imageMimeType = converted?.mimeType ?? img.mimeType;
|
|
593
|
+
|
|
594
|
+
// For Kitty, skip non-PNG images that haven't been converted yet
|
|
595
|
+
if (caps.images === "kitty" && imageMimeType !== "image/png") {
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const spacer = new Spacer(1);
|
|
600
|
+
this.addChild(spacer);
|
|
601
|
+
this.imageSpacers.push(spacer);
|
|
602
|
+
const imageComponent = new Image(
|
|
603
|
+
imageData,
|
|
604
|
+
imageMimeType,
|
|
605
|
+
{ fallbackColor: (s: string) => theme.fg("toolOutput", s) },
|
|
606
|
+
{ maxWidthCells: 60 },
|
|
607
|
+
);
|
|
608
|
+
imageComponent.setOnDimensionsResolved(() => {
|
|
609
|
+
this.updateDisplay();
|
|
610
|
+
this.ui.requestRender();
|
|
611
|
+
});
|
|
612
|
+
this.imageComponents.push(imageComponent);
|
|
613
|
+
this.addChild(imageComponent);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
const computedHidden = !useBuiltInRenderer && this.toolDefinition ? !customRendererHasContent && this.imageComponents.length === 0 : false;
|
|
619
|
+
this.hideComponent = this.manuallyHidden || computedHidden;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Render bash content using visual line truncation (like bash-execution.ts)
|
|
624
|
+
*/
|
|
625
|
+
private renderBashContent(statusIndicator: string): void {
|
|
626
|
+
const command = str(this.args?.command);
|
|
627
|
+
const timeout = this.args?.timeout as number | undefined;
|
|
628
|
+
const body = new Container();
|
|
629
|
+
|
|
630
|
+
this.contentBox.addChild(body);
|
|
631
|
+
|
|
632
|
+
const timeoutSuffix = timeout ? theme.fg("muted", ` (timeout ${timeout}s)`) : "";
|
|
633
|
+
const sandboxBadge = this.result?.details?.sandboxed ? ` ${theme.fg("success", "[sandboxed]")}` : "";
|
|
634
|
+
const toolLabel = theme.fg("toolTitle", theme.bold("bash"));
|
|
635
|
+
const shellPrompt = theme.fg("muted", "$ ");
|
|
636
|
+
|
|
637
|
+
// Always show only the first meaningful non-comment line in the header.
|
|
638
|
+
// The full command is shown below the header when expanded.
|
|
639
|
+
let commandDisplay: string;
|
|
640
|
+
let commandLines: string[] = [];
|
|
641
|
+
let isMultiLine = false;
|
|
642
|
+
if (command === null) {
|
|
643
|
+
commandDisplay = theme.fg("error", "[invalid arg]");
|
|
644
|
+
} else if (!command) {
|
|
645
|
+
commandDisplay = theme.fg("toolOutput", "...");
|
|
646
|
+
} else {
|
|
647
|
+
commandLines = command.split("\n");
|
|
648
|
+
isMultiLine = commandLines.length > 1;
|
|
649
|
+
const firstMeaningful = commandLines.find((l) => l.trim() && !l.trim().startsWith("#")) ?? commandLines[0];
|
|
650
|
+
const suffix = isMultiLine ? theme.fg("muted", " …") : "";
|
|
651
|
+
commandDisplay = theme.fg("toolOutput", firstMeaningful ?? "") + suffix;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
body.addChild(new Text(`${statusIndicator} ${toolLabel} ${shellPrompt}${commandDisplay}${timeoutSuffix}${sandboxBadge}`, 0, 0));
|
|
655
|
+
|
|
656
|
+
// When expanded, show the full command below the header (only for multi-line commands)
|
|
657
|
+
if (this.expanded && isMultiLine) {
|
|
658
|
+
const fullCommand = commandLines.map((line) => theme.fg("toolOutput", line)).join("\n");
|
|
659
|
+
body.addChild(new Text(`\n${fullCommand}`, 0, 0));
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if (this.result) {
|
|
663
|
+
const output = this.getTextOutput().trim();
|
|
664
|
+
|
|
665
|
+
if (output) {
|
|
666
|
+
const styledOutput = output
|
|
667
|
+
.split("\n")
|
|
668
|
+
.map((line) => theme.fg("toolOutput", line))
|
|
669
|
+
.join("\n");
|
|
670
|
+
|
|
671
|
+
if (this.expanded) {
|
|
672
|
+
body.addChild(new Text(`\n${styledOutput}`, 0, 0));
|
|
673
|
+
} else if (this.renderMode === "minimal") {
|
|
674
|
+
const collapsedHint = this.collapsedHintWithPrefix("\n");
|
|
675
|
+
if (collapsedHint) {
|
|
676
|
+
body.addChild(new Text(collapsedHint, 1, 0));
|
|
677
|
+
}
|
|
678
|
+
} else {
|
|
679
|
+
let cachedWidth: number | undefined;
|
|
680
|
+
let cachedLines: string[] | undefined;
|
|
681
|
+
let cachedSkipped: number | undefined;
|
|
682
|
+
|
|
683
|
+
body.addChild({
|
|
684
|
+
render: (width: number) => {
|
|
685
|
+
if (cachedLines === undefined || cachedWidth !== width) {
|
|
686
|
+
const result = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, Math.max(1, width - 1));
|
|
687
|
+
cachedLines = result.visualLines.map((line) => ` ${line}`);
|
|
688
|
+
cachedSkipped = result.skippedCount;
|
|
689
|
+
cachedWidth = width;
|
|
690
|
+
}
|
|
691
|
+
if (cachedSkipped && cachedSkipped > 0) {
|
|
692
|
+
const hint = theme.fg("muted", `... (${cachedSkipped} earlier lines)`);
|
|
693
|
+
return ["", truncateToWidth(` ${hint}`, width, "..."), ...cachedLines];
|
|
694
|
+
}
|
|
695
|
+
return ["", ...cachedLines];
|
|
696
|
+
},
|
|
697
|
+
invalidate: () => {
|
|
698
|
+
cachedWidth = undefined;
|
|
699
|
+
cachedLines = undefined;
|
|
700
|
+
cachedSkipped = undefined;
|
|
701
|
+
},
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
const truncation = this.result.details?.truncation;
|
|
707
|
+
const fullOutputPath = this.result.details?.fullOutputPath;
|
|
708
|
+
if (truncation?.truncated || fullOutputPath) {
|
|
709
|
+
const warnings: string[] = [];
|
|
710
|
+
if (fullOutputPath) {
|
|
711
|
+
warnings.push(`Full output: ${fullOutputPath}`);
|
|
712
|
+
}
|
|
713
|
+
if (truncation?.truncated) {
|
|
714
|
+
if (truncation.truncatedBy === "lines") {
|
|
715
|
+
warnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);
|
|
716
|
+
} else {
|
|
717
|
+
warnings.push(
|
|
718
|
+
`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
body.addChild(new Text(`\n${theme.fg("warning", `[${warnings.join(". ")}]`)}`, 0, 0));
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// Privilege escalation error — agent cannot sudo, show manual step callout
|
|
726
|
+
if (this.result.isError && command !== null && isBashPrivilegeError(output, command)) {
|
|
727
|
+
body.addChild(
|
|
728
|
+
new Text(
|
|
729
|
+
`\n${theme.fg("warning", "⚠ This command requires elevated privileges the agent cannot use.")}\n${theme.fg("muted", `Run it manually in your terminal:\n ${command}`)}`,
|
|
730
|
+
0,
|
|
731
|
+
0,
|
|
732
|
+
),
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
private getTextOutput(): string {
|
|
739
|
+
if (!this.result) return "";
|
|
740
|
+
|
|
741
|
+
const textBlocks = this.result.content?.filter((c: any) => c.type === "text") || [];
|
|
742
|
+
const imageBlocks = this.result.content?.filter((c: any) => c.type === "image") || [];
|
|
743
|
+
|
|
744
|
+
let output = textBlocks
|
|
745
|
+
.map((c: any) => {
|
|
746
|
+
// Use sanitizeBinaryOutput to handle binary data that crashes string-width
|
|
747
|
+
return sanitizeBinaryOutput(c.text || "");
|
|
748
|
+
})
|
|
749
|
+
.join("\n");
|
|
750
|
+
|
|
751
|
+
if (this.toolName === "bash") {
|
|
752
|
+
output = renderTerminalText(output);
|
|
753
|
+
} else {
|
|
754
|
+
output = output.replace(/\r/g, "");
|
|
755
|
+
output = stripAnsi(output);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
const caps = getCapabilities();
|
|
759
|
+
if (imageBlocks.length > 0 && (!caps.images || !this.showImages)) {
|
|
760
|
+
const imageIndicators = imageBlocks
|
|
761
|
+
.map((img: any) => {
|
|
762
|
+
return imageFallback(img.mimeType);
|
|
763
|
+
})
|
|
764
|
+
.join("\n");
|
|
765
|
+
output = output ? `${output}\n${imageIndicators}` : imageIndicators;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
return output;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
private shouldHideCollapsedPreview(): boolean {
|
|
772
|
+
// Always hide preview for read tool when not expanded (like Claude Code)
|
|
773
|
+
// For other tools, only hide in minimal mode without errors
|
|
774
|
+
if (this.toolName === "read") {
|
|
775
|
+
return !this.expanded && !this.result?.isError;
|
|
776
|
+
}
|
|
777
|
+
return !this.expanded && this.renderMode === "minimal" && !this.result?.isError;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
private collapsedExpandHint(_label?: string): string {
|
|
781
|
+
return ""; // hint is shown in editor bottom border instead
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
private collapsedHintWithPrefix(prefix = "\n\n"): string {
|
|
785
|
+
const hint = this.collapsedExpandHint();
|
|
786
|
+
return hint ? `${prefix}${hint}` : "";
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
private collapsedFirstLine(output: string): string | undefined {
|
|
790
|
+
const first = output.split("\n").map((line) => line.trim()).find(Boolean);
|
|
791
|
+
return first ? truncateToWidth(first, 120, "...") : undefined;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
private formatToolExecution(statusIndicator: string): string {
|
|
795
|
+
let text = "";
|
|
796
|
+
const invalidArg = theme.fg("error", "[invalid arg]");
|
|
797
|
+
const hideCollapsedPreview = this.shouldHideCollapsedPreview();
|
|
798
|
+
|
|
799
|
+
if (this.toolName === "read") {
|
|
800
|
+
const rawPath = str(this.args?.file_path ?? this.args?.path);
|
|
801
|
+
const path = rawPath !== null ? shortenPath(rawPath) : null;
|
|
802
|
+
const offset = this.args?.offset;
|
|
803
|
+
const limit = this.args?.limit;
|
|
804
|
+
|
|
805
|
+
const startLine = offset ?? 1;
|
|
806
|
+
const endLine = limit !== undefined ? startLine + limit - 1 : "";
|
|
807
|
+
const lineNum = offset !== undefined ? startLine : undefined;
|
|
808
|
+
|
|
809
|
+
let styledPath = path === null ? invalidArg : path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
|
810
|
+
if (rawPath && path) {
|
|
811
|
+
styledPath = editorLink(rawPath, styledPath, { cwd: this.cwd, line: lineNum, scheme: this.editorScheme });
|
|
812
|
+
}
|
|
813
|
+
let pathDisplay = styledPath;
|
|
814
|
+
if (offset !== undefined || limit !== undefined) {
|
|
815
|
+
pathDisplay += theme.fg("warning", `:${startLine}${endLine ? `-${endLine}` : ""}`);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
text = `${statusIndicator} ${theme.fg("toolTitle", theme.bold("read"))} ${pathDisplay}`;
|
|
819
|
+
|
|
820
|
+
if (this.result) {
|
|
821
|
+
const rawOutput = this.getTextOutput();
|
|
822
|
+
// Strip hashline prefixes (e.g. "1#BQ:content") for TUI display
|
|
823
|
+
const output = rawOutput.replace(/^(\s*)\d+#[ZPMQVRWSNKTXJBYH]{2}:/gm, "$1");
|
|
824
|
+
const rawPath = str(this.args?.file_path ?? this.args?.path);
|
|
825
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
826
|
+
const lines = lang ? highlightCode(replaceTabs(output), lang) : output.split("\n");
|
|
827
|
+
|
|
828
|
+
if (hideCollapsedPreview) {
|
|
829
|
+
if (output.trim()) {
|
|
830
|
+
text += this.collapsedHintWithPrefix();
|
|
831
|
+
}
|
|
832
|
+
} else {
|
|
833
|
+
const maxLines = this.expanded ? lines.length : 10;
|
|
834
|
+
const displayLines = lines.slice(0, maxLines);
|
|
835
|
+
const remaining = lines.length - maxLines;
|
|
836
|
+
|
|
837
|
+
text +=
|
|
838
|
+
"\n\n" +
|
|
839
|
+
displayLines
|
|
840
|
+
.map((line: string) => (lang ? replaceTabs(line) : theme.fg("toolOutput", replaceTabs(line))))
|
|
841
|
+
.join("\n");
|
|
842
|
+
if (remaining > 0) {
|
|
843
|
+
text += theme.fg("muted", `\n... (${remaining} more lines)`);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
const truncation = this.result.details?.truncation;
|
|
848
|
+
if (truncation?.truncated) {
|
|
849
|
+
if (truncation.firstLineExceedsLimit) {
|
|
850
|
+
text +=
|
|
851
|
+
"\n" +
|
|
852
|
+
theme.fg(
|
|
853
|
+
"warning",
|
|
854
|
+
`[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`,
|
|
855
|
+
);
|
|
856
|
+
} else if (truncation.truncatedBy === "lines") {
|
|
857
|
+
text +=
|
|
858
|
+
"\n" +
|
|
859
|
+
theme.fg(
|
|
860
|
+
"warning",
|
|
861
|
+
`[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`,
|
|
862
|
+
);
|
|
863
|
+
} else {
|
|
864
|
+
text +=
|
|
865
|
+
"\n" +
|
|
866
|
+
theme.fg(
|
|
867
|
+
"warning",
|
|
868
|
+
`[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`,
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
} else if (this.toolName === "write") {
|
|
874
|
+
const rawPath = str(this.args?.file_path ?? this.args?.path);
|
|
875
|
+
const fileContent = str(this.args?.content);
|
|
876
|
+
const path = rawPath !== null ? shortenPath(rawPath) : null;
|
|
877
|
+
|
|
878
|
+
let writePathDisplay = path === null ? invalidArg : path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
|
879
|
+
if (rawPath && path) {
|
|
880
|
+
writePathDisplay = editorLink(rawPath, writePathDisplay, { cwd: this.cwd, scheme: this.editorScheme });
|
|
881
|
+
}
|
|
882
|
+
text = `${statusIndicator} ${theme.fg("toolTitle", theme.bold("write"))} ${writePathDisplay}`;
|
|
883
|
+
|
|
884
|
+
if (fileContent === null) {
|
|
885
|
+
text += `\n\n${theme.fg("error", "[invalid content arg - expected string]")}`;
|
|
886
|
+
} else if (fileContent) {
|
|
887
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
888
|
+
|
|
889
|
+
let lines: string[];
|
|
890
|
+
if (lang) {
|
|
891
|
+
const cache = this.writeHighlightCache;
|
|
892
|
+
if (cache && cache.lang === lang && cache.rawPath === rawPath && cache.rawContent === fileContent) {
|
|
893
|
+
lines = cache.highlightedLines;
|
|
894
|
+
} else {
|
|
895
|
+
const displayContent = normalizeDisplayText(fileContent);
|
|
896
|
+
const normalized = replaceTabs(displayContent);
|
|
897
|
+
lines = highlightCode(normalized, lang);
|
|
898
|
+
this.writeHighlightCache = {
|
|
899
|
+
rawPath,
|
|
900
|
+
lang,
|
|
901
|
+
rawContent: fileContent,
|
|
902
|
+
normalizedLines: normalized.split("\n"),
|
|
903
|
+
highlightedLines: lines,
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
} else {
|
|
907
|
+
lines = normalizeDisplayText(fileContent).split("\n");
|
|
908
|
+
this.writeHighlightCache = undefined;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
if (hideCollapsedPreview) {
|
|
912
|
+
text += this.collapsedHintWithPrefix();
|
|
913
|
+
} else {
|
|
914
|
+
const totalLines = lines.length;
|
|
915
|
+
const maxLines = this.expanded ? lines.length : 10;
|
|
916
|
+
const displayLines = lines.slice(0, maxLines);
|
|
917
|
+
const remaining = lines.length - maxLines;
|
|
918
|
+
|
|
919
|
+
text +=
|
|
920
|
+
"\n\n" +
|
|
921
|
+
displayLines.map((line: string) => (lang ? line : theme.fg("toolOutput", replaceTabs(line)))).join("\n");
|
|
922
|
+
if (remaining > 0) {
|
|
923
|
+
text += theme.fg("muted", `\n... (${remaining} more lines, ${totalLines} total)`);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// Show error if tool execution failed
|
|
929
|
+
if (this.result?.isError) {
|
|
930
|
+
const errorText = this.getTextOutput();
|
|
931
|
+
if (errorText) {
|
|
932
|
+
text += `\n\n${theme.fg("error", errorText)}`;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
} else if (this.toolName === "edit") {
|
|
936
|
+
const rawPath = str(this.args?.file_path ?? this.args?.path);
|
|
937
|
+
const path = rawPath !== null ? shortenPath(rawPath) : null;
|
|
938
|
+
|
|
939
|
+
// Build path display, appending :line if we have diff info
|
|
940
|
+
const firstChangedLine =
|
|
941
|
+
(this.editDiffPreview && "firstChangedLine" in this.editDiffPreview
|
|
942
|
+
? this.editDiffPreview.firstChangedLine
|
|
943
|
+
: undefined) ||
|
|
944
|
+
(this.result && !this.result.isError ? this.result.details?.firstChangedLine : undefined);
|
|
945
|
+
|
|
946
|
+
let styledEditPath = path === null ? invalidArg : path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
|
947
|
+
if (rawPath && path) {
|
|
948
|
+
styledEditPath = editorLink(rawPath, styledEditPath, {
|
|
949
|
+
cwd: this.cwd,
|
|
950
|
+
line: firstChangedLine ?? undefined,
|
|
951
|
+
scheme: this.editorScheme,
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
let pathDisplay = styledEditPath;
|
|
955
|
+
if (firstChangedLine) {
|
|
956
|
+
pathDisplay += theme.fg("warning", `:${firstChangedLine}`);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
text = `${statusIndicator} ${theme.fg("toolTitle", theme.bold("edit"))} ${pathDisplay}`;
|
|
960
|
+
|
|
961
|
+
if (this.result?.isError) {
|
|
962
|
+
// Show error from result
|
|
963
|
+
const errorText = this.getTextOutput();
|
|
964
|
+
if (errorText) {
|
|
965
|
+
text += `\n\n${theme.fg("error", errorText)}`;
|
|
966
|
+
}
|
|
967
|
+
} else if (this.result?.details?.diff) {
|
|
968
|
+
// Tool executed successfully - use the diff from result
|
|
969
|
+
// This takes priority over editDiffPreview which may have a stale error
|
|
970
|
+
// due to race condition (async preview computed after file was modified)
|
|
971
|
+
text += hideCollapsedPreview
|
|
972
|
+
? this.collapsedHintWithPrefix()
|
|
973
|
+
: `\n\n${renderDiff(this.result.details.diff, { filePath: rawPath ?? undefined })}`;
|
|
974
|
+
} else if (this.editDiffPreview) {
|
|
975
|
+
// Use cached diff preview (before tool executes)
|
|
976
|
+
if ("error" in this.editDiffPreview) {
|
|
977
|
+
text += `\n\n${theme.fg("error", this.editDiffPreview.error)}`;
|
|
978
|
+
} else if (this.editDiffPreview.diff) {
|
|
979
|
+
text += hideCollapsedPreview
|
|
980
|
+
? this.collapsedHintWithPrefix()
|
|
981
|
+
: `\n\n${renderDiff(this.editDiffPreview.diff, { filePath: rawPath ?? undefined })}`;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
} else if (this.toolName === "ls") {
|
|
985
|
+
const rawPath = str(this.args?.path);
|
|
986
|
+
const path = rawPath !== null ? shortenPath(rawPath || ".") : null;
|
|
987
|
+
const limit = this.args?.limit;
|
|
988
|
+
|
|
989
|
+
let lsPathDisplay = path === null ? invalidArg : theme.fg("accent", path);
|
|
990
|
+
if (path && rawPath !== null) {
|
|
991
|
+
lsPathDisplay = editorLink(rawPath || ".", lsPathDisplay, { cwd: this.cwd, scheme: this.editorScheme });
|
|
992
|
+
}
|
|
993
|
+
text = `${statusIndicator} ${theme.fg("toolTitle", theme.bold("ls"))} ${lsPathDisplay}`;
|
|
994
|
+
if (limit !== undefined) {
|
|
995
|
+
text += theme.fg("toolOutput", ` (limit ${limit})`);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
if (this.result) {
|
|
999
|
+
const output = this.getTextOutput().trim();
|
|
1000
|
+
if (output) {
|
|
1001
|
+
if (hideCollapsedPreview) {
|
|
1002
|
+
text += this.collapsedHintWithPrefix();
|
|
1003
|
+
} else {
|
|
1004
|
+
const lines = output.split("\n");
|
|
1005
|
+
const maxLines = this.expanded ? lines.length : 20;
|
|
1006
|
+
const displayLines = lines.slice(0, maxLines);
|
|
1007
|
+
const remaining = lines.length - maxLines;
|
|
1008
|
+
|
|
1009
|
+
text += `\n\n${displayLines.map((line: string) => theme.fg("toolOutput", line)).join("\n")}`;
|
|
1010
|
+
if (remaining > 0) {
|
|
1011
|
+
text += theme.fg("muted", `\n... (${remaining} more lines)`);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
const entryLimit = this.result.details?.entryLimitReached;
|
|
1017
|
+
const truncation = this.result.details?.truncation;
|
|
1018
|
+
if (entryLimit || truncation?.truncated) {
|
|
1019
|
+
const warnings: string[] = [];
|
|
1020
|
+
if (entryLimit) {
|
|
1021
|
+
warnings.push(`${entryLimit} entries limit`);
|
|
1022
|
+
}
|
|
1023
|
+
if (truncation?.truncated) {
|
|
1024
|
+
warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);
|
|
1025
|
+
}
|
|
1026
|
+
text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
} else if (this.toolName === "find") {
|
|
1030
|
+
const pattern = str(this.args?.pattern);
|
|
1031
|
+
const rawPath = str(this.args?.path);
|
|
1032
|
+
const path = rawPath !== null ? shortenPath(rawPath || ".") : null;
|
|
1033
|
+
const limit = this.args?.limit;
|
|
1034
|
+
|
|
1035
|
+
let findPathDisplay = path === null ? invalidArg : path;
|
|
1036
|
+
if (path && rawPath !== null) {
|
|
1037
|
+
findPathDisplay = editorLink(rawPath || ".", theme.fg("accent", findPathDisplay), { cwd: this.cwd, scheme: this.editorScheme });
|
|
1038
|
+
} else {
|
|
1039
|
+
findPathDisplay = theme.fg("accent", findPathDisplay);
|
|
1040
|
+
}
|
|
1041
|
+
text =
|
|
1042
|
+
`${statusIndicator} ${theme.fg("toolTitle", theme.bold("find"))}` +
|
|
1043
|
+
" " +
|
|
1044
|
+
(pattern === null ? invalidArg : theme.fg("accent", pattern || "")) +
|
|
1045
|
+
theme.fg("toolOutput", " in ") +
|
|
1046
|
+
findPathDisplay;
|
|
1047
|
+
if (limit !== undefined) {
|
|
1048
|
+
text += theme.fg("toolOutput", ` (limit ${limit})`);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
if (this.result) {
|
|
1052
|
+
const output = this.getTextOutput().trim();
|
|
1053
|
+
if (output) {
|
|
1054
|
+
if (hideCollapsedPreview) {
|
|
1055
|
+
text += this.collapsedHintWithPrefix();
|
|
1056
|
+
} else {
|
|
1057
|
+
const lines = output.split("\n");
|
|
1058
|
+
const maxLines = this.expanded ? lines.length : 20;
|
|
1059
|
+
const displayLines = lines.slice(0, maxLines);
|
|
1060
|
+
const remaining = lines.length - maxLines;
|
|
1061
|
+
|
|
1062
|
+
text += `\n\n${displayLines.map((line: string) => theme.fg("toolOutput", line)).join("\n")}`;
|
|
1063
|
+
if (remaining > 0) {
|
|
1064
|
+
text += theme.fg("muted", `\n... (${remaining} more lines)`);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
const resultLimit = this.result.details?.resultLimitReached;
|
|
1070
|
+
const truncation = this.result.details?.truncation;
|
|
1071
|
+
if (resultLimit || truncation?.truncated) {
|
|
1072
|
+
const warnings: string[] = [];
|
|
1073
|
+
if (resultLimit) {
|
|
1074
|
+
warnings.push(`${resultLimit} results limit`);
|
|
1075
|
+
}
|
|
1076
|
+
if (truncation?.truncated) {
|
|
1077
|
+
warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);
|
|
1078
|
+
}
|
|
1079
|
+
text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
} else if (this.toolName === "grep") {
|
|
1083
|
+
const pattern = str(this.args?.pattern);
|
|
1084
|
+
const rawPath = str(this.args?.path);
|
|
1085
|
+
const path = rawPath !== null ? shortenPath(rawPath || ".") : null;
|
|
1086
|
+
const glob = str(this.args?.glob);
|
|
1087
|
+
const limit = this.args?.limit;
|
|
1088
|
+
|
|
1089
|
+
let grepPathDisplay = path === null ? invalidArg : path;
|
|
1090
|
+
if (path && rawPath !== null) {
|
|
1091
|
+
grepPathDisplay = editorLink(rawPath || ".", theme.fg("accent", grepPathDisplay), { cwd: this.cwd, scheme: this.editorScheme });
|
|
1092
|
+
} else {
|
|
1093
|
+
grepPathDisplay = theme.fg("accent", grepPathDisplay);
|
|
1094
|
+
}
|
|
1095
|
+
text =
|
|
1096
|
+
`${statusIndicator} ${theme.fg("toolTitle", theme.bold("grep"))}` +
|
|
1097
|
+
" " +
|
|
1098
|
+
(pattern === null ? invalidArg : theme.fg("accent", `/${pattern || ""}/`)) +
|
|
1099
|
+
theme.fg("toolOutput", " in ") +
|
|
1100
|
+
grepPathDisplay;
|
|
1101
|
+
if (glob) {
|
|
1102
|
+
text += theme.fg("toolOutput", ` (${glob})`);
|
|
1103
|
+
}
|
|
1104
|
+
if (limit !== undefined) {
|
|
1105
|
+
text += theme.fg("toolOutput", ` limit ${limit}`);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
if (this.result) {
|
|
1109
|
+
const output = this.getTextOutput().trim();
|
|
1110
|
+
if (output) {
|
|
1111
|
+
if (hideCollapsedPreview) {
|
|
1112
|
+
text += this.collapsedHintWithPrefix();
|
|
1113
|
+
} else {
|
|
1114
|
+
const lines = output.split("\n");
|
|
1115
|
+
const maxLines = this.expanded ? lines.length : 15;
|
|
1116
|
+
const displayLines = lines.slice(0, maxLines);
|
|
1117
|
+
const remaining = lines.length - maxLines;
|
|
1118
|
+
|
|
1119
|
+
text += `\n\n${displayLines.map((line: string) => theme.fg("toolOutput", line)).join("\n")}`;
|
|
1120
|
+
if (remaining > 0) {
|
|
1121
|
+
text += theme.fg("muted", `\n... (${remaining} more lines)`);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
const matchLimit = this.result.details?.matchLimitReached;
|
|
1127
|
+
const truncation = this.result.details?.truncation;
|
|
1128
|
+
const linesTruncated = this.result.details?.linesTruncated;
|
|
1129
|
+
if (matchLimit || truncation?.truncated || linesTruncated) {
|
|
1130
|
+
const warnings: string[] = [];
|
|
1131
|
+
if (matchLimit) {
|
|
1132
|
+
warnings.push(`${matchLimit} matches limit`);
|
|
1133
|
+
}
|
|
1134
|
+
if (truncation?.truncated) {
|
|
1135
|
+
warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);
|
|
1136
|
+
}
|
|
1137
|
+
if (linesTruncated) {
|
|
1138
|
+
warnings.push("some lines truncated");
|
|
1139
|
+
}
|
|
1140
|
+
text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
} else if (this.toolName === "web_search") {
|
|
1144
|
+
// Server-side Anthropic web search
|
|
1145
|
+
text = `${statusIndicator} ${theme.fg("toolTitle", theme.bold("web search"))}`;
|
|
1146
|
+
|
|
1147
|
+
if (process.env.PI_OFFLINE === "1") {
|
|
1148
|
+
text += "\n\n" + theme.fg("muted", "\u{1F50C} Offline \u{2014} web search unavailable");
|
|
1149
|
+
} else if (this.result) {
|
|
1150
|
+
const output = this.getTextOutput().trim();
|
|
1151
|
+
if (output) {
|
|
1152
|
+
if (hideCollapsedPreview) {
|
|
1153
|
+
text += this.collapsedHintWithPrefix();
|
|
1154
|
+
} else {
|
|
1155
|
+
const lines = output.split("\n");
|
|
1156
|
+
const maxLines = this.expanded ? lines.length : 10;
|
|
1157
|
+
const displayLines = lines.slice(0, maxLines);
|
|
1158
|
+
const remaining = lines.length - maxLines;
|
|
1159
|
+
|
|
1160
|
+
text += `\n\n${displayLines.map((line: string) => theme.fg("toolOutput", line)).join("\n")}`;
|
|
1161
|
+
if (remaining > 0) {
|
|
1162
|
+
text += theme.fg("muted", `\n... (${remaining} more lines)`);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
} else if (this.toolName === "lsp") {
|
|
1168
|
+
const action = this.args?.action as string | undefined;
|
|
1169
|
+
const file = this.args?.file as string | undefined;
|
|
1170
|
+
const line = this.args?.line as number | undefined;
|
|
1171
|
+
const symbol = this.args?.symbol as string | undefined;
|
|
1172
|
+
const query = this.args?.query as string | undefined;
|
|
1173
|
+
const newName = this.args?.new_name as string | undefined;
|
|
1174
|
+
|
|
1175
|
+
text = `${statusIndicator} ${theme.fg("toolTitle", theme.bold("lsp"))}`;
|
|
1176
|
+
if (action) text += ` ${theme.fg("accent", action)}`;
|
|
1177
|
+
if (file) {
|
|
1178
|
+
const shortFile = shortenPath(file);
|
|
1179
|
+
let styledFile = theme.fg("muted", shortFile);
|
|
1180
|
+
if (file && shortFile) {
|
|
1181
|
+
styledFile = editorLink(file, styledFile, { cwd: this.cwd, line, scheme: this.editorScheme });
|
|
1182
|
+
}
|
|
1183
|
+
text += ` ${styledFile}`;
|
|
1184
|
+
if (line !== undefined) text += theme.fg("warning", `:${line}`);
|
|
1185
|
+
}
|
|
1186
|
+
if (symbol) text += ` ${theme.fg("toolOutput", symbol)}`;
|
|
1187
|
+
if (query) text += ` ${theme.fg("muted", `"${query}"`)}`;
|
|
1188
|
+
if (newName) text += ` → ${theme.fg("accent", newName)}`;
|
|
1189
|
+
|
|
1190
|
+
if (this.result) {
|
|
1191
|
+
const output = this.getTextOutput().trim();
|
|
1192
|
+
if (output) {
|
|
1193
|
+
if (hideCollapsedPreview) {
|
|
1194
|
+
text += this.collapsedHintWithPrefix();
|
|
1195
|
+
} else {
|
|
1196
|
+
const lines = output.split("\n");
|
|
1197
|
+
const maxLines = this.expanded ? lines.length : 10;
|
|
1198
|
+
const displayLines = lines.slice(0, maxLines);
|
|
1199
|
+
const remaining = lines.length - maxLines;
|
|
1200
|
+
text += `\n\n${displayLines.map((l: string) => theme.fg("toolOutput", l)).join("\n")}`;
|
|
1201
|
+
if (remaining > 0) text += theme.fg("muted", `\n... (${remaining} more lines)`);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
} else {
|
|
1206
|
+
// Generic tool (shouldn't reach here for custom tools)
|
|
1207
|
+
text = `${statusIndicator} ${theme.fg("toolTitle", theme.bold(this.toolName))}`;
|
|
1208
|
+
|
|
1209
|
+
const content = JSON.stringify(this.args, null, 2);
|
|
1210
|
+
text += hideCollapsedPreview ? this.collapsedHintWithPrefix() : `\n\n${content}`;
|
|
1211
|
+
const output = this.getTextOutput();
|
|
1212
|
+
if (output && !hideCollapsedPreview) {
|
|
1213
|
+
text += `\n${output}`;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
return text;
|
|
1218
|
+
}
|
|
1201
1219
|
}
|