Repository navigation
refactor(nix): derive package metadata from the npm manifest - #1506
Conversation
`package.nix` restated the name, description, homepage, license, and `mainProgram` that `apps/ccusage/package.json` already declares, so the two drifted: the manifest describes the CLI as "Analyze coding (agent) CLI token usage and costs from local data" while Nix dropped the parentheses, and nothing tied the Nix `mainProgram` to the manifest's `bin` entry. Import the published manifest and derive all of it, following the pattern in yusukebe/ax: `lib.getLicenseFromSpdxId` turns the SPDX string into a nixpkgs license, and `mainProgram` comes from the sole `bin` key. `ccusage-static` and `ccusage-darwin-x64` already build their `meta` from `config.packages.ccusage.meta`, so they inherit this too. `version` still comes from the root manifest. `rust/crates/ccusage/ build.rs` falls back to reading it when `CCUSAGE_VERSION` is unset, and `compiled_version_matches_release_package` asserts the compiled version matches it, so moving the Nix source would split the version's origin between the Nix and plain-cargo builds. tagpr bumps both manifests together. `meta.homepage` gains the `#readme` fragment the manifest carries. The URL resolves to the same page. Verified with `nix eval`: `pname`, `version`, `license.spdxId`, and `mainProgram` are unchanged, and `ccusage-darwin-x64` still inherits the license and `mainProgram`.
|
This run was cancelled 🛑 The workflow was cancelled before completion. Please check the link below for details. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
ccusage-guide | acf86b7 | Commit Preview URL Branch Preview URL |
Jul 27 2026, 11:18 PM |
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthrough
ChangesNix package metadata
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review Please pay particular attention to whether |
@ryoppippi I have started the AI code review. It will take a few minutes to complete. |
🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '=== Changed files and diff ==='
git diff --stat HEAD^ HEAD
git diff -- package.nix package.json apps/ccusage/package.json rust/crates/ccusage/build.rs
echo '=== Locate relevant version assertions and manifest reads ==='
rg -n -C 4 --glob '!node_modules/**' \
'CCUSAGE_VERSION|compiled_version_matches_release_package|readFile.*package\.json|importJSON|package\.json' \
package.nix package.json apps/ccusage/package.json rust 2>/dev/null || true
echo '=== package.nix structure ==='
ast-grep outline package.nix --items all || true
echo '=== package.nix relevant content ==='
cat -n package.nix
echo '=== Root and app manifests: selected metadata ==='
jq '{name, version, description, homepage, license, bin}' package.json
jq '{name, version, description, homepage, license, bin}' apps/ccusage/package.json
echo '=== Rust build script and matching test context ==='
build_rs=$(fd -a '^build\.rs$' rust/crates/ccusage | head -n 1 || true)
if [ -n "$build_rs" ]; then
cat -n "$build_rs"
fi
rg -n -C 8 --glob '!node_modules/**' 'compiled_version_matches_release_package' rust . 2>/dev/null || trueLength of output: 17156 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '=== Commit patch for package.nix ==='
git show --format=fuller --find-renames --find-copies HEAD -- package.nix
echo '=== Version synchronization configuration and manifest version references ==='
rg -n -C 4 --hidden \
-g '!node_modules/**' -g '!dist/**' -g '!build/**' \
'tagpr|apps/ccusage/package\.json|ccusage-monorepo|20\.0\.19|"version"' \
.github .release-please-manifest.json .release-please-config.json package.json apps/ccusage/package.json 2>/dev/null || true
echo '=== Nix metadata validations or consumers in repository ==='
rg -n -C 3 --hidden \
-g '!node_modules/**' -g '!dist/**' -g '!build/**' \
'meta\.homepage|homepage\s*=|mainProgram|lib\.getLicenseFromSpdxId' \
. 2>/dev/null || true
echo '=== Working tree / commit identity ==='
git status --short
git show -s --format='commit=%H%nparents=%P%nsubject=%s' HEADLength of output: 17757
The metadata derivation, SPDX license conversion, and ✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
package.nix (1)
143-143: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winValidate the single
binentry before usinghead.
builtins.attrNamessorts attribute names, whilebuiltins.headdoes not enforce that exactly one binary exists. A future second entry would silently select the lexicographically first binary and publish incorrectmainProgrammetadata; an empty entry would fail less clearly. Assert the manifest’s stated single-bin contract before selecting the key.Proposed fix
- mainProgram = builtins.head (builtins.attrNames cliPackageJson.bin); + mainProgram = + let + binNames = builtins.attrNames cliPackageJson.bin; + in + assert lib.assertMsg (builtins.length binNames == 1) + "apps/ccusage/package.json must declare exactly one bin entry"; + builtins.head binNames;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@package.nix` at line 143, Update the mainProgram assignment to validate that cliPackageJson.bin contains exactly one entry before selecting its name with builtins.head; preserve the existing single-entry behavior and fail clearly for empty or multiple binary entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@package.nix`:
- Line 143: Update the mainProgram assignment to validate that
cliPackageJson.bin contains exactly one entry before selecting its name with
builtins.head; preserve the existing single-entry behavior and fail clearly for
empty or multiple binary entries.
ccusage performance comparisonPR SHA: This compares the Rust PR release binary against the configured base package on the same CI runner. Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |
ccusage performance comparisonPR SHA: This compares the PR package against the configured base package on the same CI runner. Package runtime diagnosticsCompares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself. Fixtures: Claude
Committed fixture performanceCommitted small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage. Fixtures: Claude
Large real-world-shaped fixture performanceGenerated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures. Fixtures: Claude
Artifact size
Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees. |

package.nixrestated the name, description, homepage, license, andmainProgramthatapps/ccusage/package.jsonalready declares. The two had already drifted — the manifest says "Analyze coding (agent) CLI token usage and costs from local data" while Nix dropped the parentheses — and nothing tied the NixmainProgramto the manifest'sbinentry.What Changed
apps/ccusage/package.jsonand derivepname,meta.description,meta.homepage,meta.license(vialib.getLicenseFromSpdxId), andmeta.mainProgram(the solebinkey) from it, following the pattern in yusukebe/ax.builtins.fromJSON (builtins.readFile ...)tolib.importJSON.ccusage-staticandccusage-darwin-x64already build theirmetafromconfig.packages.ccusage.meta, so they inherit this with no change.Why version stays on the root manifest
rust/crates/ccusage/build.rsfalls back to reading the rootpackage.jsonwhenCCUSAGE_VERSIONis unset, andcompiled_version_matches_release_packageasserts the compiled version matches it. Moving the Nix source would split the version's origin between the Nix build and a plaincargo build. tagpr bumps both manifests together.Behaviour change
meta.homepagegains the#readmefragment the manifest carries (https://github.com/ccusage/ccusage#readme). Same page; happy to strip it or drop it frompackage.jsonif preferred.Testing
nix evalon the resulting derivations:.#ccusage:pname=ccusage,version=20.0.19,license.spdxId=MIT,mainProgram=ccusage— all unchanged..#ccusage-darwin-x64: still inherits the license andmainProgram.nixfmt --check package.nixpasses.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is enabled.Summary by cubic
Derive
ccusageNix package metadata fromapps/ccusage/package.jsonto keep name, description, homepage, license, andmainProgramin sync. Version still comes from the rootpackage.jsonto match the Rust build.apps/ccusage/package.jsonvialib.importJSONand setpname,meta.description,meta.homepage,meta.license(withlib.getLicenseFromSpdxId), andmeta.mainProgram(from the solebinkey).package.jsonwithlib.importJSONinstead ofbuiltins.fromJSON.ccusage-staticandccusage-darwin-x64inherit the updatedmetawithout changes.meta.homepagenow includes the#readmefragment from the manifest.Written for commit acf86b7. Summary will update on new commits.
Summary by CodeRabbit