pi-subagent-manager 1.10.0 → 1.12.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.
Files changed (95) hide show
  1. package/README.md +9 -9
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +790 -0
  4. package/dist/orch/checklist-integration.js +176 -0
  5. package/dist/orch/context-entries.js +6 -0
  6. package/dist/orch/cost-ledger.js +38 -0
  7. package/dist/orch/diagnostics.js +86 -0
  8. package/dist/orch/extensions.js +66 -0
  9. package/dist/orch/housekeeping-usage.js +22 -0
  10. package/dist/orch/housekeeping.js +248 -0
  11. package/dist/orch/inherited-tools.js +57 -0
  12. package/dist/orch/mailbox.js +195 -0
  13. package/dist/orch/manager.js +970 -0
  14. package/dist/orch/paths.js +69 -0
  15. package/dist/orch/prompt.js +30 -0
  16. package/dist/orch/registry.js +115 -0
  17. package/dist/orch/runtime.js +835 -0
  18. package/dist/orch/tools.js +112 -0
  19. package/dist/orch/transcript.js +165 -0
  20. package/dist/prefs/agent-import.js +188 -0
  21. package/dist/prefs/config.js +878 -0
  22. package/dist/prefs/import-discovery.js +547 -0
  23. package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +0 -1
  24. package/dist/prefs/models.js +56 -0
  25. package/dist/prefs/settings.js +491 -0
  26. package/dist/types.js +1 -0
  27. package/dist/ui/agent-loader.js +63 -0
  28. package/dist/ui/agent-navigation-editor.js +168 -0
  29. package/dist/ui/cost-footer.js +209 -0
  30. package/dist/ui/dialog.js +505 -0
  31. package/dist/ui/import-picker.js +191 -0
  32. package/dist/ui/live-agent-view.js +527 -0
  33. package/dist/ui/model-picker.js +529 -0
  34. package/dist/ui/settings-ui.js +671 -0
  35. package/dist/ui/status-ui.js +470 -0
  36. package/dist/ui/thread-tree.js +142 -0
  37. package/dist/ui/tool-picker.js +331 -0
  38. package/dist/ui/transcript-tool.js +91 -0
  39. package/dist/ui/ui.js +1019 -0
  40. package/package.json +17 -5
  41. package/docs/assets/subagent-manager-demo.gif +0 -0
  42. package/docs/async-lifecycle.md +0 -153
  43. package/docs/custom-agents.md +0 -154
  44. package/docs/default-agents.md +0 -95
  45. package/docs/demo.md +0 -63
  46. package/docs/development.md +0 -74
  47. package/docs/importing-agents.md +0 -41
  48. package/docs/pi-footer.md +0 -128
  49. package/docs/research-claude.md +0 -258
  50. package/docs/research-codex.md +0 -143
  51. package/docs/research-default-agent-models.md +0 -121
  52. package/docs/research-model-audit-2026-10.md +0 -154
  53. package/docs/research-model-roles-coding.md +0 -99
  54. package/docs/research-model-roles-writing.md +0 -78
  55. package/docs/research-researcher-workflow.md +0 -97
  56. package/docs/settings.md +0 -293
  57. package/docs/subagent-extension-limitations.md +0 -98
  58. package/docs/threads.md +0 -73
  59. package/docs/tools-and-ui.md +0 -129
  60. package/src/index.ts +0 -920
  61. package/src/orch/checklist-integration.ts +0 -230
  62. package/src/orch/context-entries.ts +0 -15
  63. package/src/orch/cost-ledger.ts +0 -56
  64. package/src/orch/diagnostics.ts +0 -95
  65. package/src/orch/extensions.ts +0 -83
  66. package/src/orch/housekeeping-usage.ts +0 -47
  67. package/src/orch/housekeeping.ts +0 -348
  68. package/src/orch/inherited-tools.ts +0 -84
  69. package/src/orch/mailbox.ts +0 -261
  70. package/src/orch/manager.ts +0 -1084
  71. package/src/orch/paths.ts +0 -73
  72. package/src/orch/prompt.ts +0 -39
  73. package/src/orch/registry.ts +0 -168
  74. package/src/orch/runtime.ts +0 -1041
  75. package/src/orch/tools.ts +0 -190
  76. package/src/orch/transcript.ts +0 -186
  77. package/src/prefs/agent-import.ts +0 -245
  78. package/src/prefs/config.ts +0 -1017
  79. package/src/prefs/import-discovery.ts +0 -643
  80. package/src/prefs/models.ts +0 -74
  81. package/src/prefs/settings.ts +0 -614
  82. package/src/types.ts +0 -271
  83. package/src/ui/agent-loader.ts +0 -98
  84. package/src/ui/agent-navigation-editor.ts +0 -233
  85. package/src/ui/cost-footer.ts +0 -230
  86. package/src/ui/dialog.ts +0 -678
  87. package/src/ui/import-picker.ts +0 -231
  88. package/src/ui/live-agent-view.ts +0 -600
  89. package/src/ui/model-picker.ts +0 -701
  90. package/src/ui/settings-ui.ts +0 -830
  91. package/src/ui/status-ui.ts +0 -628
  92. package/src/ui/thread-tree.ts +0 -173
  93. package/src/ui/tool-picker.ts +0 -398
  94. package/src/ui/transcript-tool.ts +0 -142
  95. package/src/ui/ui.ts +0 -1407
