cc-claw 0.12.5 → 0.12.6

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/cli.js +32 -21
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -72,7 +72,7 @@ var VERSION;
72
72
  var init_version = __esm({
73
73
  "src/version.ts"() {
74
74
  "use strict";
75
- VERSION = true ? "0.12.5" : (() => {
75
+ VERSION = true ? "0.12.6" : (() => {
76
76
  try {
77
77
  return JSON.parse(readFileSync(join2(process.cwd(), "package.json"), "utf-8")).version ?? "unknown";
78
78
  } catch {
@@ -1610,6 +1610,8 @@ function initDatabase() {
1610
1610
  cache_read_tokens INTEGER NOT NULL DEFAULT 0,
1611
1611
  request_count INTEGER NOT NULL DEFAULT 0,
1612
1612
  last_input_tokens INTEGER NOT NULL DEFAULT 0,
1613
+ last_cache_read_tokens INTEGER NOT NULL DEFAULT 0,
1614
+ context_size INTEGER NOT NULL DEFAULT 0,
1613
1615
  updated_at TEXT NOT NULL DEFAULT (datetime('now'))
1614
1616
  );
1615
1617
  `);
@@ -1621,6 +1623,10 @@ function initDatabase() {
1621
1623
  db.exec("ALTER TABLE chat_usage ADD COLUMN last_cache_read_tokens INTEGER NOT NULL DEFAULT 0");
1622
1624
  } catch {
1623
1625
  }
1626
+ try {
1627
+ db.exec("ALTER TABLE chat_usage ADD COLUMN context_size INTEGER NOT NULL DEFAULT 0");
1628
+ } catch {
1629
+ }
1624
1630
  db.exec(`
1625
1631
  CREATE TABLE IF NOT EXISTS usage_log (
1626
1632
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -2361,14 +2367,15 @@ function determineEscalationTarget(chatId, currentMode) {
2361
2367
  }
2362
2368
  function getUsage(chatId) {
2363
2369
  const row = db.prepare(
2364
- "SELECT input_tokens, output_tokens, cache_read_tokens, request_count, last_input_tokens, last_cache_read_tokens FROM chat_usage WHERE chat_id = ?"
2370
+ "SELECT input_tokens, output_tokens, cache_read_tokens, request_count, last_input_tokens, last_cache_read_tokens, context_size FROM chat_usage WHERE chat_id = ?"
2365
2371
  ).get(chatId);
2366
- return row ?? { input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, request_count: 0, last_input_tokens: 0, last_cache_read_tokens: 0 };
2372
+ return row ?? { input_tokens: 0, output_tokens: 0, cache_read_tokens: 0, request_count: 0, last_input_tokens: 0, last_cache_read_tokens: 0, context_size: 0 };
2367
2373
  }
2368
- function addUsage(chatId, input, output2, cacheRead, model2, backend2) {
2374
+ function addUsage(chatId, input, output2, cacheRead, model2, backend2, contextSize) {
2375
+ const finalContextSize = contextSize ?? input + cacheRead;
2369
2376
  db.prepare(`
2370
- INSERT INTO chat_usage (chat_id, input_tokens, output_tokens, cache_read_tokens, request_count, last_input_tokens, last_cache_read_tokens, updated_at)
2371
- VALUES (?, ?, ?, ?, 1, ?, ?, datetime('now'))
2377
+ INSERT INTO chat_usage (chat_id, input_tokens, output_tokens, cache_read_tokens, request_count, last_input_tokens, last_cache_read_tokens, context_size, updated_at)
2378
+ VALUES (?, ?, ?, ?, 1, ?, ?, ?, datetime('now'))
2372
2379
  ON CONFLICT(chat_id) DO UPDATE SET
2373
2380
  input_tokens = input_tokens + ?,
2374
2381
  output_tokens = output_tokens + ?,
@@ -2376,8 +2383,9 @@ function addUsage(chatId, input, output2, cacheRead, model2, backend2) {
2376
2383
  request_count = request_count + 1,
2377
2384
  last_input_tokens = ?,
2378
2385
  last_cache_read_tokens = ?,
2386
+ context_size = ?,
2379
2387
  updated_at = datetime('now')
2380
- `).run(chatId, input, output2, cacheRead, input, cacheRead, input, output2, cacheRead, input, cacheRead);
2388
+ `).run(chatId, input, output2, cacheRead, input, cacheRead, finalContextSize, input, output2, cacheRead, input, cacheRead, finalContextSize);
2381
2389
  if (model2) {
2382
2390
  db.prepare(
2383
2391
  "INSERT INTO usage_log (chat_id, model, input_tokens, output_tokens, cache_read_tokens, backend) VALUES (?, ?, ?, ?, ?, ?)"
@@ -8237,7 +8245,7 @@ data: ${JSON.stringify(data)}
8237
8245
  model: model2,
8238
8246
  permMode: mode
8239
8247
  });
8240
- if (response.usage) addUsage2(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? "unknown");
8248
+ if (response.usage) addUsage2(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? "unknown", void 0, response.usage.contextSize);
8241
8249
  sendSSE("done", JSON.stringify({ text: response.text, usage: response.usage }));
8242
8250
  res.end();
8243
8251
  } catch (err) {
@@ -8246,7 +8254,7 @@ data: ${JSON.stringify(data)}
8246
8254
  }
8247
8255
  } else {
8248
8256
  const response = await askAgent2(chatId, body.message, { cwd, model: model2, permMode: mode });
8249
- if (response.usage) addUsage2(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? "unknown");
8257
+ if (response.usage) addUsage2(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? "unknown", void 0, response.usage.contextSize);
8250
8258
  return jsonResponse(res, { text: response.text, usage: response.usage, sessionId: response.sessionId });
8251
8259
  }
8252
8260
  } catch (err) {
@@ -9154,6 +9162,7 @@ function spawnQuery(adapter, config2, model2, cancelState, thinkingLevel, timeou
9154
9162
  let input = 0;
9155
9163
  let output2 = 0;
9156
9164
  let cacheRead = 0;
9165
+ let contextSize;
9157
9166
  let sawToolEvents = false;
9158
9167
  let sawResultEvent = false;
9159
9168
  let toolTurnCount = 0;
@@ -9230,6 +9239,7 @@ function spawnQuery(adapter, config2, model2, cancelState, thinkingLevel, timeou
9230
9239
  input += ev.usage.input;
9231
9240
  output2 += ev.usage.output;
9232
9241
  cacheRead += ev.usage.cacheRead;
9242
+ contextSize = ev.usage.input + (ev.usage.cacheRead ?? 0);
9233
9243
  }
9234
9244
  break;
9235
9245
  case "result":
@@ -9240,6 +9250,7 @@ function spawnQuery(adapter, config2, model2, cancelState, thinkingLevel, timeou
9240
9250
  input = ev.usage.input;
9241
9251
  output2 = ev.usage.output;
9242
9252
  cacheRead = ev.usage.cacheRead;
9253
+ contextSize = ev.usage.input + (ev.usage.cacheRead ?? 0);
9243
9254
  }
9244
9255
  if (adapter.shouldKillOnResult()) {
9245
9256
  try {
@@ -9296,7 +9307,7 @@ Partial output: ${accumulatedText.slice(-500)}`;
9296
9307
  reject(new Error(`CLI exited with code ${code}${stderr ? `: ${stderr.slice(0, 500)}` : ""}`));
9297
9308
  return;
9298
9309
  }
9299
- resolve({ resultText, sessionId, input, output: output2, cacheRead, sawToolEvents, sawResultEvent });
9310
+ resolve({ resultText, sessionId, input, output: output2, cacheRead, contextSize, sawToolEvents, sawResultEvent });
9300
9311
  });
9301
9312
  });
9302
9313
  }
@@ -9458,7 +9469,7 @@ async function askAgentImpl(chatId, userMessage, opts) {
9458
9469
  activeChats.delete(chatId);
9459
9470
  }
9460
9471
  if (cancelState.cancelled) {
9461
- return { text: "Stopped.", usage: { input: result.input, output: result.output, cacheRead: result.cacheRead } };
9472
+ return { text: "Stopped.", usage: { input: result.input, output: result.output, cacheRead: result.cacheRead, contextSize: result.contextSize } };
9462
9473
  }
9463
9474
  if (result.sessionId && !isSyntheticChatId(chatId)) {
9464
9475
  setSessionId(chatId, result.sessionId);
@@ -9490,7 +9501,7 @@ async function askAgentImpl(chatId, userMessage, opts) {
9490
9501
  return {
9491
9502
  text: result.resultText || `(No response from ${adapter.displayName})`,
9492
9503
  sessionId: result.sessionId,
9493
- usage: { input: result.input, output: result.output, cacheRead: result.cacheRead }
9504
+ usage: { input: result.input, output: result.output, cacheRead: result.cacheRead, contextSize: result.contextSize }
9494
9505
  };
9495
9506
  }
9496
9507
  function getMcpConfigPath(chatId) {
@@ -10536,7 +10547,7 @@ async function runHeartbeat(chatId, config2) {
10536
10547
  } catch {
10537
10548
  heartbeatModel = getModel(chatId) ?? "unknown";
10538
10549
  }
10539
- addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, heartbeatModel);
10550
+ addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, heartbeatModel, void 0, response.usage.contextSize);
10540
10551
  }
10541
10552
  const now = (/* @__PURE__ */ new Date()).toISOString();
10542
10553
  const next = new Date(Date.now() + config2.intervalMs).toISOString();
@@ -12796,7 +12807,7 @@ Tap to toggle:`,
12796
12807
  const mode = getMode(chatId);
12797
12808
  const modelSig = getModelSignature(chatId);
12798
12809
  const contextMax = adapter?.contextWindow[model2] ?? 2e5;
12799
- const contextUsed = usage2.last_input_tokens + usage2.last_cache_read_tokens;
12810
+ const contextUsed = usage2.context_size;
12800
12811
  const contextPct = contextMax > 0 ? contextUsed / contextMax * 100 : 0;
12801
12812
  const ctxBar = buildBar(contextPct);
12802
12813
  const usedK = (contextUsed / 1e3).toFixed(1);
@@ -14156,7 +14167,7 @@ async function handleVoice(msg, channel) {
14156
14167
  const vVerbose = getVerboseLevel(chatId);
14157
14168
  const vToolCb = vVerbose !== "off" ? makeToolActionCallback(chatId, channel, vVerbose) : void 0;
14158
14169
  const response = await askAgent(chatId, transcript, { cwd: getCwd(chatId), model: vModel, permMode: mode, onToolAction: vToolCb });
14159
- if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, vModel);
14170
+ if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, vModel, void 0, response.usage.contextSize);
14160
14171
  if (await handleResponseExhaustion(response.text, chatId, msg, channel)) return;
14161
14172
  const voiceResponse = ensureReaction(response.text, transcript);
14162
14173
  await sendResponse(chatId, channel, voiceResponse, msg.messageId);
@@ -14222,7 +14233,7 @@ Acknowledge receipt. Do NOT analyze the video unless they ask you to.`;
14222
14233
  const vidVerbose = getVerboseLevel(chatId);
14223
14234
  const vidToolCb = vidVerbose !== "off" ? makeToolActionCallback(chatId, channel, vidVerbose) : void 0;
14224
14235
  const response2 = await askAgent(chatId, prompt2, { cwd: getCwd(chatId), model: vidModel, permMode: vMode, onToolAction: vidToolCb });
14225
- if (response2.usage) addUsage(chatId, response2.usage.input, response2.usage.output, response2.usage.cacheRead, vidModel);
14236
+ if (response2.usage) addUsage(chatId, response2.usage.input, response2.usage.output, response2.usage.cacheRead, vidModel, void 0, response2.usage.contextSize);
14226
14237
  if (await handleResponseExhaustion(response2.text, chatId, msg, channel)) return;
14227
14238
  const vidResponse = ensureReaction(response2.text, caption || "video");
14228
14239
  await sendResponse(chatId, channel, vidResponse, msg.messageId);
@@ -14264,7 +14275,7 @@ ${content}
14264
14275
  const mVerbose = getVerboseLevel(chatId);
14265
14276
  const mToolCb = mVerbose !== "off" ? makeToolActionCallback(chatId, channel, mVerbose) : void 0;
14266
14277
  const response = await askAgent(chatId, prompt, { cwd: getCwd(chatId), model: mediaModel, permMode: mMode, onToolAction: mToolCb });
14267
- if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, mediaModel);
14278
+ if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, mediaModel, void 0, response.usage.contextSize);
14268
14279
  if (await handleResponseExhaustion(response.text, chatId, msg, channel)) return;
14269
14280
  const mediaResponse = ensureReaction(response.text, caption || "file");
14270
14281
  await sendResponse(chatId, channel, mediaResponse, msg.messageId);
@@ -14413,7 +14424,7 @@ async function handleText(msg, channel) {
14413
14424
  }
14414
14425
  });
