@ashx-j/lunr 0.2.22 → 0.2.23

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 (132) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/README.md +5 -3
  3. package/dist/builtin-extensions/lunr-browser.d.ts +7 -1
  4. package/dist/builtin-extensions/lunr-browser.d.ts.map +1 -1
  5. package/dist/builtin-extensions/lunr-browser.js +116 -3
  6. package/dist/builtin-extensions/lunr-browser.js.map +1 -1
  7. package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
  8. package/dist/builtin-extensions/pi-subagents/src/extension/index.js +1 -1
  9. package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
  10. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts +2 -0
  11. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts.map +1 -1
  12. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.js +9 -0
  13. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.js.map +1 -1
  14. package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.d.ts.map +1 -1
  15. package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js +41 -3
  16. package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js.map +1 -1
  17. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts.map +1 -1
  18. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +4 -0
  19. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js.map +1 -1
  20. package/dist/builtin-extensions/pi-subagents/src/tui/communication.d.ts +1 -1
  21. package/dist/builtin-extensions/pi-subagents/src/tui/communication.d.ts.map +1 -1
  22. package/dist/builtin-extensions/pi-subagents/src/tui/communication.js +3 -2
  23. package/dist/builtin-extensions/pi-subagents/src/tui/communication.js.map +1 -1
  24. package/dist/core/agent-session.d.ts +19 -0
  25. package/dist/core/agent-session.d.ts.map +1 -1
  26. package/dist/core/agent-session.js +230 -103
  27. package/dist/core/agent-session.js.map +1 -1
  28. package/dist/core/settings-manager.d.ts +4 -0
  29. package/dist/core/settings-manager.d.ts.map +1 -1
  30. package/dist/core/settings-manager.js +9 -0
  31. package/dist/core/settings-manager.js.map +1 -1
  32. package/dist/core/subagent-wait-interruption.d.ts +11 -0
  33. package/dist/core/subagent-wait-interruption.d.ts.map +1 -0
  34. package/dist/core/subagent-wait-interruption.js +19 -0
  35. package/dist/core/subagent-wait-interruption.js.map +1 -0
  36. package/dist/core/system-prompt.d.ts.map +1 -1
  37. package/dist/core/system-prompt.js +3 -1
  38. package/dist/core/system-prompt.js.map +1 -1
  39. package/dist/core/tools/render-utils.d.ts +3 -3
  40. package/dist/core/tools/render-utils.d.ts.map +1 -1
  41. package/dist/core/tools/render-utils.js +3 -3
  42. package/dist/core/tools/render-utils.js.map +1 -1
  43. package/dist/modes/interactive/components/assistant-message.d.ts +10 -2
  44. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  45. package/dist/modes/interactive/components/assistant-message.js +29 -5
  46. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  47. package/dist/modes/interactive/components/copyable-text.d.ts +2 -6
  48. package/dist/modes/interactive/components/copyable-text.d.ts.map +1 -1
  49. package/dist/modes/interactive/components/copyable-text.js +26 -35
  50. package/dist/modes/interactive/components/copyable-text.js.map +1 -1
  51. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  52. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  53. package/dist/modes/interactive/components/settings-selector.js +13 -0
  54. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  55. package/dist/modes/interactive/components/thinking-tail.d.ts +9 -2
  56. package/dist/modes/interactive/components/thinking-tail.d.ts.map +1 -1
  57. package/dist/modes/interactive/components/thinking-tail.js +43 -1
  58. package/dist/modes/interactive/components/thinking-tail.js.map +1 -1
  59. package/dist/modes/interactive/components/tool-execution.d.ts +4 -3
  60. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  61. package/dist/modes/interactive/components/tool-execution.js +34 -45
  62. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  63. package/dist/modes/interactive/interactive-mode.d.ts +6 -0
  64. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  65. package/dist/modes/interactive/interactive-mode.js +118 -39
  66. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  67. package/dist/modes/interactive/theme/theme.d.ts +1 -0
  68. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  69. package/dist/modes/interactive/theme/theme.js +23 -0
  70. package/dist/modes/interactive/theme/theme.js.map +1 -1
  71. package/dist/node-runtime/{agent-session-services-NQ6GKOIK.js → agent-session-services-GZVSOGYR.js} +7 -7
  72. package/dist/node-runtime/{builtin-extensions-GVC6IFDU.js → builtin-extensions-QVCXNQT4.js} +3 -3
  73. package/dist/node-runtime/{chunk-6B2POMK7.js → chunk-6VYZ5UFP.js} +1 -1
  74. package/dist/node-runtime/{chunk-VJPTNWAP.js → chunk-DD5YWFSJ.js} +1 -1
  75. package/dist/node-runtime/{chunk-TDL7UWJ7.js → chunk-DQMGU675.js} +173 -57
  76. package/dist/node-runtime/{chunk-V2A7CEXK.js → chunk-EKVFP6YF.js} +2 -2
  77. package/dist/node-runtime/{chunk-5BNJ4JUH.js → chunk-GJ2RDBRL.js} +1 -1
  78. package/dist/node-runtime/{chunk-GNN7H3B7.js → chunk-GS42T6MX.js} +1 -1
  79. package/dist/node-runtime/{chunk-PC2Z5TKZ.js → chunk-HMBGROQK.js} +3 -3
  80. package/dist/node-runtime/{chunk-GJSAD4AB.js → chunk-HPUP7E4T.js} +10 -10
  81. package/dist/node-runtime/{chunk-IVXYUAJE.js → chunk-IF24A3FH.js} +1 -1
  82. package/dist/node-runtime/{chunk-BFNXONG3.js → chunk-LFZDVKSP.js} +2 -2
  83. package/dist/node-runtime/{chunk-EQ63ANHL.js → chunk-LLUIPGDR.js} +210 -125
  84. package/dist/node-runtime/{chunk-ORH324EP.js → chunk-PCEW76PM.js} +3 -3
  85. package/dist/node-runtime/{chunk-WADV2VDS.js → chunk-QAZOULTU.js} +7 -0
  86. package/dist/node-runtime/{chunk-6427XAWG.js → chunk-QH6YL7VK.js} +3 -3
  87. package/dist/node-runtime/{chunk-7QWNYZDI.js → chunk-RDDAZOMU.js} +16 -0
  88. package/dist/node-runtime/{chunk-QDGKKKUM.js → chunk-RIR5EDDJ.js} +1 -1
  89. package/dist/node-runtime/{chunk-H3XF4UVQ.js → chunk-RWTKOC3B.js} +1 -1
  90. package/dist/node-runtime/{chunk-IQIEU7SB.js → chunk-TVJUOJZJ.js} +2 -2
  91. package/dist/node-runtime/{chunk-UAFLNHSH.js → chunk-W64JC4E7.js} +8 -8
  92. package/dist/node-runtime/{chunk-LMBNLFXQ.js → chunk-X3URCYCU.js} +4 -4
  93. package/dist/node-runtime/{chunk-VSSXXL36.js → chunk-YDO2F2IA.js} +2 -2
  94. package/dist/node-runtime/{chunk-IWOWXRWU.js → chunk-YHQ3NBB3.js} +15 -15
  95. package/dist/node-runtime/cli-runtime.js +1 -1
  96. package/dist/node-runtime/{command-3JHHXOPX.js → command-PDVTBRWA.js} +3 -3
  97. package/dist/node-runtime/{commands-2JVNFGMQ.js → commands-XDCFGIGW.js} +5 -5
  98. package/dist/node-runtime/{export-html-KBFVV63J.js → export-html-KSOIMVPI.js} +1 -1
  99. package/dist/node-runtime/{extension-input-K24TVKVW.js → extension-input-E7BJZ35H.js} +4 -4
  100. package/dist/node-runtime/{extension-selector-SPNF7EDR.js → extension-selector-WU42XDTU.js} +4 -4
  101. package/dist/node-runtime/{gateway-VFO6SFKK.js → gateway-AYWM5DIO.js} +7 -7
  102. package/dist/node-runtime/index.js +17 -17
  103. package/dist/node-runtime/{install-cli-C3CF7O7N.js → install-cli-3BO4MMQ6.js} +1 -1
  104. package/dist/node-runtime/{interactive-mode-LOM6AIF6.js → interactive-mode-4MFRKAHG.js} +13 -13
  105. package/dist/node-runtime/{interactive-view-IDSCPPK7.js → interactive-view-TUZHCQM3.js} +5 -5
  106. package/dist/node-runtime/{lunr-browser-YNW7FTYX.js → lunr-browser-RYFIIVJN.js} +91 -4
  107. package/dist/node-runtime/{lunr-cron-BKHGNBKT.js → lunr-cron-YWXEPZMQ.js} +4 -4
  108. package/dist/node-runtime/main.js +14 -14
  109. package/dist/node-runtime/{mobile-commands-HMP25WBC.js → mobile-commands-LVHDAUDP.js} +4 -4
  110. package/dist/node-runtime/{package-manager-cli-VCK4E2RC.js → package-manager-cli-6GT3Z3CK.js} +9 -9
  111. package/dist/node-runtime/{pi-subagents-FEUDLJOE.js → pi-subagents-CDWK2AKY.js} +44 -10
  112. package/dist/node-runtime/rpc-entry.js +14 -14
  113. package/dist/node-runtime/{rpc-mode-P5ODXPEG.js → rpc-mode-O3XV4SID.js} +2 -2
  114. package/dist/node-runtime/{session-selector-LHRMJOKT.js → session-selector-GIM4DHQ2.js} +4 -4
  115. package/dist/node-runtime/{settings-manager-UUZ6NUXI.js → settings-manager-6VEMXRDL.js} +1 -1
  116. package/dist/node-runtime/{setup-NRXVZBLJ.js → setup-5SR2J35A.js} +1 -1
  117. package/dist/node-runtime/{subagent-executor-MLUMBWCP.js → subagent-executor-M5VWB3D3.js} +8 -4
  118. package/dist/node-runtime/{theme-U7IGOA7O.js → theme-UOO5RVFN.js} +1 -1
  119. package/dist/node-runtime/{update-cli-4TP25CNW.js → update-cli-UVKJWRRJ.js} +1 -1
  120. package/docs/features.md +2 -0
  121. package/docs/settings.md +1 -0
  122. package/docs/usage.md +2 -2
  123. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  124. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  125. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  126. package/examples/extensions/gondolin/package-lock.json +2 -2
  127. package/examples/extensions/gondolin/package.json +1 -1
  128. package/examples/extensions/sandbox/package-lock.json +2 -2
  129. package/examples/extensions/sandbox/package.json +1 -1
  130. package/examples/extensions/with-deps/package-lock.json +2 -2
  131. package/examples/extensions/with-deps/package.json +1 -1
  132. package/package.json +4 -4
@@ -52,7 +52,7 @@ Behavior guidelines:
52
52
  - When several agents work in parallel, state file ownership up front so they do not collide.
53
53
  - Tests are good! Endless smoke tests, regressions tests for feature deletions, etc, much less good. Tests should be focused, not slop.
54
54
  - Prefer editing existing files to creating new ones.
