@oai404iao/pi-subagent 0.2.0 → 0.4.0-alpha.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/src/config.ts CHANGED
@@ -1,18 +1,26 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { dirname, join, resolve } from "node:path";
3
3
  import { CONFIG_DIR_NAME, getAgentDir } from "@earendil-works/pi-coding-agent";
4
- import type { AgentScope, ReportDelivery, SubagentSettings } from "./types.ts";
4
+ import type {
5
+ AgentScope,
6
+ BackgroundProtocol,
7
+ ReportDelivery,
8
+ SubagentSettings,
9
+ } from "./types.ts";
5
10
 
6
11
  export const CONFIG_FILE_NAME = "subagent.json";
7
12
 
8
13
  export const DEFAULT_SETTINGS: Readonly<SubagentSettings> = {
9
14
  agentScope: "user",
10
- syncBundledAgents: false,
11
15
  maxDepth: 3,
12
16
  enableRunInBackground: true,
13
17
  defaultBackground: true,
18
+ maxConcurrentBackgroundRuns: 4,
19
+ maxIdleRuntimes: 0,
20
+ backgroundProtocol: "legacy",
14
21
  reportDelivery: "wakeup",
15
22
  inheritExtensions: false,
23
+ openAIIdentity: false,
16
24
  maxOutputBytes: 50 * 1024,
17
25
  };
18
26
 
@@ -23,8 +31,12 @@ const CONFIG_KEYS = new Set([
23
31
  "maxDepth",
24
32
  "enableRunInBackground",
25
33
  "defaultBackground",
34
+ "maxConcurrentBackgroundRuns",
35
+ "maxIdleRuntimes",
36
+ "backgroundProtocol",
26
37
  "reportDelivery",
27
38
  "inheritExtensions",
39
+ "openAIIdentity",
28
40
  "maxOutputBytes",
29
41
  ]);
30
42
 
@@ -84,6 +96,11 @@ function parseReportDelivery(value: unknown, source: string): ReportDelivery {
84
96
  throw new Error(`${source}: reportDelivery must be "wakeup" or "quiet"`);
85
97
  }
86
98
 
99
+ function parseBackgroundProtocol(value: unknown, source: string): BackgroundProtocol {
100
+ if (value === "legacy" || value === "mailbox-v2") return value;
101
+ throw new Error(`${source}: backgroundProtocol must be "legacy" or "mailbox-v2"`);
102
+ }
103
+
87
104
  function parseBoolean(value: unknown, key: string, source: string): boolean {
88
105
  if (typeof value === "boolean") return value;
89
106
  throw new Error(`${source}: ${key} must be a boolean`);
@@ -117,13 +134,15 @@ function applyConfig(
117
134
  if (config.syncBundledAgents !== undefined && !options.allowSyncBundledAgents) {
118
135
  throw new Error(`${source}: syncBundledAgents may be configured only in the user-level subagent.json`);
119
136
  }
137
+ if (config.syncBundledAgents !== undefined) {
138
+ // Compatibility with 0.2/0.3 configuration files. Bundled templates are
139
+ // now always initialized on first install/version change, and this
140
+ // retired switch no longer controls runtime discovery or writes.
141
+ parseBoolean(config.syncBundledAgents, "syncBundledAgents", source);
142
+ }
120
143
  return {
121
144
  agentScope:
122
145
  config.agentScope === undefined ? settings.agentScope : parseAgentScope(config.agentScope, source),
123
- syncBundledAgents:
124
- config.syncBundledAgents === undefined
125
- ? settings.syncBundledAgents
126
- : parseBoolean(config.syncBundledAgents, "syncBundledAgents", source),
127
146
  maxDepth:
128
147
  config.maxDepth === undefined
129
148
  ? settings.maxDepth
@@ -139,6 +158,34 @@ function applyConfig(
139
158
  config.defaultBackground === undefined
140
159
  ? settings.defaultBackground
141
160
  : parseBoolean(config.defaultBackground, "defaultBackground", source),
161
+ maxConcurrentBackgroundRuns:
162
+ config.maxConcurrentBackgroundRuns === undefined
163
+ ? settings.maxConcurrentBackgroundRuns
164
+ : parseInteger(
165
+ config.maxConcurrentBackgroundRuns,
166
+ "maxConcurrentBackgroundRuns",
167
+ source,
168
+ {
169
+ minimum: 1,
170
+ maximum: Number.MAX_SAFE_INTEGER,
171
+ },
172
+ ),
173
+ maxIdleRuntimes:
174
+ config.maxIdleRuntimes === undefined
175
+ ? settings.maxIdleRuntimes
176
+ : parseInteger(
177
+ config.maxIdleRuntimes,
178
+ "maxIdleRuntimes",
179
+ source,
180
+ {
181
+ minimum: 0,
182
+ maximum: Number.MAX_SAFE_INTEGER,
183
+ },
184
+ ),
185
+ backgroundProtocol:
186
+ config.backgroundProtocol === undefined
187
+ ? settings.backgroundProtocol
188
+ : parseBackgroundProtocol(config.backgroundProtocol, source),
142
189
  reportDelivery:
143
190
  config.reportDelivery === undefined
144
191
  ? settings.reportDelivery
@@ -147,6 +194,10 @@ function applyConfig(
147
194
  config.inheritExtensions === undefined
148
195
  ? settings.inheritExtensions
149
196
  : parseBoolean(config.inheritExtensions, "inheritExtensions", source),
197
+ openAIIdentity:
198
+ config.openAIIdentity === undefined
199
+ ? settings.openAIIdentity
200
+ : parseBoolean(config.openAIIdentity, "openAIIdentity", source),
150
201
  maxOutputBytes:
151
202
  config.maxOutputBytes === undefined
152
203
  ? settings.maxOutputBytes