fix: run composite tool sections through the catalog

situation_brief, military_awareness and the HUD caption called other tools
directly, so replaced tools and interceptors did not apply to their sections.
Tools now reach each other through the catalog, and interceptors see these
calls with the calling tool as parent. Surfaces become a view over the
composed catalog, so a composite offered on voice keeps sections that voice
does not list.
This commit is contained in:
Sameh Khamis committed 2026-10-02 15:21:36 -07:00
1 parent 7ddee426e7
commit 963c791a5c
9 files changed
+219 -65

No files matched your search

+48 -1
View File
@@ -1,6 +1,13 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { TOOL_SURFACES, coreTools, toolsForSurface } from './index.js';
import {
TOOL_SURFACES,
catalogForSurface,
composeCatalog,
coreTools,
defineTool,
toolsForSurface,
} from './index.js';
const names = (tools) => tools.map((tool) => tool.name);
@@ -33,6 +40,46 @@ test('overrides turn a tool on or off for one surface', () => {
);
});
test('every table entry names a core tool and a known surface', () => {
const names = new Set(coreTools.map((tool) => tool.name));
for (const [name, entry] of Object.entries(TOOL_SURFACES)) {
assert.ok(names.has(name), name);
assert.deepEqual(Object.keys(entry), ['voice']);
}
});
test('a surface view hides tools from clients but not from composites', async () => {
const leaf = defineTool({
name: 'leaf',
title: 'Leaf',
description: 'A hidden building block.',
inputSchema: { type: 'object', properties: {} },
run: async () => ({ summary: 'leaf', data: {} }),
});
const outer = defineTool({
name: 'outer',
title: 'Outer',
description: 'Calls leaf.',
inputSchema: { type: 'object', properties: {} },
run: async (args, { tools }) => tools.call('leaf', {}),
});
const view = catalogForSurface(
composeCatalog({ tools: [leaf, outer] }),
'voice',
{ leaf: { voice: false } },
);
assert.deepEqual(
view.list().map((tool) => tool.name),
['outer'],
);
assert.equal(view.get('leaf'), undefined);
await assert.rejects(
view.call('leaf', {}),
(error) => error.code === 'unsupported',
);
assert.equal((await view.call('outer', {})).summary, 'leaf');
});
test('unknown surfaces and tool names are rejected', () => {
assert.throws(
() => toolsForSurface(coreTools, 'email'),