Skip to content

Commit 85fdfc0

Browse files
committed
Simplify freebuff end-session button: merge StopButton+EndSessionButton, remove redundant IS_FREEBUFF guard, extract END_SESSION_MESSAGE constant
1 parent be87083 commit 85fdfc0

5 files changed

Lines changed: 53 additions & 37 deletions

File tree

cli/src/chat.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ import { reportActivity } from './utils/activity-tracker'
5757
import { trackEvent } from './utils/analytics'
5858
import { showClipboardMessage } from './utils/clipboard'
5959
import { readClipboardImage } from './utils/clipboard-image'
60-
import { IS_FREEBUFF } from './utils/constants'
60+
import { endAndRejoinFreebuffSession } from './hooks/use-freebuff-session'
61+
import { END_SESSION_MESSAGE, IS_FREEBUFF } from './utils/constants'
62+
import { getSystemMessage } from './utils/message-history'
6163
import { getInputModeConfig } from './utils/input-modes'
6264

6365
import {
@@ -1453,6 +1455,13 @@ export const Chat = ({
14531455
scrollToLatest={scrollToLatest}
14541456
statusIndicatorState={statusIndicatorState}
14551457
onStop={chatKeyboardHandlers.onInterruptStream}
1458+
onEndSession={() => {
1459+
setMessages((prev) => [
1460+
...prev,
1461+
getSystemMessage(END_SESSION_MESSAGE),
1462+
])
1463+
endAndRejoinFreebuffSession().catch(() => {})
1464+
}}
14561465
freebuffSession={freebuffSession}
14571466
/>
14581467
)}

cli/src/commands/command-registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useChatStore } from '../state/chat-store'
1616
import { useFeedbackStore } from '../state/feedback-store'
1717
import { useLoginStore } from '../state/login-store'
1818
import { getChatGptOAuthStatus } from '../utils/chatgpt-oauth'
19-
import { AGENT_MODES, IS_FREEBUFF } from '../utils/constants'
19+
import { AGENT_MODES, END_SESSION_MESSAGE, IS_FREEBUFF } from '../utils/constants'
2020
import { getSystemMessage, getUserMessage } from '../utils/message-history'
2121
import { capturePendingAttachments } from '../utils/pending-attachments'
2222
import { getSkillByName } from '../utils/skill-registry'
@@ -622,7 +622,7 @@ const ALL_COMMANDS: CommandDefinition[] = [
622622
params.setMessages((prev) => [
623623
...prev,
624624
getUserMessage(params.inputValue.trim()),
625-
getSystemMessage('Ending session and returning to the waiting room…'),
625+
getSystemMessage(END_SESSION_MESSAGE),
626626
])
627627
params.saveToHistory(params.inputValue.trim())
628628
clearInput(params)

cli/src/components/status-bar.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,46 @@ import { getFreebuffModel } from '@codebuff/common/constants/freebuff-models'
22
import { TextAttributes } from '@opentui/core'
33
import React, { useEffect, useState } from 'react'
44

5+
import { Button } from './button'
56
import { ScrollToBottomButton } from './scroll-to-bottom-button'
67
import { ShimmerText } from './shimmer-text'
7-
import { StopButton } from './stop-button'
8+
89
import { useFreebuffSessionProgress } from '../hooks/use-freebuff-session-progress'
910
import { useTheme } from '../hooks/use-theme'
1011
import { formatElapsedTime } from '../utils/format-elapsed-time'
1112

1213
import type { FreebuffSessionResponse } from '../types/freebuff-session'
1314
import type { StatusIndicatorState } from '../utils/status-indicator-state'
1415

16+
/** A small status-bar action button with hover-bold styling. */
17+
const StatusActionButton = ({
18+
children,
19+
onClick,
20+
}: {
21+
children: React.ReactNode
22+
onClick: () => void
23+
}) => {
24+
const theme = useTheme()
25+
const [hovered, setHovered] = useState(false)
26+
27+
return (
28+
<Button
29+
style={{ paddingLeft: 1, paddingRight: 1 }}
30+
onClick={onClick}
31+
onMouseOver={() => setHovered(true)}
32+
onMouseOut={() => setHovered(false)}
33+
>
34+
<text>
35+
<span
36+
fg={theme.secondary}
37+
attributes={hovered ? TextAttributes.BOLD : TextAttributes.NONE}
38+
>
39+
{children}
40+
</span>
41+
</text>
42+
</Button>
43+
)
44+
}
1545

1646
const SHIMMER_INTERVAL_MS = 160
1747

@@ -42,6 +72,7 @@ interface StatusBarProps {
4272
scrollToLatest: () => void
4373
statusIndicatorState: StatusIndicatorState
4474
onStop?: () => void
75+
onEndSession?: () => void
4576
freebuffSession: FreebuffSessionResponse | null
4677
}
4778

@@ -51,6 +82,7 @@ export const StatusBar = ({
5182
scrollToLatest,
5283
statusIndicatorState,
5384
onStop,
85+
onEndSession,
5486
freebuffSession,
5587
}: StatusBarProps) => {
5688
const theme = useTheme()
@@ -229,7 +261,10 @@ export const StatusBar = ({
229261
>
230262
<text style={{ wrapMode: 'none' }}>{elapsedTimeContent}</text>
231263
{onStop && (statusIndicatorState.kind === 'waiting' || statusIndicatorState.kind === 'streaming') && (
232-
<StopButton onClick={onStop} />
264+
<StatusActionButton onClick={onStop}>■ Esc</StatusActionButton>
265+
)}
266+
{onEndSession && statusIndicatorState.kind === 'idle' && freebuffSession?.status === 'active' && (
267+
<StatusActionButton onClick={onEndSession}>✕ End session</StatusActionButton>
233268
)}
234269
{sessionProgress !== null &&
235270
sessionProgress.remainingMs < COUNTDOWN_VISIBLE_MS &&

cli/src/components/stop-button.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.

cli/src/utils/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { getCliEnv } from './env'
88
*/
99
export const IS_FREEBUFF = getCliEnv().FREEBUFF_MODE === 'true'
1010

11+
/** Message shown when the user ends a freebuff session early. */
12+
export const END_SESSION_MESSAGE =
13+
'Ending session and returning to the waiting room…'
14+
1115
// Agent IDs that should not be rendered in the CLI UI
1216
export const HIDDEN_AGENT_IDS = ['codebuff/context-pruner'] as const
1317

0 commit comments

Comments
 (0)