kiteline 0.1.0 → 0.3.0

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 (42) hide show
  1. package/README.md +5 -5
  2. package/dist/auth-CYNu-f_h.mjs +104 -0
  3. package/dist/{banner-DJdyE8-G.mjs → banner-C1Jj4n4W.mjs} +112 -41
  4. package/dist/cli.mjs +35 -11
  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-D46-e3oS.mjs → package-BoxBh8MJ.mjs} +1 -1
  10. package/dist/pair-command-DBxw6BfK.mjs +107 -0
  11. package/dist/{service-1H4ozSPX.mjs → service-C2w4PsA8.mjs} +17 -22
  12. package/dist/{src-BnClcgTs.mjs → src-CR4MmTcf.mjs} +1375 -1235
  13. package/dist/web/assets/{MagnifyingGlass.es-DLNPT1gT.js → MagnifyingGlass.es-DH9Sttou.js} +1 -1
  14. package/dist/web/assets/Plus.es-1uU9mFYr.js +1 -0
  15. package/dist/web/assets/composer-BcIdpxHM.js +1 -0
  16. package/dist/web/assets/copy-button-DRCJdYml.js +1 -0
  17. package/dist/web/assets/format-BHMU9nwj.js +9 -0
  18. package/dist/web/assets/index-BRaZDA7B.css +1 -0
  19. package/dist/web/assets/index-TWMUhgcM.js +11 -0
  20. package/dist/web/assets/lazy/{core-DbyPnbRm.js → core-pRLcnHpb.js} +1 -1
  21. package/dist/web/assets/new-BbSpVHmG.js +1 -0
  22. package/dist/web/assets/{prefs-CliZrwNF.js → prefs-q6daUElH.js} +1 -1
  23. package/dist/web/assets/routes-lV-e8sSj.js +1 -0
  24. package/dist/web/assets/s._sessionId-t7H-a-HP.js +45 -0
  25. package/dist/web/assets/settings-CbonbiKb.js +1 -0
  26. package/dist/web/assets/status-CKsUN4Lx.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-jhFEXWi7.mjs +0 -30
  32. package/dist/show-pairing-u0LfkF9W.mjs +0 -1
  33. package/dist/web/assets/IconBase.es-CfbvcPwJ.js +0 -9
  34. package/dist/web/assets/composer-B6OuQTWV.js +0 -1
  35. package/dist/web/assets/copy-button-DrJvfi1A.js +0 -1
  36. package/dist/web/assets/index-CA73h-Vn.css +0 -1
  37. package/dist/web/assets/index-Da9GDrpu.js +0 -11
  38. package/dist/web/assets/new-x01_nUpy.js +0 -1
  39. package/dist/web/assets/routes-NIOlnkZY.js +0 -1
  40. package/dist/web/assets/s._sessionId-BtgSN22Q.js +0 -45
  41. package/dist/web/assets/settings-B7yar__r.js +0 -1
  42. package/dist/web/assets/status-BFb0ZUqi.js +0 -1
package/README.md CHANGED
@@ -27,28 +27,28 @@ 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
30
+ npx kiteline --relay
31
31
  ```
32
32
 
33
- Scan the QR code it prints with your phone's camera, and you're in.
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
 
37
37
  ```bash
38
38
  npm install -g kiteline
