A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.
TypeScript
feat(package): build the Windows NSIS installer from a staged runtime
Marcelito6ebccb916c61
diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.ymlindex 09db519..b53d4ba 100644--- a/.github/workflows/windows.yml+++ b/.github/workflows/windows.yml@@ -96,5 +96,5 @@ jobs:# The daemon test files that run on Windows (the runtime build uses the addon built above).- name: Daemon tests- run: pnpm exec vitest run packages/daemon/test/windows-stop.test.ts packages/daemon/test/windows-app-channel.test.ts packages/daemon/test/app-channel-platform.test.ts packages/daemon/test/app-channel.test.ts packages/daemon/test/app-channel-fd.test.ts packages/daemon/test/windows-app-channel-addon.test.ts packages/daemon/test/process-tree.test.ts packages/daemon/test/supervisor.test.ts packages/daemon/test/runtime.test.ts packages/daemon/test/config.test.ts packages/daemon/test/isolation.test.ts packages/daemon/test/private-memory.test.ts packages/daemon/test/lifecycle.test.ts packages/daemon/test/cli.test.ts packages/daemon/test/runtime-build.test.ts scripts/package/test/lib.test.ts+ run: pnpm exec vitest run packages/daemon/test/windows-stop.test.ts packages/daemon/test/windows-app-channel.test.ts packages/daemon/test/app-channel-platform.test.ts packages/daemon/test/app-channel.test.ts packages/daemon/test/app-channel-fd.test.ts packages/daemon/test/windows-app-channel-addon.test.ts packages/daemon/test/process-tree.test.ts packages/daemon/test/supervisor.test.ts packages/daemon/test/runtime.test.ts packages/daemon/test/config.test.ts packages/daemon/test/isolation.test.ts packages/daemon/test/private-memory.test.ts packages/daemon/test/lifecycle.test.ts packages/daemon/test/cli.test.ts packages/daemon/test/runtime-build.test.ts scripts/package/test/lib.test.ts scripts/package/test/package-windows.test.tsdiff --git a/README.md b/README.mdindex 16acf82..cce4082 100644--- a/README.md+++ b/README.md@@ -106,7 +106,7 @@ Attach files with the paperclip, drag and drop, or paste. Images go straight to## Get started-There are no published releases yet: build the installer for your system. You need Node.js 24 and pnpm; the macOS app also needs Rust and the Xcode command line tools, and the Linux packages need Docker.+There are no published releases yet: build the installer for your system. You need Node.js 24 and pnpm; the macOS app also needs Rust and the Xcode command line tools, the Linux packages need Docker, and the Windows installer needs Rust, Visual Studio's C++ build tools and Go (see [docs/install.md](docs/install.md#windows)).```shpnpm install@@ -117,6 +117,10 @@ pnpm package:mac# Linux: a .deb (amd64 also builds the Arch package)pnpm package:linux --arch arm64pnpm package:linux --arch amd64++# Windows (x64): an NSIS installer, after building the native addon+pnpm package:runtime --target windows-x64+pnpm package:windows```Then follow **[docs/install.md](docs/install.md)**: opening an unsigned app on macOS 15 and later goes through **System Settings → Privacy & Security → Open Anyway**, and the guide covers permissions, where your data lives, and uninstalling.diff --git a/docs/install.md b/docs/install.mdindex 8dca2b6..17a4ebe 100644--- a/docs/install.md+++ b/docs/install.md@@ -80,6 +80,26 @@ To keep permissions across updates, sign every release with the same identity. `The command stages the runtime (`build/runtime/darwin-arm64`), signs the runtime's binaries, builds the release app, and writes the DMG to `apps/desktop/src-tauri/target/release/bundle/dmg/`. `--skip-stage` reuses a runtime staged earlier; `--check-dmg <dmg>` checks an existing DMG without building.+## Windows++### Build the installer from source++On Windows 10 or 11 (x64) with Node 24, pnpm, Rust, Visual Studio's C++ build tools (for the native addon), and Go 1.25.10 or newer:++```powershell+pnpm install+pnpm --filter @gentle-dot/daemon build:windows-stop -- --compiler <cl.exe> --headers <node-headers>/include/node --node-lib <node.lib>+$env:GENTLE_DOT_BUILD_GO = "C:\Program Files\Go\bin\go.exe"+pnpm package:runtime --target windows-x64+pnpm package:windows+```++- `build:windows-stop` builds `packages/daemon/native/windows-stop.node`, the native stop and app channel addon. The runtime build refuses to stage without it. `.github/workflows/windows.yml` shows the exact compiler, headers and `node.lib` it uses.+- `GENTLE_DOT_BUILD_GO` must be the full path of the real `go.exe` in `GOROOT\bin`, not a package manager shim. gentle-pi's postinstall builds gentle-ai from source with it. Only that directory joins the installer's `PATH`, which otherwise holds the staged Node and the Windows system folders.+- Run both commands through pnpm: on Windows, staging calls pnpm through Node instead of spawning `pnpm.cmd`.+- `package:runtime` writes `build/runtime/windows-x64` (about 320 MB): Node from its official ZIP, Engram's `engram.exe`, the daemon with its dependencies, and the web UI, each download checked against its published checksums.+- `package:windows` only packages a runtime staged earlier (`--runtime <dir>` names another one, on the same drive as the checkout). It builds an NSIS installer into `apps/desktop/src-tauri/target/release/bundle/nsis/`. Where WebView2 is missing, the installer runs Microsoft's bootstrapper, which needs the internet at that moment. WebView2 ships with Windows 11 and most Windows 10 installs.+## LinuxGentle Dot ships as a self-contained package: it carries its own Node.js, assistant engine, and Engram, so nothing else needs to be installed first. Pick the file for your system (`dpkg --print-architecture` or `uname -m` tells which):diff --git a/package.json b/package.jsonindex ae07209..466e2de 100644--- a/package.json+++ b/package.json@@ -18,6 +18,7 @@"format": "biome format --write .","test:real": "GENTLE_DOT_REAL_AGENT=1 vitest run packages/daemon/test/real-agent.test.ts","package:mac": "node scripts/package/package-mac.mjs",+ "package:windows": "node scripts/package/package-windows.mjs","package:linux": "node scripts/package/package-linux.mjs","package:linux:check": "node scripts/package/linux-check.mjs"},diff --git a/scripts/package/package-windows.mjs b/scripts/package/package-windows.mjsnew file mode 100644index 0000000..1e49713--- /dev/null+++ b/scripts/package/package-windows.mjs@@ -0,0 +1,71 @@+#!/usr/bin/env node+// Package an already staged native Windows x64 runtime. No staging, installs, or launch checks.+import { spawnSync } from "node:child_process";+import { readFileSync, statSync } from "node:fs";+import { resolve } from "node:path";+import { fileURLToPath } from "node:url";+import { assertWindowsHost, parseWindowsArgs, WINDOWS_USAGE, windowsPackagePlan } from "./windows-lib.mjs";++function isKind(path, kind) {+ try {+ return statSync(path)[kind]();+ } catch {+ return false;+ }+}++function main() {+ const options = parseWindowsArgs(process.argv.slice(2));+ if (options.help) {+ process.stdout.write(`${WINDOWS_USAGE}\n`);+ return;+ }+ // Admit the native host before reading staged files or invoking any build tools.+ assertWindowsHost(process.platform, process.arch);+ const repo = fileURLToPath(new URL("../..", import.meta.url));+ const runtime = resolve(+ process.env.INIT_CWD ?? process.cwd(),+ options.runtime ?? resolve(repo, "build/runtime/windows-x64"),+ );+ let manifest;+ try {+ manifest = JSON.parse(readFileSync(resolve(runtime, "MANIFEST.json"), "utf8"));+ } catch {+ throw new Error(+ `Missing or invalid MANIFEST.json in ${runtime}; stage the Windows runtime explicitly first.`,+ );+ }+ const plan = windowsPackagePlan({+ repo,+ runtime,+ platform: process.platform,+ arch: process.arch,+ node: process.execPath,+ manifest,+ isFile: (path) => isKind(path, "isFile"),+ isDirectory: (path) => isKind(path, "isDirectory"),+ });+ // Run the repository's installed CLI via Node, never pnpm.cmd through execFile/spawn.+ process.stdout.write(+ `Using ${runtime}; tauri build --bundles nsis (no staging; the installer adds WebView2 when missing).\n`,+ );+ const result = spawnSync(plan.program, plan.args, {+ cwd: plan.cwd,+ env: { ...process.env, ...plan.env },+ stdio: "inherit",+ });+ if (result.error || result.status !== 0)+ throw new Error(+ `Windows package build failed (${result.error?.message ?? `exit ${result.status}, signal ${result.signal ?? "none"}`}).`,+ );+ process.stdout.write(+ "NSIS build finished; installer/installed runtime has not been exercised by this command.\n",+ );+}++try {+ main();+} catch (error) {+ process.stderr.write(`package-windows: ${error.message}\n`);+ process.exitCode = 1;+}diff --git a/scripts/package/test/package-windows.test.ts b/scripts/package/test/package-windows.test.tsnew file mode 100644index 0000000..748e88e--- /dev/null+++ b/scripts/package/test/package-windows.test.ts@@ -0,0 +1,148 @@+import { readFileSync } from "node:fs";+import { resolve, win32 } from "node:path";+import { describe, expect, it } from "vitest";+import { parseWindowsArgs, WINDOWS_FILES, windowsPackagePlan } from "../windows-lib.mjs";++const manifest = { name: "gentle-dot-runtime", target: "windows-x64" };+const options = {+ repo: resolve("checkout with spaces"),+ runtime: resolve("staged runtime"),+ platform: "win32",+ arch: "x64",+ node: "C:\\Program Files\\nodejs\\node.exe",+ manifest,+ isFile: () => true,+ isDirectory: () => true,+};++describe("Windows package admission and plan (no commands executed)", () => {+ it("parses only the existing runtime override and help", () => {+ expect(parseWindowsArgs([])).toEqual({});+ expect(parseWindowsArgs(["--", "--runtime", "C:\\staged runtime"])).toEqual({+ runtime: "C:\\staged runtime",+ });+ expect(parseWindowsArgs(["--help"])).toEqual({ help: true });+ for (const args of [["--runtime"], ["--runtime", ""], ["--stage"], ["--bundles", "msi"]])+ expect(() => parseWindowsArgs(args)).toThrow();+ });+ it("rejects unsupported hosts and architectures before reading artifacts", () => {+ for (const [platform, arch] of [+ ["linux", "x64"],+ ["win32", "arm64"],+ ["darwin", "arm64"],+ ]) {+ expect(() =>+ windowsPackagePlan({+ ...options,+ platform,+ arch,+ isFile: () => {+ throw new Error("artifact read");+ },+ }),+ ).toThrow(/native Windows x64/);+ }+ });+ it("rejects wrong or absent manifest and every missing prerequisite", () => {+ for (const value of [undefined, {}, { ...manifest, target: "linux-x64" }, { ...manifest, name: "other" }])+ expect(() => windowsPackagePlan({ ...options, manifest: value })).toThrow(/MANIFEST/);+ for (const file of WINDOWS_FILES)+ expect(() =>+ windowsPackagePlan({ ...options, isFile: (path: string) => path !== resolve(options.runtime, file) }),+ ).toThrow(file);+ expect(() =>+ windowsPackagePlan({ ...options, isFile: (path: string) => !path.endsWith("tauri.js") }),+ ).toThrow(/tauri.js/);+ expect(() =>+ windowsPackagePlan({ ...options, isFile: (path: string) => !path.endsWith("icon.ico") }),+ ).toThrow(/icon.ico/);+ expect(() => windowsPackagePlan({ ...options, isDirectory: () => false })).toThrow(/gentle-ai/);+ });+ it("keeps resource paths as JSON arguments, uses local CLI through Node, and never stages or installs", () => {+ const plan = windowsPackagePlan(options);+ expect(plan.program).toBe(options.node);+ expect(plan.cwd).toBe(resolve(options.repo, "apps/desktop"));+ expect(plan.args.slice(1, 4)).toEqual(["build", "--bundles", "nsis"]);+ expect(plan.env).toEqual({ GENTLE_DOT_WINDOWS_PACKAGED_REQUIRED: "1" });+ const config = JSON.parse(plan.args[5]);+ expect(config.bundle.resources).toEqual({ [options.runtime]: "runtime" });+ expect(config.build.beforeBuildCommand).toBe("");+ expect(config.build.frontendDist).toMatch(/^\.\//);+ expect(resolve(options.repo, "apps/desktop/src-tauri", config.build.frontendDist)).toBe(+ resolve(options.runtime, "ui"),+ );+ // The installer brings WebView2 only when the machine lacks it, through the embedded bootstrapper.+ expect(config.bundle.windows.webviewInstallMode).toEqual({ type: "embedBootstrapper", silent: true });+ expect(plan.args.join(" ")).not.toMatch(/\.cmd|stage-runtime|install|download/);+ const windowsPath = 'C:\\staged runtime\\quoted "folder"';+ const quoted = windowsPackagePlan({+ ...options,+ repo: "C:\\checkout",+ runtime: windowsPath,+ path: win32,+ });+ expect(JSON.parse(quoted.args[5]).bundle.resources).toEqual({ [windowsPath]: "runtime" });+ });+ it("reproduces the cannot-be-base URL failure of an absolute Windows frontend path", () => {+ const absolute = new URL(win32.resolve("C:\\staged runtime", "ui"));+ expect(absolute.protocol).toBe("c:");+ expect(() => new URL("index.html?surface=panel&effects=none", absolute)).toThrow();+ });+ it("uses a directory relative to src-tauri, not the desktop cwd, on Windows with spaces", () => {+ const repo = "C:\\workspace\\checkout with spaces";+ const runtime = "C:\\workspace\\staged runtime";+ const plan = windowsPackagePlan({ ...options, repo, runtime, path: win32 });+ const config = JSON.parse(plan.args[5]);+ expect(plan.cwd).toBe(win32.resolve(repo, "apps/desktop"));+ expect(config.build.frontendDist).toBe("./../../../../staged runtime/ui");+ expect(win32.resolve(repo, "apps/desktop/src-tauri", config.build.frontendDist)).toBe(+ win32.resolve(runtime, "ui"),+ );+ expect(win32.resolve(plan.cwd, config.build.frontendDist)).not.toBe(win32.resolve(runtime, "ui"));+ expect(() => new URL(config.build.frontendDist)).toThrow();+ expect(config.bundle.resources).toEqual({ [runtime]: "runtime" });+ });+ it("prefixes a relative directory whose first component could otherwise be a URL scheme", () => {+ const runtime = resolve(options.repo, "apps/desktop/src-tauri/c:assets");+ const config = JSON.parse(windowsPackagePlan({ ...options, runtime }).args[5]);+ expect(config.build.frontendDist).toBe("./c:assets/ui");+ expect(() => new URL(config.build.frontendDist)).toThrow();+ });+ it("accepts same-share UNC paths and case-insensitive drive roots", () => {+ for (const [repo, runtime] of [+ ["\\\\server\\share\\checkout", "\\\\server\\share\\staged runtime"],+ ["C:\\checkout", "c:\\staged runtime"],+ ]) {+ const plan = windowsPackagePlan({ ...options, repo, runtime, path: win32 });+ const frontend = JSON.parse(plan.args[5]).build.frontendDist;+ expect(frontend).toMatch(/^\.\//);+ expect(win32.resolve(repo, "apps/desktop/src-tauri", frontend).toLowerCase()).toBe(+ win32.resolve(runtime, "ui").toLowerCase(),+ );+ }+ });+ it("rejects cross-volume and cross-share frontend paths before a build can be planned", () => {+ for (const [repo, runtime] of [+ ["C:\\checkout", "D:\\staged runtime"],+ ["\\\\server\\checkout\\repo", "\\\\server\\runtime\\staged"],+ ]) {+ expect(() => windowsPackagePlan({ ...options, repo, runtime, path: win32 })).toThrow(+ /frontendDist.*relative.*src-tauri/i,+ );+ }+ });+});++it("wires package-only marker to fallible admission before launch without changing launch_spec", () => {+ const build = readFileSync("apps/desktop/src-tauri/build.rs", "utf8");+ const daemon = readFileSync("apps/desktop/src-tauri/src/daemon.rs", "utf8");+ const launch = readFileSync("apps/desktop/src-tauri/src/daemon/launch.rs", "utf8");+ expect(build).toContain("cargo:rerun-if-env-changed=GENTLE_DOT_WINDOWS_PACKAGED_REQUIRED");+ expect(build).toContain("cargo:rustc-env=GENTLE_DOT_WINDOWS_PACKAGED_REQUIRED=");+ expect(build).toContain('env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows")');+ expect(daemon).toContain("cfg!(windows) && !cfg!(debug_assertions)");+ expect(daemon).toContain('option_env!("GENTLE_DOT_WINDOWS_PACKAGED_REQUIRED") == Some("1")');+ expect(daemon).toMatch(/validate_packaged_runtime\([\s\S]*?\)\?;\s*launch_spec\(/);+ expect(launch).toContain("pub fn validate_packaged_runtime(");+ expect(launch).toContain("pub fn launch_spec(");+});diff --git a/scripts/package/windows-lib.mjs b/scripts/package/windows-lib.mjsnew file mode 100644index 0000000..6fdb70f--- /dev/null+++ b/scripts/package/windows-lib.mjs@@ -0,0 +1,94 @@+// Windows packaging consumes an existing runtime; it never stages or installs one.+import hostPath from "node:path";++export const WINDOWS_USAGE =+ "usage: package-windows [--runtime <staged-dir>] [--help]\n" ++ "Native Windows x64 only; consumes build/runtime/windows-x64 by default. Builds NSIS; the installer adds WebView2 when missing (needs internet then).";+export const WINDOWS_FILES = Object.freeze([+ "MANIFEST.json",+ "node/bin/node.exe",+ "daemon/cli.mjs",+ "daemon/package.json",+ "daemon/native/windows-stop.node",+ "daemon/node_modules/gentle-pi/package.json",+ "bin/engram.exe",+ "bin/pi.cmd",+ "ui/index.html",+]);++export function parseWindowsArgs(argv) {+ const args = argv.filter((arg) => arg !== "--");+ if (args.length === 1 && args[0] === "--help") return { help: true };+ if (args.length === 0) return {};+ if (args.length === 2 && args[0] === "--runtime" && args[1] && !args[1].startsWith("--"))+ return { runtime: args[1] };+ throw new Error(WINDOWS_USAGE);+}++export function assertWindowsHost(platform, arch) {+ if (platform !== "win32" || arch !== "x64")+ throw new Error(+ `Packaging requires native Windows x64; got ${platform}-${arch}. No cross-build or implicit staging.`,+ );+}++/** Pure admission/argument plan. The CLI supplies filesystem predicates; tests execute no build. */+export function windowsPackagePlan({+ repo,+ runtime,+ platform,+ arch,+ node,+ manifest,+ isFile,+ isDirectory,+ path = hostPath,+}) {+ assertWindowsHost(platform, arch);+ const { resolve } = path;+ if (manifest?.name !== "gentle-dot-runtime" || manifest?.target !== "windows-x64")+ throw new Error("MANIFEST.json must describe a staged gentle-dot-runtime for windows-x64.");+ const desktop = resolve(repo, "apps/desktop");+ const cli = resolve(desktop, "node_modules/@tauri-apps/cli/tauri.js");+ const icon = resolve(desktop, "src-tauri/icons/icon.ico");+ for (const file of WINDOWS_FILES) {+ if (!isFile(resolve(runtime, file)))+ throw new Error(`Missing staged artifact ${file} in ${runtime}. Stage explicitly before packaging.`);+ }+ if (!isDirectory(resolve(runtime, "daemon/node_modules/gentle-pi/.gentle-ai")))+ throw new Error("Missing staged gentle-pi/.gentle-ai agent. Stage explicitly before packaging.");+ for (const file of [cli, icon])+ if (!isFile(file))+ throw new Error(`Missing packaging prerequisite ${file}; provision it explicitly before packaging.`);+ // Tauri resolves directories from src-tauri, not the CLI cwd. Absolute drive+ // paths deserialize as URLs (e.g. c:), whose relative page joins can panic.+ const configDir = resolve(desktop, "src-tauri");+ const frontendDir = resolve(runtime, "ui");+ const frontend = path.relative(configDir, frontendDir);+ // win32.relative can traverse between shares on one server, but Windows+ // cannot traverse above a share root. Compare roots as well as absoluteness.+ const differentWindowsRoots =+ path.sep === "\\" &&+ path.parse(configDir).root.toLowerCase() !== path.parse(frontendDir).root.toLowerCase();+ if (differentWindowsRoots || path.isAbsolute(frontend))+ throw new Error(+ "frontendDist must be relative to src-tauri; place the staged runtime on the same volume/share as the checkout.",+ );+ const config = {+ build: { beforeBuildCommand: "", frontendDist: `./${frontend.split(path.sep).join("/")}` },+ bundle: {+ resources: { [runtime]: "runtime" },+ icon: ["icons/icon.ico"],+ // WebView2 comes with Windows 11 and most Windows 10; where it is missing, the installer+ // runs Microsoft's embedded bootstrapper (about 1.8 MB, downloaded once at build time),+ // which installs it from the internet.+ windows: { webviewInstallMode: { type: "embedBootstrapper", silent: true } },+ },+ };+ return {+ program: node,+ args: [cli, "build", "--bundles", "nsis", "--config", JSON.stringify(config)],+ cwd: desktop,+ env: { GENTLE_DOT_WINDOWS_PACKAGED_REQUIRED: "1" },+ };+}