exe-watcher 0.2.6 → 0.2.8

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/dist/cli.js CHANGED
@@ -6730,11 +6730,43 @@ function parseDateRangeFlags(from, to) {
6730
6730
  return { start, end };
6731
6731
  }
6732
6732
 
6733
+ // src/progressive-backfill.ts
6734
+ var MS_PER_DAY3 = 24 * 60 * 60 * 1e3;
6735
+ var DEFAULT_COLD_START_HISTORY_DAYS = 7;
6736
+ var DEFAULT_PROGRESSIVE_CHUNK_DAYS = 30;
6737
+ function nextLocalMidnight(dateString) {
6738
+ return new Date(
6739
+ parseInt(dateString.slice(0, 4), 10),
6740
+ parseInt(dateString.slice(5, 7), 10) - 1,
6741
+ parseInt(dateString.slice(8, 10), 10) + 1
6742
+ );
6743
+ }
6744
+ function computeProgressiveBackfillStart({
6745
+ lastComputedDate,
6746
+ todayStart,
6747
+ yesterdayEnd,
6748
+ backfillDays,
6749
+ coldStartHistoryDays = DEFAULT_COLD_START_HISTORY_DAYS,
6750
+ progressiveChunkDays = DEFAULT_PROGRESSIVE_CHUNK_DAYS
6751
+ }) {
6752
+ const fullBackfillStart = new Date(todayStart.getTime() - backfillDays * MS_PER_DAY3);
6753
+ if (!lastComputedDate) {
6754
+ const priorHistoryDays = Math.max(coldStartHistoryDays - 1, 0);
6755
+ return new Date(todayStart.getTime() - priorHistoryDays * MS_PER_DAY3);
6756
+ }
6757
+ const gapStart = nextLocalMidnight(lastComputedDate);
6758
+ if (gapStart < fullBackfillStart) return fullBackfillStart;
6759
+ if (yesterdayEnd.getTime() - gapStart.getTime() > progressiveChunkDays * MS_PER_DAY3) {
6760
+ return new Date(yesterdayEnd.getTime() - progressiveChunkDays * MS_PER_DAY3);
6761
+ }
6762
+ return gapStart;
6763
+ }
6764
+
6733
6765
  // src/cli.ts
6734
6766
  import { createRequire as createRequire2 } from "module";
6735
6767
  var require2 = createRequire2(import.meta.url);
6736
6768
  var { version } = require2("../package.json");
6737
- var MS_PER_DAY3 = 24 * 60 * 60 * 1e3;
6769
+ var MS_PER_DAY4 = 24 * 60 * 60 * 1e3;
6738
6770
  var BACKFILL_DAYS = 365;
