modelstat 0.0.51 → 0.0.52

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
@@ -46813,7 +46813,7 @@ var init_scan = __esm({
46813
46813
  init_api();
46814
46814
  init_config2();
46815
46815
  init_pipeline2();
46816
- AGENT_VERSION = true ? "agent-0.0.51" : "agent-dev";
46816
+ AGENT_VERSION = true ? "agent-0.0.52" : "agent-dev";
46817
46817
  BATCH_MAX_EVENTS = INGEST_BATCH_MAX_EVENTS;
46818
46818
  BATCH_MAX_TOOL_CALLS = 2e4;
46819
46819
  BATCH_BUFFER_HARD_CAP = BATCH_MAX_EVENTS * 2;
@@ -49313,7 +49313,7 @@ var init_daemon = __esm({
49313
49313
  init_machine_key();
49314
49314
  init_scan();
49315
49315
  init_single_flight();
49316
- AGENT_VERSION2 = true ? "agent-0.0.51" : "agent-dev";
49316
+ AGENT_VERSION2 = true ? "agent-0.0.52" : "agent-dev";
49317
49317
  HEARTBEAT_INTERVAL_MS = 1e4;
49318
49318
  SCAN_INTERVAL_MS = 5 * 60 * 1e3;
49319
49319
  DISCOVERY_INTERVAL_MS = 6e4;
@@ -49438,12 +49438,12 @@ init_config2();
49438
49438
  init_identity();
49439
49439
  init_machine_key();
49440
49440
  init_scan();
49441
- import { spawn } from "child_process";
49441
+ import { spawn as spawn2 } from "child_process";
49442
49442
  import { arch as cpuArch, hostname as hostname2, platform as platform5, release } from "os";
49443
49443
  import { createInterface as createInterface3 } from "readline";
49444
49444
 
49445
49445
  // src/service.ts
49446
- import { spawnSync as spawnSync2 } from "child_process";
49446
+ import { spawn, spawnSync as spawnSync2 } from "child_process";
49447
49447
  import {
49448
49448
  copyFileSync,
49449
49449
  existsSync as existsSync9,
@@ -49518,10 +49518,7 @@ function installNativeRuntime(sourceCli) {
49518
49518
  const dest = binDir();
49519
49519
  try {
49520
49520
  const have = JSON.parse(
49521
- readFileSync4(
49522
- join7(dest, "node_modules", "node-llama-cpp", "package.json"),
49523
- "utf8"
49524
- )
49521
+ readFileSync4(join7(dest, "node_modules", "node-llama-cpp", "package.json"), "utf8")
49525
49522
  );
49526
49523
  if (have.version === version) return [`node-llama-cpp@${version} (cached)`];
49527
49524
  } catch {
@@ -49757,7 +49754,7 @@ function installTrayApp(sourceAppPath) {
49757
49754
  }
49758
49755
  return { installedAt: dest };
49759
49756
  }
49760
- function bundledTrayAppPath() {
49757
+ async function bundledTrayAppPath(progress) {
49761
49758
  if (platform3() !== "darwin") return null;
49762
49759
  const here2 = dirname6(fileURLToPath2(import.meta.url));
49763
49760
  const candidates = [
@@ -49769,22 +49766,53 @@ function bundledTrayAppPath() {
49769
49766
  for (const c of candidates) {
49770
49767
  if (existsSync9(c)) return c;
49771
49768
  }
49772
- const sourceDirs = [
49773
- join7(here2, "..", "vendor", "tray-mac"),
49774
- join7(here2, "..", "..", "tray-mac")
49775
- ];
49769
+ const sourceDirs = [join7(here2, "..", "vendor", "tray-mac"), join7(here2, "..", "..", "tray-mac")];
49776
49770
  for (const src of sourceDirs) {
49777
49771
  const build = join7(src, "build-app.sh");
49778
49772
  if (!existsSync9(build)) continue;
49779
49773
  if (!hasSwift()) return null;
49780
- const r = spawnSync2("bash", [build], { cwd: src, encoding: "utf8" });
49781
- if (r.status === 0) {
49774
+ const code = await runTrayBuild(src, build, progress);
49775
+ if (code === 0) {
49782
49776
  const app = join7(src, "build", "ModelstatTray.app");
49783
49777
  if (existsSync9(app)) return app;
49784
49778
  }
49785
49779
  }
49786
49780
  return null;
49787
49781
  }
49782
+ function createLineSplitter(onLine) {
49783
+ let buf = "";
49784
+ return {
49785
+ push(chunk) {
49786
+ buf += chunk;
49787
+ for (; ; ) {
49788
+ const nl = buf.indexOf("\n");
49789
+ if (nl === -1) break;
49790
+ const line = buf.slice(0, nl).trimEnd();
49791
+ buf = buf.slice(nl + 1);
49792
+ if (line) onLine(line);
49793
+ }
49794
+ },
49795
+ flush() {
49796
+ const line = buf.trim();
49797
+ buf = "";
49798
+ if (line) onLine(line);
49799
+ }
49800
+ };
49801
+ }
49802
+ function runTrayBuild(cwd, buildScript, progress) {
49803
+ return new Promise((resolve6) => {
49804
+ const child = spawn("bash", [buildScript], { cwd });
49805
+ const splitter = createLineSplitter((line) => progress?.onLine?.(line));
49806
+ const pump = (chunk) => splitter.push(chunk.toString("utf8"));
49807
+ child.stdout?.on("data", pump);
49808
+ child.stderr?.on("data", pump);
49809
+ child.on("error", () => resolve6(null));
49810
+ child.on("close", (code) => {
49811
+ splitter.flush();
49812
+ resolve6(code);
49813
+ });
49814
+ });
49815
+ }
49788
49816
  function hasSwift() {
49789
49817
  const r = spawnSync2("swift", ["--version"], { encoding: "utf8" });
49790
49818
  return r.status === 0;
@@ -49868,7 +49896,7 @@ function tryOpenBrowser(url) {
49868
49896
  const cmd = p === "darwin" ? "open" : p === "win32" ? "cmd" : "xdg-open";
49869
49897
  const args = p === "win32" ? ["/c", "start", "", url] : [url];
49870
49898
  try {
49871
- const child = spawn(cmd, args, {
49899
+ const child = spawn2(cmd, args, {
49872
49900
  stdio: "ignore",
49873
49901
  detached: true
49874
49902
  });
@@ -49878,7 +49906,7 @@ function tryOpenBrowser(url) {
49878
49906
  return false;
49879
49907
  }
49880
49908
  }
49881
- var AGENT_VERSION3 = true ? "agent-0.0.51" : "agent-dev";
49909
+ var AGENT_VERSION3 = true ? "agent-0.0.52" : "agent-dev";
49882
49910
  function osFamily() {
49883
49911
  const p = platform5();
49884
49912
  if (p === "darwin") return "macos";
@@ -49973,6 +50001,54 @@ function emitEvent(opts, event, fields = {}) {
49973
50001
  process.stdout.write(`${JSON.stringify({ v: 1, ts: Date.now(), event, ...fields })}
49974
50002
  `);
49975
50003
  }
50004
+ function createTrayBuildUi(opts) {
50005
+ const isTty = !opts.json && process.stdout.isTTY === true;
50006
+ let startedAt = null;
50007
+ let ticker = null;
50008
+ const paintTicker = () => {
50009
+ if (startedAt === null) return;
50010
+ const s = Math.round((Date.now() - startedAt) / 1e3);
50011
+ process.stdout.write(`\r \x1B[2m\u23F3 compiling menu-bar tray from source\u2026 ${s}s\x1B[0m\x1B[K`);
50012
+ };
50013
+ const begin = () => {
50014
+ if (startedAt !== null) return;
50015
+ startedAt = Date.now();
50016
+ emitEvent(opts, "tray_build_started", {});
50017
+ if (!opts.json) {
50018
+ process.stdout.write(
50019
+ " \x1B[2mno prebuilt tray found \u2014 compiling a small Swift app locally (first run only, ~1 min)\x1B[0m\n"
50020
+ );
50021
+ }
50022
+ if (isTty) {
50023
+ paintTicker();
50024
+ ticker = setInterval(paintTicker, 1e3);
50025
+ ticker.unref?.();
50026
+ }
50027
+ };
50028
+ return {
50029
+ onLine: (line) => {
50030
+ begin();
50031
+ emitEvent(opts, "tray_build_progress", { line });
50032
+ if (isTty) {
50033
+ process.stdout.write(`\r\x1B[K \x1B[2m${line}\x1B[0m
50034
+ `);
50035
+ } else if (!opts.json) {
50036
+ process.stdout.write(` ${line}
50037
+ `);
50038
+ }
50039
+ },
50040
+ finish: () => {
50041
+ if (ticker) {
50042
+ clearInterval(ticker);
50043
+ ticker = null;
50044
+ }
50045
+ if (isTty && startedAt !== null) process.stdout.write("\r\x1B[K");
50046
+ const elapsed = startedAt === null ? null : Date.now() - startedAt;
50047
+ if (elapsed !== null) emitEvent(opts, "tray_build_done", { elapsed_ms: elapsed });
50048
+ return elapsed;
50049
+ }
50050
+ };
50051
+ }
49976
50052
  async function cmdConnect(opts) {
49977
50053
  const step = (msg) => {
49978
50054
  if (opts.json) return;
@@ -50045,12 +50121,18 @@ async function cmdConnect(opts) {
50045
50121
  });
50046
50122
  if (platform5() === "darwin") {
50047
50123
  step("Installing menu-bar tray (macOS)");
50124
+ const buildUi = createTrayBuildUi(opts);
50048
50125
  try {
50049
- const src = bundledTrayAppPath();
50126
+ const src = await bundledTrayAppPath({ onLine: buildUi.onLine });
50127
+ const buildMs = buildUi.finish();
50050
50128
  if (src) {
50129
+ if (buildMs !== null) ok(`tray compiled from source in ${Math.round(buildMs / 1e3)}s`);
50051
50130
  const out = installTrayApp(src);
50052
50131
  if (out) {
50053
- emitEvent(opts, "tray_installed", { path: out.installedAt });
50132
+ emitEvent(opts, "tray_installed", {
50133
+ path: out.installedAt,
50134
+ ...buildMs !== null ? { build_ms: buildMs } : {}
50135
+ });
50054
50136
  ok(`tray at ${out.installedAt}`);
50055
50137
  }
50056
50138
  } else {
@@ -50058,6 +50140,7 @@ async function cmdConnect(opts) {
50058
50140
  warn("no bundled tray \u2014 skipping (install Xcode CLI tools and re-run to get the icon)");
50059
50141
  }
50060
50142
  } catch (e) {
50143
+ buildUi.finish();
50061
50144
  emitEvent(opts, "tray_install_failed", { error: e.message });
50062
50145
  warn(`tray install skipped: ${e.message}`);
50063
50146
  }