@orbit-build/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ import readline from "readline";
2
+ import picocolors from "picocolors";
3
+ import { CredentialsManager } from "@orbit-build/config";
4
+
5
+ interface ProviderChoice {
6
+ name: string;
7
+ envVar: string;
8
+ }
9
+
10
+ const PROVIDERS: Record<string, ProviderChoice> = {
11
+ "1": { name: "deepseek-openai", envVar: "DEEPSEEK_API_KEY" },
12
+ "2": { name: "openai", envVar: "OPENAI_API_KEY" },
13
+ "3": { name: "anthropic", envVar: "ANTHROPIC_API_KEY" },
14
+ "4": { name: "deepseek-anthropic", envVar: "ANTHROPIC_AUTH_TOKEN" },
15
+ };
16
+
17
+ function askQuestion(query: string): Promise<string> {
18
+ const rl = readline.createInterface({
19
+ input: process.stdin,
20
+ output: process.stdout,
21
+ });
22
+ return new Promise((resolve) => {
23
+ rl.question(query, (answer) => {
24
+ rl.close();
25
+ resolve(answer.trim());
26
+ });
27
+ });
28
+ }
29
+
30
+ function askSecret(query: string): Promise<string> {
31
+ return new Promise((resolve) => {
32
+ const rl = readline.createInterface({
33
+ input: process.stdin,
34
+ output: process.stdout,
35
+ });
36
+
37
+ const stdin = process.stdin as any;
38
+ const stdout = process.stdout as any;
39
+
40
+ stdout.write(query);
41
+ stdin.setRawMode(true);
42
+ stdin.resume();
43
+
44
+ let input = "";
45
+
46
+ const onData = (char: Buffer) => {
47
+ const charStr = char.toString("utf8");
48
+ switch (charStr) {
49
+ case "\n":
50
+ case "\r":
51
+ case "\u0004": // EOF
52
+ stdin.setRawMode(false);
53
+ stdin.pause();
54
+ stdin.removeListener("data", onData);
55
+ stdout.write("\n");
56
+ rl.close();
57
+ resolve(input.trim());
58
+ break;
59
+ case "\u0003": // Ctrl+C
60
+ stdin.setRawMode(false);
61
+ stdin.pause();
62
+ stdin.removeListener("data", onData);
63
+ stdout.write("\n");
64
+ rl.close();
65
+ process.exit(130);
66
+ break;
67
+ case "\u0008":
68
+ case "\x7f": // Backspace
69
+ if (input.length > 0) {
70
+ input = input.slice(0, -1);
71
+ stdout.write("\r" + query + "*".repeat(input.length) + " ");
72
+ stdout.write("\r" + query + "*".repeat(input.length));
73
+ }
74
+ break;
75
+ default:
76
+ if (charStr.charCodeAt(0) >= 32) {
77
+ input += charStr;
78
+ stdout.write("*");
79
+ }
80
+ break;
81
+ }
82
+ };
83
+
84
+ stdin.on("data", onData);
85
+ });
86
+ }
87
+
88
+ export async function runLogin(): Promise<void> {
89
+ console.log(picocolors.bold("\n--- Configure Orbit API Keys ---"));
90
+ console.log("Select an API provider to configure:\n");
91
+
92
+ for (const [key, provider] of Object.entries(PROVIDERS)) {
93
+ console.log(` ${picocolors.cyan(key)}) ${picocolors.bold(provider.name)} (saves to ${provider.envVar})`);
94
+ }
95
+ console.log("");
96
+
97
+ const choice = await askQuestion("Enter your choice (1-4): ");
98
+ const provider = PROVIDERS[choice];
99
+
100
+ if (!provider) {
101
+ console.log(picocolors.red("\n✖ Invalid choice. Exiting."));
102
+ return;
103
+ }
104
+
105
+ console.log(picocolors.cyan(`\nConfiguring API Key for provider "${picocolors.bold(provider.name)}"...`));
106
+ const apiKey = await askSecret("Enter API Key (input will be hidden): ");
107
+
108
+ if (!apiKey) {
109
+ console.log(picocolors.red("\n✖ API Key cannot be empty. Exiting."));
110
+ return;
111
+ }
112
+
113
+ try {
114
+ const credsManager = new CredentialsManager();
115
+ credsManager.storeSecret(provider.envVar, apiKey);
116
+ console.log(picocolors.green(`\n✔ API Key for "${provider.name}" stored securely!`));
117
+ } catch (error: any) {
118
+ console.log(picocolors.red(`\n✖ Failed to store API Key securely: ${error.message}`));
119
+ }
120
+ }
@@ -0,0 +1,290 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ nextCodePointIndex,
4
+ parseMouseWheelDirection,
5
+ previousCodePointIndex,
6
+ } from "./run.js";
7
+
8
+ // We can extract makeCompleter matcher logic from packages/cli/src/commands/run.ts to test it.
9
+ // Since it's not exported, we can recreate it or mock the exact matcher implementation:
10
+ function makeCompleter(candidates: {
11
+ commands: string[];
12
+ files: string[];
13
+ symbols: string[];
14
+ sessions: string[];
15
+ }) {
16
+ return (line: string): [string[], string] => {
17
+ if (line.startsWith("/")) {
18
+ const hits = candidates.commands.filter((c) => c.startsWith(line));
19
+ return [hits.length ? hits : candidates.commands, line];
20
+ }
21
+
22
+ const words = line.split(/\s+/);
23
+ const lastWord = words[words.length - 1] || "";
24
+
25
+ if (!lastWord) {
26
+ return [[], lastWord];
27
+ }
28
+
29
+ const fileHits = candidates.files.filter((f) => f.startsWith(lastWord));
30
+ const symbolHits = candidates.symbols.filter((s) => s.startsWith(lastWord));
31
+ const allHits = [...fileHits, ...symbolHits];
32
+
33
+ return [allHits, lastWord];
34
+ };
35
+ }
36
+
37
+ describe("REPL Autocomplete Completer Tests", () => {
38
+ const candidates = {
39
+ commands: [
40
+ "/help",
41
+ "/status",
42
+ "/config",
43
+ "/model",
44
+ "/chat",
45
+ "/commit",
46
+ "/exit",
47
+ "/quit",
48
+ "/rollback",
49
+ "/clear",
50
+ "/add",
51
+ "/drop",
52
+ "/mode",
53
+ "/copy",
54
+ ],
55
+ files: [
56
+ "src/index.ts",
57
+ "src/utils/paths.ts",
58
+ "packages/cli/src/commands/run.ts",
59
+ ],
60
+ symbols: ["AgentLoop", "checkWorkspaceBoundary", "Prompt"],
61
+ sessions: ["sess_friendly-panda-102", "sess_clever-fox-829"],
62
+ };
63
+
64
+ it("should autocomplete slash commands", () => {
65
+ const completer = makeCompleter(candidates);
66
+
67
+ const [hits, line] = completer("/ro");
68
+ expect(hits).toContain("/rollback");
69
+ expect(hits.length).toBe(1);
70
+ expect(line).toBe("/ro");
71
+
72
+ const [allHits, allLine] = completer("/");
73
+ expect(allHits).toContain("/help");
74
+ expect(allHits).toContain("/exit");
75
+ expect(allLine).toBe("/");
76
+
77
+ const [modeHits, modeLine] = completer("/mo");
78
+ expect(modeHits).toContain("/mode");
79
+ expect(modeHits).toContain("/model");
80
+ expect(modeHits.length).toBe(2);
81
+ expect(modeLine).toBe("/mo");
82
+
83
+ const [codeHits, codeLine] = completer("/co");
84
+ expect(codeHits).toContain("/config");
85
+ expect(codeHits).toContain("/commit");
86
+ expect(codeHits).toContain("/copy");
87
+ expect(codeHits.length).toBe(3);
88
+ expect(codeLine).toBe("/co");
89
+ });
90
+
91
+ it("should autocomplete file paths based on the last typed word", () => {
92
+ const completer = makeCompleter(candidates);
93
+
94
+ const [hits, line] = completer("read_file src/in");
95
+ expect(hits).toContain("src/index.ts");
96
+ expect(hits.length).toBe(1);
97
+ expect(line).toBe("src/in");
98
+ });
99
+
100
+ it("should autocomplete symbol names", () => {
101
+ const completer = makeCompleter(candidates);
102
+
103
+ const [hits, line] = completer("explain Agent");
104
+ expect(hits).toContain("AgentLoop");
105
+ expect(hits.length).toBe(1);
106
+ expect(line).toBe("Agent");
107
+ });
108
+
109
+ it("should return empty matches if the last word is empty", () => {
110
+ const completer = makeCompleter(candidates);
111
+
112
+ const [hits, line] = completer("explain ");
113
+ expect(hits.length).toBe(0);
114
+ expect(line).toBe("");
115
+ });
116
+
117
+ describe("getActiveMatches simulation logic", () => {
118
+ function simulateGetActiveMatches(
119
+ inputBuffer: string,
120
+ providerType = "openai",
121
+ ): string[] {
122
+ if (!inputBuffer.startsWith("/")) return [];
123
+ const line = inputBuffer;
124
+ const parts = line.split(/\s+/);
125
+
126
+ if (parts[0] === "/chat" && line.includes(" ")) {
127
+ if (parts.length <= 2) {
128
+ const subcommands = ["list", "ls", "new", "delete", "rm", "switch"];
129
+ const hits = subcommands
130
+ .map((sub) => `/chat ${sub}`)
131
+ .filter((c) => c.startsWith(line));
132
+ if (hits.length > 0) return hits;
133
+ }
134
+
135
+ if (
136
+ parts.length >= 3 &&
137
+ ["delete", "rm", "switch"].includes(parts[1])
138
+ ) {
139
+ const cmd = parts[0];
140
+ const sub = parts[1];
141
+ const query = parts.slice(2).join(" ");
142
+ const prefix = `${cmd} ${sub} `;
143
+ const hits = (candidates.sessions || [])
144
+ .filter((s) => {
145
+ const lowerS = s.toLowerCase();
146
+ const lowerQ = query.toLowerCase();
147
+ return (
148
+ lowerS.startsWith(lowerQ) ||
149
+ s
150
+ .replace(/^sess_/, "")
151
+ .toLowerCase()
152
+ .startsWith(lowerQ)
153
+ );
154
+ })
155
+ .map((s) => `${prefix}${s}`);
156
+ if (hits.length > 0) return hits;
157
+ }
158
+ }
159
+
160
+ if (parts[0] === "/model" && line.includes(" ")) {
161
+ const query = line.slice(7).trim();
162
+ let models: string[] = [];
163
+ if (providerType === "anthropic") {
164
+ models = [
165
+ "claude-3-5-sonnet-latest",
166
+ "claude-3-5-haiku-latest",
167
+ "claude-3-opus-latest",
168
+ ];
169
+ } else if (providerType === "openai") {
170
+ models = ["gpt-4o", "gpt-4o-mini", "o1", "o3-mini"];
171
+ } else {
172
+ models = ["deepseek-chat", "deepseek-reasoner"];
173
+ }
174
+ const hits = models
175
+ .filter((m) => m.toLowerCase().includes(query.toLowerCase()))
176
+ .map((m) => `/model ${m}`);
177
+ if (hits.length > 0) return hits;
178
+ }
179
+
180
+ if (parts[0] === "/add" && line.includes(" ")) {
181
+ let query = line.slice(5).trim();
182
+ let prefix = "/add ";
183
+ if (query.startsWith("-r ")) {
184
+ prefix = "/add -r ";
185
+ query = query.slice(3).trim();
186
+ } else if (query.startsWith("--read-only ")) {
187
+ prefix = "/add --read-only ";
188
+ query = query.slice(12).trim();
189
+ } else if (query.startsWith("--readonly ")) {
190
+ prefix = "/add --readonly ";
191
+ query = query.slice(11).trim();
192
+ } else if (query === "-r" || query === "--read-only" || query === "--readonly") {
193
+ query = "";
194
+ prefix = `/add ${parts[1]} `;
195
+ }
196
+ const hits = (candidates.files || [])
197
+ .filter((f) => f.toLowerCase().includes(query.toLowerCase()))
198
+ .map((f) => `${prefix}${f}`);
199
+ if (hits.length > 0) return hits;
200
+ }
201
+
202
+ return candidates.commands.filter((c) => c.startsWith(line));
203
+ }
204
+
205
+ it("should match main commands", () => {
206
+ expect(simulateGetActiveMatches("/ch")).toEqual(["/chat"]);
207
+ expect(simulateGetActiveMatches("/chat")).toEqual(["/chat"]);
208
+ });
209
+
210
+ it("should match subcommands when space is typed", () => {
211
+ const matches = simulateGetActiveMatches("/chat ");
212
+ expect(matches).toContain("/chat list");
213
+ expect(matches).toContain("/chat ls");
214
+ expect(matches).toContain("/chat new");
215
+ expect(matches).toContain("/chat delete");
216
+ expect(matches).toContain("/chat rm");
217
+ expect(matches).toContain("/chat switch");
218
+ });
219
+
220
+ it("should filter subcommands based on prefix", () => {
221
+ expect(simulateGetActiveMatches("/chat d")).toEqual(["/chat delete"]);
222
+ expect(simulateGetActiveMatches("/chat r")).toEqual(["/chat rm"]);
223
+ });
224
+
225
+ it("should autocomplete session IDs for delete/rm/switch", () => {
226
+ const matches = simulateGetActiveMatches("/chat delete ");
227
+ expect(matches).toContain("/chat delete sess_friendly-panda-102");
228
+ expect(matches).toContain("/chat delete sess_clever-fox-829");
229
+
230
+ expect(simulateGetActiveMatches("/chat delete c")).toEqual([
231
+ "/chat delete sess_clever-fox-829",
232
+ ]);
233
+ expect(simulateGetActiveMatches("/chat switch s")).toEqual([
234
+ "/chat switch sess_friendly-panda-102",
235
+ "/chat switch sess_clever-fox-829",
236
+ ]);
237
+ });
238
+
239
+ it("should autocomplete files for /add", () => {
240
+ const matches = simulateGetActiveMatches("/add index");
241
+ expect(matches).toContain("/add src/index.ts");
242
+ });
243
+
244
+ it("should autocomplete files for /add with -r flag", () => {
245
+ const matches = simulateGetActiveMatches("/add -r index");
246
+ expect(matches).toContain("/add -r src/index.ts");
247
+ });
248
+
249
+ it("should dynamically filter model candidates by provider type", () => {
250
+ const openaiMatches = simulateGetActiveMatches("/model gpt", "openai");
251
+ expect(openaiMatches).toContain("/model gpt-4o");
252
+ expect(openaiMatches).not.toContain("/model claude-3-5-sonnet-latest");
253
+
254
+ const anthropicMatches = simulateGetActiveMatches(
255
+ "/model claude",
256
+ "anthropic",
257
+ );
258
+ expect(anthropicMatches).toContain("/model claude-3-5-sonnet-latest");
259
+ expect(anthropicMatches).not.toContain("/model gpt-4o");
260
+ });
261
+ });
262
+ });
263
+
264
+ describe("Unicode cursor navigation", () => {
265
+ it("moves across emoji without splitting surrogate pairs", () => {
266
+ const value = "a😀中";
267
+ expect(nextCodePointIndex(value, 1)).toBe(3);
268
+ expect(previousCodePointIndex(value, 3)).toBe(1);
269
+ });
270
+
271
+ it("clamps cursor indexes to valid text boundaries", () => {
272
+ expect(previousCodePointIndex("abc", -10)).toBe(0);
273
+ expect(nextCodePointIndex("abc", 99)).toBe(3);
274
+ });
275
+ });
276
+
277
+ describe("SGR mouse wheel parsing", () => {
278
+ it("recognizes wheel up and wheel down events", () => {
279
+ expect(parseMouseWheelDirection("\x1b[<64;20;10M")).toBe("up");
280
+ expect(parseMouseWheelDirection("\x1b[<65;20;10M")).toBe("down");
281
+ });
282
+
283
+ it("ignores non-wheel mouse events and normal input", () => {
284
+ expect(parseMouseWheelDirection("\x1b[<0;20;10M")).toBeNull();
285
+ expect(parseMouseWheelDirection("hello")).toBeNull();
286
+ expect(parseMouseWheelDirection(undefined)).toBeNull();
287
+ expect(parseMouseWheelDirection(null as any)).toBeNull();
288
+ expect(parseMouseWheelDirection(123 as any)).toBeNull();
289
+ });
290
+ });
@@ -0,0 +1,196 @@
1
+ import {
2
+ ConfigLoader,
3
+ } from "@orbit-build/config";
4
+ import {
5
+ AgentLoop,
6
+ UserInteraction,
7
+ Orchestrator,
8
+ eventBus,
9
+ } from "@orbit-build/core";
10
+ import {
11
+ DeepSeekAnthropicProvider,
12
+ DeepSeekOpenAIProvider,
13
+ OpenAIProvider,
14
+ AnthropicProvider,
15
+ OllamaProvider,
16
+ } from "@orbit-build/model-providers";
17
+ import { Prompt, DiffView } from "@orbit-build/tui";
18
+ import picocolors from "picocolors";
19
+ import { existsSync, readFileSync } from "fs";
20
+ import { join } from "path";
21
+ import {
22
+ previousCodePointIndex,
23
+ nextCodePointIndex,
24
+ parseMouseWheelDirection,
25
+ pageText,
26
+ } from "../tui/FullscreenTui.js";
27
+ import { ReplController } from "../runtime/ReplController.js";
28
+
29
+ export {
30
+ previousCodePointIndex,
31
+ nextCodePointIndex,
32
+ parseMouseWheelDirection,
33
+ };
34
+
35
+ interface LocalState {
36
+ lastSessionId?: string;
37
+ lastModel?: string;
38
+ }
39
+
40
+ function getLocalState(cwd: string): LocalState {
41
+ const statePath = join(cwd, ".orbit", "state.json");
42
+ if (!existsSync(statePath)) return {};
43
+ try {
44
+ return JSON.parse(readFileSync(statePath, "utf8"));
45
+ } catch {
46
+ return {};
47
+ }
48
+ }
49
+
50
+ export async function runAgent(
51
+ cwd: string,
52
+ task?: string,
53
+ cliOverrides?: any,
54
+ multi?: boolean,
55
+ options?: { nonInteractive?: boolean; jsonl?: boolean },
56
+ ): Promise<void> {
57
+ if (options?.jsonl) {
58
+ const originalLog = console.log;
59
+ console.log = (...args: any[]) => {
60
+ console.error(...args);
61
+ };
62
+ eventBus.on("*", (event) => {
63
+ originalLog(JSON.stringify(event));
64
+ });
65
+ }
66
+
67
+ const config = ConfigLoader.loadSync(cwd, cliOverrides);
68
+
69
+ if (!cliOverrides || !cliOverrides.model) {
70
+ const localState = getLocalState(cwd);
71
+ if (localState.lastModel) {
72
+ config.models.default = localState.lastModel;
73
+ }
74
+ }
75
+
76
+ if (config.models) {
77
+ if (config.models.default) {
78
+ config.models.default = config.models.default.replace(/\[1m\]/g, "");
79
+ }
80
+ if (config.models.fast) {
81
+ config.models.fast = config.models.fast.replace(/\[1m\]/g, "");
82
+ }
83
+ }
84
+
85
+ const providerName = config.provider.default;
86
+ const pConfig = config.providers[providerName];
87
+ if (!pConfig) {
88
+ console.error(
89
+ picocolors.red(
90
+ `Provider "${providerName}" is not defined in configuration.`,
91
+ ),
92
+ );
93
+ return;
94
+ }
95
+
96
+ let providerInstance: any;
97
+ if (pConfig.type === "anthropic-compatible") {
98
+ providerInstance = new DeepSeekAnthropicProvider(
99
+ pConfig.apiKey,
100
+ pConfig.baseUrl,
101
+ );
102
+ } else if (pConfig.type === "openai-compatible") {
103
+ providerInstance = new DeepSeekOpenAIProvider(
104
+ pConfig.apiKey,
105
+ pConfig.baseUrl,
106
+ );
107
+ } else if (pConfig.type === "openai") {
108
+ providerInstance = new OpenAIProvider(pConfig.apiKey, pConfig.baseUrl);
109
+ } else if (pConfig.type === "anthropic") {
110
+ providerInstance = new AnthropicProvider(pConfig.apiKey, pConfig.baseUrl);
111
+ } else if (pConfig.type === "ollama") {
112
+ providerInstance = new OllamaProvider(pConfig.baseUrl);
113
+ }
114
+
115
+ if (!providerInstance) {
116
+ console.error(
117
+ picocolors.red(`Unsupported provider type "${pConfig.type}".`),
118
+ );
119
+ return;
120
+ }
121
+
122
+ const interaction: UserInteraction = options?.nonInteractive
123
+ ? {
124
+ async askApproval(reason: string, preview?: string): Promise<boolean> {
125
+ console.error(`\nRisk Warning [Non-Interactive Mode]: ${reason}`);
126
+ if (preview) {
127
+ console.error(picocolors.gray(`Parameters: ${preview}`));
128
+ }
129
+ console.error("Automatically denying action in non-interactive mode.");
130
+ return false;
131
+ },
132
+ showText(text: string): void {
133
+ console.error(text);
134
+ },
135
+ async showDiff(
136
+ filePath: string,
137
+ _before: string | null,
138
+ _after: string,
139
+ ): Promise<void> {
140
+ console.error(`[Diff for ${filePath} shown in non-interactive mode]`);
141
+ },
142
+ }
143
+ : {
144
+ async askApproval(reason: string, preview?: string): Promise<boolean> {
145
+ console.log(`\nRisk Warning: ${reason}`);
146
+ if (preview) {
147
+ console.log(picocolors.gray(`Parameters: ${preview}`));
148
+ }
149
+ return await Prompt.askApproval("Confirm action?");
150
+ },
151
+ showText(text: string): void {
152
+ console.log(text);
153
+ },
154
+ async showDiff(
155
+ filePath: string,
156
+ before: string | null,
157
+ after: string,
158
+ ): Promise<void> {
159
+ await pageText(DiffView.render(filePath, before, after));
160
+ },
161
+ };
162
+
163
+ const activeTask = task;
164
+ if (!activeTask) {
165
+ const controller = new ReplController(
166
+ cwd,
167
+ config,
168
+ providerInstance,
169
+ interaction,
170
+ multi,
171
+ !!cliOverrides?.direct
172
+ );
173
+ await controller.start();
174
+ return;
175
+ }
176
+
177
+ if (multi) {
178
+ const orchestrator = new Orchestrator(
179
+ cwd,
180
+ config,
181
+ providerInstance,
182
+ activeTask,
183
+ interaction,
184
+ );
185
+ await orchestrator.run();
186
+ } else {
187
+ const loop = new AgentLoop(
188
+ cwd,
189
+ config,
190
+ providerInstance,
191
+ activeTask,
192
+ interaction,
193
+ );
194
+ await loop.run();
195
+ }
196
+ }
package/src/index.ts ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { runInit } from "./commands/init.js";
4
+ import { runConfig } from "./commands/config.js";
5
+ import { runDoctor } from "./commands/doctor.js";
6
+ import { runAgent } from "./commands/run.js";
7
+ import { runLSPServer } from "./commands/LSPServer.js";
8
+ import { runLogin } from "./commands/login.js";
9
+
10
+ const program = new Command();
11
+
12
+ program
13
+ .name("orbit")
14
+ .description("Orbit - Local AI Coding Agent Runtime")
15
+ .version("0.1.0")
16
+ .argument("[task]", "task description for Orbit to execute")
17
+ .option("--provider <provider>", "specify model provider")
18
+ .option("--model <model>", "specify model name")
19
+ .option("--yes", "bypass low-risk approvals")
20
+ .option("--multi", "run in multi-agent planning/coding/review mode")
21
+ .option("--direct", "run interactive REPL in direct console streaming mode")
22
+ .action(async (task, options) => {
23
+ const cwd = process.cwd();
24
+ const overrides: any = {};
25
+ if (options.provider) {
26
+ overrides.provider = { default: options.provider };
27
+ }
28
+ if (options.model) {
29
+ overrides.models = { default: options.model };
30
+ }
31
+ if (options.direct) {
32
+ overrides.direct = true;
33
+ }
34
+ if (options.yes) {
35
+ overrides.permissions = { mode: "auto" };
36
+ }
37
+ await runAgent(cwd, task, overrides, !!options.multi);
38
+ });
39
+
40
+ program
41
+ .command("init")
42
+ .description("initialize ORBIT.md guidelines file")
43
+ .action(() => {
44
+ runInit(process.cwd());
45
+ });
46
+
47
+ program
48
+ .command("config")
49
+ .description("show resolved configurations")
50
+ .action(() => {
51
+ runConfig(process.cwd());
52
+ });
53
+
54
+ program
55
+ .command("login")
56
+ .description("interactively configure API keys for models")
57
+ .action(async () => {
58
+ await runLogin();
59
+ });
60
+
61
+ program
62
+ .command("doctor")
63
+ .description("diagnose local environment and API configs")
64
+ .action(() => {
65
+ runDoctor(process.cwd());
66
+ });
67
+
68
+ program
69
+ .command("lsp")
70
+ .description("start the local LSP autocomplete server")
71
+ .action(async () => {
72
+ await runLSPServer(process.cwd());
73
+ });
74
+
75
+ program
76
+ .command("exec")
77
+ .description("run a task in non-interactive mode and stream events as JSONL")
78
+ .argument("<prompt>", "the task prompt to execute")
79
+ .option("--provider <provider>", "specify model provider")
80
+ .option("--model <model>", "specify model name")
81
+ .option("--jsonl", "output event logs in JSONL format")
82
+ .action(async (prompt, options) => {
83
+ const cwd = process.cwd();
84
+ const overrides: any = {};
85
+ if (options.provider) {
86
+ overrides.provider = { default: options.provider };
87
+ }
88
+ if (options.model) {
89
+ overrides.models = { default: options.model };
90
+ }
91
+ await runAgent(cwd, prompt, overrides, false, {
92
+ nonInteractive: true,
93
+ jsonl: !!options.jsonl,
94
+ });
95
+ });
96
+
97
+ program.parse(process.argv);