From 2e08f2ae9674ccccdf8d135fea09080ffa66bced Mon Sep 17 00:00:00 2001 From: "shumeiko.it" Date: Sun, 25 Oct 2026 21:32:38 +0100 Subject: [PATCH] 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(). --- AGENTS.md | 3 +- THREAT_MODEL.md | 6 +-- docs/ARCHITECTURE.md | 2 +- docs/oss/upstream-fixes.md | 10 ++++ packages/agent/src/skill-tools.ts | 4 +- packages/agent/src/skill-write-service.ts | 4 +- packages/core/src/cron-store.ts | 4 +- packages/core/src/index.ts | 6 --- packages/core/src/skill-hashes.ts | 4 +- packages/core/src/waggle-db-import.ts | 7 +-- packages/server/src/local/index.ts | 25 +++++---- .../src => server/src/local}/install-audit.ts | 53 ++++++++----------- .../server/src/local/routes/connectors.ts | 3 +- packages/server/src/local/routes/extend.ts | 4 +- packages/server/src/local/routes/mcps.ts | 3 +- .../tests/local/connectors-phase4.test.ts | 3 +- packages/server/tests/local/extend.test.ts | 4 +- .../local}/install-audit-check-parity.test.ts | 4 +- .../tests/local}/install-audit.test.ts | 14 ++++- packages/server/tests/local/mcps.test.ts | 2 +- .../server/tests/routes/trust-wiring.test.ts | 12 +++++ packages/shared/src/risk.ts | 20 +++++++ 22 files changed, 118 insertions(+), 79 deletions(-) rename packages/{core/src => server/src/local}/install-audit.ts (85%) rename packages/{core/tests => server/tests/local}/install-audit-check-parity.test.ts (89%) rename packages/{core/tests => server/tests/local}/install-audit.test.ts (96%) diff --git a/AGENTS.md b/AGENTS.md index f079ca9..8e72229 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -99,7 +99,8 @@ Already removed: tiers and Stripe (P0.1); KVARK, enterprise packs, the complianc subsystem, self-learning and `packages/optimizer` (P1.4, P1.6, ADR-0004); the team and WaggleDance routes in the sidecar and `team-sync` in core, with the team server moved to `packages/team-server` (P1.1); the single-mind to multi-mind migration in core (P1.2). -Still to be removed, so do not build on it: `install-audit.ts` in core (P1.2). +The install audit trail moved from core to the server (`packages/server/src/local/install-audit.ts`, +P1.2); other packages write to it through `InstallAuditRecorder` from `@waggle/shared`. --- diff --git a/THREAT_MODEL.md b/THREAT_MODEL.md index ae2e7f2..a6bbaf6 100644 --- a/THREAT_MODEL.md +++ b/THREAT_MODEL.md @@ -70,10 +70,10 @@ regex that gates connector write actions (`_create_/_update_/_delete_/_send_/… Read-only/informational calls flow freely; destructive ops do not inherit autonomy. ### 4. Capability install audit trail — `install-audit.ts` -`packages/core/src/install-audit.ts`. Every install-relevant action (proposed, approved, -installed, rejected, failed, uninstalled) is persisted to the `.mind` DB with risk, +`packages/server/src/local/install-audit.ts`. Every install-relevant action (proposed, +approved, installed, rejected, failed, uninstalled) is persisted to `waggle.db` with risk, approval class, initiator, and trust source — a verifiable history of what was installed, -when, why, and by whom. Backs the EU-AI-Act capability-provenance story. +when, why, and by whom. ### 5. Local secret storage — `vault.ts` `packages/core/src/vault.ts`. Secrets are encrypted with AES-256-GCM under a diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 54fb1b8..99d4d3e 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -75,7 +75,6 @@ The foundation layer for the desktop/server runtime. Zero network dependencies. - **FileStore**: Workspace filesystem access with a segment-boundary + symlink-aware containment guard and a secret deny-list (see the [threat model](../THREAT_MODEL.md)). - **CronStore**: Schedule management for the cron service. CRUD on cron expressions with last/next run tracking. - **ImportParser** (`memory-import.ts`): parses ChatGPT and Claude export files into importable knowledge items. -- **InstallAudit**: append-only capability-install trail (proposed / approved / installed / rejected / uninstalled) backing the EU-AI-Act provenance story. - **Telemetry / Compliance**: telemetry pipeline and compliance reporting (`compliance/`). ### @waggle/agent @@ -111,6 +110,7 @@ The intelligence layer. Orchestrates tool execution, sub-agents, and workflows. The API layer. Fastify server exposing 29 route modules. - **Local Server** (`src/local/`): Solo mode on localhost:3333. Routes for chat, workspaces, sessions, memory, settings, vault, skills, plugins, connectors, marketplace, cron, fleet, etc. +- **InstallAuditStore** (`src/local/install-audit.ts`): append-only capability-install trail (proposed / approved / installed / rejected / uninstalled) in `waggle.db`, shown in the Audit and Activity tabs. - **Team Server** (`src/routes/`): Multi-user mode with PostgreSQL (Drizzle ORM), Redis, Clerk auth, and WebSocket presence. - **SSE Streaming**: Chat responses stream via Server-Sent Events. - **Anthropic Proxy**: Built-in `/v1/chat/completions` endpoint that translates OpenAI format to Anthropic API. diff --git a/docs/oss/upstream-fixes.md b/docs/oss/upstream-fixes.md index a976cf0..2c16781 100644 --- a/docs/oss/upstream-fixes.md +++ b/docs/oss/upstream-fixes.md @@ -68,6 +68,7 @@ Baseline: commit `b20b138` of `git.os-dev.tech/oleg.m/waggle-os`. | UF-037 | Restore overwrites database files the running sidecar holds open | Open | Sidecar, backup | | UF-038 | Marketplace installs never notify the running sidecar | Open | Marketplace, sidecar | | UF-039 | A memory saved to an unknown workspace lands in personal memory | Fixed | Sidecar, memory, privacy | +| UF-040 | The support bundle never includes recent installs | Fixed | Sidecar, support | ## Entries @@ -395,3 +396,12 @@ Entries UF-010 to UF-019 come from the UI audit `anti-slop/audit-001-2026-10-14. - Cause: the routes treat an unknown workspace the same as no workspace. - What we did: the three write routes save to personal memory only when no workspace is named and answer 404 `workspace_not_found` for a workspace that does not exist (`writeScopeForWorkspace` in `memory-records.ts`). - Recommendation: refuse writes for unknown workspaces in the main project as well. + +### UF-040. The support bundle never includes recent installs +- Status: Fixed +- Found: 2026-10-25 +- Where: at commit `b20b138`, `packages/server/src/local/index.ts:2752-2760` (`GET /api/debug/logs`) +- Symptom: the support log download in Settings (`waggle-logs-*.json`) has no `auditRecent` field, although the route promises recent install events. +- Cause: the route reads the private `db` field of the audit store and calls `prepare` on it. That field is the database wrapper (`MindDB`), which has no `prepare` method, so the call throws and the empty `catch` drops the error. +- What we did: the server's `InstallAuditStore` got `getRecentSummary()`, which returns only the timestamp, action and capability type of the latest 50 events, and the route calls it. A test checks the field and its columns. +- Recommendation: read the trail through the store's own API in the main project as well, and log errors in this route instead of dropping them. diff --git a/packages/agent/src/skill-tools.ts b/packages/agent/src/skill-tools.ts index 7597dbd..a85939e 100644 --- a/packages/agent/src/skill-tools.ts +++ b/packages/agent/src/skill-tools.ts @@ -12,7 +12,7 @@ import type { ToolDefinition } from './tools.js'; import { SkillRecommender } from './skill-recommender.js'; import { searchCapabilities, validateInstallCandidate, type MarketplaceCandidate } from './capability-acquisition.js'; import { assessTrust, formatTrustSummary } from './trust-model.js'; -import type { InstallAuditStore } from '@waggle/core'; +import type { InstallAuditRecorder } from '@waggle/shared'; // Type-only import — erased at runtime, so it does NOT reintroduce the // agent ↔ marketplace runtime cycle that the lazy import below guards against. import type { SecurityGate, MarketplacePackage } from '@waggle/marketplace'; @@ -50,7 +50,7 @@ export interface SkillToolsDeps { /** Native tool names (for acquisition search — avoids proposing install when a tool exists) */ nativeToolNames?: string[]; /** Audit store for recording install events (optional — degrades gracefully) */ - auditStore?: InstallAuditStore; + auditStore?: InstallAuditRecorder; /** Optional callback to search the marketplace catalog for capabilities */ searchMarketplace?: (query: string) => Promise; /** diff --git a/packages/agent/src/skill-write-service.ts b/packages/agent/src/skill-write-service.ts index da5a9fc..61546a8 100644 --- a/packages/agent/src/skill-write-service.ts +++ b/packages/agent/src/skill-write-service.ts @@ -17,14 +17,14 @@ import * as path from 'node:path'; import { redactSkillContent } from './skill-redaction.js'; import type { SkillInitiator } from './skill-frontmatter.js'; import { parseSkillFrontmatter } from './skill-frontmatter.js'; -import type { InstallAuditStore } from '@waggle/core'; +import type { InstallAuditRecorder } from '@waggle/shared'; /** Shared deps for every skill-write op. auditStore/onChange degrade gracefully. */ export interface SkillWriteDeps { /** Directory holding personal-scope SKILL.md files (~/.waggle/skills). */ skillsDir: string; /** Audit store — when present, every op records an install_audit row. */ - auditStore?: InstallAuditStore; + auditStore?: InstallAuditRecorder; /** Called after a successful write/delete so the caller can hot-reload skills. */ onChange?: () => void; } diff --git a/packages/core/src/cron-store.ts b/packages/core/src/cron-store.ts index 5a43952..0a39599 100644 --- a/packages/core/src/cron-store.ts +++ b/packages/core/src/cron-store.ts @@ -2,8 +2,8 @@ * Cron Store — SQLite persistence for solo cron schedules. * * Stores cron job definitions with expression validation via cron-parser, - * due-job queries, and run tracking. Follows the same pattern as - * InstallAuditStore — operates on the .mind DB with lazy table creation. + * due-job queries, and run tracking. Operates on waggle.db with lazy table + * creation. */ import cronParser from 'cron-parser'; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 562c646..dbdb15d 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -56,12 +56,6 @@ export { importLegacyMindData, type LegacyMindSource, type LegacyImportReport } // ── Waggle-specific orchestration ── export { WaggleConfig, type ProviderEntry } from './config.js'; -export { - InstallAuditStore, INSTALL_AUDIT_TABLE_SQL, - type InstallAuditEntry, type RecordAuditInput, - type AuditAction, type AuditRiskLevel, type AuditTrustSource, - type AuditApprovalClass, type AuditInitiator, type AuditCapabilityType, -} from './install-audit.js'; export { CronStore, CRON_SCHEDULES_TABLE_SQL, CRON_RUN_LEASES_TABLE_SQL, VALID_JOB_TYPES, cronExprError, type CronSchedule, type CreateScheduleInput, type CronJobType, diff --git a/packages/core/src/skill-hashes.ts b/packages/core/src/skill-hashes.ts index 09ead7a..6dbc2ab 100644 --- a/packages/core/src/skill-hashes.ts +++ b/packages/core/src/skill-hashes.ts @@ -1,9 +1,9 @@ /** * Skill Hash Store — SHA-256 content hashing for skill update detection. * - * Stores hashes of skill file content in the .mind DB. On server startup, + * Stores hashes of skill file content in waggle.db. On server startup, * compares current file hashes to stored hashes to detect changes. - * Follows the same ensureTable pattern as CronStore / InstallAuditStore. + * Follows the same ensureTable pattern as CronStore. */ import * as crypto from 'node:crypto'; diff --git a/packages/core/src/waggle-db-import.ts b/packages/core/src/waggle-db-import.ts index cf1dc1d..104e69e 100644 --- a/packages/core/src/waggle-db-import.ts +++ b/packages/core/src/waggle-db-import.ts @@ -15,7 +15,6 @@ import { AwarenessLayer } from './awareness.js'; import { CronStore } from './cron-store.js'; import { ExecutionTraceStore } from './execution-traces.js'; import { IdentityLayer } from './identity.js'; -import { InstallAuditStore } from './install-audit.js'; import { SkillHashStore } from './skill-hashes.js'; import type { DataScope, WaggleDB } from './waggle-db.js'; @@ -121,13 +120,15 @@ function copyScopedTables(source: DatabaseType, target: DatabaseType, scope: Dat * Copies Waggle data from each legacy source into `waggleDb`, once per scope. * The personal source also brings the app-wide tables; workspace sources bring * their profile and awareness items. + * + * Tables owned outside core (install_audit, owned by the server) must be created + * by their owner before this call; otherwise they take the legacy definition. */ export function importLegacyMindData(waggleDb: WaggleDB, sources: LegacyMindSource[]): LegacyImportReport[] { - // Create every target table with its current schema first. + // Create every core target table with its current schema first. new CronStore(waggleDb); new SkillHashStore(waggleDb); new ExecutionTraceStore(waggleDb); - new InstallAuditStore(waggleDb); new IdentityLayer(waggleDb); new AwarenessLayer(waggleDb); diff --git a/packages/server/src/local/index.ts b/packages/server/src/local/index.ts index 19ab756..d2a72f6 100644 --- a/packages/server/src/local/index.ts +++ b/packages/server/src/local/index.ts @@ -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 = {}) { // 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 = {}) { } } - // 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 = {}) { }; 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. diff --git a/packages/core/src/install-audit.ts b/packages/server/src/local/install-audit.ts similarity index 85% rename from packages/core/src/install-audit.ts rename to packages/server/src/local/install-audit.ts index e02aa14..b6c973e 100644 --- a/packages/core/src/install-audit.ts +++ b/packages/server/src/local/install-audit.ts @@ -5,31 +5,23 @@ * failed) so there is a verifiable history of what was installed, when, why, * and by whom. * - * Lives in waggle.db with Waggle's other own data (ADR-0007). + * Lives in waggle.db with Waggle's other own data (ADR-0007). The server owns + * the store; core keeps only shared infrastructure (P1.2), and producers outside + * the server write through InstallAuditRecorder from @waggle/shared. */ -import type { WaggleDB } from './waggle-db.js'; +import type { WaggleDB } from '@waggle/core'; import { sqlInList, RISK_LEVELS, APPROVAL_CLASSES, AUDIT_ACTIONS, AUDIT_CAPABILITY_TYPES, AUDIT_INITIATORS, TRUST_SOURCES, } from '@waggle/shared'; +import type { + AuditAction, AuditCapabilityType, AuditInitiator, ApprovalClass, + InstallAuditRecorder, RecordAuditInput, RiskLevel, TrustSource, +} from '@waggle/shared'; // ── Types ────────────────────────────────────────────────────────────── -// P7/D15 A2b: the audit vocabulary is now canonical in @waggle/shared. The -// Audit*-prefixed names are kept as aliases (re-exported) so every downstream -// `import { AuditAction, ... } from '@waggle/core'` keeps working unchanged. -// All six sets were already byte-identical to the shared ones (incl. P5/D4's -// 'uninstalled'), so this is a pure structural re-point — no value change. -export type { - AuditAction, AuditCapabilityType, AuditInitiator, - RiskLevel as AuditRiskLevel, ApprovalClass as AuditApprovalClass, TrustSource as AuditTrustSource, -} from '@waggle/shared'; -import type { - AuditAction, AuditCapabilityType, AuditInitiator, - RiskLevel as AuditRiskLevel, ApprovalClass as AuditApprovalClass, TrustSource as AuditTrustSource, -} from '@waggle/shared'; - export interface InstallAuditEntry { id: number; timestamp: string; @@ -37,26 +29,16 @@ export interface InstallAuditEntry { capability_type: AuditCapabilityType; source: string; version: string | null; - risk_level: AuditRiskLevel; - trust_source: AuditTrustSource; - approval_class: AuditApprovalClass; + risk_level: RiskLevel; + trust_source: TrustSource; + approval_class: ApprovalClass; action: AuditAction; initiator: AuditInitiator; detail: string; } -export interface RecordAuditInput { - capabilityName: string; - capabilityType: AuditCapabilityType; - source: string; - version?: string | null; - riskLevel: AuditRiskLevel; - trustSource: AuditTrustSource; - approvalClass: AuditApprovalClass; - action: AuditAction; - initiator: AuditInitiator; - detail?: string; -} +/** The coarse columns the support bundle may carry (R2-006). */ +export type InstallAuditSummary = Pick; // ── Table DDL ────────────────────────────────────────────────────────── @@ -89,7 +71,7 @@ CREATE INDEX IF NOT EXISTS idx_audit_timestamp ON install_audit (timestamp DESC) // ── Store ────────────────────────────────────────────────────────────── -export class InstallAuditStore { +export class InstallAuditStore implements InstallAuditRecorder { private db: WaggleDB; constructor(db: WaggleDB) { @@ -205,6 +187,13 @@ export class InstallAuditStore { ).all(type, limit) as InstallAuditEntry[]; } + /** Recent entries without names, versions, sources, risk or detail. */ + getRecentSummary(limit: number = 50): InstallAuditSummary[] { + return this.db.getDatabase().prepare( + 'SELECT timestamp, action, capability_type FROM install_audit ORDER BY id DESC LIMIT ?', + ).all(limit) as InstallAuditSummary[]; + } + /** Get all entries (for testing). */ getAll(): InstallAuditEntry[] { return this.db.getDatabase().prepare( diff --git a/packages/server/src/local/routes/connectors.ts b/packages/server/src/local/routes/connectors.ts index 0a2ec3c..f3e4656 100644 --- a/packages/server/src/local/routes/connectors.ts +++ b/packages/server/src/local/routes/connectors.ts @@ -1,6 +1,5 @@ import type { FastifyInstance } from 'fastify'; -import type { ConnectorHealth } from '@waggle/shared'; -import type { RecordAuditInput } from '@waggle/core'; +import type { ConnectorHealth, RecordAuditInput } from '@waggle/shared'; import { JiraConnector, SalesforceConnector, getConnectorCredential, setConnectorCredential, setConnectorCredentialBundle, diff --git a/packages/server/src/local/routes/extend.ts b/packages/server/src/local/routes/extend.ts index d638f60..7045f3d 100644 --- a/packages/server/src/local/routes/extend.ts +++ b/packages/server/src/local/routes/extend.ts @@ -13,8 +13,8 @@ */ import type { FastifyInstance } from 'fastify'; -import { EXTENSION_TYPES, type ExtensionType } from '@waggle/shared'; -import type { AuditCapabilityType, InstallAuditEntry } from '@waggle/core'; +import { EXTENSION_TYPES, type AuditCapabilityType, type ExtensionType } from '@waggle/shared'; +import type { InstallAuditEntry } from '../install-audit.js'; import { authHeaders } from './validate.js'; /** ExtensionType → marketplace InstallationType, where representable (A5). */ diff --git a/packages/server/src/local/routes/mcps.ts b/packages/server/src/local/routes/mcps.ts index e191927..80c937c 100644 --- a/packages/server/src/local/routes/mcps.ts +++ b/packages/server/src/local/routes/mcps.ts @@ -30,9 +30,10 @@ import { MCP_CATALOG, type McpInstance, type McpServer, + type RecordAuditInput, } from '@waggle/shared'; import type { McpRuntime, McpServerState } from '@waggle/agent'; -import { scanForInjection, type RecordAuditInput } from '@waggle/core'; +import { scanForInjection } from '@waggle/core'; import { MCP_SERVERS, MarketplaceInstaller, diff --git a/packages/server/tests/local/connectors-phase4.test.ts b/packages/server/tests/local/connectors-phase4.test.ts index 5aafd99..f0208d3 100644 --- a/packages/server/tests/local/connectors-phase4.test.ts +++ b/packages/server/tests/local/connectors-phase4.test.ts @@ -12,7 +12,8 @@ import Fastify from 'fastify'; import * as fs from 'node:fs'; import * as path from 'node:path'; import * as os from 'node:os'; -import { WaggleDB, InstallAuditStore, VaultStore, type SecretStore } from '@waggle/core'; +import { WaggleDB, VaultStore, type SecretStore } from '@waggle/core'; +import { InstallAuditStore } from '../../src/local/install-audit.js'; import { ConnectorRegistry, BaseConnector, diff --git a/packages/server/tests/local/extend.test.ts b/packages/server/tests/local/extend.test.ts index be2d0c9..0fec1c5 100644 --- a/packages/server/tests/local/extend.test.ts +++ b/packages/server/tests/local/extend.test.ts @@ -8,7 +8,9 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import Fastify from 'fastify'; -import { WaggleDB, InstallAuditStore, type RecordAuditInput } from '@waggle/core'; +import { WaggleDB } from '@waggle/core'; +import type { RecordAuditInput } from '@waggle/shared'; +import { InstallAuditStore } from '../../src/local/install-audit.js'; import { extendRoutes } from '../../src/local/routes/extend.js'; import { marketplaceRoutes } from '../../src/local/routes/marketplace.js'; diff --git a/packages/core/tests/install-audit-check-parity.test.ts b/packages/server/tests/local/install-audit-check-parity.test.ts similarity index 89% rename from packages/core/tests/install-audit-check-parity.test.ts rename to packages/server/tests/local/install-audit-check-parity.test.ts index e93571b..42e21f6 100644 --- a/packages/core/tests/install-audit-check-parity.test.ts +++ b/packages/server/tests/local/install-audit-check-parity.test.ts @@ -10,7 +10,7 @@ import { sqlInList, RISK_LEVELS, APPROVAL_CLASSES, AUDIT_ACTIONS, AUDIT_CAPABILITY_TYPES, AUDIT_INITIATORS, TRUST_SOURCES, } from '@waggle/shared'; -import { INSTALL_AUDIT_TABLE_SQL } from '../src/install-audit.js'; +import { INSTALL_AUDIT_TABLE_SQL } from '../../src/local/install-audit.js'; const COLUMNS = [ { col: 'capability_type', values: AUDIT_CAPABILITY_TYPES }, @@ -25,7 +25,7 @@ describe('install_audit CHECK parity (A3)', () => { for (const { col, values } of COLUMNS) { const expected = `${col} IN (${sqlInList(values)})`; - it(`core install-audit DDL pins ${col} to the canonical list`, () => { + it(`install-audit DDL pins ${col} to the canonical list`, () => { expect(INSTALL_AUDIT_TABLE_SQL).toContain(expected); }); } diff --git a/packages/core/tests/install-audit.test.ts b/packages/server/tests/local/install-audit.test.ts similarity index 96% rename from packages/core/tests/install-audit.test.ts rename to packages/server/tests/local/install-audit.test.ts index 39bcf7b..0f14ecf 100644 --- a/packages/core/tests/install-audit.test.ts +++ b/packages/server/tests/local/install-audit.test.ts @@ -5,8 +5,9 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import * as fs from 'node:fs'; import * as path from 'node:path'; import * as os from 'node:os'; -import { WaggleDB } from '../src/waggle-db.js'; -import { InstallAuditStore, type RecordAuditInput } from '../src/install-audit.js'; +import { WaggleDB } from '@waggle/core'; +import type { RecordAuditInput } from '@waggle/shared'; +import { InstallAuditStore } from '../../src/local/install-audit.js'; describe('InstallAuditStore', () => { let tmpDir: string; @@ -45,6 +46,15 @@ describe('InstallAuditStore', () => { expect(store.getByAction('uninstalled')).toHaveLength(1); }); + it('summarises recent entries without names, sources, risk or detail', () => { + store.record(makeInput({ capabilityName: 'first', action: 'proposed' })); + store.record(makeInput({ capabilityName: 'second', capabilityType: 'mcp', action: 'installed' })); + + const summary = store.getRecentSummary(1); + expect(summary).toHaveLength(1); + expect(summary[0]).toEqual({ timestamp: expect.any(String), action: 'installed', capability_type: 'mcp' }); + }); + it("migrates a legacy-CHECK table to accept 'uninstalled' (P5/D4)", () => { const tmp2 = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-audit-legacy-')); const legacyDb = new WaggleDB(path.join(tmp2, 'waggle.db')); diff --git a/packages/server/tests/local/mcps.test.ts b/packages/server/tests/local/mcps.test.ts index b78bf7d..851824b 100644 --- a/packages/server/tests/local/mcps.test.ts +++ b/packages/server/tests/local/mcps.test.ts @@ -20,7 +20,7 @@ import * as os from 'node:os'; import { PassThrough } from 'node:stream'; import Database from 'better-sqlite3'; import { WaggleDB } from '@waggle/core'; -import { InstallAuditStore } from '@waggle/core'; +import { InstallAuditStore } from '../../src/local/install-audit.js'; import { MCP_CATALOG } from '@waggle/shared'; import { SecurityGate } from '@waggle/marketplace'; import { McpRuntime, type McpProcess, type SpawnFn } from '@waggle/agent'; diff --git a/packages/server/tests/routes/trust-wiring.test.ts b/packages/server/tests/routes/trust-wiring.test.ts index 1740a42..c7de403 100644 --- a/packages/server/tests/routes/trust-wiring.test.ts +++ b/packages/server/tests/routes/trust-wiring.test.ts @@ -103,6 +103,18 @@ describe('Trust Model Runtime Wiring', () => { // so no new audit entries should be created via the API route expect(after).toBe(before); }); + + it('the support bundle carries recent installs without capability names (UF-040)', async () => { + const res = await injectWithAuth(server, { method: 'GET', url: '/api/debug/logs' }); + expect(res.statusCode).toBe(200); + + const { auditRecent } = JSON.parse(res.payload) as { auditRecent?: Array> }; + expect(auditRecent).toBeDefined(); + expect(auditRecent!.some(e => e.action === 'installed' && e.capability_type === 'skill')).toBe(true); + for (const entry of auditRecent!) { + expect(Object.keys(entry).sort()).toEqual(['action', 'capability_type', 'timestamp']); + } + }); }); describe('Audit REST endpoint', () => { diff --git a/packages/shared/src/risk.ts b/packages/shared/src/risk.ts index 6fc1a12..89e9efd 100644 --- a/packages/shared/src/risk.ts +++ b/packages/shared/src/risk.ts @@ -62,6 +62,26 @@ export type AuditCapabilityType = (typeof AUDIT_CAPABILITY_TYPES)[number]; export const AUDIT_INITIATORS = ['agent', 'user', 'system'] as const; export type AuditInitiator = (typeof AUDIT_INITIATORS)[number]; +/** One event for the install audit trail. */ +export interface RecordAuditInput { + capabilityName: string; + capabilityType: AuditCapabilityType; + source: string; + version?: string | null; + riskLevel: RiskLevel; + trustSource: TrustSource; + approvalClass: ApprovalClass; + action: AuditAction; + initiator: AuditInitiator; + detail?: string; +} + +/** Write side of the install audit trail. Producers such as the agent's skill + * tools only record; the store that also reads the trail lives in the server. */ +export interface InstallAuditRecorder { + record(input: RecordAuditInput): void; +} + /** Ascending severity order — index = rank. Used to compare/sort risk levels so a * `critical` always outranks `low` (the team-governance bug was a `?? 0` that * sorted `critical` BELOW `low`). */