feat(M3): Direct Execution
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user