@@ -5,6 +5,9 @@ import { generateObject, type ModelMessage } from "ai"
55import { SystemPrompt } from "../session/system"
66import { Instance } from "../project/instance"
77import { mergeDeep } from "remeda"
8+ import { Log } from "../util/log"
9+
10+ const log = Log . create ( { service : "agent" } )
811
912import PROMPT_GENERATE from "./generate.txt"
1013import PROMPT_COMPACTION from "./prompt/compaction.txt"
@@ -20,6 +23,7 @@ export namespace Agent {
2023 mode : z . enum ( [ "subagent" , "primary" , "all" ] ) ,
2124 native : z . boolean ( ) . optional ( ) ,
2225 hidden : z . boolean ( ) . optional ( ) ,
26+ default : z . boolean ( ) . optional ( ) ,
2327 topP : z . number ( ) . optional ( ) ,
2428 temperature : z . number ( ) . optional ( ) ,
2529 color : z . string ( ) . optional ( ) ,
@@ -245,6 +249,19 @@ export namespace Agent {
245249 item . permission = mergeAgentPermissions ( cfg . permission ?? { } , permission ?? { } )
246250 }
247251 }
252+
253+ // Mark the default agent
254+ const defaultName = cfg . default_agent ?? "build"
255+ const defaultCandidate = result [ defaultName ]
256+ if ( defaultCandidate && defaultCandidate . mode !== "subagent" ) {
257+ defaultCandidate . default = true
258+ } else {
259+ // Fall back to "build" if configured default is invalid
260+ if ( result [ "build" ] ) {
261+ result [ "build" ] . default = true
262+ }
263+ }
264+
248265 return result
249266 } )
250267
@@ -256,6 +273,12 @@ export namespace Agent {
256273 return state ( ) . then ( ( x ) => Object . values ( x ) )
257274 }
258275
276+ export async function defaultAgent ( ) : Promise < string > {
277+ const agents = await state ( )
278+ const defaultCandidate = Object . values ( agents ) . find ( ( a ) => a . default )
279+ return defaultCandidate ?. name ?? "build"
280+ }
281+
259282 export async function generate ( input : { description : string ; model ?: { providerID : string ; modelID : string } } ) {
260283 const cfg = await Config . get ( )
261284 const defaultModel = input . model ?? ( await Provider . defaultModel ( ) )
0 commit comments