MCPcopy Create free account
hub / github.com/tiann/hapi / getHappyCliCommand

Function getHappyCliCommand

cli/src/utils/spawnHappyCLI.ts:95–134  ·  view source on GitHub ↗
(args: string[])

Source from the content-addressed store, hash-verified

93}
94
95export function getHappyCliCommand(args: string[]): HappyCliCommand {
96 // Compiled binary mode: just use the executable directly
97 if (isBunCompiled()) {
98 return {
99 command: resolveHappyCliExecutable(),
100 args
101 };
102 }
103
104 // Development mode: spawn with TypeScript entrypoint
105 const projectRoot = projectPath();
106 const entrypoint = resolveEntrypoint(projectRoot);
107 const isBunRuntime = Boolean((process.versions as Record<string, string | undefined>).bun);
108
109 if (isBunRuntime) {
110 // Bun can run TypeScript directly.
111 // Force Bun's cwd to the CLI project root so alias resolution via bunfig.toml
112 // keeps working even when external tools launch HAPI from another workspace.
113 return {
114 command: process.execPath,
115 args: ['--cwd', projectRoot, entrypoint, ...args]
116 };
117 }
118
119 // When vitest runs under Node.js, HAPI_BUN_EXEC can point to the bun binary so that
120 // spawned CLI child processes still run under bun (which is required for TypeScript entrypoints).
121 const bunExecOverride = process.env['HAPI_BUN_EXEC']?.trim();
122 if (bunExecOverride && isCrossPlatformAbsolutePath(bunExecOverride) && existsSync(bunExecOverride)) {
123 return {
124 command: bunExecOverride,
125 args: ['--cwd', projectRoot, entrypoint, ...args]
126 };
127 }
128
129 // Node.js fallback: preserve execArgv (for compatibility)
130 return {
131 command: process.execPath,
132 args: [...process.execArgv, entrypoint, ...args]
133 };
134}
135
136export function spawnHappyCLI(args: string[], options: SpawnOptions = {}): ChildProcess {
137

Callers 6

generateHookSettingsFileFunction · 0.90
buildHapiMcpBridgeFunction · 0.90
runAgentSessionFunction · 0.90
spawnHappyCLIFunction · 0.85

Calls 5

isBunCompiledFunction · 0.90
projectPathFunction · 0.90
resolveEntrypointFunction · 0.85

Tested by

no test coverage detected