@odysx/codemind 0.1.0 → 0.1.1

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 (226) hide show
  1. package/dist/core/provider/index.d.ts +52 -10
  2. package/dist/core/provider/index.js +99 -12
  3. package/package.json +6 -1
  4. package/dist/commands/agents.d.ts.map +0 -1
  5. package/dist/commands/agents.js.map +0 -1
  6. package/dist/commands/auth.d.ts.map +0 -1
  7. package/dist/commands/auth.js.map +0 -1
  8. package/dist/commands/chat.d.ts.map +0 -1
  9. package/dist/commands/chat.js.map +0 -1
  10. package/dist/commands/keys.d.ts.map +0 -1
  11. package/dist/commands/keys.js.map +0 -1
  12. package/dist/commands/local.d.ts.map +0 -1
  13. package/dist/commands/local.js.map +0 -1
  14. package/dist/commands/mcp.d.ts.map +0 -1
  15. package/dist/commands/mcp.js.map +0 -1
  16. package/dist/commands/prompts.d.ts.map +0 -1
  17. package/dist/commands/prompts.js.map +0 -1
  18. package/dist/commands/skills.d.ts.map +0 -1
  19. package/dist/commands/skills.js.map +0 -1
  20. package/dist/core/auth/index.d.ts.map +0 -1
  21. package/dist/core/auth/index.js.map +0 -1
  22. package/dist/core/config/index.d.ts.map +0 -1
  23. package/dist/core/config/index.js.map +0 -1
  24. package/dist/core/history.d.ts.map +0 -1
  25. package/dist/core/history.js.map +0 -1
  26. package/dist/core/markdown-renderer.d.ts.map +0 -1
  27. package/dist/core/markdown-renderer.js.map +0 -1
  28. package/dist/core/permissions/index.d.ts.map +0 -1
  29. package/dist/core/permissions/index.js.map +0 -1
  30. package/dist/core/provider/external.d.ts.map +0 -1
  31. package/dist/core/provider/external.js.map +0 -1
  32. package/dist/core/provider/index.d.ts.map +0 -1
  33. package/dist/core/provider/index.js.map +0 -1
  34. package/dist/core/registry/index.d.ts.map +0 -1
  35. package/dist/core/registry/index.js.map +0 -1
  36. package/dist/core/schema/types.d.ts.map +0 -1
  37. package/dist/core/schema/types.js.map +0 -1
  38. package/dist/core/terminal.d.ts.map +0 -1
  39. package/dist/core/terminal.js.map +0 -1
  40. package/dist/core/workspace/index.d.ts.map +0 -1
  41. package/dist/core/workspace/index.js.map +0 -1
  42. package/dist/index.d.ts.map +0 -1
  43. package/dist/index.js.map +0 -1
  44. package/dist/ui/app.d.ts.map +0 -1
  45. package/dist/ui/app.js.map +0 -1
  46. package/dist/ui/commands/cases/catalog.d.ts.map +0 -1
  47. package/dist/ui/commands/cases/catalog.js.map +0 -1
  48. package/dist/ui/commands/cases/misc.d.ts.map +0 -1
  49. package/dist/ui/commands/cases/misc.js.map +0 -1
  50. package/dist/ui/commands/cases/tasks.d.ts.map +0 -1
  51. package/dist/ui/commands/cases/tasks.js.map +0 -1
  52. package/dist/ui/commands/runCommand.d.ts.map +0 -1
  53. package/dist/ui/commands/runCommand.js.map +0 -1
  54. package/dist/ui/components/AgentPicker.d.ts.map +0 -1
  55. package/dist/ui/components/AgentPicker.js.map +0 -1
  56. package/dist/ui/components/AuthPicker.d.ts.map +0 -1
  57. package/dist/ui/components/AuthPicker.js.map +0 -1
  58. package/dist/ui/components/Banner.d.ts.map +0 -1
  59. package/dist/ui/components/Banner.js.map +0 -1
  60. package/dist/ui/components/CommandMenu.d.ts.map +0 -1
  61. package/dist/ui/components/CommandMenu.js.map +0 -1
  62. package/dist/ui/components/ErrorBoundary.d.ts.map +0 -1
  63. package/dist/ui/components/ErrorBoundary.js.map +0 -1
  64. package/dist/ui/components/InputBar.d.ts.map +0 -1
  65. package/dist/ui/components/InputBar.js.map +0 -1
  66. package/dist/ui/components/KeysPanel.d.ts.map +0 -1
  67. package/dist/ui/components/KeysPanel.js.map +0 -1
  68. package/dist/ui/components/MessageView.d.ts.map +0 -1
  69. package/dist/ui/components/MessageView.js.map +0 -1
  70. package/dist/ui/components/PermissionPrompt.d.ts.map +0 -1
  71. package/dist/ui/components/PermissionPrompt.js.map +0 -1
  72. package/dist/ui/components/Pickers.d.ts.map +0 -1
  73. package/dist/ui/components/Pickers.js.map +0 -1
  74. package/dist/ui/components/SearchOverlay.d.ts.map +0 -1
  75. package/dist/ui/components/SearchOverlay.js.map +0 -1
  76. package/dist/ui/components/SessionPicker.d.ts.map +0 -1
  77. package/dist/ui/components/SessionPicker.js.map +0 -1
  78. package/dist/ui/components/WorkingIndicator.d.ts.map +0 -1
  79. package/dist/ui/components/WorkingIndicator.js.map +0 -1
  80. package/dist/ui/controls/ApiKeyEntry.d.ts.map +0 -1
  81. package/dist/ui/controls/ApiKeyEntry.js.map +0 -1
  82. package/dist/ui/controls/MultiSelect.d.ts.map +0 -1
  83. package/dist/ui/controls/MultiSelect.js.map +0 -1
  84. package/dist/ui/hooks/useAgentPicker.d.ts.map +0 -1
  85. package/dist/ui/hooks/useAgentPicker.js.map +0 -1
  86. package/dist/ui/hooks/useAuthFlow.d.ts.map +0 -1
  87. package/dist/ui/hooks/useAuthFlow.js.map +0 -1
  88. package/dist/ui/hooks/useKeysFlow.d.ts.map +0 -1
  89. package/dist/ui/hooks/useKeysFlow.js.map +0 -1
  90. package/dist/ui/hooks/useSessionPicker.d.ts.map +0 -1
  91. package/dist/ui/hooks/useSessionPicker.js.map +0 -1
  92. package/dist/ui/hooks/useTerminalSize.d.ts.map +0 -1
  93. package/dist/ui/hooks/useTerminalSize.js.map +0 -1
  94. package/dist/ui/input/keyRouter.d.ts.map +0 -1
  95. package/dist/ui/input/keyRouter.js.map +0 -1
  96. package/dist/ui/layouts/ScreenLayout.d.ts.map +0 -1
  97. package/dist/ui/layouts/ScreenLayout.js.map +0 -1
  98. package/dist/ui/shared/types.d.ts.map +0 -1
  99. package/dist/ui/shared/types.js.map +0 -1
  100. package/dist/ui/theme.d.ts.map +0 -1
  101. package/dist/ui/theme.js.map +0 -1
  102. package/dist/ui/utils/markdown.d.ts.map +0 -1
  103. package/dist/ui/utils/markdown.js.map +0 -1
  104. package/dist/ui/utils/mentions.d.ts.map +0 -1
  105. package/dist/ui/utils/mentions.js.map +0 -1
  106. package/dist/ui/utils/terminal-text.d.ts.map +0 -1
  107. package/dist/ui/utils/terminal-text.js.map +0 -1
  108. package/dist/ui/utils/text.d.ts.map +0 -1
  109. package/dist/ui/utils/text.js.map +0 -1
  110. package/eslint.config.js +0 -40
  111. package/graphify-out/GRAPH_REPORT.md +0 -140
  112. package/graphify-out/cache/1236b1806943f8eb5c64fece9fb448149370f4a1b52b32f0977ad528d7911291.json +0 -1
  113. package/graphify-out/cache/15cbf641dcc0fd641c18da872214918203a1f64baa7ac8430e4702ef32d18b02.json +0 -1
  114. package/graphify-out/cache/1abc52745bb46f6cc5a528530e2bc1f368c26e348dff85cdde5cad6f275d7177.json +0 -1
  115. package/graphify-out/cache/1c7815c37c13177e98895e272285f6151a8d0807478fc843ec452634b3e9912d.json +0 -1
  116. package/graphify-out/cache/1ec38c39f044f329c78642b61d6394fb8e15d0014335f32947d1f5c7b88c02bc.json +0 -1
  117. package/graphify-out/cache/20c9b57ff76dbb9d57cbd00659b0a42d2b28dd2abacf1ef4143cc67a5b6fe7f4.json +0 -1
  118. package/graphify-out/cache/285e11876884eb619e779d540cd957b33e70f14c67ecc26c9b9755aa9cedd717.json +0 -1
  119. package/graphify-out/cache/2c0a9c49ab51f4e0f07543b4e941bf802b7db31fa607c4cee8e595575be68fe7.json +0 -1
  120. package/graphify-out/cache/3025e6c2756c79ccaadd51d611f25a8b6630a6a11ce1b4e6e261b3e033dc194f.json +0 -1
  121. package/graphify-out/cache/4801a686ddfa0a52824a4fc3d65443cbb0ab9f0b030af67d02fccb520c584a08.json +0 -1
  122. package/graphify-out/cache/4f8fd96f38aa7d0293b4fab60c4581c4f3e68f4533c664c9cd78d1c53bea1cba.json +0 -1
  123. package/graphify-out/cache/5928e562b0f5700184b810e2403f4aa685e2b93c3c584c10460562b514c40fdd.json +0 -1
  124. package/graphify-out/cache/66132486efb0a4cfaeea766448f1f15bb33635808714052e7e24e5b00fbc984f.json +0 -1
  125. package/graphify-out/cache/66ab27669e7ec685130063662af9f30018c267f7639b4af4b0504a98282c383a.json +0 -1
  126. package/graphify-out/cache/6ff6b3dd433b5ffe96e166263a203dd622397e419dc00bb676824988b7defeab.json +0 -1
  127. package/graphify-out/cache/7a00a49932177a6215e2590b1ddfd6f1d8494792f693068e9d427d16b165d370.json +0 -1
  128. package/graphify-out/cache/7b681bc5182f40f707f1c0b16b78af38efffa62a1df315d10878f4de888408ef.json +0 -1
  129. package/graphify-out/cache/81196d44e50ac0b276d826a531ed10c425a528b298e3fe18e8d5a3eec996e9d5.json +0 -1
  130. package/graphify-out/cache/8934e9b32dea6e66fdc34fa1681b287ff1335c389917e0fc6ee2fc573e23e87b.json +0 -1
  131. package/graphify-out/cache/975f6c99807f86b79c80ca40c783618e2080a927eaebe6ea3db37b869f048851.json +0 -1
  132. package/graphify-out/cache/9ab98f08626fd8190462595e38de828293ad184db8df5e1177b05a8fe290faa1.json +0 -1
  133. package/graphify-out/cache/9c434a6796d7932b6e87a908c155c09cb2b8d097fc55f141f0302b6600f94749.json +0 -1
  134. package/graphify-out/cache/ac5cf4c489dc417c1f6ea728d0b6ba12ac7087bc6c2e736697ff3024b4d4e534.json +0 -1
  135. package/graphify-out/cache/ae5083b5c1dca3e5c6af485e7f6eb8a08ff8b382cdecf92ab5e0902053442afe.json +0 -1
  136. package/graphify-out/cache/b274057fc2e0118cf2746d1d8060841122bb2a2b0305566fc3f32d3a51e08bcc.json +0 -1
  137. package/graphify-out/cache/b39beef31da682387f030c0d149f6cd5b3e66effbf936cc8430db15360759dda.json +0 -1
  138. package/graphify-out/cache/bf3c6a36bb72820bc11cbf4a5c49067d1f62013d4686c019a4dbd9951b1e980e.json +0 -1
  139. package/graphify-out/cache/c034e156028d1a58b89bce659726e9a4065ddc4d2b560d6bce7a206fdff8dad3.json +0 -1
  140. package/graphify-out/cache/c619b5bbe8d1f427fbd7816d1e9fcfaf90d7201b020ae6b578166aeb9cb20683.json +0 -1
  141. package/graphify-out/cache/c8db77a9da0b0f601acfa50a620f31155cdda0d0cc0f2285adcea19e77194ee6.json +0 -1
  142. package/graphify-out/cache/ca664791ec7741a2077d9e7c10384142d30e7a3b77b388df719c315da608d57d.json +0 -1
  143. package/graphify-out/cache/cba43a116186bd55c8a63368dea4eee4a8123b2bec0a42df6efb3254f89f9a7a.json +0 -1
  144. package/graphify-out/cache/cd51cbb3dad1cf34417b9761fe2eb184a9f57d23dc86e45630e63bfa2ecafddc.json +0 -1
  145. package/graphify-out/cache/d06738cde193b34a136b94104220c17e0212b814b3e4d7ff399105635cae1a03.json +0 -1
  146. package/graphify-out/cache/d093c19f0169c0398eeb1360895b1c16ecc50abc59f4be8eec3f6fd27c89a6e5.json +0 -1
  147. package/graphify-out/cache/da8f75c438531d232fe114d5cbf2374576ce842a5fb87c7e5a88b78fdb334e5e.json +0 -1
  148. package/graphify-out/cache/e35798fa04ddede548a6953bdea506bd7d0788dfed4e8a8ea6ae77b1b60ef5e0.json +0 -1
  149. package/graphify-out/cache/e5a38c254719000487098782125e15e2e982c07d66b99d359ed1781f30f9fc8c.json +0 -1
  150. package/graphify-out/cache/e6e4c4a5a7200ee0154585b5d6538f699b0a746dbded3164f8391f06ce7cb212.json +0 -1
  151. package/graphify-out/cache/ea8d0838df6309b673b031f616b253af957898ee7289d25a541fa6183b732e4e.json +0 -1
  152. package/graphify-out/cache/ebaee92b0e881efd7a08f3143e2c1803310396b4651d4f77532003c699cc6836.json +0 -1
  153. package/graphify-out/cache/edf8543318a9e60d56d04704078da6c37202ddd6fdfc83144fe2b94fe19b80ef.json +0 -1
  154. package/graphify-out/cache/efca19d3668035f11126fc9eccbeab290abfa94babf3f9a8706de81d17aba263.json +0 -1
  155. package/graphify-out/cache/f1480bb642025ebd6d99986cdd8a7d5726897ec038300e4b095c9c938435dfad.json +0 -1
  156. package/graphify-out/cache/f459f21277f03865f732affb175b1b092954dae5967f27b3cd1864466e3e24f4.json +0 -1
  157. package/graphify-out/cache/f899e37e864010b30f4c196e86082d7bd022a0df032005e0407883ebcec36514.json +0 -1
  158. package/graphify-out/cache/fb3cbe07fbcd97c536cff9c6bc343c35f22d49613f05c53ad30ef67a75c5d93e.json +0 -1
  159. package/graphify-out/cache/fd3dc682b1ca2f5ae03b50d6b0e045ae50f5701c0a21c5a388d77ef482939d3a.json +0 -1
  160. package/graphify-out/graph.html +0 -257
  161. package/graphify-out/graph.json +0 -4396
  162. package/scripts/e2e-external.mjs +0 -65
  163. package/scripts/live-agents.mjs +0 -6
  164. package/scripts/live-stream.mjs +0 -51
  165. package/src/commands/agents.ts +0 -91
  166. package/src/commands/auth.ts +0 -39
  167. package/src/commands/chat.ts +0 -198
  168. package/src/commands/keys.ts +0 -83
  169. package/src/commands/local.ts +0 -302
  170. package/src/commands/mcp.ts +0 -74
  171. package/src/commands/prompts.ts +0 -58
  172. package/src/commands/skills.ts +0 -43
  173. package/src/core/auth/index.ts +0 -101
  174. package/src/core/config/index.ts +0 -152
  175. package/src/core/history.ts +0 -79
  176. package/src/core/markdown-renderer.ts +0 -420
  177. package/src/core/permissions/index.ts +0 -99
  178. package/src/core/provider/external.ts +0 -312
  179. package/src/core/provider/index.ts +0 -517
  180. package/src/core/registry/index.ts +0 -250
  181. package/src/core/schema/types.ts +0 -106
  182. package/src/core/terminal.ts +0 -124
  183. package/src/core/workspace/index.ts +0 -216
  184. package/src/index.ts +0 -401
  185. package/src/ui/app.tsx +0 -644
  186. package/src/ui/commands/cases/catalog.ts +0 -76
  187. package/src/ui/commands/cases/misc.ts +0 -293
  188. package/src/ui/commands/cases/tasks.ts +0 -115
  189. package/src/ui/commands/runCommand.ts +0 -178
  190. package/src/ui/components/Banner.tsx +0 -63
  191. package/src/ui/components/CommandMenu.tsx +0 -63
  192. package/src/ui/components/ErrorBoundary.tsx +0 -75
  193. package/src/ui/components/InputBar.tsx +0 -227
  194. package/src/ui/components/KeysPanel.tsx +0 -115
  195. package/src/ui/components/MessageView.tsx +0 -226
  196. package/src/ui/components/Pickers.tsx +0 -234
  197. package/src/ui/components/SearchOverlay.tsx +0 -65
  198. package/src/ui/components/WorkingIndicator.tsx +0 -35
  199. package/src/ui/controls/ApiKeyEntry.tsx +0 -29
  200. package/src/ui/controls/MultiSelect.tsx +0 -55
  201. package/src/ui/hooks/useAgentPicker.ts +0 -64
  202. package/src/ui/hooks/useAuthFlow.ts +0 -47
  203. package/src/ui/hooks/useKeysFlow.ts +0 -157
  204. package/src/ui/hooks/useSessionPicker.ts +0 -84
  205. package/src/ui/hooks/useTerminalSize.ts +0 -36
  206. package/src/ui/input/keyRouter.ts +0 -627
  207. package/src/ui/layouts/ScreenLayout.tsx +0 -202
  208. package/src/ui/shared/types.ts +0 -160
  209. package/src/ui/theme.ts +0 -53
  210. package/src/ui/utils/markdown.ts +0 -255
  211. package/src/ui/utils/mentions.ts +0 -40
  212. package/src/ui/utils/terminal-text.ts +0 -130
  213. package/src/ui/utils/text.ts +0 -174
  214. package/test/commands.test.mjs +0 -127
  215. package/test/config.test.mjs +0 -123
  216. package/test/history.test.mjs +0 -42
  217. package/test/keyrouter.test.mjs +0 -324
  218. package/test/layout.test.mjs +0 -271
  219. package/test/markdown.test.mjs +0 -92
  220. package/test/mentions.test.mjs +0 -51
  221. package/test/permissions.test.mjs +0 -130
  222. package/test/provider.test.mjs +0 -287
  223. package/test/terminal-text.test.mjs +0 -116
  224. package/test/text.test.mjs +0 -134
  225. package/test/workspace.test.mjs +0 -101
  226. package/tsconfig.json +0 -32
