Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions packages/app/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,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
1 change: 1 addition & 0 deletions packages/app/src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,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
36 changes: 25 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
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" | "project" | "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,
}
}
1 change: 1 addition & 0 deletions packages/app/src/pages/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ export default function Page() {
language={language}
timelineSessionID={timelineSessionID()}
timelineSessionKey={timelineSessionKey()}
timelineMessagesReady={timelineMessagesReady()}
timelineMessages={timelineMessages()}
mobileChanges={mobileChanges()}
mobileFallback={reviewPanel.mobileFallback()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ describe("findRunningQuestionFallbackSession", () => {
).toBeUndefined()
})

test("ignores running question parts older than the lookback window", () => {
test("recovers running question parts even when they are older than the lookback window", () => {
expect(
findRunningQuestionFallbackSession({
sessionID: "s",
hasQuestionRequest: false,
lookback: 2,
messages: [message("old"), message("recent-1"), message("recent-2")],
partsByMessageID: { old: [toolPart("question")] },
}),
).toBeUndefined()
).toBe("s")
})
})
6 changes: 1 addition & 5 deletions packages/app/src/pages/session/blockers/question-fallback.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import type { Message, Part } from "@opencode-ai/sdk/v2"

export const QUESTION_FALLBACK_LOOKBACK_MESSAGES = 5

export function findRunningQuestionFallbackSession(input: {
sessionID?: string
hasQuestionRequest: boolean
messages?: Message[]
partsByMessageID: Record<string, Part[] | undefined>
lookback?: number
}): string | undefined {
if (!input.sessionID) return undefined
if (input.hasQuestionRequest) return undefined
const messages = input.messages
if (!messages?.length) return undefined

const lookback = input.lookback ?? QUESTION_FALLBACK_LOOKBACK_MESSAGES
for (let i = messages.length - 1; i >= Math.max(0, messages.length - lookback); i--) {
for (let i = messages.length - 1; i >= 0; i--) {
const parts = input.partsByMessageID[messages[i].id]
if (!parts) continue
for (const part of parts) {
Expand Down
12 changes: 12 additions & 0 deletions packages/app/src/pages/session/session-main-view-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function shouldShowSessionOpeningState(input: {
activeSessionID?: string
timelineSessionID?: string
timelineMessagesReady: boolean
}) {
return (
!!input.activeSessionID &&
!!input.timelineSessionID &&
input.activeSessionID === input.timelineSessionID &&
!input.timelineMessagesReady
)
}
41 changes: 41 additions & 0 deletions packages/app/src/pages/session/session-main-view.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, test } from "bun:test"
import { shouldShowSessionOpeningState } from "./session-main-view-state"

describe("shouldShowSessionOpeningState", () => {
test("shows a target session loading state while route messages are not ready", () => {
expect(
shouldShowSessionOpeningState({
activeSessionID: "ses_target",
timelineSessionID: "ses_target",
timelineMessagesReady: false,
}),
).toBe(true)
})

test("does not replace the new-session home or ready timeline", () => {
expect(
shouldShowSessionOpeningState({
activeSessionID: undefined,
timelineSessionID: undefined,
timelineMessagesReady: false,
}),
).toBe(false)
expect(
shouldShowSessionOpeningState({
activeSessionID: "ses_target",
timelineSessionID: "ses_target",
timelineMessagesReady: true,
}),
).toBe(false)
})

test("does not show loading for a mismatched timeline identity", () => {
expect(
shouldShowSessionOpeningState({
activeSessionID: "ses_route",
timelineSessionID: "ses_other",
timelineMessagesReady: false,
}),
).toBe(false)
})
})
Loading
Loading