@ferris1225/pi-subagents 7.0.0 → 7.0.1

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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.0.1
4
+
5
+ ### Breaking changes
6
+
7
+ - Rename `scout` to `researcher` and `artisan` to `worker`, without aliases.
8
+ - Overwrite old settings with configuration version 2. Researcher and Worker
9
+ each have an independent model and thinking preference; neither is migrated.
10
+ - Remove provider aliases, older Pi API shims, opaque-prompt fallback, recovery
11
+ path migration, synthesized record identities, and legacy steering receipts.
12
+ Unsupported recovery files remain untouched and prevent automated cleanup.
13
+
14
+ ### Fixes and changes
15
+
16
+ - Restore model selection for each role throughout setup, dispatch, and live
17
+ orchestration. An unavailable model blocks only its assigned role.
18
+ - Redesign setup into Researcher and Worker sections with visible Model,
19
+ Thinking, and role-specific Reset controls. Preserve search, paging, focus,
20
+ Unicode input, and a compact layout for narrow terminals.
21
+ - Keep config replacement atomic and recovery ownership checks intact.
22
+ - Keep automatic releases on patch increments, including three-digit patch
23
+ numbers such as `7.0.100`.
24
+
3
25
  ## 7.0.0
4
26
 
5
27
  ### Breaking changes
package/README.md CHANGED
@@ -17,20 +17,23 @@ integration tests use the **Pi 1.5.2 SDK**.
17
17
  ```
18
18
 
19
19
  2. Choose a capable main model with Pi's model selector; it always owns review.
20
- 3. Run `/subagents-setup` and select a capable, cost-effective worker model.
20
+ 3. Run `/subagents-setup` and choose models for **Researcher** and **Worker**.
21
21
  4. Give main your task. Orchestration is the default and only workflow.
22
22
 
23
- The setup panel has three rows: **Model**, **Thinking**, and **Reset**.
23
+ The setup panel has two sections: **Researcher** for read-only research and
24
+ **Worker** for implementation and checks. Each has its own **Model**, **Thinking**,
25
+ and **Reset** controls. Both assignments stay visible together.
24
26
  Use ↑/↓ and Enter; Esc returns without changing a picker selection. Changes save
25
27
  immediately. The model picker supports search, paste, paging, and Tab for details.
26
- The menu keeps the current main model visible. Long values can be paged with
27
- PgUp/PgDn, and the panel adapts to narrow terminals.
28
+ The menu keeps the current main model visible, highlights unavailable assignments,
29
+ and returns focus to the setting you just edited. Long values can be paged with
30
+ PgUp/PgDn, and narrow terminals use a compact list with the role on each row.
28
31
 
29
32
  Workers initially **follow main** with **medium** thinking. Choose a separate
30
33
  worker model to use a cheaper model for execution. The extension does not guess
31
34
  model quality or promise savings from token prices. A saved thinking preference
32
35
  survives model changes and is clamped to the chosen model's supported levels.
33
- Reset restores Follow main and medium thinking.
36
+ Reset restores Follow main and medium thinking for that role only.
34
37
 
35
38
  The goal is to reduce expensive main-model usage, budget, and quota consumption.
36
39
  Total tokens can increase because briefs, separate contexts, and review also cost
@@ -38,33 +41,36 @@ tokens. Judge savings by total task cost and main-model usage, including retries
38
41
  and rework. Compact handoffs, retained worker sessions, reuse of valid checks, and
39
42
  delegating execution are the mechanisms; no savings benchmark is claimed here.
40
43
 
41
- ## Upgrading to v7
44
+ ## Configuration and upgrading to 7.0.1
42
45
 
43
- **This is a breaking release.** On the first session start after upgrading, the
44
- old `pi-subagents.json` is deleted and replaced with fresh worker settings.
45
- Old per-role model/thinking values are discarded, with no legacy config backup.
46
+ **This update resets settings and renames roles.** On the first session start after upgrading, the
47
+ old `pi-subagents.json` is atomically overwritten with fresh, independent role settings.
48
+ Previous model/thinking values are discarded, with no migration or config backup.
46
49
  Pi displays a notice directing you to `/subagents-setup`.
47
50
 
48
- The old role matrix, optional delegation policy, independent reviewer, and
49
- `sentinel` role are gone. Main performs review. Calls naming retired roles
50
- are rejected.
51
+ The role names are now `researcher` and `worker`; previous names are rejected.
52
+ Main continues to own planning and review. There are no role or provider aliases,
53
+ old SDK shims, or recovery-path migrations. Model references must exactly match
54
+ the available registry entry.
51
55
 
52
56
  Only the settings file is reset. Existing sessions, results, worktrees, and
53
- recovery evidence remain protected. Retired-role records can still be inspected
54
- or stopped; they do not create a supported reviewer role or resume automatically.
57
+ recovery evidence remain protected. Unsupported recovery manifests are left
58
+ untouched and block automated cleanup; they are not converted or resumed.
55
59
 
56
60
  The new configuration is stored at `~/.pi/agent/pi-subagents.json`:
57
61
 
58
62
  ```json
