@duckmind/dm-windows-x64 0.61.4 → 0.61.9
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/dm.exe +0 -0
- package/extensions/.dm-extensions.json +211 -67
- package/extensions/dm-subagents/agents/claude-code-writer.md +15 -0
- package/extensions/dm-subagents/agents/claude-code.md +15 -0
- package/extensions/dm-subagents/agents/codex-exec-writer.md +15 -0
- package/extensions/dm-subagents/agents/codex-exec.md +15 -0
- package/extensions/dm-subagents/agents/cursor-agent-writer.md +14 -0
- package/extensions/dm-subagents/agents/cursor-agent.md +14 -0
- package/extensions/dm-subagents/agents/delegate.md +3 -2
- package/extensions/dm-subagents/agents/oracle.md +10 -5
- package/extensions/dm-subagents/agents/researcher.md +2 -2
- package/extensions/dm-subagents/agents/reviewer.md +17 -7
- package/extensions/dm-subagents/agents/scout.md +5 -5
- package/extensions/dm-subagents/agents/worker.md +6 -2
- package/extensions/dm-subagents/async-retention-discovery-worker.mjs +167 -0
- package/extensions/dm-subagents/index.js +4 -0
- package/extensions/dm-subagents/inspector-runner.mjs +10 -0
- package/extensions/dm-subagents/install.mjs +3 -2
- package/extensions/dm-subagents/package.json +2 -2
- package/extensions/dm-subagents/prompts/council.md +60 -0
- package/extensions/dm-subagents/prompts/parallel-review.md +5 -1
- package/extensions/dm-subagents/prompts/review-loop.md +13 -7
- package/extensions/dm-subagents/skills/council-mode/SKILL.md +59 -0
- package/extensions/dm-subagents/skills/council-mode/references/pass-contracts.md +150 -0
- package/extensions/dm-subagents/skills/dm-subagents/SKILL.md +96 -911
- package/extensions/dm-subagents/skills/dm-subagents/references/constraints-and-recipes.md +70 -0
- package/extensions/dm-subagents/skills/dm-subagents/references/execution-controls.md +539 -0
- package/extensions/dm-subagents/skills/dm-subagents/references/management-authoring-rpc.md +161 -0
- package/extensions/dm-subagents/skills/dm-subagents/references/multi-lane-orchestration.md +51 -0
- package/extensions/dm-subagents/skills/dm-subagents/references/prompting-and-roles.md +295 -0
- package/extensions/dm-subagents/skills/dm-subagents/references/review-and-validation.md +73 -0
- package/extensions/dm-subagents/src/agents/agent-management.js +716 -484
- package/extensions/dm-subagents/src/agents/agent-refinements.js +563 -0
- package/extensions/dm-subagents/src/agents/agent-serializer.js +70 -5
- package/extensions/dm-subagents/src/agents/agents.js +1447 -299
- package/extensions/dm-subagents/src/agents/builtin-names.js +15 -0
- package/extensions/dm-subagents/src/agents/chain-serializer.js +12 -7
- package/extensions/dm-subagents/src/agents/frontmatter.js +64 -14
- package/extensions/dm-subagents/src/agents/identity.js +1 -1
- package/extensions/dm-subagents/src/agents/proactive-skills.js +14 -11
- package/extensions/dm-subagents/src/agents/runtime-agent-events.js +49 -0
- package/extensions/dm-subagents/src/agents/runtime-agent-registry.js +412 -0
- package/extensions/dm-subagents/src/agents/skills.js +52 -35
- package/extensions/dm-subagents/src/api/agents.js +6 -0
- package/extensions/dm-subagents/src/api/background-work.js +151 -0
- package/extensions/dm-subagents/src/api/capability-ceiling.js +12 -0
- package/extensions/dm-subagents/src/api/control-channel.js +3 -0
- package/extensions/dm-subagents/src/api/delegation.js +5 -0
- package/extensions/dm-subagents/src/api/dm-args.js +3 -0
- package/extensions/dm-subagents/src/api/external-job-provider.js +137 -0
- package/extensions/dm-subagents/src/api/external-runs.js +233 -0
- package/extensions/dm-subagents/src/api/intercom-bridge.js +3 -0
- package/extensions/dm-subagents/src/api/preflight.js +322 -0
- package/extensions/dm-subagents/src/api/project-panes.js +11 -0
- package/extensions/dm-subagents/src/api/shared-types.js +4 -0
- package/extensions/dm-subagents/src/extension/config.js +175 -0
- package/extensions/dm-subagents/src/extension/control-notices.js +4 -43
- package/extensions/dm-subagents/src/extension/doctor.js +71 -17
- package/extensions/dm-subagents/src/extension/fanout-child.js +49 -32
- package/extensions/dm-subagents/src/extension/index.js +711 -265
- package/extensions/dm-subagents/src/extension/public-execution.js +114 -0
- package/extensions/dm-subagents/src/extension/rpc.js +427 -22
- package/extensions/dm-subagents/src/extension/schemas.js +158 -65
- package/extensions/dm-subagents/src/extension/steering-notices.js +23 -0
- package/extensions/dm-subagents/src/extension/subagent-guide.js +31 -0
- package/extensions/dm-subagents/src/extension/tool-description.js +92 -74
- package/extensions/dm-subagents/src/extension/tool-result.js +7 -0
- package/extensions/dm-subagents/src/inspectors/herdr/actions.js +218 -0
- package/extensions/dm-subagents/src/inspectors/herdr/client.js +123 -0
- package/extensions/dm-subagents/src/inspectors/herdr/focus.js +47 -0
- package/extensions/dm-subagents/src/inspectors/herdr/inspector-runner.js +160 -0
- package/extensions/dm-subagents/src/inspectors/herdr/project-panes.js +618 -0
- package/extensions/dm-subagents/src/inspectors/herdr/session-roots-codec.js +21 -0
- package/extensions/dm-subagents/src/inspectors/herdr/shell-command.js +15 -0
- package/extensions/dm-subagents/src/integrations/herdr-status.js +377 -0
- package/extensions/dm-subagents/src/intercom/intercom-bridge.js +17 -13
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.js +371 -79
- package/extensions/dm-subagents/src/intercom/result-intercom.js +47 -7
- package/extensions/dm-subagents/src/missions/actions.js +394 -0
- package/extensions/dm-subagents/src/missions/goal-driver.js +149 -0
- package/extensions/dm-subagents/src/missions/lifecycle.js +331 -0
- package/extensions/dm-subagents/src/missions/store.js +548 -0
- package/extensions/dm-subagents/src/missions/types.js +9 -0
- package/extensions/dm-subagents/src/missions/workflow-state.js +245 -0
- package/extensions/dm-subagents/src/policy/authority.js +37 -0
- package/extensions/dm-subagents/src/profiles/profiles.js +36 -18
- package/extensions/dm-subagents/src/runs/background/active-async-capacity.js +427 -0
- package/extensions/dm-subagents/src/runs/background/active-run-index.js +122 -0
- package/extensions/dm-subagents/src/runs/background/async-execution.js +925 -137
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.js +515 -148
- package/extensions/dm-subagents/src/runs/background/async-resume.js +378 -51
- package/extensions/dm-subagents/src/runs/background/async-retention.js +828 -0
- package/extensions/dm-subagents/src/runs/background/async-status-snapshot.js +31 -0
- package/extensions/dm-subagents/src/runs/background/async-status.js +259 -22
- package/extensions/dm-subagents/src/runs/background/auto-drain.js +46 -0
- package/extensions/dm-subagents/src/runs/background/chain-append.js +50 -15
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.js +67 -12
- package/extensions/dm-subagents/src/runs/background/completion-batcher.js +5 -1
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.js +3 -11
- package/extensions/dm-subagents/src/runs/background/completion-replay.js +245 -0
- package/extensions/dm-subagents/src/runs/background/control-channel.js +423 -36
- package/extensions/dm-subagents/src/runs/background/fleet-view.js +132 -59
- package/extensions/dm-subagents/src/runs/background/index-segment.js +38 -0
- package/extensions/dm-subagents/src/runs/background/inspect-rpc.js +373 -0
- package/extensions/dm-subagents/src/runs/background/notify.js +357 -57
- package/extensions/dm-subagents/src/runs/background/owned-process-tree.js +86 -0
- package/extensions/dm-subagents/src/runs/background/process-terminal.js +269 -0
- package/extensions/dm-subagents/src/runs/background/result-delivery-ownership.js +34 -0
- package/extensions/dm-subagents/src/runs/background/result-files.js +469 -0
- package/extensions/dm-subagents/src/runs/background/result-watcher.js +540 -75
- package/extensions/dm-subagents/src/runs/background/resume-guidance.js +44 -0
- package/extensions/dm-subagents/src/runs/background/retained-children.js +119 -0
- package/extensions/dm-subagents/src/runs/background/run-id-query.js +5 -0
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.js +93 -9
- package/extensions/dm-subagents/src/runs/background/run-status.js +303 -32
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.js +784 -376
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.js +75 -34
- package/extensions/dm-subagents/src/runs/background/steering.js +221 -0
- package/extensions/dm-subagents/src/runs/background/subagent-runner.js +3106 -844
- package/extensions/dm-subagents/src/runs/background/subagent-wait.js +529 -0
- package/extensions/dm-subagents/src/runs/background/terminal-run-index.js +106 -0
- package/extensions/dm-subagents/src/runs/background/top-level-async.js +1 -1
- package/extensions/dm-subagents/src/runs/background/wait-completions.js +155 -0
- package/extensions/dm-subagents/src/runs/background/wait-config.js +46 -0
- package/extensions/dm-subagents/src/runs/background/wait-subscriptions.js +278 -0
- package/extensions/dm-subagents/src/runs/background/wait-tool.js +47 -0
- package/extensions/dm-subagents/src/runs/foreground/async-dismiss-action.js +81 -0
- package/extensions/dm-subagents/src/runs/foreground/async-steering-action.js +245 -0
- package/extensions/dm-subagents/src/runs/foreground/async-stop-action.js +74 -0
- package/extensions/dm-subagents/src/runs/foreground/execution.js +1401 -342
- package/extensions/dm-subagents/src/runs/foreground/foreground-control.js +133 -0
- package/extensions/dm-subagents/src/runs/foreground/foreground-history.js +148 -0
- package/extensions/dm-subagents/src/runs/foreground/prompt-audit.js +139 -0
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.js +4278 -1441
- package/extensions/dm-subagents/src/runs/foreground/workflow-detach-reconcile.js +278 -0
- package/extensions/dm-subagents/src/runs/foreground/workflow-foreground-steering.js +155 -0
- package/extensions/dm-subagents/src/runs/shared/abort-recovery.js +97 -0
- package/extensions/dm-subagents/src/runs/shared/acceptance.js +597 -148
- package/extensions/dm-subagents/src/runs/shared/agent-contract.js +35 -0
- package/extensions/dm-subagents/src/runs/shared/async-status-projection.js +472 -0
- package/extensions/dm-subagents/src/runs/shared/background-process-options.js +6 -0
- package/extensions/dm-subagents/src/runs/shared/capability-ceiling.js +175 -0
- package/extensions/dm-subagents/src/runs/shared/child-identity.js +32 -0
- package/extensions/dm-subagents/src/runs/shared/child-launch-plan.js +65 -0
- package/extensions/dm-subagents/src/runs/shared/child-protocol.js +447 -0
- package/extensions/dm-subagents/src/runs/shared/claude-code-adapter.js +120 -0
- package/extensions/dm-subagents/src/runs/shared/codex-exec-adapter.js +129 -0
- package/extensions/dm-subagents/src/runs/shared/completion-evidence.js +40 -0
- package/extensions/dm-subagents/src/runs/shared/completion-guard.js +140 -83
- package/extensions/dm-subagents/src/runs/shared/context-mode.js +38 -0
- package/extensions/dm-subagents/src/runs/shared/cursor-agent-adapter.js +101 -0
- package/extensions/dm-subagents/src/runs/shared/dm-args.js +445 -72
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +27 -16
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.js +19 -6
- package/extensions/dm-subagents/src/runs/shared/extension-bindings.js +81 -0
- package/extensions/dm-subagents/src/runs/shared/external-cli-contract.js +134 -0
- package/extensions/dm-subagents/src/runs/shared/external-cli-preflight.js +98 -0
- package/extensions/dm-subagents/src/runs/shared/external-cli-runner.js +419 -0
- package/extensions/dm-subagents/src/runs/shared/external-job-bridge.js +404 -0
- package/extensions/dm-subagents/src/runs/shared/external-job-runner.js +334 -0
- package/extensions/dm-subagents/src/runs/shared/fast-mode-extension.js +8 -0
- package/extensions/dm-subagents/src/runs/shared/host-step-status.js +228 -0
- package/extensions/dm-subagents/src/runs/shared/lane-metadata.js +104 -0
- package/extensions/dm-subagents/src/runs/shared/launch-cwd.js +17 -0
- package/extensions/dm-subagents/src/runs/shared/llm-intent-arbiter.js +190 -0
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.js +48 -3
- package/extensions/dm-subagents/src/runs/shared/mcp-config-sources.js +387 -0
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.js +212 -137
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-grant.js +131 -0
- package/extensions/dm-subagents/src/runs/shared/model-exclusions.js +207 -0
- package/extensions/dm-subagents/src/runs/shared/model-fallback.js +225 -55
- package/extensions/dm-subagents/src/runs/shared/model-scope.js +85 -28
- package/extensions/dm-subagents/src/runs/shared/mutation-evidence.js +182 -0
- package/extensions/dm-subagents/src/runs/shared/nested-events.js +264 -102
- package/extensions/dm-subagents/src/runs/shared/nested-render.js +15 -5
- package/extensions/dm-subagents/src/runs/shared/orca-progress-tabs.js +505 -0
- package/extensions/dm-subagents/src/runs/shared/parallel-handoff.js +653 -0
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.js +29 -12
- package/extensions/dm-subagents/src/runs/shared/permissions.js +108 -0
- package/extensions/dm-subagents/src/runs/shared/process-signal.js +13 -0
- package/extensions/dm-subagents/src/runs/shared/run-fanout-budget.js +257 -0
- package/extensions/dm-subagents/src/runs/shared/run-history.js +133 -13
- package/extensions/dm-subagents/src/runs/shared/runtime-acknowledged-extensions.js +62 -0
- package/extensions/dm-subagents/src/runs/shared/session-lease.js +225 -0
- package/extensions/dm-subagents/src/runs/shared/single-output.js +129 -27
- package/extensions/dm-subagents/src/runs/shared/spawn-budget.js +95 -0
- package/extensions/dm-subagents/src/runs/shared/structured-output.js +129 -10
- package/extensions/dm-subagents/src/runs/shared/subagent-control.js +66 -11
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.js +548 -70
- package/extensions/dm-subagents/src/runs/shared/subagent-startup-retry.js +50 -0
- package/extensions/dm-subagents/src/runs/shared/task-intent.js +130 -0
- package/extensions/dm-subagents/src/runs/shared/tool-availability.js +59 -0
- package/extensions/dm-subagents/src/runs/shared/tool-budget.js +7 -5
- package/extensions/dm-subagents/src/runs/shared/tool-timeout.js +64 -0
- package/extensions/dm-subagents/src/runs/shared/usage-budget.js +74 -0
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.js +22 -0
- package/extensions/dm-subagents/src/runs/shared/worktree-cleanup-plan.js +721 -0
- package/extensions/dm-subagents/src/runs/shared/worktree.js +168 -19
- package/extensions/dm-subagents/src/shared/accessible-dir.js +35 -0
- package/extensions/dm-subagents/src/shared/agent-stream-options.js +3 -0
- package/extensions/dm-subagents/src/shared/artifacts.js +170 -11
- package/extensions/dm-subagents/src/shared/atomic-json.js +36 -38
- package/extensions/dm-subagents/src/shared/capacity-resilient-json.js +77 -0
- package/extensions/dm-subagents/src/shared/child-session-name.js +15 -0
- package/extensions/dm-subagents/src/shared/child-transcript.js +57 -2
- package/extensions/dm-subagents/src/shared/completion-owner.js +7 -0
- package/extensions/dm-subagents/src/shared/display-text.js +142 -0
- package/extensions/dm-subagents/src/shared/extension-context.js +17 -0
- package/extensions/dm-subagents/src/shared/file-coalescer.js +9 -0
- package/extensions/dm-subagents/src/shared/file-system-retry.js +56 -0
- package/extensions/dm-subagents/src/shared/fork-context.js +96 -33
- package/extensions/dm-subagents/src/shared/formatters.js +21 -7
- package/extensions/dm-subagents/src/shared/launch-contract.js +94 -0
- package/extensions/dm-subagents/src/shared/model-info.js +10 -5
- package/extensions/dm-subagents/src/shared/node-executable.js +19 -0
- package/extensions/dm-subagents/src/shared/prompt-resources.js +10 -0
- package/extensions/dm-subagents/src/shared/pruned-fork.js +427 -0
- package/extensions/dm-subagents/src/shared/session-file-trust.js +19 -0
- package/extensions/dm-subagents/src/shared/session-tokens.js +14 -3
- package/extensions/dm-subagents/src/shared/settings.js +39 -47
- package/extensions/dm-subagents/src/shared/shortcuts.js +16 -0
- package/extensions/dm-subagents/src/shared/status-format.js +9 -2
- package/extensions/dm-subagents/src/shared/thinking-ceiling.js +41 -0
- package/extensions/dm-subagents/src/shared/types.js +47 -7
- package/extensions/dm-subagents/src/shared/utf8.js +12 -0
- package/extensions/dm-subagents/src/shared/utils.js +151 -131
- package/extensions/dm-subagents/src/shared/watch-strategy.js +3 -0
- package/extensions/dm-subagents/src/shared/workflow-child-permit.js +84 -0
- package/extensions/dm-subagents/src/slash/delegation-adapters.js +274 -0
- package/extensions/dm-subagents/src/slash/delegation-json.js +113 -0
- package/extensions/dm-subagents/src/slash/delegation-request.js +152 -0
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.js +294 -243
- package/extensions/dm-subagents/src/slash/prompt-workflows.js +35 -73
- package/extensions/dm-subagents/src/slash/selector.js +101 -0
- package/extensions/dm-subagents/src/slash/slash-bridge.js +17 -1
- package/extensions/dm-subagents/src/slash/slash-commands.js +722 -732
- package/extensions/dm-subagents/src/slash/slash-live-state.js +37 -19
- package/extensions/dm-subagents/src/slash/subagents-admin.js +410 -0
- package/extensions/dm-subagents/src/tui/fleet-status.js +824 -0
- package/extensions/dm-subagents/src/tui/fleet-transcript.js +479 -0
- package/extensions/dm-subagents/src/tui/fleet.js +1326 -0
- package/extensions/dm-subagents/src/tui/render-helpers.js +22 -0
- package/extensions/dm-subagents/src/tui/render.js +1511 -261
- package/extensions/dm-subagents/src/watchdog/change-signature.js +220 -0
- package/extensions/dm-subagents/src/watchdog/child-status.js +151 -0
- package/extensions/dm-subagents/src/watchdog/emission-guard.js +90 -0
- package/extensions/dm-subagents/src/watchdog/lsp-diagnostics.js +484 -0
- package/extensions/dm-subagents/src/watchdog/model-selection.js +154 -0
- package/extensions/dm-subagents/src/watchdog/permission-arbiter.js +138 -0
- package/extensions/dm-subagents/src/watchdog/register-child.js +112 -0
- package/extensions/dm-subagents/src/watchdog/register-main.js +419 -0
- package/extensions/dm-subagents/src/watchdog/render.js +54 -0
- package/extensions/dm-subagents/src/watchdog/review.js +251 -0
- package/extensions/dm-subagents/src/watchdog/runtime.js +803 -0
- package/extensions/dm-subagents/src/watchdog/scope.js +56 -0
- package/extensions/dm-subagents/src/watchdog/settings.js +515 -0
- package/extensions/dm-subagents/src/watchdog/tool-actions.js +151 -0
- package/extensions/dm-subagents/src/watchdog/turn-delta.js +169 -0
- package/extensions/dm-subagents/src/watchdog/types.js +29 -0
- package/extensions/dm-subagents/src/watchdog/warning-format.js +58 -0
- package/extensions/dm-subagents/src/workflows/chat-progress.js +116 -0
- package/extensions/dm-subagents/src/workflows/host-command.js +227 -0
- package/extensions/dm-subagents/src/workflows/scripted-workflow.js +2011 -0
- package/extensions/dm-subagents/src/workflows/workflow-child-summary.js +116 -0
- package/extensions/dm-subagents/src/workflows/workflow-preflight.js +243 -0
- package/extensions/dm-subagents/src/workflows/workflow-receipt.js +387 -0
- package/extensions/dm-subagents/src/workflows/workflow-settlement.js +189 -0
- package/package.json +4 -3
- package/extensions/dm-fff/package.json +0 -21
- package/extensions/dm-fff/src/index.js +0 -691
- package/extensions/dm-fff/src/query.js +0 -60
- package/extensions/dm-subagents/agents/context-builder.md +0 -46
- package/extensions/dm-subagents/agents/planner.md +0 -55
- package/extensions/dm-subagents/prompts/parallel-context-build.md +0 -55
- package/extensions/dm-subagents/prompts/parallel-handoff-plan.md +0 -61
- package/extensions/dm-subagents/src/runs/background/wait.js +0 -206
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.js +0 -1013
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.js +0 -981
- package/extensions/dm-subagents/src/runs/shared/turn-budget.js +0 -50
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function isAgentContractV1(contract) {
|
|
2
|
+
return contract?.version === 1;
|
|
3
|
+
}
|
|
4
|
+
export function buildExecutionProjection(result) {
|
|
5
|
+
if (result.detached) {
|
|
6
|
+
return { status: "detached", success: false, exitCode: result.exitCode, detached: true, ...result.error ? { error: result.error } : {} };
|
|
7
|
+
}
|
|
8
|
+
if (result.stopped) {
|
|
9
|
+
return { status: "stopped", success: false, exitCode: result.exitCode, stopped: true, ...result.error ? { error: result.error } : {} };
|
|
10
|
+
}
|
|
11
|
+
if (result.interrupted) {
|
|
12
|
+
return { status: "paused", success: false, exitCode: result.exitCode, interrupted: true, ...result.error ? { error: result.error } : {} };
|
|
13
|
+
}
|
|
14
|
+
const success = result.exitCode === 0 && !result.error && !result.timedOut;
|
|
15
|
+
return {
|
|
16
|
+
status: success ? "completed" : "failed",
|
|
17
|
+
success,
|
|
18
|
+
exitCode: result.exitCode,
|
|
19
|
+
...result.error ? { error: result.error } : {},
|
|
20
|
+
...result.timedOut ? { timedOut: true } : {}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function buildReviewProjection(result) {
|
|
24
|
+
const review = result.acceptance?.reviewResult;
|
|
25
|
+
if (!review)
|
|
26
|
+
return { status: "not-requested" };
|
|
27
|
+
return { status: review.status, findings: review.findings };
|
|
28
|
+
}
|
|
29
|
+
export function attachContractProjections(result) {
|
|
30
|
+
result.execution = buildExecutionProjection(result);
|
|
31
|
+
result.review = buildReviewProjection(result);
|
|
32
|
+
if (!result.effects)
|
|
33
|
+
result.effects = {};
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { sanitizeDisplayText, truncateDisplayText } from "../../shared/display-text.js";
|
|
2
|
+
import { formatModelThinking } from "../../shared/formatters.js";
|
|
3
|
+
import { HOST_STEP_MAX_COUNT, HOST_STEP_MAX_DETAIL_CHARS, HOST_STEP_MAX_LABEL_CHARS, HOST_STEP_MAX_PROVIDER_CHARS, HOST_STEP_MAX_REASON_CHARS, HOST_STEP_MAX_REF_CHARS, HOST_STEP_MAX_ROLE_CHARS, HOST_STEP_MAX_TARGET_CHARS, hostStepReportName, parseHostStepNode, validHostStepNodes } from "./host-step-status.js";
|
|
4
|
+
import { workflowGraphStageNodes } from "./workflow-graph.js";
|
|
5
|
+
export const ASYNC_STATUS_SNAPSHOT_KIND = "dm-subagents.async-status-snapshot";
|
|
6
|
+
export const ASYNC_STATUS_SNAPSHOT_VERSION = 1;
|
|
7
|
+
const DEFAULT_MAX_RUNS = 20;
|
|
8
|
+
const DEFAULT_MAX_CHILDREN_PER_NODE = 8;
|
|
9
|
+
const DEFAULT_MAX_DEPTH = 3;
|
|
10
|
+
const DEFAULT_MAX_STRING_LENGTH = 160;
|
|
11
|
+
const DEFAULT_MAX_SERIALIZED_BYTES = 32 * 1024;
|
|
12
|
+
const ASYNC_STATUS_SNAPSHOT_STATES = {
|
|
13
|
+
queued: true,
|
|
14
|
+
running: true,
|
|
15
|
+
complete: true,
|
|
16
|
+
failed: true,
|
|
17
|
+
partial: true,
|
|
18
|
+
paused: true,
|
|
19
|
+
stopped: true,
|
|
20
|
+
rejected: true
|
|
21
|
+
};
|
|
22
|
+
function isAsyncStatusSnapshotState(value) {
|
|
23
|
+
return Object.hasOwn(ASYNC_STATUS_SNAPSHOT_STATES, value);
|
|
24
|
+
}
|
|
25
|
+
function validHostStepList(source) {
|
|
26
|
+
if (source && "nodes" in source)
|
|
27
|
+
return validHostStepNodes(source);
|
|
28
|
+
const hostSteps = [];
|
|
29
|
+
for (const [index, value] of (source ?? []).slice(0, HOST_STEP_MAX_COUNT).entries()) {
|
|
30
|
+
try {
|
|
31
|
+
hostSteps.push(parseHostStepNode(value, `hostSteps[${index}]`));
|
|
32
|
+
} catch {}
|
|
33
|
+
}
|
|
34
|
+
return hostSteps;
|
|
35
|
+
}
|
|
36
|
+
function resolveCaps(options) {
|
|
37
|
+
return {
|
|
38
|
+
maxRuns: Math.max(0, Math.floor(options.maxRuns ?? DEFAULT_MAX_RUNS)),
|
|
39
|
+
maxChildrenPerNode: Math.max(0, Math.floor(options.maxChildrenPerNode ?? DEFAULT_MAX_CHILDREN_PER_NODE)),
|
|
40
|
+
maxDepth: Math.max(0, Math.floor(options.maxDepth ?? DEFAULT_MAX_DEPTH)),
|
|
41
|
+
maxStringLength: Math.max(0, Math.floor(options.maxStringLength ?? DEFAULT_MAX_STRING_LENGTH)),
|
|
42
|
+
maxSerializedBytes: Math.max(256, Math.floor(options.maxSerializedBytes ?? DEFAULT_MAX_SERIALIZED_BYTES))
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function publicText(value, fallback, maxLength) {
|
|
46
|
+
if (typeof value !== "string")
|
|
47
|
+
return fallback;
|
|
48
|
+
const normalized = sanitizeDisplayText(value.slice(0, Math.max(0, maxLength * 4)));
|
|
49
|
+
return truncateDisplayText(normalized || fallback, maxLength);
|
|
50
|
+
}
|
|
51
|
+
function publicOptionalText(value, maxLength) {
|
|
52
|
+
if (typeof value !== "string")
|
|
53
|
+
return;
|
|
54
|
+
const normalized = sanitizeDisplayText(value.slice(0, Math.max(0, maxLength * 4)));
|
|
55
|
+
return normalized ? truncateDisplayText(normalized, maxLength) : undefined;
|
|
56
|
+
}
|
|
57
|
+
function publicTime(value) {
|
|
58
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
59
|
+
}
|
|
60
|
+
function publicCount(value) {
|
|
61
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
62
|
+
}
|
|
63
|
+
function normalizeState(value) {
|
|
64
|
+
if (value === "completed")
|
|
65
|
+
return "complete";
|
|
66
|
+
if (value === "pending")
|
|
67
|
+
return "queued";
|
|
68
|
+
if (isAsyncStatusSnapshotState(value))
|
|
69
|
+
return value;
|
|
70
|
+
return "partial";
|
|
71
|
+
}
|
|
72
|
+
function terminalState(state) {
|
|
73
|
+
return state === "complete" || state === "failed" || state === "partial" || state === "paused" || state === "stopped" || state === "rejected";
|
|
74
|
+
}
|
|
75
|
+
function kindForMode(mode) {
|
|
76
|
+
return mode === "workflow" ? "workflow" : "subagent";
|
|
77
|
+
}
|
|
78
|
+
function labelForAgents(agents, fallback, maxLength) {
|
|
79
|
+
if (!agents?.length)
|
|
80
|
+
return publicText(fallback, fallback, maxLength);
|
|
81
|
+
const visible = agents.slice(0, 3).map((agent) => publicText(agent, "agent", maxLength)).join(", ");
|
|
82
|
+
const suffix = agents.length > 3 ? `, +${agents.length - 3} more` : "";
|
|
83
|
+
return truncateDisplayText(`${visible}${suffix}`, maxLength);
|
|
84
|
+
}
|
|
85
|
+
function activityFor(source, ctx) {
|
|
86
|
+
const currentTool = publicOptionalText(source.currentTool, ctx.caps.maxStringLength);
|
|
87
|
+
const lastActivityAt = publicTime(source.lastActivityAt);
|
|
88
|
+
const currentToolStartedAt = publicTime(source.currentToolStartedAt);
|
|
89
|
+
const turnCount = publicCount(source.turnCount);
|
|
90
|
+
const toolCount = publicCount(source.toolCount);
|
|
91
|
+
const activity = {
|
|
92
|
+
...typeof source.activityState === "string" ? { state: publicText(source.activityState, "unknown", ctx.caps.maxStringLength) } : {},
|
|
93
|
+
...currentTool ? { currentTool } : {},
|
|
94
|
+
...lastActivityAt !== undefined ? { lastActivityAt } : {},
|
|
95
|
+
...currentToolStartedAt !== undefined ? { currentToolStartedAt } : {},
|
|
96
|
+
...turnCount !== undefined ? { turnCount } : {},
|
|
97
|
+
...toolCount !== undefined ? { toolCount } : {}
|
|
98
|
+
};
|
|
99
|
+
return Object.keys(activity).length ? activity : undefined;
|
|
100
|
+
}
|
|
101
|
+
function appendBoundedChildren(children, source, ctx) {
|
|
102
|
+
const remaining = Math.max(0, ctx.caps.maxChildrenPerNode - children.length);
|
|
103
|
+
children.push(...source.slice(0, remaining));
|
|
104
|
+
ctx.omitted.children += Math.max(0, source.length - remaining);
|
|
105
|
+
}
|
|
106
|
+
function projectStep(step, index, depth, ctx) {
|
|
107
|
+
const state = normalizeState(step.status);
|
|
108
|
+
const startedAt = publicTime(step.startedAt);
|
|
109
|
+
const endedAt = publicTime(step.endedAt);
|
|
110
|
+
const updatedAt = endedAt ?? publicTime(step.lastActivityAt) ?? startedAt;
|
|
111
|
+
const activity = activityFor(step, ctx);
|
|
112
|
+
const node = {
|
|
113
|
+
id: publicText("workflowKey" in step && step.workflowKey ? step.workflowKey : ("runId" in step) && step.runId ? step.runId : `step:${index}`, `step:${index}`, ctx.caps.maxStringLength),
|
|
114
|
+
kind: "step",
|
|
115
|
+
label: publicText("label" in step && step.label ? step.label : step.agent, "step", ctx.caps.maxStringLength),
|
|
116
|
+
state,
|
|
117
|
+
...startedAt !== undefined ? { startedAt } : {},
|
|
118
|
+
...updatedAt !== undefined ? { updatedAt } : {},
|
|
119
|
+
...terminalState(state) && endedAt !== undefined ? { endedAt } : {},
|
|
120
|
+
...activity ? { activity } : {}
|
|
121
|
+
};
|
|
122
|
+
if (depth < ctx.caps.maxDepth && step.children?.length) {
|
|
123
|
+
const nested = step.children.map((child, childIndex) => projectNestedRun(child, childIndex, depth + 1, ctx));
|
|
124
|
+
const bounded = [];
|
|
125
|
+
appendBoundedChildren(bounded, nested, ctx);
|
|
126
|
+
if (bounded.length)
|
|
127
|
+
node.children = bounded;
|
|
128
|
+
} else if (step.children?.length) {
|
|
129
|
+
ctx.omitted.children += step.children.length;
|
|
130
|
+
}
|
|
131
|
+
return node;
|
|
132
|
+
}
|
|
133
|
+
function projectWorkflowGraphNode(node, index, depth, ctx) {
|
|
134
|
+
const step = {
|
|
135
|
+
agent: node.agent ?? node.label,
|
|
136
|
+
status: workflowGraphStepStatus(node.status),
|
|
137
|
+
workflowKey: node.id,
|
|
138
|
+
label: node.label
|
|
139
|
+
};
|
|
140
|
+
return projectStep(step, node.flatIndex ?? index, depth, ctx);
|
|
141
|
+
}
|
|
142
|
+
function projectNestedRun(child, index, depth, ctx) {
|
|
143
|
+
const state = normalizeState(child.state);
|
|
144
|
+
const startedAt = publicTime(child.startedAt);
|
|
145
|
+
const endedAt = publicTime(child.endedAt);
|
|
146
|
+
const updatedAt = publicTime(child.lastUpdate) ?? endedAt ?? publicTime(child.lastActivityAt) ?? startedAt;
|
|
147
|
+
const activity = activityFor(child, ctx);
|
|
148
|
+
const node = {
|
|
149
|
+
id: publicText(child.id, `nested:${index}`, ctx.caps.maxStringLength),
|
|
150
|
+
kind: kindForMode(child.mode),
|
|
151
|
+
label: child.agent ? publicText(child.agent, "subagent", ctx.caps.maxStringLength) : labelForAgents(child.agents, child.mode ?? "subagent", ctx.caps.maxStringLength),
|
|
152
|
+
state,
|
|
153
|
+
...startedAt !== undefined ? { startedAt } : {},
|
|
154
|
+
...updatedAt !== undefined ? { updatedAt } : {},
|
|
155
|
+
...terminalState(state) && endedAt !== undefined ? { endedAt } : {},
|
|
156
|
+
...activity ? { activity } : {}
|
|
157
|
+
};
|
|
158
|
+
if (depth < ctx.caps.maxDepth) {
|
|
159
|
+
const nestedSteps = child.steps?.map((step, stepIndex) => projectStep(step, stepIndex, depth + 1, ctx)) ?? [];
|
|
160
|
+
const nestedChildren = child.children?.map((nested, childIndex) => projectNestedRun(nested, childIndex, depth + 1, ctx)) ?? [];
|
|
161
|
+
const bounded = [];
|
|
162
|
+
appendBoundedChildren(bounded, [...nestedSteps, ...nestedChildren], ctx);
|
|
163
|
+
if (bounded.length)
|
|
164
|
+
node.children = bounded;
|
|
165
|
+
} else {
|
|
166
|
+
ctx.omitted.children += (child.steps?.length ?? 0) + (child.children?.length ?? 0);
|
|
167
|
+
}
|
|
168
|
+
return node;
|
|
169
|
+
}
|
|
170
|
+
function hostStepSnapshotState(state, verdict) {
|
|
171
|
+
if (state === "pending")
|
|
172
|
+
return "queued";
|
|
173
|
+
if (state === "running")
|
|
174
|
+
return "running";
|
|
175
|
+
if (state === "cancelled")
|
|
176
|
+
return "stopped";
|
|
177
|
+
if (state === "error" || verdict === "fail")
|
|
178
|
+
return "failed";
|
|
179
|
+
return verdict === undefined || verdict === "inconclusive" ? "partial" : "complete";
|
|
180
|
+
}
|
|
181
|
+
function projectHostStep(hostStep, ctx) {
|
|
182
|
+
const state = hostStepSnapshotState(hostStep.state, hostStep.verdict);
|
|
183
|
+
const detail = publicOptionalText(hostStep.detail, ctx.caps.maxStringLength);
|
|
184
|
+
const report = publicOptionalText(hostStepReportName(hostStep.reportPath), ctx.caps.maxStringLength);
|
|
185
|
+
const hostMetadata = {
|
|
186
|
+
kind: hostStep.monitorKind,
|
|
187
|
+
state: hostStep.state,
|
|
188
|
+
...hostStep.provider ? { provider: publicText(hostStep.provider, "provider", ctx.caps.maxStringLength) } : {},
|
|
189
|
+
...hostStep.role ? { role: publicText(hostStep.role, "role", ctx.caps.maxStringLength) } : {},
|
|
190
|
+
...hostStep.verdict ? { verdict: hostStep.verdict } : {},
|
|
191
|
+
...hostStep.reasonCode ? { reasonCode: publicText(hostStep.reasonCode, "reason", ctx.caps.maxStringLength) } : {},
|
|
192
|
+
...detail ? { detail } : {},
|
|
193
|
+
...hostStep.target ? { target: publicText(hostStep.target, "target", ctx.caps.maxStringLength) } : {},
|
|
194
|
+
...hostStep.freshness?.stale !== undefined ? { stale: hostStep.freshness.stale } : {},
|
|
195
|
+
...report ? { report } : {}
|
|
196
|
+
};
|
|
197
|
+
return {
|
|
198
|
+
id: publicText(hostStep.id, "host-step", ctx.caps.maxStringLength),
|
|
199
|
+
kind: "host-step",
|
|
200
|
+
label: publicText(hostStep.label, "host step", ctx.caps.maxStringLength),
|
|
201
|
+
state,
|
|
202
|
+
updatedAt: hostStep.updatedAt,
|
|
203
|
+
...terminalState(state) ? { endedAt: hostStep.updatedAt } : {},
|
|
204
|
+
hostStep: hostMetadata
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function projectRun(job, ctx) {
|
|
208
|
+
const state = normalizeState(job.status);
|
|
209
|
+
const startedAt = publicTime(job.startedAt);
|
|
210
|
+
const updatedAt = publicTime(job.updatedAt) ?? startedAt;
|
|
211
|
+
const activity = activityFor(job, ctx);
|
|
212
|
+
const node = {
|
|
213
|
+
id: publicText(job.asyncId, "async", ctx.caps.maxStringLength),
|
|
214
|
+
kind: kindForMode(job.mode),
|
|
215
|
+
label: labelForAgents(job.agents, job.mode ?? "subagent", ctx.caps.maxStringLength),
|
|
216
|
+
state,
|
|
217
|
+
...startedAt !== undefined ? { startedAt } : {},
|
|
218
|
+
...updatedAt !== undefined ? { updatedAt } : {},
|
|
219
|
+
...terminalState(state) && updatedAt !== undefined ? { endedAt: updatedAt } : {},
|
|
220
|
+
...activity ? { activity } : {}
|
|
221
|
+
};
|
|
222
|
+
if (ctx.caps.maxDepth > 0) {
|
|
223
|
+
const stepChildren = job.steps?.map((step, index) => projectStep(step, step.index ?? index, 1, ctx)) ?? [];
|
|
224
|
+
const loadedKeys = new Set(job.steps?.flatMap((step) => step.workflowKey ? [step.workflowKey] : []) ?? []);
|
|
225
|
+
const graphStages = job.mode === "workflow" ? workflowGraphStageNodes(job.workflowGraph) : [];
|
|
226
|
+
const graphChildren = graphStages.filter((graphNode) => !loadedKeys.has(graphNode.id)).map((graphNode, index) => projectWorkflowGraphNode(graphNode, index, 1, ctx));
|
|
227
|
+
const nestedChildren = job.nestedChildren?.map((child, index) => projectNestedRun(child, index, 1, ctx)) ?? [];
|
|
228
|
+
const hostStepChildren = validHostStepList(job.hostSteps).map((hostStep) => projectHostStep(hostStep, ctx));
|
|
229
|
+
const ordinaryChildren = [...stepChildren, ...graphChildren, ...nestedChildren];
|
|
230
|
+
const retainedHostSteps = hostStepChildren.slice(0, ctx.caps.maxChildrenPerNode);
|
|
231
|
+
const retainedOrdinaryChildren = ordinaryChildren.slice(0, ctx.caps.maxChildrenPerNode - retainedHostSteps.length);
|
|
232
|
+
const bounded = [];
|
|
233
|
+
bounded.push(...retainedOrdinaryChildren, ...retainedHostSteps);
|
|
234
|
+
ctx.omitted.children += ordinaryChildren.length - retainedOrdinaryChildren.length + hostStepChildren.length - retainedHostSteps.length;
|
|
235
|
+
if (bounded.length)
|
|
236
|
+
node.children = bounded;
|
|
237
|
+
} else {
|
|
238
|
+
const loadedKeys = new Set(job.steps?.flatMap((step) => step.workflowKey ? [step.workflowKey] : []) ?? []);
|
|
239
|
+
const graphStages = job.mode === "workflow" ? workflowGraphStageNodes(job.workflowGraph) : [];
|
|
240
|
+
const graphCount = graphStages.filter((graphNode) => !loadedKeys.has(graphNode.id)).length;
|
|
241
|
+
ctx.omitted.children += (job.steps?.length ?? 0) + graphCount + (job.nestedChildren?.length ?? 0) + validHostStepList(job.hostSteps).length;
|
|
242
|
+
}
|
|
243
|
+
return node;
|
|
244
|
+
}
|
|
245
|
+
function snapshotBytes(snapshot) {
|
|
246
|
+
return Buffer.byteLength(JSON.stringify(snapshot), "utf8");
|
|
247
|
+
}
|
|
248
|
+
function enforceByteLimit(snapshot) {
|
|
249
|
+
if (snapshotBytes(snapshot) <= snapshot.caps.maxSerializedBytes)
|
|
250
|
+
return;
|
|
251
|
+
snapshot.omitted.byteLimitExceeded = true;
|
|
252
|
+
const runs = snapshot.runs;
|
|
253
|
+
const initialOmittedRuns = snapshot.omitted.runs;
|
|
254
|
+
let lower = 0;
|
|
255
|
+
let upper = Math.max(0, runs.length - 1);
|
|
256
|
+
while (lower < upper) {
|
|
257
|
+
const retained = Math.ceil((lower + upper) / 2);
|
|
258
|
+
snapshot.runs = runs.slice(0, retained);
|
|
259
|
+
snapshot.omitted.runs = initialOmittedRuns + runs.length - retained;
|
|
260
|
+
if (snapshotBytes(snapshot) <= snapshot.caps.maxSerializedBytes)
|
|
261
|
+
lower = retained;
|
|
262
|
+
else
|
|
263
|
+
upper = retained - 1;
|
|
264
|
+
}
|
|
265
|
+
snapshot.runs = runs.slice(0, lower);
|
|
266
|
+
snapshot.omitted.runs = initialOmittedRuns + runs.length - lower;
|
|
267
|
+
}
|
|
268
|
+
function workflowStepActivity(step) {
|
|
269
|
+
if (step.currentTool)
|
|
270
|
+
return `tool ${step.currentTool}`;
|
|
271
|
+
if (step.currentPath)
|
|
272
|
+
return step.currentPath.split(/[\\/]/).at(-1);
|
|
273
|
+
if (step.activityState === "needs_attention")
|
|
274
|
+
return "needs attention";
|
|
275
|
+
if (step.activityState === "active_long_running")
|
|
276
|
+
return "long-running";
|
|
277
|
+
if (step.turnCount !== undefined)
|
|
278
|
+
return `${step.turnCount} turns`;
|
|
279
|
+
if (step.toolCount !== undefined)
|
|
280
|
+
return `${step.toolCount} tools`;
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
function workflowStepName(step, index) {
|
|
284
|
+
const key = step.workflowKey ?? `step ${index + 1}`;
|
|
285
|
+
const label = step.label && step.label !== key ? ` · ${step.label}` : "";
|
|
286
|
+
const phase = step.phase ? `${step.phase}: ` : "";
|
|
287
|
+
return `${phase}${key}${label} (${step.agent})`;
|
|
288
|
+
}
|
|
289
|
+
function hostStepRow(hostStep) {
|
|
290
|
+
const freshness = hostStep.freshness ? {
|
|
291
|
+
expectedRef: publicText(hostStep.freshness.expectedRef, "ref", HOST_STEP_MAX_REF_CHARS),
|
|
292
|
+
...hostStep.freshness.observedRef ? { observedRef: publicText(hostStep.freshness.observedRef, "ref", HOST_STEP_MAX_REF_CHARS) } : {},
|
|
293
|
+
...hostStep.freshness.stale !== undefined ? { stale: hostStep.freshness.stale } : {}
|
|
294
|
+
} : undefined;
|
|
295
|
+
return {
|
|
296
|
+
name: publicText(hostStep.label, "host step", HOST_STEP_MAX_LABEL_CHARS),
|
|
297
|
+
kind: hostStep.monitorKind,
|
|
298
|
+
state: hostStep.state,
|
|
299
|
+
...hostStep.role ? { role: publicText(hostStep.role, "role", HOST_STEP_MAX_ROLE_CHARS) } : {},
|
|
300
|
+
...hostStep.provider ? { provider: publicText(hostStep.provider, "provider", HOST_STEP_MAX_PROVIDER_CHARS) } : {},
|
|
301
|
+
...hostStep.verdict ? { verdict: hostStep.verdict } : {},
|
|
302
|
+
...hostStep.reasonCode ? { reasonCode: publicText(hostStep.reasonCode, "reason", HOST_STEP_MAX_REASON_CHARS) } : {},
|
|
303
|
+
...hostStep.detail ? { detail: publicText(hostStep.detail, "detail", HOST_STEP_MAX_DETAIL_CHARS) } : {},
|
|
304
|
+
...hostStep.target ? { target: publicText(hostStep.target, "target", HOST_STEP_MAX_TARGET_CHARS) } : {},
|
|
305
|
+
...freshness ? { freshness } : {},
|
|
306
|
+
...hostStep.reportPath ? { reportPath: hostStepReportName(hostStep.reportPath) } : {}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function isWorkflowPreflight(value) {
|
|
310
|
+
return value !== undefined && !Array.isArray(value) && "lanes" in value;
|
|
311
|
+
}
|
|
312
|
+
function isWorkflowGraph(value) {
|
|
313
|
+
return value !== undefined && !Array.isArray(value) && "nodes" in value;
|
|
314
|
+
}
|
|
315
|
+
function workflowGraphRowState(status) {
|
|
316
|
+
switch (status) {
|
|
317
|
+
case "pending":
|
|
318
|
+
return "planned";
|
|
319
|
+
case "completed":
|
|
320
|
+
return "complete";
|
|
321
|
+
case "detached":
|
|
322
|
+
return "paused";
|
|
323
|
+
default:
|
|
324
|
+
return status;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function workflowGraphStepStatus(status) {
|
|
328
|
+
switch (status) {
|
|
329
|
+
case "completed":
|
|
330
|
+
return "complete";
|
|
331
|
+
case "detached":
|
|
332
|
+
return "paused";
|
|
333
|
+
default:
|
|
334
|
+
return status;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function workflowGraphRowName(node) {
|
|
338
|
+
const key = publicText(node.id, "stage", HOST_STEP_MAX_LABEL_CHARS);
|
|
339
|
+
const label = publicOptionalText(node.label, HOST_STEP_MAX_LABEL_CHARS);
|
|
340
|
+
const phase = publicOptionalText(node.phase, HOST_STEP_MAX_LABEL_CHARS);
|
|
341
|
+
const agent = publicOptionalText(node.agent, HOST_STEP_MAX_LABEL_CHARS);
|
|
342
|
+
return `${phase ? `${phase}: ` : ""}${key}${label && label !== node.id ? ` · ${label}` : ""}${agent ? ` (${agent})` : ""}`;
|
|
343
|
+
}
|
|
344
|
+
function projectWorkflowGraphRow(node, preflight) {
|
|
345
|
+
return {
|
|
346
|
+
name: workflowGraphRowName(node),
|
|
347
|
+
state: workflowGraphRowState(node.status),
|
|
348
|
+
...preflight ? { preflight } : {}
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
export function projectAsyncWorkflowRows(steps, hostStepsOrPreflight, preflightOverride) {
|
|
352
|
+
const preflight = preflightOverride ?? (isWorkflowPreflight(hostStepsOrPreflight) ? hostStepsOrPreflight : undefined);
|
|
353
|
+
const graph = isWorkflowGraph(hostStepsOrPreflight) ? hostStepsOrPreflight : undefined;
|
|
354
|
+
const hostSteps = isWorkflowPreflight(hostStepsOrPreflight) || graph ? undefined : hostStepsOrPreflight;
|
|
355
|
+
const loaded = steps ?? [];
|
|
356
|
+
const declared = new Map;
|
|
357
|
+
if (graph) {
|
|
358
|
+
const loadedIndexesByKey = new Map;
|
|
359
|
+
for (const [index, step] of loaded.entries()) {
|
|
360
|
+
if (!step.workflowKey)
|
|
361
|
+
continue;
|
|
362
|
+
const indexes = loadedIndexesByKey.get(step.workflowKey) ?? [];
|
|
363
|
+
indexes.push(index);
|
|
364
|
+
loadedIndexesByKey.set(step.workflowKey, indexes);
|
|
365
|
+
}
|
|
366
|
+
const consumed = new Set;
|
|
367
|
+
const childRows = [];
|
|
368
|
+
for (const lane of preflight?.lanes ?? [])
|
|
369
|
+
declared.set(lane.key, lane);
|
|
370
|
+
const graphStages = workflowGraphStageNodes(graph);
|
|
371
|
+
const graphKeys = new Set(graphStages.map((node) => node.id));
|
|
372
|
+
const graphPhaseByNodeId = new Map;
|
|
373
|
+
for (const phase of graph.phases) {
|
|
374
|
+
for (const nodeId of phase.nodeIds) {
|
|
375
|
+
if (graphKeys.has(nodeId) && !graphPhaseByNodeId.has(nodeId))
|
|
376
|
+
graphPhaseByNodeId.set(nodeId, phase.title);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const graphLaneKeys = new Set(graphPhaseByNodeId.values());
|
|
380
|
+
const preflightForNode = (node) => {
|
|
381
|
+
const phaseTitle = graphPhaseByNodeId.get(node.id);
|
|
382
|
+
return declared.get(node.id) ?? (node.phase ? declared.get(node.phase) : undefined) ?? (phaseTitle ? declared.get(phaseTitle) : undefined);
|
|
383
|
+
};
|
|
384
|
+
for (const node of graphStages) {
|
|
385
|
+
const indexes = (loadedIndexesByKey.get(node.id) ?? []).filter((index) => !consumed.has(index));
|
|
386
|
+
if (indexes.length > 0) {
|
|
387
|
+
for (const index of indexes) {
|
|
388
|
+
consumed.add(index);
|
|
389
|
+
childRows.push(projectLoadedWorkflowRow(loaded[index], index, preflightForNode(node)));
|
|
390
|
+
}
|
|
391
|
+
} else {
|
|
392
|
+
childRows.push(projectWorkflowGraphRow(node, preflightForNode(node)));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
for (const lane of preflight?.lanes ?? []) {
|
|
396
|
+
if (graphKeys.has(lane.key) || graphLaneKeys.has(lane.key))
|
|
397
|
+
continue;
|
|
398
|
+
const indexes = (loadedIndexesByKey.get(lane.key) ?? []).filter((index) => !consumed.has(index));
|
|
399
|
+
if (indexes.length > 0) {
|
|
400
|
+
for (const index of indexes) {
|
|
401
|
+
consumed.add(index);
|
|
402
|
+
childRows.push(projectLoadedWorkflowRow(loaded[index], index, lane));
|
|
403
|
+
}
|
|
404
|
+
} else {
|
|
405
|
+
childRows.push({ name: lane.key, state: "planned", preflight: lane });
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
for (const [index, step] of loaded.entries()) {
|
|
409
|
+
if (!consumed.has(index))
|
|
410
|
+
childRows.push(projectLoadedWorkflowRow(step, index, step.workflowKey ? declared.get(step.workflowKey) : undefined));
|
|
411
|
+
}
|
|
412
|
+
return [...childRows, ...validHostStepList(graph).map(hostStepRow)];
|
|
413
|
+
}
|
|
414
|
+
const loadedIndexByKey = new Map;
|
|
415
|
+
for (const [index, step] of loaded.entries()) {
|
|
416
|
+
if (step.workflowKey !== undefined && !loadedIndexByKey.has(step.workflowKey))
|
|
417
|
+
loadedIndexByKey.set(step.workflowKey, index);
|
|
418
|
+
}
|
|
419
|
+
const consumed = new Set;
|
|
420
|
+
const childRows = [];
|
|
421
|
+
for (const lane of preflight?.lanes ?? []) {
|
|
422
|
+
declared.set(lane.key, lane);
|
|
423
|
+
const index = loadedIndexByKey.get(lane.key);
|
|
424
|
+
if (index === undefined) {
|
|
425
|
+
childRows.push({ name: lane.key, state: "planned", preflight: lane });
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
consumed.add(index);
|
|
429
|
+
childRows.push(projectLoadedWorkflowRow(loaded[index], index, lane));
|
|
430
|
+
}
|
|
431
|
+
for (const [index, step] of loaded.entries()) {
|
|
432
|
+
if (consumed.has(index))
|
|
433
|
+
continue;
|
|
434
|
+
childRows.push(projectLoadedWorkflowRow(step, index, step.workflowKey ? declared.get(step.workflowKey) : undefined));
|
|
435
|
+
}
|
|
436
|
+
return [...childRows, ...validHostStepList(hostSteps).map(hostStepRow)];
|
|
437
|
+
}
|
|
438
|
+
function projectLoadedWorkflowRow(step, index, preflight) {
|
|
439
|
+
const modelThinking = formatModelThinking(step.model, step.thinking) || undefined;
|
|
440
|
+
const activity = workflowStepActivity(step);
|
|
441
|
+
return {
|
|
442
|
+
name: workflowStepName(step, index),
|
|
443
|
+
state: step.status,
|
|
444
|
+
...step.context ? { context: step.context } : {},
|
|
445
|
+
...modelThinking ? { modelThinking } : {},
|
|
446
|
+
...activity ? { activity } : {},
|
|
447
|
+
...step.startedAt !== undefined ? { startedAt: step.startedAt } : {},
|
|
448
|
+
...step.tokens?.total !== undefined ? { tokens: step.tokens.total } : {},
|
|
449
|
+
...step.tokens?.window !== undefined ? { window: step.tokens.window } : {},
|
|
450
|
+
...preflight ? { preflight } : {}
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
export function projectAsyncStatusSnapshot(jobs, options = {}) {
|
|
454
|
+
const caps = resolveCaps(options);
|
|
455
|
+
const ctx = { caps, omitted: { runs: 0, children: 0, byteLimitExceeded: false } };
|
|
456
|
+
const sorted = [...jobs].sort((left, right) => {
|
|
457
|
+
const leftUpdated = left.updatedAt ?? left.startedAt ?? 0;
|
|
458
|
+
const rightUpdated = right.updatedAt ?? right.startedAt ?? 0;
|
|
459
|
+
return rightUpdated - leftUpdated || left.asyncId.localeCompare(right.asyncId);
|
|
460
|
+
});
|
|
461
|
+
ctx.omitted.runs += Math.max(0, sorted.length - caps.maxRuns);
|
|
462
|
+
const snapshot = {
|
|
463
|
+
kind: ASYNC_STATUS_SNAPSHOT_KIND,
|
|
464
|
+
version: ASYNC_STATUS_SNAPSHOT_VERSION,
|
|
465
|
+
generatedAt: options.generatedAt ?? Date.now(),
|
|
466
|
+
caps,
|
|
467
|
+
omitted: ctx.omitted,
|
|
468
|
+
runs: sorted.slice(0, caps.maxRuns).map((job) => projectRun(job, ctx))
|
|
469
|
+
};
|
|
470
|
+
enforceByteLimit(snapshot);
|
|
471
|
+
return snapshot;
|
|
472
|
+
}
|