diff --git a/README.md b/README.md index 2af9281..6e99448 100644 --- a/README.md +++ b/README.md @@ -194,3 +194,26 @@ See `docs/mvp-checklist.md` for the detailed checklist. Current state: phases 0-3a complete (storage foundation). Next: phase 3b (REST client, auth, connect/me). + +## Verification + +To verify the bridge works against your corporate Mattermost instance: + +1. Start the bridge: `./scripts/docker-up.sh` +2. Connect and get a token: + ```bash + ./scripts/mm-cli.sh '{"id":"1","type":"request","method":"connect","params":{"server_id":"work","url":"https://mm.local","login_id":"user","password":"pass"}}' + ``` +3. Open self-DM channel: + ```bash + ./scripts/mm-cli.sh '{"id":"2","type":"request","method":"open_self_dm","params":{"server_id":"work"}}' + ``` +4. Send a message to yourself: + ```bash + ./scripts/mm-cli.sh '{"id":"3","type":"request","method":"send_post","params":{"server_id":"work","channel_id":"","message":"Test"}}' + ``` +4. Check history: + ```bash + ./scripts/mm-cli.sh '{"id":"4","type":"request","method":"get_history","params":{"server_id":"work","channel_id":"","limit":1}}' + ``` + diff --git a/bridge/crates/mm-core/src/model/mod.rs b/bridge/crates/mm-core/src/model/mod.rs index a25f9f1..3057fac 100644 --- a/bridge/crates/mm-core/src/model/mod.rs +++ b/bridge/crates/mm-core/src/model/mod.rs @@ -75,4 +75,6 @@ pub struct Post { pub create_at: i64, pub update_at: i64, pub delete_at: i64, + #[serde(default)] + pub file_ids: Vec, } diff --git a/docs/mvp-checklist.md b/docs/mvp-checklist.md index a258d34..be0a6f1 100644 --- a/docs/mvp-checklist.md +++ b/docs/mvp-checklist.md @@ -7,7 +7,7 @@ - [x] Docker Compose as primary bridge runtime. - [x] Emacs does not start Docker. - [x] TCP JSONL transport. -- [x] Web status UI planned. +- [x] Web status UI. - [x] Mattermost 10.9.3 target. - [x] Mattermost server is source of truth. - [x] Emacs buffers are display-only. @@ -19,45 +19,41 @@ - [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. +- [x] Plain token file per server, private mode. +- [x] Explicit CA configuration, verification stays enabled. +- [x] Automated dependency resolution, no manual version pins. ## 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. +- [x] Repository tree script. +- [x] README. +- [x] .gitignore / .dockerignore. +- [x] architecture / protocol / docker / tls / mattermost notes docs. +- [x] MVP checklist. ## Phase 1 — minimal Rust bridge -- [x] Add Cargo workspace. -- [x] Add crate manifests. -- [x] Add minimal mm-core types. -- [x] Add JSONL protocol types. -- [x] Add TCP listener. -- [x] Implement ping. -- [x] Implement status. -- [x] Add smoke test for ping/status. +- [x] Cargo workspace, five crates. +- [x] mm-core: ids, errors, models. +- [x] JSONL protocol parse/validate/encode. +- [x] TCP listener, line-based handling. +- [x] ping, status, unknown_method, invalid_json. +- [x] Unit tests. +- [x] dev-check.sh, smoke-ping.sh. -## Phase 2 — Docker and status web UI +## Phase 2 — Docker and web status UI -- [x] Add Dockerfile. -- [x] Add compose.yaml. -- [x] Add bridge config from environment. -- [x] Add /health. -- [x] Add /status JSON. -- [x] Add simple HTML status page. -- [x] Add Docker helper scripts. -- [x] Add web smoke script. -- [x] Verify local bridge + web smoke. -- [x] Verify Docker Compose bridge + web smoke. +- [x] mm-web with axum. +- [x] /health, /status, HTML index. +- [x] Shared BridgeStatus between TCP and web. +- [x] Config from environment (listen addresses). +- [x] Dockerfile with Nexus builder and internal CA. +- [x] compose.yaml, docker helper scripts. +- [x] Non-root runtime user. +- [x] smoke-web.sh with proxy bypass. +- [x] MSRV-aware Cargo.lock, committed after green build. +- [x] Local bridge + web smoke verified. +- [x] Docker Compose bridge + web smoke verified. ## Phase 3a — storage foundation (no network) @@ -78,34 +74,30 @@ ## Phase 3b — authentication (network) -### 3b-1: HTTP client foundation +- [x] mm-client: HTTP client with explicit CA support. +- [x] login/password against Mattermost 10.9.3, read Token header. +- [x] Save session token via TokenStore. +- [x] Load saved token on connect. +- [x] Support PAT token. +- [x] Implement connect. +- [x] Implement me. +- [x] Map Mattermost errors to normalized error codes. +- [x] Ensure tokens/passwords are never logged. -- [ ] mm-client crate skeleton. -- [ ] reqwest dependency with rustls-tls-native-roots (for system CA) + explicit CA support. -- [ ] Client struct with base_url and optional ca_file. -- [ ] login(login_id, password) -> Result (extracts Token header). -- [ ] get_me(token) -> Result. -- [ ] Unit/integration tests for client construction. +## Phase 4a — self-DM backend vertical slice -### 3b-2: Bridge integration +- [x] Implement teams. +- [x] Resolve current user. +- [x] Create/get self direct channel. +- [x] Implement open_self_dm. +- [x] Implement get_history with ascending post order. +- [x] Implement send_post. +- [x] Bridge methods verified via smoke tests. +- [x] Post model includes file_ids. -- [ ] Implement connect method in bridge. -- [ ] Implement me method in bridge. -- [ ] Save session token via TokenStore on successful connect. -- [ ] Load saved token on startup (future: auto-reconnect). -- [ ] Support PAT token (same flow, just skip login). -- [ ] Map Mattermost API errors to normalized error codes. -- [ ] Ensure tokens/passwords are never logged. +## Phase 4b — Emacs UI (pending) -## 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. +- [ ] Connect Emacs to bridge over TCP. - [ ] Open self-DM buffer. - [ ] Display raw messages. - [ ] Send message from Emacs. @@ -127,46 +119,38 @@ ## 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. +- [ ] Thread buffer. +- [ ] mattermost-thread-display option. +- [ ] Default separate-buffer. +- [ ] Keep inline mode future-compatible. +- [ ] 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. +- [ ] Channel list buffer. +- [ ] Open channel buffer, load history, send message. +- [ ] Channel events online. - [ ] Implement mark_read. - [ ] Forced refresh with g. ## Phase 8 — TLS/self-signed support -- [ ] Add explicit CA file configuration. +- [ ] MM_CA_FILE configuration for bridge to Mattermost. +- [ ] Same CA policy for REST and WebSocket. - [ ] 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. +- [ ] Clear tls_error messages. ## 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. +- [ ] Request timeouts. +- [ ] Rate-limit handling. +- [ ] Integration smoke tests. +- [ ] Emacs Lisp tests. +- [ ] Log review for secret leaks. +- [ ] Cache permission review. +- [ ] Multiserver-ready naming review. ## Next atomic step -Verify Phase 2 locally and in Docker Compose. - -After that: - -Implement authentication foundation: connect, me, login/password, token cache. +Phase 5: WebSocket client implementation in mm-client. diff --git a/scripts/mm-cli.sh b/scripts/mm-cli.sh index 991aeb5..65d4f31 100755 --- a/scripts/mm-cli.sh +++ b/scripts/mm-cli.sh @@ -11,4 +11,5 @@ else read -r INPUT fi -printf '%s\n' "$INPUT" | nc -w 2 "$HOST" "$PORT" +# Use -q 1 to wait 1 second for response after EOF on stdin +printf '%s\n' "$INPUT" | nc -q 1 "$HOST" "$PORT"