@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,302 @@
1
+ /**
2
+ * Local execution commands — file read/write, shell exec, system access.
3
+ *
4
+ * All path-touching subcommands are confined to the workspace root
5
+ * (see core/workspace). Destructive ops additionally require the caller to
6
+ * pass --yes (the REPL's y/N prompt adds it after approval).
7
+ */
8
+ import {
9
+ readFileSync, writeFileSync, existsSync, readdirSync, mkdirSync,
10
+ statSync, unlinkSync, rmSync, renameSync,
11
+ } from "node:fs";
12
+ import { execFileSync, execSync } from "node:child_process";
13
+ import { dirname, join, relative } from "node:path";
14
+ import { registerCommand } from "../core/registry/index.js";
15
+ import type { CommandSchema, CommandResult } from "../core/schema/types.js";
16
+ import { getWorkspaceRoot, confinePath, checkCommand } from "../core/workspace/index.js";
17
+ import { decideLocal, getPermissionMode } from "../core/permissions/index.js";
18
+
19
+ const schema: CommandSchema = {
20
+ name: "local",
21
+ description: "Local execution — file, shell, and system access (scoped to workspace)",
22
+ aliases: ["l"],
23
+ options: [],
24
+ };
25
+
26
+ /** Resolve a user path inside the workspace or produce a refusal result. */
27
+ function scoped(target: string | undefined, fallback = "."): { abs?: string; refused?: CommandResult } {
28
+ const decision = confinePath(target ?? fallback);
29
+ if (!decision.ok || !decision.resolved) {
30
+ return { refused: { exitCode: 1, error: decision.error } };
31
+ }
32
+ return { abs: decision.resolved };
33
+ }
34
+
35
+ function handleRead(filePath: string, lines?: string): CommandResult {
36
+ const s = scoped(filePath);
37
+ if (s.refused) return s.refused;
38
+ const resolved = s.abs!;
39
+ if (!existsSync(resolved)) return { exitCode: 1, error: `File not found: ${resolved}` };
40
+
41
+ try {
42
+ const content = readFileSync(resolved, "utf-8");
43
+ if (lines) {
44
+ // `Number("")` is 0, so "5-" used to mean "slice(4, 0)" — an empty
45
+ // result printed as success. Parse explicitly and validate the range.
46
+ const match = /^(\d+)(?:-(\d*))?$/.exec(lines.trim());
47
+ const start = match ? Number(match[1]) : NaN;
48
+ const endRaw = match?.[2];
49
+ const end = endRaw === undefined || endRaw === "" ? undefined : Number(endRaw);
50
+ if (!match || !Number.isFinite(start) || start < 1) {
51
+ return { exitCode: 1, error: "Usage: --lines <start>-<end> (1-based)" };
52
+ }
53
+ if (end !== undefined && (!Number.isFinite(end) || end < start)) {
54
+ return { exitCode: 1, error: `Invalid line range: end (${endRaw}) is before start (${start})` };
55
+ }
56
+ const allLines = content.split("\n");
57
+ const stop = end ?? allLines.length;
58
+ const from = start - 1;
59
+ const sliced = allLines
60
+ .slice(from, stop)
61
+ .map((l: string, i: number) => `${start + i}: ${l}`);
62
+ return { exitCode: 0, data: sliced.join("\n"), formatted: true };
63
+ }
64
+ return { exitCode: 0, data: content, formatted: true };
65
+ } catch (err) {
66
+ return { exitCode: 1, error: `Cannot read: ${err instanceof Error ? err.message : err}` };
67
+ }
68
+ }
69
+
70
+ function handleWrite(filePath: string, content: string): CommandResult {
71
+ const s = scoped(filePath);
72
+ if (s.refused) return s.refused;
73
+ const resolved = s.abs!;
74
+ try {
75
+ const dir = dirname(resolved);
76
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
77
+ writeFileSync(resolved, content, "utf-8");
78
+ return { exitCode: 0, message: `Wrote ${resolved}` };
79
+ } catch (err) {
80
+ return { exitCode: 1, error: `Cannot write: ${err instanceof Error ? err.message : err}` };
81
+ }
82
+ }
83
+
84
+ function handleExec(command: string, timeout?: number): CommandResult {
85
+ // Safety denylist runs before any process spawns.
86
+ const gate = checkCommand(command);
87
+ if (!gate.ok) return { exitCode: 1, error: gate.error };
88
+ try {
89
+ const output = execSync(command, {
90
+ cwd: getWorkspaceRoot(),
91
+ timeout: (timeout ?? 30) * 1000,
92
+ encoding: "utf-8",
93
+ // 1 MB was below a chatty test suite's output; ENOBUFS then discarded
94
+ // the very output the user ran the command for.
95
+ maxBuffer: 32 * 1024 * 1024,
96
+ });
97
+ return { exitCode: 0, data: output, formatted: true };
98
+ } catch (err: unknown) {
99
+ const e = err as { stdout?: string; stderr?: string; status?: number | null; killed?: boolean; signal?: string };
100
+ // A timeout or spawn failure has no exit status; saying "exited with code
101
+ // undefined" hid both the reason and the output the command produced.
102
+ const reason = e.killed || e.signal
103
+ ? `Command timed out after ${timeout ?? 30}s`
104
+ : `Command exited with code ${e.status ?? "unknown"}`;
105
+ return {
106
+ exitCode: e.status ?? 1,
107
+ data: e.stdout ?? e.stderr ?? String(err),
108
+ error: reason,
109
+ formatted: true,
110
+ };
111
+ }
112
+ }
113
+
114
+ function handleLs(dirPath: string, showHidden: boolean): CommandResult {
115
+ const s = scoped(dirPath);
116
+ if (s.refused) return s.refused;
117
+ const resolved = s.abs!;
118
+ if (!existsSync(resolved)) return { exitCode: 1, error: `Directory not found: ${resolved}` };
119
+
120
+ try {
121
+ const entries = readdirSync(resolved, { withFileTypes: true });
122
+ const items = entries
123
+ .filter((e) => showHidden || !e.name.startsWith("."))
124
+ .map((e) => ({
125
+ name: e.name + (e.isDirectory() ? "/" : ""),
126
+ type: e.isDirectory() ? "dir" : "file",
127
+ }));
128
+ return { exitCode: 0, data: items };
129
+ } catch (err) {
130
+ return { exitCode: 1, error: `Cannot list: ${err instanceof Error ? err.message : err}` };
131
+ }
132
+ }
133
+
134
+ function handlePwd(): CommandResult {
135
+ return { exitCode: 0, data: getWorkspaceRoot(), formatted: true };
136
+ }
137
+
138
+ function handleDelete(target: string): CommandResult {
139
+ const s = scoped(target);
140
+ if (s.refused) return s.refused;
141
+ const resolved = s.abs!;
142
+ if (!existsSync(resolved)) return { exitCode: 1, error: `Not found: ${resolved}` };
143
+ // Refuse to delete the workspace root itself: every path is "inside" it, so
144
+ // a delete with no argument (or "." / "./") would otherwise wipe the tree.
145
+ const root = getWorkspaceRoot();
146
+ if (resolved === root) {
147
+ return { exitCode: 1, error: `Refused: cannot delete the workspace root (${root})` };
148
+ }
149
+ try {
150
+ const st = statSync(resolved);
151
+ if (st.isDirectory()) {
152
+ // rmSync is recursive+force in one call and never shells out, so paths
153
+ // containing quotes, spaces, or shell metacharacters are handled safely.
154
+ rmSync(resolved, { recursive: true, force: true });
155
+ return { exitCode: 0, message: `Deleted directory ${relative(root, resolved) || "."}` };
156
+ }
157
+ unlinkSync(resolved);
158
+ return { exitCode: 0, message: `Deleted ${relative(root, resolved)}` };
159
+ } catch (err) {
160
+ return { exitCode: 1, error: `Cannot delete: ${err instanceof Error ? err.message : err}` };
161
+ }
162
+ }
163
+
164
+ function handleMove(from: string, to: string): CommandResult {
165
+ if (!from || !to) return { exitCode: 1, error: "Usage: local move <from> <to>" };
166
+ const src = scoped(from);
167
+ if (src.refused) return src.refused;
168
+ const dst = scoped(to);
169
+ if (dst.refused) return dst.refused;
170
+ if (!existsSync(src.abs!)) return { exitCode: 1, error: `Not found: ${src.abs}` };
171
+ try {
172
+ const dir = dirname(dst.abs!);
173
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
174
+ renameSync(src.abs!, dst.abs!);
175
+ return { exitCode: 0, message: `Moved ${relative(getWorkspaceRoot(), src.abs!)} → ${relative(getWorkspaceRoot(), dst.abs!)}` };
176
+ } catch (err) {
177
+ return { exitCode: 1, error: `Cannot move: ${err instanceof Error ? err.message : err}` };
178
+ }
179
+ }
180
+
181
+ function handleWhich(command: string): CommandResult {
182
+ // execFile avoids interpolating the command name into a shell string.
183
+ const lookup = process.platform === "win32" ? ["where", [command]] : ["which", [command]];
184
+ try {
185
+ const output = execFileSync(lookup[0] as string, lookup[1] as string[], {
186
+ encoding: "utf-8",
187
+ stdio: ["pipe", "pipe", "pipe"],
188
+ });
189
+ return { exitCode: 0, data: output.trim(), formatted: true };
190
+ } catch {
191
+ return { exitCode: 1, error: `${command} not found in PATH` };
192
+ }
193
+ }
194
+
195
+ function parseArgs(args: string[]): Record<string, string> {
196
+ const result: Record<string, string> = {};
197
+ for (let i = 0; i < args.length; i++) {
198
+ const arg = args[i];
199
+ if (arg === "--path" || arg === "-p") result.path = args[++i];
200
+ else if (arg === "--command" || arg === "-c") result.command = args[++i];
201
+ else if (arg === "--content") result.content = args[++i];
202
+ else if (arg === "--cwd") result.cwd = args[++i];
203
+ else if (arg === "--yes" || arg === "-y") result.yes = "true";
204
+ else if (arg === "--timeout") result.timeout = args[++i];
205
+ else if (arg === "--lines") result.lines = args[++i];
206
+ else if (arg === "--hidden" || arg === "-a") result.hidden = "true";
207
+ else if (!arg.startsWith("-")) {
208
+ // Positional: first non-flag is the subcommand, then target, then the
209
+ // second path (used by `move`).
210
+ if (!result.sub) result.sub = arg;
211
+ else if (!result.target) result.target = arg;
212
+ else if (!result.moveTo) result.moveTo = arg;
213
+ }
214
+ }
215
+ return result;
216
+ }
217
+
218
+ /** Subcommands that mutate state. The mode decides whether they may run. */
219
+ const GATED = new Set(["write", "exec", "delete", "move"]);
220
+
221
+ /** Reconstruct the command a `guide` decision hands back to the user. */
222
+ const commandLine = (sub: string, parsed: Record<string, string>): string => {
223
+ const parts = ["odysx", "local", sub];
224
+ if (parsed.target) parts.push(parsed.target);
225
+ if (parsed.moveTo) parts.push(parsed.moveTo);
226
+ if (parsed.path && !parsed.target) parts.push(parsed.path);
227
+ if (parsed.command) parts.push("--command", JSON.stringify(parsed.command));
228
+ if (parsed.content !== undefined) parts.push("--content", JSON.stringify(parsed.content));
229
+ if (parsed.lines) parts.push("--lines", parsed.lines);
230
+ if (parsed.timeout) parts.push("--timeout", parsed.timeout);
231
+ if (parsed.hidden) parts.push("--hidden");
232
+ return parts.join(" ");
233
+ };
234
+
235
+ registerCommand(schema, async (_args, opts) => {
236
+ const parsed = parseArgs(opts.args as string[]);
237
+ const sub = parsed.sub ?? "pwd";
238
+ const approved = (opts as Record<string, unknown>).yes === true || parsed.yes === "true";
239
+ const mode = getPermissionMode();
240
+ const decision = decideLocal(sub, mode);
241
+
242
+ // The mode is consulted before --yes: neither the flag nor an approval from
243
+ // the REPL can override a mode that refuses or hands the command back.
244
+ if (GATED.has(sub)) {
245
+ if (decision === "refuse") {
246
+ return {
247
+ exitCode: 1,
248
+ error: `Refused: '${sub}' is not allowed in ${mode} mode. Switch with /mode or --mode.`,
249
+ };
250
+ }
251
+ if (decision === "guide") {
252
+ // Deliberately exit 0: nothing failed, the user was handed the command.
253
+ return {
254
+ exitCode: 0,
255
+ message: `[guide] nothing was run. To do it yourself:\n\n ${commandLine(sub, parsed)}\n`,
256
+ formatted: true,
257
+ };
258
+ }
259
+ // "allow" (auto mode writes) and "ask" (needs --yes) both land here.
260
+ const needsApproval = decision === "ask";
261
+ if (needsApproval && !approved) {
262
+ return {
263
+ exitCode: 1,
264
+ error: `Refused: '${sub}' requires approval in ${mode} mode. Re-run with --yes.`,
265
+ };
266
+ }
267
+ }
268
+
269
+ switch (sub) {
270
+ case "read": return handleRead(parsed.target ?? parsed.path ?? ".", parsed.lines);
271
+ case "write": {
272
+ if (!parsed.target) return { exitCode: 1, error: "Usage: local write <path> --content <text>" };
273
+ // Require --content explicitly. Defaulting to "" meant that forgetting
274
+ // the flag (or writing it last with no value) silently emptied an
275
+ // existing file — the most destructive possible reading of a typo.
276
+ if (parsed.content === undefined) {
277
+ return {
278
+ exitCode: 1,
279
+ error: "Refusing to write: --content is required (pass --content \"\" to write an empty file)",
280
+ };
281
+ }
282
+ return handleWrite(parsed.target, parsed.content);
283
+ }
284
+ case "exec": {
285
+ if (!parsed.command) return { exitCode: 1, error: "Usage: local exec --command <cmd>" };
286
+ return handleExec(parsed.command, parsed.timeout ? Number(parsed.timeout) : undefined);
287
+ }
288
+ case "delete": {
289
+ if (!parsed.target) return { exitCode: 1, error: "Usage: local delete <path>" };
290
+ return handleDelete(parsed.target);
291
+ }
292
+ case "move": return handleMove(parsed.target ?? "", parsed.moveTo ?? "");
293
+ case "ls": return handleLs(parsed.target ?? parsed.path ?? ".", parsed.hidden === "true");
294
+ case "pwd": return handlePwd();
295
+ case "which": {
296
+ if (!parsed.target) return { exitCode: 1, error: "Usage: local which <command>" };
297
+ return handleWhich(parsed.target);
298
+ }
299
+ default:
300
+ return { exitCode: 1, error: `Unknown subcommand '${sub}'. Try: read, write, exec, ls, pwd, delete, move, which` };
301
+ }
302
+ });
@@ -0,0 +1,74 @@
1
+ /**
2
+ * MCP server commands — list, register, discover tools.
3
+ */
4
+ import { registerCommand } from "../core/registry/index.js";
5
+ import { apiCall } from "../core/provider/index.js";
6
+ import type { CommandSchema, CommandResult } from "../core/schema/types.js";
7
+
8
+ const schema: CommandSchema = {
9
+ name: "mcp",
10
+ description: "Manage MCP servers and discover tools",
11
+ options: [],
12
+ };
13
+
14
+ function parseFlag(args: string[], flag: string): string | undefined {
15
+ const idx = args.indexOf(flag);
16
+ return idx !== -1 ? args[idx + 1] : undefined;
17
+ }
18
+
19
+ async function handleList(): Promise<CommandResult> {
20
+ const res = await apiCall("/api/v1/mcp-servers");
21
+ if (!res.ok) return { exitCode: 1, error: res.error };
22
+ return { exitCode: 0, data: res.data };
23
+ }
24
+
25
+ async function handleGet(serverId: string): Promise<CommandResult> {
26
+ if (!serverId) return { exitCode: 1, error: "Usage: mcp get <server-id>" };
27
+ const [serverRes, toolsRes] = await Promise.all([
28
+ apiCall(`/api/v1/mcp-servers/${serverId}`),
29
+ apiCall(`/api/v1/mcp-servers/${serverId}/tools`),
30
+ ]);
31
+ if (!serverRes.ok) return { exitCode: 1, error: serverRes.error };
32
+ return { exitCode: 0, data: { ...(serverRes.data as object), tools: toolsRes.ok ? toolsRes.data : [] } };
33
+ }
34
+
35
+ async function handleRegister(args: string[]): Promise<CommandResult> {
36
+ const name = parseFlag(args, "--name");
37
+ const url = parseFlag(args, "--url");
38
+ if (!name || !url) return { exitCode: 1, error: "Usage: mcp register --name <name> --url <url>" };
39
+
40
+ const res = await apiCall("/api/v1/mcp-servers", {
41
+ method: "POST",
42
+ body: { name, url, transport_type: parseFlag(args, "--transport") ?? "http" },
43
+ });
44
+ if (!res.ok) return { exitCode: 1, error: res.error };
45
+ return { exitCode: 0, data: res.data, message: `MCP server registered` };
46
+ }
47
+
48
+ async function handleTools(serverId: string): Promise<CommandResult> {
49
+ if (!serverId) return { exitCode: 1, error: "Usage: mcp tools <server-id>" };
50
+ const res = await apiCall(`/api/v1/mcp-servers/${serverId}/tools`);
51
+ if (!res.ok) return { exitCode: 1, error: res.error };
52
+ return { exitCode: 0, data: res.data };
53
+ }
54
+
55
+ async function handleDiscover(serverId: string): Promise<CommandResult> {
56
+ if (!serverId) return { exitCode: 1, error: "Usage: mcp discover <server-id>" };
57
+ const res = await apiCall(`/api/v1/mcp-servers/${serverId}/discover`, { method: "POST" });
58
+ if (!res.ok) return { exitCode: 1, error: res.error };
59
+ return { exitCode: 0, data: res.data };
60
+ }
61
+
62
+ registerCommand(schema, async (_args, opts) => {
63
+ const sub = opts.args[0] as string | undefined;
64
+ const rest = (opts.args as string[]).slice(1);
65
+
66
+ switch (sub) {
67
+ case "list": return handleList();
68
+ case "get": return handleGet(rest[0] ?? "");
69
+ case "register": return handleRegister(rest);
70
+ case "tools": return handleTools(rest[0] ?? "");
71
+ case "discover": return handleDiscover(rest[0] ?? "");
72
+ default: return handleList();
73
+ }
74
+ });
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Prompt template commands — list, get, resolve templates.
3
+ */
4
+ import { registerCommand } from "../core/registry/index.js";
5
+ import { apiCall, urlSegment } from "../core/provider/index.js";
6
+ import type { CommandSchema, CommandResult } from "../core/schema/types.js";
7
+
8
+ const schema: CommandSchema = {
9
+ name: "prompts",
10
+ description: "Browse and use prompt templates",
11
+ aliases: ["p"],
12
+ options: [],
13
+ };
14
+
15
+ async function handleList(): Promise<CommandResult> {
16
+ const res = await apiCall("/api/v1/prompt-templates");
17
+ if (!res.ok) return { exitCode: 1, error: res.error };
18
+ return { exitCode: 0, data: res.data };
19
+ }
20
+
21
+ async function handleGet(id: string): Promise<CommandResult> {
22
+ if (!id) return { exitCode: 1, error: "Usage: prompts get <id-or-slug>" };
23
+ let res = await apiCall(`/api/v1/prompt-templates/${urlSegment(id)}`);
24
+ if (!res.ok) res = await apiCall(`/api/v1/prompt-templates/slug/${urlSegment(id)}`);
25
+ if (!res.ok) return { exitCode: 1, error: res.error };
26
+ return { exitCode: 0, data: res.data };
27
+ }
28
+
29
+ async function handleResolve(id: string, varPairs: string): Promise<CommandResult> {
30
+ if (!id) return { exitCode: 1, error: "Usage: prompts resolve <id> --var key=val,..." };
31
+ const values: Record<string, string> = {};
32
+ if (varPairs) {
33
+ for (const pair of varPairs.split(",")) {
34
+ const [k, v] = pair.split("=");
35
+ if (k) values[k.trim()] = v?.trim() ?? "";
36
+ }
37
+ }
38
+ const res = await apiCall(`/api/v1/prompt-templates/${urlSegment(id)}/resolve`, {
39
+ method: "POST",
40
+ body: { values },
41
+ });
42
+ if (!res.ok) return { exitCode: 1, error: res.error };
43
+ return { exitCode: 0, data: res.data, formatted: true };
44
+ }
45
+
46
+ registerCommand(schema, async (_args, opts) => {
47
+ const sub = opts.args[0] as string | undefined;
48
+ const id = opts.args[1] as string | undefined;
49
+ const varFlag = (opts.args as string[]).includes("--var")
50
+ ? (opts.args as string[])[(opts.args as string[]).indexOf("--var") + 1]
51
+ : undefined;
52
+
53
+ switch (sub) {
54
+ case "get": return handleGet(id ?? "");
55
+ case "resolve": return handleResolve(id ?? "", varFlag ?? "");
56
+ default: return handleList();
57
+ }
58
+ });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Skills commands — browse marketplace, install, manage skills.
3
+ */
4
+ import { registerCommand } from "../core/registry/index.js";
5
+ import { apiCall, urlSegment } from "../core/provider/index.js";
6
+ import type { CommandSchema, CommandResult } from "../core/schema/types.js";
7
+
8
+ const schema: CommandSchema = {
9
+ name: "skills",
10
+ description: "Browse and manage agent skills",
11
+ aliases: ["s"],
12
+ options: [],
13
+ };
14
+
15
+ async function handleList(): Promise<CommandResult> {
16
+ const res = await apiCall("/api/v1/skills");
17
+ if (!res.ok) return { exitCode: 1, error: res.error };
18
+ return { exitCode: 0, data: res.data };
19
+ }
20
+
21
+ async function handleMarketplace(): Promise<CommandResult> {
22
+ const res = await apiCall("/api/v1/skills/marketplace");
23
+ if (!res.ok) return { exitCode: 1, error: res.error };
24
+ return { exitCode: 0, data: res.data };
25
+ }
26
+
27
+ async function handleGet(skillId: string): Promise<CommandResult> {
28
+ if (!skillId) return { exitCode: 1, error: "Usage: skills get <skill-id>" };
29
+ const res = await apiCall(`/api/v1/skills/${urlSegment(skillId)}`);
30
+ if (!res.ok) return { exitCode: 1, error: res.error };
31
+ return { exitCode: 0, data: res.data };
32
+ }
33
+
34
+ registerCommand(schema, async (_args, opts) => {
35
+ const sub = opts.args[0] as string | undefined;
36
+ const id = opts.args[1] as string | undefined;
37
+
38
+ switch (sub) {
39
+ case "marketplace": return handleMarketplace();
40
+ case "get": return handleGet(id ?? "");
41
+ default: return handleList();
42
+ }
43
+ });
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Auth — login, token persistence, API key validation.
3
+ */
4
+ import { apiCall } from "../provider/index.js";
5
+ import { getConfig, updateConfig, clearAuth } from "../config/index.js";
6
+ import type { CommandResult } from "../schema/types.js";
7
+
8
+ /** Login with username/password → JWT token */
9
+ export async function login(
10
+ username: string,
11
+ password: string,
12
+ apiUrl?: string,
13
+ ): Promise<CommandResult> {
14
+ if (apiUrl) updateConfig({ apiUrl });
15
+
16
+ const res = await apiCall<{
17
+ access_token: string;
18
+ token_type: string;
19
+ session_id: string;
20
+ user: { id: string; username: string; roles: string[] };
21
+ }>("/api/v1/auth/login", {
22
+ method: "POST",
23
+ body: { username, password },
24
+ });
25
+
26
+ if (!res.ok) {
27
+ return { exitCode: 1, error: res.error ?? "Login failed" };
28
+ }
29
+
30
+ // Validate before persisting anything. A proxy or IdP that answers 200 with
31
+ // an error body used to reach `res.data.user.username` (a TypeError) or,
32
+ // worse, store `token: undefined` — JSON drops the field, the CLI prints
33
+ // "Logged in as undefined", and every later request 401s.
34
+ const token = res.data?.access_token;
35
+ const name = res.data?.user?.username;
36
+ if (typeof token !== "string" || !token || typeof name !== "string" || !name) {
37
+ return {
38
+ exitCode: 1,
39
+ error: "Unexpected login response: no access token or username",
40
+ };
41
+ }
42
+
43
+ updateConfig({ token, username: name });
44
+
45
+ return {
46
+ exitCode: 0,
47
+ message: `Logged in as ${name}`,
48
+ };
49
+ }
50
+
51
+ /** Set API key directly */
52
+ export async function setApiKey(key: string): Promise<CommandResult> {
53
+ // Validate the key by calling /auth/me
54
+ updateConfig({ apiKey: key, token: null });
55
+
56
+ const res = await apiCall<{ kind: string; username: string }>("/api/v1/auth/me");
57
+ if (!res.ok) {
58
+ clearAuth();
59
+ return { exitCode: 1, error: `Invalid API key: ${res.error}` };
60
+ }
61
+
62
+ return {
63
+ exitCode: 0,
64
+ message: `API key authenticated as ${res.data?.username ?? "service"}`,
65
+ };
66
+ }
67
+
68
+ /** Logout — clear stored auth */
69
+ export function logout(): CommandResult {
70
+ clearAuth();
71
+ return { exitCode: 0, message: "Logged out" };
72
+ }
73
+
74
+ /** Show current auth status */
75
+ export function authStatus(): CommandResult {
76
+ const config = getConfig();
77
+ if (config.apiKey) {
78
+ return {
79
+ exitCode: 0,
80
+ data: {
81
+ type: "api-key",
82
+ keyPrefix: config.apiKey.slice(0, 8) + "...",
83
+ apiUrl: config.apiUrl,
84
+ },
85
+ };
86
+ }
87
+ if (config.token) {
88
+ return {
89
+ exitCode: 0,
90
+ data: {
91
+ type: "jwt",
92
+ username: config.username,
93
+ apiUrl: config.apiUrl,
94
+ },
95
+ };
96
+ }
97
+ return {
98
+ exitCode: 0,
99
+ message: "Not authenticated. Run `odysx login` or `odysx auth set-key`.",
100
+ };
101
+ }