mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
feat(app): hide and mute sessions in Recent sidebar (#63427)
This commit is contained in:
@@ -824,6 +824,11 @@ export const dict = {
|
||||
"sidebar.recent.section.recent": "Recent",
|
||||
"sidebar.recent.empty": "No recent sessions",
|
||||
"sidebar.recent.pin": "Pin",
|
||||
"sidebar.recent.mute": "Mute",
|
||||
"sidebar.recent.muted": "Muted",
|
||||
"sidebar.recent.unmute": "Unmute",
|
||||
"sidebar.recent.hide": "Hide",
|
||||
"sidebar.recent.unhide": "Unhide",
|
||||
"sidebar.recent.unpin": "Unpin",
|
||||
"sidebar.recent.moveUp": "Move up",
|
||||
"sidebar.recent.moveDown": "Move down",
|
||||
|
||||
@@ -1118,6 +1118,18 @@ export function createPluginAttachment(apis: HostApis) {
|
||||
const result = { notification: false, sound: false }
|
||||
const session = options.session
|
||||
|
||||
if (session) {
|
||||
await global.sessionPreferences.ready.promise
|
||||
|
||||
const root = global.serverCtx(ServerConnection.Key.make(session.server))?.data.session.root(session.id) ?? session.id
|
||||
|
||||
if (
|
||||
global.sessionPreferences.muted(session.server, session.id) ||
|
||||
global.sessionPreferences.muted(session.server, root)
|
||||
)
|
||||
return result
|
||||
}
|
||||
|
||||
await Promise.allSettled([
|
||||
allowed.sound &&
|
||||
global.notifications.sound(key, () => {
|
||||
|
||||
@@ -33,6 +33,7 @@ import { createSessionMessageHandoffs } from "@/session/handoff"
|
||||
import { createServerNotificationState } from "@/shell/notifications/notification"
|
||||
import { createNotificationCoordinator } from "@/shell/notifications/coordinator"
|
||||
import { useCurrentRoute } from "@/shell/state/layout"
|
||||
import { createSessionPreferences } from "@/shell/state/session-preferences"
|
||||
import { useTabs } from "@/shell/tabs/tabs"
|
||||
import { Persist, persisted } from "@/runtime/persistence/storage"
|
||||
import { createDesktopData } from "./data"
|
||||
@@ -52,6 +53,7 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext(
|
||||
init: () => {
|
||||
const server = useServers()
|
||||
const models = createGlobalModels()
|
||||
const sessionPreferences = createSessionPreferences()
|
||||
const notificationCoordinator = createNotificationCoordinator()
|
||||
const owner = getOwner()
|
||||
|
||||
@@ -79,6 +81,7 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext(
|
||||
() => server.local(effect.conn),
|
||||
server.projects.forServer(effect.key),
|
||||
notificationCoordinator,
|
||||
sessionPreferences,
|
||||
),
|
||||
dispose,
|
||||
}),
|
||||
@@ -124,6 +127,7 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext(
|
||||
retry: serverHealth.retry,
|
||||
},
|
||||
models,
|
||||
sessionPreferences,
|
||||
/** Runs each keyed sound and system notification once across windows; notifications only while none has focus. */
|
||||
notifications: notificationCoordinator,
|
||||
/** The live controller of a server, or undefined while it is unlisted or rejects our credentials. Reactive. */
|
||||
@@ -198,6 +202,7 @@ function createServerController(
|
||||
isLocal: Accessor<boolean>,
|
||||
projects: ReturnType<typeof createServerProjects>,
|
||||
notificationCoordinator: ReturnType<typeof createNotificationCoordinator>,
|
||||
sessionPreferences: ReturnType<typeof createSessionPreferences>,
|
||||
) {
|
||||
const language = useLanguage()
|
||||
const settings = useSettings()
|
||||
@@ -254,7 +259,17 @@ function createServerController(
|
||||
|
||||
const sync = createServerSyncContext(sdk, data)
|
||||
const autoApprove = createPermissionAutoApprover({ sdk, data })
|
||||
const notification = createServerNotificationState({ sdk, data, key: connKey, coordinator: notificationCoordinator })
|
||||
onCleanup(data.on("session.deleted", (event) => sessionPreferences.forget(connKey, event.data.sessionID)))
|
||||
|
||||
const notification = createServerNotificationState({
|
||||
sdk,
|
||||
data,
|
||||
key: connKey,
|
||||
coordinator: notificationCoordinator,
|
||||
muted: (id) => sessionPreferences.muted(connKey, id),
|
||||
preferencesLoaded: sessionPreferences.ready.promise,
|
||||
})
|
||||
|
||||
// Owned by the server, so a first prompt's handoff outlives the draft that sent it.
|
||||
const handoff = createSessionMessageHandoffs({ sdk, data })
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getDirectory, getFilename } from "@opencode/util/path"
|
||||
import { FileIcon } from "@opencode/ui/file-icon"
|
||||
import { Button } from "@opencode/ui/button"
|
||||
import { Dialog, DialogBody } from "@opencode/ui/dialog"
|
||||
import { Keybind } from "@opencode/ui/keybind"
|
||||
import { Tooltip } from "@opencode/ui/tooltip"
|
||||
@@ -69,6 +70,7 @@ export function CommandPaletteView(props: {
|
||||
close: () => void
|
||||
/** The row whose selection is still in progress, such as an archived session being restored. */
|
||||
busyEntryID?: string
|
||||
unhide?: (entry: CommandPaletteEntry) => (() => void) | undefined
|
||||
}) {
|
||||
const language = useLanguage()
|
||||
const tabs = useTabs()
|
||||
@@ -110,15 +112,30 @@ export function CommandPaletteView(props: {
|
||||
onSelect={props.select}
|
||||
onClose={props.close}
|
||||
>
|
||||
{(item, row) => (
|
||||
<PaletteRow
|
||||
row={row}
|
||||
item={item()}
|
||||
language={language}
|
||||
sessionOpen={sessionOpen(item())}
|
||||
busy={props.busyEntryID === item().id}
|
||||
/>
|
||||
)}
|
||||
{(item, row) => {
|
||||
const entry = () => (
|
||||
<PaletteRow
|
||||
row={row}
|
||||
item={item()}
|
||||
language={language}
|
||||
sessionOpen={sessionOpen(item())}
|
||||
busy={props.busyEntryID === item().id}
|
||||
/>
|
||||
)
|
||||
|
||||
return (
|
||||
<Show when={props.unhide?.(item())} fallback={entry()}>
|
||||
{(unhide) => (
|
||||
<div class="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-1">
|
||||
{entry()}
|
||||
<Button size="small" variant="ghost-muted" onClick={() => unhide()()}>
|
||||
{language.t("sidebar.recent.unhide")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
)
|
||||
}}
|
||||
</SearchList>
|
||||
</DialogBody>
|
||||
</Dialog>
|
||||
|
||||
@@ -160,6 +160,17 @@ export function DialogSessionSearch(props: { archived?: boolean }) {
|
||||
select={select}
|
||||
close={() => dialog.close(layer?.id)}
|
||||
busyEntryID={selectSessionRestoreEntryID(searchState())}
|
||||
unhide={(entry) => {
|
||||
const server = entry.server
|
||||
const id = entry.sessionID
|
||||
|
||||
if (!server || !id || !global.sessionPreferences.hidden(server, id)) return
|
||||
|
||||
return () => {
|
||||
global.sessionPreferences.update("hidden", server, id, false)
|
||||
dialog.close(layer?.id)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -79,6 +79,8 @@ export function createServerNotificationState(input: {
|
||||
data: Data
|
||||
key: ServerConnection.Key
|
||||
coordinator: ReturnType<typeof createNotificationCoordinator>
|
||||
muted: (sessionID: string) => boolean
|
||||
preferencesLoaded?: Promise<unknown>
|
||||
}) {
|
||||
const platform = usePlatform()
|
||||
const settings = useSettings()
|
||||
@@ -294,6 +296,7 @@ export function createServerNotificationState(input: {
|
||||
|
||||
// Loading the session keeps a background completion visible in the server-derived unread state.
|
||||
const lookup = async (sessionID: string) => {
|
||||
if (input.preferencesLoaded) await input.preferencesLoaded
|
||||
const session = input.data.session.get(sessionID)
|
||||
|
||||
if (session) return session
|
||||
@@ -309,7 +312,7 @@ export function createServerNotificationState(input: {
|
||||
if (hasRunningChild(input.data, sessionID)) return
|
||||
|
||||
void lookup(sessionID).then((session) => {
|
||||
if (disposed.value) return
|
||||
if (disposed.value || input.muted(sessionID)) return
|
||||
|
||||
if (!session) return
|
||||
|
||||
@@ -333,7 +336,7 @@ export function createServerNotificationState(input: {
|
||||
|
||||
const handleSessionError = (sessionID: string, eventID: string) => {
|
||||
void lookup(sessionID).then((session) => {
|
||||
if (disposed.value) return
|
||||
if (disposed.value || input.muted(sessionID)) return
|
||||
|
||||
if (session?.parentID) return
|
||||
|
||||
@@ -369,7 +372,7 @@ export function createServerNotificationState(input: {
|
||||
const category = kind === "question" || kind === "mcp-elicitation" ? "questions" : "permissions"
|
||||
|
||||
const pending = () => {
|
||||
if (disposed.value) return false
|
||||
if (disposed.value || input.muted(sessionID) || input.muted(input.data.session.root(sessionID))) return false
|
||||
|
||||
if (kind !== "permission") return input.data.session.form.list(sessionID)?.some((form) => form.id === requestID)
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Schema } from "effect"
|
||||
import { createMemo } from "solid-js"
|
||||
import { Persistence } from "@/runtime/persistence/schema"
|
||||
import { Persist, persisted } from "@/runtime/persistence/storage"
|
||||
import { useServers } from "@/runtime/server/registry"
|
||||
import {
|
||||
recentSessionEndpoints,
|
||||
recentSessionKey,
|
||||
removePin,
|
||||
splitRecentSessionKey,
|
||||
} from "@/shell/titlebar/recent-sessions-model"
|
||||
|
||||
const Preferences = Persistence.struct({
|
||||
hidden: Persistence.array(Schema.String),
|
||||
muted: Persistence.array(Schema.String),
|
||||
})
|
||||
|
||||
export function createSessionPreferences() {
|
||||
const servers = useServers()
|
||||
const endpoints = createMemo(() => recentSessionEndpoints(servers.list, servers.ownUrl()))
|
||||
|
||||
const [state, set, , ready] = persisted({ ...Persist.global("session.preferences"), sync: true }, Preferences, {
|
||||
hidden: [],
|
||||
muted: [],
|
||||
})
|
||||
|
||||
const key = (server: string, id: string) => recentSessionKey(endpoints().get(server) ?? server, id)
|
||||
|
||||
const identities = (stored: readonly string[]) =>
|
||||
new Set(stored.map((value) => {
|
||||
const session = splitRecentSessionKey(value)
|
||||
|
||||
return session ? key(session.server, session.sessionID) : value
|
||||
}))
|
||||
|
||||
const keys = {
|
||||
hidden: createMemo(() => identities(state.hidden)),
|
||||
muted: createMemo(() => identities(state.muted)),
|
||||
}
|
||||
|
||||
const update = (kind: keyof typeof keys, server: string, id: string, enabled: boolean) => {
|
||||
const apply = () => {
|
||||
if (keys[kind]().has(key(server, id)) === enabled) return
|
||||
const value = recentSessionKey(server, id)
|
||||
set(kind, (current) => (enabled ? [...current, value] : removePin(current, value, endpoints())))
|
||||
}
|
||||
|
||||
if (ready()) return apply()
|
||||
void ready.promise?.then(apply)
|
||||
}
|
||||
|
||||
return {
|
||||
ready,
|
||||
hidden: (server: string, id: string) => keys.hidden().has(key(server, id)),
|
||||
muted: (server: string, id: string) => keys.muted().has(key(server, id)),
|
||||
update,
|
||||
forget(server: string, id: string) {
|
||||
update("hidden", server, id, false)
|
||||
update("muted", server, id, false)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
partitionRecentSessions,
|
||||
recentSessionEndpoints,
|
||||
recentSessionKey,
|
||||
recentRowUnread,
|
||||
removePin,
|
||||
reorderPins,
|
||||
sortRecentSessions,
|
||||
@@ -39,6 +40,33 @@ const item = (server: string, value: SessionInfo): RecentSession => ({
|
||||
session: value,
|
||||
})
|
||||
|
||||
test("hiding filters hydrated pins and recent rows only on their server", () => {
|
||||
const pin = item("local", session("pinned", 1))
|
||||
const recent = item("local", session("recent", 2))
|
||||
const remote = item("remote", recent.session)
|
||||
|
||||
const input = {
|
||||
items: [recent, remote],
|
||||
pins: [pin.key],
|
||||
endpoints: new Map<string, string>(),
|
||||
open: new Set<string>(),
|
||||
archived: () => false,
|
||||
resolvePin: () => pin,
|
||||
}
|
||||
|
||||
expect(partitionRecentSessions({ ...input, hidden: (server) => server === "local" })).toEqual({
|
||||
pinned: [],
|
||||
recent: [remote],
|
||||
})
|
||||
expect(partitionRecentSessions(input).pinned).toEqual([pin])
|
||||
})
|
||||
|
||||
test("muting hides the unread dot until unmuted", () => {
|
||||
expect(recentRowUnread(true, false, true)).toBe(false)
|
||||
expect(recentRowUnread(true, false, false)).toBe(true)
|
||||
expect(recentRowUnread(true, true, false)).toBe(false)
|
||||
})
|
||||
|
||||
test("pin keys round trip server keys that contain the separator's neighbours", () => {
|
||||
const key = recentSessionKey("http://server.example:4096", "ses_1")
|
||||
|
||||
|
||||
@@ -353,6 +353,7 @@ export function mergeRecentSessions(
|
||||
* one that is not loaded yet resolves through `resolvePin`.
|
||||
*/
|
||||
export function partitionRecentSessions(input: {
|
||||
hidden?: (server: string, id: string) => boolean
|
||||
items: readonly RecentSession[]
|
||||
pins: readonly string[]
|
||||
endpoints: ReadonlyMap<string, string>
|
||||
@@ -373,6 +374,8 @@ export function partitionRecentSessions(input: {
|
||||
|
||||
if (!item || item.session.time.archived !== undefined) return []
|
||||
|
||||
if (input.hidden?.(item.server, item.session.id)) return []
|
||||
|
||||
const id = identity(item)
|
||||
|
||||
if (pinnedSessions.has(id)) return []
|
||||
@@ -386,6 +389,7 @@ export function partitionRecentSessions(input: {
|
||||
|
||||
// Opening a row should reuse an existing tab. Otherwise prefer a stable route regardless of fetch order.
|
||||
for (const item of input.items) {
|
||||
if (input.hidden?.(item.server, item.session.id)) continue
|
||||
const id = identity(item)
|
||||
|
||||
if (pinnedKeys.has(item.key) || pinnedSessions.has(id)) continue
|
||||
@@ -405,3 +409,7 @@ export function partitionRecentSessions(input: {
|
||||
|
||||
return { pinned, recent: sortRecentSessions([...recent.values()]) }
|
||||
}
|
||||
|
||||
export function recentRowUnread(unread: boolean, loading: boolean, muted: boolean) {
|
||||
return unread && !loading && !muted
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
recentPageFailed,
|
||||
recentPageHasMore,
|
||||
recentPageLoaded,
|
||||
recentRowUnread,
|
||||
recentSessionEndpoints,
|
||||
recentSessionKey,
|
||||
removePin,
|
||||
@@ -178,6 +179,7 @@ export function RecentSessions() {
|
||||
batch(() => {
|
||||
item.ctx.data.session.forget(sessionID)
|
||||
forget(item.server, sessionID)
|
||||
global.sessionPreferences.forget(item.server, sessionID)
|
||||
setHydration(produce((cache) => void delete cache[key]))
|
||||
removePinKey(key)
|
||||
})
|
||||
@@ -485,6 +487,7 @@ export function RecentSessions() {
|
||||
open: openSessions(),
|
||||
resolvePin: (key) => hydratedItems().get(key),
|
||||
archived,
|
||||
hidden: global.sessionPreferences.hidden,
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -638,6 +641,7 @@ export function RecentSessions() {
|
||||
|
||||
removePinKey(item.key)
|
||||
forget(item.server, current.id)
|
||||
global.sessionPreferences.forget(item.server, current.id)
|
||||
})
|
||||
void startTransition(() => {
|
||||
tabs.select(tabs.addSessionTab({ server: ServerConnection.Key.make(item.server), sessionId: current.id }))
|
||||
@@ -723,6 +727,7 @@ export function RecentSessions() {
|
||||
.then(() => {
|
||||
forget(item.server, item.session.id)
|
||||
removePinKey(item.key)
|
||||
ids.forEach((id) => global.sessionPreferences.forget(item.server, id))
|
||||
notifySessionTabsRemoved({
|
||||
server: ServerConnection.Key.make(item.server),
|
||||
directory: item.session.location.directory,
|
||||
@@ -931,7 +936,8 @@ function RecentSessionTab(props: RecentSessionTabProps & { dragging?: boolean })
|
||||
)
|
||||
|
||||
// A busy session shows its progress indicator instead of the unread dot.
|
||||
const unread = createMemo(() => status.unread() && !status.loading())
|
||||
const muted = () => global.sessionPreferences.muted(server(), item().session.id)
|
||||
const unread = createMemo(() => recentRowUnread(status.unread(), status.loading(), muted()))
|
||||
|
||||
createEffect(() => props.onUnreadChange(unread()))
|
||||
|
||||
@@ -962,6 +968,12 @@ function RecentSessionTab(props: RecentSessionTabProps & { dragging?: boolean })
|
||||
{language.t("sidebar.recent.moveDown")}
|
||||
</Menu.Item>
|
||||
</Show>
|
||||
<Menu.Item onSelect={() => global.sessionPreferences.update("muted", server(), item().session.id, !muted())}>
|
||||
{language.t(muted() ? "sidebar.recent.unmute" : "sidebar.recent.mute")}
|
||||
</Menu.Item>
|
||||
<Menu.Item onSelect={() => global.sessionPreferences.update("hidden", server(), item().session.id, true)}>
|
||||
{language.t("sidebar.recent.hide")}
|
||||
</Menu.Item>
|
||||
<Menu.Separator />
|
||||
<Menu.Item onSelect={rename}>{language.t("common.rename")}</Menu.Item>
|
||||
<Menu.Item onSelect={props.onArchive}>{language.t("common.archive")}</Menu.Item>
|
||||
@@ -977,6 +989,7 @@ function RecentSessionTab(props: RecentSessionTabProps & { dragging?: boolean })
|
||||
server={server()}
|
||||
session={item().session}
|
||||
preparing={false}
|
||||
label={muted() ? language.t("sidebar.recent.muted") : undefined}
|
||||
unread={unread()}
|
||||
attention={status.attention()}
|
||||
loading={status.loading()}
|
||||
|
||||
@@ -49,9 +49,9 @@ const preferences = {
|
||||
}
|
||||
|
||||
// Each test fakes only the parts of the SDK, data store and coordinator that the notification state reads.
|
||||
const createState = (input: { sdk: object; data: object; coordinator: object }) =>
|
||||
const createState = (input: { sdk: object; data: object; coordinator: object; muted?: (id: string) => boolean }) =>
|
||||
// SAFETY: the fakes cover every member the notification state reaches in that test.
|
||||
createServerNotificationState({ key: server, ...input } as never)
|
||||
createServerNotificationState({ key: server, muted: () => false, ...input } as never)
|
||||
|
||||
beforeAll(async () => {
|
||||
// Fakes replace only the hooks this test controls. Spreading the real module keeps every other export, such as
|
||||
@@ -142,6 +142,7 @@ test.each(
|
||||
"resolved",
|
||||
"auto approve",
|
||||
"root tab",
|
||||
"muted root",
|
||||
"no tab",
|
||||
"disposed",
|
||||
].map((scenario) => ({ ...request, scenario })),
|
||||
@@ -170,6 +171,7 @@ test.each(
|
||||
|
||||
const dispose = createRoot((dispose) => {
|
||||
createState({
|
||||
muted: (id) => options.scenario === "muted root" && id === "root",
|
||||
sdk: {
|
||||
scope: ServerScope.local,
|
||||
connection: { status: () => "connected" },
|
||||
@@ -237,7 +239,7 @@ test.each(
|
||||
await Promise.all(deliveries.map((run) => run()))
|
||||
|
||||
const suppressed =
|
||||
["resolved", "disposed", "no tab"].includes(options.scenario) ||
|
||||
["resolved", "disposed", "no tab", "muted root"].includes(options.scenario) ||
|
||||
(options.scenario === "auto approve" && options.kind === "permission")
|
||||
|
||||
expect(alerts).toEqual(!suppressed && options.scenario !== "notifications disabled" ? [options.title] : [])
|
||||
|
||||
Reference in New Issue
Block a user