55
- - When a reusable excerpt, prompt, or code fragment should have its own Copy button, wrap only that payload in a fenced Markdown block with the info string \`lunr-copy\`. Keep explanation outside the block. Use a longer backtick or tilde fence when the payload contains fenced code.
55
+ - When a reusable excerpt, prompt, or code fragment should be click-to-copy, wrap only that payload in a fenced Markdown block with the info string \`lunr-copy\`. Keep explanation outside the block. Use a longer backtick or tilde fence when the payload contains fenced code.
56
56
  - Only use emojis if the user explicitly requests it.
57
57
  - Never exfil private data on public platforms like github or any other services under any circumstances.
58
58
 
@@ -66,8 +66,10 @@ Guidelines:
66
66
  - Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.
67
67
  - Use write only for new files or complete rewrites.
68
68
  ${todoGuideline}- Use subagents for independent parallel work, specialist analysis, or substantial research. Subagents start with fresh sessions. Use intercom instead to coordinate with an existing lunR session.
69
+ - Resume a subagent only when its work is unfinished or the next task genuinely needs the context it built up. Otherwise launch a new subagent.
69
70
  - Use ast_search for structural code matches.
70
71
  - Use cron only when the user asks to schedule or manage unattended prompts.
72
+ - For gateway work, inspect with \`lunr gateway status\` or \`lunr gateway doctor\`, configure with \`lunr gateway setup\`, and run \`lunr gateway start\` or \`lunr gateway stop\` only with user approval. Test by asking the user to send \`/whoami\` or a normal message to the bot; there is no arbitrary outbound send command. Keep bot tokens out of commands and output. See ${docsPath}/features.md for pairing, logs, and service details.
71
73
  - Memory stores established, durable facts and stable preferences. Do not store behavior instructions, transient task details, transcripts, guesses, or secrets. Change memory only with the memory tools.
72
74
  - ~/.lunr/agent/agents/ contains optional global and per-model AGENTS.md instructions written by the user. Never modify this tree, including through shell commands.
73
75
  - Use web search when information is current, uncertain, externally referenced, or research-heavy, and cite the sources used.
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAuBhE,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,OAAiC,EAAU;IAC5E,MAAM,EACL,YAAY,EACZ,SAAS,EACT,aAAa,EACb,kBAAkB,EAClB,GAAG,EACH,YAAY,EAAE,oBAAoB,EAClC,MAAM,EAAE,cAAc,GACtB,GAAG,OAAO,CAAC;IACZ,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE1C,MAAM,aAAa,GAAG,kBAAkB,CAAC,CAAC,CAAC,OAAO,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE5E,MAAM,YAAY,GAAG,oBAAoB,IAAI,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,cAAc,IAAI,EAAE,CAAC;IAEpC,IAAI,YAAY,EAAE,CAAC;QAClB,IAAI,MAAM,GAAG,YAAY,CAAC;QAE1B,IAAI,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,aAAa,CAAC;QACzB,CAAC;QAED,+BAA+B;QAC/B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,2BAA2B,CAAC;YACtC,MAAM,IAAI,mDAAmD,CAAC;YAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;gBACxD,MAAM,IAAI,+BAA+B,QAAQ,OAAO,OAAO,+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AO,EAAE,IAAI,YAAY,EAAE,CAAC;YACxD,MAAM,IAAI,+BAA+B,QAAQ,OAAO,OAAO,+BAA+B,CAAC;QAChG,CAAC;QACD,MAAM,IAAI,sBAAsB,CAAC;IAClC,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Current model in provider/id form. */\n\tmodelSlug?: string;\n\t/** Active tools; used to decide whether read-dependent skill metadata is visible. */\n\tselectedTools?: string[];\n\t/** Legacy extension metadata retained for API compatibility; tool definitions are sent separately. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Legacy extension metadata retained for API compatibility; not appended to the default prompt. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the base system prompt and append configured context. */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tmodelSlug,\n\t\tselectedTools,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst promptCwd = cwd.replace(/\\\\/g, \"/\");\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n<project_context>\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `<project_instructions path=\"${filePath}\">\\n${content}\\n</project_instructions>\\n\\n`;\n\t\t\t}\n\t\t\tprompt += \"</project_context>\\n\";\n\t\t}\n\n\t\t// Append skills section (only if read tool is available)\n\t\tconst customPromptHasRead = !selectedTools || selectedTools.includes(\"read\");\n\t\tif (customPromptHasRead && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\tconst currentModel = modelSlug?.trim() || \"no model selected\";\n\tconst hasRead = !selectedTools || selectedTools.includes(\"read\");\n\tconst todoGuideline =\n\t\t!selectedTools || selectedTools.includes(\"todo\")\n\t\t\t? \"- Use todo for meaningful multi-step work. Every update must send the complete list, with exactly one item in progress at a time.\\n\"\n\t\t\t: \"\";\n\n\tlet prompt = `You are an expert coding assistant currently running ''${currentModel}'', operating inside lunR, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\nCurrent working directory: ''${promptCwd}''\n\nBehavior guidelines:\n- Default to writing no comments. Only add one if the why is non-obvious: a hidden constraint, a subtle invariant, a workaround for a specific bug, something that would surprise the reader. If removing the comment wouldn't confuse a future reader, don't write it.\n- Keep comments up to date! When making changes, it's important to keep things in sync. An outdated comment is worse than no comment at all.\n- Carefully consider the reversibility and blast radius of actions. Generally you can freely take local, reversible actions like editing files or running tests. But for actions that are hard to reverse, affect shared systems beyond your local environment, or could otherwise be risky or destructive, check with the user before proceeding.\n- Orchestrate subagents with intent! Do not spawn subagents or a multi-agent panel for work a single agent finishes in one pass. Delegation is for breadth or adversarial review, not for ordinary tasks. Use subagents as a tool when there is genuine benefit to it or the user explicitly asks for it.\n- When several agents work in parallel, state file ownership up front so they do not collide.\n- Tests are good! Endless smoke tests, regressions tests for feature deletions, etc, much less good. Tests should be focused, not slop.\n- Prefer editing existing files to creating new ones.\n- When a reusable excerpt, prompt, or code fragment should have its own Copy button, wrap only that payload in a fenced Markdown block with the info string \\`lunr-copy\\`. Keep explanation outside the block. Use a longer backtick or tilde fence when the payload contains fenced code.\n- Only use emojis if the user explicitly requests it.\n- Never exfil private data on public platforms like github or any other services under any circumstances.\n\n\nGuidelines:\n- Use bash for file operations like ls, rg, find\n- Use read to examine files instead of cat or sed.\n- Use edit for precise changes (edits[].oldText must match exactly)\n- When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\n- Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\n- Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\n- Use write only for new files or complete rewrites.\n${todoGuideline}- Use subagents for independent parallel work, specialist analysis, or substantial research. Subagents start with fresh sessions. Use intercom instead to coordinate with an existing lunR session.\n- Use ast_search for structural code matches.\n- Use cron only when the user asks to schedule or manage unattended prompts.\n- Memory stores established, durable facts and stable preferences. Do not store behavior instructions, transient task details, transcripts, guesses, or secrets. Change memory only with the memory tools.\n- ~/.lunr/agent/agents/ contains optional global and per-model AGENTS.md instructions written by the user. Never modify this tree, including through shell commands.\n- Use web search when information is current, uncertain, externally referenced, or research-heavy, and cite the sources used.\n- Use MCP only for capabilities exposed by configured MCP servers. Call native lunR tools directly.\n\n\nlunR documentation (read only when the user asks about lunR itself, or the task concerns lunR itself, its SDK, extensions, themes, skills, or TUI):\n- README: ${readmePath}\n- Documentation: ${docsPath}\n- Examples: ${examplesPath}\n- Always read lunR .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n<project_context>\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `<project_instructions path=\"${filePath}\">\\n${content}\\n</project_instructions>\\n\\n`;\n\t\t}\n\t\tprompt += \"</project_context>\\n\";\n\t}\n\n\t// Append skills section (only if read tool is available)\n\tif (hasRead && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\treturn prompt;\n}\n"]}
1
+ {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAuBhE,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,OAAiC,EAAU;IAC5E,MAAM,EACL,YAAY,EACZ,SAAS,EACT,aAAa,EACb,kBAAkB,EAClB,GAAG,EACH,YAAY,EAAE,oBAAoB,EAClC,MAAM,EAAE,cAAc,GACtB,GAAG,OAAO,CAAC;IACZ,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE1C,MAAM,aAAa,GAAG,kBAAkB,CAAC,CAAC,CAAC,OAAO,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE5E,MAAM,YAAY,GAAG,oBAAoB,IAAI,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,cAAc,IAAI,EAAE,CAAC;IAEpC,IAAI,YAAY,EAAE,CAAC;QAClB,IAAI,MAAM,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;;;;;;;;;;;;;;;;;;;;;EAuBtC,aAAa;;;;wXAIyW,QAAQ;;;;;;;;YAQpX,UAAU;mBACH,QAAQ;cACb,YAAY;4GACkF,CAAC;IAE5G,IAAI,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,aAAa,CAAC;IACzB,CAAC;IAED,+BAA+B;IAC/B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,2BAA2B,CAAC;QACtC,MAAM,IAAI,mDAAmD,CAAC;QAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACxD,MAAM,IAAI,+BAA+B,QAAQ,OAAO,OAAO,+BAA+B,CAAC;QAChG,CAAC;QACD,MAAM,IAAI,sBAAsB,CAAC;IAClC,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Current model in provider/id form. */\n\tmodelSlug?: string;\n\t/** Active tools; used to decide whether read-dependent skill metadata is visible. */\n\tselectedTools?: string[];\n\t/** Legacy extension metadata retained for API compatibility; tool definitions are sent separately. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Legacy extension metadata retained for API compatibility; not appended to the default prompt. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the base system prompt and append configured context. */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tmodelSlug,\n\t\tselectedTools,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst promptCwd = cwd.replace(/\\\\/g, \"/\");\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n<project_context>\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `<project_instructions path=\"${filePath}\">\\n${content}\\n</project_instructions>\\n\\n`;\n\t\t\t}\n\t\t\tprompt += \"</project_context>\\n\";\n\t\t}\n\n\t\t// Append skills section (only if read tool is available)\n\t\tconst customPromptHasRead = !selectedTools || selectedTools.includes(\"read\");\n\t\tif (customPromptHasRead && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\tconst currentModel = modelSlug?.trim() || \"no model selected\";\n\tconst hasRead = !selectedTools || selectedTools.includes(\"read\");\n\tconst todoGuideline =\n\t\t!selectedTools || selectedTools.includes(\"todo\")\n\t\t\t? \"- Use todo for meaningful multi-step work. Every update must send the complete list, with exactly one item in progress at a time.\\n\"\n\t\t\t: \"\";\n\n\tlet prompt = `You are an expert coding assistant currently running ''${currentModel}'', operating inside lunR, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\nCurrent working directory: ''${promptCwd}''\n\nBehavior guidelines:\n- Default to writing no comments. Only add one if the why is non-obvious: a hidden constraint, a subtle invariant, a workaround for a specific bug, something that would surprise the reader. If removing the comment wouldn't confuse a future reader, don't write it.\n- Keep comments up to date! When making changes, it's important to keep things in sync. An outdated comment is worse than no comment at all.\n- Carefully consider the reversibility and blast radius of actions. Generally you can freely take local, reversible actions like editing files or running tests. But for actions that are hard to reverse, affect shared systems beyond your local environment, or could otherwise be risky or destructive, check with the user before proceeding.\n- Orchestrate subagents with intent! Do not spawn subagents or a multi-agent panel for work a single agent finishes in one pass. Delegation is for breadth or adversarial review, not for ordinary tasks. Use subagents as a tool when there is genuine benefit to it or the user explicitly asks for it.\n- When several agents work in parallel, state file ownership up front so they do not collide.\n- Tests are good! Endless smoke tests, regressions tests for feature deletions, etc, much less good. Tests should be focused, not slop.\n- Prefer editing existing files to creating new ones.\n- When a reusable excerpt, prompt, or code fragment should be click-to-copy, wrap only that payload in a fenced Markdown block with the info string \\`lunr-copy\\`. Keep explanation outside the block. Use a longer backtick or tilde fence when the payload contains fenced code.\n- Only use emojis if the user explicitly requests it.\n- Never exfil private data on public platforms like github or any other services under any circumstances.\n\n\nGuidelines:\n- Use bash for file operations like ls, rg, find\n- Use read to examine files instead of cat or sed.\n- Use edit for precise changes (edits[].oldText must match exactly)\n- When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\n- Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\n- Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\n- Use write only for new files or complete rewrites.\n${todoGuideline}- Use subagents for independent parallel work, specialist analysis, or substantial research. Subagents start with fresh sessions. Use intercom instead to coordinate with an existing lunR session.\n- Resume a subagent only when its work is unfinished or the next task genuinely needs the context it built up. Otherwise launch a new subagent.\n- Use ast_search for structural code matches.\n- Use cron only when the user asks to schedule or manage unattended prompts.\n- For gateway work, inspect with \\`lunr gateway status\\` or \\`lunr gateway doctor\\`, configure with \\`lunr gateway setup\\`, and run \\`lunr gateway start\\` or \\`lunr gateway stop\\` only with user approval. Test by asking the user to send \\`/whoami\\` or a normal message to the bot; there is no arbitrary outbound send command. Keep bot tokens out of commands and output. See ${docsPath}/features.md for pairing, logs, and service details.\n- Memory stores established, durable facts and stable preferences. Do not store behavior instructions, transient task details, transcripts, guesses, or secrets. Change memory only with the memory tools.\n- ~/.lunr/agent/agents/ contains optional global and per-model AGENTS.md instructions written by the user. Never modify this tree, including through shell commands.\n- Use web search when information is current, uncertain, externally referenced, or research-heavy, and cite the sources used.\n- Use MCP only for capabilities exposed by configured MCP servers. Call native lunR tools directly.\n\n\nlunR documentation (read only when the user asks about lunR itself, or the task concerns lunR itself, its SDK, extensions, themes, skills, or TUI):\n- README: ${readmePath}\n- Documentation: ${docsPath}\n- Examples: ${examplesPath}\n- Always read lunR .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n<project_context>\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `<project_instructions path=\"${filePath}\">\\n${content}\\n</project_instructions>\\n\\n`;\n\t\t}\n\t\tprompt += \"</project_context>\\n\";\n\t}\n\n\t// Append skills section (only if read tool is available)\n\tif (hasRead && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\treturn prompt;\n}\n"]}
@@ -34,9 +34,9 @@ export declare function toolGroupRole(continuation: boolean, followed: boolean):
34
34
  * ```
35
35
  *
36
36
  * Singletons and expanded rows keep `● title detail` on one line.
37
- * Collapsed errors stay in the same-name tree; the error body is hoisted
38
- * under the last leaf so it does not split the file list. Grouped still-running
39
- * cards share the same tree as finished ones. `compact` is header-only body
37
+ * Collapsed errors stay in the same-name tree with a red status dot; details
38
+ * remain available on expansion. Grouped still-running cards share the same
39
+ * tree as finished ones. `compact` is header-only body
40
40
  * hiding at the caller; pass `tree` for chrome. `isError` is accepted so
41
41
  * callers can keep passing it, but it does not drop tree chrome.
42
42
  */
@@ -1 +1 @@
1
- {"version":3,"file":"render-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAKN,IAAI,EAGJ,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAIpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAOjD;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjF;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,aAAa,CAC5B,MAAM,EAAE;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,GA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B,CAAC,IAAI,EAAE,kBAAkB,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAmBlF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAE7E;AAED,wGAAoG;AACpG,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAEhH;AAED,wBAAgB,cAAc,CAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAClC,MAAM,CAKR;AAED,2FAA2F;AAC3F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAK5F;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK/G","sourcesContent":["import * as os from \"node:os\";\nimport { basename } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"@ashx-j/lunr-ai\";\nimport {\n\tgetCapabilities,\n\tgetImageDimensions,\n\thyperlink,\n\timageFallback,\n\tText,\n\ttruncateToWidth,\n\twrapTextWithAnsi,\n} from \"@ashx-j/lunr-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport type { ToolGroupRole } from \"../extensions/types.ts\";\n\nexport function 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\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\n// lunr: compact-by-default — tool execute() paths append truncation/limit notices\n// as a trailing \"\\n\\n[...]\" block. Compact (header-only) results blank the body,\n// so this extracts that notice to keep it visible without the full output.\nexport function extractTrailingNotice(text: string): string | undefined {\n\tconst trimmed = text.trimEnd();\n\tif (!trimmed.endsWith(\"]\")) return undefined;\n\tconst start = trimmed.lastIndexOf(\"\\n\\n[\");\n\tif (start === -1) return undefined;\n\treturn trimmed.slice(start + 2);\n}\n\nexport type ToolStatusDotState = \"pending\" | \"success\" | \"error\";\n\nexport type { ToolGroupRole };\n\nexport function toolGroupRole(continuation: boolean, followed: boolean): ToolGroupRole {\n\tif (!continuation && followed) return \"first\";\n\tif (continuation && followed) return \"middle\";\n\tif (continuation && !followed) return \"last\";\n\treturn \"singleton\";\n}\n\n/**\n * Quieter same-name chrome: the verb is printed once, then files hang off a tree.\n *\n * ```\n * ● read\n * ├─ resolve.ts\n * └─ usage-service.ts\n * ```\n *\n * Singletons and expanded rows keep `● title detail` on one line.\n * Collapsed errors stay in the same-name tree; the error body is hoisted\n * under the last leaf so it does not split the file list. Grouped still-running\n * cards share the same tree as finished ones. `compact` is header-only body\n * hiding at the caller; pass `tree` for chrome. `isError` is accepted so\n * callers can keep passing it, but it does not drop tree chrome.\n */\nexport function toolGroupTree(context: { expanded?: boolean; isError?: boolean }): boolean {\n\treturn !context.expanded;\n}\n\ninterface GroupedCallOptions {\n\trole: ToolGroupRole;\n\tcompact?: boolean;\n\ttree?: boolean;\n\tdot: string;\n\ttitle: string;\n\tdetail?: string;\n}\n\nexport class GroupedCallText extends Text {\n\tprivate call?: GroupedCallOptions;\n\tprivate formattedWidth?: number;\n\n\tsetCall(call: GroupedCallOptions): void {\n\t\tthis.setText(formatGroupedCall(call));\n\t\tthis.call = call;\n\t}\n\n\toverride setText(text: string): void {\n\t\tthis.call = undefined;\n\t\tthis.formattedWidth = undefined;\n\t\tsuper.setText(text);\n\t}\n\n\toverride render(width: number): string[] {\n\t\tif (this.call && this.formattedWidth !== width) {\n\t\t\tsuper.setText(formatGroupedCall(this.call, width));\n\t\t\tthis.formattedWidth = width;\n\t\t}\n\t\treturn super.render(width);\n\t}\n}\n\nexport function formatGroupedCall(opts: GroupedCallOptions, width?: number): string {\n\tconst detail = opts.detail?.trim() ? opts.detail : \"\";\n\tconst useTree = (opts.tree ?? opts.compact === true) && opts.role !== \"singleton\" && detail.length > 0;\n\tif (!useTree) {\n\t\treturn detail ? `${opts.dot} ${opts.title} ${detail}` : `${opts.dot} ${opts.title}`;\n\t}\n\tconst branch = opts.role === \"last\" ? \"└─\" : \"├─\";\n\tconst prefix = ` ${branch} `;\n\tconst continuation = opts.role === \"last\" ? \" \" : \" │ \";\n\tconst leaf =\n\t\twidth === undefined\n\t\t\t? `${prefix}${detail}`\n\t\t\t: wrapTextWithAnsi(replaceTabs(detail), Math.max(1, width - prefix.length))\n\t\t\t\t\t.map((line, index) => truncateToWidth(`${index === 0 ? prefix : continuation}${line}`, width, \"\"))\n\t\t\t\t\t.join(\"\\n\");\n\tif (opts.role === \"first\") {\n\t\treturn `${opts.dot} ${opts.title}\\n${leaf}`;\n\t}\n\treturn leaf;\n}\n\n/**\n * Colored status dot used as the sole state indicator on tool titles (moon theme:\n * backgrounds stay neutral). Pending = muted, success = green, error = red.\n */\nexport function toolStatusDot(state: ToolStatusDotState, theme: Theme): string {\n\treturn theme.fg(state === \"pending\" ? \"muted\" : state, \"●\");\n}\n\n/** Derive the status dot from a render context (partial → pending, error → error, else success). */\nexport function toolStatusDotFromContext(context: { isPartial: boolean; isError: boolean }, theme: Theme): string {\n\treturn toolStatusDot(context.isPartial ? \"pending\" : context.isError ? \"error\" : \"success\", theme);\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n\n/** Basename-only path for compact tool headers. Still hyperlinked to the absolute file. */\nexport function renderToolFileName(rawPath: string | null, theme: Theme, cwd: string): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tif (!rawPath) return theme.fg(\"toolOutput\", \"...\");\n\tconst name = basename(rawPath) || rawPath;\n\treturn linkPath(theme.fg(\"accent\", name), rawPath, cwd);\n}\n\n/**\n * Collapsed grep/find path. Omits cwd (`.` / empty) so the header stays one line.\n * Other paths are basename-only and hyperlinked.\n */\nexport function renderCollapsedSearchPath(rawPath: string | null, theme: Theme, cwd: string): string | undefined {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath.trim();\n\tif (!value || value === \".\" || value === \"./\") return undefined;\n\treturn renderToolFileName(value, theme, cwd);\n}\n"]}
1
+ {"version":3,"file":"render-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAKN,IAAI,EAGJ,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAIpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAOjD;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjF;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wB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O,CAAC,cAAc,CAAC,CAAS;IAEhC,OAAO,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAGtC;IAEQ,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAInC;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAMvC;CACD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAmBlF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAE7E;AAED,wGAAoG;AACpG,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAEhH;AAED,wBAAgB,cAAc,CAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAClC,MAAM,CAKR;AAED,2FAA2F;AAC3F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAK5F;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK/G","sourcesContent":["import * as os from \"node:os\";\nimport { basename } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"@ashx-j/lunr-ai\";\nimport {\n\tgetCapabilities,\n\tgetImageDimensions,\n\thyperlink,\n\timageFallback,\n\tText,\n\ttruncateToWidth,\n\twrapTextWithAnsi,\n} from \"@ashx-j/lunr-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport type { ToolGroupRole } from \"../extensions/types.ts\";\n\nexport function 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\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\n// lunr: compact-by-default — tool execute() paths append truncation/limit notices\n// as a trailing \"\\n\\n[...]\" block. Compact (header-only) results blank the body,\n// so this extracts that notice to keep it visible without the full output.\nexport function extractTrailingNotice(text: string): string | undefined {\n\tconst trimmed = text.trimEnd();\n\tif (!trimmed.endsWith(\"]\")) return undefined;\n\tconst start = trimmed.lastIndexOf(\"\\n\\n[\");\n\tif (start === -1) return undefined;\n\treturn trimmed.slice(start + 2);\n}\n\nexport type ToolStatusDotState = \"pending\" | \"success\" | \"error\";\n\nexport type { ToolGroupRole };\n\nexport function toolGroupRole(continuation: boolean, followed: boolean): ToolGroupRole {\n\tif (!continuation && followed) return \"first\";\n\tif (continuation && followed) return \"middle\";\n\tif (continuation && !followed) return \"last\";\n\treturn \"singleton\";\n}\n\n/**\n * Quieter same-name chrome: the verb is printed once, then files hang off a tree.\n *\n * ```\n * ● read\n * ├─ resolve.ts\n * └─ usage-service.ts\n * ```\n *\n * Singletons and expanded rows keep `● title detail` on one line.\n * Collapsed errors stay in the same-name tree with a red status dot; details\n * remain available on expansion. Grouped still-running cards share the same\n * tree as finished ones. `compact` is header-only body\n * hiding at the caller; pass `tree` for chrome. `isError` is accepted so\n * callers can keep passing it, but it does not drop tree chrome.\n */\nexport function toolGroupTree(context: { expanded?: boolean; isError?: boolean }): boolean {\n\treturn !context.expanded;\n}\n\ninterface GroupedCallOptions {\n\trole: ToolGroupRole;\n\tcompact?: boolean;\n\ttree?: boolean;\n\tdot: string;\n\ttitle: string;\n\tdetail?: string;\n}\n\nexport class GroupedCallText extends Text {\n\tprivate call?: GroupedCallOptions;\n\tprivate formattedWidth?: number;\n\n\tsetCall(call: GroupedCallOptions): void {\n\t\tthis.setText(formatGroupedCall(call));\n\t\tthis.call = call;\n\t}\n\n\toverride setText(text: string): void {\n\t\tthis.call = undefined;\n\t\tthis.formattedWidth = undefined;\n\t\tsuper.setText(text);\n\t}\n\n\toverride render(width: number): string[] {\n\t\tif (this.call && this.formattedWidth !== width) {\n\t\t\tsuper.setText(formatGroupedCall(this.call, width));\n\t\t\tthis.formattedWidth = width;\n\t\t}\n\t\treturn super.render(width);\n\t}\n}\n\nexport function formatGroupedCall(opts: GroupedCallOptions, width?: number): string {\n\tconst detail = opts.detail?.trim() ? opts.detail : \"\";\n\tconst useTree = (opts.tree ?? opts.compact === true) && opts.role !== \"singleton\" && detail.length > 0;\n\tif (!useTree) {\n\t\treturn detail ? `${opts.dot} ${opts.title} ${detail}` : `${opts.dot} ${opts.title}`;\n\t}\n\tconst branch = opts.role === \"last\" ? \"└─\" : \"├─\";\n\tconst prefix = ` ${branch} `;\n\tconst continuation = opts.role === \"last\" ? \" \" : \" │ \";\n\tconst leaf =\n\t\twidth === undefined\n\t\t\t? `${prefix}${detail}`\n\t\t\t: wrapTextWithAnsi(replaceTabs(detail), Math.max(1, width - prefix.length))\n\t\t\t\t\t.map((line, index) => truncateToWidth(`${index === 0 ? prefix : continuation}${line}`, width, \"\"))\n\t\t\t\t\t.join(\"\\n\");\n\tif (opts.role === \"first\") {\n\t\treturn `${opts.dot} ${opts.title}\\n${leaf}`;\n\t}\n\treturn leaf;\n}\n\n/**\n * Colored status dot used as the sole state indicator on tool titles (moon theme:\n * backgrounds stay neutral). Pending = muted, success = green, error = red.\n */\nexport function toolStatusDot(state: ToolStatusDotState, theme: Theme): string {\n\treturn theme.fg(state === \"pending\" ? \"muted\" : state, \"●\");\n}\n\n/** Derive the status dot from a render context (partial → pending, error → error, else success). */\nexport function toolStatusDotFromContext(context: { isPartial: boolean; isError: boolean }, theme: Theme): string {\n\treturn toolStatusDot(context.isPartial ? \"pending\" : context.isError ? \"error\" : \"success\", theme);\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n\n/** Basename-only path for compact tool headers. Still hyperlinked to the absolute file. */\nexport function renderToolFileName(rawPath: string | null, theme: Theme, cwd: string): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tif (!rawPath) return theme.fg(\"toolOutput\", \"...\");\n\tconst name = basename(rawPath) || rawPath;\n\treturn linkPath(theme.fg(\"accent\", name), rawPath, cwd);\n}\n\n/**\n * Collapsed grep/find path. Omits cwd (`.` / empty) so the header stays one line.\n * Other paths are basename-only and hyperlinked.\n */\nexport function renderCollapsedSearchPath(rawPath: string | null, theme: Theme, cwd: string): string | undefined {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath.trim();\n\tif (!value || value === \".\" || value === \"./\") return undefined;\n\treturn renderToolFileName(value, theme, cwd);\n}\n"]}
@@ -86,9 +86,9 @@ export function toolGroupRole(continuation, followed) {
86
86
  * ```
