refactor: move destinations from JSON file into inbound.db

The per-session destination map was being written as a sidecar JSON file
(/workspace/.nanoclaw-destinations.json) — inconsistent with the rest of
v2, where all host↔container IO goes through inbound.db / outbound.db.

Move it into a `destinations` table in INBOUND_SCHEMA. The host writes
it before every container wake AND on demand (e.g. after create_agent)
so the creator sees the new child destination mid-session without a
restart. The container queries the table live on every lookup — no
cache, no staleness window.

- src/db/schema.ts: add `destinations` table to INBOUND_SCHEMA.
- src/session-manager.ts: writeDestinationsFile → writeDestinations,
  writes via DELETE + INSERT inside a transaction.
- src/delivery.ts: create_agent handler calls writeDestinations on the
  creator's session after inserting the new destination rows.
- container/agent-runner/src/destinations.ts: queries inbound.db
  directly in every findByName/getAllDestinations/findByRouting call.
  No more cache. No setDestinationsForTest (obsolete). No fs import.
- container/agent-runner/src/index.ts and mcp-tools/index.ts: remove
  loadDestinations() calls — no longer needed.
- Test helper initTestSessionDb creates the destinations table.
  Integration test inserts a row directly instead of mocking the cache.

No backwards compatibility: sessions predating the schema update must
be recreated. This is fine on the v2 branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gavrielc
2026-04-10 16:45:53 +03:00
parent 09e1861a22
commit b591d7ce96
9 changed files with 132 additions and 79 deletions

View File

@@ -20,7 +20,7 @@ import {
markContainerRunning,
markContainerStopped,
sessionDir,
writeDestinationsFile,
writeDestinations,
} from './session-manager.js';
import type { AgentGroup, Session } from './types.js';
@@ -59,8 +59,8 @@ export async function wakeContainer(session: Session): Promise<void> {
return;
}
// Refresh the destination map file so any admin changes take effect on wake
writeDestinationsFile(agentGroup.id, session.id);
// Refresh the destination map so any admin changes take effect on wake
writeDestinations(agentGroup.id, session.id);
const mounts = buildMounts(agentGroup, session);
const containerName = `nanoclaw-v2-${agentGroup.folder}-${Date.now()}`;