14415
14426
  const elapsedSec = ((Date.now() - sigT0) / 1e3).toFixed(1);
14416
- if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2);
14427
+ if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2, void 0, response.usage.contextSize);
14417
14428
  let responseText = response.text;
14418
14429
  const sigEnabled = getModelSignature(chatId);
14419
14430
  if (sigEnabled === "on" && responseText && !responseText.startsWith("(No response")) {
@@ -14571,7 +14582,7 @@ async function handleSideQuest(parentChatId, msg, channel) {
14571
14582
  const adapterForLog = backend2 ? getAdapter(backend2) : getAdapterForChat(parentChatId);
14572
14583
  appendToLog(parentChatId, `[side quest] ${userText}`, `[side quest] ${response.text ?? ""}`, adapterForLog.id, model2 ?? null, null);
14573
14584
  if (response.usage) {
14574
- addUsage(parentChatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? void 0, backend2 ?? void 0);
14585
+ addUsage(parentChatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? void 0, backend2 ?? void 0, response.usage.contextSize);
14575
14586
  }
14576
14587
  try {
14577
14588
  const { detectAndLogSignals: detectAndLogSignals2 } = await Promise.resolve().then(() => (init_detect(), detect_exports));
@@ -15800,7 +15811,7 @@ Result: ${task.result.slice(0, 500)}` : ""
15800
15811
  const sVerbose = getVerboseLevel(chatId);
15801
15812
  const sToolCb = sVerbose !== "off" ? makeToolActionCallback(chatId, channel, sVerbose) : void 0;
15802
15813
  const response = await askAgent(chatId, skillContent, { cwd: getCwd(chatId), model: skillModel, permMode: sMode, onToolAction: sToolCb });
15803
- if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, skillModel);
15814
+ if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, skillModel, void 0, response.usage.contextSize);
15804
15815
  await sendResponse(chatId, channel, response.text);
15805
15816
  } else if (data.startsWith("evolve:")) {
15806
15817
  const parts = data.split(":");
@@ -17159,7 +17170,7 @@ async function executeJob(job) {
17159
17170
  updateJobLastRun(job.id, (/* @__PURE__ */ new Date()).toISOString());
17160
17171
  resetJobFailures(job.id);
17161
17172
  if (response.usage) {
17162
- addUsage(job.chatId, response.usage.input, response.usage.output, response.usage.cacheRead, resolvedModel);
17173
+ addUsage(job.chatId, response.usage.input, response.usage.output, response.usage.cacheRead, resolvedModel, void 0, response.usage.contextSize);
17163
17174
  }
17164
17175
  const delivered = await deliverJobOutput(job, response.text);
17165
17176
  const finalStatus = !delivered && contentStatus === "success" ? "delivery_failed" : contentStatus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-claw",
3
- "version": "0.12.5",
3
+ "version": "0.12.6",
4
4
  "description": "CC-Claw: Personal AI assistant on Telegram — multi-backend (Claude, Gemini, Codex, Cursor), sub-agent orchestration, MCP management",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",