TypeScript
fix(web): instructed compact runs without a bare compaction first (#24008)
Julius Marminge16aaf5ba7d75
diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.tsindex a03a7929b09..426818dba7a 100644--- a/apps/web/src/components/ChatView.logic.test.ts+++ b/apps/web/src/components/ChatView.logic.test.ts@@ -1102,14 +1102,21 @@ describe("planComposerTurn", () => {});it("queues behind a compaction of a stale session, except for /compact itself", () => {- expect(planComposerTurn({ ...base, resumeCompactionTokens: 120_000 })).toMatchObject({- compactBeforeSend: true,- turnDispatchMode: "queue",- shouldQueueBehindActiveRun: true,- });- expect(- planComposerTurn({ ...base, resumeCompactionTokens: 120_000, messageText: "/COMPACT" }),- ).toMatchObject({ compactBeforeSend: false, turnDispatchMode: "auto" });+ const stale = { ...base, resumeCompactionTokens: 120_000 };+ for (const messageText of ["hello", "/compactfoo"]) {+ expect(planComposerTurn({ ...stale, messageText })).toMatchObject({+ compactBeforeSend: true,+ turnDispatchMode: "queue",+ shouldQueueBehindActiveRun: true,+ });+ }+ for (const messageText of ["/COMPACT", "/compact keep the API notes", "/compact\n tests"]) {+ expect(planComposerTurn({ ...stale, messageText })).toMatchObject({+ compactBeforeSend: false,+ turnDispatchMode: "auto",+ shouldQueueBehindActiveRun: false,+ });+ }});it("queues behind a running turn only when asked to", () => {diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.tsindex 856a2b4e548..0ce51ee5e55 100644--- a/apps/web/src/components/ChatView.logic.ts+++ b/apps/web/src/components/ChatView.logic.ts@@ -931,6 +931,10 @@ 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<string>();export function dismissBranchMismatchForSession(key: string): void {@@ -1541,7 +1545,7 @@ export function planComposerTurn(input: {const compactBeforeSend =input.resumeCompactionTokens !== null &&!input.keepFullHistory &&- input.messageText.toLowerCase() !== "/compact";+ !COMPACT_COMMAND_PATTERN.test(input.messageText);return {// In worktree mode, require an explicit base branch so we don't silently// fall back to local execution when branch selection is missing.