@@ -13,8 +13,11 @@ mod presets;
1313mod runtime_metadata;
1414#[ macro_use]
1515mod windows_install;
16+ pub ( crate ) use presets:: {
17+ canonical_harness_command, command_for_runtime_id, preset_harness_definitions,
18+ preset_harness_ids,
19+ } ;
1620use presets:: { preset_catalog_entry, PRESET_HARNESSES } ;
17- pub ( crate ) use presets:: { preset_harness_definitions, preset_harness_ids} ;
1821pub ( crate ) use runtime_metadata:: KnownAcpRuntime ;
1922
2023const GOOSE_AVATAR_URL : & str = "https://goose-docs.ai/img/logo_dark.png" ;
@@ -233,7 +236,7 @@ fn executable_basename(command: &str) -> String {
233236 }
234237}
235238
236- fn normalize_command_identity ( command : & str ) -> String {
239+ pub ( crate ) fn normalize_command_identity ( command : & str ) -> String {
237240 let normalized = command. trim ( ) . replace ( '\\' , "/" ) ;
238241 let basename = normalized. rsplit ( '/' ) . next ( ) . unwrap_or ( normalized. as_str ( ) ) ;
239242 let lower = basename
@@ -295,9 +298,10 @@ pub fn default_agent_command() -> String {
295298///
296299/// Resolution order:
297300/// 1. explicit override (non-empty) — a deliberate per-instance pin;
298- /// 2. the record's own `runtime` id mapped to its primary command —
299- /// records materialize their runtime at create/migration time;
300- /// checks both static builtins AND the loaded preset/custom registry;
301+ /// 2. the record's own `runtime` id mapped to its primary command via the
302+ /// authoritative three-tier lookup (static builtins → static preset list
303+ /// → loaded registry) — preset harnesses (e.g. openclaw) resolve
304+ /// correctly even with a cold registry;
301305/// 3. legacy fallback: the linked persona's `runtime` (records created
302306/// before the unified model carry `persona_id` but no `runtime`);
303307/// 4. `default_agent_command()`.
@@ -315,15 +319,11 @@ pub fn record_agent_command(
315319 }
316320
317321 if let Some ( id) = record. runtime . as_deref ( ) {
318- // Check static builtins first.
319- if let Some ( command) = known_acp_runtime_exact ( id) . and_then ( |r| r. commands . first ( ) . copied ( ) )
320- {
321- return command. to_string ( ) ;
322- }
323- // Fall back to loaded registry for preset/custom harnesses.
324- if let Some ( def) = crate :: managed_agents:: custom_harnesses:: lookup_loaded_harness_by_id ( id)
325- {
326- return def. command . clone ( ) ;
322+ // Three-tier lookup: static builtins → static presets → loaded registry.
323+ // Using the shared resolver ensures preset harnesses (e.g. openclaw)
324+ // resolve correctly even without a warm registry.
325+ if let Some ( cmd) = presets:: command_for_runtime_id ( id) {
326+ return cmd;
327327 }
328328 }
329329
@@ -336,8 +336,9 @@ pub fn record_agent_command(
336336///
337337/// Resolution order:
338338/// 1. explicit override (non-empty) — a deliberate per-instance pin;
339- /// 2. the linked persona's `runtime` id mapped to its primary command
340- /// (checks builtins then loaded preset/custom registry);
339+ /// 2. the linked persona's `runtime` id mapped to its primary command via
340+ /// the authoritative three-tier lookup (static builtins → static preset
341+ /// list → loaded registry);
341342/// 3. `default_agent_command()` — no persona/runtime, or persona deleted.
342343pub fn effective_agent_command (
343344 persona_id : Option < & str > ,
@@ -356,15 +357,9 @@ pub fn effective_agent_command(
356357 . and_then ( |persona| persona. runtime . as_deref ( ) ) ;
357358
358359 if let Some ( id) = runtime_id {
359- // Check static builtins first.
360- if let Some ( command) = known_acp_runtime_exact ( id) . and_then ( |r| r. commands . first ( ) . copied ( ) )
361- {
362- return command. to_string ( ) ;
363- }
364- // Check loaded preset/custom registry.
365- if let Some ( def) = crate :: managed_agents:: custom_harnesses:: lookup_loaded_harness_by_id ( id)
366- {
367- return def. command . clone ( ) ;
360+ // Three-tier lookup: static builtins → static presets → loaded registry.
361+ if let Some ( cmd) = presets:: command_for_runtime_id ( id) {
362+ return cmd;
368363 }
369364 }
370365
@@ -423,12 +418,8 @@ pub fn try_record_agent_command(
423418
424419 // Record-level runtime id: if set but unresolvable → typed error.
425420 if let Some ( id) = record. runtime . as_deref ( ) {
426- if let Some ( cmd) = known_acp_runtime_exact ( id) . and_then ( |r| r. commands . first ( ) . copied ( ) ) {
427- return Ok ( cmd. to_string ( ) ) ;
428- }
429- if let Some ( def) = crate :: managed_agents:: custom_harnesses:: lookup_loaded_harness_by_id ( id)
430- {
431- return Ok ( def. command . clone ( ) ) ;
421+ if let Some ( cmd) = presets:: command_for_runtime_id ( id) {
422+ return Ok ( cmd) ;
432423 }
433424 return Err ( format ! ( "DANGLING_HARNESS_ID:{id}" ) ) ;
434425 }
@@ -437,15 +428,8 @@ pub fn try_record_agent_command(
437428 if let Some ( persona_id) = record. persona_id . as_deref ( ) {
438429 if let Some ( persona) = personas. iter ( ) . find ( |p| p. id == persona_id) {
439430 if let Some ( id) = persona. runtime . as_deref ( ) {
440- if let Some ( cmd) =
441- known_acp_runtime_exact ( id) . and_then ( |r| r. commands . first ( ) . copied ( ) )
442- {
443- return Ok ( cmd. to_string ( ) ) ;
444- }
445- if let Some ( def) =
446- crate :: managed_agents:: custom_harnesses:: lookup_loaded_harness_by_id ( id)
447- {
448- return Ok ( def. command . clone ( ) ) ;
431+ if let Some ( cmd) = presets:: command_for_runtime_id ( id) {
432+ return Ok ( cmd) ;
449433 }
450434 return Err ( format ! ( "DANGLING_HARNESS_ID:{id}" ) ) ;
451435 }
0 commit comments