painapple-code 1.0.0__py3-none-any.whl

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 (436) hide show
  1. painapple_code/__init__.py +30 -0
  2. painapple_code/__main__.py +18 -0
  3. painapple_code/_version.py +24 -0
  4. painapple_code/auth_middleware.py +930 -0
  5. painapple_code/cli/__init__.py +204 -0
  6. painapple_code/cli/deploy/__init__.py +15 -0
  7. painapple_code/cli/deploy/claude_seed.py +41 -0
  8. painapple_code/cli/deploy/config.py +260 -0
  9. painapple_code/cli/deploy/container.py +715 -0
  10. painapple_code/cli/deploy/launch.py +163 -0
  11. painapple_code/cli/deploy/runtime.py +223 -0
  12. painapple_code/cli/lifecycle_cmd.py +443 -0
  13. painapple_code/cli/list_cmd.py +572 -0
  14. painapple_code/cli/manage_cmd.py +670 -0
  15. painapple_code/cli/netinfo.py +125 -0
  16. painapple_code/cli/profiles.py +390 -0
  17. painapple_code/cli/serve_args.py +163 -0
  18. painapple_code/cli/serve_config.py +256 -0
  19. painapple_code/cli/setup_cmd.py +664 -0
  20. painapple_code/cli/ui.py +438 -0
  21. painapple_code/cost_analytics.py +879 -0
  22. painapple_code/data/models.defaults.yaml +18 -0
  23. painapple_code/data/models.yaml +18 -0
  24. painapple_code/data/presets.defaults.json +32 -0
  25. painapple_code/data/strings.yaml +2269 -0
  26. painapple_code/helpers.py +406 -0
  27. painapple_code/paths.py +1514 -0
  28. painapple_code/prompt_explorer.py +984 -0
  29. painapple_code/providers/__init__.py +224 -0
  30. painapple_code/providers/base.py +710 -0
  31. painapple_code/providers/claude/__init__.py +74 -0
  32. painapple_code/providers/claude/capabilities.py +218 -0
  33. painapple_code/providers/claude/errors.py +79 -0
  34. painapple_code/providers/claude/launch.py +50 -0
  35. painapple_code/providers/claude/summary.py +89 -0
  36. painapple_code/providers/claude/translate.py +74 -0
  37. painapple_code/providers/claude_sdk/__init__.py +139 -0
  38. painapple_code/providers/claude_sdk/driver.py +412 -0
  39. painapple_code/providers/codex/__init__.py +87 -0
  40. painapple_code/providers/codex/capabilities.py +321 -0
  41. painapple_code/providers/codex/errors.py +70 -0
  42. painapple_code/providers/codex/launch.py +142 -0
  43. painapple_code/providers/codex/summary.py +196 -0
  44. painapple_code/providers/codex/translate.py +204 -0
  45. painapple_code/providers/codex_app_server/__init__.py +100 -0
  46. painapple_code/providers/codex_app_server/capabilities.py +41 -0
  47. painapple_code/providers/codex_app_server/launch.py +202 -0
  48. painapple_code/providers/codex_app_server/summary.py +291 -0
  49. painapple_code/providers/codex_app_server/translate.py +263 -0
  50. painapple_code/providers/codex_app_server/transport.py +238 -0
  51. painapple_code/routes/__init__.py +0 -0
  52. painapple_code/routes/api_agents.py +441 -0
  53. painapple_code/routes/api_app.py +368 -0
  54. painapple_code/routes/api_app_commit_sections.py +127 -0
  55. painapple_code/routes/api_app_config.py +997 -0
  56. painapple_code/routes/api_app_session_prefs.py +217 -0
  57. painapple_code/routes/api_browser.py +690 -0
  58. painapple_code/routes/api_commands.py +374 -0
  59. painapple_code/routes/api_costs.py +128 -0
  60. painapple_code/routes/api_drafts.py +139 -0
  61. painapple_code/routes/api_exec.py +149 -0
  62. painapple_code/routes/api_files.py +542 -0
  63. painapple_code/routes/api_git.py +657 -0
  64. painapple_code/routes/api_logs.py +649 -0
  65. painapple_code/routes/api_plugins.py +275 -0
  66. painapple_code/routes/api_project_config.py +418 -0
  67. painapple_code/routes/api_prompts.py +231 -0
  68. painapple_code/routes/api_providers.py +53 -0
  69. painapple_code/routes/api_search.py +411 -0
  70. painapple_code/routes/api_session_stash.py +234 -0
  71. painapple_code/routes/api_session_welcome.py +151 -0
  72. painapple_code/routes/api_sessions.py +742 -0
  73. painapple_code/routes/api_shadow.py +323 -0
  74. painapple_code/routes/api_shadow_db.py +512 -0
  75. painapple_code/routes/api_shadow_files.py +332 -0
  76. painapple_code/routes/api_shadow_search.py +476 -0
  77. painapple_code/routes/api_skills.py +610 -0
  78. painapple_code/routes/api_tasks.py +147 -0
  79. painapple_code/routes/api_terminal.py +540 -0
  80. painapple_code/routes/api_upload.py +293 -0
  81. painapple_code/routes/api_viewer.py +229 -0
  82. painapple_code/routes/dependencies.py +109 -0
  83. painapple_code/routes/ws_chat.py +837 -0
  84. painapple_code/server.py +2208 -0
  85. painapple_code/server_logging.py +263 -0
  86. painapple_code/services/__init__.py +0 -0
  87. painapple_code/services/agent_session.py +2738 -0
  88. painapple_code/session_store.py +253 -0
  89. painapple_code/session_store_core.py +879 -0
  90. painapple_code/shadow_db.py +830 -0
  91. painapple_code/shadow_db_plans.py +369 -0
  92. painapple_code/shadow_db_queries.py +595 -0
  93. painapple_code/shadow_db_schema.py +676 -0
  94. painapple_code/shadow_git.py +1296 -0
  95. painapple_code/shadow_git_frontmatter.py +314 -0
  96. painapple_code/shadow_git_sections.py +520 -0
  97. painapple_code/shadow_git_summary.py +462 -0
  98. painapple_code/shadow_parser.py +560 -0
  99. painapple_code/static/css/00-variables.css +276 -0
  100. painapple_code/static/css/01-base.css +245 -0
  101. painapple_code/static/css/02-tooltips.css +36 -0
  102. painapple_code/static/css/09-left-rail.css +448 -0
  103. painapple_code/static/css/10-header.css +777 -0
  104. painapple_code/static/css/11-connection-bar.css +120 -0
  105. painapple_code/static/css/20-messages.css +750 -0
  106. painapple_code/static/css/21-tool-blocks.css +2340 -0
  107. painapple_code/static/css/22-edit-diff.css +619 -0
  108. painapple_code/static/css/23-thinking.css +1584 -0
  109. painapple_code/static/css/24-background-tasks.css +359 -0
  110. painapple_code/static/css/25-context-block.css +252 -0
  111. painapple_code/static/css/26-session-setup.css +144 -0
  112. painapple_code/static/css/30-markdown.css +854 -0
  113. painapple_code/static/css/40-input.css +2418 -0
  114. painapple_code/static/css/41-autocomplete.css +127 -0
  115. painapple_code/static/css/42-activity-strip.css +97 -0
  116. painapple_code/static/css/43-file-autocomplete.css +121 -0
  117. painapple_code/static/css/44-snippets-autocomplete.css +224 -0
  118. painapple_code/static/css/45-selection-bar.css +433 -0
  119. painapple_code/static/css/46-keyboard-bar.css +119 -0
  120. painapple_code/static/css/47-keyboard-longpress.css +116 -0
  121. painapple_code/static/css/47-token-profile.css +106 -0
  122. painapple_code/static/css/50-welcome.css +3095 -0
  123. painapple_code/static/css/51-modals.css +301 -0
  124. painapple_code/static/css/52-utilities.css +77 -0
  125. painapple_code/static/css/53-image-upload.css +456 -0
  126. painapple_code/static/css/54-todo-list.css +102 -0
  127. painapple_code/static/css/55-file-upload.css +113 -0
  128. painapple_code/static/css/56-chat-navigator.css +218 -0
  129. painapple_code/static/css/56-permission-card.css +332 -0
  130. painapple_code/static/css/56-plan-approval.css +204 -0
  131. painapple_code/static/css/56-question-form.css +602 -0
  132. painapple_code/static/css/57-swipe-indicator.css +95 -0
  133. painapple_code/static/css/58-session-families.css +627 -0
  134. painapple_code/static/css/59-about.css +196 -0
  135. painapple_code/static/css/61-log-explorer.css +723 -0
  136. painapple_code/static/css/62-json-tree.css +489 -0
  137. painapple_code/static/css/62-skills-widget.css +650 -0
  138. painapple_code/static/css/63-commands-widget.css +30 -0
  139. painapple_code/static/css/63-plugins-widget.css +174 -0
  140. painapple_code/static/css/63-terminal.css +516 -0
  141. painapple_code/static/css/64-search-files-widget.css +448 -0
  142. painapple_code/static/css/65-snippets-widget.css +426 -0
  143. painapple_code/static/css/66-active-sessions.css +979 -0
  144. painapple_code/static/css/66-agents-widget.css +265 -0
  145. painapple_code/static/css/66-file-explorer-widget.css +855 -0
  146. painapple_code/static/css/66-git-panel.css +791 -0
  147. painapple_code/static/css/66-history-explorer.css +1496 -0
  148. painapple_code/static/css/67-diff-viewer.css +602 -0
  149. painapple_code/static/css/67-editor-view.css +748 -0
  150. painapple_code/static/css/67-file-preview-widget.css +1873 -0
  151. painapple_code/static/css/68-browser-widget.css +337 -0
  152. painapple_code/static/css/68-compare-wizard.css +355 -0
  153. painapple_code/static/css/68-csv-preview.css +106 -0
  154. painapple_code/static/css/68-diff-preview.css +103 -0
  155. painapple_code/static/css/68-helpers-install-widget.css +491 -0
  156. painapple_code/static/css/68-image-annotate.css +346 -0
  157. painapple_code/static/css/68-terminal-view.css +98 -0
  158. painapple_code/static/css/68-uploads-widget.css +229 -0
  159. painapple_code/static/css/69-cost-analytics.css +537 -0
  160. painapple_code/static/css/70-config-panel.css +3736 -0
  161. painapple_code/static/css/70-excalidraw.css +136 -0
  162. painapple_code/static/css/70-prompt-explorer.css +890 -0
  163. painapple_code/static/css/71-chart.css +111 -0
  164. painapple_code/static/css/72-discussion-sidebar.css +678 -0
  165. painapple_code/static/css/74-debug-logs.css +656 -0
  166. painapple_code/static/css/80-open-dialog.css +146 -0
  167. painapple_code/static/css/80-quick-switcher.css +383 -0
  168. painapple_code/static/css/80-widget-system.css +1763 -0
  169. painapple_code/static/css/81-quick-actions.css +1020 -0
  170. painapple_code/static/css/82-context-popover.css +1233 -0
  171. painapple_code/static/css/83-context-menu.css +339 -0
  172. painapple_code/static/css/85-lazy-loading.css +102 -0
  173. painapple_code/static/css/86-zen-mode.css +708 -0
  174. painapple_code/static/css/87-grid-switcher.css +346 -0
  175. painapple_code/static/css/login.css +198 -0
  176. painapple_code/static/dist/app.bundle.js +7177 -0
  177. painapple_code/static/feature-triage.html +446 -0
  178. painapple_code/static/icons/apple-touch-icon.png +0 -0
  179. painapple_code/static/icons/favicon-32.png +0 -0
  180. painapple_code/static/icons/favicon.ico +0 -0
  181. painapple_code/static/icons/icon-128.png +0 -0
  182. painapple_code/static/icons/icon-144.png +0 -0
  183. painapple_code/static/icons/icon-152.png +0 -0
  184. painapple_code/static/icons/icon-180.png +0 -0
  185. painapple_code/static/icons/icon-192.png +0 -0
  186. painapple_code/static/icons/icon-384.png +0 -0
  187. painapple_code/static/icons/icon-512.png +0 -0
  188. painapple_code/static/icons/icon-72.png +0 -0
  189. painapple_code/static/icons/icon-96.png +0 -0
  190. painapple_code/static/js/action-delegate.js +187 -0
  191. painapple_code/static/js/activity-strip.js +193 -0
  192. painapple_code/static/js/app/context-menus.js +619 -0
  193. painapple_code/static/js/app/file-preview.js +163 -0
  194. painapple_code/static/js/app/init-ui.js +574 -0
  195. painapple_code/static/js/app/input-events.js +561 -0
  196. painapple_code/static/js/app/input-resize.js +313 -0
  197. painapple_code/static/js/app/message-actions.js +419 -0
  198. painapple_code/static/js/app/panels.js +210 -0
  199. painapple_code/static/js/app/rendering-delegators.js +246 -0
  200. painapple_code/static/js/app/server-loading.js +365 -0
  201. painapple_code/static/js/app/session-ops.js +287 -0
  202. painapple_code/static/js/app/session-switch.js +443 -0
  203. painapple_code/static/js/app/settings-helpers.js +280 -0
  204. painapple_code/static/js/app/startup-welcome.js +290 -0
  205. painapple_code/static/js/app-context.js +157 -0
  206. painapple_code/static/js/app.js +2134 -0
  207. painapple_code/static/js/auth-fetch.js +46 -0
  208. painapple_code/static/js/background-tasks.js +274 -0
  209. painapple_code/static/js/boot.js +73 -0
  210. painapple_code/static/js/caret-position.js +171 -0
  211. painapple_code/static/js/chat-navigator.js +710 -0
  212. painapple_code/static/js/chat-search.js +323 -0
  213. painapple_code/static/js/command-executor.js +176 -0
  214. painapple_code/static/js/command-store.js +497 -0
  215. painapple_code/static/js/components.js +1414 -0
  216. painapple_code/static/js/config.js +218 -0
  217. painapple_code/static/js/context-menu.js +740 -0
  218. painapple_code/static/js/controllers/chat-controller.js +4252 -0
  219. painapple_code/static/js/controllers/dialog-controller.js +217 -0
  220. painapple_code/static/js/controllers/tab-controller.js +1828 -0
  221. painapple_code/static/js/controllers/thinking-controller.js +915 -0
  222. painapple_code/static/js/diff-utils.js +486 -0
  223. painapple_code/static/js/drafts-pill.js +95 -0
  224. painapple_code/static/js/editor-view.js +815 -0
  225. painapple_code/static/js/effort-settings.js +430 -0
  226. painapple_code/static/js/feature-triage.js +811 -0
  227. painapple_code/static/js/file-autocomplete.js +516 -0
  228. painapple_code/static/js/file-tabs.js +123 -0
  229. painapple_code/static/js/gestures.js +448 -0
  230. painapple_code/static/js/grid-switcher.js +334 -0
  231. painapple_code/static/js/input-handler.js +1472 -0
  232. painapple_code/static/js/keyboard-bar.js +495 -0
  233. painapple_code/static/js/layout-switcher.js +109 -0
  234. painapple_code/static/js/linkify-utils.js +200 -0
  235. painapple_code/static/js/login.js +141 -0
  236. painapple_code/static/js/open-dialog.js +879 -0
  237. painapple_code/static/js/orphan-terminals.js +373 -0
  238. painapple_code/static/js/path-utils.js +179 -0
  239. painapple_code/static/js/perf-marks.js +102 -0
  240. painapple_code/static/js/permission-settings.js +475 -0
  241. painapple_code/static/js/pointer-input.js +59 -0
  242. painapple_code/static/js/preview/json-tree-menu.js +226 -0
  243. painapple_code/static/js/preview/json-tree-toolbar.js +291 -0
  244. painapple_code/static/js/preview/json-tree.js +457 -0
  245. painapple_code/static/js/preview/preview-breadcrumb.js +387 -0
  246. painapple_code/static/js/preview/preview-edit.js +367 -0
  247. painapple_code/static/js/preview/preview-events.js +361 -0
  248. painapple_code/static/js/preview/preview-history.js +567 -0
  249. painapple_code/static/js/preview/preview-inline-edit.js +869 -0
  250. painapple_code/static/js/preview/preview-poll.js +108 -0
  251. painapple_code/static/js/preview/preview-render.js +572 -0
  252. painapple_code/static/js/preview/preview-search.js +421 -0
  253. painapple_code/static/js/preview/preview-state.js +256 -0
  254. painapple_code/static/js/preview/preview-utils.js +251 -0
  255. painapple_code/static/js/preview-plugins/chart-plugin.js +22 -0
  256. painapple_code/static/js/preview-plugins/csv-plugin.js +188 -0
  257. painapple_code/static/js/preview-plugins/diff-plugin.js +258 -0
  258. painapple_code/static/js/preview-plugins/excalidraw-plugin.js +25 -0
  259. painapple_code/static/js/preview-plugins/html-plugin.js +104 -0
  260. painapple_code/static/js/preview-plugins/image-plugin.js +20 -0
  261. painapple_code/static/js/preview-plugins/index.js +34 -0
  262. painapple_code/static/js/preview-plugins/json-plugin.js +99 -0
  263. painapple_code/static/js/preview-plugins/jsonl-plugin.js +152 -0
  264. painapple_code/static/js/preview-plugins/markdown-plugin.js +266 -0
  265. painapple_code/static/js/preview-plugins/panzoom-plugin.js +63 -0
  266. painapple_code/static/js/preview-plugins/plugin-helpers.js +282 -0
  267. painapple_code/static/js/project-color-picker.js +110 -0
  268. painapple_code/static/js/project-colors.js +163 -0
  269. painapple_code/static/js/prompt-favorites.js +187 -0
  270. painapple_code/static/js/quick-actions-menu.js +1736 -0
  271. painapple_code/static/js/quick-actions-registry.js +1239 -0
  272. painapple_code/static/js/quick-switcher/controller.js +294 -0
  273. painapple_code/static/js/quick-switcher/fuzzy-scorer.js +123 -0
  274. painapple_code/static/js/quick-switcher/index.js +30 -0
  275. painapple_code/static/js/quick-switcher/providers/base-provider.js +51 -0
  276. painapple_code/static/js/quick-switcher/providers/command-provider.js +56 -0
  277. painapple_code/static/js/quick-switcher/providers/file-provider.js +291 -0
  278. painapple_code/static/js/quick-switcher/providers/panel-provider.js +132 -0
  279. painapple_code/static/js/quick-switcher/providers/project-provider.js +361 -0
  280. painapple_code/static/js/quick-switcher/providers/read-files-provider.js +104 -0
  281. painapple_code/static/js/quick-switcher/providers/skills-provider.js +129 -0
  282. painapple_code/static/js/quick-switcher/registry.js +69 -0
  283. painapple_code/static/js/quick-switcher/ui/item.js +54 -0
  284. painapple_code/static/js/quick-switcher/ui/picker.js +464 -0
  285. painapple_code/static/js/recent-opens.js +40 -0
  286. painapple_code/static/js/scroll-manager.js +530 -0
  287. painapple_code/static/js/scroll-state-machine.js +359 -0
  288. painapple_code/static/js/selection/action-bar.js +793 -0
  289. painapple_code/static/js/selection/index.js +15 -0
  290. painapple_code/static/js/selection/selection-handler.js +877 -0
  291. painapple_code/static/js/selection/state.js +181 -0
  292. painapple_code/static/js/session/agent-progress.js +202 -0
  293. painapple_code/static/js/session/handle-agent-message.js +481 -0
  294. painapple_code/static/js/session/handle-message.js +550 -0
  295. painapple_code/static/js/session/interactive.js +587 -0
  296. painapple_code/static/js/session/message-store.js +271 -0
  297. painapple_code/static/js/session/messages.js +253 -0
  298. painapple_code/static/js/session/persistence.js +179 -0
  299. painapple_code/static/js/session/restore.js +136 -0
  300. painapple_code/static/js/session/sync.js +333 -0
  301. painapple_code/static/js/session-container-pool.js +371 -0
  302. painapple_code/static/js/session-setup-panel.js +274 -0
  303. painapple_code/static/js/session.js +1047 -0
  304. painapple_code/static/js/shortcut-hints.js +272 -0
  305. painapple_code/static/js/shortcuts.js +1146 -0
  306. painapple_code/static/js/skills-autocomplete.js +262 -0
  307. painapple_code/static/js/snippets-autocomplete.js +738 -0
  308. painapple_code/static/js/stash-refs-view.js +83 -0
  309. painapple_code/static/js/stash-ui.js +768 -0
  310. painapple_code/static/js/stash.js +785 -0
  311. painapple_code/static/js/status-bar.js +1184 -0
  312. painapple_code/static/js/token-profile.js +274 -0
  313. painapple_code/static/js/tool-renderer-blocks.js +1626 -0
  314. painapple_code/static/js/tool-renderer-thinking.js +813 -0
  315. painapple_code/static/js/tool-renderer.js +1500 -0
  316. painapple_code/static/js/tooltips.js +197 -0
  317. painapple_code/static/js/upload-manager.js +1019 -0
  318. painapple_code/static/js/utils.js +521 -0
  319. painapple_code/static/js/welcome/api.js +363 -0
  320. painapple_code/static/js/welcome/cards.js +626 -0
  321. painapple_code/static/js/welcome/context-menu.js +585 -0
  322. painapple_code/static/js/welcome/families.js +801 -0
  323. painapple_code/static/js/welcome/preview.js +234 -0
  324. painapple_code/static/js/welcome/state.js +129 -0
  325. painapple_code/static/js/welcome.js +1874 -0
  326. painapple_code/static/js/widget-system/base-widget.js +717 -0
  327. painapple_code/static/js/widget-system/device-manager.js +178 -0
  328. painapple_code/static/js/widget-system/event-bus.js +152 -0
  329. painapple_code/static/js/widget-system/icons.js +120 -0
  330. painapple_code/static/js/widget-system/index.js +49 -0
  331. painapple_code/static/js/widget-system/init.js +54 -0
  332. painapple_code/static/js/widget-system/types/bottom-sheet.js +307 -0
  333. painapple_code/static/js/widget-system/types/floating.js +915 -0
  334. painapple_code/static/js/widget-system/types/index.js +40 -0
  335. painapple_code/static/js/widget-system/types/modal.js +147 -0
  336. painapple_code/static/js/widget-system/types/sidebar.js +158 -0
  337. painapple_code/static/js/widget-system/types/tab.js +146 -0
  338. painapple_code/static/js/widget-system/types/top-sheet.js +203 -0
  339. painapple_code/static/js/widget-system/widget-manager.js +1187 -0
  340. painapple_code/static/js/widgets/about-widget.js +260 -0
  341. painapple_code/static/js/widgets/active-sessions-widget.js +760 -0
  342. painapple_code/static/js/widgets/agents-widget.js +897 -0
  343. painapple_code/static/js/widgets/browser-widget.js +579 -0
  344. painapple_code/static/js/widgets/commands-widget.js +694 -0
  345. painapple_code/static/js/widgets/config/commit-sections.js +449 -0
  346. painapple_code/static/js/widgets/config/dir-autocomplete.js +224 -0
  347. painapple_code/static/js/widgets/config/gestures.js +161 -0
  348. painapple_code/static/js/widgets/config/models-tab.js +988 -0
  349. painapple_code/static/js/widgets/config/quick-actions-tab.js +882 -0
  350. painapple_code/static/js/widgets/config/shortcut-editor.js +587 -0
  351. painapple_code/static/js/widgets/config/state.js +517 -0
  352. painapple_code/static/js/widgets/config/system-controls.js +90 -0
  353. painapple_code/static/js/widgets/config-widget.js +1535 -0
  354. painapple_code/static/js/widgets/cost-analytics-widget.js +621 -0
  355. painapple_code/static/js/widgets/debug-widget.js +693 -0
  356. painapple_code/static/js/widgets/diff-viewer-widget.js +1420 -0
  357. painapple_code/static/js/widgets/discussion-widget.js +1107 -0
  358. painapple_code/static/js/widgets/file-explorer-widget.js +2166 -0
  359. painapple_code/static/js/widgets/file-preview-widget.js +861 -0
  360. painapple_code/static/js/widgets/git-widget.js +794 -0
  361. painapple_code/static/js/widgets/helpers-install-widget.js +720 -0
  362. painapple_code/static/js/widgets/history-explorer-widget.js +1804 -0
  363. painapple_code/static/js/widgets/image-annotate-widget.js +951 -0
  364. painapple_code/static/js/widgets/image-preview-widget.js +692 -0
  365. painapple_code/static/js/widgets/index.js +176 -0
  366. painapple_code/static/js/widgets/log-explorer-widget.js +1057 -0
  367. painapple_code/static/js/widgets/plugins-widget.js +305 -0
  368. painapple_code/static/js/widgets/prompt-explorer-widget.js +1119 -0
  369. painapple_code/static/js/widgets/search-files-widget.js +529 -0
  370. painapple_code/static/js/widgets/skills-widget.js +843 -0
  371. painapple_code/static/js/widgets/snippets-widget.js +479 -0
  372. painapple_code/static/js/widgets/sub-agents-widget.js +333 -0
  373. painapple_code/static/js/widgets/tasks-widget.js +379 -0
  374. painapple_code/static/js/widgets/terminal/connection.js +283 -0
  375. painapple_code/static/js/widgets/terminal/gestures.js +357 -0
  376. painapple_code/static/js/widgets/terminal/init.js +642 -0
  377. painapple_code/static/js/widgets/terminal/link-providers.js +532 -0
  378. painapple_code/static/js/widgets/terminal/osc52.js +213 -0
  379. painapple_code/static/js/widgets/terminal/render.js +159 -0
  380. painapple_code/static/js/widgets/terminal/size.js +54 -0
  381. painapple_code/static/js/widgets/terminal/state.js +211 -0
  382. painapple_code/static/js/widgets/terminal/wrap-utils.js +101 -0
  383. painapple_code/static/js/widgets/terminal-widget.js +793 -0
  384. painapple_code/static/js/widgets/uploads-widget.js +461 -0
  385. painapple_code/static/js/widgets/zen-widget.js +1001 -0
  386. painapple_code/static/login.html +51 -0
  387. painapple_code/static/manifest.json +73 -0
  388. painapple_code/static/sw.js +293 -0
  389. painapple_code/static/vendor/LICENSES.txt +769 -0
  390. painapple_code/static/vendor/README.md +103 -0
  391. painapple_code/static/vendor/codemirror.js +35 -0
  392. painapple_code/static/vendor/codemirror.js.LEGAL.txt +304 -0
  393. painapple_code/static/vendor/github-markdown-dark.min.css +1124 -0
  394. painapple_code/static/vendor/highlight-github-dark.min.css +10 -0
  395. painapple_code/static/vendor/highlight-lang-dockerfile.min.js +8 -0
  396. painapple_code/static/vendor/highlight-lang-nginx.min.js +21 -0
  397. painapple_code/static/vendor/highlight-lang-properties.min.js +10 -0
  398. painapple_code/static/vendor/highlight-lang-scala.min.js +28 -0
  399. painapple_code/static/vendor/highlight.min.js +1213 -0
  400. painapple_code/static/vendor/marked.min.js +6 -0
  401. painapple_code/static/vendor/purify.min.js +3 -0
  402. painapple_code/static/vendor/xterm-addon-fit.js +2 -0
  403. painapple_code/static/vendor/xterm.css +209 -0
  404. painapple_code/static/vendor/xterm.js +2 -0
  405. painapple_code/static/web-client.html +635 -0
  406. painapple_code/subprocess_registry.py +535 -0
  407. painapple_code/tls_cert.py +79 -0
  408. painapple_code/tools/agents/shadow-git-helper.md +400 -0
  409. painapple_code/tools/excalidraw-to-svg.js +143 -0
  410. painapple_code/tools/install-helpers.sh +148 -0
  411. painapple_code/tools/shadow-git +320 -0
  412. painapple_code/tools/shadow-query +120 -0
  413. painapple_code/tools/vegalite-to-svg.js +79 -0
  414. painapple_code/turn_query.py +766 -0
  415. painapple_code/turn_tracker.py +221 -0
  416. painapple_code/utils/__init__.py +0 -0
  417. painapple_code/utils/agent_cli.py +306 -0
  418. painapple_code/utils/chart.py +103 -0
  419. painapple_code/utils/excalidraw.py +107 -0
  420. painapple_code/utils/file_lock.py +162 -0
  421. painapple_code/utils/file_paths.py +648 -0
  422. painapple_code/utils/generate_icons.py +251 -0
  423. painapple_code/utils/proc.py +205 -0
  424. painapple_code/utils/pty_backend.py +59 -0
  425. painapple_code/utils/pty_posix.py +160 -0
  426. painapple_code/utils/pty_windows.py +245 -0
  427. painapple_code/utils/token_profiles.py +91 -0
  428. painapple_code/viewer_templates.py +657 -0
  429. painapple_code/welcome_search.py +879 -0
  430. painapple_code-1.0.0.dist-info/METADATA +292 -0
  431. painapple_code-1.0.0.dist-info/RECORD +436 -0
  432. painapple_code-1.0.0.dist-info/WHEEL +5 -0
  433. painapple_code-1.0.0.dist-info/entry_points.txt +2 -0
  434. painapple_code-1.0.0.dist-info/licenses/LICENSE +661 -0
  435. painapple_code-1.0.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +261 -0
  436. painapple_code-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1626 @@
