@odysx/codemind 0.0.0-stage → 0.1.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 (331) hide show
  1. package/README.md +293 -2
  2. package/dist/commands/agents.d.ts +2 -0
  3. package/dist/commands/agents.d.ts.map +1 -0
  4. package/dist/commands/agents.js +91 -0
  5. package/dist/commands/agents.js.map +1 -0
  6. package/dist/commands/auth.d.ts +2 -0
  7. package/dist/commands/auth.d.ts.map +1 -0
  8. package/dist/commands/auth.js +35 -0
  9. package/dist/commands/auth.js.map +1 -0
  10. package/dist/commands/chat.d.ts +2 -0
  11. package/dist/commands/chat.d.ts.map +1 -0
  12. package/dist/commands/chat.js +180 -0
  13. package/dist/commands/chat.js.map +1 -0
  14. package/dist/commands/keys.d.ts +2 -0
  15. package/dist/commands/keys.d.ts.map +1 -0
  16. package/dist/commands/keys.js +81 -0
  17. package/dist/commands/keys.js.map +1 -0
  18. package/dist/commands/local.d.ts +2 -0
  19. package/dist/commands/local.d.ts.map +1 -0
  20. package/dist/commands/local.js +325 -0
  21. package/dist/commands/local.js.map +1 -0
  22. package/dist/commands/mcp.d.ts +2 -0
  23. package/dist/commands/mcp.d.ts.map +1 -0
  24. package/dist/commands/mcp.js +73 -0
  25. package/dist/commands/mcp.js.map +1 -0
  26. package/dist/commands/prompts.d.ts +2 -0
  27. package/dist/commands/prompts.d.ts.map +1 -0
  28. package/dist/commands/prompts.js +59 -0
  29. package/dist/commands/prompts.js.map +1 -0
  30. package/dist/commands/skills.d.ts +2 -0
  31. package/dist/commands/skills.d.ts.map +1 -0
  32. package/dist/commands/skills.js +41 -0
  33. package/dist/commands/skills.js.map +1 -0
  34. package/dist/core/auth/index.d.ts +10 -0
  35. package/dist/core/auth/index.d.ts.map +1 -0
  36. package/dist/core/auth/index.js +82 -0
  37. package/dist/core/auth/index.js.map +1 -0
  38. package/dist/core/config/index.d.ts +47 -0
  39. package/dist/core/config/index.d.ts.map +1 -0
  40. package/dist/core/config/index.js +118 -0
  41. package/dist/core/config/index.js.map +1 -0
  42. package/dist/core/history.d.ts +14 -0
  43. package/dist/core/history.d.ts.map +1 -0
  44. package/dist/core/history.js +80 -0
  45. package/dist/core/history.js.map +1 -0
  46. package/dist/core/markdown-renderer.d.ts +47 -0
  47. package/dist/core/markdown-renderer.d.ts.map +1 -0
  48. package/dist/core/markdown-renderer.js +385 -0
  49. package/dist/core/markdown-renderer.js.map +1 -0
  50. package/dist/core/permissions/index.d.ts +31 -0
  51. package/dist/core/permissions/index.d.ts.map +1 -0
  52. package/dist/core/permissions/index.js +64 -0
  53. package/dist/core/permissions/index.js.map +1 -0
  54. package/dist/core/provider/external.d.ts +28 -0
  55. package/dist/core/provider/external.d.ts.map +1 -0
  56. package/dist/core/provider/external.js +248 -0
  57. package/dist/core/provider/external.js.map +1 -0
  58. package/dist/core/provider/index.d.ts +96 -0
  59. package/dist/core/provider/index.d.ts.map +1 -0
  60. package/dist/core/provider/index.js +423 -0
  61. package/dist/core/provider/index.js.map +1 -0
  62. package/dist/core/registry/index.d.ts +25 -0
  63. package/dist/core/registry/index.d.ts.map +1 -0
  64. package/dist/core/registry/index.js +216 -0
  65. package/dist/core/registry/index.js.map +1 -0
  66. package/dist/core/schema/types.d.ts +93 -0
  67. package/dist/core/schema/types.d.ts.map +1 -0
  68. package/dist/core/schema/types.js +12 -0
  69. package/dist/core/schema/types.js.map +1 -0
  70. package/dist/core/terminal.d.ts +40 -0
  71. package/dist/core/terminal.d.ts.map +1 -0
  72. package/dist/core/terminal.js +134 -0
  73. package/dist/core/terminal.js.map +1 -0
  74. package/dist/core/workspace/index.d.ts +35 -0
  75. package/dist/core/workspace/index.d.ts.map +1 -0
  76. package/dist/core/workspace/index.js +194 -0
  77. package/dist/core/workspace/index.js.map +1 -0
  78. package/dist/index.d.ts +10 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +393 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/ui/app.d.ts +3 -0
  83. package/dist/ui/app.d.ts.map +1 -0
  84. package/dist/ui/app.js +554 -0
  85. package/dist/ui/app.js.map +1 -0
  86. package/dist/ui/commands/cases/catalog.d.ts +11 -0
  87. package/dist/ui/commands/cases/catalog.d.ts.map +1 -0
  88. package/dist/ui/commands/cases/catalog.js +62 -0
  89. package/dist/ui/commands/cases/catalog.js.map +1 -0
  90. package/dist/ui/commands/cases/misc.d.ts +35 -0
  91. package/dist/ui/commands/cases/misc.d.ts.map +1 -0
  92. package/dist/ui/commands/cases/misc.js +245 -0
  93. package/dist/ui/commands/cases/misc.js.map +1 -0
  94. package/dist/ui/commands/cases/tasks.d.ts +13 -0
  95. package/dist/ui/commands/cases/tasks.d.ts.map +1 -0
  96. package/dist/ui/commands/cases/tasks.js +91 -0
  97. package/dist/ui/commands/cases/tasks.js.map +1 -0
  98. package/dist/ui/commands/runCommand.d.ts +22 -0
  99. package/dist/ui/commands/runCommand.d.ts.map +1 -0
  100. package/dist/ui/commands/runCommand.js +136 -0
  101. package/dist/ui/commands/runCommand.js.map +1 -0
  102. package/dist/ui/components/AgentPicker.d.ts +11 -0
  103. package/dist/ui/components/AgentPicker.d.ts.map +1 -0
  104. package/dist/ui/components/AgentPicker.js +7 -0
  105. package/dist/ui/components/AgentPicker.js.map +1 -0
  106. package/dist/ui/components/AuthPicker.d.ts +14 -0
  107. package/dist/ui/components/AuthPicker.d.ts.map +1 -0
  108. package/dist/ui/components/AuthPicker.js +7 -0
  109. package/dist/ui/components/AuthPicker.js.map +1 -0
  110. package/dist/ui/components/Banner.d.ts +8 -0
  111. package/dist/ui/components/Banner.d.ts.map +1 -0
  112. package/dist/ui/components/Banner.js +24 -0
  113. package/dist/ui/components/Banner.js.map +1 -0
  114. package/dist/ui/components/CommandMenu.d.ts +17 -0
  115. package/dist/ui/components/CommandMenu.d.ts.map +1 -0
  116. package/dist/ui/components/CommandMenu.js +21 -0
  117. package/dist/ui/components/CommandMenu.js.map +1 -0
  118. package/dist/ui/components/ErrorBoundary.d.ts +24 -0
  119. package/dist/ui/components/ErrorBoundary.d.ts.map +1 -0
  120. package/dist/ui/components/ErrorBoundary.js +51 -0
  121. package/dist/ui/components/ErrorBoundary.js.map +1 -0
  122. package/dist/ui/components/InputBar.d.ts +28 -0
  123. package/dist/ui/components/InputBar.d.ts.map +1 -0
  124. package/dist/ui/components/InputBar.js +108 -0
  125. package/dist/ui/components/InputBar.js.map +1 -0
  126. package/dist/ui/components/KeysPanel.d.ts +12 -0
  127. package/dist/ui/components/KeysPanel.d.ts.map +1 -0
  128. package/dist/ui/components/KeysPanel.js +25 -0
  129. package/dist/ui/components/KeysPanel.js.map +1 -0
  130. package/dist/ui/components/MessageView.d.ts +29 -0
  131. package/dist/ui/components/MessageView.d.ts.map +1 -0
  132. package/dist/ui/components/MessageView.js +107 -0
  133. package/dist/ui/components/MessageView.js.map +1 -0
  134. package/dist/ui/components/PermissionPrompt.d.ts +10 -0
  135. package/dist/ui/components/PermissionPrompt.d.ts.map +1 -0
  136. package/dist/ui/components/PermissionPrompt.js +4 -0
  137. package/dist/ui/components/PermissionPrompt.js.map +1 -0
  138. package/dist/ui/components/Pickers.d.ts +43 -0
  139. package/dist/ui/components/Pickers.d.ts.map +1 -0
  140. package/dist/ui/components/Pickers.js +33 -0
  141. package/dist/ui/components/Pickers.js.map +1 -0
  142. package/dist/ui/components/SearchOverlay.d.ts +21 -0
  143. package/dist/ui/components/SearchOverlay.d.ts.map +1 -0
  144. package/dist/ui/components/SearchOverlay.js +14 -0
  145. package/dist/ui/components/SearchOverlay.js.map +1 -0
  146. package/dist/ui/components/SessionPicker.d.ts +12 -0
  147. package/dist/ui/components/SessionPicker.d.ts.map +1 -0
  148. package/dist/ui/components/SessionPicker.js +8 -0
  149. package/dist/ui/components/SessionPicker.js.map +1 -0
  150. package/dist/ui/components/WorkingIndicator.d.ts +10 -0
  151. package/dist/ui/components/WorkingIndicator.d.ts.map +1 -0
  152. package/dist/ui/components/WorkingIndicator.js +23 -0
  153. package/dist/ui/components/WorkingIndicator.js.map +1 -0
  154. package/dist/ui/controls/ApiKeyEntry.d.ts +8 -0
  155. package/dist/ui/controls/ApiKeyEntry.d.ts.map +1 -0
  156. package/dist/ui/controls/ApiKeyEntry.js +5 -0
  157. package/dist/ui/controls/ApiKeyEntry.js.map +1 -0
  158. package/dist/ui/controls/MultiSelect.d.ts +18 -0
  159. package/dist/ui/controls/MultiSelect.d.ts.map +1 -0
  160. package/dist/ui/controls/MultiSelect.js +9 -0
  161. package/dist/ui/controls/MultiSelect.js.map +1 -0
  162. package/dist/ui/hooks/useAgentPicker.d.ts +14 -0
  163. package/dist/ui/hooks/useAgentPicker.d.ts.map +1 -0
  164. package/dist/ui/hooks/useAgentPicker.js +53 -0
  165. package/dist/ui/hooks/useAgentPicker.js.map +1 -0
  166. package/dist/ui/hooks/useAuthFlow.d.ts +14 -0
  167. package/dist/ui/hooks/useAuthFlow.d.ts.map +1 -0
  168. package/dist/ui/hooks/useAuthFlow.js +31 -0
  169. package/dist/ui/hooks/useAuthFlow.js.map +1 -0
  170. package/dist/ui/hooks/useKeysFlow.d.ts +17 -0
  171. package/dist/ui/hooks/useKeysFlow.d.ts.map +1 -0
  172. package/dist/ui/hooks/useKeysFlow.js +130 -0
  173. package/dist/ui/hooks/useKeysFlow.js.map +1 -0
  174. package/dist/ui/hooks/useSessionPicker.d.ts +29 -0
  175. package/dist/ui/hooks/useSessionPicker.d.ts.map +1 -0
  176. package/dist/ui/hooks/useSessionPicker.js +58 -0
  177. package/dist/ui/hooks/useSessionPicker.js.map +1 -0
  178. package/dist/ui/hooks/useTerminalSize.d.ts +6 -0
  179. package/dist/ui/hooks/useTerminalSize.d.ts.map +1 -0
  180. package/dist/ui/hooks/useTerminalSize.js +29 -0
  181. package/dist/ui/hooks/useTerminalSize.js.map +1 -0
  182. package/dist/ui/input/keyRouter.d.ts +125 -0
  183. package/dist/ui/input/keyRouter.d.ts.map +1 -0
  184. package/dist/ui/input/keyRouter.js +574 -0
  185. package/dist/ui/input/keyRouter.js.map +1 -0
  186. package/dist/ui/layouts/ScreenLayout.d.ts +98 -0
  187. package/dist/ui/layouts/ScreenLayout.d.ts.map +1 -0
  188. package/dist/ui/layouts/ScreenLayout.js +56 -0
  189. package/dist/ui/layouts/ScreenLayout.js.map +1 -0
  190. package/dist/ui/shared/types.d.ts +143 -0
  191. package/dist/ui/shared/types.d.ts.map +1 -0
  192. package/dist/ui/shared/types.js +38 -0
  193. package/dist/ui/shared/types.js.map +1 -0
  194. package/dist/ui/theme.d.ts +29 -0
  195. package/dist/ui/theme.d.ts.map +1 -0
  196. package/dist/ui/theme.js +54 -0
  197. package/dist/ui/theme.js.map +1 -0
  198. package/dist/ui/utils/markdown.d.ts +74 -0
  199. package/dist/ui/utils/markdown.d.ts.map +1 -0
  200. package/dist/ui/utils/markdown.js +187 -0
  201. package/dist/ui/utils/markdown.js.map +1 -0
  202. package/dist/ui/utils/mentions.d.ts +12 -0
  203. package/dist/ui/utils/mentions.d.ts.map +1 -0
  204. package/dist/ui/utils/mentions.js +28 -0
  205. package/dist/ui/utils/mentions.js.map +1 -0
  206. package/dist/ui/utils/terminal-text.d.ts +33 -0
  207. package/dist/ui/utils/terminal-text.d.ts.map +1 -0
  208. package/dist/ui/utils/terminal-text.js +123 -0
  209. package/dist/ui/utils/terminal-text.js.map +1 -0
  210. package/dist/ui/utils/text.d.ts +72 -0
  211. package/dist/ui/utils/text.d.ts.map +1 -0
  212. package/dist/ui/utils/text.js +171 -0
  213. package/dist/ui/utils/text.js.map +1 -0
  214. package/eslint.config.js +40 -0
  215. package/graphify-out/GRAPH_REPORT.md +140 -0
  216. package/graphify-out/cache/1236b1806943f8eb5c64fece9fb448149370f4a1b52b32f0977ad528d7911291.json +1 -0
  217. package/graphify-out/cache/15cbf641dcc0fd641c18da872214918203a1f64baa7ac8430e4702ef32d18b02.json +1 -0
  218. package/graphify-out/cache/1abc52745bb46f6cc5a528530e2bc1f368c26e348dff85cdde5cad6f275d7177.json +1 -0
  219. package/graphify-out/cache/1c7815c37c13177e98895e272285f6151a8d0807478fc843ec452634b3e9912d.json +1 -0
  220. package/graphify-out/cache/1ec38c39f044f329c78642b61d6394fb8e15d0014335f32947d1f5c7b88c02bc.json +1 -0
  221. package/graphify-out/cache/20c9b57ff76dbb9d57cbd00659b0a42d2b28dd2abacf1ef4143cc67a5b6fe7f4.json +1 -0
  222. package/graphify-out/cache/285e11876884eb619e779d540cd957b33e70f14c67ecc26c9b9755aa9cedd717.json +1 -0
  223. package/graphify-out/cache/2c0a9c49ab51f4e0f07543b4e941bf802b7db31fa607c4cee8e595575be68fe7.json +1 -0
  224. package/graphify-out/cache/3025e6c2756c79ccaadd51d611f25a8b6630a6a11ce1b4e6e261b3e033dc194f.json +1 -0
  225. package/graphify-out/cache/4801a686ddfa0a52824a4fc3d65443cbb0ab9f0b030af67d02fccb520c584a08.json +1 -0
  226. package/graphify-out/cache/4f8fd96f38aa7d0293b4fab60c4581c4f3e68f4533c664c9cd78d1c53bea1cba.json +1 -0
  227. package/graphify-out/cache/5928e562b0f5700184b810e2403f4aa685e2b93c3c584c10460562b514c40fdd.json +1 -0
  228. package/graphify-out/cache/66132486efb0a4cfaeea766448f1f15bb33635808714052e7e24e5b00fbc984f.json +1 -0
  229. package/graphify-out/cache/66ab27669e7ec685130063662af9f30018c267f7639b4af4b0504a98282c383a.json +1 -0
  230. package/graphify-out/cache/6ff6b3dd433b5ffe96e166263a203dd622397e419dc00bb676824988b7defeab.json +1 -0
  231. package/graphify-out/cache/7a00a49932177a6215e2590b1ddfd6f1d8494792f693068e9d427d16b165d370.json +1 -0
  232. package/graphify-out/cache/7b681bc5182f40f707f1c0b16b78af38efffa62a1df315d10878f4de888408ef.json +1 -0
  233. package/graphify-out/cache/81196d44e50ac0b276d826a531ed10c425a528b298e3fe18e8d5a3eec996e9d5.json +1 -0
  234. package/graphify-out/cache/8934e9b32dea6e66fdc34fa1681b287ff1335c389917e0fc6ee2fc573e23e87b.json +1 -0
  235. package/graphify-out/cache/975f6c99807f86b79c80ca40c783618e2080a927eaebe6ea3db37b869f048851.json +1 -0
  236. package/graphify-out/cache/9ab98f08626fd8190462595e38de828293ad184db8df5e1177b05a8fe290faa1.json +1 -0
  237. package/graphify-out/cache/9c434a6796d7932b6e87a908c155c09cb2b8d097fc55f141f0302b6600f94749.json +1 -0
  238. package/graphify-out/cache/ac5cf4c489dc417c1f6ea728d0b6ba12ac7087bc6c2e736697ff3024b4d4e534.json +1 -0
  239. package/graphify-out/cache/ae5083b5c1dca3e5c6af485e7f6eb8a08ff8b382cdecf92ab5e0902053442afe.json +1 -0
  240. package/graphify-out/cache/b274057fc2e0118cf2746d1d8060841122bb2a2b0305566fc3f32d3a51e08bcc.json +1 -0
  241. package/graphify-out/cache/b39beef31da682387f030c0d149f6cd5b3e66effbf936cc8430db15360759dda.json +1 -0
  242. package/graphify-out/cache/bf3c6a36bb72820bc11cbf4a5c49067d1f62013d4686c019a4dbd9951b1e980e.json +1 -0
  243. package/graphify-out/cache/c034e156028d1a58b89bce659726e9a4065ddc4d2b560d6bce7a206fdff8dad3.json +1 -0
  244. package/graphify-out/cache/c619b5bbe8d1f427fbd7816d1e9fcfaf90d7201b020ae6b578166aeb9cb20683.json +1 -0
  245. package/graphify-out/cache/c8db77a9da0b0f601acfa50a620f31155cdda0d0cc0f2285adcea19e77194ee6.json +1 -0
  246. package/graphify-out/cache/ca664791ec7741a2077d9e7c10384142d30e7a3b77b388df719c315da608d57d.json +1 -0
  247. package/graphify-out/cache/cba43a116186bd55c8a63368dea4eee4a8123b2bec0a42df6efb3254f89f9a7a.json +1 -0
  248. package/graphify-out/cache/cd51cbb3dad1cf34417b9761fe2eb184a9f57d23dc86e45630e63bfa2ecafddc.json +1 -0
  249. package/graphify-out/cache/d06738cde193b34a136b94104220c17e0212b814b3e4d7ff399105635cae1a03.json +1 -0
  250. package/graphify-out/cache/d093c19f0169c0398eeb1360895b1c16ecc50abc59f4be8eec3f6fd27c89a6e5.json +1 -0
  251. package/graphify-out/cache/da8f75c438531d232fe114d5cbf2374576ce842a5fb87c7e5a88b78fdb334e5e.json +1 -0
  252. package/graphify-out/cache/e35798fa04ddede548a6953bdea506bd7d0788dfed4e8a8ea6ae77b1b60ef5e0.json +1 -0
  253. package/graphify-out/cache/e5a38c254719000487098782125e15e2e982c07d66b99d359ed1781f30f9fc8c.json +1 -0
  254. package/graphify-out/cache/e6e4c4a5a7200ee0154585b5d6538f699b0a746dbded3164f8391f06ce7cb212.json +1 -0
  255. package/graphify-out/cache/ea8d0838df6309b673b031f616b253af957898ee7289d25a541fa6183b732e4e.json +1 -0
  256. package/graphify-out/cache/ebaee92b0e881efd7a08f3143e2c1803310396b4651d4f77532003c699cc6836.json +1 -0
  257. package/graphify-out/cache/edf8543318a9e60d56d04704078da6c37202ddd6fdfc83144fe2b94fe19b80ef.json +1 -0
  258. package/graphify-out/cache/efca19d3668035f11126fc9eccbeab290abfa94babf3f9a8706de81d17aba263.json +1 -0
  259. package/graphify-out/cache/f1480bb642025ebd6d99986cdd8a7d5726897ec038300e4b095c9c938435dfad.json +1 -0
  260. package/graphify-out/cache/f459f21277f03865f732affb175b1b092954dae5967f27b3cd1864466e3e24f4.json +1 -0
  261. package/graphify-out/cache/f899e37e864010b30f4c196e86082d7bd022a0df032005e0407883ebcec36514.json +1 -0
  262. package/graphify-out/cache/fb3cbe07fbcd97c536cff9c6bc343c35f22d49613f05c53ad30ef67a75c5d93e.json +1 -0
  263. package/graphify-out/cache/fd3dc682b1ca2f5ae03b50d6b0e045ae50f5701c0a21c5a388d77ef482939d3a.json +1 -0
  264. package/graphify-out/graph.html +257 -0
  265. package/graphify-out/graph.json +4396 -0
  266. package/package.json +45 -6
  267. package/scripts/e2e-external.mjs +65 -0
  268. package/scripts/live-agents.mjs +6 -0
  269. package/scripts/live-stream.mjs +51 -0
  270. package/src/commands/agents.ts +91 -0
  271. package/src/commands/auth.ts +39 -0
  272. package/src/commands/chat.ts +198 -0
  273. package/src/commands/keys.ts +83 -0
  274. package/src/commands/local.ts +302 -0
  275. package/src/commands/mcp.ts +74 -0
  276. package/src/commands/prompts.ts +58 -0
  277. package/src/commands/skills.ts +43 -0
  278. package/src/core/auth/index.ts +101 -0
  279. package/src/core/config/index.ts +152 -0
  280. package/src/core/history.ts +79 -0
  281. package/src/core/markdown-renderer.ts +420 -0
  282. package/src/core/permissions/index.ts +99 -0
  283. package/src/core/provider/external.ts +312 -0
  284. package/src/core/provider/index.ts +517 -0
  285. package/src/core/registry/index.ts +250 -0
  286. package/src/core/schema/types.ts +106 -0
  287. package/src/core/terminal.ts +124 -0
  288. package/src/core/workspace/index.ts +216 -0
  289. package/src/index.ts +401 -0
  290. package/src/ui/app.tsx +644 -0
  291. package/src/ui/commands/cases/catalog.ts +76 -0
  292. package/src/ui/commands/cases/misc.ts +293 -0
  293. package/src/ui/commands/cases/tasks.ts +115 -0
  294. package/src/ui/commands/runCommand.ts +178 -0
  295. package/src/ui/components/Banner.tsx +63 -0
  296. package/src/ui/components/CommandMenu.tsx +63 -0
  297. package/src/ui/components/ErrorBoundary.tsx +75 -0
  298. package/src/ui/components/InputBar.tsx +227 -0
  299. package/src/ui/components/KeysPanel.tsx +115 -0
  300. package/src/ui/components/MessageView.tsx +226 -0
  301. package/src/ui/components/Pickers.tsx +234 -0
  302. package/src/ui/components/SearchOverlay.tsx +65 -0
  303. package/src/ui/components/WorkingIndicator.tsx +35 -0
  304. package/src/ui/controls/ApiKeyEntry.tsx +29 -0
  305. package/src/ui/controls/MultiSelect.tsx +55 -0
  306. package/src/ui/hooks/useAgentPicker.ts +64 -0
  307. package/src/ui/hooks/useAuthFlow.ts +47 -0
  308. package/src/ui/hooks/useKeysFlow.ts +157 -0
  309. package/src/ui/hooks/useSessionPicker.ts +84 -0
  310. package/src/ui/hooks/useTerminalSize.ts +36 -0
  311. package/src/ui/input/keyRouter.ts +627 -0
  312. package/src/ui/layouts/ScreenLayout.tsx +202 -0
  313. package/src/ui/shared/types.ts +160 -0
  314. package/src/ui/theme.ts +53 -0
  315. package/src/ui/utils/markdown.ts +255 -0
  316. package/src/ui/utils/mentions.ts +40 -0
  317. package/src/ui/utils/terminal-text.ts +130 -0
  318. package/src/ui/utils/text.ts +174 -0
  319. package/test/commands.test.mjs +127 -0
  320. package/test/config.test.mjs +123 -0
  321. package/test/history.test.mjs +42 -0
  322. package/test/keyrouter.test.mjs +324 -0
  323. package/test/layout.test.mjs +271 -0
  324. package/test/markdown.test.mjs +92 -0
  325. package/test/mentions.test.mjs +51 -0
  326. package/test/permissions.test.mjs +130 -0
  327. package/test/provider.test.mjs +287 -0
  328. package/test/terminal-text.test.mjs +116 -0
  329. package/test/text.test.mjs +134 -0
  330. package/test/workspace.test.mjs +101 -0
  331. package/tsconfig.json +32 -0
