@xzzpig/pi-subagents 0.24.2 → 0.25.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 +37 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/{chunk-RU522D5W.js → chunk-FQPV4O6C.js} +183 -28
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-CYY5UMJU.js → chunk-IXCEOEJT.js} +411 -249
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-224WMDIV.js → chunk-JUYNN63E.js} +350 -123
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-XWWUDWUW.js → chunk-KRNBJPZ2.js} +670 -400
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-JEA2ZKUA.js → chunk-MMJQMPOK.js} +37 -165
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-4UH4WS4G.js → chunk-SNDCIJMK.js} +23 -12
- package/bundle/{chunk-O4D5PBVI.js → chunk-TM2K53NX.js} +3 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-BQ2OAB4Q.js → chunk-WWDUNXSE.js} +67 -30
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- 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/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- 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 +12 -3
- package/src/extension/schemas.js +7 -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 +55 -15
- 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 +7 -10
- package/src/runs/background/async-execution.js +66 -29
- 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 +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- 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 +2 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- 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-subscriptions.js +124 -12
- 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/async-steering-action.js +24 -9
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +68 -84
- package/src/runs/foreground/fork-tool-result-handler.d.ts +60 -0
- package/src/runs/foreground/fork-tool-result-handler.js +83 -0
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- 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 +6 -5
- package/src/runs/shared/child-session.js +85 -38
- 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 +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- 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 +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- 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 +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- 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/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- 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 +64 -0
- package/src/shared/fleet-transcript-reader.js +376 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- 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/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -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-native-transcript.js +1 -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 -57
- package/src/tui/fleet-transcript.js +4 -370
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- 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-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isTrustedRecordedSessionFile,
|
|
3
3
|
resolveSubagentRunId
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ULGMXABL.js";
|
|
5
5
|
import {
|
|
6
6
|
formatShellCommand
|
|
7
7
|
} from "./chunk-7J4ZXMY7.js";
|
|
8
8
|
import {
|
|
9
9
|
agentStreamOptions,
|
|
10
10
|
opencodeSessionHeaders,
|
|
11
|
-
ownsRun,
|
|
12
11
|
resolveAsyncResumeTarget
|
|
13
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-DLVPMML3.js";
|
|
13
|
+
import {
|
|
14
|
+
ownsRun
|
|
15
|
+
} from "./chunk-HXRB42AF.js";
|
|
14
16
|
import {
|
|
15
17
|
currentCompletionOwnerId,
|
|
16
18
|
listMissions,
|
|
@@ -19,12 +21,12 @@ import {
|
|
|
19
21
|
reconcileAsyncRun,
|
|
20
22
|
resolveAuthorityDecision,
|
|
21
23
|
resolveMissionStoreLocation
|
|
22
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-JH5H4CYJ.js";
|
|
23
25
|
import {
|
|
24
26
|
deliverInterruptRequest,
|
|
25
27
|
queueRevivalBrief,
|
|
26
28
|
requestAsyncSteer
|
|
27
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-LPJEKHOY.js";
|
|
28
30
|
import {
|
|
29
31
|
readStatus,
|
|
30
32
|
redactSecretValues,
|
|
@@ -32,7 +34,7 @@ import {
|
|
|
32
34
|
tryLease,
|
|
33
35
|
writeAtomicJson,
|
|
34
36
|
writePrivateAtomicJson
|
|
35
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-XAC2XNAP.js";
|
|
36
38
|
import {
|
|
37
39
|
DIRS
|
|
38
40
|
} from "./chunk-UQDHXMUG.js";
|
|
@@ -74,7 +76,7 @@ function recordSteeringRequest(status, input) {
|
|
|
74
76
|
requestedAt: input.requestedAt,
|
|
75
77
|
...input.source ? { source: input.source } : {},
|
|
76
78
|
messagePreview: steeringMessagePreview(input.message),
|
|
77
|
-
targets: input.targets.map((target) => ({ index: target.index, state: target.state, ...target.reason ? { reason: target.reason } : {} }))
|
|
79
|
+
targets: input.targets.map((target) => ({ index: target.index, state: target.state, ...target.reason ? { reason: target.reason } : {}, ...target.failureKind ? { failureKind: target.failureKind } : {} }))
|
|
78
80
|
};
|
|
79
81
|
status.requested++;
|
|
80
82
|
status.lastRequestedAt = input.requestedAt;
|
|
@@ -93,6 +95,8 @@ function updateSteeringTarget(status, requestId, index, state, now, fields = {})
|
|
|
93
95
|
const request = status.recent.find((candidate) => candidate.id === requestId);
|
|
94
96
|
const target = request?.targets.find((candidate) => candidate.index === index);
|
|
95
97
|
if (!target) return void 0;
|
|
98
|
+
if (state !== "failed") delete target.failureKind;
|
|
99
|
+
else if (fields.failureKind) target.failureKind = fields.failureKind;
|
|
96
100
|
if (state === "late" && target.state === "recovered") {
|
|
97
101
|
if (target.lateDeliveredAt === void 0) {
|
|
98
102
|
target.lateDeliveredAt = now;
|
|
@@ -142,6 +146,7 @@ function actionResultFromSteeringStatus(status, sourceRunId, requestId, replacem
|
|
|
142
146
|
...target.deliveredAt !== void 0 ? { deliveredAt: target.deliveredAt } : {},
|
|
143
147
|
...target.lateDeliveredAt !== void 0 ? { lateDeliveredAt: target.lateDeliveredAt } : {},
|
|
144
148
|
...target.reason ? { reason: target.reason } : {},
|
|
149
|
+
...target.failureKind ? { failureKind: target.failureKind } : {},
|
|
145
150
|
...target.replacementRunId ? { replacementRunId: target.replacementRunId } : {}
|
|
146
151
|
}));
|
|
147
152
|
const states = targets.map((target) => target.state);
|
|
@@ -238,6 +243,9 @@ function steerTargetsAccepted(result2) {
|
|
|
238
243
|
const targets = result2?.targets ?? [];
|
|
239
244
|
return targets.length > 0 && targets.every((target) => target.state === "queued" || target.state === "delivered");
|
|
240
245
|
}
|
|
246
|
+
function steerTargetsRejected(result2) {
|
|
247
|
+
return result2?.targets.some((target) => target.state === "failed" && target.failureKind === "rejected") === true;
|
|
248
|
+
}
|
|
241
249
|
function canQueueRetainedAsyncFollowUp(status, index) {
|
|
242
250
|
const steps = status.steps ?? [];
|
|
243
251
|
return status.state === "complete" && Boolean(status.parentWorkflowRunId) && steps.length === 1 && (steps[0]?.status === "complete" || steps[0]?.status === "completed") && Boolean(steps[0]?.sessionFile ?? status.sessionFile) && (index === void 0 || index === 0);
|
|
@@ -375,8 +383,10 @@ ${replies}` }],
|
|
|
375
383
|
if (input.signal?.aborted) {
|
|
376
384
|
return { content: [{ type: "text", text: steeringReceipt(input.message, `Steering pending for async run ${status.runId} (request ${requestId}); caller aborted before recovery.`) }], details: { mode: "management", results: [], steering: result2 } };
|
|
377
385
|
}
|
|
386
|
+
const projected = (current) => current?.steering ? actionResultFromSteeringStatus(current.steering, status.runId, requestId) : void 0;
|
|
387
|
+
const rejected = () => new Error(`Child rejected the guidance; continue it with action "resume" and id "${status.runId}".`);
|
|
378
388
|
const finalStatus = readStatus(asyncDir);
|
|
379
|
-
const finalResult =
|
|
389
|
+
const finalResult = projected(finalStatus);
|
|
380
390
|
const acceptedReply = (accepted) => {
|
|
381
391
|
const acceptedState = accepted.state === "delivered" ? "delivered" : "queued";
|
|
382
392
|
return { content: [{ type: "text", text: steeringReceipt(input.message, `Steering ${acceptedState} for async run ${status.runId} (request ${requestId}).`) }], details: { mode: "management", results: [], steering: accepted } };
|
|
@@ -384,7 +394,7 @@ ${replies}` }],
|
|
|
384
394
|
if (finalResult && steerTargetsAccepted(finalResult)) return acceptedReply(finalResult);
|
|
385
395
|
const running = (finalStatus?.steps ?? status.steps ?? []).filter((step) => step.status === "running");
|
|
386
396
|
const recoveryAllowed = (input.mode ?? "steer") === "steer" && status.mode === "single" && status.isNested !== true && running.length === 1 && Boolean(finalStatus?.steering) && (input.index === void 0 || input.index === 0);
|
|
387
|
-
if (recoveryAllowed && finalResult?.state !== "scheduled" && input.recover) {
|
|
397
|
+
if (recoveryAllowed && finalResult?.state !== "scheduled" && !steerTargetsRejected(finalResult) && input.recover) {
|
|
388
398
|
const appendSteeringNotice = (state, message) => {
|
|
389
399
|
try {
|
|
390
400
|
fs2.appendFileSync(path2.join(asyncDir, "events.jsonl"), `${JSON.stringify({ type: "subagent.steering.notice", ts: Date.now(), runId: status.runId, requestId, state, message, ...status.sessionId ? { currentSessionId: status.sessionId } : {} })}
|
|
@@ -393,18 +403,18 @@ ${replies}` }],
|
|
|
393
403
|
}
|
|
394
404
|
};
|
|
395
405
|
try {
|
|
396
|
-
const
|
|
397
|
-
const latestResult = latest?.steering ? actionResultFromSteeringStatus(latest.steering, status.runId, requestId) : void 0;
|
|
406
|
+
const latestResult = projected(readStatus(asyncDir));
|
|
398
407
|
if (latestResult && steerTargetsAccepted(latestResult)) return acceptedReply(latestResult);
|
|
408
|
+
if (steerTargetsRejected(latestResult)) throw rejected();
|
|
399
409
|
const committedAt = Date.now();
|
|
400
410
|
input.onBeforeRecoveryClaim?.(requestId, committedAt);
|
|
401
411
|
const { claimPath, markerPath } = claimSteeringRecovery(asyncDir, { requestId, sourceRunId: status.runId, committedAt });
|
|
402
412
|
input.onRecoveryCommitted?.(requestId, committedAt);
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
if (preCommitResult && preCommitResult.targets.length > 0 && preCommitResult.targets.every((target) => target.state === "queued" || target.deliveredAt !== void 0 && target.deliveredAt <= committedAt)) {
|
|
413
|
+
const preCommitResult = projected(readStatus(asyncDir));
|
|
414
|
+
if (preCommitResult && (steerTargetsRejected(preCommitResult) || preCommitResult.targets.length > 0 && preCommitResult.targets.every((target) => target.state === "queued" || target.deliveredAt !== void 0 && target.deliveredAt <= committedAt))) {
|
|
406
415
|
fs2.rmSync(markerPath, { force: true });
|
|
407
416
|
fs2.rmSync(claimPath, { force: true });
|
|
417
|
+
if (steerTargetsRejected(preCommitResult)) throw rejected();
|
|
408
418
|
return acceptedReply(preCommitResult);
|
|
409
419
|
}
|
|
410
420
|
try {
|
|
@@ -422,6 +432,10 @@ ${replies}` }],
|
|
|
422
432
|
if (input.signal?.aborted) break;
|
|
423
433
|
const candidate = readStatus(asyncDir);
|
|
424
434
|
lastObservedState = candidate?.state;
|
|
435
|
+
if (steerTargetsRejected(projected(candidate))) {
|
|
436
|
+
fs2.rmSync(claimPath, { force: true });
|
|
437
|
+
throw rejected();
|
|
438
|
+
}
|
|
425
439
|
if (candidate?.state === "paused" && candidate.endedAt !== void 0) {
|
|
426
440
|
paused = candidate;
|
|
427
441
|
break;
|
|
@@ -445,6 +459,10 @@ ${replies}` }],
|
|
|
445
459
|
if (recoveryTarget.kind !== "revive" || !recoveryTarget.sessionFile) throw new Error("Source run has no valid persisted child session; it remains paused and requires a new run.");
|
|
446
460
|
if (!recoveryTarget.recoveryDescriptor) throw new Error("Source run has no private recovery descriptor; it remains paused and is not safely resumable.");
|
|
447
461
|
const limits = remainingSteeringRecoveryLimits(recoveryTarget.recoveryDescriptor, paused);
|
|
462
|
+
if (steerTargetsRejected(projected(readStatus(asyncDir)))) {
|
|
463
|
+
fs2.rmSync(claimPath, { force: true });
|
|
464
|
+
throw rejected();
|
|
465
|
+
}
|
|
448
466
|
const revived = await input.recover(limits);
|
|
449
467
|
if (revived.isError || !revived.details.asyncId) throw new Error(revived.content[0]?.type === "text" ? revived.content[0].text : "Replacement launch failed; source run remains paused.");
|
|
450
468
|
const targetIndex = input.index ?? paused.steering?.recent.find((request) => request.id === requestId)?.targets[0]?.index ?? status.steps?.findIndex((step) => step.status === "running") ?? -1;
|
|
@@ -468,7 +486,7 @@ ${replies}` }],
|
|
|
468
486
|
failedStatus.activityState = "needs_attention";
|
|
469
487
|
writeAtomicJson(path2.join(asyncDir, "status.json"), failedStatus);
|
|
470
488
|
}
|
|
471
|
-
const failed =
|
|
489
|
+
const failed = projected(failedStatus);
|
|
472
490
|
appendSteeringNotice("failed", `Steering failed for run ${status.runId}: ${reason}`);
|
|
473
491
|
return { content: [{ type: "text", text: steeringReceipt(input.message, `Steering failed for async run ${status.runId} (request ${requestId}): ${reason}`) }], isError: true, details: { mode: "management", results: [], steering: failed ?? { requestId, state: "failed", sourceRunId: status.runId, deliveryStatus: "queued", targets: [{ index: input.index ?? 0, state: "failed", reason }] } } };
|
|
474
492
|
}
|
|
@@ -603,15 +621,12 @@ async function steerWorkflowForegroundTarget(input) {
|
|
|
603
621
|
return { content: [{ type: "text", text: steeringReceipt(message, `Steering failed for foreground run ${control.runId} (request ${requestId}): ${outcome.reason ?? "unknown error"}`) }], isError: true, details: { mode: "management", results: [], steering } };
|
|
604
622
|
}
|
|
605
623
|
|
|
606
|
-
// src/
|
|
624
|
+
// src/shared/fleet-transcript-reader.ts
|
|
607
625
|
import * as fs3 from "node:fs";
|
|
608
626
|
import * as path4 from "node:path";
|
|
609
|
-
import { getLanguageFromPath, highlightCode } from "@earendil-works/pi-coding-agent";
|
|
610
|
-
import { Markdown, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
611
627
|
var DEFAULT_MAX_RECORDS = 240;
|
|
612
628
|
var DEFAULT_MAX_BYTES = 2 * 1024 * 1024;
|
|
613
629
|
var MAX_MESSAGE_CHARS = 64 * 1024;
|
|
614
|
-
var TOOL_PREVIEW_LINES = 7;
|
|
615
630
|
function sanitizeJsonDisplayValue(value) {
|
|
616
631
|
if (typeof value === "string") {
|
|
617
632
|
const safe = safeTerminalText(value);
|
|
@@ -929,151 +944,6 @@ function readTranscriptRecords(filePath, options) {
|
|
|
929
944
|
...warnings.length ? { warning: safeTerminalText(warnings.join(" ")) } : {}
|
|
930
945
|
};
|
|
931
946
|
}
|
|
932
|
-
function statusGlyph(event, theme) {
|
|
933
|
-
if (event.status === "running") return theme.fg("warning", "\u25CF");
|
|
934
|
-
if (event.status === "error") return theme.fg("error", "\u2717");
|
|
935
|
-
return theme.fg("success", "\u2713");
|
|
936
|
-
}
|
|
937
|
-
function jsonScalar(value) {
|
|
938
|
-
if (typeof value === "string" && value.trim()) return value;
|
|
939
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
940
|
-
return void 0;
|
|
941
|
-
}
|
|
942
|
-
function parseToolArgs(event) {
|
|
943
|
-
if (!event.argsPayload) return void 0;
|
|
944
|
-
try {
|
|
945
|
-
return objectValue(JSON.parse(event.argsPayload));
|
|
946
|
-
} catch {
|
|
947
|
-
return void 0;
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
function toolDuration(event) {
|
|
951
|
-
if (event.startedAt === void 0 || event.endedAt === void 0) return void 0;
|
|
952
|
-
return `${((event.endedAt - event.startedAt) / 1e3).toFixed(1)}s`;
|
|
953
|
-
}
|
|
954
|
-
function renderExpandedTool(event, width, theme) {
|
|
955
|
-
const lines = [];
|
|
956
|
-
const args = parseToolArgs(event);
|
|
957
|
-
const glyph = statusGlyph(event, theme);
|
|
958
|
-
const output = event.output ?? event.error;
|
|
959
|
-
const outputColor = event.status === "error" ? "error" : "toolOutput";
|
|
960
|
-
if (event.name === "bash") {
|
|
961
|
-
const command = jsonScalar(args?.command) ?? event.args ?? "(unknown command)";
|
|
962
|
-
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(`$ ${command}`))}`, width, theme));
|
|
963
|
-
if (output) {
|
|
964
|
-
for (const outputLine of output.replace(/\s+$/, "").split(/\r?\n/)) {
|
|
965
|
-
for (const wrapped of renderWrapped(theme.fg(outputColor, outputLine), Math.max(1, width - 4))) {
|
|
966
|
-
lines.push(railLine(` ${wrapped}`, width, theme));
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
const duration = toolDuration(event);
|
|
971
|
-
if (duration) lines.push(railLine(theme.fg("dim", ` Took ${duration}`), width, theme));
|
|
972
|
-
return lines;
|
|
973
|
-
}
|
|
974
|
-
if (event.name === "read") {
|
|
975
|
-
const filePath = jsonScalar(args?.path ?? args?.file_path);
|
|
976
|
-
const language = filePath ? getLanguageFromPath(filePath) : void 0;
|
|
977
|
-
const rendered = !output ? [] : event.status === "error" ? output.split("\n").map((line) => theme.fg("error", line)) : language ? highlightCode(output, language) : output.split("\n");
|
|
978
|
-
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(`read ${filePath ?? event.args ?? ""}`))}`, width, theme));
|
|
979
|
-
for (const line of rendered) {
|
|
980
|
-
for (const wrapped of renderWrapped(line, Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
981
|
-
}
|
|
982
|
-
return lines;
|
|
983
|
-
}
|
|
984
|
-
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(event.name))}`, width, theme));
|
|
985
|
-
if (event.argsPayload) {
|
|
986
|
-
lines.push(railLine(theme.fg("dim", " args"), width, theme));
|
|
987
|
-
for (const argLine of event.argsPayload.split(/\r?\n/)) {
|
|
988
|
-
for (const wrapped of renderWrapped(theme.fg("muted", argLine), Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
if (output) {
|
|
992
|
-
lines.push(railLine(theme.fg(event.status === "error" ? "error" : "dim", event.status === "error" ? " error" : " output"), width, theme));
|
|
993
|
-
for (const outputLine of output.split(/\r?\n/)) {
|
|
994
|
-
for (const wrapped of renderWrapped(theme.fg(outputColor, outputLine), Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
return lines;
|
|
998
|
-
}
|
|
999
|
-
function bounded(text, width) {
|
|
1000
|
-
return truncateToWidth(text, Math.max(0, width));
|
|
1001
|
-
}
|
|
1002
|
-
function railLine(content, width, theme) {
|
|
1003
|
-
return bounded(`${theme.fg("borderMuted", "\u2502")} ${content}`, width);
|
|
1004
|
-
}
|
|
1005
|
-
function renderWrapped(text, width) {
|
|
1006
|
-
return wrapTextWithAnsi(text, Math.max(1, width));
|
|
1007
|
-
}
|
|
1008
|
-
function renderFleetTranscript(transcript, width, theme, markdownTheme, options = {}) {
|
|
1009
|
-
if (width <= 0) return [];
|
|
1010
|
-
const lines = [];
|
|
1011
|
-
if (transcript.truncated) lines.push(bounded(theme.fg("dim", "\u2191 Earlier activity omitted"), width));
|
|
1012
|
-
if (transcript.warning) {
|
|
1013
|
-
for (const line of renderWrapped(safeTerminalText(transcript.warning), Math.max(1, width - 2))) {
|
|
1014
|
-
lines.push(bounded(`${theme.fg("warning", "!")} ${theme.fg("warning", line)}`, width));
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
for (const rawEvent of transcript.events) {
|
|
1018
|
-
const event = safeTranscriptEvent(rawEvent);
|
|
1019
|
-
if (event.kind === "tool") {
|
|
1020
|
-
if (options.expandedTools && (event.output || event.argsPayload || event.error)) {
|
|
1021
|
-
lines.push(...renderExpandedTool(event, width, theme));
|
|
1022
|
-
lines.push(railLine(theme.fg("dim", " x to collapse"), width, theme));
|
|
1023
|
-
continue;
|
|
1024
|
-
}
|
|
1025
|
-
const title = theme.fg("toolTitle", theme.bold(event.name));
|
|
1026
|
-
const args = event.args ? ` ${theme.fg("dim", event.args)}` : "";
|
|
1027
|
-
const suffix = event.status === "running" ? theme.fg("warning", " running") : "";
|
|
1028
|
-
lines.push(bounded(`${theme.fg("borderMuted", "\u251C\u2500")} ${statusGlyph(event, theme)} ${title}${args}${suffix}`, width));
|
|
1029
|
-
if (event.output && event.status !== "error" && event.name === "bash") {
|
|
1030
|
-
const outputLines = event.output.replace(/\s+$/, "").split(/\r?\n/);
|
|
1031
|
-
const visible = outputLines.slice(-TOOL_PREVIEW_LINES);
|
|
1032
|
-
const hidden = Math.max(0, outputLines.length - visible.length);
|
|
1033
|
-
for (const outputLine of visible) {
|
|
1034
|
-
for (const wrapped of renderWrapped(theme.fg("toolOutput", outputLine), Math.max(1, width - 4))) {
|
|
1035
|
-
lines.push(railLine(` ${wrapped}`, width, theme));
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
if (hidden > 0) lines.push(railLine(theme.fg("dim", ` \u2026 ${hidden} earlier lines \xB7 x to expand`), width, theme));
|
|
1039
|
-
const duration = toolDuration(event);
|
|
1040
|
-
lines.push(railLine(theme.fg("dim", ` Took${duration ? ` ${duration}` : ""}`), width, theme));
|
|
1041
|
-
} else if (event.output && event.status !== "error") {
|
|
1042
|
-
const summary = truncateToWidth(event.output.replace(/\s+/g, " ").trim(), Math.max(1, width - 18), "\u2026");
|
|
1043
|
-
if (summary) lines.push(railLine(theme.fg("dim", ` ${summary} \xB7 x to expand`), width, theme));
|
|
1044
|
-
}
|
|
1045
|
-
if (event.error) {
|
|
1046
|
-
for (const errorLine of renderWrapped(event.error, Math.max(1, width - 4))) {
|
|
1047
|
-
lines.push(railLine(theme.fg("error", ` ${errorLine}`), width, theme));
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
continue;
|
|
1051
|
-
}
|
|
1052
|
-
if (event.kind === "notice") {
|
|
1053
|
-
const color = event.tone === "error" ? "error" : event.tone === "warning" ? "warning" : "dim";
|
|
1054
|
-
for (const noticeLine of renderWrapped(event.text, Math.max(1, width - 2))) {
|
|
1055
|
-
lines.push(railLine(theme.fg(color, noticeLine), width, theme));
|
|
1056
|
-
}
|
|
1057
|
-
continue;
|
|
1058
|
-
}
|
|
1059
|
-
const assistant = event.kind === "assistant";
|
|
1060
|
-
const label = assistant ? "Assistant" : "Supervisor";
|
|
1061
|
-
const marker = assistant ? theme.fg("accent", "\u25C6") : theme.fg("warning", "\u25C7");
|
|
1062
|
-
const model = assistant && event.model ? theme.fg("dim", ` \xB7 ${event.model}`) : "";
|
|
1063
|
-
lines.push(bounded(`${marker} ${theme.bold(label)}${model}`, width));
|
|
1064
|
-
if (assistant) {
|
|
1065
|
-
const rendered = new Markdown(event.text, 0, 0, markdownTheme).render(Math.max(1, width - 2));
|
|
1066
|
-
for (const markdownLine of rendered) lines.push(railLine(markdownLine, width, theme));
|
|
1067
|
-
} else {
|
|
1068
|
-
for (const userLine of renderWrapped(event.text, Math.max(1, width - 2))) {
|
|
1069
|
-
lines.push(railLine(userLine, width, theme));
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
lines.push(theme.fg("borderMuted", "\u2502"));
|
|
1073
|
-
}
|
|
1074
|
-
while (lines.length > 0 && visibleWidth(lines.at(-1) ?? "") === 1) lines.pop();
|
|
1075
|
-
return lines;
|
|
1076
|
-
}
|
|
1077
947
|
|
|
1078
948
|
// src/inspectors/types.ts
|
|
1079
949
|
var INSPECTOR_ACTIONS = ["inspector.open", "inspector.command", "inspector.status", "inspector.close"];
|
|
@@ -1265,6 +1135,7 @@ async function rewritePromptWithGuidance(input) {
|
|
|
1265
1135
|
});
|
|
1266
1136
|
const ctxThinking = input.ctx.getThinkingLevel?.();
|
|
1267
1137
|
const agent = new Agent({
|
|
1138
|
+
sessionId,
|
|
1268
1139
|
initialState: {
|
|
1269
1140
|
systemPrompt: [
|
|
1270
1141
|
"Rewrite one subagent authored task from Prompt Audit context.",
|
|
@@ -1359,9 +1230,10 @@ export {
|
|
|
1359
1230
|
resolveWorkflowForegroundSteeringTarget,
|
|
1360
1231
|
steerWorkflowRun,
|
|
1361
1232
|
steerWorkflowForegroundTarget,
|
|
1233
|
+
objectValue,
|
|
1234
|
+
safeTranscriptEvent,
|
|
1362
1235
|
readFleetTranscript,
|
|
1363
1236
|
readTranscriptRecords,
|
|
1364
|
-
renderFleetTranscript,
|
|
1365
1237
|
INSPECTOR_ACTIONS,
|
|
1366
1238
|
handleInspectorAction,
|
|
1367
1239
|
rewritePromptWithGuidance,
|
|
@@ -10,22 +10,27 @@ import {
|
|
|
10
10
|
drainOutstandingWork,
|
|
11
11
|
evaluateChildToolDiagnostic,
|
|
12
12
|
formatWatchdogCwdSection,
|
|
13
|
-
registerNativeSupervisorClient,
|
|
14
13
|
registerWaitTool,
|
|
15
14
|
resolveCurrentSessionId,
|
|
16
15
|
resolveWatchdogReviewModel,
|
|
17
16
|
startWatchdogDiffBaselineCapture
|
|
18
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-5Z7JAORM.js";
|
|
19
18
|
import {
|
|
20
|
-
MODEL_ONLY_TOOL,
|
|
21
19
|
agentStreamOptions,
|
|
22
20
|
opencodeSessionHeaders
|
|
23
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-DLVPMML3.js";
|
|
22
|
+
import {
|
|
23
|
+
registerNativeSupervisorClient
|
|
24
|
+
} from "./chunk-34TUUBRN.js";
|
|
25
|
+
import {
|
|
26
|
+
MODEL_ONLY_TOOL
|
|
27
|
+
} from "./chunk-HXRB42AF.js";
|
|
24
28
|
import {
|
|
25
29
|
inheritedNestedRouteOf
|
|
26
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-JH5H4CYJ.js";
|
|
27
31
|
import {
|
|
28
32
|
CHILD_WATCHDOG_STATUS_EVENT,
|
|
33
|
+
DEFAULT_WAIT_TOOL_NAME,
|
|
29
34
|
MISSING_STRUCTURED_ACCEPTANCE_REPORT_ERROR,
|
|
30
35
|
SUBAGENT_WATCHDOG_WARNING_TYPE,
|
|
31
36
|
appendPermissionAudit,
|
|
@@ -34,12 +39,14 @@ import {
|
|
|
34
39
|
getAgentDir,
|
|
35
40
|
permissionArgsPreview,
|
|
36
41
|
permissionDecision,
|
|
42
|
+
prepareStructuredOutputArguments,
|
|
43
|
+
setWaitToolName,
|
|
37
44
|
shouldBlockToolForBudget,
|
|
38
45
|
toolBudgetBlockedMessage,
|
|
39
46
|
toolBudgetSoftNudge,
|
|
40
47
|
validateAcceptanceReport,
|
|
41
48
|
validateStructuredOutputValue
|
|
42
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-XAC2XNAP.js";
|
|
43
50
|
import {
|
|
44
51
|
INTERCOM_SESSION_IDENTITY_EVENT
|
|
45
52
|
} from "./chunk-UQDHXMUG.js";
|
|
@@ -288,6 +295,7 @@ function createWatchdogPermissionArbiter(options = {}) {
|
|
|
288
295
|
].join("\n");
|
|
289
296
|
const tools = [tool];
|
|
290
297
|
agent = new Agent({
|
|
298
|
+
sessionId,
|
|
291
299
|
initialState: {
|
|
292
300
|
systemPrompt,
|
|
293
301
|
model: selection.model,
|
|
@@ -577,6 +585,11 @@ function modelBefore(messages, forkedAt) {
|
|
|
577
585
|
return void 0;
|
|
578
586
|
}
|
|
579
587
|
var LOADOUT_SECTIONS = /* @__PURE__ */ new Set(["tools", "rules", "docs", "skills", "advertised_subagents", "mcp_servers", "project_context"]);
|
|
588
|
+
function projectInstructionBlocks(section) {
|
|
589
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
590
|
+
for (const match of (section ?? "").matchAll(/<project_instructions\s+path=(["'])(.*?)\1\s*>[\s\S]*?<\/project_instructions>/gi)) blocks.set(match[2], match[0]);
|
|
591
|
+
return blocks;
|
|
592
|
+
}
|
|
580
593
|
function forkInstructions(input) {
|
|
581
594
|
const parent = getCurrentSystemMessage(input.parent);
|
|
582
595
|
const child = getCurrentSystemMessage(input.child);
|
|
@@ -589,6 +602,9 @@ function forkInstructions(input) {
|
|
|
589
602
|
for (const [name, value] of Object.entries(child?.sections ?? {})) {
|
|
590
603
|
if (!LOADOUT_SECTIONS.has(name) && value && parent?.sections?.[name] !== value) parts.push(value);
|
|
591
604
|
}
|
|
605
|
+
const parentFiles = projectInstructionBlocks(parent?.sections?.project_context);
|
|
606
|
+
const missingFiles = [...projectInstructionBlocks(child?.sections?.project_context)].filter(([filePath]) => !parentFiles.has(filePath)).map(([, block]) => block);
|
|
607
|
+
if (missingFiles.length > 0) parts.push(["Project instructions for your working folder, which the parent's prompt does not include:", ...missingFiles].join("\n\n"));
|
|
592
608
|
if (input.boundary) parts.push(input.boundary);
|
|
593
609
|
return `<subagent_instructions>
|
|
594
610
|
${parts.join("\n\n")}
|
|
@@ -786,6 +802,7 @@ function registerStructuredOutputTool(pi, structured) {
|
|
|
786
802
|
label: "Structured Output",
|
|
787
803
|
description: "Submit the required final structured output for this subagent step. This terminates the step.",
|
|
788
804
|
parameters,
|
|
805
|
+
prepareArguments: (args) => prepareStructuredOutputArguments(structured.schema, args),
|
|
789
806
|
async execute(_id, params) {
|
|
790
807
|
const validation = await validateStructuredOutputValue(structured.schema, params.value);
|
|
791
808
|
if (validation.status === "invalid") {
|
|
@@ -839,6 +856,7 @@ function registerSubagentPromptRuntime(pi, config, drainObservation) {
|
|
|
839
856
|
} }
|
|
840
857
|
};
|
|
841
858
|
const nestedRootRunId = inheritedNestedRouteOf(config)?.rootRunId;
|
|
859
|
+
setWaitToolName(config.waitTool.name ?? DEFAULT_WAIT_TOOL_NAME);
|
|
842
860
|
if (typeof pi.registerTool === "function") registerWaitTool(pi, waitState, config.waitTool.enabled, void 0, config.waitTool.defaultTimeoutMs, { nestedRootRunId }, () => config.hasPendingSupervisorRequest?.() === true);
|
|
843
861
|
const supervisorMetadata = childSupervisorMetadata(config);
|
|
844
862
|
let nativeSupervisorClientRegistered = false;
|
|
@@ -112,7 +112,21 @@ import { randomUUID } from "node:crypto";
|
|
|
112
112
|
var OUTPUT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
113
113
|
var PLACEHOLDER_PATTERN = /\{(?:task|previous|outputs\.([A-Za-z_][A-Za-z0-9_]*))\}/g;
|
|
114
114
|
var CHILD_FIELDS = ["cwd", "model"];
|
|
115
|
-
var
|
|
115
|
+
var SHARED_CHILD_CONTROLS = /* @__PURE__ */ new Set(["worktree", "baseRef", "context", "skill", "fast", "agentScope", "outputMode", "outputSchema", "agentContract", "acceptance", "gate", "toolBudget", "toolTimeoutMs", "control"]);
|
|
116
|
+
var SCRIPT_CHILD_FIELDS = /* @__PURE__ */ new Set(["key", "label", "phase", "resume", "async", "timeoutMs"]);
|
|
117
|
+
function unsupportedChildFieldAdvice(fields, scripts) {
|
|
118
|
+
const perChild = scripts ? "use workflow: true with runs.all items" : "you need workflow scripts, which disabledFeatures has turned off";
|
|
119
|
+
const advice = [];
|
|
120
|
+
const itemFields = fields.filter((field) => CHILD_FIELDS.includes(field));
|
|
121
|
+
if (itemFields.length > 0) advice.push(`Set ${itemFields.join(", ")} on each item, or on the subagent call itself to give every child the same value.`);
|
|
122
|
+
if (fields.includes("output")) advice.push(`For one shared output, set output on the subagent call itself: the workflow result is written there and each child gets its own file beside it. For exact or different per-child paths, ${perChild}. Do not drop output if you need durable child files.`);
|
|
123
|
+
const shared = fields.filter((field) => SHARED_CHILD_CONTROLS.has(field));
|
|
124
|
+
if (shared.length > 0) advice.push(`Set ${shared.join(", ")} on the subagent call itself to give every child the same value; for different values per child, ${perChild}.`);
|
|
125
|
+
const scriptOnly = fields.filter((field) => SCRIPT_CHILD_FIELDS.has(field));
|
|
126
|
+
if (scriptOnly.length > 0) advice.push(`For per-child ${scriptOnly.join(", ")}, ${perChild}.`);
|
|
127
|
+
advice.push("No child was launched.");
|
|
128
|
+
return advice.join(" ");
|
|
129
|
+
}
|
|
116
130
|
function isPlainRecord(value) {
|
|
117
131
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
118
132
|
const prototype = Object.getPrototypeOf(value);
|
|
@@ -122,10 +136,10 @@ function nonEmptyString(value, path) {
|
|
|
122
136
|
if (typeof value !== "string" || !value.trim()) throw new Error(`${path} must be a non-empty string.`);
|
|
123
137
|
return value;
|
|
124
138
|
}
|
|
125
|
-
function exactFields(value, path, allowed, hint) {
|
|
139
|
+
function exactFields(value, path, allowed, hint, scripts) {
|
|
126
140
|
if (!isPlainRecord(value)) throw new Error(`${path} must be an object.`);
|
|
127
141
|
const unsupported = Object.keys(value).filter((key) => !allowed.includes(key));
|
|
128
|
-
if (unsupported.length > 0) throw new Error(`${path} contains unsupported fields: ${unsupported.join(", ")}. ${hint}`);
|
|
142
|
+
if (unsupported.length > 0) throw new Error(`${path} contains unsupported fields: ${unsupported.join(", ")}. ${hint} ${unsupportedChildFieldAdvice(unsupported, scripts)}`);
|
|
129
143
|
return value;
|
|
130
144
|
}
|
|
131
145
|
function compileTemplate(template, scope) {
|
|
@@ -184,11 +198,11 @@ var SETTLE_HELPER = [
|
|
|
184
198
|
' return new Error(label + ": " + children.filter(function (child) { return !child.ok; }).map(function (child) { return child.key + " (" + child.agent + ") failed" + (child.error ? ": " + child.error : ""); }).join("; "));',
|
|
185
199
|
"}"
|
|
186
200
|
].join("\n");
|
|
187
|
-
function buildTasksScript(steps, originalTask) {
|
|
201
|
+
function buildTasksScript(steps, originalTask, scripts) {
|
|
188
202
|
if (!Array.isArray(steps) || steps.length === 0) throw new Error("tasks must be a non-empty array of { agent, task } items.");
|
|
189
203
|
const children = steps.map((item, index) => {
|
|
190
204
|
const path = `tasks[${index}]`;
|
|
191
|
-
const record = exactFields(item, path, ["agent", "task", ...CHILD_FIELDS],
|
|
205
|
+
const record = exactFields(item, path, ["agent", "task", ...CHILD_FIELDS], "Each tasks item accepts agent and task, plus optional cwd and model.", scripts);
|
|
192
206
|
const agent = nonEmptyString(record.agent, `${path}.agent`);
|
|
193
207
|
const task = nonEmptyString(record.task, `${path}.task`);
|
|
194
208
|
const taskExpression = compileTemplate(task, {
|
|
@@ -219,18 +233,18 @@ function buildChainScript(steps, originalTask) {
|
|
|
219
233
|
let stepChildren;
|
|
220
234
|
let outputName;
|
|
221
235
|
if (isPlainRecord(step) && Object.hasOwn(step, "parallel")) {
|
|
222
|
-
const record = exactFields(step, path, ["parallel"],
|
|
236
|
+
const record = exactFields(step, path, ["parallel"], "A parallel step accepts only parallel; as is supported on sequential steps only.", false);
|
|
223
237
|
const items = record.parallel;
|
|
224
238
|
if (!Array.isArray(items) || items.length === 0) throw new Error(`${path}.parallel must be a non-empty array of { agent, task } items.`);
|
|
225
239
|
stepChildren = items.map((item, itemIndex) => {
|
|
226
240
|
const itemPath = `${path}.parallel[${itemIndex}]`;
|
|
227
|
-
const itemRecord = exactFields(item, itemPath, ["agent", "task", ...CHILD_FIELDS],
|
|
241
|
+
const itemRecord = exactFields(item, itemPath, ["agent", "task", ...CHILD_FIELDS], "Each parallel item accepts agent and task, plus optional cwd and model.", false);
|
|
228
242
|
const agent = nonEmptyString(itemRecord.agent, `${itemPath}.agent`);
|
|
229
243
|
const task = nonEmptyString(itemRecord.task, `${itemPath}.task`);
|
|
230
244
|
return { key: `step-${number}-${itemIndex + 1}`, agent, fields: childFields(itemRecord, itemPath), taskExpression: compileTemplate(task, { path: `${itemPath}.task`, hasOriginalTask, previous, outputs }) };
|
|
231
245
|
});
|
|
232
246
|
} else {
|
|
233
|
-
const record = exactFields(step, path, ["agent", "task", "as", ...CHILD_FIELDS],
|
|
247
|
+
const record = exactFields(step, path, ["agent", "task", "as", ...CHILD_FIELDS], "A sequential step accepts agent, task, as, cwd and model; a parallel step accepts only parallel.", false);
|
|
234
248
|
const agent = nonEmptyString(record.agent, `${path}.agent`);
|
|
235
249
|
let task;
|
|
236
250
|
if (record.task === void 0) {
|
|
@@ -256,8 +270,8 @@ function buildChainScript(steps, originalTask) {
|
|
|
256
270
|
lines.push("return { ok: true, children };");
|
|
257
271
|
return lines.join("\n");
|
|
258
272
|
}
|
|
259
|
-
function buildStructuredWorkflowScript(kind, steps, originalTask) {
|
|
260
|
-
return kind === "tasks" ? buildTasksScript(steps, originalTask) : buildChainScript(steps, originalTask);
|
|
273
|
+
function buildStructuredWorkflowScript(kind, steps, originalTask, scripts) {
|
|
274
|
+
return kind === "tasks" ? buildTasksScript(steps, originalTask, scripts) : buildChainScript(steps, originalTask);
|
|
261
275
|
}
|
|
262
276
|
|
|
263
277
|
// src/workflows/workflow-resources.ts
|
|
@@ -375,9 +389,9 @@ function resolveRunCi(args) {
|
|
|
375
389
|
}
|
|
376
390
|
function resolveParallel(args) {
|
|
377
391
|
const unsupported = Object.keys(args).filter((key) => key !== "tasks");
|
|
378
|
-
if (unsupported.length > 0) return { error: `workflow 'parallel' args contain unsupported fields: ${unsupported.join(", ")}. Pass args.tasks: [{ agent, task, cwd?, model? }, ...]
|
|
392
|
+
if (unsupported.length > 0) return { error: `workflow 'parallel' args contain unsupported fields: ${unsupported.join(", ")}. Pass args.tasks: [{ agent, task, cwd?, model? }, ...]. ${unsupportedChildFieldAdvice(unsupported, true)}` };
|
|
379
393
|
try {
|
|
380
|
-
return { script: buildStructuredWorkflowScript("tasks", args.tasks, void 0) };
|
|
394
|
+
return { script: buildStructuredWorkflowScript("tasks", args.tasks, void 0, true) };
|
|
381
395
|
} catch (error) {
|
|
382
396
|
return { error: `workflow 'parallel' args.${error instanceof Error ? error.message : String(error)}` };
|
|
383
397
|
}
|
|
@@ -415,7 +429,7 @@ function resolveStructuredWorkflowResource(input) {
|
|
|
415
429
|
validatePlainJson(task, "task");
|
|
416
430
|
}
|
|
417
431
|
if (jsonByteLength({ [kind]: steps, task }) > MAX_ARGS_BYTES) return { ok: false, error: `${kind} input exceeds ${MAX_ARGS_BYTES} bytes.` };
|
|
418
|
-
const script = buildStructuredWorkflowScript(kind, JSON.parse(JSON.stringify(steps)), task);
|
|
432
|
+
const script = buildStructuredWorkflowScript(kind, JSON.parse(JSON.stringify(steps)), task, false);
|
|
419
433
|
return { ok: true, resource: issueWorkflowResource(kind, STRUCTURED_WORKFLOW_RESOURCE_VERSION, script) };
|
|
420
434
|
} catch (error) {
|
|
421
435
|
return { ok: false, error: error instanceof Error ? error.message.slice(0, 4096) : "Structured workflow resolution failed." };
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
} from "./chunk-7J4ZXMY7.js";
|
|
4
4
|
import {
|
|
5
5
|
getProjectSubagentsDir
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LYKG4FKH.js";
|
|
7
7
|
import {
|
|
8
8
|
getPiSpawnCommand,
|
|
9
9
|
writeAtomicJson
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-XAC2XNAP.js";
|
|
11
11
|
|
|
12
12
|
// src/inspectors/herdr/project-panes.ts
|
|
13
13
|
import * as fs from "node:fs";
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
rewriteSubagentPrompt
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OGPOCGWX.js";
|
|
4
4
|
import {
|
|
5
5
|
package_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import
|
|
6
|
+
} from "./chunk-TM2K53NX.js";
|
|
7
|
+
import {
|
|
8
|
+
WATCHDOG_DIFF_TOOL_NAME,
|
|
9
|
+
captureWatchdogDiffBaseline,
|
|
10
|
+
createWatchdogDiffTool
|
|
11
|
+
} from "./chunk-5Z7JAORM.js";
|
|
12
|
+
import "./chunk-DLVPMML3.js";
|
|
13
|
+
import "./chunk-34TUUBRN.js";
|
|
8
14
|
import {
|
|
9
15
|
MODEL_ONLY_TOOL
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-HXRB42AF.js";
|
|
17
|
+
import "./chunk-RMSABUN3.js";
|
|
12
18
|
import {
|
|
13
19
|
appendAgentRefinementOverlay
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-5OD3OWTE.js";
|
|
21
|
+
import "./chunk-JH5H4CYJ.js";
|
|
22
|
+
import "./chunk-LYKG4FKH.js";
|
|
17
23
|
import "./chunk-NIXWDZZV.js";
|
|
18
|
-
import "./chunk-
|
|
24
|
+
import "./chunk-JAXVBXGF.js";
|
|
19
25
|
import "./chunk-BGIYHF2W.js";
|
|
20
26
|
import {
|
|
21
27
|
assertNoToolModifierEntries
|
|
22
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-IH7LQVEE.js";
|
|
23
29
|
import "./chunk-CTPAE36Y.js";
|
|
24
30
|
import {
|
|
25
31
|
HERDR_PI_MAX_FRAME_BYTES,
|
|
@@ -37,7 +43,7 @@ import {
|
|
|
37
43
|
discoverAgents,
|
|
38
44
|
resolveExistingReadPaths,
|
|
39
45
|
resolveSkills
|
|
40
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-XAC2XNAP.js";
|
|
41
47
|
import "./chunk-UQDHXMUG.js";
|
|
42
48
|
import "./chunk-QXASAHIA.js";
|
|
43
49
|
import "./chunk-YFCK7H2S.js";
|
|
@@ -240,9 +246,11 @@ ${resolvedSystemPrompt}` } : void 0;
|
|
|
240
246
|
const resolved = resolveRemoteHerdrResources(process.cwd(), { agent: resources.agent, ...resources.skills ? { skills: resources.skills } : {}, ...resources.toolCeiling ? { toolCeiling: resources.toolCeiling } : {}, ...resources.reads !== void 0 ? { reads: resources.reads } : {} }, context ? pi.getActiveTools() : []);
|
|
241
247
|
resolvedSystemPrompt = resolved.systemPrompt;
|
|
242
248
|
resolvedContextPolicy = resolved;
|
|
249
|
+
if (resolved.tools.includes(WATCHDOG_DIFF_TOOL_NAME) && !pi.getAllTools().some((tool) => tool.name === WATCHDOG_DIFF_TOOL_NAME)) pi.registerTool(createWatchdogDiffTool(captureWatchdogDiffBaseline(process.cwd()), { workingTreeAtLaunch: true }));
|
|
243
250
|
pi.setActiveTools(resolved.tools);
|
|
244
251
|
const acknowledged = context ? pi.getActiveTools() : [];
|
|
245
|
-
|
|
252
|
+
const missing = resolved.tools.filter((tool) => !acknowledged.includes(tool)), extra = acknowledged.filter((tool) => !resolved.tools.includes(tool));
|
|
253
|
+
if (missing.length || extra.length) throw new Error(`Remote Pi did not apply the resolved active-tool set exactly (${[...missing.length ? [`not available: ${missing.join(", ")}`] : [], ...extra.length ? [`unexpected: ${extra.join(", ")}`] : []].join("; ")}).`);
|
|
246
254
|
configured = true;
|
|
247
255
|
send({ type: "configured", requestId: frame.requestId, nativeSessionId, agent: resolved.agent, skills: resolved.skills, model: context?.model?.provider && context.model.id ? `${context.model.provider}/${context.model.id}` : void 0, tools: acknowledged });
|
|
248
256
|
continue;
|
|
@@ -258,9 +266,12 @@ ${resolvedSystemPrompt}` } : void 0;
|
|
|
258
266
|
send({ type: "prepared", requestId: frame.requestId, nativeSessionId });
|
|
259
267
|
}
|
|
260
268
|
} catch (error) {
|
|
269
|
+
context?.ui?.notify(`pi-subagents bridge: ${error.message}`, "error");
|
|
261
270
|
socket.destroy(error);
|
|
262
271
|
}
|
|
263
272
|
});
|
|
273
|
+
socket.on("error", () => {
|
|
274
|
+
});
|
|
264
275
|
socket.on("close", () => {
|
|
265
276
|
if (client === socket) client = void 0;
|
|
266
277
|
});
|