Skip to content

Commit 5dee6f4

Browse files
committed
fix(ui): match reset soft whitespace boundary
1 parent c6e1f47 commit 5dee6f4

2 files changed

Lines changed: 52 additions & 9 deletions

File tree

ui/src/ui/app-chat.test.ts

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,24 @@ describe("handleSendChat", () => {
13801380
expect(host.chatMessage).toBe("");
13811381
});
13821382

1383-
it("preserves /reset soft args and skips confirmation dialog", async () => {
1383+
it.each([
1384+
{
1385+
input: "/reset soft please reload system prompt",
1386+
expected: "/reset soft please reload system prompt",
1387+
},
1388+
{
1389+
input: "/reset\tsoft please reload system prompt",
1390+
expected: "/reset soft please reload system prompt",
1391+
},
1392+
{
1393+
input: "/reset\nsoft please reload system prompt",
1394+
expected: "/reset soft please reload system prompt",
1395+
},
1396+
{
1397+
input: "/reset: soft please reload system prompt",
1398+
expected: "/reset soft please reload system prompt",
1399+
},
1400+
])("preserves $input args and skips confirmation dialog", async ({ input, expected }) => {
13841401
const confirm = vi.fn(() => false);
13851402
vi.stubGlobal("confirm", confirm);
13861403
const request = vi.fn(async (method: string) => {
@@ -1391,7 +1408,7 @@ describe("handleSendChat", () => {
13911408
});
13921409
const host = makeHost({
13931410
client: { request } as unknown as ChatHost["client"],
1394-
chatMessage: "/reset soft please reload system prompt",
1411+
chatMessage: input,
13951412
sessionKey: "agent:main",
13961413
});
13971414

@@ -1404,10 +1421,37 @@ describe("handleSendChat", () => {
14041421
"chat send payload",
14051422
);
14061423
expect(payload.sessionKey).toBe("agent:main");
1407-
expect(payload.message).toBe("/reset soft please reload system prompt");
1424+
expect(payload.message).toBe(expected);
14081425
expect(host.chatMessage).toBe("");
14091426
});
14101427

1428+
it.each([
1429+
"/reset softish please archive",
1430+
"/reset\tsoftish please archive",
1431+
"/reset\nsoftish please archive",
1432+
"/reset: softish please archive",
1433+
])("keeps %s on the hard-reset confirmation path", async (message) => {
1434+
const confirm = vi.fn(() => false);
1435+
vi.stubGlobal("confirm", confirm);
1436+
const request = vi.fn(async (method: string) => {
1437+
throw new Error(`Unexpected request: ${method}`);
1438+
});
1439+
const host = makeHost({
1440+
client: { request } as unknown as ChatHost["client"],
1441+
chatMessage: "keep this draft",
1442+
sessionKey: "agent:main",
1443+
});
1444+
1445+
await handleSendChat(host, message, {
1446+
confirmReset: true,
1447+
restoreDraft: true,
1448+
});
1449+
1450+
expect(confirm).toHaveBeenCalledTimes(1);
1451+
expect(request).not.toHaveBeenCalled();
1452+
expect(host.chatMessage).toBe("keep this draft");
1453+
});
1454+
14111455
it("records visible send timing phases for a normal chat send", async () => {
14121456
const request = vi.fn(async (method: string) => {
14131457
if (method === "chat.send") {

ui/src/ui/app-chat.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,17 @@ export function isChatStopCommand(text: string) {
245245
}
246246

247247
function isChatResetCommand(text: string) {
248-
const trimmed = text.trim();
249-
if (!trimmed) {
248+
const parsed = parseSlashCommand(text);
249+
if (!parsed || (parsed.command.key !== "new" && parsed.command.key !== "reset")) {
250250
return false;
251251
}
252-
const normalized = normalizeLowercaseStringOrEmpty(trimmed);
253-
if (normalized === "/new" || normalized === "/reset") {
252+
if (parsed.command.key === "new") {
254253
return true;
255254
}
256-
if (normalized.match(/^\/reset soft(?:\s|$)/)) {
255+
if (/^soft(?:\s|$)/.test(normalizeLowercaseStringOrEmpty(parsed.args))) {
257256
return false;
258257
}
259-
return normalized.startsWith("/new ") || normalized.startsWith("/reset ");
258+
return true;
260259
}
261260

262261
function confirmChatResetCommand(text: string) {

0 commit comments

Comments
 (0)