Self-improving AI Employees for everyone
Release Build Pipeline
Compile-step plan for the registry tarball @zeenie-ai/opencompany (published to npmjs and GitHub Packages, installed with bun add -g). Goal: cut cold-start ~20s further on top of the lazy-LangChain fix already in v0.0.76, shrink the Vite main bundle below 200 KB gz, and drop the tsx interpreter cost from the JS executor sidecar.
User scope (confirmed before this work): stay on the registry-tarball distribution; no Nuitka/PyOxidizer standalone binary channel; optimize Vite output too; skip the plugin-walker (11s) and service-status-refresh (20s) hotspots — those are runtime concerns, not compile-time.
Tooling
| Layer | Tool | Why |
|---|---|---|
| TypeScript type-check | typescript@7 (the native Go compiler) at the repo root |
5.9× faster on --noEmit — measured 2026-07-26 on this codebase, 3 warm runs each: ~820 ms vs ~4830 ms under tsc 5.9.3. Type-check only; Vite/esbuild keep producing the actual JS bundles. Lives in root devDependencies, exact-pinned, never ships to users. |
| Vite output | manualChunks + target: 'es2022' |
Split heavy libs (reactflow, radix-ui, lobehub, react-markdown stack) so the main bundle no longer hits the 1500KB warning ceiling. ES2022 unlocks findLast / optional-chaining-assignment without polyfills (Chrome 94+, FF 93+, Safari 15.4+ — within React 19 / Tailwind 4 baseline). |
| JS executor sidecar | bun build src/index.ts --target=bun --outfile=dist/index.js, run via bun dist/index.js |
Drops tsx interpreter startup (~500ms-1s every server boot). --target=bun yields a self-contained bundle with Express inlined — no node_modules at runtime, which is what lets the desktop bundle copy one file. (The first cut was an esbuild bundle with --packages=external run on Node; superseded when bun became the only shipped JavaScript runtime.) |
| Python | python -m compileall -q -j 0 <project dirs> + [tool.uv] compile-bytecode = true |
Pre-compile bytecode. Implemented as step [5/6] in cli/commands/build.py (COMPILEALL_SOURCE_DIRS constant lists the dirs); server/pyproject.toml's compile-bytecode = true makes step [4/6]'s uv sync --extra docs compile .venv/ site-packages too. No -O: every runtime launches python without -O, and per PEP 488 a non-optimized interpreter only loads plain .pyc — the earlier -O invocation produced .opt-1.pyc that nothing ever loaded (fixed 2026-07-14; ~30-50s cold-start gain, see performance.md). |
Package manager (bun)
Coding Agent adds a private server/pi package, pinned to the full Pi SDK
1.1.0 with its own frozen lockfile. company build installs and builds it
after the JavaScript sidecar. Its host keeps SDK imports external and ships
server/pi/dist/runtime.tgz plus an integrity manifest, preserving the full
production dependency tree and package assets. Desktop staging rebuilds and
copies the same three distribution files; Docker builds them before removing
Pi source and build dependencies. Runtime extraction is offline and uses a
content-addressed data cache. See Pi Coding Agent.
The dev workspace runs on bun (migrated from [email protected], 2026-08; pinned
via "packageManager": "[email protected]" — CI's oven-sh/setup-bun reads that pin).
Facts that are load-bearing, each verified during the migration:
- Scope: bun installs the workspace, runs scripts, and is the only
JavaScript runtime anything shipped needs — the
companyshim (bin/cli.js,#!/usr/bin/env bun), the JS executor sidecar (bun dist/index.js), the plugin CLIs in the shared<DATA_DIR>/packages/tree (server/core/js_runtime.py,bun add --cwd), the sidecar's user-package endpoints (bun add), andbun publish --access publicin release.yml.enginesis{"bun": ">=1.4.0"}; end users install withbun add -g @zeenie-ai/opencompany; the desktop app bundles bun. Node is dev/CI-only: when present, bun runs vite / vitest / eslint on it via their node shebangs (never pass--bun— vitest and eslint have open bun-runtime bugs), andcompany buildreports it as optional. - Gate:
scripts/preinstall.jsrejects non-bun installs in a source checkout. It keys onbunfig.tomlexisting (committed, excluded from the tarball by thefilesallowlist, so end-userbun add -ginstalls never trigger it — a global add runs no lifecycle scripts anyway) and onnpm_config_user_agentstarting withbun— bun's UA isbun/x.y.z npm/? node/..., so a substring match on "npm" would misfire. - Layout:
bunfig.tomlpinslinker = "isolated"— pnpm-style symlinkednode_moduleswith the store atnode_modules/.bun/(NOT.pnpm/). The phantom-dependency guard, thetypeRootstsconfig workaround, and thevite-env.d.tstriple-slash reference all depend on this layout. - Lockfile: the tracked text
bun.lockis lockfileVersion 3 — forced by the version-ranged keys in the top-leveloverridesblock (the security pins formerly underpnpm.overrides, moved verbatim). Older bun cannot read it; thepackageManagerpin is the effective read-floor. - Sharp edges (each bites silently): declaring
trustedDependenciesREPLACES bun's default trusted list rather than extending it — do not declare it (esbuild's install script would stop running); never pass--omit=optional(it drops the per-platform rollup/esbuild/TS7 binaries, oven-sh/bun#16696); bun 1.4 rejects the space-separated--cwd ..form (bun --cwd=.. run <script>is required — this is why the client typecheck script uses=); and--filtermust come AFTER therunsubcommand. - Lost guard: pnpm's
strict-peer-dependencieshas no bun equivalent (bun never errors on peer conflicts, oven-sh/bun#9135). Thetest_client_keeps_typescript_5_for_typescript_eslintCLI test is now the only check keeping clienttypescriptinside typescript-eslint's peer range. - Config invariants (gate source, manifest shape, bunfig linker, workspace
paths) are locked by
cli/tests/test_release_pipeline_config.py; the workspace-member oracle incli/tests/conftest.pyparses the rootworkspacesarray directly (bun has nopnpm list --jsonequivalent).
Implementation steps
1. TypeScript 7 type-check
The native Go compiler shipped inside mainline typescript at the 7.0 GA
(2026-07-08). The old @typescript/native-preview channel — whose binary was
named tsgo — stopped publishing the day before and must not come back.
The gate lives at the repo root, and that placement is forced, not stylistic:
clientalready depends ontypescript@^5.9.3, which typescript-eslint needs (it loads the TS API at module scope and its peer range excludes 6.x/7.x). A single manifest cannot declaretypescripttwice.typescript@7andtypescript@5both ship atscbin. Co-locating them would leave bun's bin-link conflict resolution (under the isolated linker) deciding which compiler gates CI. (No collision exists today only becausenative-preview's bin wastsgo.)Root declares no
typescriptand notypescript-eslint, so there is no peer conflict and nothing else claimstsc.root
package.json→devDependencies: { "typescript": "7.0.2" }, exact — no caret, so the compiler that gates CI never moves on an unrelated install; plus"typecheck": "tsc --noEmit -p client/tsconfig.json"client/package.json→"typecheck": "bun --cwd=.. run typecheck"(delegates up, so the CI command and its guard test stay byte-identical)"typecheck:tsc": "tsc --noEmit"— resolves client's own 5.9.3. A second opinion for triaging a red gate, NOT an equivalent check and NOT a revert path: the two compilers check different programs under different default rules. Nothing in CI runs it, so verify it independently before trusting it.
.github/workflows/predeploy.yml→bun run --filter react-flow-client typecheckin thebuild-and-lintjob. (This gate lives inpredeploy.yml, notrelease.yml.) The cross-OStest-build-startmatrix additionally runsbun run tsc --version, because the TS7 compiler is a per-platform Go binary delivered viaoptionalDependencies— the type-check itself runs only on ubuntu, so without that step the darwin-arm64 and win32-x64 binaries would be installed on every matrix run and never executed.
2. Vite manualChunks + target
client/vite.config.js→ extendbuildblock:target: 'es2022'chunkSizeWarningLimit: 850(down from 1500; the plan said 600, butvendor-icons— lucide + lobehub brand SVGs — is ~830 KB on its own, so the ceiling sits just above it and other chunks still trip it)rollupOptions.output.manualChunksmapping:vendor-react:react,react-dom,react-hook-form,@hookform/resolversvendor-flow:reactflowvendor-radix:radix-ui(the single umbrella package; no@radix-ui/*scoped entries)vendor-icons:lucide-react,@lobehub/iconsvendor-query:@tanstack/react-query,@tanstack/query-sync-storage-persister,@tanstack/react-query-persist-client,@lukemorales/query-key-factoryvendor-markdown:react-markdown,remark-gfm,remark-breaks,prismjs,react-simple-code-editor,@uiw/react-json-viewvendor-misc:idb-keyval,fuzzysort,cmdk,sonner,qrcode.react
Keep sourcemap: analyze (already correct), keep React Compiler config.
3. JS executor sidecar bundle (bun build)
server/nodejs/package.jsonscripts (no esbuild, no tsx — bun bundles and runs TypeScript natively):"build": "bun build src/index.ts --target=bun --outfile=dist/index.js"—--target=buninlinesexpressinto one self-contained file (locked flag-by-flag bytest_sidecar_build_script_carries_required_bun_build_flag, which also asserts noesbuild/--packages=external)"start": "bun dist/index.js"(wastsx src/index.ts, thennode dist/index.js;test_sidecar_start_runs_compiled_bundle_on_bun)"dev": "bun --watch src/index.ts"(test_sidecar_dev_uses_bun_watch)"engines": {"bun": ">=1.4.0"}— no Node floor (test_sidecar_engines_declare_bun_not_node)
- At runtime
nodes/code/_runtime.pyspawns[bun, dist/index.js], resolving bun throughserver/core/js_runtime.py(OPENCOMPANY_BUN_BIN, else PATH). Verified on bun 1.4.0 with Node stripped from PATH, includingnode:vmrunInContextwith the timeout. server/nodejs/.gitignore→ new file:dist/
4. Python bytecode pre-compile
Two halves (both required; see performance.md for the 2026-07-14 cold-boot measurements that motivated the split):
server/pyproject.toml→[tool.uv] compile-bytecode = truemakes everyuv sync(step[4/6]runsuv sync --extra docs;scripts/install.jsruns plainuv sync) compile all.venv/site-packages at install time. uv's default is false — without this, every dependency.pycompiles lazily on the first import after a fresh sync.cli/commands/build.py→ step[5/6]covers the project's own source:
Norun( uv_run("python", "-m", "compileall", "-q", "-j", "0", *COMPILEALL_SOURCE_DIRS), cwd=server_cwd, check=False, # missing pyc is non-fatal — runtime regenerates as needed )-O: runtimes never launch python with-O, so plain.pycis the only bytecode flavor that gets loaded (PEP 488). The list of source dirs is the publiccli.commands.build.COMPILEALL_SOURCE_DIRSconstant —scripts/install.jsmirrors it.
The tarball still excludes __pycache__/ per package.json files (cross-Python-minor pyc fragility) — compileall runs on the user's machine via company build or scripts/install.js (run by company provision: eagerly from the installer scripts, or on the first company command of a bun add -g install, which runs no lifecycle scripts).
4a-bis. .env scaffolding with fresh secrets (step [0/6])
- When no
.envexists,company buildstep[0/6]scaffolds it from.env.templateand replaces the dev placeholder values ofSECRET_KEY/JWT_SECRET_KEY/API_KEY_ENCRYPTION_KEYwith freshsecrets.token_hex(24)values (_scaffold_env_secretsincli/commands/build.py). An existing.envis never modified. The placeholder literals themselves are the SSOT frozensetDEV_SECRET_LITERALSinserver/core/config.py; server startup logs a non-fatal error banner viadev_secret_offenders()when placeholders are detected with auth enabled orDEPLOYMENT_MODE != local.
4b. Temporal binary fetch + DATA_DIR parity
- Step
[6/6]runsuv run python -m services.temporal._install, which pooch-downloads thetemporalCLI release pinned inserver/config/temporal_cli.json(checked against its SHA-256) into<DATA_DIR>/packages/temporal/<version>/(=~/.opencompany/packages/temporal/<version>/by default) and deletes any other CLI there. Pre-fetching at build time turns the download into a sub-second cache hit on firstcompany start. The download uses an explicitHTTPDownloader(timeout=300)(per-socket-read timeout — slow links can finish; pooch's 30 s default aborted them). Fatality differs by entry point:company buildkeeps the step fatal (locked bytest_temporal_install_is_fatal_on_failure), while the provisioning script (scripts/install.js, run bycompany provision) wraps it in a non-fatal try/catch becauseTemporalServerRuntime._pre_spawn()re-downloads lazily on firstcompany start. The cache survivescompany clean(packages∈_OPENCOMPANY_KEEP), so clean+build cycles don't re-download. company buildlayers.env.devfirst.build_command()callscli.config.load_dev_overrides(root)before the install steps, so the build'sDATA_DIRmatches what the runtime sees. Without it, a repo checkout'scompany buildreadDATA_DIR=~/.opencompanyfrom.env.templateand installed Temporal under user home, butcompany devthen readDATA_DIR=.opencompanyfrom.env.devand re-downloaded into<repo>/.opencompany/— a redundant ~114 MB fetch on every fresh clone.- Safe for global installs.
.env.devis git-committed for contributors but is NOT in thefileslist, so an installed (bun add -g) copy has no.env.dev—load_dev_overridesis a no-op and everything falls through to the.env.templatedefault (DATA_DIR=~/.opencompany), matchingcompany start/company daemon.
5. Wire compileall into install.js (the sidecar bundle is meant to ship pre-built)
scripts/install.js→ afteruv sync:uv run python -m compileall -q -j 0 <COMPILEALL_SOURCE_DIRS>— same shape as build.py (no-O; locked in sync bycli/tests/test_release_pipeline_config.py)
- The sidecar is not rebuilt at install time:
company buildstep[3/6]runsbun run --filter opencompany-nodejs-executor buildbeforebun pm pack/bun publish, andserver/nodejs/dist/index.jswas meant to ride inside the tarball under theserver/entry in the rootfileslist. It does not:bun pm packhonours the nestedserver/nodejs/.gitignore, which listsdist/, so 0.2.0 and 0.2.1 ship without the bundle (errors.md #26);company buildin the installed package rebuilds it. Likewise the client is only built by install.js whenclient/dist/index.htmlis missing.
Idempotent on re-runs (compileall only rewrites stale pyc; bun build is deterministic).
6. Tarball verification
bun pm pack --dry-runafter the change. Confirmserver/nodejs/dist/index.jsis included; today it is not (errors.md #26). Confirm no__pycache__/leakage.server/uv.lockis committed (since the desktop app) and ships in the tarball;.npmignoreonly hidespackage-lock.json(a legacy artefact — the tree isbun.lock-only). The desktop stage script also reads thebun pm pack --dry-runfile list as its layout source of truth, so a change to the rootfilesallowlist reaches the desktop bundle automatically.
Critical files
| File | Action |
|---|---|
root package.json |
+ typescript@7 devDep (exact-pinned), + root typecheck script |
client/package.json |
typecheck delegates to the root gate; keeps typescript@^5.x for typescript-eslint |
client/vite.config.js |
+ manualChunks, target, lower warning |
server/nodejs/package.json |
bun build --target=bun build script, bun dist/index.js start, bun --watch dev, engines.bun (no esbuild / tsx deps) |
server/nodejs/.gitignore |
new — ignore dist/ (this nested rule is what drops the bundle from bun pm pack: errors.md #26) |
cli/commands/build.py |
+ compileall step ([5/6], plain .pyc — no -O), COMPILEALL_SOURCE_DIRS constant |
scripts/install.js |
+ compileall call (expects the sidecar bundle pre-built in the tarball, which 0.2.x lacks: errors.md #26) |
server/pyproject.toml |
[tool.uv] compile-bytecode = true — uv sync compiles .venv/ site-packages |
.github/workflows/predeploy.yml |
+ typecheck gate in build-and-lint; + tsc --version in the cross-OS matrix |
Verification
bun run --filter react-flow-client typecheck→ <5s, zero errors.ANALYZE=1 bun run --filter react-flow-client build→ openclient/dist/stats.html. Expect: no chunk trips the 850 KBchunkSizeWarningLimit(vendor-iconsis the ~830 KB outlier it is sized for), main < 200 KB gz,vendor-flowsplit.cd server/nodejs && bun run build && NODEJS_EXECUTOR_PORT=<port> bun dist/index.js→ starts onNODEJS_EXECUTOR_PORT(required env; no fallback literal) in <100ms;GET /healthreportsruntime: "bun".cd server && uv run python -m compileall -q -j 0 services→ plain__pycache__/*.pycpresent (no.opt-1.pyc— nothing loads those).- Cold-start: clean install +
company start > start.log 2>&1→Application startup completeat ≤+50s (was +66.9s). bun pm pack --dry-run→server/nodejs/dist/index.jsshould be included (0.2.x omits it: errors.md #26); no__pycache__/; tarball size ≤ v0.0.76.- Smoke:
company start→ load the app URL (http://localhost:${PYTHON_BACKEND_PORT}) → run "AI Assistant" example → agent responds.
Desktop installers
The Electron shell has its own pipeline (.github/workflows/desktop-release.yml) that consumes this one's outputs (client/dist, the sidecar bundle) and adds the bundled runtimes; it is documented in desktop_app.md. Nuitka / PyOxidizer freezing was evaluated and rejected there: temporalio's PyO3 bridge, dependency-injector wiring by string, pkgutil.walk_packages plugin discovery and the Browser node's uv tool install of the browser-use CLI at runtime all need a real interpreter on disk.
Out of scope (future work)
- Nuitka / PyOxidizer standalone binaries — rejected for the desktop app (see above); a separate release channel for the CLI would face the same constraints.
- Plugin walker lazy-loading (~11s).
- Service-status refresh parallelisation (~20s post-startup-complete).
- mypyc / Cython for hot paths (low ROI — pydantic V2 already Rust, httpx/aiohttp already C).
- swc / stc TypeScript checker (not production-grade in 2026).