@wahack/pi-coding-agent 15.11.0

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 (1152) hide show
  1. package/CHANGELOG.md +10031 -0
  2. package/README.md +36 -0
  3. package/examples/README.md +21 -0
  4. package/examples/custom-tools/README.md +104 -0
  5. package/examples/custom-tools/hello/index.ts +20 -0
  6. package/examples/extensions/README.md +142 -0
  7. package/examples/extensions/api-demo.ts +79 -0
  8. package/examples/extensions/chalk-logger.ts +25 -0
  9. package/examples/extensions/hello.ts +31 -0
  10. package/examples/extensions/pirate.ts +43 -0
  11. package/examples/extensions/plan-mode.ts +549 -0
  12. package/examples/extensions/reload-runtime.ts +38 -0
  13. package/examples/extensions/thinking-note.ts +13 -0
  14. package/examples/extensions/tools.ts +145 -0
  15. package/examples/extensions/with-deps/index.ts +36 -0
  16. package/examples/extensions/with-deps/package-lock.json +31 -0
  17. package/examples/extensions/with-deps/package.json +17 -0
  18. package/examples/hooks/README.md +56 -0
  19. package/examples/hooks/auto-commit-on-exit.ts +48 -0
  20. package/examples/hooks/confirm-destructive.ts +58 -0
  21. package/examples/hooks/custom-compaction.ts +115 -0
  22. package/examples/hooks/dirty-repo-guard.ts +51 -0
  23. package/examples/hooks/file-trigger.ts +40 -0
  24. package/examples/hooks/git-checkpoint.ts +52 -0
  25. package/examples/hooks/handoff.ts +149 -0
  26. package/examples/hooks/permission-gate.ts +33 -0
  27. package/examples/hooks/protected-paths.ts +29 -0
  28. package/examples/hooks/qna.ts +118 -0
  29. package/examples/hooks/status-line.ts +39 -0
  30. package/examples/sdk/01-minimal.ts +21 -0
  31. package/examples/sdk/02-custom-model.ts +49 -0
  32. package/examples/sdk/03-custom-prompt.ts +46 -0
  33. package/examples/sdk/04-skills.ts +43 -0
  34. package/examples/sdk/06-extensions.ts +82 -0
  35. package/examples/sdk/06-hooks.ts +61 -0
  36. package/examples/sdk/07-context-files.ts +35 -0
  37. package/examples/sdk/08-prompt-templates.ts +41 -0
  38. package/examples/sdk/08-slash-commands.ts +46 -0
  39. package/examples/sdk/09-api-keys-and-oauth.ts +54 -0
  40. package/examples/sdk/11-sessions.ts +47 -0
  41. package/examples/sdk/12-redis-sessions.ts +54 -0
  42. package/examples/sdk/13-sql-sessions.ts +61 -0
  43. package/examples/sdk/README.md +172 -0
  44. package/package.json +554 -0
  45. package/scripts/build-binary.ts +100 -0
  46. package/scripts/bundle-dist.ts +90 -0
  47. package/scripts/format-prompts.ts +68 -0
  48. package/scripts/generate-docs-index.ts +40 -0
  49. package/scripts/generate-template.ts +33 -0
  50. package/scripts/omp +42 -0
  51. package/scripts/omp.ts +19 -0
  52. package/src/async/index.ts +1 -0
  53. package/src/async/job-manager.ts +625 -0
  54. package/src/auto-thinking/classifier.ts +185 -0
  55. package/src/autoresearch/command-resume.md +14 -0
  56. package/src/autoresearch/dashboard.ts +436 -0
  57. package/src/autoresearch/git.ts +319 -0
  58. package/src/autoresearch/helpers.ts +218 -0
  59. package/src/autoresearch/index.ts +536 -0
  60. package/src/autoresearch/prompt-setup.md +43 -0
  61. package/src/autoresearch/prompt.md +103 -0
  62. package/src/autoresearch/resume-message.md +10 -0
  63. package/src/autoresearch/state.ts +273 -0
  64. package/src/autoresearch/storage.ts +699 -0
  65. package/src/autoresearch/tools/init-experiment.ts +272 -0
  66. package/src/autoresearch/tools/log-experiment.ts +524 -0
  67. package/src/autoresearch/tools/run-experiment.ts +407 -0
  68. package/src/autoresearch/tools/update-notes.ts +109 -0
  69. package/src/autoresearch/types.ts +168 -0
  70. package/src/bun-imports.d.ts +28 -0
  71. package/src/capability/context-file.ts +44 -0
  72. package/src/capability/extension-module.ts +34 -0
  73. package/src/capability/extension.ts +47 -0
  74. package/src/capability/fs.ts +117 -0
  75. package/src/capability/hook.ts +40 -0
  76. package/src/capability/index.ts +436 -0
  77. package/src/capability/instruction.ts +37 -0
  78. package/src/capability/mcp.ts +74 -0
  79. package/src/capability/prompt.ts +35 -0
  80. package/src/capability/rule-buckets.ts +66 -0
  81. package/src/capability/rule.ts +261 -0
  82. package/src/capability/settings.ts +34 -0
  83. package/src/capability/skill.ts +63 -0
  84. package/src/capability/slash-command.ts +40 -0
  85. package/src/capability/ssh.ts +41 -0
  86. package/src/capability/system-prompt.ts +34 -0
  87. package/src/capability/tool.ts +38 -0
  88. package/src/capability/types.ts +168 -0
  89. package/src/cli/agents-cli.ts +138 -0
  90. package/src/cli/args.ts +340 -0
  91. package/src/cli/auth-broker-cli.ts +895 -0
  92. package/src/cli/auth-gateway-cli.ts +611 -0
  93. package/src/cli/classify-install-target.ts +76 -0
  94. package/src/cli/claude-trace-cli.ts +795 -0
  95. package/src/cli/commands/init-xdg.ts +27 -0
  96. package/src/cli/completion-gen.ts +550 -0
  97. package/src/cli/config-cli.ts +418 -0
  98. package/src/cli/dry-balance-cli.ts +856 -0
  99. package/src/cli/extension-flags.ts +48 -0
  100. package/src/cli/file-processor.ts +133 -0
  101. package/src/cli/gallery-cli.ts +230 -0
  102. package/src/cli/gallery-fixtures/agentic.ts +407 -0
  103. package/src/cli/gallery-fixtures/codeintel.ts +187 -0
  104. package/src/cli/gallery-fixtures/edit.ts +194 -0
  105. package/src/cli/gallery-fixtures/fs.ts +220 -0
  106. package/src/cli/gallery-fixtures/index.ts +40 -0
  107. package/src/cli/gallery-fixtures/interaction.ts +49 -0
  108. package/src/cli/gallery-fixtures/memory.ts +81 -0
  109. package/src/cli/gallery-fixtures/misc.ts +250 -0
  110. package/src/cli/gallery-fixtures/search.ts +213 -0
  111. package/src/cli/gallery-fixtures/shell.ts +167 -0
  112. package/src/cli/gallery-fixtures/types.ts +57 -0
  113. package/src/cli/gallery-fixtures/web.ts +158 -0
  114. package/src/cli/gallery-screenshot.ts +279 -0
  115. package/src/cli/grep-cli.ts +160 -0
  116. package/src/cli/grievances-cli.ts +256 -0
  117. package/src/cli/initial-message.ts +58 -0
  118. package/src/cli/list-models.ts +194 -0
  119. package/src/cli/plugin-cli.ts +996 -0
  120. package/src/cli/read-cli.ts +57 -0
  121. package/src/cli/session-picker.ts +79 -0
  122. package/src/cli/setup-cli.ts +231 -0
  123. package/src/cli/shell-cli.ts +176 -0
  124. package/src/cli/ssh-cli.ts +179 -0
  125. package/src/cli/startup-cwd.ts +68 -0
  126. package/src/cli/stats-cli.ts +238 -0
  127. package/src/cli/tiny-models-cli.ts +127 -0
  128. package/src/cli/update-cli.ts +611 -0
  129. package/src/cli/usage-cli.ts +603 -0
  130. package/src/cli/web-search-cli.ts +132 -0
  131. package/src/cli/worktree-cli.ts +291 -0
  132. package/src/cli-commands.ts +79 -0
  133. package/src/cli.ts +200 -0
  134. package/src/commands/acp.ts +24 -0
  135. package/src/commands/agents.ts +57 -0
  136. package/src/commands/auth-broker.ts +99 -0
  137. package/src/commands/auth-gateway.ts +69 -0
  138. package/src/commands/commit.ts +46 -0
  139. package/src/commands/complete.ts +66 -0
  140. package/src/commands/completions.ts +60 -0
  141. package/src/commands/config.ts +51 -0
  142. package/src/commands/dry-balance.ts +43 -0
  143. package/src/commands/gallery.ts +52 -0
  144. package/src/commands/grep.ts +48 -0
  145. package/src/commands/grievances.ts +51 -0
  146. package/src/commands/install.ts +107 -0
  147. package/src/commands/launch.ts +169 -0
  148. package/src/commands/plugin.ts +78 -0
  149. package/src/commands/read.ts +38 -0
  150. package/src/commands/setup.ts +67 -0
  151. package/src/commands/shell.ts +29 -0
  152. package/src/commands/ssh.ts +60 -0
  153. package/src/commands/stats.ts +29 -0
  154. package/src/commands/tiny-models.ts +36 -0
  155. package/src/commands/update.ts +21 -0
  156. package/src/commands/usage.ts +35 -0
  157. package/src/commands/web-search.ts +42 -0
  158. package/src/commands/worktree.ts +56 -0
  159. package/src/commit/agentic/agent.ts +317 -0
  160. package/src/commit/agentic/fallback.ts +96 -0
  161. package/src/commit/agentic/index.ts +355 -0
  162. package/src/commit/agentic/prompts/analyze-file.md +22 -0
  163. package/src/commit/agentic/prompts/session-user.md +25 -0
  164. package/src/commit/agentic/prompts/split-confirm.md +1 -0
  165. package/src/commit/agentic/prompts/system.md +38 -0
  166. package/src/commit/agentic/state.ts +60 -0
  167. package/src/commit/agentic/tools/analyze-file.ts +146 -0
  168. package/src/commit/agentic/tools/git-file-diff.ts +191 -0
  169. package/src/commit/agentic/tools/git-hunk.ts +50 -0
  170. package/src/commit/agentic/tools/git-overview.ts +81 -0
  171. package/src/commit/agentic/tools/index.ts +54 -0
  172. package/src/commit/agentic/tools/propose-changelog.ts +144 -0
  173. package/src/commit/agentic/tools/propose-commit.ts +109 -0
  174. package/src/commit/agentic/tools/recent-commits.ts +81 -0
  175. package/src/commit/agentic/tools/schemas.ts +23 -0
  176. package/src/commit/agentic/tools/split-commit.ts +245 -0
  177. package/src/commit/agentic/topo-sort.ts +44 -0
  178. package/src/commit/agentic/trivial.ts +51 -0
  179. package/src/commit/agentic/validation.ts +183 -0
  180. package/src/commit/analysis/conventional.ts +64 -0
  181. package/src/commit/analysis/index.ts +4 -0
  182. package/src/commit/analysis/scope.ts +242 -0
  183. package/src/commit/analysis/summary.ts +105 -0
  184. package/src/commit/analysis/validation.ts +66 -0
  185. package/src/commit/changelog/detect.ts +40 -0
  186. package/src/commit/changelog/generate.ts +97 -0
  187. package/src/commit/changelog/index.ts +234 -0
  188. package/src/commit/changelog/parse.ts +44 -0
  189. package/src/commit/cli.ts +85 -0
  190. package/src/commit/git/diff.ts +148 -0
  191. package/src/commit/index.ts +5 -0
  192. package/src/commit/map-reduce/index.ts +69 -0
  193. package/src/commit/map-reduce/map-phase.ts +193 -0
  194. package/src/commit/map-reduce/reduce-phase.ts +49 -0
  195. package/src/commit/map-reduce/utils.ts +9 -0
  196. package/src/commit/message.ts +11 -0
  197. package/src/commit/model-selection.ts +92 -0
  198. package/src/commit/pipeline.ts +243 -0
  199. package/src/commit/prompts/analysis-system.md +148 -0
  200. package/src/commit/prompts/analysis-user.md +38 -0
  201. package/src/commit/prompts/changelog-system.md +50 -0
  202. package/src/commit/prompts/changelog-user.md +18 -0
  203. package/src/commit/prompts/file-observer-system.md +24 -0
  204. package/src/commit/prompts/file-observer-user.md +8 -0
  205. package/src/commit/prompts/reduce-system.md +50 -0
  206. package/src/commit/prompts/reduce-user.md +17 -0
  207. package/src/commit/prompts/summary-retry.md +3 -0
  208. package/src/commit/prompts/summary-system.md +38 -0
  209. package/src/commit/prompts/summary-user.md +13 -0
  210. package/src/commit/prompts/types-description.md +2 -0
  211. package/src/commit/shared-llm.ts +77 -0
  212. package/src/commit/types.ts +118 -0
  213. package/src/commit/utils/exclusions.ts +42 -0
  214. package/src/commit/utils.ts +58 -0
  215. package/src/config/api-key-resolver.ts +60 -0
  216. package/src/config/append-only-context-mode.ts +31 -0
  217. package/src/config/config-file.ts +317 -0
  218. package/src/config/file-lock.ts +164 -0
  219. package/src/config/keybindings.ts +628 -0
  220. package/src/config/mcp-schema.json +230 -0
  221. package/src/config/model-discovery.ts +554 -0
  222. package/src/config/model-registry.ts +2090 -0
  223. package/src/config/model-resolver.ts +1502 -0
  224. package/src/config/model-roles.ts +74 -0
  225. package/src/config/models-config-schema.ts +226 -0
  226. package/src/config/models-config.ts +129 -0
  227. package/src/config/prompt-templates.ts +185 -0
  228. package/src/config/resolve-config-value.ts +94 -0
  229. package/src/config/settings-schema.ts +3530 -0
  230. package/src/config/settings.ts +1178 -0
  231. package/src/config.ts +242 -0
  232. package/src/cursor.ts +340 -0
  233. package/src/dap/client.ts +760 -0
  234. package/src/dap/config.ts +189 -0
  235. package/src/dap/defaults.json +212 -0
  236. package/src/dap/index.ts +4 -0
  237. package/src/dap/session.ts +1441 -0
  238. package/src/dap/types.ts +610 -0
  239. package/src/debug/index.ts +515 -0
  240. package/src/debug/log-formatting.ts +58 -0
  241. package/src/debug/log-viewer.ts +908 -0
  242. package/src/debug/profiler.ts +162 -0
  243. package/src/debug/protocol-probe.ts +267 -0
  244. package/src/debug/raw-sse-buffer.ts +273 -0
  245. package/src/debug/raw-sse.ts +292 -0
  246. package/src/debug/report-bundle.ts +374 -0
  247. package/src/debug/system-info.ts +111 -0
  248. package/src/debug/terminal-info.ts +124 -0
  249. package/src/discovery/agents-md.ts +67 -0
  250. package/src/discovery/agents.ts +230 -0
  251. package/src/discovery/at-imports.ts +273 -0
  252. package/src/discovery/builtin-defaults.ts +39 -0
  253. package/src/discovery/builtin-rules/index.ts +54 -0
  254. package/src/discovery/builtin-rules/rs-box-leak.md +48 -0
  255. package/src/discovery/builtin-rules/rs-future-prelude.md +23 -0
  256. package/src/discovery/builtin-rules/rs-lazylock.md +51 -0
  257. package/src/discovery/builtin-rules/rs-match-ergonomics.md +67 -0
  258. package/src/discovery/builtin-rules/rs-parking-lot.md +44 -0
  259. package/src/discovery/builtin-rules/rs-result-type.md +19 -0
  260. package/src/discovery/builtin-rules/ts-bare-catch.md +38 -0
  261. package/src/discovery/builtin-rules/ts-import-type.md +42 -0
  262. package/src/discovery/builtin-rules/ts-no-any.md +56 -0
  263. package/src/discovery/builtin-rules/ts-no-deprecated-leftovers.md +44 -0
  264. package/src/discovery/builtin-rules/ts-no-dynamic-import.md +39 -0
  265. package/src/discovery/builtin-rules/ts-no-return-type.md +45 -0
  266. package/src/discovery/builtin-rules/ts-no-test-timers.md +55 -0
  267. package/src/discovery/builtin-rules/ts-no-tiny-functions.md +51 -0
  268. package/src/discovery/builtin-rules/ts-promise-with-resolvers.md +65 -0
  269. package/src/discovery/builtin-rules/ts-redundant-clear-guard.md +75 -0
  270. package/src/discovery/builtin-rules/ts-set-map.md +28 -0
  271. package/src/discovery/builtin.ts +906 -0
  272. package/src/discovery/claude-plugins.ts +386 -0
  273. package/src/discovery/claude.ts +584 -0
  274. package/src/discovery/cline.ts +83 -0
  275. package/src/discovery/codex.ts +522 -0
  276. package/src/discovery/cursor.ts +220 -0
  277. package/src/discovery/gemini.ts +383 -0
  278. package/src/discovery/github.ts +154 -0
  279. package/src/discovery/helpers.ts +1016 -0
  280. package/src/discovery/index.ts +81 -0
  281. package/src/discovery/mcp-json.ts +171 -0
  282. package/src/discovery/omp-extension-roots.ts +190 -0
  283. package/src/discovery/omp-plugins.ts +383 -0
  284. package/src/discovery/opencode.ts +398 -0
  285. package/src/discovery/plugin-dir-roots.ts +28 -0
  286. package/src/discovery/ssh.ts +153 -0
  287. package/src/discovery/substitute-plugin-root.ts +29 -0
  288. package/src/discovery/vscode.ts +105 -0
  289. package/src/discovery/windsurf.ts +147 -0
  290. package/src/edit/apply-patch/index.ts +87 -0
  291. package/src/edit/apply-patch/parser.ts +174 -0
  292. package/src/edit/diff.ts +999 -0
  293. package/src/edit/file-snapshot-store.ts +91 -0
  294. package/src/edit/hashline/block-resolver.ts +33 -0
  295. package/src/edit/hashline/diff.ts +290 -0
  296. package/src/edit/hashline/execute.ts +242 -0
  297. package/src/edit/hashline/filesystem.ts +130 -0
  298. package/src/edit/hashline/index.ts +5 -0
  299. package/src/edit/hashline/noop-loop-guard.ts +99 -0
  300. package/src/edit/hashline/params.ts +18 -0
  301. package/src/edit/index.ts +571 -0
  302. package/src/edit/modes/apply-patch.lark +19 -0
  303. package/src/edit/modes/apply-patch.ts +53 -0
  304. package/src/edit/modes/patch.ts +1891 -0
  305. package/src/edit/modes/replace.ts +1137 -0
  306. package/src/edit/normalize.ts +345 -0
  307. package/src/edit/notebook.ts +242 -0
  308. package/src/edit/read-file.ts +25 -0
  309. package/src/edit/renderer.ts +769 -0
  310. package/src/edit/streaming.ts +517 -0
  311. package/src/eval/__tests__/agent-bridge.test.ts +708 -0
  312. package/src/eval/__tests__/bridge-timeout.test.ts +64 -0
  313. package/src/eval/__tests__/budget-bridge.test.ts +69 -0
  314. package/src/eval/__tests__/completion-bridge.test.ts +412 -0
  315. package/src/eval/__tests__/helpers-local-roots.test.ts +58 -0
  316. package/src/eval/__tests__/idle-timeout.test.ts +80 -0
  317. package/src/eval/__tests__/js-context-manager.test.ts +241 -0
  318. package/src/eval/__tests__/kernel-spawn.test.ts +103 -0
  319. package/src/eval/agent-bridge.ts +319 -0
  320. package/src/eval/backend.ts +71 -0
  321. package/src/eval/bridge-timeout.ts +44 -0
  322. package/src/eval/budget-bridge.ts +48 -0
  323. package/src/eval/completion-bridge.ts +207 -0
  324. package/src/eval/concurrency-bridge.ts +34 -0
  325. package/src/eval/idle-timeout.ts +91 -0
  326. package/src/eval/index.ts +4 -0
  327. package/src/eval/js/context-manager.ts +502 -0
  328. package/src/eval/js/executor.ts +173 -0
  329. package/src/eval/js/index.ts +51 -0
  330. package/src/eval/js/shared/helpers.ts +283 -0
  331. package/src/eval/js/shared/indirect-eval.ts +30 -0
  332. package/src/eval/js/shared/local-module-loader.ts +342 -0
  333. package/src/eval/js/shared/prelude.ts +2 -0
  334. package/src/eval/js/shared/prelude.txt +246 -0
  335. package/src/eval/js/shared/rewrite-imports.ts +532 -0
  336. package/src/eval/js/shared/runtime.ts +352 -0
  337. package/src/eval/js/shared/types.ts +18 -0
  338. package/src/eval/js/tool-bridge.ts +162 -0
  339. package/src/eval/js/worker-core.ts +132 -0
  340. package/src/eval/js/worker-entry.ts +30 -0
  341. package/src/eval/js/worker-protocol.ts +47 -0
  342. package/src/eval/py/__tests__/prelude.test.ts +19 -0
  343. package/src/eval/py/display.ts +71 -0
  344. package/src/eval/py/executor.ts +742 -0
  345. package/src/eval/py/index.ts +68 -0
  346. package/src/eval/py/kernel.ts +748 -0
  347. package/src/eval/py/prelude.py +658 -0
  348. package/src/eval/py/prelude.ts +3 -0
  349. package/src/eval/py/runner.py +1133 -0
  350. package/src/eval/py/runtime.ts +276 -0
  351. package/src/eval/py/spawn-options.ts +126 -0
  352. package/src/eval/py/tool-bridge.ts +182 -0
  353. package/src/eval/session-id.ts +8 -0
  354. package/src/eval/types.ts +48 -0
  355. package/src/exa/index.ts +2 -0
  356. package/src/exa/mcp-client.ts +370 -0
  357. package/src/exa/types.ts +69 -0
  358. package/src/exec/bash-executor.ts +419 -0
  359. package/src/exec/exec.ts +53 -0
  360. package/src/exec/non-interactive-env.ts +48 -0
  361. package/src/export/custom-share.ts +65 -0
  362. package/src/export/html/index.ts +164 -0
  363. package/src/export/html/template.css +1051 -0
  364. package/src/export/html/template.generated.ts +2 -0
  365. package/src/export/html/template.html +46 -0
  366. package/src/export/html/template.js +2271 -0
  367. package/src/export/html/template.macro.ts +25 -0
  368. package/src/export/html/vendor/highlight.min.js +1213 -0
  369. package/src/export/html/vendor/marked.min.js +6 -0
  370. package/src/export/ttsr.ts +583 -0
  371. package/src/extensibility/custom-commands/bundled/ci-green/index.ts +54 -0
  372. package/src/extensibility/custom-commands/bundled/review/index.ts +489 -0
  373. package/src/extensibility/custom-commands/index.ts +2 -0
  374. package/src/extensibility/custom-commands/loader.ts +238 -0
  375. package/src/extensibility/custom-commands/types.ts +113 -0
  376. package/src/extensibility/custom-tools/index.ts +7 -0
  377. package/src/extensibility/custom-tools/loader.ts +269 -0
  378. package/src/extensibility/custom-tools/types.ts +270 -0
  379. package/src/extensibility/custom-tools/wrapper.ts +47 -0
  380. package/src/extensibility/extensions/compact-handler.ts +40 -0
  381. package/src/extensibility/extensions/get-commands-handler.ts +78 -0
  382. package/src/extensibility/extensions/index.ts +16 -0
  383. package/src/extensibility/extensions/loader.ts +572 -0
  384. package/src/extensibility/extensions/runner.ts +922 -0
  385. package/src/extensibility/extensions/types.ts +1322 -0
  386. package/src/extensibility/extensions/wrapper.ts +223 -0
  387. package/src/extensibility/hooks/index.ts +5 -0
  388. package/src/extensibility/hooks/loader.ts +257 -0
  389. package/src/extensibility/hooks/runner.ts +425 -0
  390. package/src/extensibility/hooks/tool-wrapper.ts +107 -0
  391. package/src/extensibility/hooks/types.ts +606 -0
  392. package/src/extensibility/legacy-pi-ai-shim.ts +24 -0
  393. package/src/extensibility/legacy-pi-coding-agent-shim.ts +15 -0
  394. package/src/extensibility/plugins/doctor.ts +65 -0
  395. package/src/extensibility/plugins/git-url.ts +367 -0
  396. package/src/extensibility/plugins/index.ts +9 -0
  397. package/src/extensibility/plugins/installer.ts +192 -0
  398. package/src/extensibility/plugins/legacy-pi-compat.ts +682 -0
  399. package/src/extensibility/plugins/loader.ts +313 -0
  400. package/src/extensibility/plugins/manager.ts +827 -0
  401. package/src/extensibility/plugins/marketplace/cache.ts +136 -0
  402. package/src/extensibility/plugins/marketplace/fetcher.ts +317 -0
  403. package/src/extensibility/plugins/marketplace/index.ts +6 -0
  404. package/src/extensibility/plugins/marketplace/manager.ts +770 -0
  405. package/src/extensibility/plugins/marketplace/registry.ts +196 -0
  406. package/src/extensibility/plugins/marketplace/source-resolver.ts +147 -0
  407. package/src/extensibility/plugins/marketplace/types.ts +191 -0
  408. package/src/extensibility/plugins/marketplace-auto-update.ts +49 -0
  409. package/src/extensibility/plugins/parser.ts +105 -0
  410. package/src/extensibility/plugins/types.ts +194 -0
  411. package/src/extensibility/shared-events.ts +343 -0
  412. package/src/extensibility/skills.ts +312 -0
  413. package/src/extensibility/slash-commands.ts +227 -0
  414. package/src/extensibility/tool-proxy.ts +25 -0
  415. package/src/extensibility/typebox.ts +418 -0
  416. package/src/extensibility/utils.ts +44 -0
  417. package/src/goals/index.ts +3 -0
  418. package/src/goals/runtime.ts +528 -0
  419. package/src/goals/state.ts +37 -0
  420. package/src/goals/tools/goal-tool.ts +251 -0
  421. package/src/hindsight/backend.ts +354 -0
  422. package/src/hindsight/bank.ts +156 -0
  423. package/src/hindsight/client.ts +598 -0
  424. package/src/hindsight/config.ts +175 -0
  425. package/src/hindsight/content.ts +210 -0
  426. package/src/hindsight/index.ts +8 -0
  427. package/src/hindsight/mental-models.ts +429 -0
  428. package/src/hindsight/seeds.json +32 -0
  429. package/src/hindsight/state.ts +488 -0
  430. package/src/hindsight/transcript.ts +71 -0
  431. package/src/index.ts +59 -0
  432. package/src/internal-urls/agent-protocol.ts +146 -0
  433. package/src/internal-urls/artifact-protocol.ts +107 -0
  434. package/src/internal-urls/docs-index.generated.ts +106 -0
  435. package/src/internal-urls/history-protocol.ts +113 -0
  436. package/src/internal-urls/index.ts +25 -0
  437. package/src/internal-urls/issue-pr-protocol.ts +584 -0
  438. package/src/internal-urls/json-query.ts +126 -0
  439. package/src/internal-urls/local-protocol.ts +287 -0
  440. package/src/internal-urls/mcp-protocol.ts +151 -0
  441. package/src/internal-urls/memory-protocol.ts +169 -0
  442. package/src/internal-urls/omp-protocol.ts +93 -0
  443. package/src/internal-urls/parse.ts +72 -0
  444. package/src/internal-urls/registry-helpers.ts +25 -0
  445. package/src/internal-urls/router.ts +105 -0
  446. package/src/internal-urls/rule-protocol.ts +45 -0
  447. package/src/internal-urls/skill-protocol.ts +96 -0
  448. package/src/internal-urls/types.ts +152 -0
  449. package/src/internal-urls/vault-protocol.ts +936 -0
  450. package/src/irc/bus.ts +292 -0
  451. package/src/lib/xai-http.ts +124 -0
  452. package/src/lsp/client.ts +1193 -0
  453. package/src/lsp/clients/biome-client.ts +264 -0
  454. package/src/lsp/clients/index.ts +50 -0
  455. package/src/lsp/clients/lsp-linter-client.ts +93 -0
  456. package/src/lsp/clients/swiftlint-client.ts +120 -0
  457. package/src/lsp/config.ts +502 -0
  458. package/src/lsp/defaults.json +493 -0
  459. package/src/lsp/diagnostics-ledger.ts +51 -0
  460. package/src/lsp/edits.ts +267 -0
  461. package/src/lsp/index.ts +2477 -0
  462. package/src/lsp/lspmux.ts +233 -0
  463. package/src/lsp/render.ts +694 -0
  464. package/src/lsp/startup-events.ts +13 -0
  465. package/src/lsp/types.ts +455 -0
  466. package/src/lsp/utils.ts +718 -0
  467. package/src/main.ts +1325 -0
  468. package/src/mcp/client.ts +484 -0
  469. package/src/mcp/config-writer.ts +225 -0
  470. package/src/mcp/config.ts +365 -0
  471. package/src/mcp/index.ts +29 -0
  472. package/src/mcp/json-rpc.ts +122 -0
  473. package/src/mcp/loader.ts +124 -0
  474. package/src/mcp/manager.ts +1275 -0
  475. package/src/mcp/oauth-discovery.ts +442 -0
  476. package/src/mcp/oauth-flow.ts +442 -0
  477. package/src/mcp/render.ts +132 -0
  478. package/src/mcp/smithery-auth.ts +104 -0
  479. package/src/mcp/smithery-connect.ts +145 -0
  480. package/src/mcp/smithery-registry.ts +477 -0
  481. package/src/mcp/timeout.ts +59 -0
  482. package/src/mcp/tool-bridge.ts +426 -0
  483. package/src/mcp/tool-cache.ts +117 -0
  484. package/src/mcp/transports/http.ts +519 -0
  485. package/src/mcp/transports/index.ts +6 -0
  486. package/src/mcp/transports/stdio.ts +528 -0
  487. package/src/mcp/types.ts +423 -0
  488. package/src/memories/index.ts +1150 -0
  489. package/src/memories/storage.ts +577 -0
  490. package/src/memory-backend/index.ts +18 -0
  491. package/src/memory-backend/local-backend.ts +39 -0
  492. package/src/memory-backend/off-backend.ts +25 -0
  493. package/src/memory-backend/resolve.ts +25 -0
  494. package/src/memory-backend/runtime.ts +66 -0
  495. package/src/memory-backend/types.ts +166 -0
  496. package/src/mnemopi/backend.ts +547 -0
  497. package/src/mnemopi/config.ts +160 -0
  498. package/src/mnemopi/index.ts +3 -0
  499. package/src/mnemopi/state.ts +584 -0
  500. package/src/modes/acp/acp-agent.ts +2407 -0
  501. package/src/modes/acp/acp-client-bridge.ts +154 -0
  502. package/src/modes/acp/acp-event-mapper.ts +929 -0
  503. package/src/modes/acp/acp-mode.ts +23 -0
  504. package/src/modes/acp/index.ts +2 -0
  505. package/src/modes/acp/terminal-auth.ts +37 -0
  506. package/src/modes/components/agent-dashboard.ts +1206 -0
  507. package/src/modes/components/agent-hub.ts +1071 -0
  508. package/src/modes/components/assistant-message.ts +307 -0
  509. package/src/modes/components/bash-execution.ts +220 -0
  510. package/src/modes/components/bordered-loader.ts +41 -0
  511. package/src/modes/components/branch-summary-message.ts +45 -0
  512. package/src/modes/components/btw-panel.ts +104 -0
  513. package/src/modes/components/chat-block.ts +111 -0
  514. package/src/modes/components/compaction-summary-message.ts +87 -0
  515. package/src/modes/components/copy-selector.ts +206 -0
  516. package/src/modes/components/countdown-timer.ts +75 -0
  517. package/src/modes/components/custom-editor.ts +398 -0
  518. package/src/modes/components/custom-message.ts +63 -0
  519. package/src/modes/components/diff.ts +277 -0
  520. package/src/modes/components/dynamic-border.ts +34 -0
  521. package/src/modes/components/error-banner.ts +33 -0
  522. package/src/modes/components/eval-execution.ts +158 -0
  523. package/src/modes/components/execution-shared.ts +101 -0
  524. package/src/modes/components/extensions/extension-dashboard.ts +399 -0
  525. package/src/modes/components/extensions/extension-list.ts +502 -0
  526. package/src/modes/components/extensions/index.ts +9 -0
  527. package/src/modes/components/extensions/inspector-panel.ts +317 -0
  528. package/src/modes/components/extensions/state-manager.ts +627 -0
  529. package/src/modes/components/extensions/types.ts +186 -0
  530. package/src/modes/components/footer.ts +274 -0
  531. package/src/modes/components/history-search.ts +280 -0
  532. package/src/modes/components/hook-editor.ts +167 -0
  533. package/src/modes/components/hook-input.ts +87 -0
  534. package/src/modes/components/hook-message.ts +66 -0
  535. package/src/modes/components/hook-selector.ts +660 -0
  536. package/src/modes/components/index.ts +38 -0
  537. package/src/modes/components/keybinding-hints.ts +65 -0
  538. package/src/modes/components/late-diagnostics-message.ts +60 -0
  539. package/src/modes/components/login-dialog.ts +164 -0
  540. package/src/modes/components/mcp-add-wizard.ts +1340 -0
  541. package/src/modes/components/message-frame.ts +88 -0
  542. package/src/modes/components/model-selector.ts +1271 -0
  543. package/src/modes/components/oauth-selector.ts +368 -0
  544. package/src/modes/components/omfg-panel.ts +141 -0
  545. package/src/modes/components/overlay-box.ts +108 -0
  546. package/src/modes/components/plan-review-overlay.ts +820 -0
  547. package/src/modes/components/plan-toc.ts +138 -0
  548. package/src/modes/components/plugin-selector.ts +95 -0
  549. package/src/modes/components/plugin-settings.ts +722 -0
  550. package/src/modes/components/queue-mode-selector.ts +56 -0
  551. package/src/modes/components/read-tool-group.ts +670 -0
  552. package/src/modes/components/segment-track.ts +52 -0
  553. package/src/modes/components/session-selector.ts +625 -0
  554. package/src/modes/components/settings-defs.ts +189 -0
  555. package/src/modes/components/settings-selector.ts +651 -0
  556. package/src/modes/components/show-images-selector.ts +45 -0
  557. package/src/modes/components/skill-message.ts +89 -0
  558. package/src/modes/components/status-line/component.ts +869 -0
  559. package/src/modes/components/status-line/context-thresholds.ts +79 -0
  560. package/src/modes/components/status-line/git-utils.ts +42 -0
  561. package/src/modes/components/status-line/index.ts +5 -0
  562. package/src/modes/components/status-line/presets.ts +106 -0
  563. package/src/modes/components/status-line/segments.ts +584 -0
  564. package/src/modes/components/status-line/separators.ts +55 -0
  565. package/src/modes/components/status-line/token-rate.ts +66 -0
  566. package/src/modes/components/status-line/types.ts +108 -0
  567. package/src/modes/components/theme-selector.ts +63 -0
  568. package/src/modes/components/thinking-selector.ts +52 -0
  569. package/src/modes/components/tiny-title-download-progress.ts +90 -0
  570. package/src/modes/components/tips.txt +19 -0
  571. package/src/modes/components/todo-reminder.ts +38 -0
  572. package/src/modes/components/tool-execution.ts +1024 -0
  573. package/src/modes/components/transcript-container.ts +608 -0
  574. package/src/modes/components/tree-selector.ts +978 -0
  575. package/src/modes/components/ttsr-notification.ts +122 -0
  576. package/src/modes/components/user-message-selector.ts +227 -0
  577. package/src/modes/components/user-message.ts +66 -0
  578. package/src/modes/components/visual-truncate.ts +63 -0
  579. package/src/modes/components/welcome.ts +493 -0
  580. package/src/modes/controllers/btw-controller.ts +105 -0
  581. package/src/modes/controllers/command-controller-shared.ts +109 -0
  582. package/src/modes/controllers/command-controller.ts +1566 -0
  583. package/src/modes/controllers/event-controller.ts +1054 -0
  584. package/src/modes/controllers/extension-ui-controller.ts +886 -0
  585. package/src/modes/controllers/input-controller.ts +1073 -0
  586. package/src/modes/controllers/mcp-command-controller.ts +2017 -0
  587. package/src/modes/controllers/omfg-controller.ts +283 -0
  588. package/src/modes/controllers/omfg-rule.ts +647 -0
  589. package/src/modes/controllers/selector-controller.ts +1108 -0
  590. package/src/modes/controllers/ssh-command-controller.ts +384 -0
  591. package/src/modes/controllers/streaming-reveal.ts +279 -0
  592. package/src/modes/controllers/tan-command-controller.ts +173 -0
  593. package/src/modes/controllers/todo-command-controller.ts +485 -0
  594. package/src/modes/data/emojis.json +1 -0
  595. package/src/modes/emoji-autocomplete.ts +285 -0
  596. package/src/modes/gradient-highlight.ts +87 -0
  597. package/src/modes/image-references.ts +117 -0
  598. package/src/modes/index.ts +17 -0
  599. package/src/modes/interactive-mode.ts +3370 -0
  600. package/src/modes/internal-url-autocomplete.ts +143 -0
  601. package/src/modes/loop-limit.ts +140 -0
  602. package/src/modes/magic-keywords.ts +20 -0
  603. package/src/modes/markdown-prose.ts +247 -0
  604. package/src/modes/oauth-manual-input.ts +69 -0
  605. package/src/modes/orchestrate.ts +42 -0
  606. package/src/modes/print-mode.ts +126 -0
  607. package/src/modes/prompt-action-autocomplete.ts +260 -0
  608. package/src/modes/rpc/host-tools.ts +186 -0
  609. package/src/modes/rpc/host-uris.ts +235 -0
  610. package/src/modes/rpc/rpc-client.ts +963 -0
  611. package/src/modes/rpc/rpc-mode.ts +947 -0
  612. package/src/modes/rpc/rpc-subagents.ts +265 -0
  613. package/src/modes/rpc/rpc-types.ts +458 -0
  614. package/src/modes/runtime-init.ts +116 -0
  615. package/src/modes/session-observer-registry.ts +146 -0
  616. package/src/modes/setup-version.ts +11 -0
  617. package/src/modes/setup-wizard/index.ts +99 -0
  618. package/src/modes/setup-wizard/lazy.ts +16 -0
  619. package/src/modes/setup-wizard/scenes/glyph.ts +96 -0
  620. package/src/modes/setup-wizard/scenes/outro.ts +35 -0
  621. package/src/modes/setup-wizard/scenes/providers.ts +69 -0
  622. package/src/modes/setup-wizard/scenes/sign-in.ts +205 -0
  623. package/src/modes/setup-wizard/scenes/splash.ts +201 -0
  624. package/src/modes/setup-wizard/scenes/theme.ts +299 -0
  625. package/src/modes/setup-wizard/scenes/types.ts +48 -0
  626. package/src/modes/setup-wizard/scenes/web-search.ts +129 -0
  627. package/src/modes/setup-wizard/wizard-overlay.ts +275 -0
  628. package/src/modes/shared.ts +47 -0
  629. package/src/modes/theme/dark.json +95 -0
  630. package/src/modes/theme/defaults/alabaster.json +93 -0
  631. package/src/modes/theme/defaults/amethyst.json +96 -0
  632. package/src/modes/theme/defaults/anthracite.json +93 -0
  633. package/src/modes/theme/defaults/basalt.json +91 -0
  634. package/src/modes/theme/defaults/birch.json +95 -0
  635. package/src/modes/theme/defaults/dark-abyss.json +91 -0
  636. package/src/modes/theme/defaults/dark-arctic.json +104 -0
  637. package/src/modes/theme/defaults/dark-aurora.json +95 -0
  638. package/src/modes/theme/defaults/dark-catppuccin.json +107 -0
  639. package/src/modes/theme/defaults/dark-cavern.json +91 -0
  640. package/src/modes/theme/defaults/dark-copper.json +95 -0
  641. package/src/modes/theme/defaults/dark-cosmos.json +90 -0
  642. package/src/modes/theme/defaults/dark-cyberpunk.json +102 -0
  643. package/src/modes/theme/defaults/dark-dracula.json +98 -0
  644. package/src/modes/theme/defaults/dark-eclipse.json +91 -0
  645. package/src/modes/theme/defaults/dark-ember.json +95 -0
  646. package/src/modes/theme/defaults/dark-equinox.json +90 -0
  647. package/src/modes/theme/defaults/dark-forest.json +96 -0
  648. package/src/modes/theme/defaults/dark-github.json +105 -0
  649. package/src/modes/theme/defaults/dark-gruvbox.json +112 -0
  650. package/src/modes/theme/defaults/dark-lavender.json +95 -0
  651. package/src/modes/theme/defaults/dark-lunar.json +89 -0
  652. package/src/modes/theme/defaults/dark-midnight.json +95 -0
  653. package/src/modes/theme/defaults/dark-monochrome.json +94 -0
  654. package/src/modes/theme/defaults/dark-monokai.json +98 -0
  655. package/src/modes/theme/defaults/dark-nebula.json +90 -0
  656. package/src/modes/theme/defaults/dark-nord.json +97 -0
  657. package/src/modes/theme/defaults/dark-ocean.json +101 -0
  658. package/src/modes/theme/defaults/dark-one.json +100 -0
  659. package/src/modes/theme/defaults/dark-poimandres.json +142 -0
  660. package/src/modes/theme/defaults/dark-rainforest.json +91 -0
  661. package/src/modes/theme/defaults/dark-reef.json +91 -0
  662. package/src/modes/theme/defaults/dark-retro.json +92 -0
  663. package/src/modes/theme/defaults/dark-rose-pine.json +96 -0
  664. package/src/modes/theme/defaults/dark-sakura.json +95 -0
  665. package/src/modes/theme/defaults/dark-slate.json +95 -0
  666. package/src/modes/theme/defaults/dark-solarized.json +97 -0
  667. package/src/modes/theme/defaults/dark-solstice.json +90 -0
  668. package/src/modes/theme/defaults/dark-starfall.json +91 -0
  669. package/src/modes/theme/defaults/dark-sunset.json +99 -0
  670. package/src/modes/theme/defaults/dark-swamp.json +90 -0
  671. package/src/modes/theme/defaults/dark-synthwave.json +103 -0
  672. package/src/modes/theme/defaults/dark-taiga.json +91 -0
  673. package/src/modes/theme/defaults/dark-terminal.json +95 -0
  674. package/src/modes/theme/defaults/dark-tokyo-night.json +101 -0
  675. package/src/modes/theme/defaults/dark-tundra.json +91 -0
  676. package/src/modes/theme/defaults/dark-twilight.json +91 -0
  677. package/src/modes/theme/defaults/dark-volcanic.json +91 -0
  678. package/src/modes/theme/defaults/graphite.json +92 -0
  679. package/src/modes/theme/defaults/index.ts +199 -0
  680. package/src/modes/theme/defaults/light-arctic.json +107 -0
  681. package/src/modes/theme/defaults/light-aurora-day.json +91 -0
  682. package/src/modes/theme/defaults/light-canyon.json +91 -0
  683. package/src/modes/theme/defaults/light-catppuccin.json +106 -0
  684. package/src/modes/theme/defaults/light-cirrus.json +90 -0
  685. package/src/modes/theme/defaults/light-coral.json +95 -0
  686. package/src/modes/theme/defaults/light-cyberpunk.json +96 -0
  687. package/src/modes/theme/defaults/light-dawn.json +90 -0
  688. package/src/modes/theme/defaults/light-dunes.json +91 -0
  689. package/src/modes/theme/defaults/light-eucalyptus.json +95 -0
  690. package/src/modes/theme/defaults/light-forest.json +100 -0
  691. package/src/modes/theme/defaults/light-frost.json +95 -0
  692. package/src/modes/theme/defaults/light-github.json +115 -0
  693. package/src/modes/theme/defaults/light-glacier.json +91 -0
  694. package/src/modes/theme/defaults/light-gruvbox.json +108 -0
  695. package/src/modes/theme/defaults/light-haze.json +90 -0
  696. package/src/modes/theme/defaults/light-honeycomb.json +95 -0
  697. package/src/modes/theme/defaults/light-lagoon.json +91 -0
  698. package/src/modes/theme/defaults/light-lavender.json +95 -0
  699. package/src/modes/theme/defaults/light-meadow.json +91 -0
  700. package/src/modes/theme/defaults/light-mint.json +95 -0
  701. package/src/modes/theme/defaults/light-monochrome.json +101 -0
  702. package/src/modes/theme/defaults/light-ocean.json +99 -0
  703. package/src/modes/theme/defaults/light-one.json +99 -0
  704. package/src/modes/theme/defaults/light-opal.json +91 -0
  705. package/src/modes/theme/defaults/light-orchard.json +91 -0
  706. package/src/modes/theme/defaults/light-paper.json +95 -0
  707. package/src/modes/theme/defaults/light-poimandres.json +142 -0
  708. package/src/modes/theme/defaults/light-prism.json +90 -0
  709. package/src/modes/theme/defaults/light-retro.json +98 -0
  710. package/src/modes/theme/defaults/light-sand.json +95 -0
  711. package/src/modes/theme/defaults/light-savanna.json +91 -0
  712. package/src/modes/theme/defaults/light-solarized.json +102 -0
  713. package/src/modes/theme/defaults/light-soleil.json +90 -0
  714. package/src/modes/theme/defaults/light-sunset.json +99 -0
  715. package/src/modes/theme/defaults/light-synthwave.json +98 -0
  716. package/src/modes/theme/defaults/light-tokyo-night.json +111 -0
  717. package/src/modes/theme/defaults/light-wetland.json +91 -0
  718. package/src/modes/theme/defaults/light-zenith.json +89 -0
  719. package/src/modes/theme/defaults/limestone.json +94 -0
  720. package/src/modes/theme/defaults/mahogany.json +97 -0
  721. package/src/modes/theme/defaults/marble.json +93 -0
  722. package/src/modes/theme/defaults/obsidian.json +91 -0
  723. package/src/modes/theme/defaults/onyx.json +91 -0
  724. package/src/modes/theme/defaults/pearl.json +93 -0
  725. package/src/modes/theme/defaults/porcelain.json +91 -0
  726. package/src/modes/theme/defaults/quartz.json +96 -0
  727. package/src/modes/theme/defaults/sandstone.json +95 -0
  728. package/src/modes/theme/defaults/titanium.json +90 -0
  729. package/src/modes/theme/light.json +93 -0
  730. package/src/modes/theme/mermaid-cache.ts +29 -0
  731. package/src/modes/theme/shimmer.ts +235 -0
  732. package/src/modes/theme/theme-schema.json +459 -0
  733. package/src/modes/theme/theme.ts +2676 -0
  734. package/src/modes/turn-budget.ts +31 -0
  735. package/src/modes/types.ts +359 -0
  736. package/src/modes/ultrathink.ts +41 -0
  737. package/src/modes/utils/context-usage.ts +339 -0
  738. package/src/modes/utils/copy-targets.ts +360 -0
  739. package/src/modes/utils/hotkeys-markdown.ts +61 -0
  740. package/src/modes/utils/keybinding-matchers.ts +51 -0
  741. package/src/modes/utils/tools-markdown.ts +27 -0
  742. package/src/modes/utils/ui-helpers.ts +801 -0
  743. package/src/modes/workflow.ts +42 -0
  744. package/src/plan-mode/approved-plan.ts +186 -0
  745. package/src/plan-mode/plan-handoff.ts +37 -0
  746. package/src/plan-mode/plan-protection.ts +31 -0
  747. package/src/plan-mode/state.ts +6 -0
  748. package/src/priority.json +41 -0
  749. package/src/prompts/agents/designer.md +66 -0
  750. package/src/prompts/agents/explore.md +58 -0
  751. package/src/prompts/agents/frontmatter.md +11 -0
  752. package/src/prompts/agents/init.md +33 -0
  753. package/src/prompts/agents/librarian.md +119 -0
  754. package/src/prompts/agents/oracle.md +55 -0
  755. package/src/prompts/agents/plan.md +48 -0
  756. package/src/prompts/agents/reviewer.md +140 -0
  757. package/src/prompts/agents/task.md +16 -0
  758. package/src/prompts/ci-green-request.md +36 -0
  759. package/src/prompts/dry-balance-bench.md +8 -0
  760. package/src/prompts/goals/goal-budget-limit.md +16 -0
  761. package/src/prompts/goals/goal-continuation.md +28 -0
  762. package/src/prompts/goals/goal-mode-active.md +23 -0
  763. package/src/prompts/memories/consolidation.md +30 -0
  764. package/src/prompts/memories/read-path.md +11 -0
  765. package/src/prompts/memories/stage_one_input.md +6 -0
  766. package/src/prompts/memories/stage_one_system.md +21 -0
  767. package/src/prompts/review-custom-request.md +22 -0
  768. package/src/prompts/review-headless-request.md +16 -0
  769. package/src/prompts/review-request.md +69 -0
  770. package/src/prompts/steering/user-interjection.md +10 -0
  771. package/src/prompts/system/agent-creation-architect.md +50 -0
  772. package/src/prompts/system/agent-creation-user.md +6 -0
  773. package/src/prompts/system/auto-continue.md +1 -0
  774. package/src/prompts/system/auto-thinking-difficulty-local.md +14 -0
  775. package/src/prompts/system/auto-thinking-difficulty.md +12 -0
  776. package/src/prompts/system/background-tan-dispatch.md +8 -0
  777. package/src/prompts/system/btw-user.md +8 -0
  778. package/src/prompts/system/commit-message-system.md +14 -0
  779. package/src/prompts/system/custom-system-prompt.md +64 -0
  780. package/src/prompts/system/eager-todo.md +13 -0
  781. package/src/prompts/system/empty-stop-retry.md +6 -0
  782. package/src/prompts/system/irc-incoming.md +7 -0
  783. package/src/prompts/system/manual-continue.md +7 -0
  784. package/src/prompts/system/memory-consolidation-system.md +8 -0
  785. package/src/prompts/system/memory-extraction-system.md +26 -0
  786. package/src/prompts/system/omfg-user.md +50 -0
  787. package/src/prompts/system/orchestrate-notice.md +40 -0
  788. package/src/prompts/system/plan-mode-active.md +109 -0
  789. package/src/prompts/system/plan-mode-approved.md +25 -0
  790. package/src/prompts/system/plan-mode-compact-instructions.md +16 -0
  791. package/src/prompts/system/plan-mode-reference.md +11 -0
  792. package/src/prompts/system/plan-mode-subagent.md +33 -0
  793. package/src/prompts/system/plan-mode-tool-decision-reminder.md +9 -0
  794. package/src/prompts/system/project-prompt.md +52 -0
  795. package/src/prompts/system/subagent-system-prompt.md +64 -0
  796. package/src/prompts/system/subagent-user-prompt.md +3 -0
  797. package/src/prompts/system/subagent-yield-reminder.md +12 -0
  798. package/src/prompts/system/system-prompt.md +258 -0
  799. package/src/prompts/system/tiny-title-system.md +8 -0
  800. package/src/prompts/system/title-system.md +16 -0
  801. package/src/prompts/system/ttsr-interrupt.md +7 -0
  802. package/src/prompts/system/ttsr-tool-reminder.md +5 -0
  803. package/src/prompts/system/ultrathink-notice.md +3 -0
  804. package/src/prompts/system/web-search.md +25 -0
  805. package/src/prompts/system/workflow-notice.md +70 -0
  806. package/src/prompts/tools/apply-patch.md +65 -0
  807. package/src/prompts/tools/ask.md +30 -0
  808. package/src/prompts/tools/ast-edit.md +39 -0
  809. package/src/prompts/tools/ast-grep.md +42 -0
  810. package/src/prompts/tools/async-result.md +8 -0
  811. package/src/prompts/tools/bash.md +46 -0
  812. package/src/prompts/tools/browser.md +73 -0
  813. package/src/prompts/tools/checkpoint.md +16 -0
  814. package/src/prompts/tools/debug.md +34 -0
  815. package/src/prompts/tools/eval.md +92 -0
  816. package/src/prompts/tools/find.md +36 -0
  817. package/src/prompts/tools/github.md +21 -0
  818. package/src/prompts/tools/goal.md +18 -0
  819. package/src/prompts/tools/image-gen.md +7 -0
  820. package/src/prompts/tools/inspect-image-system.md +20 -0
  821. package/src/prompts/tools/inspect-image.md +32 -0
  822. package/src/prompts/tools/irc.md +59 -0
  823. package/src/prompts/tools/job.md +19 -0
  824. package/src/prompts/tools/lsp-late-diagnostic.md +8 -0
  825. package/src/prompts/tools/lsp.md +42 -0
  826. package/src/prompts/tools/memory-edit.md +8 -0
  827. package/src/prompts/tools/patch.md +70 -0
  828. package/src/prompts/tools/read.md +84 -0
  829. package/src/prompts/tools/recall.md +5 -0
  830. package/src/prompts/tools/reflect.md +5 -0
  831. package/src/prompts/tools/render-mermaid.md +9 -0
  832. package/src/prompts/tools/replace.md +30 -0
  833. package/src/prompts/tools/resolve.md +9 -0
  834. package/src/prompts/tools/retain.md +6 -0
  835. package/src/prompts/tools/rewind.md +13 -0
  836. package/src/prompts/tools/search-tool-bm25.md +32 -0
  837. package/src/prompts/tools/search.md +24 -0
  838. package/src/prompts/tools/ssh.md +31 -0
  839. package/src/prompts/tools/task-summary.md +17 -0
  840. package/src/prompts/tools/task.md +88 -0
  841. package/src/prompts/tools/todo.md +62 -0
  842. package/src/prompts/tools/web-search.md +10 -0
  843. package/src/prompts/tools/write.md +14 -0
  844. package/src/registry/agent-lifecycle.ts +218 -0
  845. package/src/registry/agent-registry.ts +151 -0
  846. package/src/sdk.ts +2558 -0
  847. package/src/secrets/index.ts +123 -0
  848. package/src/secrets/obfuscator.ts +298 -0
  849. package/src/secrets/regex.ts +21 -0
  850. package/src/session/agent-session.ts +10121 -0
  851. package/src/session/agent-storage.ts +455 -0
  852. package/src/session/artifacts.ts +135 -0
  853. package/src/session/auth-broker-config.ts +131 -0
  854. package/src/session/auth-storage.ts +29 -0
  855. package/src/session/blob-store.ts +255 -0
  856. package/src/session/client-bridge.ts +85 -0
  857. package/src/session/history-storage.ts +348 -0
  858. package/src/session/indexed-session-storage.ts +430 -0
  859. package/src/session/messages.ts +541 -0
  860. package/src/session/redis-session-storage.ts +170 -0
  861. package/src/session/session-dump-format.ts +209 -0
  862. package/src/session/session-history-format.ts +246 -0
  863. package/src/session/session-manager.ts +3676 -0
  864. package/src/session/session-storage.ts +529 -0
  865. package/src/session/shake-types.ts +43 -0
  866. package/src/session/sql-session-storage.ts +314 -0
  867. package/src/session/streaming-output.ts +1330 -0
  868. package/src/session/tool-choice-queue.ts +213 -0
  869. package/src/session/yield-queue.ts +173 -0
  870. package/src/slash-commands/acp-builtins.ts +70 -0
  871. package/src/slash-commands/builtin-registry.ts +1798 -0
  872. package/src/slash-commands/helpers/context-report.ts +39 -0
  873. package/src/slash-commands/helpers/format.ts +46 -0
  874. package/src/slash-commands/helpers/marketplace-manager.ts +25 -0
  875. package/src/slash-commands/helpers/mcp.ts +532 -0
  876. package/src/slash-commands/helpers/parse.ts +85 -0
  877. package/src/slash-commands/helpers/ssh.ts +195 -0
  878. package/src/slash-commands/helpers/stats-dashboard.ts +85 -0
  879. package/src/slash-commands/helpers/todo.ts +279 -0
  880. package/src/slash-commands/helpers/usage-report.ts +95 -0
  881. package/src/slash-commands/marketplace-install-parser.ts +99 -0
  882. package/src/slash-commands/types.ts +135 -0
  883. package/src/ssh/config-writer.ts +183 -0
  884. package/src/ssh/connection-manager.ts +509 -0
  885. package/src/ssh/ssh-executor.ts +189 -0
  886. package/src/ssh/sshfs-mount.ts +140 -0
  887. package/src/ssh/utils.ts +8 -0
  888. package/src/stt/downloader.ts +71 -0
  889. package/src/stt/index.ts +3 -0
  890. package/src/stt/recorder.ts +351 -0
  891. package/src/stt/setup.ts +52 -0
  892. package/src/stt/stt-controller.ts +160 -0
  893. package/src/stt/transcribe.py +70 -0
  894. package/src/stt/transcriber.ts +91 -0
  895. package/src/stubs/natives/index.ts +814 -0
  896. package/src/stubs/natives/package.json +7 -0
  897. package/src/stubs/tui/index.ts +282 -0
  898. package/src/stubs/tui/package.json +7 -0
  899. package/src/system-prompt.ts +611 -0
  900. package/src/task/agents.ts +167 -0
  901. package/src/task/commands.ts +132 -0
  902. package/src/task/discovery.ts +122 -0
  903. package/src/task/executor.ts +2133 -0
  904. package/src/task/index.ts +1419 -0
  905. package/src/task/name-generator.ts +1577 -0
  906. package/src/task/omp-command.ts +26 -0
  907. package/src/task/output-manager.ts +88 -0
  908. package/src/task/parallel.ts +116 -0
  909. package/src/task/render.ts +1381 -0
  910. package/src/task/repair-args.ts +129 -0
  911. package/src/task/subprocess-tool-registry.ts +88 -0
  912. package/src/task/types.ts +336 -0
  913. package/src/task/worktree.ts +514 -0
  914. package/src/telemetry-export.ts +144 -0
  915. package/src/thinking.ts +167 -0
  916. package/src/tiny/compiled-runtime.ts +179 -0
  917. package/src/tiny/device.ts +111 -0
  918. package/src/tiny/dtype.ts +101 -0
  919. package/src/tiny/models.ts +242 -0
  920. package/src/tiny/text.ts +165 -0
  921. package/src/tiny/title-client.ts +543 -0
  922. package/src/tiny/title-protocol.ts +56 -0
  923. package/src/tiny/worker.ts +568 -0
  924. package/src/tool-discovery/mode.ts +24 -0
  925. package/src/tool-discovery/tool-index.ts +256 -0
  926. package/src/tools/approval.ts +189 -0
  927. package/src/tools/archive-reader.ts +721 -0
  928. package/src/tools/ask.ts +928 -0
  929. package/src/tools/ast-edit.ts +642 -0
  930. package/src/tools/ast-grep.ts +452 -0
  931. package/src/tools/auto-generated-guard.ts +322 -0
  932. package/src/tools/bash-command-fixup.ts +37 -0
  933. package/src/tools/bash-interactive.ts +408 -0
  934. package/src/tools/bash-interceptor.ts +67 -0
  935. package/src/tools/bash-pty-selection.ts +14 -0
  936. package/src/tools/bash-skill-urls.ts +248 -0
  937. package/src/tools/bash.ts +1386 -0
  938. package/src/tools/browser/attach.ts +175 -0
  939. package/src/tools/browser/launch.ts +660 -0
  940. package/src/tools/browser/readable.ts +112 -0
  941. package/src/tools/browser/registry.ts +197 -0
  942. package/src/tools/browser/render.ts +216 -0
  943. package/src/tools/browser/tab-protocol.ts +105 -0
  944. package/src/tools/browser/tab-supervisor.ts +628 -0
  945. package/src/tools/browser/tab-worker-entry.ts +21 -0
  946. package/src/tools/browser/tab-worker.ts +1226 -0
  947. package/src/tools/browser.ts +343 -0
  948. package/src/tools/checkpoint.ts +136 -0
  949. package/src/tools/conflict-detect.ts +718 -0
  950. package/src/tools/context.ts +39 -0
  951. package/src/tools/debug.ts +1067 -0
  952. package/src/tools/eval-backends.ts +27 -0
  953. package/src/tools/eval-render.ts +752 -0
  954. package/src/tools/eval.ts +577 -0
  955. package/src/tools/fetch.ts +1926 -0
  956. package/src/tools/file-recorder.ts +35 -0
  957. package/src/tools/find.ts +609 -0
  958. package/src/tools/fs-cache-invalidation.ts +28 -0
  959. package/src/tools/gh-cache-invalidation.ts +255 -0
  960. package/src/tools/gh-format.ts +12 -0
  961. package/src/tools/gh-renderer.ts +481 -0
  962. package/src/tools/gh.ts +3720 -0
  963. package/src/tools/github-cache.ts +637 -0
  964. package/src/tools/grouped-file-output.ts +210 -0
  965. package/src/tools/image-gen.ts +1517 -0
  966. package/src/tools/index.ts +599 -0
  967. package/src/tools/inspect-image-renderer.ts +132 -0
  968. package/src/tools/inspect-image.ts +174 -0
  969. package/src/tools/irc.ts +723 -0
  970. package/src/tools/job.ts +557 -0
  971. package/src/tools/json-tree.ts +243 -0
  972. package/src/tools/jtd-to-json-schema.ts +219 -0
  973. package/src/tools/jtd-to-typescript.ts +136 -0
  974. package/src/tools/jtd-utils.ts +102 -0
  975. package/src/tools/list-limit.ts +40 -0
  976. package/src/tools/match-line-format.ts +20 -0
  977. package/src/tools/memory-edit.ts +59 -0
  978. package/src/tools/memory-recall.ts +100 -0
  979. package/src/tools/memory-reflect.ts +88 -0
  980. package/src/tools/memory-render.ts +202 -0
  981. package/src/tools/memory-retain.ts +91 -0
  982. package/src/tools/output-meta.ts +754 -0
  983. package/src/tools/output-schema-validator.ts +132 -0
  984. package/src/tools/path-utils.ts +1054 -0
  985. package/src/tools/plan-mode-guard.ts +108 -0
  986. package/src/tools/puppeteer/00_stealth_tampering.txt +63 -0
  987. package/src/tools/puppeteer/01_stealth_activity.txt +20 -0
  988. package/src/tools/puppeteer/02_stealth_hairline.txt +11 -0
  989. package/src/tools/puppeteer/03_stealth_botd.txt +384 -0
  990. package/src/tools/puppeteer/04_stealth_iframe.txt +81 -0
  991. package/src/tools/puppeteer/05_stealth_webgl.txt +75 -0
  992. package/src/tools/puppeteer/06_stealth_screen.txt +72 -0
  993. package/src/tools/puppeteer/07_stealth_fonts.txt +97 -0
  994. package/src/tools/puppeteer/08_stealth_audio.txt +51 -0
  995. package/src/tools/puppeteer/09_stealth_locale.txt +46 -0
  996. package/src/tools/puppeteer/10_stealth_plugins.txt +206 -0
  997. package/src/tools/puppeteer/11_stealth_hardware.txt +8 -0
  998. package/src/tools/puppeteer/12_stealth_codecs.txt +40 -0
  999. package/src/tools/puppeteer/13_stealth_worker.txt +74 -0
  1000. package/src/tools/read.ts +2929 -0
  1001. package/src/tools/render-mermaid.ts +69 -0
  1002. package/src/tools/render-utils.ts +838 -0
  1003. package/src/tools/renderers.ts +77 -0
  1004. package/src/tools/report-tool-issue.ts +534 -0
  1005. package/src/tools/resolve.ts +276 -0
  1006. package/src/tools/review.ts +253 -0
  1007. package/src/tools/search-tool-bm25.ts +351 -0
  1008. package/src/tools/search.ts +1580 -0
  1009. package/src/tools/sqlite-reader.ts +828 -0
  1010. package/src/tools/ssh.ts +349 -0
  1011. package/src/tools/todo.ts +982 -0
  1012. package/src/tools/tool-errors.ts +62 -0
  1013. package/src/tools/tool-result.ts +94 -0
  1014. package/src/tools/tool-timeouts.ts +30 -0
  1015. package/src/tools/tts.ts +133 -0
  1016. package/src/tools/write.ts +1217 -0
  1017. package/src/tools/yield.ts +269 -0
  1018. package/src/tui/code-cell.ts +216 -0
  1019. package/src/tui/file-list.ts +55 -0
  1020. package/src/tui/hyperlink.ts +175 -0
  1021. package/src/tui/index.ts +12 -0
  1022. package/src/tui/output-block.ts +240 -0
  1023. package/src/tui/status-line.ts +54 -0
  1024. package/src/tui/tree-list.ts +84 -0
  1025. package/src/tui/types.ts +15 -0
  1026. package/src/tui/utils.ts +103 -0
  1027. package/src/utils/block-context.ts +312 -0
  1028. package/src/utils/changelog.ts +132 -0
  1029. package/src/utils/clipboard.ts +193 -0
  1030. package/src/utils/command-args.ts +76 -0
  1031. package/src/utils/commit-message-generator.ts +151 -0
  1032. package/src/utils/edit-mode.ts +41 -0
  1033. package/src/utils/enhanced-paste.ts +230 -0
  1034. package/src/utils/event-bus.ts +33 -0
  1035. package/src/utils/external-editor.ts +65 -0
  1036. package/src/utils/file-display-mode.ts +45 -0
  1037. package/src/utils/file-mentions.ts +281 -0
  1038. package/src/utils/git.ts +1833 -0
  1039. package/src/utils/image-loading.ts +132 -0
  1040. package/src/utils/image-resize.ts +309 -0
  1041. package/src/utils/jj.ts +248 -0
  1042. package/src/utils/lang-from-path.ts +239 -0
  1043. package/src/utils/markit.ts +89 -0
  1044. package/src/utils/open.ts +55 -0
  1045. package/src/utils/session-color.ts +68 -0
  1046. package/src/utils/shell-snapshot.ts +187 -0
  1047. package/src/utils/sixel.ts +69 -0
  1048. package/src/utils/title-generator.ts +373 -0
  1049. package/src/utils/tool-choice.ts +33 -0
  1050. package/src/utils/tools-manager.ts +363 -0
  1051. package/src/web/kagi.ts +305 -0
  1052. package/src/web/parallel.ts +353 -0
  1053. package/src/web/scrapers/artifacthub.ts +207 -0
  1054. package/src/web/scrapers/arxiv.ts +83 -0
  1055. package/src/web/scrapers/aur.ts +162 -0
  1056. package/src/web/scrapers/biorxiv.ts +133 -0
  1057. package/src/web/scrapers/bluesky.ts +262 -0
  1058. package/src/web/scrapers/brew.ts +172 -0
  1059. package/src/web/scrapers/cheatsh.ts +68 -0
  1060. package/src/web/scrapers/chocolatey.ts +196 -0
  1061. package/src/web/scrapers/choosealicense.ts +95 -0
  1062. package/src/web/scrapers/cisa-kev.ts +87 -0
  1063. package/src/web/scrapers/clojars.ts +154 -0
  1064. package/src/web/scrapers/coingecko.ts +177 -0
  1065. package/src/web/scrapers/crates-io.ts +97 -0
  1066. package/src/web/scrapers/crossref.ts +136 -0
  1067. package/src/web/scrapers/devto.ts +147 -0
  1068. package/src/web/scrapers/discogs.ts +306 -0
  1069. package/src/web/scrapers/discourse.ts +197 -0
  1070. package/src/web/scrapers/dockerhub.ts +138 -0
  1071. package/src/web/scrapers/docs-rs.ts +653 -0
  1072. package/src/web/scrapers/fdroid.ts +134 -0
  1073. package/src/web/scrapers/firefox-addons.ts +191 -0
  1074. package/src/web/scrapers/flathub.ts +223 -0
  1075. package/src/web/scrapers/github-gist.ts +58 -0
  1076. package/src/web/scrapers/github.ts +704 -0
  1077. package/src/web/scrapers/gitlab.ts +401 -0
  1078. package/src/web/scrapers/go-pkg.ts +266 -0
  1079. package/src/web/scrapers/hackage.ts +140 -0
  1080. package/src/web/scrapers/hackernews.ts +189 -0
  1081. package/src/web/scrapers/hex.ts +105 -0
  1082. package/src/web/scrapers/huggingface.ts +321 -0
  1083. package/src/web/scrapers/iacr.ts +89 -0
  1084. package/src/web/scrapers/index.ts +252 -0
  1085. package/src/web/scrapers/jetbrains-marketplace.ts +159 -0
  1086. package/src/web/scrapers/lemmy.ts +203 -0
  1087. package/src/web/scrapers/lobsters.ts +175 -0
  1088. package/src/web/scrapers/mastodon.ts +292 -0
  1089. package/src/web/scrapers/maven.ts +138 -0
  1090. package/src/web/scrapers/mdn.ts +173 -0
  1091. package/src/web/scrapers/metacpan.ts +222 -0
  1092. package/src/web/scrapers/musicbrainz.ts +250 -0
  1093. package/src/web/scrapers/npm.ts +98 -0
  1094. package/src/web/scrapers/nuget.ts +183 -0
  1095. package/src/web/scrapers/nvd.ts +222 -0
  1096. package/src/web/scrapers/ollama.ts +239 -0
  1097. package/src/web/scrapers/open-vsx.ts +106 -0
  1098. package/src/web/scrapers/opencorporates.ts +292 -0
  1099. package/src/web/scrapers/openlibrary.ts +336 -0
  1100. package/src/web/scrapers/orcid.ts +286 -0
  1101. package/src/web/scrapers/osv.ts +176 -0
  1102. package/src/web/scrapers/packagist.ts +160 -0
  1103. package/src/web/scrapers/pub-dev.ts +143 -0
  1104. package/src/web/scrapers/pubmed.ts +211 -0
  1105. package/src/web/scrapers/pypi.ts +112 -0
  1106. package/src/web/scrapers/rawg.ts +110 -0
  1107. package/src/web/scrapers/readthedocs.ts +120 -0
  1108. package/src/web/scrapers/reddit.ts +95 -0
  1109. package/src/web/scrapers/repology.ts +251 -0
  1110. package/src/web/scrapers/rfc.ts +201 -0
  1111. package/src/web/scrapers/rubygems.ts +103 -0
  1112. package/src/web/scrapers/searchcode.ts +189 -0
  1113. package/src/web/scrapers/sec-edgar.ts +261 -0
  1114. package/src/web/scrapers/semantic-scholar.ts +171 -0
  1115. package/src/web/scrapers/snapcraft.ts +187 -0
  1116. package/src/web/scrapers/sourcegraph.ts +336 -0
  1117. package/src/web/scrapers/spdx.ts +108 -0
  1118. package/src/web/scrapers/spotify.ts +198 -0
  1119. package/src/web/scrapers/stackoverflow.ts +120 -0
  1120. package/src/web/scrapers/terraform.ts +277 -0
  1121. package/src/web/scrapers/tldr.ts +47 -0
  1122. package/src/web/scrapers/twitter.ts +94 -0
  1123. package/src/web/scrapers/types.ts +397 -0
  1124. package/src/web/scrapers/utils.ts +109 -0
  1125. package/src/web/scrapers/vimeo.ts +133 -0
  1126. package/src/web/scrapers/vscode-marketplace.ts +187 -0
  1127. package/src/web/scrapers/w3c.ts +156 -0
  1128. package/src/web/scrapers/wikidata.ts +344 -0
  1129. package/src/web/scrapers/wikipedia.ts +84 -0
  1130. package/src/web/scrapers/youtube.ts +325 -0
  1131. package/src/web/search/index.ts +292 -0
  1132. package/src/web/search/provider.ts +157 -0
  1133. package/src/web/search/providers/anthropic.ts +318 -0
  1134. package/src/web/search/providers/base.ts +89 -0
  1135. package/src/web/search/providers/brave.ts +152 -0
  1136. package/src/web/search/providers/codex.ts +591 -0
  1137. package/src/web/search/providers/exa.ts +400 -0
  1138. package/src/web/search/providers/gemini.ts +460 -0
  1139. package/src/web/search/providers/jina.ts +111 -0
  1140. package/src/web/search/providers/kagi.ts +86 -0
  1141. package/src/web/search/providers/kimi.ts +196 -0
  1142. package/src/web/search/providers/parallel.ts +225 -0
  1143. package/src/web/search/providers/perplexity.ts +730 -0
  1144. package/src/web/search/providers/searxng.ts +313 -0
  1145. package/src/web/search/providers/synthetic.ts +114 -0
  1146. package/src/web/search/providers/tavily.ts +176 -0
  1147. package/src/web/search/providers/utils.ts +128 -0
  1148. package/src/web/search/providers/zai.ts +333 -0
  1149. package/src/web/search/render.ts +262 -0
  1150. package/src/web/search/types.ts +482 -0
  1151. package/src/web/search/utils.ts +17 -0
  1152. package/src/workspace-tree.ts +286 -0
