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