Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 63 additions & 13 deletions packages/app/e2e/regression/tabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ test("option arrows move to the previous or next tab, and with shift to the next
await expectPath(page, sessionHref(c.id))
})

for (const navigation of ["horizontal", "vertical", "keyboard"] as const) {
for (const navigation of ["horizontal", "vertical", "keyboard", "numbered"] as const) {
test(`switching session tabs restores the caret and pastes into the destination draft (${navigation})`, async ({
page,
context,
Expand All @@ -525,22 +525,32 @@ for (const navigation of ["horizontal", "vertical", "keyboard"] as const) {
const tabB = strip.locator(`[data-titlebar-tab-link][href="${sessionHref(b.id)}"]`)
await editor.fill("Draft A")

await (navigation === "keyboard" ? page.keyboard.press("Control+Alt+ArrowRight") : tabB.click())
if (navigation === "keyboard") await page.keyboard.press("Control+Alt+ArrowRight")

if (navigation === "numbered") {
// A titlebar control stays mounted across sessions, so it still holds focus when the destination composer mounts.
const home = page.locator('[data-slot="titlebar-v2"]').getByRole("button", { name: "Home", exact: true })
await home.focus()
await expect(home).toBeFocused()
await page.keyboard.press("ControlOrMeta+2")
}

if (navigation === "horizontal" || navigation === "vertical") await tabB.click()
await expectPath(page, sessionHref(b.id))
await expect(editor).toBeFocused()
await page.evaluate(() => navigator.clipboard.writeText("Draft B"))
await page.keyboard.press("ControlOrMeta+V")
await expect(editor).toHaveText("Draft B")

await page.keyboard.press("Control+Alt+ArrowLeft")
await page.keyboard.press(navigation === "numbered" ? "ControlOrMeta+1" : "Control+Alt+ArrowLeft")
await expectPath(page, sessionHref(a.id))
await expect(editor).toBeFocused()
await expect(editor).toHaveText("Draft A")
await page.evaluate(() => navigator.clipboard.writeText(" appended"))
await page.keyboard.press("ControlOrMeta+V")
await expect(editor).toHaveText("Draft A appended")

await tabB.click()
await (navigation === "numbered" ? page.keyboard.press("ControlOrMeta+2") : tabB.click())
await expectPath(page, sessionHref(b.id))
await expect(editor).toBeFocused()
await expect(editor).toHaveText("Draft B")
Expand Down Expand Up @@ -814,7 +824,7 @@ test("Recent shows the last 7 days, and Show more reveals 30 more rows, fetching
await expect(more).toBeHidden()
})

test("Recent keeps the server's order from its last reload, which a run end or window focus triggers", async ({
test("Recent keeps the server's order through renames, run ends and window focus, and reloads for a new session", async ({
page,
}) => {
const t = Date.now() - 60_000
Expand All @@ -831,6 +841,11 @@ test("Recent keeps the server's order from its last reload, which a run end or w
},
})

let pageOneLoads = 0
page.on("request", (request) => {
if (/\/api\/session\?.*archived=false/.test(request.url())) pageOneLoads++
})
await page.clock.install()
await page.goto(
`/e2e/utils/windows-menu.html?${new URLSearchParams({ server: SERVER, path: sessionHref(a.id, "sidecar") })}`,
)
Expand Down Expand Up @@ -864,22 +879,57 @@ test("Recent keeps the server's order from its last reload, which a run end or w
await expect(rows.first()).toContainText("Tab B session")
await expect(rows.last()).toContainText("Renamed A session")

// The window coming back reloads the list, as the iOS app does when it returns to the foreground.
await page.evaluate(() => window.dispatchEvent(new Event("focus")))
await expect(rows).toHaveText([/Renamed A session/, /Tab B session/])

advance(b.id, { updated: t + 3, idle: t + 3 })
// A run end and the window coming back leave the order alone; the rename after the run end shows it arrived.
advance(a.id, { updated: t + 3, idle: t + 3 }, "Finished A session")
await workspace.push([
{
id: "evt_recent_order_run_end",
created: t + 3,
type: "session.execution.succeeded",
location: { directory: workspace.directory },
durable: { aggregateID: b.id, seq: 1, version: 1 },
data: { sessionID: b.id },
durable: { aggregateID: a.id, seq: 2, version: 1 },
data: { sessionID: a.id },
} satisfies Extract<OpenCodeEvent, { type: "session.execution.succeeded" }>,
{
id: "evt_recent_order_rename_after_run",
created: t + 3,
type: "session.renamed",
location: { directory: workspace.directory },
durable: { aggregateID: a.id, seq: 3, version: 1 },
data: { sessionID: a.id, title: "Finished A session" },
} satisfies Extract<OpenCodeEvent, { type: "session.renamed" }>,
])
await expect(rows).toHaveText([/Tab B session/, /Finished A session/])
await page.evaluate(() => {
window.dispatchEvent(new Event("focus"))
document.dispatchEvent(new Event("visibilitychange"))
})
// Past the reload debounce, so a reload either trigger had queued would have requested page one by now.
await page.clock.runFor(1_000)
await expect(rows).toHaveText([/Tab B session/, /Finished A session/])
expect(pageOneLoads).toBe(1)

// A new root session reloads page one, which brings in A's newer server time too.
const created = session({ id: "ses_tab_new", title: "Fresh session", directory: workspace.directory, created: t + 4 })
workspace.sessions.push(created)
await workspace.push([
{
id: "evt_recent_order_created",
created: t + 4,
type: "session.created",
location: { directory: workspace.directory },
durable: { aggregateID: created.id, seq: 1, version: 1 },
data: {
sessionID: created.id,
projectID: workspace.projectID,
location: { directory: workspace.directory },
slug: created.slug,
version: created.version,
},
} satisfies Extract<OpenCodeEvent, { type: "session.created" }>,
])
await expect(rows).toHaveText([/Tab B session/, /Renamed A session/])
await expect(rows).toHaveText([/Fresh session/, /Finished A session/, /Tab B session/])
expect(pageOneLoads).toBe(2)
})

test("an unfocused window preserves a restored manual unread reminder", async ({ page }) => {
Expand Down
32 changes: 31 additions & 1 deletion packages/app/src/components-lab/dialog-story-runtime.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IntegrationInfo } from "@opencode/client/promise"
import type { IntegrationInfo, PluginInfo } from "@opencode/client/promise"
import { QueryClient, QueryClientProvider } from "@tanstack/solid-query"
import type { ParentProps } from "solid-js"
import { LocalProvider } from "@/providers/models/selection"
Expand Down Expand Up @@ -503,6 +503,28 @@ type DialogStoryRuntimeOptions = {

const REDIRECT_PASTE = ["openai", "gitlab", "snowflake-cortex"]

/** Package plugins for the Plugins tab: two with a newer version, so its update controls show. */
const storyPlugins: PluginInfo[] = [
{
id: "wakatime",
source: { type: "package", target: "opencode-wakatime@latest", version: "1.2.0", outdated: true },
features: { server: true },
state: { status: "active" },
},
{
id: "notifier",
source: { type: "package", target: "opencode-notifier@latest", version: "0.4.1", outdated: true },
features: { server: true, tui: true },
state: { status: "active" },
},
{
id: "review",
source: { type: "package", target: "@acme/opencode-review@latest", version: "2.0.3" },
features: { server: true },
state: { status: "active" },
},
]

export function createStoryFetch(overrides: IntegrationInfo[] = []): typeof fetch {
const integrations = [
...overrides,
Expand Down Expand Up @@ -715,6 +737,14 @@ export function createStoryFetch(overrides: IntegrationInfo[] = []): typeof fetc

if (pathname === "/api/session/active") return jsonResponse({ data: {} })

if (pathname === "/api/plugin") return jsonResponse({ location, data: storyPlugins, ready: true })

if (pathname === "/api/plugin/check") return jsonResponse({ location, data: storyPlugins })

// Long enough to see Updating; the list keeps its flags, as a server whose check has not caught up would.
if (pathname === "/api/plugin/update")
return new Promise<Response>((resolve) => setTimeout(() => resolve(noContentResponse()), 1500))

if (pathname === "/api/config" || pathname === "/api/config/shell") return jsonResponse([])

if (pathname === "/api/mcp/resource") return jsonResponse({ location, data: { resources: [], templates: [] } })
Expand Down
5 changes: 5 additions & 0 deletions packages/app/src/runtime/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,11 @@ export const dict = {
"sidebar.view.markAllRead": "Mark all as read",
"sidebar.view.noMatch": "No other sessions match",
"settings.plugins.reload": "Reload",
"settings.plugins.check": "Check for updates",
"settings.plugins.checking": "Checking for updates",
"settings.plugins.update": "Update",
"settings.plugins.updating": "Updating",
"settings.plugins.update.label": "Update {{name}}",
"settings.plugins.status.loading": "Loading",
"settings.plugins.status.failed": "Failed",
"settings.plugins.error.notFound": "Plugin not found",
Expand Down
61 changes: 56 additions & 5 deletions packages/app/src/runtime/plugin/extension-plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ import { useLanguage } from "@/runtime/i18n/language"
import { usePlatform } from "@/runtime/platform/platform"
import { SettingsList } from "@/settings/list"
import { showToast } from "@/shell/notifications/toast"
import type { PluginUpdateView } from "@/settings/providers/plugin-update-machine"
import "@/settings/settings.css"
import { builtins } from "./builtins"
import { usePluginHost } from "./host"
import { useReservedPlugins } from "./root"

/** Update controls for the listed plugins' packages; without them the rows offer no update. */
export type ExtensionPluginUpdates = {
readonly view: (source: Extract<PluginInfo["source"], { type: "package" }>) => PluginUpdateView
readonly update: (target: string) => void
}

/**
* The plugins a server lists, for the Plugins tab of Extensions. Only the desktop app's own server (`own`) runs its
* plugins' GUIs in this window, so only its rows add the window's controls; other servers and the web list names.
* Any server's package plugins can be updated.
*/
export function ExtensionPlugins(props: { plugins: readonly PluginInfo[]; own: boolean }) {
export function ExtensionPlugins(props: {
plugins: readonly PluginInfo[]
own: boolean
updates?: ExtensionPluginUpdates
}) {
const listed = () => props.plugins.filter((plugin) => plugin.source.type !== "builtin")

return (
Expand All @@ -34,13 +46,14 @@ export function ExtensionPlugins(props: { plugins: readonly PluginInfo[]; own: b
<Icon name="cube" class="text-v2-icon-icon-muted shrink-0" />
<span class="settings-extension-name truncate">{pluginLabel(plugin)}</span>
</div>
<PluginUpdateButton plugin={plugin} updates={props.updates} />
</div>
)}
</For>
</SettingsList>
}
>
<OwnServerPlugins plugins={listed()} />
<OwnServerPlugins plugins={listed()} updates={props.updates} />
</Show>
)
}
Expand All @@ -50,7 +63,7 @@ export function ExtensionPlugins(props: { plugins: readonly PluginInfo[]; own: b
* switch that turns off only the desktop UI, Reload, status and errors, and rows for plugins main lists that the
* server list does not name. Built-ins always run and stay hidden unless they failed, which only this list reports.
*/
function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
function OwnServerPlugins(props: { plugins: readonly PluginInfo[]; updates?: ExtensionPluginUpdates }) {
const language = useLanguage()
const host = usePluginHost()
const bridge = usePlatform().plugins
Expand Down Expand Up @@ -136,7 +149,7 @@ function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
run(bridge?.manager.reload(id))
}

const row = (input: { id: string | undefined; name: string; builtin?: boolean }) => {
const row = (input: { id: string | undefined; name: string; builtin?: boolean; plugin?: PluginInfo }) => {
const state = () => (input.builtin ? "loaded" : kind(input.id))
const part = input.builtin ? "builtin" : "config"
const live = () => (state() === "loaded" ? input.id : undefined)
Expand Down Expand Up @@ -184,9 +197,15 @@ function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
</Show>
</div>
</div>
<Show when={!live() && input.plugin}>
{(plugin) => <PluginUpdateButton plugin={plugin()} updates={props.updates} />}
</Show>
<Show when={live()}>
{(id) => (
<div class="settings-servers-actions">
<Show when={input.plugin}>
{(plugin) => <PluginUpdateButton plugin={plugin()} updates={props.updates} />}
</Show>
<Button size="small" variant="ghost" onClick={() => reload(id())}>
{language.t("settings.plugins.reload")}
</Button>
Expand All @@ -206,7 +225,7 @@ function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
return (
<>
<SettingsList variant="catalog">
<For each={props.plugins}>{(plugin) => row({ id: plugin.id, name: pluginLabel(plugin) })}</For>
<For each={props.plugins}>{(plugin) => row({ id: plugin.id, name: pluginLabel(plugin), plugin })}</For>
<For each={unnamed()}>{(id) => row({ id, name: id })}</For>
<For each={failedBuiltins()}>{(id) => row({ id, name: id, builtin: true })}</For>
</SettingsList>
Expand All @@ -217,6 +236,38 @@ function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
)
}

/** Update for a package plugin with a newer version, or the update in progress; nothing otherwise. */
function PluginUpdateButton(props: { plugin: PluginInfo; updates?: ExtensionPluginUpdates }) {
const language = useLanguage()

const view = createMemo(() => {
const source = props.plugin.source

if (source.type !== "package" || !props.updates) return undefined

const current = props.updates.view(source)

return current.outdated || current.updating ? { ...current, target: source.target } : undefined
})

return (
<Show when={view()}>
{(current) => (
<Button
size="small"
variant="ghost"
disabled={current().updating}
aria-busy={current().updating}
aria-label={language.t("settings.plugins.update.label", { name: pluginLabel(props.plugin) })}
onClick={() => props.updates?.update(current().target)}
>
{language.t(current().updating ? "settings.plugins.updating" : "settings.plugins.update")}
</Button>
)}
</Show>
)
}

/** A plugin's error: its first line, the message, with the rest (such as a stack trace) behind a toggle. */
function PluginError(props: { error: string }) {
const language = useLanguage()
Expand Down
Loading
Loading