tokenusage-cli 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/THIRD_PARTY_NOTICES.md +17 -2
- package/package.json +4 -4
- package/src/commands/reconcile.js +10 -5
- package/src/commands/status.js +4 -0
- package/src/lib/cursor-config.js +5 -1
- package/src/lib/deepseek-limits.js +280 -0
- package/src/lib/deepseek-status.js +157 -0
- package/src/lib/doctor.js +50 -0
- package/src/lib/grok-limits.js +40 -1
- package/src/lib/ingest-sanitize.js +9 -0
- package/src/lib/pricing/curated-overrides.json +627 -0
- package/src/lib/pricing/index.js +16 -0
- package/src/lib/pricing-coverage.js +205 -0
- package/src/lib/provider-api-key-store.js +111 -0
- package/src/lib/provider-status.js +14 -2
- package/src/lib/qoder-limits.js +4 -1
- package/src/lib/rollout.js +286 -58
- package/src/lib/session-analytics.js +52 -2
- package/src/lib/upload-queue.js +4 -1
- package/src/lib/usage-limits.js +536 -22
package/src/lib/rollout.js
CHANGED
|
@@ -778,7 +778,7 @@ async function parseRolloutIncremental({
|
|
|
778
778
|
}
|
|
779
779
|
}
|
|
780
780
|
|
|
781
|
-
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets });
|
|
781
|
+
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets });
|
|
782
782
|
const projectBucketsQueued = projectEnabled
|
|
783
783
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
784
784
|
: 0;
|
|
@@ -1318,7 +1318,7 @@ async function parseClaudeIncremental({
|
|
|
1318
1318
|
}
|
|
1319
1319
|
}
|
|
1320
1320
|
|
|
1321
|
-
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets });
|
|
1321
|
+
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets });
|
|
1322
1322
|
const projectBucketsQueued = projectEnabled
|
|
1323
1323
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
1324
1324
|
: 0;
|
|
@@ -1493,7 +1493,7 @@ async function parseGeminiIncremental({
|
|
|
1493
1493
|
}
|
|
1494
1494
|
}
|
|
1495
1495
|
|
|
1496
|
-
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets });
|
|
1496
|
+
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets });
|
|
1497
1497
|
const projectBucketsQueued = projectEnabled
|
|
1498
1498
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
1499
1499
|
: 0;
|
|
@@ -1644,7 +1644,7 @@ async function parseOpencodeIncremental({
|
|
|
1644
1644
|
}
|
|
1645
1645
|
}
|
|
1646
1646
|
|
|
1647
|
-
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets });
|
|
1647
|
+
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets });
|
|
1648
1648
|
const projectBucketsQueued = projectEnabled
|
|
1649
1649
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
1650
1650
|
: 0;
|
|
@@ -2005,7 +2005,7 @@ async function parseOpenclawIncremental({
|
|
|
2005
2005
|
}
|
|
2006
2006
|
}
|
|
2007
2007
|
|
|
2008
|
-
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets });
|
|
2008
|
+
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets });
|
|
2009
2009
|
const projectBucketsQueued = projectEnabled
|
|
2010
2010
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
2011
2011
|
: 0;
|
|
@@ -2655,11 +2655,14 @@ async function parseRolloutRecords({
|
|
|
2655
2655
|
projectState,
|
|
2656
2656
|
event.projectKey,
|
|
2657
2657
|
source,
|
|
2658
|
+
event.model,
|
|
2658
2659
|
event.bucketStart,
|
|
2659
2660
|
event.projectRef,
|
|
2660
2661
|
);
|
|
2661
2662
|
addTotals(projectBucket.totals, event.delta);
|
|
2662
|
-
projectTouchedBuckets.add(
|
|
2663
|
+
projectTouchedBuckets.add(
|
|
2664
|
+
projectBucketKey(event.projectKey, source, event.model, event.bucketStart),
|
|
2665
|
+
);
|
|
2663
2666
|
}
|
|
2664
2667
|
eventsAggregated += 1;
|
|
2665
2668
|
}
|
|
@@ -2900,8 +2903,8 @@ async function parseRolloutRecords({
|
|
|
2900
2903
|
|
|
2901
2904
|
const bucket = getHourlyBucket(hourlyState, source, model, bucketStart);
|
|
2902
2905
|
addTotals(bucket.totals, delta);
|
|
2903
|
-
//
|
|
2904
|
-
//
|
|
2906
|
+
// Priority subsets annotate per-model rate calculations, so both the
|
|
2907
|
+
// aggregate and the (now model-dimensioned) project bucket carry them.
|
|
2905
2908
|
if (isPriorityServiceTier(serviceTier)) addPriorityUsage(bucket.totals, delta);
|
|
2906
2909
|
touchedBuckets.add(bucketKey(source, model, bucketStart));
|
|
2907
2910
|
if (currentProjectKey && projectState && projectTouchedBuckets) {
|
|
@@ -2909,11 +2912,13 @@ async function parseRolloutRecords({
|
|
|
2909
2912
|
projectState,
|
|
2910
2913
|
currentProjectKey,
|
|
2911
2914
|
source,
|
|
2915
|
+
model,
|
|
2912
2916
|
bucketStart,
|
|
2913
2917
|
currentProjectRef,
|
|
2914
2918
|
);
|
|
2915
2919
|
addTotals(projectBucket.totals, delta);
|
|
2916
|
-
|
|
2920
|
+
if (isPriorityServiceTier(serviceTier)) addPriorityUsage(projectBucket.totals, delta);
|
|
2921
|
+
projectTouchedBuckets.add(projectBucketKey(currentProjectKey, source, model, bucketStart));
|
|
2917
2922
|
}
|
|
2918
2923
|
eventsAggregated += 1;
|
|
2919
2924
|
}
|
|
@@ -3219,11 +3224,12 @@ async function parseClaudeFile({
|
|
|
3219
3224
|
projectState,
|
|
3220
3225
|
projectKey,
|
|
3221
3226
|
source,
|
|
3227
|
+
model,
|
|
3222
3228
|
bucketStart,
|
|
3223
3229
|
projectRef,
|
|
3224
3230
|
);
|
|
3225
3231
|
addTotals(projectBucket.totals, delta);
|
|
3226
|
-
projectTouchedBuckets.add(projectBucketKey(projectKey, source, bucketStart));
|
|
3232
|
+
projectTouchedBuckets.add(projectBucketKey(projectKey, source, model, bucketStart));
|
|
3227
3233
|
}
|
|
3228
3234
|
eventsAggregated += 1;
|
|
3229
3235
|
}
|
|
@@ -3340,11 +3346,14 @@ async function parseGeminiFile({
|
|
|
3340
3346
|
projectState,
|
|
3341
3347
|
projectKey,
|
|
3342
3348
|
source,
|
|
3349
|
+
projectModel,
|
|
3343
3350
|
bucketStart,
|
|
3344
3351
|
projectRef,
|
|
3345
3352
|
);
|
|
3346
3353
|
addTotals(projectBucket.totals, projectDelta);
|
|
3347
|
-
projectTouchedBuckets.add(
|
|
3354
|
+
projectTouchedBuckets.add(
|
|
3355
|
+
projectBucketKey(projectKey, source, projectModel, bucketStart),
|
|
3356
|
+
);
|
|
3348
3357
|
}
|
|
3349
3358
|
projectTotals = currentTotals;
|
|
3350
3359
|
}
|
|
@@ -3494,11 +3503,12 @@ async function parseOpencodeMessageFile({
|
|
|
3494
3503
|
projectState,
|
|
3495
3504
|
projectKey,
|
|
3496
3505
|
source,
|
|
3506
|
+
model,
|
|
3497
3507
|
bucketStart,
|
|
3498
3508
|
projectRef,
|
|
3499
3509
|
);
|
|
3500
3510
|
addTotals(projectBucket.totals, delta);
|
|
3501
|
-
projectTouchedBuckets.add(projectBucketKey(projectKey, source, bucketStart));
|
|
3511
|
+
projectTouchedBuckets.add(projectBucketKey(projectKey, source, model, bucketStart));
|
|
3502
3512
|
}
|
|
3503
3513
|
return {
|
|
3504
3514
|
messageKey,
|
|
@@ -3510,16 +3520,134 @@ async function parseOpencodeMessageFile({
|
|
|
3510
3520
|
};
|
|
3511
3521
|
}
|
|
3512
3522
|
|
|
3513
|
-
|
|
3514
|
-
|
|
3523
|
+
// Contract v2 (2026-11-03): hourly rows carry project_key. The hourly bucket
|
|
3524
|
+
// still owns the aggregate for (source, model, hour); a project bucket holds
|
|
3525
|
+
// the attributed subset for the same key. Split mode writes one row per
|
|
3526
|
+
// project plus a residual row under project_key "" (docs/cli-contract.md
|
|
3527
|
+
// §2.4 "project attribution"), so the rows add up to the aggregate and
|
|
3528
|
+
// nothing is double counted. Only model-dimensioned buckets take part: legacy
|
|
3529
|
+
// three-part buckets (project|source|hour) cannot be matched to a model and
|
|
3530
|
+
// stay inside the residual.
|
|
3531
|
+
const UNATTRIBUTED_PROJECT_KEY = "";
|
|
3532
|
+
|
|
3533
|
+
function indexProjectBucketsByGroup(projectState) {
|
|
3534
|
+
const index = new Map();
|
|
3535
|
+
const buckets = projectState?.buckets;
|
|
3536
|
+
if (!buckets || typeof buckets !== "object") return index;
|
|
3537
|
+
for (const bucket of Object.values(buckets)) {
|
|
3538
|
+
if (!bucket || typeof bucket !== "object" || !bucket.totals) continue;
|
|
3539
|
+
if (typeof bucket.hour_start !== "string" || !bucket.hour_start) continue;
|
|
3540
|
+
if (typeof bucket.model !== "string" || !bucket.model) continue;
|
|
3541
|
+
if (typeof bucket.project_key !== "string" || !bucket.project_key) continue;
|
|
3542
|
+
const source = normalizeSourceInput(bucket.source) || DEFAULT_SOURCE;
|
|
3543
|
+
const model = normalizeModelInput(bucket.model) || DEFAULT_MODEL;
|
|
3544
|
+
const groupKey = groupBucketKey(source, bucket.hour_start);
|
|
3545
|
+
let byModel = index.get(groupKey);
|
|
3546
|
+
if (!byModel) {
|
|
3547
|
+
byModel = new Map();
|
|
3548
|
+
index.set(groupKey, byModel);
|
|
3549
|
+
}
|
|
3550
|
+
let projects = byModel.get(model);
|
|
3551
|
+
if (!projects) {
|
|
3552
|
+
projects = new Map();
|
|
3553
|
+
byModel.set(model, projects);
|
|
3554
|
+
}
|
|
3555
|
+
projects.set(bucket.project_key, bucket);
|
|
3556
|
+
}
|
|
3557
|
+
return index;
|
|
3558
|
+
}
|
|
3559
|
+
|
|
3560
|
+
function totalsRowFields(totals) {
|
|
3561
|
+
return {
|
|
3562
|
+
input_tokens: totals.input_tokens,
|
|
3563
|
+
cached_input_tokens: totals.cached_input_tokens,
|
|
3564
|
+
cache_creation_input_tokens: totals.cache_creation_input_tokens,
|
|
3565
|
+
output_tokens: totals.output_tokens,
|
|
3566
|
+
reasoning_output_tokens: totals.reasoning_output_tokens,
|
|
3567
|
+
total_tokens: totals.total_tokens,
|
|
3568
|
+
billable_total_tokens: totals.billable_total_tokens ?? totals.total_tokens,
|
|
3569
|
+
total_cost_usd: totals.total_cost_usd || 0,
|
|
3570
|
+
conversation_count: totals.conversation_count,
|
|
3571
|
+
};
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3574
|
+
function appendProjectSplitRows({ group, model, aggregateBucket, projects, toAppend }) {
|
|
3575
|
+
if (!projects || projects.size === 0) return;
|
|
3576
|
+
const attributed = initTotals();
|
|
3577
|
+
const projectKeys = [...projects.keys()].sort();
|
|
3578
|
+
for (const projectKey of projectKeys) {
|
|
3579
|
+
const projectBucket = projects.get(projectKey);
|
|
3580
|
+
if (!projectBucket.totals) continue;
|
|
3581
|
+
addTotals(attributed, projectBucket.totals);
|
|
3582
|
+
const totals = projectBucket.totals;
|
|
3583
|
+
const usagePrecision = projectBucket.usage_precision || aggregateBucket.usage_precision || null;
|
|
3584
|
+
const marker = usagePrecision ? `${totalsKey(totals)}|${usagePrecision}` : totalsKey(totals);
|
|
3585
|
+
if (projectBucket.queuedHourlyKey === marker) continue;
|
|
3586
|
+
toAppend.push(
|
|
3587
|
+
JSON.stringify({
|
|
3588
|
+
source: group.source,
|
|
3589
|
+
model,
|
|
3590
|
+
hour_start: group.hourStart,
|
|
3591
|
+
project_key: projectKey,
|
|
3592
|
+
...totalsRowFields(totals),
|
|
3593
|
+
usage_precision: usagePrecision || undefined,
|
|
3594
|
+
...prioritySubsetOf(totals),
|
|
3595
|
+
...creditsSubsetOf(totals),
|
|
3596
|
+
}),
|
|
3597
|
+
);
|
|
3598
|
+
projectBucket.queuedHourlyKey = marker;
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
const residual = cloneTotals(aggregateBucket.totals);
|
|
3602
|
+
subtractTotals(residual, attributed);
|
|
3603
|
+
clampTotalsNonNegative(residual);
|
|
3604
|
+
const usagePrecision = aggregateBucket.usage_precision || null;
|
|
3605
|
+
const marker = usagePrecision ? `${totalsKey(residual)}|${usagePrecision}` : totalsKey(residual);
|
|
3606
|
+
if (aggregateBucket.queuedResidualKey === marker) return;
|
|
3607
|
+
toAppend.push(
|
|
3608
|
+
JSON.stringify({
|
|
3609
|
+
source: group.source,
|
|
3610
|
+
model,
|
|
3611
|
+
hour_start: group.hourStart,
|
|
3612
|
+
project_key: UNATTRIBUTED_PROJECT_KEY,
|
|
3613
|
+
...totalsRowFields(residual),
|
|
3614
|
+
usage_precision: usagePrecision || undefined,
|
|
3615
|
+
...prioritySubsetOf(residual),
|
|
3616
|
+
...creditsSubsetOf(residual),
|
|
3617
|
+
}),
|
|
3618
|
+
);
|
|
3619
|
+
aggregateBucket.queuedResidualKey = marker;
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3622
|
+
async function enqueueTouchedBuckets({
|
|
3623
|
+
queuePath,
|
|
3624
|
+
hourlyState,
|
|
3625
|
+
touchedBuckets,
|
|
3626
|
+
projectState = null,
|
|
3627
|
+
projectTouchedBuckets = null,
|
|
3628
|
+
}) {
|
|
3629
|
+
if (!touchedBuckets || touchedBuckets.size === 0) {
|
|
3630
|
+
// A project backfill only moves projectState (an upgrade re-reads history
|
|
3631
|
+
// for attribution without touching the hourly totals). Still emit the
|
|
3632
|
+
// split rows so the cloud learns the attribution for those hours.
|
|
3633
|
+
if (!projectState || !projectTouchedBuckets || projectTouchedBuckets.size === 0) return 0;
|
|
3634
|
+
}
|
|
3515
3635
|
|
|
3516
3636
|
const touchedGroups = new Set();
|
|
3517
|
-
for (const bucketStart of touchedBuckets) {
|
|
3637
|
+
for (const bucketStart of touchedBuckets || []) {
|
|
3518
3638
|
const parsed = parseBucketKey(bucketStart);
|
|
3519
3639
|
const hourStart = parsed.hourStart;
|
|
3520
3640
|
if (!hourStart) continue;
|
|
3521
3641
|
touchedGroups.add(groupBucketKey(parsed.source, hourStart));
|
|
3522
3642
|
}
|
|
3643
|
+
if (projectState && projectTouchedBuckets) {
|
|
3644
|
+
for (const key of projectTouchedBuckets) {
|
|
3645
|
+
const bucket = projectState.buckets?.[key];
|
|
3646
|
+
if (!bucket || typeof bucket.hour_start !== "string" || !bucket.hour_start) continue;
|
|
3647
|
+
if (typeof bucket.model !== "string" || !bucket.model) continue;
|
|
3648
|
+
touchedGroups.add(groupBucketKey(bucket.source, bucket.hour_start));
|
|
3649
|
+
}
|
|
3650
|
+
}
|
|
3523
3651
|
if (touchedGroups.size === 0) return 0;
|
|
3524
3652
|
|
|
3525
3653
|
const groupQueued =
|
|
@@ -3600,9 +3728,32 @@ async function enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets })
|
|
|
3600
3728
|
}
|
|
3601
3729
|
|
|
3602
3730
|
const codexDominants = collectCodexDominantModels(hourlyState);
|
|
3731
|
+
const projectBucketsByGroup = indexProjectBucketsByGroup(projectState);
|
|
3603
3732
|
|
|
3604
3733
|
const toAppend = [];
|
|
3605
3734
|
for (const group of groupedBuckets.values()) {
|
|
3735
|
+
const projectModels = projectBucketsByGroup.get(groupBucketKey(group.source, group.hourStart));
|
|
3736
|
+
// Split only when every model of the hour has project attribution: the
|
|
3737
|
+
// rows then add up to the untouched aggregate (project totals + residual),
|
|
3738
|
+
// so totals never move and nothing is counted twice. Mixed hours fall
|
|
3739
|
+
// back to the plain aggregate row; those project totals stay unattributed.
|
|
3740
|
+
const canSplit =
|
|
3741
|
+
projectModels &&
|
|
3742
|
+
projectModels.size > 0 &&
|
|
3743
|
+
group.buckets.size > 0 &&
|
|
3744
|
+
[...group.buckets.keys()].every((model) => projectModels.has(model));
|
|
3745
|
+
if (canSplit) {
|
|
3746
|
+
for (const [model, bucket] of group.buckets.entries()) {
|
|
3747
|
+
appendProjectSplitRows({
|
|
3748
|
+
group,
|
|
3749
|
+
model,
|
|
3750
|
+
aggregateBucket: bucket,
|
|
3751
|
+
projects: projectModels.get(model),
|
|
3752
|
+
toAppend,
|
|
3753
|
+
});
|
|
3754
|
+
}
|
|
3755
|
+
continue;
|
|
3756
|
+
}
|
|
3606
3757
|
const unknownBucket = group.buckets.get(DEFAULT_MODEL) || null;
|
|
3607
3758
|
const dominantModel = pickDominantModel(group.buckets);
|
|
3608
3759
|
let alignedModel = null;
|
|
@@ -3848,23 +3999,51 @@ async function enqueueTouchedProjectBuckets({
|
|
|
3848
3999
|
|
|
3849
4000
|
await ensureDir(path.dirname(projectQueuePath));
|
|
3850
4001
|
|
|
3851
|
-
|
|
4002
|
+
// Contract v2 (2026-11-03): project buckets gained a model dimension so the
|
|
4003
|
+
// hourly queue can be split per project. The local project queue keeps its
|
|
4004
|
+
// original (project, source, hour) wire shape: one cumulative row per group,
|
|
4005
|
+
// summed across the hour's models. Rows are last-wins, so a rewrite of the
|
|
4006
|
+
// same group is harmless.
|
|
4007
|
+
const groups = new Map();
|
|
3852
4008
|
for (const key of projectTouchedBuckets) {
|
|
3853
4009
|
const bucket = projectState.buckets[key];
|
|
3854
4010
|
if (!bucket || !bucket.totals) continue;
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
if (bucket.
|
|
3858
|
-
const
|
|
3859
|
-
|
|
3860
|
-
if (!
|
|
4011
|
+
if (typeof bucket.project_key !== "string" || !bucket.project_key) continue;
|
|
4012
|
+
if (typeof bucket.project_ref !== "string" || !bucket.project_ref) continue;
|
|
4013
|
+
if (typeof bucket.source !== "string" || typeof bucket.hour_start !== "string") continue;
|
|
4014
|
+
const groupKey = JSON.stringify([bucket.project_key, bucket.source, bucket.hour_start]);
|
|
4015
|
+
let group = groups.get(groupKey);
|
|
4016
|
+
if (!group) {
|
|
4017
|
+
group = {
|
|
4018
|
+
projectKey: bucket.project_key,
|
|
4019
|
+
projectRef: bucket.project_ref,
|
|
4020
|
+
source: bucket.source,
|
|
4021
|
+
hourStart: bucket.hour_start,
|
|
4022
|
+
changed: false,
|
|
4023
|
+
};
|
|
4024
|
+
groups.set(groupKey, group);
|
|
4025
|
+
}
|
|
4026
|
+
if (bucket.queuedKey !== totalsKey(bucket.totals)) group.changed = true;
|
|
4027
|
+
}
|
|
3861
4028
|
|
|
4029
|
+
const toAppend = [];
|
|
4030
|
+
for (const group of groups.values()) {
|
|
4031
|
+
if (!group.changed) continue;
|
|
4032
|
+
const totals = initTotals();
|
|
4033
|
+
const members = [];
|
|
4034
|
+
for (const bucket of Object.values(projectState.buckets)) {
|
|
4035
|
+
if (!bucket || !bucket.totals) continue;
|
|
4036
|
+
if (bucket.project_key !== group.projectKey) continue;
|
|
4037
|
+
if (bucket.source !== group.source || bucket.hour_start !== group.hourStart) continue;
|
|
4038
|
+
addTotals(totals, bucket.totals);
|
|
4039
|
+
members.push(bucket);
|
|
4040
|
+
}
|
|
3862
4041
|
toAppend.push(
|
|
3863
4042
|
JSON.stringify({
|
|
3864
|
-
project_ref: projectRef,
|
|
3865
|
-
project_key: projectKey,
|
|
3866
|
-
source:
|
|
3867
|
-
hour_start:
|
|
4043
|
+
project_ref: group.projectRef,
|
|
4044
|
+
project_key: group.projectKey,
|
|
4045
|
+
source: group.source,
|
|
4046
|
+
hour_start: group.hourStart,
|
|
3868
4047
|
input_tokens: totals.input_tokens,
|
|
3869
4048
|
cached_input_tokens: totals.cached_input_tokens,
|
|
3870
4049
|
cache_creation_input_tokens: totals.cache_creation_input_tokens,
|
|
@@ -3876,7 +4055,7 @@ async function enqueueTouchedProjectBuckets({
|
|
|
3876
4055
|
conversation_count: totals.conversation_count,
|
|
3877
4056
|
}),
|
|
3878
4057
|
);
|
|
3879
|
-
|
|
4058
|
+
for (const member of members) member.queuedKey = totalsKey(member.totals);
|
|
3880
4059
|
}
|
|
3881
4060
|
|
|
3882
4061
|
if (toAppend.length > 0) {
|
|
@@ -4292,12 +4471,13 @@ function subtractCountedOpencodeMessage({
|
|
|
4292
4471
|
projectState,
|
|
4293
4472
|
countedAt.projectKey,
|
|
4294
4473
|
source,
|
|
4474
|
+
countedAt.model,
|
|
4295
4475
|
countedAt.bucketStart,
|
|
4296
4476
|
countedAt.projectRef,
|
|
4297
4477
|
);
|
|
4298
4478
|
subtractTotals(projectBucket.totals, counted);
|
|
4299
4479
|
projectTouchedBuckets.add(
|
|
4300
|
-
projectBucketKey(countedAt.projectKey, source, countedAt.bucketStart),
|
|
4480
|
+
projectBucketKey(countedAt.projectKey, source, countedAt.model, countedAt.bucketStart),
|
|
4301
4481
|
);
|
|
4302
4482
|
}
|
|
4303
4483
|
return true;
|
|
@@ -4363,10 +4543,14 @@ function getHourlyBucket(state, source, model, hourStart) {
|
|
|
4363
4543
|
return bucket;
|
|
4364
4544
|
}
|
|
4365
4545
|
|
|
4366
|
-
function getProjectBucket(state, projectKey, source, hourStart, projectRef) {
|
|
4546
|
+
function getProjectBucket(state, projectKey, source, model, hourStart, projectRef) {
|
|
4367
4547
|
const buckets = state.buckets;
|
|
4368
4548
|
const normalizedSource = normalizeSourceInput(source) || DEFAULT_SOURCE;
|
|
4369
|
-
|
|
4549
|
+
// `model == null` means this parser cannot reliably pair project usage with
|
|
4550
|
+
// an hourly model (separate attribution pass or cursor drift). Such buckets
|
|
4551
|
+
// keep the legacy three-part key and are never split out of an aggregate.
|
|
4552
|
+
const normalizedModel = model == null ? null : normalizeModelInput(model) || DEFAULT_MODEL;
|
|
4553
|
+
const key = projectBucketKey(projectKey, normalizedSource, normalizedModel, hourStart);
|
|
4370
4554
|
let bucket = buckets[key];
|
|
4371
4555
|
if (!bucket || typeof bucket !== "object") {
|
|
4372
4556
|
bucket = {
|
|
@@ -4377,6 +4561,7 @@ function getProjectBucket(state, projectKey, source, hourStart, projectRef) {
|
|
|
4377
4561
|
source: normalizedSource,
|
|
4378
4562
|
hour_start: hourStart,
|
|
4379
4563
|
};
|
|
4564
|
+
if (normalizedModel) bucket.model = normalizedModel;
|
|
4380
4565
|
buckets[key] = bucket;
|
|
4381
4566
|
return bucket;
|
|
4382
4567
|
}
|
|
@@ -4392,6 +4577,7 @@ function getProjectBucket(state, projectKey, source, hourStart, projectRef) {
|
|
|
4392
4577
|
if (projectRef) bucket.project_ref = projectRef;
|
|
4393
4578
|
if (projectKey) bucket.project_key = projectKey;
|
|
4394
4579
|
bucket.source = normalizedSource;
|
|
4580
|
+
if (normalizedModel) bucket.model = normalizedModel;
|
|
4395
4581
|
bucket.hour_start = hourStart;
|
|
4396
4582
|
|
|
4397
4583
|
return bucket;
|
|
@@ -4613,9 +4799,16 @@ function bucketKey(source, model, hourStart) {
|
|
|
4613
4799
|
return `${safeSource}${BUCKET_SEPARATOR}${safeModel}${BUCKET_SEPARATOR}${hourStart}`;
|
|
4614
4800
|
}
|
|
4615
4801
|
|
|
4616
|
-
|
|
4802
|
+
// Contract v2 (2026-11-03): a project bucket is per (project, source, model,
|
|
4803
|
+
// hour) so it can be subtracted from the matching per-model hourly aggregate
|
|
4804
|
+
// when usage rows are split by project_key. Buckets written before the model
|
|
4805
|
+
// dimension existed keep their old `project|source|hour` key and are never
|
|
4806
|
+
// touched again (their usage stays in the unattributed residual).
|
|
4807
|
+
function projectBucketKey(projectKey, source, model, hourStart) {
|
|
4617
4808
|
const safeSource = normalizeSourceInput(source) || DEFAULT_SOURCE;
|
|
4618
|
-
return `${projectKey}${BUCKET_SEPARATOR}${safeSource}${BUCKET_SEPARATOR}${hourStart}`;
|
|
4809
|
+
if (model == null) return `${projectKey}${BUCKET_SEPARATOR}${safeSource}${BUCKET_SEPARATOR}${hourStart}`;
|
|
4810
|
+
const safeModel = normalizeModelInput(model) || DEFAULT_MODEL;
|
|
4811
|
+
return `${projectKey}${BUCKET_SEPARATOR}${safeSource}${BUCKET_SEPARATOR}${safeModel}${BUCKET_SEPARATOR}${hourStart}`;
|
|
4619
4812
|
}
|
|
4620
4813
|
|
|
4621
4814
|
function groupBucketKey(source, hourStart) {
|
|
@@ -6378,13 +6571,14 @@ async function parseOpencodeDbIncremental({
|
|
|
6378
6571
|
projectState,
|
|
6379
6572
|
attribution.projectKey,
|
|
6380
6573
|
defaultSource,
|
|
6574
|
+
model,
|
|
6381
6575
|
bucketStart,
|
|
6382
6576
|
attribution.projectRef,
|
|
6383
6577
|
);
|
|
6384
6578
|
addTotals(projectBucket.totals, contribution);
|
|
6385
6579
|
clampTotalsNonNegative(projectBucket.totals);
|
|
6386
6580
|
projectTouchedBuckets.add(
|
|
6387
|
-
projectBucketKey(attribution.projectKey, defaultSource, bucketStart),
|
|
6581
|
+
projectBucketKey(attribution.projectKey, defaultSource, model, bucketStart),
|
|
6388
6582
|
);
|
|
6389
6583
|
}
|
|
6390
6584
|
|
|
@@ -6411,7 +6605,7 @@ async function parseOpencodeDbIncremental({
|
|
|
6411
6605
|
}
|
|
6412
6606
|
}
|
|
6413
6607
|
|
|
6414
|
-
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets });
|
|
6608
|
+
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets });
|
|
6415
6609
|
const projectBucketsQueued = projectEnabled
|
|
6416
6610
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
6417
6611
|
: 0;
|
|
@@ -6726,12 +6920,13 @@ async function parseQoderDbIncremental({
|
|
|
6726
6920
|
projectState,
|
|
6727
6921
|
previous.projectKey,
|
|
6728
6922
|
sourceKey,
|
|
6923
|
+
previous.model,
|
|
6729
6924
|
previous.bucketStart,
|
|
6730
6925
|
previous.projectRef || null,
|
|
6731
6926
|
);
|
|
6732
6927
|
subtractTotals(oldProjectBucket.totals, previousTotals);
|
|
6733
6928
|
projectTouchedBuckets.add(
|
|
6734
|
-
projectBucketKey(previous.projectKey, sourceKey, previous.bucketStart),
|
|
6929
|
+
projectBucketKey(previous.projectKey, sourceKey, previous.model, previous.bucketStart),
|
|
6735
6930
|
);
|
|
6736
6931
|
}
|
|
6737
6932
|
}
|
|
@@ -6744,11 +6939,12 @@ async function parseQoderDbIncremental({
|
|
|
6744
6939
|
projectState,
|
|
6745
6940
|
projectKey,
|
|
6746
6941
|
sourceKey,
|
|
6942
|
+
model,
|
|
6747
6943
|
bucketStart,
|
|
6748
6944
|
projectRef,
|
|
6749
6945
|
);
|
|
6750
6946
|
addTotals(projectBucket.totals, currentTotals);
|
|
6751
|
-
projectTouchedBuckets.add(projectBucketKey(projectKey, sourceKey, bucketStart));
|
|
6947
|
+
projectTouchedBuckets.add(projectBucketKey(projectKey, sourceKey, model, bucketStart));
|
|
6752
6948
|
}
|
|
6753
6949
|
qoderState.messages[messageKey] = {
|
|
6754
6950
|
totals: currentTotals,
|
|
@@ -6779,6 +6975,8 @@ async function parseQoderDbIncremental({
|
|
|
6779
6975
|
queuePath,
|
|
6780
6976
|
hourlyState,
|
|
6781
6977
|
touchedBuckets,
|
|
6978
|
+
projectState,
|
|
6979
|
+
projectTouchedBuckets,
|
|
6782
6980
|
});
|
|
6783
6981
|
const projectBucketsQueued = projectEnabled
|
|
6784
6982
|
? await enqueueTouchedProjectBuckets({
|
|
@@ -7130,9 +7328,9 @@ async function parseQoderNewIncremental({
|
|
|
7130
7328
|
subtractTotals(oldBucket.totals, prev.totals);
|
|
7131
7329
|
touchedBuckets.add(bucketKey(sourceKey, prev.model, prev.bucketStart));
|
|
7132
7330
|
if (projectEnabled && prev.projectKey) {
|
|
7133
|
-
const oldProjectBucket = getProjectBucket(projectState, prev.projectKey, sourceKey, prev.bucketStart, prev.projectRef || null);
|
|
7331
|
+
const oldProjectBucket = getProjectBucket(projectState, prev.projectKey, sourceKey, prev.model, prev.bucketStart, prev.projectRef || null);
|
|
7134
7332
|
subtractTotals(oldProjectBucket.totals, prev.totals);
|
|
7135
|
-
projectTouchedBuckets.add(projectBucketKey(prev.projectKey, sourceKey, prev.bucketStart));
|
|
7333
|
+
projectTouchedBuckets.add(projectBucketKey(prev.projectKey, sourceKey, prev.model, prev.bucketStart));
|
|
7136
7334
|
}
|
|
7137
7335
|
}
|
|
7138
7336
|
if (cur) {
|
|
@@ -7142,10 +7340,10 @@ async function parseQoderNewIncremental({
|
|
|
7142
7340
|
// addTotals handles total_cost_usd via USD_TICKS, but credits cost is small; ensure it accumulates
|
|
7143
7341
|
touchedBuckets.add(bucketKey(sourceKey, cur.model, cur.bucketStart));
|
|
7144
7342
|
if (projectEnabled && cur.projectKey) {
|
|
7145
|
-
const projectBucket = getProjectBucket(projectState, cur.projectKey, sourceKey, cur.bucketStart, cur.projectRef);
|
|
7343
|
+
const projectBucket = getProjectBucket(projectState, cur.projectKey, sourceKey, cur.model, cur.bucketStart, cur.projectRef);
|
|
7146
7344
|
addTotals(projectBucket.totals, cur.totals);
|
|
7147
7345
|
if (cur.totals.usage_precision) projectBucket.usage_precision = cur.totals.usage_precision;
|
|
7148
|
-
projectTouchedBuckets.add(projectBucketKey(cur.projectKey, sourceKey, cur.bucketStart));
|
|
7346
|
+
projectTouchedBuckets.add(projectBucketKey(cur.projectKey, sourceKey, cur.model, cur.bucketStart));
|
|
7149
7347
|
}
|
|
7150
7348
|
qoderState.messages[key] = {
|
|
7151
7349
|
totals: cur.totals,
|
|
@@ -7171,10 +7369,10 @@ async function parseQoderNewIncremental({
|
|
|
7171
7369
|
if (cur.totals.usage_precision) bucket.usage_precision = cur.totals.usage_precision;
|
|
7172
7370
|
touchedBuckets.add(bucketKey(sourceKey, cur.model, cur.bucketStart));
|
|
7173
7371
|
if (projectEnabled && cur.projectKey) {
|
|
7174
|
-
const projectBucket = getProjectBucket(projectState, cur.projectKey, sourceKey, cur.bucketStart, cur.projectRef);
|
|
7372
|
+
const projectBucket = getProjectBucket(projectState, cur.projectKey, sourceKey, cur.model, cur.bucketStart, cur.projectRef);
|
|
7175
7373
|
addTotals(projectBucket.totals, cur.totals);
|
|
7176
7374
|
if (cur.totals.usage_precision) projectBucket.usage_precision = cur.totals.usage_precision;
|
|
7177
|
-
projectTouchedBuckets.add(projectBucketKey(cur.projectKey, sourceKey, cur.bucketStart));
|
|
7375
|
+
projectTouchedBuckets.add(projectBucketKey(cur.projectKey, sourceKey, cur.model, cur.bucketStart));
|
|
7178
7376
|
}
|
|
7179
7377
|
qoderState.messages[key] = {
|
|
7180
7378
|
totals: cur.totals,
|
|
@@ -7188,7 +7386,7 @@ async function parseQoderNewIncremental({
|
|
|
7188
7386
|
eventsAggregated += 1;
|
|
7189
7387
|
}
|
|
7190
7388
|
|
|
7191
|
-
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets });
|
|
7389
|
+
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets });
|
|
7192
7390
|
const projectBucketsQueued = projectEnabled
|
|
7193
7391
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
7194
7392
|
: 0;
|
|
@@ -11680,11 +11878,12 @@ async function parseWorkbuddyIncremental({
|
|
|
11680
11878
|
projectState,
|
|
11681
11879
|
projectKey,
|
|
11682
11880
|
source,
|
|
11881
|
+
null,
|
|
11683
11882
|
bucketStart,
|
|
11684
11883
|
projectRef,
|
|
11685
11884
|
);
|
|
11686
11885
|
addTotals(projectBucket.totals, delta);
|
|
11687
|
-
projectTouchedBuckets.add(projectBucketKey(projectKey, source, bucketStart));
|
|
11886
|
+
projectTouchedBuckets.add(projectBucketKey(projectKey, source, null, bucketStart));
|
|
11688
11887
|
},
|
|
11689
11888
|
);
|
|
11690
11889
|
|
|
@@ -11980,6 +12179,8 @@ async function parseWorkbuddyIncremental({
|
|
|
11980
12179
|
queuePath,
|
|
11981
12180
|
hourlyState,
|
|
11982
12181
|
touchedBuckets,
|
|
12182
|
+
projectState,
|
|
12183
|
+
projectTouchedBuckets,
|
|
11983
12184
|
});
|
|
11984
12185
|
const updatedAt = new Date().toISOString();
|
|
11985
12186
|
hourlyState.updatedAt = updatedAt;
|
|
@@ -15072,12 +15273,13 @@ async function parseDevinIncremental({
|
|
|
15072
15273
|
projectState,
|
|
15073
15274
|
previous.projectKey,
|
|
15074
15275
|
DEVIN_SOURCE,
|
|
15276
|
+
previous.model,
|
|
15075
15277
|
previous.bucketStart,
|
|
15076
15278
|
previous.projectRef || null,
|
|
15077
15279
|
);
|
|
15078
15280
|
subtractTotals(oldProjectBucket.totals, previousTotals);
|
|
15079
15281
|
projectTouchedBuckets.add(
|
|
15080
|
-
projectBucketKey(previous.projectKey, DEVIN_SOURCE, previous.bucketStart),
|
|
15282
|
+
projectBucketKey(previous.projectKey, DEVIN_SOURCE, previous.model, previous.bucketStart),
|
|
15081
15283
|
);
|
|
15082
15284
|
}
|
|
15083
15285
|
}
|
|
@@ -15090,12 +15292,13 @@ async function parseDevinIncremental({
|
|
|
15090
15292
|
projectState,
|
|
15091
15293
|
projectKey,
|
|
15092
15294
|
DEVIN_SOURCE,
|
|
15295
|
+
event.model,
|
|
15093
15296
|
bucketStart,
|
|
15094
15297
|
projectRef,
|
|
15095
15298
|
);
|
|
15096
15299
|
addTotals(projectBucket.totals, event.totals);
|
|
15097
15300
|
projectTouchedBuckets.add(
|
|
15098
|
-
projectBucketKey(projectKey, DEVIN_SOURCE, bucketStart),
|
|
15301
|
+
projectBucketKey(projectKey, DEVIN_SOURCE, event.model, bucketStart),
|
|
15099
15302
|
);
|
|
15100
15303
|
}
|
|
15101
15304
|
// The ledger records only what was added: owning session, model,
|
|
@@ -15130,6 +15333,8 @@ async function parseDevinIncremental({
|
|
|
15130
15333
|
queuePath,
|
|
15131
15334
|
hourlyState,
|
|
15132
15335
|
touchedBuckets,
|
|
15336
|
+
projectState,
|
|
15337
|
+
projectTouchedBuckets,
|
|
15133
15338
|
});
|
|
15134
15339
|
const projectBucketsQueued = projectEnabled
|
|
15135
15340
|
? await enqueueTouchedProjectBuckets({
|
|
@@ -16154,12 +16359,13 @@ async function parseDroidIncremental({
|
|
|
16154
16359
|
projectState,
|
|
16155
16360
|
projectKey,
|
|
16156
16361
|
"droid",
|
|
16362
|
+
model,
|
|
16157
16363
|
bucketStart,
|
|
16158
16364
|
projectRef,
|
|
16159
16365
|
);
|
|
16160
16366
|
addTotals(projectBucket.totals, projectDelta);
|
|
16161
16367
|
projectTouchedBuckets.add(
|
|
16162
|
-
projectBucketKey(projectKey, "droid", bucketStart),
|
|
16368
|
+
projectBucketKey(projectKey, "droid", model, bucketStart),
|
|
16163
16369
|
);
|
|
16164
16370
|
}
|
|
16165
16371
|
projectSessionTotals[sessionId] = {
|
|
@@ -16221,6 +16427,8 @@ async function parseDroidIncremental({
|
|
|
16221
16427
|
queuePath,
|
|
16222
16428
|
hourlyState,
|
|
16223
16429
|
touchedBuckets,
|
|
16430
|
+
projectState,
|
|
16431
|
+
projectTouchedBuckets,
|
|
16224
16432
|
});
|
|
16225
16433
|
const projectBucketsQueued = projectEnabled
|
|
16226
16434
|
? await enqueueTouchedProjectBuckets({
|
|
@@ -16721,15 +16929,17 @@ async function parseOmpLikeIncremental({
|
|
|
16721
16929
|
total_tokens: totalTokens,
|
|
16722
16930
|
conversation_count: 1,
|
|
16723
16931
|
};
|
|
16932
|
+
const projectModel = normalizeModelInput(msg.model) || fallbackModel;
|
|
16724
16933
|
const projectBucket = getProjectBucket(
|
|
16725
16934
|
projectState,
|
|
16726
16935
|
projectKey,
|
|
16727
16936
|
source,
|
|
16937
|
+
projectModel,
|
|
16728
16938
|
bucketStart,
|
|
16729
16939
|
projectRef,
|
|
16730
16940
|
);
|
|
16731
16941
|
addTotals(projectBucket.totals, delta);
|
|
16732
|
-
projectTouchedBuckets.add(projectBucketKey(projectKey, source, bucketStart));
|
|
16942
|
+
projectTouchedBuckets.add(projectBucketKey(projectKey, source, projectModel, bucketStart));
|
|
16733
16943
|
projectSeenIds.add(entryId);
|
|
16734
16944
|
});
|
|
16735
16945
|
}
|
|
@@ -16757,6 +16967,8 @@ async function parseOmpLikeIncremental({
|
|
|
16757
16967
|
queuePath,
|
|
16758
16968
|
hourlyState,
|
|
16759
16969
|
touchedBuckets,
|
|
16970
|
+
projectState,
|
|
16971
|
+
projectTouchedBuckets,
|
|
16760
16972
|
});
|
|
16761
16973
|
const projectBucketsQueued = projectEnabled
|
|
16762
16974
|
? await enqueueTouchedProjectBuckets({
|
|
@@ -17334,15 +17546,19 @@ async function parsePiLikeIncremental({
|
|
|
17334
17546
|
total_tokens: totalTokens,
|
|
17335
17547
|
conversation_count: 1,
|
|
17336
17548
|
};
|
|
17549
|
+
const projectModel = normalizeModelInput(msg.model) || fallbackModel;
|
|
17337
17550
|
const projectBucket = getProjectBucket(
|
|
17338
17551
|
projectState,
|
|
17339
17552
|
projectKey,
|
|
17340
17553
|
sourceForProvider(msg.provider),
|
|
17554
|
+
projectModel,
|
|
17341
17555
|
bucketStart,
|
|
17342
17556
|
projectRef,
|
|
17343
17557
|
);
|
|
17344
17558
|
addTotals(projectBucket.totals, delta);
|
|
17345
|
-
projectTouchedBuckets.add(
|
|
17559
|
+
projectTouchedBuckets.add(
|
|
17560
|
+
projectBucketKey(projectKey, sourceForProvider(msg.provider), projectModel, bucketStart),
|
|
17561
|
+
);
|
|
17346
17562
|
projectSeenIds.add(entryId);
|
|
17347
17563
|
}
|
|
17348
17564
|
}
|
|
@@ -17365,6 +17581,8 @@ async function parsePiLikeIncremental({
|
|
|
17365
17581
|
queuePath,
|
|
17366
17582
|
hourlyState,
|
|
17367
17583
|
touchedBuckets,
|
|
17584
|
+
projectState,
|
|
17585
|
+
projectTouchedBuckets,
|
|
17368
17586
|
});
|
|
17369
17587
|
const projectBucketsQueued = projectEnabled
|
|
17370
17588
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
@@ -21540,12 +21758,13 @@ async function parseGrokBuildIncremental({
|
|
|
21540
21758
|
projectState,
|
|
21541
21759
|
projectKey,
|
|
21542
21760
|
"grok",
|
|
21761
|
+
pending.model,
|
|
21543
21762
|
pending.hourStartStr,
|
|
21544
21763
|
projectRef,
|
|
21545
21764
|
);
|
|
21546
21765
|
addTotals(projectBucket.totals, pending.delta);
|
|
21547
21766
|
projectTouchedBuckets.add(
|
|
21548
|
-
projectBucketKey(projectKey, "grok", pending.hourStartStr),
|
|
21767
|
+
projectBucketKey(projectKey, "grok", pending.model, pending.hourStartStr),
|
|
21549
21768
|
);
|
|
21550
21769
|
}
|
|
21551
21770
|
|
|
@@ -21558,12 +21777,13 @@ async function parseGrokBuildIncremental({
|
|
|
21558
21777
|
projectState,
|
|
21559
21778
|
projectKey,
|
|
21560
21779
|
"grok",
|
|
21780
|
+
projectLastModel || DEFAULT_MODEL,
|
|
21561
21781
|
projectFinalTouchedHourStart,
|
|
21562
21782
|
projectRef,
|
|
21563
21783
|
);
|
|
21564
21784
|
addTotals(projectBucket.totals, { conversation_count: deltaMessageCount });
|
|
21565
21785
|
projectTouchedBuckets.add(
|
|
21566
|
-
projectBucketKey(projectKey, "grok", projectFinalTouchedHourStart),
|
|
21786
|
+
projectBucketKey(projectKey, "grok", projectLastModel || DEFAULT_MODEL, projectFinalTouchedHourStart),
|
|
21567
21787
|
);
|
|
21568
21788
|
}
|
|
21569
21789
|
|
|
@@ -21592,7 +21812,7 @@ async function parseGrokBuildIncremental({
|
|
|
21592
21812
|
if (projectEnabled) pruneMissingGrokProjectUpdateOffsets(projectUpdateOffsets);
|
|
21593
21813
|
|
|
21594
21814
|
let bucketsQueued = queuePath
|
|
21595
|
-
? await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets })
|
|
21815
|
+
? await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets })
|
|
21596
21816
|
: 0;
|
|
21597
21817
|
|
|
21598
21818
|
// After a semantics migration, retract stale grok queue keys that the full
|
|
@@ -22323,11 +22543,12 @@ async function parseAntigravityIncremental({
|
|
|
22323
22543
|
projectState,
|
|
22324
22544
|
c.projectKey,
|
|
22325
22545
|
c.source,
|
|
22546
|
+
c.model,
|
|
22326
22547
|
c.bucketStart,
|
|
22327
22548
|
c.projectRef || null,
|
|
22328
22549
|
);
|
|
22329
22550
|
subtractTotals(oldProjectBucket.totals, c.totals);
|
|
22330
|
-
projectTouchedBuckets.add(projectBucketKey(c.projectKey, c.source, c.bucketStart));
|
|
22551
|
+
projectTouchedBuckets.add(projectBucketKey(c.projectKey, c.source, c.model, c.bucketStart));
|
|
22331
22552
|
}
|
|
22332
22553
|
}
|
|
22333
22554
|
}
|
|
@@ -22482,7 +22703,7 @@ async function parseAntigravityIncremental({
|
|
|
22482
22703
|
}
|
|
22483
22704
|
}
|
|
22484
22705
|
|
|
22485
|
-
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets });
|
|
22706
|
+
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets });
|
|
22486
22707
|
const projectBucketsQueued = projectEnabled
|
|
22487
22708
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
22488
22709
|
: 0;
|
|
@@ -22970,11 +23191,12 @@ async function parseAntigravityFile({
|
|
|
22970
23191
|
projectState,
|
|
22971
23192
|
projectKey,
|
|
22972
23193
|
source,
|
|
23194
|
+
model,
|
|
22973
23195
|
bucketStart,
|
|
22974
23196
|
projectRef,
|
|
22975
23197
|
);
|
|
22976
23198
|
addTotals(projectBucket.totals, delta);
|
|
22977
|
-
projectTouchedBuckets.add(projectBucketKey(projectKey, source, bucketStart));
|
|
23199
|
+
projectTouchedBuckets.add(projectBucketKey(projectKey, source, model, bucketStart));
|
|
22978
23200
|
}
|
|
22979
23201
|
}
|
|
22980
23202
|
const isNewForCounter = watermarkLine > 0 ? i >= watermarkLine : true;
|
|
@@ -25668,8 +25890,8 @@ async function parseCommandCodeIncremental({
|
|
|
25668
25890
|
apply(getHourlyBucket(hourlyState, COMMAND_CODE_SOURCE, value.model, value.bucketStart).totals, totals);
|
|
25669
25891
|
touchedBuckets.add(bucketKey(COMMAND_CODE_SOURCE, value.model, value.bucketStart));
|
|
25670
25892
|
if (projectEnabled && value.projectKey) {
|
|
25671
|
-
apply(getProjectBucket(projectState, value.projectKey, COMMAND_CODE_SOURCE, value.bucketStart, value.projectRef).totals, totals);
|
|
25672
|
-
projectTouchedBuckets.add(projectBucketKey(value.projectKey, COMMAND_CODE_SOURCE, value.bucketStart));
|
|
25893
|
+
apply(getProjectBucket(projectState, value.projectKey, COMMAND_CODE_SOURCE, value.model, value.bucketStart, value.projectRef).totals, totals);
|
|
25894
|
+
projectTouchedBuckets.add(projectBucketKey(value.projectKey, COMMAND_CODE_SOURCE, value.model, value.bucketStart));
|
|
25673
25895
|
}
|
|
25674
25896
|
}
|
|
25675
25897
|
|
|
@@ -25738,7 +25960,7 @@ async function parseCommandCodeIncremental({
|
|
|
25738
25960
|
prepareBuckets(touchedBuckets, hourlyState, cursors?.hourly);
|
|
25739
25961
|
if (projectEnabled) prepareBuckets(projectTouchedBuckets, projectState, cursors?.projectHourly);
|
|
25740
25962
|
|
|
25741
|
-
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets });
|
|
25963
|
+
const bucketsQueued = await enqueueTouchedBuckets({ queuePath, hourlyState, touchedBuckets, projectState, projectTouchedBuckets });
|
|
25742
25964
|
const projectBucketsQueued = projectEnabled
|
|
25743
25965
|
? await enqueueTouchedProjectBuckets({ projectQueuePath, projectState, projectTouchedBuckets })
|
|
25744
25966
|
: 0;
|
|
@@ -25769,6 +25991,12 @@ async function parseCommandCodeIncremental({
|
|
|
25769
25991
|
}
|
|
25770
25992
|
|
|
25771
25993
|
module.exports = {
|
|
25994
|
+
enqueueTouchedBuckets,
|
|
25995
|
+
enqueueTouchedProjectBuckets,
|
|
25996
|
+
projectBucketKey,
|
|
25997
|
+
getProjectBucket,
|
|
25998
|
+
initTotals,
|
|
25999
|
+
totalsKey,
|
|
25772
26000
|
parseTraeIncremental,
|
|
25773
26001
|
listRolloutFiles,
|
|
25774
26002
|
listRolloutFilesDeep,
|