@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 +1,41 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
const MAX_NESTED_ID_LENGTH = 128;
|
|
3
|
+
export const MAX_NESTED_PATH_ENTRIES = 4;
|
|
4
|
+
export function isSafeNestedPathId(value) {
|
|
5
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_NESTED_ID_LENGTH && !path.isAbsolute(value) && !value.includes("/") && !value.includes("\\") && !value.includes("..");
|
|
6
|
+
}
|
|
7
|
+
function finiteNumber(value) {
|
|
8
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
9
|
+
}
|
|
10
|
+
function nonEmptyString(value, max) {
|
|
11
|
+
return typeof value === "string" && value.length > 0 ? value.slice(0, max) : undefined;
|
|
12
|
+
}
|
|
13
|
+
export function sanitizeNestedPath(value) {
|
|
14
|
+
if (!Array.isArray(value))
|
|
15
|
+
return [];
|
|
16
|
+
return value.map((part) => {
|
|
17
|
+
if (!part || typeof part !== "object")
|
|
18
|
+
return;
|
|
19
|
+
const record = part;
|
|
20
|
+
if (!isSafeNestedPathId(record.runId))
|
|
21
|
+
return;
|
|
22
|
+
return {
|
|
23
|
+
runId: record.runId,
|
|
24
|
+
...finiteNumber(record.stepIndex) !== undefined ? { stepIndex: finiteNumber(record.stepIndex) } : {},
|
|
25
|
+
...nonEmptyString(record.agent, 128) ? { agent: nonEmptyString(record.agent, 128) } : {}
|
|
26
|
+
};
|
|
27
|
+
}).filter((part) => Boolean(part)).slice(0, MAX_NESTED_PATH_ENTRIES);
|
|
28
|
+
}
|
|
29
|
+
export function parseNestedPathEnv(value) {
|
|
30
|
+
if (!value)
|
|
31
|
+
return [];
|
|
32
|
+
try {
|
|
33
|
+
return sanitizeNestedPath(JSON.parse(value));
|
|
34
|
+
} catch {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function encodeNestedPathEnv(value) {
|
|
39
|
+
const sanitized = sanitizeNestedPath(value);
|
|
40
|
+
return sanitized.length ? JSON.stringify(sanitized) : "";
|
|
41
|
+
}
|
|
@@ -1 +1,105 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { formatDuration, formatTokens, shortenPath } from "../../shared/formatters.js";
|
|
2
|
+
import { formatActivityLabel } from "../../shared/status-format.js";
|
|
3
|
+
export function countNestedRuns(children) {
|
|
4
|
+
const counts = { total: 0, running: 0, paused: 0, complete: 0, failed: 0, queued: 0 };
|
|
5
|
+
for (const child of children ?? []) {
|
|
6
|
+
counts.total++;
|
|
7
|
+
counts[child.state]++;
|
|
8
|
+
const nested = countNestedRuns([...child.children ?? [], ...child.steps?.flatMap((step) => step.children ?? []) ?? []]);
|
|
9
|
+
counts.total += nested.total;
|
|
10
|
+
counts.running += nested.running;
|
|
11
|
+
counts.paused += nested.paused;
|
|
12
|
+
counts.complete += nested.complete;
|
|
13
|
+
counts.failed += nested.failed;
|
|
14
|
+
counts.queued += nested.queued;
|
|
15
|
+
}
|
|
16
|
+
return counts;
|
|
17
|
+
}
|
|
18
|
+
export function formatNestedAggregate(children) {
|
|
19
|
+
const counts = countNestedRuns(children);
|
|
20
|
+
if (counts.total === 0)
|
|
21
|
+
return;
|
|
22
|
+
const parts = [
|
|
23
|
+
counts.running > 0 ? `${counts.running} running` : "",
|
|
24
|
+
counts.paused > 0 ? `${counts.paused} paused` : "",
|
|
25
|
+
counts.failed > 0 ? `${counts.failed} failed` : "",
|
|
26
|
+
counts.complete > 0 ? `${counts.complete} complete` : "",
|
|
27
|
+
counts.queued > 0 ? `${counts.queued} queued` : ""
|
|
28
|
+
].filter(Boolean);
|
|
29
|
+
return `+${counts.total} nested run${counts.total === 1 ? "" : "s"}${parts.length ? ` (${parts.join(", ")})` : ""}`;
|
|
30
|
+
}
|
|
31
|
+
function nestedRunLabel(run) {
|
|
32
|
+
if (run.agent)
|
|
33
|
+
return run.agent;
|
|
34
|
+
if (run.agents?.length)
|
|
35
|
+
return run.agents.length === 1 ? run.agents[0] : `${run.agents.slice(0, 2).join(", ")}${run.agents.length > 2 ? ` +${run.agents.length - 2}` : ""}`;
|
|
36
|
+
return run.id;
|
|
37
|
+
}
|
|
38
|
+
function formatNestedActivity(input) {
|
|
39
|
+
const facts = [];
|
|
40
|
+
if (input.currentTool && input.currentToolStartedAt !== undefined)
|
|
41
|
+
facts.push(`tool ${input.currentTool} ${formatDuration(Math.max(0, Date.now() - input.currentToolStartedAt))}`);
|
|
42
|
+
else if (input.currentTool)
|
|
43
|
+
facts.push(`tool ${input.currentTool}`);
|
|
44
|
+
if (input.currentPath)
|
|
45
|
+
facts.push(shortenPath(input.currentPath));
|
|
46
|
+
if (input.turnCount !== undefined)
|
|
47
|
+
facts.push(`${input.turnCount} turns`);
|
|
48
|
+
if (input.toolCount !== undefined)
|
|
49
|
+
facts.push(`${input.toolCount} tools`);
|
|
50
|
+
if (input.totalTokens)
|
|
51
|
+
facts.push(`${formatTokens(input.totalTokens.total)} tok`);
|
|
52
|
+
const activity = formatActivityLabel(input.lastActivityAt, input.activityState);
|
|
53
|
+
return activity || facts.length ? [activity, ...facts].filter(Boolean).join(" | ") : undefined;
|
|
54
|
+
}
|
|
55
|
+
function formatNestedRunLines(children, options) {
|
|
56
|
+
const lines = [];
|
|
57
|
+
const append = (items, depth, indent) => {
|
|
58
|
+
if (!items?.length || lines.length >= options.maxLines)
|
|
59
|
+
return;
|
|
60
|
+
if (depth > options.maxDepth) {
|
|
61
|
+
const aggregate = formatNestedAggregate(items);
|
|
62
|
+
if (aggregate && lines.length < options.maxLines)
|
|
63
|
+
lines.push(`${indent}↳ ${aggregate}`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (let index = 0;index < items.length; index++) {
|
|
67
|
+
const child = items[index];
|
|
68
|
+
if (lines.length >= options.maxLines) {
|
|
69
|
+
const aggregate = formatNestedAggregate(items.slice(index));
|
|
70
|
+
if (aggregate)
|
|
71
|
+
lines[lines.length - 1] = `${indent}↳ ${aggregate}`;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const activity = child.state === "running" ? formatNestedActivity(child) : undefined;
|
|
75
|
+
const error = child.error ? ` | error: ${child.error}` : "";
|
|
76
|
+
lines.push(`${indent}↳ ${nestedRunLabel(child)} [${child.id}] ${child.state}${activity ? ` | ${activity}` : ""}${error}`);
|
|
77
|
+
if (options.commandHints && lines.length < options.maxLines)
|
|
78
|
+
lines.push(`${indent} Status: subagent({ action: "status", id: "${child.id}" })`);
|
|
79
|
+
if (depth === options.maxDepth) {
|
|
80
|
+
const aggregate = formatNestedAggregate([...child.steps?.flatMap((step) => step.children ?? []) ?? [], ...child.children ?? []]);
|
|
81
|
+
if (aggregate && lines.length < options.maxLines)
|
|
82
|
+
lines.push(`${indent} ↳ ${aggregate}`);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
for (const [stepIndex, step] of (child.steps ?? []).entries()) {
|
|
86
|
+
if (lines.length >= options.maxLines)
|
|
87
|
+
return;
|
|
88
|
+
const stepActivity = step.status === "running" ? formatNestedActivity(step) : undefined;
|
|
89
|
+
lines.push(`${indent} ${stepIndex + 1}. ${step.agent} ${step.status}${stepActivity ? ` | ${stepActivity}` : ""}${step.error ? ` | error: ${step.error}` : ""}`);
|
|
90
|
+
append(step.children, depth + 1, `${indent} `);
|
|
91
|
+
}
|
|
92
|
+
append(child.children, depth + 1, `${indent} `);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
append(children, 0, options.indent);
|
|
96
|
+
return lines;
|
|
97
|
+
}
|
|
98
|
+
export function formatNestedRunStatusLines(children, options = {}) {
|
|
99
|
+
return formatNestedRunLines(children, {
|
|
100
|
+
indent: options.indent ?? " ",
|
|
101
|
+
maxDepth: options.maxDepth ?? 2,
|
|
102
|
+
maxLines: options.maxLines ?? 40,
|
|
103
|
+
commandHints: options.commandHints ?? false
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -1,5 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export function isParallelGroup(step) {
|
|
2
|
+
return "parallel" in step && Array.isArray(step.parallel);
|
|
3
|
+
}
|
|
4
|
+
export function isDynamicRunnerGroup(step) {
|
|
5
|
+
return "expand" in step && "collect" in step && "parallel" in step && !Array.isArray(step.parallel);
|
|
6
|
+
}
|
|
7
|
+
export function flattenSteps(steps) {
|
|
8
|
+
const flat = [];
|
|
9
|
+
for (const step of steps) {
|
|
10
|
+
if (isParallelGroup(step)) {
|
|
11
|
+
for (const task of step.parallel)
|
|
12
|
+
flat.push(task);
|
|
13
|
+
} else if (isDynamicRunnerGroup(step)) {
|
|
14
|
+
continue;
|
|
15
|
+
} else {
|
|
16
|
+
flat.push(step);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return flat;
|
|
20
|
+
}
|
|
21
|
+
export const DEFAULT_GLOBAL_CONCURRENCY_LIMIT = 20;
|
|
4
22
|
|
|
5
|
-
|
|
23
|
+
export class Semaphore {
|
|
24
|
+
available;
|
|
25
|
+
queue = [];
|
|
26
|
+
constructor(limit) {
|
|
27
|
+
this.available = Math.max(1, Math.floor(limit) || 1);
|
|
28
|
+
}
|
|
29
|
+
acquire() {
|
|
30
|
+
if (this.available > 0) {
|
|
31
|
+
this.available--;
|
|
32
|
+
return Promise.resolve();
|
|
33
|
+
}
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
this.queue.push(resolve);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
release() {
|
|
39
|
+
const next = this.queue.shift();
|
|
40
|
+
if (next) {
|
|
41
|
+
next();
|
|
42
|
+
} else {
|
|
43
|
+
this.available++;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export async function mapConcurrent(items, limit, fn, globalSemaphore) {
|
|
48
|
+
const safeLimit = Math.max(1, Math.floor(limit) || 1);
|
|
49
|
+
const results = new Array(items.length);
|
|
50
|
+
let next = 0;
|
|
51
|
+
async function worker(_workerIndex) {
|
|
52
|
+
while (next < items.length) {
|
|
53
|
+
const i = next++;
|
|
54
|
+
if (globalSemaphore) {
|
|
55
|
+
await globalSemaphore.acquire();
|
|
56
|
+
try {
|
|
57
|
+
results[i] = await fn(items[i], i);
|
|
58
|
+
} finally {
|
|
59
|
+
globalSemaphore.release();
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
results[i] = await fn(items[i], i);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
await Promise.all(Array.from({ length: Math.min(safeLimit, items.length) }, (_, wi) => worker(wi)));
|
|
67
|
+
return results;
|
|
68
|
+
}
|
|
69
|
+
export function aggregateParallelOutputs(results, headerFormat = (i, agent) => `=== Parallel Task ${i + 1} (${agent}) ===`) {
|
|
70
|
+
return results.map((r, i) => {
|
|
71
|
+
const header = headerFormat(r.taskIndex ?? i, r.agent);
|
|
72
|
+
const hasOutput = Boolean(r.output?.trim());
|
|
73
|
+
const status = r.timedOut ? `TIMED OUT${r.error ? `: ${r.error}` : ""}` : r.exitCode === -1 ? "SKIPPED" : r.exitCode !== 0 && r.exitCode !== null ? `FAILED (exit code ${r.exitCode})${r.error ? `: ${r.error}` : ""}` : r.error ? `WARNING: ${r.error}` : !hasOutput && r.outputTargetPath && r.outputTargetExists === false ? `EMPTY OUTPUT (expected output file missing: ${r.outputTargetPath})` : !hasOutput && !r.outputTargetPath ? "EMPTY OUTPUT (no textual response returned)" : "";
|
|
74
|
+
const body = status ? hasOutput ? `${status}
|
|
75
|
+
${r.output}` : status : r.output;
|
|
76
|
+
return `${header}
|
|
77
|
+
${body}`;
|
|
78
|
+
}).join(`
|
|
79
|
+
|
|
80
|
+
`);
|
|
81
|
+
}
|
|
82
|
+
export const MAX_PARALLEL_CONCURRENCY = 4;
|
|
@@ -1,5 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { getAgentDir } from "../../shared/utils.js";
|
|
4
|
+
const ROTATE_READ_THRESHOLD = 1200;
|
|
5
|
+
const ROTATE_KEEP = 1000;
|
|
6
|
+
function getHistoryPath() {
|
|
7
|
+
return path.join(getAgentDir(), "run-history.jsonl");
|
|
8
|
+
}
|
|
9
|
+
export function recordRun(agent, task, exitCode, durationMs) {
|
|
10
|
+
try {
|
|
11
|
+
const entry = {
|
|
12
|
+
agent,
|
|
13
|
+
task: task.slice(0, 200),
|
|
14
|
+
ts: Math.floor(Date.now() / 1000),
|
|
15
|
+
status: exitCode === 0 ? "ok" : "error",
|
|
16
|
+
duration: durationMs,
|
|
17
|
+
...exitCode !== 0 ? { exit: exitCode } : {}
|
|
18
|
+
};
|
|
19
|
+
const historyPath = getHistoryPath();
|
|
20
|
+
fs.mkdirSync(path.dirname(historyPath), { recursive: true });
|
|
21
|
+
fs.appendFileSync(historyPath, `${JSON.stringify(entry)}
|
|
22
|
+
`);
|
|
23
|
+
} catch {}
|
|
24
|
+
}
|
|
25
|
+
export function loadRunsForAgent(agent) {
|
|
26
|
+
const historyPath = getHistoryPath();
|
|
27
|
+
if (!fs.existsSync(historyPath))
|
|
28
|
+
return [];
|
|
29
|
+
let raw;
|
|
30
|
+
try {
|
|
31
|
+
raw = fs.readFileSync(historyPath, "utf-8");
|
|
32
|
+
} catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
let lines = raw.split(`
|
|
36
|
+
`).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
37
|
+
if (lines.length > ROTATE_READ_THRESHOLD) {
|
|
38
|
+
lines = lines.slice(-ROTATE_KEEP);
|
|
39
|
+
try {
|
|
40
|
+
fs.writeFileSync(historyPath, `${lines.join(`
|
|
4
41
|
`)}
|
|
5
|
-
`,"utf-8")
|
|
42
|
+
`, "utf-8");
|
|
43
|
+
} catch {}
|
|
44
|
+
}
|
|
45
|
+
return lines.map((line) => {
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(line);
|
|
48
|
+
} catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}).filter((entry) => Boolean(entry) && entry.agent === agent).reverse();
|
|
52
|
+
}
|
|
@@ -1,14 +1,155 @@
|
|
|
1
|
-
import*as
|
|
2
|
-
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
export function normalizeSingleOutputOverride(output, defaultOutput) {
|
|
4
|
+
if (output === false || output === "false")
|
|
5
|
+
return false;
|
|
6
|
+
if (output === true || output === "true")
|
|
7
|
+
return defaultOutput;
|
|
8
|
+
if (typeof output === "string" && output.length > 0)
|
|
9
|
+
return output;
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
export function resolveSingleOutputPath(output, runtimeCwd, requestedCwd, relativeBaseDir) {
|
|
13
|
+
if (typeof output !== "string" || !output || output === "false" || output === "true")
|
|
14
|
+
return;
|
|
15
|
+
if (path.isAbsolute(output))
|
|
16
|
+
return output;
|
|
17
|
+
if (relativeBaseDir)
|
|
18
|
+
return path.resolve(relativeBaseDir, output);
|
|
19
|
+
const baseCwd = requestedCwd ? path.isAbsolute(requestedCwd) ? requestedCwd : path.resolve(runtimeCwd, requestedCwd) : runtimeCwd;
|
|
20
|
+
return path.resolve(baseCwd, output);
|
|
21
|
+
}
|
|
22
|
+
function formatOutputPathInstruction(outputPath) {
|
|
23
|
+
return [
|
|
24
|
+
`Write your findings to exactly this path: ${outputPath}`,
|
|
25
|
+
"This path is authoritative for this run.",
|
|
26
|
+
"Ignore any other output filename or output path mentioned elsewhere, including output destinations in the base agent prompt, system prompt, or task instructions."
|
|
27
|
+
].join(`
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
export function injectSingleOutputInstruction(task, outputPath) {
|
|
31
|
+
if (!outputPath)
|
|
32
|
+
return task;
|
|
33
|
+
return `${task}
|
|
3
34
|
|
|
4
35
|
---
|
|
5
36
|
**Output:**
|
|
6
|
-
${
|
|
7
|
-
|
|
37
|
+
${formatOutputPathInstruction(outputPath)}`;
|
|
38
|
+
}
|
|
39
|
+
export function injectOutputPathSystemPrompt(systemPrompt, outputPath) {
|
|
40
|
+
if (!outputPath)
|
|
41
|
+
return systemPrompt;
|
|
42
|
+
const instruction = `Runtime output path override:
|
|
43
|
+
${formatOutputPathInstruction(outputPath)}`;
|
|
44
|
+
return systemPrompt ? `${systemPrompt}
|
|
8
45
|
|
|
9
|
-
${
|
|
46
|
+
${instruction}` : instruction;
|
|
47
|
+
}
|
|
48
|
+
function countLines(text) {
|
|
49
|
+
if (!text)
|
|
50
|
+
return 0;
|
|
51
|
+
const newlineMatches = text.match(/\r\n|\r|\n/g);
|
|
52
|
+
return (newlineMatches?.length ?? 0) + (/[\r\n]$/.test(text) ? 0 : 1);
|
|
53
|
+
}
|
|
54
|
+
function formatByteSize(bytes) {
|
|
55
|
+
if (bytes < 1024)
|
|
56
|
+
return `${bytes} B`;
|
|
57
|
+
const units = ["KB", "MB", "GB", "TB"];
|
|
58
|
+
let value = bytes / 1024;
|
|
59
|
+
let unitIndex = 0;
|
|
60
|
+
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
61
|
+
value /= 1024;
|
|
62
|
+
unitIndex++;
|
|
63
|
+
}
|
|
64
|
+
return `${value.toFixed(1)} ${units[unitIndex]}`;
|
|
65
|
+
}
|
|
66
|
+
export function formatSavedOutputReference(savedPath, fullOutput) {
|
|
67
|
+
const absolutePath = path.resolve(savedPath);
|
|
68
|
+
const bytes = Buffer.byteLength(fullOutput, "utf-8");
|
|
69
|
+
const lines = countLines(fullOutput);
|
|
70
|
+
return {
|
|
71
|
+
path: absolutePath,
|
|
72
|
+
bytes,
|
|
73
|
+
lines,
|
|
74
|
+
message: `Output saved to: ${absolutePath} (${formatByteSize(bytes)}, ${lines} ${lines === 1 ? "line" : "lines"}). Read this file if needed.`
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function validateFileOnlyOutputMode(outputMode, outputPath, context) {
|
|
78
|
+
if (outputMode === "file-only" && !outputPath) {
|
|
79
|
+
return `${context} sets outputMode: "file-only" but does not configure an output file. Set output to a path or use outputMode: "inline".`;
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
export function captureSingleOutputSnapshot(outputPath) {
|
|
84
|
+
if (!outputPath)
|
|
85
|
+
return;
|
|
86
|
+
try {
|
|
87
|
+
const stat = fs.statSync(outputPath);
|
|
88
|
+
return { exists: true, mtimeMs: stat.mtimeMs, size: stat.size };
|
|
89
|
+
} catch {
|
|
90
|
+
return { exists: false };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function persistSingleOutput(outputPath, fullOutput) {
|
|
94
|
+
if (!outputPath)
|
|
95
|
+
return {};
|
|
96
|
+
try {
|
|
97
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
98
|
+
fs.writeFileSync(outputPath, fullOutput, "utf-8");
|
|
99
|
+
return { savedPath: outputPath };
|
|
100
|
+
} catch (err) {
|
|
101
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function resolveSingleOutput(outputPath, fallbackOutput, beforeRun) {
|
|
105
|
+
if (!outputPath)
|
|
106
|
+
return { fullOutput: fallbackOutput };
|
|
107
|
+
let changedSinceStart = false;
|
|
108
|
+
try {
|
|
109
|
+
const stat = fs.statSync(outputPath);
|
|
110
|
+
changedSinceStart = !beforeRun?.exists || stat.mtimeMs !== beforeRun.mtimeMs || stat.size !== beforeRun.size;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
const code = error && typeof error === "object" && "code" in error ? error.code : undefined;
|
|
113
|
+
if (code !== "ENOENT" && code !== "ENOTDIR") {
|
|
114
|
+
return {
|
|
115
|
+
fullOutput: fallbackOutput,
|
|
116
|
+
saveError: `Failed to inspect output file: ${error instanceof Error ? error.message : String(error)}`
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (changedSinceStart) {
|
|
121
|
+
try {
|
|
122
|
+
return { fullOutput: fs.readFileSync(outputPath, "utf-8"), savedPath: outputPath };
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return {
|
|
125
|
+
fullOutput: fallbackOutput,
|
|
126
|
+
saveError: `Failed to read changed output file: ${error instanceof Error ? error.message : String(error)}`
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const save = persistSingleOutput(outputPath, fallbackOutput);
|
|
131
|
+
if (save.savedPath)
|
|
132
|
+
return { fullOutput: fallbackOutput, savedPath: save.savedPath };
|
|
133
|
+
return { fullOutput: fallbackOutput, saveError: save.error };
|
|
134
|
+
}
|
|
135
|
+
export function finalizeSingleOutput(params) {
|
|
136
|
+
let displayOutput = params.truncatedOutput || params.fullOutput;
|
|
137
|
+
if (params.exitCode === 0 && params.savedPath) {
|
|
138
|
+
const outputReference = params.outputReference ?? formatSavedOutputReference(params.savedPath, params.fullOutput);
|
|
139
|
+
if (params.outputMode === "file-only") {
|
|
140
|
+
return { displayOutput: outputReference.message, savedPath: params.savedPath, outputReference };
|
|
141
|
+
}
|
|
142
|
+
displayOutput += `
|
|
10
143
|
|
|
11
|
-
${
|
|
144
|
+
${outputReference.message}`;
|
|
145
|
+
return { displayOutput, savedPath: params.savedPath, outputReference };
|
|
146
|
+
}
|
|
147
|
+
if (params.exitCode === 0 && params.saveError && params.outputPath) {
|
|
148
|
+
displayOutput += `
|
|
12
149
|
|
|
13
|
-
Output file error: ${
|
|
14
|
-
${
|
|
150
|
+
Output file error: ${params.outputPath}
|
|
151
|
+
${params.saveError}`;
|
|
152
|
+
return { displayOutput, saveError: params.saveError };
|
|
153
|
+
}
|
|
154
|
+
return { displayOutput };
|
|
155
|
+
}
|
|
@@ -1 +1,58 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { Compile } from "typebox/compile";
|
|
5
|
+
export const STRUCTURED_OUTPUT_SCHEMA_ENV = "DM_SUBAGENT_STRUCTURED_OUTPUT_SCHEMA";
|
|
6
|
+
export const STRUCTURED_OUTPUT_CAPTURE_ENV = "DM_SUBAGENT_STRUCTURED_OUTPUT_CAPTURE";
|
|
7
|
+
export function assertJsonSchemaObject(schema, label = "outputSchema") {
|
|
8
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
|
|
9
|
+
throw new Error(`${label} must be a JSON Schema object.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function createStructuredOutputRuntime(schema, baseDir) {
|
|
13
|
+
assertJsonSchemaObject(schema);
|
|
14
|
+
const rootDir = baseDir ?? os.tmpdir();
|
|
15
|
+
fs.mkdirSync(rootDir, { recursive: true });
|
|
16
|
+
const dir = fs.mkdtempSync(path.join(rootDir, "dm-subagent-structured-"));
|
|
17
|
+
const schemaPath = path.join(dir, "schema.json");
|
|
18
|
+
const outputPath = path.join(dir, "output.json");
|
|
19
|
+
fs.writeFileSync(schemaPath, JSON.stringify(schema), { mode: 384 });
|
|
20
|
+
return { schema, schemaPath, outputPath };
|
|
21
|
+
}
|
|
22
|
+
export function validateStructuredOutputValue(schema, value) {
|
|
23
|
+
let validator;
|
|
24
|
+
try {
|
|
25
|
+
validator = Compile(schema);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return { status: "invalid", message: `invalid outputSchema: ${error instanceof Error ? error.message : String(error)}` };
|
|
28
|
+
}
|
|
29
|
+
if (validator.Check(value))
|
|
30
|
+
return { status: "valid" };
|
|
31
|
+
const errors = [...validator.Errors(value)].slice(0, 8).map((error) => {
|
|
32
|
+
const pathText = error.instancePath ? error.instancePath.replace(/^\//, "").replace(/\//g, ".") : "root";
|
|
33
|
+
return `${pathText}: ${error.message}`;
|
|
34
|
+
});
|
|
35
|
+
return { status: "invalid", message: errors.join("; ") || "schema validation failed" };
|
|
36
|
+
}
|
|
37
|
+
export function readStructuredOutput(runtime) {
|
|
38
|
+
if (!fs.existsSync(runtime.outputPath)) {
|
|
39
|
+
return { error: "Missing structured_output call; this step has outputSchema and must finish by calling structured_output." };
|
|
40
|
+
}
|
|
41
|
+
let value;
|
|
42
|
+
try {
|
|
43
|
+
value = JSON.parse(fs.readFileSync(runtime.outputPath, "utf-8"));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return { error: `Failed to read structured output: ${error instanceof Error ? error.message : String(error)}` };
|
|
46
|
+
}
|
|
47
|
+
const validation = validateStructuredOutputValue(runtime.schema, value);
|
|
48
|
+
if (validation.status === "invalid")
|
|
49
|
+
return { error: `Structured output validation failed: ${validation.message}` };
|
|
50
|
+
return { value };
|
|
51
|
+
}
|
|
52
|
+
export function cleanupStructuredOutputRuntime(runtime) {
|
|
53
|
+
if (!runtime)
|
|
54
|
+
return;
|
|
55
|
+
try {
|
|
56
|
+
fs.rmSync(path.dirname(runtime.schemaPath), { recursive: true, force: true });
|
|
57
|
+
} catch {}
|
|
58
|
+
}
|