diff --git a/packages/workflow-role-committer/package.json b/packages/workflow-role-committer/package.json index ed1b50f..05bcee2 100644 --- a/packages/workflow-role-committer/package.json +++ b/packages/workflow-role-committer/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@uncaged/workflow": "workspace:*", + "@uncaged/workflow-util-agent": "workspace:*", "@uncaged/workflow-util-role": "workspace:*", "zod": "^4.0.0" }, diff --git a/packages/workflow-role-committer/src/git-exec.ts b/packages/workflow-role-committer/src/git-exec.ts index 9fcb68c..3aeb525 100644 --- a/packages/workflow-role-committer/src/git-exec.ts +++ b/packages/workflow-role-committer/src/git-exec.ts @@ -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 { - 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}`); } } diff --git a/packages/workflow-role-committer/tsconfig.json b/packages/workflow-role-committer/tsconfig.json index 87698d3..b88bcaf 100644 --- a/packages/workflow-role-committer/tsconfig.json +++ b/packages/workflow-role-committer/tsconfig.json @@ -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" } + ] } diff --git a/packages/workflow/src/bundle-validator.ts b/packages/workflow/src/bundle-validator.ts index b833e6f..4312a23 100644 --- a/packages/workflow/src/bundle-validator.ts +++ b/packages/workflow/src/bundle-validator.ts @@ -21,6 +21,7 @@ type AcornNode = Node & { [key: string]: unknown }; function narrowNode(node: Node): T { return node as unknown as T; } + import * as acorn from "acorn"; import { err, ok, type Result } from "./result.js";