@@ -0,0 +1,2676 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import type { ThinkingLevel } from "@oh-my-pi/pi-agent-core";
4
+ import type { Effort } from "@oh-my-pi/pi-ai";
5
+ import {
6
+ detectMacOSAppearance,
7
+ MacAppearanceObserver,
8
+ type HighlightColors as NativeHighlightColors,
9
+ highlightCode as nativeHighlightCode,
10
+ supportsLanguage as nativeSupportsLanguage,
11
+ } from './stubs/natives/index.ts';
12
+ import type { EditorTheme, MarkdownTheme, SelectListTheme, SymbolTheme } from './stubs/tui/index.ts';
13
+ import { adjustHsv, colorLuma, getCustomThemesDir, isEnoent, logger, relativeLuminance } from "@oh-my-pi/pi-utils";
14
+ import chalk from "chalk";
15
+ import { LRUCache } from "lru-cache/raw";
16
+ import * as z from "zod/v4";
17
+ // Embed theme JSON files at build time
18
+ import darkThemeJson from "./dark.json" with { type: "json" };
19
+ import { defaultThemes } from "./defaults";
20
+ import lightThemeJson from "./light.json" with { type: "json" };
21
+ import { resolveMermaidAscii } from "./mermaid-cache";
22
+
23
+ export { getLanguageFromPath } from "../../utils/lang-from-path";
24
+
25
+ // ============================================================================
26
+ // Symbol Presets
27
+ // ============================================================================
28
+
29
+ export type SymbolPreset = "unicode" | "nerd" | "ascii";
30
+
31
+ /**
32
+ * All available symbol keys organized by category.
33
+ */
34
+ export type SymbolKey =
35
+ // Status Indicators
36
+ | "status.success"
37
+ | "status.error"
38
+ | "status.warning"
39
+ | "status.info"
40
+ | "status.pending"
41
+ | "status.disabled"
42
+ | "status.enabled"
43
+ | "status.running"
44
+ | "status.shadowed"
45
+ | "status.aborted"
46
+ | "status.done"
47
+ // Navigation
48
+ | "nav.cursor"
49
+ | "nav.selected"
50
+ | "nav.expand"
51
+ | "nav.collapse"
52
+ | "nav.back"
53
+ // Tree Connectors
54
+ | "tree.branch"
55
+ | "tree.last"
56
+ | "tree.vertical"
57
+ | "tree.horizontal"
58
+ | "tree.hook"
59
+ // Box Drawing - Rounded
60
+ | "boxRound.topLeft"
61
+ | "boxRound.topRight"
62
+ | "boxRound.bottomLeft"
63
+ | "boxRound.bottomRight"
64
+ | "boxRound.horizontal"
65
+ | "boxRound.vertical"
66
+ // Box Drawing - Sharp
67
+ | "boxSharp.topLeft"
68
+ | "boxSharp.topRight"
69
+ | "boxSharp.bottomLeft"
70
+ | "boxSharp.bottomRight"
71
+ | "boxSharp.horizontal"
72
+ | "boxSharp.vertical"
73
+ | "boxSharp.cross"
74
+ | "boxSharp.teeDown"
75
+ | "boxSharp.teeUp"
76
+ | "boxSharp.teeRight"
77
+ | "boxSharp.teeLeft"
78
+ // Separators
79
+ | "sep.powerline"
80
+ | "sep.powerlineThin"
81
+ | "sep.powerlineLeft"
82
+ | "sep.powerlineRight"
83
+ | "sep.powerlineThinLeft"
84
+ | "sep.powerlineThinRight"
85
+ | "sep.block"
86
+ | "sep.space"
87
+ | "sep.asciiLeft"
88
+ | "sep.asciiRight"
89
+ | "sep.dot"
90
+ | "sep.slash"
91
+ | "sep.pipe"
92
+ // Icons
93
+ | "icon.model"
94
+ | "icon.plan"
95
+ | "icon.goal"
96
+ | "icon.pause"
97
+ | "icon.loop"
98
+ | "icon.folder"
99
+ | "icon.search"
100
+ | "icon.scratchFolder"
101
+ | "icon.file"
102
+ | "icon.git"
103
+ | "icon.branch"
104
+ | "icon.pr"
105
+ | "icon.tokens"
106
+ | "icon.context"
107
+ | "icon.cost"
108
+ | "icon.time"
109
+ | "icon.pi"
110
+ | "icon.agents"
111
+ | "icon.cache"
112
+ | "icon.input"
113
+ | "icon.output"
114
+ | "icon.host"
115
+ | "icon.session"
116
+ | "icon.package"
117
+ | "icon.warning"
118
+ | "icon.rewind"
119
+ | "icon.auto"
120
+ | "icon.fast"
121
+ | "icon.extensionSkill"
122
+ | "icon.extensionTool"
123
+ | "icon.extensionSlashCommand"
124
+ | "icon.extensionMcp"
125
+ | "icon.extensionRule"
126
+ | "icon.extensionHook"
127
+ | "icon.extensionPrompt"
128
+ | "icon.extensionContextFile"
129
+ | "icon.extensionInstruction"
130
+ // STT
131
+ | "icon.mic"
132
+ // Compaction divider
133
+ | "icon.camera"
134
+ // Thinking Levels
135
+ | "thinking.minimal"
136
+ | "thinking.low"
137
+ | "thinking.medium"
138
+ | "thinking.high"
139
+ | "thinking.xhigh"
140
+ | "thinking.autoPending"
141
+ // Checkboxes
142
+ | "checkbox.checked"
143
+ | "checkbox.unchecked"
144
+ // Radio (single-choice)
145
+ | "radio.selected"
146
+ | "radio.unselected"
147
+ // Text Formatting
148
+ | "format.bullet"
149
+ | "format.dash"
150
+ | "format.bracketLeft"
151
+ | "format.bracketRight"
152
+ // Markdown-specific
153
+ | "md.quoteBorder"
154
+ | "md.hrChar"
155
+ | "md.bullet"
156
+ | "md.colorSwatch"
157
+ // Language/file type icons
158
+ | "lang.default"
159
+ | "lang.typescript"
160
+ | "lang.javascript"
161
+ | "lang.python"
162
+ | "lang.rust"
163
+ | "lang.go"
164
+ | "lang.java"
165
+ | "lang.c"
166
+ | "lang.cpp"
167
+ | "lang.csharp"
168
+ | "lang.ruby"
169
+ | "lang.php"
170
+ | "lang.swift"
171
+ | "lang.kotlin"
172
+ | "lang.shell"
173
+ | "lang.html"
174
+ | "lang.css"
175
+ | "lang.json"
176
+ | "lang.yaml"
177
+ | "lang.markdown"
178
+ | "lang.sql"
179
+ | "lang.docker"
180
+ | "lang.lua"
181
+ | "lang.text"
182
+ | "lang.env"
183
+ | "lang.toml"
184
+ | "lang.xml"
185
+ | "lang.ini"
186
+ | "lang.conf"
187
+ | "lang.log"
188
+ | "lang.csv"
189
+ | "lang.tsv"
190
+ | "lang.image"
191
+ | "lang.pdf"
192
+ | "lang.archive"
193
+ | "lang.binary"
194
+ // Settings tab icons
195
+ | "tab.appearance"
196
+ | "tab.model"
197
+ | "tab.interaction"
198
+ | "tab.context"
199
+ | "tab.editing"
200
+ | "tab.tools"
201
+ | "tab.memory"
202
+ | "tab.tasks"
203
+ | "tab.providers"
204
+ // Tool identity icons
205
+ | "tool.write"
206
+ | "tool.edit"
207
+ | "tool.bash"
208
+ | "tool.ssh"
209
+ | "tool.lsp"
210
+ | "tool.gh"
211
+ | "tool.webSearch"
212
+ | "tool.exa"
213
+ | "tool.browser"
214
+ | "tool.eval"
215
+ | "tool.debug"
216
+ | "tool.mcp"
217
+ | "tool.job"
218
+ | "tool.task"
219
+ | "tool.todo"
220
+ | "tool.memory"
221
+ | "tool.ask"
222
+ | "tool.resolve"
223
+ | "tool.review"
224
+ | "tool.inspectImage"
225
+ | "tool.goal"
226
+ | "tool.irc";
227
+
228
+ type SymbolMap = Record<SymbolKey, string>;
229
+
230
+ const UNICODE_SYMBOLS: SymbolMap = {
231
+ // Status
232
+ "status.success": "✔",
233
+ "status.error": "✘",
234
+ "status.warning": "⚠",
235
+ "status.info": "ⓘ",
236
+ "status.pending": "⏳",
237
+ "status.disabled": "⦸",
238
+ "status.enabled": "●",
239
+ "status.running": "⟳",
240
+ "status.shadowed": "◌",
241
+ "status.aborted": "⏹",
242
+ "status.done": "•",
243
+ // Navigation
244
+ "nav.cursor": "❯",
245
+ "nav.selected": "➤",
246
+ "nav.expand": "▸",
247
+ "nav.collapse": "▾",
248
+ "nav.back": "⟵",
249
+ // Tree
250
+ "tree.branch": "├─",
251
+ "tree.last": "└─",
252
+ "tree.vertical": "│",
253
+ "tree.horizontal": "─",
254
+ "tree.hook": "└",
255
+ // Box (rounded)
256
+ "boxRound.topLeft": "╭",
257
+ "boxRound.topRight": "╮",
258
+ "boxRound.bottomLeft": "╰",
259
+ "boxRound.bottomRight": "╯",
260
+ "boxRound.horizontal": "─",
261
+ "boxRound.vertical": "│",
262
+ // Box (sharp)
263
+ "boxSharp.topLeft": "┌",
264
+ "boxSharp.topRight": "┐",
265
+ "boxSharp.bottomLeft": "└",
266
+ "boxSharp.bottomRight": "┘",
267
+ "boxSharp.horizontal": "─",
268
+ "boxSharp.vertical": "│",
269
+ "boxSharp.cross": "┼",
270
+ "boxSharp.teeDown": "┬",
271
+ "boxSharp.teeUp": "┴",
272
+ "boxSharp.teeRight": "├",
273
+ "boxSharp.teeLeft": "┤",
274
+ // Separators (powerline-ish, but pure Unicode)
275
+ "sep.powerline": "▕",
276
+ "sep.powerlineThin": "┆",
277
+ "sep.powerlineLeft": "▶",
278
+ "sep.powerlineRight": "◀",
279
+ "sep.powerlineThinLeft": ">",
280
+ "sep.powerlineThinRight": "<",
281
+ "sep.block": "▌",
282
+ "sep.space": " ",
283
+ "sep.asciiLeft": ">",
284
+ "sep.asciiRight": "<",
285
+ "sep.dot": " · ",
286
+ "sep.slash": " / ",
287
+ "sep.pipe": " │ ",
288
+ // Icons
289
+ "icon.model": "⬢",
290
+ "icon.plan": "🗺",
291
+ "icon.goal": "🎯",
292
+ "icon.pause": "⏸",
293
+ "icon.loop": "↻",
294
+ "icon.folder": "📁",
295
+ "icon.search": "🔍",
296
+ "icon.scratchFolder": "🗑",
297
+ "icon.file": "📄",
298
+ "icon.git": "⎇",
299
+ "icon.branch": "⑂",
300
+ "icon.pr": "⤴",
301
+ "icon.tokens": "🪙",
302
+ "icon.context": "◫",
303
+ "icon.cost": "💲",
304
+ "icon.time": "⏱",
305
+ "icon.pi": "π",
306
+ "icon.agents": "👥",
307
+ "icon.cache": "💾",
308
+ "icon.input": "⤵",
309
+ "icon.output": "⤴",
310
+ "icon.host": "🖥",
311
+ "icon.session": "🆔",
312
+ "icon.package": "📦",
313
+ "icon.warning": "⚠",
314
+ "icon.rewind": "↶",
315
+ "icon.auto": "⟲",
316
+ "icon.fast": "⚡",
317
+ "icon.extensionSkill": "✦",
318
+ "icon.extensionTool": "🛠",
319
+ "icon.extensionSlashCommand": "⌘",
320
+ "icon.extensionMcp": "🔌",
321
+ "icon.extensionRule": "⚖",
322
+ "icon.extensionHook": "🪝",
323
+ "icon.extensionPrompt": "✎",
324
+ "icon.extensionContextFile": "📎",
325
+ "icon.extensionInstruction": "📘",
326
+ // STT
327
+ "icon.mic": "🎤",
328
+ // Compaction divider
329
+ "icon.camera": "📷",
330
+ // Thinking levels
331
+ "thinking.minimal": "◔ min",
332
+ "thinking.low": "◑ low",
333
+ "thinking.medium": "◒ med",
334
+ "thinking.high": "◕ high",
335
+ "thinking.xhigh": "◉ xhigh",
336
+ "thinking.autoPending": "⟳",
337
+ // Checkboxes
338
+ "checkbox.checked": "☑",
339
+ "checkbox.unchecked": "☐",
340
+ // Radio (single-choice)
341
+ "radio.selected": "◉",
342
+ "radio.unselected": "○",
343
+ // Formatting
344
+ "format.bullet": "•",
345
+ "format.dash": "—",
346
+ "format.bracketLeft": "⟦",
347
+ "format.bracketRight": "⟧",
348
+ // Markdown
349
+ "md.quoteBorder": "▏",
350
+ "md.hrChar": "─",
351
+ "md.bullet": "•",
352
+ "md.colorSwatch": "■",
353
+ // Language/file icons (emoji-centric, no Nerd Font required)
354
+ "lang.default": "⌘",
355
+ "lang.typescript": "🟦",
356
+ "lang.javascript": "🟨",
357
+ "lang.python": "🐍",
358
+ "lang.rust": "🦀",
359
+ "lang.go": "🐹",
360
+ "lang.java": "☕",
361
+ "lang.c": "Ⓒ",
362
+ "lang.cpp": "➕",
363
+ "lang.csharp": "♯",
364
+ "lang.ruby": "💎",
365
+ "lang.php": "🐘",
366
+ "lang.swift": "🕊",
367
+ "lang.kotlin": "🅺",
368
+ "lang.shell": "💻",
369
+ "lang.html": "🌐",
370
+ "lang.css": "🎨",
371
+ "lang.json": "🧾",
372
+ "lang.yaml": "📋",
373
+ "lang.markdown": "📝",
374
+ "lang.sql": "🗄",
375
+ "lang.docker": "🐳",
376
+ "lang.lua": "🌙",
377
+ "lang.text": "🗒",
378
+ "lang.env": "🔧",
379
+ "lang.toml": "🧾",
380
+ "lang.xml": "⟨⟩",
381
+ "lang.ini": "⚙",
382
+ "lang.conf": "⚙",
383
+ "lang.log": "📜",
384
+ "lang.csv": "📑",
385
+ "lang.tsv": "📑",
386
+ "lang.image": "🖼",
387
+ "lang.pdf": "📕",
388
+ "lang.archive": "🗜",
389
+ "lang.binary": "⚙",
390
+ // Settings tabs
391
+ "tab.appearance": "🎨",
392
+ "tab.model": "🤖",
393
+ "tab.interaction": "⌨",
394
+ "tab.context": "📋",
395
+ "tab.editing": "💻",
396
+ "tab.tools": "🔧",
397
+ "tab.memory": "🧠",
398
+ "tab.tasks": "📦",
399
+ "tab.providers": "🌐",
400
+ // Tool identity icons (per-tool signature glyph on the success header)
401
+ "tool.write": "✎",
402
+ "tool.edit": "✎",
403
+ "tool.bash": "❯",
404
+ "tool.ssh": "⇄",
405
+ "tool.lsp": "💡",
406
+ "tool.gh": "⎇",
407
+ "tool.webSearch": "⌕",
408
+ "tool.exa": "🔭",
409
+ "tool.browser": "🌐",
410
+ "tool.eval": "▶",
411
+ "tool.debug": "🐞",
412
+ "tool.mcp": "🔌",
413
+ "tool.job": "⚙",
414
+ "tool.task": "⇶",
415
+ "tool.todo": "☑",
416
+ "tool.memory": "🧠",
417
+ "tool.ask": "?",
418
+ "tool.resolve": "✓",
419
+ "tool.review": "◉",
420
+ "tool.inspectImage": "🖼",
421
+ "tool.goal": "◎",
422
+ "tool.irc": "✉",
423
+ };
424
+
425
+ const NERD_SYMBOLS: SymbolMap = {
426
+ // Status Indicators
427
+ // pick:  | alt:   
428
+ "status.success": "\uf00c",
429
+ // pick:  | alt:   
430
+ "status.error": "\uf00d",
431
+ // pick:  | alt:  
432
+ "status.warning": "\uf12a",
433
+ // pick:  | alt: 
434
+ "status.info": "\uf129",
435
+ // pick:  | alt:   
436
+ "status.pending": "\uf254",
437
+ // pick:  | alt:  
438
+ "status.disabled": "\uf05e",
439
+ // pick:  | alt:  
440
+ "status.enabled": "\uf111",
441
+ // pick:  | alt:   
442
+ "status.running": "\uf110",
443
+ // pick: ◐ | alt: ◑ ◒ ◓ ◔
444
+ "status.shadowed": "◐",
445
+ // pick:  | alt:  
446
+ "status.aborted": "\uf04d",
447
+ // pick: • | alt: ● ·
448
+ "status.done": "•",
449
+ // Navigation
450
+ // pick:  | alt:  
451
+ "nav.cursor": "\uf054",
452
+ // pick:  | alt:  
453
+ "nav.selected": "\uf178",
454
+ // pick:  | alt:  
455
+ "nav.expand": "\uf0da",
456
+ // pick:  | alt:  
457
+ "nav.collapse": "\uf0d7",
458
+ // pick:  | alt:  
459
+ "nav.back": "\uf060",
460
+ // Tree Connectors (same as unicode)
461
+ // pick: ├─ | alt: ├╴ ├╌ ╠═ ┣━
462
+ "tree.branch": "├─",
463
+ // pick: └─ | alt: └╴ └╌ ╚═ ┗━
464
+ "tree.last": "└─",
465
+ // pick: │ | alt: ┃ ║ ▏ ▕
466
+ "tree.vertical": "│",
467
+ // pick: ─ | alt: ━ ═ ╌ ┄
468
+ "tree.horizontal": "─",
469
+ // pick: └ | alt: ╰ ⎿ ↳
470
+ "tree.hook": "└",
471
+ // Box Drawing - Rounded (same as unicode)
472
+ // pick: ╭ | alt: ┌ ┏ ╔
473
+ "boxRound.topLeft": "╭",
474
+ // pick: ╮ | alt: ┐ ┓ ╗
475
+ "boxRound.topRight": "╮",
476
+ // pick: ╰ | alt: └ ┗ ╚
477
+ "boxRound.bottomLeft": "╰",
478
+ // pick: ╯ | alt: ┘ ┛ ╝
479
+ "boxRound.bottomRight": "╯",
480
+ // pick: ─ | alt: ━ ═ ╌
481
+ "boxRound.horizontal": "─",
482
+ // pick: │ | alt: ┃ ║ ▏
483
+ "boxRound.vertical": "│",
484
+ // Box Drawing - Sharp (same as unicode)
485
+ // pick: ┌ | alt: ┏ ╭ ╔
486
+ "boxSharp.topLeft": "┌",
487
+ // pick: ┐ | alt: ┓ ╮ ╗
488
+ "boxSharp.topRight": "┐",
489
+ // pick: └ | alt: ┗ ╰ ╚
490
+ "boxSharp.bottomLeft": "└",
491
+ // pick: ┘ | alt: ┛ ╯ ╝
492
+ "boxSharp.bottomRight": "┘",
493
+ // pick: ─ | alt: ━ ═ ╌
494
+ "boxSharp.horizontal": "─",
495
+ // pick: │ | alt: ┃ ║ ▏
496
+ "boxSharp.vertical": "│",
497
+ // pick: ┼ | alt: ╋ ╬ ┿
498
+ "boxSharp.cross": "┼",
499
+ // pick: ┬ | alt: ╦ ┯ ┳
500
+ "boxSharp.teeDown": "┬",
501
+ // pick: ┴ | alt: ╩ ┷ ┻
502
+ "boxSharp.teeUp": "┴",
503
+ // pick: ├ | alt: ╠ ┝ ┣
504
+ "boxSharp.teeRight": "├",
505
+ // pick: ┤ | alt: ╣ ┥ ┫
506
+ "boxSharp.teeLeft": "┤",
507
+ // Separators - Nerd Font specific
508
+ // pick:  | alt:   
509
+ "sep.powerline": "\ue0b0",
510
+ // pick:  | alt:  
511
+ "sep.powerlineThin": "\ue0b1",
512
+ // pick:  | alt:  
513
+ "sep.powerlineLeft": "\ue0b0",
514
+ // pick:  | alt:  
515
+ "sep.powerlineRight": "\ue0b2",
516
+ // pick:  | alt: 
517
+ "sep.powerlineThinLeft": "\ue0b1",
518
+ // pick:  | alt: 
519
+ "sep.powerlineThinRight": "\ue0b3",
520
+ // pick: █ | alt: ▓ ▒ ░ ▉ ▌
521
+ "sep.block": "█",
522
+ // pick: space | alt: ␠ ·
523
+ "sep.space": " ",
524
+ // pick: > | alt: › » ▸
525
+ "sep.asciiLeft": ">",
526
+ // pick: < | alt: ‹ « ◂
527
+ "sep.asciiRight": "<",
528
+ // pick: · | alt: • ⋅
529
+ "sep.dot": " · ",
530
+ // pick:  | alt: / ∕ ⁄
531
+ "sep.slash": "\ue0bb",
532
+ // pick:  | alt: │ ┃ |
533
+ "sep.pipe": "\ue0b3",
534
+ // Icons - Nerd Font specific
535
+ // pick:  | alt:   ◆
536
+ "icon.model": "\uec19",
537
+ // pick:  | alt:  
538
+ "icon.plan": "\uf2d2",
539
+ // pick: (nf-fa-bullseye) | alt: (nf-md-target) ◎ ⌖
540
+ "icon.goal": "\uf140",
541
+ // pick: (nf-fa-pause) | alt: ⏸ ||
542
+ "icon.pause": "\uf04c",
543
+ // pick: ↻ | alt: ⟳
544
+ "icon.loop": "\uf021",
545
+ // pick:  | alt:  
546
+ "icon.folder": "\uf115",
547
+ "icon.search": "\uf002",
548
+ // pick: | alt:
549
+ "icon.scratchFolder": "\uf014",
550
+ // pick:  | alt:  
551
+ "icon.file": "\uf15b",
552
+ // pick:  | alt:  ⎇
553
+ "icon.git": "\uf1d3",
554
+ // pick:  | alt:  ⎇
555
+ "icon.branch": "\uf126",
556
+ // pick:  (nf-cod-git_pull_request) | alt: (nf-oct-git_pull_request)
557
+ "icon.pr": "\uea64",
558
+ // pick:  | alt: ⊛ ◍ 
559
+ "icon.tokens": "\ue26b",
560
+ // pick:  | alt: ◫ ▦
561
+ "icon.context": "\ue70f",
562
+ // pick:  | alt: $ ¢
563
+ "icon.cost": "\uf155",
564
+ // pick:  | alt: ◷ ◴
565
+ "icon.time": "\uf017",
566
+ // pick:  | alt: π ∏ ∑
567
+ "icon.pi": "\ue22c",
568
+ // pick:  | alt: 
569
+ "icon.agents": "\uf0c0",
570
+ // pick:  | alt:  
571
+ "icon.cache": "\uf1c0",
572
+ // pick:  | alt:  →
573
+ "icon.input": "\uf090",
574
+ // pick:  | alt:  →
575
+ "icon.output": "\uf08b",
576
+ // pick:  | alt:  
577
+ "icon.host": "\uf109",
578
+ // pick:  | alt:  
579
+ "icon.session": "\uf550",
580
+ // pick:  | alt: 
581
+ "icon.package": "\uf487",
582
+ // pick:  | alt:  
583
+ "icon.warning": "\uf071",
584
+ // pick:  | alt:  ↺
585
+ "icon.rewind": "\uf0e2",
586
+ // pick: 󰁨 | alt:   
587
+ "icon.auto": "\u{f0068}",
588
+ "icon.fast": "\uf0e7",
589
+ "icon.extensionSkill": "\uf0eb",
590
+ // pick:  | alt:  
591
+ "icon.extensionTool": "\uf0ad",
592
+ // pick:  | alt: 
593
+ "icon.extensionSlashCommand": "\uf120",
594
+ // pick:  | alt:  
595
+ "icon.extensionMcp": "\uf1e6",
596
+ // pick:  | alt:  
597
+ "icon.extensionRule": "\uf0e3",
598
+ // pick:  | alt: 
599
+ "icon.extensionHook": "\uf0c1",
600
+ // pick:  | alt:  
601
+ "icon.extensionPrompt": "\uf075",
602
+ // pick:  | alt:  
603
+ "icon.extensionContextFile": "\uf0f6",
604
+ // pick:  | alt:  
605
+ "icon.extensionInstruction": "\uf02d",
606
+ // STT - fa-microphone
607
+ "icon.mic": "\uf130",
608
+ // Compaction divider - fa-camera-retro
609
+ "icon.camera": "\uf083",
610
+ // Thinking Levels - emoji labels
611
+ // pick: 🤨 min | alt:  min  min
612
+ "thinking.minimal": "\u{F0E7} min",
613
+ // pick: 🤔 low | alt:  low  low
614
+ "thinking.low": "\u{F10C} low",
615
+ // pick: 🤓 med | alt:  med  med
616
+ "thinking.medium": "\u{F192} med",
617
+ // pick: 🤯 high | alt:  high  high
618
+ "thinking.high": "\u{F111} high",
619
+ // pick: 🧠 xhi | alt:  xhi  xhi
620
+ "thinking.xhigh": "\u{F06D} xhi",
621
+ // pick: (fa-circle-o-notch) | alt: 󰂼 (nf-md-cached) ⟳
622
+ "thinking.autoPending": "\uf1ce",
623
+ // Checkboxes
624
+ // pick:  | alt:  
625
+ "checkbox.checked": "\uf14a",
626
+ // pick:  | alt: 
627
+ "checkbox.unchecked": "\uf096",
628
+ // Radio (single-choice)
629
+ // pick: (fa-dot-circle-o) | alt: ◉
630
+ "radio.selected": "\uf192",
631
+ // pick: (fa-circle-o) | alt: ○
632
+ "radio.unselected": "\uf10c",
633
+ // pick:  | alt:   •
634
+ "format.bullet": "\uf111",
635
+ // pick: – | alt: — ― -
636
+ "format.dash": "–",
637
+ // pick: ⟨ | alt: [ ⟦
638
+ "format.bracketLeft": "⟨",
639
+ // pick: ⟩ | alt: ] ⟧
640
+ "format.bracketRight": "⟩",
641
+ // Markdown-specific
642
+ // pick: │ | alt: ┃ ║
643
+ "md.quoteBorder": "│",
644
+ // pick: ─ | alt: ━ ═
645
+ "md.hrChar": "─",
646
+ // pick:  | alt:  •
647
+ "md.bullet": "\uf111",
648
+ // pick: ■ | alt: (U+F096)
649
+ "md.colorSwatch": "■",
650
+ // Language icons (nerd font devicons)
651
+ "lang.default": "",
652
+ "lang.typescript": "\u{E628}",
653
+ "lang.javascript": "\u{E60C}",
654
+ "lang.python": "\u{E606}",
655
+ "lang.rust": "\u{E7A8}",
656
+ "lang.go": "\u{E627}",
657
+ "lang.java": "\u{E738}",
658
+ "lang.c": "\u{E61E}",
659
+ "lang.cpp": "\u{E61D}",
660
+ "lang.csharp": "\u{E7BC}",
661
+ "lang.ruby": "\u{E791}",
662
+ "lang.php": "\u{E608}",
663
+ "lang.swift": "\u{E755}",
664
+ "lang.kotlin": "\u{E634}",
665
+ "lang.shell": "\u{E795}",
666
+ "lang.html": "\u{E736}",
667
+ "lang.css": "\u{E749}",
668
+ "lang.json": "\u{E60B}",
669
+ "lang.yaml": "\u{E615}",
670
+ "lang.markdown": "\u{E609}",
671
+ "lang.sql": "\u{E706}",
672
+ "lang.docker": "\u{E7B0}",
673
+ "lang.lua": "\u{E620}",
674
+ "lang.text": "\u{E612}",
675
+ "lang.env": "\u{E615}",
676
+ "lang.toml": "\u{E615}",
677
+ "lang.xml": "\u{F05C0}",
678
+ "lang.ini": "\u{E615}",
679
+ "lang.conf": "\u{E615}",
680
+ "lang.log": "\u{F0331}",
681
+ "lang.csv": "\u{F021B}",
682
+ "lang.tsv": "\u{F021B}",
683
+ "lang.image": "\u{F021F}",
684
+ "lang.pdf": "\u{F0226}",
685
+ "lang.archive": "\u{F187}",
686
+ "lang.binary": "\u{F019A}",
687
+ // Settings tab icons
688
+ "tab.appearance": "󰃣",
689
+ "tab.model": "󰚩",
690
+ "tab.interaction": "󰌌",
691
+ "tab.context": "󰘸",
692
+ "tab.editing": "",
693
+ "tab.tools": "󰠭",
694
+ "tab.memory": "󰧑",
695
+ "tab.tasks": "󰐱",
696
+ "tab.providers": "󰖟",
697
+ // Tool identity icons (per-tool signature glyph on the success header)
698
+ "tool.write": "\uEA7F",
699
+ "tool.edit": "\uEA73",
700
+ "tool.bash": "\uEBCA",
701
+ "tool.ssh": "\uEB3A",
702
+ "tool.lsp": "\uEA61",
703
+ "tool.gh": "\uEA84",
704
+ "tool.webSearch": "\uEB01",
705
+ "tool.exa": "\uEB68",
706
+ "tool.browser": "\uEAAE",
707
+ "tool.eval": "\uEBAF",
708
+ "tool.debug": "\uEAD8",
709
+ "tool.mcp": "\uEB2D",
710
+ "tool.job": "\uEBA2",
711
+ "tool.task": "\uEA7E",
712
+ "tool.todo": "\uEAB3",
713
+ "tool.memory": "\uEACE",
714
+ "tool.ask": "\uEAC7",
715
+ "tool.resolve": "\uEBB1",
716
+ "tool.review": "\uEA70",
717
+ "tool.inspectImage": "\uEAEA",
718
+ "tool.goal": "\uEBF8",
719
+ "tool.irc": "\uF086",
720
+ };
721
+
722
+ const ASCII_SYMBOLS: SymbolMap = {
723
+ // Status Indicators
724
+ "status.success": "[ok]",
725
+ "status.error": "[!!]",
726
+ "status.warning": "[!]",
727
+ "status.info": "[i]",
728
+ "status.pending": "[*]",
729
+ "status.disabled": "[ ]",
730
+ "status.enabled": "[x]",
731
+ "status.running": "[~]",
732
+ "status.shadowed": "[/]",
733
+ "status.aborted": "[-]",
734
+ "status.done": "*",
735
+ // Navigation
736
+ "nav.cursor": ">",
737
+ "nav.selected": "->",
738
+ "nav.expand": "+",
739
+ "nav.collapse": "-",
740
+ "nav.back": "<-",
741
+ // Tree Connectors
742
+ "tree.branch": "|--",
743
+ "tree.last": "'--",
744
+ "tree.vertical": "|",
745
+ "tree.horizontal": "-",
746
+ "tree.hook": "`-",
747
+ // Box Drawing - Rounded (ASCII fallback)
748
+ "boxRound.topLeft": "+",
749
+ "boxRound.topRight": "+",
750
+ "boxRound.bottomLeft": "+",
751
+ "boxRound.bottomRight": "+",
752
+ "boxRound.horizontal": "-",
753
+ "boxRound.vertical": "|",
754
+ // Box Drawing - Sharp (ASCII fallback)
755
+ "boxSharp.topLeft": "+",
756
+ "boxSharp.topRight": "+",
757
+ "boxSharp.bottomLeft": "+",
758
+ "boxSharp.bottomRight": "+",
759
+ "boxSharp.horizontal": "-",
760
+ "boxSharp.vertical": "|",
761
+ "boxSharp.cross": "+",
762
+ "boxSharp.teeDown": "+",
763
+ "boxSharp.teeUp": "+",
764
+ "boxSharp.teeRight": "+",
765
+ "boxSharp.teeLeft": "+",
766
+ // Separators
767
+ "sep.powerline": ">",
768
+ "sep.powerlineThin": ">",
769
+ "sep.powerlineLeft": ">",
770
+ "sep.powerlineRight": "<",
771
+ "sep.powerlineThinLeft": ">",
772
+ "sep.powerlineThinRight": "<",
773
+ "sep.block": "#",
774
+ "sep.space": " ",
775
+ "sep.asciiLeft": ">",
776
+ "sep.asciiRight": "<",
777
+ "sep.dot": " - ",
778
+ "sep.slash": " / ",
779
+ "sep.pipe": " | ",
780
+ // Icons
781
+ "icon.model": "[M]",
782
+ "icon.plan": "plan",
783
+ "icon.goal": "goal",
784
+ "icon.pause": "||",
785
+ "icon.loop": "loop",
786
+ "icon.folder": "[D]",
787
+ "icon.search": "[/]",
788
+ "icon.scratchFolder": "[T]",
789
+ "icon.file": "[F]",
790
+ "icon.git": "git:",
791
+ "icon.branch": "@",
792
+ "icon.pr": "PR",
793
+ "icon.tokens": "tok:",
794
+ "icon.context": "ctx:",
795
+ "icon.cost": "$",
796
+ "icon.time": "t:",
797
+ "icon.pi": "pi",
798
+ "icon.agents": "AG",
799
+ "icon.cache": "cache",
800
+ "icon.input": "in:",
801
+ "icon.output": "out:",
802
+ "icon.host": "host",
803
+ "icon.session": "id",
804
+ "icon.package": "[P]",
805
+ "icon.warning": "[!]",
806
+ "icon.rewind": "<-",
807
+ "icon.auto": "[A]",
808
+ "icon.fast": ">>",
809
+ "icon.extensionSkill": "SK",
810
+ "icon.extensionTool": "TL",
811
+ "icon.extensionSlashCommand": "/",
812
+ "icon.extensionMcp": "MCP",
813
+ "icon.extensionRule": "RL",
814
+ "icon.extensionHook": "HK",
815
+ "icon.extensionPrompt": "PR",
816
+ "icon.extensionContextFile": "CF",
817
+ "icon.extensionInstruction": "IN",
818
+ // STT
819
+ "icon.mic": "MIC",
820
+ // Compaction divider
821
+ "icon.camera": "[o]",
822
+ // Thinking Levels
823
+ "thinking.minimal": "[min]",
824
+ "thinking.low": "[low]",
825
+ "thinking.medium": "[med]",
826
+ "thinking.high": "[high]",
827
+ "thinking.xhigh": "[xhi]",
828
+ "thinking.autoPending": "[~]",
829
+ // Checkboxes
830
+ "checkbox.checked": "[x]",
831
+ "checkbox.unchecked": "[ ]",
832
+ "radio.selected": "(o)",
833
+ "radio.unselected": "( )",
834
+ "format.bullet": "*",
835
+ "format.dash": "-",
836
+ "format.bracketLeft": "[",
837
+ "format.bracketRight": "]",
838
+ // Markdown-specific
839
+ "md.quoteBorder": "|",
840
+ "md.hrChar": "-",
841
+ "md.bullet": "*",
842
+ "md.colorSwatch": "[]",
843
+ // Language icons (ASCII uses abbreviations)
844
+ "lang.default": "code",
845
+ "lang.typescript": "ts",
846
+ "lang.javascript": "js",
847
+ "lang.python": "py",
848
+ "lang.rust": "rs",
849
+ "lang.go": "go",
850
+ "lang.java": "java",
851
+ "lang.c": "c",
852
+ "lang.cpp": "cpp",
853
+ "lang.csharp": "cs",
854
+ "lang.ruby": "rb",
855
+ "lang.php": "php",
856
+ "lang.swift": "swift",
857
+ "lang.kotlin": "kt",
858
+ "lang.shell": "sh",
859
+ "lang.html": "html",
860
+ "lang.css": "css",
861
+ "lang.json": "json",
862
+ "lang.yaml": "yaml",
863
+ "lang.markdown": "md",
864
+ "lang.sql": "sql",
865
+ "lang.docker": "docker",
866
+ "lang.lua": "lua",
867
+ "lang.text": "txt",
868
+ "lang.env": "env",
869
+ "lang.toml": "toml",
870
+ "lang.xml": "xml",
871
+ "lang.ini": "ini",
872
+ "lang.conf": "conf",
873
+ "lang.log": "log",
874
+ "lang.csv": "csv",
875
+ "lang.tsv": "tsv",
876
+ "lang.image": "img",
877
+ "lang.pdf": "pdf",
878
+ "lang.archive": "zip",
879
+ "lang.binary": "bin",
880
+ // Settings tab icons
881
+ "tab.appearance": "[A]",
882
+ "tab.model": "[M]",
883
+ "tab.interaction": "[I]",
884
+ "tab.context": "[X]",
885
+ "tab.editing": "[E]",
886
+ "tab.tools": "[T]",
887
+ "tab.memory": "[Y]",
888
+ "tab.tasks": "[K]",
889
+ "tab.providers": "[P]",
890
+ // Tool identity icons (per-tool signature glyph on the success header)
891
+ "tool.write": "+f",
892
+ "tool.edit": "~",
893
+ "tool.bash": "$",
894
+ "tool.ssh": "ssh",
895
+ "tool.lsp": "lsp",
896
+ "tool.gh": "gh",
897
+ "tool.webSearch": "web",
898
+ "tool.exa": "exa",
899
+ "tool.browser": "[w]",
900
+ "tool.eval": ">_",
901
+ "tool.debug": "dbg",
902
+ "tool.mcp": "<>",
903
+ "tool.job": "job",
904
+ "tool.task": ">>>",
905
+ "tool.todo": "[x]",
906
+ "tool.memory": "mem",
907
+ "tool.ask": "[?]",
908
+ "tool.resolve": "[v]",
909
+ "tool.review": "rev",
910
+ "tool.inspectImage": "[i]",
911
+ "tool.goal": "(o)",
912
+ "tool.irc": "irc",
913
+ };
914
+
915
+ const SYMBOL_PRESETS: Record<SymbolPreset, SymbolMap> = {
916
+ unicode: UNICODE_SYMBOLS,
917
+ nerd: NERD_SYMBOLS,
918
+ ascii: ASCII_SYMBOLS,
919
+ };
920
+
921
+ export type SpinnerType = "status" | "activity";
922
+
923
+ const SPINNER_FRAMES: Record<SymbolPreset, Record<SpinnerType, string[]>> = {
924
+ unicode: {
925
+ status: ["⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"],
926
+ activity: ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
927
+ },
928
+ nerd: {
929
+ status: ["󱑖", "󱑋", "󱑌", "󱑍", "󱑎", "󱑏", "󱑐", "󱑑", "󱑒", "󱑓", "󱑔", "󱑕"],
930
+ activity: ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
931
+ },
932
+ ascii: {
933
+ status: ["|", "/", "-", "\\"],
934
+ activity: ["-", "\\", "|", "/"],
935
+ },
936
+ };
937
+
938
+ /**
939
+ * Shape accepted by `themeJson.symbols.spinnerFrames`. A flat array applies to
940
+ * both spinner types; an object lets a theme override `status` and/or
941
+ * `activity` independently. Anything not specified falls back to the symbol
942
+ * preset's default frames.
943
+ */
944
+ type SpinnerFramesOverride = string[] | { status?: string[]; activity?: string[] };
945
+
946
+ function normalizeSpinnerFramesOverride(
947
+ value: SpinnerFramesOverride | undefined,
948
+ ): Partial<Record<SpinnerType, string[]>> {
949
+ if (value === undefined) return {};
950
+ if (Array.isArray(value)) return { status: value, activity: value };
951
+ const result: Partial<Record<SpinnerType, string[]>> = {};
952
+ if (value.status) result.status = value.status;
953
+ if (value.activity) result.activity = value.activity;
954
+ return result;
955
+ }
956
+
957
+ // ============================================================================
958
+ // Types & Schema
959
+ // ============================================================================
960
+
961
+ const colorValueSchema = z.union([
962
+ z.string(), // hex "#ff0000", var ref "primary", or empty ""
963
+ z.number().int().min(0).max(255), // 256-color index
964
+ ]);
965
+
966
+ type ColorValue = z.infer<typeof colorValueSchema>;
967
+
968
+ const THEME_COLOR_KEYS = [
969
+ "accent",
970
+ "border",
971
+ "borderAccent",
972
+ "borderMuted",
973
+ "success",
974
+ "error",
975
+ "warning",
976
+ "muted",
977
+ "dim",
978
+ "text",
979
+ "thinkingText",
980
+ "selectedBg",
981
+ "userMessageBg",
982
+ "userMessageText",
983
+ "customMessageBg",
984
+ "customMessageText",
985
+ "customMessageLabel",
986
+ "toolPendingBg",
987
+ "toolSuccessBg",
988
+ "toolErrorBg",
989
+ "toolTitle",
990
+ "toolOutput",
991
+ "mdHeading",
992
+ "mdLink",
993
+ "mdLinkUrl",
994
+ "mdCode",
995
+ "mdCodeBlock",
996
+ "mdCodeBlockBorder",
997
+ "mdQuote",
998
+ "mdQuoteBorder",
999
+ "mdHr",
1000
+ "mdListBullet",
1001
+ "toolDiffAdded",
1002
+ "toolDiffRemoved",
1003
+ "toolDiffContext",
1004
+ "syntaxComment",
1005
+ "syntaxKeyword",
1006
+ "syntaxFunction",
1007
+ "syntaxVariable",
1008
+ "syntaxString",
1009
+ "syntaxNumber",
1010
+ "syntaxType",
1011
+ "syntaxOperator",
1012
+ "syntaxPunctuation",
1013
+ "thinkingOff",
1014
+ "thinkingMinimal",
1015
+ "thinkingLow",
1016
+ "thinkingMedium",
1017
+ "thinkingHigh",
1018
+ "thinkingXhigh",
1019
+ "bashMode",
1020
+ "pythonMode",
1021
+ "statusLineBg",
1022
+ "statusLineSep",
1023
+ "statusLineModel",
1024
+ "statusLinePath",
1025
+ "statusLineGitClean",
1026
+ "statusLineGitDirty",
1027
+ "statusLineContext",
1028
+ "statusLineSpend",
1029
+ "statusLineStaged",
1030
+ "statusLineDirty",
1031
+ "statusLineUntracked",
1032
+ "statusLineOutput",
1033
+ "statusLineCost",
1034
+ "statusLineSubagents",
1035
+ ] as const;
1036
+
1037
+ const themeColorsSchema = z.object(
1038
+ Object.fromEntries(THEME_COLOR_KEYS.map(key => [key, colorValueSchema])) as unknown as {
1039
+ [K in (typeof THEME_COLOR_KEYS)[number]]: typeof colorValueSchema;
1040
+ },
1041
+ );
1042
+
1043
+ const spinnerFramesArraySchema = z.array(z.string().min(1)).min(1);
1044
+ const spinnerFramesSchema = z.union([
1045
+ spinnerFramesArraySchema,
1046
+ z
1047
+ .object({
1048
+ status: spinnerFramesArraySchema.optional(),
1049
+ activity: spinnerFramesArraySchema.optional(),
1050
+ })
1051
+ .refine(value => value.status !== undefined || value.activity !== undefined, {
1052
+ message: "spinnerFrames object must define `status` and/or `activity`",
1053
+ }),
1054
+ ]);
1055
+
1056
+ const symbolPresetSchema = z.enum(["unicode", "nerd", "ascii"]);
1057
+
1058
+ const themeJsonSchema = z.object({
1059
+ $schema: z.string().optional(),
1060
+ name: z.string(),
1061
+ vars: z.record(z.string(), colorValueSchema).optional(),
1062
+ colors: themeColorsSchema,
1063
+ export: z
1064
+ .object({
1065
+ pageBg: colorValueSchema.optional(),
1066
+ cardBg: colorValueSchema.optional(),
1067
+ infoBg: colorValueSchema.optional(),
1068
+ })
1069
+ .optional(),
1070
+ symbols: z
1071
+ .object({
1072
+ preset: symbolPresetSchema.optional(),
1073
+ overrides: z.record(z.string(), z.string()).optional(),
1074
+ spinnerFrames: spinnerFramesSchema.optional(),
1075
+ })
1076
+ .optional(),
1077
+ });
1078
+
1079
+ type ThemeJson = z.infer<typeof themeJsonSchema>;
1080
+
1081
+ export type ThemeColor =
1082
+ | "accent"
1083
+ | "border"
1084
+ | "borderAccent"
1085
+ | "borderMuted"
1086
+ | "success"
1087
+ | "error"
1088
+ | "warning"
1089
+ | "muted"
1090
+ | "dim"
1091
+ | "text"
1092
+ | "thinkingText"
1093
+ | "userMessageText"
1094
+ | "customMessageText"
1095
+ | "customMessageLabel"
1096
+ | "toolTitle"
1097
+ | "toolOutput"
1098
+ | "mdHeading"
1099
+ | "mdLink"
1100
+ | "mdLinkUrl"
1101
+ | "mdCode"
1102
+ | "mdCodeBlock"
1103
+ | "mdCodeBlockBorder"
1104
+ | "mdQuote"
1105
+ | "mdQuoteBorder"
1106
+ | "mdHr"
1107
+ | "mdListBullet"
1108
+ | "toolDiffAdded"
1109
+ | "toolDiffRemoved"
1110
+ | "toolDiffContext"
1111
+ | "syntaxComment"
1112
+ | "syntaxKeyword"
1113
+ | "syntaxFunction"
1114
+ | "syntaxVariable"
1115
+ | "syntaxString"
1116
+ | "syntaxNumber"
1117
+ | "syntaxType"
1118
+ | "syntaxOperator"
1119
+ | "syntaxPunctuation"
1120
+ | "thinkingOff"
1121
+ | "thinkingMinimal"
1122
+ | "thinkingLow"
1123
+ | "thinkingMedium"
1124
+ | "thinkingHigh"
1125
+ | "thinkingXhigh"
1126
+ | "bashMode"
1127
+ | "pythonMode"
1128
+ | "statusLineSep"
1129
+ | "statusLineModel"
1130
+ | "statusLinePath"
1131
+ | "statusLineGitClean"
1132
+ | "statusLineGitDirty"
1133
+ | "statusLineContext"
1134
+ | "statusLineSpend"
1135
+ | "statusLineStaged"
1136
+ | "statusLineDirty"
1137
+ | "statusLineUntracked"
1138
+ | "statusLineOutput"
1139
+ | "statusLineCost"
1140
+ | "statusLineSubagents";
1141
+
1142
+ /** Set of all valid ThemeColor string values for runtime validation */
1143
+ const THEME_COLOR_RECORD = {
1144
+ accent: true,
1145
+ border: true,
1146
+ borderAccent: true,
1147
+ borderMuted: true,
1148
+ success: true,
1149
+ error: true,
1150
+ warning: true,
1151
+ muted: true,
1152
+ dim: true,
1153
+ text: true,
1154
+ thinkingText: true,
1155
+ userMessageText: true,
1156
+ customMessageText: true,
1157
+ customMessageLabel: true,
1158
+ toolTitle: true,
1159
+ toolOutput: true,
1160
+ mdHeading: true,
1161
+ mdLink: true,
1162
+ mdLinkUrl: true,
1163
+ mdCode: true,
1164
+ mdCodeBlock: true,
1165
+ mdCodeBlockBorder: true,
1166
+ mdQuote: true,
1167
+ mdQuoteBorder: true,
1168
+ mdHr: true,
1169
+ mdListBullet: true,
1170
+ toolDiffAdded: true,
1171
+ toolDiffRemoved: true,
1172
+ toolDiffContext: true,
1173
+ syntaxComment: true,
1174
+ syntaxKeyword: true,
1175
+ syntaxFunction: true,
1176
+ syntaxVariable: true,
1177
+ syntaxString: true,
1178
+ syntaxNumber: true,
1179
+ syntaxType: true,
1180
+ syntaxOperator: true,
1181
+ syntaxPunctuation: true,
1182
+ thinkingOff: true,
1183
+ thinkingMinimal: true,
1184
+ thinkingLow: true,
1185
+ thinkingMedium: true,
1186
+ thinkingHigh: true,
1187
+ thinkingXhigh: true,
1188
+ bashMode: true,
1189
+ pythonMode: true,
1190
+ statusLineSep: true,
1191
+ statusLineModel: true,
1192
+ statusLinePath: true,
1193
+ statusLineGitClean: true,
1194
+ statusLineGitDirty: true,
1195
+ statusLineContext: true,
1196
+ statusLineSpend: true,
1197
+ statusLineStaged: true,
1198
+ statusLineDirty: true,
1199
+ statusLineUntracked: true,
1200
+ statusLineOutput: true,
1201
+ statusLineCost: true,
1202
+ statusLineSubagents: true,
1203
+ } satisfies Record<ThemeColor, true>;
1204
+
1205
+ const VALID_THEME_COLORS: ReadonlySet<string> = new Set(Object.keys(THEME_COLOR_RECORD));
1206
+
1207
+ /** Check if a string is a valid ThemeColor value */
1208
+ export function isValidThemeColor(color: string): color is ThemeColor {
1209
+ return VALID_THEME_COLORS.has(color);
1210
+ }
1211
+
1212
+ export type ThemeBg =
1213
+ | "selectedBg"
1214
+ | "userMessageBg"
1215
+ | "customMessageBg"
1216
+ | "toolPendingBg"
1217
+ | "toolSuccessBg"
1218
+ | "toolErrorBg"
1219
+ | "statusLineBg";
1220
+
1221
+ type ColorMode = "truecolor" | "256color";
1222
+
1223
+ // ============================================================================
1224
+ // Color Utilities
1225
+ // ============================================================================
1226
+
1227
+ function detectColorMode(): ColorMode {
1228
+ const colorterm = Bun.env.COLORTERM;
1229
+ if (colorterm === "truecolor" || colorterm === "24bit") {
1230
+ return "truecolor";
1231
+ }
1232
+ // Windows Terminal supports truecolor
1233
+ if (Bun.env.WT_SESSION) {
1234
+ return "truecolor";
1235
+ }
1236
+ const term = Bun.env.TERM || "";
1237
+ // Only fall back to 256color for truly limited terminals
1238
+ if (term === "dumb" || term === "" || term === "linux") {
1239
+ return "256color";
1240
+ }
1241
+ // Assume truecolor for everything else - virtually all modern terminals support it
1242
+ return "truecolor";
1243
+ }
1244
+
1245
+ function colorToAnsi(color: string, mode: ColorMode): string {
1246
+ const format = mode === "truecolor" ? "ansi-16m" : "ansi-256";
1247
+ const ansi = Bun.color(color, format);
1248
+ if (ansi === null) {
1249
+ throw new Error(`Invalid color value: ${color}`);
1250
+ }
1251
+ return ansi;
1252
+ }
1253
+
1254
+ function fgAnsi(color: string | number, mode: ColorMode): string {
1255
+ if (color === "") return "\x1b[39m";
1256
+ if (typeof color === "number") return `\x1b[38;5;${color}m`;
1257
+ if (typeof color === "string") {
1258
+ return colorToAnsi(color, mode);
1259
+ }
1260
+ throw new Error(`Invalid color value: ${color}`);
1261
+ }
1262
+
1263
+ function bgAnsi(color: string | number, mode: ColorMode): string {
1264
+ if (color === "") return "\x1b[49m";
1265
+ if (typeof color === "number") return `\x1b[48;5;${color}m`;
1266
+ const ansi = colorToAnsi(color, mode);
1267
+ return ansi.replace("\x1b[38;", "\x1b[48;");
1268
+ }
1269
+
1270
+ function resolveVarRefs(
1271
+ value: ColorValue,
1272
+ vars: Record<string, ColorValue>,
1273
+ visited = new Set<string>(),
1274
+ ): string | number {
1275
+ if (typeof value === "number" || value === "" || value.startsWith("#")) {
1276
+ return value;
1277
+ }
1278
+ if (visited.has(value)) {
1279
+ throw new Error(`Circular variable reference detected: ${value}`);
1280
+ }
1281
+ if (!(value in vars)) {
1282
+ throw new Error(`Variable reference not found: ${value}`);
1283
+ }
1284
+ visited.add(value);
1285
+ return resolveVarRefs(vars[value], vars, visited);
1286
+ }
1287
+
1288
+ function resolveThemeColors<T extends Record<string, ColorValue>>(
1289
+ colors: T,
1290
+ vars: Record<string, ColorValue> = {},
1291
+ ): Record<keyof T, string | number> {
1292
+ const resolved: Record<string, string | number> = {};
1293
+ for (const [key, value] of Object.entries(colors)) {
1294
+ resolved[key] = resolveVarRefs(value, vars);
1295
+ }
1296
+ return resolved as Record<keyof T, string | number>;
1297
+ }
1298
+
1299
+ // ============================================================================
1300
+ // Theme Class
1301
+ // ============================================================================
1302
+
1303
+ const langMap: Record<string, SymbolKey> = {
1304
+ typescript: "lang.typescript",
1305
+ ts: "lang.typescript",
1306
+ tsx: "lang.typescript",
1307
+ javascript: "lang.javascript",
1308
+ js: "lang.javascript",
1309
+ jsx: "lang.javascript",
1310
+ mjs: "lang.javascript",
1311
+ cjs: "lang.javascript",
1312
+ python: "lang.python",
1313
+ py: "lang.python",
1314
+ rust: "lang.rust",
1315
+ rs: "lang.rust",
1316
+ go: "lang.go",
1317
+ java: "lang.java",
1318
+ c: "lang.c",
1319
+ cpp: "lang.cpp",
1320
+ "c++": "lang.cpp",
1321
+ cc: "lang.cpp",
1322
+ cxx: "lang.cpp",
1323
+ csharp: "lang.csharp",
1324
+ cs: "lang.csharp",
1325
+ ruby: "lang.ruby",
1326
+ rb: "lang.ruby",
1327
+ php: "lang.php",
1328
+ swift: "lang.swift",
1329
+ kotlin: "lang.kotlin",
1330
+ kt: "lang.kotlin",
1331
+ bash: "lang.shell",
1332
+ sh: "lang.shell",
1333
+ zsh: "lang.shell",
1334
+ fish: "lang.shell",
1335
+ powershell: "lang.shell",
1336
+ just: "lang.shell",
1337
+ shell: "lang.shell",
1338
+ html: "lang.html",
1339
+ htm: "lang.html",
1340
+ astro: "lang.html",
1341
+ vue: "lang.html",
1342
+ svelte: "lang.html",
1343
+ css: "lang.css",
1344
+ scss: "lang.css",
1345
+ sass: "lang.css",
1346
+ less: "lang.css",
1347
+ json: "lang.json",
1348
+ yaml: "lang.yaml",
1349
+ yml: "lang.yaml",
1350
+ markdown: "lang.markdown",
1351
+ md: "lang.markdown",
1352
+ sql: "lang.sql",
1353
+ dockerfile: "lang.docker",
1354
+ docker: "lang.docker",
1355
+ lua: "lang.lua",
1356
+ text: "lang.text",
1357
+ txt: "lang.text",
1358
+ plain: "lang.text",
1359
+ log: "lang.log",
1360
+ env: "lang.env",
1361
+ dotenv: "lang.env",
1362
+ toml: "lang.toml",
1363
+ xml: "lang.xml",
1364
+ ini: "lang.ini",
1365
+ conf: "lang.conf",
1366
+ cfg: "lang.conf",
1367
+ config: "lang.conf",
1368
+ properties: "lang.conf",
1369
+ csv: "lang.csv",
1370
+ tsv: "lang.tsv",
1371
+ image: "lang.image",
1372
+ img: "lang.image",
1373
+ png: "lang.image",
1374
+ jpg: "lang.image",
1375
+ jpeg: "lang.image",
1376
+ gif: "lang.image",
1377
+ webp: "lang.image",
1378
+ svg: "lang.image",
1379
+ ico: "lang.image",
1380
+ bmp: "lang.image",
1381
+ tiff: "lang.image",
1382
+ pdf: "lang.pdf",
1383
+ zip: "lang.archive",
1384
+ tar: "lang.archive",
1385
+ gz: "lang.archive",
1386
+ tgz: "lang.archive",
1387
+ bz2: "lang.archive",
1388
+ xz: "lang.archive",
1389
+ "7z": "lang.archive",
1390
+ exe: "lang.binary",
1391
+ dll: "lang.binary",
1392
+ so: "lang.binary",
1393
+ dylib: "lang.binary",
1394
+ wasm: "lang.binary",
1395
+ bin: "lang.binary",
1396
+ };
1397
+
1398
+ export class Theme {
1399
+ #fgColors: Record<ThemeColor, string>;
1400
+ #bgColors: Record<ThemeBg, string>;
1401
+ #symbols: SymbolMap;
1402
+ #spinnerFramesOverrides: Partial<Record<SpinnerType, string[]>>;
1403
+ /**
1404
+ * Perceptual luma (0..1) of the status-line background — used to classify the
1405
+ * theme light/dark. Undefined when it can't be resolved. Classified against the
1406
+ * status line (the surface session accents render on) rather than the chat bubble
1407
+ * (`userMessageBg`), which some themes (e.g. `porcelain`) style dark on an
1408
+ * otherwise-light theme.
1409
+ */
1410
+ readonly statusLineLuminance: number | undefined;
1411
+ /** WCAG relative luminance of the status-line background — basis for accent contrast. */
1412
+ readonly #statusLineContrastLuminance: number | undefined;
1413
+
1414
+ constructor(
1415
+ fgColors: Record<ThemeColor, string | number>,
1416
+ bgColors: Record<ThemeBg, string | number>,
1417
+ private readonly mode: ColorMode,
1418
+ private readonly symbolPreset: SymbolPreset,
1419
+ symbolOverrides: Partial<Record<SymbolKey, string>>,
1420
+ spinnerFramesOverrides: Partial<Record<SpinnerType, string[]>> = {},
1421
+ ) {
1422
+ this.statusLineLuminance = colorLuma(bgColors.statusLineBg);
1423
+ this.#statusLineContrastLuminance = relativeLuminance(bgColors.statusLineBg);
1424
+ this.#fgColors = {} as Record<ThemeColor, string>;
1425
+ for (const [key, value] of Object.entries(fgColors) as [ThemeColor, string | number][]) {
1426
+ this.#fgColors[key] = fgAnsi(value, mode);
1427
+ }
1428
+ this.#bgColors = {} as Record<ThemeBg, string>;
1429
+ for (const [key, value] of Object.entries(bgColors) as [ThemeBg, string | number][]) {
1430
+ this.#bgColors[key] = bgAnsi(value, mode);
1431
+ }
1432
+ // Build symbol map from preset + overrides
1433
+ const baseSymbols = SYMBOL_PRESETS[symbolPreset];
1434
+ this.#symbols = { ...baseSymbols };
1435
+ for (const [key, value] of Object.entries(symbolOverrides)) {
1436
+ if (key in this.#symbols) {
1437
+ this.#symbols[key as SymbolKey] = value;
1438
+ } else {
1439
+ logger.debug("Invalid symbol key in override", { key, availableKeys: Object.keys(this.#symbols) });
1440
+ }
1441
+ }
1442
+ this.#spinnerFramesOverrides = spinnerFramesOverrides;
1443
+ }
1444
+
1445
+ /** True when the active theme has a light status-line background. */
1446
+ get isLight(): boolean {
1447
+ return this.statusLineLuminance !== undefined && this.statusLineLuminance > 0.5;
1448
+ }
1449
+
1450
+ /**
1451
+ * Surface luminance to size session accents against on light themes; undefined on
1452
+ * dark themes so accents stay vivid. Pass straight to `getSessionAccentHex`.
1453
+ */
1454
+ get accentSurfaceLuminance(): number | undefined {
1455
+ return this.isLight ? this.#statusLineContrastLuminance : undefined;
1456
+ }
1457
+
1458
+ fg(color: ThemeColor, text: string): string {
1459
+ const ansi = this.#fgColors[color];
1460
+ if (!ansi) throw new Error(`Unknown theme color: ${color}`);
1461
+ return `${ansi}${text}\x1b[39m`; // Reset only foreground color
1462
+ }
1463
+
1464
+ bg(color: ThemeBg, text: string): string {
1465
+ const ansi = this.#bgColors[color];
1466
+ if (!ansi) throw new Error(`Unknown theme background color: ${color}`);
1467
+ return `${ansi}${text}\x1b[49m`; // Reset only background color
1468
+ }
1469
+
1470
+ bold(text: string): string {
1471
+ return chalk.bold(text);
1472
+ }
1473
+
1474
+ italic(text: string): string {
1475
+ return chalk.italic(text);
1476
+ }
1477
+
1478
+ underline(text: string): string {
1479
+ return chalk.underline(text);
1480
+ }
1481
+
1482
+ strikethrough(text: string): string {
1483
+ return chalk.strikethrough(text);
1484
+ }
1485
+
1486
+ inverse(text: string): string {
1487
+ return chalk.inverse(text);
1488
+ }
1489
+
1490
+ getFgAnsi(color: ThemeColor): string {
1491
+ const ansi = this.#fgColors[color];
1492
+ if (!ansi) throw new Error(`Unknown theme color: ${color}`);
1493
+ return ansi;
1494
+ }
1495
+
1496
+ getBgAnsi(color: ThemeBg): string {
1497
+ const ansi = this.#bgColors[color];
1498
+ if (!ansi) throw new Error(`Unknown theme background color: ${color}`);
1499
+ return ansi;
1500
+ }
1501
+
1502
+ /**
1503
+ * Foreground ANSI for text drawn **on top of** `fillColor` used as a solid
1504
+ * background (e.g. a powerline chip). Picks near-black or near-white by the
1505
+ * fill's perceived luminance (Rec. 601 luma) so the label stays legible on
1506
+ * both bright and dark fills, across light and dark themes.
1507
+ *
1508
+ * Reads the RGB out of the already-resolved truecolor escape; when the fill
1509
+ * is encoded as a 256-palette index (limited terminals) the RGB is
1510
+ * unavailable, so it falls back to the theme `text` color.
1511
+ */
1512
+ getContrastFgAnsi(fillColor: ThemeColor): string {
1513
+ const ansi = this.#fgColors[fillColor];
1514
+ const match = ansi ? /38;2;(\d+);(\d+);(\d+)/.exec(ansi) : null;
1515
+ if (!match) return this.#fgColors.text;
1516
+ const luma = 0.299 * Number(match[1]) + 0.587 * Number(match[2]) + 0.114 * Number(match[3]);
1517
+ return luma > 140 ? "\x1b[38;2;0;0;0m" : "\x1b[38;2;255;255;255m";
1518
+ }
1519
+
1520
+ getColorMode(): ColorMode {
1521
+ return this.mode;
1522
+ }
1523
+
1524
+ getThinkingBorderColor(level: ThinkingLevel | Effort): (str: string) => string {
1525
+ // Map thinking levels to dedicated theme colors
1526
+ switch (level) {
1527
+ case "off":
1528
+ return (str: string) => this.fg("thinkingOff", str);
1529
+ case "minimal":
1530
+ return (str: string) => this.fg("thinkingMinimal", str);
1531
+ case "low":
1532
+ return (str: string) => this.fg("thinkingLow", str);
1533
+ case "medium":
1534
+ return (str: string) => this.fg("thinkingMedium", str);
1535
+ case "high":
1536
+ return (str: string) => this.fg("thinkingHigh", str);
1537
+ case "xhigh":
1538
+ return (str: string) => this.fg("thinkingXhigh", str);
1539
+ default:
1540
+ return (str: string) => this.fg("thinkingOff", str);
1541
+ }
1542
+ }
1543
+
1544
+ getBashModeBorderColor(): (str: string) => string {
1545
+ return (str: string) => this.fg("bashMode", str);
1546
+ }
1547
+
1548
+ getPythonModeBorderColor(): (str: string) => string {
1549
+ return (str: string) => this.fg("pythonMode", str);
1550
+ }
1551
+
1552
+ // ============================================================================
1553
+ // Symbol Methods
1554
+ // ============================================================================
1555
+
1556
+ /**
1557
+ * Get a symbol by key.
1558
+ */
1559
+ symbol(key: SymbolKey): string {
1560
+ return this.#symbols[key];
1561
+ }
1562
+
1563
+ /**
1564
+ * Get a symbol styled with a color.
1565
+ */
1566
+ styledSymbol(key: SymbolKey, color: ThemeColor): string {
1567
+ return this.fg(color, this.#symbols[key]);
1568
+ }
1569
+
1570
+ /**
1571
+ * Get the current symbol preset.
1572
+ */
1573
+ getSymbolPreset(): SymbolPreset {
1574
+ return this.symbolPreset;
1575
+ }
1576
+
1577
+ // ============================================================================
1578
+ // Symbol Category Accessors
1579
+ // ============================================================================
1580
+
1581
+ get status() {
1582
+ return {
1583
+ success: this.#symbols["status.success"],
1584
+ error: this.#symbols["status.error"],
1585
+ warning: this.#symbols["status.warning"],
1586
+ info: this.#symbols["status.info"],
1587
+ pending: this.#symbols["status.pending"],
1588
+ disabled: this.#symbols["status.disabled"],
1589
+ enabled: this.#symbols["status.enabled"],
1590
+ running: this.#symbols["status.running"],
1591
+ shadowed: this.#symbols["status.shadowed"],
1592
+ aborted: this.#symbols["status.aborted"],
1593
+ done: this.#symbols["status.done"],
1594
+ };
1595
+ }
1596
+
1597
+ get nav() {
1598
+ return {
1599
+ cursor: this.#symbols["nav.cursor"],
1600
+ selected: this.#symbols["nav.selected"],
1601
+ expand: this.#symbols["nav.expand"],
1602
+ collapse: this.#symbols["nav.collapse"],
1603
+ back: this.#symbols["nav.back"],
1604
+ };
1605
+ }
1606
+
1607
+ get tree() {
1608
+ return {
1609
+ branch: this.#symbols["tree.branch"],
1610
+ last: this.#symbols["tree.last"],
1611
+ vertical: this.#symbols["tree.vertical"],
1612
+ horizontal: this.#symbols["tree.horizontal"],
1613
+ hook: this.#symbols["tree.hook"],
1614
+ };
1615
+ }
1616
+
1617
+ get boxRound() {
1618
+ return {
1619
+ topLeft: this.#symbols["boxRound.topLeft"],
1620
+ topRight: this.#symbols["boxRound.topRight"],
1621
+ bottomLeft: this.#symbols["boxRound.bottomLeft"],
1622
+ bottomRight: this.#symbols["boxRound.bottomRight"],
1623
+ horizontal: this.#symbols["boxRound.horizontal"],
1624
+ vertical: this.#symbols["boxRound.vertical"],
1625
+ };
1626
+ }
1627
+
1628
+ get boxSharp() {
1629
+ return {
1630
+ topLeft: this.#symbols["boxSharp.topLeft"],
1631
+ topRight: this.#symbols["boxSharp.topRight"],
1632
+ bottomLeft: this.#symbols["boxSharp.bottomLeft"],
1633
+ bottomRight: this.#symbols["boxSharp.bottomRight"],
1634
+ horizontal: this.#symbols["boxSharp.horizontal"],
1635
+ vertical: this.#symbols["boxSharp.vertical"],
1636
+ cross: this.#symbols["boxSharp.cross"],
1637
+ teeDown: this.#symbols["boxSharp.teeDown"],
1638
+ teeUp: this.#symbols["boxSharp.teeUp"],
1639
+ teeRight: this.#symbols["boxSharp.teeRight"],
1640
+ teeLeft: this.#symbols["boxSharp.teeLeft"],
1641
+ };
1642
+ }
1643
+
1644
+ get sep() {
1645
+ return {
1646
+ powerline: this.#symbols["sep.powerline"],
1647
+ powerlineThin: this.#symbols["sep.powerlineThin"],
1648
+ powerlineLeft: this.#symbols["sep.powerlineLeft"],
1649
+ powerlineRight: this.#symbols["sep.powerlineRight"],
1650
+ powerlineThinLeft: this.#symbols["sep.powerlineThinLeft"],
1651
+ powerlineThinRight: this.#symbols["sep.powerlineThinRight"],
1652
+ block: this.#symbols["sep.block"],
1653
+ space: this.#symbols["sep.space"],
1654
+ asciiLeft: this.#symbols["sep.asciiLeft"],
1655
+ asciiRight: this.#symbols["sep.asciiRight"],
1656
+ dot: this.#symbols["sep.dot"],
1657
+ slash: this.#symbols["sep.slash"],
1658
+ pipe: this.#symbols["sep.pipe"],
1659
+ };
1660
+ }
1661
+
1662
+ get icon() {
1663
+ return {
1664
+ model: this.#symbols["icon.model"],
1665
+ plan: this.#symbols["icon.plan"],
1666
+ goal: this.#symbols["icon.goal"],
1667
+ pause: this.#symbols["icon.pause"],
1668
+ loop: this.#symbols["icon.loop"],
1669
+ folder: this.#symbols["icon.folder"],
1670
+ scratchFolder: this.#symbols["icon.scratchFolder"],
1671
+ file: this.#symbols["icon.file"],
1672
+ git: this.#symbols["icon.git"],
1673
+ branch: this.#symbols["icon.branch"],
1674
+ pr: this.#symbols["icon.pr"],
1675
+ tokens: this.#symbols["icon.tokens"],
1676
+ context: this.#symbols["icon.context"],
1677
+ cost: this.#symbols["icon.cost"],
1678
+ time: this.#symbols["icon.time"],
1679
+ pi: this.#symbols["icon.pi"],
1680
+ agents: this.#symbols["icon.agents"],
1681
+ cache: this.#symbols["icon.cache"],
1682
+ input: this.#symbols["icon.input"],
1683
+ output: this.#symbols["icon.output"],
1684
+ host: this.#symbols["icon.host"],
1685
+ session: this.#symbols["icon.session"],
1686
+ package: this.#symbols["icon.package"],
1687
+ warning: this.#symbols["icon.warning"],
1688
+ rewind: this.#symbols["icon.rewind"],
1689
+ auto: this.#symbols["icon.auto"],
1690
+ fast: this.#symbols["icon.fast"],
1691
+ extensionSkill: this.#symbols["icon.extensionSkill"],
1692
+ extensionTool: this.#symbols["icon.extensionTool"],
1693
+ extensionSlashCommand: this.#symbols["icon.extensionSlashCommand"],
1694
+ extensionMcp: this.#symbols["icon.extensionMcp"],
1695
+ extensionRule: this.#symbols["icon.extensionRule"],
1696
+ extensionHook: this.#symbols["icon.extensionHook"],
1697
+ extensionPrompt: this.#symbols["icon.extensionPrompt"],
1698
+ extensionContextFile: this.#symbols["icon.extensionContextFile"],
1699
+ extensionInstruction: this.#symbols["icon.extensionInstruction"],
1700
+ mic: this.#symbols["icon.mic"],
1701
+ camera: this.#symbols["icon.camera"],
1702
+ };
1703
+ }
1704
+
1705
+ get thinking() {
1706
+ return {
1707
+ minimal: this.#symbols["thinking.minimal"],
1708
+ low: this.#symbols["thinking.low"],
1709
+ medium: this.#symbols["thinking.medium"],
1710
+ high: this.#symbols["thinking.high"],
1711
+ xhigh: this.#symbols["thinking.xhigh"],
1712
+ autoPending: this.#symbols["thinking.autoPending"],
1713
+ };
1714
+ }
1715
+
1716
+ get checkbox() {
1717
+ return {
1718
+ checked: this.#symbols["checkbox.checked"],
1719
+ unchecked: this.#symbols["checkbox.unchecked"],
1720
+ };
1721
+ }
1722
+
1723
+ get radio() {
1724
+ return {
1725
+ selected: this.#symbols["radio.selected"],
1726
+ unselected: this.#symbols["radio.unselected"],
1727
+ };
1728
+ }
1729
+
1730
+ get format() {
1731
+ return {
1732
+ bullet: this.#symbols["format.bullet"],
1733
+ dash: this.#symbols["format.dash"],
1734
+ bracketLeft: this.#symbols["format.bracketLeft"],
1735
+ bracketRight: this.#symbols["format.bracketRight"],
1736
+ };
1737
+ }
1738
+
1739
+ get md() {
1740
+ return {
1741
+ quoteBorder: this.#symbols["md.quoteBorder"],
1742
+ hrChar: this.#symbols["md.hrChar"],
1743
+ bullet: this.#symbols["md.bullet"],
1744
+ colorSwatch: this.#symbols["md.colorSwatch"],
1745
+ };
1746
+ }
1747
+
1748
+ /**
1749
+ * Default spinner frames (status spinner).
1750
+ */
1751
+ get spinnerFrames(): string[] {
1752
+ return this.getSpinnerFrames();
1753
+ }
1754
+
1755
+ /**
1756
+ * Get spinner frames by type.
1757
+ */
1758
+ getSpinnerFrames(type: SpinnerType = "status"): string[] {
1759
+ return this.#spinnerFramesOverrides[type] ?? SPINNER_FRAMES[this.symbolPreset][type];
1760
+ }
1761
+
1762
+ /**
1763
+ * Get language icon for a language name.
1764
+ * Maps common language names to their corresponding symbol keys.
1765
+ */
1766
+ getLangIcon(lang: string | undefined): string {
1767
+ if (!lang) return this.#symbols["lang.default"];
1768
+ const normalized = lang.toLowerCase();
1769
+ const key = langMap[normalized];
1770
+ return key ? this.#symbols[key] : this.#symbols["lang.default"];
1771
+ }
1772
+ }
1773
+
1774
+ // ============================================================================
1775
+ // Theme Loading
1776
+ // ============================================================================
1777
+
1778
+ const BUILTIN_THEMES: Record<string, ThemeJson> = {
1779
+ dark: darkThemeJson as ThemeJson,
1780
+ light: lightThemeJson as ThemeJson,
1781
+ ...(defaultThemes as Record<string, ThemeJson>),
1782
+ };
1783
+
1784
+ function getBuiltinThemes(): Record<string, ThemeJson> {
1785
+ return BUILTIN_THEMES;
1786
+ }
1787
+
1788
+ export async function getAvailableThemes(): Promise<string[]> {
1789
+ const themes = new Set<string>(Object.keys(getBuiltinThemes()));
1790
+ const customThemesDir = getCustomThemesDir();
1791
+ try {
1792
+ const files = await fs.promises.readdir(customThemesDir);
1793
+ for (const file of files) {
1794
+ if (file.endsWith(".json")) {
1795
+ themes.add(file.slice(0, -5));
1796
+ }
1797
+ }
1798
+ } catch {
1799
+ // Directory doesn't exist or isn't readable
1800
+ }
1801
+ return Array.from(themes).sort();
1802
+ }
1803
+
1804
+ export interface ThemeInfo {
1805
+ name: string;
1806
+ path: string | undefined;
1807
+ }
1808
+
1809
+ export async function getAvailableThemesWithPaths(): Promise<ThemeInfo[]> {
1810
+ const result: ThemeInfo[] = [];
1811
+
1812
+ // Built-in themes (embedded, no file path)
1813
+ for (const name of Object.keys(getBuiltinThemes())) {
1814
+ result.push({ name, path: undefined });
1815
+ }
1816
+
1817
+ // Custom themes
1818
+ const customThemesDir = getCustomThemesDir();
1819
+ try {
1820
+ const files = await fs.promises.readdir(customThemesDir);
1821
+ for (const file of files) {
1822
+ if (file.endsWith(".json")) {
1823
+ const name = file.slice(0, -5);
1824
+ if (!result.some(themeInfo => themeInfo.name === name)) {
1825
+ result.push({ name, path: path.join(customThemesDir, file) });
1826
+ }
1827
+ }
1828
+ }
1829
+ } catch {
1830
+ // Directory doesn't exist or isn't readable
1831
+ }
1832
+
1833
+ return result.sort((a, b) => a.name.localeCompare(b.name));
1834
+ }
1835
+
1836
+ async function loadThemeJson(name: string): Promise<ThemeJson> {
1837
+ const builtinThemes = getBuiltinThemes();
1838
+ if (name in builtinThemes) {
1839
+ return builtinThemes[name];
1840
+ }
1841
+ const customThemesDir = getCustomThemesDir();
1842
+ const themePath = path.join(customThemesDir, `${name}.json`);
1843
+ let content: string;
1844
+ try {
1845
+ content = await Bun.file(themePath).text();
1846
+ } catch (err) {
1847
+ if (isEnoent(err)) throw new Error(`Theme not found: ${name}`);
1848
+ throw err;
1849
+ }
1850
+ let json: unknown;
1851
+ try {
1852
+ json = JSON.parse(content);
1853
+ } catch (error) {
1854
+ throw new Error(`Failed to parse theme ${name}: ${error}`);
1855
+ }
1856
+ const parsed = themeJsonSchema.safeParse(json);
1857
+ if (!parsed.success) {
1858
+ const missingColors: string[] = [];
1859
+ const otherErrors: string[] = [];
1860
+
1861
+ for (const issue of parsed.error.issues) {
1862
+ const parts = issue.path;
1863
+ const colorKey = parts.length === 2 && parts[0] === "colors" && typeof parts[1] === "string" ? parts[1] : null;
1864
+
1865
+ if (colorKey && issue.code === "invalid_type" && (issue as { received?: unknown }).received === undefined) {
1866
+ missingColors.push(colorKey);
1867
+ } else {
1868
+ const pathStr = parts.length === 0 ? "/" : `/${parts.map(String).join("/")}`;
1869
+ otherErrors.push(` - ${pathStr}: ${issue.message}`);
1870
+ }
1871
+ }
1872
+
1873
+ let errorMessage = `Invalid theme "${name}":\n`;
1874
+ if (missingColors.length > 0) {
1875
+ errorMessage += `\nMissing required color tokens:\n`;
1876
+ errorMessage += missingColors.map(c => ` - ${c}`).join("\n");
1877
+ errorMessage += `\n\nPlease add these colors to your theme's "colors" object.`;
1878
+ errorMessage += `\nSee the built-in themes (dark.json, light.json) for reference values.`;
1879
+ }
1880
+ if (otherErrors.length > 0) {
1881
+ errorMessage += `\n\nOther errors:\n${otherErrors.join("\n")}`;
1882
+ }
1883
+
1884
+ throw new Error(errorMessage);
1885
+ }
1886
+ return parsed.data;
1887
+ }
1888
+
1889
+ interface CreateThemeOptions {
1890
+ mode?: ColorMode;
1891
+ symbolPresetOverride?: SymbolPreset;
1892
+ colorBlindMode?: boolean;
1893
+ }
1894
+
1895
+ /** HSV adjustment to shift green toward blue for colorblind mode (red-green colorblindness) */
1896
+ const COLORBLIND_ADJUSTMENT = { h: 60, s: 0.71 };
1897
+
1898
+ function createTheme(themeJson: ThemeJson, options: CreateThemeOptions = {}): Theme {
1899
+ const { mode, symbolPresetOverride, colorBlindMode } = options;
1900
+ const colorMode = mode ?? detectColorMode();
1901
+ const resolvedColors = resolveThemeColors(themeJson.colors, themeJson.vars);
1902
+
1903
+ if (colorBlindMode) {
1904
+ const added = resolvedColors.toolDiffAdded;
1905
+ if (typeof added === "string" && added.startsWith("#")) {
1906
+ resolvedColors.toolDiffAdded = adjustHsv(added, COLORBLIND_ADJUSTMENT);
1907
+ }
1908
+ }
1909
+
1910
+ const fgColors: Record<ThemeColor, string | number> = {} as Record<ThemeColor, string | number>;
1911
+ const bgColors: Record<ThemeBg, string | number> = {} as Record<ThemeBg, string | number>;
1912
+ const bgColorKeys: Set<string> = new Set([
1913
+ "selectedBg",
1914
+ "userMessageBg",
1915
+ "customMessageBg",
1916
+ "toolPendingBg",
1917
+ "toolSuccessBg",
1918
+ "toolErrorBg",
1919
+ "statusLineBg",
1920
+ ]);
1921
+ for (const [key, value] of Object.entries(resolvedColors)) {
1922
+ if (bgColorKeys.has(key)) {
1923
+ bgColors[key as ThemeBg] = value;
1924
+ } else {
1925
+ fgColors[key as ThemeColor] = value;
1926
+ }
1927
+ }
1928
+ // Extract symbol configuration - settings override takes precedence over theme
1929
+ const symbolPreset: SymbolPreset = symbolPresetOverride ?? themeJson.symbols?.preset ?? "unicode";
1930
+ const symbolOverrides = themeJson.symbols?.overrides ?? {};
1931
+ const spinnerFramesOverrides = normalizeSpinnerFramesOverride(themeJson.symbols?.spinnerFrames);
1932
+ return new Theme(fgColors, bgColors, colorMode, symbolPreset, symbolOverrides, spinnerFramesOverrides);
1933
+ }
1934
+
1935
+ async function loadTheme(name: string, options: CreateThemeOptions = {}): Promise<Theme> {
1936
+ const themeJson = await loadThemeJson(name);
1937
+ return createTheme(themeJson, options);
1938
+ }
1939
+
1940
+ export async function getThemeByName(name: string): Promise<Theme | undefined> {
1941
+ try {
1942
+ return await loadTheme(name);
1943
+ } catch {
1944
+ return undefined;
1945
+ }
1946
+ }
1947
+
1948
+ /** Appearance detected via OSC 11 background color query, or undefined if not yet available. */
1949
+ var terminalReportedAppearance: "dark" | "light" | undefined;
1950
+
1951
+ /** Appearance reported by the macOS fallback observer, or undefined if not yet available. */
1952
+ var macOSReportedAppearance: "dark" | "light" | undefined;
1953
+
1954
+ function shouldUseMacOSAppearanceFallback(): boolean {
1955
+ // Zellij currently breaks OSC 11 passthrough on macOS, so terminal-derived
1956
+ // appearance cannot be trusted there. Fall back to host macOS appearance
1957
+ // without letting it override valid terminal signals elsewhere.
1958
+ return process.platform === "darwin" && !!Bun.env.ZELLIJ;
1959
+ }
1960
+
1961
+ function detectTerminalBackground(): "dark" | "light" {
1962
+ // Tier 1: terminal-reported appearance from OSC 11 luminance.
1963
+ if (!shouldUseMacOSAppearanceFallback() && terminalReportedAppearance) {
1964
+ return terminalReportedAppearance;
1965
+ }
1966
+
1967
+ // Tier 2: COLORFGBG env var (static at process start, but still terminal-derived).
1968
+ const colorfgbg = Bun.env.COLORFGBG || "";
1969
+ if (colorfgbg) {
1970
+ const parts = colorfgbg.split(";");
1971
+ if (parts.length >= 2) {
1972
+ const bg = parseInt(parts[1], 10);
1973
+ if (!Number.isNaN(bg)) return bg < 8 ? "dark" : "light";
1974
+ }
1975
+ }
1976
+
1977
+ // Tier 3: host macOS appearance for known-broken terminal paths only.
1978
+ if (shouldUseMacOSAppearanceFallback()) {
1979
+ const macAppearance = macOSReportedAppearance ?? detectMacOSAppearance();
1980
+ if (macAppearance) return macAppearance;
1981
+ }
1982
+
1983
+ return "dark";
1984
+ }
1985
+
1986
+ function getDefaultTheme(): string {
1987
+ const bg = detectTerminalBackground();
1988
+ return bg === "light" ? autoLightTheme : autoDarkTheme;
1989
+ }
1990
+
1991
+ // ============================================================================
1992
+ // Global Theme Instance
1993
+ // ============================================================================
1994
+
1995
+ export var theme: Theme;
1996
+ var currentThemeName: string | undefined;
1997
+
1998
+ /** Get the name of the currently active theme. */
1999
+ export function getCurrentThemeName(): string | undefined {
2000
+ return currentThemeName;
2001
+ }
2002
+ var currentSymbolPresetOverride: SymbolPreset | undefined;
2003
+ var currentColorBlindMode: boolean = false;
2004
+ var themeWatcher: fs.FSWatcher | undefined;
2005
+ var themeReloadTimer: NodeJS.Timeout | undefined;
2006
+ var sigwinchHandler: (() => void) | undefined;
2007
+ var autoDetectedTheme: boolean = false;
2008
+ var autoDarkTheme: string = "dark";
2009
+ var autoLightTheme: string = "light";
2010
+ var onThemeChangeCallback: (() => void) | undefined;
2011
+ var themeLoadRequestId: number = 0;
2012
+
2013
+ function getCurrentThemeOptions(): CreateThemeOptions {
2014
+ return {
2015
+ symbolPresetOverride: currentSymbolPresetOverride,
2016
+ colorBlindMode: currentColorBlindMode,
2017
+ };
2018
+ }
2019
+
2020
+ export async function initTheme(
2021
+ enableWatcher: boolean = false,
2022
+ symbolPreset?: SymbolPreset,
2023
+ colorBlindMode?: boolean,
2024
+ darkTheme?: string,
2025
+ lightTheme?: string,
2026
+ ): Promise<void> {
2027
+ autoDetectedTheme = true;
2028
+ autoDarkTheme = darkTheme ?? "dark";
2029
+ autoLightTheme = lightTheme ?? "light";
2030
+ const name = getDefaultTheme();
2031
+ currentThemeName = name;
2032
+ currentSymbolPresetOverride = symbolPreset;
2033
+ currentColorBlindMode = colorBlindMode ?? false;
2034
+ try {
2035
+ theme = await loadTheme(name, getCurrentThemeOptions());
2036
+ if (enableWatcher) {
2037
+ await startThemeWatcher();
2038
+ startSigwinchListener();
2039
+ }
2040
+ } catch (err) {
2041
+ logger.debug("Theme loading failed, falling back to dark theme", { error: String(err) });
2042
+ currentThemeName = "dark";
2043
+ theme = await loadTheme("dark", getCurrentThemeOptions());
2044
+ // Don't start watcher for fallback theme
2045
+ }
2046
+ }
2047
+
2048
+ export async function setTheme(
2049
+ name: string,
2050
+ enableWatcher: boolean = false,
2051
+ ): Promise<{ success: boolean; error?: string }> {
2052
+ autoDetectedTheme = false;
2053
+ currentThemeName = name;
2054
+ const requestId = ++themeLoadRequestId;
2055
+ try {
2056
+ const loadedTheme = await loadTheme(name, getCurrentThemeOptions());
2057
+ if (requestId !== themeLoadRequestId) {
2058
+ return { success: false, error: "Theme change superseded by a newer request" };
2059
+ }
2060
+ theme = loadedTheme;
2061
+ if (enableWatcher) {
2062
+ await startThemeWatcher();
2063
+ }
2064
+ if (onThemeChangeCallback) {
2065
+ onThemeChangeCallback();
2066
+ }
2067
+ return { success: true };
2068
+ } catch (error) {
2069
+ if (requestId !== themeLoadRequestId) {
2070
+ return { success: false, error: "Theme change superseded by a newer request" };
2071
+ }
2072
+ // Theme is invalid - fall back to dark theme
2073
+ currentThemeName = "dark";
2074
+ theme = await loadTheme("dark", getCurrentThemeOptions());
2075
+ // Don't start watcher for fallback theme
2076
+ return {
2077
+ success: false,
2078
+ error: error instanceof Error ? error.message : String(error),
2079
+ };
2080
+ }
2081
+ }
2082
+
2083
+ export async function previewTheme(name: string): Promise<{ success: boolean; error?: string }> {
2084
+ const requestId = ++themeLoadRequestId;
2085
+ try {
2086
+ const loadedTheme = await loadTheme(name, getCurrentThemeOptions());
2087
+ if (requestId !== themeLoadRequestId) {
2088
+ return { success: false, error: "Theme preview superseded by a newer request" };
2089
+ }
2090
+ theme = loadedTheme;
2091
+ if (onThemeChangeCallback) {
2092
+ onThemeChangeCallback();
2093
+ }
2094
+ return { success: true };
2095
+ } catch (error) {
2096
+ if (requestId !== themeLoadRequestId) {
2097
+ return { success: false, error: "Theme preview superseded by a newer request" };
2098
+ }
2099
+ return {
2100
+ success: false,
2101
+ error: error instanceof Error ? error.message : String(error),
2102
+ };
2103
+ }
2104
+ }
2105
+
2106
+ /**
2107
+ * Enable auto-detection mode, switching to the appropriate dark/light theme.
2108
+ */
2109
+ export function enableAutoTheme(): void {
2110
+ autoDetectedTheme = true;
2111
+ reevaluateAutoTheme("enableAutoTheme");
2112
+ }
2113
+
2114
+ /**
2115
+ * Update the theme mappings for auto-detection mode.
2116
+ * When a dark/light mapping changes and auto-detection is active, re-evaluate the theme.
2117
+ */
2118
+ export function setAutoThemeMapping(mode: "dark" | "light", themeName: string): void {
2119
+ if (mode === "dark") autoDarkTheme = themeName;
2120
+ else autoLightTheme = themeName;
2121
+ reevaluateAutoTheme("setAutoThemeMapping");
2122
+ }
2123
+
2124
+ /**
2125
+ * Called when the terminal detects a dark/light appearance change.
2126
+ * The terminal layer queries OSC 11 (background color) and computes luminance;
2127
+ * Mode 2031 notifications trigger re-queries rather than providing the value directly.
2128
+ */
2129
+ export function onTerminalAppearanceChange(mode: "dark" | "light"): void {
2130
+ if (terminalReportedAppearance === mode) return;
2131
+ terminalReportedAppearance = mode;
2132
+ reevaluateAutoTheme("terminal appearance");
2133
+ }
2134
+
2135
+ export function setThemeInstance(themeInstance: Theme): void {
2136
+ autoDetectedTheme = false;
2137
+ theme = themeInstance;
2138
+ currentThemeName = "<in-memory>";
2139
+ stopThemeWatcher();
2140
+ if (onThemeChangeCallback) {
2141
+ onThemeChangeCallback();
2142
+ }
2143
+ }
2144
+
2145
+ /**
2146
+ * Set the symbol preset override, recreating the theme with the new preset.
2147
+ */
2148
+ export async function setSymbolPreset(preset: SymbolPreset): Promise<void> {
2149
+ currentSymbolPresetOverride = preset;
2150
+ if (!currentThemeName) return;
2151
+
2152
+ const requestId = ++themeLoadRequestId;
2153
+ try {
2154
+ const loadedTheme = await loadTheme(currentThemeName, getCurrentThemeOptions());
2155
+ if (requestId !== themeLoadRequestId) return;
2156
+ theme = loadedTheme;
2157
+ } catch {
2158
+ if (requestId !== themeLoadRequestId) return;
2159
+ // Fall back to dark theme with new preset
2160
+ theme = await loadTheme("dark", getCurrentThemeOptions());
2161
+ if (requestId !== themeLoadRequestId) return;
2162
+ }
2163
+ onThemeChangeCallback?.();
2164
+ }
2165
+
2166
+ /**
2167
+ * Get the current symbol preset override.
2168
+ */
2169
+ export function getSymbolPresetOverride(): SymbolPreset | undefined {
2170
+ return currentSymbolPresetOverride;
2171
+ }
2172
+
2173
+ /**
2174
+ * Set color blind mode, recreating the theme with the new setting.
2175
+ * When enabled, uses blue instead of green for diff additions.
2176
+ */
2177
+ export async function setColorBlindMode(enabled: boolean): Promise<void> {
2178
+ currentColorBlindMode = enabled;
2179
+ if (!currentThemeName) return;
2180
+
2181
+ const requestId = ++themeLoadRequestId;
2182
+ try {
2183
+ const loadedTheme = await loadTheme(currentThemeName, getCurrentThemeOptions());
2184
+ if (requestId !== themeLoadRequestId) return;
2185
+ theme = loadedTheme;
2186
+ } catch {
2187
+ if (requestId !== themeLoadRequestId) return;
2188
+ // Fall back to dark theme
2189
+ theme = await loadTheme("dark", getCurrentThemeOptions());
2190
+ if (requestId !== themeLoadRequestId) return;
2191
+ }
2192
+ onThemeChangeCallback?.();
2193
+ }
2194
+
2195
+ /**
2196
+ * Get the current color blind mode setting.
2197
+ */
2198
+ export function getColorBlindMode(): boolean {
2199
+ return currentColorBlindMode;
2200
+ }
2201
+
2202
+ export function onThemeChange(callback: () => void): void {
2203
+ onThemeChangeCallback = callback;
2204
+ }
2205
+
2206
+ /**
2207
+ * Get available symbol presets.
2208
+ */
2209
+ export function getAvailableSymbolPresets(): SymbolPreset[] {
2210
+ return ["unicode", "nerd", "ascii"];
2211
+ }
2212
+
2213
+ /**
2214
+ * Check if a string is a valid symbol preset.
2215
+ */
2216
+ export function isValidSymbolPreset(preset: string): preset is SymbolPreset {
2217
+ return preset === "unicode" || preset === "nerd" || preset === "ascii";
2218
+ }
2219
+
2220
+ async function startThemeWatcher(): Promise<void> {
2221
+ stopThemeWatcher();
2222
+
2223
+ // Only watch if it's a custom theme (not built-in)
2224
+ if (!currentThemeName || currentThemeName === "dark" || currentThemeName === "light") {
2225
+ return;
2226
+ }
2227
+
2228
+ const customThemesDir = getCustomThemesDir();
2229
+ const watchedThemeName = currentThemeName;
2230
+ const watchedFileName = `${watchedThemeName}.json`;
2231
+ const themeFile = path.join(customThemesDir, watchedFileName);
2232
+
2233
+ // Only watch if the file exists
2234
+ if (!fs.existsSync(themeFile)) {
2235
+ return;
2236
+ }
2237
+
2238
+ const scheduleReload = () => {
2239
+ if (themeReloadTimer) {
2240
+ clearTimeout(themeReloadTimer);
2241
+ }
2242
+ themeReloadTimer = setTimeout(() => {
2243
+ themeReloadTimer = undefined;
2244
+
2245
+ // Ignore stale timers after switching themes or stopping the watcher
2246
+ if (currentThemeName !== watchedThemeName) {
2247
+ return;
2248
+ }
2249
+
2250
+ // Keep the last successfully loaded theme active if the file is temporarily missing
2251
+ if (!fs.existsSync(themeFile)) {
2252
+ return;
2253
+ }
2254
+
2255
+ loadTheme(watchedThemeName, getCurrentThemeOptions())
2256
+ .then(loadedTheme => {
2257
+ theme = loadedTheme;
2258
+ if (onThemeChangeCallback) {
2259
+ onThemeChangeCallback();
2260
+ }
2261
+ })
2262
+ .catch(() => {
2263
+ // Ignore errors (file might be in invalid state while being edited)
2264
+ });
2265
+ }, 100);
2266
+ };
2267
+
2268
+ try {
2269
+ themeWatcher = fs.watch(customThemesDir, (_eventType, filename) => {
2270
+ if (currentThemeName !== watchedThemeName) {
2271
+ return;
2272
+ }
2273
+ if (!filename) {
2274
+ scheduleReload();
2275
+ return;
2276
+ }
2277
+ const changedFile = String(filename);
2278
+ if (changedFile !== watchedFileName) {
2279
+ return;
2280
+ }
2281
+ scheduleReload();
2282
+ });
2283
+ } catch {
2284
+ // Ignore errors starting watcher
2285
+ }
2286
+ }
2287
+
2288
+ /**
2289
+ * Shared logic for re-evaluating the auto-detected theme.
2290
+ * Called from SIGWINCH, terminal appearance change handler, and macOS fallback observer.
2291
+ */
2292
+ function reevaluateAutoTheme(debugLabel: string): void {
2293
+ if (!autoDetectedTheme) return;
2294
+ const resolved = getDefaultTheme();
2295
+ if (resolved === currentThemeName) return;
2296
+ currentThemeName = resolved;
2297
+ loadTheme(resolved, getCurrentThemeOptions())
2298
+ .then(loadedTheme => {
2299
+ theme = loadedTheme;
2300
+ if (onThemeChangeCallback) {
2301
+ onThemeChangeCallback();
2302
+ }
2303
+ })
2304
+ .catch(err => {
2305
+ logger.debug(`Theme switch on ${debugLabel} failed`, { error: String(err) });
2306
+ });
2307
+ }
2308
+
2309
+ // ============================================================================
2310
+ // macOS Appearance Fallback Observer
2311
+ // ============================================================================
2312
+
2313
+ var macObserver: { stop(): void } | undefined;
2314
+
2315
+ function startMacAppearanceObserver(): void {
2316
+ stopMacAppearanceObserver();
2317
+ if (!shouldUseMacOSAppearanceFallback()) return;
2318
+ try {
2319
+ macOSReportedAppearance = detectMacOSAppearance() ?? undefined;
2320
+ macObserver = MacAppearanceObserver.start((err, appearance) => {
2321
+ if (!err && (appearance === "dark" || appearance === "light")) {
2322
+ macOSReportedAppearance = appearance;
2323
+ reevaluateAutoTheme("macOS fallback");
2324
+ }
2325
+ });
2326
+ } catch (err) {
2327
+ logger.warn("Failed to start macOS appearance observer", { err });
2328
+ }
2329
+ }
2330
+
2331
+ function stopMacAppearanceObserver(): void {
2332
+ if (macObserver) {
2333
+ macObserver.stop();
2334
+ macObserver = undefined;
2335
+ }
2336
+ macOSReportedAppearance = undefined;
2337
+ }
2338
+
2339
+ // ============================================================================
2340
+ // SIGWINCH Listener
2341
+ // ============================================================================
2342
+
2343
+ /** Re-check appearance on SIGWINCH and switch dark/light when using auto-detected theme. */
2344
+ function startSigwinchListener(): void {
2345
+ stopSigwinchListener();
2346
+ sigwinchHandler = () => {
2347
+ reevaluateAutoTheme("SIGWINCH");
2348
+ };
2349
+ process.on("SIGWINCH", sigwinchHandler);
2350
+ startMacAppearanceObserver();
2351
+ }
2352
+
2353
+ function stopSigwinchListener(): void {
2354
+ if (sigwinchHandler) {
2355
+ process.removeListener("SIGWINCH", sigwinchHandler);
2356
+ sigwinchHandler = undefined;
2357
+ }
2358
+ stopMacAppearanceObserver();
2359
+ }
2360
+
2361
+ export function stopThemeWatcher(): void {
2362
+ if (themeReloadTimer) {
2363
+ clearTimeout(themeReloadTimer);
2364
+ themeReloadTimer = undefined;
2365
+ }
2366
+ if (themeWatcher) {
2367
+ themeWatcher.close();
2368
+ themeWatcher = undefined;
2369
+ }
2370
+ stopSigwinchListener();
2371
+ terminalReportedAppearance = undefined;
2372
+ }
2373
+
2374
+ // ============================================================================
2375
+ // HTML Export Helpers
2376
+ // ============================================================================
2377
+
2378
+ /**
2379
+ * Convert a 256-color index to hex string.
2380
+ * Indices 0-15: basic colors (approximate)
2381
+ * Indices 16-231: 6x6x6 color cube
2382
+ * Indices 232-255: grayscale ramp
2383
+ */
2384
+ function ansi256ToHex(index: number): string {
2385
+ // Basic colors (0-15) - approximate common terminal values
2386
+ const basicColors = [
2387
+ "#000000",
2388
+ "#800000",
2389
+ "#008000",
2390
+ "#808000",
2391
+ "#000080",
2392
+ "#800080",
2393
+ "#008080",
2394
+ "#c0c0c0",
2395
+ "#808080",
2396
+ "#ff0000",
2397
+ "#00ff00",
2398
+ "#ffff00",
2399
+ "#0000ff",
2400
+ "#ff00ff",
2401
+ "#00ffff",
2402
+ "#ffffff",
2403
+ ];
2404
+ if (index < 16) {
2405
+ return basicColors[index];
2406
+ }
2407
+
2408
+ // Color cube (16-231): 6x6x6 = 216 colors
2409
+ if (index < 232) {
2410
+ const cubeIndex = index - 16;
2411
+ const r = Math.floor(cubeIndex / 36);
2412
+ const g = Math.floor((cubeIndex % 36) / 6);
2413
+ const b = cubeIndex % 6;
2414
+ const toHex = (n: number) => (n === 0 ? 0 : 55 + n * 40).toString(16).padStart(2, "0");
2415
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
2416
+ }
2417
+
2418
+ // Grayscale (232-255): 24 shades
2419
+ const gray = 8 + (index - 232) * 10;
2420
+ const grayHex = gray.toString(16).padStart(2, "0");
2421
+ return `#${grayHex}${grayHex}${grayHex}`;
2422
+ }
2423
+
2424
+ /**
2425
+ * Get resolved theme colors as CSS-compatible hex strings.
2426
+ * Used by HTML export to generate CSS custom properties.
2427
+ */
2428
+ export async function getResolvedThemeColors(themeName?: string): Promise<Record<string, string>> {
2429
+ const name = themeName ?? getDefaultTheme();
2430
+ const isLight = name === "light";
2431
+ const themeJson = await loadThemeJson(name);
2432
+ const resolved = resolveThemeColors(themeJson.colors, themeJson.vars);
2433
+
2434
+ // Default text color for empty values (terminal uses default fg color)
2435
+ const defaultText = isLight ? "#000000" : "#e5e5e7";
2436
+
2437
+ const cssColors: Record<string, string> = {};
2438
+ for (const [key, value] of Object.entries(resolved)) {
2439
+ if (typeof value === "number") {
2440
+ cssColors[key] = ansi256ToHex(value);
2441
+ } else if (value === "") {
2442
+ // Empty means default terminal color - use sensible fallback for HTML
2443
+ cssColors[key] = defaultText;
2444
+ } else {
2445
+ cssColors[key] = value;
2446
+ }
2447
+ }
2448
+ return cssColors;
2449
+ }
2450
+
2451
+ /**
2452
+ * Check if a theme is a "light" theme by analyzing its background color luminance.
2453
+ * Loads theme JSON synchronously (built-in or custom file) and resolves userMessageBg.
2454
+ */
2455
+ export function isLightTheme(themeName?: string): boolean {
2456
+ const name = themeName ?? "dark";
2457
+ const builtinThemes = getBuiltinThemes();
2458
+ let themeJson: ThemeJson | undefined;
2459
+ if (name in builtinThemes) {
2460
+ themeJson = builtinThemes[name];
2461
+ } else {
2462
+ try {
2463
+ const customPath = path.join(getCustomThemesDir(), `${name}.json`);
2464
+ const content = fs.readFileSync(customPath, "utf-8");
2465
+ themeJson = JSON.parse(content) as ThemeJson;
2466
+ } catch {
2467
+ return false;
2468
+ }
2469
+ }
2470
+ try {
2471
+ const resolved = resolveVarRefs(themeJson.colors.userMessageBg, themeJson.vars ?? {});
2472
+ const luminance = colorLuma(resolved);
2473
+ return luminance !== undefined && luminance > 0.5;
2474
+ } catch {
2475
+ return false;
2476
+ }
2477
+ }
2478
+
2479
+ /**
2480
+ * Get explicit export colors from theme JSON, if specified.
2481
+ * Returns undefined for each color that isn't explicitly set.
2482
+ */
2483
+ export async function getThemeExportColors(themeName?: string): Promise<{
2484
+ pageBg?: string;
2485
+ cardBg?: string;
2486
+ infoBg?: string;
2487
+ }> {
2488
+ const name = themeName ?? getDefaultTheme();
2489
+ try {
2490
+ const themeJson = await loadThemeJson(name);
2491
+ const exportSection = themeJson.export;
2492
+ if (!exportSection) return {};
2493
+
2494
+ const vars = themeJson.vars ?? {};
2495
+ const resolve = (value: string | number | undefined): string | undefined => {
2496
+ if (value === undefined) return undefined;
2497
+ if (typeof value === "number") return ansi256ToHex(value);
2498
+ if (value === "" || value.startsWith("#")) return value;
2499
+ const varName = value.startsWith("$") ? value.slice(1) : value;
2500
+ if (varName in vars) {
2501
+ const resolved = resolveVarRefs(varName, vars);
2502
+ return typeof resolved === "number" ? ansi256ToHex(resolved) : resolved;
2503
+ }
2504
+ return value;
2505
+ };
2506
+
2507
+ return {
2508
+ pageBg: resolve(exportSection.pageBg),
2509
+ cardBg: resolve(exportSection.cardBg),
2510
+ infoBg: resolve(exportSection.infoBg),
2511
+ };
2512
+ } catch {
2513
+ return {};
2514
+ }
2515
+ }
2516
+
2517
+ // ============================================================================
2518
+ // TUI Helpers
2519
+ // ============================================================================
2520
+
2521
+ let cachedHighlightColorsFor: Theme | undefined;
2522
+ let cachedHighlightColors: NativeHighlightColors | undefined;
2523
+
2524
+ function getHighlightColors(t: Theme): NativeHighlightColors {
2525
+ if (cachedHighlightColorsFor !== t || !cachedHighlightColors) {
2526
+ cachedHighlightColorsFor = t;
2527
+ cachedHighlightColors = {
2528
+ comment: t.getFgAnsi("syntaxComment"),
2529
+ keyword: t.getFgAnsi("syntaxKeyword"),
2530
+ function: t.getFgAnsi("syntaxFunction"),
2531
+ variable: t.getFgAnsi("syntaxVariable"),
2532
+ string: t.getFgAnsi("syntaxString"),
2533
+ number: t.getFgAnsi("syntaxNumber"),
2534
+ type: t.getFgAnsi("syntaxType"),
2535
+ operator: t.getFgAnsi("syntaxOperator"),
2536
+ punctuation: t.getFgAnsi("syntaxPunctuation"),
2537
+ inserted: t.getFgAnsi("toolDiffAdded"),
2538
+ deleted: t.getFgAnsi("toolDiffRemoved"),
2539
+ };
2540
+ }
2541
+ return cachedHighlightColors;
2542
+ }
2543
+
2544
+ /**
2545
+ * Memoized native syntax highlight. Returns the joined ANSI string, or `null`
2546
+ * when the native tokenizer throws so callers can apply their own fallback.
2547
+ *
2548
+ * Keyed on `(lang, code)` and reset whenever the active `theme` instance
2549
+ * changes — the ANSI colors are baked into the highlighted output, so a theme
2550
+ * switch (which always reassigns `theme`) must invalidate every entry.
2551
+ *
2552
+ * Why this exists: animated tool blocks (eval/bash) repaint their box on every
2553
+ * ~33ms border-shimmer frame, and markdown re-lexes on every streamed delta.
2554
+ * Without memoization each frame can re-tokenize an unchanged code body through
2555
+ * the Rust FFI — ~26ms for 100 lines, ~40ms for 150 — consuming or overrunning
2556
+ * the 33ms frame budget and starving the spinner/render timers (the "TUI freeze").
2557
+ */
2558
+ const HIGHLIGHT_CACHE_MAX = 256;
2559
+ const highlightCache = new LRUCache<string, string>({ max: HIGHLIGHT_CACHE_MAX });
2560
+ let highlightCacheTheme: Theme | undefined;
2561
+
2562
+ function highlightCached(code: string, validLang: string | undefined): string | null {
2563
+ if (highlightCacheTheme !== theme) {
2564
+ highlightCache.clear();
2565
+ highlightCacheTheme = theme;
2566
+ }
2567
+ const key = `${validLang ?? ""}\x00${code}`;
2568
+ const hit = highlightCache.get(key);
2569
+ if (hit !== undefined) {
2570
+ return hit;
2571
+ }
2572
+ let highlighted: string;
2573
+ try {
2574
+ highlighted = nativeHighlightCode(code, validLang, getHighlightColors(theme));
2575
+ } catch {
2576
+ return null;
2577
+ }
2578
+ highlightCache.set(key, highlighted);
2579
+ return highlighted;
2580
+ }
2581
+
2582
+ /**
2583
+ * Highlight code with syntax coloring based on file extension or language.
2584
+ * Returns array of highlighted lines.
2585
+ */
2586
+ export function highlightCode(code: string, lang?: string): string[] {
2587
+ const validLang = lang && nativeSupportsLanguage(lang) ? lang : undefined;
2588
+ const highlighted = highlightCached(code, validLang);
2589
+ // Always return a fresh array: callers (e.g. renderCodeCell) push extra lines
2590
+ // onto the result, which would corrupt the cached string otherwise.
2591
+ return (highlighted ?? code).split("\n");
2592
+ }
2593
+
2594
+ export function getSymbolTheme(): SymbolTheme {
2595
+ const preset = theme.getSymbolPreset();
2596
+
2597
+ return {
2598
+ cursor: theme.nav.cursor,
2599
+ inputCursor: preset === "ascii" ? "|" : "▏",
2600
+ boxRound: theme.boxRound,
2601
+ boxSharp: theme.boxSharp,
2602
+ table: theme.boxSharp,
2603
+ quoteBorder: theme.md.quoteBorder,
2604
+ hrChar: theme.md.hrChar,
2605
+ colorSwatch: theme.md.colorSwatch,
2606
+ spinnerFrames: theme.getSpinnerFrames("activity"),
2607
+ };
2608
+ }
2609
+
2610
+ let cachedMarkdownTheme: MarkdownTheme | undefined;
2611
+ let cachedMarkdownThemeRef: Theme | undefined;
2612
+
2613
+ export function getMarkdownTheme(): MarkdownTheme {
2614
+ if (cachedMarkdownTheme !== undefined && cachedMarkdownThemeRef === theme) {
2615
+ return cachedMarkdownTheme;
2616
+ }
2617
+ const markdownTheme: MarkdownTheme = {
2618
+ heading: (text: string) => theme.fg("mdHeading", text),
2619
+ link: (text: string) => theme.fg("mdLink", text),
2620
+ linkUrl: (text: string) => theme.fg("mdLinkUrl", text),
2621
+ code: (text: string) => theme.fg("mdCode", text),
2622
+ codeBlock: (text: string) => theme.fg("mdCodeBlock", text),
2623
+ codeBlockBorder: (text: string) => theme.fg("mdCodeBlockBorder", text),
2624
+ quote: (text: string) => theme.fg("mdQuote", text),
2625
+ quoteBorder: (text: string) => theme.fg("mdQuoteBorder", text),
2626
+ hr: (text: string) => theme.fg("mdHr", text),
2627
+ listBullet: (text: string) => theme.fg("mdListBullet", text),
2628
+ bold: (text: string) => theme.bold(text),
2629
+ italic: (text: string) => theme.italic(text),
2630
+ underline: (text: string) => theme.underline(text),
2631
+ strikethrough: (text: string) => chalk.strikethrough(text),
2632
+ symbols: getSymbolTheme(),
2633
+ resolveMermaidAscii,
2634
+ highlightCode: (code: string, lang?: string): string[] => {
2635
+ const validLang = lang && nativeSupportsLanguage(lang) ? lang : undefined;
2636
+ const highlighted = highlightCached(code, validLang);
2637
+ if (highlighted !== null) return highlighted.split("\n");
2638
+ return code.split("\n").map(line => theme.fg("mdCodeBlock", line));
2639
+ },
2640
+ };
2641
+ cachedMarkdownTheme = markdownTheme;
2642
+ cachedMarkdownThemeRef = theme;
2643
+ return markdownTheme;
2644
+ }
2645
+
2646
+ export function getSelectListTheme(): SelectListTheme {
2647
+ return {
2648
+ selectedPrefix: (text: string) => theme.fg("accent", text),
2649
+ selectedText: (text: string) => theme.fg("accent", text),
2650
+ description: (text: string) => theme.fg("muted", text),
2651
+ scrollInfo: (text: string) => theme.fg("muted", text),
2652
+ noMatch: (text: string) => theme.fg("muted", text),
2653
+ symbols: getSymbolTheme(),
2654
+ };
2655
+ }
2656
+
2657
+ export function getEditorTheme(): EditorTheme {
2658
+ return {
2659
+ borderColor: (text: string) => theme.fg("borderMuted", text),
2660
+ selectList: getSelectListTheme(),
2661
+ symbols: getSymbolTheme(),
2662
+ hintStyle: (text: string) => theme.fg("dim", text),
2663
+ };
2664
+ }
2665
+
2666
+ export function getSettingsListTheme(): import('./stubs/tui/index.ts').SettingsListTheme {
2667
+ return {
2668
+ label: (text: string, selected: boolean, changed: boolean) =>
2669
+ changed ? theme.fg("statusLineGitDirty", text) : selected ? theme.fg("accent", text) : text,
2670
+ value: (text: string, selected: boolean, changed: boolean) =>
2671
+ selected ? theme.fg("accent", text) : changed ? theme.fg("statusLineGitDirty", text) : theme.fg("muted", text),
2672
+ description: (text: string) => theme.fg("dim", text),
2673
+ cursor: theme.fg("accent", `${theme.nav.cursor} `),
2674
+ hint: (text: string) => theme.fg("dim", text),
2675
+ };
2676
+ }