@xzzpig/pi-subagents 0.24.2 → 0.25.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 +22 -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-XWWUDWUW.js → chunk-5YEOWNSD.js} +371 -135
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-4UH4WS4G.js → chunk-6MNRKUHY.js} +23 -12
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-CYY5UMJU.js → chunk-IJWITCC6.js} +411 -249
- package/bundle/{chunk-RU522D5W.js → chunk-IKFKH5EL.js} +369 -50
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-JEA2ZKUA.js → chunk-IUDEI6FJ.js} +35 -200
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-224WMDIV.js → chunk-KCJFGKVK.js} +350 -123
- 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-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-BQ2OAB4Q.js → chunk-OSVXFWPG.js} +67 -30
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -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-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/{chunk-O4D5PBVI.js → chunk-YWXILP5N.js} +3 -2
- 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 +56 -24
- 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 +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/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-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- 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,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core execution logic for running subagents
|
|
3
|
-
*/
|
|
4
1
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
5
2
|
import * as path from "node:path";
|
|
6
3
|
import { discoverAgents, formatUnknownAgentError, unknownAgentDiagnosticContext } from "../../agents/agents.js";
|
|
@@ -8,9 +5,10 @@ import { alignForkedSessionCwd } from "../../shared/fork-session-cwd.js";
|
|
|
8
5
|
import { buildEffectiveSystemPrompt } from "../shared/effective-system-prompt.js";
|
|
9
6
|
import { ensureArtifactsDir, formatOutputArtifactContent, getArtifactPaths, writeArtifact, writeMetadata, } from "../../shared/artifacts.js";
|
|
10
7
|
import { createChildTranscriptWriter } from "../../shared/child-transcript.js";
|
|
8
|
+
import { extractReportedProgress } from "../../shared/reported-progress.js";
|
|
11
9
|
import { DEFAULT_MAX_OUTPUT, INTERCOM_DETACH_REQUEST_EVENT, INTERCOM_DETACH_RESPONSE_EVENT, truncateOutput, } from "../../shared/types.js";
|
|
12
10
|
import { DEFAULT_CONTROL_CONFIG, buildControlEvent, claimControlNotification, deriveActivityState, shouldEmitOpenToolAttention, shouldNotifyControlEvent, } from "../shared/subagent-control.js";
|
|
13
|
-
import { getFinalOutput, findLatestSessionFile, detectSubagentError, hasEmptyTerminalAssistantResponse, formatEmptyTerminalAssistantResponseError, extractToolArgsPreview, assistantMessageError, extractTextFromContent, MAX_STREAMED_RECENT_TOOLS, boundStreamedRecentTools, boundStreamedRecentOutput, boundStreamedToolCalls, } from "../../shared/utils.js";
|
|
11
|
+
import { getFinalOutput, findLatestSessionFile, detectSubagentError, hasEmptyTerminalAssistantResponse, formatEmptyTerminalAssistantResponseError, getTerminalAssistantStopReason, TRUNCATED_RESPONSE_ERROR, extractToolArgsPreview, assistantMessageError, extractTextFromContent, MAX_STREAMED_RECENT_TOOLS, boundStreamedRecentTools, boundStreamedRecentOutput, boundStreamedToolCalls, } from "../../shared/utils.js";
|
|
14
12
|
import { resolveSkillsWithFallback } from "../../agents/skills.js";
|
|
15
13
|
import { createPartialOutputTracker, formatPartialOutput } from "../shared/partial-output.js";
|
|
16
14
|
import { effectiveToolTimeoutMs, formatToolTimeoutMessage, resolveToolTimeoutMs, toolTimeoutCallKey, toolTimeoutFromEnv } from "../shared/tool-timeout.js";
|
|
@@ -48,6 +46,7 @@ import { childSessionFactory, childSessionHasQueuedMessages, projectChildSession
|
|
|
48
46
|
import { reconcileAttemptUsage } from "../shared/usage-reconciliation.js";
|
|
49
47
|
import { clearProviderRetry, observeProviderDiagnostics, snapshotProviderDiagnostics } from "../../shared/provider-diagnostics.js";
|
|
50
48
|
import { isRexLocalMachine } from "../shared/rex-machine.js";
|
|
49
|
+
import { pauseForSupervisorWait, startPausableTimer } from "../shared/supervisor-wait-timer.js";
|
|
51
50
|
const artifactOutputByResult = new WeakMap();
|
|
52
51
|
const acceptanceOutputByResult = new WeakMap();
|
|
53
52
|
function emptyUsage() {
|
|
@@ -210,6 +209,8 @@ function captureStructuredDelegationProgressState(progress, result) {
|
|
|
210
209
|
recentOutput: [...progress.recentOutput],
|
|
211
210
|
recentTools: progress.recentTools.slice(-MAX_STREAMED_RECENT_TOOLS).map(({ tool, args }) => ({ tool, args })),
|
|
212
211
|
activityState: progress.activityState,
|
|
212
|
+
progressText: progress.progressText,
|
|
213
|
+
progressUpdatedAt: progress.progressUpdatedAt,
|
|
213
214
|
model: progress.model ?? result.model,
|
|
214
215
|
toolCount: progress.toolCount,
|
|
215
216
|
tokens: progress.tokens,
|
|
@@ -222,6 +223,8 @@ function structuredDelegationProgressChanged(previous, progress, result) {
|
|
|
222
223
|
|| previous.currentTool !== progress.currentTool
|
|
223
224
|
|| previous.currentToolArgs !== progress.currentToolArgs
|
|
224
225
|
|| previous.activityState !== progress.activityState
|
|
226
|
+
|| previous.progressText !== progress.progressText
|
|
227
|
+
|| previous.progressUpdatedAt !== progress.progressUpdatedAt
|
|
225
228
|
|| previous.model !== (progress.model ?? result.model)
|
|
226
229
|
|| previous.toolCount !== progress.toolCount
|
|
227
230
|
|| previous.tokens !== progress.tokens
|
|
@@ -248,6 +251,7 @@ function isCompleteUsageCounter(value) {
|
|
|
248
251
|
}
|
|
249
252
|
const STOPPED_BEFORE_COMPLETION_ERROR = "Subagent stopped before completion.";
|
|
250
253
|
const AFTER_COMPACTION_SETTLEMENT = Symbol("afterCompactionSettlement");
|
|
254
|
+
const REMAINING_TIMEOUT_MS = Symbol("remainingTimeoutMs");
|
|
251
255
|
async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared) {
|
|
252
256
|
const effectiveThinking = options.thinkingOverride ?? agent.thinking;
|
|
253
257
|
const modelArg = applyThinkingSuffix(model, effectiveThinking, options.thinkingOverride !== undefined);
|
|
@@ -465,6 +469,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
465
469
|
let toolAvailabilityError;
|
|
466
470
|
let abortedBySignal = options.signal?.aborted === true;
|
|
467
471
|
let afterCompactionSettlement = false;
|
|
472
|
+
let remainingTimeoutMs;
|
|
468
473
|
if (options.workflowChildPermitLaunch) {
|
|
469
474
|
const permitError = consumeWorkflowChildPermit(options.workflowChildPermitLaunch.permit, {
|
|
470
475
|
workflowRunId: options.workflowChildPermitLaunch.workflowRunId,
|
|
@@ -504,7 +509,8 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
504
509
|
let timeoutHardFinishTimer;
|
|
505
510
|
const clearTimeoutTimers = () => {
|
|
506
511
|
if (timeoutTimer) {
|
|
507
|
-
|
|
512
|
+
remainingTimeoutMs = timeoutTimer.remainingMs();
|
|
513
|
+
timeoutTimer.clear();
|
|
508
514
|
timeoutTimer = undefined;
|
|
509
515
|
}
|
|
510
516
|
if (timeoutHardFinishTimer) {
|
|
@@ -747,6 +753,8 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
747
753
|
return events;
|
|
748
754
|
};
|
|
749
755
|
let activeLongRunningNotified = false;
|
|
756
|
+
// Pi's parallel tool execution emits every tool_execution_start before the first result message,
|
|
757
|
+
// so results are matched to their call by toolCallId; the last-started slot covers events without one.
|
|
750
758
|
const pendingToolResultsByCallId = new Map();
|
|
751
759
|
let pendingToolResult;
|
|
752
760
|
// Pi host versions may represent one tool result as either a dedicated
|
|
@@ -894,12 +902,25 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
894
902
|
toolAttentionTarget.attentionEmitted = true;
|
|
895
903
|
const durationMs = Math.max(0, now - toolAttentionTarget.startedAt);
|
|
896
904
|
const toolCallId = toolAttentionTarget.key.startsWith("id:") ? toolAttentionTarget.key.slice(3) : undefined;
|
|
905
|
+
let hasCommandController = false;
|
|
906
|
+
// Runs from the 1 s activity timer, where a throw reaches Pi's uncaughtException handler and exits Pi.
|
|
907
|
+
if (toolCallId)
|
|
908
|
+
try {
|
|
909
|
+
hasCommandController = retainsChildCommand(supervisorChannelDir(options.runId, agent.name, options.index ?? 0), toolCallId);
|
|
910
|
+
}
|
|
911
|
+
catch (error) {
|
|
912
|
+
const message = `Could not read the command state of ${agent.name}; its command controls are not offered: ${error instanceof Error ? error.message : String(error)}`;
|
|
913
|
+
if (options.onWarning)
|
|
914
|
+
options.onWarning(message, "child-command-state");
|
|
915
|
+
else
|
|
916
|
+
console.warn(`[pi-subagents] ${message}`);
|
|
917
|
+
}
|
|
897
918
|
return emitNeedsAttention(now, {
|
|
898
919
|
message: `${agent.name} has had tool '${toolAttentionTarget.tool}' open for ${Math.floor(durationMs / 1000)}s`,
|
|
899
920
|
reason: "tool_open_threshold",
|
|
900
921
|
currentTool: toolAttentionTarget.tool,
|
|
901
922
|
toolCallId,
|
|
902
|
-
hasCommandController
|
|
923
|
+
hasCommandController,
|
|
903
924
|
currentPath: toolAttentionTarget.path,
|
|
904
925
|
currentToolDurationMs: durationMs,
|
|
905
926
|
});
|
|
@@ -977,6 +998,14 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
977
998
|
result.toolBudget = toolBudgetState(options.toolBudget, Math.max(progress.toolCount, options.toolBudget.hard + 1), blockedTool);
|
|
978
999
|
}
|
|
979
1000
|
appendRecentOutput(progress, resultText.split("\n").slice(-10));
|
|
1001
|
+
// Pi 1.2+: a successful contact_supervisor progress_update call carries
|
|
1002
|
+
// its text back through the result message. Publish the matching
|
|
1003
|
+
// snapshot's text so the widget shows the latest successful update.
|
|
1004
|
+
const messageToolName = message.toolName;
|
|
1005
|
+
if (message.isError !== true && messageToolName === toolSnapshot?.tool && toolSnapshot?.progressText) {
|
|
1006
|
+
progress.progressText = toolSnapshot.progressText;
|
|
1007
|
+
progress.progressUpdatedAt = now;
|
|
1008
|
+
}
|
|
980
1009
|
if (toolSnapshot?.mutates && !budgetBlocked && message.role === "toolResult" && didMutatingToolFail(message)) {
|
|
981
1010
|
recordMutatingFailure(mutatingFailures, {
|
|
982
1011
|
tool: toolSnapshot.tool,
|
|
@@ -1087,6 +1116,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1087
1116
|
progress.durationMs = now - startTime;
|
|
1088
1117
|
progress.lastActivityAt = now;
|
|
1089
1118
|
updateActivityState(now);
|
|
1119
|
+
pauseForSupervisorWait(timeoutTimer, evt);
|
|
1090
1120
|
if (evt.type === "tool_execution_start") {
|
|
1091
1121
|
const toolArgs = evt.args && typeof evt.args === "object" && !Array.isArray(evt.args)
|
|
1092
1122
|
? evt.args
|
|
@@ -1106,7 +1136,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1106
1136
|
result.toolBudget = toolBudgetState(options.toolBudget, progress.toolCount, result.toolBudget?.blockedTool);
|
|
1107
1137
|
}
|
|
1108
1138
|
const mutates = isMutatingTool(evt.toolName, toolArgs, agent.mutationTools);
|
|
1109
|
-
pendingToolResult = { tool: evt.toolName ?? "tool", path: activeTool?.path, mutates, startedAt: now };
|
|
1139
|
+
pendingToolResult = { tool: evt.toolName ?? "tool", path: activeTool?.path, mutates, startedAt: now, progressText: extractReportedProgress(evt.toolName ?? "", evt.args) };
|
|
1110
1140
|
if (typeof evt.toolCallId === "string" && evt.toolCallId)
|
|
1111
1141
|
pendingToolResultsByCallId.set(evt.toolCallId, pendingToolResult);
|
|
1112
1142
|
fireUpdate();
|
|
@@ -1235,7 +1265,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1235
1265
|
activityTimer.unref?.();
|
|
1236
1266
|
}
|
|
1237
1267
|
if (attemptTimeout) {
|
|
1238
|
-
timeoutTimer =
|
|
1268
|
+
timeoutTimer = startPausableTimer(attemptTimeout.remainingMs, () => {
|
|
1239
1269
|
if (sessionSettled || lifecycleFinished || interruptedByControl || result.timedOut)
|
|
1240
1270
|
return;
|
|
1241
1271
|
result.timedOut = true;
|
|
@@ -1254,8 +1284,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1254
1284
|
settle(undefined, true);
|
|
1255
1285
|
}, 4000);
|
|
1256
1286
|
timeoutHardFinishTimer.unref?.();
|
|
1257
|
-
}
|
|
1258
|
-
timeoutTimer.unref?.();
|
|
1287
|
+
});
|
|
1259
1288
|
}
|
|
1260
1289
|
let toolTimeoutSequence = 0;
|
|
1261
1290
|
const activeToolTimeouts = new Map();
|
|
@@ -1295,7 +1324,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1295
1324
|
const terminateForToolTimeout = (message) => {
|
|
1296
1325
|
if (sessionSettled || lifecycleFinished || interruptedByControl || result.timedOut)
|
|
1297
1326
|
return;
|
|
1298
|
-
|
|
1327
|
+
timeoutTimer?.clear();
|
|
1299
1328
|
result.timedOut = true;
|
|
1300
1329
|
timeoutCause = message;
|
|
1301
1330
|
result.error = message;
|
|
@@ -1316,10 +1345,6 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1316
1345
|
const timeoutForTool = effectiveToolTimeoutMs(event.toolName, options.toolTimeoutMs);
|
|
1317
1346
|
if (timeoutForTool === undefined)
|
|
1318
1347
|
return;
|
|
1319
|
-
const elapsed = Date.now() - startTime;
|
|
1320
|
-
const runRemaining = attemptTimeout ? Math.max(0, attemptTimeout.remainingMs - elapsed) : undefined;
|
|
1321
|
-
if (runRemaining !== undefined && timeoutForTool >= runRemaining)
|
|
1322
|
-
return;
|
|
1323
1348
|
const key = toolTimeoutCallKey(event, ++toolTimeoutSequence);
|
|
1324
1349
|
const toolName = event.toolName;
|
|
1325
1350
|
const timer = setTimeout(() => {
|
|
@@ -1468,14 +1493,14 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1468
1493
|
const steer = created.steer.bind(created);
|
|
1469
1494
|
const followUp = created.followUp.bind(created);
|
|
1470
1495
|
created.steer = async (text) => {
|
|
1496
|
+
await steer(text);
|
|
1471
1497
|
if (cleanTerminalAssistantStopReceived || agentSettledReceived)
|
|
1472
1498
|
queuedDrainHold = true;
|
|
1473
|
-
return steer(text);
|
|
1474
1499
|
};
|
|
1475
1500
|
created.followUp = async (text) => {
|
|
1501
|
+
await followUp(text);
|
|
1476
1502
|
if (cleanTerminalAssistantStopReceived || agentSettledReceived)
|
|
1477
1503
|
queuedDrainHold = true;
|
|
1478
|
-
return followUp(text);
|
|
1479
1504
|
};
|
|
1480
1505
|
created.detached = detached;
|
|
1481
1506
|
unsubscribe = created.subscribe((event) => processEvent(event));
|
|
@@ -1524,9 +1549,9 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1524
1549
|
result.exitCode = exitCode;
|
|
1525
1550
|
result.providerDiagnostics = clearProviderRetry(result.providerDiagnostics);
|
|
1526
1551
|
progress.providerDiagnostics = result.providerDiagnostics;
|
|
1527
|
-
if (afterCompactionSettlement)
|
|
1552
|
+
if (afterCompactionSettlement)
|
|
1528
1553
|
result[AFTER_COMPACTION_SETTLEMENT] = true;
|
|
1529
|
-
|
|
1554
|
+
result[REMAINING_TIMEOUT_MS] = remainingTimeoutMs;
|
|
1530
1555
|
if (interruptedByControl) {
|
|
1531
1556
|
result.exitCode = 0;
|
|
1532
1557
|
result.interrupted = true;
|
|
@@ -1611,6 +1636,10 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1611
1636
|
? `${errInfo.errorType} failed (exit ${errInfo.exitCode}): ${errInfo.details}`
|
|
1612
1637
|
: `${errInfo.errorType} failed with exit code ${errInfo.exitCode}`;
|
|
1613
1638
|
}
|
|
1639
|
+
else if (!validatedStructuredOutput && getTerminalAssistantStopReason(messages) === "length") {
|
|
1640
|
+
result.exitCode = 1;
|
|
1641
|
+
result.error = TRUNCATED_RESPONSE_ERROR;
|
|
1642
|
+
}
|
|
1614
1643
|
}
|
|
1615
1644
|
progress.status = result.exitCode === 0 ? "completed" : "failed";
|
|
1616
1645
|
progress.durationMs = Date.now() - startTime;
|
|
@@ -1627,7 +1656,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
|
|
|
1627
1656
|
durationMs: progress.durationMs,
|
|
1628
1657
|
};
|
|
1629
1658
|
const remoteGitChanged = result.nativeMachine?.initialGit && result.nativeMachine.finalGit ? result.nativeMachine.initialGit.head !== result.nativeMachine.finalGit.head || result.nativeMachine.initialGit.dirty !== result.nativeMachine.finalGit.dirty : undefined;
|
|
1630
|
-
const mutationEvidence = result.nativeMachine && !isRexLocalMachine(options.machine) ? { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: remoteGitChanged === true, ...(remoteGitChanged === undefined ? { unavailable: "Remote Git before/after evidence was incomplete." } : {}) } : collectTrackedMutationEvidence(mutationSnapshot, mutationCwd);
|
|
1659
|
+
const mutationEvidence = result.nativeMachine && !isRexLocalMachine(options.machine) ? { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: remoteGitChanged === true, ...(remoteGitChanged === undefined ? { unavailable: "Remote Git before/after evidence was incomplete." } : {}) } : await collectTrackedMutationEvidence(mutationSnapshot, mutationCwd);
|
|
1631
1660
|
const acceptanceOutput = getFinalOutput(result.messages ?? []);
|
|
1632
1661
|
const structuredText = result.structuredOutput === undefined ? undefined : JSON.stringify(result.structuredOutput, null, 2);
|
|
1633
1662
|
let fullOutput = stripAcceptanceReport(acceptanceOutput);
|
|
@@ -1727,12 +1756,10 @@ function writeStructuredOutputArtifacts(runtime, value, acceptanceReport) {
|
|
|
1727
1756
|
// The captured value is already on the result; the file is observability only.
|
|
1728
1757
|
}
|
|
1729
1758
|
}
|
|
1730
|
-
/**
|
|
1731
|
-
* Run a subagent synchronously (blocking until complete)
|
|
1732
|
-
*/
|
|
1733
1759
|
async function runSyncCompletionInner(runtimeCwd, agents, agentName, task, options) {
|
|
1734
1760
|
const effectiveCwd = options.cwd ?? runtimeCwd;
|
|
1735
|
-
|
|
1761
|
+
// A placed child's cwd is a directory on its machine; only machine 'local' shares this disk.
|
|
1762
|
+
const cwdError = options.machine && !isRexLocalMachine(options.machine) ? undefined : preflightLaunchCwd(options.requestedCwd ?? effectiveCwd, effectiveCwd);
|
|
1736
1763
|
if (cwdError) {
|
|
1737
1764
|
return redactResultPrompt(withRunContext({
|
|
1738
1765
|
index: options.index ?? 0,
|
|
@@ -1863,6 +1890,7 @@ async function runSyncCompletionInner(runtimeCwd, agents, agentName, task, optio
|
|
|
1863
1890
|
scope: options.modelScope,
|
|
1864
1891
|
primaryModelFromParent: options.modelOverrideFromParent,
|
|
1865
1892
|
origin: options.modelOrigin ?? (options.modelOverrideFromParent ? "inherited" : "configured"),
|
|
1893
|
+
knownProviders: options.knownProviders,
|
|
1866
1894
|
});
|
|
1867
1895
|
try {
|
|
1868
1896
|
const model = applyThinkingSuffix(selectedModel, options.thinkingOverride ?? agent.thinking, options.thinkingOverride !== undefined);
|
|
@@ -2011,6 +2039,10 @@ async function runSyncCompletionInner(runtimeCwd, agents, agentName, task, optio
|
|
|
2011
2039
|
});
|
|
2012
2040
|
if (recovery.action === "resume") {
|
|
2013
2041
|
recoveryPrompt = recovery.prompt;
|
|
2042
|
+
// The retry gets the budget the first attempt left, so that attempt's supervisor waits stay uncounted.
|
|
2043
|
+
const remainingMs = attemptResult[REMAINING_TIMEOUT_MS];
|
|
2044
|
+
if (remainingMs !== undefined)
|
|
2045
|
+
attemptOptions.deadlineAt = Date.now() + remainingMs;
|
|
2014
2046
|
attemptNotes.push("[abort-recovery] compaction abort after useful progress; resuming the retained child session once on the same model.");
|
|
2015
2047
|
continue;
|
|
2016
2048
|
}
|
|
@@ -49,6 +49,7 @@ export async function rewritePromptWithGuidance(input) {
|
|
|
49
49
|
});
|
|
50
50
|
const ctxThinking = input.ctx.getThinkingLevel?.();
|
|
51
51
|
const agent = new Agent({
|
|
52
|
+
sessionId,
|
|
52
53
|
initialState: {
|
|
53
54
|
systemPrompt: [
|
|
54
55
|
"Rewrite one subagent authored task from Prompt Audit context.",
|
|
@@ -17,7 +17,7 @@ import type { ChildRuntimeConfig } from "../shared/child-runtime-config.ts";
|
|
|
17
17
|
import { type MissionLaunchBinding } from "../../missions/lifecycle.ts";
|
|
18
18
|
import { type WorkflowSteerOptions, type WorkflowSteerResult } from "../../workflows/scripted-workflow.ts";
|
|
19
19
|
import { type PreparedWorkflowResume, type WorkflowResumeRefusalReason } from "../../workflows/workflow-resume.ts";
|
|
20
|
-
import { type AcceptanceInput, type AgentContract, type ControlConfig, type Details, type ExtensionConfig, type IntercomBridgeConfig, type JsonSchemaObject, type MaxOutputConfig, type ResolvedControlConfig, type RunFanoutBudgetDescriptor, type SteeringRecoveryDescriptor, type SingleResult, type ToolBudgetConfig, type UsageBudgetConfig, type SubagentState, type ScheduleOrigin } from "../../shared/types.ts";
|
|
20
|
+
import { type AcceptanceInput, type AgentContract, type ControlConfig, type Details, type ExtensionConfig, type IntercomBridgeConfig, type JsonSchemaObject, type MaxOutputConfig, type ResolvedControlConfig, type RunFanoutBudgetDescriptor, type SteeringRecoveryDescriptor, type SingleResult, type ToolBudgetConfig, type UsageBudgetConfig, type SubagentState, type ScheduleOrigin, type RequiredRunnerLauncher } from "../../shared/types.ts";
|
|
21
21
|
export declare function unknownSubagentActionMessage(action: string, disabled?: DisabledFeatureSurface): string;
|
|
22
22
|
interface TaskParam {
|
|
23
23
|
agent: string;
|
|
@@ -49,6 +49,7 @@ export interface SubagentParamsLike {
|
|
|
49
49
|
index?: number;
|
|
50
50
|
toolCallId?: string;
|
|
51
51
|
childId?: string;
|
|
52
|
+
drain?: boolean;
|
|
52
53
|
view?: "fleet" | "transcript";
|
|
53
54
|
lines?: number;
|
|
54
55
|
topic?: string;
|
|
@@ -59,6 +60,7 @@ export interface SubagentParamsLike {
|
|
|
59
60
|
agent?: string;
|
|
60
61
|
task?: string;
|
|
61
62
|
capabilities?: boolean;
|
|
63
|
+
search?: string;
|
|
62
64
|
extensionBindings?: ExtensionBindings;
|
|
63
65
|
/** Retained async child run id. Valid only on workflow runs.run items. */
|
|
64
66
|
resume?: string;
|
|
@@ -122,6 +124,7 @@ export interface SubagentParamsLike {
|
|
|
122
124
|
machine?: string;
|
|
123
125
|
/** Internal: the typed cwd when a machine is set, kept as a remote path and never resolved locally. */
|
|
124
126
|
machineCwd?: string;
|
|
127
|
+
requireLauncher?: RequiredRunnerLauncher;
|
|
125
128
|
maxOutput?: MaxOutputConfig;
|
|
126
129
|
artifacts?: boolean;
|
|
127
130
|
includeProgress?: boolean;
|
|
@@ -205,7 +208,7 @@ interface ExecutorDeps {
|
|
|
205
208
|
}
|
|
206
209
|
export declare function removeForegroundControlIfIdle(state: SubagentState, runId: string, trackRetainedNestedRoute?: (rootRunId: string) => void): boolean;
|
|
207
210
|
export declare function promptAuditRedoParams(value: unknown, rewrittenTask: string): SubagentParamsLike;
|
|
208
|
-
export declare function readNestedRecoveryDescriptor(
|
|
211
|
+
export declare function readNestedRecoveryDescriptor(rootRunId: string, runId: string, agent: string): SteeringRecoveryDescriptor | undefined;
|
|
209
212
|
export declare function foregroundResultIntercomStatus(result: SingleResult): ReturnType<typeof resolveSubagentResultStatus>;
|
|
210
213
|
export declare function shouldSuppressRoutineResultIntercom(input: {
|
|
211
214
|
suppressRoutineResultIntercom?: boolean;
|
|
@@ -213,14 +216,6 @@ export declare function shouldSuppressRoutineResultIntercom(input: {
|
|
|
213
216
|
}): boolean;
|
|
214
217
|
export declare const DEFAULT_FOREGROUND_TIMEOUT_MS: number;
|
|
215
218
|
export { DEFAULT_ASYNC_TIMEOUT_MS };
|
|
216
|
-
/**
|
|
217
|
-
* Resolve the optional global default runtime deadline from extension config
|
|
218
|
-
* (`config.timeoutMs`). Returns undefined for unset or invalid values so callers
|
|
219
|
-
* fall back to the built-in defaults. "Invalid" covers non-positive-integer
|
|
220
|
-
* values and values above `MAX_TIMER_DELAY_MS`; the latter would overflow the
|
|
221
|
-
* Node.js timer and expire the run almost immediately instead of running long.
|
|
222
|
-
*/
|
|
223
|
-
export declare function resolveConfigDefaultTimeoutMs(raw: unknown): number | undefined;
|
|
224
219
|
export declare function resolveForegroundTimeout(params: SubagentParamsLike, defaultTimeoutMs?: number): {
|
|
225
220
|
timeoutMs?: number;
|
|
226
221
|
error?: string;
|