kiteline 0.3.4 → 0.4.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 (45) hide show
  1. package/README.md +4 -2
  2. package/dist/{banner-C1Jj4n4W.mjs → banner-BuOcmDsa.mjs} +2 -1
  3. package/dist/cli.mjs +8 -8
  4. package/dist/{control-B4iYGngw.mjs → control-BgN8_tax.mjs} +6 -2
  5. package/dist/{control-BMOIrur6.mjs → control-C7c3jEfx.mjs} +1 -1
  6. package/dist/{devices-command-Bv_bsDPa.mjs → devices-command-B3MMYPtN.mjs} +2 -2
  7. package/dist/{package-CX75B96-.mjs → package-DHOE_RH7.mjs} +1 -1
  8. package/dist/{pair-command-DyAaiyGn.mjs → pair-command-XALkCQUv.mjs} +2 -2
  9. package/dist/service-C5qMgcr3.mjs +1 -0
  10. package/dist/service-DslziQUi.mjs +350 -0
  11. package/dist/{src-BIPu215q.mjs → src-CTDwjLMW.mjs} +384 -5
  12. package/dist/web/assets/Check.es-BA1UHLtA.js +1 -0
  13. package/dist/web/assets/X.es-DJ1WqcAP.js +1 -0
  14. package/dist/web/assets/composer-BX_w26mL.js +1 -0
  15. package/dist/web/assets/copy-button-B4svySbV.js +1 -0
  16. package/dist/web/assets/format-CvRKEalM.js +9 -0
  17. package/dist/web/assets/index-BuRrTWI4.css +1 -0
  18. package/dist/web/assets/index-DGeAdCJK.js +11 -0
  19. package/dist/web/assets/lazy/{core-CU5HQPlE.js → core-d0pVacdC.js} +1 -1
  20. package/dist/web/assets/new-BoDUmHwx.js +1 -0
  21. package/dist/web/assets/prefs-CbK1R9ph.js +1 -0
  22. package/dist/web/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  23. package/dist/web/assets/routes-BccFpSN5.js +1 -0
  24. package/dist/web/assets/{s._sessionId-BH5Oq7PW.js → s._sessionId-DGue-MjF.js} +12 -12
  25. package/dist/web/assets/settings-DqB0BC9E.js +1 -0
  26. package/dist/web/assets/status-ComAJ-QA.js +1 -0
  27. package/dist/web/assets/version-eBdZEdv0.js +1 -0
  28. package/dist/web/index.html +4 -3
  29. package/dist/web/push-sw.js +45 -0
  30. package/dist/web/sw.js +1 -1
  31. package/package.json +1 -1
  32. package/dist/service-pIzAzHWX.mjs +0 -223
  33. package/dist/web/assets/Check.es-BazDUJ8l.js +0 -1
  34. package/dist/web/assets/Plus.es-BTjK6Adi.js +0 -1
  35. package/dist/web/assets/X.es-BLVrGeYn.js +0 -1
  36. package/dist/web/assets/composer-D3-nzQwm.js +0 -1
  37. package/dist/web/assets/copy-button-B5-YyZiJ.js +0 -1
  38. package/dist/web/assets/format-qC7-v1aY.js +0 -9
  39. package/dist/web/assets/index-DLCIIoKU.js +0 -11
  40. package/dist/web/assets/index-Dfz5hLiZ.css +0 -1
  41. package/dist/web/assets/new-8iHRF9aP.js +0 -1
  42. package/dist/web/assets/prefs-CwnnVOOA.js +0 -1
  43. package/dist/web/assets/routes-BC1QwJvj.js +0 -1
  44. package/dist/web/assets/settings-CFJIOWmt.js +0 -1
  45. package/dist/web/assets/status-DNclzjzI.js +0 -1
@@ -1,12 +1,12 @@
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-CX75B96-.mjs";
2
+ import { t as version$1 } from "./package-DHOE_RH7.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-DfYnQl7W.mjs";
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";
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-BuOcmDsa.mjs";
5
5
  import { homedir, hostname, platform } from "node:os";