package/src/ui/app.tsx ADDED
@@ -0,0 +1,644 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Interactive Ink UI — Claude Code style REPL.
4
+ *
5
+ * app.tsx is the orchestrator only: it owns the state hooks, builds the
6
+ * CommandCtx / KeyRouterDeps bundles, and renders ScreenLayout. The actual
7
+ * behavior lives in:
8
+ * hooks/ — per-flow state + API actions (keys, agent, sessions, auth)
9
+ * commands/ — slash-command dispatch (runCommand + cases/)
10
+ * input/ — global keyboard router (keyRouter.ts)
11
+ * layouts/ — screen composition (ScreenLayout.tsx)
12
+ * controls/ — interactive overlay widgets (MultiSelect, ApiKeyEntry)
13
+ * utils/ — pure helpers (@file mention expansion)
14
+ */
15
+ import React, { useState, useEffect, useCallback, useMemo, useRef } from "react";
16
+ import { render, useApp, useInput } from "ink";
17
+ import { homedir } from "node:os";
18
+ import { sep, join, dirname } from "node:path";
19
+ import { existsSync } from "node:fs";
20
+ import { randomUUID } from "node:crypto";
21
+ import { getConfig } from "../core/config/index.js";
22
+ import { getWorkspaceRoot, isFolderTrusted, trustFolder as rememberFolder } from "../core/workspace/index.js";
23
+ import { getPermissionMode } from "../core/permissions/index.js";
24
+ import { streamChat, apiCall } from "../core/provider/index.js";
25
+ import { getActiveProvider, streamExternalChat } from "../core/provider/external.js";
26
+ import { SLASH_COMMANDS } from "./shared/types.js";
27
+ import type { ChatMessage, CommandCtx, PendingOp, Role } from "./shared/types.js";
28
+ import { ScreenLayout } from "./layouts/ScreenLayout.js";
29
+ import { useKeysFlow } from "./hooks/useKeysFlow.js";
30
+ import { useAgentPicker } from "./hooks/useAgentPicker.js";
31
+ import { useSessionPicker } from "./hooks/useSessionPicker.js";
32
+ import { useAuthFlow } from "./hooks/useAuthFlow.js";
33
+ import { runCommand } from "./commands/runCommand.js";
34
+ import { handleKey } from "./input/keyRouter.js";
35
+ import { expandMentions } from "./utils/mentions.js";
36
+ import { wordAt, toChars, clampCursor, fuzzyRank } from "./utils/text.js";
37
+ import { useTerminalSize } from "./hooks/useTerminalSize.js";
38
+ import { ErrorBoundary } from "./components/ErrorBoundary.js";
39
+ import { enterAltScreen, exitWith, restoreScreen } from "../core/terminal.js";
40
+ import { loadHistory, appendHistory } from "../core/history.js";
41
+
42
+ /**
43
+ * Where unhandled rejections go. Writing to stderr while Ink owns the screen
44
+ * desyncs its frame tracker, so the app registers a sink that turns them into
45
+ * ordinary transcript warnings instead.
46
+ */
47
+ let rejectionSink: ((text: string) => void) | null = null;
48
+
49
+ const App = () => {
50
+ const app = useApp();
51
+ const config = getConfig();
52
+ // Re-render on window resize so the footer/menu re-layout immediately
53
+ // instead of waiting for the next keystroke.
54
+ const terminal = useTerminalSize();
55
+
56
+ /* ── Flow hooks ─────────────────────────────────────── */
57
+ /** Append a system line to the transcript (shared by every flow). */
58
+ const addMessage = useCallback((text: string) => {
59
+ setMessages((prev) => [...prev, { role: "system" as Role, text }]);
60
+ }, []);
61
+ const keysFlow = useKeysFlow(addMessage);
62
+ const agentPickFlow = useAgentPicker(addMessage);
63
+ const authFlow = useAuthFlow(addMessage);
64
+
65
+ // Route stray rejections into the transcript (see rejectionSink above).
66
+ useEffect(() => {
67
+ rejectionSink = addMessage;
68
+ return () => { rejectionSink = null; };
69
+ }, [addMessage]);
70
+
71
+ // Session id lives in a ref so command cases can read it without re-render
72
+ // dependency loops; resumeSession swaps it when loading past history.
73
+ const sessionIdRef = useRef("");
74
+ useEffect(() => {
75
+ sessionIdRef.current = randomUUID();
76
+ }, []);
77
+
78
+ const [messages, setMessages] = useState<ChatMessage[]>([]);
79
+ // <Static> writes each message once and never removes it. A transcript wipe
80
+ // (/clear, /compact, session resume) therefore needs a batch key that maps
81
+ // to a *fresh* Static; otherwise the old lines stay on screen.
82
+ const [transcriptKey, setTranscriptKey] = useState(0);
83
+ const resetTranscript = useCallback(() => {
84
+ setMessages([]);
85
+ setTranscriptKey((k) => k + 1);
86
+ }, []);
87
+ const loadHistoryMessages = useCallback(
88
+ (msgs: Array<{ role: string; content: string }>) => {
89
+ // Resuming swaps the whole transcript, so the static region must remount
90
+ // or the previous session's lines would remain on screen.
91
+ setTranscriptKey((k) => k + 1);
92
+ setMessages(msgs.map((m) => ({
93
+ role: m.role === "assistant" ? ("assistant" as Role) : ("user" as Role),
94
+ text: m.content,
95
+ })));
96
+ },
97
+ [],
98
+ );
99
+ const sessionPickFlow = useSessionPicker(addMessage, sessionIdRef, setMessages, loadHistoryMessages);
100
+
101
+ const [agentId, setAgentId] = useState(config.model ?? "master");
102
+ const permissionMode = getPermissionMode();
103
+ // Trust gate: check before the REPL is usable. If the folder is new, the
104
+ // overlay owns all input until the user accepts or declines; the trust store
105
+ // persists the answer so familiar folders start straight into the prompt.
106
+ const trustFolderPath = getWorkspaceRoot();
107
+ const [trust, setTrust] = useState(() => ({
108
+ pending: !isFolderTrusted(),
109
+ index: 0,
110
+ }));
111
+ // Launch folder for the footer. Collapse to ~/… relative to the monorepo
112
+ // root (walk up to the .git dir) — the project lives outside the OS home, so
113
+ // the OS-home rule alone would print the full C:\… absolute path. Display
114
+ // uses forward slashes even on Windows (Claude Code style).
115
+ const cwd = (() => {
116
+ const norm = (p: string) => p.split(sep).join("/");
117
+ const root = norm(getWorkspaceRoot());
118
+ const home = norm(homedir());
119
+ if (root === home || root.startsWith(home + "/")) {
120
+ return "~" + root.slice(home.length);
121
+ }
122
+ // Walk up from the workspace root to the nearest .git — that's our ~ anchor.
123
+ let anchor = root;
124
+ while (anchor && anchor !== dirname(anchor)) {
125
+ if (existsSync(join(anchor, ".git"))) break;
126
+ anchor = dirname(anchor);
127
+ }
128
+ return root === anchor || root.startsWith(anchor + "/")
129
+ ? "~" + root.slice(anchor.length)
130
+ : root;
131
+ })();
132
+ // Pending risky local op awaiting y/N approval
133
+ const [pendingOp, setPendingOp] = useState<PendingOp | null>(null);
134
+ const [input, setInputRaw] = useState("");
135
+ const [cursor, setCursor] = useState(0);
136
+ // Keep the caret inside the value on every edit path. This is an effect, not
137
+ // a side effect inside the updater: React may replay an updater (StrictMode,
138
+ // concurrent rendering), and a state write in there can run with a stale
139
+ // value and leave the caret drifting.
140
+ const setInput = useCallback<React.Dispatch<React.SetStateAction<string>>>((action) => {
141
+ setInputRaw(action);
142
+ }, []);
143
+ useEffect(() => {
144
+ setCursor((c) => clampCursor(c, input));
145
+ }, [input]);
146
+ const [streaming, setStreaming] = useState(false);
147
+ const [elapsed, setElapsed] = useState(0);
148
+ const [menuIndex, setMenuIndex] = useState(0);
149
+ // Input history recall (↑/↓ when the slash menu is closed)
150
+ // Prompt history survives restarts (~/.odysx/history.json).
151
+ const [history, setHistory] = useState<string[]>(() => loadHistory());
152
+ // Stable handle so the memoized submit / command path can append without
153
+ // taking a dependency on the history array (which would thrash the memos).
154
+ const appendHistoryRef = useRef(appendHistory);
155
+ const [historyIndex, setHistoryIndex] = useState(-1); // -1 = not browsing
156
+ const historyDraftRef = useRef(""); // what was typed before ↑ was pressed
157
+ // Ctrl+/ and Ctrl+R overlays. Ranked rows are computed here so keyRouter
158
+ // addresses exactly what ScreenLayout paints.
159
+ const [search, setSearch] = useState<{
160
+ mode: "commands" | "history" | null; query: string; index: number;
161
+ }>({ mode: null, query: "", index: 0 });
162
+ const commandRows = useMemo(
163
+ () => fuzzyRank(
164
+ SLASH_COMMANDS.map((c) => ({
165
+ key: `/${c.name}`, label: `/${c.name}${c.args ? ` ${c.args}` : ""}`, detail: c.description,
166
+ })),
167
+ search.query,
168
+ (r) => `${r.label} ${r.detail ?? ""}`,
169
+ ),
170
+ [search.query],
171
+ );
172
+ const historyRows = useMemo(
173
+ () => fuzzyRank(
174
+ history.map((h, i) => ({ key: `h${i}`, label: h })),
175
+ search.query,
176
+ (r) => r.label,
177
+ ),
178
+ [history, search.query],
179
+ );
180
+ // Live abort handle for the in-flight stream + one queued prompt.
181
+ const abortRef = useRef<AbortController | null>(null);
182
+ const queuedSubmitRef = useRef<string | null>(null);
183
+ // Per-session token accounting, filled from stream/chat responses.
184
+ const usageRef = useRef({ requests: 0, promptTokens: 0, completionTokens: 0 });
185
+ // Fresh transcript for memoized callbacks (sendTurn must see every turn).
186
+ const messagesRef = useRef<ChatMessage[]>([]);
187
+ useEffect(() => { messagesRef.current = messages; }, [messages]);
188
+
189
+ const authed = Boolean(config.apiKey || config.token);
190
+ // A bring-your-own external provider supplies its own key, so platform auth
191
+ // is not required to chat when one is active.
192
+ const externalActive = Boolean(getActiveProvider());
193
+ const agentName = agentPickFlow.agentNames.current.get(agentId) ?? agentId;
194
+
195
+ // Elapsed-seconds ticker while streaming
196
+ useEffect(() => {
197
+ if (!streaming) return;
198
+ setElapsed(0);
199
+ const iv = setInterval(() => setElapsed((s) => s + 1), 1000);
200
+ return () => clearInterval(iv);
201
+ }, [streaming]);
202
+
203
+ // Resolve the current agent's display name shortly after startup.
204
+ useEffect(() => {
205
+ if (!authed) return;
206
+ let alive = true;
207
+ import("../core/provider/index.js").then(async ({ apiCall }) => {
208
+ const res = await apiCall<Array<{ id?: string; agent_id?: string; name?: string }>>("/api/v1/agents");
209
+ if (!alive || !res.ok) return;
210
+ for (const a of res.data ?? []) {
211
+ const id = (a.id ?? a.agent_id ?? "") as string;
212
+ if (id && a.name) agentPickFlow.agentNames.current.set(id, a.name);
213
+ }
214
+ }).catch(() => { });
215
+ return () => { alive = false; };
216
+ }, [authed, agentPickFlow.agentNames]);
217
+
218
+ /* ── Local `odysx local ...` dispatch (non-gated ops + approvals) ── */
219
+ const runLocal = useCallback(async (cliArgs: string[]) => {
220
+ try {
221
+ // Import registers the command, then fetch it from the registry.
222
+ await import("../commands/local.js");
223
+ const { getAllCommands } = await import("../core/registry/index.js");
224
+ const entry = getAllCommands().get("local");
225
+ if (!entry) throw new Error("local command not registered");
226
+ const result = await entry.handler({}, { args: cliArgs });
227
+ // Keep the command output even on failure — see the same logic in
228
+ // runCommand.ts; a failed `local exec` still made sense to read.
229
+ const output =
230
+ typeof result.data === "string"
231
+ ? result.data
232
+ : result.data === undefined
233
+ ? ""
234
+ : JSON.stringify(result.data);
235
+ const body = [
236
+ result.error ? `✗ ${result.error}` : result.message,
237
+ output.trim(),
238
+ ].filter(Boolean).join("\n");
239
+ addMessage((body || "(no output)").slice(0, 1500));
240
+ } catch (err) {
241
+ addMessage(`✗ ${err instanceof Error ? err.message : String(err)}`);
242
+ }
243
+ }, [addMessage]);
244
+
245
+ /* ── Slash-menu state: opens whenever the word under the *caret* starts
246
+ * with "/" — not just at line start, so "/cmd" works mid-prompt too.
247
+ * Bare "/" lists ALL commands; typing letters after it filters them.
248
+ * A command only dispatches when it is the first token; text before it
249
+ * means the user is writing prose, so Enter sends instead. ── */
250
+ const { word: menuWordRaw, start: menuWordStart } = wordAt(input, cursor);
251
+ const menuWord = menuWordRaw.startsWith("/") ? menuWordRaw.slice(1) : null;
252
+ // menuWordStart is a code-point index; slice the code-point array, not the
253
+ // string (an emoji before the command is two UTF-16 units and would make
254
+ // the prefix look non-empty, so the menu never opened after "😀 /h").
255
+ const menuOpen =
256
+ menuWord !== null && toChars(input).slice(0, menuWordStart).join("").trim() === "";
257
+ const filteredCommands = menuOpen
258
+ ? SLASH_COMMANDS.filter((c) => c.name.startsWith(menuWord!.toLowerCase()))
259
+ : [];
260
+ const clampedMenuIndex = Math.min(menuIndex, Math.max(0, filteredCommands.length - 1));
261
+
262
+ /* ── Command context shared by all slash handlers ──── */
263
+ const requestExit = useCallback(() => {
264
+ // Stop an in-flight stream first: exiting with the HTTP body reader open
265
+ // leaves the server waiting on a socket nobody owns.
266
+ abortRef.current?.abort();
267
+ abortRef.current = null;
268
+ app.exit();
269
+ exitWith(0);
270
+ }, [app]);
271
+ const acceptTrust = useCallback(() => {
272
+ try {
273
+ rememberFolder();
274
+ setTrust((t) => ({ ...t, pending: false }));
275
+ addMessage(`✓ Trusted workspace — ${permissionMode} mode. Manage with /trust and /mode.`);
276
+ } catch (err) {
277
+ // A failed write must NOT unlock the UI: the trust store failing closed
278
+ // is what keeps an untrusted folder from being used by default.
279
+ addMessage(`✗ Could not save folder trust: ${err instanceof Error ? err.message : String(err)}`);
280
+ requestExit();
281
+ }
282
+ }, [addMessage, permissionMode, requestExit]);
283
+ const openAgentPicker = useCallback(
284
+ () => void agentPickFlow.openAgentPicker(agentId),
285
+ [agentPickFlow, agentId],
286
+ );
287
+ const cmdCtx: CommandCtx = {
288
+ addMessage,
289
+ setMessages,
290
+ sessionId: () => sessionIdRef.current,
291
+ agentId,
292
+ config: { apiKey: config.apiKey ?? undefined, token: config.token ?? undefined, apiUrl: config.apiUrl },
293
+ openAgentPicker,
294
+ setAgentId,
295
+ resumeSession: (sid) => void sessionPickFlow.resumeSession(sid),
296
+ openSessionPicker: () => void sessionPickFlow.openSessionPicker(),
297
+ openKeysPanel: keysFlow.openKeysPanel,
298
+ setPendingOp,
299
+ resetTranscript,
300
+ newSession: () => {
301
+ abortRef.current?.abort();
302
+ abortRef.current = null;
303
+ sessionIdRef.current = randomUUID();
304
+ usageRef.current = { requests: 0, promptTokens: 0, completionTokens: 0 };
305
+ resetTranscript();
306
+ addMessage(`✓ New session ${sessionIdRef.current.slice(0, 8)} — server conversation reset.`);
307
+ },
308
+ usageRef,
309
+ abortStream: () => abortRef.current?.abort(),
310
+ requestExit,
311
+ setAuthMode: authFlow.setAuthMode,
312
+ setAuthIndex: authFlow.setAuthIndex,
313
+ };
314
+ const runCommandFromShell = useCallback(
315
+ (raw: string) => runCommand(raw, cmdCtx, messages),
316
+ // cmdCtx is rebuilt each render by design — messages must stay fresh.
317
+ // eslint-disable-next-line react-hooks/exhaustive-deps
318
+ [cmdCtx, messages],
319
+ );
320
+
321
+ /* ── Chat turn: stream the reply with fallback + usage accounting ── */
322
+ const sendTurn = useCallback(async (text: string) => {
323
+ const controller = new AbortController();
324
+ abortRef.current = controller;
325
+
326
+ // Tokens can arrive dozens of times per second. Re-rendering Ink on each
327
+ // one is the main source of stream flicker, so buffer them and commit at
328
+ // ~30fps. The final flush in `finally` guarantees no text is lost.
329
+ let pending = "";
330
+ let timer: ReturnType<typeof setTimeout> | null = null;
331
+ const commit = (): void => {
332
+ if (!pending) return;
333
+ const chunk = pending;
334
+ pending = "";
335
+ setMessages((prev) => {
336
+ const next = [...prev];
337
+ const last = next[next.length - 1];
338
+ if (last && last.role === "assistant") {
339
+ next[next.length - 1] = { ...last, text: last.text + chunk };
340
+ } else {
341
+ next.push({ role: "assistant" as Role, text: chunk, agentName });
342
+ }
343
+ return next;
344
+ });
345
+ };
346
+ const appendAssistant = (token: string): void => {
347
+ if (!token) return;
348
+ pending += token;
349
+ if (timer) return;
350
+ timer = setTimeout(() => {
351
+ timer = null;
352
+ commit();
353
+ }, 33);
354
+ };
355
+ const flushAssistant = (): void => {
356
+ if (timer) {
357
+ clearTimeout(timer);
358
+ timer = null;
359
+ }
360
+ commit();
361
+ };
362
+
363
+ try {
364
+ usageRef.current.requests += 1;
365
+
366
+ // External provider active (config.provider set) → talk to it directly,
367
+ // bypassing the OdysX backend entirely (bring-your-own key).
368
+ const external = getActiveProvider();
369
+ if (external) {
370
+ // Read the transcript through a ref: sendTurn is memoized, so closing
371
+ // over `messages` would freeze the provider history at mount time
372
+ // (turn 2 onward would forget the conversation).
373
+ const history = messagesRef.current
374
+ .filter((m) => m.role === "user" || m.role === "assistant")
375
+ .map((m) => ({ role: m.role as "user" | "assistant", content: m.text }));
376
+ await streamExternalChat(
377
+ [...history, { role: "user", content: text }],
378
+ {
379
+ system:
380
+ `You are ${agentName}, the user's coding agent in the OdysX Codemind CLI. ` +
381
+ `Be concise and precise.`,
382
+ onToken: appendAssistant,
383
+ signal: controller.signal,
384
+ },
385
+ );
386
+ return;
387
+ }
388
+
389
+ await streamChat(
390
+ "/api/v1/llm/chat/stream",
391
+ { agent_id: agentId, message: text, session_id: sessionIdRef.current },
392
+ appendAssistant,
393
+ undefined,
394
+ controller.signal,
395
+ (u) => {
396
+ usageRef.current.promptTokens += u.promptTokens;
397
+ usageRef.current.completionTokens += u.completionTokens;
398
+ },
399
+ );
400
+ } catch (streamErr) {
401
+ const streamText = streamErr instanceof Error ? streamErr.message : String(streamErr);
402
+ // User pressed esc — the abort already stopped the stream; say so cleanly.
403
+ const aborted =
404
+ (streamErr instanceof Error && streamErr.name === "AbortError") || controller.signal.aborted;
405
+ if (aborted) {
406
+ flushAssistant(); // keep whatever arrived before the interrupt
407
+ addMessage("✋ interrupted");
408
+ return;
409
+ }
410
+ // The master agent doesn't support SSE — fall back to blocking /llm/chat.
411
+ if (/HTTP 400/.test(streamText) && /Streaming is not supported/i.test(streamText)) {
412
+ try {
413
+ const res = await apiCall<{
414
+ answer?: string;
415
+ usage?: { prompt_tokens?: number; completion_tokens?: number };
416
+ }>("/api/v1/llm/chat", {
417
+ method: "POST",
418
+ body: { agent_id: agentId, message: text, session_id: sessionIdRef.current },
419
+ signal: controller.signal,
420
+ });
421
+ if (!res.ok) throw new Error(res.error ?? `HTTP ${res.status}`);
422
+ usageRef.current.promptTokens += res.data?.usage?.prompt_tokens ?? 0;
423
+ usageRef.current.completionTokens += res.data?.usage?.completion_tokens ?? 0;
424
+ appendAssistant(res.data?.answer ?? "(empty reply)");
425
+ } catch (chatErr) {
426
+ addMessage(`Error: ${chatErr instanceof Error ? chatErr.message : String(chatErr)}`);
427
+ }
428
+ } else {
429
+ addMessage(`Error: ${streamText}`);
430
+ }
431
+ } finally {
432
+ // Commit any buffered tokens before the turn is marked finished.
433
+ flushAssistant();
434
+ abortRef.current = null;
435
+ setStreaming(false);
436
+ // Drain the queue: a prompt typed while this turn was running.
437
+ const queued = queuedSubmitRef.current;
438
+ if (queued) {
439
+ queuedSubmitRef.current = null;
440
+ void submitRef.current?.(queued);
441
+ }
442
+ }
443
+ }, [agentId, agentName, addMessage]);
444
+
445
+ /* Entry point for every submitted line — slash commands or chat. */
446
+ const submit = useCallback(
447
+ async (override?: string) => {
448
+ const msg = (override ?? input).trim();
449
+ setInput("");
450
+ setCursor(0);
451
+ if (!msg) return;
452
+ // A live (interactive) submit is blocked while a turn is streaming — but a
453
+ // queued drain always arrives via `override`, so it must bypass this guard.
454
+ // Without the override check the drained message hit the stale `streaming`
455
+ // closure in sendTurn's finally and was silently dropped.
456
+ if (!override && streaming) return;
457
+
458
+ if (msg.startsWith("/")) {
459
+ setHistory((h) => appendHistoryRef.current(h, msg));
460
+ setHistoryIndex(-1);
461
+ const keysSub = msg.slice(1).split(" ");
462
+ if (keysSub[0].toLowerCase() === "keys" && (keysSub[1] ?? "").toLowerCase() === "new") {
463
+ const name = keysSub.slice(2).join(" ").trim();
464
+ keysFlow.setKeys((k) => ({ ...k, mode: "create-name", draftName: name, createdKey: null }));
465
+ return;
466
+ }
467
+ runCommandFromShell(msg);
468
+ return;
469
+ }
470
+
471
+ if (!authed && !externalActive) {
472
+ addMessage("Not signed in — press Enter or type /signin to open the sign-in menu.");
473
+ // Land the user on the sign-in picker instead of a dead end: they can
474
+ // choose an existing key, manage keys, or cancel.
475
+ authFlow.setAuthIndex(0);
476
+ authFlow.setAuthMode("picker");
477
+ return;
478
+ }
479
+
480
+ // @file mentions — inline each referenced file as context before sending.
481
+ // Resolution is confined to the workspace, same as every local op, so a
482
+ // prompt can't exfiltrate files the CLI wouldn't let it read directly.
483
+ let effective = msg;
484
+ if (msg.includes("@")) {
485
+ const { readFileSync, existsSync } = await import("node:fs");
486
+ const { confinePath } = await import("../core/workspace/index.js");
487
+ const { effective: expanded, unreadable } = expandMentions(
488
+ msg,
489
+ (p) => {
490
+ const decision = confinePath(p);
491
+ if (!decision.ok || !decision.resolved) throw new Error("outside workspace");
492
+ return readFileSync(decision.resolved, "utf-8");
493
+ },
494
+ (p) => existsSync(p) && confinePath(p).ok,
495
+ );
496
+ for (const m of unreadable) addMessage(`⚠ could not read @${m} — outside workspace or missing; sending without it`);
497
+ effective = expanded;
498
+ }
499
+
500
+ setHistory((h) => appendHistoryRef.current(h, msg));
501
+ setHistoryIndex(-1);
502
+
503
+ setMessages((prev) => [...prev, { role: "user", text: msg }]);
504
+ setStreaming(true);
505
+ await sendTurn(effective);
506
+ },
507
+ [input, streaming, authed, runCommandFromShell, sendTurn, authFlow, keysFlow, addMessage],
508
+ );
509
+ // sendTurn's finally-block drains the queue through submit without a cycle.
510
+ const submitRef = useRef<typeof submit | null>(null);
511
+ submitRef.current = submit;
512
+
513
+ /* ── Keyboard handling — delegated to input/keyRouter.ts ── */
514
+ useInput((chunk, key) => {
515
+ handleKey(chunk, key, {
516
+ trust,
517
+ setTrust,
518
+ search,
519
+ setSearch,
520
+ commandRows,
521
+ historyRows,
522
+ trustFolder: acceptTrust,
523
+ pendingOp,
524
+ keys: keysFlow.keys,
525
+ sessionPick: sessionPickFlow.sessionPick,
526
+ agentPick: agentPickFlow.agentPick,
527
+ authMode: authFlow.authMode,
528
+ authIndex: authFlow.authIndex,
529
+ authBusy: authFlow.authBusy,
530
+ apiKeyDraft: authFlow.apiKeyDraft,
531
+ streaming,
532
+ input,
533
+ cursor,
534
+ history,
535
+ historyIndex,
536
+ menuOpen,
537
+ filteredCommands,
538
+ clampedMenuIndex,
539
+ menuWordLength: menuWord?.length ?? 0,
540
+
541
+ setMessages,
542
+ setPendingOp,
543
+ setKeys: keysFlow.setKeys,
544
+ openKeysPanel: keysFlow.openKeysPanel,
545
+ createKey: keysFlow.createKey,
546
+ revokeSelected: keysFlow.revokeSelected,
547
+ showUsage: keysFlow.showUsage,
548
+ selectKey: (row) => void keysFlow.selectKey(row),
549
+ resumeSession: sessionPickFlow.resumeSession,
550
+ setSessionPick: sessionPickFlow.setSessionPick,
551
+ setAgentId,
552
+ setAgentPick: agentPickFlow.setAgentPick,
553
+ setAuthMode: authFlow.setAuthMode,
554
+ setAuthIndex: authFlow.setAuthIndex,
555
+ setApiKeyDraft: authFlow.setApiKeyDraft,
556
+ submitApiKey: authFlow.submitApiKey,
557
+ runLocal,
558
+ submit,
559
+ setMenuIndex,
560
+ setInput,
561
+ setCursor,
562
+ setHistory,
563
+ setHistoryIndex,
564
+ historyDraftRef,
565
+ abortRef,
566
+ queuedSubmitRef,
567
+ runCommand: runCommandFromShell,
568
+ requestExit,
569
+ });
570
+ });
571
+
572
+ /* ── Render ─────────────────────────────────────────── */
573
+ return (
574
+ <ScreenLayout
575
+ key={transcriptKey}
576
+ messages={messages}
577
+ streaming={streaming}
578
+ elapsed={elapsed}
579
+ trust={{ ...trust, folder: trustFolderPath, mode: permissionMode }}
580
+ permissionMode={permissionMode}
581
+ search={search}
582
+ commandRows={commandRows}
583
+ historyRows={historyRows}
584
+ agentPick={agentPickFlow.agentPick}
585
+ authMode={authFlow.authMode}
586
+ authIndex={authFlow.authIndex}
587
+ authBusy={authFlow.authBusy}
588
+ apiKeyDraft={authFlow.apiKeyDraft}
589
+ sessionPick={sessionPickFlow.sessionPick}
590
+ pendingOp={pendingOp}
591
+ keys={keysFlow.keys}
592
+ menuOpen={menuOpen}
593
+ filteredCommands={filteredCommands}
594
+ clampedMenuIndex={clampedMenuIndex}
595
+ input={input}
596
+ cursor={cursor}
597
+ agentName={agentName}
598
+ model={config.model ?? ""}
599
+ authed={authed}
600
+ provider={getActiveProvider()?.name}
601
+ cwd={cwd}
602
+ rows={terminal.rows}
603
+ />
604
+ );
605
+ };
606
+
607
+ /* -----------------------------------------------------
608
+ * Render entry point
609
+ * ----------------------------------------------------- */
610
+ export const runApp = () => {
611
+ // Run the REPL in the terminal's alternate screen buffer: everything we
612
+ // render is hidden on exit and the tab continues exactly where the user
613
+ // left off — scrollback, prompts, prior commands all intact. This must be
614
+ // written BEFORE render(): raw stdout writes anywhere inside Ink's render
615
+ // lifecycle desync its frame tracker (the /clear freeze bug), but a write
616
+ // before Ink starts is safe. Signal handlers re-raise so Ctrl+C/kill
617
+ // actually terminates instead of leaving a live process on a restored screen.
618
+ enterAltScreen();
619
+
620
+ // A render-time throw must never strand the user on a half-painted alt
621
+ // screen with no way back: the boundary catches component crashes, and the
622
+ // process-level hook covers everything outside React (key handlers,
623
+ // promises) — restore first, then report.
624
+ process.on("uncaughtException", (err) => {
625
+ restoreScreen();
626
+ process.stderr.write(`\n${err.stack ?? err.message}\n`);
627
+ process.exit(1);
628
+ });
629
+ process.on("unhandledRejection", (reason) => {
630
+ // A stray rejection during a stream must be visible, not silent — but a
631
+ // raw stderr write would corrupt Ink's frame, so go through the transcript
632
+ // when the app is mounted and fall back to stderr only if it is not.
633
+ const text = `⚠ ${reason instanceof Error ? reason.message : String(reason)}`;
634
+ if (rejectionSink) rejectionSink(text);
635
+ else process.stderr.write(`\n${text}\n`);
636
+ });
637
+
638
+ render(
639
+ <ErrorBoundary>
640
+ <App />
641
+ </ErrorBoundary>,
642
+ { exitOnCtrlC: false },
643
+ );
644
+ };