59
63
  {
60
- "version": 1,
61
- "thinking": "medium"
64
+ "version": 2,
65
+ "researcher": { "thinking": "medium" },
66
+ "worker": { "thinking": "medium" }
62
67
  }
63
68
  ```
64
69
 
65
- Selecting a worker adds `model: "provider/model-id"`. This is one shared worker
66
- setting, not a map of roles. `PI_CODING_AGENT_DIR` overrides the agent directory.
67
- An unavailable or out-of-scope worker stays configured and blocks dispatch until
70
+ Selecting a model adds `model: "provider/model-id"` inside that role's object.
71
+ Each role's model and thinking are saved independently.
72
+ `PI_CODING_AGENT_DIR` overrides the agent directory.
73
+ An unavailable or out-of-scope model stays configured and blocks only its role until
68
74
  availability is restored or you select another model. Provider failures return
69
75
  to main with evidence; the extension never starts a main-model worker as a retry.
70
76
  Unreadable settings or an invalid model reference also stop new dispatches instead
@@ -94,12 +100,12 @@ reviewer. Main avoids repeating completed worker effort. Questions and review-on
94
100
  implementation. Explicit requests to work in main take precedence. Parallel workers require independent
95
101
  scope and disjoint write ownership; a fix and its regression tests share an owner.
96
102
 
97
- There are two worker tool scopes, both using the same model/thinking settings:
103
+ There are two roles, each using its own model/thinking settings:
98
104
 
99
105
  | Scope | Tool parameter | Access |
100
106
  | --- | --- | --- |
101
- | Implementation | `artisan` | Parent's live tools, including codemode; implements and checks the plan |
102
- | Read-only research | `scout` | Proven read-only lookups; no commands, builds, tests, or edits |
107
+ | Implementation | `worker` | Parent's live tools, including codemode; implements and checks the plan |
108
+ | Read-only research | `researcher` | Proven read-only lookups; no commands, builds, tests, or edits |
103
109
 
104
110
  The read-only scope preserves a tool boundary for research. It is not a separate
105
111
  reviewer. Children cannot delegate or release. Main and workers exchange briefs,
@@ -118,7 +124,7 @@ result**. Pass established facts forward and assign only missing work.
118
124
 
119
125
  ```ts
