@odysx/codemind 0.0.0-stage → 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 (108) hide show
  1. package/README.md +293 -2
  2. package/dist/commands/agents.d.ts +2 -0
  3. package/dist/commands/agents.js +91 -0
  4. package/dist/commands/auth.d.ts +2 -0
  5. package/dist/commands/auth.js +35 -0
  6. package/dist/commands/chat.d.ts +2 -0
  7. package/dist/commands/chat.js +180 -0
  8. package/dist/commands/keys.d.ts +2 -0
  9. package/dist/commands/keys.js +81 -0
  10. package/dist/commands/local.d.ts +2 -0
  11. package/dist/commands/local.js +325 -0
  12. package/dist/commands/mcp.d.ts +2 -0
  13. package/dist/commands/mcp.js +73 -0
  14. package/dist/commands/prompts.d.ts +2 -0
  15. package/dist/commands/prompts.js +59 -0
  16. package/dist/commands/skills.d.ts +2 -0
  17. package/dist/commands/skills.js +41 -0
  18. package/dist/core/auth/index.d.ts +10 -0
  19. package/dist/core/auth/index.js +82 -0
  20. package/dist/core/config/index.d.ts +47 -0
  21. package/dist/core/config/index.js +118 -0
  22. package/dist/core/history.d.ts +14 -0
  23. package/dist/core/history.js +80 -0
  24. package/dist/core/markdown-renderer.d.ts +47 -0
  25. package/dist/core/markdown-renderer.js +385 -0
  26. package/dist/core/permissions/index.d.ts +31 -0
  27. package/dist/core/permissions/index.js +64 -0
  28. package/dist/core/provider/external.d.ts +28 -0
  29. package/dist/core/provider/external.js +248 -0
  30. package/dist/core/provider/index.d.ts +138 -0
  31. package/dist/core/provider/index.js +510 -0
  32. package/dist/core/registry/index.d.ts +25 -0
  33. package/dist/core/registry/index.js +216 -0
  34. package/dist/core/schema/types.d.ts +93 -0
  35. package/dist/core/schema/types.js +12 -0
  36. package/dist/core/terminal.d.ts +40 -0
  37. package/dist/core/terminal.js +134 -0
  38. package/dist/core/workspace/index.d.ts +35 -0
  39. package/dist/core/workspace/index.js +194 -0
  40. package/dist/index.d.ts +10 -0
  41. package/dist/index.js +393 -0
  42. package/dist/ui/app.d.ts +3 -0
  43. package/dist/ui/app.js +554 -0
  44. package/dist/ui/commands/cases/catalog.d.ts +11 -0
  45. package/dist/ui/commands/cases/catalog.js +62 -0
  46. package/dist/ui/commands/cases/misc.d.ts +35 -0
  47. package/dist/ui/commands/cases/misc.js +245 -0
  48. package/dist/ui/commands/cases/tasks.d.ts +13 -0
  49. package/dist/ui/commands/cases/tasks.js +91 -0
  50. package/dist/ui/commands/runCommand.d.ts +22 -0
  51. package/dist/ui/commands/runCommand.js +136 -0
  52. package/dist/ui/components/AgentPicker.d.ts +11 -0
  53. package/dist/ui/components/AgentPicker.js +7 -0
  54. package/dist/ui/components/AuthPicker.d.ts +14 -0
  55. package/dist/ui/components/AuthPicker.js +7 -0
  56. package/dist/ui/components/Banner.d.ts +8 -0
  57. package/dist/ui/components/Banner.js +24 -0
  58. package/dist/ui/components/CommandMenu.d.ts +17 -0
  59. package/dist/ui/components/CommandMenu.js +21 -0
  60. package/dist/ui/components/ErrorBoundary.d.ts +24 -0
  61. package/dist/ui/components/ErrorBoundary.js +51 -0
  62. package/dist/ui/components/InputBar.d.ts +28 -0
  63. package/dist/ui/components/InputBar.js +108 -0
  64. package/dist/ui/components/KeysPanel.d.ts +12 -0
  65. package/dist/ui/components/KeysPanel.js +25 -0
  66. package/dist/ui/components/MessageView.d.ts +29 -0
  67. package/dist/ui/components/MessageView.js +107 -0
  68. package/dist/ui/components/PermissionPrompt.d.ts +10 -0
  69. package/dist/ui/components/PermissionPrompt.js +4 -0
  70. package/dist/ui/components/Pickers.d.ts +43 -0
  71. package/dist/ui/components/Pickers.js +33 -0
  72. package/dist/ui/components/SearchOverlay.d.ts +21 -0
  73. package/dist/ui/components/SearchOverlay.js +14 -0
  74. package/dist/ui/components/SessionPicker.d.ts +12 -0
  75. package/dist/ui/components/SessionPicker.js +8 -0
  76. package/dist/ui/components/WorkingIndicator.d.ts +10 -0
  77. package/dist/ui/components/WorkingIndicator.js +23 -0
  78. package/dist/ui/controls/ApiKeyEntry.d.ts +8 -0
  79. package/dist/ui/controls/ApiKeyEntry.js +5 -0
  80. package/dist/ui/controls/MultiSelect.d.ts +18 -0
  81. package/dist/ui/controls/MultiSelect.js +9 -0
  82. package/dist/ui/hooks/useAgentPicker.d.ts +14 -0
  83. package/dist/ui/hooks/useAgentPicker.js +53 -0
  84. package/dist/ui/hooks/useAuthFlow.d.ts +14 -0
  85. package/dist/ui/hooks/useAuthFlow.js +31 -0
  86. package/dist/ui/hooks/useKeysFlow.d.ts +17 -0
  87. package/dist/ui/hooks/useKeysFlow.js +130 -0
  88. package/dist/ui/hooks/useSessionPicker.d.ts +29 -0
  89. package/dist/ui/hooks/useSessionPicker.js +58 -0
  90. package/dist/ui/hooks/useTerminalSize.d.ts +6 -0
  91. package/dist/ui/hooks/useTerminalSize.js +29 -0
  92. package/dist/ui/input/keyRouter.d.ts +125 -0
  93. package/dist/ui/input/keyRouter.js +574 -0
  94. package/dist/ui/layouts/ScreenLayout.d.ts +98 -0
  95. package/dist/ui/layouts/ScreenLayout.js +56 -0
  96. package/dist/ui/shared/types.d.ts +143 -0
  97. package/dist/ui/shared/types.js +38 -0
  98. package/dist/ui/theme.d.ts +29 -0
  99. package/dist/ui/theme.js +54 -0
  100. package/dist/ui/utils/markdown.d.ts +74 -0
  101. package/dist/ui/utils/markdown.js +187 -0
  102. package/dist/ui/utils/mentions.d.ts +12 -0
  103. package/dist/ui/utils/mentions.js +28 -0
  104. package/dist/ui/utils/terminal-text.d.ts +33 -0
  105. package/dist/ui/utils/terminal-text.js +123 -0
  106. package/dist/ui/utils/text.d.ts +72 -0
  107. package/dist/ui/utils/text.js +171 -0
  108. package/package.json +50 -6
