Skip to content

feat: cross-session message query with permission checks (#144)#145

Open
Jerry-Xin wants to merge 3 commits intodmwork-org:mainfrom
Jerry-Xin:feat/cross-session-search
Open

feat: cross-session message query with permission checks (#144)#145
Jerry-Xin wants to merge 3 commits intodmwork-org:mainfrom
Jerry-Xin:feat/cross-session-search

Conversation

@Jerry-Xin
Copy link
Copy Markdown
Collaborator

Summary

Implements cross-session message query capability for DMWork adapter, allowing bots to read message history from other channels with proper permission checks.

Changes

New modules:

  • permission.ts — Permission validation: owner=full access, DM=self only, group=member only
  • member-cache.ts — Group member cache with 5-min TTL + reverse index (uid → groups)
  • owner-registry.ts — Maps accountId → owner_uid for owner privilege checks
  • audit.ts — Structured audit logging for all cross-session queries

Modified:

  • actions.ts — Enhanced read with cross-channel permission checks, new search action (query=shared-groups), content truncation (500 chars), non-text type tags
  • channel.ts — Pass requesterSenderId to action handlers, describeMessageTool support, listActions now includes search, fix group-to-account race condition (Map<string, string>Map<string, Set<string>>)
  • types.ts — Shared LogSink type

Security

  • Uses framework-injected requesterSenderId (trusted, not from LLM)
  • DM: only self can read own DM with bot
  • Group: only current members can read group history
  • Owner: full access via owner-registry
  • Audit log on every cross-channel query

Tests

  • 342/342 passing
  • New: permission.test.ts (10), member-cache.test.ts (11), expanded actions.test.ts (54)

Closes #144

忻役 added 3 commits April 1, 2026 16:04
)

- Extend read action with requesterSenderId permission validation
- Add search action (query=shared-groups) for shared group discovery
- New modules: permission.ts, member-cache.ts, owner-registry.ts, audit.ts
- Pass requesterSenderId from handleAction to action handlers
- Startup preload of group member cache with reverse index
- Cross-channel results wrapped with prompt injection protection
- Content truncation (500 chars) and non-text type tags
- Structured audit logging for all cross-channel queries
- 342 tests passing (54 action tests, 10 permission, 11 cache)
…ork-org#144)

- Add describeMessageTool for new OpenClaw SDK compatibility
- Keep listActions for backward compatibility with older versions
- Extract getAvailableActions shared helper to avoid duplication
- Add messageToolHints for read (DM/group history) and search (shared-groups)
- 342 tests passing
Change _groupToAccount from Map<string, string> (last-write-wins) to
Map<string, Set<string>> to track all accounts per group.

When multiple bots share a group, resolveAccountForGroup now returns
undefined instead of a random winner, preserving the framework-provided
accountId. Only corrects when the current accountId is definitively not
registered for the group (single-bot groups).

Fixes cross-session send failures and DM read returning wrong bot's
messages in multi-account deployments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: cross-session message query (read permission + search shared-groups)

1 participant