120
126
  subagent({
121
- agent: "artisan",
127
+ agent: "worker",
122
128
  task: [
123
129
  "Fix cache invalidation in src/cache.ts and its regression test.",
124
130
  "Acceptance: a write invalidates the matching key without clearing unrelated keys.",
@@ -185,7 +191,7 @@ integration into the original checkout is serialized.
185
191
 
186
192
  Workers run the native Pi CLI in RPC mode with piped I/O and retained sessions.
187
193
  Delegation/control tools are model-only: call them directly, outside codemode.
188
- Workers inherit reachable tools without activating unrelated direct tools; scout
194
+ Workers inherit reachable tools without activating unrelated direct tools; researcher
189
195
  gets only tools whose metadata proves them read-only.
190
196
 
191
197
  Unattended confirmation/input dialogs are cancelled, never auto-approved. Windows
package/index.ts CHANGED
@@ -25,7 +25,7 @@ import { errorMessage, getConfigPath, loadConfig } from "./src/configuration/con
25
25
  import { runSetup } from "./src/configuration/setup.ts";
26
26
  import { loadBuiltinAgents } from "./src/delegation/agents.ts";
27
27
  import { registerSubagentTool } from "./src/delegation/dispatch.ts";
28
- import { buildDelegationDirective, installDelegationSections } from "./src/delegation/prompt.ts";
28
+ import { installDelegationSections } from "./src/delegation/prompt.ts";
29
29
  import { buildOrchestrationSection } from "./src/delegation/orchestration.ts";
30
30
  import { currentSubagentDepth, getSubagentsRoot } from "./src/execution/spawn.ts";
31
31
  import { createDispatchCore } from "./src/lifecycle/dispatch-core.ts";
@@ -74,7 +74,7 @@ export default function (pi: ExtensionAPI): void {
74
74
  registerCancellationHooks(pi, runtime);
75
75
 
76
76
  pi.registerCommand("subagents-setup", {
77
- description: "Configure the worker model and thinking level",
77
+ description: "Configure Researcher and Worker models and thinking levels",
78
78
  handler: async (_args, ctx) => {
79
79
  await runSetup(ctx, configPath);
80
80
  },
@@ -111,7 +111,7 @@ export default function (pi: ExtensionAPI): void {
111
111
  });
112
112
  registerAnnouncements(pi, runtime);
113
113
 
114
- // Install the routing contract as prompt sections when the host can diff them.
114
+ // Install the routing contract as replaceable prompt sections.
115
115
  // A full systemPrompt return forces an opaque prompt and invalidates the cache.
116
116
  pi.on("before_agent_start", async (event, ctx) => {
117
117
  await runtime.durableRestore;
@@ -124,13 +124,6 @@ export default function (pi: ExtensionAPI): void {
124
124
  orchestration = "Worker dispatch is paused because settings could not be loaded: " + errorMessage(error)
125
125
  + " Repair the settings or run /subagents-setup. Do not substitute main-model workers.";
126
126
  }
127
- const sections = event.systemPromptOptions?.sections;
128
- if (sections) {
129
- installDelegationSections(sections, agents, sources, orchestration);
130
- return undefined;
131
- }
132
- const directive = buildDelegationDirective(agents, sources, orchestration);
133
- if (!directive) return undefined;
134
- return { systemPrompt: `${event.systemPrompt}\n${directive}` };
127
+ installDelegationSections(event.systemPromptOptions.sections, agents, sources, orchestration);
135
128
  });
136
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ferris1225/pi-subagents",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Lead/worker orchestration for Pi: main plans and reviews, configurable workers execute with retained sessions and Git worktree isolation.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,27 +1,31 @@
1
- /** Versioned worker settings. Legacy role configurations are replaced, never migrated. */
1
+ /** Independent role settings. Unsupported configuration is replaced with defaults. */
2
2
 
3
3
  import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
4
4
  import { dirname, join } from "node:path";
5
5
  import { getAgentDir, withFileMutationQueue } from "@earendil-works/pi-coding-agent";
6
6
 
7
- export const CONFIG_VERSION = 1;
8
- export const BUILTIN_AGENT_NAMES = ["scout", "artisan"] as const;
7
+ export const CONFIG_VERSION = 2;
8
+ export const BUILTIN_AGENT_NAMES = ["researcher", "worker"] as const;
9
+ export type AgentName = (typeof BUILTIN_AGENT_NAMES)[number];
9
10
  const THINKING_LEVEL_VALUES = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
10
11
  export type ThinkingLevel = (typeof THINKING_LEVEL_VALUES)[number];
11
12
  export const DEFAULT_THINKING_LEVEL: ThinkingLevel = "medium";
12
13
  export const DEFAULT_MAX_RESULT_LINES = 40;
13
14
  export const DEFAULT_IDLE_TIMEOUT_SEC = 1800;
14
15
 
15
- export interface SubagentsConfig {
16
- version: typeof CONFIG_VERSION;
17
- /** One worker model for both implementation and read-only research. Missing follows main. */
16
+ export interface AgentSettings {
17
+ /** Missing follows the main model. */
18
18
  model?: string;
19
19
  thinking: ThinkingLevel;
20
20
  }
21
21
 
22
+ export type SubagentsConfig = { version: typeof CONFIG_VERSION } & Record<AgentName, AgentSettings>;
23
+
24
+ export const DEFAULT_AGENT_SETTINGS: Readonly<AgentSettings> = Object.freeze({ thinking: DEFAULT_THINKING_LEVEL });
22
25
  export const DEFAULT_CONFIG: Readonly<SubagentsConfig> = {
23
26
  version: CONFIG_VERSION,
24
- thinking: DEFAULT_THINKING_LEVEL,
27
+ researcher: DEFAULT_AGENT_SETTINGS,
28
+ worker: DEFAULT_AGENT_SETTINGS,
25
29
  };
26
30
 
27
31
  export function getConfigPath(agentDir: string = getAgentDir()): string {
@@ -30,19 +34,26 @@ export function getConfigPath(agentDir: string = getAgentDir()): string {
30
34
 
31
35
  function isCurrentConfig(raw: unknown): raw is Record<string, unknown> {
32
36
  return typeof raw === "object" && raw !== null && !Array.isArray(raw)
33
- && (raw as Record<string, unknown>).version === CONFIG_VERSION;
37
+ && (raw as Record<string, unknown>).version === CONFIG_VERSION
38
+ && BUILTIN_AGENT_NAMES.every((role) => {
39
+ const settings = (raw as Record<string, unknown>)[role];
40
+ return typeof settings === "object" && settings !== null && !Array.isArray(settings);
41
+ });
34
42
  }
35
43
 
36
44
  export function normalizeConfig(raw: unknown): SubagentsConfig {
37
- const config: SubagentsConfig = { ...DEFAULT_CONFIG };
45
+ const config: SubagentsConfig = { version: CONFIG_VERSION, researcher: { ...DEFAULT_AGENT_SETTINGS }, worker: { ...DEFAULT_AGENT_SETTINGS } };
38
46
  if (!isCurrentConfig(raw)) return config;
39
- if (typeof raw.model === "string") {
40
- const model = raw.model.trim();
41
- const slash = model.indexOf("/");
42
- if (slash > 0 && slash < model.length - 1 && !/\s/u.test(model)) config.model = model;
43
- }
44
- if (typeof raw.thinking === "string" && (THINKING_LEVEL_VALUES as readonly string[]).includes(raw.thinking)) {
45
- config.thinking = raw.thinking as ThinkingLevel;
47
+ for (const role of BUILTIN_AGENT_NAMES) {
48
+ const settings = raw[role] as Record<string, unknown>;
49
+ if (typeof settings.model === "string") {
50
+ const model = settings.model.trim();
51
+ const slash = model.indexOf("/");
52
+ if (slash > 0 && slash < model.length - 1 && !/\s/u.test(model)) config[role].model = model;
53
+ }
54
+ if (typeof settings.thinking === "string" && (THINKING_LEVEL_VALUES as readonly string[]).includes(settings.thinking)) {
55
+ config[role].thinking = settings.thinking as ThinkingLevel;
56
+ }
46
57
  }
47
58
  return config;
48
59
  }
@@ -62,13 +73,12 @@ async function readStoredConfig(configPath: string): Promise<{ exists: boolean;
62
73
  }
63
74
  }
64
75
 
65
- /** Prepare the replacement before removing a legacy file. Callers own the mutation queue. */
66
- async function writeConfig(config: SubagentsConfig, configPath: string, removeLegacy = false): Promise<void> {
76
+ /** Replace settings atomically. Callers own the mutation queue. */
77
+ async function writeConfig(config: SubagentsConfig, configPath: string): Promise<void> {
67
78
  await mkdir(dirname(configPath), { recursive: true });
68
79
  const temporaryPath = configPath + "." + process.pid + "." + Date.now() + ".tmp";
69
80
  try {
70
81
  await writeFile(temporaryPath, JSON.stringify(config, null, 2) + "\n", "utf8");
71
- if (removeLegacy) await rm(configPath, { force: true });
72
82
  await rename(temporaryPath, configPath);
73
83
  } finally {
74
84
  await rm(temporaryPath, { force: true }).catch(() => undefined);
@@ -79,8 +89,10 @@ async function writeConfig(config: SubagentsConfig, configPath: string, removeLe
79
89
  export async function initializeConfig(configPath: string = getConfigPath()): Promise<"created" | "reset" | undefined> {
80
90
  return withFileMutationQueue(configPath, async () => {
81
91
  const stored = await readStoredConfig(configPath);
82
- if (isCurrentConfig(stored.raw) && (stored.raw.model === undefined || normalizeConfig(stored.raw).model)) return undefined;
83
- await writeConfig({ ...DEFAULT_CONFIG }, configPath, stored.exists);
92
+ const raw = stored.raw;
93
+ if (isCurrentConfig(raw) && BUILTIN_AGENT_NAMES.every((role) =>
94
+ (raw[role] as Record<string, unknown>).model === undefined || normalizeConfig(raw)[role].model)) return undefined;
95
+ await writeConfig(normalizeConfig(undefined), configPath);
84
96
  return stored.exists ? "reset" : "created";
85
97
  });
86
98
  }
@@ -88,13 +100,15 @@ export async function initializeConfig(configPath: string = getConfigPath()): Pr
88
100
  /** Dispatch reads are side-effect free; startup owns initialization and its user notice. */
89
101
  export async function loadConfig(configPath: string = getConfigPath()): Promise<SubagentsConfig> {
90
102
  const stored = await readStoredConfig(configPath);
91
- if (!stored.exists) return { ...DEFAULT_CONFIG };
103
+ if (!stored.exists) return normalizeConfig(undefined);
92
104
  if (!isCurrentConfig(stored.raw)) {
93
- throw new Error("Worker settings are invalid or incompatible. Run /subagents-setup to initialize the new configuration.");
105
+ throw new Error("Subagent settings are invalid or unsupported. Run /subagents-setup to initialize the current configuration.");
94
106
  }
95
107
  const config = normalizeConfig(stored.raw);
96
- if (stored.raw.model !== undefined && !config.model) {
97
- throw new Error("Invalid worker model reference. Use provider/model-id or remove model to explicitly follow main.");
108
+ for (const role of BUILTIN_AGENT_NAMES) {
109
+ if ((stored.raw[role] as Record<string, unknown>).model !== undefined && !config[role].model) {
110
+ throw new Error(`Invalid ${role} model reference. Use provider/model-id or remove model to explicitly follow main.`);
111
+ }
98
112
  }
99
113
  return config;
100
114
  }
@@ -15,8 +15,7 @@ import {
15
15
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
16
16
  import { DEFAULT_THINKING_LEVEL, type ThinkingLevel } from "./config.ts";
17
17
 
18
- export type ModelContext = Pick<ExtensionContext, "model" | "modelRegistry"> &
19
- Partial<Pick<ExtensionContext, "scopedModels">>;
18
+ export type ModelContext = Pick<ExtensionContext, "model" | "modelRegistry" | "scopedModels">;
20
19
 
21
20
  export const CURRENT_MAIN_MODEL = "__current_main_model__";
22
21
 
@@ -51,32 +50,6 @@ function cleanModelRef(ref: string | undefined): string | undefined {
51
50
  return trimmed || undefined;
52
51
  }
53
52
 
54
- /**
55
- * Provider ids Pi renamed while keeping the model id. Pi 1.0.3 renamed
56
- * `azure-openai-responses` to `azure`. Custom registries can still expose
57
- * either id, so prefer the exact selection before trying its published alias.
58
- */
59
- const RENAMED_PROVIDER_IDS: Readonly<Record<string, string>> = {
60
- "azure-openai-responses": "azure",
61
- };
62
-
63
- /** Stored ref plus the renamed provider id, when Pi published one. */
64
- function modelRefAliases(ref: string): readonly string[] {
65
- const normalized = ref.trim();
66
- const slash = normalized.indexOf("/");
67
- if (slash <= 0 || slash >= normalized.length - 1) return [normalized];
68
- const renamed = RENAMED_PROVIDER_IDS[normalized.slice(0, slash)];
69
- if (!renamed) return [normalized];
70
- return [normalized, `${renamed}${normalized.slice(slash)}`];
71
- }
72
-
73
- /** Prefer the alias that the live catalog actually lists. */
74
- function resolveLiveModelRef(ref: string, liveRefs: ReadonlySet<string> | undefined): string | undefined {
75
- const aliases = modelRefAliases(ref);
76
- if (!liveRefs) return aliases[0];
77
- return aliases.find((candidate) => liveRefs.has(candidate));
78
- }
79
-
80
53
  export function modelRef(model: { provider: string; id: string }): string {
81
54
  return `${model.provider}/${model.id}`;
82
55
  }
@@ -92,9 +65,7 @@ export function currentModelRef(ctx: Pick<ModelContext, "model">): string | unde
92
65
  */
93
66
  export function availableModelsInScope(ctx: ModelContext): readonly Model<Api>[] {
94
67
  const models = ctx.modelRegistry.getAvailable();
95
- // scopedModels was added after the original Pi minimum. Treat a missing field
96
- // exactly like an empty scope and use the full live registry.
97
- const scopedModels = ctx.scopedModels ?? [];
68
+ const scopedModels = ctx.scopedModels;
98
69
  if (scopedModels.length === 0) return models;
99
70
  const scopedRefs = new Set(scopedModels.map((entry) => modelRef(entry.model)));
100
71
  return models.filter((model) => scopedRefs.has(modelRef(model)));
@@ -106,8 +77,7 @@ export function findModelByRef(
106
77
  ): Model<Api> | undefined {
107
78
  const normalized = cleanModelRef(ref);
108
79
  if (!normalized) return undefined;
109
- const liveRef = resolveLiveModelRef(normalized, new Set(models.map(modelRef)));
110
- return models.find((model) => modelRef(model) === liveRef);
80
+ return models.find((model) => modelRef(model) === normalized);
111
81
  }
112
82
 
113
83
  /**
@@ -122,7 +92,7 @@ export function resolveAgentModelRoute(input: AgentModelRouteInput): ResolvedAge
122
92
  const available = input.availableRefs
123
93
  ? new Set(input.availableRefs.map((ref) => ref.trim()).filter(Boolean))
124
94
  : undefined;
125
- const resolvedSelectedRef = selectedRef ? resolveLiveModelRef(selectedRef, available) : undefined;
95
+ const resolvedSelectedRef = selectedRef && (!available || available.has(selectedRef)) ? selectedRef : undefined;
126
96
  return {
127
97
  primaryRef: selectedRef ? resolvedSelectedRef : mainRef,
128
98
  ...(selectedRef && !resolvedSelectedRef ? { unavailableSelectedRef: selectedRef } : {}),
@@ -162,14 +132,11 @@ export function buildModelPickerItems(options: {
162
132
  if (!byRef.has(ref)) byRef.set(ref, model);
163
133
  }
164
134
  const configuredRef = cleanModelRef(options.configuredRef);
165
- const liveConfiguredRef = configuredRef
166
- ? resolveLiveModelRef(configuredRef, new Set(byRef.keys())) ?? configuredRef
167
- : undefined;
168
135
 
169
136
  const refs = [...byRef.keys()]
170
137
  .sort((left, right) => {
171
- const leftRank = left === liveConfiguredRef ? 0 : left === mainRef ? 1 : 2;
172
- const rightRank = right === liveConfiguredRef ? 0 : right === mainRef ? 1 : 2;
138
+ const leftRank = left === configuredRef ? 0 : left === mainRef ? 1 : 2;
139
+ const rightRank = right === configuredRef ? 0 : right === mainRef ? 1 : 2;
173
140
  return leftRank - rightRank || left.localeCompare(right);
174
141
  });
175
142
 
@@ -182,7 +149,7 @@ export function buildModelPickerItems(options: {
182
149
  const items: ModelPickerItem[] = [dynamic];
183
150
  for (const ref of refs) {
184
151
  const model = byRef.get(ref)!;
185
- const tags = [ref === liveConfiguredRef ? "configured" : "", ref === mainRef ? "current main" : ""]
152
+ const tags = [ref === configuredRef ? "configured" : "", ref === mainRef ? "current main" : ""]
186
153
  .filter(Boolean);
187
154
  const name = model.name.trim() || model.id;
188
155
  const duplicateName = [...byRef.values()].some((other) =>
@@ -190,8 +157,8 @@ export function buildModelPickerItems(options: {
190
157
  items.push({
191
158
  value: ref,
192
159
  label: name + " · " + model.provider + (duplicateName ? " (" + model.id + ")" : ""),
193
- description: ["Reference: " + ref, "Pins this worker; failures return to main without changing models.", modelCapabilities(model), ...tags].join(" · "),
194
- saved: ref === liveConfiguredRef,
160
+ description: ["Reference: " + ref, "Pins this role; failures return to main without changing models.", modelCapabilities(model), ...tags].join(" · "),
161
+ saved: ref === configuredRef,
195
162
  });
196
163
  }
197
164
  return items;
@@ -1,15 +1,15 @@
1
- /** One worker, two settings. Main keeps Pi's model; workers share their own selection. */
1
+ /** Independent model and thinking preferences for each built-in role. */
2
2
 
3
3
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
4
4
  import {
5
- DEFAULT_CONFIG, DEFAULT_THINKING_LEVEL, errorMessage, getConfigPath,
5
+ BUILTIN_AGENT_NAMES, DEFAULT_AGENT_SETTINGS, DEFAULT_THINKING_LEVEL, errorMessage, getConfigPath,
6
6
  initializeConfig, loadConfig, saveConfig, type ThinkingLevel,
7
7
  } from "./config.ts";
8
8
  import {
9
9
  CURRENT_MAIN_MODEL, availableModelsInScope, buildModelPickerItems, currentModelRef,
10
10
  findModelByRef, resolveThinkingLevel, supportedThinkingLevels,
11
11
  } from "./models.ts";
12
- import { promptSelectOne, promptSettings, type SetupItem } from "./ui.ts";
12
+ import { promptSelectOne, promptSettings, type SetupItem, type SettingKey } from "./ui.ts";
13
13
 
14
14
  const THINKING_HINTS: Record<ThinkingLevel, string> = {
15
15
  off: "No reasoning tokens", minimal: "Minimal reasoning", low: "Light reasoning",
@@ -23,54 +23,67 @@ export async function runSetup(ctx: ExtensionContext, configPath: string = getCo
23
23
  }
24
24
  try {
25
25
  await ensureDefaultConfig(ctx, configPath);
26
- let focus = "model";
26
+ let focus: SettingKey = "researcher.model";
27
27
  let status = "Changes save immediately";
28
28
  while (true) {
29
29
  const config = await loadConfig(configPath);
30
30
  const models = availableModelsInScope(ctx);
31
- const selected = findModelByRef(models, config.model);
32
- const model = selected ?? ctx.model;
33
- const effective = resolveThinkingLevel(model, config.thinking);
34
31
  const choice = await promptSettings(ctx, {
35
32
  main: currentModelRef(ctx) ?? "Pi default",
36
- model: config.model ?? "Follow main",
37
- thinking: config.model && !selected ? config.thinking : effective + (effective !== config.thinking ? " (" + config.thinking + " requested)" : ""),
38
- note: config.model && !selected ? "Worker unavailable; dispatch paused. Select an available model." : !config.model ? "Choose a cheaper worker to reduce main-model spending." : "",
33
+ roles: BUILTIN_AGENT_NAMES.map((role) => {
34
+ const settings = config[role];
35
+ const selected = findModelByRef(models, settings.model);
36
+ const unavailable = !!settings.model && !selected;
37
+ const effective = resolveThinkingLevel(selected ?? ctx.model, settings.thinking);
38
+ return {
39
+ role, model: settings.model ?? "Follow main",
40
+ thinking: unavailable ? settings.thinking : effective + (effective !== settings.thinking ? " (" + settings.thinking + " requested)" : ""),
41
+ unavailable,
42
+ };
43
+ }),
39
44
  status, focus,
40
45
  });
41
46
  if (!choice) return;
42
47
  focus = choice;
43
- if (choice === "model") {
44
- const picked = await promptSelectOne(ctx, "Worker model", "Choose a cost-effective model · Esc back",
45
- buildModelPickerItems({ models, configuredRef: config.model, mainRef: currentModelRef(ctx) }),
46
- config.model ?? CURRENT_MAIN_MODEL);
48
+ const role = BUILTIN_AGENT_NAMES.find((name) => choice.startsWith(name + "."))!;
49
+ const title = role === "researcher" ? "Researcher" : "Worker";
50
+ const settings = config[role];
51
+ const selected = findModelByRef(models, settings.model);
52
+ const model = settings.model ? selected : ctx.model;
53
+ const effective = resolveThinkingLevel(model, settings.thinking);
54
+ if (choice === role + ".model") {
55
+ const picked = await promptSelectOne(ctx, title + " model", "Search available models · Enter save · Esc cancel",
56
+ buildModelPickerItems({ models, configuredRef: settings.model, mainRef: currentModelRef(ctx) }),
57
+ settings.model ?? CURRENT_MAIN_MODEL);
47
58
  if (picked === undefined) continue;
48
59
  const next = await loadConfig(configPath);
49
- if (picked === CURRENT_MAIN_MODEL) delete next.model;
50
- else next.model = picked;
60
+ if (picked === CURRENT_MAIN_MODEL) delete next[role].model;
61
+ else next[role].model = picked;
51
62
  await saveConfig(next, configPath);
52
- status = "Model saved";
53
- } else if (choice === "thinking") {
54
- const levels = supportedThinkingLevels(config.model && !selected ? undefined : model);
63
+ status = title + " model saved";
64
+ } else if (choice === role + ".thinking") {
65
+ const levels = supportedThinkingLevels(model);
55
66
  if (!levels.length) {
56
67
  ctx.ui.notify("Choose a model before changing thinking; its supported levels are not available yet.", "info");
57
68
  continue;
58
69
  }
59
70
  const items: SetupItem[] = levels.map((level) => ({
60
71
  value: level, label: level + (level === DEFAULT_THINKING_LEVEL ? " (default)" : ""),
61
- description: THINKING_HINTS[level], saved: level === config.thinking,
72
+ description: THINKING_HINTS[level], saved: level === settings.thinking,
62
73
  }));
63
- if (!levels.includes(config.thinking)) items.push({
64
- value: config.thinking, label: config.thinking + " (runs as " + effective + ")",
74
+ if (!levels.includes(settings.thinking)) items.push({
75
+ value: settings.thinking, label: settings.thinking + " (runs as " + effective + ")",
65
76
  description: "Saved preference; the current model clamps it.", saved: true,
66
77
  });
67
- const picked = await promptSelectOne(ctx, "Worker thinking", "Reasoning effort · Esc back", items, config.thinking);
78
+ const picked = await promptSelectOne(ctx, title + " thinking", "Reasoning effort for " + role + " · Esc cancel", items, settings.thinking);
68
79
  if (picked === undefined) continue;
69
- await saveConfig({ ...await loadConfig(configPath), thinking: picked as ThinkingLevel }, configPath);
70
- status = "Thinking saved";
71
- } else if (choice === "reset") {
72
- await saveConfig({ ...DEFAULT_CONFIG }, configPath);
73
- status = "Defaults restored";
80
+ const next = await loadConfig(configPath);
81
+ next[role].thinking = picked as ThinkingLevel;
82
+ await saveConfig(next, configPath);
83
+ status = title + " thinking saved";
84
+ } else if (choice === role + ".reset") {
85
+ await saveConfig({ ...await loadConfig(configPath), [role]: { ...DEFAULT_AGENT_SETTINGS } }, configPath);
86
+ status = title + " defaults restored";
74
87
  }
75
88
  }
76
89
  } catch (error) {
@@ -83,8 +96,8 @@ export async function ensureDefaultConfig(ctx: ExtensionContext, configPath: str
83
96
  const result = await initializeConfig(configPath);
84
97
  if (!result) return;
85
98
  ctx.ui.notify(
86
- "pi-subagents: " + (result === "reset" ? "deleted the old config and initialized new worker settings at " : "initialized worker settings at ")
87
- + configPath + ". Main plans and reviews; workers execute. Run /subagents-setup to choose a cost-effective worker model and thinking level. Defaults follow main with medium thinking.",
99
+ "pi-subagents: " + (result === "reset" ? "overwrote the old config with independent role settings at " : "initialized role settings at ")
100
+ + configPath + ". Run /subagents-setup to choose a model and thinking level for Researcher and Worker. Both default to Follow main with medium thinking.",
88
101
  "info",
89
102
  );
90
103
  } catch (error) {