pi-subagent-manager 0.9.0 → 0.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.
- package/README.md +3 -1
- package/agents/architect.md +1 -0
- package/agents/coder.md +1 -0
- package/agents/researcher.md +1 -0
- package/agents/reviewer.md +1 -0
- package/agents/tasker.md +1 -0
- package/agents/writer.md +1 -0
- package/docs/custom-agents.md +14 -0
- package/docs/default-agents.md +15 -0
- package/docs/settings.md +26 -0
- package/docs/tools-and-ui.md +14 -7
- package/package.json +1 -1
- package/src/index.ts +21 -14
- package/src/orch/manager.ts +3 -0
- package/src/orch/tools.ts +2 -1
- package/src/prefs/config.ts +7 -1
- package/src/prefs/settings.ts +62 -3
- package/src/types.ts +4 -0
- package/src/ui/agent-navigation-editor.ts +12 -15
- package/src/ui/live-agent-view.ts +23 -9
- package/src/ui/settings-ui.ts +52 -4
- package/src/ui/status-ui.ts +15 -16
- package/src/ui/ui.ts +129 -33
package/README.md
CHANGED
|
@@ -72,7 +72,9 @@ 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**. Once the main turn ends and all subagents are idle, the preview collapses to a single status-count line; `/agents tree` still opens the full tree. 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
|
+
|
|
77
|
+
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). 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).
|
|
76
78
|
|
|
77
79
|
## Docs
|
|
78
80
|
|
package/agents/architect.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: architect
|
|
3
|
+
icon: ''
|
|
3
4
|
description: Design architecture, weigh tradeoffs, and decompose ambiguous work into verifiable plans. Ground external claims in dated primary evidence when retrieval is actually available. Coordinate specialists only when delegation or execution is explicitly authorized.
|
|
4
5
|
color: mdHeading
|
|
5
6
|
thinkingLevel: high
|
package/agents/coder.md
CHANGED
package/agents/researcher.md
CHANGED
package/agents/reviewer.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: reviewer
|
|
3
|
+
icon: ''
|
|
3
4
|
description: Non-mutating review of scoped changes or existing code for demonstrable correctness and security defects, with severity, location, impact, and the smallest local repair or removal. Not for implementing fixes, style quotas, or speculative abstractions.
|
|
4
5
|
thinkingLevel: high
|
|
5
6
|
color: warning
|
package/agents/tasker.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: tasker
|
|
3
|
+
icon: ''
|
|
3
4
|
description: Complete short, bounded jobs with clear acceptance criteria, including diagnostics, extraction, mechanical edits, a few tool steps, or a targeted repository lookup. Not for ambiguous features, sustained implementation, or complex code understanding.
|
|
4
5
|
thinkingLevel: low
|
|
5
6
|
color: success
|
package/agents/writer.md
CHANGED
package/docs/custom-agents.md
CHANGED
|
@@ -22,6 +22,7 @@ These are the only locations read. Other packages' `~/.pi/agent/agents` or `.pi/
|
|
|
22
22
|
name: api-scout
|
|
23
23
|
description: Investigate APIs and find evidence before implementation
|
|
24
24
|
thinkingLevel: high
|
|
25
|
+
icon: "\uf002"
|
|
25
26
|
models:
|
|
26
27
|
- anthropic/claude-sonnet-4-6
|
|
27
28
|
- openai/gpt-5
|
|
@@ -49,11 +50,24 @@ Ask the main model to use it: _"spawn an api-scout at `stripe-webhooks` to check
|
|
|
49
50
|
| `thinkingLevel` | no | `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`. Clamped to what the model supports. |
|
|
50
51
|
| `tools` | no | `allow` / `block` lists of exact tool names. Applied per [Tool Filtering](settings.md#tool-filtering-toolfiltering). |
|
|
51
52
|
| `color` | no | pi semantic color (`accent`, `success`, `warning`, `error`, `muted`, `dim`) for the type pill and path. Default `accent`. |
|
|
53
|
+
| `icon` | no | Single literal Nerd Font glyph. Displayed only with **[labs] Nerd Font icons** enabled; omit for text-only labels. |
|
|
52
54
|
| `modelSuggestions` | no | Plain model names (e.g. `sonnet-5.5`) that rank the model picker's search. **Never** select a model at runtime. |
|
|
53
55
|
| `model` | no | Deprecated single-model alias. Still parsed; saved back as `models`. |
|
|
54
56
|
|
|
55
57
|
The Markdown body is the system prompt.
|
|
56
58
|
|
|
59
|
+
## Icons [labs]
|
|
60
|
+
|
|
61
|
+
The optional `icon` field works for any custom or bundled agent type. Choose a glyph from the [Nerd Fonts cheat sheet](https://www.nerdfonts.com/cheat-sheet) and copy the actual character into quoted YAML, for example:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
icon: "\uf002" # nf-fa-search, U+F002
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Use one Unicode private-use character, not an icon name (`nf-fa-search`), codepoint text (`U+F002`), emoji, or multiple glyphs. Both BMP and supplementary Nerd Font glyphs are supported. Omit the field to remove an icon; empty `icon:` values are invalid.
|
|
68
|
+
|
|
69
|
+
In `/agents types`, select **[labs] Icon** and paste the glyph, then save the agent. Leave the editor blank to remove it. You can configure icons while the feature is off; enable **[labs] Nerd Font icons** in `/agents` settings to see them. A Nerd Font must also be selected in your terminal. Icons supplement names, never replace them.
|
|
70
|
+
|
|
57
71
|
## Tips
|
|
58
72
|
|
|
59
73
|
- **Tools default to none.** With default filtering, an empty or missing `allow` list means the agent gets no tools. List what it needs.
|
package/docs/default-agents.md
CHANGED
|
@@ -19,6 +19,21 @@ Use tasker for one symbol or a few facts already in the repository; use research
|
|
|
19
19
|
|
|
20
20
|
Existing user/project `researcher` overrides still win over the new packaged default. Bundled `worker`, `explorer`, and `designer` remain absent: bounded work routes to tasker, frontend implementation to coder, and source investigation to researcher. Nothing is automatically renamed.
|
|
21
21
|
|
|
22
|
+
## Nerd Font icons
|
|
23
|
+
|
|
24
|
+
The optional **[labs] Nerd Font icons** [setting](settings.md#labs-nerd-font-icons-nerdfonticons) is off by default and requires a Nerd Font in your terminal. Each default has a distinct literal `icon` in its frontmatter:
|
|
25
|
+
|
|
26
|
+
| Role | Nerd Fonts identifier | Codepoint | Why this icon |
|
|
27
|
+
| --- | --- | --- | --- |
|
|
28
|
+
| `architect` | `nf-md-floor_plan` | `U+F0821` | Structure, layout, and architecture planning. |
|
|
29
|
+
| `coder` | `nf-fa-code` | `U+F121` | Implementation and source code. |
|
|
30
|
+
| `researcher` | `nf-fa-search` | `U+F002` | Evidence gathering and investigation. |
|
|
31
|
+
| `reviewer` | `nf-cod-inspect` | `U+EBD1` | Inspecting code for concrete defects. |
|
|
32
|
+
| `tasker` | `nf-oct-checklist` | `U+F45E` | Bounded tasks and checklist-style execution. |
|
|
33
|
+
| `writer` | `nf-fa-pencil` | `U+F040` | Writing and editorial work. |
|
|
34
|
+
|
|
35
|
+
Names and codepoints were checked against the [official Nerd Fonts glyph mapping](https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/glyphnames.json); the [cheat sheet](https://www.nerdfonts.com/cheat-sheet) offers previews and character copying. These are role-based design choices, not font-detected fallbacks. User/project overrides may choose another icon or omit it entirely. See [custom icons](custom-agents.md#icons-labs).
|
|
36
|
+
|
|
22
37
|
## Model suggestions are plain names, not pins
|
|
23
38
|
|
|
24
39
|
Suggestions are chosen by task capability, quality, cost, and speed. API formats, SDK adapter compatibility, provider access, and deployment convenience are not selection criteria; Pi's `pi-ai` SDK abstracts model API differences. Availability/release facts are source metadata, not a reason to downrank a capable model.
|
package/docs/settings.md
CHANGED
|
@@ -14,6 +14,8 @@ All keys are optional. Defaults:
|
|
|
14
14
|
```json
|
|
15
15
|
{
|
|
16
16
|
"subagentMode": "opportunistic",
|
|
17
|
+
"widgetMode": "full",
|
|
18
|
+
"nerdFontIcons": false,
|
|
17
19
|
"modelSelection": "pick-first-scoped",
|
|
18
20
|
"toolFiltering": "allowed",
|
|
19
21
|
"maxLevels": 3,
|
|
@@ -41,6 +43,25 @@ How much the main model is encouraged to delegate.
|
|
|
41
43
|
- Orchestration is a prompt policy, not a tool restriction. Workers don't inherit the root-only rule.
|
|
42
44
|
- Agent import needs `opportunistic` (it uses the main thread's file tools).
|
|
43
45
|
|
|
46
|
+
## Status Widget (`widgetMode`)
|
|
47
|
+
|
|
48
|
+
Controls the subagent status display above the input box. Choose **Status Widget** in `/agents` settings and save with **Ctrl+S**.
|
|
49
|
+
|
|
50
|
+
| Option | Display |
|
|
51
|
+
| ------------------ | ------- |
|
|
52
|
+
| `full` (default) | The existing multi-line tree with agent details, activity and navigation hints. |
|
|
53
|
+
| `minimal` | One line of theme-colored status counts plus cumulative input `↑` / output `↓` tokens for agents currently starting or running. |
|
|
54
|
+
|
|
55
|
+
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.
|
|
56
|
+
|
|
57
|
+
## [labs] Nerd Font icons (`nerdFontIcons`)
|
|
58
|
+
|
|
59
|
+
Experimental features are tagged **[labs]** in settings. **[labs] Nerd Font icons** is an on/off toggle, **off by default**. Enable it in `/agents` and save with **Ctrl+S**, or set `"nerdFontIcons": true` in your settings file. Configure a [Nerd Font](https://www.nerdfonts.com/) in your terminal first; unsupported fonts may show boxes or incorrect glyphs. The extension does not install or detect fonts.
|
|
60
|
+
|
|
61
|
+
When enabled, an agent type’s optional `icon` appears before its readable name in the full widget, thread browsers, live watcher header, and type picker. Types without icons remain text-only; turning it off restores text-only labels without removing configured icons. The minimal widget remains an aggregate count, with no per-agent icons. Saved settings apply immediately to newly rendered widgets and dialogs.
|
|
62
|
+
|
|
63
|
+
All six bundled agents have [role-specific icons](default-agents.md#nerd-font-icons). Add or change an icon with **[labs] Icon** in `/agents types`, or the optional `icon` frontmatter field in [your own agent](custom-agents.md#icons-labs). Retained threads keep the icon from their saved agent definition.
|
|
64
|
+
|
|
44
65
|
## Model Picking (`modelSelection`)
|
|
45
66
|
|
|
46
67
|
Which model an agent gets when its session starts.
|
|
@@ -105,3 +126,8 @@ Lower it to keep the tree tidy. Raise it for long sessions with many agents. Whe
|
|
|
105
126
|
## Scope
|
|
106
127
|
|
|
107
128
|
The dialog's scope field picks where to save: **global** or **trusted project**.
|
|
129
|
+
Your selection is remembered across dialog reopenings, projects, and Pi restarts,
|
|
130
|
+
even if you cancel. It is stored separately from manager settings in
|
|
131
|
+
`<agentDir>/subagent-manager/ui-state.json`. Untrusted projects always use Global
|
|
132
|
+
without overwriting your remembered choice. Existing project settings still
|
|
133
|
+
override global defaults; switching scope does not change the values shown.
|
package/docs/tools-and-ui.md
CHANGED
|
@@ -65,25 +65,32 @@ 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
|
+
Once the main turn has ended and no subagents are starting or running, either mode collapses to a single status-count line without the browser hint. The full tree remains available via `/agents tree` or **Left** at the start of the draft. A new main turn or active subagent restores the configured display mode.
|
|
86
|
+
|
|
87
|
+
In full mode:
|
|
81
88
|
|
|
82
89
|
- Each row: colored type pill, path, state, task, active time, input `↑` / output `↓` tokens.
|
|
83
90
|
- A second, indented line shows latest activity.
|
|
84
|
-
- Active branches are shown first; overflow is counted, not listed.
|
|
91
|
+
- Active branches are shown first; the most recent agents within each state are preferred when previews overflow. Overflow is counted, not listed.
|
|
85
92
|
- Time freezes while paused and resumes on continue.
|
|
86
|
-
-
|
|
93
|
+
- 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
94
|
|
|
88
95
|
### Interrupts and stopping agents
|
|
89
96
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -48,6 +48,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
48
48
|
return loaded.diagnostics;
|
|
49
49
|
};
|
|
50
50
|
let generation = 0;
|
|
51
|
+
let rootTurnEnded = false;
|
|
51
52
|
let navigation = new AgentNavigationController();
|
|
52
53
|
let navigationEditor: AgentNavigationEditor | undefined;
|
|
53
54
|
let navigationEditorFactory: Parameters<ExtensionContext["ui"]["setEditorComponent"]>[0];
|
|
@@ -61,9 +62,8 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
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;
|
|
65
|
+
// Pi has one custom-editor slot: do not replace another integration.
|
|
66
|
+
if (!ctx.hasUI || ctx.mode !== "tui" || !ctx.ui.setEditorComponent) return;
|
|
67
67
|
const existingFactory = ctx.ui.getEditorComponent?.();
|
|
68
68
|
if (existingFactory && existingFactory !== navigationEditorFactory) return;
|
|
69
69
|
// The host only transfers raw text, not cursor/undo/expanded-paste state.
|
|
@@ -82,7 +82,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
82
82
|
canOpen: () => manager !== undefined && context?.mode === "tui" &&
|
|
83
83
|
limits.subagentMode !== "off" && !navigation.isOpen,
|
|
84
84
|
openTree: () => manager && context
|
|
85
|
-
? navigation.open(context, manager.scope("/root")) : undefined,
|
|
85
|
+
? navigation.open(context, manager.scope("/root"), undefined, limits.nerdFontIcons) : undefined,
|
|
86
86
|
onError: (error) => context?.ui.notify(
|
|
87
87
|
error instanceof Error ? error.message : String(error), "error"),
|
|
88
88
|
});
|
|
@@ -114,12 +114,6 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
114
114
|
importInProgress = false;
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
|
-
// A migration can span clarification turns. Reload after each root turn, without converting files.
|
|
118
|
-
pi.on("agent_end", async () => {
|
|
119
|
-
if (limits.subagentMode === "off" || !migrationRequested) return;
|
|
120
|
-
store.reload();
|
|
121
|
-
if (store.diagnostics.length) context?.ui.notify(store.diagnostics.join("\n"), "warning");
|
|
122
|
-
});
|
|
123
117
|
const requireManager = () => {
|
|
124
118
|
if (!manager) throw new Error("Subagent threads are not initialized; start a Pi session first");
|
|
125
119
|
return manager;
|
|
@@ -239,8 +233,20 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
239
233
|
const refreshWidget = (ctx: ExtensionContext) => {
|
|
240
234
|
if (limits.subagentMode === "off") {
|
|
241
235
|
if (ctx.hasUI) ctx.ui.setWidget("pi-subagent", undefined);
|
|
242
|
-
} else updateWidget(ctx, requireManager().list());
|
|
236
|
+
} else updateWidget(ctx, requireManager().list(), limits.widgetMode, limits.nerdFontIcons, rootTurnEnded);
|
|
243
237
|
};
|
|
238
|
+
pi.on("agent_start", async (_event, ctx) => {
|
|
239
|
+
rootTurnEnded = false;
|
|
240
|
+
if (manager) refreshWidget(ctx);
|
|
241
|
+
});
|
|
242
|
+
pi.on("agent_end", async (_event, ctx) => {
|
|
243
|
+
rootTurnEnded = true;
|
|
244
|
+
if (manager) refreshWidget(ctx);
|
|
245
|
+
// A migration can span clarification turns. Reload after each root turn, without converting files.
|
|
246
|
+
if (limits.subagentMode === "off" || !migrationRequested) return;
|
|
247
|
+
store.reload();
|
|
248
|
+
if (store.diagnostics.length) context?.ui.notify(store.diagnostics.join("\n"), "warning");
|
|
249
|
+
});
|
|
244
250
|
syncTools();
|
|
245
251
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
246
252
|
const prompt = subagentPrompt(limits);
|
|
@@ -265,6 +271,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
265
271
|
if (manager) await manager.shutdown();
|
|
266
272
|
inheritedTools.reset();
|
|
267
273
|
context = ctx;
|
|
274
|
+
rootTurnEnded = false;
|
|
268
275
|
store = new ConfigStore({
|
|
269
276
|
cwd: ctx.cwd,
|
|
270
277
|
agentDir: getAgentDir(),
|
|
@@ -374,7 +381,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
374
381
|
if (command === "import") {
|
|
375
382
|
await importAgents(ctx, false);
|
|
376
383
|
} else if (command === "types") {
|
|
377
|
-
await editAgentTypes(ctx, store);
|
|
384
|
+
await editAgentTypes(ctx, store, limits.nerdFontIcons);
|
|
378
385
|
store.reload();
|
|
379
386
|
} else if (command === "reload") {
|
|
380
387
|
store.reload();
|
|
@@ -404,9 +411,9 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
404
411
|
},
|
|
405
412
|
});
|
|
406
413
|
} else if (command === "status") {
|
|
407
|
-
await showAgentStatus(ctx, requireManager().scope("/root"));
|
|
414
|
+
await showAgentStatus(ctx, requireManager().scope("/root"), undefined, limits.nerdFontIcons);
|
|
408
415
|
} else if (command === "tree") {
|
|
409
|
-
await navigation.open(ctx, requireManager().scope("/root"), rest.join(" ") || undefined);
|
|
416
|
+
await navigation.open(ctx, requireManager().scope("/root"), rest.join(" ") || undefined, limits.nerdFontIcons);
|
|
410
417
|
} else
|
|
411
418
|
ctx.ui.notify(
|
|
412
419
|
"Usage: /agents [tree [path] | status | settings | types | import | reload]",
|
package/src/orch/manager.ts
CHANGED
|
@@ -136,6 +136,7 @@ export class ThreadManager {
|
|
|
136
136
|
owner: current.owner,
|
|
137
137
|
type: current.type,
|
|
138
138
|
color: current.color,
|
|
139
|
+
icon: current.icon,
|
|
139
140
|
state: current.state,
|
|
140
141
|
task: current.task,
|
|
141
142
|
status: current.status,
|
|
@@ -177,6 +178,7 @@ export class ThreadManager {
|
|
|
177
178
|
const { sessionLeafId, ...storedView } = savedView;
|
|
178
179
|
const view: ThreadView = {
|
|
179
180
|
...storedView,
|
|
181
|
+
icon: storedView.icon ?? item.definition.icon,
|
|
180
182
|
updatedAt: Date.now(),
|
|
181
183
|
elapsedMs: storedView.elapsedMs ?? 0,
|
|
182
184
|
inputTokens: storedView.inputTokens ?? 0,
|
|
@@ -263,6 +265,7 @@ export class ThreadManager {
|
|
|
263
265
|
owner: parent ?? caller,
|
|
264
266
|
type: type.name,
|
|
265
267
|
color: type.color,
|
|
268
|
+
icon: type.icon,
|
|
266
269
|
state: "starting",
|
|
267
270
|
task: args.task,
|
|
268
271
|
status: "Starting",
|
package/src/orch/tools.ts
CHANGED
|
@@ -45,13 +45,14 @@ export function agentTools(
|
|
|
45
45
|
() =>
|
|
46
46
|
result(
|
|
47
47
|
getTypes().map(
|
|
48
|
-
({ name, description, thinkingLevel, color, modelSuggestions, ...type }) => ({
|
|
48
|
+
({ name, description, thinkingLevel, color, icon, modelSuggestions, ...type }) => ({
|
|
49
49
|
name,
|
|
50
50
|
description,
|
|
51
51
|
models: getModelPreferences(type),
|
|
52
52
|
modelSuggestions: modelSuggestions === undefined ? undefined : [...modelSuggestions],
|
|
53
53
|
thinkingLevel,
|
|
54
54
|
color,
|
|
55
|
+
icon,
|
|
55
56
|
}),
|
|
56
57
|
),
|
|
57
58
|
),
|
package/src/prefs/config.ts
CHANGED
|
@@ -78,6 +78,7 @@ const FIELDS = new Set([
|
|
|
78
78
|
"modelSuggestions",
|
|
79
79
|
"thinkingLevel",
|
|
80
80
|
"color",
|
|
81
|
+
"icon",
|
|
81
82
|
"tools",
|
|
82
83
|
]);
|
|
83
84
|
const SUBAGENT_MANAGER_DIR = "subagent-manager";
|
|
@@ -227,6 +228,11 @@ export function parseAgentType(content: string, filePath?: string): AgentType {
|
|
|
227
228
|
);
|
|
228
229
|
result.color = data.color as string;
|
|
229
230
|
}
|
|
231
|
+
if (Object.hasOwn(data, "icon")) {
|
|
232
|
+
if (typeof data.icon !== "string" || !/^\p{Co}$/u.test(data.icon))
|
|
233
|
+
throw new Error("icon must be a single literal Nerd Font glyph (Unicode private-use character)");
|
|
234
|
+
result.icon = data.icon;
|
|
235
|
+
}
|
|
230
236
|
if (Object.hasOwn(data, "tools")) result.tools = toolPolicy(data.tools);
|
|
231
237
|
if (filePath !== undefined) result.filePath = filePath;
|
|
232
238
|
return result;
|
|
@@ -248,7 +254,7 @@ export function serializeAgentType(type: AgentType): string {
|
|
|
248
254
|
if (models !== undefined) data.models = models;
|
|
249
255
|
if (type.modelSuggestions !== undefined)
|
|
250
256
|
data.modelSuggestions = modelSuggestionNames(type.modelSuggestions);
|
|
251
|
-
for (const key of ["thinkingLevel", "color", "tools"] as const)
|
|
257
|
+
for (const key of ["thinkingLevel", "color", "icon", "tools"] as const)
|
|
252
258
|
if (type[key] !== undefined) data[key] = type[key];
|
|
253
259
|
const content = `---\n${stringify(data)}---\n${type.systemPrompt}`;
|
|
254
260
|
parseAgentType(content);
|
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,8 @@ export type ModelSelectionMode = (typeof MODEL_SELECTION_MODES)[number];
|
|
|
29
32
|
export interface ManagerSettings {
|
|
30
33
|
subagentMode: SubagentMode;
|
|
31
34
|
toolFiltering: ToolFilteringMode;
|
|
35
|
+
widgetMode: WidgetMode;
|
|
36
|
+
nerdFontIcons: boolean;
|
|
32
37
|
maxLevels: number;
|
|
33
38
|
maxConcurrent: number;
|
|
34
39
|
maxThreads: number;
|
|
@@ -42,10 +47,12 @@ export const DEFAULT_MANAGER_SETTINGS: ManagerSettings = {
|
|
|
42
47
|
modelSelection: "pick-first-scoped",
|
|
43
48
|
subagentMode: "opportunistic",
|
|
44
49
|
toolFiltering: "allowed",
|
|
50
|
+
widgetMode: "full",
|
|
51
|
+
nerdFontIcons: false,
|
|
45
52
|
};
|
|
46
53
|
|
|
47
54
|
const KEYS = [
|
|
48
|
-
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering",
|
|
55
|
+
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "nerdFontIcons",
|
|
49
56
|
] as const;
|
|
50
57
|
const MAX_LEVELS = 32;
|
|
51
58
|
|
|
@@ -83,7 +90,9 @@ function positiveSafeInteger(value: unknown): value is number {
|
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
function requirement(key: (typeof KEYS)[number]): string {
|
|
93
|
+
if (key === "nerdFontIcons") return "nerdFontIcons must be a boolean";
|
|
86
94
|
if (key === "subagentMode") return "subagentMode must be off, opportunistic or orchestration";
|
|
95
|
+
if (key === "widgetMode") return "widgetMode must be full or minimal";
|
|
87
96
|
if (key === "toolFiltering") return "toolFiltering must be allowed, all-except-blocked or all";
|
|
88
97
|
if (key === "modelSelection")
|
|
89
98
|
return "modelSelection must be pick-first-available, pick-first-scoped or use-current";
|
|
@@ -116,6 +125,11 @@ function parseSettings(content: string): Partial<ManagerSettings> {
|
|
|
116
125
|
for (const key of KEYS) {
|
|
117
126
|
if (!Object.hasOwn(record, key)) continue;
|
|
118
127
|
const value = record[key];
|
|
128
|
+
if (key === "nerdFontIcons") {
|
|
129
|
+
if (typeof value !== "boolean") throw new Error(requirement(key));
|
|
130
|
+
layer.nerdFontIcons = value;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
119
133
|
if (key === "subagentMode") {
|
|
120
134
|
if (!SUBAGENT_MODES.includes(value as SubagentMode)) throw new Error(requirement(key));
|
|
121
135
|
layer.subagentMode = value as SubagentMode;
|
|
@@ -127,6 +141,11 @@ function parseSettings(content: string): Partial<ManagerSettings> {
|
|
|
127
141
|
layer.toolFiltering = value as ToolFilteringMode;
|
|
128
142
|
continue;
|
|
129
143
|
}
|
|
144
|
+
if (key === "widgetMode") {
|
|
145
|
+
if (!WIDGET_MODES.includes(value as WidgetMode)) throw new Error(requirement(key));
|
|
146
|
+
layer.widgetMode = value as WidgetMode;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
130
149
|
if (key === "modelSelection") {
|
|
131
150
|
if (!MODEL_SELECTION_MODES.includes(value as ModelSelectionMode))
|
|
132
151
|
throw new Error(requirement(key));
|
|
@@ -155,7 +174,7 @@ function layer(base: string, segments: string[]): SettingsLayer {
|
|
|
155
174
|
return { filePath: join(current, "settings.json"), directories };
|
|
156
175
|
}
|
|
157
176
|
|
|
158
|
-
function
|
|
177
|
+
function readLayerContent(entry: SettingsLayer): string | undefined {
|
|
159
178
|
for (const directory of entry.directories) {
|
|
160
179
|
const stat = assertNotSymlinkPath(directory);
|
|
161
180
|
if (!stat) return undefined;
|
|
@@ -166,7 +185,47 @@ function readLayer(entry: SettingsLayer): Partial<ManagerSettings> | undefined {
|
|
|
166
185
|
if (!stat) return undefined;
|
|
167
186
|
if (!stat.isFile())
|
|
168
187
|
throw new Error(`Settings must be a regular file: ${entry.filePath}`);
|
|
169
|
-
return
|
|
188
|
+
return readFileSync(entry.filePath, "utf8");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function readLayer(entry: SettingsLayer): Partial<ManagerSettings> | undefined {
|
|
192
|
+
const content = readLayerContent(entry);
|
|
193
|
+
return content === undefined ? undefined : parseSettings(content);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type ManagerSaveScope = "user" | "project";
|
|
197
|
+
|
|
198
|
+
function uiStateLayer(agentDir: string): SettingsLayer {
|
|
199
|
+
const entry = layer(agentDir, ["subagent-manager"]);
|
|
200
|
+
return { ...entry, filePath: join(dirname(entry.filePath), "ui-state.json") };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** UI preference only: never participates in manager-settings precedence. */
|
|
204
|
+
export function loadManagerSaveScope(options: {
|
|
205
|
+
agentDir: string;
|
|
206
|
+
includeProject: boolean;
|
|
207
|
+
}): ManagerSaveScope {
|
|
208
|
+
if (!options.includeProject) return "user";
|
|
209
|
+
try {
|
|
210
|
+
const content = readLayerContent(uiStateLayer(options.agentDir));
|
|
211
|
+
if (content !== undefined) {
|
|
212
|
+
const state: unknown = JSON.parse(content);
|
|
213
|
+
if (
|
|
214
|
+
state && typeof state === "object" && !Array.isArray(state) &&
|
|
215
|
+
"saveScope" in state && state.saveScope === "user"
|
|
216
|
+
) return "user";
|
|
217
|
+
}
|
|
218
|
+
} catch {
|
|
219
|
+
// Missing, invalid or unsafe UI state must not prevent opening settings.
|
|
220
|
+
}
|
|
221
|
+
return "project";
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function saveManagerSaveScope(agentDir: string, scope: ManagerSaveScope): void {
|
|
225
|
+
if (scope !== "user" && scope !== "project") throw new Error("Invalid settings scope");
|
|
226
|
+
const entry = uiStateLayer(agentDir);
|
|
227
|
+
ensureScopeDirectories(entry.directories);
|
|
228
|
+
writeAtomically(entry, `${JSON.stringify({ saveScope: scope }, null, 2)}\n`);
|
|
170
229
|
}
|
|
171
230
|
|
|
172
231
|
function detail(error: unknown): string {
|
package/src/types.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface AgentType {
|
|
|
14
14
|
thinkingLevel?: ThinkingLevel;
|
|
15
15
|
/** Pi semantic token for the type pill background and task path foreground. */
|
|
16
16
|
color?: string;
|
|
17
|
+
/** Optional literal Nerd Font glyph; displayed only when the labs setting is enabled. */
|
|
18
|
+
icon?: string;
|
|
17
19
|
tools?: { allow?: string[]; block?: string[] };
|
|
18
20
|
systemPrompt: string;
|
|
19
21
|
filePath?: string;
|
|
@@ -26,6 +28,7 @@ export interface ThreadView {
|
|
|
26
28
|
owner: string;
|
|
27
29
|
type: string;
|
|
28
30
|
color?: string;
|
|
31
|
+
icon?: string;
|
|
29
32
|
state: ThreadState;
|
|
30
33
|
task: string;
|
|
31
34
|
status: string;
|
|
@@ -118,6 +121,7 @@ export interface SavedThreadView {
|
|
|
118
121
|
owner: string;
|
|
119
122
|
type: string;
|
|
120
123
|
color?: string;
|
|
124
|
+
icon?: string;
|
|
121
125
|
state: ThreadState;
|
|
122
126
|
task: string;
|
|
123
127
|
status: string;
|
|
@@ -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,
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
} from "@earendil-works/pi-tui";
|
|
12
13
|
import type { ThreadService, TranscriptSnapshot } from "../types.ts";
|
|
13
14
|
import { dialogText, type DialogHost } from "./dialog.ts";
|
|
15
|
+
import { agentTypeLabel } from "./ui.ts";
|
|
14
16
|
|
|
15
17
|
export interface AgentViewportState {
|
|
16
18
|
scrollTop: number;
|
|
@@ -19,7 +21,7 @@ export interface AgentViewportState {
|
|
|
19
21
|
showThinking?: boolean;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
/** Fully cover main, including at very small sizes;
|
|
24
|
+
/** Fully cover main, including at very small sizes; only trusted renderers emit terminal sequences. */
|
|
23
25
|
export function fillViewport(lines: string[], width: number, height: number): string[] {
|
|
24
26
|
width = Math.max(0, Math.floor(width));
|
|
25
27
|
height = Math.max(1, Math.floor(height));
|
|
@@ -49,7 +51,7 @@ function json(value: unknown): string {
|
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
/**
|
|
54
|
+
/** Read-only observer. Never invoke watched tools' custom renderers or pass through raw controls. */
|
|
53
55
|
export class LiveAgentView {
|
|
54
56
|
private snapshot: TranscriptSnapshot | undefined;
|
|
55
57
|
private error: string | undefined;
|
|
@@ -69,6 +71,7 @@ export class LiveAgentView {
|
|
|
69
71
|
readonly path: string,
|
|
70
72
|
private viewport: AgentViewportState,
|
|
71
73
|
private done: (result: "back" | "main") => void,
|
|
74
|
+
private nerdFontIcons = false,
|
|
72
75
|
) {
|
|
73
76
|
this.scroll = new ScrollView(
|
|
74
77
|
{ render: () => this.content, invalidate() {} },
|
|
@@ -180,6 +183,19 @@ export class LiveAgentView {
|
|
|
180
183
|
.flatMap((line) => wrapTextWithAnsi(line, Math.max(1, width)));
|
|
181
184
|
}
|
|
182
185
|
|
|
186
|
+
/** Use the same themed Markdown (including code highlighting) as pi's main transcript. */
|
|
187
|
+
private markdown(value: string, width: number, thinking = false): string[] {
|
|
188
|
+
return new Markdown(
|
|
189
|
+
text(value),
|
|
190
|
+
0,
|
|
191
|
+
0,
|
|
192
|
+
getMarkdownTheme(),
|
|
193
|
+
thinking
|
|
194
|
+
? { color: (value) => this.theme.fg("thinkingText", value), italic: true }
|
|
195
|
+
: undefined,
|
|
196
|
+
).render(Math.max(1, width));
|
|
197
|
+
}
|
|
198
|
+
|
|
183
199
|
/** Tool/metadata previews are bounded by rendered rows, not just source newlines. */
|
|
184
200
|
private preview(content: unknown, width: number): string[] {
|
|
185
201
|
const values = Array.isArray(content) ? content : [content];
|
|
@@ -207,18 +223,16 @@ export class LiveAgentView {
|
|
|
207
223
|
}
|
|
208
224
|
|
|
209
225
|
private blocks(content: unknown, width: number): string[] {
|
|
210
|
-
if (typeof content === "string") return this.
|
|
226
|
+
if (typeof content === "string") return this.markdown(content, width);
|
|
211
227
|
if (!Array.isArray(content)) return this.wrap(json(content), width);
|
|
212
228
|
return content.flatMap((value) => {
|
|
213
229
|
const block = object(value);
|
|
214
230
|
if (!block) return this.wrap(json(value), width);
|
|
215
|
-
if (block.type === "text") return this.
|
|
231
|
+
if (block.type === "text") return this.markdown(String(block.text ?? ""), width);
|
|
216
232
|
if (block.type === "image") return ["[Image — text-only observer]"];
|
|
217
233
|
if (block.type === "thinking")
|
|
218
234
|
return this.viewport.showThinking
|
|
219
|
-
? this.
|
|
220
|
-
this.theme.fg("muted", line),
|
|
221
|
-
)
|
|
235
|
+
? this.markdown(String(block.thinking ?? "[redacted thinking]"), width, true)
|
|
222
236
|
: [this.theme.fg("dim", "[Thinking hidden · t show]")];
|
|
223
237
|
if (block.type === "toolCall")
|
|
224
238
|
return [
|
|
@@ -266,7 +280,7 @@ export class LiveAgentView {
|
|
|
266
280
|
const header = this.theme.fg(
|
|
267
281
|
"accent",
|
|
268
282
|
dialogText(
|
|
269
|
-
`${this.path} · ${thread?.type ?? "agent"} · ${thread?.state ?? "attaching"} — Watching — main continues`,
|
|
283
|
+
`${this.path} · ${agentTypeLabel(thread?.type ?? "agent", thread?.icon, this.nerdFontIcons)} · ${thread?.state ?? "attaching"} — Watching — main continues`,
|
|
270
284
|
),
|
|
271
285
|
);
|
|
272
286
|
const body: string[] = [];
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -8,11 +8,14 @@ import {
|
|
|
8
8
|
} from "./dialog.ts";
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_MANAGER_SETTINGS,
|
|
11
|
+
loadManagerSaveScope,
|
|
12
|
+
saveManagerSaveScope,
|
|
11
13
|
saveManagerSettings,
|
|
12
14
|
type ManagerSettings,
|
|
13
15
|
type ModelSelectionMode,
|
|
14
16
|
type SubagentMode,
|
|
15
17
|
type ToolFilteringMode,
|
|
18
|
+
type WidgetMode,
|
|
16
19
|
} from "../prefs/settings.ts";
|
|
17
20
|
import { editAgentTypes } from "./ui.ts";
|
|
18
21
|
|
|
@@ -82,6 +85,24 @@ const TOOL_FILTERING_OPTIONS = [
|
|
|
82
85
|
const TOOL_FILTERING_HELP =
|
|
83
86
|
"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
87
|
|
|
88
|
+
const WIDGET_MODE_OPTIONS = [
|
|
89
|
+
{
|
|
90
|
+
id: "full",
|
|
91
|
+
label: "Full",
|
|
92
|
+
value: "Detailed agent status rows",
|
|
93
|
+
help: "Full: show the existing agent status widget above the input box, with per-agent details.",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "minimal",
|
|
97
|
+
label: "Minimal",
|
|
98
|
+
value: "One-line counts and running-agent tokens",
|
|
99
|
+
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.",
|
|
100
|
+
},
|
|
101
|
+
] as const;
|
|
102
|
+
|
|
103
|
+
const WIDGET_MODE_HELP =
|
|
104
|
+
"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.";
|
|
105
|
+
|
|
85
106
|
const MODEL_SELECTION_OPTIONS = [
|
|
86
107
|
{
|
|
87
108
|
id: "pick-first-available",
|
|
@@ -131,7 +152,10 @@ async function configureAgentsDialog(
|
|
|
131
152
|
},
|
|
132
153
|
): Promise<void> {
|
|
133
154
|
let draft = { ...options.settings };
|
|
134
|
-
let scope
|
|
155
|
+
let scope = loadManagerSaveScope({
|
|
156
|
+
agentDir: options.agentDir,
|
|
157
|
+
includeProject: ctx.isProjectTrusted(),
|
|
158
|
+
});
|
|
135
159
|
let selectedId: string | undefined;
|
|
136
160
|
while (true) {
|
|
137
161
|
const dirty = JSON.stringify(draft) !== JSON.stringify(options.settings);
|
|
@@ -161,11 +185,23 @@ async function configureAgentsDialog(
|
|
|
161
185
|
value: MODEL_SELECTION_OPTIONS.find((mode) => mode.id === draft.modelSelection)!.label,
|
|
162
186
|
help: MODEL_SELECTION_HELP,
|
|
163
187
|
},
|
|
188
|
+
{
|
|
189
|
+
id: "widgetMode",
|
|
190
|
+
label: "Status Widget",
|
|
191
|
+
value: WIDGET_MODE_OPTIONS.find((mode) => mode.id === draft.widgetMode)!.label,
|
|
192
|
+
help: WIDGET_MODE_HELP,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: "nerdFontIcons",
|
|
196
|
+
label: "[labs] Nerd Font icons",
|
|
197
|
+
value: draft.nerdFontIcons ? "On" : "Off",
|
|
198
|
+
help: "Experimental: display each agent type’s optional icon.\nRequires a Nerd Font configured in your terminal; otherwise glyphs may appear as boxes.\nOff by default. Save and apply to update the widget immediately.",
|
|
199
|
+
},
|
|
164
200
|
{
|
|
165
201
|
id: "scope",
|
|
166
202
|
label: "Save scope",
|
|
167
203
|
value: scope === "user" ? "Global" : "Current Project",
|
|
168
|
-
help: "Global: save all values shown as your defaults for every project. Existing project settings still override them, including here.\nCurrent Project: save all values shown for this project only, overriding your global defaults here. Other projects are unchanged. Requires a trusted project.\nSwitching scope only changes where you save, not the values shown.",
|
|
204
|
+
help: "Global: save all values shown as your defaults for every project. Existing project settings still override them, including here.\nCurrent Project: save all values shown for this project only, overriding your global defaults here. Other projects are unchanged. Requires a trusted project.\nSwitching scope only changes where you save, not the values shown. Your choice is remembered across projects and restarts, even if you cancel.",
|
|
169
205
|
},
|
|
170
206
|
{
|
|
171
207
|
id: "types",
|
|
@@ -236,16 +272,28 @@ async function configureAgentsDialog(
|
|
|
236
272
|
});
|
|
237
273
|
if (MODEL_SELECTION_OPTIONS.some((option) => option.id === mode))
|
|
238
274
|
draft.modelSelection = mode as ModelSelectionMode;
|
|
275
|
+
} else if (action === "widgetMode") {
|
|
276
|
+
const mode = await dialogMenu(ctx, "Status Widget", [...WIDGET_MODE_OPTIONS], {
|
|
277
|
+
selectedId: draft.widgetMode,
|
|
278
|
+
});
|
|
279
|
+
if (WIDGET_MODE_OPTIONS.some((option) => option.id === mode))
|
|
280
|
+
draft.widgetMode = mode as WidgetMode;
|
|
281
|
+
} else if (action === "nerdFontIcons") {
|
|
282
|
+
draft.nerdFontIcons = !draft.nerdFontIcons;
|
|
239
283
|
} else if (action === "scope") {
|
|
240
284
|
if (!ctx.isProjectTrusted())
|
|
241
285
|
ctx.ui.notify(
|
|
242
286
|
"Project settings require a trusted project; saving globally.",
|
|
243
287
|
"warning",
|
|
244
288
|
);
|
|
245
|
-
else
|
|
289
|
+
else {
|
|
290
|
+
const nextScope = scope === "user" ? "project" : "user";
|
|
291
|
+
saveManagerSaveScope(options.agentDir, nextScope);
|
|
292
|
+
scope = nextScope;
|
|
293
|
+
}
|
|
246
294
|
} else if (action === "defaults") draft = { ...DEFAULT_MANAGER_SETTINGS };
|
|
247
295
|
else if (action === "types") {
|
|
248
|
-
await editAgentTypes(ctx, options.store);
|
|
296
|
+
await editAgentTypes(ctx, options.store, draft.nerdFontIcons);
|
|
249
297
|
options.store.reload();
|
|
250
298
|
} else if (action === "save") {
|
|
251
299
|
const file = saveManagerSettings({
|
package/src/ui/status-ui.ts
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
} from "./dialog.ts";
|
|
26
26
|
import type { ThreadService } from "../types.ts";
|
|
27
27
|
import { buildStatusTree, type StatusRow } from "./thread-tree.ts";
|
|
28
|
-
import { agentTypeBadge, showThreads, threadMetrics } from "./ui.ts";
|
|
28
|
+
import { agentTypeBadge, agentTypeLabel, showThreads, threadMetrics } from "./ui.ts";
|
|
29
29
|
import { LiveAgentView, fillViewport, type AgentViewportState } from "./live-agent-view.ts";
|
|
30
30
|
|
|
31
31
|
export { buildStatusTree, type StatusRow };
|
|
@@ -104,6 +104,7 @@ export class StatusDialog {
|
|
|
104
104
|
actions(path: string): void;
|
|
105
105
|
fullscreen?: boolean;
|
|
106
106
|
},
|
|
107
|
+
private nerdFontIcons = false,
|
|
107
108
|
) {
|
|
108
109
|
this.state = navigation?.state ?? { selectedPath: selected || ROOT, collapsed: new Set() };
|
|
109
110
|
}
|
|
@@ -238,7 +239,7 @@ export class StatusDialog {
|
|
|
238
239
|
const status = dialogText(thread.status);
|
|
239
240
|
return [
|
|
240
241
|
this.theme.fg(selected ? "accent" : base, head),
|
|
241
|
-
this.theme.fg(base, `${
|
|
242
|
+
this.theme.fg(base, `${agentTypeLabel(thread.type, thread.icon, this.nerdFontIcons)} ${path} `),
|
|
242
243
|
this.theme.fg(hint, state),
|
|
243
244
|
this.theme.fg(base, ` ${status}`),
|
|
244
245
|
].join("");
|
|
@@ -247,8 +248,8 @@ export class StatusDialog {
|
|
|
247
248
|
.map((part) => dialogText(part))
|
|
248
249
|
.join(" ");
|
|
249
250
|
if (selected)
|
|
250
|
-
return `${this.theme.fg("accent", head)}${agentTypeBadge(thread.type, thread.color, this.theme)} ${this.theme.fg("accent", rest)}`;
|
|
251
|
-
return `${head}${agentTypeBadge(thread.type, thread.color, this.theme)} ${rest}`;
|
|
251
|
+
return `${this.theme.fg("accent", head)}${agentTypeBadge(thread.type, thread.color, this.theme, thread.icon, this.nerdFontIcons)} ${this.theme.fg("accent", rest)}`;
|
|
252
|
+
return `${head}${agentTypeBadge(thread.type, thread.color, this.theme, thread.icon, this.nerdFontIcons)} ${rest}`;
|
|
252
253
|
}
|
|
253
254
|
|
|
254
255
|
private detail(row: StatusRow | undefined): string[] {
|
|
@@ -311,6 +312,7 @@ async function showAgentDialog(
|
|
|
311
312
|
title?: string;
|
|
312
313
|
selected?: string;
|
|
313
314
|
inspect?: (path: string) => Promise<void>;
|
|
315
|
+
nerdFontIcons?: boolean;
|
|
314
316
|
} = {},
|
|
315
317
|
): Promise<void> {
|
|
316
318
|
const open = options.inspect ?? ((path: string) => showThreads(ctx, service, path));
|
|
@@ -321,7 +323,7 @@ async function showAgentDialog(
|
|
|
321
323
|
let dialog: StatusDialog | undefined;
|
|
322
324
|
try {
|
|
323
325
|
const chosen = await ctx.ui.custom<string | undefined>((host, theme, _keys, done) => {
|
|
324
|
-
dialog = new StatusDialog(host, theme, service, done, selected, options.title);
|
|
326
|
+
dialog = new StatusDialog(host, theme, service, done, selected, options.title, undefined, options.nerdFontIcons);
|
|
325
327
|
dialog.startRefresh();
|
|
326
328
|
return dialog;
|
|
327
329
|
}, DIALOG_OPTIONS);
|
|
@@ -340,9 +342,10 @@ export async function showAgentStatus(
|
|
|
340
342
|
ctx: ExtensionCommandContext,
|
|
341
343
|
service: ThreadService,
|
|
342
344
|
inspect?: (path: string) => Promise<void>,
|
|
345
|
+
nerdFontIcons = false,
|
|
343
346
|
): Promise<void> {
|
|
344
347
|
if (!canOpenDialog(ctx)) return;
|
|
345
|
-
await showAgentDialog(ctx, service, { inspect });
|
|
348
|
+
await showAgentDialog(ctx, service, { inspect, nerdFontIcons });
|
|
346
349
|
}
|
|
347
350
|
|
|
348
351
|
/** Root-owned navigation state. Opening and closing never changes the executing session. */
|
|
@@ -363,7 +366,7 @@ export class AgentNavigationController {
|
|
|
363
366
|
this.session = undefined;
|
|
364
367
|
}
|
|
365
368
|
|
|
366
|
-
open(ctx: ExtensionContext, service: ThreadService, selectedPath?: string): Promise<void> {
|
|
369
|
+
open(ctx: ExtensionContext, service: ThreadService, selectedPath?: string, nerdFontIcons = false): Promise<void> {
|
|
367
370
|
if (this.opening) return this.opening;
|
|
368
371
|
if (!canOpenDialog(ctx)) return Promise.resolve();
|
|
369
372
|
if (selectedPath) this.tree.selectedPath = selectedPath;
|
|
@@ -423,13 +426,7 @@ export class AgentNavigationController {
|
|
|
423
426
|
{ selectedId: "No" },
|
|
424
427
|
)) === "Yes";
|
|
425
428
|
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
|
-
};
|
|
429
|
+
// Defer until Pi has installed/focused the overlay.
|
|
433
430
|
void Promise.resolve()
|
|
434
431
|
.then(async () => {
|
|
435
432
|
while (generation === this.generation) {
|
|
@@ -449,6 +446,7 @@ export class AgentNavigationController {
|
|
|
449
446
|
fullscreen: true,
|
|
450
447
|
actions: (path) => finish({ kind: "actions", path }),
|
|
451
448
|
},
|
|
449
|
+
nerdFontIcons,
|
|
452
450
|
);
|
|
453
451
|
treeDialog.startRefresh();
|
|
454
452
|
return treeDialog;
|
|
@@ -466,7 +464,7 @@ export class AgentNavigationController {
|
|
|
466
464
|
}
|
|
467
465
|
const result = await session.mount<"back" | "main">(
|
|
468
466
|
(tui, activeTheme, _keys, finish) =>
|
|
469
|
-
new LiveAgentView(tui, activeTheme, service, chosen.path, viewport!, finish),
|
|
467
|
+
new LiveAgentView(tui, activeTheme, service, chosen.path, viewport!, finish, nerdFontIcons),
|
|
470
468
|
);
|
|
471
469
|
if (result !== "back") break;
|
|
472
470
|
}
|
|
@@ -511,11 +509,12 @@ export async function showAgentTree(
|
|
|
511
509
|
ctx: ExtensionContext,
|
|
512
510
|
service: ThreadService,
|
|
513
511
|
selectedPath?: string,
|
|
512
|
+
nerdFontIcons = false,
|
|
514
513
|
): Promise<void> {
|
|
515
514
|
let navigation = navigationByService.get(service);
|
|
516
515
|
if (!navigation) {
|
|
517
516
|
navigation = new AgentNavigationController();
|
|
518
517
|
navigationByService.set(service, navigation);
|
|
519
518
|
}
|
|
520
|
-
await navigation.open(ctx, service, selectedPath);
|
|
519
|
+
await navigation.open(ctx, service, selectedPath, nerdFontIcons);
|
|
521
520
|
}
|
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,
|
|
@@ -88,12 +89,21 @@ function contrastPill(
|
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
91
|
|
|
92
|
+
/** Invalid/untrusted saved icons never reach the terminal. Names remain readable. */
|
|
93
|
+
export function agentTypeLabel(type: string, icon?: string, nerdFontIcons = false): string {
|
|
94
|
+
const prefix = nerdFontIcons && typeof icon === "string" && /^\p{Co}$/u.test(icon)
|
|
95
|
+
? `${icon} ` : "";
|
|
96
|
+
return `${prefix}${sanitizeText(type)}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
91
99
|
export function agentTypeBadge(
|
|
92
100
|
type: string,
|
|
93
101
|
color: string | undefined,
|
|
94
102
|
theme: AgentBadgeTheme,
|
|
103
|
+
icon?: string,
|
|
104
|
+
nerdFontIcons = false,
|
|
95
105
|
): string {
|
|
96
|
-
return contrastPill(type, color, theme);
|
|
106
|
+
return contrastPill(agentTypeLabel(type, icon, nerdFontIcons), color, theme);
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
function agentPath(
|
|
@@ -169,6 +179,7 @@ export function renderThreads(
|
|
|
169
179
|
threads: ThreadView[],
|
|
170
180
|
width: number,
|
|
171
181
|
theme: AgentBadgeTheme,
|
|
182
|
+
nerdFontIcons = false,
|
|
172
183
|
): string[] {
|
|
173
184
|
const priority = (thread: ThreadView) =>
|
|
174
185
|
thread.state === "starting" || thread.state === "running"
|
|
@@ -192,7 +203,7 @@ export function renderThreads(
|
|
|
192
203
|
: thread.state === "paused"
|
|
193
204
|
? "warning"
|
|
194
205
|
: "accent";
|
|
195
|
-
const badge = agentTypeBadge(thread.type, thread.color, theme);
|
|
206
|
+
const badge = agentTypeBadge(thread.type, thread.color, theme, thread.icon, nerdFontIcons);
|
|
196
207
|
const path = agentPath(thread.path, thread.color, theme);
|
|
197
208
|
const state = theme.fg(stateColor, `[${sanitizeText(thread.state)}]`);
|
|
198
209
|
const left = `${badge} ${path} ${state} ${sanitizeText(thread.status || thread.task)}`;
|
|
@@ -219,6 +230,32 @@ export function renderThreads(
|
|
|
219
230
|
const WIDGET_ROOT = "/root";
|
|
220
231
|
const MAX_WIDGET_LINES = 12;
|
|
221
232
|
const AGENT_WIDGET_PLACEMENT = { placement: "aboveEditor" as const };
|
|
233
|
+
const AGENT_BROWSER_HINT = "Press ← to open subagent browser";
|
|
234
|
+
|
|
235
|
+
interface AgentWidgetRenderOptions {
|
|
236
|
+
/** RPC widgets cannot open a terminal browser. */
|
|
237
|
+
showBrowserHint?: boolean;
|
|
238
|
+
nerdFontIcons?: boolean;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function agentWidgetStatus(
|
|
242
|
+
running: number,
|
|
243
|
+
omitted: number,
|
|
244
|
+
width: number,
|
|
245
|
+
theme: Pick<Theme, "fg">,
|
|
246
|
+
showBrowserHint: boolean,
|
|
247
|
+
): string {
|
|
248
|
+
const details = [
|
|
249
|
+
omitted > 0 ? `+${omitted} more agents` : "",
|
|
250
|
+
showBrowserHint ? AGENT_BROWSER_HINT : "",
|
|
251
|
+
].filter(Boolean);
|
|
252
|
+
return truncateToWidth(
|
|
253
|
+
theme.fg("accent", `${running} running`) +
|
|
254
|
+
(details.length ? theme.fg("muted", ` · ${details.join(" · ")}`) : ""),
|
|
255
|
+
width,
|
|
256
|
+
"",
|
|
257
|
+
);
|
|
258
|
+
}
|
|
222
259
|
|
|
223
260
|
function statePriority(state: ThreadView["state"] | undefined): number {
|
|
224
261
|
if (state === "starting" || state === "running") return 0;
|
|
@@ -316,9 +353,10 @@ function agentLine(
|
|
|
316
353
|
row: StatusRow,
|
|
317
354
|
width: number,
|
|
318
355
|
theme: AgentBadgeTheme,
|
|
356
|
+
nerdFontIcons: boolean,
|
|
319
357
|
): string {
|
|
320
358
|
const thread = row.thread!;
|
|
321
|
-
const left = `${row.prefix}${agentTypeBadge(thread.type, thread.color, theme)} ${agentPath(thread.path, thread.color, theme)} ${theme.fg(agentStateColor(thread.state), `[${sanitizeText(thread.state)}]`)} ${sanitizeText(thread.task)}`;
|
|
359
|
+
const left = `${row.prefix}${agentTypeBadge(thread.type, thread.color, theme, thread.icon, nerdFontIcons)} ${agentPath(thread.path, thread.color, theme)} ${theme.fg(agentStateColor(thread.state), `[${sanitizeText(thread.state)}]`)} ${sanitizeText(thread.task)}`;
|
|
322
360
|
return fitLine(left, theme.fg("muted", threadMetrics(thread)), width);
|
|
323
361
|
}
|
|
324
362
|
|
|
@@ -367,7 +405,8 @@ function takeWidgetRows(rows: StatusRow[], budget: number): StatusRow[] {
|
|
|
367
405
|
.sort(
|
|
368
406
|
(a, b) =>
|
|
369
407
|
statePriority(a.row.thread!.state) -
|
|
370
|
-
statePriority(b.row.thread!.state) ||
|
|
408
|
+
statePriority(b.row.thread!.state) ||
|
|
409
|
+
b.row.thread!.createdAt - a.row.thread!.createdAt || a.index - b.index,
|
|
371
410
|
);
|
|
372
411
|
const chosen = new Set<number>();
|
|
373
412
|
let used = 0;
|
|
@@ -402,6 +441,7 @@ export function renderAgentTree(
|
|
|
402
441
|
threads: ThreadView[],
|
|
403
442
|
width: number,
|
|
404
443
|
theme: AgentBadgeTheme,
|
|
444
|
+
{ showBrowserHint = true, nerdFontIcons = false }: AgentWidgetRenderOptions = {},
|
|
405
445
|
): string[] {
|
|
406
446
|
const columns = Math.max(0, width);
|
|
407
447
|
const rows = buildStatusTree(
|
|
@@ -421,53 +461,91 @@ export function renderAgentTree(
|
|
|
421
461
|
theme.fg("muted", `${live} live · ${paused} paused`),
|
|
422
462
|
columns,
|
|
423
463
|
);
|
|
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
|
-
}
|
|
464
|
+
// Reserve the last line for status and browser entry, even with no omissions.
|
|
465
|
+
const visible = takeWidgetRows(rows, MAX_WIDGET_LINES - 2);
|
|
466
|
+
const omitted = agents.length - visible.filter((row) => row.thread).length;
|
|
433
467
|
const lines = [heading];
|
|
434
468
|
for (const row of visible) {
|
|
435
469
|
if (!row.thread) {
|
|
436
470
|
lines.push(placeholderLine(row, columns, theme));
|
|
437
471
|
continue;
|
|
438
472
|
}
|
|
439
|
-
lines.push(agentLine(row, columns, theme));
|
|
473
|
+
lines.push(agentLine(row, columns, theme, nerdFontIcons));
|
|
440
474
|
lines.push(activityLine(row, columns, theme));
|
|
441
475
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
476
|
+
lines.push(agentWidgetStatus(live, omitted, columns, theme, showBrowserHint));
|
|
477
|
+
return lines;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** One-line counts for real agents; starting agents count as running, including tokens. */
|
|
481
|
+
export function renderAgentSummary(
|
|
482
|
+
threads: ThreadView[],
|
|
483
|
+
width: number,
|
|
484
|
+
theme: Pick<Theme, "fg">,
|
|
485
|
+
{ showBrowserHint = true }: AgentWidgetRenderOptions = {},
|
|
486
|
+
): string[] {
|
|
487
|
+
const agents = new Map<string, ThreadView>();
|
|
488
|
+
for (const thread of threads) {
|
|
489
|
+
if (thread?.path && thread.path !== WIDGET_ROOT && !agents.has(thread.path))
|
|
490
|
+
agents.set(thread.path, thread);
|
|
450
491
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
492
|
+
if (!agents.size) return [];
|
|
493
|
+
|
|
494
|
+
const counts: Record<Exclude<ThreadView["state"], "starting">, number> = {
|
|
495
|
+
running: 0,
|
|
496
|
+
stopped: 0,
|
|
497
|
+
failed: 0,
|
|
498
|
+
paused: 0,
|
|
499
|
+
completed: 0,
|
|
500
|
+
};
|
|
501
|
+
let input = 0;
|
|
502
|
+
let output = 0;
|
|
503
|
+
for (const thread of agents.values()) {
|
|
504
|
+
counts[thread.state === "starting" ? "running" : thread.state] += 1;
|
|
505
|
+
if (isLive(thread)) {
|
|
506
|
+
input += metricCount(thread.inputTokens);
|
|
507
|
+
output += metricCount(thread.outputTokens);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const statuses: [keyof typeof counts, ThemeColor][] = [
|
|
511
|
+
["running", "accent"],
|
|
512
|
+
["stopped", "muted"],
|
|
513
|
+
["failed", "error"],
|
|
514
|
+
["paused", "warning"],
|
|
515
|
+
["completed", "success"],
|
|
516
|
+
];
|
|
517
|
+
const left = statuses
|
|
518
|
+
.filter(([state]) => state === "running" || counts[state] > 0)
|
|
519
|
+
.map(([state, color]) => theme.fg(color, `${counts[state]} ${state}`))
|
|
520
|
+
.join(theme.fg("muted", ", "));
|
|
521
|
+
const right = theme.fg("muted", `↑${formatCount(input)} ↓${formatCount(output)}`);
|
|
522
|
+
const columns = Math.max(0, width);
|
|
523
|
+
const lines = [fitLine(left, right, columns)];
|
|
524
|
+
if (showBrowserHint)
|
|
525
|
+
lines.push(truncateToWidth(theme.fg("muted", AGENT_BROWSER_HINT), columns, ""));
|
|
454
526
|
return lines;
|
|
455
527
|
}
|
|
456
528
|
|
|
457
529
|
export function updateWidget(
|
|
458
530
|
ctx: ExtensionContext,
|
|
459
531
|
threads: ThreadView[],
|
|
532
|
+
mode: WidgetMode = "full",
|
|
533
|
+
nerdFontIcons = false,
|
|
534
|
+
rootTurnEnded = false,
|
|
460
535
|
): void {
|
|
461
536
|
if (!ctx.hasUI) return;
|
|
462
537
|
if (!threads.some((thread) => thread.path !== "/root")) {
|
|
463
538
|
ctx.ui.setWidget("pi-subagent", undefined, AGENT_WIDGET_PLACEMENT);
|
|
464
539
|
return;
|
|
465
540
|
}
|
|
541
|
+
// Retain the tree while either the main turn or any subagent is still active.
|
|
542
|
+
const settled = rootTurnEnded && !threads.some(isLive);
|
|
543
|
+
const render = mode === "minimal" || settled ? renderAgentSummary : renderAgentTree;
|
|
466
544
|
// RPC hosts accept string widgets only; a component factory is ignored.
|
|
467
545
|
if (ctx.mode === "rpc") {
|
|
468
546
|
ctx.ui.setWidget(
|
|
469
547
|
"pi-subagent",
|
|
470
|
-
|
|
548
|
+
render(threads, 80, ctx.ui.theme, { showBrowserHint: false, nerdFontIcons }),
|
|
471
549
|
AGENT_WIDGET_PLACEMENT,
|
|
472
550
|
);
|
|
473
551
|
return;
|
|
@@ -477,12 +555,15 @@ export function updateWidget(
|
|
|
477
555
|
"pi-subagent",
|
|
478
556
|
(tui) => {
|
|
479
557
|
let timer: ReturnType<typeof setInterval> | undefined;
|
|
480
|
-
if (snapshot.some(isLive)) {
|
|
558
|
+
if (mode === "full" && snapshot.some(isLive)) {
|
|
481
559
|
timer = setInterval(() => tui.requestRender(), 1000);
|
|
482
560
|
timer.unref();
|
|
483
561
|
}
|
|
484
562
|
return {
|
|
485
|
-
render: (width) =>
|
|
563
|
+
render: (width) => render(snapshot, width, ctx.ui.theme, {
|
|
564
|
+
showBrowserHint: !settled,
|
|
565
|
+
nerdFontIcons,
|
|
566
|
+
}),
|
|
486
567
|
invalidate: () => {},
|
|
487
568
|
dispose: () => {
|
|
488
569
|
if (timer) clearInterval(timer);
|
|
@@ -919,6 +1000,7 @@ const EDIT_MENU_ACTIONS = [
|
|
|
919
1000
|
"tools.allow",
|
|
920
1001
|
"tools.block",
|
|
921
1002
|
"color",
|
|
1003
|
+
"icon",
|
|
922
1004
|
"systemPrompt",
|
|
923
1005
|
"Save scope",
|
|
924
1006
|
"Source",
|
|
@@ -939,6 +1021,7 @@ const EDIT_FIELD_LABELS: Record<EditMenuAction, string> = {
|
|
|
939
1021
|
"tools.allow": "Allowed tools",
|
|
940
1022
|
"tools.block": "Blocked tools",
|
|
941
1023
|
color: "Color",
|
|
1024
|
+
icon: "[labs] Icon",
|
|
942
1025
|
systemPrompt: "System prompt",
|
|
943
1026
|
"Save scope": "Save scope",
|
|
944
1027
|
Source: "Source (read-only)",
|
|
@@ -960,6 +1043,7 @@ const EDIT_FIELD_HELP: Record<EditMenuAction, string> = {
|
|
|
960
1043
|
"Unset uses default policy; an empty list explicitly allows no tools.",
|
|
961
1044
|
"tools.block": "Exact tool names to remove from the allowed set.",
|
|
962
1045
|
color: "Thread widget color with live preview.",
|
|
1046
|
+
icon: "Paste a single Nerd Font glyph from nerdfonts.com/cheat-sheet (not its name or codepoint).\nLeave blank to remove. Display requires [labs] Nerd Font icons in settings and a Nerd Font in your terminal.",
|
|
963
1047
|
systemPrompt: "Edit the Markdown prompt body in a multiline dialog.",
|
|
964
1048
|
"Save scope":
|
|
965
1049
|
"Project definitions override global definitions with the same name.",
|
|
@@ -1026,6 +1110,8 @@ function editMenuLabel(action: EditMenuAction, draft: AgentType): string {
|
|
|
1026
1110
|
return `tools.block: ${sanitizeText(toolListMenuValue(draft.tools?.block))}`;
|
|
1027
1111
|
case "color":
|
|
1028
1112
|
return `color: ${sanitizeText(draft.color ?? "Default (inherit)")}`;
|
|
1113
|
+
case "icon":
|
|
1114
|
+
return `icon: ${draft.icon ? "Configured" : "None"}`;
|
|
1029
1115
|
case "systemPrompt":
|
|
1030
1116
|
return `systemPrompt: ${draft.systemPrompt.split("\n").length} lines · ${draft.systemPrompt.length} characters`;
|
|
1031
1117
|
default:
|
|
@@ -1036,14 +1122,16 @@ function editMenuLabel(action: EditMenuAction, draft: AgentType): string {
|
|
|
1036
1122
|
export async function editAgentTypes(
|
|
1037
1123
|
ctx: ExtensionCommandContext,
|
|
1038
1124
|
store: ConfigStore,
|
|
1125
|
+
nerdFontIcons = false,
|
|
1039
1126
|
): Promise<void> {
|
|
1040
1127
|
if (!canOpenDialog(ctx)) return;
|
|
1041
|
-
await withDialogSession(ctx, (scoped) => editAgentTypesDialog(scoped, store));
|
|
1128
|
+
await withDialogSession(ctx, (scoped) => editAgentTypesDialog(scoped, store, nerdFontIcons));
|
|
1042
1129
|
}
|
|
1043
1130
|
|
|
1044
1131
|
async function editAgentTypesDialog(
|
|
1045
1132
|
ctx: ExtensionCommandContext,
|
|
1046
1133
|
store: ConfigStore,
|
|
1134
|
+
nerdFontIcons: boolean,
|
|
1047
1135
|
): Promise<void> {
|
|
1048
1136
|
while (true) {
|
|
1049
1137
|
const types = store.list();
|
|
@@ -1057,7 +1145,7 @@ async function editAgentTypesDialog(
|
|
|
1057
1145
|
...types.map((type) => ({
|
|
1058
1146
|
id: type.name,
|
|
1059
1147
|
label: type.name,
|
|
1060
|
-
renderLabel: (label: string, theme: Theme) => agentTypeBadge(label, type.color, theme),
|
|
1148
|
+
renderLabel: (label: string, theme: Theme) => agentTypeBadge(label, type.color, theme, type.icon, nerdFontIcons),
|
|
1061
1149
|
value: type.description,
|
|
1062
1150
|
help: `${type.source ?? "user"} · ${type.filePath ?? ""}`,
|
|
1063
1151
|
})),
|
|
@@ -1095,9 +1183,11 @@ async function editAgentTypesDialog(
|
|
|
1095
1183
|
? saveScope === "user"
|
|
1096
1184
|
? "Global"
|
|
1097
1185
|
: "Trusted project"
|
|
1098
|
-
:
|
|
1099
|
-
?
|
|
1100
|
-
:
|
|
1186
|
+
: action === "icon" && nerdFontIcons && draft.icon
|
|
1187
|
+
? draft.icon
|
|
1188
|
+
: separator >= 0
|
|
1189
|
+
? decorated.slice(separator + 2)
|
|
1190
|
+
: "",
|
|
1101
1191
|
help:
|
|
1102
1192
|
action === "Source"
|
|
1103
1193
|
? (original?.filePath ??
|
|
@@ -1172,6 +1262,12 @@ async function editAgentTypesDialog(
|
|
|
1172
1262
|
value === prefill || value === prefill.trim()
|
|
1173
1263
|
? originalValue
|
|
1174
1264
|
: value;
|
|
1265
|
+
} else if (field === "icon") {
|
|
1266
|
+
const value = await dialogEditor(ctx, "Agent icon (Nerd Font glyph; blank to remove)", candidate.icon ?? "");
|
|
1267
|
+
if (value === undefined) continue;
|
|
1268
|
+
const icon = value.trim();
|
|
1269
|
+
if (!icon) delete candidate.icon;
|
|
1270
|
+
else candidate.icon = icon;
|
|
1175
1271
|
} else if (field === "models") {
|
|
1176
1272
|
const value = await editModelPreferences(
|
|
1177
1273
|
ctx,
|