Repository navigation
feat(app): pin sessions to the top of Home #57788
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { describe, expect, test } from "bun:test" | ||
| import { ServerConnection } from "@/runtime/server/registry" | ||
| import { pinnedIDs, withPin, withoutPins } from "./pins" | ||
|
|
||
| const server = ServerConnection.Key.make("sidecar") | ||
|
|
||
| describe("session pins", () => { | ||
| test("keeps the order pins were added in and ignores a repeat", () => { | ||
| const pins = withPin(withPin({}, server, "ses_a"), server, "ses_b") | ||
|
|
||
| expect(pinnedIDs(pins, server)).toEqual(["ses_a", "ses_b"]) | ||
| expect(withPin(pins, server, "ses_a")).toBe(pins) | ||
| }) | ||
|
|
||
| test("keeps the remaining order when unpinning and drops the server once empty", () => { | ||
| const pins = withPin(withPin({}, server, "ses_a"), server, "ses_b") | ||
|
|
||
| expect(pinnedIDs(withoutPins(pins, server, ["ses_a"]), server)).toEqual(["ses_b"]) | ||
| expect(withoutPins(pins, server, ["ses_a", "ses_b"])).toEqual({}) | ||
| expect(withoutPins(pins, server, ["ses_missing"])).toBe(pins) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { createSimpleContext } from "@opencode/ui/context" | ||
| import { Schema } from "effect" | ||
| import { reconcile } from "solid-js/store" | ||
| import { Persistence } from "@/runtime/persistence/schema" | ||
| import { Persist, persisted } from "@/runtime/persistence/storage" | ||
| import type { ServerConnection } from "@/runtime/server/registry" | ||
|
|
||
| // Session IDs per server, in the order they were pinned. | ||
| export const PinnedSessions = Persistence.record(Persistence.array(Schema.String)) | ||
|
|
||
| export type PinnedSessions = typeof PinnedSessions.Type | ||
|
|
||
| export function pinnedIDs(pins: PinnedSessions, server: ServerConnection.Key) { | ||
| return pins[server] ?? [] | ||
| } | ||
|
|
||
| export function isPinned(pins: PinnedSessions, server: ServerConnection.Key, sessionID: string) { | ||
| return pinnedIDs(pins, server).includes(sessionID) | ||
| } | ||
|
|
||
| export function withPin(pins: PinnedSessions, server: ServerConnection.Key, sessionID: string) { | ||
| const ids = pinnedIDs(pins, server) | ||
|
|
||
| if (ids.includes(sessionID)) return pins | ||
|
|
||
| return { ...pins, [server]: [...ids, sessionID] } | ||
| } | ||
|
|
||
| export function withoutPins(pins: PinnedSessions, server: ServerConnection.Key, sessionIDs: readonly string[]) { | ||
| const current = pinnedIDs(pins, server) | ||
| const ids = current.filter((id) => !sessionIDs.includes(id)) | ||
|
|
||
| if (ids.length === current.length) return pins | ||
|
|
||
| if (ids.length > 0) return { ...pins, [server]: ids } | ||
|
|
||
| const next = { ...pins } | ||
|
|
||
| delete next[server] | ||
|
|
||
| return next | ||
| } | ||
|
|
||
| export const { use: useSessionPins, provider: SessionPinsProvider } = createSimpleContext({ | ||
| name: "SessionPins", | ||
| gate: false, | ||
| init: () => { | ||
| const [store, setStore] = persisted(Persist.global("home.sessions.pinned"), PinnedSessions, {}) | ||
|
|
||
| return { | ||
| ids: (server: ServerConnection.Key) => pinnedIDs(store, server), | ||
| pinned: (server: ServerConnection.Key, sessionID: string) => isPinned(store, server, sessionID), | ||
| toggle(server: ServerConnection.Key, sessionID: string) { | ||
| setStore( | ||
| reconcile( | ||
| isPinned(store, server, sessionID) | ||
| ? withoutPins(store, server, [sessionID]) | ||
| : withPin(store, server, sessionID), | ||
| ), | ||
| ) | ||
| }, | ||
| forget(server: ServerConnection.Key, sessionIDs: readonly string[]) { | ||
| setStore(reconcile(withoutPins(store, server, sessionIDs))) | ||
| }, | ||
| } | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be dropped. The new
home.spec.tscase already checks pin order and that unpinning removes the group, andpackages/app/AGENTS.mdasks not to unit-test what an e2e keeper already proves. Without this file,withPin,withoutPinsandpinnedIDswould not need to be exported frompins.tsxeither.