@ferris1225/pi-subagents 6.0.4 → 7.0.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/CHANGELOG.md +65 -0
- package/README.md +226 -257
- package/index.ts +19 -6
- package/package.json +11 -10
- package/src/configuration/config.ts +63 -159
- package/src/configuration/models.ts +11 -48
- package/src/configuration/setup.ts +69 -195
- package/src/configuration/ui.ts +70 -195
- package/src/delegation/agents.ts +5 -5
- package/src/delegation/builtin-agents.ts +7 -26
- package/src/delegation/dispatch.ts +44 -76
- package/src/delegation/orchestration.ts +22 -0
- package/src/delegation/prompt.ts +30 -45
- package/src/execution/background.ts +2 -2
- package/src/execution/run-control.ts +3 -5
- package/src/execution/spawn.ts +36 -188
- package/src/isolation/worktree.ts +0 -14
- package/src/lifecycle/completion.ts +11 -34
- package/src/lifecycle/dispatch-core.ts +7 -7
- package/src/lifecycle/durable.ts +7 -18
- package/src/lifecycle/runtime.ts +4 -7
- package/src/lifecycle/stop.ts +1 -2
- package/src/lifecycle/thread-lifecycle.ts +42 -59
- package/src/lifecycle/thread-restore.ts +1 -0
- package/src/lifecycle/thread-shared.ts +17 -34
- package/src/lifecycle/tools.ts +13 -18
- package/src/presentation/announcements.ts +17 -17
- package/src/presentation/format.ts +44 -20
- package/src/presentation/monitor.ts +11 -41
- package/src/presentation/widget.ts +4 -14
- package/src/configuration/role-migration.ts +0 -39
|
@@ -1,219 +1,93 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** One worker, two settings. Main keeps Pi's model; workers share their own selection. */
|
|
2
2
|
|
|
3
|
-
import { stat } from "node:fs/promises";
|
|
4
3
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
5
4
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
agentProfile,
|
|
9
|
-
errorMessage,
|
|
10
|
-
getConfigPath,
|
|
11
|
-
loadConfig,
|
|
12
|
-
roleThinkingLevel,
|
|
13
|
-
saveConfig,
|
|
14
|
-
type SubagentsConfig,
|
|
15
|
-
type ThinkingLevel,
|
|
5
|
+
DEFAULT_CONFIG, DEFAULT_THINKING_LEVEL, errorMessage, getConfigPath,
|
|
6
|
+
initializeConfig, loadConfig, saveConfig, type ThinkingLevel,
|
|
16
7
|
} from "./config.ts";
|
|
17
8
|
import {
|
|
18
|
-
CURRENT_MAIN_MODEL,
|
|
19
|
-
|
|
20
|
-
availableModelsInScope,
|
|
21
|
-
buildModelPickerItems,
|
|
22
|
-
currentModelRef,
|
|
23
|
-
findModelByRef,
|
|
24
|
-
resolveThinkingLevel,
|
|
25
|
-
supportedThinkingLevels,
|
|
9
|
+
CURRENT_MAIN_MODEL, availableModelsInScope, buildModelPickerItems, currentModelRef,
|
|
10
|
+
findModelByRef, resolveThinkingLevel, supportedThinkingLevels,
|
|
26
11
|
} from "./models.ts";
|
|
27
|
-
import {
|
|
12
|
+
import { promptSelectOne, promptSettings, type SetupItem } from "./ui.ts";
|
|
28
13
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
minimal: "minimal reasoning",
|
|
33
|
-
low: "light reasoning",
|
|
34
|
-
medium: "balanced reasoning",
|
|
35
|
-
high: "deep reasoning",
|
|
36
|
-
xhigh: "extra-deep reasoning",
|
|
37
|
-
max: "strongest reasoning",
|
|
14
|
+
const THINKING_HINTS: Record<ThinkingLevel, string> = {
|
|
15
|
+
off: "No reasoning tokens", minimal: "Minimal reasoning", low: "Light reasoning",
|
|
16
|
+
medium: "Balanced reasoning", high: "Deep reasoning", xhigh: "Extra-deep reasoning", max: "Strongest reasoning",
|
|
38
17
|
};
|
|
39
18
|
|
|
40
|
-
const ROLE_PURPOSE: Record<string, string> = {
|
|
41
|
-
scout: "Research with citations",
|
|
42
|
-
artisan: "Implement and verify",
|
|
43
|
-
sentinel: "Review and challenge claims",
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
async function configExists(configPath: string): Promise<boolean> {
|
|
47
|
-
try {
|
|
48
|
-
await stat(configPath);
|
|
49
|
-
return true;
|
|
50
|
-
} catch {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function roleModel(ctx: ExtensionContext, config: SubagentsConfig, name: string) {
|
|
56
|
-
return findModelByRef(availableModelsInScope(ctx), config.agentModels[name]) ?? ctx.model;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function roleSettings(ctx: ExtensionContext, config: SubagentsConfig, name: string): SetupItem[] {
|
|
60
|
-
const selected = config.agentModels[name];
|
|
61
|
-
const model = findModelByRef(availableModelsInScope(ctx), selected);
|
|
62
|
-
const modelLabel = selected
|
|
63
|
-
? model ? model.name + " · " + model.provider : selected + " (unavailable)"
|
|
64
|
-
: "Follow main (dynamic)";
|
|
65
|
-
const preferred = config.agentThinkingLevels[name] ?? roleThinkingLevel(name);
|
|
66
|
-
const effective = resolveThinkingLevel(model ?? ctx.model, preferred);
|
|
67
|
-
const source = config.agentThinkingLevels[name] ? "override" : "role default";
|
|
68
|
-
const thinking = effective + (effective !== preferred ? " (" + preferred + " requested)" : "") + " · " + source;
|
|
69
|
-
return [
|
|
70
|
-
{ value: "model", label: "Model: " + modelLabel, description: selected
|
|
71
|
-
? "Pinned reference: " + selected + (model ? ". Falls back to main if it fails." : ". Unavailable; using main.")
|
|
72
|
-
: "Follows the main window's model, including future changes. Now: " + (currentModelRef(ctx) ?? "Pi default") + ". Choose a specific model to pin it." },
|
|
73
|
-
{ value: "thinking", label: "Thinking: " + thinking,
|
|
74
|
-
description: "Reasoning effort: " + thinking + ". Role default: " + roleThinkingLevel(name) + ". Model capabilities limit the effective level; your saved preference is kept when changing models." },
|
|
75
|
-
{ value: "reset", label: "Reset defaults", description: "Restore only " + name + " to Follow main and role-default thinking (" + roleThinkingLevel(name) + "). Saves immediately." },
|
|
76
|
-
];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function roleItems(ctx: ExtensionContext, config: SubagentsConfig): SetupItem[] {
|
|
80
|
-
return BUILTIN_AGENT_NAMES.map((name) => {
|
|
81
|
-
const settings = roleSettings(ctx, config, name);
|
|
82
|
-
return { value: name, label: name + " · " + (ROLE_PURPOSE[name] ?? name),
|
|
83
|
-
description: settings[0]!.label + "\n" + settings[1]!.label + "\n" + agentProfile(name)!.remark };
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** One row per role: every model and thinking choice stays visible together in the standalone modal panel. */
|
|
88
|
-
function roleRows(ctx: ExtensionContext, config: SubagentsConfig): RoleGridRow[] {
|
|
89
|
-
const mainRef = currentModelRef(ctx) ?? "Pi default";
|
|
90
|
-
const models = availableModelsInScope(ctx);
|
|
91
|
-
return BUILTIN_AGENT_NAMES.map((name) => {
|
|
92
|
-
const profile = agentProfile(name)!;
|
|
93
|
-
const selected = config.agentModels[name];
|
|
94
|
-
const model = findModelByRef(models, selected);
|
|
95
|
-
const available = !selected || Boolean(model);
|
|
96
|
-
const modelLabel = selected
|
|
97
|
-
? (model ? model.name + " · " + model.provider + (model.name !== selected ? " (" + selected + ")" : "") : selected + " (unavailable)")
|
|
98
|
-
: "Follow main (dynamic)";
|
|
99
|
-
const preferred = config.agentThinkingLevels[name] ?? roleThinkingLevel(name);
|
|
100
|
-
const effective = resolveThinkingLevel(model ?? ctx.model, preferred);
|
|
101
|
-
const clamped = effective !== preferred ? " (" + preferred + " requested)" : "";
|
|
102
|
-
const overridden = Boolean(config.agentThinkingLevels[name]);
|
|
103
|
-
return {
|
|
104
|
-
role: name,
|
|
105
|
-
purpose: ROLE_PURPOSE[name],
|
|
106
|
-
thinkingOverridden: overridden,
|
|
107
|
-
model: modelLabel,
|
|
108
|
-
thinking: effective + clamped,
|
|
109
|
-
description: profile.remark + " Model: " + (selected
|
|
110
|
-
? "pinned reference " + selected + (available ? "; falls back to main if it fails." : "; unavailable, using main.")
|
|
111
|
-
: "follows main (" + mainRef + ") dynamically.")
|
|
112
|
-
+ " Thinking: role default " + roleThinkingLevel(name) + ", clamped to the model-supported levels. Reset restores " + name + " to Follow main and that default. * marks an override.",
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async function editSetting(
|
|
118
|
-
ctx: ExtensionContext,
|
|
119
|
-
config: SubagentsConfig,
|
|
120
|
-
name: string,
|
|
121
|
-
field: string,
|
|
122
|
-
): Promise<SubagentsConfig | undefined> {
|
|
123
|
-
const next: SubagentsConfig = {
|
|
124
|
-
agentModels: { ...config.agentModels },
|
|
125
|
-
agentThinkingLevels: { ...config.agentThinkingLevels },
|
|
126
|
-
};
|
|
127
|
-
if (field === "reset") {
|
|
128
|
-
delete next.agentModels[name];
|
|
129
|
-
delete next.agentThinkingLevels[name];
|
|
130
|
-
} else if (field === "model") {
|
|
131
|
-
const choice = await promptSelectOne(ctx, name + " · Model",
|
|
132
|
-
"Follow main = dynamic · Others = pinned · Esc back without changes",
|
|
133
|
-
buildModelPickerItems({ models: availableModelsInScope(ctx), configuredRef: config.agentModels[name], mainRef: currentModelRef(ctx) }),
|
|
134
|
-
config.agentModels[name] ?? CURRENT_MAIN_MODEL);
|
|
135
|
-
if (choice === undefined) return undefined;
|
|
136
|
-
next.agentModels = applyAgentModelChoice(next.agentModels, name, choice);
|
|
137
|
-
} else if (field === "thinking") {
|
|
138
|
-
const model = roleModel(ctx, config, name);
|
|
139
|
-
const preferredDefault = roleThinkingLevel(name);
|
|
140
|
-
const effectiveDefault = resolveThinkingLevel(model, preferredDefault);
|
|
141
|
-
const supported = supportedThinkingLevels(model);
|
|
142
|
-
if (!supported.length) {
|
|
143
|
-
ctx.ui.notify("Choose a model before changing thinking; its supported levels are not available yet.", "info");
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
const current = config.agentThinkingLevels[name];
|
|
147
|
-
const options: SetupItem[] = [
|
|
148
|
-
{
|
|
149
|
-
value: ROLE_DEFAULT,
|
|
150
|
-
label: "Role default",
|
|
151
|
-
description: preferredDefault + (effectiveDefault !== preferredDefault ? " → " + effectiveDefault + " on this model" : ""),
|
|
152
|
-
saved: !current,
|
|
153
|
-
},
|
|
154
|
-
...supported.map((level) => ({
|
|
155
|
-
value: level,
|
|
156
|
-
label: level,
|
|
157
|
-
description: THINKING_LEVEL_HINTS[level],
|
|
158
|
-
saved: current === level,
|
|
159
|
-
})),
|
|
160
|
-
];
|
|
161
|
-
if (current && !supported.includes(current)) {
|
|
162
|
-
options.push({
|
|
163
|
-
value: current,
|
|
164
|
-
label: current + " (runs as " + resolveThinkingLevel(model, current) + ")",
|
|
165
|
-
description: "Saved preference; this model clamps it. Keep it for other models, or choose a supported level.",
|
|
166
|
-
saved: true,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
const choice = await promptSelectOne(ctx, name + " · Thinking",
|
|
170
|
-
"Reasoning effort · saved preferences survive model changes · Esc back",
|
|
171
|
-
options, current ?? ROLE_DEFAULT);
|
|
172
|
-
if (choice === undefined) return undefined;
|
|
173
|
-
if (choice === ROLE_DEFAULT) delete next.agentThinkingLevels[name];
|
|
174
|
-
else next.agentThinkingLevels[name] = choice as ThinkingLevel;
|
|
175
|
-
} else {
|
|
176
|
-
return undefined;
|
|
177
|
-
}
|
|
178
|
-
return next;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** Standalone modal panel for first install and later edits. */
|
|
182
19
|
export async function runSetup(ctx: ExtensionContext, configPath: string = getConfigPath()): Promise<void> {
|
|
183
20
|
if (ctx.mode !== "tui") {
|
|
184
21
|
ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
|
|
185
22
|
return;
|
|
186
23
|
}
|
|
187
24
|
try {
|
|
188
|
-
|
|
189
|
-
let focus
|
|
25
|
+
await ensureDefaultConfig(ctx, configPath);
|
|
26
|
+
let focus = "model";
|
|
190
27
|
let status = "Changes save immediately";
|
|
191
28
|
while (true) {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
await
|
|
198
|
-
|
|
199
|
-
|
|
29
|
+
const config = await loadConfig(configPath);
|
|
30
|
+
const models = availableModelsInScope(ctx);
|
|
31
|
+
const selected = findModelByRef(models, config.model);
|
|
32
|
+
const model = selected ?? ctx.model;
|
|
33
|
+
const effective = resolveThinkingLevel(model, config.thinking);
|
|
34
|
+
const choice = await promptSettings(ctx, {
|
|
35
|
+
main: currentModelRef(ctx) ?? "Pi default",
|
|
36
|
+
model: config.model ?? "Follow main",
|
|
37
|
+
thinking: config.model && !selected ? config.thinking : effective + (effective !== config.thinking ? " (" + config.thinking + " requested)" : ""),
|
|
38
|
+
note: config.model && !selected ? "Worker unavailable; dispatch paused. Select an available model." : !config.model ? "Choose a cheaper worker to reduce main-model spending." : "",
|
|
39
|
+
status, focus,
|
|
40
|
+
});
|
|
41
|
+
if (!choice) return;
|
|
42
|
+
focus = choice;
|
|
43
|
+
if (choice === "model") {
|
|
44
|
+
const picked = await promptSelectOne(ctx, "Worker model", "Choose a cost-effective model · Esc back",
|
|
45
|
+
buildModelPickerItems({ models, configuredRef: config.model, mainRef: currentModelRef(ctx) }),
|
|
46
|
+
config.model ?? CURRENT_MAIN_MODEL);
|
|
47
|
+
if (picked === undefined) continue;
|
|
48
|
+
const next = await loadConfig(configPath);
|
|
49
|
+
if (picked === CURRENT_MAIN_MODEL) delete next.model;
|
|
50
|
+
else next.model = picked;
|
|
51
|
+
await saveConfig(next, configPath);
|
|
52
|
+
status = "Model saved";
|
|
53
|
+
} else if (choice === "thinking") {
|
|
54
|
+
const levels = supportedThinkingLevels(config.model && !selected ? undefined : model);
|
|
55
|
+
if (!levels.length) {
|
|
56
|
+
ctx.ui.notify("Choose a model before changing thinking; its supported levels are not available yet.", "info");
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const items: SetupItem[] = levels.map((level) => ({
|
|
60
|
+
value: level, label: level + (level === DEFAULT_THINKING_LEVEL ? " (default)" : ""),
|
|
61
|
+
description: THINKING_HINTS[level], saved: level === config.thinking,
|
|
62
|
+
}));
|
|
63
|
+
if (!levels.includes(config.thinking)) items.push({
|
|
64
|
+
value: config.thinking, label: config.thinking + " (runs as " + effective + ")",
|
|
65
|
+
description: "Saved preference; the current model clamps it.", saved: true,
|
|
66
|
+
});
|
|
67
|
+
const picked = await promptSelectOne(ctx, "Worker thinking", "Reasoning effort · Esc back", items, config.thinking);
|
|
68
|
+
if (picked === undefined) continue;
|
|
69
|
+
await saveConfig({ ...await loadConfig(configPath), thinking: picked as ThinkingLevel }, configPath);
|
|
70
|
+
status = "Thinking saved";
|
|
71
|
+
} else if (choice === "reset") {
|
|
72
|
+
await saveConfig({ ...DEFAULT_CONFIG }, configPath);
|
|
73
|
+
status = "Defaults restored";
|
|
74
|
+
}
|
|
200
75
|
}
|
|
201
76
|
} catch (error) {
|
|
202
77
|
ctx.ui.notify("pi-subagents setup failed: " + errorMessage(error), "error");
|
|
203
78
|
}
|
|
204
79
|
}
|
|
205
80
|
|
|
206
|
-
export
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
"pi-subagents:
|
|
217
|
-
|
|
218
|
-
);
|
|
81
|
+
export async function ensureDefaultConfig(ctx: ExtensionContext, configPath: string = getConfigPath()): Promise<void> {
|
|
82
|
+
try {
|
|
83
|
+
const result = await initializeConfig(configPath);
|
|
84
|
+
if (!result) return;
|
|
85
|
+
ctx.ui.notify(
|
|
86
|
+
"pi-subagents: " + (result === "reset" ? "deleted the old config and initialized new worker settings at " : "initialized worker settings at ")
|
|
87
|
+
+ configPath + ". Main plans and reviews; workers execute. Run /subagents-setup to choose a cost-effective worker model and thinking level. Defaults follow main with medium thinking.",
|
|
88
|
+
"info",
|
|
89
|
+
);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
ctx.ui.notify("pi-subagents could not initialize settings: " + errorMessage(error) + ". Fix the config path and run /subagents-setup.", "warning");
|
|
92
|
+
}
|
|
219
93
|
}
|
package/src/configuration/ui.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Compact worker settings and a searchable model picker in standalone modal panels. */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
Input, fuzzyFilter, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi,
|
|
@@ -67,7 +67,6 @@ interface PickerOptions {
|
|
|
67
67
|
title: string;
|
|
68
68
|
hint: string;
|
|
69
69
|
initialValue?: string;
|
|
70
|
-
searchable: boolean;
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
/** Input owns Unicode editing, paste, horizontal scrolling and the IME cursor.
|
|
@@ -108,11 +107,11 @@ class Picker implements Component, Focusable {
|
|
|
108
107
|
get focused(): boolean { return this._focused; }
|
|
109
108
|
set focused(value: boolean) {
|
|
110
109
|
this._focused = value;
|
|
111
|
-
this.search.focused = value &&
|
|
110
|
+
this.search.focused = value && !this.details;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
private isSaved(item: SetupItem): boolean {
|
|
115
|
-
return item.saved ??
|
|
114
|
+
return item.saved ?? item.value === this.options.initialValue;
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
private keyLabel(action: Keybinding): string {
|
|
@@ -150,7 +149,7 @@ class Picker implements Component, Focusable {
|
|
|
150
149
|
const item = this.filtered[this.cursor];
|
|
151
150
|
return [
|
|
152
151
|
theme.bold(this.options.title + (this.details ? " · Details" : "")),
|
|
153
|
-
...(this.
|
|
152
|
+
...(this.details ? [] : this.search.render(innerWidth)),
|
|
154
153
|
item ? theme.fg("accent", "› ") + theme.underline(item.label + (this.isSaved(item) ? " [saved]" : "")) : "No matches. Clear or change the search.",
|
|
155
154
|
].map((line) => truncateToWidth(line, width, "…"));
|
|
156
155
|
}
|
|
@@ -181,7 +180,7 @@ class Picker implements Component, Focusable {
|
|
|
181
180
|
return framePanel(theme, width, titleText, subtitle, body, footer);
|
|
182
181
|
}
|
|
183
182
|
|
|
184
|
-
const searchLines =
|
|
183
|
+
const searchLines = [...this.search.render(innerWidth), ""];
|
|
185
184
|
const item = this.filtered[this.cursor];
|
|
186
185
|
const previewLines = item?.description
|
|
187
186
|
? ["", ...wrapTextWithAnsi(item.description, innerWidth).slice(0, 3).map((line, idx, arr) => {
|
|
@@ -257,7 +256,7 @@ class Picker implements Component, Focusable {
|
|
|
257
256
|
this.cursor = Math.max(0, this.cursor - this.pageRows);
|
|
258
257
|
} else if (kb.matches(data, "tui.select.pageDown")) {
|
|
259
258
|
this.cursor = Math.max(0, Math.min(count - 1, this.cursor + this.pageRows));
|
|
260
|
-
} else
|
|
259
|
+
} else {
|
|
261
260
|
const before = this.search.getValue();
|
|
262
261
|
this.search.handleInput(data);
|
|
263
262
|
if (before !== this.search.getValue()) {
|
|
@@ -276,226 +275,102 @@ class Picker implements Component, Focusable {
|
|
|
276
275
|
invalidate(): void { this.search.invalidate(); }
|
|
277
276
|
}
|
|
278
277
|
|
|
279
|
-
|
|
278
|
+
/** Single-select modal panel with fuzzy search, [saved] badge, Tab details, and paging. Esc returns without a change. */
|
|
279
|
+
export function promptSelectOne(
|
|
280
|
+
ctx: PickerContext, title: string, hint: string, items: SetupItem[], initialValue?: string,
|
|
281
|
+
): Promise<string | undefined> {
|
|
280
282
|
if (ctx.mode !== "tui") {
|
|
281
283
|
ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
|
|
282
284
|
return Promise.resolve(undefined);
|
|
283
285
|
}
|
|
284
286
|
return ctx.ui.custom<string | undefined>(
|
|
285
|
-
(tui, theme, keybindings, done) => new Picker(items,
|
|
286
|
-
{ overlay: true, overlayOptions: SETUP_OVERLAY_OPTIONS },
|
|
287
|
+
(tui, theme, keybindings, done) => new Picker(items, { title, hint, initialValue }, tui, theme, keybindings, done),
|
|
288
|
+
{ overlay: true, overlayOptions: SETUP_OVERLAY_OPTIONS, blocked: { kind: "question", message: title } },
|
|
287
289
|
);
|
|
288
290
|
}
|
|
289
291
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
ctx: PickerContext, title: string, hint: string, items: SetupItem[], initialValue?: string,
|
|
293
|
-
): Promise<string | undefined> {
|
|
294
|
-
return promptModal(ctx, items, { title, hint, initialValue, searchable: true });
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/** Vertical modal menu. initialValue restores navigation, not saved state. */
|
|
298
|
-
export function promptMenu(
|
|
299
|
-
ctx: PickerContext, title: string, hint: string, items: SetupItem[], initialValue?: string,
|
|
300
|
-
): Promise<string | undefined> {
|
|
301
|
-
return promptModal(ctx, items, { title, hint, initialValue, searchable: false });
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export interface RoleGridRow {
|
|
305
|
-
role: string;
|
|
306
|
-
purpose?: string;
|
|
292
|
+
export interface WorkerSettingsView {
|
|
293
|
+
main: string;
|
|
307
294
|
model: string;
|
|
308
|
-
/** Effective level, optionally followed by the requested level when clamped. */
|
|
309
295
|
thinking: string;
|
|
310
|
-
|
|
311
|
-
|
|
296
|
+
note: string;
|
|
297
|
+
status: string;
|
|
298
|
+
focus: string;
|
|
312
299
|
}
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
private row: number;
|
|
322
|
-
private column: number;
|
|
323
|
-
private scrollTop = 0;
|
|
324
|
-
private pageRows = 1;
|
|
325
|
-
private viewport = "";
|
|
326
|
-
private revealField = true;
|
|
327
|
-
|
|
328
|
-
private readonly rows: RoleGridRow[];
|
|
329
|
-
private readonly status: string;
|
|
300
|
+
|
|
301
|
+
const SETTING_KEYS = ["model", "thinking", "reset"] as const;
|
|
302
|
+
|
|
303
|
+
class WorkerSettings implements Component {
|
|
304
|
+
private cursor: number;
|
|
305
|
+
private detailTop = 0;
|
|
306
|
+
private detailPage = 1;
|
|
307
|
+
private readonly view: WorkerSettingsView;
|
|
330
308
|
private readonly tui: TUI;
|
|
331
309
|
private readonly theme: Theme;
|
|
332
|
-
private readonly
|
|
333
|
-
private readonly done: (
|
|
334
|
-
|
|
310
|
+
private readonly keys: KeybindingsManager;
|
|
311
|
+
private readonly done: (value: string | undefined) => void;
|
|
335
312
|
constructor(
|
|
336
|
-
|
|
337
|
-
|
|
313
|
+
view: WorkerSettingsView, tui: TUI, theme: Theme,
|
|
314
|
+
keys: KeybindingsManager, done: (value: string | undefined) => void,
|
|
338
315
|
) {
|
|
339
|
-
this.
|
|
340
|
-
this.status = status;
|
|
316
|
+
this.view = view;
|
|
341
317
|
this.tui = tui;
|
|
342
318
|
this.theme = theme;
|
|
343
|
-
this.
|
|
319
|
+
this.keys = keys;
|
|
344
320
|
this.done = done;
|
|
345
|
-
this.
|
|
346
|
-
this.column = Math.min(Math.max(0, focus.column ?? 0), GRID_COLUMNS.length - 1);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
private settings(width: number): { lines: string[]; start: number; end: number } {
|
|
350
|
-
const focused = this.rows[this.row];
|
|
351
|
-
if (!focused) return { lines: [this.theme.fg("dim", "No roles configured.")], start: 0, end: 1 };
|
|
352
|
-
const theme = this.theme;
|
|
353
|
-
const dim = (text: string) => theme.fg("dim", text);
|
|
354
|
-
const field = GRID_COLUMNS[this.column]!;
|
|
355
|
-
const label = field === "thinking" ? "Thinking (reasoning effort)" : field === "reset" ? "Reset" : "Model";
|
|
356
|
-
const lines = [theme.bold(focused.role + " · " + label), ""];
|
|
357
|
-
const starts: number[] = [];
|
|
358
|
-
const setting = (column: number, name: string, hint: string): void => {
|
|
359
|
-
starts.push(lines.length);
|
|
360
|
-
const active = this.column === column;
|
|
361
|
-
lines.push((active ? theme.fg("accent", "› ") : " ") + (active ? theme.underline(theme.bold(name)) : name) + dim(" · " + hint));
|
|
362
|
-
};
|
|
363
|
-
const value = (text: string): void => {
|
|
364
|
-
lines.push(...wrapTextWithAnsi(text, Math.max(1, width - 2)).map((line) => " " + line));
|
|
365
|
-
};
|
|
366
|
-
setting(0, "Model", "Enter edit");
|
|
367
|
-
value(focused.model);
|
|
368
|
-
setting(1, "Thinking", "effective");
|
|
369
|
-
value(focused.thinking);
|
|
370
|
-
lines.push(dim(" Source: " + (focused.thinkingOverridden ? "override *" : "role default")));
|
|
371
|
-
setting(2, "Reset", "Enter restore defaults");
|
|
372
|
-
const end = lines.length;
|
|
373
|
-
lines.push("", ...wrapTextWithAnsi(focused.description, width).map(dim));
|
|
374
|
-
return { lines, start: starts[this.column]!, end: starts[this.column + 1] ?? end };
|
|
321
|
+
this.cursor = Math.max(0, SETTING_KEYS.findIndex((key) => key === view.focus));
|
|
375
322
|
}
|
|
376
323
|
|
|
377
324
|
render(width: number): string[] {
|
|
378
325
|
if (width <= 0) return [];
|
|
379
|
-
const theme = this.theme;
|
|
380
|
-
const dim = (text: string) => theme.fg("dim", text);
|
|
381
326
|
const height = setupHeight(this.tui);
|
|
382
|
-
const framed = width >= 20 && height >=
|
|
383
|
-
const
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const detailOffset = wide ? 0 : roles.length + 1;
|
|
401
|
-
const body: string[] = [];
|
|
402
|
-
const divider = dim(" │ ");
|
|
403
|
-
if (wide) {
|
|
404
|
-
for (let i = 0; i < Math.max(roles.length, details.lines.length); i++) {
|
|
405
|
-
const left = truncateToWidth(roles[i] ?? "", roleWidth, "…");
|
|
406
|
-
body.push(left + " ".repeat(Math.max(0, roleWidth - visibleWidth(left))) + divider + (details.lines[i] ?? ""));
|
|
407
|
-
}
|
|
408
|
-
} else {
|
|
409
|
-
body.push(...roles, "", ...details.lines);
|
|
410
|
-
}
|
|
411
|
-
const footer = innerWidth >= 52
|
|
412
|
-
? [dim("↑/↓ role · ←/→ field · Enter edit · Esc close")]
|
|
413
|
-
: [dim("↑/↓ role · ←/→ field"), dim("Enter edit · Esc close")];
|
|
414
|
-
|
|
415
|
-
const chromeRows = framed ? 4 + footer.length + 1 : 3 + footer.length + 1;
|
|
416
|
-
if (body.length + chromeRows <= height) {
|
|
417
|
-
this.scrollTop = 0;
|
|
418
|
-
this.revealField = true;
|
|
419
|
-
if (!framed) {
|
|
420
|
-
return [theme.bold("Subagents · Roles"), dim(this.status), "", ...body, "", ...footer]
|
|
421
|
-
.map((line) => truncateToWidth(line, width, "…"));
|
|
422
|
-
}
|
|
423
|
-
return framePanel(theme, width, "Subagents · Roles", this.status, body, footer);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// Pin the selected identity while scrolling the existing pane content.
|
|
427
|
-
// The field's complete value and provenance remain reachable by paging.
|
|
428
|
-
const compact = height < 10;
|
|
429
|
-
const header = [details.lines[0]!];
|
|
430
|
-
const controls = innerWidth >= 58
|
|
431
|
-
? [dim("↑/↓ role · ←/→ field · PgUp/Dn scroll · Enter edit · Esc close")]
|
|
432
|
-
: compact
|
|
433
|
-
? [dim("PgUp/Dn scroll · Enter edit · Esc")]
|
|
434
|
-
: [dim("↑/↓ role · ←/→ field"), dim("PgUp/Dn scroll · Enter edit · Esc")];
|
|
435
|
-
const scrollChrome = framed ? 4 + header.length + controls.length + 1 : header.length + controls.length;
|
|
436
|
-
this.pageRows = Math.max(1, height - scrollChrome);
|
|
437
|
-
const viewport = innerWidth + ":" + this.pageRows;
|
|
438
|
-
if (this.revealField || this.viewport !== viewport) {
|
|
439
|
-
const start = detailOffset + details.start;
|
|
440
|
-
const end = detailOffset + details.end;
|
|
441
|
-
// One-line viewports show the value rather than repeating its label.
|
|
442
|
-
this.scrollTop = end - start > this.pageRows ? start + Number(this.pageRows === 1 && end > start + 1)
|
|
443
|
-
: Math.max(0, end - this.pageRows);
|
|
444
|
-
}
|
|
445
|
-
this.viewport = viewport;
|
|
446
|
-
this.revealField = false;
|
|
447
|
-
this.scrollTop = Math.max(0, Math.min(this.scrollTop, body.length - this.pageRows));
|
|
448
|
-
const visibleBody = [...header, ...body.slice(this.scrollTop, this.scrollTop + this.pageRows)];
|
|
449
|
-
if (!framed) {
|
|
450
|
-
return [...visibleBody, ...controls].map((line) => truncateToWidth(line, width, "…"));
|
|
327
|
+
const framed = width >= 20 && height >= 13;
|
|
328
|
+
const inner = Math.max(1, width - (framed ? 4 : 0));
|
|
329
|
+
const values = [this.view.model, this.view.thinking, "Follow main · medium"];
|
|
330
|
+
const labels = ["Model", "Thinking", "Reset"];
|
|
331
|
+
const rows = labels.map((label, index) => {
|
|
332
|
+
const line = truncateToWidth(label + " " + values[index], Math.max(1, inner - 2), "…");
|
|
333
|
+
return index === this.cursor ? this.theme.fg("accent", "› " + this.theme.bold(line)) : " " + line;
|
|
334
|
+
});
|
|
335
|
+
const hints = ["Worker model: " + this.view.model, "Worker thinking: " + this.view.thinking, "Restore Follow main and medium thinking."];
|
|
336
|
+
const details = [...wrapTextWithAnsi(hints[this.cursor]!, inner), ...(this.view.note ? wrapTextWithAnsi(this.view.note, inner) : [])];
|
|
337
|
+
const key = (action: Keybinding) => {
|
|
338
|
+
const name = this.keys.getKeys(action)[0] ?? "unbound";
|
|
339
|
+
return ({ escape: "Esc", enter: "Enter", up: "↑", down: "↓" } as Record<string, string>)[name] ?? name;
|
|
340
|
+
};
|
|
341
|
+
const footer = key("tui.select.cancel") + " close · " + key("tui.select.confirm") + " edit · " + key("tui.select.up") + key("tui.select.down") + " move";
|
|
342
|
+
if (height < 12) {
|
|
343
|
+
return [this.theme.bold("Subagents"), ...rows, this.view.status, footer]
|
|
344
|
+
.slice(0, height).map((line) => truncateToWidth(line, width, "…"));
|
|
451
345
|
}
|
|
452
|
-
|
|
346
|
+
this.detailPage = Math.max(1, height - (framed ? 12 : 9));
|
|
347
|
+
this.detailTop = Math.max(0, Math.min(this.detailTop, details.length - this.detailPage));
|
|
348
|
+
const body = [
|
|
349
|
+
this.theme.fg("muted", truncateToWidth("Main · " + this.view.main, inner, "…")),
|
|
350
|
+
"", ...rows, "",
|
|
351
|
+
...details.slice(this.detailTop, this.detailTop + this.detailPage).map((line) => this.theme.fg("muted", line)),
|
|
352
|
+
];
|
|
353
|
+
const status = (details.length > this.detailPage ? "PgUp/PgDn details · " : "") + this.view.status;
|
|
354
|
+
if (framed) return framePanel(this.theme, width, "Subagents", undefined, body, [status, footer]);
|
|
355
|
+
return [this.theme.bold("Subagents"), ...body, status, footer].map((line) => truncateToWidth(line, width, "…"));
|
|
453
356
|
}
|
|
454
357
|
|
|
455
358
|
handleInput(data: string): void {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
} else if (kb.matches(data, "tui.select.pageDown")) {
|
|
463
|
-
this.scrollTop += this.pageRows;
|
|
464
|
-
} else if (kb.matches(data, "tui.select.up")) {
|
|
465
|
-
if (rows) this.row = (this.row - 1 + rows) % rows;
|
|
466
|
-
} else if (kb.matches(data, "tui.select.down")) {
|
|
467
|
-
if (rows) this.row = (this.row + 1) % rows;
|
|
468
|
-
} else if (matchesKey(data, "left") || kb.matches(data, "tui.editor.cursorLeft")) {
|
|
469
|
-
this.column = (this.column - 1 + GRID_COLUMNS.length) % GRID_COLUMNS.length;
|
|
470
|
-
} else if (matchesKey(data, "right") || kb.matches(data, "tui.editor.cursorRight")) {
|
|
471
|
-
this.column = (this.column + 1) % GRID_COLUMNS.length;
|
|
472
|
-
} else if (kb.matches(data, "tui.select.confirm")) {
|
|
473
|
-
const focused = this.rows[this.row];
|
|
474
|
-
if (focused) {
|
|
475
|
-
this.done({ row: this.row, column: this.column, role: focused.role, field: GRID_COLUMNS[this.column]! });
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
} else if (kb.matches(data, "tui.select.cancel")) {
|
|
479
|
-
this.done(undefined);
|
|
480
|
-
return;
|
|
481
|
-
} else return;
|
|
482
|
-
if (this.row !== previousRow || this.column !== previousColumn) this.revealField = true;
|
|
359
|
+
if (this.keys.matches(data, "tui.select.cancel")) { this.done(undefined); return; }
|
|
360
|
+
if (this.keys.matches(data, "tui.select.confirm")) { this.done(SETTING_KEYS[this.cursor]); return; }
|
|
361
|
+
if (this.keys.matches(data, "tui.select.up")) { this.cursor = (this.cursor + 2) % 3; this.detailTop = 0; }
|
|
362
|
+
else if (this.keys.matches(data, "tui.select.down")) { this.cursor = (this.cursor + 1) % 3; this.detailTop = 0; }
|
|
363
|
+
else if (this.keys.matches(data, "tui.select.pageUp")) this.detailTop -= this.detailPage;
|
|
364
|
+
else if (this.keys.matches(data, "tui.select.pageDown")) this.detailTop += this.detailPage;
|
|
483
365
|
this.tui.requestRender();
|
|
484
366
|
}
|
|
485
367
|
|
|
486
368
|
invalidate(): void {}
|
|
487
369
|
}
|
|
488
370
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
if (ctx.mode !== "tui") {
|
|
494
|
-
ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
|
|
495
|
-
return Promise.resolve(undefined);
|
|
496
|
-
}
|
|
497
|
-
return ctx.ui.custom<RoleGridChoice | undefined>(
|
|
498
|
-
(tui, theme, keybindings, done) => new RoleGrid(rows, status, focus, tui, theme, keybindings, done),
|
|
499
|
-
{ overlay: true, overlayOptions: SETUP_OVERLAY_OPTIONS },
|
|
371
|
+
export function promptSettings(ctx: PickerContext, view: WorkerSettingsView): Promise<string | undefined> {
|
|
372
|
+
return ctx.ui.custom<string | undefined>(
|
|
373
|
+
(tui, theme, keys, done) => new WorkerSettings(view, tui, theme, keys, done),
|
|
374
|
+
{ overlay: true, overlayOptions: SETUP_OVERLAY_OPTIONS, blocked: { kind: "question", message: "Configure subagent worker" } },
|
|
500
375
|
);
|
|
501
376
|
}
|
package/src/delegation/agents.ts
CHANGED
|
@@ -91,11 +91,11 @@ export function resolveAgentTools(
|
|
|
91
91
|
return { ...agent, tools };
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/** Filesystem-write capability used by worktree admission
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
94
|
+
/** Filesystem-write capability used by worktree admission. Scout is a hard
|
|
95
|
+
* read-only boundary. An unresolved tools list means the child inherits
|
|
96
|
+
* arbitrary active tools and is therefore mutable; for a resolved list only
|
|
97
|
+
* proven read-only tools count as safe — shells, tool-reaching tools, and tools
|
|
98
|
+
* without a read-only annotation stay mutable. */
|
|
99
99
|
export function isWriteCapableAgent(
|
|
100
100
|
agent: Pick<AgentConfig, "name" | "tools">,
|
|
101
101
|
toolInfos?: readonly ToolMetadata[],
|