package/README.md CHANGED
@@ -1,3 +1,294 @@
1
- # Temporary Holding Version
1
+ # Codemind — the OdysX CLI
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Codemind** is the OdysX agent client for the terminal. You start it by typing
4
+ `odysx`; the package is published as `@odysx/codemind`, and the folder holding
5
+ it is `odysxCLI/`. Those three names refer to the same thing — the directory
6
+ name is not a rename of the product.
7
+
8
+ It gives you a full-screen REPL for conversations, plus a scriptable command
9
+ surface for agents, API keys, prompt templates, skills, MCP servers, and
10
+ workspace-scoped file and shell operations.
11
+
12
+ The CLI talks to the OdysX platform by default (streaming over SSE from
13
+ `/api/v1/llm/chat/stream`), and can be pointed at an external provider —
14
+ OpenAI-compatible, Anthropic, or Gemini — with your own key. See
15
+ [Configuration](#configuration).
16
+
17
+ ---
18
+
19
+ ## Requirements
20
+
21
+ - **Node.js >= 22.12** (declared in `engines`; `commander@15` requires it).
22
+ - A running OdysX platform, or an external provider key.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ cd odysxCLI
28
+ npm install
29
+ npm run build
30
+ npm link # puts `odysx` on your PATH
31
+ ```
32
+
33
+ Without linking, every command below also works as `node dist/index.js …`.
34
+
35
+ ## Quick start
36
+
37
+ ```bash
38
+ odysx auth set-key <your-api-key> # or set ODYSX_API_KEY in the environment
39
+ odysx # interactive UI
40
+ odysx chat "summarise src/core" # one-shot, prints the reply and exits
41
+ ```
42
+
43
+ ---
44
+
45
+ ## The interactive UI
46
+
47
+ Running `odysx` with no arguments on a terminal opens the full-screen REPL:
48
+ the transcript scrolls above, the live reply renders as it streams, and the
49
+ input bar stays pinned at the bottom with the current agent, model, provider,
50
+ message count, and workspace.
51
+
52
+ ### Keys
53
+
54
+ | Key | Action |
55
+ | --- | --- |
56
+ | `Enter` | Send the prompt — or run the highlighted slash command |
57
+ | `Shift+Enter`, `Alt+Enter`, or a trailing `\` | Insert a line break |
58
+ | `Esc` | Interrupt the streaming reply (also discards a queued prompt) |
59
+ | `Ctrl+C` | Clear the draft; press again on an empty line to exit |
60
+ | `Ctrl+D` | Exit on an empty line; otherwise delete forward |
61
+ | `Ctrl+A` / `Ctrl+E` | Jump to the start / end of the line |
62
+ | `Ctrl+U` / `Ctrl+W` | Delete to line start / delete previous word |
63
+ | `Ctrl+←` / `Ctrl+→` | Move by word |
64
+ | `↑` / `↓` | Move through the command menu, then wrapped lines, then history |
65
+ | `Tab` | Complete the highlighted command |
66
+ | `Ctrl+/` | Search all slash commands (fuzzy) |
67
+ | `Ctrl+R` | Search prompt history (fuzzy) |
68
+ | `y` / `n` | Approve or deny a pending file or shell operation |
69
+
70
+ Typing `/` opens the command menu. Typing `@path/to/file` inlines that file as
71
+ context; the path is confined to the workspace like every other local read.
72
+
73
+ ### Slash commands
74
+
75
+ `/help` `/clear` `/new` `/status` `/signin` `/keys` `/agent <id>` `/model <id>`
76
+ `/provider [name]` `/sessions [id]` `/tasks [id|retry <id>|cancel <id>|follow <id>]`
77
+ `/ralph <objective>` `/mcp` `/prompts` `/skills` `/usage` `/local <op>`
78
+ `/mode [name]` `/trust [forget <path>]` `/compact` `/export` `/quit`
79
+
80
+ Press `Enter` while the menu is open to run the highlighted command. `/new`
81
+ starts a fresh server-side conversation (the old one stays in `/sessions`);
82
+ `/clear` only wipes the visible screen.
83
+
84
+ In `/keys`, press `s` to mark a key active. The label (from `key_prefix`) is
85
+ stored in `~/.odysx/config.json` as `activeKeyLabel`; it is a local marker only.
86
+ The backend returns a key's secret only at creation, so switching the marker
87
+ cannot change the credential used on requests — use `odysx auth set-key` for
88
+ that.
89
+
90
+ ### Folder trust
91
+
92
+ The first time Codemind starts in a folder, it asks before granting access:
93
+
94
+ ```
95
+ ⚠ Trust this folder?
96
+ ↑/↓ or 1/2 to choose · Enter confirm · esc exit
97
+
98
+ ❯ 1. Yes, I trust this folder
99
+ 2. No, exit
100
+ ```
101
+
102
+ Trusting is remembered in `~/.odysx/trusted-folders.json`; trusting a parent
103
+ covers its subfolders. Declining exits — there is no partially-trusted session.
104
+ Use `/trust` to list trusted folders and `/trust forget <path>` to make a folder
105
+ ask again. Piped input refuses an untrusted folder instead of prompting.
106
+
107
+ ### Permission modes
108
+
109
+ The active mode appears in the footer and is shared by the REPL, one-shot
110
+ commands, and command handlers. Switch with `/mode <name>` or `--mode <name>`,
111
+ or set `"permissionMode"` in `~/.odysx/config.json`. Default: `manual`.
112
+
113
+ | Mode | Reads | Writes | Delete / move / exec |
114
+ | --- | --- | --- | --- |
115
+ | `plan` | allowed | refused | refused |
116
+ | `guide` | allowed | printed, not run | printed, not run |
117
+ | `manual` | allowed | asks each time | asks each time |
118
+ | `auto` | allowed | runs | asks each time |
119
+
120
+ `guide` prints the exact `odysx local …` line so you can review and run it
121
+ yourself. Even `auto` never runs an irreversible operation without approval.
122
+
123
+ ### Permission prompt
124
+
125
+ Risky workspace operations (`write`, `exec`, `delete`, `move`) never run on the
126
+ first ask: the REPL shows the target and, for writes, a before/after diff, and
127
+ waits for `y` or `n`. In non-interactive CLI use, pass `--yes` to approve.
128
+
129
+ ---
130
+
131
+ ## Commands
132
+
133
+ Each command also has a short alias, shown after `|`.
134
+
135
+ | Command | Subcommands |
136
+ | --- | --- |
137
+ | `agents \| a` | `list`, `get <id>`, `create <name>`, `delete <id> [--force]` |
138
+ | `chat \| c` | `[message]` — one-shot with a message, interactive without |
139
+ | `keys \| k` | `create --name <name> [--scopes a,b]`, `list`, `revoke <id>`, `usage <id>` |
140
+ | `auth` | `login --username <u> --password <p> [--api-url <url>]`, `set-key [--key <k>]`, `logout`, `status` |
141
+ | `local \| l` | `read`, `write`, `exec`, `ls`, `pwd`, `which`, `delete`, `move` — see below |
142
+ | `mcp` | `list`, `get <id>`, `register`, `tools [id]`, `discover [id]` |
143
+ | `prompts \| p` | `list`, `get <id-or-slug>`, `resolve <id> --var k=v,…` |
144
+ | `skills \| s` | `list`, `marketplace`, `get <id>` |
145
+
146
+ ### `local` — workspace operations
147
+
148
+ | Subcommand | Arguments and flags |
149
+ | --- | --- |
150
+ | `read <path>` | `--lines <start>-<end>` (`5-` means "to end") |
151
+ | `write <path>` | `--content <text>` — **required**; pass `--content ""` to empty a file |
152
+ | `exec` | `--command <cmd>` (required), `--timeout <seconds>` |
153
+ | `ls [path]` | `--hidden` |
154
+ | `delete <path>` | — |
155
+ | `move <from> <to>` | — |
156
+ | `pwd` | — |
157
+ | `which <command>` | — |
158
+
159
+ Gated operations (`write`, `exec`, `delete`, `move`) need approval: `--yes` in
160
+ the CLI, or `y` at the prompt in the interactive UI.
161
+
162
+ ```bash
163
+ odysx local read src/index.ts --lines 40-80
164
+ odysx local exec --command "npm test" --timeout 120 --yes
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Configuration
170
+
171
+ Settings live in `~/.odysx/config.json`:
172
+
173
+ ```json
174
+ {
175
+ "apiUrl": "http://localhost:8000",
176
+ "apiKey": null,
177
+ "model": "master",
178
+ "provider": "openai",
179
+ "providers": {
180
+ "openai": { "type": "openai", "baseUrl": "https://api.openai.com/v1", "apiKey": "sk-…", "model": "gpt-4o" },
181
+ "ollama": { "type": "openai", "baseUrl": "http://localhost:11434/v1", "model": "llama3.2" },
182
+ "claude": { "type": "anthropic", "apiKey": "sk-ant-…", "model": "claude-sonnet-5" },
183
+ "gemini": { "type": "gemini", "apiKey": "AIza…", "model": "gemini-2.0-flash" }
184
+ }
185
+ }
186
+ ```
187
+
188
+ `provider` selects the active entry; leave it `null` or `"odysx"` to use the
189
+ platform. Any `type: "openai"` entry with a custom `baseUrl` covers
190
+ OpenAI-compatible servers (Groq, Ollama, LM Studio, vLLM, Together, …).
191
+
192
+ | Environment variable | Effect |
193
+ | --- | --- |
194
+ | `ODYSX_API_KEY` | API key; overrides the config file |
195
+ | `ODYSX_TOKEN` | JWT, as an alternative to a key |
196
+ | `ODYSX_API_URL` | Platform base URL |
197
+ | `ODYSX_WORKSPACE` | Workspace root for `local` operations |
198
+ | `NO_COLOR` | Disable colour (any non-empty value) |
199
+
200
+ Environment-provided credentials are used at runtime but are **never written
201
+ back** to `config.json` — a later `/model` change cannot persist a key that was
202
+ exported in your shell. The config file is written atomically, owner-only.
203
+
204
+ ### Global flags
205
+
206
+ | Flag | Effect |
207
+ | --- | --- |
208
+ | `--legacy-repl` | Use the simple readline REPL instead of the full-screen UI |
209
+ | `--no-color` | Disable colour (also honours `NO_COLOR` and piped output) |
210
+ | `--color` | Force colour even when stdout is not a TTY |
211
+ | `--mode <name>` | Set the permission mode (`plan`, `guide`, `manual`, `auto`) |
212
+
213
+ Without a TTY on stdin, or with stdout redirected, the CLI falls back to the
214
+ readline REPL automatically so piped input works:
215
+
216
+ ```bash
217
+ printf '/status\n/quit\n' | odysx
218
+ ```
219
+
220
+ ---
221
+
222
+ ## Workspace confinement
223
+
224
+ Every `local` path is resolved against the workspace root (the directory
225
+ `odysx` was launched from, or `ODYSX_WORKSPACE`/the config file), then
226
+ resolved through symlinks and junctions and compared case-insensitively on
227
+ Windows and macOS. A path that leaves the root is refused, including one that
228
+ escapes through a link inside the tree.
229
+
230
+ Shell commands additionally pass a denylist of obviously destructive patterns.
231
+ That is a seatbelt for typos, not a sandbox — `local exec` runs with your
232
+ privileges, and everything not caught by the denylist still goes through the
233
+ approval prompt.
234
+
235
+ ---
236
+
237
+ ## Development
238
+
239
+ | Script | Purpose |
240
+ | --- | --- |
241
+ | `npm run build` | Compile TypeScript to `dist/` |
242
+ | `npm run dev` | Run `src/index.ts` directly via tsx |
243
+ | `npm test` | Node's test runner over `test/*.mjs` |
244
+ | `npm run typecheck` | `tsc --noEmit` |
245
+ | `npm run lint` | ESLint (`src/` is TS 7, which typescript-eslint cannot parse yet) |
246
+
247
+ Tests run against the **compiled** output in `dist/`, so run `npm run build`
248
+ before `npm test`.
249
+
250
+ ```
251
+ src/
252
+ index.ts entry point: TTY detection, signal/alt-screen handling, command routing
253
+ commands/ one module per CLI command group (self-registers a schema)
254
+ core/
255
+ registry/ builds the commander program from registered schemas
256
+ schema/ the command schema types (meta-driven command definitions)
257
+ provider/ API client, SSE reader, idle timeouts, external providers
258
+ config/ ~/.odysx/config.json load/save
259
+ workspace/ root detection and path confinement
260
+ terminal.ts alt-screen lifecycle, colour policy, exit flushing
261
+ ui/ the Ink REPL
262
+ app.tsx state + orchestration only
263
+ layouts/ screen composition
264
+ components/ transcript, input bar, overlays, banner
265
+ input/ keyboard router
266
+ hooks/ controls/ per-flow state and interactive widgets
267
+ utils/ pure helpers (text editing, markdown, terminal width)
268
+ ```
269
+
270
+ A few invariants worth knowing before changing the UI:
271
+
272
+ - **The transcript is split, not filtered.** Ink's `<Static>` writes each item
273
+ once and tracks a high-water-mark index, so the settled array must always be
274
+ a growing prefix. Pulling a message out of the middle re-emits or loses it.
275
+ - **Untrusted text is sanitized before rendering.** Model output, `@file`
276
+ contents, and server error strings can all contain escape sequences; they go
277
+ through `utils/terminal-text.ts` before they reach the terminal.
278
+ - **Width is display columns, not string length.** CJK and emoji occupy two
279
+ columns, and layout that measures `.length` misaligns.
280
+ - **Commands are schema-driven.** Add a command by registering a schema and a
281
+ handler; `test/commands.test.mjs` fails if the menu and the handlers drift
282
+ apart.
283
+
284
+ ## Troubleshooting
285
+
286
+ | Symptom | Cause |
287
+ | --- | --- |
288
+ | "Raw mode is not supported" | stdin is not a TTY — pipe input, or run without redirection |
289
+ | Output has no colour | stdout is piped, `NO_COLOR` is set, or `TERM=dumb` |
290
+ | The screen looks wrong after a crash | the stack trace is written to `~/.odysx/last-crash.log` |
291
+ | "Cannot connect to …" | the platform is not running, or `ODYSX_API_URL` is wrong |
292
+
293
+ Prompt history is stored in `~/.odysx/history.json`, with credential-shaped
294
+ values and secrets passed to `--content`/`--key`/`--password` redacted.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=agents.d.ts.map
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Agent commands — list, get, create, delete agents.
3
+ */
4
+ import { registerCommand } from "../core/registry/index.js";
5
+ import { apiCall, urlSegment } from "../core/provider/index.js";
6
+ const schema = {
7
+ name: "agents",
8
+ description: "Manage and interact with agents",
9
+ aliases: ["a"],
10
+ options: [],
11
+ };
12
+ async function handleList() {
13
+ const res = await apiCall("/api/v1/agents");
14
+ if (!res.ok)
15
+ return { exitCode: 1, error: res.error };
16
+ return { exitCode: 0, data: res.data };
17
+ }
18
+ async function handleGet(agentId) {
19
+ if (!agentId)
20
+ return { exitCode: 1, error: "Usage: agents get <agent-id>" };
21
+ const res = await apiCall(`/api/v1/agents/${urlSegment(agentId)}`);
22
+ if (!res.ok)
23
+ return { exitCode: 1, error: res.error };
24
+ return { exitCode: 0, data: res.data };
25
+ }
26
+ async function handleCreate(args) {
27
+ const name = args.find((a) => !a.startsWith("-"));
28
+ if (!name)
29
+ return { exitCode: 1, error: "Usage: agents create <name>" };
30
+ const type = args.includes("--type") ? args[args.indexOf("--type") + 1] : "simple";
31
+ const desc = args.includes("--description") ? args[args.indexOf("--description") + 1] : "";
32
+ const res = await apiCall("/api/v1/agents", {
33
+ method: "POST",
34
+ body: { name, agent_type: type, description: desc },
35
+ });
36
+ if (!res.ok)
37
+ return { exitCode: 1, error: res.error };
38
+ return { exitCode: 0, data: res.data, message: `Agent created` };
39
+ }
40
+ /**
41
+ * Ask a yes/no question on the terminal.
42
+ *
43
+ * Resolves null when there is no terminal to ask (piped stdin, CI, EOF). The
44
+ * previous implementation waited for a `data` event that never arrives in
45
+ * those cases, so the process either hung or exited 0 having done nothing.
46
+ */
47
+ async function confirm(question) {
48
+ if (!process.stdin.isTTY)
49
+ return null;
50
+ process.stdout.write(question);
51
+ const readline = await import("node:readline/promises");
52
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
53
+ try {
54
+ return (await rl.question("")).trim();
55
+ }
56
+ finally {
57
+ rl.close();
58
+ }
59
+ }
60
+ async function handleDelete(agentId, force) {
61
+ if (!agentId)
62
+ return { exitCode: 1, error: "Usage: agents delete <agent-id>" };
63
+ if (!force) {
64
+ const answer = await confirm(`Delete agent ${agentId}? [y/N] `);
65
+ if (answer === null) {
66
+ return {
67
+ exitCode: 1,
68
+ error: "Refusing to delete without confirmation: stdin is not a terminal (pass --force)",
69
+ };
70
+ }
71
+ if (answer !== "y" && answer !== "yes")
72
+ return { exitCode: 0, message: "Cancelled" };
73
+ }
74
+ const res = await apiCall(`/api/v1/agents/${urlSegment(agentId)}`, { method: "DELETE" });
75
+ if (!res.ok)
76
+ return { exitCode: 1, error: res.error };
77
+ return { exitCode: 0, message: `Agent ${agentId} deleted` };
78
+ }
79
+ registerCommand(schema, async (_args, opts) => {
80
+ const sub = opts.args[0];
81
+ const rest = opts.args.slice(1);
82
+ const force = opts.force;
83
+ switch (sub) {
84
+ case "list": return handleList();
85
+ case "get": return handleGet(rest[0] ?? "");
86
+ case "create": return handleCreate(rest);
87
+ case "delete": return handleDelete(rest[0] ?? "", force);
88
+ default: return handleList();
89
+ }
90
+ });
91
+ //# sourceMappingURL=agents.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Auth commands — login, logout, set-key, status.
3
+ */
4
+ import { registerCommand } from "../core/registry/index.js";
5
+ import { login, setApiKey, logout, authStatus } from "../core/auth/index.js";
6
+ const schema = {
7
+ name: "auth",
8
+ description: "Authenticate with the OdysX platform",
9
+ group: "config",
10
+ options: [],
11
+ };
12
+ function parseFlag(args, flag) {
13
+ const idx = args.indexOf(flag);
14
+ return idx !== -1 ? args[idx + 1] : undefined;
15
+ }
16
+ registerCommand(schema, async (_args, opts) => {
17
+ const sub = opts.args[0];
18
+ const rest = opts.args.slice(1);
19
+ switch (sub) {
20
+ case "login": {
21
+ const username = parseFlag(rest, "--username") ?? parseFlag(rest, "-u");
22
+ const password = parseFlag(rest, "--password") ?? parseFlag(rest, "-p");
23
+ const apiUrl = parseFlag(rest, "--api-url");
24
+ return login(username ?? "", password ?? "", apiUrl);
25
+ }
26
+ case "set-key": {
27
+ const key = parseFlag(rest, "--key") ?? rest.find((a) => !a.startsWith("-"));
28
+ return setApiKey(key ?? "");
29
+ }
30
+ case "logout": return logout();
31
+ case "status": return authStatus();
32
+ default: return authStatus();
33
+ }
34
+ });
35
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Chat commands — interactive and one-shot chat with agents.
3
+ *
4
+ * Uses the StreamingMarkdownRenderer for rich inline rendering of
5
+ * markdown responses with syntax highlighting and colorization.
6
+ */
7
+ import { registerCommand } from "../core/registry/index.js";
8
+ import { streamTurn } from "../core/provider/index.js";
9
+ import { StreamingMarkdownRenderer } from "../core/markdown-renderer.js";
10
+ import { clearViewport } from "../core/terminal.js";
11
+ import chalk from "chalk";
12
+ import { randomUUID } from "node:crypto";
13
+ const schema = {
14
+ name: "chat",
15
+ description: "Chat with an agent (interactive or one-shot)",
16
+ aliases: ["c"],
17
+ options: [],
18
+ examples: [
19
+ "odysx chat hello",
20
+ "odysx chat --agent-id research-agent what is quantum computing?",
21
+ ],
22
+ };
23
+ let currentSessionId = "";
24
+ /**
25
+ * One-shot chat: send a message and print the streamed response.
26
+ */
27
+ async function oneShotChat(message, agentId) {
28
+ const sessionId = currentSessionId || randomUUID();
29
+ process.stdout.write("\n");
30
+ const renderer = new StreamingMarkdownRenderer();
31
+ try {
32
+ await streamTurn(message, {
33
+ agentId,
34
+ sessionId,
35
+ onToken: (token) => renderer.processChunk(token),
36
+ onDone: () => {
37
+ renderer.flush();
38
+ process.stdout.write("\n");
39
+ },
40
+ });
41
+ }
42
+ catch (err) {
43
+ return { exitCode: 1, error: err instanceof Error ? err.message : String(err) };
44
+ }
45
+ currentSessionId = sessionId;
46
+ return { exitCode: 0, formatted: true };
47
+ }
48
+ /**
49
+ * Interactive chat loop with rich formatting.
50
+ */
51
+ async function interactiveChat(agentId) {
52
+ const sessionId = randomUUID();
53
+ currentSessionId = sessionId;
54
+ // External providers are stateless — they need the transcript sent with
55
+ // every turn. The platform keeps history server-side keyed by session id.
56
+ const history = [];
57
+ console.log(`\n${chalk.cyan('╔══════════════════════════════════════════════════════════════╗')}`);
58
+ console.log(`${chalk.cyan('║')} ${chalk.bold('OdysX Chat')} ${chalk.gray(`Agent: ${agentId}`)} ${chalk.gray(`Session: ${sessionId.slice(0, 8)}...`)} ${chalk.cyan('║')}`);
59
+ console.log(`${chalk.cyan('╚══════════════════════════════════════════════════════════════╝')}\n`);
60
+ console.log(chalk.gray('Type your message and press Enter. Use /help for commands, /quit to exit.\n'));
61
+ const readline = await import("node:readline");
62
+ const rl = readline.createInterface({
63
+ input: process.stdin,
64
+ output: process.stdout,
65
+ // Enable history and autocomplete
66
+ history: [],
67
+ removeHistoryDuplicates: true,
68
+ });
69
+ const prompt = () => {
70
+ rl.question(chalk.cyan("You: "), async (input) => {
71
+ const msg = input.trim();
72
+ // Handle slash commands
73
+ if (msg.startsWith("/")) {
74
+ const cmd = msg.slice(1).split(" ")[0];
75
+ switch (cmd) {
76
+ case "quit":
77
+ case "exit":
78
+ // Close the interface and let the command loop end normally.
79
+ // `process.exit` here skipped the stdout flush (truncating piped
80
+ // output) and bypassed the terminal-restore contract.
81
+ console.log(chalk.gray("\nGoodbye."));
82
+ rl.close();
83
+ return;
84
+ case "help":
85
+ console.log(chalk.gray("\nAvailable commands:"));
86
+ console.log(chalk.gray(" /help - Show this help"));
87
+ console.log(chalk.gray(" /quit - Exit the chat"));
88
+ console.log(chalk.gray(" /clear - Clear the screen"));
89
+ console.log(chalk.gray(" /history - Show conversation history"));
90
+ console.log(chalk.gray(" /stats - Show session statistics\n"));
91
+ prompt();
92
+ return;
93
+ case "clear":
94
+ // No-op when piped: a raw wipe would land in the captured output.
95
+ clearViewport();
96
+ prompt();
97
+ return;
98
+ case "history":
99
+ console.log(chalk.gray("\n[Conversation history is stored locally]"));
100
+ console.log(chalk.gray(` Session ID: ${sessionId}`));
101
+ console.log(chalk.gray(` Messages exchanged: use /stats for count\n`));
102
+ prompt();
103
+ return;
104
+ case "stats":
105
+ console.log(chalk.gray(`\n Session: ${sessionId}`));
106
+ console.log(chalk.gray(` Agent: ${agentId}\n`));
107
+ prompt();
108
+ return;
109
+ default:
110
+ console.log(chalk.gray(`\nUnknown command: /${cmd}. Type /help for available commands.\n`));
111
+ prompt();
112
+ return;
113
+ }
114
+ }
115
+ if (!msg) {
116
+ prompt();
117
+ return;
118
+ }
119
+ // Display user message
120
+ console.log(chalk.gray("You: ") + chalk.white(msg) + "\n");
121
+ // Stream agent response with markdown rendering
122
+ process.stdout.write(chalk.cyan("Agent: "));
123
+ const renderer = new StreamingMarkdownRenderer();
124
+ const startTime = Date.now();
125
+ let reply = "";
126
+ try {
127
+ await streamTurn(msg, {
128
+ agentId,
129
+ sessionId,
130
+ history,
131
+ onToken: (token) => {
132
+ reply += token;
133
+ renderer.processChunk(token);
134
+ },
135
+ onDone: () => {
136
+ renderer.flush();
137
+ const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
138
+ console.log(chalk.gray(`\n (${elapsed}s)\n`));
139
+ prompt();
140
+ },
141
+ });
142
+ history.push({ role: "user", content: msg }, { role: "assistant", content: reply });
143
+ }
144
+ catch (err) {
145
+ console.error(chalk.red(`\nError: ${err instanceof Error ? err.message : err}\n`));
146
+ prompt();
147
+ }
148
+ });
149
+ };
150
+ // Show welcome message
151
+ console.log(chalk.gray("Tip: Type /help anytime for commands.\n"));
152
+ // Keep the process alive until the interface closes — and actually settle
153
+ // when it does. A never-resolving promise meant a closed stdin (Ctrl+D,
154
+ // a dropped pipe) let the process exit mid-stream with status 0.
155
+ return new Promise((resolve) => {
156
+ rl.once("close", () => resolve({ exitCode: 0, formatted: true }));
157
+ prompt();
158
+ });
159
+ }
160
+ /** Parse args, detect --agent-id, and route into interactive vs one-shot. */
161
+ registerCommand(schema, async (_args, opts) => {
162
+ const args = opts.args;
163
+ // Parse --agent-id flag
164
+ const agentIdx = args.indexOf("--agent-id");
165
+ const agentId = agentIdx !== -1 ? args[agentIdx + 1] ?? "master" : "master";
166
+ // Everything else is the message (commander already strips "chat")
167
+ const messageParts = args.filter((a, i) => {
168
+ if (a === "--agent-id")
169
+ return false;
170
+ if (agentIdx !== -1 && i === agentIdx + 1)
171
+ return false;
172
+ return true;
173
+ });
174
+ const message = messageParts.join(" ").trim();
175
+ if (!message) {
176
+ return interactiveChat(agentId);
177
+ }
178
+ return oneShotChat(message, agentId);
179
+ });
180
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=keys.d.ts.map