39
- kiteline service install
39
+ kiteline service install --relay
40
40
  ```
41
41
 
42
42
  Everything else is in the **[docs](https://kiteline.seefun.dev/docs/)**:
43
43
 
44
- - [Reach it from anywhere](https://kiteline.seefun.dev/docs/#anywhere), with Tailscale
44
+ - [Reach it from anywhere](https://kiteline.seefun.dev/docs/#anywhere), and [what the relay sees](https://kiteline.seefun.dev/docs/#relay-privacy)
45
45
  - [Keep it running](https://kiteline.seefun.dev/docs/#always-on) all the time, even with the lid closed
46
46
  - [Approvals](https://kiteline.seefun.dev/docs/#approve) and [permission modes](https://kiteline.seefun.dev/docs/#modes)
47
47
  - [Configuration](https://kiteline.seefun.dev/docs/#config), [security](https://kiteline.seefun.dev/docs/#security) and [troubleshooting](https://kiteline.seefun.dev/docs/#troubleshooting)
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 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
@@ -906,6 +906,51 @@ function renderSVG(data, options = {}) {
906
906
  svg += "</svg>";
907
907
  return svg;
908
908
  }
909
+ // ../../packages/api/src/tunnel/relay-protocol.ts
910
+ /** The relay Kiteline uses unless told otherwise. */
911
+ const DEFAULT_RELAY = "https://relay.kiteline.seefun.dev";
912
+ const RelayPath = {
913
+ /** A computer's standing connection, over which the relay asks it to open channels. */
914
+ host: "/v1/host",
915
+ /** A phone asking for a computer: /v1/client/<hostId>. */
916
+ client: "/v1/client/",
917
+ /** A computer answering a phone: /v1/data/<channel>. */
918
+ data: "/v1/data/"
919
+ };
920
+ /** Close codes, so each side can say plainly what happened. */
921
+ const RelayClose = {
922
+ Replaced: 4e3,
923
+ BadRequest: 4400,
924
+ NotPaired: 4401,
925
+ HostOffline: 4404,
926
+ TooMany: 4429,
927
+ ShuttingDown: 4503,
928
+ HostSilent: 4504
929
+ };
930
+ function toBase64Url(bytes) {
931
+ let binary = "";
932
+ for (const byte of bytes) binary += String.fromCharCode(byte);
933
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
934
+ }
935
+ function fromBase64Url(text) {
936
+ const binary = atob(text.replace(/-/g, "+").replace(/_/g, "/"));
937
+ const out = new Uint8Array(binary.length);
938
+ for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
939
+ return out;
940
+ }
941
+ /**
942
+ * A computer's address at the relay, worked out from its relay secret: whoever can show the secret
943
+ * owns the address, and the relay needs to remember nothing.
944
+ */
945
+ async function hostIdFor(secret) {
946
+ return toBase64Url(new Uint8Array(await crypto.subtle.digest("SHA-256", secret))).slice(0, 22);
947
+ }
948
+ /** The relay's WebSocket address for a path, from its https address. */
949
+ function relaySocketUrl(relay, path) {
950
+ const url = new URL(path, relay);
951
+ url.protocol = url.protocol === "http:" ? "ws:" : "wss:";
952
+ return url.toString();
953
+ }
909
954
  // src/config.ts
910
955
  var SettingsError = class extends Error {};
911
956
  /** `apps/server/.env` when running from a clone; a published package has none. */
@@ -951,18 +996,35 @@ function address(name, what) {
951
996
  } catch {}
952
997
  throw new SettingsError(`${what} (${name}) should be a web address such as https://my-computer.my-tailnet.ts.net, not "${raw}".`);
953
998
  }
999
+ /** on and off, or a relay of your own: KITELINE_RELAY=https://relay.example.com */
1000
+ function relay() {
1001
+ const raw = text("KITELINE_RELAY");
1002
+ if (raw === void 0 || [
1003
+ "off",
1004
+ "false",
1005
+ "0",
1006
+ "no"
1007
+ ].includes(raw.toLowerCase())) return null;
1008
+ if ([
1009
+ "on",
1010
+ "true",
1011
+ "1",
1012
+ "yes"
1013
+ ].includes(raw.toLowerCase())) return DEFAULT_RELAY;
1014
+ return address("KITELINE_RELAY", "The relay");
1015
+ }
954
1016
  function readSettings() {
955
1017
  loadOwnEnvFile();
956
1018
  return {
957
1019
  port: whole("PORT", "The port", 4545, 1, 65535),
958
1020
  host: text("HOST") ?? "0.0.0.0",
959
1021
  publicUrl: address("KITELINE_PUBLIC_URL", "The public address"),
960
- token: text("KITELINE_TOKEN"),
961
1022
  home: text("KITELINE_HOME"),
962
1023
  claudePath: text("CLAUDE_PATH"),
963
1024
  allowBypass: yesNo("KITELINE_ALLOW_BYPASS", "Allowing Bypass mode", true),
964
1025
  maxSessions: whole("KITELINE_MAX_SESSIONS", "The session limit", 6, 1, 100),
965
- idleMinutes: whole("KITELINE_IDLE_MINUTES", "The idle time", 20, 1, 10080)
1026
+ idleMinutes: whole("KITELINE_IDLE_MINUTES", "The idle time", 20, 1, 10080),
1027
+ relay: relay() ?? null
966
1028
  };
967
1029
  }
