Repository navigation
Add Spend by branch & worktree lens (project x branch attribution) - #1319
Merged
Merged
Conversation
Spend per canonical project x branch, keyed by the project identity the spend-flow and By project views already use, so identical branch names in different projects never merge. Reuses the aggregateByBranch rules: last-seen branch carried forward across turns (the parser resolves the carry across a range boundary from pre-range evidence), only ever-branched sessions participate, and turns before a session's first branch stay an explicit Unknown row. Rows carry cost, behavioral calls, token components, distinct sessions (identity-based, rows overlap), activity window, per-session contributions, recorded worktree evidence (historical working directory, never today's checkout), and a coverage split: known / Unknown / no-branch-data sources. Same --period/--provider/--from/--to/--project/--exclude semantics as spend --format flow-json. docs/by-branch.md documents the lens.
New getBranchSpend bridge channel (codeburn:getBranchSpend) spawning 'spend --format branch-json' with the same period/provider/range flags and validation as the other first-click reports, plus background-priority prefetch handling. The renderer keeps the typed contract in lib/types.ts. BranchBreakdown panel: project picker (auto top project, explicit All projects view labeled project/branch), expandable branch rows with token components, worktree evidence and per-session contributions, a real session inspect detail, and the coverage note (known / Unknown / no-branch-data, identity-based distinct sessions). Reuses ListRow/Panel/Dropdown/stale-safe usePolled memo keys; selection is derived so a refresh or a vanished project falls back instead of mixing data.
The default 5173 collides with parallel CodeBurn worktree sessions sharing one machine. strictPort stays on so a busy port fails loudly instead of silently drifting; VITE_DEV_SERVER_URL follows the same port in the dev script. Note the port does NOT isolate the Electron userData profile — parallel sessions must still run the app one at a time.
getBranchSpend was the only data fetch in createBridgeHandlers without projectArgs(), so a project hidden by the Projects pane filter still showed its branches in the Spend > By branch lens. Extends the existing "scopes every fetch" test to cover the channel.
This was referenced Sep 12, 2026
iamtoruk
added a commit
that referenced
this pull request
Sep 12, 2026
…w flags Rebased on main, which since gained #1307, #1316 and #1319. - Delete app/renderer/lib/sampleNavigation.ts. It was a placeholder for a registry that never landed: #1316 ships drill-through as an onInvestigate callback prop plus NavState. The sample rows now call it, threaded from App.tsx through Compare, and open the owning session for real. - Give a CohortObservation the provider/project/session triple the sessions report keys rows by (inferSessionProvider, session.project || project.project), so a sample resolves to exactly one session row. Without it a cohort sample could not build sessionRowKey at all. - Carry projectArgs() on both cohort spawns, per #1307. The saved project filter now scopes the facet query and the report; --project-id still narrows within it. Extended the scopes-every-fetch test to cover both. - Allow --from, --to, --category and --project-id on compare in SERVE_OPTIONS. Verified over stdio: before, every cohort request but the bare facet query came back "command not served" and fell back to a spawn. - Catch the invalid-date throw on compare like report does, instead of an unhandled UsageQueryError stack trace. - Drop the unrelated CODEBURN_USER_DATA_DIR hunk in bootstrap().
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.
Supersedes #1297. All feature work by @ozymandiashh; rebased onto main (past #1307, #1316) with one correctness fix on top.
Rebase
Clean, zero conflicts. #1307 and #1316 touched the same files but not the same lines.
Fix on top
codeburn:getBranchSpendwas the only data fetch increateBridgeHandlerswithoutprojectArgs(), so a project hidden by the Projects pane filter still showed its branches in the lens. Added it, and extended the existing "scopes every fetch" test to cover the channel. Removing the call again fails that test.Real-data proof
Frozen range 2026-08-15..2026-09-05, 1927 projects, 1746 branch rows.
Math, deltas to 6dp:
totalCosttotalCostvsreport --format jsoncostsessionRowsvs branch costworktreesvs branch costIdentity is one notion, not two:
src/branch-spend.ts:339andsrc/session-contributions.ts:171both key the project throughspendProjectIdentity. Cross-checking branch-json againstsessions --format json --contributionson the same range, every one of the 1746(projectId, branch)keys matches to 0.000000. The 266 keys present only in contributions are all null-branch and total $397.528303, exactlytotals.noBranchDataCost.Branch-switching sessions are attributed per turn, not to the last branch: the carry-forward rule in
src/branch-spend.ts:234is identical tosrc/session-contributions.ts:111. 20 real multi-branch sessions in range; the largest splits $2119.88 across 47 branches.Worktrees fold into the parent project through the parser's canonical cwd;
workingDirectorystays the raw historical path as worktree evidence. Sessions with no branch anywhere go to the explicit coverage bucket, never relabeled.Contract
spend --format jsonstill rejected:unknown format "json". Valid values: flow-json, branch-json.Additive:
spend --format flow-jsonbyte-identical main vs this branch on two frozen ranges (2026-07-01..07-11 sha 7dcbca97, 2026-08-01..08-20 sha 743d3738).serve --stdioneeds no allowlist change;SERVE_OPTIONS.spendalready keys on option names. Verified live over stdio with--project,--exclude,--providerand a custom range, all ok.Privacy
No new egress. branch-json is CLI and IPC only, never enters
MenubarPayload. On a real payload, every worktree path is stripped bysanitizeForSharingand by MCPredactProjectNames.Pre-existing, out of scope here:
current.byBranch[].branchsurvives both (landed in #788), so branch names already leave the machine.Tests
Root:
tsc --noEmitclean, 4014 passed / 5 skipped, 296 files.App:
typecheckclean, 928 passed / 27 failed. Same 27 fail on main (920 passed there), all localStorage-environment failures in usePolled and overviewSnapshot.Mutation: breaking the canonical project identity in the branch key, relabeling the Unknown branch, and dropping
projectArgs()each fail a test.Perf
Lifetime on this machine, warm: flow-json 2.58s / 4.6 KB, branch-json 2.70s / 4.07 MB. CPU is a wash; the payload is 883x. JSON.parse of the 4 MB payload is 9ms.
Follow-ups, not blocking
codeburn.assignDistinguishingProjectLabelsinsrc/spend-flow.ts:68already solves this for the flow lens.branchFilters(project, branch)atapp/renderer/lib/investigation.ts:123is already there and has no caller;BranchBreakdownis the only component inSpend.tsxnot handedonInvestigate.BranchBreakdownmounts unconditionally in the Spend tab, so every visit spawns a branch-json run.