6
6
  import { createReadStream, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
7
- import { dirname, join, resolve } from "node:path";
7
+ import { basename, dirname, join, resolve } from "node:path";
8
8
  import { fileURLToPath } from "node:url";
9
- import { randomBytes, randomInt, randomUUID, timingSafeEqual } from "node:crypto";
9
+ import { createCipheriv, createECDH, createPrivateKey, hkdfSync, randomBytes, randomInt, randomUUID, sign, timingSafeEqual } from "node:crypto";
10
10
  import { STATUS_CODES, ServerResponse, createServer } from "node:http";
11
11
  import { Http2ServerRequest, constants } from "node:http2";
12
12
  import { Readable } from "node:stream";
@@ -2542,6 +2542,13 @@ var Run = class {
2542
2542
  // ../../packages/api/src/agent/manager.ts
2543
2543
  /** How long a run that died with an error is remembered. */
2544
2544
  const FAILED_MS = 3e5;
2545
+ /** A turn counts as finished once the session has rested this long: the next queued one starts sooner. */
2546
+ const DONE_SETTLE_MS = 1500;
2547
+ /** A few words of a longer text, on one line. */
2548
+ function snippet(text, max = 180) {
2549
+ const line = text.replace(/\s+/g, " ").trim();
2550
+ return line.length > max ? `${line.slice(0, max - 1).trimEnd()}…` : line;
2551
+ }
2545
2552
  var RunManager = class {
2546
2553
  config;
2547
2554
  runs = /* @__PURE__ */ new Map();
@@ -2553,6 +2560,8 @@ var RunManager = class {
2553
2560
  listWatchers = /* @__PURE__ */ new Set();
2554
2561
  listTimer = null;
2555
2562
  effort;
2563
+ /** Each session's status as last told, and the wait before calling a turn finished. */
2564
+ told = /* @__PURE__ */ new Map();
2556
2565
  constructor(config) {
2557
2566
  this.config = config;
2558
2567
  this.effort = new EffortCatalog(config.claudePath);
@@ -2742,9 +2751,57 @@ var RunManager = class {
2742
2751
  }
2743
2752
  broadcast(sessionId, event) {
2744
2753
  for (const queue of this.sessionWatchers.get(sessionId) ?? []) queue.push(event);
2754
+ if (this.config.notify) this.note(sessionId, event, this.config.notify);
2745
2755
  if (event.type === "status" || event.type === "permission" || event.type === "permission-resolved") this.scheduleListUpdate();
2746
2756
  if (event.type === "item" && event.item.kind === "user") this.scheduleListUpdate();
2747
2757
  }
2758
+ /** Picks out the moments worth a notification: asked for an answer, finished a turn, stopped on an error. */
2759
+ note(sessionId, event, notify) {
2760
+ const run = this.runs.get(sessionId);
2761
+ if (!run) return;
2762
+ const name = run.title || basename(run.cwd) || "Claude Code";
2763
+ if (event.type === "permission") {
2764
+ const { request } = event;
2765
+ const what = request.title || request.description || request.displayName || request.toolName;
2766
+ notify({
2767
+ kind: "permission",
2768
+ sessionId,
2769
+ title: `${name} needs your OK`,
2770
+ body: snippet(what)
2771
+ });
2772
+ return;
2773
+ }
2774
+ if (event.type !== "status") return;
2775
+ const before = this.told.get(sessionId);
2776
+ if (before?.timer) clearTimeout(before.timer);
2777
+ if (event.status === "closed" || event.status === "error") this.told.delete(sessionId);
2778
+ else this.told.set(sessionId, {
2779
+ status: event.status,
2780
+ timer: null
2781
+ });
2782
+ if (event.status === "error") notify({
2783
+ kind: "error",
2784
+ sessionId,
2785
+ title: `${name} stopped`,
2786
+ body: snippet(event.error || "Claude Code stopped with an error.")
2787
+ });
2788
+ else if (event.status === "idle" && (before?.status === "running" || before?.status === "waiting")) {
2789
+ const entry = this.told.get(sessionId);
2790
+ if (!entry) return;
2791
+ entry.timer = setTimeout(() => {
2792
+ entry.timer = null;
2793
+ if (run.status !== "idle") return;
2794
+ const reply = run.items.findLast((item) => item.kind === "text" && item.parent === null);
2795
+ notify({
2796
+ kind: "done",
2797
+ sessionId,
2798
+ title: `${name} is done`,
2799
+ body: snippet(reply?.kind === "text" ? reply.text : "") || "Claude Code finished its turn."
2800
+ });
2801
+ }, DONE_SETTLE_MS);
2802
+ entry.timer.unref?.();
2803
+ }
2804
+ }
2748
2805
  scheduleListUpdate() {
2749
2806
  this.listTimer ??= setTimeout(() => {
2750
2807
  this.listTimer = null;
@@ -3449,6 +3506,236 @@ var Devices = class Devices extends EventEmitter {
3449
3506
  } catch {}
3450
3507
  }
3451
3508
  };
3509
+ // ../../packages/api/src/push.ts
3510
+ /** Who to say the sender is: push services want an address, and this is the project's. */
3511
+ const SUBJECT = "https://kiteline.seefun.dev";
3512
+ /** A notification nobody collected by then isn't worth showing. */
3513
+ const TTL_SECONDS = 3600;
3514
+ /** A push service that keeps failing has lost the subscription, whatever it says. */
3515
+ const MAX_FAILURES = 5;
3516
+ /**
3517
+ * How long a device's word that Kiteline is on its screen holds. It says so again every so often while
3518
+ * that's true, and a phone that locks or loses its connection just stops saying it.
3519
+ */
3520
+ const PRESENCE_MS = 45e3;
3521
+ const b64 = (bytes) => Buffer.from(bytes).toString("base64url");
3522
+ const unb64 = (text) => Buffer.from(text, "base64url");
3523
+ function isSubscription(value) {
3524
+ const s = value;
3525
+ return !!s && typeof s.device === "string" && typeof s.endpoint === "string" && typeof s.p256dh === "string" && typeof s.auth === "string" && !!s.vapid && typeof s.vapid.d === "string" && typeof s.vapid.x === "string" && typeof s.vapid.y === "string";
3526
+ }
3527
+ /** Only a push service over HTTPS: the address comes from a phone, and the computer calls it. */
3528
+ function validEndpoint(endpoint) {
3529
+ try {
3530
+ const url = new URL(endpoint);
3531
+ return url.protocol === "https:" && !!url.hostname && !url.username && !url.password;
3532
+ } catch {
3533
+ return false;
3534
+ }
3535
+ }
3536
+ /**
3537
+ * Seals a message to one browser, as RFC 8291 lays out (aes128gcm): a fresh key pair for each send,
3538
+ * agreed with the browser's own, so only it can open what comes out.
3539
+ */
3540
+ function sealPush(payload, to, fixed) {
3541
+ const browser = unb64(to.p256dh);
3542
+ const secret = unb64(to.auth);
3543
+ if (browser.length !== 65 || browser[0] !== 4) throw new Error("That isn't a browser's push key.");
3544
+ const sender = createECDH("prime256v1");
3545
+ if (fixed) sender.setPrivateKey(fixed.privateKey);
3546
+ else sender.generateKeys();
3547
+ const ours = sender.getPublicKey();
3548
+ const shared = sender.computeSecret(browser);
3549
+ const salt = fixed?.salt ?? randomBytes(16);
3550
+ const info = Buffer.concat([
3551
+ Buffer.from("WebPush: info\0"),
3552
+ browser,
3553
+ ours
3554
+ ]);
3555
+ const material = Buffer.from(hkdfSync("sha256", shared, secret, info, 32));
3556
+ const key = Buffer.from(hkdfSync("sha256", material, salt, "Content-Encoding: aes128gcm\0", 16));
3557
+ const nonce = Buffer.from(hkdfSync("sha256", material, salt, "Content-Encoding: nonce\0", 12));
3558
+ const cipher = createCipheriv("aes-128-gcm", key, nonce);
3559
+ const sealed = Buffer.concat([
3560
+ cipher.update(payload),
3561
+ cipher.update(Buffer.from([2])),
3562
+ cipher.final()
3563
+ ]);
3564
+ const header = Buffer.alloc(21);
3565
+ salt.copy(header, 0);
3566
+ header.writeUInt32BE(4096, 16);
3567
+ header.writeUInt8(ours.length, 20);
3568
+ return Buffer.concat([
3569
+ header,
3570
+ ours,
3571
+ sealed,
3572
+ cipher.getAuthTag()
3573
+ ]);
3574
+ }
3575
+ function signingKey(vapid) {
3576
+ return createPrivateKey({
3577
+ key: {
3578
+ kty: "EC",
3579
+ crv: "P-256",
3580
+ ...vapid
3581
+ },
3582
+ format: "jwk"
3583
+ });
3584
+ }
3585
+ /** The phone's signing key's public half, as the browser was given it when it subscribed. */
3586
+ function vapidPublicKey(vapid) {
3587
+ return b64(Buffer.concat([
3588
+ Buffer.from([4]),
3589
+ unb64(vapid.x),
3590
+ unb64(vapid.y)
3591
+ ]));
3592
+ }
3593
+ /** The header that tells a push service this send is from whoever the phone subscribed to (RFC 8292). */
3594
+ function vapidHeader(endpoint, vapid, now = Date.now()) {
3595
+ const part = (value) => b64(Buffer.from(JSON.stringify(value)));
3596
+ const claims = {
3597
+ aud: new URL(endpoint).origin,
3598
+ exp: Math.floor(now / 1e3) + 43200,
3599
+ sub: SUBJECT
3600
+ };
3601
+ const unsigned = `${part({
3602
+ typ: "JWT",
3603
+ alg: "ES256"
3604
+ })}.${part(claims)}`;
3605
+ const signature = sign("sha256", Buffer.from(unsigned), {
3606
+ key: signingKey(vapid),
3607
+ dsaEncoding: "ieee-p1363"
3608
+ });
3609
+ return `vapid t=${unsigned}.${b64(signature)}, k=${vapidPublicKey(vapid)}`;
3610
+ }
3611
+ var Push = class Push {
3612
+ file;
3613
+ options;
3614
+ subscriptions;
3615
+ failures = /* @__PURE__ */ new Map();
3616
+ /** Devices that said their screen is showing Kiteline, and until when that's believed. */
3617
+ visible = /* @__PURE__ */ new Map();
3618
+ constructor(file, options) {
3619
+ this.file = file;
3620
+ this.options = options;
3621
+ this.subscriptions = Push.load(file);
3622
+ }
3623
+ static load(file) {
3624
+ try {
3625
+ const data = JSON.parse(readFileSync(file, "utf8"));
3626
+ return Array.isArray(data?.subscriptions) ? data.subscriptions.filter(isSubscription) : [];
3627
+ } catch {
3628
+ return [];
3629
+ }
3630
+ }
3631
+ save() {
3632
+ mkdirSync(dirname(this.file), {
3633
+ recursive: true,
3634
+ mode: 448
3635
+ });
3636
+ const temp = `${this.file}.${process.pid}.tmp`;
3637
+ writeFileSync(temp, `${JSON.stringify({
3638
+ version: 1,
3639
+ subscriptions: this.subscriptions
3640
+ }, null, 2)}\n`, { mode: 384 });
3641
+ renameSync(temp, this.file);
3642
+ }
3643
+ /** Where this device's notifications go, if it has them on. */
3644
+ status(device) {
3645
+ const found = this.subscriptions.find((s) => s.device === device);
3646
+ return {
3647
+ enabled: !!found,
3648
+ endpoint: found?.endpoint ?? null
3649
+ };
3650
+ }
3651
+ /**
3652
+ * Turns notifications on for a device, and sends one to show it worked: a subscription that can't be
3653
+ * sent to isn't kept. `quiet` skips that, for a device giving a changed subscription again.
3654
+ */
3655
+ async subscribe(device, subscription, { quiet = false } = {}) {
3656
+ if (!validEndpoint(subscription.endpoint)) throw new Error("That isn't a push service's address.");
3657
+ try {
3658
+ vapidHeader(subscription.endpoint, subscription.vapid);
3659
+ sealPush(/* @__PURE__ */ new Uint8Array(), subscription);
3660
+ } catch {
3661
+ throw new Error("This phone's keys for notifications can't be used. Turn them off and on again.");
3662
+ }
3663
+ const stored = {
3664
+ ...subscription,
3665
+ device,
3666
+ addedAt: (/* @__PURE__ */ new Date()).toISOString()
3667
+ };
3668
+ const outcome = quiet ? "sent" : await this.deliver(stored, {
3669
+ kind: "hello",
3670
+ title: "Notifications are on",
3671
+ body: "Kiteline will tell you here when Claude Code needs you or finishes."
3672
+ });
3673
+ if (outcome !== "sent") throw new Error(outcome === "gone" ? "This phone's push service turned the notification away. Turn notifications off and on again." : "Your computer couldn't reach this phone's push service. Check its internet connection.");
3674
+ this.subscriptions = [...this.subscriptions.filter((s) => s.device !== device), stored];
3675
+ this.failures.delete(device);
3676
+ this.save();
3677
+ }
3678
+ unsubscribe(device) {
3679
+ this.visible.delete(device);
3680
+ this.failures.delete(device);
3681
+ if (!this.subscriptions.some((s) => s.device === device)) return;
3682
+ this.subscriptions = this.subscriptions.filter((s) => s.device !== device);
3683
+ try {
3684
+ this.save();
3685
+ } catch {}
3686
+ }
3687
+ /** A device says whether Kiteline is on its screen: while it is, there's nothing to notify it of. */
3688
+ presence(device, visible) {
3689
+ if (visible) this.visible.set(device, Date.now() + PRESENCE_MS);
3690
+ else this.visible.delete(device);
3691
+ }
3692
+ watching(device) {
3693
+ return (this.visible.get(device) ?? 0) > Date.now();
3694
+ }
3695
+ /** Tells every device that has notifications on and isn't looking at Kiteline right now. */
3696
+ async notify(note) {
3697
+ const away = this.subscriptions.filter((s) => !this.watching(s.device));
3698
+ await Promise.all(away.map(async (subscription) => {
3699
+ const outcome = await this.deliver(subscription, note);
3700
+ if (outcome === "sent") {
3701
+ this.failures.delete(subscription.device);
3702
+ return;
3703
+ }
3704
+ const failures = (this.failures.get(subscription.device) ?? 0) + 1;
3705
+ this.failures.set(subscription.device, failures);
3706
+ if (outcome === "gone" || failures >= MAX_FAILURES) {
3707
+ this.options.log?.("A phone's notifications stopped working, so they're turned off for it.");
3708
+ this.unsubscribe(subscription.device);
3709
+ }
3710
+ }));
3711
+ }
3712
+ async deliver(to, note) {
3713
+ try {
3714
+ const computer = this.options.computer;
3715
+ const body = sealPush(Buffer.from(JSON.stringify({
3716
+ ...note,
3717
+ ...computer ? { computer } : {}
3718
+ })), to);
3719
+ const response = await (this.options.send ?? ((url, init) => fetch(url, init)))(to.endpoint, {
3720
+ method: "POST",
3721
+ headers: {
3722
+ authorization: vapidHeader(to.endpoint, to.vapid),
3723
+ "content-encoding": "aes128gcm",
3724
+ "content-type": "application/octet-stream",
3725
+ ttl: String(TTL_SECONDS),
3726
+ urgency: "high",
3727
+ ...note.sessionId ? { topic: note.sessionId.replaceAll("-", "").slice(0, 32) } : {}
3728
+ },
3729
+ body: new Uint8Array(body),
3730
+ signal: AbortSignal.timeout(15e3)
3731
+ });
3732
+ if (response.status >= 200 && response.status < 300) return "sent";
3733
+ return response.status === 404 || response.status === 410 ? "gone" : "failed";
3734
+ } catch {
3735
+ return "failed";
3736
+ }
3737
+ }
3738
+ };
3452
3739
  // ../../node_modules/.pnpm/@orpc+contract@1.16.1_@opentelemetry+api@1.10.0/node_modules/@orpc/contract/dist/shared/contract.D_dZrO__.mjs
3453
3740
  var ValidationError = class extends Error {
3454
3741
  issues;
@@ -9383,6 +9670,9 @@ const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
9383
9670
  $ZodURL.init(inst, def);
9384
9671
  ZodStringFormat.init(inst, def);
9385
9672
  });
9673
+ function url(params) {
9674
+ return /* @__PURE__ */ _url(ZodURL, params);
9675
+ }
9386
9676
  const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
9387
9677
  $ZodEmoji.init(inst, def);
9388
9678
  ZodStringFormat.init(inst, def);
@@ -9992,6 +10282,41 @@ dirs: protectedProcedure.input(object({
9992
10282
  dirs
9993
10283
  };
9994
10284
  }) };
10285
+ // ../../packages/api/src/routers/push.ts
10286
+ const key = string().regex(/^[\w-]+$/);
10287
+ /** Notifications are a device's own: the terminal has none to turn on. */
10288
+ function device(context) {
10289
+ if (context.caller?.kind !== "device") throw new ORPCError("BAD_REQUEST", { message: "Notifications are turned on from a paired device." });
10290
+ return context.caller.id;
10291
+ }
10292
+ /** Lock-screen notifications for the device that's asking; see ../push. */
10293
+ const pushRouter = {
10294
+ status: protectedProcedure.handler(({ context }) => context.push.status(device(context))),
10295
+ subscribe: protectedProcedure.input(object({
10296
+ endpoint: url().max(2e3),
10297
+ p256dh: key.min(80).max(100),
10298
+ auth: key.min(16).max(64),
10299
+ vapid: object({
10300
+ d: key.max(64),
10301
+ x: key.max(64),
10302
+ y: key.max(64)
10303
+ }),
10304
+ /** Giving a changed subscription again, with nothing to show for it. */
10305
+ quiet: boolean().optional()
10306
+ })).handler(async ({ input: { quiet, ...subscription }, context }) => {
10307
+ await context.push.subscribe(device(context), subscription, { quiet });
10308
+ return { ok: true };
10309
+ }),
10310
+ unsubscribe: protectedProcedure.handler(({ context }) => {
10311
+ context.push.unsubscribe(device(context));
10312
+ return { ok: true };
10313
+ }),
10314
+ /** Whether Kiteline is on this device's screen: while it is, it isn't sent notifications. */
10315
+ presence: protectedProcedure.input(object({ visible: boolean() })).handler(({ input, context }) => {
10316
+ context.push.presence(device(context), input.visible);
10317
+ return { ok: true };
10318
+ })
10319
+ };
9995
10320
  // ../../packages/api/src/routers/runs.ts
9996
10321
  const permissionMode = _enum(PERMISSION_MODES);
9997
10322
  const effort = object({
@@ -10173,9 +10498,11 @@ const appRouter = {
10173
10498
  home: homedir(),
10174
10499
  platform: platform(),
10175
10500
  version: context.version,
10501
+ latest: context.latestVersion(),
10176
10502
  allowBypass: context.allowBypass
10177
10503
  })) },
10178
10504
  devices: devicesRouter,
10505
+ push: pushRouter,
10179
10506
  sessions: sessionsRouter,
10180
10507
  runs: runsRouter,
10181
10508
  fs: fsRouter
@@ -13321,6 +13648,50 @@ async function startRelay(options) {
13321
13648
  }
13322
13649
  };
13323
13650
  }
13651
+ // src/update.ts
13652
+ /**
13653
+ * Looks up the newest Kiteline on npm, so the terminal and the app can say when there's an update.
13654
+ * It asks for the package's public page and sends nothing about this computer; KITELINE_UPDATE_CHECK=off
13655
+ * turns it off.
13656
+ */
13657
+ const LATEST = "https://registry.npmjs.org/kiteline/latest";
13658
+ const FIRST_MS = 2e4;
13659
+ const EVERY_MS = 432e5;
13660
+ function parts(version) {
13661
+ const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
13662
+ return match ? [
13663
+ Number(match[1]),
13664
+ Number(match[2]),
13665
+ Number(match[3])
13666
+ ] : null;
13667
+ }
13668
+ /** Whether `candidate` is a newer release than `current`. Anything that isn't a plain x.y.z is not. */
13669
+ function isNewer(candidate, current) {
13670
+ const theirs = parts(candidate);
13671
+ const ours = parts(current);
13672
+ if (!theirs || !ours) return false;
13673
+ for (let i = 0; i < 3; i++) if (theirs[i] !== ours[i]) return (theirs[i] ?? 0) > (ours[i] ?? 0);
13674
+ return false;
13675
+ }
13676
+ function watchForUpdates(current, onNewer) {
13677
+ let latest = null;
13678
+ const check = async () => {
13679
+ try {
13680
+ const response = await fetch(LATEST, {
13681
+ headers: { accept: "application/json" },
13682
+ signal: AbortSignal.timeout(1e4)
13683
+ });
13684
+ if (!response.ok) return;
13685
+ const { version } = await response.json();
13686
+ if (typeof version !== "string" || !isNewer(version, current) || version === latest) return;
13687
+ latest = version;
13688
+ onNewer(version);
13689
+ } catch {}
13690
+ };
13691
+ setTimeout(() => void check(), FIRST_MS).unref();
13692
+ setInterval(() => void check(), EVERY_MS).unref();
13693
+ return () => latest;
13694
+ }
13324
13695
  // src/index.ts
13325
13696
  const dev = process.argv.includes("--dev");
13326
13697
  let settings;
@@ -13351,16 +13722,23 @@ const pairingLink = pairingLinks(webPort, where);
13351
13722
  const limiter = new PairLimiter();
13352
13723
  const interactive = !dev && !!process.stdin.isTTY && !!process.stdout.isTTY;
13353
13724
  const log = (message) => console.log(` ${message}`);
13725
+ const push = new Push(join(home, "push.json"), {
13726
+ computer: where.relay?.hostId,
13727
+ log
13728
+ });
13354
13729
  const manager = new RunManager({
13355
13730
  claudePath: settings.claudePath ?? null,
13356
13731
  allowBypass,
13357
13732
  maxLiveRuns: settings.maxSessions,
13358
13733
  idleTimeoutMs: settings.idleMinutes * 6e4,
13359
- tracker: new SessionTracker(join(home, "sessions.json"))
13734
+ tracker: new SessionTracker(join(home, "sessions.json")),
13735
+ notify: (note) => void push.notify(note)
13360
13736
  });
13361
13737
  const shared = {
13362
13738
  manager,
13363
13739
  devices,
13740
+ push,
13741
+ latestVersion: dev || !settings.updateCheck ? () => null : watchForUpdates(version$1, (version) => log(`Kiteline ${version} is out, and this is ${version$1}. Update with: npm install -g kiteline@latest`)),
13364
13742
  pairingLink,
13365
13743
  allowBypass,
13366
13744
  version: version$1
@@ -13603,6 +13981,7 @@ if (!dev && webDir) {
13603
13981
  } else if (!dev) app.get("/", (c) => c.text("Kiteline's API is running. Build the web app with `pnpm build` to serve it from here."));
13604
13982
  let relay = null;
13605
13983
  devices.on("removed", (device, by) => {
13984
+ push.unsubscribe(device.id);
13606
13985
  const self = by.kind === "device" && by.id === device.id;
13607
13986
  setTimeout(() => {
13608
13987
  for (const cut of [...streams.get(device.id) ?? []]) cut();
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{br as t,en as n}from"./format-CvRKEalM.js";var r=e(t(),1),i=new Map([[`bold`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M232.49,80.49l-128,128a12,12,0,0,1-17,0l-56-56a12,12,0,1,1,17-17L96,183,215.51,63.51a12,12,0,0,1,17,17Z`}))],[`duotone`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M232,56V200a16,16,0,0,1-16,16H40a16,16,0,0,1-16-16V56A16,16,0,0,1,40,40H216A16,16,0,0,1,232,56Z`,opacity:`0.2`}),r.createElement(`path`,{d:`M205.66,85.66l-96,96a8,8,0,0,1-11.32,0l-40-40a8,8,0,0,1,11.32-11.32L104,164.69l90.34-90.35a8,8,0,0,1,11.32,11.32Z`}))],[`fill`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M216,40H40A16,16,0,0,0,24,56V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V56A16,16,0,0,0,216,40ZM205.66,85.66l-96,96a8,8,0,0,1-11.32,0l-40-40a8,8,0,0,1,11.32-11.32L104,164.69l90.34-90.35a8,8,0,0,1,11.32,11.32Z`}))],[`light`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M228.24,76.24l-128,128a6,6,0,0,1-8.48,0l-56-56a6,6,0,0,1,8.48-8.48L96,191.51,219.76,67.76a6,6,0,0,1,8.48,8.48Z`}))],[`regular`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M229.66,77.66l-128,128a8,8,0,0,1-11.32,0l-56-56a8,8,0,0,1,11.32-11.32L96,188.69,218.34,66.34a8,8,0,0,1,11.32,11.32Z`}))],[`thin`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M226.83,74.83l-128,128a4,4,0,0,1-5.66,0l-56-56a4,4,0,0,1,5.66-5.66L96,194.34,221.17,69.17a4,4,0,1,1,5.66,5.66Z`}))]]),a=r.forwardRef((e,t)=>r.createElement(n,{ref:t,...e,weights:i}));a.displayName=`CheckIcon`;export{a as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{br as t,en as n}from"./format-CvRKEalM.js";var r=e(t(),1),i=new Map([[`bold`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M184.49,136.49l-80,80a12,12,0,0,1-17-17L159,128,87.51,56.49a12,12,0,1,1,17-17l80,80A12,12,0,0,1,184.49,136.49Z`}))],[`duotone`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M176,128,96,208V48Z`,opacity:`0.2`}),r.createElement(`path`,{d:`M181.66,122.34l-80-80A8,8,0,0,0,88,48V208a8,8,0,0,0,13.66,5.66l80-80A8,8,0,0,0,181.66,122.34ZM104,188.69V67.31L164.69,128Z`}))],[`fill`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M181.66,133.66l-80,80A8,8,0,0,1,88,208V48a8,8,0,0,1,13.66-5.66l80,80A8,8,0,0,1,181.66,133.66Z`}))],[`light`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M180.24,132.24l-80,80a6,6,0,0,1-8.48-8.48L167.51,128,91.76,52.24a6,6,0,0,1,8.48-8.48l80,80A6,6,0,0,1,180.24,132.24Z`}))],[`regular`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M181.66,133.66l-80,80a8,8,0,0,1-11.32-11.32L164.69,128,90.34,53.66a8,8,0,0,1,11.32-11.32l80,80A8,8,0,0,1,181.66,133.66Z`}))],[`thin`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M178.83,130.83l-80,80a4,4,0,0,1-5.66-5.66L170.34,128,93.17,50.83a4,4,0,0,1,5.66-5.66l80,80A4,4,0,0,1,178.83,130.83Z`}))]]),a=new Map([[`bold`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M216,68H132L105.33,48a20.12,20.12,0,0,0-12-4H40A20,20,0,0,0,20,64V200a20,20,0,0,0,20,20H216.89A19.13,19.13,0,0,0,236,200.89V88A20,20,0,0,0,216,68Zm-4,128H44V68H92l28.8,21.6A12,12,0,0,0,128,92h84Z`}))],[`duotone`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M224,88V200.89a7.11,7.11,0,0,1-7.11,7.11H40a8,8,0,0,1-8-8V64a8,8,0,0,1,8-8H93.33a8,8,0,0,1,4.8,1.6L128,80h88A8,8,0,0,1,224,88Z`,opacity:`0.2`}),r.createElement(`path`,{d:`M216,72H130.67L102.93,51.2a16.12,16.12,0,0,0-9.6-3.2H40A16,16,0,0,0,24,64V200a16,16,0,0,0,16,16H216.89A15.13,15.13,0,0,0,232,200.89V88A16,16,0,0,0,216,72Zm0,128H40V64H93.33L123.2,86.4A8,8,0,0,0,128,88h88Z`}))],[`fill`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M232,88V200.89A15.13,15.13,0,0,1,216.89,216H40a16,16,0,0,1-16-16V64A16,16,0,0,1,40,48H93.33a16.12,16.12,0,0,1,9.6,3.2L130.67,72H216A16,16,0,0,1,232,88Z`}))],[`light`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M216,74H130L101.73,52.8a14,14,0,0,0-8.4-2.8H40A14,14,0,0,0,26,64V200a14,14,0,0,0,14,14H216.89A13.12,13.12,0,0,0,230,200.89V88A14,14,0,0,0,216,74Zm2,126.89a1.11,1.11,0,0,1-1.11,1.11H40a2,2,0,0,1-2-2V64a2,2,0,0,1,2-2H93.33a2,2,0,0,1,1.2.4L124.4,84.8A6,6,0,0,0,128,86h88a2,2,0,0,1,2,2Z`}))],[`regular`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M216,72H130.67L102.93,51.2a16.12,16.12,0,0,0-9.6-3.2H40A16,16,0,0,0,24,64V200a16,16,0,0,0,16,16H216.89A15.13,15.13,0,0,0,232,200.89V88A16,16,0,0,0,216,72Zm0,128H40V64H93.33L123.2,86.4A8,8,0,0,0,128,88h88Z`}))],[`thin`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M216,76H129.33l-28.8-21.6a12.05,12.05,0,0,0-7.2-2.4H40A12,12,0,0,0,28,64V200a12,12,0,0,0,12,12H216.89A11.12,11.12,0,0,0,228,200.89V88A12,12,0,0,0,216,76Zm4,124.89a3.12,3.12,0,0,1-3.11,3.11H40a4,4,0,0,1-4-4V64a4,4,0,0,1,4-4H93.33a4,4,0,0,1,2.4.8L125.6,83.2a4,4,0,0,0,2.4.8h88a4,4,0,0,1,4,4Z`}))]]),o=new Map([[`bold`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M236,64a36,36,0,1,0-48,33.94V112a4,4,0,0,1-4,4H96a27.8,27.8,0,0,0-4,.29V97.94a36,36,0,1,0-24,0v60.12a36,36,0,1,0,24,0V144a4,4,0,0,1,4-4h88a28,28,0,0,0,28-28V97.94A36.07,36.07,0,0,0,236,64ZM80,52A12,12,0,1,1,68,64,12,12,0,0,1,80,52Zm0,152a12,12,0,1,1,12-12A12,12,0,0,1,80,204ZM200,76a12,12,0,1,1,12-12A12,12,0,0,1,200,76Z`}))],[`duotone`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M224,64a24,24,0,1,1-24-24A24,24,0,0,1,224,64Z`,opacity:`0.2`}),r.createElement(`path`,{d:`M232,64a32,32,0,1,0-40,31v17a8,8,0,0,1-8,8H96a23.84,23.84,0,0,0-8,1.38V95a32,32,0,1,0-16,0v66a32,32,0,1,0,16,0V144a8,8,0,0,1,8-8h88a24,24,0,0,0,24-24V95A32.06,32.06,0,0,0,232,64ZM64,64A16,16,0,1,1,80,80,16,16,0,0,1,64,64ZM96,192a16,16,0,1,1-16-16A16,16,0,0,1,96,192ZM200,80a16,16,0,1,1,16-16A16,16,0,0,1,200,80Z`}))],[`fill`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M232,64a32,32,0,1,0-40,31v17a8,8,0,0,1-8,8H96a23.84,23.84,0,0,0-8,1.38V95a32,32,0,1,0-16,0v66a32,32,0,1,0,16,0V144a8,8,0,0,1,8-8h88a24,24,0,0,0,24-24V95A32.06,32.06,0,0,0,232,64ZM64,64A16,16,0,1,1,80,80,16,16,0,0,1,64,64ZM96,192a16,16,0,1,1-16-16A16,16,0,0,1,96,192Z`}))],[`light`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M230,64a30,30,0,1,0-36,29.4V112a10,10,0,0,1-10,10H96a21.84,21.84,0,0,0-10,2.42v-31a30,30,0,1,0-12,0v69.2a30,30,0,1,0,12,0V144a10,10,0,0,1,10-10h88a22,22,0,0,0,22-22V93.4A30.05,30.05,0,0,0,230,64ZM62,64A18,18,0,1,1,80,82,18,18,0,0,1,62,64ZM98,192a18,18,0,1,1-18-18A18,18,0,0,1,98,192ZM200,82a18,18,0,1,1,18-18A18,18,0,0,1,200,82Z`}))],[`regular`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M232,64a32,32,0,1,0-40,31v17a8,8,0,0,1-8,8H96a23.84,23.84,0,0,0-8,1.38V95a32,32,0,1,0-16,0v66a32,32,0,1,0,16,0V144a8,8,0,0,1,8-8h88a24,24,0,0,0,24-24V95A32.06,32.06,0,0,0,232,64ZM64,64A16,16,0,1,1,80,80,16,16,0,0,1,64,64ZM96,192a16,16,0,1,1-16-16A16,16,0,0,1,96,192ZM200,80a16,16,0,1,1,16-16A16,16,0,0,1,200,80Z`}))],[`thin`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M228,64a28,28,0,1,0-32,27.71V112a12,12,0,0,1-12,12H96a19.91,19.91,0,0,0-12,4V91.71a28,28,0,1,0-8,0v72.58a28,28,0,1,0,8,0V144a12,12,0,0,1,12-12h88a20,20,0,0,0,20-20V91.71A28,28,0,0,0,228,64ZM60,64A20,20,0,1,1,80,84,20,20,0,0,1,60,64Zm40,128a20,20,0,1,1-20-20A20,20,0,0,1,100,192ZM200,84a20,20,0,1,1,20-20A20,20,0,0,1,200,84Z`}))]]),s=new Map([[`bold`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M232.49,215.51,185,168a92.12,92.12,0,1,0-17,17l47.53,47.54a12,12,0,0,0,17-17ZM44,112a68,68,0,1,1,68,68A68.07,68.07,0,0,1,44,112Z`}))],[`duotone`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M192,112a80,80,0,1,1-80-80A80,80,0,0,1,192,112Z`,opacity:`0.2`}),r.createElement(`path`,{d:`M229.66,218.34,179.6,168.28a88.21,88.21,0,1,0-11.32,11.31l50.06,50.07a8,8,0,0,0,11.32-11.32ZM40,112a72,72,0,1,1,72,72A72.08,72.08,0,0,1,40,112Z`}))],[`fill`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M168,112a56,56,0,1,1-56-56A56,56,0,0,1,168,112Zm61.66,117.66a8,8,0,0,1-11.32,0l-50.06-50.07a88,88,0,1,1,11.32-11.31l50.06,50.06A8,8,0,0,1,229.66,229.66ZM112,184a72,72,0,1,0-72-72A72.08,72.08,0,0,0,112,184Z`}))],[`light`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M228.24,219.76l-51.38-51.38a86.15,86.15,0,1,0-8.48,8.48l51.38,51.38a6,6,0,0,0,8.48-8.48ZM38,112a74,74,0,1,1,74,74A74.09,74.09,0,0,1,38,112Z`}))],[`regular`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M229.66,218.34l-50.07-50.06a88.11,88.11,0,1,0-11.31,11.31l50.06,50.07a8,8,0,0,0,11.32-11.32ZM40,112a72,72,0,1,1,72,72A72.08,72.08,0,0,1,40,112Z`}))],[`thin`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M226.83,221.17l-52.7-52.7a84.1,84.1,0,1,0-5.66,5.66l52.7,52.7a4,4,0,0,0,5.66-5.66ZM36,112a76,76,0,1,1,76,76A76.08,76.08,0,0,1,36,112Z`}))]]),c=new Map([[`bold`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M208.49,191.51a12,12,0,0,1-17,17L128,145,64.49,208.49a12,12,0,0,1-17-17L111,128,47.51,64.49a12,12,0,0,1,17-17L128,111l63.51-63.52a12,12,0,0,1,17,17L145,128Z`}))],[`duotone`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M216,56V200a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V56A16,16,0,0,1,56,40H200A16,16,0,0,1,216,56Z`,opacity:`0.2`}),r.createElement(`path`,{d:`M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z`}))],[`fill`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM181.66,170.34a8,8,0,0,1-11.32,11.32L128,139.31,85.66,181.66a8,8,0,0,1-11.32-11.32L116.69,128,74.34,85.66A8,8,0,0,1,85.66,74.34L128,116.69l42.34-42.35a8,8,0,0,1,11.32,11.32L139.31,128Z`}))],[`light`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M204.24,195.76a6,6,0,1,1-8.48,8.48L128,136.49,60.24,204.24a6,6,0,0,1-8.48-8.48L119.51,128,51.76,60.24a6,6,0,0,1,8.48-8.48L128,119.51l67.76-67.75a6,6,0,0,1,8.48,8.48L136.49,128Z`}))],[`regular`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z`}))],[`thin`,r.createElement(r.Fragment,null,r.createElement(`path`,{d:`M202.83,197.17a4,4,0,0,1-5.66,5.66L128,133.66,58.83,202.83a4,4,0,0,1-5.66-5.66L122.34,128,53.17,58.83a4,4,0,0,1,5.66-5.66L128,122.34l69.17-69.17a4,4,0,1,1,5.66,5.66L133.66,128Z`}))]]),l=r.forwardRef((e,t)=>r.createElement(n,{ref:t,...e,weights:i}));l.displayName=`CaretRightIcon`;var u=r.forwardRef((e,t)=>r.createElement(n,{ref:t,...e,weights:a}));u.displayName=`FolderSimpleIcon`;var d=r.forwardRef((e,t)=>r.createElement(n,{ref:t,...e,weights:o}));d.displayName=`GitBranchIcon`;var f=r.forwardRef((e,t)=>r.createElement(n,{ref:t,...e,weights:s}));f.displayName=`MagnifyingGlassIcon`;var p=r.forwardRef((e,t)=>r.createElement(n,{ref:t,...e,weights:c}));p.displayName=`XIcon`;export{l as a,u as i,f as n,d as r,p as t};