Skip to content

Commit 9efe433

Browse files
committed
fix: get codex sessions in windows; improve message counting logic; fix session navigation in ChatInterface
1 parent ba70ad8 commit 9efe433

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

server/openai-codex.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ export async function queryCodex(command, options = {}, ws) {
280280
// Send completion event
281281
sendMessage(ws, {
282282
type: 'codex-complete',
283-
sessionId: currentSessionId
283+
sessionId: currentSessionId,
284+
actualSessionId: thread.id
284285
});
285286

286287
} catch (error) {

server/projects.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,12 @@ async function getCodexSessions(projectPath) {
12061206
const sessionData = await parseCodexSessionFile(filePath);
12071207

12081208
// Check if this session matches the project path
1209-
if (sessionData && sessionData.cwd === projectPath) {
1209+
// Handle Windows long paths with \\?\ prefix
1210+
const sessionCwd = sessionData?.cwd || '';
1211+
const cleanSessionCwd = sessionCwd.startsWith('\\\\?\\') ? sessionCwd.slice(4) : sessionCwd;
1212+
const cleanProjectPath = projectPath.startsWith('\\\\?\\') ? projectPath.slice(4) : projectPath;
1213+
1214+
if (sessionData && (sessionData.cwd === projectPath || cleanSessionCwd === cleanProjectPath || path.relative(cleanSessionCwd, cleanProjectPath) === '')) {
12101215
sessions.push({
12111216
id: sessionData.id,
12121217
summary: sessionData.summary || 'Codex Session',
@@ -1273,12 +1278,12 @@ async function parseCodexSessionFile(filePath) {
12731278
// Count messages and extract user messages for summary
12741279
if (entry.type === 'event_msg' && entry.payload?.type === 'user_message') {
12751280
messageCount++;
1276-
if (entry.payload.text) {
1277-
lastUserMessage = entry.payload.text;
1281+
if (entry.payload.message) {
1282+
lastUserMessage = entry.payload.message;
12781283
}
12791284
}
12801285

1281-
if (entry.type === 'response_item' && entry.payload?.type === 'message') {
1286+
if (entry.type === 'response_item' && entry.payload?.type === 'message' && entry.payload.role === 'assistant') {
12821287
messageCount++;
12831288
}
12841289

src/components/ChatInterface.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,11 +2980,6 @@ function ChatInterface({ selectedProject, selectedSession, ws, sendMessage, mess
29802980
if (onReplaceTemporarySession) {
29812981
onReplaceTemporarySession(latestMessage.sessionId);
29822982
}
2983-
2984-
// Navigate to the new session to ensure URL and selectedSession are updated
2985-
if (onNavigateToSession) {
2986-
onNavigateToSession(latestMessage.sessionId);
2987-
}
29882983
}
29892984
break;
29902985

@@ -3538,8 +3533,13 @@ function ChatInterface({ selectedProject, selectedSession, ws, sendMessage, mess
35383533
}
35393534

35403535
const codexPendingSessionId = sessionStorage.getItem('pendingSessionId');
3536+
const codexActualSessionId = latestMessage.actualSessionId || codexPendingSessionId;
35413537
if (codexPendingSessionId && !currentSessionId) {
3542-
setCurrentSessionId(codexPendingSessionId);
3538+
setCurrentSessionId(codexActualSessionId);
3539+
setIsSystemSessionChange(true);
3540+
if (onNavigateToSession) {
3541+
onNavigateToSession(codexActualSessionId);
3542+
}
35433543
sessionStorage.removeItem('pendingSessionId');
35443544
console.log('Codex session complete, ID set to:', codexPendingSessionId);
35453545
}

0 commit comments

Comments
 (0)