@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
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @file mention handling for submitted prompts.
3
+ * `@path/to/file` tokens are replaced with inline content blocks (capped at
4
+ * 20KB per file) so the agent sees the file contents as context.
5
+ */
6
+ export interface MentionResult {
7
+ effective: string;
8
+ unreadable: string[]; // mentions we couldn't read (caller reports them)
9
+ }
10
+
11
+ const MAX_FILE_CHARS = 20_000;
12
+
13
+ /** Synchronous variant used by the REPL (node fs). */
14
+ export const expandMentions = (
15
+ msg: string,
16
+ readFileSync: (path: string, enc: "utf-8") => string,
17
+ existsSync: (path: string) => boolean,
18
+ ): MentionResult => {
19
+ const mentions = [...msg.matchAll(/(?:^|\s)@([^\s]+)/g)].map((m) => m[1]);
20
+ if (mentions.length === 0) return { effective: msg, unreadable: [] };
21
+
22
+ const blocks: string[] = [];
23
+ const unreadable: string[] = [];
24
+ for (const mention of mentions) {
25
+ try {
26
+ if (!existsSync(mention)) throw new Error("not found");
27
+ const content = readFileSync(mention, "utf-8");
28
+ blocks.push(`--- @${mention} ---\n${content.slice(0, MAX_FILE_CHARS)}\n`);
29
+ } catch {
30
+ unreadable.push(mention);
31
+ }
32
+ }
33
+ if (blocks.length === 0) return { effective: msg, unreadable };
34
+
35
+ const stripped = msg.replace(/(?:^|\s)@[^\s]+/g, (m) => (m.startsWith(" ") ? " " : "")).trim();
36
+ return {
37
+ effective: `${stripped || "Review the attached file(s)."}\n\n${blocks.join("\n")}`,
38
+ unreadable,
39
+ };
40
+ };
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Terminal-text hygiene: sanitization and display width.
3
+ *
4
+ * Two properties matter when rendering untrusted text (model output, file
5
+ * contents pulled in through @mentions, error messages from a remote server)
6
+ * into a terminal:
7
+ *
8
+ * 1. Escape sequences must never reach the terminal. A model reply
9
+ * containing `\x1b[2J` can clear the screen, `\x1b[?1049l` can drop the
10
+ * user out of the alternate buffer, and OSC 8/52 can rewrite the title or
11
+ * the clipboard. Ink has no sanitizer of its own.
12
+ * 2. Display width is not string length. Emoji and CJK glyphs occupy two
13
+ * columns; combining marks and zero-width joiners occupy none. Padding a
14
+ * table cell by `.length` misaligns every column after the first wide
15
+ * glyph, and a border drawn to a width computed in code units wraps.
16
+ */
17
+
18
+ /* ── Sanitization ───────────────────────────────────────────────────────── */
19
+
20
+ // CSI: ESC [ params intermediates final
21
+ // OSC: ESC ] … (BEL | ESC \) DCS/PM/APC: ESC P|^|_ … (ESC \)
22
+ // Plus single-character ESC sequences and the C1 range.
23
+ // eslint-disable-next-line no-control-regex
24
+ const ESCAPE_SEQUENCE = /\x1B(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[P^_][\s\S]*?\x1B\\|[@-Z\\-_])|\x9B[0-?]*[ -/]*[@-~]|\x07/g;
25
+
26
+ /**
27
+ * Strip control sequences that could alter terminal state.
28
+ *
29
+ * Newlines and tabs are preserved (they are layout, not control), and so are
30
+ * carriage returns *only* when asked — a lone CR can overwrite the current
31
+ * line, so it is normalized away by default.
32
+ */
33
+ export const sanitize = (text: string, keepNewlines = true): string => {
34
+ let out = text.replace(ESCAPE_SEQUENCE, "");
35
+ // Other C0 control characters that would corrupt the frame. \n (0x0A) and
36
+ // \t (0x09) stay; \r (0x0D) goes — a bare CR rewrites the current line.
37
+ out = out.replace(/[\x00-\x08\x0B-\x1F\x7F]/g, "");
38
+ if (!keepNewlines) out = out.replace(/\r?\n/g, " ");
39
+ return out;
40
+ };
41
+
42
+ /** True when the text contains something `sanitize` would remove. */
43
+ export const hasControlSequences = (text: string): boolean => ESCAPE_SEQUENCE.test(text);
44
+
45
+ /* ── Display width ──────────────────────────────────────────────────────── */
46
+
47
+ /**
48
+ * Code points that occupy two terminal columns.
49
+ *
50
+ * This covers the East Asian Wide/Fullwidth ranges and the emoji blocks. It is
51
+ * deliberately a table rather than a dependency: `string-width` pulls in a
52
+ * regex engine and this list only needs to be right for what agents emit.
53
+ */
54
+ const WIDE_RANGES: ReadonlyArray<readonly [number, number]> = [
55
+ [0x1100, 0x115f], // Hangul Jamo init
56
+ [0x2e80, 0x303e], // CJK radicals, Kangxi, CJK symbols/punctuation
57
+ [0x3041, 0x33ff], // Hiragana, Katakana, Bopomofo, Hangul compat, CJK compat
58
+ [0x3400, 0x4dbf], // CJK ext A
59
+ [0x4e00, 0x9fff], // CJK unified ideographs
60
+ [0xa000, 0xa4cf], // Yi
61
+ [0xac00, 0xd7a3], // Hangul syllables
62
+ [0xf900, 0xfaff], // CJK compat ideographs
63
+ [0xfe10, 0xfe19], // Vertical forms
64
+ [0xfe30, 0xfe6f], // CJK compat forms
65
+ [0xff00, 0xff60], // Fullwidth forms
66
+ [0xffe0, 0xffe6], // Fullwidth signs
67
+ // Emoji: the whole pictographic block, including transport (🚀 U+1F680),
68
+ // supplemental symbols (U+1F900), and symbols extended-A (U+1FA70).
69
+ [0x1f300, 0x1faff],
70
+ [0x1f650, 0x1f67f], // ornamental dingbats
71
+ [0x1f680, 0x1f6ff], // transport and map symbols
72
+ [0x20000, 0x3fffd], // CJK ext B+
73
+ ];
74
+
75
+ /** Zero-width code points: combining marks and joiners. */
76
+ const isZeroWidth = (cp: number): boolean =>
77
+ (cp >= 0x0300 && cp <= 0x036f) || // combining diacritics
78
+ (cp >= 0x200b && cp <= 0x200f) || // ZWSP/ZWNJ/ZWJ/LRM/RLM
79
+ cp === 0xfeff || // BOM / zero-width no-break space
80
+ (cp >= 0xfe00 && cp <= 0xfe0f) || // variation selectors
81
+ (cp >= 0x1f3fb && cp <= 0x1f3ff); // emoji skin-tone modifiers
82
+
83
+ /** Column width of a single code point. */
84
+ const codePointWidth = (cp: number): number => {
85
+ if (isZeroWidth(cp)) return 0;
86
+ for (const [lo, hi] of WIDE_RANGES) {
87
+ if (cp >= lo && cp <= hi) return 2;
88
+ }
89
+ return 1;
90
+ };
91
+
92
+ /** Terminal columns occupied by `text` (assumes no escape sequences). */
93
+ export const displayWidth = (text: string): number => {
94
+ let width = 0;
95
+ for (const ch of text) width += codePointWidth(ch.codePointAt(0) ?? 0);
96
+ return width;
97
+ };
98
+
99
+ /** Truncate to `max` columns, appending `…` when anything was dropped. */
100
+ export const truncateToWidth = (text: string, max: number, ellipsis = "…"): string => {
101
+ if (max <= 0) return "";
102
+ if (displayWidth(text) <= max) return text;
103
+ const budget = max - displayWidth(ellipsis);
104
+ let out = "";
105
+ let used = 0;
106
+ for (const ch of text) {
107
+ const w = codePointWidth(ch.codePointAt(0) ?? 0);
108
+ if (used + w > budget) break;
109
+ out += ch;
110
+ used += w;
111
+ }
112
+ return out + ellipsis;
113
+ };
114
+
115
+ /** Pad to exactly `columns` display columns (left/right/center). */
116
+ export const padToWidth = (
117
+ text: string,
118
+ columns: number,
119
+ align: "left" | "right" | "center" = "left",
120
+ fill = " ",
121
+ ): string => {
122
+ const gap = columns - displayWidth(text);
123
+ if (gap <= 0) return text;
124
+ if (align === "right") return fill.repeat(gap) + text;
125
+ if (align === "center") {
126
+ const left = Math.floor(gap / 2);
127
+ return fill.repeat(left) + text + fill.repeat(gap - left);
128
+ }
129
+ return text + fill.repeat(gap);
130
+ };
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Character-level helpers for the prompt editor.
3
+ *
4
+ * The REPL's input is a single line driven by raw key events, so cursor
5
+ * movement has to work on strings. Characters are iterated by code point to
6
+ * keep emoji intact when moving or deleting.
7
+ */
8
+
9
+ /** Split into grapheme-ish units: surrogate pairs stay together. */
10
+ export const toChars = (text: string): string[] => Array.from(text);
11
+
12
+ /** Clamp a cursor index to a string's length (in code points). */
13
+ export const clampCursor = (cursor: number, text: string): number => {
14
+ // Iterating counts code points without allocating an array; this runs on
15
+ // every keystroke, so the array form would be wasteful.
16
+ let length = 0;
17
+ for (const _ of text) length++; // eslint-disable-line no-unused-vars
18
+ return Math.max(0, Math.min(cursor, length));
19
+ };
20
+
21
+ /** Move the cursor right by `n` characters. */
22
+ export const moveRight = (text: string, cursor: number, n = 1): number =>
23
+ clampCursor(cursor + n, text);
24
+
25
+ /** Move the cursor left by `n` characters. */
26
+ export const moveLeft = (cursor: number, n = 1): number => Math.max(0, cursor - n);
27
+
28
+ /** Insert text at the cursor; returns the new value and cursor position. */
29
+ export const insertAt = (text: string, cursor: number, insert: string): { text: string; cursor: number } => {
30
+ const chars = toChars(text);
31
+ const at = clampCursor(cursor, text);
32
+ chars.splice(at, 0, ...toChars(insert));
33
+ return { text: chars.join(""), cursor: at + toChars(insert).length };
34
+ };
35
+
36
+ /** Delete the character before the cursor (backspace). */
37
+ export const deleteBefore = (text: string, cursor: number): { text: string; cursor: number } => {
38
+ const chars = toChars(text);
39
+ const at = clampCursor(cursor, text);
40
+ if (at === 0) return { text, cursor: 0 };
41
+ chars.splice(at - 1, 1);
42
+ return { text: chars.join(""), cursor: at - 1 };
43
+ };
44
+
45
+ /** Delete the character at the cursor (delete key). */
46
+ export const deleteAt = (text: string, cursor: number): { text: string; cursor: number } => {
47
+ const chars = toChars(text);
48
+ const at = clampCursor(cursor, text);
49
+ if (at >= chars.length) return { text, cursor: at };
50
+ chars.splice(at, 1);
51
+ return { text: chars.join(""), cursor: at };
52
+ };
53
+
54
+ /**
55
+ * Which token does the cursor sit in? Used by the slash menu so it opens for
56
+ * `/cmd` typed mid-prompt, not only at line start.
57
+ */
58
+ export const wordAt = (text: string, cursor: number): { word: string; start: number } => {
59
+ const chars = toChars(text);
60
+ let start = clampCursor(cursor, text);
61
+ while (start > 0 && !/\s/.test(chars[start - 1])) start--;
62
+ return { word: chars.slice(start, clampCursor(cursor, text)).join(""), start };
63
+ };
64
+
65
+ /**
66
+ * The whitespace-delimited token around the caret, as a half-open range.
67
+ *
68
+ * `wordAt` stops at the caret (it answers "what has been typed so far"), which
69
+ * is the wrong span for *replacing* a token: completing "/he|lp" needs the
70
+ * whole "/help", or the tail gets re-appended as if it were typed arguments.
71
+ */
72
+ export const wordBounds = (text: string, cursor: number): { start: number; end: number } => {
73
+ const chars = toChars(text);
74
+ const at = clampCursor(cursor, text);
75
+ let start = at;
76
+ while (start > 0 && !/\s/.test(chars[start - 1])) start--;
77
+ let end = at;
78
+ while (end < chars.length && !/\s/.test(chars[end])) end++;
79
+ return { start, end };
80
+ };
81
+
82
+ /* ── Fuzzy matching for the command palette / history search ───────────── */
83
+
84
+ /**
85
+ * Case-insensitive subsequence score, or -1 when `query` is not a subsequence
86
+ * of `text`. Contiguous and word-start matches score higher so `h` ranks
87
+ * `/help` above `/history`. Code points, not UTF-16 units, so an emoji in a
88
+ * history entry cannot desynchronise the match.
89
+ */
90
+ export const fuzzyScore = (text: string, query: string): number => {
91
+ const q = toChars(query.toLowerCase());
92
+ if (q.length === 0) return 0;
93
+ const t = toChars(text.toLowerCase());
94
+ let ti = 0;
95
+ let score = 0;
96
+ let streak = 0;
97
+ for (const needle of q) {
98
+ let found = -1;
99
+ for (let i = ti; i < t.length; i++) {
100
+ if (t[i] === needle) { found = i; break; }
101
+ }
102
+ if (found === -1) return -1;
103
+ const wordStart = found === 0 || /\s|\/|-/.test(t[found - 1]);
104
+ streak = found === ti ? streak + 1 : 0;
105
+ score += 10 + streak * 4 + (wordStart ? 6 : 0);
106
+ ti = found + 1;
107
+ }
108
+ // Shorter haystacks are better matches for the same query.
109
+ return score - Math.floor(t.length / 10);
110
+ };
111
+
112
+ /** Sort by descending score, keeping the original order on ties. */
113
+ export const fuzzyRank = <T>(items: T[], query: string, key: (item: T) => string): T[] => {
114
+ if (!query.trim()) return items;
115
+ return items
116
+ .map((item, index) => ({ item, index, score: fuzzyScore(key(item), query) }))
117
+ .filter((x) => x.score >= 0)
118
+ .sort((a, b) => b.score - a.score || a.index - b.index)
119
+ .map((x) => x.item);
120
+ };
121
+
122
+ /* ── Multiline navigation ──────────────────────────────────────────────── */
123
+ /*
124
+ * EVERY index here is a code-point index, matching `cursor` and `toChars`.
125
+ * The first implementation used `text.indexOf("\n")` / `text.length`, which
126
+ * are UTF-16 offsets: with an emoji earlier in the string the two spaces
127
+ * disagree, so Ctrl+A did nothing, Ctrl+U deleted the wrong range, and ↑/↓
128
+ * jumped to column 0. Convert once and index the array.
129
+ */
130
+
131
+ /** Index of the first character on the cursor's line. */
132
+ export const lineStart = (text: string, cursor: number): number => {
133
+ const chars = toChars(text);
134
+ let at = clampCursor(cursor, text);
135
+ while (at > 0 && chars[at - 1] !== "\n") at--;
136
+ return at;
137
+ };
138
+
139
+ /** Index of the line terminator (or end of text) after the cursor's line. */
140
+ export const lineEnd = (text: string, cursor: number): number => {
141
+ const chars = toChars(text);
142
+ let at = clampCursor(cursor, text);
143
+ while (at < chars.length && chars[at] !== "\n") at++;
144
+ return at;
145
+ };
146
+
147
+ /** True when the cursor's line is the first / last one. */
148
+ export const onFirstLine = (text: string, cursor: number): boolean =>
149
+ lineStart(text, cursor) === 0;
150
+ export const onLastLine = (text: string, cursor: number): boolean =>
151
+ lineEnd(text, cursor) === toChars(text).length;
152
+
153
+ /**
154
+ * Move the caret one line up (-1) or down (+1), keeping the column where it
155
+ * exists and clamping to the shorter line otherwise — the behavior every
156
+ * text editor has.
157
+ */
158
+ export const moveVertical = (text: string, cursor: number, dir: -1 | 1): number => {
159
+ const chars = toChars(text);
160
+ const at = clampCursor(cursor, text);
161
+ const column = at - lineStart(text, at);
162
+ if (dir < 0) {
163
+ const start = lineStart(text, at);
164
+ if (start === 0) return at;
165
+ const prevStart = lineStart(text, start - 1);
166
+ const prevEnd = start - 1; // the newline before the current line
167
+ return Math.min(prevStart + column, prevEnd);
168
+ }
169
+ const end = lineEnd(text, at);
170
+ if (end >= chars.length) return at;
171
+ const nextStart = end + 1;
172
+ const nextEnd = lineEnd(text, nextStart);
173
+ return Math.min(nextStart + column, nextEnd);
174
+ };
@@ -0,0 +1,127 @@
1
+ // Tests: slash-command dispatch is a table, and the menu never advertises a
2
+ // command that has no body (or hides one that exists).
3
+ import { describe, it } from "node:test";
4
+ import assert from "node:assert/strict";
5
+ import { runCommand, DISPATCHABLE_COMMANDS } from "../dist/ui/commands/runCommand.js";
6
+ import { SLASH_COMMANDS } from "../dist/ui/shared/types.js";
7
+
8
+ /** Minimal ctx that records what the command asked for. */
9
+ const makeCtx = () => {
10
+ const log = [];
11
+ const ctx = {
12
+ addMessage: (t) => log.push(["message", t]),
13
+ setMessages: () => {},
14
+ sessionId: () => "sess-1234",
15
+ agentId: "master",
16
+ config: { apiUrl: "http://localhost" },
17
+ openAgentPicker: () => log.push(["agentPicker"]),
18
+ setAgentId: (id) => log.push(["agent", id]),
19
+ resumeSession: (sid) => log.push(["resume", sid]),
20
+ openSessionPicker: () => log.push(["sessionPicker"]),
21
+ openKeysPanel: async () => log.push(["keys"]),
22
+ /** Export approval is asynchronous; a test must approve or the promise hangs. */
23
+ setPendingOp: (op) => {
24
+ log.push(["pendingOp", op]);
25
+ if (op?.onApproved) op.onApproved();
26
+ },
27
+ resetTranscript: () => log.push(["reset"]),
28
+ newSession: () => log.push(["newSession"]),
29
+ usageRef: { current: { requests: 0, promptTokens: 0, completionTokens: 0 } },
30
+ abortStream: () => log.push(["abort"]),
31
+ requestExit: () => log.push(["exit"]),
32
+ setAuthMode: (m) => log.push(["authMode", m]),
33
+ setAuthIndex: (i) => log.push(["authIndex", i]),
34
+ };
35
+ return { ctx, log };
36
+ };
37
+
38
+ describe("slash command surface", () => {
39
+ it("every menu entry has a body", () => {
40
+ for (const cmd of SLASH_COMMANDS) {
41
+ assert.ok(
42
+ DISPATCHABLE_COMMANDS.includes(cmd.name),
43
+ `/${cmd.name} is advertised in the menu but has no handler`,
44
+ );
45
+ }
46
+ });
47
+
48
+ it("hidden aliases resolve to a real command", () => {
49
+ // q/exit are aliases of quit; both must be dispatchable.
50
+ for (const alias of ["q", "exit"]) {
51
+ assert.ok(DISPATCHABLE_COMMANDS.includes(alias), `${alias} missing`);
52
+ }
53
+ });
54
+
55
+ it("an unknown command reports instead of throwing", () => {
56
+ const { ctx, log } = makeCtx();
57
+ runCommand("/definitely-not-a-command", ctx, []);
58
+ assert.equal(log.length, 1);
59
+ assert.match(log[0][1], /Unknown command/);
60
+ });
61
+
62
+ it("/new rotates the session", () => {
63
+ const { ctx, log } = makeCtx();
64
+ runCommand("/new", ctx, []);
65
+ assert.ok(log.some(([k]) => k === "newSession"));
66
+ });
67
+
68
+ it("/clear aborts the stream and remounts the transcript", () => {
69
+ const { ctx, log } = makeCtx();
70
+ runCommand("/clear", ctx, [{ role: "user", text: "hi" }]);
71
+ assert.ok(log.some(([k]) => k === "abort"));
72
+ assert.ok(log.some(([k]) => k === "reset"));
73
+ });
74
+
75
+ it("/clear on an empty transcript still confirms", () => {
76
+ const { ctx, log } = makeCtx();
77
+ runCommand("/clear", ctx, []);
78
+ assert.match(log.find(([k]) => k === "message")[1], /already empty/);
79
+ });
80
+
81
+ it("/agent without an argument opens the picker, with one switches", () => {
82
+ const a = makeCtx();
83
+ runCommand("/agent", a.ctx, []);
84
+ assert.ok(a.log.some(([k]) => k === "agentPicker"));
85
+
86
+ const b = makeCtx();
87
+ runCommand("/agent reviewer", b.ctx, []);
88
+ assert.deepEqual(b.log.find(([k]) => k === "agent"), ["agent", "reviewer"]);
89
+ });
90
+
91
+ it("/sessions <id> resumes directly; bare /sessions opens the picker", () => {
92
+ const a = makeCtx();
93
+ runCommand("/sessions abc123", a.ctx, []);
94
+ assert.deepEqual(a.log.find(([k]) => k === "resume"), ["resume", "abc123"]);
95
+
96
+ const b = makeCtx();
97
+ runCommand("/sessions", b.ctx, []);
98
+ assert.ok(b.log.some(([k]) => k === "sessionPicker"));
99
+ });
100
+
101
+ it("/signin opens the auth picker at the first row", () => {
102
+ const { ctx, log } = makeCtx();
103
+ runCommand("/signin", ctx, []);
104
+ assert.ok(log.some(([k, v]) => k === "authMode" && v === "picker"));
105
+ assert.ok(log.some(([k, v]) => k === "authIndex" && v === 0));
106
+ });
107
+
108
+ it("/quit and /q and /exit all exit", () => {
109
+ for (const name of ["quit", "q", "exit"]) {
110
+ const { ctx, log } = makeCtx();
111
+ runCommand(`/${name}`, ctx, []);
112
+ assert.ok(log.some(([k]) => k === "exit"), `/${name} did not exit`);
113
+ }
114
+ });
115
+
116
+ it("/model without an argument prints usage", () => {
117
+ const { ctx, log } = makeCtx();
118
+ runCommand("/model", ctx, []);
119
+ assert.match(log.find(([k]) => k === "message")[1], /Usage: \/model/);
120
+ });
121
+
122
+ it("command names are case-insensitive", () => {
123
+ const { ctx, log } = makeCtx();
124
+ runCommand("/HELP", ctx, []);
125
+ assert.match(log.find(([k]) => k === "message")[1], /Commands:/);
126
+ });
127
+ });
@@ -0,0 +1,123 @@
1
+ // Tests: config persistence.
2
+ //
3
+ // The config file holds credentials, so the two properties asserted here are
4
+ // security-relevant: an environment-supplied secret must never be written to
5
+ // disk by an unrelated update, and a write must not be able to leave a
6
+ // half-serialised file behind.
7
+ //
8
+ // Each case runs in a child process with HOME/USERPROFILE pointed at a
9
+ // scratch directory — the config path is resolved from homedir() once at
10
+ // module load, so it cannot be redirected in-process.
11
+ import { describe, it } from "node:test";
12
+ import assert from "node:assert/strict";
13
+ import { execFileSync, spawnSync } from "node:child_process";
14
+ import { existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync, mkdirSync } from "node:fs";
15
+ import { tmpdir } from "node:os";
16
+ import { join } from "node:path";
17
+
18
+ const MODULE_URL = new URL("../dist/core/config/index.js", import.meta.url).href;
19
+
20
+ /** Run a snippet against the built config module in an isolated home dir. */
21
+ const runInScratchHome = (body, { env = {}, seed } = {}) => {
22
+ const home = mkdtempSync(join(tmpdir(), "odysx-home-"));
23
+ try {
24
+ if (seed) {
25
+ mkdirSync(join(home, ".odysx"), { recursive: true });
26
+ writeFileSync(join(home, ".odysx", "config.json"), JSON.stringify(seed, null, 2));
27
+ }
28
+ const script = `
29
+ const mod = await import(${JSON.stringify(MODULE_URL)});
30
+ ${body}
31
+ `;
32
+ const out = execFileSync(process.execPath, ["--input-type=module", "-e", script], {
33
+ env: {
34
+ ...process.env,
35
+ HOME: home,
36
+ USERPROFILE: home,
37
+ // Isolate from the developer's real credentials.
38
+ ODYSX_API_KEY: "",
39
+ ODYSX_TOKEN: "",
40
+ ODYSX_API_URL: "",
41
+ ...env,
42
+ },
43
+ encoding: "utf-8",
44
+ });
45
+ const configPath = join(home, ".odysx", "config.json");
46
+ return {
47
+ stdout: out,
48
+ configPath,
49
+ written: existsSync(configPath) ? JSON.parse(readFileSync(configPath, "utf-8")) : null,
50
+ mode: existsSync(configPath) ? statSync(configPath).mode & 0o777 : null,
51
+ };
52
+ } finally {
53
+ rmSync(home, { recursive: true, force: true });
54
+ }
55
+ };
56
+
57
+ describe("config persistence", () => {
58
+ it("never writes an environment-provided key to disk", () => {
59
+ // The leak: getConfig() merges env values into the cached object, and any
60
+ // later updateConfig (a plain /model switch) serialised the whole thing.
61
+ const { written } = runInScratchHome(
62
+ `mod.updateConfig({ model: "gpt-x" });
63
+ process.stdout.write("ok");`,
64
+ { env: { ODYSX_API_KEY: "sk-super-secret", ODYSX_TOKEN: "jwt-secret" } },
65
+ );
66
+ assert.equal(written.model, "gpt-x", "the intended change is persisted");
67
+ assert.equal(written.apiKey, null, "the env key must not be written");
68
+ assert.equal(written.token, null, "the env token must not be written");
69
+ assert.ok(!JSON.stringify(written).includes("super-secret"));
70
+ });
71
+
72
+ it("keeps the environment value in the caller's view", () => {
73
+ const { stdout } = runInScratchHome(
74
+ `const c = mod.getConfig();
75
+ process.stdout.write(c.apiKey ?? "none");`,
76
+ { env: { ODYSX_API_KEY: "sk-env" } },
77
+ );
78
+ assert.equal(stdout, "sk-env", "env still overrides at runtime");
79
+ });
80
+
81
+ it("preserves a key that was already on disk", () => {
82
+ const { written } = runInScratchHome(
83
+ `mod.updateConfig({ provider: "openai" });`,
84
+ {
85
+ env: { ODYSX_API_KEY: "sk-env" },
86
+ seed: { apiUrl: "http://localhost:8000", apiKey: "sk-from-disk", provider: null },
87
+ },
88
+ );
89
+ // The env override must be discarded in favour of what was on disk, not
90
+ // dropped entirely (which would log the user out on an unrelated update).
91
+ assert.equal(written.apiKey, "sk-from-disk");
92
+ });
93
+
94
+ it("writes the config owner-only and atomically", () => {
95
+ const { mode, written } = runInScratchHome(`mod.updateConfig({ model: "m" });`);
96
+ assert.equal(written.model, "m");
97
+ assert.ok(mode !== null);
98
+ if (process.platform !== "win32") {
99
+ assert.equal(mode, 0o600, "credentials file must not be world-readable");
100
+ }
101
+ });
102
+
103
+ it("warns instead of silently reverting when the file is corrupt", () => {
104
+ // A silent fallback to defaults looks identical to "you were never signed
105
+ // in", which sends the user hunting for a login problem that isn't there.
106
+ const home = mkdtempSync(join(tmpdir(), "odysx-home-"));
107
+ try {
108
+ mkdirSync(join(home, ".odysx"), { recursive: true });
109
+ writeFileSync(join(home, ".odysx", "config.json"), "{ not json");
110
+ const res = spawnSync(
111
+ process.execPath,
112
+ ["--input-type=module", "-e",
113
+ `const mod = await import(${JSON.stringify(MODULE_URL)}); mod.getConfig();`],
114
+ { env: { ...process.env, HOME: home, USERPROFILE: home }, encoding: "utf-8" },
115
+ );
116
+ assert.equal(res.status, 0, "a corrupt file must not crash the CLI");
117
+ assert.match(res.stderr, /could not be read/);
118
+ assert.match(res.stderr, /config\.json/);
119
+ } finally {
120
+ rmSync(home, { recursive: true, force: true });
121
+ }
122
+ });
123
+ });
@@ -0,0 +1,42 @@
1
+ // Tests: prompt-history redaction.
2
+ //
3
+ // History is a plaintext file that outlives the session, so anything written
4
+ // there must not be a credential. Recall still has to be useful, so the
5
+ // command survives — only the value is replaced.
6
+ import { describe, it } from "node:test";
7
+ import assert from "node:assert/strict";
8
+ import { redact } from "../dist/core/history.js";
9
+
10
+ describe("redact", () => {
11
+ it("replaces a --content value", () => {
12
+ const out = redact("local write src/x.ts --content 'const secret = 1'");
13
+ assert.ok(!out.includes("const secret"));
14
+ assert.match(out, /--content\s+\[redacted\]/);
15
+ });
16
+
17
+ it("replaces an --api-key value", () => {
18
+ const out = redact("auth set-key --api-key abc123");
19
+ assert.ok(!out.includes("abc123"));
20
+ assert.match(out, /\[redacted\]/);
21
+ });
22
+
23
+ it("replaces a provider key wherever it appears", () => {
24
+ const out = redact("my key is sk-abcdefghijklmnopqrstuvwx");
25
+ assert.ok(!out.includes("sk-abcdefghijklmnop"));
26
+ });
27
+
28
+ it("replaces a Google API key", () => {
29
+ const out = redact("use AIzaSyA1234567890abcdefghijklmnopqrstu");
30
+ assert.ok(!out.includes("AIzaSy"));
31
+ });
32
+
33
+ it("leaves ordinary prompts untouched", () => {
34
+ const text = "refactor the parser and run the tests";
35
+ assert.equal(redact(text), text);
36
+ });
37
+
38
+ it("does not eat text after an unrelated flag", () => {
39
+ const out = redact("local read src/app.ts --lines 10-20");
40
+ assert.equal(out, "local read src/app.ts --lines 10-20");
41
+ });
42
+ });