Skip to content
Merged
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
23 changes: 23 additions & 0 deletions agents/__tests__/base2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, test } from 'bun:test'

import {
FREEBUFF_DEEPSEEK_V4_PRO_MODEL_ID,
FREEBUFF_KIMI_MODEL_ID,
FREEBUFF_MINIMAX_MODEL_ID,
} from '@codebuff/common/constants/freebuff-models'

import { createBase2 } from '../base2/base2'

describe('base2 reviewer selection', () => {
test.each([
[FREEBUFF_MINIMAX_MODEL_ID, 'code-reviewer-minimax'],
[FREEBUFF_KIMI_MODEL_ID, 'code-reviewer-kimi'],
[FREEBUFF_DEEPSEEK_V4_PRO_MODEL_ID, 'code-reviewer-deepseek'],
])('uses matching reviewer for model %p', (model, expectedReviewer) => {
const base2 = createBase2('free', { model })

expect(base2.spawnableAgents).toContain(expectedReviewer)
expect(base2.instructionsPrompt).toContain(`Spawn a ${expectedReviewer}`)
expect(base2.stepPrompt).toContain(`spawn a ${expectedReviewer}`)
})
})
1 change: 0 additions & 1 deletion agents/base2/base2-free-deepseek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const definition = {
...createBase2('free', {
noAskUser: true,
model: FREEBUFF_DEEPSEEK_V4_PRO_MODEL_ID,
freeCodeReviewerAgentId: 'code-reviewer-deepseek',
}),
id: 'base2-free-deepseek',
displayName: 'Buffy the DeepSeek Free Orchestrator',
Expand Down
1 change: 0 additions & 1 deletion agents/base2/base2-free-kimi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { createBase2 } from './base2'
const definition = {
...createBase2('free', {
model: FREEBUFF_KIMI_MODEL_ID,
freeCodeReviewerAgentId: 'code-reviewer-kimi',
}),
id: 'base2-free-kimi',
displayName: 'Buffy the Kimi Free Orchestrator',
Expand Down
4 changes: 1 addition & 3 deletions agents/base2/base2-free.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createBase2 } from './base2'

const definition = {
...createBase2('free', {
freeCodeReviewerAgentId: 'code-reviewer-minimax',
}),
...createBase2('free'),
id: 'base2-free',
displayName: 'Buffy the Free Orchestrator',
}
Expand Down
5 changes: 3 additions & 2 deletions agents/base2/base2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FREEBUFF_GEMINI_THINKER_STEP_PROMPT,
FREEBUFF_GEMINI_THINKER_SYSTEM_INSTRUCTION,
} from '@codebuff/common/constants/freebuff-gemini-thinker'
import { FREEBUFF_REVIEWER_AGENT_ID_BY_MODEL } from '@codebuff/common/constants/free-agents'
import {
canFreebuffModelSpawnGeminiThinker,
FREEBUFF_MINIMAX_MODEL_ID,
Expand All @@ -24,7 +25,6 @@ export function createBase2(
noAskUser?: boolean
model?: SecretAgentDefinition['model']
providerOptions?: SecretAgentDefinition['providerOptions']
freeCodeReviewerAgentId?: string
},
): Omit<SecretAgentDefinition, 'id'> {
const {
Expand All @@ -33,7 +33,6 @@ export function createBase2(
noAskUser = false,
model: modelOverride,
providerOptions,
freeCodeReviewerAgentId = 'code-reviewer-lite',
} = options ?? {}
const isDefault = mode === 'default'
const isFast = mode === 'fast'
Expand All @@ -56,6 +55,8 @@ export function createBase2(
// reasoning. Fast MiniMax omits the extra round trip by construction.
const hasFreeGeminiThinker =
isFree && canFreebuffModelSpawnGeminiThinker(model)
const freeCodeReviewerAgentId =
FREEBUFF_REVIEWER_AGENT_ID_BY_MODEL[model] ?? 'code-reviewer-lite'
const defaultProviderOptions = isFree
? {
data_collection: 'deny' as const,
Expand Down
2 changes: 1 addition & 1 deletion cli/release/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codebuff",
"version": "1.0.671",
"version": "1.0.673",
"description": "AI coding agent",
"license": "MIT",
"bin": {
Expand Down
74 changes: 52 additions & 22 deletions cli/src/components/chat-history-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { SelectableList } from './selectable-list'
import { useSearchableList } from '../hooks/use-searchable-list'
import { useTerminalLayout } from '../hooks/use-terminal-layout'
import { useTheme } from '../hooks/use-theme'
import { getAllChats, formatRelativeTime } from '../utils/chat-history'
import {
deleteChatSession,
formatRelativeTime,
getAllChats,
} from '../utils/chat-history'

import type { SelectableListItem } from './selectable-list'

Expand All @@ -21,6 +25,7 @@ const LAYOUT = {
MAX_RENDERED_CHATS: 100, // Only render this many in the list
TIME_COL_WIDTH: 12, // e.g., "2 hours ago"
MSGS_COL_WIDTH: 8, // e.g., "99 msgs"
DELETE_COL_WIDTH: 6, // e.g., "[×]" + marginRight
GAP_WIDTH: 3, // gap between columns
} as const

Expand All @@ -42,34 +47,39 @@ export const ChatHistoryScreen: React.FC<ChatHistoryScreenProps> = ({
const contentWidth = terminalWidth - LAYOUT.CONTENT_PADDING

// Two-phase loading: load initial chats immediately, then more in background
const initialChats = useMemo(() => getAllChats(LAYOUT.INITIAL_CHATS), [])
const [backgroundChats, setBackgroundChats] = useState<typeof initialChats>(
[],
)
const [chats, setChats] = useState(() => getAllChats(LAYOUT.INITIAL_CHATS))
const [statusMessage, setStatusMessage] = useState<string | null>(null)

// Load more chats in the background after initial render
useEffect(() => {
// Use setTimeout to defer the expensive loading to after first paint
const timer = setTimeout(() => {
const moreChats = getAllChats(
LAYOUT.INITIAL_CHATS + LAYOUT.BACKGROUND_CHATS,
)
// Only keep the chats beyond the initial set
setBackgroundChats(moreChats.slice(LAYOUT.INITIAL_CHATS))
setChats(getAllChats(LAYOUT.INITIAL_CHATS + LAYOUT.BACKGROUND_CHATS))
}, 0)
return () => clearTimeout(timer)
}, [])

// Combine initial and background chats
const chats = useMemo(
() => [...initialChats, ...backgroundChats],
[initialChats, backgroundChats],
)
const handleDeleteChat = useCallback((chatId: string) => {
const deleted = deleteChatSession(chatId)
if (deleted) {
setChats((prev) => prev.filter((chat) => chat.chatId !== chatId))
setStatusMessage('Chat deleted')
return
}

setStatusMessage('Could not delete chat')
}, [])

// Calculate available width for the prompt text (last column, variable width)
// Format: "[time] [msgs] [prompt...]"
// Format: "[time] [msgs] [prompt...] [×]"
// reservedWidth accounts for: time col, msgs col, delete button area,
// 2 gaps between columns, list border (2), scrollbar (1), and button padding (2)
const reservedWidth =
LAYOUT.TIME_COL_WIDTH + LAYOUT.MSGS_COL_WIDTH + LAYOUT.GAP_WIDTH * 2 + 2 // +2 for padding
LAYOUT.TIME_COL_WIDTH +
LAYOUT.MSGS_COL_WIDTH +
LAYOUT.DELETE_COL_WIDTH +
LAYOUT.GAP_WIDTH * 2 +
5 // border + scrollbar + button padding
const maxPromptWidth = Math.max(20, contentWidth - reservedWidth)

// Truncate text to fit single line
Expand All @@ -81,8 +91,10 @@ export const ChatHistoryScreen: React.FC<ChatHistoryScreenProps> = ({

// Pad text to fixed width (right-pad with spaces)
const padRight = (text: string, width: number): string => {
if (text.length >= width) return text.slice(0, width)
return text + ' '.repeat(width - text.length)
// Use Array.from to count code points so emoji/wide chars don't break padding
const len = Array.from(text).length
if (len >= width) return text
return text + ' '.repeat(width - len)
}

// Convert chats to SelectableListItem format with aligned columns
Expand All @@ -98,7 +110,10 @@ export const ChatHistoryScreen: React.FC<ChatHistoryScreenProps> = ({
`${chat.messageCount} msgs`,
LAYOUT.MSGS_COL_WIDTH,
)
const prompt = truncateText(chat.lastPrompt, maxPromptWidth)
const prompt = padRight(
truncateText(chat.lastPrompt, maxPromptWidth),
maxPromptWidth,
)

return {
id: chat.chatId,
Expand Down Expand Up @@ -146,6 +161,13 @@ export const ChatHistoryScreen: React.FC<ChatHistoryScreenProps> = ({
[onSelectChat],
)

const handleChatDelete = useCallback(
(item: SelectableListItem) => {
handleDeleteChat(item.id)
},
[handleDeleteChat],
)

// Handle keyboard input
const handleKeyIntercept = useCallback(
(key: { name?: string; shift?: boolean; ctrl?: boolean }) => {
Expand Down Expand Up @@ -275,9 +297,11 @@ export const ChatHistoryScreen: React.FC<ChatHistoryScreenProps> = ({
items={filteredItems.slice(0, LAYOUT.MAX_RENDERED_CHATS)}
focusedIndex={focusedIndex}
onSelect={handleChatSelect}
actionLabel="[×]"
onAction={handleChatDelete}
onFocusChange={handleFocusChange}
emptyMessage={
initialChats.length === 0
chats.length === 0
? 'No chat history yet'
: searchQuery
? 'No matching chats'
Expand Down Expand Up @@ -314,8 +338,14 @@ export const ChatHistoryScreen: React.FC<ChatHistoryScreenProps> = ({
{/* Help text */}
<box style={{ flexGrow: 1, flexShrink: 1 }}>
<text style={{ fg: theme.muted }}>
↑↓ navigate · Enter select · Esc cancel
↑↓ navigate · Enter select · Click [×] to remove · Esc cancel
</text>
{statusMessage && (
<text style={{ fg: theme.muted }}>
{' · '}
{statusMessage}
</text>
)}
</box>

{/* Buttons - hidden on narrow screens */}
Expand Down
6 changes: 2 additions & 4 deletions cli/src/components/freebuff-model-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isFreebuffModelAvailable,
isFreebuffPremiumModelId,
} from '@codebuff/common/constants/freebuff-models'
import { getRateLimitsByModel } from '@codebuff/common/types/freebuff-session'

import { joinFreebuffQueue } from '../hooks/use-freebuff-session'
import { useNow } from '../hooks/use-now'
Expand Down Expand Up @@ -127,10 +128,7 @@ export const FreebuffModelSelector: React.FC = () => {
}, [now, selectedModel, session, setSelectedModel])

const committedModelId = session?.status === 'queued' ? session.model : null
const rateLimitsByModel =
session && 'rateLimitsByModel' in session
? session.rateLimitsByModel
: undefined
const rateLimitsByModel = getRateLimitsByModel(session)

const BUTTON_CHROME = 4 // 2 border + 2 padding
const NAME_GAP = 2 // spaces between name column and details column
Expand Down
Loading
Loading