tokmon 0.3.4 → 0.4.0

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.
Files changed (2) hide show
  1. package/dist/cli.js +27 -14
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -227,6 +227,19 @@ function isoWeekLabel(ts) {
227
227
  function monthLabel(ts) {
228
228
  return new Date(ts).toISOString().slice(0, 7);
229
229
  }
230
+ function findBlockStart(entries, now) {
231
+ const recent = entries.filter((e) => e.ts <= now).sort((a, b) => a.ts - b.ts);
232
+ if (recent.length === 0) return 0;
233
+ const GAP = 30 * 6e4;
234
+ let blockStart = recent[0].ts;
235
+ for (let i = 1; i < recent.length; i++) {
236
+ if (recent[i].ts - recent[i - 1].ts > GAP) {
237
+ blockStart = recent[i].ts;
238
+ }
239
+ }
240
+ if (now - blockStart > 5 * 36e5) return 0;
241
+ return blockStart;
242
+ }
230
243
  async function fetchDashboard() {
231
244
  const now = Date.now();
232
245
  const d = /* @__PURE__ */ new Date();
@@ -235,17 +248,20 @@ async function fetchDashboard() {
235
248
  const weekDay = d.getDay();
236
249
  const weekStart = new Date(d.getFullYear(), d.getMonth(), d.getDate() - (weekDay === 0 ? 6 : weekDay - 1)).getTime();
237
250
  const entries = await loadEntries(monthStart);
238
- const fiveHoursAgo = now - 5 * 36e5;
239
- const blockEntries = entries.filter((e) => e.ts >= fiveHoursAgo);
240
251
  let block = null;
241
- if (blockEntries.length > 0) {
242
- const spent = blockEntries.reduce((s, e) => s + e.cost, 0);
243
- const oldest = Math.min(...blockEntries.map((e) => e.ts));
244
- const elapsedHrs = (now - oldest) / 36e5;
245
- const burnRate = elapsedHrs > 0 ? spent / elapsedHrs : 0;
246
- const remainMs = Math.max(0, oldest + 5 * 36e5 - now);
247
- const percent = Math.min(100, (now - oldest) / (5 * 36e5) * 100);
248
- block = { spent, projected: burnRate * 5, burnRate, percent, remaining: minutes(remainMs / 6e4) };
252
+ const blockStart = findBlockStart(entries, now);
253
+ if (blockStart > 0) {
254
+ const blockEnd = blockStart + 5 * 36e5;
255
+ const blockEntries = entries.filter((e) => e.ts >= blockStart && e.ts < blockEnd);
256
+ if (blockEntries.length > 0) {
257
+ const spent = blockEntries.reduce((s, e) => s + e.cost, 0);
258
+ const elapsedMs = now - blockStart;
259
+ const elapsedHrs = elapsedMs / 36e5;
260
+ const burnRate = elapsedHrs > 0 ? spent / elapsedHrs : 0;
261
+ const remainMs = Math.max(0, blockEnd - now);
262
+ const percent = Math.min(100, elapsedMs / (5 * 36e5) * 100);
263
+ block = { spent, projected: burnRate * 5, burnRate, percent, remaining: minutes(remainMs / 6e4) };
264
+ }
249
265
  }
250
266
  return {
251
267
  today: sum(entries.filter((e) => e.ts >= todayStart)),
@@ -292,9 +308,6 @@ function App({ interval: cliInterval }) {
292
308
  setConfig(c);
293
309
  });
294
310
  }, []);
295
- useEffect(() => {
296
- if (stdout) stdout.write("\x1B[2J\x1B[H");
297
- }, [tab, view, showSettings]);
298
311
  useEffect(() => {
299
312
  let active = true;
300
313
  const load = async () => {
@@ -447,7 +460,7 @@ function App({ interval: cliInterval }) {
447
460
  if (error) return /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(Text, { color: "red", children: error }) });
448
461
  if (!dashboard) return /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: "Loading..." }) });
449
462
  const tableData = table ? [table.daily, table.weekly, table.monthly][view] : [];
450
- return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
463
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, minHeight: rows, children: [
451
464
  /* @__PURE__ */ jsxs(Box, { justifyContent: "space-between", children: [
452
465
  /* @__PURE__ */ jsxs(Box, { children: [
453
466
  /* @__PURE__ */ jsxs(Text, { bold: true, color: "greenBright", children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokmon",
3
- "version": "0.3.4",
3
+ "version": "0.4.0",
4
4
  "description": "Terminal dashboard for Claude Code usage and costs",
5
5
  "type": "module",
6
6
  "bin": {