From 196a5ee9226508da4d698e9af980505f0be96aa5 Mon Sep 17 00:00:00 2001
From: Dax
Date: Thu, 12 Nov 2026 08:54:05 -0500
Subject: [PATCH 01/13] chore: only require code owner review for .github
(#63543)
---
.github/CODEOWNERS | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index ae0205d60da1..a3f533d5cb31 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -1,11 +1,3 @@
-# web + desktop packages
-packages/app/ @Hona @Brendonovich
-packages/desktop/ @Hona @Brendonovich
-
-# GUI plugin SDK
-# changes here must be meticulous - pls chat first :)
-packages/plugin/src/gui/ @Hona
-
# CI and releases. Release jobs that hold secrets run only .github/workflows/release.yml and .github/release/,
-# which makes this path the release security boundary.
+# which makes this path the release security boundary. It is the only path that needs a code owner review.
/.github/ @thdxr
From 98def2f90e8596d0734929b9273defe33f74ba74 Mon Sep 17 00:00:00 2001
From: James Long
Date: Thu, 12 Nov 2026 08:08:25 -0600
Subject: [PATCH 02/13] test(app): update e2e specs for always-background
subagents (#63538)
---
.../e2e/regression/timeline-geometry.spec.ts | 10 +-
.../e2e/regression/timeline-stream.spec.ts | 217 +++++++-----------
2 files changed, 89 insertions(+), 138 deletions(-)
diff --git a/packages/app/e2e/regression/timeline-geometry.spec.ts b/packages/app/e2e/regression/timeline-geometry.spec.ts
index 4e19574c8ec2..cbc41f76b774 100644
--- a/packages/app/e2e/regression/timeline-geometry.spec.ts
+++ b/packages/app/e2e/regression/timeline-geometry.spec.ts
@@ -767,16 +767,16 @@ async function scrollsBehindComposerRegion(
content: [
{
type: "tool",
- id: "call_running_subagent",
- name: "subagent",
+ id: "call_blocking_shell",
+ name: "shell",
state: {
status: "running",
- input: { description: "Trace frame budget", agent: "explore" },
- metadata: { sessionID: "ses_running_subagent" },
+ input: { command: "bun test" },
+ metadata: {},
},
time: { created: 2 },
},
- { type: "text", id: "prt_timeline_end", text: "The last answer ends above the composer region." },
+ { type: "text", text: "The last answer ends above the composer region." },
],
time: { created: 2 },
},
diff --git a/packages/app/e2e/regression/timeline-stream.spec.ts b/packages/app/e2e/regression/timeline-stream.spec.ts
index fa7e6cc4108b..38b128fb4309 100644
--- a/packages/app/e2e/regression/timeline-stream.spec.ts
+++ b/packages/app/e2e/regression/timeline-stream.spec.ts
@@ -705,45 +705,6 @@ test("holds undelivered input still while live status above it comes and goes",
await expect.poll(lane).toBe(36)
})
-test("jumps from a finished shell's notice to its call", async ({ page }) => {
- await setupTimeline(page, {
- settings: { timelineDetail: detailed },
- sessionMessages: [
- userMessage(),
- assistantMessage([
- ...searches(0, 2),
- toolPart(
- "prt_notice_shell",
- "shell",
- "completed",
- { command: "bun serve.ts" },
- { output: "listening", metadata: { shellID: "shell_notice" } },
- ),
- ...searches(2, 2),
- textPart("prt_notice_notes", notes("Later", 80)),
- ]),
- {
- id: "msg_shell_finished",
- type: "synthetic",
- text: '\nlistening\n',
- description: "bun serve.ts",
- metadata: { source: "shell", shellID: "shell_notice", state: "completed" },
- time: { created: 1700000003000 },
- },
- ],
- })
-
- const notice = page.getByRole("button", { name: /^Shell finished/ })
- const shellTrigger = page.locator('[data-timeline-part-id="prt_notice_shell"] [data-slot="collapsible-trigger"]')
-
- await expect(notice).toBeInViewport()
- await expect(shellTrigger).toHaveCount(0)
- await notice.click()
-
- await expect(shellTrigger).toHaveAttribute("aria-expanded", "true")
- await expect(shellTrigger).toBeInViewport()
-})
-
test.describe("Working", () => {
test("shows Working between busy and reasoning states", async ({ page }) => {
const timeline = await setupTimeline(page, {
@@ -1039,7 +1000,7 @@ test("grows a streaming row without a ResizeObserver loop error", async ({ page
expect(await page.evaluate(() => document.documentElement.dataset.resizeObserverLoops)).toBeUndefined()
})
-test.describe("background shortcut", () => {
+test.describe("background work", () => {
test("does not offer a running subagent to the background", async ({ page }) => {
await setupTimeline(page, {
settings: { timelineDetail: { ...detailed, subagents: { placement: "separate" } } },
@@ -1177,7 +1138,7 @@ test.describe("background shortcut", () => {
}) => {
const childID = "ses_background_stale_call"
- // As after a lost completion notice: the call still reads running, while the child session has finished.
+ // The call records the launch; the child can finish without changing that metadata.
const timeline = await setupTimeline(page, {
settings: { timelineDetail: detailed },
sessionMessages: [
@@ -1194,7 +1155,7 @@ test.describe("background shortcut", () => {
name: "subagent",
state: {
status: "completed",
- input: { description: "Stale task", agent: "explore", background: true },
+ input: { description: "Stale task", agent: "explore" },
content: [{ type: "text", text: "working" }],
metadata: { sessionID: childID, status: "running" },
},
@@ -1209,7 +1170,9 @@ test.describe("background shortcut", () => {
const capsule = page.locator('[data-slot="session-activity-chip"]')
- await expect(page.locator('[data-timeline-part-id="call_stale"]')).toContainText("Stale task (background)")
+ await expect(
+ page.locator('[data-timeline-part-id="call_stale"]').getByText("Stale task", { exact: true }),
+ ).toBeVisible()
await expect(capsule).toHaveCount(0)
await timeline.transport.send(status("busy", 1, childID))
await expect(page.getByRole("button", { name: "1 subagent", exact: true })).toBeVisible()
@@ -1217,9 +1180,8 @@ test.describe("background shortcut", () => {
await expect(capsule).toHaveCount(0)
})
- test("separates blocking and already-backgrounded work into two rows", async ({ page }) => {
+ test("shows the shortcut for a blocking shell and lists background work in the capsule", async ({ page }) => {
const backgroundID = "ses_background_existing"
- const blockingID = "ses_background_blocking"
const timeline = await setupTimeline(page, {
settings: { timelineDetail: detailed },
@@ -1233,25 +1195,25 @@ test.describe("background shortcut", () => {
content: [
{
type: "tool",
- id: "call_backgrounded",
- name: "subagent",
+ id: "call_shell_backgrounded",
+ name: "shell",
state: {
status: "completed",
- input: { description: "Background task", agent: "explore" },
+ input: { command: "sleep 120" },
content: [{ type: "text", text: "working" }],
- metadata: { sessionID: backgroundID, status: "running" },
+ metadata: { shellID: "shell_backgrounded", status: "running" },
},
time: { created: 2, completed: 3 },
},
{
type: "tool",
- id: "call_shell_backgrounded",
- name: "shell",
+ id: "call_backgrounded",
+ name: "subagent",
state: {
status: "completed",
- input: { command: "sleep 120" },
+ input: { description: "Background task", agent: "explore" },
content: [{ type: "text", text: "working" }],
- metadata: { shellID: "shell_backgrounded", status: "running" },
+ metadata: { sessionID: backgroundID, status: "running" },
},
time: { created: 2, completed: 3 },
},
@@ -1267,12 +1229,8 @@ test.describe("background shortcut", () => {
{
type: "tool",
id: "call_blocking",
- name: "subagent",
- state: {
- status: "running",
- input: { description: "Foreground task", agent: "build" },
- metadata: { sessionID: blockingID },
- },
+ name: "shell",
+ state: { status: "running", input: { command: "sleep 10" }, metadata: { shellID: "shell_blocking" } },
time: { created: 4 },
},
],
@@ -1282,39 +1240,28 @@ test.describe("background shortcut", () => {
sessions: [
session(),
session({ id: backgroundID, parentID: sessionID, title: "Background task", agent: "explore" }),
- session({ id: blockingID, parentID: sessionID, title: "Foreground task", agent: "build" }),
],
sessionStatus: {
[sessionID]: { type: "busy" },
[backgroundID]: { type: "busy" },
- [blockingID]: { type: "busy" },
},
+ shellCommands: [
+ { id: "shell_backgrounded", command: "sleep 120" },
+ { id: "shell_blocking", command: "sleep 10" },
+ ].map((shell) => ({
+ ...shell,
+ status: "running" as const,
+ cwd: directory,
+ shell: "bash",
+ file: `/tmp/${shell.id}.out`,
+ metadata: { sessionID },
+ time: { started: 2 },
+ })),
})
- await timeline.transport.send({
- id: "evt_background_shell_created",
- created: 3,
- type: "shell.created",
- location: { directory },
- data: {
- info: {
- id: "shell_backgrounded",
- status: "running",
- command: "sleep 120",
- cwd: directory,
- shell: "bash",
- file: "/tmp/background.out",
- metadata: { sessionID },
- time: { started: 2 },
- },
- },
- })
const backgroundCard = page.locator('[data-timeline-part-id="call_backgrounded"]')
- const blockingCard = page.locator('[data-timeline-part-id="call_blocking"]')
await expect(backgroundHint(page)).toBeVisible()
- await expect(backgroundCard).toContainText("Background task (background)")
- await expect(blockingCard).toContainText("Foreground task")
- await expect(blockingCard).not.toContainText("(background)")
+ await expect(backgroundCard).toContainText("Background task")
const used = page
.locator('[data-timeline-part-ids="call_shell_backgrounded"]')
@@ -1322,18 +1269,18 @@ test.describe("background shortcut", () => {
await expect(used).toHaveText(/^Used\s*1\s*Shell$/)
await expect(used).toHaveAttribute("aria-expanded", "false")
- const activity = page.getByRole("button", { name: "2 subagents · 1 shell", exact: true })
- const list = page.getByRole("menu", { name: "2 subagents · 1 shell", exact: true })
+ const summary = "1 subagent · 1 shell"
+ const list = page.getByRole("menu", { name: summary, exact: true })
// The open menu hides the rest of the page from the accessibility tree, the capsule included.
- const capsule = page.getByRole("button", { name: "2 subagents · 1 shell", exact: true, includeHidden: true })
- const label = capsule.getByText("2 subagents · 1 shell", { exact: true })
+ const capsule = page.getByRole("button", { name: summary, exact: true, includeHidden: true })
+ const label = capsule.getByText(summary, { exact: true })
const glyph = await capsule.locator('[data-component="session-progress-indicator-v2"]').boundingBox()
const text = await label.boundingBox()
const inset = glyph!.x - (await capsule.boundingBox())!.x
- await activity.click()
+ await capsule.click()
await expect(list.locator('[data-slot="menu-v2-group-label"], [data-slot="menu-v2-separator"]')).toHaveCount(0)
- await expect(list.getByText("2 subagents · 1 shell", { exact: true })).toHaveCount(0)
+ await expect(list.getByText(summary, { exact: true })).toHaveCount(0)
await expect(label).toBeVisible()
// The panel opens above the capsule on its grid: row glyphs on the capsule's glyph, names and commands on its
@@ -1357,7 +1304,7 @@ test.describe("background shortcut", () => {
return (
panel!.y + panel!.height <= anchor!.y &&
- rows.length === 3 &&
+ rows.length === 2 &&
rows.every(
([left, start, end]) =>
Math.abs(left - glyph!.x) < 0.5 &&
@@ -1369,7 +1316,6 @@ test.describe("background shortcut", () => {
.toBe(true)
await expect(list.getByRole("menuitem")).toHaveText([
// The fixture starts every task near the epoch, so each row ends with an hours-long run time.
- /^Build\s*Foreground task\d+h \d{2}m$/,
/^Explore\s*Background task\d+h \d{2}m$/,
/^sleep 120\d+h \d{2}m$/,
])
@@ -1381,13 +1327,13 @@ test.describe("background shortcut", () => {
const interrupt = page.waitForRequest(
(request) =>
- request.method() === "POST" && new URL(request.url()).pathname === `/api/session/${blockingID}/interrupt`,
+ request.method() === "POST" && new URL(request.url()).pathname === `/api/session/${backgroundID}/interrupt`,
)
- const foreground = list.getByRole("menuitem", { name: /Foreground task/ })
+ const subagent = list.getByRole("menuitem", { name: /Background task/ })
- await foreground.hover()
- await foreground.getByRole("button", { name: "Interrupt subagent", exact: true }).click()
+ await subagent.hover()
+ await subagent.getByRole("button", { name: "Interrupt subagent", exact: true }).click()
await interrupt
await expect(list).toBeVisible()
@@ -1410,50 +1356,56 @@ test.describe("background shortcut", () => {
expect(kill.requests).toHaveLength(1)
await page.keyboard.press("Escape")
await expect(list).toHaveCount(0)
- await expect(backgroundCard).toContainText("Background task (background)")
await expect(backgroundCard.locator('[data-component="session-progress-indicator-v2"]')).toBeVisible()
await used.click()
await expect(
page.locator('[data-timeline-part-id="call_shell_backgrounded"] [data-component="text-shimmer"]'),
).toHaveAttribute("data-active", "true")
- // SAFETY: the transport forwards this payload unchanged, and the client marks a session idle from
- // `type` and `data.sessionID` alone; the child session's event needs no durable metadata here.
- await timeline.transport.send({
- id: "evt_background_succeeded",
- created: Date.now(),
- type: "session.execution.succeeded",
- data: { sessionID: backgroundID },
- } as never)
+ await timeline.send(status("idle", 1, backgroundID))
await expect(backgroundCard.locator('[data-component="session-progress-indicator-v2"]')).toHaveCount(0)
- await expect(backgroundCard).toContainText("Background task (background)")
+ await expect(backgroundCard).toContainText("Background task")
})
for (const fixture of [
{ name: "from far below", before: 40, searches: 40, after: 80 },
// The collapsed timeline fits the viewport, so it only becomes scrollable once the group opens.
- { name: "that opens the last row", before: 0, searches: 40, after: 0 },
+ { name: "in an initially unscrollable timeline", before: 0, searches: 40, after: 0 },
// Reaching the shell lands on the end of the timeline, which would otherwise follow new content again.
{ name: "at the end of the timeline", before: 40, searches: 0, after: 0 },
]) {
- // A starting subagent call is the pill's row that reveals its call; grouping subagents puts it inside the group.
- test(`holds a revealed call ${fixture.name} just under its stuck group header`, async ({ page }) => {
+ test(`holds the call revealed by a shell notice ${fixture.name} just under its stuck group header`, async ({
+ page,
+ }) => {
const timeline = await setupTimeline(page, {
- settings: { timelineDetail: { ...detailed, subagents: { placement: "grouped" } } },
- sessionStatus: { [sessionID]: { type: "busy" } },
- messages: [
+ settings: { timelineDetail: detailed },
+ sessionMessages: [
userMessage(),
- assistantMessage(
- [
- ...(fixture.before ? [textPart("prt_earlier", notes("Earlier", fixture.before))] : []),
- ...searches(0, 42 - fixture.searches),
- toolPart("prt_far_call", "subagent", "running", { description: "Map the far code", agent: "explore" }),
- // The open group outgrows the viewport, so aligning the group instead of the call misses it.
- ...searches(42 - fixture.searches, fixture.searches),
- ...(fixture.after ? [textPart("prt_follow_up", notes("Follow-up", fixture.after))] : []),
- ],
- { completed: false },
- ),
+ assistantMessage([
+ ...(fixture.before ? [textPart("prt_earlier", notes("Earlier", fixture.before))] : []),
+ ...searches(0, 42 - fixture.searches),
+ toolPart(
+ "prt_far_call",
+ "shell",
+ "completed",
+ { command: "bun serve.ts" },
+ {
+ output: "listening",
+ metadata: { shellID: "shell_notice", status: "running" },
+ },
+ ),
+ // The open group outgrows the viewport, so aligning the group instead of the call misses it.
+ ...searches(42 - fixture.searches, fixture.searches),
+ ...(fixture.after ? [textPart("prt_follow_up", notes("Follow-up", fixture.after))] : []),
+ ]),
+ {
+ id: "msg_1002_shell_finished",
+ type: "synthetic",
+ text: '\nlistening\n',
+ description: "bun serve.ts",
+ metadata: { source: "shell", shellID: "shell_notice", state: "completed" },
+ time: { created: 1700000003000 },
+ },
],
})
@@ -1472,26 +1424,25 @@ test.describe("background shortcut", () => {
})
.toBe(0)
- await expect(
- fixture.after ? page.getByText(`Follow-up note ${fixture.after}.`, { exact: true }) : group,
- ).toBeInViewport()
+ const notice = page.getByRole("button", { name: /^Shell finished/ })
+ await expect(notice).toBeInViewport()
await expect(call).toHaveCount(0)
- await page.getByRole("button", { name: "1 subagent", exact: true }).click()
- await page
- .getByRole("menu", { name: "1 subagent", exact: true })
- .getByRole("menuitem", { name: /Map the far code/ })
- .click()
+ await notice.click()
await expect(group).toHaveAttribute("aria-expanded", "true")
- await expect(call).toBeInViewport()
+ const trigger = call.locator('[data-slot="collapsible-trigger"]')
+ await expect(trigger).toHaveAttribute("aria-expanded", "true")
+ await expect(trigger).toBeInViewport()
// A call at the very end cannot rise under the header until more content arrives below it.
if (fixture.searches) await aligned()
// Nothing covers the row, so it takes the next click.
- await call.click({ trial: true })
+ await trigger.click({ trial: true })
// The agent keeps writing below the call; the call stays where it was revealed.
- await timeline.send(partUpdated(textPart("prt_late", notes("Late", 30))))
+ const late = assistantMessage([], { id: "msg_1003_late", completed: false, created: 1700000004000 })
+ await timeline.send(stepStarted(late))
+ await timeline.send(partUpdated({ id: "prt_late", messageID: late.id, type: "text", text: notes("Late", 30) }))
await expect(page.getByText("Late note 30.", { exact: true })).toBeAttached()
await aligned()
})
From 1c53e40a7fafc417a1aef03b8569f176c062e30d Mon Sep 17 00:00:00 2001
From: usrnk1 <7547651+usrnk1@users.noreply.github.com>
Date: Thu, 12 Nov 2026 15:37:30 +0100
Subject: [PATCH 03/13] feat(app): choose each server's terminal shell from its
menu (#63539)
---
.../app/src/servers/registry/row-menu.tsx | 53 ++++++++++++++++++-
packages/app/src/settings/general/general.tsx | 8 +--
packages/app/src/settings/servers/servers.tsx | 38 ++++++++-----
3 files changed, 80 insertions(+), 19 deletions(-)
diff --git a/packages/app/src/servers/registry/row-menu.tsx b/packages/app/src/servers/registry/row-menu.tsx
index e8b01f57d4bd..99df529f9f68 100644
--- a/packages/app/src/servers/registry/row-menu.tsx
+++ b/packages/app/src/servers/registry/row-menu.tsx
@@ -1,15 +1,19 @@
import { Icon } from "@opencode/ui/icon"
import { IconButton } from "@opencode/ui/icon-button"
import { Menu } from "@opencode/ui/menu"
-import { type Component, Show } from "solid-js"
+import { type Component, createMemo, For, Show } from "solid-js"
import type { ServerActionsController } from "@/servers/registry/controller"
import { useLanguage } from "@/runtime/i18n/language"
import { ServerConnection } from "@/runtime/server/registry"
+import { createShellOptions } from "@/settings/general/behavior"
+import type { ShellSettingsController } from "@/settings/general/controllers"
export const ServerRowMenu: Component<{
server: ServerConnection.Any
domain: ServerActionsController
onEdit: (server: ServerConnection.Http) => void
+ shell?: ShellSettingsController
+ action?: string
open?: boolean
onOpenChange?: (open: boolean) => void
}> = (props) => {
@@ -23,6 +27,8 @@ export const ServerRowMenu: Component<{
canRemove={props.domain.connection.canRemove(key)}
canHide={props.domain.connection.canHide(key)}
hidden={props.domain.connection.isHidden(key)}
+ shell={props.shell}
+ action={props.action}
onEdit={props.onEdit}
onRemove={() => props.domain.connection.remove(key)}
onHide={() => props.domain.connection.setHidden(key, true)}
@@ -41,6 +47,9 @@ export function serverMenuLabels(language: ReturnType) {
remove: language.t("dialog.server.menu.remove"),
hide: language.t("dialog.server.menu.hide"),
show: language.t("dialog.server.menu.show"),
+ shell: language.t("settings.general.row.shell.title"),
+ shellAuto: language.t("settings.general.row.shell.autoDefault"),
+ shellTerminalOnly: language.t("settings.general.row.shell.terminalOnly"),
}
}
@@ -50,6 +59,8 @@ export const ServerRowMenuView: Component<{
canRemove: boolean
canHide?: boolean
hidden?: boolean
+ shell?: ShellSettingsController
+ action?: string
onEdit: (server: ServerConnection.Http) => void
onRemove: () => void
onHide?: () => void
@@ -68,6 +79,7 @@ export const ServerRowMenuView: Component<{
size="small"
icon={}
aria-label={props.labels.more}
+ data-action={props.action}
/>
@@ -83,6 +95,7 @@ export const ServerRowMenuView: Component<{
>
{props.labels.edit}
+ {(shell) => }
{props.labels.show}
@@ -99,3 +112,41 @@ export const ServerRowMenuView: Component<{
)
}
+
+function ShellSubmenu(props: { shell: ShellSettingsController; labels: ReturnType }) {
+ const options = createMemo(() =>
+ createShellOptions({ shells: props.shell.shells(), current: props.shell.current() }),
+ )
+
+ const current = () => options().find((option) => option.value === props.shell.current())?.id ?? "auto"
+
+ return (
+
+ {props.labels.shell}
+
+
+ {
+ const option = options().find((item) => item.id === id)
+
+ if (option) props.shell.select(option.value)
+ }}
+ >
+
+ {(option) => (
+
+ {option.id === "auto"
+ ? props.labels.shellAuto
+ : option.terminalOnly
+ ? `${option.name} (${props.labels.shellTerminalOnly})`
+ : option.name}
+
+ )}
+
+
+
+
+
+ )
+}
diff --git a/packages/app/src/settings/general/general.tsx b/packages/app/src/settings/general/general.tsx
index e5b72a2ea81d..d0631eeca24d 100644
--- a/packages/app/src/settings/general/general.tsx
+++ b/packages/app/src/settings/general/general.tsx
@@ -69,11 +69,7 @@ const WorkspaceDestinationSetting: Component = () => {
)
}
-export const ShellSetting: Component<{
- controller: ShellSettingsController
- /** Search reveals the row with the default action; the Servers page names the other servers' rows apart. */
- action?: string
-}> = (props) => {
+export const ShellSetting: Component<{ controller: ShellSettingsController }> = (props) => {
const language = useLanguage()
const options = createMemo(() =>
@@ -89,7 +85,7 @@ export const ShellSetting: Component<{
description={language.t("settings.general.row.shell.description")}
>
}>
- form.dispatch({ type: "scan.cancelled" })}
+ form.dispatch({ type: "scan.cancelled" })}
onScan={(link) => form.dispatch({ type: "scan.completed", link })}
/>
@@ -233,3 +223,31 @@ export const DialogServer: Component<{
)
}
+
+function createRegistryForm(dialog: DialogLifecycle, edited: ServerConnection.Http | undefined) {
+ const servers = useServers()
+ const global = useGlobal()
+ const tabs = useTabs()
+
+ const originalOf = (server: ServerConnection.Http): ServerOriginal => ({
+ url: server.http.url,
+ displayName: server.displayName,
+ password: server.http.password,
+ unauthorized: isServerUnauthorized(global.servers.health[ServerConnection.key(server)]),
+ })
+
+ const original = createMemo(() => {
+ const server = servers.list.find(
+ (item): item is ServerConnection.Http => item.type === "http" && item.http.url === edited?.http.url,
+ )
+
+ return server && originalOf(server)
+ })
+
+ return createServerConnectController({
+ ...dialog,
+ target: edited ? { kind: "edit", original: untrack(original) ?? originalOf(edited) } : { kind: "add" },
+ original,
+ removeTabs: (key) => tabs.removeServer(key),
+ })
+}
diff --git a/packages/app/src/servers/connect/redeem.ts b/packages/app/src/servers/connect/redeem.ts
index b6ab401a0b22..bfd449423d21 100644
--- a/packages/app/src/servers/connect/redeem.ts
+++ b/packages/app/src/servers/connect/redeem.ts
@@ -1,5 +1,4 @@
import { useLanguage } from "@/runtime/i18n/language"
-import { usePlatform } from "@/runtime/platform/platform"
import { isMixedContent } from "./browser"
import { legacyPairingLink, pairingLink, redeemPairingLink, type Pairing } from "./pairing"
@@ -14,9 +13,8 @@ type Redeemed = { code?: string; pairing?: Pairing }
// Pasted and scanned links share one redeem path so every surface explains a failure the same way.
// Each form keeps the last token it redeemed: the code is spent, so a retry after a failed connection check reuses it,
// whichever form the link takes (a scanned QR payload, or the link the scanner then shows).
-export function useRedeemPairing(): RedeemPairing {
+export function useRedeemPairing(exchange: typeof redeemPairingLink, pageHref?: string): RedeemPairing {
const language = useLanguage()
- const platform = usePlatform()
const last: Redeemed = {}
return async (value) => {
@@ -32,7 +30,7 @@ export function useRedeemPairing(): RedeemPairing {
return { pairing: { url, password: last.pairing.password } }
}
- const result = await redeemPairingLink(link)
+ const result = await exchange(link)
if (result.type === "paired") {
last.code = link.code
@@ -44,7 +42,7 @@ export function useRedeemPairing(): RedeemPairing {
if (result.type === "expired") return { error: language.t("server.connect.link.expired") }
// A QR code can carry several addresses; the HTTPS page can reach none of them only when every one is plain HTTP.
- if (platform.platform === "web" && link.urls.every((url) => isMixedContent(location.href, url)))
+ if (pageHref && link.urls.every((url) => isMixedContent(pageHref, url)))
return { error: language.t("server.connect.mixedContent") }
return { error: language.t("server.connect.link.unreachable", { url: link.urls.join(", ") }) }
diff --git a/packages/app/src/servers/connect/scanner.tsx b/packages/app/src/servers/connect/scanner.tsx
index b5c9eb391026..42270042f2d6 100644
--- a/packages/app/src/servers/connect/scanner.tsx
+++ b/packages/app/src/servers/connect/scanner.tsx
@@ -16,7 +16,12 @@ import "./scanner.css"
// Redeems with the form's own redeem, so the form keeps the token and a failed connection check retries without the
// spent code; the form gets back a link it can show, and fills it in.
-export function PairingScanner(props: { redeem: RedeemPairing; onScan: (link: string) => void; onCancel: () => void }) {
+export function PairingScanner(props: {
+ redeem: RedeemPairing
+ onScan: (link: string) => void
+ onCancel: () => void
+ camera?: typeof createCamera
+}) {
const language = useLanguage()
const [scannerState, setScannerState] = createSignal(createScannerState())
const view = createMemo(() => selectScannerView(scannerState()))
@@ -103,21 +108,12 @@ export function PairingScanner(props: { redeem: RedeemPairing; onScan: (link: st
}
// QrScanner hides detached videos, so initialize only after this preview is mounted.
- const scanner = new QrScanner(video, (result) => dispatch({ type: "code.detected", data: result.data }), {
- preferredCamera: "environment",
- maxScansPerSecond: 10,
- returnDetailedScanResult: true,
- // QrScanner only logs a decoder that fails (for example, a worker the page may not start), so the preview
- // would look like it is still scanning.
- onDecodeError: (error) => {
- // The native BarcodeDetector engine reports an empty frame as "Scanner error: No QR code found".
- if (String(error).includes(QrScanner.NO_QR_CODE_FOUND)) return
- dispatch({ type: "decode.failed" })
- },
- })
+ const scanner = (props.camera ?? createCamera)(
+ video,
+ (data) => dispatch({ type: "code.detected", data }),
+ () => dispatch({ type: "decode.failed" }),
+ )
- // Terminal QR codes can be light-on-dark depending on the terminal theme.
- scanner.setInversionMode("both")
onCleanup(() => {
dispatch({ type: "disposed" })
scanner.destroy()
@@ -154,3 +150,24 @@ export function PairingScanner(props: { redeem: RedeemPairing; onScan: (link: st
)
}
+
+function createCamera(
+ video: HTMLVideoElement,
+ detect: (data: string) => void,
+ failed: () => void,
+): Pick {
+ const scanner = new QrScanner(video, (result) => detect(result.data), {
+ preferredCamera: "environment",
+ maxScansPerSecond: 10,
+ returnDetailedScanResult: true,
+ onDecodeError: (error) => {
+ // The native BarcodeDetector engine reports an empty frame as "Scanner error: No QR code found".
+ if (!String(error).includes(QrScanner.NO_QR_CODE_FOUND)) failed()
+ },
+ })
+
+ // Terminal QR codes can be light-on-dark depending on the terminal theme.
+ scanner.setInversionMode("both")
+
+ return scanner
+}
diff --git a/packages/gui-plugins/src/ssh/dialog.stories.tsx b/packages/gui-plugins/src/ssh/dialog.stories.tsx
index abff7f3f3e92..376efa99532f 100644
--- a/packages/gui-plugins/src/ssh/dialog.stories.tsx
+++ b/packages/gui-plugins/src/ssh/dialog.stories.tsx
@@ -18,19 +18,36 @@ import {
type SshState,
} from "../../../stories/mocks/gui-plugins/ssh"
-type FixtureState = { item?: SshItem; before?: SshItem; step: number; timer?: ReturnType }
+const challenges = {
+ trust: {
+ id: "host-key",
+ text: "The authenticity of host 'dev.example.com' can't be established.\nED25519 key fingerprint is SHA256:EXAMPLE-FINGERPRINT-FOR-STORY-ONLY.\nAre you sure you want to continue connecting?",
+ confirm: true,
+ },
+ passphrase: { id: "passphrase", text: "Enter passphrase for key '~/.ssh/id_ed25519':", confirm: false },
+ password: { id: "password", text: "brendon@dev.example.com's password:", confirm: false },
+ otp: { id: "otp", text: "Verification code:", confirm: false },
+}
+
+type FixtureState = {
+ item?: SshItem
+ before?: SshItem
+ prompts: (keyof typeof challenges)[]
+ timer?: ReturnType
+}
function Fixture(props: {
session?: boolean
settings?: boolean
- incompatible?: boolean
- keyOnly?: boolean
+ incompatible?: true | "failed-update" | "version-mismatch"
+ prompts?: (keyof typeof challenges)[]
+ rejectPassword?: boolean
connectionDelay?: number
- initial?: "connecting" | "password" | "confirmation" | "failure" | "required"
+ initial?: "connecting" | "challenge" | "failure" | "required"
responseDelay?: number
}) {
const state: FixtureState = {
- step: 0,
+ prompts: [],
item:
props.initial === "required"
? {
@@ -52,15 +69,12 @@ function Fixture(props: {
listeners.forEach((listener) => listener(snapshot()))
}
- const prompts = [
- {
- id: "host-key",
- text: "The authenticity of host 'dev.example.com' can't be established.\nED25519 key fingerprint is SHA256:EXAMPLE-FINGERPRINT-FOR-STORY-ONLY.\nAre you sure you want to continue connecting?",
- confirm: true,
- },
- { id: "password", text: "brendon@dev.example.com's password:", confirm: false },
- { id: "otp", text: "Verification code:", confirm: false },
- ]
+ const nextChallenge = () => {
+ const next = state.prompts.shift()
+ update(
+ next ? { stage: "authentication", prompt: challenges[next] } : { stage: "ready", saved: true, prompt: undefined },
+ )
+ }
const api: SshPlatform = {
getState: async () => snapshot(),
@@ -74,8 +88,9 @@ function Fixture(props: {
hosts: async () => ["devbox", "staging", "build-host"],
start: async (input) => {
clearTimeout(state.timer)
- state.before = state.item
- state.step = props.initial === "password" || props.initial === "required" ? 1 : 0
+ state.before = state.item?.config.id === input.id ? state.item : undefined
+ state.prompts =
+ props.prompts?.slice() ?? (props.initial === "required" ? ["password", "otp"] : ["trust", "password", "otp"])
state.item = {
config: input,
saved: props.initial === "required",
@@ -84,42 +99,30 @@ function Fixture(props: {
destination: "brendon@dev.example.com:22",
}
+ update({ stage: "connecting" })
+
if (props.initial === "connecting") return
- if (props.incompatible && !input.replace) {
- update({ stage: "incompatible", error: "version" })
+ if (props.incompatible && !input.replace) return update({ stage: "incompatible", error: "version" })
- return
- }
+ const connected = () => {
+ if (props.incompatible === "failed-update") return update({ stage: "failed", error: "install" })
- if (props.connectionDelay) {
- update({ stage: "connecting" })
- state.timer = setTimeout(
- () => update(props.keyOnly ? { stage: "ready" } : { stage: "authentication", prompt: prompts[state.step] }),
- props.connectionDelay,
- )
+ if (props.incompatible === "version-mismatch") return update({ stage: "incompatible", error: "version" })
- return
+ if (props.initial === "failure" && state.before?.stage !== "failed")
+ return update({ stage: "failed", error: "connection", detail: "Connection refused" })
+ nextChallenge()
}
- update(
- props.initial === "failure"
- ? {
- stage: "failed",
- error: "connection",
- detail: "ssh: connect to host dev.example.com port 22: Connection refused",
- }
- : { stage: "authentication", prompt: prompts[state.step] },
- )
+ if (!props.connectionDelay) return connected()
+ state.timer = setTimeout(connected, props.connectionDelay)
},
- respond: async () => {
+ respond: async (_id, prompt) => {
const next = () => {
- state.step += 1
- update(
- state.step < prompts.length
- ? { stage: "authentication", prompt: prompts[state.step] }
- : { stage: "ready", prompt: undefined },
- )
+ if (props.rejectPassword && state.before?.stage !== "failed" && prompt === "password")
+ return update({ stage: "failed", error: "connection", detail: "Permission denied", prompt: undefined })
+ nextChallenge()
}
if (!props.responseDelay) return next()
@@ -306,15 +309,33 @@ export const Host = { render: () => }
export const Connecting = { render: () => }
-export const Password = { render: () => }
+export const KeyOnly = { render: () => }
+
+export const Password = { render: () => }
-export const SlowPassword = { render: () => }
+export const SlowPassword = {
+ render: () => ,
+}
+
+export const KeyPassphraseRejected = {
+ render: () => ,
+}
+
+export const VerificationCode = { render: () => }
-export const Confirmation = { render: () => }
+export const Confirmation = { render: () => }
export const Failure = { render: () => }
-export const IncompatibleHost = { render: () => }
+export const AuthenticationFailureRetry = { render: () => }
+
+export const IncompatibleHost = { render: () => }
+
+export const FailedUpdate = { render: () => }
+
+export const StillIncompatibleAfterUpdate = {
+ render: () => ,
+}
export const AuthenticationRequired = { render: () => }
@@ -324,4 +345,4 @@ export const IncompatibleSession = { render: () => }
-export const KeyReconnect = { render: () => }
+export const KeyReconnect = { render: () => }
diff --git a/packages/gui-plugins/src/ssh/dialog.tsx b/packages/gui-plugins/src/ssh/dialog.tsx
index 4930f50109e0..3946cce5daa7 100644
--- a/packages/gui-plugins/src/ssh/dialog.tsx
+++ b/packages/gui-plugins/src/ssh/dialog.tsx
@@ -99,6 +99,16 @@ export function DialogSsh(props: {
submit()
}
+ const ConnectionError = () => (
+
+ {(error) => (
+
+ {plugin.t(error())}
+
+ )}
+
+ )
+
return (