pi-subagent-manager 0.9.0 → 0.10.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 +1 -1
- package/docs/settings.md +12 -0
- package/docs/tools-and-ui.md +12 -7
- package/package.json +1 -1
- package/src/index.ts +3 -4
- package/src/prefs/settings.ts +12 -1
- package/src/ui/agent-navigation-editor.ts +12 -15
- package/src/ui/live-agent-view.ts +20 -8
- package/src/ui/settings-ui.ts +31 -0
- package/src/ui/status-ui.ts +1 -7
- package/src/ui/ui.ts +86 -24
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ They inherit your current model until you set preferences. Details: [docs/defaul
|
|
|
72
72
|
| `/agents import` | Import agents from other subagent extensions |
|
|
73
73
|
| `/agents reload` | Reload definitions and settings |
|
|
74
74
|
|
|
75
|
-
A
|
|
75
|
+
A live **Agents** widget sits above the input box. Choose **Full** (the existing tree) or **Minimal** (colored status counts and running-agent token totals, plus the browser hint) under **Status Widget** in `/agents` settings. In the fullscreen tree, **Enter** watches an agent, **Escape** returns, and **i** opens existing thread actions. A status strip below the previews shows how many agents are running and **Press ← to open subagent browser**. Press **Left** at the start of the main draft to open it; normal cursor movement is unchanged. See [live navigation](docs/tools-and-ui.md#live-agent-navigation-read-only) for controls and compatibility.
|
|
76
76
|
|
|
77
77
|
## Docs
|
|
78
78
|
|
package/docs/settings.md
CHANGED
|
@@ -14,6 +14,7 @@ All keys are optional. Defaults:
|
|
|
14
14
|
```json
|
|
15
15
|
{
|
|
16
16
|
"subagentMode": "opportunistic",
|
|
17
|
+
"widgetMode": "full",
|
|
17
18
|
"modelSelection": "pick-first-scoped",
|
|
18
19
|
"toolFiltering": "allowed",
|
|
19
20
|
"maxLevels": 3,
|
|
@@ -41,6 +42,17 @@ How much the main model is encouraged to delegate.
|
|
|
41
42
|
- Orchestration is a prompt policy, not a tool restriction. Workers don't inherit the root-only rule.
|
|
42
43
|
- Agent import needs `opportunistic` (it uses the main thread's file tools).
|
|
43
44
|
|
|
45
|
+
## Status Widget (`widgetMode`)
|
|
46
|
+
|
|
47
|
+
Controls the subagent status display above the input box. Choose **Status Widget** in `/agents` settings and save with **Ctrl+S**.
|
|
48
|
+
|
|
49
|
+
| Option | Display |
|
|
50
|
+
| ------------------ | ------- |
|
|
51
|
+
| `full` (default) | The existing multi-line tree with agent details, activity and navigation hints. |
|
|
52
|
+
| `minimal` | One line of theme-colored status counts plus cumulative input `↑` / output `↓` tokens for agents currently starting or running. |
|
|
53
|
+
|
|
54
|
+
Minimal mode groups starting agents with running agents and excludes the main conversation. Token totals exclude completed, stopped, failed and paused agents. The fullscreen tree remains available via `/agents tree` in either mode.
|
|
55
|
+
|
|
44
56
|
## Model Picking (`modelSelection`)
|
|
45
57
|
|
|
46
58
|
Which model an agent gets when its session starts.
|
package/docs/tools-and-ui.md
CHANGED
|
@@ -65,25 +65,30 @@ The fullscreen watcher shows steer and agent messages in full, including the in-
|
|
|
65
65
|
- **r** retries an unavailable observation without starting a turn. Starting threads are watchable; stopped/completed threads remain readable.
|
|
66
66
|
- Frames are sanitized, viewport-bounded and coalesced during bursts. Exit, root replacement and shutdown release observers/timers. Streaming deltas never enter persisted thread events.
|
|
67
67
|
|
|
68
|
-
####
|
|
68
|
+
#### Left-arrow entry
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
Press physical **Left (←)** at the beginning of the main draft (or in an empty input) to open the subagent browser. Elsewhere, Left retains normal cursor movement. Down is always native editing/history navigation. Autocomplete, jumps, paste and configured shortcuts take precedence. Navigating preserves the main draft/cursor and does not require the root to be idle.
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
Left-arrow entry is enabled by default in the TUI; `/agents tree` remains available everywhere. Pi has one custom-editor slot: installation is skipped if another factory owns it or an existing draft is nonempty, since the host cannot transfer cursor/undo/expanded-paste state. Load order can still let a later editor replace ours. Initial startup uses Pi's history hydration; replacement installations seed history once. Session-tree rebuilds keep the existing editor instance.
|
|
73
73
|
|
|
74
74
|
While navigation is open, the host fullscreen search shortcut is temporarily disabled through public keybindings to avoid stacking a second host overlay. The prior binding owner is restored only if no other extension replaced it. **Known host limitation:** if an unrelated extension stacks another overlay above navigation, Pi's custom-UI completion can close the newer overlay instead. Avoid concurrent extension-owned overlays; a host identity-targeted completion API is needed to remove this limitation. No private host access or unsupported overlay-lifecycle workaround is used.
|
|
75
75
|
|
|
76
|
-
Run `python3 scripts/live-agent-navigation-smoke.py` after `npm install` for credential-free, offline POSIX PTY checks in regular/fullscreen mode (entry, root return, draft restoration, resize and host-search suppression). No model prompts are submitted. Broader manual acceptance
|
|
76
|
+
Run `python3 scripts/live-agent-navigation-smoke.py` after `npm install` for credential-free, offline POSIX PTY checks in regular/fullscreen mode (entry, root return, draft restoration, resize and host-search suppression). No model prompts are submitted. Broader manual acceptance covers concurrent live turns, autocomplete/paste/undo interactions, remapped shortcuts and rich custom content.
|
|
77
77
|
|
|
78
78
|
## Agents widget
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
The widget above the input editor has two display modes, selected with **Status Widget** in `/agents` settings:
|
|
81
|
+
|
|
82
|
+
- **Full** (default): the existing compact tree, at most twelve lines.
|
|
83
|
+
- **Minimal**: a summary line such as `3 running, 2 stopped, 1 failed, 1 paused ↑12k ↓3k`, with semantic theme colors. Starting agents count as running; completed agents are counted when present. Token totals include only currently starting/running agents, not the main conversation or settled threads. Use `/agents tree` for details.
|
|
84
|
+
|
|
85
|
+
In full mode:
|
|
81
86
|
|
|
82
87
|
- Each row: colored type pill, path, state, task, active time, input `↑` / output `↓` tokens.
|
|
83
88
|
- A second, indented line shows latest activity.
|
|
84
|
-
- Active branches are shown first; overflow is counted, not listed.
|
|
89
|
+
- Active branches are shown first; the most recent agents within each state are preferred when previews overflow. Overflow is counted, not listed.
|
|
85
90
|
- Time freezes while paused and resumes on continue.
|
|
86
|
-
-
|
|
91
|
+
- A small status strip below the previews shows the running count (including starting agents) and **Press ← to open subagent browser**, including when agents overflow. Minimal mode also shows the hint. RPC output omits the keyboard hint.
|
|
87
92
|
|
|
88
93
|
### Interrupts and stopping agents
|
|
89
94
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -61,9 +61,8 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
const installNavigationEditor = (ctx: ExtensionContext, seedHistory: boolean) => {
|
|
64
|
-
// Pi has one custom-editor slot:
|
|
65
|
-
if (!ctx.hasUI || ctx.mode !== "tui" || !ctx.ui.setEditorComponent
|
|
66
|
-
process.env.PI_SUBAGENT_NAVIGATION_EDITOR !== "1") return;
|
|
64
|
+
// Pi has one custom-editor slot: do not replace another integration.
|
|
65
|
+
if (!ctx.hasUI || ctx.mode !== "tui" || !ctx.ui.setEditorComponent) return;
|
|
67
66
|
const existingFactory = ctx.ui.getEditorComponent?.();
|
|
68
67
|
if (existingFactory && existingFactory !== navigationEditorFactory) return;
|
|
69
68
|
// The host only transfers raw text, not cursor/undo/expanded-paste state.
|
|
@@ -239,7 +238,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
239
238
|
const refreshWidget = (ctx: ExtensionContext) => {
|
|
240
239
|
if (limits.subagentMode === "off") {
|
|
241
240
|
if (ctx.hasUI) ctx.ui.setWidget("pi-subagent", undefined);
|
|
242
|
-
} else updateWidget(ctx, requireManager().list());
|
|
241
|
+
} else updateWidget(ctx, requireManager().list(), limits.widgetMode);
|
|
243
242
|
};
|
|
244
243
|
syncTools();
|
|
245
244
|
pi.on("before_agent_start", async (event, ctx) => {
|
package/src/prefs/settings.ts
CHANGED
|
@@ -16,6 +16,9 @@ import { dirname, join, resolve } from "node:path";
|
|
|
16
16
|
export const SUBAGENT_MODES = ["off", "opportunistic", "orchestration"] as const;
|
|
17
17
|
export type SubagentMode = (typeof SUBAGENT_MODES)[number];
|
|
18
18
|
|
|
19
|
+
export const WIDGET_MODES = ["full", "minimal"] as const;
|
|
20
|
+
export type WidgetMode = (typeof WIDGET_MODES)[number];
|
|
21
|
+
|
|
19
22
|
export const TOOL_FILTERING_MODES = ["allowed", "all-except-blocked", "all"] as const;
|
|
20
23
|
export type ToolFilteringMode = (typeof TOOL_FILTERING_MODES)[number];
|
|
21
24
|
|
|
@@ -29,6 +32,7 @@ export type ModelSelectionMode = (typeof MODEL_SELECTION_MODES)[number];
|
|
|
29
32
|
export interface ManagerSettings {
|
|
30
33
|
subagentMode: SubagentMode;
|
|
31
34
|
toolFiltering: ToolFilteringMode;
|
|
35
|
+
widgetMode: WidgetMode;
|
|
32
36
|
maxLevels: number;
|
|
33
37
|
maxConcurrent: number;
|
|
34
38
|
maxThreads: number;
|
|
@@ -42,10 +46,11 @@ export const DEFAULT_MANAGER_SETTINGS: ManagerSettings = {
|
|
|
42
46
|
modelSelection: "pick-first-scoped",
|
|
43
47
|
subagentMode: "opportunistic",
|
|
44
48
|
toolFiltering: "allowed",
|
|
49
|
+
widgetMode: "full",
|
|
45
50
|
};
|
|
46
51
|
|
|
47
52
|
const KEYS = [
|
|
48
|
-
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering",
|
|
53
|
+
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode",
|
|
49
54
|
] as const;
|
|
50
55
|
const MAX_LEVELS = 32;
|
|
51
56
|
|
|
@@ -84,6 +89,7 @@ function positiveSafeInteger(value: unknown): value is number {
|
|
|
84
89
|
|
|
85
90
|
function requirement(key: (typeof KEYS)[number]): string {
|
|
86
91
|
if (key === "subagentMode") return "subagentMode must be off, opportunistic or orchestration";
|
|
92
|
+
if (key === "widgetMode") return "widgetMode must be full or minimal";
|
|
87
93
|
if (key === "toolFiltering") return "toolFiltering must be allowed, all-except-blocked or all";
|
|
88
94
|
if (key === "modelSelection")
|
|
89
95
|
return "modelSelection must be pick-first-available, pick-first-scoped or use-current";
|
|
@@ -127,6 +133,11 @@ function parseSettings(content: string): Partial<ManagerSettings> {
|
|
|
127
133
|
layer.toolFiltering = value as ToolFilteringMode;
|
|
128
134
|
continue;
|
|
129
135
|
}
|
|
136
|
+
if (key === "widgetMode") {
|
|
137
|
+
if (!WIDGET_MODES.includes(value as WidgetMode)) throw new Error(requirement(key));
|
|
138
|
+
layer.widgetMode = value as WidgetMode;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
130
141
|
if (key === "modelSelection") {
|
|
131
142
|
if (!MODEL_SELECTION_MODES.includes(value as ModelSelectionMode))
|
|
132
143
|
throw new Error(requirement(key));
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "@earendil-works/pi-tui";
|
|
14
14
|
|
|
15
15
|
export interface AgentNavigationEditorOptions {
|
|
16
|
-
/** Must return the whole navigation interaction, so repeated
|
|
16
|
+
/** Must return the whole navigation interaction, so repeated Left cannot reopen it. */
|
|
17
17
|
openTree(): void | Promise<void>;
|
|
18
18
|
canOpen(): boolean;
|
|
19
19
|
/** Root ownership token; changing it invalidates queued transitions. */
|
|
@@ -27,9 +27,9 @@ export interface AgentNavigationEditorOptions {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Physical
|
|
30
|
+
* Physical Left boundary adapter. It owns no session/history internals and never
|
|
31
31
|
* changes the draft. Install once per root UI lifecycle, not for tree navigation.
|
|
32
|
-
* Another custom editor occupies the same host slot;
|
|
32
|
+
* Another custom editor occupies the same host slot; skip installation rather than stack.
|
|
33
33
|
*/
|
|
34
34
|
export class AgentNavigationEditor extends CustomEditor {
|
|
35
35
|
private pending = false;
|
|
@@ -59,15 +59,15 @@ export class AgentNavigationEditor extends CustomEditor {
|
|
|
59
59
|
this.inputEpoch++;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
private
|
|
63
|
-
if (!matchesKey(data, Key.
|
|
62
|
+
private ordinaryLeft(data: string): boolean {
|
|
63
|
+
if (!matchesKey(data, Key.left)) return false;
|
|
64
64
|
// Editor uses the global TUI bindings; CustomEditor uses the injected app
|
|
65
65
|
// manager. Both must agree, and a conflicting remap wins conservatively.
|
|
66
66
|
for (const keys of [this.navigationKeys, getKeybindings()]) {
|
|
67
|
-
if (!keys.matches(data, "tui.editor.
|
|
67
|
+
if (!keys.matches(data, "tui.editor.cursorLeft")) return false;
|
|
68
68
|
for (const action of Object.keys(keys.getResolvedBindings())) {
|
|
69
69
|
if (
|
|
70
|
-
action !== "tui.editor.
|
|
70
|
+
action !== "tui.editor.cursorLeft" &&
|
|
71
71
|
(action.startsWith("tui.editor.") ||
|
|
72
72
|
action.startsWith("tui.input.") ||
|
|
73
73
|
action.startsWith("tui.altScreen.") ||
|
|
@@ -82,8 +82,8 @@ export class AgentNavigationEditor extends CustomEditor {
|
|
|
82
82
|
|
|
83
83
|
override handleInput(data: string): void {
|
|
84
84
|
const outer = this.dispatchDepth === 0;
|
|
85
|
-
const
|
|
86
|
-
if (outer && !
|
|
85
|
+
const left = this.ordinaryLeft(data);
|
|
86
|
+
if (outer && !left) this.inputEpoch++;
|
|
87
87
|
const previousPaste = this.pastePending;
|
|
88
88
|
const wasPaste = previousPaste || data.includes("\x1b[200~");
|
|
89
89
|
// Update before dispatch: Pi recursively sends a suffix after the end
|
|
@@ -92,18 +92,17 @@ export class AgentNavigationEditor extends CustomEditor {
|
|
|
92
92
|
if (wasPaste && data.includes("\x1b[201~")) this.pastePending = false;
|
|
93
93
|
const wasJump = this.jumpPending;
|
|
94
94
|
const cursor = this.getCursor();
|
|
95
|
-
const lines = this.getLines();
|
|
96
95
|
const text = this.getText();
|
|
97
96
|
const eligible =
|
|
98
97
|
outer &&
|
|
99
|
-
|
|
98
|
+
left &&
|
|
100
99
|
this.focused &&
|
|
101
100
|
!this.disposed &&
|
|
102
101
|
!wasPaste &&
|
|
103
102
|
!wasJump &&
|
|
104
103
|
!this.isShowingAutocomplete() &&
|
|
105
|
-
cursor.line ===
|
|
106
|
-
cursor.col ===
|
|
104
|
+
cursor.line === 0 &&
|
|
105
|
+
cursor.col === 0;
|
|
107
106
|
const generation = eligible ? this.navigation.generation() : undefined;
|
|
108
107
|
let changed = false;
|
|
109
108
|
let consumed = false;
|
|
@@ -179,8 +178,6 @@ export class AgentNavigationEditor extends CustomEditor {
|
|
|
179
178
|
this.pending = false;
|
|
180
179
|
return;
|
|
181
180
|
}
|
|
182
|
-
// The host must guard tree input handoff; legacy terminals have no
|
|
183
|
-
// reliable key-release signal for a held Down.
|
|
184
181
|
try {
|
|
185
182
|
// Call within the checked microtask: an extra Promise.then would leave
|
|
186
183
|
// a gap in which root ownership could change after validation.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import type
|
|
2
|
+
import { getMarkdownTheme, type Theme } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import {
|
|
4
4
|
Key,
|
|
5
|
+
Markdown,
|
|
5
6
|
matchesKey,
|
|
6
7
|
ScrollView,
|
|
7
8
|
stripTerminalSequences,
|
|
@@ -19,7 +20,7 @@ export interface AgentViewportState {
|
|
|
19
20
|
showThinking?: boolean;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
/** Fully cover main, including at very small sizes;
|
|
23
|
+
/** Fully cover main, including at very small sizes; only trusted renderers emit terminal sequences. */
|
|
23
24
|
export function fillViewport(lines: string[], width: number, height: number): string[] {
|
|
24
25
|
width = Math.max(0, Math.floor(width));
|
|
25
26
|
height = Math.max(1, Math.floor(height));
|
|
@@ -49,7 +50,7 @@ function json(value: unknown): string {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
/**
|
|
53
|
+
/** Read-only observer. Never invoke watched tools' custom renderers or pass through raw controls. */
|
|
53
54
|
export class LiveAgentView {
|
|
54
55
|
private snapshot: TranscriptSnapshot | undefined;
|
|
55
56
|
private error: string | undefined;
|
|
@@ -180,6 +181,19 @@ export class LiveAgentView {
|
|
|
180
181
|
.flatMap((line) => wrapTextWithAnsi(line, Math.max(1, width)));
|
|
181
182
|
}
|
|
182
183
|
|
|
184
|
+
/** Use the same themed Markdown (including code highlighting) as pi's main transcript. */
|
|
185
|
+
private markdown(value: string, width: number, thinking = false): string[] {
|
|
186
|
+
return new Markdown(
|
|
187
|
+
text(value),
|
|
188
|
+
0,
|
|
189
|
+
0,
|
|
190
|
+
getMarkdownTheme(),
|
|
191
|
+
thinking
|
|
192
|
+
? { color: (value) => this.theme.fg("thinkingText", value), italic: true }
|
|
193
|
+
: undefined,
|
|
194
|
+
).render(Math.max(1, width));
|
|
195
|
+
}
|
|
196
|
+
|
|
183
197
|
/** Tool/metadata previews are bounded by rendered rows, not just source newlines. */
|
|
184
198
|
private preview(content: unknown, width: number): string[] {
|
|
185
199
|
const values = Array.isArray(content) ? content : [content];
|
|
@@ -207,18 +221,16 @@ export class LiveAgentView {
|
|
|
207
221
|
}
|
|
208
222
|
|
|
209
223
|
private blocks(content: unknown, width: number): string[] {
|
|
210
|
-
if (typeof content === "string") return this.
|
|
224
|
+
if (typeof content === "string") return this.markdown(content, width);
|
|
211
225
|
if (!Array.isArray(content)) return this.wrap(json(content), width);
|
|
212
226
|
return content.flatMap((value) => {
|
|
213
227
|
const block = object(value);
|
|
214
228
|
if (!block) return this.wrap(json(value), width);
|
|
215
|
-
if (block.type === "text") return this.
|
|
229
|
+
if (block.type === "text") return this.markdown(String(block.text ?? ""), width);
|
|
216
230
|
if (block.type === "image") return ["[Image — text-only observer]"];
|
|
217
231
|
if (block.type === "thinking")
|
|
218
232
|
return this.viewport.showThinking
|
|
219
|
-
? this.
|
|
220
|
-
this.theme.fg("muted", line),
|
|
221
|
-
)
|
|
233
|
+
? this.markdown(String(block.thinking ?? "[redacted thinking]"), width, true)
|
|
222
234
|
: [this.theme.fg("dim", "[Thinking hidden · t show]")];
|
|
223
235
|
if (block.type === "toolCall")
|
|
224
236
|
return [
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type ModelSelectionMode,
|
|
14
14
|
type SubagentMode,
|
|
15
15
|
type ToolFilteringMode,
|
|
16
|
+
type WidgetMode,
|
|
16
17
|
} from "../prefs/settings.ts";
|
|
17
18
|
import { editAgentTypes } from "./ui.ts";
|
|
18
19
|
|
|
@@ -82,6 +83,24 @@ const TOOL_FILTERING_OPTIONS = [
|
|
|
82
83
|
const TOOL_FILTERING_HELP =
|
|
83
84
|
"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.";
|
|
84
85
|
|
|
86
|
+
const WIDGET_MODE_OPTIONS = [
|
|
87
|
+
{
|
|
88
|
+
id: "full",
|
|
89
|
+
label: "Full",
|
|
90
|
+
value: "Detailed agent status rows",
|
|
91
|
+
help: "Full: show the existing agent status widget above the input box, with per-agent details.",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "minimal",
|
|
95
|
+
label: "Minimal",
|
|
96
|
+
value: "One-line counts and running-agent tokens",
|
|
97
|
+
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.",
|
|
98
|
+
},
|
|
99
|
+
] as const;
|
|
100
|
+
|
|
101
|
+
const WIDGET_MODE_HELP =
|
|
102
|
+
"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.";
|
|
103
|
+
|
|
85
104
|
const MODEL_SELECTION_OPTIONS = [
|
|
86
105
|
{
|
|
87
106
|
id: "pick-first-available",
|
|
@@ -161,6 +180,12 @@ async function configureAgentsDialog(
|
|
|
161
180
|
value: MODEL_SELECTION_OPTIONS.find((mode) => mode.id === draft.modelSelection)!.label,
|
|
162
181
|
help: MODEL_SELECTION_HELP,
|
|
163
182
|
},
|
|
183
|
+
{
|
|
184
|
+
id: "widgetMode",
|
|
185
|
+
label: "Status Widget",
|
|
186
|
+
value: WIDGET_MODE_OPTIONS.find((mode) => mode.id === draft.widgetMode)!.label,
|
|
187
|
+
help: WIDGET_MODE_HELP,
|
|
188
|
+
},
|
|
164
189
|
{
|
|
165
190
|
id: "scope",
|
|
166
191
|
label: "Save scope",
|
|
@@ -236,6 +261,12 @@ async function configureAgentsDialog(
|
|
|
236
261
|
});
|
|
237
262
|
if (MODEL_SELECTION_OPTIONS.some((option) => option.id === mode))
|
|
238
263
|
draft.modelSelection = mode as ModelSelectionMode;
|
|
264
|
+
} else if (action === "widgetMode") {
|
|
265
|
+
const mode = await dialogMenu(ctx, "Status Widget", [...WIDGET_MODE_OPTIONS], {
|
|
266
|
+
selectedId: draft.widgetMode,
|
|
267
|
+
});
|
|
268
|
+
if (WIDGET_MODE_OPTIONS.some((option) => option.id === mode))
|
|
269
|
+
draft.widgetMode = mode as WidgetMode;
|
|
239
270
|
} else if (action === "scope") {
|
|
240
271
|
if (!ctx.isProjectTrusted())
|
|
241
272
|
ctx.ui.notify(
|
package/src/ui/status-ui.ts
CHANGED
|
@@ -423,13 +423,7 @@ export class AgentNavigationController {
|
|
|
423
423
|
{ selectedId: "No" },
|
|
424
424
|
)) === "Yes";
|
|
425
425
|
ui.editor = (title, prefill) => dialogEditor(scoped, title, prefill ?? "");
|
|
426
|
-
// Defer until Pi has installed/focused the overlay
|
|
427
|
-
const handoffUntil = Date.now() + 100;
|
|
428
|
-
const handle = session.handleInput.bind(session);
|
|
429
|
-
session.handleInput = (data) => {
|
|
430
|
-
if (Date.now() < handoffUntil && matchesKey(data, Key.down)) return;
|
|
431
|
-
handle(data);
|
|
432
|
-
};
|
|
426
|
+
// Defer until Pi has installed/focused the overlay.
|
|
433
427
|
void Promise.resolve()
|
|
434
428
|
.then(async () => {
|
|
435
429
|
while (generation === this.generation) {
|
package/src/ui/ui.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
withDialogSession,
|
|
39
39
|
} from "./dialog.ts";
|
|
40
40
|
import { getModelPreferences } from "../prefs/models.ts";
|
|
41
|
+
import type { WidgetMode } from "../prefs/settings.ts";
|
|
41
42
|
import { buildStatusTree, type StatusRow } from "./thread-tree.ts";
|
|
42
43
|
import {
|
|
43
44
|
THINKING_LEVELS,
|
|
@@ -219,6 +220,31 @@ export function renderThreads(
|
|
|
219
220
|
const WIDGET_ROOT = "/root";
|
|
220
221
|
const MAX_WIDGET_LINES = 12;
|
|
221
222
|
const AGENT_WIDGET_PLACEMENT = { placement: "aboveEditor" as const };
|
|
223
|
+
const AGENT_BROWSER_HINT = "Press ← to open subagent browser";
|
|
224
|
+
|
|
225
|
+
interface AgentWidgetRenderOptions {
|
|
226
|
+
/** RPC widgets cannot open a terminal browser. */
|
|
227
|
+
showBrowserHint?: boolean;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function agentWidgetStatus(
|
|
231
|
+
running: number,
|
|
232
|
+
omitted: number,
|
|
233
|
+
width: number,
|
|
234
|
+
theme: Pick<Theme, "fg">,
|
|
235
|
+
showBrowserHint: boolean,
|
|
236
|
+
): string {
|
|
237
|
+
const details = [
|
|
238
|
+
omitted > 0 ? `+${omitted} more agents` : "",
|
|
239
|
+
showBrowserHint ? AGENT_BROWSER_HINT : "",
|
|
240
|
+
].filter(Boolean);
|
|
241
|
+
return truncateToWidth(
|
|
242
|
+
theme.fg("accent", `${running} running`) +
|
|
243
|
+
(details.length ? theme.fg("muted", ` · ${details.join(" · ")}`) : ""),
|
|
244
|
+
width,
|
|
245
|
+
"",
|
|
246
|
+
);
|
|
247
|
+
}
|
|
222
248
|
|
|
223
249
|
function statePriority(state: ThreadView["state"] | undefined): number {
|
|
224
250
|
if (state === "starting" || state === "running") return 0;
|
|
@@ -367,7 +393,8 @@ function takeWidgetRows(rows: StatusRow[], budget: number): StatusRow[] {
|
|
|
367
393
|
.sort(
|
|
368
394
|
(a, b) =>
|
|
369
395
|
statePriority(a.row.thread!.state) -
|
|
370
|
-
statePriority(b.row.thread!.state) ||
|
|
396
|
+
statePriority(b.row.thread!.state) ||
|
|
397
|
+
b.row.thread!.createdAt - a.row.thread!.createdAt || a.index - b.index,
|
|
371
398
|
);
|
|
372
399
|
const chosen = new Set<number>();
|
|
373
400
|
let used = 0;
|
|
@@ -402,6 +429,7 @@ export function renderAgentTree(
|
|
|
402
429
|
threads: ThreadView[],
|
|
403
430
|
width: number,
|
|
404
431
|
theme: AgentBadgeTheme,
|
|
432
|
+
{ showBrowserHint = true }: AgentWidgetRenderOptions = {},
|
|
405
433
|
): string[] {
|
|
406
434
|
const columns = Math.max(0, width);
|
|
407
435
|
const rows = buildStatusTree(
|
|
@@ -421,15 +449,9 @@ export function renderAgentTree(
|
|
|
421
449
|
theme.fg("muted", `${live} live · ${paused} paused`),
|
|
422
450
|
columns,
|
|
423
451
|
);
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const
|
|
427
|
-
let visible = takeWidgetRows(rows, rowBudget);
|
|
428
|
-
let omitted = agents.length - visible.filter((row) => row.thread).length;
|
|
429
|
-
if (omitted > 0) {
|
|
430
|
-
visible = takeWidgetRows(rows, rowBudget - 1);
|
|
431
|
-
omitted = agents.length - visible.filter((row) => row.thread).length;
|
|
432
|
-
}
|
|
452
|
+
// Reserve the last line for status and browser entry, even with no omissions.
|
|
453
|
+
const visible = takeWidgetRows(rows, MAX_WIDGET_LINES - 2);
|
|
454
|
+
const omitted = agents.length - visible.filter((row) => row.thread).length;
|
|
433
455
|
const lines = [heading];
|
|
434
456
|
for (const row of visible) {
|
|
435
457
|
if (!row.thread) {
|
|
@@ -439,35 +461,75 @@ export function renderAgentTree(
|
|
|
439
461
|
lines.push(agentLine(row, columns, theme));
|
|
440
462
|
lines.push(activityLine(row, columns, theme));
|
|
441
463
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
464
|
+
lines.push(agentWidgetStatus(live, omitted, columns, theme, showBrowserHint));
|
|
465
|
+
return lines;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** One-line counts for real agents; starting agents count as running, including tokens. */
|
|
469
|
+
export function renderAgentSummary(
|
|
470
|
+
threads: ThreadView[],
|
|
471
|
+
width: number,
|
|
472
|
+
theme: Pick<Theme, "fg">,
|
|
473
|
+
{ showBrowserHint = true }: AgentWidgetRenderOptions = {},
|
|
474
|
+
): string[] {
|
|
475
|
+
const agents = new Map<string, ThreadView>();
|
|
476
|
+
for (const thread of threads) {
|
|
477
|
+
if (thread?.path && thread.path !== WIDGET_ROOT && !agents.has(thread.path))
|
|
478
|
+
agents.set(thread.path, thread);
|
|
450
479
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
480
|
+
if (!agents.size) return [];
|
|
481
|
+
|
|
482
|
+
const counts: Record<Exclude<ThreadView["state"], "starting">, number> = {
|
|
483
|
+
running: 0,
|
|
484
|
+
stopped: 0,
|
|
485
|
+
failed: 0,
|
|
486
|
+
paused: 0,
|
|
487
|
+
completed: 0,
|
|
488
|
+
};
|
|
489
|
+
let input = 0;
|
|
490
|
+
let output = 0;
|
|
491
|
+
for (const thread of agents.values()) {
|
|
492
|
+
counts[thread.state === "starting" ? "running" : thread.state] += 1;
|
|
493
|
+
if (isLive(thread)) {
|
|
494
|
+
input += metricCount(thread.inputTokens);
|
|
495
|
+
output += metricCount(thread.outputTokens);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const statuses: [keyof typeof counts, ThemeColor][] = [
|
|
499
|
+
["running", "accent"],
|
|
500
|
+
["stopped", "muted"],
|
|
501
|
+
["failed", "error"],
|
|
502
|
+
["paused", "warning"],
|
|
503
|
+
["completed", "success"],
|
|
504
|
+
];
|
|
505
|
+
const left = statuses
|
|
506
|
+
.filter(([state]) => state === "running" || counts[state] > 0)
|
|
507
|
+
.map(([state, color]) => theme.fg(color, `${counts[state]} ${state}`))
|
|
508
|
+
.join(theme.fg("muted", ", "));
|
|
509
|
+
const right = theme.fg("muted", `↑${formatCount(input)} ↓${formatCount(output)}`);
|
|
510
|
+
const columns = Math.max(0, width);
|
|
511
|
+
const lines = [fitLine(left, right, columns)];
|
|
512
|
+
if (showBrowserHint)
|
|
513
|
+
lines.push(truncateToWidth(theme.fg("muted", AGENT_BROWSER_HINT), columns, ""));
|
|
454
514
|
return lines;
|
|
455
515
|
}
|
|
456
516
|
|
|
457
517
|
export function updateWidget(
|
|
458
518
|
ctx: ExtensionContext,
|
|
459
519
|
threads: ThreadView[],
|
|
520
|
+
mode: WidgetMode = "full",
|
|
460
521
|
): void {
|
|
461
522
|
if (!ctx.hasUI) return;
|
|
462
523
|
if (!threads.some((thread) => thread.path !== "/root")) {
|
|
463
524
|
ctx.ui.setWidget("pi-subagent", undefined, AGENT_WIDGET_PLACEMENT);
|
|
464
525
|
return;
|
|
465
526
|
}
|
|
527
|
+
const render = mode === "minimal" ? renderAgentSummary : renderAgentTree;
|
|
466
528
|
// RPC hosts accept string widgets only; a component factory is ignored.
|
|
467
529
|
if (ctx.mode === "rpc") {
|
|
468
530
|
ctx.ui.setWidget(
|
|
469
531
|
"pi-subagent",
|
|
470
|
-
|
|
532
|
+
render(threads, 80, ctx.ui.theme, { showBrowserHint: false }),
|
|
471
533
|
AGENT_WIDGET_PLACEMENT,
|
|
472
534
|
);
|
|
473
535
|
return;
|
|
@@ -477,12 +539,12 @@ export function updateWidget(
|
|
|
477
539
|
"pi-subagent",
|
|
478
540
|
(tui) => {
|
|
479
541
|
let timer: ReturnType<typeof setInterval> | undefined;
|
|
480
|
-
if (snapshot.some(isLive)) {
|
|
542
|
+
if (mode === "full" && snapshot.some(isLive)) {
|
|
481
543
|
timer = setInterval(() => tui.requestRender(), 1000);
|
|
482
544
|
timer.unref();
|
|
483
545
|
}
|
|
484
546
|
return {
|
|
485
|
-
render: (width) =>
|
|
547
|
+
render: (width) => render(snapshot, width, ctx.ui.theme),
|
|
486
548
|
invalidate: () => {},
|
|
487
549
|
dispose: () => {
|
|
488
550
|
if (timer) clearInterval(timer);
|