@vicary/pi-subagents 0.84.0 → 0.86.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-VQVVHSY6.js → chunk-2DITXA3H.js} +22 -11
- package/bundle/{chunk-V2BZYLEP.js → chunk-374MZFF4.js} +7 -2
- package/bundle/{chunk-4E7BKDTX.js → chunk-3RKFH2UZ.js} +11 -156
- package/bundle/{chunk-F4ASL6OV.js → chunk-5H4BICQZ.js} +1 -1
- package/bundle/{chunk-PALJGGYC.js → chunk-6VD7BGIC.js} +6 -3
- package/bundle/{chunk-C5P5CHYK.js → chunk-77ASNIEM.js} +1 -1
- package/bundle/{chunk-PV63UFUR.js → chunk-7QA7ZA46.js} +183 -28
- package/bundle/{chunk-NKQ6JNAS.js → chunk-7ZUFN6ME.js} +2 -1
- package/bundle/{chunk-L3WFKBEI.js → chunk-BGXEAYUM.js} +247 -153
- package/bundle/{chunk-J5YL7LYR.js → chunk-BU6PFPVX.js} +59 -27
- package/bundle/{chunk-7BWGNDNK.js → chunk-CJHFDQFJ.js} +196 -1183
- package/bundle/{chunk-DZDETGRJ.js → chunk-DD22RXYJ.js} +259 -216
- package/bundle/{chunk-CGN2TVE7.js → chunk-GJGTMLPE.js} +322 -18
- package/bundle/{chunk-XDQORLZ5.js → chunk-GLVJMI6R.js} +15 -6
- package/bundle/{chunk-D3JAFGMO.js → chunk-GRJHIXYF.js} +1 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-LFDBD4PW.js → chunk-LGINOOY5.js} +2 -2
- package/bundle/{chunk-G2Z6ZH26.js → chunk-NAFLUJ26.js} +1 -1
- package/bundle/{chunk-2DHZTCOL.js → chunk-PYOAIN3V.js} +2 -2
- package/bundle/{chunk-RSLHTEQV.js → chunk-QFLPV64W.js} +324 -111
- package/bundle/{chunk-LNRJCP2Y.js → chunk-QGO6HXHG.js} +417 -242
- package/bundle/{chunk-2S4K53MV.js → chunk-S2Q75LP3.js} +1 -1
- package/bundle/{chunk-NENDSQUY.js → chunk-UR7OW5S7.js} +9 -6
- package/bundle/{chunk-RWPNQZHS.js → chunk-WHC2XHGF.js} +217 -106
- package/bundle/{chunk-AKOIVLA5.js → chunk-WN2E5XHN.js} +135 -77
- package/bundle/{chunk-4NIY3BE6.js → chunk-XOFYXQKZ.js} +2 -2
- package/bundle/{chunk-2D52JFLF.js → chunk-YK3QYNLE.js} +41 -117
- package/bundle/chunk-ZPY5QZCS.js +1067 -0
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +24 -3
- package/docs/configuration.md +9 -9
- package/docs/extension-api.md +16 -1
- package/docs/observability.md +1 -1
- package/docs/tool-reference.md +3 -1
- package/docs/workflows.md +31 -3
- package/package.json +2 -2
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +8 -3
- package/src/extension/schemas.js +6 -4
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +35 -12
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +5 -10
- package/src/runs/background/async-execution.js +63 -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 +112 -39
- package/src/runs/background/async-retention.js +6 -1
- package/src/runs/background/auto-drain.d.ts +0 -1
- package/src/runs/background/auto-drain.js +7 -6
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +0 -1
- package/src/runs/background/run-child-session.js +1 -1
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +15 -12
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +7 -8
- package/src/runs/foreground/subagent-executor.js +113 -44
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +1 -1
- package/src/runs/shared/child-session.js +21 -2
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/types.d.ts +90 -65
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +161 -66
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +241 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
|
@@ -5,7 +5,7 @@ import { discoverAgents, findBlockingAgentDiagnostic, formatAvailableAgentLines,
|
|
|
5
5
|
import { getArtifactsDir, getProjectArtifactPackagingWarning, getProjectSubagentsDir } from "../../shared/artifacts.js";
|
|
6
6
|
import { writeAtomicJson } from "../../shared/atomic-json.js";
|
|
7
7
|
import { createCapacityResilientJsonWriter } from "../../shared/capacity-resilient-json.js";
|
|
8
|
-
import {
|
|
8
|
+
import { reportSessionWarning } from "../../shared/session-warnings.js";
|
|
9
9
|
import { resolveEffectiveThinking, toModelInfo } from "../../shared/model-info.js";
|
|
10
10
|
import { beginForegroundChild, finishForegroundChild, foregroundSchedulingSettled, settleForegroundSchedulingOwner, updateForegroundChild, } from "./foreground-control.js";
|
|
11
11
|
import { getLivePromptAudit, rewritePromptWithGuidance, updateLiveEffectivePrompt } from "./prompt-audit.js";
|
|
@@ -15,6 +15,7 @@ import { handleManagementAction } from "../../agents/agent-management.js";
|
|
|
15
15
|
import { handleRefinementAction } from "../../agents/agent-refinements.js";
|
|
16
16
|
import { buildDoctorReport } from "../../extension/doctor.js";
|
|
17
17
|
import { readSubagentGuide } from "../../extension/subagent-guide.js";
|
|
18
|
+
import { approveWorkflowChildLaunch } from "../../extension/subagent-launch-tool.js";
|
|
18
19
|
import { isWorkflowScriptPath, normalizePublicSubagentExecution, validateWorkflowCapacityOverrides } from "../../extension/public-execution.js";
|
|
19
20
|
import { readReplyWorkflowScript } from "../../extension/reply-workflow-script.js";
|
|
20
21
|
import { disabledFeatureNotice, disabledFeatureSectionNotice, disabledFeatureUseError, resolveDisabledFeatureSurface } from "../../shared/disabled-features.js";
|
|
@@ -29,7 +30,7 @@ import { formatRetainedChildren, listRetainedChildren } from "../background/reta
|
|
|
29
30
|
import { resolveModelScopesForAgent } from "../shared/model-scope.js";
|
|
30
31
|
import { getStepAgents, isParallelStep, isDynamicParallelStep, resolveExistingReadPaths, } from "../../shared/settings.js";
|
|
31
32
|
import { normalizeSkillInput } from "../../agents/skills.js";
|
|
32
|
-
import { buildAsyncRunnerSteps,
|
|
33
|
+
import { buildAsyncRunnerSteps, executeAsyncChain, executeAsyncSingle, formatAsyncStartedMessage, isAsyncAvailable, workflowAwaitedAsyncResultPath } from "../background/async-execution.js";
|
|
33
34
|
import { updateActiveRunIndex } from "../background/active-run-index.js";
|
|
34
35
|
import { steeringReceipt } from "../background/steering.js";
|
|
35
36
|
import { acquireActiveAsyncCapacity, ActiveAsyncCapacityError, getActiveAsyncCapacitySnapshot, resolveAbandonedSlotReleaseAfterMs, resolveMaxActiveAsyncRunsPerSession, transferActiveAsyncCapacity } from "../background/active-async-capacity.js";
|
|
@@ -37,7 +38,7 @@ import { isScheduledRunAction } from "../background/scheduled-runs.js";
|
|
|
37
38
|
import { encodeIndexSegment } from "../background/index-segment.js";
|
|
38
39
|
import { enqueueChainAppendRequest, readPendingChainAppendRequests, runnerStepOutputNames } from "../background/chain-append.js";
|
|
39
40
|
import { ChainOutputValidationError, validateChainOutputBindingsWithContext } from "../shared/chain-outputs.js";
|
|
40
|
-
import { acceptanceHasTypedVerify, normalizeGateAcceptance, resolveAcceptanceReportMode, TYPED_VERIFY_OUTPUT_SCHEMA_CONFLICT, validateAcceptanceInput, validateExecutionAcceptance, validateExecutionAcceptancePolicy } from "../shared/acceptance.js";
|
|
41
|
+
import { acceptanceHasTypedVerify, normalizeAcceptanceInput, normalizeGateAcceptance, resolveAcceptanceReportMode, TYPED_VERIFY_OUTPUT_SCHEMA_CONFLICT, validateAcceptanceInput, validateExecutionAcceptance, validateExecutionAcceptancePolicy } from "../shared/acceptance.js";
|
|
41
42
|
import { canPreferFork, createForkContextResolver, resolveSubagentLaunchContext } from "../../shared/fork-context.js";
|
|
42
43
|
import { createPrunedForkSessionWriter } from "../../shared/pruned-fork.js";
|
|
43
44
|
import { resolveCurrentSessionId } from "../../shared/session-identity.js";
|
|
@@ -84,7 +85,7 @@ import { getExternalJobProvider } from "../../api/external-job-provider.js";
|
|
|
84
85
|
import { externalJobFollowUpRequestDigest, externalJobFollowUpRequestId, externalJobFollowUpRunId, externalJobPromptDigest, externalJobStableJson } from "../shared/external-job-runner.js";
|
|
85
86
|
import { externalCliReceiptMetadata, normalizeExternalCliRunnerStatus } from "../shared/external-cli-contract.js";
|
|
86
87
|
import { formatHerdrMachineRunnerUnsupported, resolveMachinePlacement } from "../shared/herdr-machine.js";
|
|
87
|
-
import { lookupRunnerLauncher, resolveAgentRunnerLauncher } from "../shared/runner-launcher.js";
|
|
88
|
+
import { checkRequiredRunnerLauncher, lookupRunnerLauncher, REQUIRE_LAUNCHER_SHAPE_ERROR, resolveAgentRunnerLauncher } from "../shared/runner-launcher.js";
|
|
88
89
|
import { applyForceTopLevelAsyncOverride } from "../background/top-level-async.js";
|
|
89
90
|
import { handleMissionAction, MISSION_ACTIONS } from "../../missions/actions.js";
|
|
90
91
|
import { attachMissionToLaunchResult, missionAcceptanceStatus, prepareMissionLaunch, writeMissionAsyncBinding } from "../../missions/lifecycle.js";
|
|
@@ -111,13 +112,14 @@ import { annotateWorkflowPreflightTrace, formatWorkflowPreflight, formatWorkflow
|
|
|
111
112
|
import { authorizeWorkflowResourceHost, claimWorkflowChildPermit, consumeWorkflowResourcePermit, validateWorkflowChildPermitRoot, } from "../../shared/workflow-child-permit.js";
|
|
112
113
|
import { deepFreezeWorkflowArgs, normalizeWorkflowArgs, resolveStructuredWorkflowResource, resolveWorkflowResource } from "../../workflows/workflow-resources.js";
|
|
113
114
|
import { writeWorkflowLaunchRecord } from "../../workflows/workflow-launch-record.js";
|
|
114
|
-
import { stableJsonDigest } from "../../shared/launch-contract.js";
|
|
115
|
+
import { agentDefinitionDigest, stableJsonDigest } from "../../shared/launch-contract.js";
|
|
115
116
|
import { cleanupWorktrees, createWorktrees, preflightWorktreeSource, withWorktreeTransaction, diffWorktrees, formatWorktreeDiffSummary, } from "../shared/worktree.js";
|
|
116
117
|
import { applyReviewedCleanupPlan, formatCleanupReceipt, loadReviewedCleanupPlan } from "../shared/worktree-cleanup-apply.js";
|
|
117
118
|
import { createWorktreeCleanupPlan, formatWorktreeCleanupPlan } from "../shared/worktree-cleanup-plan.js";
|
|
118
119
|
import { DIRS, DEFAULT_ARTIFACT_CONFIG, DEFAULT_MAX_OUTPUT, DEFAULT_FORK_PREAMBLE, SUBAGENT_ACTIONS, SUBAGENT_ASYNC_STARTED_EVENT, SUBAGENT_CHILD_STATUS_EVENT, SUBAGENT_CONTROL_EVENT, SUBAGENT_CONTROL_INTERCOM_EVENT, SUBAGENT_FOREGROUND_COMPLETE_EVENT, SUBAGENT_LIFECYCLE_ARTIFACT_VERSION, checkSubagentDepth, resolveChildMaxSubagentDepth, resolveCurrentMaxSubagentDepth, resolveMaxSubagentSpawnsPerRun, truncateOutput, wrapForkTask, } from "../../shared/types.js";
|
|
119
120
|
import { deriveChildSessionName } from "../../shared/child-session-name.js";
|
|
120
121
|
import { editDistance, hasSingleAdjacentTransposition } from "../../shared/edit-distance.js";
|
|
122
|
+
import { waitToolName } from "../../shared/wait-tool-name.js";
|
|
121
123
|
const MUTATING_MANAGEMENT_ACTIONS = new Set(["command.yield", "command.cancel", "create", "update", "delete", "eject", "disable", "enable", "reset", "grant-spawn-budget", "watchdog.configure", "mission.create", "mission.update", "mission.resolve-decision", "mission.attach-run", "mission.close", "inspector.open", "inspector.close", "project.open", "project.close", "worktree.discard", "worktree.cleanup", "lane.recordMerge", "lane.recordSupersession", "refine", "refine.rollback", "dismiss", "schedule.create", "schedule.pause", "schedule.resume", "schedule.run", "schedule.run-due", "schedule.delete"]);
|
|
122
124
|
const DESTRUCTIVE_MANAGEMENT_ACTIONS = new Set(["command.cancel", "delete", "eject", "disable", "reset", "mission.close", "worktree.discard", "refine.rollback", "inspector.close", "project.close", "stop", "interrupt", "schedule.delete"]);
|
|
123
125
|
function resolveSteerDeliveryMode(mode) {
|
|
@@ -177,6 +179,47 @@ function inheritedRunFanoutBudget(deps) {
|
|
|
177
179
|
function resolveRequestedCwd(runtimeCwd, requestedCwd) {
|
|
178
180
|
return requestedCwd ? path.resolve(runtimeCwd, requestedCwd) : runtimeCwd;
|
|
179
181
|
}
|
|
182
|
+
function workflowChildLaunchArgs(workflowRunId, key, request, scriptAgent, ctxCwd, discoverAgents) {
|
|
183
|
+
// prepareWorkflowLaunchParams turns a retained resume into { action: "resume", id, message }.
|
|
184
|
+
const resume = request.action === "resume" && typeof request.id === "string" ? request.id : undefined;
|
|
185
|
+
const agent = request.agent ?? scriptAgent;
|
|
186
|
+
const task = resume !== undefined ? request.message : request.task;
|
|
187
|
+
// cwd is where execute runs a fresh local child. A resumed child keeps its retained directory, and a
|
|
188
|
+
// placed child's cwd names a directory on its machine, so neither gets a local cwd here.
|
|
189
|
+
const scope = resolveExecutionAgentScope(request.agentScope);
|
|
190
|
+
const findAgent = (dir) => typeof agent === "string" ? resolveAgentName(agent, discoverAgents(dir, scope).agents).agent : undefined;
|
|
191
|
+
const ctxAgent = request.machine === undefined ? findAgent(ctxCwd) : undefined;
|
|
192
|
+
const placed = request.machine !== undefined || ctxAgent?.machine !== undefined;
|
|
193
|
+
const runCwd = resolveRequestedCwd(ctxCwd, request.cwd);
|
|
194
|
+
const cwd = resume === undefined && !placed ? runCwd : undefined;
|
|
195
|
+
// Mirrors applySingleAgentLaunchDefaults: the agent's defaultAcceptance applies only to a fresh launch with no
|
|
196
|
+
// acceptance (gate is already acceptance here). A resume's retained commands were in the call that first launched it.
|
|
197
|
+
const acceptanceInput = request.acceptance !== undefined || resume !== undefined
|
|
198
|
+
? request.acceptance
|
|
199
|
+
: (placed || runCwd === ctxCwd ? ctxAgent ?? findAgent(ctxCwd) : findAgent(runCwd))?.defaultAcceptance;
|
|
200
|
+
// An invalid acceptance fails the launch before anything runs. Verify commands run only at level
|
|
201
|
+
// "verified", which no inferred level reaches.
|
|
202
|
+
const acceptance = acceptanceInput !== undefined && validateAcceptanceInput(acceptanceInput).length === 0 ? normalizeAcceptanceInput(acceptanceInput) : undefined;
|
|
203
|
+
const commands = acceptance?.level === "verified" ? (acceptance.verify ?? []).map((verify) => ({
|
|
204
|
+
command: verify.command,
|
|
205
|
+
...(cwd !== undefined ? { cwd: verify.cwd ? path.resolve(cwd, verify.cwd) : cwd } : {}),
|
|
206
|
+
...(verify.env !== undefined ? { env: verify.env } : {}),
|
|
207
|
+
})) : [];
|
|
208
|
+
const output = resolveSingleOutputPath(request.output, ctxCwd);
|
|
209
|
+
return {
|
|
210
|
+
workflowRunId,
|
|
211
|
+
key,
|
|
212
|
+
...(typeof agent === "string" ? { agent } : {}),
|
|
213
|
+
...(typeof task === "string" ? { task } : {}),
|
|
214
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
215
|
+
...(typeof request.model === "string" ? { model: request.model } : {}),
|
|
216
|
+
...(typeof request.async === "boolean" ? { async: request.async } : {}),
|
|
217
|
+
...(typeof request.worktree === "boolean" ? { worktree: request.worktree } : {}),
|
|
218
|
+
...(resume !== undefined ? { resume } : {}),
|
|
219
|
+
...(commands.length > 0 ? { commands } : {}),
|
|
220
|
+
...(output !== undefined ? { output } : {}),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
180
223
|
function readWorkflowScriptFile(requestedPath, requestedCwd, runtimeCwd) {
|
|
181
224
|
const scriptPath = path.resolve(resolveRequestedCwd(runtimeCwd, requestedCwd), requestedPath);
|
|
182
225
|
let script;
|
|
@@ -644,7 +687,7 @@ function resolveForegroundResumeTarget(params, state, options = {}) {
|
|
|
644
687
|
throw new Error(`Ambiguous foreground run id prefix '${requested}' matched: ${matches.map((run) => run.runId).join(", ")}. Provide a longer id.`);
|
|
645
688
|
const run = matches[0];
|
|
646
689
|
if (run.children.some((child) => child.status === "detached"))
|
|
647
|
-
throw new Error(`Foreground run '${run.runId}' is detached for intercom coordination and cannot be revived safely while any child may still be live. Reply to the supervisor request first, then wait with
|
|
690
|
+
throw new Error(`Foreground run '${run.runId}' is detached for intercom coordination and cannot be revived safely while any child may still be live. Reply to the supervisor request first, then wait with ${waitToolName()}({ id: "${run.runId}" }); use status to recover the result and do not launch a replacement while it remains detached.`);
|
|
648
691
|
if (run.children.length > 1 && params.index === undefined)
|
|
649
692
|
throw new Error(`Foreground run '${run.runId}' has ${run.children.length} children. Provide index to choose one.`);
|
|
650
693
|
const index = params.index ?? 0;
|
|
@@ -795,9 +838,8 @@ function persistAsyncWorkflowControlEvent(input) {
|
|
|
795
838
|
fs.appendFileSync(path.join(input.job.asyncDir, "events.jsonl"), `${JSON.stringify(record)}\n`, "utf-8");
|
|
796
839
|
}
|
|
797
840
|
catch (error) {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
console.error("Failed to append async workflow control event while storage is full:", error);
|
|
841
|
+
// Called from the child's 1 s activity timer, where a throw would exit Pi; the notice itself is still sent.
|
|
842
|
+
reportSessionWarning(input.state, `Failed to record a control event for workflow ${input.job.asyncId}: ${error instanceof Error ? error.message : String(error)}`, "async-workflow-control-event");
|
|
801
843
|
}
|
|
802
844
|
}
|
|
803
845
|
function emitControlNotification(input) {
|
|
@@ -1180,8 +1222,8 @@ function validateNestedSessionFile(run, trustedSessionRoots, resolveSource, visi
|
|
|
1180
1222
|
}
|
|
1181
1223
|
return realSessionFile;
|
|
1182
1224
|
}
|
|
1183
|
-
export function readNestedRecoveryDescriptor(
|
|
1184
|
-
const recoveryDescriptor = readAsyncRecoveryDescriptor(
|
|
1225
|
+
export function readNestedRecoveryDescriptor(rootRunId, runId, agent) {
|
|
1226
|
+
const recoveryDescriptor = readAsyncRecoveryDescriptor(nestedRunScope(rootRunId).asyncDirRoot, runId);
|
|
1185
1227
|
if (!recoveryDescriptor)
|
|
1186
1228
|
return undefined;
|
|
1187
1229
|
if (recoveryDescriptor.sourceRunId !== runId)
|
|
@@ -1201,7 +1243,7 @@ function resolveNestedResumeTarget(match, trustedSessionRoots, resolveSource) {
|
|
|
1201
1243
|
throw new Error(`Could not determine child agent for nested run '${run.id}'.`);
|
|
1202
1244
|
const state = run.state === "complete" || run.state === "failed" || run.state === "paused" ? run.state : "failed";
|
|
1203
1245
|
const asyncDir = resolveNestedAsyncDir(match.match.rootRunId, run);
|
|
1204
|
-
const recoveryDescriptor = readNestedRecoveryDescriptor(
|
|
1246
|
+
const recoveryDescriptor = asyncDir ? readNestedRecoveryDescriptor(match.match.rootRunId, run.id, agent) : undefined;
|
|
1205
1247
|
return compactOptional({
|
|
1206
1248
|
kind: "revive",
|
|
1207
1249
|
source: "nested",
|
|
@@ -1688,6 +1730,20 @@ async function resumeAsyncRun(input) {
|
|
|
1688
1730
|
details: { mode: "management", results: [] },
|
|
1689
1731
|
};
|
|
1690
1732
|
}
|
|
1733
|
+
// Before any worktree protection or chain attachment: a launch that required a launcher and agent definition
|
|
1734
|
+
// resumes only while both still hold.
|
|
1735
|
+
const requiredLauncher = recoveryDescriptor?.requiredLauncher;
|
|
1736
|
+
if (requiredLauncher) {
|
|
1737
|
+
const refuse = (text) => ({ content: [{ type: "text", text }], isError: true, details: { mode: "management", results: [] } });
|
|
1738
|
+
if (attachChain)
|
|
1739
|
+
return refuse(`Cannot attach a chain to run '${target.runId}': it was launched with requireLauncher, and appended steps would run inside its runner unchecked.`);
|
|
1740
|
+
const currentDigest = discoveredAgentConfig ? agentDefinitionDigest(discoveredAgentConfig) : undefined;
|
|
1741
|
+
const now = !discoveredAgentConfig ? "is missing"
|
|
1742
|
+
: recoveryDescriptor.launcher !== requiredLauncher.name || discoveredAgentConfig.launcher !== requiredLauncher.name ? `uses launcher '${discoveredAgentConfig.launcher ?? "none"}'`
|
|
1743
|
+
: currentDigest !== requiredLauncher.definitionDigest ? `has digest ${currentDigest}` : undefined;
|
|
1744
|
+
if (now)
|
|
1745
|
+
return refuse(`Cannot resume: run '${target.runId}' was launched requiring launcher '${requiredLauncher.name}' and agent definition ${requiredLauncher.definitionDigest}; agent '${target.agent}' now ${now}.`);
|
|
1746
|
+
}
|
|
1691
1747
|
if (target.source === "async" && target.runner?.type === "external-cli") {
|
|
1692
1748
|
const runner = normalizeExternalCliRunnerStatus(target.runner);
|
|
1693
1749
|
const message = runner
|
|
@@ -1698,7 +1754,8 @@ async function resumeAsyncRun(input) {
|
|
|
1698
1754
|
if (input.params.baseRef !== undefined && "managedWorktree" in target && target.managedWorktree === true) {
|
|
1699
1755
|
return { content: [{ type: "text", text: "Cannot resume with baseRef: retained managed-worktree children continue in their existing worktree. Start a new worktree run from that base ref instead." }], isError: true, details: { mode: "management", results: [] } };
|
|
1700
1756
|
}
|
|
1701
|
-
|
|
1757
|
+
// Without a handoff the resume runs in the worktree the descriptor recorded; there is no cleanup record to mark preserved.
|
|
1758
|
+
if (target.source === "async" && target.managedWorktree && target.asyncDir && fs.existsSync(parallelHandoffPath(target.asyncDir))) {
|
|
1702
1759
|
try {
|
|
1703
1760
|
const protectedCwd = await protectRetainedWorktreeForResume(parallelHandoffPath(target.asyncDir), target.runId, target.index, input.signal);
|
|
1704
1761
|
if (path.resolve(protectedCwd) !== path.resolve(effectiveCwd))
|
|
@@ -1864,8 +1921,8 @@ async function resumeAsyncRun(input) {
|
|
|
1864
1921
|
if (target.source === "nested" && !target.recoveryDescriptor) {
|
|
1865
1922
|
return { content: [{ type: "text", text: `Nested child '${target.runId}' is missing its required recovery identity. Start a new run instead.` }], isError: true, details: { mode: "management", results: [] } };
|
|
1866
1923
|
}
|
|
1867
|
-
//
|
|
1868
|
-
const recoveryAgentConfig = recoveryDescriptor ? applySteeringRecoveryAgentConfig(baseAgentConfig, recoveryDescriptor) :
|
|
1924
|
+
// Without a recovery descriptor nothing records how the run was wrapped, so the agent file's launcher applies.
|
|
1925
|
+
const recoveryAgentConfig = recoveryDescriptor ? applySteeringRecoveryAgentConfig(baseAgentConfig, recoveryDescriptor) : baseAgentConfig;
|
|
1869
1926
|
const agentConfig = intercomBridge.active ? applyIntercomBridgeToAgent(recoveryAgentConfig, intercomBridge) : recoveryAgentConfig;
|
|
1870
1927
|
const foregroundContract = target.source === "foreground" ? target.resumeContract : undefined;
|
|
1871
1928
|
const outputSchema = Object.hasOwn(input.params, "outputSchema")
|
|
@@ -1884,7 +1941,7 @@ async function resumeAsyncRun(input) {
|
|
|
1884
1941
|
}
|
|
1885
1942
|
// Refuse before capacity moves so the retained run stays resumable once the config is fixed.
|
|
1886
1943
|
if (agentConfig.launcher !== undefined && !lookupRunnerLauncher(input.deps.config.runnerLaunchers, agentConfig.launcher)) {
|
|
1887
|
-
return { content: [{ type: "text", text: `Cannot resume: run '${target.runId}'
|
|
1944
|
+
return { content: [{ type: "text", text: `Cannot resume: run '${target.runId}' uses launcher '${agentConfig.launcher}', which is no longer defined in runnerLaunchers in the user subagent config.` }], isError: true, details: { mode: "management", results: [] } };
|
|
1888
1945
|
}
|
|
1889
1946
|
const runId = randomUUID();
|
|
1890
1947
|
const topLevelResume = depth === 0 && !inheritedNestedRoute(input.deps) && !input.params.workflowParentRunId;
|
|
@@ -1930,6 +1987,7 @@ async function resumeAsyncRun(input) {
|
|
|
1930
1987
|
goal: effectiveFollowUp,
|
|
1931
1988
|
agentConfig,
|
|
1932
1989
|
recoveryAgentConfig,
|
|
1990
|
+
carriedRequiredLauncher: recoveryDescriptor?.requiredLauncher,
|
|
1933
1991
|
ctx: compactOptional({
|
|
1934
1992
|
pi: input.deps.pi,
|
|
1935
1993
|
cwd: input.requestCwd,
|
|
@@ -2117,6 +2175,7 @@ function createForegroundControlNotifier(data, deps) {
|
|
|
2117
2175
|
const enriched = workflowKey && !event.workflowKey ? { ...event, workflowKey } : event;
|
|
2118
2176
|
if (asyncWorkflow) {
|
|
2119
2177
|
persistAsyncWorkflowControlEvent({
|
|
2178
|
+
state: deps.state,
|
|
2120
2179
|
job: asyncWorkflow,
|
|
2121
2180
|
event: enriched,
|
|
2122
2181
|
controlConfig: data.controlConfig,
|
|
@@ -2626,16 +2685,6 @@ function validateLaunchOutputSchemaOverrides(params) {
|
|
|
2626
2685
|
}
|
|
2627
2686
|
return undefined;
|
|
2628
2687
|
}
|
|
2629
|
-
export const DEFAULT_FOREGROUND_TIMEOUT_MS = 30 * 60 * 1000;
|
|
2630
|
-
// Async single-agent runs also need a wall-clock backstop: a child whose bash
|
|
2631
|
-
// tool blocks forever (e.g. a background process inheriting the terminal with
|
|
2632
|
-
// no bash `timeout` arg) would otherwise hang the parent indefinitely with
|
|
2633
|
-
// zero signal. Same generous default as foreground; explicit timeoutMs/
|
|
2634
|
-
// maxRuntimeMs and agent-level defaultTimeoutMs remain authoritative.
|
|
2635
|
-
//
|
|
2636
|
-
// Deliberately NOT applied at the workflow level: async scripted workflows
|
|
2637
|
-
// stay unbounded as a whole, while each runner child has its own deadline.
|
|
2638
|
-
export { DEFAULT_ASYNC_TIMEOUT_MS };
|
|
2639
2688
|
/**
|
|
2640
2689
|
* Maximum delay a Node.js timer accepts. Values above the 32-bit signed integer
|
|
2641
2690
|
* ceiling overflow `setTimeout`, which silently clamps the delay to ~1ms and
|
|
@@ -2652,7 +2701,7 @@ function timerDelayOverflowError(name, value) {
|
|
|
2652
2701
|
/**
|
|
2653
2702
|
* Resolve the optional global default runtime deadline from extension config
|
|
2654
2703
|
* (`config.timeoutMs`). Returns undefined for unset or invalid values so callers
|
|
2655
|
-
*
|
|
2704
|
+
* use no configured deadline. "Invalid" covers non-positive-integer
|
|
2656
2705
|
* values and values above `MAX_TIMER_DELAY_MS`; the latter would overflow the
|
|
2657
2706
|
* Node.js timer and expire the run almost immediately instead of running long.
|
|
2658
2707
|
*/
|
|
@@ -2685,10 +2734,10 @@ export function resolveForegroundTimeout(params, defaultTimeoutMs) {
|
|
|
2685
2734
|
}
|
|
2686
2735
|
/**
|
|
2687
2736
|
* Resolve the effective launch timeout for a single-agent run, applying the
|
|
2688
|
-
*
|
|
2737
|
+
* configured default when neither the caller nor the agent set one.
|
|
2689
2738
|
*
|
|
2690
2739
|
* A global config default (`config.timeoutMs`, passed as `configDefaultTimeoutMs`)
|
|
2691
|
-
*
|
|
2740
|
+
* applies where a concrete default is configured.
|
|
2692
2741
|
* The async default is deliberately applied only to plain single-agent launches.
|
|
2693
2742
|
* Composite launches keep their top-level execution unbounded when no timeout is
|
|
2694
2743
|
* set — even with a config default — while their runner children resolve separate
|
|
@@ -2696,9 +2745,7 @@ export function resolveForegroundTimeout(params, defaultTimeoutMs) {
|
|
|
2696
2745
|
*/
|
|
2697
2746
|
export function resolveSingleAgentLaunchTimeout(params, async, configDefaultTimeoutMs) {
|
|
2698
2747
|
const isComposite = (params.chain?.length ?? 0) > 0 || (params.tasks?.length ?? 0) > 0 || params.workflowScript !== undefined;
|
|
2699
|
-
const
|
|
2700
|
-
const asyncSingleDefault = configDefaultTimeoutMs ?? DEFAULT_ASYNC_TIMEOUT_MS;
|
|
2701
|
-
const defaultTimeoutMs = !async ? foregroundDefault : isComposite ? undefined : asyncSingleDefault;
|
|
2748
|
+
const defaultTimeoutMs = !async || !isComposite ? configDefaultTimeoutMs : undefined;
|
|
2702
2749
|
return resolveForegroundTimeout(params, defaultTimeoutMs);
|
|
2703
2750
|
}
|
|
2704
2751
|
function resolveToolBudget(raw, label = "toolBudget", options) {
|
|
@@ -3177,6 +3224,7 @@ async function runAsyncPath(data, deps) {
|
|
|
3177
3224
|
requestedCwd: data.requestedCwd,
|
|
3178
3225
|
machine: params.machine,
|
|
3179
3226
|
machineCwd: params.machineCwd,
|
|
3227
|
+
requireLauncher: params.requireLauncher,
|
|
3180
3228
|
maxOutput: params.maxOutput,
|
|
3181
3229
|
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
3182
3230
|
artifactConfig,
|
|
@@ -3677,7 +3725,7 @@ async function runSinglePath(data, deps) {
|
|
|
3677
3725
|
? `[Read from: ${readPaths.join(", ")}]\n\n`
|
|
3678
3726
|
: "";
|
|
3679
3727
|
task = readsInstruction + task;
|
|
3680
|
-
task = injectSingleOutputInstruction(task, outputPath, agentConfig);
|
|
3728
|
+
task = injectSingleOutputInstruction(task, outputPath, agentConfig, foregroundMachine);
|
|
3681
3729
|
let effectiveSkills;
|
|
3682
3730
|
if (skillOverride === false) {
|
|
3683
3731
|
effectiveSkills = [];
|
|
@@ -3829,6 +3877,7 @@ async function runSinglePath(data, deps) {
|
|
|
3829
3877
|
suppressUnchangedDelegationUpdates,
|
|
3830
3878
|
controlConfig,
|
|
3831
3879
|
onControlEvent,
|
|
3880
|
+
onWarning: (message, key) => reportSessionWarning(deps.state, message, key),
|
|
3832
3881
|
intercomSessionName: childIntercomTarget,
|
|
3833
3882
|
orchestratorIntercomTarget: childBridgeActive ? data.intercomBridge.orchestratorTarget : undefined,
|
|
3834
3883
|
nestedRoute: foregroundControl?.nestedRoute,
|
|
@@ -4017,11 +4066,11 @@ async function runSinglePath(data, deps) {
|
|
|
4017
4066
|
const worktreeSuffix = worktreeHandoff?.suffix ? `\n\n${worktreeHandoff.suffix}` : "";
|
|
4018
4067
|
if (r.detached) {
|
|
4019
4068
|
const statusRecovery = `subagent({ action: "status", id: "${runId}" }) to recover the result; do not resume or launch a replacement while it remains detached.`;
|
|
4020
|
-
const blockingRecovery =
|
|
4069
|
+
const blockingRecovery = `${waitToolName()}({ id: "${runId}" }). Use ${statusRecovery}`;
|
|
4021
4070
|
const message = r.detachedReason === "intercom coordination"
|
|
4022
4071
|
? `Detached for intercom coordination: ${params.agent}. Reply to the supervisor request first, then wait with ${blockingRecovery}`
|
|
4023
4072
|
: r.detachedReason === "user request"
|
|
4024
|
-
? `Detached at user request: ${params.agent}. The child continues independently. Register a completion wake-up with
|
|
4073
|
+
? `Detached at user request: ${params.agent}. The child continues independently. Register a completion wake-up with ${waitToolName()}({ id: "${runId}", nonBlocking: true }), or use ${statusRecovery}`
|
|
4025
4074
|
: `Detached before task completion: ${params.agent}. Wait with ${blockingRecovery}`;
|
|
4026
4075
|
return {
|
|
4027
4076
|
content: [{ type: "text", text: `${message}${worktreeSuffix}` }],
|
|
@@ -4501,6 +4550,9 @@ export async function preflightWorkflowWorktrees(input) {
|
|
|
4501
4550
|
input.signal.throwIfAborted();
|
|
4502
4551
|
}
|
|
4503
4552
|
export function prepareWorkflowLaunchParams(workflowDefaults, childParams, parentWorkflowRunId, workflowKey, options = {}) {
|
|
4553
|
+
// Before the resume branch below, which rebuilds params field by field and would drop the requirement.
|
|
4554
|
+
if (childParams.requireLauncher !== undefined || workflowDefaults.requireLauncher !== undefined)
|
|
4555
|
+
throw new Error(REQUIRE_LAUNCHER_SHAPE_ERROR);
|
|
4504
4556
|
const { globalConcurrencyLimit: _globalConcurrencyLimit, maxSubagentSpawnsPerRun: _maxSubagentSpawnsPerRun, ...workflowDefaultsWithoutCapacity } = workflowDefaults;
|
|
4505
4557
|
const { globalConcurrencyLimit: _childGlobalConcurrencyLimit, maxSubagentSpawnsPerRun: _childMaxSubagentSpawnsPerRun, ...childParamsWithoutCapacity } = childParams;
|
|
4506
4558
|
workflowDefaults = workflowDefaultsWithoutCapacity;
|
|
@@ -4779,11 +4831,12 @@ function savedWorkflowLaunchParams(params) {
|
|
|
4779
4831
|
const { reuseFrom: _reuseFrom, scheduleOrigin: _scheduleOrigin, resumeOrigin: _resumeOrigin, ...saved } = params;
|
|
4780
4832
|
return saved;
|
|
4781
4833
|
}
|
|
4782
|
-
function workflowLaunchRecord(launch, cwd, scriptDigest) {
|
|
4783
|
-
|
|
4784
|
-
|
|
4834
|
+
function workflowLaunchRecord(launch, cwd, scriptDigest, sessionId, ceiling) {
|
|
4835
|
+
const owner = { version: 2, scriptDigest, sessionId, ...(ceiling ? { admissionCapabilityCeiling: ceiling } : {}) };
|
|
4836
|
+
if (launch.source === "structured" || launch.source === "internal")
|
|
4837
|
+
return { ...owner, source: launch.source };
|
|
4785
4838
|
// The resolved cwd is saved: a relative one would resolve against a later session's cwd.
|
|
4786
|
-
return {
|
|
4839
|
+
return { ...owner, source: launch.source, params: { ...launch.params, cwd } };
|
|
4787
4840
|
}
|
|
4788
4841
|
export function createSubagentExecutor(deps) {
|
|
4789
4842
|
const executorDeps = deps;
|
|
@@ -4944,7 +4997,7 @@ export function createSubagentExecutor(deps) {
|
|
|
4944
4997
|
if (overflowError)
|
|
4945
4998
|
return buildRequestedModeError(requestParams, overflowError);
|
|
4946
4999
|
}
|
|
4947
|
-
const timeout = requestParams.timeoutMs ?? requestParams.maxRuntimeMs ?? (requestParams.async === false ? resolveConfigDefaultTimeoutMs(deps.config.timeoutMs)
|
|
5000
|
+
const timeout = requestParams.timeoutMs ?? requestParams.maxRuntimeMs ?? (requestParams.async === false ? resolveConfigDefaultTimeoutMs(deps.config.timeoutMs) : undefined);
|
|
4948
5001
|
const workflowUsageBudget = validateUsageBudgetConfig(requestParams.usageBudget ?? deps.config.usageBudget, requestParams.usageBudget ? "usageBudget" : "config.usageBudget");
|
|
4949
5002
|
if (workflowUsageBudget.error)
|
|
4950
5003
|
return buildRequestedModeError(requestParams, workflowUsageBudget.error);
|
|
@@ -5104,8 +5157,8 @@ export function createSubagentExecutor(deps) {
|
|
|
5104
5157
|
try {
|
|
5105
5158
|
fs.mkdirSync(asyncDir, { recursive: true });
|
|
5106
5159
|
writeRunFanoutBudgetDescriptor(asyncDir, workflowFanoutBudget);
|
|
5107
|
-
if (topLevelAsyncWorkflow
|
|
5108
|
-
writeWorkflowLaunchRecord(
|
|
5160
|
+
if (topLevelAsyncWorkflow)
|
|
5161
|
+
writeWorkflowLaunchRecord(DIRS.async, workflowRunId, workflowLaunchRecord(publicWorkflowLaunch ?? { source: "internal" }, workflowCwd, workflowScriptSourceDigest, currentSessionId, workflowCapabilityCeiling));
|
|
5109
5162
|
fs.mkdirSync(DIRS.results, { recursive: true });
|
|
5110
5163
|
}
|
|
5111
5164
|
catch (error) {
|
|
@@ -5865,9 +5918,12 @@ export function createSubagentExecutor(deps) {
|
|
|
5865
5918
|
heartbeat: { status: "running", ...(childPhase ? { phase: childPhase } : {}) },
|
|
5866
5919
|
});
|
|
5867
5920
|
let preparedChildParams;
|
|
5868
|
-
const result = await runMissionWorkflowChild(missionBinding, workflowRunId, key, childPhase, () => {
|
|
5921
|
+
const result = await runMissionWorkflowChild(missionBinding, workflowRunId, key, childPhase, async () => {
|
|
5869
5922
|
const childRequest = bindMissionWorkflowChildAsyncLaunch({ ...prepareWorkflowChildLaunchParams({ workflowDefaults: workflowChildDefaults, childParams, parentWorkflowRunId: workflowRunId, workflowKey: key, ctxCwd: parentCwd, workflowCwd, artifactsDir: workflowArtifactsDir, aggregateOutputPath: workflowAggregateOutputPath, configuredOutputBaseDir, discoverAgents: discoverWorkflowAgents, agents: workflowAgents, workflowAgentScope: workflowChildDefaults.agentScope, outputOverride: childOutputOverrides.get(key), outputClaimPath: childOutputClaimPaths.get(key), options: { missionDetached: detachWorkflowChildMissions, awaitDetachedChild: true, runFanoutBudget: workflowFanoutBudget, parentDeadlineAt: workflowDeadlineAt, capabilityCeiling: workflowCapabilityCeiling } }), runFanoutAdmitted: admission.admitted }, missionBinding, deps.asyncByDefault, undefined, inheritedNestedRoute(deps)?.rootRunId);
|
|
5870
5923
|
preparedChildParams = childRequest;
|
|
5924
|
+
const launchRefusal = await approveWorkflowChildLaunch(ctx, () => workflowChildLaunchArgs(workflowRunId, key, childRequest, childParams.agent, parentCwd, discoverWorkflowAgents), workflowSignal);
|
|
5925
|
+
if (launchRefusal)
|
|
5926
|
+
return buildRequestedModeError(childRequest, launchRefusal);
|
|
5871
5927
|
if (workflowUsageBudget.budget)
|
|
5872
5928
|
workflowOwnedUsageBudgets.set(childRequest, workflowUsageBudget.budget);
|
|
5873
5929
|
if (workflowRequiredExtensions)
|
|
@@ -6192,9 +6248,12 @@ export function createSubagentExecutor(deps) {
|
|
|
6192
6248
|
heartbeat: { status: "running", ...(childPhase ? { phase: childPhase } : {}) },
|
|
6193
6249
|
});
|
|
6194
6250
|
let preparedChildParams;
|
|
6195
|
-
const result = await runMissionWorkflowChild(missionBinding, foregroundWorkflowRunId, key, childPhase, () => {
|
|
6251
|
+
const result = await runMissionWorkflowChild(missionBinding, foregroundWorkflowRunId, key, childPhase, async () => {
|
|
6196
6252
|
const childRequest = bindMissionWorkflowChildAsyncLaunch({ ...prepareWorkflowChildLaunchParams({ workflowDefaults: workflowChildDefaults, childParams: delegatedWorkflowPermit ? { ...childParams, async: false } : childParams, parentWorkflowRunId: foregroundWorkflowRunId, workflowKey: key, ctxCwd: ctx.cwd, workflowCwd, artifactsDir: workflowArtifactsDir, aggregateOutputPath: workflowAggregateOutputPath, configuredOutputBaseDir, discoverAgents: discoverWorkflowAgents, agents: workflowAgents, workflowAgentScope: workflowChildDefaults.agentScope, outputOverride: childOutputOverrides.get(key), outputClaimPath: childOutputClaimPaths.get(key), options: { missionDetached: detachWorkflowChildMissions, suppressRoutineResultIntercom: chatProgress.mode === "live-card", runFanoutBudget: workflowFanoutBudget, parentDeadlineAt: workflowDeadlineAt, capabilityCeiling: workflowCapabilityCeiling } }), runFanoutAdmitted: admission.admitted }, missionBinding, deps.asyncByDefault, undefined, inheritedNestedRoute(deps)?.rootRunId);
|
|
6197
6253
|
preparedChildParams = childRequest;
|
|
6254
|
+
const launchRefusal = await approveWorkflowChildLaunch(ctx, () => workflowChildLaunchArgs(foregroundWorkflowRunId, key, childRequest, childParams.agent, ctx.cwd, discoverWorkflowAgents), workflowSignal);
|
|
6255
|
+
if (launchRefusal)
|
|
6256
|
+
return buildRequestedModeError(childRequest, launchRefusal);
|
|
6198
6257
|
if (workflowUsageBudget.budget)
|
|
6199
6258
|
workflowOwnedUsageBudgets.set(childRequest, workflowUsageBudget.budget);
|
|
6200
6259
|
if (workflowRequiredExtensions)
|
|
@@ -7266,6 +7325,16 @@ export function createSubagentExecutor(deps) {
|
|
|
7266
7325
|
if (launcherError)
|
|
7267
7326
|
return buildRequestedModeError(effectiveParams, launcherError);
|
|
7268
7327
|
}
|
|
7328
|
+
// Refused here, before admission; executeAsyncSingle checks again on the exact agent and launcher it spawns.
|
|
7329
|
+
if (effectiveParams.requireLauncher !== undefined) {
|
|
7330
|
+
if (!effectiveParams.requireLauncher || typeof effectiveParams.requireLauncher !== "object")
|
|
7331
|
+
return buildRequestedModeError(effectiveParams, "requireLauncher must be { name, definitionDigest }.");
|
|
7332
|
+
if (!hasSingle || effectiveParams.resume !== undefined || effectiveParams.workflowParentRunId !== undefined)
|
|
7333
|
+
return buildRequestedModeError(effectiveParams, REQUIRE_LAUNCHER_SHAPE_ERROR);
|
|
7334
|
+
const required = selectedAgents[0] ? checkRequiredRunnerLauncher(selectedAgents[0], selectedAgents[0].launcher, effectiveParams.requireLauncher) : undefined;
|
|
7335
|
+
if (required?.error)
|
|
7336
|
+
return buildRequestedModeError(effectiveParams, required.error);
|
|
7337
|
+
}
|
|
7269
7338
|
if (effectiveAsync && hasSingle && effectiveParams.resume === undefined && effectiveParams.worktree === true) {
|
|
7270
7339
|
try {
|
|
7271
7340
|
await preflightWorktreeSource(effectiveCwd, { signal });
|
|
@@ -1149,13 +1149,34 @@ function verifyRedactionEnv(env) {
|
|
|
1149
1149
|
return value.length >= 4 && SENSITIVE_ENV_KEY_PATTERN.test(key);
|
|
1150
1150
|
}));
|
|
1151
1151
|
}
|
|
1152
|
-
function
|
|
1152
|
+
function verifySecrets(env) {
|
|
1153
|
+
return [...new Set(Object.values(verifyRedactionEnv(env)).filter(Boolean))].sort((left, right) => right.length - left.length);
|
|
1154
|
+
}
|
|
1155
|
+
function redactSecrets(value, secrets) {
|
|
1153
1156
|
let redacted = value;
|
|
1154
|
-
const secrets = [...new Set(Object.values(verifyRedactionEnv(env)).filter(Boolean))].sort((left, right) => right.length - left.length);
|
|
1155
1157
|
for (const secret of secrets)
|
|
1156
1158
|
redacted = redacted.replaceAll(secret, "[REDACTED]");
|
|
1157
1159
|
return redacted;
|
|
1158
1160
|
}
|
|
1161
|
+
function redactVerifyEnv(value, env) {
|
|
1162
|
+
return redactSecrets(value, verifySecrets(env));
|
|
1163
|
+
}
|
|
1164
|
+
/** Numbers are matched on their source text: parsing rounds or respells them (12345678901234567890, 1.50), which would hide a secret. */
|
|
1165
|
+
function parseRedactedVerifyValue(text, secrets) {
|
|
1166
|
+
return JSON.parse(text, (_key, value, context) => {
|
|
1167
|
+
if (typeof value === "string")
|
|
1168
|
+
return redactSecrets(value, secrets);
|
|
1169
|
+
if (typeof value === "number" && secrets.length > 0) {
|
|
1170
|
+
// Node 22+ and Bun pass the source text; without it, fail closed.
|
|
1171
|
+
const source = context?.source;
|
|
1172
|
+
return source !== undefined && redactSecrets(source, secrets) === source ? value : "[REDACTED]";
|
|
1173
|
+
}
|
|
1174
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
1175
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [redactSecrets(key, secrets), item]));
|
|
1176
|
+
}
|
|
1177
|
+
return value;
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1159
1180
|
function uniqueStrings(items) {
|
|
1160
1181
|
return unique(items.map((item) => item?.trim()).filter((item) => Boolean(item)));
|
|
1161
1182
|
}
|
|
@@ -1223,34 +1244,49 @@ const TYPED_VERIFY_OUTPUT_MAX_BYTES = 12_000;
|
|
|
1223
1244
|
* A passing `output: "json"` command must print one JSON document on stdout.
|
|
1224
1245
|
* The parsed value becomes the run's structured output; anything else turns
|
|
1225
1246
|
* the passing run into a failed one so acceptance rejects rather than
|
|
1226
|
-
* silently dropping the verdict.
|
|
1227
|
-
*
|
|
1247
|
+
* silently dropping the verdict. The raw stdout is parsed, because the stored
|
|
1248
|
+
* stdout is redacted and redaction can hit JSON syntax (`true` in KDE_FULL_SESSION).
|
|
1249
|
+
* The schema checks the raw value so a redacted string cannot fail a correct
|
|
1250
|
+
* gate. Error messages quote parts of their input (a parse error quotes ~10
|
|
1251
|
+
* chars, schema paths escape `/` and `~`), so each one is built from the
|
|
1252
|
+
* redacted text or value, never the raw one.
|
|
1228
1253
|
*/
|
|
1229
|
-
async function applyTypedVerifyOutput(command, run) {
|
|
1254
|
+
async function applyTypedVerifyOutput(command, run, rawStdout) {
|
|
1230
1255
|
if (run.status !== "passed")
|
|
1231
1256
|
return;
|
|
1232
|
-
const
|
|
1257
|
+
const secrets = verifySecrets(command.env);
|
|
1258
|
+
const stdout = rawStdout.trim();
|
|
1233
1259
|
const fail = (message) => {
|
|
1234
1260
|
run.status = "failed";
|
|
1235
|
-
run.structuredOutputError = message;
|
|
1261
|
+
run.structuredOutputError = redactSecrets(message, secrets);
|
|
1236
1262
|
};
|
|
1237
|
-
if (!stdout
|
|
1263
|
+
if (!stdout)
|
|
1238
1264
|
return fail("output: \"json\" command printed nothing on stdout.");
|
|
1239
|
-
if (stdout.
|
|
1265
|
+
if (stdout.length > TYPED_VERIFY_OUTPUT_MAX_BYTES)
|
|
1240
1266
|
return fail(`output: "json" stdout exceeded ${TYPED_VERIFY_OUTPUT_MAX_BYTES} characters and was truncated.`);
|
|
1241
1267
|
let value;
|
|
1242
1268
|
try {
|
|
1243
1269
|
value = JSON.parse(stdout);
|
|
1244
1270
|
}
|
|
1245
|
-
catch
|
|
1246
|
-
|
|
1271
|
+
catch {
|
|
1272
|
+
let reason = "parse failed";
|
|
1273
|
+
try {
|
|
1274
|
+
JSON.parse(redactSecrets(stdout, secrets));
|
|
1275
|
+
}
|
|
1276
|
+
catch (error) {
|
|
1277
|
+
reason = error instanceof Error ? error.message : String(error);
|
|
1278
|
+
}
|
|
1279
|
+
return fail(`output: "json" stdout is not valid JSON: ${reason}`);
|
|
1247
1280
|
}
|
|
1281
|
+
const redactedValue = parseRedactedVerifyValue(stdout, secrets);
|
|
1248
1282
|
if (command.schema) {
|
|
1249
1283
|
const validation = await validateStructuredOutputValue(command.schema, value);
|
|
1250
|
-
if (validation.status === "invalid")
|
|
1251
|
-
|
|
1284
|
+
if (validation.status === "invalid") {
|
|
1285
|
+
const redactedValidation = await validateStructuredOutputValue(command.schema, redactedValue);
|
|
1286
|
+
return fail(`output: "json" stdout does not match gate.schema${redactedValidation.status === "invalid" ? `: ${redactedValidation.message}` : "."}`);
|
|
1287
|
+
}
|
|
1252
1288
|
}
|
|
1253
|
-
run.structuredOutput =
|
|
1289
|
+
run.structuredOutput = redactedValue;
|
|
1254
1290
|
}
|
|
1255
1291
|
/** The first typed verify result on a ledger, if any command produced one. */
|
|
1256
1292
|
export function typedVerifyOutput(ledger) {
|
|
@@ -1258,6 +1294,13 @@ export function typedVerifyOutput(ledger) {
|
|
|
1258
1294
|
return run ? { value: run.structuredOutput } : undefined;
|
|
1259
1295
|
}
|
|
1260
1296
|
async function runMemoizedVerifyCommand(command, defaultCwd, options = {}) {
|
|
1297
|
+
// Typed gates read inputs (a report file, a log) that can change without
|
|
1298
|
+
// the tracked tree changing, so their verdicts are never reused.
|
|
1299
|
+
if (command.output === "json") {
|
|
1300
|
+
const { run, rawStdout } = await runVerifyCommand(command, defaultCwd, options);
|
|
1301
|
+
await applyTypedVerifyOutput(command, run, rawStdout);
|
|
1302
|
+
return run;
|
|
1303
|
+
}
|
|
1261
1304
|
const cwd = command.cwd ? path.resolve(defaultCwd, command.cwd) : defaultCwd;
|
|
1262
1305
|
let workspaceState;
|
|
1263
1306
|
try {
|
|
@@ -1266,10 +1309,8 @@ async function runMemoizedVerifyCommand(command, defaultCwd, options = {}) {
|
|
|
1266
1309
|
catch {
|
|
1267
1310
|
workspaceState = undefined;
|
|
1268
1311
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
if (!workspaceState || !options.artifactsDir || !options.runId || command.output === "json") {
|
|
1272
|
-
return runVerifyCommand(command, defaultCwd, options);
|
|
1312
|
+
if (!workspaceState || !options.artifactsDir || !options.runId) {
|
|
1313
|
+
return (await runVerifyCommand(command, defaultCwd, options)).run;
|
|
1273
1314
|
}
|
|
1274
1315
|
const envKeys = Object.keys(command.env ?? {}).sort();
|
|
1275
1316
|
const envHash = hash(JSON.stringify(Object.fromEntries(Object.entries(effectiveVerifyEnv(command.env)).sort(([left], [right]) => left.localeCompare(right)))));
|
|
@@ -1295,7 +1336,7 @@ async function runMemoizedVerifyCommand(command, defaultCwd, options = {}) {
|
|
|
1295
1336
|
catch {
|
|
1296
1337
|
// A cache miss or unreadable artifact must not prevent host verification.
|
|
1297
1338
|
}
|
|
1298
|
-
const result = await runVerifyCommand(command, defaultCwd, options);
|
|
1339
|
+
const { run: result } = await runVerifyCommand(command, defaultCwd, options);
|
|
1299
1340
|
const evidenced = { ...result, artifactPath, cacheKey, memoized: false, envKeys, envHash, workspaceState };
|
|
1300
1341
|
try {
|
|
1301
1342
|
fs.mkdirSync(path.dirname(artifactPath), { recursive: true });
|
|
@@ -1363,6 +1404,7 @@ export function quoteExecutableForShell(command, platform = process.platform) {
|
|
|
1363
1404
|
}
|
|
1364
1405
|
return command;
|
|
1365
1406
|
}
|
|
1407
|
+
/** `rawStdout` is unredacted and never stored; only typed output parsing reads it. */
|
|
1366
1408
|
function runVerifyCommand(command, defaultCwd, options = {}) {
|
|
1367
1409
|
return new Promise((resolve) => {
|
|
1368
1410
|
const startedAt = Date.now();
|
|
@@ -1388,11 +1430,14 @@ function runVerifyCommand(command, defaultCwd, options = {}) {
|
|
|
1388
1430
|
clearTimeout(hardKill);
|
|
1389
1431
|
options.signal?.removeEventListener("abort", abortVerification);
|
|
1390
1432
|
resolve({
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1433
|
+
run: {
|
|
1434
|
+
id: command.id,
|
|
1435
|
+
command: command.command,
|
|
1436
|
+
cwd,
|
|
1437
|
+
durationMs: Date.now() - startedAt,
|
|
1438
|
+
...result,
|
|
1439
|
+
},
|
|
1440
|
+
rawStdout: stdout,
|
|
1396
1441
|
});
|
|
1397
1442
|
};
|
|
1398
1443
|
const abortVerification = () => {
|
|
@@ -1531,8 +1576,6 @@ export async function evaluateAcceptance(input) {
|
|
|
1531
1576
|
artifactsDir: input.artifactsDir,
|
|
1532
1577
|
runId: input.runId,
|
|
1533
1578
|
});
|
|
1534
|
-
if (command.output === "json")
|
|
1535
|
-
await applyTypedVerifyOutput(command, run);
|
|
1536
1579
|
ledger.verifyRuns.push(run);
|
|
1537
1580
|
if (input.signal?.aborted)
|
|
1538
1581
|
break;
|
|
@@ -135,8 +135,20 @@ export function createChildCommandRuntime(channelDir) {
|
|
|
135
135
|
persist();
|
|
136
136
|
startInbox();
|
|
137
137
|
let timer;
|
|
138
|
+
let yieldSaveError;
|
|
139
|
+
// A throw from this timer would exit Pi. A closed controller is already cancelling the command; a failed
|
|
140
|
+
// save still yields, and the handle says the saved state is stale.
|
|
138
141
|
if (typeof yieldTimeMs === "number")
|
|
139
|
-
timer = setTimeout(() =>
|
|
142
|
+
timer = setTimeout(() => {
|
|
143
|
+
if (closed)
|
|
144
|
+
return;
|
|
145
|
+
try {
|
|
146
|
+
operate("yield", toolCallId);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
yieldSaveError = error;
|
|
150
|
+
}
|
|
151
|
+
}, yieldTimeMs);
|
|
140
152
|
const execution = Promise.resolve().then(() => tool.execute(toolCallId, args, commandSignal, (update) => {
|
|
141
153
|
job.snapshot.output = text(update);
|
|
142
154
|
if (job.snapshot.state === "running")
|
|
@@ -163,7 +175,8 @@ export function createChildCommandRuntime(channelDir) {
|
|
|
163
175
|
const result = await Promise.race([execution.then((value) => ({ value })), yielded.then(() => undefined)]);
|
|
164
176
|
if (result)
|
|
165
177
|
return result.value;
|
|
166
|
-
|
|
178
|
+
const saveWarning = yieldSaveError === undefined ? "" : `\nThe command's saved state is out of date because it could not be saved: ${yieldSaveError instanceof Error ? yieldSaveError.message : String(yieldSaveError)}`;
|
|
179
|
+
return { content: [{ type: "text", text: `Command is still running (toolCallId: ${toolCallId}). This is not a successful exit. Use subagent_command({ action: "status", toolCallId: ${JSON.stringify(toolCallId)} }) to inspect or wait, or action: "cancel" to stop it.${saveWarning}\n${job.snapshot.output}` }], details: { command: { ...job.snapshot } } };
|
|
167
180
|
},
|
|
168
181
|
};
|
|
169
182
|
},
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
1
|
import type { ChildRuntimeConfig } from "./child-runtime-config.ts";
|
|
3
2
|
import type { ChildToolDiagnostic } from "./tool-availability.ts";
|
|
4
|
-
import type { ChildSessionLaunch } from "./child-session.ts";
|
|
3
|
+
import type { ChildHookExtension, ChildSessionLaunch } from "./child-session.ts";
|
|
5
4
|
import type { ChildTranscriptWriter } from "../../shared/child-transcript.ts";
|
|
6
|
-
/** Inline extension shape accepted by pi's resource loader (`extensionFactories`). */
|
|
7
|
-
export interface ChildHookExtension {
|
|
8
|
-
name: string;
|
|
9
|
-
factory: (pi: ExtensionAPI) => void;
|
|
10
|
-
}
|
|
11
5
|
/** The host's mandatory transcript reporting, owned by the existing hook certificate. */
|
|
12
6
|
export declare function withChildSessionErrorReporting(session: Omit<ChildSessionLaunch, "onExtensionError">, transcriptWriter: ChildTranscriptWriter | undefined): ChildSessionLaunch;
|
|
13
7
|
export declare function isReadonlyChildSessionReporting(launch: ChildSessionLaunch): boolean;
|