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,230 +0,0 @@
1
- import { homedir } from "node:os";
2
- import type { Usage } from "@earendil-works/pi-ai";
3
- import type { ExtensionAPI, ExtensionContext, SessionEntry } from "@earendil-works/pi-coding-agent";
4
- import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
5
- import type { CostDisplayMode, CostValue, CostIcon } from "../prefs/settings.ts";
6
-
7
- export function footerUsage(entries: readonly SessionEntry[]) {
8
- const totals = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
9
- let cacheHit: number | undefined;
10
- const add = (usage: Usage | undefined) => {
11
- if (!usage) return;
12
- totals.input += usage.input;
13
- totals.output += usage.output;
14
- totals.cacheRead += usage.cacheRead;
15
- totals.cacheWrite += usage.cacheWrite;
16
- totals.cost += usage.cost.total;
17
- };
18
- for (const entry of entries) {
19
- if (entry.type === "usage") add(entry.usage);
20
- else if (entry.type === "message") {
21
- if (entry.message.role === "assistant") {
22
- add(entry.message.usage);
23
- const usage = entry.message.usage;
24
- const prompt = usage.input + usage.cacheRead + usage.cacheWrite;
25
- cacheHit = prompt ? (usage.cacheRead / prompt) * 100 : undefined;
26
- } else if (entry.message.role === "toolResult") add(entry.message.usage);
27
- } else if (entry.type === "branch_summary" || entry.type === "compaction") add(entry.usage);
28
- }
29
- return { ...totals, cacheHit };
30
- }
31
- export const COST_WIDGET_ID = "subagent_cost";
32
- export const COST_WIDGET_EVENT = "pi-footer:update-widget";
33
- export const COST_ICON = "\uf0d6"; // nf-fa-money_bill
34
-
35
- export function costIconGlyph(icon: CostIcon, nerdFontIcons: boolean): string {
36
- const glyphs = {
37
- money: { emoji: "💵", nerd: COST_ICON },
38
- coins: { emoji: "🪙", nerd: "\uede8" }, // nf-fa-coins
39
- wallet: { emoji: "👛", nerd: "\uee1e" }, // nf-fa-wallet
40
- };
41
- return glyphs[icon][nerdFontIcons ? "nerd" : "emoji"];
42
- }
43
-
44
- export function formatSubagentCost(cost: number, nerdFontIcons: boolean): string {
45
- return `${nerdFontIcons ? COST_ICON + " " : ""}$${cost.toFixed(4)}`;
46
- }
47
-
48
- /** Any extension-owned /footer takes priority; never infer activity from installed packages alone. */
49
- export function hasExternalFooter(pi: Pick<ExtensionAPI, "getCommands">): boolean {
50
- return pi
51
- .getCommands()
52
- .some((command) => command.name === "footer" && command.source === "extension");
53
- }
54
-
55
- export class CostFooterController {
56
- private installed = false;
57
- private requestRender: (() => void) | undefined;
58
-
59
- private publishedMode: CostDisplayMode | undefined;
60
- private statusContext: ExtensionContext | undefined;
61
- constructor(
62
- private readonly pi: Pick<ExtensionAPI, "getCommands" | "events">,
63
- private readonly subagentCost: () => number,
64
- private readonly nerdFontIcons: () => boolean,
65
- private readonly displayMode: () => CostDisplayMode = () => "pi-footer-status",
66
- private readonly costValue: () => CostValue = () => "subagents",
67
- private readonly costIcon: () => CostIcon = () => "money",
68
- ) {}
69
-
70
- private formatCost(mainCost: number): string {
71
- const cost = this.subagentCost() + (this.costValue() === "total" ? mainCost : 0);
72
- return `${costIconGlyph(this.costIcon(), this.nerdFontIcons())} $${cost.toFixed(4)}`;
73
- }
74
-
75
- refresh(ctx: ExtensionContext): void {
76
- const mode = this.displayMode();
77
- const value = this.formatCost(
78
- this.costValue() === "total" ? footerUsage(ctx.sessionManager.getEntries()).cost : 0,
79
- );
80
- if (this.publishedMode !== undefined && this.publishedMode !== mode) {
81
- this.clear();
82
- this.reset(ctx);
83
- }
84
- this.publishedMode = mode;
85
- if (mode !== "pi-footer-event") {
86
- if (ctx.hasUI) {
87
- this.statusContext = ctx;
88
- const label = this.costValue() === "total" ? "Total" : "Subagents";
89
- ctx.ui.setStatus(COST_WIDGET_ID, mode === "pi-status" ? `${label}: ${value}` : value);
90
- }
91
- return;
92
- }
93
- // Event mode also works in headless sessions; status modes need a UI consumer.
94
- this.pi.events.emit(COST_WIDGET_EVENT, { widgetId: COST_WIDGET_ID, value });
95
- if (hasExternalFooter(this.pi)) {
96
- // Do not clear setFooter here: it could already belong to pi-footer.
97
- this.installed = false;
98
- this.requestRender = undefined;
99
- return;
100
- }
101
- if (this.installed) {
102
- this.requestRender?.();
103
- return;
104
- }
105
- if (this.subagentCost() <= 0 || !ctx.hasUI || ctx.mode !== "tui") return;
106
- this.requestRender = installCostFooter(ctx, this.subagentCost, (mainCost) =>
107
- this.formatCost(mainCost),
108
- );
109
- this.installed = true;
110
- }
111
-
112
- reset(ctx: ExtensionContext): void {
113
- if (this.installed && !hasExternalFooter(this.pi)) ctx.ui.setFooter(undefined);
114
- this.installed = false;
115
- this.requestRender = undefined;
116
- }
117
-
118
- clear(): void {
119
- if (this.publishedMode === "pi-footer-event")
120
- this.pi.events.emit(COST_WIDGET_EVENT, { widgetId: COST_WIDGET_ID, value: null });
121
- this.statusContext?.ui.setStatus(COST_WIDGET_ID, undefined);
122
- this.statusContext = undefined;
123
- this.publishedMode = undefined;
124
- }
125
- }
126
-
127
- const tokens = (n: number) =>
128
- n < 1000
129
- ? String(n)
130
- : n < 10000
131
- ? `${(n / 1000).toFixed(1)}k`
132
- : n < 1000000
133
- ? `${Math.round(n / 1000)}k`
134
- : `${(n / 1000000).toFixed(1)}M`;
135
-
136
- /** Public extension UI APIs only: never inject fake usage/messages into Pi's transcript. */
137
- export function installCostFooter(
138
- ctx: ExtensionContext,
139
- subagentCost: () => number,
140
- displayCost?: (mainCost: number) => string,
141
- ): (() => void) | undefined {
142
- if (!ctx.hasUI || ctx.mode !== "tui" || !ctx.ui.setFooter) return;
143
- let requestRender: (() => void) | undefined;
144
- ctx.ui.setFooter((tui, theme, footerData) => {
145
- requestRender = () => tui.requestRender();
146
- const unsubscribe = footerData.onBranchChange(() => tui.requestRender());
147
- let entryCount = -1;
148
- let totals = footerUsage([]);
149
- return {
150
- dispose: unsubscribe,
151
- invalidate() {
152
- entryCount = -1;
153
- },
154
- render(width: number) {
155
- const entries = ctx.sessionManager.getEntries();
156
- const count = entries.length;
157
- if (count !== entryCount) {
158
- totals = footerUsage(entries);
159
- entryCount = count;
160
- }
161
- const branch = footerData.getGitBranch();
162
- const name = ctx.sessionManager.getSessionName();
163
- const cwd =
164
- ctx.cwd === homedir()
165
- ? "~"
166
- : ctx.cwd.startsWith(homedir() + "/")
167
- ? "~" + ctx.cwd.slice(homedir().length)
168
- : ctx.cwd;
169
- const location = cwd + (branch ? ` (${branch})` : "") + (name ? ` • ${name}` : "");
170
- const parts: string[] = [];
171
- if (totals.input) parts.push(`↑${tokens(totals.input)}`);
172
- if (totals.output) parts.push(`↓${tokens(totals.output)}`);
173
- if (totals.cacheRead) parts.push(`R${tokens(totals.cacheRead)}`);
174
- if (totals.cacheWrite) parts.push(`W${tokens(totals.cacheWrite)}`);
175
- if ((totals.cacheRead || totals.cacheWrite) && totals.cacheHit !== undefined)
176
- parts.push(`CH${totals.cacheHit.toFixed(1)}%`);
177
- // Pi's own usage and each child's own usage are disjoint. Never aggregate a parent's descendants twice.
178
- const subscription =
179
- ctx.model &&
180
- (ctx.model.provider === "kimi-coding" || ctx.modelRegistry?.isUsingOAuth(ctx.model));
181
- const costText =
182
- displayCost?.(totals.cost) ?? `$${(totals.cost + subagentCost()).toFixed(3)}`;
183
- parts.push(`${costText}${subscription ? " (sub)" : ""}`);
184
- const context = ctx.getContextUsage();
185
- if (context) {
186
- const text = `${context.percent === null ? "?" : context.percent.toFixed(1) + "%"}/${tokens(context.contextWindow)}`;
187
- parts.push(
188
- theme.fg(
189
- (context.percent ?? 0) > 90
190
- ? "error"
191
- : (context.percent ?? 0) > 70
192
- ? "warning"
193
- : "dim",
194
- text,
195
- ),
196
- );
197
- }
198
- const left = truncateToWidth(parts.join(" "), width, "");
199
- let right = ctx.model?.id ?? "no-model";
200
- if (ctx.model?.reasoning) right += ` • ${ctx.thinkingLevel ?? "off"}`;
201
- if (footerData.getAvailableProviderCount() > 1 && ctx.model) {
202
- const withProvider = `(${ctx.model.provider}) ${right}`;
203
- if (visibleWidth(left) + 2 + visibleWidth(withProvider) <= width) right = withProvider;
204
- }
205
- const available = width - visibleWidth(left) - 2;
206
- const stats =
207
- available > 0
208
- ? left +
209
- " ".repeat(
210
- Math.max(2, width - visibleWidth(left) - Math.min(available, visibleWidth(right))),
211
- ) +
212
- truncateToWidth(right, available, "")
213
- : left;
214
- const lines = [truncateToWidth(theme.fg("dim", location), width), theme.fg("dim", stats)];
215
- const statuses = [...footerData.getExtensionStatuses()]
216
- .sort(([a], [b]) => a.localeCompare(b))
217
- .map(([, text]) =>
218
- text
219
- .replace(/[\r\n\t]/g, " ")
220
- .replace(/ +/g, " ")
221
- .trim(),
222
- );
223
- if (statuses.length)
224
- lines.push(truncateToWidth(theme.fg("dim", statuses.join(" ")), width));
225
- return lines;
226
- },
227
- };
228
- });
229
- return () => requestRender?.();
230
- }