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.
- package/package.json +1 -1
- package/src/sync.mjs +61 -24
package/package.json
CHANGED
package/src/sync.mjs
CHANGED
|
@@ -414,33 +414,70 @@ function gatherState(workspace) {
|
|
|
414
414
|
return true;
|
|
415
415
|
}).slice(0, 20);
|
|
416
416
|
|
|
417
|
-
//
|
|
418
|
-
|
|
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
|
-
//
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
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
|
-
}
|
|
443
|
+
}
|
|
429
444
|
|
|
430
|
-
//
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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) {
|