Skip to content

Policy.ts CLI silently discards its destination argument when --launcher is absent #1859

Description

@hjbrandt

Version: v7.40.4
File: LifeOS/install/LIFEOS/HERMES/Policy.ts (the import.meta.main block)

Repro

bun LifeOS/install/LIFEOS/HERMES/Policy.ts /tmp/policy.json
# prints the full policy JSON to stdout, exits 0
ls /tmp/policy.json
# No such file or directory

Expected: ✓ policy v… → /tmp/policy.json and the file written.
Actual: the destination argument is discarded, the CLI takes the "no dest → print to stdout" path, and no file is ever written. Exit code is 0, so callers (scripts, test harnesses that generate a policy to a temp path) fail later with a confusing FileNotFoundError on the policy file rather than at the point of the actual bug.

Cause

const launcherIdx = argv.indexOf("--launcher");
// …
const positional = argv.filter((a, i) => a !== "--launcher" && i !== launcherIdx + 1);

When --launcher is not passed, launcherIdx is -1, so the filter condition i !== launcherIdx + 1 becomes i !== 0 — which removes argv[0], the destination path. positional[0] is then undefined and the stdout branch runs.

With --launcher present the CLI behaves correctly; the bug only bites the plain bun Policy.ts <dest> form.

Fix

Guard the sentinel value:

const positional = argv.filter(
  (a, i) => a !== "--launcher" && (launcherIdx === -1 || i !== launcherIdx + 1),
);

Happy to send this as a PR (3-line change, no behavior change for the --launcher form).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions