Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(cli): bundle session-runner as separate entry point for npm builds

Gener3ae91f816172
diff --git a/src/cli/daemon/daemon.test.ts b/src/cli/daemon/daemon.test.ts
index f888e070c..0ef0c4258 100644
--- a/src/cli/daemon/daemon.test.ts
+++ b/src/cli/daemon/daemon.test.ts
@@ -86,6 +86,10 @@ vi.mock("child_process", () => {
};
});
+vi.mock("fs", () => ({
+ existsSync: vi.fn((p: string) => p.endsWith("session-runner.js")),
+}));
+
vi.mock("url", () => ({
fileURLToPath: vi.fn(() => "/fake/daemon.ts"),
}));
@@ -150,9 +154,9 @@ import { startDaemon, spawnSessionRunner } from "./daemon.js";
const mockReleaseDaemonPid = vi.mocked(releaseDaemonPid);
function decodeSpawnInput(call: any[]): any {
- // spawn('bun', ['run', path, encodedInput], opts)
+ // spawn(process.execPath, [sessionRunnerPath, encodedInput], opts)
const args = call[1] as string[];
- const encoded = args[2];
+ const encoded = args[1];
return JSON.parse(Buffer.from(encoded, "base64").toString("utf-8"));
}
@@ -211,9 +215,8 @@ describe("daemon session runner dispatch", () => {
expect(spawn).toHaveBeenCalledTimes(1);
const call = vi.mocked(spawn).mock.calls[0];
- expect(call[0]).toBe("bun");
- expect((call[1] as string[])[0]).toBe("run");
- expect((call[1] as string[])[1]).toContain("session-runner.ts");
+ expect(call[0]).toBe(process.execPath);
+ expect((call[1] as string[])[0]).toContain("session-runner.js");
});
it("passes correct SessionRunnerInput to session runner", async () => {
@@ -795,14 +798,13 @@ describe("spawnSessionRunner", () => {
expect(spawn).toHaveBeenCalledTimes(1);
const call = vi.mocked(spawn).mock.calls[0];
- expect(call[0]).toBe("bun");
+ expect(call[0]).toBe(process.execPath);
const args = call[1] as string[];
- expect(args[0]).toBe("run");
- expect(args[1]).toContain("session-runner.ts");
+ expect(args[0]).toContain("session-runner.js");
// Decode and verify
- const decoded = JSON.parse(Buffer.from(args[2], "base64").toString("utf-8"));
+ const decoded = JSON.parse(Buffer.from(args[1], "base64").toString("utf-8"));
expect(decoded.task.id).toBe("t1");
expect(decoded.provider).toBe("claude");
expect(decoded.token).toBe("test_token");
diff --git a/src/cli/daemon/daemon.ts b/src/cli/daemon/daemon.ts
index 5125aa69a..0b07cdbcc 100644
--- a/src/cli/daemon/daemon.ts
+++ b/src/cli/daemon/daemon.ts
@@ -7,10 +7,16 @@ import { loadCLIConfigForProfile, saveCLIConfigForProfile } from "../lib/config.
import { log } from "../lib/logger.js";
import { cmdPrefix } from "../lib/env.js";
import { acquireDaemonPid, releaseDaemonPid } from "./pidfile.js";
+import { existsSync } from "fs";
import { execSync, spawn, type ChildProcess } from "child_process";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
+const _dir = dirname(fileURLToPath(import.meta.url));
+const sessionRunnerPath = existsSync(join(_dir, "session-runner.js"))
+ ? join(_dir, "session-runner.js")
+ : join(_dir, "session-runner.ts");
+
interface WorkspaceState {
workspaceId: string;
token: string;
@@ -243,14 +249,9 @@ export async function startDaemon(
await pollCycle();
}
-const SESSION_RUNNER_PATH = join(
- dirname(fileURLToPath(import.meta.url)),
- "session-runner.ts",
-);
-
export function spawnSessionRunner(input: SessionRunnerInput): ChildProcess {
const encoded = Buffer.from(JSON.stringify(input)).toString("base64");
- const child = spawn("bun", ["run", SESSION_RUNNER_PATH, encoded], {
+ const child = spawn(process.execPath, [sessionRunnerPath, encoded], {
detached: true,
stdio: "ignore",
});
diff --git a/src/cli/package.json b/src/cli/package.json
index 1e5f45705..6b560bf43 100644
--- a/src/cli/package.json
+++ b/src/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@alook/cli",
- "version": "0.0.4",
+ "version": "0.0.5",
"description": "Alook CLI — register and run always-on AI coding agents.",
"license": "Apache-2.0",
"homepage": "https://github.com/alookai/alook#readme",
@@ -38,7 +38,7 @@
},
"scripts": {
"dev": "bun run src/index.ts",
- "build": "bun build src/index.ts --outdir dist --target node --format esm --external citty --external commander --external postal-mime && node scripts/prepare-dist.mjs",
+ "build": "bun build src/index.ts --outdir dist --target node --format esm --external citty --external commander --external postal-mime && bun build daemon/session-runner.ts --outdir dist --target node --format esm --external citty --external commander --external postal-mime && node scripts/prepare-dist.mjs",
"prepack": "pnpm run build",
"test": "vitest run",
"typecheck": "tsc --noEmit"