@evident-ai/cli 3.5.2-dev.6d7d122 → 3.5.2-dev.6f1ed0e

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
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { createRequire as createRequire2 } from "module";
5
4
  import { Command } from "commander";
6
5
 
7
6
  // src/commands/login.ts
@@ -1158,7 +1157,7 @@ import ora4 from "ora";
1158
1157
  import { select as select4 } from "@inquirer/prompts";
1159
1158
 
1160
1159
  // src/lib/telemetry.ts
1161
- var CLI_VERSION = (true ? "3.5.2-dev.6d7d122" : void 0) ?? process.env.npm_package_version ?? "unknown";
1160
+ var CLI_VERSION = (true ? "3.5.2-dev.6f1ed0e" : void 0) ?? process.env.npm_package_version ?? "unknown";
1162
1161
  function getCliVersion() {
1163
1162
  return CLI_VERSION;
1164
1163
  }
@@ -5511,6 +5510,8 @@ var StreamForwarder = class {
5511
5510
  if (done) break;
5512
5511
  const chunk = Buffer.from(value);
5513
5512
  for (let i = 0; i < chunk.length; i += MAX_FRAME_BYTES) {
5513
+ await stream.pausePromise;
5514
+ if (ac.signal.aborted) break;
5514
5515
  const slice = chunk.subarray(i, i + MAX_FRAME_BYTES);
5515
5516
  if (this.binaryFramesSupported) {
5516
5517
  if (this.ws.readyState === WebSocket.OPEN) {
@@ -5553,6 +5554,7 @@ function classifyUpgradeRejection(headers) {
5553
5554
  }
5554
5555
  var MAX_RECONNECT_DELAY = 3e4;
5555
5556
  var BASE_RECONNECT_DELAY = 500;
5557
+ var RELAY_SILENCE_TIMEOUT_MS = 9e4;
5556
5558
  function getReconnectDelay(attempt) {
5557
5559
  const exponentialDelay = BASE_RECONNECT_DELAY * Math.pow(2, attempt);
5558
5560
  const jitter = Math.random() * 1e3;
@@ -5624,10 +5626,27 @@ function connectTunnel(options) {
5624
5626
  ws.close();
5625
5627
  reject(new Error("Connection timeout"));
5626
5628
  }, 3e4);
5629
+ let relaySilenceTimeout;
5630
+ let relaySilenceTimedOut = false;
5631
+ const clearRelaySilenceTimeout = () => {
5632
+ if (relaySilenceTimeout === void 0) return;
5633
+ clearTimeout(relaySilenceTimeout);
5634
+ relaySilenceTimeout = void 0;
5635
+ };
5636
+ const armRelaySilenceTimeout = () => {
5637
+ clearRelaySilenceTimeout();
5638
+ relaySilenceTimeout = setTimeout(() => {
5639
+ relaySilenceTimeout = void 0;
5640
+ relaySilenceTimedOut = true;
5641
+ ws.terminate();
5642
+ }, RELAY_SILENCE_TIMEOUT_MS);
5643
+ relaySilenceTimeout.unref?.();
5644
+ };
5627
5645
  let upgradeRejection = null;
5628
5646
  let upgradeRejectionReason = null;
5629
5647
  ws.on("unexpected-response", (_req, res) => {
5630
5648
  clearTimeout(connectionTimeout);
5649
+ clearRelaySilenceTimeout();
5631
5650
  const reason = classifyUpgradeRejection(res.headers);
5632
5651
  upgradeRejectionReason = reason;
5633
5652
  const chunks = [];
@@ -5657,6 +5676,7 @@ function connectTunnel(options) {
5657
5676
  onInfo?.("WebSocket connection established");
5658
5677
  });
5659
5678
  ws.on("message", (data, isBinary) => {
5679
+ if (relaySilenceTimeout !== void 0) armRelaySilenceTimeout();
5660
5680
  if (isBinary) {
5661
5681
  try {
5662
5682
  const frame = decodeBinaryBodyFrame(toUint8Array(data));
@@ -5690,6 +5710,7 @@ function connectTunnel(options) {
5690
5710
  switch (message.type) {
5691
5711
  case "connected": {
5692
5712
  clearTimeout(connectionTimeout);
5713
+ armRelaySilenceTimeout();
5693
5714
  forwarder.setBinaryFramesSupported(message.binary_frames === true);
5694
5715
  const connectedAgentId = message.agent_id ?? agentId;
5695
5716
  onConnected?.(connectedAgentId);
@@ -5714,6 +5735,7 @@ function connectTunnel(options) {
5714
5735
  });
5715
5736
  ws.on("error", (error2) => {
5716
5737
  clearTimeout(connectionTimeout);
5738
+ clearRelaySilenceTimeout();
5717
5739
  const detail = upgradeRejection ?? describeSocketError(error2, url);
5718
5740
  if (upgradeRejectionReason === "do_code_updated") {
5719
5741
  onWarning?.("Relay redeployed \u2014 reconnecting");
@@ -5725,7 +5747,8 @@ function connectTunnel(options) {
5725
5747
  );
5726
5748
  });
5727
5749
  ws.on("close", (code, reason) => {
5728
- const reasonStr = reason.toString() || upgradeRejection || (code === 1006 ? "abnormal closure" : "No reason provided");
5750
+ clearRelaySilenceTimeout();
5751
+ const reasonStr = (relaySilenceTimedOut ? "no relay heartbeat for 90s \u2014 reconnecting" : void 0) || reason.toString() || upgradeRejection || (code === 1006 ? "abnormal closure" : "No reason provided");
5729
5752
  forwarder.abortAll();
5730
5753
  onDisconnected?.(code, reasonStr);
5731
5754
  });
@@ -5733,7 +5756,7 @@ function connectTunnel(options) {
5733
5756
  }
5734
5757
 
5735
5758
  // src/lib/tunnel/runner-connection.ts
5736
- var RunnerConnection = class {
5759
+ var RunnerConnection = class _RunnerConnection {
5737
5760
  opts;
5738
5761
  sleep;
5739
5762
  now;
@@ -5747,6 +5770,10 @@ var RunnerConnection = class {
5747
5770
  reconnectAttempt = 0;
5748
5771
  generation = 0;
5749
5772
  disconnectedAtMs = null;
5773
+ static RELAY_RECONNECT_CLOSE_REASONS = /* @__PURE__ */ new Set([
5774
+ "No pong received",
5775
+ "Orphaned socket"
5776
+ ]);
5750
5777
  constructor(opts) {
5751
5778
  this.opts = opts;
5752
5779
  this.resolvedAgentId = opts.agentId;
@@ -5803,7 +5830,8 @@ var RunnerConnection = class {
5803
5830
  onDisconnected: (code, reason) => {
5804
5831
  this.disconnectedAtMs = this.now();
5805
5832
  events.onDisconnected(code, reason, { generation: this.generation });
5806
- if (this.opts.isRunning() && code !== 1e3 && !this.reconnecting) {
5833
+ const relayRequestedReconnect = code === 1e3 && _RunnerConnection.RELAY_RECONNECT_CLOSE_REASONS.has(reason);
5834
+ if (this.opts.isRunning() && (code !== 1e3 || relayRequestedReconnect) && !this.reconnecting) {
5807
5835
  this.reconnectPromise = this.connectWithRetry(true).catch((err) => {
5808
5836
  events.onError?.(`Reconnection failed: ${err.message}`);
5809
5837
  });
@@ -14129,7 +14157,7 @@ async function run(options) {
14129
14157
  }
14130
14158
 
14131
14159
  // src/index.ts
14132
- var { version } = createRequire2(import.meta.url)("../package.json");
14160
+ var version = getCliVersion();
14133
14161
  var program = new Command();
14134
14162
  program.name("evident").description("Run OpenCode locally and connect it to Evident").version(version).option(
14135
14163
  "--endpoint <url>",