GeezerVison is showing github.com — feat(app): add session location menu actions (#59607) · abn/opencode@4ba064f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/regression/session-header.spec.ts +96-1Lines changed: 96 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@ import type { SessionMessageInfo } from "@opencode/client/promise" | 2 | 2 | import { expect, test, type Page } from "@playwright/test" | 3 | 3 | import { REMOTE_SERVER, seed, sessionHref } from "../utils/app" | 4 | 4 | import { fixture, mockStressTimeline } from "../utils/session-fixture" | | 5 | +import { reviewTabs } from "../utils/side-panel" | 5 | 6 | import { expectSessionTitle } from "../utils/waits" | 6 | 7 | import { mockRemoteServer, mockWorkspace, openSession } from "../utils/workspace" | 7 | 8 |
| @@ -333,14 +334,16 @@ test.describe("location", () => { | 333 | 334 |
| 334 | 335 | test("names the project and worktree, and the card copies the full path", async ({ page, context }) => { | 335 | 336 | await context.grantPermissions(["clipboard-read", "clipboard-write"]) | 336 | | - await openSession(page, workspace) | | 337 | + await openSession(page, { ...workspace, vcs: { current: "", default: "main" } }) | 337 | 338 | await expect(trigger(page).locator('[data-slot="session-location-project"]')).toHaveText("Location") | 338 | 339 | await expect(trigger(page).locator('[data-slot="session-location-worktree"]')).toHaveText("quiet-falcon") | 339 | 340 | await expect(trigger(page)).not.toContainText("/") | 340 | 341 | await expect(trigger(page).locator('svg:has(use[href="#opencode-v2-icon-outline-worktree"])')).toBeVisible() | 341 | 342 | await trigger(page).click() | 342 | 343 | const card = page.locator('[data-slot="session-location-card"]') | 343 | 344 | const path = card.getByRole("menuitem", { name: worktree, exact: true }) | | 345 | + await expect(card.getByText("No branch", { exact: true })).toBeVisible() | | 346 | + await expect(card.getByRole("menuitem", { name: "No branch", exact: true })).toHaveCount(0) | 344 | 347 | await expect(path).toHaveText(worktree) | 345 | 348 | await expect(card.getByRole("menuitem", { name: "Copy path", exact: true })).toHaveCount(0) | 346 | 349 | // Select actual text on the first line, not the empty half of a wrapped path's bounding box. | @@ -379,6 +382,98 @@ test.describe("location", () => { | 379 | 382 | await expect(page.locator('[data-slot="session-location-card"]').getByText("apollo", { exact: true })).toBeVisible() | 380 | 383 | }) | 381 | 384 |
| | 385 | + test("copies the branch name and opens its worktree in the right-panel terminal", async ({ page, context }) => { | | 386 | + await context.grantPermissions(["clipboard-read", "clipboard-write"]) | | 387 | + await page.setViewportSize({ width: 1440, height: 900 }) | | 388 | + | | 389 | + const { pty } = await openSession(page, { | | 390 | + ...workspace, | | 391 | + vcs: (directory) => ({ current: directory === worktree ? "feature/branch-menu" : "main", default: "main" }), | | 392 | + pty: {}, | | 393 | + }) | | 394 | + | | 395 | + await expect(page.getByRole("button", { name: "More options", exact: true })).toBeVisible() | | 396 | + await trigger(page).click() | | 397 | + const card = page.locator('[data-slot="session-location-card"]') | | 398 | + const branch = card.getByRole("menuitem", { name: "feature/branch-menu", exact: true }) | | 399 | + await page.screenshot({ path: test.info().outputPath("branch-card.png"), animations: "disabled" }) | | 400 | + await branch.press("Enter") | | 401 | + const actions = page.getByRole("menu", { name: "feature/branch-menu", exact: true }) | | 402 | + await expect(actions.getByRole("menuitem")).toHaveText(["Copy branch name", "Open in terminal"]) | | 403 | + await page.screenshot({ path: test.info().outputPath("branch-actions.png"), animations: "disabled" }) | | 404 | + await actions.getByRole("menuitem", { name: "Copy branch name", exact: true }).click() | | 405 | + await expect(card).toBeHidden() | | 406 | + await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe("feature/branch-menu") | | 407 | + | | 408 | + await trigger(page).click() | | 409 | + await branch.click() | | 410 | + await actions.getByRole("menuitem", { name: "Open in terminal", exact: true }).click() | | 411 | + await expect(card).toBeHidden() | | 412 | + await expect.poll(() => pty.created.map((item) => item.cwd)).toEqual([worktree]) | | 413 | + await expect.poll(() => pty.sockets.length).toBe(1) | | 414 | + pty.send("$ pwd\r\n" + worktree + "\r\n") | | 415 | + const terminal = page.locator('[data-component="terminal"]') | | 416 | + await expect(terminal).toHaveCSS("opacity", "1") | | 417 | + await expect(terminal.locator("textarea")).toBeFocused() | | 418 | + await expect | | 419 | + .poll(async () => { | | 420 | + const box = await terminal.boundingBox() | | 421 | + const header = await page.locator("[data-session-title]").boundingBox() | | 422 | + | | 423 | + return !!box && !!header && box.x >= header.x + header.width | | 424 | + }) | | 425 | + .toBe(true) | | 426 | + await page.screenshot({ path: test.info().outputPath("branch-terminal.png"), animations: "disabled" }) | | 427 | + }) | | 428 | + | | 429 | + for (const app of [ | | 430 | + { id: "vscode", label: "VS Code" }, | | 431 | + { id: "finder", label: "Finder" }, | | 432 | + ]) { | | 433 | + test(`uses the selected ${app.label} app in the path submenu`, async ({ page }) => { | | 434 | + await page.setViewportSize({ width: 1440, height: 900 }) | | 435 | + | | 436 | + const mock = await mockWorkspace(page, { | | 437 | + ...workspace, | | 438 | + seed: { | | 439 | + storage: { | | 440 | + ...reviewTabs(worktree, "ses_location"), | | 441 | + "opencode.global.dat:plugin.file.app": { app: app.id }, | | 442 | + }, | | 443 | + }, | | 444 | + }) | | 445 | + | | 446 | + await page.goto( | | 447 | + `/e2e/utils/windows-menu.html?${new URLSearchParams({ | | 448 | + server: mock.server, | | 449 | + path: sessionHref("ses_location", "sidecar"), | | 450 | + os: "macos", | | 451 | + openApps: "1", | | 452 | + })}`, | | 453 | + ) | | 454 | + await expectSessionTitle(page, "Location session") | | 455 | + await page.getByRole("button", { name: "Toggle review", exact: true }).click() | | 456 | + // Opening review hands focus to the panel after its motion; let that finish before opening another menu. | | 457 | + await expect(page.getByRole("complementary", { name: "Review and files", exact: true })).toBeFocused() | | 458 | + await expect(page.getByRole("button", { name: `Open in ${app.label}`, exact: true })).toBeVisible() | | 459 | + await trigger(page).click() | | 460 | + await page.getByRole("menuitem", { name: worktree, exact: true }).click() | | 461 | + const actions = page.getByRole("menu", { name: worktree, exact: true }) | | 462 | + | | 463 | + if (app.id === "finder") { | | 464 | + await expect(actions.getByRole("menuitem")).toHaveText(["Copy path", "Reveal in Finder"]) | | 465 | + | | 466 | + return | | 467 | + } | | 468 | + | | 469 | + await page.screenshot({ path: test.info().outputPath("path-open-app.png"), animations: "disabled" }) | | 470 | + await actions.getByRole("menuitem", { name: "Open in VS Code", exact: true }).click() | | 471 | + await expect(page.getByLabel("Opened paths")).toHaveText( | | 472 | + JSON.stringify([{ path: worktree, app: "Visual Studio Code" }]), | | 473 | + ) | | 474 | + }) | | 475 | + } | | 476 | + | 382 | 477 | test.describe("touch", () => { | 383 | 478 | test.use({ hasTouch: true }) | 384 | 479 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/utils/windows-menu.fixture.tsx +15-3Lines changed: 15 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,15 +7,18 @@ import { PlatformProvider, type Platform } from "../../src/runtime/platform/plat | 7 | 7 |
| 8 | 8 | // The app on a Windows desktop platform, so the titlebar shows the app menu. Menu actions are listed in an output. | 9 | 9 | // `path` opens a route other than Home. | 10 | | -export function mount(input: { server: string; path?: string }) { | | 10 | +export function mount(input: { server: string; path?: string; os?: "macos"; openApps?: boolean }) { | 11 | 11 | const root = document.getElementById("root") | 12 | 12 |
| 13 | 13 | if (!root) throw new Error("Missing fixture root") | 14 | 14 | const history = createMemoryHistory() | 15 | 15 |
| 16 | 16 | if (input.path) history.set({ value: input.path, replace: true }) | 17 | 17 | render(() => { | 18 | | - const [store, setStore] = createStore<{ actions: string[] }>({ actions: [] }) | | 18 | + const [store, setStore] = createStore<{ actions: string[]; opened: { path: string; app?: string }[] }>({ | | 19 | + actions: [], | | 20 | + opened: [], | | 21 | + }) | 19 | 22 |
| 20 | 23 | const unused = async () => { | 21 | 24 | throw new Error("Unexpected fixture action") | @@ -42,7 +45,7 @@ export function mount(input: { server: string; path?: string }) { | 42 | 45 |
| 43 | 46 | const platform: Platform = { | 44 | 47 | platform: "desktop", | 45 | | - os: "windows", | | 48 | + os: input.os ?? "windows", | 46 | 49 | windowID: "windows-menu-test", | 47 | 50 | openExternal: () => undefined, | 48 | 51 | openDirectoryPickerDialog: async () => null, | @@ -52,10 +55,19 @@ export function mount(input: { server: string; path?: string }) { | 52 | 55 | runDesktopMenuAction: (action) => setStore("actions", (actions) => [...actions, action]), | 53 | 56 | } | 54 | 57 |
| | 58 | + if (input.openApps) { | | 59 | + platform.checkAppExists = async (app) => app === "Visual Studio Code" || app === "code" | | 60 | + platform.openPath = async (path, app) => void setStore("opened", (opened) => [...opened, { path, app }]) | | 61 | + platform.revealPath = async () => true | | 62 | + } | | 63 | + | 55 | 64 | return ( | 56 | 65 | <PlatformProvider value={platform}> | 57 | 66 | <AppBaseProviders locale="en"> | 58 | 67 | <output aria-label="Desktop menu actions">{store.actions.join(",")}</output> | | 68 | + <output aria-label="Opened paths" class="sr-only"> | | 69 | + {JSON.stringify(store.opened)} | | 70 | + </output> | 59 | 71 | <AppInterface | 60 | 72 | servers={[{ type: "sidecar", variant: "base", displayName: "Local Server", http: { url: input.server } }]} | 61 | 73 | router={(props) => <MemoryRouter {...props} history={history} />} | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/utils/windows-menu.html +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | <script type="module"> | 9 | 9 | import { mount } from "./windows-menu.fixture.tsx" | 10 | 10 | const params = new URLSearchParams(location.search) | 11 | | - mount({ server: params.get("server"), path: params.get("path") ?? undefined }) | | 11 | + mount({ | | 12 | + server: params.get("server"), | | 13 | + path: params.get("path") ?? undefined, | | 14 | + os: params.get("os") === "macos" ? "macos" : undefined, | | 15 | + openApps: params.get("openApps") === "1", | | 16 | + }) | 12 | 17 | </script> | 13 | 18 | </body> | 14 | 19 | </html> |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/runtime/i18n/en.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -670,6 +670,7 @@ export const dict = { | 670 | 670 | "session.header.reveal.fileExplorer": "Reveal in File Explorer", | 671 | 671 | "session.header.reveal.containingFolder": "Open containing folder", | 672 | 672 | "session.location.copyPath": "Copy path", | | 673 | + "session.location.copyBranch": "Copy branch name", | 673 | 674 | "session.location.noBranch": "No branch", | 674 | 675 |
| 675 | 676 | "settings.tab.servers": "Servers", | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/session/session-identity-header.tsx +66-17Lines changed: 66 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -147,18 +147,14 @@ export function SessionLocation(props: { | 147 | 147 | void server.ctx.data.location.vcs.sync({ directory: props.project.worktree }).catch(() => undefined) | 148 | 148 | } | 149 | 149 |
| 150 | | - const copyPath = async () => { | 151 | | - const directory = props.directory | 152 | | - | 153 | | - if (!directory) return | 154 | | - | | 150 | + const copyText = async (text: string) => { | 155 | 151 | try { | 156 | | - await (platform.writeClipboardText?.(directory) ?? navigator.clipboard.writeText(directory)) | | 152 | + await (platform.writeClipboardText?.(text) ?? navigator.clipboard.writeText(text)) | 157 | 153 | showToast({ | 158 | 154 | variant: "success", | 159 | 155 | icon: "circle-check", | 160 | 156 | title: language.t("common.copied"), | 161 | | - description: directory, | | 157 | + description: text, | 162 | 158 | }) | 163 | 159 | } catch (cause) { | 164 | 160 | showToast({ | @@ -291,10 +287,10 @@ export function SessionLocation(props: { | 291 | 287 | </Show> | 292 | 288 | </Show> | 293 | 289 | <Show when={git()}> | 294 | | - <SessionLocationDetail icon="branch"> | 295 | | - <Show | 296 | | - when={branch()} | 297 | | - fallback={ | | 290 | + <Show | | 291 | + when={branch()} | | 292 | + fallback={ | | 293 | + <SessionLocationDetail icon="branch"> | 298 | 294 | <span class="flex min-w-0 items-center gap-1.5"> | 299 | 295 | <span class="shrink-0 whitespace-nowrap">{language.t("session.location.noBranch")}</span> | 300 | 296 | <Show when={baseBranch()}> | @@ -308,11 +304,46 @@ export function SessionLocation(props: { | 308 | 304 | )} | 309 | 305 | </Show> | 310 | 306 | </span> | 311 | | - } | 312 | | - > | 313 | | - {branch()} | 314 | | - </Show> | 315 | | - </SessionLocationDetail> | | 307 | + </SessionLocationDetail> | | 308 | + } | | 309 | + > | | 310 | + {(name) => ( | | 311 | + <Menu.Sub gutter={4} overflowPadding={16} overlap> | | 312 | + <Menu.SubTrigger class="[&_[data-slot=menu-v2-item-chevron]]:text-v2-icon-icon-muted"> | | 313 | + <Icon name="branch" class="shrink-0 text-v2-icon-icon-muted" /> | | 314 | + <bdi dir="auto" class="min-w-0 truncate"> | | 315 | + {name()} | | 316 | + </bdi> | | 317 | + </Menu.SubTrigger> | | 318 | + <Menu.Portal> | | 319 | + <Menu.SubContent class="w-max max-w-[calc(100vw-32px)]" aria-label={name()}> | | 320 | + <Menu.Item onSelect={() => void copyText(name())}> | | 321 | + <Icon name="outline-copy" class="text-v2-icon-icon-muted" /> | | 322 | + {language.t("session.location.copyBranch")} | | 323 | + </Menu.Item> | | 324 | + <Show when={props.context}> | | 325 | + {(context) => ( | | 326 | + <PluginSlot | | 327 | + at="session.location.branch.menu" | | 328 | + input={{ | | 329 | + get session() { | | 330 | + return context().session | | 331 | + }, | | 332 | + get screen() { | | 333 | + return context().screen | | 334 | + }, | | 335 | + get shown() { | | 336 | + return store.open | | 337 | + }, | | 338 | + }} | | 339 | + /> | | 340 | + )} | | 341 | + </Show> | | 342 | + </Menu.SubContent> | | 343 | + </Menu.Portal> | | 344 | + </Menu.Sub> | | 345 | + )} | | 346 | + </Show> | 316 | 347 | </Show> | 317 | 348 | <Show when={props.context}> | 318 | 349 | {(context) => ( | @@ -353,7 +384,7 @@ export function SessionLocation(props: { | 353 | 384 | </Menu.SubTrigger> | 354 | 385 | <Menu.Portal> | 355 | 386 | <Menu.SubContent class="w-max max-w-[calc(100vw-32px)]" aria-label={directory()}> | 356 | | - <Menu.Item onSelect={() => void copyPath()}> | | 387 | + <Menu.Item onSelect={() => void copyText(directory())}> | 357 | 388 | <Icon name="outline-copy" class="text-v2-icon-icon-muted" /> | 358 | 389 | {language.t("session.location.copyPath")} | 359 | 390 | </Menu.Item> | @@ -363,6 +394,24 @@ export function SessionLocation(props: { | 363 | 394 | {language.t(fileManagerApp(platform.os ?? "unknown").actionLabel)} | 364 | 395 | </Menu.Item> | 365 | 396 | </Show> | | 397 | + <Show when={props.context}> | | 398 | + {(context) => ( | | 399 | + <PluginSlot | | 400 | + at="session.location.path.menu" | | 401 | + input={{ | | 402 | + get session() { | | 403 | + return context().session | | 404 | + }, | | 405 | + get screen() { | | 406 | + return context().screen | | 407 | + }, | | 408 | + get shown() { | | 409 | + return store.open | | 410 | + }, | | 411 | + }} | | 412 | + /> | | 413 | + )} | | 414 | + </Show> | 366 | 415 | </Menu.SubContent> | 367 | 416 | </Menu.Portal> | 368 | 417 | </Menu.Sub> | |
Collapse file Copy file name to clipboardExpand all lines: packages/gui-plugins/README.md +11-1Lines changed: 11 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -224,14 +224,24 @@ SDK icon fields take an `IconName` from `@opencode/plugin/gui`: the names of the | 224 | 224 | | [`LinkHandler`](../plugin/src/gui/registries.ts) | window | Opens local links, such as file paths in messages, and says whether their target exists | | 225 | 225 | | [`TitlebarItem`](../plugin/src/gui/registries.ts) | window | A pill in the titlebar or the tabs footer | | 226 | 226 | | [`ComposerPill`](../plugin/src/gui/registries.ts) | window | A pill in the row above a session's composer, optionally opening a menu of rows | | 227 | | -| [`Slot`](../plugin/src/gui/registries.ts) | window | Content for `window.bottom`, `session.header`, `session.location.menu`, `session.panel.end`; built-ins also fill `session.location.workspace` through `BuiltinSlot` | | | 227 | +| [`Slot`](../plugin/src/gui/registries.ts) | window | Content for `window.bottom`, `session.header`, `session.location.menu`, `session.panel.end`; built-ins also fill `session.location.workspace`, `session.location.branch.menu` and `session.location.path.menu` through `BuiltinSlot` | | 228 | 228 | | [`Style`](../plugin/src/gui/registries.ts) | window | CSS imported with `?inline` | | 229 | 229 | | [`MenubarItem`](../plugin/src/gui/main.ts) | main | An item of the native app menu | | 230 | 230 |
| 231 | 231 | `session.location.menu` contributes items after the project menu's location details. It receives the owning `screen`, | 232 | 232 | the live `session`, and `shown`; keep data subscriptions active only while `shown` is true. Loading headers without an | 233 | 233 | owning screen show the host's location details without this slot. | 234 | 234 |
| | 235 | +`session.location.branch.menu` (built-ins only, through `BuiltinSlot`) contributes items after Copy branch name in | | 236 | +the branch submenu, with the same `screen`, live `session`, and project-menu `shown` context. It renders only when a | | 237 | +branch name and owning screen are available. Use it for actions on the branch's working directory, such as opening | | 238 | +an integrated terminal. | | 239 | + | | 240 | +`session.location.path.menu` (built-ins only, through `BuiltinSlot`) contributes items after the host's copy and | | 241 | +reveal actions in the session directory's path submenu. It receives the same session context and renders only with | | 242 | +an owning screen. Use it for external-app actions on `session.directory` without duplicating the host's file-manager | | 243 | +action. | | 244 | + | 235 | 245 | `session.location.workspace` (built-ins only, through `BuiltinSlot`) replaces the current location row with the same | 236 | 246 | session context plus its `label` and `icon`; one contribution owns it. Without a contribution, the host keeps its | 237 | 247 | static location row. Use it to attach location actions directly | |
Collapse file Copy file name to clipboardExpand all lines: packages/gui-plugins/src/file/open-in-app.tsx +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -193,6 +193,27 @@ export function useOpenInApp(input: { session: MountedSession; path: () => strin | 193 | 193 |
| 194 | 194 | type OpenInAppState = ReturnType<typeof useOpenInApp> | 195 | 195 |
| | 196 | +export function OpenInAppMenuItem(props: { session: MountedSession }) { | | 197 | + const ctx = usePlugin() | | 198 | + | | 199 | + const state = useOpenInApp({ | | 200 | + get session() { | | 201 | + return props.session | | 202 | + }, | | 203 | + path: () => props.session.directory, | | 204 | + request: useShared().request, | | 205 | + }) | | 206 | + | | 207 | + return ( | | 208 | + <Show when={state.canOpen() && state.current().id !== "finder"}> | | 209 | + <Menu.Item disabled={state.opening()} onSelect={() => state.openPath(state.current().id)}> | | 210 | + <AppIcon id={state.current().icon} class="size-3.5 shrink-0" /> | | 211 | + {ctx.t("open.ariaLabel", { app: state.current().label })} | | 212 | + </Menu.Item> | | 213 | + </Show> | | 214 | + ) | | 215 | +} | | 216 | + | 196 | 217 | export default function OpenInAppButton(props: { session: MountedSession; screen: SessionScreen }) { | 197 | 218 | const ctx = usePlugin() | 198 | 219 | const directory = () => props.screen.file.root | |
|