Initial commit
This commit is contained in:
@@ -0,0 +1,312 @@
|
||||
# Architecture
|
||||
|
||||
## Goal
|
||||
|
||||
Build an Emacs client for corporate Mattermost, inspired by the UX of telega.el.
|
||||
|
||||
Target Mattermost server version: 10.9.3.
|
||||
|
||||
The project is intentionally split into a thin Emacs UI and a long-lived Rust bridge.
|
||||
|
||||
## High-level components
|
||||
|
||||
Emacs Lisp package:
|
||||
|
||||
- user commands;
|
||||
- buffers;
|
||||
- keybindings;
|
||||
- faces;
|
||||
- message composition;
|
||||
- display-only projections of server state.
|
||||
|
||||
Rust bridge:
|
||||
|
||||
- TCP JSON Lines server for Emacs;
|
||||
- Mattermost REST API client;
|
||||
- Mattermost WebSocket client;
|
||||
- authentication/session handling;
|
||||
- token cache;
|
||||
- online event fanout;
|
||||
- forced refresh/reconnect support;
|
||||
- web status UI.
|
||||
|
||||
Docker Compose:
|
||||
|
||||
- primary way to run the bridge;
|
||||
- bridge is started separately from Emacs;
|
||||
- Emacs only connects to an already running bridge.
|
||||
|
||||
## Source of truth
|
||||
|
||||
Mattermost server is the single source of truth.
|
||||
|
||||
The bridge may keep temporary operational state and cache files.
|
||||
|
||||
Emacs buffers are not authoritative storage. They are projections that can be rebuilt from the server.
|
||||
|
||||
## Transport
|
||||
|
||||
Emacs connects to the bridge over localhost TCP.
|
||||
|
||||
Protocol format:
|
||||
|
||||
- one JSON object per line;
|
||||
- UTF-8;
|
||||
- request/response correlation by id;
|
||||
- asynchronous events from bridge to Emacs.
|
||||
|
||||
Default planned address:
|
||||
|
||||
127.0.0.1:8765
|
||||
|
||||
Logs must not be mixed into the protocol stream.
|
||||
|
||||
## Server-scoped model
|
||||
|
||||
MVP implements one active Mattermost connection, but the architecture must be multiserver-ready.
|
||||
|
||||
All domain objects and requests must be scoped by server identity from the beginning.
|
||||
|
||||
Planned identifiers:
|
||||
|
||||
- ServerId;
|
||||
- TeamId;
|
||||
- ChannelId;
|
||||
- UserId;
|
||||
- PostId.
|
||||
|
||||
Direct messages must eventually show server/team context in buffer names and UI labels.
|
||||
|
||||
Examples:
|
||||
|
||||
*Mattermost[work]/DM:self*
|
||||
*Mattermost[work]/team:dev/DM:alice*
|
||||
*Mattermost[other]/team:platform/DM:alice*
|
||||
|
||||
This avoids confusion between identical usernames on different servers or teams.
|
||||
|
||||
## MVP vertical slice
|
||||
|
||||
The first working flow is self-DM:
|
||||
|
||||
1. start bridge with Docker Compose;
|
||||
2. connect Emacs to bridge;
|
||||
3. authenticate to Mattermost;
|
||||
4. resolve current user;
|
||||
5. open/create direct channel to self;
|
||||
6. load history;
|
||||
7. display raw messages;
|
||||
8. send message;
|
||||
9. receive online update through WebSocket;
|
||||
10. force refresh with g.
|
||||
|
||||
Channel UI comes after self-DM works.
|
||||
|
||||
## Online updates
|
||||
|
||||
Open buffers must update online from bridge events.
|
||||
|
||||
The bridge owns WebSocket connection management.
|
||||
|
||||
Emacs should not talk directly to Mattermost REST or WebSocket APIs.
|
||||
|
||||
## Forced refresh with g
|
||||
|
||||
In Mattermost buffers, g means:
|
||||
|
||||
1. ask bridge to check connection health;
|
||||
2. reconnect WebSocket if needed;
|
||||
3. refetch current buffer data from Mattermost REST API;
|
||||
4. replace buffer contents from server state;
|
||||
5. preserve unsent input where possible.
|
||||
|
||||
g is a recovery action, not just a local redraw.
|
||||
|
||||
## Threads and replies
|
||||
|
||||
Replies/threads should be separate buffers by default.
|
||||
|
||||
This must be configurable from use-package.
|
||||
|
||||
Planned option:
|
||||
|
||||
mattermost-thread-display
|
||||
|
||||
Allowed values:
|
||||
|
||||
separate-buffer
|
||||
inline
|
||||
|
||||
MVP implements separate-buffer first.
|
||||
|
||||
inline is kept as a future-compatible option.
|
||||
|
||||
## Message rendering
|
||||
|
||||
MVP displays message text as-is.
|
||||
|
||||
No Markdown rendering in MVP.
|
||||
|
||||
Later rendering must preserve raw message text for editing and server synchronization.
|
||||
|
||||
## Authentication
|
||||
|
||||
MVP supports:
|
||||
|
||||
- login/password;
|
||||
- saved session token;
|
||||
- PAT token.
|
||||
|
||||
Token cache is a separate plain file for MVP.
|
||||
|
||||
Password may be read from ~/.authinfo.
|
||||
|
||||
Strong secret protection is postponed, but logs must never print tokens or passwords.
|
||||
|
||||
Docker deployment must avoid leaking secrets through logs or environment dumps.
|
||||
|
||||
## TLS and self-signed certificates
|
||||
|
||||
Corporate Mattermost may use self-signed or internal CA certificates.
|
||||
|
||||
Bridge TLS policy:
|
||||
|
||||
- do not disable certificate verification by default;
|
||||
- support explicit CA file configuration;
|
||||
- document Docker CA mount;
|
||||
- produce clear TLS error messages.
|
||||
|
||||
Emacs-side TLS settings are separate from bridge TLS settings.
|
||||
|
||||
User currently has Emacs workaround settings:
|
||||
|
||||
(setq gnutls-verify-error nil)
|
||||
(setq tls-checksig-warn-clock-skew t)
|
||||
(setq gnutls-trustfiles '("/etc/ssl/certs/ca-certificates.crt"))
|
||||
|
||||
These settings do not affect Rust bridge TLS validation.
|
||||
|
||||
## Crate boundaries
|
||||
|
||||
mm-core:
|
||||
|
||||
- domain types;
|
||||
- identifiers;
|
||||
- normalized models;
|
||||
- shared errors;
|
||||
- no network code.
|
||||
|
||||
mm-client:
|
||||
|
||||
- Mattermost REST client;
|
||||
- Mattermost WebSocket client;
|
||||
- authentication calls;
|
||||
- TLS configuration;
|
||||
- reconnect support.
|
||||
|
||||
mm-store:
|
||||
|
||||
- session token cache;
|
||||
- PAT cache;
|
||||
- lightweight metadata cache;
|
||||
- server-scoped storage paths.
|
||||
|
||||
mm-bridge:
|
||||
|
||||
- main daemon;
|
||||
- TCP JSONL server;
|
||||
- request routing;
|
||||
- app state;
|
||||
- connection manager;
|
||||
- event fanout;
|
||||
- forced refresh handling.
|
||||
|
||||
mm-web:
|
||||
|
||||
- web status UI;
|
||||
- health endpoint;
|
||||
- status endpoint;
|
||||
- simple HTML page;
|
||||
- no secrets in responses.
|
||||
|
||||
## Emacs module boundaries
|
||||
|
||||
mattermost.el:
|
||||
|
||||
- entry point;
|
||||
- autoloaded commands;
|
||||
- high-level orchestration.
|
||||
|
||||
mattermost-custom.el:
|
||||
|
||||
- defgroup;
|
||||
- defcustom options.
|
||||
|
||||
mattermost-process.el:
|
||||
|
||||
- TCP process lifecycle;
|
||||
- reconnect to bridge;
|
||||
- process filter/sentinel.
|
||||
|
||||
mattermost-protocol.el:
|
||||
|
||||
- JSONL encoding/decoding;
|
||||
- request ids;
|
||||
- pending callbacks;
|
||||
- event dispatch.
|
||||
|
||||
mattermost-server.el:
|
||||
|
||||
- server connection model;
|
||||
- server-scoped command routing.
|
||||
|
||||
mattermost-model.el:
|
||||
|
||||
- local display models;
|
||||
- server/team/channel/user/post structs.
|
||||
|
||||
mattermost-buffer.el:
|
||||
|
||||
- common buffer behavior;
|
||||
- refresh command;
|
||||
- buffer-local state.
|
||||
|
||||
mattermost-dm.el:
|
||||
|
||||
- self-DM flow;
|
||||
- direct message buffers.
|
||||
|
||||
mattermost-channel.el:
|
||||
|
||||
- channel list;
|
||||
- channel buffers.
|
||||
|
||||
mattermost-thread.el:
|
||||
|
||||
- thread buffers;
|
||||
- reply flow.
|
||||
|
||||
mattermost-compose.el:
|
||||
|
||||
- message input;
|
||||
- send keybindings.
|
||||
|
||||
mattermost-faces.el:
|
||||
|
||||
- faces.
|
||||
|
||||
mattermost-utils.el:
|
||||
|
||||
- small shared helpers.
|
||||
|
||||
## Non-goals for MVP
|
||||
|
||||
- full multiserver UI;
|
||||
- typing indicators;
|
||||
- reactions;
|
||||
- Markdown rendering;
|
||||
- file upload/download;
|
||||
- search;
|
||||
- offline-first storage;
|
||||
- admin functions;
|
||||
- starting Docker from Emacs.
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
# Docker Runtime
|
||||
|
||||
## Decision
|
||||
|
||||
Docker Compose is the primary way to run the Rust bridge.
|
||||
|
||||
Emacs does not start containers.
|
||||
|
||||
The user starts the bridge separately, then Emacs connects to it over localhost TCP.
|
||||
|
||||
## Planned ports
|
||||
|
||||
Bridge JSONL TCP port:
|
||||
|
||||
8765
|
||||
|
||||
Web status HTTP port:
|
||||
|
||||
8766
|
||||
|
||||
Planned local bindings:
|
||||
|
||||
127.0.0.1:8765:8765
|
||||
127.0.0.1:8766:8766
|
||||
|
||||
The bridge should not be exposed publicly by default.
|
||||
|
||||
## Planned compose usage
|
||||
|
||||
Start:
|
||||
|
||||
docker compose up -d --build
|
||||
|
||||
Stop:
|
||||
|
||||
docker compose down
|
||||
|
||||
Logs:
|
||||
|
||||
docker compose logs -f mm-bridge
|
||||
|
||||
Status page:
|
||||
|
||||
http://127.0.0.1:8766/
|
||||
|
||||
Health endpoint:
|
||||
|
||||
http://127.0.0.1:8766/health
|
||||
|
||||
Status JSON:
|
||||
|
||||
http://127.0.0.1:8766/status
|
||||
|
||||
## Planned volumes
|
||||
|
||||
Persistent bridge data:
|
||||
|
||||
./data:/data
|
||||
|
||||
Purpose:
|
||||
|
||||
- session token cache;
|
||||
- PAT cache;
|
||||
- lightweight metadata;
|
||||
- future cache files.
|
||||
|
||||
MVP token files are plain files without encryption.
|
||||
|
||||
They must not be committed to git.
|
||||
|
||||
## Planned environment variables
|
||||
|
||||
Bridge listen address:
|
||||
|
||||
MM_BRIDGE_LISTEN=0.0.0.0:8765
|
||||
|
||||
Web listen address:
|
||||
|
||||
MM_WEB_LISTEN=0.0.0.0:8766
|
||||
|
||||
Data directory:
|
||||
|
||||
MM_DATA_DIR=/data
|
||||
|
||||
Default Mattermost URL:
|
||||
|
||||
MM_SERVER_URL=https://mattermost.example.local
|
||||
|
||||
Default server id:
|
||||
|
||||
MM_SERVER_ID=work
|
||||
|
||||
Optional CA file inside container:
|
||||
|
||||
MM_CA_FILE=/certs/company-ca.crt
|
||||
|
||||
Optional PAT file path:
|
||||
|
||||
MM_TOKEN_FILE=/data/tokens/work.token
|
||||
|
||||
Do not put passwords directly into compose.yaml.
|
||||
|
||||
Do not print environment variables wholesale in logs.
|
||||
|
||||
## Self-signed / internal CA
|
||||
|
||||
Mount CA certificate read-only:
|
||||
|
||||
./certs/company-ca.crt:/certs/company-ca.crt:ro
|
||||
|
||||
Then set:
|
||||
|
||||
MM_CA_FILE=/certs/company-ca.crt
|
||||
|
||||
The Rust bridge must validate certificates by default.
|
||||
|
||||
Disabling verification globally is not the default design.
|
||||
|
||||
Emacs TLS settings do not affect bridge TLS validation.
|
||||
|
||||
## Secrets
|
||||
|
||||
MVP allows plain token cache files under ./data.
|
||||
|
||||
Still required:
|
||||
|
||||
- ignore ./data in git;
|
||||
- ignore secrets in docker build context;
|
||||
- never log tokens;
|
||||
- never expose tokens in web status;
|
||||
- avoid putting passwords in compose.yaml.
|
||||
|
||||
Password may come from Emacs ~/.authinfo and be sent to bridge in connect request.
|
||||
|
||||
The bridge must not log the connect request body.
|
||||
|
||||
## Future scripts
|
||||
|
||||
Planned scripts:
|
||||
|
||||
scripts/docker-build.sh
|
||||
scripts/docker-up.sh
|
||||
scripts/docker-down.sh
|
||||
|
||||
They will be implemented after the minimal bridge compiles and responds to ping/status.
|
||||
|
||||
## Current status
|
||||
|
||||
Docker files are placeholders until the Rust bridge skeleton is implemented.
|
||||
@@ -0,0 +1,284 @@
|
||||
# Mattermost 10.9.3 Notes
|
||||
|
||||
## Target server
|
||||
|
||||
Target Mattermost server version: 10.9.3.
|
||||
|
||||
All MVP implementation must be verified against this version.
|
||||
|
||||
## REST base path
|
||||
|
||||
/api/v4
|
||||
|
||||
## Authentication
|
||||
|
||||
Login endpoint:
|
||||
|
||||
POST /api/v4/users/login
|
||||
|
||||
Request body:
|
||||
|
||||
{
|
||||
"login_id": "user@example.local",
|
||||
"password": "secret"
|
||||
}
|
||||
|
||||
Successful login returns:
|
||||
|
||||
- user object in response body;
|
||||
- session token in Token response header.
|
||||
|
||||
Future requests use:
|
||||
|
||||
Authorization: Bearer <token>
|
||||
|
||||
PAT uses the same bearer header.
|
||||
|
||||
MVP supports:
|
||||
|
||||
- login/password;
|
||||
- saved session token;
|
||||
- PAT.
|
||||
|
||||
MFA is not part of MVP unless required by the target server.
|
||||
|
||||
## Current user
|
||||
|
||||
GET /api/v4/users/me
|
||||
|
||||
The string me can be used instead of current user id in relevant endpoints.
|
||||
|
||||
## Teams
|
||||
|
||||
Planned endpoint:
|
||||
|
||||
GET /api/v4/users/me/teams
|
||||
|
||||
Used by bridge method:
|
||||
|
||||
teams
|
||||
|
||||
## Channels
|
||||
|
||||
Planned endpoints:
|
||||
|
||||
GET /api/v4/users/{user_id}/teams/{team_id}/channels
|
||||
GET /api/v4/channels/{channel_id}
|
||||
GET /api/v4/channels/{channel_id}/posts
|
||||
|
||||
Direct channel creation:
|
||||
|
||||
POST /api/v4/channels/direct
|
||||
|
||||
Request body:
|
||||
|
||||
["user_id_1", "user_id_2"]
|
||||
|
||||
For self-DM MVP:
|
||||
|
||||
["my_user_id", "my_user_id"]
|
||||
|
||||
This must be tested on Mattermost 10.9.3.
|
||||
|
||||
If self-DM creation is rejected by the server, fallback behavior must be decided explicitly before changing MVP scope.
|
||||
|
||||
## Posts
|
||||
|
||||
Create post:
|
||||
|
||||
POST /api/v4/posts
|
||||
|
||||
Request body:
|
||||
|
||||
{
|
||||
"channel_id": "channel-id",
|
||||
"message": "raw text",
|
||||
"root_id": ""
|
||||
}
|
||||
|
||||
Reply in thread:
|
||||
|
||||
{
|
||||
"channel_id": "channel-id",
|
||||
"message": "reply text",
|
||||
"root_id": "root-post-id"
|
||||
}
|
||||
|
||||
MVP sends raw text.
|
||||
|
||||
No Markdown rendering in Emacs MVP.
|
||||
|
||||
## History normalization
|
||||
|
||||
Mattermost channel posts response commonly contains:
|
||||
|
||||
- order: array of post ids;
|
||||
- posts: map from post id to post object.
|
||||
|
||||
Bridge must normalize this into an ordered posts array.
|
||||
|
||||
Display order for Emacs:
|
||||
|
||||
ascending by create_at
|
||||
|
||||
Pagination:
|
||||
|
||||
before_id
|
||||
limit
|
||||
|
||||
MVP can start with latest N posts.
|
||||
|
||||
## Mark read
|
||||
|
||||
Planned endpoint:
|
||||
|
||||
POST /api/v4/channels/view
|
||||
|
||||
Request body:
|
||||
|
||||
{
|
||||
"channel_id": "channel-id"
|
||||
}
|
||||
|
||||
Exact response shape must be verified during implementation.
|
||||
|
||||
Bridge method:
|
||||
|
||||
mark_read
|
||||
|
||||
## WebSocket
|
||||
|
||||
Endpoint:
|
||||
|
||||
/api/v4/websocket
|
||||
|
||||
Authentication challenge:
|
||||
|
||||
{
|
||||
"seq": 1,
|
||||
"action": "authentication_challenge",
|
||||
"data": {
|
||||
"token": "mattermosttokengoeshere"
|
||||
}
|
||||
}
|
||||
|
||||
Successful response:
|
||||
|
||||
{
|
||||
"status": "OK",
|
||||
"seq_reply": 1
|
||||
}
|
||||
|
||||
After authentication, server sends hello event.
|
||||
|
||||
Event envelope:
|
||||
|
||||
{
|
||||
"event": "posted",
|
||||
"data": {},
|
||||
"broadcast": {},
|
||||
"seq": 0
|
||||
}
|
||||
|
||||
## WebSocket events for MVP
|
||||
|
||||
Important:
|
||||
|
||||
hello
|
||||
posted
|
||||
post_edited
|
||||
post_deleted
|
||||
channel_viewed
|
||||
channel_updated
|
||||
|
||||
Ignored for MVP:
|
||||
|
||||
typing
|
||||
reaction_added
|
||||
reaction_removed
|
||||
|
||||
The bridge may log ignored event names at debug level, but must not fail on unknown events.
|
||||
|
||||
## posted event
|
||||
|
||||
The posted event usually contains a JSON-encoded post string inside data.post.
|
||||
|
||||
Bridge must parse it defensively:
|
||||
|
||||
- data.post may be a string containing JSON;
|
||||
- parse failure should produce a structured internal warning;
|
||||
- do not crash the WebSocket loop.
|
||||
|
||||
## Reconnect
|
||||
|
||||
WebSocket reconnect is owned by bridge.
|
||||
|
||||
On reconnect:
|
||||
|
||||
1. reopen WebSocket;
|
||||
2. authenticate;
|
||||
3. wait for hello or OK;
|
||||
4. mark connection healthy;
|
||||
5. emit websocket_connected;
|
||||
6. trigger resync for open buffers if needed.
|
||||
|
||||
Mattermost server remains source of truth.
|
||||
|
||||
Do not rely only on missed WebSocket events for correctness.
|
||||
|
||||
## Forced refresh
|
||||
|
||||
Emacs g triggers bridge forced refresh.
|
||||
|
||||
Bridge should:
|
||||
|
||||
- check REST availability;
|
||||
- check WebSocket health;
|
||||
- reconnect if needed;
|
||||
- refetch requested buffer data;
|
||||
- return fresh server state.
|
||||
|
||||
## Rate limits
|
||||
|
||||
Mattermost may return:
|
||||
|
||||
429 Too Many Requests
|
||||
|
||||
Headers may include:
|
||||
|
||||
X-Ratelimit-Limit
|
||||
X-Ratelimit-Remaining
|
||||
X-Ratelimit-Reset
|
||||
|
||||
Bridge should map this to:
|
||||
|
||||
rate_limited
|
||||
|
||||
MVP can surface the error without sophisticated retry scheduling.
|
||||
|
||||
## Error shape
|
||||
|
||||
Mattermost API errors commonly look like:
|
||||
|
||||
{
|
||||
"id": "the.error.id",
|
||||
"message": "Something went wrong",
|
||||
"request_id": "",
|
||||
"status_code": 400
|
||||
}
|
||||
|
||||
Bridge must normalize errors and never leak auth headers.
|
||||
|
||||
## Verification tasks
|
||||
|
||||
During implementation, verify on target server:
|
||||
|
||||
- login/password works;
|
||||
- Token header is returned;
|
||||
- saved session token works after restart;
|
||||
- PAT works if enabled;
|
||||
- self-DM channel can be created/opened;
|
||||
- posting to self-DM works;
|
||||
- posted event arrives for own messages;
|
||||
- mark_read endpoint works;
|
||||
- internal CA configuration works from Docker.
|
||||
@@ -0,0 +1,137 @@
|
||||
# MVP Checklist
|
||||
|
||||
## Fixed decisions
|
||||
|
||||
- [x] Emacs Lisp UI.
|
||||
- [x] Rust bridge.
|
||||
- [x] Docker Compose as primary bridge runtime.
|
||||
- [x] Emacs does not start Docker.
|
||||
- [x] TCP JSONL transport.
|
||||
- [x] Web status UI planned.
|
||||
- [x] Mattermost 10.9.3 target.
|
||||
- [x] Mattermost server is source of truth.
|
||||
- [x] Emacs buffers are display-only.
|
||||
- [x] MVP starts with self-DM.
|
||||
- [x] Raw message text, no Markdown rendering.
|
||||
- [x] Threads separate buffers by default, configurable.
|
||||
- [x] g means forced refresh and connection recovery.
|
||||
- [x] Multiserver architecture planned, not implemented in MVP.
|
||||
- [x] Typing not in MVP.
|
||||
- [x] Reactions not in MVP.
|
||||
- [x] Login/password and session/PAT token only.
|
||||
- [x] Plain token cache file for MVP.
|
||||
- [x] Explicit CA configuration for self-signed/internal CA.
|
||||
|
||||
## Phase 0 — repository bootstrap
|
||||
|
||||
- [x] Create repository tree script.
|
||||
- [x] Create README.
|
||||
- [x] Create .gitignore.
|
||||
- [x] Create .dockerignore.
|
||||
- [x] Create architecture doc.
|
||||
- [x] Create protocol doc.
|
||||
- [x] Create Docker doc.
|
||||
- [x] Create TLS doc.
|
||||
- [x] Create Mattermost 10.9.3 notes.
|
||||
- [x] Create MVP checklist.
|
||||
|
||||
## Phase 1 — minimal Rust bridge
|
||||
|
||||
- [ ] Add Cargo workspace.
|
||||
- [ ] Add crate manifests.
|
||||
- [ ] Add minimal mm-core types.
|
||||
- [ ] Add JSONL protocol types.
|
||||
- [ ] Add TCP listener.
|
||||
- [ ] Implement ping.
|
||||
- [ ] Implement status.
|
||||
- [ ] Add smoke test for ping.
|
||||
|
||||
## Phase 2 — Docker and status web UI
|
||||
|
||||
- [ ] Add Dockerfile.
|
||||
- [ ] Add compose.yaml.
|
||||
- [ ] Add bridge config from environment.
|
||||
- [ ] Add /health.
|
||||
- [ ] Add /status JSON.
|
||||
- [ ] Add simple HTML status page.
|
||||
- [ ] Verify bridge runs separately from Emacs.
|
||||
|
||||
## Phase 3 — authentication
|
||||
|
||||
- [ ] Implement login/password against Mattermost 10.9.3.
|
||||
- [ ] Save session token to cache file.
|
||||
- [ ] Load saved session token.
|
||||
- [ ] Support PAT token.
|
||||
- [ ] Implement connect.
|
||||
- [ ] Implement me.
|
||||
- [ ] Ensure tokens are never logged.
|
||||
|
||||
## Phase 4 — self-DM vertical slice
|
||||
|
||||
- [ ] Implement teams.
|
||||
- [ ] Resolve current user.
|
||||
- [ ] Create/get self direct channel.
|
||||
- [ ] Implement open_self_dm.
|
||||
- [ ] Implement get_history.
|
||||
- [ ] Implement send_post.
|
||||
- [ ] Connect Emacs to bridge.
|
||||
- [ ] Open self-DM buffer.
|
||||
- [ ] Display raw messages.
|
||||
- [ ] Send message from Emacs.
|
||||
- [ ] Receive own message online.
|
||||
|
||||
## Phase 5 — WebSocket online updates
|
||||
|
||||
- [ ] Open Mattermost WebSocket.
|
||||
- [ ] Authenticate with authentication_challenge.
|
||||
- [ ] Handle hello.
|
||||
- [ ] Handle posted.
|
||||
- [ ] Handle post_edited.
|
||||
- [ ] Handle post_deleted.
|
||||
- [ ] Fan out normalized events to Emacs.
|
||||
- [ ] Update open self-DM buffer online.
|
||||
- [ ] Add reconnect loop.
|
||||
- [ ] Implement forced refresh path for g.
|
||||
|
||||
## Phase 6 — replies/threads
|
||||
|
||||
- [ ] Implement reply_post.
|
||||
- [ ] Add thread buffer.
|
||||
- [ ] Add mattermost-thread-display.
|
||||
- [ ] Default to separate thread buffers.
|
||||
- [ ] Keep inline mode as future-compatible option.
|
||||
- [ ] Show server/team context in thread buffer names.
|
||||
|
||||
## Phase 7 — channels
|
||||
|
||||
- [ ] Implement list_channels.
|
||||
- [ ] Add channel list buffer.
|
||||
- [ ] Open channel buffer.
|
||||
- [ ] Load channel history.
|
||||
- [ ] Send channel message.
|
||||
- [ ] Receive channel events online.
|
||||
- [ ] Implement mark_read.
|
||||
- [ ] Forced refresh with g.
|
||||
|
||||
## Phase 8 — TLS/self-signed support
|
||||
|
||||
- [ ] Add explicit CA file configuration.
|
||||
- [ ] Document Docker CA mount.
|
||||
- [ ] Document Emacs CA settings separately.
|
||||
- [ ] Do not disable certificate verification by default in Rust bridge.
|
||||
- [ ] Add clear error message for TLS failures.
|
||||
|
||||
## Phase 9 — hardening
|
||||
|
||||
- [ ] Add structured errors.
|
||||
- [ ] Add request timeouts.
|
||||
- [ ] Add rate-limit handling.
|
||||
- [ ] Add basic integration smoke tests.
|
||||
- [ ] Add Emacs Lisp tests.
|
||||
- [ ] Review logs for secret leaks.
|
||||
- [ ] Review cache file permissions.
|
||||
- [ ] Review multiserver-ready identifiers and naming.
|
||||
|
||||
## Next atomic step
|
||||
|
||||
Add Rust workspace and minimal compiling bridge with ping/status over TCP JSONL.
|
||||
@@ -0,0 +1,572 @@
|
||||
# Emacs ↔ Bridge Protocol
|
||||
|
||||
## Transport
|
||||
|
||||
Localhost TCP.
|
||||
|
||||
Default planned address:
|
||||
|
||||
127.0.0.1:8765
|
||||
|
||||
Framing:
|
||||
|
||||
- UTF-8;
|
||||
- one JSON object per line;
|
||||
- newline delimiter;
|
||||
- no pretty-printed multi-line JSON;
|
||||
- no logs in protocol stream.
|
||||
|
||||
## Message kinds
|
||||
|
||||
Request from Emacs to bridge:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "ping",
|
||||
"params": {}
|
||||
}
|
||||
|
||||
Response from bridge to Emacs:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"pong": true
|
||||
}
|
||||
}
|
||||
|
||||
Error response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": false,
|
||||
"error": {
|
||||
"code": "invalid_request",
|
||||
"message": "Missing method",
|
||||
"retryable": false
|
||||
}
|
||||
}
|
||||
|
||||
Event from bridge to Emacs:
|
||||
|
||||
{
|
||||
"type": "event",
|
||||
"event": "post_created",
|
||||
"server_id": "work",
|
||||
"data": {}
|
||||
}
|
||||
|
||||
## Request rules
|
||||
|
||||
Every request has:
|
||||
|
||||
- id: string;
|
||||
- type: "request";
|
||||
- method: string;
|
||||
- params: object.
|
||||
|
||||
The bridge must respond to every request exactly once.
|
||||
|
||||
The bridge must preserve request id in the response.
|
||||
|
||||
Unknown methods return invalid_request or unknown_method error.
|
||||
|
||||
Malformed JSON returns invalid_json error.
|
||||
|
||||
## Response rules
|
||||
|
||||
Every response has:
|
||||
|
||||
- id: same as request id;
|
||||
- type: "response";
|
||||
- ok: boolean;
|
||||
- result: object when ok is true;
|
||||
- error: object when ok is false.
|
||||
|
||||
Error object:
|
||||
|
||||
- code: stable machine-readable string;
|
||||
- message: human-readable string;
|
||||
- retryable: boolean.
|
||||
|
||||
## Event rules
|
||||
|
||||
Events have no request id.
|
||||
|
||||
Events are asynchronous.
|
||||
|
||||
Events must include server_id once multiserver-ready routing is active.
|
||||
|
||||
MVP may use a configured default server id such as "default".
|
||||
|
||||
Events must not contain tokens, passwords, or raw Authorization headers.
|
||||
|
||||
## MVP methods
|
||||
|
||||
Required MVP methods:
|
||||
|
||||
ping
|
||||
status
|
||||
connect
|
||||
me
|
||||
teams
|
||||
list_channels
|
||||
get_history
|
||||
send_post
|
||||
reply_post
|
||||
mark_read
|
||||
|
||||
Additional helper for first vertical slice:
|
||||
|
||||
open_self_dm
|
||||
|
||||
## ping
|
||||
|
||||
Request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "ping",
|
||||
"params": {}
|
||||
}
|
||||
|
||||
Response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"pong": true
|
||||
}
|
||||
}
|
||||
|
||||
Purpose:
|
||||
|
||||
- verify TCP connection;
|
||||
- verify JSONL framing;
|
||||
- verify request/response correlation.
|
||||
|
||||
## status
|
||||
|
||||
Request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "status",
|
||||
"params": {}
|
||||
}
|
||||
|
||||
Response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"bridge": {
|
||||
"version": "0.1.0",
|
||||
"state": "running"
|
||||
},
|
||||
"servers": []
|
||||
}
|
||||
}
|
||||
|
||||
Purpose:
|
||||
|
||||
- bridge health;
|
||||
- later: Mattermost connection health;
|
||||
- later: WebSocket state;
|
||||
- later: authenticated user summary without secrets.
|
||||
|
||||
## connect
|
||||
|
||||
Planned request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "connect",
|
||||
"params": {
|
||||
"server_id": "work",
|
||||
"url": "https://mattermost.example.local",
|
||||
"login_id": "user@example.local",
|
||||
"password": "secret",
|
||||
"token": null,
|
||||
"ca_file": null
|
||||
}
|
||||
}
|
||||
|
||||
Rules:
|
||||
|
||||
- password and token must never be logged;
|
||||
- server_id is required architecturally;
|
||||
- MVP may default server_id to "default";
|
||||
- login/password and token are alternative auth paths;
|
||||
- saved session token may be loaded by bridge before asking Emacs for credentials.
|
||||
|
||||
Planned response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"server_id": "work",
|
||||
"user": {
|
||||
"id": "user-id",
|
||||
"username": "alice"
|
||||
},
|
||||
"websocket": "connected"
|
||||
}
|
||||
}
|
||||
|
||||
## me
|
||||
|
||||
Planned request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "me",
|
||||
"params": {
|
||||
"server_id": "work"
|
||||
}
|
||||
}
|
||||
|
||||
Planned response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"server_id": "work",
|
||||
"user": {
|
||||
"id": "user-id",
|
||||
"username": "alice",
|
||||
"nickname": "",
|
||||
"first_name": "",
|
||||
"last_name": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
## teams
|
||||
|
||||
Planned request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "teams",
|
||||
"params": {
|
||||
"server_id": "work"
|
||||
}
|
||||
}
|
||||
|
||||
Planned response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"server_id": "work",
|
||||
"teams": []
|
||||
}
|
||||
}
|
||||
|
||||
## open_self_dm
|
||||
|
||||
Planned request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "open_self_dm",
|
||||
"params": {
|
||||
"server_id": "work"
|
||||
}
|
||||
}
|
||||
|
||||
Planned response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"server_id": "work",
|
||||
"channel": {
|
||||
"id": "channel-id",
|
||||
"type": "direct",
|
||||
"display_name": "Self",
|
||||
"team_id": null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Implementation note:
|
||||
|
||||
Mattermost direct channel creation uses POST /api/v4/channels/direct with two user IDs.
|
||||
|
||||
For self-DM MVP, planned body:
|
||||
|
||||
["my_user_id", "my_user_id"]
|
||||
|
||||
This must be verified against Mattermost 10.9.3 during implementation.
|
||||
|
||||
## list_channels
|
||||
|
||||
Planned request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "list_channels",
|
||||
"params": {
|
||||
"server_id": "work",
|
||||
"team_id": "team-id"
|
||||
}
|
||||
}
|
||||
|
||||
Planned response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"server_id": "work",
|
||||
"team_id": "team-id",
|
||||
"channels": []
|
||||
}
|
||||
}
|
||||
|
||||
## get_history
|
||||
|
||||
Planned request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "get_history",
|
||||
"params": {
|
||||
"server_id": "work",
|
||||
"channel_id": "channel-id",
|
||||
"limit": 50,
|
||||
"before_id": null
|
||||
}
|
||||
}
|
||||
|
||||
Planned response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"server_id": "work",
|
||||
"channel_id": "channel-id",
|
||||
"posts": [],
|
||||
"order": "ascending",
|
||||
"has_more": false
|
||||
}
|
||||
}
|
||||
|
||||
Display rule:
|
||||
|
||||
Posts returned to Emacs should be sorted ascending by create_at for easy buffer insertion.
|
||||
|
||||
Mattermost REST may return posts in a map plus order array. The bridge normalizes this.
|
||||
|
||||
## send_post
|
||||
|
||||
Planned request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "send_post",
|
||||
"params": {
|
||||
"server_id": "work",
|
||||
"channel_id": "channel-id",
|
||||
"message": "hello",
|
||||
"root_id": null
|
||||
}
|
||||
}
|
||||
|
||||
Planned response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"server_id": "work",
|
||||
"post": {
|
||||
"id": "post-id",
|
||||
"channel_id": "channel-id",
|
||||
"user_id": "user-id",
|
||||
"root_id": null,
|
||||
"message": "hello",
|
||||
"create_at": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
## reply_post
|
||||
|
||||
Planned request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "reply_post",
|
||||
"params": {
|
||||
"server_id": "work",
|
||||
"channel_id": "channel-id",
|
||||
"root_id": "root-post-id",
|
||||
"message": "reply"
|
||||
}
|
||||
}
|
||||
|
||||
Planned response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"server_id": "work",
|
||||
"post": {
|
||||
"id": "reply-post-id",
|
||||
"channel_id": "channel-id",
|
||||
"user_id": "user-id",
|
||||
"root_id": "root-post-id",
|
||||
"message": "reply",
|
||||
"create_at": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
## mark_read
|
||||
|
||||
Planned request:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "request",
|
||||
"method": "mark_read",
|
||||
"params": {
|
||||
"server_id": "work",
|
||||
"channel_id": "channel-id"
|
||||
}
|
||||
}
|
||||
|
||||
Planned response:
|
||||
|
||||
{
|
||||
"id": "req-1",
|
||||
"type": "response",
|
||||
"ok": true,
|
||||
"result": {
|
||||
"server_id": "work",
|
||||
"channel_id": "channel-id",
|
||||
"read": true
|
||||
}
|
||||
}
|
||||
|
||||
## Planned events
|
||||
|
||||
Connection events:
|
||||
|
||||
bridge_started
|
||||
server_connected
|
||||
server_disconnected
|
||||
websocket_connected
|
||||
websocket_disconnected
|
||||
websocket_reconnecting
|
||||
resync_required
|
||||
|
||||
Post events:
|
||||
|
||||
post_created
|
||||
post_updated
|
||||
post_deleted
|
||||
|
||||
Channel events:
|
||||
|
||||
channel_updated
|
||||
channel_viewed
|
||||
|
||||
User/team events:
|
||||
|
||||
user_updated
|
||||
team_updated
|
||||
|
||||
MVP prioritizes:
|
||||
|
||||
websocket_connected
|
||||
websocket_disconnected
|
||||
post_created
|
||||
post_updated
|
||||
post_deleted
|
||||
resync_required
|
||||
|
||||
## Normalized post shape
|
||||
|
||||
{
|
||||
"id": "post-id",
|
||||
"server_id": "work",
|
||||
"channel_id": "channel-id",
|
||||
"user_id": "user-id",
|
||||
"root_id": null,
|
||||
"message": "raw text",
|
||||
"create_at": 0,
|
||||
"update_at": 0,
|
||||
"delete_at": 0
|
||||
}
|
||||
|
||||
MVP does not render Markdown.
|
||||
|
||||
## Error codes
|
||||
|
||||
Planned stable codes:
|
||||
|
||||
invalid_json
|
||||
invalid_request
|
||||
unknown_method
|
||||
unauthorized
|
||||
forbidden
|
||||
not_found
|
||||
rate_limited
|
||||
network_error
|
||||
tls_error
|
||||
server_error
|
||||
websocket_disconnected
|
||||
internal_error
|
||||
|
||||
## Security rules
|
||||
|
||||
Never log:
|
||||
|
||||
- password;
|
||||
- session token;
|
||||
- PAT;
|
||||
- Authorization header;
|
||||
- Cookie header;
|
||||
- raw login request body.
|
||||
|
||||
Status responses must not include secrets.
|
||||
|
||||
Web status UI must not include secrets.
|
||||
|
||||
Token cache files are plain files for MVP, but must be placed under bridge data directory and ignored by git/docker context.
|
||||
@@ -0,0 +1,91 @@
|
||||
# TLS and Self-Signed Certificates
|
||||
|
||||
## Context
|
||||
|
||||
Corporate Mattermost may use a certificate signed by an internal CA.
|
||||
|
||||
The user currently has Emacs-side workaround settings:
|
||||
|
||||
(setq gnutls-verify-error nil)
|
||||
(setq tls-checksig-warn-clock-skew t)
|
||||
(setq gnutls-trustfiles '("/etc/ssl/certs/ca-certificates.crt"))
|
||||
|
||||
These settings affect Emacs network connections.
|
||||
|
||||
They do not affect the Rust bridge running in Docker.
|
||||
|
||||
## Bridge policy
|
||||
|
||||
The Rust bridge must not disable TLS verification by default.
|
||||
|
||||
Preferred approach:
|
||||
|
||||
- trust system CA store;
|
||||
- allow explicit additional CA file;
|
||||
- document Docker mount;
|
||||
- return clear tls_error on failure.
|
||||
|
||||
## Planned configuration
|
||||
|
||||
Environment variable:
|
||||
|
||||
MM_CA_FILE=/certs/company-ca.crt
|
||||
|
||||
Compose volume:
|
||||
|
||||
./certs/company-ca.crt:/certs/company-ca.crt:ro
|
||||
|
||||
The CA file should be a PEM certificate.
|
||||
|
||||
## Emacs connection to bridge
|
||||
|
||||
Emacs connects to the local bridge over plain TCP:
|
||||
|
||||
127.0.0.1:8765
|
||||
|
||||
This local connection does not use TLS in MVP.
|
||||
|
||||
TLS is needed for bridge → Mattermost HTTPS/WebSocket traffic.
|
||||
|
||||
## WebSocket TLS
|
||||
|
||||
Mattermost WebSocket URL is derived from server URL:
|
||||
|
||||
https://mattermost.example.local -> wss://mattermost.example.local/api/v4/websocket
|
||||
http://mattermost.example.local -> ws://mattermost.example.local/api/v4/websocket
|
||||
|
||||
The same CA policy must apply to REST and WebSocket connections.
|
||||
|
||||
## Clock skew
|
||||
|
||||
Certificate validation can fail if system clock is wrong.
|
||||
|
||||
The bridge should report this clearly when possible.
|
||||
|
||||
Emacs setting:
|
||||
|
||||
tls-checksig-warn-clock-skew
|
||||
|
||||
does not fix Rust bridge certificate validation.
|
||||
|
||||
## Debugging checklist
|
||||
|
||||
If bridge cannot connect to Mattermost over HTTPS:
|
||||
|
||||
1. Check server URL.
|
||||
2. Check container can resolve hostname.
|
||||
3. Check container can reach server port.
|
||||
4. Check CA file is mounted.
|
||||
5. Check MM_CA_FILE points to the mounted path.
|
||||
6. Check certificate chain.
|
||||
7. Check container clock.
|
||||
8. Check Mattermost reverse proxy configuration.
|
||||
|
||||
## Non-goals for MVP
|
||||
|
||||
- automatic certificate discovery from Emacs settings;
|
||||
- disabling verification via simple flag;
|
||||
- certificate pinning;
|
||||
- mTLS client certificates.
|
||||
|
||||
mTLS can be added later if corporate infrastructure requires it.
|
||||
Reference in New Issue
Block a user