pi-subagents 0.88.0 → 0.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -1
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +3 -3
- package/bundle/{chunk-UVDLJXL6.js → chunk-2I6YN6ET.js} +34 -5
- package/bundle/{chunk-6EUQPQY7.js → chunk-443LPCRI.js} +5 -5
- package/bundle/{chunk-4QFZZV3O.js → chunk-4AL6LDBY.js} +3 -1
- package/bundle/{chunk-CKLZ5FGU.js → chunk-4ALRHKGE.js} +1 -1
- package/bundle/{chunk-SVIXQDIV.js → chunk-6JD4XCA4.js} +77 -19
- package/bundle/{chunk-RHYVKQQL.js → chunk-7W2IQFP4.js} +4 -4
- package/bundle/{chunk-W6HIYD2Z.js → chunk-A3INCQ6Z.js} +1 -1
- package/bundle/{chunk-4PM6RDE5.js → chunk-AZW4HXNU.js} +54 -36
- package/bundle/{chunk-XAOHLFJO.js → chunk-CHEABMO2.js} +68 -41
- package/bundle/{chunk-CYKNHFXB.js → chunk-EPMRDKQT.js} +1 -1
- package/bundle/{chunk-6PR44R7E.js → chunk-ETDE2VYK.js} +2 -2
- package/bundle/{chunk-4MVDMA5C.js → chunk-GHJ6BH5U.js} +13 -7
- package/bundle/{chunk-IZEKQEY4.js → chunk-HSHLPYCQ.js} +27 -10
- package/bundle/{chunk-3MFYKBKI.js → chunk-HZDLR73C.js} +4 -4
- package/bundle/{chunk-2DIEL4WG.js → chunk-JFACGAJT.js} +2 -2
- package/bundle/{chunk-L4YY2TOE.js → chunk-JRO2CU4D.js} +1 -1
- package/bundle/{chunk-KXW62VBU.js → chunk-KOLLMZ2X.js} +1 -1
- package/bundle/{chunk-47ZN7NKR.js → chunk-NONHDYXE.js} +1 -1
- package/bundle/{chunk-PJSOS2Q4.js → chunk-NQ26PJSQ.js} +96 -96
- package/bundle/{chunk-6OWNDN7R.js → chunk-PPPAEFRA.js} +2 -2
- package/bundle/{chunk-YDZ7BZD5.js → chunk-S77ZKDLS.js} +1 -1
- package/bundle/{chunk-3DT5X2QC.js → chunk-SLLZJ5EC.js} +50 -18
- package/bundle/{chunk-47GJDBIK.js → chunk-TGABNSG5.js} +5 -5
- package/bundle/{chunk-XIA5GSEU.js → chunk-UQT2EQ4U.js} +2 -2
- package/bundle/{chunk-YZPVALSQ.js → chunk-WW6GQBBS.js} +4 -4
- package/bundle/{chunk-4UGWHREQ.js → chunk-X5ZOTDHO.js} +95 -49
- package/bundle/{chunk-CTPAE36Y.js → chunk-YARY7JWU.js} +22 -0
- package/bundle/{chunk-MTPICU4A.js → chunk-YX7R55CR.js} +75 -32
- package/bundle/{chunk-GDR2ILWY.js → chunk-ZSCIHMUI.js} +50 -22
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +2 -2
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +9 -9
- package/bundle/project-panes.js +3 -3
- package/bundle/required-child-extensions.js +1 -1
- package/docs/agents.md +14 -6
- package/docs/configuration.md +2 -0
- package/docs/extension-api.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/workflows.md +8 -4
- package/package.json +1 -1
- package/src/extension/herdr-pi-bridge.js +78 -22
- package/src/extension/index.d.ts +1 -1
- package/src/extension/index.js +43 -20
- package/src/extension/schemas.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +6 -2
- package/src/extension/subagent-launch-tool.js +13 -9
- package/src/extension/subagent-options.js +5 -0
- package/src/intercom/result-intercom.js +3 -2
- package/src/runs/background/notify.d.ts +3 -0
- package/src/runs/background/notify.js +7 -2
- package/src/runs/background/run-status.js +3 -2
- package/src/runs/background/runner-child-launch.js +1 -0
- package/src/runs/background/stale-run-reconciler.js +17 -8
- package/src/runs/background/subagent-runner.js +11 -8
- package/src/runs/foreground/execution.js +8 -7
- package/src/runs/foreground/subagent-executor.js +42 -11
- package/src/runs/shared/child-launch.d.ts +2 -0
- package/src/runs/shared/child-launch.js +7 -4
- package/src/runs/shared/child-session.d.ts +3 -2
- package/src/runs/shared/child-session.js +3 -27
- package/src/runs/shared/herdr-connection.d.ts +6 -0
- package/src/runs/shared/herdr-connection.js +11 -1
- package/src/runs/shared/herdr-machine.d.ts +2 -2
- package/src/runs/shared/herdr-machine.js +47 -22
- package/src/runs/shared/herdr-pane-host.d.ts +7 -19
- package/src/runs/shared/herdr-pane-host.js +48 -33
- package/src/runs/shared/herdr-pi-protocol.d.ts +1 -0
- package/src/runs/shared/herdr-pi-protocol.js +3 -2
- package/src/runs/shared/herdr-placed-run.d.ts +2 -12
- package/src/runs/shared/herdr-placed-run.js +10 -8
- package/src/runs/shared/kept-branch-text.d.ts +8 -0
- package/src/runs/shared/kept-branch-text.js +24 -0
- package/src/runs/shared/local-machine-access.d.ts +4 -1
- package/src/runs/shared/local-machine-access.js +6 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +5 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +5 -4
- package/src/runs/shared/mutation-evidence.d.ts +7 -1
- package/src/runs/shared/mutation-evidence.js +18 -2
- package/src/runs/shared/parallel-handoff.js +19 -7
- package/src/runs/shared/placed-run-owner.d.ts +4 -2
- package/src/runs/shared/placed-run-owner.js +15 -7
- package/src/runs/shared/rex-machine.d.ts +7 -3
- package/src/runs/shared/rex-machine.js +12 -9
- package/src/runs/shared/rex-pane-host.js +7 -27
- package/src/runs/shared/single-output.js +2 -2
- package/src/runs/shared/subagent-prompt-runtime.js +33 -0
- package/src/runs/shared/tool-availability.d.ts +4 -0
- package/src/runs/shared/tool-availability.js +7 -0
- package/src/runs/shared/worktree-cleanup-plan.js +2 -2
- package/src/runs/shared/worktree.d.ts +4 -14
- package/src/runs/shared/worktree.js +38 -8
- package/src/shared/compaction-interruption.d.ts +9 -0
- package/src/shared/compaction-interruption.js +47 -0
- package/src/shared/parent-wake.d.ts +3 -2
- package/src/shared/parent-wake.js +14 -3
- package/src/shared/required-child-extensions.d.ts +2 -0
- package/src/shared/required-child-extensions.js +27 -0
- package/src/shared/types.d.ts +26 -2
- package/src/tui/fleet.d.ts +7 -2
- package/src/tui/fleet.js +22 -0
- package/src/workflows/workflow-child-summary.d.ts +2 -1
- package/src/workflows/workflow-child-summary.js +14 -6
|
@@ -229,8 +229,41 @@ 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 registered 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 registered = new Set(pi.getAllTools().map((tool) => tool.name));
|
|
244
|
+
// A required tool that never registered is the agent_start diagnostic's case.
|
|
245
|
+
const undeclared = required.filter((name) => registered.has(name) && !declared.has(name));
|
|
246
|
+
if (undeclared.length === 0)
|
|
247
|
+
return undefined;
|
|
248
|
+
const active = new Set(pi.getActiveTools());
|
|
249
|
+
// A fork declares its parent's tools on purpose, to reuse the parent's prompt cache.
|
|
250
|
+
const uncallable = config.forkCacheKey ? [] : [...declared].filter((name) => !active.has(name));
|
|
251
|
+
config.toolDiagnostic?.({
|
|
252
|
+
...(config.agent ? { agent: config.agent } : {}),
|
|
253
|
+
required: [...required],
|
|
254
|
+
available: [...registered],
|
|
255
|
+
missing: [],
|
|
256
|
+
undeclared,
|
|
257
|
+
...(uncallable.length > 0 ? { uncallable } : {}),
|
|
258
|
+
});
|
|
259
|
+
ctx.abort();
|
|
260
|
+
return undefined;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
232
263
|
/** Installed after every other extension: a returned prompt freezes out sections added after it. */
|
|
233
264
|
export function registerSubagentPromptBoundary(pi, config) {
|
|
265
|
+
if (config.requiredTools)
|
|
266
|
+
registerDeclaredToolCheck(pi, config, config.requiredTools);
|
|
234
267
|
if (!rewritesChildPrompt(config))
|
|
235
268
|
return;
|
|
236
269
|
// 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,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function installCompactionInterruptionCapture(sessionClass: {
|
|
2
|
+
prototype: object;
|
|
3
|
+
}): void;
|
|
4
|
+
/** A manual compaction of this session is in progress, until compact() returns. */
|
|
5
|
+
export declare function compactionInProgress(sessionManager: object): boolean;
|
|
6
|
+
/** A manual compaction of this session that aborted an active run is in progress. */
|
|
7
|
+
export declare function compactionInterruptedRun(sessionManager: object): boolean;
|
|
8
|
+
/** True once, for the aborted end of the run the compaction interrupted; a later run's abort is the user's. */
|
|
9
|
+
export declare function takeCompactionAbort(sessionManager: object): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Pi's manual compaction (/compact, RPC, ctx.compact()) aborts the active run before any hook runs, and its
|
|
2
|
+
// events do not say whether it interrupted one. Record that in AgentSession.compact, their shared entry point.
|
|
3
|
+
const stateSymbol = Symbol.for("pi-subagents.compaction-interruption.v1");
|
|
4
|
+
const wrappedSymbol = Symbol.for("pi-subagents.compaction-interruption.v1.wrapped");
|
|
5
|
+
// Shared with the wrapper an earlier extension instance installed before a reload.
|
|
6
|
+
const globalStore = globalThis;
|
|
7
|
+
const compactions = globalStore[stateSymbol] ??= new WeakMap();
|
|
8
|
+
export function installCompactionInterruptionCapture(sessionClass) {
|
|
9
|
+
const prototype = sessionClass.prototype;
|
|
10
|
+
const original = prototype.compact;
|
|
11
|
+
if (original[wrappedSymbol])
|
|
12
|
+
return;
|
|
13
|
+
const compact = async function (...args) {
|
|
14
|
+
const manager = this.sessionManager;
|
|
15
|
+
const compaction = compactions.get(manager) ?? { calls: 0, interrupted: false, abortPending: false };
|
|
16
|
+
compactions.set(manager, compaction);
|
|
17
|
+
compaction.calls += 1;
|
|
18
|
+
// Overlapping calls share the record: a later idle call must not erase an earlier interruption.
|
|
19
|
+
if (this.isStreaming)
|
|
20
|
+
compaction.interrupted = compaction.abortPending = true;
|
|
21
|
+
try {
|
|
22
|
+
return await original.apply(this, args);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
if (--compaction.calls === 0)
|
|
26
|
+
compactions.delete(manager);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
compact[wrappedSymbol] = true;
|
|
30
|
+
prototype.compact = compact;
|
|
31
|
+
}
|
|
32
|
+
/** A manual compaction of this session is in progress, until compact() returns. */
|
|
33
|
+
export function compactionInProgress(sessionManager) {
|
|
34
|
+
return compactions.has(sessionManager);
|
|
35
|
+
}
|
|
36
|
+
/** A manual compaction of this session that aborted an active run is in progress. */
|
|
37
|
+
export function compactionInterruptedRun(sessionManager) {
|
|
38
|
+
return compactions.get(sessionManager)?.interrupted === true;
|
|
39
|
+
}
|
|
40
|
+
/** True once, for the aborted end of the run the compaction interrupted; a later run's abort is the user's. */
|
|
41
|
+
export function takeCompactionAbort(sessionManager) {
|
|
42
|
+
const compaction = compactions.get(sessionManager);
|
|
43
|
+
if (!compaction?.abortPending)
|
|
44
|
+
return false;
|
|
45
|
+
compaction.abortPending = false;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
@@ -10,6 +10,7 @@ export interface ParentWake {
|
|
|
10
10
|
* Returns true when the message was only appended (held, or another wake is already starting
|
|
11
11
|
* the run): Pi emits no extension message_start for it.
|
|
12
12
|
* After userAborted() and until the next run starts, a turn-triggering message is only appended.
|
|
13
|
+
* So it is during a manual compaction, which Pi does not guard against a new run; takeDeferredWake() reports it.
|
|
13
14
|
*/
|
|
14
15
|
sendMessage(...args: Parameters<ExtensionAPI["sendMessage"]>): boolean;
|
|
15
16
|
/** True from an idle wake until its run starts or the session shuts down. Past the deadline it holds only while the parent is busy, which may still be the wake's preflight (for example compacting). */
|
|
@@ -18,9 +19,9 @@ export interface ParentWake {
|
|
|
18
19
|
agentStarted(): void;
|
|
19
20
|
/** The user stopped the parent run: hold wakes until the next run starts. */
|
|
20
21
|
userAborted(): void;
|
|
21
|
-
/** A deliberate resume (manual compaction) drops the hold without touching the shared wake reservation. */
|
|
22
|
-
releaseHold(): void;
|
|
23
22
|
isHeld(): boolean;
|
|
23
|
+
/** True once if a wake was only appended because a manual compaction was in progress. */
|
|
24
|
+
takeDeferredWake(): boolean;
|
|
24
25
|
sessionShutdown(reason: string | undefined): void;
|
|
25
26
|
}
|
|
26
27
|
export declare function createParentWake(pi: Pick<ExtensionAPI, "sendMessage">, now?: () => number): ParentWake;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { compactionInProgress } from "./compaction-interruption.js";
|
|
1
2
|
/** Ends a waking notice that reports results. */
|
|
2
3
|
export const COMPLETION_ACTION = "Read the saved results above and resume the already-authorized parent task, or report completion. If approval is required, explicitly ask the user. Do not silently yield, rerun completed work, or infer new authorization.";
|
|
3
4
|
/** Ends a waking notice that reports a problem or a run state rather than results. */
|
|
@@ -14,6 +15,7 @@ export function createParentWake(pi, now = Date.now) {
|
|
|
14
15
|
// Captured at bind: Pi's ctx throws once stale, which it can be by session_shutdown.
|
|
15
16
|
let session;
|
|
16
17
|
let held = false;
|
|
18
|
+
let deferred = false;
|
|
17
19
|
// Look the reservation up on every access: another extension may have created this session's entry.
|
|
18
20
|
const reservation = () => {
|
|
19
21
|
// Pi can shut an extension down before session_start binds it; an unbound wake reserved nothing.
|
|
@@ -42,6 +44,11 @@ export function createParentWake(pi, now = Date.now) {
|
|
|
42
44
|
pi.sendMessage(message, { triggerTurn: false });
|
|
43
45
|
return true;
|
|
44
46
|
}
|
|
47
|
+
if (session && compactionInProgress(session.manager)) {
|
|
48
|
+
deferred = true;
|
|
49
|
+
pi.sendMessage(message, { triggerTurn: false });
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
45
52
|
if (ctx.isIdle())
|
|
46
53
|
reservation().sentAt = now();
|
|
47
54
|
pi.sendMessage(message, options);
|
|
@@ -51,15 +58,19 @@ export function createParentWake(pi, now = Date.now) {
|
|
|
51
58
|
bindSession(context) {
|
|
52
59
|
ctx = context;
|
|
53
60
|
session = { manager: context.sessionManager, id: context.sessionManager.getSessionId() };
|
|
54
|
-
held = false;
|
|
61
|
+
held = deferred = false;
|
|
55
62
|
},
|
|
56
63
|
agentStarted() {
|
|
57
64
|
reservation().sentAt = undefined;
|
|
58
|
-
held = false;
|
|
65
|
+
held = deferred = false;
|
|
59
66
|
},
|
|
60
67
|
userAborted: () => { held = true; },
|
|
61
|
-
releaseHold: () => { held = false; },
|
|
62
68
|
isHeld: () => held,
|
|
69
|
+
takeDeferredWake() {
|
|
70
|
+
const wasDeferred = deferred;
|
|
71
|
+
deferred = false;
|
|
72
|
+
return wasDeferred;
|
|
73
|
+
},
|
|
63
74
|
sessionShutdown(reason) {
|
|
64
75
|
if (reason !== "reload")
|
|
65
76
|
reservation().sentAt = undefined;
|
|
@@ -28,6 +28,8 @@ export declare function assertRequiredChildExtensionsAdmitted(snapshots: Readonl
|
|
|
28
28
|
runnerType?: string;
|
|
29
29
|
machine?: string;
|
|
30
30
|
}): void;
|
|
31
|
+
/** Maps a path to the identity of the required extension file it names, or undefined. A required path that can't be stat'ed matches only its own spelling. */
|
|
32
|
+
export declare function createRequiredChildExtensionIdentity(requiredPaths: Iterable<string>): (extensionPath: string) => string | undefined;
|
|
31
33
|
export declare function hasMandatoryRequiredChildExtensions(snapshot: RequiredChildExtensionSnapshot | undefined): snapshot is RequiredChildExtensionSnapshot;
|
|
32
34
|
/** Persist a run's mandatory snapshot so append-step admits against it; writes nothing without a mandatory entry. */
|
|
33
35
|
export declare function writeRetainedRequiredChildExtensions(asyncDir: string, snapshot: RequiredChildExtensionSnapshot): void;
|
|
@@ -87,6 +87,33 @@ export function assertRequiredChildExtensionsAdmitted(snapshots, launch) {
|
|
|
87
87
|
if (route)
|
|
88
88
|
throw new Error(`Agent '${launch.agent}' cannot run on ${route}: the host requires child extensions (${ids.join(", ")}) for every runner, and only local native Pi children load them.`);
|
|
89
89
|
}
|
|
90
|
+
function childExtensionFileIdentity(extensionPath) {
|
|
91
|
+
if (!path.isAbsolute(extensionPath))
|
|
92
|
+
return undefined;
|
|
93
|
+
try {
|
|
94
|
+
const stat = fs.statSync(extensionPath, { bigint: true });
|
|
95
|
+
return stat.isFile() ? `${stat.dev}:${stat.ino}` : undefined;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Maps a path to the identity of the required extension file it names, or undefined. A required path that can't be stat'ed matches only its own spelling. */
|
|
102
|
+
export function createRequiredChildExtensionIdentity(requiredPaths) {
|
|
103
|
+
const aliases = new Map([...requiredPaths].map((extensionPath) => [extensionPath, childExtensionFileIdentity(extensionPath) ?? extensionPath]));
|
|
104
|
+
const identities = new Set(aliases.values());
|
|
105
|
+
return (extensionPath) => {
|
|
106
|
+
const known = aliases.get(extensionPath);
|
|
107
|
+
if (known !== undefined)
|
|
108
|
+
return known;
|
|
109
|
+
const identity = childExtensionFileIdentity(extensionPath);
|
|
110
|
+
if (identity === undefined || !identities.has(identity))
|
|
111
|
+
return undefined;
|
|
112
|
+
// Retain the alias even if the extension removes its file before reporting a failure.
|
|
113
|
+
aliases.set(extensionPath, identity);
|
|
114
|
+
return identity;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
90
117
|
export function hasMandatoryRequiredChildExtensions(snapshot) {
|
|
91
118
|
return snapshot?.some((entry) => entry.requireForAllRunners) === true;
|
|
92
119
|
}
|
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/tui/fleet.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { type Component, type MarkdownTheme, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui";
|
|
2
|
+
import { type Component, type Focusable, type MarkdownTheme, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui";
|
|
3
3
|
import { type ExternalRun } from "../api/external-runs.ts";
|
|
4
4
|
import { type FleetKeybindingAction, type FleetKeybindingsConfig, type ForegroundChildControl, type ForegroundResumeChild, type ForegroundResumeRun, type ForegroundRunControl, type SubagentState } from "../shared/types.ts";
|
|
5
5
|
import { type AsyncRunSummary } from "../runs/background/async-status.ts";
|
|
@@ -14,6 +14,7 @@ type FleetTui = {
|
|
|
14
14
|
rows: number;
|
|
15
15
|
};
|
|
16
16
|
requestRender(): void;
|
|
17
|
+
getFocusedComponent?(): Component | null;
|
|
17
18
|
};
|
|
18
19
|
type AsyncStep = AsyncRunSummary["steps"][number];
|
|
19
20
|
export type FleetItem = ({
|
|
@@ -108,7 +109,7 @@ export declare function collectFleetSnapshot(state: SubagentState, options?: {
|
|
|
108
109
|
resultsDir?: string;
|
|
109
110
|
limit?: number;
|
|
110
111
|
}): FleetSnapshot;
|
|
111
|
-
export declare class SubagentFleetComponent implements Component {
|
|
112
|
+
export declare class SubagentFleetComponent implements Component, Focusable {
|
|
112
113
|
private snapshot;
|
|
113
114
|
private selected;
|
|
114
115
|
private selectedKey;
|
|
@@ -125,6 +126,8 @@ export declare class SubagentFleetComponent implements Component {
|
|
|
125
126
|
private actionBusy;
|
|
126
127
|
private transcriptCache;
|
|
127
128
|
private disposed;
|
|
129
|
+
private hasFocus;
|
|
130
|
+
private readonly openedOver;
|
|
128
131
|
private refreshTimer;
|
|
129
132
|
private readonly refreshMs;
|
|
130
133
|
private readonly tui;
|
|
@@ -154,6 +157,8 @@ export declare class SubagentFleetComponent implements Component {
|
|
|
154
157
|
private setActionNotice;
|
|
155
158
|
private runAction;
|
|
156
159
|
private scrollDetail;
|
|
160
|
+
get focused(): boolean;
|
|
161
|
+
set focused(value: boolean);
|
|
157
162
|
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined;
|
|
158
163
|
handleInput(data: string): void;
|
|
159
164
|
private rosterLines;
|
package/src/tui/fleet.js
CHANGED
|
@@ -770,6 +770,10 @@ export class SubagentFleetComponent {
|
|
|
770
770
|
actionBusy = false;
|
|
771
771
|
transcriptCache;
|
|
772
772
|
disposed = false;
|
|
773
|
+
// Undefined until a TUI first focuses the overlay, so a fleet rendered outside one still draws.
|
|
774
|
+
hasFocus;
|
|
775
|
+
// The component focused when the fleet opened (the overlay's preFocus).
|
|
776
|
+
openedOver;
|
|
773
777
|
refreshTimer;
|
|
774
778
|
refreshMs;
|
|
775
779
|
tui;
|
|
@@ -781,6 +785,7 @@ export class SubagentFleetComponent {
|
|
|
781
785
|
keybindings;
|
|
782
786
|
constructor(tui, theme, state, done, options = {}) {
|
|
783
787
|
this.tui = tui;
|
|
788
|
+
this.openedOver = tui.getFocusedComponent?.();
|
|
784
789
|
this.viewport = new FleetViewport(() => this.tui.requestRender());
|
|
785
790
|
this.theme = theme;
|
|
786
791
|
this.markdownTheme = options.markdownTheme ?? getMarkdownTheme();
|
|
@@ -984,6 +989,15 @@ export class SubagentFleetComponent {
|
|
|
984
989
|
scrollDetail(delta) {
|
|
985
990
|
this.viewport.scroll.scrollBy(delta);
|
|
986
991
|
}
|
|
992
|
+
get focused() {
|
|
993
|
+
return this.hasFocus === true;
|
|
994
|
+
}
|
|
995
|
+
set focused(value) {
|
|
996
|
+
if (value === this.hasFocus)
|
|
997
|
+
return;
|
|
998
|
+
this.hasFocus = value;
|
|
999
|
+
this.tui.requestRender();
|
|
1000
|
+
}
|
|
987
1001
|
handleMouse(event) {
|
|
988
1002
|
// Block pointer fallback as well as inspector actions while a text/confirmation modal owns input.
|
|
989
1003
|
if (this.steerDraft !== undefined || this.redoGuidanceDraft !== undefined || this.stopConfirming || this.actionBusy) {
|
|
@@ -1339,6 +1353,14 @@ export class SubagentFleetComponent {
|
|
|
1339
1353
|
return { header: [], body: this.withActionLines(lines) };
|
|
1340
1354
|
}
|
|
1341
1355
|
render(width) {
|
|
1356
|
+
// An inline dialog that took focus (a permission prompt, select, confirm) sits under this overlay and
|
|
1357
|
+
// would be covered while it owns the keys. Hiding the overlay through its handle would cancel the
|
|
1358
|
+
// TUI's focus restore, so draw nothing until the TUI gives focus back. Focus moving to the component the
|
|
1359
|
+
// fleet opened over (a fullscreen click on the editor) shows no dialog, and the next key returns to the fleet.
|
|
1360
|
+
if (this.hasFocus === false && this.tui.getFocusedComponent?.() !== this.openedOver) {
|
|
1361
|
+
this.renderedLayout = undefined;
|
|
1362
|
+
return [];
|
|
1363
|
+
}
|
|
1342
1364
|
const layout = fleetLayout(width, this.tui.terminal?.rows ?? 32, this.selected, this.snapshot.items);
|
|
1343
1365
|
this.renderedLayout = layout;
|
|
1344
1366
|
if (!layout)
|
|
@@ -14,10 +14,11 @@ export declare function workflowChildSummary(input: {
|
|
|
14
14
|
steps?: NonNullable<AsyncStatus["steps"]>;
|
|
15
15
|
/** In-memory snapshots from synchronous child callbacks, keyed by workflow key. */
|
|
16
16
|
progress?: ReadonlyMap<string, WorkflowChildLiveProgress>;
|
|
17
|
-
/** Agent
|
|
17
|
+
/** Agent, run id and session file each child launched with, keyed by workflow key; known before an async child settles. */
|
|
18
18
|
launches?: ReadonlyMap<string, {
|
|
19
19
|
agent: string;
|
|
20
20
|
runId?: string;
|
|
21
|
+
sessionFile?: string;
|
|
21
22
|
}>;
|
|
22
23
|
}): WorkflowChildSummary;
|
|
23
24
|
export declare function parseWorkflowChildSummary(value: unknown): WorkflowChildSummary | undefined;
|
|
@@ -2,6 +2,8 @@ import { hashedSegment } from "../runs/background/index-segment.js";
|
|
|
2
2
|
const KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
3
3
|
const TERMINAL_STATES = new Set(["completed", "failed", "paused", "stopped", "rejected", "detached"]);
|
|
4
4
|
const MAX_REQUIRED_ID_BYTES = 4_096;
|
|
5
|
+
/** Linux PATH_MAX: a longer session path cannot be opened anyway. */
|
|
6
|
+
const MAX_SESSION_FILE_BYTES = 4_096;
|
|
5
7
|
const ACTIVITY_COUNTERS = ["currentToolStartedAt", "lastActivityAt", "durationMs", "toolCount", "turnCount", "tokens", "inputTokens", "outputTokens"];
|
|
6
8
|
export function workflowChildProgress(progress) {
|
|
7
9
|
return {
|
|
@@ -71,6 +73,7 @@ export function workflowChildSummary(input) {
|
|
|
71
73
|
...(bounded(entry.runId, 256) ? { runId: bounded(entry.runId, 256) } : {}),
|
|
72
74
|
...(previous?.agent ? { agent: previous.agent } : {}),
|
|
73
75
|
...(previous?.sessionName ? { sessionName: previous.sessionName } : {}),
|
|
76
|
+
...(previous?.sessionFile ? { sessionFile: previous.sessionFile } : {}),
|
|
74
77
|
...(previous?.model ? { model: previous.model } : {}),
|
|
75
78
|
...(previous?.thinking ? { thinking: previous.thinking } : {}),
|
|
76
79
|
});
|
|
@@ -94,6 +97,7 @@ export function workflowChildSummary(input) {
|
|
|
94
97
|
...(bounded(step.runId, 256) ? { runId: bounded(step.runId, 256) } : {}),
|
|
95
98
|
...(launchResolved && bounded(step.agent, 256) ? { agent: bounded(step.agent, 256) } : {}),
|
|
96
99
|
...(bounded(step.sessionName, 256) ? { sessionName: bounded(step.sessionName, 256) } : {}),
|
|
100
|
+
...(bounded(step.sessionFile, MAX_SESSION_FILE_BYTES) ? { sessionFile: step.sessionFile } : {}),
|
|
97
101
|
...(bounded(step.model, 256) ? { model: bounded(step.model, 256) } : {}),
|
|
98
102
|
...(bounded(step.thinking, 32) ? { thinking: bounded(step.thinking, 32) } : {}),
|
|
99
103
|
});
|
|
@@ -109,6 +113,7 @@ export function workflowChildSummary(input) {
|
|
|
109
113
|
...(bounded(child.runId, 256) ? { runId: bounded(child.runId, 256) } : {}),
|
|
110
114
|
...(bounded(child.agent, 256) ? { agent: bounded(child.agent, 256) } : {}),
|
|
111
115
|
...(bounded(result?.sessionName, 256) ? { sessionName: bounded(result?.sessionName, 256) } : {}),
|
|
116
|
+
...(bounded(result?.sessionFile, MAX_SESSION_FILE_BYTES) ? { sessionFile: result?.sessionFile } : {}),
|
|
112
117
|
...(bounded(result?.model, 256) ? { model: bounded(result?.model, 256) } : {}),
|
|
113
118
|
...(bounded(result?.thinking, 32) ? { thinking: bounded(result?.thinking, 32) } : {}),
|
|
114
119
|
});
|
|
@@ -121,12 +126,15 @@ export function workflowChildSummary(input) {
|
|
|
121
126
|
}
|
|
122
127
|
for (const [key, launch] of input.launches ?? []) {
|
|
123
128
|
const row = rows.get(key);
|
|
124
|
-
if (!row
|
|
129
|
+
if (!row)
|
|
125
130
|
continue;
|
|
131
|
+
const running = row.state === "running";
|
|
126
132
|
rows.set(key, {
|
|
127
133
|
...row,
|
|
128
|
-
...(!row.runId && bounded(launch.runId, 256) ? { runId: launch.runId } : {}),
|
|
129
|
-
...(!row.agent && bounded(launch.agent, 256) ? { agent: launch.agent } : {}),
|
|
134
|
+
...(running && !row.runId && bounded(launch.runId, 256) ? { runId: launch.runId } : {}),
|
|
135
|
+
...(running && !row.agent && bounded(launch.agent, 256) ? { agent: launch.agent } : {}),
|
|
136
|
+
// Finished rows keep it too: live updates carry no child results, so this is a settled child's only transcript link until the workflow returns.
|
|
137
|
+
...(!row.sessionFile && bounded(launch.sessionFile, MAX_SESSION_FILE_BYTES) ? { sessionFile: launch.sessionFile } : {}),
|
|
130
138
|
});
|
|
131
139
|
}
|
|
132
140
|
for (const [key, progress] of input.progress ?? []) {
|
|
@@ -169,21 +177,21 @@ export function parseWorkflowChildSummary(value) {
|
|
|
169
177
|
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
170
178
|
throw new Error("workflowChildren child row is invalid.");
|
|
171
179
|
const child = row;
|
|
172
|
-
if (Object.keys(child).some((key) => !["childId", "runId", "agent", "sessionName", "model", "thinking", "state", "activity"].includes(key)))
|
|
180
|
+
if (Object.keys(child).some((key) => !["childId", "runId", "agent", "sessionName", "sessionFile", "model", "thinking", "state", "activity"].includes(key)))
|
|
173
181
|
throw new Error("workflowChildren child row has unsupported fields.");
|
|
174
182
|
if (typeof child.childId !== "string" || !KEY_PATTERN.test(child.childId))
|
|
175
183
|
throw new Error("workflowChildren childId is invalid.");
|
|
176
184
|
const state = child.state;
|
|
177
185
|
if (state !== "pending" && state !== "running" && state !== "completed" && state !== "failed" && state !== "paused" && state !== "stopped" && state !== "rejected" && state !== "detached")
|
|
178
186
|
throw new Error("workflowChildren child state is invalid.");
|
|
179
|
-
for (const [field, maxBytes] of [["runId", 256], ["agent", 256], ["sessionName", 256], ["model", 256], ["thinking", 32]]) {
|
|
187
|
+
for (const [field, maxBytes] of [["runId", 256], ["agent", 256], ["sessionName", 256], ["sessionFile", MAX_SESSION_FILE_BYTES], ["model", 256], ["thinking", 32]]) {
|
|
180
188
|
if (child[field] !== undefined && bounded(child[field], maxBytes) === undefined)
|
|
181
189
|
throw new Error(`workflowChildren child ${field} is invalid.`);
|
|
182
190
|
}
|
|
183
191
|
const activity = parseActivity(child.activity);
|
|
184
192
|
if (activity && state !== "running")
|
|
185
193
|
throw new Error("workflowChildren child activity requires running state.");
|
|
186
|
-
return { childId: child.childId, state, ...(activity ? { activity } : {}), ...(child.runId ? { runId: child.runId } : {}), ...(child.agent ? { agent: child.agent } : {}), ...(child.sessionName ? { sessionName: child.sessionName } : {}), ...(child.model ? { model: child.model } : {}), ...(child.thinking ? { thinking: child.thinking } : {}) };
|
|
194
|
+
return { childId: child.childId, state, ...(activity ? { activity } : {}), ...(child.runId ? { runId: child.runId } : {}), ...(child.agent ? { agent: child.agent } : {}), ...(child.sessionName ? { sessionName: child.sessionName } : {}), ...(child.sessionFile ? { sessionFile: child.sessionFile } : {}), ...(child.model ? { model: child.model } : {}), ...(child.thinking ? { thinking: child.thinking } : {}) };
|
|
187
195
|
});
|
|
188
196
|
if (new Set(children.map((child) => child.childId)).size !== children.length)
|
|
189
197
|
throw new Error("workflowChildren has duplicate childId values.");
|