Skip to content

feat(cli): add Hermes usage reporting - #2892

Open
alexandrbasis wants to merge 1 commit into
steipete:mainfrom
alexandrbasis:feat/hermes-usage-source
Open

feat(cli): add Hermes usage reporting#2892
alexandrbasis wants to merge 1 commit into
steipete:mainfrom
alexandrbasis:feat/hermes-usage-source

Conversation

@alexandrbasis

Copy link
Copy Markdown

Summary

  • add a read-only, WAL-aware Hermes Agent state.db scanner and expose it as codexbar hermes-usage
  • aggregate all discovered Hermes profiles by CodexBar provider, model, and auxiliary task while preserving unmapped routes
  • keep billed cost, subscription-included usage, Hermes estimates, and models.dev API-equivalent estimates as separate fields
  • classify every canonical Hermes billing route, with conservative fail-closed handling for ambiguous routes and base-URL-aware Kimi/Moonshot, MiniMax OAuth, and StepFun routing

Why

Hermes Agent records token attribution in SQLite rather than Codex/Claude session JSONL, so CodexBar cannot currently report that local usage. This adds a narrow local import path without introducing another scanner framework or merging Hermes data into native provider billing totals, where the same API calls could be double-counted.

The scanner uses the persisted session_model_usage provider/model/task dimensions, includes auxiliary calls such as compression and title generation, and reconciles only positive legacy main-loop residuals from sessions. It does not infer daily history from cumulative rows.

Linked issue or maintainer sign-off

No linked issue: this is a distinct local-telemetry feature rather than a Nous Portal provider implementation.

#1367 requested Nous Portal quota support and was closed because no public portal API was available. This PR intentionally does not implement portal quota, OAuth, cookies, or remote account access; it reads only local Hermes attribution databases and requires no credentials.

Validation

  • make check
  • make test — 843 selections, 71/71 groups, 0 failed groups, 0 retries
  • focused Hermes/provider architecture suite — 56/56 tests
  • live active-WAL scan against a Hermes profile, cross-checked bucket-for-bucket with independent read-only SQL
  • missing-only explicit source returns exit 1; active database returns valid JSON and exit 0

UI proof

CLI-only change; no app UI changed.

Example:

$ codexbar hermes-usage --provider codex
Hermes local usage (all time)
Sources: 1 read, 0 missing, 0 unreadable
...

--json provides a versioned report for automation. No screenshot is applicable.

Provider and privacy impact

  • opens only discovered or explicitly supplied state.db files with SQLite read-only flags and PRAGMA query_only=ON
  • reads active WAL sidecars without copying/checkpointing and does not create sidecars for idle databases
  • never reads Hermes auth files, API keys, cookies, prompts, or message content
  • maps only explicit Hermes billing_provider routes; auto, custom, moa, azure-foundry, and other ambiguous routes remain unmapped
  • does not merge Hermes usage into provider billing dashboards, preventing silent double counting with native provider/API billing sources
  • counts input + output + cache_read + cache_write; reasoning_tokens remains an output sub-breakdown and is not added twice

Checklist

  • Added focused parser, active-WAL, legacy-schema, mapping, pricing, CLI, and architecture-gate tests
  • Added CLI/provider documentation and the exhaustive Hermes route matrix
  • Ran formatter, SwiftLint, repository checks, and the complete test suite
  • Kept the change credential-free and read-only

@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 12, 2026
@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed August 12, 2026, 4:23 PM ET / 20:23 UTC.

ClawSweeper review

What this changes

This PR adds codexbar hermes-usage, a read-only CLI scanner for local Hermes Agent SQLite attribution with separate provider, model, task, and cost-estimate reporting.

Merge readiness

Blocked until real behavior proof is added - 5 items remain

Keep open for maintainer product-direction review and real behavior proof. The implementation is a substantial new supported CLI surface, not a fix for an established bug; its source isolation is careful, but Hermes schema ownership needs explicit sponsorship.

Priority: P3
Reviewed head: 21498e9adf32f4eaf0999a29b218ccc570641b49
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is well-scoped and covered by focused fixtures, but missing inspectable real behavior proof caps the overall rating.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The body describes a live active-WAL scan but provides no inspectable after-fix terminal transcript, recording, log, or artifact; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The body describes a live active-WAL scan but provides no inspectable after-fix terminal transcript, recording, log, or artifact; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 7 items New feature is not on current main: The PR head is not an ancestor of current main, so the requested Hermes command is still a distinct proposed capability.
Explicit local-data boundary: The scanner discovers only default/profile Hermes databases and opens them with SQLite read-only URI flags, query-only mode, and WAL handling.
External-schema dependency is real: The proposed scanner directly reads Hermes session_model_usage and sessions tables; the route mapping and residual logic therefore depend on Hermes’s persisted schema and semantics.
Findings None None.
Security None None.

How this fits together

CodexBar’s CLI reports usage and local cost information for terminal users and automation. This new path reads Hermes Agent state databases, maps explicit billing routes to CodexBar providers, and emits a standalone report without changing existing provider billing totals.

