TUI/Gateway: emit internal hooks for /new and /reset

This commit is contained in:
Vignesh Natarajan
2026-02-14 16:33:19 -08:00
parent 301b3ff912
commit b08146fad6
7 changed files with 115 additions and 4 deletions

View File

@@ -204,8 +204,11 @@ export class GatewayChatClient {
return await this.client.request<SessionsPatchResult>("sessions.patch", opts);
}
async resetSession(key: string) {
return await this.client.request("sessions.reset", { key });
async resetSession(key: string, reason?: "new" | "reset") {
return await this.client.request("sessions.reset", {
key,
...(reason ? { reason } : {}),
});
}
async getStatus() {

View File

@@ -45,4 +45,42 @@ describe("tui command handlers", () => {
);
expect(requestRender).toHaveBeenCalled();
});
it("passes reset reason when handling /new and /reset", async () => {
const resetSession = vi.fn().mockResolvedValue({ ok: true });
const addSystem = vi.fn();
const requestRender = vi.fn();
const loadHistory = vi.fn().mockResolvedValue(undefined);
const { handleCommand } = createCommandHandlers({
client: { resetSession } as never,
chatLog: { addSystem } as never,
tui: { requestRender } as never,
opts: {},
state: {
currentSessionKey: "agent:main:main",
activeChatRunId: null,
sessionInfo: {},
} as never,
deliverDefault: false,
openOverlay: vi.fn(),
closeOverlay: vi.fn(),
refreshSessionInfo: vi.fn(),
loadHistory,
setSession: vi.fn(),
refreshAgents: vi.fn(),
abortActive: vi.fn(),
setActivityStatus: vi.fn(),
formatSessionKey: vi.fn(),
applySessionInfoFromPatch: vi.fn(),
noteLocalRunId: vi.fn(),
});
await handleCommand("/new");
await handleCommand("/reset");
expect(resetSession).toHaveBeenNthCalledWith(1, "agent:main:main", "new");
expect(resetSession).toHaveBeenNthCalledWith(2, "agent:main:main", "reset");
expect(loadHistory).toHaveBeenCalledTimes(2);
});
});

View File

@@ -436,7 +436,7 @@ export function createCommandHandlers(context: CommandHandlerContext) {
state.sessionInfo.totalTokens = null;
tui.requestRender();
await client.resetSession(state.currentSessionKey);
await client.resetSession(state.currentSessionKey, name);
chatLog.addSystem(`session ${state.currentSessionKey} reset`);
await loadHistory();
} catch (err) {