gent-link 0.2.21

Connect Codex and Claude Code chats across machines with the Gent CLI and desktop companion.
(() => {
  const dashboards = window.gentDashboards;
  const {byId, notice} = window.gentUI;
  const close = byId("close-tray");
  const desktop = byId("open-desktop");
  const content = byId("dashboard-content");
  let shown = false, closing = false, snapshot = null, reveal = null;
  dashboards.mount(content, {tray: true});

  function visible(next) {
    shown = next;
    reveal?.cancel();
    reveal = null;
    dashboards.visible(next);
    if (next) {
      if (snapshot) {
        dashboards.receive(snapshot);
        if (matchMedia("(prefers-reduced-motion: no-preference)").matches) {
          reveal = content.animate([
            {opacity: 0.84, clipPath: "inset(8px round 6px)"},
            {opacity: 1, clipPath: "inset(0 round 0px)"}
          ], {duration: 120, easing: "ease-out"});
        }
      } else dashboards.refresh();
      if (document.activeElement === document.body) close.focus({preventScroll: true});
    }
    snapshot = null;
  }

  function dismiss() {
    if (closing) return;
    closing = true;
    visible(false);
    window.gent.closeTray().catch(() => {
      if (!closing) return;
      closing = false;
      visible(true);
      notice("bridge-error", "Could not close the dashboard panel.", true);
    });
  }
  close.addEventListener("click", dismiss);
  desktop.addEventListener("click", () => {
    window.gent.openDesktop().catch(() => notice("bridge-error", "Could not open Gent Desktop.", true));
  });
  const resizeError = () => notice("bridge-error", "Could not resize the dashboard panel.", true);
  const steps = {ArrowLeft: [-16, 0], ArrowRight: [16, 0], ArrowUp: [0, -16], ArrowDown: [0, 16]};
  for (const grip of byId("tray-grips").querySelectorAll("button")) {
    const edge = grip.dataset.edge;
    const horizontal = edge.includes("left") ? -1 : edge.includes("right") ? 1 : 0;
    const vertical = edge === "top" ? -1 : edge.includes("bottom") ? 1 : 0;
    const shortcuts = Object.keys(steps).filter(key => steps[key][0] ? horizontal : vertical);
    grip.setAttribute("aria-keyshortcuts", shortcuts.join(" "));
    grip.title = grip.getAttribute("aria-label") + " ยท drag or use arrow keys";
    grip.disabled = !window.gent;
    const startDrag = () => window.gent.startTrayResize(edge).catch(resizeError);
    // A compositor can consume mouse-up during resize; WebKit still delivers
    // the next mouse-down even if it omits that gesture's pointer-down.
    grip.addEventListener("mousedown", event => {
      if (event.button === 0) startDrag();
    });
    grip.addEventListener("pointerdown", event => {
      if (event.pointerType === "mouse" || !event.isPrimary || event.button !== 0) return;
      event.preventDefault(); // Suppress the compatibility mouse-down for touch and pen.
      startDrag();
    });
    grip.addEventListener("keydown", event => {
      if (!shortcuts.includes(event.key) || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
      event.preventDefault();
      const [dx, dy] = steps[event.key];
      window.gent.resizeTrayBy(dx * horizontal, dy * vertical).catch(resizeError);
    });
  }
  window.gentUI.setupDashboardFullscreen();
  window.addEventListener("keydown", event => {
    if (event.key === "Escape" && !event.defaultPrevented && !event.repeat) {
      event.preventDefault();
      dismiss();
    }
  });
  window.addEventListener("gent-message", ({detail: m}) => {
    if (m?.dashboard_visibility_changed) {
      snapshot = null;
      dashboards.refresh();
      return;
    }
    if (m?.page === "tray_dashboard") {
      if (shown) dashboards.receive(m);
      // Native sends the opening snapshot before visibility. Never mount a
      // board document (or run its scripts) while the panel is hidden.
      else if (Array.isArray(m.rows) || m.read_failed) {
        snapshot = m;
        if (m.request_id) {
          close.focus({preventScroll: true});
          window.gent.showPreparedTray(m.request_id).catch(() => notice("bridge-error", "Could not open the dashboard panel.", true));
        }
      }
    }
    if (m?.visible === false) {
      closing = false;
      visible(false);
    } else if (m?.visible === true && !shown && !closing) visible(true);
  });
  if (window.gent) {
    window.gent.ready().catch(() => notice("bridge-error", "Could not connect to Gent Desktop.", true));
  } else {
    close.disabled = desktop.disabled = true;
    notice("bridge-error", "Open this panel from Gent Desktop.", true);
  }
})();