Skip to content

Add Codex project cost rollups - #1884

Merged
steipete merged 1 commit into
mainfrom
codex/pr-1820-project-cost-rollups
Jul 4, 2026
Merged

Add Codex project cost rollups#1884
steipete merged 1 commit into
mainfrom
codex/pr-1820-project-cost-rollups

Conversation

@steipete

@steipete steipete commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • group local Codex token usage and cost by canonical project while preserving each worktree/source path
  • expose project rollups in the cost-history menu, CLI text, and CLI JSON
  • refresh hosted menus when only project/source data changes and keep single differing sources visible
  • preserve the existing v8 cache artifact while migrating project metadata safely; legacy cache rows never render as Unknown before migration
  • drain bounded git subprocess output so large worktree repositories cannot deadlock the scan

Maintainer replacement for #1820 because the contributor fork cannot accept the current-main repair through the available OAuth workflow scope. Based on @clemenspeters's implementation; contributor authorship and changelog credit are preserved.

Closes #1819.

Validation

  • exact head: 46a30014728552ed5ddeef43dbc9e85bb1474da4
  • make check — repository guards, parser hash, SwiftFormat, and strict SwiftLint passed on the current-main candidate
  • make test — all 46 sharded groups passed on the reviewed project-rollup tree; exact-head CI reruns the full matrix against latest main
  • swift test --filter 'CostUsage|CostHistory|CLICost|StatusMenuHostedSubmenuRefresh' — 252 tests in 24 suites passed on the current-main candidate
  • autoreview — clean after three accepted fixes, 0.82 correctness confidence
  • CODEXBAR_DISABLE_KEYCHAIN_ACCESS=1 ./Scripts/compile_and_run.sh — exact signed production app packaged, launched, and remained running
  • exact bundled CLI forced a real local Codex scan, then returned 27 active days, 77 named projects, 80 source roots, and two multi-source projects; every project total was nonnegative
  • no SecurityAgent process appeared during live proof

Live UI boundary

The host reports Screen Recording and Accessibility denied, so menu screenshot/click proof is unavailable. The exact production app and bundled CLI exercised the real scanner, cache, canonicalization, and rendering payload path without accessing Keychain credentials.

Risk

Medium and local-data scoped. The migration intentionally narrows the retained cache window once so unscanned legacy rows cannot be mislabeled; wider history is repopulated from the original local session files on demand. Raw local paths remain confined to the existing opt-in local cost UI and CLI output.

@clawsweeper

clawsweeper Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed July 4, 2026, 5:47 AM ET / 09:47 UTC.

Summary
The branch adds Codex project/source cost rollups to scanner cache metadata, menu cost history, CLI text/JSON, docs, and focused tests while keeping the v8 cache artifact.

Reproducibility: not applicable. as a bug reproduction; this is a feature PR. Source inspection confirms current main lacks project rollup types or --group-by project, while the branch adds them.

Review metrics: 3 noteworthy metrics.

  • Changed surface: 20 files, +1603/-46. The diff spans scanner/cache, CLI, menu UI, docs, and tests, so review needs cross-layer compatibility coverage.
  • Public output surface: 1 CLI flag plus project/source JSON fields. --group-by project and new JSON fields can affect scripts and users inspecting local project paths.
  • Cache artifact strategy: Codex v8 retained, 1 metadata version added. Keeping the v8 file avoids a full artifact-version reset but still creates a one-time project metadata migration.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #1819
Summary: This PR is the maintainer replacement implementation for the open project-level Codex cost rollup feature request.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Confirm that exposing raw local project/source paths in menu and CLI JSON is intentional.
  • Confirm the one-time cache metadata migration behavior is acceptable for upgraded users.

Mantis proof suggestion
A visible menu proof would materially help because the PR changes the cost-history submenu and project/source row rendering. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis visual task: verify Codex cost history shows project rollups and source CWD rows with redacted paths.

Risk before merge

  • [P1] Project/source filesystem paths become part of the local menu and CLI JSON output, so maintainers should explicitly accept that privacy/product contract before merge.
  • [P1] The first project-metadata migration intentionally narrows retained cache history and relies on original session files to rebuild wider rollups; users missing source logs may have less historical project detail until rescanned.

