@howaboua/pi-shepherdr 0.2.15 → 0.2.17
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 +25 -0
- package/README.md +42 -33
- package/index.ts +16 -26
- package/package.json +11 -11
- package/src/agents-contract.ts +36 -8
- package/src/agents-discovery.ts +23 -7
- package/src/agents-focus.ts +242 -0
- package/src/agents-spawn.ts +23 -0
- package/src/agents-tool.ts +46 -6
- package/src/attachment-protocol.ts +7 -3
- package/src/attachment-target.ts +3 -1
- package/src/attachment.ts +3 -1
- package/src/board/host.ts +98 -366
- package/src/board/membership.ts +14 -8
- package/src/command-config.ts +51 -0
- package/src/control-panel-actions.ts +0 -20
- package/src/control-panel-items.ts +8 -36
- package/src/control-panel-view.ts +2 -11
- package/src/control-panel.ts +2 -11
- package/src/controller.ts +5 -5
- package/src/delivery.ts +0 -33
- package/src/herdr-client.ts +52 -6
- package/src/messages.ts +61 -61
- package/src/monitor-events.ts +24 -2
- package/src/monitor-questions.ts +12 -3
- package/src/monitor.ts +2 -2
- package/src/peer-channel.ts +39 -0
- package/src/peer-commands.ts +187 -0
- package/src/peer-inbox.ts +232 -55
- package/src/remote/shepherdr-channel.mjs +225 -0
- package/src/remote/shepherdr-checkpoints.mjs +5 -3
- package/src/remote/shepherdr-peer.mjs +198 -22
- package/src/remote/shepherdr.mjs +63 -8
- package/src/remote-client.ts +121 -11
- package/src/settlement.ts +1 -0
- package/src/shared-context.ts +104 -1
- package/src/types.ts +29 -0
- package/src/voice-handoff.ts +177 -0
- package/src/board/archive.ts +0 -77
- package/src/board/awareness.ts +0 -115
- package/src/board/config.ts +0 -121
- package/src/board/contract.ts +0 -181
- package/src/board/identity.ts +0 -169
- package/src/board/paging.ts +0 -55
- package/src/board/protocol.ts +0 -73
- package/src/board/queries.ts +0 -176
- package/src/board/response.ts +0 -56
- package/src/board/store.ts +0 -327
- package/src/board/tool.ts +0 -23
- package/src/board/turns.ts +0 -100
- package/src/context-briefing.ts +0 -226
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
1
|
import type { PanelOwners } from "./control-panel-items.js";
|
|
3
2
|
import { type SshSetupDraft, sshSetupArgs } from "./ssh-setup.js";
|
|
4
3
|
|
|
@@ -16,7 +15,6 @@ export class PanelActions {
|
|
|
16
15
|
busy = false;
|
|
17
16
|
message: string;
|
|
18
17
|
|
|
19
|
-
private readonly ctx: ExtensionContext;
|
|
20
18
|
private readonly options: PanelOptions;
|
|
21
19
|
private readonly signal: AbortSignal;
|
|
22
20
|
private readonly current: () => boolean;
|
|
@@ -26,7 +24,6 @@ export class PanelActions {
|
|
|
26
24
|
private readonly finish: (result: "add" | undefined) => void;
|
|
27
25
|
|
|
28
26
|
constructor(
|
|
29
|
-
ctx: ExtensionContext,
|
|
30
27
|
options: PanelOptions,
|
|
31
28
|
signal: AbortSignal,
|
|
32
29
|
message: string,
|
|
@@ -36,7 +33,6 @@ export class PanelActions {
|
|
|
36
33
|
requestRender: () => void,
|
|
37
34
|
finish: (result: "add" | undefined) => void,
|
|
38
35
|
) {
|
|
39
|
-
this.ctx = ctx;
|
|
40
36
|
this.options = options;
|
|
41
37
|
this.signal = signal;
|
|
42
38
|
this.current = current;
|
|
@@ -62,22 +58,6 @@ export class PanelActions {
|
|
|
62
58
|
if (id === "orchestration") {
|
|
63
59
|
await this.options.setOrchestration(value === "on", this.signal);
|
|
64
60
|
this.message = "Guidance saved for this session.";
|
|
65
|
-
} else if (
|
|
66
|
-
id === "board:session" ||
|
|
67
|
-
id === "board:folder" ||
|
|
68
|
-
id === "board:global"
|
|
69
|
-
) {
|
|
70
|
-
await this.options.board.setSetting(
|
|
71
|
-
this.ctx,
|
|
72
|
-
id === "board:session"
|
|
73
|
-
? "session"
|
|
74
|
-
: id === "board:folder"
|
|
75
|
-
? "folder"
|
|
76
|
-
: "global",
|
|
77
|
-
value === "inherit" ? undefined : value === "on",
|
|
78
|
-
);
|
|
79
|
-
this.check();
|
|
80
|
-
this.message = "Board setting saved.";
|
|
81
61
|
} else if (id === "connect" || id.startsWith("machine:"))
|
|
82
62
|
this.message = await this.options.reconnect(
|
|
83
63
|
id === "connect" ? undefined : id.slice(8),
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
1
|
import type { SettingItem } from "@earendil-works/pi-tui";
|
|
3
|
-
import
|
|
2
|
+
import { commandConfigPath } from "./command-config.js";
|
|
4
3
|
import type { AgentFleet } from "./fleet.js";
|
|
5
4
|
import { type SshSetupDraft, sshSetupItems } from "./ssh-setup.js";
|
|
6
5
|
|
|
@@ -8,12 +7,10 @@ export const PANEL_TABS = ["Settings", "Status", "Connections"] as const;
|
|
|
8
7
|
export type PanelTab = (typeof PANEL_TABS)[number];
|
|
9
8
|
export interface PanelOwners {
|
|
10
9
|
fleet: AgentFleet;
|
|
11
|
-
board: AgentBoard;
|
|
12
10
|
orchestration: () => boolean;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
export function buildPanelItems(
|
|
16
|
-
ctx: ExtensionContext,
|
|
17
14
|
options: PanelOwners,
|
|
18
15
|
tab: PanelTab,
|
|
19
16
|
draft: SshSetupDraft,
|
|
@@ -48,7 +45,13 @@ export function buildPanelItems(
|
|
|
48
45
|
.join("\n"),
|
|
49
46
|
})),
|
|
50
47
|
];
|
|
51
|
-
|
|
48
|
+
return [
|
|
49
|
+
{
|
|
50
|
+
id: "agent-commands",
|
|
51
|
+
label: "Agent commands",
|
|
52
|
+
currentValue: "",
|
|
53
|
+
description: `Built-in commands and skills are available. Custom extension commands require an allowlist in Shepherdr’s config. Prompt templates are also supported, but you will need to inform your agent about their existence separately.\nConfig: ${commandConfigPath()}`,
|
|
54
|
+
},
|
|
52
55
|
{
|
|
53
56
|
id: "orchestration",
|
|
54
57
|
label: "Prioritize delegation",
|
|
@@ -57,35 +60,4 @@ export function buildPanelItems(
|
|
|
57
60
|
description: "Prefer delegation over direct work in this session.",
|
|
58
61
|
},
|
|
59
62
|
];
|
|
60
|
-
try {
|
|
61
|
-
const settings = options.board.settings(ctx);
|
|
62
|
-
for (const scope of ["session", "folder", "global"] as const) {
|
|
63
|
-
if (scope === "folder" && !settings.paths.folder) continue;
|
|
64
|
-
rows.push({
|
|
65
|
-
id: `board:${scope}`,
|
|
66
|
-
label: `Board ${scope}`,
|
|
67
|
-
currentValue:
|
|
68
|
-
settings[scope] === undefined
|
|
69
|
-
? "inherit"
|
|
70
|
-
: settings[scope]
|
|
71
|
-
? "on"
|
|
72
|
-
: "off",
|
|
73
|
-
values: scope === "global" ? ["off", "on"] : ["inherit", "on", "off"],
|
|
74
|
-
description:
|
|
75
|
-
scope === "session"
|
|
76
|
-
? "Overrides folder and global defaults. Inherit removes the override."
|
|
77
|
-
: scope === "folder"
|
|
78
|
-
? "Default for this exact launch folder, unless overridden by the session."
|
|
79
|
-
: "Default for sessions without a session or folder override.",
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
rows.push({
|
|
84
|
-
id: "board-owner",
|
|
85
|
-
label: "Board settings",
|
|
86
|
-
currentValue: "unavailable",
|
|
87
|
-
description: error instanceof Error ? error.message : String(error),
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return rows;
|
|
91
63
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type ExtensionContext,
|
|
3
2
|
getSettingsListTheme,
|
|
4
3
|
type Theme,
|
|
5
4
|
} from "@earendil-works/pi-coding-agent";
|
|
@@ -36,7 +35,6 @@ export class PanelView {
|
|
|
36
35
|
private listHeight = 0;
|
|
37
36
|
private pressedRow: string | undefined;
|
|
38
37
|
|
|
39
|
-
private readonly ctx: ExtensionContext;
|
|
40
38
|
private readonly owners: PanelOwners;
|
|
41
39
|
private readonly tui: TUI;
|
|
42
40
|
private readonly theme: Theme;
|
|
@@ -47,7 +45,6 @@ export class PanelView {
|
|
|
47
45
|
private readonly close: () => void;
|
|
48
46
|
|
|
49
47
|
constructor(
|
|
50
|
-
ctx: ExtensionContext,
|
|
51
48
|
owners: PanelOwners,
|
|
52
49
|
tui: TUI,
|
|
53
50
|
theme: Theme,
|
|
@@ -57,7 +54,6 @@ export class PanelView {
|
|
|
57
54
|
current: () => boolean,
|
|
58
55
|
close: () => void,
|
|
59
56
|
) {
|
|
60
|
-
this.ctx = ctx;
|
|
61
57
|
this.owners = owners;
|
|
62
58
|
this.tui = tui;
|
|
63
59
|
this.theme = theme;
|
|
@@ -71,12 +67,7 @@ export class PanelView {
|
|
|
71
67
|
rebuild() {
|
|
72
68
|
if (!this.current() || this.editing) return;
|
|
73
69
|
try {
|
|
74
|
-
this.definitions = buildPanelItems(
|
|
75
|
-
this.ctx,
|
|
76
|
-
this.owners,
|
|
77
|
-
this.tab,
|
|
78
|
-
this.draft,
|
|
79
|
-
);
|
|
70
|
+
this.definitions = buildPanelItems(this.owners, this.tab, this.draft);
|
|
80
71
|
} catch (error) {
|
|
81
72
|
this.actions.message =
|
|
82
73
|
error instanceof Error ? error.message : String(error);
|
|
@@ -157,7 +148,7 @@ export class PanelView {
|
|
|
157
148
|
"",
|
|
158
149
|
...wrap(
|
|
159
150
|
this.tab === "Settings"
|
|
160
|
-
?
|
|
151
|
+
? ""
|
|
161
152
|
: this.tab === "Connections"
|
|
162
153
|
? "Remote needs Node on SSH PATH and Pi with Herdr integration. Herdr prepares its server before saving."
|
|
163
154
|
: `${this.owners.fleet.isActive() ? "" : "Run Pi inside Herdr. "}Add SSH targets in Connections; select a machine here to reconnect.`,
|
package/src/control-panel.ts
CHANGED
|
@@ -4,13 +4,9 @@ import type { PanelTab as Tab } from "./control-panel-items.js";
|
|
|
4
4
|
import { PanelView } from "./control-panel-view.js";
|
|
5
5
|
import { addSshConnection, type SshSetupDraft } from "./ssh-setup.js";
|
|
6
6
|
|
|
7
|
-
export function controlPanelStatus(
|
|
8
|
-
ctx: ExtensionContext,
|
|
9
|
-
options: PanelOptions,
|
|
10
|
-
): string {
|
|
7
|
+
export function controlPanelStatus(options: PanelOptions): string {
|
|
11
8
|
return [
|
|
12
9
|
`Orchestration ${options.orchestration() ? "on" : "off"}.`,
|
|
13
|
-
options.board.status(ctx),
|
|
14
10
|
...options.fleet
|
|
15
11
|
.statuses()
|
|
16
12
|
.map(
|
|
@@ -94,7 +90,6 @@ async function showControlPanel(
|
|
|
94
90
|
if (!current()) throw new Error("Session changed; reopen /herdr");
|
|
95
91
|
};
|
|
96
92
|
const actions = new PanelActions(
|
|
97
|
-
ctx,
|
|
98
93
|
options,
|
|
99
94
|
signal,
|
|
100
95
|
state.message,
|
|
@@ -105,7 +100,6 @@ async function showControlPanel(
|
|
|
105
100
|
finish,
|
|
106
101
|
);
|
|
107
102
|
const view = new PanelView(
|
|
108
|
-
ctx,
|
|
109
103
|
options,
|
|
110
104
|
tui,
|
|
111
105
|
theme,
|
|
@@ -125,10 +119,7 @@ async function showControlPanel(
|
|
|
125
119
|
cleanup();
|
|
126
120
|
done(result);
|
|
127
121
|
}
|
|
128
|
-
const subscriptions = [
|
|
129
|
-
options.fleet.subscribe(() => view.rebuild()),
|
|
130
|
-
options.board.subscribe(() => view.rebuild()),
|
|
131
|
-
];
|
|
122
|
+
const subscriptions = [options.fleet.subscribe(() => view.rebuild())];
|
|
132
123
|
function cleanup() {
|
|
133
124
|
disposed = true;
|
|
134
125
|
signal.removeEventListener("abort", close);
|
package/src/controller.ts
CHANGED
|
@@ -2,17 +2,17 @@ import type {
|
|
|
2
2
|
ExtensionAPI,
|
|
3
3
|
ExtensionContext,
|
|
4
4
|
} from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import type { AgentBoard } from "./board/host.js";
|
|
6
5
|
import {
|
|
7
6
|
contextBriefingWindow,
|
|
8
7
|
hasContextRollover,
|
|
9
8
|
recordContextBriefing,
|
|
10
9
|
registerContextBriefing,
|
|
11
|
-
} from "
|
|
10
|
+
} from "@howaboua/pi-agent-board/integration";
|
|
12
11
|
import { controlPanelStatus, openControlPanel } from "./control-panel.js";
|
|
13
12
|
import { sendPolicyMessage } from "./delivery.js";
|
|
14
13
|
import type { AgentFleet } from "./fleet.js";
|
|
15
14
|
import { activeAgentsBriefing, orchestrationGuidance } from "./messages.js";
|
|
15
|
+
import type { createPeerCommands } from "./peer-commands.js";
|
|
16
16
|
import { loadAgentProfiles } from "./profiles.js";
|
|
17
17
|
|
|
18
18
|
const ORCHESTRATION_STATE_TYPE = "pi-shepherdr-orchestration-state";
|
|
@@ -20,7 +20,7 @@ const ORCHESTRATION_STATE_TYPE = "pi-shepherdr-orchestration-state";
|
|
|
20
20
|
export function registerAgentController(
|
|
21
21
|
pi: ExtensionAPI,
|
|
22
22
|
fleet: AgentFleet,
|
|
23
|
-
|
|
23
|
+
peerCommands: ReturnType<typeof createPeerCommands>,
|
|
24
24
|
): void {
|
|
25
25
|
let orchestrationEnabled = false;
|
|
26
26
|
const panels = new Set<Promise<void>>();
|
|
@@ -127,6 +127,7 @@ export function registerAgentController(
|
|
|
127
127
|
pi.registerCommand("herdr", {
|
|
128
128
|
description: "Shepherdr settings, status and SSH setup",
|
|
129
129
|
handler: async (args, ctx) => {
|
|
130
|
+
if (await peerCommands.handle(args, ctx)) return;
|
|
130
131
|
const commandSignal = sessionLifetime.signal;
|
|
131
132
|
const commandSessionId = ctx.sessionManager.getSessionId();
|
|
132
133
|
const current = () =>
|
|
@@ -138,7 +139,6 @@ export function registerAgentController(
|
|
|
138
139
|
}
|
|
139
140
|
const options = {
|
|
140
141
|
fleet,
|
|
141
|
-
board,
|
|
142
142
|
orchestration: () => orchestrationEnabled,
|
|
143
143
|
setOrchestration: (enabled: boolean, signal: AbortSignal) =>
|
|
144
144
|
setOrchestration(ctx, enabled, signal),
|
|
@@ -156,7 +156,7 @@ export function registerAgentController(
|
|
|
156
156
|
} finally {
|
|
157
157
|
panels.delete(panel);
|
|
158
158
|
}
|
|
159
|
-
} else ctx.ui.notify(controlPanelStatus(
|
|
159
|
+
} else ctx.ui.notify(controlPanelStatus(options), "info");
|
|
160
160
|
} catch (error) {
|
|
161
161
|
if (current()) ctx.ui.notify(String(error), "error");
|
|
162
162
|
}
|
package/src/delivery.ts
CHANGED
|
@@ -3,11 +3,8 @@ import type {
|
|
|
3
3
|
ExtensionContext,
|
|
4
4
|
} from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import type {
|
|
6
|
-
CodexContextBriefingHandler,
|
|
7
6
|
CodexDeveloperCustomMessage,
|
|
8
7
|
CodexDeveloperMessageOptions,
|
|
9
|
-
hasCodexContextBriefingHost,
|
|
10
|
-
registerCodexContextBriefing,
|
|
11
8
|
trySendCodexDeveloperCustomMessage,
|
|
12
9
|
tryStartCodexPreparedIdleKickoff,
|
|
13
10
|
tryStartCodexPreparedIdlePrompt,
|
|
@@ -29,14 +26,6 @@ const preparedPrompts = new WeakMap<
|
|
|
29
26
|
ExtensionAPI,
|
|
30
27
|
typeof tryStartCodexPreparedIdlePrompt
|
|
31
28
|
>();
|
|
32
|
-
const briefingHosts = new WeakMap<
|
|
33
|
-
ExtensionAPI,
|
|
34
|
-
{
|
|
35
|
-
register: typeof registerCodexContextBriefing;
|
|
36
|
-
available: typeof hasCodexContextBriefingHost;
|
|
37
|
-
}
|
|
38
|
-
>();
|
|
39
|
-
const outdatedBriefingHosts = new WeakSet<ExtensionAPI>();
|
|
40
29
|
const PACKAGE = "@howaboua/pi-codex-conversion";
|
|
41
30
|
const MODULE = `${PACKAGE}/developer-messages`;
|
|
42
31
|
|
|
@@ -53,15 +42,6 @@ export async function registerDeveloperDelivery(
|
|
|
53
42
|
preparedKickoffs.set(pi, api.tryStartCodexPreparedIdleKickoff);
|
|
54
43
|
if (typeof api.tryStartCodexPreparedIdlePrompt === "function")
|
|
55
44
|
preparedPrompts.set(pi, api.tryStartCodexPreparedIdlePrompt);
|
|
56
|
-
if (
|
|
57
|
-
typeof api.registerCodexContextBriefing === "function" &&
|
|
58
|
-
typeof api.hasCodexContextBriefingHost === "function"
|
|
59
|
-
)
|
|
60
|
-
briefingHosts.set(pi, {
|
|
61
|
-
register: api.registerCodexContextBriefing,
|
|
62
|
-
available: api.hasCodexContextBriefingHost,
|
|
63
|
-
});
|
|
64
|
-
else outdatedBriefingHosts.add(pi);
|
|
65
45
|
} catch (error) {
|
|
66
46
|
if (!isUnavailable(error)) throw error;
|
|
67
47
|
}
|
|
@@ -109,19 +89,6 @@ export async function registerDeveloperDelivery(
|
|
|
109
89
|
});
|
|
110
90
|
}
|
|
111
91
|
|
|
112
|
-
export function registerInferenceBriefing(
|
|
113
|
-
pi: ExtensionAPI,
|
|
114
|
-
handler: CodexContextBriefingHandler,
|
|
115
|
-
) {
|
|
116
|
-
const host = briefingHosts.get(pi);
|
|
117
|
-
const unregister = host?.register(pi, handler);
|
|
118
|
-
pi.on("session_shutdown", () => unregister?.());
|
|
119
|
-
return {
|
|
120
|
-
hosted: () => host?.available(pi) ?? false,
|
|
121
|
-
outdated: outdatedBriefingHosts.has(pi),
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
92
|
export function startPreparedIdleTurn(
|
|
126
93
|
pi: ExtensionAPI,
|
|
127
94
|
ctx: Pick<ExtensionContext, "ui" | "sessionManager">,
|
package/src/herdr-client.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { createConnection } from "node:net";
|
|
2
|
+
import { hostname } from "node:os";
|
|
3
|
+
import { openPeerChannel } from "./remote/shepherdr-channel.mjs";
|
|
2
4
|
import { requestContext } from "./remote/shepherdr-context.mjs";
|
|
3
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
sendPeerCommands,
|
|
7
|
+
sendPeerFocus,
|
|
8
|
+
sendPeerMessage,
|
|
9
|
+
} from "./remote/shepherdr-peer.mjs";
|
|
4
10
|
import type {
|
|
11
|
+
FocusRequest,
|
|
5
12
|
HerdrEvent,
|
|
13
|
+
MachineIdentity,
|
|
6
14
|
PaneInfo,
|
|
15
|
+
PeerChannel,
|
|
16
|
+
PeerCommand,
|
|
7
17
|
PeerDelivery,
|
|
8
18
|
PeerMessage,
|
|
9
19
|
} from "./types.js";
|
|
@@ -56,6 +66,12 @@ export function isHerdrErrorCode(error: unknown, code: string): boolean {
|
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
export interface HerdrConnection {
|
|
69
|
+
machineIdentity(): Promise<MachineIdentity>;
|
|
70
|
+
focus(agent: PaneInfo, request: FocusRequest): Promise<unknown>;
|
|
71
|
+
openFocusChannel(
|
|
72
|
+
agent: PaneInfo,
|
|
73
|
+
request: FocusRequest,
|
|
74
|
+
): Promise<PeerChannel>;
|
|
59
75
|
requestContext(
|
|
60
76
|
path: string,
|
|
61
77
|
request: unknown,
|
|
@@ -64,6 +80,7 @@ export interface HerdrConnection {
|
|
|
64
80
|
contextRelayPath(): string;
|
|
65
81
|
request<T>(method: string, params?: object, timeoutMs?: number): Promise<T>;
|
|
66
82
|
sendMessage(agent: PaneInfo, message: PeerMessage): Promise<PeerDelivery>;
|
|
83
|
+
commands(agent: PaneInfo): Promise<PeerCommand[]>;
|
|
67
84
|
subscribe(
|
|
68
85
|
subscriptions: object[],
|
|
69
86
|
onEvent: (event: HerdrEvent) => void,
|
|
@@ -74,6 +91,29 @@ export interface HerdrConnection {
|
|
|
74
91
|
|
|
75
92
|
export class HerdrClient implements HerdrConnection {
|
|
76
93
|
readonly socketPath: string;
|
|
94
|
+
openFocusChannel(
|
|
95
|
+
agent: PaneInfo,
|
|
96
|
+
request: FocusRequest,
|
|
97
|
+
): Promise<PeerChannel> {
|
|
98
|
+
return openPeerChannel(
|
|
99
|
+
(method, params) => this.request(method, params),
|
|
100
|
+
agent,
|
|
101
|
+
request,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
async machineIdentity(): Promise<MachineIdentity> {
|
|
105
|
+
return {
|
|
106
|
+
host: hostname(),
|
|
107
|
+
session: process.env["HERDR_SESSION"] || "default",
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
focus(agent: PaneInfo, request: FocusRequest): Promise<unknown> {
|
|
111
|
+
return sendPeerFocus(
|
|
112
|
+
(method, params) => this.request(method, params),
|
|
113
|
+
agent,
|
|
114
|
+
request,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
77
117
|
requestContext(
|
|
78
118
|
path: string,
|
|
79
119
|
request: unknown,
|
|
@@ -102,6 +142,13 @@ export class HerdrClient implements HerdrConnection {
|
|
|
102
142
|
);
|
|
103
143
|
}
|
|
104
144
|
|
|
145
|
+
commands(agent: PaneInfo): Promise<PeerCommand[]> {
|
|
146
|
+
return sendPeerCommands(
|
|
147
|
+
(method, params) => this.request(method, params),
|
|
148
|
+
agent,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
105
152
|
request<T>(
|
|
106
153
|
method: string,
|
|
107
154
|
params: object = {},
|
|
@@ -245,12 +292,11 @@ export class HerdrClient implements HerdrConnection {
|
|
|
245
292
|
socket.destroy();
|
|
246
293
|
return;
|
|
247
294
|
}
|
|
295
|
+
if (value["id"] === id && value["error"] !== undefined) {
|
|
296
|
+
disconnect(errorFromResponse(value["error"]));
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
248
299
|
if (!acknowledged && value["id"] === id) {
|
|
249
|
-
if (value["error"] !== undefined) {
|
|
250
|
-
disconnect(errorFromResponse(value["error"]));
|
|
251
|
-
socket.destroy();
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
300
|
const result = value["result"];
|
|
255
301
|
if (
|
|
256
302
|
typeof result !== "object" ||
|
package/src/messages.ts
CHANGED
|
@@ -5,12 +5,13 @@ import {
|
|
|
5
5
|
getMarkdownTheme,
|
|
6
6
|
} from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import { Box, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
|
|
8
|
+
import type { BoardBinding } from "@howaboua/pi-agent-board/integration";
|
|
8
9
|
import { activityTask } from "./activity.js";
|
|
9
|
-
import type { BoardBinding } from "./board/identity.js";
|
|
10
10
|
import { sendPolicyMessage, startPreparedIdleTurn } from "./delivery.js";
|
|
11
11
|
import { getCurrentPane, getSnapshot } from "./herdr.js";
|
|
12
12
|
import type { HerdrConnection } from "./herdr-client.js";
|
|
13
13
|
import type {
|
|
14
|
+
FocusRequest,
|
|
14
15
|
LatestAssistant,
|
|
15
16
|
MachineStatus,
|
|
16
17
|
MonitoredAgent,
|
|
@@ -22,52 +23,57 @@ import type {
|
|
|
22
23
|
} from "./types.js";
|
|
23
24
|
|
|
24
25
|
const AGENT_EVENT_MESSAGE_TYPE = "herdr-agent-event";
|
|
25
|
-
const BOARD_POST_MARKER = "shepherdr-board-post-marker";
|
|
26
|
-
|
|
27
|
-
export function recordBoardPostMarker(
|
|
28
|
-
pi: ExtensionAPI,
|
|
29
|
-
ctx: ExtensionContext,
|
|
30
|
-
value: unknown,
|
|
31
|
-
): void {
|
|
32
|
-
if (
|
|
33
|
-
!value ||
|
|
34
|
-
typeof value !== "object" ||
|
|
35
|
-
!("message_id" in value) ||
|
|
36
|
-
typeof value.message_id !== "string" ||
|
|
37
|
-
!("channel_name" in value) ||
|
|
38
|
-
typeof value.channel_name !== "string"
|
|
39
|
-
)
|
|
40
|
-
return;
|
|
41
|
-
if (
|
|
42
|
-
ctx.sessionManager
|
|
43
|
-
.getBranch()
|
|
44
|
-
.some(
|
|
45
|
-
(entry) =>
|
|
46
|
-
entry.type === "custom" &&
|
|
47
|
-
entry.customType === BOARD_POST_MARKER &&
|
|
48
|
-
entry.data &&
|
|
49
|
-
typeof entry.data === "object" &&
|
|
50
|
-
"messageId" in entry.data &&
|
|
51
|
-
entry.data.messageId === value.message_id,
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
return;
|
|
55
|
-
// Owner acknowledgements reach the sender here, never the subscription inbox.
|
|
56
|
-
pi.appendEntry(BOARD_POST_MARKER, {
|
|
57
|
-
messageId: value.message_id,
|
|
58
|
-
channelName: value.channel_name,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
26
|
const REALTIME_VOICE_PROMPT_CHANNEL =
|
|
62
27
|
"@howaboua/pi-codex-conversion/realtime-voice-prompt/v1";
|
|
63
28
|
const MAX_REALTIME_VOICE_PROMPT_BYTES = 8 * 1_024;
|
|
64
29
|
const DELEGATED_WORKER_GUIDANCE =
|
|
65
30
|
"If blocked mid-run, use a question-asking tool, not peer messages. Without one, end with the blocker. Finish with an assistant reply, not a separate send report; never watch your parent.";
|
|
31
|
+
|
|
32
|
+
function focusOrigin({ source }: FocusRequest) {
|
|
33
|
+
return { host: source.host, session: source.session, pane: source.pane };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function focusArrivalContent(
|
|
37
|
+
request: FocusRequest,
|
|
38
|
+
machine: string,
|
|
39
|
+
codeMode: boolean,
|
|
40
|
+
) {
|
|
41
|
+
const returnFocus = {
|
|
42
|
+
action: "focus",
|
|
43
|
+
target: request.source.pane,
|
|
44
|
+
machine,
|
|
45
|
+
voice: request.voice === true,
|
|
46
|
+
};
|
|
47
|
+
const args = JSON.stringify(returnFocus);
|
|
48
|
+
const callable = codeMode ? `await tools.agents(${args})` : `agents ${args}`;
|
|
49
|
+
return {
|
|
50
|
+
returnFocus,
|
|
51
|
+
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}` : ""}`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function voiceFocusContinuity(request: FocusRequest): string {
|
|
56
|
+
return `User transferring voice from ${JSON.stringify(focusOrigin(request))}${request.handoff ? `\nHandoff from that session:\n${request.handoff}` : ""}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function voiceFocusReport(
|
|
60
|
+
side: "source" | "destination",
|
|
61
|
+
target: string,
|
|
62
|
+
error?: unknown,
|
|
63
|
+
): string {
|
|
64
|
+
return error === undefined
|
|
65
|
+
? `Voice transfer complete (${side}, ${target}); replacement call active`
|
|
66
|
+
: `Voice transfer failed (${side}, ${target}): ${error instanceof Error ? error.message : String(error)}. Voice availability is not confirmed; inspect the session before retrying`;
|
|
67
|
+
}
|
|
68
|
+
|
|
66
69
|
export function orchestrationGuidance(enabled: boolean, general: boolean) {
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
const ownership = "Own a scope or delegate it; don't do both.";
|
|
71
|
+
if (!enabled)
|
|
72
|
+
return `Work normally. Delegate only when useful or requested. ${ownership}`;
|
|
73
|
+
const guidance = general
|
|
69
74
|
? "Your main goal from now on is to orchestrate agents. Fan out suitable work to general agents, synthesize their results, and report the outcome. Work directly only when asked or for routine local tasks."
|
|
70
75
|
: "Your main goal from now on is to orchestrate agents. Fan out suitable work, synthesize agent results, and report the outcome. Work directly only when asked or for routine local tasks.";
|
|
76
|
+
return `${guidance} ${ownership}`;
|
|
71
77
|
}
|
|
72
78
|
export function activeAgentsBriefing(
|
|
73
79
|
agents: ScopedMonitoredAgent[],
|
|
@@ -94,20 +100,33 @@ export function activeAgentsBriefing(
|
|
|
94
100
|
),
|
|
95
101
|
].join("\n");
|
|
96
102
|
}
|
|
103
|
+
export function boardMigrationWarning() {
|
|
104
|
+
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.";
|
|
105
|
+
}
|
|
106
|
+
|
|
97
107
|
export function boardBriefing(
|
|
98
108
|
member: boolean,
|
|
99
109
|
population: "empty" | "populated" | "unavailable",
|
|
100
110
|
) {
|
|
101
111
|
const state =
|
|
102
112
|
population === "populated"
|
|
103
|
-
? "
|
|
113
|
+
? "Read relevant board threads."
|
|
104
114
|
: population === "empty"
|
|
105
115
|
? "Shared board available; no posts yet."
|
|
106
116
|
: "Shared board status unavailable. Check board help and retry reading when available.";
|
|
107
117
|
const setup = member
|
|
108
118
|
? "The root agent owns setup; follow your assigned task."
|
|
109
|
-
: "
|
|
110
|
-
return
|
|
119
|
+
: "";
|
|
120
|
+
return (
|
|
121
|
+
[
|
|
122
|
+
state,
|
|
123
|
+
setup,
|
|
124
|
+
"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.",
|
|
125
|
+
]
|
|
126
|
+
.filter(Boolean)
|
|
127
|
+
.join(" ") +
|
|
128
|
+
"\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."
|
|
129
|
+
);
|
|
111
130
|
}
|
|
112
131
|
|
|
113
132
|
export function attachmentMessage(
|
|
@@ -548,25 +567,6 @@ export function injectAgentEvent(
|
|
|
548
567
|
}
|
|
549
568
|
|
|
550
569
|
export function registerAgentEventRenderer(pi: ExtensionAPI): void {
|
|
551
|
-
pi.registerEntryRenderer(BOARD_POST_MARKER, (entry, _options, theme) => {
|
|
552
|
-
const data = entry.data;
|
|
553
|
-
const name =
|
|
554
|
-
data &&
|
|
555
|
-
typeof data === "object" &&
|
|
556
|
-
"channelName" in data &&
|
|
557
|
-
typeof data.channelName === "string" &&
|
|
558
|
-
data.channelName.trim()
|
|
559
|
-
? data.channelName.replace(/[\r\n\t\x00-\x1f\x7f]/g, " ")
|
|
560
|
-
: "Board";
|
|
561
|
-
return new Text(
|
|
562
|
-
theme.style(`Posted to board · ${name}`, {
|
|
563
|
-
fg: "syntaxString",
|
|
564
|
-
dim: true,
|
|
565
|
-
}),
|
|
566
|
-
0,
|
|
567
|
-
0,
|
|
568
|
-
);
|
|
569
|
-
});
|
|
570
570
|
pi.registerMessageRenderer<AgentEventDetails>(
|
|
571
571
|
AGENT_EVENT_MESSAGE_TYPE,
|
|
572
572
|
(message, { expanded, outputPad }, theme) => {
|
package/src/monitor-events.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type HerdrConnection, isHerdrErrorCode } from "./herdr-client.js";
|
|
2
2
|
import type { HerdrEvent, MonitoringIssue } from "./types.js";
|
|
3
3
|
|
|
4
4
|
interface SubscriptionAttempt {
|
|
@@ -147,7 +147,29 @@ export class MonitorEvents {
|
|
|
147
147
|
attempt?.controller.signal.aborted
|
|
148
148
|
)
|
|
149
149
|
return;
|
|
150
|
-
|
|
150
|
+
let failure = error instanceof Error ? error : new Error(String(error));
|
|
151
|
+
if (attempt && isHerdrErrorCode(error, "pane_not_found")) {
|
|
152
|
+
try {
|
|
153
|
+
// A closed or moved pane can disappear before its lifecycle event arrives.
|
|
154
|
+
await this.options.reconcile();
|
|
155
|
+
if (!this.active || epoch !== this.epoch) return;
|
|
156
|
+
if (attempt.key !== this.targetKey()) {
|
|
157
|
+
this.dirty = true;
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
} catch (reconcileError) {
|
|
161
|
+
failure =
|
|
162
|
+
reconcileError instanceof Error
|
|
163
|
+
? reconcileError
|
|
164
|
+
: new Error(String(reconcileError));
|
|
165
|
+
}
|
|
166
|
+
if (
|
|
167
|
+
!this.active ||
|
|
168
|
+
epoch !== this.epoch ||
|
|
169
|
+
attempt.controller.signal.aborted
|
|
170
|
+
)
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
151
173
|
this.warn(failure.message);
|
|
152
174
|
if (this.options.reconnect === false) throw failure;
|
|
153
175
|
this.scheduleReconnect();
|
package/src/monitor-questions.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { sameAgentIdentity } from "./ask-answer.js";
|
|
3
3
|
import { getAgent, sessionPath } from "./herdr.js";
|
|
4
|
-
import type
|
|
4
|
+
import { type HerdrConnection, isHerdrErrorCode } from "./herdr-client.js";
|
|
5
5
|
import type { MonitorState } from "./monitor-state.js";
|
|
6
6
|
import type { AssistantReader } from "./session-reader.js";
|
|
7
7
|
import type {
|
|
@@ -144,7 +144,7 @@ export class MonitorQuestions {
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
refresh(panels: PaneInfo[]): Promise<void> {
|
|
147
|
+
refresh(panels: PaneInfo[] = this.panels): Promise<void> {
|
|
148
148
|
this.panels = panels.filter(
|
|
149
149
|
(panel) =>
|
|
150
150
|
this.options.state.byTerminal(panel.terminal_id) && sessionPath(panel),
|
|
@@ -209,7 +209,16 @@ export class MonitorQuestions {
|
|
|
209
209
|
for (const panel of this.panels.filter(
|
|
210
210
|
(panel) => sessionPath(panel) === path,
|
|
211
211
|
)) {
|
|
212
|
-
|
|
212
|
+
if (!this.options.state.byTerminal(panel.terminal_id)) continue;
|
|
213
|
+
const current = await getAgent(
|
|
214
|
+
this.options.client,
|
|
215
|
+
panel.pane_id,
|
|
216
|
+
).catch((error: unknown) => {
|
|
217
|
+
// Pane closure can precede its lifecycle event or finish an in-flight read.
|
|
218
|
+
if (isHerdrErrorCode(error, "agent_not_found")) return undefined;
|
|
219
|
+
throw error;
|
|
220
|
+
});
|
|
221
|
+
if (!current) continue;
|
|
213
222
|
if (!sameAgentIdentity(panel, current)) continue;
|
|
214
223
|
const view = await this.options.reader.view(path);
|
|
215
224
|
if (generation !== this.generation || !this.context) return;
|