Skip to content

Commit 4af09d4

Browse files
authored
feat(ui): unify focused presentation routes (#126143)
* feat(ui): unify focused presentation routes /focus/<target> replaces unshipped standalone query links across dashboard, terminal, desktop, and native apps. Gateway-served index assets are anchored so nested documents resolve their bundles from the Control UI base path. * test(gateway): narrow emitted asset URLs Fixes check:test-types TS18048/TS2322 by dropping unmatched optional captures before comparing emitted asset URLs. * test(docs): follow centralized cloud secret guidance Fixes the stale current-main docs test after #126132 centralized GCP and Hetzner setup in docker-vm-runtime. * test(ui): retry missing locator reads The 500ms locator text read can time out while the menu label is still rendering, causing expect.poll to reject instead of using its owning 10s retry window. Treat only Playwright TimeoutError as a missing value so the outer poll retries while page-closure and arbitrary failures still surface. * test(android): capture TLS probe coroutine The TLS probe test inferred its coroutine from mutable scope children, racing unrelated child startup and teardown in CI. Capture the exact Job from inside the probe coroutine and join that owner before asserting the stale-attempt guard. * fix(gateway): preserve plugin focus routes Keep approval handling ahead of plugin dispatch, but treat focus documents as an unclaimed Control UI fallback after plugin authentication and routing. Exact and prefix plugin routes therefore retain ownership, while unclaimed reads serve the focus document and other methods return 404. * fix(ui): migrate released terminal links Preserve stable v2026.7.1 terminal query compatibility by rewriting the root/base ?view=terminal URL once to the canonical /focus/terminal path with history.replace. Keep URL parsing path-only, and leave the removed desktop and dashboard query forms as a hard cut. * test(codex): assign run-attempt tools shard Cached filtered configs caused duplicate ownership, and the test lacked a canonical full-suite owner. * test(ui): keep cloud recovery proof state-owned The recovery test should assert owner state and reload identity, while dedicated tests own transient alert visibility. * test(qa): wait for outbound bus state * fix(qa): reserve gateway ports through staging * refactor(qa): keep socket creation in gateway owner
1 parent 9814b14 commit 4af09d4

66 files changed

Lines changed: 1916 additions & 633 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/android/app/src/main/java/ai/openclaw/app/ui/DesktopScreen.kt‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,26 @@ internal fun DesktopScreen(
103103
}
104104
}
105105

106-
/** Builds the desktop document route; credentials stay in ControlUiWebView's startup script. */
106+
/** Builds the desktop focus route; credentials stay in ControlUiWebView's startup script. */
107107
internal fun desktopUrl(
108108
baseUrl: String,
109109
source: String? = null,
110110
session: String? = null,
111111
): String {
112-
val baseUri = baseUrl.trimEnd('/').toUri()
113-
val routePath = "${baseUri.encodedPath.orEmpty().trimEnd('/')}/"
112+
val normalizedSource = source?.trim()?.takeIf(String::isNotEmpty)
113+
val normalizedSession = session?.trim()?.takeIf(String::isNotEmpty)
114114
val builder =
115-
baseUri
115+
baseUrl
116+
.trimEnd('/')
117+
.toUri()
116118
.buildUpon()
117-
.encodedPath(routePath)
118119
.clearQuery()
119120
.fragment(null)
120-
.appendQueryParameter("view", "desktop")
121-
source?.let { builder.appendQueryParameter("source", it) }
122-
session?.let { builder.appendQueryParameter("session", it) }
121+
.appendPath("focus")
122+
.appendPath("desktop")
123+
when {
124+
normalizedSource != null -> builder.appendPath("source").appendPath(normalizedSource)
125+
normalizedSession != null -> builder.appendPath("session").appendPath(normalizedSession)
126+
}
123127
return builder.build().toString()
124128
}

‎apps/android/app/src/main/java/ai/openclaw/app/ui/TerminalSettingsScreen.kt‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ import androidx.compose.ui.Alignment
2727
import androidx.compose.ui.Modifier
2828
import androidx.compose.ui.text.style.TextOverflow
2929
import androidx.compose.ui.unit.dp
30+
import androidx.core.net.toUri
3031

3132
/**
3233
* Full-height terminal surface: embeds the gateway-served terminal-only
33-
* Control UI document (`/?view=terminal`, the same ghostty-web surface the
34+
* Control UI focus document (`/focus/terminal`, the same ghostty-web surface the
3435
* desktop Control UI uses) for the currently connected gateway.
3536
*/
3637
@Composable
@@ -61,7 +62,7 @@ internal fun TerminalSettingsScreen(
6162
key(page) {
6263
ControlUiWebView(
6364
page = page,
64-
url = "${page.baseUrl}/?view=terminal",
65+
url = terminalUrl(page.baseUrl),
6566
modifier = Modifier.fillMaxSize(),
6667
)
6768
}
@@ -75,3 +76,16 @@ internal fun TerminalSettingsScreen(
7576
}
7677
}
7778
}
79+
80+
/** Builds the terminal focus route without putting gateway credentials in the URL. */
81+
internal fun terminalUrl(baseUrl: String): String =
82+
baseUrl
83+
.trimEnd('/')
84+
.toUri()
85+
.buildUpon()
86+
.clearQuery()
87+
.fragment(null)
88+
.appendPath("focus")
89+
.appendPath("terminal")
90+
.build()
91+
.toString()

‎apps/android/app/src/test/java/ai/openclaw/app/GatewayBootstrapAuthTest.kt‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import kotlinx.coroutines.Job
3030
import kotlinx.coroutines.asCoroutineDispatcher
3131
import kotlinx.coroutines.async
3232
import kotlinx.coroutines.cancelAndJoin
33+
import kotlinx.coroutines.currentCoroutineContext
3334
import kotlinx.coroutines.delay
3435
import kotlinx.coroutines.flow.MutableStateFlow
3536
import kotlinx.coroutines.runBlocking
@@ -438,37 +439,26 @@ class GatewayBootstrapAuthTest {
438439
fun connect_ignoresStaleTlsProbeAfterDisconnect() =
439440
runBlocking {
440441
val fingerprint = "aa".repeat(32)
441-
val probeStarted = CompletableDeferred<Unit>()
442+
val probeJob = CompletableDeferred<Job>()
442443
val probeResult = CompletableDeferred<GatewayTlsProbeResult>()
443444
val (_, prefs, runtime) =
444445
gatewayFixture { _, _ ->
445-
probeStarted.complete(Unit)
446+
probeJob.complete(checkNotNull(currentCoroutineContext()[Job]))
446447
probeResult.await()
447448
}
448449
val endpoint = GatewayEndpoint.manual(host = "gateway.example", port = 18789)
449450
prefs.saveGatewayTlsFingerprint(endpoint.stableId, fingerprint)
450-
val runtimeScope = readField<CoroutineScope>(runtime, "scope")
451-
val existingJobs =
452-
runtimeScope.coroutineContext[Job]
453-
?.children
454-
?.toSet()
455-
.orEmpty()
456451

457452
runtime.connect(
458453
endpoint,
459454
auth(token = "shared-token"),
460455
)
461-
probeStarted.await()
462-
val probeJob =
463-
runtimeScope.coroutineContext[Job]
464-
?.children
465-
?.singleOrNull { it !in existingJobs }
466-
?: error("Expected one TLS probe job")
456+
val tlsProbeJob = probeJob.await()
467457

468458
runtime.disconnect()
469459
probeResult.complete(GatewayTlsProbeResult(fingerprintSha256 = fingerprint))
470460
// Join the owning coroutine so assertions run after its stale-attempt guard.
471-
probeJob.join()
461+
tlsProbeJob.join()
472462

473463
assertNull(runtime.pendingGatewayTrust.value)
474464
assertNull(desiredBootstrapToken(runtime, "nodeSession"))
Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ai.openclaw.app.ui
22

33
import org.junit.Assert.assertEquals
4-
import org.junit.Assert.assertFalse
54
import org.junit.Test
65
import org.junit.runner.RunWith
76
import org.robolectric.RobolectricTestRunner
@@ -11,56 +10,70 @@ import org.robolectric.annotation.Config
1110
@Config(sdk = [34])
1211
class DesktopScreenTest {
1312
@Test
14-
fun desktopUrlUsesDocumentModeWithoutSource() {
15-
val url = desktopUrl(baseUrl = "https://gateway.example.com:8443/openclaw/")
16-
17-
assertEquals("https://gateway.example.com:8443/openclaw/?view=desktop", url)
18-
assertFalse(url.contains("token="))
19-
assertFalse(url.contains("password="))
20-
}
21-
22-
@Test
23-
fun desktopUrlEncodesProvidedSource() {
24-
val url =
25-
desktopUrl(
26-
baseUrl = "https://gateway.example.com:8443",
27-
source = "environment:Mac Studio/QA & demo",
13+
fun desktopUrlBuildsCanonicalFocusPaths() {
14+
val cases =
15+
listOf(
16+
DesktopUrlCase(
17+
name = "root base",
18+
baseUrl = "https://gateway.example.com:8443",
19+
expected = "https://gateway.example.com:8443/focus/desktop",
20+
),
21+
DesktopUrlCase(
22+
name = "configured base path",
23+
baseUrl = "https://gateway.example.com:8443/openclaw/",
24+
expected = "https://gateway.example.com:8443/openclaw/focus/desktop",
25+
),
26+
DesktopUrlCase(
27+
name = "encoded source",
28+
baseUrl = "https://gateway.example.com:8443",
29+
source = "environment:Mac Studio/QA & demo",
30+
expected =
31+
"https://gateway.example.com:8443/focus/desktop/source/environment%3AMac%20Studio%2FQA%20%26%20demo",
32+
),
33+
DesktopUrlCase(
34+
name = "encoded session under configured base path",
35+
baseUrl = "https://gateway.example.com:8443/openclaw/",
36+
session = "agent:main:mobile session",
37+
expected =
38+
"https://gateway.example.com:8443/openclaw/focus/desktop/session/agent%3Amain%3Amobile%20session",
39+
),
40+
DesktopUrlCase(
41+
name = "source wins over session",
42+
baseUrl = "https://gateway.example.com:8443",
43+
source = "node:worker-1",
44+
session = "agent:main:mobile",
45+
expected = "https://gateway.example.com:8443/focus/desktop/source/node%3Aworker-1",
46+
),
47+
DesktopUrlCase(
48+
name = "empty source falls through to session",
49+
baseUrl = "https://gateway.example.com:8443",
50+
source = " ",
51+
session = "agent:main:mobile",
52+
expected = "https://gateway.example.com:8443/focus/desktop/session/agent%3Amain%3Amobile",
53+
),
54+
DesktopUrlCase(
55+
name = "empty values are omitted",
56+
baseUrl = "https://gateway.example.com:8443/openclaw/",
57+
source = " ",
58+
session = "\n",
59+
expected = "https://gateway.example.com:8443/openclaw/focus/desktop",
60+
),
2861
)
2962

30-
assertEquals(
31-
"https://gateway.example.com:8443/?view=desktop&source=environment%3AMac%20Studio%2FQA%20%26%20demo",
32-
url,
33-
)
34-
assertFalse(url.contains("token="))
35-
assertFalse(url.contains("password="))
36-
}
37-
38-
@Test
39-
fun desktopUrlEncodesProvidedSession() {
40-
val url =
41-
desktopUrl(
42-
baseUrl = "https://gateway.example.com:8443/openclaw/",
43-
session = "agent:main:mobile session",
63+
cases.forEach { case ->
64+
assertEquals(
65+
case.name,
66+
case.expected,
67+
desktopUrl(baseUrl = case.baseUrl, source = case.source, session = case.session),
4468
)
45-
46-
assertEquals(
47-
"https://gateway.example.com:8443/openclaw/?view=desktop&session=agent%3Amain%3Amobile%20session",
48-
url,
49-
)
69+
}
5070
}
5171

52-
@Test
53-
fun desktopUrlRetainsExplicitSourceAlongsideSession() {
54-
val url =
55-
desktopUrl(
56-
baseUrl = "https://gateway.example.com:8443",
57-
source = "node:worker-1",
58-
session = "agent:main:mobile",
59-
)
60-
61-
assertEquals(
62-
"https://gateway.example.com:8443/?view=desktop&source=node%3Aworker-1&session=agent%3Amain%3Amobile",
63-
url,
64-
)
65-
}
72+
private data class DesktopUrlCase(
73+
val name: String,
74+
val baseUrl: String,
75+
val source: String? = null,
76+
val session: String? = null,
77+
val expected: String,
78+
)
6679
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ai.openclaw.app.ui
2+
3+
import org.junit.Assert.assertEquals
4+
import org.junit.Test
5+
import org.junit.runner.RunWith
6+
import org.robolectric.RobolectricTestRunner
7+
import org.robolectric.annotation.Config
8+
9+
@RunWith(RobolectricTestRunner::class)
10+
@Config(sdk = [34])
11+
class TerminalSettingsScreenTest {
12+
@Test
13+
fun terminalUrlBuildsCanonicalFocusPath() {
14+
val cases =
15+
listOf(
16+
"https://gateway.example.com:8443" to
17+
"https://gateway.example.com:8443/focus/terminal",
18+
"https://gateway.example.com:8443/openclaw/" to
19+
"https://gateway.example.com:8443/openclaw/focus/terminal",
20+
)
21+
22+
cases.forEach { (baseUrl, expected) ->
23+
assertEquals(baseUrl, expected, terminalUrl(baseUrl))
24+
}
25+
}
26+
}

‎apps/ios/Sources/Desktop/DesktopHubScreen.swift‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,11 @@ struct DesktopHubScreen: View {
100100
source: String?,
101101
session: String? = nil) -> URL?
102102
{
103-
var queryItems = [URLQueryItem(name: "view", value: "desktop")]
104-
if let source = self.normalizedSource(source) {
105-
queryItems.append(URLQueryItem(name: "source", value: source))
106-
}
107-
if let session = self.normalizedSource(session) {
108-
queryItems.append(URLQueryItem(name: "session", value: session))
109-
}
103+
guard let path = self.desktopPath(source: source, session: session) else { return nil }
110104
return AuthenticatedControlUI.pageURL(
111105
config: config,
112-
path: "/",
113-
queryItems: queryItems)
106+
path: path,
107+
queryItems: [])
114108
}
115109

116110
static func desktopAuthUserScript(
@@ -147,13 +141,25 @@ struct DesktopHubScreen: View {
147141
hasher.combine(AuthenticatedControlUI.webContentIdentity(
148142
config: config,
149143
storedOperatorToken: storedOperatorToken))
150-
hasher.combine(self.normalizedSource(source))
151-
hasher.combine(self.normalizedSource(session))
144+
hasher.combine(self.desktopPath(source: source, session: session))
152145
return hasher.finalize()
153146
}
154147

155-
private static func normalizedSource(_ source: String?) -> String? {
156-
let trimmed = source?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
148+
private static func desktopPath(source: String?, session: String?) -> String? {
149+
let basePath = "/focus/desktop"
150+
if let source = self.normalizedValue(source) {
151+
guard let encoded = AuthenticatedControlUI.percentEncodedPathSegment(source) else { return nil }
152+
return "\(basePath)/source/\(encoded)"
153+
}
154+
if let session = self.normalizedValue(session) {
155+
guard let encoded = AuthenticatedControlUI.percentEncodedPathSegment(session) else { return nil }
156+
return "\(basePath)/session/\(encoded)"
157+
}
158+
return basePath
159+
}
160+
161+
private static func normalizedValue(_ value: String?) -> String? {
162+
let trimmed = value?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
157163
return trimmed.isEmpty ? nil : trimmed
158164
}
159165
}

‎apps/ios/Sources/Terminal/TerminalHubScreen.swift‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import OpenClawKit
22
import SwiftUI
33

44
/// Control-hub Terminal destination: embeds the gateway-served terminal page
5-
/// (`/?view=terminal`, the ghostty-web surface shared with the Control UI) in a
5+
/// (`/focus/terminal`, the ghostty-web surface shared with the Control UI) in a
66
/// WKWebView, authenticated with the stored gateway credentials.
77
struct TerminalHubScreen: View {
88
@Environment(NodeAppModel.self) private var appModel
@@ -87,14 +87,14 @@ struct TerminalHubScreen: View {
8787
}
8888

8989
/// Derives the terminal page URL from the active gateway connection: the
90-
/// WS endpoint flips to HTTP(S) and only `view=terminal` rides in the URL.
90+
/// WS endpoint flips to HTTP(S) and the configured Control UI base path is preserved.
9191
/// Credentials never enter the URL — they are injected as a document-start
9292
/// user script (see `terminalAuthUserScript`), matching the macOS Dashboard.
9393
static func terminalURL(config: GatewayConnectConfig?) -> URL? {
9494
AuthenticatedControlUI.pageURL(
9595
config: config,
96-
path: "/",
97-
queryItems: [URLQueryItem(name: "view", value: "terminal")])
96+
path: "/focus/terminal",
97+
queryItems: [])
9898
}
9999

100100
/// Origin-gated document-start script that hands the gateway credentials to

‎apps/ios/Sources/Web/AuthenticatedControlUIWebView.swift‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import WebKit
77
enum AuthenticatedControlUI {
88
private static let queryComponentAllowed = CharacterSet(
99
charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~")
10+
private static let pathSegmentAllowed = CharacterSet(
11+
charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!'()*")
1012

1113
static func pageURL(
1214
config: GatewayConnectConfig?,
@@ -33,10 +35,16 @@ enum AuthenticatedControlUI {
3335
return "\(name)=\(encodedValue)"
3436
}
3537
guard encodedItems.count == queryItems.count else { return nil }
36-
components.percentEncodedQuery = encodedItems.joined(separator: "&")
38+
components.percentEncodedQuery = encodedItems.isEmpty
39+
? nil
40+
: encodedItems.joined(separator: "&")
3741
return components.url
3842
}
3943

44+
static func percentEncodedPathSegment(_ value: String) -> String? {
45+
value.addingPercentEncoding(withAllowedCharacters: self.pathSegmentAllowed)
46+
}
47+
4048
/// Origin-gated document-start script for the Control UI native-auth contract.
4149
static func authUserScript(
4250
config: GatewayConnectConfig?,

0 commit comments

Comments
 (0)