Skip to content

Commit c8c0660

Browse files
Refactor agent loading and validation flow
Consolidated agent loading and validation into a single promise chain to simplify the code structure. The validation still only runs when an agent is specified, preserving the original behavior while reducing complexity. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent ece56a1 commit c8c0660

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

npm-app/src/index.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,20 @@ async function codebuff({
9999

100100
const initFileContextPromise = initProjectFileContextWithWorker(projectRoot)
101101

102-
// Load local agents, display them, then validate agent using preloaded agents
103-
const loadAgentsAndDisplayPromise = loadLocalAgents({ verbose: true }).then(
104-
(agents) => {
105-
validateAgentDefinitionsIfAuthenticated(Object.values(agents))
106-
107-
const codebuffConfig = loadCodebuffConfig()
108-
if (!agent) {
109-
displayLoadedAgents(codebuffConfig)
110-
}
111-
112-
return agents // pass along for next step
113-
},
114-
)
115-
116102
// Ensure validation runs strictly after local agent load/display
117-
const loadAndValidatePromise: Promise<void> =
118-
loadAgentsAndDisplayPromise.then(async (agents) => {
119-
// Only validate if agent is specified
120-
if (!agent) {
121-
return
122-
}
123-
await validateAgent(agent, agents)
124-
})
103+
const loadAndValidatePromise: Promise<void> = loadLocalAgents({
104+
verbose: true,
105+
}).then((agents) => {
106+
validateAgentDefinitionsIfAuthenticated(Object.values(agents))
107+
108+
const codebuffConfig = loadCodebuffConfig()
109+
if (!agent) {
110+
displayLoadedAgents(codebuffConfig)
111+
return
112+
}
113+
114+
return validateAgent(agent, agents)
115+
})
125116

126117
const readyPromise = Promise.all([
127118
initFileContextPromise,

0 commit comments

Comments
 (0)