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
62 lines
2.5 KiB
JavaScript
62 lines
2.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const registry_1 = require("./registry");
|
|
(0, registry_1.registerTool)({
|
|
name: 'spawn_agent',
|
|
description: 'Dispatch a sub-agent job to run in the background. Returns a job ID. Use this to delegate specialized work to Coder, PM, or Marketing agents.',
|
|
parameters: {
|
|
type: 'object',
|
|
properties: {
|
|
agent: { type: 'string', description: '"Coder", "PM", or "Marketing"' },
|
|
task: { type: 'string', description: 'Detailed task description for the agent' },
|
|
repo: { type: 'string', description: 'Gitea repo in "owner/name" format the agent should work on' }
|
|
},
|
|
required: ['agent', 'task', 'repo']
|
|
},
|
|
async handler(args, _ctx) {
|
|
const runnerUrl = process.env.AGENT_RUNNER_URL || 'http://localhost:3333';
|
|
try {
|
|
const res = await fetch(`${runnerUrl}/api/agent/run`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', 'X-Internal': 'true' },
|
|
body: JSON.stringify({ agent: args.agent, task: args.task, repo: args.repo })
|
|
});
|
|
const data = await res.json();
|
|
return { jobId: data.jobId, agent: args.agent, status: 'dispatched' };
|
|
}
|
|
catch (err) {
|
|
return { error: `Failed to spawn agent: ${err instanceof Error ? err.message : String(err)}` };
|
|
}
|
|
}
|
|
});
|
|
(0, registry_1.registerTool)({
|
|
name: 'get_job_status',
|
|
description: 'Check the status of a previously spawned agent job by job ID.',
|
|
parameters: {
|
|
type: 'object',
|
|
properties: {
|
|
job_id: { type: 'string', description: 'Job ID returned by spawn_agent' }
|
|
},
|
|
required: ['job_id']
|
|
},
|
|
async handler(args, _ctx) {
|
|
const runnerUrl = process.env.AGENT_RUNNER_URL || 'http://localhost:3333';
|
|
try {
|
|
const res = await fetch(`${runnerUrl}/api/jobs/${String(args.job_id)}`);
|
|
const job = await res.json();
|
|
return {
|
|
id: job.id,
|
|
agent: job.agent,
|
|
status: job.status,
|
|
progress: job.progress,
|
|
toolCalls: job.toolCalls?.length,
|
|
result: job.result,
|
|
error: job.error
|
|
};
|
|
}
|
|
catch (err) {
|
|
return { error: `Failed to get job: ${err instanceof Error ? err.message : String(err)}` };
|
|
}
|
|
}
|
|
});
|