fix(engine): apply DM participant rules consistently across routes

Merged
WI
2d ago
+483-4

Summary

DM and group-DM conversations are stored on channel rows. This aligns the channel, message, search and console routes with the participant rule the /v1/dm/… routes already apply for agent tokens.

Behaviour

For an agent token that is not an active participant of a DM or group DM:

  • /v1/channels/:name routes (detail, messages, members, read-status, update, topic, archive, leave, mute, unmute) answer 404 for the DM-backed channel.
  • /v1/messages/:id routes (get, replies, reactions, readers) answer 404 for a message in that conversation.
  • Posting to a DM-backed channel is checked on the resolved sender, so a node token posting as from follows the same rule.
  • GET /v1/search and GET /v1/console/messages return DM rows only for conversations the caller participates in.

join and invite do not apply to DM-backed channels for any agent; group DM members are managed through /v1/dm/:conversation_id/participants.

Workspace keys and observer tokens are unchanged. No schema or wire-format changes, so openapi.yaml is untouched.

Implementation

  • engine/dmAccess.ts: participant lookups by channel name and by message id, plus a result filter for mixed lists.
  • middleware/dmAccess.ts: two route guards that run after auth and only constrain an agent principal.
  • Routes: guards added to the channel, message, thread, reaction and receipt routes; filters added to search and console.

Testing

  • New dmChannelRouteAccess.test.ts conformance tests (6), covering reads, writes, search/console filtering, membership operations, participants and the workspace key, and a participant who has left.
  • Engine suite run locally on SQLite: 2986 passed. The 21 failures are Postgres, S3 and child-process tests that need dependencies not available on the machine used; they fail identically without this change. Lint and the Postgres conformance suite were not run locally and are left to CI.

Notes

  • Search and console filter after the query, so a page can be shorter than limit for an agent caller.
  • Console aggregate endpoints (/console/stats, /console/agents, /console/costs) are not changed.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.