pi-subagents 0.88.1 → 0.89.1
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 +51 -1
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-4QFZZV3O.js → chunk-4AL6LDBY.js} +3 -1
- package/bundle/{chunk-5EMPFFO4.js → chunk-4FFKVLBG.js} +4 -4
- package/bundle/{chunk-L4YY2TOE.js → chunk-5TXWZB73.js} +1 -1
- package/bundle/{chunk-ZJ2BT5TI.js → chunk-6D54VW3E.js} +56 -34
- package/bundle/{chunk-YDZ7BZD5.js → chunk-77VQEATI.js} +1 -1
- package/bundle/{chunk-7OX6O7DQ.js → chunk-BERAWSQQ.js} +5 -5
- package/bundle/{chunk-LV3CPYXJ.js → chunk-C22YEYFZ.js} +4 -4
- package/bundle/{chunk-VTUUOLM4.js → chunk-CASL47ST.js} +34 -5
- package/bundle/{chunk-YQSTGPEU.js → chunk-F6PTAPQ3.js} +75 -32
- package/bundle/{chunk-FLNDHNPE.js → chunk-IGZTXGPG.js} +98 -29
- package/bundle/{chunk-CPSUJHZE.js → chunk-KCDPTXHT.js} +39 -10
- package/bundle/{chunk-PCZEQQAQ.js → chunk-LUNVS6KP.js} +26 -15
- package/bundle/{chunk-4MVDMA5C.js → chunk-LWH7IGI3.js} +21 -7
- package/bundle/{chunk-DSHQWGHO.js → chunk-MIX3MCIF.js} +96 -96
- package/bundle/{chunk-2DIEL4WG.js → chunk-OUM6SEVD.js} +2 -2
- package/bundle/{chunk-XIA5GSEU.js → chunk-Q4VH72JI.js} +2 -2
- package/bundle/{chunk-D32H53HM.js → chunk-R3NH5XAL.js} +1 -1
- package/bundle/{chunk-6OWNDN7R.js → chunk-ROJH7KPK.js} +2 -2
- package/bundle/{chunk-4ZQBZDF3.js → chunk-SG3NCWZW.js} +86 -20
- package/bundle/{chunk-KXW62VBU.js → chunk-SWGB2P5J.js} +1 -1
- package/bundle/{chunk-N6TAAIB3.js → chunk-TDXVQPZW.js} +5 -5
- package/bundle/{chunk-6CG2VAG4.js → chunk-TRN65L4F.js} +1 -1
- package/bundle/{chunk-GDR2ILWY.js → chunk-TXC7WIPL.js} +51 -22
- package/bundle/{chunk-PYKBTBY6.js → chunk-URKQZHVH.js} +9 -9
- package/bundle/{chunk-W6HIYD2Z.js → chunk-UUW7P6KJ.js} +1 -1
- package/bundle/{chunk-CYKNHFXB.js → chunk-VEEUXJDO.js} +1 -1
- package/bundle/{chunk-47ZN7NKR.js → chunk-YJIU5WF4.js} +1 -1
- package/bundle/{chunk-RMZAAXIR.js → chunk-YLU5JFW2.js} +2 -2
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +2 -2
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +10 -4
- package/docs/configuration.md +2 -0
- package/docs/extension-api.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/workflows.md +5 -3
- package/package.json +1 -1
- package/src/extension/herdr-pi-bridge.js +79 -23
- package/src/extension/schemas.js +1 -1
- package/src/extension/subagent-options.js +5 -0
- package/src/intercom/result-intercom.js +3 -2
- package/src/runs/background/async-job-tracker.js +85 -9
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +8 -3
- 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/subagent-runner.js +11 -8
- package/src/runs/foreground/execution.js +8 -7
- package/src/runs/foreground/subagent-executor.js +31 -5
- package/src/runs/shared/child-launch.d.ts +2 -0
- package/src/runs/shared/child-launch.js +1 -1
- package/src/runs/shared/child-session.d.ts +2 -1
- 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 +49 -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/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 +34 -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/types.d.ts +26 -2
- package/src/shared/utils.d.ts +2 -0
- package/src/shared/utils.js +9 -0
- package/src/workflows/workflow-child-summary.d.ts +2 -1
- package/src/workflows/workflow-child-summary.js +14 -6
|
@@ -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>;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import * as fs from "node:fs";
|
|
2
3
|
import * as path from "node:path";
|
|
3
4
|
import { getAgentDir } from "../../shared/utils.js";
|
|
4
5
|
/** Prints `$1/manifest.json` when it is a regular file, never through a symlink. */
|
|
5
6
|
export const PLACED_MANIFEST_READ_SCRIPT = 'p="$1/manifest.json"; test -f "$p" && test ! -L "$p" && cat "$p"';
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/** A child with many extensions took about 12 s to write its manifest; a child stuck on a startup prompt holds its pane until this deadline. */
|
|
8
|
+
const PLACED_MANIFEST_DEADLINE_MS = 30_000;
|
|
9
|
+
export async function discoverPlacedBridgeManifest(access, runId, runtimeDir, missing = "The placed Pi's pi-subagents bridge manifest is not in its runtime directory; the Pi may have exited.", deadlineMs = PLACED_MANIFEST_DEADLINE_MS) {
|
|
10
|
+
const deadline = Date.now() + deadlineMs;
|
|
11
|
+
for (;;) {
|
|
8
12
|
const result = await access.runAsync(access.shellCommand(PLACED_MANIFEST_READ_SCRIPT, [runtimeDir]), { timeout: 5_000, maxBuffer: 64 * 1024 });
|
|
9
13
|
if (result.error)
|
|
10
14
|
throw new Error(`Remote bridge manifest discovery failed: ${result.error.message}`, { cause: result.error });
|
|
@@ -21,14 +25,19 @@ export async function discoverPlacedBridgeManifest(access, runId, runtimeDir, mi
|
|
|
21
25
|
throw new Error("Remote bridge manifest identity is incomplete or outside its owned runtime directory.");
|
|
22
26
|
return { socketPath: p.socketPath, nativeSessionId: p.nativeSessionId, packageVersion: p.packageVersion, protocol: p.protocol };
|
|
23
27
|
}
|
|
28
|
+
if (Date.now() >= deadline)
|
|
29
|
+
throw new Error(missing);
|
|
24
30
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
25
31
|
}
|
|
26
|
-
throw new Error(missing);
|
|
27
32
|
}
|
|
33
|
+
/** 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. */
|
|
34
|
+
export function hashedRuntimeDirName(runId) { return createHash("sha256").update(runId).digest("hex").slice(0, 12); }
|
|
28
35
|
export async function createPlacedRuntimeDir(access, runId) { const result = await access.runAsync(access.shellCommand("umask 077; mktemp -d \"${TMPDIR:-/tmp}/pi-subagents-herdr-$1-XXXXXXXX\"", [runId]), { timeout: 10_000, maxBuffer: 4096 }); if (result.error)
|
|
29
36
|
throw new Error(`Could not provision a run-private remote bridge runtime directory: ${result.error.message}`, { cause: result.error }); const value = result.stdout.trim(); if (result.status !== 0 || !path.posix.isAbsolute(value) || value.includes("\n"))
|
|
30
37
|
throw new Error("Could not provision a run-private remote bridge runtime directory."); return value; }
|
|
31
|
-
|
|
38
|
+
// Already-gone counts as removed: the placed child deletes its own runtime directory on session
|
|
39
|
+
// shutdown (herdr-pi-bridge), so the parent's cleanup races it and must tolerate losing.
|
|
40
|
+
export function removePlacedRuntimeDir(access, runtimeDir) { const result = access.run(access.shellCommand("p=$1; case \"${p##*/}\" in pi-subagents-herdr-*) if test -d \"$p\" && test ! -L \"$p\"; then rm -rf -- \"$p\"; fi; test ! -e \"$p\" && test ! -L \"$p\";; *) exit 64;; esac", [runtimeDir]), { timeout: 10_000, maxBuffer: 4096 }); if (result.status !== 0 || result.stdout)
|
|
32
41
|
throw new Error(`Could not remove the exact owned remote runtime directory: ${String(result.stderr).slice(0, 512)}`); }
|
|
33
42
|
/** The single private owner for allocation shared by every pane-native backend projection. */
|
|
34
43
|
export class PlacedRunOwner {
|
|
@@ -46,8 +55,7 @@ export class PlacedRunOwner {
|
|
|
46
55
|
#unsubscribe = () => { };
|
|
47
56
|
#snapshot = { connection: "connected", state: "ready", revision: 0 };
|
|
48
57
|
#cleanupPromise;
|
|
49
|
-
|
|
50
|
-
constructor(machine, runId, runtimeDir, connection, host, access, removeRuntime = () => removePlacedRuntimeDir(access, runtimeDir)) { this.machine = machine; this.runId = runId; this.runtimeDir = runtimeDir; this.connection = connection; this.#removeRuntime = removeRuntime; this.host = host; this.access = access; }
|
|
58
|
+
constructor(machine, runId, runtimeDir, connection, host, access) { this.machine = machine; this.runId = runId; this.runtimeDir = runtimeDir; this.connection = connection; this.host = host; this.access = access; }
|
|
51
59
|
observeEvent(event) { const data = this.host.paneEvent(event, this.#snapshot.state); if (data && (!this.terminalId || data.terminalId === this.terminalId || data.paneId === this.owned?.paneId))
|
|
52
60
|
this.#snapshot = { ...this.#snapshot, revision: this.#snapshot.revision + 1, state: data.state }; }
|
|
53
61
|
markConnectionUnknown(observed) { if (this.connection !== observed)
|
|
@@ -84,7 +92,7 @@ export class PlacedRunOwner {
|
|
|
84
92
|
} try {
|
|
85
93
|
this.#unsubscribe();
|
|
86
94
|
await this.connection.close();
|
|
87
|
-
this
|
|
95
|
+
removePlacedRuntimeDir(this.access, this.runtimeDir);
|
|
88
96
|
}
|
|
89
97
|
catch (error) {
|
|
90
98
|
failure ??= error;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { PlacementMachineReference, RexLocalMachineReference } from "../../shared/types.ts";
|
|
2
|
-
/** `machine: "local"` is reserved: this machine, in a
|
|
1
|
+
import type { HerdrLocalMachineReference, PlacementMachineReference, RexLocalMachineReference } from "../../shared/types.ts";
|
|
2
|
+
/** `machine: "local"` is reserved: this machine, in a new tab of the Herdr or Rex session this Pi runs in. It never consults the Herdr catalog. */
|
|
3
3
|
export declare const REX_LOCAL_MACHINE = "local";
|
|
4
4
|
/** Rex CLI exit codes: 3 means the target is gone, 4 means the server is unreachable (state unknown, never "gone"). */
|
|
5
5
|
export declare const REX_EXIT_GONE = 3, REX_EXIT_UNREACHABLE = 4;
|
|
6
|
-
/** A
|
|
6
|
+
/** A Rex pane in the parent's own Rex session; the other Rex reference is an SSH machine. */
|
|
7
7
|
export declare function isRexLocalMachine(machine: PlacementMachineReference | undefined): machine is RexLocalMachineReference;
|
|
8
|
+
/** A placed child without an SSH `target` (Rex or Herdr `local`) edits this machine's disk; every other placed child edits the remote one. */
|
|
9
|
+
export declare function editsLocalDisk(machine: PlacementMachineReference | undefined): machine is RexLocalMachineReference | HerdrLocalMachineReference;
|
|
8
10
|
/** The Rex server bundle's CLI, relative to the home directory. */
|
|
9
11
|
export declare const REX_BUNDLE_BIN = "Library/Application Support/com.superlogical.rex/RexServer/Versions/Current/Rex Server.app/Contents/MacOS/rex";
|
|
10
12
|
export declare const REX_CALL_TIMEOUT_MS = 15000, REX_MAX_OUTPUT: number;
|
|
@@ -23,3 +25,5 @@ export declare function resolveRexLocalPlacement(input: {
|
|
|
23
25
|
stepCwd?: string;
|
|
24
26
|
env?: NodeJS.ProcessEnv;
|
|
25
27
|
}): RexLocalMachineReference;
|
|
28
|
+
/** The real launch directory of a `local` child: `stepCwd` is absolute, `~`, or relative to the parent's launch directory `cwd`. */
|
|
29
|
+
export declare function resolveLocalLaunchCwd(parentCwd: string, stepCwd: string | undefined): string;
|
|
@@ -2,12 +2,14 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
-
/** `machine: "local"` is reserved: this machine, in a
|
|
5
|
+
/** `machine: "local"` is reserved: this machine, in a new tab of the Herdr or Rex session this Pi runs in. It never consults the Herdr catalog. */
|
|
6
6
|
export const REX_LOCAL_MACHINE = "local";
|
|
7
7
|
/** Rex CLI exit codes: 3 means the target is gone, 4 means the server is unreachable (state unknown, never "gone"). */
|
|
8
8
|
export const REX_EXIT_GONE = 3, REX_EXIT_UNREACHABLE = 4;
|
|
9
|
-
/** A
|
|
9
|
+
/** A Rex pane in the parent's own Rex session; the other Rex reference is an SSH machine. */
|
|
10
10
|
export function isRexLocalMachine(machine) { return machine?.provider === "rex" && !("target" in machine); }
|
|
11
|
+
/** A placed child without an SSH `target` (Rex or Herdr `local`) edits this machine's disk; every other placed child edits the remote one. */
|
|
12
|
+
export function editsLocalDisk(machine) { return machine !== undefined && !("target" in machine); }
|
|
11
13
|
/** The Rex server bundle's CLI, relative to the home directory. */
|
|
12
14
|
export const REX_BUNDLE_BIN = "Library/Application Support/com.superlogical.rex/RexServer/Versions/Current/Rex Server.app/Contents/MacOS/rex";
|
|
13
15
|
export const REX_CALL_TIMEOUT_MS = 15_000, REX_MAX_OUTPUT = 1024 * 1024;
|
|
@@ -64,9 +66,13 @@ export function resolveRexLocalPlacement(input) {
|
|
|
64
66
|
throw new Error(`rex session inspect exited with code ${result.status}: ${(result.stderr || result.stdout).trim().slice(0, 512)}`);
|
|
65
67
|
if (!sessionConfirmed(result.stdout, session))
|
|
66
68
|
throw new Error(`The Rex server did not confirm session ${session}.`);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
return { provider: "rex", id: REX_LOCAL_MACHINE, session, cwd: resolveLocalLaunchCwd(input.cwd, input.stepCwd), ...(server ? { server } : {}) };
|
|
70
|
+
}
|
|
71
|
+
/** The real launch directory of a `local` child: `stepCwd` is absolute, `~`, or relative to the parent's launch directory `cwd`. */
|
|
72
|
+
export function resolveLocalLaunchCwd(parentCwd, stepCwd) {
|
|
73
|
+
const step = stepCwd?.trim();
|
|
74
|
+
const home = step === "~" || step?.startsWith("~/") ? path.join(os.homedir(), step.slice(1)) : undefined;
|
|
75
|
+
const requested = home ?? (step ? path.resolve(parentCwd, step) : parentCwd);
|
|
70
76
|
let cwd;
|
|
71
77
|
try {
|
|
72
78
|
cwd = fs.realpathSync(requested);
|
|
@@ -76,8 +82,5 @@ export function resolveRexLocalPlacement(input) {
|
|
|
76
82
|
}
|
|
77
83
|
if (!fs.statSync(cwd).isDirectory())
|
|
78
84
|
throw new Error(`Machine 'local' cwd is not a directory: ${requested}.`);
|
|
79
|
-
|
|
80
|
-
if (server)
|
|
81
|
-
machine.server = server;
|
|
82
|
-
return machine;
|
|
85
|
+
return cwd;
|
|
83
86
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import * as path from "node:path";
|
|
3
2
|
import { Type } from "typebox";
|
|
4
3
|
import { Compile } from "typebox/compile";
|
|
5
|
-
import {
|
|
4
|
+
import { sshMachineAccess } from "./herdr-connection.js";
|
|
6
5
|
import { localMachineAccess } from "./local-machine-access.js";
|
|
7
6
|
import { getPiSpawnCommand } from "./pi-spawn.js";
|
|
8
|
-
import { createPlacedRuntimeDir, PLACED_MANIFEST_READ_SCRIPT, PlacedRunOwner, removePlacedRuntimeDir } from "./placed-run-owner.js";
|
|
7
|
+
import { createPlacedRuntimeDir, hashedRuntimeDirName, PLACED_MANIFEST_READ_SCRIPT, PlacedRunOwner, removePlacedRuntimeDir } from "./placed-run-owner.js";
|
|
9
8
|
import { withHerdrPaneAllocationLock } from "./placement-host.js";
|
|
10
9
|
import { isRexLocalMachine, REX_BUNDLE_BIN, REX_CALL_TIMEOUT_MS, REX_EXIT_GONE, REX_EXIT_UNREACHABLE, REX_MAX_OUTPUT, resolveRexBinary, rexCommandEnv, rexGlobalArgs } from "./rex-machine.js";
|
|
11
10
|
const REX_CLOSE_POLLS = 20, REX_CLOSE_POLL_MS = 50;
|
|
@@ -20,7 +19,7 @@ const bridgeManifestPid = Compile(Type.Object({ pid: Type.Integer() }));
|
|
|
20
19
|
/** Rex runtime directories go under /tmp: the bridge socket path inside a macOS TMPDIR exceeds the unix socket path limit. */
|
|
21
20
|
function rexAccess() { return localMachineAccess({ env: { ...rexCommandEnv(), TMPDIR: "/tmp" } }); }
|
|
22
21
|
/** The same /tmp rule on the remote, whatever TMPDIR its SSH session has. */
|
|
23
|
-
function rexSshAccess(machine, access = sshMachineAccess(machine)) { return { ...access, shellCommand: (script, args) =>
|
|
22
|
+
function rexSshAccess(machine, access = sshMachineAccess(machine)) { return { ...access, shellCommand: (script, args) => access.shellCommand(`TMPDIR=/tmp; export TMPDIR; ${script}`, args) }; }
|
|
24
23
|
function asRexMachine(machine) { if (machine.provider !== "rex")
|
|
25
24
|
throw new Error("The Rex pane host only places runs on Rex machines."); return machine; }
|
|
26
25
|
/** Runs one rex command on the pane machine with --autostart=false, the recorded server, and no inherited Rex selectors; exit 4 always throws. */
|
|
@@ -265,30 +264,11 @@ export const rexPaneHost = {
|
|
|
265
264
|
reconcile: reconcileRexPlacedRun,
|
|
266
265
|
closeOwnedPane: closeOwnedRexPane,
|
|
267
266
|
};
|
|
268
|
-
function runtimeDirPresent(access, runtimeDir) {
|
|
269
|
-
const result = access.run(access.shellCommand('test -e "$1" || test -L "$1"', [runtimeDir]), { timeout: 10_000, maxBuffer: 4096 });
|
|
270
|
-
if (result.error)
|
|
271
|
-
throw new Error(`Could not check the owned runtime directory: ${result.error.message}`, { cause: result.error });
|
|
272
|
-
return result.status === 0;
|
|
273
|
-
}
|
|
274
|
-
/** A closed local Pi removes its own runtime directory on shutdown, so already-removed counts as removed. */
|
|
275
|
-
function removeRexRuntimeDir(access, runtimeDir) {
|
|
276
|
-
if (!runtimeDirPresent(access, runtimeDir))
|
|
277
|
-
return;
|
|
278
|
-
try {
|
|
279
|
-
removePlacedRuntimeDir(access, runtimeDir);
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
if (runtimeDirPresent(access, runtimeDir))
|
|
283
|
-
throw error;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
267
|
export class RexPlacedRunOwner extends PlacedRunOwner {
|
|
287
|
-
constructor(machine, runId, runtimeDir, connection, access, host) { super(machine, runId, runtimeDir, connection, host, access
|
|
268
|
+
constructor(machine, runId, runtimeDir, connection, access, host) { super(machine, runId, runtimeDir, connection, host, access); }
|
|
288
269
|
/** A Rex SSH owner's machine carries the resolved remote cwd, and its host reconnects only to the session recorded here. */
|
|
289
270
|
static async create(machine, runId, options = {}) {
|
|
290
|
-
|
|
291
|
-
const hash = createHash("sha256").update(runId).digest("hex").slice(0, 12);
|
|
271
|
+
const hash = hashedRuntimeDirName(runId);
|
|
292
272
|
if (isRexLocalMachine(machine)) {
|
|
293
273
|
const access = rexAccess(), runtimeDir = await createPlacedRuntimeDir(access, hash);
|
|
294
274
|
try {
|
|
@@ -296,7 +276,7 @@ export class RexPlacedRunOwner extends PlacedRunOwner {
|
|
|
296
276
|
}
|
|
297
277
|
catch (error) {
|
|
298
278
|
try {
|
|
299
|
-
|
|
279
|
+
removePlacedRuntimeDir(access, runtimeDir);
|
|
300
280
|
}
|
|
301
281
|
catch (cleanupError) {
|
|
302
282
|
throw new AggregateError([error, cleanupError], "Rex owner creation failed and runtime cleanup also failed.", { cause: error });
|
|
@@ -314,7 +294,7 @@ export class RexPlacedRunOwner extends PlacedRunOwner {
|
|
|
314
294
|
}
|
|
315
295
|
catch (error) {
|
|
316
296
|
try {
|
|
317
|
-
|
|
297
|
+
removePlacedRuntimeDir(access, runtimeDir);
|
|
318
298
|
}
|
|
319
299
|
catch (cleanupError) {
|
|
320
300
|
throw new AggregateError([error, cleanupError], "Rex owner creation failed and runtime cleanup also failed.", { cause: error });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { editsLocalDisk } from "./rex-machine.js";
|
|
4
4
|
const READ_ONLY_OUTPUT_TOOLS = new Set([
|
|
5
5
|
"read", "grep", "find", "ls", "web_search", "fetch_content", "get_search_content",
|
|
6
6
|
"source_check", "intercom", "contact_supervisor", "structured_output", "watchdog_diff",
|
|
@@ -103,7 +103,7 @@ export function outputPathMappingFromTask(task, savedPath) {
|
|
|
103
103
|
export function injectSingleOutputInstruction(task, outputPath, capabilities, machine) {
|
|
104
104
|
if (!outputPath)
|
|
105
105
|
return task;
|
|
106
|
-
const remote = machine !== undefined && !
|
|
106
|
+
const remote = machine !== undefined && !editsLocalDisk(machine);
|
|
107
107
|
const delivery = !remote && (!capabilities || hasOutputWriteCapability(capabilities.tools, capabilities.mcpDirectTools))
|
|
108
108
|
? `Write your findings to exactly this path: ${outputPath}`
|
|
109
109
|
: [
|
|
@@ -229,8 +229,42 @@ function filterChildPromptOptions(options, inherited) {
|
|
|
229
229
|
function rewritesChildPrompt(config) {
|
|
230
230
|
return config.inheritProjectContext !== undefined || config.inheritGlobalContext !== undefined || config.inheritSkills !== undefined || Boolean(config.fanoutChild);
|
|
231
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* An extension can replace the tools a request declares (pi-fabric's code mode sends only its own
|
|
234
|
+
* `fabric_exec`), and Pi only reports a throw from a request hook. This hook runs after every other
|
|
235
|
+
* extension's, so a child whose active allowlisted tools were left out records why and stops
|
|
236
|
+
* before the provider gets the request. A request that declares them all passes through unchanged.
|
|
237
|
+
*/
|
|
238
|
+
function registerDeclaredToolCheck(pi, config, required) {
|
|
239
|
+
pi.on("context_with_system", (event, ctx) => {
|
|
240
|
+
const declared = new Set(getCurrentTools(event.messages).map((tool) => tool.name));
|
|
241
|
+
if (required.every((name) => declared.has(name)))
|
|
242
|
+
return undefined;
|
|
243
|
+
const active = new Set(pi.getActiveTools());
|
|
244
|
+
// Only an active tool must be declared: an extension may leave a registered tool inactive on
|
|
245
|
+
// purpose (pi-web-access's `web_enable`), and one that never registered is agent_start's case.
|
|
246
|
+
const undeclared = required.filter((name) => active.has(name) && !declared.has(name));
|
|
247
|
+
if (undeclared.length === 0)
|
|
248
|
+
return undefined;
|
|
249
|
+
const registered = new Set(pi.getAllTools().map((tool) => tool.name));
|
|
250
|
+
// A fork declares its parent's tools on purpose, to reuse the parent's prompt cache.
|
|
251
|
+
const uncallable = config.forkCacheKey ? [] : [...declared].filter((name) => !active.has(name));
|
|
252
|
+
config.toolDiagnostic?.({
|
|
253
|
+
...(config.agent ? { agent: config.agent } : {}),
|
|
254
|
+
required: [...required],
|
|
255
|
+
available: [...registered],
|
|
256
|
+
missing: [],
|
|
257
|
+
undeclared,
|
|
258
|
+
...(uncallable.length > 0 ? { uncallable } : {}),
|
|
259
|
+
});
|
|
260
|
+
ctx.abort();
|
|
261
|
+
return undefined;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
232
264
|
/** Installed after every other extension: a returned prompt freezes out sections added after it. */
|
|
233
265
|
export function registerSubagentPromptBoundary(pi, config) {
|
|
266
|
+
if (config.requiredTools)
|
|
267
|
+
registerDeclaredToolCheck(pi, config, config.requiredTools);
|
|
234
268
|
if (!rewritesChildPrompt(config))
|
|
235
269
|
return;
|
|
236
270
|
// A returned prompt replaces the whole system prompt of every request. A fork must send its
|
|
@@ -4,6 +4,10 @@ export interface ChildToolDiagnostic {
|
|
|
4
4
|
available: string[];
|
|
5
5
|
missing: string[];
|
|
6
6
|
missingMcpDirectTools?: string[];
|
|
7
|
+
/** Registered allowlisted tools an extension left out of the tools sent to the model. */
|
|
8
|
+
undeclared?: string[];
|
|
9
|
+
/** Tools sent to the model that this child cannot call. */
|
|
10
|
+
uncallable?: string[];
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
13
|
* Explain missing child tools. Foreground children run inside the parent
|
|
@@ -6,6 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export function formatChildToolDiagnostic(diagnostic, options = {}) {
|
|
8
8
|
const subject = diagnostic.agent ? `Agent '${diagnostic.agent}'` : "Subagent";
|
|
9
|
+
if (diagnostic.undeclared?.length) {
|
|
10
|
+
const uncallable = diagnostic.uncallable?.length ? ` and added ${diagnostic.uncallable.join(", ")}, which this child cannot call` : "";
|
|
11
|
+
return [
|
|
12
|
+
`${subject} declares tools: ${diagnostic.required.join(", ")}, but an extension loaded in this child replaced the tools sent to the model: it left out ${diagnostic.undeclared.join(", ")}${uncallable}.`,
|
|
13
|
+
"The `tools` field is a strict allowlist. Set `extensions: []` or list only the extensions this child needs, or omit `tools` to use that extension's tool surface.",
|
|
14
|
+
].join("\n");
|
|
15
|
+
}
|
|
9
16
|
if (options.host === "parent") {
|
|
10
17
|
return [
|
|
11
18
|
`${subject} ran as a foreground child, which never loads the parent's ambient extensions, and these child tools were unavailable: ${diagnostic.missing.join(", ")}.`,
|
|
@@ -8,7 +8,7 @@ import { PROJECT_SUBAGENTS_RELATIVE_DIR } from "../../shared/artifacts.js";
|
|
|
8
8
|
import { DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS, activeRunMarkerAgeMs } from "../background/active-run-index.js";
|
|
9
9
|
import { getAgentDir } from "../../shared/utils.js";
|
|
10
10
|
import { isTerminalParallelHandoffChildStatus, readParallelHandoffManifest } from "./parallel-handoff.js";
|
|
11
|
-
import { MACHINE_DIFF_OPTIONS, validateWorktreePatchRepresentsCurrentWorktree } from "./worktree.js";
|
|
11
|
+
import { MACHINE_DIFF_OPTIONS, isWorktreeCleanupTaskDone, validateWorktreePatchRepresentsCurrentWorktree } from "./worktree.js";
|
|
12
12
|
export const WORKTREE_CLEANUP_PLAN_VERSION = 1;
|
|
13
13
|
export const WORKTREE_CLEANUP_PLAN_TTL_MS = 30 * 60 * 1000;
|
|
14
14
|
const MAX_DISCOVERED_HANDOFFS = 256;
|
|
@@ -650,7 +650,7 @@ function buildUnknownGitEntry(input) {
|
|
|
650
650
|
return blockedEntry(entry, "unknown", "unknown", "no matching extension-owned handoff metadata was found");
|
|
651
651
|
}
|
|
652
652
|
function buildMissingMetadataEntry(input) {
|
|
653
|
-
if (input.record.task
|
|
653
|
+
if (isWorktreeCleanupTaskDone(input.record.task))
|
|
654
654
|
return undefined;
|
|
655
655
|
const pathValue = metadataRecordPath(input.record);
|
|
656
656
|
const entry = buildEntryBase({ path: pathValue, branch: input.record.task.branch, source: "metadata", metadata: input.record, targetHead: input.targetHead });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SetupCommandOptions, type SetupCommandResult } from "./worktree-setup-command.ts";
|
|
2
2
|
import { type AuthorityPolicyConfig } from "../../policy/authority.ts";
|
|
3
|
-
import type { ManagedWorktreeProvider, WorktreeNaming, WorktreeProvider } from "../../shared/types.ts";
|
|
3
|
+
import type { ManagedWorktreeProvider, ParallelHandoffCleanupTask, WorktreeNaming, WorktreeProvider } from "../../shared/types.ts";
|
|
4
4
|
export declare const DEFAULT_WORKTREE_PROVIDER: WorktreeProvider;
|
|
5
5
|
export declare const DEFAULT_WORKTREE_BASE_REF = "HEAD";
|
|
6
6
|
export declare const DEFAULT_WORKTREE_BRANCH_PREFIX = "pi-subagents/";
|
|
@@ -59,19 +59,7 @@ export interface WorktreeDiff {
|
|
|
59
59
|
patchPath: string;
|
|
60
60
|
error?: string;
|
|
61
61
|
}
|
|
62
|
-
export
|
|
63
|
-
recordedBaseDir?: string;
|
|
64
|
-
index: number;
|
|
65
|
-
path: string;
|
|
66
|
-
branch: string;
|
|
67
|
-
provider?: ManagedWorktreeProvider;
|
|
68
|
-
naming?: WorktreeNaming;
|
|
69
|
-
worktreeRemoved: boolean;
|
|
70
|
-
branchRemoved: boolean;
|
|
71
|
-
preserved?: boolean;
|
|
72
|
-
reason?: string;
|
|
73
|
-
errors?: string[];
|
|
74
|
-
}
|
|
62
|
+
export type WorktreeCleanupTask = ParallelHandoffCleanupTask;
|
|
75
63
|
export type WorktreeCleanupIntent = {
|
|
76
64
|
kind: "preserve";
|
|
77
65
|
capturedDiffs?: WorktreeDiff[];
|
|
@@ -179,6 +167,8 @@ export declare function shouldDeferWorktreeCwd(requested: WorktreeProvider | und
|
|
|
179
167
|
export declare function resolveExpectedWorktreeAgentCwd(cwd: string, runId: string, index: number, baseDir?: string): string;
|
|
180
168
|
export declare function createWorktrees(cwd: string, runId: string, count: number, options?: CreateWorktreesOptions): Promise<WorktreeSetup>;
|
|
181
169
|
export declare function diffWorktrees(setup: WorktreeSetup, agents: string[], diffsDir: string): WorktreeDiff[];
|
|
170
|
+
/** A branch kept for its commits is a finished cleanup, the same as a removed one. */
|
|
171
|
+
export declare function isWorktreeCleanupTaskDone(task: Pick<WorktreeCleanupTask, "worktreeRemoved" | "branchRemoved" | "keptBranchTip">): boolean;
|
|
182
172
|
export declare function cleanupWorktrees(setup: WorktreeSetup, intent?: WorktreeCleanupIntent): WorktreeCleanupReport;
|
|
183
173
|
export declare function formatWorktreeDiffSummary(diffs: WorktreeDiff[]): string;
|
|
184
174
|
export {};
|
|
@@ -220,8 +220,12 @@ async function probeWorktreeSource(tx, cwd) {
|
|
|
220
220
|
// pi-subagents writes durable runtime state under .pi/subagents/ by default;
|
|
221
221
|
// that state must not make managed isolation unusable for later runs.
|
|
222
222
|
const status = await tx.gitChecked(toplevel, ["status", "--porcelain", "--", `:!${PROJECT_SUBAGENTS_RELATIVE_DIR}`]);
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
const changes = status.split("\n").filter((line) => line.trim().length > 0);
|
|
224
|
+
if (changes.length > 0) {
|
|
225
|
+
const shown = changes.slice(0, 10).map((line) => ` ${line}`);
|
|
226
|
+
if (changes.length > shown.length)
|
|
227
|
+
shown.push(` … and ${changes.length - shown.length} more`);
|
|
228
|
+
throw new Error(`worktree isolation requires a clean git working tree: ${toplevel} has ${changes.length} uncommitted change(s):\n${shown.join("\n")}\nCommit or stash them first.`);
|
|
225
229
|
}
|
|
226
230
|
return toplevel;
|
|
227
231
|
}
|
|
@@ -1014,6 +1018,7 @@ function cleanupSingleWorktree(setup, worktree, intent) {
|
|
|
1014
1018
|
const errors = [];
|
|
1015
1019
|
let worktreeRemoved = false;
|
|
1016
1020
|
let branchRemoved = false;
|
|
1021
|
+
let keptBranchTip;
|
|
1017
1022
|
if (intent.kind === "preserve" && intent.cleanupBlocker) {
|
|
1018
1023
|
return {
|
|
1019
1024
|
index: worktree.index,
|
|
@@ -1124,12 +1129,32 @@ function cleanupSingleWorktree(setup, worktree, intent) {
|
|
|
1124
1129
|
errors.push(`worktree removal failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1125
1130
|
}
|
|
1126
1131
|
if (worktreeRemoved) {
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1132
|
+
let deleteBranch = true;
|
|
1133
|
+
if (intent.kind === "preserve") {
|
|
1134
|
+
// The handoff patch keeps the child's content but not its commits, so a branch holding the only copy of them stays.
|
|
1135
|
+
try {
|
|
1136
|
+
const tip = runGitChecked(setup.cwd, ["rev-parse", "--verify", `refs/heads/${worktree.branch}^{commit}`]).trim();
|
|
1137
|
+
if (tip !== setup.baseCommit) {
|
|
1138
|
+
const containing = runGitChecked(setup.cwd, ["for-each-ref", "--contains", tip, "--format=%(refname)", "refs/heads", "refs/remotes", "refs/tags"]);
|
|
1139
|
+
if (!containing.split("\n").some((ref) => ref && ref !== `refs/heads/${worktree.branch}`)) {
|
|
1140
|
+
keptBranchTip = tip;
|
|
1141
|
+
deleteBranch = false;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
catch (error) {
|
|
1146
|
+
deleteBranch = false;
|
|
1147
|
+
errors.push(`branch check failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1148
|
+
}
|
|
1130
1149
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1150
|
+
if (deleteBranch) {
|
|
1151
|
+
try {
|
|
1152
|
+
runGitChecked(setup.cwd, ["branch", "-D", worktree.branch]);
|
|
1153
|
+
branchRemoved = true;
|
|
1154
|
+
}
|
|
1155
|
+
catch (error) {
|
|
1156
|
+
errors.push(`branch removal failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1157
|
+
}
|
|
1133
1158
|
}
|
|
1134
1159
|
}
|
|
1135
1160
|
return {
|
|
@@ -1141,6 +1166,7 @@ function cleanupSingleWorktree(setup, worktree, intent) {
|
|
|
1141
1166
|
...(worktree.recordedBaseDir ? { recordedBaseDir: worktree.recordedBaseDir } : {}),
|
|
1142
1167
|
worktreeRemoved,
|
|
1143
1168
|
branchRemoved,
|
|
1169
|
+
...(keptBranchTip ? { keptBranchTip } : {}),
|
|
1144
1170
|
...(errors.length ? { errors } : {}),
|
|
1145
1171
|
};
|
|
1146
1172
|
}
|
|
@@ -1324,6 +1350,10 @@ export function diffWorktrees(setup, agents, diffsDir) {
|
|
|
1324
1350
|
setup.capturedDiffs = diffs;
|
|
1325
1351
|
return diffs;
|
|
1326
1352
|
}
|
|
1353
|
+
/** A branch kept for its commits is a finished cleanup, the same as a removed one. */
|
|
1354
|
+
export function isWorktreeCleanupTaskDone(task) {
|
|
1355
|
+
return task.worktreeRemoved && (task.branchRemoved || task.keptBranchTip !== undefined);
|
|
1356
|
+
}
|
|
1327
1357
|
export function cleanupWorktrees(setup, intent = { kind: "preserve", ...(setup.capturedDiffs ? { capturedDiffs: setup.capturedDiffs } : {}) }) {
|
|
1328
1358
|
assertWorktreeMutationAllowed();
|
|
1329
1359
|
const tasks = [];
|
|
@@ -1340,7 +1370,7 @@ export function cleanupWorktrees(setup, intent = { kind: "preserve", ...(setup.c
|
|
|
1340
1370
|
catch (error) {
|
|
1341
1371
|
errors.push(`worktree prune failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1342
1372
|
}
|
|
1343
|
-
const state = tasks.every(
|
|
1373
|
+
const state = tasks.every(isWorktreeCleanupTaskDone) && pruned ? "complete" : "partial";
|
|
1344
1374
|
return {
|
|
1345
1375
|
state,
|
|
1346
1376
|
tasks,
|
package/src/shared/types.d.ts
CHANGED
|
@@ -178,6 +178,11 @@ export interface WorkflowChildSummary {
|
|
|
178
178
|
agent?: string;
|
|
179
179
|
/** Human-readable display name for the child session, when derived at launch. */
|
|
180
180
|
sessionName?: string;
|
|
181
|
+
/**
|
|
182
|
+
* The child's session file, once its launch resolved one. The file may not exist until the
|
|
183
|
+
* child writes its first entry; a host can follow it to show the child's transcript live.
|
|
184
|
+
*/
|
|
185
|
+
sessionFile?: string;
|
|
181
186
|
model?: string;
|
|
182
187
|
thinking?: string;
|
|
183
188
|
/** Present only while a synchronous foreground child is running. */
|
|
@@ -430,6 +435,8 @@ export interface ParallelHandoffCleanupTask {
|
|
|
430
435
|
naming?: WorktreeNaming;
|
|
431
436
|
worktreeRemoved: boolean;
|
|
432
437
|
branchRemoved: boolean;
|
|
438
|
+
/** Tip of a branch cleanup kept because no other branch, remote branch, or tag holds its commits. */
|
|
439
|
+
keptBranchTip?: string;
|
|
433
440
|
preserved?: boolean;
|
|
434
441
|
reason?: string;
|
|
435
442
|
errors?: string[];
|
|
@@ -496,6 +503,10 @@ export interface ParallelHandoffReference {
|
|
|
496
503
|
childCount: number;
|
|
497
504
|
changedPatches: number;
|
|
498
505
|
cleanupState: "complete" | "partial";
|
|
506
|
+
keptBranches?: Array<{
|
|
507
|
+
branch: string;
|
|
508
|
+
tip: string;
|
|
509
|
+
}>;
|
|
499
510
|
cleanupEligibility?: CleanupEligibility;
|
|
500
511
|
}
|
|
501
512
|
export interface AgentContract {
|
|
@@ -889,6 +900,11 @@ export interface AgentProgress {
|
|
|
889
900
|
agent: string;
|
|
890
901
|
/** Human-readable display name for the child's session, when derived at launch. */
|
|
891
902
|
sessionName?: string;
|
|
903
|
+
/**
|
|
904
|
+
* The child's session file, from launch, when it has one. The file may not exist until the
|
|
905
|
+
* child writes its first entry; a host can follow it to show the child's transcript live.
|
|
906
|
+
*/
|
|
907
|
+
sessionFile?: string;
|
|
892
908
|
status: "pending" | "running" | "completed" | "failed" | "detached";
|
|
893
909
|
progressText?: string;
|
|
894
910
|
progressUpdatedAt?: number;
|
|
@@ -1720,8 +1736,16 @@ export interface RexSshMachineReference {
|
|
|
1720
1736
|
cwd: string;
|
|
1721
1737
|
}
|
|
1722
1738
|
export type RexMachineReference = RexLocalMachineReference | RexSshMachineReference;
|
|
1723
|
-
/**
|
|
1724
|
-
export
|
|
1739
|
+
/** `machine: "local"` inside a Herdr pane: a tab in the parent's own Herdr session on this machine, reached over its local socket. `socket` and `session` are recorded in the parent at resolution time; `cwd` is the real local launch directory. */
|
|
1740
|
+
export interface HerdrLocalMachineReference {
|
|
1741
|
+
provider: "herdr";
|
|
1742
|
+
id: "local";
|
|
1743
|
+
socket: string;
|
|
1744
|
+
session?: string;
|
|
1745
|
+
cwd: string;
|
|
1746
|
+
}
|
|
1747
|
+
/** Where a placed native Pi child runs. A reference without `target` is on this machine. */
|
|
1748
|
+
export type PlacementMachineReference = HerdrMachineReference | HerdrLocalMachineReference | RexMachineReference;
|
|
1725
1749
|
export interface ExternalCliMachineStatus extends HerdrMachineReference {
|
|
1726
1750
|
remoteGit?: HerdrRemoteGitStatus;
|
|
1727
1751
|
}
|
package/src/shared/utils.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare function getProjectConfigDir(projectRoot: string): string;
|
|
|
11
11
|
export declare function getAgentDir(): string;
|
|
12
12
|
export declare function pruneStatusCacheForAsyncRoot(asyncDirRoot: string, runIds: Iterable<string>): number;
|
|
13
13
|
export declare function resolveChildCwd(baseCwd: string, childCwd: string | undefined): string;
|
|
14
|
+
/** A `readStatus(asyncDir)` error caused by permissions on that run's own status file, which says nothing about whether its runner is alive. */
|
|
15
|
+
export declare function isStatusAccessError(error: unknown, asyncDir: string): boolean;
|
|
14
16
|
export declare function readStatus(asyncDir: string): AsyncStatus | null;
|
|
15
17
|
export declare function getLastActivity(outputFile: string | undefined): string;
|
|
16
18
|
export declare function findLatestSessionFile(sessionDir: string): string | null;
|