pi-subagent-manager 1.10.0 → 1.11.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 (186) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +836 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/orch/checklist-integration.d.ts +48 -0
  6. package/dist/orch/checklist-integration.d.ts.map +1 -0
  7. package/dist/orch/checklist-integration.js +204 -0
  8. package/dist/orch/checklist-integration.js.map +1 -0
  9. package/dist/orch/context-entries.d.ts +8 -0
  10. package/dist/orch/context-entries.d.ts.map +1 -0
  11. package/dist/orch/context-entries.js +8 -0
  12. package/dist/orch/context-entries.js.map +1 -0
  13. package/dist/orch/cost-ledger.d.ts +16 -0
  14. package/dist/orch/cost-ledger.d.ts.map +1 -0
  15. package/dist/orch/cost-ledger.js +43 -0
  16. package/dist/orch/cost-ledger.js.map +1 -0
  17. package/dist/orch/diagnostics.d.ts +13 -0
  18. package/dist/orch/diagnostics.d.ts.map +1 -0
  19. package/dist/orch/diagnostics.js +95 -0
  20. package/dist/orch/diagnostics.js.map +1 -0
  21. package/dist/orch/extensions.d.ts +15 -0
  22. package/dist/orch/extensions.d.ts.map +1 -0
  23. package/dist/orch/extensions.js +80 -0
  24. package/dist/orch/extensions.js.map +1 -0
  25. package/dist/orch/housekeeping-usage.d.ts +14 -0
  26. package/dist/orch/housekeeping-usage.d.ts.map +1 -0
  27. package/dist/orch/housekeeping-usage.js +27 -0
  28. package/dist/orch/housekeeping-usage.js.map +1 -0
  29. package/dist/orch/housekeeping.d.ts +89 -0
  30. package/dist/orch/housekeeping.d.ts.map +1 -0
  31. package/dist/orch/housekeeping.js +281 -0
  32. package/dist/orch/housekeeping.js.map +1 -0
  33. package/dist/orch/inherited-tools.d.ts +18 -0
  34. package/dist/orch/inherited-tools.d.ts.map +1 -0
  35. package/dist/orch/inherited-tools.js +71 -0
  36. package/dist/orch/inherited-tools.js.map +1 -0
  37. package/dist/orch/mailbox.d.ts +59 -0
  38. package/dist/orch/mailbox.d.ts.map +1 -0
  39. package/dist/orch/mailbox.js +196 -0
  40. package/dist/orch/mailbox.js.map +1 -0
  41. package/dist/orch/manager.d.ts +82 -0
  42. package/dist/orch/manager.d.ts.map +1 -0
  43. package/dist/orch/manager.js +1010 -0
  44. package/dist/orch/manager.js.map +1 -0
  45. package/dist/orch/paths.d.ts +7 -0
  46. package/dist/orch/paths.d.ts.map +1 -0
  47. package/dist/orch/paths.js +73 -0
  48. package/dist/orch/paths.js.map +1 -0
  49. package/dist/orch/prompt.d.ts +7 -0
  50. package/dist/orch/prompt.d.ts.map +1 -0
  51. package/dist/orch/prompt.js +34 -0
  52. package/dist/orch/prompt.js.map +1 -0
  53. package/dist/orch/registry.d.ts +49 -0
  54. package/dist/orch/registry.d.ts.map +1 -0
  55. package/dist/orch/registry.js +134 -0
  56. package/dist/orch/registry.js.map +1 -0
  57. package/dist/orch/runtime.d.ts +11 -0
  58. package/dist/orch/runtime.d.ts.map +1 -0
  59. package/dist/orch/runtime.js +882 -0
  60. package/dist/orch/runtime.js.map +1 -0
  61. package/dist/orch/tools.d.ts +6 -0
  62. package/dist/orch/tools.d.ts.map +1 -0
  63. package/dist/orch/tools.js +114 -0
  64. package/dist/orch/tools.js.map +1 -0
  65. package/dist/orch/transcript.d.ts +28 -0
  66. package/dist/orch/transcript.d.ts.map +1 -0
  67. package/dist/orch/transcript.js +176 -0
  68. package/dist/orch/transcript.js.map +1 -0
  69. package/dist/prefs/agent-import.d.ts +37 -0
  70. package/dist/prefs/agent-import.d.ts.map +1 -0
  71. package/dist/prefs/agent-import.js +196 -0
  72. package/dist/prefs/agent-import.js.map +1 -0
  73. package/dist/prefs/config.d.ts +108 -0
  74. package/dist/prefs/config.d.ts.map +1 -0
  75. package/dist/prefs/config.js +926 -0
  76. package/dist/prefs/config.js.map +1 -0
  77. package/dist/prefs/import-discovery.d.ts +28 -0
  78. package/dist/prefs/import-discovery.d.ts.map +1 -0
  79. package/dist/prefs/import-discovery.js +562 -0
  80. package/dist/prefs/import-discovery.js.map +1 -0
  81. package/dist/prefs/import-instructions.d.ts +3 -0
  82. package/dist/prefs/import-instructions.d.ts.map +1 -0
  83. package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +1 -0
  84. package/dist/prefs/import-instructions.js.map +1 -0
  85. package/dist/prefs/models.d.ts +24 -0
  86. package/dist/prefs/models.d.ts.map +1 -0
  87. package/dist/prefs/models.js +57 -0
  88. package/dist/prefs/models.js.map +1 -0
  89. package/dist/prefs/settings.d.ts +89 -0
  90. package/dist/prefs/settings.d.ts.map +1 -0
  91. package/dist/prefs/settings.js +505 -0
  92. package/dist/prefs/settings.js.map +1 -0
  93. package/dist/types.d.ts +293 -0
  94. package/dist/types.d.ts.map +1 -0
  95. package/dist/types.js +2 -0
  96. package/dist/types.js.map +1 -0
  97. package/dist/ui/agent-loader.d.ts +21 -0
  98. package/dist/ui/agent-loader.d.ts.map +1 -0
  99. package/dist/ui/agent-loader.js +73 -0
  100. package/dist/ui/agent-loader.js.map +1 -0
  101. package/dist/ui/agent-navigation-editor.d.ts +46 -0
  102. package/dist/ui/agent-navigation-editor.d.ts.map +1 -0
  103. package/dist/ui/agent-navigation-editor.js +189 -0
  104. package/dist/ui/agent-navigation-editor.js.map +1 -0
  105. package/dist/ui/cost-footer.d.ts +37 -0
  106. package/dist/ui/cost-footer.d.ts.map +1 -0
  107. package/dist/ui/cost-footer.js +215 -0
  108. package/dist/ui/cost-footer.js.map +1 -0
  109. package/dist/ui/dialog.d.ts +135 -0
  110. package/dist/ui/dialog.d.ts.map +1 -0
  111. package/dist/ui/dialog.js +533 -0
  112. package/dist/ui/dialog.js.map +1 -0
  113. package/dist/ui/import-picker.d.ts +38 -0
  114. package/dist/ui/import-picker.d.ts.map +1 -0
  115. package/dist/ui/import-picker.js +211 -0
  116. package/dist/ui/import-picker.js.map +1 -0
  117. package/dist/ui/live-agent-view.d.ts +82 -0
  118. package/dist/ui/live-agent-view.d.ts.map +1 -0
  119. package/dist/ui/live-agent-view.js +546 -0
  120. package/dist/ui/live-agent-view.js.map +1 -0
  121. package/dist/ui/model-picker.d.ts +109 -0
  122. package/dist/ui/model-picker.d.ts.map +1 -0
  123. package/dist/ui/model-picker.js +549 -0
  124. package/dist/ui/model-picker.js.map +1 -0
  125. package/dist/ui/settings-ui.d.ts +17 -0
  126. package/dist/ui/settings-ui.d.ts.map +1 -0
  127. package/dist/ui/settings-ui.js +679 -0
  128. package/dist/ui/settings-ui.js.map +1 -0
  129. package/dist/ui/status-ui.d.ts +67 -0
  130. package/dist/ui/status-ui.d.ts.map +1 -0
  131. package/dist/ui/status-ui.js +487 -0
  132. package/dist/ui/status-ui.js.map +1 -0
  133. package/dist/ui/thread-tree.d.ts +22 -0
  134. package/dist/ui/thread-tree.d.ts.map +1 -0
  135. package/dist/ui/thread-tree.js +153 -0
  136. package/dist/ui/thread-tree.js.map +1 -0
  137. package/dist/ui/tool-picker.d.ts +46 -0
  138. package/dist/ui/tool-picker.d.ts.map +1 -0
  139. package/dist/ui/tool-picker.js +334 -0
  140. package/dist/ui/tool-picker.js.map +1 -0
  141. package/dist/ui/transcript-tool.d.ts +2 -0
  142. package/dist/ui/transcript-tool.d.ts.map +1 -0
  143. package/dist/ui/transcript-tool.js +100 -0
  144. package/dist/ui/transcript-tool.js.map +1 -0
  145. package/dist/ui/ui.d.ts +41 -0
  146. package/dist/ui/ui.d.ts.map +1 -0
  147. package/dist/ui/ui.js +1047 -0
  148. package/dist/ui/ui.js.map +1 -0
  149. package/docs/development.md +2 -1
  150. package/package.json +16 -4
  151. package/src/index.ts +0 -920
  152. package/src/orch/checklist-integration.ts +0 -230
  153. package/src/orch/context-entries.ts +0 -15
  154. package/src/orch/cost-ledger.ts +0 -56
  155. package/src/orch/diagnostics.ts +0 -95
  156. package/src/orch/extensions.ts +0 -83
  157. package/src/orch/housekeeping-usage.ts +0 -47
  158. package/src/orch/housekeeping.ts +0 -348
  159. package/src/orch/inherited-tools.ts +0 -84
  160. package/src/orch/mailbox.ts +0 -261
  161. package/src/orch/manager.ts +0 -1084
  162. package/src/orch/paths.ts +0 -73
  163. package/src/orch/prompt.ts +0 -39
  164. package/src/orch/registry.ts +0 -168
  165. package/src/orch/runtime.ts +0 -1041
  166. package/src/orch/tools.ts +0 -190
  167. package/src/orch/transcript.ts +0 -186
  168. package/src/prefs/agent-import.ts +0 -245
  169. package/src/prefs/config.ts +0 -1017
  170. package/src/prefs/import-discovery.ts +0 -643
  171. package/src/prefs/models.ts +0 -74
  172. package/src/prefs/settings.ts +0 -614
  173. package/src/types.ts +0 -271
  174. package/src/ui/agent-loader.ts +0 -98
  175. package/src/ui/agent-navigation-editor.ts +0 -233
  176. package/src/ui/cost-footer.ts +0 -230
  177. package/src/ui/dialog.ts +0 -678
  178. package/src/ui/import-picker.ts +0 -231
  179. package/src/ui/live-agent-view.ts +0 -600
  180. package/src/ui/model-picker.ts +0 -701
  181. package/src/ui/settings-ui.ts +0 -830
  182. package/src/ui/status-ui.ts +0 -628
  183. package/src/ui/thread-tree.ts +0 -173
  184. package/src/ui/tool-picker.ts +0 -398
  185. package/src/ui/transcript-tool.ts +0 -142
  186. package/src/ui/ui.ts +0 -1407
