kiteline 0.2.0 → 0.3.1

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.
Files changed (43) hide show
  1. package/README.md +2 -2
  2. package/dist/auth-CYNu-f_h.mjs +104 -0
  3. package/dist/{banner-CXnDgf5p.mjs → banner-C1Jj4n4W.mjs} +44 -42
  4. package/dist/cli.mjs +30 -10
  5. package/dist/client.BPI7fHX3-CSey2FaL.mjs +1437 -0
  6. package/dist/control-BEq2N-wP.mjs +101 -0
  7. package/dist/control-BpOGsRCZ.mjs +1 -0
  8. package/dist/devices-command-Bubh46v1.mjs +76 -0
  9. package/dist/{package-CbMOnF6R.mjs → package-CsnKrm9M.mjs} +1 -1
  10. package/dist/pair-command-DHeG-ZsP.mjs +120 -0
  11. package/dist/{service-BCgNAv2Z.mjs → service-CsyQPw0G.mjs} +16 -22
  12. package/dist/{src-DSH8d4ZM.mjs → src-C1LEhxeO.mjs} +1054 -1420
  13. package/dist/web/assets/MagnifyingGlass.es-DUOewsuL.js +1 -0
  14. package/dist/web/assets/Plus.es-wuLJIFEO.js +1 -0
  15. package/dist/web/assets/composer-3-vKn_3C.js +1 -0
  16. package/dist/web/assets/copy-button-CSWEBRJT.js +1 -0
  17. package/dist/web/assets/format-DYOlz7Mf.js +9 -0
  18. package/dist/web/assets/index-BRaZDA7B.css +1 -0
  19. package/dist/web/assets/index-DA4jO1yh.js +11 -0
  20. package/dist/web/assets/lazy/{core-CuC-kkU7.js → core-B6TDb-vl.js} +1 -1
  21. package/dist/web/assets/new-BGVIKCzl.js +1 -0
  22. package/dist/web/assets/{prefs-D6OSXuFe.js → prefs-DzSTtEbH.js} +1 -1
  23. package/dist/web/assets/routes-DpVY3ZGq.js +1 -0
  24. package/dist/web/assets/s._sessionId-zegjksnG.js +45 -0
  25. package/dist/web/assets/settings-Dvc2znbn.js +1 -0
  26. package/dist/web/assets/status-D-preq93.js +1 -0
  27. package/dist/web/index.html +3 -3
  28. package/dist/web/sw.js +1 -1
  29. package/package.json +1 -1
  30. package/dist/auth-YhkfTv6K.mjs +0 -60
  31. package/dist/show-pairing-CTd0UfS1.mjs +0 -30
  32. package/dist/show-pairing-Zurbk9wK.mjs +0 -1
  33. package/dist/web/assets/IconBase.es-h0cGkmPy.js +0 -9
  34. package/dist/web/assets/MagnifyingGlass.es-CpSmmHxy.js +0 -1
  35. package/dist/web/assets/composer-WnPpY669.js +0 -1
  36. package/dist/web/assets/copy-button-DBETbWKF.js +0 -1
  37. package/dist/web/assets/index-CA73h-Vn.css +0 -1
  38. package/dist/web/assets/index-CTAi3HIp.js +0 -11
  39. package/dist/web/assets/new-D_XEbYrm.js +0 -1
  40. package/dist/web/assets/routes-Csbxwlji.js +0 -1
  41. package/dist/web/assets/s._sessionId-BlR4dPFc.js +0 -45
  42. package/dist/web/assets/settings-DRpTnWMo.js +0 -1
  43. package/dist/web/assets/status-C7fEa4v1.js +0 -1
package/README.md CHANGED
@@ -30,7 +30,7 @@ You need Node.js 22.18 or newer, and Claude Code signed in on the computer.
30
30
  npx kiteline --relay
31
31
  ```
32
32
 
33
- Scan the QR code it prints with your phone's camera, and 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).
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).
34
34
 
35
35
  To keep it running in the background, starting with your computer (Linux):
36
36
 
@@ -48,7 +48,7 @@ Everything else is in the **[docs](https://kiteline.seefun.dev/docs/)**:
48
48
 
49
49
  ## Good to know
50
50
 
51
- - **Treat the pairing link like a password.** Anyone who opens it can drive Claude Code on your computer. Don't open Kiteline's port to the internet; use `--relay` or Tailscale to reach it from elsewhere.
51
+ - **You approve every device.** A pairing code works once, for ten minutes, and only lets a device ask; it gets in once you allow it, like Bluetooth. Each device has its own key, and you can remove any one in Settings or with `kiteline devices`. Don't open Kiteline's port to the internet; use `--relay` or Tailscale to reach it from elsewhere.
52
52
  - **It uses Claude Code's own login,** your Claude plan or API key. Check that the way you use it fits your plan's terms.
53
53
  - **Tested on Linux so far.** Reports from real phones, macOS and Windows are very welcome.
54
54
 
@@ -0,0 +1,104 @@
1
+ import { homedir } from "node:os";
2
+ import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { randomBytes, timingSafeEqual } from "node:crypto";
5
+ // src/auth.ts
6
+ const DEVICE_COOKIE = "kiteline_device";
7
+ function kitelineHome(override) {
8
+ return override || join(homedir(), ".kiteline");
9
+ }
10
+ function writePrivate(home, name, value) {
11
+ const file = join(home, name);
12
+ mkdirSync(home, {
13
+ recursive: true,
14
+ mode: 448
15
+ });
16
+ writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`, { mode: 384 });
17
+ chmodSync(file, 384);
18
+ }
19
+ /**
20
+ * The computer's own key, in ~/.kiteline/auth.json (mode 600): the `kiteline` commands show it to
21
+ * the Kiteline that's running, to make pairing codes and manage devices. No link or log carries it,
22
+ * and no phone holds it; each of those has a key of its own.
23
+ *
24
+ * Before 0.3 this file held the one pairing code, which every pairing link carried. Finding one of
25
+ * those replaces it, so an old link opens nothing.
26
+ */
27
+ function loadComputerKey(home, options) {
28
+ if (!options.rotate) {
29
+ const key = readComputerKey(home);
30
+ if (key) return {
31
+ key,
32
+ replaced: false
33
+ };
34
+ }
35
+ let replaced = options.rotate;
36
+ try {
37
+ replaced ||= typeof JSON.parse(readFileSync(join(home, "auth.json"), "utf8")).token === "string";
38
+ } catch {}
39
+ const key = randomBytes(32).toString("base64url");
40
+ writePrivate(home, "auth.json", {
41
+ key,
42
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
43
+ });
44
+ return {
45
+ key,
46
+ replaced
47
+ };
48
+ }
49
+ function readComputerKey(home) {
50
+ try {
51
+ const stored = JSON.parse(readFileSync(join(home, "auth.json"), "utf8"));
52
+ return typeof stored.key === "string" && stored.key.length >= 43 ? stored.key : null;
53
+ } catch {
54
+ return null;
55
+ }
56
+ }
57
+ function saveServerInfo(home, info) {
58
+ try {
59
+ writePrivate(home, "server.json", info);
60
+ } catch {}
61
+ }
62
+ function readServerInfo(home) {
63
+ try {
64
+ const info = JSON.parse(readFileSync(join(home, "server.json"), "utf8"));
65
+ return typeof info.local === "string" ? info : null;
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+ /** Where a server listening on `host` answers from this computer. */
71
+ function localAddress(port, host) {
72
+ return `http://${[
73
+ "0.0.0.0",
74
+ "::",
75
+ "127.0.0.1",
76
+ "localhost",
77
+ ""
78
+ ].includes(host) ? "127.0.0.1" : host.includes(":") ? `[${host}]` : host}:${port}`;
79
+ }
80
+ function safeEqual(a, b) {
81
+ const left = Buffer.from(a);
82
+ const right = Buffer.from(b);
83
+ return left.length === right.length && timingSafeEqual(left, right);
84
+ }
85
+ /** Slows down guessing: ten wrong codes from one address locks it out for ten minutes. */
86
+ var PairLimiter = class {
87
+ failures = /* @__PURE__ */ new Map();
88
+ blocked(key) {
89
+ const entry = this.failures.get(key);
90
+ return !!entry && entry.count >= 10 && entry.until > Date.now();
91
+ }
92
+ fail(key) {
93
+ const entry = this.failures.get(key);
94
+ const fresh = !entry || entry.until < Date.now();
95
+ this.failures.set(key, {
96
+ count: fresh ? 1 : entry.count + 1,
97
+ until: Date.now() + 6e5
98
+ });
99
+ }
100
+ clear(key) {
101
+ this.failures.delete(key);
102
+ }
103
+ };
104
+ export { localAddress as a, safeEqual as c, loadComputerKey as i, saveServerInfo as l, PairLimiter as n, readComputerKey as o, kitelineHome as r, readServerInfo as s, DEVICE_COOKIE as t };
@@ -1,6 +1,6 @@
1
1
  import { parseEnv } from "node:util";
2
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
2
  import { networkInterfaces } from "node:os";
3
+ import { existsSync, readFileSync } from "node:fs";
4
4
  import { dirname, join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  // ../../node_modules/.pnpm/uqr@0.1.3/node_modules/uqr/dist/index.mjs
@@ -1019,7 +1019,6 @@ function readSettings() {
1019
1019
  port: whole("PORT", "The port", 4545, 1, 65535),
1020
1020
  host: text("HOST") ?? "0.0.0.0",
1021
1021
  publicUrl: address("KITELINE_PUBLIC_URL", "The public address"),
1022
- token: text("KITELINE_TOKEN"),
1023
1022
  home: text("KITELINE_HOME"),
1024
1023
  claudePath: text("CLAUDE_PATH"),
1025
1024
  allowBypass: yesNo("KITELINE_ALLOW_BYPASS", "Allowing Bypass mode", true),
@@ -1034,7 +1033,7 @@ function startedFromCli() {
1034
1033
  viaCli = true;
1035
1034
  }
1036
1035
  function command(name) {
1037
- if (viaCli) return name === "start" ? "kiteline" : "kiteline pair";
1036
+ if (viaCli) return name === "start" ? "kiteline" : `kiteline ${name}`;
1038
1037
  return `pnpm ${name}`;
1039
1038
  }
1040
1039
  /** How to pick another port, in the same terms. */
@@ -1049,25 +1048,32 @@ function reachableHosts() {
1049
1048
  const rank = (ip) => ip.startsWith("192.168.") ? 0 : ip.startsWith("10.") ? 1 : ip.startsWith("100.") ? 2 : 3;
1050
1049
  return hosts.sort((a, b) => rank(a) - rank(b));
1051
1050
  }
1052
- /**
1053
- * The pairing link points at the public URL when one is set (say, the HTTPS
1054
- * address from `tailscale serve`), otherwise at the first LAN address.
1055
- */
1056
- function buildPairing(port, token, options) {
1057
- const publicUrl = options.publicUrl?.replace(/\/+$/, "");
1058
- const lan = options.loopbackOnly ? [] : reachableHosts().map((host) => `http://${host}:${port}`);
1059
- const relay = options.relay?.url.replace(/\/+$/, "");
1060
- const urls = [
1051
+ /** Every address a phone might reach this computer at: the relay, the public URL, the LAN, this machine. */
1052
+ function addressesFor(port, where) {
1053
+ const publicUrl = where.publicUrl?.replace(/\/+$/, "");
1054
+ const lan = where.loopbackOnly ? [] : reachableHosts().map((host) => `http://${host}:${port}`);
1055
+ const relay = where.relay?.url.replace(/\/+$/, "");
1056
+ return [
1061
1057
  ...relay ? [relay] : [],
1062
1058
  ...publicUrl ? [publicUrl] : [],
1063
1059
  ...lan,
1064
1060
  `http://localhost:${port}`
1065
1061
  ];
1066
- const url = relay ? `${relay}/#host=${options.relay?.hostId}&pair=${token}` : `${urls[0]}/#pair=${token}`;
1067
- return {
1068
- url,
1069
- urls,
1070
- svg: renderSVG(url, { border: 1 })
1062
+ }
1063
+ /**
1064
+ * Where a one-time code goes: through the relay, the link also says which computer, and works on any
1065
+ * network; otherwise it points at the public URL when one is set (say, the HTTPS address from
1066
+ * `tailscale serve`), or else the first LAN address. The code rides after #, which browsers never send.
1067
+ */
1068
+ function pairingLinks(port, where) {
1069
+ const urls = addressesFor(port, where);
1070
+ const relay = where.relay;
1071
+ return (code) => {
1072
+ const url = relay ? `${relay.url.replace(/\/+$/, "")}/#host=${relay.hostId}&code=${code}` : `${urls[0]}/#code=${code}`;
1073
+ return {
1074
+ url,
1075
+ svg: renderSVG(url, { border: 1 })
1076
+ };
1071
1077
  };
1072
1078
  }
1073
1079
  const color = !!process.stdout.isTTY && !process.env.NO_COLOR;
@@ -1075,50 +1081,46 @@ const paint = (open, close) => (s) => color ? `\x1b[${open}m${s}\x1b[${close}m`
1075
1081
  const dim = paint("2", "22");
1076
1082
  const bold = paint("1", "22");
1077
1083
  const accent = paint("38;5;117", "39");
1078
- function printBanner(pairing, options) {
1084
+ /** Six digits as people read them off a screen: 482 913. */
1085
+ const spaced = (match) => `${match.slice(0, 3)} ${match.slice(3)}`;
1086
+ /** Who's running, and where: never a pairing link, which a service's log would keep. */
1087
+ function printBanner(urls, options) {
1079
1088
  const lines = [
1080
1089
  "",
1081
1090
  ` ${accent("◆")} ${bold("Kiteline")} ${dim(`v${options.version}`)}${options.dev ? dim(" (dev, web on :4546)") : ""}`,
1082
1091
  "",
1083
- ...pairing.urls.map((url, i) => {
1084
- const label = i === pairing.urls.length - 1 ? "Local " : url === options.relay ? "Anywhere" : "Network ";
1092
+ ...urls.map((url, i) => {
1093
+ const label = i === urls.length - 1 ? "Local " : url === options.relay ? "Anywhere" : "Network ";
1085
1094
  return ` ${dim(label)} ${url}`;
1086
1095
  }),
1087
1096
  ...options.relay ? ["", ` ${dim("Through the relay, sealed end to end: it passes your sessions on unread.")}`] : [],
1097
+ ""
1098
+ ];
1099
+ console.log(lines.join("\n"));
1100
+ }
1101
+ /** A one-time code to scan, for a person at a terminal. */
1102
+ function printPairingCode(link, options = {}) {
1103
+ const minutes = Math.max(1, Math.round((link.expiresAt - Date.now()) / 6e4));
1104
+ const lines = [
1088
1105
  "",
1089
- ` ${bold("Pair your phone:")} scan this code, or open the link on it.`,
1106
+ ` ${bold("Pair a phone:")} scan this code, or open the link on it.`,
1090
1107
  "",
1091
- ...renderUnicodeCompact(pairing.url, { border: 1 }).split("\n").map((row) => ` ${row}`),
1108
+ ...renderUnicodeCompact(link.url, { border: 1 }).split("\n").map((row) => ` ${row}`),
1092
1109
  "",
1093
- ` ${accent(pairing.url)}`,
1094
- ` ${dim("Keep this link private. Start with --new-token to unpair every device.")}`,
1110
+ ` ${accent(link.url)}`,
1111
+ ` ${dim(`Works once, for the next ${minutes} minutes. You'll be asked to allow the phone.`)}`,
1112
+ ...options.more ? [` ${dim(options.more)}`] : [],
1095
1113
  ""
1096
1114
  ];
1097
1115
  console.log(lines.join("\n"));
1098
1116
  }
1099
- /** Lets `pnpm pair` show the code later without starting a second server. */
1100
- function savePairing(home, pairing, version) {
1101
- const saved = {
1102
- version,
1103
- url: pairing.url,
1104
- urls: pairing.urls,
1105
- startedAt: (/* @__PURE__ */ new Date()).toISOString()
1106
- };
1107
- try {
1108
- mkdirSync(home, {
1109
- recursive: true,
1110
- mode: 448
1111
- });
1112
- writeFileSync(join(home, "pairing.json"), `${JSON.stringify(saved, null, 2)}\n`, { mode: 384 });
1113
- } catch {}
1114
- }
1115
1117
  function printAlreadyRunning(port) {
1116
1118
  console.error([
1117
1119
  "",
1118
1120
  ` ${accent("◆")} ${bold("Kiteline didn't start:")} port ${port} is already in use.`,
1119
1121
  "",
1120
1122
  " If Kiteline is already running, for example as the background service,",
1121
- " there's nothing to start. Show the pairing code with:",
1123
+ " there's nothing to start. Pair a phone with it:",
1122
1124
  "",
1123
1125
  ` ${accent(command("pair"))}`,
1124
1126
  "",
@@ -1133,4 +1135,4 @@ function printSettingsError(message) {
1133
1135
  ""
1134
1136
  ].join("\n"));
1135
1137
  }
1136
- export { hostIdFor as _, printAlreadyRunning as a, renderSVG as b, savePairing as c, loadOwnEnvFile as d, readSettings as f, fromBase64Url as g, RelayPath as h, dim as i, SettingsError as l, RelayClose as m, bold as n, printBanner as o, startedFromCli as p, buildPairing as r, printSettingsError as s, accent as t, command as u, relaySocketUrl as v, toBase64Url as y };
1138
+ export { RelayPath as _, pairingLinks as a, relaySocketUrl as b, printPairingCode as c, SettingsError as d, command as f, RelayClose as g, startedFromCli as h, dim as i, printSettingsError as l, readSettings as m, addressesFor as n, printAlreadyRunning as o, loadOwnEnvFile as p, bold as r, printBanner as s, accent as t, spaced as u, fromBase64Url as v, toBase64Url as x, hostIdFor as y };
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as version } from "./package-CbMOnF6R.mjs";
3
- import { i as dim, n as bold, p as startedFromCli, t as accent } from "./banner-CXnDgf5p.mjs";
2
+ import { t as version } from "./package-CsnKrm9M.mjs";
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
6
6
  const HELP = `
@@ -8,8 +8,11 @@ const HELP = `
8
8
  Drive Claude Code on this computer from your phone.
9
9
 
10
10
  ${bold("Usage")}
11
- kiteline Start Kiteline and show the code that pairs your phone
12
- kiteline pair Show the pairing code again, while Kiteline runs
11
+ kiteline Start Kiteline; the first time, it shows a code to pair your phone
12
+ kiteline pair Pair a phone: a code that works once, then you allow the phone
13
+ kiteline devices See the paired devices, and when each was last used
14
+ kiteline devices remove <name or id>
15
+ Unpair one device; with --all, every one
13
16
  kiteline service install Keep it running in the background, from startup (Linux)
14
17
  kiteline service uninstall Take the background service away
15
18
  kiteline service Say whether it's running in the background
@@ -22,7 +25,6 @@ const HELP = `
22
25
  the pairing code points there
23
26
  --relay Reach this computer from anywhere, through Kiteline's relay.
24
27
  Sealed end to end: the relay passes your sessions on unread
25
- --new-token Make a new pairing code, so every device pairs again
26
28
  --force With service install: replace a service set up by hand
27
29
  -v, --version Show the version
28
30
  -h, --help Show this
@@ -48,6 +50,7 @@ function parse() {
48
50
  host: { type: "string" },
49
51
  "public-url": { type: "string" },
50
52
  "new-token": { type: "boolean" },
53
+ all: { type: "boolean" },
51
54
  relay: { type: "boolean" },
52
55
  force: { type: "boolean" },
53
56
  help: {
@@ -89,20 +92,37 @@ if (values["public-url"] !== void 0) process.env.KITELINE_PUBLIC_URL = values["p
89
92
  if (values.relay) process.env.KITELINE_RELAY ||= "on";
90
93
  startedFromCli();
91
94
  const [command, action, ...rest] = positionals;
92
- if (rest.length) fail(`"${rest.join(" ")}" isn't something Kiteline takes. Run ${bold("kiteline --help")}.`);
95
+ if (rest.length && !(command === "devices" && action !== void 0)) fail(`"${rest.join(" ")}" isn't something Kiteline takes. Run ${bold("kiteline --help")}.`);
96
+ /** The commands that talk to the Kiteline already running, with what to do when it isn't. */
97
+ async function talk(run) {
98
+ const { Unreachable } = await import("./control-BpOGsRCZ.mjs");
99
+ try {
100
+ return await run();
101
+ } catch (error) {
102
+ if (error instanceof Unreachable) fail(error.message);
103
+ throw error;
104
+ }
105
+ }
93
106
  switch (command) {
94
107
  case void 0:
95
108
  case "start":
96
109
  if (action) fail(`"${action}" isn't something Kiteline takes. Run ${bold("kiteline --help")}.`);
97
- await import("./src-DSH8d4ZM.mjs");
110
+ await import("./src-C1LEhxeO.mjs");
98
111
  break;
99
112
  case "pair": {
100
- const { showPairing } = await import("./show-pairing-Zurbk9wK.mjs");
101
- await showPairing();
113
+ if (action) fail(`"${action}" isn't something kiteline pair takes. Run ${bold("kiteline --help")}.`);
114
+ const { pairCommand } = await import("./pair-command-DHeG-ZsP.mjs");
115
+ process.exit(await talk(pairCommand) ? 0 : 1);
116
+ break;
117
+ }
118
+ case "devices": {
119
+ const { devicesCommand } = await import("./devices-command-Bubh46v1.mjs");
120
+ await talk(() => devicesCommand(action, rest.join(" "), { all: values.all === true }));
121
+ process.exit(0);
102
122
  break;
103
123
  }
104
124
  case "service": {
105
- const { service } = await import("./service-BCgNAv2Z.mjs");
125
+ const { service } = await import("./service-CsyQPw0G.mjs");
106
126
  await service(action, { force: values.force === true });
107
127
  break;
108
128
  }