feat(security): Yerin security-agent toolset (read-only)

New securityRegistry (separate from companionRegistry) with two read-only,
secret-free tools for the Yerin security agent:
- audit_log: query the redacted audit trail by actor_kind/actor_id
- agent_inventory: list agents + capabilities/scopes (explicit projection,
  never SELECT *, no token material)

Follows the existing createRegistry() pattern. Design + wiring roadmap in
docs/yerin-security-agent.md. Not yet seeded/exposed over MCP (left for review).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-01 23:26:46 +10:00
parent 459a7749c9
commit 6c393d8069
4 changed files with 121 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import * as agents from '../../../../db/repos/agents.js';
// Privilege inventory: which agents exist and what each is allowed to do.
// Returns an explicit projection (never SELECT *) so token/secret columns can
// never leak through this view even if the agents schema grows.
export const agentInventoryTool = {
name: 'agent_inventory',
description: 'List every agent and its privilege level (capabilities + scopes). Use to audit who can read/suggest/write and to spot over-privileged agents. Never returns token material.',
input_schema: { type: 'object', properties: {} },
async handler(_args, _ctx) {
const rows = await agents.list();
const projected = rows.map(a => ({
id: a.id,
slug: a.slug,
name: a.name,
kind: a.kind,
model: a.model,
capabilities: a.capabilities || {},
scopes: a.scopes || {}
}));
return { agents: projected };
}
};

View File

@@ -0,0 +1,26 @@
import * as audit from '../../../../db/repos/audit.js';
// Yerin's window into the audit trail. Read-only. The audit repo already
// redacts sensitive diff keys (token/password/api_key/secret/authorization)
// at write time, so entries are safe to surface.
export const auditLogTool = {
name: 'audit_log',
description: 'Review the security audit trail: who (which actor) did what, newest first. Filter by actor_kind (user/agent/cron/worker/system) and/or actor_id to investigate a specific principal.',
input_schema: {
type: 'object',
properties: {
actor_kind: {
type: 'string',
enum: ['user', 'agent', 'cron', 'worker', 'system'],
description: 'optional: only entries from this kind of actor'
},
actor_id: { type: 'string', description: 'optional: only entries from this actor id (uuid)' },
limit: { type: 'integer', description: 'max entries (default 50, max 200)' }
}
},
async handler({ actor_kind, actor_id, limit } = {}, _ctx) {
const capped = Math.min(Math.max(Number(limit) || 50, 1), 200);
const entries = await audit.listByActor({ actor_kind, actor_id, limit: capped });
return { entries };
}
};

View File

@@ -0,0 +1,11 @@
import { createRegistry } from '../../registry.js';
import { auditLogTool } from './audit_log.js';
import { agentInventoryTool } from './agent_inventory.js';
// Yerin's security toolset — read-only observability, kept in its own registry
// so the security agent gets security tools (not Dross's propose_change). A
// future MCP server can expose this registry the same way companion-stdio.js
// exposes companionRegistry. Roadmap for further tools: see docs/yerin-security-agent.md
export const securityRegistry = createRegistry();
securityRegistry.registerTool(auditLogTool);
securityRegistry.registerTool(agentInventoryTool);