feat(cost): auto-format duration fields as human-readable#164
Open
stephenleo wants to merge 1 commit into
Open
feat(cost): auto-format duration fields as human-readable#164stephenleo wants to merge 1 commit into
stephenleo wants to merge 1 commit into
Conversation
Render `$cship.cost.total_duration_ms` and `$cship.cost.total_api_duration_ms` as `45s` / `1m30s` / `2h15m` (or `750ms` for sub-second values) instead of raw millisecond integers. Mirrors starship's opinionated `cmd_duration` output — no new config flags. Threshold comparisons still operate on raw milliseconds, so existing `warn_threshold = 30000.0` configs keep working unchanged. Adds `total_duration` / `total_api_duration` as accepted aliases for the `_ms`-suffixed names, on both surfaces: format-string variables (via `|` in the dispatch match arm) and TOML config keys (via `#[serde(alias)]`). Once the rendered value is human-readable, the `_ms` suffix is misleading, so either spelling reads correctly. Closes #162. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Owner
Author
|
Wait for #153 as the intent might be duplicated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$cship.cost.total_duration_msand$cship.cost.total_api_duration_msas human-readable durations (45s,1m30s,2h15m, or750msfor sub-second) instead of raw millisecond integers. Mirrors starship's opinionatedcmd_durationoutput — no new config flags.$cship.cost.total_durationand$cship.cost.total_api_durationas accepted aliases for the_ms-suffixed names, on both surfaces: format-string variables and TOML config keys.warn_threshold = 30000.0configs keep working unchanged.Closes #162.
Breaking change
Users with a custom
format = "[$value ms]($style)"on either of the duration sub-fields will now see"45s ms". Migration is a one-character edit: drop the literalmsfrom the format string. CHANGELOG entry added under[Unreleased]calling this out explicitly.Design notes
format_duration_msuses integeru64arithmetic throughout — nof64, no decimal drift, truncation is intentional and matches starship's whole-second granularity.< 1000ms) keep ms precision so a fast 500ms response doesn't read as"0s".|pattern in the dispatch match — no duplicated logic.#[serde(alias = "...")]on the existing field — canonical Rust name staystotal_duration_ms, so no cascading code changes.Test plan
cargo fmt --check— cleancargo clippy --all-targets -- -D warnings— cleancargo test— 387 lib + 68 integration tests pass (added 11 new formatter tests, 2 dispatch-alias tests, 2 config-alias tests; updated 5 cost tests + 1 integration test for new format)cargo build --release— cleantotal_duration_ms = 45000→45stotal_duration_ms = 750→750ms(not0s)warn_threshold = 30000.0fires yellow ANSI on45s$cship.cost.total_lines_addedstill renders as156$cship.cost.total_duration_msand$cship.cost.total_durationproduce byte-identical output[cship.cost.total_duration_ms]and[cship.cost.total_duration]produce byte-identical warn-styled output🤖 Generated with Claude Code