# Issue #171: Chat Command Parsing ## Objective Implement command parsing layer for chat integration that is shared across Discord, Mattermost, and Slack bridges. ## Approach 1. Create command interface types 2. Write comprehensive tests for all command formats (TDD RED phase) 3. Implement tokenizer for parsing @mosaic commands 4. Implement action dispatch logic 5. Add error handling with helpful messages 6. Verify all tests pass (TDD GREEN phase) 7. Refactor if needed (TDD REFACTOR phase) ## Command Grammar - Pattern: `@mosaic [args...]` - Actions: fix, status, cancel, retry, verbose, quiet, help - Issue reference formats: - `#42` - Current repo issue - `owner/repo#42` - Cross-repo issue - `https://git.example.com/owner/repo/issues/42` - Full URL ## Progress - [x] Create command interface types - [x] Write unit tests (RED phase) - [x] Implement command parser service - [x] Implement tokenizer - [x] Implement action dispatch - [x] Handle error responses - [x] Verify all tests pass (GREEN phase) - 24/24 tests passing - [x] Run quality gates (typecheck, lint, build, test) - All passing - [x] Commit changes ## Testing - Test all command formats - Test issue reference parsing (all 3 formats) - Test error cases (invalid commands, missing args) - Test edge cases (extra whitespace, case sensitivity) ## Notes - Parser must be platform-agnostic (works with Discord, Mattermost, Slack) - Error messages should be helpful and guide users - Follow strict TDD: tests before implementation ## Implementation Details - Used regex patterns for issue reference parsing (current repo, cross-repo, full URL) - Tokenizer splits on whitespace after normalizing input - Action dispatch uses switch statement for type safety - Helpful error messages with examples provided for invalid input - Case-insensitive command parsing (@Mosaic, @mosaic both work) - Handles edge cases: extra whitespace, leading zeros in issue numbers ## Files Created - `/home/jwoltje/src/mosaic-stack/apps/api/src/bridge/parser/command.interface.ts` - Type definitions - `/home/jwoltje/src/mosaic-stack/apps/api/src/bridge/parser/command-parser.service.ts` - Parser service - `/home/jwoltje/src/mosaic-stack/apps/api/src/bridge/parser/command-parser.spec.ts` - Unit tests ## Test Results - 24/24 tests passing - All quality gates passed (typecheck, lint, build)