Skip to content

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

Python

Keep new chat in the open folder, and make GUI text copyable.

justrach764ea8f81f10
diff --git a/AGENTS.md b/AGENTS.md
index 2efabb3c..e2537405 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -109,6 +109,11 @@ the line REPL, the fullscreen TUI, and the desktop GUI (`graff acp`). Surface
chrome can differ; the engine path cannot. If you add a wake, a latch, or a
delivery rule, wire it on all three in the same change.
+Worktrees and changes to the GUI must be 1:1 with ACP. A new-chat folder
+rule, a worktree handoff, or a session cwd that exists only in desktop chrome
+is not done — wire the same behavior through the ACP session in the same
+change. The workspace the agent runs in is not chrome.
+
## Tests must be reachable
- `zig build test` only runs the tests in files the test root pulls in. A new module's `test {}` blocks compile to nothing until something references it, and the suite still reports green.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c8e83cf1..3f0ec62e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,9 @@ current is part of cutting a release.
## v0.0.302.4
+- New chat stays in the folder already open, on the desktop and through ACP. Worktrees and other GUI workspace changes have to match the ACP session; that rule is in AGENTS.md and docs/notices.
+- GUI transcript drag-selection paints, and each message has a copy icon at the bottom.
+
- Task workspace housekeeping: `graff worktree update` merges the remote base; `gc` drops dead session trees and clean trees whose GitHub PR is MERGED (dirty trees stay). Desktop: Update from main, Clear unused trees. Asking to free space unfolds `workspace` so `action=gc` is callable this turn.
- xAI Responses WS chains `previous_response_id` on the held socket (store:false in-memory cache) and `generate:false` prewarms a fresh socket. A stalled first handshake or 426 latches HTTPS SSE for the session; chrome shows a dim `using HTTPS SSE` notice. `GRAFF_XAI_WS_CHAIN=0` opts out.
- HTTPS SSE prefers HTTP/2 (`justrach/http-zig`): connection reuse, ALPN `h2`, first-failure HTTP/1.1 latch. `GRAFF_HTTP2=0` forces 1.1.
diff --git a/CLAUDE.md b/CLAUDE.md
index 5700213e..1eb7e7e1 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1,6 +1,8 @@
# Repository instructions
-Read `AGENTS.md` first — it is the full contract for working in this repository. The rule below is repeated here because it is non-negotiable.
+Read `AGENTS.md` first — it is the full contract for working in this repository. The rules below are repeated here because they are non-negotiable.
+
+Worktrees and changes to the GUI must be 1:1 with ACP. A new-chat folder rule, a worktree handoff, or a session cwd that exists only in desktop chrome is not done until the ACP session does the same thing.
## Public tracker: bare minimum, no internals, no attribution
diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsx
index e44be2b6..dd04e725 100644
--- a/apps/native/components/site/GraffHarness.tsx
+++ b/apps/native/components/site/GraffHarness.tsx
@@ -235,11 +235,11 @@ export default function GraffHarness() {
await runPrompt(chatId, trimmed);
};
- const openChat = (id: number) => {
+ const openChat = (id: number, folder?: string) => {
setProjectsOpen(false); setAgentsOpen(false);
const session = newSessionName();
sessionNamesRef.current.set(id, session);
- const cwd = activePathRef.current ?? undefined;
+ const cwd = folder ?? activePathRef.current ?? undefined;
const ws = findWorkspace(workspacesRef.current, cwd);
const next = [...chatsRef.current, { id, title: null, messages: [], model: ws?.model ?? model ?? undefined, session, cwd }];
chatsRef.current = next; setChats(next);
@@ -272,7 +272,11 @@ export default function GraffHarness() {
});
const openStored = (name: string, cwd = activePathRef.current ?? undefined) => savedConversation.open(name, cwd);
- const newChat = () => openChat((chatIdRef.current += 1));
+ const newChat = () => {
+ const folder = chatsRef.current.find(c => c.id === activeIdRef.current)?.cwd;
+ if (folder && folder !== activePathRef.current) activateWorkspace(folder);
+ openChat((chatIdRef.current += 1), folder ?? activePathRef.current ?? undefined);
+ };
/** Focus a pane in place, or restore the selected workspace tab’s layout. */
const focusChat = (id: number, focusPrompt = true) => {
@@ -314,7 +318,7 @@ export default function GraffHarness() {
}
setSplitNotice(null);
const id = (chatIdRef.current += 1);
- openChat(id);
+ openChat(id, chatsRef.current.find(c => c.id === activeIdRef.current)?.cwd ?? activePathRef.current ?? undefined);
groups.split(id,activeId,direction === "row" ? "right" : "bottom");
};
@@ -348,9 +352,7 @@ export default function GraffHarness() {
const recents = sidebarRecents(stored, chats, unread);
- // The tab bar's folder chip is the *tab's* workspace; the sidebar's
- // switcher is the *active* one (where new tabs open). They differ only
- // after a switch, and each says so on hover.
+ // The folder chip is the tab's workspace. New chat opens there.
const cwdOf = (thread: Chat) => thread.cwd ?? activePath ?? health?.cwd;
const workspaceNameOf = (thread: Chat) => {
const dir = cwdOf(thread);
diff --git a/docs/notices/README.md b/docs/notices/README.md
new file mode 100644
index 00000000..bdff790a
--- /dev/null
+++ b/docs/notices/README.md
@@ -0,0 +1,10 @@
+# Notices
+
+Standing notes for anyone building on the desktop, including third-party ACP clients.
+
+## GUI stays 1:1 with ACP
+
+Worktrees and changes to the GUI must be 1:1 with ACP (`graff acp`). A new-chat
+folder rule, a worktree handoff, or a session cwd that exists only in desktop
+chrome is not done — wire the same behavior through the ACP session in the same
+change. The workspace the agent runs in is not chrome.
diff --git a/gui/src/app/App.tsx b/gui/src/app/App.tsx
index c6f77de7..cf4b7878 100644
--- a/gui/src/app/App.tsx
+++ b/gui/src/app/App.tsx
@@ -132,8 +132,8 @@ function AppShell() {
const [isSidebarAnimating, setIsSidebarAnimating] = useState(false);
const sidebarAnimateTimeoutRef = useRef<number | null>(null);
// Holds the latest openNewChat from the always-mounted NewChatTrigger so the
- // global Cmd/Ctrl+N shortcut can invoke it (including its git-worktree choice
- // dialog) no matter what's visible.
+ // global Cmd/Ctrl+N shortcut opens a chat in the current folder no matter
+ // what's visible.
const newChatRef = useRef<(() => void) | null>(null);
// Briefly enable a width transition on the panels so toggling the sidebar
// slides smoothly (like the artifacts drawer) instead of snapping. Kept off
@@ -229,8 +229,8 @@ function AppShell() {
};
}, []);
- // Global Cmd/Ctrl+N → new chat. Reuses NewChatTrigger's openNewChat (captured
- // in newChatRef) so the git-worktree choice dialog flows through identically.
+ // Global Cmd/Ctrl+N → new chat in the folder already open. Reuses
+ // NewChatTrigger's openNewChat (captured in newChatRef).
// Skipped while a settings view or dialog is open or while the session is
// mid-bootstrap, and ignores key presses originating inside an input/textarea
// so it never fights typing — though Cmd+N is uncommon enough to be safe.
diff --git a/gui/src/components/NewChatTrigger.tsx b/gui/src/components/NewChatTrigger.tsx
index d35a416e..7739a5dc 100644
--- a/gui/src/components/NewChatTrigger.tsx
+++ b/gui/src/components/NewChatTrigger.tsx
@@ -2,243 +2,33 @@ import { useState, type ReactNode } from "react";
import { useConversationSession, useSessionActions } from "@/hooks/useSession";
-import { Button } from "./ui/Button";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
-} from "./ui/Dialog";
-import { Input } from "./ui/Input";
-import { Label } from "./ui/Label";
-
interface NewChatTriggerProps {
children: (props: { isBusy: boolean; openNewChat: () => void }) => ReactNode;
}
-type BranchDialogMode = "local" | "worktree" | null;
-
+/** New chat stays in the folder already open. A managed chat has no project
+ * folder, so that case still starts a fresh managed chat. Starting a worktree
+ * stays on the conversation header, not on this button. */
export function NewChatTrigger({ children }: NewChatTriggerProps) {
- const { handoffChat, startNewChat } = useSessionActions();
- const { runtimeStatus, workspacePath } = useConversationSession();
- const [branchDialogMode, setBranchDialogMode] =
- useState<BranchDialogMode>(null);
- const [branchName, setBranchName] = useState("");
- const [isChoiceDialogOpen, setIsChoiceDialogOpen] = useState(false);
+ const { startNewChat } = useSessionActions();
+ const { workspaceKind, workspacePath } = useConversationSession();
const [isSubmitting, setIsSubmitting] = useState(false);
- const isGitWorkspace = runtimeStatus?.gitWorkspaceKind != null;
- const isDetachedWorktree =
- runtimeStatus?.gitWorkspaceKind === "worktree" &&
- runtimeStatus.gitBranchName == null;
-
- function resetBranchDialog() {
- setBranchDialogMode(null);
- setBranchName("");
- }
-
- async function runAction(action: () => Promise<void>) {
- setIsSubmitting(true);
- try {
- await action();
- } finally {
- setIsSubmitting(false);
- }
- }
-
- function closeBranchDialog() {
- if (isSubmitting) {
- return;
- }
-
- resetBranchDialog();
- }
-
- function openBranchDialog(mode: Exclude<BranchDialogMode, null>) {
- setBranchDialogMode(mode);
- setBranchName("");
- }
-
function openNewChat() {
- if (!isGitWorkspace || workspacePath == null) {
- void runAction(async () => {
- await startNewChat();
- });
- return;
- }
-
- setIsChoiceDialogOpen(true);
- }
-
- async function handleStartLocal() {
- setIsChoiceDialogOpen(false);
- if (workspacePath == null) {
- await runAction(async () => {
- await startNewChat();
- });
- return;
- }
-
- if (isDetachedWorktree) {
- openBranchDialog("local");
- return;
- }
-
- await runAction(async () => {
- if (runtimeStatus?.gitWorkspaceKind === "local") {
- await startNewChat(workspacePath);
- return;
- }
-
- await handoffChat({
- branchName: null,
- conversationId: null,
- sourceWorkspacePath: workspacePath,
- target: "local",
- });
- });
- }
-
- function handleStartWorktree() {
- setIsChoiceDialogOpen(false);
- openBranchDialog("worktree");
- }
-
- async function handleBranchSubmit() {
- if (workspacePath == null || branchDialogMode == null) {
- return;
- }
-
- const trimmedBranchName = branchName.trim();
- if (trimmedBranchName.length === 0) {
+ if (isSubmitting) {
return;
}
- await runAction(async () => {
- await handoffChat({
- branchName: trimmedBranchName,
- conversationId: null,
- sourceWorkspacePath: workspacePath,
- target: branchDialogMode,
- });
- resetBranchDialog();
+ const folder =
+ workspaceKind === "managed_chat" ? undefined : (workspacePath ?? undefined);
+ setIsSubmitting(true);
+ void startNewChat(folder).finally(() => {
+ setIsSubmitting(false);
});
}
- return (
- <>
- {children({
- isBusy: isSubmitting,
- openNewChat,
- })}
-
- <Dialog
- open={isChoiceDialogOpen}
- onOpenChange={(open) => {
- if (isSubmitting) {
- return;
- }
-
- setIsChoiceDialogOpen(open);
- }}
- >
- <DialogContent className="max-w-sm" showCloseButton={!isSubmitting}>
- <DialogHeader>
- <DialogTitle>Start new chat</DialogTitle>
- <DialogDescription>
- Choose whether the next chat should continue in the local checkout
- or a fresh worktree.
- </DialogDescription>
- </DialogHeader>
-
- <div className="grid gap-2">
- <Button
- type="button"
- variant="outline"
- disabled={isSubmitting}
- onClick={() => {
- void handleStartLocal();
- }}
- >
- Work locally
- </Button>
- <Button
- type="button"
- variant="outline"
- disabled={isSubmitting || workspacePath == null}
- onClick={handleStartWorktree}
- >
- New worktree
- </Button>
- </div>
- </DialogContent>
- </Dialog>
-
- <Dialog
- open={branchDialogMode != null}
- onOpenChange={(open) => {
- if (!open) {
- closeBranchDialog();
- }
- }}
- >
- <DialogContent className="max-w-md" showCloseButton={!isSubmitting}>
- <DialogHeader>
- <DialogTitle>
- {branchDialogMode === "worktree"
- ? "Start chat in worktree"
- : "Start local chat on a branch"}
- </DialogTitle>
- <DialogDescription>
- {branchDialogMode === "worktree"
- ? "Create and check out a branch in a new worktree for the next chat."
- : "Choose a branch name for the local checkout before continuing this chat there."}
- </DialogDescription>
- </DialogHeader>
-
- <div className="grid gap-2">
- <Label htmlFor="new-chat-branch-name">Branch name</Label>
- <Input
- id="new-chat-branch-name"
- value={branchName}
- onChange={(event) => {
- setBranchName(event.target.value);
- }}
- onKeyDown={(event) => {
- if (event.key !== "Enter" || isSubmitting) {
- return;
- }
-
- event.preventDefault();
- void handleBranchSubmit();
- }}
- placeholder="feature/my-branch"
- />
- </div>
-
- <DialogFooter>
- <Button
- type="button"
- variant="outline"
- disabled={isSubmitting}
- onClick={closeBranchDialog}
- >
- Cancel
- </Button>
- <Button
- type="button"
- disabled={isSubmitting || branchName.trim().length === 0}
- onClick={() => {
- void handleBranchSubmit();
- }}
- >
- Continue
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- </>
- );
+ return children({
+ isBusy: isSubmitting,
+ openNewChat,
+ });
}
diff --git a/gui/src/components/chat/AssistantResponseCopyButton.tsx b/gui/src/components/chat/AssistantResponseCopyButton.tsx
index c7b3eca4..62606b2d 100644
--- a/gui/src/components/chat/AssistantResponseCopyButton.tsx
+++ b/gui/src/components/chat/AssistantResponseCopyButton.tsx
@@ -28,10 +28,12 @@ export function AssistantResponseCopyButton({
onClick={() => {
void copy(text);
}}
- className="-ml-1 rounded-full px-1.5 text-muted-foreground hover:text-foreground"
+ className="size-7 rounded-full border border-border bg-background p-0 text-foreground shadow-none hover:bg-muted"
>
- {copied ? <Check className="size-3" /> : <Copy className="size-3" />}
- <span aria-live="polite">{label}</span>
+ {copied ? <Check className="size-3.5" /> : <Copy className="size-3.5" />}
+ <span className="sr-only" aria-live="polite">
+ {label}
+ </span>
</Button>
);
}
diff --git a/gui/src/components/chat/ChatMessageRow.test.tsx b/gui/src/components/chat/ChatMessageRow.test.tsx
index 59598022..238a4fcb 100644
--- a/gui/src/components/chat/ChatMessageRow.test.tsx
+++ b/gui/src/components/chat/ChatMessageRow.test.tsx
@@ -103,10 +103,10 @@ async function flushUpdates(delayMs = 10) {
}
describe("chat response copy dispatch", () => {
- test("the thread adds the action only to assistant messages", () => {
+ test("the thread adds the copy action to user and assistant messages", () => {
const messages: Array<[TranscriptMessage, boolean]> = [
[contentMessage("assistant", "Answer"), true],
- [contentMessage("user", "Question"), false],
+ [contentMessage("user", "Question"), true],
[contentMessage("reasoning", "Private reasoning"), false],
[
{
diff --git a/gui/src/components/chat/ChatMessageRow.tsx b/gui/src/components/chat/ChatMessageRow.tsx
index b0beaf90..afe83073 100644
--- a/gui/src/components/chat/ChatMessageRow.tsx
+++ b/gui/src/components/chat/ChatMessageRow.tsx
@@ -2,6 +2,7 @@ import {
CHAT_BODY_TONE_CLASS,
CHAT_REASONING_TONE_CLASS,
} from "./constants/chatStyles";
+import { AssistantResponseCopyButton } from "./AssistantResponseCopyButton";
import { ChatMarkdownMessage } from "./ChatMarkdownMessage";
import { ChatInlineText } from "./ChatInlineText";
import { AttachmentTray } from "@/components/attachments/AttachmentTray";
@@ -33,7 +34,7 @@ function UserChatMessage({ text, workspacePath }: UserChatMessageProps) {
.filter((item): item is NonNullable<typeof item> => item != null);
return (
- <article className="cg-message-in flex w-full flex-col items-end gap-2 select-none">
+ <article className="cg-message-in flex w-full flex-col items-end gap-2 select-text">
{attachments.length > 0 ? (
<AttachmentTray
attachments={attachments}
@@ -42,11 +43,11 @@ function UserChatMessage({ text, workspacePath }: UserChatMessageProps) {
/>
) : null}
{body.length > 0 ? (
- <div
- className="w-fit select-text rounded-xl bg-muted px-3.5 py-1.5 text-sm text-foreground"
- style={{ maxWidth: "min(42rem, 85%)" }}
- >
- <ChatInlineText as="p" text={body} workspacePath={workspacePath} />
+ <div className="flex w-fit max-w-[min(42rem,85%)] flex-col items-end gap-1.5">
+ <div className="w-fit select-text rounded-xl bg-muted px-3.5 py-1.5 text-sm text-foreground">
+ <ChatInlineText as="p" text={body} workspacePath={workspacePath} />
+ </div>
+ <AssistantResponseCopyButton text={body} />
</div>
) : null}
</article>
diff --git a/gui/src/components/chat/utils/chatThreadList.tsx b/gui/src/components/chat/utils/chatThreadList.tsx
index cdbd73fc..c0d98c99 100644
--- a/gui/src/components/chat/utils/chatThreadList.tsx
+++ b/gui/src/components/chat/utils/chatThreadList.tsx
@@ -118,7 +118,7 @@ export function renderChatThreadItem(
return (
<div
- className="mx-auto min-w-0 w-full max-w-3xl select-none"
+ className="mx-auto min-w-0 w-full max-w-3xl select-text"
style={{ paddingBottom: index === itemCount - 1 ? 0 : THREAD_ITEM_GAP }}
>
{row}
diff --git a/gui/src/styles/core.css b/gui/src/styles/core.css
index a42aaaec..ead4086c 100644
--- a/gui/src/styles/core.css
+++ b/gui/src/styles/core.css
@@ -11,6 +11,13 @@
-webkit-user-drag: none;
}
+/* The webview's system highlight does not paint on a drag, so selection has
+ its own color. Ancestors must not set user-select: none over chat text. */
+::selection {
+ background-color: color-mix(in srgb, var(--foreground) 28%, var(--background));
+ color: var(--foreground);
+}
+
/* Syntax-highlight token colors for the local code-block renderer (CodeBlock.tsx
+ highlight/). github-light defaults, github-dark under `.dark`. */
:root {