flowchart LR
  A[Hermes state databases] --> B[Read-only database discovery]
  B --> C[Usage scanner]
  C --> D[Route and model mapping]
  D --> E[Cost classification]
  E --> F[CLI text or JSON report]
  F --> G[Terminal and automation users]
Loading

Decision needed

Question Recommendation
Should CodexBar own and maintain a supported local Hermes state.db scanner and its billing-route mapping as a CLI feature? Sponsor the standalone CLI command: Approve the narrow local-only telemetry surface, subject to real-profile proof and ongoing ownership of Hermes schema compatibility.

Why: This is a new, sizeable integration with a third-party persisted schema and no linked maintainer sign-off; implementation quality cannot establish the intended long-term ownership boundary.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The body describes a live active-WAL scan but provides no inspectable after-fix terminal transcript, recording, log, or artifact; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - This adds 1,232 production lines for a third-party persisted-schema import; Hermes schema or route changes could yield misleading attribution without a maintained compatibility contract.
  • Resolve merge risk (P1) - The PR claims a live active-WAL scan, but no inspectable redacted transcript, recording, or artifact demonstrates the after-fix result on a real Hermes database.
  • Complete next step (P2) - A maintainer must decide whether CodexBar should own the Hermes local-schema integration; contributor real-behavior proof is also required before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Code and test delta production +1,232; tests +716; docs +110 The new CLI and external-schema scanner materially expand the supported maintenance surface.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    If sponsored, retain the standalone read-only CLI boundary and land only after a redacted real-profile WAL scan proves the reported buckets and source-safety behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

If sponsored, retain the standalone read-only CLI boundary and land only after a redacted real-profile WAL scan proves the reported buckets and source-safety behavior.

Do we have a high-confidence way to reproduce the issue?

Not applicable to an existing bug: the branch introduces a new capability. Its claimed live validation is not independently inspectable because no runtime transcript or artifact is attached.

Is this the best way to solve the issue?

Unclear: keeping Hermes attribution separate from native billing is a narrow technical boundary, but maintainers must first decide whether CodexBar should own this external database-schema integration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ee29794b9a1b.

Labels

Label changes:

  • add P3: This is an optional new CLI telemetry capability rather than a current user-facing regression.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body describes a live active-WAL scan but provides no inspectable after-fix terminal transcript, recording, log, or artifact; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P3: This is an optional new CLI telemetry capability rather than a current user-facing regression.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body describes a live active-WAL scan but provides no inspectable after-fix terminal transcript, recording, log, or artifact; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Authored the recent provider-architecture gate and the idle-WAL fallback used by the analogous local usage reader. (role: recent provider-architecture and local SQLite reader contributor; confidence: high; commits: 770ec06d2fc4, c4df5bb029d0; files: Sources/CodexBarCore/Vendored/CostUsage/ModelsDevPricing.swift, Sources/CodexBarCore/Providers/OpenCodeGo/OpenCodeGoLocalUsageReader.swift)
  • kentoku24: Introduced the recent per-model OpenCode Go local usage work, which is the closest merged feature-history analogue. (role: adjacent local-usage feature contributor; confidence: medium; commits: 23eb7750e471; files: Sources/CodexBarCore/Providers/OpenCodeGo/OpenCodeGoLocalUsageReader.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Post a redacted terminal transcript or recording of a real active-WAL Hermes scan, including the command and resulting source/bucket output.
  • Obtain maintainer sponsorship for the long-term Hermes schema and route-mapping ownership boundary.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 21498e9adf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

!raw.isEmpty,
raw.lowercased() != "all"
else { return nil }
guard let provider = UsageProvider(rawValue: raw.lowercased()) else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse Hermes provider filters through CLI names

When users pass the documented CodexBar provider names for mapped Hermes routes, such as --provider opencode-go, --provider qwen-cloud, --provider vertex-ai, or --provider alibaba-coding-plan, this raw-value lookup rejects them even though the rest of the CLI resolves provider names and aliases through ProviderDescriptorRegistry.cliNameMap. That makes the new --provider filter unusable for several supported Hermes mappings unless users know the internal enum raw values like opencodego/qwencloud instead of the normal CLI names.

Useful? React with 👍 / 👎.

Comment on lines +525 to +530
let input = Double(row.tokens.input) * pricing.inputCostPerToken
let output = Double(row.tokens.output) * pricing.outputCostPerToken
let cacheRead = Double(row.tokens.cacheRead)
* (pricing.cacheReadInputCostPerToken ?? pricing.inputCostPerToken)
let cacheWrite = Double(row.tokens.cacheWrite)
* (pricing.cacheCreationInputCostPerToken ?? pricing.inputCostPerToken)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply models.dev long-context rates

For Hermes rows whose matched models.dev pricing has a long-context threshold, this calculation always uses the base input/output/cache rates and ignores the *AboveThreshold rates, so large Claude/OpenAI/etc. sessions over the threshold are reported with understated API-equivalent costs. The existing cost estimator switches rates when the token count crosses thresholdTokens; this path should make the same choice before multiplying the row tokens.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant