cli-remote-agent 1.0.12 → 1.0.14

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/index.js CHANGED
@@ -336,8 +336,31 @@ function acquireSingleInstanceLock() {
336
336
  }
337
337
  }
338
338
 
339
+ // src/keep-awake.ts
340
+ var import_child_process2 = require("child_process");
341
+ function keepAwake() {
342
+ if (process.platform !== "darwin") return;
343
+ if (process.env.CRC_ALLOW_SLEEP === "1") return;
344
+ try {
345
+ const child = (0, import_child_process2.spawn)("caffeinate", ["-i", "-w", String(process.pid)], {
346
+ detached: true,
347
+ stdio: "ignore"
348
+ });
349
+ child.on("error", (err) => {
350
+ logger.warn(
351
+ { error: err.message },
352
+ "Could not start caffeinate \u2014 the Mac may idle-sleep and drop the connection"
353
+ );
354
+ });
355
+ child.unref();
356
+ logger.info("Preventing idle sleep while the agent runs (caffeinate -i)");
357
+ } catch (err) {
358
+ logger.warn({ error: err?.message }, "Could not prevent idle sleep");
359
+ }
360
+ }
361
+
339
362
  // src/tmux.ts
340
- var import_child_process3 = require("child_process");
363
+ var import_child_process4 = require("child_process");
341
364
  var import_util2 = require("util");
342
365
  var import_fs6 = __toESM(require("fs"));
343
366
  var import_path6 = __toESM(require("path"));
@@ -346,9 +369,9 @@ var import_path6 = __toESM(require("path"));
346
369
  var import_fs5 = __toESM(require("fs"));
347
370
  var import_path5 = __toESM(require("path"));
348
371
  var import_os2 = __toESM(require("os"));
349
- var import_child_process2 = require("child_process");
372
+ var import_child_process3 = require("child_process");
350
373
  var import_util = require("util");
351
- var execFileAsync = (0, import_util.promisify)(import_child_process2.execFile);
374
+ var execFileAsync = (0, import_util.promisify)(import_child_process3.execFile);
352
375
  var LIVE_SESSIONS_DIR = import_path5.default.join(import_os2.default.homedir(), ".claude", "sessions");
