# Notes: Multi-Bot Multi-Workspace Planning

## Current-State Findings

- `im_channels` is currently seeded as three fixed records: `feishu`, `telegram`, `discord`.
- `channel_bindings.channel_id` exists as a foreign key, but routing code often queries bindings with `msg.channelType`.
- The effective routing key today is `channelType + chatId`.
- New session workspace selection currently uses:
  - existing binding workspace
  - global setting `bridge_default_work_dir`
  - most recently opened workspace
- The actual Claude execution directory is derived from `sessions.workspace -> workspaces.path`.

## Current Constraints

- UI assumes one page per platform, not a dynamic list of bot instances.
- API assumes one channel record per platform.
- Session lock key uses `channelType:chatId`, so multiple bots of the same platform would collide.
- Existing data model supports chat-level workspace switching, but not bot-instance defaults.

## Target Direction

- Treat each IM bot as an `im_channels` instance row.
- Route by `channelId + chatId`.
- Add bot-level defaults such as `default_workspace_id`.
- Preserve chat-level overrides via `channel_bindings`.
- Keep conversation/session/message persistence model intact.
