Repository navigation
Add period-vs-period comparison (Compare periods) with contribution drill-down - #1296
ozymandiashh wants to merge 5 commits into
Conversation
…f engine Add src/period-diff.ts: pure period-vs-period difference engine. Totals come from the shared buildPeriodData rules; contributions per project and per model carry status new/gone/up/down/flat with pct=null at A=0 (labeled New, never an infinite percentage); normalized views per day and per 100 calls print their denominators; day arithmetic walks local midnights so DST and month boundaries count calendar days. historyBasis cross-checks the durable daily cache and reports aggregate-only carried days separately instead of force-reconciling them into the totals. diffSessions joins the drill-down on the canonical session identity (provider + project path + sessionId), attributing the model's own slice for the model lens. New command: compare-periods --format json|sessions with explicit --from-a/--to-a/--from-b/--to-b (local YYYY-MM-DD, validated loudly) defaulting to the last seven complete days vs the seven before, plus --provider and the existing --project/--exclude filtering. Range slicing reuses parseAllSessions' call-granularity behavior, so a session straddling the boundary contributes to each side by its own calls. Tests: engine fixtures including the X/Y/Z acceptance reconciliation, A=0/B=0, unequal lengths, DST and month walks, carried history, a real-parse boundary session split by call and joined back into one drill-down row, and CLI runs on a temp HOME fixture.
Two bridge channels follow the existing envelope + argv-validation pattern: codeburn:getPeriodCompare spawns compare-periods --format json with two REQUIRED local YYYY-MM-DD range pairs (validated per range), and codeburn:getPeriodCompareSessions spawns the sessions drill-down for one project/model contribution key. Contribution keys ride the --key VALUE position, so a dash-leading slug (Claude sanitizes /work/pricing to -work-pricing) passes vContributionKey where vToken would wrongly reject it. Preload and the renderer CodeburnBridge types mirror the two calls.
New sidebar section 'periods' (Compare periods, shortcut 9) rendering sections/PeriodCompare.tsx: preset last-7-complete-days vs prior 7 or two custom calendars with a swap control; range meta shows both spans, the duration delta and any overlap; totals, normalized per-day and per-100-calls tables (denominators printed, zero denominators render as em dash); project and model contribution lenses with New/Gone badges and click-to-inspect session drill-down joined across A and B; coverage block for unpriced models and aggregate-only carried history. A/B selection, lens and view persist in localStorage so returning to the screen keeps the selection. Navigation adapter until the goal-8 navigation lands: onInspectRange opens the existing Sessions section scoped to the requested range via the app's custom-range state; the Overview entry card links here. Renderer styling follows the existing panel/table conventions. Includes component tests (fixture report, New/Gone labels, per-100-calls recomputation with zero-call sides, persistence across remounts, lens switching) and user documentation at docs/compare-periods.md.
|
Landed as #1323 (2373f55) with your commits and authorship intact, rebased onto current main, plus fixes found on real data: both new fetches now carry the Projects-pane filter, compare-periods --format sessions honours --project/--exclude, the stub inspectRange (which no longer compiled after the drill-through landed) is replaced by the real navigation with project and model filters, invalid dates get the app's friendly error instead of a stack trace, and the Totals card discloses carried history inline. Verified: B minus A equals the diff for every component on frozen ranges, lenses reconcile to 1e-12, totals match models --format json to 2e-12 and the history figure matches report to the digit, drill-down rows reconcile exactly, and every existing command is byte-identical. Thank you. |
…rrors Rebase fixes on top of getagentseal#1296. - App.tsx shipped a stub inspectRange calling a setCustomRange that no longer exists after getagentseal#1316. Replaced with the real navigation: commitNav to Sessions with the clicked side's range AND projectFilters/modelFilters for the contribution key, so the drill-through lands on the population the row describes instead of the whole range. - getPeriodCompare and getPeriodCompareSessions carried no projectArgs(), so a saved project filter did not scope either fetch (getagentseal#1307). Added, and the "scopes every fetch" main-process test now covers both channels. - compare-periods --format sessions ignored --project/--exclude, so a drill-down could surface a session from a hidden project. It now filters like the report. - A bad --from-a/--to-a printed a raw stack trace: parseDateRangeFlags throws and the null check could never fire. Wrapped in the same try/catch every other date-flag command uses. - Totals card now says inline how much daily history has no session detail behind it. On a machine with aged-off sources the detail-only total is far below report/status for the same range; the Coverage card alone was three cards away from the number it qualifies.
Add Compare periods with explicit A/B ranges, project and model contributions, and session detail behind each contribution. Differences use B minus A; cost per day and cost per 100 calls use each side's own denominator. Unknown pricing, unavailable denominators and aggregate-only retained history are disclosed separately.
Project contributions and session drill-down use canonical project identities, so two projects with the same display name retain both costs. Daily normalization recomputes the percentage and direction: $100 over one day versus $160 over ten days displays $100/day versus $16/day, a decrease of 84%. Session-detail cache keys include both ranges, so changing B fetches fresh details after remount.
Validation: full root suite compared with upstream/main
a1805393(3,956 passed; the same four Node 26 DEP0205 stderr failures as main, zero additional failures); full Electron/renderer suite (893 passed, four skipped); root/app typechecks and CLI/Electron/renderer builds. Concrete fixtures exercise duplicate project labels, unequal durations, and changing B from $160 to $250 with two detail fetches. The main project-filter suite passes all nine tests on Node 24.The Sessions navigation adapter passes the selected date range. Cross-feature integration with the separate drill-through PR remains a separate step.