Unify TUI slash commands and harden tool inventory responses

This commit is contained in:
William Valentin
2026-02-21 12:39:27 -08:00
parent e9cb1d7c1a
commit b09bfc8373
16 changed files with 505 additions and 21 deletions
+72
View File
@@ -1062,6 +1062,78 @@ describe('daemon external backend integration', () => {
expect(reply).toHaveBeenCalledWith(expect.objectContaining({ text: 'external backend response' }));
});
it('forces native processing for capability/tool inventory queries', async () => {
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process')
.mockResolvedValue('Available tools (authoritative):\n- file.read');
const history: Array<{ role: 'user' | 'assistant'; content: string }> = [];
const session = {
id: 'telegram:external-tools-query',
addMessage: vi.fn((msg: { role: 'user' | 'assistant'; content: string }) => {
history.push(msg);
return msg;
}),
getHistory: vi.fn(() => [...history]),
clear: vi.fn(),
replaceHistory: vi.fn(),
getConfig: vi.fn(() => undefined),
setConfig: vi.fn(),
deleteConfig: vi.fn(),
};
const externalBackend = {
name: 'codex',
process: vi.fn(async () => 'external backend response'),
};
const router = createMessageRouter({
sessionManager: {
getSession: vi.fn(() => session),
} as unknown as MessageRouterDeps['sessionManager'],
modelRouter: {
getAvailableTiers: () => ['fast', 'default', 'complex', 'local'],
getAllLabels: () => ({ fast: 'fast', default: 'default', complex: 'complex', local: 'local' }),
getLabel: (tier: string) => tier,
} as unknown as MessageRouterDeps['modelRouter'],
systemPrompt: 'test prompt',
toolRegistry: {
clone() { return this; },
register: vi.fn(),
} as unknown as MessageRouterDeps['toolRegistry'],
toolExecutor: {} as unknown as MessageRouterDeps['toolExecutor'],
config: {
agents: {
primary_tier: 'default',
delegation: {
compaction: 'fast',
memory_extraction: 'fast',
classification: 'fast',
tool_summarisation: 'fast',
complex_reasoning: 'complex',
},
max_delegation_depth: 3,
max_iterations: 10,
},
compaction: { enabled: false },
models: { default: { provider: 'anthropic', model: 'claude' } },
} as unknown as MessageRouterDeps['config'],
externalBackends: { codex: externalBackend } as unknown as MessageRouterDeps['externalBackends'],
defaultName: 'codex',
});
const reply = vi.fn(async (_message: OutboundMessage) => {});
await router.handler({
id: 'm-external-tools-query',
channel: 'telegram',
senderId: 'external-tools-query',
text: 'check your available tools',
timestamp: Date.now(),
} as MessageRouterInput, reply);
expect(externalBackend.process).not.toHaveBeenCalled();
expect(processSpy).toHaveBeenCalled();
expect(reply).toHaveBeenCalledWith(expect.objectContaining({ text: 'Available tools (authoritative):\n- file.read' }));
});
it('falls back to native processing when external backend fails', async () => {
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process')
.mockResolvedValue('native fallback response');