pi-subagent-manager 0.15.0 → 0.16.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 +2 -1
- package/docs/tools-and-ui.md +2 -1
- package/package.json +1 -1
- package/src/index.ts +33 -6
- package/src/orch/manager.ts +44 -0
- package/src/ui/agent-loader.ts +2 -2
- package/src/ui/settings-ui.ts +7 -1
- package/src/ui/tool-picker.ts +308 -0
- package/src/ui/ui.ts +12 -37
package/README.md
CHANGED
|
@@ -68,9 +68,10 @@ They inherit your current model until you set preferences. Details: [docs/defaul
|
|
|
68
68
|
| ---------------- | ------------------------------------------------------ |
|
|
69
69
|
| `/agents` | Settings (mode, limits, model picking, tool filtering) |
|
|
70
70
|
| `/agents types` | Agent-type browser and editor |
|
|
71
|
-
| `/agents tree` | Fullscreen tree and live viewer with manual steering
|
|
71
|
+
| `/agents tree` | Fullscreen tree and live viewer with manual steering |
|
|
72
72
|
| `/agents import` | Import agents from other subagent extensions |
|
|
73
73
|
| `/agents reload` | Reload definitions and settings |
|
|
74
|
+
| `/agents reap` | Confirm the eligible count, then forget completed agents and free retained-thread slots (cannot be resumed); preserves active parents and ancestors of retained threads. Session files remain on disk. |
|
|
74
75
|
|
|
75
76
|
A live **Agents** widget sits above the input box. Choose **Full** (the existing tree) or **Minimal** (colored status counts and running-agent token totals, plus the browser hint) under **Status Widget** in `/agents` settings. In the fullscreen tree, **Enter** opens an agent's live view. Type in the bottom **Steer** input and press **Enter** to send it a steering message, including nested agents. **Tab** switches between input and transcript controls, **Escape** returns, and **i** in the tree opens existing thread actions. A status strip below the previews shows how many agents are running and **Press ← to open subagent browser**. Once the main turn ends and all subagents are idle, the preview collapses to a single status-count line. A fresh prompt hides previously settled agents from the widget; they reappear only when resumed, and `/agents tree` always keeps them available. While subagents are starting or running, press **Left** at the start of the main draft to open it; otherwise Left stays native. Press **Right** at the end of the draft (or in an empty input) to collapse the widget to one line for this session only, without changing saved settings. `/agents tree` remains available regardless of agent activity. See [live navigation](docs/tools-and-ui.md#live-agent-navigation) for controls and compatibility.
|
|
76
77
|
|
package/docs/tools-and-ui.md
CHANGED
|
@@ -45,9 +45,10 @@ Child progress and completion notifications are retained in the main agent's con
|
|
|
45
45
|
| ----------------------------- | ---------------------------------------------------------------------------------- |
|
|
46
46
|
| `/agents`, `/agents settings` | [Settings](settings.md) dialog. **Agent definitions** jumps to the type editor. |
|
|
47
47
|
| `/agents types` | Type browser and editor — see [custom agents](custom-agents.md#editing-in-the-tui) |
|
|
48
|
-
| `/agents tree [path]` | Live full tree; optional path preselects.
|
|
48
|
+
| `/agents tree [path]` | Live full tree; optional path preselects. |
|
|
49
49
|
| `/agents import` | [Import picker](importing-agents.md) |
|
|
50
50
|
| `/agents reload` | Reload definitions and settings; show diagnostics |
|
|
51
|
+
| `/agents reap` | Show the eligible count and a Confirm/Cancel dialog, then forget completed agents and free retained-thread slots. Active parents and ancestors of retained threads are preserved; reaped agents cannot be resumed. Session files are not deleted. |
|
|
51
52
|
|
|
52
53
|
### `/agents tree` keys
|
|
53
54
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,13 +7,14 @@ import { IMPORT_REQUEST_PREFIX, markImportOffered, offerAgentImport } from "./pr
|
|
|
7
7
|
import { ThreadManager } from "./orch/manager.ts";
|
|
8
8
|
import { loadManagerSettings } from "./prefs/settings.ts";
|
|
9
9
|
import { configureAgents } from "./ui/settings-ui.ts";
|
|
10
|
-
import { AgentNavigationController
|
|
10
|
+
import { AgentNavigationController } from "./ui/status-ui.ts";
|
|
11
11
|
import { AgentNavigationEditor } from "./ui/agent-navigation-editor.ts";
|
|
12
12
|
import { createDriverFactory } from "./orch/runtime.ts";
|
|
13
13
|
import { createInheritedToolSource } from "./orch/inherited-tools.ts";
|
|
14
14
|
import { subagentPrompt } from "./orch/prompt.ts";
|
|
15
15
|
import { agentTools } from "./orch/tools.ts";
|
|
16
16
|
import { editAgentTypes, updateWidget } from "./ui/ui.ts";
|
|
17
|
+
import { canOpenDialog, dialogMenu } from "./ui/dialog.ts";
|
|
17
18
|
import type { SavedThread, ThreadEvent } from "./types.ts";
|
|
18
19
|
|
|
19
20
|
const REGISTRY_ENTRY = "pi-subagent:registry:v1";
|
|
@@ -477,7 +478,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
477
478
|
manager = undefined;
|
|
478
479
|
context = undefined;
|
|
479
480
|
});
|
|
480
|
-
const agentSubcommands = ["tree", "
|
|
481
|
+
const agentSubcommands = ["tree", "settings", "types", "import", "reload", "reap"] as const;
|
|
481
482
|
pi.registerCommand("agents", {
|
|
482
483
|
description: "Configure agent settings, import/edit definitions, or show the live tree",
|
|
483
484
|
getArgumentCompletions: (argumentText) => {
|
|
@@ -504,7 +505,10 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
504
505
|
if (command === "import") {
|
|
505
506
|
await importAgents(ctx, false);
|
|
506
507
|
} else if (command === "types") {
|
|
507
|
-
await editAgentTypes(ctx, store, limits.nerdFontIcons
|
|
508
|
+
await editAgentTypes(ctx, store, limits.nerdFontIcons, {
|
|
509
|
+
getAllTools: () => pi.getAllTools(),
|
|
510
|
+
toolFiltering: limits.toolFiltering,
|
|
511
|
+
});
|
|
508
512
|
store.reload();
|
|
509
513
|
} else if (command === "reload") {
|
|
510
514
|
store.reload();
|
|
@@ -524,6 +528,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
524
528
|
store,
|
|
525
529
|
settings: limits,
|
|
526
530
|
agentDir: getAgentDir(),
|
|
531
|
+
getAllTools: () => pi.getAllTools(),
|
|
527
532
|
apply: () => {
|
|
528
533
|
const diagnostics = loadLimits(ctx);
|
|
529
534
|
requireManager().setLimits(limits);
|
|
@@ -533,13 +538,35 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
533
538
|
if (diagnostics.length) ctx.ui.notify(diagnostics.join("\n"), "warning");
|
|
534
539
|
},
|
|
535
540
|
});
|
|
536
|
-
} else if (command === "
|
|
537
|
-
|
|
541
|
+
} else if (command === "reap") {
|
|
542
|
+
const current = requireManager();
|
|
543
|
+
const candidates = current.reapCandidates();
|
|
544
|
+
if (!candidates.length) {
|
|
545
|
+
ctx.ui.notify("No completed agents eligible for reaping.", "info");
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (!canOpenDialog(ctx)) return;
|
|
549
|
+
closeNavigation();
|
|
550
|
+
const warning = `${candidates.length} completed agent${candidates.length === 1 ? "" : "s"} will be reaped.\nYou will not be able to resume them anymore.`;
|
|
551
|
+
const choice = await dialogMenu(ctx, "Reap completed agents?", [
|
|
552
|
+
{ id: "confirm", label: "Confirm", help: warning },
|
|
553
|
+
{ id: "cancel", label: "Cancel", help: warning },
|
|
554
|
+
], { selectedId: "cancel" });
|
|
555
|
+
if (choice !== "confirm" || manager !== current) return;
|
|
556
|
+
const reaped = current.reap(candidates);
|
|
557
|
+
persist();
|
|
558
|
+
refreshWidget(ctx);
|
|
559
|
+
ctx.ui.notify(
|
|
560
|
+
reaped.length
|
|
561
|
+
? `Reaped ${reaped.length} completed agent(s); their sessions can no longer be resumed.`
|
|
562
|
+
: "No completed agents eligible for reaping.",
|
|
563
|
+
"info",
|
|
564
|
+
);
|
|
538
565
|
} else if (command === "tree") {
|
|
539
566
|
await navigation.open(ctx, requireManager().scope("/root"), rest.join(" ") || undefined, limits.nerdFontIcons, limits.loaderStyle);
|
|
540
567
|
} else
|
|
541
568
|
ctx.ui.notify(
|
|
542
|
-
"Usage: /agents [tree [path] |
|
|
569
|
+
"Usage: /agents [tree [path] | settings | types | import | reload | reap]",
|
|
543
570
|
"warning",
|
|
544
571
|
);
|
|
545
572
|
},
|
package/src/orch/manager.ts
CHANGED
|
@@ -84,6 +84,50 @@ export class ThreadManager {
|
|
|
84
84
|
return [...this.records.values()].map((record) => this.view(record));
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/** Preview eligible completed sessions without changing retained records. */
|
|
88
|
+
reapCandidates(only?: readonly string[]): string[] {
|
|
89
|
+
this.assertLive();
|
|
90
|
+
const records = [...this.records.values()];
|
|
91
|
+
const eligible = new Set(
|
|
92
|
+
records
|
|
93
|
+
.filter((record) => !only || only.includes(record.view.path))
|
|
94
|
+
.filter((record) => record.view.state === "completed" && (!record.initializing || record.driver))
|
|
95
|
+
.filter((record) =>
|
|
96
|
+
!records.some(
|
|
97
|
+
(other) => active(other.view) && isDescendant(record.view.path, other.view.path),
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
.map((record) => record.view.path),
|
|
101
|
+
);
|
|
102
|
+
// Any retained descendant still needs its lexical ancestors.
|
|
103
|
+
for (const record of records) {
|
|
104
|
+
if (eligible.has(record.view.path)) continue;
|
|
105
|
+
let parent = record.view.parent;
|
|
106
|
+
while (parent && parent !== "/root") {
|
|
107
|
+
eligible.delete(parent);
|
|
108
|
+
parent = this.records.get(parent)?.view.parent ?? null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return records
|
|
112
|
+
.filter((record) => eligible.has(record.view.path))
|
|
113
|
+
.sort((a, b) => a.view.createdAt - b.view.createdAt)
|
|
114
|
+
.map((record) => record.view.path);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Revalidate an optional confirmed snapshot before forgetting sessions. */
|
|
118
|
+
reap(only?: readonly string[]): string[] {
|
|
119
|
+
const reaped: string[] = [];
|
|
120
|
+
for (const path of this.reapCandidates(only)) {
|
|
121
|
+
const record = this.records.get(path)!;
|
|
122
|
+
record.detachTranscript?.();
|
|
123
|
+
record.transcriptListeners?.clear();
|
|
124
|
+
record.driver?.dispose();
|
|
125
|
+
this.records.delete(record.view.path);
|
|
126
|
+
reaped.push(record.view.path);
|
|
127
|
+
}
|
|
128
|
+
return reaped;
|
|
129
|
+
}
|
|
130
|
+
|
|
87
131
|
/** Bind authority once; models and the user UI share this small composable service. */
|
|
88
132
|
scope(caller: string): ThreadService {
|
|
89
133
|
caller = canonicalPath(caller);
|
package/src/ui/agent-loader.ts
CHANGED
|
@@ -32,9 +32,9 @@ export const AGENT_LOADERS: Record<
|
|
|
32
32
|
},
|
|
33
33
|
hourglass: {
|
|
34
34
|
label: "Hourglass",
|
|
35
|
-
// Nerd Fonts fa-hourglass-start/half/end, pause, times-circle, stop.
|
|
35
|
+
// Nerd Fonts fa-hourglass-start/half/end, check-square, pause, times-circle, stop.
|
|
36
36
|
frames: ["\uf251", "\uf252", "\uf253"],
|
|
37
|
-
states: { completed: "\
|
|
37
|
+
states: { completed: "\uf14a", paused: "\uf04c", failed: "\uf057", stopped: "\uf04d" },
|
|
38
38
|
},
|
|
39
39
|
};
|
|
40
40
|
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
type WidgetMode,
|
|
21
21
|
} from "../prefs/settings.ts";
|
|
22
22
|
import { editAgentTypes } from "./ui.ts";
|
|
23
|
+
import type { ToolEditorOptions } from "./tool-picker.ts";
|
|
23
24
|
import { AGENT_LOADERS } from "./agent-loader.ts";
|
|
24
25
|
|
|
25
26
|
const LOADER_OPTIONS = LOADER_STYLES.map((id) => {
|
|
@@ -146,6 +147,7 @@ export async function configureAgents(
|
|
|
146
147
|
store: ConfigStore;
|
|
147
148
|
settings: ManagerSettings;
|
|
148
149
|
agentDir: string;
|
|
150
|
+
getAllTools?: ToolEditorOptions["getAllTools"];
|
|
149
151
|
apply(): void;
|
|
150
152
|
},
|
|
151
153
|
): Promise<void> {
|
|
@@ -161,6 +163,7 @@ async function configureAgentsDialog(
|
|
|
161
163
|
store: ConfigStore;
|
|
162
164
|
settings: ManagerSettings;
|
|
163
165
|
agentDir: string;
|
|
166
|
+
getAllTools?: ToolEditorOptions["getAllTools"];
|
|
164
167
|
apply(): void;
|
|
165
168
|
},
|
|
166
169
|
): Promise<void> {
|
|
@@ -325,7 +328,10 @@ async function configureAgentsDialog(
|
|
|
325
328
|
}
|
|
326
329
|
} else if (action === "defaults") draft = { ...DEFAULT_MANAGER_SETTINGS };
|
|
327
330
|
else if (action === "types") {
|
|
328
|
-
await editAgentTypes(ctx, options.store, draft.nerdFontIcons
|
|
331
|
+
await editAgentTypes(ctx, options.store, draft.nerdFontIcons, {
|
|
332
|
+
getAllTools: options.getAllTools ?? (() => []),
|
|
333
|
+
toolFiltering: draft.toolFiltering,
|
|
334
|
+
});
|
|
329
335
|
options.store.reload();
|
|
330
336
|
} else if (action === "save") {
|
|
331
337
|
const file = saveManagerSettings({
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import fuzzysort from "fuzzysort";
|
|
2
|
+
import {
|
|
3
|
+
getSelectListTheme,
|
|
4
|
+
type ExtensionAPI,
|
|
5
|
+
type ExtensionCommandContext,
|
|
6
|
+
type Theme,
|
|
7
|
+
} from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import {
|
|
9
|
+
Container,
|
|
10
|
+
getKeybindings,
|
|
11
|
+
Input,
|
|
12
|
+
Key,
|
|
13
|
+
matchesKey,
|
|
14
|
+
SelectList,
|
|
15
|
+
wrapTextWithAnsi,
|
|
16
|
+
type SelectItem,
|
|
17
|
+
} from "@earendil-works/pi-tui";
|
|
18
|
+
import type { ToolFilteringMode } from "../prefs/settings.ts";
|
|
19
|
+
import {
|
|
20
|
+
dialogHeight,
|
|
21
|
+
dialogText,
|
|
22
|
+
frameDialog,
|
|
23
|
+
DIALOG_OPTIONS,
|
|
24
|
+
type DialogHost,
|
|
25
|
+
} from "./dialog.ts";
|
|
26
|
+
|
|
27
|
+
export type SessionTool = Pick<
|
|
28
|
+
ReturnType<ExtensionAPI["getAllTools"]>[number],
|
|
29
|
+
"name" | "description"
|
|
30
|
+
>;
|
|
31
|
+
export interface ToolEditorOptions {
|
|
32
|
+
getAllTools(): readonly SessionTool[];
|
|
33
|
+
toolFiltering: ToolFilteringMode;
|
|
34
|
+
}
|
|
35
|
+
export const TOOL_EDITOR_CANCEL = Symbol("tool-editor-cancel");
|
|
36
|
+
|
|
37
|
+
export function toolPolicyNotice(
|
|
38
|
+
field: "allow" | "block",
|
|
39
|
+
policy: ToolFilteringMode,
|
|
40
|
+
): string | undefined {
|
|
41
|
+
if (field === "allow" && policy !== "allowed") {
|
|
42
|
+
return "Allow list is not used until Tool Filtering policy is changed to Allowed (except blocked).";
|
|
43
|
+
}
|
|
44
|
+
if (field === "block" && policy === "all") {
|
|
45
|
+
return "Block list is not used until Tool Filtering policy is changed from All.";
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const LAYOUT = { minPrimaryColumnWidth: 24, maxPrimaryColumnWidth: 52 };
|
|
51
|
+
interface ToolItem extends SelectItem {
|
|
52
|
+
group: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class ToolPickerComponent extends Container {
|
|
56
|
+
private readonly searchInput = new Input({ placeholder: "Search tools" });
|
|
57
|
+
private selectList = new SelectList([], 1, getSelectListTheme(), LAYOUT);
|
|
58
|
+
private currentItems: ToolItem[] = [];
|
|
59
|
+
private readonly tools: SessionTool[];
|
|
60
|
+
private readonly byName: Map<string, SessionTool>;
|
|
61
|
+
private draft: string[] | undefined;
|
|
62
|
+
private query = "";
|
|
63
|
+
private _focused = false;
|
|
64
|
+
|
|
65
|
+
constructor(
|
|
66
|
+
private readonly options: {
|
|
67
|
+
tui: DialogHost;
|
|
68
|
+
theme: Theme;
|
|
69
|
+
tools: readonly SessionTool[];
|
|
70
|
+
field: "allow" | "block";
|
|
71
|
+
toolFiltering: ToolFilteringMode;
|
|
72
|
+
initialTools?: readonly string[];
|
|
73
|
+
onDone(tools: string[] | undefined): void;
|
|
74
|
+
onCancel(): void;
|
|
75
|
+
},
|
|
76
|
+
) {
|
|
77
|
+
super();
|
|
78
|
+
this.byName = new Map(options.tools.map((tool) => [tool.name, tool]));
|
|
79
|
+
this.tools = [...this.byName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
80
|
+
this.draft =
|
|
81
|
+
options.initialTools === undefined ? undefined : [...new Set(options.initialTools)];
|
|
82
|
+
this.addChild(this.searchInput);
|
|
83
|
+
this.refresh();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get focused(): boolean {
|
|
87
|
+
return this._focused;
|
|
88
|
+
}
|
|
89
|
+
set focused(value: boolean) {
|
|
90
|
+
this._focused = value;
|
|
91
|
+
this.searchInput.focused = value;
|
|
92
|
+
}
|
|
93
|
+
getDraftTools(): readonly string[] | undefined {
|
|
94
|
+
return this.draft;
|
|
95
|
+
}
|
|
96
|
+
getCurrentItems(): readonly SelectItem[] {
|
|
97
|
+
return this.currentItems;
|
|
98
|
+
}
|
|
99
|
+
getSelectList(): SelectList {
|
|
100
|
+
return this.selectList;
|
|
101
|
+
}
|
|
102
|
+
getSearchInput(): Input {
|
|
103
|
+
return this.searchInput;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
render(width: number): string[] {
|
|
107
|
+
const { tui, theme, field, toolFiltering } = this.options;
|
|
108
|
+
const height = dialogHeight(tui);
|
|
109
|
+
const inner = Math.max(1, width - 4);
|
|
110
|
+
const notice = toolPolicyNotice(field, toolFiltering);
|
|
111
|
+
const header = [
|
|
112
|
+
...(notice ? wrapTextWithAnsi(theme.fg("warning", notice), inner) : []),
|
|
113
|
+
theme.fg(
|
|
114
|
+
"muted",
|
|
115
|
+
this.draft === undefined
|
|
116
|
+
? "Unset (use default policy). Select tools to create a list."
|
|
117
|
+
: `${this.draft.length} selected · selected tools first · type to search`,
|
|
118
|
+
),
|
|
119
|
+
...this.searchInput.render(inner),
|
|
120
|
+
];
|
|
121
|
+
const selected = this.selectList.getSelectedItem()?.value;
|
|
122
|
+
const displayRows: (ToolItem | string)[] = [];
|
|
123
|
+
let previous: string | undefined;
|
|
124
|
+
for (const item of this.currentItems) {
|
|
125
|
+
if (item.group !== previous) {
|
|
126
|
+
if (
|
|
127
|
+
item.group === "Actions" &&
|
|
128
|
+
!this.currentItems.some((row) => row.group === "Session tools · A–Z")
|
|
129
|
+
) {
|
|
130
|
+
displayRows.push(
|
|
131
|
+
this.tools.length
|
|
132
|
+
? "No unselected matching tools"
|
|
133
|
+
: "No tools available in this session",
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
displayRows.push(item.group);
|
|
137
|
+
}
|
|
138
|
+
previous = item.group;
|
|
139
|
+
displayRows.push(item);
|
|
140
|
+
}
|
|
141
|
+
const budget = Math.max(1, height - 4 - header.length);
|
|
142
|
+
const index = Math.max(
|
|
143
|
+
0,
|
|
144
|
+
displayRows.findIndex((row) => typeof row !== "string" && row.value === selected),
|
|
145
|
+
);
|
|
146
|
+
const start = Math.max(0, Math.min(index - budget + 1, displayRows.length - budget));
|
|
147
|
+
const rows = displayRows.slice(start, start + budget).map((row) => {
|
|
148
|
+
if (typeof row === "string") return theme.fg("muted", row);
|
|
149
|
+
const text = `${row.value === selected ? "›" : " "} ${row.label} ${theme.fg("muted", row.description ?? "")}`;
|
|
150
|
+
return row.value === selected ? theme.fg("accent", text) : text;
|
|
151
|
+
});
|
|
152
|
+
return frameDialog(
|
|
153
|
+
theme,
|
|
154
|
+
width,
|
|
155
|
+
height,
|
|
156
|
+
field === "allow" ? "Allowed tools" : "Blocked tools",
|
|
157
|
+
[...header, ...rows].map((line) => ` ${line}`),
|
|
158
|
+
"↑↓ select · Enter toggle/action · Ctrl+S done · Esc cancel",
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
handleInput(data: string): void {
|
|
163
|
+
if (matchesKey(data, Key.ctrl("s"))) {
|
|
164
|
+
this.finish();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const kb = getKeybindings();
|
|
168
|
+
if (
|
|
169
|
+
kb.matches(data, "tui.select.up") ||
|
|
170
|
+
kb.matches(data, "tui.select.down") ||
|
|
171
|
+
kb.matches(data, "tui.select.confirm") ||
|
|
172
|
+
kb.matches(data, "tui.select.cancel")
|
|
173
|
+
) {
|
|
174
|
+
this.selectList.handleInput(data);
|
|
175
|
+
} else {
|
|
176
|
+
this.searchInput.handleInput(data);
|
|
177
|
+
const query = this.searchInput.getValue();
|
|
178
|
+
if (query !== this.query) {
|
|
179
|
+
this.query = query;
|
|
180
|
+
this.refresh(undefined, true);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
this.options.tui.requestRender();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private finish(): void {
|
|
187
|
+
this.options.onDone(this.draft === undefined ? undefined : [...this.draft]);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private refresh(selectedValue?: string, focusResult = false): void {
|
|
191
|
+
const previousIndex = this.currentItems.findIndex(
|
|
192
|
+
(row) => row.value === this.selectList.getSelectedItem()?.value,
|
|
193
|
+
);
|
|
194
|
+
const selected = new Set(this.draft ?? []);
|
|
195
|
+
const matches = this.query.trim()
|
|
196
|
+
? fuzzysort
|
|
197
|
+
.go(this.query.trim(), this.tools, {
|
|
198
|
+
keys: ["name", "description"],
|
|
199
|
+
limit: 0,
|
|
200
|
+
threshold: 0,
|
|
201
|
+
})
|
|
202
|
+
.map((result) => result.obj)
|
|
203
|
+
: this.tools;
|
|
204
|
+
const toolItem = (name: string, checked: boolean): ToolItem => ({
|
|
205
|
+
value: `tool:${name}`,
|
|
206
|
+
label: `[${checked ? "x" : " "}] ${dialogText(name)}`,
|
|
207
|
+
description: this.byName.has(name)
|
|
208
|
+
? dialogText(this.byName.get(name)!.description)
|
|
209
|
+
: "unavailable in current session · preserved",
|
|
210
|
+
group: checked ? "Selected tools" : "Session tools · A–Z",
|
|
211
|
+
});
|
|
212
|
+
this.currentItems = [
|
|
213
|
+
...[...selected].map((name) => toolItem(name, true)),
|
|
214
|
+
...matches
|
|
215
|
+
.filter((tool) => !selected.has(tool.name))
|
|
216
|
+
.map((tool) => toolItem(tool.name, false)),
|
|
217
|
+
{
|
|
218
|
+
value: "action:done",
|
|
219
|
+
label: "Done",
|
|
220
|
+
description: "Apply this list to the agent draft",
|
|
221
|
+
group: "Actions",
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
value: "action:empty",
|
|
225
|
+
label: "Empty list",
|
|
226
|
+
description: "Set an explicit empty list",
|
|
227
|
+
group: "Actions",
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
value: "action:unset",
|
|
231
|
+
label: "Unset (use default policy)",
|
|
232
|
+
description: "Remove the explicit list",
|
|
233
|
+
group: "Actions",
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
value: "action:cancel",
|
|
237
|
+
label: "Cancel",
|
|
238
|
+
description: "Discard tool list changes",
|
|
239
|
+
group: "Actions",
|
|
240
|
+
},
|
|
241
|
+
];
|
|
242
|
+
const list = new SelectList(
|
|
243
|
+
this.currentItems,
|
|
244
|
+
Math.min(this.currentItems.length, 10),
|
|
245
|
+
getSelectListTheme(),
|
|
246
|
+
LAYOUT,
|
|
247
|
+
);
|
|
248
|
+
const preferred = focusResult
|
|
249
|
+
? this.currentItems.findIndex((row) => row.group === "Session tools · A–Z")
|
|
250
|
+
: this.currentItems.findIndex((row) => row.value === selectedValue);
|
|
251
|
+
list.setSelectedIndex(
|
|
252
|
+
preferred >= 0
|
|
253
|
+
? preferred
|
|
254
|
+
: focusResult
|
|
255
|
+
? 0
|
|
256
|
+
: Math.max(0, Math.min(previousIndex, this.currentItems.length - 1)),
|
|
257
|
+
);
|
|
258
|
+
list.onSelect = (item) => {
|
|
259
|
+
if (item.value === "action:done") this.finish();
|
|
260
|
+
else if (item.value === "action:cancel") this.options.onCancel();
|
|
261
|
+
else {
|
|
262
|
+
if (item.value === "action:unset") this.draft = undefined;
|
|
263
|
+
else if (item.value === "action:empty") this.draft = [];
|
|
264
|
+
else {
|
|
265
|
+
const name = item.value.slice("tool:".length);
|
|
266
|
+
this.draft ??= [];
|
|
267
|
+
const index = this.draft.indexOf(name);
|
|
268
|
+
if (index >= 0) this.draft.splice(index, 1);
|
|
269
|
+
else this.draft.push(name);
|
|
270
|
+
}
|
|
271
|
+
this.refresh(item.value);
|
|
272
|
+
this.options.tui.requestRender();
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
list.onCancel = () => this.options.onCancel();
|
|
276
|
+
list.onSelectionChange = () => this.options.tui.requestRender();
|
|
277
|
+
this.selectList = list;
|
|
278
|
+
if (this.children[1]) this.children[1] = list;
|
|
279
|
+
else this.addChild(list);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export async function editToolSelection(
|
|
284
|
+
ctx: ExtensionCommandContext,
|
|
285
|
+
field: "allow" | "block",
|
|
286
|
+
current: readonly string[] | undefined,
|
|
287
|
+
options: ToolEditorOptions,
|
|
288
|
+
): Promise<readonly string[] | undefined | typeof TOOL_EDITOR_CANCEL> {
|
|
289
|
+
if (ctx.mode !== "tui") {
|
|
290
|
+
if (ctx.hasUI)
|
|
291
|
+
ctx.ui.notify("Tool selection requires interactive TUI mode; draft unchanged.", "warning");
|
|
292
|
+
return TOOL_EDITOR_CANCEL;
|
|
293
|
+
}
|
|
294
|
+
return ctx.ui.custom<readonly string[] | undefined | typeof TOOL_EDITOR_CANCEL>(
|
|
295
|
+
(tui, theme, _keys, done) =>
|
|
296
|
+
new ToolPickerComponent({
|
|
297
|
+
tui,
|
|
298
|
+
theme,
|
|
299
|
+
tools: options.getAllTools(),
|
|
300
|
+
field,
|
|
301
|
+
toolFiltering: options.toolFiltering,
|
|
302
|
+
initialTools: current,
|
|
303
|
+
onDone: (tools) => done(tools),
|
|
304
|
+
onCancel: () => done(TOOL_EDITOR_CANCEL),
|
|
305
|
+
}),
|
|
306
|
+
DIALOG_OPTIONS,
|
|
307
|
+
);
|
|
308
|
+
}
|
package/src/ui/ui.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
serializeAgentType,
|
|
30
30
|
} from "../prefs/config.ts";
|
|
31
31
|
import { editModelPreferences, MODEL_EDITOR_CANCEL } from "./model-picker.ts";
|
|
32
|
+
import { editToolSelection, TOOL_EDITOR_CANCEL, type ToolEditorOptions } from "./tool-picker.ts";
|
|
32
33
|
import {
|
|
33
34
|
canOpenDialog,
|
|
34
35
|
dialogEditor,
|
|
@@ -647,44 +648,15 @@ async function editToolList(
|
|
|
647
648
|
ctx: ExtensionCommandContext,
|
|
648
649
|
type: AgentType,
|
|
649
650
|
field: "allow" | "block",
|
|
651
|
+
options: ToolEditorOptions,
|
|
650
652
|
): Promise<void> {
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
"Enter exact tool names",
|
|
655
|
-
];
|
|
656
|
-
const current = type.tools?.[field];
|
|
657
|
-
const mode = await dialogMenu(
|
|
658
|
-
ctx,
|
|
659
|
-
`tools.${field} (${sanitizeText(toolListMenuValue(current))})`,
|
|
660
|
-
modes.map((label) => ({ id: label, label })),
|
|
661
|
-
{
|
|
662
|
-
selectedId:
|
|
663
|
-
current === undefined
|
|
664
|
-
? modes[0]
|
|
665
|
-
: current.length === 0
|
|
666
|
-
? modes[1]
|
|
667
|
-
: modes[2],
|
|
668
|
-
},
|
|
669
|
-
);
|
|
670
|
-
if (!mode) return;
|
|
671
|
-
if (mode === "Unset (use default policy)") {
|
|
653
|
+
const value = await editToolSelection(ctx, field, type.tools?.[field], options);
|
|
654
|
+
if (value === TOOL_EDITOR_CANCEL) return;
|
|
655
|
+
if (value === undefined) {
|
|
672
656
|
if (type.tools) delete type.tools[field];
|
|
673
657
|
} else {
|
|
674
|
-
const value =
|
|
675
|
-
mode === "Empty list"
|
|
676
|
-
? ""
|
|
677
|
-
: await dialogEditor(
|
|
678
|
-
ctx,
|
|
679
|
-
`tools.${field}: comma-separated exact names`,
|
|
680
|
-
type.tools?.[field]?.join(", ") ?? "",
|
|
681
|
-
);
|
|
682
|
-
if (value === undefined) return;
|
|
683
658
|
type.tools ??= {};
|
|
684
|
-
type.tools[field] = value
|
|
685
|
-
.split(",")
|
|
686
|
-
.map((name) => name.trim())
|
|
687
|
-
.filter(Boolean);
|
|
659
|
+
type.tools[field] = [...value];
|
|
688
660
|
}
|
|
689
661
|
if (type.tools && !Object.keys(type.tools).length) delete type.tools;
|
|
690
662
|
}
|
|
@@ -996,8 +968,8 @@ const EDIT_FIELD_HELP: Record<EditMenuAction, string> = {
|
|
|
996
968
|
"Advisory display names to help pick a model. Not provider/model pins; never selected or required. One name per line; empty clears.",
|
|
997
969
|
thinkingLevel: "Reasoning effort. Default follows the parent session.",
|
|
998
970
|
"tools.allow":
|
|
999
|
-
"
|
|
1000
|
-
"tools.block": "
|
|
971
|
+
"Pick session tools with checkboxes. Under Allowed (except blocked), an unset or empty allow list allows no tools.",
|
|
972
|
+
"tools.block": "Pick session tools to block. Blocked tools take precedence when the policy uses this list.",
|
|
1001
973
|
color: "Thread widget color with live preview.",
|
|
1002
974
|
icon: "Paste a single Nerd Font glyph from nerdfonts.com/cheat-sheet (not its name or codepoint).\nLeave blank to remove. Display requires [labs] Nerd Font icons in settings and a Nerd Font in your terminal.",
|
|
1003
975
|
systemPrompt: "Edit the Markdown prompt body in a multiline dialog.",
|
|
@@ -1123,15 +1095,17 @@ export async function editAgentTypes(
|
|
|
1123
1095
|
ctx: ExtensionCommandContext,
|
|
1124
1096
|
store: ConfigStore,
|
|
1125
1097
|
nerdFontIcons = false,
|
|
1098
|
+
toolEditor: ToolEditorOptions = { getAllTools: () => [], toolFiltering: "allowed" },
|
|
1126
1099
|
): Promise<void> {
|
|
1127
1100
|
if (!canOpenDialog(ctx)) return;
|
|
1128
|
-
await withDialogSession(ctx, (scoped) => editAgentTypesDialog(scoped, store, nerdFontIcons));
|
|
1101
|
+
await withDialogSession(ctx, (scoped) => editAgentTypesDialog(scoped, store, nerdFontIcons, toolEditor));
|
|
1129
1102
|
}
|
|
1130
1103
|
|
|
1131
1104
|
async function editAgentTypesDialog(
|
|
1132
1105
|
ctx: ExtensionCommandContext,
|
|
1133
1106
|
store: ConfigStore,
|
|
1134
1107
|
nerdFontIcons: boolean,
|
|
1108
|
+
toolEditor: ToolEditorOptions,
|
|
1135
1109
|
): Promise<void> {
|
|
1136
1110
|
while (true) {
|
|
1137
1111
|
const types = store.list();
|
|
@@ -1437,6 +1411,7 @@ async function editAgentTypesDialog(
|
|
|
1437
1411
|
ctx,
|
|
1438
1412
|
candidate,
|
|
1439
1413
|
field === "tools.allow" ? "allow" : "block",
|
|
1414
|
+
toolEditor,
|
|
1440
1415
|
);
|
|
1441
1416
|
}
|
|
1442
1417
|
parseAgentType(serializeAgentType(candidate));
|