Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bin/failproofai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@
* --list-policies List available policies and their status
* (default) Launch production dashboard
*/
import { realpathSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { version } from "../package.json";

// Resolve the real package root early (following any npm bin symlinks) so that
// scripts/launch.ts can locate .next/standalone/server.js correctly regardless
// of how bun resolves import.meta.url for dynamically-imported modules.
if (!process.env.FAILPROOFAI_PACKAGE_ROOT) {
process.env.FAILPROOFAI_PACKAGE_ROOT = resolve(
dirname(realpathSync(fileURLToPath(import.meta.url))),
".."
);
}

const args = process.argv.slice(2);

// --version / -v
Expand Down
8 changes: 6 additions & 2 deletions scripts/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { getDefaultClaudeProjectsPath } from "../lib/paths";
import { spawn } from "child_process";
import { realpathSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { parseScriptArgs } from "./parse-script-args";
Expand Down Expand Up @@ -39,8 +40,11 @@ export function launch(mode: "dev" | "start"): void {
process.env.PORT = port;
process.env.HOSTNAME = "0.0.0.0";
cmd = "node";
// Absolute path — required so the CLI works from any working directory after install
cmdArgs = [resolve(dirname(fileURLToPath(import.meta.url)), "../.next/standalone/server.js")];
// Resolve the real package root via realpathSync so symlinked npm global binaries
// don't cause import.meta.url to point at the symlink dir instead of the package dir.
const packageRoot = process.env.FAILPROOFAI_PACKAGE_ROOT
?? resolve(dirname(realpathSync(fileURLToPath(import.meta.url))), "..");
cmdArgs = [resolve(packageRoot, ".next/standalone/server.js")];
} else {
cmd = "bunx";
cmdArgs = ["--bun", "next", "dev", ...remainingArgs];
Expand Down