feat(#171): Implement chat command parsing
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>
This commit is contained in:
90
apps/api/src/bridge/parser/command.interface.ts
Normal file
90
apps/api/src/bridge/parser/command.interface.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Command Parser Interfaces
|
||||
*
|
||||
* Defines types for parsing chat commands across all platforms
|
||||
*/
|
||||
|
||||
/**
|
||||
* Issue reference types
|
||||
*/
|
||||
export interface IssueReference {
|
||||
/**
|
||||
* Issue number
|
||||
*/
|
||||
number: number;
|
||||
|
||||
/**
|
||||
* Repository owner (optional for current repo)
|
||||
*/
|
||||
owner?: string;
|
||||
|
||||
/**
|
||||
* Repository name (optional for current repo)
|
||||
*/
|
||||
repo?: string;
|
||||
|
||||
/**
|
||||
* Full URL (if provided as URL)
|
||||
*/
|
||||
url?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supported command actions
|
||||
*/
|
||||
export enum CommandAction {
|
||||
FIX = "fix",
|
||||
STATUS = "status",
|
||||
CANCEL = "cancel",
|
||||
RETRY = "retry",
|
||||
VERBOSE = "verbose",
|
||||
QUIET = "quiet",
|
||||
HELP = "help",
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsed command result
|
||||
*/
|
||||
export interface ParsedCommand {
|
||||
/**
|
||||
* The action to perform
|
||||
*/
|
||||
action: CommandAction;
|
||||
|
||||
/**
|
||||
* Issue reference (for fix command)
|
||||
*/
|
||||
issue?: IssueReference;
|
||||
|
||||
/**
|
||||
* Job ID (for status, cancel, retry, verbose commands)
|
||||
*/
|
||||
jobId?: string;
|
||||
|
||||
/**
|
||||
* Raw arguments
|
||||
*/
|
||||
rawArgs: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Command parse error
|
||||
*/
|
||||
export interface CommandParseError {
|
||||
/**
|
||||
* Error message
|
||||
*/
|
||||
message: string;
|
||||
|
||||
/**
|
||||
* Suggested help text
|
||||
*/
|
||||
help?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command parse result (success or error)
|
||||
*/
|
||||
export type CommandParseResult =
|
||||
| { success: true; command: ParsedCommand }
|
||||
| { success: false; error: CommandParseError };
|
||||
Reference in New Issue
Block a user