Skip to content

feat(ai): Add --since, --until, and --by to cost report and roi #2193

Closed

Description

@dan-petty

Friction

devops ai cost report and devops ai cost roi take --days N (the last N days) only. On 2026-10-24 the owner asked for the local AI savings of the first three weeks of October (2026-10-01 to 2026-10-21), and the answer needed a script that copies the ledger, deletes the rows outside the range and calls SpendLedger.get_lifetime_report on the copy.

What should happen

devops ai cost report and devops ai cost roi take --since <date> and --until <date> (ISO dates or datetimes, UTC unless an offset is given), and --by day or --by week gives one row for each period, with requests, local tokens, actual spend, the local cost equivalent at the reference model, and the cloud spend avoided. --days stays as a short form of --since.

Acceptance criteria

  • devops ai cost report --since 2026-10-01 --until 2026-10-22 --by week --json gives three rows whose sums equal the report of the whole range, with a test on a ledger fixture.
  • The MCP tool ai_cost_report takes the same range.

Proposed design

Problem statement

The commands devops ai cost report and devops ai cost roi accept only --days N to select a time window. A person who needs a fixed date range, such as 2026-10-01 to 2026-10-21, must copy the ledger, delete rows outside the range, and call SpendLedger.get_lifetime_report on the copy. The commands need --since and --until for an explicit range, and --by day or --by week to group results into one row per period. The MCP tool ai_cost_report must accept the same range.

Acceptance criteria

  • Criterion 1: Running devops ai cost report --since 2026-10-01 --until 2026-10-22 --by week --json returns three rows whose column sums equal the ungrouped report of the same range.
    Verification: A test on a ledger fixture asserts that the sum of the three weekly rows equals the sum of the ungrouped report for the same date range.
  • Criterion 2: Running devops ai cost roi --since 2026-10-01 --until 2026-10-22 --by week --json returns one row per week with requests, local tokens, actual spend, local cost equivalent, and cloud spend avoided.
    Verification: A test on a ledger fixture asserts the column names and the per-week grouping of the ROI output.
  • Criterion 3: The flag --days N still works and is equivalent to --since set to today minus N days.
    Verification: A test asserts that --days 7 produces the same rows as --since with no --until.
  • Criterion 4: The MCP tool ai_cost_report accepts --since, --until, and --by with the same semantics as the CLI.
    Verification: A test in tests/test_fastmcp_contracts.py calls ai_cost_report with a date range and a grouping value, and asserts the returned rows match the CLI output for the same range.

Key questions

Open questions

  • What ledger method does the current --days path call? (missing verified source)
  • What columns appear in each grouped row? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-02: partly.
Tool: ccusage/ccusage (https://github.com/ccusage/ccusage), NOASSERTION, last activity 2026-11-02, maintained.

Activity

  1. added
    source/agent
    type/feature
    on Oct 24, 2026
  2. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/feature. The candidate proposes new features for AI cost reporting with date range and grouping options.
    • Priority: P2-Medium. The feature improves usability of existing AI cost reporting tools but is not critical for core functionality.
    • Value: Medium. The feature provides better flexibility in analyzing AI costs over specific time periods, which is valuable for planning and budgeting.
    • Effort: Medium. Implementing date range options and grouping requires modifying command-line parsing, date handling logic, and report generation code.
    • Related: fix(ai): the spend series exists at $0, a gateway call counts as local or hosted by the backend that served it, and the ledger exposition stops reusing the OTLP names #1631, which asks for a different change. Both items relate to AI cost reporting and spend ledger functionality, but the candidate adds date range and grouping features while item 1631 fixes issues with spend series exposition.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Refine cannot set this item to Ready at bb46660 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • What ledger method does the current --days path call? (missing verified source)
    • What columns appear in each grouped row? (missing verified source)
  4. added
    priority/p2-medium
    status/new
    value/medium
    effort/medium
    scope/ai
    on Oct 28, 2026
  5. devops-cli-service commented on Nov 2, 2026

    @devops-cli-service
    Contributor

    Alternatives check: partly

    Tool: ccusage/ccusage (https://github.com/ccusage/ccusage)

    • License: NOASSERTION
    • Last activity: 2026-11-02
    • Maintained: yes

    Covers:

    • Date-range selection for a cost report: --since and --until take explicit start and end dates and can be combined or used alone.
    • Period grouping as separate report commands (daily, weekly, monthly), i.e. one row per day, week or month.
    • Machine-readable per-period output via --json, with token counts and cost per period plus a summary of totals.
    • Cost computed from tokens when pre-calculated costs are absent (--mode calculate), and week-start control for weekly grouping.

    Lacks:

    • No reference-model "local cost equivalent" column and no "cloud spend avoided" or ROI comparison; it reports actual usage cost, not savings against a baseline model.
    • Reads coding-agent usage logs (Claude Code, Codex, OpenCode, etc.), not the project's own SpendLedger, so it cannot be dropped in as the ledger-backed devops ai cost report/roi implementation.
    • No ai_cost_report MCP tool with the CLI's range and grouping semantics, and no --days N short form matching the issue's spec.
    • Not a library/API the project can call from SpendLedger.get_lifetime_report; it is a separate CLI with its own data sources and output schema.

    Searches run:

    • CLI AI token cost report --since --until group by day week json
    • ccusage claude code usage cost report daily weekly monthly since until
    • ccusage daily report --since --until json output cost

    Sources:

    Checked on 2026-11-02. A person decides what this means for the item. The check changes no label and closes no issue.

  6. changed the title [-]feat(ai): devops ai cost report and roi take --since and --until and group by day or week[/-] [+]feat(ai): Add --since, --until, and --by to cost report and roi[/+] on Nov 6, 2026
  7. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 79 characters, and the limit is 60. The type and the scope stay.

    • Before: feat(ai): devops ai cost report and roi take --since and --until and group by day or week
    • After: feat(ai): Add --since, --until, and --by to cost report and roi
    • Source of the summary: the background model
  8. added
    status/in-review
    and removed
    status/new
    on Nov 9, 2026
  9. removed
    status/in-review
    on Nov 9, 2026
  10. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-09 21:49 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/aisource/agenttype/featurevalue/medium

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions