@ferris1225/pi-subagents 4.3.30 → 4.3.32

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/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Assembly point: builds the shared runtime and registers everything.
5
5
  * The heavy lifting lives in focused modules:
6
- * - delegation/ — role discovery, routing prompts, and tool contract
6
+ * - delegation/ — built-in roles, routing prompts, and tool contract
7
7
  * - configuration/ — persisted settings, model routes, and setup UI
8
8
  * - execution/ — process queue, RPC transport/control, and model handoff
9
9
  * - lifecycle/ — durable threads, restoration, controls, and delivery
@@ -21,9 +21,9 @@
21
21
 
22
22
  import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
23
23
  import { Text } from "@earendil-works/pi-tui";
24
- import { getConfigPath, loadConfig } from "./src/configuration/config.ts";
24
+ import { getConfigPath } from "./src/configuration/config.ts";
25
25
  import { runSetup } from "./src/configuration/setup.ts";
26
- import { discoverAgents } from "./src/delegation/agents.ts";
26
+ import { loadBuiltinAgents } from "./src/delegation/agents.ts";
27
27
  import { registerSubagentTool } from "./src/delegation/dispatch.ts";
28
28
  import { buildDelegationDirective, installDelegationSections } from "./src/delegation/prompt.ts";
29
29
  import { currentSubagentDepth } from "./src/execution/spawn.ts";
@@ -31,11 +31,8 @@ import { createRuntime } from "./src/lifecycle/runtime.ts";
31
31
  import { bootstrapDurableState } from "./src/lifecycle/thread-restore.ts";
32
32
  import { registerLookupTools } from "./src/lifecycle/tools.ts";
33
33
  import { registerAnnouncements } from "./src/presentation/announcements.ts";
34
- import { matchRunIds } from "./src/presentation/format.ts";
35
34
  import { clearActiveRunsWidget } from "./src/presentation/widget.ts";
36
35
 
37
- export { matchRunIds };
38
-
39
36
  export default function (pi: ExtensionAPI): void {
40
37
  const configPath = getConfigPath(getAgentDir());
41
38
  const runtime = createRuntime(pi, configPath);
@@ -71,7 +68,7 @@ export default function (pi: ExtensionAPI): void {
71
68
  registerLookupTools(pi, runtime);
72
69
 
73
70
  pi.registerCommand("subagents-setup", {
74
- description: "Configure pi-subagents: agents, models, and per-role thinking",
71
+ description: "Configure pi-subagents: model and thinking per role",
75
72
  handler: async (_args, ctx) => {
76
73
  await runSetup(ctx, configPath);
77
74
  },
@@ -86,12 +83,7 @@ export default function (pi: ExtensionAPI): void {
86
83
  // A full systemPrompt return forces an opaque prompt and invalidates the cache.
87
84
  pi.on("before_agent_start", async (event, ctx) => {
88
85
  await runtime.durableRestore;
89
- const config = await loadConfig(configPath);
90
- const { agents } = discoverAgents(ctx.cwd, {
91
- scope: config.agentScope,
92
- enabledNames: config.enabledAgents,
93
- projectTrusted: ctx.isProjectTrusted?.() === true,
94
- });
86
+ const agents = loadBuiltinAgents();
95
87
  const sources = [...runtime.threads.values()];
96
88
  const sections = event.systemPromptOptions?.sections;
97
89
  if (sections) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ferris1225/pi-subagents",
3
- "version": "4.3.30",
3
+ "version": "4.3.32",
4
4
  "description": "A managed sub-agent team for pi: lightweight scout research and artisan implementation, one-shot runs, read-only status, and Git worktree isolation.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -25,7 +25,6 @@
25
25
  "files": [
26
26
  "index.ts",
27
27
  "src",
28
- "agents",
29
28
  "README.md",
30
29
  "CHANGELOG.md",
31
30
  "LICENSE"
@@ -37,23 +36,19 @@
37
36
  },
38
37
  "scripts": {
39
38
  "check": "tsc --noEmit && npm test",
40
- "test": "node --experimental-transform-types --test test/*.test.ts",
39
+ "test": "node --test test/*.test.ts",
41
40
  "prepack": "npm run check"
42
41
  },
43
42
  "peerDependencies": {
44
- "@earendil-works/pi-agent-core": ">=1.0.0",
45
43
  "@earendil-works/pi-ai": ">=1.0.0",
46
44
  "@earendil-works/pi-coding-agent": ">=1.0.0",
47
- "@earendil-works/pi-server": ">=1.0.0",
48
45
  "@earendil-works/pi-tui": ">=1.0.0",
49
46
  "typebox": "*"
50
47
  },
51
48
  "devDependencies": {
52
- "@earendil-works/pi-agent-core": "^1.3.0",
53
- "@earendil-works/pi-ai": "^1.3.0",
54
- "@earendil-works/pi-coding-agent": "^1.3.0",
55
- "@earendil-works/pi-server": "^1.1.0",
56
- "@earendil-works/pi-tui": "^1.3.0",
49
+ "@earendil-works/pi-ai": "^1.4.0",
50
+ "@earendil-works/pi-coding-agent": "^1.4.0",
51
+ "@earendil-works/pi-tui": "^1.4.0",
57
52
  "@types/node": "^22.10.0",
58
53
  "typebox": "^1.3.27",
59
54
  "typescript": "^5.9.0"
@@ -2,37 +2,29 @@
2
2
  * Configuration load/save for pi-subagents.
3
3
  *
4
4
  * Config lives at <agentDir>/pi-subagents.json (agentDir defaults to ~/.pi/agent
5
- * and honors PI_CODING_AGENT_DIR). Parsing is defensive: invalid fields fall back
6
- * to defaults instead of throwing, so a hand-edited or partially-written file can
7
- * never break the extension at runtime. Unknown keys from older versions are
8
- * dropped and the normalized shape persisted back on load.
5
+ * and honors PI_CODING_AGENT_DIR). The only user-tunable surface is the model
6
+ * and thinking level per role; the two built-in roles are always enabled and
7
+ * every operational default is a constant. Parsing is defensive: invalid
8
+ * fields fall back to defaults instead of throwing, so a hand-edited or
9
+ * partially-written file can never break the extension at runtime. Unknown
10
+ * keys from older versions are dropped and the normalized shape persisted back
11
+ * on load.
9
12
  */
10
13
 
11
14
  import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
12
15
  import { dirname, join } from "node:path";
13
16
  import { getAgentDir, withFileMutationQueue } from "@earendil-works/pi-coding-agent";
14
- import { MAX_SUBAGENT_CONCURRENCY } from "../execution/background.ts";
15
17
 
16
- /** Full catalog of agents shipped with the package (selectable in /subagents-setup). */
18
+ /** Full catalog of agents shipped with the package; all of them always run. */
17
19
  export const BUILTIN_AGENT_NAMES = ["scout", "artisan"] as const;
18
20
 
19
- // Catalog assumed for configs written before built-in adoption tracking.
20
- // Keep this frozen so future built-ins are still recognized as new.
21
- const INITIAL_AGENT_NAMES = ["scout", "artisan"] as const;
22
-
23
- /** Agents enabled out of the box on a fresh install. */
24
- export const DEFAULT_ENABLED_AGENTS: readonly string[] = [...BUILTIN_AGENT_NAMES];
25
-
26
- export const AGENT_SCOPE_VALUES = ["user", "project", "both"] as const;
27
- export type AgentScope = (typeof AGENT_SCOPE_VALUES)[number];
28
-
29
21
  /** Thinking levels accepted by pi's `--thinking` option. */
30
- export const THINKING_LEVEL_VALUES = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
22
+ const THINKING_LEVEL_VALUES = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
31
23
  export type ThinkingLevel = (typeof THINKING_LEVEL_VALUES)[number];
32
24
  export const DEFAULT_THINKING_LEVEL: ThinkingLevel = "medium";
33
25
 
34
26
  /** Role-owned default reasoning strength. A `/subagents-setup` override wins;
35
- * there is no per-call or frontmatter thinking. */
27
+ * there is no per-call thinking. */
36
28
  export function roleThinkingLevel(agentName: string): ThinkingLevel {
37
29
  switch (agentName) {
38
30
  case "scout":
@@ -68,68 +60,30 @@ export function agentProfile(name: string): AgentProfile | undefined {
68
60
  }
69
61
 
70
62
  /** How many lines of a sub-agent result the completion message may carry.
71
- * Default: 40 — wide fan-outs multiply completion blocks, so deliveries stay
72
- * compact and the full text lives in the on-disk result artifact. */
63
+ * Wide fan-outs multiply completion blocks, so deliveries stay compact and the
64
+ * full text lives in the on-disk result artifact. */
73
65
  export const DEFAULT_MAX_RESULT_LINES = 40;
74
- /** Upper bound accepted for maxResultLines (defensive clamp). */
75
- export const MAX_RESULT_LINES_LIMIT = 2000;
76
66
 
77
67
  const CONFIG_FILE_NAME = "pi-subagents.json";
78
68
 
79
- /**
80
- * Default idle timeout in seconds: a sub-agent whose stdout (JSON event stream)
81
- * goes silent for this long is terminated; a selected model then hands the
82
- * retained session to current main. 0 disables the watchdog. Default: 1800.
83
- */
69
+ /** Idle timeout in seconds: a sub-agent whose stdout (JSON event stream) goes
70
+ * silent for this long is terminated; a configured agent model then hands
71
+ * off to the current main model. */
84
72
  export const DEFAULT_IDLE_TIMEOUT_SEC = 1800;
85
- /** Upper bound accepted for idleTimeoutSec (defensive clamp). 0 disables. */
86
- export const IDLE_TIMEOUT_SEC_LIMIT = 3600;
87
73
 
88
74
  export interface SubagentsConfig {
89
- /** Agent names that are discoverable and injected. Fresh-install default: every built-in agent. */
90
- enabledAgents: string[];
91
- /** Agent names already presented by setup. Built-ins use this catalog to opt in
92
- * once on upgrade without undoing a later explicit disable. */
93
- knownAgents: string[];
94
75
  /** Per-agent model override, keyed by agent name, as "provider/model-id". */
95
76
  agentModels: Record<string, string>;
96
77
  /** Optional per-agent thinking override from `/subagents-setup`. Missing =
97
78
  * the role default from `roleThinkingLevel`. */
98
79
  agentThinkingLevels: Record<string, ThinkingLevel>;
99
- /**
100
- * Max lines of a sub-agent result carried in the completion message. Longer
101
- * results are truncated; the full text is written to a temp file whose path
102
- * is included in the message. Default: 40.
103
- */
104
- maxResultLines: number;
105
- /** Maximum simultaneous child processes. 0 keeps automatic host capacity
106
- * (4–6); 1–6 selects an explicit limit, applied at the next dispatch. */
107
- maxConcurrentAgents: number;
108
- /** Which agent directories to discover from. Default: "user". */
109
- agentScope: AgentScope;
110
- /**
111
- * Idle timeout in seconds: a sub-agent whose stdout (JSON event stream) goes
112
- * silent for this long is terminated; a configured agent model then hands
113
- * off to the current main model. 0 disables the idle watchdog. Default: 1800.
114
- */
115
- idleTimeoutSec: number;
116
80
  }
117
81
 
118
82
  export const DEFAULT_CONFIG: SubagentsConfig = {
119
- enabledAgents: [...DEFAULT_ENABLED_AGENTS],
120
- knownAgents: [...BUILTIN_AGENT_NAMES],
121
83
  agentModels: {},
122
84
  agentThinkingLevels: {},
123
- maxResultLines: DEFAULT_MAX_RESULT_LINES,
124
- maxConcurrentAgents: 0,
125
- agentScope: "user",
126
- idleTimeoutSec: DEFAULT_IDLE_TIMEOUT_SEC,
127
85
  };
128
86
 
129
- export const FIRST_RUN_SETUP_HINT =
130
- "Run /subagents-setup to pick each role's model and thinking level. " +
131
- "Scout does lightweight read-only research. Artisan implements one substantial change.";
132
-
133
87
  export function getConfigPath(agentDir: string = getAgentDir()): string {
134
88
  return join(agentDir, CONFIG_FILE_NAME);
135
89
  }
@@ -138,10 +92,6 @@ function isRecord(value: unknown): value is Record<string, unknown> {
138
92
  return typeof value === "object" && value !== null && !Array.isArray(value);
139
93
  }
140
94
 
141
- function isAgentScope(value: unknown): value is AgentScope {
142
- return typeof value === "string" && (AGENT_SCOPE_VALUES as readonly string[]).includes(value);
143
- }
144
-
145
95
  function isModelReference(value: unknown): value is string {
146
96
  if (typeof value !== "string") return false;
147
97
  const normalized = value.trim();
@@ -149,12 +99,6 @@ function isModelReference(value: unknown): value is string {
149
99
  return slash > 0 && slash < normalized.length - 1 && !/\s/u.test(normalized);
150
100
  }
151
101
 
152
- /** Clamp a raw value to a positive integer within [1, upper]; undefined when invalid. */
153
- function clampCount(value: unknown, upper: number): number | undefined {
154
- if (typeof value !== "number" || !Number.isFinite(value)) return undefined;
155
- return Math.max(1, Math.min(upper, Math.round(value)));
156
- }
157
-
158
102
  /**
159
103
  * Merge a raw parsed JSON value over the defaults, dropping invalid fields.
160
104
  * Exported for tests.
@@ -163,22 +107,6 @@ export function normalizeConfig(raw: unknown): SubagentsConfig {
163
107
  const config = defaultConfig();
164
108
  if (!isRecord(raw)) return config;
165
109
 
166
- if (Array.isArray(raw.enabledAgents)) {
167
- const names = raw.enabledAgents.filter(
168
- (name): name is string => typeof name === "string" && name.trim().length > 0,
169
- );
170
- // An explicitly empty array is honored; duplicates collapse.
171
- config.enabledAgents = [...new Set(names.map((name) => name.trim()))];
172
- }
173
-
174
- const rawKnownAgents = Array.isArray(raw.knownAgents) ? raw.knownAgents : INITIAL_AGENT_NAMES;
175
- config.knownAgents = [...new Set(rawKnownAgents.filter(
176
- (name): name is string => typeof name === "string" && name.trim().length > 0,
177
- ).map((name) => name.trim()))];
178
- for (const name of config.enabledAgents) {
179
- if (!config.knownAgents.includes(name)) config.knownAgents.push(name);
180
- }
181
-
182
110
  if (isRecord(raw.agentModels)) {
183
111
  for (const [rawKey, value] of Object.entries(raw.agentModels)) {
184
112
  const key = rawKey.trim();
@@ -201,51 +129,16 @@ export function normalizeConfig(raw: unknown): SubagentsConfig {
201
129
  }
202
130
  }
203
131
 
204
- const maxResultLines = clampCount(raw.maxResultLines, MAX_RESULT_LINES_LIMIT);
205
- if (maxResultLines !== undefined) config.maxResultLines = maxResultLines;
206
-
207
- if (typeof raw.maxConcurrentAgents === "number" && Number.isFinite(raw.maxConcurrentAgents)) {
208
- config.maxConcurrentAgents = Math.max(0, Math.min(MAX_SUBAGENT_CONCURRENCY, Math.round(raw.maxConcurrentAgents)));
209
- }
210
-
211
- if (isAgentScope(raw.agentScope)) {
212
- config.agentScope = raw.agentScope;
213
- }
214
-
215
- // 0 disables the idle watchdog; otherwise clamp to [0, upper].
216
- if (typeof raw.idleTimeoutSec === "number" && Number.isFinite(raw.idleTimeoutSec)) {
217
- config.idleTimeoutSec = Math.max(0, Math.min(IDLE_TIMEOUT_SEC_LIMIT, Math.round(raw.idleTimeoutSec)));
218
- }
219
-
220
132
  return config;
221
133
  }
222
134
 
223
135
  function defaultConfig(): SubagentsConfig {
224
136
  return {
225
- ...DEFAULT_CONFIG,
226
- enabledAgents: [...DEFAULT_CONFIG.enabledAgents],
227
- knownAgents: [...DEFAULT_CONFIG.knownAgents],
228
137
  agentModels: {},
229
138
  agentThinkingLevels: {},
230
139
  };
231
140
  }
232
141
 
233
- function adoptNewBuiltins(config: SubagentsConfig): SubagentsConfig {
234
- const known = new Set(config.knownAgents);
235
- const fresh = BUILTIN_AGENT_NAMES.filter((name) => !known.has(name));
236
- if (fresh.length === 0) return config;
237
- return {
238
- ...config,
239
- enabledAgents: [...new Set([...config.enabledAgents, ...fresh])],
240
- knownAgents: [...known, ...fresh],
241
- };
242
- }
243
-
244
- export interface LoadConfigOptions {
245
- /** Disable read-time canonicalization for transactional UI sessions. */
246
- persistNormalization?: boolean;
247
- }
248
-
249
142
  /**
250
143
  * Load config. A missing file is a normal state and yields the defaults (not an error).
251
144
  * A corrupt file also falls back to defaults rather than throwing, so startup never breaks.
@@ -253,7 +146,6 @@ export interface LoadConfigOptions {
253
146
  */
254
147
  export async function loadConfig(
255
148
  configPath: string = getConfigPath(),
256
- options: LoadConfigOptions = {},
257
149
  ): Promise<SubagentsConfig> {
258
150
  let text: string;
259
151
  try {
@@ -270,10 +162,10 @@ export async function loadConfig(
270
162
  return defaultConfig();
271
163
  }
272
164
 
273
- const config = adoptNewBuiltins(normalizeConfig(parsed));
165
+ const config = normalizeConfig(parsed);
274
166
 
275
167
  // Persist the canonical shape when invalid or unknown fields were omitted.
276
- if (options.persistNormalization !== false && JSON.stringify(config) !== JSON.stringify(parsed)) {
168
+ if (JSON.stringify(config) !== JSON.stringify(parsed)) {
277
169
  try {
278
170
  await saveConfig(config, configPath);
279
171
  } catch {
@@ -64,7 +64,7 @@ const RENAMED_PROVIDER_IDS: Readonly<Record<string, string>> = {
64
64
  };
65
65
 
66
66
  /** Stored ref plus the renamed provider id, when Pi published one. */
67
- export function modelRefAliases(ref: string): readonly string[] {
67
+ function modelRefAliases(ref: string): readonly string[] {
68
68
  const normalized = ref.trim();
69
69
  const slash = normalized.indexOf("/");
70
70
  if (slash <= 0 || slash >= normalized.length - 1) return [normalized];