返回 CodeWhale
operate.rs
根目录 / crates / tui / src / tui / setup / operate.rs
1 use crate::tui::app::App;
2 use codewhale_runtime::config::Config;
3
4 #[derive(Debug, Clone, PartialEq, Eq)]
5 pub(super) struct SetupOperateFacts {
6 pub(super) runtime_ready: bool,
7 pub(super) runtime_result: String,
8 pub(super) roster_ready: bool,
9 pub(super) roster_result: String,
10 pub(super) concurrency_result: String,
11 pub(super) result: String,
12 }
13
14 impl Default for SetupOperateFacts {
15 fn default() -> Self {
16 Self {
17 runtime_ready: false,
18 runtime_result: "agent runtime not loaded".to_string(),
19 roster_ready: false,
20 roster_result: "Fleet not loaded".to_string(),
21 concurrency_result: "concurrency not loaded".to_string(),
22 result: "operate readiness not loaded".to_string(),
23 }
24 }
25 }
26
27 impl SetupOperateFacts {
28 pub(super) fn from_app_config(
29 app: &App,
30 config: &Config,
31 provider_ready: bool,
32 roster: &codewhale_engine::fleet::roster::FleetRoster,
33 ) -> Self {
34 let provider_identity = app.provider_identity_for_persistence();
35 let identity = app
36 .admitted_provider_identity()
37 .ok()
38 .filter(|identity| config.verify_provider_identity(identity).is_ok());
39 let subagents_enabled =
40 identity.is_some_and(|identity| config.subagents_enabled_for_provider(identity));
41 let max_subagents =
42 identity.map_or(0, |identity| config.max_subagents_for_provider(identity));
43 let launch_concurrency = identity.map_or(0, |identity| {
44 config.launch_concurrency_for_provider(identity)
45 });
46 let max_admitted = identity.map_or(0, |identity| {
47 config.max_admitted_subagents_for_provider(identity)
48 });
49 let runtime_disabled_reason = if subagents_enabled {
50 None
51 } else {
52 Some(
53 config
54 .subagents_disabled_reason()
55 .unwrap_or("disabled for active provider"),
56 )
57 };
58 let max_spawn_depth = identity.map_or(0, |identity| {
59 config.subagent_max_spawn_depth_for_provider(identity)
60 });
61 let runtime_configured =
62 subagents_enabled && max_subagents > 0 && launch_concurrency > 0 && max_spawn_depth > 0;
63 // Conversation and read-only discovery do not require a worker. This
64 // readiness fact describes whether Operate can also dispatch executable
65 // work in the background and report its lifecycle accurately.
66 let runtime_ready = runtime_configured && provider_ready;
67 let runtime_result = if let Some(reason) = runtime_disabled_reason {
68 format!("agent runtime disabled ({reason})")
69 } else if runtime_ready {
70 format!(
71 "agent runtime ready for {}; max_subagents={}, launch_concurrency={}, admission={}, max_spawn_depth={}; background dispatch and completion receipts are available",
72 provider_identity, max_subagents, launch_concurrency, max_admitted, max_spawn_depth
73 )
74 } else if runtime_configured {
75 format!(
76 "agent runtime configured for {}, but the active provider route is not ready; max_subagents={}, launch_concurrency={}, admission={}, max_spawn_depth={}",
77 provider_identity, max_subagents, launch_concurrency, max_admitted, max_spawn_depth
78 )
79 } else {
80 format!(
81 "agent runtime has no launch capacity for {}; max_subagents={}, launch_concurrency={}, admission={}, max_spawn_depth={}",
82 provider_identity, max_subagents, launch_concurrency, max_admitted, max_spawn_depth
83 )
84 };
85
86 let roster_members = roster.members().len();
87 let origin_count = |origin| {
88 roster
89 .members()
90 .iter()
91 .filter(|member| member.origin == origin)
92 .count()
93 };
94 let config_members = origin_count(codewhale_engine::fleet::roster::ProfileOrigin::Config);
95 let personal_members =
96 origin_count(codewhale_engine::fleet::roster::ProfileOrigin::Personal);
97 let project_members =
98 origin_count(codewhale_engine::fleet::roster::ProfileOrigin::Workspace);
99 let custom_roster_members = config_members + personal_members + project_members;
100 let roster_ready = roster.load_error().is_none() && roster_members > 0;
101 let roster_result = if let Some(error) = roster.load_error() {
102 error.to_string()
103 } else if custom_roster_members > 0 {
104 let origins = [
105 ("config", config_members),
106 ("personal", personal_members),
107 ("project", project_members),
108 ]
109 .into_iter()
110 .filter(|(_, count)| *count > 0)
111 .map(|(label, count)| format!("{label}={count}"))
112 .collect::<Vec<_>>()
113 .join(", ");
114 format!("{roster_members} agents (custom: {origins})")
115 } else {
116 format!("{roster_members} built-in agents; starter Fleet available")
117 };
118
119 let concurrency_result = format!(
120 "configured launch_concurrency={launch_concurrency}; max_subagents={max_subagents}; admission={max_admitted}; plan limit not probed"
121 );
122 let result = format!(
123 "provider={}, runtime={}, roster={}, concurrency={}",
124 if provider_ready {
125 "ready"
126 } else {
127 "needs_action"
128 },
129 if runtime_ready {
130 "ready"
131 } else {
132 "needs_action"
133 },
134 if roster_ready {
135 "ready"
136 } else {
137 "needs_action"
138 },
139 concurrency_result
140 );
141
142 Self {
143 runtime_ready,
144 runtime_result,
145 roster_ready,
146 roster_result,
147 concurrency_result,
148 result,
149 }
150 }
151 }
152
152 lines RUST