Skip to content

Commit bb9e666

Browse files
sahrizviclaude
andcommitted
feat: make linked workspace names clickable in the sidebar, CLI link picker, and post-scan dialog
- `workspace-sidebar.tsx`: the workspace name + manage URL in the TUI sidebar tile now render underlined/accent-styled and open the browser on click (mouse events land on the enclosing `<text>`, not the inline `<span>`, matching the pattern already used for the footer's docs/ community links since raw `<a href>` crashes in this JSX layer). - `workspace.tsx`: extracted the guarded `open()` + toast-on-failure logic from `WorkspaceLinkedDialog` into a shared `openManageUrl()` helper, and added an "Open in browser" option to `AlreadyLinkedDialog` (shown on re-entering an already-linked project) using the same helper. - `cli/cmd/link.ts`: `altimate-code link`'s "Currently linked to X" prompt and the matching picker row now wrap the workspace name in a real OSC 8 terminal hyperlink (+ underline for visual affordance), so clicking it in a supporting terminal opens the workspace directly — no click-handler needed since the terminal itself renders the link. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JsVwcBQP6VUwqEej3vK2zG
1 parent 1bbf453 commit bb9e666

3 files changed

Lines changed: 137 additions & 43 deletions

File tree

‎packages/opencode/src/cli/cmd/link.ts‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ import { recordApprovedBinding } from "@/altimate/workspace/state"
4242
const CREATE_NEW_SENTINEL = "__create_new__"
4343
const SET_UP_IN_BROWSER_SENTINEL = "__browser_handoff__"
4444

45+
/** Wrap ``text`` in an OSC 8 terminal hyperlink pointing at ``url``, or return
46+
* ``text`` unchanged when ``url`` is null. Unlike the TUI's `<a href>` (which
47+
* crashes in the current @opentui/solid JSX layer — see workspace-sidebar.tsx),
48+
* plain stdout can emit OSC 8 directly: supporting terminals (iTerm2, Ghostty,
49+
* kitty, Windows Terminal, ...) render it as a real clickable link, and
50+
* terminals that don't recognize the sequence just skip the invisible control
51+
* bytes — the visible text is unaffected either way, so no capability check
52+
* is needed before emitting it. */
53+
function hyperlink(text: string, url: string | null): string {
54+
if (!url) return text
55+
const OSC8 = "\x1b]8;;"
56+
const ST = "\x1b\\"
57+
// Underline as a visual affordance that this text is clickable — OSC 8
58+
// alone carries no default styling. ``\x1b[24m`` (underline-off only, not
59+
// a full ``\x1b[0m`` reset) so it doesn't clobber a color clack already
60+
// applied around the whole line (e.g. the dim wrapper on a submitted value).
61+
const UNDERLINE = "\x1b[4m"
62+
const UNDERLINE_OFF = "\x1b[24m"
63+
return `${OSC8}${url}${ST}${UNDERLINE}${text}${UNDERLINE_OFF}${OSC8}${ST}`
64+
}
65+
4566
export const LinkCommand = cmd({
4667
command: "link",
4768
describe: "Link this project to an Altimate workspace",
@@ -128,8 +149,15 @@ export const LinkCommand = cmd({
128149
// (freemium only today). Enterprise / localhost / custom-domain callers
129150
// silently fall back to the CLI-side quick create.
130151
const creds = await AltimateApi.getCredentials()
131-
const browserAvailable =
132-
resolveWorkspaceWebUrl(creds.altimateUrl, creds.altimateInstanceName) !== null
152+
const workspaceWebBase = resolveWorkspaceWebUrl(creds.altimateUrl, creds.altimateInstanceName)
153+
const browserAvailable = workspaceWebBase !== null
154+
// Deterministic from tenant + id, same derivation as the TUI's
155+
// buildManageUrl (workspace.tsx) — null on BYOK/unresolvable, in which
156+
// case the name below prints as plain (non-clickable) text.
157+
const currentManageUrl =
158+
currentId !== undefined && workspaceWebBase
159+
? `${workspaceWebBase.toString().replace(/\/$/, "")}/w/${currentId}`
160+
: null
133161

134162
const options: Array<{ value: string; label: string; hint?: string }> = [
135163
// Only offer browser handoff for UNLINKED projects (CodeRabbit cycle 5).
@@ -162,14 +190,15 @@ export const LinkCommand = cmd({
162190
},
163191
...list.map((dm) => ({
164192
value: String(dm.id),
165-
label: dm.id === currentId ? `● ${dm.name}` : ` ${dm.name}`,
193+
label:
194+
dm.id === currentId ? `● ${hyperlink(dm.name, currentManageUrl)}` : ` ${dm.name}`,
166195
hint: dm.id === currentId ? "currently linked here" : undefined,
167196
})),
168197
]
169198

170199
const pick = await prompts.select<string>({
171200
message: existing
172-
? `Currently linked to "${currentName}". Pick a workspace (or create a new one):`
201+
? `Currently linked to "${hyperlink(currentName!, currentManageUrl)}". Pick a workspace (or create a new one):`
173202
: "Pick a workspace to link (or create a new one):",
174203
options,
175204
initialValue: currentId !== undefined ? String(currentId) : CREATE_NEW_SENTINEL,

‎packages/opencode/src/plugin/tui/altimate/workspace-sidebar.tsx‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { readLocalBinding, type CachedBinding } from "@/altimate/workspace/state
1313
import { resolveWorkspaceWebUrl } from "@/altimate/workspace/browser-handoff"
1414
import { getResolvedWorkspaceId } from "@/altimate/workspace/session-context"
1515
import { AltimateApi } from "@/altimate/api/client"
16+
import { openManageUrl } from "./workspace"
1617

1718
const id = "altimate:sidebar-workspace"
1819

@@ -97,8 +98,26 @@ function View(props: { api: TuiPluginApi }) {
9798
>
9899
{(b) => (
99100
<>
100-
<text fg={theme().textMuted}>
101-
{b().datamateName}
101+
{/* Clicking the name (or the URL line below) opens the workspace
102+
* in the browser — the manage URL is deterministic from tenant
103+
* + id (see resolveManageBase above), so there's no extra
104+
* round-trip before it's clickable. The whole line is the
105+
* click target (mouse events only land on block-level
106+
* `<text>`/`<box>`, not inline `<span>`/`<a>` nodes), while only
107+
* the name itself is styled to look like a link — matching the
108+
* footer's community/docs links (sidebar/footer.tsx), which use
109+
* the same span-style + onMouseUp pair because raw `<a href>`
110+
* hyperlink nodes crash in this JSX layer. */}
111+
<text
112+
fg={theme().textMuted}
113+
onMouseUp={() => {
114+
const url = manageUrl()
115+
if (url) openManageUrl(props.api, url)
116+
}}
117+
>
118+
<Show when={manageUrl()} fallback={b().datamateName}>
119+
{(_u) => <span style={{ fg: theme().accent, underline: true }}>{b().datamateName}</span>}
120+
</Show>
102121
{/* ``pinned via --workspace`` means "this SESSION was launched
103122
* with --workspace and it resolved to this id". It does NOT
104123
* mean "the current binding was set by --workspace" — if the
@@ -117,7 +136,11 @@ function View(props: { api: TuiPluginApi }) {
117136
</Show>
118137
</text>
119138
<Show when={manageUrl()}>
120-
{(u) => <text fg={theme().textMuted}>{u()}</text>}
139+
{(u) => (
140+
<text fg={theme().textMuted} onMouseUp={() => openManageUrl(props.api, u())}>
141+
<span style={{ fg: theme().accent, underline: true }}>{u()}</span>
142+
</text>
143+
)}
121144
</Show>
122145
</>
123146
)}

‎packages/opencode/src/plugin/tui/altimate/workspace.tsx‎

Lines changed: 78 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -297,26 +297,11 @@ function WorkspaceLinkedDialog(props: LinkedProps) {
297297
current={props.manageUrl ? "open" : "done"}
298298
onSelect={(option) => {
299299
if (option.value === "open" && props.manageUrl) {
300-
const url = props.manageUrl
301300
// Guard before delegating to open() — a rogue manage_url with a
302301
// non-http protocol would otherwise dispatch to an unrelated OS
303302
// scheme handler. buildManageUrl only ever emits http(s) URLs from
304303
// resolveWorkspaceWebUrl, but the guard survives future changes.
305-
if (!isSafeHttpUrl(url)) {
306-
props.api.ui.toast({
307-
variant: "warning",
308-
message: `Refused to open a non-http URL: ${url}`,
309-
duration: 15_000,
310-
})
311-
} else {
312-
open(url).catch(() => {
313-
props.api.ui.toast({
314-
variant: "warning",
315-
message: `Could not open browser. Copy this URL: ${url}`,
316-
duration: 15_000,
317-
})
318-
})
319-
}
304+
openManageUrl(props.api, props.manageUrl)
320305
}
321306
props.api.ui.dialog.clear()
322307
}}
@@ -579,9 +564,10 @@ async function createAndBindInline(
579564
/** True when the URL parses and its protocol is exactly ``http:`` or ``https:``.
580565
* Used before handing a server-supplied URL to ``open()`` (which would otherwise
581566
* dispatch to whatever OS scheme handler matches the protocol). Kept exported
582-
* as a top-level helper because both ``showLinkedConfirmation`` (below) and
583-
* the on-demand link paths need the same guard. */
584-
function isSafeHttpUrl(url: string): boolean {
567+
* as a top-level helper — ``openManageUrl`` below is the sole in-module caller,
568+
* but ``cli/cmd/link.ts`` deliberately keeps its own copy (CLI/TUI split, see
569+
* that file's comment) rather than importing this one. */
570+
export function isSafeHttpUrl(url: string): boolean {
585571
try {
586572
const u = new URL(url)
587573
return u.protocol === "http:" || u.protocol === "https:"
@@ -590,6 +576,29 @@ function isSafeHttpUrl(url: string): boolean {
590576
}
591577
}
592578

579+
/** Guarded ``open(url)`` for a workspace manage-URL, with the same
580+
* refuse-and-toast / catch-and-toast behavior as ``WorkspaceLinkedDialog``'s
581+
* "open" action below. Shared with ``workspace-sidebar.tsx`` (both live under
582+
* this TUI plugin path — unlike ``isSafeHttpUrl``'s CLI/TUI split, there's no
583+
* reason for these two call sites to diverge). */
584+
export function openManageUrl(api: TuiPluginApi, url: string) {
585+
if (!isSafeHttpUrl(url)) {
586+
api.ui.toast({
587+
variant: "warning",
588+
message: `Refused to open a non-http URL: ${url}`,
589+
duration: 15_000,
590+
})
591+
return
592+
}
593+
open(url).catch(() => {
594+
api.ui.toast({
595+
variant: "warning",
596+
message: `Could not open browser. Copy this URL: ${url}`,
597+
duration: 15_000,
598+
})
599+
})
600+
}
601+
593602
/** Pick the rebind endpoint that matches which identifier the pre-check
594603
* resolved the binding on. Shared with cli/cmd/link.ts through duplicated
595604
* code (M3) — the modules deliberately don't cross-import so the CLI
@@ -636,42 +645,75 @@ interface AlreadyLinkedProps {
636645
}
637646

638647
function AlreadyLinkedDialog(props: AlreadyLinkedProps) {
648+
// Best-effort — same deterministic tenant+id derivation as buildManageUrl's
649+
// other callers. null on BYOK/unresolvable, in which case the "Open in
650+
// browser" option below is simply omitted.
651+
const [manageUrl, setManageUrl] = createSignal<string | null>(null)
652+
onMount(async () => {
653+
setManageUrl(await buildManageUrl(props.workspaceId))
654+
})
655+
639656
// Title carries the primary context (workspace name + drift/unverified hint)
640657
// since DialogSelect doesn't take a top-level description block. Verbose but
641658
// it puts the critical info in the user's field of view before they pick.
659+
//
660+
// The plugin-facing ``TuiDialogSelectProps`` (packages/plugin/src/tui.ts)
661+
// only takes a plain ``title: string`` — no ``titleView``/JSX escape hatch
662+
// like the native ``packages/tui`` DialogSelect has (see
663+
// dialog-move-session.tsx) — so the workspace name inside the title can't
664+
// be made clickable the way the sidebar tile is. "Open in browser" as a
665+
// selectable option (below) is the equivalent affordance within that API.
642666
const title = () => {
643667
const parts: string[] = [`Project is linked to workspace "${props.workspaceName}"`]
644668
const now = props.identifier.repoRemote ?? props.identifier.projectPath
645669
if (props.hasDrift && props.driftedWas) parts.push(`(was ${props.driftedWas}, now ${now})`)
646670
if (props.unverified) parts.push("(⚠ unverified — server unreachable, showing cached value)")
647671
return parts.join(" ")
648672
}
673+
const options = () => {
674+
const opts = [
675+
{
676+
title: "Attach and continue",
677+
value: "attach",
678+
description: "Use this workspace for the session.",
679+
},
680+
{
681+
title: "Re-link to a different workspace",
682+
value: "relink",
683+
description: "Swap this project's workspace.",
684+
},
685+
]
686+
if (manageUrl()) {
687+
opts.push({
688+
title: "Open in browser",
689+
value: "open",
690+
description: "View this workspace on the web.",
691+
})
692+
}
693+
opts.push({
694+
title: "Skip for now",
695+
value: "skip",
696+
description: "Close this prompt without changing the link.",
697+
})
698+
return opts
699+
}
649700
return (
650701
<props.api.ui.DialogSelect
651702
title={title()}
652-
options={[
653-
{
654-
title: "Attach and continue",
655-
value: "attach",
656-
description: "Use this workspace for the session.",
657-
},
658-
{
659-
title: "Re-link to a different workspace",
660-
value: "relink",
661-
description: "Swap this project's workspace.",
662-
},
663-
{
664-
title: "Skip for now",
665-
value: "skip",
666-
description: "Close this prompt without changing the link.",
667-
},
668-
]}
703+
options={options()}
669704
current={props.hasDrift ? "relink" : "attach"}
670705
onSelect={(option) => {
671706
if (option.value === "attach" || option.value === "skip") {
672707
props.api.ui.dialog.clear()
673708
return
674709
}
710+
if (option.value === "open") {
711+
const url = manageUrl()
712+
if (url) openManageUrl(props.api, url)
713+
// Stay open — opening the browser isn't a decision about the link
714+
// itself, so the user can still Attach/Re-link/Skip afterward.
715+
return
716+
}
675717
// relink → picker with the current workspace id as expected_current so
676718
// a concurrent re-link by another client 412s cleanly. matchedBy
677719
// determines which rebind endpoint the picker will call (M3).

0 commit comments

Comments
 (0)