The web app becomes a desktop app without changing shape: the Electron
shell spawns the Next standalone server on a loopback port and points a
sandboxed window at it. All app logic stays in the Next server.
Bands:
1. LH_DATA_DIR seam (config.ts): PATHS.data/chats/graph derive from
process.env.LH_DATA_DIR (else repo data/, unchanged in dev). New
PATHS.modelCache routes the transformers.js embedding-model cache
(~300MB) to <data>/models when the seam is set — the default cache
inside node_modules is read-only in a packaged bundle. All existing
fs writes flow through PATHS; teacherPrompt stays ROOT-anchored
(read-only asset, ships inside the bundle by design).
tests/data-dir-seam.test.ts covers set/unset via child process.
2. Standalone build (next.config.ts + scripts/build-server.mjs):
output 'standalone'; outputFileTracingExcludes data/**/* keeps the
repo's real session data out of the bundle (verified: an unexcluded
scratch build traced 34 files / 716K of real chats + ledgers).
Two empirically-verified tracer gaps required outputFileTracingIncludes:
pi-ai's provider catalog (JSON import attributes — 39 files, 500s on
/api/models without them) and onnxruntime-node's sibling dylib
(libonnxruntime.dlopen via @rpath). build-server.mjs copies public/
and .next/static per docs, refuses a leaked data/ dir, and asserts
the runtime-read prompt .md assets are traced.
3. Electron shell (electron/main.cjs, no preload):
- single-instance lock (two instances would fight over the data dir);
- free port via listen(0); spawn via process.execPath +
ELECTRON_RUN_AS_NODE=1 with PORT/HOSTNAME=127.0.0.1/LH_DATA_DIR;
- BYOK: userData/auth.json, flat {VAR: value} JSON, mode 0600,
merged into the child env only when absent from the real env
(auth UI is the settings milestone; file is hand-editable);
- poll until the server answers (no ready event), then open a
contextIsolation+sandbox window; deny-by-default permission
handler (media allowed only from the loopback origin — mic/STT
groundwork); will-navigate pinned to origin, window.open denied
with external links to the system browser; macOS Edit-menu roles;
- quit path SIGTERM→3s→SIGKILL + exit/SIGHUP nets; child stdout
mirrored to userData/logs/main.log;
- dev mode via LH_DEV_URL: no spawn, points at next dev (HMR).
4. Packaging (electron-builder.yml + build/entitlements.mac.plist):
files = electron shell only; the whole .next payload ships via
extraResources from .next (filter standalone/**/*) — NOT from
.next/standalone directly: electron-builder hard-excludes a copy's
root node_modules and the default pattern is a literal match, so
node_modules/ and .next/ were silently dropped and the server died
with 'Cannot find module next'. Asar holds no native code.
Unsigned (identity: null) until a Developer ID cert exists; hardened
runtime + audio-input entitlements laid now for the STT milestone.
desktop:dev / desktop:dist scripts (electron 44, electron-builder 26).
Live smoke of the packaged .app: server up on a random loopback port,
all API routes 200, a real GLM chat turn answered end-to-end via
auth.json BYOK, chat persisted under userData/data, second instance
exited via the lock, no orphaned server child after quit.
Gates: typecheck, eslint, 500/500 tests (+2 data-dir-seam), build.
75 lines
2.9 KiB
JavaScript
75 lines
2.9 KiB
JavaScript
import { defineConfig, globalIgnores } from "eslint/config";
|
|
import nextPlugin from "@next/eslint-plugin-next";
|
|
import tsParser from "@typescript-eslint/parser";
|
|
import importPlugin from "eslint-plugin-import";
|
|
|
|
/**
|
|
* ESLint with one job here: ENFORCE THE IMPORT LAW (the shell/core
|
|
* architecture, docs/architecture.md). Everything else stays out of the
|
|
* way — this is not a style linter.
|
|
*
|
|
* components/** → "@/src/core" (the pure core barrel) — ONLY
|
|
* app/** → "@/src/core" + "@/src/server" (the server barrel) — ONLY
|
|
* src/core/** → never imports src/agent, src/server, src/store (pure
|
|
* core: adapters implement core/ports.ts, never the reverse)
|
|
* src/agent/** → never imports src/server, src/store (dependencies —
|
|
* the storage ports, the composition — arrive via
|
|
* factories/closures from the chat-handler)
|
|
*
|
|
* tests/ and scripts/ are internal — unrestricted.
|
|
*/
|
|
|
|
export default defineConfig([
|
|
// electron/** — the desktop shell: plain Node, no framework, outside the
|
|
// import law (same rationale as scripts/).
|
|
globalIgnores([".next/**", "node_modules/**", "data/**", "next-env.d.ts", "scripts/**", "electron/**", "dist/**"]),
|
|
{
|
|
files: ["**/*.{js,mjs,ts,tsx}"],
|
|
languageOptions: {
|
|
parser: tsParser,
|
|
parserOptions: { ecmaVersion: "latest", sourceType: "module" },
|
|
},
|
|
plugins: { "@next/next": nextPlugin, import: importPlugin },
|
|
settings: {
|
|
"import/resolver": { typescript: { alwaysTryTypes: true } },
|
|
},
|
|
rules: {
|
|
...nextPlugin.configs.recommended.rules,
|
|
"import/no-restricted-paths": [
|
|
"error",
|
|
{
|
|
zones: [
|
|
{
|
|
target: "./components",
|
|
from: "./src",
|
|
// NOTE: the plugin resolves `except` relative to the zone's `from` path.
|
|
except: ["./core/index.ts"],
|
|
message:
|
|
"Browser shell imports ONLY the pure core barrel: `from \"@/src/core\"` (architecture: docs/architecture.md).",
|
|
},
|
|
{
|
|
target: "./app",
|
|
from: "./src",
|
|
except: ["./core/index.ts", "./server/index.ts"],
|
|
message:
|
|
"app/ (transport + server components) imports ONLY the barrels: `@/src/core` and `@/src/server` (architecture: docs/architecture.md).",
|
|
},
|
|
{
|
|
target: "./src/core",
|
|
from: ["./src/agent", "./src/server", "./src/store"],
|
|
message:
|
|
"Pure core never imports IO layers (agent/server/store): adapters implement core/ports.ts, and the composition root (src/server/stores.ts) passes them in (architecture: docs/architecture.md).",
|
|
},
|
|
{
|
|
target: "./src/agent",
|
|
from: ["./src/server", "./src/store"],
|
|
message:
|
|
"The agent layer receives its dependencies (storage ports via factories/closures) — it never imports the server layer or store adapters (architecture: docs/architecture.md).",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
]);
|