@duckmind/dm-darwin-x64 0.43.4 → 0.48.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/dm +0 -0
- package/extensions/.dm-extensions.json +242 -50
- package/extensions/dm-9router-ext/package.json +2 -19
- package/extensions/dm-9router-ext/src/index.js +5 -0
- package/extensions/dm-ask-user/index.js +10 -0
- package/extensions/dm-ask-user/package.json +1 -21
- package/extensions/dm-cli-anything/package.json +0 -6
- package/extensions/dm-context/package.json +2 -12
- package/extensions/dm-context/src/context.js +1 -0
- package/extensions/dm-context/src/index.js +7 -0
- package/extensions/dm-context/src/utils.js +1 -0
- package/extensions/dm-cua/package.json +0 -7
- package/extensions/dm-fff/package.json +1 -28
- package/extensions/dm-fff/src/index.js +15 -0
- package/extensions/dm-fff/src/query.js +1 -0
- package/extensions/dm-goal/package.json +2 -31
- package/extensions/dm-goal/src/goal.js +43 -0
- package/extensions/dm-grill-me/index.js +174 -0
- package/extensions/dm-grill-me/package.json +1 -26
- package/extensions/dm-image2/package.json +0 -7
- package/extensions/dm-subagents/package.json +1 -32
- package/extensions/dm-subagents/src/agents/agent-management.js +37 -0
- package/extensions/dm-subagents/src/agents/agent-memory.js +6 -0
- package/extensions/dm-subagents/src/agents/agent-scope.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-selection.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-serializer.js +7 -0
- package/extensions/dm-subagents/src/agents/agents.js +11 -0
- package/extensions/dm-subagents/src/agents/chain-serializer.js +12 -0
- package/extensions/dm-subagents/src/agents/frontmatter.js +6 -0
- package/extensions/dm-subagents/src/agents/identity.js +1 -0
- package/extensions/dm-subagents/src/agents/proactive-skills.js +1 -0
- package/extensions/dm-subagents/src/agents/skills.js +6 -0
- package/extensions/dm-subagents/src/extension/config.js +2 -0
- package/extensions/dm-subagents/src/extension/control-notices.js +4 -0
- package/extensions/dm-subagents/src/extension/doctor.js +16 -0
- package/extensions/dm-subagents/src/extension/fanout-child.js +231 -0
- package/extensions/dm-subagents/src/extension/index.js +367 -0
- package/extensions/dm-subagents/src/extension/rpc.js +8 -0
- package/extensions/dm-subagents/src/extension/schemas.js +1 -0
- package/extensions/dm-subagents/src/extension/{tool-description.ts → tool-description.js} +6 -126
- package/extensions/dm-subagents/src/intercom/intercom-bridge.js +13 -0
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.js +5 -0
- package/extensions/dm-subagents/src/intercom/result-intercom.js +3 -0
- package/extensions/dm-subagents/src/profiles/profiles.js +3 -0
- package/extensions/dm-subagents/src/runs/background/async-execution.js +46 -0
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.js +14 -0
- package/extensions/dm-subagents/src/runs/background/async-resume.js +8 -0
- package/extensions/dm-subagents/src/runs/background/async-status.js +12 -0
- package/extensions/dm-subagents/src/runs/background/chain-append.js +2 -0
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-batcher.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.js +1 -0
- package/extensions/dm-subagents/src/runs/background/control-channel.js +1 -0
- package/extensions/dm-subagents/src/runs/background/fleet-view.js +17 -0
- package/extensions/dm-subagents/src/runs/background/notify.js +3 -0
- package/extensions/dm-subagents/src/runs/background/parallel-groups.js +1 -0
- package/extensions/dm-subagents/src/runs/background/result-watcher.js +8 -0
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.js +4 -0
- package/extensions/dm-subagents/src/runs/background/run-status.js +23 -0
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.js +4 -0
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.js +11 -0
- package/extensions/dm-subagents/src/runs/background/subagent-runner.js +78 -0
- package/extensions/dm-subagents/src/runs/background/top-level-async.js +1 -0
- package/extensions/dm-subagents/src/runs/background/wait.js +11 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.js +12 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.js +102 -0
- package/extensions/dm-subagents/src/runs/foreground/execution.js +51 -0
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.js +228 -0
- package/extensions/dm-subagents/src/runs/shared/acceptance.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/completion-guard.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/dm-args.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-fallback.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-scope.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-events.js +8 -0
- package/extensions/dm-subagents/src/runs/shared/nested-path.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-render.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/run-history.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/single-output.js +14 -0
- package/extensions/dm-subagents/src/runs/shared/structured-output.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-control.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.js +22 -0
- package/extensions/dm-subagents/src/runs/shared/tool-budget.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/turn-budget.js +7 -0
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/worktree.js +3 -0
- package/extensions/dm-subagents/src/shared/artifacts.js +2 -0
- package/extensions/dm-subagents/src/shared/atomic-json.js +1 -0
- package/extensions/dm-subagents/src/shared/child-transcript.js +5 -0
- package/extensions/dm-subagents/src/shared/file-coalescer.js +1 -0
- package/extensions/dm-subagents/src/shared/fork-context.js +6 -0
- package/extensions/dm-subagents/src/shared/formatters.js +9 -0
- package/extensions/dm-subagents/src/shared/jsonl-writer.js +2 -0
- package/extensions/dm-subagents/src/shared/model-info.js +1 -0
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.js +1 -0
- package/extensions/dm-subagents/src/shared/session-identity.js +1 -0
- package/extensions/dm-subagents/src/shared/session-tokens.js +2 -0
- package/extensions/dm-subagents/src/shared/settings.js +23 -0
- package/extensions/dm-subagents/src/shared/status-format.js +1 -0
- package/extensions/dm-subagents/src/shared/types.js +8 -0
- package/extensions/dm-subagents/src/shared/utils.js +2 -0
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/prompt-workflows.js +7 -0
- package/extensions/dm-subagents/src/slash/slash-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/slash-commands.js +38 -0
- package/extensions/dm-subagents/src/slash/slash-live-state.js +6 -0
- package/extensions/dm-subagents/src/tui/render-helpers.js +1 -0
- package/extensions/dm-subagents/src/tui/render.js +4 -0
- package/extensions/dm-tasks/package.json +1 -30
- package/extensions/dm-tasks/src/auto-clear.js +1 -0
- package/extensions/dm-tasks/src/index.js +212 -0
- package/extensions/dm-tasks/src/process-tracker.js +1 -0
- package/extensions/dm-tasks/src/task-store.js +1 -0
- package/extensions/dm-tasks/src/tasks-config.js +1 -0
- package/extensions/dm-tasks/src/types.js +0 -0
- package/extensions/dm-tasks/src/ui/settings-menu.js +1 -0
- package/extensions/dm-tasks/src/ui/task-widget.js +1 -0
- package/extensions/dm-usage/index.js +9 -0
- package/extensions/dm-usage/package.json +1 -18
- package/extensions/greedysearch-dm/bin/search.mjs +51 -51
- package/extensions/greedysearch-dm/index.js +20 -0
- package/extensions/greedysearch-dm/package.json +1 -22
- package/extensions/greedysearch-dm/src/formatters/results.js +8 -0
- package/extensions/greedysearch-dm/src/formatters/sources.js +1 -0
- package/extensions/greedysearch-dm/src/formatters/synthesis.js +1 -0
- package/extensions/greedysearch-dm/src/search/research.mjs +59 -59
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +10 -10
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +20 -0
- package/extensions/greedysearch-dm/src/tools/shared.js +9 -0
- package/extensions/greedysearch-dm/src/types.js +0 -0
- package/extensions/greedysearch-dm/src/utils/helpers.js +1 -0
- package/package.json +1 -1
- package/extensions/dm-9router-ext/src/index.ts +0 -541
- package/extensions/dm-ask-user/index.ts +0 -857
- package/extensions/dm-context/src/context.ts +0 -158
- package/extensions/dm-context/src/index.ts +0 -439
- package/extensions/dm-context/src/utils.ts +0 -6
- package/extensions/dm-fff/src/index.ts +0 -1023
- package/extensions/dm-fff/src/query.ts +0 -87
- package/extensions/dm-goal/src/goal.ts +0 -1073
- package/extensions/dm-grill-me/index.ts +0 -1085
- package/extensions/dm-subagents/src/agents/agent-management.ts +0 -1052
- package/extensions/dm-subagents/src/agents/agent-memory.ts +0 -254
- package/extensions/dm-subagents/src/agents/agent-scope.ts +0 -6
- package/extensions/dm-subagents/src/agents/agent-selection.ts +0 -25
- package/extensions/dm-subagents/src/agents/agent-serializer.ts +0 -121
- package/extensions/dm-subagents/src/agents/agents.ts +0 -1553
- package/extensions/dm-subagents/src/agents/chain-serializer.ts +0 -277
- package/extensions/dm-subagents/src/agents/frontmatter.ts +0 -93
- package/extensions/dm-subagents/src/agents/identity.ts +0 -30
- package/extensions/dm-subagents/src/agents/proactive-skills.ts +0 -191
- package/extensions/dm-subagents/src/agents/skills.ts +0 -729
- package/extensions/dm-subagents/src/extension/config.ts +0 -39
- package/extensions/dm-subagents/src/extension/control-notices.ts +0 -92
- package/extensions/dm-subagents/src/extension/doctor.ts +0 -214
- package/extensions/dm-subagents/src/extension/fanout-child.ts +0 -172
- package/extensions/dm-subagents/src/extension/index.ts +0 -656
- package/extensions/dm-subagents/src/extension/rpc.ts +0 -369
- package/extensions/dm-subagents/src/extension/schemas.ts +0 -309
- package/extensions/dm-subagents/src/intercom/intercom-bridge.ts +0 -180
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.ts +0 -519
- package/extensions/dm-subagents/src/intercom/result-intercom.ts +0 -377
- package/extensions/dm-subagents/src/profiles/profiles.ts +0 -637
- package/extensions/dm-subagents/src/runs/background/async-execution.ts +0 -1065
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.ts +0 -441
- package/extensions/dm-subagents/src/runs/background/async-resume.ts +0 -391
- package/extensions/dm-subagents/src/runs/background/async-status.ts +0 -395
- package/extensions/dm-subagents/src/runs/background/chain-append.ts +0 -282
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.ts +0 -191
- package/extensions/dm-subagents/src/runs/background/completion-batcher.ts +0 -166
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.ts +0 -63
- package/extensions/dm-subagents/src/runs/background/control-channel.ts +0 -332
- package/extensions/dm-subagents/src/runs/background/fleet-view.ts +0 -515
- package/extensions/dm-subagents/src/runs/background/notify.ts +0 -225
- package/extensions/dm-subagents/src/runs/background/parallel-groups.ts +0 -45
- package/extensions/dm-subagents/src/runs/background/result-watcher.ts +0 -315
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.ts +0 -84
- package/extensions/dm-subagents/src/runs/background/run-status.ts +0 -434
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.ts +0 -514
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.ts +0 -368
- package/extensions/dm-subagents/src/runs/background/subagent-runner.ts +0 -3171
- package/extensions/dm-subagents/src/runs/background/top-level-async.ts +0 -13
- package/extensions/dm-subagents/src/runs/background/wait.ts +0 -353
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.ts +0 -1333
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.ts +0 -1313
- package/extensions/dm-subagents/src/runs/foreground/execution.ts +0 -1239
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.ts +0 -3613
- package/extensions/dm-subagents/src/runs/shared/acceptance.ts +0 -879
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.ts +0 -116
- package/extensions/dm-subagents/src/runs/shared/completion-guard.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dm-args.ts +0 -271
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.ts +0 -295
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.ts +0 -175
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -365
- package/extensions/dm-subagents/src/runs/shared/model-fallback.ts +0 -292
- package/extensions/dm-subagents/src/runs/shared/model-scope.ts +0 -128
- package/extensions/dm-subagents/src/runs/shared/nested-events.ts +0 -908
- package/extensions/dm-subagents/src/runs/shared/nested-path.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/nested-render.ts +0 -115
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.ts +0 -198
- package/extensions/dm-subagents/src/runs/shared/run-history.ts +0 -60
- package/extensions/dm-subagents/src/runs/shared/single-output.ts +0 -180
- package/extensions/dm-subagents/src/runs/shared/structured-output.ts +0 -77
- package/extensions/dm-subagents/src/runs/shared/subagent-control.ts +0 -223
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.ts +0 -342
- package/extensions/dm-subagents/src/runs/shared/tool-budget.ts +0 -74
- package/extensions/dm-subagents/src/runs/shared/turn-budget.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.ts +0 -206
- package/extensions/dm-subagents/src/runs/shared/worktree.ts +0 -600
- package/extensions/dm-subagents/src/shared/artifacts.ts +0 -113
- package/extensions/dm-subagents/src/shared/atomic-json.ts +0 -86
- package/extensions/dm-subagents/src/shared/child-transcript.ts +0 -212
- package/extensions/dm-subagents/src/shared/file-coalescer.ts +0 -40
- package/extensions/dm-subagents/src/shared/fork-context.ts +0 -194
- package/extensions/dm-subagents/src/shared/formatters.ts +0 -133
- package/extensions/dm-subagents/src/shared/jsonl-writer.ts +0 -81
- package/extensions/dm-subagents/src/shared/model-info.ts +0 -78
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.ts +0 -85
- package/extensions/dm-subagents/src/shared/session-identity.ts +0 -10
- package/extensions/dm-subagents/src/shared/session-tokens.ts +0 -44
- package/extensions/dm-subagents/src/shared/settings.ts +0 -450
- package/extensions/dm-subagents/src/shared/status-format.ts +0 -49
- package/extensions/dm-subagents/src/shared/types.ts +0 -1257
- package/extensions/dm-subagents/src/shared/utils.ts +0 -554
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.ts +0 -420
- package/extensions/dm-subagents/src/slash/prompt-workflows.ts +0 -330
- package/extensions/dm-subagents/src/slash/slash-bridge.ts +0 -176
- package/extensions/dm-subagents/src/slash/slash-commands.ts +0 -1296
- package/extensions/dm-subagents/src/slash/slash-live-state.ts +0 -292
- package/extensions/dm-subagents/src/tui/render-helpers.ts +0 -80
- package/extensions/dm-subagents/src/tui/render.ts +0 -1748
- package/extensions/dm-tasks/src/auto-clear.ts +0 -91
- package/extensions/dm-tasks/src/index.ts +0 -1145
- package/extensions/dm-tasks/src/process-tracker.ts +0 -140
- package/extensions/dm-tasks/src/task-store.ts +0 -305
- package/extensions/dm-tasks/src/tasks-config.ts +0 -23
- package/extensions/dm-tasks/src/types.ts +0 -40
- package/extensions/dm-tasks/src/ui/settings-menu.ts +0 -100
- package/extensions/dm-tasks/src/ui/task-widget.ts +0 -265
- package/extensions/dm-usage/index.ts +0 -1718
- package/extensions/greedysearch-dm/index.ts +0 -177
- package/extensions/greedysearch-dm/src/formatters/results.ts +0 -163
- package/extensions/greedysearch-dm/src/formatters/sources.ts +0 -116
- package/extensions/greedysearch-dm/src/formatters/synthesis.ts +0 -87
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.ts +0 -370
- package/extensions/greedysearch-dm/src/tools/shared.ts +0 -187
- package/extensions/greedysearch-dm/src/types.ts +0 -110
- package/extensions/greedysearch-dm/src/utils/helpers.ts +0 -40
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
interface AsyncOverrideParams {
|
|
2
|
-
async?: boolean;
|
|
3
|
-
clarify?: boolean;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function applyForceTopLevelAsyncOverride<T extends AsyncOverrideParams>(
|
|
7
|
-
params: T,
|
|
8
|
-
depth: number,
|
|
9
|
-
forceTopLevelAsync: boolean,
|
|
10
|
-
): T {
|
|
11
|
-
if (!(depth === 0 && forceTopLevelAsync)) return params;
|
|
12
|
-
return { ...params, async: true, clarify: false };
|
|
13
|
-
}
|
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `wait` tool: block the current turn until outstanding async subagent runs
|
|
3
|
-
* finish (or another completion notification arrives).
|
|
4
|
-
*
|
|
5
|
-
* Background subagent runs are detached. In an interactive session the parent
|
|
6
|
-
* can end its turn and DM will wake it with a completion notification. That
|
|
7
|
-
* does not work when the parent is a skill that must run to completion, and it
|
|
8
|
-
* cannot work at all non-interactively (`dm --print ...`), where the run is a single
|
|
9
|
-
* turn: once the turn ends there is nothing left to receive the notification.
|
|
10
|
-
*
|
|
11
|
-
* `wait` closes that gap. It keeps the turn alive until a tracked async run for
|
|
12
|
-
* this session reaches a terminal state (complete / failed / paused), the
|
|
13
|
-
* caller-supplied timeout elapses, or the turn is aborted. Because it awaits
|
|
14
|
-
* inside the turn, the completion the model was told to wait for is actually
|
|
15
|
-
* observed before the tool returns.
|
|
16
|
-
*
|
|
17
|
-
* By default `wait` returns as soon as ONE run finishes, so a fleet manager can
|
|
18
|
-
* use it in a rolling-replacement loop: launch N workers, wait for the next one
|
|
19
|
-
* to finish, spawn its replacement, wait again — keeping N in flight instead of
|
|
20
|
-
* draining to zero between batches. Pass `all: true` to block until every
|
|
21
|
-
* tracked run is terminal, or `id` to block on one specific run.
|
|
22
|
-
*
|
|
23
|
-
* `wait` also returns when a run needs attention — not just on completion. A
|
|
24
|
-
* child that goes idle or blocks for a decision surfaces `needs_attention`
|
|
25
|
-
* (the same signal DM shows as a control notice and, interactively, wakes the
|
|
26
|
-
* parent with). Since `wait` is used exactly where there is no next turn to
|
|
27
|
-
* receive that notice, it must break on it too, or a stuck child would stall
|
|
28
|
-
* the loop until the timeout. Attention runs are reported so the caller can
|
|
29
|
-
* inspect / nudge / resume / interrupt them.
|
|
30
|
-
*
|
|
31
|
-
* Wake mechanism: when given DM's event bus (`deps.events`), `wait` subscribes
|
|
32
|
-
* to the subagent completion/control channels and wakes the instant any fires,
|
|
33
|
-
* rather than waiting out a fixed poll interval. A poll still runs on the
|
|
34
|
-
* interval as a reconciliation fallback (crashed runners, missed events), and
|
|
35
|
-
* the poll is the source of truth for what actually changed — the event only
|
|
36
|
-
* ends the sleep early. With no bus, `wait` degrades to pure polling.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
import type { AgentToolResult } from "@duckmind/dm-agent-core";
|
|
40
|
-
import { listAsyncRuns, type AsyncRunSummary } from "./async-status.ts";
|
|
41
|
-
import {
|
|
42
|
-
ASYNC_DIR,
|
|
43
|
-
RESULTS_DIR,
|
|
44
|
-
SUBAGENT_ASYNC_COMPLETE_EVENT,
|
|
45
|
-
SUBAGENT_CONTROL_EVENT,
|
|
46
|
-
SUBAGENT_CONTROL_INTERCOM_EVENT,
|
|
47
|
-
SUBAGENT_RESULT_INTERCOM_EVENT,
|
|
48
|
-
type Details,
|
|
49
|
-
type SubagentState,
|
|
50
|
-
} from "../../shared/types.ts";
|
|
51
|
-
import { formatDuration } from "../../shared/formatters.ts";
|
|
52
|
-
|
|
53
|
-
/** States that mean a run is still in flight (not yet resolved). */
|
|
54
|
-
const ACTIVE_STATES: ReadonlyArray<AsyncRunSummary["state"]> = ["queued", "running"];
|
|
55
|
-
|
|
56
|
-
const DEFAULT_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes
|
|
57
|
-
const MIN_POLL_INTERVAL_MS = 250;
|
|
58
|
-
const DEFAULT_POLL_INTERVAL_MS = 1000;
|
|
59
|
-
|
|
60
|
-
export interface WaitParams {
|
|
61
|
-
/** Optional run id/prefix to wait for. When omitted, waits across every active run in this session. */
|
|
62
|
-
id?: string;
|
|
63
|
-
/**
|
|
64
|
-
* When true, block until EVERY active run in this session (or matching `id`)
|
|
65
|
-
* is terminal. Default false: return as soon as the first run finishes, so a
|
|
66
|
-
* fleet manager can spawn a replacement and wait again. Ignored when `id`
|
|
67
|
-
* targets a single run.
|
|
68
|
-
*/
|
|
69
|
-
all?: boolean;
|
|
70
|
-
/** Give up after this many milliseconds. Defaults to 30 minutes. */
|
|
71
|
-
timeoutMs?: number;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** Minimal event-bus surface wait subscribes to (matches pi.events). */
|
|
75
|
-
export interface WaitEventBus {
|
|
76
|
-
on(channel: string, handler: (data: unknown) => void): () => void;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface WaitDeps {
|
|
80
|
-
state: SubagentState;
|
|
81
|
-
asyncDirRoot?: string;
|
|
82
|
-
resultsDir?: string;
|
|
83
|
-
kill?: (pid: number, signal?: NodeJS.Signals | 0) => boolean;
|
|
84
|
-
now?: () => number;
|
|
85
|
-
pollIntervalMs?: number;
|
|
86
|
-
/** Injectable sleep for tests. */
|
|
87
|
-
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* Optional event bus (pi.events). When provided, wait wakes immediately on a
|
|
90
|
-
* subagent completion/control event instead of waiting out the poll interval;
|
|
91
|
-
* the poll then remains as a reconciliation fallback (crashed runners, missed
|
|
92
|
-
* events). Omit in tests that want pure poll behavior.
|
|
93
|
-
*/
|
|
94
|
-
events?: WaitEventBus;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** Bus channels that indicate a run changed state or needs attention. */
|
|
98
|
-
const WAKE_CHANNELS = [
|
|
99
|
-
SUBAGENT_ASYNC_COMPLETE_EVENT,
|
|
100
|
-
SUBAGENT_CONTROL_EVENT,
|
|
101
|
-
SUBAGENT_CONTROL_INTERCOM_EVENT,
|
|
102
|
-
SUBAGENT_RESULT_INTERCOM_EVENT,
|
|
103
|
-
];
|
|
104
|
-
|
|
105
|
-
function defaultSleep(ms: number, signal?: AbortSignal): Promise<void> {
|
|
106
|
-
return new Promise((resolve) => {
|
|
107
|
-
if (signal?.aborted) {
|
|
108
|
-
resolve();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const timer = setTimeout(() => {
|
|
112
|
-
signal?.removeEventListener("abort", onAbort);
|
|
113
|
-
resolve();
|
|
114
|
-
}, ms);
|
|
115
|
-
const onAbort = () => {
|
|
116
|
-
clearTimeout(timer);
|
|
117
|
-
resolve();
|
|
118
|
-
};
|
|
119
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Sleep up to `ms`, but wake early if a subagent event fires on the bus (or the
|
|
125
|
-
* turn aborts). Returns when the first of those happens. With no bus this is a
|
|
126
|
-
* plain sleep, so the poll interval alone drives progress.
|
|
127
|
-
*/
|
|
128
|
-
function waitForWake(ms: number, signal: AbortSignal | undefined, deps: WaitDeps): Promise<void> {
|
|
129
|
-
const sleep = deps.sleep ?? defaultSleep;
|
|
130
|
-
const events = deps.events;
|
|
131
|
-
if (!events) return sleep(ms, signal);
|
|
132
|
-
return new Promise((resolve) => {
|
|
133
|
-
let settled = false;
|
|
134
|
-
const unsubs: Array<() => void> = [];
|
|
135
|
-
const wakeController = new AbortController();
|
|
136
|
-
const done = () => {
|
|
137
|
-
if (settled) return;
|
|
138
|
-
settled = true;
|
|
139
|
-
wakeController.abort();
|
|
140
|
-
signal?.removeEventListener("abort", done);
|
|
141
|
-
for (const u of unsubs) {
|
|
142
|
-
try { u(); } catch { /* best effort */ }
|
|
143
|
-
}
|
|
144
|
-
resolve();
|
|
145
|
-
};
|
|
146
|
-
if (signal?.aborted) {
|
|
147
|
-
done();
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
signal?.addEventListener("abort", done, { once: true });
|
|
151
|
-
for (const channel of WAKE_CHANNELS) {
|
|
152
|
-
try { unsubs.push(events.on(channel, done)); } catch { /* ignore bad channel */ }
|
|
153
|
-
}
|
|
154
|
-
// Poll-interval fallback so we still reconcile even if no event arrives.
|
|
155
|
-
// The local signal cancels that fallback timer when an event wakes us first.
|
|
156
|
-
void sleep(ms, wakeController.signal).then(done);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function matchesId(run: AsyncRunSummary, id: string): boolean {
|
|
161
|
-
return run.id === id || run.id.startsWith(id);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/** A running run that has flagged it needs the parent's attention. */
|
|
165
|
-
function needsAttention(run: AsyncRunSummary): boolean {
|
|
166
|
-
return run.activityState === "needs_attention";
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** Queued/running runs from this session, including runs that need attention. */
|
|
170
|
-
function activeRunsForSession(params: WaitParams, deps: WaitDeps): AsyncRunSummary[] {
|
|
171
|
-
const asyncDirRoot = deps.asyncDirRoot ?? ASYNC_DIR;
|
|
172
|
-
const resultsDir = deps.resultsDir ?? RESULTS_DIR;
|
|
173
|
-
const runs = listAsyncRuns(asyncDirRoot, {
|
|
174
|
-
states: [...ACTIVE_STATES],
|
|
175
|
-
sessionId: deps.state.currentSessionId ?? undefined,
|
|
176
|
-
resultsDir,
|
|
177
|
-
kill: deps.kill,
|
|
178
|
-
now: deps.now,
|
|
179
|
-
});
|
|
180
|
-
return params.id ? runs.filter((run) => matchesId(run, params.id!)) : runs;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/** Runs (from the initial set) currently flagged needs_attention, for reporting. */
|
|
184
|
-
function attentionRunsForSession(params: WaitParams, deps: WaitDeps, initialIds: Set<string>): AsyncRunSummary[] {
|
|
185
|
-
return activeRunsForSession(params, deps).filter((run) => needsAttention(run) && initialIds.has(run.id));
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** All runs (any state) for this session, for the final summary. */
|
|
189
|
-
function allRunsForSession(params: WaitParams, deps: WaitDeps): AsyncRunSummary[] {
|
|
190
|
-
const asyncDirRoot = deps.asyncDirRoot ?? ASYNC_DIR;
|
|
191
|
-
const resultsDir = deps.resultsDir ?? RESULTS_DIR;
|
|
192
|
-
const runs = listAsyncRuns(asyncDirRoot, {
|
|
193
|
-
sessionId: deps.state.currentSessionId ?? undefined,
|
|
194
|
-
resultsDir,
|
|
195
|
-
kill: deps.kill,
|
|
196
|
-
now: deps.now,
|
|
197
|
-
});
|
|
198
|
-
return params.id ? runs.filter((run) => matchesId(run, params.id!)) : runs;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function summarizeTerminalRuns(runs: AsyncRunSummary[]): string {
|
|
202
|
-
if (runs.length === 0) return "";
|
|
203
|
-
const counts = { complete: 0, failed: 0, paused: 0 } as Record<string, number>;
|
|
204
|
-
for (const run of runs) {
|
|
205
|
-
if (run.state in counts) counts[run.state] += 1;
|
|
206
|
-
}
|
|
207
|
-
const parts: string[] = [];
|
|
208
|
-
if (counts.complete) parts.push(`${counts.complete} complete`);
|
|
209
|
-
if (counts.failed) parts.push(`${counts.failed} failed`);
|
|
210
|
-
if (counts.paused) parts.push(`${counts.paused} paused`);
|
|
211
|
-
return parts.join(", ");
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function result(text: string, isError = false): AgentToolResult<Details> {
|
|
215
|
-
return {
|
|
216
|
-
content: [{ type: "text", text }],
|
|
217
|
-
...(isError ? { isError: true } : {}),
|
|
218
|
-
details: { mode: "management", results: [] },
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Block until the targeted async runs finish, the timeout elapses, or the turn
|
|
224
|
-
* is aborted. Resolves with a short human-readable summary either way.
|
|
225
|
-
*/
|
|
226
|
-
export async function waitForSubagents(
|
|
227
|
-
params: WaitParams,
|
|
228
|
-
signal: AbortSignal | undefined,
|
|
229
|
-
deps: WaitDeps,
|
|
230
|
-
): Promise<AgentToolResult<Details>> {
|
|
231
|
-
const now = deps.now ?? Date.now;
|
|
232
|
-
const pollIntervalMs = Math.max(MIN_POLL_INTERVAL_MS, deps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS);
|
|
233
|
-
const timeoutMs = params.timeoutMs !== undefined && params.timeoutMs > 0 ? params.timeoutMs : DEFAULT_TIMEOUT_MS;
|
|
234
|
-
const startedAt = now();
|
|
235
|
-
|
|
236
|
-
// A single named run always means "wait until that one is done", regardless
|
|
237
|
-
// of `all`. Otherwise `all` decides: true → every run terminal; false → the
|
|
238
|
-
// first run to finish.
|
|
239
|
-
const waitForAll = params.id ? true : params.all === true;
|
|
240
|
-
|
|
241
|
-
let active: AsyncRunSummary[];
|
|
242
|
-
try {
|
|
243
|
-
active = activeRunsForSession(params, deps);
|
|
244
|
-
} catch (error) {
|
|
245
|
-
return result(error instanceof Error ? error.message : String(error), true);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (active.length === 0) {
|
|
249
|
-
const finished = params.id
|
|
250
|
-
? `No active run matched "${params.id}". Nothing to wait for.`
|
|
251
|
-
: "No active async runs in this session. Nothing to wait for.";
|
|
252
|
-
return result(finished);
|
|
253
|
-
}
|
|
254
|
-
if (params.id) {
|
|
255
|
-
const exact = active.filter((run) => run.id === params.id);
|
|
256
|
-
if (exact.length === 1) active = exact;
|
|
257
|
-
else if (active.length > 1) {
|
|
258
|
-
return result(`Ambiguous async run id prefix "${params.id}" matched ${active.length} active runs: ${active.map((run) => run.id).join(", ")}. Pass a longer id.`, true);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
const waitParams = params.id ? { ...params, id: active[0]!.id } : params;
|
|
262
|
-
|
|
263
|
-
// The set of runs in flight when the wait began. In first-completion mode we
|
|
264
|
-
// return as soon as any of THESE leaves the active set — a run spawned by a
|
|
265
|
-
// concurrent turn shouldn't satisfy this wait.
|
|
266
|
-
const initialIds = new Set(active.map((run) => run.id));
|
|
267
|
-
const initialCount = initialIds.size;
|
|
268
|
-
let pending = active.filter((run) => !needsAttention(run));
|
|
269
|
-
|
|
270
|
-
const done = (active: AsyncRunSummary[], attention: AsyncRunSummary[]): boolean => {
|
|
271
|
-
// A run needing attention always breaks the wait, in either mode: the
|
|
272
|
-
// caller has to act on it (nudge/resume/interrupt) and blocking longer
|
|
273
|
-
// helps nothing.
|
|
274
|
-
if (attention.length > 0) return true;
|
|
275
|
-
if (waitForAll) return active.every((run) => !initialIds.has(run.id));
|
|
276
|
-
// First-completion: satisfied once any initially-pending run is gone.
|
|
277
|
-
const stillActiveInitial = active.filter((run) => initialIds.has(run.id));
|
|
278
|
-
return stillActiveInitial.length < initialCount;
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
let attention = active.filter((run) => needsAttention(run));
|
|
282
|
-
|
|
283
|
-
while (!done(pending, attention)) {
|
|
284
|
-
if (signal?.aborted) {
|
|
285
|
-
const stillActive = pending.map((run) => `${run.id} (${run.state})`).join(", ");
|
|
286
|
-
return result(`Wait aborted after ${formatDuration(now() - startedAt)}. Still active: ${stillActive}.`, true);
|
|
287
|
-
}
|
|
288
|
-
if (now() - startedAt >= timeoutMs) {
|
|
289
|
-
const stillActive = pending.map((run) => `${run.id} (${run.state})`).join(", ");
|
|
290
|
-
return result(
|
|
291
|
-
`Wait timed out after ${formatDuration(timeoutMs)} with ${pending.length} run(s) still active: ${stillActive}. `
|
|
292
|
-
+ `The runs are detached and keep going; call wait again or inspect with subagent({ action: "status" }).`,
|
|
293
|
-
true,
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
await waitForWake(pollIntervalMs, signal, deps);
|
|
297
|
-
try {
|
|
298
|
-
active = activeRunsForSession(waitParams, deps);
|
|
299
|
-
pending = active.filter((run) => !needsAttention(run));
|
|
300
|
-
attention = attentionRunsForSession(waitParams, deps, initialIds);
|
|
301
|
-
} catch (error) {
|
|
302
|
-
return result(error instanceof Error ? error.message : String(error), true);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// Report how the finished run(s) came out. In first-completion mode, name the
|
|
307
|
-
// runs from the initial set that are now terminal.
|
|
308
|
-
let terminalSummary = "";
|
|
309
|
-
let finishedCount = 0;
|
|
310
|
-
try {
|
|
311
|
-
const allNow = allRunsForSession(waitParams, deps);
|
|
312
|
-
const terminal = allNow.filter((run) => !ACTIVE_STATES.includes(run.state) && initialIds.has(run.id));
|
|
313
|
-
finishedCount = terminal.length;
|
|
314
|
-
terminalSummary = summarizeTerminalRuns(terminal);
|
|
315
|
-
} catch {
|
|
316
|
-
// Summary is best-effort; the important part is that the wait resolved.
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const attentionNote = attention.length > 0
|
|
320
|
-
? ` ${attention.length} run(s) need attention: ${attention.map((r) => r.id).join(", ")} — inspect with subagent({ action: "status" }) then nudge/resume/interrupt.`
|
|
321
|
-
: "";
|
|
322
|
-
|
|
323
|
-
const stillRunning = pending.filter((run) => initialIds.has(run.id)).length;
|
|
324
|
-
const elapsed = formatDuration(now() - startedAt);
|
|
325
|
-
const outcome = terminalSummary ? ` Outcome: ${terminalSummary}.` : "";
|
|
326
|
-
|
|
327
|
-
if (waitForAll) {
|
|
328
|
-
const scope = params.id ? `run "${params.id}"` : `${initialCount} async run(s)`;
|
|
329
|
-
const status = attention.length > 0 ? "attention required" : "done";
|
|
330
|
-
const notificationText = attention.length > 0
|
|
331
|
-
? "Relevant completion/control events have been observed; inspect status if the notification is not visible yet."
|
|
332
|
-
: "Completion events have been observed; inspect status if the notification is not visible yet.";
|
|
333
|
-
return result(
|
|
334
|
-
`Waited ${elapsed} for ${scope}; ${status}.${outcome}${attentionNote} ${notificationText}`,
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// First-completion mode.
|
|
339
|
-
const remainder = stillRunning > 0
|
|
340
|
-
? ` ${stillRunning} run(s) still in flight — call wait again to catch the next one.`
|
|
341
|
-
: attention.length > 0
|
|
342
|
-
? " No other runs are waitable until attention is handled."
|
|
343
|
-
: " No runs remain in flight.";
|
|
344
|
-
const progress = attention.length > 0 && finishedCount === 0
|
|
345
|
-
? `${attention.length} of ${initialCount} run(s) need attention`
|
|
346
|
-
: `${finishedCount} of ${initialCount} run(s) finished`;
|
|
347
|
-
const notificationText = finishedCount > 0
|
|
348
|
-
? " Completion events for the finished run(s) have been observed; inspect status if the notification is not visible yet."
|
|
349
|
-
: " Relevant control events have been observed; inspect status if the notification is not visible yet.";
|
|
350
|
-
return result(
|
|
351
|
-
`Waited ${elapsed}; ${progress}.${outcome}${attentionNote}${remainder}${notificationText}`,
|
|
352
|
-
);
|
|
353
|
-
}
|