pi-subagent-manager 1.10.0 → 1.12.0
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/README.md +9 -9
- package/dist/index.d.ts +2 -0
- package/dist/index.js +790 -0
- package/dist/orch/checklist-integration.js +176 -0
- package/dist/orch/context-entries.js +6 -0
- package/dist/orch/cost-ledger.js +38 -0
- package/dist/orch/diagnostics.js +86 -0
- package/dist/orch/extensions.js +66 -0
- package/dist/orch/housekeeping-usage.js +22 -0
- package/dist/orch/housekeeping.js +248 -0
- package/dist/orch/inherited-tools.js +57 -0
- package/dist/orch/mailbox.js +195 -0
- package/dist/orch/manager.js +970 -0
- package/dist/orch/paths.js +69 -0
- package/dist/orch/prompt.js +30 -0
- package/dist/orch/registry.js +115 -0
- package/dist/orch/runtime.js +835 -0
- package/dist/orch/tools.js +112 -0
- package/dist/orch/transcript.js +165 -0
- package/dist/prefs/agent-import.js +188 -0
- package/dist/prefs/config.js +878 -0
- package/dist/prefs/import-discovery.js +547 -0
- package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +0 -1
- package/dist/prefs/models.js +56 -0
- package/dist/prefs/settings.js +491 -0
- package/dist/types.js +1 -0
- package/dist/ui/agent-loader.js +63 -0
- package/dist/ui/agent-navigation-editor.js +168 -0
- package/dist/ui/cost-footer.js +209 -0
- package/dist/ui/dialog.js +505 -0
- package/dist/ui/import-picker.js +191 -0
- package/dist/ui/live-agent-view.js +527 -0
- package/dist/ui/model-picker.js +529 -0
- package/dist/ui/settings-ui.js +671 -0
- package/dist/ui/status-ui.js +470 -0
- package/dist/ui/thread-tree.js +142 -0
- package/dist/ui/tool-picker.js +331 -0
- package/dist/ui/transcript-tool.js +91 -0
- package/dist/ui/ui.js +1019 -0
- package/package.json +17 -5
- package/docs/assets/subagent-manager-demo.gif +0 -0
- package/docs/async-lifecycle.md +0 -153
- package/docs/custom-agents.md +0 -154
- package/docs/default-agents.md +0 -95
- package/docs/demo.md +0 -63
- package/docs/development.md +0 -74
- package/docs/importing-agents.md +0 -41
- package/docs/pi-footer.md +0 -128
- package/docs/research-claude.md +0 -258
- package/docs/research-codex.md +0 -143
- package/docs/research-default-agent-models.md +0 -121
- package/docs/research-model-audit-2026-10.md +0 -154
- package/docs/research-model-roles-coding.md +0 -99
- package/docs/research-model-roles-writing.md +0 -78
- package/docs/research-researcher-workflow.md +0 -97
- package/docs/settings.md +0 -293
- package/docs/subagent-extension-limitations.md +0 -98
- package/docs/threads.md +0 -73
- package/docs/tools-and-ui.md +0 -129
- package/src/index.ts +0 -920
- package/src/orch/checklist-integration.ts +0 -230
- package/src/orch/context-entries.ts +0 -15
- package/src/orch/cost-ledger.ts +0 -56
- package/src/orch/diagnostics.ts +0 -95
- package/src/orch/extensions.ts +0 -83
- package/src/orch/housekeeping-usage.ts +0 -47
- package/src/orch/housekeeping.ts +0 -348
- package/src/orch/inherited-tools.ts +0 -84
- package/src/orch/mailbox.ts +0 -261
- package/src/orch/manager.ts +0 -1084
- package/src/orch/paths.ts +0 -73
- package/src/orch/prompt.ts +0 -39
- package/src/orch/registry.ts +0 -168
- package/src/orch/runtime.ts +0 -1041
- package/src/orch/tools.ts +0 -190
- package/src/orch/transcript.ts +0 -186
- package/src/prefs/agent-import.ts +0 -245
- package/src/prefs/config.ts +0 -1017
- package/src/prefs/import-discovery.ts +0 -643
- package/src/prefs/models.ts +0 -74
- package/src/prefs/settings.ts +0 -614
- package/src/types.ts +0 -271
- package/src/ui/agent-loader.ts +0 -98
- package/src/ui/agent-navigation-editor.ts +0 -233
- package/src/ui/cost-footer.ts +0 -230
- package/src/ui/dialog.ts +0 -678
- package/src/ui/import-picker.ts +0 -231
- package/src/ui/live-agent-view.ts +0 -600
- package/src/ui/model-picker.ts +0 -701
- package/src/ui/settings-ui.ts +0 -830
- package/src/ui/status-ui.ts +0 -628
- package/src/ui/thread-tree.ts +0 -173
- package/src/ui/tool-picker.ts +0 -398
- package/src/ui/transcript-tool.ts +0 -142
- package/src/ui/ui.ts +0 -1407
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import fuzzysort from "fuzzysort";
|
|
2
|
+
import { getSelectListTheme, } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { Container, getKeybindings, Input, Key, matchesKey, SelectList, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
|
|
4
|
+
import { dialogHeight, dialogText, frameDialog, DIALOG_OPTIONS, } from "./dialog.js";
|
|
5
|
+
export const TOOL_EDITOR_CANCEL = Symbol("tool-editor-cancel");
|
|
6
|
+
export function toolPolicyNotice(field, policy) {
|
|
7
|
+
if (field === "allow" && policy !== "allowed") {
|
|
8
|
+
return "Allow list is not used until Tool Filtering policy is changed to Allowed (except blocked).";
|
|
9
|
+
}
|
|
10
|
+
if (field === "block" && policy === "all") {
|
|
11
|
+
return "Block list is not used until Tool Filtering policy is changed from All.";
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const LAYOUT = { minPrimaryColumnWidth: 24, maxPrimaryColumnWidth: 52 };
|
|
16
|
+
const MCP_TOOL = /^mcp__(.+?)__(.+)$/;
|
|
17
|
+
function mcpServerOf(name) {
|
|
18
|
+
return MCP_TOOL.exec(name)?.[1];
|
|
19
|
+
}
|
|
20
|
+
export class ToolPickerComponent extends Container {
|
|
21
|
+
options;
|
|
22
|
+
searchInput = new Input({ placeholder: "Search tools" });
|
|
23
|
+
selectList = new SelectList([], 1, getSelectListTheme(), LAYOUT);
|
|
24
|
+
currentItems = [];
|
|
25
|
+
tools;
|
|
26
|
+
byName;
|
|
27
|
+
draft;
|
|
28
|
+
query = "";
|
|
29
|
+
expanded = new Set();
|
|
30
|
+
_focused = false;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
super();
|
|
33
|
+
this.options = options;
|
|
34
|
+
this.byName = new Map(options.tools.map((tool) => [tool.name, tool]));
|
|
35
|
+
this.tools = [...this.byName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
36
|
+
this.draft =
|
|
37
|
+
options.initialTools === undefined ? undefined : [...new Set(options.initialTools)];
|
|
38
|
+
this.addChild(this.searchInput);
|
|
39
|
+
this.refresh();
|
|
40
|
+
}
|
|
41
|
+
get focused() {
|
|
42
|
+
return this._focused;
|
|
43
|
+
}
|
|
44
|
+
set focused(value) {
|
|
45
|
+
this._focused = value;
|
|
46
|
+
this.searchInput.focused = value;
|
|
47
|
+
}
|
|
48
|
+
getDraftTools() {
|
|
49
|
+
return this.draft;
|
|
50
|
+
}
|
|
51
|
+
getCurrentItems() {
|
|
52
|
+
return this.currentItems;
|
|
53
|
+
}
|
|
54
|
+
getSelectList() {
|
|
55
|
+
return this.selectList;
|
|
56
|
+
}
|
|
57
|
+
getSearchInput() {
|
|
58
|
+
return this.searchInput;
|
|
59
|
+
}
|
|
60
|
+
render(width) {
|
|
61
|
+
const { tui, theme, field, toolFiltering } = this.options;
|
|
62
|
+
const height = dialogHeight(tui);
|
|
63
|
+
const inner = Math.max(1, width - 4);
|
|
64
|
+
const notice = toolPolicyNotice(field, toolFiltering);
|
|
65
|
+
const header = [
|
|
66
|
+
...(notice ? wrapTextWithAnsi(theme.fg("warning", notice), inner) : []),
|
|
67
|
+
theme.fg("muted", this.draft === undefined
|
|
68
|
+
? "Unset (use default policy). Select tools to create a list."
|
|
69
|
+
: `${this.draft.length} selected · selected tools first · type to search`),
|
|
70
|
+
...this.searchInput.render(inner),
|
|
71
|
+
];
|
|
72
|
+
const selected = this.selectList.getSelectedItem()?.value;
|
|
73
|
+
const displayRows = [];
|
|
74
|
+
let previous;
|
|
75
|
+
for (const item of this.currentItems) {
|
|
76
|
+
if (item.group !== previous) {
|
|
77
|
+
if (item.group === "Actions" &&
|
|
78
|
+
!this.currentItems.some((row) => row.group === "Session tools · A–Z")) {
|
|
79
|
+
displayRows.push(this.tools.length
|
|
80
|
+
? "No unselected matching tools"
|
|
81
|
+
: "No tools available in this session");
|
|
82
|
+
}
|
|
83
|
+
displayRows.push(item.group);
|
|
84
|
+
}
|
|
85
|
+
previous = item.group;
|
|
86
|
+
displayRows.push(item);
|
|
87
|
+
}
|
|
88
|
+
const budget = Math.max(1, height - 4 - header.length);
|
|
89
|
+
const index = Math.max(0, displayRows.findIndex((row) => typeof row !== "string" && row.value === selected));
|
|
90
|
+
const start = Math.max(0, Math.min(index - budget + 1, displayRows.length - budget));
|
|
91
|
+
const rows = displayRows.slice(start, start + budget).map((row) => {
|
|
92
|
+
if (typeof row === "string")
|
|
93
|
+
return theme.fg("muted", row);
|
|
94
|
+
const text = `${row.value === selected ? "›" : " "} ${row.label} ${theme.fg("muted", row.description ?? "")}`;
|
|
95
|
+
return row.value === selected ? theme.fg("accent", text) : text;
|
|
96
|
+
});
|
|
97
|
+
return frameDialog(theme, width, height, field === "allow" ? "Allowed tools" : "Blocked tools", [...header, ...rows].map((line) => ` ${line}`), "↑↓ select · Enter toggle/action · ←→ collapse/expand MCP · Ctrl+S done · Esc cancel");
|
|
98
|
+
}
|
|
99
|
+
handleInput(data) {
|
|
100
|
+
if (matchesKey(data, Key.ctrl("s"))) {
|
|
101
|
+
this.finish();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const kb = getKeybindings();
|
|
105
|
+
const current = this.selectList.getSelectedItem()?.value;
|
|
106
|
+
const isRight = matchesKey(data, Key.right);
|
|
107
|
+
const isLeft = matchesKey(data, Key.left);
|
|
108
|
+
if ((isRight || isLeft) && current) {
|
|
109
|
+
const server = current.startsWith("group:")
|
|
110
|
+
? current.slice("group:".length)
|
|
111
|
+
: isLeft && current.startsWith("tool:")
|
|
112
|
+
? mcpServerOf(current.slice("tool:".length))
|
|
113
|
+
: undefined;
|
|
114
|
+
const key = server === undefined ? undefined : current.startsWith("group:") ? server : `mcp__${server}`;
|
|
115
|
+
if (key !== undefined) {
|
|
116
|
+
if (isRight && current.startsWith("group:"))
|
|
117
|
+
this.expanded.add(key);
|
|
118
|
+
else if (isLeft)
|
|
119
|
+
this.expanded.delete(key);
|
|
120
|
+
this.refresh(`group:${key}`);
|
|
121
|
+
this.options.tui.requestRender();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (kb.matches(data, "tui.select.up") ||
|
|
126
|
+
kb.matches(data, "tui.select.down") ||
|
|
127
|
+
kb.matches(data, "tui.select.confirm") ||
|
|
128
|
+
kb.matches(data, "tui.select.cancel")) {
|
|
129
|
+
this.selectList.handleInput(data);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this.searchInput.handleInput(data);
|
|
133
|
+
const query = this.searchInput.getValue();
|
|
134
|
+
if (query !== this.query) {
|
|
135
|
+
this.query = query;
|
|
136
|
+
this.refresh(undefined, true);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this.options.tui.requestRender();
|
|
140
|
+
}
|
|
141
|
+
finish() {
|
|
142
|
+
this.options.onDone(this.draft === undefined ? undefined : [...this.draft]);
|
|
143
|
+
}
|
|
144
|
+
refresh(selectedValue, focusResult = false) {
|
|
145
|
+
const previousIndex = this.currentItems.findIndex((row) => row.value === this.selectList.getSelectedItem()?.value);
|
|
146
|
+
const selected = new Set(this.draft ?? []);
|
|
147
|
+
const matches = this.query.trim()
|
|
148
|
+
? fuzzysort
|
|
149
|
+
.go(this.query.trim(), this.tools, {
|
|
150
|
+
keys: ["name", "description"],
|
|
151
|
+
limit: 0,
|
|
152
|
+
threshold: 0,
|
|
153
|
+
})
|
|
154
|
+
.map((result) => result.obj)
|
|
155
|
+
: this.tools;
|
|
156
|
+
const toolItem = (name, checked) => ({
|
|
157
|
+
value: `tool:${name}`,
|
|
158
|
+
label: `[${checked ? "x" : " "}] ${dialogText(name)}`,
|
|
159
|
+
description: this.byName.has(name)
|
|
160
|
+
? dialogText(this.byName.get(name).description)
|
|
161
|
+
: "unavailable in current session · preserved",
|
|
162
|
+
group: checked ? "Selected tools" : "Session tools · A–Z",
|
|
163
|
+
});
|
|
164
|
+
const searching = this.query.trim().length > 0;
|
|
165
|
+
const groups = new Map();
|
|
166
|
+
const flat = [];
|
|
167
|
+
const addName = (name) => {
|
|
168
|
+
const server = mcpServerOf(name);
|
|
169
|
+
if (server === undefined)
|
|
170
|
+
return flat.push(name);
|
|
171
|
+
const key = `mcp__${server}`;
|
|
172
|
+
const list = groups.get(key) ?? [];
|
|
173
|
+
if (!list.includes(name))
|
|
174
|
+
list.push(name);
|
|
175
|
+
groups.set(key, list);
|
|
176
|
+
};
|
|
177
|
+
for (const name of selected)
|
|
178
|
+
if (mcpServerOf(name) === undefined)
|
|
179
|
+
addName(name);
|
|
180
|
+
const matchedNames = new Set(matches.map((tool) => tool.name));
|
|
181
|
+
for (const tool of matches)
|
|
182
|
+
if (!selected.has(tool.name))
|
|
183
|
+
addName(tool.name);
|
|
184
|
+
const members = new Map();
|
|
185
|
+
for (const name of [...this.tools.map((t) => t.name), ...selected]) {
|
|
186
|
+
const server = mcpServerOf(name);
|
|
187
|
+
if (server === undefined)
|
|
188
|
+
continue;
|
|
189
|
+
const list = members.get(`mcp__${server}`) ?? [];
|
|
190
|
+
if (!list.includes(name))
|
|
191
|
+
list.push(name);
|
|
192
|
+
members.set(`mcp__${server}`, list);
|
|
193
|
+
}
|
|
194
|
+
for (const name of selected)
|
|
195
|
+
if (mcpServerOf(name) !== undefined && !searching)
|
|
196
|
+
addName(name);
|
|
197
|
+
for (const key of [...groups.keys()]) {
|
|
198
|
+
if (searching && !members.get(key).some((n) => matchedNames.has(n)))
|
|
199
|
+
groups.delete(key);
|
|
200
|
+
}
|
|
201
|
+
if (!searching)
|
|
202
|
+
for (const key of members.keys())
|
|
203
|
+
if (!groups.has(key))
|
|
204
|
+
groups.set(key, []);
|
|
205
|
+
const flatSelected = flat.filter((n) => selected.has(n));
|
|
206
|
+
const flatUnselected = flat.filter((n) => !selected.has(n));
|
|
207
|
+
const rows = flatUnselected.map((n) => ({
|
|
208
|
+
sort: n,
|
|
209
|
+
items: [toolItem(n, false)],
|
|
210
|
+
}));
|
|
211
|
+
for (const key of groups.keys()) {
|
|
212
|
+
const all = members.get(key).sort((a, b) => a.localeCompare(b));
|
|
213
|
+
const on = all.filter((n) => selected.has(n)).length;
|
|
214
|
+
const open = searching || this.expanded.has(key);
|
|
215
|
+
const mark = on === 0 ? " " : on === all.length ? "x" : "-";
|
|
216
|
+
const items = [
|
|
217
|
+
{
|
|
218
|
+
value: `group:${key}`,
|
|
219
|
+
label: `${open ? "▾" : "▸"} [${mark}] ${dialogText(key)}`,
|
|
220
|
+
description: `${on}/${all.length} tools · ${open ? "← collapse" : "→ expand"}`,
|
|
221
|
+
group: "Session tools · A–Z",
|
|
222
|
+
},
|
|
223
|
+
];
|
|
224
|
+
if (open) {
|
|
225
|
+
for (const n of all) {
|
|
226
|
+
if (searching && !matchedNames.has(n))
|
|
227
|
+
continue;
|
|
228
|
+
const item = toolItem(n, selected.has(n));
|
|
229
|
+
item.label = ` ${item.label}`;
|
|
230
|
+
item.group = "Session tools · A–Z";
|
|
231
|
+
items.push(item);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
rows.push({ sort: key, items });
|
|
235
|
+
}
|
|
236
|
+
rows.sort((x, y) => x.sort.localeCompare(y.sort));
|
|
237
|
+
this.currentItems = [
|
|
238
|
+
...flatSelected.map((name) => toolItem(name, true)),
|
|
239
|
+
...rows.flatMap((row) => row.items),
|
|
240
|
+
{
|
|
241
|
+
value: "action:done",
|
|
242
|
+
label: "Done",
|
|
243
|
+
description: "Apply this list to the agent draft",
|
|
244
|
+
group: "Actions",
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
value: "action:empty",
|
|
248
|
+
label: "Empty list",
|
|
249
|
+
description: "Set an explicit empty list",
|
|
250
|
+
group: "Actions",
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
value: "action:unset",
|
|
254
|
+
label: "Unset (use default policy)",
|
|
255
|
+
description: "Remove the explicit list",
|
|
256
|
+
group: "Actions",
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
value: "action:cancel",
|
|
260
|
+
label: "Cancel",
|
|
261
|
+
description: "Discard tool list changes",
|
|
262
|
+
group: "Actions",
|
|
263
|
+
},
|
|
264
|
+
];
|
|
265
|
+
const list = new SelectList(this.currentItems, Math.min(this.currentItems.length, 10), getSelectListTheme(), LAYOUT);
|
|
266
|
+
const preferred = focusResult
|
|
267
|
+
? this.currentItems.findIndex((row) => row.group === "Session tools · A–Z")
|
|
268
|
+
: this.currentItems.findIndex((row) => row.value === selectedValue);
|
|
269
|
+
list.setSelectedIndex(preferred >= 0
|
|
270
|
+
? preferred
|
|
271
|
+
: focusResult
|
|
272
|
+
? 0
|
|
273
|
+
: Math.max(0, Math.min(previousIndex, this.currentItems.length - 1)));
|
|
274
|
+
list.onSelect = (item) => {
|
|
275
|
+
if (item.value === "action:done")
|
|
276
|
+
this.finish();
|
|
277
|
+
else if (item.value === "action:cancel")
|
|
278
|
+
this.options.onCancel();
|
|
279
|
+
else {
|
|
280
|
+
if (item.value.startsWith("group:")) {
|
|
281
|
+
const key = item.value.slice("group:".length);
|
|
282
|
+
const names = [
|
|
283
|
+
...new Set([...this.tools.map((t) => t.name), ...(this.draft ?? [])]),
|
|
284
|
+
].filter((n) => mcpServerOf(n) !== undefined && `mcp__${mcpServerOf(n)}` === key);
|
|
285
|
+
const allOn = names.every((n) => this.draft?.includes(n));
|
|
286
|
+
const rest = (this.draft ?? []).filter((n) => !names.includes(n));
|
|
287
|
+
this.draft = allOn ? rest : [...rest, ...names];
|
|
288
|
+
}
|
|
289
|
+
else if (item.value === "action:unset")
|
|
290
|
+
this.draft = undefined;
|
|
291
|
+
else if (item.value === "action:empty")
|
|
292
|
+
this.draft = [];
|
|
293
|
+
else {
|
|
294
|
+
const name = item.value.slice("tool:".length);
|
|
295
|
+
this.draft ??= [];
|
|
296
|
+
const index = this.draft.indexOf(name);
|
|
297
|
+
if (index >= 0)
|
|
298
|
+
this.draft.splice(index, 1);
|
|
299
|
+
else
|
|
300
|
+
this.draft.push(name);
|
|
301
|
+
}
|
|
302
|
+
this.refresh(item.value);
|
|
303
|
+
this.options.tui.requestRender();
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
list.onCancel = () => this.options.onCancel();
|
|
307
|
+
list.onSelectionChange = () => this.options.tui.requestRender();
|
|
308
|
+
this.selectList = list;
|
|
309
|
+
if (this.children[1])
|
|
310
|
+
this.children[1] = list;
|
|
311
|
+
else
|
|
312
|
+
this.addChild(list);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
export async function editToolSelection(ctx, field, current, options) {
|
|
316
|
+
if (ctx.mode !== "tui") {
|
|
317
|
+
if (ctx.hasUI)
|
|
318
|
+
ctx.ui.notify("Tool selection requires interactive TUI mode; draft unchanged.", "warning");
|
|
319
|
+
return TOOL_EDITOR_CANCEL;
|
|
320
|
+
}
|
|
321
|
+
return ctx.ui.custom((tui, theme, _keys, done) => new ToolPickerComponent({
|
|
322
|
+
tui,
|
|
323
|
+
theme,
|
|
324
|
+
tools: options.getAllTools(),
|
|
325
|
+
field,
|
|
326
|
+
toolFiltering: options.toolFiltering,
|
|
327
|
+
initialTools: current,
|
|
328
|
+
onDone: (tools) => done(tools),
|
|
329
|
+
onCancel: () => done(TOOL_EDITOR_CANCEL),
|
|
330
|
+
}), DIALOG_OPTIONS);
|
|
331
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ToolExecutionComponent, createBashToolDefinition, createPowerShellToolDefinition, createReadToolDefinition, createEditToolDefinition, createWriteToolDefinition, createGrepToolDefinition, createFindToolDefinition, createLsToolDefinition, } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Text, stripTerminalSequences } from "@earendil-works/pi-tui";
|
|
3
|
+
const renderers = new Map([
|
|
4
|
+
createBashToolDefinition(process.cwd()),
|
|
5
|
+
createPowerShellToolDefinition(process.cwd()),
|
|
6
|
+
createReadToolDefinition(process.cwd()),
|
|
7
|
+
createEditToolDefinition(process.cwd()),
|
|
8
|
+
createWriteToolDefinition(process.cwd()),
|
|
9
|
+
createGrepToolDefinition(process.cwd()),
|
|
10
|
+
createFindToolDefinition(process.cwd()),
|
|
11
|
+
createLsToolDefinition(process.cwd()),
|
|
12
|
+
].map((tool) => [
|
|
13
|
+
tool.name,
|
|
14
|
+
{ renderCall: tool.renderCall, renderResult: tool.renderResult },
|
|
15
|
+
]));
|
|
16
|
+
const edit = renderers.get("edit");
|
|
17
|
+
const editCall = edit.renderCall;
|
|
18
|
+
edit.renderCall = (args, theme, context) => editCall(args, theme, { ...context, argsComplete: false });
|
|
19
|
+
const generic = {
|
|
20
|
+
renderResult(result, options, theme) {
|
|
21
|
+
const output = result.content
|
|
22
|
+
.filter((block) => block.type === "text")
|
|
23
|
+
.map((block) => block.text)
|
|
24
|
+
.join("\n");
|
|
25
|
+
const bounded = options.expanded ? output : output.slice(0, 32768);
|
|
26
|
+
const component = new Text(theme.fg("toolOutput", bounded), 0, 0);
|
|
27
|
+
return {
|
|
28
|
+
invalidate() {
|
|
29
|
+
component.invalidate();
|
|
30
|
+
},
|
|
31
|
+
render(width) {
|
|
32
|
+
const rows = component.render(width);
|
|
33
|
+
if (options.expanded || (rows.length <= 5 && bounded.length === output.length))
|
|
34
|
+
return rows;
|
|
35
|
+
return [...rows.slice(0, 5), theme.fg("muted", "… more lines (Ctrl+O to expand)")];
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
function safeText(value) {
|
|
41
|
+
return stripTerminalSequences(value)
|
|
42
|
+
.replace(/\r\n?/g, "\n")
|
|
43
|
+
.replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
|
|
44
|
+
}
|
|
45
|
+
function sanitize(value, seen = new WeakSet(), depth = 0) {
|
|
46
|
+
if (typeof value === "string")
|
|
47
|
+
return safeText(value);
|
|
48
|
+
if (!value || typeof value !== "object")
|
|
49
|
+
return typeof value === "bigint" ? String(value) : value;
|
|
50
|
+
if (seen.has(value))
|
|
51
|
+
return "[Circular]";
|
|
52
|
+
if (depth > 64)
|
|
53
|
+
return "[Nested data omitted]";
|
|
54
|
+
seen.add(value);
|
|
55
|
+
const safe = Array.isArray(value)
|
|
56
|
+
? value.map((item) => sanitize(item, seen, depth + 1))
|
|
57
|
+
: Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
58
|
+
safeText(key),
|
|
59
|
+
sanitize(item, seen, depth + 1),
|
|
60
|
+
]));
|
|
61
|
+
seen.delete(value);
|
|
62
|
+
return safe;
|
|
63
|
+
}
|
|
64
|
+
export function renderTranscriptTool(name, id, args, result, isError, running, detail, width) {
|
|
65
|
+
const ui = { requestRender() { } };
|
|
66
|
+
const component = new ToolExecutionComponent(safeText(name), safeText(id), sanitize(args), { showImages: false }, renderers.get(name) ?? generic, ui, process.cwd());
|
|
67
|
+
const data = result && typeof result === "object" ? result : undefined;
|
|
68
|
+
const content = data?.content ?? result;
|
|
69
|
+
component.updateResult({
|
|
70
|
+
content: (Array.isArray(content) ? content : content === undefined ? [] : [content]).map((block) => {
|
|
71
|
+
if (block && typeof block === "object" && block.type === "image")
|
|
72
|
+
return { type: "text", text: "[Image — text-only observer]" };
|
|
73
|
+
if (block && typeof block === "object" && block.type === "text")
|
|
74
|
+
return {
|
|
75
|
+
type: "text",
|
|
76
|
+
text: safeText(String(block.text ?? "")),
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
type: "text",
|
|
80
|
+
text: safeText(typeof block === "string" ? block : (JSON.stringify(sanitize(block)) ?? "")),
|
|
81
|
+
};
|
|
82
|
+
}),
|
|
83
|
+
details: sanitize(data?.details),
|
|
84
|
+
isError: isError || data?.isError === true,
|
|
85
|
+
}, running);
|
|
86
|
+
component.setExpanded(detail === "full");
|
|
87
|
+
const lines = component.render(Math.max(3, width));
|
|
88
|
+
if (detail === "compact")
|
|
89
|
+
return lines.filter((line) => stripTerminalSequences(line).trim()).slice(0, 1);
|
|
90
|
+
return lines;
|
|
91
|
+
}
|