87
87
  *
88
88
  * Singletons and expanded rows keep `● title detail` on one line.
89
- * Collapsed errors stay in the same-name tree; the error body is hoisted
90
- * under the last leaf so it does not split the file list. Grouped still-running
91
- * cards share the same tree as finished ones. `compact` is header-only body
89
+ * Collapsed errors stay in the same-name tree with a red status dot; details
90
+ * remain available on expansion. Grouped still-running cards share the same
91
+ * tree as finished ones. `compact` is header-only body
92
92
  * hiding at the caller; pass `tree` for chrome. `isError` is accepted so
93
93
  * callers can keep passing it, but it does not drop tree chrome.
94
94
  */
@@ -1 +1 @@
1
- {"version":3,"file":"render-utils.js","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAsB,EAAE,KAAY,EAAE,GAAW,EAAsB;IAChH,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAChE,OAAO,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AAAA,CAC7C","sourcesContent":["import * as os from \"node:os\";\nimport { basename } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"@ashx-j/lunr-ai\";\nimport {\n\tgetCapabilities,\n\tgetImageDimensions,\n\thyperlink,\n\timageFallback,\n\tText,\n\ttruncateToWidth,\n\twrapTextWithAnsi,\n} from \"@ashx-j/lunr-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport type { ToolGroupRole } from \"../extensions/types.ts\";\n\nexport function 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\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\n// lunr: compact-by-default — tool execute() paths append truncation/limit notices\n// as a trailing \"\\n\\n[...]\" block. Compact (header-only) results blank the body,\n// so this extracts that notice to keep it visible without the full output.\nexport function extractTrailingNotice(text: string): string | undefined {\n\tconst trimmed = text.trimEnd();\n\tif (!trimmed.endsWith(\"]\")) return undefined;\n\tconst start = trimmed.lastIndexOf(\"\\n\\n[\");\n\tif (start === -1) return undefined;\n\treturn trimmed.slice(start + 2);\n}\n\nexport type ToolStatusDotState = \"pending\" | \"success\" | \"error\";\n\nexport type { ToolGroupRole };\n\nexport function toolGroupRole(continuation: boolean, followed: boolean): ToolGroupRole {\n\tif (!continuation && followed) return \"first\";\n\tif (continuation && followed) return \"middle\";\n\tif (continuation && !followed) return \"last\";\n\treturn \"singleton\";\n}\n\n/**\n * Quieter same-name chrome: the verb is printed once, then files hang off a tree.\n *\n * ```\n * ● read\n * ├─ resolve.ts\n * └─ usage-service.ts\n * ```\n *\n * Singletons and expanded rows keep `● title detail` on one line.\n * Collapsed errors stay in the same-name tree; the error body is hoisted\n * under the last leaf so it does not split the file list. Grouped still-running\n * cards share the same tree as finished ones. `compact` is header-only body\n * hiding at the caller; pass `tree` for chrome. `isError` is accepted so\n * callers can keep passing it, but it does not drop tree chrome.\n */\nexport function toolGroupTree(context: { expanded?: boolean; isError?: boolean }): boolean {\n\treturn !context.expanded;\n}\n\ninterface GroupedCallOptions {\n\trole: ToolGroupRole;\n\tcompact?: boolean;\n\ttree?: boolean;\n\tdot: string;\n\ttitle: string;\n\tdetail?: string;\n}\n\nexport class GroupedCallText extends Text {\n\tprivate call?: GroupedCallOptions;\n\tprivate formattedWidth?: number;\n\n\tsetCall(call: GroupedCallOptions): void {\n\t\tthis.setText(formatGroupedCall(call));\n\t\tthis.call = call;\n\t}\n\n\toverride setText(text: string): void {\n\t\tthis.call = undefined;\n\t\tthis.formattedWidth = undefined;\n\t\tsuper.setText(text);\n\t}\n\n\toverride render(width: number): string[] {\n\t\tif (this.call && this.formattedWidth !== width) {\n\t\t\tsuper.setText(formatGroupedCall(this.call, width));\n\t\t\tthis.formattedWidth = width;\n\t\t}\n\t\treturn super.render(width);\n\t}\n}\n\nexport function formatGroupedCall(opts: GroupedCallOptions, width?: number): string {\n\tconst detail = opts.detail?.trim() ? opts.detail : \"\";\n\tconst useTree = (opts.tree ?? opts.compact === true) && opts.role !== \"singleton\" && detail.length > 0;\n\tif (!useTree) {\n\t\treturn detail ? `${opts.dot} ${opts.title} ${detail}` : `${opts.dot} ${opts.title}`;\n\t}\n\tconst branch = opts.role === \"last\" ? \"└─\" : \"├─\";\n\tconst prefix = ` ${branch} `;\n\tconst continuation = opts.role === \"last\" ? \" \" : \" │ \";\n\tconst leaf =\n\t\twidth === undefined\n\t\t\t? `${prefix}${detail}`\n\t\t\t: wrapTextWithAnsi(replaceTabs(detail), Math.max(1, width - prefix.length))\n\t\t\t\t\t.map((line, index) => truncateToWidth(`${index === 0 ? prefix : continuation}${line}`, width, \"\"))\n\t\t\t\t\t.join(\"\\n\");\n\tif (opts.role === \"first\") {\n\t\treturn `${opts.dot} ${opts.title}\\n${leaf}`;\n\t}\n\treturn leaf;\n}\n\n/**\n * Colored status dot used as the sole state indicator on tool titles (moon theme:\n * backgrounds stay neutral). Pending = muted, success = green, error = red.\n */\nexport function toolStatusDot(state: ToolStatusDotState, theme: Theme): string {\n\treturn theme.fg(state === \"pending\" ? \"muted\" : state, \"●\");\n}\n\n/** Derive the status dot from a render context (partial → pending, error → error, else success). */\nexport function toolStatusDotFromContext(context: { isPartial: boolean; isError: boolean }, theme: Theme): string {\n\treturn toolStatusDot(context.isPartial ? \"pending\" : context.isError ? \"error\" : \"success\", theme);\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n\n/** Basename-only path for compact tool headers. Still hyperlinked to the absolute file. */\nexport function renderToolFileName(rawPath: string | null, theme: Theme, cwd: string): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tif (!rawPath) return theme.fg(\"toolOutput\", \"...\");\n\tconst name = basename(rawPath) || rawPath;\n\treturn linkPath(theme.fg(\"accent\", name), rawPath, cwd);\n}\n\n/**\n * Collapsed grep/find path. Omits cwd (`.` / empty) so the header stays one line.\n * Other paths are basename-only and hyperlinked.\n */\nexport function renderCollapsedSearchPath(rawPath: string | null, theme: Theme, cwd: string): string | undefined {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath.trim();\n\tif (!value || value === \".\" || value === \"./\") return undefined;\n\treturn renderToolFileName(value, theme, cwd);\n}\n"]}
1
+ {"version":3,"file":"render-utils.js","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EACN,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,IAAI,EACJ,eAAe,EACf,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAG5D,MAAM,UAAU,WAAW,CAAC,IAAa,EAAU;IAClD,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ;AAED,MAAM,UAAU,QAAQ,CAAC,UAAkB,EAAE,OAAe,EAAE,GAAW,EAAU;IAClF,IAAI,CAAC,eAAe,EAAE,CAAC,UAAU;QAAE,OAAO,UAAU,CAAC;IACrD,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC/C,OAAO,SAAS,CAAC,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC;AAAA,CAC/D;AAED,MAA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AQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC;IAC1C,OAAO,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;AAAA,CACxD;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAsB,EAAE,KAAY,EAAE,GAAW,EAAsB;IAChH,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAChE,OAAO,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AAAA,CAC7C","sourcesContent":["import * as os from \"node:os\";\nimport { basename } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"@ashx-j/lunr-ai\";\nimport {\n\tgetCapabilities,\n\tgetImageDimensions,\n\thyperlink,\n\timageFallback,\n\tText,\n\ttruncateToWidth,\n\twrapTextWithAnsi,\n} from \"@ashx-j/lunr-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport type { ToolGroupRole } from \"../extensions/types.ts\";\n\nexport function 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\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\n// lunr: compact-by-default — tool execute() paths append truncation/limit notices\n// as a trailing \"\\n\\n[...]\" block. Compact (header-only) results blank the body,\n// so this extracts that notice to keep it visible without the full output.\nexport function extractTrailingNotice(text: string): string | undefined {\n\tconst trimmed = text.trimEnd();\n\tif (!trimmed.endsWith(\"]\")) return undefined;\n\tconst start = trimmed.lastIndexOf(\"\\n\\n[\");\n\tif (start === -1) return undefined;\n\treturn trimmed.slice(start + 2);\n}\n\nexport type ToolStatusDotState = \"pending\" | \"success\" | \"error\";\n\nexport type { ToolGroupRole };\n\nexport function toolGroupRole(continuation: boolean, followed: boolean): ToolGroupRole {\n\tif (!continuation && followed) return \"first\";\n\tif (continuation && followed) return \"middle\";\n\tif (continuation && !followed) return \"last\";\n\treturn \"singleton\";\n}\n\n/**\n * Quieter same-name chrome: the verb is printed once, then files hang off a tree.\n *\n * ```\n * ● read\n * ├─ resolve.ts\n * └─ usage-service.ts\n * ```\n *\n * Singletons and expanded rows keep `● title detail` on one line.\n * Collapsed errors stay in the same-name tree with a red status dot; details\n * remain available on expansion. Grouped still-running cards share the same\n * tree as finished ones. `compact` is header-only body\n * hiding at the caller; pass `tree` for chrome. `isError` is accepted so\n * callers can keep passing it, but it does not drop tree chrome.\n */\nexport function toolGroupTree(context: { expanded?: boolean; isError?: boolean }): boolean {\n\treturn !context.expanded;\n}\n\ninterface GroupedCallOptions {\n\trole: ToolGroupRole;\n\tcompact?: boolean;\n\ttree?: boolean;\n\tdot: string;\n\ttitle: string;\n\tdetail?: string;\n}\n\nexport class GroupedCallText extends Text {\n\tprivate call?: GroupedCallOptions;\n\tprivate formattedWidth?: number;\n\n\tsetCall(call: GroupedCallOptions): void {\n\t\tthis.setText(formatGroupedCall(call));\n\t\tthis.call = call;\n\t}\n\n\toverride setText(text: string): void {\n\t\tthis.call = undefined;\n\t\tthis.formattedWidth = undefined;\n\t\tsuper.setText(text);\n\t}\n\n\toverride render(width: number): string[] {\n\t\tif (this.call && this.formattedWidth !== width) {\n\t\t\tsuper.setText(formatGroupedCall(this.call, width));\n\t\t\tthis.formattedWidth = width;\n\t\t}\n\t\treturn super.render(width);\n\t}\n}\n\nexport function formatGroupedCall(opts: GroupedCallOptions, width?: number): string {\n\tconst detail = opts.detail?.trim() ? opts.detail : \"\";\n\tconst useTree = (opts.tree ?? opts.compact === true) && opts.role !== \"singleton\" && detail.length > 0;\n\tif (!useTree) {\n\t\treturn detail ? `${opts.dot} ${opts.title} ${detail}` : `${opts.dot} ${opts.title}`;\n\t}\n\tconst branch = opts.role === \"last\" ? \"└─\" : \"├─\";\n\tconst prefix = ` ${branch} `;\n\tconst continuation = opts.role === \"last\" ? \" \" : \" │ \";\n\tconst leaf =\n\t\twidth === undefined\n\t\t\t? `${prefix}${detail}`\n\t\t\t: wrapTextWithAnsi(replaceTabs(detail), Math.max(1, width - prefix.length))\n\t\t\t\t\t.map((line, index) => truncateToWidth(`${index === 0 ? prefix : continuation}${line}`, width, \"\"))\n\t\t\t\t\t.join(\"\\n\");\n\tif (opts.role === \"first\") {\n\t\treturn `${opts.dot} ${opts.title}\\n${leaf}`;\n\t}\n\treturn leaf;\n}\n\n/**\n * Colored status dot used as the sole state indicator on tool titles (moon theme:\n * backgrounds stay neutral). Pending = muted, success = green, error = red.\n */\nexport function toolStatusDot(state: ToolStatusDotState, theme: Theme): string {\n\treturn theme.fg(state === \"pending\" ? \"muted\" : state, \"●\");\n}\n\n/** Derive the status dot from a render context (partial → pending, error → error, else success). */\nexport function toolStatusDotFromContext(context: { isPartial: boolean; isError: boolean }, theme: Theme): string {\n\treturn toolStatusDot(context.isPartial ? \"pending\" : context.isError ? \"error\" : \"success\", theme);\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n\n/** Basename-only path for compact tool headers. Still hyperlinked to the absolute file. */\nexport function renderToolFileName(rawPath: string | null, theme: Theme, cwd: string): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tif (!rawPath) return theme.fg(\"toolOutput\", \"...\");\n\tconst name = basename(rawPath) || rawPath;\n\treturn linkPath(theme.fg(\"accent\", name), rawPath, cwd);\n}\n\n/**\n * Collapsed grep/find path. Omits cwd (`.` / empty) so the header stays one line.\n * Other paths are basename-only and hyperlinked.\n */\nexport function renderCollapsedSearchPath(rawPath: string | null, theme: Theme, cwd: string): string | undefined {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath.trim();\n\tif (!value || value === \".\" || value === \"./\") return undefined;\n\treturn renderToolFileName(value, theme, cwd);\n}\n"]}
@@ -1,9 +1,12 @@
1
1
  import type { AssistantMessage } from "@ashx-j/lunr-ai";
