carthagent 0.0.0-stage → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (379) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -2
  3. package/bin/ctg.mjs +736 -0
  4. package/docs/budgets.md +72 -0
  5. package/docs/compaction.md +34 -0
  6. package/docs/context-efficiency-plan.md +24 -0
  7. package/docs/context-efficiency-review.md +27 -0
  8. package/docs/context-efficiency.md +49 -0
  9. package/docs/deepseek-jev-benchmark-plan.md +70 -0
  10. package/docs/deepseek-jev-benchmark-repair-plan.md +20 -0
  11. package/docs/deepseek-jev-benchmark-restart.md +9 -0
  12. package/docs/deepseek-jev-benchmark-results.md +77 -0
  13. package/docs/deepseek-jev-benchmark-running.md +60 -0
  14. package/docs/deepseek-jev-benchmark-v3-results.md +41 -0
  15. package/docs/deepseek-jev-benchmark-v4-protocol.md +15 -0
  16. package/docs/deepseek-jev-benchmark-v4-results.md +119 -0
  17. package/docs/deepseek-jev-http400-diagnosis.md +45 -0
  18. package/docs/delivery-review-evidence.md +53 -0
  19. package/docs/delivery-timeout-repair-plan.md +51 -0
  20. package/docs/evaluation-readiness.md +31 -0
  21. package/docs/evaluation.md +70 -0
  22. package/docs/extending.md +354 -0
  23. package/docs/glm-pilot-execution.md +9 -0
  24. package/docs/glm-pilot-plan.md +15 -0
  25. package/docs/glm-pilot-results.md +71 -0
  26. package/docs/graph-context-optimization.md +15 -0
  27. package/docs/jev-repository-pilot-plan.md +25 -0
  28. package/docs/jev-repository-pilot-protocol.md +39 -0
  29. package/docs/jev-repository-pilot-restart.md +7 -0
  30. package/docs/jev-repository-pilot-results.md +79 -0
  31. package/docs/jev.md +32 -0
  32. package/docs/model-registry.md +25 -0
  33. package/docs/native-compatibility.md +117 -0
  34. package/docs/opencode-archive.md +9 -0
  35. package/docs/opencode-migration.md +115 -0
  36. package/docs/opencode-runtime.md +94 -0
  37. package/docs/opencode-workspace.md +31 -0
  38. package/docs/owned-runtime-workflow-registration.md +17 -0
  39. package/docs/plan-advisor-evaluation.md +38 -0
  40. package/docs/planning-startup-fix-plan.md +23 -0
  41. package/docs/planning-startup-fix-review.md +24 -0
  42. package/docs/planning.md +118 -0
  43. package/docs/production-merge-review.md +23 -0
  44. package/docs/quality.md +35 -0
  45. package/docs/repository-benchmark-design.md +111 -0
  46. package/docs/review-assurance.md +9 -0
  47. package/docs/review-experiment-results.md +59 -0
  48. package/docs/tested-planning-roadmap.md +58 -0
  49. package/docs/tested-planning.md +58 -0
  50. package/docs/tui-pickers.md +9 -0
  51. package/docs/webdriver.md +83 -0
  52. package/docs/workflow-modes.md +26 -0
  53. package/docs/workflow.d2 +17 -0
  54. package/docs/workflow.svg +149 -0
  55. package/docs/workspace-coordination.md +9 -0
  56. package/evaluate.mjs +249 -0
  57. package/extensions/codegraph.ts +36 -0
  58. package/extensions/delivery.ts +819 -0
  59. package/extensions/experiential.ts +21 -0
  60. package/extensions/subscriptions.ts +21 -0
  61. package/guidance/profiles/authenticated-web.json +24 -0
  62. package/guidance/profiles/data-visualization.json +25 -0
  63. package/guidance/profiles/database-change.json +24 -0
  64. package/guidance/profiles/external-api.json +24 -0
  65. package/guidance/profiles/transactional-data.json +25 -0
  66. package/guidance/profiles/web-application.json +26 -0
  67. package/lib/acceptance-review.mjs +4 -0
  68. package/lib/browser-bin.mjs +160 -0
  69. package/lib/browser-errors.mjs +54 -0
  70. package/lib/browser.mjs +219 -0
  71. package/lib/budget.mjs +37 -0
  72. package/lib/cdp.mjs +221 -0
  73. package/lib/cloud/client.mjs +275 -0
  74. package/lib/cloud/control-plane.mjs +350 -0
  75. package/lib/cloud/gateway.mjs +380 -0
  76. package/lib/cloud/http.mjs +135 -0
  77. package/lib/cloud/ledger.mjs +215 -0
  78. package/lib/codegraph-query.mjs +60 -0
  79. package/lib/codegraph.mjs +378 -0
  80. package/lib/context-archive.mjs +18 -0
  81. package/lib/delivery-context.mjs +132 -0
  82. package/lib/delivery-guidance.mjs +9 -0
  83. package/lib/delivery-review.mjs +94 -0
  84. package/lib/delivery.mjs +610 -0
  85. package/lib/engine.mjs +137 -0
  86. package/lib/guidance.mjs +71 -0
  87. package/lib/jev-advisor.mjs +47 -0
  88. package/lib/opencode/archive.mjs +122 -0
  89. package/lib/opencode/compatibility.mjs +19 -0
  90. package/lib/opencode/credentials.mjs +205 -0
  91. package/lib/opencode/evaluation-budget-plugin/index.ts +147 -0
  92. package/lib/opencode/evaluation.mjs +242 -0
  93. package/lib/opencode/file-lock.mjs +86 -0
  94. package/lib/opencode/headless.mjs +200 -0
  95. package/lib/opencode/review.mjs +213 -0
  96. package/lib/opencode/runtime.mjs +246 -0
  97. package/lib/opencode/service.mjs +249 -0
  98. package/lib/opencode/session-options.mjs +60 -0
  99. package/lib/opencode/workspace.mjs +133 -0
  100. package/lib/openrouter-jev.mjs +37 -0
  101. package/lib/outcome-contract.mjs +21 -0
  102. package/lib/plan-advisor.mjs +38 -0
  103. package/lib/planning-access.mjs +7 -0
  104. package/lib/planning-advice.mjs +28 -0
  105. package/lib/planning-discovery.mjs +14 -0
  106. package/lib/planning-guide.mjs +34 -0
  107. package/lib/planning-view.mjs +57 -0
  108. package/lib/planning.mjs +155 -0
  109. package/lib/probe-diagnostics.mjs +13 -0
  110. package/lib/providers/experiential.mjs +292 -0
  111. package/lib/providers/model-catalog.json +700 -0
  112. package/lib/providers/model-catalog.mjs +7 -0
  113. package/lib/providers/names.mjs +13 -0
  114. package/lib/providers/subscription-models.mjs +483 -0
  115. package/lib/reports.mjs +80 -0
  116. package/lib/review-state.mjs +49 -0
  117. package/lib/review.mjs +114 -0
  118. package/lib/scenarios.mjs +99 -0
  119. package/lib/ship-auth.mjs +44 -0
  120. package/lib/ship-jev.mjs +59 -0
  121. package/lib/ship-telemetry.mjs +183 -0
  122. package/lib/tui/ansi.mjs +255 -0
  123. package/lib/tui/app.mjs +2445 -0
  124. package/lib/tui/auth.mjs +249 -0
  125. package/lib/tui/carthage.mjs +109 -0
  126. package/lib/tui/clipboard.mjs +122 -0
  127. package/lib/tui/d2.mjs +431 -0
  128. package/lib/tui/feed.mjs +467 -0
  129. package/lib/tui/framing.mjs +80 -0
  130. package/lib/tui/glyphs.mjs +172 -0
  131. package/lib/tui/hash-worker.mjs +11 -0
  132. package/lib/tui/mock-engine.mjs +222 -0
  133. package/lib/tui/models.mjs +73 -0
  134. package/lib/tui/picker.mjs +18 -0
  135. package/lib/tui/theme.mjs +663 -0
  136. package/lib/tui/title.mjs +7 -0
  137. package/lib/update-channel.mjs +62 -0
  138. package/lib/update.mjs +230 -0
  139. package/lib/webdriver.mjs +82 -0
  140. package/lib/workflow.mjs +88 -0
  141. package/lib/workspace.mjs +39 -0
  142. package/metadata.json +8 -0
  143. package/package.json +94 -4
  144. package/plugins/carthagent/index.ts +3 -0
  145. package/plugins/carthagent/package.json +28 -0
  146. package/plugins/carthagent/src/archive-rpc.ts +46 -0
  147. package/plugins/carthagent/src/bootstrap.ts +38 -0
  148. package/plugins/carthagent/src/index.ts +62 -0
  149. package/plugins/carthagent/src/pull-request-rpc.ts +54 -0
  150. package/plugins/carthagent/src/rpc.ts +76 -0
  151. package/plugins/carthagent/src/server/archive-rpc.ts +327 -0
  152. package/plugins/carthagent/src/server/budgets.ts +21 -0
  153. package/plugins/carthagent/src/server/codegraph.ts +46 -0
  154. package/plugins/carthagent/src/server/delivery.ts +488 -0
  155. package/plugins/carthagent/src/server/device-auth.ts +91 -0
  156. package/plugins/carthagent/src/server/native-delivery.ts +26 -0
  157. package/plugins/carthagent/src/server/orchestration.ts +56 -0
  158. package/plugins/carthagent/src/server/policy.ts +24 -0
  159. package/plugins/carthagent/src/server/providers.ts +424 -0
  160. package/plugins/carthagent/src/server/pull-request-rpc.ts +387 -0
  161. package/plugins/carthagent/src/server/session-controls.ts +82 -0
  162. package/plugins/carthagent/src/server/telemetry.ts +92 -0
  163. package/plugins/carthagent/src/server/workspace-rpc.ts +349 -0
  164. package/plugins/carthagent/src/session-rpc.ts +31 -0
  165. package/plugins/carthagent/src/testing.ts +85 -0
  166. package/plugins/carthagent/src/workspace-rpc.ts +133 -0
  167. package/plugins/carthagent/test-plugin/index.ts +4 -0
  168. package/plugins/carthagent/test-plugin/package.json +1 -0
  169. package/plugins/carthagent/tsconfig.json +19 -0
  170. package/plugins/carthagent/tui.ts +1 -0
  171. package/prompts/delivery.md +7 -0
  172. package/public/index.html +983 -0
  173. package/scenarios/cli/grade_cli.py +69 -0
  174. package/scenarios/cli/scenario.json +21 -0
  175. package/scenarios/game/baseline/minecraft.py +193 -0
  176. package/scenarios/game/context.md +1 -0
  177. package/scenarios/game/grade_minecraft_clone.py +603 -0
  178. package/scenarios/game/requirements.txt +2 -0
  179. package/scenarios/game/scenario.json +33 -0
  180. package/server.mjs +341 -0
  181. package/skills/game-development/SKILL.md +36 -0
  182. package/skills/game-development/assets/ursina_starter.py +98 -0
  183. package/skills/game-development/scripts/verify_ursina.py +80 -0
  184. package/skills/software-delivery/SKILL.md +50 -0
  185. package/skills/typescript-delivery/SKILL.md +69 -0
  186. package/tests/acceptance-review.test.mjs +13 -0
  187. package/tests/auth.test.mjs +234 -0
  188. package/tests/bounded-summary.test.mjs +68 -0
  189. package/tests/browser-bin.test.mjs +91 -0
  190. package/tests/browser.test.mjs +96 -0
  191. package/tests/budget-engine.test.mjs +110 -0
  192. package/tests/budget.test.mjs +23 -0
  193. package/tests/cli.test.mjs +245 -0
  194. package/tests/clipboard.test.mjs +79 -0
  195. package/tests/cloud-client.test.mjs +129 -0
  196. package/tests/cloud-control-plane.test.mjs +144 -0
  197. package/tests/cloud-gateway.test.mjs +147 -0
  198. package/tests/cloud-http.test.mjs +102 -0
  199. package/tests/cloud-ledger.test.mjs +75 -0
  200. package/tests/codegraph-query.test.mjs +66 -0
  201. package/tests/codegraph.test.mjs +142 -0
  202. package/tests/delivery-context.test.mjs +66 -0
  203. package/tests/delivery-review.test.mjs +139 -0
  204. package/tests/delivery.test.mjs +343 -0
  205. package/tests/engine-api.mjs +24 -0
  206. package/tests/experiential-extension.test.mjs +37 -0
  207. package/tests/experiential.test.mjs +300 -0
  208. package/tests/extension.test.mjs +921 -0
  209. package/tests/fixtures/archive-plugin/index.ts +10 -0
  210. package/tests/guidance.test.mjs +78 -0
  211. package/tests/model-registry.test.mjs +68 -0
  212. package/tests/models.test.mjs +70 -0
  213. package/tests/openai-idempotency.test.mjs +99 -0
  214. package/tests/opencode-archive-rpc.test.mjs +82 -0
  215. package/tests/opencode-delivery.test.mjs +231 -0
  216. package/tests/opencode-providers.test.mjs +414 -0
  217. package/tests/opencode-runtime.test.mjs +455 -0
  218. package/tests/opencode-session-controls.test.mjs +115 -0
  219. package/tests/opencode-session-options.test.mjs +26 -0
  220. package/tests/opencode-workspace.test.mjs +339 -0
  221. package/tests/outcome-contract.test.mjs +17 -0
  222. package/tests/picker.test.mjs +34 -0
  223. package/tests/plan-advisor.test.mjs +88 -0
  224. package/tests/plan-review-loop.test.mjs +53 -0
  225. package/tests/planning-advice.test.mjs +27 -0
  226. package/tests/planning-contract.test.mjs +65 -0
  227. package/tests/planning-startup.test.mjs +38 -0
  228. package/tests/planning-view.test.mjs +33 -0
  229. package/tests/planning.test.mjs +223 -0
  230. package/tests/probe-diagnostics.test.mjs +21 -0
  231. package/tests/pull-request-rpc.test.mjs +366 -0
  232. package/tests/review-state.test.mjs +32 -0
  233. package/tests/review.test.mjs +127 -0
  234. package/tests/server.test.mjs +252 -0
  235. package/tests/ship-jev.test.mjs +77 -0
  236. package/tests/ship-telemetry.test.mjs +333 -0
  237. package/tests/standard-workflow.test.mjs +28 -0
  238. package/tests/subscription-models.test.mjs +416 -0
  239. package/tests/subscriptions-extension.test.mjs +27 -0
  240. package/tests/terminal-title.test.mjs +13 -0
  241. package/tests/test_grade_minecraft_clone.py +199 -0
  242. package/tests/test_starter.py +78 -0
  243. package/tests/theme.test.mjs +175 -0
  244. package/tests/tui-copy-paste.test.mjs +54 -0
  245. package/tests/tui.test.mjs +808 -0
  246. package/tests/update-channels.test.mjs +129 -0
  247. package/tests/update.test.mjs +175 -0
  248. package/tests/webdriver.test.mjs +31 -0
  249. package/tests/workflow.test.mjs +47 -0
  250. package/tests/workspace-rpc.test.mjs +236 -0
  251. package/tests/workspace.test.mjs +24 -0
  252. package/tools/benchmark/advisor.test.mjs +7 -0
  253. package/tools/benchmark/advisor.ts +27 -0
  254. package/tools/benchmark/campaign.mjs +45 -0
  255. package/tools/benchmark/diagnose-request.mjs +40 -0
  256. package/tools/benchmark/eval-common.mjs +32 -0
  257. package/tools/benchmark/eval-ledger.mjs +22 -0
  258. package/tools/benchmark/eval-shop.mjs +26 -0
  259. package/tools/benchmark/eval-voxel.mjs +20 -0
  260. package/tools/benchmark/evaluate.mjs +24 -0
  261. package/tools/benchmark/evaluators.test.mjs +13 -0
  262. package/tools/benchmark/fixtures/shop/server.mjs +18 -0
  263. package/tools/benchmark/fixtures/shop/ui.html +8 -0
  264. package/tools/benchmark/freeze.mjs +30 -0
  265. package/tools/benchmark/gateway.mjs +91 -0
  266. package/tools/benchmark/gateway.test.mjs +38 -0
  267. package/tools/benchmark/generator.mjs +11 -0
  268. package/tools/benchmark/generator.test.mjs +26 -0
  269. package/tools/benchmark/guard.test.mjs +133 -0
  270. package/tools/benchmark/guard.ts +136 -0
  271. package/tools/benchmark/native-plugin/index.ts +24 -0
  272. package/tools/benchmark/planning-startup.test.mjs +47 -0
  273. package/tools/benchmark/preflight-live.mjs +31 -0
  274. package/tools/benchmark/preflight.mjs +22 -0
  275. package/tools/benchmark/replay-diagnostic.mjs +23 -0
  276. package/tools/benchmark/runner.mjs +141 -0
  277. package/tools/benchmark/runner.test.mjs +93 -0
  278. package/tools/benchmark/runtime.mjs +23 -0
  279. package/tools/benchmark/selftest.mjs +47 -0
  280. package/tools/benchmark/smoke-jev.mjs +5 -0
  281. package/tools/benchmark/tasks.mjs +20 -0
  282. package/tools/benchmark/transport.mjs +65 -0
  283. package/tools/benchmark/transport.test.mjs +44 -0
  284. package/tools/benchmark/upstream-error.mjs +18 -0
  285. package/tools/benchmark/upstream-error.test.mjs +10 -0
  286. package/tools/browser-check.mjs +109 -0
  287. package/tools/check-syntax.mjs +27 -0
  288. package/tools/evaluate-plan-advisor.mjs +20 -0
  289. package/tools/native-fixture.mjs +194 -0
  290. package/tools/native-pty-smoke.py +108 -0
  291. package/tools/native-report-plugin/index.ts +50 -0
  292. package/tools/native-report-plugin/package.json +7 -0
  293. package/tools/patch-compaction.mjs +24 -0
  294. package/tools/patch-model-catalog.mjs +12 -0
  295. package/tools/patch-print-shutdown.mjs +39 -0
  296. package/tools/repo-pilot/evaluator.cjs +32 -0
  297. package/tools/repo-pilot/reference.mjs +43 -0
  298. package/tools/repo-pilot/runner.mjs +85 -0
  299. package/tools/repo-pilot/sandbox-entry.mjs +12 -0
  300. package/tools/repo-pilot/tasks.mjs +20 -0
  301. package/tools/repo-pilot/type-evaluator.cjs +6 -0
  302. package/tools/test-native-controls.mjs +84 -0
  303. package/tools/test-native-delivery-host.mjs +307 -0
  304. package/tools/test-native-evaluation.mjs +46 -0
  305. package/tools/test-native-host.mjs +385 -0
  306. package/tools/test-native-outcomes.mjs +73 -0
  307. package/tools/test-native-package.mjs +70 -0
  308. package/tools/test-native-pty.mjs +20 -0
  309. package/tools/test-native-report.mjs +88 -0
  310. package/tools/test-native-swe-host.mjs +132 -0
  311. package/tools/test-native-swe.mjs +122 -0
  312. package/tools/test-picker-pty.py +45 -0
  313. package/tools/test-python.mjs +29 -0
  314. package/tools/test-webdriver.mjs +54 -0
  315. package/tools/verify-release-version.mjs +37 -0
  316. package/tools/webdriver-check.mjs +52 -0
  317. package/vendor/agent/bounded-summary.mjs +88 -0
  318. package/vendor/agent/chunks/anthropic-messages-VWZZOSJQ.js +6 -0
  319. package/vendor/agent/chunks/anthropic.js +75 -0
  320. package/vendor/agent/chunks/azure-openai-responses-BJLAM6CD.js +2 -0
  321. package/vendor/agent/chunks/bedrock-converse-stream.js +74 -0
  322. package/vendor/agent/chunks/chord-context.js +96 -0
  323. package/vendor/agent/chunks/chunk-4L3WN2XY.js +2 -0
  324. package/vendor/agent/chunks/chunk-6CYCI3EJ.js +12 -0
  325. package/vendor/agent/chunks/chunk-6R7UI4IY.js +2 -0
  326. package/vendor/agent/chunks/chunk-7ZC4UXSL.js +2 -0
  327. package/vendor/agent/chunks/chunk-AXIIZGTV.js +2 -0
  328. package/vendor/agent/chunks/chunk-CLNPYIDP.js +42 -0
  329. package/vendor/agent/chunks/chunk-DRQDKNXA.js +2 -0
  330. package/vendor/agent/chunks/chunk-GMWCTUPB.js +2 -0
  331. package/vendor/agent/chunks/chunk-IDDQWTHI.js +2 -0
  332. package/vendor/agent/chunks/chunk-JVUZSMYM.js +1548 -0
  333. package/vendor/agent/chunks/chunk-L2ZPNLYD.js +2 -0
  334. package/vendor/agent/chunks/chunk-NUHFSC37.js +25 -0
  335. package/vendor/agent/chunks/chunk-OUXLLA64.js +11 -0
  336. package/vendor/agent/chunks/chunk-PGXDEOVV.js +2 -0
  337. package/vendor/agent/chunks/chunk-PJACZCIR.js +2 -0
  338. package/vendor/agent/chunks/chunk-PRRNXB7S.js +2 -0
  339. package/vendor/agent/chunks/chunk-TEPMHNKQ.js +2 -0
  340. package/vendor/agent/chunks/chunk-TRDNDS6A.js +4 -0
  341. package/vendor/agent/chunks/chunk-U6ZMQKGD.js +50 -0
  342. package/vendor/agent/chunks/chunk-UAQELI3K.js +2 -0
  343. package/vendor/agent/chunks/chunk-USJZMAIR.js +2 -0
  344. package/vendor/agent/chunks/chunk-XDUWOHPL.js +6 -0
  345. package/vendor/agent/chunks/chunk-XNGRGP62.js +2 -0
  346. package/vendor/agent/chunks/github-copilot.js +2 -0
  347. package/vendor/agent/chunks/google-generative-ai-Q2K7FBDI.js +2 -0
  348. package/vendor/agent/chunks/google-vertex-7UJBF4S7.js +2 -0
  349. package/vendor/agent/chunks/https-proxy-agent-2VXB7436.js +13 -0
  350. package/vendor/agent/chunks/image-resize-worker.js +2 -0
  351. package/vendor/agent/chunks/kimi-coding.js +2 -0
  352. package/vendor/agent/chunks/lib-HGQMNYVT.js +9 -0
  353. package/vendor/agent/chunks/mistral-conversations-4M6BZBX6.js +5 -0
  354. package/vendor/agent/chunks/multipart-parser-SQ6GDJL7.js +3 -0
  355. package/vendor/agent/chunks/node-KG362ECQ.js +16 -0
  356. package/vendor/agent/chunks/node-TWVVAGPO.js +2 -0
  357. package/vendor/agent/chunks/openai-codex-responses-R6VYZTVY.js +10 -0
  358. package/vendor/agent/chunks/openai-codex.js +75 -0
  359. package/vendor/agent/chunks/openai-completions-EKZT2IH2.js +7 -0
  360. package/vendor/agent/chunks/openai-responses-TFDINO6W.js +2 -0
  361. package/vendor/agent/chunks/openrouter-images-N4XVVFSD.js +2 -0
  362. package/vendor/agent/chunks/openrouter.js +75 -0
  363. package/vendor/agent/chunks/pi-messages-PML4SPVJ.js +8 -0
  364. package/vendor/agent/chunks/radius.js +75 -0
  365. package/vendor/agent/chunks/src-UK77SYZE.js +4 -0
  366. package/vendor/agent/chunks/xai.js +2 -0
  367. package/vendor/agent/cli.js +3 -0
  368. package/vendor/agent/dist/modes/interactive/theme/dark.json +91 -0
  369. package/vendor/agent/dist/modes/interactive/theme/light.json +90 -0
  370. package/vendor/agent/dist/modes/interactive/theme/theme-schema.json +356 -0
  371. package/vendor/agent/index.js +2 -0
  372. package/vendor/agent/modes/interactive/theme/dark.json +91 -0
  373. package/vendor/agent/modes/interactive/theme/light.json +90 -0
  374. package/vendor/agent/modes/interactive/theme/theme-schema.json +356 -0
  375. package/vendor/agent/package.json +14 -0
  376. package/vendor/agent/rpc-entry.js +3 -0
  377. package/vendor/agent/theme/dark.json +91 -0
  378. package/vendor/agent/theme/light.json +90 -0
  379. package/vendor/agent/theme/theme-schema.json +356 -0
