Skip to content

AI, fully local on your computer.

16.0 KB
Raw Blame
# electron-builder configuration — HilbertRaum (Phase 11, spec §12).
#
# Goal: a PORTABLE Windows build that launches from an external drive. macOS/Linux
# targets are defined for architecture parity (spec rule: keep all three supported),
# even though only Windows is produced on this dev machine.
#
# OFFLINE GUARANTEE: packaging adds NO runtime network dependency. The real backends
# spawn `llama-server` on 127.0.0.1 only (Phase 10). The only network is dev-time
# (Electron binary download R2, npm install R6). One INBOUND listener can exist at
# runtime — the opt-in local API (Settings -> Privacy & data), off by default, bound to
# 127.0.0.1/::1 only, torn down on lock/quit, and forbiddable by drive policy. It is not
# a network dependency: nothing is contacted, and a build never opens it on its own.
#
# node:sqlite REQUIREMENT: the packaged main process needs Electron >= 37 (Node 22.x);
# `electron` is pinned to ^43.8.10 in devDependencies, so the bundled runtime has node:sqlite.
# A stripped/older runtime would lose it — do not downgrade Electron.
#
# Producing the actual artifact is a MANUAL step (R2/R5): see docs/packaging.md.

appId: space.hilbertraum.app
productName: HilbertRaum
# electron-builder derives the per-platform executable/AppImage name from the npm package name,
# which in this monorepo is the scoped "@hilbertraum/desktop" → "@hilbertraumdesktop"; the '@' is
# rejected as an unsafe path char and the build fails (first seen on the linux AppImage target,
# and it now hits mac/win too since the desktop package was renamed to a scoped name). Pin an
# explicit, path-safe name for every platform. Keep in sync with productName.
executableName: HilbertRaum

# electron-builder 26 cannot auto-detect the Electron version in this npm workspace: `electron`
# is pinned as a RANGE (^43.8.10 in devDependencies) and is HOISTED to the repo-root node_modules,
# which eb — running from apps/desktop — does not resolve, so it errors on the range. Pin the
# exact installed version here. Keep in sync with the `electron` devDependency (currently ^43.8.10 →
# 43.8.10); bump whenever the locked version changes, patch releases included.
#
# THIS FIELD, NOT THE devDependency, SELECTS THE RUNTIME THAT IS ACTUALLY PACKAGED. Wave DEP-1
# shipped Electron 37 from a build whose devDep said 39 because this line was left behind, and a
# human caught it by luck (DEP-1 §4(b)). Since wave DEP-4 that is guarded automatically:
# tests/integration/packaging.test.ts asserts this value equals the electron version pinned in
# package-lock.json (which `npm ci` installs, so it satisfies the declared range). Edit both or
# the green gate fails.
electronVersion: 43.8.10

# Electron fuses (#560, #562, #564), flipped in the packaged binary by @electron/fuses before signing.
# Measured on 43.7.7, re-checked on 43.8.0, 43.8.3, 43.8.6, 43.8.7 and 43.8.10; the record is
# docs/architecture.md "Electron fuses — design record (#562)".
#  - runAsNode OFF: ELECTRON_RUN_AS_NODE no longer turns HilbertRaum.exe into a plain Node runtime.
#    Nothing uses it (tesseract.js runs on worker_threads, which this fuse does not touch).
#  - enableNodeCliInspectArguments OFF: --inspect / --inspect-brk / SIGUSR1 open no debugger on the
#    main process. Chromium's --remote-debugging-port is a different switch and still works.
#  - enableNodeOptionsEnvironmentVariable OFF (#564): the main process reads neither NODE_OPTIONS
#    nor NODE_EXTRA_CA_CERTS (Electron unsets it). A packaged app ignored NODE_OPTIONS already,
#    except two parser flags. NODE_EXTRA_CA_CERTS is how TLS-scanning antivirus (Norton, measured)
#    and corporate proxies get their root trusted; they also install it in the OS certificate store,
#    and the in-app downloads trust that store since #564 (src/main/services/net/trust.ts, called by
#    downloadToFile before the first request). Until #564 this fuse stayed on (owner decision
#    2026-10-03), because with it off the engine and model downloads failed with "fetch failed"
#    behind Norton (measured). A root that is ONLY in NODE_EXTRA_CA_CERTS no longer counts.
#  - enableEmbeddedAsarIntegrityValidation + onlyLoadAppFromAsar ON: a modified app.asar ends the
#    app ("ASAR Integrity Violation"), and an `app/` folder planted beside a removed app.asar is
#    never loaded. electron-builder writes the header hash on every build (the Windows exe resource,
#    the macOS Info.plist key), so `asar: true` and NO `disableAsarIntegrity` are required — without
#    the hash the binary refuses to start. Windows and macOS only (Linux has no integrity check),
#    and files in app.asar.unpacked (the OCR worker closure below) are not checked.
#  - grantFileProtocolExtraPrivileges OFF (#560): `file://` pages lose the extra privileges Electron
#    gives them by default (fetch/XHR of any local file, among others). The app's own pages are served
#    from `hilbertraum://app/` (src/main/app-protocol.ts); with the fuse off the old `file://` layout's
#    module scripts are refused by CORS from origin `null` (measured), so the scheme and this line go
#    together. Since #563 the evidence-pack print window prints from memory on `hilbertraum://print/`,
#    so no page is on `file://` any more.
#  - resetAdHocDarwinSignature: flipping a fuse invalidates the ad-hoc signature of a macOS arm64
#    binary, so re-sign it ad hoc right after (a Developer ID signature, when configured, comes
#    afterwards) — not measured, no Mac here.
# The other fuses keep Electron's defaults. tests/integration/packaging.test.ts pins this block and
# checks that the installed electron-builder still maps every option (an unmapped name is ignored
# silently). Re-check the built binary's fuse wire after an Electron bump or a change here
# (docs/packaging.md "Electron fuses"); expected for 43.8.10: 000011001 (001011001 until #564).
electronFuses:
  runAsNode: false
  enableNodeOptionsEnvironmentVariable: false
  enableNodeCliInspectArguments: false
  enableEmbeddedAsarIntegrityValidation: true
  onlyLoadAppFromAsar: true
  grantFileProtocolExtraPrivileges: false
  resetAdHocDarwinSignature: true

directories:
  # buildResources holds icons etc. (optional; defaults are used if absent).
  buildResources: build
  output: release

# What goes inside app.asar. electron-builder ships production `dependencies`
# automatically (pdfjs-dist / mammoth / papaparse / yaml — the externalized parser libs),
# so the lazy require()s resolve at runtime. In this npm workspace those packages are
# HOISTED to the repo-root node_modules; electron-builder 26's collector follows hoisted/nested
# trees by default (see the includeSubNodeModules NOTE below), so mammoth's transitive deps
# come along too. ALWAYS smoke-test a PDF/DOCX/CSV import from the produced .exe — a missing
# externalized dep only surfaces at runtime, not in the green gate (see docs/packaging.md + BUILD_STATE R2).
files:
  - out/**/*
  # CODE-1 (full-audit 2026-07-12b): `npm run preview:build` / `screenshot` emit the dev-only
  # screenshot-verify preview harness (incl. staged demo chats) to out/preview/, and
  # `electron-vite build` clears only out/main|preload|renderer — so a local `npm run package`
  # after a screenshot run would fold the whole harness into app.asar. Nothing loads it at
  # runtime; keep it out. tests/integration/packaging.test.ts pins this negation.
  - '!out/preview/**'
  # out/tools/ holds the drive builders' commercial-gate tool (vite.tools.config.ts, #233) —
  # a build-machine tool run with plain node, not app code.
  - '!out/tools/**'
  - package.json
  # L18 (audit-2026-06-13): `@napi-rs/canvas` is an OPTIONAL transitive dep of pdfjs-dist
  # — a platform-specific native `.node` (Skia) our code never imports (OCR renders pages in the
  # hidden-window rasterizer, not with node-canvas). pdf.js itself `require`s it at its first import
  # in the main process; packaged, that fails, pdf.js warns twice on stderr and carries on, since the
  # main process needs only a DOMMatrix, which parsers/dommatrix-polyfill.ts supplies (#685,
  # tests/integration/pdf-parser-packaged.test.ts). The dependency collector would otherwise
  # follow the hoisted tree and bundle the win32 `.node` into app.asar, breaking
  # the pure-JS / cross-OS portable posture (a Windows .node on a macOS/Linux drive).
  # Exclude every platform variant. tests/integration/packaging.test.ts asserts this stays.
  - '!**/node_modules/@napi-rs/canvas*/**'
  # pdfjs-dist ships standard-font data (`standard_fonts/`: Foxit Type 1 + Liberation Sans
  # TrueType) that pdf.js loads only through `standardFontDataUrl`, which this app never sets,
  # so nothing reads them. The LiberationSans files are Liberation 1.07.4 under GPL v2 with a
  # physical-product clause (pdfjs-dist 6.3 corrected their notice from OFL), so they stay out
  # of the Kit (wave DEP-6, owner ruling). tests/integration/packaging.test.ts pins this.
  - '!**/node_modules/pdfjs-dist/standard_fonts/**'
  # The DEP-3 block that kept the never-imported mermaid chain out (~40 negations) retired with
  # streamdown 2.6, which no longer depends on mermaid (#550); packaging.test.ts goes red if
  # mermaid re-enters the production graph. A new negation must name each package itself:
  # electron-builder matches negations against the re-hoisted layout, where a package nested
  # under a negated parent can sit at the top level (#548).
# NOTE: `includeSubNodeModules: true` was REMOVED in electron-builder 26 (it now errors as an
# unknown property). v26's reworked dependency collector already follows hoisted/nested
# node_modules trees by default, so mammoth's transitive deps still come along — and it lays
# a source-NESTED package out at TOP level inside app.asar (measured 2026-09-02: node-fetch's
# nested whatwg-url/tr46/webidl-conversions became node_modules/<name>), which is why any
# `asarUnpack` glob must be written against that flattened layout too. If a hoisted
# externalized dep ever goes missing from app.asar, build from apps/desktop or disable hoisting
# (see docs/packaging.md "Portable build"). ALWAYS smoke-test a PDF/DOCX/CSV import + encrypted
# workspace from the produced .exe — a missing dep surfaces only at runtime.
# No native addons (node:sqlite is built into Electron; parsers are pure-JS) → skip rebuild.
npmRebuild: false

# Model manifests are the ONLY model metadata in git. Ship them beside app.asar so the
# packaged main process finds them: for the model list, resolveManifestsDir(app.getAppPath())
# walks up from resources/app.asar and matches resources/model-manifests (HILBERTRAUM_MANIFESTS_DIR
# overrides); the engine pins read exactly <process.resourcesPath>/model-manifests (#842).
# Weights + sidecar binaries are NEVER bundled — they live on the prepared drive.
extraResources:
  - from: ../../model-manifests
    to: model-manifests
  # LIC-2 (full-audit 2026-07-12): third-party license notices for every npm package bundled
  # into app.asar / the Vite bundles (Apache-2.0 NOTICE preservation, MIT/BSD attribution,
  # KaTeX OFL fonts). Generated file — regenerate with
  # `node scripts/generate-third-party-notices.mjs`; tests/integration/third-party-notices.test.ts
  # fails the gate when it is not byte-identical to a regeneration (#769).
  - from: ../../THIRD-PARTY-NOTICES.md
    to: THIRD-PARTY-NOTICES.md
  # LIC-2 (full-audit 2026-07-12b): the project's OWN GPL-3.0-or-later license text.
  # Without this the packaged artifact carries the GPL only as the package.json SPDX
  # string (the root LICENSE sits outside the apps/desktop build context and files:
  # only bundles out/** + package.json). Shipped as LICENSE.txt beside Electron's own
  # LICENSE.electron.txt / LICENSES.chromium.html; third-party-notices.test.ts pins it.
  - from: ../../LICENSE
    to: LICENSE.txt

