`HERMES/Policy.ts` silently discards its destination argument unless `--launcher` is passed
What LifeOS does here
LIFEOS/HERMES/Policy.ts builds the guard policy that the Hermes sidecar's Python plugin
(LIFEOS/HERMES/plugin/guard.py) loads to decide what the sidecar may read and do. Run as a CLI it
either prints the policy to stdout or, given a destination path, writes it there:
bun Policy.ts # print
bun Policy.ts <dest> # write to <dest>
bun Policy.ts <dest> --launcher <n> # write, with the launcher name baked in
Current behavior
The argument parser drops one positional by index:
const argv = process.argv.slice(2);
const launcherIdx = argv.indexOf("--launcher");
const launcherName = launcherIdx !== -1 ? (argv[launcherIdx + 1] ?? "") : "";
const positional = argv.filter((a, i) => a !== "--launcher" && i !== launcherIdx + 1);
const dest = positional[0];
launcherIdx + 1 is meant to skip the flag's value. When the flag is absent, indexOf returns
-1, so launcherIdx + 1 is 0 and the filter drops index 0 — the destination path.
With --launcher present the arithmetic is right: for [dest, "--launcher", "name"],
launcherIdx is 1, index 2 is dropped along with the flag, and positional is [dest].
Reproduction
Verified on v7.40.4:
$ bun LIFEOS/HERMES/Policy.ts /tmp/probe/policy.json
{ …the whole policy printed to stdout… }
$ ls /tmp/probe/policy.json
ls: /tmp/probe/policy.json: No such file or directory
$ bun LIFEOS/HERMES/Policy.ts /tmp/probe/policy.json --launcher testda
✓ policy v5 — 28 read rules → /tmp/probe/policy.json
Exit status is 0 in both cases. The first form reports nothing wrong; it just does not write the
file.
Impact
Silent, and not safe by default. A caller that asks for a policy file without passing --launcher
gets exit 0, a large JSON blob on stdout, and no file. guard.py then hits its
FileNotFoundError path, logs failing closed, and falls back to _all_guarded_tools_fallback().
That fallback is not the whole guarded surface:
return frozenset({
"read_file", "read_file_raw", "write_file", "patch", "edit_file",
"grep", "search_files", "list_files", "glob",
"terminal", "bash", "shell",
})
Twelve names. execute_code is not among them, although Policy.ts lists it in
commandBearingTools precisely because it can read arbitrary files. With no policy loaded,
evaluate("execute_code", …) returns None — an allow.
The exposure is partial, not total: write_file, patch, and edit_file are in the fallback and
stay blocked. What slips through is the guarded surface the fallback does not name — execute_code,
and privileged tools such as send and send_message, which a loaded policy would gate once the
session is tainted. So the posture with a missing policy is "closed for those twelve, open for the
rest", not closed.
Two separable defects meet here. Fixing the parser removes this trigger. The incomplete fallback deserves its own look, since any other cause of a missing or unreadable policy reaches the same state.
The shipped plugin/test_guard.py passes --launcher testda, so upstream's own suite does not hit
the parser bug. Any other caller does — including anything written against the two-argument form
v7.28.3 accepted, where the destination was simply process.argv[2].
Affected versions
Present in v7.40.4. Not present in v7.28.3 — the line does not exist there, so this is a
regression introduced with the --launcher option.
Suggested direction
Compute the value index once and reuse it, so an absent flag cannot alias index 0:
const launcherIdx = argv.indexOf("--launcher");
const valueIdx = launcherIdx === -1 ? -1 : launcherIdx + 1;
const launcherName = valueIdx === -1 ? "" : (argv[valueIdx] ?? "");
const positional = argv.filter((a, i) => i !== launcherIdx && i !== valueIdx);
A one-line regression test — run the CLI with a destination and no flag, assert the file exists — would pin it.
The parser was fixed 08-17. The fallback gap landed now and a bit wider than you asked: execute_code, read_terminal and the privileged tools are all in the no-policy fallback, and a test asserts the fallback covers everything the loaded policy names so it can't drift again. Next release. Thanks.