GeezerVison is showing github.com — refactor(app): share session index and project actions by joe-ieta · Pull Request #62845 · anomalyco/opencode
refactor(app): share session index and project actions
#62845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
516aa29
refactor(app): share the bounded session index
joe-ieta Nov 9, 2026
1cf53f4
refactor(app): share Home project actions and menus
joe-ieta Nov 9, 2026
6613ed4
chore(app): satisfy project actions lint rules
joe-ieta Nov 9, 2026
739ac31
refactor(app): keep the session index move self-contained
joe-ieta Nov 9, 2026
8c30804
chore(app): sync project actions with upstream dev
joe-ieta Nov 15, 2026
b69665d
chore(app): sync session index with upstream dev
joe-ieta Nov 19, 2026
1710919
chore(app): sync project actions with upstream dev
joe-ieta Nov 19, 2026
233ed96
refactor(app): consolidate shared navigation modules
joe-ieta Nov 19, 2026
cf0814f
chore: sync consolidated refactor with dev
joe-ieta Nov 19, 2026
b696d7a
refactor(app): require queued project selection
joe-ieta Nov 19, 2026
File filter
Filter by extension
.ts
(5)
.tsx
(3)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -17,11 +17,11 @@ import {
import { notifySessionTabsRemoved } from "@/shell/titlebar/session-events"
import { useCommand } from "@/shell/commands/command"
import {
HOME_SESSION_INDEX_LIMIT ,
HOME_SESSION_LIMIT ,
mergeHomeSessionIndex ,
retainHomeSessions ,
} from "@/home/sessions/ index"
SESSION_INDEX_LIMIT ,
SESSION_LIST_LIMIT ,
mergeSessionIndex ,
retainSessions ,
} from "@/runtime/server/session- index"
import type { LocalProject } from "@/shell/state/layout"
import { useLanguage } from "@/runtime/i18n/language"
import { ServerConnection } from "@/runtime/server/registry"
Expand All
@@ -44,7 +44,7 @@ import { usePlatform } from "@/runtime/platform/platform"
import { sessionLabel, sessionTitle } from "@/session/title"
import { showToast } from "@/shell/notifications/toast"
import { archiveHomeSession } from "./archive"
import { homeSessionsQuery } from "./ queries"
import { sessionIndexQuery } from "@/runtime/server/session- queries"
import {
HOME_SESSIONS_STALE_MS,
INITIAL_HOME_SESSIONS_LOAD_STATE,
Expand Down
Expand Up
@@ -185,7 +185,7 @@ export function createHomeSessionsController(home: HomeController) {
}
// Through the shared query, so a fetch the sidebar already started is joined and the result lands in its cache.
void queryClient.fetchQuery({ ...homeSessionsQuery (conn, ctx), staleTime: 0 }).then(
void queryClient.fetchQuery({ ...sessionIndexQuery (conn, ctx), staleTime: 0 }).then(
() => dispatchLoad({ type: "fetch.succeeded", attempt, reducedMotion: prefersReducedMotion() }),
(cause) =>
dispatchLoad({
Expand Down
Expand Up
@@ -260,7 +260,7 @@ export function createHomeSessionsController(home: HomeController) {
void Promise.allSettled(
directories.map((directory) =>
ctx.sdk.api.session.list(
{ directory, limit: HOME_SESSION_INDEX_LIMIT , order: "desc", parentID: null },
{ directory, limit: SESSION_INDEX_LIMIT , order: "desc", parentID: null },
{ signal: controller.signal },
),
),
Expand All
@@ -277,11 +277,11 @@ export function createHomeSessionsController(home: HomeController) {
if (!ctx || !conn) return []
return retainHomeSessions (
return retainSessions (
ctx.data.session.apply(
mergeHomeSessionIndex ([...fetchedSessions(), ...scopedSessions()], ctx.data.session.list()),
mergeSessionIndex ([...fetchedSessions(), ...scopedSessions()], ctx.data.session.list()),
),
HOME_SESSION_LIMIT ,
SESSION_LIST_LIMIT ,
Date.now(),
)
})
Expand All
@@ -295,7 +295,7 @@ export function createHomeSessionsController(home: HomeController) {
}),
)
const records = createMemo(() => allRecords().slice(0, HOME_SESSION_LIMIT ))
const records = createMemo(() => allRecords().slice(0, SESSION_LIST_LIMIT ))
const groups = createMemo(() => groupSessions(records(), language))
const prefetched = new Set<string>()
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2,14 +2,14 @@ import { describe, expect, test } from "bun:test"
import type { SessionInfo } from "@opencode/client/promise"
import { SESSION_RECENT_LIMIT, SESSION_RECENT_WINDOW } from "@/runtime/server/global-sync/types"
import {
HOME_SESSION_INDEX_LIMIT ,
HOME_SESSION_LIMIT ,
HOME_SESSION_PAGE_LIMIT ,
loadHomeSessionIndex ,
mergeHomeSessionIndex ,
parseHomeSessionIndex ,
retainHomeSessions ,
} from "./index"
SESSION_INDEX_LIMIT ,
SESSION_LIST_LIMIT ,
SESSION_INDEX_PAGE_LIMIT ,
loadSessionIndex ,
mergeSessionIndex ,
parseSessionIndex ,
retainSessions ,
} from "./session- index"
const session = (id: string, input: Partial<SessionInfo> = {}) =>
// SAFETY: fixtures spell every other field of the info they model, and each test only reads those fields.
Expand Down
Expand Up
@@ -41,18 +41,18 @@ const ids = (sessions: SessionInfo[]) => sessions.map((item) => item.id)
describe("Home session index", () => {
test("loads one bounded page of the newest sessions", async () => {
const all = history("/repo", HOME_SESSION_PAGE_LIMIT + 1)
const all = history("/repo", SESSION_INDEX_PAGE_LIMIT + 1)
const calls: Array<{ limit: number; order: "desc"; cursor?: string; parentID: null }> = []
const result = await loadHomeSessionIndex (async (input) => {
const result = await loadSessionIndex (async (input) => {
calls.push(input)
return { data: all.slice(0, input.limit), cursor: { next: "next" } }
})
expect(calls).toEqual([{ limit: HOME_SESSION_PAGE_LIMIT , order: "desc", parentID: null }])
expect(calls).toEqual([{ limit: SESSION_INDEX_PAGE_LIMIT , order: "desc", parentID: null }])
// Newest rows in server order, plus the recent window beyond the limit.
expect(ids(result)).toEqual(ids(all.slice(0, HOME_SESSION_INDEX_LIMIT + SESSION_RECENT_LIMIT)))
expect(ids(result)).toEqual(ids(all.slice(0, SESSION_INDEX_LIMIT + SESSION_RECENT_LIMIT)))
})
test("keeps each directory's newest sessions within the page", async () => {
Expand All
@@ -63,14 +63,14 @@ describe("Home session index", () => {
time: { created: item.time.created - 6000 * minute, updated: item.time.updated - 6000 * minute },
}))
const result = await loadHomeSessionIndex (async (input) => ({
const result = await loadSessionIndex (async (input) => ({
data: [...busy.slice(0, input.limit - quiet.length), ...quiet],
cursor: { next: "next" },
}))
expect(ids(result.filter((item) => item.location.directory === "/quiet"))).toEqual(ids(quiet))
expect(ids(result.filter((item) => item.location.directory === "/busy"))).toEqual(
ids(busy.slice(0, HOME_SESSION_INDEX_LIMIT + SESSION_RECENT_LIMIT)),
ids(busy.slice(0, SESSION_INDEX_LIMIT + SESSION_RECENT_LIMIT)),
)
})
Expand All
@@ -83,13 +83,13 @@ describe("Home session index", () => {
time: { created: item.time.created - 300 * minute, updated: item.time.updated - 300 * minute },
}))
const result = await loadHomeSessionIndex (async () => ({ data: [...archived, ...live], cursor: {} }))
const result = await loadSessionIndex (async () => ({ data: [...archived, ...live], cursor: {} }))
expect(ids(result)).toEqual(ids(live))
})
test("keeps only visible roots", () => {
expect(
parseHomeSessionIndex ([
parseSessionIndex ([
session("root"),
session("child", { parentID: "root" }),
session("archived", { time: { created: 1, updated: 1, archived: 2 } }),
Expand All
@@ -106,19 +106,19 @@ describe("Home session index parity with the complete index", () => {
const view = (index: SessionInfo[], known: SessionInfo[], removed = new Set<string>()) =>
ids(
retainHomeSessions (
mergeHomeSessionIndex (index, known).filter((item) => !removed.has(item.id)),
HOME_SESSION_LIMIT ,
retainSessions (
mergeSessionIndex (index, known).filter((item) => !removed.has(item.id)),
SESSION_LIST_LIMIT ,
now,
),
).toSorted()
const loaded = () => loadHomeSessionIndex (async () => ({ data: complete, cursor: {} }))
const loaded = () => loadSessionIndex (async () => ({ data: complete, cursor: {} }))
test("without local changes", async () => {
const result = view(await loaded(), [])
expect(result).toEqual(view(complete, []))
expect(result).toHaveLength(HOME_SESSION_LIMIT + SESSION_RECENT_LIMIT + 90 + 5)
expect(result).toHaveLength(SESSION_LIST_LIMIT + SESSION_RECENT_LIMIT + 90 + 5)
})
test("with new, re-timed, and unlisted-directory local sessions", async () => {
Expand All
@@ -140,7 +140,7 @@ describe("Home session index parity with the complete index", () => {
const removed = new Set(ids(complete.slice(0, SESSION_RECENT_LIMIT)))
const result = view(await loaded(), [], removed)
expect(result).toEqual(view(complete, [], removed))
expect(result).toHaveLength(HOME_SESSION_LIMIT + SESSION_RECENT_LIMIT + 90 + 5)
expect(result).toHaveLength(SESSION_LIST_LIMIT + SESSION_RECENT_LIMIT + 90 + 5)
expect(result.some((id) => removed.has(id))).toBe(false)
})
Expand All
@@ -151,8 +151,8 @@ describe("Home session index parity with the complete index", () => {
}))
expect(hot.every((item) => item.time.updated > now - SESSION_RECENT_WINDOW)).toBe(true)
const index = await loadHomeSessionIndex (async () => ({ data: hot, cursor: {} }))
expect(index).toHaveLength(HOME_SESSION_INDEX_LIMIT + SESSION_RECENT_LIMIT)
const index = await loadSessionIndex (async () => ({ data: hot, cursor: {} }))
expect(index).toHaveLength(SESSION_INDEX_LIMIT + SESSION_RECENT_LIMIT)
expect(view(index, [])).toEqual(view(hot, []))
})
})
Original file line number
Diff line number
Diff line change
Expand Up
@@ -4,18 +4,18 @@ import { SESSION_RECENT_LIMIT, SESSION_RECENT_WINDOW } from "@/runtime/server/gl
// One bounded page of the newest root sessions. Home shows 64 and the sidebar a handful per project, so older history
// is reached through the titlebar's server-backed search instead of downloading every session on startup.
export const HOME_SESSION_PAGE_LIMIT = 500
export const SESSION_INDEX_PAGE_LIMIT = 500
export const HOME_SESSION_LIMIT = 64
export const SESSION_LIST_LIMIT = 64
// Rows kept per directory from the fetched index: the visible limit plus the
// recent-window search bucket. Merging locally known sessions and pending
// removals into this subset resolves exactly like merging into the complete
// index, so Home shows the same rows, order, and search results while the
// query cache and every per-update re-merge stay bounded by directory count.
export const HOME_SESSION_INDEX_LIMIT = HOME_SESSION_LIMIT + SESSION_RECENT_LIMIT
export const SESSION_INDEX_LIMIT = SESSION_LIST_LIMIT + SESSION_RECENT_LIMIT
export async function loadHomeSessionIndex (
export async function loadSessionIndex (
list: (
input: {
limit: number
Expand All
@@ -27,23 +27,23 @@ export async function loadHomeSessionIndex(
) => Promise<SessionsResponse>,
signal?: AbortSignal,
) {
const response = await list({ limit: HOME_SESSION_PAGE_LIMIT , order: "desc", parentID: null }, { signal })
const response = await list({ limit: SESSION_INDEX_PAGE_LIMIT , order: "desc", parentID: null }, { signal })
return retainHomeSessions(parseHomeSessionIndex (response.data), HOME_SESSION_INDEX_LIMIT , Date.now())
return retainSessions(parseSessionIndex (response.data), SESSION_INDEX_LIMIT , Date.now())
}
// Keep this filter for locally known sessions merged into the fetched index.
export function parseHomeSessionIndex (sessions: SessionInfo[]) {
export function parseSessionIndex (sessions: SessionInfo[]) {
return sessions.filter((session) => !session.parentID && session.time.archived === undefined)
}
export function mergeHomeSessionIndex (fetched: SessionInfo[], known: SessionInfo[]) {
return parseHomeSessionIndex ([
export function mergeSessionIndex (fetched: SessionInfo[], known: SessionInfo[]) {
return parseSessionIndex ([
...new Map([...fetched, ...known].map((session) => [session.id, session] as const)).values(),
])
}
export function retainHomeSessions (sessions: SessionInfo[], limit: number, now: number) {
export function retainSessions (sessions: SessionInfo[], limit: number, now: number) {
return [...Map.groupBy(sessions, (session) => pathKey(session.location.directory)).values()].flatMap((items) => {
const sorted = items.toSorted((a, b) => {
const updated = (b.time.updated ?? b.time.created) - (a.time.updated ?? a.time.created)
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2,16 +2,16 @@ import type { SessionInfo } from "@opencode/client/promise"
import { queryOptions, skipToken } from "@tanstack/solid-query"
import type { ServerConnection } from "@/runtime/server/registry"
import type { ServerCtx } from "@/runtime/server/runtime"
import { loadHomeSessionIndex } from "./index"
import { loadSessionIndex } from "./session- index"
// Keep the immutable result opaque so Solid Query does not recursively unwrap every session on mount.
const selectSessions = (sessions: SessionInfo[]) => () => sessions
export function homeSessionsQuery (conn: ServerConnection.Any | undefined, ctx: ServerCtx | undefined) {
export function sessionIndexQuery (conn: ServerConnection.Any | undefined, ctx: ServerCtx | undefined) {
return queryOptions({
queryKey: ["home-sessions", conn] as const,
queryFn: ctx
? ({ signal }) => loadHomeSessionIndex ((input, options) => ctx.sdk.api.session.list(input, options), signal)
? ({ signal }) => loadSessionIndex ((input, options) => ctx.sdk.api.session.list(input, options), signal)
: skipToken,
retry: false,
staleTime: 30_000,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -11,7 +11,7 @@ import { useLayout } from "@/shell/state/layout"
import { useTabs } from "@/shell/tabs/tabs"
import { sessionBusy, sessionRequests, type SessionRequests } from "@/shell/layout/project-avatar-state"
import { pathKey } from "@/workspaces/path-key"
import { parseHomeSessionIndex } from "@/home/sessions/ index"
import { parseSessionIndex } from "@/runtime/server/session- index"
import { sessionFormRequest, sessionPermissionRequest, sessionTreeIDs } from "@/session/requests/session-request-tree"
import { notifySessionTabsRemoved } from "./session-events"
import { errorMessage } from "@/shell/layout/helpers"
Expand Down
Expand Up
@@ -126,7 +126,7 @@ export function createSessionInbox(options: { archived?: boolean } = {}) {
queryFn: ({ signal }: { signal: AbortSignal }) =>
item.ctx.sdk.api.session
.list({ limit: INDEX_LIMIT, order: "desc", parentID: null }, { signal })
.then((response) => parseHomeSessionIndex (response.data)),
.then((response) => parseSessionIndex (response.data)),
retry: false,
staleTime: 30_000,
refetchOnMount: true,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -14,8 +14,8 @@ import { ServerConnection } from "@/runtime/server/registry"
import { useGlobal, useServerCtx } from "@/runtime/server/runtime"
import { SessionTabAvatarView } from "@/shell/layout/session-tab-avatar"
import { compareSessionTime } from "@/shell/layout/helpers"
import { mergeHomeSessionIndex } from "@/home/sessions/ index"
import { homeSessionsQuery } from "@/home/sessions/ queries"
import { mergeSessionIndex } from "@/runtime/server/session- index"
import { sessionIndexQuery } from "@/runtime/server/session- queries"
import { listClosedTabs, type ClosedTab } from "@/shell/tabs/closed"
import { sessionIDHasOpenTab, useTabs } from "@/shell/tabs/tabs"
import { sessionTabTitle } from "./tab-title"
Expand Down
Expand Up
@@ -56,7 +56,7 @@ export function RecentlyClosedTabsMenu(props: {
const ctx = global.serverCtx(ServerConnection.key(conn))
return {
...homeSessionsQuery (conn, ctx),
...sessionIndexQuery (conn, ctx),
enabled: state.open && recent().length < 10 && ctx?.sdk.connection.status() === "connected",
}
}),
Expand All
@@ -74,7 +74,7 @@ export function RecentlyClosedTabsMenu(props: {
if (!ctx) return []
return ctx.data.session
.apply(mergeHomeSessionIndex (sessions[index]?.data?.() ?? [], ctx.data.session.list()))
.apply(mergeSessionIndex (sessions[index]?.data?.() ?? [], ctx.data.session.list()))
.filter((session) => !sessionIDHasOpenTab(tabs.store, server, session.id))
.filter(
(session) => !recent().some((entry) => entry.tab.server === server && entry.tab.sessionId === session.id),
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -13,7 +13,7 @@ import { IconButton } from "@opencode/ui/icon-button"
import { Menu } from "@opencode/ui/menu"
import { ScrollView } from "@opencode/ui/scroll-view"
import { displayName } from "@opencode/ui/project-avatar"
import { homeSessionsQuery } from "@/home/sessions/ queries"
import { sessionIndexQuery } from "@/runtime/server/session- queries"
import { createProjectActions } from "@/home/projects/actions"
import { ProjectMenuItems } from "@/home/projects/menu"
import { buildHomeSessionRecords } from "@/home/sessions/records"
Expand Down
Expand Up
@@ -229,7 +229,7 @@ function ProjectList(props: {
})
const sessions = useQuery(() => ({
...homeSessionsQuery (connection(), ctx()),
...sessionIndexQuery (connection(), ctx()),
enabled: ctx()?.sdk.connection.status() === "connected",
}))
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
import type { OpenCodeEvent, SessionInfo } from "@opencode/client/promise"
import { createStore } from "solid-js/store"
import { mergeHomeSessionIndex } from "@/home/sessions/ index"
import { mergeSessionIndex } from "@/runtime/server/session- index"
const activityTypes = [
"session.inbox.enqueued",
Expand Down
Expand Up
@@ -50,7 +50,7 @@ export function mergeSidebarSessions(
) {
const timestamps = new Map(indexed.map((session) => [session.id, session.time.updated]))
return mergeHomeSessionIndex (
return mergeSessionIndex (
indexed,
known.map((session) => {
const updated = timestamps.get(session.id)
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.