Skip to content

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

Python

feat(native): archive or delete a saved chat, and keep the model's tab name

justrach71f4c560a3a2
diff --git a/apps/native/README.md b/apps/native/README.md
index ec09452a..88856805 100644
--- a/apps/native/README.md
+++ b/apps/native/README.md
@@ -122,6 +122,15 @@ own session. The prompt's first words stand in until it answers, and
stay if it cannot. A session open in a tab shows that name in the
sidebar too.
+## Managing chats
+
+Hovering a chat in the sidebar reveals two controls. **Archive** moves the
+session file under `.graff/sessions/archived/`, so the chat leaves the list
+but the conversation stays on disk and can be moved back by hand.
+**Delete** removes the file. Either way the chat's tab closes with it, and
+the row goes at once rather than after the next poll of the session
+directory.
+
## Keyboard
| Keys | What it does |
diff --git a/apps/native/app/api/sessions/route.ts b/apps/native/app/api/sessions/route.ts
index ecb0859e..1245a7bc 100644
--- a/apps/native/app/api/sessions/route.ts
+++ b/apps/native/app/api/sessions/route.ts
@@ -1,4 +1,4 @@
-import { closeSync, existsSync, openSync, readdirSync, readFileSync, readSync, statSync } from "node:fs";
+import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, renameSync, statSync, unlinkSync } from "node:fs";
import path from "node:path";
import { NextRequest } from "next/server";
import { resolveRoot } from "@/lib/server-root";
@@ -11,6 +11,9 @@ export const dynamic = "force-dynamic";
// updated_ms — is written before the (possibly multi-MB) messages array, so the
// list peeks the prefix instead of parsing whole files.
const SESSIONS_DIR = ".graff/sessions";
+// Archived chats leave the list but stay on disk, next to graff's own
+// sessions, so a chat can be put away without losing the conversation.
+const ARCHIVE_DIR = ".graff/sessions/archived";
const EXT = ".session.json";
const NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
const PEEK_BYTES = 64 * 1024;
@@ -117,3 +120,32 @@ export async function GET(req: NextRequest) {
rows.sort((a, b) => b.updatedMs - a.updatedMs);
return Response.json({ cwd: root, sessions: rows });
}
+
+/** Put a chat away (`?archive=1`, the default: the file moves under
+ * `.graff/sessions/archived/`) or remove it for good. Either way it leaves
+ * the sidebar; only delete loses the conversation. */
+export async function DELETE(req: NextRequest) {
+ const resolved = resolveRoot(req.nextUrl.searchParams.get("root"));
+ if ("error" in resolved) return Response.json({ error: resolved.error }, { status: resolved.status });
+ const name = req.nextUrl.searchParams.get("name");
+ if (name === null || !NAME_RE.test(name)) return Response.json({ error: "bad session name" }, { status: 400 });
+ const dir = path.join(resolved.root, SESSIONS_DIR);
+ const file = path.join(dir, `${name}${EXT}`);
+ if (!existsSync(file)) return Response.json({ error: "no such session" }, { status: 404 });
+ const archive = req.nextUrl.searchParams.get("archive") !== "0";
+ try {
+ if (!archive) {
+ unlinkSync(file);
+ return Response.json({ ok: true, name, archived: false });
+ }
+ const target = path.join(resolved.root, ARCHIVE_DIR);
+ mkdirSync(target, { recursive: true });
+ let dest = path.join(target, `${name}${EXT}`);
+ // Never overwrite an earlier archive of the same name.
+ if (existsSync(dest)) dest = path.join(target, `${name}.${Date.now()}${EXT}`);
+ renameSync(file, dest);
+ return Response.json({ ok: true, name, archived: true });
+ } catch (err) {
+ return Response.json({ error: err instanceof Error ? err.message : String(err) }, { status: 502 });
+ }
+}
diff --git a/apps/native/components/primitives/SidebarNav.tsx b/apps/native/components/primitives/SidebarNav.tsx
index ccbd9d3e..7be6fbb2 100644
--- a/apps/native/components/primitives/SidebarNav.tsx
+++ b/apps/native/components/primitives/SidebarNav.tsx
@@ -77,6 +77,9 @@ type SidebarNavProps = {
workspaces?: SidebarWorkspace[];
onSwitchWorkspace?: (path: string) => void;
onNewWorkspace?: () => void;
+ /** Put a saved chat away, or (deleting) remove it for good. */
+ onArchiveRecent?: (id: string) => void;
+ onDeleteRecent?: (id: string) => void;
onWorkspaceSettings?: () => void;
};
@@ -253,6 +256,8 @@ export default function SidebarNav({
onSwitchWorkspace,
onNewWorkspace,
onWorkspaceSettings,
+ onArchiveRecent,
+ onDeleteRecent,
}: SidebarNavProps) {
const [collapsed, setCollapsed] = useState(false);
const [internalNav, setInternalNav] = useState("chats");
@@ -480,6 +485,7 @@ export default function SidebarNav({
{header}
</div>
)}
+ <div className="group/row relative">
<button
data-row
type="button"
@@ -497,6 +503,44 @@ export default function SidebarNav({
{item.label}
</span>
</button>
+ {(onArchiveRecent || onDeleteRecent) && (
+ <span className="sidebar-copy absolute inset-y-0 right-3 z-20 flex items-center gap-0.5 opacity-0 transition-opacity group-focus-within/row:opacity-100 group-hover/row:opacity-100">
+ {onArchiveRecent && (
+ <button
+ type="button"
+ aria-label={`Archive ${item.label}`}
+ title="Archive this chat — it leaves the list but stays on disk"
+ onClick={(event) => {
+ event.stopPropagation();
+ onArchiveRecent(item.id);
+ }}
+ className="flex size-6 items-center justify-center rounded-[6px] text-ink-3 transition-colors hover:bg-hover-2 hover:text-ink"
+ >
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
+ <rect x="3" y="4" width="18" height="4" rx="1" />
+ <path d="M5 8v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8M10 12h4" />
+ </svg>
+ </button>
+ )}
+ {onDeleteRecent && (
+ <button
+ type="button"
+ aria-label={`Delete ${item.label}`}
+ title="Delete this chat for good"
+ onClick={(event) => {
+ event.stopPropagation();
+ onDeleteRecent(item.id);
+ }}
+ className="flex size-6 items-center justify-center rounded-[6px] text-ink-3 transition-colors hover:bg-hover-2 hover:text-red"
+ >
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
+ <path d="M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3" />
+ </svg>
+ </button>
+ )}
+ </span>
+ )}
+ </div>
</Fragment>
);
})}
diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsx
index 7ee8cf8b..62524f72 100644
--- a/apps/native/components/site/GraffHarness.tsx
+++ b/apps/native/components/site/GraffHarness.tsx
@@ -28,7 +28,7 @@ import {
import { applyAcpUpdate, emptyTurn, finishAcpTurn, type AssistantTurn } from "@/lib/acp";
import { isFollowingTail, pinScrollerTail } from "@/lib/follow-scroll";
import { dropQueuedPrompt, enqueuePrompt, shiftQueuedPrompt, type QueuedPrompt } from "@/lib/prompt-queue";
-import { dateGroup, listSessions, loadSession, relativeTime, type StoredSession } from "@/lib/sessions";
+import { dateGroup, listSessions, loadSession, relativeTime, removeSession, type StoredSession } from "@/lib/sessions";
import { loadHistory, mergeHistory, pushHistory, saveHistory } from "@/lib/prompt-history";
import WorkspaceDialog from "@/components/site/WorkspaceDialog";
import {
@@ -54,7 +54,10 @@ type Msg =
/** `model` is what this tab's own agent was spawned with; the harness-level
* model is only the default a new tab inherits. `cwd` is the workspace the
* tab's agent runs in — fixed at spawn, like the model. */
-type Chat = { id: number; title: string | null; messages: Msg[]; model?: string; session?: string; cwd?: string };
+type Chat = { id: number; title: string | null; messages: Msg[]; model?: string; session?: string; cwd?: string;
+ /** The model named this tab from its first prompt: the session poller,
+ * which reads graff's own saved title, must leave it alone. */
+ titledByModel?: boolean };
function newPageToken(): string {
return Math.random().toString(36).slice(2, 10);
@@ -269,6 +272,7 @@ export default function GraffHarness() {
setStored(list);
setChats((current) =>
current.map((c) => {
+ if (c.titledByModel) return c;
const saved = c.session ? list.find((s) => s.name === c.session) : undefined;
return saved?.title && saved.title !== c.title ? { ...c, title: saved.title } : c;
}),
@@ -406,7 +410,7 @@ export default function GraffHarness() {
.then((body) => {
const title = body?.title?.trim();
if (!title) return;
- setChats((current) => current.map((c) => (c.id === chatId ? { ...c, title } : c)));
+ setChats((current) => current.map((c) => (c.id === chatId ? { ...c, title, titledByModel: true } : c)));
})
.catch(() => undefined);
};
@@ -545,6 +549,18 @@ export default function GraffHarness() {
void openStored(id);
};
+ /** Put a saved chat away, or remove it for good. Its tab closes with it,
+ * and the row goes at once rather than after the next poll. */
+ const dropStored = (name: string, archive: boolean) => {
+ const cwd = activePathRef.current ?? undefined;
+ const open = chatsRef.current.find((c) => c.session === name && (c.cwd ?? null) === (cwd ?? null));
+ if (open) closeChat(open.id);
+ setStored((current) => current.filter((s) => s.name !== name));
+ void removeSession(name, { root: cwd, archive })
+ .catch(() => undefined)
+ .then(() => refreshStored());
+ };
+
/* ── workspaces ── */
const persistWorkspaces = (list: Workspace[]) => {
@@ -985,6 +1001,8 @@ export default function GraffHarness() {
workspace={sidebarWorkspace}
workspaces={workspaces.map((w) => ({ path: w.path, name: w.name }))}
onSwitchWorkspace={switchWorkspace}
+ onArchiveRecent={(id) => dropStored(id, true)}
+ onDeleteRecent={(id) => dropStored(id, false)}
onNewWorkspace={() => setDialog({ mode: "new" })}
onWorkspaceSettings={() => setDialog(sidebarWorkspace ? { mode: "settings" } : { mode: "new" })}
footerLabel={copiedResume ? "Copied resume command" : (chatThread.session ?? "Connecting…")}
diff --git a/apps/native/lib/sessions.ts b/apps/native/lib/sessions.ts
index 13726b64..06e0f0e3 100644
--- a/apps/native/lib/sessions.ts
+++ b/apps/native/lib/sessions.ts
@@ -33,6 +33,16 @@ function withRoot(params: Record<string, string | undefined>): string {
}
/** Sessions saved under `<root>/.graff/sessions`; absent root = the default workspace. */
+/** Put a saved chat away (the file moves under `.graff/sessions/archived/`)
+ * or, with `archive: false`, remove it for good. */
+export async function removeSession(name: string, opts: { root?: string; archive?: boolean } = {}): Promise<void> {
+ const params = new URLSearchParams({ name });
+ if (opts.root) params.set("root", opts.root);
+ if (opts.archive === false) params.set("archive", "0");
+ const res = await fetch(`${BASE}?${params.toString()}`, { method: "DELETE", cache: "no-store" });
+ if (!res.ok) throw new Error(`sessions → ${res.status}`);
+}
+
export async function listSessions(root?: string): Promise<StoredSession[]> {
const res = await fetch(`${BASE}${withRoot({ root })}`, { cache: "no-store" });
if (!res.ok) throw new Error(`sessions → ${res.status}`);