exe-watcher 0.2.7 → 0.2.9

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,12 +6730,61 @@ 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
+ var ALL_TIME_HISTORY_DAYS = 365;
6738
+ var THIRTY_DAY_HISTORY_DAYS = 30;
6739
+ var WEEK_HISTORY_DAYS = 7;
6740
+ function resolveColdStartHistoryDays(period, now = /* @__PURE__ */ new Date()) {
6741
+ switch (period) {
6742
+ case "today":
6743
+ return 1;
6744
+ case "week":
6745
+ return WEEK_HISTORY_DAYS;
6746
+ case "30days":
6747
+ return THIRTY_DAY_HISTORY_DAYS;
6748
+ case "month":
6749
+ return Math.max(now.getDate(), 1);
6750
+ case "all":
6751
+ return ALL_TIME_HISTORY_DAYS;
6752
+ }
6753
+ }
6754
+ function nextLocalMidnight(dateString) {
6755
+ return new Date(
6756
+ parseInt(dateString.slice(0, 4), 10),
6757
+ parseInt(dateString.slice(5, 7), 10) - 1,
6758
+ parseInt(dateString.slice(8, 10), 10) + 1
6759
+ );
6760
+ }
6761
+ function computeProgressiveBackfillStart({
6762
+ lastComputedDate,
6763
+ todayStart,
6764
+ yesterdayEnd,
6765
+ backfillDays,
6766
+ coldStartHistoryDays = DEFAULT_COLD_START_HISTORY_DAYS,
6767
+ progressiveChunkDays = DEFAULT_PROGRESSIVE_CHUNK_DAYS
6768
+ }) {
6769
+ const fullBackfillStart = new Date(todayStart.getTime() - backfillDays * MS_PER_DAY3);
6770
+ if (!lastComputedDate) {
6771
+ const priorHistoryDays = Math.max(coldStartHistoryDays - 1, 0);
6772
+ return new Date(todayStart.getTime() - priorHistoryDays * MS_PER_DAY3);
6773
+ }
6774
+ const gapStart = nextLocalMidnight(lastComputedDate);
6775
+ if (gapStart < fullBackfillStart) return fullBackfillStart;
6776
+ if (yesterdayEnd.getTime() - gapStart.getTime() > progressiveChunkDays * MS_PER_DAY3) {
6777
+ return new Date(yesterdayEnd.getTime() - progressiveChunkDays * MS_PER_DAY3);
6778
+ }
6779
+ return gapStart;
6780
+ }
6781
+
6733
6782
  // src/cli.ts
6734
6783
  import { createRequire as createRequire2 } from "module";
6735
6784
  var require2 = createRequire2(import.meta.url);
6736
6785
  var { version } = require2("../package.json");
6737
- var MS_PER_DAY3 = 24 * 60 * 60 * 1e3;
6738
- var BACKFILL_DAYS = 365;
6786
+ var MS_PER_DAY4 = 24 * 60 * 60 * 1e3;
6787
+ var BACKFILL_DAYS = ALL_TIME_HISTORY_DAYS;
6739
6788
  function toDateString(date) {
6740
6789
  return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
6741
6790
  }
@@ -6765,8 +6814,8 @@ function getDateRange2(period) {
6765
6814
  return { range: { start, end }, label: "Last 30 Days" };
6766
6815
  }
6767
6816
  case "all": {
6768
- const start = new Date(now.getFullYear(), now.getMonth() - 6, now.getDate());
6769
- return { range: { start, end }, label: "Last 6 months" };
6817
+ const start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - (ALL_TIME_HISTORY_DAYS - 1));
6818
+ return { range: { start, end }, label: "All Time" };
6770
6819
  }
6771
6820
  default: {
6772
6821
  const start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 6);
@@ -7015,9 +7064,10 @@ program.command("status").description("Compact status output (today + week + mon
7015
7064
  if (opts.format === "menubar-json") {
7016
7065
  const periodInfo = getDateRange2(opts.period);
7017
7066
  const now = /* @__PURE__ */ new Date();
7067
+ const selectedPeriodHistoryDays = resolveColdStartHistoryDays(opts.period, now);
7018
7068
  const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
7019
7069
  const yesterdayEnd = new Date(todayStart.getTime() - 1);
7020
- const yesterdayStr = toDateString(new Date(todayStart.getTime() - MS_PER_DAY3));
7070
+ const yesterdayStr = toDateString(new Date(todayStart.getTime() - MS_PER_DAY4));
7021
7071
  const isAllProviders = pf === "all";
7022
7072
  const dailyCacheScope = buildDailyCacheScopeKey(opts.project, opts.exclude);
7023
7073
  const cache = await withDailyCacheLock(async () => {
@@ -7028,16 +7078,14 @@ program.command("status").description("Compact status output (today + week + mon
7028
7078
  const latestFresh = freshDays.length > 0 ? freshDays[freshDays.length - 1].date : null;
7029
7079
  c = { ...c, days: freshDays, lastComputedDate: latestFresh };
7030
7080
  }
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()) {
7081
+ const effectiveGapStart = computeProgressiveBackfillStart({
7082
+ lastComputedDate: c.lastComputedDate,
7083
+ todayStart,
7084
+ yesterdayEnd,
7085
+ backfillDays: BACKFILL_DAYS,
7086
+ coldStartHistoryDays: selectedPeriodHistoryDays
7087
+ });
7088
+ if (effectiveGapStart.getTime() <= yesterdayEnd.getTime()) {
7041
7089
  const gapRange = { start: effectiveGapStart, end: yesterdayEnd };
7042
7090
  const gapProjects = filterProjectsByName(await parseAllSessions(gapRange, "all"), opts.project, opts.exclude);
7043
7091
  const gapDays = fillMissingDays(gapRange.start, gapRange.end, aggregateProjectsIntoDays(gapProjects));
@@ -7116,7 +7164,7 @@ program.command("status").description("Compact status output (today + week + mon
7116
7164
  const display = displayNameByName.get(pf) ?? pf;
7117
7165
  providers.push({ name: display, cost: currentData.cost });
7118
7166
  }
7119
- const historyStartStr = toDateString(new Date(todayStart.getTime() - BACKFILL_DAYS * MS_PER_DAY3));
7167
+ const historyStartStr = toDateString(new Date(todayStart.getTime() - BACKFILL_DAYS * MS_PER_DAY4));
7120
7168
  const allCacheDays = getDaysInRange(cache, historyStartStr, yesterdayStr);
7121
7169
  const fullHistory = [...allCacheDays, ...todayDays.filter((d) => d.date > yesterdayStr)];
7122
7170
  const dailyHistory = fullHistory.map((d) => {