@@ -1,250 +0,0 @@
1
- /**
2
- * Command registry — builds commander.js program from command schemas.
3
- *
4
- * Each command group (agents, chat, skills, etc.) registers a schema + handler.
5
- * The registry builds the CLI tree. Subcommand routing is handled by each
6
- * command's own handler (not auto-wired).
7
- */
8
- import { Command } from "commander";
9
- import type { CommandSchema, CommandHandler } from "../schema/types.js";
10
- import { exitWith } from "../terminal.js";
11
-
12
- interface RegisteredCommand {
13
- schema: CommandSchema;
14
- handler: CommandHandler;
15
- }
16
-
17
- const registry = new Map<string, RegisteredCommand>();
18
-
19
- /** Options extended by commander (includes args array) */
20
- export interface CliOptions extends Record<string, unknown> {
21
- args: string[];
22
- }
23
-
24
- /** Register a command schema + handler */
25
- export function registerCommand(schema: CommandSchema, handler: CommandHandler): void {
26
- registry.set(schema.name, { schema, handler });
27
- }
28
-
29
- /** Get all registered commands */
30
- export function getAllCommands(): Map<string, RegisteredCommand> {
31
- return new Map(registry);
32
- }
33
-
34
- /** Build a commander.js Command from a CommandSchema */
35
- function buildCommand(registered: RegisteredCommand): Command {
36
- const { schema, handler } = registered;
37
- const cmd = new Command(schema.name).description(schema.description).allowExcessArguments(true).allowUnknownOption();
38
-
39
- if (schema.aliases) {
40
- for (const alias of schema.aliases) {
41
- cmd.alias(alias);
42
- }
43
- }
44
-
45
- if (schema.examples) {
46
- cmd.addHelpText("after", "\nExamples:");
47
- for (const ex of schema.examples) {
48
- cmd.addHelpText("after", ` $ ${ex}`);
49
- }
50
- }
51
-
52
- // Register options (skip positionals — commander handles them via .argument())
53
- const positionals = schema.options.filter((o) => o.positional).sort((a, b) => (a.position ?? 0) - (b.position ?? 0));
54
- const flags = schema.options.filter((o) => !o.positional);
55
-
56
- // Add positional arguments
57
- for (const pos of positionals) {
58
- const argStr = pos.required ? `<${pos.id}>` : `[${pos.id}]`;
59
- cmd.argument(argStr, pos.description);
60
- }
61
-
62
- // Add flags
63
- for (const opt of flags) {
64
- const flag = `--${camelToKebab(opt.id)}${opt.type === "boolean" ? "" : " <value>"}`;
65
- // Commander requires short flags to be a single character
66
- const validAlias = opt.alias && opt.alias.length === 1 ? opt.alias : undefined;
67
- const fullFlag = validAlias ? `-${validAlias}, ${flag}` : flag;
68
- if (opt.defaultValue !== undefined) {
69
- const defaultVal = opt.defaultValue;
70
- cmd.option(fullFlag, opt.description, (val: string) => {
71
- if (opt.type === "number") return Number(val);
72
- if (opt.type === "boolean") return val === "true";
73
- return val;
74
- }, defaultVal as string);
75
- } else {
76
- cmd.option(fullFlag, opt.description);
77
- }
78
- }
79
-
80
- // Action
81
- cmd.action(async (...cmdArgs: unknown[]) => {
82
- // commander passes positional args, then options object, then Command instance
83
- const cmdInstance = cmdArgs[cmdArgs.length - 1] as Command;
84
- const commanderOpts = cmdInstance.opts() as Record<string, unknown>;
85
-
86
- // Collect positional args into named keys
87
- const args: Record<string, unknown> = {};
88
- for (let i = 0; i < positionals.length; i++) {
89
- args[positionals[i].id] = cmdArgs[i];
90
- }
91
-
92
- // Merge commander opts with positional args
93
- const mergedOpts: CliOptions = { ...commanderOpts, args: cmdInstance.args } as CliOptions;
94
-
95
- try {
96
- const result = await handler(args, mergedOpts);
97
- let body = "";
98
- if (!result.formatted) {
99
- body = formatOutput(result, (commanderOpts.output as string) ?? schema.defaultOutput ?? "table");
100
- } else if (result.data !== undefined) {
101
- // Already formatted by handler — print data directly (usually a string)
102
- const dataText =
103
- typeof result.data === "string" ? result.data : JSON.stringify(result.data, null, 2);
104
- // A message can accompany formatted data (e.g. "save this key" next
105
- // to the key object). Dropping it lost the one warning that matters.
106
- body = result.message ? `${result.message}\n${dataText}` : dataText;
107
- } else {
108
- body = result.message ?? "";
109
- }
110
- if (body) console.log(body);
111
- if (result.error) {
112
- console.error(`Error: ${result.error}`);
113
- // `exitWith` is not actually `never`; without the return the call
114
- // below runs too, printing two exit paths and racing their timers.
115
- return exitWith(result.exitCode || 1);
116
- }
117
- return exitWith(result.exitCode);
118
- } catch (err) {
119
- console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
120
- exitWith(1);
121
- }
122
- });
123
-
124
- return cmd;
125
- }
126
-
127
- /** Build the root commander program from all registered commands */
128
- export function buildProgram(): Command {
129
- const program = new Command("odysx")
130
- .description("OdysX CLI — smart agents in your terminal")
131
- .version("0.1.0")
132
- // Global flags are parsed in index.ts before commander runs (and stripped
133
- // from argv), so they are documented here rather than registered as
134
- // options on every subcommand.
135
- .addHelpText(
136
- "after",
137
- "\nGlobal flags:" +
138
- "\n --legacy-repl Use the simple readline REPL instead of the full-screen UI" +
139
- "\n --no-color Disable colour (also honours NO_COLOR and piped output)" +
140
- "\n --color Force colour even when stdout is not a TTY" +
141
- "\n --mode <mode> Permission mode: plan | guide | manual | auto (default manual)",
142
- );
143
-
144
- for (const [, registered] of registry) {
145
- program.addCommand(buildCommand(registered));
146
- }
147
-
148
- return program;
149
- }
150
-
151
- /** Format command result based on output format */
152
- function formatOutput(
153
- result: { data?: unknown; message?: string },
154
- format: string,
155
- ): string {
156
- const message = result.message?.trim() ?? "";
157
- // `== null`, not `!result.data`: 0, "" and false are legitimate payloads.
158
- if (result.data === undefined || result.data === null) return message;
159
-
160
- const body = (() => {
161
- switch (format) {
162
- case "json":
163
- return JSON.stringify(result.data, null, 2);
164
- case "yaml":
165
- return toYaml(result.data);
166
- case "csv":
167
- return toCsv(result.data);
168
- case "table":
169
- default:
170
- return toTable(result.data);
171
- }
172
- })();
173
-
174
- return message ? `${message}\n${body}` : body;
175
- }
176
-
177
- function toYaml(data: unknown, indent = 0): string {
178
- const prefix = " ".repeat(indent);
179
- if (data === null || data === undefined) return `${prefix}null`;
180
- if (typeof data !== "object") return `${prefix}${JSON.stringify(data)}`;
181
- if (Array.isArray(data)) {
182
- if (data.length === 0) return `${prefix}[]`;
183
- return data.map((item) => {
184
- if (typeof item === "object" && item !== null && !Array.isArray(item)) {
185
- const entries = Object.entries(item as Record<string, unknown>);
186
- const [first, ...rest] = entries;
187
- let result = `${prefix}- ${first[0]}: ${JSON.stringify(first[1])}`;
188
- for (const [k, v] of rest) {
189
- result += `\n${prefix} ${k}: ${JSON.stringify(v)}`;
190
- }
191
- return result;
192
- }
193
- return `${prefix}- ${JSON.stringify(item)}`;
194
- }).join("\n");
195
- }
196
- const entries = Object.entries(data as Record<string, unknown>);
197
- if (entries.length === 0) return `${prefix}{}`;
198
- return entries.map(([k, v]) => `${prefix}${k}: ${typeof v === "object" ? "\n" + toYaml(v, indent + 1) : JSON.stringify(v)}`).join("\n");
199
- }
200
-
201
- function toTable(data: unknown): string {
202
- if (!Array.isArray(data)) return JSON.stringify(data, null, 2);
203
- if (data.length === 0) return "(empty)";
204
- if (typeof data[0] !== "object" || data[0] === null) {
205
- return data.map((d) => String(d)).join("\n");
206
- }
207
-
208
- const headers = Object.keys(data[0] as Record<string, unknown>);
209
- const colWidths = headers.map((h) => h.length);
210
-
211
- const rows = data.map((item) =>
212
- headers.map((h, i) => {
213
- const val = String((item as Record<string, unknown>)[h] ?? "");
214
- colWidths[i] = Math.max(colWidths[i], val.length);
215
- return val;
216
- }),
217
- );
218
-
219
- const sep = colWidths.map((w) => "-".repeat(w)).join(" ");
220
- const header = headers.map((h, i) => h.padEnd(colWidths[i])).join(" ");
221
- const body = rows.map((r) => r.map((c, i) => c.padEnd(colWidths[i])).join(" ")).join("\n");
222
-
223
- return `${header}\n${sep}\n${body}`;
224
- }
225
-
226
- function toCsv(data: unknown): string {
227
- if (!Array.isArray(data)) return JSON.stringify(data);
228
- if (data.length === 0) return "";
229
- if (typeof data[0] !== "object" || data[0] === null) {
230
- return data.map((d) => String(d)).join("\n");
231
- }
232
-
233
- const headers = Object.keys(data[0] as Record<string, unknown>);
234
- const lines = [headers.join(",")];
235
- for (const item of data) {
236
- lines.push(
237
- headers
238
- .map((h) => {
239
- const val = String((item as Record<string, unknown>)[h] ?? "");
240
- return val.includes(",") || val.includes('"') ? `"${val.replace(/"/g, '""')}"` : val;
241
- })
242
- .join(","),
243
- );
244
- }
245
- return lines.join("\n");
246
- }
247
-
248
- function camelToKebab(s: string): string {
249
- return s.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
250
- }
@@ -1,106 +0,0 @@
1
- /**
2
- * Command schema types — mirrors the frontend's declarative schema system.
3
- *
4
- * Just as the frontend uses `PageSchema > LayoutSchema > ControlSchema` to
5
- * drive form rendering, the CLI uses `CommandSchema > OptionSchema` to drive
6
- * command registration, help text, validation, and interactive prompts.
7
- *
8
- * Adding a new command = adding a schema file + a handler. The registry
9
- * auto-discovers and wires everything.
10
- */
11
-
12
- /** Allowed option types (mirrors frontend ControlType subset) */
13
- export type OptionType =
14
- | "string"
15
- | "number"
16
- | "boolean"
17
- | "choice"
18
- | "multi-choice"
19
- | "password"
20
- | "file-path"
21
- | "directory"
22
- | "json";
23
-
24
- /** Validation rule (same shape as frontend ValidationRule) */
25
- export interface ValidationRule {
26
- type: "required" | "minLength" | "maxLength" | "min" | "max" | "pattern" | "custom";
27
- value?: unknown;
28
- message: string;
29
- }
30
-
31
- /** A single option/flag for a command */
32
- export interface OptionSchema {
33
- /** Unique id (used as the flag name: --kebab-case) */
34
- id: string;
35
- /** Human label for help text */
36
- label: string;
37
- /** Short flag (single letter, e.g. "n" for -n) */
38
- alias?: string;
39
- /** Option type */
40
- type: OptionType;
41
- /** Description for --help */
42
- description: string;
43
- /** Default value */
44
- defaultValue?: unknown;
45
- /** Whether this option is required */
46
- required?: boolean;
47
- /** For choice/multi-choice: available options */
48
- choices?: Array<{ label: string; value: string }>;
49
- /** Validation rules */
50
- validations?: ValidationRule[];
51
- /** Whether this is a positional arg vs a flag */
52
- positional?: boolean;
53
- /** Order for positional args */
54
- position?: number;
55
- /** Whether to hide from --help */
56
- hidden?: boolean;
57
- /** Prompt the user interactively if value not provided via flag */
58
- prompt?: boolean;
59
- /** Prompt message for interactive input */
60
- promptMessage?: string;
61
- }
62
-
63
- /** Output format options */
64
- export type OutputFormat = "table" | "json" | "yaml" | "csv" | "tree";
65
-
66
- /** Command schema definition */
67
- export interface CommandSchema {
68
- /** Command name (e.g. "agents", "chat") */
69
- name: string;
70
- /** Command description for --help */
71
- description: string;
72
- /** Command group (for help organization) */
73
- group?: string;
74
- /** Aliases (e.g. ["a"] for "agents") */
75
- aliases?: string[];
76
- /** Options/flags for this command */
77
- options: OptionSchema[];
78
- /** Sub-commands (e.g. "agents list", "agents create") */
79
- subcommands?: CommandSchema[];
80
- /** Default output format */
81
- defaultOutput?: OutputFormat;
82
- /** Whether this command requires auth */
83
- requiresAuth?: boolean;
84
- /** Example usage strings for help text */
85
- examples?: string[];
86
- }
87
-
88
- /** Result from a command handler */
89
- export interface CommandResult {
90
- /** Exit code (0 = success) */
91
- exitCode: number;
92
- /** Output data (for JSON/YAML/table formatting) */
93
- data?: unknown;
94
- /** Human-readable message */
95
- message?: string;
96
- /** Error details if failed */
97
- error?: string;
98
- /** Whether output was already formatted (skip auto-formatting) */
99
- formatted?: boolean;
100
- }
101
-
102
- /** Command handler function — options includes `args: string[]` from commander */
103
- export type CommandHandler = (
104
- args: Record<string, unknown>,
105
- options: { args: string[] } & Record<string, unknown>,
106
- ) => Promise<CommandResult>;
@@ -1,124 +0,0 @@
1
- /**
2
- * Terminal lifecycle helpers shared by the Ink REPL and the legacy readline
3
- * REPL. Kept in one place so the alternate-screen contract (enter on start,
4
- * leave on every exit path) can't drift between the two.
5
- */
6
-
7
- let entered = false;
8
- let registered = false;
9
-
10
- const ENTER_ALT = "\x1B[?1049h";
11
- const LEAVE_ALT = "\x1B[?1049l\x1B[?25h";
12
-
13
- /**
14
- * Whether colour may be written to stdout.
15
- *
16
- * Ink/chalk decide this for themselves from TTY + TERM, but chalk 5 does not
17
- * implement the `NO_COLOR` convention and nothing in either front end
18
- * suppresses colour in piped output. Both are handled here so every writer
19
- * (Ink theme, legacy readline REPL, help text) agrees:
20
- *
21
- * - piped stdout has no screen to colour: escapes would land in the file.
22
- * - `NO_COLOR` (any non-empty value) is the user's explicit opt-out.
23
- * - `TERM=dumb` means the terminal can't render them anyway.
24
- *
25
- * `odysx --color` / `odysx --no-color` override all of the above.
26
- */
27
- export const colorEnabled = (): boolean => {
28
- if (process.argv.includes("--no-color") || process.argv.includes("--no-colors")) return false;
29
- if (process.argv.includes("--color") || process.argv.includes("--colors")) return true;
30
- if (process.env.NO_COLOR) return false;
31
- if (process.env.TERM === "dumb") return false;
32
- return Boolean(process.stdout.isTTY);
33
- };
34
-
35
- /** Clear the viewport without resetting terminal modes. No-op when piped. */
36
- export const clearViewport = (): void => {
37
- if (!process.stdout.isTTY) return;
38
- try {
39
- process.stdout.write("\x1B[2J\x1B[H");
40
- } catch { /* stream gone */ }
41
- };
42
-
43
- /** Leave the alternate screen + restore the cursor. Safe to call twice. */
44
- export function restoreScreen(): void {
45
- if (!entered) return;
46
- entered = false;
47
- try {
48
- // A terminal that already went away (closed tab, piped output) must not
49
- // make exit handlers throw.
50
- process.stdout.write(LEAVE_ALT);
51
- } catch { /* stream gone */ }
52
- }
53
-
54
- /**
55
- * Enter the alternate screen buffer and guarantee restoration on exit.
56
- *
57
- * SIGINT/SIGTERM handlers re-raise the default signal after restoring so the
58
- * process actually terminates. Registering any listener replaces Node's
59
- * default "kill" behavior; without the re-raise a `kill` or Ctrl+C from a
60
- * non-raw context would leave the process running against a restored screen.
61
- */
62
- export function enterAltScreen(): void {
63
- if (entered) return;
64
- // Piped output (CI, `odysx | tee`) has no screen to switch: writing the
65
- // escape sequence would just inject junk bytes into the captured output.
66
- // Stay in the primary buffer so the matching leave-sequence is never sent.
67
- if (!process.stdout.isTTY) return;
68
- entered = true;
69
- try {
70
- process.stdout.write(ENTER_ALT);
71
- } catch { /* stream gone */ }
72
-
73
- if (registered) return;
74
- registered = true;
75
-
76
- // `exit` runs for clean exits and uncaught exceptions.
77
- process.on("exit", restoreScreen);
78
-
79
- for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"] as const) {
80
- const handler = (): void => {
81
- restoreScreen();
82
- // Re-raise with the default disposition so the exit status is correct.
83
- process.removeListener(sig, handler);
84
- try { process.kill(process.pid, sig); } catch {
85
- process.exit(sig === "SIGINT" ? 130 : 143);
86
- }
87
- };
88
- process.on(sig, handler);
89
- }
90
- }
91
-
92
- /**
93
- * Flush stdout before exiting. On Windows, stdout to a pipe or file is
94
- * asynchronous; `process.exit()` immediately after `console.log()` can
95
- * discard the tail of the output.
96
- */
97
- export function exitWith(code = 0): never {
98
- restoreScreen();
99
- // `write("")` with a callback fires once that stream's queue is drained.
100
- // Both streams are drained: on Windows, stdout to a pipe is asynchronous,
101
- // and an error written to stderr immediately before exit could be lost.
102
- let pending = 2;
103
- let exited = false;
104
- const done = (): void => {
105
- if (exited) return;
106
- if (--pending > 0) return;
107
- exited = true;
108
- process.exit(code);
109
- };
110
- try {
111
- process.stdout.write("", done);
112
- } catch {
113
- done();
114
- }
115
- try {
116
- process.stderr.write("", done);
117
- } catch {
118
- done();
119
- }
120
- // Safety net: never hang forever on a broken stream. Unref'd so it cannot
121
- // keep an otherwise-finished process alive.
122
- setTimeout(() => process.exit(code), 250).unref();
123
- return undefined as never;
124
- }
@@ -1,216 +0,0 @@
1
- /**
2
- * Workspace — root-directory detection + path confinement for local ops.
3
- *
4
- * The CLI's local file/shell commands are scoped to a "workspace": the
5
- * directory `odysx` was launched from (overridable via ODYSX_WORKSPACE or
6
- * ~/.odysx/config.json). Every path a command touches must resolve inside
7
- * that root, so `odysx local write ../../../etc/x` can't escape it.
8
- */
9
- import {
10
- chmodSync,
11
- existsSync,
12
- mkdirSync,
13
- readFileSync,
14
- realpathSync,
15
- renameSync,
16
- unlinkSync,
17
- writeFileSync,
18
- } from "node:fs";
19
- import { basename, dirname, isAbsolute, join, resolve, sep } from "node:path";
20
- import { homedir, tmpdir } from "node:os";
21
- import { getConfig } from "../config/index.js";
22
-
23
- let cachedRoot: string | null = null;
24
-
25
- /** Windows and macOS compare paths case-insensitively; Linux does not. */
26
- const CASE_INSENSITIVE = process.platform === "win32" || process.platform === "darwin";
27
- const fold = (p: string): string => (CASE_INSENSITIVE ? p.toLowerCase() : p);
28
-
29
- /** Resolve links/junctions, falling back to the input when it doesn't exist. */
30
- const real = (p: string): string => {
31
- try {
32
- return realpathSync.native(p);
33
- } catch {
34
- return p;
35
- }
36
- };
37
-
38
- /**
39
- * Resolve the deepest existing ancestor of `p`, then re-append the missing
40
- * tail. `real()` alone is a no-op for a path that doesn't exist yet, which
41
- * would let `write linked/new.txt` escape when `linked` is a junction.
42
- */
43
- const realDeep = (p: string): string => {
44
- const tail: string[] = [];
45
- let current = p;
46
- while (!existsSync(current)) {
47
- const parent = dirname(current);
48
- if (parent === current) return p; // reached the root; nothing to resolve
49
- tail.unshift(basename(current));
50
- current = parent;
51
- }
52
- return tail.length > 0 ? join(real(current), ...tail) : real(current);
53
- };
54
-
55
- /** True when `p` is `root` itself or sits inside it. */
56
- const isInside = (p: string, root: string): boolean => {
57
- const a = fold(p);
58
- const b = fold(root);
59
- return a === b || a.startsWith(b.endsWith(sep) ? b : b + sep);
60
- };
61
-
62
- /** Resolve the workspace root (once per process): config override → env → cwd. */
63
- export function getWorkspaceRoot(): string {
64
- if (cachedRoot) return cachedRoot;
65
- const configured = getConfig().workspace ?? process.env.ODYSX_WORKSPACE ?? null;
66
- let root = configured && configured.trim() ? resolve(configured.trim()) : process.cwd();
67
- // A workspace pointing at $HOME would make "inside root" meaningless.
68
- if (fold(root) === fold(homedir()) || fold(root) === fold(tmpdir())) {
69
- root = process.cwd();
70
- }
71
- if (!existsSync(root)) mkdirSync(root, { recursive: true });
72
- cachedRoot = real(root);
73
- return cachedRoot;
74
- }
75
-
76
- export interface PathDecision {
77
- ok: boolean;
78
- /** Absolute path when ok, else an explanation of why it was refused. */
79
- resolved?: string;
80
- error?: string;
81
- }
82
-
83
- /**
84
- * Confine a user-supplied path to the workspace.
85
- *
86
- * Absolute paths are allowed only when they already sit inside the root;
87
- * relative paths are resolved against it. Both sides are resolved through
88
- * links first — a lexical check alone let a junction inside the workspace
89
- * (node_modules and AppData are full of them) point anywhere, so
90
- * `local read linked/secret` reached outside the root. Comparison is
91
- * case-folded on platforms whose filesystems are.
92
- */
93
- export function confinePath(input: string): PathDecision {
94
- // Device and UNC paths have no meaningful "inside the workspace".
95
- if (process.platform === "win32" && /^(\\\\|\/\/|\\.\\)/.test(input)) {
96
- return { ok: false, error: `Path escapes workspace (UNC/device paths are not allowed)` };
97
- }
98
-
99
- const root = getWorkspaceRoot();
100
- const candidate = isAbsolute(input) ? input : join(root, input);
101
- const abs = realDeep(resolve(candidate));
102
- if (isInside(abs, root)) {
103
- return { ok: true, resolved: abs };
104
- }
105
- return { ok: false, error: `Path escapes workspace (${abs} is outside ${root})` };
106
- }
107
-
108
- /* ── Folder trust ───────────────────────────────────────────────────────── */
109
-
110
- /**
111
- * A folder is trusted once the user has explicitly said so.
112
- *
113
- * Confinement keeps operations *inside* the workspace; trust answers the
114
- * different question of whether the workspace is one the user meant to hand
115
- * over at all. Launching in an unfamiliar directory (a cloned repo, someone
116
- * else's checkout, a shared drive) should not silently grant read, write, and
117
- * execute over it, so the REPL asks once and remembers the answer.
118
- */
119
- const TRUST_FILE = join(homedir(), ".odysx", "trusted-folders.json");
120
- let cachedTrust: string[] | null = null;
121
-
122
- const loadTrust = (): string[] => {
123
- if (cachedTrust) return cachedTrust;
124
- try {
125
- if (!existsSync(TRUST_FILE)) {
126
- cachedTrust = [];
127
- return cachedTrust;
128
- }
129
- const parsed: unknown = JSON.parse(readFileSync(TRUST_FILE, "utf-8"));
130
- cachedTrust = Array.isArray(parsed) ? parsed.filter((p): p is string => typeof p === "string") : [];
131
- } catch {
132
- // An unreadable trust file must fail closed: treat every folder as
133
- // untrusted rather than silently trusting whatever is in the workspace.
134
- cachedTrust = [];
135
- }
136
- return cachedTrust;
137
- };
138
-
139
- /** Persist atomically and owner-only, like the config file. */
140
- const saveTrust = (folders: string[]): void => {
141
- const dir = dirname(TRUST_FILE);
142
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
143
- const tmp = `${TRUST_FILE}.${process.pid}.tmp`;
144
- try {
145
- writeFileSync(tmp, JSON.stringify(folders, null, 2), { encoding: "utf-8", mode: 0o600 });
146
- try { chmodSync(tmp, 0o600); } catch { /* not POSIX */ }
147
- renameSync(tmp, TRUST_FILE);
148
- } catch (err) {
149
- try { if (existsSync(tmp)) unlinkSync(tmp); } catch { /* best effort */ }
150
- throw err;
151
- }
152
- cachedTrust = folders;
153
- };
154
-
155
- export const listTrustedFolders = (): string[] => [...loadTrust()];
156
-
157
- /**
158
- * Is `root` trusted? A folder is trusted if it, or any ancestor of it, has
159
- * been trusted — trusting a monorepo root must not mean re-answering for
160
- * every package inside it.
161
- */
162
- export const isFolderTrusted = (root: string = getWorkspaceRoot()): boolean => {
163
- const target = realDeep(resolve(root));
164
- return loadTrust().some((trusted) => isInside(target, realDeep(resolve(trusted))));
165
- };
166
-
167
- export const trustFolder = (root: string = getWorkspaceRoot()): string => {
168
- const resolved = realDeep(resolve(root));
169
- const folders = loadTrust();
170
- if (!folders.some((f) => fold(f) === fold(resolved))) {
171
- saveTrust([...folders, resolved]);
172
- }
173
- return resolved;
174
- };
175
-
176
- /** Forget a trusted folder. Returns false when it was not trusted. */
177
- export const untrustFolder = (root: string): boolean => {
178
- const target = fold(realDeep(resolve(root)));
179
- const folders = loadTrust();
180
- const next = folders.filter((f) => fold(f) !== target);
181
- if (next.length === folders.length) return false;
182
- saveTrust(next);
183
- return true;
184
- };
185
-
186
- export interface ExecDecision {
187
- ok: boolean;
188
- error?: string;
189
- }
190
-
191
- /**
192
- * Gate a shell command before running it in the workspace.
193
- *
194
- * Denylist of obviously-destructive patterns; this is a seatbelt for typos,
195
- * not a sandbox. Anything not matched still goes through the REPL's y/N
196
- * approval prompt before executing.
197
- */
198
- const DENY_PATTERNS: RegExp[] = [
199
- /\brm\s+(-[a-z]*r[a-z]*f|-[a-z]*f[a-z]*r)\b/i, // rm -rf
200
- /\bformat\b/i,
201
- /\bdel\s+\/[sq]/i, // Windows del /s /q
202
- /\brmdir\s+\/s/i,
203
- /\bRemove-Item\b.*-Recurse.*-Force/i,
204
- /\bmkfs\b/,
205
- />\s*\/dev\/sd[a-z]/, // raw device writes
206
- /\bshutdown\b|\breboot\b/i,
207
- ];
208
-
209
- export function checkCommand(command: string): ExecDecision {
210
- for (const re of DENY_PATTERNS) {
211
- if (re.test(command)) {
212
- return { ok: false, error: `Refused by safety policy: matches /${re.source}/` };
213
- }
214
- }
215
- return { ok: true };
216
- }