codowave 0.2.0 → 0.2.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/index.js DELETED
@@ -1,919 +0,0 @@
1
- // src/index.ts
2
- import { Command as Command7 } from "commander";
3
-
4
- // src/config.ts
5
- import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
6
- import { join } from "path";
7
- import { homedir } from "os";
8
- import { z } from "zod";
9
- var AIProviderSchema = z.object({
10
- provider: z.enum(["openai", "anthropic", "minimax", "ollama", "custom"]),
11
- apiKey: z.string().min(1),
12
- model: z.string().default(""),
13
- baseUrl: z.string().url().optional()
14
- });
15
- var ConfigSchema = z.object({
16
- apiKey: z.string().min(1),
17
- apiUrl: z.string().url().default("https://api.codowave.com"),
18
- repos: z.array(
19
- z.object({
20
- owner: z.string(),
21
- name: z.string(),
22
- id: z.string().optional()
23
- })
24
- ).default([]),
25
- ai: AIProviderSchema.optional()
26
- });
27
- var CONFIG_DIR = join(homedir(), ".codowave");
28
- var CONFIG_FILE = join(CONFIG_DIR, "config.json");
29
- function readConfig() {
30
- if (!existsSync(CONFIG_FILE)) {
31
- return null;
32
- }
33
- try {
34
- const raw = readFileSync(CONFIG_FILE, "utf-8");
35
- const json = JSON.parse(raw);
36
- const parsed = ConfigSchema.safeParse(json);
37
- if (!parsed.success) {
38
- return null;
39
- }
40
- return parsed.data;
41
- } catch (err) {
42
- console.warn(`[config] Failed to parse ${CONFIG_FILE}:`, err);
43
- return null;
44
- }
45
- }
46
- function readConfigOrThrow() {
47
- const config = readConfig();
48
- if (!config) {
49
- throw new Error(
50
- `No Codowave config found. Run \`codowave init\` to get started.`
51
- );
52
- }
53
- return config;
54
- }
55
- function writeConfig(config) {
56
- if (!existsSync(CONFIG_DIR)) {
57
- mkdirSync(CONFIG_DIR, { recursive: true });
58
- }
59
- writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n", "utf-8");
60
- }
61
- function updateConfig(updates) {
62
- const current = readConfig() ?? {
63
- apiKey: "",
64
- apiUrl: "https://api.codowave.com",
65
- repos: []
66
- };
67
- const merged = {
68
- ...current,
69
- ...updates
70
- };
71
- writeConfig(merged);
72
- return merged;
73
- }
74
- function getConfigPath() {
75
- return CONFIG_FILE;
76
- }
77
-
78
- // src/commands/init.tsx
79
- import { Command } from "commander";
80
- import pc2 from "picocolors";
81
- import { render } from "ink";
82
-
83
- // src/components/init/GithubAppStep.tsx
84
- import { useState, useEffect } from "react";
85
- import {
86
- Box,
87
- Text,
88
- useInput
89
- } from "ink";
90
- import Spinner from "ink-spinner";
91
- import pc from "picocolors";
92
- import { jsx, jsxs } from "react/jsx-runtime";
93
- var GithubAppStep = ({ apiUrl, onComplete, onCancel }) => {
94
- const [step, setStep] = useState("api-key");
95
- const [apiKey, setApiKey] = useState("");
96
- const [repos, setRepos] = useState([]);
97
- const [selectedRepos, setSelectedRepos] = useState(/* @__PURE__ */ new Set());
98
- const [currentSelection, setCurrentSelection] = useState(0);
99
- const [loading, setLoading] = useState(false);
100
- const [error, setError] = useState(null);
101
- useEffect(() => {
102
- if (step === "repos" && apiKey && repos.length === 0 && !loading) {
103
- fetchRepos();
104
- }
105
- }, [step, apiKey]);
106
- async function fetchRepos() {
107
- setLoading(true);
108
- setError(null);
109
- try {
110
- const response = await fetch(`${apiUrl}/api/v1/repos`, {
111
- headers: {
112
- Authorization: `Bearer ${apiKey}`,
113
- "Content-Type": "application/json"
114
- }
115
- });
116
- if (!response.ok) {
117
- if (response.status === 401) {
118
- throw new Error("Invalid API key. Please check and try again.");
119
- }
120
- throw new Error(`Failed to fetch repositories: ${response.status}`);
121
- }
122
- const data = await response.json();
123
- const fetchedRepos = data.repos || data.repositories || [];
124
- setRepos(fetchedRepos);
125
- if (fetchedRepos.length > 0) {
126
- const allIndices = /* @__PURE__ */ new Set();
127
- for (let i = 0; i < fetchedRepos.length; i++) {
128
- allIndices.add(i);
129
- }
130
- setSelectedRepos(allIndices);
131
- }
132
- } catch (err) {
133
- setError(err instanceof Error ? err.message : "Failed to fetch repositories");
134
- } finally {
135
- setLoading(false);
136
- }
137
- }
138
- function handleApiKeySubmit() {
139
- if (!apiKey.trim()) {
140
- setError("API key cannot be empty");
141
- return;
142
- }
143
- setError(null);
144
- setStep("repos");
145
- }
146
- function handleConfirm() {
147
- const selected = Array.from(selectedRepos).map((i) => repos[i]).filter((repo) => repo !== void 0);
148
- onComplete(apiKey, selected);
149
- }
150
- function handleGoBack() {
151
- setStep("api-key");
152
- setError(null);
153
- }
154
- useInput((input, key) => {
155
- if (step === "api-key") {
156
- if (key.return) {
157
- handleApiKeySubmit();
158
- return;
159
- }
160
- if (key.escape) {
161
- onCancel();
162
- return;
163
- }
164
- if (key.backspace || input === "\b") {
165
- setApiKey((prev) => prev.slice(0, -1));
166
- setError(null);
167
- return;
168
- }
169
- if (input && !key.ctrl && !key.meta) {
170
- setApiKey((prev) => prev + input);
171
- setError(null);
172
- return;
173
- }
174
- } else if (step === "repos") {
175
- if (key.escape) {
176
- handleGoBack();
177
- return;
178
- }
179
- if (key.return) {
180
- handleConfirm();
181
- return;
182
- }
183
- if (input === " ") {
184
- toggleRepo(currentSelection);
185
- return;
186
- }
187
- if (key.upArrow) {
188
- setCurrentSelection((prev) => Math.max(0, prev - 1));
189
- return;
190
- }
191
- if (key.downArrow) {
192
- setCurrentSelection((prev) => Math.min(repos.length - 1, prev + 1));
193
- return;
194
- }
195
- if (input === "a" || input === "A") {
196
- const allIndices = /* @__PURE__ */ new Set();
197
- for (let i = 0; i < repos.length; i++) {
198
- allIndices.add(i);
199
- }
200
- setSelectedRepos(allIndices);
201
- return;
202
- }
203
- if (input === "n" || input === "N") {
204
- setSelectedRepos(/* @__PURE__ */ new Set());
205
- return;
206
- }
207
- }
208
- });
209
- function toggleRepo(index) {
210
- const newSelected = new Set(selectedRepos);
211
- if (newSelected.has(index)) {
212
- newSelected.delete(index);
213
- } else {
214
- newSelected.add(index);
215
- }
216
- setSelectedRepos(newSelected);
217
- }
218
- if (step === "api-key") {
219
- return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingY: 1, children: [
220
- /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsx(Text, { bold: true, color: "cyan", children: "\u2550\u2550\u2550 GitHub App Setup \u2550\u2550\u2550" }) }),
221
- /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsx(Text, { children: "Enter your Codowave API key:" }) }),
222
- /* @__PURE__ */ jsxs(Box, { children: [
223
- /* @__PURE__ */ jsx(Text, { color: "gray", children: "> " }),
224
- /* @__PURE__ */ jsx(Text, { children: apiKey }),
225
- /* @__PURE__ */ jsx(Text, { color: "cyan", children: "_" })
226
- ] }),
227
- error && /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { color: "red", children: pc.red("\u2716 " + error) }) }),
228
- /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
229
- "Press ",
230
- /* @__PURE__ */ jsx(Text, { bold: true, children: "Enter" }),
231
- " to continue, ",
232
- /* @__PURE__ */ jsx(Text, { bold: true, children: "Esc" }),
233
- " to cancel"
234
- ] }) })
235
- ] });
236
- }
237
- if (step === "repos") {
238
- return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingY: 1, children: [
239
- /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsx(Text, { bold: true, color: "cyan", children: "\u2550\u2550\u2550 Select Repositories \u2550\u2550\u2550" }) }),
240
- loading && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Text, { color: "yellow", children: [
241
- /* @__PURE__ */ jsx(Spinner, { type: "dots" }),
242
- " Loading repositories..."
243
- ] }) }),
244
- error && /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsx(Text, { color: "red", children: pc.red("\u2716 " + error) }) }),
245
- !loading && !error && repos.length === 0 && /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsx(Text, { color: "yellow", children: "No repositories found for this API key." }) }),
246
- !loading && repos.length > 0 && /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginBottom: 1, children: repos.map((repo, index) => /* @__PURE__ */ jsxs(Box, { children: [
247
- /* @__PURE__ */ jsx(Text, { children: index === currentSelection ? " > " : " " }),
248
- /* @__PURE__ */ jsxs(Text, { color: selectedRepos.has(index) ? "green" : "gray", children: [
249
- "[",
250
- selectedRepos.has(index) ? "\u2713" : " ",
251
- "]"
252
- ] }),
253
- /* @__PURE__ */ jsx(Text, { children: " " }),
254
- /* @__PURE__ */ jsx(Text, { bold: index === currentSelection, children: /* @__PURE__ */ jsxs(Text, { dimColor: !selectedRepos.has(index), children: [
255
- repo.owner,
256
- "/",
257
- repo.name
258
- ] }) })
259
- ] }, index)) }),
260
- !loading && repos.length > 0 && /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
261
- /* @__PURE__ */ jsx(Text, { bold: true, children: "\u2191/\u2193" }),
262
- " navigate | ",
263
- /* @__PURE__ */ jsx(Text, { bold: true, children: "Space" }),
264
- " toggle | ",
265
- /* @__PURE__ */ jsx(Text, { bold: true, children: "A" }),
266
- " all | ",
267
- /* @__PURE__ */ jsx(Text, { bold: true, children: "N" }),
268
- " none"
269
- ] }) }),
270
- /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
271
- "Selected: ",
272
- /* @__PURE__ */ jsx(Text, { bold: true, color: "green", children: selectedRepos.size }),
273
- " / ",
274
- repos.length,
275
- " repos | ",
276
- /* @__PURE__ */ jsx(Text, { bold: true, children: "Enter" }),
277
- " confirm | ",
278
- /* @__PURE__ */ jsx(Text, { bold: true, children: "Esc" }),
279
- " back"
280
- ] }) })
281
- ] });
282
- }
283
- return null;
284
- };
285
-
286
- // src/commands/init.tsx
287
- import { jsx as jsx2 } from "react/jsx-runtime";
288
- var initCommand = new Command("init").description("Initialize Codowave and connect your GitHub repositories").option("--api-key <key>", "Codowave API key (non-interactive mode)").option("--api-url <url>", "Codowave API URL").option("--github-app-id <id>", "GitHub App ID").option("--github-app-private-key <key>", "GitHub App private key path").option("--repos <repos>", "Comma-separated list of repos (owner/repo)").action(async (opts) => {
289
- const existingConfig = readConfig();
290
- const defaultApiUrl = "https://api.codowave.com";
291
- if (opts.apiKey) {
292
- const config2 = {
293
- apiKey: opts.apiKey,
294
- apiUrl: opts.apiUrl || existingConfig?.apiUrl || defaultApiUrl,
295
- githubAppId: opts.githubAppId || "",
296
- githubAppPrivateKey: opts.githubAppPrivateKey || "",
297
- repos: opts.repos ? opts.repos.split(",").map((r) => {
298
- const [owner, name] = r.trim().split("/");
299
- return { owner, name };
300
- }) : [],
301
- autopilot: existingConfig?.autopilot ?? true,
302
- labels: existingConfig?.labels || {
303
- approved: "status/approved",
304
- inProgress: "status/in-progress",
305
- merged: "status/merged"
306
- }
307
- };
308
- writeConfig(config2);
309
- console.log(pc2.green("\n\u2705 Codowave initialized successfully!\n"));
310
- console.log(` API URL: ${pc2.cyan(config2.apiUrl)}`);
311
- console.log(` Repos: ${pc2.cyan(config2.repos.map((r) => `${r.owner}/${r.name}`).join(", ") || "none")}`);
312
- console.log(pc2.gray(`
313
- Config: ${getConfigPath()}
314
- `));
315
- return;
316
- }
317
- const apiUrl = existingConfig?.apiUrl || defaultApiUrl;
318
- if (existingConfig?.apiKey) {
319
- console.log(pc2.yellow("\n\u26A0 Codowave is already initialized.\n"));
320
- console.log(` API URL: ${pc2.cyan(existingConfig.apiUrl)}`);
321
- console.log(` Config: ${getConfigPath()}`);
322
- console.log(pc2.gray("\n Run with --api-key to reconfigure non-interactively.\n"));
323
- return;
324
- }
325
- let wizardComplete = false;
326
- let capturedApiKey = "";
327
- let capturedRepos = [];
328
- const { waitUntilExit } = render(
329
- /* @__PURE__ */ jsx2(
330
- GithubAppStep,
331
- {
332
- apiUrl,
333
- onComplete: (apiKey, repos) => {
334
- capturedApiKey = apiKey;
335
- capturedRepos = repos;
336
- wizardComplete = true;
337
- },
338
- onCancel: () => {
339
- process.exit(0);
340
- }
341
- }
342
- )
343
- );
344
- await waitUntilExit();
345
- if (!wizardComplete) {
346
- return;
347
- }
348
- const config = {
349
- apiKey: capturedApiKey,
350
- apiUrl,
351
- repos: capturedRepos,
352
- autopilot: true,
353
- labels: {
354
- approved: "status/approved",
355
- inProgress: "status/in-progress",
356
- merged: "status/merged"
357
- }
358
- };
359
- writeConfig(config);
360
- console.log(pc2.green("\n\u2705 Codowave initialized successfully!\n"));
361
- console.log(pc2.gray(` Config: ${getConfigPath()}
362
- `));
363
- });
364
-
365
- // src/commands/run.ts
366
- import { Command as Command2 } from "commander";
367
- import pc3 from "picocolors";
368
- var demoRuns = /* @__PURE__ */ new Map();
369
- function parseIssue(input) {
370
- const urlMatch = input.match(/github\.com\/([^/]+)\/([^/]+)\/issues\/(\d+)/);
371
- if (urlMatch && urlMatch[1] && urlMatch[2] && urlMatch[3]) {
372
- return { owner: urlMatch[1], repo: urlMatch[2], number: parseInt(urlMatch[3], 10) };
373
- }
374
- const repoMatch = input.match(/([^/]+)\/([^#]+)#(\d+)/);
375
- if (repoMatch && repoMatch[1] && repoMatch[2] && repoMatch[3]) {
376
- return { owner: repoMatch[1], repo: repoMatch[2], number: parseInt(repoMatch[3], 10) };
377
- }
378
- const numMatch = input.match(/^(\d+)$/);
379
- if (numMatch && numMatch[1]) {
380
- return { owner: "", repo: "", number: parseInt(numMatch[1], 10) };
381
- }
382
- return null;
383
- }
384
- async function triggerRun(config, issue) {
385
- const apiUrl = config.apiUrl;
386
- const apiKey = config.apiKey;
387
- const repoConfig = config.repos.find(
388
- (r) => r.owner === issue.owner && r.name === issue.repo
389
- );
390
- if (!repoConfig) {
391
- throw new Error(
392
- `Repository ${issue.owner}/${issue.repo} not configured. Run \`codowave config add-repo ${issue.owner}/${issue.repo}\``
393
- );
394
- }
395
- const response = await fetch(`${apiUrl}/api/runs`, {
396
- method: "POST",
397
- headers: {
398
- "Content-Type": "application/json",
399
- Authorization: `Bearer ${apiKey}`
400
- },
401
- body: JSON.stringify({
402
- repositoryId: repoConfig.id,
403
- issueNumber: issue.number
404
- })
405
- });
406
- if (!response.ok) {
407
- const error = await response.text();
408
- throw new Error(`Failed to trigger run: ${response.status} ${error}`);
409
- }
410
- const data = await response.json();
411
- return data.runId;
412
- }
413
- function createDemoRun(issue) {
414
- const runId = `run-${Date.now()}`;
415
- const run = {
416
- id: runId,
417
- repo: issue.owner && issue.repo ? `${issue.owner}/${issue.repo}` : "CodowaveAI/Codowave",
418
- status: "in_progress",
419
- issue: `#${issue.number}`,
420
- branchName: `agent/issue-${issue.number}`,
421
- startedAt: (/* @__PURE__ */ new Date()).toISOString(),
422
- stages: [
423
- { name: "context", status: "pending" },
424
- { name: "planning", status: "pending" },
425
- { name: "implementation", status: "pending" },
426
- { name: "testing", status: "pending" },
427
- { name: "pr-creation", status: "pending" }
428
- ]
429
- };
430
- demoRuns.set(runId, run);
431
- return run;
432
- }
433
- function streamDemoRun(run) {
434
- const stages = ["context", "planning", "implementation", "testing", "pr-creation"];
435
- let currentStage = 0;
436
- console.log(pc3.bold("\n=== Starting Run ===\n"));
437
- console.log(pc3.bold("Run ID: ") + run.id);
438
- console.log(pc3.bold("Repo: ") + run.repo);
439
- console.log(pc3.bold("Issue: ") + run.issue);
440
- console.log(pc3.bold("Branch: ") + run.branchName);
441
- console.log("");
442
- const interval = setInterval(() => {
443
- if (currentStage >= stages.length) {
444
- clearInterval(interval);
445
- run.status = "completed";
446
- run.completedAt = (/* @__PURE__ */ new Date()).toISOString();
447
- run.prNumber = 100 + Math.floor(Math.random() * 50);
448
- run.prTitle = `feat: Implement issue #${run.issue}`;
449
- console.log(pc3.green("\n\u2713 Run completed successfully!"));
450
- console.log(pc3.bold("\n=== Result ===\n"));
451
- console.log(pc3.bold("PR: ") + `#${run.prNumber} - ${run.prTitle}`);
452
- console.log(pc3.bold("Branch: ") + run.branchName);
453
- console.log("");
454
- process.exit(0);
455
- return;
456
- }
457
- const stageName = stages[currentStage];
458
- const stage = run.stages.find((s) => s.name === stageName);
459
- if (stage) {
460
- stage.status = "running";
461
- console.log(pc3.blue(`
462
- --- ${stageName} ---`));
463
- setTimeout(() => {
464
- stage.status = "completed";
465
- stage.logs = `${stageName} completed successfully`;
466
- currentStage++;
467
- }, 1e3 + Math.random() * 2e3);
468
- } else {
469
- currentStage++;
470
- }
471
- }, 500);
472
- process.on("SIGINT", () => {
473
- clearInterval(interval);
474
- run.status = "cancelled";
475
- console.log(pc3.yellow("\n\n\u26A0 Run cancelled"));
476
- process.exit(1);
477
- });
478
- }
479
- var runCommand = new Command2("run").description("Trigger Codowave to process a GitHub issue").argument("<issue>", "GitHub issue number, URL (https://github.com/owner/repo/issues/123), or owner/repo#123").option("-r, --repo <owner/repo>", "Target repository (e.g. owner/repo)").option("-s, --stream", "Stream run progress (SSE)", false).action(async (_issueArg, _options) => {
480
- try {
481
- const parsed = parseIssue(_issueArg);
482
- if (!parsed) {
483
- console.error(pc3.red("Invalid issue format. Use:"));
484
- console.error(" - Issue number: 123");
485
- console.error(" - Full URL: https://github.com/owner/repo/issues/123");
486
- console.error(" - Short form: owner/repo#123");
487
- process.exit(1);
488
- }
489
- if (_options.repo) {
490
- const parts = _options.repo.split("/");
491
- const owner = parts[0] || "";
492
- const repo = parts[1] || "";
493
- parsed.owner = owner;
494
- parsed.repo = repo;
495
- }
496
- let config = null;
497
- try {
498
- config = readConfig();
499
- } catch {
500
- }
501
- if (config && config.apiKey && config.repos.length > 0) {
502
- console.log(pc3.blue("Connecting to Codowave API..."));
503
- if (!parsed.owner || !parsed.repo) {
504
- console.error(pc3.red("Repository required. Use -r option or include in issue URL."));
505
- process.exit(1);
506
- }
507
- const runId = await triggerRun(config, parsed);
508
- console.log(pc3.green(`\u2713 Run triggered: ${runId}`));
509
- if (_options.stream) {
510
- console.log(pc3.blue("\nStreaming run progress..."));
511
- } else {
512
- console.log(pc3.gray(`
513
- Run started. Use \`codowave status ${runId}\` to check progress.`));
514
- }
515
- } else {
516
- console.log(pc3.yellow("\u26A0 No config found. Running in demo mode.\n"));
517
- const run = createDemoRun(parsed);
518
- if (_options.stream || !process.stdout.isTTY) {
519
- streamDemoRun(run);
520
- } else {
521
- console.log(pc3.green(`\u2713 Run started: ${run.id}`));
522
- console.log(pc3.gray(`
523
- Use \`codowave status ${run.id}\` to check progress.`));
524
- console.log(pc3.gray(`Use \`codowave logs ${run.id} -f\` to follow logs.`));
525
- }
526
- }
527
- } catch (err) {
528
- const message = err instanceof Error ? err.message : String(err);
529
- console.error(pc3.red(`
530
- \u2716 Error: ${message}
531
- `));
532
- process.exit(1);
533
- }
534
- });
535
-
536
- // src/commands/status.ts
537
- import { Command as Command3 } from "commander";
538
- import pc4 from "picocolors";
539
- var demoRuns2 = /* @__PURE__ */ new Map();
540
- function initDemoData() {
541
- if (demoRuns2.size === 0) {
542
- const demoRun = {
543
- id: "latest",
544
- repo: "CodowaveAI/Codowave",
545
- status: "in_progress",
546
- issue: "#53: Implement CLI status and logs commands",
547
- branchName: "agent/issue-53",
548
- startedAt: new Date(Date.now() - 5 * 60 * 1e3).toISOString(),
549
- stages: [
550
- { name: "context", status: "completed", logs: "Loaded 12 files, 3 PRs context" },
551
- { name: "planning", status: "completed", logs: "Generated implementation plan" },
552
- { name: "implementation", status: "running", logs: "Implementing status command..." },
553
- { name: "testing", status: "pending" },
554
- { name: "pr-creation", status: "pending" }
555
- ]
556
- };
557
- demoRuns2.set(demoRun.id, demoRun);
558
- const completedRun = {
559
- id: "abc-123-def",
560
- repo: "CodowaveAI/Codowave",
561
- status: "completed",
562
- issue: "#52: Add authentication flow",
563
- prNumber: 78,
564
- prTitle: "feat: Add OAuth authentication flow",
565
- branchName: "feat/auth-flow",
566
- startedAt: new Date(Date.now() - 60 * 60 * 1e3).toISOString(),
567
- completedAt: new Date(Date.now() - 45 * 60 * 1e3).toISOString(),
568
- stages: [
569
- { name: "context", status: "completed" },
570
- { name: "planning", status: "completed" },
571
- { name: "implementation", status: "completed" },
572
- { name: "testing", status: "completed" },
573
- { name: "pr-creation", status: "completed" }
574
- ]
575
- };
576
- demoRuns2.set(completedRun.id, completedRun);
577
- }
578
- }
579
- function getRun(runId) {
580
- initDemoData();
581
- if (!runId) {
582
- return Array.from(demoRuns2.values()).sort(
583
- (a, b) => new Date(b.startedAt || 0).getTime() - new Date(a.startedAt || 0).getTime()
584
- )[0];
585
- }
586
- return demoRuns2.get(runId);
587
- }
588
- function formatStatus(status) {
589
- switch (status) {
590
- case "pending":
591
- return pc4.gray("pending");
592
- case "in_progress":
593
- return pc4.blue("in_progress");
594
- case "completed":
595
- return pc4.green("completed");
596
- case "failed":
597
- return pc4.red("failed");
598
- case "cancelled":
599
- return pc4.gray("cancelled");
600
- default:
601
- return pc4.gray(status);
602
- }
603
- }
604
- function formatStageStatus(status) {
605
- switch (status) {
606
- case "pending":
607
- return pc4.gray("[ ]");
608
- case "running":
609
- return pc4.blue("[~]");
610
- case "completed":
611
- return pc4.green("[+]");
612
- case "failed":
613
- return pc4.red("[x]");
614
- case "skipped":
615
- return pc4.gray("[-]");
616
- default:
617
- return pc4.gray("[?]");
618
- }
619
- }
620
- function formatDuration(startedAt, completedAt) {
621
- if (!startedAt) return "";
622
- const start = new Date(startedAt).getTime();
623
- const end = completedAt ? new Date(completedAt).getTime() : Date.now();
624
- const seconds = Math.floor((end - start) / 1e3);
625
- if (seconds < 60) return `${seconds}s`;
626
- const minutes = Math.floor(seconds / 60);
627
- const remainingSeconds = seconds % 60;
628
- if (minutes < 60) return `${minutes}m ${remainingSeconds}s`;
629
- const hours = Math.floor(minutes / 60);
630
- const remainingMinutes = minutes % 60;
631
- return `${hours}h ${remainingMinutes}m`;
632
- }
633
- var statusCommand = new Command3("status").description("Show the status of a Codowave run").argument("[run-id]", "Run ID (defaults to latest)").option("-r, --repo <owner/repo>", "Filter by repository").action(async (_runId, _options) => {
634
- try {
635
- let config;
636
- try {
637
- config = readConfig();
638
- } catch {
639
- }
640
- const run = getRun(_runId);
641
- if (!run) {
642
- console.log(pc4.yellow("No runs found. Run `codowave run <issue>` to start a new run."));
643
- return;
644
- }
645
- if (_options?.repo && run.repo !== _options.repo) {
646
- console.log(pc4.yellow("No run found for repository " + _options.repo));
647
- return;
648
- }
649
- console.log(pc4.bold("\n=== Run Status ===\n"));
650
- console.log(pc4.bold("ID: ") + run.id);
651
- console.log(pc4.bold("Repo: ") + run.repo);
652
- console.log(pc4.bold("Issue: ") + run.issue);
653
- console.log(pc4.bold("Status: ") + formatStatus(run.status));
654
- console.log(pc4.bold("Branch: ") + (run.branchName || pc4.gray("(none)")));
655
- if (run.prNumber) {
656
- console.log(pc4.bold("PR: ") + "#" + run.prNumber + " - " + (run.prTitle || ""));
657
- }
658
- if (run.startedAt) {
659
- console.log(pc4.bold("Started: ") + new Date(run.startedAt).toLocaleString());
660
- }
661
- if (run.completedAt) {
662
- console.log(pc4.bold("Duration: ") + formatDuration(run.startedAt, run.completedAt));
663
- } else if (run.startedAt) {
664
- console.log(pc4.bold("Duration: ") + pc4.blue("running... ") + formatDuration(run.startedAt));
665
- }
666
- if (run.errorMessage) {
667
- console.log(pc4.bold("Error: ") + pc4.red(run.errorMessage));
668
- }
669
- console.log(pc4.bold("\n=== Stages ===\n"));
670
- for (const stage of run.stages) {
671
- const statusIcon = formatStageStatus(stage.status);
672
- const statusText = pc4.bold("[" + stage.status + "]");
673
- console.log(" " + statusIcon + " " + pc4.bold(stage.name.padEnd(20)) + " " + statusText);
674
- }
675
- console.log("");
676
- } catch (err) {
677
- const message = err instanceof Error ? err.message : String(err);
678
- console.error(pc4.red("\n=== Error: " + message + " ===\n"));
679
- process.exit(1);
680
- }
681
- });
682
-
683
- // src/commands/logs.ts
684
- import { Command as Command4 } from "commander";
685
- import pc5 from "picocolors";
686
- var logsCommand = new Command4("logs").description("Stream logs for a Codowave run").argument("[run-id]", "Run ID (defaults to latest)").option("-f, --follow", "Follow log output (SSE stream)").option("-s, --stage <name>", "Show logs for a specific stage").option("--no-color", "Disable colored output").action(async (_runId, _options) => {
687
- try {
688
- let config;
689
- try {
690
- config = readConfig();
691
- } catch {
692
- }
693
- const run = getRun(_runId);
694
- if (!run) {
695
- console.log(pc5.yellow("No runs found. Run `codowave run <issue>` to start a new run."));
696
- return;
697
- }
698
- if (_options?.stage) {
699
- const stage = run.stages.find((s) => s.name === _options.stage);
700
- if (!stage) {
701
- console.log(pc5.red('Stage "' + _options.stage + '" not found.'));
702
- console.log(pc5.gray("Available stages: ") + run.stages.map((s) => s.name).join(", "));
703
- return;
704
- }
705
- console.log(pc5.bold("\n=== Logs: " + stage.name + " ===\n"));
706
- console.log(pc5.bold("Status: ") + stage.status);
707
- if (stage.logs) {
708
- console.log(pc5.gray("\n--- Output ---\n"));
709
- console.log(stage.logs);
710
- } else {
711
- console.log(pc5.gray("\n(no logs available yet)"));
712
- }
713
- if (_options.follow && stage.status === "running") {
714
- console.log(pc5.blue("\n--- Following live logs (Ctrl+C to exit) ---\n"));
715
- console.log(pc5.gray("(Live streaming would connect to API SSE endpoint in production)"));
716
- }
717
- console.log("");
718
- return;
719
- }
720
- console.log(pc5.bold("\n=== Logs: " + run.id + " ===\n"));
721
- console.log(pc5.bold("Issue: ") + run.issue);
722
- console.log(pc5.bold("Status: ") + run.status);
723
- console.log("");
724
- for (const stage of run.stages) {
725
- const statusIcon = stage.status === "completed" ? "[+]" : stage.status === "failed" ? "[x]" : stage.status === "running" ? "[~]" : "[ ]";
726
- console.log(pc5.bold("\n" + statusIcon + " " + stage.name + "\n"));
727
- if (stage.logs) {
728
- console.log(stage.logs);
729
- } else if (stage.status === "pending") {
730
- console.log(pc5.gray("(pending)"));
731
- } else if (stage.status === "running") {
732
- console.log(pc5.blue("(running...)"));
733
- } else if (stage.status === "skipped") {
734
- console.log(pc5.gray("(skipped)"));
735
- }
736
- }
737
- if (_options?.follow && run.status === "in_progress") {
738
- console.log(pc5.blue("\n--- Following live logs (Ctrl+C to exit) ---\n"));
739
- console.log(pc5.gray("(Live streaming would connect to API SSE endpoint in production)"));
740
- let dots = 0;
741
- const interval = setInterval(() => {
742
- dots = (dots + 1) % 4;
743
- process.stdout.write(pc5.blue("\r" + " ".repeat(dots) + " waiting for updates..."));
744
- }, 500);
745
- process.on("SIGINT", () => {
746
- clearInterval(interval);
747
- console.log(pc5.gray("\n\n(Stopped following)"));
748
- process.exit(0);
749
- });
750
- }
751
- console.log("");
752
- } catch (err) {
753
- const message = err instanceof Error ? err.message : String(err);
754
- console.error(pc5.red("\n=== Error: " + message + " ===\n"));
755
- process.exit(1);
756
- }
757
- });
758
-
759
- // src/commands/config-cmd.ts
760
- import { Command as Command5 } from "commander";
761
- import pc6 from "picocolors";
762
- var configCommand = new Command5("config").description("Get or set Codowave configuration values");
763
- configCommand.command("list").description("List all available config options").action(() => {
764
- console.log(pc6.bold("\n\u{1F4CB} Available Config Options:\n"));
765
- console.log(` ${pc6.cyan("apiKey")} ${pc6.gray("\u2014 Your Codowave API key")}`);
766
- console.log(` ${pc6.cyan("apiUrl")} ${pc6.gray("\u2014 API endpoint URL (default: https://api.codowave.com)")}`);
767
- console.log(` ${pc6.cyan("repos")} ${pc6.gray("\u2014 List of configured repositories")}`);
768
- console.log(` ${pc6.cyan("configPath")} ${pc6.gray("\u2014 Path to the config file")}`);
769
- console.log("");
770
- });
771
- configCommand.command("get <key>").description("Get a config value").action((key) => {
772
- try {
773
- const config = readConfigOrThrow();
774
- if (key === "configPath") {
775
- console.log(pc6.green(getConfigPath()));
776
- return;
777
- }
778
- if (key === "repos") {
779
- if (config.repos.length === 0) {
780
- console.log(pc6.yellow("No repos configured."));
781
- } else {
782
- console.log(pc6.bold("\n\u{1F4E6} Configured Repositories:\n"));
783
- config.repos.forEach((repo, index) => {
784
- console.log(` ${index + 1}. ${pc6.cyan(`${repo.owner}/${repo.name}`)}`);
785
- if (repo.id) {
786
- console.log(` ${pc6.gray("ID: " + repo.id)}`);
787
- }
788
- });
789
- console.log("");
790
- }
791
- return;
792
- }
793
- const value = config[key];
794
- if (value === void 0) {
795
- console.error(pc6.red(`\u2716 Unknown config key: ${key}`));
796
- console.log(pc6.gray(` Run \`codowave config list\` to see available options.`));
797
- process.exit(1);
798
- }
799
- console.log(value);
800
- } catch (err) {
801
- console.error(pc6.red(`\u2716 ${err instanceof Error ? err.message : String(err)}`));
802
- process.exit(1);
803
- }
804
- });
805
- configCommand.command("set <key> <value>").description("Set a config value").action((key, value) => {
806
- try {
807
- const validKeys = ["apiKey", "apiUrl"];
808
- if (!validKeys.includes(key)) {
809
- console.error(pc6.red(`\u2716 Cannot set '${key}' directly.`));
810
- console.log(pc6.gray(` For 'repos', use \`codowave init\` to manage repositories.`));
811
- console.log(pc6.gray(` Run \`codowave config list\` to see available options.`));
812
- process.exit(1);
813
- }
814
- if (key === "apiUrl") {
815
- try {
816
- new URL(value);
817
- } catch {
818
- console.error(pc6.red(`\u2716 Invalid URL: ${value}`));
819
- process.exit(1);
820
- }
821
- }
822
- const updates = { [key]: value };
823
- const newConfig = updateConfig(updates);
824
- console.log(pc6.green(`\u2713 Updated ${key}`));
825
- console.log(pc6.gray(` ${key} = ${newConfig[key]}`));
826
- } catch (err) {
827
- console.error(pc6.red(`\u2716 ${err instanceof Error ? err.message : String(err)}`));
828
- process.exit(1);
829
- }
830
- });
831
- configCommand.command("show").description("Show all current config values").action(() => {
832
- try {
833
- const config = readConfigOrThrow();
834
- console.log(pc6.bold("\n\u2699\uFE0F Current Configuration:\n"));
835
- console.log(` ${pc6.cyan("apiKey")}: ${config.apiKey ? pc6.green("\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") + pc6.gray(" (hidden)") : pc6.yellow("not set")}`);
836
- console.log(` ${pc6.cyan("apiUrl")}: ${config.apiUrl}`);
837
- console.log(` ${pc6.cyan("repos")}: ${config.repos.length} repository(s) configured`);
838
- console.log(` ${pc6.cyan("configPath")}: ${pc6.gray(getConfigPath())}`);
839
- if (config.repos.length > 0) {
840
- console.log(pc6.bold(pc6.gray("\n Repositories:")));
841
- config.repos.forEach((repo) => {
842
- console.log(` \u2022 ${repo.owner}/${repo.name}${repo.id ? pc6.gray(` (${repo.id})`) : ""}`);
843
- });
844
- }
845
- console.log("");
846
- } catch (err) {
847
- console.error(pc6.red(`\u2716 ${err instanceof Error ? err.message : String(err)}`));
848
- process.exit(1);
849
- }
850
- });
851
- configCommand.action(() => {
852
- configCommand.help();
853
- });
854
-
855
- // src/commands/connect.ts
856
- import { Command as Command6 } from "commander";
857
- import pc7 from "picocolors";
858
- var PRO_API_URL = "https://api.codowave.com";
859
- var connectCommand = new Command6("connect").description("Connect to Codowave Pro (upgrade from OSS)").action(async () => {
860
- try {
861
- console.log(pc7.bold("\n\u{1F517} Codowave Connect\n"));
862
- console.log(pc7.gray("This command upgrades your OSS installation to Codowave Pro.\n"));
863
- const config = readConfig();
864
- const isAlreadyPro = config?.apiUrl === PRO_API_URL;
865
- if (isAlreadyPro) {
866
- console.log(pc7.green("\u2713 You are already connected to Codowave Pro!"));
867
- console.log(pc7.gray(` API URL: ${config?.apiUrl}`));
868
- console.log("");
869
- return;
870
- }
871
- console.log(pc7.blue("Starting OAuth device flow...\n"));
872
- console.log(pc7.gray(" 1. Requesting device code..."));
873
- const deviceCode = `CODOWAVE-${Date.now().toString(36).toUpperCase()}`;
874
- const verificationUri = "https://codowave.com/activate";
875
- console.log(pc7.green("\n \u26A0\uFE0F Device Code: ") + pc7.bold(deviceCode));
876
- console.log(pc7.gray("\n 2. Please visit: ") + pc7.cyan(verificationUri));
877
- console.log(pc7.gray(" and enter the device code above.\n"));
878
- console.log(pc7.yellow(" \u2139\uFE0F This is a stub implementation."));
879
- console.log(pc7.gray(" In production, this would poll for OAuth completion.\n"));
880
- console.log(pc7.blue(" 3. Would save Pro token and switch API URL...\n"));
881
- console.log(pc7.bold("What would happen:\n"));
882
- console.log(` \u2022 Save Pro API token to ${getConfigPath()}`);
883
- console.log(` \u2022 Set apiUrl to ${PRO_API_URL}`);
884
- console.log("");
885
- console.log(pc7.gray("Run with ") + pc7.cyan("CODOWAVE_CONNECT=1") + pc7.gray(" to enable (not implemented yet)"));
886
- console.log("");
887
- } catch (err) {
888
- const message = err instanceof Error ? err.message : String(err);
889
- console.error(pc7.red(`
890
- \u2716 Error: ${message}
891
- `));
892
- process.exit(1);
893
- }
894
- });
895
-
896
- // src/index.ts
897
- import { createRequire } from "module";
898
- var require2 = createRequire(import.meta.url);
899
- var { version } = require2("../package.json");
900
- var VERSION = version;
901
- var program = new Command7();
902
- program.name("codowave").description("Codowave OSS CLI \u2014 AI-powered coding agent for your GitHub repositories").version(VERSION, "-v, --version", "Output the current version").option("--api-url <url>", "Override the Codowave API URL");
903
- program.addCommand(initCommand);
904
- program.addCommand(runCommand);
905
- program.addCommand(statusCommand);
906
- program.addCommand(logsCommand);
907
- program.addCommand(configCommand);
908
- program.addCommand(connectCommand);
909
- var args = process.argv.slice(2);
910
- var isInitOrHelp = args[0] === "init" || args.includes("--help") || args.includes("-h") || args.includes("--version") || args.includes("-v") || args.length === 0;
911
- if (!isInitOrHelp) {
912
- const config = readConfig();
913
- if (!config?.apiUrl) {
914
- console.log("\n\u274C Codowave not initialized. Run: codowave init\n");
915
- process.exit(1);
916
- }
917
- }
918
- program.parse();
919
- //# sourceMappingURL=index.js.map