@xzzpig/pi-subagents 0.24.1 → 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 +28 -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-ZWXU5SPQ.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-6BJUEES3.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-SLNMBXLL.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-LMGQAJ3O.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-Y6H2G6KX.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-TGLFTQWJ.js → chunk-YWXILP5N.js} +5 -4
- 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/node_modules/@xzzpig/pi-components/CHANGELOG.md +12 -0
- package/node_modules/@xzzpig/pi-components/README.md +94 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.d.ts +186 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.js +693 -0
- package/node_modules/@xzzpig/pi-components/package.json +5 -1
- package/package.json +4 -4
- 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,16 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isTrustedRecordedSessionFile,
|
|
3
3
|
resolveSubagentRunId
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ULGMXABL.js";
|
|
5
5
|
import {
|
|
6
6
|
formatShellCommand
|
|
7
7
|
} from "./chunk-7J4ZXMY7.js";
|
|
8
8
|
import {
|
|
9
9
|
agentStreamOptions,
|
|
10
10
|
opencodeSessionHeaders,
|
|
11
|
-
ownsRun,
|
|
12
11
|
resolveAsyncResumeTarget
|
|
13
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-DLVPMML3.js";
|
|
13
|
+
import {
|
|
14
|
+
ownsRun
|
|
15
|
+
} from "./chunk-HXRB42AF.js";
|
|
14
16
|
import {
|
|
15
17
|
currentCompletionOwnerId,
|
|
16
18
|
listMissions,
|
|
@@ -19,12 +21,12 @@ import {
|
|
|
19
21
|
reconcileAsyncRun,
|
|
20
22
|
resolveAuthorityDecision,
|
|
21
23
|
resolveMissionStoreLocation
|
|
22
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-JH5H4CYJ.js";
|
|
23
25
|
import {
|
|
24
26
|
deliverInterruptRequest,
|
|
25
27
|
queueRevivalBrief,
|
|
26
28
|
requestAsyncSteer
|
|
27
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-LPJEKHOY.js";
|
|
28
30
|
import {
|
|
29
31
|
readStatus,
|
|
30
32
|
redactSecretValues,
|
|
@@ -32,7 +34,7 @@ import {
|
|
|
32
34
|
tryLease,
|
|
33
35
|
writeAtomicJson,
|
|
34
36
|
writePrivateAtomicJson
|
|
35
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-XAC2XNAP.js";
|
|
36
38
|
import {
|
|
37
39
|
DIRS
|
|
38
40
|
} from "./chunk-UQDHXMUG.js";
|
|
@@ -74,7 +76,7 @@ function recordSteeringRequest(status, input) {
|
|
|
74
76
|
requestedAt: input.requestedAt,
|
|
75
77
|
...input.source ? { source: input.source } : {},
|
|
76
78
|
messagePreview: steeringMessagePreview(input.message),
|
|
77
|
-
targets: input.targets.map((target) => ({ index: target.index, state: target.state, ...target.reason ? { reason: target.reason } : {} }))
|
|
79
|
+
targets: input.targets.map((target) => ({ index: target.index, state: target.state, ...target.reason ? { reason: target.reason } : {}, ...target.failureKind ? { failureKind: target.failureKind } : {} }))
|
|
78
80
|
};
|
|
79
81
|
status.requested++;
|
|
80
82
|
status.lastRequestedAt = input.requestedAt;
|
|
@@ -93,6 +95,8 @@ function updateSteeringTarget(status, requestId, index, state, now, fields = {})
|
|
|
93
95
|
const request = status.recent.find((candidate) => candidate.id === requestId);
|
|
94
96
|
const target = request?.targets.find((candidate) => candidate.index === index);
|
|
95
97
|
if (!target) return void 0;
|
|
98
|
+
if (state !== "failed") delete target.failureKind;
|
|
99
|
+
else if (fields.failureKind) target.failureKind = fields.failureKind;
|
|
96
100
|
if (state === "late" && target.state === "recovered") {
|
|
97
101
|
if (target.lateDeliveredAt === void 0) {
|
|
98
102
|
target.lateDeliveredAt = now;
|
|
@@ -142,6 +146,7 @@ function actionResultFromSteeringStatus(status, sourceRunId, requestId, replacem
|
|
|
142
146
|
...target.deliveredAt !== void 0 ? { deliveredAt: target.deliveredAt } : {},
|
|
143
147
|
...target.lateDeliveredAt !== void 0 ? { lateDeliveredAt: target.lateDeliveredAt } : {},
|
|
144
148
|
...target.reason ? { reason: target.reason } : {},
|
|
149
|
+
...target.failureKind ? { failureKind: target.failureKind } : {},
|
|
145
150
|
...target.replacementRunId ? { replacementRunId: target.replacementRunId } : {}
|
|
146
151
|
}));
|
|
147
152
|
const states = targets.map((target) => target.state);
|
|
@@ -238,6 +243,9 @@ function steerTargetsAccepted(result2) {
|
|
|
238
243
|
const targets = result2?.targets ?? [];
|
|
239
244
|
return targets.length > 0 && targets.every((target) => target.state === "queued" || target.state === "delivered");
|
|
240
245
|
}
|
|
246
|
+
function steerTargetsRejected(result2) {
|
|
247
|
+
return result2?.targets.some((target) => target.state === "failed" && target.failureKind === "rejected") === true;
|
|
248
|
+
}
|
|
241
249
|
function canQueueRetainedAsyncFollowUp(status, index) {
|
|
242
250
|
const steps = status.steps ?? [];
|
|
243
251
|
return status.state === "complete" && Boolean(status.parentWorkflowRunId) && steps.length === 1 && (steps[0]?.status === "complete" || steps[0]?.status === "completed") && Boolean(steps[0]?.sessionFile ?? status.sessionFile) && (index === void 0 || index === 0);
|
|
@@ -375,8 +383,10 @@ ${replies}` }],
|
|
|
375
383
|
if (input.signal?.aborted) {
|
|
376
384
|
return { content: [{ type: "text", text: steeringReceipt(input.message, `Steering pending for async run ${status.runId} (request ${requestId}); caller aborted before recovery.`) }], details: { mode: "management", results: [], steering: result2 } };
|
|
377
385
|
}
|
|
386
|
+
const projected = (current) => current?.steering ? actionResultFromSteeringStatus(current.steering, status.runId, requestId) : void 0;
|
|
387
|
+
const rejected = () => new Error(`Child rejected the guidance; continue it with action "resume" and id "${status.runId}".`);
|
|
378
388
|
const finalStatus = readStatus(asyncDir);
|
|
379
|
-
const finalResult =
|
|
389
|
+
const finalResult = projected(finalStatus);
|
|
380
390
|
const acceptedReply = (accepted) => {
|
|
381
391
|
const acceptedState = accepted.state === "delivered" ? "delivered" : "queued";
|
|
382
392
|
return { content: [{ type: "text", text: steeringReceipt(input.message, `Steering ${acceptedState} for async run ${status.runId} (request ${requestId}).`) }], details: { mode: "management", results: [], steering: accepted } };
|
|
@@ -384,7 +394,7 @@ ${replies}` }],
|
|
|
384
394
|
if (finalResult && steerTargetsAccepted(finalResult)) return acceptedReply(finalResult);
|
|
385
395
|
const running = (finalStatus?.steps ?? status.steps ?? []).filter((step) => step.status === "running");
|
|
386
396
|
const recoveryAllowed = (input.mode ?? "steer") === "steer" && status.mode === "single" && status.isNested !== true && running.length === 1 && Boolean(finalStatus?.steering) && (input.index === void 0 || input.index === 0);
|
|
387
|
-
if (recoveryAllowed && finalResult?.state !== "scheduled" && input.recover) {
|
|
397
|
+
if (recoveryAllowed && finalResult?.state !== "scheduled" && !steerTargetsRejected(finalResult) && input.recover) {
|
|
388
398
|
const appendSteeringNotice = (state, message) => {
|
|
389
399
|
try {
|
|
390
400
|
fs2.appendFileSync(path2.join(asyncDir, "events.jsonl"), `${JSON.stringify({ type: "subagent.steering.notice", ts: Date.now(), runId: status.runId, requestId, state, message, ...status.sessionId ? { currentSessionId: status.sessionId } : {} })}
|
|
@@ -393,18 +403,18 @@ ${replies}` }],
|
|
|
393
403
|
}
|
|
394
404
|
};
|
|
395
405
|
try {
|
|
396
|
-
const
|
|
397
|
-
const latestResult = latest?.steering ? actionResultFromSteeringStatus(latest.steering, status.runId, requestId) : void 0;
|
|
406
|
+
const latestResult = projected(readStatus(asyncDir));
|
|
398
407
|
if (latestResult && steerTargetsAccepted(latestResult)) return acceptedReply(latestResult);
|
|
408
|
+
if (steerTargetsRejected(latestResult)) throw rejected();
|
|
399
409
|
const committedAt = Date.now();
|
|
400
410
|
input.onBeforeRecoveryClaim?.(requestId, committedAt);
|
|
401
411
|
const { claimPath, markerPath } = claimSteeringRecovery(asyncDir, { requestId, sourceRunId: status.runId, committedAt });
|
|
402
412
|
input.onRecoveryCommitted?.(requestId, committedAt);
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
if (preCommitResult && preCommitResult.targets.length > 0 && preCommitResult.targets.every((target) => target.state === "queued" || target.deliveredAt !== void 0 && target.deliveredAt <= committedAt)) {
|
|
413
|
+
const preCommitResult = projected(readStatus(asyncDir));
|
|
414
|
+
if (preCommitResult && (steerTargetsRejected(preCommitResult) || preCommitResult.targets.length > 0 && preCommitResult.targets.every((target) => target.state === "queued" || target.deliveredAt !== void 0 && target.deliveredAt <= committedAt))) {
|
|
406
415
|
fs2.rmSync(markerPath, { force: true });
|
|
407
416
|
fs2.rmSync(claimPath, { force: true });
|
|
417
|
+
if (steerTargetsRejected(preCommitResult)) throw rejected();
|
|
408
418
|
return acceptedReply(preCommitResult);
|
|
409
419
|
}
|
|
410
420
|
try {
|
|
@@ -422,6 +432,10 @@ ${replies}` }],
|
|
|
422
432
|
if (input.signal?.aborted) break;
|
|
423
433
|
const candidate = readStatus(asyncDir);
|
|
424
434
|
lastObservedState = candidate?.state;
|
|
435
|
+
if (steerTargetsRejected(projected(candidate))) {
|
|
436
|
+
fs2.rmSync(claimPath, { force: true });
|
|
437
|
+
throw rejected();
|
|
438
|
+
}
|
|
425
439
|
if (candidate?.state === "paused" && candidate.endedAt !== void 0) {
|
|
426
440
|
paused = candidate;
|
|
427
441
|
break;
|
|
@@ -445,6 +459,10 @@ ${replies}` }],
|
|
|
445
459
|
if (recoveryTarget.kind !== "revive" || !recoveryTarget.sessionFile) throw new Error("Source run has no valid persisted child session; it remains paused and requires a new run.");
|
|
446
460
|
if (!recoveryTarget.recoveryDescriptor) throw new Error("Source run has no private recovery descriptor; it remains paused and is not safely resumable.");
|
|
447
461
|
const limits = remainingSteeringRecoveryLimits(recoveryTarget.recoveryDescriptor, paused);
|
|
462
|
+
if (steerTargetsRejected(projected(readStatus(asyncDir)))) {
|
|
463
|
+
fs2.rmSync(claimPath, { force: true });
|
|
464
|
+
throw rejected();
|
|
465
|
+
}
|
|
448
466
|
const revived = await input.recover(limits);
|
|
449
467
|
if (revived.isError || !revived.details.asyncId) throw new Error(revived.content[0]?.type === "text" ? revived.content[0].text : "Replacement launch failed; source run remains paused.");
|
|
450
468
|
const targetIndex = input.index ?? paused.steering?.recent.find((request) => request.id === requestId)?.targets[0]?.index ?? status.steps?.findIndex((step) => step.status === "running") ?? -1;
|
|
@@ -468,7 +486,7 @@ ${replies}` }],
|
|
|
468
486
|
failedStatus.activityState = "needs_attention";
|
|
469
487
|
writeAtomicJson(path2.join(asyncDir, "status.json"), failedStatus);
|
|
470
488
|
}
|
|
471
|
-
const failed =
|
|
489
|
+
const failed = projected(failedStatus);
|
|
472
490
|
appendSteeringNotice("failed", `Steering failed for run ${status.runId}: ${reason}`);
|
|
473
491
|
return { content: [{ type: "text", text: steeringReceipt(input.message, `Steering failed for async run ${status.runId} (request ${requestId}): ${reason}`) }], isError: true, details: { mode: "management", results: [], steering: failed ?? { requestId, state: "failed", sourceRunId: status.runId, deliveryStatus: "queued", targets: [{ index: input.index ?? 0, state: "failed", reason }] } } };
|
|
474
492
|
}
|
|
@@ -603,15 +621,12 @@ async function steerWorkflowForegroundTarget(input) {
|
|
|
603
621
|
return { content: [{ type: "text", text: steeringReceipt(message, `Steering failed for foreground run ${control.runId} (request ${requestId}): ${outcome.reason ?? "unknown error"}`) }], isError: true, details: { mode: "management", results: [], steering } };
|
|
604
622
|
}
|
|
605
623
|
|
|
606
|
-
// src/
|
|
624
|
+
// src/shared/fleet-transcript-reader.ts
|
|
607
625
|
import * as fs3 from "node:fs";
|
|
608
626
|
import * as path4 from "node:path";
|
|
609
|
-
import { getLanguageFromPath, highlightCode } from "@earendil-works/pi-coding-agent";
|
|
610
|
-
import { Markdown, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
611
627
|
var DEFAULT_MAX_RECORDS = 240;
|
|
612
628
|
var DEFAULT_MAX_BYTES = 2 * 1024 * 1024;
|
|
613
629
|
var MAX_MESSAGE_CHARS = 64 * 1024;
|
|
614
|
-
var TOOL_PREVIEW_LINES = 7;
|
|
615
630
|
function sanitizeJsonDisplayValue(value) {
|
|
616
631
|
if (typeof value === "string") {
|
|
617
632
|
const safe = safeTerminalText(value);
|
|
@@ -895,185 +910,6 @@ function readFleetTranscript(filePath, options) {
|
|
|
895
910
|
...warnings.length ? { warning: safeTerminalText(warnings.join(" ")) } : {}
|
|
896
911
|
};
|
|
897
912
|
}
|
|
898
|
-
function readTranscriptRecords(filePath, options) {
|
|
899
|
-
const validated = validateTranscriptPath(filePath, options.trustedRoots);
|
|
900
|
-
if (!validated.resolvedPath) {
|
|
901
|
-
return { records: [], truncated: false, readFailed: true, ...validated.warning ? { warning: safeTerminalText(validated.warning) } : {} };
|
|
902
|
-
}
|
|
903
|
-
const maxRecords = Math.max(1, options.maxRecords ?? DEFAULT_MAX_RECORDS);
|
|
904
|
-
const tail = readTailLines(validated.resolvedPath, Math.max(1024, options.maxBytes ?? DEFAULT_MAX_BYTES));
|
|
905
|
-
const selected = tail.lines.slice(-maxRecords);
|
|
906
|
-
const records = [];
|
|
907
|
-
let malformed = 0;
|
|
908
|
-
for (const line of selected) {
|
|
909
|
-
if (!line.trim()) continue;
|
|
910
|
-
try {
|
|
911
|
-
const parsed = JSON.parse(line);
|
|
912
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
913
|
-
records.push(parsed);
|
|
914
|
-
} else {
|
|
915
|
-
malformed++;
|
|
916
|
-
}
|
|
917
|
-
} catch {
|
|
918
|
-
malformed++;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
const warnings = [
|
|
922
|
-
tail.warning,
|
|
923
|
-
malformed > 0 ? `Skipped ${malformed} malformed transcript record${malformed === 1 ? "" : "s"}.` : void 0
|
|
924
|
-
].filter((value) => Boolean(value));
|
|
925
|
-
return {
|
|
926
|
-
records,
|
|
927
|
-
...tail.warning ? { readFailed: true } : {},
|
|
928
|
-
truncated: tail.truncated || tail.lines.length > maxRecords,
|
|
929
|
-
...warnings.length ? { warning: safeTerminalText(warnings.join(" ")) } : {}
|
|
930
|
-
};
|
|
931
|
-
}
|
|
932
|
-
function statusGlyph(event, theme) {
|
|
933
|
-
if (event.status === "running") return theme.fg("warning", "\u25CF");
|
|
934
|
-
if (event.status === "error") return theme.fg("error", "\u2717");
|
|
935
|
-
return theme.fg("success", "\u2713");
|
|
936
|
-
}
|
|
937
|
-
function jsonScalar(value) {
|
|
938
|
-
if (typeof value === "string" && value.trim()) return value;
|
|
939
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
940
|
-
return void 0;
|
|
941
|
-
}
|
|
942
|
-
function parseToolArgs(event) {
|
|
943
|
-
if (!event.argsPayload) return void 0;
|
|
944
|
-
try {
|
|
945
|
-
return objectValue(JSON.parse(event.argsPayload));
|
|
946
|
-
} catch {
|
|
947
|
-
return void 0;
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
function toolDuration(event) {
|
|
951
|
-
if (event.startedAt === void 0 || event.endedAt === void 0) return void 0;
|
|
952
|
-
return `${((event.endedAt - event.startedAt) / 1e3).toFixed(1)}s`;
|
|
953
|
-
}
|
|
954
|
-
function renderExpandedTool(event, width, theme) {
|
|
955
|
-
const lines = [];
|
|
956
|
-
const args = parseToolArgs(event);
|
|
957
|
-
const glyph = statusGlyph(event, theme);
|
|
958
|
-
const output = event.output ?? event.error;
|
|
959
|
-
const outputColor = event.status === "error" ? "error" : "toolOutput";
|
|
960
|
-
if (event.name === "bash") {
|
|
961
|
-
const command = jsonScalar(args?.command) ?? event.args ?? "(unknown command)";
|
|
962
|
-
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(`$ ${command}`))}`, width, theme));
|
|
963
|
-
if (output) {
|
|
964
|
-
for (const outputLine of output.replace(/\s+$/, "").split(/\r?\n/)) {
|
|
965
|
-
for (const wrapped of renderWrapped(theme.fg(outputColor, outputLine), Math.max(1, width - 4))) {
|
|
966
|
-
lines.push(railLine(` ${wrapped}`, width, theme));
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
const duration = toolDuration(event);
|
|
971
|
-
if (duration) lines.push(railLine(theme.fg("dim", ` Took ${duration}`), width, theme));
|
|
972
|
-
return lines;
|
|
973
|
-
}
|
|
974
|
-
if (event.name === "read") {
|
|
975
|
-
const filePath = jsonScalar(args?.path ?? args?.file_path);
|
|
976
|
-
const language = filePath ? getLanguageFromPath(filePath) : void 0;
|
|
977
|
-
const rendered = !output ? [] : event.status === "error" ? output.split("\n").map((line) => theme.fg("error", line)) : language ? highlightCode(output, language) : output.split("\n");
|
|
978
|
-
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(`read ${filePath ?? event.args ?? ""}`))}`, width, theme));
|
|
979
|
-
for (const line of rendered) {
|
|
980
|
-
for (const wrapped of renderWrapped(line, Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
981
|
-
}
|
|
982
|
-
return lines;
|
|
983
|
-
}
|
|
984
|
-
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(event.name))}`, width, theme));
|
|
985
|
-
if (event.argsPayload) {
|
|
986
|
-
lines.push(railLine(theme.fg("dim", " args"), width, theme));
|
|
987
|
-
for (const argLine of event.argsPayload.split(/\r?\n/)) {
|
|
988
|
-
for (const wrapped of renderWrapped(theme.fg("muted", argLine), Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
if (output) {
|
|
992
|
-
lines.push(railLine(theme.fg(event.status === "error" ? "error" : "dim", event.status === "error" ? " error" : " output"), width, theme));
|
|
993
|
-
for (const outputLine of output.split(/\r?\n/)) {
|
|
994
|
-
for (const wrapped of renderWrapped(theme.fg(outputColor, outputLine), Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
return lines;
|
|
998
|
-
}
|
|
999
|
-
function bounded(text, width) {
|
|
1000
|
-
return truncateToWidth(text, Math.max(0, width));
|
|
1001
|
-
}
|
|
1002
|
-
function railLine(content, width, theme) {
|
|
1003
|
-
return bounded(`${theme.fg("borderMuted", "\u2502")} ${content}`, width);
|
|
1004
|
-
}
|
|
1005
|
-
function renderWrapped(text, width) {
|
|
1006
|
-
return wrapTextWithAnsi(text, Math.max(1, width));
|
|
1007
|
-
}
|
|
1008
|
-
function renderFleetTranscript(transcript, width, theme, markdownTheme, options = {}) {
|
|
1009
|
-
if (width <= 0) return [];
|
|
1010
|
-
const lines = [];
|
|
1011
|
-
if (transcript.truncated) lines.push(bounded(theme.fg("dim", "\u2191 Earlier activity omitted"), width));
|
|
1012
|
-
if (transcript.warning) {
|
|
1013
|
-
for (const line of renderWrapped(safeTerminalText(transcript.warning), Math.max(1, width - 2))) {
|
|
1014
|
-
lines.push(bounded(`${theme.fg("warning", "!")} ${theme.fg("warning", line)}`, width));
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
for (const rawEvent of transcript.events) {
|
|
1018
|
-
const event = safeTranscriptEvent(rawEvent);
|
|
1019
|
-
if (event.kind === "tool") {
|
|
1020
|
-
if (options.expandedTools && (event.output || event.argsPayload || event.error)) {
|
|
1021
|
-
lines.push(...renderExpandedTool(event, width, theme));
|
|
1022
|
-
lines.push(railLine(theme.fg("dim", " x to collapse"), width, theme));
|
|
1023
|
-
continue;
|
|
1024
|
-
}
|
|
1025
|
-
const title = theme.fg("toolTitle", theme.bold(event.name));
|
|
1026
|
-
const args = event.args ? ` ${theme.fg("dim", event.args)}` : "";
|
|
1027
|
-
const suffix = event.status === "running" ? theme.fg("warning", " running") : "";
|
|
1028
|
-
lines.push(bounded(`${theme.fg("borderMuted", "\u251C\u2500")} ${statusGlyph(event, theme)} ${title}${args}${suffix}`, width));
|
|
1029
|
-
if (event.output && event.status !== "error" && event.name === "bash") {
|
|
1030
|
-
const outputLines = event.output.replace(/\s+$/, "").split(/\r?\n/);
|
|
1031
|
-
const visible = outputLines.slice(-TOOL_PREVIEW_LINES);
|
|
1032
|
-
const hidden = Math.max(0, outputLines.length - visible.length);
|
|
1033
|
-
for (const outputLine of visible) {
|
|
1034
|
-
for (const wrapped of renderWrapped(theme.fg("toolOutput", outputLine), Math.max(1, width - 4))) {
|
|
1035
|
-
lines.push(railLine(` ${wrapped}`, width, theme));
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
if (hidden > 0) lines.push(railLine(theme.fg("dim", ` \u2026 ${hidden} earlier lines \xB7 x to expand`), width, theme));
|
|
1039
|
-
const duration = toolDuration(event);
|
|
1040
|
-
lines.push(railLine(theme.fg("dim", ` Took${duration ? ` ${duration}` : ""}`), width, theme));
|
|
1041
|
-
} else if (event.output && event.status !== "error") {
|
|
1042
|
-
const summary = truncateToWidth(event.output.replace(/\s+/g, " ").trim(), Math.max(1, width - 18), "\u2026");
|
|
1043
|
-
if (summary) lines.push(railLine(theme.fg("dim", ` ${summary} \xB7 x to expand`), width, theme));
|
|
1044
|
-
}
|
|
1045
|
-
if (event.error) {
|
|
1046
|
-
for (const errorLine of renderWrapped(event.error, Math.max(1, width - 4))) {
|
|
1047
|
-
lines.push(railLine(theme.fg("error", ` ${errorLine}`), width, theme));
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
continue;
|
|
1051
|
-
}
|
|
1052
|
-
if (event.kind === "notice") {
|
|
1053
|
-
const color = event.tone === "error" ? "error" : event.tone === "warning" ? "warning" : "dim";
|
|
1054
|
-
for (const noticeLine of renderWrapped(event.text, Math.max(1, width - 2))) {
|
|
1055
|
-
lines.push(railLine(theme.fg(color, noticeLine), width, theme));
|
|
1056
|
-
}
|
|
1057
|
-
continue;
|
|
1058
|
-
}
|
|
1059
|
-
const assistant = event.kind === "assistant";
|
|
1060
|
-
const label = assistant ? "Assistant" : "Supervisor";
|
|
1061
|
-
const marker = assistant ? theme.fg("accent", "\u25C6") : theme.fg("warning", "\u25C7");
|
|
1062
|
-
const model = assistant && event.model ? theme.fg("dim", ` \xB7 ${event.model}`) : "";
|
|
1063
|
-
lines.push(bounded(`${marker} ${theme.bold(label)}${model}`, width));
|
|
1064
|
-
if (assistant) {
|
|
1065
|
-
const rendered = new Markdown(event.text, 0, 0, markdownTheme).render(Math.max(1, width - 2));
|
|
1066
|
-
for (const markdownLine of rendered) lines.push(railLine(markdownLine, width, theme));
|
|
1067
|
-
} else {
|
|
1068
|
-
for (const userLine of renderWrapped(event.text, Math.max(1, width - 2))) {
|
|
1069
|
-
lines.push(railLine(userLine, width, theme));
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
lines.push(theme.fg("borderMuted", "\u2502"));
|
|
1073
|
-
}
|
|
1074
|
-
while (lines.length > 0 && visibleWidth(lines.at(-1) ?? "") === 1) lines.pop();
|
|
1075
|
-
return lines;
|
|
1076
|
-
}
|
|
1077
913
|
|
|
1078
914
|
// src/inspectors/types.ts
|
|
1079
915
|
var INSPECTOR_ACTIONS = ["inspector.open", "inspector.command", "inspector.status", "inspector.close"];
|
|
@@ -1265,6 +1101,7 @@ async function rewritePromptWithGuidance(input) {
|
|
|
1265
1101
|
});
|
|
1266
1102
|
const ctxThinking = input.ctx.getThinkingLevel?.();
|
|
1267
1103
|
const agent = new Agent({
|
|
1104
|
+
sessionId,
|
|
1268
1105
|
initialState: {
|
|
1269
1106
|
systemPrompt: [
|
|
1270
1107
|
"Rewrite one subagent authored task from Prompt Audit context.",
|
|
@@ -1360,8 +1197,6 @@ export {
|
|
|
1360
1197
|
steerWorkflowRun,
|
|
1361
1198
|
steerWorkflowForegroundTarget,
|
|
1362
1199
|
readFleetTranscript,
|
|
1363
|
-
readTranscriptRecords,
|
|
1364
|
-
renderFleetTranscript,
|
|
1365
1200
|
INSPECTOR_ACTIONS,
|
|
1366
1201
|
handleInspectorAction,
|
|
1367
1202
|
rewritePromptWithGuidance,
|