feat(web): old Claude threads compact on send instead of stacking notices (#16631)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
079e4bccdc
commit
655dfbe8ba
6 files changed
+251
-154
No files matched your search
@@ -39,7 +39,6 @@ import { feedbackBannerItem } from "./chat/ComposerFeedback";
|
||||
import { usageLimitsBannerItem } from "./chat/ComposerUsageLimits";
|
||||
import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { Minimize2Icon } from "lucide-react";
|
||||
import {
|
||||
questionAttachmentDraftId,
|
||||
questionAttachmentDraftPrefix,
|
||||
@@ -486,6 +485,8 @@ import {
|
||||
} from "./chat/QueuedRunsControl";
|
||||
import { useLinkedThreadPullRequest } from "./ThreadStatusIndicators";
|
||||
import type { ComposerBannerStackItem } from "./chat/ComposerBannerStack";
|
||||
import { ThreadStatusLine } from "./chat/ThreadStatusLine";
|
||||
import { formatRelativeTimeLabel, formatRelativeTimeUntilLabel } from "../timestampFormat";
|
||||
import { ComposerSurface } from "./chat/ComposerSurface";
|
||||
import { resolveThreadSyncPhase } from "../threadSync";
|
||||
import {
|
||||
@@ -493,7 +494,7 @@ import {
|
||||
hasDismissedResumeCompaction,
|
||||
shouldOfferResumeCompaction,
|
||||
} from "./chat/ContextWindowMeter.logic";
|
||||
import { deriveLatestContextWindowSnapshot, formatContextWindowTokens } from "../lib/contextWindow";
|
||||
import { deriveLatestContextWindowSnapshot } from "../lib/contextWindow";
|
||||
import {
|
||||
DRAFT_HERO_TRANSITION_ANIMATION_ID,
|
||||
DRAFT_HERO_TRANSITION_EASING,
|
||||
@@ -7563,73 +7564,61 @@ export default function ChatView(props: ChatViewProps) {
|
||||
isStoppingBackgroundWork,
|
||||
onOpenRelatedThread,
|
||||
]);
|
||||
// A woken thread announces itself in the open view, not just the sidebar
|
||||
// pill. Dismissing marks the wake as seen (same acknowledgment as the
|
||||
// pill); sending a message clears it as a side effect of the send path.
|
||||
const wokeThreadBannerItem = useMemo<ComposerBannerStackItem | null>(() => {
|
||||
if (!activeThreadWokeVisible) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
id: `thread-woke:${activeThread?.id ?? "unknown"}`,
|
||||
variant: "info",
|
||||
icon: <AlarmClockIcon />,
|
||||
title: "Thread woke from snooze",
|
||||
description: "Send a message to continue",
|
||||
dismissLabel: "Dismiss Woke notification",
|
||||
onDismiss: acknowledgeActiveThreadWoke,
|
||||
};
|
||||
}, [acknowledgeActiveThreadWoke, activeThread?.id, activeThreadWokeVisible]);
|
||||
const parkedThreadBannerItem = useMemo<ComposerBannerStackItem | null>(() => {
|
||||
if (!activeThreadSnoozed && !activeThreadSettled) {
|
||||
return null;
|
||||
}
|
||||
const isSnoozed = activeThreadSnoozed;
|
||||
return {
|
||||
id: `thread-${isSnoozed ? "snoozed" : "settled"}:${activeThread?.id ?? "unknown"}`,
|
||||
variant: "info",
|
||||
icon: isSnoozed ? <AlarmClockIcon /> : <CheckCircle2Icon />,
|
||||
title: `This thread is ${isSnoozed ? "snoozed" : "settled"}`,
|
||||
description: `Send a message to ${isSnoozed ? "wake" : "unsettle"}`,
|
||||
actions: (
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
disabled={!canOperateThread || (isSnoozed ? isUnsnoozing : isUnsettling)}
|
||||
onClick={() =>
|
||||
void (isSnoozed ? handleUnsnoozeActiveThread() : handleUnsettleActiveThread())
|
||||
}
|
||||
>
|
||||
{isSnoozed
|
||||
? isUnsnoozing
|
||||
? "Waking..."
|
||||
: "Wake now"
|
||||
: isUnsettling
|
||||
? "Un-settling..."
|
||||
: "Un-settle"}
|
||||
</Button>
|
||||
),
|
||||
};
|
||||
// Settled, snoozed, and woke are thread state, not composer actions: each
|
||||
// gets one quiet line after the last message instead of a banner. A woken
|
||||
// thread announces itself here, not just in the sidebar pill. Dismissing
|
||||
// marks the wake as seen (same acknowledgment as the pill); sending a
|
||||
// message clears it as a side effect of the send path.
|
||||
// Memoized: it is the timeline's list footer, and a new element re-renders that footer.
|
||||
// nowMinute keeps the relative time fresh.
|
||||
const threadStatusLine = useMemo(() => {
|
||||
void nowMinute;
|
||||
return activeThreadSnoozed ? (
|
||||
<ThreadStatusLine
|
||||
icon={<AlarmClockIcon />}
|
||||
label={
|
||||
activeThreadShell?.snoozedUntil
|
||||
? `Snoozed, ${formatRelativeTimeUntilLabel(activeThreadShell.snoozedUntil)}`
|
||||
: "Snoozed"
|
||||
}
|
||||
actionLabel={isUnsnoozing ? "Waking..." : "Wake now"}
|
||||
actionDisabled={!canOperateThread || isUnsnoozing}
|
||||
onAction={() => void handleUnsnoozeActiveThread()}
|
||||
/>
|
||||
) : activeThreadSettled ? (
|
||||
<ThreadStatusLine
|
||||
icon={<CheckCircle2Icon />}
|
||||
label={
|
||||
activeThreadShell?.settledAt
|
||||
? `Settled ${formatRelativeTimeLabel(activeThreadShell.settledAt)}`
|
||||
: "Settled"
|
||||
}
|
||||
actionLabel={isUnsettling ? "Un-settling..." : "Un-settle"}
|
||||
actionDisabled={!canOperateThread || isUnsettling}
|
||||
onAction={() => void handleUnsettleActiveThread()}
|
||||
/>
|
||||
) : activeThreadWokeVisible ? (
|
||||
<ThreadStatusLine
|
||||
icon={<AlarmClockIcon />}
|
||||
label="Woke from snooze"
|
||||
actionLabel="Dismiss"
|
||||
onAction={acknowledgeActiveThreadWoke}
|
||||
/>
|
||||
) : null;
|
||||
}, [
|
||||
activeThread?.id,
|
||||
acknowledgeActiveThreadWoke,
|
||||
activeThreadSettled,
|
||||
activeThreadShell?.settledAt,
|
||||
activeThreadShell?.snoozedUntil,
|
||||
activeThreadSnoozed,
|
||||
activeThreadWokeVisible,
|
||||
canOperateThread,
|
||||
handleUnsnoozeActiveThread,
|
||||
handleUnsettleActiveThread,
|
||||
isUnsnoozing,
|
||||
handleUnsnoozeActiveThread,
|
||||
isUnsettling,
|
||||
isUnsnoozing,
|
||||
nowMinute,
|
||||
]);
|
||||
// Session-scoped dismissals, one key per (thread, snapshot). A set rather
|
||||
// than a single slot so dismissing the banner on one thread does not
|
||||
// resurface it on another thread dismissed earlier.
|
||||
const [dismissedResumeCompactionKeys, setDismissedResumeCompactionKeys] = useState<
|
||||
ReadonlySet<string>
|
||||
>(new Set());
|
||||
const resumeCompactionKey =
|
||||
activeThread && activeContextWindow
|
||||
? `${activeThread.id}:${activeContextWindow.updatedAt}`
|
||||
: null;
|
||||
const activeThreadHasCompactableConversation = serverVisibleTurnItems.some(
|
||||
({ item }) =>
|
||||
item.type === "user_message" &&
|
||||
@@ -7661,73 +7650,36 @@ export default function ChatView(props: ChatViewProps) {
|
||||
? "Compaction is unavailable for this provider"
|
||||
: "Compacting is unavailable right now"
|
||||
: null;
|
||||
const resumeCompactionBannerItem = useMemo<ComposerBannerStackItem | null>(() => {
|
||||
if (
|
||||
!activeThread ||
|
||||
!activeContextWindow ||
|
||||
resumeCompactionKey === null ||
|
||||
dismissedResumeCompactionKeys.has(resumeCompactionKey) ||
|
||||
resumeCompactionPermanentlyDismissed ||
|
||||
nativeResumeCompactionDismissed ||
|
||||
pendingUserInputs.length > 0 ||
|
||||
phase === "running" ||
|
||||
!shouldOfferResumeCompaction({
|
||||
provider: selectedProvider,
|
||||
usedTokens: activeContextWindow.usedTokens,
|
||||
updatedAt: activeContextWindow.updatedAt,
|
||||
now: `${nowMinute}:00.000Z`,
|
||||
})
|
||||
) {
|
||||
return null;
|
||||
// Tokens a stale Claude session would re-read on its next turn. While set,
|
||||
// Enter compacts first and the composer's send button says so; "Send with
|
||||
// full history" in its menu skips that once. Held queues and multi-model
|
||||
// sends never compact first, so the offer hides for them.
|
||||
const resumeCompactionTokens =
|
||||
activeContextWindow &&
|
||||
!resumeCompactionPermanentlyDismissed &&
|
||||
!nativeResumeCompactionDismissed &&
|
||||
!compactDisabled &&
|
||||
!hasHeldQueuedRuns &&
|
||||
multipleModelSelections === null &&
|
||||
shouldOfferResumeCompaction({
|
||||
provider: selectedProvider,
|
||||
usedTokens: activeContextWindow.usedTokens,
|
||||
updatedAt: activeContextWindow.updatedAt,
|
||||
now: `${nowMinute}:00.000Z`,
|
||||
})
|
||||
? activeContextWindow.usedTokens
|
||||
: null;
|
||||
// Set only for the synchronous span of a "Send with full history" submit;
|
||||
// onSend reads it before its first await.
|
||||
const keepFullHistoryOnceRef = useRef(false);
|
||||
const sendWithFullHistory = useCallback((send: () => void) => {
|
||||
keepFullHistoryOnceRef.current = true;
|
||||
try {
|
||||
send();
|
||||
} finally {
|
||||
keepFullHistoryOnceRef.current = false;
|
||||
}
|
||||
|
||||
const dismiss = () =>
|
||||
setDismissedResumeCompactionKeys((keys) => new Set(keys).add(resumeCompactionKey));
|
||||
const compactAction = (
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
disabled={compactDisabled}
|
||||
onClick={() => {
|
||||
if (compactDisabled) return;
|
||||
composerRef.current?.compactContext();
|
||||
}}
|
||||
>
|
||||
Compact
|
||||
</Button>
|
||||
);
|
||||
return {
|
||||
id: `resume-compaction:${resumeCompactionKey}`,
|
||||
variant: "info",
|
||||
icon: <Minimize2Icon />,
|
||||
title: "Resume with less context",
|
||||
description: `${formatContextWindowTokens(activeContextWindow.usedTokens)} tokens from earlier`,
|
||||
actions: compactDisabledReason ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={<span className="inline-flex">{compactAction}</span>} />
|
||||
<TooltipPopup side="top">{compactDisabledReason}</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : (
|
||||
compactAction
|
||||
),
|
||||
dismissLabel: "Keep full history",
|
||||
onDismiss: dismiss,
|
||||
};
|
||||
}, [
|
||||
activeContextWindow,
|
||||
activeThread,
|
||||
compactDisabled,
|
||||
compactDisabledReason,
|
||||
composerRef,
|
||||
dismissedResumeCompactionKeys,
|
||||
nativeResumeCompactionDismissed,
|
||||
nowMinute,
|
||||
pendingUserInputs.length,
|
||||
phase,
|
||||
resumeCompactionKey,
|
||||
resumeCompactionPermanentlyDismissed,
|
||||
selectedProvider,
|
||||
]);
|
||||
}, []);
|
||||
const handleRestoreThreadBranch = useCallback(() => {
|
||||
if (!canWriteSourceControl) return;
|
||||
if (gitStatusQuery.data?.hasWorkingTreeChanges) {
|
||||
@@ -7779,10 +7731,6 @@ export default function ChatView(props: ChatViewProps) {
|
||||
const backgroundWorkItems = [goalBannerItem, backgroundWorkBannerItem].filter(
|
||||
(item) => item !== null,
|
||||
);
|
||||
const resumeCompactionItems =
|
||||
resumeCompactionBannerItem === null ? [] : [resumeCompactionBannerItem];
|
||||
const wokeThreadItems = wokeThreadBannerItem === null ? [] : [wokeThreadBannerItem];
|
||||
const parkedThreadItems = parkedThreadBannerItem === null ? [] : [parkedThreadBannerItem];
|
||||
// The user asked for this one, so it leads the notice tier instead of trailing it.
|
||||
const usageLimitsItems = usageLimitsBanner === null ? [] : [usageLimitsBanner];
|
||||
const projectCloneItems = projectCloneBannerItem === null ? [] : [projectCloneBannerItem];
|
||||
@@ -7794,9 +7742,6 @@ export default function ChatView(props: ChatViewProps) {
|
||||
...projectCloneItems,
|
||||
...systemComposerBannerItems,
|
||||
...backgroundWorkItems,
|
||||
...resumeCompactionItems,
|
||||
...wokeThreadItems,
|
||||
...parkedThreadItems,
|
||||
];
|
||||
}
|
||||
return [
|
||||
@@ -7806,8 +7751,6 @@ export default function ChatView(props: ChatViewProps) {
|
||||
...projectCloneItems,
|
||||
...systemComposerBannerItems,
|
||||
...backgroundWorkItems,
|
||||
...resumeCompactionItems,
|
||||
...wokeThreadItems,
|
||||
{
|
||||
id: `branch-mismatch:${activeBranchMismatchKey}`,
|
||||
variant: "info",
|
||||
@@ -7846,7 +7789,6 @@ export default function ChatView(props: ChatViewProps) {
|
||||
setBranchMismatchDismissTick((tick) => tick + 1);
|
||||
},
|
||||
},
|
||||
...parkedThreadItems,
|
||||
];
|
||||
}, [
|
||||
activeBranchMismatchKey,
|
||||
@@ -7860,13 +7802,10 @@ export default function ChatView(props: ChatViewProps) {
|
||||
backgroundWorkBannerItem,
|
||||
goalBannerItem,
|
||||
localCheckoutBranchMismatch,
|
||||
parkedThreadBannerItem,
|
||||
projectCloneBannerItem,
|
||||
resumeCompactionBannerItem,
|
||||
showBranchMismatchBanner,
|
||||
systemComposerBannerItems,
|
||||
usageLimitsBanner,
|
||||
wokeThreadBannerItem,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -8692,6 +8631,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
},
|
||||
) => {
|
||||
e?.preventDefault();
|
||||
const keepFullHistory = keepFullHistoryOnceRef.current;
|
||||
// Typed out in full rather than picked from the menu. Attachments or contexts
|
||||
// mean the user is sending a prompt, so those go through as usual.
|
||||
if (
|
||||
@@ -9216,7 +9156,16 @@ export default function ChatView(props: ChatViewProps) {
|
||||
);
|
||||
const messageIdForSend = newMessageId();
|
||||
const messageCreatedAt = new Date().toISOString();
|
||||
const shouldQueueBehindActiveRun = phase === "running" && dispatchMode === "queue";
|
||||
// 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.
|
||||
const compactBeforeSend =
|
||||
resumeCompactionTokens !== null &&
|
||||
!keepFullHistory &&
|
||||
messageTextForSend.toLowerCase() !== "/compact";
|
||||
const turnDispatchMode = compactBeforeSend ? "queue" : dispatchMode;
|
||||
const shouldQueueBehindActiveRun =
|
||||
compactBeforeSend || (phase === "running" && dispatchMode === "queue");
|
||||
const outgoingMessageText = formatOutgoingPrompt({
|
||||
provider: ctxSelectedProvider,
|
||||
model: ctxSelectedModel,
|
||||
@@ -9799,6 +9748,22 @@ export default function ChatView(props: ChatViewProps) {
|
||||
failure = turnAttachmentsResult;
|
||||
}
|
||||
|
||||
if (failure === null && compactBeforeSend) {
|
||||
const compactResult = await startThreadTurn({
|
||||
environmentId,
|
||||
input: {
|
||||
threadId: threadIdForSend,
|
||||
message: { messageId: newMessageId(), role: "user", text: "/compact", attachments: [] },
|
||||
modelSelection: ctxSelectedModelSelection,
|
||||
runtimeMode,
|
||||
interactionMode: sendInteractionMode,
|
||||
},
|
||||
});
|
||||
if (compactResult._tag === "Failure") {
|
||||
failure = compactResult;
|
||||
}
|
||||
}
|
||||
|
||||
let backgroundDraftOpened = false;
|
||||
let turnStartSucceeded = false;
|
||||
if (failure === null && turnAttachmentsResult._tag === "Success") {
|
||||
@@ -9876,7 +9841,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
titleSeed: title,
|
||||
runtimeMode,
|
||||
interactionMode: sendInteractionMode,
|
||||
dispatchMode,
|
||||
dispatchMode: turnDispatchMode,
|
||||
...(bootstrap ? { bootstrap } : {}),
|
||||
createdAt: messageCreatedAt,
|
||||
},
|
||||
@@ -11324,6 +11289,7 @@ export default function ChatView(props: ChatViewProps) {
|
||||
{...(draftId ? { onWorktreeSetupWorkLocally } : {})}
|
||||
{...(onOpenWorktreeSetupTerminal ? { onOpenWorktreeSetupTerminal } : {})}
|
||||
isPreparingWorktree={!paintOnlyDisplayedTimeline && isPreparingWorktree}
|
||||
footer={paintOnlyDisplayedTimeline ? null : threadStatusLine}
|
||||
listRef={legendListRef}
|
||||
timelineEntries={displayedTimeline.entries}
|
||||
providerStatuses={
|
||||
@@ -11575,6 +11541,8 @@ export default function ChatView(props: ChatViewProps) {
|
||||
) : null
|
||||
}
|
||||
bannerItems={composerBannerItems}
|
||||
resumeCompactionTokens={resumeCompactionTokens}
|
||||
onSendWithFullHistory={sendWithFullHistory}
|
||||
// With attachments or contexts aboard the pick just inserts the
|
||||
// text, so it sends as a prompt like the typed path would.
|
||||
onUsageLimitsCommand={
|
||||
|
||||
@@ -1386,6 +1386,8 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
|
||||
onCompactContext?: (() => void) | undefined;
|
||||
compactDisabled: boolean;
|
||||
compactDisabledReason: string | null;
|
||||
compactBeforeSendTokens: number | null;
|
||||
onSendWithFullHistory: () => void;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
@@ -1424,6 +1426,8 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
|
||||
onPreviousPendingQuestion={props.onPreviousPendingQuestion}
|
||||
onInterrupt={props.onInterrupt}
|
||||
onImplementPlanInNewThread={props.onImplementPlanInNewThread}
|
||||
compactBeforeSendTokens={props.compactBeforeSendTokens}
|
||||
onSendWithFullHistory={props.onSendWithFullHistory}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
@@ -1543,6 +1547,10 @@ export interface ChatComposerProps {
|
||||
sendDisabledReason: string | null;
|
||||
isPreparingWorktree: boolean;
|
||||
bannerItems: readonly ComposerBannerStackItem[];
|
||||
/** Tokens Enter compacts before sending; null when the next send keeps full history. */
|
||||
resumeCompactionTokens: number | null;
|
||||
/** Runs `send` as a one-off send that keeps full history instead of compacting first. */
|
||||
onSendWithFullHistory: (send: () => void) => void;
|
||||
/** Picking /usage-limits from the menu is the action itself; the draft keeps nothing of it. */
|
||||
onUsageLimitsCommand?: (() => void) | undefined;
|
||||
environmentUnavailable: {
|
||||
@@ -3002,7 +3010,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
projectSelectionRequired ||
|
||||
environmentUnavailable !== null ||
|
||||
(!composerSendState.hasSendableContent && !showResumeAction);
|
||||
const collapsedComposerPrimaryActionLabel = showResumeAction ? "Resume thread" : "Send message";
|
||||
const collapsedComposerPrimaryActionLabel = showResumeAction
|
||||
? "Resume thread"
|
||||
: props.resumeCompactionTokens !== null
|
||||
? "Open composer to compact and send"
|
||||
: "Send message";
|
||||
const showMobilePendingAnswerActions =
|
||||
isMobileViewport && !isComposerCollapsedMobile && pendingPrimaryAction !== null;
|
||||
|
||||
@@ -4250,6 +4262,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
},
|
||||
[phase, settings.followUpBehavior, submitComposer],
|
||||
);
|
||||
const { onSendWithFullHistory } = props;
|
||||
const sendWithFullHistory = useCallback(
|
||||
() => onSendWithFullHistory(() => submitComposer()),
|
||||
[onSendWithFullHistory, submitComposer],
|
||||
);
|
||||
const submitCitationAndSend = useCallback(() => {
|
||||
submitComposer(
|
||||
undefined,
|
||||
@@ -6868,6 +6885,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
if (showResumeAction) onResume();
|
||||
// Compacting first is only sent from the labeled button, so expand to show it.
|
||||
else if (props.resumeCompactionTokens !== null) expandMobileComposer();
|
||||
else submitComposer();
|
||||
}}
|
||||
>
|
||||
@@ -7584,6 +7603,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
|
||||
onPreviousPendingQuestion={onPreviousActivePendingUserInputQuestion}
|
||||
onInterrupt={handleInterruptPrimaryAction}
|
||||
onImplementPlanInNewThread={handleImplementPlanInNewThreadPrimaryAction}
|
||||
compactBeforeSendTokens={props.resumeCompactionTokens}
|
||||
onSendWithFullHistory={sendWithFullHistory}
|
||||
compactDisabled={
|
||||
compactDisabled || noProviderAvailable || isSendBusy || isConnecting
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { CheckIcon, ChevronDownIcon, ChevronLeftIcon, PlayIcon } from "lucide-re
|
||||
import { CornerUpRight, ListPlus } from "lucide";
|
||||
import { MorphIcon } from "~/components/MorphIcon";
|
||||
import { useEnvironmentIdentificationMode } from "~/hooks/useSettings";
|
||||
import { formatContextWindowTokens } from "~/lib/contextWindow";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { useShortcutModifierState } from "../../shortcutModifierState";
|
||||
import { StageBackdropButtonArt, useSidebarStageBackdropVariant } from "../SidebarStageBackdrop";
|
||||
@@ -50,6 +51,9 @@ interface ComposerPrimaryActionsProps {
|
||||
onPreviousPendingQuestion: () => void;
|
||||
onInterrupt: () => void;
|
||||
onImplementPlanInNewThread: () => void;
|
||||
/** Tokens a stale session would re-read. When set, Enter compacts first and the button says so. */
|
||||
compactBeforeSendTokens?: number | null;
|
||||
onSendWithFullHistory?: () => void;
|
||||
}
|
||||
|
||||
const formatPendingPrimaryActionLabel = (input: {
|
||||
@@ -103,6 +107,8 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
|
||||
onPreviousPendingQuestion,
|
||||
onInterrupt,
|
||||
onImplementPlanInNewThread,
|
||||
compactBeforeSendTokens = null,
|
||||
onSendWithFullHistory,
|
||||
}: ComposerPrimaryActionsProps) {
|
||||
const pointerFocusProps = preserveComposerFocusOnPointerDown
|
||||
? { onPointerDown: preventPointerFocus }
|
||||
@@ -260,6 +266,59 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
|
||||
}
|
||||
|
||||
const showResume = canResume && !hasSendableContent && !isEditingQueuedMessage;
|
||||
const sendBlocked = isSendBusy || isSendDisabled || isConnecting || isEnvironmentUnavailable;
|
||||
|
||||
if (compactBeforeSendTokens !== null && !showResume && !isEditingQueuedMessage) {
|
||||
const tokens = formatContextWindowTokens(compactBeforeSendTokens);
|
||||
return (
|
||||
<div data-chat-composer-compact-send="true" className="flex items-center justify-end">
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<button
|
||||
type="submit"
|
||||
className={cn(
|
||||
messageActionPillClassName,
|
||||
"h-9 rounded-r-none sm:h-8",
|
||||
compact ? "px-3" : "px-4",
|
||||
)}
|
||||
{...pointerFocusProps}
|
||||
onClick={onSubmitMessage}
|
||||
disabled={sendBlocked || !hasSendableContent}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{isConnecting || isSendBusy ? "Sending..." : "Compact and send"}
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>Summarize {tokens} tokens of history, then send</TooltipPopup>
|
||||
</Tooltip>
|
||||
<Menu>
|
||||
<MenuTrigger
|
||||
render={
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
messageActionPillClassName,
|
||||
"h-9 rounded-l-none border-l border-message-action-foreground/20 px-2 sm:h-8",
|
||||
)}
|
||||
aria-label="Send options"
|
||||
{...pointerFocusProps}
|
||||
disabled={sendBlocked || !hasSendableContent}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ChevronDownIcon className="size-3.5" />
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="end" side="top" {...composerFloatingLayerProps}>
|
||||
<MenuItem disabled={sendBlocked} onClick={onSendWithFullHistory}>
|
||||
Send with full history ({tokens} tokens)
|
||||
</MenuItem>
|
||||
</MenuPopup>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const submitLabel = showResume
|
||||
? "Resume thread"
|
||||
: isEditingQueuedMessage
|
||||
|
||||
@@ -371,11 +371,18 @@ const TIMELINE_LIST_HEADER = <div className="h-3 sm:h-4" />;
|
||||
const TIMELINE_LIST_FADE_HEADER = (
|
||||
<div className="h-[var(--workspace-titlebar-scroll-fade-height)]" />
|
||||
);
|
||||
function TimelineListFooter({ composerInset }: { readonly composerInset: number }) {
|
||||
function TimelineListFooter({
|
||||
composerInset,
|
||||
children,
|
||||
}: {
|
||||
readonly composerInset: number;
|
||||
readonly children?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div aria-hidden>
|
||||
<div style={{ height: composerInset }} />
|
||||
<div className="h-3 sm:h-4" />
|
||||
<div>
|
||||
{children}
|
||||
<div aria-hidden style={{ height: composerInset }} />
|
||||
<div aria-hidden className="h-3 sm:h-4" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -434,6 +441,8 @@ interface MessagesTimelineProps {
|
||||
onOpenWorktreeSetupTerminal?: (terminalId: string) => void;
|
||||
isPreparingWorktree?: boolean;
|
||||
isCompacting?: boolean;
|
||||
/** Thread state shown after the last message, such as a settled or snoozed line. */
|
||||
footer?: ReactNode;
|
||||
|
||||
listRef: React.RefObject<LegendListRef | null>;
|
||||
timelineEntries: ReadonlyArray<TimelineEntry>;
|
||||
@@ -512,6 +521,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
activeTurnInProgress,
|
||||
activeTurnStartedAt = null,
|
||||
worktreeSetup = null,
|
||||
footer = null,
|
||||
onCancelWorktreeSetup,
|
||||
retryableWorkspacePreparationRunIds = EMPTY_RUN_IDS,
|
||||
onRetryWorkspacePreparation,
|
||||
@@ -988,8 +998,12 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
[shouldRestoreVisibleContentPosition],
|
||||
);
|
||||
const timelineListFooter = useMemo(
|
||||
() => <TimelineListFooter composerInset={anchoredEndSpace ? 0 : contentInsetEndAdjustment} />,
|
||||
[anchoredEndSpace, contentInsetEndAdjustment],
|
||||
() => (
|
||||
<TimelineListFooter composerInset={anchoredEndSpace ? 0 : contentInsetEndAdjustment}>
|
||||
{footer}
|
||||
</TimelineListFooter>
|
||||
),
|
||||
[anchoredEndSpace, contentInsetEndAdjustment, footer],
|
||||
);
|
||||
|
||||
const measureContentOverflow = useCallback(
|
||||
@@ -1308,7 +1322,9 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
rows.length === 0 &&
|
||||
!isWorking &&
|
||||
parentThreadLink === null &&
|
||||
historyControls === undefined
|
||||
historyControls === undefined &&
|
||||
// A status line (settled, snoozed) still needs the list, whose footer renders it.
|
||||
footer === null
|
||||
) {
|
||||
if (hideEmptyPlaceholder) {
|
||||
// Occupy the pane with the theme surface so a thread switch cannot
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import { InlineButton } from "../ui/button";
|
||||
|
||||
/**
|
||||
* One quiet line after the last message for thread state that does not change
|
||||
* what Enter does: settled, snoozed, or just woke. Sending a message clears each of
|
||||
* them, so the action is only the explicit way out.
|
||||
*/
|
||||
export function ThreadStatusLine(props: {
|
||||
readonly icon: ReactNode;
|
||||
readonly label: string;
|
||||
readonly actionLabel: string;
|
||||
readonly actionDisabled?: boolean;
|
||||
readonly onAction: () => void;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
data-chat-thread-status-line="true"
|
||||
className="mx-auto flex w-full min-w-0 max-w-(--chat-content-max-width) items-center gap-1.5 px-4 pb-2 text-muted-foreground text-xs [&_svg]:size-3.5 [&_svg]:shrink-0"
|
||||
>
|
||||
{props.icon}
|
||||
<span className="min-w-0 truncate">{props.label}</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<InlineButton tone="muted" disabled={props.actionDisabled} onClick={props.onAction}>
|
||||
{props.actionLabel}
|
||||
</InlineButton>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -49,9 +49,12 @@ Set **Auto-compact after** in the Claude provider settings to an integer between
|
||||
window. Leave it empty for Claude Code's default.
|
||||
|
||||
You can also send `/compact` in an existing conversation. Web and desktop offer
|
||||
**Compact context** from the context meter and may suggest it when you return to
|
||||
a large older thread. See [commands and skills](./composer.md#commands-and-skills)
|
||||
for using composer commands.
|
||||
**Compact context** from the context meter. When you return to a large thread
|
||||
after more than an hour, the send button changes to **Compact and send**: Enter
|
||||
summarizes the history first, then sends your message. To keep the full history
|
||||
for that message, open the menu next to the button and choose **Send with full
|
||||
history**. See [commands and skills](./composer.md#commands-and-skills) for using
|
||||
composer commands.
|
||||
|
||||
## Usage limits
|
||||
|
||||
|
||||
Reference in new issue
Block a user