MCPcopy Create free account
hub / github.com/SethGammon/Citadel / loadEvents

Function loadEvents

scripts/permission-audit.js:61–87  ·  view source on GitHub ↗

* Load permission events from both sources, normalized to * { ts, tool, target, decision }. * * audit.jsonl entries (event === 'permission-request') predate the dedicated * log; to avoid double counting we only include audit entries older than the * earliest record in permission-events.jsonl.

(root)

Source from the content-addressed store, hash-verified

59 * earliest record in permission-events.jsonl.
60 */
61function loadEvents(root) {
62 const telemetryDir = path.join(root, '.planning', 'telemetry');
63 const dedicated = readJsonl(path.join(telemetryDir, 'permission-events.jsonl'))
64 .filter((e) => e && e.ts)
65 .map((e) => ({
66 ts: e.ts,
67 tool: e.tool || 'unknown',
68 target: e.target || '',
69 decision: e.decision || 'deferred',
70 }));
71
72 const earliestDedicated = dedicated.length
73 ? dedicated.reduce((min, e) => (e.ts < min ? e.ts : min), dedicated[0].ts)
74 : null;
75
76 const historical = readJsonl(path.join(telemetryDir, 'audit.jsonl'))
77 .filter((e) => e && e.event === 'permission-request' && e.timestamp)
78 .filter((e) => earliestDedicated === null || e.timestamp < earliestDedicated)
79 .map((e) => ({
80 ts: e.timestamp,
81 tool: e.tool || 'unknown',
82 target: e.target || '',
83 decision: e.decision || 'deferred',
84 }));
85
86 return historical.concat(dedicated).sort((a, b) => (a.ts < b.ts ? -1 : 1));
87}
88
89function countBy(events, keyFn) {
90 const counts = new Map();

Callers 1

mainFunction · 0.85

Calls 1

readJsonlFunction · 0.70

Tested by

no test coverage detected