Skip to content

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

Python

Unfold workspace when the user asks to free disk.

justracha1566c3f12cc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a629e1a3..616f003a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,7 +12,7 @@ current is part of cutting a release.
## v0.0.302.4
-- 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, disk use on the projects card. `/workspace gc` and `workspace action=gc` free space when the user asks; they do not run because a turn finished.
+- 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.
## v0.0.302.3
diff --git a/assets/skills/workspace.md b/assets/skills/workspace.md
index ab40e3a0..a2fc717c 100644
--- a/assets/skills/workspace.md
+++ b/assets/skills/workspace.md
@@ -32,7 +32,8 @@ A new independent task is `workspace action=create`.
then runs `scripts.setup` from `.graff/workspace.toml`.
`graff worktree run <name>` is the run script. The user lands or archives;
do not spawn a child to delete a tree. When the user asks to free disk or
- clear unused trees, `workspace action=gc` (or `/workspace gc`). That drops
+ clear unused trees, the harness unfolds `workspace` and you call
+ `action=gc` (or `/workspace gc`). That drops
dead session trees and clean trees whose GitHub PR is MERGED. Dirty trees
stay. Do not gc because a turn finished.
4. If the match is ambiguous, name more of the path. Do not guess.
diff --git a/src/named_work.zig b/src/named_work.zig
index b7c29404..ec35abc5 100644
--- a/src/named_work.zig
+++ b/src/named_work.zig
@@ -68,6 +68,10 @@ pub fn beginTurn(self: *Agent) void {
if (fold.noticeExplicit(taskOf(self))) {
self.invalidateRootTools();
}
+ if (@import("worktree_reap.zig").userAskedToFreeTrees(taskOf(self))) {
+ fold.markLoaded("workspace");
+ self.invalidateRootTools();
+ }
}
}
diff --git a/src/worktree_reap.zig b/src/worktree_reap.zig
index 2b7de11b..853bb549 100644
--- a/src/worktree_reap.zig
+++ b/src/worktree_reap.zig
@@ -27,6 +27,33 @@ fn pidGone(io: Io, pid: i32) bool {
return proc_identity.probe(io, pid) == .gone;
}
+fn hasIgnoreCase(hay: []const u8, needle: []const u8) bool {
+ if (hay.len < needle.len) return false;
+ var i: usize = 0;
+ while (i + needle.len <= hay.len) : (i += 1) {
+ if (std.ascii.eqlIgnoreCase(hay[i .. i + needle.len], needle)) return true;
+ }
+ return false;
+}
+
+/// User asked to free disk. Unfold `workspace` so action=gc is callable.
+/// Do not match a generic "clean up" — that is finish-is-not-archive.
+pub fn userAskedToFreeTrees(text: []const u8) bool {
+ const needles = [_][]const u8{
+ "clear up space",
+ "free space",
+ "free disk",
+ "clear unused",
+ "unused worktree",
+ "unused trees",
+ "workspace gc",
+ "/workspace gc",
+ "worktree gc",
+ };
+ for (needles) |n| if (hasIgnoreCase(text, n)) return true;
+ return false;
+}
+
/// Drop registrations whose dirs are already gone, then remove clean
/// auto-isolate trees whose pid is dead. Returns how many directories went.
pub fn orphans(gpa: Allocator, io: Io, arena: Allocator, cwd: []const u8) usize {
@@ -102,6 +129,14 @@ pub fn mergedPulls(gpa: Allocator, io: Io, arena: Allocator, cwd: []const u8) us
return removed;
}
+test "userAskedToFreeTrees: space/gc wording, not generic cleanup" {
+ try std.testing.expect(userAskedToFreeTrees("can we clear up space"));
+ try std.testing.expect(userAskedToFreeTrees("Free disk please"));
+ try std.testing.expect(userAskedToFreeTrees("run worktree gc"));
+ try std.testing.expect(!userAskedToFreeTrees("clean up the worktree after you finish"));
+ try std.testing.expect(!userAskedToFreeTrees("summarize the architecture"));
+}
+
test "sessionPid: only auto-isolate session branches" {
try std.testing.expectEqual(@as(?i32, 65043), sessionPid("refs/heads/worktree-session-65043-e9cc718d"));
try std.testing.expectEqual(@as(?i32, 65043), sessionPid("worktree-session-65043-e9cc718d"));