feat(oneshot): add --usage-file JSON usage report to hermes -z (#59615)

* feat(oneshot): add --usage-file JSON usage report to hermes -z

Pipelines driving hermes -z (batch reviewers, cron scripts, eval
harnesses) had no way to account for per-invocation spend: the agent
computes estimated_cost_usd and full token counts internally, but
oneshot mode discards everything except the final response text.

- hermes -z PROMPT --usage-file PATH writes a JSON report after the
  run: estimated_cost_usd, cost_status/source, input/output/cache/
  reasoning/total tokens, api_calls, model, provider, session_id,
  completed, failed.
- Written even when the run fails (with a failure field) so callers
  can always account for spend; the write itself is best-effort and
  never masks the run's own outcome.
- Flag registered in both the full parser and the Termux fast path;
  added to both value-flag scan sets so profile detection stays
  correct.

Validation: 6 unit tests + live E2E (real -z run produced a report
with real OpenRouter cost + token counts).

* test: include usage_file kwarg in oneshot dispatch assertions

The two dispatch tests assert the exact kwargs dict passed to
run_oneshot; the new usage_file kwarg must appear there.
This commit is contained in:
Teknium 2026-07-06 11:10:51 -07:00 committed by GitHub
parent 7426c09bee
commit 7dfd5077ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 133 additions and 0 deletions

View file

@ -112,6 +112,17 @@ def build_top_level_parser():
"auto-bypassed. Intended for scripts / pipes."
),
)
parser.add_argument(
"--usage-file",
metavar="PATH",
default=None,
help=(
"One-shot mode only: after the run, write a JSON usage report "
"(estimated cost, token counts, model, api_calls) to PATH. "
"The report is written even when the run fails, so pipelines "
"can always account for spend. No effect outside -z/--oneshot."
),
)
# --model / --provider are accepted at the top level so they can pair
# with -z without needing the `chat` subcommand. If neither -z nor a
# subcommand consumes them, they fall through harmlessly as None.