From 1835b39e2c619543ae9655e3b1c9b65a8a9b8a28 Mon Sep 17 00:00:00 2001 From: Aamer Akhter Date: Mon, 23 Nov 2026 13:20:32 -0500 Subject: [PATCH] fix(preview): COD-152 resolve abbreviated Codex file tabs --- src/web/public/app.js | 11 ++++++++++- src/web/public/terminal-ui.js | 2 +- test/response-viewer-file-links.test.ts | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/web/public/app.js b/src/web/public/app.js index afaf2b4a..a34b6cf4 100644 --- a/src/web/public/app.js +++ b/src/web/public/app.js @@ -3222,6 +3222,8 @@ class CodemanApp { } _findCodexResponseFile(messages, label, session, sidebar = false) { + const [prefix, suffix, ...extra] = sidebar ? label.split('…') : []; + const abbreviated = Boolean(prefix && suffix && extra.length === 0); let match = null; for (const message of messages) { if (message.role !== 'assistant' || typeof message.text !== 'string' || (!sidebar && !message.text.includes(label))) continue; @@ -3235,7 +3237,14 @@ class CodemanApp { this._linkifyFilePaths(rendered.content); for (const link of links) { const path = resolveLinkedFilePath(link.dataset.path, session.workingDir); - if (sidebar && path.split('/').pop() !== label) continue; + if (sidebar) { + const basename = path.split('/').pop(); + // Codex preserves both ends of a filename when it shortens the tab. + const matchesEnds = + abbreviated && basename.length > prefix.length + suffix.length && + basename.startsWith(prefix) && basename.endsWith(suffix); + if (basename !== label && !matchesEnds) continue; + } // Ambiguity includes web URLs and unsupported files with the same label. if (!link.dataset.linkified || link.dataset.folder || !/^\/(?!\/)/.test(path) || !previewsInFileViewer(path)) { return null; diff --git a/src/web/public/terminal-ui.js b/src/web/public/terminal-ui.js index e361080f..07eb7fe2 100644 --- a/src/web/public/terminal-ui.js +++ b/src/web/public/terminal-ui.js @@ -526,7 +526,7 @@ function codexSidebarFileRow(terminal, row) { to--; } const label = line.translateToString(false, from, to).trim(); - if (label && !label.includes('…') && previewsInFileViewer(label)) entries.push({ label, start: from, end: to }); + if (label && previewsInFileViewer(label)) entries.push({ label, start: from, end: to }); }; if (row === headerRow) { let from = divider + 1; diff --git a/test/response-viewer-file-links.test.ts b/test/response-viewer-file-links.test.ts index 09ab0dfd..7b642932 100644 --- a/test/response-viewer-file-links.test.ts +++ b/test/response-viewer-file-links.test.ts @@ -427,6 +427,30 @@ describe('Codex terminal response link matching', () => { ).toBeNull(); }); + it('resolves an abbreviated native tab only when one path matches both visible ends', () => { + const app = appForTranscript(); + const session = { workingDir: '/work/project' }; + const name = 'Interview panel plan - requisition 2026943.docx'; + const exact = { role: 'assistant', text: `[Download]()` }; + const near = { role: 'assistant', text: '[Wrong extension]()' }; + const label = 'Interview…26943.docx'; + expect(app._findCodexResponseFile([exact, near], label, session, true)).toBe(`/work/project/out/${name}`); + expect( + app._findCodexResponseFile( + [ + exact, + { + role: 'assistant', + text: '[Another draft]()', + }, + ], + label, + session, + true + ) + ).toBeNull(); + }); + it.each([ '[Word brief](out/different.docx)', '[Word brief](https://example.test/report.docx)',