style(desktop): format no-console-git and pad new spawn statements

This commit is contained in:
Hermes Agent
2026-09-24 19:33:21 -05:00
committed by brooklyn!
parent 4fd73cc0f3
commit d7f06c964b
5 changed files with 43 additions and 13 deletions

View File

@@ -273,6 +273,7 @@ function runGit(gitBin: string, args: string[], cwd?: string): Promise<{ code: n
env: noninteractiveGitEnv(),
stdio: ['ignore', 'ignore', 'pipe']
})
const child = spawn(spec.command, spec.args, spec.options)
let stderr = ''

View File

@@ -59,6 +59,7 @@ function gitFor(cwd, gitBin) {
const binary = simpleGitBinary(gitBin, host)
const binaryParts = Array.isArray(binary) ? binary : [binary]
const unsafe = binaryParts.some(part => /\s/.test(part)) || Boolean(gitBin && /\s/.test(gitBin))
const git = simpleGit({
baseDir: cwd,
binary,

View File

@@ -3108,6 +3108,7 @@ function runGit(args, options: any = {}): Promise<{ code: number; stdout: string
const gitBinary = resolveGitBinary()
const gitArgs = IS_WINDOWS ? ['-c', 'windows.appendAtomically=false', ...args] : args
const host = IS_WINDOWS ? windowsGitHost(true) : null
const plan = planNoConsoleGitSpawn({
gitBin: gitBinary,
args: gitArgs,

View File

@@ -124,6 +124,7 @@ test('host script forwards git argv unchanged and sets CREATE_NO_WINDOW', () =>
HERMES_GIT_NO_CONSOLE: '1'
}
})
const parsed = JSON.parse(out)
assert.deepEqual(parsed.argv, [gitBin, ...gitArgs])

View File

@@ -73,28 +73,38 @@ export function resolveNoConsolePython({
roots?: string[]
fileExists?: (candidate: string) => boolean
}): string | null {
if (!isWindows) {return null}
if (!isWindows) {
return null
}
const candidates: string[] = []
const override = env.HERMES_DESKTOP_PYTHON
if (override) {candidates.push(override)}
if (override) {
candidates.push(override)
}
const hermesRoot = env.HERMES_DESKTOP_HERMES_ROOT
const searchRoots = hermesRoot ? [hermesRoot, ...roots] : roots
for (const root of searchRoots) {
if (!root) {continue}
if (!root) {
continue
}
candidates.push(path.win32.join(root, '.venv', 'Scripts', 'python.exe'))
candidates.push(path.win32.join(root, 'venv', 'Scripts', 'python.exe'))
}
for (const candidate of candidates) {
if (!candidate || isPythonW(candidate) || isWindowsAppsStub(candidate)) {continue}
if (!candidate || isPythonW(candidate) || isWindowsAppsStub(candidate)) {
continue
}
try {
if (fileExists(candidate)) {return candidate}
if (fileExists(candidate)) {
return candidate
}
} catch {
continue
}
@@ -107,7 +117,9 @@ export function ensureNoConsoleGitScript(dir = os.tmpdir()) {
const scriptPath = path.join(dir, 'hermes-no-console-git.py')
try {
if (fs.readFileSync(scriptPath, 'utf8') === NO_CONSOLE_GIT_SCRIPT) {return scriptPath}
if (fs.readFileSync(scriptPath, 'utf8') === NO_CONSOLE_GIT_SCRIPT) {
return scriptPath
}
} catch {
// Missing or unreadable: rewrite below.
}
@@ -118,11 +130,15 @@ export function ensureNoConsoleGitScript(dir = os.tmpdir()) {
}
export function windowsGitHost(isWindows = process.platform === 'win32'): NoConsoleGitHost | null {
if (!isWindows) {return null}
if (!isWindows) {
return null
}
const pythonBin = resolveNoConsolePython({ isWindows: true })
if (!pythonBin) {return null}
if (!pythonBin) {
return null
}
try {
return { isWindows: true, pythonBin, scriptPath: ensureNoConsoleGitScript() }
@@ -135,12 +151,16 @@ export function noConsoleGitEnv(base: NodeJS.ProcessEnv | undefined, gitBin: str
const env: NodeJS.ProcessEnv = {}
for (const [key, value] of Object.entries(base || {})) {
if (value !== undefined) {env[key] = value}
if (value !== undefined) {
env[key] = value
}
}
env.HERMES_GIT_ARGV0 = JSON.stringify(gitBin || 'git')
if (!env.GIT_TERMINAL_PROMPT) {env.GIT_TERMINAL_PROMPT = '0'}
if (!env.GIT_TERMINAL_PROMPT) {
env.GIT_TERMINAL_PROMPT = '0'
}
return env
}
@@ -242,7 +262,9 @@ export function execGit(
let settled = false
const finish = (error?: Error, code: number | null = child.exitCode) => {
if (settled) {return}
if (settled) {
return
}
settled = true
@@ -272,12 +294,16 @@ export function execGit(
stderr += chunk.toString()
})
child.once('error', error => {
if (timer) {clearTimeout(timer)}
if (timer) {
clearTimeout(timer)
}
finish(error)
})
child.once('close', code => {
if (timer) {clearTimeout(timer)}
if (timer) {
clearTimeout(timer)
}
finish(undefined, code)
})