Skip to content

Commit af552d4

Browse files
authored
feat(ui): resolve session URLs through the gateway with best-effort slug matching (#114422)
* feat(ui): resolve session URLs through the gateway with best-effort slug matching Session URLs now resolve a stored board face and a display-name slug through the gateway instead of guessing from the browser's cached session page. - An uncached open marks only the in-app navigation, never the shareable href, so the chat loader can re-derive the face and replace the URL. - A cached row settles the lookup locally, keeping navigation off the wire. - A one-segment reference resolves short id, then literal key, then display-name slug; ties reuse the existing disambiguation view. * refactor(ui): keep slug ties on short disambiguation prefixes Slug candidates reused the full uuid, which produced 32-character links in the disambiguation view. uniqueShortIdPrefix already falls back to the full id when the bounded search was truncated, so reuse it and drop the flag. * fix(ui): navigate worktree owner links in-app so the face marker survives The Worktrees owner link was a bare anchor consuming only the shareable href, so preferenceDerivedFace was a no-op there and an uncached owner always opened on chat. Match the other session surfaces: keep the clean href and navigate with the options on plain clicks. * fix(ui): search the first uuid block so long session references resolve The gateway matches sessions.list search as a plain substring and stored keys hold a hyphenated uuid, so any hyphen-stripped reference past the first block matched nothing and 404'd. This hit disambiguation links, which offer prefixes longer than eight characters. Send the first block and keep applying the full prefix per row. A resolved slug now canonicalizes to that same short reference instead of a full uuid, so /chat/main/deploy-monitor settles on -6db92d48. * docs(ui): record why the face marker stays out of shareable hrefs
1 parent 067820f commit af552d4

25 files changed

Lines changed: 1089 additions & 101 deletions

‎docs/web/dashboards.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ thread's `/dashboard/<agent>/<sessionRef>` URL.
2424

2525
The Chat or Dashboard face preference is stored server-side per thread. It
2626
therefore follows you when you connect to the same gateway from another device.
27+
Opening a thread from the sidebar, Sessions, Tasks, Workboard, or Worktrees
28+
applies that stored face even when the thread is outside the page of sessions
29+
already loaded by the browser.
2730
The active dashboard tab and remembered chat-dock position remain per-device UI
2831
state, so each browser can keep its own working layout.
2932

‎docs/web/urls.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ the reconstructed session key. The remaining literal segments are authoritative
8787
too. A slug, when present, is always decorative; literal-key forms do not
8888
synthesize one.
8989

90+
As a best-effort convenience, an unescaped one-segment literal that does not
91+
resolve as an exact session key is also checked against display-name slugs. One
92+
exact slug match is replaced in the address bar with its full
93+
`/<namespace>/<agentId>/<slug>-<shortId>` reference. If several sessions share
94+
the slug, the UI shows the same disambiguation view used for short-id ties
95+
instead of guessing. Exact short-id and literal-key references always win over
96+
slug matching.
97+
9098
If one short id matches more than one session, the UI does not guess. It shows a
9199
small disambiguation view with the matching display names, agents, and longer id
92100
prefixes. Use a longer prefix to make the URL unique. Resolution examines at

‎packages/session-url-contract/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function isReservedSessionRest(rest: string, mainKey: string | undefined): boole
8282
);
8383
}
8484

85-
function controlUiSessionSlug(displayName: string | undefined | null): string {
85+
export function controlUiSessionSlug(displayName: string | undefined | null): string {
8686
const tokens = (displayName ?? "")
8787
.toLowerCase()
8888
.replace(/[^a-z0-9]+/gu, "-")

‎packages/session-url-contract/src/parse.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type ControlUiSessionPathTarget =
1111
kind: "literal";
1212
agentId: string;
1313
sessionKey: string;
14+
slugCandidate?: string;
1415
};
1516

1617
const SHORT_SESSION_REF_RE = /^(?:.*-)?([0-9a-f]{8,32})$/iu;
@@ -127,7 +128,7 @@ export function parseControlUiSessionPath(
127128
const shortId = segment.match(SHORT_SESSION_REF_RE)?.[1]?.toLowerCase();
128129
return shortId
129130
? { namespace, kind: "short", agentId, shortId }
130-
: { namespace, kind: "literal", agentId, sessionKey };
131+
: { namespace, kind: "literal", agentId, sessionKey, slugCandidate: segment };
131132
}
132133
return null;
133134
}

