@howaboua/pi-shepherdr 0.1.1 → 0.1.2
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 +9 -1
- package/index.ts +4 -5
- package/package.json +1 -1
- package/src/fleet.ts +556 -0
- package/src/herdr-client.ts +10 -1
- package/src/herdr.ts +6 -5
- package/src/launch.ts +13 -7
- package/src/machines-config.ts +148 -0
- package/src/master-mode.ts +214 -26
- package/src/messages.ts +41 -10
- package/src/monitor-events.ts +7 -5
- package/src/monitor.ts +61 -50
- package/src/remote/shepherdr.mjs +400 -0
- package/src/remote-client.ts +420 -0
- package/src/session-reader.ts +88 -69
- package/src/settlement.ts +20 -11
- package/src/tool.ts +62 -23
- package/src/types.ts +11 -0
- package/src/widget.ts +23 -8
package/src/tool.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StringEnum, Type } from "@earendil-works/pi-ai";
|
|
2
2
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import {
|
|
3
|
+
import type { AgentFleet } from "./fleet.js";
|
|
4
|
+
import { resolvePiAgent } from "./herdr.js";
|
|
4
5
|
import {
|
|
5
6
|
START_PLACEMENTS,
|
|
6
7
|
type StartAgentParams,
|
|
@@ -15,6 +16,7 @@ const FIRE_AND_FORGET =
|
|
|
15
16
|
|
|
16
17
|
type ToolParams = StartAgentParams & {
|
|
17
18
|
action: (typeof ACTIONS)[number];
|
|
19
|
+
machine?: string;
|
|
18
20
|
target?: string;
|
|
19
21
|
};
|
|
20
22
|
|
|
@@ -46,9 +48,11 @@ function compactAgent(
|
|
|
46
48
|
agent: PaneInfo,
|
|
47
49
|
snapshot: SessionSnapshot,
|
|
48
50
|
monitored: boolean,
|
|
51
|
+
machine: string,
|
|
49
52
|
): Record<string, unknown> {
|
|
50
53
|
const names = labels(snapshot);
|
|
51
54
|
return {
|
|
55
|
+
machine,
|
|
52
56
|
id: agent.pane_id,
|
|
53
57
|
...(agent.name ? { name: agent.name } : {}),
|
|
54
58
|
status: agent.agent_status,
|
|
@@ -78,18 +82,21 @@ function findRecord(
|
|
|
78
82
|
|
|
79
83
|
export function registerHerdrAgentsTool(
|
|
80
84
|
pi: ExtensionAPI,
|
|
81
|
-
|
|
85
|
+
fleet: AgentFleet,
|
|
82
86
|
): void {
|
|
83
87
|
pi.registerTool({
|
|
84
88
|
name: "herdr_agents",
|
|
85
89
|
label: "Shepherdr",
|
|
86
90
|
description:
|
|
87
|
-
"Herdr Pi agents. start needs name and placement; new_tab needs workspace; pane placement needs pane ID. watch/unwatch need target; send needs target and prompt.",
|
|
91
|
+
"Herdr Pi agents across configured machines. start needs name and placement; new_tab needs workspace; pane placement needs pane ID. watch/unwatch need target; send needs target and prompt.",
|
|
88
92
|
promptGuidelines: [
|
|
89
93
|
"Act as an orchestrator: delegate project implementation, synthesize worker results, and report them to the user. Work directly only when explicitly asked or for configuration, documentation, and routine operations in the current working directory",
|
|
90
94
|
],
|
|
91
95
|
parameters: Type.Object({
|
|
92
96
|
action: StringEnum(ACTIONS),
|
|
97
|
+
machine: Type.Optional(
|
|
98
|
+
Type.String({ description: "Configured machine; defaults to local" }),
|
|
99
|
+
),
|
|
93
100
|
target: Type.Optional(
|
|
94
101
|
Type.String({ description: "Agent name or pane ID" }),
|
|
95
102
|
),
|
|
@@ -123,30 +130,56 @@ export function registerHerdrAgentsTool(
|
|
|
123
130
|
}),
|
|
124
131
|
executionMode: "sequential",
|
|
125
132
|
async execute(_toolCallId, params: ToolParams, _signal, _onUpdate, ctx) {
|
|
126
|
-
const monitor = getMonitor();
|
|
127
|
-
const client = monitor.client;
|
|
128
133
|
if (params.action === "list") {
|
|
129
|
-
const
|
|
134
|
+
const machines = await fleet.snapshots(params.machine);
|
|
130
135
|
return result({
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
machines: machines.map(
|
|
137
|
+
({
|
|
138
|
+
snapshot: _snapshot,
|
|
139
|
+
monitoredPaneIds: _monitoredPaneIds,
|
|
140
|
+
...machine
|
|
141
|
+
}) => machine,
|
|
142
|
+
),
|
|
143
|
+
agents: machines.flatMap((machine) => {
|
|
144
|
+
if (!machine.snapshot) return [];
|
|
145
|
+
return machine.snapshot.agents
|
|
146
|
+
.filter(
|
|
147
|
+
(agent) =>
|
|
148
|
+
agent.agent === "pi" &&
|
|
149
|
+
(!machine.local ||
|
|
150
|
+
agent.pane_id !== process.env["HERDR_PANE_ID"]),
|
|
151
|
+
)
|
|
152
|
+
.map((agent) =>
|
|
153
|
+
compactAgent(
|
|
154
|
+
agent,
|
|
155
|
+
machine.snapshot!,
|
|
156
|
+
machine.monitoredPaneIds?.has(agent.pane_id) ?? false,
|
|
157
|
+
machine.name,
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
}),
|
|
161
|
+
workspaces: machines.flatMap((machine) =>
|
|
162
|
+
(machine.snapshot?.workspaces ?? []).map((workspace) => ({
|
|
163
|
+
machine: machine.name,
|
|
164
|
+
id: workspace.workspace_id,
|
|
165
|
+
label: workspace.label,
|
|
166
|
+
})),
|
|
167
|
+
),
|
|
144
168
|
});
|
|
145
169
|
}
|
|
170
|
+
const runtime = fleet.connected(params.machine);
|
|
171
|
+
const { client, machine, monitor } = runtime;
|
|
146
172
|
if (params.action === "start") {
|
|
147
|
-
const started = await startAgent(
|
|
173
|
+
const started = await startAgent(
|
|
174
|
+
client,
|
|
175
|
+
monitor,
|
|
176
|
+
params,
|
|
177
|
+
runtime.local ? ctx.cwd : runtime.fallbackCwd,
|
|
178
|
+
runtime.resolveDirectory,
|
|
179
|
+
);
|
|
148
180
|
return result({
|
|
149
181
|
started: true,
|
|
182
|
+
machine,
|
|
150
183
|
id: started.id,
|
|
151
184
|
...(params.prompt?.trim() ? { next: FIRE_AND_FORGET } : {}),
|
|
152
185
|
});
|
|
@@ -155,16 +188,21 @@ export function registerHerdrAgentsTool(
|
|
|
155
188
|
const target = required(params.target, "target");
|
|
156
189
|
if (params.action === "unwatch") {
|
|
157
190
|
const record = findRecord(monitor, target);
|
|
158
|
-
if (!record) return result({ unwatched: false, target });
|
|
191
|
+
if (!record) return result({ unwatched: false, machine, target });
|
|
159
192
|
await monitor.unwatch(record.paneId);
|
|
160
|
-
return result({ unwatched: true, id: record.paneId });
|
|
193
|
+
return result({ unwatched: true, machine, id: record.paneId });
|
|
161
194
|
}
|
|
162
195
|
|
|
163
|
-
const agent = await resolvePiAgent(
|
|
196
|
+
const agent = await resolvePiAgent(
|
|
197
|
+
client,
|
|
198
|
+
target,
|
|
199
|
+
runtime.local ? process.env["HERDR_PANE_ID"] : "",
|
|
200
|
+
);
|
|
164
201
|
if (params.action === "watch") {
|
|
165
202
|
await monitor.watch(agent);
|
|
166
203
|
return result({
|
|
167
204
|
watched: true,
|
|
205
|
+
machine,
|
|
168
206
|
id: agent.pane_id,
|
|
169
207
|
next: FIRE_AND_FORGET,
|
|
170
208
|
});
|
|
@@ -185,6 +223,7 @@ export function registerHerdrAgentsTool(
|
|
|
185
223
|
}
|
|
186
224
|
return result({
|
|
187
225
|
sent: true,
|
|
226
|
+
machine,
|
|
188
227
|
id: agent.pane_id,
|
|
189
228
|
next: FIRE_AND_FORGET,
|
|
190
229
|
});
|
package/src/types.ts
CHANGED
|
@@ -66,6 +66,17 @@ export interface MonitoredAgent {
|
|
|
66
66
|
readonly workspaceId: string;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
type MachineConnectionStatus = "connected" | "connecting" | "unavailable";
|
|
70
|
+
|
|
71
|
+
export interface MachineStatus {
|
|
72
|
+
local: boolean;
|
|
73
|
+
name: string;
|
|
74
|
+
reason?: string;
|
|
75
|
+
status: MachineConnectionStatus;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type ScopedMonitoredAgent = MonitoredAgent & { machine: string };
|
|
79
|
+
|
|
69
80
|
export interface LatestAssistant {
|
|
70
81
|
id: string;
|
|
71
82
|
stopReason?: string;
|
package/src/widget.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { basename } from "node:path";
|
|
2
2
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { activityStatus } from "./activity.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
AgentStatus,
|
|
6
|
+
MachineStatus,
|
|
7
|
+
ScopedMonitoredAgent,
|
|
8
|
+
} from "./types.js";
|
|
5
9
|
|
|
6
10
|
const WIDGET_ID = "herdr-agents";
|
|
7
11
|
const MAX_VISIBLE_AGENTS = 8;
|
|
@@ -24,24 +28,32 @@ function statusAppearance(status: AgentStatus): {
|
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
function agentLine(
|
|
31
|
+
function agentLine(
|
|
32
|
+
ctx: ExtensionContext,
|
|
33
|
+
agent: ScopedMonitoredAgent,
|
|
34
|
+
machines: Map<string, MachineStatus>,
|
|
35
|
+
): string {
|
|
28
36
|
const theme = ctx.ui.theme;
|
|
29
37
|
const status = activityStatus(agent.activity);
|
|
30
|
-
const
|
|
31
|
-
const
|
|
38
|
+
const connected = machines.get(agent.machine)?.status === "connected";
|
|
39
|
+
const appearance = connected
|
|
40
|
+
? statusAppearance(status)
|
|
41
|
+
: ({ icon: "?", tone: "error" } as const);
|
|
42
|
+
const name = `${agent.machine} / ${agent.name ?? agent.paneId}`;
|
|
32
43
|
const location = agent.cwd ? basename(agent.cwd) : agent.paneId;
|
|
33
44
|
return [
|
|
34
45
|
theme.fg("muted", "│"),
|
|
35
46
|
theme.fg(appearance.tone, appearance.icon),
|
|
36
47
|
theme.fg("accent", name),
|
|
37
|
-
theme.fg(appearance.tone, status),
|
|
48
|
+
theme.fg(appearance.tone, connected ? status : "offline"),
|
|
38
49
|
theme.fg("dim", `· ${location}`),
|
|
39
50
|
].join(" ");
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
export function renderAgentWidget(
|
|
43
54
|
ctx: ExtensionContext | undefined,
|
|
44
|
-
agents:
|
|
55
|
+
agents: ScopedMonitoredAgent[],
|
|
56
|
+
machines: MachineStatus[],
|
|
45
57
|
): void {
|
|
46
58
|
if (!ctx?.hasUI) return;
|
|
47
59
|
if (agents.length === 0) {
|
|
@@ -55,11 +67,14 @@ export function renderAgentWidget(
|
|
|
55
67
|
statusOrder(activityStatus(right.activity)) ||
|
|
56
68
|
(left.name ?? left.paneId).localeCompare(right.name ?? right.paneId),
|
|
57
69
|
);
|
|
70
|
+
const machinesByName = new Map(
|
|
71
|
+
machines.map((machine) => [machine.name, machine]),
|
|
72
|
+
);
|
|
58
73
|
const lines = [
|
|
59
|
-
`${theme.fg("accent", "╭─ herdr agents")} ${theme.fg("dim",
|
|
74
|
+
`${theme.fg("accent", "╭─ herdr agents")} ${theme.fg("dim", `${agents.length} · ${machines.filter((machine) => machine.status === "connected").length}/${machines.length} machines`)}`,
|
|
60
75
|
...ordered
|
|
61
76
|
.slice(0, MAX_VISIBLE_AGENTS)
|
|
62
|
-
.map((agent) => agentLine(ctx, agent)),
|
|
77
|
+
.map((agent) => agentLine(ctx, agent, machinesByName)),
|
|
63
78
|
];
|
|
64
79
|
if (ordered.length > MAX_VISIBLE_AGENTS) {
|
|
65
80
|
lines.push(
|