pi-subagent-manager 0.19.0 β 0.21.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 +2 -2
- package/docs/pi-footer.md +128 -0
- package/docs/settings.md +11 -5
- package/docs/tools-and-ui.md +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/prefs/settings.ts +23 -1
- package/src/ui/cost-footer.ts +26 -12
- package/src/ui/live-agent-view.ts +111 -169
- package/src/ui/settings-ui.ts +69 -15
- package/src/ui/status-ui.ts +9 -10
- package/src/ui/thread-tree.ts +2 -2
- package/src/ui/transcript-tool.ts +142 -0
package/README.md
CHANGED
|
@@ -77,9 +77,9 @@ A live **Agents** widget sits above the input box. Choose **Full** (the existing
|
|
|
77
77
|
|
|
78
78
|
**Cost accounting:** Agent rows show estimated USD cost (including cache reads/writes) when reported. Completed, paused, stopped, and failed agents roll up only newly incurred cost. Accounting survives resume, reload, branch navigation, and reaping; nested agents' own costs are counted once. Running-agent costs remain in their rows until settlement. This changes the footer display, not Pi's native session statistics.
|
|
79
79
|
|
|
80
|
-
-
|
|
80
|
+
- Open **[labs] Footer display** in `/agents settings` to choose a location (**Replace Pi status**, **pi-footer status widget**, or **pi-footer event**), a value (**Only subagent cost** or **Total cost**), and a money icon. Defaults: status widget, settled subagent-only cost, and π΅. The stable ID/key is **`subagent_cost`**.
|
|
81
81
|
- **`npm:pi-footer`:** with the default status-key mode, add **Extension Status** through `/footer` and select **`subagent_cost`**. Event mode instead requires a **Pi Event Value** widget with **Widget ID** entered manually and **Raw value only** enabled; event IDs are not listed in the status selector.
|
|
82
|
-
- Values publish at session start and immediately on subagent startup, including
|
|
82
|
+
- Values publish at session start and immediately on subagent startup, including `π΅ $0.0000`, then after settlement/settings changes. Total cost includes the main session plus settled subagents. The icon picker offers three Nerd Font choices when the labs toggle is on, otherwise three emoji choices. Status modes leave your footer untouched; event mode retains a fallback showing the selected value/icon when no extension provides `/footer`. See [Cost display settings](docs/settings.md#labs-cost-display-costdisplay) and the [pi-footer setup guide with exact snippets](docs/pi-footer.md).
|
|
83
83
|
|
|
84
84
|
Experimental features are marked **[labs]** in settings. Enable **[labs] Nerd Font icons** in `/agents` to show role-specific icons beside agent names (off by default; requires a Nerd Font in your terminal). Loaders appear **before**, never instead of, the role icon. Choose Circle, Braille, or Hourglass under **[labs] Loader style**, with previews of every animation frame and each family's completed, paused, failed, and stopped icons. Custom agent types can set an optional `icon` or use **[labs] Icon** in `/agents types`. See [icon setup](docs/settings.md#labs-nerd-font-icons-nerdfonticons).
|
|
85
85
|
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Subagent dollar totals in pi-footer
|
|
2
|
+
|
|
3
|
+
With `npm:pi-footer` loaded, choose one of the two integration paths below. Both
|
|
4
|
+
show the selected **Display value**: settled subagent-only USD (default), or total
|
|
5
|
+
main-session + settled-subagent USD. Keep pi-footerβs native cost widget if you
|
|
6
|
+
want the main-session cost shown separately.
|
|
7
|
+
|
|
8
|
+
The shared status key / event Widget ID is exactly **`subagent_cost`**. It is not
|
|
9
|
+
`pi-subagent-manager`, an extension file path, or an npm package ID.
|
|
10
|
+
|
|
11
|
+
## Extension Status (recommended; default)
|
|
12
|
+
|
|
13
|
+
1. Open `/agents settings` β **[labs] Footer display** β **Location**, choose
|
|
14
|
+
**pi-footer status widget**, return to settings, and save with **Ctrl+S**.
|
|
15
|
+
2. Open `/footer`, choose **Edit lines**, select a row, and add **Extension Status**.
|
|
16
|
+
3. Set **Status key** to **`subagent_cost`** and enable **Raw value only**.
|
|
17
|
+
4. Save the footer configuration.
|
|
18
|
+
|
|
19
|
+
The corresponding subagent-manager setting is:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"costDisplay": "pi-footer-status"
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
For a file-based footer setup, insert this widget object into an existing row
|
|
28
|
+
array in `lines` in `~/.pi/agent/extensions/pi-footer.json`:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"id": "subagent-cost-status",
|
|
33
|
+
"type": "external-status",
|
|
34
|
+
"enabled": true,
|
|
35
|
+
"options": {
|
|
36
|
+
"externalStatusKey": "subagent_cost",
|
|
37
|
+
"raw": true,
|
|
38
|
+
"hideWhenEmpty": true,
|
|
39
|
+
"trimValue": 0
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Here `id` identifies the footer widget instance; **`externalStatusKey`** is the
|
|
45
|
+
lookup key that must match the publisher. Do not put the package name in it.
|
|
46
|
+
The manager already publishes the value using this API (no extra extension needed):
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
ctx.ui.setStatus("subagent_cost", "π΅ $0.1234");
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
It clears the status with `ctx.ui.setStatus("subagent_cost", undefined)`.
|
|
53
|
+
|
|
54
|
+
## Pi Event Value (alternative)
|
|
55
|
+
|
|
56
|
+
1. Open `/agents settings` β **[labs] Footer display** β **Location**, choose
|
|
57
|
+
**pi-footer event**, return to settings, and save with **Ctrl+S**.
|
|
58
|
+
2. In `/footer`, add a **Pi Event Value** widget to the desired row.
|
|
59
|
+
3. Enter **Widget ID** as **`subagent_cost`** manually, replacing the generated ID,
|
|
60
|
+
and enable **Raw value only**. Event IDs do **not** appear in the status-key selector.
|
|
61
|
+
4. Save the footer configuration.
|
|
62
|
+
|
|
63
|
+
The corresponding subagent-manager setting is:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"costDisplay": "pi-footer-event"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Insert this widget object into an existing row array in the footer's `lines`:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"id": "subagent-cost-event",
|
|
76
|
+
"type": "event",
|
|
77
|
+
"enabled": true,
|
|
78
|
+
"options": {
|
|
79
|
+
"widgetId": "subagent_cost",
|
|
80
|
+
"raw": true,
|
|
81
|
+
"hideWhenEmpty": true
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The manager already emits the following event; no custom publisher is required.
|
|
87
|
+
This is the exact event name and payload shape, with an illustrative dollar value:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
pi.events.emit("pi-footer:update-widget", {
|
|
91
|
+
widgetId: "subagent_cost",
|
|
92
|
+
value: "π΅ $0.1234",
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
To clear the event value, the manager emits:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
pi.events.emit("pi-footer:update-widget", {
|
|
100
|
+
widgetId: "subagent_cost",
|
|
101
|
+
value: null,
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## File locations and refresh behavior
|
|
106
|
+
|
|
107
|
+
- Merge `costDisplay`, `costValue`, and `costIcon` settings into
|
|
108
|
+
`~/.pi/agent/subagent-manager/settings.json`, or the trusted-project override
|
|
109
|
+
`.pi/agent/subagent-manager/settings.json`. Preserve your other settings.
|
|
110
|
+
- Footer widget snippets are **objects inside a row**, not complete configuration
|
|
111
|
+
files: the structure is `"lines": [[widgetObject, otherWidgetObject]]`. Preserve
|
|
112
|
+
existing rows and widgets. `PI_FOOTER_CONFIG` can override the footer file path.
|
|
113
|
+
- After manual file edits, use Pi's `/reload` to reload extensions and settings.
|
|
114
|
+
Using the settings dialogs applies changes immediately when saved.
|
|
115
|
+
- Choose only the widget matching your selected mode. Switching modes clears the
|
|
116
|
+
old output; shutdown clears the published value too.
|
|
117
|
+
- `$0.0000` appears at session start/reload and immediately on subagent startup.
|
|
118
|
+
Running costs settle on completion, pause, stop, or failure; they remain in
|
|
119
|
+
agent rows until then. Nested agents are counted once, and accounting survives
|
|
120
|
+
resume and reaping. The selected money, coins, or wallet icon prefixes the
|
|
121
|
+
dollar value: emoji with Nerd Font icons off, or a Nerd Font glyph with it on.
|
|
122
|
+
- If the status key is missing, check that the manager is loaded and the location
|
|
123
|
+
is **pi-footer status widget**, not **pi-footer event**. **Replace Pi status**
|
|
124
|
+
uses the same status key but includes a Subagents/Total label. All locations
|
|
125
|
+
support either display value; choose **Only subagent cost** for a subtotal.
|
|
126
|
+
|
|
127
|
+
See [Cost display settings](settings.md#labs-cost-display-costdisplay) for all modes
|
|
128
|
+
and fallback behavior when pi-footer is not loaded.
|
package/docs/settings.md
CHANGED
|
@@ -18,6 +18,8 @@ All keys are optional. Defaults:
|
|
|
18
18
|
"nerdFontIcons": false,
|
|
19
19
|
"loaderStyle": "circle",
|
|
20
20
|
"costDisplay": "pi-footer-status",
|
|
21
|
+
"costValue": "subagents",
|
|
22
|
+
"costIcon": "money",
|
|
21
23
|
"finalRecap": false,
|
|
22
24
|
"modelSelection": "pick-first-scoped",
|
|
23
25
|
"toolFiltering": "allowed",
|
|
@@ -73,15 +75,19 @@ The Labs preview shows every family's running animation frames and completed, pa
|
|
|
73
75
|
|
|
74
76
|
## [labs] Cost display (`costDisplay`)
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
Open **[labs] Footer display** in `/agents settings` to choose the location, display value, and icon, then return and save. The stable ID/key is **`subagent_cost`**.
|
|
77
79
|
|
|
78
80
|
| Value | Output |
|
|
79
81
|
| --- | --- |
|
|
80
|
-
| `pi-footer-status` (default) | Publishes
|
|
81
|
-
| `pi-footer-event` | Emits `pi-footer:update-widget` with `widgetId: "subagent_cost"`. Add **Pi Event Value**, enter **Widget ID** manually, and enable **Raw value only**. Event IDs do not appear in the status selector. Without an extension providing `/footer`, preserves the
|
|
82
|
-
| `pi-status` |
|
|
82
|
+
| `pi-footer-status` (default) | Publishes `π΅ $0.0000` via Piβs `setStatus` API. In `/footer`, add **Extension Status** and pick **`subagent_cost`** from the status-key selector. |
|
|
83
|
+
| `pi-footer-event` | Emits `pi-footer:update-widget` with `widgetId: "subagent_cost"`. Add **Pi Event Value**, enter **Widget ID** manually, and enable **Raw value only**. Event IDs do not appear in the status selector. Without an extension providing `/footer`, preserves the fallback footer, using the selected value/icon. |
|
|
84
|
+
| `pi-status` | **Replace Pi status**: sets the managerβs Pi status to `Subagents: π΅ $0.0000` or `Total: π΅ $0.0000`; no pi-footer events or custom footer. |
|
|
83
85
|
|
|
84
|
-
Both status modes use the same public Pi status API: third-party footers may also display Pi status-only output. These modes never replace your footer.
|
|
86
|
+
Both status modes use the same public Pi status API: third-party footers may also display Pi status-only output. These modes never replace your footer. **Display value** (`costValue`) is independent of location: `subagents` (default) shows settled subagent-only USD; `total` adds the main sessionβs cost. In all modes, running subagent costs settle on completion, pause, stop, or failure. Values publish on session start/reload, immediately when a subagent starts (even at zero), after settlement/settings changes, and when main-session turns end. Switching locations clears the previous output; shutdown clears the published value.
|
|
87
|
+
|
|
88
|
+
**Icon** (`costIcon`) offers `money` (default), `coins`, or `wallet`. With **[labs] Nerd Font icons** off, these appear as π΅, πͺ, or π. With it on, the picker and output use corresponding Nerd Font glyphs instead. The semantic choice survives toggling font mode.
|
|
89
|
+
|
|
90
|
+
See [Subagent dollar totals in pi-footer](pi-footer.md) for step-by-step setup and copy-paste widget configuration, status-key, and event snippets.
|
|
85
91
|
|
|
86
92
|
## [labs] Final Recap (`finalRecap`)
|
|
87
93
|
|
package/docs/tools-and-ui.md
CHANGED
|
@@ -72,7 +72,7 @@ Refreshes every second and keeps your selection, collapse state and scroll posit
|
|
|
72
72
|
|
|
73
73
|
### Live agent navigation
|
|
74
74
|
|
|
75
|
-
The fullscreen watcher renders steer and agent messages (including thinking) as Markdown, same as pi's main transcript. Tool calls
|
|
75
|
+
The fullscreen watcher renders steer and agent messages (including thinking) as Markdown, same as pi's main transcript. Tool calls and their results share pi's native `ToolExecutionComponent`, with built-in renderers for shell commands, reads, highlighted writes, edit diffs and search tools. Pending, successful and failed executions use pi's active theme colors. Unknown tools use pi's safe generic renderer; nested executions appear beneath their parent. **Ctrl+O** toggles full tool output from either input or transcript focus. **t** cycles detail levels with transcript controls focused: **preview** (default: pi's native tool previews, first three rendered thinking lines), **compact** (one line per call, thinking hidden), **full** (complete tool output and thinking). Successful reads are collapsed by default, just like pi; expand them with **Ctrl+O**. Inherited context is initially collapsed (**c** toggles it with transcript controls focused). Watching alone never starts a turn, switches sessions, or changes model/tool/resource ownership. Extension renderers are never invoked, raw terminal controls are stripped, and images use safe text placeholders. Legacy sessions without reliable inherited-prefix metadata show their whole transcript.
|
|
76
76
|
|
|
77
77
|
- The bottom **Steer** input is focused initially. Type and press **Enter** to send to the inspected agent, including nested descendants, through the same service as `agent_steer`: running agents receive queued input; paused/completed/stopped agents resume their retained session. Empty input is ignored. Sending leaves the viewer open; failures are shown and preserve the draft for retry.
|
|
78
78
|
- **Tab** switches between steering input and transcript controls. While typing, **c/t/l/r** are ordinary text and **Home/End** move the input cursor. Pasting never submits by itself.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -51,6 +51,8 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
51
51
|
() => costLedger.totalUsd,
|
|
52
52
|
() => limits.nerdFontIcons,
|
|
53
53
|
() => limits.costDisplay,
|
|
54
|
+
() => limits.costValue,
|
|
55
|
+
() => limits.costIcon,
|
|
54
56
|
);
|
|
55
57
|
const refreshCostFooter = (ctx: ExtensionContext) => costFooter.refresh(ctx);
|
|
56
58
|
const rollupCost = (thread: ThreadView) => {
|
package/src/prefs/settings.ts
CHANGED
|
@@ -22,6 +22,12 @@ export type WidgetMode = (typeof WIDGET_MODES)[number];
|
|
|
22
22
|
export const COST_DISPLAY_MODES = ["pi-footer-event", "pi-footer-status", "pi-status"] as const;
|
|
23
23
|
export type CostDisplayMode = (typeof COST_DISPLAY_MODES)[number];
|
|
24
24
|
|
|
25
|
+
export const COST_VALUES = ["subagents", "total"] as const;
|
|
26
|
+
export type CostValue = (typeof COST_VALUES)[number];
|
|
27
|
+
|
|
28
|
+
export const COST_ICONS = ["money", "coins", "wallet"] as const;
|
|
29
|
+
export type CostIcon = (typeof COST_ICONS)[number];
|
|
30
|
+
|
|
25
31
|
export const LOADER_STYLES = ["circle", "braille", "hourglass"] as const;
|
|
26
32
|
export type LoaderStyle = (typeof LOADER_STYLES)[number];
|
|
27
33
|
|
|
@@ -40,6 +46,8 @@ export interface ManagerSettings {
|
|
|
40
46
|
toolFiltering: ToolFilteringMode;
|
|
41
47
|
widgetMode: WidgetMode;
|
|
42
48
|
costDisplay: CostDisplayMode;
|
|
49
|
+
costValue: CostValue;
|
|
50
|
+
costIcon: CostIcon;
|
|
43
51
|
nerdFontIcons: boolean;
|
|
44
52
|
loaderStyle: LoaderStyle;
|
|
45
53
|
finalRecap: boolean;
|
|
@@ -58,13 +66,15 @@ export const DEFAULT_MANAGER_SETTINGS: ManagerSettings = {
|
|
|
58
66
|
toolFiltering: "allowed",
|
|
59
67
|
widgetMode: "full",
|
|
60
68
|
costDisplay: "pi-footer-status",
|
|
69
|
+
costValue: "subagents",
|
|
70
|
+
costIcon: "money",
|
|
61
71
|
nerdFontIcons: false,
|
|
62
72
|
loaderStyle: "circle",
|
|
63
73
|
finalRecap: false,
|
|
64
74
|
};
|
|
65
75
|
|
|
66
76
|
const KEYS = [
|
|
67
|
-
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "costDisplay", "nerdFontIcons", "loaderStyle", "finalRecap",
|
|
77
|
+
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "costDisplay", "costValue", "costIcon", "nerdFontIcons", "loaderStyle", "finalRecap",
|
|
68
78
|
] as const;
|
|
69
79
|
const MAX_LEVELS = 32;
|
|
70
80
|
|
|
@@ -106,6 +116,8 @@ function requirement(key: (typeof KEYS)[number]): string {
|
|
|
106
116
|
if (key === "subagentMode") return "subagentMode must be off, opportunistic or orchestration";
|
|
107
117
|
if (key === "widgetMode") return "widgetMode must be full or minimal";
|
|
108
118
|
if (key === "costDisplay") return "costDisplay must be pi-footer-event, pi-footer-status or pi-status";
|
|
119
|
+
if (key === "costValue") return "costValue must be subagents or total";
|
|
120
|
+
if (key === "costIcon") return "costIcon must be money, coins or wallet";
|
|
109
121
|
if (key === "loaderStyle") return "loaderStyle must be circle, braille or hourglass";
|
|
110
122
|
if (key === "toolFiltering") return "toolFiltering must be allowed, all-except-blocked or all";
|
|
111
123
|
if (key === "modelSelection")
|
|
@@ -165,6 +177,16 @@ function parseSettings(content: string): Partial<ManagerSettings> {
|
|
|
165
177
|
layer.costDisplay = value as CostDisplayMode;
|
|
166
178
|
continue;
|
|
167
179
|
}
|
|
180
|
+
if (key === "costValue") {
|
|
181
|
+
if (!COST_VALUES.includes(value as CostValue)) throw new Error(requirement(key));
|
|
182
|
+
layer.costValue = value as CostValue;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (key === "costIcon") {
|
|
186
|
+
if (!COST_ICONS.includes(value as CostIcon)) throw new Error(requirement(key));
|
|
187
|
+
layer.costIcon = value as CostIcon;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
168
190
|
if (key === "loaderStyle") {
|
|
169
191
|
if (!LOADER_STYLES.includes(value as LoaderStyle)) throw new Error(requirement(key));
|
|
170
192
|
layer.loaderStyle = value as LoaderStyle;
|
package/src/ui/cost-footer.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { homedir } from "node:os";
|
|
|
2
2
|
import type { Usage } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { ExtensionAPI, ExtensionContext, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
5
|
-
import type { CostDisplayMode } from "../prefs/settings.ts";
|
|
5
|
+
import type { CostDisplayMode, CostValue, CostIcon } from "../prefs/settings.ts";
|
|
6
6
|
|
|
7
7
|
export function footerUsage(entries: readonly SessionEntry[]) {
|
|
8
8
|
const totals = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
|
|
@@ -32,6 +32,15 @@ export const COST_WIDGET_ID = "subagent_cost";
|
|
|
32
32
|
export const COST_WIDGET_EVENT = "pi-footer:update-widget";
|
|
33
33
|
export const COST_ICON = "\uf0d6";
|
|
34
34
|
|
|
35
|
+
export function costIconGlyph(icon: CostIcon, nerdFontIcons: boolean): string {
|
|
36
|
+
const glyphs = {
|
|
37
|
+
money: { emoji: "π΅", nerd: COST_ICON },
|
|
38
|
+
coins: { emoji: "πͺ", nerd: "\u{f0512}" },
|
|
39
|
+
wallet: { emoji: "π", nerd: "\u{f055d}" },
|
|
40
|
+
};
|
|
41
|
+
return glyphs[icon][nerdFontIcons ? "nerd" : "emoji"];
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
export function formatSubagentCost(cost: number, nerdFontIcons: boolean): string {
|
|
36
45
|
return `${nerdFontIcons ? COST_ICON + " " : ""}$${cost.toFixed(4)}`;
|
|
37
46
|
}
|
|
@@ -54,11 +63,20 @@ export class CostFooterController {
|
|
|
54
63
|
private readonly subagentCost: () => number,
|
|
55
64
|
private readonly nerdFontIcons: () => boolean,
|
|
56
65
|
private readonly displayMode: () => CostDisplayMode = () => "pi-footer-status",
|
|
66
|
+
private readonly costValue: () => CostValue = () => "subagents",
|
|
67
|
+
private readonly costIcon: () => CostIcon = () => "money",
|
|
57
68
|
) {}
|
|
58
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
|
+
|
|
59
75
|
refresh(ctx: ExtensionContext): void {
|
|
60
76
|
const mode = this.displayMode();
|
|
61
|
-
const value =
|
|
77
|
+
const value = this.formatCost(
|
|
78
|
+
this.costValue() === "total" ? footerUsage(ctx.sessionManager.getEntries()).cost : 0,
|
|
79
|
+
);
|
|
62
80
|
if (this.publishedMode !== undefined && this.publishedMode !== mode) {
|
|
63
81
|
this.clear();
|
|
64
82
|
this.reset(ctx);
|
|
@@ -67,14 +85,8 @@ export class CostFooterController {
|
|
|
67
85
|
if (mode !== "pi-footer-event") {
|
|
68
86
|
if (ctx.hasUI) {
|
|
69
87
|
this.statusContext = ctx;
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
? `Total: ${formatSubagentCost(
|
|
73
|
-
footerUsage(ctx.sessionManager.getEntries()).cost + this.subagentCost(),
|
|
74
|
-
this.nerdFontIcons(),
|
|
75
|
-
)}`
|
|
76
|
-
: value;
|
|
77
|
-
ctx.ui.setStatus(COST_WIDGET_ID, statusValue);
|
|
88
|
+
const label = this.costValue() === "total" ? "Total" : "Subagents";
|
|
89
|
+
ctx.ui.setStatus(COST_WIDGET_ID, mode === "pi-status" ? `${label}: ${value}` : value);
|
|
78
90
|
}
|
|
79
91
|
return;
|
|
80
92
|
}
|
|
@@ -91,7 +103,7 @@ export class CostFooterController {
|
|
|
91
103
|
return;
|
|
92
104
|
}
|
|
93
105
|
if (this.subagentCost() <= 0 || !ctx.hasUI || ctx.mode !== "tui") return;
|
|
94
|
-
this.requestRender = installCostFooter(ctx, this.subagentCost);
|
|
106
|
+
this.requestRender = installCostFooter(ctx, this.subagentCost, (mainCost) => this.formatCost(mainCost));
|
|
95
107
|
this.installed = true;
|
|
96
108
|
}
|
|
97
109
|
|
|
@@ -123,6 +135,7 @@ const tokens = (n: number) =>
|
|
|
123
135
|
export function installCostFooter(
|
|
124
136
|
ctx: ExtensionContext,
|
|
125
137
|
subagentCost: () => number,
|
|
138
|
+
displayCost?: (mainCost: number) => string,
|
|
126
139
|
): (() => void) | undefined {
|
|
127
140
|
if (!ctx.hasUI || ctx.mode !== "tui" || !ctx.ui.setFooter) return;
|
|
128
141
|
let requestRender: (() => void) | undefined;
|
|
@@ -163,7 +176,8 @@ export function installCostFooter(
|
|
|
163
176
|
const subscription =
|
|
164
177
|
ctx.model &&
|
|
165
178
|
(ctx.model.provider === "kimi-coding" || ctx.modelRegistry?.isUsingOAuth(ctx.model));
|
|
166
|
-
|
|
179
|
+
const costText = displayCost?.(totals.cost) ?? `$${(totals.cost + subagentCost()).toFixed(3)}`;
|
|
180
|
+
parts.push(`${costText}${subscription ? " (sub)" : ""}`);
|
|
167
181
|
const context = ctx.getContextUsage();
|
|
168
182
|
if (context) {
|
|
169
183
|
const text = `${context.percent === null ? "?" : context.percent.toFixed(1) + "%"}/${tokens(context.contextWindow)}`;
|
|
@@ -11,12 +11,11 @@ import {
|
|
|
11
11
|
visibleWidth,
|
|
12
12
|
wrapTextWithAnsi,
|
|
13
13
|
} from "@earendil-works/pi-tui";
|
|
14
|
-
import type { ThreadService, TranscriptSnapshot } from "../types.ts";
|
|
14
|
+
import type { ThreadService, TranscriptSnapshot, TranscriptToolState } from "../types.ts";
|
|
15
15
|
import { dialogText, type DialogHost } from "./dialog.ts";
|
|
16
16
|
import { AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeLabel } from "./ui.ts";
|
|
17
17
|
import type { LoaderStyle } from "../prefs/settings.ts";
|
|
18
|
-
|
|
19
|
-
type ThemeBg = Parameters<Theme["bg"]>[0];
|
|
18
|
+
import { renderTranscriptTool } from "./transcript-tool.ts";
|
|
20
19
|
|
|
21
20
|
/** Transcript detail level cycled by the t key: full β preview β compact. */
|
|
22
21
|
export type TranscriptDetail = "full" | "preview" | "compact";
|
|
@@ -59,7 +58,7 @@ function json(value: unknown): string {
|
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
/** Live transcript and manual steering.
|
|
61
|
+
/** Live transcript and manual steering. Reuse trusted pi built-ins; strip untrusted controls. */
|
|
63
62
|
export class LiveAgentView {
|
|
64
63
|
private snapshot: TranscriptSnapshot | undefined;
|
|
65
64
|
private error: string | undefined;
|
|
@@ -84,6 +83,22 @@ export class LiveAgentView {
|
|
|
84
83
|
private steerStatus: string | undefined;
|
|
85
84
|
private steerFailed = false;
|
|
86
85
|
|
|
86
|
+
private results = new Map<string, AgentMessage>();
|
|
87
|
+
private tools = new Map<string, TranscriptToolState>();
|
|
88
|
+
private renderedTools = new Set<string>();
|
|
89
|
+
private toolCache = new Map<
|
|
90
|
+
string,
|
|
91
|
+
{
|
|
92
|
+
args: unknown;
|
|
93
|
+
result: unknown;
|
|
94
|
+
running: boolean;
|
|
95
|
+
isError: boolean;
|
|
96
|
+
name: string;
|
|
97
|
+
width: number;
|
|
98
|
+
detail: TranscriptDetail;
|
|
99
|
+
lines: string[];
|
|
100
|
+
}
|
|
101
|
+
>();
|
|
87
102
|
constructor(
|
|
88
103
|
private host: DialogHost,
|
|
89
104
|
private theme: Theme,
|
|
@@ -186,6 +201,7 @@ export class LiveAgentView {
|
|
|
186
201
|
snapshot.revision < this.snapshot.revision))
|
|
187
202
|
)
|
|
188
203
|
return;
|
|
204
|
+
if (snapshot.generation !== this.snapshot?.generation) this.toolCache.clear();
|
|
189
205
|
this.snapshot = snapshot;
|
|
190
206
|
this.error = snapshot.error;
|
|
191
207
|
this.syncProgress();
|
|
@@ -219,6 +235,7 @@ export class LiveAgentView {
|
|
|
219
235
|
|
|
220
236
|
invalidate(): void {
|
|
221
237
|
this.cache = new WeakMap();
|
|
238
|
+
this.toolCache.clear();
|
|
222
239
|
this.input.invalidate();
|
|
223
240
|
}
|
|
224
241
|
|
|
@@ -242,6 +259,12 @@ export class LiveAgentView {
|
|
|
242
259
|
if (matchesKey(data, Key.escape)) return this.done("back");
|
|
243
260
|
if (matchesKey(data, Key.ctrl("q")) || matchesKey(data, Key.ctrl("c")))
|
|
244
261
|
return this.done("main");
|
|
262
|
+
if (matchesKey(data, Key.ctrl("o"))) {
|
|
263
|
+
this.viewport.detail = this.detail === "full" ? "preview" : "full";
|
|
264
|
+
this.invalidate();
|
|
265
|
+
this.host.requestRender();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
245
268
|
if (matchesKey(data, Key.tab)) {
|
|
246
269
|
this.editing = !this.editing;
|
|
247
270
|
this.input.focused = this.focused && this.editing;
|
|
@@ -290,18 +313,6 @@ export class LiveAgentView {
|
|
|
290
313
|
return lines.map((line) => ` ${line}`);
|
|
291
314
|
}
|
|
292
315
|
|
|
293
|
-
/** Full-width themed band with one column of padding, like pi's tool boxes. */
|
|
294
|
-
private band(lines: string[], token: ThemeBg, width: number): string[] {
|
|
295
|
-
const inner = Math.max(1, width - 2);
|
|
296
|
-
return lines.map((line) => {
|
|
297
|
-
const clipped = truncateToWidth(line, inner, "", true);
|
|
298
|
-
return this.theme.bg(
|
|
299
|
-
token,
|
|
300
|
-
` ${clipped}${" ".repeat(Math.max(0, inner - visibleWidth(clipped)))} `,
|
|
301
|
-
);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
316
|
private wrap(value: string, width: number): string[] {
|
|
306
317
|
return text(value)
|
|
307
318
|
.split("\n")
|
|
@@ -354,11 +365,7 @@ export class LiveAgentView {
|
|
|
354
365
|
return content.flatMap((value) => {
|
|
355
366
|
const block = object(value);
|
|
356
367
|
if (block?.type === "toolCall")
|
|
357
|
-
return this.
|
|
358
|
-
this.toolCall(String(block.name), block.arguments, inner),
|
|
359
|
-
"toolSuccessBg",
|
|
360
|
-
width,
|
|
361
|
-
);
|
|
368
|
+
return this.tool(String(block.id), String(block.name), block.arguments, width);
|
|
362
369
|
return this.pad(this.blockLines(value, inner));
|
|
363
370
|
});
|
|
364
371
|
}
|
|
@@ -381,13 +388,17 @@ export class LiveAgentView {
|
|
|
381
388
|
}
|
|
382
389
|
|
|
383
390
|
private message(message: AgentMessage, width: number): string[] {
|
|
384
|
-
|
|
385
|
-
|
|
391
|
+
if (message.role === "toolResult") {
|
|
392
|
+
const result = message as unknown as Record<string, unknown>;
|
|
393
|
+
return this.tool(String(result.toolCallId), String(result.toolName), {}, width);
|
|
394
|
+
}
|
|
386
395
|
const data = message as unknown as Record<string, unknown>;
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
396
|
+
const hasTools =
|
|
397
|
+
Array.isArray(data.content) &&
|
|
398
|
+
data.content.some((block: unknown) => object(block)?.type === "toolCall");
|
|
399
|
+
const cached = !hasTools && this.cache.get(message);
|
|
400
|
+
if (cached && cached.width === width && cached.detail === this.detail) return cached.lines;
|
|
401
|
+
const label = message.role;
|
|
391
402
|
const collapsed = !["user", "assistant", "custom"].includes(message.role);
|
|
392
403
|
const content = data.content ?? data.summary ?? data.output ?? data;
|
|
393
404
|
const inner = Math.max(1, width - 2);
|
|
@@ -398,128 +409,64 @@ export class LiveAgentView {
|
|
|
398
409
|
: this.wrap(String(data.errorMessage), inner)
|
|
399
410
|
).map((line) => this.theme.fg("error", line))
|
|
400
411
|
: [];
|
|
401
|
-
const lines =
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
),
|
|
409
|
-
"",
|
|
410
|
-
]
|
|
411
|
-
: [
|
|
412
|
-
...this.pad([heading]),
|
|
413
|
-
...(collapsed ? this.pad(this.preview(content, inner)) : this.blocks(content, width)),
|
|
414
|
-
...this.pad(errors),
|
|
415
|
-
"",
|
|
416
|
-
];
|
|
417
|
-
this.cache.set(message, { width, detail: this.detail, lines });
|
|
412
|
+
const lines = [
|
|
413
|
+
...this.pad([heading]),
|
|
414
|
+
...(collapsed ? this.pad(this.preview(content, inner)) : this.blocks(content, width)),
|
|
415
|
+
...this.pad(errors),
|
|
416
|
+
"",
|
|
417
|
+
];
|
|
418
|
+
if (!hasTools) this.cache.set(message, { width, detail: this.detail, lines });
|
|
418
419
|
return lines;
|
|
419
420
|
}
|
|
420
421
|
|
|
421
|
-
/**
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
};
|
|
434
|
-
const num = (key: string): number | undefined => {
|
|
435
|
-
const value = data?.[key];
|
|
436
|
-
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
437
|
-
};
|
|
438
|
-
const title = (value: string) => this.theme.fg("accent", value);
|
|
439
|
-
const detail = (value: string) => this.theme.fg("muted", value);
|
|
440
|
-
const path = str("file_path") ?? str("path");
|
|
422
|
+
/** Pair a call with its committed result or live partial, then render nested executions in place. */
|
|
423
|
+
private tool(id: string, name: string, args: unknown, width: number): string[] {
|
|
424
|
+
if (this.renderedTools.has(id)) return [];
|
|
425
|
+
this.renderedTools.add(id);
|
|
426
|
+
const state = this.tools.get(id);
|
|
427
|
+
const result = this.results.get(id) ?? state?.result;
|
|
428
|
+
const running =
|
|
429
|
+
!this.results.has(id) && (state ? state.state === "running" : result === undefined);
|
|
430
|
+
const isError = Boolean(object(result)?.isError ?? state?.isError);
|
|
431
|
+
// Committed call arguments are authoritative; orphan results use retained live args if available.
|
|
432
|
+
if (state && !Object.keys(object(args) ?? {}).length) args = state.args;
|
|
433
|
+
const cached = this.toolCache.get(id);
|
|
441
434
|
let lines: string[];
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
break;
|
|
466
|
-
}
|
|
467
|
-
case "edit":
|
|
468
|
-
lines = [`${title("edit")} ${path ?? "?"}`];
|
|
469
|
-
break;
|
|
470
|
-
case "write": {
|
|
471
|
-
lines = [`${title("write")} ${path ?? "?"}`];
|
|
472
|
-
const content = str("content");
|
|
473
|
-
if (content) {
|
|
474
|
-
const contentLines = content.split("\n");
|
|
475
|
-
while (contentLines.length && contentLines.at(-1) === "") contentLines.pop();
|
|
476
|
-
lines.push(...contentLines);
|
|
477
|
-
}
|
|
478
|
-
break;
|
|
479
|
-
}
|
|
480
|
-
case "grep": {
|
|
481
|
-
const pattern = str("pattern");
|
|
482
|
-
const glob = str("glob");
|
|
483
|
-
const limit = num("limit");
|
|
484
|
-
lines = [
|
|
485
|
-
`${title("grep")} ${this.theme.fg("accent", `/${pattern ?? ""}/`)}` +
|
|
486
|
-
`${path ? detail(` in ${path}`) : ""}${glob ? detail(` (${glob})`) : ""}` +
|
|
487
|
-
`${limit != null ? detail(` limit ${limit}`) : ""}`,
|
|
488
|
-
];
|
|
489
|
-
break;
|
|
490
|
-
}
|
|
491
|
-
case "find": {
|
|
492
|
-
const pattern = str("pattern");
|
|
493
|
-
const limit = num("limit");
|
|
494
|
-
lines = [
|
|
495
|
-
`${title("find")} ${this.theme.fg("accent", pattern ?? "")}` +
|
|
496
|
-
`${path ? detail(` in ${path}`) : ""}${limit != null ? detail(` (limit ${limit})`) : ""}`,
|
|
497
|
-
];
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
case "ls": {
|
|
501
|
-
const limit = num("limit");
|
|
502
|
-
lines = [
|
|
503
|
-
`${title("ls")} ${path ?? "."}${limit != null ? detail(` (limit ${limit})`) : ""}`,
|
|
504
|
-
];
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
default:
|
|
508
|
-
lines = [title(dialogText(name)), ...json(args).split("\n")];
|
|
435
|
+
if (
|
|
436
|
+
cached &&
|
|
437
|
+
cached.args === args &&
|
|
438
|
+
cached.result === result &&
|
|
439
|
+
cached.running === running &&
|
|
440
|
+
cached.isError === isError &&
|
|
441
|
+
cached.name === name &&
|
|
442
|
+
cached.width === width &&
|
|
443
|
+
cached.detail === this.detail
|
|
444
|
+
) {
|
|
445
|
+
lines = cached.lines;
|
|
446
|
+
} else {
|
|
447
|
+
lines = renderTranscriptTool(name, id, args, result, isError, running, this.detail, width);
|
|
448
|
+
this.toolCache.set(id, {
|
|
449
|
+
args,
|
|
450
|
+
result,
|
|
451
|
+
running,
|
|
452
|
+
isError,
|
|
453
|
+
name,
|
|
454
|
+
width,
|
|
455
|
+
detail: this.detail,
|
|
456
|
+
lines,
|
|
457
|
+
});
|
|
509
458
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
bounded.push(line);
|
|
520
|
-
chars += line.length;
|
|
459
|
+
const nested: string[] = [];
|
|
460
|
+
for (const child of this.tools.values()) {
|
|
461
|
+
if (child.parentToolCallId !== id || this.renderedTools.has(child.toolCallId)) continue;
|
|
462
|
+
nested.push(
|
|
463
|
+
` ${this.theme.fg("dim", "β³ nested tool")}`,
|
|
464
|
+
...this.tool(child.toolCallId, child.toolName, child.args, Math.max(3, width - 2)).map(
|
|
465
|
+
(line) => ` ${line}`,
|
|
466
|
+
),
|
|
467
|
+
);
|
|
521
468
|
}
|
|
522
|
-
return
|
|
469
|
+
return [...lines, ...nested];
|
|
523
470
|
}
|
|
524
471
|
|
|
525
472
|
render(width: number): string[] {
|
|
@@ -534,6 +481,16 @@ export class LiveAgentView {
|
|
|
534
481
|
`${this.path} Β· ${agentTypeLabel(thread?.type ?? "agent", thread?.icon, this.nerdFontIcons, thread ? agentProgressIcon(thread, this.nerdFontIcons, Date.now(), true, this.loaderStyle) : undefined)} Β· ${thread?.state ?? "attaching"} β Watching β main continues`,
|
|
535
482
|
),
|
|
536
483
|
);
|
|
484
|
+
this.results = new Map(
|
|
485
|
+
(snapshot?.messages ?? [])
|
|
486
|
+
.filter((message) => message.role === "toolResult")
|
|
487
|
+
.map((message) => [
|
|
488
|
+
String((message as unknown as Record<string, unknown>).toolCallId),
|
|
489
|
+
message,
|
|
490
|
+
]),
|
|
491
|
+
);
|
|
492
|
+
this.tools = new Map((snapshot?.tools ?? []).map((tool) => [tool.toolCallId, tool]));
|
|
493
|
+
this.renderedTools.clear();
|
|
537
494
|
const body: string[] = [];
|
|
538
495
|
if (this.error)
|
|
539
496
|
body.push(
|
|
@@ -559,31 +516,16 @@ export class LiveAgentView {
|
|
|
559
516
|
` ${this.theme.fg("warning", "Assistant streamingβ¦")}`,
|
|
560
517
|
...this.message(snapshot.assistant, columns),
|
|
561
518
|
);
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
.
|
|
566
|
-
|
|
567
|
-
for (const tool of snapshot.tools)
|
|
568
|
-
if (
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
dialogText(
|
|
573
|
-
`β ${tool.state}${tool.isError ? " (error)" : ""}${tool.parentToolCallId ? " (nested)" : ""}`,
|
|
574
|
-
),
|
|
575
|
-
)}`;
|
|
576
|
-
body.push(...this.band(call, "toolSuccessBg", columns));
|
|
577
|
-
if (tool.result !== undefined && this.detail !== "compact")
|
|
578
|
-
body.push(
|
|
579
|
-
...this.band(
|
|
580
|
-
this.preview(object(tool.result)?.content ?? tool.result, inner),
|
|
581
|
-
tool.isError ? "toolErrorBg" : "customMessageBg",
|
|
582
|
-
columns,
|
|
583
|
-
),
|
|
584
|
-
);
|
|
585
|
-
body.push("");
|
|
586
|
-
}
|
|
519
|
+
// Parents first even when nested notifications arrive before the outer call.
|
|
520
|
+
for (const tool of snapshot.tools)
|
|
521
|
+
if (!tool.parentToolCallId && !this.results.has(tool.toolCallId))
|
|
522
|
+
body.push(...this.tool(tool.toolCallId, tool.toolName, tool.args, columns));
|
|
523
|
+
// An orphan nested execution still needs to be visible if its parent is unavailable.
|
|
524
|
+
for (const tool of snapshot.tools)
|
|
525
|
+
if (!this.renderedTools.has(tool.toolCallId) && !this.results.has(tool.toolCallId))
|
|
526
|
+
body.push(...this.tool(tool.toolCallId, tool.toolName, tool.args, columns));
|
|
527
|
+
for (const id of this.toolCache.keys())
|
|
528
|
+
if (!this.renderedTools.has(id)) this.toolCache.delete(id);
|
|
587
529
|
if (!body.length)
|
|
588
530
|
body.push(
|
|
589
531
|
thread?.state === "starting"
|
|
@@ -606,7 +548,7 @@ export class LiveAgentView {
|
|
|
606
548
|
this.saveViewport();
|
|
607
549
|
const footer = this.error
|
|
608
550
|
? "Ctrl+R Retry Β· Tab input/transcript Β· Esc tree Β· Ctrl+Q main"
|
|
609
|
-
: `${this.editing ? "Enter steer Β· Tab browse" : `Tab steer Β· Home/End scroll Β· c context Β· t view:${this.detail}`} Β· Esc tree Β· Ctrl+Q main Β· ββ/PgUp/PgDn scroll Β· ${this.viewport.follow ? "following" : "scrolled"}`;
|
|
551
|
+
: `${this.editing ? "Enter steer Β· Tab browse" : `Tab steer Β· Home/End scroll Β· c context Β· t view:${this.detail}`} Β· Ctrl+O expand tools Β· Esc tree Β· Ctrl+Q main Β· ββ/PgUp/PgDn scroll Β· ${this.viewport.follow ? "following" : "scrolled"}`;
|
|
610
552
|
const input = ` ${this.input.render(inner)[0]!}`;
|
|
611
553
|
const status = this.theme.fg(
|
|
612
554
|
this.steerStatus ? (this.steerFailed ? "error" : "muted") : this.error ? "error" : "muted",
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_MANAGER_SETTINGS,
|
|
11
11
|
type CostDisplayMode,
|
|
12
|
+
COST_ICONS,
|
|
13
|
+
type CostIcon,
|
|
14
|
+
type CostValue,
|
|
12
15
|
LOADER_STYLES,
|
|
13
16
|
type LoaderStyle,
|
|
14
17
|
loadManagerSaveScope,
|
|
@@ -23,6 +26,7 @@ import {
|
|
|
23
26
|
import { editAgentTypes } from "./ui.ts";
|
|
24
27
|
import type { ToolEditorOptions } from "./tool-picker.ts";
|
|
25
28
|
import { AGENT_LOADERS } from "./agent-loader.ts";
|
|
29
|
+
import { costIconGlyph } from "./cost-footer.ts";
|
|
26
30
|
|
|
27
31
|
const LOADER_OPTIONS = LOADER_STYLES.map((id) => {
|
|
28
32
|
const loader = AGENT_LOADERS[id];
|
|
@@ -120,22 +124,76 @@ const WIDGET_MODE_HELP =
|
|
|
120
124
|
|
|
121
125
|
const COST_DISPLAY_OPTIONS = [
|
|
122
126
|
{
|
|
123
|
-
id: "pi-
|
|
124
|
-
label: "
|
|
125
|
-
help: "
|
|
127
|
+
id: "pi-status",
|
|
128
|
+
label: "Replace Pi status",
|
|
129
|
+
help: "Show the selected cost in Piβs status area, without replacing the whole footer. Third-party footers may also consume this status.",
|
|
126
130
|
},
|
|
127
131
|
{
|
|
128
132
|
id: "pi-footer-status",
|
|
129
|
-
label: "pi-footer status
|
|
130
|
-
|
|
133
|
+
label: "pi-footer status widget",
|
|
134
|
+
value: "subagent_cost",
|
|
135
|
+
help: "Status key: subagent_cost\nSelect subagent_cost in pi-footerβs Extension Status widget. Does not replace your footer.",
|
|
131
136
|
},
|
|
132
137
|
{
|
|
133
|
-
id: "pi-
|
|
134
|
-
label: "
|
|
135
|
-
|
|
138
|
+
id: "pi-footer-event",
|
|
139
|
+
label: "pi-footer event",
|
|
140
|
+
value: "subagent_cost",
|
|
141
|
+
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.",
|
|
136
142
|
},
|
|
137
143
|
] as const;
|
|
138
144
|
|
|
145
|
+
const COST_VALUE_OPTIONS = [
|
|
146
|
+
{ id: "subagents", label: "Only subagent cost", help: "Settled USD cost of all subagents; excludes the main session." },
|
|
147
|
+
{ id: "total", label: "Total cost", help: "Main session USD cost plus all settled subagent costs." },
|
|
148
|
+
] as const;
|
|
149
|
+
|
|
150
|
+
const COST_ICON_LABELS = { money: "Money", coins: "Coins", wallet: "Wallet" } as const;
|
|
151
|
+
|
|
152
|
+
/** Edits the shared draft; only the outer settings screen saves or applies it. */
|
|
153
|
+
async function configureFooterDisplay(ctx: ExtensionCommandContext, draft: ManagerSettings): Promise<void> {
|
|
154
|
+
let selectedId: string | undefined;
|
|
155
|
+
while (true) {
|
|
156
|
+
const action = await dialogMenu(ctx, "[labs] Footer display", [
|
|
157
|
+
{
|
|
158
|
+
id: "location",
|
|
159
|
+
label: "Location",
|
|
160
|
+
value: COST_DISPLAY_OPTIONS.find((option) => option.id === draft.costDisplay)!.label,
|
|
161
|
+
help: "Choose Pi status, a pi-footer status widget, or a pi-footer event. Integration IDs are shown in the location picker.",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: "value",
|
|
165
|
+
label: "Display value",
|
|
166
|
+
value: COST_VALUE_OPTIONS.find((option) => option.id === draft.costValue)!.label,
|
|
167
|
+
help: "Show only settled subagent cost, or main session plus settled subagents. Applies to every location.",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
id: "icon",
|
|
171
|
+
label: "Icon",
|
|
172
|
+
value: `${costIconGlyph(draft.costIcon, draft.nerdFontIcons)} ${COST_ICON_LABELS[draft.costIcon]}`,
|
|
173
|
+
help: `Choose a money-related ${draft.nerdFontIcons ? "Nerd Font" : "emoji"} icon. The family follows [labs] Nerd Font icons.`,
|
|
174
|
+
},
|
|
175
|
+
{ id: "back", label: "Back", help: "Return to settings. Save and apply there to commit these changes." },
|
|
176
|
+
], { selectedId, footer: "ββ/Tab navigate Β· Enter edit Β· Esc back" });
|
|
177
|
+
if (!action || action === "back") return;
|
|
178
|
+
selectedId = action;
|
|
179
|
+
if (action === "location") {
|
|
180
|
+
const mode = await dialogMenu(ctx, "Footer location", [...COST_DISPLAY_OPTIONS], { selectedId: draft.costDisplay });
|
|
181
|
+
if (COST_DISPLAY_OPTIONS.some((option) => option.id === mode)) draft.costDisplay = mode as CostDisplayMode;
|
|
182
|
+
} else if (action === "value") {
|
|
183
|
+
const value = await dialogMenu(ctx, "Footer display value", [...COST_VALUE_OPTIONS], { selectedId: draft.costValue });
|
|
184
|
+
if (COST_VALUE_OPTIONS.some((option) => option.id === value)) draft.costValue = value as CostValue;
|
|
185
|
+
} else if (action === "icon") {
|
|
186
|
+
const icon = await dialogMenu(ctx, `Footer icon Β· ${draft.nerdFontIcons ? "Nerd Font" : "Emoji"}`, COST_ICONS.map((id) => ({
|
|
187
|
+
id,
|
|
188
|
+
label: COST_ICON_LABELS[id],
|
|
189
|
+
value: costIconGlyph(id, draft.nerdFontIcons),
|
|
190
|
+
help: `${costIconGlyph(id, draft.nerdFontIcons)} ${COST_ICON_LABELS[id]} Β· ${draft.nerdFontIcons ? "Requires a Nerd Font in your terminal." : "Emoji icon."}`,
|
|
191
|
+
})), { selectedId: draft.costIcon });
|
|
192
|
+
if (COST_ICONS.includes(icon as CostIcon)) draft.costIcon = icon as CostIcon;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
139
197
|
const MODEL_SELECTION_OPTIONS = [
|
|
140
198
|
{
|
|
141
199
|
id: "pick-first-available",
|
|
@@ -228,9 +286,9 @@ async function configureAgentsDialog(
|
|
|
228
286
|
},
|
|
229
287
|
{
|
|
230
288
|
id: "costDisplay",
|
|
231
|
-
label: "[labs]
|
|
289
|
+
label: "[labs] Footer display",
|
|
232
290
|
value: COST_DISPLAY_OPTIONS.find((mode) => mode.id === draft.costDisplay)!.label,
|
|
233
|
-
help: "
|
|
291
|
+
help: "Configure footer location, displayed cost, and money icon in a submenu. Save and apply to update immediately.",
|
|
234
292
|
},
|
|
235
293
|
{
|
|
236
294
|
id: "nerdFontIcons",
|
|
@@ -332,11 +390,7 @@ async function configureAgentsDialog(
|
|
|
332
390
|
if (WIDGET_MODE_OPTIONS.some((option) => option.id === mode))
|
|
333
391
|
draft.widgetMode = mode as WidgetMode;
|
|
334
392
|
} else if (action === "costDisplay") {
|
|
335
|
-
|
|
336
|
-
selectedId: draft.costDisplay,
|
|
337
|
-
});
|
|
338
|
-
if (COST_DISPLAY_OPTIONS.some((option) => option.id === mode))
|
|
339
|
-
draft.costDisplay = mode as CostDisplayMode;
|
|
393
|
+
await configureFooterDisplay(ctx, draft);
|
|
340
394
|
} else if (action === "nerdFontIcons") {
|
|
341
395
|
draft.nerdFontIcons = !draft.nerdFontIcons;
|
|
342
396
|
} else if (action === "loaderStyle") {
|
package/src/ui/status-ui.ts
CHANGED
|
@@ -294,29 +294,28 @@ export class StatusDialog {
|
|
|
294
294
|
]
|
|
295
295
|
.map((part) => dialogText(part))
|
|
296
296
|
.join(" ");
|
|
297
|
-
const
|
|
297
|
+
const identityLine = [
|
|
298
298
|
selected ? this.theme.fg("accent", head) : head,
|
|
299
299
|
badge,
|
|
300
300
|
this.theme.fg(inactive ? base : selected ? "accent" : "text", ` ${identity} `),
|
|
301
301
|
this.theme.fg(inactive ? hint : "muted", dialogText(thread.state)),
|
|
302
302
|
].join("");
|
|
303
303
|
// Continue the tree's vertical guides without repeating the branch or selection marker.
|
|
304
|
-
const stem = row.prefix.replace("
|
|
304
|
+
const stem = row.prefix.replace("β ", "β ").replace("β ", " ");
|
|
305
305
|
const activity = ` ${stem} ${dialogText(thread.status || thread.task)}`;
|
|
306
306
|
const metrics = this.theme.fg(base, threadMetrics(thread));
|
|
307
307
|
const metricWidth = visibleWidth(metrics);
|
|
308
|
-
const
|
|
308
|
+
const first =
|
|
309
309
|
metricWidth >= width
|
|
310
310
|
? truncateToWidth(metrics, width, "")
|
|
311
311
|
: (() => {
|
|
312
|
-
const left = truncateToWidth(
|
|
313
|
-
|
|
314
|
-
width - metricWidth - 1,
|
|
315
|
-
);
|
|
316
|
-
return (
|
|
317
|
-
left + " ".repeat(Math.max(1, width - visibleWidth(left) - metricWidth)) + metrics
|
|
318
|
-
);
|
|
312
|
+
const left = truncateToWidth(identityLine, width - metricWidth - 1);
|
|
313
|
+
return left + " ".repeat(Math.max(1, width - visibleWidth(left) - metricWidth)) + metrics;
|
|
319
314
|
})();
|
|
315
|
+
const second = truncateToWidth(
|
|
316
|
+
this.theme.fg(inactive ? base : selected ? "accent" : "muted", activity),
|
|
317
|
+
width,
|
|
318
|
+
);
|
|
320
319
|
return [first, second];
|
|
321
320
|
}
|
|
322
321
|
|
package/src/ui/thread-tree.ts
CHANGED
|
@@ -137,10 +137,10 @@ export function buildStatusTree(
|
|
|
137
137
|
for (const [index, node] of ordered.entries()) {
|
|
138
138
|
visited.add(node.path);
|
|
139
139
|
const last = index === ordered.length - 1;
|
|
140
|
-
const stem = ancestors.map((isLast) => (isLast ? "
|
|
140
|
+
const stem = ancestors.map((isLast) => (isLast ? " " : "β ")).join("");
|
|
141
141
|
rows.push({
|
|
142
142
|
path: node.path,
|
|
143
|
-
prefix: stem + (top ? "" : last ? "
|
|
143
|
+
prefix: stem + (top ? "" : last ? "β " : "β "),
|
|
144
144
|
hasChildren: node.children.length > 0,
|
|
145
145
|
...(node.thread ? { thread: node.thread } : {}),
|
|
146
146
|
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ToolExecutionComponent,
|
|
3
|
+
type ToolDefinition,
|
|
4
|
+
createBashToolDefinition,
|
|
5
|
+
createPowerShellToolDefinition,
|
|
6
|
+
createReadToolDefinition,
|
|
7
|
+
createEditToolDefinition,
|
|
8
|
+
createWriteToolDefinition,
|
|
9
|
+
createGrepToolDefinition,
|
|
10
|
+
createFindToolDefinition,
|
|
11
|
+
createLsToolDefinition,
|
|
12
|
+
} from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import { Text, stripTerminalSequences, type TUI } from "@earendil-works/pi-tui";
|
|
14
|
+
|
|
15
|
+
/** Only trusted pi built-ins: observing a transcript must never execute extension renderers. */
|
|
16
|
+
type Renderers = Pick<ToolDefinition<any, any>, "renderCall" | "renderResult">;
|
|
17
|
+
const renderers = new Map<string, Renderers>(
|
|
18
|
+
[
|
|
19
|
+
createBashToolDefinition(process.cwd()),
|
|
20
|
+
createPowerShellToolDefinition(process.cwd()),
|
|
21
|
+
createReadToolDefinition(process.cwd()),
|
|
22
|
+
createEditToolDefinition(process.cwd()),
|
|
23
|
+
createWriteToolDefinition(process.cwd()),
|
|
24
|
+
createGrepToolDefinition(process.cwd()),
|
|
25
|
+
createFindToolDefinition(process.cwd()),
|
|
26
|
+
createLsToolDefinition(process.cwd()),
|
|
27
|
+
].map((tool) => [
|
|
28
|
+
tool.name,
|
|
29
|
+
{ renderCall: tool.renderCall, renderResult: tool.renderResult } as Renderers,
|
|
30
|
+
]),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// Native edit call previews otherwise read today's file asynchronously. An observer must
|
|
34
|
+
// use the recorded result.diff, not inspect a possibly different worktree on every paint.
|
|
35
|
+
const edit = renderers.get("edit")!;
|
|
36
|
+
const editCall = edit.renderCall!;
|
|
37
|
+
edit.renderCall = (args, theme, context) =>
|
|
38
|
+
editCall(args, theme, { ...context, argsComplete: false });
|
|
39
|
+
|
|
40
|
+
// Pi's generic fallback is unbounded. Retain the native tool box/title, but bound
|
|
41
|
+
// unknown-tool previews by visual rows (extension tools can return enormous single lines).
|
|
42
|
+
const generic: Renderers = {
|
|
43
|
+
renderResult(result, options, theme) {
|
|
44
|
+
const output = result.content
|
|
45
|
+
.filter((block) => block.type === "text")
|
|
46
|
+
.map((block) => block.text)
|
|
47
|
+
.join("\n");
|
|
48
|
+
const bounded = options.expanded ? output : output.slice(0, 32768);
|
|
49
|
+
const component = new Text(theme.fg("toolOutput", bounded), 0, 0);
|
|
50
|
+
return {
|
|
51
|
+
invalidate() {
|
|
52
|
+
component.invalidate();
|
|
53
|
+
},
|
|
54
|
+
render(width) {
|
|
55
|
+
const rows = component.render(width);
|
|
56
|
+
if (options.expanded || (rows.length <= 5 && bounded.length === output.length)) return rows;
|
|
57
|
+
return [...rows.slice(0, 5), theme.fg("muted", "β¦ more lines (Ctrl+O to expand)")];
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
function safeText(value: string): string {
|
|
63
|
+
return stripTerminalSequences(value)
|
|
64
|
+
.replace(/\r\n?/g, "\n")
|
|
65
|
+
.replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Sanitize args, content AND details before trusted renderers interpolate them. */
|
|
69
|
+
function sanitize(value: unknown, seen = new WeakSet<object>(), depth = 0): any {
|
|
70
|
+
if (typeof value === "string") return safeText(value);
|
|
71
|
+
if (!value || typeof value !== "object") return typeof value === "bigint" ? String(value) : value;
|
|
72
|
+
if (seen.has(value)) return "[Circular]";
|
|
73
|
+
if (depth > 64) return "[Nested data omitted]";
|
|
74
|
+
seen.add(value);
|
|
75
|
+
const safe = Array.isArray(value)
|
|
76
|
+
? value.map((item) => sanitize(item, seen, depth + 1))
|
|
77
|
+
: Object.fromEntries(
|
|
78
|
+
Object.entries(value).map(([key, item]) => [
|
|
79
|
+
safeText(key),
|
|
80
|
+
sanitize(item, seen, depth + 1),
|
|
81
|
+
]),
|
|
82
|
+
);
|
|
83
|
+
seen.delete(value);
|
|
84
|
+
return safe;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function renderTranscriptTool(
|
|
88
|
+
name: string,
|
|
89
|
+
id: string,
|
|
90
|
+
args: unknown,
|
|
91
|
+
result: unknown,
|
|
92
|
+
isError: boolean,
|
|
93
|
+
running: boolean,
|
|
94
|
+
detail: "full" | "preview" | "compact",
|
|
95
|
+
width: number,
|
|
96
|
+
): string[] {
|
|
97
|
+
// The native shell renderer owns elapsed-time intervals after markExecutionStarted().
|
|
98
|
+
// An observer has no execution lifecycle to dispose, so intentionally don't start that clock.
|
|
99
|
+
const ui = { requestRender() {} } as TUI;
|
|
100
|
+
const component = new ToolExecutionComponent(
|
|
101
|
+
safeText(name),
|
|
102
|
+
safeText(id),
|
|
103
|
+
sanitize(args),
|
|
104
|
+
{ showImages: false },
|
|
105
|
+
renderers.get(name) ?? generic,
|
|
106
|
+
ui,
|
|
107
|
+
process.cwd(),
|
|
108
|
+
);
|
|
109
|
+
const data =
|
|
110
|
+
result && typeof result === "object" ? (result as Record<string, unknown>) : undefined;
|
|
111
|
+
const content = data?.content ?? result;
|
|
112
|
+
component.updateResult(
|
|
113
|
+
{
|
|
114
|
+
content: (Array.isArray(content) ? content : content === undefined ? [] : [content]).map(
|
|
115
|
+
(block) => {
|
|
116
|
+
// Never hand image payloads to pi (even showImages:false can trigger Kitty conversion).
|
|
117
|
+
if (block && typeof block === "object" && (block as { type?: string }).type === "image")
|
|
118
|
+
return { type: "text", text: "[Image β text-only observer]" };
|
|
119
|
+
if (block && typeof block === "object" && (block as { type?: string }).type === "text")
|
|
120
|
+
return {
|
|
121
|
+
type: "text",
|
|
122
|
+
text: safeText(String((block as { text?: unknown }).text ?? "")),
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
type: "text",
|
|
126
|
+
text: safeText(
|
|
127
|
+
typeof block === "string" ? block : (JSON.stringify(sanitize(block)) ?? ""),
|
|
128
|
+
),
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
),
|
|
132
|
+
details: sanitize(data?.details),
|
|
133
|
+
isError: isError || data?.isError === true,
|
|
134
|
+
},
|
|
135
|
+
running,
|
|
136
|
+
);
|
|
137
|
+
component.setExpanded(detail === "full");
|
|
138
|
+
const lines = component.render(Math.max(3, width));
|
|
139
|
+
if (detail === "compact")
|
|
140
|
+
return lines.filter((line) => stripTerminalSequences(line).trim()).slice(0, 1);
|
|
141
|
+
return lines;
|
|
142
|
+
}
|