modelstat 0.0.29 → 0.0.30

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.mjs CHANGED
@@ -47031,6 +47031,26 @@ async function sendHeartbeat() {
47031
47031
  }
47032
47032
  } catch {
47033
47033
  }
47034
+ writeLocalStatus(body).catch(() => void 0);
47035
+ }
47036
+ async function writeLocalStatus(snapshot) {
47037
+ const { homedir: homedir9 } = await import("os");
47038
+ const { join: join11 } = await import("path");
47039
+ const { writeFile, mkdir: mkdir2, rename } = await import("fs/promises");
47040
+ if (!lastStatusPath) {
47041
+ const dir = join11(homedir9(), ".modelstat");
47042
+ try {
47043
+ await mkdir2(dir, { recursive: true });
47044
+ } catch {
47045
+ }
47046
+ lastStatusPath = join11(dir, "last-status.json");
47047
+ }
47048
+ const tmp = `${lastStatusPath}.tmp`;
47049
+ try {
47050
+ await writeFile(tmp, JSON.stringify({ ...snapshot, written_at: (/* @__PURE__ */ new Date()).toISOString() }));
47051
+ await rename(tmp, lastStatusPath);
47052
+ } catch {
47053
+ }
47034
47054
  }
47035
47055
  async function runDiscovery() {
47036
47056
  const deviceId = state.deviceId;
@@ -47174,7 +47194,7 @@ async function runDaemon(opts = {}) {
47174
47194
  await new Promise(() => {
47175
47195
  });
47176
47196
  }
47177
- var import_undici2, AGENT_VERSION2, HEARTBEAT_INTERVAL_MS, SCAN_INTERVAL_MS, status;
47197
+ var import_undici2, AGENT_VERSION2, HEARTBEAT_INTERVAL_MS, SCAN_INTERVAL_MS, status, lastStatusPath;
47178
47198
  var init_daemon = __esm({
47179
47199
  "src/daemon.ts"() {
47180
47200
  "use strict";
@@ -47214,6 +47234,7 @@ var init_daemon = __esm({
47214
47234
  stats: {},
47215
47235
  lastEventAt: null
47216
47236
  };
47237
+ lastStatusPath = null;
47217
47238
  }
47218
47239
  });
47219
47240
 
@@ -47989,15 +48010,34 @@ function fmtTokens(v) {
47989
48010
  if (n >= 1e3) return `${(n / 1e3).toFixed(0)}K`;
47990
48011
  return String(n);
47991
48012
  }
48013
+ async function readLocalStatus() {
48014
+ try {
48015
+ const { homedir: homedir9 } = await import("os");
48016
+ const { join: join11 } = await import("path");
48017
+ const { readFile } = await import("fs/promises");
48018
+ const p = join11(homedir9(), ".modelstat", "last-status.json");
48019
+ const txt = await readFile(p, "utf8");
48020
+ return JSON.parse(txt);
48021
+ } catch {
48022
+ return null;
48023
+ }
48024
+ }
47992
48025
  async function cmdStats(args) {
47993
48026
  const asJson = args.includes("--json");
47994
48027
  const claim = state.claimCode;
48028
+ const local = await readLocalStatus();
47995
48029
  if (!claim) {
47996
48030
  if (asJson) {
47997
- process.stdout.write(`${JSON.stringify({ paired: false, reason: "no_claim_code" })}
47998
- `);
48031
+ process.stdout.write(
48032
+ `${JSON.stringify({
48033
+ paired: false,
48034
+ reason: "no_claim_code",
48035
+ local
48036
+ })}
48037
+ `
48038
+ );
47999
48039
  } else {
48000
- console.log("no claim code on record \u2014 run `modelstat connect` first");
48040
+ console.log("no claim code on record \u2014 run `npx modelstat@latest` first");
48001
48041
  }
48002
48042
  return;
48003
48043
  }
@@ -48006,17 +48046,27 @@ async function cmdStats(args) {
48006
48046
  const dashboard = `${state.apiUrl.replace(/\/$/, "")}/dashboard`;
48007
48047
  if (asJson) {
48008
48048
  process.stdout.write(
48009
- `${JSON.stringify({ paired: true, claimed: true, dashboard })}
48049
+ `${JSON.stringify({
48050
+ paired: true,
48051
+ claimed: true,
48052
+ dashboard,
48053
+ local
48054
+ })}
48010
48055
  `
48011
48056
  );
48012
48057
  } else {
48013
48058
  console.log("device is claimed \u2014 live stats available at:");
48014
48059
  console.log(` ${dashboard}`);
48060
+ if (local) {
48061
+ console.log(`local agent: ${local.status ?? "?"}${local.message ? ` \xB7 ${local.message}` : ""}`);
48062
+ const stats = local.stats ?? {};
48063
+ for (const [k, v] of Object.entries(stats)) console.log(` ${k}: ${v}`);
48064
+ }
48015
48065
  }
48016
48066
  return;
48017
48067
  }
48018
48068
  if (asJson) {
48019
- process.stdout.write(`${JSON.stringify(view)}
48069
+ process.stdout.write(`${JSON.stringify({ ...view, local })}
48020
48070
  `);
48021
48071
  return;
48022
48072
  }