@vicary/pi-subagents 0.88.0 → 0.89.0
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 +54 -1
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +3 -3
- package/bundle/{chunk-6EUQPQY7.js → chunk-443LPCRI.js} +5 -5
- package/bundle/{chunk-4QFZZV3O.js → chunk-4AL6LDBY.js} +3 -1
- package/bundle/{chunk-CKLZ5FGU.js → chunk-4ALRHKGE.js} +1 -1
- package/bundle/{chunk-SVIXQDIV.js → chunk-6JD4XCA4.js} +77 -19
- package/bundle/{chunk-XZXYPZUT.js → chunk-7JLNWAMO.js} +54 -36
- package/bundle/{chunk-RHYVKQQL.js → chunk-7W2IQFP4.js} +4 -4
- package/bundle/{chunk-W6HIYD2Z.js → chunk-A3INCQ6Z.js} +1 -1
- package/bundle/{chunk-JYHTDTOZ.js → chunk-CFIYO2IV.js} +5 -5
- package/bundle/{chunk-CYKNHFXB.js → chunk-EPMRDKQT.js} +1 -1
- package/bundle/{chunk-6PR44R7E.js → chunk-ETDE2VYK.js} +2 -2
- package/bundle/{chunk-4MVDMA5C.js → chunk-GHJ6BH5U.js} +13 -7
- package/bundle/{chunk-IZEKQEY4.js → chunk-HSHLPYCQ.js} +27 -10
- package/bundle/{chunk-3MFYKBKI.js → chunk-HZDLR73C.js} +4 -4
- package/bundle/{chunk-2DIEL4WG.js → chunk-JFACGAJT.js} +2 -2
- package/bundle/{chunk-L4YY2TOE.js → chunk-JRO2CU4D.js} +1 -1
- package/bundle/{chunk-KXW62VBU.js → chunk-KOLLMZ2X.js} +1 -1
- package/bundle/{chunk-TDJKY2NE.js → chunk-LEPIY76E.js} +34 -5
- package/bundle/{chunk-BW5JLKIU.js → chunk-MJHQIUU7.js} +68 -41
- package/bundle/{chunk-47ZN7NKR.js → chunk-NONHDYXE.js} +1 -1
- package/bundle/{chunk-PJSOS2Q4.js → chunk-NQ26PJSQ.js} +96 -96
- package/bundle/{chunk-AOSILI5R.js → chunk-OVBUEVOT.js} +95 -49
- package/bundle/{chunk-NVGQE2H2.js → chunk-PFZZMVD5.js} +75 -32
- package/bundle/{chunk-YDZ7BZD5.js → chunk-S77ZKDLS.js} +1 -1
- package/bundle/{chunk-3DT5X2QC.js → chunk-SLLZJ5EC.js} +50 -18
- package/bundle/{chunk-V7SZMS6W.js → chunk-SWL2EITY.js} +2 -2
- package/bundle/{chunk-XIA5GSEU.js → chunk-UQT2EQ4U.js} +2 -2
- package/bundle/{chunk-YZPVALSQ.js → chunk-WW6GQBBS.js} +4 -4
- package/bundle/{chunk-CTPAE36Y.js → chunk-YARY7JWU.js} +22 -0
- package/bundle/{chunk-GDR2ILWY.js → chunk-ZSCIHMUI.js} +50 -22
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +2 -2
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +9 -9
- package/bundle/project-panes.js +3 -3
- package/bundle/required-child-extensions.js +1 -1
- package/docs/agents.md +14 -6
- package/docs/configuration.md +2 -0
- package/docs/extension-api.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/workflows.md +8 -4
- package/package.json +2 -2
- package/src/extension/herdr-pi-bridge.js +78 -22
- package/src/extension/index.d.ts +1 -1
- package/src/extension/index.js +43 -20
- package/src/extension/schemas.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +6 -2
- package/src/extension/subagent-launch-tool.js +13 -9
- package/src/extension/subagent-options.js +5 -0
- package/src/intercom/result-intercom.js +3 -2
- package/src/runs/background/notify.d.ts +3 -0
- package/src/runs/background/notify.js +7 -2
- package/src/runs/background/run-status.js +3 -2
- package/src/runs/background/runner-child-launch.js +1 -0
- package/src/runs/background/stale-run-reconciler.js +17 -8
- package/src/runs/background/subagent-runner.js +11 -8
- package/src/runs/foreground/execution.js +8 -7
- package/src/runs/foreground/subagent-executor.js +42 -11
- package/src/runs/shared/child-launch.d.ts +2 -0
- package/src/runs/shared/child-launch.js +7 -4
- package/src/runs/shared/child-session.d.ts +3 -2
- package/src/runs/shared/child-session.js +3 -27
- package/src/runs/shared/herdr-connection.d.ts +6 -0
- package/src/runs/shared/herdr-connection.js +11 -1
- package/src/runs/shared/herdr-machine.d.ts +2 -2
- package/src/runs/shared/herdr-machine.js +47 -22
- package/src/runs/shared/herdr-pane-host.d.ts +7 -19
- package/src/runs/shared/herdr-pane-host.js +48 -33
- package/src/runs/shared/herdr-pi-protocol.d.ts +1 -0
- package/src/runs/shared/herdr-pi-protocol.js +3 -2
- package/src/runs/shared/herdr-placed-run.d.ts +2 -12
- package/src/runs/shared/herdr-placed-run.js +10 -8
- package/src/runs/shared/kept-branch-text.d.ts +8 -0
- package/src/runs/shared/kept-branch-text.js +24 -0
- package/src/runs/shared/local-machine-access.d.ts +4 -1
- package/src/runs/shared/local-machine-access.js +6 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +5 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +5 -4
- package/src/runs/shared/mutation-evidence.d.ts +7 -1
- package/src/runs/shared/mutation-evidence.js +18 -2
- package/src/runs/shared/parallel-handoff.js +19 -7
- package/src/runs/shared/placed-run-owner.d.ts +4 -2
- package/src/runs/shared/placed-run-owner.js +15 -7
- package/src/runs/shared/rex-machine.d.ts +7 -3
- package/src/runs/shared/rex-machine.js +12 -9
- package/src/runs/shared/rex-pane-host.js +7 -27
- package/src/runs/shared/single-output.js +2 -2
- package/src/runs/shared/subagent-prompt-runtime.js +33 -0
- package/src/runs/shared/tool-availability.d.ts +4 -0
- package/src/runs/shared/tool-availability.js +7 -0
- package/src/runs/shared/worktree-cleanup-plan.js +2 -2
- package/src/runs/shared/worktree.d.ts +4 -14
- package/src/runs/shared/worktree.js +38 -8
- package/src/shared/compaction-interruption.d.ts +9 -0
- package/src/shared/compaction-interruption.js +47 -0
- package/src/shared/parent-wake.d.ts +3 -2
- package/src/shared/parent-wake.js +14 -3
- package/src/shared/required-child-extensions.d.ts +2 -0
- package/src/shared/required-child-extensions.js +27 -0
- package/src/shared/types.d.ts +26 -2
- package/src/tui/fleet.d.ts +7 -2
- package/src/tui/fleet.js +22 -0
- package/src/workflows/workflow-child-summary.d.ts +2 -1
- package/src/workflows/workflow-child-summary.js +14 -6
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { HerdrMachineReference, PlacementMachineReference } from "../../shared/types.ts";
|
|
1
|
+
import type { HerdrLocalMachineReference, HerdrMachineReference, PlacementMachineReference } from "../../shared/types.ts";
|
|
2
2
|
import { type HerdrForwardedConnection, type HerdrRpcClient } from "./herdr-connection.ts";
|
|
3
3
|
import type { HerdrRunIdentity } from "./herdr-placed-run.ts";
|
|
4
|
-
import { PlacedRunOwner
|
|
4
|
+
import { PlacedRunOwner } from "./placed-run-owner.ts";
|
|
5
5
|
import { type PlacementAgentKind, type PlacementBridgeIdentity, type PlacementEvidenceProof, type PlacementOwnedPane, type PlacementPromptOptions, type PlacementReconnectCheck, type PlacementRunState, type PlacementStartOptions } from "./placement-host.ts";
|
|
6
|
+
type HerdrPlacementMachine = HerdrMachineReference | HerdrLocalMachineReference;
|
|
6
7
|
export interface HerdrPaneCandidate {
|
|
7
8
|
endpoint: {
|
|
8
9
|
session: string | null;
|
|
@@ -35,7 +36,7 @@ export declare function provisionHerdrPane(client: HerdrRpcClient, cwd: string,
|
|
|
35
36
|
paneId: string;
|
|
36
37
|
}>;
|
|
37
38
|
declare function closeOwnedHerdrPane(connection: HerdrForwardedConnection, owned: PlacementOwnedPane, terminalId: string | undefined, agentName: string | undefined): Promise<void>;
|
|
38
|
-
/** Herdr pane host: Herdr RPC over the SSH-forwarded
|
|
39
|
+
/** Herdr pane host: Herdr RPC over the Herdr socket, SSH-forwarded for a saved machine and direct for `local`. Ownership is the Herdr terminal_id/pane_id pair; run state comes from agent_status. */
|
|
39
40
|
export declare const herdrPaneHost: {
|
|
40
41
|
connect(machine: PlacementMachineReference): Promise<HerdrForwardedConnection>;
|
|
41
42
|
sessionOf(connection: HerdrForwardedConnection): string | null;
|
|
@@ -61,23 +62,10 @@ export declare const herdrPaneHost: {
|
|
|
61
62
|
reconcile: typeof reconcileHerdrPlacedRun;
|
|
62
63
|
closeOwnedPane: typeof closeOwnedHerdrPane;
|
|
63
64
|
};
|
|
64
|
-
/** SSH
|
|
65
|
-
export declare
|
|
66
|
-
sshBin?: string;
|
|
67
|
-
env?: NodeJS.ProcessEnv;
|
|
68
|
-
}): Promise<PlacedBridgeManifest>;
|
|
69
|
-
export declare function createRemoteRuntimeDir(machine: HerdrMachineReference, runId: string, options?: {
|
|
70
|
-
sshBin?: string;
|
|
71
|
-
env?: NodeJS.ProcessEnv;
|
|
72
|
-
}): Promise<string>;
|
|
73
|
-
export declare function removeRemoteRuntimeDir(machine: HerdrMachineReference, runtimeDir: string, options?: {
|
|
74
|
-
sshBin?: string;
|
|
75
|
-
env?: NodeJS.ProcessEnv;
|
|
76
|
-
}): void;
|
|
77
|
-
/** The placed-run owner bound to Herdr and SSH access, plus the separate provision and start steps the external CLI adapters use. */
|
|
78
|
-
export declare class HerdrPlacedRunOwner extends PlacedRunOwner<HerdrForwardedConnection, HerdrMachineReference> {
|
|
65
|
+
/** The placed-run owner bound to Herdr and its machine access (SSH, or this machine for `local`), plus the separate provision and start steps the external CLI adapters use. */
|
|
66
|
+
export declare class HerdrPlacedRunOwner<M extends HerdrPlacementMachine = HerdrMachineReference> extends PlacedRunOwner<HerdrForwardedConnection, M> {
|
|
79
67
|
private constructor();
|
|
80
|
-
static create(machine:
|
|
68
|
+
static create<M extends HerdrPlacementMachine>(machine: M, runId: string, beforePane?: (owner: HerdrPlacedRunOwner<M>) => void | Promise<void>): Promise<HerdrPlacedRunOwner<M>>;
|
|
81
69
|
provision(environment?: Record<string, string>): Promise<PlacementOwnedPane>;
|
|
82
70
|
start(kind: PlacementAgentKind, name: string, args: string[], options?: PlacementStartOptions): Promise<{
|
|
83
71
|
terminalId: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { connectHerdrMachine, sshMachineAccess } from "./herdr-connection.js";
|
|
2
|
+
import { connectHerdrMachine, herdrLocalEnv, parseHerdrEndpoint, runBoundedCommand, SocketRpcClient, sshMachineAccess } from "./herdr-connection.js";
|
|
3
3
|
import { HERDR_PI_MODE_ENV, HERDR_PI_RUN_ENV, HERDR_PI_RUNTIME_DIR_ENV } from "./herdr-pi-protocol.js";
|
|
4
|
-
import {
|
|
4
|
+
import { localMachineAccess } from "./local-machine-access.js";
|
|
5
|
+
import { createPlacedRuntimeDir, hashedRuntimeDirName, PlacedRunOwner, removePlacedRuntimeDir } from "./placed-run-owner.js";
|
|
5
6
|
import { herdrPaneAllocationKey, withHerdrPaneAllocationLock } from "./placement-host.js";
|
|
6
7
|
function herdrRunState(status, fallback = "unknown") {
|
|
7
8
|
return status === "working" ? "working" : status === "blocked" ? "blocked" : status === "idle" || status === "done" ? "settled" : status === "unknown" ? "unknown" : fallback;
|
|
@@ -53,9 +54,23 @@ export async function provisionHerdrPane(client, cwd, runId, runtimeDir, environ
|
|
|
53
54
|
return { workspaceId: workspace.workspaceId, tabId: workspace.tabId, paneId: workspace.paneId };
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
|
-
function provisionHerdrOwnedPane(connection, machine, runId, runtimeDir, environment) { return provisionHerdrPane(connection.client, machine.cwd, runId, runtimeDir, environment, herdrPaneAllocationKey(machine.target, connection.endpoint.session, machine.cwd)); }
|
|
57
|
+
function provisionHerdrOwnedPane(connection, machine, runId, runtimeDir, environment) { return provisionHerdrPane(connection.client, machine.cwd, runId, runtimeDir, environment, "target" in machine ? herdrPaneAllocationKey(machine.target, connection.endpoint.session, machine.cwd) : JSON.stringify(["local", machine.socket, connection.endpoint.session, machine.cwd])); }
|
|
57
58
|
function asHerdrMachine(machine) { if (machine.provider !== "herdr")
|
|
58
|
-
throw new Error("The Herdr pane host only places runs on Herdr
|
|
59
|
+
throw new Error("The Herdr pane host only places runs on Herdr machines."); return machine; }
|
|
60
|
+
/** `machine: "local"` in Herdr: the recorded server on this machine, confirmed by socket and session, reached without SSH. */
|
|
61
|
+
async function connectLocalHerdrMachine(machine) {
|
|
62
|
+
const result = await runBoundedCommand(process.env.HERDR_BIN ?? "herdr", ["status", "server", "--json"], { env: herdrLocalEnv(machine.socket, machine.session, process.env), timeout: 15_000 });
|
|
63
|
+
if (result.error)
|
|
64
|
+
throw new Error(`Local Herdr discovery failed: ${result.error.message}`, { cause: result.error });
|
|
65
|
+
if (result.status !== 0)
|
|
66
|
+
throw new Error(`Local Herdr discovery failed with code ${result.status}: ${(result.stderr || result.stdout).trim().slice(0, 512)}`);
|
|
67
|
+
const endpoint = parseHerdrEndpoint(result.stdout, machine.session);
|
|
68
|
+
if (endpoint.socket !== machine.socket)
|
|
69
|
+
throw new Error(`Local Herdr server identity mismatch: expected socket ${machine.socket}, received ${endpoint.socket}.`);
|
|
70
|
+
return { endpoint, socketPath: machine.socket, client: new SocketRpcClient(machine.socket), ...localMachineAccess().openSockets() };
|
|
71
|
+
}
|
|
72
|
+
/** Local runtime directories go under /tmp: the bridge socket path inside a macOS TMPDIR exceeds the unix socket path limit. */
|
|
73
|
+
function herdrAccess(machine) { return "target" in machine ? sshMachineAccess(machine) : localMachineAccess({ env: { ...process.env, TMPDIR: "/tmp" } }); }
|
|
59
74
|
async function startHerdrAgent(connection, owned, kind, name, args, options = {}) {
|
|
60
75
|
const clock = options.clock ?? { now: () => Date.now(), wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)) }, deadline = clock.now() + (options.timeoutMs ?? 5_000), pollMs = options.pollMs ?? 50;
|
|
61
76
|
let response;
|
|
@@ -99,9 +114,9 @@ async function closeOwnedHerdrPane(connection, owned, terminalId, agentName) {
|
|
|
99
114
|
await connection.client.call("pane.close", { pane_id: owned.paneId });
|
|
100
115
|
}
|
|
101
116
|
}
|
|
102
|
-
/** Herdr pane host: Herdr RPC over the SSH-forwarded
|
|
117
|
+
/** Herdr pane host: Herdr RPC over the Herdr socket, SSH-forwarded for a saved machine and direct for `local`. Ownership is the Herdr terminal_id/pane_id pair; run state comes from agent_status. */
|
|
103
118
|
export const herdrPaneHost = {
|
|
104
|
-
connect(machine) { return connectHerdrMachine(
|
|
119
|
+
connect(machine) { const herdr = asHerdrMachine(machine); return "target" in herdr ? connectHerdrMachine(herdr) : connectLocalHerdrMachine(herdr); },
|
|
105
120
|
sessionOf(connection) { return connection.endpoint.session; },
|
|
106
121
|
async launch(connection, machine, runId, runtimeDir, request, onPane, options) { const owned = await provisionHerdrOwnedPane(connection, asHerdrMachine(machine), runId, runtimeDir, request.environment); await onPane(owned); const { terminalId } = await startHerdrAgent(connection, owned, request.kind, request.name, request.args, options); return { owned, terminalId }; },
|
|
107
122
|
async prompt(connection, identity, text, options = {}) {
|
|
@@ -127,37 +142,37 @@ export const herdrPaneHost = {
|
|
|
127
142
|
reconcile: reconcileHerdrPlacedRun,
|
|
128
143
|
closeOwnedPane: closeOwnedHerdrPane,
|
|
129
144
|
};
|
|
130
|
-
/** SSH
|
|
131
|
-
export function discoverBridgeManifest(machine, runId, runtimeDir, options = {}) { return discoverPlacedBridgeManifest(sshMachineAccess(machine, options), runId, runtimeDir); }
|
|
132
|
-
export function createRemoteRuntimeDir(machine, runId, options = {}) { return createPlacedRuntimeDir(sshMachineAccess(machine, options), runId); }
|
|
133
|
-
export function removeRemoteRuntimeDir(machine, runtimeDir, options = {}) { removePlacedRuntimeDir(sshMachineAccess(machine, options), runtimeDir); }
|
|
134
|
-
/** The placed-run owner bound to Herdr and SSH access, plus the separate provision and start steps the external CLI adapters use. */
|
|
145
|
+
/** The placed-run owner bound to Herdr and its machine access (SSH, or this machine for `local`), plus the separate provision and start steps the external CLI adapters use. */
|
|
135
146
|
export class HerdrPlacedRunOwner extends PlacedRunOwner {
|
|
136
|
-
constructor(machine, runId, runtimeDir, connection,
|
|
137
|
-
static async create(machine, runId, beforePane) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
await beforePane?.(owner);
|
|
141
|
-
return owner;
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
const cleanupErrors = [];
|
|
147
|
+
constructor(machine, runId, runtimeDir, connection, access) { super(machine, runId, runtimeDir, connection, herdrPaneHost, access); }
|
|
148
|
+
static async create(machine, runId, beforePane) {
|
|
149
|
+
const access = herdrAccess(machine), runtimeDir = await createPlacedRuntimeDir(access, "target" in machine ? runId : hashedRuntimeDirName(runId));
|
|
150
|
+
let connection;
|
|
145
151
|
try {
|
|
146
|
-
await
|
|
152
|
+
connection = await herdrPaneHost.connect(machine);
|
|
153
|
+
const owner = new HerdrPlacedRunOwner(machine, runId, runtimeDir, connection, access);
|
|
154
|
+
await beforePane?.(owner);
|
|
155
|
+
return owner;
|
|
147
156
|
}
|
|
148
|
-
catch (
|
|
149
|
-
cleanupErrors
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
catch (error) {
|
|
158
|
+
const cleanupErrors = [];
|
|
159
|
+
try {
|
|
160
|
+
await connection?.close();
|
|
161
|
+
}
|
|
162
|
+
catch (cleanupError) {
|
|
163
|
+
cleanupErrors.push(cleanupError);
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
removePlacedRuntimeDir(access, runtimeDir);
|
|
167
|
+
}
|
|
168
|
+
catch (cleanupError) {
|
|
169
|
+
cleanupErrors.push(cleanupError);
|
|
170
|
+
}
|
|
171
|
+
if (cleanupErrors.length)
|
|
172
|
+
throw new AggregateError([error, ...cleanupErrors], "Herdr owner creation failed and cleanup also failed.", { cause: error });
|
|
173
|
+
throw error;
|
|
156
174
|
}
|
|
157
|
-
|
|
158
|
-
throw new AggregateError([error, ...cleanupErrors], "Herdr owner creation failed and cleanup also failed.", { cause: error });
|
|
159
|
-
throw error;
|
|
160
|
-
} }
|
|
175
|
+
}
|
|
161
176
|
async provision(environment) { this.owned = await provisionHerdrOwnedPane(this.connection, this.machine, this.runId, this.runtimeDir, environment); return this.owned; }
|
|
162
177
|
async start(kind, name, args, options = {}) {
|
|
163
178
|
if (!this.owned)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const HERDR_PI_PROTOCOL = 1;
|
|
2
2
|
export declare const HERDR_PI_MAX_FRAME_BYTES: number;
|
|
3
|
+
export declare const HERDR_PI_MAX_ACCEPTANCE_PROMPT_BYTES: number;
|
|
3
4
|
export declare const HERDR_PI_MODE_ENV = "PI_SUBAGENTS_HERDR_BRIDGE";
|
|
4
5
|
export declare const HERDR_PI_RUN_ENV = "PI_SUBAGENTS_HERDR_RUN_ID";
|
|
5
6
|
export declare const HERDR_PI_RUNTIME_DIR_ENV = "PI_SUBAGENTS_HERDR_RUNTIME_DIR";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
export const HERDR_PI_PROTOCOL = 1;
|
|
3
3
|
export const HERDR_PI_MAX_FRAME_BYTES = 1024 * 1024;
|
|
4
|
+
export const HERDR_PI_MAX_ACCEPTANCE_PROMPT_BYTES = 256 * 1024;
|
|
4
5
|
export const HERDR_PI_MODE_ENV = "PI_SUBAGENTS_HERDR_BRIDGE";
|
|
5
6
|
export const HERDR_PI_RUN_ENV = "PI_SUBAGENTS_HERDR_RUN_ID";
|
|
6
7
|
export const HERDR_PI_RUNTIME_DIR_ENV = "PI_SUBAGENTS_HERDR_RUNTIME_DIR";
|
|
@@ -26,11 +27,11 @@ export class HerdrPiFrameDecoder {
|
|
|
26
27
|
#buffer = Buffer.alloc(0);
|
|
27
28
|
push(chunk) {
|
|
28
29
|
this.#buffer = Buffer.concat([this.#buffer, chunk]);
|
|
29
|
-
if (this.#buffer.byteLength > HERDR_PI_MAX_FRAME_BYTES)
|
|
30
|
-
throw new Error(`Herdr Pi frame exceeds ${HERDR_PI_MAX_FRAME_BYTES} bytes.`);
|
|
31
30
|
const frames = [];
|
|
32
31
|
for (;;) {
|
|
33
32
|
const newline = this.#buffer.indexOf(10);
|
|
33
|
+
if ((newline < 0 ? this.#buffer.byteLength : newline) >= HERDR_PI_MAX_FRAME_BYTES)
|
|
34
|
+
throw new Error(`Herdr Pi frame exceeds ${HERDR_PI_MAX_FRAME_BYTES} bytes.`);
|
|
34
35
|
if (newline < 0)
|
|
35
36
|
break;
|
|
36
37
|
const line = this.#buffer.subarray(0, newline);
|
|
@@ -48,12 +48,7 @@ export declare function boundedHerdrReconnect(identity: HerdrRunIdentity, lastEv
|
|
|
48
48
|
}>;
|
|
49
49
|
export declare function serializeHerdrPiLaunch(launch: ChildSessionLaunch): {
|
|
50
50
|
args: string[];
|
|
51
|
-
resources:
|
|
52
|
-
agent: string;
|
|
53
|
-
skills?: string[];
|
|
54
|
-
toolCeiling?: string[];
|
|
55
|
-
reads?: string[] | false;
|
|
56
|
-
};
|
|
51
|
+
resources: NonNullable<ChildSessionLaunch["remoteResources"]>;
|
|
57
52
|
};
|
|
58
53
|
export declare class BridgeChannel {
|
|
59
54
|
#private;
|
|
@@ -72,12 +67,7 @@ export declare class BridgeChannel {
|
|
|
72
67
|
get failed(): boolean;
|
|
73
68
|
adopt(listener: (frame: HerdrPiFrame) => void): HerdrPiFrame[];
|
|
74
69
|
wait(type: string, requestId: string): Promise<HerdrPiFrame>;
|
|
75
|
-
configure(resources:
|
|
76
|
-
agent: string;
|
|
77
|
-
skills?: string[];
|
|
78
|
-
toolCeiling?: string[];
|
|
79
|
-
reads?: string[] | false;
|
|
80
|
-
}): Promise<HerdrPiFrame>;
|
|
70
|
+
configure(resources: ReturnType<typeof serializeHerdrPiLaunch>["resources"]): Promise<HerdrPiFrame>;
|
|
81
71
|
supervisorDelivered(requestId: string): void;
|
|
82
72
|
prepare(requestId: string, operation: string, text?: string, supervisorId?: string, supervisorError?: string): Promise<HerdrPiFrame>;
|
|
83
73
|
close(): void;
|
|
@@ -4,11 +4,11 @@ import * as net from "node:net";
|
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import packageJson from "../../../package.json" with { type: "json" };
|
|
6
6
|
import { herdrPaneHost, HerdrPlacedRunOwner } from "./herdr-pane-host.js";
|
|
7
|
-
import { encodeHerdrPiFrame, HERDR_PI_MODE_ENV, HERDR_PI_PROTOCOL, HERDR_PI_RUN_ENV, HERDR_PI_RUNTIME_DIR_ENV, HerdrPiFrameDecoder, validateHerdrPiRunId } from "./herdr-pi-protocol.js";
|
|
7
|
+
import { encodeHerdrPiFrame, HERDR_PI_MAX_ACCEPTANCE_PROMPT_BYTES, HERDR_PI_MODE_ENV, HERDR_PI_PROTOCOL, HERDR_PI_RUN_ENV, HERDR_PI_RUNTIME_DIR_ENV, HerdrPiFrameDecoder, validateHerdrPiRunId } from "./herdr-pi-protocol.js";
|
|
8
8
|
import { discoverPlacedBridgeManifest } from "./placed-run-owner.js";
|
|
9
9
|
import { RexPlacedRunOwner } from "./rex-pane-host.js";
|
|
10
10
|
import { ensureSupervisorChannelDir } from "../../intercom/native-supervisor-channel.js";
|
|
11
|
-
import {
|
|
11
|
+
import { editsLocalDisk } from "./rex-machine.js";
|
|
12
12
|
import { PLACED_RESTORE_UNSUPPORTED } from "./herdr-machine.js";
|
|
13
13
|
/** The pane half comes from the host; the bridge half (run, package, protocol, native session, evidence cursor) is host-neutral. */
|
|
14
14
|
export function reconcileHerdrReconnect(identity, candidate, lastEvidenceCursor, host = herdrPaneHost) {
|
|
@@ -47,11 +47,13 @@ export function serializeHerdrPiLaunch(launch) {
|
|
|
47
47
|
throw new Error("Pane-native remote Pi cannot transfer local bindings, MCP selections, or process environment.");
|
|
48
48
|
if (launch.runtime.nestedRoute || launch.runtime.fanoutChild || launch.runtime.depth > 1)
|
|
49
49
|
throw new Error("Nested delegation from a pane-native remote Pi is not supported.");
|
|
50
|
-
if (launch.excludeTools?.length || launch.runtime.permissions || launch.runtime.toolBudget || launch.runtime.requiredExtensions || launch.runtime.mcpDirectTools?.length)
|
|
51
|
-
throw new Error("Pane-native remote Pi cannot yet represent exclusions, permission rules, tool budgets, MCP direct tools,
|
|
50
|
+
if (launch.excludeTools?.length || launch.runtime.permissions || launch.runtime.toolBudget || launch.runtime.requiredExtensions || launch.runtime.mcpDirectTools?.length || launch.runtime.structuredOutput)
|
|
51
|
+
throw new Error("Pane-native remote Pi cannot yet represent exclusions, permission rules, tool budgets, MCP direct tools, required-extension contracts, or outputSchema; remove machine placement.");
|
|
52
52
|
const resources = launch.remoteResources;
|
|
53
53
|
if (!resources || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(resources.agent) || resources.skills?.some((name) => !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(name)) || resources.toolCeiling?.some((name) => !/^[A-Za-z0-9_-]{1,64}$/u.test(name)) || (resources.reads !== undefined && resources.reads !== false && resources.reads.some((read) => typeof read !== "string" || Buffer.byteLength(read) > 4096)))
|
|
54
54
|
throw new Error("Pane-native remote resources require bounded logical agent, skill, tool, and read names.");
|
|
55
|
+
if (resources.acceptancePrompt !== undefined && Buffer.byteLength(resources.acceptancePrompt) > HERDR_PI_MAX_ACCEPTANCE_PROMPT_BYTES)
|
|
56
|
+
throw new Error(`A placed Pi child's acceptance instructions exceed ${HERDR_PI_MAX_ACCEPTANCE_PROMPT_BYTES} bytes; shorten the acceptance criteria or remove machine placement.`);
|
|
55
57
|
const args = [];
|
|
56
58
|
if (launch.noSkills)
|
|
57
59
|
args.push("--no-skills", "--no-prompt-templates");
|
|
@@ -59,7 +61,7 @@ export function serializeHerdrPiLaunch(launch) {
|
|
|
59
61
|
args.push("--no-context-files");
|
|
60
62
|
if (launch.model)
|
|
61
63
|
args.push("--model", launch.model);
|
|
62
|
-
return { args, resources: { agent: resources.agent, ...(resources.skills ? { skills: [...resources.skills] } : {}), ...(resources.toolCeiling ? { toolCeiling: [...resources.toolCeiling] } : {}), ...(resources.reads !== undefined ? { reads: resources.reads === false ? false : [...resources.reads] } : {}) } };
|
|
64
|
+
return { args, resources: { agent: resources.agent, ...(resources.skills ? { skills: [...resources.skills] } : {}), ...(resources.toolCeiling ? { toolCeiling: [...resources.toolCeiling] } : {}), ...(resources.reads !== undefined ? { reads: resources.reads === false ? false : [...resources.reads] } : {}), ...(resources.acceptancePrompt ? { acceptancePrompt: resources.acceptancePrompt } : {}) } };
|
|
63
65
|
}
|
|
64
66
|
export class BridgeChannel {
|
|
65
67
|
socket;
|
|
@@ -345,9 +347,9 @@ export async function reconnectHerdrPiSession(session, launch, dependencies = {}
|
|
|
345
347
|
}
|
|
346
348
|
export async function createHerdrPiSession(launch) {
|
|
347
349
|
if (!launch.machine)
|
|
348
|
-
throw new Error("Pane-native Pi launch requires a
|
|
350
|
+
throw new Error("Pane-native Pi launch requires a machine.");
|
|
349
351
|
if (launch.machine.provider !== "herdr")
|
|
350
|
-
throw new Error("Herdr pane-native Pi launch requires a Herdr
|
|
352
|
+
throw new Error("Herdr pane-native Pi launch requires a Herdr machine.");
|
|
351
353
|
const policy = serializeHerdrPiLaunch(launch);
|
|
352
354
|
const runId = safeRunId(launch.runtime.runId);
|
|
353
355
|
return startPlacedPiSession(launch, await HerdrPlacedRunOwner.create(launch.machine, runId), policy);
|
|
@@ -385,7 +387,7 @@ async function startPlacedPiSession(launch, owner, policy) {
|
|
|
385
387
|
throw new Error(`Remote Pi agent '${policy.resources.agent}' did not activate required tools: ${missingRequired.join(", ")}.`);
|
|
386
388
|
if (launch.model && configured.model !== launch.model.split(":")[0])
|
|
387
389
|
throw new Error(`Remote Pi model '${launch.model}' did not resolve to the requested provider/model.`);
|
|
388
|
-
const identity = { runId, machineId: machine.id, target:
|
|
390
|
+
const identity = { runId, machineId: machine.id, target: editsLocalDisk(machine) ? machine.id : machine.target, session: owner.host.sessionOf(connection), workspaceId: owned.workspaceId, tabId: owned.tabId, paneId: owned.paneId, terminalId, agentName, nativeSessionId: manifest.nativeSessionId, cwd: machine.cwd, runtimeDir };
|
|
389
391
|
owner.journal(identity);
|
|
390
392
|
const session = new HerdrPiSession(owner, bridgeForward, bridge, configured.tools, typeof ready.model === "string" ? ready.model : undefined, launch.runtime, ready.initialGit);
|
|
391
393
|
reconnectSession = session;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ParallelHandoffReference } from "../../shared/types.ts";
|
|
2
|
+
export type KeptBranch = NonNullable<ParallelHandoffReference["keptBranches"]>[number];
|
|
3
|
+
/** Kept branches from a saved handoff reference, which is read back from disk. */
|
|
4
|
+
export declare function readKeptBranches(value: unknown): KeptBranch[];
|
|
5
|
+
export declare function formatKeptBranchLines(keptBranches: readonly KeptBranch[]): string[];
|
|
6
|
+
/** The kept-branch lines follow the handoff line directly: `parseKeptBranchLines` reads them back from there. */
|
|
7
|
+
export declare function formatParallelHandoffLines(handoffPath: string, keptBranches: unknown): string[];
|
|
8
|
+
export declare function parseKeptBranchLines(lines: string[]): KeptBranch[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const KEPT_BRANCH_LINE = /^Kept branch (\S+) at ([0-9a-f]+): its commits are on no other branch\.$/;
|
|
2
|
+
/** Kept branches from a saved handoff reference, which is read back from disk. */
|
|
3
|
+
export function readKeptBranches(value) {
|
|
4
|
+
if (!Array.isArray(value))
|
|
5
|
+
return [];
|
|
6
|
+
return value.filter((entry) => typeof entry?.branch === "string" && typeof entry?.tip === "string");
|
|
7
|
+
}
|
|
8
|
+
export function formatKeptBranchLines(keptBranches) {
|
|
9
|
+
return keptBranches.map(({ branch, tip }) => `Kept branch ${branch} at ${tip.slice(0, 12)}: its commits are on no other branch.`);
|
|
10
|
+
}
|
|
11
|
+
/** The kept-branch lines follow the handoff line directly: `parseKeptBranchLines` reads them back from there. */
|
|
12
|
+
export function formatParallelHandoffLines(handoffPath, keptBranches) {
|
|
13
|
+
return [`Parallel handoff: ${handoffPath}`, ...formatKeptBranchLines(readKeptBranches(keptBranches))];
|
|
14
|
+
}
|
|
15
|
+
export function parseKeptBranchLines(lines) {
|
|
16
|
+
const kept = [];
|
|
17
|
+
for (const line of lines) {
|
|
18
|
+
const match = line.match(KEPT_BRANCH_LINE);
|
|
19
|
+
if (!match)
|
|
20
|
+
break;
|
|
21
|
+
kept.push({ branch: match[1], tip: match[2] });
|
|
22
|
+
}
|
|
23
|
+
return kept;
|
|
24
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { PlacementMachineAccess } from "./placement-host.ts";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Machine access for the parent's own machine: the same quoted `sh -c` scripts the SSH access sends, run directly through /bin/sh.
|
|
4
|
+
* They keep this process's PATH instead of the fixed remote one, which lacks coreutils on hosts such as NixOS.
|
|
5
|
+
*/
|
|
3
6
|
export declare function localMachineAccess(options?: {
|
|
4
7
|
env?: NodeJS.ProcessEnv;
|
|
5
8
|
}): PlacementMachineAccess;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { runBoundedCommand, shellScriptCommand } from "./herdr-connection.js";
|
|
4
4
|
const DEFAULT_TIMEOUT_MS = 15_000, DEFAULT_MAX_BUFFER = 256 * 1024;
|
|
5
5
|
/** Sockets on this machine are already reachable: forwarding returns the path unchanged and closing is a no-op. */
|
|
6
6
|
function localSockets() {
|
|
@@ -10,11 +10,14 @@ function localSockets() {
|
|
|
10
10
|
async close() { },
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Machine access for the parent's own machine: the same quoted `sh -c` scripts the SSH access sends, run directly through /bin/sh.
|
|
15
|
+
* They keep this process's PATH instead of the fixed remote one, which lacks coreutils on hosts such as NixOS.
|
|
16
|
+
*/
|
|
14
17
|
export function localMachineAccess(options = {}) {
|
|
15
18
|
const env = options.env ?? process.env;
|
|
16
19
|
return {
|
|
17
|
-
shellCommand:
|
|
20
|
+
shellCommand: shellScriptCommand,
|
|
18
21
|
run(command, limits = {}) {
|
|
19
22
|
const spawned = spawnSync("/bin/sh", ["-c", command], { encoding: "utf8", env, timeout: limits.timeout ?? DEFAULT_TIMEOUT_MS, maxBuffer: limits.maxBuffer ?? DEFAULT_MAX_BUFFER, windowsHide: true });
|
|
20
23
|
const result = { status: spawned.status, stdout: spawned.stdout ?? "", stderr: spawned.stderr ?? "" };
|
|
@@ -53,6 +53,7 @@ export interface McpRuntimeSnapshotHost {
|
|
|
53
53
|
/** Pi 0.99: servers extensions added with `pi.registerMcpServer()`. */
|
|
54
54
|
getMcpServers?(): readonly {
|
|
55
55
|
name: string;
|
|
56
|
+
extensionPath: string;
|
|
56
57
|
}[];
|
|
57
58
|
}
|
|
58
59
|
/** A `pi.getAllTools()` entry; `exposure` and `namespace` exist only from Pi 0.99. */
|
|
@@ -76,8 +77,9 @@ export declare function resolveMcpDirectToolResolution(mcpDirectTools: string[]
|
|
|
76
77
|
export declare function formatUnresolvedBuiltinMcpSelectors(agentName: string | undefined, selectors: readonly string[]): string;
|
|
77
78
|
/**
|
|
78
79
|
* Selected servers that only an extension registered, which a child without ambient extensions
|
|
79
|
-
* never has
|
|
80
|
-
* the
|
|
80
|
+
* never has unless the registering extension is one the child loads (`loadedByChild`). A server of
|
|
81
|
+
* the same name in an `mcp.json` the child reads takes precedence; like Pi, the project file is read
|
|
82
|
+
* only when the project is trusted.
|
|
81
83
|
*/
|
|
82
|
-
export declare function extensionOnlyMcpServers(selections: readonly ResolvedMcpDirectToolSelection[], host: McpRuntimeSnapshotHost, cwd: string, projectTrusted: boolean): string[];
|
|
84
|
+
export declare function extensionOnlyMcpServers(selections: readonly ResolvedMcpDirectToolSelection[], host: McpRuntimeSnapshotHost, cwd: string, projectTrusted: boolean, loadedByChild: (extensionPath: string) => boolean): string[];
|
|
83
85
|
export declare function computeMcpServerHash(definition: ServerEntry): string;
|
|
@@ -118,11 +118,12 @@ export function formatUnresolvedBuiltinMcpSelectors(agentName, selectors) {
|
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Selected servers that only an extension registered, which a child without ambient extensions
|
|
121
|
-
* never has
|
|
122
|
-
* the
|
|
121
|
+
* never has unless the registering extension is one the child loads (`loadedByChild`). A server of
|
|
122
|
+
* the same name in an `mcp.json` the child reads takes precedence; like Pi, the project file is read
|
|
123
|
+
* only when the project is trusted.
|
|
123
124
|
*/
|
|
124
|
-
export function extensionOnlyMcpServers(selections, host, cwd, projectTrusted) {
|
|
125
|
-
const registered = new Set(host.getMcpServers?.().map(({ name }) => name));
|
|
125
|
+
export function extensionOnlyMcpServers(selections, host, cwd, projectTrusted, loadedByChild) {
|
|
126
|
+
const registered = new Set(host.getMcpServers?.().filter(({ extensionPath }) => !loadedByChild(extensionPath)).map(({ name }) => name));
|
|
126
127
|
const servers = [...new Set(selections.map(({ selector }) => selector.split("/")[0]))].filter((server) => registered.has(server));
|
|
127
128
|
if (servers.length === 0)
|
|
128
129
|
return [];
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type { ArtifactPaths, TimeoutRecoveryProjection, TimeoutRecoverySummary, TrackedMutationEvidence, TrackedMutationSnapshot } from "../../shared/types.ts";
|
|
1
|
+
import type { ArtifactPaths, HerdrRemoteGitStatus, TimeoutRecoveryProjection, TimeoutRecoverySummary, TrackedMutationEvidence, TrackedMutationSnapshot } from "../../shared/types.ts";
|
|
2
2
|
export declare function snapshotTrackedMutations(cwd: string): TrackedMutationSnapshot;
|
|
3
|
+
/** A placed child on another machine edits that machine's disk, so local Git evidence stands in only as a marked placeholder. */
|
|
4
|
+
export declare function remoteMutationSnapshot(cwd: string): TrackedMutationSnapshot;
|
|
5
|
+
export declare function remoteMutationEvidence(machine: {
|
|
6
|
+
initialGit?: HerdrRemoteGitStatus;
|
|
7
|
+
finalGit?: HerdrRemoteGitStatus;
|
|
8
|
+
}): TrackedMutationEvidence;
|
|
3
9
|
export declare function collectTrackedMutationEvidence(snapshot: TrackedMutationSnapshot, cwd?: string): Promise<TrackedMutationEvidence>;
|
|
4
10
|
/** Keep status and completion details to bounded routing evidence, not raw output or effects. */
|
|
5
11
|
export declare function projectTimeoutRecovery(value: unknown): TimeoutRecoveryProjection | undefined;
|
|
@@ -43,6 +43,14 @@ async function hashFileAsync(diffPath) {
|
|
|
43
43
|
function splitNul(output) {
|
|
44
44
|
return output.split("\0").filter((part) => part.length > 0);
|
|
45
45
|
}
|
|
46
|
+
/** Git prints its whole option reference after the error, which must not reach recovery summaries. */
|
|
47
|
+
function gitFailureReason(error) {
|
|
48
|
+
const stderr = error && typeof error === "object" && "stderr" in error ? String(error.stderr ?? "") : "";
|
|
49
|
+
if (/not a git repository/i.test(stderr))
|
|
50
|
+
return "not a Git work tree";
|
|
51
|
+
const firstLine = (stderr || (error instanceof Error ? error.message : String(error))).split("\n").find((line) => line.trim().length > 0);
|
|
52
|
+
return firstLine?.trim() ?? "git failed";
|
|
53
|
+
}
|
|
46
54
|
function hashLargeDiff(cwd, relativePath) {
|
|
47
55
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagents-tracked-diff-"));
|
|
48
56
|
const diffPath = path.join(tempDir, "diff.patch");
|
|
@@ -96,7 +104,7 @@ export function snapshotTrackedMutations(cwd) {
|
|
|
96
104
|
return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: changed.paths, fingerprints, truncated: changed.truncated };
|
|
97
105
|
}
|
|
98
106
|
catch (error) {
|
|
99
|
-
return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: [], fingerprints: {}, unavailable:
|
|
107
|
+
return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: [], fingerprints: {}, unavailable: gitFailureReason(error) };
|
|
100
108
|
}
|
|
101
109
|
}
|
|
102
110
|
async function fingerprintPathAsync(cwd, relativePath) {
|
|
@@ -116,6 +124,14 @@ async function fingerprintPathAsync(cwd, relativePath) {
|
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
126
|
}
|
|
127
|
+
/** A placed child on another machine edits that machine's disk, so local Git evidence stands in only as a marked placeholder. */
|
|
128
|
+
export function remoteMutationSnapshot(cwd) {
|
|
129
|
+
return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: [], fingerprints: {}, unavailable: "Local Git evidence is not authoritative for a pane-native remote run." };
|
|
130
|
+
}
|
|
131
|
+
export function remoteMutationEvidence(machine) {
|
|
132
|
+
const changed = machine.initialGit && machine.finalGit ? machine.initialGit.head !== machine.finalGit.head || machine.initialGit.dirty !== machine.finalGit.dirty : undefined;
|
|
133
|
+
return { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: changed === true, ...(changed === undefined ? { unavailable: "Remote Git before/after evidence was incomplete." } : {}) };
|
|
134
|
+
}
|
|
119
135
|
export async function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
|
|
120
136
|
if (snapshot.unavailable) {
|
|
121
137
|
return { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: false, unavailable: snapshot.unavailable };
|
|
@@ -144,7 +160,7 @@ export async function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cw
|
|
|
144
160
|
};
|
|
145
161
|
}
|
|
146
162
|
catch (error) {
|
|
147
|
-
return { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: false, unavailable:
|
|
163
|
+
return { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: false, unavailable: gitFailureReason(error) };
|
|
148
164
|
}
|
|
149
165
|
}
|
|
150
166
|
function formatPathList(paths) {
|
|
@@ -3,8 +3,9 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { writeAtomicJson } from "../../shared/atomic-json.js";
|
|
5
5
|
import { stableJsonDigest } from "../../shared/launch-contract.js";
|
|
6
|
-
import { cleanupWorktrees, withWorktreeTransaction } from "./worktree.js";
|
|
6
|
+
import { cleanupWorktrees, isWorktreeCleanupTaskDone, withWorktreeTransaction } from "./worktree.js";
|
|
7
7
|
import { assertWorkflowLaneKey, normalizeWorkflowLaneMetadata } from "./lane-metadata.js";
|
|
8
|
+
import { formatKeptBranchLines } from "./kept-branch-text.js";
|
|
8
9
|
function optionalIdentity(value, label) {
|
|
9
10
|
if (value === undefined)
|
|
10
11
|
return undefined;
|
|
@@ -209,6 +210,7 @@ export function resolveRetainedWorktreeCwd(manifestPath, runId, childIndex, reco
|
|
|
209
210
|
}
|
|
210
211
|
function referenceFor(manifestPath, manifest) {
|
|
211
212
|
const children = manifest.groups.flatMap((group) => group.children);
|
|
213
|
+
const keptBranches = manifest.groups.flatMap((group) => group.cleanup.tasks.flatMap((task) => task.keptBranchTip ? [{ branch: task.branch, tip: task.keptBranchTip }] : []));
|
|
212
214
|
return {
|
|
213
215
|
version: 1,
|
|
214
216
|
path: manifestPath,
|
|
@@ -216,6 +218,7 @@ function referenceFor(manifestPath, manifest) {
|
|
|
216
218
|
childCount: children.length,
|
|
217
219
|
changedPatches: children.filter((child) => child.patch.changed).length,
|
|
218
220
|
cleanupState: manifest.groups.every((group) => group.cleanup.state === "complete") ? "complete" : "partial",
|
|
221
|
+
...(keptBranches.length ? { keptBranches } : {}),
|
|
219
222
|
...(Object.prototype.hasOwnProperty.call(manifest, "cleanupEligibility")
|
|
220
223
|
? { cleanupEligibility: trustedStoredCleanupEligibility(manifest) }
|
|
221
224
|
: {}),
|
|
@@ -627,6 +630,8 @@ function writeParallelHandoffGroupUnlocked(input) {
|
|
|
627
630
|
task.worktreeRemoved = true;
|
|
628
631
|
if (previous?.branchRemoved)
|
|
629
632
|
task.branchRemoved = true;
|
|
633
|
+
if (previous?.keptBranchTip)
|
|
634
|
+
task.keptBranchTip = previous.keptBranchTip;
|
|
630
635
|
if (!task.worktreeRemoved && previous?.reason?.includes("retained child resume")) {
|
|
631
636
|
task.preserved = true;
|
|
632
637
|
task.reason = previous.reason;
|
|
@@ -719,10 +724,17 @@ export function writeWorktreeSetupHandoff(input) {
|
|
|
719
724
|
});
|
|
720
725
|
}
|
|
721
726
|
export function formatParallelHandoffReference(reference) {
|
|
722
|
-
|
|
727
|
+
// After cleanup a patch is the only copy of the work, and nothing applies it to the parent's checkout.
|
|
728
|
+
const patches = reference.changedPatches > 0 ? "; the work is in groups[].children[].patch, not applied to this checkout" : "";
|
|
729
|
+
const kept = reference.cleanupState === "complete" ? "" : "; groups[].cleanup.tasks[] (reason, errors) says what stayed behind";
|
|
730
|
+
return [
|
|
731
|
+
`Worktree handoff: ${reference.path} (${reference.childCount} children, ${reference.changedPatches} changed patches, cleanup ${reference.cleanupState})${patches}${kept}`,
|
|
732
|
+
...formatKeptBranchLines(reference.keptBranches ?? []),
|
|
733
|
+
].join("\n");
|
|
723
734
|
}
|
|
724
735
|
export function formatParallelHandoffError(error) {
|
|
725
|
-
|
|
736
|
+
// This can fire before, during, or after cleanup, so it cannot say whether the worktrees still exist.
|
|
737
|
+
return `Worktree handoff unavailable: ${error instanceof Error ? error.message : String(error)}; check \`git worktree list\` for worktrees left behind`;
|
|
726
738
|
}
|
|
727
739
|
export function discardPreservedWorktrees(...args) {
|
|
728
740
|
return withHandoffWriteLock(args[0], () => discardPreservedWorktreesUnlocked(...args));
|
|
@@ -734,7 +746,7 @@ function discardPreservedWorktreesUnlocked(manifestPath, authorization) {
|
|
|
734
746
|
throw new Error(`Parallel handoff manifest not found: ${resolvedPath}`);
|
|
735
747
|
let attempted = 0;
|
|
736
748
|
for (const group of manifest.groups) {
|
|
737
|
-
const pending = group.cleanup.tasks.filter((task) => task.preserved && (
|
|
749
|
+
const pending = group.cleanup.tasks.filter((task) => task.preserved && !isWorktreeCleanupTaskDone(task));
|
|
738
750
|
if (pending.length === 0)
|
|
739
751
|
continue;
|
|
740
752
|
attempted += pending.length;
|
|
@@ -753,13 +765,13 @@ function discardPreservedWorktreesUnlocked(manifestPath, authorization) {
|
|
|
753
765
|
syntheticPaths: [],
|
|
754
766
|
})),
|
|
755
767
|
}, { kind: "discard", authorization });
|
|
756
|
-
const updates = new Map(report.tasks.map((task) => [task.index, task
|
|
768
|
+
const updates = new Map(report.tasks.map((task) => [task.index, isWorktreeCleanupTaskDone(task)
|
|
757
769
|
? task
|
|
758
770
|
: { ...task, preserved: true, reason: task.reason ?? "discard cleanup remains incomplete" }]));
|
|
759
771
|
group.cleanup = {
|
|
760
772
|
state: group.cleanup.tasks.every((task) => {
|
|
761
773
|
const next = updates.get(task.index) ?? task;
|
|
762
|
-
return next
|
|
774
|
+
return isWorktreeCleanupTaskDone(next);
|
|
763
775
|
}) && report.pruned ? "complete" : "partial",
|
|
764
776
|
tasks: group.cleanup.tasks.map((task) => updates.get(task.index) ?? task),
|
|
765
777
|
pruned: report.pruned,
|
|
@@ -769,7 +781,7 @@ function discardPreservedWorktreesUnlocked(manifestPath, authorization) {
|
|
|
769
781
|
manifest.updatedAt = Date.now();
|
|
770
782
|
writeAtomicJson(resolvedPath, manifest);
|
|
771
783
|
const remaining = manifest.groups.flatMap((group) => group.cleanup.tasks.map((task) => ({ group, task })))
|
|
772
|
-
.filter(({ task }) => task.preserved && (
|
|
784
|
+
.filter(({ task }) => task.preserved && !isWorktreeCleanupTaskDone(task));
|
|
773
785
|
const lines = attempted === 0
|
|
774
786
|
? [`No preserved worktrees remain in ${resolvedPath}.`]
|
|
775
787
|
: [`Discard processed ${attempted} preserved worktree${attempted === 1 ? "" : "s"}.`, `Manifest: ${resolvedPath}`];
|
|
@@ -9,7 +9,9 @@ export interface PlacedBridgeManifest {
|
|
|
9
9
|
}
|
|
10
10
|
/** Prints `$1/manifest.json` when it is a regular file, never through a symlink. */
|
|
11
11
|
export declare const PLACED_MANIFEST_READ_SCRIPT = "p=\"$1/manifest.json\"; test -f \"$p\" && test ! -L \"$p\" && cat \"$p\"";
|
|
12
|
-
export declare function discoverPlacedBridgeManifest(access: PlacementMachineAccess, runId: string, runtimeDir: string, missing?: string): Promise<PlacedBridgeManifest>;
|
|
12
|
+
export declare function discoverPlacedBridgeManifest(access: PlacementMachineAccess, runId: string, runtimeDir: string, missing?: string, deadlineMs?: number): Promise<PlacedBridgeManifest>;
|
|
13
|
+
/** A short hash names a runtime directory under /tmp, so /tmp/pi-subagents-herdr-<hash>-XXXXXXXX/bridge.sock (57 bytes) fits the 103-byte macOS socket path limit for any run id. */
|
|
14
|
+
export declare function hashedRuntimeDirName(runId: string): string;
|
|
13
15
|
export declare function createPlacedRuntimeDir(access: PlacementMachineAccess, runId: string): Promise<string>;
|
|
14
16
|
export declare function removePlacedRuntimeDir(access: PlacementMachineAccess, runtimeDir: string): void;
|
|
15
17
|
/** The single private owner for allocation shared by every pane-native backend projection. */
|
|
@@ -26,7 +28,7 @@ export declare class PlacedRunOwner<C extends PlacementSockets, M extends Placem
|
|
|
26
28
|
agentName?: string;
|
|
27
29
|
startedArgv?: string[];
|
|
28
30
|
identity?: HerdrRunIdentity;
|
|
29
|
-
protected constructor(machine: M, runId: string, runtimeDir: string, connection: C, host: PlacementPaneHost<C>, access: PlacementMachineAccess
|
|
31
|
+
protected constructor(machine: M, runId: string, runtimeDir: string, connection: C, host: PlacementPaneHost<C>, access: PlacementMachineAccess);
|
|
30
32
|
observeEvent(event: unknown): void;
|
|
31
33
|
markConnectionUnknown(observed: C): boolean;
|
|
32
34
|
subscribe(listener: (event: unknown) => void, disconnected: (error: Error) => void): Promise<void>;
|