cc-claw 0.12.5 → 0.12.7

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 +76 -61
  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.7" : (() => {
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 (?, ?, ?, ?, ?, ?)"
@@ -3481,7 +3489,7 @@ var init_claude = __esm({
3481
3489
  });
3482
3490
 
3483
3491
  // src/backends/gemini.ts
3484
- import { existsSync as existsSync3 } from "fs";
3492
+ import { existsSync as existsSync3, mkdirSync } from "fs";
3485
3493
  import { execSync as execSync2 } from "child_process";
3486
3494
  import { join as join5 } from "path";
3487
3495
  function stripThinkingContent(text) {
@@ -3657,6 +3665,10 @@ var init_gemini = __esm({
3657
3665
  if (!slot) return { env, slot: null };
3658
3666
  if (slot.slotType === "api_key" && slot.apiKey) {
3659
3667
  env.GEMINI_API_KEY = slot.apiKey;
3668
+ const isolatedHome = join5(CC_CLAW_HOME, "gemini-slots", `apikey-${slot.id}`);
3669
+ if (!existsSync3(isolatedHome)) mkdirSync(isolatedHome, { recursive: true });
3670
+ env.GEMINI_CLI_HOME = isolatedHome;
3671
+ delete env.GOOGLE_API_KEY;
3660
3672
  } else if (slot.slotType === "oauth" && slot.configHome) {
3661
3673
  env.GEMINI_CLI_HOME = slot.configHome;
3662
3674
  delete env.GEMINI_API_KEY;
@@ -4512,7 +4524,7 @@ If the user asks *how* to do something with CC-Claw, use this expertise to sugge
4512
4524
  import {
4513
4525
  existsSync as existsSync7,
4514
4526
  writeFileSync,
4515
- mkdirSync,
4527
+ mkdirSync as mkdirSync2,
4516
4528
  readFileSync as readFileSync2,
4517
4529
  statSync as statSync2,
4518
4530
  copyFileSync,
@@ -4536,11 +4548,11 @@ function migrateFile(legacyPath, newPath, label2) {
4536
4548
  }
4537
4549
  function bootstrapWorkspaceFiles() {
4538
4550
  if (!existsSync7(IDENTITY_PATH)) {
4539
- mkdirSync(IDENTITY_PATH, { recursive: true });
4551
+ mkdirSync2(IDENTITY_PATH, { recursive: true });
4540
4552
  log("[bootstrap] Created identity/ directory");
4541
4553
  }
4542
4554
  if (!existsSync7(WORKSPACE_PATH)) {
4543
- mkdirSync(WORKSPACE_PATH, { recursive: true });
4555
+ mkdirSync2(WORKSPACE_PATH, { recursive: true });
4544
4556
  }
4545
4557
  migrateFile(LEGACY_SOUL_PATH, SOUL_PATH, "SOUL.md");
4546
4558
  migrateFile(LEGACY_USER_PATH, USER_PATH, "USER.md");
@@ -4567,11 +4579,11 @@ function bootstrapWorkspaceFiles() {
4567
4579
  log(`[bootstrap] Created default USER.md (timezone: ${tz})`);
4568
4580
  }
4569
4581
  if (!existsSync7(CONTEXT_DIR)) {
4570
- mkdirSync(CONTEXT_DIR, { recursive: true });
4582
+ mkdirSync2(CONTEXT_DIR, { recursive: true });
4571
4583
  log("[bootstrap] Created context/ directory");
4572
4584
  }
4573
4585
  if (!existsSync7(MEDIA_PATH)) {
4574
- mkdirSync(MEDIA_PATH, { recursive: true });
4586
+ mkdirSync2(MEDIA_PATH, { recursive: true });
4575
4587
  log("[bootstrap] Created media/ directory");
4576
4588
  }
4577
4589
  const expertisePath = join6(CONTEXT_DIR, "cc-claw-expertise.md");
@@ -5662,7 +5674,7 @@ var init_propagate = __esm({
5662
5674
  });
5663
5675
 
5664
5676
  // src/agents/mcp-config.ts
5665
- import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2, existsSync as existsSync9, readdirSync as readdirSync3, unlinkSync as unlinkSync3 } from "fs";
5677
+ import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync2, existsSync as existsSync9, readdirSync as readdirSync3, unlinkSync as unlinkSync3 } from "fs";
5666
5678
  import { join as join8, dirname } from "path";
5667
5679
  import { fileURLToPath } from "url";
5668
5680
  function generateOrchestratorMcpConfig(opts) {
@@ -5684,7 +5696,7 @@ function generateOrchestratorMcpConfig(opts) {
5684
5696
  };
5685
5697
  }
5686
5698
  function writeMcpConfigFile(config2) {
5687
- mkdirSync2(MCP_CONFIG_DIR, { recursive: true, mode: 448 });
5699
+ mkdirSync3(MCP_CONFIG_DIR, { recursive: true, mode: 448 });
5688
5700
  const jsonConfig = {
5689
5701
  mcpServers: {
5690
5702
  [config2.name]: {
@@ -5827,7 +5839,7 @@ var init_loader2 = __esm({
5827
5839
  });
5828
5840
 
5829
5841
  // src/agents/agent-log.ts
5830
- import { writeFileSync as writeFileSync3, readdirSync as readdirSync5, statSync as statSync3, unlinkSync as unlinkSync4, mkdirSync as mkdirSync3 } from "fs";
5842
+ import { writeFileSync as writeFileSync3, readdirSync as readdirSync5, statSync as statSync3, unlinkSync as unlinkSync4, mkdirSync as mkdirSync4 } from "fs";
5831
5843
  import { join as join10 } from "path";
5832
5844
  function truncate(text, maxBytes) {
5833
5845
  if (Buffer.byteLength(text, "utf-8") <= maxBytes) return text;
@@ -5867,7 +5879,7 @@ function writeAgentLog(data) {
5867
5879
  ""
5868
5880
  ];
5869
5881
  try {
5870
- mkdirSync3(AGENTS_PATH, { recursive: true });
5882
+ mkdirSync4(AGENTS_PATH, { recursive: true });
5871
5883
  writeFileSync3(logPath, lines.join("\n"), "utf-8");
5872
5884
  } catch (err) {
5873
5885
  log(`[agent-log] Failed to write log for ${data.agentId}: ${err}`);
@@ -5876,7 +5888,7 @@ function writeAgentLog(data) {
5876
5888
  }
5877
5889
  function pruneAgentLogs() {
5878
5890
  try {
5879
- mkdirSync3(AGENTS_PATH, { recursive: true });
5891
+ mkdirSync4(AGENTS_PATH, { recursive: true });
5880
5892
  const files = readdirSync5(AGENTS_PATH).filter((f) => f.endsWith(".log")).map((f) => {
5881
5893
  const fullPath = join10(AGENTS_PATH, f);
5882
5894
  const stat2 = statSync3(fullPath);
@@ -7502,7 +7514,7 @@ __export(apply_exports, {
7502
7514
  isTargetAllowed: () => isTargetAllowed,
7503
7515
  rollbackInsight: () => rollbackInsight
7504
7516
  });
7505
- import { readFileSync as readFileSync7, writeFileSync as writeFileSync4, existsSync as existsSync12, mkdirSync as mkdirSync4, readdirSync as readdirSync7, unlinkSync as unlinkSync5 } from "fs";
7517
+ import { readFileSync as readFileSync7, writeFileSync as writeFileSync4, existsSync as existsSync12, mkdirSync as mkdirSync5, readdirSync as readdirSync7, unlinkSync as unlinkSync5 } from "fs";
7506
7518
  import { join as join12, dirname as dirname2 } from "path";
7507
7519
  function isTargetAllowed(relativePath) {
7508
7520
  if (relativePath.includes("..")) return false;
@@ -7617,7 +7629,7 @@ async function applyInsight(insightId) {
7617
7629
  try {
7618
7630
  const parentDir = dirname2(absolutePath);
7619
7631
  if (!existsSync12(parentDir)) {
7620
- mkdirSync4(parentDir, { recursive: true });
7632
+ mkdirSync5(parentDir, { recursive: true });
7621
7633
  }
7622
7634
  if (original) {
7623
7635
  writeFileSync4(backupPath, original, "utf-8");
@@ -7775,7 +7787,7 @@ __export(server_exports, {
7775
7787
  });
7776
7788
  import { createServer } from "http";
7777
7789
  import { randomBytes } from "crypto";
7778
- import { writeFileSync as writeFileSync5, mkdirSync as mkdirSync5, existsSync as existsSync13 } from "fs";
7790
+ import { writeFileSync as writeFileSync5, mkdirSync as mkdirSync6, existsSync as existsSync13 } from "fs";
7779
7791
  function createSubAgentToken(agentId) {
7780
7792
  const token = `sub:${agentId.slice(0, 8)}:${randomBytes(16).toString("hex")}`;
7781
7793
  subAgentTokens.set(token, agentId);
@@ -8237,7 +8249,7 @@ data: ${JSON.stringify(data)}
8237
8249
  model: model2,
8238
8250
  permMode: mode
8239
8251
  });
8240
- if (response.usage) addUsage2(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? "unknown");
8252
+ if (response.usage) addUsage2(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? "unknown", void 0, response.usage.contextSize);
8241
8253
  sendSSE("done", JSON.stringify({ text: response.text, usage: response.usage }));
8242
8254
  res.end();
8243
8255
  } catch (err) {
@@ -8246,7 +8258,7 @@ data: ${JSON.stringify(data)}
8246
8258
  }
8247
8259
  } else {
8248
8260
  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");
8261
+ if (response.usage) addUsage2(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? "unknown", void 0, response.usage.contextSize);
8250
8262
  return jsonResponse(res, { text: response.text, usage: response.usage, sessionId: response.sessionId });
8251
8263
  }
8252
8264
  } catch (err) {
@@ -8611,7 +8623,7 @@ data: ${JSON.stringify(data)}
8611
8623
  });
8612
8624
  server.listen(PORT, "127.0.0.1");
8613
8625
  try {
8614
- mkdirSync5(DATA_PATH, { recursive: true });
8626
+ mkdirSync6(DATA_PATH, { recursive: true });
8615
8627
  const tokenPath = `${DATA_PATH}/api-token`;
8616
8628
  writeFileSync5(tokenPath, DASHBOARD_TOKEN, { mode: 384 });
8617
8629
  } catch (err) {
@@ -9154,6 +9166,7 @@ function spawnQuery(adapter, config2, model2, cancelState, thinkingLevel, timeou
9154
9166
  let input = 0;
9155
9167
  let output2 = 0;
9156
9168
  let cacheRead = 0;
9169
+ let contextSize;
9157
9170
  let sawToolEvents = false;
9158
9171
  let sawResultEvent = false;
9159
9172
  let toolTurnCount = 0;
@@ -9230,6 +9243,7 @@ function spawnQuery(adapter, config2, model2, cancelState, thinkingLevel, timeou
9230
9243
  input += ev.usage.input;
9231
9244
  output2 += ev.usage.output;
9232
9245
  cacheRead += ev.usage.cacheRead;
9246
+ contextSize = ev.usage.input + (ev.usage.cacheRead ?? 0);
9233
9247
  }
9234
9248
  break;
9235
9249
  case "result":
@@ -9240,6 +9254,7 @@ function spawnQuery(adapter, config2, model2, cancelState, thinkingLevel, timeou
9240
9254
  input = ev.usage.input;
9241
9255
  output2 = ev.usage.output;
9242
9256
  cacheRead = ev.usage.cacheRead;
9257
+ contextSize = ev.usage.input + (ev.usage.cacheRead ?? 0);
9243
9258
  }
9244
9259
  if (adapter.shouldKillOnResult()) {
9245
9260
  try {
@@ -9296,7 +9311,7 @@ Partial output: ${accumulatedText.slice(-500)}`;
9296
9311
  reject(new Error(`CLI exited with code ${code}${stderr ? `: ${stderr.slice(0, 500)}` : ""}`));
9297
9312
  return;
9298
9313
  }
9299
- resolve({ resultText, sessionId, input, output: output2, cacheRead, sawToolEvents, sawResultEvent });
9314
+ resolve({ resultText, sessionId, input, output: output2, cacheRead, contextSize, sawToolEvents, sawResultEvent });
9300
9315
  });
9301
9316
  });
9302
9317
  }
@@ -9458,7 +9473,7 @@ async function askAgentImpl(chatId, userMessage, opts) {
9458
9473
  activeChats.delete(chatId);
9459
9474
  }
9460
9475
  if (cancelState.cancelled) {
9461
- return { text: "Stopped.", usage: { input: result.input, output: result.output, cacheRead: result.cacheRead } };
9476
+ return { text: "Stopped.", usage: { input: result.input, output: result.output, cacheRead: result.cacheRead, contextSize: result.contextSize } };
9462
9477
  }
9463
9478
  if (result.sessionId && !isSyntheticChatId(chatId)) {
9464
9479
  setSessionId(chatId, result.sessionId);
@@ -9490,7 +9505,7 @@ async function askAgentImpl(chatId, userMessage, opts) {
9490
9505
  return {
9491
9506
  text: result.resultText || `(No response from ${adapter.displayName})`,
9492
9507
  sessionId: result.sessionId,
9493
- usage: { input: result.input, output: result.output, cacheRead: result.cacheRead }
9508
+ usage: { input: result.input, output: result.output, cacheRead: result.cacheRead, contextSize: result.contextSize }
9494
9509
  };
9495
9510
  }
9496
9511
  function getMcpConfigPath(chatId) {
@@ -10536,7 +10551,7 @@ async function runHeartbeat(chatId, config2) {
10536
10551
  } catch {
10537
10552
  heartbeatModel = getModel(chatId) ?? "unknown";
10538
10553
  }
10539
- addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, heartbeatModel);
10554
+ addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, heartbeatModel, void 0, response.usage.contextSize);
10540
10555
  }
10541
10556
  const now = (/* @__PURE__ */ new Date()).toISOString();
10542
10557
  const next = new Date(Date.now() + config2.intervalMs).toISOString();
@@ -10836,7 +10851,7 @@ var init_classify = __esm({
10836
10851
  });
10837
10852
 
10838
10853
  // src/media/image-gen.ts
10839
- import { mkdirSync as mkdirSync6, existsSync as existsSync17 } from "fs";
10854
+ import { mkdirSync as mkdirSync7, existsSync as existsSync17 } from "fs";
10840
10855
  import { writeFile as writeFile2 } from "fs/promises";
10841
10856
  import { join as join17 } from "path";
10842
10857
  async function generateImage(prompt) {
@@ -10886,7 +10901,7 @@ async function generateImage(prompt) {
10886
10901
  throw new Error(textResponse ?? "Gemini did not generate an image. The prompt may have been filtered.");
10887
10902
  }
10888
10903
  if (!existsSync17(IMAGE_OUTPUT_DIR)) {
10889
- mkdirSync6(IMAGE_OUTPUT_DIR, { recursive: true });
10904
+ mkdirSync7(IMAGE_OUTPUT_DIR, { recursive: true });
10890
10905
  }
10891
10906
  const ext = mimeType.includes("jpeg") || mimeType.includes("jpg") ? "jpg" : "png";
10892
10907
  const filename = `img_${Date.now()}.${ext}`;
@@ -12796,7 +12811,7 @@ Tap to toggle:`,
12796
12811
  const mode = getMode(chatId);
12797
12812
  const modelSig = getModelSignature(chatId);
12798
12813
  const contextMax = adapter?.contextWindow[model2] ?? 2e5;
12799
- const contextUsed = usage2.last_input_tokens + usage2.last_cache_read_tokens;
12814
+ const contextUsed = usage2.context_size;
12800
12815
  const contextPct = contextMax > 0 ? contextUsed / contextMax * 100 : 0;
12801
12816
  const ctxBar = buildBar(contextPct);
12802
12817
  const usedK = (contextUsed / 1e3).toFixed(1);
@@ -14156,7 +14171,7 @@ async function handleVoice(msg, channel) {
14156
14171
  const vVerbose = getVerboseLevel(chatId);
14157
14172
  const vToolCb = vVerbose !== "off" ? makeToolActionCallback(chatId, channel, vVerbose) : void 0;
14158
14173
  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);
14174
+ if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, vModel, void 0, response.usage.contextSize);
14160
14175
  if (await handleResponseExhaustion(response.text, chatId, msg, channel)) return;
14161
14176
  const voiceResponse = ensureReaction(response.text, transcript);
14162
14177
  await sendResponse(chatId, channel, voiceResponse, msg.messageId);
@@ -14222,7 +14237,7 @@ Acknowledge receipt. Do NOT analyze the video unless they ask you to.`;
14222
14237
  const vidVerbose = getVerboseLevel(chatId);
14223
14238
  const vidToolCb = vidVerbose !== "off" ? makeToolActionCallback(chatId, channel, vidVerbose) : void 0;
14224
14239
  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);
14240
+ if (response2.usage) addUsage(chatId, response2.usage.input, response2.usage.output, response2.usage.cacheRead, vidModel, void 0, response2.usage.contextSize);
14226
14241
  if (await handleResponseExhaustion(response2.text, chatId, msg, channel)) return;
14227
14242
  const vidResponse = ensureReaction(response2.text, caption || "video");
14228
14243
  await sendResponse(chatId, channel, vidResponse, msg.messageId);
@@ -14264,7 +14279,7 @@ ${content}
14264
14279
  const mVerbose = getVerboseLevel(chatId);
14265
14280
  const mToolCb = mVerbose !== "off" ? makeToolActionCallback(chatId, channel, mVerbose) : void 0;
14266
14281
  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);
14282
+ if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, mediaModel, void 0, response.usage.contextSize);
14268
14283
  if (await handleResponseExhaustion(response.text, chatId, msg, channel)) return;
14269
14284
  const mediaResponse = ensureReaction(response.text, caption || "file");
14270
14285
  await sendResponse(chatId, channel, mediaResponse, msg.messageId);
@@ -14413,7 +14428,7 @@ async function handleText(msg, channel) {
14413
14428
  }
14414
14429
  });
14415
14430
  const elapsedSec = ((Date.now() - sigT0) / 1e3).toFixed(1);
14416
- if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2);
14431
+ if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2, void 0, response.usage.contextSize);
14417
14432
  let responseText = response.text;
14418
14433
  const sigEnabled = getModelSignature(chatId);
14419
14434
  if (sigEnabled === "on" && responseText && !responseText.startsWith("(No response")) {
@@ -14571,7 +14586,7 @@ async function handleSideQuest(parentChatId, msg, channel) {
14571
14586
  const adapterForLog = backend2 ? getAdapter(backend2) : getAdapterForChat(parentChatId);
14572
14587
  appendToLog(parentChatId, `[side quest] ${userText}`, `[side quest] ${response.text ?? ""}`, adapterForLog.id, model2 ?? null, null);
14573
14588
  if (response.usage) {
14574
- addUsage(parentChatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? void 0, backend2 ?? void 0);
14589
+ addUsage(parentChatId, response.usage.input, response.usage.output, response.usage.cacheRead, model2 ?? void 0, backend2 ?? void 0, response.usage.contextSize);
14575
14590
  }
14576
14591
  try {
14577
14592
  const { detectAndLogSignals: detectAndLogSignals2 } = await Promise.resolve().then(() => (init_detect(), detect_exports));
@@ -15800,7 +15815,7 @@ Result: ${task.result.slice(0, 500)}` : ""
15800
15815
  const sVerbose = getVerboseLevel(chatId);
15801
15816
  const sToolCb = sVerbose !== "off" ? makeToolActionCallback(chatId, channel, sVerbose) : void 0;
15802
15817
  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);
15818
+ if (response.usage) addUsage(chatId, response.usage.input, response.usage.output, response.usage.cacheRead, skillModel, void 0, response.usage.contextSize);
15804
15819
  await sendResponse(chatId, channel, response.text);
15805
15820
  } else if (data.startsWith("evolve:")) {
15806
15821
  const parts = data.split(":");
@@ -17159,7 +17174,7 @@ async function executeJob(job) {
17159
17174
  updateJobLastRun(job.id, (/* @__PURE__ */ new Date()).toISOString());
17160
17175
  resetJobFailures(job.id);
17161
17176
  if (response.usage) {
17162
- addUsage(job.chatId, response.usage.input, response.usage.output, response.usage.cacheRead, resolvedModel);
17177
+ addUsage(job.chatId, response.usage.input, response.usage.output, response.usage.cacheRead, resolvedModel, void 0, response.usage.contextSize);
17163
17178
  }
17164
17179
  const delivered = await deliverJobOutput(job, response.text);
17165
17180
  const finalStatus = !delivered && contentStatus === "success" ? "delivery_failed" : contentStatus;
@@ -17461,7 +17476,7 @@ var init_wrap_backend = __esm({
17461
17476
  });
17462
17477
 
17463
17478
  // src/agents/runners/config-loader.ts
17464
- import { readFileSync as readFileSync10, readdirSync as readdirSync8, existsSync as existsSync19, mkdirSync as mkdirSync7, watchFile, unwatchFile } from "fs";
17479
+ import { readFileSync as readFileSync10, readdirSync as readdirSync8, existsSync as existsSync19, mkdirSync as mkdirSync8, watchFile, unwatchFile } from "fs";
17465
17480
  import { join as join20 } from "path";
17466
17481
  import { execFileSync } from "child_process";
17467
17482
  function resolveExecutable(config2) {
@@ -17612,7 +17627,7 @@ function loadRunnerConfig(filePath) {
17612
17627
  }
17613
17628
  function loadAllRunnerConfigs() {
17614
17629
  if (!existsSync19(RUNNERS_PATH)) {
17615
- mkdirSync7(RUNNERS_PATH, { recursive: true });
17630
+ mkdirSync8(RUNNERS_PATH, { recursive: true });
17616
17631
  return [];
17617
17632
  }
17618
17633
  const files = readdirSync8(RUNNERS_PATH).filter((f) => f.endsWith(".json"));
@@ -18653,7 +18668,7 @@ __export(ai_skill_exports, {
18653
18668
  generateAiSkill: () => generateAiSkill,
18654
18669
  installAiSkill: () => installAiSkill
18655
18670
  });
18656
- import { existsSync as existsSync21, writeFileSync as writeFileSync7, mkdirSync as mkdirSync8 } from "fs";
18671
+ import { existsSync as existsSync21, writeFileSync as writeFileSync7, mkdirSync as mkdirSync9 } from "fs";
18657
18672
  import { join as join22 } from "path";
18658
18673
  import { homedir as homedir7 } from "os";
18659
18674
  function generateAiSkill() {
@@ -19058,7 +19073,7 @@ function installAiSkill() {
19058
19073
  const skillDir = join22(dir, "cc-claw-cli");
19059
19074
  const skillPath = join22(skillDir, "SKILL.md");
19060
19075
  try {
19061
- mkdirSync8(skillDir, { recursive: true });
19076
+ mkdirSync9(skillDir, { recursive: true });
19062
19077
  writeFileSync7(skillPath, skill, "utf-8");
19063
19078
  installed.push(skillPath);
19064
19079
  } catch {
@@ -19089,7 +19104,7 @@ var index_exports = {};
19089
19104
  __export(index_exports, {
19090
19105
  main: () => main
19091
19106
  });
19092
- import { mkdirSync as mkdirSync9, existsSync as existsSync22, renameSync, statSync as statSync5, readFileSync as readFileSync12 } from "fs";
19107
+ import { mkdirSync as mkdirSync10, existsSync as existsSync22, renameSync, statSync as statSync5, readFileSync as readFileSync12 } from "fs";
19093
19108
  import { join as join23 } from "path";
19094
19109
  import dotenv from "dotenv";
19095
19110
  function migrateLayout() {
@@ -19237,10 +19252,10 @@ async function main() {
19237
19252
  bootstrapSkills().catch((err) => error("[cc-claw] Skill bootstrap failed:", err));
19238
19253
  try {
19239
19254
  const { generateAiSkill: generateAiSkill2 } = await Promise.resolve().then(() => (init_ai_skill(), ai_skill_exports));
19240
- const { writeFileSync: writeFileSync12, mkdirSync: mkdirSync15 } = await import("fs");
19255
+ const { writeFileSync: writeFileSync12, mkdirSync: mkdirSync16 } = await import("fs");
19241
19256
  const { join: join28 } = await import("path");
19242
19257
  const skillDir = join28(SKILLS_PATH, "cc-claw-cli");
19243
- mkdirSync15(skillDir, { recursive: true });
19258
+ mkdirSync16(skillDir, { recursive: true });
19244
19259
  writeFileSync12(join28(skillDir, "SKILL.md"), generateAiSkill2(), "utf-8");
19245
19260
  log("[cc-claw] AI skill updated");
19246
19261
  } catch {
@@ -19312,7 +19327,7 @@ var init_index = __esm({
19312
19327
  init_bootstrap2();
19313
19328
  init_health3();
19314
19329
  for (const dir of [CC_CLAW_HOME, DATA_PATH, LOGS_PATH, SKILLS_PATH, RUNNERS_PATH, AGENTS_PATH]) {
19315
- if (!existsSync22(dir)) mkdirSync9(dir, { recursive: true });
19330
+ if (!existsSync22(dir)) mkdirSync10(dir, { recursive: true });
19316
19331
  }
19317
19332
  migrateLayout();
19318
19333
  if (existsSync22(ENV_PATH)) {
@@ -19436,7 +19451,7 @@ __export(service_exports, {
19436
19451
  serviceStatus: () => serviceStatus,
19437
19452
  uninstallService: () => uninstallService
19438
19453
  });
19439
- import { existsSync as existsSync24, mkdirSync as mkdirSync10, writeFileSync as writeFileSync8, unlinkSync as unlinkSync6 } from "fs";
19454
+ import { existsSync as existsSync24, mkdirSync as mkdirSync11, writeFileSync as writeFileSync8, unlinkSync as unlinkSync6 } from "fs";
19440
19455
  import { execFileSync as execFileSync2, execSync as execSync7 } from "child_process";
19441
19456
  import { homedir as homedir8, platform } from "os";
19442
19457
  import { join as join24, dirname as dirname4 } from "path";
@@ -19511,8 +19526,8 @@ function generatePlist() {
19511
19526
  }
19512
19527
  function installMacOS() {
19513
19528
  const agentsDir = dirname4(PLIST_PATH);
19514
- if (!existsSync24(agentsDir)) mkdirSync10(agentsDir, { recursive: true });
19515
- if (!existsSync24(LOGS_PATH)) mkdirSync10(LOGS_PATH, { recursive: true });
19529
+ if (!existsSync24(agentsDir)) mkdirSync11(agentsDir, { recursive: true });
19530
+ if (!existsSync24(LOGS_PATH)) mkdirSync11(LOGS_PATH, { recursive: true });
19516
19531
  if (existsSync24(PLIST_PATH)) {
19517
19532
  try {
19518
19533
  execFileSync2("launchctl", ["unload", PLIST_PATH]);
@@ -19599,8 +19614,8 @@ WantedBy=default.target
19599
19614
  `;
19600
19615
  }
19601
19616
  function installLinux() {
19602
- if (!existsSync24(SYSTEMD_DIR)) mkdirSync10(SYSTEMD_DIR, { recursive: true });
19603
- if (!existsSync24(LOGS_PATH)) mkdirSync10(LOGS_PATH, { recursive: true });
19617
+ if (!existsSync24(SYSTEMD_DIR)) mkdirSync11(SYSTEMD_DIR, { recursive: true });
19618
+ if (!existsSync24(LOGS_PATH)) mkdirSync11(LOGS_PATH, { recursive: true });
19604
19619
  writeFileSync8(UNIT_PATH, generateUnit());
19605
19620
  console.log(` Installed: ${UNIT_PATH}`);
19606
19621
  execFileSync2("systemctl", ["--user", "daemon-reload"]);
@@ -20288,7 +20303,7 @@ __export(gemini_exports, {
20288
20303
  geminiReorder: () => geminiReorder,
20289
20304
  geminiRotation: () => geminiRotation
20290
20305
  });
20291
- import { existsSync as existsSync28, mkdirSync as mkdirSync11, writeFileSync as writeFileSync9, readFileSync as readFileSync17, chmodSync } from "fs";
20306
+ import { existsSync as existsSync28, mkdirSync as mkdirSync12, writeFileSync as writeFileSync9, readFileSync as readFileSync17, chmodSync } from "fs";
20292
20307
  import { join as join25 } from "path";
20293
20308
  import { createInterface as createInterface5 } from "readline";
20294
20309
  function requireDb() {
@@ -20402,12 +20417,12 @@ async function geminiAddKey(globalOpts, opts) {
20402
20417
  async function geminiAddAccount(globalOpts, opts) {
20403
20418
  await requireWriteDb();
20404
20419
  const slotsDir = join25(CC_CLAW_HOME, "gemini-slots");
20405
- if (!existsSync28(slotsDir)) mkdirSync11(slotsDir, { recursive: true });
20420
+ if (!existsSync28(slotsDir)) mkdirSync12(slotsDir, { recursive: true });
20406
20421
  const { addGeminiSlot: addGeminiSlot2 } = await Promise.resolve().then(() => (init_store5(), store_exports5));
20407
20422
  const tempId = Date.now();
20408
20423
  const slotDir = join25(slotsDir, `slot-${tempId}`);
20409
- mkdirSync11(slotDir, { recursive: true, mode: 448 });
20410
- mkdirSync11(join25(slotDir, ".gemini"), { recursive: true });
20424
+ mkdirSync12(slotDir, { recursive: true, mode: 448 });
20425
+ mkdirSync12(join25(slotDir, ".gemini"), { recursive: true });
20411
20426
  writeFileSync9(join25(slotDir, ".gemini", "settings.json"), JSON.stringify({
20412
20427
  security: { auth: { selectedType: "oauth-personal" } }
20413
20428
  }, null, 2));
@@ -21251,7 +21266,7 @@ __export(db_exports, {
21251
21266
  dbPath: () => dbPath,
21252
21267
  dbStats: () => dbStats
21253
21268
  });
21254
- import { existsSync as existsSync34, statSync as statSync8, copyFileSync as copyFileSync2, mkdirSync as mkdirSync12 } from "fs";
21269
+ import { existsSync as existsSync34, statSync as statSync8, copyFileSync as copyFileSync2, mkdirSync as mkdirSync13 } from "fs";
21255
21270
  import { dirname as dirname5 } from "path";
21256
21271
  async function dbStats(globalOpts) {
21257
21272
  if (!existsSync34(DB_PATH)) {
@@ -21302,7 +21317,7 @@ async function dbBackup(globalOpts, destPath) {
21302
21317
  }
21303
21318
  const dest = destPath ?? `${DB_PATH}.backup-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}`;
21304
21319
  try {
21305
- mkdirSync12(dirname5(dest), { recursive: true });
21320
+ mkdirSync13(dirname5(dest), { recursive: true });
21306
21321
  copyFileSync2(DB_PATH, dest);
21307
21322
  const walPath = DB_PATH + "-wal";
21308
21323
  if (existsSync34(walPath)) copyFileSync2(walPath, dest + "-wal");
@@ -22553,7 +22568,7 @@ var completion_exports = {};
22553
22568
  __export(completion_exports, {
22554
22569
  completionCommand: () => completionCommand
22555
22570
  });
22556
- import { writeFileSync as writeFileSync10, mkdirSync as mkdirSync13 } from "fs";
22571
+ import { writeFileSync as writeFileSync10, mkdirSync as mkdirSync14 } from "fs";
22557
22572
  import { join as join26 } from "path";
22558
22573
  import { homedir as homedir9 } from "os";
22559
22574
  async function completionCommand(opts) {
@@ -22571,7 +22586,7 @@ async function completionCommand(opts) {
22571
22586
  }
22572
22587
  if (opts.install) {
22573
22588
  const dir = join26(homedir9(), ".config", "cc-claw", "completions");
22574
- mkdirSync13(dir, { recursive: true });
22589
+ mkdirSync14(dir, { recursive: true });
22575
22590
  const filename = shell === "zsh" ? "_cc-claw" : shell === "fish" ? "cc-claw.fish" : "cc-claw.bash";
22576
22591
  const filepath = join26(dir, filename);
22577
22592
  writeFileSync10(filepath, script, "utf-8");
@@ -23162,7 +23177,7 @@ var init_evolve = __esm({
23162
23177
 
23163
23178
  // src/setup.ts
23164
23179
  var setup_exports = {};
23165
- import { existsSync as existsSync46, writeFileSync as writeFileSync11, readFileSync as readFileSync20, copyFileSync as copyFileSync3, mkdirSync as mkdirSync14, statSync as statSync9 } from "fs";
23180
+ import { existsSync as existsSync46, writeFileSync as writeFileSync11, readFileSync as readFileSync20, copyFileSync as copyFileSync3, mkdirSync as mkdirSync15, statSync as statSync9 } from "fs";
23166
23181
  import { execFileSync as execFileSync4 } from "child_process";
23167
23182
  import { createInterface as createInterface7 } from "readline";
23168
23183
  import { join as join27 } from "path";
@@ -23240,7 +23255,7 @@ async function setup() {
23240
23255
  }
23241
23256
  console.log("");
23242
23257
  for (const dir of [CC_CLAW_HOME, DATA_PATH, LOGS_PATH, SKILLS_PATH, RUNNERS_PATH, AGENTS_PATH]) {
23243
- if (!existsSync46(dir)) mkdirSync14(dir, { recursive: true });
23258
+ if (!existsSync46(dir)) mkdirSync15(dir, { recursive: true });
23244
23259
  }
23245
23260
  const env = {};
23246
23261
  const envSource = existsSync46(ENV_PATH) ? ENV_PATH : existsSync46(".env") ? ".env" : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-claw",
3
- "version": "0.12.5",
3
+ "version": "0.12.7",
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",