Files
2026-05-27 23:29:53 +01:00

3.2 KiB

Tasks: enterprise-api-plugin-messaging

Change ID: enterprise-api-plugin-messaging Package: @suaveplan/api-plugin-messaging Target path: api/comms/api-plugin-messaging Prerequisite packages on Verdaccio: @suaveplan/api, @suaveplan/api-shared, @suaveplan/api-plugin-auth, @suaveplan/api-plugin-database, @suaveplan/api-plugin-file-upload, @suaveplan/api-plugin-notifications, @suaveplan/suppression, @suaveplan/events, @suaveplan/rate-limiter, @suaveplan/error


0. Pre-flight (non-negotiable)

  • 0.1 Confirm clean working tree (git status reports nothing) and no in-flight worktrees with uncommitted work (git worktree list then git status in 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.md matches find packages -maxdepth 3 -name package.json count. Drift here means a prior change archived without regenerating the manifest.

1. Scaffold + types + errors + events

  • Create api/comms/api-plugin-messaging/; package.json v0.0.0; standard tooling.
  • Types: Thread, ThreadParticipant, Message, Reaction, ReadReceipt, MessagingPluginConfig (Zod).
  • Errors: 6-code union + metadata + registration. Test + doc.
  • Events: MessagingEventMap (messaging:message:sent, messaging:thread:created, messaging:message:deleted, messaging:reaction:added).

2. SurrealQL

  • thread.surql, thread_participant.surql, message.surql, reaction.surql, read_receipt.surql. tenantId indexes; full-text on message content.

3. Services (each .test.ts + .md)

  • ThreadService: createThread (1:1 or group), getThread, listThreads, addParticipant, removeParticipant.
  • MessageService: sendMessage (check suppression list), editMessage, deleteMessage, listMessages (paginated), markRead. Rate-limit on send. Notify via api-plugin-notifications on unread message.
  • ReactionService: addReaction, removeReaction, listReactions.
  • ModerationService: flagMessage, deleteMessageAdmin, banParticipant.

4. Routes

  • GET/POST /messaging/threads — requireAuth.
  • GET /messaging/threads/:id, GET/POST /messaging/threads/:id/messages — requireAuth.
  • POST /messaging/threads/:id/read — requireAuth.
  • POST /messaging/threads/:id/reactions — requireAuth + rate-limit.
  • Route .test.ts + .md.

5. Plugin factory + integration tests + publish

  • createMessagingPlugin: definePlugin, dependencies: ["database", "auth"], migrationsPath: "./surql".
  • Integration: create thread → send message → read receipt → notification triggered (real SurrealDB).
  • bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-messaging — green; 100% coverage.
  • bun scripts/publish.ts --package @suaveplan/api-plugin-messaging.
  • Archive → openspec/archive/2026-04-24-enterprise-api-plugin-messaging/.