feat: make /transfer bidirectional across telegram and tui

This commit is contained in:
William Valentin
2026-02-18 07:55:08 -08:00
parent d48adbe0b0
commit 16af5e75fd
13 changed files with 262 additions and 17 deletions
+70
View File
@@ -213,6 +213,76 @@ describe('daemon command fast-path integration', () => {
expect(session.deleteConfig).toHaveBeenCalledWith('modelTier');
});
it('handles /transfer command via command fast-path and copies session to TUI', async () => {
const processSpy = vi.spyOn(AgentOrchestrator.prototype, 'process');
const transferSpy = vi.fn();
const session = {
id: 'telegram:user-1',
addMessage: vi.fn(),
getHistory: vi.fn(() => []),
clear: vi.fn(),
replaceHistory: vi.fn(),
getConfig: vi.fn(() => undefined),
setConfig: vi.fn(),
deleteConfig: vi.fn(),
};
const commandRegistry = new CommandRegistry();
registerBuiltinCommands(commandRegistry);
const router = createMessageRouter({
sessionManager: {
getSession: vi.fn(() => session),
transferSession: transferSpy,
} 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'],
commandRegistry,
});
const reply = vi.fn(async (_message: OutboundMessage) => {});
await router.handler({
id: 'm-transfer',
channel: 'telegram',
senderId: 'user-1',
text: '/transfer tui',
timestamp: Date.now(),
metadata: { isCommand: true, command: 'transfer', commandArgs: 'tui' },
} as MessageRouterInput, reply);
expect(processSpy).not.toHaveBeenCalled();
expect(transferSpy).toHaveBeenCalledWith('telegram', 'user-1', 'tui', 'local');
expect(reply).toHaveBeenCalledWith({
text: 'Session transferred to TUI (local)',
replyTo: 'm-transfer',
});
});
it('emits user.action audit events for channel messages', async () => {
const mockAuditLogger = {
userAction: vi.fn(),