Skip to content

Add Spend by branch & worktree lens (project x branch attribution) - #1297

Closed
ozymandiashh wants to merge 4 commits into
getagentseal:mainfrom
ozymandiashh:zcode/goal-10-branch-worktree
Closed

ozymandiashh wants to merge 4 commits into
getagentseal:mainfrom
ozymandiashh:zcode/goal-10-branch-worktree

Conversation

@ozymandiashh

@ozymandiashh ozymandiashh commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Add Spend → By branch: select a project and inspect its AI spend per branch, then expand recorded worktrees and session contributions. Branch identity combines the canonical project id and branch name, so equal branch names in separate projects remain distinct. Worktree evidence comes from recorded historical working directories.

The CLI exposes branches --format json through the typed Electron bridge. Attribution carries the last observed branch across turns and preserves unknown metadata explicitly. The existing menubar branch contract remains intact. Desktop development uses the standard port 5173 in both Vite and the Electron launch command.

Validation: full root suite compared with upstream/main a1805393 (3,938 passed; the same four Node 26 DEP0205 stderr failures as main); full app suite (888 passed, four skipped); root/app typechecks and CLI/Electron/renderer builds. Branch fixtures cover equal branch names across projects, branch switches, pre-range carry, worktree evidence, missing metadata and token components. The main project-filter suite passes all nine tests on Node 24.

Branch metadata coverage follows what providers record. The feature does not infer branch value, merge state or branch-to-PR links. Details: docs/by-branch.md.

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.
@iamtoruk

Copy link
Copy Markdown
Member

Landed as #1319 (003854c) with your commits and authorship intact, rebased onto current main, plus one fix: getBranchSpend was the only main-process fetch without the Projects-pane filter, so a hidden project still showed its branches; now carries projectArgs() like every sibling, with the scoping test extended. Verified on a frozen range: 1,927 projects and 1,746 branch rows sum exactly to report totals, and every (project, branch) key matches the drill-through contributions to the cent. Branch-switching sessions are attributed per turn. flow-json byte-identical. One pre-existing leak it surfaced is tracked in #1321. Thank you.

@iamtoruk iamtoruk closed this Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants