graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(native): packaged app uses its own UI and warms Chrome
Rach Pradhan6ca3c41cfef0
diff --git a/apps/native/app/api/browser/route.ts b/apps/native/app/api/browser/route.tsindex 0b88762d..30c28511 100644--- a/apps/native/app/api/browser/route.ts+++ b/apps/native/app/api/browser/route.ts@@ -168,6 +168,10 @@ export async function POST(req: NextRequest) {async function handle(chat: string, method: string, params: Record<string, unknown>): Promise<Response> {try {+ if (method === "warm") {+ await ensureKuri();+ return Response.json({ kuri: kuriState() });+ }if (method === "stop") {tabs.clear();stopKuri();diff --git a/apps/native/app/layout.tsx b/apps/native/app/layout.tsxindex 0f2a2789..b619e37c 100644--- a/apps/native/app/layout.tsx+++ b/apps/native/app/layout.tsx@@ -2,6 +2,7 @@ import type { Metadata } from "next";import { Inter, JetBrains_Mono } from "next/font/google";import "./globals.css";import { ThemeSync } from "@/components/site/ThemeSync";+import { BrowserWarm } from "@/components/site/BrowserWarm";const inter = Inter({subsets: ["latin"],@@ -30,6 +31,7 @@ export default function RootLayout({</head><body className={`${inter.variable} ${mono.variable} font-sans`}><ThemeSync />+ <BrowserWarm />{children}</body></html>diff --git a/apps/native/components/site/BrowserPane.tsx b/apps/native/components/site/BrowserPane.tsxindex f34951e6..1dfff34d 100644--- a/apps/native/components/site/BrowserPane.tsx+++ b/apps/native/components/site/BrowserPane.tsx@@ -223,7 +223,7 @@ export default function BrowserPane({const open = useCallback(async (target: string) => {- setBusy(infoRef.current ? "Loading…" : "Starting the browser…");+ setBusy(infoRef.current ? "Loading page…" : "Starting Chrome…");setError(null);try {const { width, height } = paneSize();@@ -674,14 +674,11 @@ export default function BrowserPane({onChange={(e) => setUrl(e.target.value)}onFocus={(e) => e.currentTarget.select()}spellCheck={false}- placeholder="localhost:3000 or a URL"+ placeholder="URL"aria-label="Address"title="Address (Cmd/Ctrl+L from the page)"className="h-7 min-w-0 flex-1 rounded-[7px] bg-field px-2 font-mono text-[12px] text-ink shadow-hairline outline-none placeholder:text-ink-3 focus:bg-hover"/>- <button type="submit" className="h-7 shrink-0 rounded-[7px] bg-hover-2 px-2.5 text-[12px] font-medium text-ink transition-colors hover:bg-line-strong">- Go- </button><selectvalue={String(preset)}onChange={(e) => setPreset(e.target.value === "fit" ? "fit" : (Number(e.target.value) as Preset))}@@ -826,7 +823,7 @@ export default function BrowserPane({</div>) : (<div className="flex h-full items-center justify-center px-6 text-center text-[12.5px] text-ink-3">- {busy ?? (error ? "" : "Enter an address above.")}+ {busy ?? (error ? "" : "Type a URL above. Chrome starts with the app.")}</div>)}{busy && src && (diff --git a/apps/native/components/site/BrowserWarm.tsx b/apps/native/components/site/BrowserWarm.tsxnew file mode 100644index 00000000..96ab071f--- /dev/null+++ b/apps/native/components/site/BrowserWarm.tsx@@ -0,0 +1,12 @@+"use client";++import { useEffect } from "react";+import { browserWarm } from "@/lib/browser-client";++/** Start Kuri's Chrome with the window, so opening the pane is not a wait. */+export function BrowserWarm() {+ useEffect(() => {+ void browserWarm().catch(() => undefined);+ }, []);+ return null;+}diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsxindex 73deed20..dde60f4a 100644--- a/apps/native/components/site/GraffHarness.tsx+++ b/apps/native/components/site/GraffHarness.tsx@@ -128,7 +128,7 @@ export default function GraffHarness() {try {if (!browserOpenRestored.current) {browserOpenRestored.current = true;- if (window.localStorage.getItem(BROWSER_OPEN_KEY) === "1") setBrowserOpen(true);+ if (window.localStorage.getItem(BROWSER_OPEN_KEY) !== "0") setBrowserOpen(true);return;}window.localStorage.setItem(BROWSER_OPEN_KEY, browserOpen ? "1" : "0");diff --git a/apps/native/desktop/main.zig b/apps/native/desktop/main.zigindex d97ff2bf..d86d690a 100644--- a/apps/native/desktop/main.zig+++ b/apps/native/desktop/main.zig@@ -83,18 +83,23 @@ pub fn main(init: std.process.Init) !void {}/// The URL the window opens, and whether anything is actually serving it.-/// Order matters: an explicit pin wins, then a dev server the developer is-/// already running, then the interface inside this bundle.+/// A packaged `.app` always starts the copy inside the bundle: a leftover+/// Next on :3000 from some other checkout is not this release. Loose+/// `graff-native` binaries still attach to a dev server first.fn resolve(init: std.process.Init, buf: []u8) struct { []const u8, bool } {if (init.environ_map.get("GRAFF_NATIVE_URL")) |pinned| return .{ pinned, true };- for (default_urls) |candidate| {- if (listening(candidate)) return .{ candidate, true };+ const bundle = bundlePath(init.gpa);+ const packaged = if (bundle) |b| std.mem.endsWith(u8, b, ".app") else false;+ if (!packaged) {+ for (default_urls) |candidate| {+ if (listening(candidate)) return .{ candidate, true };+ }}- // Set this to debug against a server you start yourself while still- // running the packaged app.+ // Set GRAFF_NATIVE_URL to debug against a server you start yourself+ // while still running the packaged app.if (init.environ_map.get("GRAFF_NATIVE_NO_SERVER") == null) {- if (bundlePath(init.gpa)) |bundle| {- if (server.start(init.gpa, init.io, init.environ_map, bundle)) |port| {+ if (bundle) |b| {+ if (server.start(init.gpa, init.io, init.environ_map, b)) |port| {const url = std.fmt.bufPrint(buf, "http://127.0.0.1:{d}", .{port}) catchreturn .{ default_urls[0], false };return .{ url, true };diff --git a/apps/native/lib/browser-client.ts b/apps/native/lib/browser-client.tsindex a801186d..01d9e347 100644--- a/apps/native/lib/browser-client.ts+++ b/apps/native/lib/browser-client.ts@@ -84,6 +84,7 @@ export function frameUrl(chat: string, quality: number, tick: number): string {return `${BASE}?chat=${encodeURIComponent(chat)}&frame=1&q=${quality}&t=${tick}`;}+export const browserWarm = () => browserCall<{ kuri: KuriState }>("default", "warm");export const browserOpen = (chat: string, url: string, width: number, height: number) =>browserCall<PageInfo>(chat, "open", { url, width, height });export const browserNavigate = (chat: string, url: string) => browserCall<PageInfo>(chat, "navigate", { url });