@@ -1,830 +0,0 @@
1
- import type { ExtensionCommandContext, Theme } from "@earendil-works/pi-coding-agent";
2
- import { discoverSubagentExtensions, extensionDisplayName } from "../orch/extensions.ts";
3
- import type { ConfigStore } from "../prefs/config.ts";
4
- import {
5
- canOpenDialog,
6
- dialogInput,
7
- dialogMenu,
8
- withDialogSession,
9
- type DialogRow,
10
- } from "./dialog.ts";
11
- import {
12
- DEFAULT_MANAGER_SETTINGS,
13
- settingsValueEqual,
14
- type CostDisplayMode,
15
- COST_ICONS,
16
- type CostIcon,
17
- type CostValue,
18
- LOADER_STYLES,
19
- type LoaderStyle,
20
- deleteManagerSettings,
21
- loadManagerSettingsLayers,
22
- managerSettingsPath,
23
- saveManagerOverrides,
24
- setManagerProjectSettings,
25
- type ManagerSettings,
26
- type ModelSelectionMode,
27
- type SubagentMode,
28
- type ToolFilteringMode,
29
- type WidgetMode,
30
- } from "../prefs/settings.ts";
31
- import { editAgentTypes, type AgentEditorOptions } from "./ui.ts";
32
- import { HOUSEKEEPING_PICKER_CANCEL, pickHousekeepingModel } from "./model-picker.ts";
33
- import type { ToolEditorOptions } from "./tool-picker.ts";
34
- import { AGENT_LOADERS, availableLoaderStyles, effectiveLoaderStyle } from "./agent-loader.ts";
35
- import { costIconGlyph } from "./cost-footer.ts";
36
- import { CHECKLIST_REQUIREMENTS, type ChecklistStatus } from "../orch/checklist-integration.ts";
37
-
38
- const LOADER_OPTIONS = LOADER_STYLES.map((id) => {
39
- const loader = AGENT_LOADERS[id];
40
- return {
41
- id,
42
- label: loader.label,
43
- value: `${loader.frames.join(" ")} · ${Object.values(loader.states).join(" ")}`,
44
- help: `Each row: all starting/running frames · completed, paused, failed, stopped.\nStarting/running: ${loader.frames.join(" ")}\nCompleted: ${loader.states.completed} · Paused: ${loader.states.paused}\nFailed: ${loader.states.failed} · Stopped: ${loader.states.stopped}\n${loader.requiresNerdFont ? "Requires [lab] Nerd Font icons On." : id === "braille" ? "Standard Unicode Braille; no Nerd Font needed." : "ASCII only; no special font needed."} The loader appears before the role icon when enabled.`,
45
- };
46
- });
47
-
48
- const FIELDS = [
49
- {
50
- id: "maxLevels",
51
- label: "Maximum levels",
52
- help: "How deep agents can delegate.\nYour main conversation is level 1; 3 allows an agent and its child.\nPositive integer, at most 32.",
53
- },
54
- {
55
- id: "maxConcurrent",
56
- label: "Concurrent agents",
57
- help: "How many agents can be active at once across all levels.\nParents waiting for children also count.\nPositive safe integer.",
58
- },
59
- {
60
- id: "maxThreads",
61
- label: "Retained threads",
62
- help: "How many agent sessions can be kept for follow-up work, including completed and paused agents.\nAt the limit, new agents cannot start.\nPositive safe integer.",
63
- },
64
- ] as const;
65
-
66
- const MODE_OPTIONS = [
67
- {
68
- id: "off",
69
- label: "Off",
70
- value: "No subagent tools or prompt guidance",
71
- help: "Off: hide subagent tools and inject no subagent guidance into the system prompt.\nExisting work and retained sessions are kept.",
72
- },
73
- {
74
- id: "opportunistic",
75
- label: "Opportunistic",
76
- value: "Parallelizable or very large tasks only",
77
- help: "Opportunistic: make subagent tools available.\nDelegate only when tasks can be parallelized or a task is very large; otherwise work directly.",
78
- },
79
- {
80
- id: "orchestration",
81
- label: "Orchestration",
82
- value: "/root coordinates; subagents execute",
83
- help: "Orchestration: tell /root to delegate all task execution to subagents and only coordinate and synthesize results.\nThis rule is not inherited by workers.",
84
- },
85
- ] as const;
86
-
87
- const MODE_HELP =
88
- "Off: no subagent tools or prompt guidance.\nOpportunistic: delegate only parallelizable or very large tasks.\nOrchestration: /root delegates all execution and only coordinates and synthesizes results.";
89
-
90
- const TOOL_FILTERING_OPTIONS = [
91
- {
92
- id: "allowed",
93
- label: "Allowed (except blocked)",
94
- value: "Allow list minus block list",
95
- help: "Only tools in the agent YAML allow list are available, minus its block list.\nBlocked tools take precedence. A missing or empty allow list means no tools.",
96
- },
97
- {
98
- id: "all-except-blocked",
99
- label: "All except blocked",
100
- value: "Ignore allow list",
101
- help: "All available tools except those in the agent YAML block list.\nThe allow list is completely ignored.",
102
- },
103
- {
104
- id: "all",
105
- label: "All",
106
- value: "Ignore both lists",
107
- help: "All available tools.\nThe agent YAML allow and block lists are completely ignored.",
108
- },
109
- ] as const;
110
-
111
- const TOOL_FILTERING_HELP =
112
- "Allowed (except blocked): only allow-listed tools, minus blocked tools; a missing or empty allow list means no tools.\nAll except blocked: ignore the allow list; block-listed tools remain blocked.\nAll: ignore both lists.\nSave and apply to affect agents when their sessions start.";
113
-
114
- const WIDGET_MODE_OPTIONS = [
115
- {
116
- id: "full",
117
- label: "Full",
118
- value: "Detailed agent status rows",
119
- help: "Full: show the existing agent status widget above the input box, with per-agent details.",
120
- },
121
- {
122
- id: "minimal",
123
- label: "Minimal",
124
- value: "One-line counts and running-agent tokens",
125
- help: "Minimal: show status counts in one line above the input box.\nStarting agents count as running. Token totals include only active (starting/running) agents.",
126
- },
127
- ] as const;
128
-
129
- const WIDGET_MODE_HELP =
130
- "Full: detailed agent status rows above the input box.\nMinimal: one-line status counts and cumulative input/output tokens for active (starting/running) agents.\nSave and apply to update the widget immediately.";
131
-
132
- const COST_DISPLAY_OPTIONS = [
133
- {
134
- id: "pi-status",
135
- label: "Replace Pi status",
136
- help: "Show the selected cost in Pi’s status area, without replacing the whole footer. Third-party footers may also consume this status.",
137
- },
138
- {
139
- id: "pi-footer-status",
140
- label: "pi-footer status widget",
141
- value: "subagent_cost",
142
- help: "Status key: subagent_cost\nSelect subagent_cost in pi-footer’s Extension Status widget. Does not replace your footer.",
143
- },
144
- {
145
- id: "pi-footer-event",
146
- label: "pi-footer event",
147
- value: "subagent_cost",
148
- help: "Event: pi-footer:update-widget\nWidget ID: subagent_cost\nAdd a Pi Event Value widget and enable Raw value only. Without an external /footer, retain the cost fallback.",
149
- },
150
- ] as const;
151
-
152
- const COST_VALUE_OPTIONS = [
153
- {
154
- id: "subagents",
155
- label: "Only subagent cost",
156
- help: "Settled USD cost of all subagents; excludes the main session.",
157
- },
158
- {
159
- id: "total",
160
- label: "Total cost",
161
- help: "Main session USD cost plus all settled subagent costs.",
162
- },
163
- ] as const;
164
-
165
- const COST_ICON_LABELS = { money: "Money", coins: "Coins", wallet: "Wallet" } as const;
166
-
167
- type SettingsLayers = ReturnType<typeof loadManagerSettingsLayers>;
168
-
169
- /** Persisted changes, not unsaved draft values; theme styling is computed on render. */
170
- function withProvenance(
171
- row: DialogRow,
172
- keys: (keyof ManagerSettings)[],
173
- layers: SettingsLayers,
174
- ): DialogRow {
175
- const globalChanged = keys.some(
176
- (key) =>
177
- layers.global[key] !== undefined &&
178
- !settingsValueEqual(layers.global[key], DEFAULT_MANAGER_SETTINGS[key]),
179
- );
180
- const projectChanged = keys.some(
181
- (key) =>
182
- layers.project[key] !== undefined &&
183
- !settingsValueEqual(layers.project[key], layers.global[key] ?? DEFAULT_MANAGER_SETTINGS[key]),
184
- );
185
- return {
186
- ...row,
187
- renderIndicators: (theme) =>
188
- (globalChanged ? theme.fg("accent", "●") : " ") +
189
- " " +
190
- (projectChanged ? theme.fg("warning", "●") : " "),
191
- help: `${row.label}\n${row.help ?? ""}`,
192
- };
193
- }
194
-
195
- function provenanceLegend(theme: Theme): string {
196
- const global = theme.fg("accent", "●");
197
- const project = theme.fg("warning", "●");
198
- return (
199
- theme.fg("muted", "Saved: ") +
200
- `${global} Global · ${project} Current Project · ${global} ${project} Both`
201
- );
202
- }
203
-
204
- /** Selection edits stay in the outer draft until Save and apply. */
205
- async function configureSubagentExtensions(
206
- ctx: ExtensionCommandContext,
207
- draft: ManagerSettings,
208
- agentDir: string,
209
- ): Promise<void> {
210
- const available = await discoverSubagentExtensions({
211
- cwd: ctx.cwd,
212
- agentDir,
213
- projectTrusted: ctx.isProjectTrusted(),
214
- });
215
- const selected = new Set(
216
- draft.subagentExtensions === true ? available : draft.subagentExtensions || [],
217
- );
218
- // Keep stale selections visible and removable; runtime still intersects with discovery.
219
- const files = [...new Set([...available, ...selected])].sort();
220
- let selectedId: string | undefined;
221
- while (true) {
222
- const action = await dialogMenu(
223
- ctx,
224
- "[lab] Subagent extensions",
225
- [
226
- ...files.map((file) => ({
227
- id: file,
228
- label: `${selected.has(file) ? "[x]" : "[ ]"} ${extensionDisplayName(file)}`,
229
- value: available.includes(file) ? (selected.has(file) ? "On" : "Off") : "Unavailable",
230
- help: `${file}\n${available.includes(file) ? "Reload this extension in newly opened subagent sessions." : "Not currently discoverable/trusted; will not load. Toggle Off to remove the saved selection."}\nSpace/Enter toggles. Changes are saved only with outer Save and apply.`,
231
- })),
232
- {
233
- id: "back",
234
- label: "Back",
235
- help: files.length
236
- ? "Return to settings; selection is not saved yet."
237
- : "No extensions available (configured or auto-discovered). CLI-only, inline, built-in extensions and this manager are excluded.",
238
- },
239
- ],
240
- { selectedId, spaceSelect: true, footer: "↑↓/Tab navigate · Space/Enter toggle · Esc back" },
241
- );
242
- if (!action || action === "back") {
243
- draft.subagentExtensions = [...selected].sort();
244
- return;
245
- }
246
- selectedId = action;
247
- if (selected.has(action)) selected.delete(action);
248
- else selected.add(action);
249
- }
250
- }
251
-
252
- /** Edits the shared draft; only the outer settings screen saves or applies it. */
253
- async function configureFooterDisplay(
254
- ctx: ExtensionCommandContext,
255
- draft: ManagerSettings,
256
- layers: SettingsLayers,
257
- ): Promise<void> {
258
- let selectedId: string | undefined;
259
- while (true) {
260
- const action = await dialogMenu(
261
- ctx,
262
- "Footer display",
263
- (
264
- [
265
- {
266
- id: "location",
267
- label: "Location",
268
- value: COST_DISPLAY_OPTIONS.find((option) => option.id === draft.costDisplay)!.label,
269
- help: "Choose Pi status, a pi-footer status widget, or a pi-footer event. Integration IDs are shown in the location picker.",
270
- },
271
- {
272
- id: "value",
273
- label: "Display value",
274
- value: COST_VALUE_OPTIONS.find((option) => option.id === draft.costValue)!.label,
275
- help: "Show only settled subagent cost, or main session plus settled subagents. Applies to every location.",
276
- },
277
- {
278
- id: "icon",
279
- label: "Icon",
280
- value: `${costIconGlyph(draft.costIcon, draft.nerdFontIcons)} ${COST_ICON_LABELS[draft.costIcon]}`,
281
- help: `Choose a money-related ${draft.nerdFontIcons ? "Nerd Font" : "emoji"} icon. The family follows [lab] Nerd Font icons.`,
282
- },
283
- {
284
- id: "back",
285
- label: "Back",
286
- help: "Return to settings. Save and apply there to commit these changes.",
287
- },
288
- ] as DialogRow[]
289
- ).map((row) => {
290
- const key = (
291
- { location: "costDisplay", value: "costValue", icon: "costIcon" } as Record<
292
- string,
293
- keyof ManagerSettings
294
- >
295
- )[row.id];
296
- return key ? withProvenance(row, [key], layers) : row;
297
- }),
298
- {
299
- selectedId,
300
- renderLegend: provenanceLegend,
301
- footer: "↑↓/Tab navigate · Enter edit · Esc back",
302
- },
303
- );
304
- if (!action || action === "back") return;
305
- selectedId = action;
306
- if (action === "location") {
307
- const mode = await dialogMenu(ctx, "Footer location", [...COST_DISPLAY_OPTIONS], {
308
- selectedId: draft.costDisplay,
309
- });
310
- if (COST_DISPLAY_OPTIONS.some((option) => option.id === mode))
311
- draft.costDisplay = mode as CostDisplayMode;
312
- } else if (action === "value") {
313
- const value = await dialogMenu(ctx, "Footer display value", [...COST_VALUE_OPTIONS], {
314
- selectedId: draft.costValue,
315
- });
316
- if (COST_VALUE_OPTIONS.some((option) => option.id === value))
317
- draft.costValue = value as CostValue;
318
- } else if (action === "icon") {
319
- const icon = await dialogMenu(
320
- ctx,
321
- `Footer icon · ${draft.nerdFontIcons ? "Nerd Font" : "Emoji"}`,
322
- COST_ICONS.map((id) => ({
323
- id,
324
- label: COST_ICON_LABELS[id],
325
- value: costIconGlyph(id, draft.nerdFontIcons),
326
- help: `${costIconGlyph(id, draft.nerdFontIcons)} ${COST_ICON_LABELS[id]} · ${draft.nerdFontIcons ? "Requires a Nerd Font in your terminal." : "Emoji icon."}`,
327
- })),
328
- { selectedId: draft.costIcon },
329
- );
330
- if (COST_ICONS.includes(icon as CostIcon)) draft.costIcon = icon as CostIcon;
331
- }
332
- }
333
- }
334
-
335
- function housekeepingValue(draft: ManagerSettings): string {
336
- if (!draft.housekeepingEnabled) return "Off";
337
- return draft.housekeepingModel ? `On · ${draft.housekeepingModel}` : "On · no model selected";
338
- }
339
-
340
- const HOUSEKEEPING_HELP =
341
- "Experimental: a model you choose writes a one-line summary of each running agent's current work, shown in the tree and widget instead of raw tool-call status.\nSends the agent's task and recent tool names/arguments/text to the selected model, uses extra tokens, and is not included in subagent cost totals.\nOff by default. Any failure keeps the original status. Choose from available and scoped models.";
342
-
343
- /** Edits the shared draft; only the outer settings screen saves or applies it. */
344
- async function configureHousekeeping(
345
- ctx: ExtensionCommandContext,
346
- draft: ManagerSettings,
347
- layers: SettingsLayers,
348
- ): Promise<void> {
349
- let selectedId: string | undefined;
350
- while (true) {
351
- const action = await dialogMenu(
352
- ctx,
353
- "[lab] Housekeeping model",
354
- (
355
- [
356
- {
357
- id: "enabled",
358
- label: "Summaries",
359
- value: draft.housekeepingEnabled ? "On" : "Off",
360
- help: "Name each running agent's work in one line using the housekeeping model, replacing raw tool-call status in the tree and widget.\nInactive until a model is selected. Off by default.",
361
- },
362
- {
363
- id: "model",
364
- label: "Model",
365
- value: draft.housekeepingModel || "Not selected",
366
- valueColor: draft.housekeepingModel ? undefined : ("muted" as const),
367
- help: "Pick any available model; scoped models are listed first. A small, fast, inexpensive model is usually enough.\nIf the model later becomes unavailable (no credentials, removed), summaries stay inactive and normal status shows.",
368
- },
369
- {
370
- id: "back",
371
- label: "Back",
372
- help: "Return to settings. Save and apply there to commit these changes.",
373
- },
374
- ] as DialogRow[]
375
- ).map((row) => {
376
- const key = (
377
- { enabled: "housekeepingEnabled", model: "housekeepingModel" } as Record<
378
- string,
379
- keyof ManagerSettings
380
- >
381
- )[row.id];
382
- return key ? withProvenance(row, [key], layers) : row;
383
- }),
384
- {
385
- selectedId,
386
- renderLegend: provenanceLegend,
387
- footer: "↑↓/Tab navigate · Enter edit · Esc back",
388
- },
389
- );
390
- if (!action || action === "back") return;
391
- selectedId = action;
392
- if (action === "enabled") draft.housekeepingEnabled = !draft.housekeepingEnabled;
393
- else if (action === "model") {
394
- const picked = await pickHousekeepingModel(ctx, draft.housekeepingModel);
395
- if (picked !== HOUSEKEEPING_PICKER_CANCEL) draft.housekeepingModel = picked;
396
- }
397
- }
398
- }
399
-
400
- const MODEL_SELECTION_OPTIONS = [
401
- {
402
- id: "pick-first-available",
403
- label: "Pick First (available)",
404
- value: "First available model in the agent's list",
405
- help: "Pick First (available):\nPick the first model in the agent's models list available in Pi with an enabled, authenticated provider.\nSkip missing models and providers without credentials; try the next preference.",
406
- },
407
- {
408
- id: "pick-first-scoped",
409
- label: "Pick First (scoped)",
410
- value: "First available preference in the session scope",
411
- help: "Pick First (scoped):\nPick the first available model in the agent's models list that is also selected in the current session's /scoped-models. An empty scope allows all available models.\nSkip unavailable models and providers without credentials.",
412
- },
413
- {
414
- id: "use-current",
415
- label: "Use Current",
416
- value: "Use the main session's current model",
417
- help: "Use Current:\nIgnore the agent's models list and use the main session's current model.\nKeep each agent's configured thinking level, not the main session's thinking level.",
418
- },
419
- ] as const;
420
-
421
- const MODEL_SELECTION_HELP =
422
- "Pick First (available): first preference with an enabled, authenticated provider in Pi.\nPick First (scoped): same, limited to the current session's /scoped-models when non-empty.\nUse Current: ignore models and use the main session's current model; keep the agent's thinking level.\nOnly the models list affects runtime picking; modelSuggestions are search hints.\nSave and apply to affect agents when their sessions start.";
423
-
424
- export async function configureAgents(
425
- ctx: ExtensionCommandContext,
426
- options: {
427
- store: ConfigStore;
428
- settings: ManagerSettings;
429
- agentDir: string;
430
- getAllTools?: ToolEditorOptions["getAllTools"];
431
- resolveAgentSettings?: AgentEditorOptions["resolveAgentSettings"];
432
- /** Live pi-checklist eligibility; absent means unavailable (fail closed). */
433
- checklistStatus?: () => ChecklistStatus;
434
- apply(): void;
435
- },
436
- ): Promise<void> {
437
- if (!canOpenDialog(ctx)) return;
438
- await withDialogSession(ctx, (scoped) => configureAgentsDialog(scoped, options));
439
- }
440
-
441
- /** Always shown; "disabled" (muted, guarded) unless pi-checklist prerequisites currently hold. */
442
- function checklistRow(enabled: boolean, status: ChecklistStatus): DialogRow {
443
- const requirements = `${CHECKLIST_REQUIREMENTS}\nWhen On and eligible, adds prompt guidance to tag which agent works on each checklist task via meta.agent; in Orchestration mode /root must use the checklist. Off by default.`;
444
- if (status.eligible)
445
- return {
446
- id: "checklistIntegration",
447
- label: "[lab] Checklist integration",
448
- value: enabled ? "On" : "Off",
449
- help: `Experimental: integrate with pi-checklist.\n${requirements}\nAvailable now: pi-checklist ≥3.0.0 is loaded with task meta enabled.`,
450
- };
451
- return {
452
- id: "checklistIntegration",
453
- label: "[lab] Checklist integration",
454
- value: enabled ? "On · inactive (unavailable)" : "Off · unavailable",
455
- valueColor: "muted",
456
- help: `Experimental: integrate with pi-checklist.\nUnavailable: ${status.reason ?? "requirements not met"}.\n${requirements}\n${enabled ? "Saved On but inactive until requirements are met; Enter turns it Off." : "Cannot be turned On until requirements are met."}`,
457
- };
458
- }
459
-
460
- async function configureAgentsDialog(
461
- ctx: ExtensionCommandContext,
462
- options: {
463
- store: ConfigStore;
464
- settings: ManagerSettings;
465
- agentDir: string;
466
- getAllTools?: ToolEditorOptions["getAllTools"];
467
- resolveAgentSettings?: AgentEditorOptions["resolveAgentSettings"];
468
- /** Live pi-checklist eligibility; absent means unavailable (fail closed). */
469
- checklistStatus?: () => ChecklistStatus;
470
- apply(): void;
471
- },
472
- ): Promise<void> {
473
- const checklistStatus = (): ChecklistStatus => {
474
- try {
475
- return (
476
- options.checklistStatus?.() ?? {
477
- eligible: false,
478
- reason: "pi-checklist status is unavailable",
479
- }
480
- );
481
- } catch (error) {
482
- return {
483
- eligible: false,
484
- reason: `could not verify pi-checklist: ${error instanceof Error ? error.message : String(error)}`,
485
- };
486
- }
487
- };
488
- const readLayers = () =>
489
- loadManagerSettingsLayers({
490
- cwd: ctx.cwd,
491
- agentDir: options.agentDir,
492
- includeProject: ctx.isProjectTrusted(),
493
- });
494
- let layers = readLayers();
495
- const reportDiagnostics = () => {
496
- for (const diagnostic of layers.diagnostics) ctx.ui.notify(diagnostic, "warning");
497
- };
498
- reportDiagnostics();
499
- let baseline = { ...layers.settings };
500
- let draft = { ...baseline };
501
- let scope = layers.scope;
502
- let selectedId: string | undefined;
503
- while (true) {
504
- const dirty = JSON.stringify(draft) !== JSON.stringify(baseline);
505
- const action = await dialogMenu(
506
- ctx,
507
- `Agents settings${dirty ? " · unsaved" : ""}`,
508
- (
509
- [
510
- {
511
- id: "subagentMode",
512
- label: "Subagent Mode",
513
- value: MODE_OPTIONS.find((mode) => mode.id === draft.subagentMode)!.label,
514
- help: MODE_HELP,
515
- },
516
- {
517
- id: "toolFiltering",
518
- label: "Tool Filtering",
519
- value: TOOL_FILTERING_OPTIONS.find((mode) => mode.id === draft.toolFiltering)!.label,
520
- help: TOOL_FILTERING_HELP,
521
- },
522
- ...FIELDS.map((field) => ({
523
- ...field,
524
- value: String(draft[field.id]),
525
- })),
526
- {
527
- id: "modelSelection",
528
- label: "Model Picking",
529
- value: MODEL_SELECTION_OPTIONS.find((mode) => mode.id === draft.modelSelection)!.label,
530
- help: MODEL_SELECTION_HELP,
531
- },
532
- {
533
- id: "widgetMode",
534
- label: "Status Widget",
535
- value: WIDGET_MODE_OPTIONS.find((mode) => mode.id === draft.widgetMode)!.label,
536
- help: WIDGET_MODE_HELP,
537
- },
538
- {
539
- id: "costDisplay",
540
- label: "Footer display",
541
- value: COST_DISPLAY_OPTIONS.find((mode) => mode.id === draft.costDisplay)!.label,
542
- help: "Configure footer location, displayed cost, and money icon in a submenu. Save and apply to update immediately.",
543
- },
544
- {
545
- id: "loaderStyle",
546
- label: "Loader style",
547
- value:
548
- AGENT_LOADERS[effectiveLoaderStyle(draft.loaderStyle, draft.nerdFontIcons)].label,
549
- help: "Preview every animation frame and settled state.\nNerd Fonts Off: Braille (standard Unicode), ASCII, ASCII Star and ASCII Pulse. On: all palettes, including Circle and Hourglass.\nNerd-only saved styles fall back to ASCII while Nerd Fonts are off. Save and apply to update immediately.",
550
- },
551
- {
552
- id: "housekeeping",
553
- label: "[lab] Housekeeping model",
554
- value: housekeepingValue(draft),
555
- valueColor:
556
- draft.housekeepingEnabled && !draft.housekeepingModel
557
- ? ("warning" as const)
558
- : undefined,
559
- help: HOUSEKEEPING_HELP,
560
- },
561
- {
562
- id: "nerdFontIcons",
563
- label: "[lab] Nerd Font icons",
564
- value: draft.nerdFontIcons ? "On" : "Off",
565
- help: "Experimental: display each agent type’s optional Nerd Font icon and unlock Nerd Font loader palettes.\nRequires a Nerd Font configured in your terminal; otherwise glyphs may appear as boxes.\nOff by default. Braille and ASCII loaders work with this Off. Save and apply to update immediately.",
566
- },
567
- {
568
- id: "subagentExtensions",
569
- label: "[lab] Subagent extensions",
570
- value: Array.isArray(draft.subagentExtensions)
571
- ? `${draft.subagentExtensions.length} selected`
572
- : draft.subagentExtensions
573
- ? "All (legacy)"
574
- : "None",
575
- help: "Experimental: reload selected user/trusted-project extension hooks, including auto-discovered .ts/.js files and subdirectory entry points, in separate subagent sessions (not CLI-only or inline extensions). Bugs and unintended consequences may occur if hooks assume main-session state.\nRead limitations: https://github.com/championswimmer/pi-subagent-manager/blob/main/docs/subagent-extension-limitations.md\nSelect individual extensions in the submenu. None by default. Save and apply affects newly opened sessions, not already-open agents.",
576
- },
577
- checklistRow(draft.checklistIntegration, checklistStatus()),
578
- {
579
- id: "finalRecap",
580
- label: "[lab] Final Recap",
581
- value: draft.finalRecap ? "On" : "Off",
582
- help: "Experimental: when detached agents finish or fail and the main agent is idle, automatically ask the main agent to summarize their results.\nEnabling this may cause extra model turns and uses more tokens and context.\nOff by default. Subagent Mode Off suppresses automatic summaries.",
583
- },
584
- {
585
- id: "scope",
586
- label: "Save scope",
587
- value: scope === "user" ? "Global" : "Current Project",
588
- help: "Global: save overrides of built-in defaults for all projects.\nCurrent Project: save overrides of global settings for this trusted project.\nSwitching requires confirmation: enabling Project creates its settings file; switching to Global deletes it and discards unsaved edits. Confirmed scope changes happen immediately, even if you later cancel.",
589
- },
590
- {
591
- id: "types",
592
- label: "Agent definitions",
593
- value: `${options.store.list().length} types`,
594
- help: "Create or edit agent definitions.\nConfigure model preferences and tool policy for each agent type.",
595
- },
596
- {
597
- id: "defaults",
598
- label: "Restore defaults",
599
- help: "Pick Global or Project, then delete that scope's settings.json so its defaults apply again.\nThe file is removed, not rewritten; unsaved edits are discarded. This cannot be undone.",
600
- },
601
- {
602
- id: "save",
603
- label: "Save and apply",
604
- value: dirty ? "(changes)" : undefined,
605
- valueColor: dirty ? ("warning" as const) : undefined,
606
- help: "Save only overrides to the selected scope and reload settings now.\nUnchanged values inherit from the lower layer.\nRunning agents and retained sessions are kept.",
607
- },
608
- {
609
- id: "cancel",
610
- label: "Cancel",
611
- help: "Close without saving manager settings.",
612
- },
613
- ] as DialogRow[]
614
- ).map((row) => {
615
- const keys =
616
- row.id === "costDisplay"
617
- ? (["costDisplay", "costValue", "costIcon"] as (keyof ManagerSettings)[])
618
- : row.id === "housekeeping"
619
- ? (["housekeepingEnabled", "housekeepingModel"] as (keyof ManagerSettings)[])
620
- : row.id in DEFAULT_MANAGER_SETTINGS
621
- ? [row.id as keyof ManagerSettings]
622
- : [];
623
- return keys.length ? withProvenance(row, keys, layers) : row;
624
- }),
625
- {
626
- selectedId,
627
- saveId: "save",
628
- renderLegend: provenanceLegend,
629
- footer: "↑↓/Tab navigate · Enter edit · Ctrl+S save · Esc cancel",
630
- },
631
- );
632
- if (!action || action === "cancel") return;
633
- selectedId = action;
634
- try {
635
- const field = FIELDS.find((field) => field.id === action);
636
- if (field) {
637
- const value = await dialogInput(ctx, field.label, String(draft[field.id]), field.help);
638
- if (value === undefined) continue;
639
- const number = Number(value.trim());
640
- if (
641
- !/^\d+$/.test(value.trim()) ||
642
- !Number.isSafeInteger(number) ||
643
- number < 1 ||
644
- (field.id === "maxLevels" && number > 32)
645
- )
646
- throw new Error(field.help);
647
- draft[field.id] = number;
648
- } else if (action === "subagentMode") {
649
- const mode = await dialogMenu(ctx, "Subagent Mode", [...MODE_OPTIONS], {
650
- selectedId: draft.subagentMode,
651
- });
652
- if (MODE_OPTIONS.some((option) => option.id === mode))
653
- draft.subagentMode = mode as SubagentMode;
654
- } else if (action === "toolFiltering") {
655
- const mode = await dialogMenu(ctx, "Tool Filtering", [...TOOL_FILTERING_OPTIONS], {
656
- selectedId: draft.toolFiltering,
657
- });
658
- if (TOOL_FILTERING_OPTIONS.some((option) => option.id === mode))
659
- draft.toolFiltering = mode as ToolFilteringMode;
660
- } else if (action === "modelSelection") {
661
- const mode = await dialogMenu(ctx, "Model Picking", [...MODEL_SELECTION_OPTIONS], {
662
- selectedId: draft.modelSelection,
663
- });
664
- if (MODEL_SELECTION_OPTIONS.some((option) => option.id === mode))
665
- draft.modelSelection = mode as ModelSelectionMode;
666
- } else if (action === "widgetMode") {
667
- const mode = await dialogMenu(ctx, "Status Widget", [...WIDGET_MODE_OPTIONS], {
668
- selectedId: draft.widgetMode,
669
- });
670
- if (WIDGET_MODE_OPTIONS.some((option) => option.id === mode))
671
- draft.widgetMode = mode as WidgetMode;
672
- } else if (action === "costDisplay") {
673
- await configureFooterDisplay(ctx, draft, layers);
674
- } else if (action === "housekeeping") {
675
- await configureHousekeeping(ctx, draft, layers);
676
- } else if (action === "nerdFontIcons") {
677
- draft.nerdFontIcons = !draft.nerdFontIcons;
678
- } else if (action === "loaderStyle") {
679
- const styles = availableLoaderStyles(draft.nerdFontIcons);
680
- const style = await dialogMenu(
681
- ctx,
682
- "Loader style",
683
- LOADER_OPTIONS.filter((option) => styles.includes(option.id)),
684
- { selectedId: effectiveLoaderStyle(draft.loaderStyle, draft.nerdFontIcons) },
685
- );
686
- if (styles.includes(style as LoaderStyle)) draft.loaderStyle = style as LoaderStyle;
687
- } else if (action === "subagentExtensions") {
688
- await configureSubagentExtensions(ctx, draft, options.agentDir);
689
- } else if (action === "checklistIntegration") {
690
- const status = checklistStatus();
691
- // Turning Off is always allowed; turning On requires current eligibility.
692
- if (!draft.checklistIntegration && !status.eligible)
693
- ctx.ui.notify(
694
- `Checklist integration cannot be enabled: ${status.reason ?? "requirements not met"}. ${CHECKLIST_REQUIREMENTS}`,
695
- "warning",
696
- );
697
- else draft.checklistIntegration = !draft.checklistIntegration;
698
- } else if (action === "finalRecap") {
699
- draft.finalRecap = !draft.finalRecap;
700
- } else if (action === "scope") {
701
- if (!ctx.isProjectTrusted())
702
- ctx.ui.notify("Project settings require a trusted project; saving globally.", "warning");
703
- else {
704
- const nextScope = scope === "user" ? "project" : "user";
705
- const message =
706
- nextScope === "project"
707
- ? "Create project file now; outer Cancel cannot undo.\nThis will create this project's settings.json. Further changes will be saved there. Unsaved edits are kept until Save and apply."
708
- : "Delete project file now. Discard edits. No undo.\nUnsaved edits will be discarded. Outer Cancel cannot undo. We reload global settings; further changes are saved globally.";
709
- const confirmation = await dialogMenu(
710
- ctx,
711
- nextScope === "project"
712
- ? "Enable project settings?"
713
- : "Clear project settings and use Global?",
714
- [
715
- { id: "confirm", label: "Confirm", help: message },
716
- {
717
- id: "cancel",
718
- label: "Cancel",
719
- help: message + "\nCancel leaves files, scope and unsaved edits unchanged.",
720
- },
721
- ],
722
- { selectedId: "cancel", footer: "↑↓/Tab choose · Enter select · Esc cancel" },
723
- );
724
- if (confirmation !== "confirm") continue;
725
- setManagerProjectSettings({
726
- cwd: ctx.cwd,
727
- agentDir: options.agentDir,
728
- includeProject: ctx.isProjectTrusted(),
729
- enabled: nextScope === "project",
730
- expectedLayers: layers,
731
- });
732
- layers = readLayers();
733
- reportDiagnostics();
734
- scope = nextScope;
735
- if (scope === "user") {
736
- baseline = { ...layers.settings };
737
- draft = { ...baseline };
738
- options.apply();
739
- }
740
- }
741
- } else if (action === "defaults") {
742
- const target = {
743
- cwd: ctx.cwd,
744
- agentDir: options.agentDir,
745
- includeProject: ctx.isProjectTrusted(),
746
- };
747
- const globalPath = managerSettingsPath(target, "user");
748
- const projectPath = target.includeProject
749
- ? managerSettingsPath(target, "project")
750
- : undefined;
751
- const explain = (path: string) =>
752
- `Deletes this file now (nothing is written):\n${path}\nIf it does not exist, nothing happens. Unsaved edits are discarded. No undo.`;
753
- const rows: DialogRow[] = [
754
- {
755
- id: "user",
756
- label: "Global",
757
- value: "Restore global defaults",
758
- help: explain(globalPath),
759
- },
760
- ...(projectPath
761
- ? [
762
- {
763
- id: "project",
764
- label: "Project",
765
- value: "Restore project defaults",
766
- help: explain(projectPath),
767
- },
768
- ]
769
- : []),
770
- { id: "cancel", label: "Cancel", help: "Delete nothing." },
771
- ];
772
- const choice = await dialogMenu(
773
- ctx,
774
- "Restore defaults: delete which settings file?",
775
- rows,
776
- {
777
- selectedId: "cancel",
778
- footer: "↑↓/Tab choose · Enter delete file · Esc cancel",
779
- },
780
- );
781
- if (choice === "user" || choice === "project") {
782
- const { filePath, deleted } = deleteManagerSettings({ ...target, scope: choice });
783
- layers = readLayers();
784
- reportDiagnostics();
785
- baseline = { ...layers.settings };
786
- draft = { ...baseline };
787
- scope = layers.scope;
788
- options.apply();
789
- ctx.ui.notify(
790
- deleted
791
- ? `Deleted ${filePath}. Defaults restored.`
792
- : `No settings file at ${filePath}; nothing to delete.`,
793
- "info",
794
- );
795
- }
796
- } else if (action === "types") {
797
- await editAgentTypes(ctx, options.store, draft.nerdFontIcons, {
798
- getAllTools: options.getAllTools ?? (() => []),
799
- toolFiltering: draft.toolFiltering,
800
- resolveAgentSettings: options.resolveAgentSettings,
801
- });
802
- options.store.reload();
803
- } else if (action === "save") {
804
- if (draft.checklistIntegration && !baseline.checklistIntegration) {
805
- const status = checklistStatus();
806
- if (!status.eligible)
807
- throw new Error(
808
- `Checklist integration cannot be enabled: ${status.reason ?? "requirements not met"}. Turn it Off or satisfy: ${CHECKLIST_REQUIREMENTS}`,
809
- );
810
- }
811
- const file = saveManagerOverrides({
812
- cwd: ctx.cwd,
813
- agentDir: options.agentDir,
814
- includeProject: ctx.isProjectTrusted(),
815
- scope,
816
- settings: draft,
817
- expectedLayers: layers,
818
- });
819
- options.apply();
820
- ctx.ui.notify(
821
- `Saved ${file}. Settings reloaded; unchanged values inherit from the lower layer.`,
822
- "info",
823
- );
824
- return;
825
- }
826
- } catch (error) {
827
- ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
828
- }
829
- }
830
- }