6739
6771
  function toDateString(date) {
6740
6772
  return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
@@ -7017,7 +7049,7 @@ program.command("status").description("Compact status output (today + week + mon
7017
7049
  const now = /* @__PURE__ */ new Date();
7018
7050
  const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
7019
7051
  const yesterdayEnd = new Date(todayStart.getTime() - 1);
7020
- const yesterdayStr = toDateString(new Date(todayStart.getTime() - MS_PER_DAY3));
7052
+ const yesterdayStr = toDateString(new Date(todayStart.getTime() - MS_PER_DAY4));
7021
7053
  const isAllProviders = pf === "all";
7022
7054
  const dailyCacheScope = buildDailyCacheScopeKey(opts.project, opts.exclude);
7023
7055
  const cache = await withDailyCacheLock(async () => {
@@ -7028,16 +7060,13 @@ program.command("status").description("Compact status output (today + week + mon
7028
7060
  const latestFresh = freshDays.length > 0 ? freshDays[freshDays.length - 1].date : null;
7029
7061
  c = { ...c, days: freshDays, lastComputedDate: latestFresh };
7030
7062
  }
7031
- const PROGRESSIVE_CHUNK_DAYS = 30;
7032
- const isColdStart = !c.lastComputedDate;
7033
- const gapStart = c.lastComputedDate ? new Date(
7034
- parseInt(c.lastComputedDate.slice(0, 4)),
7035
- parseInt(c.lastComputedDate.slice(5, 7)) - 1,
7036
- parseInt(c.lastComputedDate.slice(8, 10)) + 1
7037
- ) : new Date(todayStart.getTime() - BACKFILL_DAYS * MS_PER_DAY3);
7038
- const fullBackfillStart = new Date(todayStart.getTime() - BACKFILL_DAYS * MS_PER_DAY3);
7039
- const effectiveGapStart = isColdStart ? todayStart : gapStart < fullBackfillStart ? fullBackfillStart : yesterdayEnd.getTime() - gapStart.getTime() > PROGRESSIVE_CHUNK_DAYS * MS_PER_DAY3 ? new Date(yesterdayEnd.getTime() - PROGRESSIVE_CHUNK_DAYS * MS_PER_DAY3) : gapStart;
7040
- if (!isColdStart && effectiveGapStart.getTime() <= yesterdayEnd.getTime()) {
7063
+ const effectiveGapStart = computeProgressiveBackfillStart({
7064
+ lastComputedDate: c.lastComputedDate,
7065
+ todayStart,
7066
+ yesterdayEnd,
7067
+ backfillDays: BACKFILL_DAYS
7068
+ });
7069
+ if (effectiveGapStart.getTime() <= yesterdayEnd.getTime()) {
7041
7070
  const gapRange = { start: effectiveGapStart, end: yesterdayEnd };
7042
7071
  const gapProjects = filterProjectsByName(await parseAllSessions(gapRange, "all"), opts.project, opts.exclude);
7043
7072
  const gapDays = fillMissingDays(gapRange.start, gapRange.end, aggregateProjectsIntoDays(gapProjects));
@@ -7112,16 +7141,11 @@ program.command("status").description("Compact status output (today + week + mon
7112
7141
  for (const [name, cost] of Object.entries(providerTotals)) {
7113
7142
  providers.push({ name: displayNameByName.get(name) ?? name, cost });
7114
7143
  }
7115
- for (const p of allProviders) {
7116
- if (providers.some((pc) => pc.name === p.displayName)) continue;
7117
- const sources = await p.discoverSessions();
7118
- if (sources.length > 0) providers.push({ name: p.displayName, cost: 0 });
7119
- }
7120
7144
  } else {
7121
7145
  const display = displayNameByName.get(pf) ?? pf;
7122
7146
  providers.push({ name: display, cost: currentData.cost });
7123
7147
  }
7124
- const historyStartStr = toDateString(new Date(todayStart.getTime() - BACKFILL_DAYS * MS_PER_DAY3));
7148
+ const historyStartStr = toDateString(new Date(todayStart.getTime() - BACKFILL_DAYS * MS_PER_DAY4));
7125
7149
  const allCacheDays = getDaysInRange(cache, historyStartStr, yesterdayStr);
7126
7150
  const fullHistory = [...allCacheDays, ...todayDays.filter((d) => d.date > yesterdayStr)];
7127
7151
  const dailyHistory = fullHistory.map((d) => {
@@ -7205,11 +7229,11 @@ program.command("status").description("Compact status output (today + week + mon
7205
7229
  const [proj7d, proj30d] = await Promise.all([
7206
7230
  Promise.race([
7207
7231
  parseAllSessions(getDateRange2("week").range, "all"),
7208
- new Promise((r) => setTimeout(() => r([]), 3e3))
7232
+ new Promise((r) => setTimeout(() => r([]), 500))
7209
7233
  ]),
7210
7234
  Promise.race([
7211
7235
  parseAllSessions(getDateRange2("30days").range, "all"),
7212
- new Promise((r) => setTimeout(() => r([]), 3e3))
7236
+ new Promise((r) => setTimeout(() => r([]), 500))
7213
7237
  ])
7214
7238
  ]);
7215
7239
  projectSpend = buildProjectSpend(allTodayProjects, proj7d, proj30d);
@@ -7217,7 +7241,9 @@ program.command("status").description("Compact status output (today + week + mon
7217
7241
  projectSpend = buildProjectSpend(allTodayProjects, [], []);
7218
7242
  }
7219
7243
  const diagnostics = { daysCount, parseTimeMs, warnings };
7220
- console.log(JSON.stringify(buildMenubarPayload(currentData, providers, optimize, dailyHistory, agentStats, projectSpend, exeOsDetected, statsFileAge, diagnostics)));
7244
+ const payload = buildMenubarPayload(currentData, providers, optimize, dailyHistory, agentStats, projectSpend, exeOsDetected, statsFileAge, diagnostics);
7245
+ const json = JSON.stringify(payload);
7246
+ console.log(json);
7221
7247
  return;
7222
7248
  }
7223
7249
  if (opts.format === "json") {