ccguard
Version:
Automated enforcement of net-negative LOC, complexity constraints, and quality standards for Claude code
63 lines • 2.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserPromptHandler = void 0;
const contracts_1 = require("../contracts");
const CommandRegistry_1 = require("../commands/CommandRegistry");
const commands_1 = require("../commands");
class UserPromptHandler {
guardManager;
commandRegistry;
constructor(guardManager) {
this.guardManager = guardManager;
this.commandRegistry = CommandRegistry_1.CommandRegistry.createWithDefaults(commands_1.defaultCommands);
}
async processUserCommand(inputData) {
try {
const parsedData = JSON.parse(inputData);
const result = contracts_1.UserPromptSubmitSchema.safeParse(parsedData);
if (!result.success) {
return null;
}
const prompt = result.data.prompt.trim();
// Check if this is a ccguard command (case insensitive)
if (!prompt.toLowerCase().startsWith('ccguard ')) {
return null;
}
// Parse command and args - preserve original case for arguments
const parts = prompt.split(' ').filter(p => p.length > 0);
if (parts.length < 2) {
return null;
}
const commandName = parts[1].toLowerCase(); // Only lowercase the command name
const args = parts.slice(2); // Keep original case for arguments
// Find and execute command
const command = this.commandRegistry.get(commandName);
if (!command) {
return {
decision: 'block',
reason: `Unknown command: ${commandName}. Available commands: ${this.getAvailableCommands()}`,
};
}
return await command.execute(this.guardManager, args);
}
catch {
return null;
}
}
getAvailableCommands() {
const commands = this.commandRegistry.getAll();
return commands.map(c => c.name).join(', ');
}
async getDisabledResult() {
const isEnabled = await this.guardManager.isEnabled();
if (!isEnabled) {
return {
decision: 'approve',
reason: 'CCGuard is disabled',
};
}
return null;
}
}
exports.UserPromptHandler = UserPromptHandler;
//# sourceMappingURL=userPromptHandler.js.map