feat(chat): add /stop cancellation command across gateway and telegram

This commit is contained in:
William Valentin
2026-02-19 09:52:57 -08:00
parent 027f7ad283
commit cd74b1e78a
9 changed files with 203 additions and 11 deletions
+21
View File
@@ -36,6 +36,7 @@ describe('createAgentHandlers command fast-path', () => {
setBusy: vi.fn(),
setOnToolUse: vi.fn(),
isBusy: vi.fn(() => false),
cancel: vi.fn(() => true),
};
const sessionManager = {
@@ -219,6 +220,26 @@ describe('createAgentHandlers command fast-path', () => {
expect(((sent[0] as GatewayEvent).data as { content: string }).content).toContain('Reset default to: anthropic/claude-sonnet-4');
});
it('handles /stop command via fast-path and requests cancellation', async () => {
const sent: OutboundMessage[] = [];
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
const req: GatewayRequest = {
id: 12,
method: 'agent.send',
params: {
message: '/stop',
connectionId: 'conn-1',
metadata: { isCommand: true, command: 'stop' },
},
};
await handlers['agent.send'](req, send);
expect(sessionBridge.cancel).toHaveBeenCalledWith('conn-1');
expect(mockAgent.process).not.toHaveBeenCalled();
expect(((sent[0] as GatewayEvent).data as { content: string }).content).toContain('Cancellation requested');
});
it('falls through to agent.process for unknown commands', async () => {
const sent: OutboundMessage[] = [];
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
+6
View File
@@ -294,6 +294,12 @@ export function createAgentHandlers(deps: AgentHandlerDeps) {
}
return 'Session reset.';
},
cancelRun: () => {
const cancelled = deps.sessionBridge.cancel(connectionId);
return cancelled
? 'Cancellation requested. The active operation will stop at the next safe point.'
: 'No active operation to cancel.';
},
getApprovals: () => {
if (!deps.hookEngine) {
return 'Approval gates are not enabled in this runtime.';