@liberseek/boft-cli-win32-arm64 0.8.0 → 0.8.1

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.
@@ -27737,6 +27737,8 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
27737
27737
  harness,
27738
27738
  sessionId: external_exports.string().min(1).max(512),
27739
27739
  project: project.nullable(),
27740
+ /** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
27741
+ title: external_exports.string().min(1).max(200).optional(),
27740
27742
  /** Models the session used, most requests first. */
27741
27743
  models: external_exports.array(model).max(16),
27742
27744
  firstAtMs: count,
@@ -27803,7 +27805,12 @@ var usageStatisticsResultSchema = external_exports.strictObject({
27803
27805
  * The sessions that spent the most, by cost and by tokens without cache, all filters applied;
27804
27806
  * requests without a native session are not listed here but count everywhere else.
27805
27807
  */
27806
- sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
27808
+ sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
27809
+ /**
27810
+ * The sessions last active in the range, newest first, all filters applied. Optional for older
27811
+ * Hosts; missing is treated as no list rather than no sessions.
27812
+ */
27813
+ recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
27807
27814
  });
27808
27815
 
27809
27816
  // ../../shared-contracts/dist/ids.js
@@ -4200,6 +4200,20 @@ import { zstdDecompressSync } from "node:zlib";
4200
4200
  // ../../harness-adapter/dist/usage-statistics.js
4201
4201
  var MAX_SESSION_ID_LENGTH = 512;
4202
4202
  var MAX_CWD_LENGTH = 4096;
4203
+ var MAX_SESSION_TITLE_LENGTH = 200;
4204
+ function usageSessionTitle(value) {
4205
+ if (typeof value !== "string")
4206
+ return void 0;
4207
+ const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
4208
+ if (!normalized)
4209
+ return void 0;
4210
+ if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
4211
+ return normalized;
4212
+ const characters = [...normalized];
4213
+ if (characters.length <= MAX_SESSION_TITLE_LENGTH)
4214
+ return normalized;
4215
+ return `${characters.slice(0, MAX_SESSION_TITLE_LENGTH - 1).join("").trimEnd()}…`;
4216
+ }
4203
4217
  function sessionIdOk(value) {
4204
4218
  return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
4205
4219
  }
