one-more-token 0.5.0 → 0.5.2

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/main.js CHANGED
@@ -152,9 +152,9 @@ function nullish(input2) {
152
152
  return input2 === null || input2 === void 0;
153
153
  }
154
154
  function cleanRegex(source3) {
155
- const start = source3.startsWith("^") ? 1 : 0;
155
+ const start2 = source3.startsWith("^") ? 1 : 0;
156
156
  const end = source3.endsWith("$") ? source3.length - 1 : source3.length;
157
- return source3.slice(start, end);
157
+ return source3.slice(start2, end);
158
158
  }
159
159
  function floatSafeRemainder(val, step) {
160
160
  const ratio = val / step;
@@ -543,9 +543,9 @@ function sizeCaps(defChecks) {
543
543
  }
544
544
  return caps;
545
545
  }
546
- function attachSchema(issues, start, inst) {
546
+ function attachSchema(issues, start2, inst) {
547
547
  var _a3;
548
- for (let i = start; i < issues.length; i++) {
548
+ for (let i = start2; i < issues.length; i++) {
549
549
  (_a3 = issues[i]).schema ?? (_a3.schema = inst);
550
550
  }
551
551
  }
@@ -2279,10 +2279,10 @@ function capSize(inst, size) {
2279
2279
  if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
2280
2280
  for (const [max, ch] of sizeCaps(inst._zod.def.checks)) {
2281
2281
  if (n > max && ch._zod.def.when(payload)) {
2282
- const start = payload.issues.length;
2282
+ const start2 = payload.issues.length;
2283
2283
  ch._zod.check(payload);
2284
- payload.issues[start].continue = false;
2285
- attachSchema(payload.issues, start, inst);
2284
+ payload.issues[start2].continue = false;
2285
+ attachSchema(payload.issues, start2, inst);
2286
2286
  return payload;
2287
2287
  }
2288
2288
  }
@@ -20901,8 +20901,8 @@ async function readSentAlertKeys(db) {
20901
20901
  );
20902
20902
  return new Set(
20903
20903
  rows.map((row) => {
20904
- const start = new Date(Number(row.ms)).toISOString();
20905
- return alertKey(String(row.alert_id), start);
20904
+ const start2 = new Date(Number(row.ms)).toISOString();
20905
+ return alertKey(String(row.alert_id), start2);
20906
20906
  })
20907
20907
  );
20908
20908
  }
@@ -21015,8 +21015,8 @@ var init_files = __esm({
21015
21015
  const sorted = [...list].sort((a, b) => a.validFrom.localeCompare(b.validFrom));
21016
21016
  for (let i = 1; i < sorted.length; i++) {
21017
21017
  const previousEnd = sorted[i - 1]?.validTo;
21018
- const start = sorted[i]?.validFrom ?? "";
21019
- if (previousEnd === null || previousEnd !== void 0 && previousEnd >= start) {
21018
+ const start2 = sorted[i]?.validFrom ?? "";
21019
+ if (previousEnd === null || previousEnd !== void 0 && previousEnd >= start2) {
21020
21020
  ctx.addIssue({ code: "custom", message: `overlapping validity for ${key2}` });
21021
21021
  }
21022
21022
  }
@@ -22070,11 +22070,11 @@ function rollingSpans(turns, length) {
22070
22070
  function monthlySpans(turns, anchor2, now, active) {
22071
22071
  const byStart = /* @__PURE__ */ new Map();
22072
22072
  const add2 = (ms3) => {
22073
- const { start, end } = monthlySpanAt(anchor2, ms3);
22074
- let span = byStart.get(start);
22073
+ const { start: start2, end } = monthlySpanAt(anchor2, ms3);
22074
+ let span = byStart.get(start2);
22075
22075
  if (!span) {
22076
- span = { start, end, turns: [] };
22077
- byStart.set(start, span);
22076
+ span = { start: start2, end, turns: [] };
22077
+ byStart.set(start2, span);
22078
22078
  }
22079
22079
  return span;
22080
22080
  };
@@ -22247,17 +22247,17 @@ function computeQuotas(input2) {
22247
22247
  now
22248
22248
  );
22249
22249
  });
22250
- const start = Math.max(from, activeFrom ?? from);
22250
+ const start2 = Math.max(from, activeFrom ?? from);
22251
22251
  const end = Math.min(to, activeTo ?? to);
22252
22252
  let apiEquivalentUsd = 0;
22253
22253
  let unpricedTurns = 0;
22254
22254
  for (const turn of own2) {
22255
- if (turn.ms < start || turn.ms >= end) continue;
22255
+ if (turn.ms < start2 || turn.ms >= end) continue;
22256
22256
  if (turn.computedCostUsd === null) unpricedTurns++;
22257
22257
  else apiEquivalentUsd += turn.computedCostUsd;
22258
22258
  }
22259
22259
  const price2 = plan.monthlyPriceUsd ?? null;
22260
- const paidUsd = price2 === null ? null : price2 * Math.max(0, end - start) / AVERAGE_MONTH;
22260
+ const paidUsd = price2 === null ? null : price2 * Math.max(0, end - start2) / AVERAGE_MONTH;
22261
22261
  return [
22262
22262
  {
22263
22263
  id: subscription.id,
@@ -23223,7 +23223,7 @@ var init_db_queue = __esm({
23223
23223
  function summaryPeriod(params, now = Date.now()) {
23224
23224
  const froms = params.getAll("from");
23225
23225
  const tos = params.getAll("to");
23226
- let start = now - 7 * DAY3;
23226
+ let start2 = now - 7 * DAY3;
23227
23227
  let end = now;
23228
23228
  if (froms.length || tos.length) {
23229
23229
  if (froms.length !== 1 || tos.length !== 1) return null;
@@ -23232,12 +23232,12 @@ function summaryPeriod(params, now = Date.now()) {
23232
23232
  if (/\.\d{4,}/.test(value2)) return NaN;
23233
23233
  return Date.parse(value2);
23234
23234
  };
23235
- start = parse4(froms[0]);
23235
+ start2 = parse4(froms[0]);
23236
23236
  end = parse4(tos[0]);
23237
23237
  }
23238
- if (!Number.isFinite(start) || !Number.isFinite(end) || start >= end) return null;
23239
- if ((utcDay(end - 1) - utcDay(start)) / DAY3 + 1 > 366) return null;
23240
- const from = new Date(start).toISOString();
23238
+ if (!Number.isFinite(start2) || !Number.isFinite(end) || start2 >= end) return null;
23239
+ if ((utcDay(end - 1) - utcDay(start2)) / DAY3 + 1 > 366) return null;
23240
+ const from = new Date(start2).toISOString();
23241
23241
  const to = new Date(end).toISOString();
23242
23242
  if (from.length !== 24 || to.length !== 24) return null;
23243
23243
  return { from, to };
@@ -23727,19 +23727,19 @@ var init_url = __esm({
23727
23727
  tryDecodeURI = (str) => tryDecode(str, decodeURI);
23728
23728
  getPath = (request) => {
23729
23729
  const url2 = request.url;
23730
- const start = url2.indexOf("/", url2.indexOf(":") + 4);
23731
- let i = start;
23730
+ const start2 = url2.indexOf("/", url2.indexOf(":") + 4);
23731
+ let i = start2;
23732
23732
  for (; i < url2.length; i++) {
23733
23733
  const charCode = url2.charCodeAt(i);
23734
23734
  if (charCode === 37) {
23735
23735
  const queryIndex = url2.indexOf("?", i);
23736
23736
  const hashIndex = url2.indexOf("#", i);
23737
23737
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
23738
- const path = url2.slice(start, end);
23738
+ const path = url2.slice(start2, end);
23739
23739
  return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
23740
23740
  } else if (charCode === 63 || charCode === 35) break;
23741
23741
  }
23742
- return url2.slice(start, i);
23742
+ return url2.slice(start2, i);
23743
23743
  };
23744
23744
  getPathNoStrict = (request) => {
23745
23745
  const result = getPath(request);
@@ -29035,7 +29035,7 @@ var init_store4 = __esm({
29035
29035
 
29036
29036
  // src/web/static.ts
29037
29037
  import { readFile as readFile3, stat } from "node:fs/promises";
29038
- import { join as join11, normalize as normalize4 } from "node:path";
29038
+ import { join as join11, normalize as normalize4, sep as sep2 } from "node:path";
29039
29039
  import { fileURLToPath as fileURLToPath3 } from "node:url";
29040
29040
  function contentTypeOf(path) {
29041
29041
  const dot = path.lastIndexOf(".");
@@ -29053,7 +29053,7 @@ async function readWebFile(dist, urlPath) {
29053
29053
  if (urlPath.includes("\0")) return null;
29054
29054
  const root2 = normalize4(dist);
29055
29055
  const target = normalize4(join11(root2, urlPath === "/" ? "index.html" : urlPath));
29056
- if (!target.startsWith(root2)) return null;
29056
+ if (!target.startsWith(root2 + sep2)) return null;
29057
29057
  const file2 = await exists(target) ? target : join11(root2, "index.html");
29058
29058
  if (!await exists(file2)) return null;
29059
29059
  return { contentType: contentTypeOf(file2), body: await readFile3(file2, "utf8") };
@@ -29676,8 +29676,8 @@ async function monthlyData(db, period, options) {
29676
29676
  };
29677
29677
  }
29678
29678
  function monthPeriodBefore(period) {
29679
- const start = Date.parse(period.from);
29680
- const date8 = new Date(start);
29679
+ const start2 = Date.parse(period.from);
29680
+ const date8 = new Date(start2);
29681
29681
  const previous = Date.UTC(date8.getUTCFullYear(), date8.getUTCMonth() - 1, 1);
29682
29682
  return { from: new Date(previous).toISOString(), to: period.from };
29683
29683
  }
@@ -29878,11 +29878,11 @@ var init_dist2 = __esm({
29878
29878
  isHttpWhitespace = (code) => code === 9 || code === 10 || code === 13 || code === 32;
29879
29879
  normalizeHeaderValue = (value2) => {
29880
29880
  if (!isHttpWhitespace(value2.charCodeAt(0)) && !isHttpWhitespace(value2.charCodeAt(value2.length - 1))) return value2;
29881
- let start = 0;
29881
+ let start2 = 0;
29882
29882
  let end = value2.length;
29883
- while (start < end && isHttpWhitespace(value2.charCodeAt(start))) start++;
29884
- while (end > start && isHttpWhitespace(value2.charCodeAt(end - 1))) end--;
29885
- return value2.slice(start, end);
29883
+ while (start2 < end && isHttpWhitespace(value2.charCodeAt(start2))) start2++;
29884
+ while (end > start2 && isHttpWhitespace(value2.charCodeAt(end - 1))) end--;
29885
+ return value2.slice(start2, end);
29886
29886
  };
29887
29887
  forbiddenHeaderValue = /[\0\r\n]/;
29888
29888
  GlobalHeaders = globalThis.Headers;
@@ -31154,9 +31154,9 @@ var init_server = __esm({
31154
31154
 
31155
31155
  // src/start.ts
31156
31156
  import { exec } from "node:child_process";
31157
- import { existsSync } from "node:fs";
31157
+ import { existsSync, mkdirSync } from "node:fs";
31158
31158
  import { homedir as homedir4 } from "node:os";
31159
- import { join as join13 } from "node:path";
31159
+ import { dirname as dirname3, join as join13 } from "node:path";
31160
31160
  function defaultOpenBrowser(url2) {
31161
31161
  return new Promise((resolve) => {
31162
31162
  const command = process.platform === "darwin" ? `open ${JSON.stringify(url2)}` : process.platform === "win32" ? `start "" ${JSON.stringify(url2)}` : `xdg-open ${JSON.stringify(url2)}`;
@@ -31211,6 +31211,7 @@ ${detected.join("\n")}
31211
31211
  let db;
31212
31212
  let server;
31213
31213
  try {
31214
+ if (options.db !== ":memory:") mkdirSync(dirname3(options.db), { recursive: true });
31214
31215
  db = await openDatabase(options.db);
31215
31216
  await migrate(db);
31216
31217
  const home = io.env.HOME ?? homedir4();
@@ -31254,8 +31255,6 @@ var init_start = __esm({
31254
31255
  init_src();
31255
31256
  init_app();
31256
31257
  init_service7();
31257
- init_options();
31258
- init_scheduler2();
31259
31258
  init_server();
31260
31259
  init_static();
31261
31260
  EXIT_OK = 0;
@@ -31276,26 +31275,28 @@ __export(cli_exports, {
31276
31275
  USAGE: () => USAGE,
31277
31276
  run: () => run2
31278
31277
  });
31279
- import { mkdirSync } from "node:fs";
31278
+ import { mkdirSync as mkdirSync2 } from "node:fs";
31280
31279
  import { homedir as homedir5 } from "node:os";
31281
- import { dirname as dirname3 } from "node:path";
31280
+ import { dirname as dirname4 } from "node:path";
31282
31281
  async function run2(argv, io, deps = { waitForShutdown: () => waitForSignal() }) {
31283
31282
  const [command, ...args] = argv;
31284
- if (command === void 0 || command === "--help" || command === "-h") {
31283
+ if (command === void 0) return start([], io, deps);
31284
+ if (command === "--help" || command === "-h") {
31285
31285
  io.stdout(USAGE);
31286
31286
  return EXIT_OK2;
31287
31287
  }
31288
31288
  if (command.startsWith("-")) {
31289
- return usageError(io, "omt", `unknown option "${command}"`);
31289
+ if (argv.includes("--help") || argv.includes("-h")) {
31290
+ io.stdout(USAGE);
31291
+ return EXIT_OK2;
31292
+ }
31293
+ return start(argv, io, deps);
31290
31294
  }
31291
31295
  switch (command) {
31292
31296
  case "serve":
31293
31297
  return serveCommand(args, io, deps);
31294
31298
  case "start":
31295
- return startCommand(args, io, {
31296
- waitForShutdown: deps.waitForShutdown ?? (() => waitForSignal()),
31297
- ...deps.openBrowser ? { openBrowser: deps.openBrowser } : {}
31298
- });
31299
+ return start(args, io, deps);
31299
31300
  case "ingest":
31300
31301
  return ingestCommand(args, io, deps);
31301
31302
  case "watch":
@@ -31314,6 +31315,12 @@ ${HELP_HINT}
31314
31315
  `);
31315
31316
  return EXIT_USAGE2;
31316
31317
  }
31318
+ function start(args, io, deps) {
31319
+ return startCommand(args, io, {
31320
+ waitForShutdown: deps.waitForShutdown ?? (() => waitForSignal()),
31321
+ ...deps.openBrowser ? { openBrowser: deps.openBrowser } : {}
31322
+ });
31323
+ }
31317
31324
  async function ingestCommand(args, io, deps) {
31318
31325
  const parsed = parseIngestOptions(args);
31319
31326
  if (!parsed.ok) return usageError(io, "omt ingest", parsed.error);
@@ -31406,7 +31413,7 @@ async function serveCommand(args, io, deps) {
31406
31413
  }
31407
31414
  }
31408
31415
  async function openMigratedDatabase(options) {
31409
- if (options.db !== ":memory:") mkdirSync(dirname3(options.db), { recursive: true });
31416
+ if (options.db !== ":memory:") mkdirSync2(dirname4(options.db), { recursive: true });
31410
31417
  const db = await openDatabase(options.db);
31411
31418
  try {
31412
31419
  await migrate(db);
@@ -31440,7 +31447,10 @@ var init_cli = __esm({
31440
31447
  HELP_HINT = "Run `omt --help` for usage.";
31441
31448
  USAGE = `One More Token: local dashboard for AI coding agent usage.
31442
31449
 
31443
- Usage: omt <command> [options]
31450
+ Usage: omt [<command>] [options]
31451
+
31452
+ With no command, omt runs "start": ingest local metrics, serve the dashboard
31453
+ and open it in the browser.
31444
31454
 
31445
31455
  Commands:
31446
31456
  start Ingest local agent metrics, serve the dashboard and open it in the browser
@@ -31495,10 +31505,10 @@ Global options:
31495
31505
  });
31496
31506
 
31497
31507
  // src/entry-npm.ts
31498
- import { dirname as dirname4, join as join14 } from "node:path";
31508
+ import { dirname as dirname5, join as join14 } from "node:path";
31499
31509
  import { fileURLToPath as fileURLToPath4 } from "node:url";
31500
- var here = dirname4(fileURLToPath4(import.meta.url));
31501
- var root = dirname4(here);
31510
+ var here = dirname5(fileURLToPath4(import.meta.url));
31511
+ var root = dirname5(here);
31502
31512
  process.env.OMT_DATA_DIR ??= join14(root, "data");
31503
31513
  process.env.OMT_WEB_DIST ??= join14(root, "web-dist");
31504
31514
  process.env.OMT_MIGRATIONS_DIR ??= join14(root, "migrations");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "one-more-token",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "One More Token: local dashboard for AI coding agent usage (omt start | serve | ingest | watch)",
5
5
  "license": "MIT",
6
6
  "type": "module",