@@ -0,0 +1,663 @@
1
+ /** carthagent theme palettes — opencode token set, Node-only, zero dependencies.
2
+ *
3
+ * Token model ripped from opencode's theme.json schema (extracted from the
4
+ * opencode 1.18.30 binary): primary/secondary/accent, error/warning/success/
5
+ * info, text/textMuted, background/backgroundPanel/backgroundElement,
6
+ * border/borderActive/borderSubtle, diff*, markdown*, syntax*.
7
+ *
8
+ * Resolution: { dark, light } objects pick by mode ('dark' default);
9
+ * plain hex strings and "none" (terminal default) pass through; bare names
10
+ * resolve against `defs`. Legacy carthagent keys (accent, muted, faint, ok, warn,
11
+ * err, info, grad, panelBg, userChip, borderHot, accent2, hot) are derived
12
+ * so existing render code keeps working during migration.
13
+ */
14
+ import { fg, bg, mix, gradient, paint, BOLD, DIM, ITALIC, UNDERLINE, RESET } from './ansi.mjs';
15
+
16
+ export const DEFAULT_MODE = 'dark';
17
+
18
+ /** Resolve one token value: hex, "none", def-name, or {dark,light}. */
19
+ export function resolveToken(value, defs, mode = DEFAULT_MODE) {
20
+ if (value == null) return null;
21
+ if (typeof value === 'object') {
22
+ const v = value[mode] ?? value.dark ?? value.light;
23
+ return resolveToken(v, defs, mode);
24
+ }
25
+ const s = String(value);
26
+ if (s === 'none') return 'none';
27
+ if (/^#[0-9a-fA-F]{3,8}$/.test(s)) return s.length === 4
28
+ ? '#' + [...s.slice(1)].map(c => c + c).join('')
29
+ : s.slice(0, 7);
30
+ if (/^\d{1,3}$/.test(s)) return s; // ansi 256 index passthrough
31
+ if (defs && defs[s] != null) return resolveToken(defs[s], defs, mode);
32
+ return s;
33
+ }
34
+
35
+ /** Flatten a raw {defs, theme} theme into plain hex tokens for a mode. */
36
+ export function flattenTheme(raw, mode = DEFAULT_MODE) {
37
+ const defs = raw.defs || {};
38
+ const flat = {};
39
+ for (const [k, v] of Object.entries(raw.theme || {})) {
40
+ flat[k] = resolveToken(v, defs, mode);
41
+ }
42
+ // Legacy carthagent aliases so existing render code keeps working.
43
+ flat.accent ??= flat.primary;
44
+ flat.accent2 ??= flat.secondary;
45
+ flat.hot ??= flat.accent;
46
+ flat.muted ??= flat.textMuted;
47
+ flat.faint ??= flat.textMuted;
48
+ flat.ok ??= flat.success;
49
+ flat.warn ??= flat.warning;
50
+ flat.err ??= flat.error;
51
+ flat.info ??= flat.info ?? flat.primary;
52
+ flat.borderHot ??= flat.borderActive;
53
+ flat.grad ??= [flat.primary, flat.accent, flat.secondary].filter(Boolean);
54
+ flat.panelBg ??= flat.backgroundPanel;
55
+ flat.userChip ??= flat.backgroundElement;
56
+ flat.label = raw.label || flat.label;
57
+ return flat;
58
+ }
59
+
60
+ const OPENCODE_DEFS = {
61
+ darkBg: '#0f0f0f',
62
+ darkBgPanel: '#15141b',
63
+ darkBorder: '#2d2d2d',
64
+ darkFgMuted: '#838383',
65
+ darkFg: '#edecee',
66
+ purple: '#a277ff',
67
+ pink: '#f694ff',
68
+ blue: '#82e2ff',
69
+ red: '#ff6767',
70
+ orange: '#ffca85',
71
+ cyan: '#61ffca',
72
+ green: '#9dff65',
73
+ };
74
+
75
+ const OPENCODE_THEME = {
76
+ primary: 'purple', secondary: 'pink', accent: 'purple',
77
+ error: 'red', warning: 'orange', success: 'cyan', info: 'purple',
78
+ text: 'darkFg', textMuted: 'darkFgMuted',
79
+ background: 'darkBg', backgroundPanel: 'darkBgPanel', backgroundElement: 'darkBgPanel',
80
+ border: 'darkBorder', borderActive: 'darkFgMuted', borderSubtle: 'darkBorder',
81
+ diffAdded: 'cyan', diffRemoved: 'red',
82
+ diffContext: 'darkFgMuted', diffHunkHeader: 'darkFgMuted',
83
+ diffHighlightAdded: 'cyan', diffHighlightRemoved: 'red',
84
+ diffAddedBg: '#354933', diffRemovedBg: '#3f191a', diffContextBg: 'darkBgPanel',
85
+ diffLineNumber: '#898989',
86
+ diffAddedLineNumberBg: '#162620', diffRemovedLineNumberBg: '#26161a',
87
+ markdownText: 'darkFg', markdownHeading: 'purple',
88
+ markdownLink: 'pink', markdownLinkText: 'purple', markdownCode: 'cyan',
89
+ markdownBlockQuote: 'darkFgMuted', markdownEmph: 'orange', markdownStrong: 'purple',
90
+ markdownHorizontalRule: 'darkFgMuted',
91
+ markdownListItem: 'purple', markdownListEnumeration: 'purple',
92
+ markdownImage: 'pink', markdownImageText: 'purple', markdownCodeBlock: 'darkFg',
93
+ syntaxComment: 'darkFgMuted', syntaxKeyword: 'pink', syntaxFunction: 'purple',
94
+ syntaxVariable: 'purple', syntaxString: 'cyan', syntaxNumber: 'green',
95
+ syntaxType: 'purple', syntaxOperator: 'pink', syntaxPunctuation: 'darkFg',
96
+ };
97
+
98
+ const TOKYONIGHT_DEFS = {
99
+ bg: '#1a1b26', bgAlt: '#16161e', bgPanel: '#1f2335', bgElement: '#292e42',
100
+ fg: '#c0caf5', fgMuted: '#9a9fb8', comment: '#9a9fb8',
101
+ blue: '#7aa2f7', purple: '#bb9af7', cyan: '#7dcfff', green: '#9ece6a',
102
+ yellow: '#e0af68', orange: '#ff9e64', red: '#f7768e', teal: '#73daca',
103
+ };
104
+
105
+ const TOKYONIGHT_THEME = {
106
+ primary: 'blue', secondary: 'purple', accent: 'cyan',
107
+ error: 'red', warning: 'yellow', success: 'green', info: 'blue',
108
+ text: 'fg', textMuted: 'fgMuted',
109
+ background: 'bg', backgroundPanel: 'bgPanel', backgroundElement: 'bgElement',
110
+ border: '#3b4261', borderActive: 'blue', borderSubtle: '#2e3350',
111
+ diffAdded: 'green', diffRemoved: 'red',
112
+ diffContext: 'comment', diffHunkHeader: 'cyan',
113
+ diffHighlightAdded: 'green', diffHighlightRemoved: 'red',
114
+ diffAddedBg: '#1e3a2a', diffRemovedBg: '#3a1e2a', diffContextBg: 'bgPanel',
115
+ diffLineNumber: 'fgMuted',
116
+ diffAddedLineNumberBg: '#1e3a2a', diffRemovedLineNumberBg: '#3a1e2a',
117
+ markdownText: 'fg', markdownHeading: 'purple',
118
+ markdownLink: 'blue', markdownLinkText: 'cyan', markdownCode: 'green',
119
+ markdownBlockQuote: 'comment', markdownEmph: 'yellow', markdownStrong: 'orange',
120
+ markdownHorizontalRule: 'comment',
121
+ markdownListItem: 'blue', markdownListEnumeration: 'cyan',
122
+ markdownImage: 'blue', markdownImageText: 'cyan', markdownCodeBlock: 'fg',
123
+ syntaxComment: 'comment', syntaxKeyword: 'purple', syntaxFunction: 'blue',
124
+ syntaxVariable: 'fg', syntaxString: 'green', syntaxNumber: 'orange',
125
+ syntaxType: 'cyan', syntaxOperator: 'purple', syntaxPunctuation: 'fg',
126
+ };
127
+
128
+ const RAW_THEMES = {
129
+ // Carthagent's default: Tyrian purple surfaces with high-contrast Punic gold.
130
+ carthage: {
131
+ label: 'Carthage',
132
+ defs: {},
133
+ theme: {
134
+ primary: '#f2c66d', secondary: '#c7a5ff', accent: '#f2c66d',
135
+ error: '#ff969e', warning: '#f2c66d', success: '#76d6aa', info: '#c7a5ff',
136
+ text: '#f7f1e5', textMuted: '#b8a9c9',
137
+ background: '#120d1c', backgroundPanel: '#1d1429', backgroundElement: '#2a1d3c',
138
+ border: '#49385d', borderActive: '#f2c66d', borderSubtle: '#372947',
139
+ diffAdded: '#76d6aa', diffRemoved: '#ff969e',
140
+ diffContext: '#b8a9c9', diffHunkHeader: '#c7a5ff',
141
+ diffHighlightAdded: '#76d6aa', diffHighlightRemoved: '#ff969e',
142
+ diffAddedBg: '#173328', diffRemovedBg: '#3a1c2a', diffContextBg: '#1d1429',
143
+ diffLineNumber: '#b8a9c9',
144
+ diffAddedLineNumberBg: '#173328', diffRemovedLineNumberBg: '#3a1c2a',
145
+ markdownText: '#f7f1e5', markdownHeading: '#f2c66d',
146
+ markdownLink: '#c7a5ff', markdownLinkText: '#ead9ff', markdownCode: '#76d6aa',
147
+ markdownBlockQuote: '#b8a9c9', markdownEmph: '#f2c66d', markdownStrong: '#ead9ff',
148
+ markdownHorizontalRule: '#8b76a3',
149
+ markdownListItem: '#f2c66d', markdownListEnumeration: '#c7a5ff',
150
+ markdownImage: '#c7a5ff', markdownImageText: '#ead9ff', markdownCodeBlock: '#f7f1e5',
151
+ syntaxComment: '#a99abb', syntaxKeyword: '#c7a5ff', syntaxFunction: '#f2c66d',
152
+ syntaxVariable: '#f7f1e5', syntaxString: '#76d6aa', syntaxNumber: '#f2c66d',
153
+ syntaxType: '#ead9ff', syntaxOperator: '#c7a5ff', syntaxPunctuation: '#f7f1e5',
154
+ },
155
+ },
156
+ opencode: { label: 'Opencode', defs: OPENCODE_DEFS, theme: OPENCODE_THEME },
157
+ tokyonight: { label: 'Tokyonight', defs: TOKYONIGHT_DEFS, theme: TOKYONIGHT_THEME },
158
+ // Legacy carthagent palettes, expressed in the opencode token set.
159
+ nebula: {
160
+ label: 'Nebula',
161
+ defs: {},
162
+ theme: {
163
+ primary: '#8b7bff', secondary: '#4dd0e1', accent: '#c792ea',
164
+ error: '#f16d75', warning: '#f0b35e', success: '#58d68d', info: '#6cb5f4',
165
+ text: '#d8dbe9', textMuted: '#969bb8',
166
+ background: '#0e1020', backgroundPanel: '#14152b', backgroundElement: '#2a2f55',
167
+ border: '#3d4266', borderActive: '#8b7bff', borderSubtle: '#2b2f4d',
168
+ diffAdded: '#58d68d', diffRemoved: '#f16d75',
169
+ diffContext: '#969bb8', diffHunkHeader: '#4dd0e1',
170
+ diffHighlightAdded: '#58d68d', diffHighlightRemoved: '#f16d75',
171
+ diffAddedBg: '#14281e', diffRemovedBg: '#2c1518', diffContextBg: '#14152b',
172
+ diffLineNumber: '#888ca4',
173
+ diffAddedLineNumberBg: '#14281e', diffRemovedLineNumberBg: '#2c1518',
174
+ markdownText: '#d8dbe9', markdownHeading: '#8b7bff',
175
+ markdownLink: '#4dd0e1', markdownLinkText: '#c792ea', markdownCode: '#58d68d',
176
+ markdownBlockQuote: '#969bb8', markdownEmph: '#f0b35e', markdownStrong: '#c792ea',
177
+ markdownHorizontalRule: '#888ca4',
178
+ markdownListItem: '#8b7bff', markdownListEnumeration: '#4dd0e1',
179
+ markdownImage: '#4dd0e1', markdownImageText: '#c792ea', markdownCodeBlock: '#d8dbe9',
180
+ syntaxComment: '#888ca4', syntaxKeyword: '#c792ea', syntaxFunction: '#8b7bff',
181
+ syntaxVariable: '#d8dbe9', syntaxString: '#58d68d', syntaxNumber: '#f0b35e',
182
+ syntaxType: '#4dd0e1', syntaxOperator: '#c792ea', syntaxPunctuation: '#969bb8',
183
+ },
184
+ },
185
+ ember: {
186
+ label: 'Ember',
187
+ defs: {},
188
+ theme: {
189
+ primary: '#ff9e64', secondary: '#ffc53d', accent: '#ff7a93',
190
+ error: '#f7768e', warning: '#e0af68', success: '#9ece6a', info: '#7aa2f7',
191
+ text: '#e8ddce', textMuted: '#ac9e89',
192
+ background: '#1a130d', backgroundPanel: '#231a13', backgroundElement: '#453322',
193
+ border: '#57493a', borderActive: '#ff9e64', borderSubtle: '#40352a',
194
+ diffAdded: '#9ece6a', diffRemoved: '#f7768e',
195
+ diffContext: '#ac9e89', diffHunkHeader: '#7aa2f7',
196
+ diffHighlightAdded: '#9ece6a', diffHighlightRemoved: '#f7768e',
197
+ diffAddedBg: '#222a14', diffRemovedBg: '#2c1418', diffContextBg: '#231a13',
198
+ diffLineNumber: '#978e81',
199
+ diffAddedLineNumberBg: '#222a14', diffRemovedLineNumberBg: '#2c1418',
200
+ markdownText: '#e8ddce', markdownHeading: '#ff9e64',
201
+ markdownLink: '#7aa2f7', markdownLinkText: '#ff7a93', markdownCode: '#9ece6a',
202
+ markdownBlockQuote: '#ac9e89', markdownEmph: '#e0af68', markdownStrong: '#ff7a93',
203
+ markdownHorizontalRule: '#978e81',
204
+ markdownListItem: '#ff9e64', markdownListEnumeration: '#ffc53d',
205
+ markdownImage: '#7aa2f7', markdownImageText: '#ff7a93', markdownCodeBlock: '#e8ddce',
206
+ syntaxComment: '#978e81', syntaxKeyword: '#ff7a93', syntaxFunction: '#ff9e64',
207
+ syntaxVariable: '#e8ddce', syntaxString: '#9ece6a', syntaxNumber: '#e0af68',
208
+ syntaxType: '#7aa2f7', syntaxOperator: '#ff7a93', syntaxPunctuation: '#ac9e89',
209
+ },
210
+ },
211
+ forest: {
212
+ label: 'Forest',
213
+ defs: {},
214
+ theme: {
215
+ primary: '#7ee081', secondary: '#4dd0a1', accent: '#d4e157',
216
+ error: '#ff6f60', warning: '#ffd54f', success: '#58d68d', info: '#64b5f6',
217
+ text: '#d8e8d8', textMuted: '#8fac99',
218
+ background: '#0b1510', backgroundPanel: '#0f1f16', backgroundElement: '#1f4030',
219
+ border: '#3a5546', borderActive: '#7ee081', borderSubtle: '#2a4034',
220
+ diffAdded: '#58d68d', diffRemoved: '#ff6f60',
221
+ diffContext: '#8fac99', diffHunkHeader: '#64b5f6',
222
+ diffHighlightAdded: '#58d68d', diffHighlightRemoved: '#ff6f60',
223
+ diffAddedBg: '#12241a', diffRemovedBg: '#2a1412', diffContextBg: '#0f1f16',
224
+ diffLineNumber: '#7b9085',
225
+ diffAddedLineNumberBg: '#12241a', diffRemovedLineNumberBg: '#2a1412',
226
+ markdownText: '#d8e8d8', markdownHeading: '#7ee081',
227
+ markdownLink: '#64b5f6', markdownLinkText: '#4dd0a1', markdownCode: '#58d68d',
228
+ markdownBlockQuote: '#8fac99', markdownEmph: '#ffd54f', markdownStrong: '#d4e157',
229
+ markdownHorizontalRule: '#7b9085',
230
+ markdownListItem: '#7ee081', markdownListEnumeration: '#4dd0a1',
231
+ markdownImage: '#64b5f6', markdownImageText: '#4dd0a1', markdownCodeBlock: '#d8e8d8',
232
+ syntaxComment: '#7b9085', syntaxKeyword: '#d4e157', syntaxFunction: '#7ee081',
233
+ syntaxVariable: '#d8e8d8', syntaxString: '#58d68d', syntaxNumber: '#ffd54f',
234
+ syntaxType: '#4dd0a1', syntaxOperator: '#d4e157', syntaxPunctuation: '#8fac99',
235
+ },
236
+ },
237
+ mono: {
238
+ label: 'Mono',
239
+ defs: {},
240
+ theme: {
241
+ primary: '#e0e0e0', secondary: '#a8a8a8', accent: '#ffffff',
242
+ error: '#f0a8a8', warning: '#f0e0a8', success: '#c8f0c8', info: '#b8d0f0',
243
+ text: '#d4d4d4', textMuted: '#9b9b9b',
244
+ background: '#101010', backgroundPanel: '#161616', backgroundElement: '#303030',
245
+ border: '#4a4a4a', borderActive: '#e0e0e0', borderSubtle: '#2c2c2c',
246
+ diffAdded: '#c8f0c8', diffRemoved: '#f0a8a8',
247
+ diffContext: '#9b9b9b', diffHunkHeader: '#9b9b9b',
248
+ diffHighlightAdded: '#c8f0c8', diffHighlightRemoved: '#f0a8a8',
249
+ diffAddedBg: '#1a2a1a', diffRemovedBg: '#2a1a1a', diffContextBg: '#161616',
250
+ diffLineNumber: '#949494',
251
+ diffAddedLineNumberBg: '#1a2a1a', diffRemovedLineNumberBg: '#2a1a1a',
252
+ markdownText: '#d4d4d4', markdownHeading: '#ffffff',
253
+ markdownLink: '#b8d0f0', markdownLinkText: '#a8a8a8', markdownCode: '#c8f0c8',
254
+ markdownBlockQuote: '#9b9b9b', markdownEmph: '#f0e0a8', markdownStrong: '#ffffff',
255
+ markdownHorizontalRule: '#949494',
256
+ markdownListItem: '#e0e0e0', markdownListEnumeration: '#a8a8a8',
257
+ markdownImage: '#b8d0f0', markdownImageText: '#a8a8a8', markdownCodeBlock: '#d4d4d4',
258
+ syntaxComment: '#949494', syntaxKeyword: '#e0e0e0', syntaxFunction: '#ffffff',
259
+ syntaxVariable: '#d4d4d4', syntaxString: '#c8f0c8', syntaxNumber: '#f0e0a8',
260
+ syntaxType: '#b8d0f0', syntaxOperator: '#e0e0e0', syntaxPunctuation: '#9b9b9b',
261
+ },
262
+ }, 'obsidian': {
263
+ label: 'Obsidian',
264
+ defs: {},
265
+ theme: {
266
+ primary: '#a78bff', secondary: '#d2a8ff',
267
+ accent: '#a78bff', error: '#ff7d7d',
268
+ warning: '#ffc078', success: '#5fd4a4',
269
+ info: '#d2a8ff', text: '#e8e8e8',
270
+ textMuted: '#9a9a9a', background: '#0f0f0f',
271
+ backgroundPanel: '#161616', backgroundElement: '#1d1d1d',
272
+ border: '#3d3d3d', borderActive: '#a78bff',
273
+ borderSubtle: '#2c2c2c', diffContext: '#808080',
274
+ diffHunkHeader: '#a78bff', diffContextBg: '#161616',
275
+ diffLineNumber: '#9a9a9a', markdownText: '#e8e8e8',
276
+ markdownHeading: '#a78bff', markdownLink: '#d2a8ff',
277
+ markdownLinkText: '#a78bff', markdownCode: '#5fd4a4',
278
+ markdownBlockQuote: '#9a9a9a', markdownEmph: '#ffc078',
279
+ markdownStrong: '#a78bff', markdownHorizontalRule: '#808080',
280
+ markdownListItem: '#a78bff', markdownListEnumeration: '#a78bff',
281
+ markdownImage: '#d2a8ff', markdownImageText: '#a78bff',
282
+ markdownCodeBlock: '#c9c9c9', syntaxComment: '#808080',
283
+ syntaxKeyword: '#d2a8ff', syntaxFunction: '#a78bff',
284
+ syntaxVariable: '#e8e8e8', syntaxString: '#5fd4a4',
285
+ syntaxNumber: '#ffc078', syntaxType: '#d2a8ff',
286
+ syntaxOperator: '#d2a8ff', syntaxPunctuation: '#e8e8e8',
287
+ diffAdded: '#5fd4a4', diffRemoved: '#ff7d7d',
288
+ diffHighlightAdded: '#5fd4a4', diffHighlightRemoved: '#ff7d7d',
289
+ diffAddedBg: '#1b2d25', diffRemovedBg: '#332020',
290
+ diffAddedLineNumberBg: '#151d19', diffRemovedLineNumberBg: '#201717',
291
+ },
292
+ },
293
+ 'midnight': {
294
+ label: 'Midnight',
295
+ defs: {},
296
+ theme: {
297
+ primary: '#58a6ff', secondary: '#d2a8ff',
298
+ accent: '#58a6ff', error: '#ff7b72',
299
+ warning: '#e3b341', success: '#56d364',
300
+ info: '#d2a8ff', text: '#e6edf3',
301
+ textMuted: '#9198a1', background: '#0d1117',
302
+ backgroundPanel: '#161b22', backgroundElement: '#21262d',
303
+ border: '#3d444d', borderActive: '#58a6ff',
304
+ borderSubtle: '#30363d', diffContext: '#7d8590',
305
+ diffHunkHeader: '#58a6ff', diffContextBg: '#161b22',
306
+ diffLineNumber: '#9198a1', markdownText: '#e6edf3',
307
+ markdownHeading: '#58a6ff', markdownLink: '#d2a8ff',
308
+ markdownLinkText: '#58a6ff', markdownCode: '#56d364',
309
+ markdownBlockQuote: '#9198a1', markdownEmph: '#e3b341',
310
+ markdownStrong: '#58a6ff', markdownHorizontalRule: '#7d8590',
311
+ markdownListItem: '#58a6ff', markdownListEnumeration: '#58a6ff',
312
+ markdownImage: '#d2a8ff', markdownImageText: '#58a6ff',
313
+ markdownCodeBlock: '#d1d7e0', syntaxComment: '#7d8590',
314
+ syntaxKeyword: '#d2a8ff', syntaxFunction: '#58a6ff',
315
+ syntaxVariable: '#e6edf3', syntaxString: '#56d364',
316
+ syntaxNumber: '#e3b341', syntaxType: '#d2a8ff',
317
+ syntaxOperator: '#d2a8ff', syntaxPunctuation: '#e6edf3',
318
+ diffAdded: '#56d364', diffRemoved: '#ff7b72',
319
+ diffHighlightAdded: '#56d364', diffHighlightRemoved: '#ff7b72',
320
+ diffAddedBg: '#182e23', diffRemovedBg: '#312125',
321
+ diffAddedLineNumberBg: '#121f1c', diffRemovedLineNumberBg: '#1e181d',
322
+ },
323
+ },
324
+ 'solarized-dark': {
325
+ label: 'Solarized Dark',
326
+ defs: {},
327
+ theme: {
328
+ primary: '#5eacdc', secondary: '#c98bd0',
329
+ accent: '#5eacdc', error: '#f0938a',
330
+ warning: '#d4a72c', success: '#a4b94e',
331
+ info: '#c98bd0', text: '#a2b2b2',
332
+ textMuted: '#9aa9ac', background: '#002b36',
333
+ backgroundPanel: '#073642', backgroundElement: '#0a4050',
334
+ border: '#1a5c6e', borderActive: '#5eacdc',
335
+ borderSubtle: '#0d4a5a', diffContext: '#8d9c9e',
336
+ diffHunkHeader: '#5eacdc', diffContextBg: '#073642',
337
+ diffLineNumber: '#9aa9ac', markdownText: '#a2b2b2',
338
+ markdownHeading: '#5eacdc', markdownLink: '#c98bd0',
339
+ markdownLinkText: '#5eacdc', markdownCode: '#a4b94e',
340
+ markdownBlockQuote: '#9aa9ac', markdownEmph: '#d4a72c',
341
+ markdownStrong: '#5eacdc', markdownHorizontalRule: '#8d9c9e',
342
+ markdownListItem: '#5eacdc', markdownListEnumeration: '#5eacdc',
343
+ markdownImage: '#c98bd0', markdownImageText: '#5eacdc',
344
+ markdownCodeBlock: '#a5b5b5', syntaxComment: '#8d9c9e',
345
+ syntaxKeyword: '#c98bd0', syntaxFunction: '#5eacdc',
346
+ syntaxVariable: '#a2b2b2', syntaxString: '#a4b94e',
347
+ syntaxNumber: '#d4a72c', syntaxType: '#c98bd0',
348
+ syntaxOperator: '#c98bd0', syntaxPunctuation: '#a2b2b2',
349
+ diffAdded: '#a4b94e', diffRemoved: '#f0938a',
350
+ diffHighlightAdded: '#a4b94e', diffHighlightRemoved: '#f0938a',
351
+ diffAddedBg: '#19403a', diffRemovedBg: '#243b43',
352
+ diffAddedLineNumberBg: '#0b3538', diffRemovedLineNumberBg: '#11323c',
353
+ },
354
+ },
355
+ 'nord': {
356
+ label: 'Nord',
357
+ defs: {},
358
+ theme: {
359
+ primary: '#8fc4d3', secondary: '#c2a6ce',
360
+ accent: '#8fc4d3', error: '#e6a8ad',
361
+ warning: '#ebcb8b', success: '#a3be8c',
362
+ info: '#c2a6ce', text: '#eceff4',
363
+ textMuted: '#c0c9d8', background: '#2e3440',
364
+ backgroundPanel: '#3b4252', backgroundElement: '#3f4653',
365
+ border: '#5b6a82', borderActive: '#8fc4d3',
366
+ borderSubtle: '#4c566a', diffContext: '#a6aec0',
367
+ diffHunkHeader: '#8fc4d3', diffContextBg: '#3b4252',
368
+ diffLineNumber: '#c0c9d8', markdownText: '#eceff4',
369
+ markdownHeading: '#8fc4d3', markdownLink: '#c2a6ce',
370
+ markdownLinkText: '#8fc4d3', markdownCode: '#a3be8c',
371
+ markdownBlockQuote: '#c0c9d8', markdownEmph: '#ebcb8b',
372
+ markdownStrong: '#8fc4d3', markdownHorizontalRule: '#a6aec0',
373
+ markdownListItem: '#8fc4d3', markdownListEnumeration: '#8fc4d3',
374
+ markdownImage: '#c2a6ce', markdownImageText: '#8fc4d3',
375
+ markdownCodeBlock: '#d8dee9', syntaxComment: '#a6aec0',
376
+ syntaxKeyword: '#c2a6ce', syntaxFunction: '#8fc4d3',
377
+ syntaxVariable: '#eceff4', syntaxString: '#a3be8c',
378
+ syntaxNumber: '#ebcb8b', syntaxType: '#c2a6ce',
379
+ syntaxOperator: '#c2a6ce', syntaxPunctuation: '#eceff4',
380
+ diffAdded: '#a3be8c', diffRemoved: '#e6a8ad',
381
+ diffHighlightAdded: '#a3be8c', diffHighlightRemoved: '#e6a8ad',
382
+ diffAddedBg: '#40494b', diffRemovedBg: '#4a4550',
383
+ diffAddedLineNumberBg: '#363e45', diffRemovedLineNumberBg: '#3b3c48',
384
+ },
385
+ },
386
+ 'contrast-dark': {
387
+ label: 'High Contrast Dark',
388
+ defs: {},
389
+ theme: {
390
+ primary: '#82aaff', secondary: '#5eead4',
391
+ accent: '#82aaff', error: '#ff8a8a',
392
+ warning: '#fde047', success: '#5eead4',
393
+ info: '#5eead4', text: '#ffffff',
394
+ textMuted: '#b8b8b8', background: '#000000',
395
+ backgroundPanel: '#0d0d0d', backgroundElement: '#1a1a1a',
396
+ border: '#8f8f8f', borderActive: '#82aaff',
397
+ borderSubtle: '#6f6f6f', diffContext: '#949494',
398
+ diffHunkHeader: '#82aaff', diffContextBg: '#0d0d0d',
399
+ diffLineNumber: '#b8b8b8', markdownText: '#ffffff',
400
+ markdownHeading: '#82aaff', markdownLink: '#5eead4',
401
+ markdownLinkText: '#82aaff', markdownCode: '#5eead4',
402
+ markdownBlockQuote: '#b8b8b8', markdownEmph: '#fde047',
403
+ markdownStrong: '#82aaff', markdownHorizontalRule: '#949494',
404
+ markdownListItem: '#82aaff', markdownListEnumeration: '#82aaff',
405
+ markdownImage: '#5eead4', markdownImageText: '#82aaff',
406
+ markdownCodeBlock: '#e0e0e0', syntaxComment: '#949494',
407
+ syntaxKeyword: '#5eead4', syntaxFunction: '#82aaff',
408
+ syntaxVariable: '#ffffff', syntaxString: '#5eead4',
409
+ syntaxNumber: '#fde047', syntaxType: '#5eead4',
410
+ syntaxOperator: '#5eead4', syntaxPunctuation: '#ffffff',
411
+ diffAdded: '#5eead4', diffRemoved: '#ff8a8a',
412
+ diffHighlightAdded: '#5eead4', diffHighlightRemoved: '#ff8a8a',
413
+ diffAddedBg: '#0e2320', diffRemovedBg: '#261515',
414
+ diffAddedLineNumberBg: '#07100f', diffRemovedLineNumberBg: '#120a0a',
415
+ },
416
+ },
417
+ 'okabe-dark': {
418
+ label: 'Okabe-Ito Dark',
419
+ defs: {},
420
+ theme: {
421
+ primary: '#56b4e9', secondary: '#cc79a7',
422
+ accent: '#56b4e9', error: '#f07c3f',
423
+ warning: '#e8d24a', success: '#35d6a5',
424
+ info: '#cc79a7', text: '#e8eaed',
425
+ textMuted: '#9ba1aa', background: '#121316',
426
+ backgroundPanel: '#1a1c21', backgroundElement: '#22252b',
427
+ border: '#41454f', borderActive: '#56b4e9',
428
+ borderSubtle: '#30333b', diffContext: '#7e8490',
429
+ diffHunkHeader: '#56b4e9', diffContextBg: '#1a1c21',
430
+ diffLineNumber: '#9ba1aa', markdownText: '#e8eaed',
431
+ markdownHeading: '#56b4e9', markdownLink: '#cc79a7',
432
+ markdownLinkText: '#56b4e9', markdownCode: '#35d6a5',
433
+ markdownBlockQuote: '#9ba1aa', markdownEmph: '#e8d24a',
434
+ markdownStrong: '#56b4e9', markdownHorizontalRule: '#7e8490',
435
+ markdownListItem: '#56b4e9', markdownListEnumeration: '#56b4e9',
436
+ markdownImage: '#cc79a7', markdownImageText: '#56b4e9',
437
+ markdownCodeBlock: '#c9cdd4', syntaxComment: '#7e8490',
438
+ syntaxKeyword: '#cc79a7', syntaxFunction: '#56b4e9',
439
+ syntaxVariable: '#e8eaed', syntaxString: '#35d6a5',
440
+ syntaxNumber: '#e8d24a', syntaxType: '#cc79a7',
441
+ syntaxOperator: '#cc79a7', syntaxPunctuation: '#e8eaed',
442
+ diffAdded: '#35d6a5', diffRemoved: '#f07c3f',
443
+ diffHighlightAdded: '#35d6a5', diffHighlightRemoved: '#f07c3f',
444
+ diffAddedBg: '#17302b', diffRemovedBg: '#33231c',
445
+ diffAddedLineNumberBg: '#142120', diffRemovedLineNumberBg: '#221a19',
446
+ },
447
+ },
448
+ 'paper': {
449
+ label: 'Paper',
450
+ defs: {},
451
+ theme: {
452
+ primary: '#5b4bd4', secondary: '#0e7c86',
453
+ accent: '#5b4bd4', error: '#cb2d3b',
454
+ warning: '#8a6100', success: '#157347',
455
+ info: '#0e7c86', text: '#24292f',
456
+ textMuted: '#5c6470', background: '#faf9f6',
457
+ backgroundPanel: '#ffffff', backgroundElement: '#f1efe9',
458
+ border: '#c9c3b4', borderActive: '#5b4bd4',
459
+ borderSubtle: '#e0dcd2', diffContext: '#666d76',
460
+ diffHunkHeader: '#5b4bd4', diffContextBg: '#ffffff',
461
+ diffLineNumber: '#5c6470', markdownText: '#24292f',
462
+ markdownHeading: '#5b4bd4', markdownLink: '#0e7c86',
463
+ markdownLinkText: '#5b4bd4', markdownCode: '#157347',
464
+ markdownBlockQuote: '#5c6470', markdownEmph: '#8a6100',
465
+ markdownStrong: '#5b4bd4', markdownHorizontalRule: '#666d76',
466
+ markdownListItem: '#5b4bd4', markdownListEnumeration: '#5b4bd4',
467
+ markdownImage: '#0e7c86', markdownImageText: '#5b4bd4',
468
+ markdownCodeBlock: '#3a424d', syntaxComment: '#666d76',
469
+ syntaxKeyword: '#0e7c86', syntaxFunction: '#5b4bd4',
470
+ syntaxVariable: '#24292f', syntaxString: '#157347',
471
+ syntaxNumber: '#8a6100', syntaxType: '#0e7c86',
472
+ syntaxOperator: '#0e7c86', syntaxPunctuation: '#24292f',
473
+ diffAdded: '#105635', diffRemoved: '#98222c',
474
+ diffHighlightAdded: '#105635', diffHighlightRemoved: '#98222c',
475
+ diffAddedBg: '#e3ece5', diffRemovedBg: '#f5e5e3',
476
+ diffAddedLineNumberBg: '#dfe9e1', diffRemovedLineNumberBg: '#f4e1e0',
477
+ },
478
+ },
479
+ 'daylight': {
480
+ label: 'Daylight',
481
+ defs: {},
482
+ theme: {
483
+ primary: '#0963c9', secondary: '#8250df',
484
+ accent: '#0963c9', error: '#cf222e',
485
+ warning: '#8a5700', success: '#1a7f37',
486
+ info: '#8250df', text: '#1f2328',
487
+ textMuted: '#59636e', background: '#f6f8fa',
488
+ backgroundPanel: '#ffffff', backgroundElement: '#eef1f4',
489
+ border: '#b7c0c9', borderActive: '#0963c9',
490
+ borderSubtle: '#d1d9e0', diffContext: '#6a7280',
491
+ diffHunkHeader: '#0963c9', diffContextBg: '#ffffff',
492
+ diffLineNumber: '#59636e', markdownText: '#1f2328',
493
+ markdownHeading: '#0963c9', markdownLink: '#8250df',
494
+ markdownLinkText: '#0963c9', markdownCode: '#1a7f37',
495
+ markdownBlockQuote: '#59636e', markdownEmph: '#8a5700',
496
+ markdownStrong: '#0963c9', markdownHorizontalRule: '#6a7280',
497
+ markdownListItem: '#0963c9', markdownListEnumeration: '#0963c9',
498
+ markdownImage: '#8250df', markdownImageText: '#0963c9',
499
+ markdownCodeBlock: '#383f47', syntaxComment: '#6a7280',
500
+ syntaxKeyword: '#8250df', syntaxFunction: '#0963c9',
501
+ syntaxVariable: '#1f2328', syntaxString: '#1a7f37',
502
+ syntaxNumber: '#8a5700', syntaxType: '#8250df',
503
+ syntaxOperator: '#8250df', syntaxPunctuation: '#1f2328',
504
+ diffAdded: '#145f29', diffRemoved: '#9b1a23',
505
+ diffHighlightAdded: '#145f29', diffHighlightRemoved: '#9b1a23',
506
+ diffAddedBg: '#e0ece7', diffRemovedBg: '#f2e3e6',
507
+ diffAddedLineNumberBg: '#dce9e3', diffRemovedLineNumberBg: '#f1dee2',
508
+ },
509
+ },
510
+ 'solarized-light': {
511
+ label: 'Solarized Light',
512
+ defs: {},
513
+ theme: {
514
+ primary: '#1e6aa4', secondary: '#a04a7c',
515
+ accent: '#1e6aa4', error: '#c62d2b',
516
+ warning: '#866500', success: '#636f00',
517
+ info: '#a04a7c', text: '#073642',
518
+ textMuted: '#556970', background: '#fdf6e3',
519
+ backgroundPanel: '#fdf6e3', backgroundElement: '#f1e9d2',
520
+ border: '#cbbf98', borderActive: '#1e6aa4',
521
+ borderSubtle: '#e3d8b8', diffContext: '#5a6e75',
522
+ diffHunkHeader: '#1e6aa4', diffContextBg: '#fdf6e3',
523
+ diffLineNumber: '#4a5b61', markdownText: '#073642',
524
+ markdownHeading: '#1e6aa4', markdownLink: '#a04a7c',
525
+ markdownLinkText: '#1e6aa4', markdownCode: '#636f00',
526
+ markdownBlockQuote: '#556970', markdownEmph: '#866500',
527
+ markdownStrong: '#1e6aa4', markdownHorizontalRule: '#5a6e75',
528
+ markdownListItem: '#1e6aa4', markdownListEnumeration: '#1e6aa4',
529
+ markdownImage: '#a04a7c', markdownImageText: '#1e6aa4',
530
+ markdownCodeBlock: '#2d4a52', syntaxComment: '#5a6e75',
531
+ syntaxKeyword: '#a04a7c', syntaxFunction: '#1e6aa4',
532
+ syntaxVariable: '#073642', syntaxString: '#636f00',
533
+ syntaxNumber: '#866500', syntaxType: '#a04a7c',
534
+ syntaxOperator: '#a04a7c', syntaxPunctuation: '#073642',
535
+ diffAdded: '#4a5300', diffRemoved: '#952220',
536
+ diffHighlightAdded: '#4a5300', diffHighlightRemoved: '#952220',
537
+ diffAddedBg: '#eee9cc', diffRemovedBg: '#f8e2d1',
538
+ diffAddedLineNumberBg: '#ebe6c8', diffRemovedLineNumberBg: '#f6decd',
539
+ },
540
+ },
541
+ 'contrast-light': {
542
+ label: 'High Contrast Light',
543
+ defs: {},
544
+ theme: {
545
+ primary: '#0043c8', secondary: '#00633b',
546
+ accent: '#0043c8', error: '#b00020',
547
+ warning: '#694d00', success: '#00633b',
548
+ info: '#00633b', text: '#000000',
549
+ textMuted: '#3d3d3d', background: '#ffffff',
550
+ backgroundPanel: '#ffffff', backgroundElement: '#f2f2f2',
551
+ border: '#595959', borderActive: '#0043c8',
552
+ borderSubtle: '#767676', diffContext: '#525252',
553
+ diffHunkHeader: '#0043c8', diffContextBg: '#ffffff',
554
+ diffLineNumber: '#3d3d3d', markdownText: '#000000',
555
+ markdownHeading: '#0043c8', markdownLink: '#00633b',
556
+ markdownLinkText: '#0043c8', markdownCode: '#00633b',
557
+ markdownBlockQuote: '#3d3d3d', markdownEmph: '#694d00',
558
+ markdownStrong: '#0043c8', markdownHorizontalRule: '#525252',
559
+ markdownListItem: '#0043c8', markdownListEnumeration: '#0043c8',
560
+ markdownImage: '#00633b', markdownImageText: '#0043c8',
561
+ markdownCodeBlock: '#1a1a1a', syntaxComment: '#525252',
562
+ syntaxKeyword: '#00633b', syntaxFunction: '#0043c8',
563
+ syntaxVariable: '#000000', syntaxString: '#00633b',
564
+ syntaxNumber: '#694d00', syntaxType: '#00633b',
565
+ syntaxOperator: '#00633b', syntaxPunctuation: '#000000',
566
+ diffAdded: '#004a2c', diffRemoved: '#840018',
567
+ diffHighlightAdded: '#004a2c', diffHighlightRemoved: '#840018',
568
+ diffAddedBg: '#e6efeb', diffRemovedBg: '#f7e6e9',
569
+ diffAddedLineNumberBg: '#e0ece7', diffRemovedLineNumberBg: '#f6e0e4',
570
+ },
571
+ },
572
+ 'okabe-light': {
573
+ label: 'Okabe-Ito Light',
574
+ defs: {},
575
+ theme: {
576
+ primary: '#0072b2', secondary: '#a3537f',
577
+ accent: '#0072b2', error: '#a3537f',
578
+ warning: '#8a6300', success: '#00795b',
579
+ info: '#a3537f', text: '#20242a',
580
+ textMuted: '#4f5862', background: '#fbfbf8',
581
+ backgroundPanel: '#ffffff', backgroundElement: '#f2f2ec',
582
+ border: '#b8b8a8', borderActive: '#0072b2',
583
+ borderSubtle: '#dadad0', diffContext: '#667079',
584
+ diffHunkHeader: '#0072b2', diffContextBg: '#ffffff',
585
+ diffLineNumber: '#4f5862', markdownText: '#20242a',
586
+ markdownHeading: '#0072b2', markdownLink: '#a3537f',
587
+ markdownLinkText: '#0072b2', markdownCode: '#00795b',
588
+ markdownBlockQuote: '#4f5862', markdownEmph: '#8a6300',
589
+ markdownStrong: '#0072b2', markdownHorizontalRule: '#667079',
590
+ markdownListItem: '#0072b2', markdownListEnumeration: '#0072b2',
591
+ markdownImage: '#a3537f', markdownImageText: '#0072b2',
592
+ markdownCodeBlock: '#343c46', syntaxComment: '#667079',
593
+ syntaxKeyword: '#a3537f', syntaxFunction: '#0072b2',
594
+ syntaxVariable: '#20242a', syntaxString: '#00795b',
595
+ syntaxNumber: '#8a6300', syntaxType: '#a3537f',
596
+ syntaxOperator: '#a3537f', syntaxPunctuation: '#20242a',
597
+ diffAdded: '#005b44', diffRemoved: '#7a3e5f',
598
+ diffHighlightAdded: '#005b44', diffHighlightRemoved: '#7a3e5f',
599
+ diffAddedBg: '#e2eee8', diffRemovedBg: '#f2eaec',
600
+ diffAddedLineNumberBg: '#ddebe5', diffRemovedLineNumberBg: '#f0e7e9',
601
+ },
602
+ },
603
+ };
604
+
605
+ /** Zip a dark and a light theme into one adaptive theme whose tokens are
606
+ * {dark, light} objects resolved by flattenTheme(mode). */
607
+ function pairThemes(darkName, lightName, label) {
608
+ const theme = {};
609
+ const dt = RAW_THEMES[darkName].theme;
610
+ const lt = RAW_THEMES[lightName].theme;
611
+ for (const k of Object.keys(dt)) theme[k] = { dark: dt[k], light: lt[k] };
612
+ return { label, theme };
613
+ }
614
+
615
+ // Adaptive themes: the same tokens switch dark/light palette by terminal mode.
616
+ RAW_THEMES.solarized = pairThemes('solarized-dark', 'solarized-light', 'Solarized (auto)');
617
+ RAW_THEMES.okabe = pairThemes('okabe-dark', 'okabe-light', 'Okabe-Ito (auto)');
618
+ RAW_THEMES.contrast = pairThemes('contrast-dark', 'contrast-light', 'High Contrast (auto)');
619
+ RAW_THEMES.system = pairThemes('obsidian', 'paper', 'System (auto)');
620
+
621
+ export const THEMES = RAW_THEMES;
622
+
623
+ export const THEME_NAMES = Object.keys(THEMES);
624
+
625
+ /** Guess whether the terminal is running a light or dark color scheme.
626
+ * CARTHAGENT_THEME_MODE=light|dark overrides; otherwise COLORFGBG's background
627
+ * index (0-6 or 8 = dark ANSI colors, 7 or 9-15 = light); default dark. */
628
+ export function detectTermMode(env = {}) {
629
+ const forced = String(env.CARTHAGENT_THEME_MODE || '').toLowerCase();
630
+ if (forced === 'light' || forced === 'dark') return forced;
631
+ const parts = String(env.COLORFGBG || '').split(';');
632
+ const idx = Number(parts[parts.length - 1]);
633
+ if (Number.isFinite(idx) && env.COLORFGBG !== undefined) return idx === 7 || idx >= 9 ? 'light' : 'dark';
634
+ return DEFAULT_MODE;
635
+ }
636
+
637
+ /** Back-compat: flattened palettes keyed by name, per mode. */
638
+ export function themePalettes(mode = DEFAULT_MODE) {
639
+ const out = {};
640
+ for (const [name, raw] of Object.entries(RAW_THEMES)) out[name] = flattenTheme(raw, mode);
641
+ return out;
642
+ }
643
+
644
+ const _flatCache = new Map();
645
+ function flatPalettes(mode = DEFAULT_MODE) {
646
+ if (!_flatCache.has(mode)) _flatCache.set(mode, themePalettes(mode));
647
+ return _flatCache.get(mode);
648
+ }
649
+
650
+ export function getTheme(name, mode = DEFAULT_MODE) {
651
+ const key = resolveThemeName(name);
652
+ const palettes = flatPalettes(mode);
653
+ return palettes[key] || palettes.carthage;
654
+ }
655
+
656
+ /** Resolve an env/flag theme name, defaulting to Carthagent's own palette. */
657
+ export function resolveThemeName(name) {
658
+ if (!name) return 'carthage';
659
+ const n = String(name).toLowerCase();
660
+ return THEME_NAMES.find(k => k === n || (RAW_THEMES[k].label || '').toLowerCase() === n) || 'carthage';
661
+ }
662
+
663
+ export { fg, bg, mix, gradient, paint, BOLD, DIM, ITALIC, UNDERLINE, RESET };