Alejandro Gutiérrez
|
3c0154ae70
|
feat(broker): port routing + status model from claude-intercom to postgres
Ports the proven claude-intercom broker logic into apps/broker with
SQLite → Drizzle/Postgres translation. Core state engine kept verbatim:
source-priority writes (hook > manual > jsonl), fresh-gating, TTL
sweeper for stuck-working, pending-status race handler, priority
delivery gates (now/next/low), Windows path encoding (5-candidate
fallback incl. Roberto's H:\Claude → H--Claude rule).
New modules:
- broker.ts (492 lines): writeStatus, handleHookSetStatus, sweepers,
presence lifecycle, message queueing + drainForMember, sourceRank +
isHookFresh / isSourceFresh logic, findMemberByPubkey (WS auth hook).
- paths.ts (141): cwdToProjectKeyCandidates + findActiveJsonl +
inferStatusFromJsonl — JSONL fallback inference for peers without
hooks installed or with stale hook signals.
- types.ts (111): WS protocol envelopes (hello/send/push/ack/error/
set_status), HookSetStatusRequest/Response, ConnectedPeer view.
- index.ts (323): HTTP on BROKER_PORT+1 for /hook/set-status + /health;
WebSocket on BROKER_PORT for authenticated peer connections with
hello/send/set_status handlers; connections registry; heartbeat
ping/pong every 30s; graceful SIGTERM/SIGINT that marks all active
presences disconnected.
Mesh scoping: every query/mutation includes meshId. Peer identity is
split between mesh.member (stable) and mesh.presence (ephemeral). WS
hello authenticates by pubkey against mesh.member (signature verify is
stubbed — libsodium wiring lands in client-side package later).
Broker never sees plaintext: nonce + ciphertext are opaque text fields
passed through. Routing happens on targetSpec (pubkey | "#channel" |
"tag:xyz" | "*"), resolved against currently-connected peers.
Dependencies not installed; no tests run. Verified via static review
of imports against @turbostarter/db exports.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
2026-04-04 21:32:14 +01:00 |
|