@ferris1225/pi-subagents 4.3.31 → 4.3.33
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 +80 -0
- package/LICENSE +1 -1
- package/README.md +215 -273
- package/index.ts +15 -14
- package/package.json +10 -10
- package/skills/workflow/SKILL.md +226 -0
- package/src/configuration/config.ts +17 -121
- package/src/configuration/models.ts +1 -1
- package/src/configuration/setup.ts +80 -176
- package/src/configuration/ui.ts +28 -66
- package/src/delegation/agents.ts +79 -209
- package/src/delegation/builtin-agents.ts +60 -0
- package/src/delegation/dispatch.ts +32 -149
- package/src/delegation/prompt.ts +7 -5
- package/src/execution/rpc-control.ts +6 -2
- package/src/execution/rpc-run.ts +60 -20
- package/src/execution/spawn.ts +17 -28
- package/src/isolation/git-command.ts +1 -2
- package/src/isolation/recovery.ts +1 -1
- package/src/isolation/temp-hygiene.ts +2 -2
- package/src/isolation/worktree.ts +31 -17
- package/src/lifecycle/completion.ts +1 -1
- package/src/lifecycle/dispatch-core.ts +142 -0
- package/src/lifecycle/durable.ts +3 -3
- package/src/lifecycle/runtime.ts +34 -1
- package/src/lifecycle/thread-lifecycle.ts +36 -25
- package/src/lifecycle/thread-shared.ts +11 -4
- package/src/lifecycle/tools.ts +84 -11
- package/src/presentation/monitor.ts +39 -17
- package/src/presentation/widget.ts +2 -2
- package/src/workflow/durable.ts +195 -0
- package/src/workflow/engine.ts +625 -0
- package/src/workflow/files.ts +217 -0
- package/src/workflow/plan.ts +340 -0
- package/src/workflow/state.ts +48 -0
- package/src/workflow/tool.ts +269 -0
- package/workflows/code-review.md +57 -0
- package/workflows/migration.md +52 -0
- package/workflows/research.md +47 -0
- package/agents/artisan.md +0 -18
- package/agents/scout.md +0 -19
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Interactive configuration wizard for /subagents-setup.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The catalog is fixed: scout and artisan are always enabled. The menu lets the
|
|
5
|
+
* user pick a model and thinking level for each role — that is the entire
|
|
6
|
+
* configuration surface.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { stat } from "node:fs/promises";
|
|
10
10
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
11
11
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
12
|
-
import { discoverAgents } from "../delegation/agents.ts";
|
|
13
12
|
import {
|
|
14
13
|
AGENT_PROFILES,
|
|
15
14
|
BUILTIN_AGENT_NAMES,
|
|
16
15
|
DEFAULT_CONFIG,
|
|
17
|
-
DEFAULT_ENABLED_AGENTS,
|
|
18
16
|
agentProfile,
|
|
19
17
|
errorMessage,
|
|
20
18
|
getConfigPath,
|
|
@@ -35,7 +33,7 @@ import {
|
|
|
35
33
|
resolveThinkingLevel,
|
|
36
34
|
supportedThinkingLevels,
|
|
37
35
|
} from "./models.ts";
|
|
38
|
-
import {
|
|
36
|
+
import { promptSelectOne } from "./ui.ts";
|
|
39
37
|
|
|
40
38
|
const THINKING_LEVEL_HINTS: Record<ThinkingLevel, string> = {
|
|
41
39
|
off: "no reasoning tokens",
|
|
@@ -47,31 +45,6 @@ const THINKING_LEVEL_HINTS: Record<ThinkingLevel, string> = {
|
|
|
47
45
|
max: "strongest reasoning",
|
|
48
46
|
};
|
|
49
47
|
|
|
50
|
-
function setupAgentNames(ctx: ExtensionContext, config: SubagentsConfig): string[] {
|
|
51
|
-
const { agents } = discoverAgents(ctx.cwd, {
|
|
52
|
-
scope: config.agentScope,
|
|
53
|
-
projectTrusted: ctx.isProjectTrusted?.() === true,
|
|
54
|
-
});
|
|
55
|
-
const available = new Set(agents.map((agent) => agent.name));
|
|
56
|
-
return [...new Set([...BUILTIN_AGENT_NAMES, ...available])].filter((name) => available.has(name));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function agentPickerItems(names: readonly string[]): Array<{ value: string; label: string; description: string }> {
|
|
60
|
-
return names.map((name) => {
|
|
61
|
-
const profile = agentProfile(name);
|
|
62
|
-
return {
|
|
63
|
-
value: name,
|
|
64
|
-
label: profile ? name : `${name} (custom)`,
|
|
65
|
-
description: profile ? `${profile.summary} — ${profile.remark}` : "custom agent",
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function moduleLabel(name: string): string {
|
|
71
|
-
const profile = agentProfile(name);
|
|
72
|
-
return profile ? `${name} — ${profile.summary}` : `${name} (custom)`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
48
|
async function configExists(configPath: string): Promise<boolean> {
|
|
76
49
|
try {
|
|
77
50
|
await stat(configPath);
|
|
@@ -81,20 +54,6 @@ async function configExists(configPath: string): Promise<boolean> {
|
|
|
81
54
|
}
|
|
82
55
|
}
|
|
83
56
|
|
|
84
|
-
async function pickEnabledAgents(
|
|
85
|
-
ctx: ExtensionContext,
|
|
86
|
-
config: SubagentsConfig,
|
|
87
|
-
): Promise<string[] | undefined> {
|
|
88
|
-
const names = setupAgentNames(ctx, config);
|
|
89
|
-
return promptSelectMany(
|
|
90
|
-
ctx,
|
|
91
|
-
"Which roles should be available?",
|
|
92
|
-
"Each line is a role and its job. Space toggles • Enter confirms • Esc back",
|
|
93
|
-
agentPickerItems(names),
|
|
94
|
-
config.enabledAgents.filter((name) => names.includes(name)),
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
57
|
async function pickConfiguredModel(
|
|
99
58
|
ctx: ExtensionContext,
|
|
100
59
|
title: string,
|
|
@@ -120,7 +79,7 @@ async function pickAgentModel(
|
|
|
120
79
|
ctx: ExtensionContext,
|
|
121
80
|
agentName: string,
|
|
122
81
|
agentModels: Readonly<Record<string, string>>,
|
|
123
|
-
escNote = "
|
|
82
|
+
escNote = "returns to the role list",
|
|
124
83
|
): Promise<string | undefined> {
|
|
125
84
|
const profile = agentProfile(agentName);
|
|
126
85
|
const duty = profile ? ` — ${profile.summary}` : "";
|
|
@@ -149,7 +108,7 @@ async function pickAgentStrength(
|
|
|
149
108
|
agentName: string,
|
|
150
109
|
model: Model<Api> | undefined,
|
|
151
110
|
current: ThinkingLevel | undefined,
|
|
152
|
-
escNote = "
|
|
111
|
+
escNote = "returns to model selection",
|
|
153
112
|
): Promise<ThinkingLevel | undefined> {
|
|
154
113
|
const supported = supportedThinkingLevels(model);
|
|
155
114
|
const roleDefault = resolveThinkingLevel(model, roleThinkingLevel(agentName));
|
|
@@ -176,85 +135,67 @@ async function pickAgentStrength(
|
|
|
176
135
|
) as Promise<ThinkingLevel | undefined>;
|
|
177
136
|
}
|
|
178
137
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
"Name, then what it owns • ↑/↓ • Enter selects • Esc returns to settings",
|
|
191
|
-
enabledAgents.map((name) => {
|
|
192
|
-
const profile = agentProfile(name);
|
|
193
|
-
return {
|
|
194
|
-
value: name,
|
|
195
|
-
label: moduleLabel(name),
|
|
196
|
-
description: profile?.remark,
|
|
197
|
-
};
|
|
198
|
-
}),
|
|
199
|
-
);
|
|
138
|
+
function applyThinkingChoice(
|
|
139
|
+
levels: Record<string, ThinkingLevel>,
|
|
140
|
+
agentName: string,
|
|
141
|
+
strength: ThinkingLevel,
|
|
142
|
+
model: Model<Api> | undefined,
|
|
143
|
+
): Record<string, ThinkingLevel> {
|
|
144
|
+
const next = { ...levels };
|
|
145
|
+
const roleDefault = resolveThinkingLevel(model, roleThinkingLevel(agentName));
|
|
146
|
+
if (strength === roleDefault) delete next[agentName];
|
|
147
|
+
else next[agentName] = resolveThinkingLevel(model, strength);
|
|
148
|
+
return next;
|
|
200
149
|
}
|
|
201
150
|
|
|
202
|
-
interface
|
|
203
|
-
name: string;
|
|
151
|
+
interface RoleChoice {
|
|
204
152
|
model: string;
|
|
205
153
|
strength: ThinkingLevel;
|
|
206
154
|
}
|
|
207
155
|
|
|
208
|
-
|
|
156
|
+
/** Model then thinking for one fixed role. Esc on the model picker backs out to
|
|
157
|
+
* the menu; Esc on the thinking picker re-asks the model. */
|
|
158
|
+
async function configureOneRole(
|
|
209
159
|
ctx: ExtensionContext,
|
|
160
|
+
agentName: string,
|
|
210
161
|
config: SubagentsConfig,
|
|
211
|
-
): Promise<
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const enabled = available.filter((name) => config.enabledAgents.includes(name));
|
|
162
|
+
): Promise<RoleChoice | undefined> {
|
|
163
|
+
const profile = agentProfile(agentName);
|
|
164
|
+
if (profile) ctx.ui.notify(`${agentName}: ${profile.remark}`, "info");
|
|
215
165
|
while (true) {
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
);
|
|
228
|
-
if (modelChoice === undefined) break;
|
|
229
|
-
const model = effectiveModelForChoice(ctx, name, modelChoice, config.agentModels);
|
|
230
|
-
const strength = await pickAgentStrength(
|
|
231
|
-
ctx,
|
|
232
|
-
name,
|
|
233
|
-
model,
|
|
234
|
-
config.agentThinkingLevels[name],
|
|
235
|
-
"returns to model selection",
|
|
236
|
-
);
|
|
237
|
-
if (strength === undefined) continue;
|
|
238
|
-
return { name, model: modelChoice, strength };
|
|
239
|
-
}
|
|
166
|
+
const modelChoice = await pickAgentModel(ctx, agentName, config.agentModels);
|
|
167
|
+
if (modelChoice === undefined) return undefined;
|
|
168
|
+
const model = effectiveModelForChoice(ctx, agentName, modelChoice, config.agentModels);
|
|
169
|
+
const strength = await pickAgentStrength(
|
|
170
|
+
ctx,
|
|
171
|
+
agentName,
|
|
172
|
+
model,
|
|
173
|
+
config.agentThinkingLevels[agentName],
|
|
174
|
+
);
|
|
175
|
+
if (strength === undefined) continue;
|
|
176
|
+
return { model: modelChoice, strength };
|
|
240
177
|
}
|
|
241
178
|
}
|
|
242
179
|
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
function applyThinkingChoice(
|
|
249
|
-
levels: Record<string, ThinkingLevel>,
|
|
180
|
+
async function applyRoleChoice(
|
|
181
|
+
ctx: ExtensionContext,
|
|
182
|
+
configPath: string,
|
|
183
|
+
config: SubagentsConfig,
|
|
250
184
|
agentName: string,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
185
|
+
choice: RoleChoice,
|
|
186
|
+
): Promise<SubagentsConfig> {
|
|
187
|
+
const agentModels = applyAgentModelChoice({ ...config.agentModels }, agentName, choice.model);
|
|
188
|
+
const model = effectiveModelForChoice(ctx, agentName, choice.model, agentModels);
|
|
189
|
+
const next: SubagentsConfig = {
|
|
190
|
+
agentModels,
|
|
191
|
+
agentThinkingLevels: applyThinkingChoice(
|
|
192
|
+
{ ...config.agentThinkingLevels },
|
|
193
|
+
agentName,
|
|
194
|
+
choice.strength,
|
|
195
|
+
model,
|
|
196
|
+
),
|
|
197
|
+
};
|
|
198
|
+
await saveConfig(next, configPath);
|
|
258
199
|
return next;
|
|
259
200
|
}
|
|
260
201
|
|
|
@@ -274,15 +215,13 @@ async function introduceSetup(ctx: ExtensionContext): Promise<boolean> {
|
|
|
274
215
|
return choice !== undefined;
|
|
275
216
|
}
|
|
276
217
|
|
|
218
|
+
/** Walk both roles in order — model, then thinking — and save once at the end. */
|
|
277
219
|
async function runFullSetup(ctx: ExtensionContext, configPath: string, base: SubagentsConfig): Promise<boolean> {
|
|
278
220
|
if (!(await introduceSetup(ctx))) return false;
|
|
279
221
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
let agentModels = keepAgentEntries(base.agentModels, enabled);
|
|
284
|
-
let agentThinkingLevels = keepAgentEntries(base.agentThinkingLevels, enabled);
|
|
285
|
-
for (const agentName of enabled) {
|
|
222
|
+
let agentModels = { ...base.agentModels };
|
|
223
|
+
let agentThinkingLevels = { ...base.agentThinkingLevels };
|
|
224
|
+
for (const agentName of BUILTIN_AGENT_NAMES) {
|
|
286
225
|
const profile = agentProfile(agentName);
|
|
287
226
|
if (profile) ctx.ui.notify(`${agentName}: ${profile.remark}`, "info");
|
|
288
227
|
const choice = await pickAgentModel(ctx, agentName, agentModels);
|
|
@@ -296,74 +235,39 @@ async function runFullSetup(ctx: ExtensionContext, configPath: string, base: Sub
|
|
|
296
235
|
agentThinkingLevels = applyThinkingChoice(agentThinkingLevels, agentName, strength, model);
|
|
297
236
|
}
|
|
298
237
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
knownAgents: setupAgentNames(ctx, base),
|
|
302
|
-
agentModels,
|
|
303
|
-
agentThinkingLevels,
|
|
304
|
-
maxResultLines: base.maxResultLines,
|
|
305
|
-
maxConcurrentAgents: base.maxConcurrentAgents,
|
|
306
|
-
agentScope: base.agentScope,
|
|
307
|
-
idleTimeoutSec: base.idleTimeoutSec,
|
|
308
|
-
};
|
|
309
|
-
await saveConfig(next, configPath);
|
|
310
|
-
ctx.ui.notify(
|
|
311
|
-
`pi-subagents saved to ${configPath}. Models and thinking levels are set; open Configure an agent to change one.`,
|
|
312
|
-
"info",
|
|
313
|
-
);
|
|
238
|
+
await saveConfig({ agentModels, agentThinkingLevels }, configPath);
|
|
239
|
+
ctx.ui.notify(`pi-subagents saved to ${configPath}.`, "info");
|
|
314
240
|
return true;
|
|
315
241
|
}
|
|
316
242
|
|
|
243
|
+
function roleRow(name: string, config: SubagentsConfig): string {
|
|
244
|
+
const profile = AGENT_PROFILES[name as keyof typeof AGENT_PROFILES];
|
|
245
|
+
const model = config.agentModels[name] ?? "current main model";
|
|
246
|
+
const thinking = config.agentThinkingLevels[name] ?? roleThinkingLevel(name);
|
|
247
|
+
return `${name} — ${profile.summary} · model: ${model} · thinking: ${thinking}`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Menu: one row per fixed role showing its current route, plus a both-roles
|
|
251
|
+
* walk. Esc exits; saving happens after each change so a later Esc loses
|
|
252
|
+
* nothing. */
|
|
317
253
|
async function runMenu(ctx: ExtensionContext, configPath: string, config: SubagentsConfig): Promise<void> {
|
|
318
254
|
while (true) {
|
|
255
|
+
const rows = BUILTIN_AGENT_NAMES.map((name) => roleRow(name, config));
|
|
319
256
|
const choice = await ctx.ui.select("pi-subagents settings", [
|
|
320
|
-
|
|
321
|
-
"
|
|
322
|
-
"Full re-setup — pick each role's model and thinking again",
|
|
257
|
+
...rows,
|
|
258
|
+
"Both roles — walk model and thinking for each",
|
|
323
259
|
]);
|
|
324
260
|
if (choice === undefined) return;
|
|
325
|
-
if (choice.startsWith("
|
|
261
|
+
if (choice.startsWith("Both")) {
|
|
326
262
|
if (await runFullSetup(ctx, configPath, config)) return;
|
|
327
263
|
continue;
|
|
328
264
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
};
|
|
335
|
-
if (choice.startsWith("Enable")) {
|
|
336
|
-
const enabled = await pickEnabledAgents(ctx, config);
|
|
337
|
-
if (enabled === undefined) continue;
|
|
338
|
-
next.enabledAgents = enabled;
|
|
339
|
-
next.knownAgents = setupAgentNames(ctx, config);
|
|
340
|
-
next.agentModels = keepAgentEntries(next.agentModels, enabled);
|
|
341
|
-
next.agentThinkingLevels = keepAgentEntries(next.agentThinkingLevels, enabled);
|
|
342
|
-
} else {
|
|
343
|
-
let configuredAny = false;
|
|
344
|
-
while (true) {
|
|
345
|
-
const picked = await configureOneAgent(ctx, next);
|
|
346
|
-
if (!picked) break;
|
|
347
|
-
configuredAny = true;
|
|
348
|
-
next.agentModels = applyAgentModelChoice(next.agentModels, picked.name, picked.model);
|
|
349
|
-
const model = effectiveModelForChoice(ctx, picked.name, picked.model, next.agentModels);
|
|
350
|
-
next.agentThinkingLevels = applyThinkingChoice(
|
|
351
|
-
next.agentThinkingLevels,
|
|
352
|
-
picked.name,
|
|
353
|
-
picked.strength,
|
|
354
|
-
model,
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
if (!configuredAny) continue;
|
|
358
|
-
await saveConfig(next, configPath);
|
|
359
|
-
ctx.ui.notify(`pi-subagents updated. Saved to ${configPath}`, "info");
|
|
360
|
-
config = next;
|
|
361
|
-
continue;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
await saveConfig(next, configPath);
|
|
265
|
+
const agentName = BUILTIN_AGENT_NAMES.find((name) => choice.startsWith(name));
|
|
266
|
+
if (!agentName) continue;
|
|
267
|
+
const picked = await configureOneRole(ctx, agentName, config);
|
|
268
|
+
if (!picked) continue;
|
|
269
|
+
config = await applyRoleChoice(ctx, configPath, config, agentName, picked);
|
|
365
270
|
ctx.ui.notify(`pi-subagents updated. Saved to ${configPath}`, "info");
|
|
366
|
-
return;
|
|
367
271
|
}
|
|
368
272
|
}
|
|
369
273
|
|
|
@@ -377,7 +281,7 @@ export async function runSetup(ctx: ExtensionContext, configPath: string = getCo
|
|
|
377
281
|
const exists = await configExists(configPath);
|
|
378
282
|
const config = await loadConfig(configPath);
|
|
379
283
|
if (exists) await runMenu(ctx, configPath, config);
|
|
380
|
-
else if (!(await runFullSetup(ctx, configPath,
|
|
284
|
+
else if (!(await runFullSetup(ctx, configPath, DEFAULT_CONFIG))) {
|
|
381
285
|
ctx.ui.notify("pi-subagents setup cancelled.", "info");
|
|
382
286
|
}
|
|
383
287
|
} catch (error) {
|
package/src/configuration/ui.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TUI
|
|
2
|
+
* TUI picker for /subagents-setup, built on @earendil-works/pi-tui.
|
|
3
3
|
*
|
|
4
|
-
* A single self-contained `Picker` component powers
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - multi-select (module picker): same navigation, Space toggles a checkbox,
|
|
8
|
-
* Enter confirms the selection set.
|
|
4
|
+
* A single self-contained `Picker` component powers the model and thinking
|
|
5
|
+
* selectors: type to fuzzy-filter, arrows to move, PageUp/PageDown to page,
|
|
6
|
+
* Enter to choose, Esc to cancel.
|
|
9
7
|
*
|
|
10
8
|
* pi-tui's built-in SelectList only handles up/down/confirm/cancel (no paging),
|
|
11
9
|
* so we render the list ourselves and use the injected keybinding manager. Every line
|
|
@@ -38,8 +36,6 @@ interface PickerStyles {
|
|
|
38
36
|
selectedLabel: (t: string) => string;
|
|
39
37
|
label: (t: string) => string;
|
|
40
38
|
dim: (t: string) => string;
|
|
41
|
-
checked: (t: string) => string;
|
|
42
|
-
unchecked: (t: string) => string;
|
|
43
39
|
filterEcho: (t: string) => string;
|
|
44
40
|
}
|
|
45
41
|
|
|
@@ -50,10 +46,8 @@ function pickerItemSearchText(item: PickerItem): string {
|
|
|
50
46
|
}
|
|
51
47
|
|
|
52
48
|
interface PickerCallbacks {
|
|
53
|
-
/**
|
|
54
|
-
onSelect
|
|
55
|
-
/** multi-select: fired with the full chosen set on Enter. */
|
|
56
|
-
onConfirm?: (values: string[]) => void;
|
|
49
|
+
/** Fired with the highlighted value on Enter. */
|
|
50
|
+
onSelect: (value: string) => void;
|
|
57
51
|
onCancel: () => void;
|
|
58
52
|
}
|
|
59
53
|
|
|
@@ -62,18 +56,28 @@ class Picker implements Component, Focusable {
|
|
|
62
56
|
private query = "";
|
|
63
57
|
private cursor = 0;
|
|
64
58
|
private filtered: PickerItem[];
|
|
59
|
+
private readonly items: PickerItem[];
|
|
60
|
+
private readonly styles: PickerStyles;
|
|
61
|
+
private readonly headerLines: string[];
|
|
62
|
+
private readonly tui: TUI;
|
|
63
|
+
private readonly keybindings: KeybindingsManager;
|
|
64
|
+
private readonly cb: PickerCallbacks;
|
|
65
65
|
|
|
66
66
|
constructor(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
private readonly keybindings: KeybindingsManager,
|
|
74
|
-
private readonly cb: PickerCallbacks,
|
|
67
|
+
items: PickerItem[],
|
|
68
|
+
styles: PickerStyles,
|
|
69
|
+
headerLines: string[],
|
|
70
|
+
tui: TUI,
|
|
71
|
+
keybindings: KeybindingsManager,
|
|
72
|
+
cb: PickerCallbacks,
|
|
75
73
|
initialValue?: string,
|
|
76
74
|
) {
|
|
75
|
+
this.items = items;
|
|
76
|
+
this.styles = styles;
|
|
77
|
+
this.headerLines = headerLines;
|
|
78
|
+
this.tui = tui;
|
|
79
|
+
this.keybindings = keybindings;
|
|
80
|
+
this.cb = cb;
|
|
77
81
|
this.filtered = items;
|
|
78
82
|
const initialIndex = initialValue === undefined ? -1 : items.findIndex((item) => item.value === initialValue);
|
|
79
83
|
if (initialIndex >= 0) this.cursor = initialIndex;
|
|
@@ -116,10 +120,7 @@ class Picker implements Component, Focusable {
|
|
|
116
120
|
const mark = isCursor ? s.cursorMark("❯ ") : " ";
|
|
117
121
|
const label = isCursor ? s.selectedLabel(item.label) : s.label(item.label);
|
|
118
122
|
const description = item.description ? s.dim(` — ${item.description}`) : "";
|
|
119
|
-
|
|
120
|
-
? mark + (this.selected.has(item.value) ? s.checked("[x] ") : s.unchecked("[ ] ")) + label + description
|
|
121
|
-
: mark + label + description;
|
|
122
|
-
lines.push(fit(line));
|
|
123
|
+
lines.push(fit(mark + label + description));
|
|
123
124
|
}
|
|
124
125
|
const more = this.filtered.length > PAGE_SIZE ? " ↑/↓ move • PgUp/PgDn page" : "";
|
|
125
126
|
lines.push(fit(s.dim(` (${this.cursor + 1}/${this.filtered.length})${more}`)));
|
|
@@ -140,14 +141,8 @@ class Picker implements Component, Focusable {
|
|
|
140
141
|
} else if (kb.matches(data, "tui.select.pageDown")) {
|
|
141
142
|
this.cursor = Math.min(Math.max(0, this.filtered.length - 1), this.cursor + PAGE_SIZE);
|
|
142
143
|
} else if (kb.matches(data, "tui.select.confirm")) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// sequence and re-render it as the saved role order.
|
|
146
|
-
this.cb.onConfirm?.(this.items.filter((item) => this.selected.has(item.value)).map((item) => item.value));
|
|
147
|
-
} else {
|
|
148
|
-
const item = this.filtered[this.cursor];
|
|
149
|
-
if (item) this.cb.onSelect?.(item.value);
|
|
150
|
-
}
|
|
144
|
+
const item = this.filtered[this.cursor];
|
|
145
|
+
if (item) this.cb.onSelect(item.value);
|
|
151
146
|
return;
|
|
152
147
|
} else if (kb.matches(data, "tui.select.cancel")) {
|
|
153
148
|
this.cb.onCancel();
|
|
@@ -156,18 +151,6 @@ class Picker implements Component, Focusable {
|
|
|
156
151
|
this.query = this.query.slice(0, -1);
|
|
157
152
|
this.cursor = 0;
|
|
158
153
|
this.recompute();
|
|
159
|
-
} else if (data === " ") {
|
|
160
|
-
if (this.multi) {
|
|
161
|
-
const item = this.filtered[this.cursor];
|
|
162
|
-
if (item) {
|
|
163
|
-
if (this.selected.has(item.value)) this.selected.delete(item.value);
|
|
164
|
-
else this.selected.add(item.value);
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
this.query += data;
|
|
168
|
-
this.cursor = 0;
|
|
169
|
-
this.recompute();
|
|
170
|
-
}
|
|
171
154
|
} else if (isPrintable(data)) {
|
|
172
155
|
this.query += data;
|
|
173
156
|
this.cursor = 0;
|
|
@@ -195,8 +178,6 @@ function makeStyles(theme: Theme): PickerStyles {
|
|
|
195
178
|
selectedLabel: (t) => theme.fg("accent", theme.bold(t)),
|
|
196
179
|
label: (t) => t,
|
|
197
180
|
dim: (t) => theme.fg("dim", t),
|
|
198
|
-
checked: (t) => theme.fg("accent", t),
|
|
199
|
-
unchecked: (t) => theme.fg("dim", t),
|
|
200
181
|
filterEcho: (t) => theme.fg("accent", t),
|
|
201
182
|
};
|
|
202
183
|
}
|
|
@@ -221,28 +202,9 @@ export function promptSelectOne(
|
|
|
221
202
|
return ctx.ui.custom<string | undefined>((tui, theme, keybindings, done) => {
|
|
222
203
|
const styles = makeStyles(theme);
|
|
223
204
|
const header = [styles.title(title), styles.hint(hint)];
|
|
224
|
-
return new Picker(items,
|
|
205
|
+
return new Picker(items, styles, header, tui, keybindings, {
|
|
225
206
|
onSelect: (value) => done(value),
|
|
226
207
|
onCancel: () => done(undefined),
|
|
227
208
|
}, initialValue);
|
|
228
209
|
});
|
|
229
210
|
}
|
|
230
|
-
|
|
231
|
-
/** Multi-select with fuzzy filter + paging. Resolves undefined on Esc. */
|
|
232
|
-
export function promptSelectMany(
|
|
233
|
-
ctx: PickerContext,
|
|
234
|
-
title: string,
|
|
235
|
-
hint: string,
|
|
236
|
-
items: PickerItem[],
|
|
237
|
-
initialSelected: readonly string[],
|
|
238
|
-
): Promise<string[] | undefined> {
|
|
239
|
-
if (!requireTui(ctx)) return Promise.resolve(undefined);
|
|
240
|
-
return ctx.ui.custom<string[] | undefined>((tui, theme, keybindings, done) => {
|
|
241
|
-
const styles = makeStyles(theme);
|
|
242
|
-
const header = [styles.title(title), styles.hint(hint)];
|
|
243
|
-
return new Picker(items, true, new Set<string>(initialSelected), styles, header, tui, keybindings, {
|
|
244
|
-
onConfirm: (values) => done(values),
|
|
245
|
-
onCancel: () => done(undefined),
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
}
|