Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

Fix Codex file change diff rendering (#16823)

Arvin Xua587a78a794d
diff --git a/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.test.ts b/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.test.ts
index 3e0f76b6952..079e35b6783 100644
--- a/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.test.ts
+++ b/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.test.ts
@@ -76,6 +76,44 @@ describe('CodexFileChangeTracker', () => {
expect((enriched.item as any).diffText).toContain(`diff --git a${addPath} b${addPath}`);
});
+ it('does not synthesize a whole-file diff when an update starts without a path snapshot', async () => {
+ const dir = await mkdtemp(path.join(tmpdir(), 'codex-file-change-tracker-'));
+ tempDirs.push(dir);
+
+ const updatePath = path.join(dir, 'existing.ts');
+ await writeFile(updatePath, 'line one\nline two\nline three\n', 'utf8');
+
+ const tracker = new CodexFileChangeTracker();
+
+ await tracker.track({
+ item: {
+ changes: [],
+ id: 'item_missing_snapshot',
+ type: 'file_change',
+ },
+ type: 'item.started',
+ });
+
+ await writeFile(updatePath, 'line one\nline two updated\nline three\n', 'utf8');
+
+ const enriched = await tracker.track({
+ item: {
+ changes: [{ kind: 'update', path: updatePath }],
+ id: 'item_missing_snapshot',
+ type: 'file_change',
+ },
+ type: 'item.completed',
+ });
+
+ expect(enriched.item).toMatchObject({
+ changes: [{ kind: 'update', linesAdded: 0, linesDeleted: 0, path: updatePath }],
+ linesAdded: 0,
+ linesDeleted: 0,
+ });
+ expect(enriched.item).not.toHaveProperty('diffText');
+ expect(enriched.item.changes?.[0]).not.toHaveProperty('diffText');
+ });
+
it('treats rename changes as metadata-only and keeps line stats at zero', async () => {
const dir = await mkdtemp(path.join(tmpdir(), 'codex-file-change-tracker-'));
tempDirs.push(dir);
diff --git a/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.ts b/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.ts
index c755cb44ff4..5265308c668 100644
--- a/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.ts
+++ b/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.ts
@@ -6,6 +6,8 @@ import { createPatch } from 'diff';
interface CodexFileChangeEntry {
diffText?: string;
kind?: string;
+ linesAdded?: number;
+ linesDeleted?: number;
path?: string;
}
@@ -38,7 +40,7 @@ interface CodexFileChangeDiff extends CodexFileChangeLineStats {
diffText?: string;
}
-interface CodexTrackedFileChangeEntry extends CodexFileChangeEntry, CodexFileChangeDiff {}
+type CodexTrackedFileChangeEntry = CodexFileChangeEntry & CodexFileChangeDiff;
interface CodexTrackedFileChangeItem extends CodexFileChangeItem, CodexFileChangeLineStats {
changes?: CodexTrackedFileChangeEntry[];
@@ -147,6 +149,13 @@ const computeFileChangeDiff = async (
return buildFileChangeDiff(filePath, previousContent, '');
}
+ if (!snapshot) {
+ return {
+ linesAdded: change.linesAdded ?? 0,
+ linesDeleted: change.linesDeleted ?? 0,
+ };
+ }
+
if (!snapshot?.exists && !current.exists) return { linesAdded: 0, linesDeleted: 0 };
if (snapshot?.exists && snapshot.content === undefined) return { linesAdded: 0, linesDeleted: 0 };