fix(preview): COD-152 resolve abbreviated Codex file tabs

This commit is contained in:
Aamer Akhter committed 2026-11-23 13:20:32 -05:00
1 parent 6de846ba9a
commit 1835b39e2c
3 files changed
+35 -2

No files matched your search

+10 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+24
View File
@@ -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](<out/${name}>)` };
const near = { role: 'assistant', text: '[Wrong extension](<out/Interview draft 2026943.pdf>)' };
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](<other/Interview alternate 2026943.docx>)',
},
],
label,
session,
true
)
).toBeNull();
});
it.each([
'[Word brief](out/different.docx)',
'[Word brief](https://example.test/report.docx)',