@kvali/cli 0.7.7 → 0.7.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kvali",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "Live progress for Claude Code: plan progress, the current step and the time left, what the agent is doing right now, tokens and your plan limits, in a pane beside the chat.",
5
5
  "author": { "name": "Giorgi Khiladze" },
6
6
  "homepage": "https://github.com/webGrandpa/kvali",
package/dist/kvali.mjs CHANGED
@@ -89,6 +89,16 @@ function restOfPlan(typical, spent, left) {
89
89
  function fmtClock(ms) {
90
90
  return new Date(ms).toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" });
91
91
  }
92
+ function limitStopText(stop, now) {
93
+ const what = `Stopped at the ${stop.limit}`;
94
+ if (stop.resetsAt === void 0) return what;
95
+ const when = fmtWhen(stop.resetsAt, now);
96
+ return stop.resetsAt > now ? `${what} \xB7 resets at ${when}` : `${what} \xB7 it reset at ${when}`;
97
+ }
98
+ function fmtWhen(ms, now) {
99
+ if (Math.abs(ms - now) < 20 * 36e5) return fmtClock(ms);
100
+ return `${new Date(ms).toLocaleDateString(void 0, { weekday: "short", day: "numeric", month: "short" })} ${fmtClock(ms)}`;
101
+ }
92
102
  function fmtAbout(ms) {
93
103
  const m = Math.max(1, Math.round(ms / 6e4));
94
104
  return m < 60 ? `~${m}m` : `~${Math.floor(m / 60)}h ${String(m % 60).padStart(2, "0")}m`;
@@ -1646,6 +1656,106 @@ function loopKey(a) {
1646
1656
  return a.kind === "command" ? `command:${a.detail ?? a.label}` : `${a.label}:${a.detail ?? ""}`;
1647
1657
  }
1648
1658
 
1659
+ // ../core/src/util/limit-stop.ts
1660
+ var LIMIT_TEXT = /^(?:You've hit your|You've reached your|You're out of usage credits|Claude AI usage limit reached)/i;
1661
+ var LIMIT_NAMES = {
1662
+ five_hour: "5-hour limit",
1663
+ seven_day: "weekly limit",
1664
+ seven_day_opus: "Opus limit",
1665
+ seven_day_sonnet: "Sonnet limit",
1666
+ seven_day_overage_included: "Fable limit",
1667
+ overage: "usage credit limit"
1668
+ };
1669
+ var toMs = (v) => v < 1e12 ? v * 1e3 : v;
1670
+ function limitStopOf(record, text, at) {
1671
+ const t = text.trim();
1672
+ const isLimit = record.apiError === "usage_limit_reached" || LIMIT_TEXT.test(t) || record.error === "rate_limit" && /\blimit\b/i.test(t) && !/rate limited/i.test(t);
1673
+ if (!isLimit) return void 0;
1674
+ const info = record.apiErrorParams?.rate_limit_info;
1675
+ let resetsAt = typeof info?.resetsAt === "number" && info.resetsAt > 0 ? toMs(info.resetsAt) : void 0;
1676
+ resetsAt ??= parseResetsAt(t, at);
1677
+ const named = typeof info?.rateLimitType === "string" ? LIMIT_NAMES[info.rateLimitType] : void 0;
1678
+ const said = /^You've (?:hit|reached) your (.+?)(?:\s+·|\.|$)/i.exec(t)?.[1]?.trim();
1679
+ return { at, limit: named ?? (said && said.length <= 40 ? said : "usage limit"), resetsAt };
1680
+ }
1681
+ var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
1682
+ var DAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
1683
+ function validZone(tz) {
1684
+ if (!tz) return void 0;
1685
+ try {
1686
+ new Intl.DateTimeFormat("en-US", { timeZone: tz });
1687
+ return tz;
1688
+ } catch {
1689
+ return void 0;
1690
+ }
1691
+ }
1692
+ function wall(t, tz) {
1693
+ const parts = new Intl.DateTimeFormat("en-US", {
1694
+ timeZone: tz,
1695
+ hourCycle: "h23",
1696
+ year: "numeric",
1697
+ month: "numeric",
1698
+ day: "numeric",
1699
+ hour: "numeric",
1700
+ minute: "numeric",
1701
+ weekday: "short"
1702
+ }).formatToParts(new Date(t));
1703
+ const get = (type) => parts.find((p2) => p2.type === type)?.value ?? "";
1704
+ return {
1705
+ y: Number(get("year")),
1706
+ mo: Number(get("month")) - 1,
1707
+ d: Number(get("day")),
1708
+ h: Number(get("hour")) % 24,
1709
+ mi: Number(get("minute")),
1710
+ wd: DAYS.indexOf(get("weekday").slice(0, 3).toLowerCase())
1711
+ };
1712
+ }
1713
+ function instant(y, mo, d, h, mi, tz) {
1714
+ const want = Date.UTC(y, mo, d, h, mi);
1715
+ let t = want;
1716
+ for (let i = 0; i < 3; i += 1) {
1717
+ const w = wall(t, tz);
1718
+ const diff = want - Date.UTC(w.y, w.mo, w.d, w.h, w.mi);
1719
+ if (diff === 0) break;
1720
+ t += diff;
1721
+ }
1722
+ return t;
1723
+ }
1724
+ function parseResetsAt(text, at) {
1725
+ const legacy = /usage limit reached\|(\d{10,13})/i.exec(text);
1726
+ if (legacy) return toMs(Number(legacy[1]));
1727
+ const rel2 = /\bresets?\s+in\s+(?:(\d+)\s*d(?:ays?)?\s*)?(?:(\d+)\s*h(?:ours?|rs?)?\s*)?(?:(\d+)\s*m(?:in(?:ute)?s?)?)?/i.exec(text);
1728
+ if (rel2 && (rel2[1] || rel2[2] || rel2[3])) return at + ((Number(rel2[1] ?? 0) * 24 + Number(rel2[2] ?? 0)) * 60 + Number(rel2[3] ?? 0)) * 6e4;
1729
+ const m = /\bresets?\s+(?:on\s+)?(?:(sun|mon|tue|wed|thu|fri|sat)[a-z]*,?\s+)?(?:(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?\s+(\d{1,2})(?:st|nd|rd|th)?,?\s+)?(?:at\s+)?(\d{1,2})(?::(\d{2}))?\s*(am|pm)?(?:\s*\(([^)]+)\))?/i.exec(
1730
+ text
1731
+ );
1732
+ if (!m) return void 0;
1733
+ let h = Number(m[4]);
1734
+ const mi = Number(m[5] ?? 0);
1735
+ const ampm = m[6]?.toLowerCase();
1736
+ if (ampm) {
1737
+ if (h < 1 || h > 12) return void 0;
1738
+ h = h % 12 + (ampm === "pm" ? 12 : 0);
1739
+ } else if (!m[5] || h > 23) {
1740
+ return void 0;
1741
+ }
1742
+ if (mi > 59) return void 0;
1743
+ const tz = validZone(m[7]?.trim()) ?? Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
1744
+ const now = wall(at, tz);
1745
+ if (m[2]) {
1746
+ const mo = MONTHS.indexOf(m[2].toLowerCase());
1747
+ const d = Number(m[3]);
1748
+ let t2 = instant(now.y, mo, d, h, mi, tz);
1749
+ if (t2 < at - 864e5) t2 = instant(now.y + 1, mo, d, h, mi, tz);
1750
+ return t2;
1751
+ }
1752
+ let days = 0;
1753
+ if (m[1]) days = (DAYS.indexOf(m[1].toLowerCase()) - now.wd + 7) % 7;
1754
+ let t = instant(now.y, now.mo, now.d + days, h, mi, tz);
1755
+ if (t <= at) t = instant(now.y, now.mo, now.d + days + (m[1] ? 7 : 1), h, mi, tz);
1756
+ return t;
1757
+ }
1758
+
1649
1759
  // ../core/src/adapters/claude-code.ts
1650
1760
  var PULSE_FRESH_MS = 3e4;
1651
1761
  var PULSE_ACTIVE = /* @__PURE__ */ new Set(["requesting", "thinking", "writing", "tool-input", "running", "needs-you", "stalled"]);
@@ -1892,7 +2002,10 @@ var ClaudeCodeAdapter = class {
1892
2002
  if (st.lastRecordAt === void 0 || ts > st.lastRecordAt) st.lastRecordAt = ts;
1893
2003
  }
1894
2004
  if (typeof o.version === "string") st.version = o.version;
1895
- if (typeof o.entrypoint === "string") st.entrypoint = o.entrypoint;
2005
+ if (typeof o.entrypoint === "string") {
2006
+ st.entrypoint = o.entrypoint;
2007
+ if (o.entrypoint !== "cli" && /vscode|jetbrains|ide/.test(o.entrypoint)) st.ranInEditor = true;
2008
+ }
1896
2009
  if (typeof o.cwd === "string" && o.cwd) {
1897
2010
  st.cwd = o.cwd;
1898
2011
  st.launchCwd ??= o.cwd;
@@ -2000,8 +2113,20 @@ var ClaudeCodeAdapter = class {
2000
2113
  if (typeof m.model === "string" && m.model !== "<synthetic>") st.model = m.model;
2001
2114
  st.lastModelAt = ts;
2002
2115
  this.countUsage(st, o, ts, ctx, true);
2003
- if (m.model !== "<synthetic>") st.trouble = void 0;
2116
+ if (m.model !== "<synthetic>") {
2117
+ st.trouble = void 0;
2118
+ st.limitStop = void 0;
2119
+ }
2004
2120
  if (o.isApiErrorMessage || o.error && m.model === "<synthetic>") {
2121
+ const limit = limitStopOf(o, contentText(m.content), ts);
2122
+ if (limit) {
2123
+ st.limitStop = limit;
2124
+ st.phase = "idle";
2125
+ st.phaseAt = ts;
2126
+ st.open.clear();
2127
+ this.endTurn(st, ts, void 0);
2128
+ return;
2129
+ }
2005
2130
  st.phase = "error";
2006
2131
  st.phaseAt = ts;
2007
2132
  st.errorText = firstLine(contentText(m.content) || "API error", 120);
@@ -2154,6 +2279,7 @@ var ClaudeCodeAdapter = class {
2154
2279
  st.turnOpen = true;
2155
2280
  st.turnEndedBy = void 0;
2156
2281
  st.loops.reset();
2282
+ st.limitStop = void 0;
2157
2283
  }
2158
2284
  if (!isCommand) {
2159
2285
  st.phase = "working";
@@ -2359,6 +2485,10 @@ var ClaudeCodeAdapter = class {
2359
2485
  if (beat.phase === "interrupted") detail = "Interrupted";
2360
2486
  else if (beat.phase === "error") detail = st.errorText ?? "Stopped with an error";
2361
2487
  }
2488
+ if (st.limitStop && status !== "working" && status !== "waiting" && status !== "stale") {
2489
+ status = "idle";
2490
+ detail = limitStopText(st.limitStop, now);
2491
+ }
2362
2492
  if (status === "working") {
2363
2493
  const stale = staleness(lastSignal, ctx);
2364
2494
  if (stale) {
@@ -2385,8 +2515,10 @@ var ClaudeCodeAdapter = class {
2385
2515
  model: st.model,
2386
2516
  agentVersion: st.version,
2387
2517
  host: st.entrypoint === void 0 ? void 0 : st.entrypoint === "cli" ? "terminal" : /vscode|jetbrains|ide/.test(st.entrypoint) ? "editor" : "app",
2518
+ ranInEditor: st.ranInEditor || void 0,
2388
2519
  status,
2389
2520
  statusDetail: detail,
2521
+ limitStop: st.limitStop && status === "idle" ? { ...st.limitStop } : void 0,
2390
2522
  startedAt: st.startedAt,
2391
2523
  updatedAt: Math.max(st.updatedAt, live?.at ?? 0),
2392
2524
  tasks,
@@ -3396,9 +3528,14 @@ function describeCodexCall(name, args, at) {
3396
3528
  }
3397
3529
  return { kind: "tool", label: name, startedAt: at };
3398
3530
  }
3531
+ var RESUMED_DAYS = 90;
3532
+ var RESUMED_SCAN_MS = 6e4;
3399
3533
  var CodexAdapter = class extends JsonlSessionAdapter {
3400
3534
  /** The account's plan windows, from every session's readings. */
3401
3535
  limitBook = new LimitBook();
3536
+ /** Rollouts in older day folders that were written lately: sessions resumed since they began. */
3537
+ resumed = [];
3538
+ resumedAt = -Infinity;
3402
3539
  limits(ctx) {
3403
3540
  const windows = this.limitBook.windows(ctx.now());
3404
3541
  return windows.length ? { agent: this.id, agentLabel: this.label, windows } : void 0;
@@ -3418,18 +3555,48 @@ var CodexAdapter = class extends JsonlSessionAdapter {
3418
3555
  dirs.add(path7.join(root, String(d.getUTCFullYear()), pad(d.getUTCMonth() + 1), pad(d.getUTCDate())));
3419
3556
  }
3420
3557
  const out = [];
3558
+ const seen = /* @__PURE__ */ new Set();
3421
3559
  for (const dir of dirs) {
3422
3560
  for (const f of await listDir(dir)) {
3423
3561
  if (!f.isFile() || !f.name.startsWith("rollout-") || !f.name.endsWith(".jsonl")) continue;
3424
3562
  const file = path7.join(dir, f.name);
3425
3563
  const st = await statSafe(file);
3426
- if (st) out.push({ path: file, mtimeMs: st.mtimeMs });
3564
+ if (st) {
3565
+ out.push({ path: file, mtimeMs: st.mtimeMs });
3566
+ seen.add(file);
3567
+ }
3427
3568
  }
3428
3569
  }
3570
+ if (now - this.resumedAt >= RESUMED_SCAN_MS) {
3571
+ this.resumedAt = now;
3572
+ const found = [];
3573
+ for (let i = days + 1; i <= RESUMED_DAYS; i += 1) {
3574
+ const d = new Date(now - i * 864e5);
3575
+ const pad = (n) => String(n).padStart(2, "0");
3576
+ for (const dir of /* @__PURE__ */ new Set([
3577
+ path7.join(root, String(d.getFullYear()), pad(d.getMonth() + 1), pad(d.getDate())),
3578
+ path7.join(root, String(d.getUTCFullYear()), pad(d.getUTCMonth() + 1), pad(d.getUTCDate()))
3579
+ ])) {
3580
+ if (dirs.has(dir)) continue;
3581
+ for (const f of await listDir(dir)) {
3582
+ if (!f.isFile() || !f.name.startsWith("rollout-") || !f.name.endsWith(".jsonl")) continue;
3583
+ const file = path7.join(dir, f.name);
3584
+ const st = await statSafe(file);
3585
+ if (st && now - st.mtimeMs < ctx.activeWindowMs) found.push(file);
3586
+ }
3587
+ }
3588
+ }
3589
+ this.resumed = found;
3590
+ }
3591
+ for (const file of this.resumed) {
3592
+ if (seen.has(file)) continue;
3593
+ const st = await statSafe(file);
3594
+ if (st) out.push({ path: file, mtimeMs: st.mtimeMs });
3595
+ }
3429
3596
  return out;
3430
3597
  }
3431
3598
  createState(file) {
3432
- const m = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/i.exec(file);
3599
+ const m = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})?\.jsonl$/i.exec(file);
3433
3600
  const daily = {};
3434
3601
  return {
3435
3602
  file,
@@ -8819,7 +8986,7 @@ function qrTerminal(text, color = true) {
8819
8986
  }
8820
8987
 
8821
8988
  // src/index.ts
8822
- var VERSION = "0.7.7";
8989
+ var VERSION = "0.7.8";
8823
8990
  function parse(argv) {
8824
8991
  const opts = {
8825
8992
  json: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kvali/cli",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "Live progress, time left, tokens, plan limits and phone alerts for AI coding agents (Claude Code, Codex, Gemini CLI, Antigravity, Copilot, Cline, Roo Code, Kilo Code, OpenCode), in your terminal.",
5
5
  "license": "MIT",
6
6
  "author": "Giorgi Khiladze (https://github.com/webGrandpa)",