@apholdings/jensen-code 0.0.3 → 0.0.5

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.
Files changed (166) hide show
  1. package/dist/cli/args.d.ts.map +1 -1
  2. package/dist/cli/args.js +6 -6
  3. package/dist/cli/args.js.map +1 -1
  4. package/dist/config.d.ts +6 -5
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +32 -25
  7. package/dist/config.js.map +1 -1
  8. package/dist/core/agent-session.d.ts +1 -0
  9. package/dist/core/agent-session.d.ts.map +1 -1
  10. package/dist/core/agent-session.js +25 -0
  11. package/dist/core/agent-session.js.map +1 -1
  12. package/dist/core/extensions/loader.d.ts.map +1 -1
  13. package/dist/core/extensions/loader.js +1 -1
  14. package/dist/core/extensions/loader.js.map +1 -1
  15. package/dist/core/footer-data-provider.d.ts +4 -1
  16. package/dist/core/footer-data-provider.d.ts.map +1 -1
  17. package/dist/core/footer-data-provider.js +25 -11
  18. package/dist/core/footer-data-provider.js.map +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/modes/interactive/components/custom-editor.d.ts +1 -0
  24. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  25. package/dist/modes/interactive/components/custom-editor.js +5 -0
  26. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  27. package/dist/modes/interactive/components/footer.d.ts +0 -2
  28. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  29. package/dist/modes/interactive/components/footer.js +8 -146
  30. package/dist/modes/interactive/components/footer.js.map +1 -1
  31. package/dist/modes/interactive/components/header.d.ts +9 -3
  32. package/dist/modes/interactive/components/header.d.ts.map +1 -1
  33. package/dist/modes/interactive/components/header.js +125 -196
  34. package/dist/modes/interactive/components/header.js.map +1 -1
  35. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  36. package/dist/modes/interactive/components/tool-execution.js +1 -2
  37. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  38. package/dist/modes/interactive/interactive-mode.d.ts +23 -4
  39. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  40. package/dist/modes/interactive/interactive-mode.js +657 -243
  41. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  42. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  43. package/dist/modes/interactive/theme/theme.js +2 -0
  44. package/dist/modes/interactive/theme/theme.js.map +1 -1
  45. package/dist/utils/frontmatter.d.ts.map +1 -1
  46. package/dist/utils/frontmatter.js +8 -4
  47. package/dist/utils/frontmatter.js.map +1 -1
  48. package/dist/utils/tools-manager.d.ts.map +1 -1
  49. package/dist/utils/tools-manager.js +2 -2
  50. package/dist/utils/tools-manager.js.map +1 -1
  51. package/examples/extensions/osgrep.ts +643 -0
  52. package/examples/extensions/subagent/agents.ts +150 -38
  53. package/examples/extensions/subagent/index.ts +634 -514
  54. package/package.json +4 -3
  55. package/examples/README.md +0 -25
  56. package/examples/extensions/README.md +0 -206
  57. package/examples/extensions/antigravity-image-gen.ts +0 -416
  58. package/examples/extensions/auto-commit-on-exit.ts +0 -50
  59. package/examples/extensions/bash-spawn-hook.ts +0 -31
  60. package/examples/extensions/bookmark.ts +0 -51
  61. package/examples/extensions/built-in-tool-renderer.ts +0 -247
  62. package/examples/extensions/claude-rules.ts +0 -87
  63. package/examples/extensions/commands.ts +0 -73
  64. package/examples/extensions/confirm-destructive.ts +0 -60
  65. package/examples/extensions/custom-compaction.ts +0 -115
  66. package/examples/extensions/custom-footer.ts +0 -65
  67. package/examples/extensions/custom-header.ts +0 -74
  68. package/examples/extensions/custom-provider-anthropic/index.ts +0 -605
  69. package/examples/extensions/custom-provider-anthropic/package-lock.json +0 -24
  70. package/examples/extensions/custom-provider-anthropic/package.json +0 -19
  71. package/examples/extensions/custom-provider-gitlab-duo/index.ts +0 -350
  72. package/examples/extensions/custom-provider-gitlab-duo/package.json +0 -16
  73. package/examples/extensions/custom-provider-gitlab-duo/test.ts +0 -82
  74. package/examples/extensions/custom-provider-qwen-cli/index.ts +0 -346
  75. package/examples/extensions/custom-provider-qwen-cli/package.json +0 -16
  76. package/examples/extensions/dirty-repo-guard.ts +0 -57
  77. package/examples/extensions/doom-overlay/README.md +0 -46
  78. package/examples/extensions/doom-overlay/doom/build/doom.js +0 -21
  79. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  80. package/examples/extensions/doom-overlay/doom/build.sh +0 -152
  81. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +0 -72
  82. package/examples/extensions/doom-overlay/doom-component.ts +0 -132
  83. package/examples/extensions/doom-overlay/doom-engine.ts +0 -173
  84. package/examples/extensions/doom-overlay/doom-keys.ts +0 -104
  85. package/examples/extensions/doom-overlay/index.ts +0 -75
  86. package/examples/extensions/doom-overlay/wad-finder.ts +0 -51
  87. package/examples/extensions/dynamic-resources/SKILL.md +0 -8
  88. package/examples/extensions/dynamic-resources/dynamic.json +0 -79
  89. package/examples/extensions/dynamic-resources/dynamic.md +0 -5
  90. package/examples/extensions/dynamic-resources/index.ts +0 -16
  91. package/examples/extensions/dynamic-tools.ts +0 -75
  92. package/examples/extensions/event-bus.ts +0 -44
  93. package/examples/extensions/file-trigger.ts +0 -42
  94. package/examples/extensions/git-checkpoint.ts +0 -54
  95. package/examples/extensions/handoff.ts +0 -151
  96. package/examples/extensions/hello.ts +0 -26
  97. package/examples/extensions/inline-bash.ts +0 -95
  98. package/examples/extensions/input-transform.ts +0 -44
  99. package/examples/extensions/interactive-shell.ts +0 -197
  100. package/examples/extensions/mac-system-theme.ts +0 -48
  101. package/examples/extensions/message-renderer.ts +0 -60
  102. package/examples/extensions/minimal-mode.ts +0 -427
  103. package/examples/extensions/modal-editor.ts +0 -86
  104. package/examples/extensions/model-status.ts +0 -32
  105. package/examples/extensions/notify.ts +0 -56
  106. package/examples/extensions/overlay-qa-tests.ts +0 -1349
  107. package/examples/extensions/overlay-test.ts +0 -151
  108. package/examples/extensions/permission-gate.ts +0 -35
  109. package/examples/extensions/pirate.ts +0 -48
  110. package/examples/extensions/plan-mode/README.md +0 -65
  111. package/examples/extensions/plan-mode/index.ts +0 -341
  112. package/examples/extensions/plan-mode/utils.ts +0 -168
  113. package/examples/extensions/preset.ts +0 -399
  114. package/examples/extensions/protected-paths.ts +0 -31
  115. package/examples/extensions/provider-payload.ts +0 -15
  116. package/examples/extensions/qna.ts +0 -120
  117. package/examples/extensions/question.ts +0 -265
  118. package/examples/extensions/questionnaire.ts +0 -428
  119. package/examples/extensions/rainbow-editor.ts +0 -89
  120. package/examples/extensions/reload-runtime.ts +0 -38
  121. package/examples/extensions/rpc-demo.ts +0 -125
  122. package/examples/extensions/sandbox/index.ts +0 -319
  123. package/examples/extensions/sandbox/package-lock.json +0 -92
  124. package/examples/extensions/sandbox/package.json +0 -19
  125. package/examples/extensions/send-user-message.ts +0 -98
  126. package/examples/extensions/session-name.ts +0 -28
  127. package/examples/extensions/shutdown-command.ts +0 -64
  128. package/examples/extensions/snake.ts +0 -344
  129. package/examples/extensions/space-invaders.ts +0 -561
  130. package/examples/extensions/ssh.ts +0 -221
  131. package/examples/extensions/status-line.ts +0 -41
  132. package/examples/extensions/subagent/README.md +0 -172
  133. package/examples/extensions/subagent/agents/planner.md +0 -37
  134. package/examples/extensions/subagent/agents/reviewer.md +0 -35
  135. package/examples/extensions/subagent/agents/scout.md +0 -50
  136. package/examples/extensions/subagent/agents/worker.md +0 -24
  137. package/examples/extensions/subagent/prompts/implement-and-review.md +0 -10
  138. package/examples/extensions/subagent/prompts/implement.md +0 -10
  139. package/examples/extensions/subagent/prompts/scout-and-plan.md +0 -9
  140. package/examples/extensions/summarize.ts +0 -196
  141. package/examples/extensions/system-prompt-header.ts +0 -18
  142. package/examples/extensions/timed-confirm.ts +0 -71
  143. package/examples/extensions/titlebar-spinner.ts +0 -59
  144. package/examples/extensions/todo.ts +0 -300
  145. package/examples/extensions/tool-override.ts +0 -144
  146. package/examples/extensions/tools.ts +0 -147
  147. package/examples/extensions/trigger-compact.ts +0 -41
  148. package/examples/extensions/truncated-tool.ts +0 -193
  149. package/examples/extensions/widget-placement.ts +0 -18
  150. package/examples/extensions/with-deps/index.ts +0 -33
  151. package/examples/extensions/with-deps/package-lock.json +0 -31
  152. package/examples/extensions/with-deps/package.json +0 -22
  153. package/examples/rpc-extension-ui.ts +0 -632
  154. package/examples/sdk/01-minimal.ts +0 -23
  155. package/examples/sdk/02-custom-model.ts +0 -50
  156. package/examples/sdk/03-custom-prompt.ts +0 -56
  157. package/examples/sdk/04-skills.ts +0 -47
  158. package/examples/sdk/05-tools.ts +0 -57
  159. package/examples/sdk/06-extensions.ts +0 -89
  160. package/examples/sdk/07-context-files.ts +0 -41
  161. package/examples/sdk/08-prompt-templates.ts +0 -48
  162. package/examples/sdk/09-api-keys-and-oauth.ts +0 -49
  163. package/examples/sdk/10-settings.ts +0 -52
  164. package/examples/sdk/11-sessions.ts +0 -49
  165. package/examples/sdk/12-full-control.ts +0 -83
  166. package/examples/sdk/README.md +0 -145
