audit-log.mjs
31 lines 886 B
Raw
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0 feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes… Human minor ⚠ breaking 11 days ago
1 /**
2 * Hub audit log. Appends events to data_dir/hub_audit.log.
3 */
4
5 import fs from 'fs';
6 import path from 'path';
7
8 /**
9 * Append an audit entry. Creates data_dir if needed.
10 * @param {string} dataDir - Path to data directory
11 * @param {{
12 * userId: string,
13 * action: string,
14 * proposalId: string,
15 * detail?: Record<string, unknown>,
16 * }} entry
17 */
18 export function appendAudit(dataDir, entry) {
19 const logPath = path.join(dataDir, 'hub_audit.log');
20 const dir = path.dirname(logPath);
21 if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
22 const line =
23 JSON.stringify({
24 ts: new Date().toISOString(),
25 user_id: entry.userId,
26 action: entry.action,
27 proposal_id: entry.proposalId,
28 ...(entry.detail && typeof entry.detail === 'object' ? { detail: entry.detail } : {}),
29 }) + '\n';
30 fs.appendFileSync(logPath, line, 'utf8');
31 }
File History 1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882 fix(test): align Band B landing assertion with desktop MCP … Human 11 days ago