codeam-cli 1.4.9 → 1.4.10
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 +10 -75
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -115,7 +115,7 @@ var import_qrcode_terminal = __toESM(require("qrcode-terminal"));
|
|
|
115
115
|
// package.json
|
|
116
116
|
var package_default = {
|
|
117
117
|
name: "codeam-cli",
|
|
118
|
-
version: "1.4.
|
|
118
|
+
version: "1.4.10",
|
|
119
119
|
description: "Remote control Claude Code from your mobile device",
|
|
120
120
|
main: "dist/index.js",
|
|
121
121
|
bin: {
|
|
@@ -1387,29 +1387,9 @@ var HistoryService = class {
|
|
|
1387
1387
|
}
|
|
1388
1388
|
pluginId;
|
|
1389
1389
|
cwd;
|
|
1390
|
-
currentConversationId = null;
|
|
1391
1390
|
get projectDir() {
|
|
1392
1391
|
return path4.join(os4.homedir(), ".claude", "projects", encodeCwd(this.cwd));
|
|
1393
1392
|
}
|
|
1394
|
-
/** Set the current Claude conversation ID (extracted from /cost command or session start) */
|
|
1395
|
-
setCurrentConversationId(id) {
|
|
1396
|
-
this.currentConversationId = id;
|
|
1397
|
-
}
|
|
1398
|
-
/** Extract conversation ID from Claude output (e.g., from session resume messages) */
|
|
1399
|
-
tryExtractConversationIdFromOutput(output) {
|
|
1400
|
-
const patterns = [
|
|
1401
|
-
/Resuming session[:\s]+([a-f0-9-]{36})/i,
|
|
1402
|
-
/session[:\s]+([a-f0-9-]{36})/i,
|
|
1403
|
-
/conversation[:\s]+([a-f0-9-]{36})/i
|
|
1404
|
-
];
|
|
1405
|
-
for (const pattern of patterns) {
|
|
1406
|
-
const match = output.match(pattern);
|
|
1407
|
-
if (match) {
|
|
1408
|
-
this.currentConversationId = match[1];
|
|
1409
|
-
return;
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
1393
|
/**
|
|
1414
1394
|
* Read the most recently modified JSONL session file and extract the
|
|
1415
1395
|
* context window usage from the last assistant message's usage field.
|
|
@@ -1420,13 +1400,10 @@ var HistoryService = class {
|
|
|
1420
1400
|
*/
|
|
1421
1401
|
getCurrentUsage() {
|
|
1422
1402
|
const dir = this.projectDir;
|
|
1423
|
-
console.log(`[HistoryService] Looking for sessions in: ${dir}`);
|
|
1424
|
-
console.log(`[HistoryService] Current conversation ID: ${this.currentConversationId ?? "not set"}`);
|
|
1425
1403
|
let entries;
|
|
1426
1404
|
try {
|
|
1427
1405
|
entries = fs4.readdirSync(dir, { withFileTypes: true });
|
|
1428
|
-
} catch
|
|
1429
|
-
console.log(`[HistoryService] Failed to read directory: ${err}`);
|
|
1406
|
+
} catch {
|
|
1430
1407
|
return null;
|
|
1431
1408
|
}
|
|
1432
1409
|
const files = entries.filter((e) => e.isFile() && e.name.endsWith(".jsonl")).map((e) => {
|
|
@@ -1436,66 +1413,29 @@ var HistoryService = class {
|
|
|
1436
1413
|
return { name: e.name, mtime: 0 };
|
|
1437
1414
|
}
|
|
1438
1415
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
1439
|
-
if (files.length === 0)
|
|
1440
|
-
console.log(`[HistoryService] No .jsonl files found in directory`);
|
|
1441
|
-
return null;
|
|
1442
|
-
}
|
|
1443
|
-
let targetFile = files[0].name;
|
|
1444
|
-
if (this.currentConversationId) {
|
|
1445
|
-
const conversationFile = `${this.currentConversationId}.jsonl`;
|
|
1446
|
-
const exists = files.some((f) => f.name === conversationFile);
|
|
1447
|
-
if (exists) {
|
|
1448
|
-
targetFile = conversationFile;
|
|
1449
|
-
console.log(`[HistoryService] Using tracked conversation file: ${targetFile}`);
|
|
1450
|
-
} else {
|
|
1451
|
-
console.log(`[HistoryService] Tracked conversation file not found, using most recent: ${targetFile}`);
|
|
1452
|
-
}
|
|
1453
|
-
} else {
|
|
1454
|
-
console.log(`[HistoryService] No tracked conversation, using most recent: ${targetFile}`);
|
|
1455
|
-
}
|
|
1416
|
+
if (files.length === 0) return null;
|
|
1456
1417
|
let raw;
|
|
1457
1418
|
try {
|
|
1458
|
-
raw = fs4.readFileSync(path4.join(dir,
|
|
1459
|
-
} catch
|
|
1460
|
-
console.log(`[HistoryService] Failed to read file: ${err}`);
|
|
1419
|
+
raw = fs4.readFileSync(path4.join(dir, files[0].name), "utf8");
|
|
1420
|
+
} catch {
|
|
1461
1421
|
return null;
|
|
1462
1422
|
}
|
|
1463
1423
|
let lastUsage = null;
|
|
1464
1424
|
let lastModel = null;
|
|
1465
|
-
|
|
1466
|
-
let hasAnyMessages = false;
|
|
1467
|
-
const lines = raw.split("\n").filter(Boolean);
|
|
1468
|
-
console.log(`[HistoryService] File has ${lines.length} lines`);
|
|
1469
|
-
for (const line of lines) {
|
|
1425
|
+
for (const line of raw.split("\n").filter(Boolean)) {
|
|
1470
1426
|
try {
|
|
1471
1427
|
const record = JSON.parse(line);
|
|
1472
|
-
if (record["type"] === "user" || record["type"] === "assistant") {
|
|
1473
|
-
hasAnyMessages = true;
|
|
1474
|
-
}
|
|
1475
1428
|
if (record["type"] === "assistant") {
|
|
1476
|
-
assistantMessageCount++;
|
|
1477
1429
|
const msg = record["message"];
|
|
1478
|
-
|
|
1479
|
-
if (usage && (usage["input_tokens"] !== void 0 || usage["prompt_tokens"] !== void 0)) {
|
|
1480
|
-
lastUsage = usage;
|
|
1481
|
-
console.log(`[HistoryService] Found usage data: ${JSON.stringify(lastUsage)}`);
|
|
1482
|
-
}
|
|
1430
|
+
if (msg?.["usage"]) lastUsage = msg["usage"];
|
|
1483
1431
|
if (msg?.["model"]) lastModel = msg["model"];
|
|
1484
1432
|
}
|
|
1485
1433
|
} catch {
|
|
1486
1434
|
}
|
|
1487
1435
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
console.log(`[HistoryService] File has messages but no usage data (Claude Code may not have recorded usage yet)`);
|
|
1492
|
-
return { used: 0, total: 2e5, percent: 0, model: lastModel, outputTokens: 0, cacheReadTokens: 0 };
|
|
1493
|
-
}
|
|
1494
|
-
console.log(`[HistoryService] No messages or usage data found in session file`);
|
|
1495
|
-
return null;
|
|
1496
|
-
}
|
|
1497
|
-
const inputTokens = (lastUsage["input_tokens"] ?? lastUsage["prompt_tokens"] ?? 0) + (lastUsage["cache_read_input_tokens"] ?? 0) + (lastUsage["cache_creation_input_tokens"] ?? 0);
|
|
1498
|
-
const outputTokens = lastUsage["output_tokens"] ?? lastUsage["completion_tokens"] ?? 0;
|
|
1436
|
+
if (!lastUsage) return null;
|
|
1437
|
+
const inputTokens = (lastUsage["input_tokens"] ?? 0) + (lastUsage["cache_read_input_tokens"] ?? 0) + (lastUsage["cache_creation_input_tokens"] ?? 0);
|
|
1438
|
+
const outputTokens = lastUsage["output_tokens"] ?? 0;
|
|
1499
1439
|
const total = 2e5;
|
|
1500
1440
|
const percent = Math.min(100, Math.round(inputTokens / total * 100));
|
|
1501
1441
|
return { used: inputTokens, total, percent, model: lastModel, outputTokens, cacheReadTokens: lastUsage["cache_read_input_tokens"] ?? 0 };
|
|
@@ -1585,12 +1525,9 @@ async function start() {
|
|
|
1585
1525
|
showInfo(`${session.userName} \xB7 ${import_picocolors2.default.cyan(session.plan)}`);
|
|
1586
1526
|
showInfo("Launching Claude Code...\n");
|
|
1587
1527
|
const cwd = process.cwd();
|
|
1588
|
-
console.log(`[CLI] Starting with cwd: ${cwd}`);
|
|
1589
|
-
console.log(`[CLI] Session: ${session.id}, Plugin: ${pluginId}`);
|
|
1590
1528
|
const ws = new WebSocketService(session.id, pluginId);
|
|
1591
1529
|
const historySvc = new HistoryService(pluginId, cwd);
|
|
1592
1530
|
const outputSvc = new OutputService(session.id, pluginId, (conversationId) => {
|
|
1593
|
-
console.log(`[CLI] Detected Claude conversation ID: ${conversationId}`);
|
|
1594
1531
|
historySvc.setCurrentConversationId(conversationId);
|
|
1595
1532
|
});
|
|
1596
1533
|
function sendPrompt(prompt) {
|
|
@@ -1641,10 +1578,8 @@ async function start() {
|
|
|
1641
1578
|
claude.interrupt();
|
|
1642
1579
|
break;
|
|
1643
1580
|
case "get_context": {
|
|
1644
|
-
console.log(`[CLI] Received get_context command, fetching usage...`);
|
|
1645
1581
|
const usage = historySvc.getCurrentUsage();
|
|
1646
1582
|
const result = usage ?? { used: 0, total: 2e5, percent: 0, model: null, outputTokens: 0, cacheReadTokens: 0, error: "No usage data found" };
|
|
1647
|
-
console.log(`[CLI] Sending context result: ${JSON.stringify(result)}`);
|
|
1648
1583
|
await relay.sendResult(cmd.id, "completed", result);
|
|
1649
1584
|
break;
|
|
1650
1585
|
}
|