@astralyn/pi 0.82.6 → 0.82.7
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/CHANGELOG.md +27 -0
- package/README.md +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +11 -13
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/core/extensions/types.d.ts +4 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +2 -2
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -5
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -41
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +42 -11
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +6 -7
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +17 -8
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +3 -3
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +4 -4
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +7 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +11 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +2 -3
- package/dist/core/tools/write.js.map +1 -1
- package/dist/extensions/deepwiki/render.d.ts.map +1 -1
- package/dist/extensions/deepwiki/render.js +34 -22
- package/dist/extensions/deepwiki/render.js.map +1 -1
- package/dist/extensions/plan/constants.d.ts +32 -4
- package/dist/extensions/plan/constants.d.ts.map +1 -1
- package/dist/extensions/plan/constants.js +37 -6
- package/dist/extensions/plan/constants.js.map +1 -1
- package/dist/extensions/plan/index.d.ts +27 -0
- package/dist/extensions/plan/index.d.ts.map +1 -1
- package/dist/extensions/plan/index.js +150 -44
- package/dist/extensions/plan/index.js.map +1 -1
- package/dist/extensions/plan/schema.d.ts +5 -0
- package/dist/extensions/plan/schema.d.ts.map +1 -1
- package/dist/extensions/plan/schema.js.map +1 -1
- package/dist/extensions/plan/state.d.ts +11 -2
- package/dist/extensions/plan/state.d.ts.map +1 -1
- package/dist/extensions/plan/state.js +31 -9
- package/dist/extensions/plan/state.js.map +1 -1
- package/dist/extensions/plan/storage.d.ts +11 -3
- package/dist/extensions/plan/storage.d.ts.map +1 -1
- package/dist/extensions/plan/storage.js +45 -20
- package/dist/extensions/plan/storage.js.map +1 -1
- package/dist/extensions/plan/view.d.ts +15 -7
- package/dist/extensions/plan/view.d.ts.map +1 -1
- package/dist/extensions/plan/view.js +91 -16
- package/dist/extensions/plan/view.js.map +1 -1
- package/dist/extensions/question/dialog.d.ts.map +1 -1
- package/dist/extensions/question/dialog.js +29 -10
- package/dist/extensions/question/dialog.js.map +1 -1
- package/dist/extensions/question/index.d.ts.map +1 -1
- package/dist/extensions/question/index.js +7 -2
- package/dist/extensions/question/index.js.map +1 -1
- package/dist/extensions/question/render.d.ts +4 -8
- package/dist/extensions/question/render.d.ts.map +1 -1
- package/dist/extensions/question/render.js +202 -29
- package/dist/extensions/question/render.js.map +1 -1
- package/dist/extensions/question/results.d.ts.map +1 -1
- package/dist/extensions/question/results.js +1 -0
- package/dist/extensions/question/results.js.map +1 -1
- package/dist/extensions/question/schema.d.ts.map +1 -1
- package/dist/extensions/question/schema.js +2 -2
- package/dist/extensions/question/schema.js.map +1 -1
- package/dist/extensions/question/types.d.ts +1 -0
- package/dist/extensions/question/types.d.ts.map +1 -1
- package/dist/extensions/question/types.js +1 -1
- package/dist/extensions/question/types.js.map +1 -1
- package/dist/extensions/router/stream.d.ts +1 -0
- package/dist/extensions/router/stream.d.ts.map +1 -1
- package/dist/extensions/router/stream.js +44 -13
- package/dist/extensions/router/stream.js.map +1 -1
- package/dist/extensions/subagent/constants.d.ts +1 -0
- package/dist/extensions/subagent/constants.d.ts.map +1 -1
- package/dist/extensions/subagent/constants.js +1 -0
- package/dist/extensions/subagent/constants.js.map +1 -1
- package/dist/extensions/subagent/index.d.ts.map +1 -1
- package/dist/extensions/subagent/index.js +2 -0
- package/dist/extensions/subagent/index.js.map +1 -1
- package/dist/extensions/subagent/render.d.ts.map +1 -1
- package/dist/extensions/subagent/render.js +121 -48
- package/dist/extensions/subagent/render.js.map +1 -1
- package/dist/extensions/subagent/retry.d.ts +17 -0
- package/dist/extensions/subagent/retry.d.ts.map +1 -0
- package/dist/extensions/subagent/retry.js +41 -0
- package/dist/extensions/subagent/retry.js.map +1 -0
- package/dist/extensions/subagent/runner.d.ts.map +1 -1
- package/dist/extensions/subagent/runner.js +33 -5
- package/dist/extensions/subagent/runner.js.map +1 -1
- package/dist/extensions/subagent/sdk-runner.d.ts +6 -0
- package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -1
- package/dist/extensions/subagent/sdk-runner.js +46 -24
- package/dist/extensions/subagent/sdk-runner.js.map +1 -1
- package/dist/extensions/subagent/types.d.ts +7 -0
- package/dist/extensions/subagent/types.d.ts.map +1 -1
- package/dist/extensions/subagent/types.js.map +1 -1
- package/dist/extensions/todo/index.d.ts.map +1 -1
- package/dist/extensions/todo/index.js +1 -1
- package/dist/extensions/todo/index.js.map +1 -1
- package/dist/extensions/todo/state.d.ts.map +1 -1
- package/dist/extensions/todo/state.js +10 -2
- package/dist/extensions/todo/state.js.map +1 -1
- package/dist/extensions/todo/view.d.ts +1 -1
- package/dist/extensions/todo/view.d.ts.map +1 -1
- package/dist/extensions/todo/view.js +179 -34
- package/dist/extensions/todo/view.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +2 -1
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/armin.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.js +5 -0
- package/dist/modes/interactive/components/armin.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +4 -2
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts +13 -6
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.js +54 -17
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +10 -6
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +11 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +56 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +3 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +52 -2
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +10 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +133 -18
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts +1 -0
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +5 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +10 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +55 -2
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +5 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +72 -18
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +3 -2
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/utils/paths.d.ts +6 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +8 -0
- package/dist/utils/paths.js.map +1 -1
- package/docs/bundled/README.md +1 -0
- package/docs/bundled/extensions/deepwiki.md +1 -1
- package/docs/bundled/extensions/plan.md +10 -9
- package/docs/bundled/extensions/question.md +7 -5
- package/docs/bundled/extensions/router.md +3 -4
- package/docs/bundled/extensions/statusline.md +0 -1
- package/docs/bundled/extensions/subagent.md +4 -3
- package/docs/bundled/extensions/todo.md +1 -1
- package/docs/bundled/tool-presentation.md +17 -16
- package/docs/extensions.md +20 -5
- package/docs/rpc.md +1 -1
- package/docs/usage.md +1 -1
- package/npm-shrinkwrap.json +6 -6
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEX,YAAY,EAGZ,MAAM,gCAAgC,CAAC;AA+LxC,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAmHvD","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getSupportedThinkingLevels } from \"@earendil-works/pi-ai/compat\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { emptyUsage } from \"./activity.ts\";\nimport { discoverAgents, subagentToolDescription } from \"./agents.ts\";\nimport { SUBAGENT_COMMAND_NAME, SUBAGENT_TOOL_LABEL, SUBAGENT_TOOL_NAME, THINKING_LEVELS } from \"./constants.ts\";\nimport { type PickerItem, SearchPickerComponent } from \"./picker.ts\";\nimport { renderSubagentCall, renderSubagentResult } from \"./render.ts\";\nimport type { ParentModelContext } from \"./resolve.ts\";\nimport { ConcurrencyGate, isSubagentError, runSubagentInvocation, statusSummary } from \"./runner.ts\";\nimport { SubagentParamsSchema } from \"./schema.ts\";\nimport { loadSubagentConfig, resetProfileOverrides, updateProfileOverride } from \"./settings.ts\";\nimport type { AgentDefinition, AgentDiscoveryResult, SubagentDetails, SubagentProfileOverride } from \"./types.ts\";\n\nfunction formatParentModel(model: { provider: string; id: string } | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"none\";\n}\n\n// Settings resolve in two layers: a saved override wins, otherwise the\n// profile inherits the parent session. Inherited rows show the value\n// currently in effect so the menu doubles as a status view.\nfunction effectiveSettings(\n\toverride: SubagentProfileOverride | undefined,\n\tctx: ExtensionCommandContext,\n\tparentThinking: string,\n): { model: string; thinking: string } {\n\treturn {\n\t\tmodel: override?.model ?? `inherit (${formatParentModel(ctx.model)})`,\n\t\tthinking: override?.thinking ?? `inherit (${parentThinking})`,\n\t};\n}\n\n// The thinking picker lists what the effective model actually supports;\n// if the saved override names a model that is unavailable right now,\n// every level shows and the runtime clamp decides.\nfunction effectiveModelFor(\n\tctx: ExtensionCommandContext,\n\toverride: SubagentProfileOverride | undefined,\n): Model<Api> | undefined {\n\tif (override?.model) {\n\t\tconst separator = override.model.indexOf(\"/\");\n\t\tif (separator <= 0) return undefined;\n\t\treturn ctx.modelRegistry.find(override.model.slice(0, separator), override.model.slice(separator + 1));\n\t}\n\treturn ctx.model;\n}\n\nasync function pickModel(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n): Promise<void> {\n\tconst items: PickerItem<string | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${formatParentModel(ctx.model)})`,\n\t\t\tcurrent: !override?.model,\n\t\t},\n\t\t...ctx.modelRegistry.getAvailable().map((model) => ({\n\t\t\tvalue: `${model.provider}/${model.id}`,\n\t\t\tlabel: `${model.provider}/${model.id}`,\n\t\t\tdetail: model.name && model.name !== model.id ? model.name : undefined,\n\t\t\tcurrent: override?.model === `${model.provider}/${model.id}`,\n\t\t})),\n\t];\n\tconst selected = await ctx.ui.custom<string | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Model for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { model: selected ?? undefined }, getAgentDir());\n}\n\nasync function pickThinking(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n\tparentThinking: string,\n): Promise<void> {\n\tconst model = effectiveModelFor(ctx, override);\n\tconst levels = model ? (getSupportedThinkingLevels(model) as ThinkingLevel[]) : [...THINKING_LEVELS];\n\tconst items: PickerItem<ThinkingLevel | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${parentThinking})`,\n\t\t\tcurrent: !override?.thinking,\n\t\t},\n\t\t...levels.map((level) => ({ value: level, label: level, current: override?.thinking === level })),\n\t];\n\tconst selected = await ctx.ui.custom<ThinkingLevel | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Thinking for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { thinking: selected ?? undefined }, getAgentDir());\n}\n\nasync function configureProfile(\n\tctx: ExtensionCommandContext,\n\tagent: AgentDefinition,\n\tparentThinking: string,\n): Promise<void> {\n\tconst agentDir = getAgentDir();\n\twhile (true) {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst override = config.profiles[agent.name];\n\t\tconst effective = effectiveSettings(override, ctx, parentThinking);\n\t\tconst action = await ctx.ui.select(`${agent.name} — ${agent.description}`, [\n\t\t\t`Model: ${effective.model}`,\n\t\t\t`Thinking: ${effective.thinking}`,\n\t\t\t\"Back\",\n\t\t]);\n\t\tif (!action || action === \"Back\") return;\n\t\tif (action.startsWith(\"Model:\")) {\n\t\t\tawait pickModel(ctx, agent.name, override);\n\t\t\tcontinue;\n\t\t}\n\t\tawait pickThinking(ctx, agent.name, override, parentThinking);\n\t}\n}\n\nasync function syncParentProviders(\n\truntime: ModelRuntime,\n\tregistry: ModelRegistry,\n\tsyncedIds: Set<string>,\n): Promise<void> {\n\tconst nextIds = new Set(registry.getRegisteredProviderIds());\n\tfor (const id of syncedIds) {\n\t\tif (!nextIds.has(id)) runtime.unregisterProvider(id);\n\t}\n\tfor (const id of nextIds) {\n\t\tconst native = registry.getRegisteredNativeProvider(id);\n\t\tif (native) runtime.registerNativeProvider(native);\n\t\telse {\n\t\t\tconst config = registry.getRegisteredProviderConfig(id);\n\t\t\tif (config) runtime.registerProvider(id, config);\n\t\t}\n\t\tconst auth = await registry.getProviderAuth(id);\n\t\tif (auth?.auth.apiKey) await runtime.setRuntimeApiKey(id, auth.auth.apiKey, { allowNetwork: false });\n\t}\n\tsyncedIds.clear();\n\tfor (const id of nextIds) syncedIds.add(id);\n}\n\nasync function showAgentsCommand(ctx: ExtensionCommandContext, parentThinking: string): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/agents requires an interactive UI.\", \"warning\");\n\t\treturn;\n\t}\n\tconst agentDir = getAgentDir();\n\tconst reset = \"Reset all overrides\";\n\tconst done = \"Done\";\n\twhile (true) {\n\t\tconst discovery = discoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir });\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst rows = discovery.agents.map((agent) => {\n\t\t\tconst effective = effectiveSettings(config.profiles[agent.name], ctx, parentThinking);\n\t\t\treturn `${agent.name} — model: ${effective.model} · thinking: ${effective.thinking}`;\n\t\t});\n\t\tconst issueCount = discovery.diagnostics.length;\n\t\tconst issues = issueCount ? [`Show ${issueCount} agent file issue${issueCount === 1 ? \"\" : \"s\"}`] : [];\n\t\tconst action = await ctx.ui.select(\"Subagent profiles — select one to configure\", [\n\t\t\t...rows,\n\t\t\t...issues,\n\t\t\treset,\n\t\t\tdone,\n\t\t]);\n\t\tif (!action || action === done) return;\n\t\tif (action === reset) {\n\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\"Reset profile overrides?\",\n\t\t\t\t\"Clear every saved Subagent model and thinking override?\",\n\t\t\t);\n\t\t\tif (confirmed) {\n\t\t\t\tawait resetProfileOverrides(agentDir);\n\t\t\t\tctx.ui.notify(\"All profiles now inherit the parent session.\", \"info\");\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (issues.length > 0 && action === issues[0]) {\n\t\t\tctx.ui.notify(\n\t\t\t\tdiscovery.diagnostics.map((diagnostic) => `${diagnostic.path}: ${diagnostic.message}`).join(\"\\n\"),\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst agent = discovery.agents.find((candidate) => action.startsWith(`${candidate.name} — `));\n\t\tif (agent) await configureProfile(ctx, agent, parentThinking);\n\t}\n}\n\nexport default function subagent(pi: ExtensionAPI): void {\n\tconst gate = new ConcurrencyGate();\n\tconst activeAborters = new Set<() => Promise<void>>();\n\tconst syncedProviderIds = new Set<string>();\n\tlet modelRuntimePromise: Promise<ModelRuntime> | undefined;\n\n\tconst getModelRuntime = async (ctx: ExtensionContext): Promise<ModelRuntime> => {\n\t\tif (!modelRuntimePromise) {\n\t\t\tconst agentDir = getAgentDir();\n\t\t\tconst created = ModelRuntime.create({\n\t\t\t\tauthPath: join(agentDir, \"auth.json\"),\n\t\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\t});\n\t\t\t// A transient failure (network, filesystem) must not brick the tool\n\t\t\t// for the rest of the session: drop the rejected promise so the\n\t\t\t// next invocation retries creation.\n\t\t\tcreated.catch(() => {\n\t\t\t\tif (modelRuntimePromise === created) modelRuntimePromise = undefined;\n\t\t\t});\n\t\t\tmodelRuntimePromise = created;\n\t\t}\n\t\tconst runtime = await modelRuntimePromise;\n\t\tawait syncParentProviders(runtime, ctx.modelRegistry, syncedProviderIds);\n\t\treturn runtime;\n\t};\n\n\tconst registerSubagentTool = (discovery: AgentDiscoveryResult): void => {\n\t\tpi.registerTool<typeof SubagentParamsSchema, SubagentDetails>({\n\t\t\tname: SUBAGENT_TOOL_NAME,\n\t\t\tlabel: SUBAGENT_TOOL_LABEL,\n\t\t\tdescription: subagentToolDescription(discovery),\n\t\t\tpromptSnippet: \"Delegate focused research, review, or implementation tasks to isolated subagents\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use subagent when a bounded task benefits from isolated context or parallel investigation; choose a profile and write its briefing using the tool description.\",\n\t\t\t],\n\t\t\tparameters: SubagentParamsSchema,\n\t\t\tasync execute(_toolCallId, params, signal, onUpdate, ctx): Promise<AgentToolResult<SubagentDetails>> {\n\t\t\t\t// First paint before any await: model-runtime creation and task\n\t\t\t\t// resolution can stall on first use (network, filesystem), and\n\t\t\t\t// the transcript card must not sit empty while they do.\n\t\t\t\tonUpdate?.({\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Initializing…\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: params.tasks ? \"parallel\" : \"single\",\n\t\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\t\truns: [],\n\t\t\t\t\t\tstartedAt: Date.now(),\n\t\t\t\t\t\tusage: emptyUsage(),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tconst discovery = discoverAgents(ctx.cwd, {\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t});\n\t\t\t\tconst runtime = await getModelRuntime(ctx);\n\t\t\t\tconst parent: ParentModelContext = {\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tthinking: pi.getThinkingLevel(),\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t};\n\t\t\t\tconst execution = await runSubagentInvocation({\n\t\t\t\t\tparams,\n\t\t\t\t\tparentCwd: ctx.cwd,\n\t\t\t\t\tagents: discovery.agents,\n\t\t\t\t\tparent,\n\t\t\t\t\tmodelRuntime: runtime,\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tsignal,\n\t\t\t\t\tgate,\n\t\t\t\t\tonUpdate: (details) => {\n\t\t\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: statusSummary(details) }], details });\n\t\t\t\t\t},\n\t\t\t\t\tregisterAbort: (abort) => {\n\t\t\t\t\t\tactiveAborters.add(abort);\n\t\t\t\t\t\treturn () => activeAborters.delete(abort);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: execution.content }],\n\t\t\t\t\tdetails: execution.details,\n\t\t\t\t\tusage: execution.usage,\n\t\t\t\t};\n\t\t\t},\n\t\t\trenderCall(args, theme) {\n\t\t\t\treturn renderSubagentCall(args, theme);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderSubagentResult(result, options, theme, context.isError);\n\t\t\t},\n\t\t});\n\t};\n\n\tregisterSubagentTool(discoverAgents(process.cwd(), { projectTrusted: false, agentDir: getAgentDir() }));\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\tregisterSubagentTool(\n\t\t\tdiscoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir: getAgentDir() }),\n\t\t);\n\t});\n\n\tpi.registerCommand(SUBAGENT_COMMAND_NAME, {\n\t\tdescription: \"Configure Subagent profiles, models, and thinking levels\",\n\t\thandler: async (_args, ctx) => showAgentsCommand(ctx, pi.getThinkingLevel()),\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== SUBAGENT_TOOL_NAME) return;\n\t\tconst details = event.details as SubagentDetails | undefined;\n\t\tif (details && isSubagentError(details)) return { isError: true };\n\t});\n\n\tpi.on(\"session_shutdown\", async () => {\n\t\tawait Promise.allSettled([...activeAborters].map((abort) => abort()));\n\t\tactiveAborters.clear();\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEX,YAAY,EAGZ,MAAM,gCAAgC,CAAC;AA+LxC,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAqHvD","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getSupportedThinkingLevels } from \"@earendil-works/pi-ai/compat\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { emptyUsage } from \"./activity.ts\";\nimport { discoverAgents, subagentToolDescription } from \"./agents.ts\";\nimport { SUBAGENT_COMMAND_NAME, SUBAGENT_TOOL_LABEL, SUBAGENT_TOOL_NAME, THINKING_LEVELS } from \"./constants.ts\";\nimport { type PickerItem, SearchPickerComponent } from \"./picker.ts\";\nimport { renderSubagentCall, renderSubagentResult } from \"./render.ts\";\nimport type { ParentModelContext } from \"./resolve.ts\";\nimport { ConcurrencyGate, isSubagentError, runSubagentInvocation, statusSummary } from \"./runner.ts\";\nimport { SubagentParamsSchema } from \"./schema.ts\";\nimport { loadSubagentConfig, resetProfileOverrides, updateProfileOverride } from \"./settings.ts\";\nimport type { AgentDefinition, AgentDiscoveryResult, SubagentDetails, SubagentProfileOverride } from \"./types.ts\";\n\nfunction formatParentModel(model: { provider: string; id: string } | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"none\";\n}\n\n// Settings resolve in two layers: a saved override wins, otherwise the\n// profile inherits the parent session. Inherited rows show the value\n// currently in effect so the menu doubles as a status view.\nfunction effectiveSettings(\n\toverride: SubagentProfileOverride | undefined,\n\tctx: ExtensionCommandContext,\n\tparentThinking: string,\n): { model: string; thinking: string } {\n\treturn {\n\t\tmodel: override?.model ?? `inherit (${formatParentModel(ctx.model)})`,\n\t\tthinking: override?.thinking ?? `inherit (${parentThinking})`,\n\t};\n}\n\n// The thinking picker lists what the effective model actually supports;\n// if the saved override names a model that is unavailable right now,\n// every level shows and the runtime clamp decides.\nfunction effectiveModelFor(\n\tctx: ExtensionCommandContext,\n\toverride: SubagentProfileOverride | undefined,\n): Model<Api> | undefined {\n\tif (override?.model) {\n\t\tconst separator = override.model.indexOf(\"/\");\n\t\tif (separator <= 0) return undefined;\n\t\treturn ctx.modelRegistry.find(override.model.slice(0, separator), override.model.slice(separator + 1));\n\t}\n\treturn ctx.model;\n}\n\nasync function pickModel(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n): Promise<void> {\n\tconst items: PickerItem<string | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${formatParentModel(ctx.model)})`,\n\t\t\tcurrent: !override?.model,\n\t\t},\n\t\t...ctx.modelRegistry.getAvailable().map((model) => ({\n\t\t\tvalue: `${model.provider}/${model.id}`,\n\t\t\tlabel: `${model.provider}/${model.id}`,\n\t\t\tdetail: model.name && model.name !== model.id ? model.name : undefined,\n\t\t\tcurrent: override?.model === `${model.provider}/${model.id}`,\n\t\t})),\n\t];\n\tconst selected = await ctx.ui.custom<string | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Model for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { model: selected ?? undefined }, getAgentDir());\n}\n\nasync function pickThinking(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n\tparentThinking: string,\n): Promise<void> {\n\tconst model = effectiveModelFor(ctx, override);\n\tconst levels = model ? (getSupportedThinkingLevels(model) as ThinkingLevel[]) : [...THINKING_LEVELS];\n\tconst items: PickerItem<ThinkingLevel | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${parentThinking})`,\n\t\t\tcurrent: !override?.thinking,\n\t\t},\n\t\t...levels.map((level) => ({ value: level, label: level, current: override?.thinking === level })),\n\t];\n\tconst selected = await ctx.ui.custom<ThinkingLevel | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Thinking for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { thinking: selected ?? undefined }, getAgentDir());\n}\n\nasync function configureProfile(\n\tctx: ExtensionCommandContext,\n\tagent: AgentDefinition,\n\tparentThinking: string,\n): Promise<void> {\n\tconst agentDir = getAgentDir();\n\twhile (true) {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst override = config.profiles[agent.name];\n\t\tconst effective = effectiveSettings(override, ctx, parentThinking);\n\t\tconst action = await ctx.ui.select(`${agent.name} — ${agent.description}`, [\n\t\t\t`Model: ${effective.model}`,\n\t\t\t`Thinking: ${effective.thinking}`,\n\t\t\t\"Back\",\n\t\t]);\n\t\tif (!action || action === \"Back\") return;\n\t\tif (action.startsWith(\"Model:\")) {\n\t\t\tawait pickModel(ctx, agent.name, override);\n\t\t\tcontinue;\n\t\t}\n\t\tawait pickThinking(ctx, agent.name, override, parentThinking);\n\t}\n}\n\nasync function syncParentProviders(\n\truntime: ModelRuntime,\n\tregistry: ModelRegistry,\n\tsyncedIds: Set<string>,\n): Promise<void> {\n\tconst nextIds = new Set(registry.getRegisteredProviderIds());\n\tfor (const id of syncedIds) {\n\t\tif (!nextIds.has(id)) runtime.unregisterProvider(id);\n\t}\n\tfor (const id of nextIds) {\n\t\tconst native = registry.getRegisteredNativeProvider(id);\n\t\tif (native) runtime.registerNativeProvider(native);\n\t\telse {\n\t\t\tconst config = registry.getRegisteredProviderConfig(id);\n\t\t\tif (config) runtime.registerProvider(id, config);\n\t\t}\n\t\tconst auth = await registry.getProviderAuth(id);\n\t\tif (auth?.auth.apiKey) await runtime.setRuntimeApiKey(id, auth.auth.apiKey, { allowNetwork: false });\n\t}\n\tsyncedIds.clear();\n\tfor (const id of nextIds) syncedIds.add(id);\n}\n\nasync function showAgentsCommand(ctx: ExtensionCommandContext, parentThinking: string): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/agents requires an interactive UI.\", \"warning\");\n\t\treturn;\n\t}\n\tconst agentDir = getAgentDir();\n\tconst reset = \"Reset all overrides\";\n\tconst done = \"Done\";\n\twhile (true) {\n\t\tconst discovery = discoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir });\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst rows = discovery.agents.map((agent) => {\n\t\t\tconst effective = effectiveSettings(config.profiles[agent.name], ctx, parentThinking);\n\t\t\treturn `${agent.name} — model: ${effective.model} · thinking: ${effective.thinking}`;\n\t\t});\n\t\tconst issueCount = discovery.diagnostics.length;\n\t\tconst issues = issueCount ? [`Show ${issueCount} agent file issue${issueCount === 1 ? \"\" : \"s\"}`] : [];\n\t\tconst action = await ctx.ui.select(\"Subagent profiles — select one to configure\", [\n\t\t\t...rows,\n\t\t\t...issues,\n\t\t\treset,\n\t\t\tdone,\n\t\t]);\n\t\tif (!action || action === done) return;\n\t\tif (action === reset) {\n\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\"Reset profile overrides?\",\n\t\t\t\t\"Clear every saved Subagent model and thinking override?\",\n\t\t\t);\n\t\t\tif (confirmed) {\n\t\t\t\tawait resetProfileOverrides(agentDir);\n\t\t\t\tctx.ui.notify(\"All profiles now inherit the parent session.\", \"info\");\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (issues.length > 0 && action === issues[0]) {\n\t\t\tctx.ui.notify(\n\t\t\t\tdiscovery.diagnostics.map((diagnostic) => `${diagnostic.path}: ${diagnostic.message}`).join(\"\\n\"),\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst agent = discovery.agents.find((candidate) => action.startsWith(`${candidate.name} — `));\n\t\tif (agent) await configureProfile(ctx, agent, parentThinking);\n\t}\n}\n\nexport default function subagent(pi: ExtensionAPI): void {\n\tconst gate = new ConcurrencyGate();\n\tconst activeAborters = new Set<() => Promise<void>>();\n\tconst syncedProviderIds = new Set<string>();\n\tlet modelRuntimePromise: Promise<ModelRuntime> | undefined;\n\n\tconst getModelRuntime = async (ctx: ExtensionContext): Promise<ModelRuntime> => {\n\t\tif (!modelRuntimePromise) {\n\t\t\tconst agentDir = getAgentDir();\n\t\t\tconst created = ModelRuntime.create({\n\t\t\t\tauthPath: join(agentDir, \"auth.json\"),\n\t\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\t});\n\t\t\t// A transient failure (network, filesystem) must not brick the tool\n\t\t\t// for the rest of the session: drop the rejected promise so the\n\t\t\t// next invocation retries creation.\n\t\t\tcreated.catch(() => {\n\t\t\t\tif (modelRuntimePromise === created) modelRuntimePromise = undefined;\n\t\t\t});\n\t\t\tmodelRuntimePromise = created;\n\t\t}\n\t\tconst runtime = await modelRuntimePromise;\n\t\tawait syncParentProviders(runtime, ctx.modelRegistry, syncedProviderIds);\n\t\treturn runtime;\n\t};\n\n\tconst registerSubagentTool = (discovery: AgentDiscoveryResult): void => {\n\t\tpi.registerTool<typeof SubagentParamsSchema, SubagentDetails>({\n\t\t\tname: SUBAGENT_TOOL_NAME,\n\t\t\tlabel: SUBAGENT_TOOL_LABEL,\n\t\t\tdescription: subagentToolDescription(discovery),\n\t\t\trendersOwnProgress: true,\n\t\t\trenderRefreshIntervalMs: 1000,\n\t\t\tpromptSnippet: \"Delegate focused research, review, or implementation tasks to isolated subagents\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use subagent when a bounded task benefits from isolated context or parallel investigation; choose a profile and write its briefing using the tool description.\",\n\t\t\t],\n\t\t\tparameters: SubagentParamsSchema,\n\t\t\tasync execute(_toolCallId, params, signal, onUpdate, ctx): Promise<AgentToolResult<SubagentDetails>> {\n\t\t\t\t// First paint before any await: model-runtime creation and task\n\t\t\t\t// resolution can stall on first use (network, filesystem), and\n\t\t\t\t// the transcript card must not sit empty while they do.\n\t\t\t\tonUpdate?.({\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Initializing…\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: params.tasks ? \"parallel\" : \"single\",\n\t\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\t\truns: [],\n\t\t\t\t\t\tstartedAt: Date.now(),\n\t\t\t\t\t\tusage: emptyUsage(),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tconst discovery = discoverAgents(ctx.cwd, {\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t});\n\t\t\t\tconst runtime = await getModelRuntime(ctx);\n\t\t\t\tconst parent: ParentModelContext = {\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tthinking: pi.getThinkingLevel(),\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t};\n\t\t\t\tconst execution = await runSubagentInvocation({\n\t\t\t\t\tparams,\n\t\t\t\t\tparentCwd: ctx.cwd,\n\t\t\t\t\tagents: discovery.agents,\n\t\t\t\t\tparent,\n\t\t\t\t\tmodelRuntime: runtime,\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tsignal,\n\t\t\t\t\tgate,\n\t\t\t\t\tonUpdate: (details) => {\n\t\t\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: statusSummary(details) }], details });\n\t\t\t\t\t},\n\t\t\t\t\tregisterAbort: (abort) => {\n\t\t\t\t\t\tactiveAborters.add(abort);\n\t\t\t\t\t\treturn () => activeAborters.delete(abort);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: execution.content }],\n\t\t\t\t\tdetails: execution.details,\n\t\t\t\t\tusage: execution.usage,\n\t\t\t\t};\n\t\t\t},\n\t\t\trenderCall(args, theme) {\n\t\t\t\treturn renderSubagentCall(args, theme);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderSubagentResult(result, options, theme, context.isError);\n\t\t\t},\n\t\t});\n\t};\n\n\tregisterSubagentTool(discoverAgents(process.cwd(), { projectTrusted: false, agentDir: getAgentDir() }));\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\tregisterSubagentTool(\n\t\t\tdiscoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir: getAgentDir() }),\n\t\t);\n\t});\n\n\tpi.registerCommand(SUBAGENT_COMMAND_NAME, {\n\t\tdescription: \"Configure Subagent profiles, models, and thinking levels\",\n\t\thandler: async (_args, ctx) => showAgentsCommand(ctx, pi.getThinkingLevel()),\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== SUBAGENT_TOOL_NAME) return;\n\t\tconst details = event.details as SubagentDetails | undefined;\n\t\tif (details && isSubagentError(details)) return { isError: true };\n\t});\n\n\tpi.on(\"session_shutdown\", async () => {\n\t\tawait Promise.allSettled([...activeAborters].map((abort) => abort()));\n\t\tactiveAborters.clear();\n\t});\n}\n"]}
|
|
@@ -186,6 +186,8 @@ export default function subagent(pi) {
|
|
|
186
186
|
name: SUBAGENT_TOOL_NAME,
|
|
187
187
|
label: SUBAGENT_TOOL_LABEL,
|
|
188
188
|
description: subagentToolDescription(discovery),
|
|
189
|
+
rendersOwnProgress: true,
|
|
190
|
+
renderRefreshIntervalMs: 1000,
|
|
189
191
|
promptSnippet: "Delegate focused research, review, or implementation tasks to isolated subagents",
|
|
190
192
|
promptGuidelines: [
|
|
191
193
|
"Use subagent when a bounded task benefits from isolated context or parallel investigation; choose a profile and write its briefing using the tool description.",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/subagent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQ9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjH,OAAO,EAAmB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,qBAAqB,EAAE,aAAa,EAAE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AAE,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;IACxG,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;QACvC,oBAAoB,CACnB,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,GAAG,CAAC,gBAAgB,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,CAAC,CAC5F,CAAC;IAAA,CACF,CAAC,CAAC;IAEH,EAAE,CAAC,eAAe,CAAC,qBAAqB,EAAE;QACzC,WAAW,EAAE,0DAA0D;QACvE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,iBAAiB,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC;KAC5E,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;QACrC,IAAI,KAAK,CAAC,QAAQ,KAAK,kBAAkB;YAAE,OAAO;QAClD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAsC,CAAC;QAC7D,IAAI,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAAA,CAClE,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE,CAAC;QACrC,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACtE,cAAc,CAAC,KAAK,EAAE,CAAC;IAAA,CACvB,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getSupportedThinkingLevels } from \"@earendil-works/pi-ai/compat\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { emptyUsage } from \"./activity.ts\";\nimport { discoverAgents, subagentToolDescription } from \"./agents.ts\";\nimport { SUBAGENT_COMMAND_NAME, SUBAGENT_TOOL_LABEL, SUBAGENT_TOOL_NAME, THINKING_LEVELS } from \"./constants.ts\";\nimport { type PickerItem, SearchPickerComponent } from \"./picker.ts\";\nimport { renderSubagentCall, renderSubagentResult } from \"./render.ts\";\nimport type { ParentModelContext } from \"./resolve.ts\";\nimport { ConcurrencyGate, isSubagentError, runSubagentInvocation, statusSummary } from \"./runner.ts\";\nimport { SubagentParamsSchema } from \"./schema.ts\";\nimport { loadSubagentConfig, resetProfileOverrides, updateProfileOverride } from \"./settings.ts\";\nimport type { AgentDefinition, AgentDiscoveryResult, SubagentDetails, SubagentProfileOverride } from \"./types.ts\";\n\nfunction formatParentModel(model: { provider: string; id: string } | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"none\";\n}\n\n// Settings resolve in two layers: a saved override wins, otherwise the\n// profile inherits the parent session. Inherited rows show the value\n// currently in effect so the menu doubles as a status view.\nfunction effectiveSettings(\n\toverride: SubagentProfileOverride | undefined,\n\tctx: ExtensionCommandContext,\n\tparentThinking: string,\n): { model: string; thinking: string } {\n\treturn {\n\t\tmodel: override?.model ?? `inherit (${formatParentModel(ctx.model)})`,\n\t\tthinking: override?.thinking ?? `inherit (${parentThinking})`,\n\t};\n}\n\n// The thinking picker lists what the effective model actually supports;\n// if the saved override names a model that is unavailable right now,\n// every level shows and the runtime clamp decides.\nfunction effectiveModelFor(\n\tctx: ExtensionCommandContext,\n\toverride: SubagentProfileOverride | undefined,\n): Model<Api> | undefined {\n\tif (override?.model) {\n\t\tconst separator = override.model.indexOf(\"/\");\n\t\tif (separator <= 0) return undefined;\n\t\treturn ctx.modelRegistry.find(override.model.slice(0, separator), override.model.slice(separator + 1));\n\t}\n\treturn ctx.model;\n}\n\nasync function pickModel(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n): Promise<void> {\n\tconst items: PickerItem<string | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${formatParentModel(ctx.model)})`,\n\t\t\tcurrent: !override?.model,\n\t\t},\n\t\t...ctx.modelRegistry.getAvailable().map((model) => ({\n\t\t\tvalue: `${model.provider}/${model.id}`,\n\t\t\tlabel: `${model.provider}/${model.id}`,\n\t\t\tdetail: model.name && model.name !== model.id ? model.name : undefined,\n\t\t\tcurrent: override?.model === `${model.provider}/${model.id}`,\n\t\t})),\n\t];\n\tconst selected = await ctx.ui.custom<string | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Model for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { model: selected ?? undefined }, getAgentDir());\n}\n\nasync function pickThinking(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n\tparentThinking: string,\n): Promise<void> {\n\tconst model = effectiveModelFor(ctx, override);\n\tconst levels = model ? (getSupportedThinkingLevels(model) as ThinkingLevel[]) : [...THINKING_LEVELS];\n\tconst items: PickerItem<ThinkingLevel | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${parentThinking})`,\n\t\t\tcurrent: !override?.thinking,\n\t\t},\n\t\t...levels.map((level) => ({ value: level, label: level, current: override?.thinking === level })),\n\t];\n\tconst selected = await ctx.ui.custom<ThinkingLevel | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Thinking for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { thinking: selected ?? undefined }, getAgentDir());\n}\n\nasync function configureProfile(\n\tctx: ExtensionCommandContext,\n\tagent: AgentDefinition,\n\tparentThinking: string,\n): Promise<void> {\n\tconst agentDir = getAgentDir();\n\twhile (true) {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst override = config.profiles[agent.name];\n\t\tconst effective = effectiveSettings(override, ctx, parentThinking);\n\t\tconst action = await ctx.ui.select(`${agent.name} — ${agent.description}`, [\n\t\t\t`Model: ${effective.model}`,\n\t\t\t`Thinking: ${effective.thinking}`,\n\t\t\t\"Back\",\n\t\t]);\n\t\tif (!action || action === \"Back\") return;\n\t\tif (action.startsWith(\"Model:\")) {\n\t\t\tawait pickModel(ctx, agent.name, override);\n\t\t\tcontinue;\n\t\t}\n\t\tawait pickThinking(ctx, agent.name, override, parentThinking);\n\t}\n}\n\nasync function syncParentProviders(\n\truntime: ModelRuntime,\n\tregistry: ModelRegistry,\n\tsyncedIds: Set<string>,\n): Promise<void> {\n\tconst nextIds = new Set(registry.getRegisteredProviderIds());\n\tfor (const id of syncedIds) {\n\t\tif (!nextIds.has(id)) runtime.unregisterProvider(id);\n\t}\n\tfor (const id of nextIds) {\n\t\tconst native = registry.getRegisteredNativeProvider(id);\n\t\tif (native) runtime.registerNativeProvider(native);\n\t\telse {\n\t\t\tconst config = registry.getRegisteredProviderConfig(id);\n\t\t\tif (config) runtime.registerProvider(id, config);\n\t\t}\n\t\tconst auth = await registry.getProviderAuth(id);\n\t\tif (auth?.auth.apiKey) await runtime.setRuntimeApiKey(id, auth.auth.apiKey, { allowNetwork: false });\n\t}\n\tsyncedIds.clear();\n\tfor (const id of nextIds) syncedIds.add(id);\n}\n\nasync function showAgentsCommand(ctx: ExtensionCommandContext, parentThinking: string): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/agents requires an interactive UI.\", \"warning\");\n\t\treturn;\n\t}\n\tconst agentDir = getAgentDir();\n\tconst reset = \"Reset all overrides\";\n\tconst done = \"Done\";\n\twhile (true) {\n\t\tconst discovery = discoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir });\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst rows = discovery.agents.map((agent) => {\n\t\t\tconst effective = effectiveSettings(config.profiles[agent.name], ctx, parentThinking);\n\t\t\treturn `${agent.name} — model: ${effective.model} · thinking: ${effective.thinking}`;\n\t\t});\n\t\tconst issueCount = discovery.diagnostics.length;\n\t\tconst issues = issueCount ? [`Show ${issueCount} agent file issue${issueCount === 1 ? \"\" : \"s\"}`] : [];\n\t\tconst action = await ctx.ui.select(\"Subagent profiles — select one to configure\", [\n\t\t\t...rows,\n\t\t\t...issues,\n\t\t\treset,\n\t\t\tdone,\n\t\t]);\n\t\tif (!action || action === done) return;\n\t\tif (action === reset) {\n\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\"Reset profile overrides?\",\n\t\t\t\t\"Clear every saved Subagent model and thinking override?\",\n\t\t\t);\n\t\t\tif (confirmed) {\n\t\t\t\tawait resetProfileOverrides(agentDir);\n\t\t\t\tctx.ui.notify(\"All profiles now inherit the parent session.\", \"info\");\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (issues.length > 0 && action === issues[0]) {\n\t\t\tctx.ui.notify(\n\t\t\t\tdiscovery.diagnostics.map((diagnostic) => `${diagnostic.path}: ${diagnostic.message}`).join(\"\\n\"),\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst agent = discovery.agents.find((candidate) => action.startsWith(`${candidate.name} — `));\n\t\tif (agent) await configureProfile(ctx, agent, parentThinking);\n\t}\n}\n\nexport default function subagent(pi: ExtensionAPI): void {\n\tconst gate = new ConcurrencyGate();\n\tconst activeAborters = new Set<() => Promise<void>>();\n\tconst syncedProviderIds = new Set<string>();\n\tlet modelRuntimePromise: Promise<ModelRuntime> | undefined;\n\n\tconst getModelRuntime = async (ctx: ExtensionContext): Promise<ModelRuntime> => {\n\t\tif (!modelRuntimePromise) {\n\t\t\tconst agentDir = getAgentDir();\n\t\t\tconst created = ModelRuntime.create({\n\t\t\t\tauthPath: join(agentDir, \"auth.json\"),\n\t\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\t});\n\t\t\t// A transient failure (network, filesystem) must not brick the tool\n\t\t\t// for the rest of the session: drop the rejected promise so the\n\t\t\t// next invocation retries creation.\n\t\t\tcreated.catch(() => {\n\t\t\t\tif (modelRuntimePromise === created) modelRuntimePromise = undefined;\n\t\t\t});\n\t\t\tmodelRuntimePromise = created;\n\t\t}\n\t\tconst runtime = await modelRuntimePromise;\n\t\tawait syncParentProviders(runtime, ctx.modelRegistry, syncedProviderIds);\n\t\treturn runtime;\n\t};\n\n\tconst registerSubagentTool = (discovery: AgentDiscoveryResult): void => {\n\t\tpi.registerTool<typeof SubagentParamsSchema, SubagentDetails>({\n\t\t\tname: SUBAGENT_TOOL_NAME,\n\t\t\tlabel: SUBAGENT_TOOL_LABEL,\n\t\t\tdescription: subagentToolDescription(discovery),\n\t\t\tpromptSnippet: \"Delegate focused research, review, or implementation tasks to isolated subagents\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use subagent when a bounded task benefits from isolated context or parallel investigation; choose a profile and write its briefing using the tool description.\",\n\t\t\t],\n\t\t\tparameters: SubagentParamsSchema,\n\t\t\tasync execute(_toolCallId, params, signal, onUpdate, ctx): Promise<AgentToolResult<SubagentDetails>> {\n\t\t\t\t// First paint before any await: model-runtime creation and task\n\t\t\t\t// resolution can stall on first use (network, filesystem), and\n\t\t\t\t// the transcript card must not sit empty while they do.\n\t\t\t\tonUpdate?.({\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Initializing…\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: params.tasks ? \"parallel\" : \"single\",\n\t\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\t\truns: [],\n\t\t\t\t\t\tstartedAt: Date.now(),\n\t\t\t\t\t\tusage: emptyUsage(),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tconst discovery = discoverAgents(ctx.cwd, {\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t});\n\t\t\t\tconst runtime = await getModelRuntime(ctx);\n\t\t\t\tconst parent: ParentModelContext = {\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tthinking: pi.getThinkingLevel(),\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t};\n\t\t\t\tconst execution = await runSubagentInvocation({\n\t\t\t\t\tparams,\n\t\t\t\t\tparentCwd: ctx.cwd,\n\t\t\t\t\tagents: discovery.agents,\n\t\t\t\t\tparent,\n\t\t\t\t\tmodelRuntime: runtime,\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tsignal,\n\t\t\t\t\tgate,\n\t\t\t\t\tonUpdate: (details) => {\n\t\t\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: statusSummary(details) }], details });\n\t\t\t\t\t},\n\t\t\t\t\tregisterAbort: (abort) => {\n\t\t\t\t\t\tactiveAborters.add(abort);\n\t\t\t\t\t\treturn () => activeAborters.delete(abort);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: execution.content }],\n\t\t\t\t\tdetails: execution.details,\n\t\t\t\t\tusage: execution.usage,\n\t\t\t\t};\n\t\t\t},\n\t\t\trenderCall(args, theme) {\n\t\t\t\treturn renderSubagentCall(args, theme);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderSubagentResult(result, options, theme, context.isError);\n\t\t\t},\n\t\t});\n\t};\n\n\tregisterSubagentTool(discoverAgents(process.cwd(), { projectTrusted: false, agentDir: getAgentDir() }));\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\tregisterSubagentTool(\n\t\t\tdiscoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir: getAgentDir() }),\n\t\t);\n\t});\n\n\tpi.registerCommand(SUBAGENT_COMMAND_NAME, {\n\t\tdescription: \"Configure Subagent profiles, models, and thinking levels\",\n\t\thandler: async (_args, ctx) => showAgentsCommand(ctx, pi.getThinkingLevel()),\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== SUBAGENT_TOOL_NAME) return;\n\t\tconst details = event.details as SubagentDetails | undefined;\n\t\tif (details && isSubagentError(details)) return { isError: true };\n\t});\n\n\tpi.on(\"session_shutdown\", async () => {\n\t\tawait Promise.allSettled([...activeAborters].map((abort) => abort()));\n\t\tactiveAborters.clear();\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/subagent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQ9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjH,OAAO,EAAmB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,eAAe,EAAE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AAA,CACH","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { getSupportedThinkingLevels } from \"@earendil-works/pi-ai/compat\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tAgentToolResult,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { emptyUsage } from \"./activity.ts\";\nimport { discoverAgents, subagentToolDescription } from \"./agents.ts\";\nimport { SUBAGENT_COMMAND_NAME, SUBAGENT_TOOL_LABEL, SUBAGENT_TOOL_NAME, THINKING_LEVELS } from \"./constants.ts\";\nimport { type PickerItem, SearchPickerComponent } from \"./picker.ts\";\nimport { renderSubagentCall, renderSubagentResult } from \"./render.ts\";\nimport type { ParentModelContext } from \"./resolve.ts\";\nimport { ConcurrencyGate, isSubagentError, runSubagentInvocation, statusSummary } from \"./runner.ts\";\nimport { SubagentParamsSchema } from \"./schema.ts\";\nimport { loadSubagentConfig, resetProfileOverrides, updateProfileOverride } from \"./settings.ts\";\nimport type { AgentDefinition, AgentDiscoveryResult, SubagentDetails, SubagentProfileOverride } from \"./types.ts\";\n\nfunction formatParentModel(model: { provider: string; id: string } | undefined): string {\n\treturn model ? `${model.provider}/${model.id}` : \"none\";\n}\n\n// Settings resolve in two layers: a saved override wins, otherwise the\n// profile inherits the parent session. Inherited rows show the value\n// currently in effect so the menu doubles as a status view.\nfunction effectiveSettings(\n\toverride: SubagentProfileOverride | undefined,\n\tctx: ExtensionCommandContext,\n\tparentThinking: string,\n): { model: string; thinking: string } {\n\treturn {\n\t\tmodel: override?.model ?? `inherit (${formatParentModel(ctx.model)})`,\n\t\tthinking: override?.thinking ?? `inherit (${parentThinking})`,\n\t};\n}\n\n// The thinking picker lists what the effective model actually supports;\n// if the saved override names a model that is unavailable right now,\n// every level shows and the runtime clamp decides.\nfunction effectiveModelFor(\n\tctx: ExtensionCommandContext,\n\toverride: SubagentProfileOverride | undefined,\n): Model<Api> | undefined {\n\tif (override?.model) {\n\t\tconst separator = override.model.indexOf(\"/\");\n\t\tif (separator <= 0) return undefined;\n\t\treturn ctx.modelRegistry.find(override.model.slice(0, separator), override.model.slice(separator + 1));\n\t}\n\treturn ctx.model;\n}\n\nasync function pickModel(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n): Promise<void> {\n\tconst items: PickerItem<string | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${formatParentModel(ctx.model)})`,\n\t\t\tcurrent: !override?.model,\n\t\t},\n\t\t...ctx.modelRegistry.getAvailable().map((model) => ({\n\t\t\tvalue: `${model.provider}/${model.id}`,\n\t\t\tlabel: `${model.provider}/${model.id}`,\n\t\t\tdetail: model.name && model.name !== model.id ? model.name : undefined,\n\t\t\tcurrent: override?.model === `${model.provider}/${model.id}`,\n\t\t})),\n\t];\n\tconst selected = await ctx.ui.custom<string | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Model for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { model: selected ?? undefined }, getAgentDir());\n}\n\nasync function pickThinking(\n\tctx: ExtensionCommandContext,\n\tprofileName: string,\n\toverride: SubagentProfileOverride | undefined,\n\tparentThinking: string,\n): Promise<void> {\n\tconst model = effectiveModelFor(ctx, override);\n\tconst levels = model ? (getSupportedThinkingLevels(model) as ThinkingLevel[]) : [...THINKING_LEVELS];\n\tconst items: PickerItem<ThinkingLevel | null>[] = [\n\t\t{\n\t\t\tvalue: null,\n\t\t\tlabel: \"inherit\",\n\t\t\tdetail: `Follow the parent session (${parentThinking})`,\n\t\t\tcurrent: !override?.thinking,\n\t\t},\n\t\t...levels.map((level) => ({ value: level, label: level, current: override?.thinking === level })),\n\t];\n\tconst selected = await ctx.ui.custom<ThinkingLevel | null | undefined>(\n\t\t(_tui, theme, _keybindings, done) => new SearchPickerComponent(theme, `Thinking for ${profileName}`, items, done),\n\t);\n\tif (selected === undefined) return;\n\tawait updateProfileOverride(profileName, { thinking: selected ?? undefined }, getAgentDir());\n}\n\nasync function configureProfile(\n\tctx: ExtensionCommandContext,\n\tagent: AgentDefinition,\n\tparentThinking: string,\n): Promise<void> {\n\tconst agentDir = getAgentDir();\n\twhile (true) {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst override = config.profiles[agent.name];\n\t\tconst effective = effectiveSettings(override, ctx, parentThinking);\n\t\tconst action = await ctx.ui.select(`${agent.name} — ${agent.description}`, [\n\t\t\t`Model: ${effective.model}`,\n\t\t\t`Thinking: ${effective.thinking}`,\n\t\t\t\"Back\",\n\t\t]);\n\t\tif (!action || action === \"Back\") return;\n\t\tif (action.startsWith(\"Model:\")) {\n\t\t\tawait pickModel(ctx, agent.name, override);\n\t\t\tcontinue;\n\t\t}\n\t\tawait pickThinking(ctx, agent.name, override, parentThinking);\n\t}\n}\n\nasync function syncParentProviders(\n\truntime: ModelRuntime,\n\tregistry: ModelRegistry,\n\tsyncedIds: Set<string>,\n): Promise<void> {\n\tconst nextIds = new Set(registry.getRegisteredProviderIds());\n\tfor (const id of syncedIds) {\n\t\tif (!nextIds.has(id)) runtime.unregisterProvider(id);\n\t}\n\tfor (const id of nextIds) {\n\t\tconst native = registry.getRegisteredNativeProvider(id);\n\t\tif (native) runtime.registerNativeProvider(native);\n\t\telse {\n\t\t\tconst config = registry.getRegisteredProviderConfig(id);\n\t\t\tif (config) runtime.registerProvider(id, config);\n\t\t}\n\t\tconst auth = await registry.getProviderAuth(id);\n\t\tif (auth?.auth.apiKey) await runtime.setRuntimeApiKey(id, auth.auth.apiKey, { allowNetwork: false });\n\t}\n\tsyncedIds.clear();\n\tfor (const id of nextIds) syncedIds.add(id);\n}\n\nasync function showAgentsCommand(ctx: ExtensionCommandContext, parentThinking: string): Promise<void> {\n\tif (!ctx.hasUI) {\n\t\tctx.ui.notify(\"/agents requires an interactive UI.\", \"warning\");\n\t\treturn;\n\t}\n\tconst agentDir = getAgentDir();\n\tconst reset = \"Reset all overrides\";\n\tconst done = \"Done\";\n\twhile (true) {\n\t\tconst discovery = discoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir });\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst rows = discovery.agents.map((agent) => {\n\t\t\tconst effective = effectiveSettings(config.profiles[agent.name], ctx, parentThinking);\n\t\t\treturn `${agent.name} — model: ${effective.model} · thinking: ${effective.thinking}`;\n\t\t});\n\t\tconst issueCount = discovery.diagnostics.length;\n\t\tconst issues = issueCount ? [`Show ${issueCount} agent file issue${issueCount === 1 ? \"\" : \"s\"}`] : [];\n\t\tconst action = await ctx.ui.select(\"Subagent profiles — select one to configure\", [\n\t\t\t...rows,\n\t\t\t...issues,\n\t\t\treset,\n\t\t\tdone,\n\t\t]);\n\t\tif (!action || action === done) return;\n\t\tif (action === reset) {\n\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\"Reset profile overrides?\",\n\t\t\t\t\"Clear every saved Subagent model and thinking override?\",\n\t\t\t);\n\t\t\tif (confirmed) {\n\t\t\t\tawait resetProfileOverrides(agentDir);\n\t\t\t\tctx.ui.notify(\"All profiles now inherit the parent session.\", \"info\");\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (issues.length > 0 && action === issues[0]) {\n\t\t\tctx.ui.notify(\n\t\t\t\tdiscovery.diagnostics.map((diagnostic) => `${diagnostic.path}: ${diagnostic.message}`).join(\"\\n\"),\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tconst agent = discovery.agents.find((candidate) => action.startsWith(`${candidate.name} — `));\n\t\tif (agent) await configureProfile(ctx, agent, parentThinking);\n\t}\n}\n\nexport default function subagent(pi: ExtensionAPI): void {\n\tconst gate = new ConcurrencyGate();\n\tconst activeAborters = new Set<() => Promise<void>>();\n\tconst syncedProviderIds = new Set<string>();\n\tlet modelRuntimePromise: Promise<ModelRuntime> | undefined;\n\n\tconst getModelRuntime = async (ctx: ExtensionContext): Promise<ModelRuntime> => {\n\t\tif (!modelRuntimePromise) {\n\t\t\tconst agentDir = getAgentDir();\n\t\t\tconst created = ModelRuntime.create({\n\t\t\t\tauthPath: join(agentDir, \"auth.json\"),\n\t\t\t\tmodelsPath: join(agentDir, \"models.json\"),\n\t\t\t});\n\t\t\t// A transient failure (network, filesystem) must not brick the tool\n\t\t\t// for the rest of the session: drop the rejected promise so the\n\t\t\t// next invocation retries creation.\n\t\t\tcreated.catch(() => {\n\t\t\t\tif (modelRuntimePromise === created) modelRuntimePromise = undefined;\n\t\t\t});\n\t\t\tmodelRuntimePromise = created;\n\t\t}\n\t\tconst runtime = await modelRuntimePromise;\n\t\tawait syncParentProviders(runtime, ctx.modelRegistry, syncedProviderIds);\n\t\treturn runtime;\n\t};\n\n\tconst registerSubagentTool = (discovery: AgentDiscoveryResult): void => {\n\t\tpi.registerTool<typeof SubagentParamsSchema, SubagentDetails>({\n\t\t\tname: SUBAGENT_TOOL_NAME,\n\t\t\tlabel: SUBAGENT_TOOL_LABEL,\n\t\t\tdescription: subagentToolDescription(discovery),\n\t\t\trendersOwnProgress: true,\n\t\t\trenderRefreshIntervalMs: 1000,\n\t\t\tpromptSnippet: \"Delegate focused research, review, or implementation tasks to isolated subagents\",\n\t\t\tpromptGuidelines: [\n\t\t\t\t\"Use subagent when a bounded task benefits from isolated context or parallel investigation; choose a profile and write its briefing using the tool description.\",\n\t\t\t],\n\t\t\tparameters: SubagentParamsSchema,\n\t\t\tasync execute(_toolCallId, params, signal, onUpdate, ctx): Promise<AgentToolResult<SubagentDetails>> {\n\t\t\t\t// First paint before any await: model-runtime creation and task\n\t\t\t\t// resolution can stall on first use (network, filesystem), and\n\t\t\t\t// the transcript card must not sit empty while they do.\n\t\t\t\tonUpdate?.({\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Initializing…\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: params.tasks ? \"parallel\" : \"single\",\n\t\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\t\truns: [],\n\t\t\t\t\t\tstartedAt: Date.now(),\n\t\t\t\t\t\tusage: emptyUsage(),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tconst discovery = discoverAgents(ctx.cwd, {\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t});\n\t\t\t\tconst runtime = await getModelRuntime(ctx);\n\t\t\t\tconst parent: ParentModelContext = {\n\t\t\t\t\tmodel: ctx.model,\n\t\t\t\t\tthinking: pi.getThinkingLevel(),\n\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t};\n\t\t\t\tconst execution = await runSubagentInvocation({\n\t\t\t\t\tparams,\n\t\t\t\t\tparentCwd: ctx.cwd,\n\t\t\t\t\tagents: discovery.agents,\n\t\t\t\t\tparent,\n\t\t\t\t\tmodelRuntime: runtime,\n\t\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\t\t\tsignal,\n\t\t\t\t\tgate,\n\t\t\t\t\tonUpdate: (details) => {\n\t\t\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: statusSummary(details) }], details });\n\t\t\t\t\t},\n\t\t\t\t\tregisterAbort: (abort) => {\n\t\t\t\t\t\tactiveAborters.add(abort);\n\t\t\t\t\t\treturn () => activeAborters.delete(abort);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: execution.content }],\n\t\t\t\t\tdetails: execution.details,\n\t\t\t\t\tusage: execution.usage,\n\t\t\t\t};\n\t\t\t},\n\t\t\trenderCall(args, theme) {\n\t\t\t\treturn renderSubagentCall(args, theme);\n\t\t\t},\n\t\t\trenderResult(result, options, theme, context) {\n\t\t\t\treturn renderSubagentResult(result, options, theme, context.isError);\n\t\t\t},\n\t\t});\n\t};\n\n\tregisterSubagentTool(discoverAgents(process.cwd(), { projectTrusted: false, agentDir: getAgentDir() }));\n\tpi.on(\"session_start\", (_event, ctx) => {\n\t\tregisterSubagentTool(\n\t\t\tdiscoverAgents(ctx.cwd, { projectTrusted: ctx.isProjectTrusted(), agentDir: getAgentDir() }),\n\t\t);\n\t});\n\n\tpi.registerCommand(SUBAGENT_COMMAND_NAME, {\n\t\tdescription: \"Configure Subagent profiles, models, and thinking levels\",\n\t\thandler: async (_args, ctx) => showAgentsCommand(ctx, pi.getThinkingLevel()),\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== SUBAGENT_TOOL_NAME) return;\n\t\tconst details = event.details as SubagentDetails | undefined;\n\t\tif (details && isSubagentError(details)) return { isError: true };\n\t});\n\n\tpi.on(\"session_shutdown\", async () => {\n\t\tawait Promise.allSettled([...activeAborters].map((abort) => abort()));\n\t\tactiveAborters.clear();\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAqC,MAAM,wBAAwB,CAAC;AAC3F,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAE/F,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAEtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAyC,MAAM,YAAY,CAAC;AAuezF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,CAqBhF;AAED,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,EACxC,OAAO,EAAE,uBAAuB,EAChC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,GACd,SAAS,CA0DX","sourcesContent":["import { type Component, Container, Markdown, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentToolResult, ToolRenderResultOptions } from \"../../core/extensions/types.ts\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getMarkdownTheme, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { statusSummary } from \"./runner.ts\";\nimport type { SubagentParams } from \"./schema.ts\";\nimport type { SubagentDetails, SubagentRunDetails, SubagentRunStatus } from \"./types.ts\";\n\nconst SINGLE_EXCERPT_LIMIT = 200;\nconst RUN_LINE_EXCERPT_LIMIT = 64;\nconst LIVE_TAIL_LIMIT = 100;\nconst COLLAPSED_RUN_LIMIT = 4;\nconst PROMPT_PREVIEW_LINES = 2;\nconst PROMPT_PREVIEW_LINE_LIMIT = 120;\nconst ACTIVITY_SUMMARY_LIMIT = 96;\nconst ACTIVITY_RESULT_LIMIT = 64;\n// Sub-10s tool calls are routine; a duration only earns ink when it\n// explains where the time went.\nconst ACTIVITY_DURATION_MIN_MS = 10_000;\nconst EXPANDED_LIVE_TAIL_LINES = 3;\n\n// Display-only: profile names stay lowercase everywhere the model sees\n// them; the transcript shows \"general\" as \"General\", \"code-reviewer\" as\n// \"Code Reviewer\".\nfunction displayAgentName(name: string): string {\n\treturn name\n\t\t.split(/[-_]/u)\n\t\t.filter(Boolean)\n\t\t.map((word) => `${word[0]?.toUpperCase() ?? \"\"}${word.slice(1)}`)\n\t\t.join(\" \");\n}\n\nfunction singleAgentName(args: { agent?: string | null }): string {\n\treturn displayAgentName(args.agent ?? \"general\");\n}\n\nfunction truncate(text: string, limit: number): string {\n\treturn text.length <= limit ? text : `${text.slice(0, Math.max(0, limit - 1))}…`;\n}\n\n// Transcript excerpts render inside plain Text components, so markdown\n// punctuation would show up literally; strip the common inline syntax.\nfunction stripInlineMarkdown(text: string): string {\n\treturn text\n\t\t.replace(/```[a-zA-Z0-9-]*/gu, \"\")\n\t\t.replace(/`([^`]*)`/gu, \"$1\")\n\t\t.replace(/\\*\\*([^*]+)\\*\\*/gu, \"$1\")\n\t\t.replace(/__([^_]+)__/gu, \"$1\")\n\t\t.replace(/\\[([^\\]]+)\\]\\([^)]*\\)/gu, \"$1\")\n\t\t.replace(/^#{1,6}\\s+/gmu, \"\");\n}\n\n// Markdown tables and horizontal rules turn into symbol soup when\n// flattened onto one line; drop those lines before inline stripping.\nfunction stripBlockMarkdown(text: string): string {\n\treturn text\n\t\t.split(\"\\n\")\n\t\t.filter((line) => {\n\t\t\tconst trimmed = line.trim();\n\t\t\tif (trimmed.startsWith(\"|\")) return false;\n\t\t\treturn !(trimmed.length >= 3 && /^[-—─═=*_|:\\s]+$/u.test(trimmed));\n\t\t})\n\t\t.join(\"\\n\");\n}\n\n// finalOutput/liveText carry model-facing truncation notices from\n// boundText/tailText. Only recognize their exact boundary lines so literal\n// discussion of the marker remains visible in the transcript.\nconst OUTPUT_TRUNCATION_NOTICE_PATTERN = /^\\[Output truncated(?:: \\d+ bytes omitted)?\\.\\]$/u;\nconst EARLIER_OUTPUT_NOTICE = \"[Earlier output omitted.]\";\n\nfunction terminalOutputNotice(text: string): { text: string; truncated: boolean } {\n\tconst lines = text.split(\"\\n\");\n\tlet index = lines.length - 1;\n\twhile (index >= 0 && !lines[index]?.trim()) index--;\n\tif (index < 0 || !OUTPUT_TRUNCATION_NOTICE_PATTERN.test(lines[index]?.trim() ?? \"\")) {\n\t\treturn { text, truncated: false };\n\t}\n\tlines.splice(index, 1);\n\treturn { text: lines.join(\"\\n\").trimEnd(), truncated: true };\n}\n\nfunction replaceBoundaryNotices(text: string): string {\n\tconst lines = text.split(\"\\n\");\n\tconst first = lines.findIndex((line) => Boolean(line.trim()));\n\tif (first >= 0 && lines[first]?.trim() === EARLIER_OUTPUT_NOTICE) lines[first] = \"…\";\n\tlet last = lines.length - 1;\n\twhile (last >= 0 && !lines[last]?.trim()) last--;\n\tif (last >= 0 && OUTPUT_TRUNCATION_NOTICE_PATTERN.test(lines[last]?.trim() ?? \"\")) lines[last] = \"…\";\n\treturn lines.join(\"\\n\");\n}\n\nfunction plainExcerpt(text: string, limit: number): string {\n\treturn truncate(stripInlineMarkdown(stripBlockMarkdown(text)).replace(/\\s+/gu, \" \").trim(), limit);\n}\n\nfunction excerpt(text: string, limit: number): string {\n\treturn plainExcerpt(replaceBoundaryNotices(text), limit);\n}\n\n// Generated notice-only boundary lines must never become the live line the\n// user watches; identical text in the body remains ordinary model output.\nfunction liveTailLines(run: SubagentRunDetails): string[] {\n\tconst { text } = terminalOutputNotice(run.liveText);\n\tconst lines = text\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter(Boolean);\n\tif (lines[0] === EARLIER_OUTPUT_NOTICE) lines.shift();\n\treturn lines;\n}\n\nfunction liveTail(run: SubagentRunDetails): string | undefined {\n\tconst last = liveTailLines(run).at(-1);\n\treturn last ? excerpt(last, LIVE_TAIL_LIMIT) : undefined;\n}\n\n// Completed-run excerpts read better cut at a sentence boundary than\n// mid-word; fall back to a hard truncate when no boundary lands in the\n// second half of the window.\nfunction leadingSentences(text: string, limit: number): string {\n\tconst cleaned = excerpt(text, Number.MAX_SAFE_INTEGER);\n\tif (cleaned.length <= limit) return cleaned;\n\tconst window = cleaned.slice(0, limit);\n\tlet boundary = -1;\n\tfor (const match of window.matchAll(/[.!?。!?](?=\\s|$)/gu)) {\n\t\tboundary = (match.index ?? 0) + match[0].length;\n\t}\n\tif (boundary >= limit / 2) return window.slice(0, boundary).trimEnd();\n\treturn truncate(window, limit);\n}\n\nconst VERIFY_COMMAND_PATTERN = /\\b(test|lint|typecheck|tsc|vitest|jest|pytest|build|check|fmt|format|compile)\\b/iu;\nconst INSPECT_COMMAND_PATTERN = /\\b(rg|grep|find|git (?:diff|status|log|show)|ls|tree|cat|head|tail)\\b/iu;\nconst RETRY_MARKER_PATTERN = /^Retrying\\b/u;\nconst STREAM_MARKERS = new Set([\"Thinking…\", \"Writing response…\"]);\n\n// Translates raw tool traffic into what the worker is doing right now, so\n// the collapsed card reads as a phase instead of a command line. Modelled\n// on tool-type classification; the raw tool summary stays as evidence on\n// the next line.\nfunction runIntent(run: SubagentRunDetails): string {\n\tconst current = run.currentActivity;\n\tif (current && RETRY_MARKER_PATTERN.test(current)) return current;\n\tconst running = [...run.activities].reverse().find((activity) => activity.status === \"running\");\n\tif (running) {\n\t\tif (running.toolName === \"edit\" || running.toolName === \"write\") return \"Applying changes\";\n\t\tif (running.toolName === \"bash\") {\n\t\t\tif (VERIFY_COMMAND_PATTERN.test(running.summary)) return \"Verifying changes\";\n\t\t\treturn INSPECT_COMMAND_PATTERN.test(running.summary) ? \"Exploring code\" : \"Running commands\";\n\t\t}\n\t\treturn \"Exploring code\";\n\t}\n\tconst recent = run.activities.slice(-5);\n\tif (current && STREAM_MARKERS.has(current)) {\n\t\tif (recent.some((activity) => activity.status === \"failed\")) return \"Investigating a failure\";\n\t\treturn current;\n\t}\n\tif (recent.some((activity) => activity.status === \"failed\")) return \"Investigating a failure\";\n\tif (recent.some((activity) => activity.toolName === \"edit\" || activity.toolName === \"write\"))\n\t\treturn \"Reviewing changes\";\n\tif (recent.length > 0) return \"Exploring code\";\n\treturn current ?? \"Thinking…\";\n}\n\n// The raw tool summary backs up the intent line; suppress it when it would\n// just repeat a stream/retry marker.\nfunction runEvidence(run: SubagentRunDetails): string | undefined {\n\tconst current = run.currentActivity;\n\tif (!current || STREAM_MARKERS.has(current) || RETRY_MARKER_PATTERN.test(current)) return undefined;\n\treturn current;\n}\n\nfunction liveElapsed(run: SubagentRunDetails): string | undefined {\n\tif (run.startedAt === undefined) return undefined;\n\tconst end = run.endedAt ?? Date.now();\n\treturn formatDuration(Math.max(0, (end - run.startedAt) / 1000));\n}\n\nfunction statusColor(status: SubagentRunStatus): \"success\" | \"error\" | \"warning\" | \"accent\" | \"muted\" {\n\tswitch (status) {\n\t\tcase \"completed\":\n\t\t\treturn \"success\";\n\t\tcase \"failed\":\n\t\t\treturn \"error\";\n\t\tcase \"aborted\":\n\t\t\treturn \"warning\";\n\t\tcase \"running\":\n\t\t\treturn \"accent\";\n\t\tdefault:\n\t\t\treturn \"muted\";\n\t}\n}\n\n// The tool shell already paints a call-level status dot (● in\n// warning/success/error), so `●` is off-limits here: `›` marks where the\n// work currently is, and the remaining glyphs are terminal states.\nfunction statusMarker(status: SubagentRunStatus, theme: Theme): string {\n\tconst glyph =\n\t\tstatus === \"completed\"\n\t\t\t? \"✓\"\n\t\t\t: status === \"failed\"\n\t\t\t\t? \"×\"\n\t\t\t\t: status === \"aborted\"\n\t\t\t\t\t? \"■\"\n\t\t\t\t\t: status === \"running\"\n\t\t\t\t\t\t? \"›\"\n\t\t\t\t\t\t: \"○\";\n\treturn theme.fg(statusColor(status), glyph);\n}\n\nfunction statusWord(status: SubagentRunStatus): string {\n\tswitch (status) {\n\t\tcase \"completed\":\n\t\t\treturn \"Completed\";\n\t\tcase \"failed\":\n\t\t\treturn \"Failed\";\n\t\tcase \"aborted\":\n\t\t\treturn \"Aborted\";\n\t\tcase \"running\":\n\t\t\treturn \"Running\";\n\t\tdefault:\n\t\t\treturn \"Queued\";\n\t}\n}\n\nfunction runTitle(run: SubagentRunDetails, theme: Theme, index?: number): string {\n\tconst number = index === undefined ? \"\" : theme.fg(\"dim\", `${index} · `);\n\treturn `${statusMarker(run.status, theme)} ${number}${theme.fg(\"accent\", displayAgentName(run.agent))}${theme.fg(\"dim\", ` · ${truncate(run.description, 48)}`)}`;\n}\n\n// Mid-run token totals are cache-inflated (totalTokens sums cache reads\n// across turns), so live lines quote tool uses and the context watermark\n// instead; settled lines get the real total.\nfunction runProgressText(run: SubagentRunDetails): string {\n\tconst items = [`${run.usage.toolUses} tool use${run.usage.toolUses === 1 ? \"\" : \"s\"}`];\n\tif (run.usage.contextTokens) items.push(`ctx:${formatTokens(run.usage.contextTokens)}`);\n\treturn items.join(\" · \");\n}\n\nfunction runLine(run: SubagentRunDetails, theme: Theme, index?: number): string {\n\tlet line = runTitle(run, theme, index);\n\tconst detail =\n\t\trun.status === \"running\"\n\t\t\t? runIntent(run)\n\t\t\t: run.status === \"failed\" || run.status === \"aborted\"\n\t\t\t\t? run.error && excerpt(run.error, RUN_LINE_EXCERPT_LIMIT)\n\t\t\t\t: run.finalOutput && excerpt(run.finalOutput, RUN_LINE_EXCERPT_LIMIT);\n\tif (detail) line += theme.fg(run.status === \"failed\" ? \"error\" : \"dim\", ` — ${detail}`);\n\tif (run.status === \"running\") {\n\t\tline += theme.fg(\"dim\", ` · ${runProgressText(run)}`);\n\t\tconst elapsed = liveElapsed(run);\n\t\tif (elapsed) line += theme.fg(\"dim\", ` · ${elapsed}`);\n\t}\n\tconst settled = run.status !== \"running\" && run.status !== \"queued\";\n\tif (settled && run.startedAt !== undefined && run.endedAt !== undefined) {\n\t\tline += theme.fg(\"dim\", ` · ${formatDuration(Math.max(0, (run.endedAt - run.startedAt) / 1000))}`);\n\t}\n\treturn line;\n}\n\n// Keep active work visible while a batch is in flight: completed runs\n// may otherwise crowd a still-running task out of the collapsed window.\nfunction selectCollapsedRuns(runs: SubagentRunDetails[], isPartial: boolean): SubagentRunDetails[] {\n\tif (runs.length <= COLLAPSED_RUN_LIMIT) return runs;\n\tif (!isPartial) return runs.slice(0, COLLAPSED_RUN_LIMIT);\n\tconst active = runs.filter((run) => run.status === \"running\" || run.status === \"queued\");\n\tconst settled = runs.filter((run) => run.status !== \"running\" && run.status !== \"queued\");\n\treturn [...active, ...settled].slice(0, COLLAPSED_RUN_LIMIT);\n}\n\nfunction singleCollapsedLines(details: SubagentDetails, theme: Theme): string[] {\n\tconst run = details.runs[0];\n\tif (!run) return [theme.fg(\"muted\", \"Initializing…\")];\n\tif (run.status === \"running\" || run.status === \"queued\") {\n\t\tconst isInitializing =\n\t\t\trun.status === \"running\" && run.usage.turns === 0 && run.usage.toolUses === 0 && run.liveText.length === 0;\n\t\tconst intent =\n\t\t\trun.status === \"queued\"\n\t\t\t\t? (run.currentActivity ?? \"queued\")\n\t\t\t\t: isInitializing\n\t\t\t\t\t? \"Initializing…\"\n\t\t\t\t\t: runIntent(run);\n\t\t// No status marker here: the shell's call-level dot already covers\n\t\t// the whole card, and a single run has nothing to disambiguate.\n\t\tlet status = theme.fg(\"dim\", intent);\n\t\tif (run.status === \"running\" && !isInitializing) {\n\t\t\tstatus += theme.fg(\"dim\", ` · ${runProgressText(run)}`);\n\t\t\tif (run.usage.cost) status += theme.fg(\"dim\", ` · $${run.usage.cost.toFixed(3)}`);\n\t\t\tconst elapsed = liveElapsed(run);\n\t\t\tif (elapsed) status += theme.fg(\"dim\", ` · ${elapsed}`);\n\t\t}\n\t\tconst lines = [status];\n\t\tconst evidence = runEvidence(run);\n\t\tif (evidence && evidence !== intent)\n\t\t\tlines.push(`${theme.fg(\"accent\", \"›\")} ${theme.fg(\"dim\", excerpt(evidence, LIVE_TAIL_LIMIT))}`);\n\t\tconst tail = liveTail(run);\n\t\tif (tail) lines.push(theme.fg(\"dim\", tail));\n\t\treturn lines;\n\t}\n\tif (run.error) return [theme.fg(\"error\", excerpt(run.error, SINGLE_EXCERPT_LIMIT))];\n\tif (run.finalOutput) return [theme.fg(\"toolOutput\", leadingSentences(run.finalOutput, SINGLE_EXCERPT_LIMIT))];\n\treturn [theme.fg(\"muted\", run.status)];\n}\n\n// Deep-trimmed settled footer: turns and per-run breakdowns belong to the\n// expanded view. Parallel batches keep only whole-call numbers — the run\n// rows above already localize the work.\nfunction collapsedUsageText(details: SubagentDetails, extended: boolean): string {\n\tconst usage = details.usage;\n\tconst items: string[] = [];\n\tif (usage.totalTokens) items.push(`${formatTokens(usage.totalTokens)} tok`);\n\tif (extended && usage.toolUses) items.push(`${usage.toolUses} tool use${usage.toolUses === 1 ? \"\" : \"s\"}`);\n\tif (extended && usage.contextTokens) items.push(`ctx:${formatTokens(usage.contextTokens)}`);\n\tif (usage.cost) items.push(`$${usage.cost.toFixed(3)}`);\n\tif (details.endedAt !== undefined) {\n\t\titems.push(formatDuration(Math.max(0, (details.endedAt - details.startedAt) / 1000)));\n\t}\n\treturn items.join(\" · \");\n}\n\nfunction batchUsageText(details: SubagentDetails, isPartial: boolean): string {\n\tconst usage = details.usage;\n\tconst items: string[] = [];\n\t// The aggregate mixes settled and running runs while partial, and the\n\t// running share is cache-inflated — quote the total only once settled.\n\tif (!isPartial && usage.totalTokens) items.push(`${formatTokens(usage.totalTokens)} tok`);\n\tif (usage.toolUses) items.push(`${usage.toolUses} tool use${usage.toolUses === 1 ? \"\" : \"s\"}`);\n\tif (usage.turns) items.push(`${usage.turns} turn${usage.turns === 1 ? \"\" : \"s\"}`);\n\tif (usage.contextTokens) items.push(`ctx:${formatTokens(usage.contextTokens)}`);\n\tif (usage.cost) items.push(`$${usage.cost.toFixed(3)}`);\n\tif (details.endedAt !== undefined) {\n\t\titems.push(formatDuration(Math.max(0, (details.endedAt - details.startedAt) / 1000)));\n\t}\n\treturn items.join(\" · \");\n}\n\nfunction formatTokens(value: number): string {\n\tif (value < 1_000) return String(value);\n\tif (value < 1_000_000) return `${(value / 1_000).toFixed(value < 10_000 ? 1 : 0)}k`;\n\treturn `${(value / 1_000_000).toFixed(1)}M`;\n}\n\nfunction formatDuration(seconds: number): string {\n\tif (seconds >= 90) return `${Math.floor(seconds / 60)}m ${Math.round(seconds % 60)}s`;\n\treturn `${seconds.toFixed(seconds < 10 ? 1 : 0)}s`;\n}\n\nfunction runDurationText(run: SubagentRunDetails): string | undefined {\n\tif (run.startedAt === undefined || run.endedAt === undefined) return undefined;\n\treturn formatDuration(Math.max(0, (run.endedAt - run.startedAt) / 1000));\n}\n\n// One dim line per run: what it cost. Settled runs quote the real token\n// total; running runs skip it (cache-inflated mid-run) and tick elapsed\n// time instead. Batch sections fold model/thinking/cwd in here because\n// their `──` header already carries verdict and duration.\nfunction runMetricsText(run: SubagentRunDetails, includeIdentity: boolean): string {\n\tconst usage = run.usage;\n\tconst settled = run.status !== \"running\" && run.status !== \"queued\";\n\tconst items: string[] = [];\n\tif (includeIdentity) {\n\t\titems.push(run.model);\n\t\tif (run.thinking !== \"off\") items.push(run.thinking);\n\t\tif (run.cwd) items.push(`cwd: ${run.cwd}`);\n\t}\n\tif (settled && usage.totalTokens) items.push(`${formatTokens(usage.totalTokens)} tok`);\n\tif (usage.toolUses) items.push(`${usage.toolUses} tool use${usage.toolUses === 1 ? \"\" : \"s\"}`);\n\tif (usage.turns) items.push(`${usage.turns} turn${usage.turns === 1 ? \"\" : \"s\"}`);\n\tif (usage.contextTokens) items.push(`ctx:${formatTokens(usage.contextTokens)}`);\n\tif (usage.cost) items.push(`$${usage.cost.toFixed(3)}`);\n\tconst duration = settled ? (includeIdentity ? undefined : runDurationText(run)) : liveElapsed(run);\n\tif (duration) items.push(duration);\n\treturn items.join(\" · \");\n}\n\n// The details prompt is a 1KB bounded copy of the briefing; the preview\n// shows the first content lines (blank lines carry nothing at two lines\n// of budget) and never pretends to more fidelity than that.\nfunction promptSection(run: SubagentRunDetails, theme: Theme): string[] {\n\tconst boundedPrompt = terminalOutputNotice(run.prompt);\n\tconst lines = boundedPrompt.text\n\t\t.split(\"\\n\")\n\t\t.map((line) => plainExcerpt(line.trim(), Number.MAX_SAFE_INTEGER))\n\t\t.filter(Boolean);\n\tconst shown = lines.slice(0, PROMPT_PREVIEW_LINES);\n\tconst preview = shown.map((line) => theme.fg(\"dim\", truncate(line, PROMPT_PREVIEW_LINE_LIMIT)));\n\t// A one-line briefing clipped mid-sentence must still say it continues.\n\tconst clipped = shown.some((line) => line.length > PROMPT_PREVIEW_LINE_LIMIT);\n\tconst remaining = lines.length - shown.length;\n\tconst capped = boundedPrompt.truncated;\n\tconst section = [theme.fg(\"muted\", \"Prompt\"), ...preview];\n\tif (remaining > 0 || capped || clipped) {\n\t\tlet note = \"… continues\";\n\t\tif (remaining > 0) note += `, ${remaining} more line${remaining === 1 ? \"\" : \"s\"}`;\n\t\tif (capped) note += \" · capped at 1KB\";\n\t\tsection.push(theme.fg(\"muted\", note));\n\t}\n\treturn section;\n}\n\n// Each run expands into a report cover sheet: verdict and cost up top, a\n// bounded Prompt/Activity digest in the middle, then the full Report —\n// the one unbounded element, placed last so the card ends where reading\n// begins. Single runs skip the `──` header (the call header already names\n// them); batch sections carry a numbered header matching the contents\n// list above.\nfunction renderRunDetails(run: SubagentRunDetails, theme: Theme, single: boolean, index?: number): Component {\n\tconst container = new Container();\n\tconst settled = run.status !== \"running\" && run.status !== \"queued\";\n\tif (single) {\n\t\tconst identity = [run.model];\n\t\tif (run.thinking !== \"off\") identity.push(`${run.thinking} thinking`);\n\t\tif (run.cwd) identity.push(`cwd: ${run.cwd}`);\n\t\tcontainer.addChild(\n\t\t\tnew Text(\n\t\t\t\t`${statusMarker(run.status, theme)} ${theme.fg(statusColor(run.status), statusWord(run.status))}${theme.fg(\"dim\", ` · ${identity.join(\" · \")}`)}`,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t} else {\n\t\tconst label = index === undefined ? \"\" : `${index} `;\n\t\tconst duration = settled ? runDurationText(run) : undefined;\n\t\tcontainer.addChild(\n\t\t\tnew Text(\n\t\t\t\t`${theme.fg(\"dim\", `── ${label}`)}${statusMarker(run.status, theme)} ${theme.fg(\"accent\", displayAgentName(run.agent))}${theme.fg(\"dim\", ` · ${truncate(run.description, 48)}`)}${duration ? theme.fg(\"dim\", ` · ${duration}`) : \"\"}`,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t}\n\tif (run.status !== \"queued\") {\n\t\tconst metrics = runMetricsText(run, !single);\n\t\tif (metrics) container.addChild(new Text(theme.fg(\"dim\", metrics), 0, 0));\n\t}\n\tcontainer.addChild(new Spacer(1));\n\tfor (const line of promptSection(run, theme)) container.addChild(new Text(line, 0, 0));\n\tif (run.activities.length > 0) {\n\t\tcontainer.addChild(new Spacer(1));\n\t\tconst total = run.usage.toolUses;\n\t\tconst label = total > run.activities.length ? `Activity · last ${run.activities.length} of ${total}` : \"Activity\";\n\t\tcontainer.addChild(new Text(theme.fg(\"muted\", label), 0, 0));\n\t\tfor (const activity of run.activities) {\n\t\t\t// Deviation earns ink: × and › are marked, success rows are quiet\n\t\t\t// one-liners without result echoes.\n\t\t\tlet text: string;\n\t\t\tif (activity.status === \"failed\") {\n\t\t\t\ttext = `${theme.fg(\"error\", \"×\")} ${theme.fg(\"toolOutput\", excerpt(activity.summary, ACTIVITY_SUMMARY_LIMIT))}`;\n\t\t\t\tif (activity.resultSummary) {\n\t\t\t\t\ttext += ` ${theme.fg(\"error\", `· ${excerpt(activity.resultSummary, ACTIVITY_RESULT_LIMIT)}`)}`;\n\t\t\t\t}\n\t\t\t} else if (activity.status === \"running\") {\n\t\t\t\ttext = `${theme.fg(\"accent\", \"›\")} ${theme.fg(\"toolOutput\", excerpt(activity.summary, ACTIVITY_SUMMARY_LIMIT))}`;\n\t\t\t} else {\n\t\t\t\ttext = theme.fg(\"toolOutput\", excerpt(activity.summary, ACTIVITY_SUMMARY_LIMIT));\n\t\t\t}\n\t\t\tif (activity.endedAt !== undefined && activity.endedAt - activity.startedAt >= ACTIVITY_DURATION_MIN_MS) {\n\t\t\t\ttext += ` ${theme.fg(\"dim\", `· ${formatDuration((activity.endedAt - activity.startedAt) / 1000)}`)}`;\n\t\t\t}\n\t\t\tcontainer.addChild(new Text(text, 0, 0));\n\t\t}\n\t}\n\t// The live tail is the \"now\" end of the timeline; once the run settles,\n\t// Report takes this slot without moving anything above it.\n\tif (run.status === \"running\" && run.liveText) {\n\t\tconst tail = liveTailLines(run).slice(-EXPANDED_LIVE_TAIL_LINES);\n\t\tif (tail.length > 0) {\n\t\t\tcontainer.addChild(new Spacer(1));\n\t\t\tcontainer.addChild(new Text(theme.fg(\"muted\", \"Working\"), 0, 0));\n\t\t\tfor (const line of tail) {\n\t\t\t\tcontainer.addChild(new Text(theme.fg(\"dim\", excerpt(line, LIVE_TAIL_LIMIT)), 0, 0));\n\t\t\t}\n\t\t}\n\t}\n\tif (run.error) {\n\t\tcontainer.addChild(new Spacer(1));\n\t\tcontainer.addChild(new Text(theme.fg(\"muted\", \"Error\"), 0, 0));\n\t\tcontainer.addChild(new Text(theme.fg(\"error\", run.error), 0, 0));\n\t}\n\tif (run.finalOutput) {\n\t\tcontainer.addChild(new Spacer(1));\n\t\tconst label = settled && run.status !== \"completed\" ? \"Report · partial\" : \"Report\";\n\t\tcontainer.addChild(new Text(theme.fg(\"muted\", label), 0, 0));\n\t\tcontainer.addChild(new Markdown(run.finalOutput, 0, 0, getMarkdownTheme()));\n\t}\n\treturn container;\n}\n\n// The call header stays a single line: run rows in the result area take\n// over within the first update and carry richer per-task state, so a\n// task list here would render everything twice. The task count alone\n// distinguishes a batch from a single delegation.\nexport function renderSubagentCall(args: SubagentParams, theme: Theme): Component {\n\tconst modes = [args.prompt != null && \"prompt\", args.tasks != null && \"tasks\"].filter((mode): mode is string =>\n\t\tBoolean(mode),\n\t);\n\tif (modes.length > 1) {\n\t\treturn new Text(\n\t\t\t`${theme.fg(\"toolTitle\", theme.bold(\"Subagent \"))}${theme.fg(\"error\", `invalid · ${modes.join(\" + \")}`)}`,\n\t\t\t0,\n\t\t\t0,\n\t\t);\n\t}\n\tif (args.tasks) {\n\t\treturn new Text(\n\t\t\t`${theme.fg(\"toolTitle\", theme.bold(\"Multi-Agent\"))}${theme.fg(\"dim\", ` · ${args.tasks.length} task${args.tasks.length === 1 ? \"\" : \"s\"}`)}`,\n\t\t\t0,\n\t\t\t0,\n\t\t);\n\t}\n\tlet text = theme.fg(\"toolTitle\", theme.bold(`${singleAgentName(args)} Agent`));\n\tif (args.description) text += theme.fg(\"dim\", ` · ${truncate(args.description, 72)}`);\n\treturn new Text(text, 0, 0);\n}\n\nexport function renderSubagentResult(\n\tresult: AgentToolResult<SubagentDetails>,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tisError: boolean,\n): Component {\n\tconst details = result.details;\n\tif (!details) {\n\t\tconst text = result.content.find((part) => part.type === \"text\");\n\t\treturn new Text(text?.type === \"text\" ? text.text : \"(no output)\", 0, 0);\n\t}\n\t// The pre-resolution first paint carries no runs yet, in either mode.\n\tif (details.runs.length === 0) {\n\t\treturn new Text(theme.fg(\"muted\", \"Initializing…\"), 0, 0);\n\t}\n\tif (!options.expanded) {\n\t\tconst lines: string[] = [];\n\t\tif (details.mode === \"single\") {\n\t\t\tlines.push(...singleCollapsedLines(details, theme));\n\t\t} else {\n\t\t\tlet header = statusSummary(details);\n\t\t\tif (options.isPartial) {\n\t\t\t\theader += ` · ${formatDuration(Math.max(0, (Date.now() - details.startedAt) / 1000))}`;\n\t\t\t}\n\t\t\tlines.push(theme.fg(isError ? \"error\" : options.isPartial ? \"accent\" : \"muted\", header));\n\t\t\tconst shown = selectCollapsedRuns(details.runs, Boolean(options.isPartial));\n\t\t\t// Stable ordinals (the run's task position, not its display slot)\n\t\t\t// keep identity readable while active-first ordering reshuffles\n\t\t\t// rows, and match the expanded section numbers.\n\t\t\tfor (const run of shown) lines.push(runLine(run, theme, details.runs.indexOf(run) + 1));\n\t\t\tconst hidden = details.runs.length - shown.length;\n\t\t\tif (hidden > 0) lines.push(theme.fg(\"muted\", `+${hidden} more`));\n\t\t}\n\t\tif (!options.isPartial) {\n\t\t\tconst usage = collapsedUsageText(details, details.mode === \"single\");\n\t\t\tif (usage) lines.push(theme.fg(\"dim\", usage));\n\t\t\tlines.push(theme.fg(\"muted\", `(${keyHint(\"app.tools.expand\", \"to expand\")})`));\n\t\t}\n\t\treturn new Text(lines.join(\"\\n\"), 0, 0);\n\t}\n\tconst container = new Container();\n\tconst single = details.mode === \"single\" && details.runs.length === 1;\n\tif (!single) {\n\t\tcontainer.addChild(new Text(theme.fg(isError ? \"error\" : \"toolTitle\", statusSummary(details)), 0, 0));\n\t\t// Numbered table of contents: the TUI cannot jump, but matching the\n\t\t// numbers against the `──` section headers below makes an 8-run\n\t\t// batch navigable by eye.\n\t\tdetails.runs.forEach((run, index) => {\n\t\t\tcontainer.addChild(new Text(runLine(run, theme, index + 1), 0, 0));\n\t\t});\n\t}\n\tdetails.runs.forEach((run, index) => {\n\t\tif (!single || index > 0) container.addChild(new Spacer(1));\n\t\tcontainer.addChild(renderRunDetails(run, theme, single, single ? undefined : index + 1));\n\t});\n\tif (!single) {\n\t\tconst usage = batchUsageText(details, Boolean(options.isPartial));\n\t\tif (usage) {\n\t\t\tcontainer.addChild(new Spacer(1));\n\t\t\tcontainer.addChild(new Text(theme.fg(\"dim\", usage), 0, 0));\n\t\t}\n\t}\n\treturn container;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAqC,MAAM,wBAAwB,CAAC;AAC3F,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAE/F,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAGtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAyC,MAAM,YAAY,CAAC;AA8iBzF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,CAqBhF;AAED,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,EACxC,OAAO,EAAE,uBAAuB,EAChC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,GACd,SAAS,CAgEX","sourcesContent":["import { type Component, Container, Markdown, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentToolResult, ToolRenderResultOptions } from \"../../core/extensions/types.ts\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { getMarkdownTheme, type Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { getSubagentRetryView } from \"./retry.ts\";\nimport { statusSummary } from \"./runner.ts\";\nimport type { SubagentParams } from \"./schema.ts\";\nimport type { SubagentDetails, SubagentRunDetails, SubagentRunStatus } from \"./types.ts\";\n\nconst SINGLE_EXCERPT_LIMIT = 200;\nconst RUN_LINE_EXCERPT_LIMIT = 96;\nconst RUN_ERROR_EXCERPT_LIMIT = 200;\nconst RETRY_ERROR_EXCERPT_LIMIT = 160;\nconst LIVE_TAIL_LIMIT = 100;\nconst COLLAPSED_RUN_LIMIT = 4;\nconst PROMPT_PREVIEW_LINES = 2;\nconst PROMPT_PREVIEW_LINE_LIMIT = 120;\nconst ACTIVITY_SUMMARY_LIMIT = 96;\nconst ACTIVITY_RESULT_LIMIT = 64;\n// Sub-10s tool calls are routine; a duration only earns ink when it\n// explains where the time went.\nconst ACTIVITY_DURATION_MIN_MS = 10_000;\nconst EXPANDED_LIVE_TAIL_LINES = 3;\n\nclass IndentedText implements Component {\n\tprivate readonly text: Text;\n\tprivate readonly indent: number;\n\n\tconstructor(text: string, indent: number) {\n\t\tthis.text = new Text(text, 0, 0);\n\t\tthis.indent = indent;\n\t}\n\n\trender(width: number): string[] {\n\t\tconst indent = Math.min(this.indent, Math.max(0, width - 1));\n\t\tconst prefix = \" \".repeat(indent);\n\t\treturn this.text.render(Math.max(1, width - indent)).map((line) => `${prefix}${line}`);\n\t}\n\n\tinvalidate(): void {\n\t\tthis.text.invalidate();\n\t}\n}\n\n// Display-only: profile names stay lowercase everywhere the model sees\n// them; the transcript shows \"general\" as \"General\", \"code-reviewer\" as\n// \"Code Reviewer\".\nfunction displayAgentName(name: string): string {\n\treturn name\n\t\t.split(/[-_]/u)\n\t\t.filter(Boolean)\n\t\t.map((word) => `${word[0]?.toUpperCase() ?? \"\"}${word.slice(1)}`)\n\t\t.join(\" \");\n}\n\nfunction singleAgentName(args: { agent?: string | null }): string {\n\treturn displayAgentName(args.agent ?? \"general\");\n}\n\nfunction truncate(text: string, limit: number): string {\n\treturn text.length <= limit ? text : `${text.slice(0, Math.max(0, limit - 1))}…`;\n}\n\n// Transcript excerpts render inside plain Text components, so markdown\n// punctuation would show up literally; strip the common inline syntax.\nfunction stripInlineMarkdown(text: string): string {\n\treturn text\n\t\t.replace(/```[a-zA-Z0-9-]*/gu, \"\")\n\t\t.replace(/`([^`]*)`/gu, \"$1\")\n\t\t.replace(/\\*\\*([^*]+)\\*\\*/gu, \"$1\")\n\t\t.replace(/__([^_]+)__/gu, \"$1\")\n\t\t.replace(/\\[([^\\]]+)\\]\\([^)]*\\)/gu, \"$1\")\n\t\t.replace(/^#{1,6}\\s+/gmu, \"\");\n}\n\n// Markdown tables and horizontal rules turn into symbol soup when\n// flattened onto one line; drop those lines before inline stripping.\nfunction stripBlockMarkdown(text: string): string {\n\treturn text\n\t\t.split(\"\\n\")\n\t\t.filter((line) => {\n\t\t\tconst trimmed = line.trim();\n\t\t\tif (trimmed.startsWith(\"|\")) return false;\n\t\t\treturn !(trimmed.length >= 3 && /^[-—─═=*_|:\\s]+$/u.test(trimmed));\n\t\t})\n\t\t.join(\"\\n\");\n}\n\n// finalOutput/liveText carry model-facing truncation notices from\n// boundText/tailText. Only recognize their exact boundary lines so literal\n// discussion of the marker remains visible in the transcript.\nconst OUTPUT_TRUNCATION_NOTICE_PATTERN = /^\\[Output truncated(?:: \\d+ bytes omitted)?\\.\\]$/u;\nconst EARLIER_OUTPUT_NOTICE = \"[Earlier output omitted.]\";\n\nfunction terminalOutputNotice(text: string): { text: string; truncated: boolean } {\n\tconst lines = text.split(\"\\n\");\n\tlet index = lines.length - 1;\n\twhile (index >= 0 && !lines[index]?.trim()) index--;\n\tif (index < 0 || !OUTPUT_TRUNCATION_NOTICE_PATTERN.test(lines[index]?.trim() ?? \"\")) {\n\t\treturn { text, truncated: false };\n\t}\n\tlines.splice(index, 1);\n\treturn { text: lines.join(\"\\n\").trimEnd(), truncated: true };\n}\n\nfunction replaceBoundaryNotices(text: string): string {\n\tconst lines = text.split(\"\\n\");\n\tconst first = lines.findIndex((line) => Boolean(line.trim()));\n\tif (first >= 0 && lines[first]?.trim() === EARLIER_OUTPUT_NOTICE) lines[first] = \"…\";\n\tlet last = lines.length - 1;\n\twhile (last >= 0 && !lines[last]?.trim()) last--;\n\tif (last >= 0 && OUTPUT_TRUNCATION_NOTICE_PATTERN.test(lines[last]?.trim() ?? \"\")) lines[last] = \"…\";\n\treturn lines.join(\"\\n\");\n}\n\nfunction plainExcerpt(text: string, limit: number): string {\n\treturn truncate(stripInlineMarkdown(stripBlockMarkdown(text)).replace(/\\s+/gu, \" \").trim(), limit);\n}\n\nfunction excerpt(text: string, limit: number): string {\n\treturn plainExcerpt(replaceBoundaryNotices(text), limit);\n}\n\n// Generated notice-only boundary lines must never become the live line the\n// user watches; identical text in the body remains ordinary model output.\nfunction liveTailLines(run: SubagentRunDetails): string[] {\n\tconst { text } = terminalOutputNotice(run.liveText);\n\tconst lines = text\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter(Boolean);\n\tif (lines[0] === EARLIER_OUTPUT_NOTICE) lines.shift();\n\treturn lines;\n}\n\nfunction liveTail(run: SubagentRunDetails): string | undefined {\n\tconst last = liveTailLines(run).at(-1);\n\treturn last ? excerpt(last, LIVE_TAIL_LIMIT) : undefined;\n}\n\n// Completed-run excerpts read better cut at a sentence boundary than\n// mid-word; fall back to a hard truncate when no boundary lands in the\n// second half of the window.\nfunction leadingSentences(text: string, limit: number): string {\n\tconst cleaned = excerpt(text, Number.MAX_SAFE_INTEGER);\n\tif (cleaned.length <= limit) return cleaned;\n\tconst window = cleaned.slice(0, limit);\n\tlet boundary = -1;\n\tfor (const match of window.matchAll(/[.!?。!?](?=\\s|$)/gu)) {\n\t\tboundary = (match.index ?? 0) + match[0].length;\n\t}\n\tif (boundary >= limit / 2) return window.slice(0, boundary).trimEnd();\n\treturn truncate(cleaned, limit);\n}\n\nconst VERIFY_COMMAND_PATTERN = /\\b(test|lint|typecheck|tsc|vitest|jest|pytest|build|check|fmt|format|compile)\\b/iu;\nconst INSPECT_COMMAND_PATTERN = /\\b(rg|grep|find|git (?:diff|status|log|show)|ls|tree|cat|head|tail)\\b/iu;\nconst RETRY_MARKER_PATTERN = /^Retrying\\b/u;\nconst STREAM_MARKERS = new Set([\"Thinking…\", \"Writing response…\"]);\n\nfunction retryText(run: SubagentRunDetails): string | undefined {\n\tconst retry = getSubagentRetryView(run);\n\tif (!retry) return undefined;\n\tconst status =\n\t\tretry.remainingSeconds > 0\n\t\t\t? `Retrying (${retry.attempt}/${retry.maxAttempts}) in ${retry.remainingSeconds}s`\n\t\t\t: `Retrying now… (${retry.attempt}/${retry.maxAttempts})`;\n\tconst error = excerpt(retry.error, RETRY_ERROR_EXCERPT_LIMIT);\n\treturn error ? `${status} — ${error}` : status;\n}\n\n// Translates raw tool traffic into what the worker is doing right now, so\n// the collapsed card reads as a phase instead of a command line. Modelled\n// on tool-type classification; the raw tool summary stays as evidence on\n// the next line.\nfunction runIntent(run: SubagentRunDetails): string {\n\tconst retry = retryText(run);\n\tif (retry) return retry;\n\tconst current = run.currentActivity;\n\tif (current && RETRY_MARKER_PATTERN.test(current)) return current;\n\tconst running = [...run.activities].reverse().find((activity) => activity.status === \"running\");\n\tif (running) {\n\t\tif (running.toolName === \"edit\" || running.toolName === \"write\") return \"Applying changes\";\n\t\tif (running.toolName === \"bash\") {\n\t\t\tif (VERIFY_COMMAND_PATTERN.test(running.summary)) return \"Verifying changes\";\n\t\t\treturn INSPECT_COMMAND_PATTERN.test(running.summary) ? \"Exploring code\" : \"Running commands\";\n\t\t}\n\t\treturn \"Exploring code\";\n\t}\n\tconst recent = run.activities.slice(-5);\n\tif (current && STREAM_MARKERS.has(current)) {\n\t\tif (recent.some((activity) => activity.status === \"failed\")) return \"Investigating a failure\";\n\t\treturn current;\n\t}\n\tif (recent.some((activity) => activity.status === \"failed\")) return \"Investigating a failure\";\n\tif (recent.some((activity) => activity.toolName === \"edit\" || activity.toolName === \"write\"))\n\t\treturn \"Reviewing changes\";\n\tif (recent.length > 0) return \"Exploring code\";\n\treturn current ?? \"Thinking…\";\n}\n\n// The raw tool summary backs up the intent line; suppress it when it would\n// just repeat a stream/retry marker.\nfunction runEvidence(run: SubagentRunDetails): string | undefined {\n\tif (getSubagentRetryView(run)) return undefined;\n\tconst current = run.currentActivity;\n\tif (!current || STREAM_MARKERS.has(current) || RETRY_MARKER_PATTERN.test(current)) return undefined;\n\treturn current;\n}\n\nfunction liveElapsed(run: SubagentRunDetails): string | undefined {\n\tif (run.startedAt === undefined) return undefined;\n\tconst end = run.endedAt ?? Date.now();\n\treturn formatDuration(Math.max(0, (end - run.startedAt) / 1000));\n}\n\nfunction statusColor(status: SubagentRunStatus): \"success\" | \"error\" | \"warning\" | \"accent\" | \"muted\" {\n\tswitch (status) {\n\t\tcase \"completed\":\n\t\t\treturn \"success\";\n\t\tcase \"failed\":\n\t\t\treturn \"error\";\n\t\tcase \"aborted\":\n\t\t\treturn \"warning\";\n\t\tcase \"running\":\n\t\t\treturn \"accent\";\n\t\tdefault:\n\t\t\treturn \"muted\";\n\t}\n}\n\n// The tool shell already paints a call-level status dot (● in\n// warning/success/error), so `●` is off-limits here: `›` marks where the\n// work currently is, and the remaining glyphs are terminal states.\nfunction statusMarker(status: SubagentRunStatus, theme: Theme): string {\n\tconst glyph =\n\t\tstatus === \"completed\"\n\t\t\t? \"✓\"\n\t\t\t: status === \"failed\"\n\t\t\t\t? \"×\"\n\t\t\t\t: status === \"aborted\"\n\t\t\t\t\t? \"■\"\n\t\t\t\t\t: status === \"running\"\n\t\t\t\t\t\t? \"›\"\n\t\t\t\t\t\t: \"○\";\n\treturn theme.fg(statusColor(status), glyph);\n}\n\nfunction statusWord(status: SubagentRunStatus): string {\n\tswitch (status) {\n\t\tcase \"completed\":\n\t\t\treturn \"Completed\";\n\t\tcase \"failed\":\n\t\t\treturn \"Failed\";\n\t\tcase \"aborted\":\n\t\t\treturn \"Aborted\";\n\t\tcase \"running\":\n\t\t\treturn \"Running\";\n\t\tdefault:\n\t\t\treturn \"Queued\";\n\t}\n}\n\nfunction runTitle(run: SubagentRunDetails, theme: Theme, index?: number): string {\n\tconst number = index === undefined ? \"\" : theme.fg(\"dim\", `${index} · `);\n\treturn `${statusMarker(run.status, theme)} ${number}${theme.fg(\"accent\", displayAgentName(run.agent))}${theme.fg(\"dim\", ` · ${truncate(run.description, 48)}`)}`;\n}\n\n// Mid-run token totals are cache-inflated (totalTokens sums cache reads\n// across turns), so live lines quote tool uses and the context watermark\n// instead; settled lines get the real total.\nfunction runProgressText(run: SubagentRunDetails): string {\n\tconst items = [`${run.usage.toolUses} tool use${run.usage.toolUses === 1 ? \"\" : \"s\"}`];\n\tif (run.usage.contextTokens) items.push(`ctx: ${formatTokens(run.usage.contextTokens)}`);\n\treturn items.join(\" · \");\n}\n\nfunction runLine(run: SubagentRunDetails, theme: Theme, index?: number): string {\n\tlet line = runTitle(run, theme, index);\n\tconst retry = retryText(run);\n\tconst detail =\n\t\tretry ??\n\t\t(run.status === \"running\"\n\t\t\t? excerpt(runIntent(run), LIVE_TAIL_LIMIT)\n\t\t\t: run.status === \"failed\" || run.status === \"aborted\"\n\t\t\t\t? undefined\n\t\t\t\t: run.finalOutput && leadingSentences(run.finalOutput, RUN_LINE_EXCERPT_LIMIT));\n\tif (detail) line += theme.fg(\"dim\", ` — ${detail}`);\n\tif (run.status === \"running\") {\n\t\tline += theme.fg(\"dim\", ` · ${runProgressText(run)}`);\n\t\tif (run.usage.cost) line += theme.fg(\"dim\", ` · $${run.usage.cost.toFixed(3)}`);\n\t\tconst elapsed = liveElapsed(run);\n\t\tif (elapsed) line += theme.fg(\"dim\", ` · ${elapsed}`);\n\t}\n\tconst settled = run.status !== \"running\" && run.status !== \"queued\";\n\tif (settled && run.startedAt !== undefined && run.endedAt !== undefined) {\n\t\tline += theme.fg(\"dim\", ` · ${formatDuration(Math.max(0, (run.endedAt - run.startedAt) / 1000))}`);\n\t}\n\treturn line;\n}\n\nfunction runErrorExcerpt(run: SubagentRunDetails): string | undefined {\n\tif ((run.status !== \"failed\" && run.status !== \"aborted\") || !run.error) return undefined;\n\treturn leadingSentences(run.error, RUN_ERROR_EXCERPT_LIMIT);\n}\n\nfunction runErrorIndent(index?: number): number {\n\treturn index === undefined ? 2 : 5 + String(index).length;\n}\n\nfunction addRunSummary(container: Container, run: SubagentRunDetails, theme: Theme, index?: number): void {\n\tcontainer.addChild(new Text(runLine(run, theme, index), 0, 0));\n\tconst error = runErrorExcerpt(run);\n\tif (error) container.addChild(new IndentedText(theme.fg(\"error\", error), runErrorIndent(index)));\n}\n\n// Keep active work visible while a batch is in flight: completed runs\n// may otherwise crowd a still-running task out of the collapsed window.\nfunction selectCollapsedRuns(runs: SubagentRunDetails[], isPartial: boolean): SubagentRunDetails[] {\n\tif (runs.length <= COLLAPSED_RUN_LIMIT) return runs;\n\tif (!isPartial) return runs.slice(0, COLLAPSED_RUN_LIMIT);\n\tconst active = runs.filter((run) => run.status === \"running\" || run.status === \"queued\");\n\tconst retrying = active.filter((run) => getSubagentRetryView(run));\n\tconst retryingSet = new Set(retrying);\n\tconst otherActive = active.filter((run) => !retryingSet.has(run));\n\tconst settled = runs.filter((run) => run.status !== \"running\" && run.status !== \"queued\");\n\treturn [...retrying, ...otherActive, ...settled].slice(0, COLLAPSED_RUN_LIMIT);\n}\n\nfunction singleCollapsedLines(details: SubagentDetails, theme: Theme): string[] {\n\tconst run = details.runs[0];\n\tif (!run) return [theme.fg(\"muted\", \"Initializing…\")];\n\tif (run.status === \"running\" || run.status === \"queued\") {\n\t\tconst retry = retryText(run);\n\t\tconst isInitializing =\n\t\t\trun.status === \"running\" &&\n\t\t\t!retry &&\n\t\t\trun.usage.turns === 0 &&\n\t\t\trun.usage.toolUses === 0 &&\n\t\t\trun.liveText.length === 0;\n\t\tconst rawIntent =\n\t\t\tretry ??\n\t\t\t(run.status === \"queued\"\n\t\t\t\t? (run.currentActivity ?? statusWord(run.status))\n\t\t\t\t: isInitializing\n\t\t\t\t\t? \"Initializing…\"\n\t\t\t\t\t: runIntent(run));\n\t\tconst intent = excerpt(rawIntent, LIVE_TAIL_LIMIT);\n\t\t// No status marker here: the shell's call-level dot already covers\n\t\t// the whole card, and a single run has nothing to disambiguate.\n\t\tlet status = theme.fg(\"dim\", intent);\n\t\tif (run.status === \"running\" && !isInitializing) {\n\t\t\tstatus += theme.fg(\"dim\", ` · ${runProgressText(run)}`);\n\t\t\tif (run.usage.cost) status += theme.fg(\"dim\", ` · $${run.usage.cost.toFixed(3)}`);\n\t\t\tconst elapsed = liveElapsed(run);\n\t\t\tif (elapsed) status += theme.fg(\"dim\", ` · ${elapsed}`);\n\t\t}\n\t\tconst lines = [status];\n\t\tconst evidence = runEvidence(run);\n\t\tif (evidence && evidence !== rawIntent)\n\t\t\tlines.push(`${theme.fg(\"accent\", \"›\")} ${theme.fg(\"dim\", excerpt(evidence, LIVE_TAIL_LIMIT))}`);\n\t\tconst tail = liveTail(run);\n\t\tif (tail) lines.push(theme.fg(\"dim\", tail));\n\t\treturn lines;\n\t}\n\tif (run.error) return [theme.fg(\"error\", excerpt(run.error, SINGLE_EXCERPT_LIMIT))];\n\tif (run.finalOutput) return [theme.fg(\"toolOutput\", leadingSentences(run.finalOutput, SINGLE_EXCERPT_LIMIT))];\n\treturn [theme.fg(\"muted\", statusWord(run.status))];\n}\n\n// Deep-trimmed settled footer: turns and per-run breakdowns belong to the\n// expanded view. Parallel batches keep only whole-call numbers — the run\n// rows above already localize the work.\nfunction collapsedUsageText(details: SubagentDetails, extended: boolean): string {\n\tconst usage = details.usage;\n\tconst items: string[] = [];\n\tif (usage.totalTokens) items.push(`${formatTokens(usage.totalTokens)} tok`);\n\tif (extended && usage.toolUses) items.push(`${usage.toolUses} tool use${usage.toolUses === 1 ? \"\" : \"s\"}`);\n\tif (extended && usage.contextTokens) items.push(`ctx: ${formatTokens(usage.contextTokens)}`);\n\tif (usage.cost) items.push(`$${usage.cost.toFixed(3)}`);\n\tif (details.endedAt !== undefined) {\n\t\titems.push(formatDuration(Math.max(0, (details.endedAt - details.startedAt) / 1000)));\n\t}\n\treturn items.join(\" · \");\n}\n\nfunction batchUsageText(details: SubagentDetails, isPartial: boolean): string {\n\tconst usage = details.usage;\n\tconst items: string[] = [];\n\t// The aggregate mixes settled and running runs while partial, and the\n\t// running share is cache-inflated — quote the total only once settled.\n\tif (!isPartial && usage.totalTokens) items.push(`${formatTokens(usage.totalTokens)} tok`);\n\tif (usage.toolUses) items.push(`${usage.toolUses} tool use${usage.toolUses === 1 ? \"\" : \"s\"}`);\n\tif (usage.turns) items.push(`${usage.turns} turn${usage.turns === 1 ? \"\" : \"s\"}`);\n\tif (usage.contextTokens) items.push(`ctx: ${formatTokens(usage.contextTokens)}`);\n\tif (usage.cost) items.push(`$${usage.cost.toFixed(3)}`);\n\tif (details.endedAt !== undefined) {\n\t\titems.push(formatDuration(Math.max(0, (details.endedAt - details.startedAt) / 1000)));\n\t}\n\treturn items.join(\" · \");\n}\n\nfunction formatTokens(value: number): string {\n\tif (value < 1_000) return String(value);\n\tif (value < 1_000_000) return `${(value / 1_000).toFixed(value < 10_000 ? 1 : 0)}k`;\n\treturn `${(value / 1_000_000).toFixed(1)}M`;\n}\n\nfunction formatDuration(seconds: number): string {\n\tconst roundedSeconds = Math.round(seconds);\n\tif (roundedSeconds >= 60) return `${Math.floor(roundedSeconds / 60)}m ${roundedSeconds % 60}s`;\n\treturn `${seconds.toFixed(seconds < 10 ? 1 : 0)}s`;\n}\n\nfunction runDurationText(run: SubagentRunDetails): string | undefined {\n\tif (run.startedAt === undefined || run.endedAt === undefined) return undefined;\n\treturn formatDuration(Math.max(0, (run.endedAt - run.startedAt) / 1000));\n}\n\n// One dim line per run: what it cost. Settled runs quote the real token\n// total; running runs skip it (cache-inflated mid-run) and tick elapsed\n// time instead. Batch sections fold model/thinking/cwd in here because\n// their `──` header already carries verdict and duration.\nfunction runMetricsText(run: SubagentRunDetails, includeIdentity: boolean): string {\n\tconst usage = run.usage;\n\tconst settled = run.status !== \"running\" && run.status !== \"queued\";\n\tconst items: string[] = [];\n\tif (includeIdentity) {\n\t\titems.push(run.model);\n\t\tif (run.thinking !== \"off\") items.push(run.thinking);\n\t\tif (run.cwd) items.push(`cwd: ${run.cwd}`);\n\t}\n\tif (settled && usage.totalTokens) items.push(`${formatTokens(usage.totalTokens)} tok`);\n\tif (usage.toolUses) items.push(`${usage.toolUses} tool use${usage.toolUses === 1 ? \"\" : \"s\"}`);\n\tif (usage.turns) items.push(`${usage.turns} turn${usage.turns === 1 ? \"\" : \"s\"}`);\n\tif (usage.contextTokens) items.push(`ctx: ${formatTokens(usage.contextTokens)}`);\n\tif (usage.cost) items.push(`$${usage.cost.toFixed(3)}`);\n\tconst duration = settled ? (includeIdentity ? undefined : runDurationText(run)) : liveElapsed(run);\n\tif (duration) items.push(duration);\n\treturn items.join(\" · \");\n}\n\n// The details prompt is a 1KB bounded copy of the briefing; the preview\n// shows the first content lines (blank lines carry nothing at two lines\n// of budget) and never pretends to more fidelity than that.\nfunction promptSection(run: SubagentRunDetails, theme: Theme): string[] {\n\tconst boundedPrompt = terminalOutputNotice(run.prompt);\n\tconst lines = boundedPrompt.text\n\t\t.split(\"\\n\")\n\t\t.map((line) => plainExcerpt(line.trim(), Number.MAX_SAFE_INTEGER))\n\t\t.filter(Boolean);\n\tconst shown = lines.slice(0, PROMPT_PREVIEW_LINES);\n\tconst preview = shown.map((line) => theme.fg(\"dim\", truncate(line, PROMPT_PREVIEW_LINE_LIMIT)));\n\t// A one-line briefing clipped mid-sentence must still say it continues.\n\tconst clipped = shown.some((line) => line.length > PROMPT_PREVIEW_LINE_LIMIT);\n\tconst remaining = lines.length - shown.length;\n\tconst capped = boundedPrompt.truncated;\n\tconst section = [theme.fg(\"muted\", \"Prompt\"), ...preview];\n\tif (remaining > 0 || capped || clipped) {\n\t\tlet note = \"… continues\";\n\t\tif (remaining > 0) note += `, ${remaining} more line${remaining === 1 ? \"\" : \"s\"}`;\n\t\tif (capped) note += \" · capped at 1KB\";\n\t\tsection.push(theme.fg(\"muted\", note));\n\t}\n\treturn section;\n}\n\n// Each run expands into a report cover sheet: verdict and cost up top, a\n// bounded Prompt/Activity digest in the middle, then the full Report —\n// the one unbounded element, placed last so the card ends where reading\n// begins. Single runs skip the `──` header (the call header already names\n// them); batch sections carry a numbered header matching the contents\n// list above.\nfunction renderRunDetails(run: SubagentRunDetails, theme: Theme, single: boolean, index?: number): Component {\n\tconst container = new Container();\n\tconst settled = run.status !== \"running\" && run.status !== \"queued\";\n\tif (single) {\n\t\tconst identity = [run.model];\n\t\tif (run.thinking !== \"off\") identity.push(`${run.thinking} thinking`);\n\t\tif (run.cwd) identity.push(`cwd: ${run.cwd}`);\n\t\tcontainer.addChild(\n\t\t\tnew Text(\n\t\t\t\t`${statusMarker(run.status, theme)} ${theme.fg(statusColor(run.status), statusWord(run.status))}${theme.fg(\"dim\", ` · ${identity.join(\" · \")}`)}`,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t} else {\n\t\tconst label = index === undefined ? \"\" : `${index} · `;\n\t\tconst duration = settled ? runDurationText(run) : undefined;\n\t\tcontainer.addChild(\n\t\t\tnew Text(\n\t\t\t\t`${theme.fg(\"dim\", `── ${label}`)}${statusMarker(run.status, theme)} ${theme.fg(\"accent\", displayAgentName(run.agent))}${theme.fg(\"dim\", ` · ${truncate(run.description, 48)}`)}${duration ? theme.fg(\"dim\", ` · ${duration}`) : \"\"}`,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t}\n\tif (run.status !== \"queued\") {\n\t\tconst metrics = runMetricsText(run, !single);\n\t\tif (metrics) container.addChild(new Text(theme.fg(\"dim\", metrics), 0, 0));\n\t}\n\tconst retry = retryText(run);\n\tif (retry) container.addChild(new Text(theme.fg(\"accent\", retry), 0, 0));\n\tcontainer.addChild(new Spacer(1));\n\tfor (const line of promptSection(run, theme)) container.addChild(new Text(line, 0, 0));\n\tif (run.activities.length > 0) {\n\t\tcontainer.addChild(new Spacer(1));\n\t\tconst total = run.usage.toolUses;\n\t\tconst label = total > run.activities.length ? `Activity · last ${run.activities.length} of ${total}` : \"Activity\";\n\t\tcontainer.addChild(new Text(theme.fg(\"muted\", label), 0, 0));\n\t\tfor (const activity of run.activities) {\n\t\t\t// Deviation earns ink: × and › are marked, success rows are quiet\n\t\t\t// one-liners without result echoes.\n\t\t\tlet text: string;\n\t\t\tif (activity.status === \"failed\") {\n\t\t\t\ttext = `${theme.fg(\"error\", \"×\")} ${theme.fg(\"toolOutput\", excerpt(activity.summary, ACTIVITY_SUMMARY_LIMIT))}`;\n\t\t\t\tif (activity.resultSummary) {\n\t\t\t\t\ttext += ` ${theme.fg(\"error\", `· ${excerpt(activity.resultSummary, ACTIVITY_RESULT_LIMIT)}`)}`;\n\t\t\t\t}\n\t\t\t} else if (activity.status === \"running\") {\n\t\t\t\ttext = `${theme.fg(\"accent\", \"›\")} ${theme.fg(\"toolOutput\", excerpt(activity.summary, ACTIVITY_SUMMARY_LIMIT))}`;\n\t\t\t} else {\n\t\t\t\ttext = ` ${theme.fg(\"toolOutput\", excerpt(activity.summary, ACTIVITY_SUMMARY_LIMIT))}`;\n\t\t\t}\n\t\t\tif (activity.endedAt !== undefined && activity.endedAt - activity.startedAt >= ACTIVITY_DURATION_MIN_MS) {\n\t\t\t\ttext += ` ${theme.fg(\"dim\", `· ${formatDuration((activity.endedAt - activity.startedAt) / 1000)}`)}`;\n\t\t\t}\n\t\t\tcontainer.addChild(new Text(text, 0, 0));\n\t\t}\n\t}\n\t// The live tail is the \"now\" end of the timeline; once the run settles,\n\t// Report takes this slot without moving anything above it.\n\tif (run.status === \"running\" && run.liveText) {\n\t\tconst tail = liveTailLines(run).slice(-EXPANDED_LIVE_TAIL_LINES);\n\t\tif (tail.length > 0) {\n\t\t\tcontainer.addChild(new Spacer(1));\n\t\t\tcontainer.addChild(new Text(theme.fg(\"muted\", \"Working\"), 0, 0));\n\t\t\tfor (const line of tail) {\n\t\t\t\tcontainer.addChild(new Text(theme.fg(\"dim\", excerpt(line, LIVE_TAIL_LIMIT)), 0, 0));\n\t\t\t}\n\t\t}\n\t}\n\tif (run.error) {\n\t\tcontainer.addChild(new Spacer(1));\n\t\tcontainer.addChild(new Text(theme.fg(\"muted\", \"Error\"), 0, 0));\n\t\tcontainer.addChild(new Text(theme.fg(\"error\", run.error), 0, 0));\n\t}\n\tif (run.finalOutput) {\n\t\tcontainer.addChild(new Spacer(1));\n\t\tconst label = settled && run.status !== \"completed\" ? \"Report · partial\" : \"Report\";\n\t\tcontainer.addChild(new Text(theme.fg(\"muted\", label), 0, 0));\n\t\tcontainer.addChild(\n\t\t\tnew Markdown(run.finalOutput, 0, 0, getMarkdownTheme(), {\n\t\t\t\tcolor: (text) => theme.fg(\"toolOutput\", text),\n\t\t\t}),\n\t\t);\n\t}\n\treturn container;\n}\n\n// The call header stays a single line: run rows in the result area take\n// over within the first update and carry richer per-task state, so a\n// task list here would render everything twice. The task count alone\n// distinguishes a batch from a single delegation.\nexport function renderSubagentCall(args: SubagentParams, theme: Theme): Component {\n\tconst modes = [args.prompt != null && \"prompt\", args.tasks != null && \"tasks\"].filter((mode): mode is string =>\n\t\tBoolean(mode),\n\t);\n\tif (modes.length > 1) {\n\t\treturn new Text(\n\t\t\t`${theme.fg(\"toolTitle\", theme.bold(\"Subagent \"))}${theme.fg(\"error\", `invalid · ${modes.join(\" + \")}`)}`,\n\t\t\t0,\n\t\t\t0,\n\t\t);\n\t}\n\tif (args.tasks) {\n\t\treturn new Text(\n\t\t\t`${theme.fg(\"toolTitle\", theme.bold(\"Multi-Agent\"))}${theme.fg(\"dim\", ` · ${args.tasks.length} task${args.tasks.length === 1 ? \"\" : \"s\"}`)}`,\n\t\t\t0,\n\t\t\t0,\n\t\t);\n\t}\n\tlet text = theme.fg(\"toolTitle\", theme.bold(`${singleAgentName(args)} Agent`));\n\tif (args.description) text += theme.fg(\"dim\", ` · ${truncate(args.description, 72)}`);\n\treturn new Text(text, 0, 0);\n}\n\nexport function renderSubagentResult(\n\tresult: AgentToolResult<SubagentDetails>,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tisError: boolean,\n): Component {\n\tconst details = result.details;\n\tif (!details) {\n\t\tconst text = result.content.find((part) => part.type === \"text\");\n\t\treturn new Text(text?.type === \"text\" ? text.text : \"(no output)\", 0, 0);\n\t}\n\t// The pre-resolution first paint carries no runs yet, in either mode.\n\tif (details.runs.length === 0) {\n\t\treturn new Text(theme.fg(\"muted\", \"Initializing…\"), 0, 0);\n\t}\n\tif (!options.expanded) {\n\t\tif (details.mode === \"single\") {\n\t\t\tconst lines = singleCollapsedLines(details, theme);\n\t\t\tif (!options.isPartial) {\n\t\t\t\tconst usage = collapsedUsageText(details, true);\n\t\t\t\tif (usage) lines.push(theme.fg(\"dim\", usage));\n\t\t\t\tlines.push(theme.fg(\"muted\", `(${keyHint(\"app.tools.expand\", \"to expand\")})`));\n\t\t\t}\n\t\t\treturn new Text(lines.join(\"\\n\"), 0, 0);\n\t\t}\n\n\t\tconst container = new Container();\n\t\tlet header = statusSummary(details);\n\t\tif (options.isPartial) {\n\t\t\theader += ` · ${formatDuration(Math.max(0, (Date.now() - details.startedAt) / 1000))}`;\n\t\t}\n\t\tcontainer.addChild(new Text(theme.fg(isError ? \"error\" : options.isPartial ? \"accent\" : \"muted\", header), 0, 0));\n\t\tconst shown = selectCollapsedRuns(details.runs, Boolean(options.isPartial));\n\t\t// Stable ordinals (the run's task position, not its display slot)\n\t\t// keep identity readable while active-first ordering reshuffles\n\t\t// rows, and match the expanded section numbers.\n\t\tfor (const run of shown) addRunSummary(container, run, theme, details.runs.indexOf(run) + 1);\n\t\tconst hidden = details.runs.length - shown.length;\n\t\tif (hidden > 0) container.addChild(new Text(theme.fg(\"muted\", `+${hidden} more`), 0, 0));\n\t\tif (!options.isPartial) {\n\t\t\tconst usage = collapsedUsageText(details, false);\n\t\t\tif (usage) container.addChild(new Text(theme.fg(\"dim\", usage), 0, 0));\n\t\t\tcontainer.addChild(new Text(theme.fg(\"muted\", `(${keyHint(\"app.tools.expand\", \"to expand\")})`), 0, 0));\n\t\t}\n\t\treturn container;\n\t}\n\tconst container = new Container();\n\tconst single = details.mode === \"single\" && details.runs.length === 1;\n\tif (!single) {\n\t\tcontainer.addChild(new Text(theme.fg(isError ? \"error\" : \"toolTitle\", statusSummary(details)), 0, 0));\n\t\t// Numbered table of contents: the TUI cannot jump, but matching the\n\t\t// numbers against the `──` section headers below makes an 8-run\n\t\t// batch navigable by eye.\n\t\tdetails.runs.forEach((run, index) => {\n\t\t\taddRunSummary(container, run, theme, index + 1);\n\t\t});\n\t}\n\tdetails.runs.forEach((run, index) => {\n\t\tif (!single || index > 0) container.addChild(new Spacer(1));\n\t\tcontainer.addChild(renderRunDetails(run, theme, single, single ? undefined : index + 1));\n\t});\n\tif (!single) {\n\t\tconst usage = batchUsageText(details, Boolean(options.isPartial));\n\t\tif (usage) {\n\t\t\tcontainer.addChild(new Spacer(1));\n\t\t\tcontainer.addChild(new Text(theme.fg(\"dim\", usage), 0, 0));\n\t\t}\n\t}\n\treturn container;\n}\n"]}
|