Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions packages/app/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const dict = {
"common.goForward": "Navigate forward",
"common.loading": "Loading",
"common.loading.ellipsis": "...",
"common.retry": "Retry",
"common.showMore": "Show more",
"common.cancel": "Cancel",
"common.open": "Open",
Expand Down Expand Up @@ -623,6 +624,7 @@ export const dict = {
"session.messages.loadingEarlier": "Loading earlier messages...",
"session.messages.loadEarlier": "Load earlier messages",
"session.messages.loading": "Loading messages...",
"session.opening": "Opening session...",
"session.messages.jumpToLatest": "Jump to latest",
"session.turnChange.undoBlocked": "Undo blocked",
"session.turnChange.redoBlocked": "Redo blocked",
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export const dict = {
"common.goForward": "前进",
"common.loading": "加载中",
"common.loading.ellipsis": "...",
"common.retry": "重试",
"common.showMore": "显示更多",
"common.cancel": "取消",
"common.connect": "连接",
Expand Down Expand Up @@ -585,6 +586,7 @@ export const dict = {
"session.messages.loadingEarlier": "正在加载更早的消息...",
"session.messages.loadEarlier": "加载更早的消息",
"session.messages.loading": "正在加载消息...",
"session.opening": "正在打开会话...",
"session.messages.jumpToLatest": "跳转到最新",
"session.turnChange.undoBlocked": "无法撤销",
"session.turnChange.redoBlocked": "无法重做",
Expand Down
39 changes: 28 additions & 11 deletions packages/app/src/pages/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ import {
displayName,
effectiveWorkspaceOrder,
errorMessage,
newSessionRoute,
openProjectRoute,
openSessionRoute,
startupAutoselectDirectory,
sortedRootSessions,
workspaceKey,
Expand All @@ -84,6 +82,7 @@ import {
pawworkSessionDirectories,
sortPawworkSidebarSessions,
} from "./layout/pawwork-session-source"
import { createShellNavigation } from "./layout/shell-navigation"
import {
buildPawworkSessionWindow,
nextPawworkSessionWindowLimit,
Expand Down Expand Up @@ -1364,11 +1363,15 @@ export default function Layout(props: ParentProps) {
})
}

function openSettings() {
function openSettingsSurface() {
setSettingsTab("general")
setSettingsOpen(true)
}

function openSettings() {
shellNavigation.openSettings()
}

createEffect(() => {
command.setModalOpen(settingsOpen())
})
Expand Down Expand Up @@ -1415,6 +1418,14 @@ export default function Layout(props: ParentProps) {
return currentProject()?.worktree ?? projectRoot(directory)
}

function releaseTransientShellLocks() {
if (sizet !== undefined) {
clearTimeout(sizet)
sizet = undefined
}
setState("sizing", false)
}

function syncSessionRoute(directory: string, id: string, root = activeProjectRoot(directory)) {
notification.session.markViewed(id)
const expanded = untrack(() => store.workspaceExpanded[directory])
Expand All @@ -1433,19 +1444,22 @@ export default function Layout(props: ParentProps) {
}

function navigateToSession(session: Session | undefined) {
if (!session) return
navigate(openSessionRoute(session.directory, session.id))
shellNavigation.openSession(session)
}

function openPawworkHome(directory?: string) {
const root = directory ? projectRoot(directory) : currentProject()?.worktree ?? projectRoot(currentDir())
if (!root) {
chooseProject()
return
}
navigate(newSessionRoute(root))
shellNavigation.openNewSession(directory)
}

const shellNavigation = createShellNavigation({
navigate,
releaseTransientLocks: releaseTransientShellLocks,
resolveProjectRoot: projectRoot,
currentProjectRoot: () => currentProject()?.worktree ?? projectRoot(currentDir()),
chooseProject,
openSettingsSurface,
})

function openProject(directory: string, shouldNavigate = true) {
layout.projects.open(directory)
if (shouldNavigate) return navigateToProject(directory)
Expand Down Expand Up @@ -2037,6 +2051,8 @@ export default function Layout(props: ParentProps) {
currentDir,
navList: currentSessions,
prefetchSession,
openSession: navigateToSession,
openNewSession: openPawworkHome,
workspaceName,
renameWorkspace,
editorOpen,
Expand Down Expand Up @@ -2079,6 +2095,7 @@ export default function Layout(props: ParentProps) {
sortMode={() => store.pawworkSortMode}
setScrollContainerRef={workspaceSidebarCtx.setScrollContainerRef}
prefetchSession={prefetchSession}
onOpenSession={navigateToSession}
onRenameSession={renamePawworkSession}
onTogglePinnedSession={togglePinnedSession}
exportSessionAvailable={exportSessionAvailable}
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/pages/layout/pawwork-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const PawworkSidebar = (props: {
sortMode: Accessor<PawworkSortMode>
setScrollContainerRef: (el: HTMLDivElement | undefined) => void
prefetchSession: (session: Session, priority?: "high" | "low") => void
hrefForSession?: (session: Session) => string
onOpenSession: (session: Session) => void
onRenameSession: (session: Session, next: string) => Promise<void>
onTogglePinnedSession: (sessionID: string) => void
exportSessionAvailable: Accessor<boolean>
Expand Down Expand Up @@ -158,6 +160,8 @@ export const PawworkSidebar = (props: {
slug={entry.item.slug}
showChild
prefetchSession={props.prefetchSession}
hrefForSession={props.hrefForSession}
onOpenSession={props.onOpenSession}
pinned={() => isPinned()}
timeText={() =>
entry.item.created > 0
Expand Down
85 changes: 85 additions & 0 deletions packages/app/src/pages/layout/shell-navigation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { describe, expect, test } from "bun:test"
import { base64Encode } from "@opencode-ai/util/encode"
import { createShellNavigation } from "./shell-navigation"

describe("createShellNavigation", () => {
test("opens a new session through one shell action and releases transient locks first", () => {
const calls: string[] = []
const shell = createShellNavigation({
navigate: (route) => calls.push(`navigate:${route}`),
releaseTransientLocks: (reason) => calls.push(`release:${reason}`),
resolveProjectRoot: (directory) => `/root:${directory}`,
currentProjectRoot: () => "/current",
chooseProject: () => calls.push("chooseProject"),
openSettingsSurface: () => calls.push("settings"),
})

shell.openNewSession("/repo")

expect(calls).toEqual([`release:new-session`, `navigate:/${base64Encode("/root:/repo")}/session`])
})

test("opens an existing session through one shell action and releases transient locks first", () => {
const calls: string[] = []
const shell = createShellNavigation({
navigate: (route) => calls.push(`navigate:${route}`),
releaseTransientLocks: (reason) => calls.push(`release:${reason}`),
resolveProjectRoot: (directory) => directory,
currentProjectRoot: () => "/current",
chooseProject: () => calls.push("chooseProject"),
openSettingsSurface: () => calls.push("settings"),
})

shell.openSession({ directory: "/repo", id: "ses_123" })

expect(calls).toEqual([`release:session`, `navigate:/${base64Encode("/repo")}/session/ses_123`])
})

test("opens settings through the same shell action owner instead of a standalone signal", () => {
const calls: string[] = []
const shell = createShellNavigation({
navigate: (route) => calls.push(`navigate:${route}`),
releaseTransientLocks: (reason) => calls.push(`release:${reason}`),
resolveProjectRoot: (directory) => directory,
currentProjectRoot: () => "/current",
chooseProject: () => calls.push("chooseProject"),
openSettingsSurface: () => calls.push("settings"),
})

shell.openSettings()

expect(calls).toEqual(["release:settings", "settings"])
})

test("falls back to project chooser when no directory can be resolved for a new session", () => {
const calls: string[] = []
const shell = createShellNavigation({
navigate: (route) => calls.push(`navigate:${route}`),
releaseTransientLocks: (reason) => calls.push(`release:${reason}`),
resolveProjectRoot: () => "",
currentProjectRoot: () => undefined,
chooseProject: () => calls.push("chooseProject"),
openSettingsSurface: () => calls.push("settings"),
})

shell.openNewSession()

expect(calls).toEqual(["release:choose-project", "chooseProject"])
})

test("falls back to project chooser when an explicit directory cannot be resolved", () => {
const calls: string[] = []
const shell = createShellNavigation({
navigate: (route) => calls.push(`navigate:${route}`),
releaseTransientLocks: (reason) => calls.push(`release:${reason}`),
resolveProjectRoot: () => undefined,
currentProjectRoot: () => "/current",
chooseProject: () => calls.push("chooseProject"),
openSettingsSurface: () => calls.push("settings"),
})

shell.openNewSession("/repo")

expect(calls).toEqual(["release:choose-project", "chooseProject"])
})
})
50 changes: 50 additions & 0 deletions packages/app/src/pages/layout/shell-navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { newSessionRoute, openSessionRoute } from "./helpers"

export type ShellNavigationReleaseReason = "new-session" | "session" | "settings" | "choose-project"

export type ShellNavigationSession = {
directory: string
id: string
}

export function createShellNavigation(input: {
navigate: (route: string) => void
releaseTransientLocks: (reason: ShellNavigationReleaseReason) => void
resolveProjectRoot: (directory: string) => string | undefined
currentProjectRoot: () => string | undefined
chooseProject: () => void
openSettingsSurface: () => void
}) {
const resolveNewSessionRoot = (directory?: string) => {
if (directory) return input.resolveProjectRoot(directory)
return input.currentProjectRoot()
}

const openNewSession = (directory?: string) => {
const root = resolveNewSessionRoot(directory)
if (!root) {
input.releaseTransientLocks("choose-project")
input.chooseProject()
return
}
input.releaseTransientLocks("new-session")
input.navigate(newSessionRoute(root))
}

const openSession = (session: ShellNavigationSession | undefined) => {
if (!session) return
input.releaseTransientLocks("session")
input.navigate(openSessionRoute(session.directory, session.id))
}

const openSettings = () => {
input.releaseTransientLocks("settings")
input.openSettingsSurface()
}

return {
openNewSession,
openSession,
openSettings,
}
}
66 changes: 66 additions & 0 deletions packages/app/src/pages/layout/sidebar-item-navigation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { describe, expect, test } from "bun:test"
import {
defaultNewSessionHref,
defaultSessionHref,
openSidebarLinkWithShell,
shouldOpenLinkWithShell,
type SidebarLinkClick,
} from "./sidebar-item-navigation"

const click = (overrides: Partial<SidebarLinkClick> = {}): SidebarLinkClick => ({
defaultPrevented: false,
button: 0,
metaKey: false,
ctrlKey: false,
shiftKey: false,
altKey: false,
...overrides,
})

describe("sidebar item navigation", () => {
test("builds the fallback href for normal browser navigation", () => {
expect(defaultSessionHref("repo-slug", { id: "ses_123" })).toBe("/repo-slug/session/ses_123")
expect(defaultNewSessionHref("repo-slug")).toBe("/repo-slug/session")
})

test("routes ordinary left-clicks through the shell owner", () => {
expect(shouldOpenLinkWithShell(click())).toBe(true)
})

test("opens sidebar links through the shell owner after preventing default navigation", () => {
const calls: string[] = []
const handled = openSidebarLinkWithShell(
{
...click(),
preventDefault: () => calls.push("preventDefault"),
},
() => calls.push("open"),
)

expect(handled).toBe(true)
expect(calls).toEqual(["preventDefault", "open"])
})

test("keeps modified or non-left clicks on the anchor default path", () => {
expect(shouldOpenLinkWithShell(click({ metaKey: true }))).toBe(false)
expect(shouldOpenLinkWithShell(click({ ctrlKey: true }))).toBe(false)
expect(shouldOpenLinkWithShell(click({ shiftKey: true }))).toBe(false)
expect(shouldOpenLinkWithShell(click({ altKey: true }))).toBe(false)
expect(shouldOpenLinkWithShell(click({ button: 1 }))).toBe(false)
expect(shouldOpenLinkWithShell(click({ defaultPrevented: true }))).toBe(false)
})

test("does not call the shell owner for modified clicks", () => {
const calls: string[] = []
const handled = openSidebarLinkWithShell(
{
...click({ metaKey: true }),
preventDefault: () => calls.push("preventDefault"),
},
() => calls.push("open"),
)

expect(handled).toBe(false)
expect(calls).toEqual([])
})
})
36 changes: 36 additions & 0 deletions packages/app/src/pages/layout/sidebar-item-navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Session } from "@opencode-ai/sdk/v2/client"

export type SidebarLinkClick = {
defaultPrevented: boolean
button: number
metaKey: boolean
ctrlKey: boolean
shiftKey: boolean
altKey: boolean
}

export type SidebarShellLinkEvent = SidebarLinkClick & {
preventDefault: () => void
}

export function defaultSessionHref(slug: string, session: Pick<Session, "id">) {
return `/${slug}/session/${session.id}`
}

export function defaultNewSessionHref(slug: string) {
return `/${slug}/session`
}

export function shouldOpenLinkWithShell(event: SidebarLinkClick) {
if (event.defaultPrevented) return false
if (event.button !== 0) return false
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return false
return true
}

export function openSidebarLinkWithShell(event: SidebarShellLinkEvent, open: () => void) {
if (!shouldOpenLinkWithShell(event)) return false
event.preventDefault()
open()
return true
}
Loading
Loading