Skip to content

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

Python

Land is user-driven merge-back for task workspaces

justrach9340ce0efa7b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03441385..7dc7596f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,7 +15,7 @@ current is part of cutting a release.
- Desktop first launch: one MCP install (no overlapping flock / “MCP setup incomplete”), and `graff` on login-shell PATH (zsh/bash login+interactive, Homebrew and `~/bin` shims).
- Ctrl-V screenshot paste is not killed by a leftover Esc (`clipboard helper unavailable`).
- Desktop auto-update accepts 4-part hotfix versions (`0.0.302.3`), not only `0.0.xxx`.
-- Task workspaces are graff-native (`.graff/workspace.toml`, `.worktreeinclude`, `GRAFF_WORKSPACE_*`). Copy gitignored files and run setup/run/archive scripts (ADR 0153). Desktop Tools: New task workspace, Run, Archive.
+- Task workspaces are graff-native (`.graff/workspace.toml`, `.worktreeinclude`, `GRAFF_WORKSPACE_*`). Copy gitignored files and run setup/run/archive scripts (ADR 0153). Desktop Tools: New task workspace, Run, Land, Archive. The agent does not delete a named tree.
## v0.0.302.2
diff --git a/apps/native/app/api/worktree/route.ts b/apps/native/app/api/worktree/route.ts
index ffeced0e..6b442717 100644
--- a/apps/native/app/api/worktree/route.ts
+++ b/apps/native/app/api/worktree/route.ts
@@ -1,5 +1,5 @@
import { spawn } from "node:child_process";
-import { graffBin, parseCreate, runCommand, sanitizeSlug, slugFromCheckout } from "@/lib/worktree-cli";
+import { graffBin, parseCreate, repoRoot, runCommand, sanitizeSlug, slugFromCheckout } from "@/lib/worktree-cli";
import { resolveRoot } from "@/lib/server-root";
export const runtime = "nodejs";
@@ -32,10 +32,13 @@ export async function POST(req: Request) {
if ("error" in resolved) return Response.json({ error: resolved.error }, { status: resolved.status });
const bin = graffBin();
const action = body.action;
+ const repo = repoRoot(resolved.root);
+ const slug = () => sanitizeSlug(typeof body.name === "string" ? body.name : "")
+ ?? slugFromCheckout(resolved.root);
if (action === "create") {
const name = sanitizeSlug(typeof body.name === "string" ? body.name : "");
if (!name) return Response.json({ error: "workspace name must be 1-64 letters, digits, '.', '_' or '-'" }, { status: 400 });
- const result = await run(bin, ["worktree", "create", name], resolved.root, 120_000);
+ const result = await run(bin, ["worktree", "create", name], repo, 120_000);
const parsed = parseCreate(result.stdout);
if (result.code !== 0 || !parsed) {
return Response.json({ error: result.stderr.trim() || result.stdout.trim() || "create failed" }, { status: 502 });
@@ -43,16 +46,21 @@ export async function POST(req: Request) {
return Response.json(parsed);
}
if (action === "archive") {
- const name = sanitizeSlug(typeof body.name === "string" ? body.name : "")
- ?? slugFromCheckout(resolved.root);
+ const name = slug();
if (!name) return Response.json({ error: "not a task workspace" }, { status: 400 });
- const result = await run(bin, ["worktree", "archive", name], resolved.root, 60_000);
+ const result = await run(bin, ["worktree", "archive", name], repo, 60_000);
if (result.code !== 0) return Response.json({ error: result.stderr.trim() || result.stdout.trim() || "archive failed" }, { status: 502 });
- return Response.json({ ok: true, output: result.stdout.trim() });
+ return Response.json({ ok: true, output: result.stdout.trim(), root: repo });
+ }
+ if (action === "merge" || action === "land") {
+ const name = slug();
+ if (!name) return Response.json({ error: "not a task workspace" }, { status: 400 });
+ const result = await run(bin, ["worktree", "merge", name], repo, 120_000);
+ if (result.code !== 0) return Response.json({ error: result.stderr.trim() || result.stdout.trim() || "land failed" }, { status: 502 });
+ return Response.json({ ok: true, output: result.stdout.trim(), root: repo });
}
if (action === "run") {
- const name = sanitizeSlug(typeof body.name === "string" ? body.name : "")
- ?? slugFromCheckout(resolved.root);
+ const name = slug();
if (!name) return Response.json({ error: "not a task workspace" }, { status: 400 });
return Response.json({ ok: true, name, command: runCommand(name) });
}
diff --git a/apps/native/components/site/HarnessChrome.tsx b/apps/native/components/site/HarnessChrome.tsx
index b11e7016..c7412f35 100644
--- a/apps/native/components/site/HarnessChrome.tsx
+++ b/apps/native/components/site/HarnessChrome.tsx
@@ -7,7 +7,7 @@ import { IconSidebarLeftOpen } from "@/lib/icons";
import type { PointerEvent, MouseEvent, ReactNode } from "react";
import type { Chat } from "./harness-types";
import reviewStyles from "./ChangesPane.module.css";
-import { archiveTaskWorkspace, createTaskWorkspace, runTaskWorkspace } from "./harness-task-workspace";
+import { archiveTaskWorkspace, createTaskWorkspace, landTaskWorkspace, runTaskWorkspace } from "./harness-task-workspace";
type Props = {
navigationToggle?: ReactNode; sidebarVisible?: boolean;
@@ -58,6 +58,7 @@ export default function HarnessChrome({navigationToggle, sidebarVisible = false,
{onReviews && <button type="button" aria-label="GitHub reviews" aria-pressed={reviewsOpen} onClick={onReviews}>Reviews</button>}
<button type="button" aria-label="New task workspace" onClick={() => void createTaskWorkspace(chatCwd).catch(err => window.alert(String(err.message || err)))}>New task workspace</button>
<button type="button" aria-label="Run workspace script" onClick={() => void runTaskWorkspace(chatCwd, () => { if (!terminalVisible) toggleTerminal(); }).catch(err => window.alert(String(err.message || err)))}>Run</button>
+ <button type="button" aria-label="Land task workspace" onClick={() => void landTaskWorkspace(chatCwd).catch(err => window.alert(String(err.message || err)))}>Land</button>
<button type="button" aria-label="Archive task workspace" onClick={() => void archiveTaskWorkspace(chatCwd).catch(err => window.alert(String(err.message || err)))}>Archive</button>
<button type="button" aria-label="Toggle terminal" aria-pressed={terminalVisible} onClick={toggleTerminal}>Terminal <span className="ml-auto text-ink-3">⌘J</span></button>
<button type="button" aria-label="Browser" aria-pressed={browserOpen} onClick={onBrowser}>Browser{pinCount > 0 ? ` (${pinCount})` : ""}</button>
diff --git a/apps/native/components/site/ProjectsPane.tsx b/apps/native/components/site/ProjectsPane.tsx
index df8566ba..2335d306 100644
--- a/apps/native/components/site/ProjectsPane.tsx
+++ b/apps/native/components/site/ProjectsPane.tsx
@@ -2,6 +2,14 @@
import { useState } from "react";
import { IconFolder, IconPlusMedium } from "@/lib/icons";
import { compareWorkspaceActivity, workspaceSourceLabel, type Workspace } from "@/lib/workspaces";
+import { archiveTaskWorkspace, landTaskWorkspace } from "./harness-task-workspace";
+
+function taskSlug(path: string): string | null {
+ const parts = path.replace(/\\/g, "/").split("/");
+ const i = parts.lastIndexOf("worktrees");
+ if (i >= 0 && parts[i - 1] === ".graff" && parts[i + 1]) return parts[i + 1];
+ return null;
+}
export default function ProjectsPane({ workspaces, current, onOpen, onContinue, onNewChat, onClose }: {
workspaces: Workspace[]; current: string | null; onOpen: () => void;
@@ -20,10 +28,14 @@ export default function ProjectsPane({ workspaces, current, onOpen, onContinue,
<div className="grid gap-3 xl:grid-cols-2">
{shown.map(w => <article key={w.path} data-project-path={w.path} className="min-w-0 rounded-[14px] border border-line bg-surface p-4">
<div className="flex items-center gap-2 text-ink"><IconFolder size={19} /><h2 className="min-w-0 flex-1 truncate font-medium">{w.name}</h2>{w.path === current && <span className="text-xs text-accent">Current</span>}</div>
- <p className="my-3 break-all font-mono text-xs text-ink-3">{workspaceSourceLabel(w)} · {w.path}</p>
+ <p className="my-3 break-all font-mono text-xs text-ink-3">{workspaceSourceLabel(w)} · {w.path}{taskSlug(w.path) ? ` · worktree-${taskSlug(w.path)}` : ""}</p>
<div className="flex flex-wrap gap-2">
- <button type="button" onClick={() => onContinue(w.path)} className="rounded-control bg-hover-2 px-3 py-2 text-sm text-ink">Continue conversation</button>
+ <button type="button" onClick={() => onContinue(w.path)} className="rounded-control bg-hover-2 px-3 py-2 text-sm text-ink">Open</button>
<button type="button" onClick={() => onNewChat(w.path)} className="rounded-control px-3 py-2 text-sm text-ink-2 hover:bg-hover">New chat</button>
+ {taskSlug(w.path) && <>
+ <button type="button" onClick={() => void landTaskWorkspace(w.path).catch(err => window.alert(String(err.message || err)))} className="rounded-control px-3 py-2 text-sm text-ink-2 hover:bg-hover">Land</button>
+ <button type="button" onClick={() => void archiveTaskWorkspace(w.path).catch(err => window.alert(String(err.message || err)))} className="rounded-control px-3 py-2 text-sm text-ink-2 hover:bg-hover">Archive</button>
+ </>}
</div>
</article>)}
</div>
diff --git a/apps/native/components/site/harness-task-workspace.ts b/apps/native/components/site/harness-task-workspace.ts
index 1d356a5c..a66f85ca 100644
--- a/apps/native/components/site/harness-task-workspace.ts
+++ b/apps/native/components/site/harness-task-workspace.ts
@@ -4,7 +4,7 @@ async function post(action: string, root: string | undefined, name?: string) {
headers: { "content-type": "application/json" },
body: JSON.stringify({ action, root, name }),
});
- const body = await response.json() as { error?: string; path?: string; command?: string; output?: string };
+ const body = await response.json() as { error?: string; path?: string; command?: string; output?: string; root?: string };
if (!response.ok) throw new Error(body.error || "Worktree request failed");
return body;
}
@@ -30,4 +30,12 @@ export async function archiveTaskWorkspace(root?: string): Promise<void> {
if (!window.confirm("Archive this task workspace? Dirty or unique-commit trees stay.")) return;
const body = await post("archive", root);
if (body.output && !body.output.startsWith("✓")) window.alert(body.output);
+ if (body.root) window.dispatchEvent(new CustomEvent("graff-open-workspace", { detail: { cwd: body.root } }));
+}
+
+export async function landTaskWorkspace(root?: string): Promise<void> {
+ if (!window.confirm("Land this workspace onto the base branch as one commit and remove the checkout?")) return;
+ const body = await post("merge", root);
+ if (body.output) window.alert(body.output);
+ if (body.root) window.dispatchEvent(new CustomEvent("graff-open-workspace", { detail: { cwd: body.root } }));
}
diff --git a/apps/native/lib/worktree-cli.test.ts b/apps/native/lib/worktree-cli.test.ts
index 2352e447..422ac169 100644
--- a/apps/native/lib/worktree-cli.test.ts
+++ b/apps/native/lib/worktree-cli.test.ts
@@ -1,6 +1,6 @@
import { test } from "bun:test";
import assert from "node:assert/strict";
-import { parseCreate, runCommand, sanitizeSlug, slugFromCheckout } from "./worktree-cli";
+import { parseCreate, repoRoot, runCommand, sanitizeSlug, slugFromCheckout } from "./worktree-cli";
test("sanitizeSlug matches the engine's workspace names", () => {
assert.equal(sanitizeSlug("tokyo"), "tokyo");
@@ -27,3 +27,8 @@ test("slugFromCheckout reads a task worktree folder", () => {
assert.equal(slugFromCheckout("/repo"), null);
assert.equal(runCommand("tokyo"), "graff worktree run tokyo");
});
+
+test("repoRoot strips a task worktree suffix", () => {
+ assert.equal(repoRoot("/repo/.graff/worktrees/task-a"), "/repo");
+ assert.equal(repoRoot("/repo"), "/repo");
+});
diff --git a/apps/native/lib/worktree-cli.ts b/apps/native/lib/worktree-cli.ts
index bcf05f94..3d24fd75 100644
--- a/apps/native/lib/worktree-cli.ts
+++ b/apps/native/lib/worktree-cli.ts
@@ -41,3 +41,12 @@ export function parseCreate(stdout: string): CreateResult | null {
export function runCommand(name: string): string {
return `graff worktree run ${name}`;
}
+
+/** The git repo root for a task checkout (`…/.graff/worktrees/<name>` → `…`). */
+export function repoRoot(checkout: string): string {
+ const norm = checkout.replace(/\\/g, "/");
+ const marker = "/.graff/worktrees/";
+ const i = norm.lastIndexOf(marker);
+ if (i > 0) return checkout.slice(0, i);
+ return checkout;
+}
diff --git a/assets/skills/workspace.md b/assets/skills/workspace.md
index cc97dda4..11d23e25 100644
--- a/assets/skills/workspace.md
+++ b/assets/skills/workspace.md
@@ -30,8 +30,10 @@ A new independent task is `workspace action=create`.
Create copies gitignored files matching `.worktreeinclude` (else
`include` in `.graff/workspace.toml`, else `.env*`) from the main checkout,
then runs `scripts.setup` from `.graff/workspace.toml`.
- `graff worktree run <name>` is the run script; `archive` runs `scripts.archive`
- before removing a clean duplicate (ADR 0153). Desktop Tools: New task workspace, Run, Archive.
+ `graff worktree run <name>` is the run script. The user lands or archives;
+ do not spawn a child to delete a tree. `graff worktree land <name>` squash-lands
+ onto the base branch and removes the checkout. `archive` removes a clean
+ duplicate only. Desktop Tools: New task workspace, Run, Land, Archive.
4. If the match is ambiguous, name more of the path. Do not guess.
Do not paste every worktree path into the next user turn. The list result is
diff --git a/src/cli.zig b/src/cli.zig
index c09cc5a9..f68de46a 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -338,6 +338,7 @@ pub const usage_text =
\\ graff worktree run <name> run the workspace run script from that checkout
\\ graff worktree archive <name> remove a clean duplicate checkout; dirty or unique-commit trees stay
\\ graff worktree merge <name> squash-land worktree-<name> onto the current branch + clean up
+ \\ graff worktree land <name> same as merge
\\ graff worktree remove <name> discard worktree-<name> (drops its scratch work) + delete the branch
\\ graff worktree prune drop git registrations for worktrees whose dirs were deleted
\\ graff servers background servers graff started (this session's or older): pid, port, age
diff --git a/src/worktree_cmd.zig b/src/worktree_cmd.zig
index b52527f2..c1f6ac55 100644
--- a/src/worktree_cmd.zig
+++ b/src/worktree_cmd.zig
@@ -68,9 +68,9 @@ pub fn worktreeCommand(gpa: Allocator, io: Io, arena: Allocator, args: []const [
return worktree_prune.listWithAge(gpa, io, arena, out);
}
- if (std.mem.eql(u8, action, "merge")) {
+ if (std.mem.eql(u8, action, "merge") or std.mem.eql(u8, action, "land")) {
if (args.len < 2) {
- try out.writeAll("usage: graff worktree merge <name>\n");
+ try out.writeAll("usage: graff worktree merge <name>\n graff worktree land <name>\n");
return;
}
const name = args[1];