GeezerVison is showing github.com — feat(app): hide and mute sessions in Recent sidebar (#63427) · drpr/opencode@6c34e24
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/src/runtime/i18n/en.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -824,6 +824,11 @@ export const dict = { | 824 | 824 | "sidebar.recent.section.recent": "Recent", | 825 | 825 | "sidebar.recent.empty": "No recent sessions", | 826 | 826 | "sidebar.recent.pin": "Pin", | | 827 | + "sidebar.recent.mute": "Mute", | | 828 | + "sidebar.recent.muted": "Muted", | | 829 | + "sidebar.recent.unmute": "Unmute", | | 830 | + "sidebar.recent.hide": "Hide", | | 831 | + "sidebar.recent.unhide": "Unhide", | 827 | 832 | "sidebar.recent.unpin": "Unpin", | 828 | 833 | "sidebar.recent.moveUp": "Move up", | 829 | 834 | "sidebar.recent.moveDown": "Move down", | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/runtime/plugin/host-apis.tsx +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1118,6 +1118,18 @@ export function createPluginAttachment(apis: HostApis) { | 1118 | 1118 | const result = { notification: false, sound: false } | 1119 | 1119 | const session = options.session | 1120 | 1120 |
| | 1121 | + if (session) { | | 1122 | + await global.sessionPreferences.ready.promise | | 1123 | + | | 1124 | + const root = global.serverCtx(ServerConnection.Key.make(session.server))?.data.session.root(session.id) ?? session.id | | 1125 | + | | 1126 | + if ( | | 1127 | + global.sessionPreferences.muted(session.server, session.id) || | | 1128 | + global.sessionPreferences.muted(session.server, root) | | 1129 | + ) | | 1130 | + return result | | 1131 | + } | | 1132 | + | 1121 | 1133 | await Promise.allSettled([ | 1122 | 1134 | allowed.sound && | 1123 | 1135 | global.notifications.sound(key, () => { | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/runtime/server/runtime.tsx +16-1Lines changed: 16 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,6 +33,7 @@ import { createSessionMessageHandoffs } from "@/session/handoff" | 33 | 33 | import { createServerNotificationState } from "@/shell/notifications/notification" | 34 | 34 | import { createNotificationCoordinator } from "@/shell/notifications/coordinator" | 35 | 35 | import { useCurrentRoute } from "@/shell/state/layout" | | 36 | +import { createSessionPreferences } from "@/shell/state/session-preferences" | 36 | 37 | import { useTabs } from "@/shell/tabs/tabs" | 37 | 38 | import { Persist, persisted } from "@/runtime/persistence/storage" | 38 | 39 | import { createDesktopData } from "./data" | @@ -52,6 +53,7 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext( | 52 | 53 | init: () => { | 53 | 54 | const server = useServers() | 54 | 55 | const models = createGlobalModels() | | 56 | + const sessionPreferences = createSessionPreferences() | 55 | 57 | const notificationCoordinator = createNotificationCoordinator() | 56 | 58 | const owner = getOwner() | 57 | 59 |
| @@ -79,6 +81,7 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext( | 79 | 81 | () => server.local(effect.conn), | 80 | 82 | server.projects.forServer(effect.key), | 81 | 83 | notificationCoordinator, | | 84 | + sessionPreferences, | 82 | 85 | ), | 83 | 86 | dispose, | 84 | 87 | }), | @@ -124,6 +127,7 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext( | 124 | 127 | retry: serverHealth.retry, | 125 | 128 | }, | 126 | 129 | models, | | 130 | + sessionPreferences, | 127 | 131 | /** Runs each keyed sound and system notification once across windows; notifications only while none has focus. */ | 128 | 132 | notifications: notificationCoordinator, | 129 | 133 | /** The live controller of a server, or undefined while it is unlisted or rejects our credentials. Reactive. */ | @@ -198,6 +202,7 @@ function createServerController( | 198 | 202 | isLocal: Accessor<boolean>, | 199 | 203 | projects: ReturnType<typeof createServerProjects>, | 200 | 204 | notificationCoordinator: ReturnType<typeof createNotificationCoordinator>, | | 205 | + sessionPreferences: ReturnType<typeof createSessionPreferences>, | 201 | 206 | ) { | 202 | 207 | const language = useLanguage() | 203 | 208 | const settings = useSettings() | @@ -254,7 +259,17 @@ function createServerController( | 254 | 259 |
| 255 | 260 | const sync = createServerSyncContext(sdk, data) | 256 | 261 | const autoApprove = createPermissionAutoApprover({ sdk, data }) | 257 | | - const notification = createServerNotificationState({ sdk, data, key: connKey, coordinator: notificationCoordinator }) | | 262 | + onCleanup(data.on("session.deleted", (event) => sessionPreferences.forget(connKey, event.data.sessionID))) | | 263 | + | | 264 | + const notification = createServerNotificationState({ | | 265 | + sdk, | | 266 | + data, | | 267 | + key: connKey, | | 268 | + coordinator: notificationCoordinator, | | 269 | + muted: (id) => sessionPreferences.muted(connKey, id), | | 270 | + preferencesLoaded: sessionPreferences.ready.promise, | | 271 | + }) | | 272 | + | 258 | 273 | // Owned by the server, so a first prompt's handoff outlives the draft that sent it. | 259 | 274 | const handoff = createSessionMessageHandoffs({ sdk, data }) | 260 | 275 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/shell/commands/dialog.tsx +26-9Lines changed: 26 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { getDirectory, getFilename } from "@opencode/util/path" | 2 | 2 | import { FileIcon } from "@opencode/ui/file-icon" | | 3 | +import { Button } from "@opencode/ui/button" | 3 | 4 | import { Dialog, DialogBody } from "@opencode/ui/dialog" | 4 | 5 | import { Keybind } from "@opencode/ui/keybind" | 5 | 6 | import { Tooltip } from "@opencode/ui/tooltip" | @@ -69,6 +70,7 @@ export function CommandPaletteView(props: { | 69 | 70 | close: () => void | 70 | 71 | /** The row whose selection is still in progress, such as an archived session being restored. */ | 71 | 72 | busyEntryID?: string | | 73 | + unhide?: (entry: CommandPaletteEntry) => (() => void) | undefined | 72 | 74 | }) { | 73 | 75 | const language = useLanguage() | 74 | 76 | const tabs = useTabs() | @@ -110,15 +112,30 @@ export function CommandPaletteView(props: { | 110 | 112 | onSelect={props.select} | 111 | 113 | onClose={props.close} | 112 | 114 | > | 113 | | - {(item, row) => ( | 114 | | - <PaletteRow | 115 | | - row={row} | 116 | | - item={item()} | 117 | | - language={language} | 118 | | - sessionOpen={sessionOpen(item())} | 119 | | - busy={props.busyEntryID === item().id} | 120 | | - /> | 121 | | - )} | | 115 | + {(item, row) => { | | 116 | + const entry = () => ( | | 117 | + <PaletteRow | | 118 | + row={row} | | 119 | + item={item()} | | 120 | + language={language} | | 121 | + sessionOpen={sessionOpen(item())} | | 122 | + busy={props.busyEntryID === item().id} | | 123 | + /> | | 124 | + ) | | 125 | + | | 126 | + return ( | | 127 | + <Show when={props.unhide?.(item())} fallback={entry()}> | | 128 | + {(unhide) => ( | | 129 | + <div class="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-1"> | | 130 | + {entry()} | | 131 | + <Button size="small" variant="ghost-muted" onClick={() => unhide()()}> | | 132 | + {language.t("sidebar.recent.unhide")} | | 133 | + </Button> | | 134 | + </div> | | 135 | + )} | | 136 | + </Show> | | 137 | + ) | | 138 | + }} | 122 | 139 | </SearchList> | 123 | 140 | </DialogBody> | 124 | 141 | </Dialog> | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/shell/commands/session-search.tsx +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -160,6 +160,17 @@ export function DialogSessionSearch(props: { archived?: boolean }) { | 160 | 160 | select={select} | 161 | 161 | close={() => dialog.close(layer?.id)} | 162 | 162 | busyEntryID={selectSessionRestoreEntryID(searchState())} | | 163 | + unhide={(entry) => { | | 164 | + const server = entry.server | | 165 | + const id = entry.sessionID | | 166 | + | | 167 | + if (!server || !id || !global.sessionPreferences.hidden(server, id)) return | | 168 | + | | 169 | + return () => { | | 170 | + global.sessionPreferences.update("hidden", server, id, false) | | 171 | + dialog.close(layer?.id) | | 172 | + } | | 173 | + }} | 163 | 174 | /> | 164 | 175 | ) | 165 | 176 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/shell/notifications/notification.tsx +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,6 +79,8 @@ export function createServerNotificationState(input: { | 79 | 79 | data: Data | 80 | 80 | key: ServerConnection.Key | 81 | 81 | coordinator: ReturnType<typeof createNotificationCoordinator> | | 82 | + muted: (sessionID: string) => boolean | | 83 | + preferencesLoaded?: Promise<unknown> | 82 | 84 | }) { | 83 | 85 | const platform = usePlatform() | 84 | 86 | const settings = useSettings() | @@ -294,6 +296,7 @@ export function createServerNotificationState(input: { | 294 | 296 |
| 295 | 297 | // Loading the session keeps a background completion visible in the server-derived unread state. | 296 | 298 | const lookup = async (sessionID: string) => { | | 299 | + if (input.preferencesLoaded) await input.preferencesLoaded | 297 | 300 | const session = input.data.session.get(sessionID) | 298 | 301 |
| 299 | 302 | if (session) return session | @@ -309,7 +312,7 @@ export function createServerNotificationState(input: { | 309 | 312 | if (hasRunningChild(input.data, sessionID)) return | 310 | 313 |
| 311 | 314 | void lookup(sessionID).then((session) => { | 312 | | - if (disposed.value) return | | 315 | + if (disposed.value || input.muted(sessionID)) return | 313 | 316 |
| 314 | 317 | if (!session) return | 315 | 318 |
| @@ -333,7 +336,7 @@ export function createServerNotificationState(input: { | 333 | 336 |
| 334 | 337 | const handleSessionError = (sessionID: string, eventID: string) => { | 335 | 338 | void lookup(sessionID).then((session) => { | 336 | | - if (disposed.value) return | | 339 | + if (disposed.value || input.muted(sessionID)) return | 337 | 340 |
| 338 | 341 | if (session?.parentID) return | 339 | 342 |
| @@ -369,7 +372,7 @@ export function createServerNotificationState(input: { | 369 | 372 | const category = kind === "question" || kind === "mcp-elicitation" ? "questions" : "permissions" | 370 | 373 |
| 371 | 374 | const pending = () => { | 372 | | - if (disposed.value) return false | | 375 | + if (disposed.value || input.muted(sessionID) || input.muted(input.data.session.root(sessionID))) return false | 373 | 376 |
| 374 | 377 | if (kind !== "permission") return input.data.session.form.list(sessionID)?.some((form) => form.id === requestID) | 375 | 378 |
| |
Collapse file Copy file name to clipboard +62Lines changed: 62 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { Schema } from "effect" | | 2 | +import { createMemo } from "solid-js" | | 3 | +import { Persistence } from "@/runtime/persistence/schema" | | 4 | +import { Persist, persisted } from "@/runtime/persistence/storage" | | 5 | +import { useServers } from "@/runtime/server/registry" | | 6 | +import { | | 7 | + recentSessionEndpoints, | | 8 | + recentSessionKey, | | 9 | + removePin, | | 10 | + splitRecentSessionKey, | | 11 | +} from "@/shell/titlebar/recent-sessions-model" | | 12 | + | | 13 | +const Preferences = Persistence.struct({ | | 14 | + hidden: Persistence.array(Schema.String), | | 15 | + muted: Persistence.array(Schema.String), | | 16 | +}) | | 17 | + | | 18 | +export function createSessionPreferences() { | | 19 | + const servers = useServers() | | 20 | + const endpoints = createMemo(() => recentSessionEndpoints(servers.list, servers.ownUrl())) | | 21 | + | | 22 | + const [state, set, , ready] = persisted({ ...Persist.global("session.preferences"), sync: true }, Preferences, { | | 23 | + hidden: [], | | 24 | + muted: [], | | 25 | + }) | | 26 | + | | 27 | + const key = (server: string, id: string) => recentSessionKey(endpoints().get(server) ?? server, id) | | 28 | + | | 29 | + const identities = (stored: readonly string[]) => | | 30 | + new Set(stored.map((value) => { | | 31 | + const session = splitRecentSessionKey(value) | | 32 | + | | 33 | + return session ? key(session.server, session.sessionID) : value | | 34 | + })) | | 35 | + | | 36 | + const keys = { | | 37 | + hidden: createMemo(() => identities(state.hidden)), | | 38 | + muted: createMemo(() => identities(state.muted)), | | 39 | + } | | 40 | + | | 41 | + const update = (kind: keyof typeof keys, server: string, id: string, enabled: boolean) => { | | 42 | + const apply = () => { | | 43 | + if (keys[kind]().has(key(server, id)) === enabled) return | | 44 | + const value = recentSessionKey(server, id) | | 45 | + set(kind, (current) => (enabled ? [...current, value] : removePin(current, value, endpoints()))) | | 46 | + } | | 47 | + | | 48 | + if (ready()) return apply() | | 49 | + void ready.promise?.then(apply) | | 50 | + } | | 51 | + | | 52 | + return { | | 53 | + ready, | | 54 | + hidden: (server: string, id: string) => keys.hidden().has(key(server, id)), | | 55 | + muted: (server: string, id: string) => keys.muted().has(key(server, id)), | | 56 | + update, | | 57 | + forget(server: string, id: string) { | | 58 | + update("hidden", server, id, false) | | 59 | + update("muted", server, id, false) | | 60 | + }, | | 61 | + } | | 62 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/shell/titlebar/recent-sessions-model.test.ts +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ import { | 13 | 13 | partitionRecentSessions, | 14 | 14 | recentSessionEndpoints, | 15 | 15 | recentSessionKey, | | 16 | + recentRowUnread, | 16 | 17 | removePin, | 17 | 18 | reorderPins, | 18 | 19 | sortRecentSessions, | @@ -39,6 +40,33 @@ const item = (server: string, value: SessionInfo): RecentSession => ({ | 39 | 40 | session: value, | 40 | 41 | }) | 41 | 42 |
| | 43 | +test("hiding filters hydrated pins and recent rows only on their server", () => { | | 44 | + const pin = item("local", session("pinned", 1)) | | 45 | + const recent = item("local", session("recent", 2)) | | 46 | + const remote = item("remote", recent.session) | | 47 | + | | 48 | + const input = { | | 49 | + items: [recent, remote], | | 50 | + pins: [pin.key], | | 51 | + endpoints: new Map<string, string>(), | | 52 | + open: new Set<string>(), | | 53 | + archived: () => false, | | 54 | + resolvePin: () => pin, | | 55 | + } | | 56 | + | | 57 | + expect(partitionRecentSessions({ ...input, hidden: (server) => server === "local" })).toEqual({ | | 58 | + pinned: [], | | 59 | + recent: [remote], | | 60 | + }) | | 61 | + expect(partitionRecentSessions(input).pinned).toEqual([pin]) | | 62 | +}) | | 63 | + | | 64 | +test("muting hides the unread dot until unmuted", () => { | | 65 | + expect(recentRowUnread(true, false, true)).toBe(false) | | 66 | + expect(recentRowUnread(true, false, false)).toBe(true) | | 67 | + expect(recentRowUnread(true, true, false)).toBe(false) | | 68 | +}) | | 69 | + | 42 | 70 | test("pin keys round trip server keys that contain the separator's neighbours", () => { | 43 | 71 | const key = recentSessionKey("http://server.example:4096", "ses_1") | 44 | 72 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/shell/titlebar/recent-sessions-model.ts +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -353,6 +353,7 @@ export function mergeRecentSessions( | 353 | 353 | * one that is not loaded yet resolves through `resolvePin`. | 354 | 354 | */ | 355 | 355 | export function partitionRecentSessions(input: { | | 356 | + hidden?: (server: string, id: string) => boolean | 356 | 357 | items: readonly RecentSession[] | 357 | 358 | pins: readonly string[] | 358 | 359 | endpoints: ReadonlyMap<string, string> | @@ -373,6 +374,8 @@ export function partitionRecentSessions(input: { | 373 | 374 |
| 374 | 375 | if (!item || item.session.time.archived !== undefined) return [] | 375 | 376 |
| | 377 | + if (input.hidden?.(item.server, item.session.id)) return [] | | 378 | + | 376 | 379 | const id = identity(item) | 377 | 380 |
| 378 | 381 | if (pinnedSessions.has(id)) return [] | @@ -386,6 +389,7 @@ export function partitionRecentSessions(input: { | 386 | 389 |
| 387 | 390 | // Opening a row should reuse an existing tab. Otherwise prefer a stable route regardless of fetch order. | 388 | 391 | for (const item of input.items) { | | 392 | + if (input.hidden?.(item.server, item.session.id)) continue | 389 | 393 | const id = identity(item) | 390 | 394 |
| 391 | 395 | if (pinnedKeys.has(item.key) || pinnedSessions.has(id)) continue | @@ -405,3 +409,7 @@ export function partitionRecentSessions(input: { | 405 | 409 |
| 406 | 410 | return { pinned, recent: sortRecentSessions([...recent.values()]) } | 407 | 411 | } | | 412 | + | | 413 | +export function recentRowUnread(unread: boolean, loading: boolean, muted: boolean) { | | 414 | + return unread && !loading && !muted | | 415 | +} |
|