Files
Claude-Code-Workflow/ccw/src/core/services/cli-session-audit.ts
catlog22 362f354f1c Add benchmark results and tests for LSP graph builder and staged search
- Introduced a new benchmark results file for performance comparison on 2026-02-09.
- Added a test for LspGraphBuilder to ensure it does not expand nodes at maximum depth.
- Created a test for the staged search pipeline to validate fallback behavior when stage 1 returns empty results.
2026-02-09 21:43:13 +08:00

40 lines
1.1 KiB
TypeScript

import { existsSync, mkdirSync, appendFileSync } from 'fs';
import path from 'path';
export type CliSessionAuditEventType =
| 'session_created'
| 'session_closed'
| 'session_send'
| 'session_execute'
| 'session_resize'
| 'session_share_created'
| 'session_idle_reaped';
export interface CliSessionAuditEvent {
type: CliSessionAuditEventType;
timestamp: string;
projectRoot: string;
sessionKey?: string;
tool?: string;
resumeKey?: string;
workingDir?: string;
ip?: string;
userAgent?: string;
details?: Record<string, unknown>;
}
function auditFilePath(projectRoot: string): string {
return path.join(projectRoot, '.workflow', 'audit', 'cli-sessions.jsonl');
}
export function appendCliSessionAudit(event: CliSessionAuditEvent): void {
try {
const filePath = auditFilePath(event.projectRoot);
const dir = path.dirname(filePath);
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
appendFileSync(filePath, JSON.stringify(event) + '\n', { encoding: 'utf8' });
} catch {
// Best-effort: never fail API requests due to audit write errors.
}
}