File size: 2,033 Bytes
272a04f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a5489c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
/**
 * Command Parser for Prix AI
 *
 * Parses and validates Prix commands from GitHub comments.
 * Supports multiple syntaxes and provides structured output.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBotComment = exports.parsePrixCommand = void 0;
/**
 * Parse a comment body to detect Prix commands
 *
 * Supported syntaxes:
 * - !prix plan
 * - /prix plan
 * - prix plan
 *
 * @param commentBody The raw comment body
 * @returns Parsed command object
 */
const parsePrixCommand = (commentBody) => {
    const trimmed = commentBody.trim();
    // Check if this is a Prix command
    const prixCommandRegex = /^[/!]?prix\s+(\w+)(.*)$/i;
    const match = trimmed.match(prixCommandRegex);
    if (!match) {
        return {
            isPrixCommand: false,
            command: null,
            args: [],
            rawCommand: ''
        };
    }
    const commandStr = match[1].toLowerCase();
    const argsStr = match[2].trim();
    const args = argsStr ? argsStr.split(/\s+/).filter(Boolean) : [];
    // Map command string to command type
    const commandMap = {
        plan: 'plan',
        fix: 'fix',
        review: 'review',
        help: 'help'
    };
    const command = commandMap[commandStr] || null;
    return {
        isPrixCommand: true,
        command,
        args,
        rawCommand: match[0]
    };
};
exports.parsePrixCommand = parsePrixCommand;
/**
 * Check if a comment is from a bot (to prevent loops)
 *
 * @param username The GitHub username
 * @param botUsername The bot's username (default: 'prix-ai[bot]')
 * @returns True if the comment is from a bot
 */
const isBotComment = (username, botUsername = 'prix-ai[bot]') => {
    if (!username)
        return false;
    const normalizedUsername = username.toLowerCase();
    const normalizedBot = botUsername.toLowerCase();
    return (normalizedUsername === normalizedBot || normalizedUsername.endsWith('[bot]'));
};
exports.isBotComment = isBotComment;
//# sourceMappingURL=command-parser.js.map