codeam-cli 1.4.10 → 1.4.11

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.
Files changed (2) hide show
  1. package/dist/index.js +59 -13
  2. 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.10",
118
+ version: "1.4.11",
119
119
  description: "Remote control Claude Code from your mobile device",
120
120
  main: "dist/index.js",
121
121
  bin: {
@@ -492,12 +492,15 @@ var CommandRelayService = class {
492
492
  const commands = data?.data;
493
493
  if (!Array.isArray(commands)) return;
494
494
  for (const obj of commands) {
495
- this.onCommand({
496
- id: obj.id,
497
- sessionId: obj.sessionId,
498
- type: obj.type,
499
- payload: obj.payload ?? {}
500
- });
495
+ try {
496
+ await this.onCommand({
497
+ id: obj.id,
498
+ sessionId: obj.sessionId,
499
+ type: obj.type,
500
+ payload: obj.payload ?? {}
501
+ });
502
+ } catch {
503
+ }
501
504
  }
502
505
  } catch {
503
506
  }
@@ -1387,9 +1390,29 @@ var HistoryService = class {
1387
1390
  }
1388
1391
  pluginId;
1389
1392
  cwd;
1393
+ currentConversationId = null;
1390
1394
  get projectDir() {
1391
1395
  return path4.join(os4.homedir(), ".claude", "projects", encodeCwd(this.cwd));
1392
1396
  }
1397
+ /** Set the current Claude conversation ID (extracted from /cost command or session start) */
1398
+ setCurrentConversationId(id) {
1399
+ this.currentConversationId = id;
1400
+ }
1401
+ /** Extract conversation ID from Claude output (e.g., from session resume messages) */
1402
+ tryExtractConversationIdFromOutput(output) {
1403
+ const patterns = [
1404
+ /Resuming session[:\s]+([a-f0-9-]{36})/i,
1405
+ /session[:\s]+([a-f0-9-]{36})/i,
1406
+ /conversation[:\s]+([a-f0-9-]{36})/i
1407
+ ];
1408
+ for (const pattern of patterns) {
1409
+ const match = output.match(pattern);
1410
+ if (match) {
1411
+ this.currentConversationId = match[1];
1412
+ return;
1413
+ }
1414
+ }
1415
+ }
1393
1416
  /**
1394
1417
  * Read the most recently modified JSONL session file and extract the
1395
1418
  * context window usage from the last assistant message's usage field.
@@ -1414,28 +1437,51 @@ var HistoryService = class {
1414
1437
  }
1415
1438
  }).sort((a, b) => b.mtime - a.mtime);
1416
1439
  if (files.length === 0) return null;
1440
+ let targetFile = files[0].name;
1441
+ if (this.currentConversationId) {
1442
+ const conversationFile = `${this.currentConversationId}.jsonl`;
1443
+ const exists = files.some((f) => f.name === conversationFile);
1444
+ if (exists) {
1445
+ targetFile = conversationFile;
1446
+ }
1447
+ }
1417
1448
  let raw;
1418
1449
  try {
1419
- raw = fs4.readFileSync(path4.join(dir, files[0].name), "utf8");
1450
+ raw = fs4.readFileSync(path4.join(dir, targetFile), "utf8");
1420
1451
  } catch {
1421
1452
  return null;
1422
1453
  }
1423
1454
  let lastUsage = null;
1424
1455
  let lastModel = null;
1425
- for (const line of raw.split("\n").filter(Boolean)) {
1456
+ let assistantMessageCount = 0;
1457
+ let hasAnyMessages = false;
1458
+ const lines = raw.split("\n").filter(Boolean);
1459
+ for (const line of lines) {
1426
1460
  try {
1427
1461
  const record = JSON.parse(line);
1462
+ if (record["type"] === "user" || record["type"] === "assistant") {
1463
+ hasAnyMessages = true;
1464
+ }
1428
1465
  if (record["type"] === "assistant") {
1466
+ assistantMessageCount++;
1429
1467
  const msg = record["message"];
1430
- if (msg?.["usage"]) lastUsage = msg["usage"];
1468
+ const usage = msg?.["usage"];
1469
+ if (usage && (usage["input_tokens"] !== void 0 || usage["prompt_tokens"] !== void 0)) {
1470
+ lastUsage = usage;
1471
+ }
1431
1472
  if (msg?.["model"]) lastModel = msg["model"];
1432
1473
  }
1433
1474
  } catch {
1434
1475
  }
1435
1476
  }
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;
1477
+ if (!lastUsage) {
1478
+ if (hasAnyMessages) {
1479
+ return { used: 0, total: 2e5, percent: 0, model: lastModel, outputTokens: 0, cacheReadTokens: 0 };
1480
+ }
1481
+ return null;
1482
+ }
1483
+ const inputTokens = (lastUsage["input_tokens"] ?? lastUsage["prompt_tokens"] ?? 0) + (lastUsage["cache_read_input_tokens"] ?? 0) + (lastUsage["cache_creation_input_tokens"] ?? 0);
1484
+ const outputTokens = lastUsage["output_tokens"] ?? lastUsage["completion_tokens"] ?? 0;
1439
1485
  const total = 2e5;
1440
1486
  const percent = Math.min(100, Math.round(inputTokens / total * 100));
1441
1487
  return { used: inputTokens, total, percent, model: lastModel, outputTokens, cacheReadTokens: lastUsage["cache_read_input_tokens"] ?? 0 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeam-cli",
3
- "version": "1.4.10",
3
+ "version": "1.4.11",
4
4
  "description": "Remote control Claude Code from your mobile device",
5
5
  "main": "dist/index.js",
6
6
  "bin": {