feat(tools): surface browser tool activation and policy diagnostics

This commit is contained in:
William Valentin
2026-02-16 18:16:43 -08:00
parent fc6a79ed90
commit 10a83717f9
2 changed files with 46 additions and 0 deletions
+34
View File
@@ -196,6 +196,40 @@ describe('configSchema — server', () => {
});
});
describe('configSchema — browser', () => {
const minimalConfig = {
telegram: { bot_token: 'test', allowed_chat_ids: [1] },
models: { default: { provider: 'anthropic', model: 'claude-3' } },
};
it('defaults browser tools to disabled with safe runtime defaults', () => {
const result = configSchema.parse(minimalConfig);
expect(result.browser.enabled).toBe(false);
expect(result.browser.headless).toBe(true);
expect(result.browser.max_pages).toBe(5);
expect(result.browser.default_timeout).toBe(30000);
});
it('accepts explicit browser config', () => {
const result = configSchema.parse({
...minimalConfig,
browser: {
enabled: true,
executable_path: '/usr/bin/chromium',
headless: false,
max_pages: 3,
default_timeout: 45000,
},
});
expect(result.browser.enabled).toBe(true);
expect(result.browser.executable_path).toBe('/usr/bin/chromium');
expect(result.browser.headless).toBe(false);
expect(result.browser.max_pages).toBe(3);
expect(result.browser.default_timeout).toBe(45000);
});
});
describe('configSchema — backup', () => {
const minimalConfig = {
telegram: { bot_token: 'test', allowed_chat_ids: [1] },
+12
View File
@@ -66,6 +66,7 @@ export function initTools(deps: ToolsDeps): ToolsResult {
}
// Initialize browser manager and register browser tools (if enabled)
const browserToolNames = ['browser.navigate', 'browser.screenshot', 'browser.click', 'browser.type', 'browser.content', 'browser.eval'];
let browserManager: BrowserManager | undefined;
if (config.browser?.enabled) {
const manager = new BrowserManager({
@@ -86,6 +87,8 @@ export function initTools(deps: ToolsDeps): ToolsResult {
await manager.shutdown();
console.log('Browser manager stopped');
});
} else {
console.log('Browser tools disabled (set browser.enabled=true to register browser.* tools)');
}
const toolExecutor = new ToolExecutor(toolRegistry, hookEngine);
@@ -99,5 +102,14 @@ export function initTools(deps: ToolsDeps): ToolsResult {
console.log(`Tool policy: profile=${effectiveProfile}, deny=[${config.tools.deny.join(', ')}]`);
}
if (config.browser?.enabled) {
const allNames = toolRegistry.list().map((tool) => tool.name);
const allowed = toolPolicy.resolveAllowedNames(allNames);
const availableBrowserTools = browserToolNames.filter((name) => allowed.has(name));
if (availableBrowserTools.length === 0) {
console.log('Browser tools are registered but blocked by tool policy (use tools.profile=coding/full or tools.allow).');
}
}
return { toolRegistry, toolExecutor, browserManager };
}