feat(coding-agent): add tool override support via extensions

- Add setActiveTools() to ExtensionAPI for dynamic tool management
- Extensions can now override, wrap, or disable built-in tools
- Add tool-override.ts example demonstrating the pattern
- Update documentation for tool override capabilities
This commit is contained in:
Mario Zechner 2026-01-08 13:14:27 +01:00
parent 7a2c19cdf0
commit e3dd4f21d1
10 changed files with 211 additions and 61 deletions

View file

@ -514,7 +514,10 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
}
// Initially active tools = active built-in + extension tools
let activeToolsArray: Tool[] = [...initialActiveBuiltInTools, ...wrappedExtensionTools];
// Extension tools can override built-in tools with the same name
const extensionToolNames = new Set(wrappedExtensionTools.map((t) => t.name));
const nonOverriddenBuiltInTools = initialActiveBuiltInTools.filter((t) => !extensionToolNames.has(t.name));
let activeToolsArray: Tool[] = [...nonOverriddenBuiltInTools, ...wrappedExtensionTools];
time("combineTools");
// Wrap tools with extensions if available

View file

@ -222,12 +222,6 @@ export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): strin
const hasLs = tools.includes("ls");
const hasRead = tools.includes("read");
// Read-only mode notice (only if we have some read-only tools but no write tools)
// Skip this if there are no built-in tools at all (extensions may provide write capabilities)
if (tools.length > 0 && !hasBash && !hasEdit && !hasWrite) {
guidelinesList.push("You are in READ-ONLY mode - you cannot modify files or execute arbitrary commands");
}
// Bash without edit/write = read-only bash mode
if (hasBash && !hasEdit && !hasWrite) {
guidelinesList.push(
@ -266,9 +260,7 @@ export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): strin
// Always include these
guidelinesList.push("Be concise in your responses");
if (tools.length > 0) {
guidelinesList.push("Show file paths clearly when working with files");
}
guidelinesList.push("Show file paths clearly when working with files");
const guidelines = guidelinesList.map((g) => `- ${g}`).join("\n");