Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/web/src/components/ChatView.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 5 additions & 8 deletions apps/web/src/components/ChatView.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();

export function dismissBranchMismatchForSession(key: string): void {
Expand Down Expand Up @@ -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.
Expand Down
Loading