A local-first multi-agent app development platform, built on PenguinHarness
/**
* Per-form app identity — pure, no Electron imports, so it unit-tests under plain
* vitest.
*
* A dev shell must be able to run while an installed release build is running (#292).
* "Dev" is a *profile* — an instance identity plus its default data root — and not the
* same thing as being unpackaged: an unpackaged run defaults to it, and a packaged
* build opts into it with `--dev`, so one installed exe can also run as a second,
* isolated instance. What stays keyed on `app.isPackaged` is capability, not identity:
* whether there is an installed artifact to update or a bundled CLI to install. Electron keys everything that must stay per-instance on the app
* name: the userData directory holds the Chromium profile and this shell's state
* files (server-port, preferred-port, cli-install-offered), and the single-instance
* lock is derived from it — under a shared name a second launch does not open a
* second app, it quits into the running instance's window. A dev-suffixed name
* therefore separates the whole set at once (own profile, own sticky port, own
* instance lock) and doubles as the visible marker of which instance is which (the
* macOS app menu label follows app.name).
*
* The Windows AppUserModelID splits the same way: Windows groups taskbar buttons and
* routes toast notifications by AUMID, so a dev run must not claim the installed
* app's identity. (Dev toasts may not render without an installed shortcut carrying
* the dev AUMID — acceptable for a source run; the release value keeps matching what
* electron-builder stamps on the installed shortcuts, see electron-builder.yml.)
*
* Tripwire for whoever edits main.ts's imports: Electron resolves the userData path
* once, on the first read, and caches it — so `app.setName()` only relocates anything
* while nothing has read it yet. ESM evaluates every import before main.ts's first
* statement, which means a module-scope `app.getPath(…)` anywhere in the import graph
* would silently pin userData to the package name and undo this whole split. Verified
* safe today, including updater.ts's eager `electron-updater` construction; keep any
* new `app.getPath` call inside a function.
*/
import path from "node:path";
export interface AppIdentity {
/** app.setName() value; Electron derives the default userData directory from it. */
name: string;
/** Windows AppUserModelID. The release value must equal electron-builder.yml's appId. */
appUserModelId: string;
}
/** Which instance this process is: the installed app, or the isolated dev instance. */
export type Profile = "release" | "dev";
/** The command-line switch that puts a packaged build on the dev profile. */
export const DEV_SWITCH = "--dev";
/**
* The profile rule: `--dev` on the command line always selects the dev profile; without
* it an unpackaged run is dev (the repo's `pnpm desktop`) and a packaged one is release.
* Read from `process.argv` rather than `app.commandLine` so it can run before anything
* touches Electron's cached paths (see the tripwire above).
*/
export function resolveProfile(opts: { argv: readonly string[]; isPackaged: boolean }): Profile {
if (opts.argv.includes(DEV_SWITCH)) return "dev";
return opts.isPackaged ? "release" : "dev";
}
/** The identity for this profile: release, or dev-suffixed so both can run side by side. */
export function appIdentity(profile: Profile): AppIdentity {
// Adelie's own bundle id, not the upstream product's: it is what the earlier Adelie
// desktop release installed under, so this shell upgrades that install instead of
// landing beside it, and it must stay equal to electron-builder.yml's appId (the
// release-profile test reads the two back to each other).
return profile === "release"
? { name: "Adelie", appUserModelId: "com.lmliheng.adelie" }
: { name: "Adelie-Dev", appUserModelId: "com.lmliheng.adelie.dev" };
}
/**
* The dev default data root, `~/.penguin/dev-data` — the same convention as the repo's
* other dev entry points (CONTRIBUTING.md), kept apart from the release/CLI
* `~/.penguin/data`. Without this split a dev shell launched bare (no PENGUIN_HOME)
* would find the release install's server.lock on the shared root and attach to the
* running RELEASE instance — or, with the release idle, spawn its own server over the
* release's data.
*/
export function devDataRoot(homedir: string): string {
return path.join(homedir, ".penguin", "dev-data");
}
/**
* This form's data root, i.e. the precedence rule itself: an explicit `PENGUIN_HOME`
* always wins; without one the release profile shares the CLI's root by design, so a
* desktop install and the CLI see the same Agents, Sessions and usage, while the dev
* profile takes the repo's dev root instead of attaching to — or writing into — the
* release install's data.
*
* `releaseRoot` stays a thunk (core's `resolveRoot`) so core remains the single
* definition point of `~/.penguin/data`; it is only called when there is no explicit
* value, which is exactly the case where `resolveRoot()` yields that default. Pure, so
* the rule is unit-tested — it cannot be, inline in main.ts, which imports Electron.
*/
export function desktopDataRoot(opts: {
envHome: string | undefined;
profile: Profile;
homedir: string;
releaseRoot: () => string;
}): string {
return (
opts.envHome ?? (opts.profile === "release" ? opts.releaseRoot() : devDataRoot(opts.homedir))
);
}