@threadbase-sh/streamer 1.70.5 → 1.70.6

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.cjs CHANGED
@@ -127837,7 +127837,7 @@ function uidScope() {
127837
127837
  function resolveOwnLabel() {
127838
127838
  if (process.env.LAUNCHD_LABEL) return process.env.LAUNCHD_LABEL;
127839
127839
  try {
127840
- (0, import_node_child_process5.execFileSync)("launchctl", ["print", `${uidScope()}/homebrew.mxcl.tb-streamer`], {
127840
+ (0, import_node_child_process6.execFileSync)("launchctl", ["print", `${uidScope()}/homebrew.mxcl.tb-streamer`], {
127841
127841
  stdio: "ignore"
127842
127842
  });
127843
127843
  return "homebrew.mxcl.tb-streamer";
@@ -127847,7 +127847,7 @@ function resolveOwnLabel() {
127847
127847
  }
127848
127848
  function isLabelLoaded(label) {
127849
127849
  try {
127850
- (0, import_node_child_process5.execFileSync)("launchctl", ["list", label], { stdio: "ignore" });
127850
+ (0, import_node_child_process6.execFileSync)("launchctl", ["list", label], { stdio: "ignore" });
127851
127851
  return true;
127852
127852
  } catch {
127853
127853
  return false;
@@ -127867,7 +127867,7 @@ function detectConflictingAgents() {
127867
127867
  }
127868
127868
  }
127869
127869
  try {
127870
- const out = (0, import_node_child_process5.execFileSync)("launchctl", ["list"], {
127870
+ const out = (0, import_node_child_process6.execFileSync)("launchctl", ["list"], {
127871
127871
  stdio: ["ignore", "pipe", "ignore"]
127872
127872
  }).toString();
127873
127873
  for (const line of out.split("\n")) {
@@ -127900,11 +127900,11 @@ function formatConflictMessage(conflicts) {
127900
127900
  );
127901
127901
  return lines.join("\n");
127902
127902
  }
127903
- var import_node_child_process5, KNOWN_STREAMER_LABELS, LEGACY_PATTERN;
127903
+ var import_node_child_process6, KNOWN_STREAMER_LABELS, LEGACY_PATTERN;
127904
127904
  var init_conflict_check = __esm({
127905
127905
  "src/lifecycle/conflict-check.ts"() {
127906
127906
  "use strict";
127907
- import_node_child_process5 = require("child_process");
127907
+ import_node_child_process6 = require("child_process");
127908
127908
  init_constants();
127909
127909
  KNOWN_STREAMER_LABELS = [
127910
127910
  "com.ronen.threadbase",
@@ -127932,7 +127932,7 @@ function uidScope2() {
127932
127932
  function resolveLoadedLabel() {
127933
127933
  if (process.env.LAUNCHD_LABEL) return process.env.LAUNCHD_LABEL;
127934
127934
  try {
127935
- (0, import_node_child_process6.execFileSync)("launchctl", ["print", `${uidScope2()}/${BREW_LAUNCHD_LABEL2}`], {
127935
+ (0, import_node_child_process7.execFileSync)("launchctl", ["print", `${uidScope2()}/${BREW_LAUNCHD_LABEL2}`], {
127936
127936
  stdio: "ignore"
127937
127937
  });
127938
127938
  return BREW_LAUNCHD_LABEL2;
@@ -127945,7 +127945,7 @@ function fullTarget() {
127945
127945
  }
127946
127946
  function isAgentLoaded() {
127947
127947
  try {
127948
- (0, import_node_child_process6.execFileSync)("launchctl", ["list", resolveLoadedLabel()], { stdio: "ignore" });
127948
+ (0, import_node_child_process7.execFileSync)("launchctl", ["list", resolveLoadedLabel()], { stdio: "ignore" });
127949
127949
  return true;
127950
127950
  } catch {
127951
127951
  return false;
@@ -127953,7 +127953,7 @@ function isAgentLoaded() {
127953
127953
  }
127954
127954
  function bootoutAgent(timeoutMs = 2e3) {
127955
127955
  try {
127956
- (0, import_node_child_process6.execFileSync)("launchctl", ["bootout", fullTarget()], { stdio: "ignore" });
127956
+ (0, import_node_child_process7.execFileSync)("launchctl", ["bootout", fullTarget()], { stdio: "ignore" });
127957
127957
  } catch {
127958
127958
  }
127959
127959
  const deadline = Date.now() + timeoutMs;
@@ -127964,7 +127964,7 @@ function bootoutAgent(timeoutMs = 2e3) {
127964
127964
  }
127965
127965
  function bootstrapAgent(plistPath, opts) {
127966
127966
  try {
127967
- (0, import_node_child_process6.execFileSync)("launchctl", ["bootstrap", uidScope2(), plistPath], {
127967
+ (0, import_node_child_process7.execFileSync)("launchctl", ["bootstrap", uidScope2(), plistPath], {
127968
127968
  stdio: ["ignore", "ignore", "pipe"]
127969
127969
  });
127970
127970
  } catch (err) {
@@ -127977,7 +127977,7 @@ function bootstrapAgent(plistPath, opts) {
127977
127977
  }
127978
127978
  }
127979
127979
  function kickstartAgent() {
127980
- (0, import_node_child_process6.execFileSync)("launchctl", ["kickstart", "-k", fullTarget()], { stdio: "ignore" });
127980
+ (0, import_node_child_process7.execFileSync)("launchctl", ["kickstart", "-k", fullTarget()], { stdio: "ignore" });
127981
127981
  }
127982
127982
  function darwinPlistPath() {
127983
127983
  return `${process.env.HOME}/Library/LaunchAgents/${resolveLoadedLabel()}.plist`;
@@ -127987,7 +127987,7 @@ function getLogPaths() {
127987
127987
  }
127988
127988
  function getAgentPid() {
127989
127989
  try {
127990
- const out = (0, import_node_child_process6.execFileSync)("launchctl", ["list"], {
127990
+ const out = (0, import_node_child_process7.execFileSync)("launchctl", ["list"], {
127991
127991
  stdio: ["ignore", "pipe", "ignore"]
127992
127992
  }).toString();
127993
127993
  const label = resolveLoadedLabel();
@@ -128003,11 +128003,11 @@ function getAgentPid() {
128003
128003
  return null;
128004
128004
  }
128005
128005
  }
128006
- var import_node_child_process6, BREW_LAUNCHD_LABEL2;
128006
+ var import_node_child_process7, BREW_LAUNCHD_LABEL2;
128007
128007
  var init_launchd = __esm({
128008
128008
  "src/lifecycle/launchd.ts"() {
128009
128009
  "use strict";
128010
- import_node_child_process6 = require("child_process");
128010
+ import_node_child_process7 = require("child_process");
128011
128011
  init_constants();
128012
128012
  BREW_LAUNCHD_LABEL2 = "homebrew.mxcl.tb-streamer";
128013
128013
  }
@@ -128079,7 +128079,7 @@ __export(task_scheduler_exports, {
128079
128079
  kickstartAgent: () => kickstartAgent2
128080
128080
  });
128081
128081
  function ps2(command) {
128082
- return (0, import_node_child_process7.execFileSync)("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
128082
+ return (0, import_node_child_process8.execFileSync)("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
128083
128083
  stdio: ["ignore", "pipe", "ignore"]
128084
128084
  }).toString();
128085
128085
  }
@@ -128123,11 +128123,11 @@ function getAgentPid2() {
128123
128123
  return null;
128124
128124
  }
128125
128125
  }
128126
- var import_node_child_process7;
128126
+ var import_node_child_process8;
128127
128127
  var init_task_scheduler = __esm({
128128
128128
  "src/lifecycle/task-scheduler.ts"() {
128129
128129
  "use strict";
128130
- import_node_child_process7 = require("child_process");
128130
+ import_node_child_process8 = require("child_process");
128131
128131
  init_constants();
128132
128132
  }
128133
128133
  });
@@ -128512,7 +128512,7 @@ __export(repo_exports, {
128512
128512
  });
128513
128513
  function getGitToplevel(cwd) {
128514
128514
  try {
128515
- return (0, import_node_child_process9.execFileSync)("git", ["rev-parse", "--show-toplevel"], {
128515
+ return (0, import_node_child_process10.execFileSync)("git", ["rev-parse", "--show-toplevel"], {
128516
128516
  cwd,
128517
128517
  stdio: ["ignore", "pipe", "ignore"]
128518
128518
  }).toString().trim();
@@ -128520,11 +128520,11 @@ function getGitToplevel(cwd) {
128520
128520
  return null;
128521
128521
  }
128522
128522
  }
128523
- var import_node_child_process9;
128523
+ var import_node_child_process10;
128524
128524
  var init_repo = __esm({
128525
128525
  "src/lifecycle/repo.ts"() {
128526
128526
  "use strict";
128527
- import_node_child_process9 = require("child_process");
128527
+ import_node_child_process10 = require("child_process");
128528
128528
  }
128529
128529
  });
128530
128530
 
@@ -153141,6 +153141,7 @@ function pruneAgentConversations(cache) {
153141
153141
  }
153142
153142
 
153143
153143
  // src/services/host-pressure/hostPressure.ts
153144
+ var import_node_child_process4 = require("child_process");
153144
153145
  var import_os16 = require("os");
153145
153146
  var import_perf_hooks = require("perf_hooks");
153146
153147
  var HOST_PRESSURE_SAMPLE_MS = 5e3;
@@ -153175,6 +153176,59 @@ var HOST_PRESSURE_BARS = {
153175
153176
  };
153176
153177
  var REASON_ORDER = ["memory", "event_loop", "load", "agents"];
153177
153178
  var RANK = { ok: 0, elevated: 1, critical: 2 };
153179
+ function parseMacMemoryPressureFreeRatio(output) {
153180
+ const match2 = output.match(/System-wide memory free percentage:\s*(\d+(?:\.\d+)?)%/);
153181
+ if (!match2) return void 0;
153182
+ const percentage = Number(match2[1]);
153183
+ return percentage <= 100 ? percentage / 100 : void 0;
153184
+ }
153185
+ function runMacMemoryPressure() {
153186
+ return new Promise((resolve4, reject) => {
153187
+ (0, import_node_child_process4.execFile)(
153188
+ "/usr/bin/memory_pressure",
153189
+ ["-Q"],
153190
+ { encoding: "utf8", timeout: 1e3 },
153191
+ (error51, stdout2) => {
153192
+ if (error51) {
153193
+ reject(error51);
153194
+ return;
153195
+ }
153196
+ resolve4(stdout2);
153197
+ }
153198
+ );
153199
+ });
153200
+ }
153201
+ async function readMacMemoryPressureFreeRatio(run2 = runMacMemoryPressure) {
153202
+ try {
153203
+ return parseMacMemoryPressureFreeRatio(await run2());
153204
+ } catch {
153205
+ return void 0;
153206
+ }
153207
+ }
153208
+ var MacMemoryPressureProbe = class {
153209
+ constructor(read) {
153210
+ this.read = read;
153211
+ }
153212
+ read;
153213
+ current;
153214
+ pending = false;
153215
+ refresh() {
153216
+ if (this.pending) return;
153217
+ this.pending = true;
153218
+ void this.read().then((ratio) => {
153219
+ this.current = ratio;
153220
+ }).finally(() => {
153221
+ this.pending = false;
153222
+ });
153223
+ }
153224
+ value() {
153225
+ return this.current;
153226
+ }
153227
+ };
153228
+ function hostMemoryFreeRatio(platform3, totalBytes, freeBytes, macPressureFreeRatio) {
153229
+ if (platform3 === "darwin") return macPressureFreeRatio;
153230
+ return totalBytes > 0 ? freeBytes / totalBytes : 1;
153231
+ }
153178
153232
  function worst(levels) {
153179
153233
  return levels.reduce(
153180
153234
  (acc, level) => RANK[level] > RANK[acc] ? level : acc,
@@ -153234,7 +153288,7 @@ function cpuBusyRatio(previous, next) {
153234
153288
  return 1 - idle / total;
153235
153289
  }
153236
153290
  function classifyHostPressure(sample, previous, platform3) {
153237
- const memRaw = schmittLowIsWorse(
153291
+ const mem = sample.memFreeRatio === void 0 ? "ok" : schmittLowIsWorse(
153238
153292
  sample.memFreeRatio,
153239
153293
  previous,
153240
153294
  HOST_PRESSURE_BARS.memFreeRatio.enterElevated,
@@ -153242,7 +153296,6 @@ function classifyHostPressure(sample, previous, platform3) {
153242
153296
  HOST_PRESSURE_BARS.memFreeRatio.enterCritical,
153243
153297
  HOST_PRESSURE_BARS.memFreeRatio.leaveCritical
153244
153298
  );
153245
- const mem = platform3 === "darwin" && memRaw === "critical" ? "elevated" : memRaw;
153246
153299
  const eventLoop = schmittHighIsWorse(
153247
153300
  sample.eventLoopP99Ms,
153248
153301
  previous,
@@ -153326,23 +153379,28 @@ var HostPressureMonitor = class {
153326
153379
  };
153327
153380
  function createHostPressureMonitor(wsHub, liveAgents) {
153328
153381
  const histogram = (0, import_perf_hooks.monitorEventLoopDelay)({ resolution: 20 });
153329
- const windows = process.platform === "win32";
153382
+ const platform3 = process.platform;
153383
+ const windows = platform3 === "win32";
153384
+ const macMemoryPressure = platform3 === "darwin" ? new MacMemoryPressureProbe(readMacMemoryPressureFreeRatio) : null;
153330
153385
  let prevCpuTimes = null;
153386
+ macMemoryPressure?.refresh();
153331
153387
  const monitor = new HostPressureMonitor({
153332
153388
  wsHub,
153333
153389
  histogram,
153334
153390
  readSample: () => {
153335
153391
  const eventLoopP99Ms = histogram.percentile(99) / 1e6;
153336
153392
  histogram.reset();
153337
- const total = (0, import_os16.totalmem)();
153393
+ const total = platform3 === "darwin" ? 0 : (0, import_os16.totalmem)();
153394
+ const free = platform3 === "darwin" ? 0 : (0, import_os16.freemem)();
153338
153395
  const cpuList = (0, import_os16.cpus)();
153339
153396
  const sample = {
153340
153397
  liveAgents: liveAgents(),
153341
- memFreeRatio: total > 0 ? (0, import_os16.freemem)() / total : 1,
153398
+ memFreeRatio: hostMemoryFreeRatio(platform3, total, free, macMemoryPressure?.value()),
153342
153399
  eventLoopP99Ms,
153343
153400
  load1: (0, import_os16.loadavg)()[0],
153344
153401
  ncpu: cpuList.length
153345
153402
  };
153403
+ macMemoryPressure?.refresh();
153346
153404
  if (windows) {
153347
153405
  const cpuTimes = cpuList.map((cpu) => cpu.times);
153348
153406
  sample.cpuBusyRatio = cpuBusyRatio(prevCpuTimes, cpuTimes);
@@ -157690,9 +157748,9 @@ function downloadPath(version2, filename) {
157690
157748
  }
157691
157749
 
157692
157750
  // src/updater/restart.ts
157693
- var import_node_child_process4 = require("child_process");
157751
+ var import_node_child_process5 = require("child_process");
157694
157752
  var import_node_util3 = require("util");
157695
- var execFileP = (0, import_node_util3.promisify)(import_node_child_process4.execFile);
157753
+ var execFileP = (0, import_node_util3.promisify)(import_node_child_process5.execFile);
157696
157754
  var BREW_LAUNCHD_LABEL = "homebrew.mxcl.tb-streamer";
157697
157755
  var DEPLOY_LAUNCHD_LABEL = "com.ronen.threadbase";
157698
157756
  function resolveDefaultLabel() {
@@ -161141,7 +161199,7 @@ async function printServerBanner({
161141
161199
  }
161142
161200
 
161143
161201
  // cli/prod.ts
161144
- var import_node_child_process8 = require("child_process");
161202
+ var import_node_child_process9 = require("child_process");
161145
161203
  var import_node_fs23 = require("fs");
161146
161204
  init_auth();
161147
161205
  init_feature_flags();
@@ -161306,7 +161364,7 @@ var defaultSpawnTail = ({ files, lines, follow }) => {
161306
161364
  ] : ["-n", String(lines), ...follow ? ["-F"] : [], ...existing];
161307
161365
  const program3 = isWindows3 ? "powershell.exe" : "tail";
161308
161366
  return new Promise((resolve4) => {
161309
- const child = (0, import_node_child_process8.spawn)(program3, args, {
161367
+ const child = (0, import_node_child_process9.spawn)(program3, args, {
161310
161368
  stdio: ["ignore", "inherit", "inherit"]
161311
161369
  });
161312
161370
  child.on(