Skip to content

Commit e202b8a

Browse files
authored
feat(desktop,installer): switch LoopX.app default surface to Workbench and auto-install macOS App (#10254)
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent 69c3be0 commit e202b8a

17 files changed

Lines changed: 905 additions & 48 deletions

‎apps/desktop/loopx-control-plane/src-tauri/src/lib.rs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,12 @@ pub fn run() {
145145
// endpoints are an explicit developer/QA choice, never a second default
146146
// Chat store created merely by opening a release window.
147147
let private_endpoints = std::env::var_os("LOOPX_DESKTOP_PRIVATE_ENDPOINTS");
148-
let endpoints = service_endpoints::ServiceEndpoints::for_window(private_endpoints.as_deref())
149-
.expect("could not allocate LoopX loopback endpoints");
148+
let surface_override = std::env::var_os("LOOPX_DESKTOP_SURFACE");
149+
let endpoints = service_endpoints::ServiceEndpoints::for_window_with_surface(
150+
private_endpoints.as_deref(),
151+
surface_override.as_deref(),
152+
)
153+
.expect("could not allocate LoopX loopback endpoints");
150154
#[cfg(dev)]
151155
let web_origin = "http://127.0.0.1:5173".to_string();
152156
#[cfg(not(dev))]
@@ -280,6 +284,7 @@ pub fn run() {
280284
}
281285
Ok(Some(started)) => {
282286
let healed = started.healed;
287+
let launch_url = started.workspace_launch_url().cloned();
283288
if let Err(mut returned) = lifecycle.adopt(started) {
284289
// The window closed or a new handoff claimed
285290
// the runtime while this start was in flight:
@@ -298,7 +303,7 @@ pub fn run() {
298303
handoff
299304
.lock()
300305
.expect("workspace handoff lock")
301-
.services_ready();
306+
.services_ready_at(launch_url);
302307
WorkspaceHandoff::reconcile(&handoff, &handle);
303308
maintenance::start_background_update(&handle);
304309
if healed {

‎apps/desktop/loopx-control-plane/src-tauri/src/maintenance.rs‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,20 @@ fn resume_runtime(
12451245
);
12461246
return Ok(current);
12471247
}
1248-
let bundled = bundled_runtime::identity(app)?;
1248+
let bundled = match bundled_runtime::identity(app) {
1249+
Ok(identity) => identity,
1250+
Err(ref error) if error == "runtime_bundle_missing" && installed.is_some() => {
1251+
// Thin local macOS installations built by scripts/install-local.sh
1252+
// ship without an embedded 95MB runtime tarball and intentionally
1253+
// reuse the machine's verified installed `loopx` CLI.
1254+
state.separately_managed_runtime.store(
1255+
!is_private_runtime(&selection.executable, &private_executable),
1256+
Ordering::Release,
1257+
);
1258+
return Ok(current);
1259+
}
1260+
Err(error) => return Err(error),
1261+
};
12491262
let candidate =
12501263
crate::runtime_selection::bundled_runtime_candidate(app.package_info(), &bundled)?;
12511264
// Only a launch-time developer override pins a runtime. Ordinary launches

‎apps/desktop/loopx-control-plane/src-tauri/src/service_endpoints.rs‎

Lines changed: 110 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,54 @@
11
use std::{ffi::OsStr, net::TcpListener};
22

3-
use crate::services::ServiceKind;
3+
use crate::services::{ServiceKind, SERVICE_KINDS};
44

5-
/// A native window keeps one endpoint pair across runtime repairs. Normal
5+
/// Desktop workspace UI surface. Workbench is the default; LegacyDashboard is an
6+
/// explicit opt-in escape hatch (`LOOPX_DESKTOP_SURFACE=legacy|dashboard`) while
7+
/// remaining legacy dashboard panels are absorbed and retired.
8+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9+
pub(crate) enum WorkspaceSurface {
10+
Workbench,
11+
LegacyDashboard,
12+
}
13+
14+
impl WorkspaceSurface {
15+
pub fn from_env(value: Option<&OsStr>) -> std::io::Result<Self> {
16+
let Some(raw) = value else {
17+
return Ok(Self::Workbench);
18+
};
19+
let normalized = raw.to_string_lossy().trim().to_ascii_lowercase();
20+
match normalized.as_str() {
21+
"" | "workbench" => Ok(Self::Workbench),
22+
"legacy" | "dashboard" => Ok(Self::LegacyDashboard),
23+
_ => Err(std::io::Error::new(
24+
std::io::ErrorKind::InvalidInput,
25+
"LOOPX_DESKTOP_SURFACE must be workbench, legacy, or dashboard",
26+
)),
27+
}
28+
}
29+
}
30+
31+
/// A native window keeps one endpoint set across runtime repairs. Normal
632
/// windows share the machine services; explicit private endpoints are opt-in.
733
#[derive(Clone, Copy)]
834
pub(crate) struct ServiceEndpoints {
935
status: u16,
1036
chat: u16,
37+
workbench: u16,
1138
pub isolated: bool,
39+
pub surface: WorkspaceSurface,
1240
}
1341

1442
impl ServiceEndpoints {
43+
#[cfg(test)]
1544
pub fn for_window(private_endpoints: Option<&OsStr>) -> std::io::Result<Self> {
45+
Self::for_window_with_surface(private_endpoints, None)
46+
}
47+
48+
pub fn for_window_with_surface(
49+
private_endpoints: Option<&OsStr>,
50+
surface_override: Option<&OsStr>,
51+
) -> std::io::Result<Self> {
1652
let isolated = match private_endpoints {
1753
None => false,
1854
Some(value) if value == "0" => false,
@@ -24,25 +60,39 @@ impl ServiceEndpoints {
2460
))
2561
}
2662
};
27-
Self::allocate(isolated)
63+
let surface = WorkspaceSurface::from_env(surface_override)?;
64+
Self::allocate_for_surface(isolated, surface)
2865
}
2966

67+
#[cfg(test)]
3068
pub fn allocate(isolated: bool) -> std::io::Result<Self> {
69+
Self::allocate_for_surface(isolated, WorkspaceSurface::Workbench)
70+
}
71+
72+
pub fn allocate_for_surface(
73+
isolated: bool,
74+
surface: WorkspaceSurface,
75+
) -> std::io::Result<Self> {
3176
if !isolated {
3277
return Ok(Self {
3378
status: 8766,
3479
chat: 8767,
80+
workbench: 8796,
3581
isolated,
82+
surface,
3683
});
3784
}
38-
// Keep both reservations until their distinct ports have been chosen.
85+
// Keep all reservations until distinct ports have been chosen.
3986
// The CLI owns binding; an intervening listener fails closed at start.
4087
let status = reserve_private_endpoint()?;
4188
let chat = reserve_private_endpoint()?;
89+
let workbench = reserve_private_endpoint()?;
4290
Ok(Self {
4391
status: status.local_addr()?.port(),
4492
chat: chat.local_addr()?.port(),
93+
workbench: workbench.local_addr()?.port(),
4594
isolated,
95+
surface,
4696
})
4797
}
4898

@@ -64,10 +114,13 @@ impl ServiceEndpoints {
64114
};
65115
let status = reserve()?;
66116
let chat = reserve()?;
117+
let workbench = reserve()?;
67118
Ok(Self {
68119
status: status.local_addr()?.port(),
69120
chat: chat.local_addr()?.port(),
121+
workbench: workbench.local_addr()?.port(),
70122
isolated: true,
123+
surface: WorkspaceSurface::LegacyDashboard,
71124
})
72125
}
73126

@@ -78,17 +131,32 @@ impl ServiceEndpoints {
78131
}
79132
}
80133

134+
pub fn workbench_port(self) -> u16 {
135+
self.workbench
136+
}
137+
138+
pub fn required_services(self) -> &'static [ServiceKind] {
139+
const WORKBENCH_CORE_ONLY: [ServiceKind; 1] = [ServiceKind::Chat];
140+
match self.surface {
141+
WorkspaceSurface::Workbench => &WORKBENCH_CORE_ONLY,
142+
WorkspaceSurface::LegacyDashboard => &SERVICE_KINDS,
143+
}
144+
}
145+
81146
#[cfg(any(not(dev), test))]
82147
pub fn workspace_origin(self) -> String {
83-
format!("http://127.0.0.1:{}/chat/", self.chat)
148+
match self.surface {
149+
WorkspaceSurface::Workbench => format!("http://127.0.0.1:{}/", self.workbench),
150+
WorkspaceSurface::LegacyDashboard => format!("http://127.0.0.1:{}/chat/", self.chat),
151+
}
84152
}
85153
}
86154

87155
fn reserve_private_endpoint() -> std::io::Result<TcpListener> {
88156
// A host may customize its ephemeral range to include the CLI ports.
89157
for _ in 0..8 {
90158
let listener = TcpListener::bind(("127.0.0.1", 0))?;
91-
if ![8766, 8767].contains(&listener.local_addr()?.port()) {
159+
if ![8766, 8767, 8796].contains(&listener.local_addr()?.port()) {
92160
return Ok(listener);
93161
}
94162
}
@@ -103,11 +171,15 @@ mod tests {
103171
use super::*;
104172

105173
#[test]
106-
fn ordinary_window_uses_the_same_machine_service_addresses() {
174+
fn ordinary_window_defaults_to_workbench_and_shares_machine_service_addresses() {
107175
for choice in [None, Some(OsStr::new("0"))] {
108176
let endpoints = ServiceEndpoints::for_window(choice).unwrap();
177+
assert_eq!(endpoints.surface, WorkspaceSurface::Workbench);
109178
assert_eq!(endpoints.port(ServiceKind::Status), 8766);
110179
assert_eq!(endpoints.port(ServiceKind::Chat), 8767);
180+
assert_eq!(endpoints.workbench_port(), 8796);
181+
assert_eq!(endpoints.required_services(), &[ServiceKind::Chat]);
182+
assert_eq!(endpoints.workspace_origin(), "http://127.0.0.1:8796/");
111183
assert!(!endpoints.isolated);
112184
}
113185
assert!(
@@ -117,6 +189,23 @@ mod tests {
117189
);
118190
}
119191

192+
#[test]
193+
fn explicit_legacy_surface_preserves_dashboard_origin_and_dual_services() {
194+
for choice in ["legacy", "dashboard", "LEGACY"] {
195+
let endpoints =
196+
ServiceEndpoints::for_window_with_surface(None, Some(OsStr::new(choice))).unwrap();
197+
assert_eq!(endpoints.surface, WorkspaceSurface::LegacyDashboard);
198+
assert_eq!(
199+
endpoints.required_services(),
200+
&[ServiceKind::Status, ServiceKind::Chat]
201+
);
202+
assert_eq!(endpoints.workspace_origin(), "http://127.0.0.1:8767/chat/");
203+
}
204+
let invalid =
205+
ServiceEndpoints::for_window_with_surface(None, Some(OsStr::new("unknown"))).err();
206+
assert_eq!(invalid.unwrap().kind(), std::io::ErrorKind::InvalidInput);
207+
}
208+
120209
#[test]
121210
fn invalid_private_endpoint_choice_cannot_fall_through_to_machine_state() {
122211
for choice in ["", "true", "yes", "2"] {
@@ -135,6 +224,7 @@ mod tests {
135224
let endpoints = ServiceEndpoints::allocate(false).unwrap();
136225
assert_eq!(endpoints.port(ServiceKind::Status), 8766);
137226
assert_eq!(endpoints.port(ServiceKind::Chat), 8767);
227+
assert_eq!(endpoints.workbench_port(), 8796);
138228
assert!(!endpoints.isolated);
139229
}
140230

@@ -143,11 +233,21 @@ mod tests {
143233
let endpoints = ServiceEndpoints::allocate(true).unwrap();
144234
assert!(endpoints.isolated);
145235
assert_ne!(endpoints.status, endpoints.chat);
146-
assert!(![8766, 8767].contains(&endpoints.status));
147-
assert!(![8766, 8767].contains(&endpoints.chat));
236+
assert_ne!(endpoints.chat, endpoints.workbench);
237+
assert_ne!(endpoints.status, endpoints.workbench);
238+
assert!(![8766, 8767, 8796].contains(&endpoints.status));
239+
assert!(![8766, 8767, 8796].contains(&endpoints.chat));
240+
assert!(![8766, 8767, 8796].contains(&endpoints.workbench));
148241
assert_eq!(
149242
endpoints.workspace_origin(),
150-
format!("http://127.0.0.1:{}/chat/", endpoints.chat)
243+
format!("http://127.0.0.1:{}/", endpoints.workbench)
244+
);
245+
let legacy =
246+
ServiceEndpoints::allocate_for_surface(true, WorkspaceSurface::LegacyDashboard)
247+
.unwrap();
248+
assert_eq!(
249+
legacy.workspace_origin(),
250+
format!("http://127.0.0.1:{}/chat/", legacy.chat)
151251
);
152252
}
153253
}

0 commit comments

Comments
 (0)