pi-subagents 0.84.0 → 0.86.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 +83 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-JG4QKI5M.js → chunk-2IYBCYFU.js} +214 -97
- package/bundle/{chunk-V2BZYLEP.js → chunk-374MZFF4.js} +7 -2
- package/bundle/{chunk-4E7BKDTX.js → chunk-3RKFH2UZ.js} +11 -156
- package/bundle/{chunk-F4ASL6OV.js → chunk-5H4BICQZ.js} +1 -1
- package/bundle/{chunk-PALJGGYC.js → chunk-6VD7BGIC.js} +6 -3
- package/bundle/{chunk-C5P5CHYK.js → chunk-77ASNIEM.js} +1 -1
- package/bundle/{chunk-XDQORLZ5.js → chunk-7ADDXUGF.js} +15 -6
- package/bundle/{chunk-PV63UFUR.js → chunk-7QA7ZA46.js} +183 -28
- package/bundle/{chunk-NKQ6JNAS.js → chunk-7ZUFN6ME.js} +2 -1
- package/bundle/{chunk-SSG7IEP5.js → chunk-A637IMAO.js} +2 -2
- package/bundle/{chunk-L3WFKBEI.js → chunk-BGXEAYUM.js} +247 -153
- package/bundle/{chunk-J5YL7LYR.js → chunk-BU6PFPVX.js} +59 -27
- package/bundle/{chunk-DZDETGRJ.js → chunk-BWC2LVII.js} +259 -216
- package/bundle/{chunk-CGN2TVE7.js → chunk-GJGTMLPE.js} +322 -18
- package/bundle/{chunk-D3JAFGMO.js → chunk-GRJHIXYF.js} +1 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-LFDBD4PW.js → chunk-LGINOOY5.js} +2 -2
- package/bundle/{chunk-G2Z6ZH26.js → chunk-NAFLUJ26.js} +1 -1
- package/bundle/{chunk-235AWJUQ.js → chunk-O3YH7XIY.js} +324 -111
- package/bundle/{chunk-2DHZTCOL.js → chunk-PYOAIN3V.js} +2 -2
- package/bundle/{chunk-LNRJCP2Y.js → chunk-QGO6HXHG.js} +417 -242
- package/bundle/{chunk-VQVVHSY6.js → chunk-QM3JGE4W.js} +22 -11
- package/bundle/{chunk-2S4K53MV.js → chunk-S2Q75LP3.js} +1 -1
- package/bundle/{chunk-NENDSQUY.js → chunk-UR7OW5S7.js} +9 -6
- package/bundle/{chunk-AKOIVLA5.js → chunk-WN2E5XHN.js} +135 -77
- package/bundle/{chunk-2D52JFLF.js → chunk-YK3QYNLE.js} +41 -117
- package/bundle/{chunk-7BWGNDNK.js → chunk-ZJJCPV3L.js} +190 -1177
- package/bundle/chunk-ZPY5QZCS.js +1067 -0
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +23 -2
- package/docs/configuration.md +4 -4
- package/docs/extension-api.md +16 -1
- package/docs/tool-reference.md +2 -0
- package/docs/workflows.md +30 -2
- package/package.json +1 -1
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +8 -3
- package/src/extension/schemas.js +5 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +35 -12
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +5 -9
- package/src/runs/background/async-execution.js +62 -27
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +112 -39
- package/src/runs/background/async-retention.js +6 -1
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +0 -1
- package/src/runs/background/run-child-session.js +1 -1
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +15 -12
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +3 -2
- package/src/runs/foreground/subagent-executor.js +107 -26
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +1 -1
- package/src/runs/shared/child-session.js +21 -2
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/types.d.ts +85 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +161 -66
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +241 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
1
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import * as os from "node:os";
|
|
5
5
|
import * as path from "node:path";
|
|
6
|
+
import { promisify } from "node:util";
|
|
6
7
|
const MAX_TRACKED_PATHS = 500;
|
|
7
8
|
const MAX_HASH_BYTES = 1024 * 1024;
|
|
8
9
|
const MAX_TIMEOUT_FILES = 20;
|
|
@@ -13,6 +14,32 @@ function gitArguments(args) {
|
|
|
13
14
|
function gitOutput(cwd, args, maxBuffer = MAX_HASH_BYTES) {
|
|
14
15
|
return execFileSync("git", gitArguments(args), { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer, windowsHide: true });
|
|
15
16
|
}
|
|
17
|
+
const execFileAsync = promisify(execFile);
|
|
18
|
+
/** The collection path runs while sibling children settle, so git runs off the event loop. */
|
|
19
|
+
async function gitOutputAsync(cwd, args) {
|
|
20
|
+
return (await execFileAsync("git", gitArguments(args), { cwd, encoding: "utf-8", maxBuffer: MAX_HASH_BYTES, windowsHide: true })).stdout;
|
|
21
|
+
}
|
|
22
|
+
/** Yields to the event loop every 2 MiB so hashing a large diff does not stall other work. */
|
|
23
|
+
async function hashFileAsync(diffPath) {
|
|
24
|
+
const hash = createHash("sha256");
|
|
25
|
+
const fd = fs.openSync(diffPath, "r");
|
|
26
|
+
try {
|
|
27
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
28
|
+
let chunks = 0;
|
|
29
|
+
for (;;) {
|
|
30
|
+
const bytesRead = fs.readSync(fd, buffer, 0, buffer.length, null);
|
|
31
|
+
if (bytesRead === 0)
|
|
32
|
+
break;
|
|
33
|
+
hash.update(bytesRead === buffer.length ? buffer : buffer.subarray(0, bytesRead));
|
|
34
|
+
if (++chunks % 32 === 0)
|
|
35
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
fs.closeSync(fd);
|
|
40
|
+
}
|
|
41
|
+
return hash.digest("hex");
|
|
42
|
+
}
|
|
16
43
|
function splitNul(output) {
|
|
17
44
|
return output.split("\0").filter((part) => part.length > 0);
|
|
18
45
|
}
|
|
@@ -41,8 +68,9 @@ function hashLargeDiff(cwd, relativePath) {
|
|
|
41
68
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
42
69
|
}
|
|
43
70
|
}
|
|
44
|
-
|
|
45
|
-
|
|
71
|
+
const CHANGED_FILES_ARGS = ["diff", "--no-ext-diff", "--name-only", "-z", "HEAD", "--"];
|
|
72
|
+
function changedTrackedFiles(nameOnlyOutput) {
|
|
73
|
+
const paths = splitNul(nameOnlyOutput);
|
|
46
74
|
return { paths: paths.slice(0, MAX_TRACKED_PATHS), truncated: paths.length > MAX_TRACKED_PATHS };
|
|
47
75
|
}
|
|
48
76
|
function fingerprintPath(cwd, relativePath) {
|
|
@@ -61,7 +89,7 @@ function sameFingerprint(left, right) {
|
|
|
61
89
|
}
|
|
62
90
|
export function snapshotTrackedMutations(cwd) {
|
|
63
91
|
try {
|
|
64
|
-
const changed =
|
|
92
|
+
const changed = changedTrackedFiles(gitOutput(cwd, CHANGED_FILES_ARGS));
|
|
65
93
|
const fingerprints = {};
|
|
66
94
|
for (const file of changed.paths)
|
|
67
95
|
fingerprints[file] = fingerprintPath(cwd, file);
|
|
@@ -71,12 +99,29 @@ export function snapshotTrackedMutations(cwd) {
|
|
|
71
99
|
return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: [], fingerprints: {}, unavailable: error instanceof Error ? error.message : String(error) };
|
|
72
100
|
}
|
|
73
101
|
}
|
|
74
|
-
|
|
102
|
+
async function fingerprintPathAsync(cwd, relativePath) {
|
|
103
|
+
try {
|
|
104
|
+
const diff = await gitOutputAsync(cwd, ["diff", "--no-ext-diff", "--binary", "HEAD", "--", relativePath]);
|
|
105
|
+
return { kind: "diff", digest: createHash("sha256").update(diff).digest("hex") };
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-mutation-evidence-"));
|
|
109
|
+
try {
|
|
110
|
+
const diffPath = path.join(tempDir, "diff.bin");
|
|
111
|
+
await gitOutputAsync(cwd, ["diff", "--no-ext-diff", "--binary", `--output=${diffPath}`, "HEAD", "--", relativePath]);
|
|
112
|
+
return { kind: "diff", digest: await hashFileAsync(diffPath) };
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export async function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
|
|
75
120
|
if (snapshot.unavailable) {
|
|
76
121
|
return { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: false, unavailable: snapshot.unavailable };
|
|
77
122
|
}
|
|
78
123
|
try {
|
|
79
|
-
const current =
|
|
124
|
+
const current = changedTrackedFiles(await gitOutputAsync(cwd, CHANGED_FILES_ARGS));
|
|
80
125
|
const startDirty = new Set(snapshot.dirtyFiles);
|
|
81
126
|
const candidates = new Set([...snapshot.dirtyFiles, ...current.paths]);
|
|
82
127
|
const changedFiles = [];
|
|
@@ -86,7 +131,7 @@ export function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
|
|
|
86
131
|
changedFiles.push(file);
|
|
87
132
|
continue;
|
|
88
133
|
}
|
|
89
|
-
if (!sameFingerprint(snapshot.fingerprints[file],
|
|
134
|
+
if (!sameFingerprint(snapshot.fingerprints[file], await fingerprintPathAsync(cwd, file)))
|
|
90
135
|
changedFiles.push(file);
|
|
91
136
|
}
|
|
92
137
|
changedFiles.sort();
|
|
@@ -87,6 +87,7 @@ export interface NestedRunResolutionScope {
|
|
|
87
87
|
parentStepIndex?: number;
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
+
export declare function collectNestedRuns(children: NestedRunSummary[] | undefined, output?: NestedRunSummary[]): NestedRunSummary[];
|
|
90
91
|
export declare function findNestedRunMatchesById(id: string, options?: {
|
|
91
92
|
prefix?: boolean;
|
|
92
93
|
scope?: NestedRunResolutionScope;
|
|
@@ -564,7 +564,7 @@ export function retainNestedLookupRoute(state, route, sessionId) {
|
|
|
564
564
|
}
|
|
565
565
|
state.retainedNestedLookupRoutes.routes.set(route.rootRunId, route);
|
|
566
566
|
}
|
|
567
|
-
function collectNestedRuns(children, output = []) {
|
|
567
|
+
export function collectNestedRuns(children, output = []) {
|
|
568
568
|
for (const child of children ?? []) {
|
|
569
569
|
output.push(child);
|
|
570
570
|
collectNestedRuns(child.children, output);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
|
|
3
|
+
import { DEFAULT_WAIT_TOOL_NAME, waitToolName } from "../../shared/wait-tool-name.js";
|
|
4
|
+
const COORDINATION_TOOLS = new Set(["contact_supervisor", "intercom", "structured_output"]);
|
|
5
|
+
const isInternalTool = (tool) => COORDINATION_TOOLS.has(tool) || tool === waitToolName();
|
|
4
6
|
const DECISIONS = new Set(["allow", "ask", "deny"]);
|
|
5
7
|
const MAX_POLICY_BYTES = 16 * 1024;
|
|
6
8
|
const MAX_PREVIEW_BYTES = 2048;
|
|
@@ -20,7 +22,7 @@ export function validatePermissionRules(value, label) {
|
|
|
20
22
|
throw new Error(`${label} contains an empty tool name.`);
|
|
21
23
|
if (tool === "bash")
|
|
22
24
|
throw new Error(`${label}.bash is unsupported; pi-subagents leaves bash policy to pi-guard.`);
|
|
23
|
-
if (
|
|
25
|
+
if (isInternalTool(tool) || tool === DEFAULT_WAIT_TOOL_NAME)
|
|
24
26
|
throw new Error(`${label}.${tool} is reserved for child coordination and cannot be gated.`);
|
|
25
27
|
if (!DECISIONS.has(decision))
|
|
26
28
|
throw new Error(`${label}.${tool} must be allow, ask, or deny.`);
|
|
@@ -47,7 +49,7 @@ export function resolvePermissionRules(globalConfig, agentRules) {
|
|
|
47
49
|
return Object.keys(merged).length ? merged : undefined;
|
|
48
50
|
}
|
|
49
51
|
export function permissionDecision(rules, toolName) {
|
|
50
|
-
if (toolName === "bash" ||
|
|
52
|
+
if (toolName === "bash" || isInternalTool(toolName))
|
|
51
53
|
return "allow";
|
|
52
54
|
return rules?.[toolName] ?? "allow";
|
|
53
55
|
}
|
|
@@ -39,6 +39,10 @@ export interface PlacementStartOptions {
|
|
|
39
39
|
wait(ms: number): Promise<void>;
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
+
/** `stopped` ends a pending prompt retry once the run is aborted or disposed, so a refused prompt is never sent after that. */
|
|
43
|
+
export interface PlacementPromptOptions extends PlacementStartOptions {
|
|
44
|
+
stopped?: () => boolean;
|
|
45
|
+
}
|
|
42
46
|
/** What to start in a new pane; the pane is created in the machine's cwd with this environment. */
|
|
43
47
|
export interface PlacementLaunchRequest {
|
|
44
48
|
kind: PlacementAgentKind;
|
|
@@ -81,7 +85,7 @@ export interface PlacementPaneHost<C extends PlacementSockets = PlacementSockets
|
|
|
81
85
|
owned: PlacementOwnedPane;
|
|
82
86
|
terminalId: string;
|
|
83
87
|
}>;
|
|
84
|
-
prompt(connection: C, identity: HerdrRunIdentity, text: string): Promise<void>;
|
|
88
|
+
prompt(connection: C, identity: HerdrRunIdentity, text: string, options?: PlacementPromptOptions): Promise<void>;
|
|
85
89
|
subscribe(connection: C, paneId: string, listener: (event: unknown) => void, onDisconnect: (error: Error) => void): Promise<() => void>;
|
|
86
90
|
paneEvent(event: unknown, fallback: PlacementRunState): {
|
|
87
91
|
terminalId: unknown;
|
|
@@ -51,7 +51,6 @@ export declare const rexPaneHost: {
|
|
|
51
51
|
reconcile: typeof reconcileRexPlacedRun;
|
|
52
52
|
closeOwnedPane: typeof closeOwnedRexPane;
|
|
53
53
|
};
|
|
54
|
-
/** The placed-run owner bound to Rex and the pane machine's access. */
|
|
55
54
|
export declare class RexPlacedRunOwner extends PlacedRunOwner<RexConnection, RexMachineReference> {
|
|
56
55
|
private constructor();
|
|
57
56
|
/** A Rex SSH owner's machine carries the resolved remote cwd, and its host reconnects only to the session recorded here. */
|
|
@@ -40,7 +40,6 @@ function requireRexSuccess(result, what) {
|
|
|
40
40
|
if (result.status !== 0)
|
|
41
41
|
throw new Error(`Rex ${what} exited with code ${result.status}: ${result.stderr.trim().slice(0, 512)}`);
|
|
42
42
|
}
|
|
43
|
-
/** Parses rex's JSON output against its schema; undefined when the shape does not match. */
|
|
44
43
|
function parseRexJson(text, validator, what) {
|
|
45
44
|
let value;
|
|
46
45
|
try {
|
|
@@ -284,7 +283,6 @@ function removeRexRuntimeDir(access, runtimeDir) {
|
|
|
284
283
|
throw error;
|
|
285
284
|
}
|
|
286
285
|
}
|
|
287
|
-
/** The placed-run owner bound to Rex and the pane machine's access. */
|
|
288
286
|
export class RexPlacedRunOwner extends PlacedRunOwner {
|
|
289
287
|
constructor(machine, runId, runtimeDir, connection, access, host) { super(machine, runId, runtimeDir, connection, host, access, () => removeRexRuntimeDir(access, runtimeDir)); }
|
|
290
288
|
/** A Rex SSH owner's machine carries the resolved remote cwd, and its host reconnects only to the session recorded here. */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parent-owned folder for a run's relaunch records: `async-subagent-launches/<id>/`, beside the
|
|
3
|
+
* runs root that holds the run folder. A runner launcher that isolates a run binds only the run's own
|
|
4
|
+
* folder, so the run cannot rewrite what a later resume starts or under which identity.
|
|
5
|
+
* Callers pass a runs root they know (never one derived from a requested path), because a run can
|
|
6
|
+
* build a runs-shaped tree inside its own folder.
|
|
7
|
+
* A nested run's records stay in its root run's folder (`nested-subagent-runs/<root>/.launches/<id>/`):
|
|
8
|
+
* the child runner that started it writes them, so they add no isolation, and a folder shared by every
|
|
9
|
+
* root run would only mix their records.
|
|
10
|
+
*/
|
|
11
|
+
export declare function runLaunchDir(runsRoot: string, runId: string): string;
|
|
12
|
+
export declare function recoveryDescriptorPath(runsRoot: string, runId: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* The parent-owned folder for a run's relaunch records: `async-subagent-launches/<id>/`, beside the
|
|
4
|
+
* runs root that holds the run folder. A runner launcher that isolates a run binds only the run's own
|
|
5
|
+
* folder, so the run cannot rewrite what a later resume starts or under which identity.
|
|
6
|
+
* Callers pass a runs root they know (never one derived from a requested path), because a run can
|
|
7
|
+
* build a runs-shaped tree inside its own folder.
|
|
8
|
+
* A nested run's records stay in its root run's folder (`nested-subagent-runs/<root>/.launches/<id>/`):
|
|
9
|
+
* the child runner that started it writes them, so they add no isolation, and a folder shared by every
|
|
10
|
+
* root run would only mix their records.
|
|
11
|
+
*/
|
|
12
|
+
export function runLaunchDir(runsRoot, runId) {
|
|
13
|
+
if (!runId || runId !== path.basename(runId) || runId === "." || runId === "..")
|
|
14
|
+
throw new Error(`Invalid run id for a launch folder: '${runId}'.`);
|
|
15
|
+
if (path.basename(path.dirname(runsRoot)) === "nested-subagent-runs")
|
|
16
|
+
return path.join(runsRoot, ".launches", runId);
|
|
17
|
+
return path.join(path.dirname(runsRoot), "async-subagent-launches", runId);
|
|
18
|
+
}
|
|
19
|
+
export function recoveryDescriptorPath(runsRoot, runId) {
|
|
20
|
+
return path.join(runLaunchDir(runsRoot, runId), "recovery-descriptor.json");
|
|
21
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentConfig } from "../../agents/agents.ts";
|
|
2
|
-
import type { RunnerLauncher } from "../../shared/types.ts";
|
|
2
|
+
import type { RequiredRunnerLauncher, RunnerLauncher } from "../../shared/types.ts";
|
|
3
|
+
export declare const REQUIRE_LAUNCHER_SHAPE_ERROR = "requireLauncher is supported only on a top-level single-agent call (agent + task); it cannot be combined with tasks, chain, workflow, an action, resume, or a workflow child.";
|
|
3
4
|
/** Own-property lookup, so an inherited object key can never select a command. */
|
|
4
5
|
export declare function lookupRunnerLauncher(runnerLaunchers: Record<string, string[]> | undefined, name: string): RunnerLauncher | undefined;
|
|
5
6
|
/** A launcher wraps the local Pi background runner, so it cannot combine with machine placement or an external runner. */
|
|
@@ -9,3 +10,13 @@ export declare function resolveAgentRunnerLauncher(agent: Pick<AgentConfig, "nam
|
|
|
9
10
|
launcher?: RunnerLauncher;
|
|
10
11
|
error?: string;
|
|
11
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Checks a call's launcher requirement against the agent and launcher a launch resolved. On a match it returns the
|
|
15
|
+
* digest it checked, so the launch can record that digest instead of hashing the agent file again.
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkRequiredRunnerLauncher(agent: AgentConfig, launcherName: string | undefined, required: RequiredRunnerLauncher): {
|
|
18
|
+
definitionDigest: string;
|
|
19
|
+
error?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { agentDefinitionDigest } from "../../shared/launch-contract.js";
|
|
2
|
+
export const REQUIRE_LAUNCHER_SHAPE_ERROR = "requireLauncher is supported only on a top-level single-agent call (agent + task); it cannot be combined with tasks, chain, workflow, an action, resume, or a workflow child.";
|
|
1
3
|
/** Own-property lookup, so an inherited object key can never select a command. */
|
|
2
4
|
export function lookupRunnerLauncher(runnerLaunchers, name) {
|
|
3
5
|
const argv = runnerLaunchers && Object.hasOwn(runnerLaunchers, name) ? runnerLaunchers[name] : undefined;
|
|
@@ -22,3 +24,17 @@ export function resolveAgentRunnerLauncher(agent, runnerLaunchers, machine) {
|
|
|
22
24
|
const launcher = lookupRunnerLauncher(runnerLaunchers, agent.launcher);
|
|
23
25
|
return launcher ? { launcher } : { error: `Agent '${agent.name}' uses launcher '${agent.launcher}', which is not defined in runnerLaunchers in the user subagent config.` };
|
|
24
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks a call's launcher requirement against the agent and launcher a launch resolved. On a match it returns the
|
|
29
|
+
* digest it checked, so the launch can record that digest instead of hashing the agent file again.
|
|
30
|
+
*/
|
|
31
|
+
export function checkRequiredRunnerLauncher(agent, launcherName, required) {
|
|
32
|
+
if (launcherName === undefined)
|
|
33
|
+
return { error: `Agent '${agent.name}' has no launcher, but the call requires launcher '${required.name}'.` };
|
|
34
|
+
if (launcherName !== required.name)
|
|
35
|
+
return { error: `Agent '${agent.name}' uses launcher '${launcherName}', but the call requires launcher '${required.name}'.` };
|
|
36
|
+
const definitionDigest = agentDefinitionDigest(agent);
|
|
37
|
+
if (definitionDigest !== required.definitionDigest)
|
|
38
|
+
return { error: `Agent '${agent.name}' definition digest is ${definitionDigest}, but the call requires ${required.definitionDigest}; the agent definition changed after it was checked.` };
|
|
39
|
+
return { definitionDigest };
|
|
40
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Message } from "@earendil-works/pi-ai";
|
|
2
|
-
import type { OutputMode, SavedOutputReference } from "../../shared/types.ts";
|
|
2
|
+
import type { OutputMode, PlacementMachineReference, SavedOutputReference } from "../../shared/types.ts";
|
|
3
3
|
export interface SingleOutputSnapshot {
|
|
4
4
|
exists: boolean;
|
|
5
5
|
mtimeMs?: number;
|
|
@@ -27,7 +27,8 @@ export declare function outputPathMappingFromTask(task: string, savedPath: strin
|
|
|
27
27
|
requestedPath: string;
|
|
28
28
|
savedPath: string;
|
|
29
29
|
} | undefined;
|
|
30
|
-
|
|
30
|
+
/** A child on another machine cannot write the parent-side path; its final reply is saved there instead. */
|
|
31
|
+
export declare function injectSingleOutputInstruction(task: string, outputPath: string | undefined, capabilities?: OutputInstructionCapabilities, machine?: PlacementMachineReference): string;
|
|
31
32
|
export declare function formatSavedOutputReference(savedPath: string, fullOutput: string): SavedOutputReference;
|
|
32
33
|
/**
|
|
33
34
|
* Keeps at most INLINE_OUTPUT_HEAD_CHARS of a child's output inline and points to the file holding all of it.
|
|
@@ -78,7 +79,6 @@ export declare function finalizeSingleOutput(params: {
|
|
|
78
79
|
saveError?: string;
|
|
79
80
|
};
|
|
80
81
|
/**
|
|
81
|
-
* Determines whether an output resolution error represents an unrecoverable settlement failure.
|
|
82
82
|
* Returns true for fatal claim-path mismatches in any mode, or when required file-only output
|
|
83
83
|
* fails to persist without a savedPath. Inline and optional outputs remain nonfatal warnings.
|
|
84
84
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
+
import { isRexLocalMachine } from "./rex-machine.js";
|
|
3
4
|
const READ_ONLY_OUTPUT_TOOLS = new Set([
|
|
4
5
|
"read", "grep", "find", "ls", "web_search", "fetch_content", "get_search_content",
|
|
5
6
|
"source_check", "intercom", "contact_supervisor", "structured_output", "watchdog_diff",
|
|
@@ -98,10 +99,12 @@ export function outputPathMappingFromTask(task, savedPath) {
|
|
|
98
99
|
return undefined;
|
|
99
100
|
return { requestedPath, savedPath };
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
+
/** A child on another machine cannot write the parent-side path; its final reply is saved there instead. */
|
|
103
|
+
export function injectSingleOutputInstruction(task, outputPath, capabilities, machine) {
|
|
102
104
|
if (!outputPath)
|
|
103
105
|
return task;
|
|
104
|
-
const
|
|
106
|
+
const remote = machine !== undefined && !isRexLocalMachine(machine);
|
|
107
|
+
const delivery = !remote && (!capabilities || hasOutputWriteCapability(capabilities.tools, capabilities.mcpDirectTools))
|
|
105
108
|
? `Write your findings to exactly this path: ${outputPath}`
|
|
106
109
|
: [
|
|
107
110
|
"Return the complete artifact in your final response.",
|
|
@@ -339,7 +342,6 @@ export function finalizeSingleOutput(params) {
|
|
|
339
342
|
return { displayOutput };
|
|
340
343
|
}
|
|
341
344
|
/**
|
|
342
|
-
* Determines whether an output resolution error represents an unrecoverable settlement failure.
|
|
343
345
|
* Returns true for fatal claim-path mismatches in any mode, or when required file-only output
|
|
344
346
|
* fails to persist without a savedPath. Inline and optional outputs remain nonfatal warnings.
|
|
345
347
|
*/
|
|
@@ -38,6 +38,8 @@ interface JsonSchemaValidationError {
|
|
|
38
38
|
}
|
|
39
39
|
type CompileJsonSchema = (schema: unknown) => CompiledJsonSchema;
|
|
40
40
|
export declare function resolveCompileFromPackageRoot(packageRoot: string): Promise<CompileJsonSchema | undefined>;
|
|
41
|
+
/** Resolves once the validator has loaded or failed; a failure is reported by the structured_output call. */
|
|
42
|
+
export declare function structuredOutputValidatorReady(): Promise<void>;
|
|
41
43
|
export declare function assertJsonSchemaObject(schema: unknown, label?: string): asserts schema is JsonSchemaObject;
|
|
42
44
|
export declare function createStructuredOutputRuntime(schema: JsonSchemaObject, baseDir?: string, options?: {
|
|
43
45
|
acceptanceReport?: ResolvedAcceptanceReportMode;
|
|
@@ -48,6 +50,12 @@ export declare function validateStructuredOutputValue(schema: JsonSchemaObject,
|
|
|
48
50
|
status: "invalid";
|
|
49
51
|
message: string;
|
|
50
52
|
}>;
|
|
53
|
+
/**
|
|
54
|
+
* The tool's `prepareArguments` hook: checks the raw `value` before Pi converts tool arguments
|
|
55
|
+
* (Pi can turn `"x"` into `["x"]` or `null` into `"null"`), so only a value that already matches
|
|
56
|
+
* the schema is captured. Fails closed when the validator has not loaded.
|
|
57
|
+
*/
|
|
58
|
+
export declare function prepareStructuredOutputArguments(schema: JsonSchemaObject, args: unknown): unknown;
|
|
51
59
|
export declare function readStructuredOutput(runtime: StructuredOutputRuntime): Promise<{
|
|
52
60
|
value?: unknown;
|
|
53
61
|
error?: string;
|
|
@@ -152,6 +152,9 @@ export function createStructuredOutputToolParameters(schema, options = {}) {
|
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
let cachedCompile;
|
|
155
|
+
// prepareArguments is synchronous, so it can only use a compiler that has already loaded.
|
|
156
|
+
let loadedCompile;
|
|
157
|
+
let compileLoadError;
|
|
155
158
|
export async function resolveCompileFromPackageRoot(packageRoot) {
|
|
156
159
|
const requireFromRoot = createRequire(path.join(packageRoot, "package.json"));
|
|
157
160
|
const resolved = requireFromRoot.resolve("typebox/compile");
|
|
@@ -196,13 +199,21 @@ async function importCompile() {
|
|
|
196
199
|
}
|
|
197
200
|
function loadCompile() {
|
|
198
201
|
if (!cachedCompile) {
|
|
199
|
-
cachedCompile = importCompile().
|
|
202
|
+
cachedCompile = importCompile().then((compile) => {
|
|
203
|
+
loadedCompile = compile;
|
|
204
|
+
return compile;
|
|
205
|
+
}, (error) => {
|
|
200
206
|
cachedCompile = undefined;
|
|
207
|
+
compileLoadError = error;
|
|
201
208
|
throw error;
|
|
202
209
|
});
|
|
203
210
|
}
|
|
204
211
|
return cachedCompile;
|
|
205
212
|
}
|
|
213
|
+
/** Resolves once the validator has loaded or failed; a failure is reported by the structured_output call. */
|
|
214
|
+
export function structuredOutputValidatorReady() {
|
|
215
|
+
return loadCompile().then(() => undefined, () => undefined);
|
|
216
|
+
}
|
|
206
217
|
function jsonPointerTarget(root, pointer) {
|
|
207
218
|
if (pointer === "#")
|
|
208
219
|
return root;
|
|
@@ -379,7 +390,24 @@ export function createStructuredOutputRuntime(schema, baseDir, options = {}) {
|
|
|
379
390
|
};
|
|
380
391
|
}
|
|
381
392
|
export async function validateStructuredOutputValue(schema, value) {
|
|
382
|
-
|
|
393
|
+
return validateWithCompile(await loadCompile(), schema, value);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* The tool's `prepareArguments` hook: checks the raw `value` before Pi converts tool arguments
|
|
397
|
+
* (Pi can turn `"x"` into `["x"]` or `null` into `"null"`), so only a value that already matches
|
|
398
|
+
* the schema is captured. Fails closed when the validator has not loaded.
|
|
399
|
+
*/
|
|
400
|
+
export function prepareStructuredOutputArguments(schema, args) {
|
|
401
|
+
if (!args || typeof args !== "object" || !("value" in args))
|
|
402
|
+
return args;
|
|
403
|
+
if (!loadedCompile)
|
|
404
|
+
throw compileLoadError ?? new Error("Structured output validator is still loading; call structured_output again.");
|
|
405
|
+
const validation = validateWithCompile(loadedCompile, schema, args.value);
|
|
406
|
+
if (validation.status === "invalid")
|
|
407
|
+
throw new Error(`Structured output validation failed: ${validation.message}`);
|
|
408
|
+
return args;
|
|
409
|
+
}
|
|
410
|
+
function validateWithCompile(compile, schema, value) {
|
|
383
411
|
let validator;
|
|
384
412
|
try {
|
|
385
413
|
validator = compile(schema);
|
|
@@ -387,9 +415,16 @@ export async function validateStructuredOutputValue(schema, value) {
|
|
|
387
415
|
catch (error) {
|
|
388
416
|
return { status: "invalid", message: `invalid outputSchema: ${error instanceof Error ? error.message : String(error)}` };
|
|
389
417
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
418
|
+
let originalErrors;
|
|
419
|
+
try {
|
|
420
|
+
if (validator.Check(value))
|
|
421
|
+
return { status: "valid" };
|
|
422
|
+
originalErrors = [...validator.Errors(value)];
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
// A recursive $ref compiles but overflows the stack when checked.
|
|
426
|
+
return { status: "invalid", message: `outputSchema cannot be validated (cyclic or too deep): ${error instanceof Error ? error.message : String(error)}` };
|
|
427
|
+
}
|
|
393
428
|
const errors = [];
|
|
394
429
|
const uniqueErrors = new Set();
|
|
395
430
|
const seen = new Set();
|
|
@@ -85,6 +85,5 @@ export declare function stripParentOnlySubagentMessages(messages: unknown[], opt
|
|
|
85
85
|
}): unknown[];
|
|
86
86
|
export declare function formatSteerMessage(request: SteerRequest): string;
|
|
87
87
|
export declare function registerPermissionGate(pi: ExtensionAPI, permissions: ChildPermissions | undefined, childWatchdog: ChildWatchdogConfig | undefined, requestPermission?: (request: WatchdogPermissionRequest) => Promise<WatchdogPermissionResult>): void;
|
|
88
|
-
/** Register every child-side hook the prompt runtime owns for one child session. */
|
|
89
88
|
export default function registerSubagentPromptRuntime(pi: ExtensionAPI, config?: ChildRuntimeConfig, drainObservation?: import("./readonly-drain-observation.ts").ReadonlyDrainObservation): void;
|
|
90
89
|
export {};
|
|
@@ -5,7 +5,7 @@ import { declarationsEqual, getCurrentSystemMessage, getCurrentTools } from "@ea
|
|
|
5
5
|
import { registerNativeSupervisorClient } from "../../intercom/native-supervisor-channel.js";
|
|
6
6
|
import { permissionDecision } from "./permissions.js";
|
|
7
7
|
import { RUNTIME_EXTENSION_ACK_EVENT, isRuntimeAcknowledgedExtensionId } from "./runtime-acknowledged-extensions.js";
|
|
8
|
-
import { createStructuredOutputToolParameters, MISSING_STRUCTURED_ACCEPTANCE_REPORT_ERROR, validateStructuredOutputValue } from "./structured-output.js";
|
|
8
|
+
import { createStructuredOutputToolParameters, MISSING_STRUCTURED_ACCEPTANCE_REPORT_ERROR, prepareStructuredOutputArguments, validateStructuredOutputValue } from "./structured-output.js";
|
|
9
9
|
import { validateAcceptanceReport } from "./acceptance.js";
|
|
10
10
|
import { formatChildToolDiagnostic } from "./tool-availability.js";
|
|
11
11
|
import { shouldBlockToolForBudget, toolBudgetBlockedMessage, toolBudgetSoftNudge } from "./tool-budget.js";
|
|
@@ -20,6 +20,7 @@ import { inheritedNestedRouteOf } from "./nested-events.js";
|
|
|
20
20
|
import { registerWaitTool } from "../background/wait-tool.js";
|
|
21
21
|
import { drainOutstandingWork } from "../background/auto-drain.js";
|
|
22
22
|
import { MODEL_ONLY_TOOL } from "../../shared/extension-context.js";
|
|
23
|
+
import { DEFAULT_WAIT_TOOL_NAME, setWaitToolName } from "../../shared/wait-tool-name.js";
|
|
23
24
|
import { childSupervisorMetadata, evaluateChildToolDiagnostic, } from "./child-runtime-config.js";
|
|
24
25
|
const STRUCTURED_OUTPUT_INSTRUCTIONS = [
|
|
25
26
|
"This subagent step has a strict structured output contract.",
|
|
@@ -593,6 +594,7 @@ function registerStructuredOutputTool(pi, structured) {
|
|
|
593
594
|
label: "Structured Output",
|
|
594
595
|
description: "Submit the required final structured output for this subagent step. This terminates the step.",
|
|
595
596
|
parameters,
|
|
597
|
+
prepareArguments: (args) => prepareStructuredOutputArguments(structured.schema, args),
|
|
596
598
|
async execute(_id, params) {
|
|
597
599
|
const validation = await validateStructuredOutputValue(structured.schema, params.value);
|
|
598
600
|
if (validation.status === "invalid") {
|
|
@@ -617,7 +619,6 @@ function registerStructuredOutputTool(pi, structured) {
|
|
|
617
619
|
},
|
|
618
620
|
});
|
|
619
621
|
}
|
|
620
|
-
/** Register every child-side hook the prompt runtime owns for one child session. */
|
|
621
622
|
export default function registerSubagentPromptRuntime(pi, config, drainObservation) {
|
|
622
623
|
// A path-based load has no ChildRuntimeConfig. This can happen if an
|
|
623
624
|
// ambient-extension discovery path finds the runtime module in addition to
|
|
@@ -655,6 +656,7 @@ export default function registerSubagentPromptRuntime(pi, config, drainObservati
|
|
|
655
656
|
};
|
|
656
657
|
const nestedRootRunId = inheritedNestedRouteOf(config)?.rootRunId;
|
|
657
658
|
// fanout-child assigns config.hasPendingSupervisorRequest after this hook registers, so read it per wait.
|
|
659
|
+
setWaitToolName(config.waitTool.name ?? DEFAULT_WAIT_TOOL_NAME);
|
|
658
660
|
if (typeof pi.registerTool === "function")
|
|
659
661
|
registerWaitTool(pi, waitState, config.waitTool.enabled, undefined, config.waitTool.defaultTimeoutMs, { nestedRootRunId }, () => config.hasPendingSupervisorRequest?.() === true);
|
|
660
662
|
const supervisorMetadata = childSupervisorMetadata(config);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { waitToolName } from "../../shared/wait-tool-name.js";
|
|
1
2
|
export const TOOL_TIMEOUT_ENV = "PI_SUBAGENT_TOOL_TIMEOUT_MS";
|
|
2
3
|
/** Maximum delay a Node.js timer accepts without overflow. */
|
|
3
4
|
const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
@@ -16,7 +17,7 @@ export const TOOL_TIMEOUT_EXEMPT_TOOLS = new Set(["contact_supervisor", "interco
|
|
|
16
17
|
// Backward-compatible export name for existing callers/tests.
|
|
17
18
|
export const TOOL_TIMEOUT_ALLOWLIST = TOOL_TIMEOUT_EXEMPT_TOOLS;
|
|
18
19
|
export function isToolTimeoutExempt(toolName) {
|
|
19
|
-
return toolName !== undefined && TOOL_TIMEOUT_EXEMPT_TOOLS.has(toolName);
|
|
20
|
+
return toolName !== undefined && (TOOL_TIMEOUT_EXEMPT_TOOLS.has(toolName) || toolName === waitToolName());
|
|
20
21
|
}
|
|
21
22
|
export function defaultToolTimeoutMs(toolName) {
|
|
22
23
|
return toolName !== undefined && DEFAULT_FAST_TOOL_TIMEOUT_TOOLS.has(toolName)
|
|
@@ -68,7 +68,6 @@ interface GitWorktreeRecord {
|
|
|
68
68
|
locked?: boolean;
|
|
69
69
|
}
|
|
70
70
|
declare function realpathExisting(candidate: string, nativeRealpath?: (filePath: string) => string, fallbackRealpath?: (filePath: string) => string): string;
|
|
71
|
-
/** Internal test seam; this is not part of the public subagent tool API. */
|
|
72
71
|
export declare const __testables: {
|
|
73
72
|
realpathExisting: typeof realpathExisting;
|
|
74
73
|
};
|
|
@@ -50,7 +50,6 @@ function realpathExisting(candidate, nativeRealpath = fs.realpathSync.native, fa
|
|
|
50
50
|
return fallbackRealpath(candidate);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
/** Internal test seam; this is not part of the public subagent tool API. */
|
|
54
53
|
export const __testables = { realpathExisting };
|
|
55
54
|
function comparablePath(candidate) {
|
|
56
55
|
let current = path.resolve(candidate);
|
|
@@ -151,6 +151,9 @@ export declare class WorktreeSetupError extends Error {
|
|
|
151
151
|
}
|
|
152
152
|
/** Later async finalization owners wrap their synchronous diff/cleanup as ONE turn. */
|
|
153
153
|
export declare function withWorktreeTransaction<T>(action: () => T | Promise<T>): Promise<T>;
|
|
154
|
+
export declare function findListedWorktreeOnBranch(repoCwd: string, branch: string): string | undefined;
|
|
155
|
+
export declare function findListedWorktreeAgentCwd(repoCwd: string, branch: string): string | undefined;
|
|
156
|
+
export declare function isComparablePathInside(parent: string, child: string): boolean;
|
|
154
157
|
/** Validate a captured patch against the worktree index without changing either. */
|
|
155
158
|
export declare function validateWorktreePatch(worktreePath: string, patchPath: string): string | undefined;
|
|
156
159
|
export declare function validateWorktreePatchRepresentsCurrentWorktree(worktreePath: string, baseCommit: string, patchPath: string): string | undefined;
|
|
@@ -136,6 +136,26 @@ function runGitChecked(cwd, args) {
|
|
|
136
136
|
}
|
|
137
137
|
return result.stdout;
|
|
138
138
|
}
|
|
139
|
+
export function findListedWorktreeOnBranch(repoCwd, branch) {
|
|
140
|
+
let current;
|
|
141
|
+
for (const line of runGitChecked(repoCwd, ["worktree", "list", "--porcelain"]).split("\n")) {
|
|
142
|
+
if (line.startsWith("worktree "))
|
|
143
|
+
current = line.slice("worktree ".length);
|
|
144
|
+
else if (line === `branch refs/heads/${branch}` && current)
|
|
145
|
+
return normalizeComparableCwd(current);
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
export function findListedWorktreeAgentCwd(repoCwd, branch) {
|
|
150
|
+
const worktree = findListedWorktreeOnBranch(repoCwd, branch);
|
|
151
|
+
if (!worktree)
|
|
152
|
+
return undefined;
|
|
153
|
+
const cwdRelative = resolveRepoCwdRelative(repoCwd);
|
|
154
|
+
return cwdRelative ? path.join(worktree, cwdRelative) : worktree;
|
|
155
|
+
}
|
|
156
|
+
export function isComparablePathInside(parent, child) {
|
|
157
|
+
return isPathInside(normalizeComparableCwd(parent), normalizeComparableCwd(child));
|
|
158
|
+
}
|
|
139
159
|
/** Validate a captured patch against the worktree index without changing either. */
|
|
140
160
|
export function validateWorktreePatch(worktreePath, patchPath) {
|
|
141
161
|
const result = runGit(worktreePath, [...PATCH_VALIDATION_OPTIONS, patchPath]);
|
|
@@ -3,7 +3,7 @@ type TimerApi = {
|
|
|
3
3
|
clearTimeout(handle: unknown): void;
|
|
4
4
|
};
|
|
5
5
|
export type CapacityResilientJsonWriterOptions = {
|
|
6
|
-
/**
|
|
6
|
+
/** It must be atomic for each target path. */
|
|
7
7
|
write?: (filePath: string, payload: object) => void;
|
|
8
8
|
/** Keep retry timers referenced by the event loop (needed by child runners). */
|
|
9
9
|
keepAlive?: boolean;
|
|
@@ -7,8 +7,7 @@ import type { StreamFn } from "@earendil-works/pi-agent-core";
|
|
|
7
7
|
* parent keeps `long`, the same split Claude Code makes between its main
|
|
8
8
|
* conversation and its subagents.
|
|
9
9
|
*
|
|
10
|
-
* Unset means children inherit the parent's retention
|
|
11
|
-
* before this setting existed.
|
|
10
|
+
* Unset means children inherit the parent's retention.
|
|
12
11
|
*/
|
|
13
12
|
export declare function childCacheRetention(env?: NodeJS.ProcessEnv): string | undefined;
|
|
14
13
|
/**
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* parent keeps `long`, the same split Claude Code makes between its main
|
|
7
7
|
* conversation and its subagents.
|
|
8
8
|
*
|
|
9
|
-
* Unset means children inherit the parent's retention
|
|
10
|
-
* before this setting existed.
|
|
9
|
+
* Unset means children inherit the parent's retention.
|
|
11
10
|
*/
|
|
12
11
|
export function childCacheRetention(env = process.env) {
|
|
13
12
|
return env.PI_SUBAGENT_CACHE_RETENTION || undefined;
|