refactor(server): move the install audit trail from core to the server (P1.2, UF-040)
Core keeps only shared infrastructure, so InstallAuditStore leaves it and lives in packages/server/src/local/install-audit.ts. The trail itself stays: the Audit and Activity tabs, the extend and export routes, and the threat model entry keep working on the same waggle.db table. - @waggle/shared gets RecordAuditInput and the narrow InstallAuditRecorder (record only), which the agent's skill tools now depend on. - The server creates the audit table before the one-time legacy copy, which no longer constructs it in core. - UF-040: GET /api/debug/logs called prepare() on the store's private db wrapper, which has none, so the support bundle never carried recent installs. It now reads them through getRecentSummary().
This commit is contained in:
@@ -10,8 +10,9 @@ import Fastify, { type FastifyInstance, type FastifyRequest } from 'fastify';
|
||||
import cors from '@fastify/cors';
|
||||
import fastifyStatic from '@fastify/static';
|
||||
import websocket from '@fastify/websocket';
|
||||
import { WaggleDB, importLegacyMindData, workspaceDataScope, type LegacyMindSource, WorkspaceManager, WaggleConfig, createEmbeddingProvider, type EmbeddingProviderConfig, type EmbeddingProviderInstance, InstallAuditStore, CronStore, AwarenessLayer, VaultStore, SkillHashStore, TelemetryStore, TELEMETRY_EVENTS, ExecutionTraceStore } from '@waggle/core';
|
||||
import { WaggleDB, importLegacyMindData, workspaceDataScope, type LegacyMindSource, WorkspaceManager, WaggleConfig, createEmbeddingProvider, type EmbeddingProviderConfig, type EmbeddingProviderInstance, CronStore, AwarenessLayer, VaultStore, SkillHashStore, TelemetryStore, TELEMETRY_EVENTS, ExecutionTraceStore } from '@waggle/core';
|
||||
import { corsOriginAllowed } from './cors-config.js';
|
||||
import { InstallAuditStore } from './install-audit.js';
|
||||
import { getStorageProvider } from './storage/index.js';
|
||||
import { isLoopbackBind, resolveBindHost } from './net-config.js';
|
||||
import { isLocalRequest } from './origin-guard.js';
|
||||
@@ -362,7 +363,7 @@ declare module 'fastify' {
|
||||
eventBus: EventEmitter;
|
||||
agentRunner?: AgentRunner;
|
||||
agentState: AgentState;
|
||||
auditStore: import('@waggle/core').InstallAuditStore;
|
||||
auditStore: InstallAuditStore;
|
||||
cronStore: import('@waggle/core').CronStore;
|
||||
waggleDb: import('@waggle/core').WaggleDB;
|
||||
/** Memory (ADR-0007): personal and workspace memories, reached only through the contract. */
|
||||
@@ -501,6 +502,11 @@ export async function buildLocalServer(config: Partial<LocalConfig> = {}) {
|
||||
// A workspace whose directory fails the path checks has nothing to copy.
|
||||
}
|
||||
}
|
||||
// Install audit store — persistent trail for capability install events. Its
|
||||
// table must exist before the legacy copy below, which fills it.
|
||||
const auditStore = new InstallAuditStore(waggleDb);
|
||||
server.decorate('auditStore', auditStore);
|
||||
|
||||
for (const report of importLegacyMindData(waggleDb, legacySources)) {
|
||||
if (report.status === 'imported') {
|
||||
log.info(`[waggle-db] copied legacy data for ${report.scope}: ${JSON.stringify(report.copied)}`);
|
||||
@@ -509,10 +515,6 @@ export async function buildLocalServer(config: Partial<LocalConfig> = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
// Install audit store — persistent trail for capability install events
|
||||
const auditStore = new InstallAuditStore(waggleDb);
|
||||
server.decorate('auditStore', auditStore);
|
||||
|
||||
// Cron store — SQLite-backed schedule persistence for Solo
|
||||
const cronStore = new CronStore(waggleDb);
|
||||
server.decorate('cronStore', cronStore);
|
||||
@@ -1933,13 +1935,10 @@ export async function buildLocalServer(config: Partial<LocalConfig> = {}) {
|
||||
};
|
||||
try { payload.health = await server.inject({ method: 'GET', url: '/health' }).then(r => JSON.parse(r.payload)); } catch { /* non-blocking */ }
|
||||
try {
|
||||
const raw = (server.auditStore as unknown as { db?: { prepare: (sql: string) => { all: () => unknown[] } } })?.db;
|
||||
if (raw) {
|
||||
// R2-006: expose only a coarse, non-recon column subset (no capability
|
||||
// names/versions/sources, risk_level, approval_class, initiator or detail)
|
||||
// and cap the rows — the support bundle needs activity shape, not an inventory.
|
||||
payload.auditRecent = raw.prepare('SELECT timestamp, action, capability_type FROM install_audit ORDER BY timestamp DESC LIMIT 50').all();
|
||||
}
|
||||
// R2-006: expose only a coarse, non-recon column subset (no capability
|
||||
// names/versions/sources, risk_level, approval_class, initiator or detail)
|
||||
// and cap the rows — the support bundle needs activity shape, not an inventory.
|
||||
payload.auditRecent = server.auditStore.getRecentSummary(50);
|
||||
} catch { /* non-blocking */ }
|
||||
// R2-006: vault key NAMES dropped — even names are recon material and the
|
||||
// support bundle does not need them.
|
||||
|
||||
Reference in New Issue
Block a user