feat(#170): Implement mosaic-bridge module for Discord

Created the mosaic-bridge module to enable Discord integration for
chat-based control of Mosaic Stack. This module provides the foundation
for receiving commands via Discord and forwarding them to the stitcher
for job orchestration.

Key Features:
- Discord bot connection and authentication
- Command parsing (@mosaic fix, status, cancel, verbose, quiet, help)
- Thread management for job updates
- Chat provider interface for future platform extensibility
- Noise management (low/medium/high verbosity levels)

Implementation Details:
- Created IChatProvider interface for platform abstraction
- Implemented DiscordService with Discord.js
- Basic command parsing (detailed parsing in #171)
- Thread creation for job-specific updates
- Configuration via environment variables

Commands Supported:
- @mosaic fix <issue> - Start job for issue
- @mosaic status <job> - Get job status (placeholder)
- @mosaic cancel <job> - Cancel running job (placeholder)
- @mosaic verbose <job> - Stream full logs (placeholder)
- @mosaic quiet - Reduce notifications (placeholder)
- @mosaic help - Show available commands

Testing:
- 23/23 tests passing (TDD approach)
- Unit tests for Discord service
- Module integration tests
- 100% coverage of critical paths

Quality Gates:
- Typecheck: PASSED
- Lint: PASSED
- Build: PASSED
- Tests: PASSED (23/23)

Environment Variables:
- DISCORD_BOT_TOKEN - Bot authentication token
- DISCORD_GUILD_ID - Server/Guild ID (optional)
- DISCORD_CONTROL_CHANNEL_ID - Channel for commands

Files Created:
- apps/api/src/bridge/bridge.module.ts
- apps/api/src/bridge/discord/discord.service.ts
- apps/api/src/bridge/interfaces/chat-provider.interface.ts
- apps/api/src/bridge/index.ts
- Full test coverage

Dependencies Added:
- discord.js@latest

Next Steps:
- Issue #171: Implement detailed command parsing
- Issue #172: Add Herald integration for job updates
- Future: Add Slack, Matrix support via IChatProvider

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-01 21:26:40 -06:00
parent fd78b72ee8
commit 4ac21d1a3a
45 changed files with 1988 additions and 18 deletions

View File

@@ -0,0 +1,79 @@
/**
* Chat Provider Interface
*
* Defines the contract for chat platform integrations (Discord, Slack, Matrix, etc.)
*/
export interface ChatMessage {
id: string;
channelId: string;
authorId: string;
authorName: string;
content: string;
timestamp: Date;
threadId?: string;
}
export interface ChatCommand {
command: string;
args: string[];
message: ChatMessage;
}
export interface ThreadCreateOptions {
channelId: string;
name: string;
message: string;
}
export interface ThreadMessageOptions {
threadId: string;
content: string;
}
export interface VerbosityLevel {
level: "low" | "medium" | "high";
description: string;
}
/**
* Chat Provider Interface
*
* All chat platform integrations must implement this interface
*/
export interface IChatProvider {
/**
* Connect to the chat platform
*/
connect(): Promise<void>;
/**
* Disconnect from the chat platform
*/
disconnect(): Promise<void>;
/**
* Check if the provider is connected
*/
isConnected(): boolean;
/**
* Send a message to a channel or thread
*/
sendMessage(channelId: string, content: string): Promise<void>;
/**
* Create a thread for job updates
*/
createThread(options: ThreadCreateOptions): Promise<string>;
/**
* Send a message to a thread
*/
sendThreadMessage(options: ThreadMessageOptions): Promise<void>;
/**
* Parse a command from a message
*/
parseCommand(message: ChatMessage): ChatCommand | null;
}

View File

@@ -0,0 +1 @@
export * from "./chat-provider.interface";