pi-agent-swarm 0.5.0 → 0.7.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 +13 -1
- package/dist/chunks/{chunk-77JHO3GV.ts → chunk-CV4VP4UE.ts} +9 -1
- package/dist/chunks/{chunk-77JHO3GV.ts.map → chunk-CV4VP4UE.ts.map} +1 -1
- package/dist/chunks/{menu-NLK5I2DA.ts → menu-A2TQAWN6.ts} +2 -2
- package/dist/index.ts +1941 -162
- package/dist/index.ts.map +4 -4
- package/package.json +1 -1
- package/src/cache-warming.ts +147 -0
- package/src/external-runtime.ts +244 -0
- package/src/lead-mcp-bridge.ts +43 -2
- package/src/leader-handoff-bridge.ts +6 -0
- package/src/leader-recycling.ts +16 -3
- package/src/leader-runtime.ts +179 -12
- package/src/leader-session-runtime.ts +23 -0
- package/src/ledger.ts +28 -1
- package/src/mission-badge.ts +331 -0
- package/src/mission.ts +281 -0
- package/src/org.ts +10 -0
- package/src/pi-agent-swarm.ts +3 -0
- package/src/reviewer.ts +88 -0
- package/src/settings.ts +254 -1
- package/src/swarm-controller.ts +822 -7
- package/src/tools.ts +103 -1
- /package/dist/chunks/{menu-NLK5I2DA.ts.map → menu-A2TQAWN6.ts.map} +0 -0
package/src/reviewer.ts
CHANGED
|
@@ -177,12 +177,100 @@ export class ReviewerVerdictStore {
|
|
|
177
177
|
return undefined;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
hasPassingVerdict(taskId: string): boolean {
|
|
181
|
+
return this.records.some((rec) => rec.taskId === taskId && rec.verdict.verdict === "pass");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
consecutiveFailsForTask(taskId: string): number {
|
|
185
|
+
let count = 0;
|
|
186
|
+
for (let i = this.records.length - 1; i >= 0; i -= 1) {
|
|
187
|
+
const rec = this.records[i];
|
|
188
|
+
if (rec?.taskId !== taskId) continue;
|
|
189
|
+
if (rec.verdict.verdict === "fail") {
|
|
190
|
+
count += 1;
|
|
191
|
+
} else {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return count;
|
|
196
|
+
}
|
|
197
|
+
|
|
180
198
|
clear(): void {
|
|
181
199
|
this.records.length = 0;
|
|
182
200
|
this.byMessageId.clear();
|
|
183
201
|
}
|
|
184
202
|
}
|
|
185
203
|
|
|
204
|
+
export const MAX_CONSECUTIVE_REVIEWER_FAILS = 2;
|
|
205
|
+
|
|
206
|
+
export function inferModelFamily(modelRef: string): string {
|
|
207
|
+
const lower = modelRef.toLowerCase();
|
|
208
|
+
if (lower.includes("claude")) return "claude";
|
|
209
|
+
if (lower.includes("gemini")) return "gemini";
|
|
210
|
+
if (lower.includes("deepseek")) return "deepseek";
|
|
211
|
+
if (lower.includes("kimi") || lower.includes("moonshot") || /\/k3(\b|[-_.])/u.test(lower)) return "kimi";
|
|
212
|
+
if (lower.includes("qwen")) return "qwen";
|
|
213
|
+
if (lower.includes("glm")) return "glm";
|
|
214
|
+
if (lower.includes("gpt") || lower.includes("o1") || lower.includes("o3") || lower.includes("o4")) return "openai";
|
|
215
|
+
const stripped = lower.replace(/^(?:pi|agy):/u, "");
|
|
216
|
+
return stripped.split(/[/:]/u)[0] || "unknown";
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface ReviewerModelCandidate {
|
|
220
|
+
ref: string;
|
|
221
|
+
sawQuota?: boolean;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Picks up to 2 real concrete models from a different model family than the implementer,
|
|
226
|
+
* excluding recently quota-exhausted models. Never invents nonexistent model names.
|
|
227
|
+
*/
|
|
228
|
+
export function suggestCrossFamilyReviewerModels(
|
|
229
|
+
implementerModelRef: string | undefined,
|
|
230
|
+
candidates: readonly ReviewerModelCandidate[],
|
|
231
|
+
): string[] {
|
|
232
|
+
const implFamily = implementerModelRef ? inferModelFamily(implementerModelRef) : "";
|
|
233
|
+
const seenFamilies = new Set<string>();
|
|
234
|
+
const picked: string[] = [];
|
|
235
|
+
for (const candidate of candidates) {
|
|
236
|
+
if (candidate.sawQuota) continue;
|
|
237
|
+
const family = inferModelFamily(candidate.ref);
|
|
238
|
+
if (implFamily && family === implFamily) continue;
|
|
239
|
+
if (seenFamilies.has(family)) continue;
|
|
240
|
+
seenFamilies.add(family);
|
|
241
|
+
picked.push(candidate.ref);
|
|
242
|
+
if (picked.length >= 2) break;
|
|
243
|
+
}
|
|
244
|
+
return picked;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function formatReviewGovernanceReminder(params: {
|
|
248
|
+
policy: "suggest" | "required";
|
|
249
|
+
taskId: string;
|
|
250
|
+
implementerName: string;
|
|
251
|
+
implementerModel?: string;
|
|
252
|
+
suggestedReviewerModels: readonly string[];
|
|
253
|
+
}): string {
|
|
254
|
+
const modelHint =
|
|
255
|
+
params.suggestedReviewerModels.length > 0
|
|
256
|
+
? ` Recommended cross-family reviewer model(s): ${params.suggestedReviewerModels.join(" or ")}.`
|
|
257
|
+
: "";
|
|
258
|
+
if (params.policy === "required") {
|
|
259
|
+
return `\n\n[Swarm Governance — Review Required] Implementer ${params.implementerName} reported results for task "${params.taskId}", and no independent reviewer "pass" verdict is recorded yet. Before closing out this task, spawn an independent read-only reviewer (role="reviewer") to verify real files/diffs.${modelHint}`;
|
|
260
|
+
}
|
|
261
|
+
return `\n\n[Swarm Governance — Review Suggested] Implementer ${params.implementerName} reported results for task "${params.taskId}" with no independent reviewer verdict yet. For substantive code/doc/hardware changes, consider spawning role="reviewer" in a fresh read-only context.${modelHint}`;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function formatReviewerEscalationNotice(params: {
|
|
265
|
+
taskId: string;
|
|
266
|
+
consecutiveFails: number;
|
|
267
|
+
blockingIssues: readonly string[];
|
|
268
|
+
}): string {
|
|
269
|
+
const issueText =
|
|
270
|
+
params.blockingIssues.length > 0 ? ` Blocking issues: ${params.blockingIssues.slice(0, 5).join("; ")}.` : "";
|
|
271
|
+
return `\n\n[Swarm Escalation — Reviewer Circuit Open] Task "${params.taskId}" has received ${params.consecutiveFails} consecutive reviewer "fail" verdicts.${issueText} Stop the implementer/reviewer retry loop and escalate to the human user for a decision.`;
|
|
272
|
+
}
|
|
273
|
+
|
|
186
274
|
function stringList(value: unknown, field: string): string[] {
|
|
187
275
|
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
188
276
|
throw new Error(`Reviewer verdict ${field} must be an array of strings`);
|
package/src/settings.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from "./budget.js";
|
|
14
14
|
import type { SwarmColorPaletteName } from "./color.js";
|
|
15
15
|
import { DEFAULT_LEDGER_SETTINGS, type SwarmLedgerSettings } from "./ledger.js";
|
|
16
|
+
import { DEFAULT_MISSION_COUNTDOWN_SETTINGS, type MissionCountdownSettings } from "./mission.js";
|
|
16
17
|
import type { SwarmIsolationMode } from "./worktree.js";
|
|
17
18
|
|
|
18
19
|
export const SWARM_SETTINGS_FILE = "pi-agent-swarm.json";
|
|
@@ -26,6 +27,25 @@ export const DEFAULT_LEADER_RECYCLING_SETTINGS: Readonly<LeaderRecyclingSettings
|
|
|
26
27
|
maxReplacements: 3,
|
|
27
28
|
});
|
|
28
29
|
|
|
30
|
+
export type SwarmReviewPolicy = "off" | "suggest" | "required";
|
|
31
|
+
|
|
32
|
+
export interface CacheWarmingSettings {
|
|
33
|
+
/** Whether to extend Pi's built-in CacheWarmer while the lead is waiting for active workers. */
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
/** Hard cap on how long to keep the leader cache warm while waiting for workers (ms). */
|
|
36
|
+
maxWaitDurationMs: number;
|
|
37
|
+
/** Hard cap on total warm refreshes per idle wait window. */
|
|
38
|
+
maxRefreshesPerWait: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const DEFAULT_CACHE_WARMING_SETTINGS: Readonly<CacheWarmingSettings> = Object.freeze({
|
|
42
|
+
enabled: true,
|
|
43
|
+
maxWaitDurationMs: 30 * 60_000,
|
|
44
|
+
maxRefreshesPerWait: 8,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const DEFAULT_REVIEW_POLICY: SwarmReviewPolicy = "suggest";
|
|
48
|
+
|
|
29
49
|
export const DEFAULT_SWARM_SETTINGS: Readonly<SwarmSettings> = Object.freeze({
|
|
30
50
|
autoName: true,
|
|
31
51
|
colorPalette: "muted",
|
|
@@ -38,6 +58,9 @@ export const DEFAULT_SWARM_SETTINGS: Readonly<SwarmSettings> = Object.freeze({
|
|
|
38
58
|
leaderRecycling: DEFAULT_LEADER_RECYCLING_SETTINGS,
|
|
39
59
|
ledger: DEFAULT_LEDGER_SETTINGS,
|
|
40
60
|
budget: DEFAULT_SWARM_BUDGET_SETTINGS,
|
|
61
|
+
cacheWarming: DEFAULT_CACHE_WARMING_SETTINGS,
|
|
62
|
+
missionCountdown: DEFAULT_MISSION_COUNTDOWN_SETTINGS,
|
|
63
|
+
reviewPolicy: DEFAULT_REVIEW_POLICY,
|
|
41
64
|
});
|
|
42
65
|
|
|
43
66
|
export interface LeaderRecyclingSettings {
|
|
@@ -46,6 +69,7 @@ export interface LeaderRecyclingSettings {
|
|
|
46
69
|
softContextPercent: number;
|
|
47
70
|
softContextTokens: number;
|
|
48
71
|
highWaterPercent: number;
|
|
72
|
+
highWaterTokens?: number;
|
|
49
73
|
maxReplacements: number;
|
|
50
74
|
}
|
|
51
75
|
|
|
@@ -62,8 +86,12 @@ export interface SwarmSettings {
|
|
|
62
86
|
leaderRecycling: LeaderRecyclingSettings;
|
|
63
87
|
ledger: SwarmLedgerSettings;
|
|
64
88
|
budget: SwarmBudgetSettings;
|
|
89
|
+
cacheWarming: CacheWarmingSettings;
|
|
90
|
+
missionCountdown: MissionCountdownSettings;
|
|
91
|
+
reviewPolicy: SwarmReviewPolicy;
|
|
65
92
|
profilesDir?: string;
|
|
66
93
|
allowedProfiles?: readonly string[];
|
|
94
|
+
workerPiArgs?: readonly string[];
|
|
67
95
|
}
|
|
68
96
|
|
|
69
97
|
export type SwarmSettingsField = keyof SwarmSettings;
|
|
@@ -134,10 +162,36 @@ const SETTING_FIELDS = [
|
|
|
134
162
|
"leaderRecycling",
|
|
135
163
|
"ledger",
|
|
136
164
|
"budget",
|
|
165
|
+
"cacheWarming",
|
|
166
|
+
"missionCountdown",
|
|
167
|
+
"reviewPolicy",
|
|
137
168
|
"profilesDir",
|
|
138
169
|
"allowedProfiles",
|
|
170
|
+
"workerPiArgs",
|
|
139
171
|
] as const satisfies readonly SwarmSettingsField[];
|
|
140
172
|
const SETTING_FIELD_SET = new Set<string>(SETTING_FIELDS);
|
|
173
|
+
const RESERVED_WORKER_PI_FLAGS = new Set([
|
|
174
|
+
"--",
|
|
175
|
+
"--name",
|
|
176
|
+
"-n",
|
|
177
|
+
"--mode",
|
|
178
|
+
"--print",
|
|
179
|
+
"-p",
|
|
180
|
+
"--no-session",
|
|
181
|
+
"--session",
|
|
182
|
+
"--session-id",
|
|
183
|
+
"--continue",
|
|
184
|
+
"-c",
|
|
185
|
+
"--resume",
|
|
186
|
+
"-r",
|
|
187
|
+
"--fork",
|
|
188
|
+
"--help",
|
|
189
|
+
"-h",
|
|
190
|
+
"--version",
|
|
191
|
+
"-v",
|
|
192
|
+
]);
|
|
193
|
+
const MAX_WORKER_PI_ARGS = 32;
|
|
194
|
+
const MAX_WORKER_PI_ARG_LENGTH = 256;
|
|
141
195
|
|
|
142
196
|
export function swarmSettingsFilePath(): string {
|
|
143
197
|
return join(getAgentDir(), SWARM_SETTINGS_FILE);
|
|
@@ -169,6 +223,14 @@ function normalizeLeaderRecycling(value: unknown): { settings: LeaderRecyclingSe
|
|
|
169
223
|
(minimum: number, maximum: number) =>
|
|
170
224
|
(candidate: unknown): candidate is number =>
|
|
171
225
|
typeof candidate === "number" && Number.isInteger(candidate) && candidate >= minimum && candidate <= maximum;
|
|
226
|
+
let highWaterTokens: number | undefined;
|
|
227
|
+
if (value.highWaterTokens !== undefined) {
|
|
228
|
+
if (integer(1, 10_000_000)(value.highWaterTokens)) {
|
|
229
|
+
highWaterTokens = value.highWaterTokens;
|
|
230
|
+
} else {
|
|
231
|
+
warnings.push("leaderRecycling.highWaterTokens must be an integer from 1 to 10000000; ignoring invalid value.");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
172
234
|
return {
|
|
173
235
|
settings: {
|
|
174
236
|
enabled: read(
|
|
@@ -184,12 +246,134 @@ function normalizeLeaderRecycling(value: unknown): { settings: LeaderRecyclingSe
|
|
|
184
246
|
softContextPercent: read("softContextPercent", integer(1, 100), "must be an integer from 1 to 100"),
|
|
185
247
|
softContextTokens: read("softContextTokens", integer(1, 10_000_000), "must be an integer from 1 to 10000000"),
|
|
186
248
|
highWaterPercent: read("highWaterPercent", integer(1, 100), "must be an integer from 1 to 100"),
|
|
249
|
+
...(highWaterTokens !== undefined ? { highWaterTokens } : {}),
|
|
187
250
|
maxReplacements: read("maxReplacements", integer(0, 10), "must be an integer from 0 to 10"),
|
|
188
251
|
},
|
|
189
252
|
warnings,
|
|
190
253
|
};
|
|
191
254
|
}
|
|
192
255
|
|
|
256
|
+
function normalizeCacheWarmingSettings(value: unknown): { settings: CacheWarmingSettings; warnings: string[] } {
|
|
257
|
+
if (value === undefined) return { settings: { ...DEFAULT_CACHE_WARMING_SETTINGS }, warnings: [] };
|
|
258
|
+
if (!isRecord(value)) {
|
|
259
|
+
return {
|
|
260
|
+
settings: { ...DEFAULT_CACHE_WARMING_SETTINGS },
|
|
261
|
+
warnings: ["cacheWarming must be an object; using all cacheWarming defaults."],
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const warnings: string[] = [];
|
|
265
|
+
let enabled = DEFAULT_CACHE_WARMING_SETTINGS.enabled;
|
|
266
|
+
if (value.enabled !== undefined) {
|
|
267
|
+
if (typeof value.enabled === "boolean") enabled = value.enabled;
|
|
268
|
+
else warnings.push(`cacheWarming.enabled must be a boolean; using ${String(enabled)}.`);
|
|
269
|
+
}
|
|
270
|
+
let maxWaitDurationMs = DEFAULT_CACHE_WARMING_SETTINGS.maxWaitDurationMs;
|
|
271
|
+
if (value.maxWaitDurationMs !== undefined) {
|
|
272
|
+
if (
|
|
273
|
+
typeof value.maxWaitDurationMs === "number" &&
|
|
274
|
+
Number.isInteger(value.maxWaitDurationMs) &&
|
|
275
|
+
value.maxWaitDurationMs >= 60_000 &&
|
|
276
|
+
value.maxWaitDurationMs <= 3_600_000
|
|
277
|
+
) {
|
|
278
|
+
maxWaitDurationMs = value.maxWaitDurationMs;
|
|
279
|
+
} else {
|
|
280
|
+
warnings.push(
|
|
281
|
+
`cacheWarming.maxWaitDurationMs must be an integer from 60000 to 3600000; using ${String(maxWaitDurationMs)}.`,
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
let maxRefreshesPerWait = DEFAULT_CACHE_WARMING_SETTINGS.maxRefreshesPerWait;
|
|
286
|
+
if (value.maxRefreshesPerWait !== undefined) {
|
|
287
|
+
if (
|
|
288
|
+
typeof value.maxRefreshesPerWait === "number" &&
|
|
289
|
+
Number.isInteger(value.maxRefreshesPerWait) &&
|
|
290
|
+
value.maxRefreshesPerWait >= 1 &&
|
|
291
|
+
value.maxRefreshesPerWait <= 30
|
|
292
|
+
) {
|
|
293
|
+
maxRefreshesPerWait = value.maxRefreshesPerWait;
|
|
294
|
+
} else {
|
|
295
|
+
warnings.push(
|
|
296
|
+
`cacheWarming.maxRefreshesPerWait must be an integer from 1 to 30; using ${String(maxRefreshesPerWait)}.`,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return { settings: { enabled, maxWaitDurationMs, maxRefreshesPerWait }, warnings };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function normalizeMissionCountdownSettings(value: unknown): {
|
|
304
|
+
settings: MissionCountdownSettings;
|
|
305
|
+
warnings: string[];
|
|
306
|
+
} {
|
|
307
|
+
if (value === undefined) return { settings: { ...DEFAULT_MISSION_COUNTDOWN_SETTINGS }, warnings: [] };
|
|
308
|
+
if (!isRecord(value)) {
|
|
309
|
+
return {
|
|
310
|
+
settings: { ...DEFAULT_MISSION_COUNTDOWN_SETTINGS },
|
|
311
|
+
warnings: ["missionCountdown must be an object; using all missionCountdown defaults."],
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const warnings: string[] = [];
|
|
315
|
+
let enabled = DEFAULT_MISSION_COUNTDOWN_SETTINGS.enabled;
|
|
316
|
+
if (value.enabled !== undefined) {
|
|
317
|
+
if (typeof value.enabled === "boolean") enabled = value.enabled;
|
|
318
|
+
else warnings.push(`missionCountdown.enabled must be a boolean; using ${String(enabled)}.`);
|
|
319
|
+
}
|
|
320
|
+
let requireBeforeSpawn = DEFAULT_MISSION_COUNTDOWN_SETTINGS.requireBeforeSpawn;
|
|
321
|
+
if (value.requireBeforeSpawn !== undefined) {
|
|
322
|
+
if (typeof value.requireBeforeSpawn === "boolean") requireBeforeSpawn = value.requireBeforeSpawn;
|
|
323
|
+
else {
|
|
324
|
+
warnings.push(`missionCountdown.requireBeforeSpawn must be a boolean; using ${String(requireBeforeSpawn)}.`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
let minMinutes = DEFAULT_MISSION_COUNTDOWN_SETTINGS.minMinutes;
|
|
328
|
+
if (value.minMinutes !== undefined) {
|
|
329
|
+
if (
|
|
330
|
+
typeof value.minMinutes === "number" &&
|
|
331
|
+
Number.isFinite(value.minMinutes) &&
|
|
332
|
+
value.minMinutes > 0 &&
|
|
333
|
+
value.minMinutes <= 60
|
|
334
|
+
) {
|
|
335
|
+
minMinutes = value.minMinutes;
|
|
336
|
+
} else {
|
|
337
|
+
warnings.push(`missionCountdown.minMinutes must be a positive number <= 60; using ${String(minMinutes)}.`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
let maxMinutes = DEFAULT_MISSION_COUNTDOWN_SETTINGS.maxMinutes;
|
|
341
|
+
if (value.maxMinutes !== undefined) {
|
|
342
|
+
if (
|
|
343
|
+
typeof value.maxMinutes === "number" &&
|
|
344
|
+
Number.isFinite(value.maxMinutes) &&
|
|
345
|
+
value.maxMinutes >= minMinutes &&
|
|
346
|
+
value.maxMinutes <= 480
|
|
347
|
+
) {
|
|
348
|
+
maxMinutes = value.maxMinutes;
|
|
349
|
+
} else {
|
|
350
|
+
warnings.push(
|
|
351
|
+
`missionCountdown.maxMinutes must be a number from ${String(minMinutes)} to 480; using ${String(maxMinutes)}.`,
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (maxMinutes < minMinutes) maxMinutes = minMinutes;
|
|
356
|
+
let wrapUpGraceMs = DEFAULT_MISSION_COUNTDOWN_SETTINGS.wrapUpGraceMs;
|
|
357
|
+
if (value.wrapUpGraceMs !== undefined) {
|
|
358
|
+
if (
|
|
359
|
+
typeof value.wrapUpGraceMs === "number" &&
|
|
360
|
+
Number.isInteger(value.wrapUpGraceMs) &&
|
|
361
|
+
value.wrapUpGraceMs >= 100 &&
|
|
362
|
+
value.wrapUpGraceMs <= 3_600_000
|
|
363
|
+
) {
|
|
364
|
+
wrapUpGraceMs = value.wrapUpGraceMs;
|
|
365
|
+
} else {
|
|
366
|
+
warnings.push(
|
|
367
|
+
`missionCountdown.wrapUpGraceMs must be an integer from 100 to 3600000; using ${String(wrapUpGraceMs)}.`,
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
settings: { enabled, requireBeforeSpawn, minMinutes, maxMinutes, wrapUpGraceMs },
|
|
373
|
+
warnings,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
193
377
|
function normalizeLedgerSettings(value: unknown): { settings: SwarmLedgerSettings; warnings: string[] } {
|
|
194
378
|
if (value === undefined) return { settings: { ...DEFAULT_LEDGER_SETTINGS }, warnings: [] };
|
|
195
379
|
if (!isRecord(value)) {
|
|
@@ -371,6 +555,19 @@ export function normalizeSwarmSettingsDocument(value: unknown): NormalizedSwarmS
|
|
|
371
555
|
const budget = normalizeBudgetSettings(value.budget);
|
|
372
556
|
settings.budget = budget.settings;
|
|
373
557
|
if (Object.hasOwn(value, "budget")) sources.budget = "user";
|
|
558
|
+
const cacheWarming = normalizeCacheWarmingSettings(value.cacheWarming);
|
|
559
|
+
settings.cacheWarming = cacheWarming.settings;
|
|
560
|
+
if (Object.hasOwn(value, "cacheWarming")) sources.cacheWarming = "user";
|
|
561
|
+
const missionCountdown = normalizeMissionCountdownSettings(value.missionCountdown);
|
|
562
|
+
settings.missionCountdown = missionCountdown.settings;
|
|
563
|
+
if (Object.hasOwn(value, "missionCountdown")) sources.missionCountdown = "user";
|
|
564
|
+
if (Object.hasOwn(value, "reviewPolicy")) {
|
|
565
|
+
if (value.reviewPolicy !== "off" && value.reviewPolicy !== "suggest" && value.reviewPolicy !== "required") {
|
|
566
|
+
return undefined;
|
|
567
|
+
}
|
|
568
|
+
settings.reviewPolicy = value.reviewPolicy;
|
|
569
|
+
sources.reviewPolicy = "user";
|
|
570
|
+
}
|
|
374
571
|
if (Object.hasOwn(value, "profilesDir")) {
|
|
375
572
|
if (
|
|
376
573
|
typeof value.profilesDir !== "string" ||
|
|
@@ -392,7 +589,37 @@ export function normalizeSwarmSettingsDocument(value: unknown): NormalizedSwarmS
|
|
|
392
589
|
settings.allowedProfiles = [...new Set(value.allowedProfiles)];
|
|
393
590
|
sources.allowedProfiles = "user";
|
|
394
591
|
}
|
|
395
|
-
|
|
592
|
+
if (Object.hasOwn(value, "workerPiArgs")) {
|
|
593
|
+
if (!Array.isArray(value.workerPiArgs) || value.workerPiArgs.length > MAX_WORKER_PI_ARGS) {
|
|
594
|
+
return undefined;
|
|
595
|
+
}
|
|
596
|
+
const normalizedArgs: string[] = [];
|
|
597
|
+
for (const item of value.workerPiArgs) {
|
|
598
|
+
if (typeof item !== "string") return undefined;
|
|
599
|
+
const trimmed = item.trim();
|
|
600
|
+
if (
|
|
601
|
+
trimmed.length === 0 ||
|
|
602
|
+
trimmed.length > MAX_WORKER_PI_ARG_LENGTH ||
|
|
603
|
+
trimmed.includes("\0") ||
|
|
604
|
+
trimmed.includes("\n") ||
|
|
605
|
+
trimmed.includes("\r")
|
|
606
|
+
) {
|
|
607
|
+
return undefined;
|
|
608
|
+
}
|
|
609
|
+
const flagHead = trimmed.includes("=") ? trimmed.slice(0, trimmed.indexOf("=")) : trimmed;
|
|
610
|
+
if (RESERVED_WORKER_PI_FLAGS.has(flagHead)) return undefined;
|
|
611
|
+
normalizedArgs.push(trimmed);
|
|
612
|
+
}
|
|
613
|
+
settings.workerPiArgs = normalizedArgs;
|
|
614
|
+
sources.workerPiArgs = "user";
|
|
615
|
+
}
|
|
616
|
+
const warnings = [
|
|
617
|
+
...leaderRecycling.warnings,
|
|
618
|
+
...ledger.warnings,
|
|
619
|
+
...budget.warnings,
|
|
620
|
+
...cacheWarming.warnings,
|
|
621
|
+
...missionCountdown.warnings,
|
|
622
|
+
];
|
|
396
623
|
return { settings, sources, ...(warnings.length > 0 ? { warnings } : {}) };
|
|
397
624
|
}
|
|
398
625
|
|
|
@@ -455,12 +682,16 @@ export function createInMemorySwarmSettingsRuntime(initial: SwarmSettingsPatch =
|
|
|
455
682
|
...(canonical.confirmSessionLaunch !== undefined ? { confirmSessionLaunch: "user" as const } : {}),
|
|
456
683
|
...(canonical.externalCommand ? { externalCommand: "user" as const } : {}),
|
|
457
684
|
...(canonical.pinToLeadWorkspace !== undefined ? { pinToLeadWorkspace: "user" as const } : {}),
|
|
685
|
+
...(canonical.workerPiArgs !== undefined ? { workerPiArgs: "user" as const } : {}),
|
|
458
686
|
...(canonical.exposeLeadMcp !== undefined ? { exposeLeadMcp: "user" as const } : {}),
|
|
459
687
|
...(canonical.isolation !== undefined ? { isolation: "user" as const } : {}),
|
|
460
688
|
...(canonical.resourceLeases !== undefined ? { resourceLeases: "user" as const } : {}),
|
|
461
689
|
...(canonical.leaderRecycling !== undefined ? { leaderRecycling: "user" as const } : {}),
|
|
462
690
|
...(canonical.ledger !== undefined ? { ledger: "user" as const } : {}),
|
|
463
691
|
...(canonical.budget !== undefined ? { budget: "user" as const } : {}),
|
|
692
|
+
...(canonical.cacheWarming !== undefined ? { cacheWarming: "user" as const } : {}),
|
|
693
|
+
...(canonical.missionCountdown !== undefined ? { missionCountdown: "user" as const } : {}),
|
|
694
|
+
...(canonical.reviewPolicy !== undefined ? { reviewPolicy: "user" as const } : {}),
|
|
464
695
|
...(canonical.profilesDir !== undefined ? { profilesDir: "user" as const } : {}),
|
|
465
696
|
...(canonical.allowedProfiles !== undefined ? { allowedProfiles: "user" as const } : {}),
|
|
466
697
|
},
|
|
@@ -540,6 +771,18 @@ export function createSwarmSettingsRuntime(options: SwarmSettingsRuntimeOptions
|
|
|
540
771
|
...canonicalPatch.budget,
|
|
541
772
|
};
|
|
542
773
|
}
|
|
774
|
+
if (canonicalPatch.cacheWarming && isRecord(latest.document.cacheWarming)) {
|
|
775
|
+
document.cacheWarming = {
|
|
776
|
+
...latest.document.cacheWarming,
|
|
777
|
+
...canonicalPatch.cacheWarming,
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
if (canonicalPatch.missionCountdown && isRecord(latest.document.missionCountdown)) {
|
|
781
|
+
document.missionCountdown = {
|
|
782
|
+
...latest.document.missionCountdown,
|
|
783
|
+
...canonicalPatch.missionCountdown,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
543
786
|
const normalized = normalizeSwarmSettingsDocument(document);
|
|
544
787
|
if (!normalized) throw new Error("Refusing to publish invalid Pi Agent Swarm settings.");
|
|
545
788
|
await publishSettingsDocument(document, getPath(), operations);
|
|
@@ -664,8 +907,12 @@ function builtInSources(): Record<SwarmSettingsField, SwarmSettingsSource> {
|
|
|
664
907
|
leaderRecycling: "built-in",
|
|
665
908
|
ledger: "built-in",
|
|
666
909
|
budget: "built-in",
|
|
910
|
+
cacheWarming: "built-in",
|
|
911
|
+
missionCountdown: "built-in",
|
|
912
|
+
reviewPolicy: "built-in",
|
|
667
913
|
profilesDir: "built-in",
|
|
668
914
|
allowedProfiles: "built-in",
|
|
915
|
+
workerPiArgs: "built-in",
|
|
669
916
|
};
|
|
670
917
|
}
|
|
671
918
|
|
|
@@ -679,6 +926,9 @@ function defaultSettings(): SwarmSettings {
|
|
|
679
926
|
standard: { ...DEFAULT_STANDARD_BUDGET },
|
|
680
927
|
heavy: { ...DEFAULT_HEAVY_BUDGET },
|
|
681
928
|
},
|
|
929
|
+
cacheWarming: { ...DEFAULT_CACHE_WARMING_SETTINGS },
|
|
930
|
+
missionCountdown: { ...DEFAULT_MISSION_COUNTDOWN_SETTINGS },
|
|
931
|
+
reviewPolicy: DEFAULT_REVIEW_POLICY,
|
|
682
932
|
};
|
|
683
933
|
}
|
|
684
934
|
|
|
@@ -694,9 +944,12 @@ function freezeState(state: SwarmSettingsState): Readonly<SwarmSettingsState> {
|
|
|
694
944
|
standard: Object.freeze({ ...state.settings.budget.standard }),
|
|
695
945
|
heavy: Object.freeze({ ...state.settings.budget.heavy }),
|
|
696
946
|
}),
|
|
947
|
+
cacheWarming: Object.freeze({ ...state.settings.cacheWarming }),
|
|
948
|
+
missionCountdown: Object.freeze({ ...state.settings.missionCountdown }),
|
|
697
949
|
...(state.settings.allowedProfiles
|
|
698
950
|
? { allowedProfiles: Object.freeze([...state.settings.allowedProfiles]) }
|
|
699
951
|
: {}),
|
|
952
|
+
...(state.settings.workerPiArgs ? { workerPiArgs: Object.freeze([...state.settings.workerPiArgs]) } : {}),
|
|
700
953
|
}),
|
|
701
954
|
sources: Object.freeze({ ...state.sources }),
|
|
702
955
|
...(state.warnings ? { warnings: Object.freeze([...state.warnings]) } : {}),
|