xonecas.io
64875
Mc

mini-coder / commit c1d12fb

fix: resolve subagent runner command for js installs

xonecas2026-03-11 c1d12fb4a7076cf03597a9f718996e84fe8134fa parent 7998d3f

2 files changed

src/agent/subagent-runner.test.ts+28−0
@@ -0,0 +1,28 @@
1+import { describe, expect, test } from "bun:test";
2+import { resolveMcCommand } from "./subagent-runner.ts";
3+
4+describe("resolveMcCommand", () => {
5+ test("uses Bun.main for TypeScript entrypoints", () => {
6+ expect(
7+ resolveMcCommand("/usr/bin/bun", "/repo/src/index.ts", undefined),
8+ ).toEqual(["/usr/bin/bun", "/repo/src/index.ts"]);
9+ });
10+
11+ test("uses Bun.main for installed JavaScript entrypoints", () => {
12+ expect(
13+ resolveMcCommand("/usr/bin/bun", "/repo/dist/mc.js", undefined),
14+ ).toEqual(["/usr/bin/bun", "/repo/dist/mc.js"]);
15+ });
16+
17+ test("falls back to argv[1] when Bun.main is eval", () => {
18+ expect(
19+ resolveMcCommand("/usr/bin/bun", "/repo/[eval]", "/repo/src/index.ts"),
20+ ).toEqual(["/usr/bin/bun", "/repo/src/index.ts"]);
21+ });
22+
23+ test("returns bare execPath when no script entrypoint exists", () => {
24+ expect(resolveMcCommand("/repo/mc", undefined, "--help")).toEqual([
25+ "/repo/mc",
26+ ]);
27+ });
28+});
src/agent/subagent-runner.ts+20−7
@@ -7,15 +7,28 @@ import {
77
88 /**
99 * Resolve the command to invoke a new `mc` subprocess.
10- * - Dev: process.argv[1] ends with ".ts" → [bun, script]
11- * - Prod: compiled binary → [process.execPath]
10+ * - Dev / installed JS: Bun runs a script entrypoint → [bun, script]
11+ * - Compiled binary: no script entrypoint is available → [process.execPath]
1212 */
13-function getMcCommand(): string[] {
14- const script = process.argv[1];
15- if (script?.endsWith(".ts")) {
16- return [process.execPath, script];
13+export function resolveMcCommand(
14+ execPath: string,
15+ mainModule: string | undefined,
16+ argv1: string | undefined,
17+): string[] {
18+ const script =
19+ mainModule &&
20+ !mainModule.endsWith("/[eval]") &&
21+ !mainModule.endsWith("\\[eval]")
22+ ? mainModule
23+ : argv1;
24+ if (script && /\.(?:[cm]?[jt]s)$/.test(script)) {
25+ return [execPath, script];
1726 }
18- return [process.execPath];
27+ return [execPath];
28+}
29+
30+function getMcCommand(): string[] {
31+ return resolveMcCommand(process.execPath, Bun.main, process.argv[1]);
1932 }
2033
2134 // Loose recursion cap passed via environment so subprocess chains are bounded