Initial commit

Signed-off-by: Ilan Bigio <ilan@openai.com>
This commit is contained in:
Ilan Bigio
2025-04-16 12:56:08 -04:00
commit 59a180ddec
163 changed files with 30587 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
/* eslint-disable no-console */
import type { ResponseItem } from "openai/resources/responses/responses";
import { loadConfig } from "../config";
import fs from "fs/promises";
import os from "os";
import path from "path";
const SESSIONS_ROOT = path.join(os.homedir(), ".codex", "sessions");
async function saveRolloutToHomeSessions(
items: Array<ResponseItem>,
): Promise<void> {
await fs.mkdir(SESSIONS_ROOT, { recursive: true });
const sessionId = crypto.randomUUID();
const timestamp = new Date().toISOString();
const ts = timestamp.replace(/[:.]/g, "-").slice(0, 10);
const filename = `rollout-${ts}-${sessionId}.json`;
const filePath = path.join(SESSIONS_ROOT, filename);
const config = loadConfig();
try {
await fs.writeFile(
filePath,
JSON.stringify(
{
session: {
timestamp,
id: sessionId,
instructions: config.instructions,
},
items,
},
null,
2,
),
"utf8",
);
} catch (error) {
console.error(`Failed to save rollout to ${filePath}: `, error);
}
}
let debounceTimer: NodeJS.Timeout | null = null;
let pendingItems: Array<ResponseItem> | null = null;
export function saveRollout(items: Array<ResponseItem>): void {
pendingItems = items;
if (debounceTimer) {
clearTimeout(debounceTimer);
}
debounceTimer = setTimeout(() => {
if (pendingItems) {
saveRolloutToHomeSessions(pendingItems).catch(() => {});
pendingItems = null;
}
debounceTimer = null;
}, 2000);
}