Merge branch 'main' into feature/hybrid-search
Resolved conflicts by: - Keeping feature/hybrid-search build process documentation in CLAUDE.md - Removing deleted plugin/scripts/search-server.js (intentionally deleted in feature branch) - Removing usage logging from worker-service.ts (telemetry captured at SDK level) - Rebuilt worker-service.cjs after resolving source file conflicts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -454,6 +454,11 @@ class WorkerService {
|
||||
// Parse and store with prompt number (non-blocking Chroma sync)
|
||||
this.handleAgentMessage(session, textContent, session.lastPromptNumber);
|
||||
}
|
||||
|
||||
// Capture usage data from result messages
|
||||
if (message.type === 'result' && message.subtype === 'success') {
|
||||
// Usage telemetry is captured at SDK level
|
||||
}
|
||||
}
|
||||
|
||||
// Mark completed
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { appendFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
|
||||
/**
|
||||
* Usage data structure from Claude Agent SDK result messages
|
||||
*/
|
||||
export interface UsageData {
|
||||
timestamp: string;
|
||||
sessionDbId: number;
|
||||
claudeSessionId: string;
|
||||
project: string;
|
||||
promptNumber: number;
|
||||
model: string;
|
||||
sessionId: string; // SDK session ID
|
||||
uuid: string; // SDK message UUID
|
||||
durationMs: number;
|
||||
durationApiMs: number;
|
||||
numTurns: number;
|
||||
totalCostUsd: number;
|
||||
usage: {
|
||||
inputTokens: number;
|
||||
outputTokens: number;
|
||||
cacheCreationInputTokens: number;
|
||||
cacheReadInputTokens: number;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Logger for capturing usage metrics to JSONL files
|
||||
*/
|
||||
export class UsageLogger {
|
||||
private logDir: string;
|
||||
private logFile: string;
|
||||
|
||||
constructor() {
|
||||
this.logDir = join(homedir(), '.claude-mem', 'usage-logs');
|
||||
// Create a daily log file
|
||||
const date = new Date().toISOString().split('T')[0]; // YYYY-MM-DD
|
||||
this.logFile = join(this.logDir, `usage-${date}.jsonl`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log usage data from SDK result message
|
||||
*/
|
||||
logUsage(data: UsageData): void {
|
||||
try {
|
||||
const line = JSON.stringify(data) + '\n';
|
||||
appendFileSync(this.logFile, line, 'utf-8');
|
||||
} catch (error) {
|
||||
console.error('Failed to log usage data:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current log file path
|
||||
*/
|
||||
getLogFilePath(): string {
|
||||
return this.logFile;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user