From 9a974bea1f5096c20f8b4912be40e4c9972076f8 Mon Sep 17 00:00:00 2001 From: NiveditJain Date: Wed, 8 Apr 2026 06:51:44 +0000 Subject: [PATCH] [ef-46] fix: bundle CLI for Node.js compatibility, support npm install -g The CLI entry point used #!/usr/bin/env bun shebang and imported TypeScript files directly, making it incompatible with npm install -g on systems without bun. Bundle the CLI into dist/cli.mjs via bun build with #!/usr/bin/env node shebang so it works with both node and bun runtimes. - Add build:cli script that bundles bin/failproofai.mjs into dist/cli.mjs - Change bin entry from bin/failproofai.mjs to dist/cli.mjs - Bump version to 0.0.2-beta.1 - Fix error message: "server binary" -> "server.js" - Add postinstall validation: fail install if server.js is missing - Update docs to show both npm and bun install commands - Mark Bun as optional (only needed for development) Co-Authored-By: Claude Opus 4.6 --- README.md | 4 +++- docs/getting-started.md | 4 +++- docs/introduction.md | 4 +++- docs/package-aliases.md | 2 ++ package.json | 11 ++++++----- scripts/launch.ts | 2 +- scripts/postinstall.mjs | 11 +++++++++++ 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b86b4753..d2e7fe38 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Everything runs locally — no data leaves your machine. ## Requirements - Node.js >= 20.9.0 -- Bun >= 1.3.0 +- Bun >= 1.3.0 (optional — only needed for development / building from source) --- @@ -37,6 +37,8 @@ Everything runs locally — no data leaves your machine. ```bash npm install -g failproofai +# or +bun add -g failproofai ``` --- diff --git a/docs/getting-started.md b/docs/getting-started.md index 77329f93..3d0b7b33 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -7,7 +7,7 @@ icon: rocket ## Requirements - **Node.js** >= 20.9.0 -- **Bun** >= 1.3.0 (used as the runtime and bundler) +- **Bun** >= 1.3.0 (optional — only needed for development / building from source) --- @@ -15,6 +15,8 @@ icon: rocket ```bash npm install -g failproofai +# or +bun add -g failproofai ``` --- diff --git a/docs/introduction.md b/docs/introduction.md index 6eccfe4c..6e93bc32 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -24,10 +24,12 @@ It also includes a local web dashboard for browsing Claude Code sessions, inspec ## Quick start -Install globally via npm: +Install globally: ```bash npm install -g failproofai +# or +bun add -g failproofai ``` Enable policies: diff --git a/docs/package-aliases.md b/docs/package-aliases.md index f3bd3043..a2700fb7 100644 --- a/docs/package-aliases.md +++ b/docs/package-aliases.md @@ -10,6 +10,8 @@ The canonical npm package is **`failproofai`**: ```bash npm install -g failproofai +# or +bun add -g failproofai ``` --- diff --git a/package.json b/package.json index 266e82ce..13d405ee 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "failproofai", - "version": "0.0.1", + "version": "0.0.2-beta.1", "description": "Open-source hooks, policies, and project visualization for Claude Code & Agents SDK", "bin": { - "failproofai": "./bin/failproofai.mjs" + "failproofai": "./dist/cli.mjs" }, "files": [ "bin/", @@ -19,10 +19,11 @@ "bun": ">=1.3.0" }, "scripts": { - "predev": "bun link", + "predev": "bun run build:cli && bun link", "dev": "FAILPROOFAI_TELEMETRY_DISABLED=1 bun scripts/dev.ts --port 8020", - "build": "bun build --target=node --format=cjs --outfile=dist/index.js src/index.ts && bun --bun next build && node -e \"const {cpSync}=require('fs');cpSync('.next/static','.next/standalone/.next/static',{recursive:true});\"", - "prestart": "bun link", + "build:cli": "bun build --target=node --format=esm --outfile=dist/cli.mjs bin/failproofai.mjs --external posthog-node && node -e \"const fs=require('fs');const c=fs.readFileSync('dist/cli.mjs','utf8');fs.writeFileSync('dist/cli.mjs',c.replace('#!/usr/bin/env bun','#!/usr/bin/env node').replace('// @bun\\n',''))\"", + "build": "bun build --target=node --format=cjs --outfile=dist/index.js src/index.ts && bun run build:cli && bun --bun next build && node -e \"const {cpSync}=require('fs');cpSync('.next/static','.next/standalone/.next/static',{recursive:true});\"", + "prestart": "bun run build:cli && bun link", "start": "FAILPROOFAI_TELEMETRY_DISABLED=1 bun scripts/start.ts", "test": "vitest", "test:run": "vitest run", diff --git a/scripts/launch.ts b/scripts/launch.ts index c0ba5dea..d7da6140 100644 --- a/scripts/launch.ts +++ b/scripts/launch.ts @@ -49,7 +49,7 @@ export function launch(mode: "dev" | "start"): void { const serverJsPath = resolve(packageRoot, ".next/standalone/server.js"); if (!existsSync(serverJsPath)) { console.error( - `\nError: Cannot find server binary at:\n ${serverJsPath}\n\n` + + `\nError: Cannot find server.js at:\n ${serverJsPath}\n\n` + `The package may be missing its build output.\n` + `Try reinstalling:\n npm install -g failproofai@latest\n` ); diff --git a/scripts/postinstall.mjs b/scripts/postinstall.mjs index e1344318..86e8208f 100644 --- a/scripts/postinstall.mjs +++ b/scripts/postinstall.mjs @@ -18,6 +18,17 @@ import { trackInstallEvent } from "./install-telemetry.mjs"; // from process.cwd() only when we are being installed as a dependency by someone else. if (!process.env.INIT_CWD || process.env.INIT_CWD === process.cwd()) process.exit(0); +// Verify server.js exists — fail the install early if the dashboard build is missing. +const serverJsPath = resolve(process.cwd(), ".next", "standalone", "server.js"); +if (!existsSync(serverJsPath)) { + console.error( + `\n[failproofai] Error: server.js not found at:\n ${serverJsPath}\n\n` + + ` The package may not have been built correctly.\n` + + ` Try reinstalling: npm install -g failproofai@latest\n` + ); + process.exit(1); +} + const FAILPROOFAI_HOOK_MARKER = "__failproofai_hook__"; const NAMESPACE = "failproofai-telemetry-v1";