Skip to content

Commit 6c34e24

Browse files
authored
feat(app): hide and mute sessions in Recent sidebar (#63427)
1 parent a7041d4 commit 6c34e24

11 files changed

Lines changed: 193 additions & 17 deletions

File tree

‎packages/app/src/runtime/i18n/en.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,11 @@ export const dict = {
824824
"sidebar.recent.section.recent": "Recent",
825825
"sidebar.recent.empty": "No recent sessions",
826826
"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",
827832
"sidebar.recent.unpin": "Unpin",
828833
"sidebar.recent.moveUp": "Move up",
829834
"sidebar.recent.moveDown": "Move down",

‎packages/app/src/runtime/plugin/host-apis.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,18 @@ export function createPluginAttachment(apis: HostApis) {
11181118
const result = { notification: false, sound: false }
11191119
const session = options.session
11201120

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+
11211133
await Promise.allSettled([
11221134
allowed.sound &&
11231135
global.notifications.sound(key, () => {

‎packages/app/src/runtime/server/runtime.tsx‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { createSessionMessageHandoffs } from "@/session/handoff"
3333
import { createServerNotificationState } from "@/shell/notifications/notification"
3434
import { createNotificationCoordinator } from "@/shell/notifications/coordinator"
3535
import { useCurrentRoute } from "@/shell/state/layout"
36+
import { createSessionPreferences } from "@/shell/state/session-preferences"
3637
import { useTabs } from "@/shell/tabs/tabs"
3738
import { Persist, persisted } from "@/runtime/persistence/storage"
3839
import { createDesktopData } from "./data"
@@ -52,6 +53,7 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext(
5253
init: () => {
5354
const server = useServers()
5455
const models = createGlobalModels()
56+
const sessionPreferences = createSessionPreferences()
5557
const notificationCoordinator = createNotificationCoordinator()
5658
const owner = getOwner()
5759

@@ -79,6 +81,7 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext(
7981
() => server.local(effect.conn),
8082
server.projects.forServer(effect.key),
8183
notificationCoordinator,
84+
sessionPreferences,
8285
),
8386
dispose,
8487
}),
@@ -124,6 +127,7 @@ export const { use: useGlobal, provider: GlobalProvider } = createSimpleContext(
124127
retry: serverHealth.retry,
125128
},
126129
models,
130+
sessionPreferences,
127131
/** Runs each keyed sound and system notification once across windows; notifications only while none has focus. */
128132
notifications: notificationCoordinator,
129133
/** The live controller of a server, or undefined while it is unlisted or rejects our credentials. Reactive. */
@@ -198,6 +202,7 @@ function createServerController(
198202
isLocal: Accessor<boolean>,
199203
projects: ReturnType<typeof createServerProjects>,
200204
notificationCoordinator: ReturnType<typeof createNotificationCoordinator>,
205+
sessionPreferences: ReturnType<typeof createSessionPreferences>,
201206
) {
202207
const language = useLanguage()
203208
const settings = useSettings()
@@ -254,7 +259,17 @@ function createServerController(
254259

255260
const sync = createServerSyncContext(sdk, data)
256261
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+
258273
// Owned by the server, so a first prompt's handoff outlives the draft that sent it.
259274
const handoff = createSessionMessageHandoffs({ sdk, data })
260275

‎packages/app/src/shell/commands/dialog.tsx‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getDirectory, getFilename } from "@opencode/util/path"
22
import { FileIcon } from "@opencode/ui/file-icon"
3+
import { Button } from "@opencode/ui/button"
34
import { Dialog, DialogBody } from "@opencode/ui/dialog"
45
import { Keybind } from "@opencode/ui/keybind"
56
import { Tooltip } from "@opencode/ui/tooltip"
@@ -69,6 +70,7 @@ export function CommandPaletteView(props: {
6970
close: () => void
7071
/** The row whose selection is still in progress, such as an archived session being restored. */
7172
busyEntryID?: string
73+
unhide?: (entry: CommandPaletteEntry) => (() => void) | undefined
7274
}) {
7375
const language = useLanguage()
7476
const tabs = useTabs()
@@ -110,15 +112,30 @@ export function CommandPaletteView(props: {
110112
onSelect={props.select}
111113
onClose={props.close}
112114
>
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+
}}
122139
</SearchList>
123140
</DialogBody>
124141
</Dialog>

‎packages/app/src/shell/commands/session-search.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ export function DialogSessionSearch(props: { archived?: boolean }) {
160160
select={select}
161161
close={() => dialog.close(layer?.id)}
162162
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+
}}
163174
/>
164175
)
165176
}

‎packages/app/src/shell/notifications/notification.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ export function createServerNotificationState(input: {
7979
data: Data
8080
key: ServerConnection.Key
8181
coordinator: ReturnType<typeof createNotificationCoordinator>
82+
muted: (sessionID: string) => boolean
83+
preferencesLoaded?: Promise<unknown>
8284
}) {
8385
const platform = usePlatform()
8486
const settings = useSettings()
@@ -294,6 +296,7 @@ export function createServerNotificationState(input: {
294296

295297
// Loading the session keeps a background completion visible in the server-derived unread state.
296298
const lookup = async (sessionID: string) => {
299+
if (input.preferencesLoaded) await input.preferencesLoaded
297300
const session = input.data.session.get(sessionID)
298301

299302
if (session) return session
@@ -309,7 +312,7 @@ export function createServerNotificationState(input: {
309312
if (hasRunningChild(input.data, sessionID)) return
310313

311314
void lookup(sessionID).then((session) => {
312-
if (disposed.value) return
315+
if (disposed.value || input.muted(sessionID)) return
313316

314317
if (!session) return
315318

@@ -333,7 +336,7 @@ export function createServerNotificationState(input: {
333336

334337
const handleSessionError = (sessionID: string, eventID: string) => {
335338
void lookup(sessionID).then((session) => {
336-
if (disposed.value) return
339+
if (disposed.value || input.muted(sessionID)) return
337340

338341
if (session?.parentID) return
339342

@@ -369,7 +372,7 @@ export function createServerNotificationState(input: {
369372
const category = kind === "question" || kind === "mcp-elicitation" ? "questions" : "permissions"
370373

371374
const pending = () => {
372-
if (disposed.value) return false
375+
if (disposed.value || input.muted(sessionID) || input.muted(input.data.session.root(sessionID))) return false
373376

374377
if (kind !== "permission") return input.data.session.form.list(sessionID)?.some((form) => form.id === requestID)
375378

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
}

‎packages/app/src/shell/titlebar/recent-sessions-model.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
partitionRecentSessions,
1414
recentSessionEndpoints,
1515
recentSessionKey,
16+
recentRowUnread,
1617
removePin,
1718
reorderPins,
1819
sortRecentSessions,
@@ -39,6 +40,33 @@ const item = (server: string, value: SessionInfo): RecentSession => ({
3940
session: value,
4041
})
4142

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+
4270
test("pin keys round trip server keys that contain the separator's neighbours", () => {
4371
const key = recentSessionKey("http://server.example:4096", "ses_1")
4472

‎packages/app/src/shell/titlebar/recent-sessions-model.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ export function mergeRecentSessions(
353353
* one that is not loaded yet resolves through `resolvePin`.
354354
*/
355355
export function partitionRecentSessions(input: {
356+
hidden?: (server: string, id: string) => boolean
356357
items: readonly RecentSession[]
357358
pins: readonly string[]
358359
endpoints: ReadonlyMap<string, string>
@@ -373,6 +374,8 @@ export function partitionRecentSessions(input: {
373374

374375
if (!item || item.session.time.archived !== undefined) return []
375376

377+
if (input.hidden?.(item.server, item.session.id)) return []
378+
376379
const id = identity(item)
377380

378381
if (pinnedSessions.has(id)) return []
@@ -386,6 +389,7 @@ export function partitionRecentSessions(input: {
386389

387390
// Opening a row should reuse an existing tab. Otherwise prefer a stable route regardless of fetch order.
388391
for (const item of input.items) {
392+
if (input.hidden?.(item.server, item.session.id)) continue
389393
const id = identity(item)
390394

391395
if (pinnedKeys.has(item.key) || pinnedSessions.has(id)) continue
@@ -405,3 +409,7 @@ export function partitionRecentSessions(input: {
405409

406410
return { pinned, recent: sortRecentSessions([...recent.values()]) }
407411
}
412+
413+
export function recentRowUnread(unread: boolean, loading: boolean, muted: boolean) {
414+
return unread && !loading && !muted
415+
}

0 commit comments

Comments
 (0)