Skip to content

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

Python

feat(desktop): Updates settings for check and six-hour auto-download

Rach Pradhan85c64e22dee8
diff --git a/apps/native/components/site/DesktopUpdates.tsx b/apps/native/components/site/DesktopUpdates.tsx
index 9d9acd9b..b3cd52fa 100644
--- a/apps/native/components/site/DesktopUpdates.tsx
+++ b/apps/native/components/site/DesktopUpdates.tsx
@@ -2,41 +2,169 @@
import { useEffect, useRef, useState } from "react";
import { desktop, type UpdateState } from "@/lib/desktop";
+function statusCopy(state: UpdateState): string {
+ return {
+ idle: "Checks shortly after launch and every six hours.",
+ checking: "Checking for updates…",
+ current: `Codegraff ${state.currentVersion} is up to date.`,
+ downloading: `Downloading Codegraff ${state.version} · ${state.percent ?? 0}%`,
+ ready: `Codegraff ${state.version} is ready.`,
+ installing: "Preparing to restart…",
+ error: state.message ?? "Could not update.",
+ unavailable: state.message ?? "Install a signed release in Applications to receive updates.",
+ }[state.status];
+}
+
export default function DesktopUpdates() {
const [state, setState] = useState<UpdateState | null>(null);
const [dismissed, setDismissed] = useState(false);
- const previous = useRef<UpdateState['status'] | null>(null);
+ const [open, setOpen] = useState(false);
+ const previous = useRef<UpdateState["status"] | null>(null);
+ const panel = useRef<HTMLDivElement>(null);
useEffect(() => {
const bridge = desktop();
if (!bridge?.updates || !bridge.updateSubscribe) return;
let alive = true;
const receive = (next: UpdateState) => {
if (!alive) return;
- if (next.status !== 'downloading' || previous.current !== 'downloading') setDismissed(false);
+ if (next.status !== "downloading" || previous.current !== "downloading") setDismissed(false);
previous.current = next.status;
setState(next);
};
const unsubscribe = bridge.updateSubscribe(receive);
- void bridge.updates('state').then(receive).catch(() => {});
- return () => { alive = false; unsubscribe(); };
+ void bridge.updates("state").then(receive).catch(() => {});
+ return () => {
+ alive = false;
+ unsubscribe();
+ };
}, []);
- if (!state || dismissed || state.status === 'idle' || (!state.interactive && ['current', 'checking', 'error', 'unavailable'].includes(state.status))) return null;
- const message = {
- checking: 'Checking for updates…', current: `Codegraff ${state.currentVersion} is up to date.`,
- downloading: `Downloading Codegraff ${state.version} · ${state.percent ?? 0}%`,
- ready: `Codegraff ${state.version} is ready.`, installing: 'Preparing to restart…',
- error: state.message, unavailable: state.message,
- }[state.status];
- const act = async (action: 'check' | 'restart') => {
- try { const next = await desktop()?.updates?.(action); if (next) setState(next); }
- catch { setState({ ...state, status: 'error', interactive: true, message: 'Could not update. Please try again.' }); }
+ useEffect(() => {
+ if (!open) return;
+ const outside = (event: PointerEvent) => {
+ if (!panel.current?.contains(event.target as Node)) setOpen(false);
+ };
+ const keys = (event: KeyboardEvent) => {
+ if (event.key === "Escape") setOpen(false);
+ };
+ document.addEventListener("pointerdown", outside);
+ document.addEventListener("keydown", keys);
+ return () => {
+ document.removeEventListener("pointerdown", outside);
+ document.removeEventListener("keydown", keys);
+ };
+ }, [open]);
+ if (!state) return null;
+
+ const act = async (action: "check" | "restart" | "automatic", value?: boolean) => {
+ try {
+ const next = await desktop()?.updates?.(action, value);
+ if (next) setState(next);
+ } catch {
+ setState({ ...state, status: "error", interactive: true, message: "Could not update. Please try again." });
+ }
};
- return <div data-desktop-update className="fixed bottom-4 left-4 z-[110] w-80 max-w-[calc(100vw-32px)] rounded-xl border border-line bg-page p-3 text-sm text-ink shadow-card">
- <div className="flex items-center gap-3"><p role="status" className="min-w-0 flex-1">{message}</p>
- <button aria-label="Dismiss update notification" className="size-7 shrink-0 rounded hover:bg-hover" onClick={() => setDismissed(true)}>×</button></div>
- {state.status === 'downloading' && <progress aria-label="Update download" max={100} value={state.percent ?? 0} className="mt-2 h-1 w-full accent-current" />}
- {state.status === 'ready' && <><p className="mt-1 text-xs text-ink-3">Restart when your work is finished. Active tasks and terminals will stop.</p>
- <button className="mt-2 rounded-lg bg-ink px-3 py-1.5 text-page" onClick={() => void act('restart')}>Restart to update</button></>}
- {state.status === 'error' && <button className="mt-2 rounded-lg bg-hover px-3 py-1.5" onClick={() => void act('check')}>Try again</button>}
- </div>;
+
+ const toast =
+ !dismissed &&
+ state.status !== "idle" &&
+ (state.interactive || !["current", "checking", "error", "unavailable"].includes(state.status));
+
+ return (
+ <>
+ <div className="pointer-events-none fixed top-[calc(var(--desktop-title-height,0px)+10px)] right-3 z-[110]">
+ <button
+ type="button"
+ data-desktop-update-settings
+ aria-expanded={open}
+ aria-haspopup="dialog"
+ className="pointer-events-auto flex h-8 items-center gap-1.5 rounded-[8px] border border-line bg-page px-2.5 text-[12px] font-medium text-ink-2 shadow-hairline hover:bg-hover hover:text-ink"
+ onClick={() => setOpen((value) => !value)}
+ >
+ Updates
+ </button>
+ {open && (
+ <div
+ ref={panel}
+ role="dialog"
+ aria-label="Update settings"
+ data-desktop-update-panel
+ className="pointer-events-auto absolute right-0 mt-2 w-80 max-w-[calc(100vw-24px)] rounded-xl border border-line bg-page p-3 text-sm text-ink shadow-card"
+ >
+ <p className="text-[11px] font-medium tracking-wide text-ink-3 uppercase">App updates</p>
+ <p className="mt-1 text-[13px] text-ink">Codegraff {state.currentVersion}</p>
+ <p role="status" className="mt-1 text-[12px] leading-relaxed text-ink-2">
+ {statusCopy(state)}
+ </p>
+ {state.status === "downloading" && (
+ <progress aria-label="Update download" max={100} value={state.percent ?? 0} className="mt-2 h-1 w-full accent-current" />
+ )}
+ <div className="mt-3 flex flex-col gap-2">
+ <button
+ type="button"
+ data-desktop-update-check
+ className="rounded-lg bg-hover px-3 py-1.5 text-left text-[12.5px] font-medium hover:bg-hover-2"
+ onClick={() => void act("check")}
+ >
+ Check for Updates
+ </button>
+ {state.status === "ready" && (
+ <button
+ type="button"
+ className="rounded-lg bg-ink px-3 py-1.5 text-left text-[12.5px] font-medium text-page"
+ onClick={() => void act("restart")}
+ >
+ Restart to update
+ </button>
+ )}
+ <button
+ type="button"
+ data-desktop-update-automatic
+ role="switch"
+ aria-checked={state.automatic}
+ className="flex items-center justify-between rounded-lg px-1 py-1 text-[12.5px] text-ink-2 hover:bg-hover"
+ onClick={() => void act("automatic", !state.automatic)}
+ >
+ <span>Download updates automatically</span>
+ <span
+ aria-hidden
+ className={`ml-3 h-5 w-9 rounded-full p-0.5 transition-colors ${state.automatic ? "bg-accent" : "bg-hover-2"}`}
+ >
+ <span className={`block size-4 rounded-full bg-page transition-transform ${state.automatic ? "translate-x-4" : ""}`} />
+ </span>
+ </button>
+ <p className="px-1 text-[11px] leading-relaxed text-ink-3">
+ When this is on, Codegraff checks shortly after launch and every six hours. Restart is always yours to confirm.
+ </p>
+ </div>
+ </div>
+ )}
+ </div>
+ {toast && (
+ <div data-desktop-update className="fixed bottom-4 left-4 z-[110] w-80 max-w-[calc(100vw-32px)] rounded-xl border border-line bg-page p-3 text-sm text-ink shadow-card">
+ <div className="flex items-center gap-3">
+ <p role="status" className="min-w-0 flex-1">
+ {statusCopy(state)}
+ </p>
+ <button aria-label="Dismiss update notification" className="size-7 shrink-0 rounded hover:bg-hover" onClick={() => setDismissed(true)}>
+ ×
+ </button>
+ </div>
+ {state.status === "downloading" && <progress aria-label="Update download" max={100} value={state.percent ?? 0} className="mt-2 h-1 w-full accent-current" />}
+ {state.status === "ready" && (
+ <>
+ <p className="mt-1 text-xs text-ink-3">Restart when your work is finished. Active tasks and terminals will stop.</p>
+ <button className="mt-2 rounded-lg bg-ink px-3 py-1.5 text-page" onClick={() => void act("restart")}>
+ Restart to update
+ </button>
+ </>
+ )}
+ {state.status === "error" && (
+ <button className="mt-2 rounded-lg bg-hover px-3 py-1.5" onClick={() => void act("check")}>
+ Try again
+ </button>
+ )}
+ </div>
+ )}
+ </>
+ );
}
diff --git a/apps/native/electron/README.md b/apps/native/electron/README.md
index 4367b32d..9aca3f1f 100644
--- a/apps/native/electron/README.md
+++ b/apps/native/electron/README.md
@@ -151,8 +151,8 @@ Never publish a development bundle as the signed download.
Signed distribution builds check the public GitHub release feed shortly after
launch and every six hours. Downloads happen in the background. The notification
shows progress and offers **Restart to update**; downloading never stops a task,
-and closing the app does not silently install an update. The Codegraff menu has
-**Check for Updates…** and an **Automatically Download Updates** preference.
+and closing the app does not silently install an update. The Codegraff menu has **Check for Updates…** and **Automatically Download Updates**.
+The app chrome also has an **Updates** settings panel for the same check and preference.
Development builds, smoke tests and apps running from a mounted disk image do not
check online. Install the app in Applications first.
diff --git a/apps/native/electron/preload.cjs b/apps/native/electron/preload.cjs
index 64178f4e..b8442405 100644
--- a/apps/native/electron/preload.cjs
+++ b/apps/native/electron/preload.cjs
@@ -1,7 +1,7 @@
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('graffDesktop', {
projects: (action, value) => ipcRenderer.invoke('projects', { action, value }),
- updates: action => ipcRenderer.invoke('updates', action),
+ updates: (action, value) => ipcRenderer.invoke('updates', action, value),
updateSubscribe: callback => {
const listener = (_event, state) => callback(state);
ipcRenderer.on('update-state', listener);
diff --git a/apps/native/electron/updates-visual.cjs b/apps/native/electron/updates-visual.cjs
index 64c80874..6bb75efc 100644
--- a/apps/native/electron/updates-visual.cjs
+++ b/apps/native/electron/updates-visual.cjs
@@ -9,8 +9,15 @@ async function runUpdateVisuals({ origin, output }) {
wc.debugger.attach('1.3');
await wc.debugger.sendCommand('Page.enable');
await wc.debugger.sendCommand('Page.addScriptToEvaluateOnNewDocument', { source: `
- window.__restarts=0;let listener;window.__update=state=>listener?.({currentVersion:'1.0.0',automatic:true,interactive:false,...state});
- window.graffDesktop={updateSubscribe:fn=>{listener=fn;return()=>{}},updates:async action=>{if(action==='restart'){window.__restarts++;return {status:'installing'}}return {status:'idle'}}};` });
+ window.__restarts=0;window.__automatic=true;let listener;
+ const base=()=>({currentVersion:'1.0.0',automatic:window.__automatic,interactive:false});
+ window.__update=state=>listener?.({...base(),...state});
+ window.graffDesktop={updateSubscribe:fn=>{listener=fn;return()=>{}},updates:async(action,value)=>{
+ if(action==='restart'){window.__restarts++;const s={...base(),status:'installing'};listener?.(s);return s;}
+ if(action==='check'){const s={...base(),status:'checking',interactive:true};listener?.(s);return s;}
+ if(action==='automatic'){window.__automatic=!!value;const s={...base(),status:'idle'};listener?.(s);return s;}
+ return {...base(),status:'idle'};
+ }};` });
await win.loadURL(`${origin}/visual-tests`);
win.focus();
console.log('Update visual fixture loaded.');
@@ -41,7 +48,16 @@ async function runUpdateVisuals({ origin, output }) {
wc.sendInputEvent({ type: 'mouseUp', x: Math.round(target.x), y: Math.round(target.y), button: 'left', clickCount: 1 });
await wait(`window.__restarts===1`);
await wait(`document.querySelector('[data-desktop-update]')?.textContent.includes('Preparing to restart')`);
- console.log('Update UI passed: quiet checks/errors, download progress, explicit restart only.');
+ await js(`document.querySelector('[data-desktop-update-settings]').click()`);
+ await wait(`!!document.querySelector('[data-desktop-update-panel]')`);
+ assert.equal(await js(`document.querySelector('[data-desktop-update-panel]')?.textContent.includes('every six hours')`), true, 'settings explain the six-hour poll');
+ await js(`document.querySelector('[data-desktop-update-check]').click()`);
+ await wait(`document.querySelector('[data-desktop-update-panel]')?.textContent.includes('Checking for updates')`);
+ await js(`document.querySelector('[data-desktop-update-automatic]').click()`);
+ await wait(`document.querySelector('[data-desktop-update-automatic]')?.getAttribute('aria-checked')==='false'`);
+ assert.equal(await js('window.__automatic'), false, 'settings toggle persists automatic downloads');
+ fs.writeFileSync(path.join(output, 'update-settings.png'), (await wc.capturePage(undefined, { stayAwake: true })).toPNG());
+ console.log('Update UI passed: quiet checks/errors, download progress, explicit restart, in-app settings.');
} finally { win.destroy(); }
}
module.exports = { runUpdateVisuals };
diff --git a/apps/native/electron/updates.cjs b/apps/native/electron/updates.cjs
index ba10249d..c8647db7 100644
--- a/apps/native/electron/updates.cjs
+++ b/apps/native/electron/updates.cjs
@@ -1,6 +1,9 @@
const fs = require('node:fs');
const path = require('node:path');
+const FIRST_CHECK_MS = 30_000;
+const POLL_MS = 6 * 60 * 60 * 1000;
+
function createUpdates({ updater, version, available = true, automatic = true, notify, save = () => {}, onReady }) {
let state = { status: available ? 'idle' : 'unavailable', currentVersion: version, automatic, interactive: false };
let checking = false;
@@ -64,10 +67,14 @@ function installUpdates({ app, win, ipcMain, trusted, resources }) {
try { automatic = JSON.parse(fs.readFileSync(prefs, 'utf8')).automatic !== false; } catch {}
const available = app.isPackaged && process.platform === 'darwin' && !process.env.GRAFF_ELECTRON_SMOKE &&
!process.execPath.startsWith('/Volumes/') && fs.existsSync(path.join(resources, 'app-update.yml'));
+ let autoItem;
const controller = createUpdates({ version: app.getVersion(), automatic, available,
updater: available ? require('./updater-runtime.cjs') : null,
save: value => { fs.mkdirSync(path.dirname(prefs), { recursive: true }); fs.writeFileSync(prefs, JSON.stringify({ automatic: value })); },
- notify: state => { if (!win.isDestroyed()) { win.webContents.send('update-state', state); win.setProgressBar(state.status === 'downloading' ? (state.percent ?? 0) / 100 : -1); } },
+ notify: state => {
+ if (autoItem) autoItem.checked = state.automatic;
+ if (!win.isDestroyed()) { win.webContents.send('update-state', state); win.setProgressBar(state.status === 'downloading' ? (state.percent ?? 0) / 100 : -1); }
+ },
onReady: readyVersion => {
// The standard update modal (Sparkle/electron-updater style): pops once
// per downloaded version, after the download — never mid-conversation.
@@ -83,21 +90,23 @@ function installUpdates({ app, win, ipcMain, trusted, resources }) {
}).catch(() => {});
},
});
- ipcMain.handle('updates', async (event, action) => {
+ autoItem = { label: 'Automatically Download Updates', type: 'checkbox', checked: automatic,
+ click: item => controller.setAutomatic(item.checked) };
+ ipcMain.handle('updates', async (event, action, value) => {
trusted(event);
if (action === 'check') await controller.check(true);
else if (action === 'restart') controller.restart();
+ else if (action === 'automatic') controller.setAutomatic(!!value);
else if (action !== 'state') throw Error('Unknown update action');
return controller.state();
});
const check = () => { if (controller.state().automatic) void controller.check(); };
- const first = setTimeout(check, 30000), repeat = setInterval(check, 6 * 60 * 60 * 1000);
+ const first = setTimeout(check, FIRST_CHECK_MS), repeat = setInterval(check, POLL_MS);
first.unref(); repeat.unref();
app.once('before-quit', () => { clearTimeout(first); clearInterval(repeat); });
return [
{ label: 'Check for Updates…', click: () => void controller.check(true) },
- { label: 'Automatically Download Updates', type: 'checkbox', checked: automatic,
- click: item => controller.setAutomatic(item.checked) },
+ autoItem,
];
}
-module.exports = { createUpdates, installUpdates };
+module.exports = { createUpdates, installUpdates, FIRST_CHECK_MS, POLL_MS };
diff --git a/apps/native/electron/updates.test.cjs b/apps/native/electron/updates.test.cjs
index d64775a9..69c8739f 100644
--- a/apps/native/electron/updates.test.cjs
+++ b/apps/native/electron/updates.test.cjs
@@ -77,3 +77,17 @@ test('the ready modal pops once per version, never in a dismiss loop', async ()
f.updater.emit('update-downloaded', { version: '1.0.2' });
expect(f.ready).toEqual(['1.0.1', '1.0.2']);
});
+
+test('automatic checks wait 30s after launch then every six hours', () => {
+ const { FIRST_CHECK_MS, POLL_MS } = require('./updates.cjs');
+ expect(FIRST_CHECK_MS).toBe(30_000);
+ expect(POLL_MS).toBe(6 * 60 * 60 * 1000);
+});
+
+test('in-app settings expose check and the six-hour automatic poll', () => {
+ const src = require('node:fs').readFileSync(require('node:path').join(__dirname, '../components/site/DesktopUpdates.tsx'), 'utf8');
+ expect(src).toContain('data-desktop-update-settings');
+ expect(src).toContain('Check for Updates');
+ expect(src).toContain('every six hours');
+ expect(src).toContain('data-desktop-update-automatic');
+});
diff --git a/apps/native/lib/desktop.ts b/apps/native/lib/desktop.ts
index 629359b6..165080a6 100644
--- a/apps/native/lib/desktop.ts
+++ b/apps/native/lib/desktop.ts
@@ -6,7 +6,7 @@ export type TerminalEvent = { id: string; seq: number; data?: string; exit?: num
export type UpdateState = { status: 'idle' | 'unavailable' | 'checking' | 'current' | 'downloading' | 'ready' | 'installing' | 'error'; currentVersion: string; version?: string; percent?: number; automatic: boolean; interactive: boolean; message?: string };
export type DesktopBridge = {
projects?(action: 'load' | 'save', value?: { list: import('./workspaces').Workspace[]; active: string | null }): Promise<{ list: import('./workspaces').Workspace[]; active: string | null } | null | void>;
- updates?(action: 'state' | 'check' | 'restart'): Promise<UpdateState>;
+ updates?(action: 'state' | 'check' | 'restart' | 'automatic', value?: boolean): Promise<UpdateState>;
updateSubscribe?(callback: (state: UpdateState) => void): () => void;
terminal?(action: string, params?: Record<string, unknown>): Promise<{id: string; seq: number; history: string; exit: number | null}>;
terminalSubscribe?(callback: (event: TerminalEvent) => void): () => void;