kiteline 0.3.1 → 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/README.md CHANGED
@@ -27,7 +27,7 @@ It's self-hosted: your phone talks straight to your computer, and Claude Code ke
27
27
  You need Node.js 22.18 or newer, and Claude Code signed in on the computer.
28
28
 
29
29
  ```bash
30
- npx kiteline --relay
30
+ npx kiteline --relay # or: pnpm dlx kiteline --relay, or: bunx kiteline --relay
31
31
  ```
32
32
 
33
33
  Scan the QR code it prints with your phone's camera, check that the phone and the terminal show the same six digits, and allow it: you're in, on any network. `--relay` connects through Kiteline's relay, sealed end to end: it passes your sessions on without being able to read them. Leave it out to keep Kiteline to your own Wi-Fi, or [use Tailscale](https://kiteline.seefun.dev/docs/#tailscale).
@@ -35,7 +35,7 @@ Scan the QR code it prints with your phone's camera, check that the phone and th
35
35
  To keep it running in the background, starting with your computer (Linux):
36
36
 
37
37
  ```bash
38
- npm install -g kiteline
38
+ npm install -g kiteline # or: pnpm add -g kiteline, or: bun add -g kiteline
39
39
  kiteline service install --relay
40
40
  ```
41
41
 
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as version } from "./package-CsnKrm9M.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-C1LEhxeO.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")}.`);
@@ -122,7 +122,7 @@ switch (command) {
122
122
  break;
123
123
  }
124
124
  case "service": {
125
- const { service } = await import("./service-CsyQPw0G.mjs");
125
+ const { service } = await import("./service-Fzh98Meh.mjs");
126
126
  await service(action, { force: values.force === true });
127
127
  break;
128
128
  }
@@ -1,3 +1,3 @@
1
1
  // package.json
2
- var version = "0.3.1";
2
+ var version = "0.3.3";
3
3
  export { version as t };
@@ -2,7 +2,7 @@ import { a as localAddress, r as kitelineHome } from "./auth-CYNu-f_h.mjs";
2
2
  import { d as SettingsError, i as dim, m as readSettings, r as bold, t as accent } from "./banner-C1Jj4n4W.mjs";
3
3
  import { homedir, userInfo } from "node:os";
4
4
  import { copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
5
- import { delimiter, dirname, join } from "node:path";
5
+ import { delimiter, dirname, join, resolve } from "node:path";
6
6
  import { spawnSync } from "node:child_process";
7
7
  // src/service.ts
8
8
  /**
@@ -62,7 +62,41 @@ function shellPath() {
62
62
  const kept = (process.env.PATH ?? "").split(delimiter).filter(Boolean).filter((folder) => !/[\\/]_npx[\\/]|node_modules[\\/]\.bin/.test(folder));
63
63
  return [...new Set(kept)].join(delimiter) || "/usr/local/bin:/usr/bin:/bin";
64
64
  }
65
- function unitText(node, script) {
65
+ /** One-off runners keep their copy only for a while; each one's own way to install it for good. */
66
+ const RUNNERS = [
67
+ {
68
+ pattern: /[\\/]_npx[\\/]/,
69
+ name: "npx",
70
+ install: "npm install -g kiteline"
71
+ },
72
+ {
73
+ pattern: /[\\/]dlx[\\/]/,
74
+ name: "pnpm dlx",
75
+ install: "pnpm add -g kiteline"
76
+ },
77
+ {
78
+ pattern: /[\\/]bunx-/,
79
+ name: "bunx",
80
+ install: "bun add -g kiteline"
81
+ }
82
+ ];
83
+ /**
84
+ * What the service runs. npm and bun install Kiteline at a path that stays put across updates, so the
85
+ * service runs that file with this Node. pnpm keeps each global install in a folder of its own and
86
+ * points its `kiteline` command at the current one, so there the service runs that command, which
87
+ * still finds Kiteline after an update.
88
+ */
89
+ function launcher(script, node) {
90
+ const given = resolve(script);
91
+ const real = realpathSync(given);
92
+ const pnpmHome = /^(.*?)[\\/]global[\\/]v?\d+[\\/]/.exec(given)?.[1];
93
+ if (pnpmHome && /[\\/]\.pnpm[\\/]/.test(real)) {
94
+ const command = [join(pnpmHome, "bin", "kiteline"), join(pnpmHome, "kiteline")].find((shim) => existsSync(shim));
95
+ if (command) return [command];
96
+ }
97
+ return [node, real];
98
+ }
99
+ function unitText(command) {
66
100
  const settings = KEPT.flatMap((key) => {
67
101
  const value = process.env[key]?.trim();
68
102
  return value ? [`Environment=${quote(`${key}=${value}`)}`] : [];
@@ -76,7 +110,7 @@ Wants=network-online.target
76
110
 
77
111
  [Service]
78
112
  Type=simple
79
- ExecStart=${quote(node, { command: true })} ${quote(script, { command: true })}
113
+ ExecStart=${command.map((part) => quote(part, { command: true })).join(" ")}
80
114
  ${settings.length ? `${settings.join("\n")}\n` : ""}# Claude Code's Bash tool runs with this shell and finds tools in these folders, as in your terminal.
81
115
  Environment=${quote(`SHELL=${process.env.SHELL || "/bin/sh"}`)}
82
116
  Environment=${quote(`PATH=${shellPath()}`)}
@@ -94,8 +128,10 @@ async function answers(url) {
94
128
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
95
129
  async function install({ force }) {
96
130
  requireSystemd();
97
- const script = realpathSync(process.argv[1] ?? "");
98
- if (/[\\/]_npx[\\/]|[\\/]dlx[\\/]|[\\/]bunx-/.test(script)) fail("This copy of Kiteline came from npx, which may clear it out later, and a service needs one that stays.", "Install it, then set up the service with that copy:", "", ` ${accent("npm install -g kiteline")}`, ` ${accent("kiteline service install")}`);
131
+ const script = process.argv[1] ?? "";
132
+ const real = realpathSync(script);
133
+ const runner = RUNNERS.find(({ pattern }) => pattern.test(real) || pattern.test(script));
134
+ if (runner) fail(`This copy of Kiteline came from ${runner.name}, which may clear it out later, and a service needs one that stays.`, "Install it, then set up the service with that copy:", "", ` ${accent(runner.install)}`, ` ${accent("kiteline service install")}`);
99
135
  let settings;
100
136
  try {
101
137
  settings = readSettings();
@@ -110,7 +146,7 @@ async function install({ force }) {
110
146
  if (!(systemctl("is-active", NAME).stdout.trim() === "active") && await answers(url)) fail(`Something already answers on port ${settings.port}, perhaps Kiteline in another terminal.`, `Stop it first (Ctrl C in its window), then run ${bold("kiteline service install")} again.`);
111
147
  mkdirSync(dirname(file), { recursive: true });
112
148
  if (existing !== null && !existing.includes(MARK)) copyFileSync(file, `${file}.bak`);
113
- writeFileSync(file, unitText(process.execPath, script));
149
+ writeFileSync(file, unitText(launcher(script, process.execPath)));
114
150
  const serverFile = join(kitelineHome(settings.home), "server.json");
115
151
  const before = existsSync(serverFile) ? statSync(serverFile).mtimeMs : 0;
116
152
  for (const step of [
@@ -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-CsnKrm9M.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.1",
3
+ "version": "0.3.3",
4
4
  "description": "Drive Claude Code on your computer from your phone.",
5
5
  "keywords": [
6
6
  "claude",