Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix(native): only split resume into a tab that already has a chat

justrache600c84e98eb
diff --git a/apps/native/lib/chat-groups.test.ts b/apps/native/lib/chat-groups.test.ts
index 0f75c4cb..0449ef65 100644
--- a/apps/native/lib/chat-groups.test.ts
+++ b/apps/native/lib/chat-groups.test.ts
@@ -23,10 +23,10 @@ test('merging and ungrouping preserve other tabs and enforce the pane cap', () =
expect(replaceChatGroup(layouts,1,[])).toEqual([layouts[1]]);
});
test('resume from the same folder splits into the open tab, not a new tab', () => {
- const chats = [{ id: 1, cwd: '/repo' }, { id: 2, cwd: '/other' }];
+ const chats = [{ id: 1, cwd: '/repo', messages: [{}] }, { id: 2, cwd: '/other', messages: [{}] }];
const groups = [{ ids: [1] }, { ids: [2] }];
expect(resumeSplitTarget(chats, groups, 1, '/repo', '/repo', 4)).toBe(1);
expect(resumeSplitTarget(chats, groups, 1, '/other', '/repo', 4)).toBeNull();
expect(resumeSplitTarget(chats, [{ ids: [1, 3, 4, 5] }], 1, '/repo', '/repo', 4)).toBeNull();
- expect(resumeSplitTarget([{ id: 1 }], [{ ids: [1] }], 1, '/repo', '/repo', 4)).toBe(1);
+ expect(resumeSplitTarget([{ id: 1, cwd: '/repo', messages: [] }], [{ ids: [1] }], 1, '/repo', '/repo', 4)).toBeNull();
});
diff --git a/apps/native/lib/chat-groups.ts b/apps/native/lib/chat-groups.ts
index 295027d2..18791690 100644
--- a/apps/native/lib/chat-groups.ts
+++ b/apps/native/lib/chat-groups.ts
@@ -32,7 +32,7 @@ export function reorderChatGroups<T extends { id: number }>(chats: T[], groups:
/** Resume into the focused tab when it already belongs to this folder. */
export function resumeSplitTarget(
- chats: { id: number; cwd?: string | null }[],
+ chats: { id: number; cwd?: string | null; messages?: { length: number } }[],
groups: { ids: number[] }[],
focusedId: number,
resumeCwd: string | null | undefined,
@@ -43,6 +43,9 @@ export function resumeSplitTarget(
if (!folder) return null;
const host = groups.find(group => group.ids.includes(focusedId));
if (!host || host.ids.length >= cap) return null;
- const same = host.ids.some(id => (chats.find(chat => chat.id === id)?.cwd ?? activePath ?? null) === folder);
- return same ? focusedId : null;
+ const occupied = host.ids.some(id => {
+ const chat = chats.find(item => item.id === id);
+ return (chat?.cwd ?? activePath ?? null) === folder && (chat?.messages?.length ?? 0) > 0;
+ });
+ return occupied ? focusedId : null;
}