353
376
  function isAlive(pid) {
354
377
  try {
@@ -415,7 +438,7 @@ async function findClaudeSessionForPtyPid(ptyPid) {
415
438
  }
416
439
 
417
440
  // src/tmux.ts
418
- var execFileAsync2 = (0, import_util2.promisify)(import_child_process3.execFile);
441
+ var execFileAsync2 = (0, import_util2.promisify)(import_child_process4.execFile);
419
442
  var IS_WIN = process.platform === "win32";
420
443
  var cachedTmuxPath;
421
444
  function resolveTmuxPath() {
@@ -470,9 +493,10 @@ async function killTmuxSession(name) {
470
493
  return { ok: false, error: msg };
471
494
  }
472
495
  }
473
- async function scrollTmux(name, direction) {
496
+ async function scrollTmux(name, direction, lines = 12) {
474
497
  const bin = resolveTmuxPath();
475
498
  if (!bin) return { inCopyMode: false };
499
+ const n = Math.max(1, Math.min(200, Math.round(lines)));
476
500
  const target = name;
477
501
  const run = (args) => execFileAsync2(bin, args, { timeout: 4e3 }).catch(() => {
478
502
  });
@@ -490,11 +514,11 @@ async function scrollTmux(name, direction) {
490
514
  }
491
515
  if (direction === "up") {
492
516
  if (!await inMode()) await run(["copy-mode", "-t", target]);
493
- await run(["send-keys", "-t", target, "-X", "halfpage-up"]);
517
+ await run(["send-keys", "-t", target, "-N", String(n), "-X", "scroll-up"]);
494
518
  return { inCopyMode: true };
495
519
  }
496
520
  if (!await inMode()) return { inCopyMode: false };
497
- await run(["send-keys", "-t", target, "-X", "halfpage-down"]);
521
+ await run(["send-keys", "-t", target, "-N", String(n), "-X", "scroll-down"]);
498
522
  try {
499
523
  const { stdout } = await execFileAsync2(bin, ["display-message", "-t", target, "-p", "#{scroll_position}"], { timeout: 3e3 });
500
524
  if ((parseInt(stdout.trim(), 10) || 0) === 0) {
@@ -556,7 +580,7 @@ function buildTmuxLaunch(name, launch) {
556
580
  // src/heartbeat.ts
557
581
  var import_os4 = __toESM(require("os"));
558
582
  var import_path8 = __toESM(require("path"));
559
- var import_child_process5 = require("child_process");
583
+ var import_child_process6 = require("child_process");
560
584
 
561
585
  // src/pty-session.ts
562
586
  var pty = __toESM(require("node-pty"));
@@ -565,12 +589,12 @@ var import_path7 = require("path");
565
589
  var import_os3 = require("os");
566
590
 
567
591
  // src/shell.ts
568
- var import_child_process4 = require("child_process");
592
+ var import_child_process5 = require("child_process");
569
593
  function detectShell(preference) {
570
594
  if (preference !== "auto") return preference;
571
595
  if (process.platform === "win32") {
572
596
  try {
573
- (0, import_child_process4.execSync)("where pwsh", { stdio: "ignore" });
597
+ (0, import_child_process5.execSync)("where pwsh", { stdio: "ignore" });
574
598
  return "pwsh.exe";
575
599
  } catch {
576
600
  return "powershell.exe";
@@ -844,7 +868,7 @@ function getCpuUsage() {
844
868
  function getRootPaths() {
845
869
  if (process.platform === "win32") {
846
870
  try {
847
- const output = (0, import_child_process5.execSync)("wmic logicaldisk get name", { encoding: "utf-8" });
871
+ const output = (0, import_child_process6.execSync)("wmic logicaldisk get name", { encoding: "utf-8" });
848
872
  return output.split("\n").map((l) => l.trim()).filter((l) => /^[A-Z]:$/.test(l)).map((l) => l + "\\");
849
873
  } catch {
850
874
  return ["C:\\"];
@@ -965,12 +989,12 @@ async function downloadFile(filePath, serverUrl, secret, agentId) {
965
989
  }
966
990
 
967
991
  // src/vpn-manager.ts
968
- var import_child_process6 = require("child_process");
992
+ var import_child_process7 = require("child_process");
969
993
  var import_util3 = require("util");
970
994
  var import_fs9 = __toESM(require("fs"));
971
995
  var import_path10 = __toESM(require("path"));
972
996
  var import_os6 = __toESM(require("os"));
973
- var execAsync = (0, import_util3.promisify)(import_child_process6.exec);
997
+ var execAsync = (0, import_util3.promisify)(import_child_process7.exec);
974
998
  var isWindows = process.platform === "win32";
975
999
  var VPN_DIR = import_path10.default.join(import_os6.default.homedir(), ".crc-agent", "vpn");
976
1000
  function shq(value) {
@@ -1610,6 +1634,7 @@ if (!lock.ok) {
1610
1634
  process.exit(1);
1611
1635
  }
1612
1636
  ensurePtyHelperExecutable();
1637
+ keepAwake();
1613
1638
  process.on("unhandledRejection", (reason) => {
1614
1639
  logger.error({ reason }, "Unhandled promise rejection (agent kept alive)");
1615
1640
  });
@@ -1719,10 +1744,10 @@ socket.on(TMUX_KILL, async (payload) => {
1719
1744
  socket.emit(TMUX_KILL_RESULT, { requestId, name, ok: result.ok, error: result.error });
1720
1745
  });
1721
1746
  socket.on(TMUX_SCROLL, async (payload) => {
1722
- const { sessionId, direction } = payload;
1747
+ const { sessionId, direction, lines } = payload;
1723
1748
  const name = sessionId && sessionTmuxName.get(sessionId);
1724
1749
  if (!name) return;
1725
- const { inCopyMode } = await scrollTmux(name, direction);
1750
+ const { inCopyMode } = await scrollTmux(name, direction, lines);
1726
1751
  sessionInCopyMode.set(sessionId, inCopyMode);
1727
1752
  });
1728
1753
  socket.on(TERMINAL_INPUT, (payload) => {