Skip to content

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

Python

fix(native): the desktop window loaded a stale page, and can install itself

justrach2e3801006129
diff --git a/apps/native/desktop/README.md b/apps/native/desktop/README.md
index 386ab982..735e13ad 100644
--- a/apps/native/desktop/README.md
+++ b/apps/native/desktop/README.md
@@ -25,10 +25,15 @@ bundle for macOS to read an icon from.
## A signed, notarized app
```bash
-apps/native/desktop/build-app.sh # build + sign
-NOTARIZE=1 apps/native/desktop/build-app.sh # …and send it to Apple
+apps/native/desktop/build-app.sh # build + sign
+NOTARIZE=1 apps/native/desktop/build-app.sh # …and send it to Apple
+NOTARIZE=1 INSTALL=1 apps/native/desktop/build-app.sh # …and put it in /Applications
```
+Install what was notarized, not a later re-signed build: re-signing
+replaces the signature the stapled ticket belongs to, and the copy stops
+being notarized. `INSTALL_DIR` moves the destination.
+
macOS only, and it refuses to run anywhere else: the shell is AppKit and
WKWebView, and every tool it uses (`iconutil`, `codesign`, `notarytool`)
comes with Xcode's command line tools. It writes `zig-out/macos/Codegraff.app`
@@ -47,6 +52,12 @@ Launched from Finder an app inherits no environment, so with
`GRAFF_NATIVE_URL` unset the shell looks for a dev server on 3777 and then
3000, and falls back to the first so the window still opens.
+The document is fetched with `NSURLRequestReloadIgnoringLocalCacheData`.
+The window points at a dev server whose bundle changes underneath it, and
+WebKit will otherwise serve a page from an earlier build: the HTML loads,
+its scripts never start against the new server, and the app sits on
+"Connecting…" for good.
+
On Linux the same `main.zig` prints the URL and tries `xdg-open`. WKWebView
is macOS-only — that is a merjs limitation, not a graff one. The existing
Tauri app in `gui/` is unchanged.
diff --git a/apps/native/desktop/build-app.sh b/apps/native/desktop/build-app.sh
index 1e1a1e33..c9d622d3 100755
--- a/apps/native/desktop/build-app.sh
+++ b/apps/native/desktop/build-app.sh
@@ -58,4 +58,14 @@ if [[ "${NOTARIZE:-0}" == "1" ]]; then
echo "▸ stapled and zipped: $zip"
fi
+if [[ "${INSTALL:-0}" == "1" ]]; then
+ dest="${INSTALL_DIR:-/Applications}/Codegraff.app"
+ echo "▸ installing to $dest"
+ # ditto keeps the signature intact, which cp -R does not always do.
+ rm -rf "$dest"
+ ditto "$app" "$dest"
+ codesign --verify --deep --strict "$dest"
+ echo "▸ installed: $dest"
+fi
+
echo "▸ $app"
diff --git a/apps/native/desktop/main.zig b/apps/native/desktop/main.zig
index bd33aa08..189b307a 100644
--- a/apps/native/desktop/main.zig
+++ b/apps/native/desktop/main.zig
@@ -74,6 +74,12 @@ const NSWindowStyleMaskMiniaturizable: NSUInteger = 4;
const NSWindowStyleMaskResizable: NSUInteger = 8;
const NSBackingStoreBuffered: NSUInteger = 2;
const NSApplicationActivationPolicyRegular: NSInteger = 0;
+/// NSURLRequestReloadIgnoringLocalCacheData. The window points at a dev
+/// server whose bundle changes under it; WebKit's cache happily serves a
+/// page from a previous build, which then fails to start against the new
+/// one. Always fetch the document fresh.
+const NSURLRequestReloadIgnoringLocalCacheData: NSUInteger = 1;
+const load_timeout_s: f64 = 30;
const YES: BOOL = 1;
const NO: BOOL = 0;
@@ -119,6 +125,10 @@ fn sendWebViewInit(recv: Id, s: Sel, frame: CGRect, config: Id) Id {
const F = *const fn (Id, Sel, CGRect, Id) callconv(.c) Id;
return @as(F, @ptrCast(&objc_msgSend))(recv, s, frame, config);
}
+fn sendRequestInit(recv: Id, s: Sel, url: Id, policy: NSUInteger, timeout: f64) Id {
+ const F = *const fn (Id, Sel, Id, NSUInteger, f64) callconv(.c) Id;
+ return @as(F, @ptrCast(&objc_msgSend))(recv, s, url, policy, timeout);
+}
fn sendBytes(recv: Id, s: Sel, ptr: [*]const u8, len: NSUInteger) Id {
const F = *const fn (Id, Sel, [*]const u8, NSUInteger) callconv(.c) Id;
return @as(F, @ptrCast(&objc_msgSend))(recv, s, ptr, len);
@@ -166,7 +176,13 @@ fn runMac(url: []const u8) !void {
const ns_url_str = sendStr(cls("NSString"), sel("stringWithUTF8String:"), url_z.ptr);
const ns_url = send1(cls("NSURL"), sel("URLWithString:"), ns_url_str);
- const request = send1(cls("NSURLRequest"), sel("requestWithURL:"), ns_url);
+ const request = sendRequestInit(
+ cls("NSURLRequest"),
+ sel("requestWithURL:cachePolicy:timeoutInterval:"),
+ ns_url,
+ NSURLRequestReloadIgnoringLocalCacheData,
+ load_timeout_s,
+ );
_ = send1(webview, sel("loadRequest:"), request);
send1v(window, sel("makeKeyAndOrderFront:"), null);