dal-code 1.0.0 → 1.0.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 +67 -1
- package/dist/core/auth-guidance.d.ts +1 -0
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-guidance.js +6 -0
- package/dist/core/auth-guidance.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +4 -7
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +13 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +47 -48
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +46 -43
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +10 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +13 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/tools/bash.d.ts +3 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +61 -8
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +43 -6
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/dal/builtins.d.ts.map +1 -1
- package/dist/dal/builtins.js +1 -0
- package/dist/dal/builtins.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +12 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +22 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +2 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +24 -7
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +39 -2
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +200 -29
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +35 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +177 -23
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/tui-renderer.js +2 -2
- package/dist/modes/interactive/tui-renderer.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-bridge/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-gateway/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-halo/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/package.json +9 -6
- package/dist/node_modules/@dalcode/dal-mcp/src/add-wizard.ts +142 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/command-parser.ts +218 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/config-edit.ts +99 -0
- package/dist/node_modules/@dalcode/dal-mcp/src/index.ts +161 -18
- package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.ts +8 -3
- package/dist/node_modules/@dalcode/dal-office/LICENSE +21 -0
- package/dist/node_modules/@dalcode/dal-office/package.json +37 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/csv.ts +84 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/index.ts +111 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/ooxml.ts +109 -0
- package/dist/node_modules/@dalcode/dal-office/src/extract/pdf.ts +43 -0
- package/dist/node_modules/@dalcode/dal-office/src/index.ts +43 -0
- package/dist/node_modules/@dalcode/dal-office/src/paths.ts +107 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/chart.ts +111 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/docx.ts +155 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/pptx.ts +386 -0
- package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.ts +99 -0
- package/dist/node_modules/@dalcode/dal-office/src/scenes.ts +197 -0
- package/dist/node_modules/@dalcode/dal-office/src/scratchpad.ts +49 -0
- package/dist/node_modules/@dalcode/dal-office/src/themes.ts +240 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/chart-generate.ts +122 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/doc-generate.ts +123 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/drawio-generate.ts +99 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/md-generate.ts +76 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.ts +106 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.ts +91 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/read-file.ts +71 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/shared.ts +54 -0
- package/dist/node_modules/@dalcode/dal-office/src/tools/sheet-generate.ts +101 -0
- package/dist/node_modules/@dalcode/dal-office/src/truncate.ts +27 -0
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.d.ts.map +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +233 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.ts +322 -1
- package/dist/node_modules/@dalcode/dal-skills/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-skills/src/discover.ts +101 -0
- package/dist/node_modules/@dalcode/dal-skills/src/index.ts +71 -9
- package/dist/node_modules/@dalcode/dal-skills/src/install.ts +140 -0
- package/dist/node_modules/@dalcode/dal-skills/src/manage.ts +446 -0
- package/dist/node_modules/@dalcode/dal-skills/src/packages.ts +39 -1
- package/dist/node_modules/@dalcode/dal-subagent/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-subagent/src/index.ts +46 -4
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
- package/dist/node_modules/@dalcode/deepailab/package.json +4 -4
- package/dist/node_modules/@dalcode/deepailab/src/index.ts +7 -1
- package/dist/node_modules/@dalcode/deepailab/src/model-defaults.ts +42 -6
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +3 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js +3 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +23 -22
- package/dist/node_modules/@earendil-works/pi-tui/dist/fuzzy.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +4 -3
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +4 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/dist/utils/changelog.d.ts +37 -4
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +80 -17
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +13 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +1 -1
- package/npm-shrinkwrap.json +1511 -25
- package/package.json +8 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiC,MAAM,wBAAwB,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAiBxF;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAYhF;AAED;;;GAGG;AACH,qBAAa,eAAgB,YAAW,SAAS;IAChD,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAA6B;IAE/C,YAAY,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,0BAA0B,EAGxE;IAED,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAEtC;IAED,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAE5C;IAED;;;OAGG;IACH,UAAU,IAAI,IAAI,CAEjB;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI,CAEd;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAwH9B;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth, visibleWidth } from \"@earendil-works/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport { areExperimentalFeaturesEnabled } from \"../../../core/experimental.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { addUsageToTotals, createUsageTotals } from \"../../../core/usage-totals.ts\";\nimport { t } from \"../../../dal/i18n.ts\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\n/**\n * Format token counts for compact footer display.\n */\nexport function formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * No-op: git branch caching now handled by provider.\n\t * Kept for compatibility with existing call sites in interactive-mode.\n\t */\n\tinvalidate(): void {\n\t\t// No-op: git branch is cached/invalidated by provider\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\n\t\t// Calculate cumulative usage from ALL session entries (not just post-compaction messages)\n\t\tconst usageTotals = createUsageTotals();\n\t\tlet latestCacheHitRate: number | undefined;\n\n\t\tfor (const entry of this.session.sessionManager.getEntries()) {\n\t\t\tif (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\t\taddUsageToTotals(usageTotals, entry.message.usage);\n\n\t\t\t\tconst latestPromptTokens =\n\t\t\t\t\tentry.message.usage.input + entry.message.usage.cacheRead + entry.message.usage.cacheWrite;\n\t\t\t\tlatestCacheHitRate =\n\t\t\t\t\tlatestPromptTokens > 0 ? (entry.message.usage.cacheRead / latestPromptTokens) * 100 : undefined;\n\t\t\t} else if (entry.type === \"message\" && entry.message.role === \"toolResult\" && entry.message.usage) {\n\t\t\t\taddUsageToTotals(usageTotals, entry.message.usage);\n\t\t\t} else if ((entry.type === \"branch_summary\" || entry.type === \"compaction\") && entry.usage) {\n\t\t\t\taddUsageToTotals(usageTotals, entry.usage);\n\t\t\t}\n\t\t}\n\n\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\tconst contextUsage = this.session.getContextUsage();\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} · ${branch}`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} · ${sessionName}`;\n\t\t}\n\n\t\tconst dimPart = (text: string) => theme.fg(\"dim\", text);\n\t\tconst statsParts: string[] = [];\n\t\tif (usageTotals.input) statsParts.push(dimPart(`↑${formatTokens(usageTotals.input)}`));\n\t\tif (usageTotals.output) statsParts.push(dimPart(`↓${formatTokens(usageTotals.output)}`));\n\t\tif (usageTotals.cacheRead) statsParts.push(dimPart(`R${formatTokens(usageTotals.cacheRead)}`));\n\t\tif (usageTotals.cacheWrite) statsParts.push(dimPart(`W${formatTokens(usageTotals.cacheWrite)}`));\n\t\tif ((usageTotals.cacheRead > 0 || usageTotals.cacheWrite > 0) && latestCacheHitRate !== undefined) {\n\t\t\tstatsParts.push(dimPart(`CH${latestCacheHitRate.toFixed(1)}%`));\n\t\t}\n\n\t\t// Kimi Coding is subscription-backed despite using API-key authentication.\n\t\tconst usingSubscription = state.model\n\t\t\t? state.model.provider === \"kimi-coding\" || this.session.modelRuntime.isUsingSubscription(state.model.provider)\n\t\t\t: false;\n\t\tif (usageTotals.cost || usingSubscription) {\n\t\t\tconst costStr = `$${usageTotals.cost.toFixed(3)}${usingSubscription ? ` (${t(\"会员\")})` : \"\"}`;\n\t\t\tstatsParts.push(dimPart(costStr));\n\t\t}\n\n\t\tif (contextPercent === \"?\" || contextPercentValue > 0) {\n\t\t\tconst contextLabel = contextPercent === \"?\" ? `${t(\"上下文\")} ?` : `${contextPercent}%`;\n\t\t\tlet contextPercentStr: string;\n\t\t\tif (contextPercentValue > 90) {\n\t\t\t\tcontextPercentStr = theme.fg(\"error\", contextLabel);\n\t\t\t} else if (contextPercentValue > 70) {\n\t\t\t\tcontextPercentStr = theme.fg(\"warning\", contextLabel);\n\t\t\t} else {\n\t\t\t\tcontextPercentStr = dimPart(contextLabel);\n\t\t\t}\n\t\t\tif (this.autoCompactEnabled && contextPercent !== \"?\" && contextPercentValue > 0) {\n\t\t\t\tcontextPercentStr += theme.fg(\"dim\", ` ${t(\"自动压缩\")}`);\n\t\t\t}\n\t\t\tstatsParts.push(contextPercentStr);\n\t\t}\n\t\tif (areExperimentalFeaturesEnabled()) {\n\t\t\tstatsParts.push(theme.bold(theme.fg(\"warning\", \"xp\")));\n\t\t}\n\n\t\tconst unsignedIn = !state.model || state.model.id === \"unknown\" || state.model.provider === \"unknown\";\n\t\tconst modelName = unsignedIn ? t(\"未登录\") : state.model!.id;\n\t\tlet modelLabel = modelName;\n\t\tif (!unsignedIn && state.model?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\tmodelLabel =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} · ${t(\"思考关\")}` : `${modelName} · ${t(\"思考\")} ${thinkingLevel}`;\n\t\t}\n\t\tif (!unsignedIn && this.footerData.getAvailableProviderCount() > 1 && state.model) {\n\t\t\tmodelLabel = `(${state.model.provider}) ${modelLabel}`;\n\t\t}\n\n\t\tstatsParts.push(dimPart(modelLabel));\n\t\tconst right = statsParts.join(dimPart(\" · \"));\n\t\tconst left = `${theme.fg(\"muted\", \"▍\")} ${theme.fg(\"dim\", pwd)}`;\n\t\tconst minPadding = 2;\n\t\tlet leftDisplay = left;\n\t\tlet rightDisplay = right;\n\t\tif (visibleWidth(left) + minPadding + visibleWidth(right) > width) {\n\t\t\tconst maxLeft = Math.max(4, width - minPadding - Math.min(visibleWidth(right), Math.floor(width / 2)));\n\t\t\tleftDisplay = truncateToWidth(left, maxLeft, theme.fg(\"dim\", \"...\"));\n\t\t}\n\t\tif (visibleWidth(leftDisplay) + minPadding + visibleWidth(rightDisplay) > width) {\n\t\t\tconst availableForRight = Math.max(0, width - visibleWidth(leftDisplay) - minPadding);\n\t\t\trightDisplay = availableForRight > 0 ? truncateToWidth(right, availableForRight, theme.fg(\"dim\", \"...\")) : \"\";\n\t\t}\n\t\tconst padding = \" \".repeat(Math.max(minPadding, width - visibleWidth(leftDisplay) - visibleWidth(rightDisplay)));\n\t\tconst lines = [leftDisplay + (rightDisplay ? padding + rightDisplay : \"\")];\n\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tif (extensionStatuses.size > 0) {\n\t\t\tconst sortedStatuses = Array.from(extensionStatuses.entries())\n\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t.map(([, text]) => sanitizeStatusText(text));\n\t\t\tconst statusLine = sortedStatuses.join(\" \");\n\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiC,MAAM,wBAAwB,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAiBxF;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAYhF;AAED;;;GAGG;AACH,qBAAa,eAAgB,YAAW,SAAS;IAChD,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAA6B;IAK/C,OAAO,CAAC,UAAU,CAEL;IAEb,YAAY,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,0BAA0B,EAGxE;IAED,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAGtC;IAED,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAE5C;IAED;;;OAGG;IACH,UAAU,IAAI,IAAI,CAEjB;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI,CAEd;IAED,OAAO,CAAC,aAAa;IA+BrB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAsG9B;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth, visibleWidth } from \"@earendil-works/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport { areExperimentalFeaturesEnabled } from \"../../../core/experimental.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { addUsageToTotals, createUsageTotals, type UsageTotals } from \"../../../core/usage-totals.ts\";\nimport { t } from \"../../../dal/i18n.ts\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\n/**\n * Format token counts for compact footer display.\n */\nexport function formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\t// The footer re-renders on every spinner tick (~80ms); scanning thousands of\n\t// entries each frame showed up as real CPU. Entry list is append-only in\n\t// practice, so cache the totals keyed by (length, last entry reference) —\n\t// both an append and a wholesale session swap change at least one of them.\n\tprivate usageCache:\n\t\t| { entryCount: number; lastEntry: unknown; totals: UsageTotals; latestCacheHitRate: number | undefined }\n\t\t| undefined;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t\tthis.usageCache = undefined;\n\t}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * No-op: git branch caching now handled by provider.\n\t * Kept for compatibility with existing call sites in interactive-mode.\n\t */\n\tinvalidate(): void {\n\t\t// No-op: git branch is cached/invalidated by provider\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\tprivate getUsageStats(): { totals: UsageTotals; latestCacheHitRate: number | undefined } {\n\t\tconst entries = this.session.sessionManager.getEntries();\n\t\tconst lastEntry = entries.at(-1);\n\t\tconst cached = this.usageCache;\n\t\tif (cached && cached.entryCount === entries.length && cached.lastEntry === lastEntry) {\n\t\t\treturn { totals: cached.totals, latestCacheHitRate: cached.latestCacheHitRate };\n\t\t}\n\n\t\t// Calculate cumulative usage from ALL session entries (not just post-compaction messages)\n\t\tconst totals = createUsageTotals();\n\t\tlet latestCacheHitRate: number | undefined;\n\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\t\taddUsageToTotals(totals, entry.message.usage);\n\n\t\t\t\tconst latestPromptTokens =\n\t\t\t\t\tentry.message.usage.input + entry.message.usage.cacheRead + entry.message.usage.cacheWrite;\n\t\t\t\tlatestCacheHitRate =\n\t\t\t\t\tlatestPromptTokens > 0 ? (entry.message.usage.cacheRead / latestPromptTokens) * 100 : undefined;\n\t\t\t} else if (entry.type === \"message\" && entry.message.role === \"toolResult\" && entry.message.usage) {\n\t\t\t\taddUsageToTotals(totals, entry.message.usage);\n\t\t\t} else if ((entry.type === \"branch_summary\" || entry.type === \"compaction\") && entry.usage) {\n\t\t\t\taddUsageToTotals(totals, entry.usage);\n\t\t\t}\n\t\t}\n\n\t\tthis.usageCache = { entryCount: entries.length, lastEntry, totals, latestCacheHitRate };\n\t\treturn { totals, latestCacheHitRate };\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\t\tconst { totals: usageTotals, latestCacheHitRate } = this.getUsageStats();\n\n\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\tconst contextUsage = this.session.getContextUsage();\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} · ${branch}`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} · ${sessionName}`;\n\t\t}\n\n\t\tconst dimPart = (text: string) => theme.fg(\"dim\", text);\n\t\tconst statsParts: string[] = [];\n\t\tif (usageTotals.input) statsParts.push(dimPart(`↑${formatTokens(usageTotals.input)}`));\n\t\tif (usageTotals.output) statsParts.push(dimPart(`↓${formatTokens(usageTotals.output)}`));\n\t\tif (usageTotals.cacheRead) statsParts.push(dimPart(`R${formatTokens(usageTotals.cacheRead)}`));\n\t\tif (usageTotals.cacheWrite) statsParts.push(dimPart(`W${formatTokens(usageTotals.cacheWrite)}`));\n\t\tif ((usageTotals.cacheRead > 0 || usageTotals.cacheWrite > 0) && latestCacheHitRate !== undefined) {\n\t\t\tstatsParts.push(dimPart(`CH${latestCacheHitRate.toFixed(1)}%`));\n\t\t}\n\n\t\t// Kimi Coding is subscription-backed despite using API-key authentication.\n\t\tconst usingSubscription = state.model\n\t\t\t? state.model.provider === \"kimi-coding\" || this.session.modelRuntime.isUsingSubscription(state.model.provider)\n\t\t\t: false;\n\t\tif (usageTotals.cost || usingSubscription) {\n\t\t\tconst costStr = `$${usageTotals.cost.toFixed(3)}${usingSubscription ? ` (${t(\"会员\")})` : \"\"}`;\n\t\t\tstatsParts.push(dimPart(costStr));\n\t\t}\n\n\t\tif (contextPercent === \"?\" || contextPercentValue > 0) {\n\t\t\tconst contextLabel = contextPercent === \"?\" ? `${t(\"上下文\")} ?` : `${contextPercent}%`;\n\t\t\tlet contextPercentStr: string;\n\t\t\tif (contextPercentValue > 90) {\n\t\t\t\tcontextPercentStr = theme.fg(\"error\", contextLabel);\n\t\t\t} else if (contextPercentValue > 70) {\n\t\t\t\tcontextPercentStr = theme.fg(\"warning\", contextLabel);\n\t\t\t} else {\n\t\t\t\tcontextPercentStr = dimPart(contextLabel);\n\t\t\t}\n\t\t\tif (this.autoCompactEnabled && contextPercent !== \"?\" && contextPercentValue > 0) {\n\t\t\t\tcontextPercentStr += theme.fg(\"dim\", ` ${t(\"自动压缩\")}`);\n\t\t\t}\n\t\t\tstatsParts.push(contextPercentStr);\n\t\t}\n\t\tif (areExperimentalFeaturesEnabled()) {\n\t\t\tstatsParts.push(theme.bold(theme.fg(\"warning\", \"xp\")));\n\t\t}\n\n\t\tconst unsignedIn = !state.model || state.model.id === \"unknown\" || state.model.provider === \"unknown\";\n\t\tconst modelName = unsignedIn ? t(\"未登录\") : state.model!.id;\n\t\tlet modelLabel = modelName;\n\t\tif (!unsignedIn && state.model?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\tmodelLabel =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} · ${t(\"思考关\")}` : `${modelName} · ${t(\"思考\")} ${thinkingLevel}`;\n\t\t}\n\t\tif (!unsignedIn && this.footerData.getAvailableProviderCount() > 1 && state.model) {\n\t\t\tmodelLabel = `(${state.model.provider}) ${modelLabel}`;\n\t\t}\n\n\t\tstatsParts.push(dimPart(modelLabel));\n\t\tconst right = statsParts.join(dimPart(\" · \"));\n\t\tconst left = `${theme.fg(\"muted\", \"▍\")} ${theme.fg(\"dim\", pwd)}`;\n\t\tconst minPadding = 2;\n\t\tlet leftDisplay = left;\n\t\tlet rightDisplay = right;\n\t\tif (visibleWidth(left) + minPadding + visibleWidth(right) > width) {\n\t\t\tconst maxLeft = Math.max(4, width - minPadding - Math.min(visibleWidth(right), Math.floor(width / 2)));\n\t\t\tleftDisplay = truncateToWidth(left, maxLeft, theme.fg(\"dim\", \"...\"));\n\t\t}\n\t\tif (visibleWidth(leftDisplay) + minPadding + visibleWidth(rightDisplay) > width) {\n\t\t\tconst availableForRight = Math.max(0, width - visibleWidth(leftDisplay) - minPadding);\n\t\t\trightDisplay = availableForRight > 0 ? truncateToWidth(right, availableForRight, theme.fg(\"dim\", \"...\")) : \"\";\n\t\t}\n\t\tconst padding = \" \".repeat(Math.max(minPadding, width - visibleWidth(leftDisplay) - visibleWidth(rightDisplay)));\n\t\tconst lines = [leftDisplay + (rightDisplay ? padding + rightDisplay : \"\")];\n\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tif (extensionStatuses.size > 0) {\n\t\t\tconst sortedStatuses = Array.from(extensionStatuses.entries())\n\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t.map(([, text]) => sanitizeStatusText(text));\n\t\t\tconst statusLine = sortedStatuses.join(\" \");\n\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
@@ -49,12 +49,18 @@ export class FooterComponent {
|
|
|
49
49
|
autoCompactEnabled = true;
|
|
50
50
|
session;
|
|
51
51
|
footerData;
|
|
52
|
+
// The footer re-renders on every spinner tick (~80ms); scanning thousands of
|
|
53
|
+
// entries each frame showed up as real CPU. Entry list is append-only in
|
|
54
|
+
// practice, so cache the totals keyed by (length, last entry reference) —
|
|
55
|
+
// both an append and a wholesale session swap change at least one of them.
|
|
56
|
+
usageCache;
|
|
52
57
|
constructor(session, footerData) {
|
|
53
58
|
this.session = session;
|
|
54
59
|
this.footerData = footerData;
|
|
55
60
|
}
|
|
56
61
|
setSession(session) {
|
|
57
62
|
this.session = session;
|
|
63
|
+
this.usageCache = undefined;
|
|
58
64
|
}
|
|
59
65
|
setAutoCompactEnabled(enabled) {
|
|
60
66
|
this.autoCompactEnabled = enabled;
|
|
@@ -73,25 +79,36 @@ export class FooterComponent {
|
|
|
73
79
|
dispose() {
|
|
74
80
|
// Git watcher cleanup handled by provider
|
|
75
81
|
}
|
|
76
|
-
|
|
77
|
-
const
|
|
82
|
+
getUsageStats() {
|
|
83
|
+
const entries = this.session.sessionManager.getEntries();
|
|
84
|
+
const lastEntry = entries.at(-1);
|
|
85
|
+
const cached = this.usageCache;
|
|
86
|
+
if (cached && cached.entryCount === entries.length && cached.lastEntry === lastEntry) {
|
|
87
|
+
return { totals: cached.totals, latestCacheHitRate: cached.latestCacheHitRate };
|
|
88
|
+
}
|
|
78
89
|
// Calculate cumulative usage from ALL session entries (not just post-compaction messages)
|
|
79
|
-
const
|
|
90
|
+
const totals = createUsageTotals();
|
|
80
91
|
let latestCacheHitRate;
|
|
81
|
-
for (const entry of
|
|
92
|
+
for (const entry of entries) {
|
|
82
93
|
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
83
|
-
addUsageToTotals(
|
|
94
|
+
addUsageToTotals(totals, entry.message.usage);
|
|
84
95
|
const latestPromptTokens = entry.message.usage.input + entry.message.usage.cacheRead + entry.message.usage.cacheWrite;
|
|
85
96
|
latestCacheHitRate =
|
|
86
97
|
latestPromptTokens > 0 ? (entry.message.usage.cacheRead / latestPromptTokens) * 100 : undefined;
|
|
87
98
|
}
|
|
88
99
|
else if (entry.type === "message" && entry.message.role === "toolResult" && entry.message.usage) {
|
|
89
|
-
addUsageToTotals(
|
|
100
|
+
addUsageToTotals(totals, entry.message.usage);
|
|
90
101
|
}
|
|
91
102
|
else if ((entry.type === "branch_summary" || entry.type === "compaction") && entry.usage) {
|
|
92
|
-
addUsageToTotals(
|
|
103
|
+
addUsageToTotals(totals, entry.usage);
|
|
93
104
|
}
|
|
94
105
|
}
|
|
106
|
+
this.usageCache = { entryCount: entries.length, lastEntry, totals, latestCacheHitRate };
|
|
107
|
+
return { totals, latestCacheHitRate };
|
|
108
|
+
}
|
|
109
|
+
render(width) {
|
|
110
|
+
const state = this.session.state;
|
|
111
|
+
const { totals: usageTotals, latestCacheHitRate } = this.getUsageStats();
|
|
95
112
|
// Calculate context usage from session (handles compaction correctly).
|
|
96
113
|
// After compaction, tokens are unknown until the next LLM response.
|
|
97
114
|
const contextUsage = this.session.getContextUsage();
|
|
@@ -1 +1 @@
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AAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9C,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC5C,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,KAAK,CAAC;IAAA,CACb;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth, visibleWidth } from \"@earendil-works/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport { areExperimentalFeaturesEnabled } from \"../../../core/experimental.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { addUsageToTotals, createUsageTotals } from \"../../../core/usage-totals.ts\";\nimport { t } from \"../../../dal/i18n.ts\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\n/**\n * Format token counts for compact footer display.\n */\nexport function formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * No-op: git branch caching now handled by provider.\n\t * Kept for compatibility with existing call sites in interactive-mode.\n\t */\n\tinvalidate(): void {\n\t\t// No-op: git branch is cached/invalidated by provider\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\n\t\t// Calculate cumulative usage from ALL session entries (not just post-compaction messages)\n\t\tconst usageTotals = createUsageTotals();\n\t\tlet latestCacheHitRate: number | undefined;\n\n\t\tfor (const entry of this.session.sessionManager.getEntries()) {\n\t\t\tif (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\t\taddUsageToTotals(usageTotals, entry.message.usage);\n\n\t\t\t\tconst latestPromptTokens =\n\t\t\t\t\tentry.message.usage.input + entry.message.usage.cacheRead + entry.message.usage.cacheWrite;\n\t\t\t\tlatestCacheHitRate =\n\t\t\t\t\tlatestPromptTokens > 0 ? (entry.message.usage.cacheRead / latestPromptTokens) * 100 : undefined;\n\t\t\t} else if (entry.type === \"message\" && entry.message.role === \"toolResult\" && entry.message.usage) {\n\t\t\t\taddUsageToTotals(usageTotals, entry.message.usage);\n\t\t\t} else if ((entry.type === \"branch_summary\" || entry.type === \"compaction\") && entry.usage) {\n\t\t\t\taddUsageToTotals(usageTotals, entry.usage);\n\t\t\t}\n\t\t}\n\n\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\tconst contextUsage = this.session.getContextUsage();\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} · ${branch}`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} · ${sessionName}`;\n\t\t}\n\n\t\tconst dimPart = (text: string) => theme.fg(\"dim\", text);\n\t\tconst statsParts: string[] = [];\n\t\tif (usageTotals.input) statsParts.push(dimPart(`↑${formatTokens(usageTotals.input)}`));\n\t\tif (usageTotals.output) statsParts.push(dimPart(`↓${formatTokens(usageTotals.output)}`));\n\t\tif (usageTotals.cacheRead) statsParts.push(dimPart(`R${formatTokens(usageTotals.cacheRead)}`));\n\t\tif (usageTotals.cacheWrite) statsParts.push(dimPart(`W${formatTokens(usageTotals.cacheWrite)}`));\n\t\tif ((usageTotals.cacheRead > 0 || usageTotals.cacheWrite > 0) && latestCacheHitRate !== undefined) {\n\t\t\tstatsParts.push(dimPart(`CH${latestCacheHitRate.toFixed(1)}%`));\n\t\t}\n\n\t\t// Kimi Coding is subscription-backed despite using API-key authentication.\n\t\tconst usingSubscription = state.model\n\t\t\t? state.model.provider === \"kimi-coding\" || this.session.modelRuntime.isUsingSubscription(state.model.provider)\n\t\t\t: false;\n\t\tif (usageTotals.cost || usingSubscription) {\n\t\t\tconst costStr = `$${usageTotals.cost.toFixed(3)}${usingSubscription ? ` (${t(\"会员\")})` : \"\"}`;\n\t\t\tstatsParts.push(dimPart(costStr));\n\t\t}\n\n\t\tif (contextPercent === \"?\" || contextPercentValue > 0) {\n\t\t\tconst contextLabel = contextPercent === \"?\" ? `${t(\"上下文\")} ?` : `${contextPercent}%`;\n\t\t\tlet contextPercentStr: string;\n\t\t\tif (contextPercentValue > 90) {\n\t\t\t\tcontextPercentStr = theme.fg(\"error\", contextLabel);\n\t\t\t} else if (contextPercentValue > 70) {\n\t\t\t\tcontextPercentStr = theme.fg(\"warning\", contextLabel);\n\t\t\t} else {\n\t\t\t\tcontextPercentStr = dimPart(contextLabel);\n\t\t\t}\n\t\t\tif (this.autoCompactEnabled && contextPercent !== \"?\" && contextPercentValue > 0) {\n\t\t\t\tcontextPercentStr += theme.fg(\"dim\", ` ${t(\"自动压缩\")}`);\n\t\t\t}\n\t\t\tstatsParts.push(contextPercentStr);\n\t\t}\n\t\tif (areExperimentalFeaturesEnabled()) {\n\t\t\tstatsParts.push(theme.bold(theme.fg(\"warning\", \"xp\")));\n\t\t}\n\n\t\tconst unsignedIn = !state.model || state.model.id === \"unknown\" || state.model.provider === \"unknown\";\n\t\tconst modelName = unsignedIn ? t(\"未登录\") : state.model!.id;\n\t\tlet modelLabel = modelName;\n\t\tif (!unsignedIn && state.model?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\tmodelLabel =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} · ${t(\"思考关\")}` : `${modelName} · ${t(\"思考\")} ${thinkingLevel}`;\n\t\t}\n\t\tif (!unsignedIn && this.footerData.getAvailableProviderCount() > 1 && state.model) {\n\t\t\tmodelLabel = `(${state.model.provider}) ${modelLabel}`;\n\t\t}\n\n\t\tstatsParts.push(dimPart(modelLabel));\n\t\tconst right = statsParts.join(dimPart(\" · \"));\n\t\tconst left = `${theme.fg(\"muted\", \"▍\")} ${theme.fg(\"dim\", pwd)}`;\n\t\tconst minPadding = 2;\n\t\tlet leftDisplay = left;\n\t\tlet rightDisplay = right;\n\t\tif (visibleWidth(left) + minPadding + visibleWidth(right) > width) {\n\t\t\tconst maxLeft = Math.max(4, width - minPadding - Math.min(visibleWidth(right), Math.floor(width / 2)));\n\t\t\tleftDisplay = truncateToWidth(left, maxLeft, theme.fg(\"dim\", \"...\"));\n\t\t}\n\t\tif (visibleWidth(leftDisplay) + minPadding + visibleWidth(rightDisplay) > width) {\n\t\t\tconst availableForRight = Math.max(0, width - visibleWidth(leftDisplay) - minPadding);\n\t\t\trightDisplay = availableForRight > 0 ? truncateToWidth(right, availableForRight, theme.fg(\"dim\", \"...\")) : \"\";\n\t\t}\n\t\tconst padding = \" \".repeat(Math.max(minPadding, width - visibleWidth(leftDisplay) - visibleWidth(rightDisplay)));\n\t\tconst lines = [leftDisplay + (rightDisplay ? padding + rightDisplay : \"\")];\n\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tif (extensionStatuses.size > 0) {\n\t\t\tconst sortedStatuses = Array.from(extensionStatuses.entries())\n\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t.map(([, text]) => sanitizeStatusText(text));\n\t\t\tconst statusLine = sortedStatuses.join(\" \");\n\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"footer.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAkB,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEvF,OAAO,EAAE,8BAA8B,EAAE,MAA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,KAAK,GAAG,CAAC,WAAW,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAE3E,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC;QACjE,IAAI,iBAAiB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;iBAC5D,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;iBACtC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9C,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC5C,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,KAAK,CAAC;IAAA,CACb;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth, visibleWidth } from \"@earendil-works/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport { areExperimentalFeaturesEnabled } from \"../../../core/experimental.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { addUsageToTotals, createUsageTotals, type UsageTotals } from \"../../../core/usage-totals.ts\";\nimport { t } from \"../../../dal/i18n.ts\";\nimport { theme } from \"../theme/theme.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\n/**\n * Format token counts for compact footer display.\n */\nexport function formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows pwd, token stats, and context usage.\n * Computes token/context stats from session, gets git branch and extension statuses from provider.\n */\nexport class FooterComponent implements Component {\n\tprivate autoCompactEnabled = true;\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\t// The footer re-renders on every spinner tick (~80ms); scanning thousands of\n\t// entries each frame showed up as real CPU. Entry list is append-only in\n\t// practice, so cache the totals keyed by (length, last entry reference) —\n\t// both an append and a wholesale session swap change at least one of them.\n\tprivate usageCache:\n\t\t| { entryCount: number; lastEntry: unknown; totals: UsageTotals; latestCacheHitRate: number | undefined }\n\t\t| undefined;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t\tthis.usageCache = undefined;\n\t}\n\n\tsetAutoCompactEnabled(enabled: boolean): void {\n\t\tthis.autoCompactEnabled = enabled;\n\t}\n\n\t/**\n\t * No-op: git branch caching now handled by provider.\n\t * Kept for compatibility with existing call sites in interactive-mode.\n\t */\n\tinvalidate(): void {\n\t\t// No-op: git branch is cached/invalidated by provider\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\tprivate getUsageStats(): { totals: UsageTotals; latestCacheHitRate: number | undefined } {\n\t\tconst entries = this.session.sessionManager.getEntries();\n\t\tconst lastEntry = entries.at(-1);\n\t\tconst cached = this.usageCache;\n\t\tif (cached && cached.entryCount === entries.length && cached.lastEntry === lastEntry) {\n\t\t\treturn { totals: cached.totals, latestCacheHitRate: cached.latestCacheHitRate };\n\t\t}\n\n\t\t// Calculate cumulative usage from ALL session entries (not just post-compaction messages)\n\t\tconst totals = createUsageTotals();\n\t\tlet latestCacheHitRate: number | undefined;\n\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\t\taddUsageToTotals(totals, entry.message.usage);\n\n\t\t\t\tconst latestPromptTokens =\n\t\t\t\t\tentry.message.usage.input + entry.message.usage.cacheRead + entry.message.usage.cacheWrite;\n\t\t\t\tlatestCacheHitRate =\n\t\t\t\t\tlatestPromptTokens > 0 ? (entry.message.usage.cacheRead / latestPromptTokens) * 100 : undefined;\n\t\t\t} else if (entry.type === \"message\" && entry.message.role === \"toolResult\" && entry.message.usage) {\n\t\t\t\taddUsageToTotals(totals, entry.message.usage);\n\t\t\t} else if ((entry.type === \"branch_summary\" || entry.type === \"compaction\") && entry.usage) {\n\t\t\t\taddUsageToTotals(totals, entry.usage);\n\t\t\t}\n\t\t}\n\n\t\tthis.usageCache = { entryCount: entries.length, lastEntry, totals, latestCacheHitRate };\n\t\treturn { totals, latestCacheHitRate };\n\t}\n\n\trender(width: number): string[] {\n\t\tconst state = this.session.state;\n\t\tconst { totals: usageTotals, latestCacheHitRate } = this.getUsageStats();\n\n\t\t// Calculate context usage from session (handles compaction correctly).\n\t\t// After compaction, tokens are unknown until the next LLM response.\n\t\tconst contextUsage = this.session.getContextUsage();\n\t\tconst contextPercentValue = contextUsage?.percent ?? 0;\n\t\tconst contextPercent = contextUsage?.percent !== null ? contextPercentValue.toFixed(1) : \"?\";\n\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} · ${branch}`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} · ${sessionName}`;\n\t\t}\n\n\t\tconst dimPart = (text: string) => theme.fg(\"dim\", text);\n\t\tconst statsParts: string[] = [];\n\t\tif (usageTotals.input) statsParts.push(dimPart(`↑${formatTokens(usageTotals.input)}`));\n\t\tif (usageTotals.output) statsParts.push(dimPart(`↓${formatTokens(usageTotals.output)}`));\n\t\tif (usageTotals.cacheRead) statsParts.push(dimPart(`R${formatTokens(usageTotals.cacheRead)}`));\n\t\tif (usageTotals.cacheWrite) statsParts.push(dimPart(`W${formatTokens(usageTotals.cacheWrite)}`));\n\t\tif ((usageTotals.cacheRead > 0 || usageTotals.cacheWrite > 0) && latestCacheHitRate !== undefined) {\n\t\t\tstatsParts.push(dimPart(`CH${latestCacheHitRate.toFixed(1)}%`));\n\t\t}\n\n\t\t// Kimi Coding is subscription-backed despite using API-key authentication.\n\t\tconst usingSubscription = state.model\n\t\t\t? state.model.provider === \"kimi-coding\" || this.session.modelRuntime.isUsingSubscription(state.model.provider)\n\t\t\t: false;\n\t\tif (usageTotals.cost || usingSubscription) {\n\t\t\tconst costStr = `$${usageTotals.cost.toFixed(3)}${usingSubscription ? ` (${t(\"会员\")})` : \"\"}`;\n\t\t\tstatsParts.push(dimPart(costStr));\n\t\t}\n\n\t\tif (contextPercent === \"?\" || contextPercentValue > 0) {\n\t\t\tconst contextLabel = contextPercent === \"?\" ? `${t(\"上下文\")} ?` : `${contextPercent}%`;\n\t\t\tlet contextPercentStr: string;\n\t\t\tif (contextPercentValue > 90) {\n\t\t\t\tcontextPercentStr = theme.fg(\"error\", contextLabel);\n\t\t\t} else if (contextPercentValue > 70) {\n\t\t\t\tcontextPercentStr = theme.fg(\"warning\", contextLabel);\n\t\t\t} else {\n\t\t\t\tcontextPercentStr = dimPart(contextLabel);\n\t\t\t}\n\t\t\tif (this.autoCompactEnabled && contextPercent !== \"?\" && contextPercentValue > 0) {\n\t\t\t\tcontextPercentStr += theme.fg(\"dim\", ` ${t(\"自动压缩\")}`);\n\t\t\t}\n\t\t\tstatsParts.push(contextPercentStr);\n\t\t}\n\t\tif (areExperimentalFeaturesEnabled()) {\n\t\t\tstatsParts.push(theme.bold(theme.fg(\"warning\", \"xp\")));\n\t\t}\n\n\t\tconst unsignedIn = !state.model || state.model.id === \"unknown\" || state.model.provider === \"unknown\";\n\t\tconst modelName = unsignedIn ? t(\"未登录\") : state.model!.id;\n\t\tlet modelLabel = modelName;\n\t\tif (!unsignedIn && state.model?.reasoning) {\n\t\t\tconst thinkingLevel = state.thinkingLevel || \"off\";\n\t\t\tmodelLabel =\n\t\t\t\tthinkingLevel === \"off\" ? `${modelName} · ${t(\"思考关\")}` : `${modelName} · ${t(\"思考\")} ${thinkingLevel}`;\n\t\t}\n\t\tif (!unsignedIn && this.footerData.getAvailableProviderCount() > 1 && state.model) {\n\t\t\tmodelLabel = `(${state.model.provider}) ${modelLabel}`;\n\t\t}\n\n\t\tstatsParts.push(dimPart(modelLabel));\n\t\tconst right = statsParts.join(dimPart(\" · \"));\n\t\tconst left = `${theme.fg(\"muted\", \"▍\")} ${theme.fg(\"dim\", pwd)}`;\n\t\tconst minPadding = 2;\n\t\tlet leftDisplay = left;\n\t\tlet rightDisplay = right;\n\t\tif (visibleWidth(left) + minPadding + visibleWidth(right) > width) {\n\t\t\tconst maxLeft = Math.max(4, width - minPadding - Math.min(visibleWidth(right), Math.floor(width / 2)));\n\t\t\tleftDisplay = truncateToWidth(left, maxLeft, theme.fg(\"dim\", \"...\"));\n\t\t}\n\t\tif (visibleWidth(leftDisplay) + minPadding + visibleWidth(rightDisplay) > width) {\n\t\t\tconst availableForRight = Math.max(0, width - visibleWidth(leftDisplay) - minPadding);\n\t\t\trightDisplay = availableForRight > 0 ? truncateToWidth(right, availableForRight, theme.fg(\"dim\", \"...\")) : \"\";\n\t\t}\n\t\tconst padding = \" \".repeat(Math.max(minPadding, width - visibleWidth(leftDisplay) - visibleWidth(rightDisplay)));\n\t\tconst lines = [leftDisplay + (rightDisplay ? padding + rightDisplay : \"\")];\n\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tif (extensionStatuses.size > 0) {\n\t\t\tconst sortedStatuses = Array.from(extensionStatuses.entries())\n\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t.map(([, text]) => sanitizeStatusText(text));\n\t\t\tconst statusLine = sortedStatuses.join(\" \");\n\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
@@ -33,11 +33,30 @@ export declare class ToolExecutionComponent extends Container {
|
|
|
33
33
|
private hideComponent;
|
|
34
34
|
private activityPulse?;
|
|
35
35
|
private collapsedAway;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the transcript cursor is sitting on this call.
|
|
38
|
+
*
|
|
39
|
+
* Purely presentational — it draws the arrow that says "ctrl+o acts on this
|
|
40
|
+
* one". The transcript is an append-only log with no selection model of its
|
|
41
|
+
* own, so the cursor lives in interactive-mode and each component only
|
|
42
|
+
* needs to know whether it is the chosen one.
|
|
43
|
+
*/
|
|
44
|
+
private focused;
|
|
36
45
|
private leadingStreak;
|
|
37
46
|
constructor(toolName: string, toolCallId: string, args: any, options: ToolExecutionOptions | undefined, toolDefinition: ToolRenderers | ToolDefinition<any, any, any> | undefined, ui: TUI, cwd: string);
|
|
38
47
|
dispose(): void;
|
|
39
48
|
/** Completed, collapsed, not an error — safe to fold into a streak. */
|
|
40
49
|
isQuietFoldable(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The arrow drawn at the head of a collapsed row.
|
|
52
|
+
*
|
|
53
|
+
* Only the focused row gets one, and unfocused rows keep their existing
|
|
54
|
+
* left edge: reserving a marker column on every row would shift the whole
|
|
55
|
+
* transcript two characters right to serve a cursor that is usually not
|
|
56
|
+
* even on screen.
|
|
57
|
+
*/
|
|
58
|
+
private focusMarker;
|
|
59
|
+
setFocused(focused: boolean): void;
|
|
41
60
|
setStreakPresentation(collapsedAway: boolean, leadingStreak?: number): void;
|
|
42
61
|
private getCallRenderer;
|
|
43
62
|
private getResultRenderer;
|
|
@@ -71,6 +90,24 @@ export declare class ToolExecutionComponent extends Container {
|
|
|
71
90
|
private isBlankComponent;
|
|
72
91
|
private formatToolExecution;
|
|
73
92
|
}
|
|
74
|
-
/**
|
|
75
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Collapse a finished run of tool calls into one row plus a count.
|
|
95
|
+
*
|
|
96
|
+
* `scope` decides how far back it may reach, and that is a rendering concern,
|
|
97
|
+
* not a cosmetic one. The transcript renderer can only patch lines that were
|
|
98
|
+
* visible: when the first changed line sits above the viewport it clears the
|
|
99
|
+
* screen AND the scrollback and repaints everything (tui-main-screen.ts,
|
|
100
|
+
* `firstChanged < prevViewportTop`). Rewriting a streak that has already
|
|
101
|
+
* scrolled away therefore costs a full redraw — which looks like the screen
|
|
102
|
+
* jumping, destroys the user's scroll-back history, and on a long transcript
|
|
103
|
+
* fires on every single tool_execution_end.
|
|
104
|
+
*
|
|
105
|
+
* "tail" — only the run at the end of the document, which is the one still
|
|
106
|
+
* being extended and still on screen. Changes stay near the bottom, so the
|
|
107
|
+
* renderer patches instead of repainting. Use this while a turn is running.
|
|
108
|
+
* "all" — every run. Only safe when the frame is being drawn from scratch
|
|
109
|
+
* anyway, i.e. right after a session is rebuilt, where there is no previous
|
|
110
|
+
* viewport to disturb.
|
|
111
|
+
*/
|
|
112
|
+
export declare function foldQuietToolStreak(children: readonly Component[], scope?: "tail" | "all"): void;
|
|
76
113
|
//# sourceMappingURL=tool-execution.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-execution.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/tool-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,SAAS,EACd,SAAS,EAKT,KAAK,GAAG,EAER,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,mCAAmC,CAAC;AAS3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAO5E,YAAY,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AA+B5E,MAAM,WAAW,oBAAoB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,mBAAmB,CAAY;IACvC,OAAO,CAAC,qBAAqB,CAAC,CAAY;IAC1C,OAAO,CAAC,uBAAuB,CAAC,CAAY;IAC5C,OAAO,CAAC,aAAa,CAAW;IAChC,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,eAAe,CAAS;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AAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAClF,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,OAAO,EAAE,OAAO,CAAC;KACjB,EACD,SAAS,UAAQ,GACf,IAAI,CAKN;IAED,OAAO,CAAC,0BAA0B;IAuBlC,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAGnC;IAED,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAGjC;IAED,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAGtC;IAEQ,UAAU,IAAI,IAAI,CAG1B;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAsCvC;IAED,OAAO,CAAC,aAAa;IAiHrB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,mBAAmB;CAiB3B;AAID,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CA4BxE","sourcesContent":["import {\n\tBox,\n\ttype Component,\n\tContainer,\n\tgetCapabilities,\n\tImage,\n\tSpacer,\n\tText,\n\ttype TUI,\n\ttruncateToWidth,\n} from \"@earendil-works/pi-tui\";\nimport type { ToolDefinition, ToolRenderContext } from \"../../../core/extensions/types.ts\";\nimport { createAllToolDefinitions, type ToolName } from \"../../../core/tools/index.ts\";\nimport {\n\tcompactToolArgHint,\n\tcountOutputLines,\n\tformatCollapsedSummary,\n\tgetTextOutput as getRenderedTextOutput,\n\tprettyToolLabel,\n} from \"../../../core/tools/render-utils.ts\";\nimport type { ToolRenderers } from \"../../../core/tools/renderers/index.ts\";\nimport { t } from \"../../../dal/i18n.ts\";\nimport { convertToPng } from \"../../../utils/image-convert.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { keyHint } from \"./keybinding-hints.ts\";\nimport { PulseLabel } from \"./status-indicator.ts\";\n\nexport type { ToolRenderers } from \"../../../core/tools/renderers/index.ts\";\n\nconst FALLBACK_PREVIEW_LINES = 0;\n\n/** Collapsed tools render as a single Claude-style row: call + muted stats. */\nclass CollapsedToolRow implements Component {\n\tprivate readonly call: Component;\n\tprivate readonly result?: Component;\n\n\tconstructor(call: Component, result?: Component) {\n\t\tthis.call = call;\n\t\tthis.result = result;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.call.invalidate?.();\n\t\tthis.result?.invalidate?.();\n\t}\n\n\trender(width: number): string[] {\n\t\tconst callLine = (this.call.render(width)[0] ?? \"\").replace(/\\s+$/, \"\");\n\t\tconst resultText = (this.result?.render(width) ?? [])\n\t\t\t.map((line) => line.trim())\n\t\t\t.filter((line) => line.length > 0)\n\t\t\t.join(\" · \");\n\t\tif (!callLine.trim() && !resultText) return [];\n\t\tconst combined = resultText ? `${callLine} ${theme.fg(\"dim\", resultText)}` : callLine;\n\t\treturn [truncateToWidth(combined, Math.max(1, width), theme.fg(\"dim\", \"...\"))];\n\t}\n}\n\nexport interface ToolExecutionOptions {\n\tshowImages?: boolean;\n\timageWidthCells?: number;\n}\n\nexport class ToolExecutionComponent extends Container {\n\tprivate contentBox: Box;\n\tprivate contentText: Text;\n\tprivate selfRenderContainer: Container;\n\tprivate callRendererComponent?: Component;\n\tprivate resultRendererComponent?: Component;\n\tprivate rendererState: any = {};\n\tprivate imageComponents: Image[] = [];\n\tprivate imageSpacers: Spacer[] = [];\n\tprivate toolName: string;\n\tprivate toolCallId: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate imageWidthCells: number;\n\tprivate isPartial = true;\n\tprivate toolDefinition?: ToolRenderers;\n\tprivate builtInToolDefinition?: ToolRenderers;\n\tprivate ui: TUI;\n\tprivate cwd: string;\n\tprivate executionStarted = false;\n\tprivate argsComplete = false;\n\tprivate result?: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tisError: boolean;\n\t\tdetails?: any;\n\t};\n\tprivate convertedImages: Map<number, { data: string; mimeType: string }> = new Map();\n\tprivate hideComponent = false;\n\tprivate activityPulse?: PulseLabel;\n\tprivate collapsedAway = false;\n\tprivate leadingStreak = 0;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\ttoolCallId: string,\n\t\targs: any,\n\t\toptions: ToolExecutionOptions = {},\n\t\ttoolDefinition: ToolRenderers | ToolDefinition<any, any, any> | undefined,\n\t\tui: TUI,\n\t\tcwd: string,\n\t) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.toolCallId = toolCallId;\n\t\tthis.args = args;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.builtInToolDefinition = createAllToolDefinitions(cwd)[toolName as ToolName];\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.imageWidthCells = options.imageWidthCells ?? 60;\n\t\tthis.ui = ui;\n\t\tthis.cwd = cwd;\n\n\t\t// Always create all shell variants. contentBox is used for default renderer-based composition.\n\t\t// selfRenderContainer is used when the tool renders its own framing.\n\t\t// contentText is reserved for generic fallback rendering when no tool definition exists.\n\t\tthis.contentBox = new Box(0, 0);\n\t\tthis.contentText = new Text(\"\", 0, 0);\n\t\tthis.selfRenderContainer = new Container();\n\n\t\tif (this.hasRendererDefinition()) {\n\t\t\tthis.addChild(this.getRenderShell() === \"self\" ? this.selfRenderContainer : this.contentBox);\n\t\t} else {\n\t\t\tthis.addChild(this.contentText);\n\t\t}\n\n\t\tthis.updateDisplay();\n\t}\n\n\tdispose(): void {\n\t\tthis.activityPulse?.dispose();\n\t\tthis.activityPulse = undefined;\n\t}\n\n\t/** Completed, collapsed, not an error — safe to fold into a streak. */\n\tisQuietFoldable(): boolean {\n\t\treturn !this.expanded && !!this.result && !this.result.isError && !this.isPartial;\n\t}\n\n\tsetStreakPresentation(collapsedAway: boolean, leadingStreak = 0): void {\n\t\tthis.collapsedAway = collapsedAway;\n\t\tthis.leadingStreak = collapsedAway ? 0 : leadingStreak;\n\t}\n\n\tprivate getCallRenderer(): ToolRenderers[\"renderCall\"] | undefined {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderCall;\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderCall;\n\t\t}\n\t\treturn this.toolDefinition.renderCall ?? this.builtInToolDefinition.renderCall;\n\t}\n\n\tprivate getResultRenderer(): ToolRenderers[\"renderResult\"] | undefined {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderResult;\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderResult;\n\t\t}\n\t\treturn this.toolDefinition.renderResult ?? this.builtInToolDefinition.renderResult;\n\t}\n\n\tprivate hasRendererDefinition(): boolean {\n\t\treturn this.builtInToolDefinition !== undefined || this.toolDefinition !== undefined;\n\t}\n\n\tprivate getRenderShell(): \"default\" | \"self\" {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderShell ?? \"default\";\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderShell ?? \"default\";\n\t\t}\n\t\treturn this.toolDefinition.renderShell ?? this.builtInToolDefinition.renderShell ?? \"default\";\n\t}\n\n\tprivate getRenderContext(lastComponent: Component | undefined): ToolRenderContext {\n\t\treturn {\n\t\t\targs: this.args,\n\t\t\ttoolCallId: this.toolCallId,\n\t\t\tinvalidate: () => {\n\t\t\t\tthis.invalidate();\n\t\t\t\tthis.ui.requestRender();\n\t\t\t},\n\t\t\tlastComponent,\n\t\t\tstate: this.rendererState,\n\t\t\tcwd: this.cwd,\n\t\t\texecutionStarted: this.executionStarted,\n\t\t\targsComplete: this.argsComplete,\n\t\t\tisPartial: this.isPartial,\n\t\t\texpanded: this.expanded,\n\t\t\tshowImages: this.showImages,\n\t\t\tisError: this.result?.isError ?? false,\n\t\t};\n\t}\n\n\tprivate createCallFallback(): Component {\n\t\tconst label = prettyToolLabel(this.toolName);\n\t\tconst hint = compactToolArgHint(this.args);\n\t\tconst title = theme.fg(\"toolTitle\", theme.bold(label));\n\t\treturn new Text(hint ? `${title} ${theme.fg(\"dim\", hint)}` : title, 0, 0);\n\t}\n\n\tprivate createResultFallback(): Component | undefined {\n\t\tconst output = this.getTextOutput();\n\t\tif (!output) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (!this.expanded && !this.result?.isError) {\n\t\t\tconst n = countOutputLines(output);\n\t\t\tconst summary = formatCollapsedSummary(theme, n > 0 ? [`${n} lines`] : []);\n\t\t\treturn summary ? new Text(summary, 0, 0) : undefined;\n\t\t}\n\n\t\tconst lines = output.split(\"\\n\");\n\t\tconst displayLines = this.expanded ? lines : lines.slice(0, Math.max(FALLBACK_PREVIEW_LINES, 0));\n\t\tconst remaining = lines.length - displayLines.length;\n\t\tlet text = displayLines.map((line) => theme.fg(\"toolOutput\", line)).join(\"\\n\");\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t\treturn text ? new Text(text, 0, 0) : undefined;\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tthis.updateDisplay();\n\t}\n\n\tmarkExecutionStarted(): void {\n\t\tthis.executionStarted = true;\n\t\tthis.updateDisplay();\n\t\tthis.ui.requestRender();\n\t}\n\n\tsetArgsComplete(): void {\n\t\tthis.argsComplete = true;\n\t\tthis.updateDisplay();\n\t\tthis.ui.requestRender();\n\t}\n\n\tupdateResult(\n\t\tresult: {\n\t\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\t\tdetails?: any;\n\t\t\tisError: boolean;\n\t\t},\n\t\tisPartial = false,\n\t): void {\n\t\tthis.result = result;\n\t\tthis.isPartial = isPartial;\n\t\tthis.updateDisplay();\n\t\tthis.maybeConvertImagesForKitty();\n\t}\n\n\tprivate maybeConvertImagesForKitty(): void {\n\t\tconst caps = getCapabilities();\n\t\tif (caps.images !== \"kitty\") return;\n\t\tif (!this.result) return;\n\n\t\tconst imageBlocks = this.result.content.filter((c) => c.type === \"image\");\n\t\tfor (let i = 0; i < imageBlocks.length; i++) {\n\t\t\tconst img = imageBlocks[i];\n\t\t\tif (!img.data || !img.mimeType) continue;\n\t\t\tif (img.mimeType === \"image/png\") continue;\n\t\t\tif (this.convertedImages.has(i)) continue;\n\n\t\t\tconst index = i;\n\t\t\tconvertToPng(img.data, img.mimeType).then((converted) => {\n\t\t\t\tif (converted) {\n\t\t\t\t\tthis.convertedImages.set(index, converted);\n\t\t\t\t\tthis.updateDisplay();\n\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetShowImages(show: boolean): void {\n\t\tthis.showImages = show;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetImageWidthCells(width: number): void {\n\t\tthis.imageWidthCells = Math.max(1, Math.floor(width));\n\t\tthis.updateDisplay();\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tthis.updateDisplay();\n\t}\n\n\toverride render(width: number): string[] {\n\t\tif (this.hideComponent || this.collapsedAway) {\n\t\t\treturn [];\n\t\t}\n\n\t\tlet lines: string[];\n\t\tif (this.hasRendererDefinition() && this.getRenderShell() === \"self\") {\n\t\t\tconst contentLines = this.selfRenderContainer.render(width);\n\t\t\tif (this.imageComponents.length === 0 && contentLines.every((line) => line.trim() === \"\")) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tlines = [];\n\t\t\tif (contentLines.length > 0) {\n\t\t\t\tlines.push(...contentLines);\n\t\t\t}\n\t\t\tfor (let i = 0; i < this.imageComponents.length; i++) {\n\t\t\t\tconst spacer = this.imageSpacers[i];\n\t\t\t\tif (spacer) {\n\t\t\t\t\tlines.push(...spacer.render(width));\n\t\t\t\t}\n\t\t\t\tconst imageComponent = this.imageComponents[i];\n\t\t\t\tif (imageComponent) {\n\t\t\t\t\tlines.push(...imageComponent.render(width));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tlines = super.render(width);\n\t\t}\n\n\t\tif (this.activityPulse && lines.length > 0) {\n\t\t\tconst glyph = this.activityPulse.render(2)[0] ?? \"\";\n\t\t\tlines[0] = truncateToWidth(`${glyph} ${lines[0]}`, Math.max(1, width), theme.fg(\"dim\", \"...\"));\n\t\t}\n\t\tif (this.leadingStreak > 0) {\n\t\t\treturn [theme.fg(\"dim\", `${this.leadingStreak} ${t(\"个工具\")}`), ...lines];\n\t\t}\n\t\treturn lines;\n\t}\n\n\tprivate updateDisplay(): void {\n\t\tconst bgFn =\n\t\t\tthis.result?.isError && !this.isPartial ? (text: string) => theme.bg(\"toolErrorBg\", text) : undefined;\n\n\t\tlet hasContent = false;\n\t\tthis.hideComponent = false;\n\t\tif (this.hasRendererDefinition()) {\n\t\t\tconst renderContainer = this.getRenderShell() === \"self\" ? this.selfRenderContainer : this.contentBox;\n\t\t\tif (renderContainer instanceof Box) {\n\t\t\t\trenderContainer.setBgFn(bgFn);\n\t\t\t}\n\t\t\trenderContainer.clear();\n\n\t\t\tlet callComponent: Component | undefined;\n\t\t\tconst callRenderer = this.getCallRenderer();\n\t\t\tif (!callRenderer) {\n\t\t\t\tcallComponent = this.createCallFallback();\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tcallComponent = callRenderer(this.args, theme, this.getRenderContext(this.callRendererComponent));\n\t\t\t\t\tthis.callRendererComponent = callComponent;\n\t\t\t\t} catch {\n\t\t\t\t\tthis.callRendererComponent = undefined;\n\t\t\t\t\tcallComponent = this.createCallFallback();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet resultComponent: Component | undefined;\n\t\t\tif (this.result) {\n\t\t\t\tconst resultRenderer = this.getResultRenderer();\n\t\t\t\tif (!resultRenderer) {\n\t\t\t\t\tresultComponent = this.createResultFallback();\n\t\t\t\t} else {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tresultComponent = resultRenderer(\n\t\t\t\t\t\t\t{ content: this.result.content as any, details: this.result.details },\n\t\t\t\t\t\t\t{ expanded: this.expanded, isPartial: this.isPartial },\n\t\t\t\t\t\t\ttheme,\n\t\t\t\t\t\t\tthis.getRenderContext(this.resultRendererComponent),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.resultRendererComponent = resultComponent;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tthis.resultRendererComponent = undefined;\n\t\t\t\t\t\tresultComponent = this.createResultFallback();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (resultComponent && this.isBlankComponent(resultComponent)) {\n\t\t\t\t\tresultComponent = undefined;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst foldCollapsed =\n\t\t\t\t!this.expanded && !this.result?.isError && !!callComponent && callComponent.render(240).length <= 1;\n\t\t\tif (foldCollapsed && callComponent) {\n\t\t\t\trenderContainer.addChild(new CollapsedToolRow(callComponent, resultComponent));\n\t\t\t\thasContent = true;\n\t\t\t} else {\n\t\t\t\tif (callComponent) {\n\t\t\t\t\trenderContainer.addChild(callComponent);\n\t\t\t\t\thasContent = true;\n\t\t\t\t}\n\t\t\t\tif (resultComponent) {\n\t\t\t\t\trenderContainer.addChild(resultComponent);\n\t\t\t\t\thasContent = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t\thasContent = true;\n\t\t}\n\n\t\tfor (const img of this.imageComponents) {\n\t\t\tthis.removeChild(img);\n\t\t}\n\t\tthis.imageComponents = [];\n\t\tfor (const spacer of this.imageSpacers) {\n\t\t\tthis.removeChild(spacer);\n\t\t}\n\t\tthis.imageSpacers = [];\n\n\t\tif (this.result) {\n\t\t\tconst imageBlocks = this.result.content.filter((c) => c.type === \"image\");\n\t\t\tconst caps = getCapabilities();\n\t\t\tfor (let i = 0; i < imageBlocks.length; i++) {\n\t\t\t\tconst img = imageBlocks[i];\n\t\t\t\tif (caps.images && this.showImages && img.data && img.mimeType) {\n\t\t\t\t\tconst converted = this.convertedImages.get(i);\n\t\t\t\t\tconst imageData = converted?.data ?? img.data;\n\t\t\t\t\tconst imageMimeType = converted?.mimeType ?? img.mimeType;\n\t\t\t\t\tif (caps.images === \"kitty\" && imageMimeType !== \"image/png\") continue;\n\n\t\t\t\t\tconst spacer = new Spacer(1);\n\t\t\t\t\tthis.addChild(spacer);\n\t\t\t\t\tthis.imageSpacers.push(spacer);\n\t\t\t\t\tconst imageComponent = new Image(\n\t\t\t\t\t\timageData,\n\t\t\t\t\t\timageMimeType,\n\t\t\t\t\t\t{ fallbackColor: (s: string) => theme.fg(\"toolOutput\", s) },\n\t\t\t\t\t\t{ maxWidthCells: this.imageWidthCells },\n\t\t\t\t\t);\n\t\t\t\t\tthis.imageComponents.push(imageComponent);\n\t\t\t\t\tthis.addChild(imageComponent);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (this.hasRendererDefinition() && !hasContent && this.imageComponents.length === 0) {\n\t\t\tthis.hideComponent = true;\n\t\t}\n\t\tthis.syncActivityPulse();\n\t}\n\n\tprivate syncActivityPulse(): void {\n\t\tconst live = (!this.result || this.isPartial) && !this.hideComponent;\n\t\tif (live) {\n\t\t\tif (!this.activityPulse) {\n\t\t\t\tthis.activityPulse = new PulseLabel(this.ui, \"\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis.activityPulse?.dispose();\n\t\tthis.activityPulse = undefined;\n\t}\n\n\tprivate getTextOutput(): string {\n\t\treturn getRenderedTextOutput(this.result, this.showImages);\n\t}\n\n\tprivate isBlankComponent(component: Component): boolean {\n\t\tif (!(component instanceof Text)) return false;\n\t\tconst lines = component.render(120);\n\t\treturn lines.every((line) => line.trim() === \"\");\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tconst label = prettyToolLabel(this.toolName);\n\t\tconst hint = compactToolArgHint(this.args);\n\t\tlet text = theme.fg(\"toolTitle\", theme.bold(label));\n\t\tif (hint) text += ` ${theme.fg(\"dim\", hint)}`;\n\t\tconst output = this.getTextOutput();\n\t\tif (this.expanded || this.result?.isError) {\n\t\t\tif (this.args && this.expanded) {\n\t\t\t\ttext += `\\n${theme.fg(\"dim\", JSON.stringify(this.args))}`;\n\t\t\t}\n\t\t\tif (output) text += `\\n${theme.fg(\"toolOutput\", output)}`;\n\t\t} else if (output) {\n\t\t\tconst n = countOutputLines(output);\n\t\t\tif (n > 0) text += formatCollapsedSummary(theme, [`${n} lines`]);\n\t\t}\n\t\treturn text;\n\t}\n}\n\nconst FOLD_STREAK_FROM = 3;\n\n/** Collapse consecutive completed tool rows in place, keeping the last one. */\nexport function foldQuietToolStreak(children: readonly Component[]): void {\n\tfor (const child of children) {\n\t\tif (child instanceof ToolExecutionComponent) child.setStreakPresentation(false, 0);\n\t}\n\tlet index = 0;\n\twhile (index < children.length) {\n\t\tconst child = children[index];\n\t\tif (!(child instanceof ToolExecutionComponent) || !child.isQuietFoldable()) {\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\t\tlet end = index + 1;\n\t\twhile (\n\t\t\tend < children.length &&\n\t\t\tchildren[end] instanceof ToolExecutionComponent &&\n\t\t\t(children[end] as ToolExecutionComponent).isQuietFoldable()\n\t\t) {\n\t\t\tend++;\n\t\t}\n\t\tconst count = end - index;\n\t\tif (count >= FOLD_STREAK_FROM) {\n\t\t\tfor (let i = index; i < end - 1; i++) {\n\t\t\t\t(children[i] as ToolExecutionComponent).setStreakPresentation(true, 0);\n\t\t\t}\n\t\t\t(children[end - 1] as ToolExecutionComponent).setStreakPresentation(false, count - 1);\n\t\t}\n\t\tindex = end;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-execution.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/tool-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,SAAS,EACd,SAAS,EAKT,KAAK,GAAG,EAER,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,mCAAmC,CAAC;AAS3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAQ5E,YAAY,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAuF5E,MAAM,WAAW,oBAAoB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,mBAAmB,CAAY;IACvC,OAAO,CAAC,qBAAqB,CAAC,CAAY;IAC1C,OAAO,CAAC,uBAAuB,CAAC,CAAY;IAC5C,OAAO,CAAC,aAAa,CAAW;IAChC,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,cAAc,CAAC,CAAgB;IACvC,OAAO,CAAC,qBAAqB,CAAC,CAAgB;IAC9C,OAAO,CAAC,EAAE,CAAM;IAChB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAC,CAIb;IACF,OAAO,CAAC,eAAe,CAA8D;I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AAE,OAAO,CAAC;KACjB,EACD,SAAS,UAAQ,GACf,IAAI,CAKN;IAED,OAAO,CAAC,0BAA0B;IAuBlC,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAGnC;IAED,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAGjC;IAED,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAGtC;IAEQ,UAAU,IAAI,IAAI,CAG1B;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAsCvC;IAED,OAAO,CAAC,aAAa;IAmHrB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,mBAAmB;CAiB3B;AAmCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,GAAE,MAAM,GAAG,KAAc,GAAG,IAAI,CAoBxG","sourcesContent":["import {\n\tBox,\n\ttype Component,\n\tContainer,\n\tgetCapabilities,\n\tImage,\n\tSpacer,\n\tText,\n\ttype TUI,\n\ttruncateToWidth,\n} from \"@earendil-works/pi-tui\";\nimport type { ToolDefinition, ToolRenderContext } from \"../../../core/extensions/types.ts\";\nimport { createAllToolDefinitions, type ToolName } from \"../../../core/tools/index.ts\";\nimport {\n\tcompactToolArgHint,\n\tcountOutputLines,\n\tformatCollapsedSummary,\n\tgetTextOutput as getRenderedTextOutput,\n\tprettyToolLabel,\n} from \"../../../core/tools/render-utils.ts\";\nimport type { ToolRenderers } from \"../../../core/tools/renderers/index.ts\";\nimport { t } from \"../../../dal/i18n.ts\";\nimport { stripAnsi } from \"../../../utils/ansi.ts\";\nimport { convertToPng } from \"../../../utils/image-convert.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { keyHint } from \"./keybinding-hints.ts\";\nimport { PulseLabel } from \"./status-indicator.ts\";\n\nexport type { ToolRenderers } from \"../../../core/tools/renderers/index.ts\";\n\nconst FALLBACK_PREVIEW_LINES = 0;\n\n/**\n * Left gutter for tool rows.\n *\n * Two spaces, matching the width of the focus marker (\"\\u25b8 \") so a row does\n * not shift sideways when the cursor lands on it — a transcript that twitches\n * as you arrow through it is worse than one with no cursor at all.\n */\nconst TOOL_ROW_INDENT = \" \";\n\n/** Collapsed tools render as a single Claude-style row: call + muted stats. */\nclass CollapsedToolRow implements Component {\n\tprivate readonly call: Component;\n\tprivate readonly result?: Component;\n\tprivate readonly marker: string;\n\n\tconstructor(call: Component, result?: Component, marker = \"\") {\n\t\tthis.call = call;\n\t\tthis.result = result;\n\t\tthis.marker = marker;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.call.invalidate?.();\n\t\tthis.result?.invalidate?.();\n\t}\n\n\trender(width: number): string[] {\n\t\t// Indent, so a run of tool calls reads as work done *under* the reply\n\t\t// rather than as a peer of it. Without it the transcript is a flat wall\n\t\t// of equally-weighted lines and the eye has nowhere to land.\n\t\tconst indent = this.marker ? \"\" : TOOL_ROW_INDENT;\n\t\tconst inner = Math.max(1, width - TOOL_ROW_INDENT.length);\n\t\tconst callLine = (this.call.render(inner)[0] ?? \"\").replace(/\\s+$/, \"\");\n\t\t// Stripped before recolouring: the result component already paints its\n\t\t// summary \"muted\", and wrapping that in \"dim\" left the inner colour\n\t\t// winning, so the stats came out the same brightness as the description\n\t\t// and the row had two levels where it needs three.\n\t\tconst resultText = stripAnsi(\n\t\t\t(this.result?.render(inner) ?? [])\n\t\t\t\t.map((line) => line.trim())\n\t\t\t\t.filter((line) => line.length > 0)\n\t\t\t\t.join(\" · \"),\n\t\t);\n\t\tif (!callLine.trim() && !resultText) return [];\n\t\tconst combined = resultText ? `${callLine} ${theme.fg(\"dim\", resultText)}` : callLine;\n\t\tconst line = `${indent}${this.marker}${combined}`;\n\t\treturn [truncateToWidth(line, Math.max(1, width), theme.fg(\"dim\", \"...\"))];\n\t}\n}\n\n/**\n * Prefixes one component's first line with the cursor marker.\n *\n * An expanded call is not a single row, so it cannot go through\n * CollapsedToolRow — but the cursor still has to be visible on it, or moving\n * onto something you already opened looks like the keypress did nothing.\n */\nclass FocusMarkerRow implements Component {\n\tprivate readonly inner: Component;\n\tprivate readonly marker: string;\n\n\tconstructor(inner: Component, marker: string) {\n\t\tthis.inner = inner;\n\t\tthis.marker = marker;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.inner.invalidate?.();\n\t}\n\n\trender(width: number): string[] {\n\t\t// The gutter has to come out of the child's width, not be added on top of\n\t\t// it: prepending without shrinking pushed rendered lines past the\n\t\t// terminal edge and tripped the TUI's own width assertion\n\t\t// (\"Rendered line 200 exceeds terminal width (82 > 80)\").\n\t\tconst gutter = stripAnsi(this.marker).length;\n\t\tconst lines = this.inner.render(Math.max(1, width - gutter));\n\t\tif (lines.length === 0) return lines;\n\t\tconst pad = \" \".repeat(gutter);\n\t\treturn [`${this.marker}${lines[0]}`, ...lines.slice(1).map((line) => `${pad}${line}`)];\n\t}\n}\n\nexport interface ToolExecutionOptions {\n\tshowImages?: boolean;\n\timageWidthCells?: number;\n}\n\nexport class ToolExecutionComponent extends Container {\n\tprivate contentBox: Box;\n\tprivate contentText: Text;\n\tprivate selfRenderContainer: Container;\n\tprivate callRendererComponent?: Component;\n\tprivate resultRendererComponent?: Component;\n\tprivate rendererState: any = {};\n\tprivate imageComponents: Image[] = [];\n\tprivate imageSpacers: Spacer[] = [];\n\tprivate toolName: string;\n\tprivate toolCallId: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate imageWidthCells: number;\n\tprivate isPartial = true;\n\tprivate toolDefinition?: ToolRenderers;\n\tprivate builtInToolDefinition?: ToolRenderers;\n\tprivate ui: TUI;\n\tprivate cwd: string;\n\tprivate executionStarted = false;\n\tprivate argsComplete = false;\n\tprivate result?: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tisError: boolean;\n\t\tdetails?: any;\n\t};\n\tprivate convertedImages: Map<number, { data: string; mimeType: string }> = new Map();\n\tprivate hideComponent = false;\n\tprivate activityPulse?: PulseLabel;\n\tprivate collapsedAway = false;\n\t/**\n\t * Whether the transcript cursor is sitting on this call.\n\t *\n\t * Purely presentational — it draws the arrow that says \"ctrl+o acts on this\n\t * one\". The transcript is an append-only log with no selection model of its\n\t * own, so the cursor lives in interactive-mode and each component only\n\t * needs to know whether it is the chosen one.\n\t */\n\tprivate focused = false;\n\tprivate leadingStreak = 0;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\ttoolCallId: string,\n\t\targs: any,\n\t\toptions: ToolExecutionOptions = {},\n\t\ttoolDefinition: ToolRenderers | ToolDefinition<any, any, any> | undefined,\n\t\tui: TUI,\n\t\tcwd: string,\n\t) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.toolCallId = toolCallId;\n\t\tthis.args = args;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.builtInToolDefinition = createAllToolDefinitions(cwd)[toolName as ToolName];\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.imageWidthCells = options.imageWidthCells ?? 60;\n\t\tthis.ui = ui;\n\t\tthis.cwd = cwd;\n\n\t\t// Always create all shell variants. contentBox is used for default renderer-based composition.\n\t\t// selfRenderContainer is used when the tool renders its own framing.\n\t\t// contentText is reserved for generic fallback rendering when no tool definition exists.\n\t\tthis.contentBox = new Box(0, 0);\n\t\tthis.contentText = new Text(\"\", 0, 0);\n\t\tthis.selfRenderContainer = new Container();\n\n\t\tif (this.hasRendererDefinition()) {\n\t\t\tthis.addChild(this.getRenderShell() === \"self\" ? this.selfRenderContainer : this.contentBox);\n\t\t} else {\n\t\t\tthis.addChild(this.contentText);\n\t\t}\n\n\t\tthis.updateDisplay();\n\t}\n\n\tdispose(): void {\n\t\tthis.activityPulse?.dispose();\n\t\tthis.activityPulse = undefined;\n\t}\n\n\t/** Completed, collapsed, not an error — safe to fold into a streak. */\n\tisQuietFoldable(): boolean {\n\t\treturn !this.expanded && !!this.result && !this.result.isError && !this.isPartial;\n\t}\n\n\t/**\n\t * The arrow drawn at the head of a collapsed row.\n\t *\n\t * Only the focused row gets one, and unfocused rows keep their existing\n\t * left edge: reserving a marker column on every row would shift the whole\n\t * transcript two characters right to serve a cursor that is usually not\n\t * even on screen.\n\t */\n\tprivate focusMarker(): string {\n\t\treturn this.focused ? theme.fg(\"accent\", this.expanded ? \"\\u25be \" : \"\\u25b8 \") : \"\";\n\t}\n\n\tsetFocused(focused: boolean): void {\n\t\tif (this.focused === focused) return;\n\t\tthis.focused = focused;\n\t\tthis.invalidate();\n\t}\n\n\tsetStreakPresentation(collapsedAway: boolean, leadingStreak = 0): void {\n\t\tthis.collapsedAway = collapsedAway;\n\t\tthis.leadingStreak = collapsedAway ? 0 : leadingStreak;\n\t}\n\n\tprivate getCallRenderer(): ToolRenderers[\"renderCall\"] | undefined {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderCall;\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderCall;\n\t\t}\n\t\treturn this.toolDefinition.renderCall ?? this.builtInToolDefinition.renderCall;\n\t}\n\n\tprivate getResultRenderer(): ToolRenderers[\"renderResult\"] | undefined {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderResult;\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderResult;\n\t\t}\n\t\treturn this.toolDefinition.renderResult ?? this.builtInToolDefinition.renderResult;\n\t}\n\n\tprivate hasRendererDefinition(): boolean {\n\t\treturn this.builtInToolDefinition !== undefined || this.toolDefinition !== undefined;\n\t}\n\n\tprivate getRenderShell(): \"default\" | \"self\" {\n\t\tif (!this.builtInToolDefinition) {\n\t\t\treturn this.toolDefinition?.renderShell ?? \"default\";\n\t\t}\n\t\tif (!this.toolDefinition) {\n\t\t\treturn this.builtInToolDefinition.renderShell ?? \"default\";\n\t\t}\n\t\treturn this.toolDefinition.renderShell ?? this.builtInToolDefinition.renderShell ?? \"default\";\n\t}\n\n\tprivate getRenderContext(lastComponent: Component | undefined): ToolRenderContext {\n\t\treturn {\n\t\t\targs: this.args,\n\t\t\ttoolCallId: this.toolCallId,\n\t\t\tinvalidate: () => {\n\t\t\t\tthis.invalidate();\n\t\t\t\tthis.ui.requestRender();\n\t\t\t},\n\t\t\tlastComponent,\n\t\t\tstate: this.rendererState,\n\t\t\tcwd: this.cwd,\n\t\t\texecutionStarted: this.executionStarted,\n\t\t\targsComplete: this.argsComplete,\n\t\t\tisPartial: this.isPartial,\n\t\t\texpanded: this.expanded,\n\t\t\tshowImages: this.showImages,\n\t\t\tisError: this.result?.isError ?? false,\n\t\t};\n\t}\n\n\tprivate createCallFallback(): Component {\n\t\tconst label = prettyToolLabel(this.toolName);\n\t\tconst hint = compactToolArgHint(this.args);\n\t\tconst title = theme.fg(\"toolTitle\", theme.bold(label));\n\t\treturn new Text(hint ? `${title} ${theme.fg(\"dim\", hint)}` : title, 0, 0);\n\t}\n\n\tprivate createResultFallback(): Component | undefined {\n\t\tconst output = this.getTextOutput();\n\t\tif (!output) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (!this.expanded && !this.result?.isError) {\n\t\t\tconst n = countOutputLines(output);\n\t\t\tconst summary = formatCollapsedSummary(theme, n > 0 ? [`${n} lines`] : []);\n\t\t\treturn summary ? new Text(summary, 0, 0) : undefined;\n\t\t}\n\n\t\tconst lines = output.split(\"\\n\");\n\t\tconst displayLines = this.expanded ? lines : lines.slice(0, Math.max(FALLBACK_PREVIEW_LINES, 0));\n\t\tconst remaining = lines.length - displayLines.length;\n\t\tlet text = displayLines.map((line) => theme.fg(\"toolOutput\", line)).join(\"\\n\");\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t\treturn text ? new Text(text, 0, 0) : undefined;\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tthis.updateDisplay();\n\t}\n\n\tmarkExecutionStarted(): void {\n\t\tthis.executionStarted = true;\n\t\tthis.updateDisplay();\n\t\tthis.ui.requestRender();\n\t}\n\n\tsetArgsComplete(): void {\n\t\tthis.argsComplete = true;\n\t\tthis.updateDisplay();\n\t\tthis.ui.requestRender();\n\t}\n\n\tupdateResult(\n\t\tresult: {\n\t\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\t\tdetails?: any;\n\t\t\tisError: boolean;\n\t\t},\n\t\tisPartial = false,\n\t): void {\n\t\tthis.result = result;\n\t\tthis.isPartial = isPartial;\n\t\tthis.updateDisplay();\n\t\tthis.maybeConvertImagesForKitty();\n\t}\n\n\tprivate maybeConvertImagesForKitty(): void {\n\t\tconst caps = getCapabilities();\n\t\tif (caps.images !== \"kitty\") return;\n\t\tif (!this.result) return;\n\n\t\tconst imageBlocks = this.result.content.filter((c) => c.type === \"image\");\n\t\tfor (let i = 0; i < imageBlocks.length; i++) {\n\t\t\tconst img = imageBlocks[i];\n\t\t\tif (!img.data || !img.mimeType) continue;\n\t\t\tif (img.mimeType === \"image/png\") continue;\n\t\t\tif (this.convertedImages.has(i)) continue;\n\n\t\t\tconst index = i;\n\t\t\tconvertToPng(img.data, img.mimeType).then((converted) => {\n\t\t\t\tif (converted) {\n\t\t\t\t\tthis.convertedImages.set(index, converted);\n\t\t\t\t\tthis.updateDisplay();\n\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetShowImages(show: boolean): void {\n\t\tthis.showImages = show;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetImageWidthCells(width: number): void {\n\t\tthis.imageWidthCells = Math.max(1, Math.floor(width));\n\t\tthis.updateDisplay();\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tthis.updateDisplay();\n\t}\n\n\toverride render(width: number): string[] {\n\t\tif (this.hideComponent || this.collapsedAway) {\n\t\t\treturn [];\n\t\t}\n\n\t\tlet lines: string[];\n\t\tif (this.hasRendererDefinition() && this.getRenderShell() === \"self\") {\n\t\t\tconst contentLines = this.selfRenderContainer.render(width);\n\t\t\tif (this.imageComponents.length === 0 && contentLines.every((line) => line.trim() === \"\")) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tlines = [];\n\t\t\tif (contentLines.length > 0) {\n\t\t\t\tlines.push(...contentLines);\n\t\t\t}\n\t\t\tfor (let i = 0; i < this.imageComponents.length; i++) {\n\t\t\t\tconst spacer = this.imageSpacers[i];\n\t\t\t\tif (spacer) {\n\t\t\t\t\tlines.push(...spacer.render(width));\n\t\t\t\t}\n\t\t\t\tconst imageComponent = this.imageComponents[i];\n\t\t\t\tif (imageComponent) {\n\t\t\t\t\tlines.push(...imageComponent.render(width));\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tlines = super.render(width);\n\t\t}\n\n\t\tif (this.activityPulse && lines.length > 0) {\n\t\t\tconst glyph = this.activityPulse.render(2)[0] ?? \"\";\n\t\t\tlines[0] = truncateToWidth(`${glyph} ${lines[0]}`, Math.max(1, width), theme.fg(\"dim\", \"...\"));\n\t\t}\n\t\tif (this.leadingStreak > 0) {\n\t\t\treturn [theme.fg(\"dim\", `${this.leadingStreak} ${t(\"个工具\")}`), ...lines];\n\t\t}\n\t\treturn lines;\n\t}\n\n\tprivate updateDisplay(): void {\n\t\tconst bgFn =\n\t\t\tthis.result?.isError && !this.isPartial ? (text: string) => theme.bg(\"toolErrorBg\", text) : undefined;\n\n\t\tlet hasContent = false;\n\t\tthis.hideComponent = false;\n\t\tif (this.hasRendererDefinition()) {\n\t\t\tconst renderContainer = this.getRenderShell() === \"self\" ? this.selfRenderContainer : this.contentBox;\n\t\t\tif (renderContainer instanceof Box) {\n\t\t\t\trenderContainer.setBgFn(bgFn);\n\t\t\t}\n\t\t\trenderContainer.clear();\n\n\t\t\tlet callComponent: Component | undefined;\n\t\t\tconst callRenderer = this.getCallRenderer();\n\t\t\tif (!callRenderer) {\n\t\t\t\tcallComponent = this.createCallFallback();\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tcallComponent = callRenderer(this.args, theme, this.getRenderContext(this.callRendererComponent));\n\t\t\t\t\tthis.callRendererComponent = callComponent;\n\t\t\t\t} catch {\n\t\t\t\t\tthis.callRendererComponent = undefined;\n\t\t\t\t\tcallComponent = this.createCallFallback();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet resultComponent: Component | undefined;\n\t\t\tif (this.result) {\n\t\t\t\tconst resultRenderer = this.getResultRenderer();\n\t\t\t\tif (!resultRenderer) {\n\t\t\t\t\tresultComponent = this.createResultFallback();\n\t\t\t\t} else {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tresultComponent = resultRenderer(\n\t\t\t\t\t\t\t{ content: this.result.content as any, details: this.result.details },\n\t\t\t\t\t\t\t{ expanded: this.expanded, isPartial: this.isPartial },\n\t\t\t\t\t\t\ttheme,\n\t\t\t\t\t\t\tthis.getRenderContext(this.resultRendererComponent),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.resultRendererComponent = resultComponent;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tthis.resultRendererComponent = undefined;\n\t\t\t\t\t\tresultComponent = this.createResultFallback();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (resultComponent && this.isBlankComponent(resultComponent)) {\n\t\t\t\t\tresultComponent = undefined;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst foldCollapsed =\n\t\t\t\t!this.expanded && !this.result?.isError && !!callComponent && callComponent.render(240).length <= 1;\n\t\t\tif (foldCollapsed && callComponent) {\n\t\t\t\trenderContainer.addChild(new CollapsedToolRow(callComponent, resultComponent, this.focusMarker()));\n\t\t\t\thasContent = true;\n\t\t\t} else {\n\t\t\t\tif (callComponent) {\n\t\t\t\t\t// Same gutter as the collapsed row, so expanding a call does not\n\t\t\t\t\t// make it jump left out of the column its neighbours sit in.\n\t\t\t\t\trenderContainer.addChild(new FocusMarkerRow(callComponent, this.focusMarker() || TOOL_ROW_INDENT));\n\t\t\t\t\thasContent = true;\n\t\t\t\t}\n\t\t\t\tif (resultComponent) {\n\t\t\t\t\trenderContainer.addChild(resultComponent);\n\t\t\t\t\thasContent = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t\thasContent = true;\n\t\t}\n\n\t\tfor (const img of this.imageComponents) {\n\t\t\tthis.removeChild(img);\n\t\t}\n\t\tthis.imageComponents = [];\n\t\tfor (const spacer of this.imageSpacers) {\n\t\t\tthis.removeChild(spacer);\n\t\t}\n\t\tthis.imageSpacers = [];\n\n\t\tif (this.result) {\n\t\t\tconst imageBlocks = this.result.content.filter((c) => c.type === \"image\");\n\t\t\tconst caps = getCapabilities();\n\t\t\tfor (let i = 0; i < imageBlocks.length; i++) {\n\t\t\t\tconst img = imageBlocks[i];\n\t\t\t\tif (caps.images && this.showImages && img.data && img.mimeType) {\n\t\t\t\t\tconst converted = this.convertedImages.get(i);\n\t\t\t\t\tconst imageData = converted?.data ?? img.data;\n\t\t\t\t\tconst imageMimeType = converted?.mimeType ?? img.mimeType;\n\t\t\t\t\tif (caps.images === \"kitty\" && imageMimeType !== \"image/png\") continue;\n\n\t\t\t\t\tconst spacer = new Spacer(1);\n\t\t\t\t\tthis.addChild(spacer);\n\t\t\t\t\tthis.imageSpacers.push(spacer);\n\t\t\t\t\tconst imageComponent = new Image(\n\t\t\t\t\t\timageData,\n\t\t\t\t\t\timageMimeType,\n\t\t\t\t\t\t{ fallbackColor: (s: string) => theme.fg(\"toolOutput\", s) },\n\t\t\t\t\t\t{ maxWidthCells: this.imageWidthCells },\n\t\t\t\t\t);\n\t\t\t\t\tthis.imageComponents.push(imageComponent);\n\t\t\t\t\tthis.addChild(imageComponent);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (this.hasRendererDefinition() && !hasContent && this.imageComponents.length === 0) {\n\t\t\tthis.hideComponent = true;\n\t\t}\n\t\tthis.syncActivityPulse();\n\t}\n\n\tprivate syncActivityPulse(): void {\n\t\tconst live = (!this.result || this.isPartial) && !this.hideComponent;\n\t\tif (live) {\n\t\t\tif (!this.activityPulse) {\n\t\t\t\tthis.activityPulse = new PulseLabel(this.ui, \"\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis.activityPulse?.dispose();\n\t\tthis.activityPulse = undefined;\n\t}\n\n\tprivate getTextOutput(): string {\n\t\treturn getRenderedTextOutput(this.result, this.showImages);\n\t}\n\n\tprivate isBlankComponent(component: Component): boolean {\n\t\tif (!(component instanceof Text)) return false;\n\t\tconst lines = component.render(120);\n\t\treturn lines.every((line) => line.trim() === \"\");\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tconst label = prettyToolLabel(this.toolName);\n\t\tconst hint = compactToolArgHint(this.args);\n\t\tlet text = theme.fg(\"toolTitle\", theme.bold(label));\n\t\tif (hint) text += ` ${theme.fg(\"dim\", hint)}`;\n\t\tconst output = this.getTextOutput();\n\t\tif (this.expanded || this.result?.isError) {\n\t\t\tif (this.args && this.expanded) {\n\t\t\t\ttext += `\\n${theme.fg(\"dim\", JSON.stringify(this.args))}`;\n\t\t\t}\n\t\t\tif (output) text += `\\n${theme.fg(\"toolOutput\", output)}`;\n\t\t} else if (output) {\n\t\t\tconst n = countOutputLines(output);\n\t\t\tif (n > 0) text += formatCollapsedSummary(theme, [`${n} lines`]);\n\t\t}\n\t\treturn text;\n\t}\n}\n\nconst FOLD_STREAK_FROM = 3;\n\n/** Collapse consecutive completed tool rows in place, keeping the last one. */\n/**\n * Whether a child puts nothing on screen.\n *\n * The transcript interleaves assistant messages with tool calls, and a message\n * that is only hidden thinking draws nothing — but it is still a sibling. The\n * streak scan used to stop at it, so a turn that alternated\n * message/tool/message/tool never had three tool calls in a row by that\n * measure and nothing ever folded. That is how a single turn filled the screen\n * with thirty rows of finished work: the folding was written, wired to\n * tool_execution_end, and silently doing nothing.\n *\n * Escape sequences are stripped before the check, so a child emitting only\n * colour or terminal-integration codes still counts as invisible.\n */\nfunction rendersNothing(child: Component): boolean {\n\t// Asked, never measured. Laying the child out to find out cost 2.4s per\n\t// call on a 200-component transcript — Markdown caches exactly one\n\t// (text, width) pair, so probing at a width the real frame does not use\n\t// threw that cache away and re-laid-out the whole history, on every single\n\t// tool_execution_end. A component that cannot answer counts as visible:\n\t// failing to fold is a cosmetic loss, guessing wrong is a correctness one.\n\tconst probe = (child as { isBlank?: () => boolean }).isBlank;\n\tif (typeof probe !== \"function\") return false;\n\ttry {\n\t\treturn probe.call(child) === true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Collapse a finished run of tool calls into one row plus a count.\n *\n * `scope` decides how far back it may reach, and that is a rendering concern,\n * not a cosmetic one. The transcript renderer can only patch lines that were\n * visible: when the first changed line sits above the viewport it clears the\n * screen AND the scrollback and repaints everything (tui-main-screen.ts,\n * `firstChanged < prevViewportTop`). Rewriting a streak that has already\n * scrolled away therefore costs a full redraw — which looks like the screen\n * jumping, destroys the user's scroll-back history, and on a long transcript\n * fires on every single tool_execution_end.\n *\n * \"tail\" — only the run at the end of the document, which is the one still\n * being extended and still on screen. Changes stay near the bottom, so the\n * renderer patches instead of repainting. Use this while a turn is running.\n * \"all\" — every run. Only safe when the frame is being drawn from scratch\n * anyway, i.e. right after a session is rebuilt, where there is no previous\n * viewport to disturb.\n */\nexport function foldQuietToolStreak(children: readonly Component[], scope: \"tail\" | \"all\" = \"tail\"): void {\n\tif (scope === \"all\") {\n\t\tfor (const child of children) {\n\t\t\tif (child instanceof ToolExecutionComponent) child.setStreakPresentation(false, 0);\n\t\t}\n\t\tlet index = 0;\n\t\twhile (index < children.length) {\n\t\t\tconst run = collectRunFrom(children, index);\n\t\t\tif (run === null) {\n\t\t\t\tindex++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tapplyRun(run.members);\n\t\t\tindex = Math.max(run.end, index + 1);\n\t\t}\n\t\treturn;\n\t}\n\n\tconst run = collectTrailingRun(children);\n\tif (run.length > 0) applyRun(run);\n}\n\n/** Mark all but the last member of a run as folded away, with the count on the last. */\nfunction applyRun(members: readonly ToolExecutionComponent[]): void {\n\tif (members.length < FOLD_STREAK_FROM) return;\n\tfor (let i = 0; i < members.length - 1; i++) {\n\t\tmembers[i]!.setStreakPresentation(true, 0);\n\t}\n\tmembers[members.length - 1]!.setStreakPresentation(false, members.length - 1);\n}\n\n/** The run starting at `index`, or null when nothing foldable starts there. */\nfunction collectRunFrom(\n\tchildren: readonly Component[],\n\tindex: number,\n): { members: ToolExecutionComponent[]; end: number } | null {\n\tconst child = children[index];\n\tif (!(child instanceof ToolExecutionComponent) || !child.isQuietFoldable()) return null;\n\tconst members: ToolExecutionComponent[] = [child];\n\tlet end = index + 1;\n\tlet cursor = index + 1;\n\twhile (cursor < children.length) {\n\t\tconst next = children[cursor];\n\t\tif (next instanceof ToolExecutionComponent && next.isQuietFoldable()) {\n\t\t\tmembers.push(next);\n\t\t\tcursor++;\n\t\t\tend = cursor;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!(next instanceof ToolExecutionComponent) && rendersNothing(next)) {\n\t\t\tcursor++;\n\t\t\tcontinue;\n\t\t}\n\t\tbreak;\n\t}\n\treturn { members, end };\n}\n\n/** The run at the very end of the document, stepping back over invisible siblings. */\nfunction collectTrailingRun(children: readonly Component[]): ToolExecutionComponent[] {\n\tconst members: ToolExecutionComponent[] = [];\n\tfor (let i = children.length - 1; i >= 0; i--) {\n\t\tconst child = children[i];\n\t\tif (child instanceof ToolExecutionComponent && child.isQuietFoldable()) {\n\t\t\tmembers.unshift(child);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!(child instanceof ToolExecutionComponent) && rendersNothing(child!)) continue;\n\t\tbreak;\n\t}\n\treturn members;\n}\n"]}
|