feat(M3): Direct Execution

This commit is contained in:
2026-05-18 18:11:45 -05:00
parent fe94629797
commit a2cfa7027e
2 changed files with 29 additions and 7 deletions
+13 -3
View File
@@ -1,4 +1,6 @@
import type { ChildProcess } from "node:child_process";
import { spawn as defaultSpawn } from "node:child_process";
import type { PathLike } from "node:fs";
import { existsSync as defaultExistsSync } from "node:fs";
import type { ClientName, ExecResult } from "./types.js";
import { ClientNotFoundError, ExecError } from "./types.js";
@@ -12,8 +14,8 @@ const CLIENT_ARGS: Record<ClientName, (prompt: string) => string[]> = {
export interface ExecuteOptions {
clientPath?: string;
timeoutMs?: number;
spawn?: typeof defaultSpawn;
existsSync?: typeof defaultExistsSync;
spawn?: (command: string, args: string[], options?: { shell?: boolean }) => ChildProcess;
existsSync?: (path: PathLike) => boolean;
}
export async function executePrompt(
@@ -38,7 +40,15 @@ export async function executePrompt(
throw new ClientNotFoundError(client);
}
const args = CLIENT_ARGS[client](prompt);
const argBuilder = (CLIENT_ARGS as Record<string, (prompt: string) => string[]>)[client];
if (!argBuilder) {
throw new ExecError(`Unknown client: ${client}`, {
stdout: "",
stderr: "",
exitCode: -1,
});
}
const args = argBuilder(prompt);
return new Promise((resolve, reject) => {
let settled = false;