968
1030
  /** How the person started Kiteline, so the hints it prints name a command they can run. */
@@ -971,7 +1033,7 @@ function startedFromCli() {
971
1033
  viaCli = true;
972
1034
  }
973
1035
  function command(name) {
974
- if (viaCli) return name === "start" ? "kiteline" : "kiteline pair";
1036
+ if (viaCli) return name === "start" ? "kiteline" : `kiteline ${name}`;
975
1037
  return `pnpm ${name}`;
976
1038
  }
977
1039
  /** How to pick another port, in the same terms. */
@@ -986,23 +1048,32 @@ function reachableHosts() {
986
1048
  const rank = (ip) => ip.startsWith("192.168.") ? 0 : ip.startsWith("10.") ? 1 : ip.startsWith("100.") ? 2 : 3;
987
1049
  return hosts.sort((a, b) => rank(a) - rank(b));
988
1050
  }
989
- /**
990
- * The pairing link points at the public URL when one is set (say, the HTTPS
991
- * address from `tailscale serve`), otherwise at the first LAN address.
992
- */
993
- function buildPairing(port, token, options) {
994
- const publicUrl = options.publicUrl?.replace(/\/+$/, "");
995
- const lan = options.loopbackOnly ? [] : reachableHosts().map((host) => `http://${host}:${port}`);
996
- 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 [
1057
+ ...relay ? [relay] : [],
997
1058
  ...publicUrl ? [publicUrl] : [],
998
1059
  ...lan,
999
1060
  `http://localhost:${port}`
1000
1061
  ];
1001
- const url = `${urls[0]}/#pair=${token}`;
1002
- return {
1003
- url,
1004
- urls,
1005
- 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
+ };
1006
1077
  };
1007
1078
  }
1008
1079
  const color = !!process.stdout.isTTY && !process.env.NO_COLOR;
@@ -1010,46 +1081,46 @@ const paint = (open, close) => (s) => color ? `\x1b[${open}m${s}\x1b[${close}m`
1010
1081
  const dim = paint("2", "22");
1011
1082
  const bold = paint("1", "22");
1012
1083
  const accent = paint("38;5;117", "39");
1013
- 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) {
1014
1088
  const lines = [
1015
1089
  "",
1016
1090
  ` ${accent("◆")} ${bold("Kiteline")} ${dim(`v${options.version}`)}${options.dev ? dim(" (dev, web on :4546)") : ""}`,
1017
1091
  "",
1018
- ...pairing.urls.map((url, i) => ` ${dim(i === pairing.urls.length - 1 ? "Local " : "Network ")} ${url}`),
1092
+ ...urls.map((url, i) => {
1093
+ const label = i === urls.length - 1 ? "Local " : url === options.relay ? "Anywhere" : "Network ";
1094
+ return ` ${dim(label)} ${url}`;
1095
+ }),
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 = [
1019
1105
  "",
1020
- ` ${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.`,
1021
1107
  "",
1022
- ...renderUnicodeCompact(pairing.url, { border: 1 }).split("\n").map((row) => ` ${row}`),
1108
+ ...renderUnicodeCompact(link.url, { border: 1 }).split("\n").map((row) => ` ${row}`),
1023
1109
  "",
1024
- ` ${accent(pairing.url)}`,
1025
- ` ${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)}`] : [],
1026
1113
  ""
1027
1114
  ];
1028
1115
  console.log(lines.join("\n"));
1029
1116
  }
