mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
- driver now stages the manifest via the parent-owned common bundle-inputs.mjs (bundle-inputs.json written where require_manifest expects it) and creates WORK_ROOT/LOG_DIR/HOME dirs up front - HOME is set to the sandbox (HOME_SANDBOX was exported but never used) - the installed executable is derived from CFBundleExecutable in the bundle's own Info.plist (packaged name is 'Hermes Bundled', no rename assumed) and persisted in an install receipt the update phase reads — no hardcoded Contents/MacOS/Hermes - codesign -dv display output is read from STDERR via spawnSync combined streams (execFileSync stdout was always empty) - identity is verified as the exact CFBundleIdentifier and an explicit teamId is required and verified exactly on both sides (mirrors the common resolver's rules); dropped the com.nousresearch.* prefix check - relaunch proof additionally requires the watcher's appBin to equal the receipt path - lipo -archs verifies the installed bundle matches the leg's arch - feed server binds port 0 and writes a readiness JSON with the actual port; the driver configures desktop_feed_base_url from it instead of a fixed 8791; path traversal check uses path.relative with a real separator-aware rejection - feed channel derives from the NEW tag (canary tags serve releases/darwin/canary/<arch->canary-mac.yml); manifest validator rejects channel-crossing pairs - sha512 of the release zip is streamed, no whole-file buffer - serve/watcher pids are globals killed by a top-level EXIT trap (trap referenced a local under set -u; watcher leaked on failure) - final PASS line uses the update phase's new_tag (old_tag was out of scope there) - tests exercise helper behavior (validators, streamed hash, safeJoin, per-channel feed layout) instead of source-shape assumptions
84 lines
3.2 KiB
JavaScript
84 lines
3.2 KiB
JavaScript
#!/usr/bin/env node
|
|
'use strict'
|
|
// mac-bundled-serve.mjs — loopback-only static file server for the macOS
|
|
// bundled-update E2E feed. Serves the directory produced by
|
|
// mac-bundled-feed.mjs over 127.0.0.1, logs every request to a JSONL file
|
|
// (the proof the app really fetched THIS feed), and stays up until killed.
|
|
//
|
|
// --port 0 (the default) binds an ephemeral port; the ACTUAL port is
|
|
// written as JSON to --ready once listening, so the driver configures the
|
|
// app with the real URL instead of a hard-coded one.
|
|
//
|
|
// Usage: node mac-bundled-serve.mjs --dir <feed-dir> [--port 0] \
|
|
// --log <requests.jsonl> [--health /__healthz] [--ready <json>]
|
|
|
|
import http from 'node:http'
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import { pathToFileURL } from 'node:url'
|
|
import { parseArgs } from 'node:util'
|
|
|
|
/** Resolve `pathname` inside `root`, rejecting any path that escapes it
|
|
* (path traversal). Returns null when the target is outside the root. */
|
|
export function safeJoin(root, pathname) {
|
|
const target = path.resolve(root, '.' + decodeURIComponent(pathname))
|
|
const rel = path.relative(path.resolve(root), target)
|
|
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return null
|
|
return target
|
|
}
|
|
|
|
const invokedDirectly = process.argv[1] &&
|
|
import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
|
|
|
|
if (invokedDirectly) {
|
|
const { values } = parseArgs({
|
|
options: {
|
|
dir: { type: 'string' },
|
|
port: { type: 'string', default: '0' },
|
|
log: { type: 'string' },
|
|
health: { type: 'string', default: '/__healthz' },
|
|
ready: { type: 'string' },
|
|
}
|
|
})
|
|
|
|
const root = path.resolve(values.dir)
|
|
if (!fs.existsSync(root)) {
|
|
console.error(`feed dir not found: ${root}`)
|
|
process.exit(1)
|
|
}
|
|
const logStream = values.log ? fs.createWriteStream(values.log, { flags: 'a' }) : null
|
|
|
|
const server = http.createServer((req, res) => {
|
|
const url = new URL(req.url, 'http://127.0.0.1')
|
|
if (logStream) {
|
|
logStream.write(JSON.stringify({ t: Date.now(), path: url.pathname, ua: req.headers['user-agent'] || '' }) + '\n')
|
|
}
|
|
if (url.pathname === values.health) {
|
|
res.writeHead(200, { 'content-type': 'text/plain' })
|
|
res.end('ok\n')
|
|
return
|
|
}
|
|
const target = safeJoin(root, url.pathname)
|
|
if (!target || !fs.existsSync(target) || !fs.statSync(target).isFile()) {
|
|
res.writeHead(404, { 'content-type': 'text/plain' })
|
|
res.end('not found\n')
|
|
return
|
|
}
|
|
// no-store: the updater must always see the live feed, never a cache.
|
|
res.writeHead(200, {
|
|
'content-type': target.endsWith('.yml') ? 'text/yaml; charset=utf-8' : 'application/zip',
|
|
'content-length': fs.statSync(target).size,
|
|
'cache-control': 'no-store'
|
|
})
|
|
fs.createReadStream(target).pipe(res)
|
|
})
|
|
|
|
// Loopback only, by construction and by policy: the production updater
|
|
// accepts loopback HTTP overrides exclusively (mac-client.ts).
|
|
server.listen(Number(values.port), '127.0.0.1', () => {
|
|
const port = server.address().port
|
|
const receipt = { port, url: `http://127.0.0.1:${port}`, root }
|
|
if (values.ready) fs.writeFileSync(values.ready, JSON.stringify(receipt) + '\n')
|
|
console.log(`serving ${root} on http://127.0.0.1:${port}`)
|
|
})
|
|
}
|