Maintainer options:

  1. Accept the local-cache migration (recommended)
    Merge with the current v8 metadata migration if maintainers accept that older unscanned cache rows are temporarily omitted and wider history is rebuilt from session logs.
  2. Narrow the path output contract
    If raw local paths should not be exposed to integrations, change the menu/JSON output to redact, omit, or gate project and source paths before merge.
  3. Pause for privacy wording
    If the reporting contract is still unsettled, hold the PR until docs or UI copy makes the local-path behavior explicit.

Next step before merge

  • [P2] Remaining action is maintainer acceptance of compatibility/privacy risk and normal merge checks, not an automated code repair.

Security
Cleared: No dependency, CI, secret, network, or code-execution supply-chain concern was found; local path exposure is tracked as product/compatibility risk.

Review details

Best possible solution:

Merge after normal maintainer review if the project/path reporting contract and one-time cache metadata migration are intentional.

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

Not applicable as a bug reproduction; this is a feature PR. Source inspection confirms current main lacks project rollup types or --group-by project, while the branch adds them.

Is this the best way to solve the issue?

Yes, with maintainer acceptance of the compatibility risk. The additive scanner/model layer plus CLI/menu exposure is maintainable, and this replacement fixes the earlier source-row, refresh-signature, and cache-artifact concerns.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P3: This is a useful but non-urgent reporting feature with limited blast radius and no broken existing workflow.
  • add merge-risk: 🚨 compatibility: The PR changes local persisted cache metadata and public CLI JSON/text output, so upgraded-user and integration behavior need maintainer acceptance.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this owner-authored PR, and the body includes live CLI scan and Keychain-disabled bundle validation context.

Label justifications:

  • P3: This is a useful but non-urgent reporting feature with limited blast radius and no broken existing workflow.
  • merge-risk: 🚨 compatibility: The PR changes local persisted cache metadata and public CLI JSON/text output, so upgraded-user and integration behavior need maintainer acceptance.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this owner-authored PR, and the body includes live CLI scan and Keychain-disabled bundle validation context.
Evidence reviewed

What I checked:

Likely related people:

  • steipete: Current-main blame/log history ties the cost fetcher and CLI cost surfaces to prior merged baseline work, and this owner-authored replacement PR carries the current repair. (role: baseline and replacement owner; confidence: high; commits: 51eeae71bad8, 056016083470; files: Sources/CodexBarCore/CostUsageFetcher.swift, Sources/CodexBarCLI/CLICostCommand.swift)
  • dylanstieri: Recent main history includes Codex priority/cost scanner work and a Codex cost-inflation fix in the same scanner/cache area this PR extends. (role: recent scanner contributor; confidence: medium; commits: 840bb8b3435f, e71db5e47a07; files: Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift, Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+CacheHelpers.swift)
  • kiranmagic7: Recent merged work changed Codex archived-row preservation and dedupe behavior in the cache helper path that project rollups reuse. (role: recent scanner/cache contributor; confidence: medium; commits: d648a9612920, 0065ca42e6ab; files: Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift, Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+CacheHelpers.swift)
  • iam-brain: Git history shows prior Codex priority pricing and standard/fast cost split work that is adjacent to project rollup cost attribution. (role: adjacent cost-pricing contributor; confidence: medium; commits: cdb6acba6407, 2f6a31c23e2c; files: Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+CacheHelpers.swift, Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Jul 4, 2026

@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: 0560160834

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

var exitCode: ExitCode = .success

for provider in providers {
for provider in providers where groupBy != .project || provider == .codex || format == .json {

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 Fail when project grouping leaves no provider

When text output is grouped by project and the selected providers do not include Codex (for example, codexbar cost --provider claude --group-by project), this filter skips every provider after only emitting a warning, leaving sections empty and exiting with success and no stdout. That makes an unsupported invocation look successful; fail before the loop or fall back to regular cost output when the filtered provider set is empty.

Useful? React with 👍 / 👎.

Group local Codex usage and costs by canonical project and worktree source across menus, CLI text, and JSON output. Preserve the existing cache artifact while migrating project metadata safely, and avoid rendering legacy cache rows before migration.

Co-authored-by: Clemens Peters <c.peters@conventic.com>
@steipete
steipete force-pushed the codex/pr-1820-project-cost-rollups branch from 0560160 to 46a3001 Compare July 4, 2026 10:28
@steipete
steipete merged commit 1e49619 into main Jul 4, 2026
10 checks passed
@steipete
steipete deleted the codex/pr-1820-project-cost-rollups branch July 4, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: project-level Codex token and cost rollups

1 participant