Skip to content

Commit 70e9c5f

Browse files
vegerotOpenCode
andcommitted
fix(acp): list sessions across projects
Use the global session listing endpoint for ACP session discovery so clients like Zed can import OpenCode history across projects instead of only the current project. ACP session/list defines cwd as an optional filter: when clients omit cwd, they are asking for the first page of sessions known to the agent, not sessions scoped to the ACP process working directory. The previous implementation delegated to the legacy project-scoped /session endpoint, which made registry-launched ACP processes appear to have stale or empty history. Delegate to the global /experimental/session endpoint instead and keep applying cwd only when the client supplies it. Closes anomalyco#33036 Closes anomalyco#18575 Closes anomalyco#16137 Co-authored-by: opencode <[email protected]>
1 parent dd8ab39 commit 70e9c5f

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,12 @@ export function make(input: {
248248
const limit = 100
249249
const sessions = yield* request(
250250
() =>
251-
input.sdk.session.list(
251+
input.sdk.experimental.session.list(
252252
{
253253
...(params.cwd ? { directory: params.cwd } : {}),
254254
roots: true,
255+
...(cursor !== undefined && Number.isFinite(cursor) ? { cursor } : {}),
256+
limit: limit + 1,
255257
},
256258
{ throwOnError: true },
257259
),

‎packages/opencode/test/acp/service-session.test.ts‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ describe("ACP service sessions", () => {
213213
title: `Session ${index + 1}`,
214214
time: { created: index + 1, updated: index + 1 },
215215
}))
216+
const sessionListCalls: { directory?: string }[] = []
217+
const experimentalSessionListCalls: { directory?: string; roots?: boolean; cursor?: number; limit?: number }[] = []
218+
const listServerSessions = (input: { directory?: string; cursor?: number; limit?: number }) =>
219+
sessions
220+
.filter((session) => !input.directory || session.directory === input.directory)
221+
.filter((session) => input.cursor === undefined || session.time.updated < input.cursor)
222+
.toSorted((a, b) => b.time.updated - a.time.updated)
223+
.slice(0, input.limit)
216224
const sdk = {
217225
global: {
218226
event: (input?: { signal?: AbortSignal }) => Promise.resolve({ stream: events.stream(input?.signal) }),
@@ -244,10 +252,12 @@ describe("ACP service sessions", () => {
244252
session: {
245253
create: () => Promise.resolve({ data: { id: "ses_new" } }),
246254
get: () => Promise.resolve({ data: { id: "ses_loaded" } }),
247-
list: (input: { directory?: string }) =>
248-
Promise.resolve({
255+
list: (input: { directory?: string }) => {
256+
sessionListCalls.push(input)
257+
return Promise.resolve({
249258
data: input.directory ? sessions.filter((session) => session.directory === input.directory) : sessions,
250-
}),
259+
})
260+
},
251261
messages: () => Promise.resolve({ data: messages }),
252262
prompt: async (input: { sessionID: string }) => {
253263
const response = await (options?.prompt?.(input) ??
@@ -295,6 +305,14 @@ describe("ACP service sessions", () => {
295305
return Promise.resolve({ data: { id: `fork_${input.sessionID}` } })
296306
},
297307
},
308+
experimental: {
309+
session: {
310+
list: (input: { directory?: string; cursor?: number; limit?: number }) => {
311+
experimentalSessionListCalls.push(input)
312+
return Promise.resolve({ data: listServerSessions(input) })
313+
},
314+
},
315+
},
298316
mcp: {
299317
add: (input: { name?: string }) => {
300318
if (input.name) mcpAdds.push(input.name)
@@ -330,6 +348,8 @@ describe("ACP service sessions", () => {
330348
summarizes,
331349
usageUpdates,
332350
events,
351+
sessionListCalls,
352+
experimentalSessionListCalls,
333353
}
334354
}
335355

@@ -418,6 +438,15 @@ describe("ACP service sessions", () => {
418438
])
419439
})
420440

441+
it("lists sessions through the global session endpoint", async () => {
442+
const { service, sessionListCalls, experimentalSessionListCalls } = makeService()
443+
const result = await Effect.runPromise(service.listSessions({}))
444+
445+
expect(result.sessions[0]?.sessionId).toBe("ses_102")
446+
expect(sessionListCalls).toEqual([])
447+
expect(experimentalSessionListCalls).toEqual([{ roots: true, limit: 101 }])
448+
})
449+
421450
it("lists sessions sorted by updated time with cursor support", async () => {
422451
const { service } = makeService()
423452
const first = await Effect.runPromise(service.listSessions({ cwd: "/workspace" }))
@@ -1318,6 +1347,11 @@ describe("ACP service sessions", () => {
13181347
list: () => Promise.resolve({ data: [] }),
13191348
prompt: () => Promise.reject({ name: "ProviderAuthError", data: { providerID: "test" } }),
13201349
},
1350+
experimental: {
1351+
session: {
1352+
list: () => Promise.resolve({ data: [] }),
1353+
},
1354+
},
13211355
mcp: {
13221356
add: () => Promise.resolve({ data: {} }),
13231357
},

0 commit comments

Comments
 (0)