@threadbase-sh/streamer 1.31.3 → 1.32.0

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
@@ -123460,6 +123460,97 @@ var require_semver2 = __commonJS({
123460
123460
  }
123461
123461
  });
123462
123462
 
123463
+ // src/lifecycle/conflict-check.ts
123464
+ var conflict_check_exports = {};
123465
+ __export(conflict_check_exports, {
123466
+ KNOWN_STREAMER_LABELS: () => KNOWN_STREAMER_LABELS,
123467
+ detectConflictingAgents: () => detectConflictingAgents,
123468
+ formatConflictMessage: () => formatConflictMessage
123469
+ });
123470
+ function uidScope() {
123471
+ return `gui/${process.getuid?.() ?? 501}`;
123472
+ }
123473
+ function resolveOwnLabel() {
123474
+ if (process.env.LAUNCHD_LABEL) return process.env.LAUNCHD_LABEL;
123475
+ try {
123476
+ (0, import_node_child_process4.execFileSync)("launchctl", ["print", `${uidScope()}/homebrew.mxcl.tb-streamer`], {
123477
+ stdio: "ignore"
123478
+ });
123479
+ return "homebrew.mxcl.tb-streamer";
123480
+ } catch {
123481
+ return LAUNCHD_LABEL;
123482
+ }
123483
+ }
123484
+ function isLabelLoaded(label) {
123485
+ try {
123486
+ (0, import_node_child_process4.execFileSync)("launchctl", ["list", label], { stdio: "ignore" });
123487
+ return true;
123488
+ } catch {
123489
+ return false;
123490
+ }
123491
+ }
123492
+ function detectConflictingAgents() {
123493
+ if (process.platform !== "darwin") return [];
123494
+ const ownLabel = resolveOwnLabel();
123495
+ const conflicts = [];
123496
+ for (const label of KNOWN_STREAMER_LABELS) {
123497
+ if (label === ownLabel) continue;
123498
+ if (isLabelLoaded(label)) {
123499
+ conflicts.push({
123500
+ label,
123501
+ resolution: label === "homebrew.mxcl.tb-streamer" ? "uninstall-homebrew" : "bootout"
123502
+ });
123503
+ }
123504
+ }
123505
+ try {
123506
+ const out = (0, import_node_child_process4.execFileSync)("launchctl", ["list"], {
123507
+ stdio: ["ignore", "pipe", "ignore"]
123508
+ }).toString();
123509
+ for (const line of out.split("\n")) {
123510
+ const parts = line.trim().split(/\s+/);
123511
+ const label = parts[2];
123512
+ if (!label) continue;
123513
+ if (LEGACY_PATTERN.test(label) && label !== ownLabel && !conflicts.some((c) => c.label === label)) {
123514
+ conflicts.push({ label, resolution: "bootout" });
123515
+ }
123516
+ }
123517
+ } catch {
123518
+ }
123519
+ return conflicts;
123520
+ }
123521
+ function formatConflictMessage(conflicts) {
123522
+ if (conflicts.length === 0) return "";
123523
+ const lines = ["Conflicting Threadbase streamer agents detected:", ""];
123524
+ for (const c of conflicts) {
123525
+ if (c.resolution === "uninstall-homebrew") {
123526
+ lines.push(
123527
+ ` \u2022 ${c.label} \u2014 run: brew services stop tb-streamer && brew uninstall tb-streamer`
123528
+ );
123529
+ } else {
123530
+ lines.push(` \u2022 ${c.label} \u2014 run: launchctl bootout gui/$(id -u)/${c.label}`);
123531
+ }
123532
+ }
123533
+ lines.push(
123534
+ "",
123535
+ "Only one Threadbase streamer can bind port 8766. Remove the conflicting agent(s) to proceed."
123536
+ );
123537
+ return lines.join("\n");
123538
+ }
123539
+ var import_node_child_process4, KNOWN_STREAMER_LABELS, LEGACY_PATTERN;
123540
+ var init_conflict_check = __esm({
123541
+ "src/lifecycle/conflict-check.ts"() {
123542
+ "use strict";
123543
+ import_node_child_process4 = require("child_process");
123544
+ init_constants();
123545
+ KNOWN_STREAMER_LABELS = [
123546
+ "com.ronen.threadbase",
123547
+ "homebrew.mxcl.tb-streamer",
123548
+ "com.threadbase.streamer"
123549
+ ];
123550
+ LEGACY_PATTERN = /^com\.threadbase\.streamer/;
123551
+ }
123552
+ });
123553
+
123463
123554
  // src/lifecycle/launchd.ts
123464
123555
  var launchd_exports = {};