# Asar keeps the app a single archive; node:sqlite + the parser libs work from it. The asar
# integrity fuses above require it (onlyLoadAppFromAsar loads nothing else).
asar: true
# tesseract.js spawns its Node OCR worker via worker_threads, which loads the worker
# SCRIPT (and the WASM core it requires) through real filesystem reads — those cannot
# see inside the asar archive (Phase 38, R-O2). Unpack both packages; the engine
# rewrites app.asar → app.asar.unpacked in the resolved workerPath.
#
# This list is the worker's require-graph closure, derived by
# tests/integration/asar-unpack-closure.test.ts (#232): every module the worker script can
# `require` must match a glob here, at every location electron-builder may place it in the
# asar. With only the two tesseract packages listed, the worker's hoisted deps stayed inside
# app.asar and the load failure killed the app (measured 2026-07-19). The manual packaged
# smoke (BUILD_STATE §5 item 18(c)) remains the executable proof. `node-fetch` is only
# reached behind `global.fetch ||` (never on Electron's Node) but is unpacked anyway.
# Dev-mode OCR is unaffected. User-facing text: docs/known-limitations.md.
# Unpacked files sit outside the asar integrity check (#562, measured): keep this list to the
# worker closure, nothing else.
asarUnpack:
  - 'node_modules/tesseract.js/**'
  - 'node_modules/tesseract.js-core/**'
  # the worker's hoisted runtime deps (#232):
  - 'node_modules/regenerator-runtime/**'
  - 'node_modules/is-url/**'
  - 'node_modules/bmp-js/**'
  - 'node_modules/wasm-feature-detect/**'
  # node-fetch's own deps (tr46, webidl-conversions, whatwg-url) are NESTED under it in the
  # source tree but the electron-builder 26 collector FLATTENS them to top level inside the
  # asar (measured on the 2026-09-02 win-unpacked artifact) — the closure test checks both
  # destinations, so all four are listed.
  - 'node_modules/node-fetch/**'
  - 'node_modules/whatwg-url/**'
  - 'node_modules/tr46/**'
  - 'node_modules/webidl-conversions/**'

# CODE SIGNING (Phase 13). Signing turns a scary OS gatekeeper dialog into a clean launch
# for a non-technical buyer; it is the single most important non-code task for the
# commercial drive. ALL signing secrets are supplied by ENV VARS on the build/CI machine
# and NEVER committed (CLAUDE.md hard rule). The green gate (typecheck/test/build) does NOT
# invoke electron-builder, so none of this runs in CI by default — it is a documented
# manual/CI build step (see docs/packaging.md). The unsigned DIY fallback ("Run anyway" /
# right-click Open) is documented in docs/troubleshooting.md.

win:
  target:
    - portable
  # signtoolOptions are read from env on the build machine:
  #   WIN_CSC_LINK              path/URL to the OV/EV .pfx (or base64) — NEVER in the repo
  #   WIN_CSC_KEY_PASSWORD      the .pfx password
  # Signing lets SmartScreen build reputation for the publisher; Microsoft treats certificate
  # types alike for this (docs/packaging.md "Code signing & notarization", #850). The
  # launcher (Start HilbertRaum.cmd) is a script and is not itself signed; the portable
  # .exe it spawns IS signed, which is what SmartScreen evaluates.
  signtoolOptions:
    signingHashAlgorithms:
      - sha256
    # certificateSubjectName / certificateSha1 can be set here for an EV token; left unset
    # so a .pfx supplied via WIN_CSC_LINK/WIN_CSC_KEY_PASSWORD is used.

# A single self-contained .exe — copy it onto the drive root next to the prepared layout
# and launch it with HILBERTRAUM_DRIVE_ROOT pointing at the drive (see docs/packaging.md).
portable:
  artifactName: HilbertRaum-${version}-portable.exe

mac:
  target:
    - dir
  category: public.app-category.productivity
  # macOS signing + notarization. Without notarization a USB-launched .app is quarantined
  # ("can't be opened / damaged"). Supplied via env on the build machine:
  #   CSC_LINK / CSC_KEY_PASSWORD          the "Developer ID Application" cert (.p12)
  #   APPLE_ID / APPLE_APP_SPECIFIC_PASSWORD / APPLE_TEAM_ID   notarization credentials
  # hardenedRuntime + the entitlements file are required for notarization to pass.
  hardenedRuntime: true
  gatekeeperAssess: false
  entitlements: build/entitlements.mac.plist
  entitlementsInherit: build/entitlements.mac.plist
  # notarize: electron-builder auto-notarizes when the APPLE_* env vars are present and this
  # is not explicitly false. Set to false for an unsigned local/dev build.

linux:
  target:
    - AppImage
  category: Utility