Boxlang runtime desktop electron

From ortus-docs/coldbox-docs · View interactive version

Boxlang runtime desktop electron is an AI agent skill from the GitHub repository ortus-docs/coldbox-docs. Use this skill when building BoxLang desktop applications with Electron and the BoxLang MiniServer, including process lifecycle wiring, miniserver.json-driven development control, runtime/Package.bx packaging, .boxlang-dev.json versus .boxlang.json behavior, default /app and /public mappings, and cr

How to use this skill

Skill file

BoxLang Desktop Runtime (Electron + MiniServer)

Overview

This skill applies to desktop applications that embed BoxLang using Electron and run a local BoxLang MiniServer process.

Core model:

This pattern gives a desktop UX without replacing BoxLang with another backend stack.


Architecture Baseline

Expected module boundaries:

Preserve modular boundaries in app/electron/* instead of collapsing logic into a single file.


Packaging Model

Package the MiniServer runtime, not Java:

Important runtime constraint:


Configuration Responsibilities

`miniserver.json` (development server control)

Use this as the primary local server control file for desktop development:

Example:

{
    "port": 59700,
    "host": "127.0.0.1",
    "webRoot": "public",
    "serverHome": ".boxlang",
    "rewrites": true,
    "debug": false,
    "envFile": ".env"
}

`.boxlang-dev.json` vs `.boxlang.json`

Use split runtime config for predictable behavior:

Both should include baseline mappings so classes/templates resolve predictably:

"/app": {
    "path": "${user-dir}/app",
    "external": false
},
"/public": "${user-dir}/public"

Startup and Readiness Pattern

Recommended process flow in BoxLang.js:

  1. Detect packaged runtime executable and fallback command.
  2. Ensure execute permission on Unix-like systems.
  3. Spawn MiniServer with miniserver.json.
  4. Poll server URL readiness with timeout and retry interval.
  5. On ready: load BrowserWindow URL.
  6. On crash: apply controlled restart strategy with delay and user notification.

Checklist for robust lifecycle handling:


Build and Packaging Workflow

Common script set for this runtime style:

Use package:full for distributable builds.


Electron Forge

This project uses Electron Forge as the packaging and distribution tool (forge.config.cjs).

Critical constraint — `asar` must always be `false`

packagerConfig: {
    asar: false,
    ...
}

BoxLang.js spawns runtime/bin/boxlang-miniserver as a real OS process. If asar: true, Forge archives the app directory into a single .asar file and the spawned path no longer exists on the filesystem, breaking MiniServer startup entirely.

Icon resolution

Forge resolves icons from the base name in packagerConfig.icon:

icon: "./public/includes/icon",

It then appends the platform-appropriate extension automatically:

| Platform | Extension | Source |

|----------|-----------|--------|

| macOS | .icns | public/includes/icon.icns (from iconset via iconutil) |

| Windows | .ico | public/includes/icon.ico (generated by npm run generate:icons) |

| Linux | .png | public/includes/icon.iconset/icon.png |

All three files must exist at package time. Missing any one causes a fatal Forge error on that platform.

Makers

| Platform | Maker | Output |

|----------|-------|--------|

| macOS | @electron-forge/maker-dmg, @electron-forge/maker-zip | .dmg, .zip |

| Windows | @electron-forge/maker-squirrel, @electron-forge/maker-zip | .exe (Squirrel), .zip |

| Linux | @electron-forge/maker-deb, @electron-forge/maker-rpm | .deb, .rpm |

Windows installer uses Squirrel, not NSIS.

postMake hook

The config includes a postMake hook that copies unsigned-build helper scripts (mac-open.sh, win-unblock.ps1, UNSIGNED-BUILD.md) into every ZIP artifact so end users have bypass instructions without hunting for docs.


BoxLang and Runtime Rules


Troubleshooting Guide

MiniServer fails to start

Permission denied on Unix-like hosts

App runs but UI assets missing

Runs on dev machine but fails on user machine


CI / GitHub Actions Constraints

Node.js Version for Windows Builds

Pin the Windows runner to Node 20 LTS. cross-zip (a transitive dependency of @electron-forge/maker-zip) calls fs.rmdir(path, { recursive: true }), which was removed in Node.js 22+. Running Node 25 on windows-latest causes a hard failure during the Squirrel make step:

TypeError [ERR_INVALID_ARG_VALUE]: The property 'options.recursive' is no longer supported. Received true

Workaround in .github/workflows/build.yml:

- name: Set up Node.js
  uses: actions/setup-node@v6
  with:
    # Pin to Node 20 LTS — cross-zip uses fs.rmdir({recursive:true}) removed in Node 22+
    node-version: "20"
    cache: "npm"

Revisit when cross-zip or @electron-forge/maker-zip ships a patched release.

Windows `.ico` Icon Requirement

The Squirrel installer (@electron-forge/maker-squirrel) requires a real .ico file on Windows. Forge auto-resolves icons from the base name configured in packagerConfig.icon. A missing .ico produces:

Fatal error: Unable to set icon

The scripts/generate-icons.js script generates public/includes/icon.ico from the PNG iconset. Run it in CI before packaging:

- name: Generate Windows icon
  run: npm run generate:icons

- name: Package Electron app (Windows)
  run: npm run package:win

Alternatively, commit public/includes/icon.ico to the repository to skip the generation step in CI entirely (recommended for faster, more predictable builds).


Agent Instruction Conventions

For repositories using this starter, adopt the two-file instruction pattern for maximum agent compatibility:

Template for .github/copilot-instructions.md:

# Project — Copilot Bridge Instructions

Use AGENTS.md at repository root as the canonical instruction source.

## Canonical Source

- Primary instructions: AGENTS.md
- If any conflict exists, AGENTS.md wins.

## Critical Guardrails

- Keep modular boundaries in app/electron/* — do not collapse into a single file.
- Preserve process lifecycle safety in MiniServer startup and shutdown paths.
- Preserve cross-platform behavior (macOS, Windows, Linux).
- Do not remove packaged-runtime-first fallback to global boxlang-miniserver.
- Never enable asar in forge.config.cjs — MiniServer spawning requires real filesystem paths.

Best Practices

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.