mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-22 16:25:58 +00:00
Review on #20379, finding 4 (Medium). Three portability defects in the visual verification harness: - `FORCE_COLOR=3 COLORTERM=truecolor tsx ...` POSIX env assignment does not work under the Windows npm command shell. The script is now a plain Node launcher (scripts/visual/run.mjs) that sets the env itself and spawns tsx via require.resolve('tsx/cli') — no cross-env, no shell syntax. - Hardcoded /tmp/tui-visual.{html,png} resolve to a drive-root path like C:\tmp on native Windows (and fail when that directory doesn't exist). Both scripts now derive the output directory from a shared paths.mjs helper: os.tmpdir()/hermes-tui-visual (created recursively; HERMES_TUI_VISUAL_DIR overrides for CI or side-by-side runs). - electron was undeclared by ui-tui and only worked via hoisting luck. The launcher now resolves it EXPLICITLY from the install tree the desktop workspace already provides (require('electron') in plain Node returns the binary path), with an ELECTRON_BIN override and a clear error pointing at the repo-root install when it's absent — instead of declaring a second ~100MB dependency on a TUI workspace for a dev-only harness. Also fixes the trailing-whitespace line in render.tsx that `git diff --check` flags. Verified end-to-end: render writes the HTML scene sheet and the electron shot step produces the screenshot from the tmpdir path; the missing-electron error path prints the guidance message.
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
// Zero-dependency launcher for the visual harness (`npm run visual`).
|
|
//
|
|
// - Sets FORCE_COLOR/COLORTERM itself instead of POSIX `VAR=x cmd` shell
|
|
// assignments (which break under the Windows npm command shell) — no
|
|
// cross-env needed.
|
|
// - Resolves electron from the install tree (the desktop workspace already
|
|
// ships it; a root `npm install` hoists it) instead of declaring a second
|
|
// copy as a ui-tui dependency. ELECTRON_BIN overrides for exotic setups.
|
|
import { spawnSync } from 'child_process'
|
|
import { createRequire } from 'module'
|
|
import { dirname, join } from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
const require = createRequire(import.meta.url)
|
|
|
|
const run = (bin, args, env = {}) => {
|
|
const { status } = spawnSync(bin, args, { env: { ...process.env, ...env }, stdio: 'inherit' })
|
|
|
|
if (status !== 0) {
|
|
process.exit(status ?? 1)
|
|
}
|
|
}
|
|
|
|
// 1. Render the scene sheet (tsx is a ui-tui devDependency).
|
|
run(process.execPath, [require.resolve('tsx/cli'), join(here, 'render.tsx')], {
|
|
COLORTERM: 'truecolor',
|
|
FORCE_COLOR: '3'
|
|
})
|
|
|
|
// 2. Screenshot it with electron, borrowed from the workspace that owns it.
|
|
let electronBin = process.env.ELECTRON_BIN
|
|
|
|
if (!electronBin) {
|
|
try {
|
|
// In plain Node, `require('electron')` evaluates to the binary path.
|
|
electronBin = require('electron')
|
|
} catch {
|
|
console.error(
|
|
'electron is not installed in this tree — the visual harness borrows it from the\n' +
|
|
'desktop workspace. Run `npm install` at the repo root, or point ELECTRON_BIN at a binary.'
|
|
)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
run(electronBin, [join(here, 'shot.mjs')])
|