feat(FN-1403): add run audit system with SQLite persistence

- Add run-audit event types and SQLite schema migration
- Implement typed store read/write/query APIs for run audit
- Make audit writes atomic with task updates (transactional writes)
- Fix SQLite parameter type casting in db layer
- Add comprehensive tests for RunMutationContext and audit functionality
This commit is contained in:
gsxdsm
2026-04-09 16:39:16 -07:00
parent 69a4507113
commit f257c53059
8 changed files with 847 additions and 28 deletions

View File

@@ -59,7 +59,7 @@ export function fromJson<T>(json: string | null | undefined): T | undefined {
// ── Schema Definition ────────────────────────────────────────────────
const SCHEMA_VERSION = 24;
const SCHEMA_VERSION = 25;
function normalizeTaskComments(
steeringComments: SteeringComment[] | undefined,
@@ -905,6 +905,36 @@ export class Database {
`);
});
}
if (version < 25) {
this.applyMigration(25, () => {
this.db.exec(`
CREATE TABLE IF NOT EXISTS runAuditEvents (
id TEXT PRIMARY KEY,
timestamp TEXT NOT NULL,
taskId TEXT,
agentId TEXT NOT NULL,
runId TEXT NOT NULL,
domain TEXT NOT NULL,
mutationType TEXT NOT NULL,
target TEXT NOT NULL,
metadata TEXT
)
`);
this.db.exec(`
CREATE INDEX IF NOT EXISTS idxRunAuditEventsRunIdTimestamp
ON runAuditEvents(runId, timestamp)
`);
this.db.exec(`
CREATE INDEX IF NOT EXISTS idxRunAuditEventsTaskIdTimestamp
ON runAuditEvents(taskId, timestamp)
`);
this.db.exec(`
CREATE INDEX IF NOT EXISTS idxRunAuditEventsTimestamp
ON runAuditEvents(timestamp)
`);
});
}
}
/**