@powerhousedao/desktop 6.2.3-dev.59 → 6.2.3-dev.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-BL61-fyi.mjs","names":[],"sources":["../src/app-json.ts","../src/bundle-stack.ts","../src/shell-project.ts","../src/shell-toolchain.ts","../src/shell.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { z } from \"zod\";\n\n/**\n * `hosts/desktop/app.json` — the builder's desktop identity (phase 7, mode 1:\n * the builder ships under THEIR identity without writing Rust). It is the ONE\n * file a builder edits; `shell-project.ts` projects it into a generated\n * `tauri-shell/` that depends on the published `ph-desktop-shell` crate. Every\n * field validates strictly so a typo fails with the field named, not silently.\n */\n\nconst identifierSchema = z\n .string()\n .min(1)\n .regex(\n /^[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)+$/,\n \"identifier must be reverse-DNS (e.g. com.acme.app): dot-separated alphanumeric segments\",\n );\n\nconst windowSchema = z\n .strictObject({\n title: z.string().min(1).optional(),\n width: z.number().int().positive().optional(),\n height: z.number().int().positive().optional(),\n resizable: z.boolean().optional(),\n })\n .optional();\n\nconst fileAssociationSchema = z.strictObject({\n /** Extensions WITHOUT the leading dot (\"phd\", not \".phd\"). */\n ext: z.array(z.string().min(1).regex(/^[^.]/, \"drop the leading dot\")).min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n mimeType: z.string().optional(),\n});\n\n/** Where the generated Cargo.toml resolves `ph-desktop-shell` from. Default\n * (omitted) = the published crates.io version. */\nconst shellSourceSchema = z\n .strictObject({\n /** Local checkout for shell development (the lab points here). */\n path: z.string().min(1).optional(),\n /** Git source, pinned to a tag/rev, for pre-publication consumption. */\n git: z.string().min(1).optional(),\n tag: z.string().min(1).optional(),\n rev: z.string().min(1).optional(),\n /** crates.io version requirement (default DEFAULT_SHELL_CRATE_VERSION). */\n version: z.string().min(1).optional(),\n })\n .refine((s) => !(s.path && s.git), {\n message: \"shell.source: set path OR git, not both\",\n })\n .optional();\n\nexport const appJsonSchema = z.strictObject({\n identifier: identifierSchema,\n productName: z.string().min(1),\n /** Single source image (square PNG, 1024×1024 recommended); the icon set\n * for every platform is generated from it via `tauri icon`. */\n icon: z.string().min(1),\n window: windowSchema,\n fileAssociations: z.array(fileAssociationSchema).optional(),\n shell: shellSourceSchema,\n});\n\nexport type AppJson = z.infer<typeof appJsonSchema>;\nexport type AppJsonShellSource = NonNullable<AppJson[\"shell\"]>;\n\n/** Default crates.io version requirement for the shell crate (D7.b: the flip\n * to crates.io default once published — the crate is live). */\nexport const DEFAULT_SHELL_CRATE_VERSION = \"0.1\";\n\nexport const APP_JSON_FILE = \"app.json\";\n\n/** Read + validate hosts/<host>/app.json. Throws with the field named on a\n * bad value, and a clear message when the file is absent. */\nexport function loadAppJson(hostDir: string): AppJson {\n const file = path.join(hostDir, APP_JSON_FILE);\n if (!fs.existsSync(file)) {\n throw new Error(\n `No ${APP_JSON_FILE} in ${hostDir} — run \\`ph generate desktop-shell\\` to scaffold the builder identity, or set runner.shell.project to a prebuilt shell.`,\n );\n }\n let raw: unknown;\n try {\n raw = JSON.parse(fs.readFileSync(file, \"utf8\"));\n } catch (error) {\n throw new Error(`${file}: not valid JSON — ${String(error)}`, {\n cause: error,\n });\n }\n const result = appJsonSchema.safeParse(raw);\n if (!result.success) {\n const issues = result.error.issues\n .map((i) => ` ${i.path.join(\".\") || \"(root)\"}: ${i.message}`)\n .join(\"\\n\");\n throw new Error(`${file} is invalid:\\n${issues}`);\n }\n return result.data;\n}\n\n/** A filesystem/crate-safe slug of the product name — the generated binary\n * and Cargo package name. Falls back to the identifier's last segment. */\nexport function appSlug(app: AppJson): string {\n const fromName = app.productName\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n if (fromName) return fromName;\n const seg = app.identifier.split(\".\").pop() ?? \"app\";\n return seg.toLowerCase().replace(/[^a-z0-9]+/g, \"-\");\n}\n","import { spawnSync } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * P6.3 — stage the shippable STACK into the shell project: everything the\n * installed app needs to run `ph run desktop` with no environment at all\n * (D6.c). The shell's resources map `../dist-stack` → `stack`, and its\n * uniform-runners mode falls back to `resources/stack` when the env pair is\n * absent. Layout:\n *\n * dist-stack/\n * hosts/ the project's host files\n * agents/ when present\n * powerhouse.config.json\n * package.json minimal, names the project\n * dist/ the BUILT Connect (ph run connect build)\n * node_modules/ vendored @powerhousedao/ph-cli (hoisted,\n * real files — computed-specifier imports and\n * PGlite wasm forbid bundling)\n */\nexport interface BundleStackOptions {\n projectRoot: string;\n shellProjectDir: string;\n /** Vendor the runtime packages (slow). Skipped when false — an existing\n * vendored tree is left in place. */\n vendor?: boolean;\n /** The ph-cli version/tag to vendor. Default: \"dev\". NOTE: the vendored\n * ph-cli must carry the `run` command — registry tags published before\n * uniform-runners landed cannot run a stack; until a nightly catches up,\n * pass `phCliSpec` with a locally packed tarball instead. */\n phCliVersion?: string;\n /** Overrides the ph-cli install spec entirely (e.g. a `pnpm pack` tarball\n * path for a not-yet-published build). */\n phCliSpec?: string;\n /** The connect member's port — written into the stack's shell.json so the\n * shell knows where to probe/navigate with no environment at all. */\n connectPort?: number;\n /** Absolute paths to skip when staging `hosts/` — in mode 1 the generated\n * shell dir sits under `hosts/` and must not be copied into itself. */\n excludeDirs?: string[];\n logger?: (message: string) => void;\n}\n\nexport interface BundleStackResult {\n stackDir: string;\n vendored: boolean;\n}\n\nfunction copyIfExists(from: string, to: string): boolean {\n if (!fs.existsSync(from)) return false;\n fs.cpSync(from, to, { recursive: true });\n return true;\n}\n\n/**\n * Recursively copy `src` → `dest`, skipping any path in `excludes`. Unlike\n * fs.cpSync this tolerates `dest` living INSIDE `src`: in mode 1 the generated\n * shell (and its `dist-stack`) sits under `hosts/<desktop>/`, so staging the\n * project's `hosts/` straight into the shell would be a copy-into-self that\n * cpSync rejects outright. Excluding the shell subtree both avoids that and\n * keeps the crate + node sidecar out of the shippable stack.\n */\nfunction copyDirFiltered(\n src: string,\n dest: string,\n excludes: string[],\n): boolean {\n if (!fs.existsSync(src)) return false;\n const skip = new Set(excludes.map((e) => path.resolve(e)));\n const walk = (s: string, d: string): void => {\n if (skip.has(path.resolve(s))) return;\n const stat = fs.statSync(s);\n if (stat.isDirectory()) {\n fs.mkdirSync(d, { recursive: true });\n for (const entry of fs.readdirSync(s)) {\n walk(path.join(s, entry), path.join(d, entry));\n }\n } else {\n fs.copyFileSync(s, d);\n }\n };\n walk(src, dest);\n return true;\n}\n\nexport function bundleStack(options: BundleStackOptions): BundleStackResult {\n const log = options.logger ?? console.log;\n const stackDir = path.join(options.shellProjectDir, \"dist-stack\");\n\n // Fresh staging for project files; the vendored node_modules survives\n // unless re-vendoring (it is by far the slowest part).\n for (const entry of [\n \"hosts\",\n \"agents\",\n \"dist\",\n \"powerhouse.config.json\",\n \"package.json\",\n ]) {\n fs.rmSync(path.join(stackDir, entry), { recursive: true, force: true });\n }\n fs.mkdirSync(stackDir, { recursive: true });\n\n // hosts/ gets the filtered copy — the generated shell subtree lives under\n // it and must not be copied into itself (nor shipped in the stack).\n const hostsStaged = copyDirFiltered(\n path.join(options.projectRoot, \"hosts\"),\n path.join(stackDir, \"hosts\"),\n options.excludeDirs ?? [],\n );\n log(` hosts/ ${hostsStaged ? \"staged\" : \"absent — skipped\"}`);\n for (const dir of [\"agents\", \"dist\"]) {\n const copied = copyIfExists(\n path.join(options.projectRoot, dir),\n path.join(stackDir, dir),\n );\n log(` ${dir}/ ${copied ? \"staged\" : \"absent — skipped\"}`);\n }\n\n // Inside the package there is no nested shell — the shell IS the window —\n // so the staged desktop host runs on the generic compound. Rewrite the\n // runner.module projection in the STAGED copy only.\n const stagedDesktopHost = path.join(stackDir, \"hosts\", \"desktop\", \"host.js\");\n if (fs.existsSync(stagedDesktopHost)) {\n const source = fs.readFileSync(stagedDesktopHost, \"utf8\");\n if (source.includes(\"@powerhousedao/desktop/runner\")) {\n fs.writeFileSync(\n stagedDesktopHost,\n \"// STAGED COPY (bundle-stack): runner.module rewritten to the generic\\n\" +\n \"// compound — the packaged shell is the window; there is no nested shell.\\n\" +\n source.replace(\n /@powerhousedao\\/desktop\\/runner/g,\n \"@powerhousedao/host-core/runners/compound\",\n ),\n );\n log(\n \" hosts/desktop/host.js: runner rewritten to the generic compound (staged copy)\",\n );\n }\n }\n copyIfExists(\n path.join(options.projectRoot, \"powerhouse.config.json\"),\n path.join(stackDir, \"powerhouse.config.json\"),\n );\n\n // shell.json: the stack's contract with the shell. The no-env (packaged)\n // path has nobody to set PH_WIN_CONNECT_PORT, so the shell reads the probe\n // and window port from here.\n if (typeof options.connectPort === \"number\") {\n fs.writeFileSync(\n path.join(stackDir, \"shell.json\"),\n `${JSON.stringify({ connectPort: options.connectPort }, null, 2)}\\n`,\n );\n log(` shell.json: connectPort ${options.connectPort}`);\n }\n\n // A minimal manifest: names the project (lock identity) and depends on\n // ph-cli so the vendored tree resolves exactly like a real install.\n const sourcePkg = JSON.parse(\n fs.readFileSync(path.join(options.projectRoot, \"package.json\"), \"utf8\"),\n ) as { name?: string };\n const version = options.phCliVersion ?? \"dev\";\n fs.writeFileSync(\n path.join(stackDir, \"package.json\"),\n `${JSON.stringify(\n {\n name: sourcePkg.name ?? \"powerhouse-desktop-stack\",\n private: true,\n type: \"module\",\n dependencies: { \"@powerhousedao/ph-cli\": version },\n },\n null,\n 2,\n )}\\n`,\n );\n\n let vendored = false;\n if (options.vendor !== false) {\n const phCliSpec = options.phCliSpec ?? `@powerhousedao/ph-cli@${version}`;\n // host-core rides along: host files resolve runner modules (the generic\n // compound) from the STACK's own node_modules.\n const specs = `\"${phCliSpec}\" \"@powerhousedao/host-core@${version}\"`;\n log(` vendoring ${specs} (hoisted, real files)…`);\n // One command string: shell:true with an args ARRAY concatenates without\n // escaping (DEP0190 warns); the spec values are our own constants/paths.\n const result = spawnSync(\n `npm install ${specs} --install-strategy=hoisted --omit=dev --no-audit --no-fund`,\n { cwd: stackDir, stdio: \"pipe\", shell: true, windowsHide: true },\n );\n if (result.status !== 0) {\n throw new Error(\n `bundle-stack: vendoring failed (${result.status}):\\n` +\n `${result.stderr.toString().slice(-800)}`,\n );\n }\n vendored = true;\n } else {\n log(\" vendoring skipped (vendor: false) — existing tree left in place\");\n }\n\n return { stackDir, vendored };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n appSlug,\n DEFAULT_SHELL_CRATE_VERSION,\n type AppJson,\n type AppJsonShellSource,\n} from \"./app-json.js\";\n\n/**\n * P7.3 — project `hosts/desktop/app.json` into a generated `tauri-shell/`:\n * a STANDALONE tauri crate that depends on the published `ph-desktop-shell`\n * library, carries the builder's identity, and is built/run by the desktop\n * runner's dev/build verbs. The builder never writes Rust.\n *\n * Everything here mirrors the known-good reference app\n * (ph-desktop-shell/apps/powerhouse-desktop): the tauri plumbing (main.rs,\n * build.rs, capabilities, the loading page, externalBin + icon mechanics) is\n * copied verbatim; only identity/port fields are projected from app.json. The\n * projection is idempotent and stale-detected — a file is rewritten only when\n * its content changes, so Cargo.lock, the generated icon set, and tauri-build\n * output are never disturbed by a regen with an unchanged app.json.\n */\n\nexport const SHELL_DIR = \"tauri-shell\";\n/** The icon source the runner feeds to `tauri icon` (copied from app.icon). */\nexport const ICON_SOURCE = \"app-icon.png\";\n\nexport interface ProjectShellInput {\n /** hosts/<host>/ — where app.json lives and tauri-shell/ is written. */\n hostDir: string;\n app: AppJson;\n /** The connect member's port — baked into the remote capability so the\n * served Connect origin can reach the shell's launch-queue commands. */\n connectPort: number;\n}\n\nexport interface ProjectShellResult {\n shellDir: string;\n /** The crate/bin name (and the built exe stem the runner looks for). */\n binName: string;\n /** True when any projected file was created or changed this call. */\n changed: boolean;\n}\n\n/** `ph-desktop-shell` dependency line for the generated Cargo.toml, from\n * app.json's shell.source (path > git > crates.io version). */\nfunction shellDependency(source: AppJsonShellSource | undefined): string {\n if (source?.path) {\n // Forward slashes work in Cargo.toml on every platform.\n const p = source.path.replace(/\\\\/g, \"/\");\n return `ph-desktop-shell = { path = ${JSON.stringify(p)} }`;\n }\n if (source?.git) {\n const parts = [`git = ${JSON.stringify(source.git)}`];\n if (source.tag) parts.push(`tag = ${JSON.stringify(source.tag)}`);\n if (source.rev) parts.push(`rev = ${JSON.stringify(source.rev)}`);\n return `ph-desktop-shell = { ${parts.join(\", \")} }`;\n }\n const version = source?.version ?? DEFAULT_SHELL_CRATE_VERSION;\n return `ph-desktop-shell = ${JSON.stringify(version)}`;\n}\n\nfunction cargoToml(app: AppJson, binName: string): string {\n return `# GENERATED from ../app.json by @powerhousedao/desktop — do not edit by\n# hand; edit app.json and re-run \\`ph run desktop dev|build\\`. Cargo.lock is\n# preserved across regens.\n[package]\nname = ${JSON.stringify(binName)}\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[build-dependencies]\ntauri-build = { version = \"2\", features = [] }\n\n[dependencies]\ntauri = { version = \"2\", features = [\"tray-icon\", \"devtools\"] }\n# Plugins must be DIRECT deps of the app crate: tauri-build only sees\n# permission manifests (shell:allow-spawn etc.) from direct dependencies.\ntauri-plugin-shell = \"2\"\ntauri-plugin-single-instance = \"2\"\n${shellDependency(app.shell)}\n\n[[bin]]\nname = ${JSON.stringify(binName)}\npath = \"src/main.rs\"\n\n[profile.release]\ncodegen-units = 1\nlto = true\n`;\n}\n\nconst MAIN_RS = `// GENERATED — identity bakes from tauri.conf.json via generate_context!;\n// behavior is the shared ph-desktop-shell library. Edit ../app.json, not this.\n#![cfg_attr(not(debug_assertions), windows_subsystem = \"windows\")]\n\nfn main() {\n ph_desktop_shell::run(tauri::generate_context!(), Default::default());\n}\n`;\n\nconst BUILD_RS = `// GENERATED — mirrors the reference shell. Connect is served over\n// http://127.0.0.1 (a remote origin to Tauri), so the launch-queue commands\n// need an explicit ACL; declaring the command manifest here generates the\n// allow-<command> permissions that capabilities/*.json grant.\nfn main() {\n tauri_build::try_build(tauri_build::Attributes::new().app_manifest(\n tauri_build::AppManifest::new().commands(&[\n \"take_launch_files\",\n \"read_launch_file\",\n \"log_from_webview\",\n ]),\n ))\n .expect(\"failed to run tauri-build\");\n}\n`;\n\nfunction loadingHtml(productName: string): string {\n const name = productName.replace(/[<&]/g, (c) =>\n c === \"<\" ? \"&lt;\" : \"&amp;\",\n );\n return `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <title>${name}</title>\n <style>\n :root { color-scheme: light dark; }\n body {\n margin: 0; height: 100vh;\n display: flex; align-items: center; justify-content: center;\n font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif;\n background: #0f1115; color: #e6e8eb;\n }\n .box { text-align: center; }\n .dot {\n width: 10px; height: 10px; border-radius: 50%;\n background: #4ade80; display: inline-block; margin-right: 8px;\n animation: pulse 1.2s ease-in-out infinite;\n }\n @keyframes pulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }\n </style>\n </head>\n <body>\n <div class=\"box\"><span class=\"dot\"></span>Starting ${name}…</div>\n </body>\n</html>\n`;\n}\n\nfunction tauriConf(input: ProjectShellInput): string {\n const { app } = input;\n const win = app.window ?? {};\n const fileAssociations =\n app.fileAssociations && app.fileAssociations.length > 0\n ? app.fileAssociations.map((fa) => ({\n ext: fa.ext,\n name: fa.name,\n ...(fa.description ? { description: fa.description } : {}),\n ...(fa.mimeType ? { mimeType: fa.mimeType } : {}),\n }))\n : undefined;\n const conf = {\n $schema: \"https://schema.tauri.app/config/2\",\n productName: app.productName,\n version: \"0.1.0\",\n identifier: app.identifier,\n build: { frontendDist: \"./ui\" },\n app: {\n windows: [\n {\n title: win.title ?? app.productName,\n width: win.width ?? 1440,\n height: win.height ?? 900,\n resizable: win.resizable ?? true,\n visible: true,\n dragDropEnabled: false,\n create: false,\n },\n ],\n security: { csp: null },\n },\n bundle: {\n active: true,\n // Cross-platform: nsis (Windows, no WiX), app+dmg (macOS). The runner\n // passes host-appropriate --bundles at build time; tauri skips targets\n // not valid for the build host.\n targets: [\"nsis\", \"app\", \"dmg\"],\n // `tauri icon` generates .ico (Windows) and .icns (macOS) + pngs from\n // the single app-icon.png; the config references the per-platform set.\n icon: [\n \"icons/32x32.png\",\n \"icons/128x128.png\",\n \"icons/128x128@2x.png\",\n \"icons/icon.icns\",\n \"icons/icon.ico\",\n ],\n ...(fileAssociations ? { fileAssociations } : {}),\n externalBin: [\"binaries/node\"],\n resources: { \"./dist-stack\": \"stack\" },\n },\n };\n return JSON.stringify(conf, null, 2) + \"\\n\";\n}\n\nfunction defaultCapability(): string {\n return (\n JSON.stringify(\n {\n $schema: \"../gen/schemas/desktop-schema.json\",\n identifier: \"default\",\n description: \"Lets the shell spawn the bundled node sidecar.\",\n windows: [\"main\"],\n permissions: [\n \"core:default\",\n \"allow-take-launch-files\",\n \"allow-read-launch-file\",\n \"allow-log-from-webview\",\n {\n identifier: \"shell:allow-spawn\",\n allow: [{ name: \"binaries/node\", sidecar: true, args: true }],\n },\n {\n identifier: \"shell:allow-execute\",\n allow: [{ name: \"binaries/node\", sidecar: true, args: true }],\n },\n ],\n },\n null,\n 2,\n ) + \"\\n\"\n );\n}\n\nfunction connectCapability(connectPort: number): string {\n const origin = `http://127.0.0.1:${connectPort}`;\n return (\n JSON.stringify(\n {\n $schema: \"../gen/schemas/desktop-schema.json\",\n identifier: \"connect\",\n description:\n \"Connect is served over http://127.0.0.1 (a remote origin to Tauri); without this the launch-queue commands are rejected before they run.\",\n windows: [\"main\"],\n remote: { urls: [origin, `${origin}/*`] },\n permissions: [\n \"allow-take-launch-files\",\n \"allow-read-launch-file\",\n \"allow-log-from-webview\",\n ],\n },\n null,\n 2,\n ) + \"\\n\"\n );\n}\n\nconst GITIGNORE = `# Generated tauri shell — only Cargo.lock and app-icon.png are tracked.\n/target\n/gen\n/icons\n/dist-stack\n/binaries\n`;\n\nconst DIST_STACK_README = `This directory is replaced at \\`ph run desktop build\\` with the shippable\nstack (hosts + powerhouse.config.json + built Connect + vendored ph-cli). It\nis bundled as the app's \\`stack\\` resource so the installed app runs with no\nenvironment. Kept as a placeholder so tauri's resource glob resolves in dev.\n`;\n\n/** Write a file only when its content differs; returns whether it changed. */\nfunction writeIfChanged(file: string, content: string): boolean {\n if (fs.existsSync(file) && fs.readFileSync(file, \"utf8\") === content) {\n return false;\n }\n fs.mkdirSync(path.dirname(file), { recursive: true });\n fs.writeFileSync(file, content);\n return true;\n}\n\n/**\n * Materialize/refresh `<hostDir>/tauri-shell/` from app.json. Idempotent:\n * unchanged app.json rewrites nothing. Does NOT run `tauri icon` or fetch the\n * node binary — those are toolchain steps the runner performs at dev/build.\n */\nexport function projectShell(input: ProjectShellInput): ProjectShellResult {\n const { hostDir, app, connectPort } = input;\n const binName = appSlug(app);\n const shellDir = path.join(hostDir, SHELL_DIR);\n const files: Array<[string, string]> = [\n [\"Cargo.toml\", cargoToml(app, binName)],\n [\"src/main.rs\", MAIN_RS],\n [\"build.rs\", BUILD_RS],\n [\"tauri.conf.json\", tauriConf(input)],\n [\"ui/index.html\", loadingHtml(app.productName)],\n [\"capabilities/default.json\", defaultCapability()],\n [\"capabilities/connect.json\", connectCapability(connectPort)],\n [\".gitignore\", GITIGNORE],\n [\"dist-stack/README.md\", DIST_STACK_README],\n ];\n let changed = false;\n for (const [rel, content] of files) {\n if (writeIfChanged(path.join(shellDir, rel), content)) changed = true;\n }\n // Stage the icon source next to the shell (tauri icon reads it at build).\n const iconSrc = path.resolve(hostDir, app.icon);\n const iconDest = path.join(shellDir, ICON_SOURCE);\n if (fs.existsSync(iconSrc)) {\n const bytes = fs.readFileSync(iconSrc);\n if (!fs.existsSync(iconDest) || !fs.readFileSync(iconDest).equals(bytes)) {\n fs.mkdirSync(shellDir, { recursive: true });\n fs.writeFileSync(iconDest, bytes);\n changed = true;\n }\n }\n return { shellDir, binName, changed };\n}\n","import { execSync, spawnSync } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\n/**\n * The native toolchain the generated shell (mode 1) needs to build/run, and\n * the provisioning steps around it. `cargo tauri dev|build` compiles the\n * generated crate — but tauri-build validates two things AT COMPILE TIME that\n * must exist first (both confirmed against a live `cargo check`):\n * - the node sidecar `binaries/node-<triple>` (externalBin), and\n * - `icons/icon.ico` on Windows (the app's Win32 resource).\n * So dev/build provision the sidecar + icon set before invoking tauri, and\n * fail with install guidance when cargo or the Tauri CLI is absent — a\n * missing executable must read as a clear instruction, never a deep cargo\n * stack trace.\n */\n\nexport interface NodeTarget {\n triple: string;\n dist: string;\n /** Path within the extracted archive (POSIX) / \"node.exe\" on Windows. */\n bin: string;\n ext: string;\n}\n\n/** The Node release triple for a build host — the sidecar filename tauri\n * resolves (`node-<triple>`). Pure, so the mapping is unit-tested. */\nexport function nodeSidecarTarget(\n platform: NodeJS.Platform,\n arch: string,\n): NodeTarget {\n const table: Record<string, NodeTarget | undefined> = {\n \"win32 x64\": {\n triple: \"x86_64-pc-windows-msvc\",\n dist: \"win-x64\",\n bin: \"node.exe\",\n ext: \".exe\",\n },\n \"darwin arm64\": {\n triple: \"aarch64-apple-darwin\",\n dist: \"darwin-arm64\",\n bin: \"bin/node\",\n ext: \"\",\n },\n \"darwin x64\": {\n triple: \"x86_64-apple-darwin\",\n dist: \"darwin-x64\",\n bin: \"bin/node\",\n ext: \"\",\n },\n \"linux x64\": {\n triple: \"x86_64-unknown-linux-gnu\",\n dist: \"linux-x64\",\n bin: \"bin/node\",\n ext: \"\",\n },\n };\n const target = table[`${platform} ${arch}`];\n if (!target) {\n throw new Error(\n `No Node sidecar mapping for ${platform} ${arch} — the desktop shell ` +\n `supports win32/x64, darwin/arm64, darwin/x64, linux/x64.`,\n );\n }\n return target;\n}\n\n/** Fetch the stock Node the shell ships as its sidecar into `<shellDir>/\n * binaries`, named per target triple. No-op when already present. Ported from\n * the reference repo's fetch-node.mjs (the builder has no such script). */\nexport function fetchNodeSidecar(\n shellDir: string,\n version: string = process.versions.node,\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch,\n): string {\n const target = nodeSidecarTarget(platform, arch);\n const binariesDir = path.join(shellDir, \"binaries\");\n fs.mkdirSync(binariesDir, { recursive: true });\n const dest = path.join(binariesDir, `node-${target.triple}${target.ext}`);\n if (fs.existsSync(dest)) return dest;\n\n if (platform === \"win32\") {\n const url = `https://nodejs.org/dist/v${version}/win-x64/node.exe`;\n execSync(`curl -fsSL -o \"${dest}\" \"${url}\"`, { stdio: \"inherit\" });\n } else {\n const name = `node-v${version}-${target.dist}`;\n const url = `https://nodejs.org/dist/v${version}/${name}.tar.gz`;\n execSync(\n `curl -fsSL \"${url}\" | tar -xz -C \"${binariesDir}\" --strip-components=2 ${name}/${target.bin}`,\n { stdio: \"inherit\", shell: \"/bin/sh\" },\n );\n fs.renameSync(path.join(binariesDir, \"node\"), dest);\n fs.chmodSync(dest, 0o755);\n }\n return dest;\n}\n\n/** Default bundle targets for the build host (`cargo tauri build --bundles`).\n * macOS gets app+dmg, Windows nsis, Linux deb+appimage — a host only builds\n * installers it can produce. */\nexport function tauriBundlesForHost(\n platform: NodeJS.Platform = process.platform,\n): string[] {\n switch (platform) {\n case \"darwin\":\n return [\"app\", \"dmg\"];\n case \"win32\":\n return [\"nsis\"];\n default:\n return [\"deb\", \"appimage\"];\n }\n}\n\nexport interface TauriCommand {\n /** The executable to spawn (e.g. \"cargo\" or a node path). */\n cmd: string;\n /** Args that precede the tauri subcommand (e.g. [\"tauri\"] for cargo). */\n prefix: string[];\n /** How the CLI was found — for logging + the preflight message. */\n via: \"cargo-tauri\" | \"node-cli\";\n}\n\n/** Spawn parameters that avoid DEP0190 (args array + shell:true): cargo on\n * Windows needs the shell for PATH/.exe + subcommand resolution — pass ONE\n * string, empty args; everything else runs argv directly (shell:false). The\n * joined tokens here are our own constants/paths, never user input. */\nexport function tauriSpawn(\n tauri: TauriCommand,\n subcommand: string[],\n): { command: string; args: string[]; shell: boolean } {\n const argv = [...tauri.prefix, ...subcommand];\n if (tauri.cmd === \"cargo\" && process.platform === \"win32\") {\n return { command: [\"cargo\", ...argv].join(\" \"), args: [], shell: true };\n }\n return { command: tauri.cmd, args: argv, shell: false };\n}\n\nfunction probe(cmd: string, args: string[]): boolean {\n const onWin = process.platform === \"win32\";\n try {\n const r = spawnSync(\n onWin ? [cmd, ...args].join(\" \") : cmd,\n onWin ? [] : args,\n { stdio: \"ignore\", shell: onWin },\n );\n return r.status === 0;\n } catch {\n return false;\n }\n}\n\n/** Is a Rust `cargo` on PATH? (needed to compile the shell crate). */\nexport function hasCargo(): boolean {\n return probe(\"cargo\", [\"--version\"]);\n}\n\n/** Resolve a Tauri CLI: a global `cargo tauri`, else a `@tauri-apps/cli`\n * resolvable from the project. Returns null when neither is available. */\nexport function resolveTauriCommand(projectRoot: string): TauriCommand | null {\n if (probe(\"cargo\", [\"tauri\", \"--version\"])) {\n return { cmd: \"cargo\", prefix: [\"tauri\"], via: \"cargo-tauri\" };\n }\n try {\n const require_ = createRequire(\n pathToFileURL(path.join(projectRoot, \"package.json\")).href,\n );\n // @tauri-apps/cli exposes its binary entry; resolve its package then bin.\n const pkgJson = require_.resolve(\"@tauri-apps/cli/package.json\");\n const pkgDir = path.dirname(pkgJson);\n const pkg = JSON.parse(fs.readFileSync(pkgJson, \"utf8\")) as {\n bin?: string | Record<string, string>;\n };\n const bin = pkg.bin;\n const rel = typeof bin === \"string\" ? bin : bin?.tauri;\n if (rel) {\n return {\n cmd: process.execPath,\n prefix: [path.join(pkgDir, rel)],\n via: \"node-cli\",\n };\n }\n } catch {\n // not installed in the project\n }\n return null;\n}\n\nexport interface Toolchain {\n cargo: boolean;\n tauri: TauriCommand | null;\n}\n\nexport function detectToolchain(projectRoot: string): Toolchain {\n return { cargo: hasCargo(), tauri: resolveTauriCommand(projectRoot) };\n}\n\n/** Throw a clear, actionable error when the native toolchain is incomplete —\n * the desktop verbs call this before any cargo work so a missing executable\n * is an instruction, not a stack trace. */\nexport function preflightOrThrow(\n tc: Toolchain,\n hostName: string,\n): TauriCommand {\n const missing: string[] = [];\n if (!tc.cargo) {\n missing.push(\n \" • Rust/cargo — install from https://rustup.rs (then restart your shell)\",\n );\n }\n if (!tc.tauri) {\n missing.push(\n ' • Tauri CLI — `cargo install tauri-cli --version \"^2\"` ' +\n \"(or add @tauri-apps/cli@^2 to your project's devDependencies)\",\n );\n }\n if (missing.length > 0 || !tc.tauri) {\n throw new Error(\n `hosts/${hostName}: the desktop shell needs a native toolchain that is ` +\n `not installed:\\n${missing.join(\"\\n\")}\\n` +\n `Install the above, then re-run \\`ph run ${hostName} dev\\` / ` +\n `\\`ph run ${hostName} build\\`. (The headless stack — \\`ph run ` +\n `${hostName}\\` — needs none of this.)`,\n );\n }\n return tc.tauri;\n}\n\n/** `<tauri> icon <source>` — generates the per-platform icon set (icon.ico +\n * icon.icns + pngs) the bundle references and tauri-build requires. */\nexport function runTauriIcon(\n tauri: TauriCommand,\n shellDir: string,\n iconSource: string,\n): void {\n const { command, args, shell } = tauriSpawn(tauri, [\"icon\", iconSource]);\n const r = spawnSync(command, args, {\n cwd: shellDir,\n stdio: \"inherit\",\n shell,\n });\n if (r.status !== 0) {\n throw new Error(\n `\\`tauri icon ${iconSource}\\` failed (exit ${r.status ?? \"?\"}) in ` +\n `${shellDir} — check that app.icon is a square PNG.`,\n );\n }\n}\n","import { spawn, type ChildProcess } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\n/**\n * Shell discovery and launch. The Rust/Tauri shell lives in the\n * ph-win-desktop repo (cargo cannot ride an npm package); the runner locates\n * a checkout via `runner.shell.project` or PH_DESKTOP_SHELL and prefers its\n * BUILT exe (dev config like window title is baked into a build — the\n * `--config` projection below applies to tauri-cli invocations only).\n */\n\nexport interface ShellOptions {\n /** Path to a ph-win-desktop checkout (absolute or project-relative). */\n project?: string;\n window?: { title?: string; width?: number; height?: number };\n tray?: boolean;\n fileAssociations?: string[];\n}\n\nexport interface ResolvedShell {\n projectDir: string;\n /** A built exe when one exists (debug preferred for dev), else undefined →\n * fall back to `pnpm tauri dev`. */\n exe?: string;\n}\n\nexport function resolveShell(\n projectRoot: string,\n options: ShellOptions | undefined,\n env: Record<string, string | undefined>,\n): ResolvedShell {\n const configured = options?.project ?? env.PH_DESKTOP_SHELL;\n if (!configured) {\n throw new Error(\n \"No desktop shell configured: set runner.shell.project in the host file \" +\n \"(path to a ph-win-desktop checkout) or the PH_DESKTOP_SHELL \" +\n \"environment variable. `ph run desktop` (headless stack) needs neither.\",\n );\n }\n const projectDir = path.resolve(projectRoot, configured);\n if (!fs.existsSync(path.join(projectDir, \"src-tauri\"))) {\n throw new Error(\n `Desktop shell not found at ${projectDir} (no src-tauri/) — check ` +\n `runner.shell.project / PH_DESKTOP_SHELL.`,\n );\n }\n const candidates = [\n path.join(projectDir, \"src-tauri\", \"target\", \"debug\", \"ph-win.exe\"),\n path.join(projectDir, \"src-tauri\", \"target\", \"release\", \"ph-win.exe\"),\n path.join(projectDir, \"src-tauri\", \"target\", \"debug\", \"ph-win\"),\n path.join(projectDir, \"src-tauri\", \"target\", \"release\", \"ph-win\"),\n ];\n const exe = candidates.find((c) => fs.existsSync(c));\n return { projectDir, exe };\n}\n\n/** Resolve the project's ph-cli entry from ITS dependency tree — the same\n * resolution `ph run` itself uses. */\nexport function resolvePhCliEntry(projectRoot: string): string {\n const require_ = createRequire(\n pathToFileURL(path.join(projectRoot, \"package.json\")).href,\n );\n const pkgPath = require_.resolve(\"@powerhousedao/ph-cli/package.json\");\n return path.join(path.dirname(pkgPath), \"dist\", \"cli.mjs\");\n}\n\n/** The env trio (plus flag and userData) the shell's uniform-runners mode\n * reads — wired by the RUNNER so nobody exports variables by hand. */\nexport function shellEnv(\n projectRoot: string,\n connectPort: number,\n env: Record<string, string | undefined>,\n): Record<string, string> {\n return {\n FEATURE_UNIFORM_RUNNERS_ENABLED: \"1\",\n PH_RUN_PROJECT: projectRoot,\n PH_RUN_CLI: resolvePhCliEntry(projectRoot),\n PH_WIN_CONNECT_PORT: String(connectPort),\n ...(env.PH_USER_DATA_DIR ? { PH_USER_DATA_DIR: env.PH_USER_DATA_DIR } : {}),\n };\n}\n\n/** Project host shell options onto a tauri `--config` merge patch (D6.d) —\n * the host file stays the single source for app identity on tauri-cli\n * invocations; a built exe has these baked. */\nexport function tauriConfigPatch(\n options: ShellOptions | undefined,\n): Record<string, unknown> | undefined {\n if (!options) return undefined;\n const patch: Record<string, unknown> = {};\n if (options.window) {\n patch.app = {\n windows: [\n {\n ...(options.window.title ? { title: options.window.title } : {}),\n ...(options.window.width ? { width: options.window.width } : {}),\n ...(options.window.height ? { height: options.window.height } : {}),\n },\n ],\n };\n }\n if (options.fileAssociations?.length) {\n patch.bundle = {\n fileAssociations: [\n {\n ext: options.fileAssociations.map((e) => e.replace(/^\\./, \"\")),\n name: \"Powerhouse Document\",\n },\n ],\n };\n }\n return Object.keys(patch).length > 0 ? patch : undefined;\n}\n\nexport function launchShell(\n shell: ResolvedShell,\n envVars: Record<string, string>,\n options: ShellOptions | undefined,\n): ChildProcess {\n if (shell.exe) {\n return spawn(shell.exe, [], {\n cwd: shell.projectDir,\n env: { ...process.env, ...envVars },\n stdio: \"inherit\",\n windowsHide: true,\n });\n }\n // tauri dev (needs cargo); config projection applies here.\n const patch = tauriConfigPatch(options);\n const args = [\"tauri\", \"dev\"];\n if (patch) args.push(\"--config\", JSON.stringify(patch));\n return spawn(\"pnpm\", args, {\n cwd: shell.projectDir,\n env: { ...process.env, ...envVars },\n stdio: \"inherit\",\n shell: true,\n windowsHide: true,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAM,mBAAmB,EACtB,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,MACC,qCACA,yFACF;AAEF,MAAM,eAAe,EAClB,aAAa;CACZ,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC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AQ,KAAA;AACjD;AAEA,SAAgB,YACd,OACA,SACA,SACc;CACd,IAAI,MAAM,KACR,OAAO,MAAM,MAAM,KAAK,CAAC,GAAG;EAC1B,KAAK,MAAM;EACX,KAAK;GAAE,GAAG,QAAQ;GAAK,GAAG;EAAQ;EAClC,OAAO;EACP,aAAa;CACf,CAAC;CAGH,MAAM,QAAQ,iBAAiB,OAAO;CACtC,MAAM,OAAO,CAAC,SAAS,KAAK;CAC5B,IAAI,OAAO,KAAK,KAAK,YAAY,KAAK,UAAU,KAAK,CAAC;CACtD,OAAO,MAAM,QAAQ,MAAM;EACzB,KAAK,MAAM;EACX,KAAK;GAAE,GAAG,QAAQ;GAAK,GAAG;EAAQ;EAClC,OAAO;EACP,OAAO;EACP,aAAa;CACf,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/desktop",
3
- "version": "6.2.3-dev.59",
3
+ "version": "6.2.3-dev.61",
4
4
  "description": "The desktop runner for uniform-runners hosts: the generic compound stack wrapped in a native shell — dev opens the window, build stages the shippable stack.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,7 +30,7 @@
