mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-28 09:02:24 +00:00
fix: key the daily project split per real path, not per label (#1679)
A project label can span several paths: every Claude session started from the home folder shares -Users-<name>, while its cwd puts it in a different project. The day rollup keyed by label kept the first path it saw, so a rooted --project headline took the whole label bucket on some days and missed it on others. Key per (label, path), read old label-keyed days unchanged, bump the daily cache to v67.
This commit is contained in:
parent
1284290743
commit
01705cf8f2
5 changed files with 86 additions and 17 deletions
|
|
@ -323,7 +323,12 @@ import type { DateRange, ProjectSummary } from './types.js'
|
|||
// v66: Codex fork replay bursts drop only records found in the parent rollout;
|
||||
// burst records the parent kept only inside a running total now count. Calls
|
||||
// only rise, so no PENDING_REDERIVE_PROVIDER_VERSIONS entry is needed.
|
||||
export const DAILY_CACHE_VERSION = 66
|
||||
// v67: a day's project split is keyed per (label, path) instead of per label,
|
||||
// which kept only the first path a label showed that day and handed the whole
|
||||
// label (e.g. every home-folder Claude session) to whichever project owned it.
|
||||
// Day and provider totals are unchanged, only the split inside them moves, so
|
||||
// no PENDING_REDERIVE_PROVIDER_VERSIONS entry is needed.
|
||||
export const DAILY_CACHE_VERSION = 67
|
||||
const MIN_SUPPORTED_VERSION = 28
|
||||
|
||||
/// Providers whose per-day CALL COUNT means something different at
|
||||
|
|
@ -403,6 +408,22 @@ export type CategoryDayStats = { turns: number; cost: number; savingsUSD: number
|
|||
/// mapping are gone.
|
||||
export type ProjectDayStats = { cost: number; calls: number; savingsUSD: number; sessions: number; path?: string }
|
||||
|
||||
/// One project label can span several real paths (every Claude session started
|
||||
/// from the home folder shares `-Users-<name>`), so since v67 a day's project
|
||||
/// split is keyed per (label, path). Days written earlier key by label alone
|
||||
/// and keep one path for the whole label; they stay readable through
|
||||
/// projectDayIdentity.
|
||||
const PROJECT_KEY_SEP = '\u0000'
|
||||
|
||||
export function projectDayKey(project: string, path?: string): string {
|
||||
return path ? `${project}${PROJECT_KEY_SEP}${path}` : project
|
||||
}
|
||||
|
||||
export function projectDayIdentity(key: string, stats: ProjectDayStats): ProjectFilterTarget & { projectPath: string } {
|
||||
const sep = key.indexOf(PROJECT_KEY_SEP)
|
||||
return { project: sep === -1 ? key : key.slice(0, sep), projectPath: stats.path ?? '' }
|
||||
}
|
||||
|
||||
export type ProviderDaySlice = {
|
||||
calls: number
|
||||
cost: number
|
||||
|
|
@ -1779,8 +1800,8 @@ export function cachedProjectIdentities(cache: DailyCache, startStr: string, end
|
|||
const identities: ProjectFilterTarget[] = []
|
||||
for (const day of cache.days) {
|
||||
if (day.date < startStr || day.date > endStr || !day.projects) continue
|
||||
for (const [name, stats] of Object.entries(day.projects)) {
|
||||
identities.push({ project: name, projectPath: stats.path ?? '' })
|
||||
for (const [key, stats] of Object.entries(day.projects)) {
|
||||
identities.push(projectDayIdentity(key, stats))
|
||||
}
|
||||
}
|
||||
return identities
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { DailyEntry, ProjectDayStats, ProviderDaySlice } from './daily-cache.js'
|
||||
import { projectDayKey, type DailyEntry, type ProjectDayStats, type ProviderDaySlice } from './daily-cache.js'
|
||||
import type { PeriodData } from './menubar-json.js'
|
||||
import { CATEGORY_LABELS, type ProjectSummary, type TaskCategory } from './types.js'
|
||||
import { behavioralCallWeight, isBehavioralTurn } from './behavioral-weight.js'
|
||||
|
|
@ -67,14 +67,14 @@ export function aggregateProjectsIntoDays(projects: ProjectSummary[], dateKeyFn:
|
|||
}
|
||||
const ensureProject = (holder: { projects?: Record<string, ProjectDayStats> }, project: string, path?: string): ProjectDayStats => {
|
||||
const projects = (holder.projects ??= {})
|
||||
const key = projectDayKey(project, path)
|
||||
// defineProperty so a project directory named "__proto__" becomes an own
|
||||
// key instead of mutating the prototype link.
|
||||
let p = Object.hasOwn(projects, project) ? projects[project] : undefined
|
||||
let p = Object.hasOwn(projects, key) ? projects[key] : undefined
|
||||
if (!p) {
|
||||
p = { cost: 0, calls: 0, savingsUSD: 0, sessions: 0 }
|
||||
Object.defineProperty(projects, project, { value: p, enumerable: true, writable: true, configurable: true })
|
||||
p = { cost: 0, calls: 0, savingsUSD: 0, sessions: 0, ...(path ? { path } : {}) }
|
||||
Object.defineProperty(projects, key, { value: p, enumerable: true, writable: true, configurable: true })
|
||||
}
|
||||
if (!p.path && path) p.path = path
|
||||
return p
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import { scanAndDetect } from './optimize.js'
|
|||
import { callBillableOutputTokens, sessionBillableOutput, sessionBillableOutputTokens, inferSessionProvider } from './session-output.js'
|
||||
import { getDateRange } from './cli-date.js'
|
||||
import { activityStreak } from './streak.js'
|
||||
import { getDaysInRange, ensureCacheHydrated, loadDailyCache, cachedProjectIdentities, emptyCache, mergeDayEntries, BACKFILL_DAYS, toDateString, type DailyCache, type DailyEntry, type ProjectDayStats, type ProviderDaySlice } from './daily-cache.js'
|
||||
import { getDaysInRange, ensureCacheHydrated, loadDailyCache, cachedProjectIdentities, projectDayIdentity, emptyCache, mergeDayEntries, BACKFILL_DAYS, toDateString, type DailyCache, type DailyEntry, type ProjectDayStats, type ProviderDaySlice } from './daily-cache.js'
|
||||
import { buildGranularHistory } from './granular-history.js'
|
||||
import { spendProjectIdentity } from './spend-flow.js'
|
||||
import { AGGREGATE_ONLY_PROVIDER, excludeAggregateOnlyProjects, excludesAggregateOnlyProviders } from './parser.js'
|
||||
|
|
@ -602,7 +602,7 @@ function sumMatchingProjects(
|
|||
): { cost: number; calls: number; savingsUSD: number; sessions: number; projects: Record<string, ProjectDayStats>; matched: number } {
|
||||
const out = { cost: 0, calls: 0, savingsUSD: 0, sessions: 0, projects: {} as Record<string, ProjectDayStats>, matched: 0 }
|
||||
for (const [name, p] of Object.entries(projects)) {
|
||||
if (!matches({ project: name, projectPath: p.path ?? '' })) continue
|
||||
if (!matches(projectDayIdentity(name, p))) continue
|
||||
out.cost += p.cost
|
||||
out.calls += p.calls
|
||||
out.savingsUSD += p.savingsUSD ?? 0
|
||||
|
|
@ -1419,7 +1419,8 @@ export function buildPayloadProjects(
|
|||
}
|
||||
if (cacheDays) {
|
||||
for (const d of cacheDays) {
|
||||
for (const [name, p] of Object.entries(d.projects ?? {})) {
|
||||
for (const [key, p] of Object.entries(d.projects ?? {})) {
|
||||
const name = projectDayIdentity(key, p).project
|
||||
if (p.path) {
|
||||
const id = spendProjectIdentity({ project: name, projectPath: p.path }).id
|
||||
let byId = knownBySlug.get(name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue