@oai404iao/pi-subagent 0.3.0 → 0.4.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,17 +1,16 @@
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 { AgentScope, RuntimeMode, SubagentSettings } from "./types.ts";
5
5
 
6
6
  export const CONFIG_FILE_NAME = "subagent.json";
7
7
 
8
8
  export const DEFAULT_SETTINGS: Readonly<SubagentSettings> = {
9
9
  agentScope: "user",
10
- syncBundledAgents: false,
11
10
  maxDepth: 3,
12
- enableRunInBackground: true,
13
- defaultBackground: true,
14
- reportDelivery: "wakeup",
11
+ runtimeMode: "background",
12
+ maxConcurrentBackgroundRuns: 4,
13
+ maxIdleRuntimes: 0,
15
14
  inheritExtensions: false,
16
15
  openAIIdentity: false,
17
16
  maxOutputBytes: 50 * 1024,
@@ -20,11 +19,10 @@ export const DEFAULT_SETTINGS: Readonly<SubagentSettings> = {
20
19
  const CONFIG_KEYS = new Set([
21
20
  "$schema",
22
21
  "agentScope",
23
- "syncBundledAgents",
24
22
  "maxDepth",
25
- "enableRunInBackground",
26
- "defaultBackground",
27
- "reportDelivery",
23
+ "runtimeMode",
24
+ "maxConcurrentBackgroundRuns",
25
+ "maxIdleRuntimes",
28
26
  "inheritExtensions",
29
27
  "openAIIdentity",
30
28
  "maxOutputBytes",
@@ -81,9 +79,9 @@ function parseAgentScope(value: unknown, source: string): AgentScope {
81
79
  throw new Error(`${source}: agentScope must be "user", "project", or "both"`);
82
80
  }
83
81
 
84
- function parseReportDelivery(value: unknown, source: string): ReportDelivery {
85
- if (value === "wakeup" || value === "quiet") return value;
86
- throw new Error(`${source}: reportDelivery must be "wakeup" or "quiet"`);
82
+ function parseRuntimeMode(value: unknown, source: string): RuntimeMode {
83
+ if (value === "foreground" || value === "background") return value;
84
+ throw new Error(`${source}: runtimeMode must be "foreground" or "background"`);
87
85
  }
88
86
 
89
87
  function parseBoolean(value: unknown, key: string, source: string): boolean {
@@ -114,18 +112,12 @@ function applyConfig(
114
112
  settings: SubagentSettings,
115
113
  config: ConfigRecord,
116
114
  source: string,
117
- options: { allowSyncBundledAgents: boolean },
118
115
  ): SubagentSettings {
119
- if (config.syncBundledAgents !== undefined && !options.allowSyncBundledAgents) {
120
- throw new Error(`${source}: syncBundledAgents may be configured only in the user-level subagent.json`);
121
- }
122
116
  return {
123
117
  agentScope:
124
- config.agentScope === undefined ? settings.agentScope : parseAgentScope(config.agentScope, source),
125
- syncBundledAgents:
126
- config.syncBundledAgents === undefined
127
- ? settings.syncBundledAgents
128
- : parseBoolean(config.syncBundledAgents, "syncBundledAgents", source),
118
+ config.agentScope === undefined
119
+ ? settings.agentScope
120
+ : parseAgentScope(config.agentScope, source),
129
121
  maxDepth:
130
122
  config.maxDepth === undefined
131
123
  ? settings.maxDepth
@@ -133,18 +125,34 @@ function applyConfig(
133
125
  minimum: 0,
134
126
  maximum: Number.MAX_SAFE_INTEGER,
135
127
  }),
136
- enableRunInBackground:
137
- config.enableRunInBackground === undefined
138
- ? settings.enableRunInBackground
139
- : parseBoolean(config.enableRunInBackground, "enableRunInBackground", source),
140
- defaultBackground:
141
- config.defaultBackground === undefined
142
- ? settings.defaultBackground
143
- : parseBoolean(config.defaultBackground, "defaultBackground", source),
144
- reportDelivery:
145
- config.reportDelivery === undefined
146
- ? settings.reportDelivery
147
- : parseReportDelivery(config.reportDelivery, source),
128
+ runtimeMode:
129
+ config.runtimeMode === undefined
130
+ ? settings.runtimeMode
131
+ : parseRuntimeMode(config.runtimeMode, source),
132
+ maxConcurrentBackgroundRuns:
133
+ config.maxConcurrentBackgroundRuns === undefined
134
+ ? settings.maxConcurrentBackgroundRuns
135
+ : parseInteger(
136
+ config.maxConcurrentBackgroundRuns,
137
+ "maxConcurrentBackgroundRuns",
138
+ source,
139
+ {
140
+ minimum: 1,
141
+ maximum: Number.MAX_SAFE_INTEGER,
142
+ },
143
+ ),
144
+ maxIdleRuntimes:
145
+ config.maxIdleRuntimes === undefined
146
+ ? settings.maxIdleRuntimes
147
+ : parseInteger(
148
+ config.maxIdleRuntimes,
149
+ "maxIdleRuntimes",
150
+ source,
151
+ {
152
+ minimum: 0,
153
+ maximum: Number.MAX_SAFE_INTEGER,
154
+ },
155
+ ),
148
156
  inheritExtensions:
149
157
  config.inheritExtensions === undefined
150
158
  ? settings.inheritExtensions
@@ -169,7 +177,7 @@ export function loadSettings(options: LoadSettingsOptions): LoadedSettings {
169
177
  const userPath = join(options.agentDir ?? getAgentDir(), CONFIG_FILE_NAME);
170
178
  const userConfig = readConfig(userPath);
171
179
  if (userConfig) {
172
- settings = applyConfig(settings, userConfig, userPath, { allowSyncBundledAgents: true });
180
+ settings = applyConfig(settings, userConfig, userPath);
173
181
  sources.push(userPath);
174
182
  }
175
183
 
@@ -178,7 +186,7 @@ export function loadSettings(options: LoadSettingsOptions): LoadedSettings {
178
186
  if (projectPath) {
179
187
  const projectConfig = readConfig(projectPath);
180
188
  if (projectConfig) {
181
- settings = applyConfig(settings, projectConfig, projectPath, { allowSyncBundledAgents: false });
189
+ settings = applyConfig(settings, projectConfig, projectPath);
182
190
  sources.push(projectPath);
183
191
  }
184
192
  }