codmir 0.3.2 → 0.4.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.
- package/LICENSE +55 -0
- package/README.md +219 -14
- package/dist/analyze-LULBI4ZC.mjs +7 -0
- package/dist/chunk-ASGAT3Z5.mjs +756 -0
- package/dist/chunk-EBO3CZXG.mjs +15 -0
- package/dist/{chunk-7HVQNURM.mjs → chunk-GU32P57R.mjs} +70 -0
- package/dist/cli/index.js +2018 -146
- package/dist/cli/index.mjs +1166 -139
- package/dist/index.d.mts +76 -1
- package/dist/index.d.ts +76 -1
- package/dist/index.js +70 -0
- package/dist/index.mjs +2 -1
- package/dist/voice-agent/index.d.mts +134 -0
- package/dist/voice-agent/index.d.ts +134 -0
- package/dist/voice-agent/index.js +220 -0
- package/dist/voice-agent/index.mjs +187 -0
- package/dist/voice-daemon/index.d.mts +354 -0
- package/dist/voice-daemon/index.d.ts +354 -0
- package/dist/voice-daemon/index.js +1089 -0
- package/dist/voice-daemon/index.mjs +1046 -0
- package/package.json +49 -12
package/dist/cli/index.mjs
CHANGED
|
@@ -1,7 +1,143 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
CodmirClient
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-GU32P57R.mjs";
|
|
5
|
+
import {
|
|
6
|
+
analyzeCommand,
|
|
7
|
+
clearConfig,
|
|
8
|
+
ensureConfigDir,
|
|
9
|
+
getBaseUrl,
|
|
10
|
+
getExecutionContext,
|
|
11
|
+
getProjectConfig,
|
|
12
|
+
getToken,
|
|
13
|
+
isAuthenticated,
|
|
14
|
+
readConfig,
|
|
15
|
+
readProjectConfig,
|
|
16
|
+
writeConfig,
|
|
17
|
+
writeProjectConfig
|
|
18
|
+
} from "../chunk-ASGAT3Z5.mjs";
|
|
19
|
+
import {
|
|
20
|
+
__commonJS
|
|
21
|
+
} from "../chunk-EBO3CZXG.mjs";
|
|
22
|
+
|
|
23
|
+
// package.json
|
|
24
|
+
var require_package = __commonJS({
|
|
25
|
+
"package.json"(exports, module) {
|
|
26
|
+
module.exports = {
|
|
27
|
+
name: "codmir",
|
|
28
|
+
version: "0.4.0",
|
|
29
|
+
description: "Official codmir SDK - AI that prevents wasted engineering time. CLI, SDK, voice assistant, codebase analysis, and intelligent automation.",
|
|
30
|
+
main: "dist/index.js",
|
|
31
|
+
module: "dist/index.mjs",
|
|
32
|
+
types: "dist/index.d.ts",
|
|
33
|
+
bin: {
|
|
34
|
+
codmir: "dist/cli/index.js"
|
|
35
|
+
},
|
|
36
|
+
exports: {
|
|
37
|
+
".": {
|
|
38
|
+
types: "./dist/index.d.ts",
|
|
39
|
+
require: "./dist/index.js",
|
|
40
|
+
import: "./dist/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./voice-agent": {
|
|
43
|
+
types: "./dist/voice-agent/index.d.ts",
|
|
44
|
+
require: "./dist/voice-agent/index.js",
|
|
45
|
+
import: "./dist/voice-agent/index.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./voice-daemon": {
|
|
48
|
+
types: "./dist/voice-daemon/index.d.ts",
|
|
49
|
+
require: "./dist/voice-daemon/index.js",
|
|
50
|
+
import: "./dist/voice-daemon/index.mjs"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
files: [
|
|
54
|
+
"dist",
|
|
55
|
+
"README.md",
|
|
56
|
+
"LICENSE",
|
|
57
|
+
"runkit-example.js"
|
|
58
|
+
],
|
|
59
|
+
scripts: {
|
|
60
|
+
build: "tsup src/index.ts src/cli/index.ts src/voice-agent/index.ts src/voice-daemon/index.ts --format cjs,esm --dts --clean",
|
|
61
|
+
dev: "tsup src/index.ts src/cli/index.ts --format cjs,esm --dts --watch",
|
|
62
|
+
prepublishOnly: "pnpm build",
|
|
63
|
+
test: "jest",
|
|
64
|
+
"test:login": "node scripts/test/login.mjs",
|
|
65
|
+
"test:link": "node scripts/test/link.mjs",
|
|
66
|
+
"test:projects": "node scripts/test/projects.mjs",
|
|
67
|
+
"test:whoami": "node scripts/test/whoami.mjs",
|
|
68
|
+
"test:logout": "node scripts/test/logout.mjs",
|
|
69
|
+
"test:all": "npm run test:logout && npm run test:login && npm run test:whoami && npm run test:projects"
|
|
70
|
+
},
|
|
71
|
+
keywords: [
|
|
72
|
+
"codmir",
|
|
73
|
+
"sdk",
|
|
74
|
+
"cli",
|
|
75
|
+
"ai",
|
|
76
|
+
"codebase-analysis",
|
|
77
|
+
"knowledge-base",
|
|
78
|
+
"task-replication",
|
|
79
|
+
"usage-tracking",
|
|
80
|
+
"observability",
|
|
81
|
+
"project-management",
|
|
82
|
+
"tickets",
|
|
83
|
+
"tasks",
|
|
84
|
+
"automation",
|
|
85
|
+
"multi-agent",
|
|
86
|
+
"ai-assistant",
|
|
87
|
+
"voice-assistant",
|
|
88
|
+
"speech-recognition",
|
|
89
|
+
"voice-daemon",
|
|
90
|
+
"wake-word"
|
|
91
|
+
],
|
|
92
|
+
author: "codmir",
|
|
93
|
+
license: "MIT",
|
|
94
|
+
repository: {
|
|
95
|
+
type: "git",
|
|
96
|
+
url: "https://github.com/codmir/codmir.git",
|
|
97
|
+
directory: "apps/web/packages/codmir-client"
|
|
98
|
+
},
|
|
99
|
+
bugs: {
|
|
100
|
+
url: "https://github.com/codmir/codmir/issues"
|
|
101
|
+
},
|
|
102
|
+
homepage: "https://codmir.com",
|
|
103
|
+
runkit: {
|
|
104
|
+
example: "runkit-example.js"
|
|
105
|
+
},
|
|
106
|
+
devDependencies: {
|
|
107
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
108
|
+
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
109
|
+
"@semantic-release/git": "^10.0.1",
|
|
110
|
+
"@semantic-release/github": "^11.0.0",
|
|
111
|
+
"@semantic-release/npm": "^12.0.1",
|
|
112
|
+
"@semantic-release/release-notes-generator": "^14.0.0",
|
|
113
|
+
"@types/node": "^20.10.0",
|
|
114
|
+
"@types/prompts": "^2.4.9",
|
|
115
|
+
"@types/ws": "^8.18.1",
|
|
116
|
+
"@types/blessed": "^0.1.25",
|
|
117
|
+
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
118
|
+
"semantic-release": "^24.0.0",
|
|
119
|
+
tsup: "^8.0.1",
|
|
120
|
+
typescript: "^5.8.3"
|
|
121
|
+
},
|
|
122
|
+
dependencies: {
|
|
123
|
+
blessed: "^0.1.81",
|
|
124
|
+
"blessed-contrib": "^4.11.0",
|
|
125
|
+
chalk: "^5.3.0",
|
|
126
|
+
clipboardy: "^5.0.1",
|
|
127
|
+
commander: "^12.0.0",
|
|
128
|
+
"form-data": "^4.0.5",
|
|
129
|
+
glob: "^10.3.10",
|
|
130
|
+
open: "^10.0.0",
|
|
131
|
+
ora: "^9.0.0",
|
|
132
|
+
prompts: "^2.4.2",
|
|
133
|
+
ws: "^8.18.3"
|
|
134
|
+
},
|
|
135
|
+
engines: {
|
|
136
|
+
node: ">=18.0.0"
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
});
|
|
5
141
|
|
|
6
142
|
// src/cli/index.ts
|
|
7
143
|
import { Command } from "commander";
|
|
@@ -9,78 +145,6 @@ import { Command } from "commander";
|
|
|
9
145
|
// src/cli/utils/auth.ts
|
|
10
146
|
import open from "open";
|
|
11
147
|
import * as readline from "readline";
|
|
12
|
-
|
|
13
|
-
// src/cli/utils/config.ts
|
|
14
|
-
import fs from "fs";
|
|
15
|
-
import path from "path";
|
|
16
|
-
import os from "os";
|
|
17
|
-
var CONFIG_DIR = path.join(os.homedir(), ".codmir");
|
|
18
|
-
var CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
19
|
-
var PROJECT_CONFIG_FILE = ".codmir.json";
|
|
20
|
-
function ensureConfigDir() {
|
|
21
|
-
if (!fs.existsSync(CONFIG_DIR)) {
|
|
22
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function readConfig() {
|
|
26
|
-
ensureConfigDir();
|
|
27
|
-
if (!fs.existsSync(CONFIG_FILE)) {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
const data = fs.readFileSync(CONFIG_FILE, "utf-8");
|
|
32
|
-
return JSON.parse(data);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error("Error reading config:", error);
|
|
35
|
-
return {};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function writeConfig(config) {
|
|
39
|
-
ensureConfigDir();
|
|
40
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
41
|
-
}
|
|
42
|
-
function clearConfig() {
|
|
43
|
-
if (fs.existsSync(CONFIG_FILE)) {
|
|
44
|
-
fs.unlinkSync(CONFIG_FILE);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function readProjectConfig(cwd = process.cwd()) {
|
|
48
|
-
const configPath = path.join(cwd, PROJECT_CONFIG_FILE);
|
|
49
|
-
if (!fs.existsSync(configPath)) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
const data = fs.readFileSync(configPath, "utf-8");
|
|
54
|
-
return JSON.parse(data);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error("Error reading project config:", error);
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function writeProjectConfig(config, cwd = process.cwd()) {
|
|
61
|
-
const configPath = path.join(cwd, PROJECT_CONFIG_FILE);
|
|
62
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
63
|
-
const gitignorePath = path.join(cwd, ".gitignore");
|
|
64
|
-
if (fs.existsSync(gitignorePath)) {
|
|
65
|
-
const gitignore = fs.readFileSync(gitignorePath, "utf-8");
|
|
66
|
-
if (!gitignore.includes(PROJECT_CONFIG_FILE)) {
|
|
67
|
-
fs.appendFileSync(gitignorePath, `
|
|
68
|
-
# codmir
|
|
69
|
-
${PROJECT_CONFIG_FILE}
|
|
70
|
-
`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function getToken() {
|
|
75
|
-
const config = readConfig();
|
|
76
|
-
return config.token || null;
|
|
77
|
-
}
|
|
78
|
-
function isAuthenticated() {
|
|
79
|
-
const token = getToken();
|
|
80
|
-
return !!token;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/cli/utils/auth.ts
|
|
84
148
|
function promptForToken() {
|
|
85
149
|
return new Promise((resolve) => {
|
|
86
150
|
const rl = readline.createInterface({
|
|
@@ -122,7 +186,8 @@ async function startOAuthFlow(baseUrl = "https://codmir.com") {
|
|
|
122
186
|
if (!userResponse.ok) {
|
|
123
187
|
throw new Error("Invalid token or authentication failed");
|
|
124
188
|
}
|
|
125
|
-
const
|
|
189
|
+
const response = await userResponse.json();
|
|
190
|
+
const user = response.data || response;
|
|
126
191
|
return {
|
|
127
192
|
token,
|
|
128
193
|
user: {
|
|
@@ -146,7 +211,8 @@ async function authenticateWithToken(token, baseUrl = "https://codmir.com") {
|
|
|
146
211
|
if (!response.ok) {
|
|
147
212
|
throw new Error("Invalid token");
|
|
148
213
|
}
|
|
149
|
-
const
|
|
214
|
+
const responseData = await response.json();
|
|
215
|
+
const user = responseData.data || responseData;
|
|
150
216
|
return {
|
|
151
217
|
token,
|
|
152
218
|
user: {
|
|
@@ -181,11 +247,16 @@ async function loginCommand(options) {
|
|
|
181
247
|
console.log(chalk.dim(" Authenticate to start using codmir CLI\n"));
|
|
182
248
|
try {
|
|
183
249
|
let authResult;
|
|
250
|
+
const baseUrl = getBaseUrl();
|
|
251
|
+
if (baseUrl !== "https://codmir.com") {
|
|
252
|
+
console.log(chalk.dim(` Connecting to: ${baseUrl}
|
|
253
|
+
`));
|
|
254
|
+
}
|
|
184
255
|
if (options.token) {
|
|
185
256
|
console.log(chalk.dim(" Authenticating with provided token..."));
|
|
186
|
-
authResult = await authenticateWithToken(options.token);
|
|
257
|
+
authResult = await authenticateWithToken(options.token, baseUrl);
|
|
187
258
|
} else {
|
|
188
|
-
authResult = await startOAuthFlow();
|
|
259
|
+
authResult = await startOAuthFlow(baseUrl);
|
|
189
260
|
}
|
|
190
261
|
saveAuth(authResult);
|
|
191
262
|
console.log(chalk.green("\n\u2705 Successfully logged in!"));
|
|
@@ -198,24 +269,124 @@ async function loginCommand(options) {
|
|
|
198
269
|
}
|
|
199
270
|
}
|
|
200
271
|
|
|
201
|
-
// src/cli/commands/
|
|
272
|
+
// src/cli/commands/logout.ts
|
|
202
273
|
import chalk2 from "chalk";
|
|
274
|
+
async function logoutCommand() {
|
|
275
|
+
if (!isAuthenticated()) {
|
|
276
|
+
console.log(chalk2.yellow("\u26A0\uFE0F Not logged in"));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const config = readConfig();
|
|
280
|
+
clearConfig();
|
|
281
|
+
console.log(chalk2.green("\u2705 Successfully logged out"));
|
|
282
|
+
if (config.email) {
|
|
283
|
+
console.log(chalk2.dim(" Goodbye,"), chalk2.bold(config.email));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/cli/commands/whoami.ts
|
|
288
|
+
import chalk3 from "chalk";
|
|
289
|
+
async function whoamiCommand() {
|
|
290
|
+
if (!isAuthenticated()) {
|
|
291
|
+
console.error(chalk3.red("\u274C Not authenticated"));
|
|
292
|
+
console.log(chalk3.dim(" Run"), chalk3.cyan("codmir login"), chalk3.dim("first"));
|
|
293
|
+
process.exit(1);
|
|
294
|
+
}
|
|
295
|
+
const config = readConfig();
|
|
296
|
+
console.log(chalk3.bold("\n\u{1F464} Current User\n"));
|
|
297
|
+
console.log(chalk3.dim(" Name:"), chalk3.bold(config.name || "N/A"));
|
|
298
|
+
console.log(chalk3.dim(" Email:"), chalk3.bold(config.email || "N/A"));
|
|
299
|
+
console.log(chalk3.dim(" User ID:"), chalk3.dim(config.userId || "N/A"));
|
|
300
|
+
if (config.lastLogin) {
|
|
301
|
+
const lastLogin = new Date(config.lastLogin);
|
|
302
|
+
console.log(chalk3.dim(" Last Login:"), chalk3.dim(lastLogin.toLocaleString()));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/cli/commands/link.ts
|
|
203
307
|
import prompts from "prompts";
|
|
308
|
+
import chalk4 from "chalk";
|
|
309
|
+
|
|
310
|
+
// src/cli/utils/machine-id.ts
|
|
311
|
+
import fs from "fs";
|
|
312
|
+
import path from "path";
|
|
313
|
+
import os from "os";
|
|
314
|
+
import crypto from "crypto";
|
|
315
|
+
var MACHINE_ID_FILE = path.join(os.homedir(), ".codmir", "machine-id");
|
|
316
|
+
function getMachineId() {
|
|
317
|
+
ensureConfigDir();
|
|
318
|
+
if (fs.existsSync(MACHINE_ID_FILE)) {
|
|
319
|
+
try {
|
|
320
|
+
return fs.readFileSync(MACHINE_ID_FILE, "utf-8").trim();
|
|
321
|
+
} catch (error) {
|
|
322
|
+
console.error("Error reading machine ID:", error);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const machineId = crypto.randomBytes(16).toString("hex");
|
|
326
|
+
try {
|
|
327
|
+
fs.writeFileSync(MACHINE_ID_FILE, machineId);
|
|
328
|
+
} catch (error) {
|
|
329
|
+
console.error("Error saving machine ID:", error);
|
|
330
|
+
}
|
|
331
|
+
return machineId;
|
|
332
|
+
}
|
|
333
|
+
function getMachineInfo() {
|
|
334
|
+
return {
|
|
335
|
+
machineId: getMachineId(),
|
|
336
|
+
hostname: os.hostname(),
|
|
337
|
+
platform: os.platform(),
|
|
338
|
+
arch: os.arch(),
|
|
339
|
+
nodeVersion: process.version,
|
|
340
|
+
cliVersion: getPackageVersion()
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function getPackageVersion() {
|
|
344
|
+
try {
|
|
345
|
+
const pkg = require_package();
|
|
346
|
+
return pkg.version;
|
|
347
|
+
} catch {
|
|
348
|
+
return "unknown";
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async function registerMachine(projectId, token, baseUrl) {
|
|
352
|
+
const machineInfo = getMachineInfo();
|
|
353
|
+
try {
|
|
354
|
+
const response = await fetch(`${baseUrl}/api/cli/register`, {
|
|
355
|
+
method: "POST",
|
|
356
|
+
headers: {
|
|
357
|
+
"Content-Type": "application/json",
|
|
358
|
+
"X-API-Key": token
|
|
359
|
+
},
|
|
360
|
+
body: JSON.stringify({
|
|
361
|
+
projectId,
|
|
362
|
+
...machineInfo,
|
|
363
|
+
workingDirectory: process.cwd()
|
|
364
|
+
})
|
|
365
|
+
});
|
|
366
|
+
if (!response.ok) {
|
|
367
|
+
throw new Error(`Failed to register machine: ${response.statusText}`);
|
|
368
|
+
}
|
|
369
|
+
} catch (error) {
|
|
370
|
+
console.error("[codmir] Failed to register machine:", error);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// src/cli/commands/link.ts
|
|
204
375
|
async function linkCommand(options) {
|
|
205
376
|
const token = getToken();
|
|
206
377
|
if (!token) {
|
|
207
|
-
console.error(
|
|
208
|
-
console.log(
|
|
378
|
+
console.error(chalk4.red("\u274C Not authenticated"));
|
|
379
|
+
console.log(chalk4.dim(" Run"), chalk4.cyan("codmir login"), chalk4.dim("first"));
|
|
209
380
|
process.exit(1);
|
|
210
381
|
}
|
|
211
|
-
console.log(
|
|
212
|
-
console.log(
|
|
382
|
+
console.log(chalk4.bold("\n\u{1F517} codmir link"));
|
|
383
|
+
console.log(chalk4.dim(" Link this directory to a codmir project\n"));
|
|
213
384
|
const existing = readProjectConfig();
|
|
214
385
|
if (existing) {
|
|
215
|
-
console.log(
|
|
216
|
-
console.log(
|
|
386
|
+
console.log(chalk4.yellow("\u26A0\uFE0F This directory is already linked to:"));
|
|
387
|
+
console.log(chalk4.dim(" Project ID:"), chalk4.bold(existing.projectId));
|
|
217
388
|
if (existing.projectName) {
|
|
218
|
-
console.log(
|
|
389
|
+
console.log(chalk4.dim(" Project:"), chalk4.bold(existing.projectName));
|
|
219
390
|
}
|
|
220
391
|
const { overwrite } = await prompts({
|
|
221
392
|
type: "confirm",
|
|
@@ -224,31 +395,33 @@ async function linkCommand(options) {
|
|
|
224
395
|
initial: false
|
|
225
396
|
});
|
|
226
397
|
if (!overwrite) {
|
|
227
|
-
console.log(
|
|
398
|
+
console.log(chalk4.dim(" Cancelled"));
|
|
228
399
|
return;
|
|
229
400
|
}
|
|
230
401
|
}
|
|
231
402
|
try {
|
|
403
|
+
const baseUrl = getBaseUrl();
|
|
232
404
|
const client = new CodmirClient({
|
|
233
405
|
apiKey: token,
|
|
234
|
-
baseUrl
|
|
406
|
+
baseUrl
|
|
235
407
|
});
|
|
236
408
|
let projectId = options.project;
|
|
237
409
|
let orgId = options.org;
|
|
238
|
-
console.log(
|
|
239
|
-
const response = await fetch(`${
|
|
410
|
+
console.log(chalk4.dim(" Fetching your projects...\n"));
|
|
411
|
+
const response = await fetch(`${baseUrl}/api/projects`, {
|
|
240
412
|
headers: {
|
|
241
|
-
"
|
|
413
|
+
"X-API-Key": token
|
|
242
414
|
}
|
|
243
415
|
});
|
|
244
416
|
if (!response.ok) {
|
|
245
417
|
throw new Error("Failed to fetch projects");
|
|
246
418
|
}
|
|
247
|
-
const
|
|
419
|
+
const responseData = await response.json();
|
|
420
|
+
const projects = responseData.data || responseData;
|
|
248
421
|
if (!projectId) {
|
|
249
422
|
if (projects.length === 0) {
|
|
250
|
-
console.log(
|
|
251
|
-
console.log(
|
|
423
|
+
console.log(chalk4.yellow("\u26A0\uFE0F You don't have any projects yet"));
|
|
424
|
+
console.log(chalk4.dim(" Create a project at"), chalk4.cyan("https://codmir.com"));
|
|
252
425
|
process.exit(1);
|
|
253
426
|
}
|
|
254
427
|
const { selectedProject } = await prompts({
|
|
@@ -262,14 +435,14 @@ async function linkCommand(options) {
|
|
|
262
435
|
}))
|
|
263
436
|
});
|
|
264
437
|
if (!selectedProject) {
|
|
265
|
-
console.log(
|
|
438
|
+
console.log(chalk4.dim(" Cancelled"));
|
|
266
439
|
return;
|
|
267
440
|
}
|
|
268
441
|
projectId = selectedProject;
|
|
269
442
|
}
|
|
270
443
|
const project = projects.find((p) => p.id === projectId);
|
|
271
444
|
if (!project) {
|
|
272
|
-
console.error(
|
|
445
|
+
console.error(chalk4.red("\u274C Project not found"));
|
|
273
446
|
process.exit(1);
|
|
274
447
|
}
|
|
275
448
|
writeProjectConfig({
|
|
@@ -277,51 +450,35 @@ async function linkCommand(options) {
|
|
|
277
450
|
organizationId: project.organizationId || orgId,
|
|
278
451
|
projectName: project.name
|
|
279
452
|
});
|
|
280
|
-
console.log(
|
|
281
|
-
console.log(
|
|
282
|
-
console.log(
|
|
283
|
-
console.log(
|
|
284
|
-
console.log(
|
|
453
|
+
console.log(chalk4.green("\n\u2705 Successfully linked!"));
|
|
454
|
+
console.log(chalk4.dim(" Project:"), chalk4.bold(project.name));
|
|
455
|
+
console.log(chalk4.dim(" ID:"), chalk4.bold(project.id));
|
|
456
|
+
console.log(chalk4.dim("\n Configuration saved to"), chalk4.cyan(".codmir.json"));
|
|
457
|
+
console.log(chalk4.dim(" You can now use the codmir package in your project"));
|
|
458
|
+
await registerMachine(project.id, token, baseUrl);
|
|
459
|
+
console.log();
|
|
460
|
+
const { analyze } = await prompts({
|
|
461
|
+
type: "confirm",
|
|
462
|
+
name: "analyze",
|
|
463
|
+
message: "Analyze codebase now? (Recommended)",
|
|
464
|
+
initial: true
|
|
465
|
+
});
|
|
466
|
+
if (analyze) {
|
|
467
|
+
console.log();
|
|
468
|
+
const { analyzeCommand: analyzeCommand2 } = await import("../analyze-LULBI4ZC.mjs");
|
|
469
|
+
await analyzeCommand2({ mode: "local" });
|
|
470
|
+
} else {
|
|
471
|
+
console.log();
|
|
472
|
+
console.log(chalk4.dim(" You can analyze later with:"), chalk4.cyan("codmir analyze"));
|
|
473
|
+
console.log();
|
|
474
|
+
}
|
|
285
475
|
} catch (error) {
|
|
286
|
-
console.
|
|
476
|
+
console.log(chalk4.red("\n\u274C Failed to link project"));
|
|
477
|
+
console.log(chalk4.dim(error.message));
|
|
287
478
|
process.exit(1);
|
|
288
479
|
}
|
|
289
480
|
}
|
|
290
481
|
|
|
291
|
-
// src/cli/commands/whoami.ts
|
|
292
|
-
import chalk3 from "chalk";
|
|
293
|
-
async function whoamiCommand() {
|
|
294
|
-
if (!isAuthenticated()) {
|
|
295
|
-
console.error(chalk3.red("\u274C Not authenticated"));
|
|
296
|
-
console.log(chalk3.dim(" Run"), chalk3.cyan("codmir login"), chalk3.dim("first"));
|
|
297
|
-
process.exit(1);
|
|
298
|
-
}
|
|
299
|
-
const config = readConfig();
|
|
300
|
-
console.log(chalk3.bold("\n\u{1F464} Current User\n"));
|
|
301
|
-
console.log(chalk3.dim(" Name:"), chalk3.bold(config.name || "N/A"));
|
|
302
|
-
console.log(chalk3.dim(" Email:"), chalk3.bold(config.email || "N/A"));
|
|
303
|
-
console.log(chalk3.dim(" User ID:"), chalk3.dim(config.userId || "N/A"));
|
|
304
|
-
if (config.lastLogin) {
|
|
305
|
-
const lastLogin = new Date(config.lastLogin);
|
|
306
|
-
console.log(chalk3.dim(" Last Login:"), chalk3.dim(lastLogin.toLocaleString()));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// src/cli/commands/logout.ts
|
|
311
|
-
import chalk4 from "chalk";
|
|
312
|
-
async function logoutCommand() {
|
|
313
|
-
if (!isAuthenticated()) {
|
|
314
|
-
console.log(chalk4.yellow("\u26A0\uFE0F Not logged in"));
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const config = readConfig();
|
|
318
|
-
clearConfig();
|
|
319
|
-
console.log(chalk4.green("\u2705 Successfully logged out"));
|
|
320
|
-
if (config.email) {
|
|
321
|
-
console.log(chalk4.dim(" Goodbye,"), chalk4.bold(config.email));
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
482
|
// src/cli/commands/init.ts
|
|
326
483
|
import chalk5 from "chalk";
|
|
327
484
|
import fs2 from "fs";
|
|
@@ -401,15 +558,17 @@ async function projectsCommand() {
|
|
|
401
558
|
}
|
|
402
559
|
console.log(chalk6.bold("\n\u{1F4C1} Your Projects\n"));
|
|
403
560
|
try {
|
|
404
|
-
const
|
|
561
|
+
const baseUrl = getBaseUrl();
|
|
562
|
+
const response = await fetch(`${baseUrl}/api/projects`, {
|
|
405
563
|
headers: {
|
|
406
|
-
"
|
|
564
|
+
"X-API-Key": token
|
|
407
565
|
}
|
|
408
566
|
});
|
|
409
567
|
if (!response.ok) {
|
|
410
568
|
throw new Error("Failed to fetch projects");
|
|
411
569
|
}
|
|
412
|
-
const
|
|
570
|
+
const responseData = await response.json();
|
|
571
|
+
const projects = responseData.data || responseData;
|
|
413
572
|
if (projects.length === 0) {
|
|
414
573
|
console.log(chalk6.yellow(" No projects found"));
|
|
415
574
|
console.log(chalk6.dim(" Create one at"), chalk6.cyan("https://codmir.com"));
|
|
@@ -430,6 +589,860 @@ async function projectsCommand() {
|
|
|
430
589
|
}
|
|
431
590
|
}
|
|
432
591
|
|
|
592
|
+
// src/cli/commands/assistant.ts
|
|
593
|
+
import chalk7 from "chalk";
|
|
594
|
+
import ora from "ora";
|
|
595
|
+
import prompts2 from "prompts";
|
|
596
|
+
import clipboardy from "clipboardy";
|
|
597
|
+
import fs3 from "fs";
|
|
598
|
+
import path3 from "path";
|
|
599
|
+
import FormData from "form-data";
|
|
600
|
+
async function assistantCommand(query, options = {}) {
|
|
601
|
+
const token = getToken();
|
|
602
|
+
if (!token) {
|
|
603
|
+
console.error(chalk7.red("\u274C Not authenticated"));
|
|
604
|
+
console.log(chalk7.dim(" Run"), chalk7.cyan("codmir login"), chalk7.dim("first"));
|
|
605
|
+
process.exit(1);
|
|
606
|
+
}
|
|
607
|
+
const baseUrl = getBaseUrl();
|
|
608
|
+
const conversationHistory = [];
|
|
609
|
+
const context = getExecutionContext();
|
|
610
|
+
if (context.isLinkedProject) {
|
|
611
|
+
console.log(chalk7.dim(` \u{1F4C1} Project: ${context.projectConfig?.projectName || context.projectConfig?.projectId}`));
|
|
612
|
+
console.log(chalk7.dim(` \u{1F517} Mode: ${chalk7.cyan("local")} (linked project)
|
|
613
|
+
`));
|
|
614
|
+
} else {
|
|
615
|
+
console.log(chalk7.dim(` \u{1F310} Mode: ${chalk7.yellow("global")}
|
|
616
|
+
`));
|
|
617
|
+
}
|
|
618
|
+
conversationHistory.push({
|
|
619
|
+
role: "system",
|
|
620
|
+
content: `You are codmir, an AI assistant for developers. You help with:
|
|
621
|
+
- Code questions and debugging
|
|
622
|
+
- Project setup and configuration
|
|
623
|
+
- Best practices and patterns
|
|
624
|
+
- Task automation
|
|
625
|
+
|
|
626
|
+
Be concise, practical, and code-focused. Use lowercase "codmir" for the brand.`
|
|
627
|
+
});
|
|
628
|
+
console.log(chalk7.bold("\n\u{1F916} codmir"));
|
|
629
|
+
console.log(chalk7.dim(" AI assistant for developers\n"));
|
|
630
|
+
if (query) {
|
|
631
|
+
await handleQuery(query, conversationHistory, baseUrl, token, options);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
console.log(chalk7.dim(" Type your question or"), chalk7.cyan("exit"), chalk7.dim("to quit"));
|
|
635
|
+
console.log(chalk7.dim(" \u{1F4CB} Tip: Copy images to clipboard before asking for automatic upload"));
|
|
636
|
+
console.log(chalk7.dim(' Example: "How do I setup authentication?"\n'));
|
|
637
|
+
while (true) {
|
|
638
|
+
const { userInput } = await prompts2({
|
|
639
|
+
type: "text",
|
|
640
|
+
name: "userInput",
|
|
641
|
+
message: chalk7.cyan("codmir"),
|
|
642
|
+
validate: (value) => value.length > 0 || "Please enter a question"
|
|
643
|
+
});
|
|
644
|
+
if (!userInput || userInput.toLowerCase() === "exit" || userInput.toLowerCase() === "quit") {
|
|
645
|
+
console.log(chalk7.dim("\n Goodbye! \u{1F44B}\n"));
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
await handleQuery(userInput, conversationHistory, baseUrl, token, options);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
async function handleQuery(query, conversationHistory, baseUrl, token, options) {
|
|
652
|
+
let imagePaths;
|
|
653
|
+
const hasClipboardImage = await checkClipboardForImage();
|
|
654
|
+
if (hasClipboardImage) {
|
|
655
|
+
const { attachImage } = await prompts2({
|
|
656
|
+
type: "confirm",
|
|
657
|
+
name: "attachImage",
|
|
658
|
+
message: chalk7.cyan("\u{1F4CB} Image detected in clipboard. Attach to message?"),
|
|
659
|
+
initial: true
|
|
660
|
+
});
|
|
661
|
+
if (attachImage) {
|
|
662
|
+
const imagePath = await saveClipboardImage();
|
|
663
|
+
if (imagePath) {
|
|
664
|
+
imagePaths = [imagePath];
|
|
665
|
+
console.log(chalk7.green(" \u2713 Image attached from clipboard\n"));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
conversationHistory.push({
|
|
670
|
+
role: "user",
|
|
671
|
+
content: query,
|
|
672
|
+
images: imagePaths
|
|
673
|
+
});
|
|
674
|
+
const spinner = ora({
|
|
675
|
+
text: chalk7.dim("Thinking..."),
|
|
676
|
+
color: "cyan",
|
|
677
|
+
spinner: {
|
|
678
|
+
interval: 80,
|
|
679
|
+
frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"]
|
|
680
|
+
}
|
|
681
|
+
}).start();
|
|
682
|
+
try {
|
|
683
|
+
let response;
|
|
684
|
+
if (imagePaths && imagePaths.length > 0) {
|
|
685
|
+
const formData = new FormData();
|
|
686
|
+
formData.append("query", query);
|
|
687
|
+
formData.append("model", options.model || "gpt-4-turbo-preview");
|
|
688
|
+
if (options.project) formData.append("project", options.project);
|
|
689
|
+
if (options.context) formData.append("includeContext", "true");
|
|
690
|
+
formData.append("messages", JSON.stringify(conversationHistory));
|
|
691
|
+
for (const imagePath of imagePaths) {
|
|
692
|
+
formData.append("images", fs3.createReadStream(imagePath));
|
|
693
|
+
}
|
|
694
|
+
response = await fetch(`${baseUrl}/api/assistant/chat`, {
|
|
695
|
+
method: "POST",
|
|
696
|
+
headers: {
|
|
697
|
+
"X-API-Key": token,
|
|
698
|
+
...formData.getHeaders()
|
|
699
|
+
},
|
|
700
|
+
body: formData
|
|
701
|
+
});
|
|
702
|
+
} else {
|
|
703
|
+
response = await fetch(`${baseUrl}/api/assistant/chat`, {
|
|
704
|
+
method: "POST",
|
|
705
|
+
headers: {
|
|
706
|
+
"Content-Type": "application/json",
|
|
707
|
+
"X-API-Key": token
|
|
708
|
+
},
|
|
709
|
+
body: JSON.stringify({
|
|
710
|
+
messages: conversationHistory,
|
|
711
|
+
model: options.model || "gpt-4-turbo-preview",
|
|
712
|
+
project: options.project,
|
|
713
|
+
includeContext: options.context
|
|
714
|
+
})
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
spinner.stop();
|
|
718
|
+
if (!response.ok) {
|
|
719
|
+
throw new Error(`API error: ${response.status}`);
|
|
720
|
+
}
|
|
721
|
+
const data = await response.json();
|
|
722
|
+
const assistantMessage = data.message || data.content || "Sorry, I couldn't process that.";
|
|
723
|
+
conversationHistory.push({
|
|
724
|
+
role: "assistant",
|
|
725
|
+
content: assistantMessage
|
|
726
|
+
});
|
|
727
|
+
console.log("\n" + renderResponse(assistantMessage) + "\n");
|
|
728
|
+
} catch (error) {
|
|
729
|
+
spinner.stop();
|
|
730
|
+
console.error(chalk7.red("\n\u274C Error:"), error instanceof Error ? error.message : "Unknown error");
|
|
731
|
+
console.log(chalk7.dim(" Try again or check your connection\n"));
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
function renderResponse(message) {
|
|
735
|
+
const indicator = getIndicator();
|
|
736
|
+
const lines = message.split("\n");
|
|
737
|
+
let output = "";
|
|
738
|
+
lines.forEach((line, index) => {
|
|
739
|
+
if (index === 0) {
|
|
740
|
+
output += `${indicator} ${chalk7.white(line)}
|
|
741
|
+
`;
|
|
742
|
+
} else {
|
|
743
|
+
output += ` ${chalk7.white(line)}
|
|
744
|
+
`;
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
return output;
|
|
748
|
+
}
|
|
749
|
+
function getIndicator() {
|
|
750
|
+
const isDark = isTerminalDark();
|
|
751
|
+
if (isDark) {
|
|
752
|
+
return chalk7.whiteBright("\u25CF");
|
|
753
|
+
} else {
|
|
754
|
+
return chalk7.black("\u25CF");
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
function isTerminalDark() {
|
|
758
|
+
const colorScheme = process.env.COLORFGBG;
|
|
759
|
+
if (colorScheme) {
|
|
760
|
+
const parts = colorScheme.split(";");
|
|
761
|
+
const bg = parseInt(parts[1] || "0");
|
|
762
|
+
return bg < 8;
|
|
763
|
+
}
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
766
|
+
async function quickQueryCommand(query, options = {}) {
|
|
767
|
+
const conversationHistory = [{
|
|
768
|
+
role: "system",
|
|
769
|
+
content: "You are codmir, a concise AI assistant for developers. Give short, practical answers."
|
|
770
|
+
}];
|
|
771
|
+
const token = getToken();
|
|
772
|
+
if (!token) {
|
|
773
|
+
console.error(chalk7.red("\u274C Not authenticated"));
|
|
774
|
+
process.exit(1);
|
|
775
|
+
}
|
|
776
|
+
await handleQuery(query, conversationHistory, getBaseUrl(), token, options);
|
|
777
|
+
}
|
|
778
|
+
async function checkClipboardForImage() {
|
|
779
|
+
try {
|
|
780
|
+
const clipboardContent = await clipboardy.read();
|
|
781
|
+
return clipboardContent.startsWith("data:image/") || clipboardContent.match(/\.(png|jpg|jpeg|gif|webp)$/i) !== null;
|
|
782
|
+
} catch {
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
async function saveClipboardImage() {
|
|
787
|
+
try {
|
|
788
|
+
const clipboardContent = await clipboardy.read();
|
|
789
|
+
if (clipboardContent.startsWith("data:image/")) {
|
|
790
|
+
const matches = clipboardContent.match(/^data:image\/(\w+);base64,(.+)$/);
|
|
791
|
+
if (!matches) return null;
|
|
792
|
+
const ext = matches[1];
|
|
793
|
+
const base64Data = matches[2];
|
|
794
|
+
const buffer = Buffer.from(base64Data, "base64");
|
|
795
|
+
const tmpPath = path3.join("/tmp", `codmir-assistant-${Date.now()}.${ext}`);
|
|
796
|
+
fs3.writeFileSync(tmpPath, buffer);
|
|
797
|
+
return tmpPath;
|
|
798
|
+
}
|
|
799
|
+
if (fs3.existsSync(clipboardContent)) {
|
|
800
|
+
return clipboardContent;
|
|
801
|
+
}
|
|
802
|
+
return null;
|
|
803
|
+
} catch (error) {
|
|
804
|
+
console.error(chalk7.dim(" Failed to save clipboard image"));
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// src/cli/commands/ticket.ts
|
|
810
|
+
import chalk8 from "chalk";
|
|
811
|
+
import prompts3 from "prompts";
|
|
812
|
+
import clipboardy2 from "clipboardy";
|
|
813
|
+
import fs4 from "fs";
|
|
814
|
+
import path4 from "path";
|
|
815
|
+
import FormData2 from "form-data";
|
|
816
|
+
async function createTicketCommand() {
|
|
817
|
+
const token = getToken();
|
|
818
|
+
if (!token) {
|
|
819
|
+
console.error(chalk8.red("\u274C Not authenticated"));
|
|
820
|
+
console.log(chalk8.dim(" Run"), chalk8.cyan("codmir login"), chalk8.dim("first"));
|
|
821
|
+
process.exit(1);
|
|
822
|
+
}
|
|
823
|
+
console.log(chalk8.bold("\n\u{1F3AB} Create Ticket\n"));
|
|
824
|
+
try {
|
|
825
|
+
const linkedProject = getProjectConfig();
|
|
826
|
+
let selectedProject = null;
|
|
827
|
+
let selectedOrg = null;
|
|
828
|
+
if (linkedProject) {
|
|
829
|
+
const { useLinked } = await prompts3({
|
|
830
|
+
type: "confirm",
|
|
831
|
+
name: "useLinked",
|
|
832
|
+
message: `Use linked project: ${chalk8.cyan(linkedProject.name)}?`,
|
|
833
|
+
initial: true
|
|
834
|
+
});
|
|
835
|
+
if (useLinked) {
|
|
836
|
+
selectedProject = linkedProject;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (!selectedProject) {
|
|
840
|
+
const selection = await navigateAndSelectProject(token);
|
|
841
|
+
if (!selection) {
|
|
842
|
+
console.log(chalk8.yellow("\n\u26A0\uFE0F Cancelled"));
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
selectedProject = selection.project;
|
|
846
|
+
selectedOrg = selection.organization;
|
|
847
|
+
}
|
|
848
|
+
console.log(chalk8.green("\n\u2713 Project:"), chalk8.cyan(selectedProject.name));
|
|
849
|
+
const ticketData = await collectTicketDetails();
|
|
850
|
+
if (!ticketData) {
|
|
851
|
+
console.log(chalk8.yellow("\n\u26A0\uFE0F Cancelled"));
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
const hasClipboardImage = await checkClipboardForImage2();
|
|
855
|
+
if (hasClipboardImage) {
|
|
856
|
+
const { attachImage } = await prompts3({
|
|
857
|
+
type: "confirm",
|
|
858
|
+
name: "attachImage",
|
|
859
|
+
message: chalk8.cyan("\u{1F4CB} Image detected in clipboard. Attach to ticket?"),
|
|
860
|
+
initial: true
|
|
861
|
+
});
|
|
862
|
+
if (attachImage) {
|
|
863
|
+
const imagePath = await saveClipboardImage2();
|
|
864
|
+
if (imagePath) {
|
|
865
|
+
ticketData.images = [imagePath];
|
|
866
|
+
console.log(chalk8.green("\u2713 Image attached"));
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
await createTicket(token, selectedProject.id, ticketData);
|
|
871
|
+
} catch (error) {
|
|
872
|
+
console.error(chalk8.red("\n\u274C Error:"), error instanceof Error ? error.message : "Unknown error");
|
|
873
|
+
process.exit(1);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
async function navigateAndSelectProject(token) {
|
|
877
|
+
const baseUrl = getBaseUrl();
|
|
878
|
+
console.log(chalk8.dim("\n Loading organizations..."));
|
|
879
|
+
const orgsResponse = await fetch(`${baseUrl}/api/user/organizations`, {
|
|
880
|
+
headers: { "X-API-Key": token }
|
|
881
|
+
});
|
|
882
|
+
if (!orgsResponse.ok) {
|
|
883
|
+
throw new Error("Failed to fetch organizations");
|
|
884
|
+
}
|
|
885
|
+
const { organizations } = await orgsResponse.json();
|
|
886
|
+
if (!organizations || organizations.length === 0) {
|
|
887
|
+
console.log(chalk8.yellow("\n\u26A0\uFE0F No organizations found"));
|
|
888
|
+
return null;
|
|
889
|
+
}
|
|
890
|
+
console.log(chalk8.bold("\n\u{1F579}\uFE0F Select Organization"));
|
|
891
|
+
console.log(chalk8.dim(" Use \u2191\u2193 arrows to navigate, Enter to select\n"));
|
|
892
|
+
const { orgIndex } = await prompts3({
|
|
893
|
+
type: "select",
|
|
894
|
+
name: "orgIndex",
|
|
895
|
+
message: chalk8.cyan("Organization"),
|
|
896
|
+
choices: organizations.map((org, index) => ({
|
|
897
|
+
title: `${getJoystickIndicator(index)} ${org.name}`,
|
|
898
|
+
value: index,
|
|
899
|
+
description: org.slug
|
|
900
|
+
})),
|
|
901
|
+
initial: 0
|
|
902
|
+
});
|
|
903
|
+
if (orgIndex === void 0) return null;
|
|
904
|
+
const selectedOrg = organizations[orgIndex];
|
|
905
|
+
console.log(chalk8.dim("\n Loading projects..."));
|
|
906
|
+
const projectsResponse = await fetch(
|
|
907
|
+
`${baseUrl}/api/organizations/${selectedOrg.id}/projects`,
|
|
908
|
+
{ headers: { "X-API-Key": token } }
|
|
909
|
+
);
|
|
910
|
+
if (!projectsResponse.ok) {
|
|
911
|
+
throw new Error("Failed to fetch projects");
|
|
912
|
+
}
|
|
913
|
+
const projectsData = await projectsResponse.json();
|
|
914
|
+
const projects = projectsData.data || projectsData;
|
|
915
|
+
if (!projects || projects.length === 0) {
|
|
916
|
+
console.log(chalk8.yellow("\n\u26A0\uFE0F No projects found in this organization"));
|
|
917
|
+
return null;
|
|
918
|
+
}
|
|
919
|
+
console.log(chalk8.bold("\n\u{1F579}\uFE0F Select Project"));
|
|
920
|
+
console.log(chalk8.dim(" Use \u2191\u2193 arrows to navigate, Enter to select\n"));
|
|
921
|
+
const { projectIndex } = await prompts3({
|
|
922
|
+
type: "select",
|
|
923
|
+
name: "projectIndex",
|
|
924
|
+
message: chalk8.cyan("Project"),
|
|
925
|
+
choices: projects.map((project, index) => ({
|
|
926
|
+
title: `${getJoystickIndicator(index)} ${project.name}`,
|
|
927
|
+
value: index,
|
|
928
|
+
description: project.key
|
|
929
|
+
})),
|
|
930
|
+
initial: 0
|
|
931
|
+
});
|
|
932
|
+
if (projectIndex === void 0) return null;
|
|
933
|
+
return {
|
|
934
|
+
organization: selectedOrg,
|
|
935
|
+
project: projects[projectIndex]
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
function getJoystickIndicator(index) {
|
|
939
|
+
const indicators = ["\u25B8", "\u25B9", "\u25B8", "\u25B9"];
|
|
940
|
+
return chalk8.cyan(indicators[index % indicators.length]);
|
|
941
|
+
}
|
|
942
|
+
async function collectTicketDetails() {
|
|
943
|
+
console.log(chalk8.bold("\n\u{1F4DD} Ticket Details\n"));
|
|
944
|
+
const responses = await prompts3([
|
|
945
|
+
{
|
|
946
|
+
type: "text",
|
|
947
|
+
name: "title",
|
|
948
|
+
message: chalk8.cyan("Title"),
|
|
949
|
+
validate: (value) => value.length > 0 || "Title is required"
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
type: "text",
|
|
953
|
+
name: "description",
|
|
954
|
+
message: chalk8.cyan("Description"),
|
|
955
|
+
initial: ""
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
type: "select",
|
|
959
|
+
name: "type",
|
|
960
|
+
message: chalk8.cyan("Type"),
|
|
961
|
+
choices: [
|
|
962
|
+
{ title: "\u{1F41B} Bug", value: "BUG" },
|
|
963
|
+
{ title: "\u2728 Feature", value: "FEATURE" },
|
|
964
|
+
{ title: "\u{1F4CB} Task", value: "TASK" },
|
|
965
|
+
{ title: "\u{1F527} Improvement", value: "IMPROVEMENT" }
|
|
966
|
+
],
|
|
967
|
+
initial: 0
|
|
968
|
+
},
|
|
969
|
+
{
|
|
970
|
+
type: "select",
|
|
971
|
+
name: "priority",
|
|
972
|
+
message: chalk8.cyan("Priority"),
|
|
973
|
+
choices: [
|
|
974
|
+
{ title: "\u{1F7E2} Low", value: "LOW" },
|
|
975
|
+
{ title: "\u{1F7E1} Medium", value: "MEDIUM" },
|
|
976
|
+
{ title: "\u{1F7E0} High", value: "HIGH" },
|
|
977
|
+
{ title: "\u{1F534} Critical", value: "CRITICAL" }
|
|
978
|
+
],
|
|
979
|
+
initial: 1
|
|
980
|
+
}
|
|
981
|
+
]);
|
|
982
|
+
if (!responses.title) return null;
|
|
983
|
+
return responses;
|
|
984
|
+
}
|
|
985
|
+
async function checkClipboardForImage2() {
|
|
986
|
+
try {
|
|
987
|
+
const clipboardContent = await clipboardy2.read();
|
|
988
|
+
return clipboardContent.startsWith("data:image/") || clipboardContent.match(/\.(png|jpg|jpeg|gif|webp)$/i) !== null;
|
|
989
|
+
} catch {
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
async function saveClipboardImage2() {
|
|
994
|
+
try {
|
|
995
|
+
const clipboardContent = await clipboardy2.read();
|
|
996
|
+
if (clipboardContent.startsWith("data:image/")) {
|
|
997
|
+
const matches = clipboardContent.match(/^data:image\/(\w+);base64,(.+)$/);
|
|
998
|
+
if (!matches) return null;
|
|
999
|
+
const ext = matches[1];
|
|
1000
|
+
const base64Data = matches[2];
|
|
1001
|
+
const buffer = Buffer.from(base64Data, "base64");
|
|
1002
|
+
const tmpPath = path4.join("/tmp", `codmir-ticket-${Date.now()}.${ext}`);
|
|
1003
|
+
fs4.writeFileSync(tmpPath, buffer);
|
|
1004
|
+
return tmpPath;
|
|
1005
|
+
}
|
|
1006
|
+
if (fs4.existsSync(clipboardContent)) {
|
|
1007
|
+
return clipboardContent;
|
|
1008
|
+
}
|
|
1009
|
+
return null;
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
console.error(chalk8.dim(" Failed to save clipboard image"));
|
|
1012
|
+
return null;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
async function createTicket(token, projectId, ticketData) {
|
|
1016
|
+
const baseUrl = getBaseUrl();
|
|
1017
|
+
console.log(chalk8.dim("\n Creating ticket..."));
|
|
1018
|
+
try {
|
|
1019
|
+
let response;
|
|
1020
|
+
if (ticketData.images && ticketData.images.length > 0) {
|
|
1021
|
+
const formData = new FormData2();
|
|
1022
|
+
formData.append("title", ticketData.title);
|
|
1023
|
+
if (ticketData.description) formData.append("description", ticketData.description);
|
|
1024
|
+
if (ticketData.type) formData.append("type", ticketData.type);
|
|
1025
|
+
if (ticketData.priority) formData.append("priority", ticketData.priority);
|
|
1026
|
+
for (const imagePath of ticketData.images) {
|
|
1027
|
+
formData.append("images", fs4.createReadStream(imagePath));
|
|
1028
|
+
}
|
|
1029
|
+
response = await fetch(`${baseUrl}/api/project/${projectId}/tickets`, {
|
|
1030
|
+
method: "POST",
|
|
1031
|
+
headers: {
|
|
1032
|
+
"X-API-Key": token,
|
|
1033
|
+
...formData.getHeaders()
|
|
1034
|
+
},
|
|
1035
|
+
body: formData
|
|
1036
|
+
});
|
|
1037
|
+
} else {
|
|
1038
|
+
response = await fetch(`${baseUrl}/api/project/${projectId}/tickets`, {
|
|
1039
|
+
method: "POST",
|
|
1040
|
+
headers: {
|
|
1041
|
+
"Content-Type": "application/json",
|
|
1042
|
+
"X-API-Key": token
|
|
1043
|
+
},
|
|
1044
|
+
body: JSON.stringify(ticketData)
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
if (!response.ok) {
|
|
1048
|
+
const error = await response.text();
|
|
1049
|
+
throw new Error(`Failed to create ticket: ${error}`);
|
|
1050
|
+
}
|
|
1051
|
+
const ticket = await response.json();
|
|
1052
|
+
const ticketData_response = ticket.data || ticket;
|
|
1053
|
+
console.log(chalk8.green("\n\u2705 Ticket created successfully!\n"));
|
|
1054
|
+
console.log(chalk8.bold(" Ticket:"), chalk8.cyan(`#${ticketData_response.key || ticketData_response.id}`));
|
|
1055
|
+
console.log(chalk8.bold(" Title:"), ticketData_response.title);
|
|
1056
|
+
console.log(chalk8.bold(" Type:"), getTypeEmoji(ticketData_response.type), ticketData_response.type);
|
|
1057
|
+
console.log(chalk8.bold(" Priority:"), getPriorityEmoji(ticketData_response.priority), ticketData_response.priority);
|
|
1058
|
+
if (ticketData.images && ticketData.images.length > 0) {
|
|
1059
|
+
console.log(chalk8.bold(" Attachments:"), chalk8.green(`${ticketData.images.length} image(s)`));
|
|
1060
|
+
}
|
|
1061
|
+
console.log();
|
|
1062
|
+
} catch (error) {
|
|
1063
|
+
throw error;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
function getTypeEmoji(type) {
|
|
1067
|
+
const emojis = {
|
|
1068
|
+
BUG: "\u{1F41B}",
|
|
1069
|
+
FEATURE: "\u2728",
|
|
1070
|
+
TASK: "\u{1F4CB}",
|
|
1071
|
+
IMPROVEMENT: "\u{1F527}"
|
|
1072
|
+
};
|
|
1073
|
+
return emojis[type] || "\u{1F4CB}";
|
|
1074
|
+
}
|
|
1075
|
+
function getPriorityEmoji(priority) {
|
|
1076
|
+
const emojis = {
|
|
1077
|
+
LOW: "\u{1F7E2}",
|
|
1078
|
+
MEDIUM: "\u{1F7E1}",
|
|
1079
|
+
HIGH: "\u{1F7E0}",
|
|
1080
|
+
CRITICAL: "\u{1F534}"
|
|
1081
|
+
};
|
|
1082
|
+
return emojis[priority] || "\u{1F7E1}";
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
// src/cli/commands/council.ts
|
|
1086
|
+
import chalk9 from "chalk";
|
|
1087
|
+
import ora2 from "ora";
|
|
1088
|
+
import prompts4 from "prompts";
|
|
1089
|
+
import WebSocket from "ws";
|
|
1090
|
+
var ROLE_ICONS = {
|
|
1091
|
+
architect: "\u{1F3D7}\uFE0F ",
|
|
1092
|
+
security: "\u{1F512}",
|
|
1093
|
+
implementer: "\u{1F4BB}",
|
|
1094
|
+
reviewer: "\u{1F50D}"
|
|
1095
|
+
};
|
|
1096
|
+
var ROLE_COLORS = {
|
|
1097
|
+
architect: chalk9.blue,
|
|
1098
|
+
security: chalk9.red,
|
|
1099
|
+
implementer: chalk9.green,
|
|
1100
|
+
reviewer: chalk9.yellow
|
|
1101
|
+
};
|
|
1102
|
+
async function councilCommand(task, options = {}) {
|
|
1103
|
+
try {
|
|
1104
|
+
printHeader();
|
|
1105
|
+
if (!task) {
|
|
1106
|
+
const response = await prompts4({
|
|
1107
|
+
type: "text",
|
|
1108
|
+
name: "task",
|
|
1109
|
+
message: chalk9.cyan("\u{1F916} What would you like the council to build?"),
|
|
1110
|
+
validate: (value) => value.length > 0 || "Task cannot be empty"
|
|
1111
|
+
});
|
|
1112
|
+
if (!response.task) {
|
|
1113
|
+
console.log(chalk9.yellow("\nCouncil session cancelled."));
|
|
1114
|
+
process.exit(0);
|
|
1115
|
+
}
|
|
1116
|
+
task = response.task;
|
|
1117
|
+
}
|
|
1118
|
+
console.log("");
|
|
1119
|
+
const token = getToken();
|
|
1120
|
+
const baseUrl = getBaseUrl();
|
|
1121
|
+
if (!token) {
|
|
1122
|
+
console.log(chalk9.red("\u274C Not authenticated. Please run: codmir login"));
|
|
1123
|
+
process.exit(1);
|
|
1124
|
+
}
|
|
1125
|
+
const mode = options.local ? "local" : "lambda";
|
|
1126
|
+
const apiUrl = baseUrl.replace("http", "ws") + "/council";
|
|
1127
|
+
console.log(chalk9.gray(`Mode: ${mode === "lambda" ? "AWS Lambda (Serverless)" : "Local LAN Cluster"}`));
|
|
1128
|
+
console.log("");
|
|
1129
|
+
const ws = new WebSocket(apiUrl, {
|
|
1130
|
+
headers: {
|
|
1131
|
+
Authorization: `Bearer ${token}`
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
let sessionId = null;
|
|
1135
|
+
let currentSpinner = null;
|
|
1136
|
+
let roundResponses = [];
|
|
1137
|
+
ws.on("open", () => {
|
|
1138
|
+
ws.send(JSON.stringify({
|
|
1139
|
+
type: "create-session",
|
|
1140
|
+
problem: task,
|
|
1141
|
+
mode,
|
|
1142
|
+
options: {
|
|
1143
|
+
initialMembers: parseInt(options.members || "2"),
|
|
1144
|
+
timeout: parseInt(options.timeout || "300") * 1e3
|
|
1145
|
+
}
|
|
1146
|
+
}));
|
|
1147
|
+
});
|
|
1148
|
+
ws.on("message", (data) => {
|
|
1149
|
+
const message = JSON.parse(data.toString());
|
|
1150
|
+
handleCouncilMessage(message, {
|
|
1151
|
+
currentSpinner,
|
|
1152
|
+
roundResponses,
|
|
1153
|
+
onSpinnerUpdate: (spinner) => {
|
|
1154
|
+
currentSpinner = spinner;
|
|
1155
|
+
},
|
|
1156
|
+
onExit: () => process.exit(0)
|
|
1157
|
+
});
|
|
1158
|
+
});
|
|
1159
|
+
ws.on("error", (error) => {
|
|
1160
|
+
if (currentSpinner) currentSpinner.fail();
|
|
1161
|
+
console.log(chalk9.red(`
|
|
1162
|
+
\u274C Connection error: ${error.message}`));
|
|
1163
|
+
process.exit(1);
|
|
1164
|
+
});
|
|
1165
|
+
ws.on("close", () => {
|
|
1166
|
+
if (currentSpinner) currentSpinner.stop();
|
|
1167
|
+
});
|
|
1168
|
+
} catch (error) {
|
|
1169
|
+
console.log(chalk9.red(`
|
|
1170
|
+
\u274C Error: ${error instanceof Error ? error.message : "Unknown error"}`));
|
|
1171
|
+
process.exit(1);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
function printHeader() {
|
|
1175
|
+
console.log("");
|
|
1176
|
+
console.log(chalk9.blue.bold("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
|
|
1177
|
+
console.log(chalk9.blue.bold("\u2551 Claude Council - AI Collaboration \u2551"));
|
|
1178
|
+
console.log(chalk9.blue.bold('\u2551 "Preventing wasted engineering time" \u2551'));
|
|
1179
|
+
console.log(chalk9.blue.bold("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
|
|
1180
|
+
console.log("");
|
|
1181
|
+
}
|
|
1182
|
+
function handleCouncilMessage(message, context) {
|
|
1183
|
+
const { currentSpinner, roundResponses, onSpinnerUpdate, onExit } = context;
|
|
1184
|
+
switch (message.type) {
|
|
1185
|
+
case "session-created":
|
|
1186
|
+
console.log(chalk9.yellow("\u{1F3AD} Assembling Claude Council..."));
|
|
1187
|
+
console.log("");
|
|
1188
|
+
break;
|
|
1189
|
+
case "spawning-member":
|
|
1190
|
+
const spinner = ora2({
|
|
1191
|
+
text: `Spawning ${message.role} in Docker container on ${message.location || "Lambda"}...`,
|
|
1192
|
+
color: "cyan"
|
|
1193
|
+
}).start();
|
|
1194
|
+
onSpinnerUpdate(spinner);
|
|
1195
|
+
break;
|
|
1196
|
+
case "member-ready":
|
|
1197
|
+
if (currentSpinner) {
|
|
1198
|
+
currentSpinner.succeed(
|
|
1199
|
+
chalk9.green(`\u2713 ${capitalize(message.role)} ready (${message.memberId})`)
|
|
1200
|
+
);
|
|
1201
|
+
}
|
|
1202
|
+
break;
|
|
1203
|
+
case "all-members-ready":
|
|
1204
|
+
console.log("");
|
|
1205
|
+
console.log(chalk9.cyan("\u{1F4AC} Council Session Started"));
|
|
1206
|
+
console.log(chalk9.gray(` Session ID: ${message.sessionId}`));
|
|
1207
|
+
console.log(chalk9.gray(` Members: ${message.memberCount}`));
|
|
1208
|
+
console.log("");
|
|
1209
|
+
break;
|
|
1210
|
+
case "round-start":
|
|
1211
|
+
printRoundHeader(message.round ?? 0);
|
|
1212
|
+
roundResponses.length = 0;
|
|
1213
|
+
break;
|
|
1214
|
+
case "member-thinking": {
|
|
1215
|
+
const role = message.role ?? "architect";
|
|
1216
|
+
const thinkSpinner = ora2({
|
|
1217
|
+
text: `${ROLE_ICONS[role]} ${capitalize(role)} is analyzing...`,
|
|
1218
|
+
color: "yellow"
|
|
1219
|
+
}).start();
|
|
1220
|
+
onSpinnerUpdate(thinkSpinner);
|
|
1221
|
+
break;
|
|
1222
|
+
}
|
|
1223
|
+
case "member-response": {
|
|
1224
|
+
if (currentSpinner) currentSpinner.stop();
|
|
1225
|
+
const role = message.role ?? "architect";
|
|
1226
|
+
const roleColor = ROLE_COLORS[role] || chalk9.white;
|
|
1227
|
+
const icon = ROLE_ICONS[role] || "\u{1F916}";
|
|
1228
|
+
console.log("");
|
|
1229
|
+
console.log(roleColor.bold(`${icon} ${capitalize(role)}:`));
|
|
1230
|
+
const formatted = formatResponse(typeof message.content === "string" ? message.content : "");
|
|
1231
|
+
console.log(chalk9.gray(` ${formatted}`));
|
|
1232
|
+
console.log("");
|
|
1233
|
+
roundResponses.push(message);
|
|
1234
|
+
break;
|
|
1235
|
+
}
|
|
1236
|
+
case "round-complete":
|
|
1237
|
+
const agreementCount = typeof message.agreements === "number" ? message.agreements : 0;
|
|
1238
|
+
const totalMembers = typeof message.totalMembers === "number" ? message.totalMembers : roundResponses.length;
|
|
1239
|
+
const agreementPercent = Math.round(agreementCount / totalMembers * 100);
|
|
1240
|
+
console.log(chalk9.gray(` Agreement: ${agreementCount}/${totalMembers} (${agreementPercent}%)`));
|
|
1241
|
+
console.log("");
|
|
1242
|
+
break;
|
|
1243
|
+
case "consensus-reached":
|
|
1244
|
+
console.log(chalk9.green.bold("\n\u2705 CONSENSUS REACHED!"));
|
|
1245
|
+
console.log(chalk9.gray(` Rounds: ${message.rounds}`));
|
|
1246
|
+
console.log(chalk9.gray(` Time: ${message.time}s`));
|
|
1247
|
+
console.log("");
|
|
1248
|
+
break;
|
|
1249
|
+
case "spawning-additional-member":
|
|
1250
|
+
console.log(chalk9.yellow(`
|
|
1251
|
+
\u26A0\uFE0F Discussion needs more input. Spawning ${message.role}...`));
|
|
1252
|
+
break;
|
|
1253
|
+
case "generating-solution":
|
|
1254
|
+
const genSpinner = ora2({
|
|
1255
|
+
text: "Synthesizing final solution from council discussion...",
|
|
1256
|
+
color: "green"
|
|
1257
|
+
}).start();
|
|
1258
|
+
onSpinnerUpdate(genSpinner);
|
|
1259
|
+
break;
|
|
1260
|
+
case "solution-ready":
|
|
1261
|
+
if (currentSpinner) currentSpinner.succeed("Solution generated");
|
|
1262
|
+
console.log("");
|
|
1263
|
+
console.log(chalk9.blue.bold("\u2500".repeat(65)));
|
|
1264
|
+
console.log(chalk9.blue.bold("\u{1F4CB} Solution"));
|
|
1265
|
+
console.log(chalk9.blue.bold("\u2500".repeat(65)));
|
|
1266
|
+
console.log("");
|
|
1267
|
+
console.log(message.solution);
|
|
1268
|
+
console.log("");
|
|
1269
|
+
if (message.files && message.files.length > 0) {
|
|
1270
|
+
console.log(chalk9.cyan("\u{1F4C1} Files created:"));
|
|
1271
|
+
message.files.forEach((file) => {
|
|
1272
|
+
console.log(chalk9.gray(` \u251C\u2500 ${file}`));
|
|
1273
|
+
});
|
|
1274
|
+
console.log("");
|
|
1275
|
+
}
|
|
1276
|
+
break;
|
|
1277
|
+
case "stats":
|
|
1278
|
+
printStats(message.stats);
|
|
1279
|
+
break;
|
|
1280
|
+
case "cleanup-start":
|
|
1281
|
+
console.log(chalk9.yellow("\u{1F9F9} Cleaning up council members..."));
|
|
1282
|
+
break;
|
|
1283
|
+
case "member-destroyed":
|
|
1284
|
+
console.log(chalk9.gray(` \u251C\u2500 Destroying ${message.role}... \u2713`));
|
|
1285
|
+
break;
|
|
1286
|
+
case "session-complete":
|
|
1287
|
+
console.log("");
|
|
1288
|
+
console.log(chalk9.green.bold("\u2728 Council session complete!"));
|
|
1289
|
+
console.log("");
|
|
1290
|
+
onExit();
|
|
1291
|
+
break;
|
|
1292
|
+
case "timeout":
|
|
1293
|
+
console.log(chalk9.yellow("\n\u23F1\uFE0F Discussion timeout reached"));
|
|
1294
|
+
console.log(chalk9.gray(" The council needs your input to continue."));
|
|
1295
|
+
break;
|
|
1296
|
+
case "error":
|
|
1297
|
+
if (currentSpinner) currentSpinner.fail();
|
|
1298
|
+
console.log(chalk9.red(`
|
|
1299
|
+
\u274C Error: ${message.error}`));
|
|
1300
|
+
onExit();
|
|
1301
|
+
break;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
function printRoundHeader(round) {
|
|
1305
|
+
console.log(chalk9.cyan("\u2500".repeat(65)));
|
|
1306
|
+
console.log(chalk9.cyan(`Round ${round} - Council Discussion`));
|
|
1307
|
+
console.log(chalk9.cyan("\u2500".repeat(65)));
|
|
1308
|
+
}
|
|
1309
|
+
function formatResponse(content) {
|
|
1310
|
+
const maxLength = 300;
|
|
1311
|
+
if (content.length > maxLength) {
|
|
1312
|
+
return content.substring(0, maxLength) + "...";
|
|
1313
|
+
}
|
|
1314
|
+
return content;
|
|
1315
|
+
}
|
|
1316
|
+
function printStats(stats) {
|
|
1317
|
+
console.log(chalk9.blue.bold("\u2500".repeat(65)));
|
|
1318
|
+
console.log(chalk9.blue.bold("\u{1F4CA} Session Statistics"));
|
|
1319
|
+
console.log(chalk9.blue.bold("\u2500".repeat(65)));
|
|
1320
|
+
console.log("");
|
|
1321
|
+
console.log(chalk9.gray(` Council members: ${stats.members || 0}`));
|
|
1322
|
+
console.log(chalk9.gray(` Discussion rounds: ${stats.rounds || 0}`));
|
|
1323
|
+
console.log(chalk9.gray(` Total time: ${stats.time || 0}s`));
|
|
1324
|
+
console.log(chalk9.gray(` API cost: $${(stats.cost || 0).toFixed(2)}`));
|
|
1325
|
+
console.log(chalk9.gray(` Lines of code: ${stats.linesOfCode || 0}`));
|
|
1326
|
+
console.log("");
|
|
1327
|
+
}
|
|
1328
|
+
function capitalize(str) {
|
|
1329
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
// src/cli/commands/usage.ts
|
|
1333
|
+
import chalk10 from "chalk";
|
|
1334
|
+
import prompts5 from "prompts";
|
|
1335
|
+
async function usageCommand(options = {}) {
|
|
1336
|
+
const token = getToken();
|
|
1337
|
+
if (!token) {
|
|
1338
|
+
console.error(chalk10.red("\u274C Not authenticated"));
|
|
1339
|
+
console.log(chalk10.dim(" Run"), chalk10.cyan("codmir login"), chalk10.dim("first"));
|
|
1340
|
+
process.exit(1);
|
|
1341
|
+
}
|
|
1342
|
+
console.log(chalk10.bold("\n\u{1F4CA} API Usage & Billing\n"));
|
|
1343
|
+
const baseUrl = getBaseUrl();
|
|
1344
|
+
const month = options.month || (/* @__PURE__ */ new Date()).toISOString().slice(0, 7);
|
|
1345
|
+
try {
|
|
1346
|
+
const response = await fetch(`${baseUrl}/api/keys`, {
|
|
1347
|
+
headers: { "X-API-Key": token }
|
|
1348
|
+
});
|
|
1349
|
+
if (!response.ok) {
|
|
1350
|
+
throw new Error(`Failed to fetch API keys: ${response.status}`);
|
|
1351
|
+
}
|
|
1352
|
+
const { keys } = await response.json();
|
|
1353
|
+
if (keys.length === 0) {
|
|
1354
|
+
console.log(chalk10.yellow("\u26A0\uFE0F No API keys found"));
|
|
1355
|
+
console.log(chalk10.dim(" Create one at:"), chalk10.cyan("https://codmir.com/settings/api-keys"));
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
console.log(chalk10.bold(`\u{1F4C5} Month: ${month}
|
|
1359
|
+
`));
|
|
1360
|
+
let totalRequests = 0;
|
|
1361
|
+
let totalAICalls = 0;
|
|
1362
|
+
let totalTokens = 0;
|
|
1363
|
+
let totalCostCents = 0;
|
|
1364
|
+
for (const key of keys) {
|
|
1365
|
+
const usage = key.monthlyUsage[0];
|
|
1366
|
+
const costDollars = usage ? (usage.totalCostCents / 100).toFixed(2) : "0.00";
|
|
1367
|
+
const tokenCount = Number(usage?.totalTokens || 0);
|
|
1368
|
+
totalRequests += usage?.totalRequests || 0;
|
|
1369
|
+
totalAICalls += usage?.totalAICalls || 0;
|
|
1370
|
+
totalTokens += tokenCount;
|
|
1371
|
+
totalCostCents += usage?.totalCostCents || 0;
|
|
1372
|
+
console.log(chalk10.cyan.bold(`\u{1F511} ${key.name}`));
|
|
1373
|
+
console.log(chalk10.dim(` Key: ${key.keyPrefix}...`));
|
|
1374
|
+
console.log(chalk10.dim(` Scope: ${key.scope}`));
|
|
1375
|
+
console.log();
|
|
1376
|
+
console.log(chalk10.bold(" Usage:"));
|
|
1377
|
+
console.log(chalk10.dim(` Total Requests: ${(usage?.totalRequests || 0).toLocaleString()}`));
|
|
1378
|
+
console.log(chalk10.dim(` AI Calls: ${(usage?.totalAICalls || 0).toLocaleString()}`));
|
|
1379
|
+
console.log(chalk10.dim(` Tokens Used: ${tokenCount.toLocaleString()}`));
|
|
1380
|
+
const costColor = getCostColor(usage?.totalCostCents || 0);
|
|
1381
|
+
console.log(chalk10.bold(" Cost:"));
|
|
1382
|
+
console.log(costColor(` This Month: $${costDollars}`));
|
|
1383
|
+
if (key.lastUsedAt) {
|
|
1384
|
+
const lastUsed = new Date(key.lastUsedAt);
|
|
1385
|
+
const daysAgo = Math.floor((Date.now() - lastUsed.getTime()) / (1e3 * 60 * 60 * 24));
|
|
1386
|
+
console.log(chalk10.dim(` Last Used: ${lastUsed.toLocaleDateString()} (${daysAgo} days ago)`));
|
|
1387
|
+
} else {
|
|
1388
|
+
console.log(chalk10.dim(" Last Used: Never"));
|
|
1389
|
+
}
|
|
1390
|
+
if (options.detailed && usage) {
|
|
1391
|
+
console.log();
|
|
1392
|
+
console.log(chalk10.bold(" Provider Breakdown:"));
|
|
1393
|
+
if (usage.openaiTokens > 0) {
|
|
1394
|
+
console.log(chalk10.dim(` OpenAI: ${Number(usage.openaiTokens).toLocaleString()} tokens ($${(usage.openaiCostCents / 100).toFixed(2)})`));
|
|
1395
|
+
}
|
|
1396
|
+
if (usage.anthropicTokens > 0) {
|
|
1397
|
+
console.log(chalk10.dim(` Anthropic: ${Number(usage.anthropicTokens).toLocaleString()} tokens ($${(usage.anthropicCostCents / 100).toFixed(2)})`));
|
|
1398
|
+
}
|
|
1399
|
+
if (usage.localTokens > 0) {
|
|
1400
|
+
console.log(chalk10.dim(` Local: ${Number(usage.localTokens).toLocaleString()} tokens (free)`));
|
|
1401
|
+
}
|
|
1402
|
+
if (usage.totalAnalyses > 0) {
|
|
1403
|
+
console.log();
|
|
1404
|
+
console.log(chalk10.bold(" Codebase Analysis:"));
|
|
1405
|
+
console.log(chalk10.dim(` Total Analyses: ${usage.totalAnalyses}`));
|
|
1406
|
+
console.log(chalk10.dim(` Local: ${usage.localAnalyses}`));
|
|
1407
|
+
console.log(chalk10.dim(` Deep (Railway): ${usage.deepAnalyses} ($${(usage.railwayCostCents / 100).toFixed(2)})`));
|
|
1408
|
+
console.log(chalk10.dim(` Files Processed: ${Number(usage.filesProcessed).toLocaleString()}`));
|
|
1409
|
+
console.log(chalk10.dim(` Lines Processed: ${Number(usage.linesProcessed).toLocaleString()}`));
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
console.log();
|
|
1413
|
+
console.log(chalk10.dim(" \u2500".repeat(50)));
|
|
1414
|
+
console.log();
|
|
1415
|
+
}
|
|
1416
|
+
console.log(chalk10.bold.cyan("\u{1F4C8} Summary\n"));
|
|
1417
|
+
console.log(chalk10.dim(` Total Requests: ${totalRequests.toLocaleString()}`));
|
|
1418
|
+
console.log(chalk10.dim(` AI Calls: ${totalAICalls.toLocaleString()}`));
|
|
1419
|
+
console.log(chalk10.dim(` Tokens Used: ${totalTokens.toLocaleString()}`));
|
|
1420
|
+
console.log();
|
|
1421
|
+
console.log(chalk10.bold.green(` Total Cost: $${(totalCostCents / 100).toFixed(2)}`));
|
|
1422
|
+
console.log();
|
|
1423
|
+
if (totalCostCents > 5e3) {
|
|
1424
|
+
console.log(chalk10.yellow(" \u26A0\uFE0F High usage detected this month"));
|
|
1425
|
+
console.log(chalk10.dim(" Consider optimizing AI calls or using local mode"));
|
|
1426
|
+
console.log();
|
|
1427
|
+
}
|
|
1428
|
+
if (!options.detailed && keys.length > 0) {
|
|
1429
|
+
console.log(chalk10.dim(" \u{1F4A1} Tip: Use"), chalk10.cyan("--detailed"), chalk10.dim("for provider breakdown"));
|
|
1430
|
+
}
|
|
1431
|
+
console.log(chalk10.dim(" \u{1F4C5} View other months:"), chalk10.cyan("codmir usage --month 2025-01"));
|
|
1432
|
+
console.log();
|
|
1433
|
+
} catch (error) {
|
|
1434
|
+
console.error(chalk10.red("\n\u274C Failed to get usage stats"));
|
|
1435
|
+
console.error(chalk10.dim(" Error:"), error instanceof Error ? error.message : "Unknown error");
|
|
1436
|
+
process.exit(1);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
function getCostColor(costCents) {
|
|
1440
|
+
if (costCents === 0) return chalk10.dim;
|
|
1441
|
+
if (costCents < 100) return chalk10.green;
|
|
1442
|
+
if (costCents < 1e3) return chalk10.yellow;
|
|
1443
|
+
return chalk10.red;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
433
1446
|
// src/cli/index.ts
|
|
434
1447
|
var program = new Command();
|
|
435
1448
|
program.name("codmir").description("codmir CLI - the AI that prevents wasted engineering time").version("0.1.0");
|
|
@@ -438,7 +1451,21 @@ program.command("link").description("Link current directory to a codmir project"
|
|
|
438
1451
|
program.command("whoami").description("Show current authenticated user").action(whoamiCommand);
|
|
439
1452
|
program.command("logout").description("Log out of codmir").action(logoutCommand);
|
|
440
1453
|
program.command("init").description("Initialize codmir in your project").action(initCommand);
|
|
441
|
-
program.command("projects").alias("ls").description("List your projects").action(projectsCommand);
|
|
1454
|
+
program.command("projects").alias("ls").description("List all your projects").action(projectsCommand);
|
|
1455
|
+
program.command("ticket").alias("create").description("\u{1F3AB} Create a new ticket with interactive navigation").action(createTicketCommand);
|
|
1456
|
+
program.command("codmir [query...]").alias("ai").description("\u{1F916} AI assistant for developers").option("-p, --project <id>", "Include project context").option("-c, --context", "Include current directory context").option("-m, --model <name>", "AI model to use (default: gpt-4-turbo-preview)").action((query, options) => {
|
|
1457
|
+
const queryString = query ? query.join(" ") : void 0;
|
|
1458
|
+
assistantCommand(queryString, options);
|
|
1459
|
+
});
|
|
1460
|
+
program.command("ask <query...>").description("Quick AI query without interactive mode").option("-p, --project <id>", "Include project context").action((query, options) => {
|
|
1461
|
+
quickQueryCommand(query.join(" "), options);
|
|
1462
|
+
});
|
|
1463
|
+
program.command("analyze").description("\u{1F50D} Analyze codebase and generate knowledge base").option("--full", "Run full deep analysis").option("--force", "Force re-analysis even if knowledge base exists").option("--mode <mode>", "Analysis mode: local or railway").action(analyzeCommand);
|
|
1464
|
+
program.command("usage").description("\u{1F4CA} View API usage and billing stats").option("--month <YYYY-MM>", "Month to view (default: current month)").option("--detailed", "Show detailed provider breakdown").action(usageCommand);
|
|
1465
|
+
program.command("council [task...]").description("\u{1F3AD} Assemble a council of Claude AI agents to collaborate on complex tasks").option("-m, --members <count>", "Number of initial council members (2-4)", "2").option("-t, --timeout <seconds>", "Max discussion time in seconds", "300").option("--local", "Run on local LAN cluster instead of Lambda").action((task, options) => {
|
|
1466
|
+
const taskString = task ? task.join(" ") : void 0;
|
|
1467
|
+
councilCommand(taskString, options);
|
|
1468
|
+
});
|
|
442
1469
|
program.parse(process.argv);
|
|
443
1470
|
if (!process.argv.slice(2).length) {
|
|
444
1471
|
program.outputHelp();
|