diff --git a/extensions/cli/src/subagent/builtInAgents.ts b/extensions/cli/src/subagent/builtInAgents.ts index 6947c5eb4..3c8ce4359 100644 --- a/extensions/cli/src/subagent/builtInAgents.ts +++ b/extensions/cli/src/subagent/builtInAgents.ts @@ -1,7 +1,5 @@ import { AgentConfig } from "./types.js"; -// todo - move this to the subagent directory - /** * Built-in agent configurations */ @@ -11,20 +9,7 @@ export const BUILT_IN_AGENTS: Record = { displayName: "General Agent", description: "General-purpose agent for researching complex questions and executing multi-step tasks autonomously", - tools: { - // Enable all standard tools (refactor to use BUILTIN_TOOLS) - Read: true, - Write: true, - Edit: true, - multiEdit: true, - listFiles: true, - searchCode: true, - runTerminalCommand: true, - Fetch: true, - writeChecklist: true, - // Explicitly disable Subagent to prevent recursion - Subagent: false, - }, + availableTools: [], // model: "haiku-4-5-latest", // if the model is not there, skip the subagent tool (check api key?) systemPrompt: `You are a specialized task execution agent. @@ -48,19 +33,11 @@ export function getAgent(name: string): AgentConfig | null { return BUILT_IN_AGENTS[name] || null; } -/** - * List all available subagents - */ -export function listSubagents(): AgentConfig[] { - return Object.values(BUILT_IN_AGENTS); -} - /** * Generate dynamic tool description listing available agents */ export function generateSubagentToolDescription(): string { - const agents = listSubagents(); - const agentList = agents + const agentList = Object.values(BUILT_IN_AGENTS) .map((agent) => ` - ${agent.name}: ${agent.description}`) .join("\n"); diff --git a/extensions/cli/src/subagent/executor.ts b/extensions/cli/src/subagent/executor.ts index 9c27962ac..2c30a7a41 100644 --- a/extensions/cli/src/subagent/executor.ts +++ b/extensions/cli/src/subagent/executor.ts @@ -1,8 +1,12 @@ import type { ChatHistoryItem } from "core"; -import { services } from "../services/index.js"; +import { + SERVICE_NAMES, + serviceContainer, + services, +} from "../services/index.js"; +import { ToolPermissionServiceState } from "../services/ToolPermissionService.js"; import { streamChatResponse } from "../stream/streamChatResponse.js"; -import { Tool } from "../tools/types.js"; import { logger } from "../util/logger.js"; import { AgentConfig } from "./types.js"; @@ -27,17 +31,6 @@ export interface SubAgentResult { error?: string; } -/** - * Filter tools based on agent configuration - */ -function filterToolsByAgent(allTools: Tool[], agent: AgentConfig): Tool[] { - return allTools.filter((tool) => { - const toolName = tool.name; - // If tool is explicitly disabled in agent config, filter it out - return agent.tools[toolName] !== false; - }); -} - /** * Build system message for the agent */ @@ -64,11 +57,16 @@ async function buildAgentSystemMessage(agent: AgentConfig): Promise { export async function executeSubAgent( options: SubAgentExecutionOptions, ): Promise { - const { agent, prompt, abortController, onOutputUpdate } = options; + const mainAgentPermissionsState = + await serviceContainer.get( + SERVICE_NAMES.TOOL_PERMISSIONS, + ); + + const { agent: subAgent, prompt, abortController, onOutputUpdate } = options; try { logger.debug("Starting subagent execution", { - agent: agent.name, + agent: subAgent.name, }); // Get model and LLM API from model service @@ -79,23 +77,23 @@ export async function executeSubAgent( throw new Error("Model or LLM API not available"); } - logger.debug("debug1 model and llmapi", { model, llmApi }); + logger.debug("debug1 model and llmapi", { model, llmApi, subAgent }); - // Get all available tools - const { getAllAvailableTools } = await import("../tools/index.js"); - const allTools = await getAllAvailableTools(true); // headless mode + // allow all tools for now + // todo: eventually we want to show the same prompt in a dialog whether asking whether that tool call is allowed or not - // Filter tools based on agent configuration - const allowedTools = filterToolsByAgent(allTools, agent); - - logger.debug("debug1 Filtered tools for agent", { - agent: agent.name, - toolCount: allowedTools.length, - tools: allowedTools.map((t) => t.name).filter((t) => t !== "Subagent"), // explicityly remove subagent to prevent recursion - }); + serviceContainer.set( + SERVICE_NAMES.TOOL_PERMISSIONS, + { + ...mainAgentPermissionsState, + permissions: { + policies: [{ tool: "*", permission: "allow" }], + }, + }, + ); // Build agent system message - const systemMessage = await buildAgentSystemMessage(agent); + const systemMessage = await buildAgentSystemMessage(subAgent); // Store original system message function const originalGetSystemMessage = services.systemMessage?.getSystemMessage; @@ -167,7 +165,7 @@ export async function executeSubAgent( }); logger.debug("Subagent execution completed", { - agent: agent.name, + agent: subAgent.name, responseLength: response.length, }); @@ -185,10 +183,16 @@ export async function executeSubAgent( if (chatHistorySvc && originalIsReady) { chatHistorySvc.isReady = originalIsReady; } + + // Restore original main agent tool permissions + serviceContainer.set( + SERVICE_NAMES.TOOL_PERMISSIONS, + mainAgentPermissionsState, + ); } } catch (error: any) { logger.error("Subagent execution failed", { - agent: agent.name, + agent: subAgent.name, error: error.message, }); diff --git a/extensions/cli/src/subagent/types.ts b/extensions/cli/src/subagent/types.ts index e3575cef4..df5cb4d10 100644 --- a/extensions/cli/src/subagent/types.ts +++ b/extensions/cli/src/subagent/types.ts @@ -9,7 +9,7 @@ export interface AgentConfig { /** Description of when to use this agent */ description: string; /** Tool configuration - which tools are available to this agent */ - tools: Record; + availableTools: string[]; /** Optional custom system prompt for the agent */ systemPrompt?: string; }