Skip to content

Commit 8add170

Browse files
committed
fix(acp): use global session list in unstable_listSessions
`unstable_listSessions` called `sdk.session.list()` which is scoped to the current project via `Instance.project.id`. Running ACP from `/` or any non-git directory resolves to project `"global"`, hiding sessions from git projects. Switch to `sdk.experimental.session.list()` which calls `Session.listGlobal()` — a SQLite query across all projects. Also delegate sorting, cursor, and limit to the server instead of doing it in-memory. Closes anomalyco#18575
1 parent 10a3d6c commit 8add170

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎packages/opencode/src/acp/agent.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,19 +671,22 @@ export namespace ACP {
671671
const cursor = params.cursor ? Number(params.cursor) : undefined
672672
const limit = 100
673673

674-
const sessions = await this.sdk.session
674+
// Use global session list so sessions from all projects are returned,
675+
// not just the current project scoped by Instance.project.id
676+
const sessions = await this.sdk.experimental.session
675677
.list(
676678
{
677679
directory: params.cwd ?? undefined,
678680
roots: true,
681+
cursor,
682+
limit: limit + 1,
679683
},
680684
{ throwOnError: true },
681685
)
682686
.then((x) => x.data ?? [])
683687

684-
const sorted = sessions.toSorted((a, b) => b.time.updated - a.time.updated)
685-
const filtered = cursor ? sorted.filter((s) => s.time.updated < cursor) : sorted
686-
const page = filtered.slice(0, limit)
688+
const hasMore = sessions.length > limit
689+
const page = hasMore ? sessions.slice(0, limit) : sessions
687690

688691
const entries: SessionInfo[] = page.map((session) => ({
689692
sessionId: session.id,
@@ -693,7 +696,7 @@ export namespace ACP {
693696
}))
694697

695698
const last = page[page.length - 1]
696-
const next = filtered.length > limit && last ? String(last.time.updated) : undefined
699+
const next = hasMore && last ? String(last.time.updated) : undefined
697700

698701
const response: ListSessionsResponse = {
699702
sessions: entries,

0 commit comments

Comments
 (0)