123465
123556
  __export(launchd_exports, {
@@ -123471,13 +123562,13 @@ __export(launchd_exports, {
123471
123562
  isAgentLoaded: () => isAgentLoaded,
123472
123563
  kickstartAgent: () => kickstartAgent
123473
123564
  });
123474
- function uidScope() {
123565
+ function uidScope2() {
123475
123566
  return `gui/${process.getuid?.() ?? 501}`;
123476
123567
  }
123477
123568
  function resolveLoadedLabel() {
123478
123569
  if (process.env.LAUNCHD_LABEL) return process.env.LAUNCHD_LABEL;
123479
123570
  try {
123480
- (0, import_node_child_process4.execFileSync)("launchctl", ["print", `${uidScope()}/${BREW_LAUNCHD_LABEL2}`], {
123571
+ (0, import_node_child_process5.execFileSync)("launchctl", ["print", `${uidScope2()}/${BREW_LAUNCHD_LABEL2}`], {
123481
123572
  stdio: "ignore"
123482
123573
  });
123483
123574
  return BREW_LAUNCHD_LABEL2;
@@ -123486,11 +123577,11 @@ function resolveLoadedLabel() {
123486
123577
  }
123487
123578
  }
123488
123579
  function fullTarget() {
123489
- return `${uidScope()}/${resolveLoadedLabel()}`;
123580
+ return `${uidScope2()}/${resolveLoadedLabel()}`;
123490
123581
  }
123491
123582
  function isAgentLoaded() {
123492
123583
  try {
123493
- (0, import_node_child_process4.execFileSync)("launchctl", ["list", resolveLoadedLabel()], { stdio: "ignore" });
123584
+ (0, import_node_child_process5.execFileSync)("launchctl", ["list", resolveLoadedLabel()], { stdio: "ignore" });
123494
123585
  return true;
123495
123586
  } catch {
123496
123587
  return false;
@@ -123498,7 +123589,7 @@ function isAgentLoaded() {
123498
123589
  }
123499
123590
  function bootoutAgent(timeoutMs = 2e3) {
123500
123591
  try {
123501
- (0, import_node_child_process4.execFileSync)("launchctl", ["bootout", fullTarget()], { stdio: "ignore" });
123592
+ (0, import_node_child_process5.execFileSync)("launchctl", ["bootout", fullTarget()], { stdio: "ignore" });
123502
123593
  } catch {
123503
123594
  }
123504
123595
  const deadline = Date.now() + timeoutMs;
@@ -123510,7 +123601,7 @@ function bootoutAgent(timeoutMs = 2e3) {
123510
123601
  }
123511
123602
  function bootstrapAgent(plistPath) {
123512
123603
  try {
123513
- (0, import_node_child_process4.execFileSync)("launchctl", ["bootstrap", uidScope(), plistPath], {
123604
+ (0, import_node_child_process5.execFileSync)("launchctl", ["bootstrap", uidScope2(), plistPath], {
123514
123605
  stdio: ["ignore", "ignore", "pipe"]
123515
123606
  });
123516
123607
  } catch (err) {
@@ -123523,7 +123614,7 @@ function bootstrapAgent(plistPath) {
123523
123614
  }
123524
123615
  }
123525
123616
  function kickstartAgent() {
123526
- (0, import_node_child_process4.execFileSync)("launchctl", ["kickstart", "-k", fullTarget()], { stdio: "ignore" });
123617
+ (0, import_node_child_process5.execFileSync)("launchctl", ["kickstart", "-k", fullTarget()], { stdio: "ignore" });
123527
123618
  }
123528
123619
  function darwinPlistPath() {
123529
123620
  return `${process.env.HOME}/Library/LaunchAgents/${resolveLoadedLabel()}.plist`;
@@ -123534,7 +123625,7 @@ function getLogPaths() {
123534
123625
  }
123535
123626
  function getAgentPid() {
123536
123627
  try {
123537
- const out = (0, import_node_child_process4.execFileSync)("launchctl", ["list"], {
123628
+ const out = (0, import_node_child_process5.execFileSync)("launchctl", ["list"], {
123538
123629
  stdio: ["ignore", "pipe", "ignore"]
123539
123630
  }).toString();
123540
123631
  const label = resolveLoadedLabel();
@@ -123550,11 +123641,11 @@ function getAgentPid() {
123550
123641
  return null;
123551
123642
  }
123552
123643
  }
123553
- var import_node_child_process4, import_node_path25, BREW_LAUNCHD_LABEL2;
123644
+ var import_node_child_process5, import_node_path25, BREW_LAUNCHD_LABEL2;
123554
123645
  var init_launchd = __esm({
123555
123646
  "src/lifecycle/launchd.ts"() {
123556
123647
  "use strict";
123557
- import_node_child_process4 = require("child_process");
123648
+ import_node_child_process5 = require("child_process");
123558
123649
  import_node_path25 = require("path");
123559
123650
  init_constants();
123560
123651
  BREW_LAUNCHD_LABEL2 = "homebrew.mxcl.tb-streamer";
@@ -123627,7 +123718,7 @@ __export(task_scheduler_exports, {
123627
123718
  kickstartAgent: () => kickstartAgent2
123628
123719
  });
123629
123720
  function ps2(command) {
123630
- return (0, import_node_child_process5.execFileSync)("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
123721
+ return (0, import_node_child_process6.execFileSync)("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
123631
123722
  stdio: ["ignore", "pipe", "ignore"]
123632
123723
  }).toString();
123633
123724
  }
@@ -123673,11 +123764,11 @@ function getAgentPid2() {
123673
123764
  return null;
123674
123765
  }
123675
123766
  }
123676
- var import_node_child_process5;
123767
+ var import_node_child_process6;
123677
123768
  var init_task_scheduler = __esm({
123678
123769
  "src/lifecycle/task-scheduler.ts"() {
123679
123770
  "use strict";
123680
- import_node_child_process5 = require("child_process");
123771
+ import_node_child_process6 = require("child_process");
123681
123772
  init_constants();
123682
123773
  }
123683
123774
  });
@@ -124021,7 +124112,7 @@ __export(repo_exports, {
124021
124112
  });
124022
124113
  function getGitToplevel(cwd) {
124023
124114
  try {
124024
- return (0, import_node_child_process7.execFileSync)("git", ["rev-parse", "--show-toplevel"], {
124115
+ return (0, import_node_child_process8.execFileSync)("git", ["rev-parse", "--show-toplevel"], {
124025
124116
  cwd,
124026
124117
  stdio: ["ignore", "pipe", "ignore"]
124027
124118
  }).toString().trim();
@@ -124029,11 +124120,11 @@ function getGitToplevel(cwd) {
124029
124120
  return null;
124030
124121
  }
124031
124122
  }
124032
- var import_node_child_process7;
124123
+ var import_node_child_process8;
124033
124124
  var init_repo = __esm({
124034
124125
  "src/lifecycle/repo.ts"() {
124035
124126
  "use strict";
124036
- import_node_child_process7 = require("child_process");
124127
+ import_node_child_process8 = require("child_process");
124037
124128
  }
124038
124129
  });
124039
124130
 
@@ -151006,8 +151097,9 @@ async function runInstall(opts) {
151006
151097
  }
151007
151098
 
151008
151099
  // cli/prod.ts
151009
- var import_node_child_process6 = require("child_process");
151100
+ var import_node_child_process7 = require("child_process");
151010
151101
  var import_node_fs22 = require("fs");
151102
+ init_conflict_check();
151011
151103
  init_constants();
151012
151104
  init_launchd();
151013
151105
  init_marker();
@@ -151090,6 +151182,18 @@ async function runProdDoctor(opts) {
151090
151182
  if (!getSupervisor().isAgentLoaded()) {
151091
151183
  findings.push("launchd agent is not loaded \u2014 prod is fully down");
151092
151184
  }
151185
+ const conflicts = detectConflictingAgents();
151186
+ for (const c of conflicts) {
151187
+ if (c.resolution === "uninstall-homebrew") {
151188
+ findings.push(
151189
+ `conflicting agent: ${c.label} \u2014 run: brew services stop tb-streamer && brew uninstall tb-streamer`
151190
+ );
151191
+ } else {
151192
+ findings.push(
151193
+ `conflicting agent: ${c.label} \u2014 run: launchctl bootout gui/$(id -u)/${c.label}`
151194
+ );
151195
+ }
151196
+ }
151093
151197
  return { findings, repairs };
151094
151198
  }
151095
151199
  var defaultSpawnTail = ({ files, lines, follow }) => {
@@ -151104,7 +151208,7 @@ var defaultSpawnTail = ({ files, lines, follow }) => {
151104
151208
  if (follow) args.push("-F");
151105
151209
  args.push(...existing);
151106
151210
  return new Promise((resolve6) => {
151107
- const child = (0, import_node_child_process6.spawn)("tail", args, { stdio: ["ignore", "inherit", "inherit"] });
151211
+ const child = (0, import_node_child_process7.spawn)("tail", args, { stdio: ["ignore", "inherit", "inherit"] });
151108
151212
  child.on("error", (err) => resolve6({ ok: false, message: `tail failed: ${err.message}` }));
151109
151213
  child.on("exit", (code) => resolve6({ ok: code === 0 }));
151110
151214
  });
@@ -151260,6 +151364,13 @@ program2.command("serve").description("Start the streamer server").option("-p, -
151260
151364
  const publicUrl = opts.publicUrl ?? loadPublicUrl() ?? null;
151261
151365
  const isProdInvocation = opts.prod === true || process.ppid === 1;
151262
151366
  if (!isProdInvocation) appendDevSessionMarker();
151367
+ if (process.platform === "darwin") {
151368
+ const { detectConflictingAgents: detectConflictingAgents2, formatConflictMessage: formatConflictMessage2 } = await Promise.resolve().then(() => (init_conflict_check(), conflict_check_exports));
151369
+ const conflicts = detectConflictingAgents2();
151370
+ if (conflicts.length > 0) {
151371
+ log7.warn(formatConflictMessage2(conflicts), void 0, "console");
151372
+ }
151373
+ }
151263
151374
  let resolvedDefaultPermissionMode = opts.defaultPermissionMode;
151264
151375
  if (resolvedDefaultPermissionMode === void 0 && !isProdInvocation && process.env.THREADBASE_SKIP_PERMISSION_MODE_PROMPT !== "true" && loadDefaultPermissionMode() === void 0 && import_node_process3.stdin.isTTY) {
151265
151376
  const { interactivePermissionModePrompt: interactivePermissionModePrompt2 } = await Promise.resolve().then(() => (init_prompt(), prompt_exports));