Skip to content

Commit f1ce79f

Browse files
committed
fix
1 parent f53ebf0 commit f1ce79f

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

codex-cli/src/cli.tsx

+11-10
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ initLogger();
5353
const sessions: Array<{ id: string }> = [];
5454
if (fs.existsSync(sessionsRoot)) {
5555
for (const file of fs.readdirSync(sessionsRoot)) {
56-
const m = file.match(/^rollout-([^.]+)\.json$/);
56+
const m = file.match(/^(.+)\.json$/);
5757
if (m && m[1]) {
5858
sessions.push({ id: m[1] });
5959
}
6060
}
6161
}
6262
for (const session of sessions) {
63-
const sessionPath = path.join(sessionsRoot, `rollout-${session.id}.json`);
63+
const sessionPath = path.join(sessionsRoot, `${session.id}.json`);
6464
const stats = fs.statSync(sessionPath);
6565
const size = stats.size;
6666
const formattedDate = new Intl.DateTimeFormat(undefined, {
@@ -351,15 +351,17 @@ if (
351351
console.error("session id required");
352352
process.exit(1);
353353
}
354+
// Use provided session id for new or resuming sessions
355+
if (cli.flags.session) {
356+
setSessionId(sessionIdFlag);
357+
}
354358

355359
let targetFile: string | undefined;
356360
if (fs.existsSync(sessionsDir)) {
357-
const files = fs
358-
.readdirSync(sessionsDir)
359-
.filter((f) => f.endsWith(`-${sessionIdFlag}.json`));
360-
if (files.length > 0) {
361-
files.sort();
362-
targetFile = path.join(sessionsDir, files[files.length - 1] ?? "");
361+
const candidateFile = `${sessionIdFlag}.json`;
362+
const candidatePath = path.join(sessionsDir, candidateFile);
363+
if (fs.existsSync(candidatePath)) {
364+
targetFile = candidatePath;
363365
}
364366
}
365367
if (!targetFile) {
@@ -381,8 +383,7 @@ if (
381383
console.error(`error loading session ${sessionIdFlag}: ${e}`);
382384
process.exit(1);
383385
}
384-
// Start or resume the named session
385-
setSessionId(sessionIdFlag);
386+
// Resume the named session (session id already set above)
386387
}
387388

388389
if (cli.flags.sessionPath) {

codex-cli/src/utils/storage/save-rollout.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function saveRolloutAsync(
1616
await fs.mkdir(SESSIONS_ROOT, { recursive: true });
1717

1818
const timestamp = new Date().toISOString();
19-
const filename = `rollout-${sessionId}.json`;
19+
const filename = `${sessionId}.json`;
2020
const filePath = path.join(SESSIONS_ROOT, filename);
2121
const config = loadConfig();
2222

codex-cli/tests/cli-session.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe("codex session CLI", () => {
5555
const sessId = "testsess";
5656
const sessDir = path.join(tmpHome, sessionsDirName);
5757
fs.mkdirSync(sessDir, { recursive: true });
58-
const filename = `rollout-${sessId}.json`;
58+
const filename = `${sessId}.json`;
5959
const filePath = path.join(sessDir, filename);
6060
const fileContent = JSON.stringify(
6161
{

0 commit comments

Comments
 (0)