@duckmind/dm-windows-x64 0.60.6 → 0.60.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 +70 -123
- package/extensions/dm-9router-ext/src/index.js +410 -5
- package/extensions/dm-caveman/extensions/caveman.js +283 -12
- package/extensions/dm-cliproxy/index.js +182 -2
- package/extensions/dm-cliproxy/scripts/check-config-migration.js +66 -8
- package/extensions/dm-cliproxy/src/apply.js +228 -1
- package/extensions/dm-cliproxy/src/cache.js +42 -1
- package/extensions/dm-cliproxy/src/commands.js +50 -2
- package/extensions/dm-cliproxy/src/compat.js +81 -1
- package/extensions/dm-cliproxy/src/config.js +192 -2
- package/extensions/dm-cliproxy/src/conflicts.js +46 -1
- package/extensions/dm-cliproxy/src/fetch-models.js +190 -1
- package/extensions/dm-cliproxy/src/fetch-usage.js +41 -1
- package/extensions/dm-cliproxy/src/log.js +23 -1
- package/extensions/dm-cliproxy/src/status-quota.js +77 -1
- package/extensions/dm-cliproxy/src/ui-frame.js +50 -1
- package/extensions/dm-cliproxy/src/ui-hub/hub.js +199 -2
- package/extensions/dm-cliproxy/src/ui-hub/index.js +26 -2
- package/extensions/dm-cliproxy/src/ui-hub/shell.js +46 -1
- package/extensions/dm-cliproxy/src/ui-hub/view-diagnostics.js +69 -1
- package/extensions/dm-cliproxy/src/ui-hub/view-models.js +379 -1
- package/extensions/dm-cliproxy/src/ui-hub/view-usage.js +106 -1
- package/extensions/dm-cliproxy/src/ui-picker/catalog.js +41 -1
- package/extensions/dm-cliproxy/src/ui-picker/mutate.js +115 -1
- package/extensions/dm-cliproxy/src/ui-picker/prompt-confirm.js +35 -1
- package/extensions/dm-cliproxy/src/ui-picker/prompt-name.js +62 -1
- package/extensions/dm-cliproxy/src/ui-picker/providers.js +45 -1
- package/extensions/dm-cliproxy/src/ui-picker/render-text.js +34 -1
- package/extensions/dm-cliproxy/src/ui-picker/rows.js +57 -1
- package/extensions/dm-cliproxy/src/ui-setup.js +260 -2
- package/extensions/dm-cliproxy/src/ui-usage.js +151 -1
- package/extensions/dm-cliproxy/src/usage-shared-cache.js +97 -1
- package/extensions/dm-context/src/context.js +144 -1
- package/extensions/dm-context/src/index.js +339 -7
- package/extensions/dm-context/src/utils.js +9 -1
- package/extensions/dm-cua/bin/browser-cua.mjs +73 -8
- package/extensions/dm-cua/index.js +75 -6
- package/extensions/dm-cua/src/browser-cua-lib.mjs +490 -6
- package/extensions/dm-cua/src/browser-install.mjs +331 -2
- package/extensions/dm-fff/src/index.js +688 -12
- package/extensions/dm-fff/src/query.js +60 -1
- package/extensions/dm-goal/src/goal.js +894 -23
- package/extensions/dm-image2/index.js +103 -9
- package/extensions/dm-image2/src/image-lib.mjs +1275 -8
- package/extensions/dm-subagents/install.mjs +62 -8
- package/extensions/dm-subagents/src/agents/agent-management.js +1190 -36
- package/extensions/dm-subagents/src/agents/agent-memory.js +216 -6
- package/extensions/dm-subagents/src/agents/agent-scope.js +5 -1
- package/extensions/dm-subagents/src/agents/agent-selection.js +20 -1
- package/extensions/dm-subagents/src/agents/agent-serializer.js +120 -5
- package/extensions/dm-subagents/src/agents/agents.js +1139 -11
- package/extensions/dm-subagents/src/agents/chain-serializer.js +299 -11
- package/extensions/dm-subagents/src/agents/frontmatter.js +65 -6
- package/extensions/dm-subagents/src/agents/identity.js +29 -1
- package/extensions/dm-subagents/src/agents/proactive-skills.js +141 -1
- package/extensions/dm-subagents/src/agents/skills.js +614 -6
- package/extensions/dm-subagents/src/extension/config.js +35 -2
- package/extensions/dm-subagents/src/extension/control-notices.js +69 -4
- package/extensions/dm-subagents/src/extension/doctor.js +172 -15
- package/extensions/dm-subagents/src/extension/fanout-child.js +158 -231
- package/extensions/dm-subagents/src/extension/index.js +521 -359
- package/extensions/dm-subagents/src/extension/rpc.js +266 -7
- package/extensions/dm-subagents/src/extension/schemas.js +275 -1
- package/extensions/dm-subagents/src/extension/tool-description.js +111 -6
- package/extensions/dm-subagents/src/intercom/intercom-bridge.js +126 -4
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.js +452 -5
- package/extensions/dm-subagents/src/intercom/result-intercom.js +319 -3
- package/extensions/dm-subagents/src/profiles/profiles.js +458 -3
- package/extensions/dm-subagents/src/runs/background/async-execution.js +834 -40
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.js +435 -14
- package/extensions/dm-subagents/src/runs/background/async-resume.js +334 -8
- package/extensions/dm-subagents/src/runs/background/async-status.js +313 -12
- package/extensions/dm-subagents/src/runs/background/chain-append.js +245 -2
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.js +136 -1
- package/extensions/dm-subagents/src/runs/background/completion-batcher.js +94 -1
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.js +54 -1
- package/extensions/dm-subagents/src/runs/background/control-channel.js +190 -1
- package/extensions/dm-subagents/src/runs/background/fleet-view.js +483 -17
- package/extensions/dm-subagents/src/runs/background/notify.js +129 -3
- package/extensions/dm-subagents/src/runs/background/parallel-groups.js +34 -1
- package/extensions/dm-subagents/src/runs/background/result-watcher.js +236 -6
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.js +76 -4
- package/extensions/dm-subagents/src/runs/background/run-status.js +427 -23
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.js +487 -4
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.js +306 -9
- package/extensions/dm-subagents/src/runs/background/subagent-runner.js +2849 -73
- package/extensions/dm-subagents/src/runs/background/top-level-async.js +5 -1
- package/extensions/dm-subagents/src/runs/background/wait.js +206 -11
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.js +1013 -12
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.js +980 -101
- package/extensions/dm-subagents/src/runs/foreground/execution.js +1165 -45
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.js +3157 -222
- package/extensions/dm-subagents/src/runs/shared/acceptance.js +835 -3
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.js +104 -1
- package/extensions/dm-subagents/src/runs/shared/completion-guard.js +116 -3
- package/extensions/dm-subagents/src/runs/shared/dm-args.js +208 -1
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +90 -1
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.js +282 -1
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.js +148 -1
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.js +305 -1
- package/extensions/dm-subagents/src/runs/shared/model-fallback.js +194 -1
- package/extensions/dm-subagents/src/runs/shared/model-scope.js +65 -1
- package/extensions/dm-subagents/src/runs/shared/nested-events.js +851 -8
- package/extensions/dm-subagents/src/runs/shared/nested-path.js +41 -1
- package/extensions/dm-subagents/src/runs/shared/nested-render.js +105 -1
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.js +81 -4
- package/extensions/dm-subagents/src/runs/shared/run-history.js +51 -4
- package/extensions/dm-subagents/src/runs/shared/single-output.js +149 -8
- package/extensions/dm-subagents/src/runs/shared/structured-output.js +58 -1
- package/extensions/dm-subagents/src/runs/shared/subagent-control.js +166 -5
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.js +329 -13
- package/extensions/dm-subagents/src/runs/shared/tool-budget.js +73 -1
- package/extensions/dm-subagents/src/runs/shared/turn-budget.js +47 -4
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.js +196 -1
- package/extensions/dm-subagents/src/runs/shared/worktree.js +435 -3
- package/extensions/dm-subagents/src/shared/artifacts.js +92 -2
- package/extensions/dm-subagents/src/shared/atomic-json.js +55 -1
- package/extensions/dm-subagents/src/shared/child-transcript.js +167 -5
- package/extensions/dm-subagents/src/shared/file-coalescer.js +25 -1
- package/extensions/dm-subagents/src/shared/fork-context.js +147 -4
- package/extensions/dm-subagents/src/shared/formatters.js +98 -7
- package/extensions/dm-subagents/src/shared/jsonl-writer.js +56 -2
- package/extensions/dm-subagents/src/shared/model-info.js +62 -1
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.js +68 -1
- package/extensions/dm-subagents/src/shared/session-identity.js +6 -1
- package/extensions/dm-subagents/src/shared/session-tokens.js +39 -2
- package/extensions/dm-subagents/src/shared/settings.js +198 -11
- package/extensions/dm-subagents/src/shared/status-format.js +53 -1
- package/extensions/dm-subagents/src/shared/types.js +184 -6
- package/extensions/dm-subagents/src/shared/utils.js +462 -2
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.js +288 -1
- package/extensions/dm-subagents/src/slash/prompt-workflows.js +297 -7
- package/extensions/dm-subagents/src/slash/slash-bridge.js +118 -1
- package/extensions/dm-subagents/src/slash/slash-commands.js +1287 -31
- package/extensions/dm-subagents/src/slash/slash-live-state.js +240 -4
- package/extensions/dm-subagents/src/tui/render-helpers.js +64 -1
- package/extensions/dm-subagents/src/tui/render.js +1542 -4
- package/extensions/dm-usage/index.js +1294 -9
- package/extensions/greedysearch-dm/bin/cdp-greedy.mjs +40 -9
- package/extensions/greedysearch-dm/bin/cdp-headless.mjs +5 -2
- package/extensions/greedysearch-dm/bin/cdp-visible.mjs +5 -2
- package/extensions/greedysearch-dm/bin/cdp.mjs +896 -30
- package/extensions/greedysearch-dm/bin/gschrome.mjs +30 -2
- package/extensions/greedysearch-dm/bin/kill-visible.mjs +7 -2
- package/extensions/greedysearch-dm/bin/launch-visible.mjs +13 -2
- package/extensions/greedysearch-dm/bin/launch.mjs +282 -10
- package/extensions/greedysearch-dm/bin/mcp.mjs +386 -361
- package/extensions/greedysearch-dm/bin/search.mjs +620 -540
- package/extensions/greedysearch-dm/bin/visible.mjs +22 -2
- package/extensions/greedysearch-dm/extractors/bing-copilot.mjs +329 -579
- package/extensions/greedysearch-dm/extractors/chatgpt.mjs +301 -583
- package/extensions/greedysearch-dm/extractors/common.mjs +408 -32
- package/extensions/greedysearch-dm/extractors/consensus.mjs +376 -365
- package/extensions/greedysearch-dm/extractors/consent.mjs +303 -14
- package/extensions/greedysearch-dm/extractors/gemini.mjs +228 -592
- package/extensions/greedysearch-dm/extractors/google-ai.mjs +78 -499
- package/extensions/greedysearch-dm/extractors/logically.mjs +270 -347
- package/extensions/greedysearch-dm/extractors/perplexity.mjs +243 -581
- package/extensions/greedysearch-dm/extractors/selectors.mjs +32 -1
- package/extensions/greedysearch-dm/extractors/semantic-scholar.mjs +130 -317
- package/extensions/greedysearch-dm/index.js +123 -23
- package/extensions/greedysearch-dm/src/fetcher.mjs +576 -2
- package/extensions/greedysearch-dm/src/formatters/results.js +95 -10
- package/extensions/greedysearch-dm/src/formatters/sources.js +57 -1
- package/extensions/greedysearch-dm/src/formatters/synthesis.js +49 -1
- package/extensions/greedysearch-dm/src/github.mjs +222 -7
- package/extensions/greedysearch-dm/src/reddit.mjs +145 -14
- package/extensions/greedysearch-dm/src/search/browser-lifecycle.mjs +340 -9
- package/extensions/greedysearch-dm/src/search/challenge-detect.mjs +112 -4
- package/extensions/greedysearch-dm/src/search/chrome.mjs +486 -285
- package/extensions/greedysearch-dm/src/search/constants.mjs +109 -8
- package/extensions/greedysearch-dm/src/search/defaults.mjs +10 -1
- package/extensions/greedysearch-dm/src/search/engines.mjs +79 -9
- package/extensions/greedysearch-dm/src/search/fetch-source.mjs +441 -349
- package/extensions/greedysearch-dm/src/search/file-sources.mjs +29 -7
- package/extensions/greedysearch-dm/src/search/minimize.mjs +86 -1
- package/extensions/greedysearch-dm/src/search/output.mjs +51 -5
- package/extensions/greedysearch-dm/src/search/paths.mjs +48 -1
- package/extensions/greedysearch-dm/src/search/pdf.mjs +63 -2
- package/extensions/greedysearch-dm/src/search/port-pid.mjs +69 -1
- package/extensions/greedysearch-dm/src/search/progress.mjs +109 -2
- package/extensions/greedysearch-dm/src/search/query.mjs +21 -1
- package/extensions/greedysearch-dm/src/search/recovery.mjs +49 -1
- package/extensions/greedysearch-dm/src/search/research.mjs +2227 -458
- package/extensions/greedysearch-dm/src/search/scale-aware.mjs +61 -11
- package/extensions/greedysearch-dm/src/search/simple-research.mjs +396 -805
- package/extensions/greedysearch-dm/src/search/sources.mjs +412 -1
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +127 -12
- package/extensions/greedysearch-dm/src/search/synthesis.mjs +202 -12
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +209 -23
- package/extensions/greedysearch-dm/src/tools/shared.js +226 -10
- package/extensions/greedysearch-dm/src/utils/content.mjs +35 -4
- package/extensions/greedysearch-dm/src/utils/helpers.js +22 -1
- package/extensions/greedysearch-dm/src/utils/node-runtime.mjs +10 -1
- package/extensions/greedysearch-dm/src/utils/system-cmds.mjs +61 -1
- package/package.json +1 -1
|
@@ -1,3 +1,319 @@
|
|
|
1
|
-
import{randomUUID
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import {
|
|
4
|
+
SUBAGENT_RESULT_INTERCOM_DELIVERY_EVENT,
|
|
5
|
+
SUBAGENT_RESULT_INTERCOM_EVENT
|
|
6
|
+
} from "../shared/types.js";
|
|
7
|
+
export function resolveSubagentResultStatus(input) {
|
|
8
|
+
if (input.detached)
|
|
9
|
+
return "detached";
|
|
10
|
+
if (input.interrupted || input.state === "paused")
|
|
11
|
+
return "paused";
|
|
12
|
+
if (typeof input.success === "boolean")
|
|
13
|
+
return input.success ? "completed" : "failed";
|
|
14
|
+
if (input.state === "complete")
|
|
15
|
+
return "completed";
|
|
16
|
+
if (input.state === "failed")
|
|
17
|
+
return "failed";
|
|
18
|
+
if (typeof input.exitCode === "number")
|
|
19
|
+
return input.exitCode === 0 ? "completed" : "failed";
|
|
20
|
+
return "failed";
|
|
21
|
+
}
|
|
22
|
+
function countStatuses(children) {
|
|
23
|
+
const counts = {
|
|
24
|
+
completed: 0,
|
|
25
|
+
failed: 0,
|
|
26
|
+
paused: 0,
|
|
27
|
+
detached: 0
|
|
28
|
+
};
|
|
29
|
+
for (const child of children) {
|
|
30
|
+
counts[child.status] += 1;
|
|
31
|
+
}
|
|
32
|
+
return counts;
|
|
33
|
+
}
|
|
34
|
+
function formatStatusCounts(counts) {
|
|
35
|
+
const parts = [
|
|
36
|
+
counts.completed ? `${counts.completed} completed` : undefined,
|
|
37
|
+
counts.failed ? `${counts.failed} failed` : undefined,
|
|
38
|
+
counts.paused ? `${counts.paused} paused` : undefined,
|
|
39
|
+
counts.detached ? `${counts.detached} detached` : undefined
|
|
40
|
+
].filter((part) => Boolean(part));
|
|
41
|
+
return parts.length ? parts.join(", ") : "0 results";
|
|
42
|
+
}
|
|
43
|
+
function resolveGroupedStatus(children) {
|
|
44
|
+
const counts = countStatuses(children);
|
|
45
|
+
if (counts.failed > 0)
|
|
46
|
+
return "failed";
|
|
47
|
+
if (counts.paused > 0)
|
|
48
|
+
return "paused";
|
|
49
|
+
if (counts.completed > 0)
|
|
50
|
+
return "completed";
|
|
51
|
+
if (counts.detached > 0)
|
|
52
|
+
return "detached";
|
|
53
|
+
return "failed";
|
|
54
|
+
}
|
|
55
|
+
function compactNestedRun(run, depth = 0) {
|
|
56
|
+
return {
|
|
57
|
+
id: run.id,
|
|
58
|
+
parentRunId: run.parentRunId,
|
|
59
|
+
...run.parentStepIndex !== undefined ? { parentStepIndex: run.parentStepIndex } : {},
|
|
60
|
+
...run.parentAgent ? { parentAgent: run.parentAgent } : {},
|
|
61
|
+
depth: run.depth,
|
|
62
|
+
path: run.path.slice(0, 4).map((part) => ({
|
|
63
|
+
runId: part.runId,
|
|
64
|
+
...part.stepIndex !== undefined ? { stepIndex: part.stepIndex } : {},
|
|
65
|
+
...part.agent ? { agent: part.agent } : {}
|
|
66
|
+
})),
|
|
67
|
+
...run.asyncDir ? { asyncDir: run.asyncDir } : {},
|
|
68
|
+
...run.sessionId ? { sessionId: run.sessionId } : {},
|
|
69
|
+
...run.sessionFile ? { sessionFile: run.sessionFile } : {},
|
|
70
|
+
...run.intercomTarget ? { intercomTarget: run.intercomTarget } : {},
|
|
71
|
+
...run.ownerIntercomTarget ? { ownerIntercomTarget: run.ownerIntercomTarget } : {},
|
|
72
|
+
...run.leafIntercomTarget ? { leafIntercomTarget: run.leafIntercomTarget } : {},
|
|
73
|
+
...run.ownerState ? { ownerState: run.ownerState } : {},
|
|
74
|
+
...run.mode ? { mode: run.mode } : {},
|
|
75
|
+
state: run.state,
|
|
76
|
+
...run.agent ? { agent: run.agent } : {},
|
|
77
|
+
...run.agents?.length ? { agents: run.agents.slice(0, 12) } : {},
|
|
78
|
+
...run.currentStep !== undefined ? { currentStep: run.currentStep } : {},
|
|
79
|
+
...run.chainStepCount !== undefined ? { chainStepCount: run.chainStepCount } : {},
|
|
80
|
+
...run.parallelGroups?.length ? { parallelGroups: run.parallelGroups.slice(0, 8) } : {},
|
|
81
|
+
...run.activityState ? { activityState: run.activityState } : {},
|
|
82
|
+
...run.lastActivityAt !== undefined ? { lastActivityAt: run.lastActivityAt } : {},
|
|
83
|
+
...run.currentTool ? { currentTool: run.currentTool } : {},
|
|
84
|
+
...run.currentToolStartedAt !== undefined ? { currentToolStartedAt: run.currentToolStartedAt } : {},
|
|
85
|
+
...run.currentPath ? { currentPath: run.currentPath } : {},
|
|
86
|
+
...run.turnCount !== undefined ? { turnCount: run.turnCount } : {},
|
|
87
|
+
...run.toolCount !== undefined ? { toolCount: run.toolCount } : {},
|
|
88
|
+
...run.totalTokens ? { totalTokens: run.totalTokens } : {},
|
|
89
|
+
...run.startedAt !== undefined ? { startedAt: run.startedAt } : {},
|
|
90
|
+
...run.endedAt !== undefined ? { endedAt: run.endedAt } : {},
|
|
91
|
+
...run.lastUpdate !== undefined ? { lastUpdate: run.lastUpdate } : {},
|
|
92
|
+
...run.error ? { error: run.error } : {},
|
|
93
|
+
...run.steps?.length ? { steps: run.steps.slice(0, 12).map((step) => ({
|
|
94
|
+
agent: step.agent,
|
|
95
|
+
status: step.status,
|
|
96
|
+
...step.sessionFile ? { sessionFile: step.sessionFile } : {},
|
|
97
|
+
...step.activityState ? { activityState: step.activityState } : {},
|
|
98
|
+
...step.lastActivityAt !== undefined ? { lastActivityAt: step.lastActivityAt } : {},
|
|
99
|
+
...step.currentTool ? { currentTool: step.currentTool } : {},
|
|
100
|
+
...step.currentToolStartedAt !== undefined ? { currentToolStartedAt: step.currentToolStartedAt } : {},
|
|
101
|
+
...step.currentPath ? { currentPath: step.currentPath } : {},
|
|
102
|
+
...step.turnCount !== undefined ? { turnCount: step.turnCount } : {},
|
|
103
|
+
...step.toolCount !== undefined ? { toolCount: step.toolCount } : {},
|
|
104
|
+
...step.startedAt !== undefined ? { startedAt: step.startedAt } : {},
|
|
105
|
+
...step.endedAt !== undefined ? { endedAt: step.endedAt } : {},
|
|
106
|
+
...step.error ? { error: step.error } : {},
|
|
107
|
+
...depth < 2 && step.children?.length ? { children: step.children.slice(0, 8).map((child) => compactNestedRun(child, depth + 1)) } : {}
|
|
108
|
+
})) } : {},
|
|
109
|
+
...depth < 2 && run.children?.length ? { children: run.children.slice(0, 8).map((child) => compactNestedRun(child, depth + 1)) } : {}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export function compactNestedResultChildren(children) {
|
|
113
|
+
if (!children?.length)
|
|
114
|
+
return;
|
|
115
|
+
return children.slice(0, 16).map((child) => compactNestedRun(child));
|
|
116
|
+
}
|
|
117
|
+
export function attachNestedChildrenToResultChildren(runId, children, nestedChildren) {
|
|
118
|
+
const compact = compactNestedResultChildren(nestedChildren);
|
|
119
|
+
if (!compact?.length)
|
|
120
|
+
return children.map((child) => ({ ...child, children: compactNestedResultChildren(child.children) }));
|
|
121
|
+
return children.map((child, index) => {
|
|
122
|
+
const childIndex = child.index ?? index;
|
|
123
|
+
const alreadyAttachedIds = new Set(child.children?.map((nested) => nested.id) ?? []);
|
|
124
|
+
const attached = compact.filter((nested) => nested.parentRunId === runId && nested.parentStepIndex === childIndex && !alreadyAttachedIds.has(nested.id));
|
|
125
|
+
const fallbackAttached = children.length === 1 ? compact.filter((nested) => nested.parentRunId === runId && nested.parentStepIndex === undefined && !alreadyAttachedIds.has(nested.id)) : [];
|
|
126
|
+
const merged = compactNestedResultChildren([...child.children ?? [], ...attached, ...fallbackAttached]);
|
|
127
|
+
return merged?.length ? { ...child, children: merged } : { ...child, children: undefined };
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function formatNestedResultLines(children) {
|
|
131
|
+
if (!children?.length)
|
|
132
|
+
return [];
|
|
133
|
+
const lines = ["Nested subagents:"];
|
|
134
|
+
let remaining = 10;
|
|
135
|
+
const append = (runs, indent) => {
|
|
136
|
+
for (const run of runs ?? []) {
|
|
137
|
+
if (remaining <= 0) {
|
|
138
|
+
lines.push(`${indent}↳ +more nested runs; inspect status for full tree`);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
remaining--;
|
|
142
|
+
const label = run.agent ?? run.agents?.join("+") ?? run.id;
|
|
143
|
+
lines.push(`${indent}↳ ${label} — ${run.state} [${run.id}]`);
|
|
144
|
+
if (run.sessionFile)
|
|
145
|
+
lines.push(`${indent} Session: ${run.sessionFile}`);
|
|
146
|
+
append(run.children, `${indent} `);
|
|
147
|
+
for (const step of run.steps ?? [])
|
|
148
|
+
append(step.children, `${indent} `);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
append(children, "");
|
|
152
|
+
return lines;
|
|
153
|
+
}
|
|
154
|
+
function asyncResumeGuidance(input) {
|
|
155
|
+
if (input.source !== "async" || !input.asyncId)
|
|
156
|
+
return;
|
|
157
|
+
const resumable = input.children.filter((child) => typeof child.sessionPath === "string" && fs.existsSync(child.sessionPath));
|
|
158
|
+
if (input.children.length === 1 && resumable.length === 1) {
|
|
159
|
+
return `Revive: subagent({ action: "resume", id: "${input.asyncId}", message: "..." })`;
|
|
160
|
+
}
|
|
161
|
+
if (resumable.length > 0) {
|
|
162
|
+
const firstIndex = resumable[0]?.index ?? input.children.indexOf(resumable[0]);
|
|
163
|
+
return `Revive child: subagent({ action: "resume", id: "${input.asyncId}", index: ${firstIndex}, message: "..." })`;
|
|
164
|
+
}
|
|
165
|
+
return "Resume: unavailable; no child session file was persisted.";
|
|
166
|
+
}
|
|
167
|
+
function formatSubagentResultIntercomMessage(input) {
|
|
168
|
+
const counts = countStatuses(input.children);
|
|
169
|
+
const lines = [
|
|
170
|
+
"subagent results",
|
|
171
|
+
"",
|
|
172
|
+
`Run: ${input.runId}`,
|
|
173
|
+
`Mode: ${input.mode}`,
|
|
174
|
+
`Status: ${input.status}`,
|
|
175
|
+
`Children: ${formatStatusCounts(counts)}`
|
|
176
|
+
];
|
|
177
|
+
if (input.mode === "chain" && typeof input.chainSteps === "number") {
|
|
178
|
+
lines.push(`Chain steps: ${input.chainSteps}`);
|
|
179
|
+
}
|
|
180
|
+
if (input.asyncId)
|
|
181
|
+
lines.push(`Async id: ${input.asyncId}`);
|
|
182
|
+
if (input.asyncDir)
|
|
183
|
+
lines.push(`Async dir: ${input.asyncDir}`);
|
|
184
|
+
const resumeGuidance = asyncResumeGuidance(input);
|
|
185
|
+
if (resumeGuidance)
|
|
186
|
+
lines.push(resumeGuidance);
|
|
187
|
+
if (input.children.some((child) => child.intercomTarget)) {
|
|
188
|
+
lines.push("");
|
|
189
|
+
lines.push(input.source === "async" ? "Previous intercom targets below identify child sessions used while they were running. Inspect artifacts or session logs if resume is unavailable." : "Intercom targets below identify child sessions used while they were running; completed child sessions may no longer be reachable. Inspect artifacts or session logs for follow-up.");
|
|
190
|
+
}
|
|
191
|
+
for (let index = 0;index < input.children.length; index++) {
|
|
192
|
+
const child = input.children[index];
|
|
193
|
+
lines.push("");
|
|
194
|
+
lines.push(`${index + 1}. ${child.agent} — ${child.status}`);
|
|
195
|
+
if (child.intercomTarget)
|
|
196
|
+
lines.push(`${input.source === "async" ? "Previous intercom target" : "Run intercom target"}: ${child.intercomTarget}`);
|
|
197
|
+
if (child.artifactPath)
|
|
198
|
+
lines.push(`Output artifact: ${child.artifactPath}`);
|
|
199
|
+
if (child.sessionPath)
|
|
200
|
+
lines.push(`Session: ${child.sessionPath}`);
|
|
201
|
+
lines.push(...formatNestedResultLines(child.children));
|
|
202
|
+
lines.push("Summary:");
|
|
203
|
+
lines.push(child.summary);
|
|
204
|
+
}
|
|
205
|
+
return lines.join(`
|
|
206
|
+
`);
|
|
207
|
+
}
|
|
208
|
+
export function buildSubagentResultIntercomPayload(input) {
|
|
209
|
+
const children = input.children.map((child) => ({
|
|
210
|
+
...child,
|
|
211
|
+
summary: child.summary.trim() || "(no output)",
|
|
212
|
+
children: compactNestedResultChildren(child.children)
|
|
213
|
+
}));
|
|
214
|
+
const status = resolveGroupedStatus(children);
|
|
215
|
+
const summary = formatStatusCounts(countStatuses(children));
|
|
216
|
+
const firstChild = children[0];
|
|
217
|
+
const payload = {
|
|
218
|
+
to: input.to,
|
|
219
|
+
runId: input.runId,
|
|
220
|
+
mode: input.mode,
|
|
221
|
+
status,
|
|
222
|
+
summary,
|
|
223
|
+
source: input.source,
|
|
224
|
+
children,
|
|
225
|
+
...input.asyncId ? { asyncId: input.asyncId } : {},
|
|
226
|
+
...input.asyncDir ? { asyncDir: input.asyncDir } : {},
|
|
227
|
+
...typeof input.chainSteps === "number" ? { chainSteps: input.chainSteps } : {},
|
|
228
|
+
...firstChild?.agent ? { agent: firstChild.agent } : {},
|
|
229
|
+
...firstChild?.index !== undefined ? { index: firstChild.index } : {},
|
|
230
|
+
...firstChild?.artifactPath ? { artifactPath: firstChild.artifactPath } : {},
|
|
231
|
+
...firstChild?.sessionPath ? { sessionPath: firstChild.sessionPath } : {},
|
|
232
|
+
message: ""
|
|
233
|
+
};
|
|
234
|
+
payload.message = formatSubagentResultIntercomMessage(payload);
|
|
235
|
+
return payload;
|
|
236
|
+
}
|
|
237
|
+
export async function deliverSubagentResultIntercomEvent(events, payload, timeoutMs = 500) {
|
|
238
|
+
return deliverSubagentIntercomMessageEvent(events, payload.to, payload.message, timeoutMs, payload);
|
|
239
|
+
}
|
|
240
|
+
export async function deliverSubagentIntercomMessageEvent(events, to, message, timeoutMs = 500, extra = {}) {
|
|
241
|
+
if (typeof events.on !== "function" || typeof events.emit !== "function")
|
|
242
|
+
return false;
|
|
243
|
+
const requestId = typeof extra.requestId === "string" ? extra.requestId : randomUUID();
|
|
244
|
+
return new Promise((resolve) => {
|
|
245
|
+
let settled = false;
|
|
246
|
+
let unsubscribe;
|
|
247
|
+
let timer;
|
|
248
|
+
const finish = (delivered) => {
|
|
249
|
+
if (settled)
|
|
250
|
+
return;
|
|
251
|
+
settled = true;
|
|
252
|
+
if (timer)
|
|
253
|
+
clearTimeout(timer);
|
|
254
|
+
unsubscribe?.();
|
|
255
|
+
resolve(delivered);
|
|
256
|
+
};
|
|
257
|
+
unsubscribe = events.on(SUBAGENT_RESULT_INTERCOM_DELIVERY_EVENT, (data) => {
|
|
258
|
+
if (!data || typeof data !== "object")
|
|
259
|
+
return;
|
|
260
|
+
const delivery = data;
|
|
261
|
+
if (delivery.requestId !== requestId)
|
|
262
|
+
return;
|
|
263
|
+
finish(delivery.delivered === true);
|
|
264
|
+
});
|
|
265
|
+
timer = setTimeout(() => finish(false), timeoutMs);
|
|
266
|
+
try {
|
|
267
|
+
events.emit(SUBAGENT_RESULT_INTERCOM_EVENT, { ...extra, to, message, requestId });
|
|
268
|
+
} catch {
|
|
269
|
+
finish(false);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function stripSingleResultOutputs(result) {
|
|
274
|
+
return {
|
|
275
|
+
...result,
|
|
276
|
+
messages: undefined,
|
|
277
|
+
finalOutput: undefined,
|
|
278
|
+
truncation: undefined
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
export function stripDetailsOutputsForIntercomReceipt(details) {
|
|
282
|
+
return {
|
|
283
|
+
...details,
|
|
284
|
+
results: details.results.map(stripSingleResultOutputs)
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
export function formatSubagentResultReceipt(input) {
|
|
288
|
+
const counts = countStatuses(input.payload.children);
|
|
289
|
+
const modeLabel = input.mode === "single" ? "single subagent result" : input.mode === "parallel" ? "parallel subagent results" : "chain subagent results";
|
|
290
|
+
const lines = [
|
|
291
|
+
`Delivered ${modeLabel} via intercom.`,
|
|
292
|
+
`Run: ${input.runId}`,
|
|
293
|
+
`Children: ${formatStatusCounts(counts)}`
|
|
294
|
+
];
|
|
295
|
+
const artifacts = input.payload.children.filter((child) => typeof child.artifactPath === "string");
|
|
296
|
+
if (artifacts.length > 0) {
|
|
297
|
+
lines.push("Artifacts:");
|
|
298
|
+
for (const child of artifacts) {
|
|
299
|
+
lines.push(`- ${child.agent} [${child.status}]: ${child.artifactPath}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const intercomTargets = input.payload.children.filter((child) => typeof child.intercomTarget === "string");
|
|
303
|
+
if (intercomTargets.length > 0) {
|
|
304
|
+
lines.push("Run intercom targets (may be inactive after completion):");
|
|
305
|
+
for (const child of intercomTargets) {
|
|
306
|
+
lines.push(`- ${child.agent} [${child.status}]: ${child.intercomTarget}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const sessions = input.payload.children.filter((child) => typeof child.sessionPath === "string");
|
|
310
|
+
if (sessions.length > 0) {
|
|
311
|
+
lines.push("Sessions:");
|
|
312
|
+
for (const child of sessions) {
|
|
313
|
+
lines.push(`- ${child.agent} [${child.status}]: ${child.sessionPath}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
lines.push("Full grouped output was sent over intercom.");
|
|
317
|
+
return lines.join(`
|
|
318
|
+
`);
|
|
319
|
+
}
|