clawkit-ai 1.1.0 → 1.1.2

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/package.json +1 -1
  2. package/src/sync.mjs +61 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawkit-ai",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Transform your OpenClaw agent into a production-ready AI assistant with memory, skills, and a dashboard",
5
5
  "type": "module",
6
6
  "bin": {
package/src/sync.mjs CHANGED
@@ -414,33 +414,70 @@ function gatherState(workspace) {
414
414
  return true;
415
415
  }).slice(0, 20);
416
416
 
417
- // --- Token Usage & Cost ---
418
- state.usage = { inputTokens: 0, outputTokens: 0, contextUsed: 0, contextMax: 0, costEstimate: '', model: '', compactions: 0 };
417
+ // Agent activity status
418
+ const statusFile = join(workspace, 'logs', 'agent-status.txt');
419
+ if (existsSync(statusFile)) {
420
+ state.agentActivity = readFileSync(statusFile, 'utf8').trim().slice(0, 100);
421
+ } else if (state.recentActivity.length > 0) {
422
+ state.agentActivity = state.recentActivity[0].message.slice(0, 80);
423
+ } else {
424
+ state.agentActivity = 'Waiting for instructions';
425
+ }
419
426
 
420
- // Try to read from OpenClaw gateway config for model
421
- try {
422
- const gwConfig = join(process.env.HOME || '', '.openclaw', 'config.yaml');
423
- if (existsSync(gwConfig)) {
424
- const cfg = readFileSync(gwConfig, 'utf8');
425
- const modelMatch = cfg.match(/model:\s*["']?([^\s"']+)/);
426
- if (modelMatch) state.usage.model = modelMatch[1];
427
+ // --- Token Usage & Cost + Context Breakdown ---
428
+ state.usage = { inputTokens: 0, outputTokens: 0, contextUsed: 0, contextMax: 0, costEstimate: '', model: '', compactions: 0, breakdown: [] };
429
+
430
+ // Calculate context breakdown from injected workspace files
431
+ const injectedFiles = ['AGENTS.md', 'SOUL.md', 'TOOLS.md', 'IDENTITY.md', 'USER.md', 'HEARTBEAT.md', 'MEMORY.md'];
432
+ let totalFileTokens = 0;
433
+ const breakdown = [];
434
+
435
+ for (const fname of injectedFiles) {
436
+ const fpath = join(workspace, fname);
437
+ if (existsSync(fpath)) {
438
+ const bytes = statSync(fpath).size;
439
+ const tokens = Math.round(bytes / 4); // ~4 chars per token
440
+ totalFileTokens += tokens;
441
+ breakdown.push({ label: fname.replace('.md', ''), tokens });
427
442
  }
428
- } catch {}
443
+ }
429
444
 
430
- // Try to get session stats from gateway HTTP API
431
- try {
432
- const statusOut = execSync('curl -s -m 3 http://127.0.0.1:18789/api/session/status 2>/dev/null || true', { timeout: 5000, encoding: 'utf8' });
433
- const statusMatch = statusOut.match(/\{[\s\S]*\}/);
434
- if (statusMatch) {
435
- const sd = JSON.parse(statusMatch[0]);
436
- if (sd.inputTokens || sd.tokensIn) state.usage.inputTokens = sd.inputTokens || sd.tokensIn || 0;
437
- if (sd.outputTokens || sd.tokensOut) state.usage.outputTokens = sd.outputTokens || sd.tokensOut || 0;
438
- if (sd.contextUsed) state.usage.contextUsed = sd.contextUsed;
439
- if (sd.contextMax) state.usage.contextMax = sd.contextMax;
440
- if (sd.compactions) state.usage.compactions = sd.compactions;
441
- if (sd.model) state.usage.model = sd.model;
442
- }
443
- } catch {}
445
+ // Add estimates for system prompt and tools
446
+ breakdown.push({ label: 'System Prompt', tokens: 3000 });
447
+ breakdown.push({ label: 'Tool Definitions', tokens: 2000 });
448
+ breakdown.push({ label: 'Skills List', tokens: 1500 });
449
+ totalFileTokens += 6500;
450
+
451
+ // Sort by size descending
452
+ breakdown.sort((a, b) => b.tokens - a.tokens);
453
+ state.usage.breakdown = breakdown;
454
+ state.usage.systemTokens = totalFileTokens;
455
+
456
+ // Read context stats from logs/context-stats.json (updated by agent)
457
+ const ctxStatsPath = join(workspace, 'logs', 'context-stats.json');
458
+ if (existsSync(ctxStatsPath)) {
459
+ try {
460
+ const cs = JSON.parse(readFileSync(ctxStatsPath, 'utf8'));
461
+ state.usage.model = cs.model || state.usage.model;
462
+ state.usage.inputTokens = cs.inputTokens || 0;
463
+ state.usage.outputTokens = cs.outputTokens || 0;
464
+ state.usage.contextUsed = cs.contextUsed || 0;
465
+ state.usage.contextMax = cs.contextMax || 0;
466
+ state.usage.compactions = cs.compactions || 0;
467
+ } catch {}
468
+ }
469
+
470
+ // Fallback: read model from gateway config
471
+ if (!state.usage.model) {
472
+ try {
473
+ const gwPath = join(process.env.HOME || '', '.openclaw', 'openclaw.json');
474
+ if (existsSync(gwPath)) {
475
+ const gw = JSON.parse(readFileSync(gwPath, 'utf8'));
476
+ const primary = gw.agents?.defaults?.model?.primary;
477
+ if (primary) state.usage.model = primary;
478
+ }
479
+ } catch {}
480
+ }
444
481
 
445
482
  // If we couldn't get from CLI, estimate from daily note sizes
446
483
  if (!state.usage.model) {