{"version":3,"file":"nested-render.d.ts","sourceRoot":"","sources":["../../../../src/runs/shared/nested-render.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE7E,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,SAAS,GAAG,eAAe,CA4BzF;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAalG;AAoFD,wBAAgB,0BAA0B,CACzC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,SAAS,EACxC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GAC7F,MAAM,EAAE,CAOV","sourcesContent":["import { formatDuration, formatModelThinking, formatTokens, shortenPath } from \"../../shared/formatters.ts\";\nimport { formatActivityLabel } from \"../../shared/status-format.ts\";\nimport type { ActivityState, NestedRunSummary } from \"../../shared/types.ts\";\n\nexport interface NestedRunCounts {\n\ttotal: number;\n\trunning: number;\n\tpaused: number;\n\tcomplete: number;\n\tfailed: number;\n\trejected: number;\n\tstopped: number;\n\tqueued: number;\n}\n\nexport function countNestedRuns(children: NestedRunSummary[] | undefined): NestedRunCounts {\n\tconst counts: NestedRunCounts = {\n\t\ttotal: 0,\n\t\trunning: 0,\n\t\tpaused: 0,\n\t\tcomplete: 0,\n\t\tfailed: 0,\n\t\trejected: 0,\n\t\tstopped: 0,\n\t\tqueued: 0,\n\t};\n\tfor (const child of children ?? []) {\n\t\tcounts.total++;\n\t\tcounts[child.state]++;\n\t\tconst nested = countNestedRuns([\n\t\t\t...(child.children ?? []),\n\t\t\t...(child.steps?.flatMap((step) => step.children ?? []) ?? []),\n\t\t]);\n\t\tcounts.total += nested.total;\n\t\tcounts.running += nested.running;\n\t\tcounts.paused += nested.paused;\n\t\tcounts.complete += nested.complete;\n\t\tcounts.failed += nested.failed;\n\t\tcounts.rejected += nested.rejected;\n\t\tcounts.stopped += nested.stopped;\n\t\tcounts.queued += nested.queued;\n\t}\n\treturn counts;\n}\n\nexport function formatNestedAggregate(children: NestedRunSummary[] | undefined): string | undefined {\n\tconst counts = countNestedRuns(children);\n\tif (counts.total === 0) return undefined;\n\tconst parts = [\n\t\tcounts.running > 0 ? `${counts.running} running` : \"\",\n\t\tcounts.paused > 0 ? `${counts.paused} paused` : \"\",\n\t\tcounts.failed > 0 ? `${counts.failed} failed` : \"\",\n\t\tcounts.rejected > 0 ? `${counts.rejected} rejected` : \"\",\n\t\tcounts.stopped > 0 ? `${counts.stopped} stopped` : \"\",\n\t\tcounts.complete > 0 ? `${counts.complete} complete` : \"\",\n\t\tcounts.queued > 0 ? `${counts.queued} queued` : \"\",\n\t].filter(Boolean);\n\treturn `+${counts.total} nested run${counts.total === 1 ? \"\" : \"s\"}${parts.length ? ` (${parts.join(\", \")})` : \"\"}`;\n}\n\nfunction nestedRunLabel(run: NestedRunSummary): string {\n\tif (run.agent) return run.agent;\n\tif (run.agents?.length)\n\t\treturn run.agents.length === 1\n\t\t\t? run.agents[0]!\n\t\t\t: `${run.agents.slice(0, 2).join(\", \")}${run.agents.length > 2 ? ` +${run.agents.length - 2}` : \"\"}`;\n\treturn run.id;\n}\n\nfunction formatNestedActivity(input: {\n\tactivityState?: ActivityState;\n\tlastActivityAt?: number;\n\tcurrentTool?: string;\n\tcurrentToolStartedAt?: number;\n\tcurrentPath?: string;\n\tturnCount?: number;\n\ttoolCount?: number;\n\ttotalTokens?: NestedRunSummary[\"totalTokens\"];\n}): string | undefined {\n\tconst facts: string[] = [];\n\tif (input.currentTool && input.currentToolStartedAt !== undefined)\n\t\tfacts.push(`tool ${input.currentTool} ${formatDuration(Math.max(0, Date.now() - input.currentToolStartedAt))}`);\n\telse if (input.currentTool) facts.push(`tool ${input.currentTool}`);\n\tif (input.currentPath) facts.push(shortenPath(input.currentPath));\n\tif (input.turnCount !== undefined) facts.push(`${input.turnCount} turns`);\n\tif (input.toolCount !== undefined) facts.push(`${input.toolCount} tools`);\n\tif (input.totalTokens) facts.push(`${formatTokens(input.totalTokens.total)} tok`);\n\tconst activity = formatActivityLabel(input.lastActivityAt, input.activityState as ActivityState | undefined);\n\treturn activity || facts.length ? [activity, ...facts].filter(Boolean).join(\" | \") : undefined;\n}\n\nfunction formatNestedRunLines(\n\tchildren: NestedRunSummary[] | undefined,\n\toptions: { indent: string; maxDepth: number; maxLines: number; commandHints?: boolean },\n): string[] {\n\tconst lines: string[] = [];\n\tconst append = (items: NestedRunSummary[] | undefined, depth: number, indent: string): void => {\n\t\tif (!items?.length || lines.length >= options.maxLines) return;\n\t\tif (depth > options.maxDepth) {\n\t\t\tconst aggregate = formatNestedAggregate(items);\n\t\t\tif (aggregate && lines.length < options.maxLines) lines.push(`${indent}↳ ${aggregate}`);\n\t\t\treturn;\n\t\t}\n\t\tfor (let index = 0; index < items.length; index++) {\n\t\t\tconst child = items[index]!;\n\t\t\tif (lines.length >= options.maxLines) {\n\t\t\t\tconst aggregate = formatNestedAggregate(items.slice(index));\n\t\t\t\tif (aggregate) lines[lines.length - 1] = `${indent}↳ ${aggregate}`;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst activity = child.state === \"running\" ? formatNestedActivity(child) : undefined;\n\t\t\tconst error = child.error ? ` | error: ${child.error}` : \"\";\n\t\t\tconst modelThinking = formatModelThinking(child.model, child.thinking);\n\t\t\tlines.push(\n\t\t\t\t`${indent}↳ ${nestedRunLabel(child)} [${child.id}] ${child.state}${modelThinking ? ` | ${modelThinking}` : \"\"}${activity ? ` | ${activity}` : \"\"}${error}`,\n\t\t\t);\n\t\t\tif (options.commandHints && lines.length < options.maxLines)\n\t\t\t\tlines.push(`${indent}  Status: subagent({ action: \"status\", id: \"${child.id}\" })`);\n\t\t\tif (depth === options.maxDepth) {\n\t\t\t\tconst aggregate = formatNestedAggregate([\n\t\t\t\t\t...(child.steps?.flatMap((step) => step.children ?? []) ?? []),\n\t\t\t\t\t...(child.children ?? []),\n\t\t\t\t]);\n\t\t\t\tif (aggregate && lines.length < options.maxLines) lines.push(`${indent}  ↳ ${aggregate}`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const [stepIndex, step] of (child.steps ?? []).entries()) {\n\t\t\t\tif (lines.length >= options.maxLines) return;\n\t\t\t\tconst stepActivity = step.status === \"running\" ? formatNestedActivity(step) : undefined;\n\t\t\t\tconst stepModelThinking = formatModelThinking(step.model, step.thinking);\n\t\t\t\tlines.push(\n\t\t\t\t\t`${indent}  ${stepIndex + 1}. ${step.agent} ${step.status}${stepModelThinking ? ` | ${stepModelThinking}` : \"\"}${stepActivity ? ` | ${stepActivity}` : \"\"}${step.error ? ` | error: ${step.error}` : \"\"}`,\n\t\t\t\t);\n\t\t\t\tappend(step.children, depth + 1, `${indent}    `);\n\t\t\t}\n\t\t\tappend(child.children, depth + 1, `${indent}  `);\n\t\t}\n\t};\n\tappend(children, 0, options.indent);\n\treturn lines;\n}\n\nexport function formatNestedRunStatusLines(\n\tchildren: NestedRunSummary[] | undefined,\n\toptions: { indent?: string; maxDepth?: number; maxLines?: number; commandHints?: boolean } = {},\n): string[] {\n\treturn formatNestedRunLines(children, {\n\t\tindent: options.indent ?? \"  \",\n\t\tmaxDepth: options.maxDepth ?? 2,\n\t\tmaxLines: options.maxLines ?? 40,\n\t\tcommandHints: options.commandHints ?? false,\n\t});\n}\n"]}