PRININIT / lib /src /command-parser.js
Rachit-Tw's picture
Upload 183 files
272a04f verified
Raw
History Blame Contribute Delete
2.03 kB
"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