1
+ /**
2
+ * Tool Renderer — Block-mode methods
3
+ *
4
+ * Full tool-block renderers (Bash, Read, Edit, Write, Grep, Glob, WebFetch, Task,
5
+ * Skill, TaskOutput, TaskStop, EnterPlanMode, Todo) and their helpers.
6
+ * Mixed into ToolRenderer.prototype by tool-renderer.js.
7
+ */
8
+
9
+ import S from './strings.js';
10
+ import { escapeHtml, escapeAttr, b64Attr, parseTaskUsage, formatTokensBadge, formatDuration } from './utils.js';
11
+ import { generateSmartDiff, renderSmartDiff } from './diff-utils.js';
12
+ import { parseBackgroundTaskOutput } from './background-tasks.js';
13
+ import { cleanToolError, ansiToHtml, colorizeBashLine, getLangForExt } from './tool-renderer.js';
14
+ import { MarkdownRenderer } from './components.js';
15
+ import { basename, isAbsolutePath } from './path-utils.js';
16
+
17
+ /**
18
+ * Line-wrap toggle button for monospace tool previews (Read / Write blocks).
19
+ * Shares the single chat-wide wrap preference with the markdown code blocks —
20
+ * the `.wrap-toggle` marker is caught by the document-level delegate in
21
+ * components.js, which flips `.wrapped` on every wrappable block at once.
22
+ * `actionClass` is the block's own button class so it inherits sibling styling.
23
+ */
24
+ function wrapToggleBtn(actionClass) {
25
+ const active = MarkdownRenderer.getCodeWrapPref();
26
+ return `<button class="${actionClass} wrap-toggle${active ? ' active' : ''}" data-tooltip="${S.code_block.toggle_wrap}" aria-pressed="${active}">
27
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M3 12h15a3 3 0 1 1 0 6h-4"/><polyline points="16 16 14 18 16 20"/><path d="M3 18h7"/></svg>
28
+ </button>`;
29
+ }
30
+
31
+ export const blockMethods = {
32
+ /**
33
+ * Render a colorized diff for Edit tool operations.
34
+ * Shows removed lines in red, added lines in green, with stats and file link.
35
+ * @param {object} input - Tool input with file_path, old_string, new_string
36
+ * @param {string} toolOutput - Tool output for line number parsing
37
+ * @param {string} [toolId] - Tool ID for linking to Changes panel
38
+ */
39
+ renderEditDiff(input, toolOutput, toolId = null, serverStartLine = null) {
40
+ const { file_path, old_string, new_string } = input;
41
+ if (!file_path || old_string === undefined || new_string === undefined) {
42
+ return null; // Fall back to default rendering
43
+ }
44
+
45
+ const filename = basename(file_path);
46
+ const oldLines = old_string.split('\n');
47
+ const newLines = new_string.split('\n');
48
+
49
+ // Use server-provided startLine (from structuredPatch) or fallback to client-side
50
+ // parsing. Both can fail (pending edit, failed edit, output without a snippet) —
51
+ // then we render without line numbers rather than numbering from 1.
52
+ const startLine = serverStartLine || this.parseEditLineNumber(toolOutput, new_string);
53
+ const lineNumsKnown = !!startLine;
54
+
55
+ // Generate smart diff with line matching and word-level highlighting
56
+ const diffEntries = generateSmartDiff(oldLines, newLines, startLine || 1, escapeHtml, {
57
+ contextLines: 2, // Show 2 lines of context around changes
58
+ collapseThreshold: 5 // Collapse runs of 5+ unchanged lines
59
+ });
60
+
61
+ // Collapse tall diffs to the first rows, like Write/Read blocks
62
+ const MAX_VISIBLE_ROWS = 10;
63
+ const totalRows = diffEntries.reduce((n, e) => n + (e.type === 'modified' ? 2 : 1), 0);
64
+ const needsExpand = totalRows > MAX_VISIBLE_ROWS;
65
+ const hiddenRows = needsExpand ? totalRows - MAX_VISIBLE_ROWS : 0;
66
+ const diffLines = renderSmartDiff(diffEntries, { hideAfter: needsExpand ? MAX_VISIBLE_ROWS : Infinity });
67
+ const expandBtn = needsExpand
68
+ ? `<button class="diff-expand-btn" data-act="toggle-expand" data-block=".edit-diff" data-more-label="▼ ${hiddenRows} more lines">▼ ${hiddenRows} more lines</button>`
69
+ : '';
70
+
71
+ // Calculate stats from actual diff entries (not raw line counts)
72
+ // - 'added': lines that exist only in new_string
73
+ // - 'removed': lines that exist only in old_string
74
+ // - 'modified': lines that changed (counts as both +1 and -1)
75
+ const addedCount = diffEntries.filter(e => e.type === 'added').length;
76
+ const removedCount = diffEntries.filter(e => e.type === 'removed').length;
77
+ const modifiedCount = diffEntries.filter(e => e.type === 'modified').length;
78
+ const statsText = `<span class="diff-stat-added">+${addedCount + modifiedCount}</span> <span class="diff-stat-removed">-${removedCount + modifiedCount}</span>`;
79
+
80
+ // Calculate line range for preview highlighting (only when the position is real)
81
+ const previewOpts = lineNumsKnown
82
+ ? JSON.stringify({ start: startLine, end: startLine + newLines.length - 1 })
83
+ : '{}';
84
+
85
+ // Cache edit data for side-by-side viewer (avoids large strings in onclick)
86
+ const sbsCacheId = window.DiffViewerWidget?.cacheEditData?.(file_path, old_string, new_string, startLine || 1) || '';
87
+
88
+ return `<div class="edit-diff${lineNumsKnown ? '' : ' line-nums-unknown'}${MarkdownRenderer.getCodeWrapPref() ? ' wrapped' : ''}">
89
+ <div class="edit-diff-header">
90
+ <svg class="edit-diff-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
91
+ <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
92
+ <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
93
+ </svg>
94
+ ${this.fileLink(file_path, filename, 'edit-diff-path')}
95
+ <span class="edit-diff-stats">${statsText}</span>
96
+ <div class="edit-actions">
97
+ ${wrapToggleBtn('edit-action')}
98
+ <button class="edit-action" data-act="preview-file" data-file="${escapeAttr(file_path)}" data-preview-opts="${escapeAttr(previewOpts)}" data-tooltip="Preview">
99
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
100
+ </button>
101
+ <button class="edit-action" data-act="open-in-editor" data-file="${escapeAttr(file_path)}" data-tooltip="Open in editor">
102
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>
103
+ </button>
104
+ ${sbsCacheId ? `<button class="edit-action" data-act="open-diff-cache" data-cache-id="${escapeAttr(sbsCacheId)}" data-tooltip="Side-by-side">
105
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="8" height="18" rx="1"/><rect x="13" y="3" width="8" height="18" rx="1"/></svg>
106
+ </button>` : ''}
107
+ </div>
108
+ </div>
109
+ <div class="edit-diff-content">${diffLines}</div>
110
+ ${expandBtn}
111
+ </div>`;
112
+ },
113
+
114
+ /**
115
+ * Parse line number from Edit tool output.
116
+ * Claude returns format like: " 1234→ content here" or "1234\tcontent here"
117
+ */
118
+ /**
119
+ * Render a Read tool block for image files with inline preview
120
+ */
121
+ renderReadImageBlock(msg) {
122
+ const filePath = msg.toolInput?.file_path || '';
123
+ const filename = basename(filePath) || '(unknown)';
124
+ const hasOutput = msg.toolOutput || msg.toolError;
125
+ const isCompleted = msg.toolCompleted || hasOutput;
126
+ const imgUrl = `/api/file-raw?path=${encodeURIComponent(filePath)}`;
127
+
128
+ if (!isCompleted) {
129
+ return `<div class="tool-block read-block read-image" id="tool-${msg.id}">
130
+ <div class="read-header">
131
+ <svg class="read-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>
132
+ ${this.fileLink(filePath, filename, 'read-filename')}
133
+ <span class="read-status-loading">reading...</span>
134
+ </div>
135
+ </div>`;
136
+ }
137
+
138
+ return `<div class="tool-block read-block read-image" id="tool-${msg.id}">
139
+ <div class="read-header">
140
+ <svg class="read-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>
141
+ ${this.fileLink(filePath, filename, 'read-filename')}
142
+ <span class="read-lang">image</span>
143
+ <div class="read-actions">
144
+ <button class="read-action" data-act="preview-file" data-file="${escapeAttr(filePath)}" data-tooltip="Preview">
145
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
146
+ </button>
147
+ </div>
148
+ </div>
149
+ <div class="read-content read-image-content">
150
+ <img src="${imgUrl}" alt="${escapeHtml(filename)}" loading="lazy" />
151
+ </div>
152
+ </div>`;
153
+ },
154
+
155
+ /**
156
+ * Render a Read tool block for code/text files with syntax highlighting
157
+ */
158
+ renderReadBlock(msg, { defaultExpanded = false } = {}) {
159
+ const filePath = msg.toolInput?.file_path || '';
160
+ const filename = basename(filePath) || '(unknown)';
161
+ const hasOutput = msg.toolOutput || msg.toolError;
162
+ const isCompleted = msg.toolCompleted || hasOutput;
163
+
164
+ // Check for sibling tool error
165
+ const readCleaned = cleanToolError(msg.toolOutput || msg.toolError || '');
166
+ if (readCleaned.isSiblingError) {
167
+ return this._renderSiblingErrorBlock(msg, 'read', escapeHtml(filename));
168
+ }
169
+
170
+ // Detect language from file extension
171
+ const ext = filename.split('.').pop()?.toLowerCase() || '';
172
+ const { hlLang, displayLang } = getLangForExt(ext, filename);
173
+ const isImage = hlLang === 'image';
174
+ const lowerFn = filename.toLowerCase();
175
+ const isExcalidraw = lowerFn.endsWith('.excalidraw') || lowerFn.endsWith('.excalidraw.md');
176
+
177
+ // Image icon SVG
178
+ const iconSvg = isImage
179
+ ? '<svg class="read-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>'
180
+ : '<svg class="read-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>';
181
+
182
+ // Loading state
183
+ if (!isCompleted) {
184
+ return `<div class="tool-block read-block read-loading" id="tool-${msg.id}">
185
+ <div class="read-header">
186
+ ${iconSvg}
187
+ ${this.fileLink(filePath, filename, 'read-filename')}
188
+ <span class="read-status-loading">reading...</span>
189
+ </div>
190
+ </div>`;
191
+ }
192
+
193
+ // Image file — show inline thumbnail instead of code lines
194
+ if (isImage) {
195
+ const rawUrl = `/api/file-raw?path=${encodeURIComponent(filePath)}`;
196
+ return `<div class="tool-block read-block read-image" id="tool-${msg.id}">
197
+ <div class="read-header">
198
+ ${iconSvg}
199
+ ${this.fileLink(filePath, filename, 'read-filename')}
200
+ <span class="read-lang">${displayLang}</span>
201
+ <div class="read-actions">
202
+ <button class="read-action" data-act="preview-file" data-file="${escapeAttr(filePath)}" data-tooltip="Preview">
203
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
204
+ </button>
205
+ </div>
206
+ </div>
207
+ <div class="read-content read-image-content">
208
+ <img src="${rawUrl}" alt="${escapeHtml(filename)}" loading="lazy" />
209
+ </div>
210
+ </div>`;
211
+ }
212
+
213
+ // Excalidraw file — show rendered SVG thumbnail via /api/file-raw
214
+ if (isExcalidraw) {
215
+ const rawUrl = `/api/file-raw?path=${encodeURIComponent(filePath)}&dark=true`;
216
+ return `<div class="tool-block read-block read-excalidraw" id="tool-${msg.id}" data-file-path="${escapeAttr(filePath)}">
217
+ <div class="read-header">
218
+ ${iconSvg}
219
+ ${this.fileLink(filePath, filename, 'read-filename')}
220
+ <span class="read-lang">excalidraw</span>
221
+ <div class="read-actions">
222
+ <button class="read-action" data-act="preview-file" data-file="${escapeAttr(filePath)}" data-tooltip="Preview">
223
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
224
+ </button>
225
+ </div>
226
+ </div>
227
+ <div class="read-content read-excalidraw-content">
228
+ <div class="read-excalidraw-loading">
229
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
230
+ <path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
231
+ </svg>
232
+ Rendering diagram...
233
+ </div>
234
+ <div class="read-excalidraw-svg" data-src="${rawUrl}" style="display:none"></div>
235
+ </div>
236
+ </div>`;
237
+ }
238
+
239
+ // Parse the Read output to extract lines
240
+ const { lines, isTruncated, firstLine, lastLine } = this.parseReadOutput(msg.toolOutput || '');
241
+
242
+ // Compact line range display
243
+ let lineRange = '';
244
+ const totalLines = lines.length;
245
+ if (firstLine && lastLine) {
246
+ lineRange = firstLine === lastLine ? `:${firstLine}` : `:${firstLine}-${lastLine}`;
247
+ }
248
+
249
+ // Max 8 lines shown by default, rest collapsed
250
+ const MAX_VISIBLE = 8;
251
+ const needsExpand = totalLines > MAX_VISIBLE;
252
+ const hiddenCount = totalLines - MAX_VISIBLE;
253
+
254
+ // Build code content with syntax highlighting
255
+ const codeLines = lines.map(({ num, content }, idx) => {
256
+ let highlighted;
257
+ if (window.hljs && hlLang !== 'plaintext') {
258
+ try {
259
+ highlighted = window.hljs.highlight(content || ' ', { language: hlLang, ignoreIllegals: true }).value;
260
+ } catch {
261
+ highlighted = escapeHtml(content);
262
+ }
263
+ } else {
264
+ highlighted = escapeHtml(content);
265
+ }
266
+ const hidden = needsExpand && idx >= MAX_VISIBLE ? ' read-line-hidden' : '';
267
+ return `<div class="read-line${hidden}" data-line="${num}"><span class="read-line-num">${num}</span><span class="read-line-content">${highlighted}</span></div>`;
268
+ }).join('');
269
+
270
+ // Build preview options for line range
271
+ const previewOpts = firstLine && lastLine && firstLine !== lastLine
272
+ ? JSON.stringify({ start: firstLine, end: lastLine })
273
+ : firstLine ? JSON.stringify({ line: firstLine }) : '{}';
274
+
275
+ // Expand button if needed
276
+ const expandBtn = needsExpand
277
+ ? `<button class="read-expand-btn" data-act="toggle-expand" data-block=".read-block" data-more-label="▼ ${hiddenCount} more lines">${defaultExpanded ? '▲ Collapse' : `▼ ${hiddenCount} more lines`}</button>`
278
+ : '';
279
+
280
+ const expandedClass = defaultExpanded ? ' expanded' : '';
281
+ const wrappedClass = MarkdownRenderer.getCodeWrapPref() ? ' wrapped' : '';
282
+ return `<div class="tool-block read-block${expandedClass}${wrappedClass}" id="tool-${msg.id}">
283
+ <div class="read-header">
284
+ ${iconSvg}
285
+ ${this.fileLink(filePath, filename, 'read-filename')}
286
+ <span class="read-line-info">${lineRange}</span>
287
+ <span class="read-line-count">${totalLines}</span>
288
+ <span class="read-lang">${displayLang}</span>
289
+ <div class="read-actions">
290
+ <button class="read-action" data-act="preview-file" data-file="${escapeAttr(filePath)}" data-preview-opts="${escapeAttr(previewOpts)}" data-tooltip="Preview">
291
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
292
+ </button>
293
+ <button class="read-action" data-act="open-in-editor" data-file="${escapeAttr(filePath)}" data-tooltip="Open in editor">
294
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>
295
+ </button>
296
+ ${wrapToggleBtn('read-action')}
297
+ <button class="read-action" data-act="copy-b64" data-copy="${b64Attr(lines.map(l => l.content).join('\n'))}" data-tooltip="Copy">
298
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
299
+ </button>
300
+ </div>
301
+ </div>
302
+ <div class="read-content">
303
+ <pre class="read-code" data-language="${hlLang}"><code class="language-${hlLang}">${codeLines}</code></pre>
304
+ ${expandBtn}
305
+ </div>
306
+ </div>`;
307
+ },
308
+
309
+ /**
310
+ * Render a compact Bash/Shell tool block
311
+ * Design: Clickable command copies, expandable for long/multiline commands
312
+ */
313
+ renderBashBlock(msg, { defaultExpanded = false } = {}) {
314
+ const command = msg.toolInput.command || '';
315
+ const output = typeof msg.toolOutput === 'string' ? msg.toolOutput : (msg.toolOutput != null ? String(msg.toolOutput) : '');
316
+ const hasOutput = msg.toolOutput || msg.toolError;
317
+ const isCompleted = msg.toolCompleted || hasOutput;
318
+
319
+ // Clean tool_use_error XML from both error and output fields
320
+ const cleanedError = cleanToolError(msg.toolError);
321
+ const cleanedOutput = cleanToolError(output);
322
+ const isError = !!msg.toolError || cleanedOutput.isSiblingError;
323
+ const siblingError = cleanedError.isSiblingError || cleanedOutput.isSiblingError;
324
+
325
+ // Detect background task
326
+ const bgTask = parseBackgroundTaskOutput(output);
327
+ if (bgTask || msg.toolInput?.run_in_background) {
328
+ return this.renderBackgroundTaskCard(msg, bgTask);
329
+ }
330
+
331
+ // Check if command needs expansion (long or multiline)
332
+ const isMultiline = command.includes('\n');
333
+ const isLongCommand = command.length > 60 || isMultiline;
334
+
335
+ // Command and output are model/tool text and go into a `data-` attribute
336
+ // as base64, NOT interpolated into the handler.
337
+ //
338
+ // This previously used JSON.stringify(x).replace(/"/g, '&quot;') and was
339
+ // an XSS: that replace maps the JSON string's own delimiters AND any
340
+ // literal `&quot;` in the payload to the same sequence, and the HTML
341
+ // parser decodes every `&quot;` back to `"` before the JS is compiled —
342
+ // so a payload containing `&quot;` closed the string early and the rest
343
+ // ran as script. Tool *output* reaches this path, so a `cat` of an
344
+ // attacker-controlled file was enough. Base64's alphabet has no quote,
345
+ // `&` or `<`, so it cannot break out of an attribute at all.
346
+ const cmdEncoded = b64Attr(command);
347
+ const outputEncoded = b64Attr(output);
348
+
349
+ // Parse output lines
350
+ const outputLines = output.split('\n');
351
+ const totalLines = outputLines.length;
352
+ const MAX_VISIBLE = 8;
353
+ const needsExpand = totalLines > MAX_VISIBLE;
354
+ const hiddenCount = totalLines - MAX_VISIBLE;
355
+
356
+ // Check if output has ANSI codes
357
+ const hasAnsi = output.includes('\x1b[');
358
+
359
+ // Build verifiedFiles map from fileLinks for client-side scanning
360
+ // (server positions don't work after colorization adds <span> tags)
361
+ const verifiedFiles = {};
362
+ if (msg.fileLinks && Array.isArray(msg.fileLinks)) {
363
+ for (const link of msg.fileLinks) {
364
+ if (link.path && link.resolved) {
365
+ verifiedFiles[link.path] = link.resolved;
366
+ }
367
+ }
368
+ }
369
+ // Fallback: use message-level verifiedFiles when fileLinks is absent
370
+ // (e.g., messages loaded from server API where fileLinks isn't persisted)
371
+ if (Object.keys(verifiedFiles).length === 0 && msg.verifiedFiles) {
372
+ Object.assign(verifiedFiles, msg.verifiedFiles);
373
+ }
374
+
375
+ // Build output with line hiding and colorization
376
+ // Track position in original output to adjust fileLinks per-line
377
+ let outputPos = 0;
378
+ const outputHtml = outputLines.map((line, idx) => {
379
+ const hidden = needsExpand && idx >= MAX_VISIBLE ? ' bash-line-hidden' : '';
380
+ const lineStart = outputPos;
381
+ const lineEnd = outputPos + line.length;
382
+ outputPos = lineEnd + 1; // +1 for newline
383
+
384
+ let lineHtml;
385
+ if (hasAnsi) {
386
+ // Convert ANSI codes to HTML
387
+ lineHtml = ansiToHtml(line) || escapeHtml(line);
388
+ } else {
389
+ // Apply pattern-based colorization
390
+ const escaped = escapeHtml(line);
391
+ lineHtml = colorizeBashLine(line, escaped);
392
+ }
393
+
394
+ // Apply URL and file path linkification
395
+ // Use client-side scanning with verifiedFiles (position-based doesn't work after colorization)
396
+ lineHtml = this.linkifyToolOutput(lineHtml, null, verifiedFiles);
397
+
398
+ return `<div class="bash-line${hidden}">${lineHtml}</div>`;
399
+ }).join('');
400
+
401
+ const expandBtn = needsExpand
402
+ ? `<button class="bash-expand-btn" data-act="toggle-expand" data-block=".bash-block" data-more-label="▼ ${hiddenCount} more lines">${defaultExpanded ? '▲ Collapse' : `▼ ${hiddenCount} more lines`}</button>`
403
+ : '';
404
+
405
+ // Copy command button (inside command wrapper, shows on hover)
406
+ const copyCmdBtn = `<button class="bash-copy-cmd" data-act="copy-b64" data-copy="${cmdEncoded}" data-label-sel=".copy-label" data-tooltip="Copy command">
407
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
408
+ <span class="copy-label">Copy</span>
409
+ </button>`;
410
+
411
+ // Copy output button (inside output area with label)
412
+ const copyOutputBtn = `<button class="bash-copy-output" data-act="copy-b64" data-copy="${outputEncoded}" data-label-sel="span">
413
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
414
+ <span>Copy output</span>
415
+ </button>`;
416
+
417
+ // Loading state
418
+ if (!isCompleted) {
419
+ return `<div class="tool-block bash-block bash-loading${isLongCommand ? ' has-long-cmd' : ''}" id="tool-${msg.id}">
420
+ <div class="bash-header">
421
+ <div class="bash-cmd-wrapper"${isLongCommand ? ` data-act="toggle-class" data-block=".bash-block" data-cls="cmd-expanded"` : ''}>
422
+ <code class="bash-cmd">${escapeHtml(command)}</code>
423
+ ${copyCmdBtn}
424
+ </div>
425
+ <span class="bash-status-loading">${S.tool_renderer.status.running}</span>
426
+ </div>
427
+ </div>`;
428
+ }
429
+
430
+ const expandedClass = defaultExpanded ? ' expanded' : '';
431
+ return `<div class="tool-block bash-block${isError ? ' bash-error' : ''}${isLongCommand ? ' has-long-cmd' : ''}${expandedClass}" id="tool-${msg.id}">
432
+ <div class="bash-header">
433
+ <div class="bash-cmd-wrapper"${isLongCommand ? ` data-act="toggle-class" data-block=".bash-block" data-cls="cmd-expanded"` : ''}>
434
+ <code class="bash-cmd">${escapeHtml(command)}</code>
435
+ ${copyCmdBtn}
436
+ </div>
437
+ ${totalLines > 0 ? `<span class="bash-line-count">${totalLines}</span>` : ''}
438
+ </div>
439
+ ${siblingError
440
+ ? `<div class="bash-output bash-output-sibling-error"><span class="bash-sibling-label">${S.tool_renderer.status.skipped}</span> a parallel tool call failed</div>`
441
+ : (output || isError ? `<div class="bash-output${isError ? ' bash-output-error' : ''}">${copyOutputBtn}${isError ? escapeHtml(cleanedError.text) : outputHtml}${expandBtn}</div>` : '')}
442
+ </div>`;
443
+ },
444
+
445
+ /**
446
+ * Render a compact WebFetch/WebSearch tool block.
447
+ * Header: icon + domain/query + prompt preview + copy button
448
+ * Body: markdown-rendered response content
449
+ */
450
+ renderWebFetchBlock(msg, { defaultExpanded = false } = {}) {
451
+ const isSearch = msg.toolName === 'WebSearch';
452
+ const input = msg.toolInput || {};
453
+ const output = typeof msg.toolOutput === 'string' ? msg.toolOutput : (msg.toolOutput != null ? String(msg.toolOutput) : '');
454
+ const hasOutput = msg.toolOutput || msg.toolError;
455
+ const isCompleted = msg.toolCompleted || hasOutput;
456
+
457
+ // Clean tool errors
458
+ const cleanedError = cleanToolError(msg.toolError);
459
+ const cleanedOutput = cleanToolError(output);
460
+ const isError = !!msg.toolError || cleanedOutput.isSiblingError;
461
+ const siblingError = cleanedError.isSiblingError || cleanedOutput.isSiblingError;
462
+
463
+ // Extract display info
464
+ let domain = '';
465
+ let fullUrl = '';
466
+ if (isSearch) {
467
+ domain = input.query || '';
468
+ if (domain.length > 60) domain = domain.slice(0, 57) + '...';
469
+ } else {
470
+ fullUrl = input.url || '';
471
+ try { domain = new URL(fullUrl).hostname; } catch { domain = fullUrl; }
472
+ }
473
+
474
+ // Prompt preview (truncated)
475
+ const prompt = input.prompt || '';
476
+ const promptPreview = prompt.length > 80 ? prompt.slice(0, 77) + '...' : prompt;
477
+
478
+ // Icons
479
+ const iconSvg = isSearch
480
+ ? '<circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>'
481
+ : '<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>';
482
+
483
+ // Copy output button
484
+ // Base64 into a data- attribute, never interpolated into the handler
485
+ // (this is WebFetch/WebSearch output — remote, attacker-influenced).
486
+ const outputEncoded = b64Attr(output);
487
+ const copyOutputBtn = output ? `<button class="bash-copy-output" data-act="copy-b64" data-copy="${outputEncoded}" data-label-sel="span">
488
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
489
+ <span>Copy</span>
490
+ </button>` : '';
491
+
492
+ // Loading state
493
+ if (!isCompleted) {
494
+ return `<div class="tool-block webfetch-block webfetch-loading" id="tool-${msg.id}">
495
+ <div class="webfetch-header">
496
+ <span class="webfetch-icon">
497
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">${iconSvg}</svg>
498
+ </span>
499
+ <span class="webfetch-domain">${escapeHtml(domain)}</span>
500
+ ${promptPreview ? `<span class="webfetch-prompt">${escapeHtml(promptPreview)}</span>` : ''}
501
+ <span class="webfetch-status-loading">${isSearch ? 'Searching...' : 'Fetching...'}</span>
502
+ </div>
503
+ </div>`;
504
+ }
505
+
506
+ // Parse output lines early (needed for both body and header line count)
507
+ const outputLines = output ? output.split('\n') : [];
508
+ const totalLines = outputLines.length;
509
+
510
+ // Build output content
511
+ let outputHtml = '';
512
+ if (siblingError) {
513
+ outputHtml = `<div class="webfetch-output"><span class="bash-sibling-label">${S.tool_renderer.status.skipped}</span> a parallel tool call failed</div>`;
514
+ } else if (isError) {
515
+ outputHtml = `<div class="webfetch-output webfetch-output-error">${escapeHtml(cleanedError.text)}</div>`;
516
+ } else if (output) {
517
+ const MAX_VISIBLE = 12;
518
+ const needsExpand = totalLines > MAX_VISIBLE;
519
+ const hiddenCount = totalLines - MAX_VISIBLE;
520
+
521
+ const linesHtml = outputLines.map((line, idx) => {
522
+ const hidden = needsExpand && idx >= MAX_VISIBLE ? ' webfetch-line-hidden' : '';
523
+ const escaped = escapeHtml(line);
524
+ // Linkify URLs in output
525
+ const linkified = this.linkifyToolOutput(escaped, null, {});
526
+ return `<div class="webfetch-line${hidden}">${linkified}</div>`;
527
+ }).join('');
528
+
529
+ const expandBtn = needsExpand
530
+ ? `<button class="webfetch-expand-btn" data-act="toggle-expand" data-block=".webfetch-block" data-more-label="▼ ${hiddenCount} more lines">${defaultExpanded ? '▲ Collapse' : `▼ ${hiddenCount} more lines`}</button>`
531
+ : '';
532
+
533
+ outputHtml = `<div class="webfetch-output">${copyOutputBtn}${linesHtml}${expandBtn}</div>`;
534
+ }
535
+
536
+ // Domain display - clickable link for WebFetch, plain text for WebSearch
537
+ const domainDisplay = isSearch
538
+ ? `<span class="webfetch-domain">${escapeHtml(domain)}</span>`
539
+ : `<a class="webfetch-domain" href="${escapeAttr(MarkdownRenderer.sanitizeHref(fullUrl))}" target="_blank" rel="noopener">${escapeHtml(domain)}</a>`;
540
+
541
+ const expandedClass = defaultExpanded ? ' expanded' : '';
542
+ return `<div class="tool-block webfetch-block${isSearch ? ' websearch-block' : ''}${isError ? ' webfetch-error' : ''}${expandedClass}" id="tool-${msg.id}">
543
+ <div class="webfetch-header">
544
+ <span class="webfetch-icon">
545
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">${iconSvg}</svg>
546
+ </span>
547
+ ${domainDisplay}
548
+ ${promptPreview ? `<span class="webfetch-prompt">${escapeHtml(promptPreview)}</span>` : ''}
549
+ ${totalLines > 0 ? `<span class="webfetch-line-count">${totalLines}</span>` : ''}
550
+ </div>
551
+ ${outputHtml}
552
+ </div>`;
553
+ },
554
+
555
+ /**
556
+ * Render a background task inline card with live output preview.
557
+ * Replaces the default "Command running in background..." text.
558
+ */
559
+ renderBackgroundTaskCard(msg, bgTask) {
560
+ const command = msg.toolInput?.command || '';
561
+ const taskId = bgTask?.taskId || '';
562
+ const isLongCommand = command.length > 60 || command.includes('\n');
563
+
564
+ // Display command compactly (last segment after &&)
565
+ const cmdDisplay = command.includes('&&')
566
+ ? command.split('&&').pop().trim()
567
+ : command;
568
+
569
+ return `<div class="tool-block bash-block bg-task-card${isLongCommand ? ' has-long-cmd' : ''}" id="tool-${msg.id}" data-task-id="${escapeHtml(taskId)}">
570
+ <div class="bash-header bg-task-header">
571
+ <span class="bg-task-icon">
572
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
573
+ <circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>
574
+ </svg>
575
+ </span>
576
+ <div class="bash-cmd-wrapper"${isLongCommand ? ` data-act="toggle-class" data-block=".bg-task-card" data-cls="cmd-expanded"` : ''}>
577
+ <code class="bash-cmd">${escapeHtml(cmdDisplay)}</code>
578
+ </div>
579
+ <span class="bg-task-badge bg-task-badge-running" id="bg-task-${escapeHtml(taskId)}-badge">
580
+ <span class="bg-task-pulse"></span>
581
+ Running
582
+ </span>
583
+ </div>
584
+ <div class="bg-task-output" id="bg-task-${escapeHtml(taskId)}-output">
585
+ <div class="bg-task-loading">Waiting for output...</div>
586
+ </div>
587
+ <div class="bg-task-actions">
588
+ <span class="bg-task-id" data-tooltip="Task ID">${escapeHtml(taskId)}</span>
589
+ <button class="bg-task-btn" data-act="open-bg-task" data-task-id="${escapeAttr(taskId)}">
590
+ View Full Output
591
+ </button>
592
+ </div>
593
+ </div>`;
594
+ },
595
+
596
+ /**
597
+ * Render a compact Grep tool block
598
+ */
599
+ renderGrepBlock(msg, { defaultExpanded = false } = {}) {
600
+ const pattern = msg.toolInput.pattern || '';
601
+ const path = msg.toolInput.path || '.';
602
+ const output = typeof msg.toolOutput === 'string' ? msg.toolOutput : (msg.toolOutput != null ? String(msg.toolOutput) : '');
603
+ const hasOutput = msg.toolOutput || msg.toolError;
604
+ const isCompleted = msg.toolCompleted || hasOutput;
605
+
606
+ // Check for sibling tool error
607
+ const grepCleaned = cleanToolError(output || msg.toolError || '');
608
+ if (grepCleaned.isSiblingError) {
609
+ return this._renderSiblingErrorBlock(msg, 'grep', `/${escapeHtml(pattern.length > 40 ? pattern.slice(0, 37) + '...' : pattern)}/`);
610
+ }
611
+
612
+ // Build verifiedFiles map from fileLinks for click handling
613
+ const verifiedFiles = {};
614
+ if (msg.fileLinks && Array.isArray(msg.fileLinks)) {
615
+ for (const link of msg.fileLinks) {
616
+ if (link.path && link.resolved) {
617
+ verifiedFiles[link.path] = link.resolved;
618
+ }
619
+ }
620
+ }
621
+ if (Object.keys(verifiedFiles).length === 0 && msg.verifiedFiles) {
622
+ Object.assign(verifiedFiles, msg.verifiedFiles);
623
+ }
624
+
625
+ // Helper to make a file path clickable
626
+ const makeFileLink = (filePath, displayName, lineNum = null) => {
627
+ const resolvedPath = verifiedFiles[filePath] || filePath;
628
+ // Path rides in a data- attribute and is read back via dataset —
629
+ // never interpolated into the handler. The old
630
+ // `resolvedPath.replace(/'/g, "\\'")` escaped ONLY apostrophes, so a
631
+ // filename containing `"` terminated the inline handler attribute
632
+ // itself and could inject siblings (and a trailing `\` defeated
633
+ // the escape). Mirrors the reference impl in tool-renderer.js.
634
+ const lineOpts = lineNum ? JSON.stringify({ scrollToLine: lineNum, flash: true }) : '{}';
635
+ return `<a href="#" class="file-path-link" data-act="open-file-link" data-file="${escapeAttr(resolvedPath)}" data-line-opts="${escapeAttr(lineOpts)}" data-tooltip="${escapeHtml(resolvedPath)}">${escapeHtml(displayName)}</a>`;
636
+ };
637
+
638
+ // Parse grep results - filter out summary/metadata lines
639
+ const results = output.split('\n').filter(l => {
640
+ const trimmed = l.trim();
641
+ if (!trimmed) return false;
642
+ // Filter out summary lines
643
+ if (/^Found \d+ files?$/i.test(trimmed)) return false;
644
+ if (/^No matches found$/i.test(trimmed)) return false;
645
+ // Filter out pagination metadata from Claude's Grep tool
646
+ if (/^\[Showing results with pagination/i.test(trimmed)) return false;
647
+ return true;
648
+ });
649
+ const totalMatches = results.length;
650
+ const MAX_VISIBLE = 10;
651
+ const needsExpand = totalMatches > MAX_VISIBLE;
652
+ const hiddenCount = totalMatches - MAX_VISIBLE;
653
+
654
+ // Build results list with file links
655
+ const resultsHtml = results.map((line, idx) => {
656
+ const hidden = needsExpand && idx >= MAX_VISIBLE ? ' grep-result-hidden' : '';
657
+
658
+ // Try to extract file:line:content format (standard grep -n output)
659
+ const fileLineMatch = line.match(/^([^:]+):(\d+):(.*)$/);
660
+ if (fileLineMatch) {
661
+ const [, file, lineNum, content] = fileLineMatch;
662
+ const displayName = basename(file);
663
+ return `<div class="grep-result${hidden}">
664
+ <span class="grep-file">${makeFileLink(file, displayName, parseInt(lineNum))}</span>
665
+ <span class="grep-linenum">:${lineNum}</span>
666
+ <span class="grep-content">${escapeHtml(content.slice(0, 80))}</span>
667
+ </div>`;
668
+ }
669
+
670
+ // Try file:line-content format (context lines from -A/-B/-C)
671
+ const fileContextMatch = line.match(/^([^:]+):(\d+)-(.*)$/);
672
+ if (fileContextMatch) {
673
+ const [, file, lineNum, content] = fileContextMatch;
674
+ const displayName = basename(file);
675
+ return `<div class="grep-result grep-context${hidden}">
676
+ <span class="grep-file">${makeFileLink(file, displayName, parseInt(lineNum))}</span>
677
+ <span class="grep-linenum">:${lineNum}</span>
678
+ <span class="grep-content">${escapeHtml(content.slice(0, 80))}</span>
679
+ </div>`;
680
+ }
681
+
682
+ // Try linenum: content format (match line in content mode)
683
+ const lineNumMatch = line.match(/^(\d+):(.*)$/);
684
+ if (lineNumMatch) {
685
+ const [, lineNum, content] = lineNumMatch;
686
+ return `<div class="grep-result${hidden}">
687
+ <span class="grep-linenum">${lineNum}:</span>
688
+ <span class="grep-content">${escapeHtml(content.slice(0, 100))}</span>
689
+ </div>`;
690
+ }
691
+
692
+ // Try linenum- content format (context line in content mode)
693
+ const contextMatch = line.match(/^(\d+)-(.*)$/);
694
+ if (contextMatch) {
695
+ const [, lineNum, content] = contextMatch;
696
+ return `<div class="grep-result grep-context${hidden}">
697
+ <span class="grep-linenum">${lineNum}-</span>
698
+ <span class="grep-content">${escapeHtml(content.slice(0, 100))}</span>
699
+ </div>`;
700
+ }
701
+
702
+ // Just a file path (files_with_matches mode) - make clickable
703
+ if (line.includes('/') || line.match(/\.\w+$/)) {
704
+ const resolvedPath = verifiedFiles[line];
705
+ if (resolvedPath) {
706
+ return `<div class="grep-result${hidden}"><span class="grep-content">${makeFileLink(line, line)}</span></div>`;
707
+ }
708
+ }
709
+
710
+ // Plain text - wrap in content span for consistent styling
711
+ return `<div class="grep-result${hidden}"><span class="grep-content">${escapeHtml(line)}</span></div>`;
712
+ }).join('');
713
+
714
+ const expandBtn = needsExpand
715
+ ? `<button class="grep-expand-btn" data-act="toggle-expand" data-block=".grep-block" data-more-label="▼ ${hiddenCount} more">${defaultExpanded ? '▲ Collapse' : `▼ ${hiddenCount} more`}</button>`
716
+ : '';
717
+
718
+ // Loading state
719
+ if (!isCompleted) {
720
+ return `<div class="tool-block grep-block grep-loading" id="tool-${msg.id}">
721
+ <div class="grep-header">
722
+ <svg class="grep-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
723
+ <circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>
724
+ </svg>
725
+ <code class="grep-pattern">/${escapeHtml(pattern)}/</code>
726
+ <span class="grep-status-loading">searching...</span>
727
+ </div>
728
+ </div>`;
729
+ }
730
+
731
+ const expandedClass = defaultExpanded ? ' expanded' : '';
732
+ return `<div class="tool-block grep-block${expandedClass}" id="tool-${msg.id}">
733
+ <div class="grep-header">
734
+ <svg class="grep-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
735
+ <circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>
736
+ </svg>
737
+ <code class="grep-pattern">/${escapeHtml(pattern.length > 40 ? pattern.slice(0, 37) + '...' : pattern)}/</code>
738
+ <span class="grep-match-count">${totalMatches} match${totalMatches !== 1 ? 'es' : ''}</span>
739
+ <div class="grep-actions">
740
+ <button class="grep-action" data-act="copy-b64" data-copy="${b64Attr(results.join('\n'))}" data-tooltip="Copy results">
741
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
742
+ </button>
743
+ </div>
744
+ </div>
745
+ ${totalMatches > 0 ? `<div class="grep-results">${resultsHtml}${expandBtn}</div>` : `<div class="grep-empty">${S.tool_renderer.empty.no_matches}</div>`}
746
+ </div>`;
747
+ },
748
+
749
+ /**
750
+ * Render a compact Glob tool block
751
+ */
752
+ renderGlobBlock(msg, { defaultExpanded = false } = {}) {
753
+ const pattern = msg.toolInput.pattern || '';
754
+ const basePath = msg.toolInput.path || '';
755
+ const output = typeof msg.toolOutput === 'string' ? msg.toolOutput : (msg.toolOutput != null ? String(msg.toolOutput) : '');
756
+ const hasOutput = msg.toolOutput || msg.toolError;
757
+ const isCompleted = msg.toolCompleted || hasOutput;
758
+
759
+ // Check for sibling tool error
760
+ const globCleaned = cleanToolError(output || msg.toolError || '');
761
+ if (globCleaned.isSiblingError) {
762
+ return this._renderSiblingErrorBlock(msg, 'glob', escapeHtml(pattern.length > 50 ? pattern.slice(0, 47) + '...' : pattern));
763
+ }
764
+
765
+ // Parse file list - keep original paths for linking
766
+ const originalFiles = output.split('\n').filter(l => l.trim());
767
+
768
+ // Build verifiedFiles map from fileLinks for click handling
769
+ const verifiedFiles = {};
770
+ if (msg.fileLinks && Array.isArray(msg.fileLinks)) {
771
+ for (const link of msg.fileLinks) {
772
+ if (link.path && link.resolved) {
773
+ verifiedFiles[link.path] = link.resolved;
774
+ }
775
+ }
776
+ }
777
+ if (Object.keys(verifiedFiles).length === 0 && msg.verifiedFiles) {
778
+ Object.assign(verifiedFiles, msg.verifiedFiles);
779
+ }
780
+
781
+ // Convert absolute paths to relative paths for display
782
+ let files = [...originalFiles];
783
+ let commonPrefix = '';
784
+ if (files.length > 0 && isAbsolutePath(files[0])) {
785
+ // Use basePath if it's absolute
786
+ if (basePath && isAbsolutePath(basePath)) {
787
+ commonPrefix = basePath.endsWith('/') ? basePath : basePath + '/';
788
+ } else {
789
+ // Find common directory prefix among all files
790
+ const firstFile = files[0];
791
+ const lastSlash = firstFile.lastIndexOf('/');
792
+ if (lastSlash > 0) {
793
+ // Start with first file's directory as potential prefix
794
+ commonPrefix = firstFile.slice(0, lastSlash + 1);
795
+ // Find shortest common prefix
796
+ for (const file of files) {
797
+ while (commonPrefix && !file.startsWith(commonPrefix)) {
798
+ const prevSlash = commonPrefix.lastIndexOf('/', commonPrefix.length - 2);
799
+ commonPrefix = prevSlash > 0 ? commonPrefix.slice(0, prevSlash + 1) : '';
800
+ }
801
+ }
802
+ }
803
+ }
804
+
805
+ // Strip the common prefix for display
806
+ if (commonPrefix) {
807
+ files = files.map(f => f.startsWith(commonPrefix) ? f.slice(commonPrefix.length) : f);
808
+ }
809
+ }
810
+
811
+ const totalFiles = files.length;
812
+ const MAX_VISIBLE = 12;
813
+ const needsExpand = totalFiles > MAX_VISIBLE;
814
+ const hiddenCount = totalFiles - MAX_VISIBLE;
815
+
816
+ // Build file list with clickable links
817
+ const filesHtml = files.map((displayFile, idx) => {
818
+ const hidden = needsExpand && idx >= MAX_VISIBLE ? ' glob-file-hidden' : '';
819
+ const isDir = displayFile.endsWith('/');
820
+ const originalPath = originalFiles[idx];
821
+ const resolvedPath = verifiedFiles[originalPath] || originalPath;
822
+
823
+ // Make files clickable (not directories)
824
+ if (!isDir && resolvedPath) {
825
+ // Path via dataset, not interpolated into the handler — see the
826
+ // note on makeFileLink above for what the old escape missed.
827
+ return `<div class="glob-file${hidden}"><a href="#" class="file-path-link" data-act="open-file-link" data-file="${escapeAttr(resolvedPath)}" data-tooltip="${escapeHtml(resolvedPath)}">${escapeHtml(displayFile)}</a></div>`;
828
+ }
829
+ return `<div class="glob-file${hidden}${isDir ? ' glob-dir' : ''}">${escapeHtml(displayFile)}</div>`;
830
+ }).join('');
831
+
832
+ const expandBtn = needsExpand
833
+ ? `<button class="glob-expand-btn" data-act="toggle-expand" data-block=".glob-block" data-more-label="▼ ${hiddenCount} more">${defaultExpanded ? '▲ Collapse' : `▼ ${hiddenCount} more`}</button>`
834
+ : '';
835
+
836
+ // Loading state
837
+ if (!isCompleted) {
838
+ return `<div class="tool-block glob-block glob-loading" id="tool-${msg.id}">
839
+ <div class="glob-header">
840
+ <svg class="glob-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
841
+ <path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>
842
+ </svg>
843
+ <code class="glob-pattern">${escapeHtml(pattern)}</code>
844
+ <span class="glob-status-loading">searching...</span>
845
+ </div>
846
+ </div>`;
847
+ }
848
+
849
+ const expandedClass = defaultExpanded ? ' expanded' : '';
850
+ return `<div class="tool-block glob-block${expandedClass}" id="tool-${msg.id}">
851
+ <div class="glob-header">
852
+ <svg class="glob-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
853
+ <path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>
854
+ </svg>
855
+ <code class="glob-pattern">${escapeHtml(pattern.length > 50 ? pattern.slice(0, 47) + '...' : pattern)}</code>
856
+ <span class="glob-file-count">${totalFiles} file${totalFiles !== 1 ? 's' : ''}</span>
857
+ <div class="glob-actions">
858
+ <button class="glob-action" data-act="copy-b64" data-copy="${b64Attr(files.join('\n'))}" data-tooltip="Copy file list">
859
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
860
+ </button>
861
+ </div>
862
+ </div>
863
+ ${totalFiles > 0 ? `<div class="glob-files">${filesHtml}${expandBtn}</div>` : `<div class="glob-empty">${S.tool_renderer.empty.no_files}</div>`}
864
+ </div>`;
865
+ },
866
+
867
+ /**
868
+ * Render a compact Write tool block
869
+ * Shows filename, line count, and status with preview/open actions
870
+ */
871
+ renderWriteBlock(msg, { defaultExpanded = false } = {}) {
872
+ const filePath = msg.toolInput?.file_path || '';
873
+ const filename = basename(filePath) || '(unknown)';
874
+ const content = msg.toolInput.content || '';
875
+ const hasOutput = msg.toolOutput || msg.toolError;
876
+ const isCompleted = msg.toolCompleted || hasOutput;
877
+
878
+ // Check for sibling tool error
879
+ const writeCleaned = cleanToolError(msg.toolOutput || msg.toolError || '');
880
+ if (writeCleaned.isSiblingError) {
881
+ return this._renderSiblingErrorBlock(msg, 'write', escapeHtml(filename));
882
+ }
883
+ const isError = !!msg.toolError;
884
+
885
+ // Detect language from file extension
886
+ const ext = filename.split('.').pop()?.toLowerCase() || '';
887
+ const { hlLang, displayLang } = getLangForExt(ext, filename);
888
+ const isImage = hlLang === 'image';
889
+
890
+ // Check if this is a Vega-Lite chart file or excalidraw diagram
891
+ const isChart = filename.toLowerCase().endsWith('.vl.json');
892
+ const lowerName = filename.toLowerCase();
893
+ const isExcalidraw = lowerName.endsWith('.excalidraw') || lowerName.endsWith('.excalidraw.md');
894
+
895
+ // Image/write icon SVG
896
+ const iconSvg = isImage
897
+ ? '<svg class="write-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>'
898
+ : '<svg class="write-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="12" y1="18" x2="12" y2="12"/><line x1="9" y1="15" x2="15" y2="15"/></svg>';
899
+
900
+ // Status indicator
901
+ const statusClass = isError ? 'write-status-error' : (isCompleted ? 'write-status-success' : 'write-status-pending');
902
+ const statusText = isError ? 'Failed' : (isCompleted ? 'Created' : 'Writing...');
903
+
904
+ // Loading state
905
+ if (!isCompleted && !content) {
906
+ return `<div class="tool-block write-block write-loading" id="tool-${msg.id}">
907
+ <div class="write-header">
908
+ ${iconSvg}
909
+ ${this.fileLink(filePath, filename, 'write-filename')}
910
+ <span class="write-status-loading">writing...</span>
911
+ </div>
912
+ </div>`;
913
+ }
914
+
915
+ // Image file — show inline thumbnail instead of code lines
916
+ if (isImage) {
917
+ const rawUrl = `/api/file-raw?path=${encodeURIComponent(filePath)}`;
918
+ return `<div class="tool-block write-block write-image${isError ? ' write-error' : ''}" id="tool-${msg.id}">
919
+ <div class="write-header">
920
+ ${iconSvg}
921
+ ${this.fileLink(filePath, filename, 'write-filename')}
922
+ <span class="write-lang">${displayLang}</span>
923
+ <span class="write-status ${statusClass}">${statusText}</span>
924
+ <div class="write-actions">
925
+ <button class="write-action" data-act="preview-file" data-file="${escapeAttr(filePath)}" data-tooltip="Preview">
926
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
927
+ </button>
928
+ </div>
929
+ </div>
930
+ <div class="write-content write-image-content">
931
+ <img src="${rawUrl}" alt="${escapeHtml(filename)}" loading="lazy" />
932
+ </div>
933
+ </div>`;
934
+ }
935
+
936
+ // Chart rendering for .vl.json files — show rendered SVG instead of raw JSON
937
+ if (isChart && content) {
938
+ const encoded = btoa(unescape(encodeURIComponent(content)));
939
+ return `<div class="tool-block write-block write-chart" id="tool-${msg.id}">
940
+ <div class="write-header">
941
+ <svg class="write-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
942
+ <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="12" y1="18" x2="12" y2="12"/><line x1="9" y1="15" x2="15" y2="15"/>
943
+ </svg>
944
+ ${this.fileLink(filePath, filename, 'write-filename')}
945
+ <span class="write-lang">${displayLang}</span>
946
+ <span class="write-status ${statusClass}">${statusText}</span>
947
+ <div class="write-actions">
948
+ <button class="write-action" data-act="preview-file" data-file="${escapeAttr(filePath)}" data-tooltip="Preview">
949
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
950
+ </button>
951
+ <button class="write-action write-chart-toggle-json" data-act="toggle-json-view" data-block=".write-chart" data-cls="show-json" data-on-label="Show chart" data-off-label="Show JSON" data-tooltip="Show JSON">
952
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
953
+ </button>
954
+ <button class="write-action" data-act="copy-b64" data-copy="${encoded}" data-tooltip="Copy JSON">
955
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
956
+ </button>
957
+ </div>
958
+ </div>
959
+ <div class="write-content write-chart-pending" data-chart-json="${encoded}">
960
+ <div class="chart-inline-loading">
961
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
962
+ <path d="M12 20V10M6 20V4M18 20v-4"/>
963
+ </svg>
964
+ Rendering chart...
965
+ </div>
966
+ </div>
967
+ <div class="write-content write-chart-json" style="display:none">
968
+ <pre class="write-code" data-language="json"><code class="language-json">${window.hljs ? window.hljs.highlight(content, { language: 'json', ignoreIllegals: true }).value : escapeHtml(content)}</code></pre>
969
+ </div>
970
+ </div>`;
971
+ }
972
+
973
+ // Excalidraw rendering — show rendered SVG instead of raw JSON
974
+ if (isExcalidraw && content) {
975
+ const encoded = btoa(unescape(encodeURIComponent(content)));
976
+ return `<div class="tool-block write-block write-excalidraw" id="tool-${msg.id}" data-file-path="${escapeAttr(filePath)}">
977
+ <div class="write-header">
978
+ <svg class="write-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
979
+ <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="12" y1="18" x2="12" y2="12"/><line x1="9" y1="15" x2="15" y2="15"/>
980
+ </svg>
981
+ ${this.fileLink(filePath, filename, 'write-filename')}
982
+ <span class="write-lang">${displayLang}</span>
983
+ <span class="write-status ${statusClass}">${statusText}</span>
984
+ <div class="write-actions">
985
+ <button class="write-action" data-act="preview-file" data-file="${escapeAttr(filePath)}" data-tooltip="Preview">
986
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
987
+ </button>
988
+ <button class="write-action write-excalidraw-toggle-json" data-act="toggle-json-view" data-block=".write-excalidraw" data-cls="show-json" data-on-label="Show diagram" data-off-label="Show JSON" data-tooltip="Show JSON">
989
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
990
+ </button>
991
+ <button class="write-action" data-act="copy-b64" data-copy="${encoded}" data-tooltip="Copy JSON">
992
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
993
+ </button>
994
+ </div>
995
+ </div>
996
+ <div class="write-content write-excalidraw-pending" data-excalidraw-json="${encoded}">
997
+ <div class="excalidraw-inline-loading">
998
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
999
+ <path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
1000
+ </svg>
1001
+ Rendering diagram...
1002
+ </div>
1003
+ </div>
1004
+ <div class="write-content write-excalidraw-json" style="display:none">
1005
+ <pre class="write-code" data-language="json"><code class="language-json">${window.hljs ? window.hljs.highlight(content, { language: 'json', ignoreIllegals: true }).value : escapeHtml(content)}</code></pre>
1006
+ </div>
1007
+ </div>`;
1008
+ }
1009
+
1010
+ // Count lines
1011
+ const lines = content.split('\n');
1012
+ const totalLines = lines.length;
1013
+
1014
+ // Max 8 lines shown by default
1015
+ const MAX_VISIBLE = 8;
1016
+ const needsExpand = totalLines > MAX_VISIBLE;
1017
+ const hiddenCount = totalLines - MAX_VISIBLE;
1018
+
1019
+ // Build code content with syntax highlighting
1020
+ const codeLines = lines.map((lineContent, idx) => {
1021
+ let highlighted;
1022
+ if (window.hljs && hlLang !== 'plaintext') {
1023
+ try {
1024
+ highlighted = window.hljs.highlight(lineContent || ' ', { language: hlLang, ignoreIllegals: true }).value;
1025
+ } catch {
1026
+ highlighted = escapeHtml(lineContent);
1027
+ }
1028
+ } else {
1029
+ highlighted = escapeHtml(lineContent);
1030
+ }
1031
+ const hidden = needsExpand && idx >= MAX_VISIBLE ? ' write-line-hidden' : '';
1032
+ return `<div class="write-line${hidden}" data-line="${idx + 1}"><span class="write-line-num">${idx + 1}</span><span class="write-line-content">${highlighted}</span></div>`;
1033
+ }).join('');
1034
+
1035
+ // Expand button if needed
1036
+ const expandBtn = needsExpand
1037
+ ? `<button class="write-expand-btn" data-act="toggle-expand" data-block=".write-block" data-more-label="▼ ${hiddenCount} more lines">${defaultExpanded ? '▲ Collapse' : `▼ ${hiddenCount} more lines`}</button>`
1038
+ : '';
1039
+
1040
+ const expandedClass = defaultExpanded ? ' expanded' : '';
1041
+ const wrappedClass = MarkdownRenderer.getCodeWrapPref() ? ' wrapped' : '';
1042
+ return `<div class="tool-block write-block${isError ? ' write-error' : ''}${expandedClass}${wrappedClass}" id="tool-${msg.id}">
1043
+ <div class="write-header">
1044
+ ${iconSvg}
1045
+ ${this.fileLink(filePath, filename, 'write-filename')}
1046
+ <span class="write-line-count">${totalLines}</span>
1047
+ <span class="write-lang">${displayLang}</span>
1048
+ <span class="write-status ${statusClass}">${statusText}</span>
1049
+ <div class="write-actions">
1050
+ <button class="write-action" data-act="preview-file" data-file="${escapeAttr(filePath)}" data-tooltip="Preview">
1051
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
1052
+ </button>
1053
+ <button class="write-action" data-act="open-in-editor" data-file="${escapeAttr(filePath)}" data-tooltip="Open in editor">
1054
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>
1055
+ </button>
1056
+ ${wrapToggleBtn('write-action')}
1057
+ <button class="write-action" data-act="copy-b64" data-copy="${b64Attr(content)}" data-tooltip="Copy">
1058
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
1059
+ </button>
1060
+ </div>
1061
+ </div>
1062
+ <div class="write-content">
1063
+ <pre class="write-code" data-language="${hlLang}"><code class="language-${hlLang}">${codeLines}</code></pre>
1064
+ ${expandBtn}
1065
+ </div>
1066
+ </div>`;
1067
+ },
1068
+
1069
+ /**
1070
+ * Render a Task (agent) tool block with grouped style
1071
+ * Similar to ThinkingController's _renderTaskGroup but for standalone tool blocks
1072
+ */
1073
+ renderTaskBlock(msg) {
1074
+ const desc = msg.toolInput?.description || 'Running task...';
1075
+ const subagentType = msg.toolInput?.subagent_type || '';
1076
+ const hasOutput = msg.toolOutput || msg.toolError;
1077
+ const isCompleted = msg.toolCompleted || hasOutput;
1078
+ const isError = !!msg.toolError;
1079
+
1080
+ // Status badge
1081
+ let statusBadge;
1082
+ if (isError) {
1083
+ statusBadge = '<span class="task-block-badge task-block-badge-error">Failed</span>';
1084
+ } else if (isCompleted) {
1085
+ statusBadge = '<span class="task-block-badge task-block-badge-success">Done</span>';
1086
+ } else {
1087
+ statusBadge = '<span class="task-block-badge task-block-badge-pending">Running...</span>';
1088
+ }
1089
+
1090
+ // Parse agent response from toolOutput
1091
+ const { text: agentResponse, usage } = this._parseTaskOutputWithUsage(msg.toolOutput);
1092
+
1093
+ // Usage badges (tokens + duration)
1094
+ let usageBadges = '';
1095
+ if (usage) {
1096
+ const tokBadge = formatTokensBadge(usage.totalTokens);
1097
+ const durBadge = formatDuration(usage.durationMs);
1098
+ if (tokBadge) usageBadges += `<span class="task-block-tokens">${tokBadge}</span>`;
1099
+ if (durBadge) usageBadges += `<span class="task-block-duration">${durBadge}</span>`;
1100
+ }
1101
+
1102
+ // Preview for collapsed state (first ~150 chars, markdown stripped)
1103
+ let outputPreview = '';
1104
+ if (isCompleted && agentResponse && !isError) {
1105
+ const strippedResponse = this._stripMarkdownForPreview(agentResponse);
1106
+ const preview = strippedResponse.slice(0, 150).trim();
1107
+ if (preview) {
1108
+ outputPreview = `<div class="task-block-preview">${escapeHtml(preview)}${strippedResponse.length > 150 ? '...' : ''}</div>`;
1109
+ }
1110
+ }
1111
+
1112
+ // Full response for expanded state (rendered with markdown)
1113
+ let fullResponse = '';
1114
+ if (isCompleted && agentResponse) {
1115
+ const renderedContent = this._renderMarkdownSafe(agentResponse);
1116
+ fullResponse = `<div class="task-block-response">${renderedContent}</div>`;
1117
+ }
1118
+
1119
+ // Error display
1120
+ let errorHtml = '';
1121
+ if (isError && msg.toolError) {
1122
+ errorHtml = `<div class="task-block-error">${escapeHtml(msg.toolError)}</div>`;
1123
+ }
1124
+
1125
+ const hasExpandableContent = agentResponse || isError;
1126
+
1127
+ return `<div class="tool-block task-block" id="tool-${msg.id}" data-complete="${isCompleted}" data-tool-use-id="${msg.toolId || ''}">
1128
+ <div class="task-block-header" data-act="toggle-task-block" data-id="${escapeAttr(msg.id)}">
1129
+ <span class="task-block-icon">
1130
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
1131
+ <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
1132
+ <circle cx="9" cy="7" r="4"/>
1133
+ <path d="M23 21v-2a4 4 0 0 0-3-3.87"/>
1134
+ <path d="M16 3.13a4 4 0 0 1 0 7.75"/>
1135
+ </svg>
1136
+ </span>
1137
+ <span class="task-block-label">Task</span>
1138
+ <span class="task-block-desc">${escapeHtml(desc)}</span>
1139
+ ${subagentType ? `<span class="task-block-type">${escapeHtml(subagentType)}</span>` : ''}
1140
+ ${usageBadges}
1141
+ ${statusBadge}
1142
+ ${hasExpandableContent ? '<span class="task-block-expand">›</span>' : ''}
1143
+ </div>
1144
+ ${outputPreview}
1145
+ ${errorHtml}
1146
+ <div class="task-block-body">
1147
+ ${fullResponse}
1148
+ </div>
1149
+ </div>`;
1150
+ },
1151
+
1152
+ renderSkillBlock(msg) {
1153
+ const skillName = msg.toolInput?.skill || 'skill';
1154
+ const args = msg.toolInput?.args || '';
1155
+ const hasOutput = msg.toolOutput || msg.toolError;
1156
+ const isCompleted = msg.toolCompleted || hasOutput;
1157
+ const isError = !!msg.toolError;
1158
+
1159
+ // Status badge
1160
+ let statusBadge;
1161
+ if (isError) {
1162
+ statusBadge = '<span class="skill-block-badge skill-block-badge-error">Failed</span>';
1163
+ } else if (isCompleted) {
1164
+ statusBadge = '<span class="skill-block-badge skill-block-badge-success">Done</span>';
1165
+ } else {
1166
+ statusBadge = '<span class="skill-block-badge skill-block-badge-pending">Running...</span>';
1167
+ }
1168
+
1169
+ // Output for expanded state
1170
+ const outputText = msg.toolOutput || msg.toolError || '';
1171
+ const hasExpandableContent = !!outputText;
1172
+
1173
+ // Preview for collapsed state
1174
+ let outputPreview = '';
1175
+ if (isCompleted && outputText && !isError) {
1176
+ const preview = outputText.slice(0, 150).trim();
1177
+ if (preview) {
1178
+ outputPreview = `<div class="skill-block-preview">${escapeHtml(preview)}${outputText.length > 150 ? '...' : ''}</div>`;
1179
+ }
1180
+ }
1181
+
1182
+ // Error display
1183
+ let errorHtml = '';
1184
+ if (isError && msg.toolError) {
1185
+ errorHtml = `<div class="skill-block-error">${escapeHtml(msg.toolError)}</div>`;
1186
+ }
1187
+
1188
+ // Full output for expanded state
1189
+ let fullOutput = '';
1190
+ if (isCompleted && outputText) {
1191
+ fullOutput = `<div class="skill-block-response"><pre>${escapeHtml(outputText)}</pre></div>`;
1192
+ }
1193
+
1194
+ return `<div class="tool-block skill-block" id="tool-${msg.id}">
1195
+ <div class="skill-block-header" data-act="toggle-skill-block" data-id="${escapeAttr(msg.id)}">
1196
+ <span class="skill-block-icon">
1197
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
1198
+ <path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>
1199
+ </svg>
1200
+ </span>
1201
+ <span class="skill-block-label">Skill</span>
1202
+ <span class="skill-block-name">/${escapeHtml(skillName)}</span>
1203
+ ${args ? `<span class="skill-block-args">${escapeHtml(args.length > 60 ? args.slice(0, 57) + '...' : args)}</span>` : ''}
1204
+ ${statusBadge}
1205
+ ${hasExpandableContent ? '<span class="skill-block-expand">›</span>' : ''}
1206
+ </div>
1207
+ ${outputPreview}
1208
+ ${errorHtml}
1209
+ <div class="skill-block-body">
1210
+ ${fullOutput}
1211
+ </div>
1212
+ </div>`;
1213
+ },
1214
+
1215
+ /**
1216
+ * Parse XML-like tags from TaskOutput result (shell/bash tasks).
1217
+ * Format: <tag>value</tag> with <output>...</output> containing the actual log.
1218
+ */
1219
+ /**
1220
+ * Parse agent streaming JSONL output into useful components.
1221
+ * Extracts slug, text responses, tool counts, and token usage.
1222
+ */
1223
+ renderTaskOutputBlock(msg) {
1224
+ const taskId = msg.toolInput?.task_id || '';
1225
+ const hasOutput = msg.toolOutput || msg.toolError;
1226
+ const isCompleted = msg.toolCompleted || hasOutput;
1227
+ const isError = !!msg.toolError;
1228
+
1229
+ // Try XML parsing first (shell/bash tasks)
1230
+ const xmlParsed = this._parseTaskOutputXml(msg.toolOutput || '');
1231
+ if (xmlParsed.status || xmlParsed.exit_code) {
1232
+ return this._renderShellTaskOutput(msg, taskId, xmlParsed, isCompleted, isError);
1233
+ }
1234
+
1235
+ // Parse as agent stream (JSONL from background agents)
1236
+ const stream = this._parseAgentStream(msg.toolOutput || '');
1237
+ return this._renderAgentTaskOutput(msg, taskId, stream, isCompleted, isError);
1238
+ },
1239
+
1240
+ /** Render shell/bash task output (XML structured) */
1241
+ _renderShellTaskOutput(msg, taskId, xml, isCompleted, isError) {
1242
+ const exitCode = xml.exit_code;
1243
+ const taskType = xml.task_type || '';
1244
+ const taskLog = xml.output || '';
1245
+ const status = xml.status || '';
1246
+ const isSuccess = status === 'completed' && exitCode === '0';
1247
+ const isFailed = isError || status === 'failed' || (exitCode && exitCode !== '0');
1248
+ const isRunning = status === 'running' || status === 'pending' || status === 'started';
1249
+
1250
+ let statusBadge;
1251
+ if (isFailed) {
1252
+ statusBadge = `<span class="tob-badge tob-badge-error">exit ${escapeHtml(exitCode || '?')}</span>`;
1253
+ } else if (isSuccess) {
1254
+ statusBadge = '<span class="tob-badge tob-badge-success">exit 0</span>';
1255
+ } else if (isRunning) {
1256
+ statusBadge = `<span class="tob-badge tob-badge-pending">${escapeHtml(status)}</span>`;
1257
+ } else if (status) {
1258
+ statusBadge = `<span class="tob-badge tob-badge-success">${escapeHtml(status)}</span>`;
1259
+ } else {
1260
+ statusBadge = '<span class="tob-badge tob-badge-pending">Waiting...</span>';
1261
+ }
1262
+
1263
+ const typeBadge = taskType ? `<span class="tob-type">${escapeHtml(taskType)}</span>` : '';
1264
+
1265
+ // Preview: first log line, or "running" notice
1266
+ let outputPreview = '';
1267
+ if (taskLog) {
1268
+ const firstLine = taskLog.split('\n').find(l => l.trim()) || '';
1269
+ const preview = firstLine.slice(0, 120).trim();
1270
+ if (preview) {
1271
+ outputPreview = `<div class="tob-preview">${escapeHtml(preview)}${taskLog.split('\n').length > 1 ? '...' : ''}</div>`;
1272
+ }
1273
+ } else if (isRunning) {
1274
+ outputPreview = '<div class="tob-preview tob-preview-muted">Task is running...</div>';
1275
+ } else if (isSuccess || isFailed) {
1276
+ outputPreview = `<div class="tob-preview tob-preview-muted">${S.tool_renderer.empty.no_output}</div>`;
1277
+ }
1278
+
1279
+ let errorHtml = '';
1280
+ if (isError && msg.toolError) {
1281
+ errorHtml = `<div class="tob-error">${escapeHtml(msg.toolError)}</div>`;
1282
+ }
1283
+
1284
+ const hasExpandableContent = !!taskLog || isError;
1285
+
1286
+ return `<div class="tool-block tob tob-shell" id="tool-${msg.id}">
1287
+ <div class="tob-header" data-act="toggle-task-output-block" data-id="${escapeAttr(msg.id)}">
1288
+ <span class="tob-icon">
1289
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
1290
+ <polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/>
1291
+ </svg>
1292
+ </span>
1293
+ <span class="tob-label">Task Result</span>
1294
+ ${taskId ? `<span class="tob-task-id">${escapeHtml(taskId)}</span>` : ''}
1295
+ ${typeBadge}
1296
+ ${statusBadge}
1297
+ ${hasExpandableContent ? '<span class="tob-expand">›</span>' : ''}
1298
+ </div>
1299
+ ${outputPreview}
1300
+ ${errorHtml}
1301
+ <div class="tob-body">
1302
+ ${taskLog ? `<div class="tob-log"><pre>${escapeHtml(taskLog)}</pre></div>` : ''}
1303
+ </div>
1304
+ </div>`;
1305
+ },
1306
+
1307
+ /** Render agent task output (JSONL stream from background agents) */
1308
+ _renderAgentTaskOutput(msg, taskId, stream, isCompleted, isError) {
1309
+ const { slug, texts, toolCounts, totalInputTokens, totalOutputTokens, isTruncated, truncatedPath } = stream;
1310
+ const totalTokens = totalInputTokens + totalOutputTokens;
1311
+
1312
+ // Extract task ID from truncated path: /tmp/claude-{uid}/{slug}/tasks/{taskId}.output
1313
+ let truncatedTaskId = '';
1314
+ if (truncatedPath) {
1315
+ const m = truncatedPath.match(/\/tasks\/([a-f0-9]+)\.output$/);
1316
+ if (m) truncatedTaskId = m[1];
1317
+ }
1318
+
1319
+ // Combine all agent text responses
1320
+ const agentResponse = texts.join('\n\n');
1321
+
1322
+ // Status badge
1323
+ let statusBadge;
1324
+ if (isError) {
1325
+ statusBadge = '<span class="tob-badge tob-badge-error">Failed</span>';
1326
+ } else if (isTruncated && !agentResponse) {
1327
+ statusBadge = '<span class="tob-badge tob-badge-warn">Truncated</span>';
1328
+ } else if (isCompleted) {
1329
+ statusBadge = '<span class="tob-badge tob-badge-success">Done</span>';
1330
+ } else {
1331
+ statusBadge = '<span class="tob-badge tob-badge-pending">Waiting...</span>';
1332
+ }
1333
+
1334
+ // Preview from agent response (stripped markdown, 150 chars)
1335
+ let outputPreview = '';
1336
+ if (agentResponse) {
1337
+ const stripped = this._stripMarkdownForPreview(agentResponse);
1338
+ const preview = stripped.slice(0, 150).trim();
1339
+ if (preview) {
1340
+ outputPreview = `<div class="tob-preview">${escapeHtml(preview)}${stripped.length > 150 ? '...' : ''}</div>`;
1341
+ }
1342
+ } else if (isTruncated) {
1343
+ // Truncated output — show clean message, never raw JSON
1344
+ outputPreview = '<div class="tob-preview tob-preview-muted">Output truncated</div>';
1345
+ } else if (!isCompleted) {
1346
+ outputPreview = '<div class="tob-preview tob-preview-muted">Waiting for agent result...</div>';
1347
+ } else {
1348
+ // Completed but no parseable text
1349
+ const raw = (msg.toolOutput || '').trim();
1350
+ if (!raw) {
1351
+ outputPreview = `<div class="tob-preview tob-preview-muted">${S.tool_renderer.empty.no_response}</div>`;
1352
+ } else if (raw.startsWith('{') || raw.startsWith('[')) {
1353
+ // JSON-ish content that didn't parse into text blocks
1354
+ outputPreview = '<div class="tob-preview tob-preview-muted">Agent output (no text summary)</div>';
1355
+ } else {
1356
+ const preview = raw.slice(0, 150);
1357
+ outputPreview = `<div class="tob-preview tob-preview-muted">${escapeHtml(preview)}${raw.length > 150 ? '...' : ''}</div>`;
1358
+ }
1359
+ }
1360
+
1361
+ // Truncation warning bar with "View Full Output" button
1362
+ let truncatedHtml = '';
1363
+ if (isTruncated) {
1364
+ const viewBtn = truncatedTaskId
1365
+ ? ` <button class="tob-view-full-btn" data-act="open-bg-task" data-task-id="${escapeAttr(truncatedTaskId)}" data-tooltip="Open in Background Tasks widget">${S.tool_renderer.buttons.view_full}</button>`
1366
+ : '';
1367
+ truncatedHtml = `<div class="tob-truncated">
1368
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="12" height="12"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
1369
+ <span>Output truncated${truncatedPath ? ` — <code>${escapeHtml(truncatedPath)}</code>` : ''}</span>
1370
+ ${viewBtn}
1371
+ </div>`;
1372
+ }
1373
+
1374
+ // Error display
1375
+ let errorHtml = '';
1376
+ if (isError && msg.toolError) {
1377
+ errorHtml = `<div class="tob-error">${escapeHtml(msg.toolError)}</div>`;
1378
+ }
1379
+
1380
+ // Full response for expanded state (markdown rendered)
1381
+ let fullResponse = '';
1382
+ if (agentResponse) {
1383
+ const renderedContent = this._renderMarkdownSafe(agentResponse);
1384
+ fullResponse = `<div class="tob-response">${renderedContent}</div>`;
1385
+ }
1386
+
1387
+ // Tool activity footer
1388
+ let footerHtml = '';
1389
+ const toolEntries = Object.entries(toolCounts);
1390
+ if (toolEntries.length > 0 || totalTokens > 0) {
1391
+ const pills = toolEntries
1392
+ .sort((a, b) => b[1] - a[1])
1393
+ .map(([name, count]) => `<span class="tob-tool-pill">${escapeHtml(name)} ×${count}</span>`)
1394
+ .join('');
1395
+ const tokensBadge = totalTokens > 0 ? `<span class="tob-tokens">${formatTokensBadge(totalTokens)}</span>` : '';
1396
+ footerHtml = `<div class="tob-footer">${pills}${tokensBadge}</div>`;
1397
+ }
1398
+
1399
+ const hasExpandableContent = !!agentResponse || !!truncatedHtml || isError;
1400
+
1401
+ // Icon: agent/users icon (matches Task block)
1402
+ return `<div class="tool-block tob tob-agent" id="tool-${msg.id}">
1403
+ <div class="tob-header" data-act="toggle-task-output-block" data-id="${escapeAttr(msg.id)}">
1404
+ <span class="tob-icon">
1405
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
1406
+ <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>
1407
+ </svg>
1408
+ </span>
1409
+ <span class="tob-label">Agent Result</span>
1410
+ ${slug ? `<span class="tob-slug">${escapeHtml(slug)}</span>` : (taskId ? `<span class="tob-task-id">${escapeHtml(taskId)}</span>` : '')}
1411
+ ${statusBadge}
1412
+ ${hasExpandableContent ? '<span class="tob-expand">›</span>' : ''}
1413
+ </div>
1414
+ ${outputPreview}
1415
+ ${errorHtml}
1416
+ <div class="tob-body">
1417
+ ${truncatedHtml}
1418
+ ${fullResponse}
1419
+ ${footerHtml}
1420
+ </div>
1421
+ </div>`;
1422
+ },
1423
+
1424
+ renderTaskStopBlock(msg) {
1425
+ const taskId = msg.toolInput?.task_id || '';
1426
+ const hasOutput = msg.toolOutput || msg.toolError;
1427
+ const isCompleted = msg.toolCompleted || hasOutput;
1428
+
1429
+ // Clean XML wrapper from error text — check both toolError and toolOutput
1430
+ // (error tool_results from Claude put the XML in toolOutput via block.content)
1431
+ const cleanedFromError = cleanToolError(msg.toolError || '');
1432
+ const cleanedFromOutput = cleanToolError(msg.toolOutput || '');
1433
+ const hasXmlError = cleanedFromError.text !== (msg.toolError || '').trim()
1434
+ || cleanedFromOutput.text !== (msg.toolOutput || '').trim();
1435
+ const isError = !!msg.toolError || hasXmlError;
1436
+ const errorText = cleanedFromError.text || cleanedFromOutput.text;
1437
+
1438
+ // Detect "not running (status: X)" — task was already done/stopped
1439
+ let notRunningStatus = '';
1440
+ if (errorText) {
1441
+ const nrMatch = errorText.match(/not running\s*\(status:\s*(\w+)\)/i);
1442
+ if (nrMatch) notRunningStatus = nrMatch[1].toLowerCase();
1443
+ }
1444
+ const isAlreadyDone = notRunningStatus === 'completed';
1445
+ const isAlreadyStopped = notRunningStatus === 'stopped';
1446
+ const isNotRunning = !!notRunningStatus;
1447
+
1448
+ // Parse JSON output: {"message":"...", "task_id":"...", "task_type":"...", "command":"..."}
1449
+ let parsed = {};
1450
+ if (msg.toolOutput && !isNotRunning) {
1451
+ try { parsed = JSON.parse(msg.toolOutput); } catch { }
1452
+ }
1453
+ const message = parsed.message || '';
1454
+ const taskType = parsed.task_type || '';
1455
+ const command = parsed.command || '';
1456
+
1457
+ let statusBadge;
1458
+ if (isNotRunning && isAlreadyDone) {
1459
+ statusBadge = '<span class="tob-badge tob-badge-success">Already Completed</span>';
1460
+ } else if (isNotRunning && isAlreadyStopped) {
1461
+ statusBadge = '<span class="tob-badge tob-badge-stopped">Already Stopped</span>';
1462
+ } else if (isNotRunning) {
1463
+ statusBadge = `<span class="tob-badge tob-badge-warn">${escapeHtml(notRunningStatus)}</span>`;
1464
+ } else if (isError) {
1465
+ statusBadge = '<span class="tob-badge tob-badge-error">Failed</span>';
1466
+ } else if (isCompleted) {
1467
+ statusBadge = '<span class="tob-badge tob-badge-stopped">Stopped</span>';
1468
+ } else {
1469
+ statusBadge = '<span class="tob-badge tob-badge-pending">Stopping...</span>';
1470
+ }
1471
+
1472
+ const typeBadge = taskType ? `<span class="tob-type">${escapeHtml(taskType)}</span>` : '';
1473
+
1474
+ // Show the command that was stopped as preview
1475
+ let previewHtml = '';
1476
+ if (command) {
1477
+ const cmdShort = command.length > 100 ? command.slice(0, 97) + '...' : command;
1478
+ previewHtml = `<div class="tob-preview" style="font-family: var(--font-mono);">${escapeHtml(cmdShort)}</div>`;
1479
+ } else if (message && !isError) {
1480
+ previewHtml = `<div class="tob-preview">${escapeHtml(message.slice(0, 120))}</div>`;
1481
+ }
1482
+
1483
+ let errorHtml = '';
1484
+ if (isError) {
1485
+ if (isNotRunning) {
1486
+ // Friendly message for "not running" cases (not a real error)
1487
+ const friendlyMsg = isAlreadyDone
1488
+ ? 'Task had already completed before stop was requested'
1489
+ : isAlreadyStopped
1490
+ ? 'Task had already been stopped'
1491
+ : `Task was not running (status: ${escapeHtml(notRunningStatus)})`;
1492
+ errorHtml = `<div class="tob-preview tob-preview-muted">${friendlyMsg}</div>`;
1493
+ } else {
1494
+ // Genuine error — show cleaned text (no XML tags)
1495
+ errorHtml = `<div class="tob-error">${escapeHtml(errorText)}</div>`;
1496
+ }
1497
+ }
1498
+
1499
+ // Use neutral border for "already completed" (not red)
1500
+ const stopClass = isAlreadyDone ? 'tob-stop tob-stop-neutral' : 'tob-stop';
1501
+
1502
+ return `<div class="tool-block tob ${stopClass}" id="tool-${msg.id}">
1503
+ <div class="tob-header">
1504
+ <span class="tob-icon">
1505
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
1506
+ <rect x="3" y="3" width="18" height="18" rx="2"/>
1507
+ </svg>
1508
+ </span>
1509
+ <span class="tob-label">Task Stopped</span>
1510
+ ${taskId ? `<span class="tob-task-id">${escapeHtml(taskId)}</span>` : ''}
1511
+ ${typeBadge}
1512
+ ${statusBadge}
1513
+ </div>
1514
+ ${previewHtml}
1515
+ ${errorHtml}
1516
+ </div>`;
1517
+ },
1518
+
1519
+ /**
1520
+ * Render EnterPlanMode as a compact single-line block.
1521
+ */
1522
+ renderEnterPlanBlock(msg) {
1523
+ const hasOutput = msg.toolOutput || msg.toolError;
1524
+ const isCompleted = msg.toolCompleted || hasOutput;
1525
+
1526
+ const statusBadge = isCompleted
1527
+ ? '<span class="plan-mode-badge plan-mode-badge-active">Active</span>'
1528
+ : '<span class="plan-mode-badge plan-mode-badge-pending">Entering...</span>';
1529
+
1530
+ return `<div class="tool-block plan-mode-block" id="tool-${msg.id}">
1531
+ <div class="plan-mode-header">
1532
+ <span class="plan-mode-icon">
1533
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
1534
+ <path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/>
1535
+ <rect x="8" y="2" width="8" height="4" rx="1"/>
1536
+ </svg>
1537
+ </span>
1538
+ <span class="plan-mode-label">Plan Mode</span>
1539
+ ${statusBadge}
1540
+ </div>
1541
+ </div>`;
1542
+ },
1543
+
1544
+ /**
1545
+ * Parse Task toolOutput to extract text content
1546
+ * Output format is usually: [{"type":"text","text":"..."}]
1547
+ */
1548
+ /**
1549
+ * Strip markdown syntax for clean preview text
1550
+ */
1551
+ /**
1552
+ * Update a Task block result while preserving nested children
1553
+ * Called when Task completes to show response without losing nested tools
1554
+ */
1555
+ /**
1556
+ * Update a Task block with live progress from task_progress events.
1557
+ * Shows current activity, tool count, and duration between header and body.
1558
+ */
1559
+ /**
1560
+ * Parse Read tool output to extract line numbers and content
1561
+ * Format: " 123→\tcontent" or " 123→content"
1562
+ */
1563
+ /**
1564
+ * Render a nice todo list for TodoWrite tool
1565
+ */
1566
+ renderTodoBlock(msg) {
1567
+ let input = msg.toolInput || {};
1568
+ if (typeof input === 'string') {
1569
+ try { input = JSON.parse(input); } catch { input = {}; }
1570
+ }
1571
+ const todos = Array.isArray(input.todos) ? input.todos : [];
1572
+
1573
+ // Count by status
1574
+ const completed = todos.filter(t => t.status === 'completed').length;
1575
+ const inProgress = todos.filter(t => t.status === 'in_progress').length;
1576
+ const pending = todos.filter(t => t.status === 'pending').length;
1577
+
1578
+ // Build todo items HTML
1579
+ const todoItems = todos.map(todo => {
1580
+ const status = todo.status || 'pending';
1581
+ const statusClass = `todo-${status.replace('_', '-')}`;
1582
+ let statusIcon;
1583
+ if (status === 'completed') {
1584
+ statusIcon = `<svg class="todo-icon completed" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1585
+ <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
1586
+ <polyline points="22 4 12 14.01 9 11.01"/>
1587
+ </svg>`;
1588
+ } else if (status === 'in_progress') {
1589
+ statusIcon = `<svg class="todo-icon in-progress" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1590
+ <circle cx="12" cy="12" r="10"/>
1591
+ <polyline points="12 6 12 12 16 14"/>
1592
+ </svg>`;
1593
+ } else {
1594
+ statusIcon = `<svg class="todo-icon pending" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1595
+ <circle cx="12" cy="12" r="10"/>
1596
+ </svg>`;
1597
+ }
1598
+
1599
+ return `<div class="todo-item ${statusClass}">
1600
+ ${statusIcon}
1601
+ <span class="todo-content">${escapeHtml(todo.content || '')}</span>
1602
+ </div>`;
1603
+ }).join('');
1604
+
1605
+ // Summary line
1606
+ const summaryParts = [];
1607
+ if (completed > 0) summaryParts.push(`${completed} done`);
1608
+ if (inProgress > 0) summaryParts.push(`${inProgress} active`);
1609
+ if (pending > 0) summaryParts.push(`${pending} pending`);
1610
+ const summary = summaryParts.join(' · ') || 'No tasks';
1611
+
1612
+ return `<div class="tool-block todo-block" id="tool-${msg.id}">
1613
+ <div class="todo-header">
1614
+ <span class="todo-title">
1615
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1616
+ <path d="M9 11l3 3L22 4"/>
1617
+ <path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/>
1618
+ </svg>
1619
+ Tasks
1620
+ </span>
1621
+ <span class="todo-summary">${summary}</span>
1622
+ </div>
1623
+ <div class="todo-list">${todoItems}</div>
1624
+ </div>`;
1625
+ },
1626
+ };