refactor(modules): extract agent-to-agent as registry-based module

Last extraction of Phase 3. Moves inter-agent messaging + create_agent +
destination projection into src/modules/agent-to-agent/. Core retains:

- `channel_type === 'agent'` dispatch in delivery.ts, guarded by
  hasTable('agent_destinations') + dynamic import into module.
- Channel-permission ACL in delivery.ts, guarded by hasTable, with
  inlined SQL (no module import from core).
- writeDestinations call in container-runner.ts, guarded by hasTable +
  dynamic import into module.
- createMessagingGroupAgent's destination side effect in db/messaging-groups.ts,
  guarded by hasTable. This is a documented transitional tier violation
  (core imports from optional module), analogous to src/access.ts.

Migration `004-agent-destinations.ts` renamed to `module-agent-to-agent-
destinations.ts` preserving `name: 'agent-destinations'` so existing DBs
don't re-run it.

delivery.ts: 600 → 449 lines. handleSystemAction's last switch case gone
(just registry + default log-and-drop). notifyAgent helper removed (only
create_agent used it).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gavrielc
2026-04-18 19:00:10 +03:00
parent c80a23e24f
commit 46b19dcf9c
13 changed files with 345 additions and 264 deletions

View File

@@ -31,7 +31,6 @@ import {
markContainerRunning,
markContainerStopped,
sessionDir,
writeDestinations,
writeSessionRouting,
} from './session-manager.js';
import type { AgentGroup, Session } from './types.js';
@@ -90,8 +89,12 @@ async function spawnContainer(session: Session): Promise<void> {
}
// Refresh the destination map and default reply routing so any admin
// changes take effect on wake.
writeDestinations(agentGroup.id, session.id);
// changes take effect on wake. Destinations come from the agent-to-agent
// module — skip when the module isn't installed (table absent).
if (hasTable(getDb(), 'agent_destinations')) {
const { writeDestinations } = await import('./modules/agent-to-agent/write-destinations.js');
writeDestinations(agentGroup.id, session.id);
}
writeSessionRouting(agentGroup.id, session.id);
// Resolve the effective provider + any host-side contribution it declares