30
30
  "./package.json": "./package.json"
31
31
  },
32
32
  "dependencies": {
33
- "@powerhousedao/host-core": "6.2.3-dev.59",
33
+ "@powerhousedao/host-core": "6.2.3-dev.61",
34
34
  "zod": "4.3.6"
35
35
  },
36
36
  "devDependencies": {
@@ -1,148 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import { spawn, spawnSync } from "node:child_process";
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- import { pathToFileURL } from "node:url";
6
- //#region src/bundle-stack.ts
7
- function copyIfExists(from, to) {
8
- if (!fs.existsSync(from)) return false;
9
- fs.cpSync(from, to, { recursive: true });
10
- return true;
11
- }
12
- function bundleStack(options) {
13
- const log = options.logger ?? console.log;
14
- const stackDir = path.join(options.shellProjectDir, "dist-stack");
15
- for (const entry of [
16
- "hosts",
17
- "agents",
18
- "dist",
19
- "powerhouse.config.json",
20
- "package.json"
21
- ]) fs.rmSync(path.join(stackDir, entry), {
22
- recursive: true,
23
- force: true
24
- });
25
- fs.mkdirSync(stackDir, { recursive: true });
26
- for (const dir of [
27
- "hosts",
28
- "agents",
29
- "dist"
30
- ]) log(` ${dir}/ ${copyIfExists(path.join(options.projectRoot, dir), path.join(stackDir, dir)) ? "staged" : "absent — skipped"}`);
31
- const stagedDesktopHost = path.join(stackDir, "hosts", "desktop", "host.js");
32
- if (fs.existsSync(stagedDesktopHost)) {
33
- const source = fs.readFileSync(stagedDesktopHost, "utf8");
34
- if (source.includes("@powerhousedao/desktop/runner")) {
35
- fs.writeFileSync(stagedDesktopHost, "// STAGED COPY (bundle-stack): runner.module rewritten to the generic\n// compound — the packaged shell is the window; there is no nested shell.\n" + source.replace(/@powerhousedao\/desktop\/runner/g, "@powerhousedao/host-core/runners/compound"));
36
- log(" hosts/desktop/host.js: runner rewritten to the generic compound (staged copy)");
37
- }
38
- }
39
- copyIfExists(path.join(options.projectRoot, "powerhouse.config.json"), path.join(stackDir, "powerhouse.config.json"));
40
- if (typeof options.connectPort === "number") {
41
- fs.writeFileSync(path.join(stackDir, "shell.json"), `${JSON.stringify({ connectPort: options.connectPort }, null, 2)}\n`);
42
- log(` shell.json: connectPort ${options.connectPort}`);
43
- }
44
- const sourcePkg = JSON.parse(fs.readFileSync(path.join(options.projectRoot, "package.json"), "utf8"));
45
- const version = options.phCliVersion ?? "dev";
46
- fs.writeFileSync(path.join(stackDir, "package.json"), `${JSON.stringify({
47
- name: sourcePkg.name ?? "powerhouse-desktop-stack",
48
- private: true,
49
- type: "module",
50
- dependencies: { "@powerhousedao/ph-cli": version }
51
- }, null, 2)}\n`);
52
- let vendored = false;
53
- if (options.vendor !== false) {
54
- const specs = `"${options.phCliSpec ?? `@powerhousedao/ph-cli@${version}`}" "@powerhousedao/host-core@${version}"`;
55
- log(` vendoring ${specs} (hoisted, real files)…`);
56
- const result = spawnSync(`npm install ${specs} --install-strategy=hoisted --omit=dev --no-audit --no-fund`, {
57
- cwd: stackDir,
58
- stdio: "pipe",
59
- shell: true,
60
- windowsHide: true
61
- });
62
- if (result.status !== 0) throw new Error(`bundle-stack: vendoring failed (${result.status}):\n${result.stderr.toString().slice(-800)}`);
63
- vendored = true;
64
- } else log(" vendoring skipped (vendor: false) — existing tree left in place");
65
- return {
66
- stackDir,
67
- vendored
68
- };
69
- }
70
- //#endregion
71
- //#region src/shell.ts
72
- function resolveShell(projectRoot, options, env) {
73
- const configured = options?.project ?? env.PH_DESKTOP_SHELL;
74
- if (!configured) throw new Error("No desktop shell configured: set runner.shell.project in the host file (path to a ph-win-desktop checkout) or the PH_DESKTOP_SHELL environment variable. `ph run desktop` (headless stack) needs neither.");
75
- const projectDir = path.resolve(projectRoot, configured);
76
- if (!fs.existsSync(path.join(projectDir, "src-tauri"))) throw new Error(`Desktop shell not found at ${projectDir} (no src-tauri/) — check runner.shell.project / PH_DESKTOP_SHELL.`);
77
- return {
78
- projectDir,
79
- exe: [
80
- path.join(projectDir, "src-tauri", "target", "debug", "ph-win.exe"),
81
- path.join(projectDir, "src-tauri", "target", "release", "ph-win.exe"),
82
- path.join(projectDir, "src-tauri", "target", "debug", "ph-win"),
83
- path.join(projectDir, "src-tauri", "target", "release", "ph-win")
84
- ].find((c) => fs.existsSync(c))
85
- };
86
- }
87
- /** Resolve the project's ph-cli entry from ITS dependency tree — the same
88
- * resolution `ph run` itself uses. */
89
- function resolvePhCliEntry(projectRoot) {
90
- const pkgPath = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href).resolve("@powerhousedao/ph-cli/package.json");
91
- return path.join(path.dirname(pkgPath), "dist", "cli.mjs");
92
- }
93
- /** The env trio (plus flag and userData) the shell's uniform-runners mode
94
- * reads — wired by the RUNNER so nobody exports variables by hand. */
95
- function shellEnv(projectRoot, connectPort, env) {
96
- return {
97
- FEATURE_UNIFORM_RUNNERS_ENABLED: "1",
98
- PH_RUN_PROJECT: projectRoot,
99
- PH_RUN_CLI: resolvePhCliEntry(projectRoot),
100
- PH_WIN_CONNECT_PORT: String(connectPort),
101
- ...env.PH_USER_DATA_DIR ? { PH_USER_DATA_DIR: env.PH_USER_DATA_DIR } : {}
102
- };
103
- }
104
- /** Project host shell options onto a tauri `--config` merge patch (D6.d) —
105
- * the host file stays the single source for app identity on tauri-cli
106
- * invocations; a built exe has these baked. */
107
- function tauriConfigPatch(options) {
108
- if (!options) return void 0;
109
- const patch = {};
110
- if (options.window) patch.app = { windows: [{
111
- ...options.window.title ? { title: options.window.title } : {},
112
- ...options.window.width ? { width: options.window.width } : {},
113
- ...options.window.height ? { height: options.window.height } : {}
114
- }] };
115
- if (options.fileAssociations?.length) patch.bundle = { fileAssociations: [{
116
- ext: options.fileAssociations.map((e) => e.replace(/^\./, "")),
117
- name: "Powerhouse Document"
118
- }] };
119
- return Object.keys(patch).length > 0 ? patch : void 0;
120
- }
121
- function launchShell(shell, envVars, options) {
122
- if (shell.exe) return spawn(shell.exe, [], {
123
- cwd: shell.projectDir,
124
- env: {
125
- ...process.env,
126
- ...envVars
127
- },
128
- stdio: "inherit",
129
- windowsHide: true
130
- });
131
- const patch = tauriConfigPatch(options);
132
- const args = ["tauri", "dev"];
133
- if (patch) args.push("--config", JSON.stringify(patch));
134
- return spawn("pnpm", args, {
135
- cwd: shell.projectDir,
136
- env: {
137
- ...process.env,
138
- ...envVars
139
- },
140
- stdio: "inherit",
141
- shell: true,
142
- windowsHide: true
143
- });
144
- }
145
- //#endregion
146
- export { tauriConfigPatch as a, shellEnv as i, resolvePhCliEntry as n, bundleStack as o, resolveShell as r, launchShell as t };
147
-
148
- //# sourceMappingURL=shell-DcBLVLVz.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shell-DcBLVLVz.mjs","names":[],"sources":["../src/bundle-stack.ts","../src/shell.ts"],"sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * P6.3 — stage the shippable STACK into the shell project: everything the\n * installed app needs to run `ph run desktop` with no environment at all\n * (D6.c). The shell's resources map `../dist-stack` → `stack`, and its\n * uniform-runners mode falls back to `resources/stack` when the env pair is\n * absent. Layout:\n *\n * dist-stack/\n * hosts/ the project's host files\n * agents/ when present\n * powerhouse.config.json\n * package.json minimal, names the project\n * dist/ the BUILT Connect (ph run connect build)\n * node_modules/ vendored @powerhousedao/ph-cli (hoisted,\n * real files — computed-specifier imports and\n * PGlite wasm forbid bundling)\n */\nexport interface BundleStackOptions {\n projectRoot: string;\n shellProjectDir: string;\n /** Vendor the runtime packages (slow). Skipped when false — an existing\n * vendored tree is left in place. */\n vendor?: boolean;\n /** The ph-cli version/tag to vendor. Default: \"dev\". NOTE: the vendored\n * ph-cli must carry the `run` command — registry tags published before\n * uniform-runners landed cannot run a stack; until a nightly catches up,\n * pass `phCliSpec` with a locally packed tarball instead. */\n phCliVersion?: string;\n /** Overrides the ph-cli install spec entirely (e.g. a `pnpm pack` tarball\n * path for a not-yet-published build). */\n phCliSpec?: string;\n /** The connect member's port — written into the stack's shell.json so the\n * shell knows where to probe/navigate with no environment at all. */\n connectPort?: number;\n logger?: (message: string) => void;\n}\n\nexport interface BundleStackResult {\n stackDir: string;\n vendored: boolean;\n}\n\nfunction copyIfExists(from: string, to: string): boolean {\n if (!fs.existsSync(from)) return false;\n fs.cpSync(from, to, { recursive: true });\n return true;\n}\n\nexport function bundleStack(options: BundleStackOptions): BundleStackResult {\n const log = options.logger ?? console.log;\n const stackDir = path.join(options.shellProjectDir, \"dist-stack\");\n\n // Fresh staging for project files; the vendored node_modules survives\n // unless re-vendoring (it is by far the slowest part).\n for (const entry of [\n \"hosts\",\n \"agents\",\n \"dist\",\n \"powerhouse.config.json\",\n \"package.json\",\n ]) {\n fs.rmSync(path.join(stackDir, entry), { recursive: true, force: true });\n }\n fs.mkdirSync(stackDir, { recursive: true });\n\n for (const dir of [\"hosts\", \"agents\", \"dist\"]) {\n const copied = copyIfExists(\n path.join(options.projectRoot, dir),\n path.join(stackDir, dir),\n );\n log(` ${dir}/ ${copied ? \"staged\" : \"absent — skipped\"}`);\n }\n\n // Inside the package there is no nested shell — the shell IS the window —\n // so the staged desktop host runs on the generic compound. Rewrite the\n // runner.module projection in the STAGED copy only.\n const stagedDesktopHost = path.join(stackDir, \"hosts\", \"desktop\", \"host.js\");\n if (fs.existsSync(stagedDesktopHost)) {\n const source = fs.readFileSync(stagedDesktopHost, \"utf8\");\n if (source.includes(\"@powerhousedao/desktop/runner\")) {\n fs.writeFileSync(\n stagedDesktopHost,\n \"// STAGED COPY (bundle-stack): runner.module rewritten to the generic\\n\" +\n \"// compound — the packaged shell is the window; there is no nested shell.\\n\" +\n source.replace(\n /@powerhousedao\\/desktop\\/runner/g,\n \"@powerhousedao/host-core/runners/compound\",\n ),\n );\n log(\n \" hosts/desktop/host.js: runner rewritten to the generic compound (staged copy)\",\n );\n }\n }\n copyIfExists(\n path.join(options.projectRoot, \"powerhouse.config.json\"),\n path.join(stackDir, \"powerhouse.config.json\"),\n );\n\n // shell.json: the stack's contract with the shell. The no-env (packaged)\n // path has nobody to set PH_WIN_CONNECT_PORT, so the shell reads the probe\n // and window port from here.\n if (typeof options.connectPort === \"number\") {\n fs.writeFileSync(\n path.join(stackDir, \"shell.json\"),\n `${JSON.stringify({ connectPort: options.connectPort }, null, 2)}\\n`,\n );\n log(` shell.json: connectPort ${options.connectPort}`);\n }\n\n // A minimal manifest: names the project (lock identity) and depends on\n // ph-cli so the vendored tree resolves exactly like a real install.\n const sourcePkg = JSON.parse(\n fs.readFileSync(path.join(options.projectRoot, \"package.json\"), \"utf8\"),\n ) as { name?: string };\n const version = options.phCliVersion ?? \"dev\";\n fs.writeFileSync(\n path.join(stackDir, \"package.json\"),\n `${JSON.stringify(\n {\n name: sourcePkg.name ?? \"powerhouse-desktop-stack\",\n private: true,\n type: \"module\",\n dependencies: { \"@powerhousedao/ph-cli\": version },\n },\n null,\n 2,\n )}\\n`,\n );\n\n let vendored = false;\n if (options.vendor !== false) {\n const phCliSpec = options.phCliSpec ?? `@powerhousedao/ph-cli@${version}`;\n // host-core rides along: host files resolve runner modules (the generic\n // compound) from the STACK's own node_modules.\n const specs = `\"${phCliSpec}\" \"@powerhousedao/host-core@${version}\"`;\n log(` vendoring ${specs} (hoisted, real files)…`);\n // One command string: shell:true with an args ARRAY concatenates without\n // escaping (DEP0190 warns); the spec values are our own constants/paths.\n const result = spawnSync(\n `npm install ${specs} --install-strategy=hoisted --omit=dev --no-audit --no-fund`,\n { cwd: stackDir, stdio: \"pipe\", shell: true, windowsHide: true },\n );\n if (result.status !== 0) {\n throw new Error(\n `bundle-stack: vendoring failed (${result.status}):\\n` +\n `${result.stderr.toString().slice(-800)}`,\n );\n }\n vendored = true;\n } else {\n log(\" vendoring skipped (vendor: false) — existing tree left in place\");\n }\n\n return { stackDir, vendored };\n}\n","import { spawn, type ChildProcess } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\n/**\n * Shell discovery and launch. The Rust/Tauri shell lives in the\n * ph-win-desktop repo (cargo cannot ride an npm package); the runner locates\n * a checkout via `runner.shell.project` or PH_DESKTOP_SHELL and prefers its\n * BUILT exe (dev config like window title is baked into a build — the\n * `--config` projection below applies to tauri-cli invocations only).\n */\n\nexport interface ShellOptions {\n /** Path to a ph-win-desktop checkout (absolute or project-relative). */\n project?: string;\n window?: { title?: string; width?: number; height?: number };\n tray?: boolean;\n fileAssociations?: string[];\n}\n\nexport interface ResolvedShell {\n projectDir: string;\n /** A built exe when one exists (debug preferred for dev), else undefined →\n * fall back to `pnpm tauri dev`. */\n exe?: string;\n}\n\nexport function resolveShell(\n projectRoot: string,\n options: ShellOptions | undefined,\n env: Record<string, string | undefined>,\n): ResolvedShell {\n const configured = options?.project ?? env.PH_DESKTOP_SHELL;\n if (!configured) {\n throw new Error(\n \"No desktop shell configured: set runner.shell.project in the host file \" +\n \"(path to a ph-win-desktop checkout) or the PH_DESKTOP_SHELL \" +\n \"environment variable. `ph run desktop` (headless stack) needs neither.\",\n );\n }\n const projectDir = path.resolve(projectRoot, configured);\n if (!fs.existsSync(path.join(projectDir, \"src-tauri\"))) {\n throw new Error(\n `Desktop shell not found at ${projectDir} (no src-tauri/) — check ` +\n `runner.shell.project / PH_DESKTOP_SHELL.`,\n );\n }\n const candidates = [\n path.join(projectDir, \"src-tauri\", \"target\", \"debug\", \"ph-win.exe\"),\n path.join(projectDir, \"src-tauri\", \"target\", \"release\", \"ph-win.exe\"),\n path.join(projectDir, \"src-tauri\", \"target\", \"debug\", \"ph-win\"),\n path.join(projectDir, \"src-tauri\", \"target\", \"release\", \"ph-win\"),\n ];\n const exe = candidates.find((c) => fs.existsSync(c));\n return { projectDir, exe };\n}\n\n/** Resolve the project's ph-cli entry from ITS dependency tree — the same\n * resolution `ph run` itself uses. */\nexport function resolvePhCliEntry(projectRoot: string): string {\n const require_ = createRequire(\n pathToFileURL(path.join(projectRoot, \"package.json\")).href,\n );\n const pkgPath = require_.resolve(\"@powerhousedao/ph-cli/package.json\");\n return path.join(path.dirname(pkgPath), \"dist\", \"cli.mjs\");\n}\n\n/** The env trio (plus flag and userData) the shell's uniform-runners mode\n * reads — wired by the RUNNER so nobody exports variables by hand. */\nexport function shellEnv(\n projectRoot: string,\n connectPort: number,\n env: Record<string, string | undefined>,\n): Record<string, string> {\n return {\n FEATURE_UNIFORM_RUNNERS_ENABLED: \"1\",\n PH_RUN_PROJECT: projectRoot,\n PH_RUN_CLI: resolvePhCliEntry(projectRoot),\n PH_WIN_CONNECT_PORT: String(connectPort),\n ...(env.PH_USER_DATA_DIR ? { PH_USER_DATA_DIR: env.PH_USER_DATA_DIR } : {}),\n };\n}\n\n/** Project host shell options onto a tauri `--config` merge patch (D6.d) —\n * the host file stays the single source for app identity on tauri-cli\n * invocations; a built exe has these baked. */\nexport function tauriConfigPatch(\n options: ShellOptions | undefined,\n): Record<string, unknown> | undefined {\n if (!options) return undefined;\n const patch: Record<string, unknown> = {};\n if (options.window) {\n patch.app = {\n windows: [\n {\n ...(options.window.title ? { title: options.window.title } : {}),\n ...(options.window.width ? { width: options.window.width } : {}),\n ...(options.window.height ? { height: options.window.height } : {}),\n },\n ],\n };\n }\n if (options.fileAssociations?.length) {\n patch.bundle = {\n fileAssociations: [\n {\n ext: options.fileAssociations.map((e) => e.replace(/^\\./, \"\")),\n name: \"Powerhouse Document\",\n },\n ],\n };\n }\n return Object.keys(patch).length > 0 ? patch : undefined;\n}\n\nexport function launchShell(\n shell: ResolvedShell,\n envVars: Record<string, string>,\n options: ShellOptions | undefined,\n): ChildProcess {\n if (shell.exe) {\n return spawn(shell.exe, [], {\n cwd: shell.projectDir,\n env: { ...process.env, ...envVars },\n stdio: \"inherit\",\n windowsHide: true,\n });\n }\n // tauri dev (needs cargo); config projection applies here.\n const patch = tauriConfigPatch(options);\n const args = [\"tauri\", \"dev\"];\n if (patch) args.push(\"--config\", JSON.stringify(patch));\n return spawn(\"pnpm\", args, {\n cwd: shell.projectDir,\n env: { ...process.env, ...envVars },\n stdio: \"inherit\",\n shell: true,\n windowsHide: true,\n });\n}\n"],"mappings":";;;;;;AA8CA,SAAS,aAAa,MAAc,IAAqB;CACvD,IAAI,CAAC,GAAG,WAAW,IAAI,GAAG,OAAO;CACjC,GAAG,OAAO,MAAM,IAAI,EAAE,WAAW,KAAK,CAAC;CACvC,OAAO;AACT;AAEA,SAAgB,YAAY,SAAgD;CAC1E,MAAM,MAAM,QAAQ,UAAU,QAAQ;CACtC,MAAM,WAAW,KAAK,KAAK,QAAQ,iBAAiB,YAAY;CAIhE,KAAK,MAAM,SAAS;EAClB;EACA;EACA;EACA;EACA;CACF,GACE,GAAG,OAAO,KAAK,KAAK,UAAU,KAAK,GAAG;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC;CAExE,GAAG,UAAU,UAAU,EAAE,WAAW,KAAK,CAAC;CAE1C,KAAK,MAAM,OAAO;EAAC;EA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