@narumitw/pi-herdr 0.4.1 → 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 +7 -0
- package/README.md +20 -47
- 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 +41 -47
- package/dist/index.ts.map +2 -2
- package/package.json +2 -6
- package/src/herdr-menu.ts +2 -1
- package/src/herdr-observer.ts +22 -33
- package/src/herdr-protocol.ts +20 -7
- package/src/herdr-widget.ts +7 -27
- 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,12 @@
|
|
|
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
|
+
|
|
3
10
|
## 0.4.1
|
|
4
11
|
|
|
5
12
|
### Patch 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.
|
|
@@ -160,8 +139,10 @@ The widget does not focus panes, read terminal output, send prompts, or mark a b
|
|
|
160
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.
|
|
161
140
|
Opening `/herdr` in TUI mode also restores disclosure when the widget is enabled, without changing or saving the enable setting.
|
|
162
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.
|
|
163
|
-
The extension discovers the current
|
|
164
|
-
Events trigger serialized, coalesced reads rather than replacing current state with event payloads.
|
|
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.
|
|
165
146
|
Agent names, workspace labels, and cleared presentation fields update from these authoritative reads.
|
|
166
147
|
Changes to the current pane, workspace, or recognized-agent set rebuild the pane-scoped subscriptions without consuming the bounded failure retry.
|
|
167
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`.
|
|
@@ -172,31 +153,24 @@ Session replacement and shutdown abort the subscription, pending reads, reconnec
|
|
|
172
153
|
The extension connects only to the Unix socket or Windows named pipe provided by `HERDR_SOCKET_PATH`.
|
|
173
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.
|
|
174
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.
|
|
175
|
-
For the widget, it reads the canonical current pane
|
|
176
|
-
|
|
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.
|
|
177
158
|
Widget fields can include workspace, tab, pane, terminal, agent, display, name, title, label, state-label, and lifecycle identifiers supplied by Herdr.
|
|
178
|
-
|
|
179
|
-
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.
|
|
180
161
|
The package does not authenticate the endpoint, so trust the environment that launches Pi and controls these variables.
|
|
181
162
|
|
|
182
|
-
The bundled skills load operating guidance from the local CLI only after an explicit request for Herdr or Herdr Core.
|
|
183
|
-
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.
|
|
184
|
-
Those commands execute with the same user permissions as Pi and can affect live terminal sessions.
|
|
185
|
-
Both bootstraps stop when their CLI is unavailable or its `--skill` command fails; the `herdr` bootstrap also stops when `HERDR_ENV` is not `1`.
|
|
186
|
-
Command recipes, approval handling, and other operating safety rules come from the selected CLI's installed version instead of being duplicated by this package.
|
|
187
|
-
|
|
188
163
|
## 🚧 Limitations
|
|
189
164
|
|
|
190
165
|
- Lifecycle reporting, metadata reporting, and the agent widget are disabled in RPC, JSON, and print modes.
|
|
191
|
-
- 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.
|
|
192
168
|
- The widget cannot show blocked prompt text because Herdr does not expose it through public pane responses.
|
|
193
|
-
- 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.
|
|
194
170
|
- A pane-label change appears on its next update event or authoritative refresh; an agent rename emits a pane-update event.
|
|
195
171
|
- Integration requires a running compatible Herdr session and valid injected environment variables.
|
|
196
|
-
- Each skill requires its matching CLI with `--skill` support; `hc` does not enable the legacy Herdr lifecycle reports or widget.
|
|
197
172
|
- Socket failures are intentionally silent after the bounded retry.
|
|
198
|
-
-
|
|
199
|
-
- 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.
|
|
200
174
|
|
|
201
175
|
## 🗂️ Package layout
|
|
202
176
|
|
|
@@ -207,13 +181,12 @@ packages/pi-herdr/
|
|
|
207
181
|
│ └── herdr-agent-state.ts # Herdr lifecycle integration
|
|
208
182
|
├── dist/ # Generated TypeScript runtime loaded by Pi
|
|
209
183
|
├── scripts/ # Deterministic runtime builder
|
|
210
|
-
├── skills/ # Published herdr and hc bootstraps for CLI-owned guidance
|
|
211
184
|
└── test/ # Behavior and lifecycle coverage
|
|
212
185
|
```
|
|
213
186
|
|
|
214
187
|
## 🔎 Keywords
|
|
215
188
|
|
|
216
|
-
Pi, Herdr,
|
|
189
|
+
Pi, Herdr, terminal multiplexer, coding agents, agent status, lifecycle state, pane metadata.
|
|
217
190
|
|
|
218
191
|
## 📄 License
|
|
219
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
|
);
|
|
@@ -611,6 +613,7 @@ function herdrWidgetFingerprint(snapshot) {
|
|
|
611
613
|
}
|
|
612
614
|
|
|
613
615
|
// src/herdr-observer.ts
|
|
616
|
+
var MAX_CONSECUTIVE_DISCARDS = 2;
|
|
614
617
|
var HerdrTopologyChangedError = class extends Error {
|
|
615
618
|
};
|
|
616
619
|
var HerdrCleanupError = class extends AggregateError {
|
|
@@ -618,15 +621,6 @@ var HerdrCleanupError = class extends AggregateError {
|
|
|
618
621
|
function renderHerdrWidget(snapshot, theme, width) {
|
|
619
622
|
return createHerdrWidget(snapshot, theme, false).render(width);
|
|
620
623
|
}
|
|
621
|
-
function isRelevantEvent(model, event) {
|
|
622
|
-
if (event.type === "created" || event.type === "updated") {
|
|
623
|
-
return model.isCurrentWorkspace(event.pane.workspaceId);
|
|
624
|
-
}
|
|
625
|
-
if (event.type === "moved") {
|
|
626
|
-
return model.isCurrentPane(event.previousPaneId) || model.isCurrentWorkspace(event.previousWorkspaceId) || model.isCurrentWorkspace(event.pane.workspaceId);
|
|
627
|
-
}
|
|
628
|
-
return "workspaceId" in event && model.isCurrentWorkspace(event.workspaceId);
|
|
629
|
-
}
|
|
630
624
|
function subscriptionFingerprint(currentPane, panes) {
|
|
631
625
|
const agentPaneIds = panes.filter((pane) => pane.agent !== void 0).map((pane) => pane.paneId).sort();
|
|
632
626
|
return JSON.stringify([currentPane.paneId, currentPane.workspaceId, agentPaneIds]);
|
|
@@ -695,7 +689,7 @@ function createHerdrWidgetObserver(options) {
|
|
|
695
689
|
{
|
|
696
690
|
id: requestId("list"),
|
|
697
691
|
method: "pane.list",
|
|
698
|
-
params: {
|
|
692
|
+
params: {}
|
|
699
693
|
},
|
|
700
694
|
signal
|
|
701
695
|
),
|
|
@@ -708,30 +702,26 @@ function createHerdrWidgetObserver(options) {
|
|
|
708
702
|
options.environment.socketEndpoint,
|
|
709
703
|
{
|
|
710
704
|
id: requestId("workspace"),
|
|
711
|
-
method: "workspace.
|
|
712
|
-
params: {
|
|
705
|
+
method: "workspace.list",
|
|
706
|
+
params: {}
|
|
713
707
|
},
|
|
714
708
|
signal
|
|
715
709
|
)
|
|
716
710
|
]);
|
|
717
711
|
if (!owns(ctx, expectedGeneration) || signal.aborted) return void 0;
|
|
718
712
|
const panes = parsePaneListResult(listResult);
|
|
719
|
-
const
|
|
713
|
+
const panesById = new Map(panes.map((pane) => [pane.paneId, pane]));
|
|
720
714
|
const namesByPane = new Map(
|
|
721
|
-
parseAgentListResult(agentResult).filter((pane) => pane.workspaceId ===
|
|
715
|
+
parseAgentListResult(agentResult).filter((pane) => panesById.get(pane.paneId)?.workspaceId === pane.workspaceId).map((pane) => [pane.paneId, pane.agentName])
|
|
722
716
|
);
|
|
723
717
|
const withAgentName = (pane) => ({
|
|
724
718
|
...pane,
|
|
725
719
|
agentName: namesByPane.get(pane.paneId) ?? pane.agentName
|
|
726
720
|
});
|
|
727
|
-
const workspace = parseWorkspaceGetResult(workspaceResult);
|
|
728
|
-
if (workspace.workspaceId !== currentPane.workspaceId) {
|
|
729
|
-
throw new Error("Herdr returned a mismatched workspace");
|
|
730
|
-
}
|
|
731
721
|
return {
|
|
732
722
|
currentPane: withAgentName(currentPane),
|
|
733
723
|
panes: panes.map(withAgentName),
|
|
734
|
-
|
|
724
|
+
workspaces: parseWorkspaceListResult(workspaceResult)
|
|
735
725
|
};
|
|
736
726
|
};
|
|
737
727
|
const runAttempt = async (ctx, expectedGeneration, sessionSignal) => {
|
|
@@ -769,8 +759,8 @@ function createHerdrWidgetObserver(options) {
|
|
|
769
759
|
if (!discovered) return;
|
|
770
760
|
const subscribedFingerprint = subscriptionFingerprint(discovered.currentPane, discovered.panes);
|
|
771
761
|
const model = new HerdrWidgetModel();
|
|
772
|
-
model.reset(discovered.currentPane, discovered.panes, discovered.workspace);
|
|
773
762
|
let dirty = true;
|
|
763
|
+
let consecutiveDiscards = 0;
|
|
774
764
|
subscription = await subscribe(
|
|
775
765
|
options.environment.socketEndpoint,
|
|
776
766
|
{
|
|
@@ -782,7 +772,7 @@ function createHerdrWidgetObserver(options) {
|
|
|
782
772
|
(frame) => {
|
|
783
773
|
if (!attemptActive || !owns(ctx, expectedGeneration) || signal.aborted) return;
|
|
784
774
|
const event = parseHerdrPaneEvent(frame);
|
|
785
|
-
if (!event
|
|
775
|
+
if (!event) return;
|
|
786
776
|
dirty = true;
|
|
787
777
|
wakeRefresh();
|
|
788
778
|
}
|
|
@@ -802,11 +792,15 @@ function createHerdrWidgetObserver(options) {
|
|
|
802
792
|
dirty = false;
|
|
803
793
|
const refreshed = await loadPaneSet(ctx, expectedGeneration, signal);
|
|
804
794
|
if (!refreshed || signal.aborted) break;
|
|
805
|
-
if (dirty) continue;
|
|
806
795
|
if (subscriptionFingerprint(refreshed.currentPane, refreshed.panes) !== subscribedFingerprint) {
|
|
807
796
|
throw new HerdrTopologyChangedError();
|
|
808
797
|
}
|
|
809
|
-
|
|
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);
|
|
810
804
|
publish(ctx, model, expectedGeneration);
|
|
811
805
|
await new Promise((resolve) => {
|
|
812
806
|
wake = resolve;
|
|
@@ -1106,7 +1100,7 @@ function createHerdrSettingsController(pi, observer, options = {}) {
|
|
|
1106
1100
|
try {
|
|
1107
1101
|
const [{ runMenu }, { createHerdrMenu }] = await Promise.all([
|
|
1108
1102
|
import("@narumitw/pi-tui-kit"),
|
|
1109
|
-
import("./chunks/herdr-menu-
|
|
1103
|
+
import("./chunks/herdr-menu-H74GELLE.ts")
|
|
1110
1104
|
]);
|
|
1111
1105
|
if (!current(expected)) return;
|
|
1112
1106
|
if (enabled && ctx.mode === "tui") observer.restore(ctx);
|