diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index e365609..6fb03f4 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -248,6 +248,8 @@ async function runInitWorkspace(force: boolean): Promise { if (!existsSync(join(nerveRoot, ".git"))) { try { await runCommand("git", ["init"], nerveRoot); + await runCommand("git", ["add", "."], nerveRoot); + await runCommand("git", ["commit", "-m", "Initial nerve workspace"], nerveRoot); } catch { process.stdout.write("⚠️ git init failed — skipping.\n"); } diff --git a/packages/cli/src/commands/start.ts b/packages/cli/src/commands/start.ts index b2e8ee3..2df8ef5 100644 --- a/packages/cli/src/commands/start.ts +++ b/packages/cli/src/commands/start.ts @@ -1,7 +1,6 @@ -import { createWriteStream } from "node:fs"; -import { readFileSync } from "node:fs"; +import { createWriteStream, existsSync, readFileSync } from "node:fs"; import { mkdir } from "node:fs/promises"; -import { join } from "node:path"; +import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { parseNerveConfig } from "@uncaged/nerve-core"; @@ -85,6 +84,23 @@ async function runForeground(nerveRoot: string): Promise { await kernel.ready; } +/** Path to the CLI entry script (for spawning `start` without `-d`). */ +function cliEntryScript(): string { + const here = fileURLToPath(import.meta.url); + const ext = here.endsWith(".ts") ? ".ts" : ".js"; + // When bundled, `here` is already the CLI entry (e.g. dist/cli.js). + // When running from source, `here` is src/commands/start.ts → go up to src/cli.ts. + const candidates = [ + join(dirname(here), `cli${ext}`), // bundled: dist/cli.js + join(dirname(here), "..", `cli${ext}`), // source: src/commands/start.ts → src/cli.ts + ]; + const cliPath = candidates.find((p) => existsSync(p)); + if (!cliPath) { + throw new Error(`CLI entry not found (searched: ${candidates.join(", ")})`); + } + return cliPath; +} + async function runDaemon(nerveRoot: string): Promise { if (isRunning()) { const pid = readPidFile(); @@ -108,9 +124,9 @@ async function runDaemon(nerveRoot: string): Promise { else resolve(); }); - const selfPath = fileURLToPath(import.meta.url); + const cliPath = cliEntryScript(); - const child = spawn(process.execPath, [selfPath, "start"], { + const child = spawn(process.execPath, [cliPath, "start"], { detached: true, stdio: ["ignore", logStream.fd, logStream.fd], env: { ...process.env, NERVE_DAEMON_MODE: "1" },