1030
- /** Lets `pnpm pair` show the code later without starting a second server. */
1031
- function savePairing(home, pairing, version) {
1032
- const saved = {
1033
- version,
1034
- url: pairing.url,
1035
- urls: pairing.urls,
1036
- startedAt: (/* @__PURE__ */ new Date()).toISOString()
1037
- };
1038
- try {
1039
- mkdirSync(home, {
1040
- recursive: true,
1041
- mode: 448
1042
- });
1043
- writeFileSync(join(home, "pairing.json"), `${JSON.stringify(saved, null, 2)}\n`, { mode: 384 });
1044
- } catch {}
1045
- }
1046
1117
  function printAlreadyRunning(port) {
1047
1118
  console.error([
1048
1119
  "",
1049
1120
  ` ${accent("◆")} ${bold("Kiteline didn't start:")} port ${port} is already in use.`,
1050
1121
  "",
1051
1122
  " If Kiteline is already running, for example as the background service,",
1052
- " there's nothing to start. Show the pairing code with:",
1123
+ " there's nothing to start. Pair a phone with it:",
1053
1124
  "",
1054
1125
  ` ${accent(command("pair"))}`,
1055
1126
  "",
@@ -1064,4 +1135,4 @@ function printSettingsError(message) {
1064
1135
  ""
1065
1136
  ].join("\n"));
1066
1137
  }
1067
- export { printAlreadyRunning as a, savePairing as c, loadOwnEnvFile as d, readSettings as f, dim as i, SettingsError as l, renderSVG as m, bold as n, printBanner as o, startedFromCli as p, buildPairing as r, printSettingsError as s, accent as t, command as u };
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-D46-e3oS.mjs";
3
- import { i as dim, n as bold, p as startedFromCli, t as accent } from "./banner-DJdyE8-G.mjs";
2
+ import { t as version } from "./package-BoxBh8MJ.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
@@ -20,12 +23,13 @@ const HELP = `
20
23
  127.0.0.1 keeps it to this computer, for Tailscale Serve
21
24
  --public-url <url> The address your phone uses, like your Tailscale one;
22
25
  the pairing code points there
23
- --new-token Make a new pairing code, so every device pairs again
26
+ --relay Reach this computer from anywhere, through Kiteline's relay.
27
+ Sealed end to end: the relay passes your sessions on unread
24
28
  --force With service install: replace a service set up by hand
25
29
  -v, --version Show the version
26
30
  -h, --help Show this
27
31
 
28
- The options also work as environment variables (PORT, HOST, KITELINE_PUBLIC_URL), and a few
32
+ The options also work as environment variables (PORT, HOST, KITELINE_PUBLIC_URL, KITELINE_RELAY), and a few
29
33
  more settings do too: ${accent("https://kiteline.seefun.dev/docs/#config")}
30
34
  `;
31
35
  function fail(message) {
@@ -46,6 +50,8 @@ function parse() {
46
50
  host: { type: "string" },
47
51
  "public-url": { type: "string" },
48
52
  "new-token": { type: "boolean" },
53
+ all: { type: "boolean" },
54
+ relay: { type: "boolean" },
49
55
  force: { type: "boolean" },
50
56
  help: {
51
57
  type: "boolean",
@@ -83,22 +89,40 @@ if (values.help || positionals[0] === "help") {
83
89
  if (values.port !== void 0) process.env.PORT = values.port;
84
90
  if (values.host !== void 0) process.env.HOST = values.host;
85
91
  if (values["public-url"] !== void 0) process.env.KITELINE_PUBLIC_URL = values["public-url"];
92
+ if (values.relay) process.env.KITELINE_RELAY ||= "on";
86
93
  startedFromCli();
87
94
  const [command, action, ...rest] = positionals;
88
- 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
+ }
89
106
  switch (command) {
90
107
  case void 0:
91
108
  case "start":
92
109
  if (action) fail(`"${action}" isn't something Kiteline takes. Run ${bold("kiteline --help")}.`);
93
- await import("./src-BnClcgTs.mjs");
110
+ await import("./src-CR4MmTcf.mjs");
94
111
  break;
95
112
  case "pair": {
96
- const { showPairing } = await import("./show-pairing-u0LfkF9W.mjs");
97
- await showPairing();
113
+ if (action) fail(`"${action}" isn't something kiteline pair takes. Run ${bold("kiteline --help")}.`);
114
+ const { pairCommand } = await import("./pair-command-DBxw6BfK.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);
98
122
  break;
99
123
  }
100
124
  case "service": {
101
- const { service } = await import("./service-1H4ozSPX.mjs");
125
+ const { service } = await import("./service-C2w4PsA8.mjs");
102
126
  await service(action, { force: values.force === true });
103
127
  break;
104
128
  }