@@ -0,0 +1,491 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { closeSync, constants, fchmodSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ export const SUBAGENT_MODES = ["off", "opportunistic", "orchestration"];
5
+ export const WIDGET_MODES = ["full", "minimal"];
6
+ const COST_DISPLAY_MODES = ["pi-footer-event", "pi-footer-status", "pi-status"];
7
+ const COST_VALUES = ["subagents", "total"];
8
+ export const COST_ICONS = ["money", "coins", "wallet"];
9
+ export const LOADER_STYLES = [
10
+ "circle",
11
+ "braille",
12
+ "hourglass",
13
+ "ascii",
14
+ "ascii-star",
15
+ "ascii-pulse",
16
+ ];
17
+ export const TOOL_FILTERING_MODES = ["allowed", "all-except-blocked", "all"];
18
+ export const MODEL_SELECTION_MODES = [
19
+ "pick-first-available",
20
+ "pick-first-scoped",
21
+ "use-current",
22
+ ];
23
+ export function settingsValueEqual(a, b) {
24
+ return JSON.stringify(a) === JSON.stringify(b);
25
+ }
26
+ export const DEFAULT_MANAGER_SETTINGS = {
27
+ maxLevels: 3,
28
+ maxConcurrent: 16,
29
+ maxThreads: 64,
30
+ modelSelection: "pick-first-scoped",
31
+ subagentMode: "opportunistic",
32
+ toolFiltering: "all-except-blocked",
33
+ widgetMode: "full",
34
+ costDisplay: "pi-footer-status",
35
+ costValue: "subagents",
36
+ costIcon: "money",
37
+ nerdFontIcons: false,
38
+ loaderStyle: "circle",
39
+ finalRecap: false,
40
+ subagentExtensions: false,
41
+ checklistIntegration: false,
42
+ housekeepingEnabled: false,
43
+ housekeepingModel: "",
44
+ };
45
+ const HOUSEKEEPING_MODEL = /^[^\s/]+\/[^\s]+$/;
46
+ const isHousekeepingModel = (value) => typeof value === "string" && (value === "" || HOUSEKEEPING_MODEL.test(value));
47
+ const KEYS = [
48
+ "maxLevels",
49
+ "maxConcurrent",
50
+ "maxThreads",
51
+ "modelSelection",
52
+ "subagentMode",
53
+ "toolFiltering",
54
+ "widgetMode",
55
+ "costDisplay",
56
+ "costValue",
57
+ "costIcon",
58
+ "nerdFontIcons",
59
+ "loaderStyle",
60
+ "finalRecap",
61
+ "subagentExtensions",
62
+ "checklistIntegration",
63
+ "housekeepingEnabled",
64
+ "housekeepingModel",
65
+ ];
66
+ const MAX_LEVELS = 32;
67
+ function errorCode(error) {
68
+ return typeof error === "object" && error !== null && "code" in error
69
+ ? String(error.code)
70
+ : undefined;
71
+ }
72
+ function lstatIfPresent(path) {
73
+ try {
74
+ return lstatSync(path);
75
+ }
76
+ catch (error) {
77
+ if (errorCode(error) === "ENOENT")
78
+ return undefined;
79
+ throw error;
80
+ }
81
+ }
82
+ function assertNotSymlinkPath(path) {
83
+ const stat = lstatIfPresent(path);
84
+ if (stat?.isSymbolicLink())
85
+ throw new Error(`Unsafe symlink path: ${path}`);
86
+ return stat;
87
+ }
88
+ function isSupportedKey(key) {
89
+ return KEYS.includes(key);
90
+ }
91
+ function positiveSafeInteger(value) {
92
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
93
+ }
94
+ function requirement(key) {
95
+ if (key === "subagentExtensions")
96
+ return "subagentExtensions must be a boolean or an array of absolute file paths";
97
+ if (key === "nerdFontIcons" ||
98
+ key === "finalRecap" ||
99
+ key === "checklistIntegration" ||
100
+ key === "housekeepingEnabled")
101
+ return `${key} must be a boolean`;
102
+ if (key === "housekeepingModel")
103
+ return "housekeepingModel must be empty or provider/model-id";
104
+ if (key === "subagentMode")
105
+ return "subagentMode must be off, opportunistic or orchestration";
106
+ if (key === "widgetMode")
107
+ return "widgetMode must be full or minimal";
108
+ if (key === "costDisplay")
109
+ return "costDisplay must be pi-footer-event, pi-footer-status or pi-status";
110
+ if (key === "costValue")
111
+ return "costValue must be subagents or total";
112
+ if (key === "costIcon")
113
+ return "costIcon must be money, coins or wallet";
114
+ if (key === "loaderStyle")
115
+ return `loaderStyle must be one of: ${LOADER_STYLES.join(", ")}`;
116
+ if (key === "toolFiltering")
117
+ return "toolFiltering must be allowed, all-except-blocked or all";
118
+ if (key === "modelSelection")
119
+ return "modelSelection must be pick-first-available, pick-first-scoped or use-current";
120
+ return `${key} must be a positive safe integer`;
121
+ }
122
+ function parseSettings(content) {
123
+ let parsed;
124
+ try {
125
+ parsed = JSON.parse(content);
126
+ }
127
+ catch (error) {
128
+ const detail = error instanceof Error ? error.message : String(error);
129
+ throw new Error(`Invalid JSON: ${detail}`);
130
+ }
131
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
132
+ throw new Error("Settings must be a JSON object");
133
+ }
134
+ const record = parsed;
135
+ for (const key of Object.keys(record)) {
136
+ if (!isSupportedKey(key) && key !== "scopedModelFiltering")
137
+ throw new Error(`Unknown settings key: ${key}`);
138
+ }
139
+ const layer = {};
140
+ if (Object.hasOwn(record, "scopedModelFiltering")) {
141
+ if (typeof record.scopedModelFiltering !== "boolean")
142
+ throw new Error("scopedModelFiltering must be a boolean");
143
+ if (!Object.hasOwn(record, "modelSelection"))
144
+ layer.modelSelection = record.scopedModelFiltering
145
+ ? "pick-first-scoped"
146
+ : "pick-first-available";
147
+ }
148
+ for (const key of KEYS) {
149
+ if (!Object.hasOwn(record, key))
150
+ continue;
151
+ const value = record[key];
152
+ if (key === "nerdFontIcons" ||
153
+ key === "finalRecap" ||
154
+ key === "checklistIntegration" ||
155
+ key === "housekeepingEnabled") {
156
+ if (typeof value !== "boolean")
157
+ throw new Error(requirement(key));
158
+ layer[key] = value;
159
+ continue;
160
+ }
161
+ if (key === "subagentExtensions") {
162
+ if (typeof value !== "boolean" &&
163
+ !(Array.isArray(value) &&
164
+ value.every((entry) => typeof entry === "string" &&
165
+ entry.length > 0 &&
166
+ resolve(entry) === entry &&
167
+ !entry.includes("\0"))))
168
+ throw new Error(requirement(key));
169
+ layer.subagentExtensions =
170
+ typeof value === "boolean" ? value : [...new Set(value)].sort();
171
+ continue;
172
+ }
173
+ if (key === "housekeepingModel") {
174
+ if (!isHousekeepingModel(value))
175
+ throw new Error(requirement(key));
176
+ layer.housekeepingModel = value;
177
+ continue;
178
+ }
179
+ if (key === "subagentMode") {
180
+ if (!SUBAGENT_MODES.includes(value))
181
+ throw new Error(requirement(key));
182
+ layer.subagentMode = value;
183
+ continue;
184
+ }
185
+ if (key === "toolFiltering") {
186
+ if (!TOOL_FILTERING_MODES.includes(value))
187
+ throw new Error(requirement(key));
188
+ layer.toolFiltering = value;
189
+ continue;
190
+ }
191
+ if (key === "widgetMode") {
192
+ if (!WIDGET_MODES.includes(value))
193
+ throw new Error(requirement(key));
194
+ layer.widgetMode = value;
195
+ continue;
196
+ }
197
+ if (key === "costDisplay") {
198
+ if (!COST_DISPLAY_MODES.includes(value))
199
+ throw new Error(requirement(key));
200
+ layer.costDisplay = value;
201
+ continue;
202
+ }
203
+ if (key === "costValue") {
204
+ if (!COST_VALUES.includes(value))
205
+ throw new Error(requirement(key));
206
+ layer.costValue = value;
207
+ continue;
208
+ }
209
+ if (key === "costIcon") {
210
+ if (!COST_ICONS.includes(value))
211
+ throw new Error(requirement(key));
212
+ layer.costIcon = value;
213
+ continue;
214
+ }
215
+ if (key === "loaderStyle") {
216
+ if (!LOADER_STYLES.includes(value))
217
+ throw new Error(requirement(key));
218
+ layer.loaderStyle = value;
219
+ continue;
220
+ }
221
+ if (key === "modelSelection") {
222
+ if (!MODEL_SELECTION_MODES.includes(value))
223
+ throw new Error(requirement(key));
224
+ layer.modelSelection = value;
225
+ continue;
226
+ }
227
+ if (!positiveSafeInteger(value))
228
+ throw new Error(requirement(key));
229
+ if (key === "maxLevels" && value > MAX_LEVELS)
230
+ throw new Error("maxLevels must be <= 32");
231
+ layer[key] = value;
232
+ }
233
+ return layer;
234
+ }
235
+ function layer(base, segments) {
236
+ let current = resolve(base);
237
+ const directories = [current];
238
+ for (const segment of segments) {
239
+ current = join(current, segment);
240
+ directories.push(current);
241
+ }
242
+ return { filePath: join(current, "settings.json"), directories };
243
+ }
244
+ function settingsFileExists(entry) {
245
+ for (const directory of entry.directories) {
246
+ const stat = assertNotSymlinkPath(directory);
247
+ if (!stat)
248
+ return false;
249
+ if (!stat.isDirectory())
250
+ throw new Error(`Settings directory must be a directory: ${directory}`);
251
+ }
252
+ const stat = assertNotSymlinkPath(entry.filePath);
253
+ if (!stat)
254
+ return false;
255
+ if (!stat.isFile())
256
+ throw new Error(`Settings must be a regular file: ${entry.filePath}`);
257
+ return true;
258
+ }
259
+ function detail(error) {
260
+ return error instanceof Error ? error.message : String(error);
261
+ }
262
+ export function loadManagerSettingsLayers(options) {
263
+ const result = {
264
+ settings: { ...DEFAULT_MANAGER_SETTINGS },
265
+ diagnostics: [],
266
+ global: {},
267
+ project: {},
268
+ scope: "user",
269
+ };
270
+ const layers = [
271
+ ["global", layer(options.agentDir, ["subagent-manager"])],
272
+ ];
273
+ if (options.includeProject)
274
+ layers.push(["project", layer(options.cwd, [".pi", "agent", "subagent-manager"])]);
275
+ for (const [scope, entry] of layers) {
276
+ try {
277
+ if (!settingsFileExists(entry))
278
+ continue;
279
+ if (scope === "project")
280
+ result.scope = "project";
281
+ const parsed = parseSettings(readFileSync(entry.filePath, "utf8"));
282
+ result[scope] = parsed;
283
+ Object.assign(result.settings, parsed);
284
+ }
285
+ catch (error) {
286
+ result.diagnostics.push(`${entry.filePath}: ${detail(error)}`);
287
+ }
288
+ }
289
+ return result;
290
+ }
291
+ export function loadManagerSettings(options) {
292
+ const { settings, diagnostics } = loadManagerSettingsLayers(options);
293
+ return { settings, diagnostics };
294
+ }
295
+ function serializedSettings(settings) {
296
+ if (settings === null || typeof settings !== "object" || Array.isArray(settings)) {
297
+ throw new Error("Settings must be a JSON object");
298
+ }
299
+ for (const key of Object.keys(settings)) {
300
+ if (!isSupportedKey(key))
301
+ throw new Error(`Unknown settings key: ${key}`);
302
+ }
303
+ const parsed = parseSettings(JSON.stringify(settings));
304
+ for (const key of KEYS) {
305
+ if (!Object.hasOwn(parsed, key))
306
+ throw new Error(requirement(key));
307
+ }
308
+ const serialized = `${JSON.stringify(parsed, null, 2)}\n`;
309
+ const confirmed = parseSettings(serialized);
310
+ for (const key of KEYS) {
311
+ if (!settingsValueEqual(confirmed[key], parsed[key]))
312
+ throw new Error(requirement(key));
313
+ }
314
+ return serialized;
315
+ }
316
+ function assertExistingDirectory(directory) {
317
+ const stat = assertNotSymlinkPath(directory);
318
+ if (!stat?.isDirectory())
319
+ throw new Error(`Settings directory must be a directory: ${directory}`);
320
+ }
321
+ function ensureOwnedDirectory(directory) {
322
+ let stat = assertNotSymlinkPath(directory);
323
+ if (!stat) {
324
+ try {
325
+ mkdirSync(directory);
326
+ }
327
+ catch (error) {
328
+ if (errorCode(error) !== "EEXIST")
329
+ throw error;
330
+ }
331
+ stat = assertNotSymlinkPath(directory);
332
+ }
333
+ if (!stat?.isDirectory())
334
+ throw new Error(`Settings directory must be a directory: ${directory}`);
335
+ }
336
+ function ensureScopeDirectories(directories) {
337
+ assertExistingDirectory(directories[0]);
338
+ for (let index = 1; index < directories.length; index++) {
339
+ assertExistingDirectory(directories[index - 1]);
340
+ ensureOwnedDirectory(directories[index]);
341
+ }
342
+ }
343
+ function assertRegularFileOrAbsent(filePath) {
344
+ const stat = assertNotSymlinkPath(filePath);
345
+ if (stat && !stat.isFile())
346
+ throw new Error(`Settings must be a regular file: ${filePath}`);
347
+ }
348
+ function exclusiveCreateFlags() {
349
+ return constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW || 0);
350
+ }
351
+ function writeAtomically(entry, content, overwrite = true) {
352
+ const filePath = entry.filePath;
353
+ const temporary = join(dirname(filePath), `.settings.${randomUUID()}.tmp`);
354
+ let created = false;
355
+ try {
356
+ for (const directory of entry.directories)
357
+ assertExistingDirectory(directory);
358
+ assertRegularFileOrAbsent(filePath);
359
+ const fd = openSync(temporary, exclusiveCreateFlags(), 0o600);
360
+ created = true;
361
+ try {
362
+ fchmodSync(fd, 0o600);
363
+ writeFileSync(fd, content);
364
+ }
365
+ finally {
366
+ closeSync(fd);
367
+ }
368
+ for (const directory of entry.directories)
369
+ assertExistingDirectory(directory);
370
+ assertRegularFileOrAbsent(filePath);
371
+ const tempStat = assertNotSymlinkPath(temporary);
372
+ if (!tempStat?.isFile())
373
+ throw new Error(`Settings must be a regular file: ${temporary}`);
374
+ if (overwrite)
375
+ renameSync(temporary, filePath);
376
+ else {
377
+ try {
378
+ linkSync(temporary, filePath);
379
+ }
380
+ catch (error) {
381
+ if (errorCode(error) !== "EEXIST")
382
+ throw error;
383
+ assertRegularFileOrAbsent(filePath);
384
+ }
385
+ }
386
+ }
387
+ finally {
388
+ if (created) {
389
+ try {
390
+ if (lstatIfPresent(temporary))
391
+ unlinkSync(temporary);
392
+ }
393
+ catch {
394
+ }
395
+ }
396
+ }
397
+ }
398
+ export function saveManagerSettings(options) {
399
+ if (options.scope !== "user" && options.scope !== "project") {
400
+ throw new Error("Invalid settings scope");
401
+ }
402
+ if (options.scope === "project" && !options.includeProject) {
403
+ throw new Error("Project settings are not enabled/trusted");
404
+ }
405
+ const content = serializedSettings(options.settings);
406
+ const entry = options.scope === "user"
407
+ ? layer(options.agentDir, ["subagent-manager"])
408
+ : layer(options.cwd, [".pi", "agent", "subagent-manager"]);
409
+ ensureScopeDirectories(entry.directories);
410
+ writeAtomically(entry, content);
411
+ return entry.filePath;
412
+ }
413
+ function assertExpectedLayers(current, expected) {
414
+ if (current.scope !== expected.scope ||
415
+ KEYS.some((key) => !settingsValueEqual(current.global[key], expected.global[key]) ||
416
+ !settingsValueEqual(current.project[key], expected.project[key])) ||
417
+ current.diagnostics.length !== expected.diagnostics.length ||
418
+ current.diagnostics.some((diagnostic, index) => diagnostic !== expected.diagnostics[index])) {
419
+ throw new Error("Settings changed on disk. Reopen settings before saving or switching scope to avoid stale inherited values.");
420
+ }
421
+ }
422
+ export function saveManagerOverrides(options) {
423
+ if (options.scope !== "user" && options.scope !== "project")
424
+ throw new Error("Invalid settings scope");
425
+ if (options.scope === "project" && !options.includeProject)
426
+ throw new Error("Project settings are not enabled/trusted");
427
+ const parsed = parseSettings(serializedSettings(options.settings));
428
+ const current = loadManagerSettingsLayers(options);
429
+ if (options.expectedLayers)
430
+ assertExpectedLayers(current, options.expectedLayers);
431
+ if (options.scope === "project") {
432
+ const globalPath = layer(options.agentDir, ["subagent-manager"]).filePath;
433
+ const globalDiagnostics = current.diagnostics.filter((diagnostic) => diagnostic.startsWith(`${globalPath}:`));
434
+ if (globalDiagnostics.length > 0)
435
+ throw new Error(`Cannot save project overrides while global settings are invalid. Fix global settings and reopen settings. ${globalDiagnostics.join("; ")}`);
436
+ }
437
+ const inherited = options.scope === "user"
438
+ ? DEFAULT_MANAGER_SETTINGS
439
+ : { ...DEFAULT_MANAGER_SETTINGS, ...current.global };
440
+ const overrides = Object.fromEntries(KEYS.filter((key) => !settingsValueEqual(parsed[key], inherited[key])).map((key) => [
441
+ key,
442
+ parsed[key],
443
+ ]));
444
+ const entry = options.scope === "user"
445
+ ? layer(options.agentDir, ["subagent-manager"])
446
+ : layer(options.cwd, [".pi", "agent", "subagent-manager"]);
447
+ ensureScopeDirectories(entry.directories);
448
+ writeAtomically(entry, `${JSON.stringify(overrides, null, 2)}\n`);
449
+ return entry.filePath;
450
+ }
451
+ export function setManagerProjectSettings(options) {
452
+ if (!options.includeProject)
453
+ throw new Error("Project settings are not enabled/trusted");
454
+ if (typeof options.enabled !== "boolean")
455
+ throw new Error("Invalid project settings state");
456
+ if (options.expectedLayers)
457
+ assertExpectedLayers(loadManagerSettingsLayers(options), options.expectedLayers);
458
+ const entry = layer(options.cwd, [".pi", "agent", "subagent-manager"]);
459
+ const present = settingsFileExists(entry);
460
+ if (options.enabled) {
461
+ if (!present) {
462
+ ensureScopeDirectories(entry.directories);
463
+ writeAtomically(entry, "{}\n", false);
464
+ }
465
+ }
466
+ else if (present) {
467
+ if (settingsFileExists(entry))
468
+ unlinkSync(entry.filePath);
469
+ }
470
+ return entry.filePath;
471
+ }
472
+ export function managerSettingsPath(options, scope) {
473
+ if (scope === "project") {
474
+ if (!options.includeProject)
475
+ throw new Error("Project settings are not enabled/trusted");
476
+ return layer(options.cwd, [".pi", "agent", "subagent-manager"]).filePath;
477
+ }
478
+ return layer(options.agentDir, ["subagent-manager"]).filePath;
479
+ }
480
+ export function deleteManagerSettings(options) {
481
+ if (options.scope !== "user" && options.scope !== "project")
482
+ throw new Error("Invalid settings scope");
483
+ const filePath = managerSettingsPath(options, options.scope);
484
+ const entry = options.scope === "project"
485
+ ? layer(options.cwd, [".pi", "agent", "subagent-manager"])
486
+ : layer(options.agentDir, ["subagent-manager"]);
487
+ if (!settingsFileExists(entry))
488
+ return { filePath, deleted: false };
489
+ unlinkSync(entry.filePath);
490
+ return { filePath, deleted: true };
491
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
@@ -0,0 +1,63 @@
1
+ import { LOADER_STYLES } from "../prefs/settings.js";
2
+ export const AGENT_PROGRESS_INTERVAL = 180;
3
+ export const AGENT_LOADERS = {
4
+ circle: {
5
+ label: "Circle",
6
+ requiresNerdFont: true,
7
+ frames: Array.from({ length: 8 }, (_, index) => String.fromCodePoint(0xf0a9e + index)),
8
+ states: {
9
+ completed: "\u{f05e0}",
10
+ paused: "\u{f03e5}",
11
+ failed: "\u{f0159}",
12
+ stopped: "\u{f0666}",
13
+ },
14
+ },
15
+ braille: {
16
+ label: "Braille",
17
+ requiresNerdFont: false,
18
+ frames: Array.from("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"),
19
+ states: { completed: "✓", paused: "Ⅱ", failed: "×", stopped: "■" },
20
+ },
21
+ hourglass: {
22
+ label: "Hourglass",
23
+ requiresNerdFont: true,
24
+ frames: ["\uf251", "\uf252", "\uf253"],
25
+ states: { completed: "\uf14a", paused: "\uf04c", failed: "\uf057", stopped: "\uf04d" },
26
+ },
27
+ ascii: {
28
+ label: "ASCII",
29
+ requiresNerdFont: false,
30
+ frames: ["|", "/", "-", "\\"],
31
+ states: { completed: "+", paused: "=", failed: "!", stopped: "#" },
32
+ },
33
+ "ascii-star": {
34
+ label: "ASCII Star",
35
+ requiresNerdFont: false,
36
+ frames: ["+", "x", "*"],
37
+ states: { completed: "+", paused: "=", failed: "!", stopped: "#" },
38
+ },
39
+ "ascii-pulse": {
40
+ label: "ASCII Pulse",
41
+ requiresNerdFont: false,
42
+ frames: ["=", "*", "-"],
43
+ states: { completed: "+", paused: "=", failed: "!", stopped: "#" },
44
+ },
45
+ };
46
+ export function availableLoaderStyles(nerdFontIcons) {
47
+ return LOADER_STYLES.filter((style) => nerdFontIcons || !AGENT_LOADERS[style].requiresNerdFont);
48
+ }
49
+ export function effectiveLoaderStyle(style, nerdFontIcons) {
50
+ return !nerdFontIcons && AGENT_LOADERS[style].requiresNerdFont ? "ascii" : style;
51
+ }
52
+ export function agentProgressIcon(thread, nerdFontIcons, now = Date.now(), animate = true, loaderStyle = "circle") {
53
+ const loader = AGENT_LOADERS[effectiveLoaderStyle(loaderStyle, nerdFontIcons)];
54
+ if (thread.state === "starting" || thread.state === "running") {
55
+ const index = animate ? Math.floor(Math.max(0, now) / AGENT_PROGRESS_INTERVAL) : 0;
56
+ return loader.frames[index % loader.frames.length];
57
+ }
58
+ return loader.states[thread.state];
59
+ }
60
+ export function isAgentLoaderGlyph(glyph, nerdFontIcons = true) {
61
+ return Object.values(AGENT_LOADERS).some((loader) => (nerdFontIcons || !loader.requiresNerdFont) &&
62
+ (loader.frames.includes(glyph) || Object.values(loader.states).includes(glyph)));
63
+ }