@@ -4209,12 +4223,14 @@ function cwdOk(value) {
4209
4223
  function withUsageSession(entry, session) {
4210
4224
  const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
4211
4225
  const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
4226
+ const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
4212
4227
  if (sessionId === void 0 && cwd === void 0)
4213
4228
  return entry;
4214
4229
  return {
4215
4230
  ...entry,
4216
4231
  ...sessionId !== void 0 ? { sessionId } : {},
4217
- ...cwd !== void 0 ? { cwd } : {}
4232
+ ...cwd !== void 0 ? { cwd } : {},
4233
+ ...sessionTitle !== void 0 ? { sessionTitle } : {}
4218
4234
  };
4219
4235
  }
4220
4236
  function usageEntryFromRequest(request, occurredAtMs) {
@@ -18904,6 +18920,8 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
18904
18920
  harness,
18905
18921
  sessionId: external_exports.string().min(1).max(512),
18906
18922
  project: project.nullable(),
18923
+ /** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
18924
+ title: external_exports.string().min(1).max(200).optional(),
18907
18925
  /** Models the session used, most requests first. */
18908
18926
  models: external_exports.array(model).max(16),
18909
18927
  firstAtMs: count,
@@ -18970,7 +18988,12 @@ var usageStatisticsResultSchema = external_exports.strictObject({
18970
18988
  * The sessions that spent the most, by cost and by tokens without cache, all filters applied;
18971
18989
  * requests without a native session are not listed here but count everywhere else.
18972
18990
  */
18973
- sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
18991
+ sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
18992
+ /**
18993
+ * The sessions last active in the range, newest first, all filters applied. Optional for older
18994
+ * Hosts; missing is treated as no list rather than no sessions.
18995
+ */
18996
+ recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
18974
18997
  });
18975
18998
 
18976
18999
  // ../../shared-contracts/dist/ids.js
@@ -22170,9 +22193,11 @@ async function readDshUsage(file2) {
22170
22193
  if (entries.length === 0 && line.startsWith('{"type":"session"')) {
22171
22194
  try {
22172
22195
  const header = JSON.parse(line);
22196
+ const title = usageSessionTitle(header.title ?? header.name);
22173
22197
  session = {
22174
22198
  ...typeof header.id === "string" ? { sessionId: header.id } : {},
22175
- ...typeof header.cwd === "string" ? { cwd: header.cwd } : {}
22199
+ ...typeof header.cwd === "string" ? { cwd: header.cwd } : {},
22200
+ ...title ? { title } : {}
22176
22201
  };
22177
22202
  } catch {
22178
22203
  }
@@ -384,6 +384,20 @@ import path4 from "node:path";
384
384
  import { createInterface } from "node:readline";
385
385
  var MAX_SESSION_ID_LENGTH = 512;
386
386
  var MAX_CWD_LENGTH = 4096;
387
+ var MAX_SESSION_TITLE_LENGTH = 200;
388
+ function usageSessionTitle(value) {
389
+ if (typeof value !== "string")
390
+ return void 0;
391
+ const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
392
+ if (!normalized)
393
+ return void 0;
394
+ if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
395
+ return normalized;
396
+ const characters = [...normalized];
397
+ if (characters.length <= MAX_SESSION_TITLE_LENGTH)
398
+ return normalized;
399
+ return `${characters.slice(0, MAX_SESSION_TITLE_LENGTH - 1).join("").trimEnd()}…`;
400
+ }
387
401
  function sessionIdOk(value) {
388
402
  return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
389
403
  }
@@ -393,12 +407,14 @@ function cwdOk(value) {
393
407
  function withUsageSession(entry, session) {
394
408
  const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
395
409
  const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
410
+ const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
396
411
  if (sessionId === void 0 && cwd === void 0)
397
412
  return entry;
398
413
  return {
399
414
  ...entry,
400
415
  ...sessionId !== void 0 ? { sessionId } : {},
401
- ...cwd !== void 0 ? { cwd } : {}
416
+ ...cwd !== void 0 ? { cwd } : {},
417
+ ...sessionTitle !== void 0 ? { sessionTitle } : {}
402
418
  };
403
419
  }
404
420
  async function jsonlUsageSources(root, maxDepth, signal) {
@@ -464,12 +480,18 @@ function count(value) {
464
480
  function grokHome(environment) {
465
481
  return environment.GROK_HOME || path5.join(environment.HOME || os2.homedir(), ".grok");
466
482
  }
467
- async function forkedAtMs(directory) {
483
+ async function grokSummary(directory) {
468
484
  try {
469
485
  const summary = JSON.parse(await readFile(path5.join(directory, "summary.json"), "utf8"));
470
- return isRecord(summary) && typeof summary.parent_session_id === "string" ? nativeTimeMs(summary.created_at) : null;
486
+ if (!isRecord(summary))
487
+ return { forkedAt: null };
488
+ const title = usageSessionTitle(summary.generated_title) ?? usageSessionTitle(summary.session_summary);
489
+ return {
490
+ forkedAt: typeof summary.parent_session_id === "string" ? nativeTimeMs(summary.created_at) : null,
491
+ ...title ? { title } : {}
492
+ };
471
493
  } catch {
472
- return null;
494
+ return { forkedAt: null };
473
495
  }
474
496
  }
475
497
  function grokSession(file2) {
@@ -483,12 +505,18 @@ function grokSession(file2) {
483
505
  return { sessionId: path5.basename(directory), cwd };
484
506
  }
485
507
  async function readGrokUsage(file2, signal) {
486
- const forkedAt = await forkedAtMs(path5.dirname(file2));
508
+ const summary = await grokSummary(path5.dirname(file2));
509
+ const forkedAt = summary.forkedAt;
510
+ let title = summary.title;
487
511
  const session = grokSession(file2);
488
512
  const entries = [];
489
- for await (const line of jsonlRecords(file2, '"turn_completed"', signal)) {
513
+ for await (const line of jsonlRecords(file2, '"sessionUpdate"', signal)) {
490
514
  const params = isRecord(line.params) ? line.params : {};
491
515
  const update = isRecord(params.update) ? params.update : {};
516
+ if (!title && update.sessionUpdate === "user_message_chunk") {
517
+ title = usageSessionTitle(isRecord(update.content) ? update.content.text : void 0);
518
+ continue;
519
+ }
492
520
  const usage = isRecord(update.usage) ? update.usage : {};
493
521
  if (update.sessionUpdate !== "turn_completed" || typeof update.prompt_id !== "string")
494
522
  continue;
@@ -519,7 +547,7 @@ async function readGrokUsage(file2, signal) {
519
547
  // A turn Grok marks incomplete has no cost of its own; it counts as free rather
520
548
  // than as a model without a price.
521
549
  ...ticks !== null ? { costUsd: ticks / USD_TICKS } : usage.usageIsIncomplete === true ? { costUsd: 0 } : {}
522
- }, session));
550
+ }, { ...session, ...title ? { title } : {} }));
523
551
  }
524
552
  }
525
553
  return entries;
@@ -19406,6 +19434,8 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
19406
19434
  harness,
19407
19435
  sessionId: external_exports.string().min(1).max(512),
19408
19436
  project: project.nullable(),
19437
+ /** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
19438
+ title: external_exports.string().min(1).max(200).optional(),
19409
19439
  /** Models the session used, most requests first. */
19410
19440
  models: external_exports.array(model).max(16),
19411
19441
  firstAtMs: count2,
@@ -19472,7 +19502,12 @@ var usageStatisticsResultSchema = external_exports.strictObject({
19472
19502
  * The sessions that spent the most, by cost and by tokens without cache, all filters applied;
19473
19503
  * requests without a native session are not listed here but count everywhere else.
19474
19504
  */
19475
- sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
19505
+ sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
19506
+ /**
19507
+ * The sessions last active in the range, newest first, all filters applied. Optional for older
19508
+ * Hosts; missing is treated as no list rather than no sessions.
19509
+ */
19510
+ recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
19476
19511
  });
19477
19512
 
19478
19513
  // ../../shared-contracts/dist/ids.js
@@ -1138,10 +1138,10 @@ function mergeDefs(...defs) {
1138
1138
  function cloneDef(schema) {
1139
1139
  return mergeDefs(schema._zod.def);
1140
1140
  }
1141
- function getElementAtPath(obj, path8) {
1142
- if (!path8)
1141
+ function getElementAtPath(obj, path9) {
1142
+ if (!path9)
1143
1143
  return obj;
1144
- return path8.reduce((acc, key) => acc?.[key], obj);
1144
+ return path9.reduce((acc, key) => acc?.[key], obj);
1145
1145
  }
1146
1146
  function promiseAllObject(promisesObj) {
1147
1147
  const keys = Object.keys(promisesObj);
@@ -1550,11 +1550,11 @@ function explicitlyAborted(x, startIndex = 0) {
1550
1550
  }
1551
1551
  return false;
1552
1552
  }
1553
- function prefixIssues(path8, issues) {
1553
+ function prefixIssues(path9, issues) {
1554
1554
  return issues.map((iss) => {
1555
1555
  var _a3;
1556
1556
  (_a3 = iss).path ?? (_a3.path = []);
1557
- iss.path.unshift(path8);
1557
+ iss.path.unshift(path9);
1558
1558
  return iss;
1559
1559
  });
1560
1560
  }
@@ -1701,16 +1701,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
1701
1701
  }
1702
1702
  function formatError(error51, mapper = (issue2) => issue2.message) {
1703
1703
  const fieldErrors = { _errors: [] };
1704
- const processError = (error52, path8 = []) => {
1704
+ const processError = (error52, path9 = []) => {
1705
1705
  for (const issue2 of error52.issues) {
1706
1706
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1707
- issue2.errors.map((issues) => processError({ issues }, [...path8, ...issue2.path]));
1707
+ issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
1708
1708
  } else if (issue2.code === "invalid_key") {
1709
- processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
1709
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1710
1710
  } else if (issue2.code === "invalid_element") {
1711
- processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
1711
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1712
1712
  } else {
1713
- const fullpath = [...path8, ...issue2.path];
1713
+ const fullpath = [...path9, ...issue2.path];
1714
1714
  if (fullpath.length === 0) {
1715
1715
  fieldErrors._errors.push(mapper(issue2));
1716
1716
  } else {
@@ -1737,17 +1737,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
1737
1737
  }
1738
1738
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
1739
1739
  const result = { errors: [] };
1740
- const processError = (error52, path8 = []) => {
1740
+ const processError = (error52, path9 = []) => {
1741
1741
  var _a3, _b;
1742
1742
  for (const issue2 of error52.issues) {
1743
1743
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1744
- issue2.errors.map((issues) => processError({ issues }, [...path8, ...issue2.path]));
1744
+ issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
1745
1745
  } else if (issue2.code === "invalid_key") {
1746
- processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
1746
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1747
1747
  } else if (issue2.code === "invalid_element") {
1748
- processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
1748
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1749
1749
  } else {
1750
- const fullpath = [...path8, ...issue2.path];
1750
+ const fullpath = [...path9, ...issue2.path];
1751
1751
  if (fullpath.length === 0) {
1752
1752
  result.errors.push(mapper(issue2));
1753
1753
  continue;
@@ -1779,8 +1779,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
1779
1779
  }
1780
1780
  function toDotPath(_path) {
1781
1781
  const segs = [];
1782
- const path8 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1783
- for (const seg of path8) {
1782
+ const path9 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1783
+ for (const seg of path9) {
1784
1784
  if (typeof seg === "number")
1785
1785
  segs.push(`[${seg}]`);
1786
1786
  else if (typeof seg === "symbol")
@@ -14472,13 +14472,13 @@ function resolveRef(ref, ctx) {
14472
14472
  if (!ref.startsWith("#")) {
14473
14473
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14474
14474
  }
14475
- const path8 = ref.slice(1).split("/").filter(Boolean);
14476
- if (path8.length === 0) {
14475
+ const path9 = ref.slice(1).split("/").filter(Boolean);
14476
+ if (path9.length === 0) {
14477
14477
  return ctx.rootSchema;
14478
14478
  }
14479
14479
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14480
- if (path8[0] === defsKey) {
14481
- const key = path8[1];
14480
+ if (path9[0] === defsKey) {
14481
+ const key = path9[1];
14482
14482
  if (!key || !ctx.defs[key]) {
14483
14483
  throw new Error(`Reference not found: ${ref}`);
14484
14484
  }
@@ -15043,6 +15043,8 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
15043
15043
  harness,
15044
15044
  sessionId: external_exports.string().min(1).max(512),
15045
15045
  project: project.nullable(),
15046
+ /** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
15047
+ title: external_exports.string().min(1).max(200).optional(),
15046
15048
  /** Models the session used, most requests first. */
15047
15049
  models: external_exports.array(model).max(16),
15048
15050
  firstAtMs: count,
@@ -15109,7 +15111,12 @@ var usageStatisticsResultSchema = external_exports.strictObject({
15109
15111
  * The sessions that spent the most, by cost and by tokens without cache, all filters applied;
15110
15112
  * requests without a native session are not listed here but count everywhere else.
15111
15113
  */
15112
- sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
15114
+ sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
15115
+ /**
15116
+ * The sessions last active in the range, newest first, all filters applied. Optional for older
15117
+ * Hosts; missing is treated as no list rather than no sessions.
15118
+ */
15119
+ recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
15113
15120
  });
15114
15121
 
15115
15122
  // ../../shared-contracts/dist/ids.js
@@ -18050,14 +18057,14 @@ function gatewayDiff(text2) {
18050
18057
  if (!text2 || text2.length > 1024 * 1024)
18051
18058
  return [];
18052
18059
  const result = [];
18053
- let path8 = "";
18060
+ let path9 = "";
18054
18061
  let inHunk = false;
18055
18062
  let oldLines = [], newLines = [];
18056
18063
  const flush = () => {
18057
- if (path8)
18064
+ if (path9)
18058
18065
  result.push({
18059
18066
  type: "diff",
18060
- path: path8,
18067
+ path: path9,
18061
18068
  oldText: oldLines.join("\n"),
18062
18069
  newText: newLines.join("\n")
18063
18070
  });
@@ -18070,24 +18077,24 @@ function gatewayDiff(text2) {
18070
18077
  if (header) {
18071
18078
  flush();
18072
18079
  inHunk = false;
18073
- path8 = (header[2] === "/dev/null" ? header[1] ?? "" : header[2] ?? "").replace(/^[ab]\//u, "");
18080
+ path9 = (header[2] === "/dev/null" ? header[1] ?? "" : header[2] ?? "").replace(/^[ab]\//u, "");
18074
18081
  continue;
18075
18082
  }
18076
18083
  if (line.startsWith("--- ") && !inHunk) {
18077
18084
  flush();
18078
- path8 = line.slice(4).replace(/^a\//u, "");
18085
+ path9 = line.slice(4).replace(/^a\//u, "");
18079
18086
  } else if (line.startsWith("+++ ") && !inHunk) {
18080
18087
  const next = line.slice(4);
18081
18088
  if (next !== "/dev/null")
18082
- path8 = next.replace(/^b\//u, "");
18089
+ path9 = next.replace(/^b\//u, "");
18083
18090
  } else if (line.startsWith("@@")) {
18084
18091
  inHunk = true;
18085
18092
  continue;
18086
- } else if (path8 && line.startsWith("-"))
18093
+ } else if (path9 && line.startsWith("-"))
18087
18094
  oldLines.push(line.slice(1));
18088
- else if (path8 && line.startsWith("+"))
18095
+ else if (path9 && line.startsWith("+"))
18089
18096
  newLines.push(line.slice(1));
18090
- else if (path8 && line.startsWith(" ")) {
18097
+ else if (path9 && line.startsWith(" ")) {
18091
18098
  oldLines.push(line.slice(1));
18092
18099
  newLines.push(line.slice(1));
18093
18100
  }
@@ -18511,8 +18518,150 @@ var HermesGatewaySessionTransport = class {
18511
18518
  }
18512
18519
  };
18513
18520
 
18514
- // dist/gateway-open.js
18521
+ // dist/usage-statistics.js
18522
+ import os3 from "node:os";
18515
18523
  import path7 from "node:path";
18524
+ import { lstat } from "node:fs/promises";
18525
+
18526
+ // ../../harness-adapter/dist/usage-statistics.js
18527
+ var MAX_SESSION_ID_LENGTH = 512;
18528
+ var MAX_CWD_LENGTH = 4096;
18529
+ var MAX_SESSION_TITLE_LENGTH = 200;
18530
+ function usageSessionTitle(value) {
18531
+ if (typeof value !== "string")
18532
+ return void 0;
18533
+ const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
18534
+ if (!normalized)
18535
+ return void 0;
18536
+ if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
18537
+ return normalized;
18538
+ const characters = [...normalized];
18539
+ if (characters.length <= MAX_SESSION_TITLE_LENGTH)
18540
+ return normalized;
18541
+ return `${characters.slice(0, MAX_SESSION_TITLE_LENGTH - 1).join("").trimEnd()}…`;
18542
+ }
18543
+ function sessionIdOk(value) {
18544
+ return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
18545
+ }
18546
+ function cwdOk(value) {
18547
+ return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
18548
+ }
18549
+ function withUsageSession(entry, session) {
18550
+ const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
18551
+ const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
18552
+ const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
18553
+ if (sessionId === void 0 && cwd === void 0)
18554
+ return entry;
18555
+ return {
18556
+ ...entry,
18557
+ ...sessionId !== void 0 ? { sessionId } : {},
18558
+ ...cwd !== void 0 ? { cwd } : {},
18559
+ ...sessionTitle !== void 0 ? { sessionTitle } : {}
18560
+ };
18561
+ }
18562
+ function usageEntryFromRequest(request, occurredAtMs) {
18563
+ if (!Number.isSafeInteger(occurredAtMs) || occurredAtMs <= 0)
18564
+ return null;
18565
+ return {
18566
+ id: request.requestId,
18567
+ occurredAtMs,
18568
+ ...request.model !== void 0 ? { model: request.model } : {},
18569
+ inputTokens: request.inputTokens,
18570
+ ...request.cachedInputTokens !== void 0 ? { cachedInputTokens: request.cachedInputTokens } : {},
18571
+ ...request.cacheWriteInputTokens !== void 0 ? { cacheWriteInputTokens: request.cacheWriteInputTokens } : {},
18572
+ ...request.cacheWrite1hInputTokens !== void 0 ? { cacheWrite1hInputTokens: request.cacheWrite1hInputTokens } : {},
18573
+ outputTokens: request.outputTokens,
18574
+ ...request.reasoningOutputTokens !== void 0 ? { reasoningOutputTokens: request.reasoningOutputTokens } : {}
18575
+ };
18576
+ }
18577
+
18578
+ // dist/usage-statistics.js
18579
+ function hermesStateDatabasePath(environment) {
18580
+ const home = environment.HOME || environment.USERPROFILE || os3.homedir();
18581
+ const configured = environment.HERMES_HOME;
18582
+ return path7.resolve(configured ? path7.join(configured, "state.db") : path7.join(home, ".hermes", "state.db"));
18583
+ }
18584
+ async function fingerprint(file2) {
18585
+ const info = await lstat(file2).catch(() => null);
18586
+ if (!info?.isFile())
18587
+ return null;
18588
+ const wal = await lstat(`${file2}-wal`).catch(() => null);
18589
+ return `${info.ino}:${info.size}:${info.mtimeMs}:${wal ? `${wal.size}:${wal.mtimeMs}` : "-"}`;
18590
+ }
18591
+ function tokenCount(value) {
18592
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
18593
+ }
18594
+ function hermesUsageEntry(row) {
18595
+ const apiCalls = tokenCount(row.api_call_count) ? row.api_call_count : 0;
18596
+ const input = tokenCount(row.input_tokens) ? row.input_tokens : 0;
18597
+ const output = tokenCount(row.output_tokens) ? row.output_tokens : 0;
18598
+ const cacheRead = tokenCount(row.cache_read_tokens) ? row.cache_read_tokens : 0;
18599
+ const cacheWrite = tokenCount(row.cache_write_tokens) ? row.cache_write_tokens : 0;
18600
+ const reasoning = tokenCount(row.reasoning_tokens) ? row.reasoning_tokens : 0;
18601
+ if (apiCalls === 0 && input === 0 && output === 0 && cacheRead === 0 && cacheWrite === 0) {
18602
+ return null;
18603
+ }
18604
+ const id = typeof row.id === "string" && row.id.length > 0 ? row.id : null;
18605
+ const epochSeconds = (value) => {
18606
+ if (typeof value !== "number" || !Number.isFinite(value))
18607
+ return null;
18608
+ const ms = Math.floor(value * 1e3);
18609
+ return Number.isSafeInteger(ms) && !Number.isNaN(new Date(ms).getTime()) ? ms : null;
18610
+ };
18611
+ const at = epochSeconds(row.last_activity_at) ?? epochSeconds(row.started_at);
18612
+ if (id === null || at === null)
18613
+ return null;
18614
+ const request = {
18615
+ requestId: id,
18616
+ ...typeof row.model === "string" && row.model.length > 0 ? { model: row.model } : {},
18617
+ inputTokens: input + cacheRead + cacheWrite,
18618
+ outputTokens: output,
18619
+ ...reasoning > 0 ? { reasoningOutputTokens: reasoning } : {},
18620
+ // Both buckets exist whenever either does: the writer records them as a pair.
18621
+ ...cacheRead > 0 || cacheWrite > 0 ? { cachedInputTokens: cacheRead, cacheWriteInputTokens: cacheWrite } : {}
18622
+ };
18623
+ const entry = usageEntryFromRequest(request, at);
18624
+ if (!entry)
18625
+ return null;
18626
+ return withUsageSession(entry, {
18627
+ sessionId: id,
18628
+ cwd: typeof row.cwd === "string" ? row.cwd : void 0,
18629
+ title: usageSessionTitle(row.title ?? row.display_name)
18630
+ });
18631
+ }
18632
+ var SESSIONS_QUERY = `
18633
+ SELECT id, model, cwd, title, display_name, started_at, last_activity_at,
18634
+ api_call_count, input_tokens, output_tokens, cache_read_tokens,
18635
+ cache_write_tokens, reasoning_tokens
18636
+ FROM sessions`;
18637
+ async function readHermesUsage(file2) {
18638
+ const { DatabaseSync } = await import("node:sqlite");
18639
+ const database = new DatabaseSync(file2, { readOnly: true });
18640
+ try {
18641
+ const entries = [];
18642
+ for (const row of database.prepare(SESSIONS_QUERY).iterate()) {
18643
+ const entry = hermesUsageEntry(row);
18644
+ if (entry)
18645
+ entries.push(entry);
18646
+ }
18647
+ return entries;
18648
+ } finally {
18649
+ database.close();
18650
+ }
18651
+ }
18652
+ function createHermesUsageStatistics(environment) {
18653
+ return Object.freeze({
18654
+ async listSources() {
18655
+ const file2 = hermesStateDatabasePath(environment);
18656
+ const stamp = await fingerprint(file2);
18657
+ return stamp ? [{ id: file2, fingerprint: stamp }] : [];
18658
+ },
18659
+ readSource: (id) => readHermesUsage(id)
18660
+ });
18661
+ }
18662
+
18663
+ // dist/gateway-open.js
18664
+ import path8 from "node:path";
18516
18665
  import { realpath } from "node:fs/promises";
18517
18666
 
18518
18667
  // dist/hermes-session.js
@@ -18722,16 +18871,16 @@ var Diff = class {
18722
18871
  }
18723
18872
  }
18724
18873
  }
18725
- addToPath(path8, added, removed, oldPosInc, options) {
18726
- const last = path8.lastComponent;
18874
+ addToPath(path9, added, removed, oldPosInc, options) {
18875
+ const last = path9.lastComponent;
18727
18876
  if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
18728
18877
  return {
18729
- oldPos: path8.oldPos + oldPosInc,
18878
+ oldPos: path9.oldPos + oldPosInc,
18730
18879
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
18731
18880
  };
18732
18881
  } else {
18733
18882
  return {
18734
- oldPos: path8.oldPos + oldPosInc,
18883
+ oldPos: path9.oldPos + oldPosInc,
18735
18884
  lastComponent: { count: 1, added, removed, previousComponent: last }
18736
18885
  };
18737
18886
  }
@@ -19046,8 +19195,8 @@ function hermesFileChanges(update) {
19046
19195
  for (const block of update.content ?? []) {
19047
19196
  if (block.type !== "diff")
19048
19197
  continue;
19049
- const { path: path8, oldText, newText } = block;
19050
- if (!path8.trim() || /[\0\r\n]/u.test(path8) || typeof newText !== "string")
19198
+ const { path: path9, oldText, newText } = block;
19199
+ if (!path9.trim() || /[\0\r\n]/u.test(path9) || typeof newText !== "string")
19051
19200
  continue;
19052
19201
  if (oldText === newText)
19053
19202
  continue;
@@ -19055,10 +19204,10 @@ function hermesFileChanges(update) {
19055
19204
  if (bytes > MAX_DIFF_BYTES || changes.length === MAX_DIFFS)
19056
19205
  return [];
19057
19206
  changes.push({
19058
- path: path8,
19207
+ path: path9,
19059
19208
  kind: "update",
19060
19209
  diffScope: "fragment",
19061
- unifiedDiff: createTwoFilesPatch(path8, path8, oldText ?? "", newText, "", "", {
19210
+ unifiedDiff: createTwoFilesPatch(path9, path9, oldText ?? "", newText, "", "", {
19062
19211
  context: 3
19063
19212
  })
19064
19213
  });
@@ -19861,7 +20010,7 @@ ${reason}` }
19861
20010
 
19862
20011
  // dist/gateway-open.js
19863
20012
  async function sameDirectory(left, right) {
19864
- return await realpath(left).catch(() => path7.resolve(left)) === await realpath(right).catch(() => path7.resolve(right));
20013
+ return await realpath(left).catch(() => path8.resolve(left)) === await realpath(right).catch(() => path8.resolve(right));
19865
20014
  }
19866
20015
  var gatewayCapabilities = {
19867
20016
  configuration: {
@@ -20003,8 +20152,10 @@ var HermesAdapter = class {
20003
20152
  #gatewayTransports = /* @__PURE__ */ new Set();
20004
20153
  #gatewayProbes = /* @__PURE__ */ new Map();
20005
20154
  #openingNativeIds = /* @__PURE__ */ new Set();
20155
+ usageStatistics;
20006
20156
  constructor(options = {}) {
20007
20157
  this.#options = options;
20158
+ this.usageStatistics = createHermesUsageStatistics(options.environment ?? process.env);
20008
20159
  }
20009
20160
  async inspect(input = {}) {
20010
20161
  const cwd = input.cwd ?? process.cwd();
@@ -15163,6 +15163,8 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
15163
15163
  harness,
15164
15164
  sessionId: external_exports.string().min(1).max(512),
15165
15165
  project: project.nullable(),
15166
+ /** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
15167
+ title: external_exports.string().min(1).max(200).optional(),
15166
15168
  /** Models the session used, most requests first. */
15167
15169
  models: external_exports.array(model).max(16),
15168
15170
  firstAtMs: count,
@@ -15229,7 +15231,12 @@ var usageStatisticsResultSchema = external_exports.strictObject({
15229
15231
  * The sessions that spent the most, by cost and by tokens without cache, all filters applied;
15230
15232
  * requests without a native session are not listed here but count everywhere else.
15231
15233
  */
15232
- sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
15234
+ sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
15235
+ /**
15236
+ * The sessions last active in the range, newest first, all filters applied. Optional for older
15237
+ * Hosts; missing is treated as no list rather than no sessions.
15238
+ */
15239
+ recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
15233
15240
  });
15234
15241
 
15235
15242
  // ../../shared-contracts/dist/ids.js
@@ -15022,6 +15022,8 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
15022
15022
  harness,
15023
15023
  sessionId: external_exports.string().min(1).max(512),
15024
15024
  project: project.nullable(),
15025
+ /** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
15026
+ title: external_exports.string().min(1).max(200).optional(),
15025
15027
  /** Models the session used, most requests first. */
15026
15028
  models: external_exports.array(model).max(16),
15027
15029
  firstAtMs: count,
@@ -15088,7 +15090,12 @@ var usageStatisticsResultSchema = external_exports.strictObject({
15088
15090
  * The sessions that spent the most, by cost and by tokens without cache, all filters applied;
15089
15091
  * requests without a native session are not listed here but count everywhere else.
15090
15092
  */
15091
- sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
15093
+ sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
15094
+ /**
15095
+ * The sessions last active in the range, newest first, all filters applied. Optional for older
15096
+ * Hosts; missing is treated as no list rather than no sessions.
15097
+ */
15098
+ recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
15092
15099
  });
15093
15100
 
15094
15101
  // ../../shared-contracts/dist/ids.js
@@ -14931,6 +14931,8 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
14931
14931
  harness,
14932
14932
  sessionId: external_exports.string().min(1).max(512),
14933
14933
  project: project.nullable(),
14934
+ /** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
14935
+ title: external_exports.string().min(1).max(200).optional(),
14934
14936
  /** Models the session used, most requests first. */
14935
14937
  models: external_exports.array(model).max(16),
14936
14938
  firstAtMs: count,
@@ -14997,7 +14999,12 @@ var usageStatisticsResultSchema = external_exports.strictObject({
14997
14999
  * The sessions that spent the most, by cost and by tokens without cache, all filters applied;
14998
15000
  * requests without a native session are not listed here but count everywhere else.
14999
15001
  */
15000
- sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
15002
+ sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
15003
+ /**
15004
+ * The sessions last active in the range, newest first, all filters applied. Optional for older
15005
+ * Hosts; missing is treated as no list rather than no sessions.
15006
+ */
15007
+ recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
15001
15008
  });
15002
15009
 
15003
15010
  // ../../shared-contracts/dist/ids.js