@duckmind/dm-windows-x64 0.60.6 → 0.60.8
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,2 +1,245 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { writeAtomicJson } from "../../shared/atomic-json.js";
|
|
5
|
+
import { appendJsonl } from "../../shared/artifacts.js";
|
|
6
|
+
import { readStatus } from "../../shared/utils.js";
|
|
7
|
+
import { isDynamicRunnerGroup, isParallelGroup } from "../shared/parallel-utils.js";
|
|
8
|
+
const APPEND_REQUESTS_DIR = "append-requests";
|
|
9
|
+
function appendDir(asyncDir) {
|
|
10
|
+
return path.join(asyncDir, APPEND_REQUESTS_DIR);
|
|
11
|
+
}
|
|
12
|
+
function appendRequestPath(asyncDir, request) {
|
|
13
|
+
return path.join(appendDir(asyncDir), `${request.createdAt}-${request.id}.json`);
|
|
14
|
+
}
|
|
15
|
+
function listAppendRequestFiles(asyncDir) {
|
|
16
|
+
const dir = appendDir(asyncDir);
|
|
17
|
+
try {
|
|
18
|
+
return fs.readdirSync(dir).filter((entry) => entry.endsWith(".json")).map((entry) => path.join(dir, entry)).sort();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (error.code === "ENOENT")
|
|
21
|
+
return [];
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function countPendingChainAppendRequests(asyncDir) {
|
|
26
|
+
return listAppendRequestFiles(asyncDir).length;
|
|
27
|
+
}
|
|
28
|
+
export function runnerStepOutputNames(steps) {
|
|
29
|
+
const names = [];
|
|
30
|
+
for (const step of steps) {
|
|
31
|
+
if (isParallelGroup(step)) {
|
|
32
|
+
names.push(...step.parallel.map((task) => task.outputName).filter((name) => Boolean(name)));
|
|
33
|
+
} else if (isDynamicRunnerGroup(step)) {
|
|
34
|
+
if (step.collect.as)
|
|
35
|
+
names.push(step.collect.as);
|
|
36
|
+
} else if (step.outputName) {
|
|
37
|
+
names.push(step.outputName);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return names;
|
|
41
|
+
}
|
|
42
|
+
export function enqueueChainAppendRequest(input) {
|
|
43
|
+
const status = readStatus(input.asyncDir);
|
|
44
|
+
if (!status)
|
|
45
|
+
throw new Error(`No async run status found for '${input.runId}'.`);
|
|
46
|
+
if (status.runId !== input.runId)
|
|
47
|
+
throw new Error(`Async run id mismatch: expected '${input.runId}', found '${status.runId}'.`);
|
|
48
|
+
if (status.mode !== "chain")
|
|
49
|
+
throw new Error(`Run '${input.runId}' is ${status.mode}; only active chain runs accept appended steps.`);
|
|
50
|
+
if (status.state !== "running")
|
|
51
|
+
throw new Error(`Run '${input.runId}' is ${status.state}; only running chain runs accept appended steps.`);
|
|
52
|
+
const stillInProgress = (status.steps ?? []).some((step) => step.status === "running" || step.status === "pending") || (status.pendingAppends ?? 0) > 0;
|
|
53
|
+
if (!stillInProgress)
|
|
54
|
+
throw new Error(`Run '${input.runId}' has no running or pending chain steps left; append-step must target an in-progress chain.`);
|
|
55
|
+
if (input.steps.length === 0)
|
|
56
|
+
throw new Error("append-step requires one chain step.");
|
|
57
|
+
const request = {
|
|
58
|
+
id: randomUUID(),
|
|
59
|
+
createdAt: input.now ?? Date.now(),
|
|
60
|
+
steps: input.steps
|
|
61
|
+
};
|
|
62
|
+
fs.mkdirSync(appendDir(input.asyncDir), { recursive: true });
|
|
63
|
+
writeAtomicJson(appendRequestPath(input.asyncDir, request), request);
|
|
64
|
+
const pendingCount = countPendingChainAppendRequests(input.asyncDir);
|
|
65
|
+
const statusPath = path.join(input.asyncDir, "status.json");
|
|
66
|
+
const updatedStatus = { ...status, pendingAppends: pendingCount, lastUpdate: request.createdAt };
|
|
67
|
+
writeAtomicJson(statusPath, updatedStatus);
|
|
68
|
+
appendJsonl(path.join(input.asyncDir, "events.jsonl"), JSON.stringify({
|
|
69
|
+
type: "subagent.chain.append.requested",
|
|
70
|
+
ts: request.createdAt,
|
|
71
|
+
runId: input.runId,
|
|
72
|
+
requestId: request.id,
|
|
73
|
+
stepCount: input.steps.length,
|
|
74
|
+
pendingAppends: pendingCount
|
|
75
|
+
}));
|
|
76
|
+
return { request, pendingCount };
|
|
77
|
+
}
|
|
78
|
+
function readAppendRequest(filePath) {
|
|
79
|
+
const raw = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
80
|
+
if (!raw.id || typeof raw.id !== "string")
|
|
81
|
+
return;
|
|
82
|
+
if (!Number.isFinite(raw.createdAt))
|
|
83
|
+
return;
|
|
84
|
+
if (!Array.isArray(raw.steps) || raw.steps.length === 0)
|
|
85
|
+
return;
|
|
86
|
+
return { id: raw.id, createdAt: raw.createdAt, steps: raw.steps };
|
|
87
|
+
}
|
|
88
|
+
export function readPendingChainAppendRequests(asyncDir) {
|
|
89
|
+
return listAppendRequestFiles(asyncDir).map((filePath) => readAppendRequest(filePath)).filter((request) => Boolean(request)).sort((left, right) => left.createdAt - right.createdAt || left.id.localeCompare(right.id));
|
|
90
|
+
}
|
|
91
|
+
export function consumeChainAppendRequests(asyncDir) {
|
|
92
|
+
const requests = [];
|
|
93
|
+
for (const filePath of listAppendRequestFiles(asyncDir)) {
|
|
94
|
+
const request = readAppendRequest(filePath);
|
|
95
|
+
try {
|
|
96
|
+
fs.unlinkSync(filePath);
|
|
97
|
+
} catch {}
|
|
98
|
+
if (request)
|
|
99
|
+
requests.push(request);
|
|
100
|
+
}
|
|
101
|
+
return requests.sort((left, right) => left.createdAt - right.createdAt || left.id.localeCompare(right.id));
|
|
102
|
+
}
|
|
103
|
+
function statusStepForTask(task) {
|
|
104
|
+
return {
|
|
105
|
+
agent: task.agent,
|
|
106
|
+
phase: task.phase,
|
|
107
|
+
label: task.label,
|
|
108
|
+
outputName: task.outputName,
|
|
109
|
+
structured: task.structured,
|
|
110
|
+
status: "pending",
|
|
111
|
+
...task.sessionFile ? { sessionFile: task.sessionFile } : {},
|
|
112
|
+
skills: task.skills,
|
|
113
|
+
model: task.model,
|
|
114
|
+
thinking: task.thinking,
|
|
115
|
+
attemptedModels: task.modelCandidates && task.modelCandidates.length > 0 ? task.modelCandidates : task.model ? [task.model] : undefined,
|
|
116
|
+
recentTools: [],
|
|
117
|
+
recentOutput: []
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function statusStepsForRunnerStep(step) {
|
|
121
|
+
if (isParallelGroup(step))
|
|
122
|
+
return step.parallel.map(statusStepForTask);
|
|
123
|
+
if (isDynamicRunnerGroup(step)) {
|
|
124
|
+
return [{
|
|
125
|
+
agent: `expand:${step.parallel.agent}`,
|
|
126
|
+
phase: step.phase ?? step.parallel.phase,
|
|
127
|
+
label: step.label ?? step.parallel.label ?? `Dynamic fanout (${step.collect.as})`,
|
|
128
|
+
outputName: step.collect.as,
|
|
129
|
+
structured: Boolean(step.collect.outputSchema),
|
|
130
|
+
status: "pending",
|
|
131
|
+
recentTools: [],
|
|
132
|
+
recentOutput: []
|
|
133
|
+
}];
|
|
134
|
+
}
|
|
135
|
+
return [statusStepForTask(step)];
|
|
136
|
+
}
|
|
137
|
+
function pushPhase(graph, phase, nodeId) {
|
|
138
|
+
if (!phase)
|
|
139
|
+
return;
|
|
140
|
+
let group = graph.phases.find((candidate) => candidate.title === phase);
|
|
141
|
+
if (!group) {
|
|
142
|
+
group = { title: phase, nodeIds: [] };
|
|
143
|
+
graph.phases.push(group);
|
|
144
|
+
}
|
|
145
|
+
group.nodeIds.push(nodeId);
|
|
146
|
+
}
|
|
147
|
+
function graphNodeForSequential(step, stepIndex, flatIndex) {
|
|
148
|
+
return {
|
|
149
|
+
id: `step-${stepIndex}`,
|
|
150
|
+
kind: "step",
|
|
151
|
+
agent: step.agent,
|
|
152
|
+
phase: step.phase,
|
|
153
|
+
label: step.label?.trim() || step.agent || `Step ${stepIndex + 1}`,
|
|
154
|
+
status: "pending",
|
|
155
|
+
flatIndex,
|
|
156
|
+
stepIndex,
|
|
157
|
+
outputName: step.outputName,
|
|
158
|
+
structured: step.structured
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function graphNodeForParallel(step, stepIndex, flatIndex, graph) {
|
|
162
|
+
const children = step.parallel.map((task, taskIndex) => {
|
|
163
|
+
const childId = `step-${stepIndex}-agent-${taskIndex}`;
|
|
164
|
+
pushPhase(graph, task.phase, childId);
|
|
165
|
+
return {
|
|
166
|
+
id: childId,
|
|
167
|
+
kind: "agent",
|
|
168
|
+
agent: task.agent,
|
|
169
|
+
phase: task.phase,
|
|
170
|
+
label: task.label?.trim() || task.agent || `Agent ${taskIndex + 1}`,
|
|
171
|
+
status: "pending",
|
|
172
|
+
flatIndex: flatIndex + taskIndex,
|
|
173
|
+
stepIndex,
|
|
174
|
+
outputName: task.outputName,
|
|
175
|
+
structured: task.structured
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
id: `step-${stepIndex}`,
|
|
180
|
+
kind: "parallel-group",
|
|
181
|
+
label: step.parallel.length === 1 ? "Parallel task" : `Parallel group (${step.parallel.length})`,
|
|
182
|
+
status: "pending",
|
|
183
|
+
stepIndex,
|
|
184
|
+
children
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function graphNodeForDynamic(step, stepIndex) {
|
|
188
|
+
return {
|
|
189
|
+
id: `step-${stepIndex}`,
|
|
190
|
+
kind: "dynamic-parallel-group",
|
|
191
|
+
label: step.label?.trim() || step.parallel.label?.trim() || `Dynamic fanout (${step.collect.as})`,
|
|
192
|
+
status: "pending",
|
|
193
|
+
stepIndex,
|
|
194
|
+
outputName: step.collect.as,
|
|
195
|
+
structured: Boolean(step.collect.outputSchema),
|
|
196
|
+
dynamic: {
|
|
197
|
+
sourceOutput: step.expand.from.output,
|
|
198
|
+
sourcePath: step.expand.from.path,
|
|
199
|
+
itemName: step.expand.item ?? "item",
|
|
200
|
+
maxItems: step.expand.maxItems,
|
|
201
|
+
collectAs: step.collect.as
|
|
202
|
+
},
|
|
203
|
+
children: []
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function appendWorkflowNode(graph, step, stepIndex, flatIndex) {
|
|
207
|
+
if (!graph)
|
|
208
|
+
return;
|
|
209
|
+
if (isParallelGroup(step)) {
|
|
210
|
+
graph.nodes.push(graphNodeForParallel(step, stepIndex, flatIndex, graph));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (isDynamicRunnerGroup(step)) {
|
|
214
|
+
graph.nodes.push(graphNodeForDynamic(step, stepIndex));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const node = graphNodeForSequential(step, stepIndex, flatIndex);
|
|
218
|
+
graph.nodes.push(node);
|
|
219
|
+
pushPhase(graph, step.phase, node.id);
|
|
220
|
+
}
|
|
221
|
+
export function appendRunnerStepsToStatus(input) {
|
|
222
|
+
let addedChainSteps = 0;
|
|
223
|
+
let addedFlatSteps = 0;
|
|
224
|
+
for (const step of input.steps) {
|
|
225
|
+
const stepIndex = input.status.chainStepCount ?? input.status.steps?.length ?? 0;
|
|
226
|
+
const flatIndex = input.status.steps?.length ?? 0;
|
|
227
|
+
const statusSteps = statusStepsForRunnerStep(step);
|
|
228
|
+
input.status.steps ??= [];
|
|
229
|
+
input.status.steps.push(...statusSteps);
|
|
230
|
+
if (isParallelGroup(step)) {
|
|
231
|
+
input.status.parallelGroups ??= [];
|
|
232
|
+
input.status.parallelGroups.push({ start: flatIndex, count: step.parallel.length, stepIndex });
|
|
233
|
+
} else if (isDynamicRunnerGroup(step)) {
|
|
234
|
+
input.status.parallelGroups ??= [];
|
|
235
|
+
input.status.parallelGroups.push({ start: flatIndex, count: 1, stepIndex });
|
|
236
|
+
}
|
|
237
|
+
appendWorkflowNode(input.status.workflowGraph, step, stepIndex, flatIndex);
|
|
238
|
+
input.status.chainStepCount = stepIndex + 1;
|
|
239
|
+
addedChainSteps++;
|
|
240
|
+
addedFlatSteps += statusSteps.length;
|
|
241
|
+
}
|
|
242
|
+
input.status.pendingAppends = input.pendingAppends ?? 0;
|
|
243
|
+
input.status.lastUpdate = input.now ?? Date.now();
|
|
244
|
+
return { addedChainSteps, addedFlatSteps };
|
|
245
|
+
}
|
|
@@ -1 +1,136 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { readStatus } from "../../shared/utils.js";
|
|
4
|
+
const TERMINAL_STATES = new Set(["complete", "failed", "paused"]);
|
|
5
|
+
const TERMINAL_STEP_STATUSES = new Set(["complete", "completed", "failed", "paused"]);
|
|
6
|
+
function readResultFile(resultPath) {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(fs.readFileSync(resultPath, "utf-8"));
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function selectedStatusStep(status, index) {
|
|
17
|
+
return status?.steps?.[index];
|
|
18
|
+
}
|
|
19
|
+
function isTerminalStatus(status, index) {
|
|
20
|
+
if (!status)
|
|
21
|
+
return false;
|
|
22
|
+
const step = selectedStatusStep(status, index);
|
|
23
|
+
if (step && TERMINAL_STEP_STATUSES.has(step.status))
|
|
24
|
+
return true;
|
|
25
|
+
return TERMINAL_STATES.has(status.state);
|
|
26
|
+
}
|
|
27
|
+
function resultState(result, child) {
|
|
28
|
+
if (!result)
|
|
29
|
+
return;
|
|
30
|
+
if (child?.success === true)
|
|
31
|
+
return "complete";
|
|
32
|
+
if (child?.success === false)
|
|
33
|
+
return result.state === "paused" ? "paused" : "failed";
|
|
34
|
+
if (result.state === "complete" || result.state === "failed" || result.state === "paused")
|
|
35
|
+
return result.state;
|
|
36
|
+
if (result.success === true)
|
|
37
|
+
return "complete";
|
|
38
|
+
if (result.success === false)
|
|
39
|
+
return "failed";
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
function outputFromTerminalStatus(root, status, step) {
|
|
43
|
+
const agent = step?.agent ?? status.steps?.[root.index]?.agent ?? "subagent";
|
|
44
|
+
const timedOut = step?.timedOut === true || status.timedOut === true;
|
|
45
|
+
const message = step?.error ?? status.error ?? `Attached async root ${root.runId} ended without a result file at ${root.resultPath}.`;
|
|
46
|
+
return {
|
|
47
|
+
agent,
|
|
48
|
+
output: message,
|
|
49
|
+
success: false,
|
|
50
|
+
exitCode: 1,
|
|
51
|
+
error: message,
|
|
52
|
+
...timedOut ? { timedOut: true } : {},
|
|
53
|
+
...step?.sessionFile ?? status.sessionFile ? { sessionFile: step?.sessionFile ?? status.sessionFile } : {},
|
|
54
|
+
...step?.model ? { model: step.model } : {},
|
|
55
|
+
...step?.attemptedModels ? { attemptedModels: step.attemptedModels } : {},
|
|
56
|
+
...step?.modelAttempts ? { modelAttempts: step.modelAttempts } : {},
|
|
57
|
+
...step?.totalCost ? { totalCost: step.totalCost } : {},
|
|
58
|
+
...step?.structuredOutput !== undefined ? { structuredOutput: step.structuredOutput } : {},
|
|
59
|
+
...step?.structuredOutputPath ? { structuredOutputPath: step.structuredOutputPath } : {},
|
|
60
|
+
...step?.structuredOutputSchemaPath ? { structuredOutputSchemaPath: step.structuredOutputSchemaPath } : {},
|
|
61
|
+
...step?.acceptance ? { acceptance: step.acceptance } : {}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function outputFromTimeout(root, status, message) {
|
|
65
|
+
const step = selectedStatusStep(status, root.index);
|
|
66
|
+
return {
|
|
67
|
+
agent: step?.agent ?? status?.steps?.[root.index]?.agent ?? "subagent",
|
|
68
|
+
output: message,
|
|
69
|
+
success: false,
|
|
70
|
+
exitCode: 1,
|
|
71
|
+
error: message,
|
|
72
|
+
timedOut: true,
|
|
73
|
+
...step?.sessionFile ?? status?.sessionFile ? { sessionFile: step?.sessionFile ?? status?.sessionFile } : {},
|
|
74
|
+
...step?.model ? { model: step.model } : {},
|
|
75
|
+
...step?.attemptedModels ? { attemptedModels: step.attemptedModels } : {},
|
|
76
|
+
...step?.modelAttempts ? { modelAttempts: step.modelAttempts } : {},
|
|
77
|
+
...step?.totalCost ? { totalCost: step.totalCost } : {}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function buildImportedResult(root, status, result) {
|
|
81
|
+
const child = result.results?.[root.index];
|
|
82
|
+
const step = selectedStatusStep(status, root.index);
|
|
83
|
+
const state = resultState(result, child);
|
|
84
|
+
const agent = child?.agent ?? step?.agent ?? status?.steps?.[root.index]?.agent ?? "subagent";
|
|
85
|
+
const output = child?.output ?? result.summary ?? "";
|
|
86
|
+
const timedOut = child?.timedOut === true || step?.timedOut === true || result.timedOut === true || status?.timedOut === true;
|
|
87
|
+
const success = state === "complete" && !timedOut;
|
|
88
|
+
const error = child?.error ?? (success ? undefined : result.error ?? result.summary ?? status?.error ?? `Attached async root ${root.runId} did not complete successfully.`);
|
|
89
|
+
return {
|
|
90
|
+
agent,
|
|
91
|
+
output: success ? output : output || error || "",
|
|
92
|
+
success,
|
|
93
|
+
exitCode: success ? 0 : 1,
|
|
94
|
+
...error ? { error } : {},
|
|
95
|
+
...timedOut ? { timedOut: true } : {},
|
|
96
|
+
...child?.sessionFile ?? step?.sessionFile ?? status?.sessionFile ? { sessionFile: child?.sessionFile ?? step?.sessionFile ?? status?.sessionFile } : {},
|
|
97
|
+
...child?.intercomTarget ? { intercomTarget: child.intercomTarget } : {},
|
|
98
|
+
...child?.model ?? step?.model ? { model: child?.model ?? step?.model } : {},
|
|
99
|
+
...child?.attemptedModels ?? step?.attemptedModels ? { attemptedModels: child?.attemptedModels ?? step?.attemptedModels } : {},
|
|
100
|
+
...child?.modelAttempts ?? step?.modelAttempts ? { modelAttempts: child?.modelAttempts ?? step?.modelAttempts } : {},
|
|
101
|
+
...child?.totalCost ?? step?.totalCost ? { totalCost: child?.totalCost ?? step?.totalCost } : {},
|
|
102
|
+
...child?.structuredOutput !== undefined ? { structuredOutput: child.structuredOutput } : step?.structuredOutput !== undefined ? { structuredOutput: step.structuredOutput } : {},
|
|
103
|
+
...child?.structuredOutputPath ?? step?.structuredOutputPath ? { structuredOutputPath: child?.structuredOutputPath ?? step?.structuredOutputPath } : {},
|
|
104
|
+
...child?.structuredOutputSchemaPath ?? step?.structuredOutputSchemaPath ? { structuredOutputSchemaPath: child?.structuredOutputSchemaPath ?? step?.structuredOutputSchemaPath } : {},
|
|
105
|
+
...child?.acceptance ?? step?.acceptance ? { acceptance: child?.acceptance ?? step?.acceptance } : {}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export async function waitForImportedAsyncRoot(root, options = {}) {
|
|
109
|
+
const pollIntervalMs = options.pollIntervalMs ?? 500;
|
|
110
|
+
const terminalResultGraceMs = options.terminalResultGraceMs ?? 1000;
|
|
111
|
+
const now = options.now ?? Date.now;
|
|
112
|
+
let terminalSince;
|
|
113
|
+
for (;; ) {
|
|
114
|
+
const status = readStatus(root.asyncDir);
|
|
115
|
+
if (options.shouldAbort?.())
|
|
116
|
+
return outputFromTimeout(root, status, options.timeoutMessage ?? "Subagent timed out.");
|
|
117
|
+
const result = readResultFile(root.resultPath);
|
|
118
|
+
if (result)
|
|
119
|
+
return buildImportedResult(root, status, result);
|
|
120
|
+
if (isTerminalStatus(status, root.index)) {
|
|
121
|
+
terminalSince ??= now();
|
|
122
|
+
if (now() - terminalSince >= terminalResultGraceMs) {
|
|
123
|
+
return outputFromTerminalStatus(root, status, selectedStatusStep(status, root.index));
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
terminalSince = undefined;
|
|
127
|
+
}
|
|
128
|
+
if (!status && !fs.existsSync(root.asyncDir)) {
|
|
129
|
+
throw new Error(`Attached async root '${root.runId}' directory does not exist: ${root.asyncDir}`);
|
|
130
|
+
}
|
|
131
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export function resolveAsyncRootResultPath(resultsDir, runId) {
|
|
135
|
+
return path.join(resultsDir, `${runId}.json`);
|
|
136
|
+
}
|
|
@@ -1 +1,94 @@
|
|
|
1
|
-
|
|
1
|
+
export const DEFAULT_COMPLETION_BATCH_CONFIG = {
|
|
2
|
+
enabled: true,
|
|
3
|
+
debounceMs: 150,
|
|
4
|
+
maxWaitMs: 1000,
|
|
5
|
+
stragglerDebounceMs: 75,
|
|
6
|
+
stragglerMaxWaitMs: 400,
|
|
7
|
+
stragglerWindowMs: 2000
|
|
8
|
+
};
|
|
9
|
+
function parsePositiveInt(value) {
|
|
10
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value) || value < 1)
|
|
11
|
+
return;
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
export function resolveCompletionBatchConfig(globalConfig, override) {
|
|
15
|
+
const enabled = typeof override?.enabled === "boolean" ? override.enabled : typeof globalConfig?.enabled === "boolean" ? globalConfig.enabled : DEFAULT_COMPLETION_BATCH_CONFIG.enabled;
|
|
16
|
+
return {
|
|
17
|
+
enabled,
|
|
18
|
+
debounceMs: parsePositiveInt(override?.debounceMs) ?? parsePositiveInt(globalConfig?.debounceMs) ?? DEFAULT_COMPLETION_BATCH_CONFIG.debounceMs,
|
|
19
|
+
maxWaitMs: parsePositiveInt(override?.maxWaitMs) ?? parsePositiveInt(globalConfig?.maxWaitMs) ?? DEFAULT_COMPLETION_BATCH_CONFIG.maxWaitMs,
|
|
20
|
+
stragglerDebounceMs: parsePositiveInt(override?.stragglerDebounceMs) ?? parsePositiveInt(globalConfig?.stragglerDebounceMs) ?? DEFAULT_COMPLETION_BATCH_CONFIG.stragglerDebounceMs,
|
|
21
|
+
stragglerMaxWaitMs: parsePositiveInt(override?.stragglerMaxWaitMs) ?? parsePositiveInt(globalConfig?.stragglerMaxWaitMs) ?? DEFAULT_COMPLETION_BATCH_CONFIG.stragglerMaxWaitMs,
|
|
22
|
+
stragglerWindowMs: parsePositiveInt(override?.stragglerWindowMs) ?? parsePositiveInt(globalConfig?.stragglerWindowMs) ?? DEFAULT_COMPLETION_BATCH_CONFIG.stragglerWindowMs
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const defaultTimers = {
|
|
26
|
+
setTimeout: (handler, delayMs) => setTimeout(handler, delayMs),
|
|
27
|
+
clearTimeout: (handle) => clearTimeout(handle)
|
|
28
|
+
};
|
|
29
|
+
function unrefHandle(handle) {
|
|
30
|
+
if (handle && typeof handle === "object" && "unref" in handle && typeof handle.unref === "function") {
|
|
31
|
+
handle.unref();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function createCompletionBatcher(options) {
|
|
35
|
+
const timers = options.timers ?? defaultTimers;
|
|
36
|
+
const now = options.now ?? Date.now;
|
|
37
|
+
const config = options.config;
|
|
38
|
+
if (!config.enabled) {
|
|
39
|
+
return {
|
|
40
|
+
push(item) {
|
|
41
|
+
options.emit([item]);
|
|
42
|
+
},
|
|
43
|
+
flush() {},
|
|
44
|
+
dispose() {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
let pending = [];
|
|
48
|
+
let debounceTimer = null;
|
|
49
|
+
let maxWaitTimer = null;
|
|
50
|
+
let straggler = false;
|
|
51
|
+
let lastEmitAt = null;
|
|
52
|
+
const clearTimers = () => {
|
|
53
|
+
if (debounceTimer) {
|
|
54
|
+
timers.clearTimeout(debounceTimer);
|
|
55
|
+
debounceTimer = null;
|
|
56
|
+
}
|
|
57
|
+
if (maxWaitTimer) {
|
|
58
|
+
timers.clearTimeout(maxWaitTimer);
|
|
59
|
+
maxWaitTimer = null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const emitGroup = () => {
|
|
63
|
+
clearTimers();
|
|
64
|
+
if (pending.length === 0)
|
|
65
|
+
return;
|
|
66
|
+
const items = pending;
|
|
67
|
+
pending = [];
|
|
68
|
+
lastEmitAt = now();
|
|
69
|
+
options.emit(items);
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
push(item) {
|
|
73
|
+
if (pending.length === 0) {
|
|
74
|
+
straggler = lastEmitAt !== null && now() - lastEmitAt < config.stragglerWindowMs;
|
|
75
|
+
}
|
|
76
|
+
pending.push(item);
|
|
77
|
+
if (debounceTimer)
|
|
78
|
+
timers.clearTimeout(debounceTimer);
|
|
79
|
+
const debounceDelay = straggler ? config.stragglerDebounceMs : config.debounceMs;
|
|
80
|
+
debounceTimer = timers.setTimeout(emitGroup, debounceDelay);
|
|
81
|
+
unrefHandle(debounceTimer);
|
|
82
|
+
if (!maxWaitTimer) {
|
|
83
|
+
const maxWaitDelay = straggler ? config.stragglerMaxWaitMs : config.maxWaitMs;
|
|
84
|
+
maxWaitTimer = timers.setTimeout(emitGroup, maxWaitDelay);
|
|
85
|
+
unrefHandle(maxWaitTimer);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
flush: emitGroup,
|
|
89
|
+
dispose() {
|
|
90
|
+
clearTimers();
|
|
91
|
+
pending = [];
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -1 +1,54 @@
|
|
|
1
|
-
function
|
|
1
|
+
function asNonEmptyString(value) {
|
|
2
|
+
if (typeof value !== "string")
|
|
3
|
+
return;
|
|
4
|
+
const trimmed = value.trim();
|
|
5
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
6
|
+
}
|
|
7
|
+
function asFiniteNumber(value) {
|
|
8
|
+
if (typeof value !== "number")
|
|
9
|
+
return;
|
|
10
|
+
return Number.isFinite(value) ? value : undefined;
|
|
11
|
+
}
|
|
12
|
+
export function buildCompletionKey(data, fallback) {
|
|
13
|
+
const id = asNonEmptyString(data.id);
|
|
14
|
+
if (id)
|
|
15
|
+
return `id:${id}`;
|
|
16
|
+
const sessionId = asNonEmptyString(data.sessionId) ?? "no-session";
|
|
17
|
+
const agent = asNonEmptyString(data.agent) ?? "unknown";
|
|
18
|
+
const timestamp = asFiniteNumber(data.timestamp);
|
|
19
|
+
const taskIndex = asFiniteNumber(data.taskIndex);
|
|
20
|
+
const totalTasks = asFiniteNumber(data.totalTasks);
|
|
21
|
+
const success = typeof data.success === "boolean" ? data.success ? "1" : "0" : "?";
|
|
22
|
+
return [
|
|
23
|
+
"meta",
|
|
24
|
+
sessionId,
|
|
25
|
+
agent,
|
|
26
|
+
timestamp !== undefined ? String(timestamp) : "no-ts",
|
|
27
|
+
taskIndex !== undefined ? String(taskIndex) : "-",
|
|
28
|
+
totalTasks !== undefined ? String(totalTasks) : "-",
|
|
29
|
+
success,
|
|
30
|
+
fallback
|
|
31
|
+
].join(":");
|
|
32
|
+
}
|
|
33
|
+
function pruneSeenMap(seen, now, ttlMs) {
|
|
34
|
+
for (const [key, ts] of seen.entries()) {
|
|
35
|
+
if (now - ts > ttlMs)
|
|
36
|
+
seen.delete(key);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function markSeenWithTtl(seen, key, now, ttlMs) {
|
|
40
|
+
pruneSeenMap(seen, now, ttlMs);
|
|
41
|
+
if (seen.has(key))
|
|
42
|
+
return true;
|
|
43
|
+
seen.set(key, now);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
export function getGlobalSeenMap(storeKey) {
|
|
47
|
+
const globalStore = globalThis;
|
|
48
|
+
const existing = globalStore[storeKey];
|
|
49
|
+
if (existing instanceof Map)
|
|
50
|
+
return existing;
|
|
51
|
+
const map = new Map;
|
|
52
|
+
globalStore[storeKey] = map;
|
|
53
|
+
return map;
|
|
54
|
+
}
|