Skip to content

Commit 9cd633b

Browse files
committed
Clean up validating agents
1 parent cda203c commit 9cd633b

File tree

4 files changed

+42
-84
lines changed

4 files changed

+42
-84
lines changed

cli/src/app.tsx

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import os from 'os'
22
import path from 'path'
33

4-
import { pluralize } from '@codebuff/common/util/string'
54
import { NetworkError, RETRYABLE_ERROR_CODES } from '@codebuff/sdk'
6-
import { useCallback, useMemo, useRef, useState } from 'react'
5+
import { useCallback, useMemo, useRef } from 'react'
76
import { useShallow } from 'zustand/react/shallow'
87

98
import { Chat } from './chat'
109
import { LoginModal } from './components/login-modal'
1110
import { TerminalLink } from './components/terminal-link'
12-
import { ToolCallItem } from './components/tools/tool-call-item'
13-
import { useAgentValidation } from './hooks/use-agent-validation'
1411
import { useAuthQuery } from './hooks/use-auth-query'
1512
import { useAuthState } from './hooks/use-auth-state'
1613
import { useLogo } from './hooks/use-logo'
@@ -30,11 +27,6 @@ interface AppProps {
3027
agentId?: string
3128
requireAuth: boolean | null
3229
hasInvalidCredentials: boolean
33-
loadedAgentsData: {
34-
agents: Array<{ id: string; displayName: string }>
35-
agentsDir: string
36-
} | null
37-
validationErrors: Array<{ id: string; message: string }>
3830
fileTree: FileTreeNode[]
3931
continueChat: boolean
4032
continueChatId?: string
@@ -45,8 +37,6 @@ export const App = ({
4537
agentId,
4638
requireAuth,
4739
hasInvalidCredentials,
48-
loadedAgentsData,
49-
validationErrors,
5040
fileTree,
5141
continueChat,
5242
continueChatId,
@@ -55,7 +45,6 @@ export const App = ({
5545
const theme = useTheme()
5646
const { textBlock: logoBlock } = useLogo({ availableWidth: contentMaxWidth })
5747

58-
const [isAgentListCollapsed, setIsAgentListCollapsed] = useState(true)
5948
const inputRef = useRef<MultilineInputHandle | null>(null)
6049
const { setInputFocused, setIsFocusSupported, resetChatStore } = useChatStore(
6150
useShallow((store) => ({
@@ -93,9 +82,6 @@ export const App = ({
9382
resetChatStore,
9483
})
9584

96-
// Agent validation
97-
useAgentValidation(validationErrors)
98-
9985
const headerContent = useMemo(() => {
10086
const homeDir = os.homedir()
10187
const repoRoot = getProjectRoot()
@@ -104,19 +90,6 @@ export const App = ({
10490
? repoRoot
10591
: `~/${relativePath}`
10692

107-
const sortedAgents = loadedAgentsData
108-
? [...loadedAgentsData.agents].sort((a, b) => {
109-
const displayNameComparison = (a.displayName || '')
110-
.toLowerCase()
111-
.localeCompare((b.displayName || '').toLowerCase())
112-
113-
return (
114-
displayNameComparison ||
115-
a.id.toLowerCase().localeCompare(b.id.toLowerCase())
116-
)
117-
})
118-
: null
119-
12093
return (
12194
<box
12295
style={{
@@ -154,7 +127,7 @@ export const App = ({
154127
</text>
155128
</box>
156129
)
157-
}, [loadedAgentsData, logoBlock, theme, isAgentListCollapsed])
130+
}, [logoBlock, theme])
158131

159132
// Derive auth reachability + retrying state inline from authQuery error
160133
const authError = authQuery.error
@@ -195,7 +168,6 @@ export const App = ({
195168
headerContent={headerContent}
196169
initialPrompt={initialPrompt}
197170
agentId={agentId}
198-
validationErrors={validationErrors}
199171
fileTree={fileTree}
200172
inputRef={inputRef}
201173
setIsAuthenticated={setIsAuthenticated}

cli/src/chat.tsx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ import { getProjectRoot } from './project-files'
4646
import { useChatStore } from './state/chat-store'
4747
import { useFeedbackStore } from './state/feedback-store'
4848
import { usePublishStore } from './state/publish-store'
49-
import { addClipboardPlaceholder, addPendingImageFromFile, validateAndAddImage } from './utils/add-pending-image'
49+
import {
50+
addClipboardPlaceholder,
51+
addPendingImageFromFile,
52+
validateAndAddImage,
53+
} from './utils/add-pending-image'
5054
import { createChatScrollAcceleration } from './utils/chat-scroll-accel'
5155
import { showClipboardMessage } from './utils/clipboard'
5256
import { readClipboardImage } from './utils/clipboard-image'
@@ -80,7 +84,6 @@ export const Chat = ({
8084
headerContent,
8185
initialPrompt,
8286
agentId,
83-
validationErrors,
8487
fileTree,
8588
inputRef,
8689
setIsAuthenticated,
@@ -93,7 +96,6 @@ export const Chat = ({
9396
headerContent: React.ReactNode
9497
initialPrompt: string | null
9598
agentId?: string
96-
validationErrors: Array<{ id: string; message: string }>
9799
fileTree: FileTreeNode[]
98100
inputRef: React.MutableRefObject<MultilineInputHandle | null>
99101
setIsAuthenticated: Dispatch<SetStateAction<boolean | null>>
@@ -124,7 +126,7 @@ export const Chat = ({
124126
const theme = useTheme()
125127
const markdownPalette = useMemo(() => createMarkdownPalette(theme), [theme])
126128

127-
const { validate: validateAgents } = useAgentValidation(validationErrors)
129+
const { validate: validateAgents } = useAgentValidation()
128130

129131
// Subscribe to ask_user bridge to trigger form display
130132
useAskUserBridge()
@@ -396,7 +398,6 @@ export const Chat = ({
396398
const setInputMode = useChatStore((state) => state.setInputMode)
397399
const askUserState = useChatStore((state) => state.askUserState)
398400

399-
400401
const {
401402
slashContext,
402403
mentionContext,
@@ -563,7 +564,7 @@ export const Chat = ({
563564
const ghostModeMessages = pendingBashMessages.filter(
564565
(msg) => !msg.isRunning && !msg.addedToHistory,
565566
)
566-
567+
567568
// Add ghost mode messages to UI history
568569
for (const msg of ghostModeMessages) {
569570
addBashMessageToHistory({
@@ -575,7 +576,7 @@ export const Chat = ({
575576
setMessages,
576577
})
577578
}
578-
579+
579580
// Mark ghost mode messages as added to history (so they don't show as ghost UI)
580581
// but keep them in pendingBashMessages so they get sent to LLM with next user message
581582
if (ghostModeMessages.length > 0) {
@@ -654,7 +655,13 @@ export const Chat = ({
654655
})
655656
setSlashSelectedIndex(0)
656657
},
657-
[slashMatches, slashContext, inputValue, setInputValue, setSlashSelectedIndex],
658+
[
659+
slashMatches,
660+
slashContext,
661+
inputValue,
662+
setInputValue,
663+
setSlashSelectedIndex,
664+
],
658665
)
659666

660667
const handleMentionItemClick = useCallback(
@@ -722,19 +729,15 @@ export const Chat = ({
722729
})),
723730
)
724731

725-
const {
726-
publishMode,
727-
openPublishMode,
728-
closePublish,
729-
preSelectAgents,
730-
} = usePublishStore(
731-
useShallow((state) => ({
732-
publishMode: state.publishMode,
733-
openPublishMode: state.openPublishMode,
734-
closePublish: state.closePublish,
735-
preSelectAgents: state.preSelectAgents,
736-
})),
737-
)
732+
const { publishMode, openPublishMode, closePublish, preSelectAgents } =
733+
usePublishStore(
734+
useShallow((state) => ({
735+
publishMode: state.publishMode,
736+
openPublishMode: state.openPublishMode,
737+
closePublish: state.closePublish,
738+
preSelectAgents: state.preSelectAgents,
739+
})),
740+
)
738741

739742
const publishMutation = usePublishMutation()
740743

@@ -1280,10 +1283,7 @@ export const Chat = ({
12801283
{pendingBashMessages
12811284
.filter((msg) => !msg.addedToHistory)
12821285
.map((msg) => (
1283-
<PendingBashMessage
1284-
key={`pending-bash-${msg.id}`}
1285-
message={msg}
1286-
/>
1286+
<PendingBashMessage key={`pending-bash-${msg.id}`} message={msg} />
12871287
))}
12881288
</scrollbox>
12891289

cli/src/hooks/use-agent-validation.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { validateAgents } from '@codebuff/sdk'
22
import { useCallback, useState } from 'react'
33

4-
54
import { loadAgentDefinitions } from '../utils/local-agent-registry'
65
import { logger } from '../utils/logger'
6+
import { filterNetworkErrors } from '../utils/validation-error-helpers'
77

88
export type ValidationError = {
99
id: string
@@ -25,11 +25,10 @@ type UseAgentValidationResult = {
2525
* Hook that provides agent validation functionality.
2626
* Call validate() manually to trigger validation (e.g., on message send).
2727
*/
28-
export const useAgentValidation = (
29-
initialErrors: ValidationError[] = [],
30-
): UseAgentValidationResult => {
31-
const [validationErrors, setValidationErrors] =
32-
useState<ValidationError[]>(initialErrors)
28+
export const useAgentValidation = (): UseAgentValidationResult => {
29+
const [validationErrors, setValidationErrors] = useState<ValidationError[]>(
30+
[],
31+
)
3332
const [isValidating, setIsValidating] = useState(false)
3433

3534
// Validate agents and update state
@@ -48,8 +47,11 @@ export const useAgentValidation = (
4847
setValidationErrors([])
4948
return { success: true, errors: [] }
5049
} else {
51-
setValidationErrors(validationResult.validationErrors)
52-
return { success: false, errors: validationResult.validationErrors }
50+
const filteredValidationErrors = filterNetworkErrors(
51+
validationResult.validationErrors,
52+
)
53+
setValidationErrors(filteredValidationErrors)
54+
return { success: false, errors: filteredValidationErrors }
5355
}
5456
} catch (error) {
5557
logger.error({ error }, 'Agent validation failed with exception')

cli/src/index.tsx

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import { promises as fs } from 'fs'
44
import { createRequire } from 'module'
55

6-
76
import { API_KEY_ENV_VAR } from '@codebuff/common/old-constants'
87
import { getProjectFileTree } from '@codebuff/common/project-file-tree'
9-
import { validateAgents } from '@codebuff/sdk'
108
import { createCliRenderer } from '@opentui/core'
119
import { createRoot } from '@opentui/react'
12-
import { QueryClient, QueryClientProvider, focusManager } from '@tanstack/react-query'
10+
import {
11+
QueryClient,
12+
QueryClientProvider,
13+
focusManager,
14+
} from '@tanstack/react-query'
1315
import { Command } from 'commander'
1416
import React from 'react'
1517

@@ -19,11 +21,9 @@ import { initializeApp } from './init/init-app'
1921
import { getProjectRoot } from './project-files'
2022
import { initAnalytics } from './utils/analytics'
2123
import { getUserCredentials } from './utils/auth'
22-
import { loadAgentDefinitions, getLoadedAgentsData } from './utils/local-agent-registry'
2324
import { clearLogFile, logger } from './utils/logger'
2425
import { detectTerminalTheme } from './utils/terminal-color-detection'
2526
import { setOscDetectedTheme } from './utils/theme-system'
26-
import { filterNetworkErrors } from './utils/validation-error-helpers'
2727

2828
import type { FileTreeNode } from '@codebuff/common/util/file'
2929

@@ -171,20 +171,6 @@ async function main(): Promise<void> {
171171
clearLogFile()
172172
}
173173

174-
const loadedAgentsData = getLoadedAgentsData()
175-
176-
let validationErrors: Array<{ id: string; message: string }> = []
177-
if (loadedAgentsData) {
178-
const agentDefinitions = loadAgentDefinitions()
179-
const validationResult = await validateAgents(agentDefinitions, {
180-
remote: true,
181-
})
182-
183-
if (!validationResult.success) {
184-
validationErrors = filterNetworkErrors(validationResult.validationErrors)
185-
}
186-
}
187-
188174
const queryClient = createQueryClient()
189175

190176
const AppWithAsyncAuth = () => {
@@ -234,8 +220,6 @@ async function main(): Promise<void> {
234220
agentId={agent}
235221
requireAuth={requireAuth}
236222
hasInvalidCredentials={hasInvalidCredentials}
237-
loadedAgentsData={loadedAgentsData}
238-
validationErrors={validationErrors}
239223
fileTree={fileTree}
240224
continueChat={continueChat}
241225
continueChatId={continueId ?? undefined}

0 commit comments

Comments
 (0)