capsule-ai-cli
Version:
The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing
47 lines • 1.34 kB
JavaScript
import chalk from 'chalk';
import { EventEmitter } from 'events';
export class BashConfirmationService extends EventEmitter {
autoApprove = false;
dangerousPatterns = [
/rm\s+-rf/i,
/rm\s+.*\*/,
/>\s*\/dev\/[^/]+$/,
/mkfs/i,
/dd\s+if=/i,
/format/i,
/del\s+\/[sf]/i,
/:(){ :|:& };:/,
/chmod\s+777/i,
/chown.*-R/i,
/sudo\s+rm/i,
];
setAutoApprove(enabled) {
this.autoApprove = enabled;
}
isAutoApprove() {
return this.autoApprove;
}
isDangerousCommand(command) {
return this.dangerousPatterns.some(pattern => pattern.test(command));
}
async confirmBash(preview) {
if (this.autoApprove) {
const message = chalk.dim(` ⎿ Auto-executing: ${preview.command}`);
console.log(message);
return true;
}
return new Promise((resolve) => {
this.emit('showBashConfirmation', {
...preview,
onConfirm: () => {
resolve(true);
},
onCancel: () => {
resolve(false);
}
});
});
}
}
export const bashConfirmationService = new BashConfirmationService();
//# sourceMappingURL=bash-confirmation.js.map