graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Preserve selected project when restoring desktop tabs
Rach Pradhan12c6e8936093
diff --git a/apps/native/lib/tab-recovery.test.ts b/apps/native/lib/tab-recovery.test.tsindex 87f71aaf..c6996700 100644--- a/apps/native/lib/tab-recovery.test.ts+++ b/apps/native/lib/tab-recovery.test.ts@@ -6,15 +6,17 @@ test('open tab references and split groups survive a new page without saving traconst store = new Map<string, string>();const storage = { getItem: (key: string) => store.get(key) ?? null, setItem: (key: string, value: string) => { store.set(key, value); } };const state = tabRecovery([- { id: 3, session: 'native-first', cwd: '/repo/.graff/worktrees/first', title: 'First', messages: [{ id: 1, role: 'user', text: 'private prompt' }] },+ { id: 3, session: 'native-first', cwd: '/repo/.graff/worktrees/first', project: '/repo', title: 'First', messages: [{ id: 1, role: 'user', text: 'private prompt' }] },{ id: 8, session: 'native-second', cwd: '/repo/.graff/worktrees/second', title: 'Second', messages: [] },], 8, [{ ids: [3, 8], direction: 'column' }]);saveTabRecovery(storage, state);assert.deepEqual(loadTabRecovery(storage), state);assert.equal(store.get(TAB_RECOVERY_KEY)?.includes('private prompt'), false);+ assert.equal(loadTabRecovery(storage)?.tabs[0].project, '/repo');});test('malformed or obsolete tab references do not replace the new chat', () => {const storage = { getItem: () => JSON.stringify({ tabs: [{ id: 1, session: '../escape' }], activeId: 1 }) };assert.equal(loadTabRecovery(storage), null);+ assert.equal(loadTabRecovery({ getItem: () => JSON.stringify({ tabs: [{ id: 1, session: 'valid', project: '../escape' }], activeId: 1 }) }), null);});diff --git a/apps/native/lib/tab-recovery.ts b/apps/native/lib/tab-recovery.tsindex 7d46c31b..6d42cf72 100644--- a/apps/native/lib/tab-recovery.ts+++ b/apps/native/lib/tab-recovery.ts@@ -2,14 +2,14 @@ import type { ChatGroup } from "./chat-groups";import type { Chat } from "@/components/site/harness-types";export const TAB_RECOVERY_KEY = "graff.native.open-tabs.v1";-export type TabReference = Pick<Chat, "id" | "session" | "cwd" | "title" | "model">;+export type TabReference = Pick<Chat, "id" | "session" | "cwd" | "project" | "title" | "model">;export type TabRecovery = { tabs: TabReference[]; activeId: number; groups: ChatGroup[] };/** Keep only references and layout. Transcripts remain in the engine's saved* sessions; drafts and live tool state must never be mistaken for a checkpoint. */export function tabRecovery(chats: readonly Chat[], activeId: number, groups: readonly ChatGroup[]): TabRecovery {return {- tabs: chats.slice(0, 50).map(({ id, session, cwd, title, model }) => ({ id, session, cwd, title, model })),+ tabs: chats.slice(0, 50).map(({ id, session, cwd, project, title, model }) => ({ id, session, cwd, project, title, model })),activeId,groups: groups.map(group => ({ ids: [...group.ids], direction: group.direction, ...(group.tree ? { tree: group.tree } : {}) })),};@@ -31,8 +31,10 @@ export function loadTabRecovery(storage: Pick<Storage, "getItem"> | null): TabReif (!Number.isSafeInteger(tab.id) || (tab.id as number) < 1 || seen.has(tab.id as number) ||typeof tab.session !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(tab.session)) return null;if (tab.cwd !== undefined && (typeof tab.cwd !== "string" || !tab.cwd.startsWith("/"))) return null;+ if (tab.project !== undefined && (typeof tab.project !== "string" || !tab.project.startsWith("/"))) return null;seen.add(tab.id as number);tabs.push({ id: tab.id as number, session: tab.session, cwd: tab.cwd as string | undefined,+ project: tab.project as string | undefined,title: typeof tab.title === "string" ? tab.title : null,model: typeof tab.model === "string" ? tab.model : undefined });}