Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions src/CodexAcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,21 +1083,16 @@ export class CodexAcpClient {
"appServer",
"unknown",
];
const requestedCwd = request.cwd?.trim() ?? null;
const filterByCwd = (thread: Thread): boolean => {
if (!requestedCwd) return true;
if (isAbsolutePathLike(requestedCwd)) {
return arePathsEqual(thread.cwd, requestedCwd);
}
return arePathBasenamesEqual(thread.cwd, requestedCwd);
};
const requestedCwd = request.cwd?.trim() || null;

const preferredProvider = this.getModelProvider();
const modelProviders = preferredProvider ? [preferredProvider] : [];
const listResponse = await this.codexClient.threadList({
cursor: request.cursor ?? null,
modelProviders: modelProviders,
sourceKinds: sourceKinds,
cwd: requestedCwd,
useStateDbOnly: true,
});

const mapThreadToSession = (thread: Thread) => ({
Expand All @@ -1107,25 +1102,8 @@ export class CodexAcpClient {
updatedAt: new Date(thread.updatedAt * 1000).toISOString(),
});

if (listResponse.data.length === 0) {
const diagnostics = await this.runSessionListDiagnostics();
logger.log("Session list diagnostics", diagnostics);
}

let sessions = listResponse.data.map(mapThreadToSession);
if (requestedCwd) {
const filtered = listResponse.data
.filter(filterByCwd)
.map(mapThreadToSession);
if (filtered.length > 0 || isAbsolutePathLike(requestedCwd)) {
sessions = filtered;
} else {
logger.log("Ignoring non-absolute cwd filter for session/list", {cwd: requestedCwd});
}
}

return {
sessions,
sessions: listResponse.data.map(mapThreadToSession),
nextCursor: listResponse.nextCursor ?? null,
};
}
Expand Down
57 changes: 11 additions & 46 deletions src/__tests__/CodexACPAgent/list-sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,8 @@ describe("CodexACPAgent - list sessions", () => {
name: null,
turns: [],
};
const threadB: Thread = {
id: "sess-2",
sessionId: "sess-2",
parentThreadId: null,
threadSource: null,
forkedFromId: null,
preview: "Other session",
ephemeral: false,
modelProvider: "openai",
createdAt: 300,
updatedAt: 400,
recencyAt: null,
status: { type: "idle" },
path: null,
cwd: "/repo/other",
cliVersion: "0.0.0",
section: null,
sectionEnteredAt: null,
source: "cli",
agentNickname: null,
agentRole: null,
gitInfo: null,
name: null,
turns: [],
};

codexAppServerClient.threadList = vi.fn().mockResolvedValue({
data: [threadA, threadB],
data: [threadA],
nextCursor: "next-cursor",
});
codexAppServerClient.threadLoadedList = vi.fn().mockResolvedValue({
Expand All @@ -87,13 +61,15 @@ describe("CodexACPAgent - list sessions", () => {
"appServer",
"unknown",
],
cwd: "/repo/project",
useStateDbOnly: true,
}));
await expect(JSON.stringify(response, null, 2)).toMatchFileSnapshot(
"data/list-sessions.json"
);
});

it("normalizes Windows cwd filters before comparing absolute paths", async () => {
it("forwards absolute Windows cwd filters to the app server", async () => {
const fixture = createCodexMockTestFixture();
const codexAcpAgent = fixture.getCodexAcpAgent();
const codexAcpClient = fixture.getCodexAcpClient();
Expand All @@ -115,7 +91,7 @@ describe("CodexACPAgent - list sessions", () => {
recencyAt: null,
status: { type: "idle" },
path: null,
cwd: "D:\\workspace\\sample-project\\",
cwd: "d:/workspace/sample-project",
cliVersion: "0.0.0",
section: null,
sectionEnteredAt: null,
Expand All @@ -126,16 +102,8 @@ describe("CodexACPAgent - list sessions", () => {
name: null,
turns: [],
};
const otherThread: Thread = {
...matchingThread,
id: "sess-other",
sessionId: "sess-other",
preview: "Other session",
cwd: "D:\\workspace\\other-project",
};

codexAppServerClient.threadList = vi.fn().mockResolvedValue({
data: [matchingThread, otherThread],
data: [matchingThread],
nextCursor: null,
});

Expand All @@ -146,17 +114,14 @@ describe("CodexACPAgent - list sessions", () => {

expect(response.sessions).toEqual([{
sessionId: "sess-win",
cwd: "D:\\workspace\\sample-project\\",
cwd: "d:/workspace/sample-project",
title: "Windows session",
updatedAt: "1970-01-01T00:03:20.000Z",
}]);

const basenameResponse = await codexAcpAgent.listSessions({
cwd: "sample-project",
cursor: null,
});

expect(basenameResponse.sessions.map(session => session.sessionId)).toEqual(["sess-win"]);
expect(codexAppServerClient.threadList).toHaveBeenCalledWith(expect.objectContaining({
cwd: "d:/workspace/sample-project",
useStateDbOnly: true,
}));
});

it("should prefer the explicit thread name as the session title", async () => {
Expand Down