refactor: add handling for internal Codex metadata in conversation search

This commit is contained in:
Haileyesus
2026-04-27 22:30:31 +03:00
parent 5af2b719e2
commit 8570bd7bab

View File

@@ -100,6 +100,15 @@ const INTERNAL_CONTENT_PREFIXES = [
'[Request interrupted',
] as const;
/**
* Codex includes extra internal metadata tags that should not surface as
* user-facing searchable conversation content.
*/
const CODEX_INTERNAL_CONTENT_PREFIXES = [
'<environment_context>',
'<cwd>',
] as const;
function normalizeComparablePath(inputPath: string): string {
if (!inputPath || typeof inputPath !== 'string') {
return '';
@@ -156,6 +165,11 @@ function isInternalContent(content: string): boolean {
return INTERNAL_CONTENT_PREFIXES.some((prefix) => content.startsWith(prefix));
}
function isInternalCodexContent(content: string): boolean {
const normalized = content.trimStart();
return CODEX_INTERNAL_CONTENT_PREFIXES.some((prefix) => normalized.startsWith(prefix));
}
function escapeRegex(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
@@ -807,7 +821,6 @@ async function parseCodexSessionMatches(
if (entry.type === 'event_msg' && isVisibleCodexUserMessage(entry.payload as AnyRecord)) {
text = String(entry.payload.message);
role = 'user';
latestUserMessageText = text;
} else if (
entry.type === 'event_msg'
&& entry.payload?.type === 'agent_reasoning'
@@ -820,9 +833,6 @@ async function parseCodexSessionMatches(
if (payload.role === 'user') {
text = extractCodexText(payload.content);
role = 'user';
if (text) {
latestUserMessageText = text;
}
} else if (payload.role === 'assistant') {
text = extractCodexText(payload.content);
role = 'assistant';
@@ -844,6 +854,12 @@ async function parseCodexSessionMatches(
if (!text || !role) {
continue;
}
if (isInternalCodexContent(text)) {
continue;
}
if (role === 'user') {
latestUserMessageText = text;
}
const fingerprint = `${role}:${text.trim().toLowerCase()}`;
if (seenMessageFingerprints.has(fingerprint)) {