Skip to content
Closed
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
20 changes: 19 additions & 1 deletion plugins/codex/scripts/lib/codex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -658,19 +658,37 @@ function sourceContentSha256(sourcePath) {
return crypto.createHash("sha256").update(fs.readFileSync(sourcePath)).digest("hex");
}

function normalizeLedgerPath(sourcePath) {
// On Windows, Codex records ledger paths with the \\?\ extended-length
// prefix (e.g. \\?\C:\Users\...), while fs.realpathSync returns the plain
// form. Strip the prefix (including the \\?\UNC\ variant) and compare
// case-insensitively so ledger records match realpath output.
let normalized = String(sourcePath);
if (process.platform === "win32") {
if (normalized.startsWith("\\\\?\\UNC\\")) {
normalized = `\\\\${normalized.slice(8)}`;
} else if (normalized.startsWith("\\\\?\\")) {
normalized = normalized.slice(4);
}
return normalized.toLowerCase();
}
return normalized;
}

function importedThreadIdForSource(sourcePath) {
const ledgerPath = path.join(resolveCodexHome(), "external_agent_session_imports.json");
if (!fs.existsSync(ledgerPath)) {
return null;
}
const ledger = readJsonFile(ledgerPath);
const canonicalSource = fs.realpathSync(sourcePath);
const normalizedSource = normalizeLedgerPath(canonicalSource);
const contentSha256 = sourceContentSha256(canonicalSource);
const records = Array.isArray(ledger?.records) ? ledger.records : [];
const match = records
.filter(
(record) =>
record?.source_path === canonicalSource &&
normalizeLedgerPath(record?.source_path) === normalizedSource &&
record?.content_sha256 === contentSha256 &&
typeof record?.imported_thread_id === "string"
)
Expand Down