@@ -0,0 +1,22 @@
|
||||
import { appendFile, mkdir } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
const ALLOWED = new Set(['event', 'state', 'code', 'lane', 'jobId', 'durationMs', 'success', 'reason']);
|
||||
|
||||
export class PrivacyLog {
|
||||
constructor({ file = path.join(process.env.XDG_STATE_HOME || path.join(process.env.HOME || '/tmp', '.local/state'), 'jarvis/events.jsonl') } = {}) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
async record(event, fields = {}) {
|
||||
const safe = { ts: new Date().toISOString(), event };
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
if (ALLOWED.has(key) && (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')) safe[key] = value;
|
||||
}
|
||||
await mkdir(path.dirname(this.file), { recursive: true });
|
||||
await appendFile(this.file, `${JSON.stringify(safe)}\n`, 'utf8');
|
||||
return safe;
|
||||
}
|
||||
}
|
||||
|
||||
export { ALLOWED };
|
||||
Reference in New Issue
Block a user