kiteline 0.3.2 → 0.3.3

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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as version } from "./package-D0hl72v4.mjs";
2
+ import { t as version } from "./package-COJ2H5Hh.mjs";
3
3
  import { h as startedFromCli, i as dim, r as bold, t as accent } from "./banner-C1Jj4n4W.mjs";
4
4
  import { parseArgs } from "node:util";
5
5
  // src/cli.ts
@@ -107,7 +107,7 @@ switch (command) {
107
107
  case void 0:
108
108
  case "start":
109
109
  if (action) fail(`"${action}" isn't something Kiteline takes. Run ${bold("kiteline --help")}.`);
110
- await import("./src-DekrqcQL.mjs");
110
+ await import("./src-MfqVh1pV.mjs");
111
111
  break;
112
112
  case "pair": {
113
113
  if (action) fail(`"${action}" isn't something kiteline pair takes. Run ${bold("kiteline --help")}.`);
@@ -1,3 +1,3 @@
1
1
  // package.json
2
- var version = "0.3.2";
2
+ var version = "0.3.3";
3
3
  export { version as t };
@@ -1,5 +1,5 @@
1
1
  import { A as runWithSpan, C as isObject$1, D as parseEmptyableJSON, E as overlayProxy, M as toArray, N as value, S as isAsyncIteratorObject, T as onError, _ as toORPCError, a as toHttpPath, b as asyncIteratorWithSpan, c as toStandardLazyRequest, d as HibernationEventIterator, f as flattenHeader, g as isORPCErrorStatus, h as fallbackORPCErrorStatus, i as StandardRPCSerializer, j as setSpanError, k as resolveMaybeOptionalOptions, n as StandardRPCJsonSerializer, p as ORPCError, s as toFetchResponse, u as mapEventIterator, v as NullProtoObj, w as isTypescriptObject, x as intercept, y as ORPC_NAME } from "./client.BPI7fHX3-CSey2FaL.mjs";
2
- import { t as version$1 } from "./package-D0hl72v4.mjs";
2
+ import { t as version$1 } from "./package-COJ2H5Hh.mjs";
3
3
  import { a as localAddress, c as safeEqual, i as loadComputerKey, l as saveServerInfo, n as PairLimiter, r as kitelineHome, t as DEVICE_COOKIE } from "./auth-CYNu-f_h.mjs";
4
4
  import { _ as RelayPath, a as pairingLinks, b as relaySocketUrl, c as printPairingCode, d as SettingsError, f as command, g as RelayClose, i as dim, l as printSettingsError, m as readSettings, n as addressesFor, o as printAlreadyRunning, r as bold, s as printBanner, t as accent, u as spaced, v as fromBase64Url, x as toBase64Url, y as hostIdFor } from "./banner-C1Jj4n4W.mjs";
5
5
  import { homedir, hostname, platform } from "node:os";
@@ -12917,6 +12917,8 @@ var SocketTimeout = class extends Error {
12917
12917
  /** More than the biggest real request: six photos at the limit, base64 in JSON. */
12918
12918
  const MAX_BODY = 41943040;
12919
12919
  const HANDSHAKE_MS = 2e4;
12920
+ /** The phone pings every 20 seconds; a tunnel that's heard nothing for three of those is dead. */
12921
+ const SILENCE_MS$1 = 6e4;
12920
12922
  /**
12921
12923
  * The computer's end of one phone's tunnel. Answers the handshake with the key the phone names,
12922
12924
  * refuses a phone that can't prove it, then turns each request into a `Request` for `handle`, saying
@@ -12938,6 +12940,11 @@ async function serveTunnel(ws, keyFor, handle, hooks = {}) {
12938
12940
  const who = identity;
12939
12941
  hooks.opened?.(who, (code, reason) => socket.close(code, reason));
12940
12942
  socket.onClose(() => hooks.closed?.(who));
12943
+ let lastHeard = Date.now();
12944
+ const watchdog = setInterval(() => {
12945
+ if (Date.now() - lastHeard > SILENCE_MS$1) socket.close(1e3, "silent");
12946
+ }, 15e3);
12947
+ socket.onClose(() => clearInterval(watchdog));
12941
12948
  const streams = /* @__PURE__ */ new Map();
12942
12949
  let sending = Promise.resolve();
12943
12950
  let closed = false;
@@ -12986,6 +12993,7 @@ async function serveTunnel(ws, keyFor, handle, hooks = {}) {
12986
12993
  try {
12987
12994
  for (;;) {
12988
12995
  const frame = await socket.next();
12996
+ lastHeard = Date.now();
12989
12997
  const { type, stream: id, payload } = unpack(await cipher.open(frame));
12990
12998
  switch (type) {
12991
12999
  case Msg.Ping:
@@ -13042,6 +13050,15 @@ function joinChunks(chunks, size) {
13042
13050
  return out;
13043
13051
  }
13044
13052
  // src/relay.ts
13053
+ /**
13054
+ * This computer's side of the relay: one standing connection out to it, over which the relay asks
13055
+ * for a channel whenever a phone wants this computer. Each channel is a sealed tunnel, opened with the
13056
+ * phone's own key or, while it asks to pair, the one-time code it scanned; what comes through is
13057
+ * answered by the same API the phone would reach directly, as that device.
13058
+ */
13059
+ /** How often this computer pings the relay, and how long a quiet connection lasts before it's given up. */
13060
+ const PING_MS = 2e4;
13061
+ const SILENCE_MS = 5e4;
13045
13062
  /** The relay's secret for this computer, kept beside its other keys. Its hash is our address. */
13046
13063
  function relaySecret(home) {
13047
13064
  const file = join(home, "relay.json");
@@ -13110,24 +13127,52 @@ async function startRelay(options) {
13110
13127
  let connected = false;
13111
13128
  let stopped = false;
13112
13129
  let socket = null;
13113
- let silence = null;
13130
+ /** Stops the current connection's watchdog, when the relay connection is stopped for good. */
13131
+ let quiet = null;
13114
13132
  const connect = () => {
13115
13133
  if (stopped) return;
13116
13134
  const ws = new WebSocket(relaySocketUrl(options.relay, RelayPath.host));
13117
13135
  socket = ws;
13118
13136
  let lastHeard = Date.now();
13137
+ let gone = false;
13138
+ /**
13139
+ * Done with this connection, whether it closed or only went quiet. A dead one may never finish
13140
+ * closing, which can take a quarter of an hour, so this doesn't wait for it to: it reconnects.
13141
+ */
13142
+ const lost = (code) => {
13143
+ if (gone) return;
13144
+ gone = true;
13145
+ clearInterval(watchdog);
13146
+ try {
13147
+ ws.close();
13148
+ } catch {}
13149
+ if (stopped) return;
13150
+ if (connected) options.log("Lost the relay; reconnecting.");
13151
+ else if (attempt === 0) {
13152
+ const why = code === RelayClose.TooMany ? "it's full right now" : "couldn't reach it";
13153
+ options.log(`The relay at ${options.relay} isn't answering (${why}); retrying in the background.`);
13154
+ }
13155
+ connected = false;
13156
+ attempt++;
13157
+ const wait = Math.min(3e4, 1e3 * 2 ** Math.min(attempt, 5)) + Math.random() * 1e3;
13158
+ setTimeout(connect, wait).unref();
13159
+ };
13160
+ const watchdog = setInterval(() => {
13161
+ if (Date.now() - lastHeard > SILENCE_MS) lost();
13162
+ else if (ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({ t: "ping" }));
13163
+ }, PING_MS);
13164
+ quiet = () => clearInterval(watchdog);
13119
13165
  ws.addEventListener("open", () => {
13166
+ if (gone) return;
13167
+ lastHeard = Date.now();
13120
13168
  ws.send(JSON.stringify({
13121
13169
  t: "hello",
13122
13170
  secret,
13123
13171
  version: options.version
13124
13172
  }));
13125
- silence = setInterval(() => {
13126
- if (Date.now() - lastHeard > 75e3) ws.close();
13127
- else ws.send(JSON.stringify({ t: "ping" }));
13128
- }, 3e4);
13129
13173
  });
13130
13174
  ws.addEventListener("message", (event) => {
13175
+ if (gone) return;
13131
13176
  lastHeard = Date.now();
13132
13177
  let message;
13133
13178
  try {
@@ -13150,19 +13195,7 @@ async function startRelay(options) {
13150
13195
  });
13151
13196
  }
13152
13197
  });
13153
- ws.addEventListener("close", (event) => {
13154
- if (silence) clearInterval(silence);
13155
- if (stopped) return;
13156
- if (connected) options.log("Lost the relay; reconnecting.");
13157
- else if (attempt === 0) {
13158
- const why = event.code === RelayClose.TooMany ? "it's full right now" : "couldn't reach it";
13159
- options.log(`The relay at ${options.relay} isn't answering (${why}); retrying in the background.`);
13160
- }
13161
- connected = false;
13162
- attempt++;
13163
- const wait = Math.min(3e4, 1e3 * 2 ** Math.min(attempt, 5)) + Math.random() * 1e3;
13164
- setTimeout(connect, wait).unref();
13165
- });
13198
+ ws.addEventListener("close", (event) => lost(event.code));
13166
13199
  ws.addEventListener("error", () => {});
13167
13200
  };
13168
13201
  connect();
@@ -13177,7 +13210,7 @@ async function startRelay(options) {
13177
13210
  },
13178
13211
  stop() {
13179
13212
  stopped = true;
13180
- if (silence) clearInterval(silence);
13213
+ quiet?.();
13181
13214
  socket?.close();
13182
13215
  }
13183
13216
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kiteline",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Drive Claude Code on your computer from your phone.",
5
5
  "keywords": [
6
6
  "claude",