@fitchmultz/pi-subagents 0.0.0-stage → 0.44.5
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 +1654 -0
- package/LICENSE +21 -0
- package/README.md +1533 -2
- package/agents/context-builder.md +97 -0
- package/agents/debugger.md +51 -0
- package/agents/delegate.md +13 -0
- package/agents/fixer.md +37 -0
- package/agents/oracle.md +71 -0
- package/agents/planner.md +72 -0
- package/agents/researcher.md +51 -0
- package/agents/reviewer-claude.md +69 -0
- package/agents/reviewer-gpt.md +68 -0
- package/agents/reviewer-ponytail.md +82 -0
- package/agents/reviewer-security.md +81 -0
- package/agents/reviewer.md +69 -0
- package/agents/scout.md +66 -0
- package/agents/ui-designer.md +51 -0
- package/agents/watcher.md +26 -0
- package/agents/worker.md +46 -0
- package/agents/writer.md +36 -0
- package/dist/agents/agent-management.js +923 -0
- package/dist/agents/agent-scope.js +7 -0
- package/dist/agents/agent-selection.js +20 -0
- package/dist/agents/agent-serializer.js +100 -0
- package/dist/agents/agents.js +752 -0
- package/dist/agents/chain-serializer.js +367 -0
- package/dist/agents/frontmatter.js +21 -0
- package/dist/agents/identity.js +29 -0
- package/dist/agents/skills.js +570 -0
- package/dist/extension/build-info.js +1 -0
- package/dist/extension/compact-tools.js +112 -0
- package/dist/extension/config.js +22 -0
- package/dist/extension/control-notices.js +29 -0
- package/dist/extension/doctor.js +143 -0
- package/dist/extension/fanout-child.js +326 -0
- package/dist/extension/index.js +577 -0
- package/dist/extension/schemas.js +416 -0
- package/dist/extension/tool-input.js +20 -0
- package/dist/extension/tool-result.js +14 -0
- package/dist/history/canonical-result.js +81 -0
- package/dist/history/database.js +72 -0
- package/dist/history/index.js +199 -0
- package/dist/history/ingest.js +468 -0
- package/dist/history/queries.js +350 -0
- package/dist/history/store.js +216 -0
- package/dist/history/types.js +4 -0
- package/dist/history/worker.js +466 -0
- package/dist/intercom/intercom-bridge.js +112 -0
- package/dist/intercom/live-intercom.js +94 -0
- package/dist/intercom/result-intercom.js +373 -0
- package/dist/pi-intercom/agent-dir.js +10 -0
- package/dist/pi-intercom/bridge.js +750 -0
- package/dist/pi-intercom/broker/broker.js +426 -0
- package/dist/pi-intercom/broker/client.js +492 -0
- package/dist/pi-intercom/broker/framing.js +65 -0
- package/dist/pi-intercom/broker/paths.js +42 -0
- package/dist/pi-intercom/broker/pid.js +66 -0
- package/dist/pi-intercom/broker/spawn.js +221 -0
- package/dist/pi-intercom/config.js +102 -0
- package/dist/pi-intercom/index.js +2942 -0
- package/dist/pi-intercom/reply-tracker.js +182 -0
- package/dist/pi-intercom/session-targets.js +128 -0
- package/dist/pi-intercom/subagent-live-events.js +132 -0
- package/dist/pi-intercom/topics.js +157 -0
- package/dist/pi-intercom/types.js +163 -0
- package/dist/pi-intercom/ui/compose.js +269 -0
- package/dist/pi-intercom/ui/inline-message.js +80 -0
- package/dist/pi-intercom/ui/session-list.js +124 -0
- package/dist/runs/background/async-control.js +95 -0
- package/dist/runs/background/async-execution.js +676 -0
- package/dist/runs/background/async-job-tracker.js +383 -0
- package/dist/runs/background/async-result-file.js +58 -0
- package/dist/runs/background/async-resume.js +305 -0
- package/dist/runs/background/async-status.js +442 -0
- package/dist/runs/background/completion-dedupe.js +69 -0
- package/dist/runs/background/completion-delivery.js +245 -0
- package/dist/runs/background/notify.js +71 -0
- package/dist/runs/background/parallel-groups.js +55 -0
- package/dist/runs/background/result-watcher.js +426 -0
- package/dist/runs/background/run-id-resolver.js +64 -0
- package/dist/runs/background/run-status.js +382 -0
- package/dist/runs/background/stale-run-reconciler.js +335 -0
- package/dist/runs/background/subagent-runner-launcher.js +55 -0
- package/dist/runs/background/subagent-runner.js +1872 -0
- package/dist/runs/background/top-level-async.js +5 -0
- package/dist/runs/foreground/chain-clarify.js +1152 -0
- package/dist/runs/foreground/clarify-invocation.js +72 -0
- package/dist/runs/foreground/execution-input.js +423 -0
- package/dist/runs/foreground/foreground-control.js +817 -0
- package/dist/runs/foreground/question-control.js +88 -0
- package/dist/runs/foreground/run-async-path.js +205 -0
- package/dist/runs/foreground/subagent-executor.js +442 -0
- package/dist/runs/foreground/subagent-params.js +165 -0
- package/dist/runs/foreground/wait-run.js +141 -0
- package/dist/runs/shared/acceptance-contract.js +253 -0
- package/dist/runs/shared/acceptance-evaluation.js +256 -0
- package/dist/runs/shared/acceptance-finalization.js +280 -0
- package/dist/runs/shared/acceptance-reports.js +147 -0
- package/dist/runs/shared/acceptance.js +4 -0
- package/dist/runs/shared/chain-outputs.js +110 -0
- package/dist/runs/shared/child-attempt.js +693 -0
- package/dist/runs/shared/child-execution-cwd.js +96 -0
- package/dist/runs/shared/child-observations.js +114 -0
- package/dist/runs/shared/claude-code.js +199 -0
- package/dist/runs/shared/completion-guard.js +31 -0
- package/dist/runs/shared/dynamic-fanout.js +274 -0
- package/dist/runs/shared/history-index.js +72 -0
- package/dist/runs/shared/mcp-direct-tool-allowlist.js +334 -0
- package/dist/runs/shared/model-fallback.js +185 -0
- package/dist/runs/shared/mutating-tool-guard.js +170 -0
- package/dist/runs/shared/native-finalization.js +101 -0
- package/dist/runs/shared/native-usage.js +153 -0
- package/dist/runs/shared/nested-events.js +700 -0
- package/dist/runs/shared/nested-path.js +48 -0
- package/dist/runs/shared/nested-render.js +108 -0
- package/dist/runs/shared/parallel-utils.js +61 -0
- package/dist/runs/shared/parent-receipts.js +68 -0
- package/dist/runs/shared/parent-usage.js +121 -0
- package/dist/runs/shared/pi-args.js +310 -0
- package/dist/runs/shared/pi-spawn.js +52 -0
- package/dist/runs/shared/run-history-queries.js +45 -0
- package/dist/runs/shared/run-history.js +110 -0
- package/dist/runs/shared/run-id-ambiguity.js +4 -0
- package/dist/runs/shared/run-records.js +679 -0
- package/dist/runs/shared/session-cwd-preload.js +33 -0
- package/dist/runs/shared/single-output.js +222 -0
- package/dist/runs/shared/streaming-text.js +15 -0
- package/dist/runs/shared/structured-output.js +55 -0
- package/dist/runs/shared/subagent-control.js +179 -0
- package/dist/runs/shared/subagent-prompt-runtime.js +197 -0
- package/dist/runs/shared/subagent-tool-loop-guard.js +66 -0
- package/dist/runs/shared/supervisor-questions.js +350 -0
- package/dist/runs/shared/workflow-graph.js +214 -0
- package/dist/runs/shared/workflow-policy.js +84 -0
- package/dist/runs/shared/worktree.js +525 -0
- package/dist/shared/agent-context-policy.js +126 -0
- package/dist/shared/artifacts.js +96 -0
- package/dist/shared/atomic-json.js +13 -0
- package/dist/shared/cooperative.js +20 -0
- package/dist/shared/execution-cwd.js +14 -0
- package/dist/shared/file-coalescer.js +21 -0
- package/dist/shared/fork-context.js +49 -0
- package/dist/shared/formatters.js +85 -0
- package/dist/shared/journal-reader.js +407 -0
- package/dist/shared/lazy-tools.js +32 -0
- package/dist/shared/model-info.js +68 -0
- package/dist/shared/native-session.js +15 -0
- package/dist/shared/native-tui.js +18 -0
- package/dist/shared/native-typebox.js +20 -0
- package/dist/shared/post-exit-stdio-guard.js +197 -0
- package/dist/shared/prompt-sections.js +8 -0
- package/dist/shared/session-entries.js +52 -0
- package/dist/shared/session-identity.js +14 -0
- package/dist/shared/settings.js +254 -0
- package/dist/shared/status-format.js +111 -0
- package/dist/shared/temp-root.js +114 -0
- package/dist/shared/types.js +207 -0
- package/dist/shared/ui-mode.js +3 -0
- package/dist/shared/utils.js +334 -0
- package/dist/slash/prompt-template-bridge.js +298 -0
- package/dist/slash/slash-bridge.js +116 -0
- package/dist/slash/slash-commands.js +607 -0
- package/dist/slash/slash-live-state.js +246 -0
- package/dist/tui/action-hints.js +75 -0
- package/dist/tui/agent-history.js +197 -0
- package/dist/tui/agent-view.js +1656 -0
- package/dist/tui/render.js +1515 -0
- package/docs/intercom-bridge.md +212 -0
- package/docs/intercom.md +581 -0
- package/docs/performance.md +121 -0
- package/package.json +102 -4
- package/prompts/gather-context-and-clarify.md +14 -0
- package/prompts/parallel-cleanup.md +62 -0
- package/prompts/parallel-context-build.md +56 -0
- package/prompts/parallel-handoff-plan.md +62 -0
- package/prompts/parallel-research.md +51 -0
- package/prompts/parallel-review.md +59 -0
- package/prompts/review-loop.md +42 -0
- package/scripts/build.mjs +134 -0
- package/scripts/check-compat.mjs +48 -0
- package/scripts/compat-host.mjs +19 -0
- package/scripts/intercom-bridge-credentials.mjs +143 -0
- package/scripts/intercom-remote.mjs +103 -0
- package/scripts/linux-smoke.sh +51 -0
- package/scripts/local-install-smoke.mjs +66 -0
- package/scripts/native-package-smoke.mjs +82 -0
- package/scripts/package-smoke.mjs +209 -0
- package/scripts/prepare.mjs +67 -0
- package/scripts/real-pi-smoke.mjs +415 -0
- package/scripts/run-tests.mjs +149 -0
- package/skills/pi-intercom/SKILL.md +113 -0
- package/skills/pi-intercom/evals/evals.json +29 -0
- package/skills/pi-intercom/evals/trigger-evals.json +47 -0
- package/skills/pi-intercom/references/peer-sessions.md +69 -0
- package/skills/pi-subagents/SKILL.md +76 -0
- package/skills/pi-subagents/evals/evals.json +29 -0
- package/skills/pi-subagents/evals/trigger-evals.json +42 -0
- package/skills/pi-subagents/references/full-orchestration-guide.md +863 -0
- package/src/agents/agent-management.ts +813 -0
- package/src/agents/agent-scope.ts +7 -0
- package/src/agents/agent-selection.ts +23 -0
- package/src/agents/agent-serializer.ts +99 -0
- package/src/agents/agents.ts +916 -0
- package/src/agents/chain-serializer.ts +329 -0
- package/src/agents/frontmatter.ts +21 -0
- package/src/agents/identity.ts +30 -0
- package/src/agents/skills.ts +637 -0
- package/src/extension/build-info.ts +2 -0
- package/src/extension/compact-tools.ts +114 -0
- package/src/extension/config.ts +23 -0
- package/src/extension/control-notices.ts +47 -0
- package/src/extension/doctor.ts +171 -0
- package/src/extension/fanout-child.ts +312 -0
- package/src/extension/index.ts +649 -0
- package/src/extension/schemas.ts +444 -0
- package/src/extension/tool-input.ts +19 -0
- package/src/extension/tool-result.ts +16 -0
- package/src/history/canonical-result.ts +62 -0
- package/src/history/database.ts +59 -0
- package/src/history/index.ts +156 -0
- package/src/history/ingest.ts +349 -0
- package/src/history/queries.ts +241 -0
- package/src/history/store.ts +203 -0
- package/src/history/types.ts +166 -0
- package/src/history/worker.ts +321 -0
- package/src/intercom/intercom-bridge.ts +123 -0
- package/src/intercom/live-intercom.ts +104 -0
- package/src/intercom/result-intercom.ts +429 -0
- package/src/pi-intercom/agent-dir.ts +9 -0
- package/src/pi-intercom/bridge.ts +668 -0
- package/src/pi-intercom/broker/broker.ts +463 -0
- package/src/pi-intercom/broker/client.ts +558 -0
- package/src/pi-intercom/broker/framing.ts +77 -0
- package/src/pi-intercom/broker/paths.ts +47 -0
- package/src/pi-intercom/broker/pid.ts +59 -0
- package/src/pi-intercom/broker/spawn.ts +248 -0
- package/src/pi-intercom/config.ts +142 -0
- package/src/pi-intercom/index.ts +2929 -0
- package/src/pi-intercom/reply-tracker.ts +211 -0
- package/src/pi-intercom/session-targets.ts +172 -0
- package/src/pi-intercom/subagent-live-events.ts +133 -0
- package/src/pi-intercom/topics.ts +125 -0
- package/src/pi-intercom/types.ts +271 -0
- package/src/pi-intercom/ui/compose.ts +289 -0
- package/src/pi-intercom/ui/inline-message.ts +92 -0
- package/src/pi-intercom/ui/session-list.ts +139 -0
- package/src/runs/background/async-control.ts +89 -0
- package/src/runs/background/async-execution.ts +850 -0
- package/src/runs/background/async-job-tracker.ts +385 -0
- package/src/runs/background/async-result-file.ts +62 -0
- package/src/runs/background/async-resume.ts +333 -0
- package/src/runs/background/async-status.ts +481 -0
- package/src/runs/background/completion-dedupe.ts +79 -0
- package/src/runs/background/completion-delivery.ts +195 -0
- package/src/runs/background/notify.ts +123 -0
- package/src/runs/background/parallel-groups.ts +53 -0
- package/src/runs/background/result-watcher.ts +423 -0
- package/src/runs/background/run-id-resolver.ts +69 -0
- package/src/runs/background/run-status.ts +384 -0
- package/src/runs/background/stale-run-reconciler.ts +369 -0
- package/src/runs/background/subagent-runner-launcher.ts +56 -0
- package/src/runs/background/subagent-runner.ts +2053 -0
- package/src/runs/background/top-level-async.ts +13 -0
- package/src/runs/foreground/chain-clarify.ts +1340 -0
- package/src/runs/foreground/clarify-invocation.ts +77 -0
- package/src/runs/foreground/execution-input.ts +467 -0
- package/src/runs/foreground/foreground-control.ts +821 -0
- package/src/runs/foreground/question-control.ts +82 -0
- package/src/runs/foreground/run-async-path.ts +243 -0
- package/src/runs/foreground/subagent-executor.ts +501 -0
- package/src/runs/foreground/subagent-params.ts +320 -0
- package/src/runs/foreground/wait-run.ts +124 -0
- package/src/runs/shared/acceptance-contract.ts +257 -0
- package/src/runs/shared/acceptance-evaluation.ts +275 -0
- package/src/runs/shared/acceptance-finalization.ts +353 -0
- package/src/runs/shared/acceptance-reports.ts +152 -0
- package/src/runs/shared/acceptance.ts +33 -0
- package/src/runs/shared/chain-outputs.ts +114 -0
- package/src/runs/shared/child-attempt.ts +623 -0
- package/src/runs/shared/child-execution-cwd.ts +91 -0
- package/src/runs/shared/child-observations.ts +99 -0
- package/src/runs/shared/claude-code.ts +243 -0
- package/src/runs/shared/completion-guard.ts +35 -0
- package/src/runs/shared/dynamic-fanout.ts +295 -0
- package/src/runs/shared/history-index.ts +69 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +376 -0
- package/src/runs/shared/model-fallback.ts +219 -0
- package/src/runs/shared/mutating-tool-guard.ts +194 -0
- package/src/runs/shared/native-finalization.ts +128 -0
- package/src/runs/shared/native-usage.ts +113 -0
- package/src/runs/shared/nested-events.ts +752 -0
- package/src/runs/shared/nested-path.ts +52 -0
- package/src/runs/shared/nested-render.ts +119 -0
- package/src/runs/shared/parallel-utils.ts +153 -0
- package/src/runs/shared/parent-receipts.ts +59 -0
- package/src/runs/shared/parent-usage.ts +121 -0
- package/src/runs/shared/pi-args.ts +350 -0
- package/src/runs/shared/pi-spawn.ts +52 -0
- package/src/runs/shared/run-history-queries.ts +44 -0
- package/src/runs/shared/run-history.ts +100 -0
- package/src/runs/shared/run-id-ambiguity.ts +4 -0
- package/src/runs/shared/run-records.ts +607 -0
- package/src/runs/shared/session-cwd-preload.ts +27 -0
- package/src/runs/shared/single-output.ts +267 -0
- package/src/runs/shared/streaming-text.ts +18 -0
- package/src/runs/shared/structured-output.ts +68 -0
- package/src/runs/shared/subagent-control.ts +219 -0
- package/src/runs/shared/subagent-prompt-runtime.ts +201 -0
- package/src/runs/shared/subagent-tool-loop-guard.ts +89 -0
- package/src/runs/shared/supervisor-questions.ts +415 -0
- package/src/runs/shared/workflow-graph.ts +220 -0
- package/src/runs/shared/workflow-policy.ts +125 -0
- package/src/runs/shared/worktree.ts +635 -0
- package/src/shared/agent-context-policy.ts +184 -0
- package/src/shared/artifacts.ts +95 -0
- package/src/shared/atomic-json.ts +16 -0
- package/src/shared/cooperative.ts +21 -0
- package/src/shared/execution-cwd.ts +14 -0
- package/src/shared/file-coalescer.ts +29 -0
- package/src/shared/fork-context.ts +68 -0
- package/src/shared/formatters.ts +84 -0
- package/src/shared/journal-reader.ts +333 -0
- package/src/shared/lazy-tools.ts +36 -0
- package/src/shared/model-info.ts +81 -0
- package/src/shared/native-session.ts +8 -0
- package/src/shared/native-tui.ts +10 -0
- package/src/shared/native-typebox.ts +14 -0
- package/src/shared/post-exit-stdio-guard.ts +204 -0
- package/src/shared/prompt-sections.ts +10 -0
- package/src/shared/session-entries.ts +49 -0
- package/src/shared/session-identity.ts +18 -0
- package/src/shared/settings.ts +384 -0
- package/src/shared/status-format.ts +123 -0
- package/src/shared/temp-root.ts +107 -0
- package/src/shared/types.ts +1260 -0
- package/src/shared/ui-mode.ts +5 -0
- package/src/shared/utils.ts +342 -0
- package/src/slash/prompt-template-bridge.ts +408 -0
- package/src/slash/slash-bridge.ts +178 -0
- package/src/slash/slash-commands.ts +617 -0
- package/src/slash/slash-live-state.ts +292 -0
- package/src/tui/action-hints.ts +69 -0
- package/src/tui/agent-history.ts +210 -0
- package/src/tui/agent-view.ts +1323 -0
- package/src/tui/render.ts +1550 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { scanJournal } from "../../shared/journal-reader.ts";
|
|
5
|
+
import { renderWidget, widgetRenderKey } from "../../tui/render.ts";
|
|
6
|
+
import { formatControlNoticeMessage, isObsoleteIdleNotice } from "../shared/subagent-control.ts";
|
|
7
|
+
import {
|
|
8
|
+
type AsyncJobState,
|
|
9
|
+
type AsyncStartedEvent,
|
|
10
|
+
type ControlEvent,
|
|
11
|
+
type SubagentState,
|
|
12
|
+
POLL_INTERVAL_MS,
|
|
13
|
+
RESULTS_DIR,
|
|
14
|
+
SUBAGENT_CONTROL_EVENT,
|
|
15
|
+
SUBAGENT_CONTROL_INTERCOM_EVENT,
|
|
16
|
+
} from "../../shared/types.ts";
|
|
17
|
+
import { readStatus } from "../../shared/utils.ts";
|
|
18
|
+
import { normalizeParallelGroups } from "./parallel-groups.ts";
|
|
19
|
+
import { reconcileAsyncRun, reconcileNestedAsyncDescendants } from "./stale-run-reconciler.ts";
|
|
20
|
+
import { attachRootChildrenToSteps, findNestedRouteForRootId, hasLiveNestedDescendants } from "../shared/nested-events.ts";
|
|
21
|
+
import { asyncStatusToSummary, createAsyncRunDiscovery, listAsyncRuns } from "./async-status.ts";
|
|
22
|
+
import { isTuiContext } from "../../shared/ui-mode.ts";
|
|
23
|
+
import { exactAsyncRunLocation, type AsyncRunRecord } from "./async-resume.ts";
|
|
24
|
+
import type { OwnedRunRestoration } from "../shared/run-records.ts";
|
|
25
|
+
|
|
26
|
+
interface AsyncJobTrackerOptions {
|
|
27
|
+
render?: (ctx: ExtensionContext, jobs: AsyncJobState[]) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createAsyncJobTracker(pi: Pick<ExtensionAPI, "events">, state: SubagentState, asyncDirRoot: string, options: AsyncJobTrackerOptions = {}): {
|
|
31
|
+
ensurePoller: () => void;
|
|
32
|
+
handleStarted: (data: unknown) => void;
|
|
33
|
+
handleComplete: (data: unknown) => void;
|
|
34
|
+
restoreJobs: (sessionId: string, ctx: ExtensionContext, restoration?: OwnedRunRestoration) => void;
|
|
35
|
+
resetJobs: (ctx?: ExtensionContext) => void;
|
|
36
|
+
} {
|
|
37
|
+
const resultsDir = RESULTS_DIR;
|
|
38
|
+
let restoreDiscovery: (() => AsyncRunRecord[]) | undefined;
|
|
39
|
+
let restoreBoundary = 0;
|
|
40
|
+
let restoreDiscoveryDeadline = 0;
|
|
41
|
+
const rerenderWidget = (ctx: ExtensionContext, jobs = Array.from(state.asyncJobs.values())) => {
|
|
42
|
+
(options.render ?? renderWidget)(ctx, jobs);
|
|
43
|
+
const uiWithRender: ExtensionContext["ui"] & { requestRender?: () => void } = ctx.ui;
|
|
44
|
+
uiWithRender.requestRender?.();
|
|
45
|
+
};
|
|
46
|
+
const cancelCleanup = (asyncId: string) => {
|
|
47
|
+
const existingTimer = state.cleanupTimers.get(asyncId);
|
|
48
|
+
if (!existingTimer) return;
|
|
49
|
+
clearTimeout(existingTimer);
|
|
50
|
+
state.cleanupTimers.delete(asyncId);
|
|
51
|
+
};
|
|
52
|
+
const scheduleCleanup = (asyncId: string) => {
|
|
53
|
+
cancelCleanup(asyncId);
|
|
54
|
+
const timer = setTimeout(() => {
|
|
55
|
+
state.cleanupTimers.delete(asyncId);
|
|
56
|
+
state.asyncJobs.delete(asyncId);
|
|
57
|
+
if (state.lastUiContext) {
|
|
58
|
+
rerenderWidget(state.lastUiContext);
|
|
59
|
+
}
|
|
60
|
+
}, 10000);
|
|
61
|
+
state.cleanupTimers.set(asyncId, timer);
|
|
62
|
+
};
|
|
63
|
+
const emitNewControlEvents = (job: AsyncJobState) => {
|
|
64
|
+
const eventsPath = path.join(job.asyncDir, "events.jsonl");
|
|
65
|
+
try {
|
|
66
|
+
const stat = fs.statSync(eventsPath);
|
|
67
|
+
const identity = `${stat.dev}:${stat.ino}`;
|
|
68
|
+
if (job.controlEventIdentity !== identity || stat.size < (job.controlEventCursor ?? 0)) job.controlEventCursor = 0;
|
|
69
|
+
job.controlEventIdentity = identity;
|
|
70
|
+
if (stat.size === (job.controlEventCursor ?? 0)) return;
|
|
71
|
+
const cursor = scanJournal(eventsPath, (path) => !path.length || ["type", "event", "channels", "childIntercomTarget", "noticeText", "intercom"].includes(String(path[0])), ({ value, end }) => {
|
|
72
|
+
if (value?.type === "subagent.control") {
|
|
73
|
+
const record = value as { event?: ControlEvent; channels?: string[]; childIntercomTarget?: string; noticeText?: string; intercom?: { to?: string; message?: string } };
|
|
74
|
+
if (record.event?.type === "needs_attention" && Array.isArray(record.channels)
|
|
75
|
+
&& (job.controlEventSince === undefined || typeof record.event.ts === "number" && record.event.ts >= job.controlEventSince)) {
|
|
76
|
+
const payload = { event: record.event, source: "async" as const, asyncDir: job.asyncDir, childIntercomTarget: record.childIntercomTarget,
|
|
77
|
+
noticeText: record.noticeText ?? formatControlNoticeMessage(record.event, record.childIntercomTarget) };
|
|
78
|
+
if (!isObsoleteIdleNotice(payload)) {
|
|
79
|
+
if (record.channels.includes("event")) pi.events.emit(SUBAGENT_CONTROL_EVENT, payload);
|
|
80
|
+
if (record.channels.includes("intercom") && record.intercom?.to && record.intercom.message) pi.events.emit(SUBAGENT_CONTROL_INTERCOM_EVENT, { ...payload, to: record.intercom.to, message: record.intercom.message });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
job.controlEventCursor = end;
|
|
85
|
+
}, { policy: "live", start: job.controlEventCursor ?? 0 });
|
|
86
|
+
job.controlEventCursor = cursor;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") console.error(`Failed to read async control events for '${job.asyncDir}':`, error);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const refreshNestedJob = (job: AsyncJobState) => {
|
|
93
|
+
if (!job.nestedRoute) return;
|
|
94
|
+
job.nestedChildren = reconcileNestedAsyncDescendants(job.nestedRoute, { resultsDir });
|
|
95
|
+
attachRootChildrenToSteps(job.asyncId, job.steps, job.nestedChildren);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const ensurePoller = () => {
|
|
99
|
+
if (state.poller) return;
|
|
100
|
+
state.poller = setInterval(() => {
|
|
101
|
+
let widgetChanged = false;
|
|
102
|
+
let restoredRecords: AsyncRunRecord[] = [];
|
|
103
|
+
if (restoreDiscovery) {
|
|
104
|
+
try {
|
|
105
|
+
restoredRecords = restoreDiscovery();
|
|
106
|
+
widgetChanged = discoverRestoredJobs(restoredRecords, true);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error("Failed to discover active async jobs:", error);
|
|
109
|
+
}
|
|
110
|
+
if (Date.now() >= restoreDiscoveryDeadline) {
|
|
111
|
+
restoreDiscovery = undefined;
|
|
112
|
+
restoreDiscoveryDeadline = 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (state.asyncJobs.size === 0) {
|
|
116
|
+
if (restoreDiscovery) return;
|
|
117
|
+
if (state.lastUiContext && isTuiContext(state.lastUiContext)) rerenderWidget(state.lastUiContext, []);
|
|
118
|
+
if (state.poller) {
|
|
119
|
+
clearInterval(state.poller);
|
|
120
|
+
state.poller = null;
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const restoredByDir = new Map(restoredRecords.map((record) => [record.location.asyncDir, record]));
|
|
125
|
+
for (const job of state.asyncJobs.values()) {
|
|
126
|
+
const widgetStateBefore = widgetRenderKey(job);
|
|
127
|
+
let nestedRefreshFailed = false;
|
|
128
|
+
const refreshNestedProjection = () => {
|
|
129
|
+
try {
|
|
130
|
+
refreshNestedJob(job);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
nestedRefreshFailed = true;
|
|
133
|
+
console.error(`Failed to refresh nested async descendants for '${job.asyncDir}':`, error);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
emitNewControlEvents(job);
|
|
139
|
+
refreshNestedProjection();
|
|
140
|
+
const reconciliation = restoredByDir.get(job.asyncDir) ?? reconcileAsyncRun(job.asyncDir, {
|
|
141
|
+
resultsDir,
|
|
142
|
+
startedRun: {
|
|
143
|
+
runId: job.asyncId,
|
|
144
|
+
pid: job.pid,
|
|
145
|
+
sessionId: job.sessionId,
|
|
146
|
+
mode: job.mode,
|
|
147
|
+
agents: job.agents,
|
|
148
|
+
chainStepCount: job.chainStepCount,
|
|
149
|
+
parallelGroups: job.parallelGroups,
|
|
150
|
+
startedAt: job.startedAt,
|
|
151
|
+
sessionFile: job.sessionFile,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
const status = reconciliation.status ?? readStatus(job.asyncDir);
|
|
155
|
+
if (status) {
|
|
156
|
+
const summary = asyncStatusToSummary(job.asyncDir, status, [], job.nestedRoute ? job.nestedChildren ?? [] : undefined);
|
|
157
|
+
const previousStatus = job.status;
|
|
158
|
+
job.status = summary.state;
|
|
159
|
+
if (job.status !== "complete" && job.status !== "failed" && job.status !== "blocked" && job.status !== "paused") cancelCleanup(job.asyncId);
|
|
160
|
+
job.sessionId = summary.sessionId ?? job.sessionId;
|
|
161
|
+
job.activityState = summary.activityState;
|
|
162
|
+
job.lastActivityAt = summary.lastActivityAt ?? job.lastActivityAt;
|
|
163
|
+
job.currentTool = summary.currentTool;
|
|
164
|
+
job.currentToolStartedAt = summary.currentToolStartedAt;
|
|
165
|
+
job.currentPath = summary.currentPath;
|
|
166
|
+
job.turnCount = summary.turnCount ?? job.turnCount;
|
|
167
|
+
job.toolCount = summary.toolCount ?? job.toolCount;
|
|
168
|
+
job.mode = summary.mode;
|
|
169
|
+
job.currentStep = summary.currentStep ?? job.currentStep;
|
|
170
|
+
job.chainStepCount = summary.chainStepCount ?? job.chainStepCount;
|
|
171
|
+
job.startedAt = summary.startedAt;
|
|
172
|
+
if (summary.lastUpdate !== undefined) job.updatedAt = summary.lastUpdate;
|
|
173
|
+
if (summary.steps.length) {
|
|
174
|
+
const groups = summary.parallelGroups ?? [];
|
|
175
|
+
job.parallelGroups = groups.length ? groups : job.parallelGroups;
|
|
176
|
+
const activeGroup = summary.currentStep !== undefined
|
|
177
|
+
? groups.find((group) => summary.currentStep! >= group.start && summary.currentStep! < group.start + group.count)
|
|
178
|
+
: undefined;
|
|
179
|
+
const visibleSteps = activeGroup
|
|
180
|
+
? summary.steps.slice(activeGroup.start, activeGroup.start + activeGroup.count)
|
|
181
|
+
: summary.steps;
|
|
182
|
+
job.activeParallelGroup = Boolean(activeGroup);
|
|
183
|
+
job.agents = visibleSteps.map((step) => step.agent);
|
|
184
|
+
job.steps = visibleSteps;
|
|
185
|
+
attachRootChildrenToSteps(job.asyncId, job.steps, job.nestedChildren);
|
|
186
|
+
job.stepsTotal = visibleSteps.length;
|
|
187
|
+
job.runningSteps = visibleSteps.filter((step) => step.status === "running").length;
|
|
188
|
+
job.completedSteps = visibleSteps.filter((step) => step.status === "complete" || step.status === "completed").length;
|
|
189
|
+
if (summary.state === "complete") job.completedSteps = visibleSteps.length;
|
|
190
|
+
}
|
|
191
|
+
job.totalTokens = summary.totalTokens ?? job.totalTokens;
|
|
192
|
+
job.sessionFile = summary.sessionFile ?? job.sessionFile;
|
|
193
|
+
if ((job.status === "complete" || job.status === "failed" || job.status === "blocked" || job.status === "paused") && !nestedRefreshFailed && !hasLiveNestedDescendants(job.nestedChildren) && (previousStatus !== job.status || !state.cleanupTimers.has(job.asyncId))) {
|
|
194
|
+
scheduleCleanup(job.asyncId);
|
|
195
|
+
}
|
|
196
|
+
if (widgetRenderKey(job) !== widgetStateBefore) widgetChanged = true;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (job.status === "queued") {
|
|
200
|
+
job.status = "running";
|
|
201
|
+
job.updatedAt = Date.now();
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (job.status !== "failed") {
|
|
205
|
+
console.error(`Failed to read async status for '${job.asyncDir}':`, error);
|
|
206
|
+
job.status = "failed";
|
|
207
|
+
job.updatedAt = Date.now();
|
|
208
|
+
}
|
|
209
|
+
if (!hasLiveNestedDescendants(job.nestedChildren) && !state.cleanupTimers.has(job.asyncId)) {
|
|
210
|
+
scheduleCleanup(job.asyncId);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (widgetRenderKey(job) !== widgetStateBefore) widgetChanged = true;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (widgetChanged && state.lastUiContext && isTuiContext(state.lastUiContext)) rerenderWidget(state.lastUiContext);
|
|
217
|
+
}, POLL_INTERVAL_MS);
|
|
218
|
+
state.poller.unref?.();
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const handleStarted = (data: unknown) => {
|
|
222
|
+
const info = data as AsyncStartedEvent;
|
|
223
|
+
if (!info.id) return;
|
|
224
|
+
const now = Date.now();
|
|
225
|
+
const asyncDir = info.asyncDir ?? exactAsyncRunLocation(info.id, asyncDirRoot, resultsDir).asyncDir ?? path.join(asyncDirRoot, info.id);
|
|
226
|
+
const rawAgents = info.agents?.length ? info.agents : info.chain && info.chain.length > 0 ? info.chain : info.agent ? [info.agent] : undefined;
|
|
227
|
+
const validParallelGroups = normalizeParallelGroups(info.parallelGroups, Number.MAX_SAFE_INTEGER, info.chainStepCount ?? Number.MAX_SAFE_INTEGER);
|
|
228
|
+
const firstGroup = validParallelGroups.find((group) => group.start === 0);
|
|
229
|
+
const firstGroupCount = firstGroup?.count;
|
|
230
|
+
const agents = firstGroupCount && firstGroupCount > 0
|
|
231
|
+
? rawAgents?.slice(0, firstGroupCount)
|
|
232
|
+
: rawAgents;
|
|
233
|
+
state.asyncJobs.set(info.id, {
|
|
234
|
+
asyncId: info.id,
|
|
235
|
+
asyncDir,
|
|
236
|
+
status: "queued",
|
|
237
|
+
pid: typeof info.pid === "number" ? info.pid : undefined,
|
|
238
|
+
...(typeof info.sessionId === "string" ? { sessionId: info.sessionId } : {}),
|
|
239
|
+
mode: info.mode ?? (info.chain ? "chain" : "single"),
|
|
240
|
+
agents,
|
|
241
|
+
chainStepCount: info.chainStepCount,
|
|
242
|
+
parallelGroups: validParallelGroups,
|
|
243
|
+
nestedRoute: info.nestedRoute,
|
|
244
|
+
stepsTotal: firstGroupCount ?? agents?.length,
|
|
245
|
+
activeParallelGroup: Boolean(firstGroupCount && firstGroupCount > 0),
|
|
246
|
+
startedAt: now,
|
|
247
|
+
updatedAt: now,
|
|
248
|
+
});
|
|
249
|
+
ensurePoller();
|
|
250
|
+
if (state.lastUiContext && isTuiContext(state.lastUiContext)) {
|
|
251
|
+
rerenderWidget(state.lastUiContext);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const handleComplete = (data: unknown) => {
|
|
256
|
+
const result = data as { id?: string; success?: boolean; state?: string; asyncDir?: string };
|
|
257
|
+
const asyncId = result.id;
|
|
258
|
+
if (!asyncId) return;
|
|
259
|
+
const job = state.asyncJobs.get(asyncId);
|
|
260
|
+
let nestedRefreshFailed = false;
|
|
261
|
+
if (job) {
|
|
262
|
+
job.status = result.state === "blocked" ? "blocked" : result.state === "paused" ? "paused" : result.success ? "complete" : "failed";
|
|
263
|
+
job.updatedAt = Date.now();
|
|
264
|
+
if (result.asyncDir) job.asyncDir = result.asyncDir;
|
|
265
|
+
try {
|
|
266
|
+
refreshNestedJob(job);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
nestedRefreshFailed = true;
|
|
269
|
+
console.error(`Failed to refresh nested async descendants for '${job.asyncDir}':`, error);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (state.lastUiContext && isTuiContext(state.lastUiContext)) {
|
|
273
|
+
rerenderWidget(state.lastUiContext);
|
|
274
|
+
}
|
|
275
|
+
if (!nestedRefreshFailed && !hasLiveNestedDescendants(job?.nestedChildren)) scheduleCleanup(asyncId);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const discoverRestoredJobs = (records: AsyncRunRecord[], sinceBoundary: boolean): boolean => {
|
|
279
|
+
let changed = false;
|
|
280
|
+
for (const run of listAsyncRuns(asyncDirRoot, {
|
|
281
|
+
states: ["queued", "running"],
|
|
282
|
+
records,
|
|
283
|
+
resultsDir,
|
|
284
|
+
skipInvalid: true,
|
|
285
|
+
})) {
|
|
286
|
+
if (state.asyncJobs.has(run.id)) continue;
|
|
287
|
+
const groups = run.parallelGroups ?? [];
|
|
288
|
+
const activeGroup = run.currentStep !== undefined
|
|
289
|
+
? groups.find((group) => run.currentStep! >= group.start && run.currentStep! < group.start + group.count)
|
|
290
|
+
: undefined;
|
|
291
|
+
const steps = activeGroup
|
|
292
|
+
? run.steps.slice(activeGroup.start, activeGroup.start + activeGroup.count)
|
|
293
|
+
: run.steps;
|
|
294
|
+
let controlEventCursor = 0;
|
|
295
|
+
let controlEventSince: number | undefined = sinceBoundary ? restoreBoundary : undefined;
|
|
296
|
+
// Shared discovery has already started. An EOF observed now could swallow
|
|
297
|
+
// attention appended during it; late publications use the same original cut.
|
|
298
|
+
if (!sinceBoundary) try {
|
|
299
|
+
controlEventCursor = fs.statSync(path.join(run.asyncDir, "events.jsonl")).size;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
|
|
302
|
+
controlEventSince = restoreBoundary;
|
|
303
|
+
console.error(`Failed to inspect async control events for '${run.asyncDir}':`, error);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
let nestedRoute: ReturnType<typeof findNestedRouteForRootId>;
|
|
307
|
+
try {
|
|
308
|
+
nestedRoute = findNestedRouteForRootId(run.id);
|
|
309
|
+
} catch (error) {
|
|
310
|
+
console.error(`Failed to restore nested async descendants for '${run.asyncDir}':`, error);
|
|
311
|
+
}
|
|
312
|
+
state.asyncJobs.set(run.id, {
|
|
313
|
+
asyncId: run.id,
|
|
314
|
+
asyncDir: run.asyncDir,
|
|
315
|
+
status: run.state,
|
|
316
|
+
pid: run.pid,
|
|
317
|
+
sessionId: run.sessionId,
|
|
318
|
+
activityState: run.activityState,
|
|
319
|
+
lastActivityAt: run.lastActivityAt,
|
|
320
|
+
currentTool: run.currentTool,
|
|
321
|
+
currentToolStartedAt: run.currentToolStartedAt,
|
|
322
|
+
currentPath: run.currentPath,
|
|
323
|
+
turnCount: run.turnCount,
|
|
324
|
+
toolCount: run.toolCount,
|
|
325
|
+
mode: run.mode,
|
|
326
|
+
agents: steps.map((step) => step.agent),
|
|
327
|
+
currentStep: run.currentStep,
|
|
328
|
+
chainStepCount: run.chainStepCount,
|
|
329
|
+
parallelGroups: groups,
|
|
330
|
+
steps,
|
|
331
|
+
stepsTotal: steps.length,
|
|
332
|
+
runningSteps: steps.filter((step) => step.status === "running").length,
|
|
333
|
+
completedSteps: steps.filter((step) => step.status === "complete" || step.status === "completed").length,
|
|
334
|
+
activeParallelGroup: Boolean(activeGroup),
|
|
335
|
+
startedAt: run.startedAt,
|
|
336
|
+
updatedAt: run.lastUpdate ?? run.startedAt,
|
|
337
|
+
totalTokens: run.totalTokens,
|
|
338
|
+
sessionFile: run.sessionFile,
|
|
339
|
+
controlEventCursor,
|
|
340
|
+
controlEventSince,
|
|
341
|
+
nestedRoute,
|
|
342
|
+
nestedChildren: run.nestedChildren,
|
|
343
|
+
});
|
|
344
|
+
changed = true;
|
|
345
|
+
}
|
|
346
|
+
return changed;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const restoreJobs = (sessionId: string, ctx: ExtensionContext, restoration?: OwnedRunRestoration) => {
|
|
350
|
+
restoreBoundary = restoration?.startedAt ?? Date.now();
|
|
351
|
+
restoreDiscovery = restoration?.discover ?? createAsyncRunDiscovery(asyncDirRoot, {
|
|
352
|
+
sessionId: ctx.sessionManager?.getSessionFile() ?? sessionId, ownerSessionId: ctx.sessionManager?.getSessionId(), resultsDir, skipInvalid: true,
|
|
353
|
+
});
|
|
354
|
+
restoreDiscoveryDeadline = restoreBoundary + 2_000;
|
|
355
|
+
try {
|
|
356
|
+
discoverRestoredJobs(restoration?.records ?? restoreDiscovery(), Boolean(restoration));
|
|
357
|
+
} catch (error) {
|
|
358
|
+
console.error("Failed to discover active async jobs:", error);
|
|
359
|
+
}
|
|
360
|
+
if (isTuiContext(ctx)) {
|
|
361
|
+
state.lastUiContext = ctx;
|
|
362
|
+
rerenderWidget(ctx);
|
|
363
|
+
}
|
|
364
|
+
ensurePoller();
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const resetJobs = (ctx?: ExtensionContext) => {
|
|
368
|
+
restoreDiscovery = undefined;
|
|
369
|
+
restoreBoundary = 0;
|
|
370
|
+
restoreDiscoveryDeadline = 0;
|
|
371
|
+
for (const timer of state.cleanupTimers.values()) {
|
|
372
|
+
clearTimeout(timer);
|
|
373
|
+
}
|
|
374
|
+
state.cleanupTimers.clear();
|
|
375
|
+
state.asyncJobs.clear();
|
|
376
|
+
state.foregroundRuns?.clear();
|
|
377
|
+
state.resultFileCoalescer.clear();
|
|
378
|
+
if (ctx && isTuiContext(ctx)) {
|
|
379
|
+
state.lastUiContext = ctx;
|
|
380
|
+
rerenderWidget(ctx, []);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
return { ensurePoller, handleStarted, handleComplete, restoreJobs, resetJobs };
|
|
385
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AsyncResultChild, AsyncResultFile, AsyncResultTerminalState } from "../../shared/types.ts";
|
|
2
|
+
import { ownerProjection, readJsonProjection } from "../../shared/journal-reader.ts";
|
|
3
|
+
|
|
4
|
+
export function isDurableRun(value: object | null | undefined): boolean {
|
|
5
|
+
return Boolean(value && "runtimeVersion" in value && value.runtimeVersion === 2);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type ParsedAsyncResultFile = Omit<AsyncResultFile, "results"> & {
|
|
9
|
+
results?: AsyncResultChild[];
|
|
10
|
+
terminalState: AsyncResultTerminalState;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function getErrorMessage(error: unknown): string {
|
|
14
|
+
return error instanceof Error ? error.message : String(error);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
18
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isNotFoundError(error: unknown): boolean {
|
|
22
|
+
return typeof error === "object"
|
|
23
|
+
&& error !== null
|
|
24
|
+
&& "code" in error
|
|
25
|
+
&& (error as NodeJS.ErrnoException).code === "ENOENT";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function deriveAsyncResultTerminalState(input: Pick<AsyncResultFile, "success" | "state" | "exitCode">): AsyncResultTerminalState {
|
|
29
|
+
if (input.success === true) return "complete";
|
|
30
|
+
if (input.success === false) return input.state === "blocked" ? "blocked" : input.state === "paused" ? "paused" : "failed";
|
|
31
|
+
if (input.state === "complete" || input.state === "failed" || input.state === "blocked" || input.state === "paused") return input.state;
|
|
32
|
+
if (input.exitCode === 0) return "paused";
|
|
33
|
+
return "failed";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function normalizeResultChild(value: unknown, index: number, resultPath: string): AsyncResultChild {
|
|
37
|
+
if (!isRecord(value)) throw new Error(`Invalid async result file '${resultPath}': results[${index}] must be an object.`);
|
|
38
|
+
return value as AsyncResultChild;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function readAsyncResultFile(resultPath: string): ParsedAsyncResultFile {
|
|
42
|
+
let data: AsyncResultFile;
|
|
43
|
+
try {
|
|
44
|
+
data = readJsonProjection(resultPath, ownerProjection);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw new Error(`Failed to read async result file '${resultPath}': ${getErrorMessage(error)}`, {
|
|
47
|
+
cause: error instanceof Error ? error : undefined,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (!isRecord(data)) throw new Error(`Failed to parse async result file '${resultPath}': expected a JSON object.`);
|
|
51
|
+
if (data.results !== undefined && !Array.isArray(data.results)) throw new Error(`Invalid async result file '${resultPath}': results must be an array.`);
|
|
52
|
+
return { ...data, results: data.results?.map((child, index) => normalizeResultChild(child, index, resultPath)), terminalState: deriveAsyncResultTerminalState(data) };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function readAsyncResultFileIfExists(resultPath: string): ParsedAsyncResultFile | undefined {
|
|
56
|
+
try {
|
|
57
|
+
return readAsyncResultFile(resultPath);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (isNotFoundError(error instanceof Error ? error.cause : undefined)) return undefined;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|