@howaboua/pi-shepherdr 0.2.23 → 0.2.24
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 -18
- package/README.md +63 -60
- package/biome.json +1 -1
- package/index.ts +2 -2
- package/package.json +14 -9
- package/src/agents-discovery.ts +41 -26
- package/src/agents-focus.ts +2 -2
- package/src/agents-reply.ts +1 -1
- package/src/agents-spawn.ts +2 -2
- package/src/agents-tool.ts +2 -2
- package/src/agents-work.ts +3 -3
- package/src/attachment-notes.ts +14 -2
- package/src/attachment-protocol.ts +21 -4
- package/src/attachment-routing.ts +1 -1
- package/src/attachment-target.ts +5 -2
- package/src/attachment.ts +2 -3
- package/src/board/host.ts +2 -2
- package/src/board/membership.ts +1 -1
- package/src/{control-panel-actions.ts → control-panel/actions.ts} +2 -2
- package/src/{control-panel.ts → control-panel/index.ts} +4 -4
- package/src/{control-panel-items.ts → control-panel/items.ts} +3 -3
- package/src/{control-panel-view.ts → control-panel/view.ts} +3 -3
- package/src/controller.ts +6 -3
- package/src/fleet/index.ts +384 -0
- package/src/fleet/inspection.ts +141 -0
- package/src/fleet/machine.ts +52 -0
- package/src/fleet/monitor.ts +71 -0
- package/src/fleet/persistence.ts +42 -0
- package/src/fleet/reconnect.ts +75 -0
- package/src/fleet/setup.ts +92 -0
- package/src/messages/attachments.ts +39 -0
- package/src/messages/attribution.ts +75 -0
- package/src/messages/event-details.ts +69 -0
- package/src/messages/events.ts +189 -0
- package/src/messages/focus.ts +38 -0
- package/src/messages/guidance.ts +83 -0
- package/src/messages/render.ts +89 -0
- package/src/messages/voice-announcements.ts +79 -0
- package/src/monitor.ts +2 -2
- package/src/peer-inbox.ts +2 -2
- package/src/remote/client.ts +127 -0
- package/src/remote/context-relay.ts +84 -0
- package/src/remote/deployment.ts +179 -0
- package/src/remote/focus-channels.ts +89 -0
- package/src/remote/transport.ts +369 -0
- package/src/settlement/collector.ts +122 -0
- package/src/settlement/delivery.ts +144 -0
- package/src/{settlement.ts → settlement/index.ts} +23 -233
- package/src/shared-context-host.ts +33 -11
- package/src/shared-context.ts +10 -4
- package/src/spawn-context.ts +20 -17
- package/src/voice-handoff.ts +1 -1
- package/src/worker-service.ts +2 -2
- package/src/fleet.ts +0 -702
- package/src/messages.ts +0 -637
- package/src/remote-client.ts +0 -761
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { activityTask } from "../activity.js";
|
|
6
|
+
import { sendPolicyMessage } from "../delivery.js";
|
|
7
|
+
import type {
|
|
8
|
+
ExtensionMessage,
|
|
9
|
+
LatestAssistant,
|
|
10
|
+
MonitoredAgent,
|
|
11
|
+
PaneInfo,
|
|
12
|
+
SettledAgentStatus,
|
|
13
|
+
} from "../types.js";
|
|
14
|
+
import {
|
|
15
|
+
type AgentEventLabels,
|
|
16
|
+
agentSource,
|
|
17
|
+
sourceAttributes,
|
|
18
|
+
xml,
|
|
19
|
+
} from "./attribution.js";
|
|
20
|
+
import {
|
|
21
|
+
AGENT_EVENT_MESSAGE_TYPE,
|
|
22
|
+
type AgentEventDetails,
|
|
23
|
+
} from "./event-details.js";
|
|
24
|
+
import { agentVoicePrompt, announceAgentEvent } from "./voice-announcements.js";
|
|
25
|
+
|
|
26
|
+
interface AgentEventOptions {
|
|
27
|
+
agent: PaneInfo;
|
|
28
|
+
agentToolName: string;
|
|
29
|
+
codeMode?: boolean;
|
|
30
|
+
extensionMessages?: ExtensionMessage[];
|
|
31
|
+
blockedMessage?: string;
|
|
32
|
+
labels: AgentEventLabels;
|
|
33
|
+
machine: string;
|
|
34
|
+
machineLabel: string;
|
|
35
|
+
operatorPrefix: string;
|
|
36
|
+
record: MonitoredAgent;
|
|
37
|
+
reply?: LatestAssistant;
|
|
38
|
+
status: SettledAgentStatus | "extension-message";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function operatorCommand(operatorPrefix: string, command: string): string {
|
|
42
|
+
return `\`${operatorPrefix} ${command}\``;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function blockedOperatorHint(
|
|
46
|
+
agentToolName: string,
|
|
47
|
+
machine: string,
|
|
48
|
+
operatorPrefix: string,
|
|
49
|
+
paneId: string,
|
|
50
|
+
): string {
|
|
51
|
+
return `Inspect first with ${operatorCommand(operatorPrefix, `agent read ${paneId} --source visible`)}; respond through ${agentToolName} with machine=${JSON.stringify(machine)}, or use ${operatorCommand(operatorPrefix, `agent send-keys ${paneId} <keys>`)} for interactive controls.`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function failedOperatorHint(
|
|
55
|
+
agentToolName: string,
|
|
56
|
+
machine: string,
|
|
57
|
+
operatorPrefix: string,
|
|
58
|
+
paneId: string,
|
|
59
|
+
): string {
|
|
60
|
+
return `Inspect with ${operatorCommand(operatorPrefix, `agent read ${paneId} --source recent-unwrapped --lines 80`)} and assess the failure. If this task has not already been retried and one simple corrective prompt could recover it, try once through ${agentToolName} with machine=${JSON.stringify(machine)}. If it fails again or the setup looks broken, stop retrying and tell the user.`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function agentEvent(options: AgentEventOptions): {
|
|
64
|
+
content: string;
|
|
65
|
+
details: AgentEventDetails;
|
|
66
|
+
} {
|
|
67
|
+
const {
|
|
68
|
+
agent,
|
|
69
|
+
agentToolName,
|
|
70
|
+
codeMode,
|
|
71
|
+
extensionMessages,
|
|
72
|
+
blockedMessage,
|
|
73
|
+
labels,
|
|
74
|
+
machine,
|
|
75
|
+
machineLabel,
|
|
76
|
+
operatorPrefix,
|
|
77
|
+
record,
|
|
78
|
+
reply,
|
|
79
|
+
status,
|
|
80
|
+
} = options;
|
|
81
|
+
const task = activityTask(record.activity);
|
|
82
|
+
const blocked = status === "blocked";
|
|
83
|
+
const notification = status === "extension-message";
|
|
84
|
+
const failed = !blocked && reply?.stopReason === "error";
|
|
85
|
+
const cwd = agent.foreground_cwd ?? agent.cwd ?? record.cwd;
|
|
86
|
+
const tag = notification
|
|
87
|
+
? "herdr_agent_extension_message"
|
|
88
|
+
: blocked
|
|
89
|
+
? "herdr_agent_blocked"
|
|
90
|
+
: failed
|
|
91
|
+
? "herdr_agent_failed"
|
|
92
|
+
: "herdr_agent_result";
|
|
93
|
+
const attributes = sourceAttributes({
|
|
94
|
+
machine,
|
|
95
|
+
machine_name: machineLabel !== machine ? machineLabel : undefined,
|
|
96
|
+
...agentSource(agent, labels),
|
|
97
|
+
name: agent.name ?? record.name,
|
|
98
|
+
directory: cwd,
|
|
99
|
+
});
|
|
100
|
+
const lines = [`<${tag} ${attributes}>`];
|
|
101
|
+
if (task && !notification) lines.push(`<task>${xml(task)}</task>`);
|
|
102
|
+
if (blockedMessage) {
|
|
103
|
+
lines.push(`<blocked_on>${xml(blockedMessage)}</blocked_on>`);
|
|
104
|
+
}
|
|
105
|
+
for (const message of extensionMessages ?? []) {
|
|
106
|
+
lines.push(message.message);
|
|
107
|
+
if (message.reply !== undefined) {
|
|
108
|
+
const request = {
|
|
109
|
+
action: "reply",
|
|
110
|
+
machine,
|
|
111
|
+
target: agent.pane_id,
|
|
112
|
+
extension: message.extension,
|
|
113
|
+
id: message.id,
|
|
114
|
+
message: message.reply,
|
|
115
|
+
};
|
|
116
|
+
const call = codeMode
|
|
117
|
+
? `await tools.${agentToolName}(${JSON.stringify(request)})`
|
|
118
|
+
: `${agentToolName} ${JSON.stringify(request)}`;
|
|
119
|
+
lines.push(`Reply: ${call}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (blocked) {
|
|
123
|
+
lines.push(
|
|
124
|
+
`<operator_hint>${xml(blockedOperatorHint(agentToolName, machine, operatorPrefix, agent.pane_id))}</operator_hint>`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (failed) {
|
|
128
|
+
lines.push(
|
|
129
|
+
`<operator_hint>${xml(failedOperatorHint(agentToolName, machine, operatorPrefix, agent.pane_id))}</operator_hint>`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (reply) lines.push(`<response>${xml(reply.text)}</response>`);
|
|
133
|
+
lines.push(`</${tag}>`);
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
content: lines.join("\n"),
|
|
137
|
+
details: {
|
|
138
|
+
machine,
|
|
139
|
+
machineLabel,
|
|
140
|
+
paneId: agent.pane_id,
|
|
141
|
+
state: notification
|
|
142
|
+
? "extension-message"
|
|
143
|
+
: blocked
|
|
144
|
+
? "blocked"
|
|
145
|
+
: failed
|
|
146
|
+
? "failed"
|
|
147
|
+
: "finished",
|
|
148
|
+
...(extensionMessages ? { extensionMessages } : {}),
|
|
149
|
+
...(agent.name || record.name ? { name: agent.name || record.name } : {}),
|
|
150
|
+
...(cwd ? { cwd } : {}),
|
|
151
|
+
...(labels.workspace ? { workspace: labels.workspace } : {}),
|
|
152
|
+
...(labels.tab ? { tab: labels.tab } : {}),
|
|
153
|
+
...(task && !notification ? { task } : {}),
|
|
154
|
+
...(blockedMessage ? { blockedOn: blockedMessage } : {}),
|
|
155
|
+
...(reply ? { response: reply.text } : {}),
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function injectAgentEvent(
|
|
161
|
+
pi: ExtensionAPI,
|
|
162
|
+
_ctx: ExtensionContext,
|
|
163
|
+
options: AgentEventOptions,
|
|
164
|
+
): void {
|
|
165
|
+
const tools = pi.getActiveTools();
|
|
166
|
+
const message = agentEvent({
|
|
167
|
+
...options,
|
|
168
|
+
codeMode:
|
|
169
|
+
tools.includes("exec") ||
|
|
170
|
+
tools.includes("code") ||
|
|
171
|
+
tools.includes("notebook"),
|
|
172
|
+
});
|
|
173
|
+
const delivery = { triggerTurn: true, deliverAs: "steer" as const };
|
|
174
|
+
sendPolicyMessage(
|
|
175
|
+
pi,
|
|
176
|
+
{
|
|
177
|
+
customType: AGENT_EVENT_MESSAGE_TYPE,
|
|
178
|
+
content: message.content,
|
|
179
|
+
details: message.details,
|
|
180
|
+
display: true,
|
|
181
|
+
},
|
|
182
|
+
delivery,
|
|
183
|
+
);
|
|
184
|
+
announceAgentEvent(
|
|
185
|
+
pi,
|
|
186
|
+
`pi-shepherdr:${message.details.machine}:${message.details.paneId}`,
|
|
187
|
+
agentVoicePrompt(message.details),
|
|
188
|
+
);
|
|
189
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FocusRequest } from "../types.js";
|
|
2
|
+
|
|
3
|
+
function focusOrigin({ source }: FocusRequest) {
|
|
4
|
+
return { host: source.host, session: source.session, pane: source.pane };
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function focusArrivalContent(
|
|
8
|
+
request: FocusRequest,
|
|
9
|
+
machine: string,
|
|
10
|
+
codeMode: boolean,
|
|
11
|
+
) {
|
|
12
|
+
const returnFocus = {
|
|
13
|
+
action: "focus",
|
|
14
|
+
target: request.source.pane,
|
|
15
|
+
machine,
|
|
16
|
+
voice: request.voice === true,
|
|
17
|
+
};
|
|
18
|
+
const args = JSON.stringify(returnFocus);
|
|
19
|
+
const callable = codeMode ? `await tools.agents(${args})` : `agents ${args}`;
|
|
20
|
+
return {
|
|
21
|
+
returnFocus,
|
|
22
|
+
content: `User arrived from ${JSON.stringify({ ...focusOrigin(request), machine })}\nReturn: ${callable}${request.voice ? "\nVoice transfer pending" : ""}${request.handoff ? `\nHandoff from that session:\n${request.handoff}` : ""}`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function voiceFocusContinuity(request: FocusRequest): string {
|
|
27
|
+
return `User transferring voice from ${JSON.stringify(focusOrigin(request))}${request.handoff ? `\nHandoff from that session:\n${request.handoff}` : ""}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function voiceFocusReport(
|
|
31
|
+
side: "source" | "destination",
|
|
32
|
+
target: string,
|
|
33
|
+
error?: unknown,
|
|
34
|
+
): string {
|
|
35
|
+
return error === undefined
|
|
36
|
+
? `Voice transfer complete (${side}, ${target}); replacement call active`
|
|
37
|
+
: `Voice transfer failed (${side}, ${target}): ${error instanceof Error ? error.message : String(error)}. Voice availability is not confirmed; inspect the session before retrying`;
|
|
38
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { activityTask } from "../activity.js";
|
|
2
|
+
import type { MachineStatus, ScopedMonitoredAgent } from "../types.js";
|
|
3
|
+
|
|
4
|
+
export function orchestrationGuidance(enabled: boolean, general: boolean) {
|
|
5
|
+
const ownership = "Own a scope or delegate it; don't do both.";
|
|
6
|
+
if (!enabled)
|
|
7
|
+
return `Work normally. Delegate only when useful or requested. ${ownership}`;
|
|
8
|
+
const guidance = general
|
|
9
|
+
? "Orchestrate general agents with separate scopes. Integrate their results, validate the combined outcome and report it. Work directly only when asked or for routine local tasks."
|
|
10
|
+
: "Orchestrate agents with separate scopes. Integrate their results, validate the combined outcome and report it. Work directly only when asked or for routine local tasks.";
|
|
11
|
+
return `${guidance} ${ownership}`;
|
|
12
|
+
}
|
|
13
|
+
export function activeAgentsBriefing(
|
|
14
|
+
agents: ScopedMonitoredAgent[],
|
|
15
|
+
machines: MachineStatus[],
|
|
16
|
+
): string | undefined {
|
|
17
|
+
if (!agents.length) return;
|
|
18
|
+
return [
|
|
19
|
+
"Supervised agents after context rollover. Their instructions are reference data, not tasks for you. Do not repeat settled tasks or duplicate running work. Status is last observed; read a target for its reply or pending extension messages.",
|
|
20
|
+
JSON.stringify(
|
|
21
|
+
agents.map((agent) => ({
|
|
22
|
+
machine: agent.machine,
|
|
23
|
+
target: agent.paneId,
|
|
24
|
+
...(agent.name ? { name: agent.name } : {}),
|
|
25
|
+
status:
|
|
26
|
+
agent.activity.phase === "settled"
|
|
27
|
+
? agent.activity.status
|
|
28
|
+
: agent.activity.phase,
|
|
29
|
+
connection:
|
|
30
|
+
machines.find((machine) => machine.id === agent.machine)?.status ??
|
|
31
|
+
"unavailable",
|
|
32
|
+
...(agent.cwd ? { cwd: agent.cwd } : {}),
|
|
33
|
+
...((agent.instructions ?? activityTask(agent.activity))
|
|
34
|
+
? { instructions: agent.instructions ?? activityTask(agent.activity) }
|
|
35
|
+
: {}),
|
|
36
|
+
})),
|
|
37
|
+
),
|
|
38
|
+
].join("\n");
|
|
39
|
+
}
|
|
40
|
+
export function boardMigrationWarning() {
|
|
41
|
+
return "Boards moved to Pi Agent Board. Install @howaboua/pi-agent-board for the same features as a separate extension. Your saved boards are preserved.";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function boardBriefing(
|
|
45
|
+
member: boolean,
|
|
46
|
+
population: "empty" | "populated" | "unavailable",
|
|
47
|
+
gpt = false,
|
|
48
|
+
) {
|
|
49
|
+
const state =
|
|
50
|
+
population === "populated"
|
|
51
|
+
? "Read relevant board threads."
|
|
52
|
+
: population === "empty"
|
|
53
|
+
? gpt
|
|
54
|
+
? "Shared board available; posts=none."
|
|
55
|
+
: "Shared board available; no posts yet."
|
|
56
|
+
: gpt
|
|
57
|
+
? "Shared board status unavailable; board help→retry read when available."
|
|
58
|
+
: "Shared board status unavailable. Check board help and retry reading when available.";
|
|
59
|
+
const setup = member
|
|
60
|
+
? gpt
|
|
61
|
+
? "Root owns setup; follow assigned task."
|
|
62
|
+
: "The root agent owns setup; follow your assigned task."
|
|
63
|
+
: "";
|
|
64
|
+
if (gpt)
|
|
65
|
+
return [
|
|
66
|
+
state,
|
|
67
|
+
setup,
|
|
68
|
+
"Posts=work-changing ownership/decisions/findings/blockers only. Existing thread replies; link≠repeat. Personal checkpoints→notes. No ack/status spam/duplicate completion reports. Assignments/urgent messages→agents.",
|
|
69
|
+
"Channels=workstreams; threads=topics. Reuse relevant channels≠catchalls. New channel requires distinct coordination purpose; never task/result announcement only.",
|
|
70
|
+
]
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join(" ");
|
|
73
|
+
return (
|
|
74
|
+
[
|
|
75
|
+
state,
|
|
76
|
+
setup,
|
|
77
|
+
"Post only new information that changes another agent's work: ownership, decisions, findings or blockers. Reply in existing threads; link rather than repeat. Keep personal checkpoints in notes. Skip acknowledgements, routine status and duplicated completion reports. Use agents for assignments and urgent messages.",
|
|
78
|
+
]
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.join(" ") +
|
|
81
|
+
"\n\nChannels group shared workstreams; threads group topics. Reuse a relevant channel, not a catch-all. Create a channel only for a distinct coordination need, never just to announce a task or result."
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ExtensionAPI,
|
|
3
|
+
getMarkdownTheme,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { Box, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
|
|
6
|
+
import {
|
|
7
|
+
AGENT_EVENT_MESSAGE_TYPE,
|
|
8
|
+
type AgentEventDetails,
|
|
9
|
+
eventDetails,
|
|
10
|
+
} from "./event-details.js";
|
|
11
|
+
|
|
12
|
+
export function registerAgentEventRenderer(pi: ExtensionAPI): void {
|
|
13
|
+
pi.registerMessageRenderer<AgentEventDetails>(
|
|
14
|
+
AGENT_EVENT_MESSAGE_TYPE,
|
|
15
|
+
(message, { expanded, outputPad }, theme) => {
|
|
16
|
+
const details = eventDetails(message.details);
|
|
17
|
+
if (!details) {
|
|
18
|
+
const box = new Box(outputPad, 1, (value) =>
|
|
19
|
+
theme.bg("customMessageBg", value),
|
|
20
|
+
);
|
|
21
|
+
box.addChild(
|
|
22
|
+
new Text(
|
|
23
|
+
typeof message.content === "string"
|
|
24
|
+
? message.content
|
|
25
|
+
: "Herdr agent event unavailable",
|
|
26
|
+
0,
|
|
27
|
+
0,
|
|
28
|
+
),
|
|
29
|
+
);
|
|
30
|
+
return box;
|
|
31
|
+
}
|
|
32
|
+
const blocked = details?.state === "blocked";
|
|
33
|
+
const failed = details?.state === "failed";
|
|
34
|
+
const notification = details.state === "extension-message";
|
|
35
|
+
const agentIdentity = details?.name
|
|
36
|
+
? `${details.name} (${details.paneId})`
|
|
37
|
+
: (details?.paneId ?? "unknown");
|
|
38
|
+
const identity = `${details.machineLabel ?? details.machine} / ${agentIdentity}`;
|
|
39
|
+
const title = theme.fg(
|
|
40
|
+
blocked || failed ? "error" : "success",
|
|
41
|
+
`Herdr agent ${identity} · ${notification ? "extension message pending" : blocked ? "blocked" : failed ? "failed" : "finished"}`,
|
|
42
|
+
);
|
|
43
|
+
const location = [details?.workspace, details?.tab]
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
.join(" / ");
|
|
46
|
+
const metadata = [location, details?.cwd].filter(Boolean).join(" · ");
|
|
47
|
+
const box = new Box(outputPad, 1, (value) =>
|
|
48
|
+
theme.bg("customMessageBg", value),
|
|
49
|
+
);
|
|
50
|
+
box.addChild(new Text(title, 0, 0));
|
|
51
|
+
if (metadata) box.addChild(new Text(theme.fg("dim", metadata), 0, 0));
|
|
52
|
+
if (blocked || notification) {
|
|
53
|
+
box.addChild(new Spacer(1));
|
|
54
|
+
box.addChild(
|
|
55
|
+
new Text(
|
|
56
|
+
theme.fg(
|
|
57
|
+
"warning",
|
|
58
|
+
details?.blockedOn ??
|
|
59
|
+
(notification
|
|
60
|
+
? "Extension message pending"
|
|
61
|
+
: "Agent needs input or approval"),
|
|
62
|
+
),
|
|
63
|
+
0,
|
|
64
|
+
0,
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
if (details.extensionMessages && expanded) {
|
|
68
|
+
for (const message of details.extensionMessages) {
|
|
69
|
+
box.addChild(new Spacer(1));
|
|
70
|
+
box.addChild(
|
|
71
|
+
new Markdown(message.message, 0, 0, getMarkdownTheme()),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (expanded && details?.task) {
|
|
77
|
+
box.addChild(new Spacer(1));
|
|
78
|
+
box.addChild(new Text(theme.fg("muted", "Task"), 0, 0));
|
|
79
|
+
box.addChild(new Markdown(details.task, 0, 0, getMarkdownTheme()));
|
|
80
|
+
}
|
|
81
|
+
if (details?.response) {
|
|
82
|
+
box.addChild(new Spacer(1));
|
|
83
|
+
box.addChild(new Text(theme.fg("muted", "Response"), 0, 0));
|
|
84
|
+
box.addChild(new Markdown(details.response, 0, 0, getMarkdownTheme()));
|
|
85
|
+
}
|
|
86
|
+
return box;
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { PeerMessage } from "../types.js";
|
|
3
|
+
import type { AgentEventDetails } from "./event-details.js";
|
|
4
|
+
|
|
5
|
+
const REALTIME_VOICE_PROMPT_CHANNEL =
|
|
6
|
+
"@howaboua/pi-codex-conversion/realtime-voice-prompt/v1";
|
|
7
|
+
const MAX_REALTIME_VOICE_PROMPT_BYTES = 8 * 1_024;
|
|
8
|
+
|
|
9
|
+
function boundedVoicePrompt(prompt: string): string {
|
|
10
|
+
const bytes = new TextEncoder().encode(prompt);
|
|
11
|
+
if (bytes.byteLength <= MAX_REALTIME_VOICE_PROMPT_BYTES) return prompt;
|
|
12
|
+
return new TextDecoder()
|
|
13
|
+
.decode(bytes.subarray(0, MAX_REALTIME_VOICE_PROMPT_BYTES), {
|
|
14
|
+
stream: true,
|
|
15
|
+
})
|
|
16
|
+
.trimEnd();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function agentVoicePrompt(details: AgentEventDetails): string {
|
|
20
|
+
const lines = [
|
|
21
|
+
`Worker: ${details.machineLabel ?? details.machine} / ${details.name?.trim() || "unnamed"}`,
|
|
22
|
+
`State: ${details.state}`,
|
|
23
|
+
];
|
|
24
|
+
if (details.task?.trim()) lines.push(`Task:\n${details.task.trim()}`);
|
|
25
|
+
let instruction: string;
|
|
26
|
+
if (details.state === "blocked" || details.state === "extension-message") {
|
|
27
|
+
instruction =
|
|
28
|
+
details.state === "extension-message"
|
|
29
|
+
? "Briefly tell the user what this worker reports."
|
|
30
|
+
: "Briefly tell the user why this monitored worker is blocked and what attention may be required.";
|
|
31
|
+
if (details.blockedOn?.trim())
|
|
32
|
+
lines.push(`Reason:\n${details.blockedOn.trim()}`);
|
|
33
|
+
if (details.extensionMessages)
|
|
34
|
+
lines.push(
|
|
35
|
+
...details.extensionMessages.map((message) => message.message),
|
|
36
|
+
);
|
|
37
|
+
} else {
|
|
38
|
+
instruction =
|
|
39
|
+
details.state === "failed"
|
|
40
|
+
? "Briefly tell the user that this monitored worker failed and include useful detail from its report."
|
|
41
|
+
: "Briefly tell the user what this monitored worker found or completed; do not merely announce that it finished.";
|
|
42
|
+
if (details.response?.trim())
|
|
43
|
+
lines.push(`Report:\n${details.response.trim()}`);
|
|
44
|
+
}
|
|
45
|
+
return boundedVoicePrompt(`${instruction}\n\n${lines.join("\n\n")}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function announceAgentEvent(
|
|
49
|
+
pi: ExtensionAPI,
|
|
50
|
+
candidateId: string,
|
|
51
|
+
prompt: string,
|
|
52
|
+
): void {
|
|
53
|
+
const id =
|
|
54
|
+
new TextEncoder().encode(candidateId).byteLength <= 160
|
|
55
|
+
? candidateId
|
|
56
|
+
: "pi-shepherdr:worker";
|
|
57
|
+
pi.events.emit(REALTIME_VOICE_PROMPT_CHANNEL, { id, active: true, prompt });
|
|
58
|
+
pi.events.emit(REALTIME_VOICE_PROMPT_CHANNEL, { id, active: false, prompt });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function announcePeerMessage(
|
|
62
|
+
pi: ExtensionAPI,
|
|
63
|
+
message: PeerMessage,
|
|
64
|
+
): void {
|
|
65
|
+
const source = Object.fromEntries(
|
|
66
|
+
Array.from(
|
|
67
|
+
message.sender.matchAll(/ ([a-z_]+)="([^"]*)"/g),
|
|
68
|
+
([, key, value]) => [key, value],
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
if (source["kind"] !== "message" || message.text.startsWith("/")) return;
|
|
72
|
+
announceAgentEvent(
|
|
73
|
+
pi,
|
|
74
|
+
`pi-shepherdr:${source["host"] ?? "local"}:${source["pane"] ?? "peer"}`,
|
|
75
|
+
boundedVoicePrompt(
|
|
76
|
+
`Briefly tell the user the useful update from this peer.\n\nPeer: ${source["host"] ?? "local"} / ${source["name"] || source["pane"] || "unnamed"}\n\nUpdate:\n${message.text.trim()}`,
|
|
77
|
+
),
|
|
78
|
+
);
|
|
79
|
+
}
|
package/src/monitor.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
import { isSettledStatus } from "./activity.js";
|
|
6
6
|
import { getSnapshot } from "./herdr.js";
|
|
7
7
|
import { type HerdrConnection, isDispatchRejected } from "./herdr-client.js";
|
|
8
|
-
import { injectAgentEvent } from "./messages.js";
|
|
8
|
+
import { injectAgentEvent } from "./messages/events.js";
|
|
9
9
|
import { parseMonitorEvent } from "./monitor-event.js";
|
|
10
10
|
import { MonitorEvents } from "./monitor-events.js";
|
|
11
11
|
import { MonitorExtensionMessages } from "./monitor-extension-messages.js";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
type ClaimedSettlement,
|
|
16
16
|
SettlementReporter,
|
|
17
17
|
type SettlementRequest,
|
|
18
|
-
} from "./settlement.js";
|
|
18
|
+
} from "./settlement/index.js";
|
|
19
19
|
import type {
|
|
20
20
|
ExtensionReply,
|
|
21
21
|
HerdrEvent,
|
package/src/peer-inbox.ts
CHANGED
|
@@ -8,10 +8,10 @@ import type {
|
|
|
8
8
|
import { acceptFocus, readFocus } from "./agents-focus.js";
|
|
9
9
|
import { sendPolicyMessage } from "./delivery.js";
|
|
10
10
|
import { dispatchExtensionReply } from "./extension-reply.js";
|
|
11
|
-
import type { AgentFleet } from "./fleet.js";
|
|
11
|
+
import type { AgentFleet } from "./fleet/index.js";
|
|
12
12
|
import { getCurrentPane } from "./herdr.js";
|
|
13
13
|
import { HerdrClient } from "./herdr-client.js";
|
|
14
|
-
import { announcePeerMessage } from "./messages.js";
|
|
14
|
+
import { announcePeerMessage } from "./messages/voice-announcements.js";
|
|
15
15
|
import { acceptFocusChannel } from "./peer-channel.js";
|
|
16
16
|
import type { createPeerCommands } from "./peer-commands.js";
|
|
17
17
|
import {
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { HerdrConnection } from "../herdr-client.js";
|
|
2
|
+
import type { SshMachine } from "../machine-catalog.js";
|
|
3
|
+
import type { AssistantReader } from "../session-reader.js";
|
|
4
|
+
import type {
|
|
5
|
+
LatestAssistant,
|
|
6
|
+
PaneInfo,
|
|
7
|
+
PeerDelivery,
|
|
8
|
+
PeerMessage,
|
|
9
|
+
SessionView,
|
|
10
|
+
} from "../types.js";
|
|
11
|
+
import { connectRemoteBridge } from "./deployment.js";
|
|
12
|
+
import { readPeerCommands } from "./shepherdr-peer.mjs";
|
|
13
|
+
import { RemoteTransport } from "./transport.js";
|
|
14
|
+
|
|
15
|
+
/** Operation-specific RPC shapes and responses; transport owns all live resources. */
|
|
16
|
+
export class RemoteHerdrClient
|
|
17
|
+
extends RemoteTransport
|
|
18
|
+
implements HerdrConnection, AssistantReader
|
|
19
|
+
{
|
|
20
|
+
static async connect(
|
|
21
|
+
config: SshMachine,
|
|
22
|
+
onClose: (error: Error) => void,
|
|
23
|
+
): Promise<RemoteHerdrClient> {
|
|
24
|
+
const child = await connectRemoteBridge(config);
|
|
25
|
+
const client = new RemoteHerdrClient(child, onClose);
|
|
26
|
+
try {
|
|
27
|
+
await client.ready();
|
|
28
|
+
return client;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
client.close();
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async request<T>(
|
|
36
|
+
method: string,
|
|
37
|
+
params: object = {},
|
|
38
|
+
timeoutMs = 10_000,
|
|
39
|
+
): Promise<T> {
|
|
40
|
+
return (await this.call(
|
|
41
|
+
{ op: "request", method, params, timeoutMs },
|
|
42
|
+
timeoutMs + 1_000,
|
|
43
|
+
)) as T;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async replyExtension(
|
|
47
|
+
agent: PaneInfo,
|
|
48
|
+
reply: import("../types.js").ExtensionReply,
|
|
49
|
+
): Promise<string> {
|
|
50
|
+
const result = await this.call(
|
|
51
|
+
{ op: "extension-reply", agent, reply },
|
|
52
|
+
60_000,
|
|
53
|
+
);
|
|
54
|
+
if (typeof result !== "string")
|
|
55
|
+
throw new Error(
|
|
56
|
+
"Invalid extension reply receipt; inspect the target before retrying",
|
|
57
|
+
);
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async commands(
|
|
62
|
+
agent: PaneInfo,
|
|
63
|
+
): Promise<import("../types.js").PeerCommand[]> {
|
|
64
|
+
const result = await this.call({ op: "commands", agent }, 26_000);
|
|
65
|
+
return readPeerCommands(result);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async sendMessage(
|
|
69
|
+
agent: PaneInfo,
|
|
70
|
+
message: PeerMessage,
|
|
71
|
+
): Promise<PeerDelivery> {
|
|
72
|
+
const result = await this.call(
|
|
73
|
+
{ op: "message", agent, message },
|
|
74
|
+
message.text.trim() === "/quit" ? 0 : 26_000,
|
|
75
|
+
);
|
|
76
|
+
if (
|
|
77
|
+
!result ||
|
|
78
|
+
typeof result !== "object" ||
|
|
79
|
+
!("command" in result) ||
|
|
80
|
+
typeof result.command !== "boolean"
|
|
81
|
+
)
|
|
82
|
+
throw new Error(
|
|
83
|
+
"Invalid peer acknowledgement; inspect the target before retrying",
|
|
84
|
+
);
|
|
85
|
+
return { command: result.command };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async machineIdentity(): Promise<import("../types.js").MachineIdentity> {
|
|
89
|
+
const result = await this.call({ op: "identity" });
|
|
90
|
+
if (
|
|
91
|
+
!result ||
|
|
92
|
+
typeof result !== "object" ||
|
|
93
|
+
!("host" in result) ||
|
|
94
|
+
typeof result.host !== "string" ||
|
|
95
|
+
!("session" in result) ||
|
|
96
|
+
typeof result.session !== "string"
|
|
97
|
+
)
|
|
98
|
+
throw new Error("Could not identify remote Herdr session");
|
|
99
|
+
return { host: result.host, session: result.session };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
focus(
|
|
103
|
+
agent: PaneInfo,
|
|
104
|
+
request: import("../types.js").FocusRequest,
|
|
105
|
+
): Promise<unknown> {
|
|
106
|
+
return this.call({ op: "focus", agent, request }, 60_000);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async latest(path?: string): Promise<LatestAssistant | undefined> {
|
|
110
|
+
return (await this.view(path)).assistant;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async view(path?: string): Promise<SessionView> {
|
|
114
|
+
return (await this.call({ op: "view", path })) as SessionView;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async keybindings(): Promise<Record<string, unknown>> {
|
|
118
|
+
return (await this.call({ op: "keybindings" })) as Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async directory(
|
|
122
|
+
value: string | undefined,
|
|
123
|
+
fallback: string,
|
|
124
|
+
): Promise<string> {
|
|
125
|
+
return (await this.call({ op: "directory", value, fallback })) as string;
|
|
126
|
+
}
|
|
127
|
+
}
|