@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/README.md +294 -89
- package/agents/worker.md +1 -1
- package/config.example.json +3 -4
- package/config.schema.json +26 -20
- package/index.ts +2 -0
- package/package.json +13 -12
- package/src/agent-state.ts +125 -0
- package/src/agent-sync.ts +171 -88
- package/src/agents.ts +3 -22
- package/src/catalog.ts +47 -0
- package/src/completion-mailbox.ts +656 -0
- package/src/config.ts +43 -35
- package/src/coordinator.ts +2172 -326
- package/src/descriptor.ts +96 -33
- package/src/index.ts +176 -58
- package/src/mailbox.ts +451 -0
- package/src/providers.ts +221 -28
- package/src/render.ts +23 -16
- package/src/scheduler.ts +173 -0
- package/src/schemas.ts +76 -38
- package/src/task-path.ts +146 -0
- package/src/types.ts +53 -15
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,
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
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
|
|
85
|
-
if (value === "
|
|
86
|
-
throw new Error(`${source}:
|
|
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
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
137
|
-
config.
|
|
138
|
-
? settings.
|
|
139
|
-
:
|
|
140
|
-
|
|
141
|
-
config.
|
|
142
|
-
? settings.
|
|
143
|
-
:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
|
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
|
|
189
|
+
settings = applyConfig(settings, projectConfig, projectPath);
|
|
182
190
|
sources.push(projectPath);
|
|
183
191
|
}
|
|
184
192
|
}
|