@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.
- package/dist/core/provider/index.d.ts +52 -10
- package/dist/core/provider/index.js +99 -12
- package/package.json +6 -1
- package/dist/commands/agents.d.ts.map +0 -1
- package/dist/commands/agents.js.map +0 -1
- package/dist/commands/auth.d.ts.map +0 -1
- package/dist/commands/auth.js.map +0 -1
- package/dist/commands/chat.d.ts.map +0 -1
- package/dist/commands/chat.js.map +0 -1
- package/dist/commands/keys.d.ts.map +0 -1
- package/dist/commands/keys.js.map +0 -1
- package/dist/commands/local.d.ts.map +0 -1
- package/dist/commands/local.js.map +0 -1
- package/dist/commands/mcp.d.ts.map +0 -1
- package/dist/commands/mcp.js.map +0 -1
- package/dist/commands/prompts.d.ts.map +0 -1
- package/dist/commands/prompts.js.map +0 -1
- package/dist/commands/skills.d.ts.map +0 -1
- package/dist/commands/skills.js.map +0 -1
- package/dist/core/auth/index.d.ts.map +0 -1
- package/dist/core/auth/index.js.map +0 -1
- package/dist/core/config/index.d.ts.map +0 -1
- package/dist/core/config/index.js.map +0 -1
- package/dist/core/history.d.ts.map +0 -1
- package/dist/core/history.js.map +0 -1
- package/dist/core/markdown-renderer.d.ts.map +0 -1
- package/dist/core/markdown-renderer.js.map +0 -1
- package/dist/core/permissions/index.d.ts.map +0 -1
- package/dist/core/permissions/index.js.map +0 -1
- package/dist/core/provider/external.d.ts.map +0 -1
- package/dist/core/provider/external.js.map +0 -1
- package/dist/core/provider/index.d.ts.map +0 -1
- package/dist/core/provider/index.js.map +0 -1
- package/dist/core/registry/index.d.ts.map +0 -1
- package/dist/core/registry/index.js.map +0 -1
- package/dist/core/schema/types.d.ts.map +0 -1
- package/dist/core/schema/types.js.map +0 -1
- package/dist/core/terminal.d.ts.map +0 -1
- package/dist/core/terminal.js.map +0 -1
- package/dist/core/workspace/index.d.ts.map +0 -1
- package/dist/core/workspace/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/ui/app.d.ts.map +0 -1
- package/dist/ui/app.js.map +0 -1
- package/dist/ui/commands/cases/catalog.d.ts.map +0 -1
- package/dist/ui/commands/cases/catalog.js.map +0 -1
- package/dist/ui/commands/cases/misc.d.ts.map +0 -1
- package/dist/ui/commands/cases/misc.js.map +0 -1
- package/dist/ui/commands/cases/tasks.d.ts.map +0 -1
- package/dist/ui/commands/cases/tasks.js.map +0 -1
- package/dist/ui/commands/runCommand.d.ts.map +0 -1
- package/dist/ui/commands/runCommand.js.map +0 -1
- package/dist/ui/components/AgentPicker.d.ts.map +0 -1
- package/dist/ui/components/AgentPicker.js.map +0 -1
- package/dist/ui/components/AuthPicker.d.ts.map +0 -1
- package/dist/ui/components/AuthPicker.js.map +0 -1
- package/dist/ui/components/Banner.d.ts.map +0 -1
- package/dist/ui/components/Banner.js.map +0 -1
- package/dist/ui/components/CommandMenu.d.ts.map +0 -1
- package/dist/ui/components/CommandMenu.js.map +0 -1
- package/dist/ui/components/ErrorBoundary.d.ts.map +0 -1
- package/dist/ui/components/ErrorBoundary.js.map +0 -1
- package/dist/ui/components/InputBar.d.ts.map +0 -1
- package/dist/ui/components/InputBar.js.map +0 -1
- package/dist/ui/components/KeysPanel.d.ts.map +0 -1
- package/dist/ui/components/KeysPanel.js.map +0 -1
- package/dist/ui/components/MessageView.d.ts.map +0 -1
- package/dist/ui/components/MessageView.js.map +0 -1
- package/dist/ui/components/PermissionPrompt.d.ts.map +0 -1
- package/dist/ui/components/PermissionPrompt.js.map +0 -1
- package/dist/ui/components/Pickers.d.ts.map +0 -1
- package/dist/ui/components/Pickers.js.map +0 -1
- package/dist/ui/components/SearchOverlay.d.ts.map +0 -1
- package/dist/ui/components/SearchOverlay.js.map +0 -1
- package/dist/ui/components/SessionPicker.d.ts.map +0 -1
- package/dist/ui/components/SessionPicker.js.map +0 -1
- package/dist/ui/components/WorkingIndicator.d.ts.map +0 -1
- package/dist/ui/components/WorkingIndicator.js.map +0 -1
- package/dist/ui/controls/ApiKeyEntry.d.ts.map +0 -1
- package/dist/ui/controls/ApiKeyEntry.js.map +0 -1
- package/dist/ui/controls/MultiSelect.d.ts.map +0 -1
- package/dist/ui/controls/MultiSelect.js.map +0 -1
- package/dist/ui/hooks/useAgentPicker.d.ts.map +0 -1
- package/dist/ui/hooks/useAgentPicker.js.map +0 -1
- package/dist/ui/hooks/useAuthFlow.d.ts.map +0 -1
- package/dist/ui/hooks/useAuthFlow.js.map +0 -1
- package/dist/ui/hooks/useKeysFlow.d.ts.map +0 -1
- package/dist/ui/hooks/useKeysFlow.js.map +0 -1
- package/dist/ui/hooks/useSessionPicker.d.ts.map +0 -1
- package/dist/ui/hooks/useSessionPicker.js.map +0 -1
- package/dist/ui/hooks/useTerminalSize.d.ts.map +0 -1
- package/dist/ui/hooks/useTerminalSize.js.map +0 -1
- package/dist/ui/input/keyRouter.d.ts.map +0 -1
- package/dist/ui/input/keyRouter.js.map +0 -1
- package/dist/ui/layouts/ScreenLayout.d.ts.map +0 -1
- package/dist/ui/layouts/ScreenLayout.js.map +0 -1
- package/dist/ui/shared/types.d.ts.map +0 -1
- package/dist/ui/shared/types.js.map +0 -1
- package/dist/ui/theme.d.ts.map +0 -1
- package/dist/ui/theme.js.map +0 -1
- package/dist/ui/utils/markdown.d.ts.map +0 -1
- package/dist/ui/utils/markdown.js.map +0 -1
- package/dist/ui/utils/mentions.d.ts.map +0 -1
- package/dist/ui/utils/mentions.js.map +0 -1
- package/dist/ui/utils/terminal-text.d.ts.map +0 -1
- package/dist/ui/utils/terminal-text.js.map +0 -1
- package/dist/ui/utils/text.d.ts.map +0 -1
- package/dist/ui/utils/text.js.map +0 -1
- package/eslint.config.js +0 -40
- package/graphify-out/GRAPH_REPORT.md +0 -140
- package/graphify-out/cache/1236b1806943f8eb5c64fece9fb448149370f4a1b52b32f0977ad528d7911291.json +0 -1
- package/graphify-out/cache/15cbf641dcc0fd641c18da872214918203a1f64baa7ac8430e4702ef32d18b02.json +0 -1
- package/graphify-out/cache/1abc52745bb46f6cc5a528530e2bc1f368c26e348dff85cdde5cad6f275d7177.json +0 -1
- package/graphify-out/cache/1c7815c37c13177e98895e272285f6151a8d0807478fc843ec452634b3e9912d.json +0 -1
- package/graphify-out/cache/1ec38c39f044f329c78642b61d6394fb8e15d0014335f32947d1f5c7b88c02bc.json +0 -1
- package/graphify-out/cache/20c9b57ff76dbb9d57cbd00659b0a42d2b28dd2abacf1ef4143cc67a5b6fe7f4.json +0 -1
- package/graphify-out/cache/285e11876884eb619e779d540cd957b33e70f14c67ecc26c9b9755aa9cedd717.json +0 -1
- package/graphify-out/cache/2c0a9c49ab51f4e0f07543b4e941bf802b7db31fa607c4cee8e595575be68fe7.json +0 -1
- package/graphify-out/cache/3025e6c2756c79ccaadd51d611f25a8b6630a6a11ce1b4e6e261b3e033dc194f.json +0 -1
- package/graphify-out/cache/4801a686ddfa0a52824a4fc3d65443cbb0ab9f0b030af67d02fccb520c584a08.json +0 -1
- package/graphify-out/cache/4f8fd96f38aa7d0293b4fab60c4581c4f3e68f4533c664c9cd78d1c53bea1cba.json +0 -1
- package/graphify-out/cache/5928e562b0f5700184b810e2403f4aa685e2b93c3c584c10460562b514c40fdd.json +0 -1
- package/graphify-out/cache/66132486efb0a4cfaeea766448f1f15bb33635808714052e7e24e5b00fbc984f.json +0 -1
- package/graphify-out/cache/66ab27669e7ec685130063662af9f30018c267f7639b4af4b0504a98282c383a.json +0 -1
- package/graphify-out/cache/6ff6b3dd433b5ffe96e166263a203dd622397e419dc00bb676824988b7defeab.json +0 -1
- package/graphify-out/cache/7a00a49932177a6215e2590b1ddfd6f1d8494792f693068e9d427d16b165d370.json +0 -1
- package/graphify-out/cache/7b681bc5182f40f707f1c0b16b78af38efffa62a1df315d10878f4de888408ef.json +0 -1
- package/graphify-out/cache/81196d44e50ac0b276d826a531ed10c425a528b298e3fe18e8d5a3eec996e9d5.json +0 -1
- package/graphify-out/cache/8934e9b32dea6e66fdc34fa1681b287ff1335c389917e0fc6ee2fc573e23e87b.json +0 -1
- package/graphify-out/cache/975f6c99807f86b79c80ca40c783618e2080a927eaebe6ea3db37b869f048851.json +0 -1
- package/graphify-out/cache/9ab98f08626fd8190462595e38de828293ad184db8df5e1177b05a8fe290faa1.json +0 -1
- package/graphify-out/cache/9c434a6796d7932b6e87a908c155c09cb2b8d097fc55f141f0302b6600f94749.json +0 -1
- package/graphify-out/cache/ac5cf4c489dc417c1f6ea728d0b6ba12ac7087bc6c2e736697ff3024b4d4e534.json +0 -1
- package/graphify-out/cache/ae5083b5c1dca3e5c6af485e7f6eb8a08ff8b382cdecf92ab5e0902053442afe.json +0 -1
- package/graphify-out/cache/b274057fc2e0118cf2746d1d8060841122bb2a2b0305566fc3f32d3a51e08bcc.json +0 -1
- package/graphify-out/cache/b39beef31da682387f030c0d149f6cd5b3e66effbf936cc8430db15360759dda.json +0 -1
- package/graphify-out/cache/bf3c6a36bb72820bc11cbf4a5c49067d1f62013d4686c019a4dbd9951b1e980e.json +0 -1
- package/graphify-out/cache/c034e156028d1a58b89bce659726e9a4065ddc4d2b560d6bce7a206fdff8dad3.json +0 -1
- package/graphify-out/cache/c619b5bbe8d1f427fbd7816d1e9fcfaf90d7201b020ae6b578166aeb9cb20683.json +0 -1
- package/graphify-out/cache/c8db77a9da0b0f601acfa50a620f31155cdda0d0cc0f2285adcea19e77194ee6.json +0 -1
- package/graphify-out/cache/ca664791ec7741a2077d9e7c10384142d30e7a3b77b388df719c315da608d57d.json +0 -1
- package/graphify-out/cache/cba43a116186bd55c8a63368dea4eee4a8123b2bec0a42df6efb3254f89f9a7a.json +0 -1
- package/graphify-out/cache/cd51cbb3dad1cf34417b9761fe2eb184a9f57d23dc86e45630e63bfa2ecafddc.json +0 -1
- package/graphify-out/cache/d06738cde193b34a136b94104220c17e0212b814b3e4d7ff399105635cae1a03.json +0 -1
- package/graphify-out/cache/d093c19f0169c0398eeb1360895b1c16ecc50abc59f4be8eec3f6fd27c89a6e5.json +0 -1
- package/graphify-out/cache/da8f75c438531d232fe114d5cbf2374576ce842a5fb87c7e5a88b78fdb334e5e.json +0 -1
- package/graphify-out/cache/e35798fa04ddede548a6953bdea506bd7d0788dfed4e8a8ea6ae77b1b60ef5e0.json +0 -1
- package/graphify-out/cache/e5a38c254719000487098782125e15e2e982c07d66b99d359ed1781f30f9fc8c.json +0 -1
- package/graphify-out/cache/e6e4c4a5a7200ee0154585b5d6538f699b0a746dbded3164f8391f06ce7cb212.json +0 -1
- package/graphify-out/cache/ea8d0838df6309b673b031f616b253af957898ee7289d25a541fa6183b732e4e.json +0 -1
- package/graphify-out/cache/ebaee92b0e881efd7a08f3143e2c1803310396b4651d4f77532003c699cc6836.json +0 -1
- package/graphify-out/cache/edf8543318a9e60d56d04704078da6c37202ddd6fdfc83144fe2b94fe19b80ef.json +0 -1
- package/graphify-out/cache/efca19d3668035f11126fc9eccbeab290abfa94babf3f9a8706de81d17aba263.json +0 -1
- package/graphify-out/cache/f1480bb642025ebd6d99986cdd8a7d5726897ec038300e4b095c9c938435dfad.json +0 -1
- package/graphify-out/cache/f459f21277f03865f732affb175b1b092954dae5967f27b3cd1864466e3e24f4.json +0 -1
- package/graphify-out/cache/f899e37e864010b30f4c196e86082d7bd022a0df032005e0407883ebcec36514.json +0 -1
- package/graphify-out/cache/fb3cbe07fbcd97c536cff9c6bc343c35f22d49613f05c53ad30ef67a75c5d93e.json +0 -1
- package/graphify-out/cache/fd3dc682b1ca2f5ae03b50d6b0e045ae50f5701c0a21c5a388d77ef482939d3a.json +0 -1
- package/graphify-out/graph.html +0 -257
- package/graphify-out/graph.json +0 -4396
- package/scripts/e2e-external.mjs +0 -65
- package/scripts/live-agents.mjs +0 -6
- package/scripts/live-stream.mjs +0 -51
- package/src/commands/agents.ts +0 -91
- package/src/commands/auth.ts +0 -39
- package/src/commands/chat.ts +0 -198
- package/src/commands/keys.ts +0 -83
- package/src/commands/local.ts +0 -302
- package/src/commands/mcp.ts +0 -74
- package/src/commands/prompts.ts +0 -58
- package/src/commands/skills.ts +0 -43
- package/src/core/auth/index.ts +0 -101
- package/src/core/config/index.ts +0 -152
- package/src/core/history.ts +0 -79
- package/src/core/markdown-renderer.ts +0 -420
- package/src/core/permissions/index.ts +0 -99
- package/src/core/provider/external.ts +0 -312
- package/src/core/provider/index.ts +0 -517
- package/src/core/registry/index.ts +0 -250
- package/src/core/schema/types.ts +0 -106
- package/src/core/terminal.ts +0 -124
- package/src/core/workspace/index.ts +0 -216
- package/src/index.ts +0 -401
- package/src/ui/app.tsx +0 -644
- package/src/ui/commands/cases/catalog.ts +0 -76
- package/src/ui/commands/cases/misc.ts +0 -293
- package/src/ui/commands/cases/tasks.ts +0 -115
- package/src/ui/commands/runCommand.ts +0 -178
- package/src/ui/components/Banner.tsx +0 -63
- package/src/ui/components/CommandMenu.tsx +0 -63
- package/src/ui/components/ErrorBoundary.tsx +0 -75
- package/src/ui/components/InputBar.tsx +0 -227
- package/src/ui/components/KeysPanel.tsx +0 -115
- package/src/ui/components/MessageView.tsx +0 -226
- package/src/ui/components/Pickers.tsx +0 -234
- package/src/ui/components/SearchOverlay.tsx +0 -65
- package/src/ui/components/WorkingIndicator.tsx +0 -35
- package/src/ui/controls/ApiKeyEntry.tsx +0 -29
- package/src/ui/controls/MultiSelect.tsx +0 -55
- package/src/ui/hooks/useAgentPicker.ts +0 -64
- package/src/ui/hooks/useAuthFlow.ts +0 -47
- package/src/ui/hooks/useKeysFlow.ts +0 -157
- package/src/ui/hooks/useSessionPicker.ts +0 -84
- package/src/ui/hooks/useTerminalSize.ts +0 -36
- package/src/ui/input/keyRouter.ts +0 -627
- package/src/ui/layouts/ScreenLayout.tsx +0 -202
- package/src/ui/shared/types.ts +0 -160
- package/src/ui/theme.ts +0 -53
- package/src/ui/utils/markdown.ts +0 -255
- package/src/ui/utils/mentions.ts +0 -40
- package/src/ui/utils/terminal-text.ts +0 -130
- package/src/ui/utils/text.ts +0 -174
- package/test/commands.test.mjs +0 -127
- package/test/config.test.mjs +0 -123
- package/test/history.test.mjs +0 -42
- package/test/keyrouter.test.mjs +0 -324
- package/test/layout.test.mjs +0 -271
- package/test/markdown.test.mjs +0 -92
- package/test/mentions.test.mjs +0 -51
- package/test/permissions.test.mjs +0 -130
- package/test/provider.test.mjs +0 -287
- package/test/terminal-text.test.mjs +0 -116
- package/test/text.test.mjs +0 -134
- package/test/workspace.test.mjs +0 -101
- package/tsconfig.json +0 -32
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Catalog listing commands: /mcp, /prompts, /skills.
|
|
3
|
-
*/
|
|
4
|
-
import type { CommandCtx } from "../../shared/types.js";
|
|
5
|
-
|
|
6
|
-
/** /mcp — list registered MCP servers. */
|
|
7
|
-
export const runMcp = async (ctx: CommandCtx): Promise<void> => {
|
|
8
|
-
const { apiCall } = await import("../../../core/provider/index.js");
|
|
9
|
-
const res = await apiCall<Array<{ id?: string; name?: string; url?: string; status?: string }>>("/api/v1/mcp-servers");
|
|
10
|
-
if (!res.ok) {
|
|
11
|
-
ctx.addMessage(`✗ ${res.error}`);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (!res.data.length) {
|
|
15
|
-
ctx.addMessage("No MCP servers registered. Register one: odysx mcp register");
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
ctx.addMessage(
|
|
19
|
-
`MCP servers (${res.data.length}):\n` +
|
|
20
|
-
res.data.map((s) => ` ${(s.name || s.id || "?").padEnd(24)} ${s.status ?? ""}`).join("\n"),
|
|
21
|
-
);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/** /prompts [slug] — list templates or render one template's body. */
|
|
25
|
-
export const runPrompts = async (arg: string, ctx: CommandCtx): Promise<void> => {
|
|
26
|
-
const { apiCall } = await import("../../../core/provider/index.js");
|
|
27
|
-
if (arg.trim()) {
|
|
28
|
-
// Resolve one template by id or slug and show its rendered body.
|
|
29
|
-
let res = await apiCall<{ name?: string; content?: string; template?: string }>(
|
|
30
|
-
`/api/v1/prompt-templates/${encodeURIComponent(arg.trim())}`,
|
|
31
|
-
);
|
|
32
|
-
if (!res.ok) {
|
|
33
|
-
res = await apiCall(`/api/v1/prompt-templates/slug/${encodeURIComponent(arg.trim())}`);
|
|
34
|
-
}
|
|
35
|
-
if (!res.ok) {
|
|
36
|
-
ctx.addMessage(`✗ ${res.error}`);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
ctx.addMessage(`${res.data.name ?? arg}\n\n${(res.data.content ?? res.data.template ?? "").slice(0, 600)}`);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const res = await apiCall<Array<{ id?: string; name?: string; slug?: string; description?: string }>>("/api/v1/prompt-templates");
|
|
43
|
-
if (!res.ok) {
|
|
44
|
-
ctx.addMessage(`✗ ${res.error}`);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (!res.data.length) {
|
|
48
|
-
ctx.addMessage("No prompt templates found.");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
ctx.addMessage(
|
|
52
|
-
`Prompt templates (${res.data.length}) — view with /prompts <slug>:\n` +
|
|
53
|
-
res.data.slice(0, 15).map((p) => ` ${(p.slug || p.id || "?").padEnd(24)} ${p.name ?? ""}`).join("\n"),
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/** /skills — list installed skills. */
|
|
58
|
-
export const runSkills = async (ctx: CommandCtx): Promise<void> => {
|
|
59
|
-
const { apiCall } = await import("../../../core/provider/index.js");
|
|
60
|
-
const res = await apiCall<Array<{ id?: string; name?: string; description?: string }>>("/api/v1/skills");
|
|
61
|
-
if (!res.ok) {
|
|
62
|
-
ctx.addMessage(`✗ ${res.error}`);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (!res.data.length) {
|
|
66
|
-
ctx.addMessage("No skills installed. Browse: odysx skills marketplace");
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
ctx.addMessage(
|
|
70
|
-
`Skills (${res.data.length}):\n` +
|
|
71
|
-
res.data
|
|
72
|
-
.slice(0, 15)
|
|
73
|
-
.map((s) => ` ${(s.name || s.id || "?").padEnd(24)} ${s.description?.slice(0, 48) ?? ""}`)
|
|
74
|
-
.join("\n"),
|
|
75
|
-
);
|
|
76
|
-
};
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Misc slash-command bodies: help/status/model/sessions/usage/export/local/quit.
|
|
3
|
-
*/
|
|
4
|
-
import type { CommandCtx, PendingOp } from "../../shared/types.js";
|
|
5
|
-
import { SLASH_COMMANDS } from "../../shared/types.js";
|
|
6
|
-
import { getConfig } from "../../../core/config/index.js";
|
|
7
|
-
|
|
8
|
-
/** /help — the command table. */
|
|
9
|
-
export const runHelp = (ctx: CommandCtx): void => {
|
|
10
|
-
ctx.addMessage(
|
|
11
|
-
"Commands:\n" +
|
|
12
|
-
SLASH_COMMANDS.map((c) => ` /${c.name}${c.args ? " " + c.args : ""}`.padEnd(18) + c.description).join("\n"),
|
|
13
|
-
);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/** /status — session info block. */
|
|
17
|
-
export const runStatus = async (ctx: CommandCtx): Promise<void> => {
|
|
18
|
-
const { getWorkspaceRoot, isFolderTrusted } = await import("../../../core/workspace/index.js");
|
|
19
|
-
const { getPermissionMode } = await import("../../../core/permissions/index.js");
|
|
20
|
-
ctx.addMessage(
|
|
21
|
-
`Session: ${ctx.sessionId().slice(0, 8)}\nAgent: ${ctx.agentId}\n` +
|
|
22
|
-
`Auth: ${ctx.config.apiKey ? "api-key" : ctx.config.token ? "jwt" : "none"}\n` +
|
|
23
|
-
`API: ${ctx.config.apiUrl}\nWorkspace: ${getWorkspaceRoot()}\n` +
|
|
24
|
-
`Permissions: ${getPermissionMode()}\nTrusted: ${isFolderTrusted() ? "yes" : "no"}`,
|
|
25
|
-
);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/** /mode — show or switch the permission posture for workspace operations. */
|
|
29
|
-
export const runMode = async (arg: string, ctx: CommandCtx): Promise<void> => {
|
|
30
|
-
const { PERMISSION_MODES, getPermissionMode, setPermissionMode, isPermissionMode } =
|
|
31
|
-
await import("../../../core/permissions/index.js");
|
|
32
|
-
|
|
33
|
-
const wanted = arg.trim().toLowerCase();
|
|
34
|
-
if (!wanted) {
|
|
35
|
-
const current = getPermissionMode();
|
|
36
|
-
ctx.addMessage(
|
|
37
|
-
`Permission mode: ${current}\n\n` +
|
|
38
|
-
PERMISSION_MODES.map((m) =>
|
|
39
|
-
` ${m.id === current ? "❯" : " "} ${m.id.padEnd(8)}${m.summary}`,
|
|
40
|
-
).join("\n") +
|
|
41
|
-
`\n\nSwitch with /mode <${PERMISSION_MODES.map((m) => m.id).join("|")}>`,
|
|
42
|
-
);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!isPermissionMode(wanted)) {
|
|
47
|
-
ctx.addMessage(
|
|
48
|
-
`Unknown mode '${arg.trim()}'. Choose one of: ${PERMISSION_MODES.map((m) => m.id).join(", ")}`,
|
|
49
|
-
);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
setPermissionMode(wanted);
|
|
53
|
-
ctx.addMessage(`✓ Permission mode: ${wanted}`);
|
|
54
|
-
// A mode that blocks or defers the very command being typed deserves a
|
|
55
|
-
// word, since it stays in effect for every later turn too.
|
|
56
|
-
if (wanted === "plan") ctx.addMessage("Writes, deletes, moves, and exec are now refused.");
|
|
57
|
-
if (wanted === "guide") ctx.addMessage("Mutating commands will be printed for you to run, not executed.");
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/** /trust — list trusted folders, or forget one. */
|
|
61
|
-
export const runTrust = async (arg: string, ctx: CommandCtx): Promise<void> => {
|
|
62
|
-
const { listTrustedFolders, untrustFolder, getWorkspaceRoot, isFolderTrusted } =
|
|
63
|
-
await import("../../../core/workspace/index.js");
|
|
64
|
-
|
|
65
|
-
const [verb, ...rest] = arg.trim().split(/\s+/).filter(Boolean);
|
|
66
|
-
if (verb?.toLowerCase() === "forget") {
|
|
67
|
-
const target = rest.join(" ") || getWorkspaceRoot();
|
|
68
|
-
ctx.addMessage(
|
|
69
|
-
untrustFolder(target)
|
|
70
|
-
? `✓ No longer trusted: ${target}\nThe next launch in that folder will ask again.`
|
|
71
|
-
: `Not a trusted folder: ${target}`,
|
|
72
|
-
);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const folders = listTrustedFolders();
|
|
77
|
-
ctx.addMessage(
|
|
78
|
-
`Workspace: ${getWorkspaceRoot()} (${isFolderTrusted() ? "trusted" : "NOT trusted"})\n\n` +
|
|
79
|
-
(folders.length === 0
|
|
80
|
-
? "No trusted folders yet."
|
|
81
|
-
: `Trusted folders:\n${folders.map((f) => ` ${f}`).join("\n")}`) +
|
|
82
|
-
`\n\nForget one with /trust forget <path>`,
|
|
83
|
-
);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
/** /model <id> — persist a model override. */
|
|
87
|
-
export const runModel = async (arg: string, ctx: CommandCtx): Promise<void> => {
|
|
88
|
-
if (!arg) {
|
|
89
|
-
ctx.addMessage("Usage: /model <id>");
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const { updateConfig } = await import("../../../core/config/index.js");
|
|
93
|
-
updateConfig({ model: arg });
|
|
94
|
-
ctx.addMessage(`Model updated: ${arg}`);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/** /provider — list configured external providers or switch the active one. */
|
|
98
|
-
export const runProvider = async (arg: string, ctx: CommandCtx): Promise<void> => {
|
|
99
|
-
const { getConfig, updateConfig } = await import("../../../core/config/index.js");
|
|
100
|
-
const config = getConfig();
|
|
101
|
-
const providers = config.providers ?? {};
|
|
102
|
-
|
|
103
|
-
// No arg → show what's configured and which is active.
|
|
104
|
-
if (!arg) {
|
|
105
|
-
const active = config.provider && config.provider !== "odysx" ? config.provider : null;
|
|
106
|
-
const names = Object.keys(providers);
|
|
107
|
-
if (names.length === 0) {
|
|
108
|
-
ctx.addMessage(
|
|
109
|
-
`No external providers configured. Add to ~/.odysx/config.json:\n\n` +
|
|
110
|
-
` "providers": {\n` +
|
|
111
|
-
` "openai": { "type": "openai", "apiKey": "sk-…", "model": "gpt-4o" },\n` +
|
|
112
|
-
` "ollama": { "type": "openai", "baseUrl": "http://localhost:11434/v1", "model": "llama3.2" },\n` +
|
|
113
|
-
` "claude": { "type": "anthropic", "apiKey": "sk-ant-…", "model": "claude-sonnet-5" },\n` +
|
|
114
|
-
` "gemini": { "type": "gemini", "apiKey": "AIza…", "model": "gemini-2.0-flash" }\n` +
|
|
115
|
-
` }\n\n` +
|
|
116
|
-
`Then /provider openai — or /provider odysx to stay on the platform.`,
|
|
117
|
-
);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const lines = names.map((name) => {
|
|
121
|
-
const p = providers[name]!;
|
|
122
|
-
const mark = name === active ? "›" : " ";
|
|
123
|
-
return `${mark} ${name} (${p.type} · ${p.model}${p.baseUrl ? ` · ${p.baseUrl}` : ""})`;
|
|
124
|
-
});
|
|
125
|
-
ctx.addMessage(
|
|
126
|
-
`Providers${active ? ` — active: ${active}` : " — active: odysx (platform)"}:\n${lines.join("\n")}\n\n/provider <name> to switch · /provider odysx for the platform`,
|
|
127
|
-
);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Arg → switch.
|
|
132
|
-
const target = arg.trim().toLowerCase();
|
|
133
|
-
if (target === "odysx") {
|
|
134
|
-
updateConfig({ provider: null });
|
|
135
|
-
ctx.addMessage("Provider → odysx platform");
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (!providers[target]) {
|
|
139
|
-
ctx.addMessage(`✗ Unknown provider '${target}'. Configured: ${Object.keys(providers).join(", ") || "(none)"} · odysx`);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
updateConfig({ provider: target });
|
|
143
|
-
ctx.addMessage(`Provider → ${target} (${providers[target]!.model}). New messages now use it.`);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/** /usage — per-session token totals. */
|
|
147
|
-
export const runUsage = (ctx: CommandCtx): void => {
|
|
148
|
-
const u = ctx.usageRef.current;
|
|
149
|
-
const external = getConfig().provider;
|
|
150
|
-
const source = external && external !== "odysx" ? external : "the platform";
|
|
151
|
-
ctx.addMessage(
|
|
152
|
-
`Usage this session (approximate — ~4 characters ≈ 1 token):\n` +
|
|
153
|
-
` requests: ${u.requests}\n` +
|
|
154
|
-
` prompt tokens: ${u.promptTokens}\n` +
|
|
155
|
-
` completion tokens: ${u.completionTokens}\n` +
|
|
156
|
-
` total tokens: ${u.promptTokens + u.completionTokens}\n` +
|
|
157
|
-
`Source: ${source}. These are client-side estimates, not billing figures.`,
|
|
158
|
-
);
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/** /export — dump transcript JSON next to cwd, through the permission gate. */
|
|
162
|
-
export const runExport = async (
|
|
163
|
-
messages: Array<{ role: string; text: string; agentName?: string }>,
|
|
164
|
-
ctx: CommandCtx,
|
|
165
|
-
): Promise<void> => {
|
|
166
|
-
const fn = `odysx-session-${ctx.sessionId().slice(0, 8)}.json`;
|
|
167
|
-
const { decideLocal, getPermissionMode } = await import("../../../core/permissions/index.js");
|
|
168
|
-
const { confinePath } = await import("../../../core/workspace/index.js");
|
|
169
|
-
const mode = getPermissionMode();
|
|
170
|
-
const decision = decideLocal("write", mode);
|
|
171
|
-
if (decision === "refuse" || decision === "guide") {
|
|
172
|
-
ctx.addMessage(
|
|
173
|
-
decision === "refuse"
|
|
174
|
-
? `✗ Export is a write and is not allowed in ${mode} mode.`
|
|
175
|
-
: `[guide] nothing was written. To export yourself, run /export in manual or auto mode.`,
|
|
176
|
-
);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const target = confinePath(fn);
|
|
180
|
-
if (!target.ok || !target.resolved) {
|
|
181
|
-
ctx.addMessage(`✗ ${target.error ?? "Cannot export outside the workspace"}`);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
const { writeFileSync } = await import("node:fs");
|
|
186
|
-
// The path was confined above; only the write itself is gated. Approval
|
|
187
|
-
// lives in the shared PendingOp flow, so manual mode can't quietly skip it.
|
|
188
|
-
if (decision === "ask") {
|
|
189
|
-
await new Promise<void>((resolve) => {
|
|
190
|
-
ctx.setPendingOp({
|
|
191
|
-
kind: "write",
|
|
192
|
-
summary: `export transcript to ${fn}`,
|
|
193
|
-
cliArgs: [], // no re-dispatch: the approved write happens in the callback below
|
|
194
|
-
diff: { file: fn, before: "", after: JSON.stringify({
|
|
195
|
-
sessionId: ctx.sessionId(), agentId: ctx.agentId, messages,
|
|
196
|
-
}, null, 2).slice(0, 200) },
|
|
197
|
-
onApproved: () => {
|
|
198
|
-
try {
|
|
199
|
-
writeFileSync(target.resolved!, JSON.stringify({
|
|
200
|
-
sessionId: ctx.sessionId(), agentId: ctx.agentId, messages,
|
|
201
|
-
}, null, 2));
|
|
202
|
-
ctx.addMessage(`Exported to: ${fn}`);
|
|
203
|
-
} catch (err) {
|
|
204
|
-
ctx.addMessage(`✗ Export failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
205
|
-
}
|
|
206
|
-
resolve();
|
|
207
|
-
},
|
|
208
|
-
onDenied: () => {
|
|
209
|
-
ctx.addMessage("Export cancelled.");
|
|
210
|
-
resolve();
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
writeFileSync(target.resolved, JSON.stringify({
|
|
217
|
-
sessionId: ctx.sessionId(), agentId: ctx.agentId, messages,
|
|
218
|
-
}, null, 2));
|
|
219
|
-
ctx.addMessage(`Exported to: ${fn}`);
|
|
220
|
-
} catch (err) {
|
|
221
|
-
ctx.addMessage(`✗ Export failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* /local <read|write|exec|...> — mutating ops are put to the permission mode
|
|
227
|
-
* before anything is shown or run.
|
|
228
|
-
*
|
|
229
|
-
* Returns true when the caller must NOT run the command itself: either the
|
|
230
|
-
* prompt is now on screen, or the mode already answered (refused, or printed
|
|
231
|
-
* the command in guide mode). Read-only subcommands and `allow` decisions
|
|
232
|
-
* return false so the handler runs normally.
|
|
233
|
-
*/
|
|
234
|
-
export const runLocalGate = async (arg: string, ctx: CommandCtx): Promise<boolean> => {
|
|
235
|
-
const parts = arg.trim().split(/\s+/).filter(Boolean);
|
|
236
|
-
const sub = (parts[0] ?? "").toLowerCase();
|
|
237
|
-
if (sub !== "write" && sub !== "exec" && sub !== "delete" && sub !== "move") return false;
|
|
238
|
-
|
|
239
|
-
const { decideLocal, getPermissionMode } = await import("../../../core/permissions/index.js");
|
|
240
|
-
const mode = getPermissionMode();
|
|
241
|
-
const decision = decideLocal(sub, mode);
|
|
242
|
-
|
|
243
|
-
if (decision === "refuse") {
|
|
244
|
-
ctx.addMessage(
|
|
245
|
-
`✗ /local ${sub} is not allowed in ${mode} mode — switch with /mode manual or /mode auto.`,
|
|
246
|
-
);
|
|
247
|
-
return true;
|
|
248
|
-
}
|
|
249
|
-
if (decision === "guide") {
|
|
250
|
-
ctx.addMessage(
|
|
251
|
-
`[guide] nothing was run. To do it yourself:\n\n odysx local ${parts.join(" ")}\n`,
|
|
252
|
-
);
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
255
|
-
// `auto` acts on ordinary writes; everything else reaches the prompt.
|
|
256
|
-
if (decision === "allow") return false;
|
|
257
|
-
|
|
258
|
-
const buildOp = (diff: PendingOp["diff"]) =>
|
|
259
|
-
ctx.setPendingOp({
|
|
260
|
-
kind: sub as PendingOp["kind"],
|
|
261
|
-
summary:
|
|
262
|
-
sub === "exec"
|
|
263
|
-
? `run \`${arg.replace(/^exec\s*/i, "")}\` in the workspace`
|
|
264
|
-
: `${sub} ${parts.slice(1).filter((p) => !p.startsWith("-")).join(" ") || "(target)"} in the workspace`,
|
|
265
|
-
cliArgs: parts,
|
|
266
|
-
diff,
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// For writes, read the *current* file so the prompt can show a real diff.
|
|
270
|
-
// The read is confined exactly like the write itself — otherwise the prompt
|
|
271
|
-
// could display an arbitrary file outside the workspace while the handler
|
|
272
|
-
// writes a different one in it.
|
|
273
|
-
if (sub === "write") {
|
|
274
|
-
const target = parts[1];
|
|
275
|
-
const contentFlagIdx = parts.indexOf("--content");
|
|
276
|
-
const after = contentFlagIdx !== -1 ? (parts[contentFlagIdx + 1] ?? "") : "";
|
|
277
|
-
try {
|
|
278
|
-
const { existsSync, readFileSync } = await import("node:fs");
|
|
279
|
-
const { confinePath } = await import("../../../core/workspace/index.js");
|
|
280
|
-
const decision = target ? confinePath(target) : null;
|
|
281
|
-
const before =
|
|
282
|
-
decision?.ok && decision.resolved && existsSync(decision.resolved)
|
|
283
|
-
? readFileSync(decision.resolved, "utf-8")
|
|
284
|
-
: "";
|
|
285
|
-
buildOp({ file: target ?? "(target)", before: before.slice(0, 200), after });
|
|
286
|
-
} catch {
|
|
287
|
-
buildOp(undefined);
|
|
288
|
-
}
|
|
289
|
-
} else {
|
|
290
|
-
buildOp(undefined);
|
|
291
|
-
}
|
|
292
|
-
return true;
|
|
293
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* /tasks and /ralph case bodies — background agent task inspection & enqueue.
|
|
3
|
-
*
|
|
4
|
-
* Task verbs mirror the backend routes: `retry` re-enqueues a failed/cancelled
|
|
5
|
-
* task, `cancel` requests cancellation, `follow` prints one status snapshot
|
|
6
|
-
* (the caller can repeat it, or watch the task in the web UI).
|
|
7
|
-
*/
|
|
8
|
-
import type { CommandCtx } from "../../shared/types.js";
|
|
9
|
-
|
|
10
|
-
/** Split the first word of a task verb from its id. */
|
|
11
|
-
const verbArg = (arg: string): { verb: string; id: string } => {
|
|
12
|
-
const [verb = "", ...rest] = arg.trim().split(/\s+/).filter(Boolean);
|
|
13
|
-
return { verb: verb.toLowerCase(), id: rest.join(" ").trim() };
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/** Detail lines shared by /tasks <id> and /tasks follow <id>. */
|
|
17
|
-
const formatTask = (t: {
|
|
18
|
-
id: string; name: string; status: string; mode?: string;
|
|
19
|
-
error?: string | null; result?: { answer?: string } | null;
|
|
20
|
-
metadata?: { steps?: Array<Record<string, unknown>> };
|
|
21
|
-
}): string => {
|
|
22
|
-
const steps = (t.metadata?.steps ?? []) as Array<{ stage?: string; agent?: string; done?: boolean }>;
|
|
23
|
-
const stepLines = steps
|
|
24
|
-
.slice(-8)
|
|
25
|
-
.map((s) => ` · ${s.stage}${s.agent ? ` (${s.agent})` : ""}${s.done === false ? " ✗" : ""}`)
|
|
26
|
-
.join("\n");
|
|
27
|
-
return (
|
|
28
|
-
`Task ${t.id.slice(0, 12)} — ${t.name}\n` +
|
|
29
|
-
` status: ${t.status}${t.mode ? ` · mode ${t.mode}` : ""}\n` +
|
|
30
|
-
(stepLines ? ` steps:\n${stepLines}\n` : "") +
|
|
31
|
-
(t.error ? ` error: ${t.error.slice(0, 200)}\n` : "") +
|
|
32
|
-
(t.result?.answer ? `\n${t.result.answer.slice(0, 800)}` : "")
|
|
33
|
-
);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/** /tasks [id] — list recent tasks, or show one task's status/steps/result. */
|
|
37
|
-
export const runTasks = async (arg: string, ctx: CommandCtx): Promise<void> => {
|
|
38
|
-
const { apiCall } = await import("../../../core/provider/index.js");
|
|
39
|
-
const { verb, id: rest } = verbArg(arg);
|
|
40
|
-
|
|
41
|
-
if (verb === "retry" || verb === "cancel" || verb === "follow") {
|
|
42
|
-
if (!rest) {
|
|
43
|
-
ctx.addMessage(`Usage: /tasks ${verb} <task-id>`);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const taskId = encodeURIComponent(rest);
|
|
47
|
-
if (verb === "retry") {
|
|
48
|
-
const res = await apiCall(`/api/v1/tasks/${taskId}/retry`, { method: "POST" });
|
|
49
|
-
ctx.addMessage(
|
|
50
|
-
res.ok
|
|
51
|
-
? `↻ Task ${rest.slice(0, 12)} re-queued — /tasks ${rest} to watch it.`
|
|
52
|
-
: `✗ Retry failed: ${res.error}`,
|
|
53
|
-
);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (verb === "cancel") {
|
|
57
|
-
const res = await apiCall(`/api/v1/tasks/${taskId}`, { method: "DELETE" });
|
|
58
|
-
ctx.addMessage(
|
|
59
|
-
res.ok
|
|
60
|
-
? `■ Task ${rest.slice(0, 12)} cancelled.`
|
|
61
|
-
: `✗ Cancel failed: ${res.error}`,
|
|
62
|
-
);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
// follow: one snapshot. Repeat, or poll with /watch later.
|
|
66
|
-
const res = await apiCall<Parameters<typeof formatTask>[0]>(`/api/v1/tasks/${taskId}`);
|
|
67
|
-
ctx.addMessage(res.ok && res.data ? formatTask(res.data) : `✗ ${res.error ?? "Task not found"}`);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const id = arg.trim();
|
|
72
|
-
if (id) {
|
|
73
|
-
const res = await apiCall<Parameters<typeof formatTask>[0]>(`/api/v1/tasks/${encodeURIComponent(id)}`);
|
|
74
|
-
ctx.addMessage(res.ok && res.data ? formatTask(res.data) : `✗ ${res.error ?? "Task not found"}`);
|
|
75
|
-
} else {
|
|
76
|
-
const res = await apiCall<Array<{ id: string; name: string; status: string; created_at?: string }>>("/api/v1/tasks?limit=15");
|
|
77
|
-
if (!res.ok) {
|
|
78
|
-
ctx.addMessage(`✗ ${res.error}`);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!res.data.length) {
|
|
82
|
-
ctx.addMessage("No tasks yet. /ralph <objective> or /tasks create runs one.");
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
ctx.addMessage(
|
|
86
|
-
`Tasks (${res.data.length}) — inspect with /tasks <id>:\n` +
|
|
87
|
-
res.data
|
|
88
|
-
.map((t) => ` ${t.id.slice(0, 12).padEnd(14)} ${t.status.padEnd(10)} ${t.name.slice(0, 40)}`)
|
|
89
|
-
.join("\n"),
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/** /ralph <objective> — opt-in autonomous loop: enqueue a ralph-flagged chat task. */
|
|
95
|
-
export const runRalph = async (arg: string, ctx: CommandCtx): Promise<void> => {
|
|
96
|
-
if (!arg.trim()) {
|
|
97
|
-
ctx.addMessage("Usage: /ralph <objective>");
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const { apiCall } = await import("../../../core/provider/index.js");
|
|
101
|
-
const res = await apiCall<{ id: string }>("/api/v1/tasks", {
|
|
102
|
-
method: "POST",
|
|
103
|
-
headers: { "Content-Type": "application/json" },
|
|
104
|
-
body: {
|
|
105
|
-
name: arg.trim().slice(0, 60),
|
|
106
|
-
payload: { message: arg.trim(), session_id: ctx.sessionId(), ralph: true, ralph_iterations: 3 },
|
|
107
|
-
metadata: { mode: "chat", ralph_enabled: true },
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
if (!res.ok) {
|
|
111
|
-
ctx.addMessage(`✗ /ralph failed: ${res.error}`);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
ctx.addMessage(`⚙ Ralph run queued (${res.data.id.slice(0, 12)}) — poll with /tasks ${res.data.id}`);
|
|
115
|
-
};
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slash-command dispatcher.
|
|
3
|
-
*
|
|
4
|
-
* The command surface is declared once in `SLASH_COMMANDS` (shared/types.ts);
|
|
5
|
-
* this file maps each declared name to its body. Anything missing from the
|
|
6
|
-
* table falls through to the unknown-command notice, and
|
|
7
|
-
* `test/commands.test.mjs` asserts the two lists agree — so a command added to
|
|
8
|
-
* the menu but not implemented (or vice versa) fails CI instead of shipping.
|
|
9
|
-
*
|
|
10
|
-
* Handlers receive the raw argument string and a CommandCtx, and never reach
|
|
11
|
-
* into component state directly.
|
|
12
|
-
*/
|
|
13
|
-
import type { ChatMessage, CommandCtx } from "../shared/types.js";
|
|
14
|
-
import { runTasks, runRalph } from "./cases/tasks.js";
|
|
15
|
-
import { runMcp, runPrompts, runSkills } from "./cases/catalog.js";
|
|
16
|
-
import {
|
|
17
|
-
runHelp, runStatus, runModel, runProvider, runUsage, runExport, runLocalGate, runMode, runTrust,
|
|
18
|
-
} from "./cases/misc.js";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Handlers may be async. The return value matters to the non-interactive
|
|
22
|
-
* front end, which drains a piped script and exits as soon as the loop ends:
|
|
23
|
-
* firing a handler without awaiting it let the process die mid-request
|
|
24
|
-
* (`printf '/mcp\n' | odysx` printed nothing and exited 0).
|
|
25
|
-
*/
|
|
26
|
-
type Handler = (arg: string, ctx: CommandCtx, messages: ChatMessage[]) => void | Promise<void>;
|
|
27
|
-
|
|
28
|
-
/** Run a registered `local` command handler and print its result (non-gated ops). */
|
|
29
|
-
const runLocal = async (cliArgs: string[], ctx: CommandCtx): Promise<void> => {
|
|
30
|
-
try {
|
|
31
|
-
// Import registers the command, then fetch it from the registry.
|
|
32
|
-
await import("../../commands/local.js");
|
|
33
|
-
const { getAllCommands } = await import("../../core/registry/index.js");
|
|
34
|
-
const entry = getAllCommands().get("local");
|
|
35
|
-
if (!entry) throw new Error("local command not registered");
|
|
36
|
-
const result = await entry.handler({}, { args: cliArgs });
|
|
37
|
-
// Keep the command's own output even when it failed: `local exec` reports
|
|
38
|
-
// a non-zero status *and* carries the compiler/test output the user needs.
|
|
39
|
-
// Showing only the error phrase discarded it.
|
|
40
|
-
const output =
|
|
41
|
-
typeof result.data === "string"
|
|
42
|
-
? result.data
|
|
43
|
-
: result.data === undefined
|
|
44
|
-
? ""
|
|
45
|
-
: JSON.stringify(result.data);
|
|
46
|
-
const body = [
|
|
47
|
-
result.error ? `✗ ${result.error}` : result.message,
|
|
48
|
-
output.trim(),
|
|
49
|
-
].filter(Boolean).join("\n");
|
|
50
|
-
ctx.addMessage((body || "(no output)").slice(0, 1500));
|
|
51
|
-
} catch (err) {
|
|
52
|
-
const text = err instanceof Error ? err.message : String(err);
|
|
53
|
-
ctx.addMessage(`✗ ${text}`);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Slash name → body. Keys must stay in sync with SLASH_COMMANDS.
|
|
59
|
-
* A handler may ignore `arg` (no-argument commands) or parse it.
|
|
60
|
-
*/
|
|
61
|
-
const HANDLERS: Record<string, Handler> = {
|
|
62
|
-
help: (_a, ctx) => runHelp(ctx),
|
|
63
|
-
|
|
64
|
-
clear: (_a, ctx, messages) => {
|
|
65
|
-
// Wipe the transcript; if a reply is mid-stream, stop it too so its
|
|
66
|
-
// tokens don't keep appending after the wipe. resetTranscript also
|
|
67
|
-
// remounts the <Static> region, which otherwise keeps old lines.
|
|
68
|
-
ctx.abortStream();
|
|
69
|
-
const had = messages.length > 0;
|
|
70
|
-
ctx.resetTranscript();
|
|
71
|
-
if (!had) {
|
|
72
|
-
// Nothing to wipe — still confirm so Enter visibly did something.
|
|
73
|
-
ctx.addMessage("✓ conversation already empty");
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
// /compact is the historical alias for a context wipe; same behavior.
|
|
78
|
-
compact: (_a, ctx, messages) => HANDLERS.clear!("", ctx, messages),
|
|
79
|
-
|
|
80
|
-
new: (_a, ctx) => ctx.newSession(),
|
|
81
|
-
|
|
82
|
-
status: (_a, ctx) => runStatus(ctx),
|
|
83
|
-
|
|
84
|
-
agent: (arg, ctx) => {
|
|
85
|
-
if (!arg) {
|
|
86
|
-
ctx.openAgentPicker();
|
|
87
|
-
} else {
|
|
88
|
-
ctx.setAgentId(arg);
|
|
89
|
-
ctx.addMessage(`Agent set to: ${arg}`);
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
model: (arg, ctx) => runModel(arg, ctx),
|
|
94
|
-
|
|
95
|
-
provider: (arg, ctx) => runProvider(arg, ctx),
|
|
96
|
-
|
|
97
|
-
// Open the sign-in menu (auth picker). Shareable between the base path and
|
|
98
|
-
// the slash-menu's Enter handler since both route through here.
|
|
99
|
-
signin: (_a, ctx) => {
|
|
100
|
-
ctx.setAuthIndex(0);
|
|
101
|
-
ctx.setAuthMode("picker");
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
// /keys and /keys new both open the panel; creation starts from a keystroke
|
|
105
|
-
// there, because the flow needs the keys state owned by app.tsx.
|
|
106
|
-
keys: (_a, ctx) => ctx.openKeysPanel(),
|
|
107
|
-
|
|
108
|
-
sessions: (arg, ctx) => {
|
|
109
|
-
// /sessions <id> → resume directly; bare /sessions → interactive picker
|
|
110
|
-
const sid = arg.trim();
|
|
111
|
-
return sid ? ctx.resumeSession(sid) : ctx.openSessionPicker();
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
tasks: (arg, ctx) => runTasks(arg, ctx),
|
|
115
|
-
ralph: (arg, ctx) => runRalph(arg, ctx),
|
|
116
|
-
mcp: (_a, ctx) => runMcp(ctx),
|
|
117
|
-
prompts: (arg, ctx) => runPrompts(arg, ctx),
|
|
118
|
-
skills: (_a, ctx) => runSkills(ctx),
|
|
119
|
-
usage: (_a, ctx) => runUsage(ctx),
|
|
120
|
-
export: (_a, ctx, messages) => runExport(messages, ctx),
|
|
121
|
-
|
|
122
|
-
// Who decides whether a workspace operation may run, and which folders this
|
|
123
|
-
// session is allowed to touch at all.
|
|
124
|
-
mode: (arg, ctx) => runMode(arg, ctx),
|
|
125
|
-
trust: (arg, ctx) => runTrust(arg, ctx),
|
|
126
|
-
|
|
127
|
-
local: async (arg, ctx) => {
|
|
128
|
-
// Risky ops (write/exec/delete/move) go through the permission prompt
|
|
129
|
-
// first. The gate is async because it reads the current file for the diff.
|
|
130
|
-
const cliArgs = arg.trim().split(/\s+/).filter(Boolean);
|
|
131
|
-
// Awaited, not fire-and-forget: a rejection here used to escape as an
|
|
132
|
-
// unhandledRejection, and the piped path would exit before the op ran.
|
|
133
|
-
const gated = await runLocalGate(arg, ctx);
|
|
134
|
-
if (!gated) await runLocal(cliArgs, ctx);
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
quit: (_a, ctx) => ctx.requestExit(),
|
|
138
|
-
// /exit is a documented alias of /quit; aliases are declared in the handler
|
|
139
|
-
// table rather than duplicated in the menu so /help stays one row each.
|
|
140
|
-
exit: (_a, ctx) => ctx.requestExit(),
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
/** Alternate names that dispatch to the same body but are hidden from /help. */
|
|
144
|
-
const ALIASES: Record<string, string> = {
|
|
145
|
-
q: "quit",
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
/** Every dispatchable slash name, including hidden aliases. Used by tests. */
|
|
149
|
-
export const DISPATCHABLE_COMMANDS: readonly string[] = [
|
|
150
|
-
...Object.keys(HANDLERS),
|
|
151
|
-
...Object.keys(ALIASES),
|
|
152
|
-
];
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Dispatch a slash command. Resolves once the handler's async work is done,
|
|
156
|
-
* so a non-interactive caller can await it before exiting. Rejections are
|
|
157
|
-
* reported into the transcript rather than escaping to the process.
|
|
158
|
-
*/
|
|
159
|
-
export const runCommand = async (
|
|
160
|
-
raw: string,
|
|
161
|
-
ctx: CommandCtx,
|
|
162
|
-
messages: ChatMessage[],
|
|
163
|
-
): Promise<void> => {
|
|
164
|
-
const [name, ...rest] = raw.replace(/^\//, "").split(" ");
|
|
165
|
-
const arg = rest.join(" ");
|
|
166
|
-
const key = (ALIASES[name.toLowerCase()] ?? name.toLowerCase());
|
|
167
|
-
const handler = HANDLERS[key];
|
|
168
|
-
|
|
169
|
-
if (!handler) {
|
|
170
|
-
ctx.addMessage(`Unknown command: /${name}. Try /help.`);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
await handler(arg, ctx, messages);
|
|
175
|
-
} catch (err) {
|
|
176
|
-
ctx.addMessage(`✗ ${err instanceof Error ? err.message : String(err)}`);
|
|
177
|
-
}
|
|
178
|
-
};
|