@@ -1 +1 @@
1
- {"version":3,"file":"tool-execution.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/tool-execution.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,SAAS,EAOT,KAAK,GAAG,EAER,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAmDxE,MAAM,WAAW,oBAAoB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAUD;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,QAAQ,CAA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O,GAAG,IAAI,CAGnC;IAED,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAGjC;IAEQ,UAAU,IAAI,IAAI,CAG1B;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAKvC;IAED,OAAO,CAAC,aAAa;IAiIrB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA+EzB,OAAO,CAAC,aAAa;IA2BrB,OAAO,CAAC,mBAAmB;CA8S3B","sourcesContent":["import * as os from \"node:os\";\nimport {\n\tBox,\n\tContainer,\n\tgetCapabilities,\n\tgetImageDimensions,\n\tImage,\n\timageFallback,\n\tSpacer,\n\tText,\n\ttype TUI,\n\ttruncateToWidth,\n} from \"@apholdings/jensen-tui\";\nimport stripAnsi from \"strip-ansi\";\nimport type { ToolDefinition } from \"../../../core/extensions/types.js\";\nimport { computeEditDiff, type EditDiffError, type EditDiffResult } from \"../../../core/tools/edit-diff.js\";\nimport { allTools } from \"../../../core/tools/index.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from \"../../../core/tools/truncate.js\";\nimport { convertToPng } from \"../../../utils/image-convert.js\";\nimport { sanitizeBinaryOutput } from \"../../../utils/shell.js\";\nimport { getLanguageFromPath, highlightCode, theme } from \"../theme/theme.js\";\nimport { renderDiff } from \"./diff.js\";\nimport { keyHint } from \"./keybinding-hints.js\";\nimport { truncateToVisualLines } from \"./visual-truncate.js\";\n\n// Preview line limit for bash when not expanded\nconst BASH_PREVIEW_LINES = 5;\n// During partial write tool-call streaming, re-highlight the first N lines fully\n// to keep multiline tokenization mostly correct without re-highlighting the full file.\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n\n/**\n * Convert absolute path to tilde notation if it's in home directory\n */\nfunction shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\n/**\n * Replace tabs with spaces for consistent rendering\n */\nfunction replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\n/**\n * Normalize control characters for terminal preview rendering.\n * Keep tool arguments unchanged, sanitize only display text.\n */\nfunction normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\n/** Safely coerce value to string for display. Returns null if invalid type. */\nfunction str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null; // Invalid type\n}\n\nexport interface ToolExecutionOptions {\n\tshowImages?: boolean; // default: true (only used if terminal supports images)\n}\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\n\n/**\n * Component that renders a tool call with its result (updateable)\n */\nexport class ToolExecutionComponent extends Container {\n\tprivate contentBox: Box; // Used for custom tools and bash visual truncation\n\tprivate contentText: Text; // For built-in tools (with its own padding/bg)\n\tprivate imageComponents: Image[] = [];\n\tprivate imageSpacers: Spacer[] = [];\n\tprivate toolName: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate isPartial = true;\n\tprivate toolDefinition?: ToolDefinition;\n\tprivate ui: TUI;\n\tprivate cwd: string;\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\t// Cached edit diff preview (computed when args arrive, before tool executes)\n\tprivate editDiffPreview?: EditDiffResult | EditDiffError;\n\tprivate editDiffArgsKey?: string; // Track which args the preview is for\n\t// Cached converted images for Kitty protocol (which requires PNG), keyed by index\n\tprivate convertedImages: Map<number, { data: string; mimeType: string }> = new Map();\n\t// Incremental syntax highlighting cache for write tool call args\n\tprivate writeHighlightCache?: WriteHighlightCache;\n\t// When true, this component intentionally renders no lines\n\tprivate hideComponent = false;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\targs: any,\n\t\toptions: ToolExecutionOptions = {},\n\t\ttoolDefinition: ToolDefinition | undefined,\n\t\tui: TUI,\n\t\tcwd: string = process.cwd(),\n\t) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.args = args;\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.ui = ui;\n\t\tthis.cwd = cwd;\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Always create both - contentBox for custom tools/bash, contentText for other built-ins\n\t\tthis.contentBox = new Box(1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\t\tthis.contentText = new Text(\"\", 1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\n\t\t// Use contentBox for bash (visual truncation) or custom tools with custom renderers\n\t\t// Use contentText for built-in tools (including overrides without custom renderers)\n\t\tif (toolName === \"bash\" || (toolDefinition && !this.shouldUseBuiltInRenderer())) {\n\t\t\tthis.addChild(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\t/**\n\t * Check if we should use built-in rendering for this tool.\n\t * Returns true if the tool name is a built-in AND either there's no toolDefinition\n\t * or the toolDefinition doesn't provide custom renderers.\n\t */\n\tprivate shouldUseBuiltInRenderer(): boolean {\n\t\tconst isBuiltInName = this.toolName in allTools;\n\t\tconst hasCustomRenderers = this.toolDefinition?.renderCall || this.toolDefinition?.renderResult;\n\t\treturn isBuiltInName && !hasCustomRenderers;\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tif (this.toolName === \"write\" && this.isPartial) {\n\t\t\tthis.updateWriteHighlightCacheIncremental();\n\t\t}\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate highlightSingleLine(line: string, lang: string): string {\n\t\tconst highlighted = highlightCode(line, lang);\n\t\treturn highlighted[0] ?? \"\";\n\t}\n\n\tprivate refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\t\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\t\tif (prefixCount === 0) return;\n\n\t\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\t\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\t\tfor (let i = 0; i < prefixCount; i++) {\n\t\t\tcache.highlightedLines[i] =\n\t\t\t\tprefixHighlighted[i] ?? this.highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t\t}\n\t}\n\n\tprivate rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): void {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tif (!lang) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst displayContent = normalizeDisplayText(fileContent);\n\t\tconst normalized = replaceTabs(displayContent);\n\t\tthis.writeHighlightCache = {\n\t\t\trawPath,\n\t\t\tlang,\n\t\t\trawContent: fileContent,\n\t\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\t\thighlightedLines: highlightCode(normalized, lang),\n\t\t};\n\t}\n\n\tprivate updateWriteHighlightCacheIncremental(): void {\n\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\tconst fileContent = str(this.args?.content);\n\t\tif (rawPath === null || fileContent === null) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tif (!lang) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.writeHighlightCache) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tconst cache = this.writeHighlightCache;\n\t\tif (cache.lang !== lang || cache.rawPath !== rawPath) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!fileContent.startsWith(cache.rawContent)) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tif (fileContent.length === cache.rawContent.length) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\t\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\t\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\t\tcache.rawContent = fileContent;\n\n\t\tif (cache.normalizedLines.length === 0) {\n\t\t\tcache.normalizedLines.push(\"\");\n\t\t\tcache.highlightedLines.push(\"\");\n\t\t}\n\n\t\tconst segments = deltaNormalized.split(\"\\n\");\n\t\tconst lastIndex = cache.normalizedLines.length - 1;\n\t\tcache.normalizedLines[lastIndex] += segments[0];\n\t\tcache.highlightedLines[lastIndex] = this.highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\n\t\tfor (let i = 1; i < segments.length; i++) {\n\t\t\tcache.normalizedLines.push(segments[i]);\n\t\t\tcache.highlightedLines.push(this.highlightSingleLine(segments[i], cache.lang));\n\t\t}\n\n\t\tthis.refreshWriteHighlightPrefix(cache);\n\t}\n\n\t/**\n\t * Signal that args are complete (tool is about to execute).\n\t * This triggers diff computation for edit tool.\n\t */\n\tsetArgsComplete(): void {\n\t\tif (this.toolName === \"write\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tif (rawPath !== null && fileContent !== null) {\n\t\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\t}\n\t\t}\n\t\tthis.maybeComputeEditDiff();\n\t}\n\n\t/**\n\t * Compute edit diff preview when we have complete args.\n\t * This runs async and updates display when done.\n\t */\n\tprivate maybeComputeEditDiff(): void {\n\t\tif (this.toolName !== \"edit\") return;\n\n\t\tconst path = this.args?.path;\n\t\tconst oldText = this.args?.oldText;\n\t\tconst newText = this.args?.newText;\n\n\t\t// Need all three params to compute diff\n\t\tif (!path || oldText === undefined || newText === undefined) return;\n\n\t\t// Create a key to track which args this computation is for\n\t\tconst argsKey = JSON.stringify({ path, oldText, newText });\n\n\t\t// Skip if we already computed for these exact args\n\t\tif (this.editDiffArgsKey === argsKey) return;\n\n\t\tthis.editDiffArgsKey = argsKey;\n\n\t\t// Compute diff async\n\t\tcomputeEditDiff(path, oldText, newText, this.cwd).then((result) => {\n\t\t\t// Only update if args haven't changed since we started\n\t\t\tif (this.editDiffArgsKey === argsKey) {\n\t\t\t\tthis.editDiffPreview = result;\n\t\t\t\tthis.updateDisplay();\n\t\t\t\tthis.ui.requestRender();\n\t\t\t}\n\t\t});\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\tif (this.toolName === \"write\" && !isPartial) {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tif (rawPath !== null && fileContent !== null) {\n\t\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\t}\n\t\t}\n\t\tthis.updateDisplay();\n\t\t// Convert non-PNG images to PNG for Kitty protocol (async)\n\t\tthis.maybeConvertImagesForKitty();\n\t}\n\n\t/**\n\t * Convert non-PNG images to PNG for Kitty graphics protocol.\n\t * Kitty requires PNG format (f=100), so JPEG/GIF/WebP won't display.\n\t */\n\tprivate maybeConvertImagesForKitty(): void {\n\t\tconst caps = getCapabilities();\n\t\t// Only needed for Kitty protocol\n\t\tif (caps.images !== \"kitty\") return;\n\t\tif (!this.result) return;\n\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\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\t// Skip if already PNG or already converted\n\t\t\tif (img.mimeType === \"image/png\") continue;\n\t\t\tif (this.convertedImages.has(i)) continue;\n\n\t\t\t// Convert async\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\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) {\n\t\t\treturn [];\n\t\t}\n\t\treturn super.render(width);\n\t}\n\n\tprivate updateDisplay(): void {\n\t\t// Set background based on state\n\t\tconst bgFn = this.isPartial\n\t\t\t? (text: string) => theme.bg(\"toolPendingBg\", text)\n\t\t\t: this.result?.isError\n\t\t\t\t? (text: string) => theme.bg(\"toolErrorBg\", text)\n\t\t\t\t: (text: string) => theme.bg(\"toolSuccessBg\", text);\n\n\t\tconst useBuiltInRenderer = this.shouldUseBuiltInRenderer();\n\t\tlet customRendererHasContent = false;\n\t\tthis.hideComponent = false;\n\n\t\t// Use built-in rendering for built-in tools (or overrides without custom renderers)\n\t\tif (useBuiltInRenderer) {\n\t\t\tif (this.toolName === \"bash\") {\n\t\t\t\t// Bash uses Box with visual line truncation\n\t\t\t\tthis.contentBox.setBgFn(bgFn);\n\t\t\t\tthis.contentBox.clear();\n\t\t\t\tthis.renderBashContent();\n\t\t\t} else {\n\t\t\t\t// Other built-in tools: use Text directly with caching\n\t\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t\t}\n\t\t} else if (this.toolDefinition) {\n\t\t\t// Custom tools use Box for flexible component rendering\n\t\t\tthis.contentBox.setBgFn(bgFn);\n\t\t\tthis.contentBox.clear();\n\n\t\t\t// Render call component\n\t\t\tif (this.toolDefinition.renderCall) {\n\t\t\t\ttry {\n\t\t\t\t\tconst callComponent = this.toolDefinition.renderCall(this.args, theme);\n\t\t\t\t\tif (callComponent !== undefined) {\n\t\t\t\t\t\tthis.contentBox.addChild(callComponent);\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Fall back to default on error\n\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(this.toolName)), 0, 0));\n\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No custom renderCall, show tool name\n\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(this.toolName)), 0, 0));\n\t\t\t\tcustomRendererHasContent = true;\n\t\t\t}\n\n\t\t\t// Render result component if we have a result\n\t\t\tif (this.result && this.toolDefinition.renderResult) {\n\t\t\t\ttry {\n\t\t\t\t\tconst resultComponent = this.toolDefinition.renderResult(\n\t\t\t\t\t\t{ content: this.result.content as any, details: this.result.details },\n\t\t\t\t\t\t{ expanded: this.expanded, isPartial: this.isPartial },\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t);\n\t\t\t\t\tif (resultComponent !== undefined) {\n\t\t\t\t\t\tthis.contentBox.addChild(resultComponent);\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Fall back to showing raw output on error\n\t\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\t\tif (output) {\n\t\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolOutput\", output), 0, 0));\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (this.result) {\n\t\t\t\t// Has result but no custom renderResult\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tif (output) {\n\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolOutput\", output), 0, 0));\n\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Unknown tool with no registered definition - show generic fallback\n\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t}\n\n\t\t// Handle images (same for both custom and built-in)\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: any) => c.type === \"image\") || [];\n\t\t\tconst caps = getCapabilities();\n\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\t// Use converted PNG for Kitty protocol if available\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\n\t\t\t\t\t// For Kitty, skip non-PNG images that haven't been converted yet\n\t\t\t\t\tif (caps.images === \"kitty\" && imageMimeType !== \"image/png\") {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\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: 60 },\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 (!useBuiltInRenderer && this.toolDefinition) {\n\t\t\tthis.hideComponent = !customRendererHasContent && this.imageComponents.length === 0;\n\t\t}\n\t}\n\n\t/**\n\t * Render bash content using visual line truncation (like bash-execution.ts)\n\t */\n\tprivate renderBashContent(): void {\n\t\tconst command = str(this.args?.command);\n\t\tconst timeout = this.args?.timeout as number | undefined;\n\n\t\t// Header\n\t\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\t\tconst commandDisplay =\n\t\t\tcommand === null ? theme.fg(\"error\", \"[invalid arg]\") : command ? command : theme.fg(\"toolOutput\", \"...\");\n\t\tthis.contentBox.addChild(\n\t\t\tnew Text(theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix, 0, 0),\n\t\t);\n\n\t\tif (this.result) {\n\t\t\tconst output = this.getTextOutput().trim();\n\n\t\t\tif (output) {\n\t\t\t\t// Style each line for the output\n\t\t\t\tconst styledOutput = output\n\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t\t\t.join(\"\\n\");\n\n\t\t\t\tif (this.expanded) {\n\t\t\t\t\t// Show all lines when expanded\n\t\t\t\t\tthis.contentBox.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t\t\t} else {\n\t\t\t\t\t// Use visual line truncation when collapsed with width-aware caching\n\t\t\t\t\tlet cachedWidth: number | undefined;\n\t\t\t\t\tlet cachedLines: string[] | undefined;\n\t\t\t\t\tlet cachedSkipped: number | undefined;\n\n\t\t\t\t\tthis.contentBox.addChild({\n\t\t\t\t\t\trender: (width: number) => {\n\t\t\t\t\t\t\tif (cachedLines === undefined || cachedWidth !== width) {\n\t\t\t\t\t\t\t\tconst result = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\t\t\tcachedLines = result.visualLines;\n\t\t\t\t\t\t\t\tcachedSkipped = result.skippedCount;\n\t\t\t\t\t\t\t\tcachedWidth = width;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (cachedSkipped && cachedSkipped > 0) {\n\t\t\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t\t\t` ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...cachedLines];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Add blank line for spacing (matches expanded case)\n\t\t\t\t\t\t\treturn [\"\", ...cachedLines];\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinvalidate: () => {\n\t\t\t\t\t\t\tcachedWidth = undefined;\n\t\t\t\t\t\t\tcachedLines = undefined;\n\t\t\t\t\t\t\tcachedSkipped = undefined;\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Truncation warnings\n\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\tconst fullOutputPath = this.result.details?.fullOutputPath;\n\t\t\tif (truncation?.truncated || fullOutputPath) {\n\t\t\t\tconst warnings: string[] = [];\n\t\t\t\tif (fullOutputPath) {\n\t\t\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t\t\t}\n\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\twarnings.push(\n\t\t\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.contentBox.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getTextOutput(): string {\n\t\tif (!this.result) return \"\";\n\n\t\tconst textBlocks = this.result.content?.filter((c: any) => c.type === \"text\") || [];\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\n\t\tlet output = textBlocks\n\t\t\t.map((c: any) => {\n\t\t\t\t// Use sanitizeBinaryOutput to handle binary data that crashes string-width\n\t\t\t\treturn sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\");\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\n\t\tconst caps = getCapabilities();\n\t\tif (imageBlocks.length > 0 && (!caps.images || !this.showImages)) {\n\t\t\tconst imageIndicators = imageBlocks\n\t\t\t\t.map((img: any) => {\n\t\t\t\t\tconst dims = img.data ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\t\treturn imageFallback(img.mimeType, dims);\n\t\t\t\t})\n\t\t\t\t.join(\"\\n\");\n\t\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tlet text = \"\";\n\t\tconst invalidArg = theme.fg(\"error\", \"[invalid arg]\");\n\n\t\tif (this.toolName === \"read\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\t\t\tconst offset = this.args?.offset;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\tlet pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\t\t\tif (offset !== undefined || limit !== undefined) {\n\t\t\t\tconst startLine = offset ?? 1;\n\t\t\t\tconst endLine = limit !== undefined ? startLine + limit - 1 : \"\";\n\t\t\t\tpathDisplay += theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n\t\t\t}\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}`;\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\t\t\tconst lines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext +=\n\t\t\t\t\t\"\\n\\n\" +\n\t\t\t\t\tdisplayLines\n\t\t\t\t\t\t.map((line: string) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line))))\n\t\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t}\n\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"write\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"write\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\"));\n\n\t\t\tif (fileContent === null) {\n\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t\t\t} else if (fileContent) {\n\t\t\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\n\t\t\t\tlet lines: string[];\n\t\t\t\tif (lang) {\n\t\t\t\t\tconst cache = this.writeHighlightCache;\n\t\t\t\t\tif (cache && cache.lang === lang && cache.rawPath === rawPath && cache.rawContent === fileContent) {\n\t\t\t\t\t\tlines = cache.highlightedLines;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst displayContent = normalizeDisplayText(fileContent);\n\t\t\t\t\t\tconst normalized = replaceTabs(displayContent);\n\t\t\t\t\t\tlines = highlightCode(normalized, lang);\n\t\t\t\t\t\tthis.writeHighlightCache = {\n\t\t\t\t\t\t\trawPath,\n\t\t\t\t\t\t\tlang,\n\t\t\t\t\t\t\trawContent: fileContent,\n\t\t\t\t\t\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\t\t\t\t\t\thighlightedLines: lines,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlines = normalizeDisplayText(fileContent).split(\"\\n\");\n\t\t\t\t\tthis.writeHighlightCache = undefined;\n\t\t\t\t}\n\n\t\t\t\tconst totalLines = lines.length;\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext +=\n\t\t\t\t\t\"\\n\\n\" +\n\t\t\t\t\tdisplayLines.map((line: string) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext +=\n\t\t\t\t\t\ttheme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`) +\n\t\t\t\t\t\t` ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Show error if tool execution failed\n\t\t\tif (this.result?.isError) {\n\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\tif (errorText) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", errorText)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"edit\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\n\t\t\t// Build path display, appending :line if we have diff info\n\t\t\tlet pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\t\t\tconst firstChangedLine =\n\t\t\t\t(this.editDiffPreview && \"firstChangedLine\" in this.editDiffPreview\n\t\t\t\t\t? this.editDiffPreview.firstChangedLine\n\t\t\t\t\t: undefined) ||\n\t\t\t\t(this.result && !this.result.isError ? this.result.details?.firstChangedLine : undefined);\n\t\t\tif (firstChangedLine) {\n\t\t\t\tpathDisplay += theme.fg(\"warning\", `:${firstChangedLine}`);\n\t\t\t}\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n\n\t\t\tif (this.result?.isError) {\n\t\t\t\t// Show error from result\n\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\tif (errorText) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", errorText)}`;\n\t\t\t\t}\n\t\t\t} else if (this.result?.details?.diff) {\n\t\t\t\t// Tool executed successfully - use the diff from result\n\t\t\t\t// This takes priority over editDiffPreview which may have a stale error\n\t\t\t\t// due to race condition (async preview computed after file was modified)\n\t\t\t\ttext += `\\n\\n${renderDiff(this.result.details.diff, { filePath: rawPath ?? undefined })}`;\n\t\t\t} else if (this.editDiffPreview) {\n\t\t\t\t// Use cached diff preview (before tool executes)\n\t\t\t\tif (\"error\" in this.editDiffPreview) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", this.editDiffPreview.error)}`;\n\t\t\t\t} else if (this.editDiffPreview.diff) {\n\t\t\t\t\ttext += `\\n\\n${renderDiff(this.editDiffPreview.diff, { filePath: rawPath ?? undefined })}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"ls\") {\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"ls\"))} ${path === null ? invalidArg : theme.fg(\"accent\", path)}`;\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 20;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst entryLimit = this.result.details?.entryLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (entryLimit || truncation?.truncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (entryLimit) {\n\t\t\t\t\t\twarnings.push(`${entryLimit} entries limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"find\") {\n\t\t\tconst pattern = str(this.args?.pattern);\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"find\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(pattern === null ? invalidArg : theme.fg(\"accent\", pattern || \"\")) +\n\t\t\t\ttheme.fg(\"toolOutput\", ` in ${path === null ? invalidArg : path}`);\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 20;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst resultLimit = this.result.details?.resultLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (resultLimit || truncation?.truncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (resultLimit) {\n\t\t\t\t\t\twarnings.push(`${resultLimit} results limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"grep\") {\n\t\t\tconst pattern = str(this.args?.pattern);\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst glob = str(this.args?.glob);\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"grep\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(pattern === null ? invalidArg : theme.fg(\"accent\", `/${pattern || \"\"}/`)) +\n\t\t\t\ttheme.fg(\"toolOutput\", ` in ${path === null ? invalidArg : path}`);\n\t\t\tif (glob) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (${glob})`);\n\t\t\t}\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` limit ${limit}`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 15;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst matchLimit = this.result.details?.matchLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tconst linesTruncated = this.result.details?.linesTruncated;\n\t\t\t\tif (matchLimit || truncation?.truncated || linesTruncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (matchLimit) {\n\t\t\t\t\t\twarnings.push(`${matchLimit} matches limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (linesTruncated) {\n\t\t\t\t\t\twarnings.push(\"some lines truncated\");\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Generic tool (shouldn't reach here for custom tools)\n\t\t\ttext = theme.fg(\"toolTitle\", theme.bold(this.toolName));\n\n\t\t\tconst content = JSON.stringify(this.args, null, 2);\n\t\t\ttext += `\\n\\n${content}`;\n\t\t\tconst output = this.getTextOutput();\n\t\t\tif (output) {\n\t\t\t\ttext += `\\n${output}`;\n\t\t\t}\n\t\t}\n\n\t\treturn text;\n\t}\n}\n"]}
1
+ {"version":3,"file":"tool-execution.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/tool-execution.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,SAAS,EAOT,KAAK,GAAG,EAER,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAmDxE,MAAM,WAAW,oBAAoB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAUD;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,EAAE,CAAM;IAChB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,MAAM,CAAC,CAIb;IAEF,OAAO,CAAC,eAAe,CAAC,CAAiC;IACzD,OAAO,CAAC,eAAe,CAAC,CAAS;IAEjC,OAAO,CAAC,eAAe,CAA8D;IAErF,OAAO,CAAC,mBAAmB,CAAC,CAAsB;IAElD,OAAO,CAAC,aAAa,CAAS;IAE9B,YACC,QAAQ,EAAE,MAAM,EAChB,IAAI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\ttype TUI,\n\ttruncateToWidth,\n} from \"@apholdings/jensen-tui\";\nimport stripAnsi from \"strip-ansi\";\nimport type { ToolDefinition } from \"../../../core/extensions/types.js\";\nimport { computeEditDiff, type EditDiffError, type EditDiffResult } from \"../../../core/tools/edit-diff.js\";\nimport { allTools } from \"../../../core/tools/index.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from \"../../../core/tools/truncate.js\";\nimport { convertToPng } from \"../../../utils/image-convert.js\";\nimport { sanitizeBinaryOutput } from \"../../../utils/shell.js\";\nimport { getLanguageFromPath, highlightCode, theme } from \"../theme/theme.js\";\nimport { renderDiff } from \"./diff.js\";\nimport { keyHint } from \"./keybinding-hints.js\";\nimport { truncateToVisualLines } from \"./visual-truncate.js\";\n\n// Preview line limit for bash when not expanded\nconst BASH_PREVIEW_LINES = 5;\n// During partial write tool-call streaming, re-highlight the first N lines fully\n// to keep multiline tokenization mostly correct without re-highlighting the full file.\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n\n/**\n * Convert absolute path to tilde notation if it's in home directory\n */\nfunction shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\n/**\n * Replace tabs with spaces for consistent rendering\n */\nfunction replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\n/**\n * Normalize control characters for terminal preview rendering.\n * Keep tool arguments unchanged, sanitize only display text.\n */\nfunction normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\n/** Safely coerce value to string for display. Returns null if invalid type. */\nfunction str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null; // Invalid type\n}\n\nexport interface ToolExecutionOptions {\n\tshowImages?: boolean; // default: true (only used if terminal supports images)\n}\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\n\n/**\n * Component that renders a tool call with its result (updateable)\n */\nexport class ToolExecutionComponent extends Container {\n\tprivate contentBox: Box; // Used for custom tools and bash visual truncation\n\tprivate contentText: Text; // For built-in tools (with its own padding/bg)\n\tprivate imageComponents: Image[] = [];\n\tprivate imageSpacers: Spacer[] = [];\n\tprivate toolName: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate isPartial = true;\n\tprivate toolDefinition?: ToolDefinition;\n\tprivate ui: TUI;\n\tprivate cwd: string;\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\t// Cached edit diff preview (computed when args arrive, before tool executes)\n\tprivate editDiffPreview?: EditDiffResult | EditDiffError;\n\tprivate editDiffArgsKey?: string; // Track which args the preview is for\n\t// Cached converted images for Kitty protocol (which requires PNG), keyed by index\n\tprivate convertedImages: Map<number, { data: string; mimeType: string }> = new Map();\n\t// Incremental syntax highlighting cache for write tool call args\n\tprivate writeHighlightCache?: WriteHighlightCache;\n\t// When true, this component intentionally renders no lines\n\tprivate hideComponent = false;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\targs: any,\n\t\toptions: ToolExecutionOptions = {},\n\t\ttoolDefinition: ToolDefinition | undefined,\n\t\tui: TUI,\n\t\tcwd: string = process.cwd(),\n\t) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.args = args;\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.ui = ui;\n\t\tthis.cwd = cwd;\n\n\t\t// Always create both - contentBox for custom tools/bash, contentText for other built-ins\n\t\tthis.contentBox = new Box(1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\t\tthis.contentText = new Text(\"\", 1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\n\t\t// Use contentBox for bash (visual truncation) or custom tools with custom renderers\n\t\t// Use contentText for built-in tools (including overrides without custom renderers)\n\t\tif (toolName === \"bash\" || (toolDefinition && !this.shouldUseBuiltInRenderer())) {\n\t\t\tthis.addChild(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\t/**\n\t * Check if we should use built-in rendering for this tool.\n\t * Returns true if the tool name is a built-in AND either there's no toolDefinition\n\t * or the toolDefinition doesn't provide custom renderers.\n\t */\n\tprivate shouldUseBuiltInRenderer(): boolean {\n\t\tconst isBuiltInName = this.toolName in allTools;\n\t\tconst hasCustomRenderers = this.toolDefinition?.renderCall || this.toolDefinition?.renderResult;\n\t\treturn isBuiltInName && !hasCustomRenderers;\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tif (this.toolName === \"write\" && this.isPartial) {\n\t\t\tthis.updateWriteHighlightCacheIncremental();\n\t\t}\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate highlightSingleLine(line: string, lang: string): string {\n\t\tconst highlighted = highlightCode(line, lang);\n\t\treturn highlighted[0] ?? \"\";\n\t}\n\n\tprivate refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\t\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\t\tif (prefixCount === 0) return;\n\n\t\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\t\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\t\tfor (let i = 0; i < prefixCount; i++) {\n\t\t\tcache.highlightedLines[i] =\n\t\t\t\tprefixHighlighted[i] ?? this.highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t\t}\n\t}\n\n\tprivate rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): void {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tif (!lang) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst displayContent = normalizeDisplayText(fileContent);\n\t\tconst normalized = replaceTabs(displayContent);\n\t\tthis.writeHighlightCache = {\n\t\t\trawPath,\n\t\t\tlang,\n\t\t\trawContent: fileContent,\n\t\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\t\thighlightedLines: highlightCode(normalized, lang),\n\t\t};\n\t}\n\n\tprivate updateWriteHighlightCacheIncremental(): void {\n\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\tconst fileContent = str(this.args?.content);\n\t\tif (rawPath === null || fileContent === null) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tif (!lang) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.writeHighlightCache) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tconst cache = this.writeHighlightCache;\n\t\tif (cache.lang !== lang || cache.rawPath !== rawPath) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!fileContent.startsWith(cache.rawContent)) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tif (fileContent.length === cache.rawContent.length) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\t\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\t\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\t\tcache.rawContent = fileContent;\n\n\t\tif (cache.normalizedLines.length === 0) {\n\t\t\tcache.normalizedLines.push(\"\");\n\t\t\tcache.highlightedLines.push(\"\");\n\t\t}\n\n\t\tconst segments = deltaNormalized.split(\"\\n\");\n\t\tconst lastIndex = cache.normalizedLines.length - 1;\n\t\tcache.normalizedLines[lastIndex] += segments[0];\n\t\tcache.highlightedLines[lastIndex] = this.highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\n\t\tfor (let i = 1; i < segments.length; i++) {\n\t\t\tcache.normalizedLines.push(segments[i]);\n\t\t\tcache.highlightedLines.push(this.highlightSingleLine(segments[i], cache.lang));\n\t\t}\n\n\t\tthis.refreshWriteHighlightPrefix(cache);\n\t}\n\n\t/**\n\t * Signal that args are complete (tool is about to execute).\n\t * This triggers diff computation for edit tool.\n\t */\n\tsetArgsComplete(): void {\n\t\tif (this.toolName === \"write\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tif (rawPath !== null && fileContent !== null) {\n\t\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\t}\n\t\t}\n\t\tthis.maybeComputeEditDiff();\n\t}\n\n\t/**\n\t * Compute edit diff preview when we have complete args.\n\t * This runs async and updates display when done.\n\t */\n\tprivate maybeComputeEditDiff(): void {\n\t\tif (this.toolName !== \"edit\") return;\n\n\t\tconst path = this.args?.path;\n\t\tconst oldText = this.args?.oldText;\n\t\tconst newText = this.args?.newText;\n\n\t\t// Need all three params to compute diff\n\t\tif (!path || oldText === undefined || newText === undefined) return;\n\n\t\t// Create a key to track which args this computation is for\n\t\tconst argsKey = JSON.stringify({ path, oldText, newText });\n\n\t\t// Skip if we already computed for these exact args\n\t\tif (this.editDiffArgsKey === argsKey) return;\n\n\t\tthis.editDiffArgsKey = argsKey;\n\n\t\t// Compute diff async\n\t\tcomputeEditDiff(path, oldText, newText, this.cwd).then((result) => {\n\t\t\t// Only update if args haven't changed since we started\n\t\t\tif (this.editDiffArgsKey === argsKey) {\n\t\t\t\tthis.editDiffPreview = result;\n\t\t\t\tthis.updateDisplay();\n\t\t\t\tthis.ui.requestRender();\n\t\t\t}\n\t\t});\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\tif (this.toolName === \"write\" && !isPartial) {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tif (rawPath !== null && fileContent !== null) {\n\t\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\t}\n\t\t}\n\t\tthis.updateDisplay();\n\t\t// Convert non-PNG images to PNG for Kitty protocol (async)\n\t\tthis.maybeConvertImagesForKitty();\n\t}\n\n\t/**\n\t * Convert non-PNG images to PNG for Kitty graphics protocol.\n\t * Kitty requires PNG format (f=100), so JPEG/GIF/WebP won't display.\n\t */\n\tprivate maybeConvertImagesForKitty(): void {\n\t\tconst caps = getCapabilities();\n\t\t// Only needed for Kitty protocol\n\t\tif (caps.images !== \"kitty\") return;\n\t\tif (!this.result) return;\n\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\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\t// Skip if already PNG or already converted\n\t\t\tif (img.mimeType === \"image/png\") continue;\n\t\t\tif (this.convertedImages.has(i)) continue;\n\n\t\t\t// Convert async\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\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) {\n\t\t\treturn [];\n\t\t}\n\t\treturn [...super.render(width), \"\"];\n\t}\n\n\tprivate updateDisplay(): void {\n\t\t// Set background based on state\n\t\tconst bgFn = this.isPartial\n\t\t\t? (text: string) => theme.bg(\"toolPendingBg\", text)\n\t\t\t: this.result?.isError\n\t\t\t\t? (text: string) => theme.bg(\"toolErrorBg\", text)\n\t\t\t\t: (text: string) => theme.bg(\"toolSuccessBg\", text);\n\n\t\tconst useBuiltInRenderer = this.shouldUseBuiltInRenderer();\n\t\tlet customRendererHasContent = false;\n\t\tthis.hideComponent = false;\n\n\t\t// Use built-in rendering for built-in tools (or overrides without custom renderers)\n\t\tif (useBuiltInRenderer) {\n\t\t\tif (this.toolName === \"bash\") {\n\t\t\t\t// Bash uses Box with visual line truncation\n\t\t\t\tthis.contentBox.setBgFn(bgFn);\n\t\t\t\tthis.contentBox.clear();\n\t\t\t\tthis.renderBashContent();\n\t\t\t} else {\n\t\t\t\t// Other built-in tools: use Text directly with caching\n\t\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t\t}\n\t\t} else if (this.toolDefinition) {\n\t\t\t// Custom tools use Box for flexible component rendering\n\t\t\tthis.contentBox.setBgFn(bgFn);\n\t\t\tthis.contentBox.clear();\n\n\t\t\t// Render call component\n\t\t\tif (this.toolDefinition.renderCall) {\n\t\t\t\ttry {\n\t\t\t\t\tconst callComponent = this.toolDefinition.renderCall(this.args, theme);\n\t\t\t\t\tif (callComponent !== undefined) {\n\t\t\t\t\t\tthis.contentBox.addChild(callComponent);\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Fall back to default on error\n\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(this.toolName)), 0, 0));\n\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No custom renderCall, show tool name\n\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(this.toolName)), 0, 0));\n\t\t\t\tcustomRendererHasContent = true;\n\t\t\t}\n\n\t\t\t// Render result component if we have a result\n\t\t\tif (this.result && this.toolDefinition.renderResult) {\n\t\t\t\ttry {\n\t\t\t\t\tconst resultComponent = this.toolDefinition.renderResult(\n\t\t\t\t\t\t{ content: this.result.content as any, details: this.result.details },\n\t\t\t\t\t\t{ expanded: this.expanded, isPartial: this.isPartial },\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t);\n\t\t\t\t\tif (resultComponent !== undefined) {\n\t\t\t\t\t\tthis.contentBox.addChild(resultComponent);\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Fall back to showing raw output on error\n\t\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\t\tif (output) {\n\t\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolOutput\", output), 0, 0));\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (this.result) {\n\t\t\t\t// Has result but no custom renderResult\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tif (output) {\n\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolOutput\", output), 0, 0));\n\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Unknown tool with no registered definition - show generic fallback\n\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t}\n\n\t\t// Handle images (same for both custom and built-in)\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: any) => c.type === \"image\") || [];\n\t\t\tconst caps = getCapabilities();\n\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\t// Use converted PNG for Kitty protocol if available\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\n\t\t\t\t\t// For Kitty, skip non-PNG images that haven't been converted yet\n\t\t\t\t\tif (caps.images === \"kitty\" && imageMimeType !== \"image/png\") {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\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: 60 },\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 (!useBuiltInRenderer && this.toolDefinition) {\n\t\t\tthis.hideComponent = !customRendererHasContent && this.imageComponents.length === 0;\n\t\t}\n\t}\n\n\t/**\n\t * Render bash content using visual line truncation (like bash-execution.ts)\n\t */\n\tprivate renderBashContent(): void {\n\t\tconst command = str(this.args?.command);\n\t\tconst timeout = this.args?.timeout as number | undefined;\n\n\t\t// Header\n\t\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\t\tconst commandDisplay =\n\t\t\tcommand === null ? theme.fg(\"error\", \"[invalid arg]\") : command ? command : theme.fg(\"toolOutput\", \"...\");\n\t\tthis.contentBox.addChild(\n\t\t\tnew Text(theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix, 0, 0),\n\t\t);\n\n\t\tif (this.result) {\n\t\t\tconst output = this.getTextOutput().trim();\n\n\t\t\tif (output) {\n\t\t\t\t// Style each line for the output\n\t\t\t\tconst styledOutput = output\n\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t\t\t.join(\"\\n\");\n\n\t\t\t\tif (this.expanded) {\n\t\t\t\t\t// Show all lines when expanded\n\t\t\t\t\tthis.contentBox.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t\t\t} else {\n\t\t\t\t\t// Use visual line truncation when collapsed with width-aware caching\n\t\t\t\t\tlet cachedWidth: number | undefined;\n\t\t\t\t\tlet cachedLines: string[] | undefined;\n\t\t\t\t\tlet cachedSkipped: number | undefined;\n\n\t\t\t\t\tthis.contentBox.addChild({\n\t\t\t\t\t\trender: (width: number) => {\n\t\t\t\t\t\t\tif (cachedLines === undefined || cachedWidth !== width) {\n\t\t\t\t\t\t\t\tconst result = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\t\t\tcachedLines = result.visualLines;\n\t\t\t\t\t\t\t\tcachedSkipped = result.skippedCount;\n\t\t\t\t\t\t\t\tcachedWidth = width;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (cachedSkipped && cachedSkipped > 0) {\n\t\t\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t\t\t` ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...cachedLines];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Add blank line for spacing (matches expanded case)\n\t\t\t\t\t\t\treturn [\"\", ...cachedLines];\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinvalidate: () => {\n\t\t\t\t\t\t\tcachedWidth = undefined;\n\t\t\t\t\t\t\tcachedLines = undefined;\n\t\t\t\t\t\t\tcachedSkipped = undefined;\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Truncation warnings\n\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\tconst fullOutputPath = this.result.details?.fullOutputPath;\n\t\t\tif (truncation?.truncated || fullOutputPath) {\n\t\t\t\tconst warnings: string[] = [];\n\t\t\t\tif (fullOutputPath) {\n\t\t\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t\t\t}\n\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\twarnings.push(\n\t\t\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.contentBox.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getTextOutput(): string {\n\t\tif (!this.result) return \"\";\n\n\t\tconst textBlocks = this.result.content?.filter((c: any) => c.type === \"text\") || [];\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\n\t\tlet output = textBlocks\n\t\t\t.map((c: any) => {\n\t\t\t\t// Use sanitizeBinaryOutput to handle binary data that crashes string-width\n\t\t\t\treturn sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\");\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\n\t\tconst caps = getCapabilities();\n\t\tif (imageBlocks.length > 0 && (!caps.images || !this.showImages)) {\n\t\t\tconst imageIndicators = imageBlocks\n\t\t\t\t.map((img: any) => {\n\t\t\t\t\tconst dims = img.data ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\t\treturn imageFallback(img.mimeType, dims);\n\t\t\t\t})\n\t\t\t\t.join(\"\\n\");\n\t\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tlet text = \"\";\n\t\tconst invalidArg = theme.fg(\"error\", \"[invalid arg]\");\n\n\t\tif (this.toolName === \"read\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\t\t\tconst offset = this.args?.offset;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\tlet pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\t\t\tif (offset !== undefined || limit !== undefined) {\n\t\t\t\tconst startLine = offset ?? 1;\n\t\t\t\tconst endLine = limit !== undefined ? startLine + limit - 1 : \"\";\n\t\t\t\tpathDisplay += theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n\t\t\t}\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}`;\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\t\t\tconst lines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext +=\n\t\t\t\t\t\"\\n\\n\" +\n\t\t\t\t\tdisplayLines\n\t\t\t\t\t\t.map((line: string) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line))))\n\t\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t}\n\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"write\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"write\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\"));\n\n\t\t\tif (fileContent === null) {\n\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t\t\t} else if (fileContent) {\n\t\t\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\n\t\t\t\tlet lines: string[];\n\t\t\t\tif (lang) {\n\t\t\t\t\tconst cache = this.writeHighlightCache;\n\t\t\t\t\tif (cache && cache.lang === lang && cache.rawPath === rawPath && cache.rawContent === fileContent) {\n\t\t\t\t\t\tlines = cache.highlightedLines;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst displayContent = normalizeDisplayText(fileContent);\n\t\t\t\t\t\tconst normalized = replaceTabs(displayContent);\n\t\t\t\t\t\tlines = highlightCode(normalized, lang);\n\t\t\t\t\t\tthis.writeHighlightCache = {\n\t\t\t\t\t\t\trawPath,\n\t\t\t\t\t\t\tlang,\n\t\t\t\t\t\t\trawContent: fileContent,\n\t\t\t\t\t\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\t\t\t\t\t\thighlightedLines: lines,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlines = normalizeDisplayText(fileContent).split(\"\\n\");\n\t\t\t\t\tthis.writeHighlightCache = undefined;\n\t\t\t\t}\n\n\t\t\t\tconst totalLines = lines.length;\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext +=\n\t\t\t\t\t\"\\n\\n\" +\n\t\t\t\t\tdisplayLines.map((line: string) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext +=\n\t\t\t\t\t\ttheme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`) +\n\t\t\t\t\t\t` ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Show error if tool execution failed\n\t\t\tif (this.result?.isError) {\n\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\tif (errorText) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", errorText)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"edit\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\n\t\t\t// Build path display, appending :line if we have diff info\n\t\t\tlet pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\t\t\tconst firstChangedLine =\n\t\t\t\t(this.editDiffPreview && \"firstChangedLine\" in this.editDiffPreview\n\t\t\t\t\t? this.editDiffPreview.firstChangedLine\n\t\t\t\t\t: undefined) ||\n\t\t\t\t(this.result && !this.result.isError ? this.result.details?.firstChangedLine : undefined);\n\t\t\tif (firstChangedLine) {\n\t\t\t\tpathDisplay += theme.fg(\"warning\", `:${firstChangedLine}`);\n\t\t\t}\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n\n\t\t\tif (this.result?.isError) {\n\t\t\t\t// Show error from result\n\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\tif (errorText) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", errorText)}`;\n\t\t\t\t}\n\t\t\t} else if (this.result?.details?.diff) {\n\t\t\t\t// Tool executed successfully - use the diff from result\n\t\t\t\t// This takes priority over editDiffPreview which may have a stale error\n\t\t\t\t// due to race condition (async preview computed after file was modified)\n\t\t\t\ttext += `\\n\\n${renderDiff(this.result.details.diff, { filePath: rawPath ?? undefined })}`;\n\t\t\t} else if (this.editDiffPreview) {\n\t\t\t\t// Use cached diff preview (before tool executes)\n\t\t\t\tif (\"error\" in this.editDiffPreview) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", this.editDiffPreview.error)}`;\n\t\t\t\t} else if (this.editDiffPreview.diff) {\n\t\t\t\t\ttext += `\\n\\n${renderDiff(this.editDiffPreview.diff, { filePath: rawPath ?? undefined })}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"ls\") {\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"ls\"))} ${path === null ? invalidArg : theme.fg(\"accent\", path)}`;\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 20;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst entryLimit = this.result.details?.entryLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (entryLimit || truncation?.truncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (entryLimit) {\n\t\t\t\t\t\twarnings.push(`${entryLimit} entries limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"find\") {\n\t\t\tconst pattern = str(this.args?.pattern);\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"find\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(pattern === null ? invalidArg : theme.fg(\"accent\", pattern || \"\")) +\n\t\t\t\ttheme.fg(\"toolOutput\", ` in ${path === null ? invalidArg : path}`);\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 20;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst resultLimit = this.result.details?.resultLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (resultLimit || truncation?.truncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (resultLimit) {\n\t\t\t\t\t\twarnings.push(`${resultLimit} results limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"grep\") {\n\t\t\tconst pattern = str(this.args?.pattern);\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst glob = str(this.args?.glob);\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"grep\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(pattern === null ? invalidArg : theme.fg(\"accent\", `/${pattern || \"\"}/`)) +\n\t\t\t\ttheme.fg(\"toolOutput\", ` in ${path === null ? invalidArg : path}`);\n\t\t\tif (glob) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (${glob})`);\n\t\t\t}\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` limit ${limit}`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 15;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst matchLimit = this.result.details?.matchLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tconst linesTruncated = this.result.details?.linesTruncated;\n\t\t\t\tif (matchLimit || truncation?.truncated || linesTruncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (matchLimit) {\n\t\t\t\t\t\twarnings.push(`${matchLimit} matches limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (linesTruncated) {\n\t\t\t\t\t\twarnings.push(\"some lines truncated\");\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Generic tool (shouldn't reach here for custom tools)\n\t\t\ttext = theme.fg(\"toolTitle\", theme.bold(this.toolName));\n\n\t\t\tconst content = JSON.stringify(this.args, null, 2);\n\t\t\ttext += `\\n\\n${content}`;\n\t\t\tconst output = this.getTextOutput();\n\t\t\tif (output) {\n\t\t\t\ttext += `\\n${output}`;\n\t\t\t}\n\t\t}\n\n\t\treturn text;\n\t}\n}\n"]}
@@ -82,7 +82,6 @@ export class ToolExecutionComponent extends Container {
82
82
  this.toolDefinition = toolDefinition;
83
83
  this.ui = ui;
84
84
  this.cwd = cwd;
85
- this.addChild(new Spacer(1));
86
85
  // Always create both - contentBox for custom tools/bash, contentText for other built-ins
87
86
  this.contentBox = new Box(1, 1, (text) => theme.bg("toolPendingBg", text));
88
87
  this.contentText = new Text("", 1, 1, (text) => theme.bg("toolPendingBg", text));
@@ -295,7 +294,7 @@ export class ToolExecutionComponent extends Container {
295
294
  if (this.hideComponent) {
296
295
  return [];
297
296
  }
298
- return super.render(width);
297
+ return [...super.render(width), ""];
299
298
  }
300
299
  updateDisplay() {
301
300
  // Set background based on state
@@ -1 +1 @@
1
- {"version":3,"file":"tool-execution.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/tool-execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EACN,GAAG,EACH,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,KAAK,EACL,aAAa,EACb,MAAM,EACN,IAAI,EAEJ,eAAe,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,eAAe,EAA2C,MAAM,kCAAkC,CAAC;AAC5G,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,gDAAgD;AAChD,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,iFAAiF;AACjF,uFAAuF;AACvF,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAE9C;;G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aAAM,CAAC;YACP,uDAAuD;YACvD,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAExD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACnD,IAAI,IAAI,OAAO,OAAO,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACpC,IAAI,MAAM,EAAE,CAAC;gBACZ,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YACvB,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IAAA,CACZ;CACD","sourcesContent":["import * as os from \"node:os\";\nimport {\n\tBox,\n\tContainer,\n\tgetCapabilities,\n\tgetImageDimensions,\n\tImage,\n\timageFallback,\n\tSpacer,\n\tText,\n\ttype TUI,\n\ttruncateToWidth,\n} from \"@apholdings/jensen-tui\";\nimport stripAnsi from \"strip-ansi\";\nimport type { ToolDefinition } from \"../../../core/extensions/types.js\";\nimport { computeEditDiff, type EditDiffError, type EditDiffResult } from \"../../../core/tools/edit-diff.js\";\nimport { allTools } from \"../../../core/tools/index.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from \"../../../core/tools/truncate.js\";\nimport { convertToPng } from \"../../../utils/image-convert.js\";\nimport { sanitizeBinaryOutput } from \"../../../utils/shell.js\";\nimport { getLanguageFromPath, highlightCode, theme } from \"../theme/theme.js\";\nimport { renderDiff } from \"./diff.js\";\nimport { keyHint } from \"./keybinding-hints.js\";\nimport { truncateToVisualLines } from \"./visual-truncate.js\";\n\n// Preview line limit for bash when not expanded\nconst BASH_PREVIEW_LINES = 5;\n// During partial write tool-call streaming, re-highlight the first N lines fully\n// to keep multiline tokenization mostly correct without re-highlighting the full file.\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n\n/**\n * Convert absolute path to tilde notation if it's in home directory\n */\nfunction shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\n/**\n * Replace tabs with spaces for consistent rendering\n */\nfunction replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\n/**\n * Normalize control characters for terminal preview rendering.\n * Keep tool arguments unchanged, sanitize only display text.\n */\nfunction normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\n/** Safely coerce value to string for display. Returns null if invalid type. */\nfunction str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null; // Invalid type\n}\n\nexport interface ToolExecutionOptions {\n\tshowImages?: boolean; // default: true (only used if terminal supports images)\n}\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\n\n/**\n * Component that renders a tool call with its result (updateable)\n */\nexport class ToolExecutionComponent extends Container {\n\tprivate contentBox: Box; // Used for custom tools and bash visual truncation\n\tprivate contentText: Text; // For built-in tools (with its own padding/bg)\n\tprivate imageComponents: Image[] = [];\n\tprivate imageSpacers: Spacer[] = [];\n\tprivate toolName: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate isPartial = true;\n\tprivate toolDefinition?: ToolDefinition;\n\tprivate ui: TUI;\n\tprivate cwd: string;\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\t// Cached edit diff preview (computed when args arrive, before tool executes)\n\tprivate editDiffPreview?: EditDiffResult | EditDiffError;\n\tprivate editDiffArgsKey?: string; // Track which args the preview is for\n\t// Cached converted images for Kitty protocol (which requires PNG), keyed by index\n\tprivate convertedImages: Map<number, { data: string; mimeType: string }> = new Map();\n\t// Incremental syntax highlighting cache for write tool call args\n\tprivate writeHighlightCache?: WriteHighlightCache;\n\t// When true, this component intentionally renders no lines\n\tprivate hideComponent = false;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\targs: any,\n\t\toptions: ToolExecutionOptions = {},\n\t\ttoolDefinition: ToolDefinition | undefined,\n\t\tui: TUI,\n\t\tcwd: string = process.cwd(),\n\t) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.args = args;\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.ui = ui;\n\t\tthis.cwd = cwd;\n\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Always create both - contentBox for custom tools/bash, contentText for other built-ins\n\t\tthis.contentBox = new Box(1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\t\tthis.contentText = new Text(\"\", 1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\n\t\t// Use contentBox for bash (visual truncation) or custom tools with custom renderers\n\t\t// Use contentText for built-in tools (including overrides without custom renderers)\n\t\tif (toolName === \"bash\" || (toolDefinition && !this.shouldUseBuiltInRenderer())) {\n\t\t\tthis.addChild(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\t/**\n\t * Check if we should use built-in rendering for this tool.\n\t * Returns true if the tool name is a built-in AND either there's no toolDefinition\n\t * or the toolDefinition doesn't provide custom renderers.\n\t */\n\tprivate shouldUseBuiltInRenderer(): boolean {\n\t\tconst isBuiltInName = this.toolName in allTools;\n\t\tconst hasCustomRenderers = this.toolDefinition?.renderCall || this.toolDefinition?.renderResult;\n\t\treturn isBuiltInName && !hasCustomRenderers;\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tif (this.toolName === \"write\" && this.isPartial) {\n\t\t\tthis.updateWriteHighlightCacheIncremental();\n\t\t}\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate highlightSingleLine(line: string, lang: string): string {\n\t\tconst highlighted = highlightCode(line, lang);\n\t\treturn highlighted[0] ?? \"\";\n\t}\n\n\tprivate refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\t\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\t\tif (prefixCount === 0) return;\n\n\t\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\t\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\t\tfor (let i = 0; i < prefixCount; i++) {\n\t\t\tcache.highlightedLines[i] =\n\t\t\t\tprefixHighlighted[i] ?? this.highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t\t}\n\t}\n\n\tprivate rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): void {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tif (!lang) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst displayContent = normalizeDisplayText(fileContent);\n\t\tconst normalized = replaceTabs(displayContent);\n\t\tthis.writeHighlightCache = {\n\t\t\trawPath,\n\t\t\tlang,\n\t\t\trawContent: fileContent,\n\t\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\t\thighlightedLines: highlightCode(normalized, lang),\n\t\t};\n\t}\n\n\tprivate updateWriteHighlightCacheIncremental(): void {\n\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\tconst fileContent = str(this.args?.content);\n\t\tif (rawPath === null || fileContent === null) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tif (!lang) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.writeHighlightCache) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tconst cache = this.writeHighlightCache;\n\t\tif (cache.lang !== lang || cache.rawPath !== rawPath) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!fileContent.startsWith(cache.rawContent)) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tif (fileContent.length === cache.rawContent.length) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\t\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\t\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\t\tcache.rawContent = fileContent;\n\n\t\tif (cache.normalizedLines.length === 0) {\n\t\t\tcache.normalizedLines.push(\"\");\n\t\t\tcache.highlightedLines.push(\"\");\n\t\t}\n\n\t\tconst segments = deltaNormalized.split(\"\\n\");\n\t\tconst lastIndex = cache.normalizedLines.length - 1;\n\t\tcache.normalizedLines[lastIndex] += segments[0];\n\t\tcache.highlightedLines[lastIndex] = this.highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\n\t\tfor (let i = 1; i < segments.length; i++) {\n\t\t\tcache.normalizedLines.push(segments[i]);\n\t\t\tcache.highlightedLines.push(this.highlightSingleLine(segments[i], cache.lang));\n\t\t}\n\n\t\tthis.refreshWriteHighlightPrefix(cache);\n\t}\n\n\t/**\n\t * Signal that args are complete (tool is about to execute).\n\t * This triggers diff computation for edit tool.\n\t */\n\tsetArgsComplete(): void {\n\t\tif (this.toolName === \"write\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tif (rawPath !== null && fileContent !== null) {\n\t\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\t}\n\t\t}\n\t\tthis.maybeComputeEditDiff();\n\t}\n\n\t/**\n\t * Compute edit diff preview when we have complete args.\n\t * This runs async and updates display when done.\n\t */\n\tprivate maybeComputeEditDiff(): void {\n\t\tif (this.toolName !== \"edit\") return;\n\n\t\tconst path = this.args?.path;\n\t\tconst oldText = this.args?.oldText;\n\t\tconst newText = this.args?.newText;\n\n\t\t// Need all three params to compute diff\n\t\tif (!path || oldText === undefined || newText === undefined) return;\n\n\t\t// Create a key to track which args this computation is for\n\t\tconst argsKey = JSON.stringify({ path, oldText, newText });\n\n\t\t// Skip if we already computed for these exact args\n\t\tif (this.editDiffArgsKey === argsKey) return;\n\n\t\tthis.editDiffArgsKey = argsKey;\n\n\t\t// Compute diff async\n\t\tcomputeEditDiff(path, oldText, newText, this.cwd).then((result) => {\n\t\t\t// Only update if args haven't changed since we started\n\t\t\tif (this.editDiffArgsKey === argsKey) {\n\t\t\t\tthis.editDiffPreview = result;\n\t\t\t\tthis.updateDisplay();\n\t\t\t\tthis.ui.requestRender();\n\t\t\t}\n\t\t});\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\tif (this.toolName === \"write\" && !isPartial) {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tif (rawPath !== null && fileContent !== null) {\n\t\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\t}\n\t\t}\n\t\tthis.updateDisplay();\n\t\t// Convert non-PNG images to PNG for Kitty protocol (async)\n\t\tthis.maybeConvertImagesForKitty();\n\t}\n\n\t/**\n\t * Convert non-PNG images to PNG for Kitty graphics protocol.\n\t * Kitty requires PNG format (f=100), so JPEG/GIF/WebP won't display.\n\t */\n\tprivate maybeConvertImagesForKitty(): void {\n\t\tconst caps = getCapabilities();\n\t\t// Only needed for Kitty protocol\n\t\tif (caps.images !== \"kitty\") return;\n\t\tif (!this.result) return;\n\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\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\t// Skip if already PNG or already converted\n\t\t\tif (img.mimeType === \"image/png\") continue;\n\t\t\tif (this.convertedImages.has(i)) continue;\n\n\t\t\t// Convert async\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\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) {\n\t\t\treturn [];\n\t\t}\n\t\treturn super.render(width);\n\t}\n\n\tprivate updateDisplay(): void {\n\t\t// Set background based on state\n\t\tconst bgFn = this.isPartial\n\t\t\t? (text: string) => theme.bg(\"toolPendingBg\", text)\n\t\t\t: this.result?.isError\n\t\t\t\t? (text: string) => theme.bg(\"toolErrorBg\", text)\n\t\t\t\t: (text: string) => theme.bg(\"toolSuccessBg\", text);\n\n\t\tconst useBuiltInRenderer = this.shouldUseBuiltInRenderer();\n\t\tlet customRendererHasContent = false;\n\t\tthis.hideComponent = false;\n\n\t\t// Use built-in rendering for built-in tools (or overrides without custom renderers)\n\t\tif (useBuiltInRenderer) {\n\t\t\tif (this.toolName === \"bash\") {\n\t\t\t\t// Bash uses Box with visual line truncation\n\t\t\t\tthis.contentBox.setBgFn(bgFn);\n\t\t\t\tthis.contentBox.clear();\n\t\t\t\tthis.renderBashContent();\n\t\t\t} else {\n\t\t\t\t// Other built-in tools: use Text directly with caching\n\t\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t\t}\n\t\t} else if (this.toolDefinition) {\n\t\t\t// Custom tools use Box for flexible component rendering\n\t\t\tthis.contentBox.setBgFn(bgFn);\n\t\t\tthis.contentBox.clear();\n\n\t\t\t// Render call component\n\t\t\tif (this.toolDefinition.renderCall) {\n\t\t\t\ttry {\n\t\t\t\t\tconst callComponent = this.toolDefinition.renderCall(this.args, theme);\n\t\t\t\t\tif (callComponent !== undefined) {\n\t\t\t\t\t\tthis.contentBox.addChild(callComponent);\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Fall back to default on error\n\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(this.toolName)), 0, 0));\n\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No custom renderCall, show tool name\n\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(this.toolName)), 0, 0));\n\t\t\t\tcustomRendererHasContent = true;\n\t\t\t}\n\n\t\t\t// Render result component if we have a result\n\t\t\tif (this.result && this.toolDefinition.renderResult) {\n\t\t\t\ttry {\n\t\t\t\t\tconst resultComponent = this.toolDefinition.renderResult(\n\t\t\t\t\t\t{ content: this.result.content as any, details: this.result.details },\n\t\t\t\t\t\t{ expanded: this.expanded, isPartial: this.isPartial },\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t);\n\t\t\t\t\tif (resultComponent !== undefined) {\n\t\t\t\t\t\tthis.contentBox.addChild(resultComponent);\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Fall back to showing raw output on error\n\t\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\t\tif (output) {\n\t\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolOutput\", output), 0, 0));\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (this.result) {\n\t\t\t\t// Has result but no custom renderResult\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tif (output) {\n\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolOutput\", output), 0, 0));\n\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Unknown tool with no registered definition - show generic fallback\n\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t}\n\n\t\t// Handle images (same for both custom and built-in)\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: any) => c.type === \"image\") || [];\n\t\t\tconst caps = getCapabilities();\n\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\t// Use converted PNG for Kitty protocol if available\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\n\t\t\t\t\t// For Kitty, skip non-PNG images that haven't been converted yet\n\t\t\t\t\tif (caps.images === \"kitty\" && imageMimeType !== \"image/png\") {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\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: 60 },\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 (!useBuiltInRenderer && this.toolDefinition) {\n\t\t\tthis.hideComponent = !customRendererHasContent && this.imageComponents.length === 0;\n\t\t}\n\t}\n\n\t/**\n\t * Render bash content using visual line truncation (like bash-execution.ts)\n\t */\n\tprivate renderBashContent(): void {\n\t\tconst command = str(this.args?.command);\n\t\tconst timeout = this.args?.timeout as number | undefined;\n\n\t\t// Header\n\t\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\t\tconst commandDisplay =\n\t\t\tcommand === null ? theme.fg(\"error\", \"[invalid arg]\") : command ? command : theme.fg(\"toolOutput\", \"...\");\n\t\tthis.contentBox.addChild(\n\t\t\tnew Text(theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix, 0, 0),\n\t\t);\n\n\t\tif (this.result) {\n\t\t\tconst output = this.getTextOutput().trim();\n\n\t\t\tif (output) {\n\t\t\t\t// Style each line for the output\n\t\t\t\tconst styledOutput = output\n\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t\t\t.join(\"\\n\");\n\n\t\t\t\tif (this.expanded) {\n\t\t\t\t\t// Show all lines when expanded\n\t\t\t\t\tthis.contentBox.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t\t\t} else {\n\t\t\t\t\t// Use visual line truncation when collapsed with width-aware caching\n\t\t\t\t\tlet cachedWidth: number | undefined;\n\t\t\t\t\tlet cachedLines: string[] | undefined;\n\t\t\t\t\tlet cachedSkipped: number | undefined;\n\n\t\t\t\t\tthis.contentBox.addChild({\n\t\t\t\t\t\trender: (width: number) => {\n\t\t\t\t\t\t\tif (cachedLines === undefined || cachedWidth !== width) {\n\t\t\t\t\t\t\t\tconst result = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\t\t\tcachedLines = result.visualLines;\n\t\t\t\t\t\t\t\tcachedSkipped = result.skippedCount;\n\t\t\t\t\t\t\t\tcachedWidth = width;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (cachedSkipped && cachedSkipped > 0) {\n\t\t\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t\t\t` ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...cachedLines];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Add blank line for spacing (matches expanded case)\n\t\t\t\t\t\t\treturn [\"\", ...cachedLines];\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinvalidate: () => {\n\t\t\t\t\t\t\tcachedWidth = undefined;\n\t\t\t\t\t\t\tcachedLines = undefined;\n\t\t\t\t\t\t\tcachedSkipped = undefined;\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Truncation warnings\n\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\tconst fullOutputPath = this.result.details?.fullOutputPath;\n\t\t\tif (truncation?.truncated || fullOutputPath) {\n\t\t\t\tconst warnings: string[] = [];\n\t\t\t\tif (fullOutputPath) {\n\t\t\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t\t\t}\n\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\twarnings.push(\n\t\t\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.contentBox.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getTextOutput(): string {\n\t\tif (!this.result) return \"\";\n\n\t\tconst textBlocks = this.result.content?.filter((c: any) => c.type === \"text\") || [];\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\n\t\tlet output = textBlocks\n\t\t\t.map((c: any) => {\n\t\t\t\t// Use sanitizeBinaryOutput to handle binary data that crashes string-width\n\t\t\t\treturn sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\");\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\n\t\tconst caps = getCapabilities();\n\t\tif (imageBlocks.length > 0 && (!caps.images || !this.showImages)) {\n\t\t\tconst imageIndicators = imageBlocks\n\t\t\t\t.map((img: any) => {\n\t\t\t\t\tconst dims = img.data ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\t\treturn imageFallback(img.mimeType, dims);\n\t\t\t\t})\n\t\t\t\t.join(\"\\n\");\n\t\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tlet text = \"\";\n\t\tconst invalidArg = theme.fg(\"error\", \"[invalid arg]\");\n\n\t\tif (this.toolName === \"read\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\t\t\tconst offset = this.args?.offset;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\tlet pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\t\t\tif (offset !== undefined || limit !== undefined) {\n\t\t\t\tconst startLine = offset ?? 1;\n\t\t\t\tconst endLine = limit !== undefined ? startLine + limit - 1 : \"\";\n\t\t\t\tpathDisplay += theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n\t\t\t}\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}`;\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\t\t\tconst lines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext +=\n\t\t\t\t\t\"\\n\\n\" +\n\t\t\t\t\tdisplayLines\n\t\t\t\t\t\t.map((line: string) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line))))\n\t\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t}\n\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"write\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"write\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\"));\n\n\t\t\tif (fileContent === null) {\n\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t\t\t} else if (fileContent) {\n\t\t\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\n\t\t\t\tlet lines: string[];\n\t\t\t\tif (lang) {\n\t\t\t\t\tconst cache = this.writeHighlightCache;\n\t\t\t\t\tif (cache && cache.lang === lang && cache.rawPath === rawPath && cache.rawContent === fileContent) {\n\t\t\t\t\t\tlines = cache.highlightedLines;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst displayContent = normalizeDisplayText(fileContent);\n\t\t\t\t\t\tconst normalized = replaceTabs(displayContent);\n\t\t\t\t\t\tlines = highlightCode(normalized, lang);\n\t\t\t\t\t\tthis.writeHighlightCache = {\n\t\t\t\t\t\t\trawPath,\n\t\t\t\t\t\t\tlang,\n\t\t\t\t\t\t\trawContent: fileContent,\n\t\t\t\t\t\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\t\t\t\t\t\thighlightedLines: lines,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlines = normalizeDisplayText(fileContent).split(\"\\n\");\n\t\t\t\t\tthis.writeHighlightCache = undefined;\n\t\t\t\t}\n\n\t\t\t\tconst totalLines = lines.length;\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext +=\n\t\t\t\t\t\"\\n\\n\" +\n\t\t\t\t\tdisplayLines.map((line: string) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext +=\n\t\t\t\t\t\ttheme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`) +\n\t\t\t\t\t\t` ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Show error if tool execution failed\n\t\t\tif (this.result?.isError) {\n\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\tif (errorText) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", errorText)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"edit\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\n\t\t\t// Build path display, appending :line if we have diff info\n\t\t\tlet pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\t\t\tconst firstChangedLine =\n\t\t\t\t(this.editDiffPreview && \"firstChangedLine\" in this.editDiffPreview\n\t\t\t\t\t? this.editDiffPreview.firstChangedLine\n\t\t\t\t\t: undefined) ||\n\t\t\t\t(this.result && !this.result.isError ? this.result.details?.firstChangedLine : undefined);\n\t\t\tif (firstChangedLine) {\n\t\t\t\tpathDisplay += theme.fg(\"warning\", `:${firstChangedLine}`);\n\t\t\t}\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n\n\t\t\tif (this.result?.isError) {\n\t\t\t\t// Show error from result\n\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\tif (errorText) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", errorText)}`;\n\t\t\t\t}\n\t\t\t} else if (this.result?.details?.diff) {\n\t\t\t\t// Tool executed successfully - use the diff from result\n\t\t\t\t// This takes priority over editDiffPreview which may have a stale error\n\t\t\t\t// due to race condition (async preview computed after file was modified)\n\t\t\t\ttext += `\\n\\n${renderDiff(this.result.details.diff, { filePath: rawPath ?? undefined })}`;\n\t\t\t} else if (this.editDiffPreview) {\n\t\t\t\t// Use cached diff preview (before tool executes)\n\t\t\t\tif (\"error\" in this.editDiffPreview) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", this.editDiffPreview.error)}`;\n\t\t\t\t} else if (this.editDiffPreview.diff) {\n\t\t\t\t\ttext += `\\n\\n${renderDiff(this.editDiffPreview.diff, { filePath: rawPath ?? undefined })}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"ls\") {\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"ls\"))} ${path === null ? invalidArg : theme.fg(\"accent\", path)}`;\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 20;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst entryLimit = this.result.details?.entryLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (entryLimit || truncation?.truncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (entryLimit) {\n\t\t\t\t\t\twarnings.push(`${entryLimit} entries limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"find\") {\n\t\t\tconst pattern = str(this.args?.pattern);\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"find\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(pattern === null ? invalidArg : theme.fg(\"accent\", pattern || \"\")) +\n\t\t\t\ttheme.fg(\"toolOutput\", ` in ${path === null ? invalidArg : path}`);\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 20;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst resultLimit = this.result.details?.resultLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (resultLimit || truncation?.truncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (resultLimit) {\n\t\t\t\t\t\twarnings.push(`${resultLimit} results limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"grep\") {\n\t\t\tconst pattern = str(this.args?.pattern);\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst glob = str(this.args?.glob);\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"grep\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(pattern === null ? invalidArg : theme.fg(\"accent\", `/${pattern || \"\"}/`)) +\n\t\t\t\ttheme.fg(\"toolOutput\", ` in ${path === null ? invalidArg : path}`);\n\t\t\tif (glob) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (${glob})`);\n\t\t\t}\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` limit ${limit}`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 15;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst matchLimit = this.result.details?.matchLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tconst linesTruncated = this.result.details?.linesTruncated;\n\t\t\t\tif (matchLimit || truncation?.truncated || linesTruncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (matchLimit) {\n\t\t\t\t\t\twarnings.push(`${matchLimit} matches limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (linesTruncated) {\n\t\t\t\t\t\twarnings.push(\"some lines truncated\");\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Generic tool (shouldn't reach here for custom tools)\n\t\t\ttext = theme.fg(\"toolTitle\", theme.bold(this.toolName));\n\n\t\t\tconst content = JSON.stringify(this.args, null, 2);\n\t\t\ttext += `\\n\\n${content}`;\n\t\t\tconst output = this.getTextOutput();\n\t\t\tif (output) {\n\t\t\t\ttext += `\\n${output}`;\n\t\t\t}\n\t\t}\n\n\t\treturn text;\n\t}\n}\n"]}
1
+ {"version":3,"file":"tool-execution.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/tool-execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EACN,GAAG,EACH,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,KAAK,EACL,aAAa,EACb,MAAM,EACN,IAAI,EAEJ,eAAe,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,eAAe,EAA2C,MAAM,kCAAkC,CAAC;AAC5G,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAA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C,EAAE,CAAC,SAAS,EAAE,eAAe,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC3E,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,uDAAuD;YACvD,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAExD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACnD,IAAI,IAAI,OAAO,OAAO,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACpC,IAAI,MAAM,EAAE,CAAC;gBACZ,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YACvB,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IAAA,CACZ;CACD","sourcesContent":["import * as os from \"node:os\";\nimport {\n\tBox,\n\tContainer,\n\tgetCapabilities,\n\tgetImageDimensions,\n\tImage,\n\timageFallback,\n\tSpacer,\n\tText,\n\ttype TUI,\n\ttruncateToWidth,\n} from \"@apholdings/jensen-tui\";\nimport stripAnsi from \"strip-ansi\";\nimport type { ToolDefinition } from \"../../../core/extensions/types.js\";\nimport { computeEditDiff, type EditDiffError, type EditDiffResult } from \"../../../core/tools/edit-diff.js\";\nimport { allTools } from \"../../../core/tools/index.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from \"../../../core/tools/truncate.js\";\nimport { convertToPng } from \"../../../utils/image-convert.js\";\nimport { sanitizeBinaryOutput } from \"../../../utils/shell.js\";\nimport { getLanguageFromPath, highlightCode, theme } from \"../theme/theme.js\";\nimport { renderDiff } from \"./diff.js\";\nimport { keyHint } from \"./keybinding-hints.js\";\nimport { truncateToVisualLines } from \"./visual-truncate.js\";\n\n// Preview line limit for bash when not expanded\nconst BASH_PREVIEW_LINES = 5;\n// During partial write tool-call streaming, re-highlight the first N lines fully\n// to keep multiline tokenization mostly correct without re-highlighting the full file.\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n\n/**\n * Convert absolute path to tilde notation if it's in home directory\n */\nfunction shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\n/**\n * Replace tabs with spaces for consistent rendering\n */\nfunction replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\n/**\n * Normalize control characters for terminal preview rendering.\n * Keep tool arguments unchanged, sanitize only display text.\n */\nfunction normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\n/** Safely coerce value to string for display. Returns null if invalid type. */\nfunction str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null; // Invalid type\n}\n\nexport interface ToolExecutionOptions {\n\tshowImages?: boolean; // default: true (only used if terminal supports images)\n}\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\n\n/**\n * Component that renders a tool call with its result (updateable)\n */\nexport class ToolExecutionComponent extends Container {\n\tprivate contentBox: Box; // Used for custom tools and bash visual truncation\n\tprivate contentText: Text; // For built-in tools (with its own padding/bg)\n\tprivate imageComponents: Image[] = [];\n\tprivate imageSpacers: Spacer[] = [];\n\tprivate toolName: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate isPartial = true;\n\tprivate toolDefinition?: ToolDefinition;\n\tprivate ui: TUI;\n\tprivate cwd: string;\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\t// Cached edit diff preview (computed when args arrive, before tool executes)\n\tprivate editDiffPreview?: EditDiffResult | EditDiffError;\n\tprivate editDiffArgsKey?: string; // Track which args the preview is for\n\t// Cached converted images for Kitty protocol (which requires PNG), keyed by index\n\tprivate convertedImages: Map<number, { data: string; mimeType: string }> = new Map();\n\t// Incremental syntax highlighting cache for write tool call args\n\tprivate writeHighlightCache?: WriteHighlightCache;\n\t// When true, this component intentionally renders no lines\n\tprivate hideComponent = false;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\targs: any,\n\t\toptions: ToolExecutionOptions = {},\n\t\ttoolDefinition: ToolDefinition | undefined,\n\t\tui: TUI,\n\t\tcwd: string = process.cwd(),\n\t) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.args = args;\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.toolDefinition = toolDefinition;\n\t\tthis.ui = ui;\n\t\tthis.cwd = cwd;\n\n\t\t// Always create both - contentBox for custom tools/bash, contentText for other built-ins\n\t\tthis.contentBox = new Box(1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\t\tthis.contentText = new Text(\"\", 1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\n\t\t// Use contentBox for bash (visual truncation) or custom tools with custom renderers\n\t\t// Use contentText for built-in tools (including overrides without custom renderers)\n\t\tif (toolName === \"bash\" || (toolDefinition && !this.shouldUseBuiltInRenderer())) {\n\t\t\tthis.addChild(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\t/**\n\t * Check if we should use built-in rendering for this tool.\n\t * Returns true if the tool name is a built-in AND either there's no toolDefinition\n\t * or the toolDefinition doesn't provide custom renderers.\n\t */\n\tprivate shouldUseBuiltInRenderer(): boolean {\n\t\tconst isBuiltInName = this.toolName in allTools;\n\t\tconst hasCustomRenderers = this.toolDefinition?.renderCall || this.toolDefinition?.renderResult;\n\t\treturn isBuiltInName && !hasCustomRenderers;\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tif (this.toolName === \"write\" && this.isPartial) {\n\t\t\tthis.updateWriteHighlightCacheIncremental();\n\t\t}\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate highlightSingleLine(line: string, lang: string): string {\n\t\tconst highlighted = highlightCode(line, lang);\n\t\treturn highlighted[0] ?? \"\";\n\t}\n\n\tprivate refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\t\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\t\tif (prefixCount === 0) return;\n\n\t\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\t\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\t\tfor (let i = 0; i < prefixCount; i++) {\n\t\t\tcache.highlightedLines[i] =\n\t\t\t\tprefixHighlighted[i] ?? this.highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t\t}\n\t}\n\n\tprivate rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): void {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tif (!lang) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst displayContent = normalizeDisplayText(fileContent);\n\t\tconst normalized = replaceTabs(displayContent);\n\t\tthis.writeHighlightCache = {\n\t\t\trawPath,\n\t\t\tlang,\n\t\t\trawContent: fileContent,\n\t\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\t\thighlightedLines: highlightCode(normalized, lang),\n\t\t};\n\t}\n\n\tprivate updateWriteHighlightCacheIncremental(): void {\n\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\tconst fileContent = str(this.args?.content);\n\t\tif (rawPath === null || fileContent === null) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tif (!lang) {\n\t\t\tthis.writeHighlightCache = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.writeHighlightCache) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tconst cache = this.writeHighlightCache;\n\t\tif (cache.lang !== lang || cache.rawPath !== rawPath) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!fileContent.startsWith(cache.rawContent)) {\n\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\treturn;\n\t\t}\n\n\t\tif (fileContent.length === cache.rawContent.length) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\t\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\t\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\t\tcache.rawContent = fileContent;\n\n\t\tif (cache.normalizedLines.length === 0) {\n\t\t\tcache.normalizedLines.push(\"\");\n\t\t\tcache.highlightedLines.push(\"\");\n\t\t}\n\n\t\tconst segments = deltaNormalized.split(\"\\n\");\n\t\tconst lastIndex = cache.normalizedLines.length - 1;\n\t\tcache.normalizedLines[lastIndex] += segments[0];\n\t\tcache.highlightedLines[lastIndex] = this.highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\n\t\tfor (let i = 1; i < segments.length; i++) {\n\t\t\tcache.normalizedLines.push(segments[i]);\n\t\t\tcache.highlightedLines.push(this.highlightSingleLine(segments[i], cache.lang));\n\t\t}\n\n\t\tthis.refreshWriteHighlightPrefix(cache);\n\t}\n\n\t/**\n\t * Signal that args are complete (tool is about to execute).\n\t * This triggers diff computation for edit tool.\n\t */\n\tsetArgsComplete(): void {\n\t\tif (this.toolName === \"write\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tif (rawPath !== null && fileContent !== null) {\n\t\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\t}\n\t\t}\n\t\tthis.maybeComputeEditDiff();\n\t}\n\n\t/**\n\t * Compute edit diff preview when we have complete args.\n\t * This runs async and updates display when done.\n\t */\n\tprivate maybeComputeEditDiff(): void {\n\t\tif (this.toolName !== \"edit\") return;\n\n\t\tconst path = this.args?.path;\n\t\tconst oldText = this.args?.oldText;\n\t\tconst newText = this.args?.newText;\n\n\t\t// Need all three params to compute diff\n\t\tif (!path || oldText === undefined || newText === undefined) return;\n\n\t\t// Create a key to track which args this computation is for\n\t\tconst argsKey = JSON.stringify({ path, oldText, newText });\n\n\t\t// Skip if we already computed for these exact args\n\t\tif (this.editDiffArgsKey === argsKey) return;\n\n\t\tthis.editDiffArgsKey = argsKey;\n\n\t\t// Compute diff async\n\t\tcomputeEditDiff(path, oldText, newText, this.cwd).then((result) => {\n\t\t\t// Only update if args haven't changed since we started\n\t\t\tif (this.editDiffArgsKey === argsKey) {\n\t\t\t\tthis.editDiffPreview = result;\n\t\t\t\tthis.updateDisplay();\n\t\t\t\tthis.ui.requestRender();\n\t\t\t}\n\t\t});\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\tif (this.toolName === \"write\" && !isPartial) {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tif (rawPath !== null && fileContent !== null) {\n\t\t\t\tthis.rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t\t\t}\n\t\t}\n\t\tthis.updateDisplay();\n\t\t// Convert non-PNG images to PNG for Kitty protocol (async)\n\t\tthis.maybeConvertImagesForKitty();\n\t}\n\n\t/**\n\t * Convert non-PNG images to PNG for Kitty graphics protocol.\n\t * Kitty requires PNG format (f=100), so JPEG/GIF/WebP won't display.\n\t */\n\tprivate maybeConvertImagesForKitty(): void {\n\t\tconst caps = getCapabilities();\n\t\t// Only needed for Kitty protocol\n\t\tif (caps.images !== \"kitty\") return;\n\t\tif (!this.result) return;\n\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\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\t// Skip if already PNG or already converted\n\t\t\tif (img.mimeType === \"image/png\") continue;\n\t\t\tif (this.convertedImages.has(i)) continue;\n\n\t\t\t// Convert async\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\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) {\n\t\t\treturn [];\n\t\t}\n\t\treturn [...super.render(width), \"\"];\n\t}\n\n\tprivate updateDisplay(): void {\n\t\t// Set background based on state\n\t\tconst bgFn = this.isPartial\n\t\t\t? (text: string) => theme.bg(\"toolPendingBg\", text)\n\t\t\t: this.result?.isError\n\t\t\t\t? (text: string) => theme.bg(\"toolErrorBg\", text)\n\t\t\t\t: (text: string) => theme.bg(\"toolSuccessBg\", text);\n\n\t\tconst useBuiltInRenderer = this.shouldUseBuiltInRenderer();\n\t\tlet customRendererHasContent = false;\n\t\tthis.hideComponent = false;\n\n\t\t// Use built-in rendering for built-in tools (or overrides without custom renderers)\n\t\tif (useBuiltInRenderer) {\n\t\t\tif (this.toolName === \"bash\") {\n\t\t\t\t// Bash uses Box with visual line truncation\n\t\t\t\tthis.contentBox.setBgFn(bgFn);\n\t\t\t\tthis.contentBox.clear();\n\t\t\t\tthis.renderBashContent();\n\t\t\t} else {\n\t\t\t\t// Other built-in tools: use Text directly with caching\n\t\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t\t}\n\t\t} else if (this.toolDefinition) {\n\t\t\t// Custom tools use Box for flexible component rendering\n\t\t\tthis.contentBox.setBgFn(bgFn);\n\t\t\tthis.contentBox.clear();\n\n\t\t\t// Render call component\n\t\t\tif (this.toolDefinition.renderCall) {\n\t\t\t\ttry {\n\t\t\t\t\tconst callComponent = this.toolDefinition.renderCall(this.args, theme);\n\t\t\t\t\tif (callComponent !== undefined) {\n\t\t\t\t\t\tthis.contentBox.addChild(callComponent);\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Fall back to default on error\n\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(this.toolName)), 0, 0));\n\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No custom renderCall, show tool name\n\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(this.toolName)), 0, 0));\n\t\t\t\tcustomRendererHasContent = true;\n\t\t\t}\n\n\t\t\t// Render result component if we have a result\n\t\t\tif (this.result && this.toolDefinition.renderResult) {\n\t\t\t\ttry {\n\t\t\t\t\tconst resultComponent = this.toolDefinition.renderResult(\n\t\t\t\t\t\t{ content: this.result.content as any, details: this.result.details },\n\t\t\t\t\t\t{ expanded: this.expanded, isPartial: this.isPartial },\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t);\n\t\t\t\t\tif (resultComponent !== undefined) {\n\t\t\t\t\t\tthis.contentBox.addChild(resultComponent);\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Fall back to showing raw output on error\n\t\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\t\tif (output) {\n\t\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolOutput\", output), 0, 0));\n\t\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (this.result) {\n\t\t\t\t// Has result but no custom renderResult\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tif (output) {\n\t\t\t\t\tthis.contentBox.addChild(new Text(theme.fg(\"toolOutput\", output), 0, 0));\n\t\t\t\t\tcustomRendererHasContent = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Unknown tool with no registered definition - show generic fallback\n\t\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\t\tthis.contentText.setText(this.formatToolExecution());\n\t\t}\n\n\t\t// Handle images (same for both custom and built-in)\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: any) => c.type === \"image\") || [];\n\t\t\tconst caps = getCapabilities();\n\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\t// Use converted PNG for Kitty protocol if available\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\n\t\t\t\t\t// For Kitty, skip non-PNG images that haven't been converted yet\n\t\t\t\t\tif (caps.images === \"kitty\" && imageMimeType !== \"image/png\") {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\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: 60 },\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 (!useBuiltInRenderer && this.toolDefinition) {\n\t\t\tthis.hideComponent = !customRendererHasContent && this.imageComponents.length === 0;\n\t\t}\n\t}\n\n\t/**\n\t * Render bash content using visual line truncation (like bash-execution.ts)\n\t */\n\tprivate renderBashContent(): void {\n\t\tconst command = str(this.args?.command);\n\t\tconst timeout = this.args?.timeout as number | undefined;\n\n\t\t// Header\n\t\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\t\tconst commandDisplay =\n\t\t\tcommand === null ? theme.fg(\"error\", \"[invalid arg]\") : command ? command : theme.fg(\"toolOutput\", \"...\");\n\t\tthis.contentBox.addChild(\n\t\t\tnew Text(theme.fg(\"toolTitle\", theme.bold(`$ ${commandDisplay}`)) + timeoutSuffix, 0, 0),\n\t\t);\n\n\t\tif (this.result) {\n\t\t\tconst output = this.getTextOutput().trim();\n\n\t\t\tif (output) {\n\t\t\t\t// Style each line for the output\n\t\t\t\tconst styledOutput = output\n\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t\t\t.join(\"\\n\");\n\n\t\t\t\tif (this.expanded) {\n\t\t\t\t\t// Show all lines when expanded\n\t\t\t\t\tthis.contentBox.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t\t\t} else {\n\t\t\t\t\t// Use visual line truncation when collapsed with width-aware caching\n\t\t\t\t\tlet cachedWidth: number | undefined;\n\t\t\t\t\tlet cachedLines: string[] | undefined;\n\t\t\t\t\tlet cachedSkipped: number | undefined;\n\n\t\t\t\t\tthis.contentBox.addChild({\n\t\t\t\t\t\trender: (width: number) => {\n\t\t\t\t\t\t\tif (cachedLines === undefined || cachedWidth !== width) {\n\t\t\t\t\t\t\t\tconst result = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\t\t\tcachedLines = result.visualLines;\n\t\t\t\t\t\t\t\tcachedSkipped = result.skippedCount;\n\t\t\t\t\t\t\t\tcachedWidth = width;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (cachedSkipped && cachedSkipped > 0) {\n\t\t\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${cachedSkipped} earlier lines,`) +\n\t\t\t\t\t\t\t\t\t` ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t\t\t\treturn [\"\", truncateToWidth(hint, width, \"...\"), ...cachedLines];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Add blank line for spacing (matches expanded case)\n\t\t\t\t\t\t\treturn [\"\", ...cachedLines];\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinvalidate: () => {\n\t\t\t\t\t\t\tcachedWidth = undefined;\n\t\t\t\t\t\t\tcachedLines = undefined;\n\t\t\t\t\t\t\tcachedSkipped = undefined;\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Truncation warnings\n\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\tconst fullOutputPath = this.result.details?.fullOutputPath;\n\t\t\tif (truncation?.truncated || fullOutputPath) {\n\t\t\t\tconst warnings: string[] = [];\n\t\t\t\tif (fullOutputPath) {\n\t\t\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t\t\t}\n\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\twarnings.push(\n\t\t\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.contentBox.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getTextOutput(): string {\n\t\tif (!this.result) return \"\";\n\n\t\tconst textBlocks = this.result.content?.filter((c: any) => c.type === \"text\") || [];\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\n\t\tlet output = textBlocks\n\t\t\t.map((c: any) => {\n\t\t\t\t// Use sanitizeBinaryOutput to handle binary data that crashes string-width\n\t\t\t\treturn sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\");\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\n\t\tconst caps = getCapabilities();\n\t\tif (imageBlocks.length > 0 && (!caps.images || !this.showImages)) {\n\t\t\tconst imageIndicators = imageBlocks\n\t\t\t\t.map((img: any) => {\n\t\t\t\t\tconst dims = img.data ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\t\treturn imageFallback(img.mimeType, dims);\n\t\t\t\t})\n\t\t\t\t.join(\"\\n\");\n\t\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tlet text = \"\";\n\t\tconst invalidArg = theme.fg(\"error\", \"[invalid arg]\");\n\n\t\tif (this.toolName === \"read\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\t\t\tconst offset = this.args?.offset;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\tlet pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\t\t\tif (offset !== undefined || limit !== undefined) {\n\t\t\t\tconst startLine = offset ?? 1;\n\t\t\t\tconst endLine = limit !== undefined ? startLine + limit - 1 : \"\";\n\t\t\t\tpathDisplay += theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n\t\t\t}\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}`;\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\t\t\tconst lines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext +=\n\t\t\t\t\t\"\\n\\n\" +\n\t\t\t\t\tdisplayLines\n\t\t\t\t\t\t.map((line: string) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line))))\n\t\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t}\n\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext +=\n\t\t\t\t\t\t\t\"\\n\" +\n\t\t\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t\t`[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"write\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst fileContent = str(this.args?.content);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"write\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\"));\n\n\t\t\tif (fileContent === null) {\n\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t\t\t} else if (fileContent) {\n\t\t\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\n\t\t\t\tlet lines: string[];\n\t\t\t\tif (lang) {\n\t\t\t\t\tconst cache = this.writeHighlightCache;\n\t\t\t\t\tif (cache && cache.lang === lang && cache.rawPath === rawPath && cache.rawContent === fileContent) {\n\t\t\t\t\t\tlines = cache.highlightedLines;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst displayContent = normalizeDisplayText(fileContent);\n\t\t\t\t\t\tconst normalized = replaceTabs(displayContent);\n\t\t\t\t\t\tlines = highlightCode(normalized, lang);\n\t\t\t\t\t\tthis.writeHighlightCache = {\n\t\t\t\t\t\t\trawPath,\n\t\t\t\t\t\t\tlang,\n\t\t\t\t\t\t\trawContent: fileContent,\n\t\t\t\t\t\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\t\t\t\t\t\thighlightedLines: lines,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlines = normalizeDisplayText(fileContent).split(\"\\n\");\n\t\t\t\t\tthis.writeHighlightCache = undefined;\n\t\t\t\t}\n\n\t\t\t\tconst totalLines = lines.length;\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext +=\n\t\t\t\t\t\"\\n\\n\" +\n\t\t\t\t\tdisplayLines.map((line: string) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext +=\n\t\t\t\t\t\ttheme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`) +\n\t\t\t\t\t\t` ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Show error if tool execution failed\n\t\t\tif (this.result?.isError) {\n\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\tif (errorText) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", errorText)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"edit\") {\n\t\t\tconst rawPath = str(this.args?.file_path ?? this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\n\t\t\t// Build path display, appending :line if we have diff info\n\t\t\tlet pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\t\t\tconst firstChangedLine =\n\t\t\t\t(this.editDiffPreview && \"firstChangedLine\" in this.editDiffPreview\n\t\t\t\t\t? this.editDiffPreview.firstChangedLine\n\t\t\t\t\t: undefined) ||\n\t\t\t\t(this.result && !this.result.isError ? this.result.details?.firstChangedLine : undefined);\n\t\t\tif (firstChangedLine) {\n\t\t\t\tpathDisplay += theme.fg(\"warning\", `:${firstChangedLine}`);\n\t\t\t}\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n\n\t\t\tif (this.result?.isError) {\n\t\t\t\t// Show error from result\n\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\tif (errorText) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", errorText)}`;\n\t\t\t\t}\n\t\t\t} else if (this.result?.details?.diff) {\n\t\t\t\t// Tool executed successfully - use the diff from result\n\t\t\t\t// This takes priority over editDiffPreview which may have a stale error\n\t\t\t\t// due to race condition (async preview computed after file was modified)\n\t\t\t\ttext += `\\n\\n${renderDiff(this.result.details.diff, { filePath: rawPath ?? undefined })}`;\n\t\t\t} else if (this.editDiffPreview) {\n\t\t\t\t// Use cached diff preview (before tool executes)\n\t\t\t\tif (\"error\" in this.editDiffPreview) {\n\t\t\t\t\ttext += `\\n\\n${theme.fg(\"error\", this.editDiffPreview.error)}`;\n\t\t\t\t} else if (this.editDiffPreview.diff) {\n\t\t\t\t\ttext += `\\n\\n${renderDiff(this.editDiffPreview.diff, { filePath: rawPath ?? undefined })}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"ls\") {\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext = `${theme.fg(\"toolTitle\", theme.bold(\"ls\"))} ${path === null ? invalidArg : theme.fg(\"accent\", path)}`;\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 20;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst entryLimit = this.result.details?.entryLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (entryLimit || truncation?.truncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (entryLimit) {\n\t\t\t\t\t\twarnings.push(`${entryLimit} entries limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"find\") {\n\t\t\tconst pattern = str(this.args?.pattern);\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"find\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(pattern === null ? invalidArg : theme.fg(\"accent\", pattern || \"\")) +\n\t\t\t\ttheme.fg(\"toolOutput\", ` in ${path === null ? invalidArg : path}`);\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 20;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst resultLimit = this.result.details?.resultLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tif (resultLimit || truncation?.truncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (resultLimit) {\n\t\t\t\t\t\twarnings.push(`${resultLimit} results limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"grep\") {\n\t\t\tconst pattern = str(this.args?.pattern);\n\t\t\tconst rawPath = str(this.args?.path);\n\t\t\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\t\t\tconst glob = str(this.args?.glob);\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"grep\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(pattern === null ? invalidArg : theme.fg(\"accent\", `/${pattern || \"\"}/`)) +\n\t\t\t\ttheme.fg(\"toolOutput\", ` in ${path === null ? invalidArg : path}`);\n\t\t\tif (glob) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` (${glob})`);\n\t\t\t}\n\t\t\tif (limit !== undefined) {\n\t\t\t\ttext += theme.fg(\"toolOutput\", ` limit ${limit}`);\n\t\t\t}\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 15;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += `\\n\\n${displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"expandTools\", \"to expand\")})`;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst matchLimit = this.result.details?.matchLimitReached;\n\t\t\t\tconst truncation = this.result.details?.truncation;\n\t\t\t\tconst linesTruncated = this.result.details?.linesTruncated;\n\t\t\t\tif (matchLimit || truncation?.truncated || linesTruncated) {\n\t\t\t\t\tconst warnings: string[] = [];\n\t\t\t\t\tif (matchLimit) {\n\t\t\t\t\t\twarnings.push(`${matchLimit} matches limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (truncation?.truncated) {\n\t\t\t\t\t\twarnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\t\t\t\t}\n\t\t\t\t\tif (linesTruncated) {\n\t\t\t\t\t\twarnings.push(\"some lines truncated\");\n\t\t\t\t\t}\n\t\t\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Generic tool (shouldn't reach here for custom tools)\n\t\t\ttext = theme.fg(\"toolTitle\", theme.bold(this.toolName));\n\n\t\t\tconst content = JSON.stringify(this.args, null, 2);\n\t\t\ttext += `\\n\\n${content}`;\n\t\t\tconst output = this.getTextOutput();\n\t\t\tif (output) {\n\t\t\t\ttext += `\\n${output}`;\n\t\t\t}\n\t\t}\n\n\t\treturn text;\n\t}\n}\n"]}
@@ -36,20 +36,26 @@ export declare class InteractiveMode {
36
36
  private header;
37
37
  /** Container that normally hosts the prompt/editor, but may be replaced by selectors or extension UI. */
38
38
  private editorContainer;
39
+ private promptAreaComponent;
40
+ private promptWidgetsVisible;
39
41
  private footer;
40
42
  private footerDataProvider;
41
43
  private keybindings;
42
44
  private version;
43
45
  private isInitialized;
46
+ private initializing;
44
47
  private onInputCallback?;
45
48
  private loadingAnimation;
46
49
  private pendingWorkingMessage;
47
50
  private readonly defaultWorkingMessage;
51
+ private startupUiGateActive;
52
+ private deferredStartupNotices;
48
53
  private lastSigintTime;
49
54
  private lastEscapeTime;
50
55
  private changelogMarkdown;
51
56
  private lastStatusSpacer;
52
57
  private lastStatusText;
58
+ private statusComponent;
53
59
  private streamingComponent;
54
60
  private streamingMessage;
55
61
  private pendingTools;
@@ -68,6 +74,11 @@ export declare class InteractiveMode {
68
74
  private retryEscapeHandler?;
69
75
  private compactionQueuedMessages;
70
76
  private shutdownRequested;
77
+ private uiEpoch;
78
+ private sessionEpoch;
79
+ private isInitialMessagesRendered;
80
+ private statusOwner;
81
+ private promptOwner;
71
82
  private extensionSelector;
72
83
  private extensionInput;
73
84
  private extensionEditor;
@@ -92,7 +103,7 @@ export declare class InteractiveMode {
92
103
  private buildHelpReferenceText;
93
104
  private clearHelpContainer;
94
105
  private handleHelpCommand;
95
- private resetSessionUiState;
106
+ private resetInteractiveSessionUI;
96
107
  init(): Promise<void>;
97
108
  /**
98
109
  * Update terminal title with session name and cwd.
@@ -155,6 +166,12 @@ export declare class InteractiveMode {
155
166
  private setExtensionWidget;
156
167
  private clearExtensionWidgets;
157
168
  private resetExtensionUI;
169
+ private setPromptWidgetsVisible;
170
+ private mountPromptOwner;
171
+ private restoreCanonicalEditor;
172
+ private mountStatusOwner;
173
+ private mountStatusLoader;
174
+ private clearStatusOwner;
158
175
  private static readonly MAX_WIDGET_LINES;
159
176
  /**
160
177
  * Render all extension widgets to the widget container.
@@ -266,9 +283,11 @@ export declare class InteractiveMode {
266
283
  private toggleThinkingBlockVisibility;
267
284
  private openExternalEditor;
268
285
  clearEditor(): void;
269
- showError(errorMessage: string): void;
270
- showWarning(warningMessage: string): void;
271
- showNewVersionNotification(newVersion: string): void;
286
+ showError(errorMessage: string, ownerEpoch?: number): void;
287
+ private enqueueStartupNotice;
288
+ private flushDeferredStartupNotices;
289
+ showWarning(warningMessage: string, ownerEpoch?: number): void;
290
+ showNewVersionNotification(newVersion: string, ownerEpoch?: number): void;
272
291
  /**
273
292
  * Get all queued messages (read-only).
274
293
  * Combines session queue and compaction queue.