4.5 KiB
4.5 KiB
Tasks: enterprise-message-bridge
Change ID: enterprise-message-bridge
Package: @suaveplan/message-bridge
Target path: universal/social/message-bridge
Prerequisite packages on Verdaccio: @suaveplan/error, @suaveplan/types, @suaveplan/events, @suaveplan/retry
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Scaffold
- Create
universal/social/message-bridge/withsrc/,tests/,src/__benchmarks__/and all feature subdirectories per the layout inproposal.md. - Write
package.jsonat version0.1.0with"type": "module","sideEffects": false, correctexportsmap,dependencies, anddevDependencies. - Write
tsconfig.jsonextending@suaveplan/typescript-config/library.json. - Write
vitest.config.tsusingcreateTestConfig()from@suaveplan/testing/config. - Add
lint,typecheck,test,test:coverage,build,docs:checkscripts.
2. Types + errors
src/types/common.ts—UnifiedMessage,MessageAttachment,SendOptions,AdapterSendOptions,MessageAdapter(interface),MessageBridgeOptions,RouteRule.src/types/common.md(≥200 words, both examples, API reference).src/error-codes.ts—MessageBridgeErrorCode(6 codes), metadata, register, eager call.src/types/schemas.ts+schemas.md— Zod schemas.
3. Core modules
src/core/deduplicator/—Deduplicator(windowMs): tracks aMap<key, expiresAt>;isDuplicate(key)returns true if key was seen within window and not expired;record(key)adds entry withnow + windowMsexpiry;purge()removes expired entries (called on eachisDuplicatecheck). Tests: first occurrence not duplicate, second within window is duplicate, after window expires not duplicate,windowMs=0always not duplicate.src/routing/route-rules/—applyRoutes(bridge, rules): subscribes tobridge.on('message', ...), matches rules byfromPlatform, callsbridge.sendtotoPlatformwith optional transform; returns unsubscribe function. Tests: message from matching platform is forwarded, non-matching platform skipped, transform applied, unsubscribe stops forwarding.src/core/message-bridge/—MessageBridge:register(adapter)adds to internal map;start(signal)iterates registered adapters and starts each (async generators) funnelled into a shared queue; on inbound message, checksDeduplicator; if new, emits viabusand callson('message')listeners.send(options, text)looks up adapter byoptions.platform, callsadapter.send. Tests: register/unregister, send to registered platform, send to unknown platform throws, deduplication suppresses second occurrence, start/stop via AbortSignal, route forwarding end-to-end with stub adapters.
4. OTel instrumentation
- Counter
message_bridge.inbound_totalwith attributemessage_bridge.platformon each new inbound message. - Counter
message_bridge.outbound_totalwith same attribute on each send. - Histogram
message_bridge.send_duration_ms.
5. Property-based tests (tests/property.test.ts)
- Deduplication: for arbitrary sequences of
(key, timestamp)pairs with a fixed window, the deduplicator correctly reports duplicate status consistent with the window boundary.
6. Benchmarks (src/__benchmarks__/message-bridge.bench.ts)
Deduplicator.isDuplicatefor 100 000 unique keys.
7. Docs + verify
- One
.mdper implementation file (≥200 words, both examples, API reference). RootREADME.md. bunx turbo lint typecheck test --filter=@suaveplan/message-bridge— green.bunx turbo test:coverage --filter=@suaveplan/message-bridge— 100%.bun scripts/publish.ts --package @suaveplan/message-bridge.- Archive:
openspec/archive/2026-04-24-enterprise-message-bridge/.