@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,12 +1,313 @@
|
|
|
1
|
-
import*as m from"node:fs";import*as T from"node:path";import*as z from"node:fs";import*as P from"node:path";var D=new Map;function s($){return $ instanceof Error?$.message:String($)}function H$($){return typeof $==="object"&&$!==null&&"code"in $&&$.code==="ENOENT"}function W$($){let f=P.join($,"status.json"),j;try{j=z.statSync(f)}catch(q){if(H$(q))return null;throw Error(`Failed to inspect async status file '${f}': ${s(q)}`,{cause:q instanceof Error?q:void 0})}let J=D.get(f);if(J&&J.mtime===j.mtimeMs)return J.status;let Q;try{Q=z.readFileSync(f,"utf-8")}catch(q){if(H$(q))return null;throw Error(`Failed to read async status file '${f}': ${s(q)}`,{cause:q instanceof Error?q:void 0})}let Z;try{Z=JSON.parse(Q)}catch(q){throw Error(`Failed to parse async status file '${f}': ${s(q)}`,{cause:q instanceof Error?q:void 0})}if(D.set(f,{mtime:j.mtimeMs,status:Z}),D.size>50){let q=D.keys().next().value;if(q)D.delete(q)}return Z}import*as x from"node:os";import*as I from"node:path";function c($){return $.trim().replace(/[^A-Za-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"unknown"}function o$($){let f=$?.env??process.env,j=$&&Object.hasOwn($,"getuid")?$.getuid:process.getuid?.bind(process);if(typeof j==="function")return`uid-${j()}`;for(let q of["USERNAME","USER","LOGNAME"]){let B=f[q];if(B)return`user-${c(B)}`}let J=$&&Object.hasOwn($,"userInfo")?$.userInfo:x.userInfo;try{let q=J?.().username;if(q)return`user-${c(q)}`}catch{}let Q=f.USERPROFILE??f.HOME;if(Q)return`home-${c(Q)}`;let Z=$&&Object.hasOwn($,"homedir")?$.homedir:x.homedir;try{let q=Z?.();if(q)return`home-${c(q)}`}catch{}return"shared"}var S=I.join(x.tmpdir(),`dm-subagents-${o$()}`),h=I.join(S,"async-subagent-results"),u$=I.join(S,"async-subagent-runs"),p$=I.join(S,"chain-runs"),a0=I.join(S,"artifacts");var e=["off","minimal","low","medium","high","xhigh"];function G$($){let f=$.lastIndexOf(":");if(f===-1)return{baseModel:$,thinkingSuffix:""};let j=e.find((J)=>J===$.substring(f+1));if(!j)return{baseModel:$,thinkingSuffix:""};return{baseModel:$.substring(0,f),thinkingSuffix:`:${j}`}}function d($){return $<1000?String($):$<1e4?`${($/1000).toFixed(1)}k`:`${Math.round($/1000)}k`}function L$($,f){let j=$?G$($):void 0,J=j?.baseModel??$,Q=e.find((q)=>q===f?.trim()),Z=j?.thinkingSuffix?j.thinkingSuffix.slice(1):Q;if(J){let q=J.lastIndexOf("/");if(q!==-1)J=J.slice(q+1)}return[J,Z?`thinking ${Z}`:void 0].filter(Boolean).join(" · ")}function w($){if($<1000)return`${$}ms`;if($<60000)return`${($/1000).toFixed(1)}s`;return`${Math.floor($/60000)}m${Math.floor($%60000/1000)}s`}function b($){let f=process.env.HOME;if(f&&$.startsWith(f))return`~${$.slice(f.length)}`;return $}function l$($){if($<1000)return"now";if($<60000)return`${Math.floor($/1000)}s`;return`${Math.floor($/60000)}m`}function n($,f,j=Date.now()){if($===void 0){if(f==="needs_attention")return"needs attention";if(f==="active_long_running")return"active but long-running";return}let J=l$(Math.max(0,j-$));if(f==="needs_attention")return`no activity for ${J}`;if(f==="active_long_running")return`active but long-running · last activity ${J} ago`;return J==="now"?"active now":`active ${J} ago`}function r$($){return $==="complete"||$==="completed"}function i$($){return $===1?"1 agent running":`${$} agents running`}function t($,f,j={}){let J=$.filter((O)=>O.status==="running").length,Q=$.filter((O)=>r$(O.status)).length,Z=$.filter((O)=>O.status==="failed").length,q=$.filter((O)=>O.status==="paused").length,B=[`${Q}/${f} done`];if(j.showRunning!==!1&&J>0)B.unshift(i$(J));if(Z>0)B.push(`${Z} failed`);if(q>0)B.push(`${q} paused`);return B.join(" · ")}import{randomUUID as X0}from"node:crypto";import*as M from"node:fs";import*as G from"node:path";import*as M$ from"node:path";var a$=128,s$=4;function $$($){return typeof $==="string"&&$.length>0&&$.length<=a$&&!M$.isAbsolute($)&&!$.includes("/")&&!$.includes("\\")&&!$.includes("..")}function V$($){return typeof $==="number"&&Number.isFinite($)?$:void 0}function U$($,f){return typeof $==="string"&&$.length>0?$.slice(0,f):void 0}function A$($){if(!Array.isArray($))return[];return $.map((f)=>{if(!f||typeof f!=="object")return;let j=f;if(!$$(j.runId))return;return{runId:j.runId,...V$(j.stepIndex)!==void 0?{stepIndex:V$(j.stepIndex)}:{},...U$(j.agent,128)?{agent:U$(j.agent,128)}:{}}}).filter((f)=>Boolean(f)).slice(0,s$)}import*as C from"node:path";import{fileURLToPath as T$}from"node:url";import*as F from"node:os";import*as _ from"node:path";var Wf=_.join(F.homedir(),".config","mcp","mcp.json"),Gf={cursor:[_.join(F.homedir(),".cursor","mcp.json")],"claude-code":[_.join(F.homedir(),".claude","mcp.json"),_.join(F.homedir(),".claude.json"),_.join(F.homedir(),".claude","claude_desktop_config.json")],"claude-desktop":[_.join(F.homedir(),"Library","Application Support","Claude","claude_desktop_config.json")],codex:[_.join(F.homedir(),".codex","config.json")],windsurf:[_.join(F.homedir(),".windsurf","mcp.json")],vscode:[".vscode/mcp.json"]};import{Compile as Uf}from"typebox/compile";function z$($,f){let j=T$($),J=C.extname(j),Q=[".js",".mjs",".cjs",".ts",".mts",".cts"].includes(J)?J:".ts";return C.join(C.dirname(j),`${f}${Q}`)}function _$($){return C.basename(T$($)).startsWith("dm-args.")}function t$($=import.meta.url){let f=_$($)?"subagent-prompt-runtime":C.join("..","runs","shared","subagent-prompt-runtime");return z$($,f)}function $0($=import.meta.url){let f=_$($)?C.join("..","..","extension","fanout-child"):"fanout-child";return z$($,f)}var Rf=t$(),Df=$0();import*as f0 from"node:fs";import*as y from"node:path";var j0=[10,25,50,100,200,500,1000,2000,4000],J0=new Set(["EACCES","EBUSY","EPERM"]),C$=typeof SharedArrayBuffer<"u"?new SharedArrayBuffer(4):void 0,F$=C$?new Int32Array(C$):void 0;function Z0($){if($<=0)return;if(F$)try{Atomics.wait(F$,0,0,$);return}catch{}let f=Date.now()+$;while(Date.now()<f);}function Q0($){let f=$?.code;return typeof f==="string"&&J0.has(f)}function q0($,f,j,J,Q){for(let Z=0;;Z++)try{$.renameSync(f,j);return}catch(q){let B=J[Z];if(B===void 0||!Q0(q))throw q;Q(B)}}function B0($={}){let f=$.fs??f0,j=$.now??Date.now,J=$.pid??process.pid,Q=$.random??Math.random,q=$.retryRenameErrors??process.platform==="win32"?$.retryDelaysMs??j0:[],B=$.wait??Z0;return(O,W)=>{f.mkdirSync(y.dirname(O),{recursive:!0});let L=y.join(y.dirname(O),`.${y.basename(O)}.${J}.${j()}.${Q().toString(36).slice(2)}.tmp`);try{f.writeFileSync(L,JSON.stringify(W,null,2),"utf-8"),q0(f,L,O,q,B)}finally{f.rmSync(L,{force:!0})}}}var N=B0();var u=G.join(S,"nested-subagent-events"),O0="route.json",K0="registry.json",Q$=65536,f$=12,g=16,j$=3;function p($){return $$($)}function Y0($,f){if(!p(f))throw Error(`${$} must be a non-empty safe id token.`)}function E$($,f){Y0($,f)}function J$($,f){let j=G.resolve($),J=G.resolve(f);return J===j||J.startsWith(`${j}${G.sep}`)}function b$($){return G.dirname(G.resolve($.eventSink))}function r($){if(E$("rootRunId",$.rootRunId),E$("capabilityToken",$.capabilityToken),!J$(u,$.eventSink))throw Error("Nested event sink is outside the subagent nested event root.");if(!J$(u,$.controlInbox))throw Error("Nested control inbox is outside the subagent nested event root.");if(b$($)!==G.dirname(G.resolve($.controlInbox)))throw Error("Nested event sink and control inbox must share one route root.")}function y$($,f){if(!f.asyncDir)return;let j=G.resolve(f.asyncDir),J=G.resolve(S,"nested-subagent-runs",$,f.id),Q=G.relative(J,j);return j===J||!Q.startsWith("..")&&!G.isAbsolute(Q)?j:void 0}function K($){return typeof $==="number"&&Number.isFinite($)?$:void 0}function H($,f=512){return typeof $==="string"&&$.length>0?$.slice(0,f):void 0}function H0($){if(!$||typeof $!=="object")return;let f=$,j=K(f.input),J=K(f.output),Q=K(f.total);return j!==void 0&&J!==void 0&&Q!==void 0?{input:j,output:J,total:Q}:void 0}function W0($){if(!$||typeof $!=="object")return;let f=$,j=K(f.inputTokens),J=K(f.outputTokens),Q=K(f.costUsd);return j!==void 0&&J!==void 0&&Q!==void 0?{inputTokens:j,outputTokens:J,costUsd:Q}:void 0}function l($){if(!$||typeof $!=="object")return;let f=$,j=K(f.maxTurns),J=K(f.graceTurns),Q=K(f.turnCount),Z=f.outcome==="within-budget"||f.outcome==="wrap-up-requested"||f.outcome==="exceeded"?f.outcome:void 0;if(j===void 0||J===void 0||Q===void 0||!Z)return;return{maxTurns:j,graceTurns:J,turnCount:Q,outcome:Z,...K(f.wrapUpRequestedAtTurn)!==void 0?{wrapUpRequestedAtTurn:K(f.wrapUpRequestedAtTurn)}:{},...K(f.exceededAtTurn)!==void 0?{exceededAtTurn:K(f.exceededAtTurn)}:{}}}function G0($,f){return $==="queued"||$==="running"||$==="complete"||$==="failed"||$==="paused"?$:f}function L0($,f){if(!$||typeof $!=="object")return;let j=$,J=H(j.agent,128);if(!J)return;let Q=j.status==="pending"||j.status==="running"||j.status==="complete"||j.status==="completed"||j.status==="failed"||j.status==="paused"?j.status:"pending";return{agent:J,status:Q,...H(j.sessionFile,2048)?{sessionFile:H(j.sessionFile,2048)}:{},...j.activityState==="active_long_running"||j.activityState==="needs_attention"?{activityState:j.activityState}:{},...K(j.lastActivityAt)!==void 0?{lastActivityAt:K(j.lastActivityAt)}:{},...H(j.currentTool,128)?{currentTool:H(j.currentTool,128)}:{},...K(j.currentToolStartedAt)!==void 0?{currentToolStartedAt:K(j.currentToolStartedAt)}:{},...H(j.currentPath,2048)?{currentPath:H(j.currentPath,2048)}:{},...K(j.turnCount)!==void 0?{turnCount:K(j.turnCount)}:{},...K(j.toolCount)!==void 0?{toolCount:K(j.toolCount)}:{},...K(j.startedAt)!==void 0?{startedAt:K(j.startedAt)}:{},...K(j.endedAt)!==void 0?{endedAt:K(j.endedAt)}:{},...H(j.error,1024)?{error:H(j.error,1024)}:{},...j.timedOut===!0?{timedOut:!0}:{},...l(j.turnBudget)?{turnBudget:l(j.turnBudget)}:{},...j.turnBudgetExceeded===!0?{turnBudgetExceeded:!0}:{},...j.wrapUpRequested===!0?{wrapUpRequested:!0}:{},...f<j$&&Array.isArray(j.children)?{children:j.children.map((Z)=>i(Z,f+1)).filter((Z)=>Boolean(Z)).slice(0,g)}:{}}}function i($,f=0){if(!$||typeof $!=="object")return;let j=$;if(!p(j.id)||!p(j.parentRunId))return;let J=A$(j.path),Q=Array.isArray(j.steps)?j.steps.map((B)=>L0(B,f+1)).filter((B)=>Boolean(B)).slice(0,f$):void 0,Z=H0(j.totalTokens),q=W0(j.totalCost);return{id:j.id,parentRunId:j.parentRunId,...K(j.parentStepIndex)!==void 0?{parentStepIndex:K(j.parentStepIndex)}:{},...H(j.parentAgent,128)?{parentAgent:H(j.parentAgent,128)}:{},depth:Math.min(Math.max(0,K(j.depth)??0),j$),path:J,state:G0(j.state,"running"),...H(j.asyncDir,2048)?{asyncDir:H(j.asyncDir,2048)}:{},...K(j.pid)!==void 0&&K(j.pid)>0&&Number.isInteger(K(j.pid))?{pid:K(j.pid)}:{},...H(j.sessionId,256)?{sessionId:H(j.sessionId,256)}:{},...H(j.sessionFile,2048)?{sessionFile:H(j.sessionFile,2048)}:{},...H(j.intercomTarget,256)?{intercomTarget:H(j.intercomTarget,256)}:{},...H(j.ownerIntercomTarget,256)?{ownerIntercomTarget:H(j.ownerIntercomTarget,256)}:{},...H(j.leafIntercomTarget,256)?{leafIntercomTarget:H(j.leafIntercomTarget,256)}:{},...j.ownerState==="live"||j.ownerState==="gone"||j.ownerState==="unknown"?{ownerState:j.ownerState}:{},...H(j.controlInbox,2048)?{controlInbox:H(j.controlInbox,2048)}:{},...H(j.capabilityToken,128)?{capabilityToken:H(j.capabilityToken,128)}:{},...j.mode==="single"||j.mode==="parallel"||j.mode==="chain"?{mode:j.mode}:{},...H(j.agent,128)?{agent:H(j.agent,128)}:{},...Array.isArray(j.agents)?{agents:j.agents.map((B)=>H(B,128)).filter((B)=>Boolean(B)).slice(0,f$)}:{},...K(j.currentStep)!==void 0?{currentStep:K(j.currentStep)}:{},...K(j.chainStepCount)!==void 0?{chainStepCount:K(j.chainStepCount)}:{},...j.activityState==="active_long_running"||j.activityState==="needs_attention"?{activityState:j.activityState}:{},...K(j.lastActivityAt)!==void 0?{lastActivityAt:K(j.lastActivityAt)}:{},...H(j.currentTool,128)?{currentTool:H(j.currentTool,128)}:{},...K(j.currentToolStartedAt)!==void 0?{currentToolStartedAt:K(j.currentToolStartedAt)}:{},...H(j.currentPath,2048)?{currentPath:H(j.currentPath,2048)}:{},...K(j.turnCount)!==void 0?{turnCount:K(j.turnCount)}:{},...K(j.toolCount)!==void 0?{toolCount:K(j.toolCount)}:{},...Z?{totalTokens:Z}:{},...q?{totalCost:q}:{},...K(j.startedAt)!==void 0?{startedAt:K(j.startedAt)}:{},...K(j.endedAt)!==void 0?{endedAt:K(j.endedAt)}:{},...K(j.lastUpdate)!==void 0?{lastUpdate:K(j.lastUpdate)}:{},...K(j.timeoutMs)!==void 0?{timeoutMs:K(j.timeoutMs)}:{},...K(j.deadlineAt)!==void 0?{deadlineAt:K(j.deadlineAt)}:{},...j.timedOut===!0?{timedOut:!0}:{},...l(j.turnBudget)?{turnBudget:l(j.turnBudget)}:{},...j.turnBudgetExceeded===!0?{turnBudgetExceeded:!0}:{},...j.wrapUpRequested===!0?{wrapUpRequested:!0}:{},...H(j.error,1024)?{error:H(j.error,1024)}:{},...Q&&Q.length>0?{steps:Q}:{},...f<j$&&Array.isArray(j.children)?{children:j.children.map((B)=>i(B,f+1)).filter((B)=>Boolean(B)).slice(0,g)}:{}}}function Z$($,f){if(Buffer.byteLength($,"utf-8")>Q$)return;let j;try{j=JSON.parse($)}catch{return}if(!j||typeof j!=="object")return;let J=j;if(J.type!=="subagent.nested.started"&&J.type!=="subagent.nested.updated"&&J.type!=="subagent.nested.completed")return;if(J.rootRunId!==f.rootRunId||J.capabilityToken!==f.capabilityToken)return;if(!p(J.parentRunId))return;let Q=K(J.ts);if(Q===void 0)return;let Z=i(J.child);if(!Z||Z.id===f.rootRunId)return;let q={...Z,controlInbox:f.controlInbox,capabilityToken:f.capabilityToken,ownerState:Z.ownerState??"unknown"};return{type:J.type,ts:Q,rootRunId:f.rootRunId,parentRunId:J.parentRunId,...K(J.parentStepIndex)!==void 0?{parentStepIndex:K(J.parentStepIndex)}:{},capabilityToken:f.capabilityToken,child:q}}function V0($,f){if(!$.includes(`
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
${B}`:q,L=(($.steps?.length)?$.steps:[{agent:"subagent",status:"running"}]).map((Y)=>Y.status==="running"||Y.status==="pending"?{...Y,status:"failed",activityState:void 0,endedAt:Y.endedAt??j,durationMs:Y.startedAt!==void 0&&Y.durationMs===void 0?Math.max(0,j-Y.startedAt):Y.durationMs,exitCode:Y.exitCode??1,error:Y.error??O}:Y),X={...$,state:"failed",activityState:void 0,lastUpdate:j,endedAt:j,steps:L},V=L[$.currentStep??0]?.agent??L[0]?.agent??"subagent";return{status:X,message:O,result:{id:Q,agent:V,mode:$.mode,success:!1,state:"failed",summary:O,results:L.map((Y)=>({agent:Y.agent,output:Y.status==="complete"||Y.status==="completed"?"":O,error:Y.status==="complete"||Y.status==="completed"?void 0:Y.error??O,success:Y.status==="complete"||Y.status==="completed",model:Y.model,attemptedModels:Y.attemptedModels,modelAttempts:Y.modelAttempts,sessionFile:Y.sessionFile})),exitCode:1,timestamp:j,durationMs:Math.max(0,j-$.startedAt),asyncDir:f,sessionId:$.sessionId,sessionFile:$.sessionFile}}}function k$($,f,j,J,Q){let Z=N0(f,$,J,Q);return N(j,Z.result),N(A.join($,"status.json"),Z.status),E0(A.join($,"events.jsonl"),{type:"subagent.run.repaired_stale",ts:J,runId:Z.status.runId,pid:f.pid,resultPath:j,message:Z.message}),{status:Z.status,repaired:!0,resultPath:j,message:Z.message}}function v$($){return $==="complete"||$==="failed"||$==="paused"}function*O$($){for(let f of $??[])yield f,yield*O$(f.children),yield*O$(f.steps?.flatMap((j)=>j.children??[]))}function c$($,f={}){let j=a($);for(let J of O$(j.children)){if(J.state!=="running"&&J.state!=="queued")continue;let Q=y$($.rootRunId,J);if(!Q)continue;let Z=K$(Q,{...f,resultsDir:A.join(f.resultsDir??h,"nested",$.rootRunId)}),q=Z.status;if(!q)continue;if(!Z.repaired&&!v$(q.state))continue;let B=f.now?.()??Date.now();N$($,{type:v$(q.state)?"subagent.nested.completed":"subagent.nested.updated",ts:B,parentRunId:J.parentRunId,parentStepIndex:J.parentStepIndex,child:D$(q,Q,{id:J.id,parentRunId:J.parentRunId,parentStepIndex:J.parentStepIndex,depth:J.depth,path:J.path,mode:J.mode,ts:B})})}}function R0($,f=process.kill){try{return f($,0),"alive"}catch(j){let J=typeof j==="object"&&j!==null&&"code"in j?j.code:void 0;if(J==="ESRCH")return"dead";if(J==="EPERM")return"unknown";return"unknown"}}function K$($,f={}){let j=f.now?.()??Date.now(),J=S0($),Q=!J&&f.startedRun?I0($,f.startedRun,j):void 0,Z=J??Q;if(!Z)return{status:null,repaired:!1};let q=Z.runId||A.basename($),B=A.join(f.resultsDir??h,`${q}.json`);if(U.existsSync(B)){let W=Z.state==="running"||Z.state==="queued"?x0(Z,B,j):void 0;if(W)return N(A.join($,"status.json"),W),{status:W,repaired:!0,resultPath:B,message:"Existing async result file was used to repair stale running status."};return{status:Z,repaired:!1,resultPath:B}}if(Z.state!=="running"||typeof Z.pid!=="number")return{status:J??null,repaired:!1,resultPath:B};if(!J){let W=f.startedRun?.startedAt??Z.startedAt;if(j-W<(f.missingStatusGraceMs??1000))return{status:null,repaired:!1,resultPath:B}}if(R0(Z.pid,f.kill)!=="dead"){let W=f.staleAlivePidMs??86400000,L=Z.lastUpdate??Z.startedAt;if(j-L<=W)return{status:J??null,repaired:!1,resultPath:B};let X=`Async runner process ${Z.pid} still has a live PID, but status has not updated for ${j-L}ms. Marked run failed by stale-run reconciliation because PID ownership cannot be verified.`;return k$($,Z,B,j,X)}return k$($,Z,B,j)}function v($){return $ instanceof Error?$.message:String($)}function Y$($){return typeof $==="object"&&$!==null&&"code"in $&&$.code==="ENOENT"}function D0($,f){let j=T.join($,f);try{return m.statSync(j).isDirectory()}catch(J){if(Y$(J))return!1;throw Error(`Failed to inspect async run path '${j}': ${v(J)}`,{cause:J instanceof Error?J:void 0})}}function P0($){if(!$)return;try{return m.statSync($).mtimeMs}catch(f){if(Y$(f))return;throw Error(`Failed to inspect async output file '${$}': ${v(f)}`,{cause:f instanceof Error?f:void 0})}}function w0($,f){if(f.state!=="running")return{activityState:f.activityState,lastActivityAt:f.lastActivityAt};let j=f.outputFile?T.isAbsolute(f.outputFile)?f.outputFile:T.join($,f.outputFile):void 0,J=typeof f.currentStep==="number"?f.steps?.[f.currentStep]:void 0;return{activityState:f.activityState,lastActivityAt:f.lastActivityAt??P0(j)??J?.lastActivityAt??J?.startedAt??f.startedAt}}function g0($,f,j=[],J){if(f.sessionId!==void 0&&typeof f.sessionId!=="string")throw Error(`Invalid async status '${T.join($,"status.json")}': sessionId must be a string.`);let{activityState:Q,lastActivityAt:Z}=w0($,f),q=f.steps??[],B=f.chainStepCount??q.length,O=k(f.parallelGroups,q.length,B),W=[];if(j.length===0&&J)try{W=a(J)?.children??[]}catch(X){j.push(`Nested status unavailable: ${v(X)}`)}let L=q.map((X,V)=>{let{activityState:Y,lastActivityAt:E}=X;return{index:V,agent:X.agent,...X.label?{label:X.label}:{},...X.phase?{phase:X.phase}:{},...X.outputName?{outputName:X.outputName}:{},...X.structured?{structured:X.structured}:{},status:X.status,...Y?{activityState:Y}:{},...E?{lastActivityAt:E}:{},...X.currentTool?{currentTool:X.currentTool}:{},...X.currentToolArgs?{currentToolArgs:X.currentToolArgs}:{},...X.currentToolStartedAt?{currentToolStartedAt:X.currentToolStartedAt}:{},...X.currentPath?{currentPath:X.currentPath}:{},...X.recentTools?{recentTools:X.recentTools.map((R)=>({...R}))}:{},...X.recentOutput?{recentOutput:[...X.recentOutput]}:{},...X.turnCount!==void 0?{turnCount:X.turnCount}:{},...X.toolCount!==void 0?{toolCount:X.toolCount}:{},...X.steerCount!==void 0?{steerCount:X.steerCount}:{},...X.lastSteerAt!==void 0?{lastSteerAt:X.lastSteerAt}:{},...X.durationMs!==void 0?{durationMs:X.durationMs}:{},...X.tokens?{tokens:X.tokens}:{},...X.totalCost?{totalCost:X.totalCost}:{},...X.skills?{skills:X.skills}:{},...X.model?{model:X.model}:{},...X.thinking?{thinking:X.thinking}:{},...X.attemptedModels?{attemptedModels:X.attemptedModels}:{},...X.error?{error:X.error}:{},...X.timedOut!==void 0?{timedOut:X.timedOut}:{},...X.turnBudget?{turnBudget:X.turnBudget}:{},...X.turnBudgetExceeded!==void 0?{turnBudgetExceeded:X.turnBudgetExceeded}:{},...X.wrapUpRequested!==void 0?{wrapUpRequested:X.wrapUpRequested}:{},...X.children?.length?{children:X.children}:{}}});return R$(f.runId||T.basename($),L,W),{id:f.runId||T.basename($),asyncDir:$,...f.sessionId?{sessionId:f.sessionId}:{},state:f.state,...f.error?{error:f.error}:{},activityState:Q,lastActivityAt:Z,currentTool:f.currentTool,currentToolStartedAt:f.currentToolStartedAt,currentPath:f.currentPath,turnCount:f.turnCount,toolCount:f.toolCount,steerCount:f.steerCount,lastSteerAt:f.lastSteerAt,mode:f.mode,cwd:f.cwd,startedAt:f.startedAt,lastUpdate:f.lastUpdate,endedAt:f.endedAt,...f.timeoutMs!==void 0?{timeoutMs:f.timeoutMs}:{},...f.deadlineAt!==void 0?{deadlineAt:f.deadlineAt}:{},...f.timedOut!==void 0?{timedOut:f.timedOut}:{},...f.turnBudget?{turnBudget:f.turnBudget}:{},...f.turnBudgetExceeded!==void 0?{turnBudgetExceeded:f.turnBudgetExceeded}:{},...f.wrapUpRequested!==void 0?{wrapUpRequested:f.wrapUpRequested}:{},currentStep:f.currentStep,...f.chainStepCount!==void 0?{chainStepCount:f.chainStepCount}:{},...f.pendingAppends!==void 0?{pendingAppends:f.pendingAppends}:{},...O.length?{parallelGroups:O}:{},steps:L,...W.length?{nestedChildren:W}:{},...j.length?{nestedWarnings:j}:{},...f.sessionDir?{sessionDir:f.sessionDir}:{},...f.outputFile?{outputFile:f.outputFile}:{},...f.totalTokens?{totalTokens:f.totalTokens}:{},...f.totalCost?{totalCost:f.totalCost}:{},...f.sessionFile?{sessionFile:f.sessionFile}:{}}}function k0($){let f=(j)=>{switch(j){case"running":return 0;case"queued":return 1;case"failed":return 2;case"paused":return 2;case"complete":return 3}};return[...$].sort((j,J)=>{let Q=f(j.state)-f(J.state);if(Q!==0)return Q;let Z=j.lastUpdate??j.endedAt??j.startedAt;return(J.lastUpdate??J.endedAt??J.startedAt)-Z})}function Wj($,f={}){let j;try{j=m.readdirSync($).filter((O)=>D0($,O))}catch(O){if(Y$(O))return[];throw Error(`Failed to list async runs in '${$}': ${v(O)}`,{cause:O instanceof Error?O:void 0})}let J=f.states?new Set(f.states):void 0,Q=[],Z,q=(O)=>{if(!Z)Z=I$();return Z.get(O)};for(let O of j){let W=T.join($,O),X=(f.reconcile===!1?void 0:K$(W,{resultsDir:f.resultsDir,kill:f.kill,now:f.now}))?.status??W$(W);if(!X)continue;if(J&&!J.has(X.state))continue;if(f.sessionId&&X.sessionId!==f.sessionId)continue;let V=[],Y;try{if(Y=q(X.runId||T.basename(W)),Y)c$(Y,{resultsDir:f.resultsDir,kill:f.kill,now:f.now})}catch(R){V.push(`Nested status unavailable: ${v(R)}`)}let E=g0(W,X,V,Y);Q.push(E)}let B=k0(Q);return f.limit!==void 0?B.slice(0,f.limit):B}function h$($){let f=[];if($.currentTool&&$.currentToolStartedAt!==void 0)f.push(`tool ${$.currentTool} ${w(Math.max(0,Date.now()-$.currentToolStartedAt))}`);else if($.currentTool)f.push(`tool ${$.currentTool}`);if($.currentPath)f.push(b($.currentPath));if($.turnCount!==void 0)f.push(`${$.turnCount} turns`);if($.turnBudgetExceeded&&$.turnBudget)f.push(`turn budget exceeded ${$.turnBudget.turnCount}/${$.turnBudget.maxTurns}+${$.turnBudget.graceTurns}`);else if($.wrapUpRequested&&$.turnBudget)f.push(`wrap-up requested ${$.turnBudget.turnCount}/${$.turnBudget.maxTurns}`);else if($.turnBudget)f.push(`turn budget ${$.turnBudget.turnCount}/${$.turnBudget.maxTurns}+${$.turnBudget.graceTurns}`);if($.toolCount!==void 0)f.push(`${$.toolCount} tools`);if($.steerCount!==void 0)f.push(`${$.steerCount} steers`);if(typeof $.lastSteerAt==="number"&&Number.isFinite($.lastSteerAt))f.push(`last steer ${new Date($.lastSteerAt).toISOString()}`);let j=n($.lastActivityAt,$.activityState);return j||f.length?[j,...f].filter(Boolean).join(" | "):void 0}function v0($){let f=$.label?`${$.label} (${$.agent})`:$.agent,j=$.phase?`[${$.phase}] `:"",J=[`${$.index+1}. ${j}${f}`,$.status],Q=h$($);if(Q)J.push(Q);let Z=L$($.model,$.thinking);if(Z)J.push(Z);if($.durationMs!==void 0)J.push(w($.durationMs));if($.tokens)J.push(`${d($.tokens.total)} tok`);return J.join(" | ")}function m0($){if(!$.outputFile)return;return T.isAbsolute($.outputFile)?$.outputFile:T.join($.asyncDir,$.outputFile)}function c0($){let f=$.steps.length||1,j=$.chainStepCount??f,J=k($.parallelGroups,$.steps.length,j),Q=$.currentStep!==void 0?J.find((Z)=>$.currentStep>=Z.start&&$.currentStep<Z.start+Z.count):void 0;if(Q){let Z=$.steps.slice(Q.start,Q.start+Q.count),q=t(Z,Q.count,{showRunning:$.state==="running"});if($.mode==="parallel")return q;return`step ${Q.stepIndex+1}/${j} · parallel group: ${q}`}if($.mode==="parallel")return t($.steps,f,{showRunning:$.state==="running"});if($.mode==="chain"&&$.currentStep!==void 0&&J.length>0)return`step ${g$($.currentStep,j,J)+1}/${j}`;return $.currentStep!==void 0?`step ${$.currentStep+1}/${f}`:`steps ${f}`}function h0($){let f=c0($),j=$.cwd?b($.cwd):b($.asyncDir),J=h$($),Q=$.pendingAppends?` | ${$.pendingAppends} pending append${$.pendingAppends===1?"":"s"}`:"";return`${$.id} | ${$.state}${J?` | ${J}`:""} | ${$.mode} | ${f}${Q} | ${j}`}function Gj($,f="Active async runs"){if($.length===0)return`No ${f.toLowerCase()}.`;let j=[`${f}: ${$.length}`,""];for(let J of $){j.push(`- ${h0(J)}`);for(let B of J.steps)j.push(` ${v0(B)}`),j.push(...B$(B.children,{indent:" ",maxLines:12}));let Q=new Set(J.steps.flatMap((B)=>B.children?.map((O)=>O.id)??[])),Z=J.nestedChildren?.filter((B)=>!Q.has(B.id))??[];if(j.push(...B$(Z,{indent:" ",maxLines:12})),J.error)j.push(` Error: ${J.error}`);for(let B of J.nestedWarnings??[])j.push(` Warning: ${B}`);let q=m0(J);if(q)j.push(` output: ${b(q)}`);if(J.sessionFile)j.push(` session: ${b(J.sessionFile)}`);j.push("")}return j.join(`
|
|
12
|
-
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { formatDuration, formatModelThinking, formatTokens, shortenPath } from "../../shared/formatters.js";
|
|
4
|
+
import { formatActivityLabel, formatParallelOutcome } from "../../shared/status-format.js";
|
|
5
|
+
import { readStatus } from "../../shared/utils.js";
|
|
6
|
+
import { attachRootChildrenToSteps, buildNestedRouteIndex, projectNestedEvents } from "../shared/nested-events.js";
|
|
7
|
+
import { formatNestedRunStatusLines } from "../shared/nested-render.js";
|
|
8
|
+
import { flatToLogicalStepIndex, normalizeParallelGroups } from "./parallel-groups.js";
|
|
9
|
+
import { reconcileAsyncRun, reconcileNestedAsyncDescendants } from "./stale-run-reconciler.js";
|
|
10
|
+
function getErrorMessage(error) {
|
|
11
|
+
return error instanceof Error ? error.message : String(error);
|
|
12
|
+
}
|
|
13
|
+
function isNotFoundError(error) {
|
|
14
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
15
|
+
}
|
|
16
|
+
function isAsyncRunDir(root, entry) {
|
|
17
|
+
const entryPath = path.join(root, entry);
|
|
18
|
+
try {
|
|
19
|
+
return fs.statSync(entryPath).isDirectory();
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (isNotFoundError(error))
|
|
22
|
+
return false;
|
|
23
|
+
throw new Error(`Failed to inspect async run path '${entryPath}': ${getErrorMessage(error)}`, {
|
|
24
|
+
cause: error instanceof Error ? error : undefined
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function outputFileMtime(outputFile) {
|
|
29
|
+
if (!outputFile)
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
return fs.statSync(outputFile).mtimeMs;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (isNotFoundError(error))
|
|
35
|
+
return;
|
|
36
|
+
throw new Error(`Failed to inspect async output file '${outputFile}': ${getErrorMessage(error)}`, {
|
|
37
|
+
cause: error instanceof Error ? error : undefined
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function deriveAsyncActivityState(asyncDir, status) {
|
|
42
|
+
if (status.state !== "running")
|
|
43
|
+
return { activityState: status.activityState, lastActivityAt: status.lastActivityAt };
|
|
44
|
+
const outputPath = status.outputFile ? path.isAbsolute(status.outputFile) ? status.outputFile : path.join(asyncDir, status.outputFile) : undefined;
|
|
45
|
+
const currentStep = typeof status.currentStep === "number" ? status.steps?.[status.currentStep] : undefined;
|
|
46
|
+
return {
|
|
47
|
+
activityState: status.activityState,
|
|
48
|
+
lastActivityAt: status.lastActivityAt ?? outputFileMtime(outputPath) ?? currentStep?.lastActivityAt ?? currentStep?.startedAt ?? status.startedAt
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
|
|
52
|
+
if (status.sessionId !== undefined && typeof status.sessionId !== "string") {
|
|
53
|
+
throw new Error(`Invalid async status '${path.join(asyncDir, "status.json")}': sessionId must be a string.`);
|
|
54
|
+
}
|
|
55
|
+
const { activityState, lastActivityAt } = deriveAsyncActivityState(asyncDir, status);
|
|
56
|
+
const steps = status.steps ?? [];
|
|
57
|
+
const chainStepCount = status.chainStepCount ?? steps.length;
|
|
58
|
+
const parallelGroups = normalizeParallelGroups(status.parallelGroups, steps.length, chainStepCount);
|
|
59
|
+
let nestedChildren = [];
|
|
60
|
+
if (nestedWarnings.length === 0 && nestedRoute) {
|
|
61
|
+
try {
|
|
62
|
+
nestedChildren = projectNestedEvents(nestedRoute)?.children ?? [];
|
|
63
|
+
} catch (error) {
|
|
64
|
+
nestedWarnings.push(`Nested status unavailable: ${getErrorMessage(error)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const summarizedSteps = steps.map((step, index) => {
|
|
68
|
+
const stepActivityState = step.activityState;
|
|
69
|
+
const stepLastActivityAt = step.lastActivityAt;
|
|
70
|
+
return {
|
|
71
|
+
index,
|
|
72
|
+
agent: step.agent,
|
|
73
|
+
...step.label ? { label: step.label } : {},
|
|
74
|
+
...step.phase ? { phase: step.phase } : {},
|
|
75
|
+
...step.outputName ? { outputName: step.outputName } : {},
|
|
76
|
+
...step.structured ? { structured: step.structured } : {},
|
|
77
|
+
status: step.status,
|
|
78
|
+
...stepActivityState ? { activityState: stepActivityState } : {},
|
|
79
|
+
...stepLastActivityAt ? { lastActivityAt: stepLastActivityAt } : {},
|
|
80
|
+
...step.currentTool ? { currentTool: step.currentTool } : {},
|
|
81
|
+
...step.currentToolArgs ? { currentToolArgs: step.currentToolArgs } : {},
|
|
82
|
+
...step.currentToolStartedAt ? { currentToolStartedAt: step.currentToolStartedAt } : {},
|
|
83
|
+
...step.currentPath ? { currentPath: step.currentPath } : {},
|
|
84
|
+
...step.recentTools ? { recentTools: step.recentTools.map((tool) => ({ ...tool })) } : {},
|
|
85
|
+
...step.recentOutput ? { recentOutput: [...step.recentOutput] } : {},
|
|
86
|
+
...step.turnCount !== undefined ? { turnCount: step.turnCount } : {},
|
|
87
|
+
...step.toolCount !== undefined ? { toolCount: step.toolCount } : {},
|
|
88
|
+
...step.steerCount !== undefined ? { steerCount: step.steerCount } : {},
|
|
89
|
+
...step.lastSteerAt !== undefined ? { lastSteerAt: step.lastSteerAt } : {},
|
|
90
|
+
...step.durationMs !== undefined ? { durationMs: step.durationMs } : {},
|
|
91
|
+
...step.tokens ? { tokens: step.tokens } : {},
|
|
92
|
+
...step.totalCost ? { totalCost: step.totalCost } : {},
|
|
93
|
+
...step.skills ? { skills: step.skills } : {},
|
|
94
|
+
...step.model ? { model: step.model } : {},
|
|
95
|
+
...step.thinking ? { thinking: step.thinking } : {},
|
|
96
|
+
...step.attemptedModels ? { attemptedModels: step.attemptedModels } : {},
|
|
97
|
+
...step.error ? { error: step.error } : {},
|
|
98
|
+
...step.timedOut !== undefined ? { timedOut: step.timedOut } : {},
|
|
99
|
+
...step.turnBudget ? { turnBudget: step.turnBudget } : {},
|
|
100
|
+
...step.turnBudgetExceeded !== undefined ? { turnBudgetExceeded: step.turnBudgetExceeded } : {},
|
|
101
|
+
...step.wrapUpRequested !== undefined ? { wrapUpRequested: step.wrapUpRequested } : {},
|
|
102
|
+
...step.children?.length ? { children: step.children } : {}
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
attachRootChildrenToSteps(status.runId || path.basename(asyncDir), summarizedSteps, nestedChildren);
|
|
106
|
+
return {
|
|
107
|
+
id: status.runId || path.basename(asyncDir),
|
|
108
|
+
asyncDir,
|
|
109
|
+
...status.sessionId ? { sessionId: status.sessionId } : {},
|
|
110
|
+
state: status.state,
|
|
111
|
+
...status.error ? { error: status.error } : {},
|
|
112
|
+
activityState,
|
|
113
|
+
lastActivityAt,
|
|
114
|
+
currentTool: status.currentTool,
|
|
115
|
+
currentToolStartedAt: status.currentToolStartedAt,
|
|
116
|
+
currentPath: status.currentPath,
|
|
117
|
+
turnCount: status.turnCount,
|
|
118
|
+
toolCount: status.toolCount,
|
|
119
|
+
steerCount: status.steerCount,
|
|
120
|
+
lastSteerAt: status.lastSteerAt,
|
|
121
|
+
mode: status.mode,
|
|
122
|
+
cwd: status.cwd,
|
|
123
|
+
startedAt: status.startedAt,
|
|
124
|
+
lastUpdate: status.lastUpdate,
|
|
125
|
+
endedAt: status.endedAt,
|
|
126
|
+
...status.timeoutMs !== undefined ? { timeoutMs: status.timeoutMs } : {},
|
|
127
|
+
...status.deadlineAt !== undefined ? { deadlineAt: status.deadlineAt } : {},
|
|
128
|
+
...status.timedOut !== undefined ? { timedOut: status.timedOut } : {},
|
|
129
|
+
...status.turnBudget ? { turnBudget: status.turnBudget } : {},
|
|
130
|
+
...status.turnBudgetExceeded !== undefined ? { turnBudgetExceeded: status.turnBudgetExceeded } : {},
|
|
131
|
+
...status.wrapUpRequested !== undefined ? { wrapUpRequested: status.wrapUpRequested } : {},
|
|
132
|
+
currentStep: status.currentStep,
|
|
133
|
+
...status.chainStepCount !== undefined ? { chainStepCount: status.chainStepCount } : {},
|
|
134
|
+
...status.pendingAppends !== undefined ? { pendingAppends: status.pendingAppends } : {},
|
|
135
|
+
...parallelGroups.length ? { parallelGroups } : {},
|
|
136
|
+
steps: summarizedSteps,
|
|
137
|
+
...nestedChildren.length ? { nestedChildren } : {},
|
|
138
|
+
...nestedWarnings.length ? { nestedWarnings } : {},
|
|
139
|
+
...status.sessionDir ? { sessionDir: status.sessionDir } : {},
|
|
140
|
+
...status.outputFile ? { outputFile: status.outputFile } : {},
|
|
141
|
+
...status.totalTokens ? { totalTokens: status.totalTokens } : {},
|
|
142
|
+
...status.totalCost ? { totalCost: status.totalCost } : {},
|
|
143
|
+
...status.sessionFile ? { sessionFile: status.sessionFile } : {}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function sortRuns(runs) {
|
|
147
|
+
const rank = (state) => {
|
|
148
|
+
switch (state) {
|
|
149
|
+
case "running":
|
|
150
|
+
return 0;
|
|
151
|
+
case "queued":
|
|
152
|
+
return 1;
|
|
153
|
+
case "failed":
|
|
154
|
+
return 2;
|
|
155
|
+
case "paused":
|
|
156
|
+
return 2;
|
|
157
|
+
case "complete":
|
|
158
|
+
return 3;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
return [...runs].sort((a, b) => {
|
|
162
|
+
const byState = rank(a.state) - rank(b.state);
|
|
163
|
+
if (byState !== 0)
|
|
164
|
+
return byState;
|
|
165
|
+
const aTime = a.lastUpdate ?? a.endedAt ?? a.startedAt;
|
|
166
|
+
const bTime = b.lastUpdate ?? b.endedAt ?? b.startedAt;
|
|
167
|
+
return bTime - aTime;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
export function listAsyncRuns(asyncDirRoot, options = {}) {
|
|
171
|
+
let entries;
|
|
172
|
+
try {
|
|
173
|
+
entries = fs.readdirSync(asyncDirRoot).filter((entry) => isAsyncRunDir(asyncDirRoot, entry));
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (isNotFoundError(error))
|
|
176
|
+
return [];
|
|
177
|
+
throw new Error(`Failed to list async runs in '${asyncDirRoot}': ${getErrorMessage(error)}`, {
|
|
178
|
+
cause: error instanceof Error ? error : undefined
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
const allowedStates = options.states ? new Set(options.states) : undefined;
|
|
182
|
+
const runs = [];
|
|
183
|
+
let nestedRouteIndex;
|
|
184
|
+
const resolveNestedRoute = (rootRunId) => {
|
|
185
|
+
if (!nestedRouteIndex)
|
|
186
|
+
nestedRouteIndex = buildNestedRouteIndex();
|
|
187
|
+
return nestedRouteIndex.get(rootRunId);
|
|
188
|
+
};
|
|
189
|
+
for (const entry of entries) {
|
|
190
|
+
const asyncDir = path.join(asyncDirRoot, entry);
|
|
191
|
+
const reconciliation = options.reconcile === false ? undefined : reconcileAsyncRun(asyncDir, { resultsDir: options.resultsDir, kill: options.kill, now: options.now });
|
|
192
|
+
const status = reconciliation?.status ?? readStatus(asyncDir);
|
|
193
|
+
if (!status)
|
|
194
|
+
continue;
|
|
195
|
+
if (allowedStates && !allowedStates.has(status.state))
|
|
196
|
+
continue;
|
|
197
|
+
if (options.sessionId && status.sessionId !== options.sessionId)
|
|
198
|
+
continue;
|
|
199
|
+
const nestedWarnings = [];
|
|
200
|
+
let nestedRoute;
|
|
201
|
+
try {
|
|
202
|
+
nestedRoute = resolveNestedRoute(status.runId || path.basename(asyncDir));
|
|
203
|
+
if (nestedRoute)
|
|
204
|
+
reconcileNestedAsyncDescendants(nestedRoute, { resultsDir: options.resultsDir, kill: options.kill, now: options.now });
|
|
205
|
+
} catch (error) {
|
|
206
|
+
nestedWarnings.push(`Nested status unavailable: ${getErrorMessage(error)}`);
|
|
207
|
+
}
|
|
208
|
+
const summary = statusToSummary(asyncDir, status, nestedWarnings, nestedRoute);
|
|
209
|
+
runs.push(summary);
|
|
210
|
+
}
|
|
211
|
+
const sorted = sortRuns(runs);
|
|
212
|
+
return options.limit !== undefined ? sorted.slice(0, options.limit) : sorted;
|
|
213
|
+
}
|
|
214
|
+
function formatActivityFacts(input) {
|
|
215
|
+
const facts = [];
|
|
216
|
+
if (input.currentTool && input.currentToolStartedAt !== undefined)
|
|
217
|
+
facts.push(`tool ${input.currentTool} ${formatDuration(Math.max(0, Date.now() - input.currentToolStartedAt))}`);
|
|
218
|
+
else if (input.currentTool)
|
|
219
|
+
facts.push(`tool ${input.currentTool}`);
|
|
220
|
+
if (input.currentPath)
|
|
221
|
+
facts.push(shortenPath(input.currentPath));
|
|
222
|
+
if (input.turnCount !== undefined)
|
|
223
|
+
facts.push(`${input.turnCount} turns`);
|
|
224
|
+
if (input.turnBudgetExceeded && input.turnBudget)
|
|
225
|
+
facts.push(`turn budget exceeded ${input.turnBudget.turnCount}/${input.turnBudget.maxTurns}+${input.turnBudget.graceTurns}`);
|
|
226
|
+
else if (input.wrapUpRequested && input.turnBudget)
|
|
227
|
+
facts.push(`wrap-up requested ${input.turnBudget.turnCount}/${input.turnBudget.maxTurns}`);
|
|
228
|
+
else if (input.turnBudget)
|
|
229
|
+
facts.push(`turn budget ${input.turnBudget.turnCount}/${input.turnBudget.maxTurns}+${input.turnBudget.graceTurns}`);
|
|
230
|
+
if (input.toolCount !== undefined)
|
|
231
|
+
facts.push(`${input.toolCount} tools`);
|
|
232
|
+
if (input.steerCount !== undefined)
|
|
233
|
+
facts.push(`${input.steerCount} steers`);
|
|
234
|
+
if (typeof input.lastSteerAt === "number" && Number.isFinite(input.lastSteerAt))
|
|
235
|
+
facts.push(`last steer ${new Date(input.lastSteerAt).toISOString()}`);
|
|
236
|
+
const activity = formatActivityLabel(input.lastActivityAt, input.activityState);
|
|
237
|
+
return activity || facts.length ? [activity, ...facts].filter(Boolean).join(" | ") : undefined;
|
|
238
|
+
}
|
|
239
|
+
function formatStepLine(step) {
|
|
240
|
+
const display = step.label ? `${step.label} (${step.agent})` : step.agent;
|
|
241
|
+
const phase = step.phase ? `[${step.phase}] ` : "";
|
|
242
|
+
const parts = [`${step.index + 1}. ${phase}${display}`, step.status];
|
|
243
|
+
const activity = formatActivityFacts(step);
|
|
244
|
+
if (activity)
|
|
245
|
+
parts.push(activity);
|
|
246
|
+
const modelThinking = formatModelThinking(step.model, step.thinking);
|
|
247
|
+
if (modelThinking)
|
|
248
|
+
parts.push(modelThinking);
|
|
249
|
+
if (step.durationMs !== undefined)
|
|
250
|
+
parts.push(formatDuration(step.durationMs));
|
|
251
|
+
if (step.tokens)
|
|
252
|
+
parts.push(`${formatTokens(step.tokens.total)} tok`);
|
|
253
|
+
return parts.join(" | ");
|
|
254
|
+
}
|
|
255
|
+
export function formatAsyncRunOutputPath(run) {
|
|
256
|
+
if (!run.outputFile)
|
|
257
|
+
return;
|
|
258
|
+
return path.isAbsolute(run.outputFile) ? run.outputFile : path.join(run.asyncDir, run.outputFile);
|
|
259
|
+
}
|
|
260
|
+
export function formatAsyncRunProgressLabel(run) {
|
|
261
|
+
const stepCount = run.steps.length || 1;
|
|
262
|
+
const chainStepCount = run.chainStepCount ?? stepCount;
|
|
263
|
+
const groups = normalizeParallelGroups(run.parallelGroups, run.steps.length, chainStepCount);
|
|
264
|
+
const activeGroup = run.currentStep !== undefined ? groups.find((group) => run.currentStep >= group.start && run.currentStep < group.start + group.count) : undefined;
|
|
265
|
+
if (activeGroup) {
|
|
266
|
+
const groupSteps = run.steps.slice(activeGroup.start, activeGroup.start + activeGroup.count);
|
|
267
|
+
const groupLabel = formatParallelOutcome(groupSteps, activeGroup.count, { showRunning: run.state === "running" });
|
|
268
|
+
if (run.mode === "parallel")
|
|
269
|
+
return groupLabel;
|
|
270
|
+
return `step ${activeGroup.stepIndex + 1}/${chainStepCount} · parallel group: ${groupLabel}`;
|
|
271
|
+
}
|
|
272
|
+
if (run.mode === "parallel")
|
|
273
|
+
return formatParallelOutcome(run.steps, stepCount, { showRunning: run.state === "running" });
|
|
274
|
+
if (run.mode === "chain" && run.currentStep !== undefined && groups.length > 0) {
|
|
275
|
+
const logicalStep = flatToLogicalStepIndex(run.currentStep, chainStepCount, groups);
|
|
276
|
+
return `step ${logicalStep + 1}/${chainStepCount}`;
|
|
277
|
+
}
|
|
278
|
+
return run.currentStep !== undefined ? `step ${run.currentStep + 1}/${stepCount}` : `steps ${stepCount}`;
|
|
279
|
+
}
|
|
280
|
+
function formatRunHeader(run) {
|
|
281
|
+
const stepLabel = formatAsyncRunProgressLabel(run);
|
|
282
|
+
const cwd = run.cwd ? shortenPath(run.cwd) : shortenPath(run.asyncDir);
|
|
283
|
+
const activity = formatActivityFacts(run);
|
|
284
|
+
const pending = run.pendingAppends ? ` | ${run.pendingAppends} pending append${run.pendingAppends === 1 ? "" : "s"}` : "";
|
|
285
|
+
return `${run.id} | ${run.state}${activity ? ` | ${activity}` : ""} | ${run.mode} | ${stepLabel}${pending} | ${cwd}`;
|
|
286
|
+
}
|
|
287
|
+
export function formatAsyncRunList(runs, heading = "Active async runs") {
|
|
288
|
+
if (runs.length === 0)
|
|
289
|
+
return `No ${heading.toLowerCase()}.`;
|
|
290
|
+
const lines = [`${heading}: ${runs.length}`, ""];
|
|
291
|
+
for (const run of runs) {
|
|
292
|
+
lines.push(`- ${formatRunHeader(run)}`);
|
|
293
|
+
for (const step of run.steps) {
|
|
294
|
+
lines.push(` ${formatStepLine(step)}`);
|
|
295
|
+
lines.push(...formatNestedRunStatusLines(step.children, { indent: " ", maxLines: 12 }));
|
|
296
|
+
}
|
|
297
|
+
const attached = new Set(run.steps.flatMap((step) => step.children?.map((child) => child.id) ?? []));
|
|
298
|
+
const unattached = run.nestedChildren?.filter((child) => !attached.has(child.id)) ?? [];
|
|
299
|
+
lines.push(...formatNestedRunStatusLines(unattached, { indent: " ", maxLines: 12 }));
|
|
300
|
+
if (run.error)
|
|
301
|
+
lines.push(` Error: ${run.error}`);
|
|
302
|
+
for (const warning of run.nestedWarnings ?? [])
|
|
303
|
+
lines.push(` Warning: ${warning}`);
|
|
304
|
+
const outputPath = formatAsyncRunOutputPath(run);
|
|
305
|
+
if (outputPath)
|
|
306
|
+
lines.push(` output: ${shortenPath(outputPath)}`);
|
|
307
|
+
if (run.sessionFile)
|
|
308
|
+
lines.push(` session: ${shortenPath(run.sessionFile)}`);
|
|
309
|
+
lines.push("");
|
|
310
|
+
}
|
|
311
|
+
return lines.join(`
|
|
312
|
+
`).trimEnd();
|
|
313
|
+
}
|