Skip to content

Commit 4b4c4d0

Browse files
committed
fix(tui): let idle local stop finish
1 parent 88ecd12 commit 4b4c4d0

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

src/tui/embedded-backend.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,46 @@ describe("EmbeddedTuiBackend", () => {
818818
await flushMicrotasks();
819819
});
820820

821+
it("sends idle slash stop as a normal prompt so the TUI receives a terminal event", async () => {
822+
const { EmbeddedTuiBackend } = await import("./embedded-backend.js");
823+
const pending = deferred<{
824+
payloads: Array<{ text: string }>;
825+
meta: Record<string, unknown>;
826+
}>();
827+
agentCommandFromIngressMock.mockReturnValueOnce(pending.promise);
828+
829+
const backend = new EmbeddedTuiBackend();
830+
const events: Array<{ event: string; payload: unknown }> = [];
831+
backend.onEvent = (evt) => {
832+
events.push({ event: evt.event, payload: evt.payload });
833+
};
834+
backend.start();
835+
await backend.sendChat({
836+
sessionKey: "agent:main:main",
837+
message: "/stop",
838+
runId: "run-local-idle-stop",
839+
});
840+
841+
expect(agentCommandFromIngressMock).toHaveBeenCalledTimes(1);
842+
843+
pending.resolve({ payloads: [{ text: "idle stop prompt" }], meta: {} });
844+
await flushMicrotasks();
845+
846+
expect(events).toContainEqual({
847+
event: "chat",
848+
payload: {
849+
runId: "run-local-idle-stop",
850+
sessionKey: "agent:main:main",
851+
state: "final",
852+
message: {
853+
role: "assistant",
854+
content: [{ type: "text", text: "idle stop prompt" }],
855+
timestamp: embeddedEventTimestamp,
856+
},
857+
},
858+
});
859+
});
860+
821861
it("queues same-session sends behind terminal local runs until maintenance settles", async () => {
822862
const { EmbeddedTuiBackend } = await import("./embedded-backend.js");
823863
const first = deferred<{

src/tui/embedded-backend.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ function resolveBtwQuestion(message: string): string | undefined {
135135
return question ? question : undefined;
136136
}
137137

138-
function isSlashStopCommand(text: string): boolean {
139-
const trimmed = text.trim();
140-
return trimmed.startsWith("/") && isChatStopCommandText(trimmed);
141-
}
142-
143138
function payloadText(parts: unknown): string {
144139
if (!Array.isArray(parts)) {
145140
return "";
@@ -331,9 +326,7 @@ export class EmbeddedTuiBackend implements TuiBackend {
331326
const runId = opts.runId ?? randomUUID();
332327
const question = resolveBtwQuestion(opts.message);
333328
const abortableSessionRun = this.hasAbortableSessionRun(opts.sessionKey);
334-
const stopCommand =
335-
isChatStopCommandText(opts.message) &&
336-
(isSlashStopCommand(opts.message) || abortableSessionRun);
329+
const stopCommand = abortableSessionRun && isChatStopCommandText(opts.message);
337330
const queuedAfter =
338331
question || stopCommand ? undefined : this.findQueuedSessionRunPromise(opts.sessionKey);
339332
if (stopCommand) {

0 commit comments

Comments
 (0)