@ferris1225/pi-subagents 6.0.3 → 6.0.4
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 +11 -0
- package/README.md +69 -194
- package/index.ts +2 -12
- package/package.json +1 -1
- package/src/configuration/config.ts +2 -6
- package/src/configuration/role-migration.ts +3 -14
- package/src/configuration/setup.ts +75 -36
- package/src/configuration/ui.ts +337 -54
- package/src/delegation/agents.ts +0 -1
- package/src/delegation/builtin-agents.ts +5 -26
- package/src/delegation/dispatch.ts +27 -118
- package/src/delegation/prompt.ts +15 -47
- package/src/lifecycle/cancellation.ts +4 -8
- package/src/lifecycle/durable.ts +0 -18
- package/src/lifecycle/runtime.ts +7 -56
- package/src/lifecycle/thread-lifecycle.ts +5 -33
- package/src/lifecycle/thread-restore.ts +0 -3
- package/src/lifecycle/thread-shared.ts +1 -11
- package/src/lifecycle/tools.ts +12 -97
- package/src/presentation/monitor.ts +727 -758
- package/src/presentation/widget.ts +33 -131
- package/src/delegation/ownership.ts +0 -98
- package/src/delegation/phase-scope.ts +0 -186
- package/src/workflow/acceptance.ts +0 -67
- package/src/workflow/durable.ts +0 -228
- package/src/workflow/engine.ts +0 -816
- package/src/workflow/plan.ts +0 -409
- package/src/workflow/state.ts +0 -55
- package/src/workflow/templates.ts +0 -156
- package/src/workflow/tool.ts +0 -254
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
resolveThinkingLevel,
|
|
25
25
|
supportedThinkingLevels,
|
|
26
26
|
} from "./models.ts";
|
|
27
|
-
import { promptMenu, promptSelectOne, type SetupItem } from "./ui.ts";
|
|
27
|
+
import { promptMenu, promptRoleGrid, promptSelectOne, type RoleGridFocus, type RoleGridRow, type SetupItem } from "./ui.ts";
|
|
28
28
|
|
|
29
29
|
const ROLE_DEFAULT = "__role_default__";
|
|
30
30
|
const THINKING_LEVEL_HINTS: Record<ThinkingLevel, string> = {
|
|
@@ -37,6 +37,12 @@ const THINKING_LEVEL_HINTS: Record<ThinkingLevel, string> = {
|
|
|
37
37
|
max: "strongest reasoning",
|
|
38
38
|
};
|
|
39
39
|
|
|
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
|
+
|
|
40
46
|
async function configExists(configPath: string): Promise<boolean> {
|
|
41
47
|
try {
|
|
42
48
|
await stat(configPath);
|
|
@@ -50,14 +56,7 @@ function roleModel(ctx: ExtensionContext, config: SubagentsConfig, name: string)
|
|
|
50
56
|
return findModelByRef(availableModelsInScope(ctx), config.agentModels[name]) ?? ctx.model;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
scout: "Research with citations",
|
|
55
|
-
artisan: "Implement and verify",
|
|
56
|
-
sentinel: "Review implementation",
|
|
57
|
-
skeptic: "Challenge a named claim",
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
function roleSettings(ctx: ExtensionContext, config: SubagentsConfig, name: string): SetupItem[] {
|
|
59
|
+
export function roleSettings(ctx: ExtensionContext, config: SubagentsConfig, name: string): SetupItem[] {
|
|
61
60
|
const selected = config.agentModels[name];
|
|
62
61
|
const model = findModelByRef(availableModelsInScope(ctx), selected);
|
|
63
62
|
const modelLabel = selected
|
|
@@ -77,13 +76,44 @@ function roleSettings(ctx: ExtensionContext, config: SubagentsConfig, name: stri
|
|
|
77
76
|
];
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
function roleItems(ctx: ExtensionContext, config: SubagentsConfig): SetupItem[] {
|
|
79
|
+
export function roleItems(ctx: ExtensionContext, config: SubagentsConfig): SetupItem[] {
|
|
81
80
|
return BUILTIN_AGENT_NAMES.map((name) => {
|
|
82
81
|
const settings = roleSettings(ctx, config, name);
|
|
83
|
-
return { value: name, label: name + " · " + ROLE_PURPOSE[name],
|
|
82
|
+
return { value: name, label: name + " · " + (ROLE_PURPOSE[name] ?? name),
|
|
84
83
|
description: settings[0]!.label + "\n" + settings[1]!.label + "\n" + agentProfile(name)!.remark };
|
|
85
84
|
});
|
|
86
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
|
+
|
|
87
117
|
async function editSetting(
|
|
88
118
|
ctx: ExtensionContext,
|
|
89
119
|
config: SubagentsConfig,
|
|
@@ -99,7 +129,7 @@ async function editSetting(
|
|
|
99
129
|
delete next.agentThinkingLevels[name];
|
|
100
130
|
} else if (field === "model") {
|
|
101
131
|
const choice = await promptSelectOne(ctx, name + " · Model",
|
|
102
|
-
"Follow main = dynamic · Others = pinned",
|
|
132
|
+
"Follow main = dynamic · Others = pinned · Esc back without changes",
|
|
103
133
|
buildModelPickerItems({ models: availableModelsInScope(ctx), configuredRef: config.agentModels[name], mainRef: currentModelRef(ctx) }),
|
|
104
134
|
config.agentModels[name] ?? CURRENT_MAIN_MODEL);
|
|
105
135
|
if (choice === undefined) return undefined;
|
|
@@ -113,17 +143,31 @@ async function editSetting(
|
|
|
113
143
|
ctx.ui.notify("Choose a model before changing thinking; its supported levels are not available yet.", "info");
|
|
114
144
|
return undefined;
|
|
115
145
|
}
|
|
116
|
-
const options = [
|
|
117
|
-
{ value: ROLE_DEFAULT, label: "Role default", description: preferredDefault + (effectiveDefault !== preferredDefault ? " → " + effectiveDefault + " on this model" : "") },
|
|
118
|
-
...supported.map((level) => ({ value: level, label: level, description: THINKING_LEVEL_HINTS[level] })),
|
|
119
|
-
];
|
|
120
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
|
+
];
|
|
121
161
|
if (current && !supported.includes(current)) {
|
|
122
|
-
options.push({
|
|
123
|
-
|
|
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
|
+
});
|
|
124
168
|
}
|
|
125
169
|
const choice = await promptSelectOne(ctx, name + " · Thinking",
|
|
126
|
-
"Reasoning effort · saved preferences survive model changes",
|
|
170
|
+
"Reasoning effort · saved preferences survive model changes · Esc back",
|
|
127
171
|
options, current ?? ROLE_DEFAULT);
|
|
128
172
|
if (choice === undefined) return undefined;
|
|
129
173
|
if (choice === ROLE_DEFAULT) delete next.agentThinkingLevels[name];
|
|
@@ -134,8 +178,7 @@ async function editSetting(
|
|
|
134
178
|
return next;
|
|
135
179
|
}
|
|
136
180
|
|
|
137
|
-
|
|
138
|
-
/** The same role overview serves first install and later edits. */
|
|
181
|
+
/** Standalone modal panel for first install and later edits. */
|
|
139
182
|
export async function runSetup(ctx: ExtensionContext, configPath: string = getConfigPath()): Promise<void> {
|
|
140
183
|
if (ctx.mode !== "tui") {
|
|
141
184
|
ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
|
|
@@ -143,29 +186,25 @@ export async function runSetup(ctx: ExtensionContext, configPath: string = getCo
|
|
|
143
186
|
}
|
|
144
187
|
try {
|
|
145
188
|
let config = await loadConfig(configPath);
|
|
146
|
-
let
|
|
147
|
-
const settingFocus: Record<string, string> = {};
|
|
189
|
+
let focus: RoleGridFocus = {};
|
|
148
190
|
let status = "Changes save immediately";
|
|
149
191
|
while (true) {
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (!next) continue;
|
|
159
|
-
await saveConfig(next, configPath);
|
|
160
|
-
config = next;
|
|
161
|
-
status = "Saved " + name + (field === "reset" ? " defaults" : " " + field);
|
|
162
|
-
}
|
|
192
|
+
const choice = await promptRoleGrid(ctx, roleRows(ctx, config), focus, status);
|
|
193
|
+
if (choice === undefined) return;
|
|
194
|
+
focus = { row: choice.row, column: choice.column };
|
|
195
|
+
const next = await editSetting(ctx, config, choice.role, choice.field);
|
|
196
|
+
if (!next) continue;
|
|
197
|
+
await saveConfig(next, configPath);
|
|
198
|
+
config = next;
|
|
199
|
+
status = "Saved " + choice.role + (choice.field === "reset" ? " defaults" : " " + choice.field);
|
|
163
200
|
}
|
|
164
201
|
} catch (error) {
|
|
165
202
|
ctx.ui.notify("pi-subagents setup failed: " + errorMessage(error), "error");
|
|
166
203
|
}
|
|
167
204
|
}
|
|
168
205
|
|
|
206
|
+
export { promptMenu };
|
|
207
|
+
|
|
169
208
|
/** Write shipped defaults once so every role works immediately. */
|
|
170
209
|
export async function ensureDefaultConfig(
|
|
171
210
|
ctx: ExtensionContext,
|
package/src/configuration/ui.ts
CHANGED
|
@@ -1,24 +1,68 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Standalone modal panels for /subagents-setup role settings and model selection. */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
Input, fuzzyFilter, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi,
|
|
5
|
-
type Component, type Focusable, type Keybinding, type KeybindingsManager, type SelectItem, type TUI,
|
|
5
|
+
type Component, type Focusable, type Keybinding, type KeybindingsManager, type OverlayOptions, type SelectItem, type TUI,
|
|
6
6
|
} from "@earendil-works/pi-tui";
|
|
7
7
|
import type { ExtensionCommandContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
|
|
9
9
|
type PickerContext = Pick<ExtensionCommandContext, "mode" | "ui">;
|
|
10
|
-
const PAGE_SIZE =
|
|
10
|
+
const PAGE_SIZE = 10;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
export const SETUP_OVERLAY_OPTIONS: OverlayOptions = {
|
|
13
|
+
anchor: "center",
|
|
14
|
+
width: "86%",
|
|
15
|
+
minWidth: 72,
|
|
16
|
+
maxHeight: "88%",
|
|
17
|
+
margin: { top: 1, bottom: 1, left: 2, right: 2 },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Modal height budget on the full terminal canvas instead of the input dock. */
|
|
14
21
|
function setupHeight(tui: TUI): number {
|
|
15
|
-
|
|
22
|
+
const termRows = tui.terminal?.rows ?? 28;
|
|
23
|
+
const maxRows = Math.floor(termRows * 0.88);
|
|
24
|
+
return Math.max(6, Math.min(maxRows, termRows - 2));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function padToWidth(text: string, width: number): string {
|
|
28
|
+
const truncated = truncateToWidth(text, width, "…");
|
|
29
|
+
return truncated + " ".repeat(Math.max(0, width - visibleWidth(truncated)));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function framePanel(theme: Theme, width: number, title: string, subtitle: string | undefined, body: string[], footer: string[]): string[] {
|
|
33
|
+
if (width <= 0) return [];
|
|
34
|
+
if (width < 20) {
|
|
35
|
+
return [theme.bold(title), ...(subtitle ? [theme.fg("dim", subtitle)] : []), ...body, ...footer]
|
|
36
|
+
.map((line) => truncateToWidth(line, width, "…"));
|
|
37
|
+
}
|
|
38
|
+
const border = (text: string) => theme.fg("border", text);
|
|
39
|
+
const innerWidth = Math.max(1, width - 4);
|
|
40
|
+
const topInner = Math.max(1, width - 2);
|
|
41
|
+
const titleBadge = truncateToWidth(" " + title + " ", topInner, "…");
|
|
42
|
+
const titleWidth = visibleWidth(titleBadge);
|
|
43
|
+
const topFill = Math.max(0, topInner - titleWidth - 1);
|
|
44
|
+
const row = (line = "") => border("│") + " " + padToWidth(line, innerWidth) + " " + border("│");
|
|
45
|
+
const divider = border("├" + "─".repeat(topInner) + "┤");
|
|
46
|
+
|
|
47
|
+
const out: string[] = [
|
|
48
|
+
border("╭─") + theme.fg("accent", theme.bold(titleBadge)) + border("─".repeat(topFill) + "╮"),
|
|
49
|
+
];
|
|
50
|
+
if (subtitle) out.push(row(theme.fg("muted", subtitle)));
|
|
51
|
+
out.push(divider);
|
|
52
|
+
for (const line of body) out.push(row(line));
|
|
53
|
+
if (footer.length) {
|
|
54
|
+
out.push(divider);
|
|
55
|
+
for (const line of footer) out.push(row(line));
|
|
56
|
+
}
|
|
57
|
+
out.push(border("╰" + "─".repeat(topInner) + "╯"));
|
|
58
|
+
return out;
|
|
16
59
|
}
|
|
17
60
|
|
|
18
61
|
export interface SetupItem extends SelectItem {
|
|
19
62
|
/** Saved state is independent of the navigation cursor. */
|
|
20
63
|
saved?: boolean;
|
|
21
64
|
}
|
|
65
|
+
|
|
22
66
|
interface PickerOptions {
|
|
23
67
|
title: string;
|
|
24
68
|
hint: string;
|
|
@@ -27,11 +71,11 @@ interface PickerOptions {
|
|
|
27
71
|
}
|
|
28
72
|
|
|
29
73
|
/** Input owns Unicode editing, paste, horizontal scrolling and the IME cursor.
|
|
30
|
-
*
|
|
74
|
+
* Selection, paging, and Tab detail inspection run inside a standalone modal panel. */
|
|
31
75
|
class Picker implements Component, Focusable {
|
|
32
76
|
private _focused = false;
|
|
33
77
|
private cursor = 0;
|
|
34
|
-
private pageRows =
|
|
78
|
+
private pageRows = PAGE_SIZE;
|
|
35
79
|
private details = false;
|
|
36
80
|
private detailTop = 0;
|
|
37
81
|
private filterFocus?: string;
|
|
@@ -88,58 +132,96 @@ class Picker implements Component, Focusable {
|
|
|
88
132
|
render(width: number): string[] {
|
|
89
133
|
if (width <= 0) return [];
|
|
90
134
|
const theme = this.theme;
|
|
135
|
+
const dim = (text: string) => theme.fg("dim", text);
|
|
91
136
|
const muted = (text: string) => theme.fg("muted", text);
|
|
92
137
|
const height = setupHeight(this.tui);
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
if (!(height === 3 && this.options.searchable && !this.details)) {
|
|
97
|
-
lines.push(theme.bold(this.options.title + (this.details ? " · Details" : "")));
|
|
98
|
-
}
|
|
99
|
-
if (!this.details && this.options.hint && height >= 10) lines.push(muted(this.options.hint));
|
|
100
|
-
if (!this.details && this.options.searchable) lines.push(...this.search.render(width));
|
|
138
|
+
const framed = width >= 20 && height >= 10;
|
|
139
|
+
const innerWidth = framed ? Math.max(1, width - 4) : width;
|
|
140
|
+
|
|
101
141
|
const move = this.keyLabel("tui.select.up") + "/" + this.keyLabel("tui.select.down");
|
|
102
142
|
const confirm = this.keyLabel("tui.select.confirm");
|
|
103
143
|
const cancel = this.keyLabel("tui.select.cancel");
|
|
104
144
|
const pageKeys = this.keyLabel("tui.select.pageUp") + "/" + this.keyLabel("tui.select.pageDown");
|
|
105
145
|
const page = pageKeys === "PgUp/PgDn" ? "PgUp/Dn" : pageKeys;
|
|
146
|
+
const matchCount = this.filtered.length ? (this.cursor + 1) + "/" + this.filtered.length + " matches" : "0 results";
|
|
147
|
+
|
|
148
|
+
if (!framed && height < 8) {
|
|
149
|
+
this.pageRows = 1;
|
|
150
|
+
const item = this.filtered[this.cursor];
|
|
151
|
+
return [
|
|
152
|
+
theme.bold(this.options.title + (this.details ? " · Details" : "")),
|
|
153
|
+
...(this.options.searchable && !this.details ? this.search.render(innerWidth) : []),
|
|
154
|
+
item ? theme.fg("accent", "› ") + theme.underline(item.label + (this.isSaved(item) ? " [saved]" : "")) : "No matches. Clear or change the search.",
|
|
155
|
+
].map((line) => truncateToWidth(line, width, "…"));
|
|
156
|
+
}
|
|
157
|
+
|
|
106
158
|
const navigation = move + " move · " + confirm + " select · " + cancel + " back";
|
|
107
|
-
const selectionHint = visibleWidth(navigation) <=
|
|
108
|
-
const footer =
|
|
109
|
-
?
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
159
|
+
const selectionHint = visibleWidth(navigation) <= innerWidth ? navigation : confirm + " select · " + cancel + " back · " + move;
|
|
160
|
+
const footer = this.details
|
|
161
|
+
? (innerWidth >= 56
|
|
162
|
+
? [dim(move + " scroll · " + page + " page · Tab list · " + confirm + " select · " + cancel + " back")]
|
|
163
|
+
: [dim(move + " scroll · Tab list · " + cancel + " back"), dim(page + " page · " + confirm + " select")])
|
|
164
|
+
: (innerWidth >= 64
|
|
165
|
+
? [dim(selectionHint + " · " + matchCount + " · " + page + " · Tab details")]
|
|
166
|
+
: [dim(selectionHint), dim(matchCount + " · " + page + " · Tab details")]);
|
|
167
|
+
|
|
168
|
+
const titleText = "Subagents · " + this.options.title + (this.details ? " · Details" : "");
|
|
169
|
+
const subtitle = !this.details && this.options.hint ? this.options.hint : undefined;
|
|
170
|
+
const chromeRows = framed ? (subtitle ? 4 : 3) + footer.length + 1 : 2 + footer.length;
|
|
171
|
+
|
|
115
172
|
if (this.details) {
|
|
173
|
+
const budget = Math.max(1, height - chromeRows);
|
|
116
174
|
this.pageRows = budget;
|
|
117
|
-
const details = this.detailLines(
|
|
175
|
+
const details = this.detailLines(innerWidth);
|
|
118
176
|
this.detailTop = Math.max(0, Math.min(this.detailTop, details.length - budget));
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const start = Math.max(0, Math.min(this.cursor - Math.floor(this.pageRows / 2), this.filtered.length - this.pageRows));
|
|
123
|
-
const visible = this.filtered.slice(start, start + this.pageRows);
|
|
124
|
-
if (!visible.length) lines.push(muted(this.search.getValue() ? "No matches. Clear or change the search." : "No choices available."));
|
|
125
|
-
for (const [index, item] of visible.entries()) {
|
|
126
|
-
const active = start + index === this.cursor;
|
|
127
|
-
const suffix = this.isSaved(item) ? " [saved]" : "";
|
|
128
|
-
const label = truncateToWidth(item.label, Math.max(0, width - 2 - visibleWidth(suffix)), "…") + suffix;
|
|
129
|
-
lines.push(active ? theme.fg("accent", "› ") + theme.underline(theme.bold(label)) : " " + label);
|
|
130
|
-
}
|
|
131
|
-
// Menus show the active role/setting's explanation. Choice lists only
|
|
132
|
-
// use spare rows for context, never displacing another choice.
|
|
133
|
-
const spare = Math.min(3, height - lines.length - footer.length);
|
|
134
|
-
const item = this.filtered[this.cursor];
|
|
135
|
-
if (spare > 0 && item?.description) {
|
|
136
|
-
const wrapped = wrapTextWithAnsi(item.description, width);
|
|
137
|
-
const preview = wrapped.slice(0, spare);
|
|
138
|
-
if (wrapped.length > spare) preview[spare - 1] = truncateToWidth(preview[spare - 1]! + "…", width, "…");
|
|
139
|
-
lines.push(...preview.map(muted));
|
|
177
|
+
const body = details.slice(this.detailTop, this.detailTop + budget);
|
|
178
|
+
if (!framed) {
|
|
179
|
+
return [theme.bold(titleText), ...body, ...footer].map((line) => truncateToWidth(line, width, "…"));
|
|
140
180
|
}
|
|
181
|
+
return framePanel(theme, width, titleText, subtitle, body, footer);
|
|
141
182
|
}
|
|
142
|
-
|
|
183
|
+
|
|
184
|
+
const searchLines = this.options.searchable ? [...this.search.render(innerWidth), ""] : [];
|
|
185
|
+
const item = this.filtered[this.cursor];
|
|
186
|
+
const previewLines = item?.description
|
|
187
|
+
? ["", ...wrapTextWithAnsi(item.description, innerWidth).slice(0, 3).map((line, idx, arr) => {
|
|
188
|
+
const allWrapped = wrapTextWithAnsi(item.description!, innerWidth);
|
|
189
|
+
if (idx === arr.length - 1 && allWrapped.length > arr.length) {
|
|
190
|
+
return muted(truncateToWidth(line + "…", innerWidth, "…"));
|
|
191
|
+
}
|
|
192
|
+
return muted(line);
|
|
193
|
+
})]
|
|
194
|
+
: [];
|
|
195
|
+
|
|
196
|
+
const availAfterSearch = Math.max(1, height - chromeRows - searchLines.length);
|
|
197
|
+
const minListRows = Math.min(Math.max(1, this.filtered.length), Math.min(6, availAfterSearch));
|
|
198
|
+
const detailBudget = Math.max(0, Math.min(previewLines.length, availAfterSearch - minListRows));
|
|
199
|
+
const visibleDetails = previewLines.slice(0, detailBudget);
|
|
200
|
+
this.pageRows = Math.max(1, Math.min(PAGE_SIZE, availAfterSearch - visibleDetails.length));
|
|
201
|
+
const start = Math.max(0, Math.min(this.cursor - Math.floor(this.pageRows / 2), this.filtered.length - this.pageRows));
|
|
202
|
+
const visible = this.filtered.slice(start, start + this.pageRows);
|
|
203
|
+
|
|
204
|
+
const body: string[] = [...searchLines];
|
|
205
|
+
if (!visible.length) {
|
|
206
|
+
body.push(dim(this.search.getValue() ? "No matches. Clear or change the search." : "No choices available."));
|
|
207
|
+
}
|
|
208
|
+
for (const [index, choice] of visible.entries()) {
|
|
209
|
+
const selected = start + index === this.cursor;
|
|
210
|
+
const suffix = this.isSaved(choice) ? " [saved]" : "";
|
|
211
|
+
const label = truncateToWidth(choice.label, Math.max(0, innerWidth - 2 - visibleWidth(suffix)), "…") + suffix;
|
|
212
|
+
body.push(selected ? theme.fg("accent", "› ") + theme.underline(theme.bold(label)) : " " + label);
|
|
213
|
+
}
|
|
214
|
+
body.push(...visibleDetails);
|
|
215
|
+
|
|
216
|
+
if (!framed) {
|
|
217
|
+
return [
|
|
218
|
+
theme.bold(titleText),
|
|
219
|
+
...(subtitle && height >= 12 ? [muted(subtitle)] : []),
|
|
220
|
+
...body,
|
|
221
|
+
...footer,
|
|
222
|
+
].map((line) => truncateToWidth(line, width, "…"));
|
|
223
|
+
}
|
|
224
|
+
return framePanel(theme, width, titleText, subtitle, body, footer);
|
|
143
225
|
}
|
|
144
226
|
|
|
145
227
|
handleInput(data: string): void {
|
|
@@ -194,25 +276,226 @@ class Picker implements Component, Focusable {
|
|
|
194
276
|
invalidate(): void { this.search.invalidate(); }
|
|
195
277
|
}
|
|
196
278
|
|
|
197
|
-
function
|
|
279
|
+
function promptModal(ctx: PickerContext, items: SetupItem[], options: PickerOptions): Promise<string | undefined> {
|
|
198
280
|
if (ctx.mode !== "tui") {
|
|
199
281
|
ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
|
|
200
282
|
return Promise.resolve(undefined);
|
|
201
283
|
}
|
|
202
|
-
return ctx.ui.custom<string | undefined>(
|
|
203
|
-
new Picker(items, options, tui, theme, keybindings, done)
|
|
284
|
+
return ctx.ui.custom<string | undefined>(
|
|
285
|
+
(tui, theme, keybindings, done) => new Picker(items, options, tui, theme, keybindings, done),
|
|
286
|
+
{ overlay: true, overlayOptions: SETUP_OVERLAY_OPTIONS },
|
|
287
|
+
);
|
|
204
288
|
}
|
|
205
289
|
|
|
206
|
-
/**
|
|
290
|
+
/** Single-select modal panel with fuzzy search, [saved] badge, Tab details, and paging. Esc returns without a change. */
|
|
207
291
|
export function promptSelectOne(
|
|
208
292
|
ctx: PickerContext, title: string, hint: string, items: SetupItem[], initialValue?: string,
|
|
209
293
|
): Promise<string | undefined> {
|
|
210
|
-
return
|
|
294
|
+
return promptModal(ctx, items, { title, hint, initialValue, searchable: true });
|
|
211
295
|
}
|
|
212
296
|
|
|
213
|
-
/**
|
|
297
|
+
/** Vertical modal menu. initialValue restores navigation, not saved state. */
|
|
214
298
|
export function promptMenu(
|
|
215
299
|
ctx: PickerContext, title: string, hint: string, items: SetupItem[], initialValue?: string,
|
|
216
300
|
): Promise<string | undefined> {
|
|
217
|
-
return
|
|
301
|
+
return promptModal(ctx, items, { title, hint, initialValue, searchable: false });
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface RoleGridRow {
|
|
305
|
+
role: string;
|
|
306
|
+
purpose?: string;
|
|
307
|
+
model: string;
|
|
308
|
+
/** Effective level, optionally followed by the requested level when clamped. */
|
|
309
|
+
thinking: string;
|
|
310
|
+
thinkingOverridden?: boolean;
|
|
311
|
+
description: string;
|
|
312
|
+
}
|
|
313
|
+
export interface RoleGridFocus { row?: number; column?: number; }
|
|
314
|
+
const GRID_COLUMNS = ["model", "thinking", "reset"] as const;
|
|
315
|
+
export type RoleGridColumn = (typeof GRID_COLUMNS)[number];
|
|
316
|
+
export interface RoleGridChoice { row: number; column: number; role: string; field: RoleGridColumn; }
|
|
317
|
+
|
|
318
|
+
/** Standalone modal panel with a role register beside the selected role's settings;
|
|
319
|
+
* narrow terminals stack the same regions. Full effective values are never squeezed into grid cells. */
|
|
320
|
+
class RoleGrid implements Component {
|
|
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;
|
|
330
|
+
private readonly tui: TUI;
|
|
331
|
+
private readonly theme: Theme;
|
|
332
|
+
private readonly keybindings: KeybindingsManager;
|
|
333
|
+
private readonly done: (choice: RoleGridChoice | undefined) => void;
|
|
334
|
+
|
|
335
|
+
constructor(
|
|
336
|
+
rows: RoleGridRow[], status: string, focus: RoleGridFocus, tui: TUI, theme: Theme,
|
|
337
|
+
keybindings: KeybindingsManager, done: (choice: RoleGridChoice | undefined) => void,
|
|
338
|
+
) {
|
|
339
|
+
this.rows = rows;
|
|
340
|
+
this.status = status;
|
|
341
|
+
this.tui = tui;
|
|
342
|
+
this.theme = theme;
|
|
343
|
+
this.keybindings = keybindings;
|
|
344
|
+
this.done = done;
|
|
345
|
+
this.row = Math.min(Math.max(0, focus.row ?? 0), Math.max(0, rows.length - 1));
|
|
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 };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
render(width: number): string[] {
|
|
378
|
+
if (width <= 0) return [];
|
|
379
|
+
const theme = this.theme;
|
|
380
|
+
const dim = (text: string) => theme.fg("dim", text);
|
|
381
|
+
const height = setupHeight(this.tui);
|
|
382
|
+
const framed = width >= 20 && height >= 10;
|
|
383
|
+
const innerWidth = framed ? Math.max(1, width - 4) : width;
|
|
384
|
+
const wide = innerWidth >= 72;
|
|
385
|
+
// The two panes close exactly: roleWidth + 3-column gutter + detailWidth = innerWidth.
|
|
386
|
+
const roleWidth = wide ? Math.min(28, Math.max(20, Math.floor(innerWidth * 0.28))) : innerWidth;
|
|
387
|
+
const roles: string[] = [];
|
|
388
|
+
for (const [index, role] of this.rows.entries()) {
|
|
389
|
+
const selected = index === this.row;
|
|
390
|
+
const title = role.purpose && wide ? role.role + " · " + role.purpose : role.role;
|
|
391
|
+
const clippedTitle = truncateToWidth(title, Math.max(1, roleWidth - 2), "…");
|
|
392
|
+
const name = selected ? theme.bold(clippedTitle) : clippedTitle;
|
|
393
|
+
roles.push((selected ? theme.fg("accent", "› ") : " ") + name);
|
|
394
|
+
if (wide) {
|
|
395
|
+
const summary = role.model + " · " + role.thinking + (role.thinkingOverridden ? " *" : "");
|
|
396
|
+
roles.push(dim(" " + truncateToWidth(summary, roleWidth - 2, "…")));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const details = this.settings(wide ? innerWidth - roleWidth - 3 : innerWidth);
|
|
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, "…"));
|
|
451
|
+
}
|
|
452
|
+
return framePanel(theme, width, "Subagents · Roles", this.status, visibleBody, controls);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
handleInput(data: string): void {
|
|
456
|
+
const kb = this.keybindings;
|
|
457
|
+
const rows = this.rows.length;
|
|
458
|
+
const previousRow = this.row;
|
|
459
|
+
const previousColumn = this.column;
|
|
460
|
+
if (kb.matches(data, "tui.select.pageUp")) {
|
|
461
|
+
this.scrollTop -= this.pageRows;
|
|
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;
|
|
483
|
+
this.tui.requestRender();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
invalidate(): void {}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** Role × setting modal panel. Esc closes without a change. */
|
|
490
|
+
export function promptRoleGrid(
|
|
491
|
+
ctx: PickerContext, rows: RoleGridRow[], focus: RoleGridFocus = {}, status = "Changes save immediately",
|
|
492
|
+
): Promise<RoleGridChoice | undefined> {
|
|
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 },
|
|
500
|
+
);
|
|
218
501
|
}
|
package/src/delegation/agents.ts
CHANGED
|
@@ -26,7 +26,6 @@ const BUILTIN_READ_ONLY_TOOL_NAMES = ["read", "grep", "find", "ls"] as const;
|
|
|
26
26
|
const BUILTIN_READ_ONLY_TOOL_SET: ReadonlySet<string> = new Set(BUILTIN_READ_ONLY_TOOL_NAMES);
|
|
27
27
|
export const SUBAGENT_TOOL_NAMES = [
|
|
28
28
|
"subagent",
|
|
29
|
-
"subagent_workflow",
|
|
30
29
|
"subagent_status",
|
|
31
30
|
"subagent_message",
|
|
32
31
|
"subagent_stop",
|