1- import { execFileSync } from "node:child_process" ;
1+ import { execFile , execFileSync } from "node:child_process" ;
22import fs from "node:fs" ;
3+ import { promisify } from "node:util" ;
34
45/** @typedef {import("node:child_process").ExecFileSyncOptions } ExecFileSyncOptions */
56/** @typedef {import("node:child_process").ExecFileSyncOptionsWithBufferEncoding } ExecFileSyncOptionsWithBufferEncoding */
@@ -13,6 +14,7 @@ import fs from "node:fs";
1314 */
1415
1516const PLAIN_GH_MAX_BUFFER_BYTES = 32 * 1024 * 1024 ;
17+ const execFileAsync = promisify ( execFile ) ;
1618
1719/**
1820 * @param {string } filePath
@@ -167,15 +169,35 @@ export function execPlainGh(args, options = {}) {
167169 * @returns {string | Uint8Array<ArrayBuffer> }
168170 */
169171export function execGhRead ( args , options = { } , params = { } ) {
170- const env = plainGhEnv ( options . env ?? process . env ) ;
171- // Cache-aware reads stay on PATH even when another caller selects an explicit binary.
172- delete env . OPENCLAW_GH_BIN ;
173172 const execFileSyncImpl = params . execFileSyncImpl ?? execFileSync ;
174173 return execFileSyncImpl ( "gh" , args , {
175174 ...options ,
176- env,
175+ env : ghReadEnv ( options . env ) ,
176+ maxBuffer : options . maxBuffer ?? PLAIN_GH_MAX_BUFFER_BYTES ,
177+ } ) ;
178+ }
179+
180+ /** @param {NodeJS.ProcessEnv } [env] */
181+ function ghReadEnv ( env ) {
182+ const next = plainGhEnv ( env ) ;
183+ // Cache-aware reads stay on PATH even when another caller selects an explicit binary.
184+ delete next . OPENCLAW_GH_BIN ;
185+ return next ;
186+ }
187+
188+ /**
189+ * @param {readonly string[] } args
190+ * @param {import("node:child_process").ExecFileOptions } [options]
191+ * @returns {Promise<string> }
192+ */
193+ export async function execGhReadAsync ( args , options = { } ) {
194+ const { stdout } = await execFileAsync ( "gh" , args , {
195+ ...options ,
196+ encoding : "utf8" ,
197+ env : ghReadEnv ( options . env ) ,
177198 maxBuffer : options . maxBuffer ?? PLAIN_GH_MAX_BUFFER_BYTES ,
178199 } ) ;
200+ return stdout ;
179201}
180202
181203/**
0 commit comments