Add command parsing layer for chat integration (Discord, Mattermost, Slack). Features: - Parse @mosaic commands with action dispatch - Support 3 issue reference formats: #42, owner/repo#42, full URL - Handle 7 actions: fix, status, cancel, retry, verbose, quiet, help - Comprehensive error handling with helpful messages - Case-insensitive parsing - Platform-agnostic design Implementation: - CommandParserService with tokenizer and action dispatcher - Regex-based issue reference parsing - Type-safe command structures - 24 unit tests with 100% coverage TDD approach: - RED: Wrote comprehensive tests first - GREEN: Implemented parser to pass all tests - REFACTOR: Fixed TypeScript strict mode and linting issues Quality gates passed: - ✓ Typecheck - ✓ Lint - ✓ Build - ✓ Tests (24/24 passing) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2.3 KiB
2.3 KiB
Issue #171: Chat Command Parsing
Objective
Implement command parsing layer for chat integration that is shared across Discord, Mattermost, and Slack bridges.
Approach
- Create command interface types
- Write comprehensive tests for all command formats (TDD RED phase)
- Implement tokenizer for parsing @mosaic commands
- Implement action dispatch logic
- Add error handling with helpful messages
- Verify all tests pass (TDD GREEN phase)
- Refactor if needed (TDD REFACTOR phase)
Command Grammar
- Pattern:
@mosaic <action> [args...] - Actions: fix, status, cancel, retry, verbose, quiet, help
- Issue reference formats:
#42- Current repo issueowner/repo#42- Cross-repo issuehttps://git.example.com/owner/repo/issues/42- Full URL
Progress
- Create command interface types
- Write unit tests (RED phase)
- Implement command parser service
- Implement tokenizer
- Implement action dispatch
- Handle error responses
- Verify all tests pass (GREEN phase) - 24/24 tests passing
- Run quality gates (typecheck, lint, build, test) - All passing
- 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)