Skip to content

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

Python

fix(native): split same-folder resumes and add a pane picker

justrach5e604ff43b18
diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsx
index 92f67e07..3bf6b0e3 100644
--- a/apps/native/components/site/GraffHarness.tsx
+++ b/apps/native/components/site/GraffHarness.tsx
@@ -12,7 +12,7 @@ import ProjectsPane from "./ProjectsPane";
import { useSavedConversation, ConversationOpenNotice } from "./useSavedConversation";
import { useQuietSettings } from "./useQuietSettings";
import { useTabDrag } from "./useTabDrag";
-import { mergeChatGroups, reorderChatGroups } from "@/lib/chat-groups";
+import { mergeChatGroups, reorderChatGroups, resumeSplitTarget } from "@/lib/chat-groups";
import { useChatGroups } from "./useChatGroups";
import AppSettings from "./AppSettings";
import HarnessChrome from "./HarnessChrome";
@@ -132,6 +132,10 @@ export default function GraffHarness() {
// own scroller and its own place in its transcript.
const groups = useChatGroups(chats, activeId);
const { panes, setPanes, direction: splitDirection } = groups;
+ const groupsRef = useRef(groups);
+ groupsRef.current = groups;
+ const activeIdRef = useRef(activeId);
+ activeIdRef.current = activeId;
const [zoomedPane, setZoomedPane] = useState<number | null>(null);
const chatsRef = useRef(chats);
chatsRef.current = chats;
@@ -256,6 +260,8 @@ export default function GraffHarness() {
sessionNamesRef.current.set(id, name);
const next = [...chatsRef.current, { id, title: loaded.meta.title ?? name, messages, model: loaded.meta.model ?? undefined, session: name, cwd, snapshot: loaded.snapshot }];
chatsRef.current = next; setChats(next);
+ const host = resumeSplitTarget(chatsRef.current, groupsRef.current.groups, activeIdRef.current, cwd, activePathRef.current, MAX_COLUMNS);
+ if (host != null) groupsRef.current.split(id, host, "right");
selectStored(id, cwd);
},
});
diff --git a/apps/native/components/site/HarnessChrome.tsx b/apps/native/components/site/HarnessChrome.tsx
index 40289241..5289a4d6 100644
--- a/apps/native/components/site/HarnessChrome.tsx
+++ b/apps/native/components/site/HarnessChrome.tsx
@@ -2,6 +2,7 @@ import SessionTabs from "./SessionTabs";
import type {SplitTree} from "@/lib/split-tree";
import ActionMenu from "@/components/primitives/ActionMenu";
import AppSettings from "./AppSettings";
+import WorkspacePaneMenu from "./WorkspacePaneMenu";
import type { PointerEvent, MouseEvent, ReactNode } from "react";
import type { Chat } from "./harness-types";
import reviewStyles from "./ChangesPane.module.css";
@@ -50,12 +51,14 @@ export default function HarnessChrome({navigationToggle, sidebarVisible = false,
</svg>
</button>
</div>
+ {!sidebarVisible && <WorkspacePaneMenu className="ml-1 shrink-0" filesOpen={filesOpen} changesOpen={changesOpen} browserOpen={browserOpen} terminalVisible={terminalVisible} pinCount={pinCount} onFiles={onFiles} openChanges={openChanges} onBrowser={onBrowser} toggleTerminal={toggleTerminal} />}
</div>
<div className={`${reviewStyles.actions} flex min-h-10 shrink-0 items-center gap-1 ${sidebarVisible ? "justify-end px-1" : "border-t border-line px-2"} py-1`}>
{navigationToggle}
<button type="button" aria-pressed={filesOpen && !changesOpen} onClick={onFiles} title={`${chatCwd ?? "Workspace"}\nShow this chat's files`}
className={`max-w-48 truncate lg:hidden ${paneBtn(filesOpen && !changesOpen)}`}>{workspaceName}</button>
<div className={`flex items-center gap-1 ${sidebarVisible ? "rounded-[14px] border border-line bg-page px-2 py-0.5" : ""}`}>
+ {sidebarVisible && <WorkspacePaneMenu filesOpen={filesOpen} changesOpen={changesOpen} browserOpen={browserOpen} terminalVisible={terminalVisible} pinCount={pinCount} onFiles={onFiles} openChanges={openChanges} onBrowser={onBrowser} toggleTerminal={toggleTerminal} />}
<button type="button" aria-label="Files" aria-pressed={filesOpen && !changesOpen} onClick={onFiles} className={`hidden lg:inline-flex ${paneBtn(filesOpen && !changesOpen)}`}>Files</button>
<button type="button" aria-label="Review workspace changes" aria-pressed={changesOpen} onClick={openChanges} className={paneBtn(changesOpen)}>Changes</button>
<button type="button" aria-label="Browser" aria-pressed={browserOpen} onClick={onBrowser} className={paneBtn(browserOpen)}>Browser{pinCount > 0 ? ` (${pinCount})` : ""}</button>
diff --git a/apps/native/components/site/WorkspacePaneMenu.tsx b/apps/native/components/site/WorkspacePaneMenu.tsx
new file mode 100644
index 00000000..1e6fa976
--- /dev/null
+++ b/apps/native/components/site/WorkspacePaneMenu.tsx
@@ -0,0 +1,46 @@
+import ActionMenu from "@/components/primitives/ActionMenu";
+
+type Props = {
+ className?: string;
+ filesOpen: boolean;
+ changesOpen: boolean;
+ browserOpen: boolean;
+ terminalVisible: boolean;
+ pinCount: number;
+ onFiles(): void;
+ openChanges(): void;
+ onBrowser(): void;
+ toggleTerminal(): void;
+};
+
+export default function WorkspacePaneMenu({
+ className = "",
+ filesOpen, changesOpen, browserOpen, terminalVisible, pinCount,
+ onFiles, openChanges, onBrowser, toggleTerminal,
+}: Props) {
+ return (
+ <ActionMenu
+ label="Workspace panes"
+ className={className}
+ text={
+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" aria-hidden>
+ <rect x="3" y="4" width="18" height="16" rx="2" />
+ <path d="M15 4v16" />
+ </svg>
+ }
+ >
+ <button type="button" aria-pressed={changesOpen} onClick={openChanges}>
+ Review
+ </button>
+ <button type="button" aria-pressed={terminalVisible} onClick={toggleTerminal}>
+ Terminal <span className="ml-auto text-ink-3">⌘J</span>
+ </button>
+ <button type="button" aria-pressed={browserOpen} onClick={onBrowser}>
+ Browser{pinCount > 0 ? ` (${pinCount})` : ""}
+ </button>
+ <button type="button" aria-pressed={filesOpen && !changesOpen} onClick={onFiles}>
+ Files
+ </button>
+ </ActionMenu>
+ );
+}
diff --git a/apps/native/lib/chat-groups.test.ts b/apps/native/lib/chat-groups.test.ts
index ca965e98..0f75c4cb 100644
--- a/apps/native/lib/chat-groups.test.ts
+++ b/apps/native/lib/chat-groups.test.ts
@@ -1,5 +1,5 @@
import { test, expect } from 'bun:test';
-import { chatGroups, replaceChatGroup, mergeChatGroups, reorderChatGroups } from './chat-groups';
+import { chatGroups, replaceChatGroup, mergeChatGroups, reorderChatGroups, resumeSplitTarget } from './chat-groups';
test('closing an entire side preserves the remaining nested split axis',()=>{
const tree={key:'root',axis:'row' as const,ratio:.5,first:1,second:{key:'nested',axis:'column' as const,ratio:.5,first:2,second:3}};
const [group]=chatGroups([{id:2},{id:3}],[{ids:[1,2,3],direction:'row',tree}]);
@@ -22,3 +22,11 @@ test('merging and ungrouping preserve other tabs and enforce the pane cap', () =
expect(replaceChatGroup(layouts,1,[1,2,3,4])).toEqual([{ids:[1,2,3,4],direction:'column'}]);
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 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);
+});
diff --git a/apps/native/lib/chat-groups.ts b/apps/native/lib/chat-groups.ts
index da3c25c0..295027d2 100644
--- a/apps/native/lib/chat-groups.ts
+++ b/apps/native/lib/chat-groups.ts
@@ -29,3 +29,20 @@ export function reorderChatGroups<T extends { id: number }>(chats: T[], groups:
order.splice(order.indexOf(destination) + Number(after), 0, moving);
return order.flatMap(group => group.ids.map(id => chats.find(chat => chat.id === id)!));
}
+
+/** Resume into the focused tab when it already belongs to this folder. */
+export function resumeSplitTarget(
+ chats: { id: number; cwd?: string | null }[],
+ groups: { ids: number[] }[],
+ focusedId: number,
+ resumeCwd: string | null | undefined,
+ activePath: string | null | undefined,
+ cap: number,
+): number | null {
+ const folder = resumeCwd ?? activePath ?? null;
+ 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;
+}