framework
Version:
The (AI) Framework: turnkey, zero-config AI orchestration that wraps a coding-agent CLI (Claude Code) as a black box and takes you from an idea to a running app. Vite for AI.
30 lines • 1.54 kB
JavaScript
import { exec as cpExec } from 'node:child_process';
import { isAbsolute, join } from 'node:path';
/**
* A {@link DeployExecutor} that runs shell commands on the host, in the
* workspace the wrapped agent built (its `cwd`). This is what lets a real deploy
* target (e.g. `cloudflareTarget`) install / build / run `wrangler` against the
* code Claude Code just wrote, since the runner seam's `LocalRunner` cannot: it
* mkdtemps a fresh workspace and deletes it on dispose.
*
* Never rejects: a non-zero exit or a spawn error resolves to an {@link ExecResult}
* with the exit code and captured output, matching the runner-session contract
* the deploy targets expect.
*/
export function hostExecutor(cwd, opts = {}) {
const baseEnv = opts.env ?? process.env;
const maxBuffer = opts.maxBuffer ?? 16 * 1024 * 1024;
return {
exec(command, execOpts = {}) {
const dir = execOpts.cwd ? (isAbsolute(execOpts.cwd) ? execOpts.cwd : join(cwd, execOpts.cwd)) : cwd;
const env = execOpts.env ? { ...baseEnv, ...execOpts.env } : baseEnv;
return new Promise(resolvePromise => {
cpExec(command, { cwd: dir, env, timeout: execOpts.timeoutMs ?? 0, maxBuffer }, (err, stdout, stderr) => {
const exitCode = err ? (typeof err.code === 'number' ? err.code : 1) : 0;
resolvePromise({ stdout: String(stdout), stderr: String(stderr), exitCode });
});
});
},
};
}
//# sourceMappingURL=host-exec.js.map