refactor: replace gitExec with spawnCli from workflow-util-agent

Remove hand-rolled execFile + promisify, delegate to spawnCli.
Same throw-on-error interface, better error messages.
This commit is contained in:
2026-05-06 09:51:06 +00:00
parent e38852a761
commit c15a5554c0
4 changed files with 22 additions and 22 deletions
@@ -10,6 +10,7 @@
},
"dependencies": {
"@uncaged/workflow": "workspace:*",
"@uncaged/workflow-util-agent": "workspace:*",
"@uncaged/workflow-util-role": "workspace:*",
"zod": "^4.0.0"
},
@@ -1,26 +1,20 @@
import { execFile } from "node:child_process";
import { promisify } from "node:util";
const execFileAsync = promisify(execFile);
import { spawnCli } from "@uncaged/workflow-util-agent";
/** Runs `git` with args in `cwd`; throws if git exits non-zero. */
export async function gitExec(cwd: string, args: readonly string[]): Promise<string> {
try {
const r = await execFileAsync("git", [...args], {
cwd,
encoding: "utf8",
maxBuffer: 10 * 1024 * 1024,
});
return r.stdout;
} catch (e) {
const stderr =
typeof e === "object" &&
e !== null &&
"stderr" in e &&
typeof (e as { stderr: unknown }).stderr === "string"
? (e as { stderr: string }).stderr
: "";
const msg = e instanceof Error ? e.message : String(e);
throw new Error(`git ${args.join(" ")} failed: ${msg}${stderr ? ` (${stderr.trim()})` : ""}`);
const result = await spawnCli("git", [...args], { cwd, timeoutMs: null });
if (result.ok) {
return result.value;
}
const error = result.error;
switch (error.kind) {
case "non_zero_exit":
throw new Error(
`git ${args.join(" ")} failed (exit ${error.exitCode}): ${error.stderr.trim() || error.stdout.trim()}`,
);
case "timeout":
throw new Error(`git ${args.join(" ")} timed out`);
case "spawn_failed":
throw new Error(`git ${args.join(" ")} spawn failed: ${error.message}`);
}
}
@@ -7,5 +7,9 @@
"types": ["bun-types"]
},
"include": ["src/**/*.ts"],
"references": [{ "path": "../workflow" }, { "path": "../workflow-util-role" }]
"references": [
{ "path": "../workflow" },
{ "path": "../workflow-util-agent" },
{ "path": "../workflow-util-role" }
]
}
@@ -21,6 +21,7 @@ type AcornNode = Node & { [key: string]: unknown };
function narrowNode<T extends Node>(node: Node): T {
return node as unknown as T;
}
import * as acorn from "acorn";
import { err, ok, type Result } from "./result.js";