mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
pre-update-backup-config.ts (4de06d1dbf) survived the rewrite with no
caller: the checkout strategy called preflightStateDb unconditionally, so a
user who turned the pre-update backup family off in config.yaml still got
an emergency state.db snapshot on every Desktop update. Gate the preflight
on `hermes config get updates.pre_update_backup` in the composition root;
an unreadable answer keeps the snapshot, as before.
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { execFile } from 'node:child_process'
|
|
import { promisify } from 'node:util'
|
|
|
|
const DISABLED_BACKUP_MODES = new Set(['off', 'false', 'none', 'disabled'])
|
|
const execFileAsync = promisify(execFile)
|
|
|
|
export function preUpdateBackupEnabled(value: unknown): boolean {
|
|
if (value === false || value === null) {
|
|
return false
|
|
}
|
|
|
|
return typeof value !== 'string' || !DISABLED_BACKUP_MODES.has(value.trim().toLowerCase())
|
|
}
|
|
|
|
export interface HermesConfigRuntime {
|
|
command?: string | null
|
|
args?: string[]
|
|
env?: NodeJS.ProcessEnv
|
|
shell?: boolean
|
|
}
|
|
|
|
export async function readPreUpdateBackupEnabled(
|
|
runtime: HermesConfigRuntime | Promise<HermesConfigRuntime>,
|
|
hermesHome: string,
|
|
run = execFileAsync
|
|
): Promise<boolean> {
|
|
try {
|
|
const resolvedRuntime = await runtime
|
|
|
|
if (!resolvedRuntime.command || !resolvedRuntime.args) {
|
|
return true
|
|
}
|
|
|
|
const result = await run(resolvedRuntime.command, resolvedRuntime.args, {
|
|
encoding: 'utf8',
|
|
env: { ...process.env, ...resolvedRuntime.env, HERMES_HOME: hermesHome },
|
|
shell: Boolean(resolvedRuntime.shell),
|
|
timeout: 15_000,
|
|
windowsHide: true
|
|
})
|
|
|
|
return preUpdateBackupEnabled(JSON.parse(String(result.stdout).trim()))
|
|
} catch {
|
|
// A missing runtime, probe failure, or malformed response must not weaken
|
|
// the emergency recovery path.
|
|
return true
|
|
}
|
|
}
|