diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts index 426818dba7a24..598237d3761cc 100644 --- a/apps/web/src/components/ChatView.logic.test.ts +++ b/apps/web/src/components/ChatView.logic.test.ts @@ -1119,6 +1119,26 @@ describe("planComposerTurn", () => { } }); + it.each([ + "/compact Keep the interface decisions, drop the debugging output", + "/compact keep the interface decisions", + "/compact\nkeep the interface decisions", + ])("does not compact a stale session before /compact with instructions: %j", (messageText) => { + expect( + planComposerTurn({ ...base, resumeCompactionTokens: 250_000, messageText }), + ).toMatchObject({ compactBeforeSend: false, turnDispatchMode: "auto" }); + }); + + it("compacts a stale session before mixed-case /Compact with instructions, which Claude reads as prose", () => { + expect( + planComposerTurn({ + ...base, + resumeCompactionTokens: 250_000, + messageText: "/Compact keep the interface decisions", + }), + ).toMatchObject({ compactBeforeSend: true, turnDispatchMode: "queue" }); + }); + it("queues behind a running turn only when asked to", () => { const running = { ...base, diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts index 0ce51ee5e5534..5445e21516740 100644 --- a/apps/web/src/components/ChatView.logic.ts +++ b/apps/web/src/components/ChatView.logic.ts @@ -931,10 +931,6 @@ export function shouldShowPlanFollowUpPrompt(input: { ); } -// A typed `/compact`, with or without instructions, is already the compaction. Queueing a -// bare one ahead of it would run an uninstructed compaction first and charge for two. -const COMPACT_COMMAND_PATTERN = /^\/compact(?:\s|$)/i; - const sessionDismissedBranchMismatchKeys = new Set(); export function dismissBranchMismatchForSession(key: string): void { @@ -1541,11 +1537,12 @@ export function planComposerTurn(input: { isFirstMessage && input.sendEnvMode === "worktree" && !input.worktreePath; // A stale Claude session compacts before this message so the turn does not re-read the // old history. The message queues behind the /compact run, since steering into it is - // rejected. + // rejected. A /compact send already is that compaction. The server normalizes a bare + // command of any case, but Claude only reads instructions after a lowercase /compact. + const isCompactCommand = + input.messageText.toLowerCase() === "/compact" || /^\/compact\s/.test(input.messageText); const compactBeforeSend = - input.resumeCompactionTokens !== null && - !input.keepFullHistory && - !COMPACT_COMMAND_PATTERN.test(input.messageText); + input.resumeCompactionTokens !== null && !input.keepFullHistory && !isCompactCommand; return { // In worktree mode, require an explicit base branch so we don't silently // fall back to local execution when branch selection is missing.