@howaboua/pi-shepherdr 0.2.22 → 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 +16 -18
- package/README.md +79 -58
- package/biome.json +1 -1
- package/index.ts +7 -3
- package/package.json +14 -9
- package/src/agents-discovery.ts +42 -27
- package/src/agents-focus.ts +2 -2
- package/src/agents-reply.ts +1 -1
- package/src/agents-spawn.ts +143 -137
- package/src/agents-tool.ts +3 -3
- package/src/agents-work.ts +33 -9
- 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/launch.ts +14 -2
- 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-extension-messages.ts +14 -1
- package/src/monitor.ts +4 -2
- package/src/peer-inbox.ts +2 -2
- package/src/profile-prompt.ts +32 -0
- package/src/profiles.ts +5 -25
- 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-role.ts +83 -0
- package/src/worker-service.ts +74 -89
- package/src/fleet.ts +0 -702
- package/src/messages.ts +0 -629
- package/src/remote-client.ts +0 -751
|
@@ -5,10 +5,10 @@ import type {
|
|
|
5
5
|
import type {
|
|
6
6
|
SharedContextRequest,
|
|
7
7
|
SharedContextResult,
|
|
8
|
-
} from "@howaboua/pi-
|
|
8
|
+
} from "@howaboua/pi-notes-compaction/context-sharing";
|
|
9
9
|
import { attachmentOwner, attachmentRoutes } from "./attachment-protocol.js";
|
|
10
10
|
import type { AgentBoard } from "./board/host.js";
|
|
11
|
-
import type { AgentFleet } from "./fleet.js";
|
|
11
|
+
import type { AgentFleet } from "./fleet/index.js";
|
|
12
12
|
import {
|
|
13
13
|
listenContext,
|
|
14
14
|
sessionContextPath,
|
|
@@ -21,37 +21,60 @@ export async function registerSharedAgentContext(
|
|
|
21
21
|
board: AgentBoard,
|
|
22
22
|
): Promise<SharedAgentContext> {
|
|
23
23
|
let api:
|
|
24
|
-
| typeof import("@howaboua/pi-
|
|
24
|
+
| typeof import("@howaboua/pi-notes-compaction/context-sharing")
|
|
25
25
|
| undefined;
|
|
26
26
|
try {
|
|
27
|
-
api = await import("@howaboua/pi-
|
|
27
|
+
api = await import("@howaboua/pi-notes-compaction/context-sharing");
|
|
28
28
|
} catch (error) {
|
|
29
29
|
const failure = error as { code?: string; message?: string };
|
|
30
30
|
const missing = failure.message?.match(
|
|
31
31
|
/Cannot find (?:package|module) ['"]([^'"]+)['"]/,
|
|
32
32
|
)?.[1];
|
|
33
|
-
const module = "@howaboua/pi-
|
|
33
|
+
const module = "@howaboua/pi-notes-compaction/context-sharing";
|
|
34
34
|
const unavailable =
|
|
35
35
|
((failure.code === "ERR_MODULE_NOT_FOUND" ||
|
|
36
36
|
failure.code === "MODULE_NOT_FOUND") &&
|
|
37
|
-
(missing === "@howaboua/pi-
|
|
37
|
+
(missing === "@howaboua/pi-notes-compaction" ||
|
|
38
38
|
missing === module ||
|
|
39
39
|
missing?.endsWith(`/${module}`))) ||
|
|
40
40
|
(failure.code === "ERR_PACKAGE_PATH_NOT_EXPORTED" &&
|
|
41
|
-
failure.message?.includes("@howaboua/pi-
|
|
41
|
+
failure.message?.includes("@howaboua/pi-notes-compaction") &&
|
|
42
42
|
failure.message.includes("./context-sharing"));
|
|
43
43
|
if (!unavailable)
|
|
44
44
|
throw new Error(
|
|
45
|
-
"Update pi-
|
|
45
|
+
"Update pi-notes-compaction to use shared agent context",
|
|
46
46
|
{ cause: error },
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
|
-
const connection = api?.
|
|
49
|
+
const connection = api?.connectNotesContextSharing(pi);
|
|
50
|
+
let relationships:
|
|
51
|
+
| ReturnType<
|
|
52
|
+
typeof import("@howaboua/pi-codex-conversion/agent-relationship")["connectCodexAgentRelationships"]
|
|
53
|
+
>
|
|
54
|
+
| undefined;
|
|
55
|
+
try {
|
|
56
|
+
const relationshipApi = await import(
|
|
57
|
+
"@howaboua/pi-codex-conversion/agent-relationship"
|
|
58
|
+
);
|
|
59
|
+
relationships = relationshipApi.connectCodexAgentRelationships(pi);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
const failure = error as { code?: string; message?: string };
|
|
62
|
+
if (
|
|
63
|
+
!(
|
|
64
|
+
(failure.code === "ERR_MODULE_NOT_FOUND" ||
|
|
65
|
+
failure.code === "MODULE_NOT_FOUND" ||
|
|
66
|
+
failure.code === "ERR_PACKAGE_PATH_NOT_EXPORTED") &&
|
|
67
|
+
failure.message?.includes("pi-codex-conversion")
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
50
72
|
const shared = new SharedAgentContext(
|
|
51
73
|
pi,
|
|
52
74
|
fleet,
|
|
53
75
|
() => connection?.service,
|
|
54
76
|
board,
|
|
77
|
+
() => relationships?.service,
|
|
55
78
|
);
|
|
56
79
|
let close: (() => Promise<void>) | undefined;
|
|
57
80
|
let unregister: (() => void) | undefined;
|
|
@@ -103,8 +126,6 @@ export async function registerSharedAgentContext(
|
|
|
103
126
|
signal,
|
|
104
127
|
);
|
|
105
128
|
if (attached) return attached;
|
|
106
|
-
if (connection?.service?.describe(context)?.storage === "remote")
|
|
107
|
-
return undefined;
|
|
108
129
|
return shared.handle(
|
|
109
130
|
context,
|
|
110
131
|
{ operation: "context", request, visited: [] },
|
|
@@ -129,6 +150,7 @@ export async function registerSharedAgentContext(
|
|
|
129
150
|
unregister?.();
|
|
130
151
|
await close?.();
|
|
131
152
|
connection?.dispose();
|
|
153
|
+
relationships?.dispose();
|
|
132
154
|
});
|
|
133
155
|
fleet.setContextRelay((ctx, request, signal) =>
|
|
134
156
|
shared.handle(ctx, request, signal),
|
package/src/shared-context.ts
CHANGED
|
@@ -4,16 +4,17 @@ import type {
|
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { binding, isBoardEnvelope } from "@howaboua/pi-agent-board/integration";
|
|
7
|
+
import type { CodexAgentRelationshipService } from "@howaboua/pi-codex-conversion/agent-relationship";
|
|
7
8
|
import type {
|
|
8
9
|
ContextSharingService,
|
|
9
10
|
SharedContextRequest,
|
|
10
11
|
SharedContextResult,
|
|
11
|
-
} from "@howaboua/pi-
|
|
12
|
+
} from "@howaboua/pi-notes-compaction/context-sharing";
|
|
12
13
|
import { Check } from "typebox/value";
|
|
13
14
|
import { AgentAttachment } from "./attachment.js";
|
|
14
15
|
import { Identity } from "./attachment-protocol.js";
|
|
15
16
|
import type { AgentBoard } from "./board/host.js";
|
|
16
|
-
import type { AgentFleet } from "./fleet.js";
|
|
17
|
+
import type { AgentFleet } from "./fleet/index.js";
|
|
17
18
|
import { sessionPath } from "./herdr.js";
|
|
18
19
|
import {
|
|
19
20
|
requestContext,
|
|
@@ -35,6 +36,9 @@ export class SharedAgentContext {
|
|
|
35
36
|
private readonly fleet: AgentFleet;
|
|
36
37
|
private readonly getService: () => ContextSharingService | undefined;
|
|
37
38
|
private readonly board: AgentBoard;
|
|
39
|
+
private readonly getRelationships: () =>
|
|
40
|
+
| CodexAgentRelationshipService
|
|
41
|
+
| undefined;
|
|
38
42
|
private running = false;
|
|
39
43
|
readonly attachment: AgentAttachment;
|
|
40
44
|
readonly spawns: SpawnContext;
|
|
@@ -44,12 +48,14 @@ export class SharedAgentContext {
|
|
|
44
48
|
fleet: AgentFleet,
|
|
45
49
|
getService: () => ContextSharingService | undefined,
|
|
46
50
|
board: AgentBoard,
|
|
51
|
+
getRelationships: () => CodexAgentRelationshipService | undefined,
|
|
47
52
|
) {
|
|
48
53
|
this.fleet = fleet;
|
|
49
54
|
this.getService = getService;
|
|
50
55
|
this.board = board;
|
|
56
|
+
this.getRelationships = getRelationships;
|
|
51
57
|
this.attachment = new AgentAttachment(pi, board, getService);
|
|
52
|
-
this.spawns = new SpawnContext(pi, getService);
|
|
58
|
+
this.spawns = new SpawnContext(pi, getService, getRelationships);
|
|
53
59
|
pi.on("before_agent_start", () => {
|
|
54
60
|
this.running = true;
|
|
55
61
|
});
|
|
@@ -149,7 +155,7 @@ export class SharedAgentContext {
|
|
|
149
155
|
}
|
|
150
156
|
if ("operation" in value && value.operation === "bind-relationship") {
|
|
151
157
|
return (
|
|
152
|
-
|
|
158
|
+
this.getRelationships()?.bind(
|
|
153
159
|
ctx,
|
|
154
160
|
"relationship" in value ? value.relationship : undefined,
|
|
155
161
|
) ?? null
|
package/src/spawn-context.ts
CHANGED
|
@@ -3,8 +3,9 @@ import type {
|
|
|
3
3
|
ExtensionAPI,
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
6
|
+
import type { CodexAgentRelationshipService } from "@howaboua/pi-codex-conversion/agent-relationship";
|
|
7
|
+
import type { ContextSharingService } from "@howaboua/pi-notes-compaction/context-sharing";
|
|
8
|
+
import type { ConnectedMachine } from "./fleet/index.js";
|
|
8
9
|
import { sessionPath } from "./herdr.js";
|
|
9
10
|
import { sessionContextPath } from "./remote/shepherdr-context.mjs";
|
|
10
11
|
import type { PaneInfo } from "./types.js";
|
|
@@ -21,14 +22,20 @@ interface Routing {
|
|
|
21
22
|
transport: "shepherdr";
|
|
22
23
|
parent: string;
|
|
23
24
|
}
|
|
25
|
+
|
|
24
26
|
export class SpawnContext {
|
|
25
27
|
private readonly pi: ExtensionAPI;
|
|
28
|
+
private readonly getRelationships: () =>
|
|
29
|
+
| CodexAgentRelationshipService
|
|
30
|
+
| undefined;
|
|
26
31
|
private readonly getService: () => ContextSharingService | undefined;
|
|
27
32
|
constructor(
|
|
28
33
|
pi: ExtensionAPI,
|
|
29
34
|
getService: () => ContextSharingService | undefined,
|
|
35
|
+
getRelationships: () => CodexAgentRelationshipService | undefined,
|
|
30
36
|
) {
|
|
31
37
|
this.pi = pi;
|
|
38
|
+
this.getRelationships = getRelationships;
|
|
32
39
|
this.getService = getService;
|
|
33
40
|
}
|
|
34
41
|
prepareRelationship(
|
|
@@ -36,8 +43,8 @@ export class SpawnContext {
|
|
|
36
43
|
runtime: ConnectedMachine,
|
|
37
44
|
args: readonly string[],
|
|
38
45
|
) {
|
|
39
|
-
const service = this.
|
|
40
|
-
if (!service
|
|
46
|
+
const service = this.getRelationships();
|
|
47
|
+
if (!service) return undefined;
|
|
41
48
|
// Session-selection profiles resume existing identities rather than creating workers.
|
|
42
49
|
if (
|
|
43
50
|
args.some((arg) =>
|
|
@@ -48,7 +55,7 @@ export class SpawnContext {
|
|
|
48
55
|
)
|
|
49
56
|
return undefined;
|
|
50
57
|
const parentThreadId = ctx.sessionManager.getSessionId();
|
|
51
|
-
const cacheAffinityId = service.cacheAffinityId
|
|
58
|
+
const cacheAffinityId = service.cacheAffinityId(ctx);
|
|
52
59
|
const linkage = { parentThreadId, subagentKind: "collab_spawn" };
|
|
53
60
|
const relationship = {
|
|
54
61
|
...linkage,
|
|
@@ -112,18 +119,15 @@ export class SpawnContext {
|
|
|
112
119
|
throw new Error(
|
|
113
120
|
"Shared context spawn requires a saved controller session",
|
|
114
121
|
);
|
|
115
|
-
const routing: Routing
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
: runtime.client.contextRelayPath(),
|
|
122
|
-
}
|
|
123
|
-
: undefined;
|
|
122
|
+
const routing: Routing = {
|
|
123
|
+
transport: "shepherdr",
|
|
124
|
+
parent: runtime.local
|
|
125
|
+
? sessionContextPath(parentFile)
|
|
126
|
+
: runtime.client.contextRelayPath(),
|
|
127
|
+
};
|
|
124
128
|
const { binding, adopt } = await service.createChild(ctx, {
|
|
125
129
|
name,
|
|
126
|
-
|
|
130
|
+
routing,
|
|
127
131
|
});
|
|
128
132
|
return {
|
|
129
133
|
accept: async (agent: PaneInfo) => {
|
|
@@ -136,8 +140,7 @@ export class SpawnContext {
|
|
|
136
140
|
);
|
|
137
141
|
if (!value)
|
|
138
142
|
return {
|
|
139
|
-
warning:
|
|
140
|
-
"Spawned without shared context: the target needs Codex conversion with notes-based continuity",
|
|
143
|
+
warning: "Spawned without shared context: the target needs Notes",
|
|
141
144
|
};
|
|
142
145
|
if (
|
|
143
146
|
typeof value !== "object" ||
|
package/src/voice-handoff.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { recordContextBriefing } from "@howaboua/pi-agent-board/integration";
|
|
7
|
-
import { voiceFocusContinuity, voiceFocusReport } from "./messages.js";
|
|
7
|
+
import { voiceFocusContinuity, voiceFocusReport } from "./messages/focus.js";
|
|
8
8
|
import { registerFocusChannelReceiver } from "./peer-channel.js";
|
|
9
9
|
import type { FocusRequest, PaneInfo, PeerChannel } from "./types.js";
|
|
10
10
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
|
|
6
|
+
export const WORKER_FLAG = "shepherdr-worker";
|
|
7
|
+
export const PULSE_WORKER_FLAG = "shepherdr-pulse-worker";
|
|
8
|
+
const WORKER_MARKER = "herdr-worker-v1";
|
|
9
|
+
const LEGACY_PULSE_MARKER = "herdr-pulse-worker-v1";
|
|
10
|
+
const WORKER_ROLE_CHANNEL = "shepherdr:worker-role:v1";
|
|
11
|
+
|
|
12
|
+
type SessionManager = ExtensionContext["sessionManager"];
|
|
13
|
+
|
|
14
|
+
/** Optional synchronous event request; consumers need no Shepherdr import. */
|
|
15
|
+
interface WorkerRoleRequest {
|
|
16
|
+
sessionManager: SessionManager;
|
|
17
|
+
reply: (worker: boolean) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function markedWorker(manager: SessionManager, pulseOnly = false): boolean {
|
|
21
|
+
const sessionId = manager.getSessionId();
|
|
22
|
+
return manager.getEntries().some((entry) => {
|
|
23
|
+
if (
|
|
24
|
+
entry.type !== "custom" ||
|
|
25
|
+
(entry.customType !== WORKER_MARKER &&
|
|
26
|
+
entry.customType !== LEGACY_PULSE_MARKER)
|
|
27
|
+
)
|
|
28
|
+
return false;
|
|
29
|
+
const data = entry.data as
|
|
30
|
+
| { sessionId?: unknown; pulse?: unknown }
|
|
31
|
+
| undefined;
|
|
32
|
+
return (
|
|
33
|
+
data?.sessionId === sessionId &&
|
|
34
|
+
(!pulseOnly ||
|
|
35
|
+
entry.customType === LEGACY_PULSE_MARKER ||
|
|
36
|
+
data.pulse === true)
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function registerWorkerRole(pi: ExtensionAPI) {
|
|
42
|
+
pi.registerFlag(WORKER_FLAG, {
|
|
43
|
+
type: "boolean",
|
|
44
|
+
default: false,
|
|
45
|
+
description: "Run as a supervised Shepherdr worker",
|
|
46
|
+
});
|
|
47
|
+
pi.registerFlag(PULSE_WORKER_FLAG, {
|
|
48
|
+
type: "boolean",
|
|
49
|
+
default: false,
|
|
50
|
+
description: "Run as a detached pulse worker",
|
|
51
|
+
});
|
|
52
|
+
const isWorker = (manager: SessionManager) =>
|
|
53
|
+
pi.getFlag(WORKER_FLAG) === true ||
|
|
54
|
+
pi.getFlag(PULSE_WORKER_FLAG) === true ||
|
|
55
|
+
markedWorker(manager);
|
|
56
|
+
const isPulseWorker = (manager: SessionManager) =>
|
|
57
|
+
pi.getFlag(PULSE_WORKER_FLAG) === true || markedWorker(manager, true);
|
|
58
|
+
// Read the supplied native session directly, even before our session_start.
|
|
59
|
+
pi.events.on(WORKER_ROLE_CHANNEL, (request: unknown) => {
|
|
60
|
+
const value = request as Partial<WorkerRoleRequest> | undefined;
|
|
61
|
+
if (
|
|
62
|
+
typeof value?.reply === "function" &&
|
|
63
|
+
typeof value.sessionManager?.getSessionId === "function" &&
|
|
64
|
+
typeof value.sessionManager.getEntries === "function"
|
|
65
|
+
)
|
|
66
|
+
value.reply(isWorker(value.sessionManager));
|
|
67
|
+
});
|
|
68
|
+
pi.on("before_agent_start", (_event, ctx) => {
|
|
69
|
+
const pulse = pi.getFlag(PULSE_WORKER_FLAG) === true;
|
|
70
|
+
if (
|
|
71
|
+
(pi.getFlag(WORKER_FLAG) === true || pulse) &&
|
|
72
|
+
(!markedWorker(ctx.sessionManager) ||
|
|
73
|
+
(pulse && !markedWorker(ctx.sessionManager, true)))
|
|
74
|
+
) {
|
|
75
|
+
// Startup entries would prevent fresh Notes family adoption before work.
|
|
76
|
+
pi.appendEntry(WORKER_MARKER, {
|
|
77
|
+
sessionId: ctx.sessionManager.getSessionId(),
|
|
78
|
+
...(pulse ? { pulse: true } : {}),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return { isWorker, isPulseWorker };
|
|
83
|
+
}
|
package/src/worker-service.ts
CHANGED
|
@@ -4,9 +4,9 @@ import type {
|
|
|
4
4
|
ExtensionContext,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { activityTask } from "./activity.js";
|
|
7
|
-
import {
|
|
7
|
+
import { dispatchAgentWork, reserveAgentName } from "./agents-work.js";
|
|
8
8
|
import type { AgentBoard } from "./board/host.js";
|
|
9
|
-
import type { AgentFleet } from "./fleet.js";
|
|
9
|
+
import type { AgentFleet } from "./fleet/index.js";
|
|
10
10
|
import { getSnapshot, sessionPath } from "./herdr.js";
|
|
11
11
|
import {
|
|
12
12
|
RolledBackAgentLaunchError,
|
|
@@ -14,14 +14,13 @@ import {
|
|
|
14
14
|
startAgent,
|
|
15
15
|
UnstartedAgentLaunchError,
|
|
16
16
|
} from "./launch.js";
|
|
17
|
-
import { attributeAgentPrompt } from "./messages.js";
|
|
17
|
+
import { attributeAgentPrompt } from "./messages/attribution.js";
|
|
18
18
|
import { loadAgentProfiles, profileAgentArgs } from "./profiles.js";
|
|
19
19
|
import type { SharedAgentContext } from "./shared-context.js";
|
|
20
20
|
import type { PaneInfo } from "./types.js";
|
|
21
|
+
import { PULSE_WORKER_FLAG, type registerWorkerRole } from "./worker-role.js";
|
|
21
22
|
|
|
22
23
|
const ENTRY = "herdr-owned-worker-v1";
|
|
23
|
-
const WORKER_MARKER = "herdr-pulse-worker-v1";
|
|
24
|
-
const WORKER_FLAG = "shepherdr-pulse-worker";
|
|
25
24
|
const RUNNER_PROTOCOL = "@howaboua/pi-pulses/runner/v1";
|
|
26
25
|
// Structural implementation of Pulses' optional runner ABI, without a private-package dependency.
|
|
27
26
|
interface PulseRun {
|
|
@@ -84,28 +83,12 @@ export function registerWorkerService(
|
|
|
84
83
|
fleet: AgentFleet,
|
|
85
84
|
shared: SharedAgentContext,
|
|
86
85
|
board: AgentBoard,
|
|
86
|
+
workerRole: ReturnType<typeof registerWorkerRole>,
|
|
87
87
|
): void {
|
|
88
88
|
let active: ExtensionContext | undefined;
|
|
89
89
|
let busy = false;
|
|
90
|
-
pi.registerFlag(WORKER_FLAG, {
|
|
91
|
-
type: "boolean",
|
|
92
|
-
default: false,
|
|
93
|
-
description: "Run as a detached pulse worker",
|
|
94
|
-
});
|
|
95
|
-
const markedWorker = (ctx: ExtensionContext) =>
|
|
96
|
-
ctx.sessionManager
|
|
97
|
-
.getEntries()
|
|
98
|
-
.some(
|
|
99
|
-
(entry) =>
|
|
100
|
-
entry.type === "custom" &&
|
|
101
|
-
entry.customType === WORKER_MARKER &&
|
|
102
|
-
(entry.data as { sessionId?: unknown } | undefined)?.sessionId ===
|
|
103
|
-
ctx.sessionManager.getSessionId(),
|
|
104
|
-
);
|
|
105
90
|
const isController = (ctx: ExtensionContext) =>
|
|
106
|
-
ctx.mode === "tui" &&
|
|
107
|
-
pi.getFlag(WORKER_FLAG) !== true &&
|
|
108
|
-
!markedWorker(ctx);
|
|
91
|
+
ctx.mode === "tui" && !workerRole.isPulseWorker(ctx.sessionManager);
|
|
109
92
|
function assertContext(ctx: ExtensionContext) {
|
|
110
93
|
if (!isController(ctx))
|
|
111
94
|
throw new Error("Detached workers cannot claim or schedule pulses");
|
|
@@ -257,7 +240,6 @@ export function registerWorkerService(
|
|
|
257
240
|
if (!profile)
|
|
258
241
|
throw new Error("General worker profile is unavailable");
|
|
259
242
|
const profileArgs = profileAgentArgs(profile, {
|
|
260
|
-
targetLocal: true,
|
|
261
243
|
includePrompt: false,
|
|
262
244
|
});
|
|
263
245
|
if (
|
|
@@ -272,70 +254,79 @@ export function registerWorkerService(
|
|
|
272
254
|
);
|
|
273
255
|
const args = [
|
|
274
256
|
...profileArgs,
|
|
275
|
-
`--${
|
|
257
|
+
`--${PULSE_WORKER_FLAG}`,
|
|
276
258
|
...(worker ? ["--session", worker.sessionPath] : []),
|
|
277
259
|
];
|
|
278
|
-
const
|
|
279
|
-
const
|
|
280
|
-
? undefined
|
|
281
|
-
: shared.spawns.prepareRelationship(ctx, runtime, args);
|
|
282
|
-
const sharing =
|
|
283
|
-
worker || profile.shareContext === false
|
|
284
|
-
? undefined
|
|
285
|
-
: await shared.spawns.prepare(ctx, runtime, name, args);
|
|
286
|
-
const boardBinding = worker
|
|
287
|
-
? undefined
|
|
288
|
-
: await board.prepare(ctx, runtime, name, args);
|
|
289
|
-
const workspace = runtime.local
|
|
290
|
-
? process.env["HERDR_WORKSPACE_ID"]
|
|
291
|
-
: undefined;
|
|
292
|
-
stage = "launch";
|
|
293
|
-
const started = await startAgent(
|
|
294
|
-
runtime.client,
|
|
295
|
-
{
|
|
296
|
-
name,
|
|
297
|
-
label: input.title,
|
|
298
|
-
cwd: input.cwd,
|
|
299
|
-
placement: workspace ? "new_tab" : "new_workspace",
|
|
300
|
-
...(workspace ? { workspace } : {}),
|
|
301
|
-
},
|
|
302
|
-
runtime.fallbackCwd,
|
|
303
|
-
runtime.resolveDirectory,
|
|
304
|
-
{ agentArgs: args },
|
|
305
|
-
);
|
|
260
|
+
const reservation = await reserveAgentName(runtime, input.title);
|
|
261
|
+
const { name } = reservation;
|
|
306
262
|
try {
|
|
307
|
-
const
|
|
308
|
-
|
|
263
|
+
const relationship = worker
|
|
264
|
+
? undefined
|
|
265
|
+
: shared.spawns.prepareRelationship(ctx, runtime, args);
|
|
266
|
+
const sharing =
|
|
267
|
+
worker || profile.shareContext === false
|
|
268
|
+
? undefined
|
|
269
|
+
: await shared.spawns.prepare(ctx, runtime, name, args);
|
|
270
|
+
const boardBinding = worker
|
|
271
|
+
? undefined
|
|
272
|
+
: await board.prepare(ctx, runtime, name, args);
|
|
273
|
+
const workspace = runtime.local
|
|
274
|
+
? process.env["HERDR_WORKSPACE_ID"]
|
|
275
|
+
: undefined;
|
|
276
|
+
stage = "launch";
|
|
277
|
+
const started = await startAgent(
|
|
278
|
+
runtime.client,
|
|
279
|
+
{
|
|
280
|
+
name,
|
|
281
|
+
label: input.title,
|
|
282
|
+
cwd: input.cwd,
|
|
283
|
+
placement: workspace ? "new_tab" : "new_workspace",
|
|
284
|
+
...(workspace ? { workspace } : {}),
|
|
285
|
+
},
|
|
286
|
+
runtime.fallbackCwd,
|
|
287
|
+
runtime.resolveDirectory,
|
|
288
|
+
{ agentArgs: args },
|
|
309
289
|
);
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
290
|
+
try {
|
|
291
|
+
const relationshipResult = await relationship?.accept(
|
|
292
|
+
started.agent,
|
|
293
|
+
);
|
|
294
|
+
await boardBinding?.accept(started.agent);
|
|
295
|
+
const sharingResult = await sharing?.accept(started.agent);
|
|
296
|
+
for (const warning of [
|
|
297
|
+
relationshipResult?.warning,
|
|
298
|
+
sharingResult?.warning,
|
|
299
|
+
])
|
|
300
|
+
if (warning) ctx.ui.notify(warning, "warning");
|
|
301
|
+
assertBranch();
|
|
302
|
+
panel = started.agent;
|
|
303
|
+
const file = sessionPath(panel);
|
|
304
|
+
if (!file || (worker && file !== worker.sessionPath))
|
|
305
|
+
throw new Error("Worker did not restore its saved session");
|
|
306
|
+
const identity = await runtime.client.machineIdentity();
|
|
307
|
+
worker = {
|
|
308
|
+
workerId: worker?.workerId ?? crypto.randomUUID(),
|
|
309
|
+
pulseId: input.taskId,
|
|
310
|
+
runId: "",
|
|
311
|
+
parent: ctx.sessionManager.getSessionFile()!,
|
|
312
|
+
...identity,
|
|
313
|
+
target: panel.pane_id,
|
|
314
|
+
terminal: panel.terminal_id,
|
|
315
|
+
sessionPath: file,
|
|
316
|
+
cwd: input.cwd,
|
|
317
|
+
};
|
|
318
|
+
pi.appendEntry(ENTRY, worker);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
return await rollbackStartedAgent(
|
|
321
|
+
runtime.client,
|
|
322
|
+
started,
|
|
323
|
+
error,
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
stage = "preflight";
|
|
327
|
+
} finally {
|
|
328
|
+
reservation.release();
|
|
337
329
|
}
|
|
338
|
-
stage = "preflight";
|
|
339
330
|
}
|
|
340
331
|
if (!worker) throw new Error("Worker ownership is unavailable");
|
|
341
332
|
const attributed = await attributeAgentPrompt(
|
|
@@ -397,12 +388,6 @@ export function registerWorkerService(
|
|
|
397
388
|
pi.on("session_start", () => {
|
|
398
389
|
active = undefined;
|
|
399
390
|
});
|
|
400
|
-
pi.on("before_agent_start", (_event, ctx) => {
|
|
401
|
-
if (pi.getFlag(WORKER_FLAG) === true && !markedWorker(ctx))
|
|
402
|
-
pi.appendEntry(WORKER_MARKER, {
|
|
403
|
-
sessionId: ctx.sessionManager.getSessionId(),
|
|
404
|
-
});
|
|
405
|
-
});
|
|
406
391
|
pi.on("resources_discover", (_event, ctx) => {
|
|
407
392
|
active = ctx;
|
|
408
393
|
});
|