cline-sdk
Version:
Comprehensive SDK for Cline - AI-powered development assistant with database integration, execution modes, and custom functions
173 lines • 6.67 kB
JavaScript
;
/**
* Execution Modes for Cline SDK
*
* Defines different operational modes:
* - ASK: Only answers questions, no tool execution
* - PLAN: Creates plans but doesn't execute actions
* - ACT: Full execution mode with all tools enabled
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MODE_DEFINITIONS = void 0;
exports.getModeRestrictions = getModeRestrictions;
exports.isToolAllowed = isToolAllowed;
exports.parseModeSwitch = parseModeSwitch;
exports.getModeDescription = getModeDescription;
exports.generateModeStatus = generateModeStatus;
/**
* Mode definitions and their characteristics
*/
exports.MODE_DEFINITIONS = {
ask: {
mode: "ask",
allowedTools: [], // No tools allowed in ask mode
description: "Question-only mode: Provides answers and explanations without executing any actions",
systemPromptAddition: `
IMPORTANT: You are currently in ASK MODE - you can only provide information, answers, and explanations.
- You CANNOT execute any tools or perform any actions
- You CANNOT write files, run commands, or modify anything
- You CAN provide detailed explanations, code examples, and guidance
- If the user needs actions performed, tell them they need to change the execution mode
- Focus on being helpful through knowledge and advice only`,
},
plan: {
mode: "plan",
allowedTools: ["Read", "DatabaseSchema"], // Only read-only tools
description: "Planning mode: Can inspect and analyze but cannot modify anything",
systemPromptAddition: `
You are in PLAN MODE - you can inspect and analyze but cannot execute modifying actions.
- You CAN read files and inspect database schemas
- You CAN create detailed plans and explanations
- You CANNOT write files, run commands, or modify databases
- You CANNOT execute tools that change the system state
- When creating plans, be specific about the steps needed
- If execution is needed, tell the user they need to change to execution mode`,
},
act: {
mode: "act",
allowedTools: ["Write", "Read", "Bash", "DatabaseQuery", "DatabaseSchema", "DatabaseRLS", "CustomFunction"], // All tools
description: "Full execution mode: Can perform all actions and use all tools",
systemPromptAddition: `
You are in ACT MODE - you have full access to execute actions and use tools.
- You CAN write files, run commands, and modify databases (within permissions)
- You CAN use all available tools to complete tasks
- Be careful with destructive operations - confirm when appropriate
- Always explain what you're doing and why
- Only the user can switch modes, not you`,
},
};
/**
* Get mode restrictions based on execution mode
*/
function getModeRestrictions(mode) {
switch (mode) {
case "ask":
return {
canExecuteTools: false,
canWriteFiles: false,
canRunCommands: false,
canModifyDatabase: false,
canAccessFileSystem: false,
maxToolsPerTask: 0,
};
case "plan":
return {
canExecuteTools: true,
canWriteFiles: false,
canRunCommands: false,
canModifyDatabase: false,
canAccessFileSystem: true, // Read-only access
maxToolsPerTask: 5,
};
case "act":
return {
canExecuteTools: true,
canWriteFiles: true,
canRunCommands: true,
canModifyDatabase: true,
canAccessFileSystem: true,
maxToolsPerTask: undefined, // No limit
};
default:
throw new Error(`Unknown execution mode: ${mode}`);
}
}
/**
* Check if a tool is allowed in the current mode
*/
function isToolAllowed(toolName, mode) {
// In ask mode, no tools are allowed
if (mode === "ask") {
return false;
}
// In plan mode, only read-only tools are allowed
if (mode === "plan") {
const readOnlyTools = ["Read", "DatabaseSchema"];
return readOnlyTools.includes(toolName);
}
// In act mode, check if tool is in the allowed list
if (mode === "act") {
const config = exports.MODE_DEFINITIONS[mode];
return config.allowedTools.includes(toolName);
}
return false;
}
/**
* Parse mode switch commands from user input
* Only responds to explicit mode commands, no automatic detection
*/
function parseModeSwitch(userInput) {
const input = userInput.toLowerCase().trim();
// Only direct mode commands - no automatic mode detection
if (input === "/ask") {
return "ask";
}
if (input === "/plan") {
return "plan";
}
if (input === "/act") {
return "act";
}
// Explicit mode switch commands
if (input.startsWith("/ask ") || input === "switch to ask mode") {
return "ask";
}
if (input.startsWith("/plan ") || input === "switch to plan mode") {
return "plan";
}
if (input.startsWith("/act ") || input === "switch to act mode") {
return "act";
}
return null;
}
/**
* Get user-friendly mode description
*/
function getModeDescription(mode) {
return exports.MODE_DEFINITIONS[mode].description;
}
/**
* Generate mode status message
*/
function generateModeStatus(mode) {
const config = exports.MODE_DEFINITIONS[mode];
const restrictions = getModeRestrictions(mode);
let status = `🔧 Current Mode: ${mode.toUpperCase()}\n`;
status += `📝 ${config.description}\n\n`;
status += `Capabilities:\n`;
status += `- Execute Tools: ${restrictions.canExecuteTools ? "✅" : "❌"}\n`;
status += `- Write Files: ${restrictions.canWriteFiles ? "✅" : "❌"}\n`;
status += `- Run Commands: ${restrictions.canRunCommands ? "✅" : "❌"}\n`;
status += `- Modify Database: ${restrictions.canModifyDatabase ? "✅" : "❌"}\n`;
status += `- Access File System: ${restrictions.canAccessFileSystem ? "✅" : "❌"}\n`;
if (restrictions.maxToolsPerTask !== undefined) {
status += `- Max Tools Per Task: ${restrictions.maxToolsPerTask}\n`;
}
status += `\nAllowed Tools: ${config.allowedTools.length > 0 ? config.allowedTools.join(", ") : "None"}\n`;
status += `\nTo switch modes:\n`;
status += `- "/ask" or "switch to ask mode" - Question-only mode\n`;
status += `- "/plan" or "switch to plan mode" - Planning and analysis mode\n`;
status += `- "/act" or "switch to act mode" - Full execution mode`;
return status;
}
//# sourceMappingURL=execution-modes.js.map