2
2
  import { Container, type MarkdownTheme } from "@ashx-j/lunr-tui";
3
+ import type { ReasoningDisplay } from "../../../core/settings-manager.ts";
3
4
  import { type ThinkingRunTiming } from "./thinking-summary.ts";
4
- export interface AssistantMessageCopyOptions {
5
+ export interface AssistantMessageOptions {
5
6
  copyText?: (text: string) => Promise<void>;
6
7
  requestRender?: () => void;
8
+ reasoningDisplay?: ReasoningDisplay;
9
+ onThinkingAnimationChange?: (active: boolean) => void;
7
10
  }
8
11
  /**
9
12
  * Component that renders a complete assistant message
@@ -25,8 +28,13 @@ export declare class AssistantMessageComponent extends Container {
25
28
  private readonly copyText;
26
29
  private readonly requestRender;
27
30
  private readonly copyStates;
28
- constructor(message?: AssistantMessage, hideThinkingBlock?: boolean, markdownTheme?: MarkdownTheme, hiddenThinkingLabel?: string, outputPad?: number, thinkingCollapse?: boolean, copyOptions?: AssistantMessageCopyOptions);
31
+ private reasoningDisplay;
32
+ private readonly onThinkingAnimationChange?;
33
+ private readonly thinkingAnimationStart;
34
+ private thinkingAnimationActive;
35
+ constructor(message?: AssistantMessage, hideThinkingBlock?: boolean, markdownTheme?: MarkdownTheme, hiddenThinkingLabel?: string, outputPad?: number, thinkingCollapse?: boolean, options?: AssistantMessageOptions);
29
36
  invalidate(): void;
37
+ setReasoningDisplay(display: ReasoningDisplay): void;
30
38
  setHideThinkingBlock(hide: boolean): void;
31
39
  setThinkingCollapse(collapse: boolean): void;
32
40
  setExpanded(expanded: boolean): void;
@@ -1 +1 @@
1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IAEQ,UAAU,IAAI,IAAI,CAK1B;IAED,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAKxC;IAGD,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAK3C;IAGD,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAMnC;IAED,OAAO,CAAC,aAAa;IAIrB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAgBxC;IAED,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAcnE;IAED,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,SAAS,GAAG,IAAI,CAEjE;IAED,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK1C;IAED,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAKlC;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAQvC;IAED,OAAO,CAAC,qBAAqB;IAI7B,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,gBAAgB,CAAA;KAAE,GAAG,IAAI,CAgH9F;IAED,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,iBAAiB;IAKzB,OAAO,CAAC,iBAAiB;CAgEzB","sourcesContent":["import type { AssistantMessage } from \"@ashx-j/lunr-ai\";\nimport { type Component, Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@ashx-j/lunr-tui\";\nimport { copyToClipboard } from \"../../../utils/clipboard.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { CopyableTextBlockComponent, type CopyableTextStatus, parseCopyableTextSegments } from \"./copyable-text.ts\";\nimport {\n\tformatThoughtDuration,\n\tisThinkingRunComplete,\n\ttype ThinkingRunTiming,\n\tthinkingSnippet,\n} from \"./thinking-summary.ts\";\nimport { ThinkingTailComponent } from \"./thinking-tail.ts\";\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\nexport interface AssistantMessageCopyOptions {\n\tcopyText?: (text: string) => Promise<void>;\n\trequestRender?: () => void;\n}\n\ninterface CopyState {\n\tpayload: string;\n\tstatus: CopyableTextStatus;\n}\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tselectable = true;\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\t// lunr: collapsible reasoning — when true, a completed thinking run renders as\n\t// \"✻ Thought for Xs\" + its first sentence instead of the full block.\n\tprivate thinkingCollapse: boolean;\n\t// lunr: per-run expand. `expanded` still means \"all runs\" for setExpanded().\n\tprivate expanded = false;\n\tprivate expandedRuns = new Set<number>();\n\t// lunr: live per-run timings from interactive-mode; undefined = history message\n\t// (always treated as final, rendered without durations).\n\tprivate thinkingTimings?: ThinkingRunTiming[];\n\tprivate markdownTheme: MarkdownTheme;\n\t// lunr: kept for the deferred alternative hidden-thinking indicator (Phase 8 removed the label render).\n\t// biome-ignore lint/correctness/noUnusedPrivateClassMembers: retained for future use\n\tprivate hiddenThinkingLabel: string;\n\tprivate outputPad: number;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate thinkingSource?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\tprivate readonly copyText: (text: string) => Promise<void>;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly copyStates = new Map<string, CopyState>();\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t\toutputPad = 1,\n\t\tthinkingCollapse = false,\n\t\tcopyOptions: AssistantMessageCopyOptions = {},\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.thinkingCollapse = thinkingCollapse;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\t\tthis.outputPad = outputPad;\n\t\tthis.copyText = copyOptions.copyText ?? copyToClipboard;\n\t\tthis.requestRender = copyOptions.requestRender ?? (() => {});\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\t// lunr: collapsible reasoning toggles (live; re-render like setHideThinkingBlock).\n\tsetThinkingCollapse(collapse: boolean): void {\n\t\tthis.thinkingCollapse = collapse;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\t// lunr: Expandable hook; true expands every thinking run, false collapses all.\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tif (!expanded) this.expandedRuns.clear();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tprivate isRunExpanded(runIndex: number): boolean {\n\t\treturn this.expanded || this.expandedRuns.has(runIndex);\n\t}\n\n\ttoggleThinkingRun(runIndex: number): void {\n\t\tif (this.expanded) {\n\t\t\tthis.expanded = false;\n\t\t\tthis.expandedRuns.clear();\n\t\t\tconst count = this.lastMessage ? collectThinkingRuns(this.lastMessage.content).length : 0;\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\tif (i !== runIndex) this.expandedRuns.add(i);\n\t\t\t}\n\t\t} else if (this.expandedRuns.has(runIndex)) {\n\t\t\tthis.expandedRuns.delete(runIndex);\n\t\t} else {\n\t\t\tthis.expandedRuns.add(runIndex);\n\t\t}\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\thandleClick(localY: number, width: number, localX?: number): boolean {\n\t\tconst contentWidth = width;\n\t\tlet y = 0;\n\t\tfor (const child of this.contentContainer.children) {\n\t\t\tconst h = child.render(contentWidth).length;\n\t\t\tif (localY >= y && localY < y + h) {\n\t\t\t\tif (typeof child.handleClick === \"function\") {\n\t\t\t\t\treturn child.handleClick(localY - y, contentWidth, localX);\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\ty += h;\n\t\t}\n\t\treturn false;\n\t}\n\n\tsetThinkingTimings(timings: ThinkingRunTiming[] | undefined): void {\n\t\tthis.thinkingTimings = timings;\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tsetOutputPad(padding: number): void {\n\t\tthis.outputPad = padding;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) return lines;\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\n\t\treturn lines;\n\t}\n\n\tprivate thinkingSourceOptions(): { thinkingSource?: AssistantMessage } | undefined {\n\t\treturn this.thinkingSource ? { thinkingSource: this.thinkingSource } : undefined;\n\t}\n\n\tupdateContent(message: AssistantMessage, options?: { thinkingSource?: AssistantMessage }): void {\n\t\tthis.lastMessage = message;\n\t\tthis.thinkingSource = options?.thinkingSource;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst sourceMessage = this.thinkingSource ?? message;\n\t\tconst sourceThinkingRuns = collectThinkingRuns(sourceMessage.content);\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) =>\n\t\t\t\t(c.type === \"text\" && c.text.trim()) ||\n\t\t\t\t(!this.hideThinkingBlock && c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tlet isFirstTextBlock = true;\n\t\tlet thinkingRunIndex = -1;\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\tfor (const segment of parseCopyableTextSegments(content.text)) {\n\t\t\t\t\tif (segment.type === \"markdown\") {\n\t\t\t\t\t\tconst trimmed = segment.text.trim();\n\t\t\t\t\t\tif (!trimmed) continue;\n\t\t\t\t\t\tconst text = isFirstTextBlock ? `● ${trimmed}` : trimmed;\n\t\t\t\t\t\tisFirstTextBlock = false;\n\t\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\t\tnew Markdown(text, this.outputPad, 0, this.markdownTheme, {\n\t\t\t\t\t\t\t\tcolor: (body: string) => theme.fg(\"userMessageText\", body),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst key = `${i}:${segment.start}`;\n\t\t\t\t\tconst copyState = this.copyStates.get(key);\n\t\t\t\t\tconst status = copyState?.payload === segment.payload ? copyState.status : \"idle\";\n\t\t\t\t\tif (copyState && copyState.payload !== segment.payload) this.copyStates.delete(key);\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew CopyableTextBlockComponent(\n\t\t\t\t\t\t\tsegment.payload,\n\t\t\t\t\t\t\tsegment.complete,\n\t\t\t\t\t\t\tthis.outputPad,\n\t\t\t\t\t\t\tthis.markdownTheme,\n\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\t() => this.copyPayload(key, segment.payload),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (content.type === \"thinking\") {\n\t\t\t\tthinkingRunIndex++;\n\t\t\t\tconst displayBlocks: string[] = [];\n\t\t\t\tfor (; i < message.content.length; i++) {\n\t\t\t\t\tconst thinkingContent = message.content[i];\n\t\t\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\t\t\tif (thinking) {\n\t\t\t\t\t\tdisplayBlocks.push(thinking);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti--;\n\n\t\t\t\tif (displayBlocks.length === 0 || this.hideThinkingBlock) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst sourceBlocks = sourceThinkingRuns[thinkingRunIndex] ?? [];\n\t\t\t\tconst fullyRevealed =\n\t\t\t\t\tdisplayBlocks.length === sourceBlocks.length &&\n\t\t\t\t\tdisplayBlocks.every((block, index) => block === sourceBlocks[index]);\n\t\t\t\tthis.renderThinkingRun(thinkingRunIndex, displayBlocks, message, i, fullyRevealed);\n\t\t\t}\n\t\t}\n\n\t\t// Check if incomplete/failed - show after partial content.\n\t\t// For aborted/error tool calls, tool execution components show the error.\n\t\t// Length stops can happen before a tool call is complete, so surface them here too.\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (message.stopReason === \"length\") {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\tthis.contentContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t\"Error: Model stopped because it reached the maximum output token limit. The response may be incomplete.\",\n\t\t\t\t\t),\n\t\t\t\t\tthis.outputPad,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), this.outputPad, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), this.outputPad, 0));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate copyPayload(key: string, payload: string): void {\n\t\tif (this.copyStates.get(key)?.status === \"copying\") return;\n\t\tthis.copyStates.set(key, { payload, status: \"copying\" });\n\t\tthis.refreshCopyStatus();\n\n\t\tPromise.resolve()\n\t\t\t.then(() => this.copyText(payload))\n\t\t\t.then(() => {\n\t\t\t\tthis.copyStates.set(key, { payload, status: \"copied\" });\n\t\t\t\tthis.refreshCopyStatus();\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tconst message = (error instanceof Error ? error.message : String(error)).replace(/\\s+/g, \" \").trim();\n\t\t\t\tthis.copyStates.set(key, { payload, status: { error: message || \"Unknown error\" } });\n\t\t\t\tthis.refreshCopyStatus();\n\t\t\t});\n\t}\n\n\tprivate refreshCopyStatus(): void {\n\t\tif (this.lastMessage) this.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\tthis.requestRender();\n\t}\n\n\tprivate renderThinkingRun(\n\t\tthinkingRunIndex: number,\n\t\tthinkingBlocks: string[],\n\t\tdisplayMessage: AssistantMessage,\n\t\tdisplayIndex: number,\n\t\tfullyRevealed: boolean,\n\t): void {\n\t\tconst hasVisibleContentAfter =\n\t\t\tdisplayIndex >= 0\n\t\t\t\t? displayMessage.content\n\t\t\t\t\t\t.slice(displayIndex + 1)\n\t\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()))\n\t\t\t\t: displayMessage.content.some((c) => c.type === \"text\" && c.text.trim());\n\n\t\t// Provider completion can precede the reveal cursor; keep animating until it catches up.\n\t\tconst runComplete =\n\t\t\tfullyRevealed &&\n\t\t\tisThinkingRunComplete(false, this.thinkingTimings?.[thinkingRunIndex], this.thinkingTimings !== undefined);\n\t\tconst wrap = (inner: Component): void => {\n\t\t\tthis.contentContainer.addChild(new ThinkingRunBlock(this, thinkingRunIndex, inner));\n\t\t};\n\t\tif (this.thinkingCollapse && !this.isRunExpanded(thinkingRunIndex) && runComplete) {\n\t\t\tconst timing = this.thinkingTimings?.[thinkingRunIndex];\n\t\t\tconst label =\n\t\t\t\ttiming?.end !== undefined\n\t\t\t\t\t? `✻ Thought for ${formatThoughtDuration(timing.end - timing.start)}`\n\t\t\t\t\t: \"✻ Thought\";\n\t\t\tconst block = new Container();\n\t\t\tblock.addChild(new Text(theme.fg(\"thinkingText\", theme.italic(label)), this.outputPad, 0));\n\t\t\tconst joinedThinking = thinkingBlocks.join(\"\\n\\n\");\n\t\t\tconst snippet = thinkingSnippet(\n\t\t\t\tdisplayMessage.provider === \"openai-codex\" ? joinedThinking.replaceAll(\"**\", \"\") : joinedThinking,\n\t\t\t);\n\t\t\tif (snippet) {\n\t\t\t\tblock.addChild(new Text(theme.fg(\"thinkingText\", theme.italic(snippet)), this.outputPad + 2, 0));\n\t\t\t}\n\t\t\twrap(block);\n\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (!runComplete && !this.isRunExpanded(thinkingRunIndex)) {\n\t\t\twrap(\n\t\t\t\tnew ThinkingTailComponent(thinkingBlocks.join(\"\\n\\n\"), this.outputPad, 0, this.markdownTheme, {\n\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\titalic: true,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\twrap(\n\t\t\tnew Markdown(thinkingBlocks.join(\"\\n\\n\"), this.outputPad, 0, this.markdownTheme, {\n\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\titalic: true,\n\t\t\t}),\n\t\t);\n\t\tif (hasVisibleContentAfter) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\t}\n}\n\nclass ThinkingRunBlock extends Container {\n\tprivate readonly owner: AssistantMessageComponent;\n\tprivate readonly runIndex: number;\n\n\tconstructor(owner: AssistantMessageComponent, runIndex: number, inner: Component) {\n\t\tsuper();\n\t\tthis.owner = owner;\n\t\tthis.runIndex = runIndex;\n\t\tthis.addChild(inner);\n\t}\n\n\thandleClick(_localY: number, _width: number): boolean {\n\t\tthis.owner.toggleThinkingRun(this.runIndex);\n\t\treturn true;\n\t}\n}\n\nfunction collectThinkingRuns(content: AssistantMessage[\"content\"]): string[][] {\n\tconst runs: string[][] = [];\n\tfor (let i = 0; i < content.length; i++) {\n\t\tconst block = content[i];\n\t\tif (block.type !== \"thinking\") continue;\n\t\tconst blocks: string[] = [];\n\t\tfor (; i < content.length; i++) {\n\t\t\tconst thinkingContent = content[i];\n\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\ti--;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\tif (thinking) blocks.push(thinking);\n\t\t}\n\t\truns.push(blocks);\n\t}\n\treturn runs;\n}\n"]}
1
+ {"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAkB,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,wBAAwB,CAAC;AAC/G,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAI1E,OAAO,EAGN,KAAK,iBAAiB,EAEtB,MAAM,uBAAuB,CAAC;AAO/B,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,yBAAyB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACtD;AAOD;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,UAAU,UAAQ;IAClB,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IAGnC,OAAO,CAAC,gBAAgB,CAAU;IAElC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAqB;IAGzC,OAAO,CAAC,eAAe,CAAC,CAAsB;IAC9C,OAAO,CAAC,aAAa,CAAgB;IAGrC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,cAAc,CAAC,CAAmB;IAC1C,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkC;IAC3D,OAAO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Ac,CAAC,EAAE,gBAAgB,CAAA;KAAE,GAAG,IAAI,CA6G9F;IAED,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,iBAAiB;IAKzB,OAAO,CAAC,iBAAiB;CAmFzB","sourcesContent":["import type { AssistantMessage } from \"@ashx-j/lunr-ai\";\nimport { type Component, Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@ashx-j/lunr-tui\";\nimport type { ReasoningDisplay } from \"../../../core/settings-manager.ts\";\nimport { copyToClipboard } from \"../../../utils/clipboard.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { CopyableTextBlockComponent, type CopyableTextStatus, parseCopyableTextSegments } from \"./copyable-text.ts\";\nimport {\n\tformatThoughtDuration,\n\tisThinkingRunComplete,\n\ttype ThinkingRunTiming,\n\tthinkingSnippet,\n} from \"./thinking-summary.ts\";\nimport { ThinkingLineComponent, ThinkingTailComponent } from \"./thinking-tail.ts\";\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\nexport interface AssistantMessageOptions {\n\tcopyText?: (text: string) => Promise<void>;\n\trequestRender?: () => void;\n\treasoningDisplay?: ReasoningDisplay;\n\tonThinkingAnimationChange?: (active: boolean) => void;\n}\n\ninterface CopyState {\n\tpayload: string;\n\tstatus: CopyableTextStatus;\n}\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tselectable = true;\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\t// lunr: collapsible reasoning — when true, a completed thinking run renders as\n\t// \"✻ Thought for Xs\" + its first sentence instead of the full block.\n\tprivate thinkingCollapse: boolean;\n\t// lunr: per-run expand. `expanded` still means \"all runs\" for setExpanded().\n\tprivate expanded = false;\n\tprivate expandedRuns = new Set<number>();\n\t// lunr: live per-run timings from interactive-mode; undefined = history message\n\t// (always treated as final, rendered without durations).\n\tprivate thinkingTimings?: ThinkingRunTiming[];\n\tprivate markdownTheme: MarkdownTheme;\n\t// lunr: kept for the deferred alternative hidden-thinking indicator (Phase 8 removed the label render).\n\t// biome-ignore lint/correctness/noUnusedPrivateClassMembers: retained for future use\n\tprivate hiddenThinkingLabel: string;\n\tprivate outputPad: number;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate thinkingSource?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\tprivate readonly copyText: (text: string) => Promise<void>;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly copyStates = new Map<string, CopyState>();\n\tprivate reasoningDisplay: ReasoningDisplay;\n\tprivate readonly onThinkingAnimationChange?: (active: boolean) => void;\n\tprivate readonly thinkingAnimationStart = performance.now();\n\tprivate thinkingAnimationActive = false;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t\toutputPad = 1,\n\t\tthinkingCollapse = false,\n\t\toptions: AssistantMessageOptions = {},\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.thinkingCollapse = thinkingCollapse;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\t\tthis.outputPad = outputPad;\n\t\tthis.copyText = options.copyText ?? copyToClipboard;\n\t\tthis.requestRender = options.requestRender ?? (() => {});\n\t\tthis.reasoningDisplay = options.reasoningDisplay ?? \"auto\";\n\t\tthis.onThinkingAnimationChange = options.onThinkingAnimationChange;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tsetReasoningDisplay(display: ReasoningDisplay): void {\n\t\tthis.reasoningDisplay = display;\n\t\tif (this.lastMessage) this.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\t// lunr: collapsible reasoning toggles (live; re-render like setHideThinkingBlock).\n\tsetThinkingCollapse(collapse: boolean): void {\n\t\tthis.thinkingCollapse = collapse;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\t// lunr: Expandable hook; true expands every thinking run, false collapses all.\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tif (!expanded) this.expandedRuns.clear();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tprivate isRunExpanded(runIndex: number): boolean {\n\t\treturn this.expanded || this.expandedRuns.has(runIndex);\n\t}\n\n\ttoggleThinkingRun(runIndex: number): void {\n\t\tif (this.expanded) {\n\t\t\tthis.expanded = false;\n\t\t\tthis.expandedRuns.clear();\n\t\t\tconst count = this.lastMessage ? collectThinkingRuns(this.lastMessage.content).length : 0;\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\tif (i !== runIndex) this.expandedRuns.add(i);\n\t\t\t}\n\t\t} else if (this.expandedRuns.has(runIndex)) {\n\t\t\tthis.expandedRuns.delete(runIndex);\n\t\t} else {\n\t\t\tthis.expandedRuns.add(runIndex);\n\t\t}\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\thandleClick(localY: number, width: number, localX?: number): boolean {\n\t\tconst contentWidth = width;\n\t\tlet y = 0;\n\t\tfor (const child of this.contentContainer.children) {\n\t\t\tconst h = child.render(contentWidth).length;\n\t\t\tif (localY >= y && localY < y + h) {\n\t\t\t\tif (typeof child.handleClick === \"function\") {\n\t\t\t\t\treturn child.handleClick(localY - y, contentWidth, localX);\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\ty += h;\n\t\t}\n\t\treturn false;\n\t}\n\n\tsetThinkingTimings(timings: ThinkingRunTiming[] | undefined): void {\n\t\tthis.thinkingTimings = timings;\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tsetOutputPad(padding: number): void {\n\t\tthis.outputPad = padding;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) return lines;\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\n\t\treturn lines;\n\t}\n\n\tprivate thinkingSourceOptions(): { thinkingSource?: AssistantMessage } | undefined {\n\t\treturn this.thinkingSource ? { thinkingSource: this.thinkingSource } : undefined;\n\t}\n\n\tupdateContent(message: AssistantMessage, options?: { thinkingSource?: AssistantMessage }): void {\n\t\tthis.lastMessage = message;\n\t\tthis.thinkingSource = options?.thinkingSource;\n\t\tthis.thinkingAnimationActive = false;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst sourceMessage = this.thinkingSource ?? message;\n\t\tconst sourceThinkingRuns = collectThinkingRuns(sourceMessage.content);\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) =>\n\t\t\t\t(c.type === \"text\" && c.text.trim()) ||\n\t\t\t\t(!this.hideThinkingBlock && c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tlet isFirstTextBlock = true;\n\t\tlet thinkingRunIndex = -1;\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\tfor (const segment of parseCopyableTextSegments(content.text)) {\n\t\t\t\t\tif (segment.type === \"markdown\") {\n\t\t\t\t\t\tconst trimmed = segment.text.trim();\n\t\t\t\t\t\tif (!trimmed) continue;\n\t\t\t\t\t\tconst text = isFirstTextBlock ? `● ${trimmed}` : trimmed;\n\t\t\t\t\t\tisFirstTextBlock = false;\n\t\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\t\tnew Markdown(text, this.outputPad, 0, this.markdownTheme, {\n\t\t\t\t\t\t\t\tcolor: (body: string) => theme.fg(\"userMessageText\", body),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst key = `${i}:${segment.start}`;\n\t\t\t\t\tconst copyState = this.copyStates.get(key);\n\t\t\t\t\tconst status = copyState?.payload === segment.payload ? copyState.status : \"idle\";\n\t\t\t\t\tif (copyState && copyState.payload !== segment.payload) this.copyStates.delete(key);\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew CopyableTextBlockComponent(segment.payload, segment.complete, this.outputPad, status, () =>\n\t\t\t\t\t\t\tthis.copyPayload(key, segment.payload),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (content.type === \"thinking\") {\n\t\t\t\tthinkingRunIndex++;\n\t\t\t\tconst displayBlocks: string[] = [];\n\t\t\t\tfor (; i < message.content.length; i++) {\n\t\t\t\t\tconst thinkingContent = message.content[i];\n\t\t\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\t\t\tif (thinking) {\n\t\t\t\t\t\tdisplayBlocks.push(thinking);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti--;\n\n\t\t\t\tif (displayBlocks.length === 0 || this.hideThinkingBlock) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst sourceBlocks = sourceThinkingRuns[thinkingRunIndex] ?? [];\n\t\t\t\tconst fullyRevealed =\n\t\t\t\t\tdisplayBlocks.length === sourceBlocks.length &&\n\t\t\t\t\tdisplayBlocks.every((block, index) => block === sourceBlocks[index]);\n\t\t\t\tthis.renderThinkingRun(thinkingRunIndex, displayBlocks, message, i, fullyRevealed);\n\t\t\t}\n\t\t}\n\n\t\t// Check if incomplete/failed - show after partial content.\n\t\t// For aborted/error tool calls, tool execution components show the error.\n\t\t// Length stops can happen before a tool call is complete, so surface them here too.\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (message.stopReason === \"length\") {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\tthis.contentContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t\"Error: Model stopped because it reached the maximum output token limit. The response may be incomplete.\",\n\t\t\t\t\t),\n\t\t\t\t\tthis.outputPad,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), this.outputPad, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), this.outputPad, 0));\n\t\t\t}\n\t\t}\n\t\tthis.onThinkingAnimationChange?.(this.thinkingAnimationActive);\n\t}\n\n\tprivate copyPayload(key: string, payload: string): void {\n\t\tif (this.copyStates.get(key)?.status === \"copying\") return;\n\t\tthis.copyStates.set(key, { payload, status: \"copying\" });\n\t\tthis.refreshCopyStatus();\n\n\t\tPromise.resolve()\n\t\t\t.then(() => this.copyText(payload))\n\t\t\t.then(() => {\n\t\t\t\tthis.copyStates.set(key, { payload, status: \"copied\" });\n\t\t\t\tthis.refreshCopyStatus();\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tconst message = (error instanceof Error ? error.message : String(error)).replace(/\\s+/g, \" \").trim();\n\t\t\t\tthis.copyStates.set(key, { payload, status: { error: message || \"Unknown error\" } });\n\t\t\t\tthis.refreshCopyStatus();\n\t\t\t});\n\t}\n\n\tprivate refreshCopyStatus(): void {\n\t\tif (this.lastMessage) this.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\tthis.requestRender();\n\t}\n\n\tprivate renderThinkingRun(\n\t\tthinkingRunIndex: number,\n\t\tthinkingBlocks: string[],\n\t\tdisplayMessage: AssistantMessage,\n\t\tdisplayIndex: number,\n\t\tfullyRevealed: boolean,\n\t): void {\n\t\tconst hasVisibleContentAfter =\n\t\t\tdisplayIndex >= 0\n\t\t\t\t? displayMessage.content\n\t\t\t\t\t\t.slice(displayIndex + 1)\n\t\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()))\n\t\t\t\t: displayMessage.content.some((c) => c.type === \"text\" && c.text.trim());\n\n\t\t// Provider completion can precede the reveal cursor; keep animating until it catches up.\n\t\tconst runComplete =\n\t\t\tfullyRevealed &&\n\t\t\tisThinkingRunComplete(false, this.thinkingTimings?.[thinkingRunIndex], this.thinkingTimings !== undefined);\n\t\tconst wrap = (inner: Component): void => {\n\t\t\tthis.contentContainer.addChild(new ThinkingRunBlock(this, thinkingRunIndex, inner));\n\t\t};\n\t\tif (this.thinkingCollapse && !this.isRunExpanded(thinkingRunIndex) && runComplete) {\n\t\t\tconst timing = this.thinkingTimings?.[thinkingRunIndex];\n\t\t\tconst label =\n\t\t\t\ttiming?.end !== undefined\n\t\t\t\t\t? `✻ Thought for ${formatThoughtDuration(timing.end - timing.start)}`\n\t\t\t\t\t: \"✻ Thought\";\n\t\t\tconst block = new Container();\n\t\t\tblock.addChild(new Text(theme.fg(\"thinkingText\", theme.italic(label)), this.outputPad, 0));\n\t\t\tconst joinedThinking = thinkingBlocks.join(\"\\n\\n\");\n\t\t\tconst snippet = thinkingSnippet(\n\t\t\t\tdisplayMessage.provider === \"openai-codex\" ? joinedThinking.replaceAll(\"**\", \"\") : joinedThinking,\n\t\t\t);\n\t\t\tif (snippet) {\n\t\t\t\tblock.addChild(new Text(theme.fg(\"thinkingText\", theme.italic(snippet)), this.outputPad + 2, 0));\n\t\t\t}\n\t\t\twrap(block);\n\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (!runComplete && !this.isRunExpanded(thinkingRunIndex)) {\n\t\t\tconst oneLine =\n\t\t\t\tthis.reasoningDisplay === \"one-line\" ||\n\t\t\t\t(this.reasoningDisplay === \"auto\" && displayMessage.provider === \"openai-codex\");\n\t\t\tif (oneLine) {\n\t\t\t\tthis.thinkingAnimationActive = true;\n\t\t\t\t// The line owns its vertical padding, including the initial message spacer.\n\t\t\t\tif (this.contentContainer.children.length === 1 && this.contentContainer.children[0] instanceof Spacer) {\n\t\t\t\t\tthis.contentContainer.clear();\n\t\t\t\t}\n\t\t\t\twrap(\n\t\t\t\t\tnew ThinkingLineComponent(\n\t\t\t\t\t\tthinkingBlocks.join(\"\\n\\n\"),\n\t\t\t\t\t\tthis.outputPad,\n\t\t\t\t\t\tthis.markdownTheme,\n\t\t\t\t\t\tthis.thinkingAnimationStart,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\twrap(\n\t\t\t\tnew ThinkingTailComponent(thinkingBlocks.join(\"\\n\\n\"), this.outputPad, 0, this.markdownTheme, {\n\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\titalic: true,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\twrap(\n\t\t\tnew Markdown(thinkingBlocks.join(\"\\n\\n\"), this.outputPad, 0, this.markdownTheme, {\n\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\titalic: true,\n\t\t\t}),\n\t\t);\n\t\tif (hasVisibleContentAfter) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\t}\n}\n\nclass ThinkingRunBlock extends Container {\n\tprivate readonly owner: AssistantMessageComponent;\n\tprivate readonly runIndex: number;\n\n\tconstructor(owner: AssistantMessageComponent, runIndex: number, inner: Component) {\n\t\tsuper();\n\t\tthis.owner = owner;\n\t\tthis.runIndex = runIndex;\n\t\tthis.addChild(inner);\n\t}\n\n\thandleClick(_localY: number, _width: number): boolean {\n\t\tthis.owner.toggleThinkingRun(this.runIndex);\n\t\treturn true;\n\t}\n}\n\nfunction collectThinkingRuns(content: AssistantMessage[\"content\"]): string[][] {\n\tconst runs: string[][] = [];\n\tfor (let i = 0; i < content.length; i++) {\n\t\tconst block = content[i];\n\t\tif (block.type !== \"thinking\") continue;\n\t\tconst blocks: string[] = [];\n\t\tfor (; i < content.length; i++) {\n\t\t\tconst thinkingContent = content[i];\n\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\ti--;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\tif (thinking) blocks.push(thinking);\n\t\t}\n\t\truns.push(blocks);\n\t}\n\treturn runs;\n}\n"]}
@@ -3,7 +3,7 @@ import { copyToClipboard } from "../../../utils/clipboard.js";
3
3
  import { getMarkdownTheme, theme } from "../theme/theme.js";
4
4
  import { CopyableTextBlockComponent, parseCopyableTextSegments } from "./copyable-text.js";
5
5
  import { formatThoughtDuration, isThinkingRunComplete, thinkingSnippet, } from "./thinking-summary.js";
6
- import { ThinkingTailComponent } from "./thinking-tail.js";
6
+ import { ThinkingLineComponent, ThinkingTailComponent } from "./thinking-tail.js";
7
7
  const OSC133_ZONE_START = "\x1b]133;A\x07";
8
8
  const OSC133_ZONE_END = "\x1b]133;B\x07";
9
9
  const OSC133_ZONE_FINAL = "\x1b]133;C\x07";
@@ -34,15 +34,21 @@ export class AssistantMessageComponent extends Container {
34
34
  copyText;
35
35
  requestRender;
36
36
  copyStates = new Map();
37
- constructor(message, hideThinkingBlock = false, markdownTheme = getMarkdownTheme(), hiddenThinkingLabel = "Thinking...", outputPad = 1, thinkingCollapse = false, copyOptions = {}) {
37
+ reasoningDisplay;
38
+ onThinkingAnimationChange;
39
+ thinkingAnimationStart = performance.now();
40
+ thinkingAnimationActive = false;
41
+ constructor(message, hideThinkingBlock = false, markdownTheme = getMarkdownTheme(), hiddenThinkingLabel = "Thinking...", outputPad = 1, thinkingCollapse = false, options = {}) {
38
42
  super();
39
43
  this.hideThinkingBlock = hideThinkingBlock;
40
44
  this.thinkingCollapse = thinkingCollapse;
41
45
  this.markdownTheme = markdownTheme;
42
46
  this.hiddenThinkingLabel = hiddenThinkingLabel;
43
47
  this.outputPad = outputPad;
44
- this.copyText = copyOptions.copyText ?? copyToClipboard;
45
- this.requestRender = copyOptions.requestRender ?? (() => { });
48
+ this.copyText = options.copyText ?? copyToClipboard;
49
+ this.requestRender = options.requestRender ?? (() => { });
50
+ this.reasoningDisplay = options.reasoningDisplay ?? "auto";
51
+ this.onThinkingAnimationChange = options.onThinkingAnimationChange;
46
52
  // Container for text/thinking content
47
53
  this.contentContainer = new Container();
48
54
  this.addChild(this.contentContainer);
@@ -56,6 +62,11 @@ export class AssistantMessageComponent extends Container {
56
62
  this.updateContent(this.lastMessage, this.thinkingSourceOptions());
57
63
  }
58
64
  }
65
+ setReasoningDisplay(display) {
66
+ this.reasoningDisplay = display;
67
+ if (this.lastMessage)
68
+ this.updateContent(this.lastMessage, this.thinkingSourceOptions());
69
+ }
59
70
  setHideThinkingBlock(hide) {
60
71
  this.hideThinkingBlock = hide;
61
72
  if (this.lastMessage) {
@@ -145,6 +156,7 @@ export class AssistantMessageComponent extends Container {
145
156
  updateContent(message, options) {
146
157
  this.lastMessage = message;
147
158
  this.thinkingSource = options?.thinkingSource;
159
+ this.thinkingAnimationActive = false;
148
160
  // Clear content container
149
161
  this.contentContainer.clear();
150
162
  const sourceMessage = this.thinkingSource ?? message;
@@ -177,7 +189,7 @@ export class AssistantMessageComponent extends Container {
177
189
  const status = copyState?.payload === segment.payload ? copyState.status : "idle";
178
190
  if (copyState && copyState.payload !== segment.payload)
179
191
  this.copyStates.delete(key);
180
- this.contentContainer.addChild(new CopyableTextBlockComponent(segment.payload, segment.complete, this.outputPad, this.markdownTheme, status, () => this.copyPayload(key, segment.payload)));
192
+ this.contentContainer.addChild(new CopyableTextBlockComponent(segment.payload, segment.complete, this.outputPad, status, () => this.copyPayload(key, segment.payload)));
181
193
  }
182
194
  }
183
195
  else if (content.type === "thinking") {
@@ -226,6 +238,7 @@ export class AssistantMessageComponent extends Container {
226
238
  this.contentContainer.addChild(new Text(theme.fg("error", `Error: ${errorMsg}`), this.outputPad, 0));
227
239
  }
228
240
  }
241
+ this.onThinkingAnimationChange?.(this.thinkingAnimationActive);
229
242
  }
230
243
  copyPayload(key, payload) {
231
244
  if (this.copyStates.get(key)?.status === "copying")
@@ -280,6 +293,17 @@ export class AssistantMessageComponent extends Container {
280
293
  return;
281
294
  }
282
295
  if (!runComplete && !this.isRunExpanded(thinkingRunIndex)) {
296
+ const oneLine = this.reasoningDisplay === "one-line" ||
297
+ (this.reasoningDisplay === "auto" && displayMessage.provider === "openai-codex");
298
+ if (oneLine) {
299
+ this.thinkingAnimationActive = true;
300
+ // The line owns its vertical padding, including the initial message spacer.
301
+ if (this.contentContainer.children.length === 1 && this.contentContainer.children[0] instanceof Spacer) {
302
+ this.contentContainer.clear();
303
+ }
304
+ wrap(new ThinkingLineComponent(thinkingBlocks.join("\n\n"), this.outputPad, this.markdownTheme, this.thinkingAnimationStart));
305
+ return;
306
+ }
283
307
  wrap(new ThinkingTailComponent(thinkingBlocks.join("\n\n"), this.outputPad, 0, this.markdownTheme, {
284
308
  color: (text) => theme.fg("thinkingText", text),
285
309
  italic: true,
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,SAAS,EAAE,QAAQ,EAAsB,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC/G,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAA2B,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACpH,OAAO,EACN,qBAAqB,EACrB,qBAAqB,EAErB,eAAe,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAC3C,MAAM,eAAe,GAAG,gBAAgB,CAAC;AACzC,MAAM,i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nB,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["import type { AssistantMessage } from \"@ashx-j/lunr-ai\";\nimport { type Component, Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@ashx-j/lunr-tui\";\nimport { copyToClipboard } from \"../../../utils/clipboard.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { CopyableTextBlockComponent, type CopyableTextStatus, parseCopyableTextSegments } from \"./copyable-text.ts\";\nimport {\n\tformatThoughtDuration,\n\tisThinkingRunComplete,\n\ttype ThinkingRunTiming,\n\tthinkingSnippet,\n} from \"./thinking-summary.ts\";\nimport { ThinkingTailComponent } from \"./thinking-tail.ts\";\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\nexport interface AssistantMessageCopyOptions {\n\tcopyText?: (text: string) => Promise<void>;\n\trequestRender?: () => void;\n}\n\ninterface CopyState {\n\tpayload: string;\n\tstatus: CopyableTextStatus;\n}\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tselectable = true;\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\t// lunr: collapsible reasoning — when true, a completed thinking run renders as\n\t// \"✻ Thought for Xs\" + its first sentence instead of the full block.\n\tprivate thinkingCollapse: boolean;\n\t// lunr: per-run expand. `expanded` still means \"all runs\" for setExpanded().\n\tprivate expanded = false;\n\tprivate expandedRuns = new Set<number>();\n\t// lunr: live per-run timings from interactive-mode; undefined = history message\n\t// (always treated as final, rendered without durations).\n\tprivate thinkingTimings?: ThinkingRunTiming[];\n\tprivate markdownTheme: MarkdownTheme;\n\t// lunr: kept for the deferred alternative hidden-thinking indicator (Phase 8 removed the label render).\n\t// biome-ignore lint/correctness/noUnusedPrivateClassMembers: retained for future use\n\tprivate hiddenThinkingLabel: string;\n\tprivate outputPad: number;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate thinkingSource?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\tprivate readonly copyText: (text: string) => Promise<void>;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly copyStates = new Map<string, CopyState>();\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t\toutputPad = 1,\n\t\tthinkingCollapse = false,\n\t\tcopyOptions: AssistantMessageCopyOptions = {},\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.thinkingCollapse = thinkingCollapse;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\t\tthis.outputPad = outputPad;\n\t\tthis.copyText = copyOptions.copyText ?? copyToClipboard;\n\t\tthis.requestRender = copyOptions.requestRender ?? (() => {});\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\t// lunr: collapsible reasoning toggles (live; re-render like setHideThinkingBlock).\n\tsetThinkingCollapse(collapse: boolean): void {\n\t\tthis.thinkingCollapse = collapse;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\t// lunr: Expandable hook; true expands every thinking run, false collapses all.\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tif (!expanded) this.expandedRuns.clear();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tprivate isRunExpanded(runIndex: number): boolean {\n\t\treturn this.expanded || this.expandedRuns.has(runIndex);\n\t}\n\n\ttoggleThinkingRun(runIndex: number): void {\n\t\tif (this.expanded) {\n\t\t\tthis.expanded = false;\n\t\t\tthis.expandedRuns.clear();\n\t\t\tconst count = this.lastMessage ? collectThinkingRuns(this.lastMessage.content).length : 0;\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\tif (i !== runIndex) this.expandedRuns.add(i);\n\t\t\t}\n\t\t} else if (this.expandedRuns.has(runIndex)) {\n\t\t\tthis.expandedRuns.delete(runIndex);\n\t\t} else {\n\t\t\tthis.expandedRuns.add(runIndex);\n\t\t}\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\thandleClick(localY: number, width: number, localX?: number): boolean {\n\t\tconst contentWidth = width;\n\t\tlet y = 0;\n\t\tfor (const child of this.contentContainer.children) {\n\t\t\tconst h = child.render(contentWidth).length;\n\t\t\tif (localY >= y && localY < y + h) {\n\t\t\t\tif (typeof child.handleClick === \"function\") {\n\t\t\t\t\treturn child.handleClick(localY - y, contentWidth, localX);\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\ty += h;\n\t\t}\n\t\treturn false;\n\t}\n\n\tsetThinkingTimings(timings: ThinkingRunTiming[] | undefined): void {\n\t\tthis.thinkingTimings = timings;\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tsetOutputPad(padding: number): void {\n\t\tthis.outputPad = padding;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) return lines;\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\n\t\treturn lines;\n\t}\n\n\tprivate thinkingSourceOptions(): { thinkingSource?: AssistantMessage } | undefined {\n\t\treturn this.thinkingSource ? { thinkingSource: this.thinkingSource } : undefined;\n\t}\n\n\tupdateContent(message: AssistantMessage, options?: { thinkingSource?: AssistantMessage }): void {\n\t\tthis.lastMessage = message;\n\t\tthis.thinkingSource = options?.thinkingSource;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst sourceMessage = this.thinkingSource ?? message;\n\t\tconst sourceThinkingRuns = collectThinkingRuns(sourceMessage.content);\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) =>\n\t\t\t\t(c.type === \"text\" && c.text.trim()) ||\n\t\t\t\t(!this.hideThinkingBlock && c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tlet isFirstTextBlock = true;\n\t\tlet thinkingRunIndex = -1;\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\tfor (const segment of parseCopyableTextSegments(content.text)) {\n\t\t\t\t\tif (segment.type === \"markdown\") {\n\t\t\t\t\t\tconst trimmed = segment.text.trim();\n\t\t\t\t\t\tif (!trimmed) continue;\n\t\t\t\t\t\tconst text = isFirstTextBlock ? `● ${trimmed}` : trimmed;\n\t\t\t\t\t\tisFirstTextBlock = false;\n\t\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\t\tnew Markdown(text, this.outputPad, 0, this.markdownTheme, {\n\t\t\t\t\t\t\t\tcolor: (body: string) => theme.fg(\"userMessageText\", body),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst key = `${i}:${segment.start}`;\n\t\t\t\t\tconst copyState = this.copyStates.get(key);\n\t\t\t\t\tconst status = copyState?.payload === segment.payload ? copyState.status : \"idle\";\n\t\t\t\t\tif (copyState && copyState.payload !== segment.payload) this.copyStates.delete(key);\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew CopyableTextBlockComponent(\n\t\t\t\t\t\t\tsegment.payload,\n\t\t\t\t\t\t\tsegment.complete,\n\t\t\t\t\t\t\tthis.outputPad,\n\t\t\t\t\t\t\tthis.markdownTheme,\n\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\t() => this.copyPayload(key, segment.payload),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (content.type === \"thinking\") {\n\t\t\t\tthinkingRunIndex++;\n\t\t\t\tconst displayBlocks: string[] = [];\n\t\t\t\tfor (; i < message.content.length; i++) {\n\t\t\t\t\tconst thinkingContent = message.content[i];\n\t\t\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\t\t\tif (thinking) {\n\t\t\t\t\t\tdisplayBlocks.push(thinking);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti--;\n\n\t\t\t\tif (displayBlocks.length === 0 || this.hideThinkingBlock) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst sourceBlocks = sourceThinkingRuns[thinkingRunIndex] ?? [];\n\t\t\t\tconst fullyRevealed =\n\t\t\t\t\tdisplayBlocks.length === sourceBlocks.length &&\n\t\t\t\t\tdisplayBlocks.every((block, index) => block === sourceBlocks[index]);\n\t\t\t\tthis.renderThinkingRun(thinkingRunIndex, displayBlocks, message, i, fullyRevealed);\n\t\t\t}\n\t\t}\n\n\t\t// Check if incomplete/failed - show after partial content.\n\t\t// For aborted/error tool calls, tool execution components show the error.\n\t\t// Length stops can happen before a tool call is complete, so surface them here too.\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (message.stopReason === \"length\") {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\tthis.contentContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t\"Error: Model stopped because it reached the maximum output token limit. The response may be incomplete.\",\n\t\t\t\t\t),\n\t\t\t\t\tthis.outputPad,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), this.outputPad, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), this.outputPad, 0));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate copyPayload(key: string, payload: string): void {\n\t\tif (this.copyStates.get(key)?.status === \"copying\") return;\n\t\tthis.copyStates.set(key, { payload, status: \"copying\" });\n\t\tthis.refreshCopyStatus();\n\n\t\tPromise.resolve()\n\t\t\t.then(() => this.copyText(payload))\n\t\t\t.then(() => {\n\t\t\t\tthis.copyStates.set(key, { payload, status: \"copied\" });\n\t\t\t\tthis.refreshCopyStatus();\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tconst message = (error instanceof Error ? error.message : String(error)).replace(/\\s+/g, \" \").trim();\n\t\t\t\tthis.copyStates.set(key, { payload, status: { error: message || \"Unknown error\" } });\n\t\t\t\tthis.refreshCopyStatus();\n\t\t\t});\n\t}\n\n\tprivate refreshCopyStatus(): void {\n\t\tif (this.lastMessage) this.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\tthis.requestRender();\n\t}\n\n\tprivate renderThinkingRun(\n\t\tthinkingRunIndex: number,\n\t\tthinkingBlocks: string[],\n\t\tdisplayMessage: AssistantMessage,\n\t\tdisplayIndex: number,\n\t\tfullyRevealed: boolean,\n\t): void {\n\t\tconst hasVisibleContentAfter =\n\t\t\tdisplayIndex >= 0\n\t\t\t\t? displayMessage.content\n\t\t\t\t\t\t.slice(displayIndex + 1)\n\t\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()))\n\t\t\t\t: displayMessage.content.some((c) => c.type === \"text\" && c.text.trim());\n\n\t\t// Provider completion can precede the reveal cursor; keep animating until it catches up.\n\t\tconst runComplete =\n\t\t\tfullyRevealed &&\n\t\t\tisThinkingRunComplete(false, this.thinkingTimings?.[thinkingRunIndex], this.thinkingTimings !== undefined);\n\t\tconst wrap = (inner: Component): void => {\n\t\t\tthis.contentContainer.addChild(new ThinkingRunBlock(this, thinkingRunIndex, inner));\n\t\t};\n\t\tif (this.thinkingCollapse && !this.isRunExpanded(thinkingRunIndex) && runComplete) {\n\t\t\tconst timing = this.thinkingTimings?.[thinkingRunIndex];\n\t\t\tconst label =\n\t\t\t\ttiming?.end !== undefined\n\t\t\t\t\t? `✻ Thought for ${formatThoughtDuration(timing.end - timing.start)}`\n\t\t\t\t\t: \"✻ Thought\";\n\t\t\tconst block = new Container();\n\t\t\tblock.addChild(new Text(theme.fg(\"thinkingText\", theme.italic(label)), this.outputPad, 0));\n\t\t\tconst joinedThinking = thinkingBlocks.join(\"\\n\\n\");\n\t\t\tconst snippet = thinkingSnippet(\n\t\t\t\tdisplayMessage.provider === \"openai-codex\" ? joinedThinking.replaceAll(\"**\", \"\") : joinedThinking,\n\t\t\t);\n\t\t\tif (snippet) {\n\t\t\t\tblock.addChild(new Text(theme.fg(\"thinkingText\", theme.italic(snippet)), this.outputPad + 2, 0));\n\t\t\t}\n\t\t\twrap(block);\n\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (!runComplete && !this.isRunExpanded(thinkingRunIndex)) {\n\t\t\twrap(\n\t\t\t\tnew ThinkingTailComponent(thinkingBlocks.join(\"\\n\\n\"), this.outputPad, 0, this.markdownTheme, {\n\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\titalic: true,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\twrap(\n\t\t\tnew Markdown(thinkingBlocks.join(\"\\n\\n\"), this.outputPad, 0, this.markdownTheme, {\n\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\titalic: true,\n\t\t\t}),\n\t\t);\n\t\tif (hasVisibleContentAfter) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\t}\n}\n\nclass ThinkingRunBlock extends Container {\n\tprivate readonly owner: AssistantMessageComponent;\n\tprivate readonly runIndex: number;\n\n\tconstructor(owner: AssistantMessageComponent, runIndex: number, inner: Component) {\n\t\tsuper();\n\t\tthis.owner = owner;\n\t\tthis.runIndex = runIndex;\n\t\tthis.addChild(inner);\n\t}\n\n\thandleClick(_localY: number, _width: number): boolean {\n\t\tthis.owner.toggleThinkingRun(this.runIndex);\n\t\treturn true;\n\t}\n}\n\nfunction collectThinkingRuns(content: AssistantMessage[\"content\"]): string[][] {\n\tconst runs: string[][] = [];\n\tfor (let i = 0; i < content.length; i++) {\n\t\tconst block = content[i];\n\t\tif (block.type !== \"thinking\") continue;\n\t\tconst blocks: string[] = [];\n\t\tfor (; i < content.length; i++) {\n\t\t\tconst thinkingContent = content[i];\n\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\ti--;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\tif (thinking) blocks.push(thinking);\n\t\t}\n\t\truns.push(blocks);\n\t}\n\treturn runs;\n}\n"]}
1
+ {"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,SAAS,EAAE,QAAQ,EAAsB,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE/G,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAA2B,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACpH,OAAO,EACN,qBAAqB,EACrB,qBAAqB,EAErB,eAAe,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAElF,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAC3C,MAAM,eAAe,GAAG,gBAAgB,CAAC;AACzC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAc3C;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IACvD,UAAU,GAAG,IAAI,CAAC;IACV,gBAAgB,CAAY;IAC5B,iBAAiB,CAAU;IAC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;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAAA,CACrB;IAED,WAAW,CAAC,OAAe,EAAE,MAAc,EAAW;QACrD,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IAAA,CACZ;CACD;AAED,SAAS,mBAAmB,CAAC,OAAoC,EAAc;IAC9E,MAAM,IAAI,GAAe,EAAE,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;YAAE,SAAS;QACxC,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,MAAM,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YACnC,IAAI,eAAe,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACzC,CAAC,EAAE,CAAC;gBACJ,MAAM;YACP,CAAC;YACD,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACjD,IAAI,QAAQ;gBAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["import type { AssistantMessage } from \"@ashx-j/lunr-ai\";\nimport { type Component, Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@ashx-j/lunr-tui\";\nimport type { ReasoningDisplay } from \"../../../core/settings-manager.ts\";\nimport { copyToClipboard } from \"../../../utils/clipboard.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { CopyableTextBlockComponent, type CopyableTextStatus, parseCopyableTextSegments } from \"./copyable-text.ts\";\nimport {\n\tformatThoughtDuration,\n\tisThinkingRunComplete,\n\ttype ThinkingRunTiming,\n\tthinkingSnippet,\n} from \"./thinking-summary.ts\";\nimport { ThinkingLineComponent, ThinkingTailComponent } from \"./thinking-tail.ts\";\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\nexport interface AssistantMessageOptions {\n\tcopyText?: (text: string) => Promise<void>;\n\trequestRender?: () => void;\n\treasoningDisplay?: ReasoningDisplay;\n\tonThinkingAnimationChange?: (active: boolean) => void;\n}\n\ninterface CopyState {\n\tpayload: string;\n\tstatus: CopyableTextStatus;\n}\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tselectable = true;\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\t// lunr: collapsible reasoning — when true, a completed thinking run renders as\n\t// \"✻ Thought for Xs\" + its first sentence instead of the full block.\n\tprivate thinkingCollapse: boolean;\n\t// lunr: per-run expand. `expanded` still means \"all runs\" for setExpanded().\n\tprivate expanded = false;\n\tprivate expandedRuns = new Set<number>();\n\t// lunr: live per-run timings from interactive-mode; undefined = history message\n\t// (always treated as final, rendered without durations).\n\tprivate thinkingTimings?: ThinkingRunTiming[];\n\tprivate markdownTheme: MarkdownTheme;\n\t// lunr: kept for the deferred alternative hidden-thinking indicator (Phase 8 removed the label render).\n\t// biome-ignore lint/correctness/noUnusedPrivateClassMembers: retained for future use\n\tprivate hiddenThinkingLabel: string;\n\tprivate outputPad: number;\n\tprivate lastMessage?: AssistantMessage;\n\tprivate thinkingSource?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\tprivate readonly copyText: (text: string) => Promise<void>;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly copyStates = new Map<string, CopyState>();\n\tprivate reasoningDisplay: ReasoningDisplay;\n\tprivate readonly onThinkingAnimationChange?: (active: boolean) => void;\n\tprivate readonly thinkingAnimationStart = performance.now();\n\tprivate thinkingAnimationActive = false;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t\toutputPad = 1,\n\t\tthinkingCollapse = false,\n\t\toptions: AssistantMessageOptions = {},\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.thinkingCollapse = thinkingCollapse;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\t\tthis.outputPad = outputPad;\n\t\tthis.copyText = options.copyText ?? copyToClipboard;\n\t\tthis.requestRender = options.requestRender ?? (() => {});\n\t\tthis.reasoningDisplay = options.reasoningDisplay ?? \"auto\";\n\t\tthis.onThinkingAnimationChange = options.onThinkingAnimationChange;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tsetReasoningDisplay(display: ReasoningDisplay): void {\n\t\tthis.reasoningDisplay = display;\n\t\tif (this.lastMessage) this.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\t// lunr: collapsible reasoning toggles (live; re-render like setHideThinkingBlock).\n\tsetThinkingCollapse(collapse: boolean): void {\n\t\tthis.thinkingCollapse = collapse;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\t// lunr: Expandable hook; true expands every thinking run, false collapses all.\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tif (!expanded) this.expandedRuns.clear();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tprivate isRunExpanded(runIndex: number): boolean {\n\t\treturn this.expanded || this.expandedRuns.has(runIndex);\n\t}\n\n\ttoggleThinkingRun(runIndex: number): void {\n\t\tif (this.expanded) {\n\t\t\tthis.expanded = false;\n\t\t\tthis.expandedRuns.clear();\n\t\t\tconst count = this.lastMessage ? collectThinkingRuns(this.lastMessage.content).length : 0;\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\tif (i !== runIndex) this.expandedRuns.add(i);\n\t\t\t}\n\t\t} else if (this.expandedRuns.has(runIndex)) {\n\t\t\tthis.expandedRuns.delete(runIndex);\n\t\t} else {\n\t\t\tthis.expandedRuns.add(runIndex);\n\t\t}\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\thandleClick(localY: number, width: number, localX?: number): boolean {\n\t\tconst contentWidth = width;\n\t\tlet y = 0;\n\t\tfor (const child of this.contentContainer.children) {\n\t\t\tconst h = child.render(contentWidth).length;\n\t\t\tif (localY >= y && localY < y + h) {\n\t\t\t\tif (typeof child.handleClick === \"function\") {\n\t\t\t\t\treturn child.handleClick(localY - y, contentWidth, localX);\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\ty += h;\n\t\t}\n\t\treturn false;\n\t}\n\n\tsetThinkingTimings(timings: ThinkingRunTiming[] | undefined): void {\n\t\tthis.thinkingTimings = timings;\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\tsetOutputPad(padding: number): void {\n\t\tthis.outputPad = padding;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\tconst lines = super.render(width);\n\t\tif (this.hasToolCalls || lines.length === 0) return lines;\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\n\t\treturn lines;\n\t}\n\n\tprivate thinkingSourceOptions(): { thinkingSource?: AssistantMessage } | undefined {\n\t\treturn this.thinkingSource ? { thinkingSource: this.thinkingSource } : undefined;\n\t}\n\n\tupdateContent(message: AssistantMessage, options?: { thinkingSource?: AssistantMessage }): void {\n\t\tthis.lastMessage = message;\n\t\tthis.thinkingSource = options?.thinkingSource;\n\t\tthis.thinkingAnimationActive = false;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst sourceMessage = this.thinkingSource ?? message;\n\t\tconst sourceThinkingRuns = collectThinkingRuns(sourceMessage.content);\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) =>\n\t\t\t\t(c.type === \"text\" && c.text.trim()) ||\n\t\t\t\t(!this.hideThinkingBlock && c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tlet isFirstTextBlock = true;\n\t\tlet thinkingRunIndex = -1;\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\tfor (const segment of parseCopyableTextSegments(content.text)) {\n\t\t\t\t\tif (segment.type === \"markdown\") {\n\t\t\t\t\t\tconst trimmed = segment.text.trim();\n\t\t\t\t\t\tif (!trimmed) continue;\n\t\t\t\t\t\tconst text = isFirstTextBlock ? `● ${trimmed}` : trimmed;\n\t\t\t\t\t\tisFirstTextBlock = false;\n\t\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\t\tnew Markdown(text, this.outputPad, 0, this.markdownTheme, {\n\t\t\t\t\t\t\t\tcolor: (body: string) => theme.fg(\"userMessageText\", body),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst key = `${i}:${segment.start}`;\n\t\t\t\t\tconst copyState = this.copyStates.get(key);\n\t\t\t\t\tconst status = copyState?.payload === segment.payload ? copyState.status : \"idle\";\n\t\t\t\t\tif (copyState && copyState.payload !== segment.payload) this.copyStates.delete(key);\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew CopyableTextBlockComponent(segment.payload, segment.complete, this.outputPad, status, () =>\n\t\t\t\t\t\t\tthis.copyPayload(key, segment.payload),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (content.type === \"thinking\") {\n\t\t\t\tthinkingRunIndex++;\n\t\t\t\tconst displayBlocks: string[] = [];\n\t\t\t\tfor (; i < message.content.length; i++) {\n\t\t\t\t\tconst thinkingContent = message.content[i];\n\t\t\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\t\t\tif (thinking) {\n\t\t\t\t\t\tdisplayBlocks.push(thinking);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti--;\n\n\t\t\t\tif (displayBlocks.length === 0 || this.hideThinkingBlock) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst sourceBlocks = sourceThinkingRuns[thinkingRunIndex] ?? [];\n\t\t\t\tconst fullyRevealed =\n\t\t\t\t\tdisplayBlocks.length === sourceBlocks.length &&\n\t\t\t\t\tdisplayBlocks.every((block, index) => block === sourceBlocks[index]);\n\t\t\t\tthis.renderThinkingRun(thinkingRunIndex, displayBlocks, message, i, fullyRevealed);\n\t\t\t}\n\t\t}\n\n\t\t// Check if incomplete/failed - show after partial content.\n\t\t// For aborted/error tool calls, tool execution components show the error.\n\t\t// Length stops can happen before a tool call is complete, so surface them here too.\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (message.stopReason === \"length\") {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\tthis.contentContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t\"Error: Model stopped because it reached the maximum output token limit. The response may be incomplete.\",\n\t\t\t\t\t),\n\t\t\t\t\tthis.outputPad,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), this.outputPad, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), this.outputPad, 0));\n\t\t\t}\n\t\t}\n\t\tthis.onThinkingAnimationChange?.(this.thinkingAnimationActive);\n\t}\n\n\tprivate copyPayload(key: string, payload: string): void {\n\t\tif (this.copyStates.get(key)?.status === \"copying\") return;\n\t\tthis.copyStates.set(key, { payload, status: \"copying\" });\n\t\tthis.refreshCopyStatus();\n\n\t\tPromise.resolve()\n\t\t\t.then(() => this.copyText(payload))\n\t\t\t.then(() => {\n\t\t\t\tthis.copyStates.set(key, { payload, status: \"copied\" });\n\t\t\t\tthis.refreshCopyStatus();\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tconst message = (error instanceof Error ? error.message : String(error)).replace(/\\s+/g, \" \").trim();\n\t\t\t\tthis.copyStates.set(key, { payload, status: { error: message || \"Unknown error\" } });\n\t\t\t\tthis.refreshCopyStatus();\n\t\t\t});\n\t}\n\n\tprivate refreshCopyStatus(): void {\n\t\tif (this.lastMessage) this.updateContent(this.lastMessage, this.thinkingSourceOptions());\n\t\tthis.requestRender();\n\t}\n\n\tprivate renderThinkingRun(\n\t\tthinkingRunIndex: number,\n\t\tthinkingBlocks: string[],\n\t\tdisplayMessage: AssistantMessage,\n\t\tdisplayIndex: number,\n\t\tfullyRevealed: boolean,\n\t): void {\n\t\tconst hasVisibleContentAfter =\n\t\t\tdisplayIndex >= 0\n\t\t\t\t? displayMessage.content\n\t\t\t\t\t\t.slice(displayIndex + 1)\n\t\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()))\n\t\t\t\t: displayMessage.content.some((c) => c.type === \"text\" && c.text.trim());\n\n\t\t// Provider completion can precede the reveal cursor; keep animating until it catches up.\n\t\tconst runComplete =\n\t\t\tfullyRevealed &&\n\t\t\tisThinkingRunComplete(false, this.thinkingTimings?.[thinkingRunIndex], this.thinkingTimings !== undefined);\n\t\tconst wrap = (inner: Component): void => {\n\t\t\tthis.contentContainer.addChild(new ThinkingRunBlock(this, thinkingRunIndex, inner));\n\t\t};\n\t\tif (this.thinkingCollapse && !this.isRunExpanded(thinkingRunIndex) && runComplete) {\n\t\t\tconst timing = this.thinkingTimings?.[thinkingRunIndex];\n\t\t\tconst label =\n\t\t\t\ttiming?.end !== undefined\n\t\t\t\t\t? `✻ Thought for ${formatThoughtDuration(timing.end - timing.start)}`\n\t\t\t\t\t: \"✻ Thought\";\n\t\t\tconst block = new Container();\n\t\t\tblock.addChild(new Text(theme.fg(\"thinkingText\", theme.italic(label)), this.outputPad, 0));\n\t\t\tconst joinedThinking = thinkingBlocks.join(\"\\n\\n\");\n\t\t\tconst snippet = thinkingSnippet(\n\t\t\t\tdisplayMessage.provider === \"openai-codex\" ? joinedThinking.replaceAll(\"**\", \"\") : joinedThinking,\n\t\t\t);\n\t\t\tif (snippet) {\n\t\t\t\tblock.addChild(new Text(theme.fg(\"thinkingText\", theme.italic(snippet)), this.outputPad + 2, 0));\n\t\t\t}\n\t\t\twrap(block);\n\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (!runComplete && !this.isRunExpanded(thinkingRunIndex)) {\n\t\t\tconst oneLine =\n\t\t\t\tthis.reasoningDisplay === \"one-line\" ||\n\t\t\t\t(this.reasoningDisplay === \"auto\" && displayMessage.provider === \"openai-codex\");\n\t\t\tif (oneLine) {\n\t\t\t\tthis.thinkingAnimationActive = true;\n\t\t\t\t// The line owns its vertical padding, including the initial message spacer.\n\t\t\t\tif (this.contentContainer.children.length === 1 && this.contentContainer.children[0] instanceof Spacer) {\n\t\t\t\t\tthis.contentContainer.clear();\n\t\t\t\t}\n\t\t\t\twrap(\n\t\t\t\t\tnew ThinkingLineComponent(\n\t\t\t\t\t\tthinkingBlocks.join(\"\\n\\n\"),\n\t\t\t\t\t\tthis.outputPad,\n\t\t\t\t\t\tthis.markdownTheme,\n\t\t\t\t\t\tthis.thinkingAnimationStart,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\twrap(\n\t\t\t\tnew ThinkingTailComponent(thinkingBlocks.join(\"\\n\\n\"), this.outputPad, 0, this.markdownTheme, {\n\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\titalic: true,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\twrap(\n\t\t\tnew Markdown(thinkingBlocks.join(\"\\n\\n\"), this.outputPad, 0, this.markdownTheme, {\n\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\titalic: true,\n\t\t\t}),\n\t\t);\n\t\tif (hasVisibleContentAfter) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\t}\n}\n\nclass ThinkingRunBlock extends Container {\n\tprivate readonly owner: AssistantMessageComponent;\n\tprivate readonly runIndex: number;\n\n\tconstructor(owner: AssistantMessageComponent, runIndex: number, inner: Component) {\n\t\tsuper();\n\t\tthis.owner = owner;\n\t\tthis.runIndex = runIndex;\n\t\tthis.addChild(inner);\n\t}\n\n\thandleClick(_localY: number, _width: number): boolean {\n\t\tthis.owner.toggleThinkingRun(this.runIndex);\n\t\treturn true;\n\t}\n}\n\nfunction collectThinkingRuns(content: AssistantMessage[\"content\"]): string[][] {\n\tconst runs: string[][] = [];\n\tfor (let i = 0; i < content.length; i++) {\n\t\tconst block = content[i];\n\t\tif (block.type !== \"thinking\") continue;\n\t\tconst blocks: string[] = [];\n\t\tfor (; i < content.length; i++) {\n\t\t\tconst thinkingContent = content[i];\n\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\ti--;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\tif (thinking) blocks.push(thinking);\n\t\t}\n\t\truns.push(blocks);\n\t}\n\treturn runs;\n}\n"]}