@howaboua/pi-shepherdr 0.2.27 → 0.2.28-core.12.1.gda85fa2e8a0f
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 +48 -48
- package/index.ts +7 -1
- package/package.json +2 -9
- package/src/agent-identity.ts +3 -3
- package/src/agents-contract.ts +10 -14
- package/src/agents-discovery.ts +34 -54
- package/src/agents-focus.ts +23 -35
- package/src/agents-spawn.ts +24 -23
- package/src/agents-tool.ts +4 -19
- package/src/agents-work.ts +4 -3
- package/src/attachment-notes.ts +8 -7
- package/src/attachment-protocol.ts +3 -2
- package/src/attachment-routing.ts +1 -1
- package/src/attachment-target.ts +10 -18
- package/src/attachment.ts +14 -9
- package/src/board/discovery.ts +67 -0
- package/src/board/host.ts +93 -63
- package/src/board/membership.ts +16 -11
- package/src/board/records.ts +185 -0
- package/src/close-idle.ts +2 -9
- package/src/context-briefing.ts +230 -0
- package/src/context-routing.ts +1 -1
- package/src/control-panel/index.ts +2 -4
- package/src/control-panel/items.ts +1 -11
- package/src/control-panel/view.ts +3 -9
- package/src/controller.ts +50 -63
- package/src/core/AGENTS.md +7 -4
- package/src/core/admission-broker.mjs +235 -0
- package/src/core/admission-endpoint.ts +180 -0
- package/src/core/admission-owner.mjs +52 -0
- package/src/core/admission-startup.ts +130 -0
- package/src/core/admission.ts +181 -0
- package/src/core/agents.ts +102 -0
- package/src/core/backend.ts +110 -84
- package/src/core/client.ts +16 -0
- package/src/core/focus-channel-helper.mjs +6 -27
- package/src/core/focus-channel-wire.mjs +9 -6
- package/src/core/focus-channel.ts +5 -3
- package/src/core/focus-window.ts +15 -4
- package/src/core/helper-bootstrap.mjs +70 -0
- package/src/core/helper-context.mjs +98 -0
- package/src/core/helper-core.mjs +121 -0
- package/src/core/machines.ts +30 -0
- package/src/core/registration.ts +7 -2
- package/src/core/remote-endpoint.ts +80 -74
- package/src/core/remote-helper.ts +330 -0
- package/src/core/remote-reader.ts +3 -42
- package/src/core/remote-service.mjs +239 -0
- package/src/core/remote-transport.ts +290 -0
- package/src/core/spawn.ts +20 -20
- package/src/core/terminal-peer.mjs +57 -0
- package/src/core/terminal.ts +4 -2
- package/src/delivery.ts +39 -0
- package/src/fleet/catalog.ts +16 -58
- package/src/fleet/connection.ts +9 -18
- package/src/fleet/index.ts +38 -76
- package/src/fleet/inspection.ts +9 -22
- package/src/fleet/machine.ts +28 -12
- package/src/fleet/monitor.ts +8 -29
- package/src/fleet/persistence.ts +2 -2
- package/src/fleet/reconnect.ts +5 -3
- package/src/fleet/setup.ts +6 -16
- package/src/launch-contract.ts +0 -3
- package/src/launch-location.ts +4 -132
- package/src/launch.ts +18 -144
- package/src/messages/attachments.ts +1 -1
- package/src/messages/attribution.ts +9 -14
- package/src/messages/events.ts +5 -9
- package/src/messages/focus.ts +2 -7
- package/src/messages/guidance.ts +2 -43
- package/src/messages/peer-sharing.ts +133 -0
- package/src/monitor-events.ts +14 -43
- package/src/monitor-extension-messages.ts +5 -6
- package/src/monitor-record.ts +4 -0
- package/src/monitor-state.ts +1 -101
- package/src/monitor.ts +38 -66
- package/src/notes-discovery.ts +67 -0
- package/src/peer-inbox.ts +21 -27
- package/src/remote/context-relay.ts +25 -10
- package/src/remote/notes-reader.mjs +67 -0
- package/src/remote/shepherdr-channel.mjs +1 -1
- package/src/remote/shepherdr-checkpoints.mjs +49 -102
- package/src/remote/shepherdr-context.mjs +1 -1
- package/src/remote/shepherdr-peer.mjs +19 -24
- package/src/remote/shepherdr-session.mjs +18 -7
- package/src/saved-context.ts +62 -0
- package/src/settlement/collector.ts +29 -9
- package/src/settlement/index.ts +35 -6
- package/src/shared-context-host.ts +27 -33
- package/src/shared-context.ts +44 -15
- package/src/spawn-context.ts +11 -3
- package/src/spawn-ownership.ts +1 -1
- package/src/ssh-setup.ts +40 -73
- package/src/types.ts +4 -8
- package/src/voice-handoff.ts +1 -1
- package/src/widget.ts +7 -2
- package/src/worker-ownership.ts +2 -8
- package/src/worker-service.ts +6 -14
- package/src/core/context-relay.mjs +0 -111
- package/src/core/remote-exec.ts +0 -122
- package/src/core/remote-helper.mjs +0 -244
- package/src/core/remote-relay.ts +0 -191
- package/src/core/request.ts +0 -124
- package/src/herdr-client.ts +0 -364
- package/src/herdr.ts +0 -268
- package/src/machine-catalog.ts +0 -83
- package/src/monitor-event.ts +0 -84
- package/src/remote/client.ts +0 -127
- package/src/remote/deployment.ts +0 -179
- package/src/remote/focus-channels.ts +0 -89
- package/src/remote/shepherdr.mjs +0 -504
- package/src/remote/transport.ts +0 -369
package/src/fleet/persistence.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { LOCAL_MACHINE } from "
|
|
2
|
+
import { LOCAL_MACHINE } from "./machine.js";
|
|
3
3
|
export const MONITOR_STATE_TYPE = "herdr-agents-monitor-state";
|
|
4
4
|
|
|
5
5
|
export function savedAgents(
|
|
@@ -41,7 +41,7 @@ export function savedAgents(
|
|
|
41
41
|
);
|
|
42
42
|
if (retained.length !== latest.length)
|
|
43
43
|
ctx.ui.notify(
|
|
44
|
-
"Ignored saved local agent watches from another
|
|
44
|
+
"Ignored saved local agent watches from another Core; watch them again in this session.",
|
|
45
45
|
"warning",
|
|
46
46
|
);
|
|
47
47
|
return retained;
|
package/src/fleet/reconnect.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MachineRuntime, resolveMachine } from "./machine.js";
|
|
2
2
|
|
|
3
3
|
/** Explicit reconnect selection and user receipts; never schedules autonomous reconnects. */
|
|
4
4
|
export function connectMachines(
|
|
@@ -7,11 +7,13 @@ export function connectMachines(
|
|
|
7
7
|
retrySetup: (name: string, runtime: MachineRuntime) => Promise<void>,
|
|
8
8
|
connectMachine: (name: string) => Promise<void>,
|
|
9
9
|
): string {
|
|
10
|
-
const target = machine?.trim()
|
|
10
|
+
const target = machine?.trim()
|
|
11
|
+
? resolveMachine(runtimes, machine)
|
|
12
|
+
: undefined;
|
|
11
13
|
if (target) {
|
|
12
14
|
const runtime = runtimes.get(target);
|
|
13
15
|
if (!runtime)
|
|
14
|
-
throw new Error(`
|
|
16
|
+
throw new Error(`Unknown Core machine ${JSON.stringify(target)}`);
|
|
15
17
|
if (
|
|
16
18
|
runtime.status === "connected" &&
|
|
17
19
|
(runtime.monitoringIssue || runtime.contextRelayError)
|
package/src/fleet/setup.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { CoreConnection } from "../core/backend.js";
|
|
3
|
-
import { RemoteHerdrClient } from "../remote/client.js";
|
|
2
|
+
import type { CoreConnection } from "../core/backend.js";
|
|
4
3
|
import { errorMessage, type MachineRuntime } from "./machine.js";
|
|
5
4
|
|
|
6
5
|
/** Explicitly requested sharing/monitor readiness; fleet supplies current-selection leases. */
|
|
7
6
|
export class FleetSetup {
|
|
8
7
|
// Concurrent publishers share one start; existing children retain its route.
|
|
9
|
-
private readonly relays = new WeakMap<
|
|
10
|
-
RemoteHerdrClient | CoreConnection,
|
|
11
|
-
Promise<void>
|
|
12
|
-
>();
|
|
8
|
+
private readonly relays = new WeakMap<CoreConnection, Promise<void>>();
|
|
13
9
|
private readonly refresh: () => void;
|
|
14
10
|
constructor(refresh: () => void) {
|
|
15
11
|
this.refresh = refresh;
|
|
@@ -33,7 +29,7 @@ export class FleetSetup {
|
|
|
33
29
|
prepareContextRelay(
|
|
34
30
|
name: string,
|
|
35
31
|
runtime: MachineRuntime,
|
|
36
|
-
client:
|
|
32
|
+
client: CoreConnection,
|
|
37
33
|
ctx: ExtensionContext,
|
|
38
34
|
isSelected: () => boolean,
|
|
39
35
|
): Promise<void> {
|
|
@@ -56,7 +52,7 @@ export class FleetSetup {
|
|
|
56
52
|
private async openContextRelay(
|
|
57
53
|
name: string,
|
|
58
54
|
runtime: MachineRuntime,
|
|
59
|
-
client:
|
|
55
|
+
client: CoreConnection,
|
|
60
56
|
ctx: ExtensionContext,
|
|
61
57
|
isSelected: () => boolean,
|
|
62
58
|
): Promise<void> {
|
|
@@ -79,9 +75,7 @@ export class FleetSetup {
|
|
|
79
75
|
(request: unknown, signal: AbortSignal) =>
|
|
80
76
|
this.contextRelay!(ctx, request, signal),
|
|
81
77
|
] as const;
|
|
82
|
-
|
|
83
|
-
await client.startContextRelay(...args, failed);
|
|
84
|
-
else await client.startContextRelay(...args);
|
|
78
|
+
await client.startContextRelay(...args, failed);
|
|
85
79
|
if (!isSelected()) return;
|
|
86
80
|
delete runtime.contextRelayError;
|
|
87
81
|
} catch (error) {
|
|
@@ -103,11 +97,7 @@ export class FleetSetup {
|
|
|
103
97
|
runtime.attempting = true;
|
|
104
98
|
this.refresh();
|
|
105
99
|
try {
|
|
106
|
-
if (
|
|
107
|
-
runtime.contextRelayError &&
|
|
108
|
-
(runtime.client instanceof RemoteHerdrClient ||
|
|
109
|
-
runtime.client instanceof CoreConnection)
|
|
110
|
-
)
|
|
100
|
+
if (runtime.contextRelayError && runtime.client)
|
|
111
101
|
await this.prepareContextRelay(
|
|
112
102
|
name,
|
|
113
103
|
runtime,
|
package/src/launch-contract.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type { PaneInfo } from "./types.js";
|
|
|
3
3
|
export const START_PLACEMENTS = [
|
|
4
4
|
"new_workspace",
|
|
5
5
|
"new_tab",
|
|
6
|
-
"pane",
|
|
7
6
|
"terminal",
|
|
8
7
|
] as const;
|
|
9
8
|
|
|
@@ -11,14 +10,12 @@ export interface StartAgentParams {
|
|
|
11
10
|
cwd?: string;
|
|
12
11
|
label?: string;
|
|
13
12
|
name?: string;
|
|
14
|
-
pane?: string;
|
|
15
13
|
placement?: (typeof START_PLACEMENTS)[number];
|
|
16
14
|
workspace?: string;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export interface CreatedLocationCleanup {
|
|
20
18
|
id: string;
|
|
21
|
-
method: "tab.close" | "workspace.close" | "terminal.close";
|
|
22
19
|
}
|
|
23
20
|
|
|
24
21
|
export interface StartedAgent {
|
package/src/launch-location.ts
CHANGED
|
@@ -1,146 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import { closeTerminal } from "./core/agents.js";
|
|
2
|
+
import type { CoreConnection } from "./core/backend.js";
|
|
3
3
|
import {
|
|
4
4
|
type CreatedLocationCleanup,
|
|
5
5
|
RolledBackAgentLaunchError,
|
|
6
|
-
requiredStartField,
|
|
7
|
-
type StartAgentParams,
|
|
8
|
-
UnstartedAgentLaunchError,
|
|
9
6
|
} from "./launch-contract.js";
|
|
10
|
-
import type { PaneInfo } from "./types.js";
|
|
11
|
-
|
|
12
|
-
export async function createStartPane(
|
|
13
|
-
client: HerdrConnection,
|
|
14
|
-
params: StartAgentParams,
|
|
15
|
-
cwd: string,
|
|
16
|
-
label: string,
|
|
17
|
-
): Promise<{
|
|
18
|
-
cleanup?: CreatedLocationCleanup;
|
|
19
|
-
paneId: string;
|
|
20
|
-
}> {
|
|
21
|
-
const placement = params.placement;
|
|
22
|
-
if (!placement) throw new Error("placement is required for start");
|
|
23
|
-
if (placement === "terminal")
|
|
24
|
-
throw new UnstartedAgentLaunchError(
|
|
25
|
-
"terminal placement requires Core; use new_tab or new_workspace in legacy Herdr",
|
|
26
|
-
);
|
|
27
|
-
if (placement === "pane") {
|
|
28
|
-
return { paneId: requiredStartField(params.pane, "pane") };
|
|
29
|
-
}
|
|
30
|
-
if (placement === "new_tab") {
|
|
31
|
-
const workspaceTarget = requiredStartField(params.workspace, "workspace");
|
|
32
|
-
let workspace;
|
|
33
|
-
try {
|
|
34
|
-
workspace = resolveWorkspace(await getSnapshot(client), workspaceTarget);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
throw new UnstartedAgentLaunchError(error);
|
|
37
|
-
}
|
|
38
|
-
// A failed create response may still have created a location.
|
|
39
|
-
const created = createdLocation(
|
|
40
|
-
await client.request<unknown>("tab.create", {
|
|
41
|
-
workspace_id: workspace.workspace_id,
|
|
42
|
-
cwd,
|
|
43
|
-
label,
|
|
44
|
-
focus: false,
|
|
45
|
-
}),
|
|
46
|
-
"tab.create result",
|
|
47
|
-
);
|
|
48
|
-
return {
|
|
49
|
-
paneId: created.root_pane.pane_id,
|
|
50
|
-
cleanup: { method: "tab.close", id: created.tab.tab_id },
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const created = createdLocation(
|
|
54
|
-
await client.request<unknown>("workspace.create", {
|
|
55
|
-
cwd,
|
|
56
|
-
focus: false,
|
|
57
|
-
}),
|
|
58
|
-
"workspace.create result",
|
|
59
|
-
true,
|
|
60
|
-
);
|
|
61
|
-
try {
|
|
62
|
-
await client.request("tab.rename", { tab_id: created.tab.tab_id, label });
|
|
63
|
-
} catch (error) {
|
|
64
|
-
return rollbackCreatedLocation(
|
|
65
|
-
client,
|
|
66
|
-
{ method: "workspace.close", id: created.workspace.workspace_id },
|
|
67
|
-
error,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
paneId: created.root_pane.pane_id,
|
|
72
|
-
cleanup: { method: "workspace.close", id: created.workspace.workspace_id },
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function createdLocation(
|
|
77
|
-
value: unknown,
|
|
78
|
-
path: string,
|
|
79
|
-
): { root_pane: PaneInfo; tab: { tab_id: string } };
|
|
80
|
-
function createdLocation(
|
|
81
|
-
value: unknown,
|
|
82
|
-
path: string,
|
|
83
|
-
withWorkspace: true,
|
|
84
|
-
): {
|
|
85
|
-
root_pane: PaneInfo;
|
|
86
|
-
tab: { tab_id: string };
|
|
87
|
-
workspace: { workspace_id: string };
|
|
88
|
-
};
|
|
89
|
-
function createdLocation(
|
|
90
|
-
value: unknown,
|
|
91
|
-
path: string,
|
|
92
|
-
withWorkspace = false,
|
|
93
|
-
): {
|
|
94
|
-
root_pane: PaneInfo;
|
|
95
|
-
tab: { tab_id: string };
|
|
96
|
-
workspace?: { workspace_id: string };
|
|
97
|
-
} {
|
|
98
|
-
if (typeof value !== "object" || value === null) {
|
|
99
|
-
throw new Error(`Herdr ${path} must be an object`);
|
|
100
|
-
}
|
|
101
|
-
const result = value as Record<string, unknown>;
|
|
102
|
-
const tabId = nestedId(result["tab"], "tab_id", `${path}.tab`);
|
|
103
|
-
return {
|
|
104
|
-
root_pane: parsePaneInfo(result["root_pane"], `${path}.root_pane`),
|
|
105
|
-
tab: { tab_id: tabId },
|
|
106
|
-
...(withWorkspace
|
|
107
|
-
? {
|
|
108
|
-
workspace: {
|
|
109
|
-
workspace_id: nestedId(
|
|
110
|
-
result["workspace"],
|
|
111
|
-
"workspace_id",
|
|
112
|
-
`${path}.workspace`,
|
|
113
|
-
),
|
|
114
|
-
},
|
|
115
|
-
}
|
|
116
|
-
: {}),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function nestedId(value: unknown, key: string, path: string): string {
|
|
121
|
-
if (typeof value !== "object" || value === null) {
|
|
122
|
-
throw new Error(`Herdr ${path} must be an object`);
|
|
123
|
-
}
|
|
124
|
-
const id = (value as Record<string, unknown>)[key];
|
|
125
|
-
if (typeof id !== "string")
|
|
126
|
-
throw new Error(`Herdr ${path}.${key} must be string`);
|
|
127
|
-
return id;
|
|
128
|
-
}
|
|
129
7
|
|
|
130
8
|
export async function rollbackCreatedLocation(
|
|
131
|
-
client:
|
|
9
|
+
client: CoreConnection,
|
|
132
10
|
cleanup: CreatedLocationCleanup | undefined,
|
|
133
11
|
cause: unknown,
|
|
134
12
|
): Promise<never> {
|
|
135
13
|
if (!cleanup) throw cause;
|
|
136
14
|
try {
|
|
137
|
-
await client
|
|
138
|
-
[cleanup.method === "tab.close"
|
|
139
|
-
? "tab_id"
|
|
140
|
-
: cleanup.method === "terminal.close"
|
|
141
|
-
? "id"
|
|
142
|
-
: "workspace_id"]: cleanup.id,
|
|
143
|
-
});
|
|
15
|
+
await closeTerminal(client, cleanup.id);
|
|
144
16
|
} catch (cleanupError) {
|
|
145
17
|
throw new Error(
|
|
146
18
|
`${cause instanceof Error ? cause.message : String(cause)}; rollback also failed: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`,
|
package/src/launch.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { parseArgs } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import { CoreConnection } from "./core/backend.js";
|
|
4
|
+
import type { CoreConnection } from "./core/backend.js";
|
|
5
5
|
import { startCoreAgent } from "./core/spawn.js";
|
|
6
|
-
import { getAgent, getPane, parsePaneInfo, sessionPath } from "./herdr.js";
|
|
7
|
-
import { type HerdrConnection, isHerdrErrorCode } from "./herdr-client.js";
|
|
8
6
|
import {
|
|
9
7
|
requiredStartField,
|
|
10
8
|
type StartAgentParams,
|
|
11
9
|
type StartedAgent,
|
|
12
10
|
UnstartedAgentLaunchError,
|
|
13
11
|
} from "./launch-contract.js";
|
|
14
|
-
import {
|
|
15
|
-
import type { PaneInfo } from "./types.js";
|
|
12
|
+
import { rollbackCreatedLocation } from "./launch-location.js";
|
|
16
13
|
import { WORKER_FLAG } from "./worker-role.js";
|
|
17
14
|
|
|
18
15
|
export {
|
|
@@ -43,39 +40,21 @@ export type DirectoryResolver = (
|
|
|
43
40
|
fallback: string,
|
|
44
41
|
) => Promise<string>;
|
|
45
42
|
|
|
46
|
-
function resolveStartDirectory(
|
|
47
|
-
params: StartAgentParams,
|
|
48
|
-
fallbackCwd: string,
|
|
49
|
-
resolveDirectory: DirectoryResolver = directory,
|
|
50
|
-
): Promise<string> {
|
|
51
|
-
return params.placement === "pane"
|
|
52
|
-
? Promise.resolve(fallbackCwd)
|
|
53
|
-
: resolveDirectory(params.cwd, fallbackCwd);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
43
|
export async function resolvePreparationDirectory(
|
|
57
|
-
client: HerdrConnection,
|
|
58
44
|
params: StartAgentParams,
|
|
59
45
|
fallbackCwd: string,
|
|
60
46
|
resolveDirectory: DirectoryResolver = directory,
|
|
61
47
|
): Promise<string> {
|
|
62
|
-
|
|
63
|
-
throw new UnstartedAgentLaunchError(
|
|
64
|
-
"Core cannot start Pi in an existing terminal without terminal input; use terminal, new_tab or new_workspace placement",
|
|
65
|
-
);
|
|
66
|
-
if (params.placement !== "pane") {
|
|
67
|
-
return resolveStartDirectory(params, fallbackCwd, resolveDirectory);
|
|
68
|
-
}
|
|
69
|
-
const pane = await getPane(client, requiredStartField(params.pane, "pane"));
|
|
70
|
-
return pane.foreground_cwd?.trim() || pane.cwd?.trim() || fallbackCwd;
|
|
48
|
+
return resolveDirectory(params.cwd, fallbackCwd);
|
|
71
49
|
}
|
|
72
50
|
|
|
73
51
|
interface StartAgentOptions {
|
|
74
52
|
agentArgs?: string[];
|
|
53
|
+
signal?: AbortSignal;
|
|
75
54
|
}
|
|
76
55
|
|
|
77
56
|
export async function startAgent(
|
|
78
|
-
client:
|
|
57
|
+
client: CoreConnection,
|
|
79
58
|
params: StartAgentParams,
|
|
80
59
|
fallbackCwd: string,
|
|
81
60
|
resolveDirectory: DirectoryResolver = directory,
|
|
@@ -105,137 +84,32 @@ export async function startAgent(
|
|
|
105
84
|
"spawn requires a persistent Pi session; remove --no-session from profile pi_args",
|
|
106
85
|
);
|
|
107
86
|
}
|
|
108
|
-
if (params.placement === "pane" && params.cwd) {
|
|
109
|
-
throw new Error(
|
|
110
|
-
"cwd cannot change an existing pane; prepare the pane through Herdr",
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
if (client instanceof CoreConnection && params.placement === "pane")
|
|
114
|
-
throw new UnstartedAgentLaunchError(
|
|
115
|
-
"Core cannot start Pi in an existing terminal without terminal input; use terminal, new_tab or new_workspace placement",
|
|
116
|
-
);
|
|
117
87
|
let cwd: string;
|
|
118
88
|
try {
|
|
119
|
-
cwd = await
|
|
89
|
+
cwd = await resolveDirectory(params.cwd, fallbackCwd);
|
|
120
90
|
} catch (error) {
|
|
121
91
|
throw new UnstartedAgentLaunchError(error);
|
|
122
92
|
}
|
|
123
|
-
|
|
124
|
-
return startCoreAgent(client, params, cwd, label, args);
|
|
125
|
-
const created = await createStartPane(client, params, cwd, label);
|
|
126
|
-
let agent: PaneInfo;
|
|
93
|
+
let entered = false;
|
|
127
94
|
try {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
95
|
+
return await client.admission.run(
|
|
96
|
+
"launch",
|
|
97
|
+
() => {
|
|
98
|
+
entered = true;
|
|
99
|
+
return startCoreAgent(client, params, cwd, args, options.signal);
|
|
100
|
+
},
|
|
101
|
+
options.signal,
|
|
102
|
+
);
|
|
135
103
|
} catch (error) {
|
|
136
|
-
|
|
104
|
+
if (!entered) throw new UnstartedAgentLaunchError(error);
|
|
105
|
+
throw error;
|
|
137
106
|
}
|
|
138
|
-
return {
|
|
139
|
-
agent,
|
|
140
|
-
...(created.cleanup ? { cleanup: created.cleanup } : {}),
|
|
141
|
-
id: agent.pane_id,
|
|
142
|
-
};
|
|
143
107
|
}
|
|
144
108
|
|
|
145
109
|
export async function rollbackStartedAgent(
|
|
146
|
-
client:
|
|
110
|
+
client: CoreConnection,
|
|
147
111
|
started: StartedAgent,
|
|
148
112
|
cause: unknown,
|
|
149
113
|
): Promise<never> {
|
|
150
114
|
return rollbackCreatedLocation(client, started.cleanup, cause);
|
|
151
115
|
}
|
|
152
|
-
|
|
153
|
-
async function startWhenShellReady(
|
|
154
|
-
client: HerdrConnection,
|
|
155
|
-
params: Record<string, unknown>,
|
|
156
|
-
): Promise<PaneInfo> {
|
|
157
|
-
const shellDeadline = Date.now() + 3_000;
|
|
158
|
-
let started: { agent: PaneInfo };
|
|
159
|
-
for (;;) {
|
|
160
|
-
try {
|
|
161
|
-
const result = await client.request<{ agent?: unknown }>(
|
|
162
|
-
"agent.start",
|
|
163
|
-
params,
|
|
164
|
-
35_000,
|
|
165
|
-
);
|
|
166
|
-
started = {
|
|
167
|
-
agent: parsePaneInfo(result.agent, "agent.start result.agent"),
|
|
168
|
-
};
|
|
169
|
-
break;
|
|
170
|
-
} catch (error) {
|
|
171
|
-
if (
|
|
172
|
-
!isHerdrErrorCode(error, "agent_pane_busy") ||
|
|
173
|
-
Date.now() >= shellDeadline
|
|
174
|
-
) {
|
|
175
|
-
throw error;
|
|
176
|
-
}
|
|
177
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const name = requiredStartField(
|
|
182
|
-
typeof params["name"] === "string" ? params["name"] : undefined,
|
|
183
|
-
"name",
|
|
184
|
-
);
|
|
185
|
-
const paneId = requiredStartField(
|
|
186
|
-
typeof params["pane_id"] === "string" ? params["pane_id"] : undefined,
|
|
187
|
-
"pane_id",
|
|
188
|
-
);
|
|
189
|
-
const terminalId = started.agent.terminal_id;
|
|
190
|
-
const readyDeadline = Date.now() + 30_000;
|
|
191
|
-
let waitingForSession = false;
|
|
192
|
-
while (Date.now() < readyDeadline) {
|
|
193
|
-
let current: PaneInfo;
|
|
194
|
-
try {
|
|
195
|
-
current = await resolveDuringStart(client, name, paneId);
|
|
196
|
-
} catch (error) {
|
|
197
|
-
if (!isHerdrErrorCode(error, "agent_not_found")) throw error;
|
|
198
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (current.terminal_id !== terminalId || current.name !== name) {
|
|
202
|
-
throw new Error(`named agent ${name} no longer owns ${paneId}`);
|
|
203
|
-
}
|
|
204
|
-
if (current.agent && current.agent !== "pi") {
|
|
205
|
-
throw new Error(`expected pi, detected ${current.agent}`);
|
|
206
|
-
}
|
|
207
|
-
if (current.agent_status === "blocked") {
|
|
208
|
-
throw new Error(`agent ${name} is blocked during startup`);
|
|
209
|
-
}
|
|
210
|
-
waitingForSession =
|
|
211
|
-
(current.agent_status === "idle" || current.agent_status === "done") &&
|
|
212
|
-
current.interactive_ready === true &&
|
|
213
|
-
current.agent === "pi";
|
|
214
|
-
if (waitingForSession) {
|
|
215
|
-
if (sessionPath(current)) return current;
|
|
216
|
-
// Herdr can finish launch before Pi reports its persistent session.
|
|
217
|
-
} else if (
|
|
218
|
-
(current.agent_status === "idle" || current.agent_status === "done") &&
|
|
219
|
-
current.launch_pending === false
|
|
220
|
-
) {
|
|
221
|
-
throw new Error("agent process exited before becoming interactive");
|
|
222
|
-
}
|
|
223
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
224
|
-
}
|
|
225
|
-
throw new Error(
|
|
226
|
-
`timed out waiting for agent ${name} ${waitingForSession ? "to register its Pi session" : "to become interactive"}`,
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
async function resolveDuringStart(
|
|
231
|
-
client: HerdrConnection,
|
|
232
|
-
name: string,
|
|
233
|
-
paneId: string,
|
|
234
|
-
): Promise<PaneInfo> {
|
|
235
|
-
try {
|
|
236
|
-
return await getAgent(client, name);
|
|
237
|
-
} catch (error) {
|
|
238
|
-
if (!isHerdrErrorCode(error, "agent_not_found")) throw error;
|
|
239
|
-
return getAgent(client, paneId);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type { HerdrConnection } from "../herdr-client.js";
|
|
1
|
+
import { getCurrentPane, getSnapshot } from "../core/agents.js";
|
|
2
|
+
import type { CoreConnection } from "../core/backend.js";
|
|
4
3
|
import type { PaneInfo, PeerMessage } from "../types.js";
|
|
5
4
|
|
|
6
5
|
const DELEGATED_WORKER_GUIDANCE =
|
|
7
6
|
"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.";
|
|
7
|
+
const PEER_MESSAGE_GUIDANCE =
|
|
8
|
+
"A peer message does not make you the sender's sub-agent or establish shared context.";
|
|
8
9
|
|
|
9
10
|
export function xml(value: string): string {
|
|
10
11
|
return value
|
|
@@ -26,9 +27,7 @@ export function agentSource(
|
|
|
26
27
|
): Record<string, string | undefined> {
|
|
27
28
|
const paneName = agent.label || agent.title;
|
|
28
29
|
return {
|
|
29
|
-
|
|
30
|
-
? { terminal: agent.terminal_id }
|
|
31
|
-
: { pane: agent.pane_id }),
|
|
30
|
+
terminal: agent.terminal_id,
|
|
32
31
|
...(agent.workspace_id ? { workspace: agent.workspace_id } : {}),
|
|
33
32
|
...(agent.tab_id ? { tab: agent.tab_id } : {}),
|
|
34
33
|
...(agent.name ? { name: agent.name } : {}),
|
|
@@ -51,7 +50,7 @@ export function sourceAttributes(
|
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
export async function attributeAgentPrompt(
|
|
54
|
-
client:
|
|
53
|
+
client: CoreConnection,
|
|
55
54
|
message: string,
|
|
56
55
|
kind: "message" | "task",
|
|
57
56
|
): Promise<PeerMessage> {
|
|
@@ -65,12 +64,7 @@ export async function attributeAgentPrompt(
|
|
|
65
64
|
const tab = snapshot.tabs.find((tab) => tab.tab_id === pane.tab_id)?.label;
|
|
66
65
|
const source = {
|
|
67
66
|
kind,
|
|
68
|
-
...(
|
|
69
|
-
? await client.machineIdentity()
|
|
70
|
-
: {
|
|
71
|
-
host: hostname(),
|
|
72
|
-
session: process.env["HERDR_SESSION"] || "default",
|
|
73
|
-
}),
|
|
67
|
+
...(await client.machineIdentity()),
|
|
74
68
|
...agentSource(pane, {
|
|
75
69
|
...(workspace ? { workspace } : {}),
|
|
76
70
|
...(tab ? { tab } : {}),
|
|
@@ -79,6 +73,7 @@ export async function attributeAgentPrompt(
|
|
|
79
73
|
return {
|
|
80
74
|
sender: `<herdr_sender ${sourceAttributes(source)} />`,
|
|
81
75
|
text: message,
|
|
82
|
-
|
|
76
|
+
context:
|
|
77
|
+
kind === "task" ? DELEGATED_WORKER_GUIDANCE : PEER_MESSAGE_GUIDANCE,
|
|
83
78
|
};
|
|
84
79
|
}
|
package/src/messages/events.ts
CHANGED
|
@@ -47,9 +47,8 @@ function blockedOperatorHint(
|
|
|
47
47
|
machine: string,
|
|
48
48
|
operatorPrefix: string,
|
|
49
49
|
paneId: string,
|
|
50
|
-
core: boolean,
|
|
51
50
|
): string {
|
|
52
|
-
return `Inspect first with ${operatorCommand(operatorPrefix,
|
|
51
|
+
return `Inspect first with ${operatorCommand(operatorPrefix, `read ${paneId}`)}; respond through ${agentToolName} with machine=${JSON.stringify(machine)}, or use ${operatorCommand(operatorPrefix, `keys ${paneId} <keys>`)} for interactive controls.`;
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
function failedOperatorHint(
|
|
@@ -57,9 +56,8 @@ function failedOperatorHint(
|
|
|
57
56
|
machine: string,
|
|
58
57
|
operatorPrefix: string,
|
|
59
58
|
paneId: string,
|
|
60
|
-
core: boolean,
|
|
61
59
|
): string {
|
|
62
|
-
return `Inspect with ${operatorCommand(operatorPrefix,
|
|
60
|
+
return `Inspect with ${operatorCommand(operatorPrefix, `read ${paneId} --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.`;
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
function agentEvent(options: AgentEventOptions): {
|
|
@@ -85,9 +83,7 @@ function agentEvent(options: AgentEventOptions): {
|
|
|
85
83
|
const notification = status === "extension-message";
|
|
86
84
|
const failed = !blocked && reply?.stopReason === "error";
|
|
87
85
|
const operatorTarget =
|
|
88
|
-
|
|
89
|
-
? `${machineLabel}/${agent.pane_id}`
|
|
90
|
-
: agent.pane_id;
|
|
86
|
+
machine !== "local" ? `${machine}/${agent.pane_id}` : agent.pane_id;
|
|
91
87
|
const cwd = agent.foreground_cwd ?? agent.cwd ?? record.cwd;
|
|
92
88
|
const tag = notification
|
|
93
89
|
? "herdr_agent_extension_message"
|
|
@@ -127,12 +123,12 @@ function agentEvent(options: AgentEventOptions): {
|
|
|
127
123
|
}
|
|
128
124
|
if (blocked) {
|
|
129
125
|
lines.push(
|
|
130
|
-
`<operator_hint>${xml(blockedOperatorHint(agentToolName, machine, operatorPrefix, operatorTarget
|
|
126
|
+
`<operator_hint>${xml(blockedOperatorHint(agentToolName, machine, operatorPrefix, operatorTarget))}</operator_hint>`,
|
|
131
127
|
);
|
|
132
128
|
}
|
|
133
129
|
if (failed) {
|
|
134
130
|
lines.push(
|
|
135
|
-
`<operator_hint>${xml(failedOperatorHint(agentToolName, machine, operatorPrefix, operatorTarget
|
|
131
|
+
`<operator_hint>${xml(failedOperatorHint(agentToolName, machine, operatorPrefix, operatorTarget))}</operator_hint>`,
|
|
136
132
|
);
|
|
137
133
|
}
|
|
138
134
|
if (reply) lines.push(`<response>${xml(reply.text)}</response>`);
|
package/src/messages/focus.ts
CHANGED
|
@@ -4,9 +4,7 @@ function focusOrigin({ source }: FocusRequest) {
|
|
|
4
4
|
return {
|
|
5
5
|
host: source.host,
|
|
6
6
|
session: source.session,
|
|
7
|
-
|
|
8
|
-
? { terminal: source.terminal }
|
|
9
|
-
: { pane: source.pane }),
|
|
7
|
+
terminal: source.terminal,
|
|
10
8
|
};
|
|
11
9
|
}
|
|
12
10
|
|
|
@@ -17,10 +15,7 @@ export function focusArrivalContent(
|
|
|
17
15
|
) {
|
|
18
16
|
const returnFocus = {
|
|
19
17
|
action: "focus",
|
|
20
|
-
target:
|
|
21
|
-
request.source.backend === "core"
|
|
22
|
-
? request.source.terminal
|
|
23
|
-
: request.source.pane!,
|
|
18
|
+
target: request.source.terminal,
|
|
24
19
|
machine,
|
|
25
20
|
voice: request.voice === true,
|
|
26
21
|
};
|
package/src/messages/guidance.ts
CHANGED
|
@@ -16,7 +16,7 @@ export function activeAgentsBriefing(
|
|
|
16
16
|
): string | undefined {
|
|
17
17
|
if (!agents.length) return;
|
|
18
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
|
|
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's latest reply for a missing path or pending extension messages; terminal reads inspect the TUI.",
|
|
20
20
|
JSON.stringify(
|
|
21
21
|
agents.map((agent) => {
|
|
22
22
|
const instructions = [
|
|
@@ -44,46 +44,5 @@ export function activeAgentsBriefing(
|
|
|
44
44
|
].join("\n");
|
|
45
45
|
}
|
|
46
46
|
export function boardMigrationWarning() {
|
|
47
|
-
return "
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function boardBriefing(
|
|
51
|
-
member: boolean,
|
|
52
|
-
population: "empty" | "populated" | "unavailable",
|
|
53
|
-
gpt = false,
|
|
54
|
-
) {
|
|
55
|
-
const state =
|
|
56
|
-
population === "populated"
|
|
57
|
-
? "Read relevant board threads."
|
|
58
|
-
: population === "empty"
|
|
59
|
-
? gpt
|
|
60
|
-
? "Shared board available; posts=none."
|
|
61
|
-
: "Shared board available; no posts yet."
|
|
62
|
-
: gpt
|
|
63
|
-
? "Shared board status unavailable; board help→retry read when available."
|
|
64
|
-
: "Shared board status unavailable. Check board help and retry reading when available.";
|
|
65
|
-
const setup = member
|
|
66
|
-
? gpt
|
|
67
|
-
? "Root owns setup; follow assigned task."
|
|
68
|
-
: "The root agent owns setup; follow your assigned task."
|
|
69
|
-
: "";
|
|
70
|
-
if (gpt)
|
|
71
|
-
return [
|
|
72
|
-
state,
|
|
73
|
-
setup,
|
|
74
|
-
"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.",
|
|
75
|
-
"Channels=workstreams; threads=topics. Reuse relevant channels≠catchalls. New channel requires distinct coordination purpose; never task/result announcement only.",
|
|
76
|
-
]
|
|
77
|
-
.filter(Boolean)
|
|
78
|
-
.join(" ");
|
|
79
|
-
return (
|
|
80
|
-
[
|
|
81
|
-
state,
|
|
82
|
-
setup,
|
|
83
|
-
"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.",
|
|
84
|
-
]
|
|
85
|
-
.filter(Boolean)
|
|
86
|
-
.join(" ") +
|
|
87
|
-
"\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."
|
|
88
|
-
);
|
|
47
|
+
return "Shared boards are unavailable. Load Agent Board or Agent Comms and reload Pi. Your saved boards are preserved; other agent operations remain available.";
|
|
89
48
|
}
|