# Issue #170: Implement mosaic-bridge module for Discord ## Objective Create the mosaic-bridge module to enable Discord integration. This module will: - Connect to Discord via bot token - Listen for commands in designated channels - Forward commands to stitcher - Receive status updates from herald - Post updates to threads with appropriate verbosity ## Prerequisites - Issue #166 (Stitcher module) must be complete - StitcherService available ## Approach 1. Create bridge module structure 2. Define chat provider interface for extensibility 3. Implement Discord service using Discord.js 4. Add command parsing (basic implementation) 5. Implement thread management for job updates 6. Add configuration management 7. Follow TDD: Write tests before implementation ## Commands to Implement - `@mosaic fix ` - Start job for issue - `@mosaic status ` - Get job status - `@mosaic cancel ` - Cancel running job - `@mosaic verbose ` - Stream full logs to thread - `@mosaic quiet` - Reduce notifications - `@mosaic help` - Show commands ## Noise Management Strategy - **Main channel**: Low verbosity (milestones only) - **Job threads**: Medium verbosity (step completions) - **DMs**: Configurable per user ## Progress - [x] Install discord.js dependency - [x] Create bridge module structure - [x] Define ChatProvider interface - [x] Write tests for Discord service (RED phase) - [x] Implement Discord service (GREEN phase) - [x] Implement command parsing - [x] Implement thread management - [x] Add configuration - [x] Refactor and optimize (REFACTOR phase) - [x] Run quality gates (typecheck, lint, build, test) - [x] Commit changes ## Results - **Tests**: 23/23 passing (20 Discord service + 3 module tests) - **Typecheck**: PASSED - **Lint**: PASSED - **Build**: PASSED - **Coverage**: High (all critical paths tested) ## Testing Strategy - Unit tests for command parsing - Unit tests for thread management - Mock Discord.js client for testing - Test stitcher integration - Verify configuration loading ## Environment Variables - `DISCORD_BOT_TOKEN` - Bot authentication token - `DISCORD_GUILD_ID` - Server/Guild ID - `DISCORD_CONTROL_CHANNEL_ID` - Channel for commands ## Notes - Keep Discord.js interactions isolated in discord.service.ts - Use ChatProvider interface to allow future platform additions (Slack, Matrix, etc.) - Basic command parsing in this issue; detailed parsing comes in #171 - DO NOT push to remote, just commit locally