@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,152 +0,0 @@
1
- /**
2
- * Config management — persists auth + settings to ~/.odysx/config.json.
3
- *
4
- * Two rules shape this module:
5
- * 1. Values that came from the environment are never written back. A CI or
6
- * ephemeral shell may export ODYSX_API_KEY; any later `updateConfig`
7
- * (a mere `/model gpt-x`) used to serialise the whole merged object and
8
- * leave that secret in plaintext on disk.
9
- * 2. Writes are atomic and owner-only. A truncated write would lose the
10
- * user's session, and the default umask leaves the file world-readable.
11
- */
12
- import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
13
- import { join } from "node:path";
14
- import { homedir } from "node:os";
15
-
16
- /** External LLM provider endpoint (bring-your-own key). See
17
- * core/provider/external.ts for the wire protocols. */
18
- export interface ExternalProviderConfig {
19
- type: "openai" | "anthropic" | "gemini";
20
- baseUrl?: string;
21
- apiKey?: string;
22
- model: string;
23
- }
24
-
25
- export interface OdysxConfig {
26
- apiUrl: string;
27
- token: string | null;
28
- apiKey: string | null;
29
- username: string | null;
30
- defaultOutput: string;
31
- telemetry: boolean;
32
- model: string | null;
33
- /** Workspace root for local file/shell ops (defaults to launch cwd). */
34
- workspace?: string | null;
35
- /** Active external provider name; absent/null/"odysx" = OdysX platform. */
36
- provider?: string | null;
37
- /** Permission posture for workspace operations. See core/permissions. */
38
- permissionMode?: string | null;
39
- /**
40
- * Local label of the API key selected in /keys (derived from `key_prefix`).
41
- * The key secret itself stays in `apiKey`; this is only a human-readable
42
- * marker, because the backend never returns a created key's secret twice.
43
- */
44
- activeKeyLabel?: string | null;
45
- /** Named provider endpoints usable via /provider <name>. */
46
- providers?: Record<string, ExternalProviderConfig>;
47
- }
48
-
49
- const CONFIG_DIR = join(homedir(), ".odysx");
50
- const CONFIG_FILE = join(CONFIG_DIR, "config.json");
51
-
52
- const DEFAULT_CONFIG: OdysxConfig = {
53
- apiUrl: "http://localhost:8000",
54
- token: null,
55
- apiKey: null,
56
- username: null,
57
- defaultOutput: "table",
58
- telemetry: true,
59
- model: null,
60
- provider: null,
61
- providers: {},
62
- };
63
-
64
- let cachedConfig: OdysxConfig | null = null;
65
- /** The last state known to be on disk — the source of truth for what to write.
66
- * Kept separate from `cachedConfig`, which also carries env overrides. */
67
- let diskConfig: OdysxConfig | null = null;
68
-
69
- /** Fields that an environment variable may override, mapped to that variable. */
70
- const ENV_OVERRIDES: Array<{ key: keyof OdysxConfig; env: string }> = [
71
- { key: "apiUrl", env: "ODYSX_API_URL" },
72
- { key: "apiKey", env: "ODYSX_API_KEY" },
73
- { key: "token", env: "ODYSX_TOKEN" },
74
- ];
75
-
76
- function loadFromDisk(): OdysxConfig {
77
- if (!existsSync(CONFIG_FILE)) return { ...DEFAULT_CONFIG };
78
- try {
79
- const raw = readFileSync(CONFIG_FILE, "utf-8");
80
- return { ...DEFAULT_CONFIG, ...JSON.parse(raw) };
81
- } catch (err) {
82
- // Don't silently pretend the user has no config: a corrupt file means
83
- // they are about to be treated as logged out, which is worth saying.
84
- process.stderr.write(
85
- `⚠ ${CONFIG_FILE} could not be read (${err instanceof Error ? err.message : String(err)}); using defaults\n`,
86
- );
87
- return { ...DEFAULT_CONFIG };
88
- }
89
- }
90
-
91
- /** Load config from disk (or defaults), with environment overrides applied. */
92
- export function getConfig(): OdysxConfig {
93
- if (cachedConfig) return cachedConfig;
94
-
95
- const base = loadFromDisk();
96
- diskConfig = { ...base };
97
- const merged = { ...base } as unknown as Record<string, unknown>;
98
- for (const { key, env } of ENV_OVERRIDES) {
99
- const value = process.env[env];
100
- if (value) merged[key] = value;
101
- }
102
- cachedConfig = merged as unknown as OdysxConfig;
103
- return cachedConfig;
104
- }
105
-
106
- /**
107
- * Save config to disk.
108
- *
109
- * Environment-derived values are written back as whatever was on disk before,
110
- * so exporting a key never causes it to be persisted by an unrelated update.
111
- * The write goes to a sibling temp file that is chmod'd 0600 and renamed into
112
- * place: rename is atomic, so a crash can't leave a half-written config.
113
- */
114
- export function saveConfig(config: OdysxConfig): void {
115
- if (!existsSync(CONFIG_DIR)) {
116
- mkdirSync(CONFIG_DIR, { recursive: true });
117
- }
118
-
119
- const toWrite: OdysxConfig = { ...config };
120
- const onDisk = diskConfig ?? DEFAULT_CONFIG;
121
- const writable = toWrite as unknown as Record<string, unknown>;
122
- for (const { key, env } of ENV_OVERRIDES) {
123
- if (process.env[env]) writable[key] = (onDisk as unknown as Record<string, unknown>)[key];
124
- }
125
-
126
- const tmp = `${CONFIG_FILE}.${process.pid}.tmp`;
127
- try {
128
- writeFileSync(tmp, JSON.stringify(toWrite, null, 2), { encoding: "utf-8", mode: 0o600 });
129
- // mode on create is subject to umask; chmod makes it explicit.
130
- try { chmodSync(tmp, 0o600); } catch { /* not POSIX, or FS without modes */ }
131
- renameSync(tmp, CONFIG_FILE);
132
- } catch (err) {
133
- try { if (existsSync(tmp)) unlinkSync(tmp); } catch { /* best effort */ }
134
- throw err;
135
- }
136
-
137
- diskConfig = { ...toWrite };
138
- cachedConfig = config; // the caller's view still includes env overrides
139
- }
140
-
141
- /** Update a config field and save */
142
- export function updateConfig(updates: Partial<OdysxConfig>): OdysxConfig {
143
- const config = getConfig();
144
- const updated = { ...config, ...updates };
145
- saveConfig(updated);
146
- return updated;
147
- }
148
-
149
- /** Clear auth tokens (logout) */
150
- export function clearAuth(): void {
151
- updateConfig({ token: null, apiKey: null });
152
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * Prompt history persistence.
3
- *
4
- * The REPL's ↑ recall was in-memory only, so every launch started with an
5
- * empty history — the single most jarring difference from a real shell.
6
- * History is appended to ~/.odysx/history.json (deduped, capped) and loaded
7
- * once at startup. All failures are silent: a corrupt or unwritable history
8
- * file must never stop the CLI from starting.
9
- */
10
- import { chmodSync, existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
11
- import { join, dirname } from "node:path";
12
- import { homedir } from "node:os";
13
-
14
- const HISTORY_FILE = join(homedir(), ".odysx", "history.json");
15
- const MAX_ENTRIES = 500;
16
-
17
- /** Flags whose following value is a credential or private content. */
18
- const SECRET_FLAGS = [
19
- "--content", "--password", "--api-key", "--apiKey", "--token",
20
- "--secret", "--key", "--value",
21
- ];
22
-
23
- /** Anything that looks like a provider key, wherever it appears. */
24
- const SECRET_TOKEN = /\b(sk-[A-Za-z0-9_-]{12,}|AIza[A-Za-z0-9_-]{20,}|gsk_[A-Za-z0-9]{12,})\b/g;
25
-
26
- /**
27
- * Strip credentials before a line is written to disk.
28
- *
29
- * History is a plaintext file that outlives the session, and every submitted
30
- * line used to be stored verbatim — including `local write --content <secret>`
31
- * and pasted API keys. Redacting the value keeps recall useful without
32
- * turning the history file into a credential store.
33
- */
34
- export const redact = (entry: string): string => {
35
- let out = entry;
36
- for (const flag of SECRET_FLAGS) {
37
- const escaped = flag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
38
- out = out.replace(
39
- new RegExp(`(${escaped})(\\s+|=)(\"[^\"]*\"|'[^']*'|\\S+)`, "gi"),
40
- "$1$2[redacted]",
41
- );
42
- }
43
- return out.replace(SECRET_TOKEN, "[redacted]");
44
- };
45
-
46
- export function loadHistory(): string[] {
47
- try {
48
- if (!existsSync(HISTORY_FILE)) return [];
49
- const parsed: unknown = JSON.parse(readFileSync(HISTORY_FILE, "utf-8"));
50
- if (!Array.isArray(parsed)) return [];
51
- return parsed.filter((entry): entry is string => typeof entry === "string").slice(-MAX_ENTRIES);
52
- } catch {
53
- return [];
54
- }
55
- }
56
-
57
- export function saveHistory(entries: string[]): void {
58
- try {
59
- const dir = dirname(HISTORY_FILE);
60
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
61
- writeFileSync(HISTORY_FILE, JSON.stringify(entries.slice(-MAX_ENTRIES), null, 0), {
62
- encoding: "utf-8",
63
- mode: 0o600,
64
- });
65
- // mode on create is subject to umask; make it explicit where supported.
66
- try { chmodSync(HISTORY_FILE, 0o600); } catch { /* not POSIX */ }
67
- } catch { /* history is a convenience, never fatal */ }
68
- }
69
-
70
- /** Append an entry, dropping consecutive duplicates, and persist. */
71
- export function appendHistory(entries: string[], entry: string): string[] {
72
- const trimmed = entry.trim();
73
- if (!trimmed) return entries;
74
- const safe = redact(trimmed);
75
- if (entries[entries.length - 1] === safe) return entries;
76
- const next = [...entries, safe].slice(-MAX_ENTRIES);
77
- saveHistory(next);
78
- return next;
79
- }
@@ -1,420 +0,0 @@
1
- /**
2
- * Markdown Renderer for Console Chat
3
- *
4
- * Transforms streaming markdown content into beautifully formatted console output
5
- * with syntax highlighting, colorization, and proper code block handling.
6
- */
7
-
8
- import markdownIt from "markdown-it";
9
- import chalk from "chalk";
10
-
11
- // Initialize markdown-it with common options
12
- const md = markdownIt({
13
- html: true,
14
- linkify: true,
15
- typographer: true,
16
- // Disabled markdown-it code highlighting - using custom renderer for better control
17
- // highlight: (str, lang) => {
18
- // // Simple syntax highlighting for common languages
19
- // if (lang) {
20
- // return highlightCode(str, lang);
21
- // }
22
- // return str;
23
- // }
24
- });
25
-
26
- /**
27
- * Simple code highlighting using chalk
28
- */
29
- function highlightCode(code: string, _lang: string): string {
30
- const lines = code.split('\n');
31
- let inString = false;
32
- let stringChar = '';
33
- let escaped = false;
34
-
35
- return lines.map((line, idx) => {
36
- let result = '';
37
- let i = 0;
38
-
39
- while (i < line.length) {
40
- const char = line[i];
41
-
42
- // Handle strings
43
- if (!inString && (char === '"' || char === "'" || char === '`')) {
44
- inString = true;
45
- stringChar = char;
46
- result += chalk.yellow(char);
47
- } else if (inString && char === stringChar && !escaped) {
48
- inString = false;
49
- result += chalk.yellow(char);
50
- } else if (inString && char === '\\' && !escaped) {
51
- escaped = true;
52
- result += chalk.yellow(char);
53
- } else {
54
- escaped = false;
55
-
56
- if (inString) {
57
- result += chalk.yellow(char);
58
- } else {
59
- // Keywords
60
- const keywords = ['const', 'let', 'var', 'function', 'return', 'if', 'else', 'for', 'while', 'class', 'import', 'export', 'from', 'async', 'await', 'try', 'catch', 'throw', 'new', 'this', 'typeof', 'instanceof', 'def', 'pass', 'lambda', 'yield', 'with', 'as', 'is', 'not', 'and', 'or', 'in', 'True', 'False', 'None'];
61
- const nextWord = line.slice(i).match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)/);
62
- if (nextWord && keywords.includes(nextWord[1])) {
63
- result += chalk.blue(nextWord[1]);
64
- i += nextWord[1].length - 1;
65
- } else if (char.match(/[{}()[\];,]/)) {
66
- result += chalk.gray(char);
67
- } else if (char === '#' && i === 0) {
68
- // Python comment
69
- result += chalk.green(line.slice(i));
70
- break;
71
- } else if (char === '/' && i + 1 < line.length && line[i + 1] === '/') {
72
- // JS/TS comment
73
- result += chalk.green(line.slice(i));
74
- break;
75
- } else {
76
- result += chalk.white(char);
77
- }
78
- }
79
- }
80
- i++;
81
- }
82
-
83
- return chalk.gray(`${String(idx + 1).padStart(3, ' ')} | `) + result;
84
- }).join('\n');
85
- }
86
-
87
- /**
88
- * Render a full markdown string to console with colors
89
- */
90
- export function renderMarkdown(markdown: string): void {
91
- if (!markdown || markdown.trim() === '') return;
92
-
93
- const rendered = md.render(markdown);
94
-
95
- // Parse the HTML output and convert to chalk-styled output
96
- const lines = rendered.split('\n');
97
-
98
- for (const line of lines) {
99
- const trimmed = line.trim();
100
-
101
- if (!trimmed) {
102
- console.log('');
103
- continue;
104
- }
105
-
106
- // Headings
107
- const headingMatch = trimmed.match(/^<h([1-6])>(.*?)<\/h[1-6]>$/);
108
- if (headingMatch) {
109
- const level = parseInt(headingMatch[1]);
110
- const text = stripHtml(headingMatch[2]);
111
- const prefix = '#'.repeat(level) + ' ';
112
- console.log(chalk.bold(chalk.rgb(255, 165, 0)(prefix + text)));
113
- continue;
114
- }
115
-
116
- // Paragraphs
117
- if (trimmed.startsWith('<p>') && trimmed.endsWith('</p>')) {
118
- const text = stripHtml(trimmed.slice(3, -4));
119
- console.log(chalk.gray(text));
120
- continue;
121
- }
122
-
123
- // Lists
124
- if (trimmed.startsWith('<ul>') || trimmed.startsWith('<ol>')) {
125
- // Skip list container tags
126
- continue;
127
- }
128
- if (trimmed.startsWith('</ul>') || trimmed.startsWith('</ol>')) {
129
- continue;
130
- }
131
- const liMatch = trimmed.match(/^<li>(.*?)<\/li>$/);
132
- if (liMatch) {
133
- const text = stripHtml(liMatch[1]);
134
- console.log(chalk.green(' • ') + chalk.white(text));
135
- continue;
136
- }
137
-
138
- // Code blocks
139
- if (trimmed.startsWith('<pre><code') && trimmed.endsWith('</code></pre>')) {
140
- // Extract code content
141
- const codeMatch = trimmed.match(/<pre><code[^>]*>([\s\S]*)<\/code><\/pre>/);
142
- if (codeMatch) {
143
- console.log(chalk.cyan('┌─ Code Block ─'));
144
- console.log(codeMatch[1]);
145
- console.log(chalk.cyan('└───────────────'));
146
- }
147
- continue;
148
- }
149
-
150
- // Inline code
151
- if (trimmed.includes('<code>') && !trimmed.includes('<pre>')) {
152
- let text = trimmed.replace(/<code>(.*?)<\/code>/g, (_, code) => chalk.cyan('`' + stripHtml(code) + '`'));
153
- text = stripHtml(text);
154
- console.log(chalk.gray(text));
155
- continue;
156
- }
157
-
158
- // Blockquotes
159
- if (trimmed.startsWith('<blockquote>') && trimmed.endsWith('</blockquote>')) {
160
- const text = stripHtml(trimmed.slice(12, -13));
161
- console.log(chalk.magenta('│ ') + chalk.gray(text));
162
- continue;
163
- }
164
-
165
- // Horizontal rule
166
- if (trimmed === '<hr>') {
167
- console.log(chalk.gray('─'.repeat(60)));
168
- continue;
169
- }
170
-
171
- // Links
172
- if (trimmed.includes('<a href=')) {
173
- let text = trimmed.replace(/<a href="([^"]*)">([^<]*)<\/a>/g, (_, url, linkText) =>
174
- chalk.underline(chalk.blue(linkText)) + chalk.dim(` (${url})`)
175
- );
176
- text = stripHtml(text);
177
- console.log(chalk.gray(text));
178
- continue;
179
- }
180
-
181
- // Bold/Italic
182
- let text = trimmed
183
- .replace(/<strong>(.*?)<\/strong>/g, (_, t) => chalk.bold(stripHtml(t)))
184
- .replace(/<b>(.*?)<\/b>/g, (_, t) => chalk.bold(stripHtml(t)))
185
- .replace(/<em>(.*?)<\/em>/g, (_, t) => chalk.italic(stripHtml(t)))
186
- .replace(/<i>(.*?)<\/i>/g, (_, t) => chalk.italic(stripHtml(t)));
187
-
188
- text = stripHtml(text);
189
- if (text.trim()) {
190
- console.log(chalk.gray(text));
191
- }
192
- }
193
- }
194
-
195
- /**
196
- * Strip HTML tags from string
197
- */
198
- function stripHtml(html: string): string {
199
- return html
200
- .replace(/<[^>]*>/g, '')
201
- .replace(/</g, '<')
202
- .replace(/>/g, '>')
203
- .replace(/&/g, '&')
204
- .replace(/"/g, '"')
205
- .replace(/'/g, "'")
206
- .replace(/&nbsp;/g, ' ');
207
- }
208
-
209
- /**
210
- * Streaming markdown renderer - processes tokens as they arrive
211
- */
212
- export class StreamingMarkdownRenderer {
213
- private buffer: string = '';
214
- private inCodeBlock = false;
215
- private codeBlockLang = '';
216
- private codeBuffer: string[] = [];
217
-
218
- /**
219
- * Process a chunk of streamed markdown
220
- */
221
- processChunk(chunk: string): void {
222
- this.buffer += chunk;
223
-
224
- // Check for code block start
225
- if (!this.inCodeBlock) {
226
- const codeBlockStart = this.buffer.match(/```(\w*)\n/);
227
- if (codeBlockStart && codeBlockStart.index !== undefined) {
228
- this.inCodeBlock = true;
229
- this.codeBlockLang = codeBlockStart[1] || '';
230
- this.codeBuffer = [];
231
-
232
- // Print everything before the code block
233
- const beforeCode = this.buffer.slice(0, codeBlockStart.index);
234
- if (beforeCode.trim()) {
235
- this.renderInline(beforeCode);
236
- }
237
-
238
- this.buffer = this.buffer.slice(codeBlockStart.index + codeBlockStart[0].length);
239
- console.log(chalk.cyan('\n┌─ Code Block (' + (this.codeBlockLang || 'text') + ') ─'));
240
- return;
241
- }
242
- } else {
243
- // Check for code block end
244
- const codeBlockEnd = this.buffer.indexOf('\n```');
245
- if (codeBlockEnd !== -1) {
246
- const codeContent = this.buffer.slice(0, codeBlockEnd);
247
- this.codeBuffer.push(codeContent);
248
- this.buffer = this.buffer.slice(codeBlockEnd + 4);
249
- this.inCodeBlock = false;
250
-
251
- // Render the code block with highlighting
252
- const fullCode = this.codeBuffer.join('\n');
253
- console.log(highlightCode(fullCode, this.codeBlockLang));
254
- console.log(chalk.cyan('└──────────────────────────\n'));
255
- this.codeBuffer = [];
256
- } else {
257
- // Still in code block, accumulate
258
- this.codeBuffer.push(this.buffer);
259
- this.buffer = '';
260
- }
261
- return;
262
- }
263
-
264
- // Render non-code content as we go
265
- this.renderInline(this.buffer);
266
- this.buffer = '';
267
- }
268
-
269
- /**
270
- * Render inline markdown (non-code-block content)
271
- */
272
- private renderInline(text: string): void {
273
- if (!text.trim()) return;
274
-
275
- // Split by newlines and process each line
276
- const lines = text.split('\n');
277
- for (const line of lines) {
278
- if (!line.trim()) continue;
279
-
280
- // Handle headings
281
- const headingMatch = line.match(/^(#{1,6})\s+(.*)/);
282
- if (headingMatch) {
283
- const level = headingMatch[1].length;
284
- const text = headingMatch[2];
285
- const prefix = '#'.repeat(level) + ' ';
286
- console.log(chalk.bold(chalk.rgb(255, 165, 0)(prefix + text)));
287
- continue;
288
- }
289
-
290
- // Handle list items
291
- const listMatch = line.match(/^[\s]*[-*+]\s+(.*)/);
292
- if (listMatch) {
293
- console.log(chalk.green(' • ') + chalk.white(this.formatInline(listMatch[1])));
294
- continue;
295
- }
296
-
297
- // Handle numbered lists
298
- const numMatch = line.match(/^[\s]*\d+\.\s+(.*)/);
299
- if (numMatch) {
300
- console.log(chalk.green(' 1. ') + chalk.white(this.formatInline(numMatch[1])));
301
- continue;
302
- }
303
-
304
- // Handle blockquotes
305
- const quoteMatch = line.match(/^>\s*(.*)/);
306
- if (quoteMatch) {
307
- console.log(chalk.magenta('│ ') + chalk.gray(this.formatInline(quoteMatch[1])));
308
- continue;
309
- }
310
-
311
- // Handle horizontal rule
312
- if (line.match(/^[-*_]{3,}$/)) {
313
- console.log(chalk.gray('─'.repeat(60)));
314
- continue;
315
- }
316
-
317
- // Regular text with inline formatting
318
- console.log(chalk.gray(this.formatInline(line)));
319
- }
320
- }
321
-
322
- /**
323
- * Format inline markdown elements (bold, italic, code, links)
324
- */
325
- private formatInline(text: string): string {
326
- return text
327
- .replace(/\*\*(.*?)\*\*/g, (_, t) => chalk.bold(t))
328
- .replace(/__(.*?)__/g, (_, t) => chalk.bold(t))
329
- .replace(/\*(.*?)\*/g, (_, t) => chalk.italic(t))
330
- .replace(/_(.*?)_/g, (_, t) => chalk.italic(t))
331
- .replace(/`([^`]+)`/g, (_, t) => chalk.cyan('`' + t + '`'))
332
- .replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, linkText, url) =>
333
- chalk.underline(chalk.blue(linkText)) + chalk.dim(` (${url})`)
334
- );
335
- }
336
-
337
- /**
338
- * Flush any remaining buffer
339
- */
340
- flush(): void {
341
- if (this.buffer.trim()) {
342
- this.renderInline(this.buffer);
343
- this.buffer = '';
344
- }
345
- if (this.inCodeBlock && this.codeBuffer.length > 0) {
346
- const fullCode = this.codeBuffer.join('\n');
347
- console.log(highlightCode(fullCode, this.codeBlockLang));
348
- console.log(chalk.cyan('└──────────────────────────\n'));
349
- }
350
- }
351
- }
352
-
353
- /**
354
- * Pure markdown → plain-text-with-unicode-markers converter for the Ink UI.
355
- *
356
- * Returns a string (Ink <Text> renders ANSI-free text, so styling is expressed
357
- * with unicode markers instead of chalk escapes — chalk output would leak raw
358
- * escape codes into Ink's reconciled frame).
359
- */
360
- export function markdownToText(markdown: string): string {
361
- if (!markdown || !markdown.trim()) return "";
362
- const lines = md.render(markdown).split("\n");
363
- const out: string[] = [];
364
-
365
- for (const raw of lines) {
366
- const line = raw.trim();
367
- if (!line) continue;
368
-
369
- // Headings: underline with ─ instead of #
370
- const h = line.match(/^<h([1-6])>(.*?)<\/h[1-6]>$/);
371
- if (h) {
372
- const text = stripTags(h[2]);
373
- out.push("", text.toUpperCase(), "─".repeat(Math.min(text.length, 60)));
374
- continue;
375
- }
376
- // Paragraph
377
- if (line.startsWith("<p>") && line.endsWith("</p>")) {
378
- out.push(stripTags(line.slice(3, -4)));
379
- continue;
380
- }
381
- // List item → bullet
382
- const li = line.match(/^<li>(.*?)<\/li>$/);
383
- if (li) {
384
- out.push(` • ${stripTags(li[1])}`);
385
- continue;
386
- }
387
- // Blockquote
388
- if (line.startsWith("<blockquote>")) {
389
- out.push(`│ ${stripTags(line.replace(/<\/?blockquote>/g, ""))}`);
390
- continue;
391
- }
392
- // Code block (rendered HTML keeps newlines inside <code>)
393
- if (line.startsWith("<pre>") || line.startsWith("<code>")) {
394
- out.push(...stripTags(line).split("\n").map((l) => ` ${l}`));
395
- continue;
396
- }
397
- // Horizontal rule
398
- if (/^<(hr|hr\s)/.test(line)) {
399
- out.push("─".repeat(60));
400
- continue;
401
- }
402
- out.push(stripTags(line));
403
- }
404
-
405
- return out.join("\n");
406
- }
407
-
408
- /** Strip remaining HTML tags and decode a handful of common entities. */
409
- function stripTags(html: string): string {
410
- return html
411
- .replace(/<br\s*\/?>/g, "\n")
412
- .replace(/<[^>]+>/g, "")
413
- .replace(/&amp;/g, "&")
414
- .replace(/&lt;/g, "<")
415
- .replace(/&gt;/g, ">")
416
- .replace(/&quot;/g, '"')
417
- .replace(/&#39;/g, "'");
418
- }
419
-
420
- export { md };