@narumitw/pi-herdr 0.4.0 → 0.5.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/CHANGELOG.md +17 -0
- package/README.md +24 -48
- package/dist/chunks/{herdr-menu-IUPFF5YK.ts → herdr-menu-H74GELLE.ts} +3 -2
- package/dist/chunks/herdr-menu-H74GELLE.ts.map +7 -0
- package/dist/index.ts +54 -51
- package/dist/index.ts.map +2 -2
- package/package.json +4 -8
- package/src/herdr-menu.ts +2 -1
- package/src/herdr-observer.ts +31 -34
- package/src/herdr-protocol.ts +20 -7
- package/src/herdr-settings-controller.ts +1 -0
- package/src/herdr-widget.ts +17 -30
- package/dist/chunks/herdr-menu-IUPFF5YK.ts.map +0 -7
- package/skills/hc/SKILL.md +0 -22
- package/skills/herdr/SKILL.md +0 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @narumitw/pi-herdr
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 97fdd84: Show sibling agents across all workspaces in the connected Herdr session, with each workspace's label and live status, name, and topology updates. Keep the widget updating during sustained events with bounded read discards and immediate catch-up.
|
|
8
|
+
- 2735f56: Remove the bundled `herdr` and `hc` bootstrap skills. Install operating skills separately if needed; this package no longer provides `/skill:herdr` or `/skill:hc`. Keep lifecycle reporting, pane metadata, the agent widget, and `/herdr` unchanged.
|
|
9
|
+
|
|
10
|
+
## 0.4.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- cf7b63d: Put editor widget names and short current count/state summaries in their divider lines. Remove duplicate body titles while retaining safety text, detail rows, privacy modes, and standalone RPC/tool output. In fullscreen Pi, click anywhere in a widget to collapse it to one named line, then click that line to restore the latest content. Preserve independent, session-local disclosure through updates without taking editor focus, changing domain data, or stopping background work. Existing owner controls provide keyboard restoration; regular-mode mouse input remains terminal-owned.
|
|
15
|
+
|
|
16
|
+
The Kit minor release supplies the named widget state and publisher disclosure APIs. Changesets raises all adopting consumers' Kit dependency floors in the same Version PR. Publish and verify the exact Kit artifact before its consumers.
|
|
17
|
+
- Updated dependencies [cf7b63d]
|
|
18
|
+
- @narumitw/pi-tui-kit@0.70.0
|
|
19
|
+
|
|
3
20
|
## 0.4.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -2,19 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@narumitw/pi-herdr) [](https://pi.dev) [](./LICENSE)
|
|
4
4
|
|
|
5
|
-
Connect Pi's interactive lifecycle to Herdr
|
|
5
|
+
Connect Pi's interactive lifecycle to Herdr, publish pane metadata, and show sibling agent status.
|
|
6
6
|
|
|
7
7
|
## ✨ Features
|
|
8
8
|
|
|
9
9
|
- Reports Pi session identity and `working`, `blocked`, and `idle` lifecycle states to the current Herdr pane.
|
|
10
10
|
- Publishes bounded `model`, `provider`, `thinking`, `session`, and `context_usage` tokens for Herdr sidebar rows.
|
|
11
|
-
- Shows recognized sibling agents
|
|
11
|
+
- Shows recognized sibling agents across all workspaces in the connected Herdr session in a passive widget above Pi's editor, with a saved visibility toggle in `/herdr`.
|
|
12
12
|
- Refreshes the widget on Herdr pane, workspace-name, and agent-status updates without polling the CLI.
|
|
13
13
|
- Coalesces rapid state changes and retries short-lived local socket failures without interrupting Pi.
|
|
14
14
|
- Derives blocked state from Pi's public `ui_prompt_start` and `ui_prompt_end` lifecycle events.
|
|
15
|
-
- Bundles thin `herdr` and `hc` bootstrap skills for explicit inspection and control requests.
|
|
16
|
-
- Loads version-matched operating guidance from `herdr --skill` or `hc --skill`.
|
|
17
|
-
- Keeps extension and skill installation in one Pi package.
|
|
18
15
|
|
|
19
16
|
## 📦 Install
|
|
20
17
|
|
|
@@ -39,41 +36,23 @@ pi --no-extensions -e ./packages/pi-herdr
|
|
|
39
36
|
|
|
40
37
|
An unbuilt local checkout has no generated entrypoint and cannot be loaded by package directory.
|
|
41
38
|
|
|
42
|
-
Pi extensions
|
|
43
|
-
Install only trusted packages, and review the source
|
|
39
|
+
Pi extensions run with your user permissions.
|
|
40
|
+
Install only trusted packages, and review the source before loading this package.
|
|
44
41
|
|
|
45
42
|
## 🚀 Quick start
|
|
46
43
|
|
|
47
44
|
Start Pi inside a Herdr-managed pane after installing the package.
|
|
48
45
|
The extension activates automatically when `HERDR_ENV=1`, `HERDR_SOCKET_PATH`, and `HERDR_PANE_ID` are present.
|
|
49
|
-
When the
|
|
50
|
-
Ask Pi to use Herdr, or invoke `/skill:herdr`, when you want it to inspect or control the current Herdr session.
|
|
51
|
-
Before the first control command, the bootstrap loads `herdr --skill` once and reuses those instructions while they remain in the current context.
|
|
52
|
-
For Herdr Core terminals, invoke `/skill:hc` instead; it loads `hc --skill` without requiring a Herdr-managed pane.
|
|
46
|
+
When any workspace in the connected Herdr session contains another recognized agent, Pi shows its state and workspace in a widget above the editor.
|
|
53
47
|
|
|
54
|
-
If the standalone integration
|
|
48
|
+
If the standalone integration is already installed, remove it after installing this package to avoid duplicate state reports:
|
|
55
49
|
|
|
56
50
|
```bash
|
|
57
51
|
rm ~/.pi/agent/extensions/herdr-agent-state.ts
|
|
58
|
-
rm -rf ~/.agents/skills/herdr
|
|
59
52
|
```
|
|
60
53
|
|
|
61
54
|
Run `/reload` or restart Pi after changing the installed resources.
|
|
62
55
|
|
|
63
|
-
## 🧠 Skills
|
|
64
|
-
|
|
65
|
-
The bundled skills load CLI-owned guidance once and reuse it while it remains in the current context:
|
|
66
|
-
|
|
67
|
-
- [`herdr`](./skills/herdr/SKILL.md), invoked with `/skill:herdr`, loads `herdr --skill` for legacy Herdr panes and requires `HERDR_ENV=1`.
|
|
68
|
-
- [`hc`](./skills/hc/SKILL.md), invoked with `/skill:hc`, loads `hc --skill` for Herdr Core persistent terminals and agents; it requires neither `HERDR_ENV=1` nor `HC_TERMINAL_ID`.
|
|
69
|
-
|
|
70
|
-
Both skills apply only after an explicit request for their CLI, not merely because a task could use background work or delegation.
|
|
71
|
-
The CLIs are separate; neither skill substitutes the other CLI when its command fails.
|
|
72
|
-
|
|
73
|
-
The `herdr` skill treats panes created for background work as temporary and attempts to close them after collecting the required output.
|
|
74
|
-
Ask Pi explicitly to keep a pane open after the task when you want to inspect or use it later.
|
|
75
|
-
Automatic cleanup runs only when the installed Herdr guidance provides a conditional close that atomically confirms the recorded pane ownership and acceptable agent or shell state; otherwise Pi leaves the pane open and reports the limitation.
|
|
76
|
-
|
|
77
56
|
## 💬 Commands
|
|
78
57
|
|
|
79
58
|
`/herdr` opens a menu to toggle the agent widget and view status or help, inspired by `/tool`.
|
|
@@ -146,7 +125,7 @@ rows = [
|
|
|
146
125
|
|
|
147
126
|
## 🐑 Agent widget
|
|
148
127
|
|
|
149
|
-
The widget lists
|
|
128
|
+
The widget lists recognized agents across all workspaces in the connected Herdr session and excludes the pane running the current Pi session.
|
|
150
129
|
Each row presents state, agent, pane, and workspace in that order, using theme hierarchy instead of repeating field labels.
|
|
151
130
|
State icons follow Herdr's distinct static symbols: `×` blocked, `◐` working, `✓` done, `○` idle, and `·` unknown.
|
|
152
131
|
Pi theme roles map blocked to `error`, working to `warning`, done to `accent`, idle to `success`, and unknown to `dim` without hard-coded terminal colors.
|
|
@@ -156,9 +135,14 @@ Terminal titles are not used as agent identity.
|
|
|
156
135
|
The widget orders agents by `blocked`, `done`, `working`, `idle`, and `unknown`, shows at most five rows, and reports any remaining count.
|
|
157
136
|
A state label published through Herdr metadata can replace the raw state name.
|
|
158
137
|
Herdr's public pane responses do not expose the blocked prompt message, so the widget cannot show that reason.
|
|
159
|
-
The widget
|
|
160
|
-
|
|
161
|
-
|
|
138
|
+
The widget does not focus panes, read terminal output, send prompts, or mark a background `done` state as seen.
|
|
139
|
+
Its separator is named **Herdr**. In fullscreen TUI mode, click anywhere in the widget, including blank columns, to collapse it to that separator. Click the separator to restore the latest agents without moving keyboard focus.
|
|
140
|
+
Opening `/herdr` in TUI mode also restores disclosure when the widget is enabled, without changing or saving the enable setting.
|
|
141
|
+
Disclosure survives updates, temporary absence, and host remounts; session start or restarting the observer resets it. Collapse does not change Herdr data, reporting, subscriptions, or saved settings.
|
|
142
|
+
The extension discovers the current pane, session-wide pane list, workspace labels, and agent names, opens pane-scoped status subscriptions plus pane and workspace subscriptions, and then reloads those identities.
|
|
143
|
+
Events trigger serialized, coalesced reads rather than replacing current state with event payloads.
|
|
144
|
+
If events arrive during reads, the extension discards up to two consecutive reads. On the third invalidated read, it publishes that complete snapshot and immediately reads again, so sustained events cannot prevent updates.
|
|
145
|
+
Snapshots can briefly lag newer events; changes to the current pane or recognized-agent subscription set are reconciled before publication.
|
|
162
146
|
Agent names, workspace labels, and cleared presentation fields update from these authoritative reads.
|
|
163
147
|
Changes to the current pane, workspace, or recognized-agent set rebuild the pane-scoped subscriptions without consuming the bounded failure retry.
|
|
164
148
|
Unexpected disconnection or `events_lost` clears the widget before one bounded reconnect attempt, and a second failure leaves it hidden until the next Pi session or `/reload`.
|
|
@@ -169,31 +153,24 @@ Session replacement and shutdown abort the subscription, pending reads, reconnec
|
|
|
169
153
|
The extension connects only to the Unix socket or Windows named pipe provided by `HERDR_SOCKET_PATH`.
|
|
170
154
|
Lifecycle reporting sends the current Herdr pane ID, Pi session path or ID, lifecycle state, session start reason, and blocked label to that endpoint.
|
|
171
155
|
Metadata reporting sends the current Herdr pane ID plus only the selected model ID, provider ID, effective Thinking level, explicit Pi session name, and rounded context-usage percentage.
|
|
172
|
-
For the widget, it reads the canonical current pane
|
|
173
|
-
|
|
156
|
+
For the widget, it reads the canonical current pane and session-wide pane, workspace, and agent lists, then subscribes to pane creation, updates, closure, movement, exit, agent detection, agent-status changes, and workspace creation, closure, and renames.
|
|
157
|
+
Agent names are joined only to matching pane and workspace identities in the session-wide pane list.
|
|
174
158
|
Widget fields can include workspace, tab, pane, terminal, agent, display, name, title, label, state-label, and lifecycle identifiers supplied by Herdr.
|
|
175
|
-
|
|
176
|
-
The extension
|
|
159
|
+
Events from every workspace in the connected Herdr session can refresh the widget.
|
|
160
|
+
The extension strips terminal controls at the display boundary and never reads sibling terminal output for the widget.
|
|
177
161
|
The package does not authenticate the endpoint, so trust the environment that launches Pi and controls these variables.
|
|
178
162
|
|
|
179
|
-
The bundled skills load operating guidance from the local CLI only after an explicit request for Herdr or Herdr Core.
|
|
180
|
-
The returned CLI-owned instructions can direct Pi to inspect terminals, create panes or persistent terminals, start agents, send input, and run local or remote commands.
|
|
181
|
-
Those commands execute with the same user permissions as Pi and can affect live terminal sessions.
|
|
182
|
-
Both bootstraps stop when their CLI is unavailable or its `--skill` command fails; the `herdr` bootstrap also stops when `HERDR_ENV` is not `1`.
|
|
183
|
-
Command recipes, approval handling, and other operating safety rules come from the selected CLI's installed version instead of being duplicated by this package.
|
|
184
|
-
|
|
185
163
|
## 🚧 Limitations
|
|
186
164
|
|
|
187
165
|
- Lifecycle reporting, metadata reporting, and the agent widget are disabled in RPC, JSON, and print modes.
|
|
188
|
-
- The widget has no settings for placement, workspace scope, or row count.
|
|
166
|
+
- The widget has no settings for placement, workspace scope, or row count; it does not discover other Herdr sessions or saved machines.
|
|
167
|
+
- After loading an updated build, a terminal operator should check cross-workspace labels, regular/fullscreen appearance, and mouse disclosure; automated tests cannot verify physical terminal behavior.
|
|
189
168
|
- The widget cannot show blocked prompt text because Herdr does not expose it through public pane responses.
|
|
190
|
-
- The widget requires compatible pane
|
|
169
|
+
- The widget requires compatible pane and workspace subscriptions; unsupported subscriptions hide the widget without disabling lifecycle or metadata reporting.
|
|
191
170
|
- A pane-label change appears on its next update event or authoritative refresh; an agent rename emits a pane-update event.
|
|
192
171
|
- Integration requires a running compatible Herdr session and valid injected environment variables.
|
|
193
|
-
- Each skill requires its matching CLI with `--skill` support; `hc` does not enable the legacy Herdr lifecycle reports or widget.
|
|
194
172
|
- Socket failures are intentionally silent after the bounded retry.
|
|
195
|
-
-
|
|
196
|
-
- The package does not install, start, update, or configure Herdr or Herdr Core itself.
|
|
173
|
+
- The package does not install, start, update, or configure Herdr itself.
|
|
197
174
|
|
|
198
175
|
## 🗂️ Package layout
|
|
199
176
|
|
|
@@ -204,13 +181,12 @@ packages/pi-herdr/
|
|
|
204
181
|
│ └── herdr-agent-state.ts # Herdr lifecycle integration
|
|
205
182
|
├── dist/ # Generated TypeScript runtime loaded by Pi
|
|
206
183
|
├── scripts/ # Deterministic runtime builder
|
|
207
|
-
├── skills/ # Published herdr and hc bootstraps for CLI-owned guidance
|
|
208
184
|
└── test/ # Behavior and lifecycle coverage
|
|
209
185
|
```
|
|
210
186
|
|
|
211
187
|
## 🔎 Keywords
|
|
212
188
|
|
|
213
|
-
Pi, Herdr,
|
|
189
|
+
Pi, Herdr, terminal multiplexer, coding agents, agent status, lifecycle state, pane metadata.
|
|
214
190
|
|
|
215
191
|
## 📄 License
|
|
216
192
|
|
|
@@ -14,7 +14,7 @@ function createHerdrMenu(options) {
|
|
|
14
14
|
{
|
|
15
15
|
id: "widget",
|
|
16
16
|
label: `Agent widget: ${options.isEnabled() ? "On" : "Off"}`,
|
|
17
|
-
description: "Show or hide
|
|
17
|
+
description: "Show or hide agents across all workspaces above the editor",
|
|
18
18
|
action: "toggle"
|
|
19
19
|
},
|
|
20
20
|
{ id: "status", label: "Status", to: "status" },
|
|
@@ -29,6 +29,7 @@ function createHerdrMenu(options) {
|
|
|
29
29
|
lines: [
|
|
30
30
|
`Agent widget setting: ${options.isEnabled() ? "on" : "off"}`,
|
|
31
31
|
"The widget appears only in TUI mode with recognized sibling agents.",
|
|
32
|
+
"Scope: all workspaces in the connected Herdr session.",
|
|
32
33
|
"Lifecycle and metadata reporting are independent of this setting.",
|
|
33
34
|
`User settings file: ${options.settingsPath}`
|
|
34
35
|
],
|
|
@@ -53,4 +54,4 @@ function createHerdrMenu(options) {
|
|
|
53
54
|
export {
|
|
54
55
|
createHerdrMenu
|
|
55
56
|
};
|
|
56
|
-
//# sourceMappingURL=herdr-menu-
|
|
57
|
+
//# sourceMappingURL=herdr-menu-H74GELLE.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/herdr-menu.ts"],
|
|
4
|
+
"sourcesContent": ["import type { MenuDefinition } from \"@narumitw/pi-tui-kit\";\n\nexport function createHerdrMenu(options: {\n settingsPath: string;\n isEnabled(): boolean;\n toggle(signal: AbortSignal): Promise<boolean>;\n}): MenuDefinition<undefined, \"main\" | \"status\" | \"help\", \"toggle\"> {\n return {\n start: \"main\",\n screens: {\n // One setting stays on the main menu, matching /tool rather than adding a submenu.\n main: () => ({\n kind: \"actions\",\n title: \"Herdr\",\n items: [\n {\n id: \"widget\",\n label: `Agent widget: ${options.isEnabled() ? \"On\" : \"Off\"}`,\n description: \"Show or hide agents across all workspaces above the editor\",\n action: \"toggle\",\n },\n { id: \"status\", label: \"Status\", to: \"status\" },\n { id: \"help\", label: \"Help\", to: \"help\" },\n { id: \"close\", label: \"Close\", close: true },\n ],\n hint: \"close\",\n }),\n status: () => ({\n kind: \"detail\",\n title: \"Herdr Status\",\n lines: [\n `Agent widget setting: ${options.isEnabled() ? \"on\" : \"off\"}`,\n \"The widget appears only in TUI mode with recognized sibling agents.\",\n \"Scope: all workspaces in the connected Herdr session.\",\n \"Lifecycle and metadata reporting are independent of this setting.\",\n `User settings file: ${options.settingsPath}`,\n ],\n hint: \"back\",\n }),\n help: () => ({\n kind: \"detail\",\n title: \"Herdr Help\",\n lines: [\n \"Toggle Agent widget from /herdr. Changes are saved immediately; closing does not undo them.\",\n \"Manual pi-herdr.json changes apply after /reload or the next session start.\",\n \"The widget defaults to on. Project overrides are not read.\",\n ],\n hint: \"back\",\n }),\n },\n actions: {\n toggle: async ({ signal }) => ((await options.toggle(signal)) ? { kind: \"stay\" } : { kind: \"rejected\" }),\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAEO,SAAS,gBAAgB,SAIoC;AAClE,SAAO;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA;AAAA,MAEP,MAAM,OAAO;AAAA,QACX,MAAM;AAAA,QACN,OAAO;AAAA,QACP,OAAO;AAAA,UACL;AAAA,YACE,IAAI;AAAA,YACJ,OAAO,iBAAiB,QAAQ,UAAU,IAAI,OAAO,KAAK;AAAA,YAC1D,aAAa;AAAA,YACb,QAAQ;AAAA,UACV;AAAA,UACA,EAAE,IAAI,UAAU,OAAO,UAAU,IAAI,SAAS;AAAA,UAC9C,EAAE,IAAI,QAAQ,OAAO,QAAQ,IAAI,OAAO;AAAA,UACxC,EAAE,IAAI,SAAS,OAAO,SAAS,OAAO,KAAK;AAAA,QAC7C;AAAA,QACA,MAAM;AAAA,MACR;AAAA,MACA,QAAQ,OAAO;AAAA,QACb,MAAM;AAAA,QACN,OAAO;AAAA,QACP,OAAO;AAAA,UACL,yBAAyB,QAAQ,UAAU,IAAI,OAAO,KAAK;AAAA,UAC3D;AAAA,UACA;AAAA,UACA;AAAA,UACA,uBAAuB,QAAQ,YAAY;AAAA,QAC7C;AAAA,QACA,MAAM;AAAA,MACR;AAAA,MACA,MAAM,OAAO;AAAA,QACX,MAAM;AAAA,QACN,OAAO;AAAA,QACP,OAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QACA,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,QAAQ,OAAO,EAAE,OAAO,MAAQ,MAAM,QAAQ,OAAO,MAAM,IAAK,EAAE,MAAM,OAAO,IAAI,EAAE,MAAM,WAAW;AAAA,IACxG;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.ts
CHANGED
|
@@ -300,6 +300,8 @@ import { createEditorStatusPublisher } from "@narumitw/pi-tui-kit/editor-status-
|
|
|
300
300
|
// src/herdr-protocol.ts
|
|
301
301
|
var HERDR_AGENT_STATUSES = ["idle", "working", "blocked", "done", "unknown"];
|
|
302
302
|
var HERDR_WIDGET_TOPOLOGY_SUBSCRIPTIONS = [
|
|
303
|
+
{ type: "workspace.created" },
|
|
304
|
+
{ type: "workspace.closed" },
|
|
303
305
|
{ type: "pane.created" },
|
|
304
306
|
{ type: "pane.updated" },
|
|
305
307
|
{ type: "workspace.renamed" },
|
|
@@ -387,19 +389,30 @@ function parseAgentListResult(value) {
|
|
|
387
389
|
return pane ? [pane] : [];
|
|
388
390
|
});
|
|
389
391
|
}
|
|
390
|
-
function
|
|
391
|
-
if (!isRecord2(value) || value.type !== "
|
|
392
|
-
throw new Error("Herdr returned an invalid workspace response");
|
|
392
|
+
function parseWorkspaceListResult(value) {
|
|
393
|
+
if (!isRecord2(value) || value.type !== "workspace_list" || !Array.isArray(value.workspaces)) {
|
|
394
|
+
throw new Error("Herdr returned an invalid workspace-list response");
|
|
393
395
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
396
|
+
return value.workspaces.map((workspace) => {
|
|
397
|
+
if (!isRecord2(workspace)) throw new Error("Herdr returned an invalid workspace");
|
|
398
|
+
const workspaceId = requiredString(workspace.workspace_id);
|
|
399
|
+
if (!workspaceId) throw new Error("Herdr returned an invalid workspace identity");
|
|
400
|
+
return { workspaceId, label: optionalString(workspace.label) };
|
|
401
|
+
});
|
|
397
402
|
}
|
|
398
403
|
function parseHerdrPaneEvent(value) {
|
|
399
404
|
if (!isRecord2(value) || typeof value.event !== "string" || !isRecord2(value.data)) {
|
|
400
405
|
return void 0;
|
|
401
406
|
}
|
|
402
407
|
const data = value.data;
|
|
408
|
+
if (value.event === "workspace_created") {
|
|
409
|
+
const workspaceId = isRecord2(data.workspace) ? requiredString(data.workspace.workspace_id) : void 0;
|
|
410
|
+
return workspaceId ? { type: "workspace_created", workspaceId } : void 0;
|
|
411
|
+
}
|
|
412
|
+
if (value.event === "workspace_closed") {
|
|
413
|
+
const workspaceId = requiredString(data.workspace_id);
|
|
414
|
+
return workspaceId ? { type: "workspace_closed", workspaceId } : void 0;
|
|
415
|
+
}
|
|
403
416
|
if (value.event === "workspace_renamed") {
|
|
404
417
|
const workspaceId = requiredString(data.workspace_id);
|
|
405
418
|
if (!workspaceId || typeof data.label !== "string") return void 0;
|
|
@@ -523,32 +536,21 @@ function immutableSnapshot(rows) {
|
|
|
523
536
|
}
|
|
524
537
|
var HerdrWidgetModel = class {
|
|
525
538
|
currentPaneId;
|
|
526
|
-
|
|
527
|
-
workspace;
|
|
539
|
+
workspaces = /* @__PURE__ */ new Map();
|
|
528
540
|
panes = /* @__PURE__ */ new Map();
|
|
529
|
-
reset(currentPane, panes,
|
|
541
|
+
reset(currentPane, panes, workspaces = []) {
|
|
530
542
|
this.currentPaneId = currentPane.paneId;
|
|
531
|
-
this.
|
|
532
|
-
this.workspace = { ...workspace };
|
|
543
|
+
this.workspaces = new Map(workspaces.map((workspace) => [workspace.workspaceId, { ...workspace }]));
|
|
533
544
|
this.panes = new Map(panes.map((pane) => [pane.paneId, observedPane(pane)]));
|
|
534
545
|
}
|
|
535
546
|
clear() {
|
|
536
547
|
this.currentPaneId = void 0;
|
|
537
|
-
this.
|
|
538
|
-
this.workspace = void 0;
|
|
548
|
+
this.workspaces.clear();
|
|
539
549
|
this.panes.clear();
|
|
540
550
|
}
|
|
541
|
-
isCurrentPane(paneId) {
|
|
542
|
-
return this.currentPaneId === paneId;
|
|
543
|
-
}
|
|
544
|
-
isCurrentWorkspace(workspaceId) {
|
|
545
|
-
return this.currentWorkspaceId === workspaceId;
|
|
546
|
-
}
|
|
547
551
|
snapshot() {
|
|
548
|
-
if (!this.currentPaneId
|
|
549
|
-
const rows = [...this.panes.values()].filter(
|
|
550
|
-
(pane) => pane.workspaceId === this.currentWorkspaceId && pane.paneId !== this.currentPaneId && pane.agent !== void 0
|
|
551
|
-
).map((pane) => rowForPane(pane, this.workspace));
|
|
552
|
+
if (!this.currentPaneId) return void 0;
|
|
553
|
+
const rows = [...this.panes.values()].filter((pane) => pane.paneId !== this.currentPaneId && pane.agent !== void 0).map((pane) => rowForPane(pane, this.workspaces.get(pane.workspaceId) ?? { workspaceId: pane.workspaceId }));
|
|
552
554
|
rows.sort(
|
|
553
555
|
(left, right) => STATE_ORDER[left.state] - STATE_ORDER[right.state] || left.agent.localeCompare(right.agent) || left.pane.localeCompare(right.pane) || left.paneId.localeCompare(right.paneId)
|
|
554
556
|
);
|
|
@@ -583,12 +585,14 @@ function stateSymbol(state) {
|
|
|
583
585
|
return "\xB7";
|
|
584
586
|
}
|
|
585
587
|
}
|
|
586
|
-
function
|
|
588
|
+
function herdrWidgetSummary(snapshot) {
|
|
589
|
+
return `${snapshot.totalAgents} sibling ${snapshot.totalAgents === 1 ? "agent" : "agents"}`;
|
|
590
|
+
}
|
|
591
|
+
function createHerdrWidget(snapshot, theme, includeHeader = true) {
|
|
587
592
|
return new EditorStatusWidget({
|
|
588
593
|
theme,
|
|
589
594
|
renderBody() {
|
|
590
|
-
const
|
|
591
|
-
const lines = [theme.fg("muted", `Herdr \xB7 ${snapshot.totalAgents} sibling ${noun}`)];
|
|
595
|
+
const lines = includeHeader ? [theme.fg("muted", `Herdr \xB7 ${herdrWidgetSummary(snapshot)}`)] : [];
|
|
592
596
|
const separator = theme.fg("dim", " \xB7 ");
|
|
593
597
|
for (const row of snapshot.rows) {
|
|
594
598
|
const state = stateStyle(theme, row.state, `${stateSymbol(row.state)} ${row.stateLabel}`);
|
|
@@ -609,21 +613,13 @@ function herdrWidgetFingerprint(snapshot) {
|
|
|
609
613
|
}
|
|
610
614
|
|
|
611
615
|
// src/herdr-observer.ts
|
|
616
|
+
var MAX_CONSECUTIVE_DISCARDS = 2;
|
|
612
617
|
var HerdrTopologyChangedError = class extends Error {
|
|
613
618
|
};
|
|
614
619
|
var HerdrCleanupError = class extends AggregateError {
|
|
615
620
|
};
|
|
616
621
|
function renderHerdrWidget(snapshot, theme, width) {
|
|
617
|
-
return createHerdrWidget(snapshot, theme).render(width);
|
|
618
|
-
}
|
|
619
|
-
function isRelevantEvent(model, event) {
|
|
620
|
-
if (event.type === "created" || event.type === "updated") {
|
|
621
|
-
return model.isCurrentWorkspace(event.pane.workspaceId);
|
|
622
|
-
}
|
|
623
|
-
if (event.type === "moved") {
|
|
624
|
-
return model.isCurrentPane(event.previousPaneId) || model.isCurrentWorkspace(event.previousWorkspaceId) || model.isCurrentWorkspace(event.pane.workspaceId);
|
|
625
|
-
}
|
|
626
|
-
return "workspaceId" in event && model.isCurrentWorkspace(event.workspaceId);
|
|
622
|
+
return createHerdrWidget(snapshot, theme, false).render(width);
|
|
627
623
|
}
|
|
628
624
|
function subscriptionFingerprint(currentPane, panes) {
|
|
629
625
|
const agentPaneIds = panes.filter((pane) => pane.agent !== void 0).map((pane) => pane.paneId).sort();
|
|
@@ -693,7 +689,7 @@ function createHerdrWidgetObserver(options) {
|
|
|
693
689
|
{
|
|
694
690
|
id: requestId("list"),
|
|
695
691
|
method: "pane.list",
|
|
696
|
-
params: {
|
|
692
|
+
params: {}
|
|
697
693
|
},
|
|
698
694
|
signal
|
|
699
695
|
),
|
|
@@ -706,30 +702,26 @@ function createHerdrWidgetObserver(options) {
|
|
|
706
702
|
options.environment.socketEndpoint,
|
|
707
703
|
{
|
|
708
704
|
id: requestId("workspace"),
|
|
709
|
-
method: "workspace.
|
|
710
|
-
params: {
|
|
705
|
+
method: "workspace.list",
|
|
706
|
+
params: {}
|
|
711
707
|
},
|
|
712
708
|
signal
|
|
713
709
|
)
|
|
714
710
|
]);
|
|
715
711
|
if (!owns(ctx, expectedGeneration) || signal.aborted) return void 0;
|
|
716
712
|
const panes = parsePaneListResult(listResult);
|
|
717
|
-
const
|
|
713
|
+
const panesById = new Map(panes.map((pane) => [pane.paneId, pane]));
|
|
718
714
|
const namesByPane = new Map(
|
|
719
|
-
parseAgentListResult(agentResult).filter((pane) => pane.workspaceId ===
|
|
715
|
+
parseAgentListResult(agentResult).filter((pane) => panesById.get(pane.paneId)?.workspaceId === pane.workspaceId).map((pane) => [pane.paneId, pane.agentName])
|
|
720
716
|
);
|
|
721
717
|
const withAgentName = (pane) => ({
|
|
722
718
|
...pane,
|
|
723
719
|
agentName: namesByPane.get(pane.paneId) ?? pane.agentName
|
|
724
720
|
});
|
|
725
|
-
const workspace = parseWorkspaceGetResult(workspaceResult);
|
|
726
|
-
if (workspace.workspaceId !== currentPane.workspaceId) {
|
|
727
|
-
throw new Error("Herdr returned a mismatched workspace");
|
|
728
|
-
}
|
|
729
721
|
return {
|
|
730
722
|
currentPane: withAgentName(currentPane),
|
|
731
723
|
panes: panes.map(withAgentName),
|
|
732
|
-
|
|
724
|
+
workspaces: parseWorkspaceListResult(workspaceResult)
|
|
733
725
|
};
|
|
734
726
|
};
|
|
735
727
|
const runAttempt = async (ctx, expectedGeneration, sessionSignal) => {
|
|
@@ -767,8 +759,8 @@ function createHerdrWidgetObserver(options) {
|
|
|
767
759
|
if (!discovered) return;
|
|
768
760
|
const subscribedFingerprint = subscriptionFingerprint(discovered.currentPane, discovered.panes);
|
|
769
761
|
const model = new HerdrWidgetModel();
|
|
770
|
-
model.reset(discovered.currentPane, discovered.panes, discovered.workspace);
|
|
771
762
|
let dirty = true;
|
|
763
|
+
let consecutiveDiscards = 0;
|
|
772
764
|
subscription = await subscribe(
|
|
773
765
|
options.environment.socketEndpoint,
|
|
774
766
|
{
|
|
@@ -780,7 +772,7 @@ function createHerdrWidgetObserver(options) {
|
|
|
780
772
|
(frame) => {
|
|
781
773
|
if (!attemptActive || !owns(ctx, expectedGeneration) || signal.aborted) return;
|
|
782
774
|
const event = parseHerdrPaneEvent(frame);
|
|
783
|
-
if (!event
|
|
775
|
+
if (!event) return;
|
|
784
776
|
dirty = true;
|
|
785
777
|
wakeRefresh();
|
|
786
778
|
}
|
|
@@ -800,11 +792,15 @@ function createHerdrWidgetObserver(options) {
|
|
|
800
792
|
dirty = false;
|
|
801
793
|
const refreshed = await loadPaneSet(ctx, expectedGeneration, signal);
|
|
802
794
|
if (!refreshed || signal.aborted) break;
|
|
803
|
-
if (dirty) continue;
|
|
804
795
|
if (subscriptionFingerprint(refreshed.currentPane, refreshed.panes) !== subscribedFingerprint) {
|
|
805
796
|
throw new HerdrTopologyChangedError();
|
|
806
797
|
}
|
|
807
|
-
|
|
798
|
+
if (dirty && consecutiveDiscards < MAX_CONSECUTIVE_DISCARDS) {
|
|
799
|
+
consecutiveDiscards += 1;
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
consecutiveDiscards = 0;
|
|
803
|
+
model.reset(refreshed.currentPane, refreshed.panes, refreshed.workspaces);
|
|
808
804
|
publish(ctx, model, expectedGeneration);
|
|
809
805
|
await new Promise((resolve) => {
|
|
810
806
|
wake = resolve;
|
|
@@ -879,8 +875,10 @@ function createHerdrWidgetObserver(options) {
|
|
|
879
875
|
const expectedGeneration = generation;
|
|
880
876
|
publisher = createEditorStatusPublisher({
|
|
881
877
|
key: HERDR_WIDGET_KEY,
|
|
878
|
+
name: "Herdr",
|
|
882
879
|
context: ctx,
|
|
883
880
|
isCurrent: () => expectedGeneration === generation,
|
|
881
|
+
summary: herdrWidgetSummary,
|
|
884
882
|
render: renderHerdrWidget
|
|
885
883
|
});
|
|
886
884
|
const task = run(ctx, expectedGeneration, controller.signal);
|
|
@@ -893,6 +891,10 @@ function createHerdrWidgetObserver(options) {
|
|
|
893
891
|
}
|
|
894
892
|
);
|
|
895
893
|
},
|
|
894
|
+
restore(ctx) {
|
|
895
|
+
if (activeSession === void 0 || !owns(ctx)) return false;
|
|
896
|
+
return publisher?.setCollapsed(false) ?? false;
|
|
897
|
+
},
|
|
896
898
|
async shutdown(ctx) {
|
|
897
899
|
if (activeSession !== void 0 && !owns(ctx)) return;
|
|
898
900
|
controller?.abort(new DOMException("Herdr widget session shut down", "AbortError"));
|
|
@@ -1098,9 +1100,10 @@ function createHerdrSettingsController(pi, observer, options = {}) {
|
|
|
1098
1100
|
try {
|
|
1099
1101
|
const [{ runMenu }, { createHerdrMenu }] = await Promise.all([
|
|
1100
1102
|
import("@narumitw/pi-tui-kit"),
|
|
1101
|
-
import("./chunks/herdr-menu-
|
|
1103
|
+
import("./chunks/herdr-menu-H74GELLE.ts")
|
|
1102
1104
|
]);
|
|
1103
1105
|
if (!current(expected)) return;
|
|
1106
|
+
if (enabled && ctx.mode === "tui") observer.restore(ctx);
|
|
1104
1107
|
await runMenu(
|
|
1105
1108
|
ctx,
|
|
1106
1109
|
createHerdrMenu({
|