Replaces the single 800-line tools.ts and its switch dispatcher with a Theia-inspired registry pattern — each tool domain is its own file, and dispatch is a plain Map.get() call with no central routing function. New structure in src/tools/: registry.ts — ToolDefinition (with handler), registerTool(), executeTool(), ALL_TOOLS context.ts — ToolContext, MemoryUpdate interfaces security.ts — PROTECTED_* constants + assertGiteaWritable/assertCoolifyDeployable utils.ts — safeResolve(), EXCLUDED set file.ts — read_file, write_file, replace_in_file, list_directory, find_files, search_code shell.ts — execute_command git.ts — git_commit_and_push coolify.ts — coolify_*, list_all_apps, get_app_status, deploy_app gitea.ts — gitea_*, list_repos, list_all_issues, read_repo_file agent.ts — spawn_agent, get_job_status memory.ts — save_memory index.ts — barrel with side-effect imports + re-exports Adding a new tool now requires only a new file + registerTool() call. No switch statement, no shared array to edit. External API unchanged. Made-with: Cursor
24 lines
802 B
JavaScript
24 lines
802 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.ALL_TOOLS = void 0;
|
|
exports.registerTool = registerTool;
|
|
exports.executeTool = executeTool;
|
|
/** Live registry — grows as domain files are imported. */
|
|
const _registry = new Map();
|
|
/**
|
|
* Mutable array kept in sync with the registry.
|
|
* Used by agents.ts to pick tool subsets by name (backwards-compatible with ALL_TOOLS).
|
|
*/
|
|
exports.ALL_TOOLS = [];
|
|
function registerTool(tool) {
|
|
_registry.set(tool.name, tool);
|
|
exports.ALL_TOOLS.push(tool);
|
|
}
|
|
/** Dispatch a tool call by name — O(1) map lookup, no switch needed. */
|
|
async function executeTool(name, args, ctx) {
|
|
const tool = _registry.get(name);
|
|
if (!tool)
|
|
return { error: `Unknown tool: ${name}` };
|
|
return tool.handler(args, ctx);
|
|
}
|