@lune_99/pi-subagent 0.0.0-stage → 0.2.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 +57 -0
- package/LICENSE +21 -0
- package/README.md +185 -2
- package/docs/capture.json +30 -0
- package/docs/previews.md +22 -0
- package/docs/reference.md +264 -0
- package/docs/subagent-auto-tiers.png +0 -0
- package/docs/subagent-inspector.png +0 -0
- package/docs/subagent-overview.png +0 -0
- package/package.json +82 -5
- package/skills/create-lune-subagent/SKILL.md +190 -0
- package/src/auto-model.ts +601 -0
- package/src/catalog.ts +111 -0
- package/src/definition-file.ts +147 -0
- package/src/definitions.ts +330 -0
- package/src/dock/dock-alert.ts +78 -0
- package/src/dock/dock-contribution.ts +328 -0
- package/src/extension-tools.ts +46 -0
- package/src/index.ts +194 -0
- package/src/inspector/details.ts +119 -0
- package/src/inspector/inspector.ts +677 -0
- package/src/inspector/layout.ts +119 -0
- package/src/inspector/transcript.ts +735 -0
- package/src/inspector/viewport.ts +62 -0
- package/src/inspector/wrap.ts +136 -0
- package/src/models.ts +69 -0
- package/src/notify/notification-box.ts +408 -0
- package/src/notify/notifier.ts +586 -0
- package/src/paths.ts +34 -0
- package/src/render/lune-theme.ts +68 -0
- package/src/render/text.ts +121 -0
- package/src/run/guide.ts +31 -0
- package/src/run/report-tool.ts +90 -0
- package/src/run/run-file.ts +194 -0
- package/src/run/run-manager.ts +935 -0
- package/src/run/run-session.ts +307 -0
- package/src/run/run.ts +773 -0
- package/src/run/session-start.ts +283 -0
- package/src/run/types.ts +175 -0
- package/src/run/worktree.ts +138 -0
- package/src/schema.ts +9 -0
- package/src/settings/agents-menu.ts +376 -0
- package/src/settings/panel.ts +221 -0
- package/src/settings/schema.ts +75 -0
- package/src/settings/thinking-choices.ts +92 -0
- package/src/tools/format.ts +397 -0
- package/src/tools/subagent-tools.ts +355 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
|
|
3
|
+
import { getAgentDir, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import {
|
|
5
|
+
createSettingsMenuField,
|
|
6
|
+
type SettingsChoice,
|
|
7
|
+
type SettingsChoiceSource,
|
|
8
|
+
type SettingsMenu,
|
|
9
|
+
type SettingsMenuDefinition,
|
|
10
|
+
type SettingsPanelField,
|
|
11
|
+
type SettingsPanelSchema,
|
|
12
|
+
} from "@lune_99/pi-lune-extensions-core/panel";
|
|
13
|
+
import type { DeepReadonly, SettingsScope } from "@lune_99/pi-lune-extensions-core/settings";
|
|
14
|
+
import Type from "typebox";
|
|
15
|
+
|
|
16
|
+
import type { ToolCatalog } from "../catalog.ts";
|
|
17
|
+
import { editDefinitionFile, type DefinitionField } from "../definition-file.ts";
|
|
18
|
+
import { loadDefinitions, type AgentDefinition, type LoadedDefinitions } from "../definitions.ts";
|
|
19
|
+
import { AUTO_MODEL, allowedModels, formatModelRef, type ModelRef } from "../models.ts";
|
|
20
|
+
import { definitionsDir, projectDefinitionsDir } from "../paths.ts";
|
|
21
|
+
import { REPORT_TOOL_NAME } from "../run/report-tool.ts";
|
|
22
|
+
import { ISOLATION_MODES, THINKING_LEVELS } from "../run/types.ts";
|
|
23
|
+
import type { SubagentSettings } from "./schema.ts";
|
|
24
|
+
import { defaultThinkingChoice, thinkingChoices } from "./thinking-choices.ts";
|
|
25
|
+
|
|
26
|
+
export interface AgentsMenuOptions {
|
|
27
|
+
/** The tools runs can select in the current session; undefined until it has started. */
|
|
28
|
+
catalog(): ToolCatalog | undefined;
|
|
29
|
+
/** After a file was written; `previousFile` differs from `edited.file` after a rename. */
|
|
30
|
+
onEdit(previousFile: string, edited: AgentDefinition): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The Custom agents menu: one entry per definition file of the viewed scope, global for the user
|
|
35
|
+
* folder and project for the project folder, and one page of fields per agent. Every field reads
|
|
36
|
+
* and writes the file itself, so the page always shows what the next session loads.
|
|
37
|
+
*/
|
|
38
|
+
export function agentsMenu(options: AgentsMenuOptions): SettingsMenuDefinition<SubagentSettings> {
|
|
39
|
+
// A renamed file keeps the entry ID it had, so its open page stays open.
|
|
40
|
+
const entryIds = new Map<string, string>();
|
|
41
|
+
const entryId = (file: string): string => entryIds.get(file) ?? file;
|
|
42
|
+
const edited = (previousFile: string, definition: AgentDefinition): void => {
|
|
43
|
+
if (definition.file !== previousFile) {
|
|
44
|
+
entryIds.set(definition.file, entryId(previousFile));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
options.onEdit(previousFile, definition);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
id: "agents",
|
|
52
|
+
label: "Custom agents",
|
|
53
|
+
description:
|
|
54
|
+
"Edit agent definition files: your user agents at global scope, this project's agents " +
|
|
55
|
+
"at project scope. Model, thinking, tools and isolation apply to the next run; names " +
|
|
56
|
+
"and descriptions apply after /reload.",
|
|
57
|
+
summary: ({ context, scope }) => {
|
|
58
|
+
// An untrusted project's folder is not read; the panel refuses its scope anyway.
|
|
59
|
+
if (scope === "project" && !context.isProjectTrusted()) {
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { definitions, problems } = loadScope(context, scope);
|
|
64
|
+
|
|
65
|
+
return [
|
|
66
|
+
count(definitions.length, scope === "global" ? "user agent" : "project agent"),
|
|
67
|
+
problems.length > 0 ? `${problems.length} not loaded` : "",
|
|
68
|
+
]
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
.join(" · ");
|
|
71
|
+
},
|
|
72
|
+
open: ({ context, scope, values }): SettingsMenu => {
|
|
73
|
+
const loaded = loadScope(context, scope);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
fields: [
|
|
77
|
+
...loaded.definitions.map((definition) =>
|
|
78
|
+
createSettingsMenuField({
|
|
79
|
+
id: entryId(definition.file),
|
|
80
|
+
label: definition.name,
|
|
81
|
+
description: definition.description,
|
|
82
|
+
scopes: [scope],
|
|
83
|
+
summary: () => agentSummary(definition, values),
|
|
84
|
+
menu: () => ({
|
|
85
|
+
fields: agentFields(
|
|
86
|
+
definition,
|
|
87
|
+
loaded,
|
|
88
|
+
scope,
|
|
89
|
+
options,
|
|
90
|
+
edited,
|
|
91
|
+
values,
|
|
92
|
+
),
|
|
93
|
+
}),
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
96
|
+
...loaded.problems.map((problem) =>
|
|
97
|
+
createSettingsMenuField({
|
|
98
|
+
id: `problem:${problem.file}`,
|
|
99
|
+
label: basename(problem.file),
|
|
100
|
+
description: problem.message,
|
|
101
|
+
scopes: [scope],
|
|
102
|
+
summary: () => "Not loaded",
|
|
103
|
+
disabled: () => "Fix the file by hand; it does not load.",
|
|
104
|
+
menu: () => ({ fields: [] }),
|
|
105
|
+
}),
|
|
106
|
+
),
|
|
107
|
+
],
|
|
108
|
+
emptyMessage:
|
|
109
|
+
`No ${scope === "global" ? "user" : "project"} agents in ` +
|
|
110
|
+
`${scopeDir(context, scope)}. The create-lune-subagent skill creates one.`,
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function scopeDir(context: ExtensionContext, scope: SettingsScope): string {
|
|
117
|
+
return scope === "global" ? definitionsDir(getAgentDir()) : projectDefinitionsDir(context.cwd);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function loadScope(context: ExtensionContext, scope: SettingsScope): LoadedDefinitions {
|
|
121
|
+
return loadDefinitions(scopeDir(context, scope), scope === "global" ? "user" : "project");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function agentSummary(definition: AgentDefinition, values: DeepReadonly<SubagentSettings>): string {
|
|
125
|
+
return [
|
|
126
|
+
definition.model ?? "main model",
|
|
127
|
+
definition.thinking ??
|
|
128
|
+
(definition.model === AUTO_MODEL && values.autoClassifier
|
|
129
|
+
? "automatic thinking"
|
|
130
|
+
: "main thinking"),
|
|
131
|
+
definition.tools ? count(definition.tools.length, "tool") : "default tools",
|
|
132
|
+
definition.isolation ?? "shared",
|
|
133
|
+
].join(" · ");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function agentFields(
|
|
137
|
+
definition: AgentDefinition,
|
|
138
|
+
loaded: LoadedDefinitions,
|
|
139
|
+
scope: SettingsScope,
|
|
140
|
+
options: AgentsMenuOptions,
|
|
141
|
+
edited: (previousFile: string, definition: AgentDefinition) => void,
|
|
142
|
+
values: DeepReadonly<SubagentSettings>,
|
|
143
|
+
): SettingsPanelField[] {
|
|
144
|
+
const field = <T>(spec: {
|
|
145
|
+
id: DefinitionField;
|
|
146
|
+
label: string;
|
|
147
|
+
description: string;
|
|
148
|
+
schema: SettingsPanelSchema;
|
|
149
|
+
editor: "text" | "select" | "cycle";
|
|
150
|
+
value: T | undefined;
|
|
151
|
+
required?: boolean;
|
|
152
|
+
choices?: readonly SettingsChoice<T | null>[];
|
|
153
|
+
choiceSource?: SettingsChoiceSource;
|
|
154
|
+
formatValue?: (value: T | null) => string;
|
|
155
|
+
}): SettingsPanelField => {
|
|
156
|
+
const write = (value: string | readonly string[] | undefined): Promise<void> => {
|
|
157
|
+
try {
|
|
158
|
+
edited(
|
|
159
|
+
definition.file,
|
|
160
|
+
editDefinitionFile(definition, spec.id, value, loaded.definitions),
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
return Promise.resolve();
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return Promise.reject(error instanceof Error ? error : new Error(String(error)));
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const value = spec.value ?? null;
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
id: spec.id,
|
|
172
|
+
label: spec.label,
|
|
173
|
+
description: spec.description,
|
|
174
|
+
schema: spec.schema,
|
|
175
|
+
editor: spec.editor,
|
|
176
|
+
scopes: [scope],
|
|
177
|
+
choices: spec.choices,
|
|
178
|
+
choiceSource: spec.choiceSource,
|
|
179
|
+
formatValue: spec.formatValue
|
|
180
|
+
? (shown) => spec.formatValue!(shown as T | null)
|
|
181
|
+
: undefined,
|
|
182
|
+
inspect: () => ({
|
|
183
|
+
defaultValue: null,
|
|
184
|
+
globalValue: scope === "global" && spec.value !== undefined ? value : undefined,
|
|
185
|
+
projectValue: scope === "project" && spec.value !== undefined ? value : undefined,
|
|
186
|
+
value,
|
|
187
|
+
source: spec.value === undefined ? "default" : scope,
|
|
188
|
+
}),
|
|
189
|
+
// null is the "leave it out" choice of the optional fields.
|
|
190
|
+
set: (next) => write(next === null ? undefined : (next as string | string[])),
|
|
191
|
+
reset: () =>
|
|
192
|
+
spec.required
|
|
193
|
+
? Promise.reject(
|
|
194
|
+
new Error(`${spec.label} is required; enter a new value instead.`),
|
|
195
|
+
)
|
|
196
|
+
: write(undefined),
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
const nullable = (schema: SettingsPanelSchema) =>
|
|
200
|
+
Type.Union([Type.Null(), schema]) as SettingsPanelSchema;
|
|
201
|
+
|
|
202
|
+
return [
|
|
203
|
+
field({
|
|
204
|
+
id: "name",
|
|
205
|
+
label: "Name",
|
|
206
|
+
description:
|
|
207
|
+
"Letters, digits, '.', '_' and '-'. A file named after the agent is renamed with " +
|
|
208
|
+
"it. The main agent sees the new name after /reload.",
|
|
209
|
+
schema: Type.String({ minLength: 1 }),
|
|
210
|
+
editor: "text",
|
|
211
|
+
value: definition.name,
|
|
212
|
+
required: true,
|
|
213
|
+
}),
|
|
214
|
+
field({
|
|
215
|
+
id: "description",
|
|
216
|
+
label: "Description",
|
|
217
|
+
description:
|
|
218
|
+
"When the main agent should choose this agent; one line in its subagents list. " +
|
|
219
|
+
"Applies after /reload.",
|
|
220
|
+
schema: Type.String({ minLength: 1 }),
|
|
221
|
+
editor: "text",
|
|
222
|
+
value: definition.description,
|
|
223
|
+
required: true,
|
|
224
|
+
}),
|
|
225
|
+
field<string>({
|
|
226
|
+
id: "model",
|
|
227
|
+
label: "Model",
|
|
228
|
+
description:
|
|
229
|
+
"A model of the subagent allowed set, auto to route both model and thinking per " +
|
|
230
|
+
"task, or the main agent's model. Selecting auto removes any saved thinking " +
|
|
231
|
+
"level. Ctrl+R removes the model field.",
|
|
232
|
+
schema: nullable(Type.String({ minLength: 1 })),
|
|
233
|
+
editor: "select",
|
|
234
|
+
value: definition.model,
|
|
235
|
+
choiceSource: modelChoices(definition.model, values.allowedModels),
|
|
236
|
+
formatValue: (value) => value ?? "Main agent's model",
|
|
237
|
+
}),
|
|
238
|
+
field<string>({
|
|
239
|
+
id: "thinking",
|
|
240
|
+
label: "Thinking",
|
|
241
|
+
description:
|
|
242
|
+
definition.model === AUTO_MODEL
|
|
243
|
+
? "Model auto selects thinking for each task. Fixed levels require a fixed " +
|
|
244
|
+
"or inherited model."
|
|
245
|
+
: "Choose a supported level for the model. Ctrl+R removes the field.",
|
|
246
|
+
schema: nullable(Type.Union(THINKING_LEVELS.map((level) => Type.Literal(level)))),
|
|
247
|
+
editor: "select",
|
|
248
|
+
value: definition.thinking,
|
|
249
|
+
choiceSource: thinkingChoices(definition.model, values, definition.thinking),
|
|
250
|
+
formatValue: (value) => value ?? defaultThinkingChoice(definition.model, values).label,
|
|
251
|
+
}),
|
|
252
|
+
field<string[]>({
|
|
253
|
+
id: "tools",
|
|
254
|
+
label: "Tools →",
|
|
255
|
+
description:
|
|
256
|
+
"Space toggles a tool. Unchecked everywhere means no task tools, only report. " +
|
|
257
|
+
"Ctrl+R removes the field, so runs get the defaultTools setting. MCP tools are " +
|
|
258
|
+
"not listed; keep them in the file by hand.",
|
|
259
|
+
schema: Type.Array(Type.String({ minLength: 1 }), {
|
|
260
|
+
uniqueItems: true,
|
|
261
|
+
}) as SettingsPanelSchema,
|
|
262
|
+
editor: "select",
|
|
263
|
+
value: definition.tools,
|
|
264
|
+
choiceSource: toolChoices(options, definition.tools),
|
|
265
|
+
formatValue: (value) =>
|
|
266
|
+
value === null
|
|
267
|
+
? "Default tools"
|
|
268
|
+
: value.length === 0
|
|
269
|
+
? "None · report only"
|
|
270
|
+
: `${value.length} selected`,
|
|
271
|
+
}),
|
|
272
|
+
field<string>({
|
|
273
|
+
id: "isolation",
|
|
274
|
+
label: "Isolation",
|
|
275
|
+
description:
|
|
276
|
+
"shared works in your directory; worktree gets its own Git worktree. Enter " +
|
|
277
|
+
"cycles; Ctrl+R removes the field.",
|
|
278
|
+
schema: nullable(Type.Union(ISOLATION_MODES.map((mode) => Type.Literal(mode)))),
|
|
279
|
+
editor: "cycle",
|
|
280
|
+
value: definition.isolation,
|
|
281
|
+
choices: [
|
|
282
|
+
{ value: null, label: "Default · shared" },
|
|
283
|
+
...ISOLATION_MODES.map((mode) => ({ value: mode, label: mode })),
|
|
284
|
+
],
|
|
285
|
+
}),
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function modelChoices(
|
|
290
|
+
current: string | undefined,
|
|
291
|
+
selection: readonly ModelRef[],
|
|
292
|
+
): SettingsChoiceSource<string | null> {
|
|
293
|
+
return {
|
|
294
|
+
rowLayout: "inline",
|
|
295
|
+
load: ({ context }) => {
|
|
296
|
+
const models = allowedModels(context, selection);
|
|
297
|
+
const refs = models.map((model) => formatModelRef(model));
|
|
298
|
+
|
|
299
|
+
return [
|
|
300
|
+
{
|
|
301
|
+
value: null,
|
|
302
|
+
label: "Main agent's model",
|
|
303
|
+
description: "Leave model out: runs use the main agent's model.",
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
value: AUTO_MODEL,
|
|
307
|
+
label: AUTO_MODEL,
|
|
308
|
+
description:
|
|
309
|
+
"The classifier in the Subagents settings chooses the model and thinking " +
|
|
310
|
+
"for each task. Selecting auto removes any saved thinking level.",
|
|
311
|
+
},
|
|
312
|
+
...models.map((model) => ({
|
|
313
|
+
value: formatModelRef(model),
|
|
314
|
+
label: model.id,
|
|
315
|
+
badge: model.provider,
|
|
316
|
+
searchText: `${formatModelRef(model)} ${model.name}`,
|
|
317
|
+
description: model.name,
|
|
318
|
+
})),
|
|
319
|
+
...(current !== undefined && current !== AUTO_MODEL && !refs.includes(current)
|
|
320
|
+
? [
|
|
321
|
+
{
|
|
322
|
+
value: current,
|
|
323
|
+
label: current,
|
|
324
|
+
badge: "Not allowed",
|
|
325
|
+
description:
|
|
326
|
+
"Not in the subagent allowed set now, so runs of this agent fail to start.",
|
|
327
|
+
},
|
|
328
|
+
]
|
|
329
|
+
: []),
|
|
330
|
+
];
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function toolChoices(
|
|
336
|
+
options: AgentsMenuOptions,
|
|
337
|
+
current: readonly string[] | undefined,
|
|
338
|
+
): SettingsChoiceSource<string> {
|
|
339
|
+
return {
|
|
340
|
+
multiple: true,
|
|
341
|
+
rowLayout: "inline",
|
|
342
|
+
load: () => {
|
|
343
|
+
const catalog = options.catalog();
|
|
344
|
+
|
|
345
|
+
if (!catalog) {
|
|
346
|
+
throw new Error("The tool list loads with the session; try again in a moment.");
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const tools = catalog.tools.filter((tool) => tool.name !== REPORT_TOOL_NAME);
|
|
350
|
+
const known = new Set(tools.map((tool) => tool.name));
|
|
351
|
+
|
|
352
|
+
return [
|
|
353
|
+
...tools.map((tool) => ({
|
|
354
|
+
value: tool.name,
|
|
355
|
+
label: tool.name,
|
|
356
|
+
badge: tool.source === "native" ? "Pi" : tool.source,
|
|
357
|
+
description: tool.description,
|
|
358
|
+
})),
|
|
359
|
+
...(current ?? [])
|
|
360
|
+
.filter((name) => !known.has(name))
|
|
361
|
+
.map((name) => ({
|
|
362
|
+
value: name,
|
|
363
|
+
label: name,
|
|
364
|
+
badge: name.startsWith("mcp__") ? "MCP" : "Unavailable",
|
|
365
|
+
description: name.startsWith("mcp__")
|
|
366
|
+
? "An MCP tool; its server connects in the run."
|
|
367
|
+
: "Not registered now. Runs of this agent fail to start until it is.",
|
|
368
|
+
})),
|
|
369
|
+
];
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function count(value: number, noun: string): string {
|
|
375
|
+
return `${value} ${noun}${value === 1 ? "" : "s"}`;
|
|
376
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineSettingsPanel,
|
|
3
|
+
modelChoices,
|
|
4
|
+
type ModelReference,
|
|
5
|
+
type SettingsChoiceSource,
|
|
6
|
+
} from "@lune_99/pi-lune-extensions-core/panel";
|
|
7
|
+
|
|
8
|
+
import { allowedModels, formatModelRef } from "../models.ts";
|
|
9
|
+
import { AUTO_TIERS, type AutoTier } from "../run/types.ts";
|
|
10
|
+
import { formatPercent } from "../tools/format.ts";
|
|
11
|
+
import { agentsMenu, type AgentsMenuOptions } from "./agents-menu.ts";
|
|
12
|
+
import { subagentSettings, type SubagentSettings } from "./schema.ts";
|
|
13
|
+
|
|
14
|
+
const classifierChoices: SettingsChoiceSource<ModelReference | null> = modelChoices({
|
|
15
|
+
type: "classifier",
|
|
16
|
+
specialChoices: (_context, classifiers) => [
|
|
17
|
+
{
|
|
18
|
+
value: null,
|
|
19
|
+
label: "None · main session model",
|
|
20
|
+
description: classifiers.length
|
|
21
|
+
? "Runs started with model auto use the main session's model and thinking."
|
|
22
|
+
: "No classifier is available. Configure a classifier provider in Pi with /login " +
|
|
23
|
+
"or its environment credentials, then press Ctrl+R to refresh.",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const allowedModelChoices = {
|
|
29
|
+
...modelChoices<"chat", ModelReference, SubagentSettings>({
|
|
30
|
+
scopes: ["scoped"],
|
|
31
|
+
emptyMessage: "No scoped models. Configure Pi's scoped models to select an override.",
|
|
32
|
+
specialChoices: ({ context, values }, models) => {
|
|
33
|
+
const scoped = new Set(models.map((model) => formatModelRef(model)));
|
|
34
|
+
const available = new Set(context.modelRegistry.getAvailable().map(formatModelRef));
|
|
35
|
+
|
|
36
|
+
return values.allowedModels
|
|
37
|
+
.filter((model) => !scoped.has(formatModelRef(model)))
|
|
38
|
+
.map((model) => ({
|
|
39
|
+
value: { provider: model.provider, id: model.id },
|
|
40
|
+
label: model.id,
|
|
41
|
+
badge: available.has(formatModelRef(model)) ? "Outside scope" : "Unavailable",
|
|
42
|
+
searchText: formatModelRef(model),
|
|
43
|
+
description: available.has(formatModelRef(model))
|
|
44
|
+
? `${formatModelRef(model)} remains allowed by this saved override. Uncheck to remove it.`
|
|
45
|
+
: `${formatModelRef(model)} is no longer available in Pi and cannot start a run. Uncheck to remove it.`,
|
|
46
|
+
}));
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
multiple: true as const,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const TIERS: Record<AutoTier, { label: string; description: string }> = {
|
|
53
|
+
light: {
|
|
54
|
+
label: "Light",
|
|
55
|
+
description: "Tasks that find, read or run something and report what it shows.",
|
|
56
|
+
},
|
|
57
|
+
standard: {
|
|
58
|
+
label: "Standard",
|
|
59
|
+
description: "Clear, well-specified changes and checks with a known path.",
|
|
60
|
+
},
|
|
61
|
+
complex: {
|
|
62
|
+
label: "Complex",
|
|
63
|
+
description: "Several steps across files or sources toward a clear goal.",
|
|
64
|
+
},
|
|
65
|
+
deep: {
|
|
66
|
+
label: "Deep",
|
|
67
|
+
description: "Design decisions, trade-offs, unclear failures and reviews for subtle bugs.",
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** The models runs may use, plus a selected one the scope no longer allows, so it can change. */
|
|
72
|
+
function tierChoices(
|
|
73
|
+
tier: AutoTier,
|
|
74
|
+
): SettingsChoiceSource<SubagentSettings["autoTiers"][AutoTier], SubagentSettings> {
|
|
75
|
+
return {
|
|
76
|
+
rowLayout: "inline",
|
|
77
|
+
load: ({ context, values }) => {
|
|
78
|
+
const models = allowedModels(context, values.allowedModels);
|
|
79
|
+
const allowed = new Set(models.map((model) => formatModelRef(model)));
|
|
80
|
+
const current = values.autoTiers[tier];
|
|
81
|
+
|
|
82
|
+
return [
|
|
83
|
+
{ value: null, label: "None", description: emptyTier(tier) },
|
|
84
|
+
...models.map((model) => ({
|
|
85
|
+
value: { provider: model.provider, id: model.id },
|
|
86
|
+
label: model.id,
|
|
87
|
+
badge: model.provider,
|
|
88
|
+
searchText: `${formatModelRef(model)} ${model.name}`,
|
|
89
|
+
description: model.name,
|
|
90
|
+
})),
|
|
91
|
+
...(current && !allowed.has(formatModelRef(current))
|
|
92
|
+
? [
|
|
93
|
+
{
|
|
94
|
+
value: { provider: current.provider, id: current.id },
|
|
95
|
+
label: current.id,
|
|
96
|
+
badge: "Not allowed",
|
|
97
|
+
description: `${formatModelRef(current)} is not in the subagent allowed set now, so auto runs of this tier fail to start. Select another model.`,
|
|
98
|
+
},
|
|
99
|
+
]
|
|
100
|
+
: []),
|
|
101
|
+
];
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function emptyTier(tier: AutoTier): string {
|
|
107
|
+
return tier === "deep"
|
|
108
|
+
? "These tasks use the main agent's model."
|
|
109
|
+
: "These tasks use the next tier up that has a model, else the main agent's model.";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function createSubagentPanel(options: AgentsMenuOptions) {
|
|
113
|
+
return defineSettingsPanel(subagentSettings, {
|
|
114
|
+
id: "subagents",
|
|
115
|
+
label: "Subagents",
|
|
116
|
+
fields: (field) => [
|
|
117
|
+
field("allowedModels", {
|
|
118
|
+
label: "Allowed models",
|
|
119
|
+
description:
|
|
120
|
+
"Select models from Pi's scoped models. A nonempty selection replaces the " +
|
|
121
|
+
"session's allowed model list for new subagent runs; clear it to follow Pi's " +
|
|
122
|
+
"scope again. Space toggles, Enter saves. Inheriting the main agent's model " +
|
|
123
|
+
"is unchanged, and existing runs keep their model.",
|
|
124
|
+
formatValue: (value) =>
|
|
125
|
+
value.length > 0 ? `${value.length} selected` : "Default · Pi's model scope",
|
|
126
|
+
choiceSource: allowedModelChoices,
|
|
127
|
+
}),
|
|
128
|
+
field("autoClassifier", {
|
|
129
|
+
label: "Classifier model",
|
|
130
|
+
description:
|
|
131
|
+
"The Pi classifier that rates each task of a run started with model auto and " +
|
|
132
|
+
"picks both the model and thinking level. None: auto runs use the main " +
|
|
133
|
+
"session's model and thinking.",
|
|
134
|
+
formatValue: (value) =>
|
|
135
|
+
value ? `${value.provider}/${value.id}` : "None · main session model",
|
|
136
|
+
choiceSource: classifierChoices,
|
|
137
|
+
}),
|
|
138
|
+
field("autoOnly", {
|
|
139
|
+
label: "Auto mode only",
|
|
140
|
+
description:
|
|
141
|
+
"Inline runs always route both model and thinking: subagent_start has no " +
|
|
142
|
+
"model or thinking parameters, and explicit overrides fail. Custom agents " +
|
|
143
|
+
"keep their definition's model. Changes apply to the next start.",
|
|
144
|
+
}),
|
|
145
|
+
...AUTO_TIERS.map((tier) =>
|
|
146
|
+
field(["autoTiers", tier], {
|
|
147
|
+
label: TIERS[tier].label,
|
|
148
|
+
description: `${TIERS[tier].description} Without a model: ${emptyTier(tier)}`,
|
|
149
|
+
inMenu: "tiers",
|
|
150
|
+
formatValue: (value) =>
|
|
151
|
+
value
|
|
152
|
+
? `${value.provider}/${value.id}`
|
|
153
|
+
: tier === "deep"
|
|
154
|
+
? "None · main agent's model"
|
|
155
|
+
: "None · next tier up",
|
|
156
|
+
choiceSource: tierChoices(tier),
|
|
157
|
+
}),
|
|
158
|
+
),
|
|
159
|
+
field("autoRiskFloor", {
|
|
160
|
+
label: "High-risk floor",
|
|
161
|
+
description:
|
|
162
|
+
"The lowest tier whose model a high-risk task may use. A task is high risk " +
|
|
163
|
+
"when a mistake in it could seriously harm security, privacy, data, money or " +
|
|
164
|
+
"production. The rated tier stays as it is; only the model rises. This is a " +
|
|
165
|
+
"model choice only: it changes no tool permission or approval.",
|
|
166
|
+
inMenu: "tiers",
|
|
167
|
+
choices: [
|
|
168
|
+
{
|
|
169
|
+
value: "off",
|
|
170
|
+
label: "Off",
|
|
171
|
+
description: "High-risk tasks use the model of their rated tier.",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
value: "standard",
|
|
175
|
+
label: "Standard",
|
|
176
|
+
description: "High-risk tasks use at least the Standard model.",
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
value: "complex",
|
|
180
|
+
label: "Complex",
|
|
181
|
+
description: "High-risk tasks use at least the Complex model.",
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
value: "deep",
|
|
185
|
+
label: "Deep",
|
|
186
|
+
description:
|
|
187
|
+
"High-risk tasks use the Deep model, else the main agent's model.",
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
}),
|
|
191
|
+
field("autoRiskThreshold", {
|
|
192
|
+
label: "High-risk threshold",
|
|
193
|
+
description:
|
|
194
|
+
"The classifier's probability, from 0 to 1, from which a task counts as high " +
|
|
195
|
+
"risk. A missed high-risk task usually costs more than a false alarm, so the " +
|
|
196
|
+
"default 0.4 is below one half. Adjust it with your own tasks.",
|
|
197
|
+
inMenu: "tiers",
|
|
198
|
+
formatValue: (value) => formatPercent(value),
|
|
199
|
+
}),
|
|
200
|
+
],
|
|
201
|
+
menus: [
|
|
202
|
+
{
|
|
203
|
+
id: "tiers",
|
|
204
|
+
label: "Auto tiers",
|
|
205
|
+
description:
|
|
206
|
+
"The model for each task tier of runs started with model auto, from the " +
|
|
207
|
+
"subagent allowed set. A tier without a model uses the next tier up that has one, " +
|
|
208
|
+
"and the main agent's model is the last step. The high-risk floor raises the " +
|
|
209
|
+
"model of tasks rated high risk.",
|
|
210
|
+
summary: ({ values }) => {
|
|
211
|
+
const set = AUTO_TIERS.filter((tier) => values.autoTiers[tier]).length;
|
|
212
|
+
|
|
213
|
+
return set === 0
|
|
214
|
+
? "none set · main agent's model"
|
|
215
|
+
: `${set} of ${AUTO_TIERS.length} set`;
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
agentsMenu(options),
|
|
219
|
+
],
|
|
220
|
+
});
|
|
221
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { defineSettings, type DeepReadonly } from "@lune_99/pi-lune-extensions-core/settings";
|
|
2
|
+
import Type, { type Static } from "typebox";
|
|
3
|
+
|
|
4
|
+
import { DEFAULT_AUTO_MODEL_SETTINGS, type AutoModelSettings } from "../auto-model.ts";
|
|
5
|
+
import { AUTO_TIERS } from "../run/types.ts";
|
|
6
|
+
|
|
7
|
+
const modelReference = () =>
|
|
8
|
+
Type.Object(
|
|
9
|
+
{ provider: Type.String({ minLength: 1 }), id: Type.String({ minLength: 1 }) },
|
|
10
|
+
{ additionalProperties: false },
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const tierModel = () => Type.Union([Type.Null(), modelReference()], { default: null });
|
|
14
|
+
|
|
15
|
+
export const subagentSchema = Type.Object(
|
|
16
|
+
{
|
|
17
|
+
allowedModels: Type.Array(modelReference(), { default: [], uniqueItems: true }),
|
|
18
|
+
autoOnly: Type.Boolean({ default: false }),
|
|
19
|
+
autoClassifier: Type.Union([Type.Null(), modelReference()], { default: null }),
|
|
20
|
+
autoTiers: Type.Object(
|
|
21
|
+
{ light: tierModel(), standard: tierModel(), complex: tierModel(), deep: tierModel() },
|
|
22
|
+
{
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
default: { light: null, standard: null, complex: null, deep: null },
|
|
25
|
+
},
|
|
26
|
+
),
|
|
27
|
+
autoRiskFloor: Type.Union(
|
|
28
|
+
[
|
|
29
|
+
Type.Literal("off"),
|
|
30
|
+
Type.Literal("standard"),
|
|
31
|
+
Type.Literal("complex"),
|
|
32
|
+
Type.Literal("deep"),
|
|
33
|
+
],
|
|
34
|
+
{ default: DEFAULT_AUTO_MODEL_SETTINGS.riskFloor ?? "off" },
|
|
35
|
+
),
|
|
36
|
+
autoRiskThreshold: Type.Number({
|
|
37
|
+
minimum: 0,
|
|
38
|
+
maximum: 1,
|
|
39
|
+
default: DEFAULT_AUTO_MODEL_SETTINGS.riskThreshold,
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
{ additionalProperties: false },
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export type SubagentSettings = Static<typeof subagentSchema>;
|
|
46
|
+
|
|
47
|
+
export const subagentSettings = defineSettings({
|
|
48
|
+
id: "pi-subagent",
|
|
49
|
+
schema: subagentSchema,
|
|
50
|
+
migrations: [
|
|
51
|
+
// 1 → 2: one model per task tier replaced the list of candidate models.
|
|
52
|
+
(overrides) => {
|
|
53
|
+
delete overrides.autoModels;
|
|
54
|
+
|
|
55
|
+
return overrides;
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export function autoModelSettings(
|
|
61
|
+
settings: DeepReadonly<Omit<SubagentSettings, "allowedModels" | "autoOnly">>,
|
|
62
|
+
): AutoModelSettings {
|
|
63
|
+
return {
|
|
64
|
+
classifier: settings.autoClassifier ? { ...settings.autoClassifier } : null,
|
|
65
|
+
tiers: Object.fromEntries(
|
|
66
|
+
AUTO_TIERS.map((tier) => {
|
|
67
|
+
const model = settings.autoTiers[tier];
|
|
68
|
+
|
|
69
|
+
return [tier, model ? { ...model } : null];
|
|
70
|
+
}),
|
|
71
|
+
) as AutoModelSettings["tiers"],
|
|
72
|
+
riskFloor: settings.autoRiskFloor === "off" ? null : settings.autoRiskFloor,
|
|
73
|
+
riskThreshold: settings.autoRiskThreshold,
|
|
74
|
+
};
|
|
75
|
+
}
|