You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 29d792b
Browse filesBrowse the repository at this point in the historyBrowse files
Merge remote-tracking branch 'origin/main' into fix/opencode-since-until-adapter
Resolves the workspace split from #1428, which moved the files this branch
touches into separate crates:
- `date_utils` now lives in `ccusage-core`. The window helpers added here
(`date_within_range`, `date_range_bounds_ms`) are `pub` rather than
`pub(crate)`, because the opencode adapter that calls them is its own
crate now; `parse_compact_date` and `start_of_day_ms` stay private.
`parse_digits` keeps main's private, overflow-checked version.
- `filter_loaded_entries_by_date` moved from the claude adapter to
`ccusage-adapter-common`. Main's copy still inlined the date predicate,
so it now calls the shared `date_within_range` instead — the point of
collapsing the three copies in the first place.
- `opencode::has_data` follows the adapter crate's new `pub` surface.
Do not keep growing `main.rs` or single large adapter files. Use these
36
50
responsibility boundaries where practical:
37
51
38
-
-`adapter/<agent>/mod.rs` - public adapter surface and command wiring.
39
-
-`adapter/<agent>/paths.rs` - environment variables, defaults, and path discovery.
40
-
-`adapter/<agent>/parser.rs` - raw record parsing and token/model mapping.
41
-
-`adapter/<agent>/loader.rs` - file walking, SQLite reads, dedupe, and date filtering entry points.
42
-
-`adapter/<agent>/report.rs` - JSON/table row shaping when agent-specific.
43
-
- shared modules stay in `types.rs`, `summary.rs`, `output.rs`, `pricing.rs`, `progress.rs`, and `date_utils.rs`.
52
+
-`adapters/<agent>/src/lib.rs` - public adapter surface and command wiring.
53
+
-`adapters/<agent>/src/paths.rs` - environment variables, defaults, and path discovery.
54
+
-`adapters/<agent>/src/parser.rs` - raw record parsing and token/model mapping.
55
+
-`adapters/<agent>/src/loader.rs` - file walking, SQLite reads, dedupe, and date filtering entry points.
56
+
-`adapters/<agent>/src/report.rs` - JSON/table row shaping when agent-specific.
57
+
- shared modules stay in `ccusage-core` (`types.rs`, `summary.rs`, `output.rs`, `pricing.rs`, `progress.rs`, `date_utils.rs`) or in `ccusage-adapter-common` when they are about reading files or rendering the shared agent table.
58
+
- do not add a dependency from one adapter to another; move the shared part into `ccusage-adapter-common` instead.
44
59
45
-
Keep public `pub(crate)` surfaces narrow. Prefer moving tests with the code they exercise instead of leaving all Rust tests in `main.rs`.
60
+
Prefer moving tests with the code they exercise instead of leaving all Rust tests in `main.rs`.
46
61
47
62
When splitting large Rust modules or removing duplication, use the `reduce-similarities` skill, which runs `similarity-rs` for `.rs` files.
48
63
64
+
## Visibility
65
+
66
+
Inside this workspace `pub` is only for what another crate actually uses.
67
+
Everything else is `pub(crate)`, including items that other modules in the same
68
+
crate reach through a module chain.
69
+
70
+
`just hawk` runs [hawk](https://github.com/astral-sh/hawk) over the workspace and
71
+
reports `pub` items nothing outside their crate needs. Run it after adding a
72
+
crate and after widening a visibility. `rust/hawk.toml` lists the shipped entry
73
+
points; anything not reachable from them can be narrowed. Adding `--fix` to the
74
+
underlying `cargo hawk check` applies the narrowing.
75
+
76
+
hawk is not in nixpkgs, so the dev shell does not provide it. Install a prebuilt
77
+
release first:
78
+
79
+
```sh
80
+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/hawk/releases/latest/download/cargo-hawk-installer.sh | sh
81
+
```
82
+
83
+
It uses `rustc_private` and only runs on the toolchain it was built against,
84
+
which is why `rust-toolchain.toml` pins 1.97.1. It is experimental - its README
85
+
says it is "not intended for public consumption" - and no CI check runs it, so
86
+
read its findings as suggestions and confirm each one before narrowing.
87
+
49
88
## Pricing Embedding
50
89
51
90
TypeScript uses build/macro-time pricing snapshots. Rust should not rely on a manually edited `claude-pricing.json` as the only embedded source.
@@ -57,7 +96,11 @@ When changing pricing:
57
96
- For Nix builds, pass the locked LiteLLM `model_prices_and_context_window.json`
58
97
to `build.rs` through `CCUSAGE_PRICING_JSON_PATH`.
59
98
- For non-Nix Cargo builds, have `build.rs` read the same `litellm` revision from
60
-
`flake.lock` and fetch that pinned raw JSON at build time.
99
+
`flake.lock` and fetch that pinned raw JSON at build time. That download lives
100
+
behind the off-by-default `fetch-litellm-pricing` feature, because its rustls
101
+
stack is the most expensive build-dependency in the workspace: the dev shell
102
+
and every Nix package set `CCUSAGE_PRICING_JSON_PATH` instead, and only the
103
+
Windows release build enables the feature.
61
104
- Do not check generated LiteLLM pricing snapshots into the repository.
62
105
- Keep pricing JSON filtering and compacting in `build.rs` so runtime code loads
63
106
the generated build-time snapshot first, then built-in model overrides, then
if git diff --quiet -- rust/crates/ccusage-core/src/models-dev-pricing.json rust/crates/ccusage-adapter-codex/src/codex-auto-review-fallbacks.json; then
102
+
echo "models.dev pricing snapshots are unchanged; skipping PR."
Copy file name to clipboardExpand all lines: AGENTS.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,8 +41,11 @@ Check the nearest package-specific `AGENTS.md` before editing package code:
41
41
- Runtime libraries for bundled packages belong in `devDependencies` unless explicitly requested otherwise.
42
42
- When initializing this repository environment, run `direnv allow` so the pinned Nix dev shell is activated.
43
43
- Prefer tools provided by the Nix dev shell before falling back to ad hoc installs: `rg`, `fd`, `fzf`, `delta`, `dust`, `jq`, `gh`, `hyperfine`, `similarity`, `ast-grep`, `typos`, and `typos-lsp`. When a missing tool would be useful for repeated agent work in this repository, add it to `flake.nix`.
44
-
- The production CLI is Rust-first under `rust/crates/ccusage`. Put new runtime behavior there unless the work is specifically about npm packaging, generated schemas, docs tooling, or benchmark scripts.
45
-
- For Rust code, keep modules small, keep `pub(crate)` surfaces narrow, prefer fixture-backed parser/loader tests, and run cargo checks through the `just` recipes when possible.
44
+
- The production CLI is Rust-first under `rust/crates` and `rust/adapters`. Put source-specific
45
+
runtime behavior in `rust/adapters/<agent>` and shared behavior in
46
+
`ccusage-core` or `ccusage-adapter-common` unless the work is specifically about
47
+
npm packaging, generated schemas, docs tooling, or benchmark scripts.
48
+
- For Rust code, keep modules small, use `pub` only for what another crate uses and `pub(crate)` for everything else (`just hawk` reports the difference), prefer fixture-backed parser/loader tests, and run cargo checks through the `just` recipes when possible.
46
49
- TypeScript rules still apply to `.ts`, `.tsx`, `.js`, and `.jsx` package/tooling files. Use `typescript` there, especially `satisfies` and `as const satisfies` for typed literals.
47
50
- For TypeScript package code, use `logger.ts` instead of `console.log`, use `.ts` extensions for local imports, and avoid dynamic imports.
48
51
- After code changes, run `just fmt` when formatting may apply. Rely on git hooks and CI for covered checks; run `just typecheck` or `just test` manually when the change touches behavior, types, package code, or when hooks/CI do not cover the edited files. `just` is the single entry point for repo tasks (`just --list`); recipes route to the pnpm workspace or the Nix flake.
0 commit comments