‎ui/src/app/app-host.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
UI_COMMAND_EVENT,
1616
} from "../components/panel-toggle-contract.ts";
1717
import { i18n } from "../i18n/index.ts";
18+
import { SESSION_FACE_PREFERENCE_PARAM } from "../lib/sessions/route-navigation.ts";
1819
import { createStorageMock } from "../test-helpers/storage.ts";
1920
import { selectShellRouteState } from "./app-host-route-state.ts";
2021
import { resetAppHostTestGlobals, type ShellKeyboardState } from "./app-host.test-support.ts";
@@ -907,7 +908,12 @@ describe("OpenClaw shell keyboard shortcuts", () => {
907908
expect(setSessionKey).toHaveBeenCalledWith(
908909
"agent:main:dashboard:12345678-90ab-cdef-1234-567890abcdef",
909910
);
910-
expect(navigate).toHaveBeenCalledWith("chat", { pathname: "/chat/main/12345678" });
911+
// The pushed command names a session the UI has not cached, so its face is a guess
912+
// and the navigation is marked for the chat loader to re-derive from the gateway.
913+
expect(navigate).toHaveBeenCalledWith("chat", {
914+
pathname: "/chat/main/12345678",
915+
search: `?${SESSION_FACE_PREFERENCE_PARAM}=1`,
916+
});
911917
expect(uiCommandEvent).toHaveBeenLastCalledWith(
912918
expect.objectContaining({
913919
detail: {

‎ui/src/app/app-host.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,15 @@ class OpenClawShell extends OpenClawLightDomElement {
839839
const face = resolveSessionPreferredFaceForKey(context, sessionKey);
840840
// Ambiguous one-segment keys intentionally fall back to /chat;
841841
// the removed query deep-link format is not a compatibility path.
842-
this.navigate(face, sessionNavigationTarget({ context, face, sessionKey }).options);
842+
this.navigate(
843+
face,
844+
sessionNavigationTarget({
845+
context,
846+
face,
847+
sessionKey,
848+
preferenceDerivedFace: true,
849+
}).options,
850+
);
843851
},
844852
}),
845853
);
@@ -901,7 +909,12 @@ class OpenClawShell extends OpenClawLightDomElement {
901909
const face = resolveSessionPreferredFaceForKey(context, command.sessionKey);
902910
this.navigate(
903911
face,
904-
sessionNavigationTarget({ context, face, sessionKey: command.sessionKey }).options,
912+
sessionNavigationTarget({
913+
context,
914+
face,
915+
sessionKey: command.sessionKey,
916+
preferenceDerivedFace: true,
917+
}).options,
905918
);
906919
};
907920

@@ -1765,7 +1778,15 @@ class OpenClawShell extends OpenClawLightDomElement {
17651778
.onSelectSession=${(sessionKey: string) => {
17661779
context.gateway.setSessionKey(sessionKey);
17671780
const face = resolveSessionPreferredFaceForKey(context, sessionKey);
1768-
this.navigate(face, sessionNavigationTarget({ context, face, sessionKey }).options);
1781+
this.navigate(
1782+
face,
1783+
sessionNavigationTarget({
1784+
context,
1785+
face,
1786+
sessionKey,
1787+
preferenceDerivedFace: true,
1788+
}).options,
1789+
);
17691790
}}
17701791
.onSlashCommand=${this.handleCommandPaletteSlashCommand}
17711792
></openclaw-command-palette>`

‎ui/src/components/app-sidebar-render.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export function renderAppSidebarHomeRow(host: AppSidebarRenderHost) {
145145
basePath: host.basePath,
146146
row: mainRow ?? undefined,
147147
mainKey: parseAgentSessionKey(mainKey)?.rest,
148+
preferenceDerivedFace: true,
148149
}).href}
149150
class="nav-item nav-item--home ${active ? "nav-item--active" : ""}"
150151
aria-current=${active ? "page" : nothing}

‎ui/src/components/app-sidebar-session-navigation-logic.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export function buildSidebarSessionNavigationState(input: {
132132
basePath: context?.basePath ?? "",
133133
row,
134134
mainKey,
135+
preferenceDerivedFace: true,
135136
}).href,
136137
active: row.key === navigation.activeRowKey,
137138
visuallyActive: input.highlightCurrentSession && row.key === navigation.currentSessionKey,

‎ui/src/components/app-sidebar-session-navigation.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
293293
basePath: this.basePath,
294294
row: this.findSidebarSessionByKey(sessionKey),
295295
mainKey: this.sessionMainKey(),
296+
preferenceDerivedFace: true,
296297
});
297298
this.context?.gateway.setSessionKey(sessionKey);
298299
this.onNavigate?.(face, target.options);
@@ -432,6 +433,7 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
432433
basePath: this.basePath,
433434
row: this.findSidebarSessionByKey(sessionKey),
434435
mainKey: this.sessionMainKey(),
436+
preferenceDerivedFace: true,
435437
});
436438
this.context?.gateway.setSessionKey(sessionKey);
437439
if (isSessionRouteId(this.activeRouteId)) {

‎ui/src/lib/sessions/route-navigation.test.ts‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, expect, it } from "vitest";
22
import { buildCatalogSessionKey } from "./catalog-key.ts";
3-
import { resolveSessionPreferredFace, sessionNavigationTarget } from "./route-navigation.ts";
3+
import {
4+
resolveSessionPreferredFace,
5+
SESSION_FACE_PREFERENCE_PARAM,
6+
sessionNavigationTarget,
7+
} from "./route-navigation.ts";
48

59
describe("sessionNavigationTarget", () => {
610
it("defaults generic opens to chat and honors a stored dashboard preference", () => {
@@ -69,4 +73,38 @@ describe("sessionNavigationTarget", () => {
6973
options: { pathname: "/chat/research/telegram/12345" },
7074
});
7175
});
76+
77+
it("marks an uncached preference-derived face for in-app navigation but keeps href shareable", () => {
78+
const target = sessionNavigationTarget({
79+
face: "chat",
80+
sessionKey: "agent:main:dashboard:12345678-90ab-cdef-1234-567890abcdef",
81+
fallbackAgentId: "main",
82+
preferenceDerivedFace: true,
83+
});
84+
85+
// href gets copied and shared, so it stays the clean best-guess path; only the
86+
// in-app navigation carries the marker that lets the loader re-derive the face.
87+
expect(target.href).toBe("/chat/main/12345678");
88+
expect(target.options).toEqual({
89+
pathname: "/chat/main/12345678",
90+
search: `?${SESSION_FACE_PREFERENCE_PARAM}=1`,
91+
});
92+
});
93+
94+
it("leaves a cached row unmarked because its stored face is already authoritative", () => {
95+
const row = {
96+
key: "agent:main:dashboard:12345678-90ab-cdef-1234-567890abcdef",
97+
displayName: "Release Notes",
98+
};
99+
const target = sessionNavigationTarget({
100+
face: "chat",
101+
sessionKey: row.key,
102+
fallbackAgentId: "main",
103+
row,
104+
preferenceDerivedFace: true,
105+
});
106+
107+
expect(target.href).toBe("/chat/main/release-notes-12345678");
108+
expect(target.options).toEqual({ pathname: "/chat/main/release-notes-12345678" });
109+
});
72110
});

0 commit comments

Comments
 (0)