diff --git a/CLAUDE.md b/CLAUDE.md index 4bab870e..a72ae1ad 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -124,6 +124,7 @@ would double-load every global. | `worktrees.py` / `worktree_spawn.py` / `repo_locks.py` / `gitutil.py` | Worktree cache + affiliation / spawn + two-window layout / per-repo git lock + per-dir open lock / shared git helpers | | `pids.py` | `@periscope_id` mint / stamp / rebind / resolve — pane identity | | `session_status.py` | Authoritative Claude-session state from `/sessions/.json` | +| `resources.py` | Memory footprint + CPU per owner (each pane, server, webview, elsewhere) through libproc on the tick's process snapshot; `measure()` feeds `/api/state` | | `turns.py` | Pane transcript view (`GET /api/pane/turns`) | | `bg_commander.py` | Background command jobs + status sync | | `poke.py` | Daily session poke: one Haiku message per account at 08:00 so the 5h window resets ~13:00; verified, logged, prod-only | @@ -143,7 +144,7 @@ commit `static/dist/` whenever `static/src/` changes** — boot has no build ste | Area | Modules | |---|---| | entry / state | `main.jsx`, `store.js` (transient signals), `prefs.js` (server-prefs cache — the persistence boundary), `poll.js` (the single `/api/state` loop) | -| chrome | `chrome/{Header,FilterBar,UsagePill}.jsx` | +| chrome | `chrome/{Header,FilterBar,UsagePill,ResourcePill}.jsx` (`chrome/resources.js`: the resource pill's pure formatting) | | split view | `split/{Split,Rail,RailRows,Detail,…}.jsx` + `split/railTree.js` — the only view. Rail is TRACK-anchored: Track → (derived Branch) → Pane; branch rows are derived from live `w.branch`, not entities | | review | `review/{Walkthrough,ReviewsQueue}.jsx` + `walkthrough.js` (the PR walkthrough view, the cross-track reviews queue, their pure helpers) | | terminal | `terminal/{Terminal,TerminalSearch}.jsx` + `terminalCore.js` (imperative xterm + `/ws/pane`) | diff --git a/docs/superpowers/plans/2026-10-30-resource-monitor.md b/docs/superpowers/plans/2026-10-30-resource-monitor.md new file mode 100644 index 00000000..4f4ec0bc --- /dev/null +++ b/docs/superpowers/plans/2026-10-30-resource-monitor.md @@ -0,0 +1,1549 @@ +# Resource Monitor Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Show memory footprint and CPU for each pane, the periscope server, its webview and everything else, in a header pill, its popover and the detail header (THI-448). + +**Architecture:** A new stdlib-only `periscope/resources.py` reads every process's `proc_pid_rusage` through `ctypes` once per `build_state` tick, on the process snapshot the tick already takes (`agent_processes.process_snapshot()`), assigns each process to one group, and turns CPU-time deltas into per-core percentages. `build_state` puts a `res` on each window row and a `resources` block on the blob; the frontend renders them. The ↻ cycle hint switches from `ps` RSS to footprint. + +**Tech Stack:** Python 3.13 stdlib (`ctypes` on `/usr/lib/libproc.dylib` and `/usr/lib/libSystem.dylib`), FastAPI, pytest; Preact + `@preact/signals`, vitest, Vite. + +**Spec:** `docs/superpowers/specs/2026-10-30-resource-monitor-design.md` — read it first. + +**Worktree:** `/Users/thibaultdody/dev/worktrees/periscope/thi-448-resource-monitor`, branch `thibaultdody/thi-448-show-memory-footprint-and-cpu-for-periscope-its-webview-and`. Run every command from there. + +**Before touching tests:** read `docs/testing.md` (no leaked threads; `.venv` drift → `uv sync`). + +**Commits:** one per task step marked Commit; single-line messages in the repo's `area: what (THI-448)` style, ending with the line `Co-Authored-By: Claude Opus 5.5 (1M context) ` after a blank line. + +--- + +## File structure + +| File | Change | Responsibility | +|---|---|---| +| `periscope/resources.py` | create | rusage/sysctl bindings, group assignment, CPU accounting, `measure()` | +| `periscope/agent_processes.py` | modify | `_descendants` → `descendants` (resources reuses it) | +| `periscope/routes/state.py` | modify | call `resources.measure`, add `res` / `resources` | +| `periscope/session_status.py` | modify | `_claude_procs` drops `rss=`; `claude_proc_for` returns `mem_mb` | +| `periscope/config.py` | modify | `MEM_*_RSS_KB` → `MEM_*_MB` | +| `periscope/window_view.py` | modify | `mem_signal` on footprint, sends `trigger` / `gb` | +| `tests/conftest.py` | modify | autouse `_no_live_resources` stub | +| `tests/test_resources.py` | create | resources unit tests + one real-machine smoke test | +| `tests/test_session_status.py`, `tests/test_window_view.py`, `tests/routes/test_state.py` | modify | updated / new cases | +| `static/src/chrome/resources.js` | create | pure formatting and ordering | +| `static/src/chrome/ResourcePill.jsx` | create | header pill + popover | +| `static/src/chrome/Header.jsx`, `static/src/store.js`, `static/src/poll.js` | modify | wire the `resources` signal and the pill | +| `static/src/split/Detail.jsx` | modify | `· 6.8G mem · 58% cpu` part | +| `static/src/util.js` | modify | `memHint` reads `gb` / `trigger` | +| `static/styles.css` | modify | pill + popover styles | +| `static/src/chrome/__tests__/resources.test.js`, `.../resourcePillRender.test.jsx`, `static/src/__tests__/paneHeaderRes.test.js`, `static/src/__tests__/memHint.test.js`, `static/src/__tests__/agent.test.js` | create/modify | vitest | +| `CLAUDE.md` | modify | module table row for `resources.py` | + +--- + +### Task 1: rusage and sysctl bindings + +**Files:** +- Create: `periscope/resources.py` +- Create: `tests/test_resources.py` +- Modify: `tests/conftest.py` + +- [ ] **Step 1: Write the failing smoke test** + +Create `tests/test_resources.py`: + +```python +"""resources: footprint and CPU per owner. Everything except the smoke tests +runs on fake snapshots and fake rusage readings.""" + +import os + +import pytest + +from periscope import resources + + +# ── the real system calls ──────────────────────────────────────────────── + + +def test_read_measures_this_process(): + r = resources._read(os.getpid()) + assert r.footprint > 0 + assert r.cpu_ns > 0 + assert 0 < r.start <= resources._now() + + +def test_read_gone_pid_is_none(): + assert resources._read(99_999_999) is None + + +def test_footprint_mb_of_this_process(): + assert resources.footprint_mb(os.getpid()) > 0 + + +def test_machine_reads_the_kernel(): + m = resources.machine() + assert set(m) == {"load1", "swap_used_mb", "swap_total_mb", "mem_free_pct"} + assert 0 <= m["swap_used_mb"] <= m["swap_total_mb"] + assert 0 <= m["mem_free_pct"] <= 100 + + +def test_responsible_pid_of_this_process_is_a_pid(): + assert resources._responsible(os.getpid()) > 0 +``` + +- [ ] **Step 2: Run it to verify it fails** + +Run: `uv run pytest tests/test_resources.py -q` +Expected: FAIL — `ImportError: cannot import name 'resources'`. + +- [ ] **Step 3: Write the bindings** + +Create `periscope/resources.py`: + +```python +"""Memory footprint and CPU per owner: each pane, the periscope server, its +webview, and everything else on the machine. + +Footprint (`phys_footprint`, Activity Monitor's Memory), not RSS: RSS leaves +out compressed and swapped pages, which is where a machine deep in swap keeps +most of its memory — the webview read 276 MB resident against 2.8 GB of +footprint. Read through libproc/libSystem with ctypes: ~3 µs a process, no +subprocess. +""" + +from __future__ import annotations + +import ctypes +import os +from dataclasses import dataclass + +_u64 = ctypes.c_uint64 +_RUSAGE_INFO_V1 = 1 + + +class _RusageInfoV1(ctypes.Structure): + # rusage_info_v1: the v0 fields recycle.rs binds, plus + # the CPU time of reaped children (144 bytes). + _fields_ = [("uuid", ctypes.c_uint8 * 16)] + [ + (name, _u64) + for name in ( + "user_time", + "system_time", + "pkg_idle_wkups", + "interrupt_wkups", + "pageins", + "wired_size", + "resident_size", + "phys_footprint", + "proc_start_abstime", + "proc_exit_abstime", + "child_user_time", + "child_system_time", + "child_pkg_idle_wkups", + "child_interrupt_wkups", + "child_pageins", + "child_elapsed_abstime", + ) + ] + + +class _Timebase(ctypes.Structure): + _fields_ = [("numer", ctypes.c_uint32), ("denom", ctypes.c_uint32)] + + +class _SwapUsage(ctypes.Structure): + # struct xsw_usage + _fields_ = [ + ("total", _u64), + ("avail", _u64), + ("used", _u64), + ("pagesize", ctypes.c_uint32), + ("encrypted", ctypes.c_int32), + ] + + +_libproc = ctypes.CDLL("/usr/lib/libproc.dylib") +_libproc.proc_pid_rusage.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_void_p] +_libsystem = ctypes.CDLL("/usr/lib/libSystem.dylib") +_libsystem.responsibility_get_pid_responsible_for_pid.argtypes = [ctypes.c_int] +_libsystem.responsibility_get_pid_responsible_for_pid.restype = ctypes.c_int +_libsystem.mach_absolute_time.restype = _u64 +_timebase = _Timebase() +_libsystem.mach_timebase_info(ctypes.byref(_timebase)) +# rusage times are mach absolute units: 125/3 ns each on Apple silicon. +_NS_PER_TICK = _timebase.numer / _timebase.denom + + +@dataclass(frozen=True) +class Reading: + footprint: int # bytes + cpu_ns: int # own CPU time plus its reaped children's + start: int # ns on _now()'s clock; (pid, start) is a process's identity + + +def _read(pid: int) -> Reading | None: + """One process's rusage, or None when it is gone or not the user's + (root-owned processes refuse).""" + info = _RusageInfoV1() + if _libproc.proc_pid_rusage(pid, _RUSAGE_INFO_V1, ctypes.byref(info)) != 0: + return None + ticks = info.user_time + info.system_time + info.child_user_time + info.child_system_time + return Reading(info.phys_footprint, int(ticks * _NS_PER_TICK), int(info.proc_start_abstime * _NS_PER_TICK)) + + +def _responsible(pid: int) -> int: + """The pid macOS holds responsible for `pid`: for a WebKit helper, the app + hosting the webview. A private libSystem call, like the shell's + `_webProcessIdentifier`.""" + return _libsystem.responsibility_get_pid_responsible_for_pid(pid) + + +def _now() -> int: + """ns on the clock `proc_start_abstime` counts on.""" + return int(_libsystem.mach_absolute_time() * _NS_PER_TICK) + + +def footprint_mb(pid: int) -> int | None: + reading = _read(pid) + return None if reading is None else reading.footprint >> 20 + + +def _sysctl(name: str, buf: ctypes.Structure | ctypes.c_int) -> None: + size = ctypes.c_size_t(ctypes.sizeof(buf)) + _libsystem.sysctlbyname(name.encode(), ctypes.byref(buf), ctypes.byref(size), None, ctypes.c_size_t(0)) + + +def machine() -> dict: + """Load, swap and free memory, straight from the kernel. mem_free_pct is the + figure `memory_pressure` prints.""" + swap = _SwapUsage() + level = ctypes.c_int() + _sysctl("vm.swapusage", swap) + _sysctl("kern.memorystatus_level", level) + return { + "load1": round(os.getloadavg()[0], 1), + "swap_used_mb": swap.used >> 20, + "swap_total_mb": swap.total >> 20, + "mem_free_pct": level.value, + } +``` + +- [ ] **Step 4: Run the tests to verify they pass** + +Run: `uv run pytest tests/test_resources.py -q` +Expected: 5 passed. + +- [ ] **Step 5: Commit** + +```bash +git add periscope/resources.py tests/test_resources.py +git commit -m "resources: footprint, CPU time and machine figures through libproc/sysctl, no subprocess (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 2: assign every process to one group + +**Files:** +- Modify: `periscope/agent_processes.py:96,146` +- Modify: `periscope/resources.py` +- Test: `tests/test_resources.py` + +- [ ] **Step 1: Make the subtree walk public** + +In `periscope/agent_processes.py`, rename `_descendants` to `descendants` (definition at line 96 and the call at line 146). Add a one-line docstring to it: + +```python +def descendants(root_pid: int, snapshot: dict[int, ProcessInfo]): + """`root_pid`'s process (when in the snapshot) and every process below it.""" +``` + +Run: `uv run pytest tests/test_agent_processes.py -q` — Expected: PASS. + +- [ ] **Step 2: Write the failing tests** + +Append to `tests/test_resources.py`: + +```python +# ── group assignment ───────────────────────────────────────────────────── + +from periscope.agent_processes import ProcessInfo + +SERVER = os.getpid() + + +def _proc(pid, ppid, comm="/bin/zsh"): + return ProcessInfo(pid=pid, ppid=ppid, started_at=0, comm=comm, argv=comm, state="S") + + +def _snapshot(): + return { + p.pid: p + for p in ( + _proc(1, 0, "/sbin/launchd"), + _proc(SERVER, 1, "/usr/bin/python3"), + _proc(900, SERVER, "/opt/homebrew/bin/tmux"), # control-mode client + _proc(500, 1, "/Applications/Periscope.app/Contents/MacOS/periscope-app"), + _proc(600, 1, "/System/Library/.../com.apple.WebKit.WebContent"), + _proc(100, 1, "/bin/zsh"), # pane %1's root + _proc(101, 100, "/opt/homebrew/bin/claude"), + _proc(102, 101, "/usr/local/bin/node"), # a tool child + _proc(200, 1, "/bin/zsh"), # pane %2's root + _proc(700, 1, "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"), + ) + } + + +def test_assign_puts_every_process_in_one_group(monkeypatch): + monkeypatch.setattr(resources, "_responsible", {600: 500}.get) + named, per_pane = resources._assign(_snapshot(), {"%1": 100, "%2": 200}) + assert named["server"] == {SERVER, 900} + assert named["webview"] == {500, 600} # the WebContent by responsible pid, not by parent + assert per_pane == {"%1": {100, 101, 102}, "%2": {200}} + assert named["panes"] == {100, 101, 102, 200} + assert named["elsewhere"] == {1, 700} + + +def test_assign_without_the_app_has_no_webview(monkeypatch): + monkeypatch.setattr(resources, "_responsible", lambda pid: pid) + snap = {pid: p for pid, p in _snapshot().items() if pid != 500} + named, _ = resources._assign(snap, {"%1": 100}) + assert "webview" not in named + assert 600 in named["elsewhere"] +``` + +- [ ] **Step 3: Run them to verify they fail** + +Run: `uv run pytest tests/test_resources.py -k assign -q` +Expected: FAIL — `AttributeError: module 'periscope.resources' has no attribute '_assign'`. + +- [ ] **Step 4: Implement `_assign`** + +In `periscope/resources.py`, add `from periscope.agent_processes import ProcessInfo, descendants` to the imports (`agent_processes` is stdlib-only too), the constant below `_RUSAGE_INFO_V1`, and the function after `machine()`: + +```python +# The Tauri shell's executable (src-tauri). Its WebKit helpers have launchd as +# their parent, so they're found by responsible pid instead. +_APP_NAME = "periscope-app" +``` + +```python +def _assign( + snapshot: dict[int, ProcessInfo], panes: dict[str, int] +) -> tuple[dict[str, set[int]], dict[str, set[int]]]: + """Every process in exactly one group: ({"server", "webview"?, "panes", + "elsewhere"} → pids, pane_id → pids). Claimed in that order, so a process + is never counted twice.""" + claimed: set[int] = set() + + def claim(pids: set[int]) -> set[int]: + fresh = pids - claimed + claimed.update(fresh) + return fresh + + def subtree(root: int) -> set[int]: + return {p.pid for p in descendants(root, snapshot)} + + named = {"server": claim(subtree(os.getpid()))} + apps = {p.pid for p in snapshot.values() if os.path.basename(p.comm) == _APP_NAME} + if apps: + named["webview"] = claim(apps | {pid for pid in snapshot if _responsible(pid) in apps}) + per_pane = {pane_id: claim(subtree(root)) for pane_id, root in panes.items()} + named["panes"] = set().union(*per_pane.values()) + named["elsewhere"] = set(snapshot) - claimed + return named, per_pane +``` + +- [ ] **Step 5: Run the tests to verify they pass** + +Run: `uv run pytest tests/test_resources.py tests/test_agent_processes.py -q` +Expected: PASS. + +- [ ] **Step 6: Commit** + +```bash +git add periscope/agent_processes.py periscope/resources.py tests/test_resources.py +git commit -m "resources: every process lands in one group — server, webview by responsible pid, each pane's subtree, elsewhere (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 3: a group's CPU over the interval + +**Files:** +- Modify: `periscope/resources.py` +- Test: `tests/test_resources.py` + +- [ ] **Step 1: Write the failing tests** + +Append to `tests/test_resources.py`: + +```python +# ── CPU accounting (spec D4, D5) ───────────────────────────────────────── + +S = 1_000_000_000 # one second in ns + + +def _cpu(prev_at, prev, at, cur): + return resources._cpu_pct(resources._Sample(prev_at, prev), resources._Sample(at, cur)) + + +def test_cpu_is_unknown_without_a_previous_sample(): + assert resources._cpu_pct(None, resources._Sample(S, {(1, 0): S})) is None + + +def test_cpu_steady_process(): + assert _cpu(0, {(1, 0): S}, S, {(1, 0): S + S // 2}) == 50.0 + + +def test_cpu_counts_a_process_started_since_the_previous_sample(): + assert _cpu(S, {}, 2 * S, {(2, S + S // 2): S // 5}) == 20.0 + + +def test_cpu_ignores_an_old_process_new_to_the_group(): + # Started before the previous sample: its total isn't this interval's. + assert _cpu(S, {}, 2 * S, {(2, S // 2): 7 * S}) == 0.0 + + +def test_cpu_counts_a_reaped_child_once(): + # Child 2 had 0.3 s; it ran 0.1 s more and exited, and parent 1 reaped it: + # the parent's total gains the child's final 0.4 s plus 0.1 s of its own. + prev = {(1, 0): S, (2, 0): 3 * S // 10} + cur = {(1, 0): S + 4 * S // 10 + S // 10} + assert _cpu(0, prev, S, cur) == 20.0 + + +def test_cpu_clamps_a_child_reaped_outside_the_group(): + assert _cpu(0, {(1, 0): S, (2, 0): 5 * S}, S, {(1, 0): S + S // 10}) == 0.0 + + +def test_cpu_never_diffs_a_reused_pid_against_its_predecessor(): + # pid 1 exited (5 s, reaped by member 9) and a new pid 1 started since. + prev = {(1, 0): 5 * S, (9, 0): S} + cur = {(9, 0): 6 * S, (1, S + S // 2): S // 10} + assert _cpu(S, prev, 2 * S, cur) == 10.0 + + +def test_cpu_treats_a_stale_previous_sample_as_missing(): + assert _cpu(0, {(1, 0): S}, 11 * S, {(1, 0): 2 * S}) is None +``` + +- [ ] **Step 2: Run them to verify they fail** + +Run: `uv run pytest tests/test_resources.py -k cpu -q` +Expected: FAIL — no attribute `_Sample`. + +- [ ] **Step 3: Implement `_Sample` and `_cpu_pct`** + +In `periscope/resources.py`, add below `_APP_NAME`: + +```python +# A previous sample older than this (a hub that idled with no subscribers) +# would average hours into one number; it counts as missing. +_STALE_NS = 10 * 1_000_000_000 +``` + +and after `_assign`: + +```python +@dataclass(frozen=True) +class _Sample: + at: int # ns, _now()'s clock + totals: dict[tuple[int, int], int] # (pid, start) → cpu_ns, the group's members + + +def _cpu_pct(prev: _Sample | None, cur: _Sample) -> float | None: + """The group's CPU per core since `prev` (100 = one core), or None with no + usable previous sample. + + A member that vanished was reaped, and its whole CPU time reappears in its + parent's children time, so its last total comes off. A member reaped + outside the group never comes back, hence the clamp at 0.""" + if prev is None or cur.at - prev.at > _STALE_NS: + return None + delta = 0 + for ident, total in cur.totals.items(): + if ident in prev.totals: + delta += total - prev.totals[ident] + elif ident[1] > prev.at: # started since the previous sample + delta += total + for ident, total in prev.totals.items(): + if ident not in cur.totals: + delta -= total + return round(max(delta, 0) / (cur.at - prev.at) * 100, 1) +``` + +- [ ] **Step 4: Run the tests to verify they pass** + +Run: `uv run pytest tests/test_resources.py -q` +Expected: PASS. + +- [ ] **Step 5: Commit** + +```bash +git add periscope/resources.py tests/test_resources.py +git commit -m "resources: a group's CPU counts children reaped within it and never diffs a reused pid (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 4: `measure()` — one pass, under a lock, at most every 0.5 s + +**Files:** +- Modify: `periscope/resources.py` +- Test: `tests/test_resources.py` + +- [ ] **Step 1: Write the failing tests** + +Append to `tests/test_resources.py`: + +```python +# ── measure ────────────────────────────────────────────────────────────── + +import threading + + +@pytest.fixture(autouse=True) +def _no_live_resources(monkeypatch): + """Overrides conftest's stub of the same name: these tests install their + own fakes, and the smoke tests read the real test process.""" + monkeypatch.setattr(resources, "_prev", {}) + monkeypatch.setattr(resources, "_last", None) + +MACHINE = {"load1": 1.0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 50} +MB = 1 << 20 + + +class _Clock: + def __init__(self): + self.t = 10 * S + + def __call__(self): + return self.t + + +@pytest.fixture +def fake(monkeypatch): + """A machine of _snapshot()'s processes, each 100 MB, CPU set per test.""" + clock = _Clock() + cpu = {pid: 0 for pid in _snapshot()} + monkeypatch.setattr(resources, "process_snapshot", _snapshot) + monkeypatch.setattr(resources, "_responsible", {600: 500}.get) + monkeypatch.setattr(resources, "machine", lambda: MACHINE) + monkeypatch.setattr(resources, "_now", clock) + monkeypatch.setattr(resources, "_read", lambda pid: resources.Reading(100 * MB, cpu[pid], 0) if pid in cpu else None) + return clock, cpu + + +PANES = {"%1": 100, "%2": 200} + + +def test_measure_first_pass_has_memory_and_unknown_cpu(fake): + m = resources.measure(PANES) + assert m.panes == {"%1": {"mem_mb": 300, "cpu_pct": None}, "%2": {"mem_mb": 100, "cpu_pct": None}} + assert m.totals["server"] == {"mem_mb": 200, "cpu_pct": None} + assert m.totals["webview"] == {"mem_mb": 200, "cpu_pct": None} + assert m.totals["panes"] == {"mem_mb": 400, "cpu_pct": None} + assert m.totals["elsewhere"] == {"mem_mb": 200, "cpu_pct": None} + assert m.totals["machine"] == MACHINE + + +def test_measure_second_pass_has_cpu(fake): + clock, cpu = fake + resources.measure(PANES) + clock.t += S + cpu[102] += S // 2 # the pane's tool child: half a core + m = resources.measure(PANES) + assert m.panes["%1"]["cpu_pct"] == 50.0 + assert m.panes["%2"]["cpu_pct"] == 0.0 + assert m.totals["panes"]["cpu_pct"] == 50.0 + assert m.totals["server"]["cpu_pct"] == 0.0 + + +def test_measure_within_half_a_second_returns_the_previous_measurement(fake): + clock, _ = fake + first = resources.measure(PANES) + clock.t += S // 10 + assert resources.measure(PANES) is first + + +def test_measure_skips_unreadable_processes(fake, monkeypatch): + monkeypatch.setattr(resources, "_read", lambda pid: None if pid == 102 else resources.Reading(100 * MB, 0, 0)) + assert resources.measure(PANES).panes["%1"]["mem_mb"] == 200 + + +def test_measure_without_the_app_sends_no_webview(fake, monkeypatch): + monkeypatch.setattr(resources, "process_snapshot", lambda: {p: v for p, v in _snapshot().items() if p != 500}) + assert resources.measure(PANES).totals["webview"] is None + + +def test_measure_is_none_when_the_snapshot_failed(fake, monkeypatch): + monkeypatch.setattr(resources, "process_snapshot", lambda: None) + assert resources.measure(PANES) is None + + +def test_measure_from_many_threads_at_once(fake): + out = [] + threads = [threading.Thread(target=lambda: out.append(resources.measure(PANES))) for _ in range(8)] + for t in threads: + t.start() + for t in threads: + t.join() + assert len(out) == 8 + assert all(m is out[0] for m in out) # one computed, the rest inside 0.5 s +``` + +- [ ] **Step 2: Run them to verify they fail** + +Run: `uv run pytest tests/test_resources.py -k measure -q` +Expected: FAIL — no attribute `measure` / `process_snapshot`. + +- [ ] **Step 3: Implement `measure`** + +In `periscope/resources.py`: +- add `import threading` to the imports and change the agent_processes import to `from periscope.agent_processes import ProcessInfo, descendants, process_snapshot`; +- add below `_STALE_NS`: + +```python +# A delta over less than this reads noise (5 ms windows measured 0% for a +# server averaging 10%); a caller inside it gets the previous measurement. +_MIN_INTERVAL_NS = 500_000_000 +``` + +- append at the end of the module: + +```python +@dataclass(frozen=True) +class Measurement: + panes: dict[str, dict] # pane_id → {mem_mb, cpu_pct} + totals: dict # server, webview (None without the app), panes, elsewhere: {mem_mb, cpu_pct}; machine + + +# build_state runs from the state hub, the REST fallback poll and other tabs at +# once; the lock makes each read-diff-write of _prev whole. +_lock = threading.Lock() +_prev: dict[str, _Sample] = {} # group key → its last sample +_last: tuple[int, Measurement] | None = None + + +def measure(panes: dict[str, int]) -> Measurement | None: + """Footprint and CPU for each pane (pane_id → its root pid, tmux's + pane_pid) and every other group. None when this tick's process snapshot + failed: an empty tree would collapse every pane to its shell and read as + real.""" + global _prev, _last + snapshot = process_snapshot() + if snapshot is None: + return None + with _lock: + now = _now() + if _last is not None and now - _last[0] < _MIN_INTERVAL_NS: + return _last[1] + named, per_pane = _assign(snapshot, panes) + readings = {pid: r for pid in snapshot if (r := _read(pid)) is not None} + prev, _prev = _prev, {} + + def group(key: str, pids: set[int]) -> dict: + members = {(pid, readings[pid].start): readings[pid] for pid in pids if pid in readings} + cur = _Sample(now, {ident: r.cpu_ns for ident, r in members.items()}) + _prev[key] = cur + return { + "mem_mb": sum(r.footprint for r in members.values()) >> 20, + "cpu_pct": _cpu_pct(prev.get(key), cur), + } + + totals: dict = {"webview": None} | {key: group(key, pids) for key, pids in named.items()} + totals["machine"] = machine() + measurement = Measurement({pane_id: group(f"pane:{pane_id}", pids) for pane_id, pids in per_pane.items()}, totals) + _last = (now, measurement) + return measurement +``` + +- [ ] **Step 4: Run the tests to verify they pass** + +Run: `uv run pytest tests/test_resources.py -q` +Expected: PASS (all of Tasks 1–4). The module-level `_no_live_resources` fixture added above resets `_prev` / `_last` per test, and in Task 5 it overrides conftest's stub of the same name. + +- [ ] **Step 5: Commit** + +```bash +git add periscope/resources.py tests/test_resources.py +git commit -m "resources: measure() reads every process once per tick under a lock, at most every 0.5 s (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 5: keep every other test off the real machine + +**Files:** +- Modify: `tests/conftest.py` (after `_no_live_session_scan`, ~line 83) + +- [ ] **Step 1: Add the autouse stub** + +```python +@pytest.fixture(autouse=True) +def _no_live_resources(monkeypatch): + """Keep resources.measure off the real machine: no `ps` snapshot, no + rusage reads, no sysctl. Every /api/state build calls it, so without this + any route test would read the developer's real processes. + tests/test_resources.py overrides this fixture by name and installs its + own fakes.""" + from periscope import resources + + monkeypatch.setattr(resources, "process_snapshot", dict) + monkeypatch.setattr(resources, "_read", lambda pid: None) + monkeypatch.setattr(resources, "_responsible", lambda pid: 0) + monkeypatch.setattr( + resources, "machine", lambda: {"load1": 0.0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 100} + ) + monkeypatch.setattr(resources, "_prev", {}) + monkeypatch.setattr(resources, "_last", None) +``` + +- [ ] **Step 2: Run the whole Python suite** + +Run: `uv run pytest -q` +Expected: PASS (nothing calls `measure` yet; this proves the fixture itself is sound). + +- [ ] **Step 3: Commit** + +```bash +git add tests/conftest.py +git commit -m "tests: an autouse stub keeps resources off the real machine (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 6: `/api/state` carries `res` and `resources` + +**Files:** +- Modify: `periscope/routes/state.py` +- Test: `tests/routes/test_state.py` + +- [ ] **Step 1: Write the failing tests** + +Append to `tests/routes/test_state.py`: + +```python +def _patch_one_window(mocker): + fake_windows = [ + {"session": "main", "index": 0, "name": "x", "active": True, "cwd": "/tmp", + "pid_raw": "", "pane_id": "%7", "pane_pid": "4242", "pid": "abc123"}, + ] + _patch(mocker, "list_windows", return_value=fake_windows) + _patch(mocker, "update_focus_from_windows") + _patch(mocker, "_attach_git_then_resolve_pids") + _patch(mocker, "capture", return_value="$ ls\n") + _patch(mocker, "parse_pane", return_value={"agent": None, "spinner": None, "state": "shell"}) + _patch(mocker, "cached_git_state", return_value={"branch": "main"}) + _patch(mocker, "cached_pr_state", return_value={"pr": None}) + _patch(mocker, "cached_claude_usage", return_value={}) + _patch(mocker, "cached_plan_usage", return_value={}) + _patch(mocker, "all_pane_ids", return_value={"%7"}) + _patch(mocker, "_channel_gc") + + +def test_state_carries_each_panes_resources_and_the_totals(client, mocker, clean_state): + from periscope import resources + + _patch_one_window(mocker) + group = {"mem_mb": 512, "cpu_pct": 12.5} + totals = {"server": group, "webview": None, "panes": group, "elsewhere": group, "machine": {"load1": 1.0}} + measure = mocker.patch.object( + resources, "measure", return_value=resources.Measurement({"%7": group}, totals) + ) + + body = client.get("/api/state").json() + measure.assert_called_once_with({"%7": 4242}) + assert body["windows"][0]["res"] == group + assert body["resources"] == totals + + +def test_state_sends_no_resources_when_the_snapshot_failed(client, mocker, clean_state): + from periscope import resources + + _patch_one_window(mocker) + mocker.patch.object(resources, "measure", return_value=None) + + body = client.get("/api/state").json() + assert body["windows"][0]["res"] is None + assert body["resources"] is None +``` + +- [ ] **Step 2: Run them to verify they fail** + +Run: `uv run pytest tests/routes/test_state.py -k resources -q` +Expected: FAIL — `KeyError: 'res'`. + +- [ ] **Step 3: Wire `measure` into `build_state`** + +In `periscope/routes/state.py`, change the import line `from periscope import store, updater, usage` to `from periscope import resources, store, updater, usage`. After `annotate_cost_pressure(result)` insert: + +```python + # Memory and CPU per owner, on this tick's process snapshot. Each row's + # pane_pid roots its pane's group; None when the snapshot failed. + measured = resources.measure({v["pane_id"]: int(v["pane_pid"]) for v in result if v.get("pane_pid")}) + for view in result: + view["res"] = measured.panes.get(view["pane_id"]) if measured else None +``` + +and in the returned dict, after `"editor": …`, add: + +```python + # server / webview / panes / elsewhere / machine (resources.measure); + # the header pill and its popover. + "resources": measured.totals if measured else None, +``` + +- [ ] **Step 4: Run the state tests** + +Run: `uv run pytest tests/routes/test_state.py -q` +Expected: PASS. If an existing test's fake window has no `pane_id`, `view["pane_id"]` raises — every row from `list_windows` has one (`panes.py:427`), so give that fake one rather than loosening the code. + +- [ ] **Step 5: Commit** + +```bash +git add periscope/routes/state.py tests/routes/test_state.py +git commit -m "state: each row carries its pane's res and the blob the resources totals (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 7: the ↻ cycle hint on footprint + +**Files:** +- Modify: `periscope/config.py:155-161` +- Modify: `periscope/session_status.py:54-56,151-185,511-528` +- Modify: `periscope/window_view.py:27,224-239` +- Test: `tests/test_session_status.py:124-196`, `tests/test_window_view.py:803-832` + +- [ ] **Step 1: Update the tests first** + +In `tests/test_session_status.py`, replace `_PS_SAMPLE` and `test_claude_procs_carry_rss_and_age`: + +```python +_PS_SAMPLE = ( + " 9448 01-02:08:58 /Users/tom/.local/bin/claude\n" + " 9876 22:09:53 /Users/tom/.local/share/claude/versions/2.1.161\n" + " 329 05:33 /usr/libexec/logd\n" + " 1 91-10:00:00 /sbin/launchd\n" +) +``` + +```python +def test_claude_procs_carry_age(monkeypatch): + class _R: + stdout = _PS_SAMPLE + + monkeypatch.setattr(ss, "_claude_procs_cache", None) + monkeypatch.setattr(ss.subprocess, "run", lambda *a, **k: _R()) + assert ss._claude_procs() == { + 9448: 26 * 3600 + 8 * 60 + 58, + 9876: 22 * 3600 + 9 * 60 + 53, + } +``` + +and the `claude_proc_for` cases: + +```python +def test_claude_proc_for_returns_stats(tmp_path, monkeypatch): + # status "shell" is untrusted for STATE, but measurement still applies — + # a bloated claude deserves the hint regardless of what it's doing. + _seed_procs(tmp_path, monkeypatch, _sess(300, "sid-m", "shell"), {300: 4 * 86400}) + monkeypatch.setattr(ss.resources, "footprint_mb", {300: 4400}.get) + assert ss.claude_proc_for("sid-m") == {"pid": 300, "mem_mb": 4400, "age_s": 4 * 86400} +``` + +In `test_claude_proc_for_unmapped_none`, change `{302: (1, 1)}` to `{302: 1}`. + +In `tests/test_window_view.py`, replace the four `mem_signal` tests (lines 803–832): + +```python +def test_mem_signal_none_when_healthy(): + from periscope.window_view import mem_signal + + assert mem_signal(None) is None + assert mem_signal({"pid": 1, "mem_mb": 600, "age_s": 3600}) is None + + +def test_mem_signal_warn_on_footprint(): + from periscope.window_view import mem_signal + + out = mem_signal({"pid": 1, "mem_mb": 2048, "age_s": 60}) + assert out == {"tier": "warn", "trigger": "mem", "gb": 2.0, "age_s": 60} + + +def test_mem_signal_warn_on_age_alone(): + from periscope.window_view import mem_signal + + out = mem_signal({"pid": 1, "mem_mb": 500, "age_s": 3 * 86400}) + assert out == {"tier": "warn", "trigger": "age", "gb": 0.5, "age_s": 3 * 86400} + + +def test_mem_signal_bad_overrides_warn(): + from periscope.window_view import mem_signal + + out = mem_signal({"pid": 1, "mem_mb": 4300, "age_s": 60}) + assert out["tier"] == "bad" + assert out["gb"] == 4.2 + + +def test_mem_signal_unreadable_footprint_trips_on_age_only(): + from periscope.window_view import mem_signal + + assert mem_signal({"pid": 1, "mem_mb": None, "age_s": 60}) is None + out = mem_signal({"pid": 1, "mem_mb": None, "age_s": 3 * 86400}) + assert out == {"tier": "warn", "trigger": "age", "gb": None, "age_s": 3 * 86400} +``` + +- [ ] **Step 2: Run them to verify they fail** + +Run: `uv run pytest tests/test_session_status.py tests/test_window_view.py -k "claude_proc or mem_signal" -q` +Expected: FAIL. + +- [ ] **Step 3: Implement** + +`periscope/config.py` — replace the thresholds block: + +```python +# Claude cycle-hint thresholds (rail ↻ chip): red when a pane's claude +# footprint crosses BAD, amber at WARN footprint or WARN age. Healthy claudes +# sit at 0.25–0.55GB of footprint; the leak class that motivated this shows up +# as multi-GB on multi-day processes. +MEM_BAD_MB = 4 * 1024 # 4GB +MEM_WARN_MB = 2 * 1024 # 2GB +MEM_WARN_AGE_S = 3 * 86400 # 3 days +``` + +`periscope/session_status.py`: +- add `from periscope import resources` to the imports; +- cache comment and type: `# (built_at, {pid: age_s}) — one ps snapshot serves both pid` / `# liveness (the key set) and the uptime cycle-hint.` and `_claude_procs_cache: tuple[float, dict[int, int]] | None = None`; +- `_claude_procs`: + +```python +def _claude_procs() -> dict[int, int]: + """{pid: age_s} of running `claude` processes, snapshotted once per poll. + The key set guards against honoring a session file whose process has + exited or whose pid was recycled; age feeds the cycle-hint. `comm` is the + full executable path; claude's launcher (`.../bin/claude`) and versioned + binary (`.../share/claude/versions/`) both contain "claude". comm may + itself contain spaces, hence maxsplit=2.""" + global _claude_procs_cache + now = time.time() + if _claude_procs_cache and now - _claude_procs_cache[0] < _CACHE_TTL_S: + return _claude_procs_cache[1] + procs: dict[int, int] = {} + try: + out = subprocess.run( + ["ps", "-axo", "pid=,etime=,comm="], + capture_output=True, + text=True, + timeout=5, + ).stdout + for line in out.splitlines(): + parts = line.split(None, 2) + if len(parts) != 3: + continue + pid_s, etime, comm = parts + if "claude" in comm.lower(): + with contextlib.suppress(ValueError): + procs[int(pid_s)] = parse_etime(etime) + except (OSError, subprocess.SubprocessError): + pass + _claude_procs_cache = (now, procs) + return procs +``` + +- `claude_proc_for`: + +```python +def claude_proc_for(sid: str | None) -> dict | None: + """Process stats for a sessionId's claude: {"pid", "mem_mb", "age_s"}, or + None when unmapped or not a live claude. mem_mb is its footprint, None if + it exited since the ps snapshot. Measurement, not state — applies even when + the status is one session_state_for doesn't trust (a bloated claude + deserves the cycle-hint regardless of what it's doing).""" + if not sid: + return None + d = _index().get(sid) + if not d: + return None + try: + pid = int(d.get("pid")) + except (TypeError, ValueError): + return None + age = _claude_procs().get(pid) + if age is None: + return None + return {"pid": pid, "mem_mb": resources.footprint_mb(pid), "age_s": age} +``` + +`periscope/window_view.py` — import line 27 becomes `from periscope.config import MEM_BAD_MB, MEM_WARN_AGE_S, MEM_WARN_MB`, and: + +```python +def mem_signal(proc: dict | None) -> dict | None: + """Cycle-hint for a claude process, from claude_proc_for's stats dict: + "bad" at ≥MEM_BAD_MB of footprint, "warn" at ≥MEM_WARN_MB or + ≥MEM_WARN_AGE_S, None otherwise — None renders nothing, so a healthy pane + costs no rail space. `trigger` says which limit tripped, so the chip leads + with it. Policy lives here (config thresholds); measurement stays in + session_status, which can't import config.""" + if not proc: + return None + mb, age = proc["mem_mb"], proc["age_s"] + if mb is not None and mb >= MEM_WARN_MB: + trigger = "mem" + elif age >= MEM_WARN_AGE_S: + trigger = "age" + else: + return None + tier = "bad" if mb is not None and mb >= MEM_BAD_MB else "warn" + return {"tier": tier, "trigger": trigger, "gb": None if mb is None else round(mb / 1024, 1), "age_s": age} +``` + +- [ ] **Step 4: Run the suite** + +Run: `uv run pytest -q` and `git grep -n "RSS_KB\|rss_kb\|rss_gb" periscope tests` (expect no output). +Expected: PASS, no leftover names. + +- [ ] **Step 5: Commit** + +```bash +git add periscope/config.py periscope/session_status.py periscope/window_view.py tests/test_session_status.py tests/test_window_view.py +git commit -m "cycle hint: the ↻ chip reads claude's footprint, not RSS, and says which limit tripped (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 8: frontend formatting and `memHint` + +**Files:** +- Create: `static/src/chrome/resources.js` +- Create: `static/src/chrome/__tests__/resources.test.js` +- Modify: `static/src/util.js:105-119` +- Modify: `static/src/__tests__/memHint.test.js`, `static/src/__tests__/agent.test.js:34` + +- [ ] **Step 1: Write the failing tests** + +Create `static/src/chrome/__tests__/resources.test.js`: + +```js +// resources.js — formatting and ordering behind and the +// detail header's mem/cpu part. +import { describe, expect, it } from "vitest"; +import { fmtCpu, fmtMem, machineLine, ownedMb, paneLines } from "../resources.js"; + +describe("fmtMem", () => { + it("megabytes under a gigabyte, one decimal of gigabytes above", () => { + expect(fmtMem(512)).toBe("512M"); + expect(fmtMem(1024)).toBe("1.0G"); + expect(fmtMem(6963)).toBe("6.8G"); + }); +}); + +describe("fmtCpu", () => { + it("rounds per-core percent; unknown is a dash, never 0", () => { + expect(fmtCpu(57.6)).toBe("58%"); + expect(fmtCpu(0)).toBe("0%"); + expect(fmtCpu(null)).toBe("–"); + }); +}); + +describe("ownedMb", () => { + const g = (mem_mb) => ({ mem_mb, cpu_pct: null }); + it("adds server, webview and panes — not elsewhere", () => { + expect(ownedMb({ server: g(100), webview: g(2000), panes: g(10000), elsewhere: g(9999) })).toBe(12100); + }); + it("counts no webview when there is none", () => { + expect(ownedMb({ server: g(100), webview: null, panes: g(900), elsewhere: g(1) })).toBe(1000); + }); +}); + +describe("paneLines", () => { + it("heaviest first, skipping rows without a measurement", () => { + const a = { pid: "a", res: { mem_mb: 300, cpu_pct: 1 } }; + const b = { pid: "b", res: { mem_mb: 7000, cpu_pct: 58 } }; + const c = { pid: "c", res: null }; + expect(paneLines([a, b, c]).map((l) => l.w.pid)).toEqual(["b", "a"]); + }); +}); + +describe("machineLine", () => { + it("load, swap and free memory", () => { + expect(machineLine({ load1: 52.3, swap_used_mb: 16896, swap_total_mb: 17818, mem_free_pct: 27 })) + .toBe("load 52.3 · swap 16.5G/17.4G · 27% free"); + }); +}); +``` + +Replace `static/src/__tests__/memHint.test.js`'s two tier cases: + +```js + it("a footprint trip leads with gigabytes", () => { + const h = memHint({ tier: "bad", trigger: "mem", gb: 4.2, age_s: 2 * 86400 + 5 * 3600 }); + expect(h.label).toBe("4.2G"); + expect(h.cls).toBe("mem-bad"); + expect(h.title).toContain("4.2GB"); + expect(h.title).toContain("2d 5h"); + }); + + it("an age trip leads with uptime days", () => { + const h = memHint({ tier: "warn", trigger: "age", gb: 0.5, age_s: 3 * 86400 }); + expect(h.label).toBe("3d"); + expect(h.cls).toBe("mem-warn"); + }); + + it("an age trip with an unreadable footprint still explains itself", () => { + const h = memHint({ tier: "warn", trigger: "age", gb: null, age_s: 3 * 86400 }); + expect(h.title).toContain("running 3d 0h"); + expect(h.title).not.toContain("null"); + }); +``` + +In `static/src/__tests__/agent.test.js:34`, change `mem: { rss_gb: 4, age_s: 86400 },` to `mem: { tier: "bad", trigger: "mem", gb: 4, age_s: 86400 },`. + +- [ ] **Step 2: Run them to verify they fail** + +Run: `npx vitest run static/src/chrome/__tests__/resources.test.js static/src/__tests__/memHint.test.js` +Expected: FAIL — module not found / label mismatch. + +- [ ] **Step 3: Implement** + +Create `static/src/chrome/resources.js`: + +```js +// Formatting and ordering behind and the detail header. +// /api/state's `resources` groups and each row's `res` are +// { mem_mb, cpu_pct }: memory footprint, and CPU per core (100 = one core +// busy) — null until the server has two samples to diff. + +export function fmtMem(mb) { + return mb >= 1024 ? `${(mb / 1024).toFixed(1)}G` : `${mb}M`; +} + +export function fmtCpu(pct) { + return pct == null ? "–" : `${Math.round(pct)}%`; +} + +// The pill's figure: what periscope and its panes hold. Elsewhere is the rest +// of the machine, shown in the popover, not owned here. +export function ownedMb(r) { + return r.server.mem_mb + (r.webview?.mem_mb || 0) + r.panes.mem_mb; +} + +// Popover pane lines, heaviest first. A row has no `res` when the server's +// snapshot failed that tick. +export function paneLines(windows) { + return windows + .filter((w) => w.res) + .map((w) => ({ w, ...w.res })) + .sort((a, b) => b.mem_mb - a.mem_mb); +} + +export function machineLine(m) { + return `load ${m.load1} · swap ${fmtMem(m.swap_used_mb)}/${fmtMem(m.swap_total_mb)} · ${m.mem_free_pct}% free`; +} +``` + +In `static/src/util.js`, replace the comment and body of `memHint` (lines ~105–119): + +```js +// Cycle-hint chip content (rail ↻ chip + detail header). `mem` is the +// server's `w.mem` ({tier: "warn"|"bad", trigger: "mem"|"age", gb, age_s}) +// or null/undefined — the server only sends it when a threshold tripped, so +// null → no chip. The label leads with whichever limit tripped. gb is null +// when claude's footprint couldn't be read. +export function memHint(mem) { + if (!mem) return null; + const days = Math.floor(mem.age_s / 86400); + const hours = Math.floor((mem.age_s % 86400) / 3600); + const up = days > 0 ? `${days}d ${hours}h` : `${hours}h`; + const what = mem.gb == null ? `Claude has been running ${up}` : `Claude is using ${mem.gb}GB after ${up}`; + return { + label: mem.trigger === "mem" ? `${mem.gb}G` : `${days}d`, + title: `${what} — consider exiting and resuming this session`, + cls: `mem-${mem.tier}`, + }; +} +``` + +(Keep whatever doc-comment lines above line 105 that describe the chip if they differ; the four comment lines above are the replacement for the `rss_gb` description.) + +- [ ] **Step 4: Run them to verify they pass** + +Run: `npx vitest run static/src/chrome/__tests__/resources.test.js static/src/__tests__/memHint.test.js static/src/__tests__/agent.test.js` +Expected: PASS. + +- [ ] **Step 5: Commit** + +```bash +git add static/src/chrome/resources.js static/src/chrome/__tests__/resources.test.js static/src/util.js static/src/__tests__/memHint.test.js static/src/__tests__/agent.test.js +git commit -m "ui: resources formatting, and memHint labels from the server's trigger (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 9: the header pill and popover + +**Files:** +- Modify: `static/src/store.js` (signals block, ~line 34) +- Modify: `static/src/poll.js` (store import list ending line 33; commit block ~line 66) +- Create: `static/src/chrome/ResourcePill.jsx` +- Create: `static/src/chrome/__tests__/resourcePillRender.test.jsx` +- Modify: `static/src/chrome/Header.jsx:29,138` +- Modify: `static/styles.css` (after the `.update-menu-error` rule, ~line 302) + +- [ ] **Step 1: Add the signal and feed it** + +`static/src/store.js`, after `export const updateInfo = …`: + +```js +export const resources = signal(null); // /api/state resources: { server, webview, panes, elsewhere, machine }, or null when the server's snapshot failed +``` + +`static/src/poll.js`: add `resources,` to the `from "./store.js"` import list, and after `updateInfo.value = data.update || null;`: + +```js + resources.value = data.resources || null; +``` + +- [ ] **Step 2: Write the failing render test** + +Create `static/src/chrome/__tests__/resourcePillRender.test.jsx`: + +```jsx +// Render-path test for . Same rationale/technique as +// usagePillRender.test.jsx: catches wiring errors a build alone can't. + +import render from "preact-render-to-string"; +import { afterEach, describe, expect, it } from "vitest"; +import { resources, windows } from "../../store.js"; +import { ResourcePill } from "../ResourcePill.jsx"; + +const g = (mem_mb, cpu_pct) => ({ mem_mb, cpu_pct }); +const R = { + server: g(176, 7), + webview: g(2900, 40), + panes: g(12800, 112), + elsewhere: g(30000, 300), + machine: { load1: 52.3, swap_used_mb: 16896, swap_total_mb: 17818, mem_free_pct: 27 }, +}; + +afterEach(() => { + resources.value = null; + windows.value = []; +}); + +describe("", () => { + it("renders nothing without a measurement", () => { + expect(render()).toBe(""); + }); + + it("shows what periscope and its panes hold", () => { + resources.value = R; + const html = render(); + expect(html).toContain("▣ 15.5G"); // 176 + 2900 + 12800 MB: elsewhere is not periscope's + }); + + it("lists the owners, panes heaviest first, then elsewhere and the machine", () => { + resources.value = R; + windows.value = [ + { pid: "a", name: "light", res: g(300, 1) }, + { pid: "b", name: "heavy", res: g(6963, 58) }, + ]; + const html = render(); + const order = [">periscope server<", ">webview<", ">heavy<", ">light<", ">elsewhere<", "load 52.3"]; + const at = order.map((s) => html.indexOf(s)); + expect(at.every((i) => i >= 0)).toBe(true); + expect([...at].sort((x, y) => x - y)).toEqual(at); + expect(html).toContain("6.8G"); + expect(html).toContain("58%"); + }); + + it("leaves the webview line out when there is no app", () => { + resources.value = { ...R, webview: null }; + expect(render()).not.toContain(">webview<"); + }); +}); +``` + +Run: `npx vitest run static/src/chrome/__tests__/resourcePillRender.test.jsx` +Expected: FAIL — cannot find `../ResourcePill.jsx`. + +- [ ] **Step 3: Write the component** + +Create `static/src/chrome/ResourcePill.jsx`: + +```jsx +// "▣ 15.5G" pill: memory held by the periscope server, its webview and every +// pane's process tree (resources.py). Click → each owner's memory and CPU, +// panes heaviest first, then everything else on the machine and the machine's +// load / swap / free memory. Hidden when the server sent no measurement (its +// process snapshot failed that tick). +import { signal } from "@preact/signals"; +import { useCallback, useEffect, useRef } from "preact/hooks"; +import { useEscape } from "../hooks/useEscape.js"; +import { selectPane } from "../split/alertFeed.js"; +import { resources, windows } from "../store.js"; +import { paneLabel } from "../util.js"; +import { fmtCpu, fmtMem, machineLine, ownedMb, paneLines } from "./resources.js"; + +const popoverOpen = signal(false); +const CPU_TIP = "CPU per core: 100% is one core fully busy"; + +function Line({ label, group, onClick }) { + return ( +
+ {label} + {fmtMem(group.mem_mb)} + {fmtCpu(group.cpu_pct)} +
+ ); +} + +export function ResourcePill() { + const ref = useRef(null); + const open = popoverOpen.value; + const r = resources.value; + const close = useCallback(() => { popoverOpen.value = false; }, []); + useEscape(close, open); + useEffect(() => { + if (!open) return; + function onDocClick(e) { + if (ref.current && !ref.current.contains(e.target)) close(); + } + document.addEventListener("click", onDocClick); + return () => document.removeEventListener("click", onDocClick); + }, [open]); + // The pill can vanish with the popover open (a tick with no measurement); + // close it, or Escape stays bound to an invisible popover. + useEffect(() => { + if (!r && open) close(); + }, [r, open]); + if (!r) return null; + + return ( +
+ + +
+ ); +} +``` + +- [ ] **Step 4: Run the render test** + +Run: `npx vitest run static/src/chrome/__tests__/resourcePillRender.test.jsx` +Expected: PASS. + +- [ ] **Step 5: Place it and style it** + +`static/src/chrome/Header.jsx`: add `import { ResourcePill } from "./ResourcePill.jsx";` (alphabetical, before `SpawnAccountPicker`), and render `` directly after ``. + +`static/styles.css`, after the `.update-menu-error` rule: + +```css +/* Resource pill (ResourcePill.jsx): neutral, it reports rather than calls to action. */ +.res-pill { + flex: 0 0 auto; + align-self: center; + font: inherit; + font-size: 11px; + padding: 2px 8px; + border-radius: 999px; + cursor: pointer; + color: var(--fg-2); + background: transparent; + border: 1px solid var(--line); +} +.res-pill:hover { color: var(--fg-1); } +.tb-dd-menu.res-menu { left: auto; right: 0; width: max-content; min-width: 260px; gap: 0; padding: 6px; font-size: 11px; } +.res-line { display: grid; grid-template-columns: 1fr 5ch 5ch; gap: 8px; padding: 2px 6px; border-radius: var(--r-sm); } +.res-line.is-pane { cursor: pointer; } +.res-line.is-pane:hover { background: color-mix(in oklch, var(--fg-1) 8%, transparent); } +.res-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.res-mem, .res-cpu { text-align: right; font-variant-numeric: tabular-nums; } +.res-cpu { color: var(--fg-3); cursor: help; } +.res-machine { margin-top: 6px; padding: 4px 6px 0; border-top: 1px solid var(--line); color: var(--fg-3); } +``` + +- [ ] **Step 6: Run the frontend suite** + +Run: `npm test` +Expected: PASS. + +- [ ] **Step 7: Commit** + +```bash +git add static/src/store.js static/src/poll.js static/src/chrome/ResourcePill.jsx static/src/chrome/__tests__/resourcePillRender.test.jsx static/src/chrome/Header.jsx static/styles.css +git commit -m "ui: a header pill with each owner's memory and CPU, panes heaviest first (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 10: the detail header's mem / cpu part + +**Files:** +- Modify: `static/src/split/Detail.jsx:34,258-260` +- Create: `static/src/__tests__/paneHeaderRes.test.js` + +- [ ] **Step 1: Write the failing test** + +Create `static/src/__tests__/paneHeaderRes.test.js`: + +```js +// The detail header's "6.8G mem · 58% cpu" part: the selected pane's whole +// process tree (the row's `res`). +import { h } from "preact"; +import render from "preact-render-to-string"; +import { describe, expect, it } from "vitest"; +import { PaneHeader } from "../split/Detail.jsx"; + +const base = { pid: "p1", target: "dev:1", state: "shell" }; + +describe("PaneHeader resources", () => { + it("labels memory and CPU", () => { + const html = render(h(PaneHeader, { w: { ...base, res: { mem_mb: 6963, cpu_pct: 57.6 } } })); + expect(html).toContain("6.8G mem · 58% cpu"); + }); + + it("shows a dash before the server has two samples", () => { + const html = render(h(PaneHeader, { w: { ...base, res: { mem_mb: 300, cpu_pct: null } } })); + expect(html).toContain("300M mem · – cpu"); + }); + + it("shows nothing without a measurement", () => { + expect(render(h(PaneHeader, { w: { ...base, res: null } }))).not.toContain("header-res"); + }); +}); +``` + +Run: `npx vitest run static/src/__tests__/paneHeaderRes.test.js` — Expected: FAIL. + +- [ ] **Step 2: Implement** + +In `static/src/split/Detail.jsx` add `import { fmtCpu, fmtMem } from "../chrome/resources.js";` to the imports, and after the `context_pct` block (before `if (w.agent === "claude" && w.mem)`): + +```jsx + if (w.res) { + parts.push( + <> + · + + {`${fmtMem(w.res.mem_mb)} mem · ${fmtCpu(w.res.cpu_pct)} cpu`} + + + ); + } +``` + +- [ ] **Step 3: Run the frontend suite** + +Run: `npm test` +Expected: PASS. + +- [ ] **Step 4: Commit** + +```bash +git add static/src/split/Detail.jsx static/src/__tests__/paneHeaderRes.test.js +git commit -m "ui: the detail header shows the pane's memory and CPU, labelled (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +--- + +### Task 11: build, gate, verify in the browser, docs + +**Files:** +- Modify: `static/dist/*` (build output), `CLAUDE.md`, `docs/superpowers/specs/2026-10-30-resource-monitor-design.md` + +- [ ] **Step 1: Build and commit the bundle** + +```bash +npm run build +git add static/dist +git commit -m "build: static/dist with the resource pill (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +- [ ] **Step 2: Full gate** + +Run: `bin/check && uv run pytest -q && npm test` +Expected: zero lint/type violations; all tests pass. Fix anything red in the task that introduced it, with its own commit. + +- [ ] **Step 3: Verify against the dev server** + +```bash +PERISCOPE_PORT=17375 PERISCOPE_DEV=1 uv run server.py # run in the background +sleep 5; curl -s http://127.0.0.1:17375/api/state | python3 -c "import json,sys; d=json.load(sys.stdin); print(d['resources']); print([(w['name'], w.get('res')) for w in d['windows']][:5])" +sleep 2; curl -s http://127.0.0.1:17375/api/state | python3 -c "import json,sys; print(json.load(sys.stdin)['resources']['panes'])" +``` + +Expected: `resources` has `server`, `webview` (the running `periscope-app`, or `null`), `panes`, `elsewhere`, `machine`; rows carry `res`; the second call has a numeric `cpu_pct`. Cross-check one pane's `mem_mb` against `top -l 1 -stats pid,mem` for its claude (the pane figure must be at least the claude's). Open http://127.0.0.1:17375/ in a browser: the pill shows next to the usage meters, the popover lists owners, clicking a pane line selects it, Escape closes it, and the detail header shows `… mem · … cpu`. Stop the dev server afterwards. + +- [ ] **Step 4: Docs** + +`CLAUDE.md` module table — add a row after `usage.py`'s row group (alphabetical placement is not required; put it next to `session_status.py`): + +``` +| `resources.py` | Memory footprint + CPU per owner (each pane, server, webview, elsewhere) through libproc on the tick's process snapshot; `measure()` feeds `/api/state` | +``` + +Spec — record the two places the plan differs: +- D7: `mem_signal` gets claude's footprint from `claude_proc_for` (a direct `resources.footprint_mb` read), not from the tick's measurement — the fan-out builds the row before `measure` runs. +- Server section: `resources.py` imports `agent_processes` (stdlib-only) for the snapshot and `descendants`; `res` / `resources` are `null`, not absent, when the snapshot failed. + +```bash +git add CLAUDE.md docs/superpowers/specs/2026-10-30-resource-monitor-design.md +git commit -m "docs: resources.py in the module table; the spec records where the plan differs (THI-448) + +Co-Authored-By: Claude Opus 5.5 (1M context) " +``` + +- [ ] **Step 5: Hand off** + +Do not push. Report to the user: the commits, the gate output, and what the dev-server check showed; ask before pushing the branch and opening the PR (title starts `THI-448:`). diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md new file mode 100644 index 00000000..43191606 --- /dev/null +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -0,0 +1,158 @@ +# Resource monitor + +The dashboard shows how much memory and CPU each owner uses (the panes, the periscope server, its webview, and +everything else) so that lag with ~10 agents can be traced to an owner before anything is optimized. THI-448, first +slice. + +## What the measurements showed (2026-10-30, 11 panes) + +| Owner | Footprint | CPU (per core, as `top` reads) | +|---|---|---| +| Machine (16 GB RAM, 10 cores) | ~48 GB; 16.5 of 17.4 GB swap used | load avg 50–70 | +| Panes, whole process subtrees | 12.8 GB | 112% | +| ↳ heaviest pane | 6.8 GB, mostly `tsc`/`prettier`/`eslint`; its claude 446 MB | 58% | +| Webview: `periscope-app` and its WebKit helpers | live WebContent 2–3 GB (7.7 GB peak), a parked WebContent never reaped 1.3 GB, GPU 79 MB | ~40% WebContent, GPU most CPU of the app | +| Periscope server + tmux control clients | 176 MB | ~7% own, ~38% more in reaped children | +| Elsewhere, e.g. an orphaned `lgtm` node server | 4.1 GB for that one process | ~0 | + +`ps` RSS left out compressed and swapped pages: the webview read 276 MB resident against 2,855 MB of footprint, one +claude 111 MB against 460 MB. + +## Scope + +In: measurement, the header pill and popover, the detail-header numbers. +Out, each its own later PR: dashboard freshness (`build_state` time, `/ws/state` frame gap), a 1 h history, the +recycle-pending indicator (THI-449). +THI-449 (recycle gate, unreaped WebContent) and THI-450 (subprocesses per tick) are separate tickets. + +## Decisions + +**D1 — Memory is `phys_footprint`; CPU is the change in CPU time; both come from `proc_pid_rusage`.** Footprint is +what Activity Monitor calls Memory and what the shell's recycle already uses. Read through `ctypes` on +`/usr/lib/libproc.dylib` with the `RUSAGE_INFO_V1` flavor, which adds the CPU time of a process's reaped children +to the V0 fields `recycle.rs` binds. CPU times are mach absolute units, scaled by `mach_timebase_info` (125/3 on +this machine). Stdlib only, so `uv run server.py`'s PEP-723 header doesn't change. CPU% is a share of the whole machine +(100% = every core busy), not per core like `top`: groups listed side by side read as parts of one total, where +per-core figures ran past 100% (2.25 cores = 225%). Measured cost of a whole pass, including D3's `proc_name` and +responsible-pid calls for every process: 4–6 ms on ~750–790 processes (one rusage read is ~3 µs). + +**D2 — Measurement runs inside `build_state`, once per tick, on the tick's existing process snapshot.** +`build_state` takes `agent_processes.process_snapshot()` once, before the fan-out, whose `codex_process_for_pane` +calls hit the same 1 s cache, and hands it to `measure` after the fan-out: no subprocess is added, however slow the +tick. When the snapshot is `None` (a `ps` failure), `res` and `resources` are `null` for that tick +rather than computed from an empty tree, which would collapse every pane to its shell. A separate sampler thread +was rejected: it would need its own process table and a thread under `docs/testing.md`'s rules. + +**D3 — Every process on the machine lands in exactly one group.** +- **Each window row's pane:** the row's `pane_pid` and all its descendants in the snapshot. The claude process alone + undercounts a busy session (446 MB against 6.8 GB above). `panes` is the sum over rows, so the rows add up to it. +- **Server:** periscope's own pid and its descendants (the tmux control clients, whatever `git`/`gh`/`ps` is running). +- **Webview:** the `periscope-app` process (matched by the kernel's process name, `proc_name`: `ps` cuts the + `comm` column to 16 characters) and every process whose responsible pid is that app, found through + libSystem's `responsibility_get_pid_responsible_for_pid`. That covers every WebKit helper: the live WebContent, + any parked WebContent the recycle didn't reap, GPU and Networking. The WebKit helpers have launchd as their parent, + so the process tree can't find them. With no `periscope-app` running (dashboard in a browser tab), `webview` is + `null`. +- **Elsewhere:** every other process readable by the user. That includes the tmux server, non-active panes of split + windows, the `periscope-input` pane, daemons a session left running, and every other app. No attempt is made to + attribute these: the orphaned `lgtm` server's responsible process is Ghostty, the same as Ghostty's own processes. + Processes `proc_pid_rusage` can't read (root-owned, or gone since the snapshot) are skipped. + +**D4 — A process is identified by (pid, start time), and a group's CPU accounts for exits.** Samples are keyed by +`(pid, ri_proc_start_abstime)`, so a recycled pid never diffs against an unrelated process. Each process's own time +and its reaped children's time are kept apart. Accounting is per process across the whole machine, then summed per +group: +- a process that vanished since the previous sample was reaped, and its whole CPU time reappears in its reaper's + children time. Its last total (own + children) was counted already, so it is charged to its nearest surviving + ancestor: walk the previous sample's parent chain past every process that vanished too. With no readable survivor + on the chain (launchd, which reaps orphans), it is charged to no one; +- a process present in both samples counts the change in its own time, plus the change in its children time less + what was charged to it, floored at 0; +- a process absent from the previous sample counts its whole total, none of which was counted before. +So a Bash tool command (claude → `zsh -c` → command, both exiting in one interval) counts only its last interval in +claude's pane. A closed pane's shell is charged to the tmux server, and so is its claude, whose chain walks there +too; the claude was orphaned to launchd (measured: the shell exits first), so the server never gains it, and the +floor caps the loss at that survivor's reaped-children time for the interval; its own CPU is never touched. A group's result is `null` when it exceeds +every core for the whole interval, which only CPU from outside the interval can do. This catches the short-lived +`git`/`gh`/`tsc` runs that live less than a tick, which own-time sampling would count as 0. + +**D5 — Samples are taken under a lock, at most every 0.5 s, and never against stale history.** `build_state` can +run concurrently from the state hub, the REST fallback poll and other tabs. One lock covers read-diff-write. A +caller within 0.5 s of the previous sample, with the same panes, gets the previous measurement back instead of a new delta (5 ms windows measured 0% +for a server averaging 10%). A previous sample older than 60 s (a hub that idled with no subscribers) counts as +missing; a loaded machine was measured at 3–28 s a tick, so a slow tick still measures. With no usable previous sample, or an impossible delta (D4), `cpu_pct` is `null`, never 0. A 0 is either +measured idle, or a reaper's children time D4 floored. + +**D6 — The machine line reads the kernel directly, with no fork.** Load average from `os.getloadavg()`; physical RAM +from `sysctlbyname("hw.memsize")`; swap used and total from `vm.swapusage`; free memory percent from `kern.memorystatus_level`, the figure +`memory_pressure` prints. + +**D7 — The ↻ cycle hint keeps watching the claude process alone, measured as footprint.** The leak it targets lives +in claude, not in its tool children. The thresholds become `MEM_WARN_MB` / `MEM_BAD_MB` at the same values (2 GB / +4 GB); today's claudes sit at 250–550 MB, so nothing new trips. `claude_proc_for` reads the claude's footprint +directly (`resources.footprint_mb`, one ~3 µs read), because the fan-out builds each row before `measure` runs; an unreadable footprint (the claude exited since `ps`) means +no live claude, so `gb` is always a number. The chip sends `{tier, gb, age_s, trigger}` where `trigger` is `"mem"` or `"age"`, so +`memHint` labels from it instead of repeating the 2 GB threshold in JS. `_claude_procs()` keeps its `ps` call for +liveness and age but drops `rss=`; moving liveness off `ps` belongs to THI-450. + +## Server + +`periscope/resources.py`, stdlib plus `agent_processes` (itself stdlib-only) for the snapshot and `descendants`: + +- `measure(snapshot, panes)` → `Measurement | None`, given the tick's process snapshot and `{pane_id: pane_pid}`. + It assigns each process to a group (D3), reads every process once (the sample is stamped just before the reads), + computes footprint and CPU per group (D4, D5), and returns `panes: {pane_id: {mem_mb, cpu_pct}}` and + `totals: {server, webview, panes, elsewhere, machine}`. Each group is `{mem_mb, cpu_pct}`; `webview` may be `null`; + `machine` is D6's `{load1, ram_mb, swap_used_mb, swap_total_mb, mem_free_pct}`. `None` when the snapshot is. +- `footprint_mb(pid)` — one process's footprint, for the ↻ hint (D7). + +`build_state` takes the snapshot before the fan-out (D2) and calls `measure` after it, before the narrator merge. +Each row gets `res`; the blob gets `resources`. + +`/api/healthz` is unchanged: its only programmatic caller (`bin/periscope`) reads `.version`, and a narrow sample +there would disturb the CPU history of every other group. + +## UI + +- **Header pill** after `UsagePill`: `▣ 18.1G`, the memory of server, webview and panes together. CPU stays out of + the pill. Hidden when `resources` is absent. +- **Popover** on click, one line each with memory and CPU: periscope server, webview, all panes (the `panes` + group), then every pane sorted by memory (a line selects its pane), then elsewhere, then the machine line: + `16.0G RAM · swap 16.5G/17.4G · 27% free · load 52.3`. RAM leads because footprints count compressed and swapped + pages: the groups can add up past it, and that overcommitment is what the line shows. + The CPU column's tooltip says 100% = every core busy; under 10% it shows one decimal. A `null` CPU shows `–`. +- **Detail header**: `· 6.8G mem · 5.8% cpu` after the context %, for the selected pane (the heaviest pane above: + 58% of one core is 5.8% of a 10-core machine). +- Formatting (MB → `0.6G` / `512M`, CPU rounding, `null`) and the sort go in a pure `static/src/chrome/resources.js`, + tested with vitest, the way `usageSummary.js` backs `UsagePill`. +- `memHint` reads `gb` and `trigger`. + +## Tests + +- `tests/conftest.py`: an autouse fixture stubs `build_state`'s snapshot (an empty one, no `ps`) and + `resources.measure`'s system calls, so no test reads the real machine's processes. Tests of `resources` itself + replace the same seams with fakes. +- `tests/test_resources.py`, over a fake snapshot and fake rusage: + - group assignment, including a WebKit helper found by responsible pid, a process outside every group, and a + server inside a pane's subtree (counted once); + - CPU: first sample (`null`), steady second sample, pid reuse, a process absent from the previous sample, a child + that exits and is reaped by its parent, a Bash tool command whose `zsh -c` and command both exit in one + interval, a closed pane's shell reaped by the tmux server in another group, an orphan launchd reaped whose chain + reaches a survivor (floored, nothing stolen), a delta past every core (`null`); + - the 0.5 s and 60 s rules, and two threads sampling at once (forced to overlap, so the test needs the lock); + - a `None` snapshot; + - smoke tests that read the test process itself through the real `proc_pid_rusage`, one of them after reaping a + CPU-burning child, so the `child_*` field offsets are checked. +- `tests/test_window_view.py`: `mem_signal` on footprint, each tier and trigger (updating today's RSS cases). +- `tests/routes/`: `/api/state` carries `res` and `resources`, and omits both when the snapshot is `None`. +- vitest: `resources.js` formatting, `null` CPU and ordering; `memHint` with `gb`/`trigger` (updating + `memHint.test.js` and `agent.test.js`). + +## Assumptions + +- Periscope runs only on macOS (`ci.yml`: "periscope only runs on macOS hosts"), so `libproc` is always present. +- `responsibility_get_pid_responsible_for_pid` is a private libSystem function, the same kind of private API the shell + already relies on (`_webProcessIdentifier`). It worked on this machine (macOS 27) for every WebKit helper. +- Summing `phys_footprint` across the webview's processes doesn't double count; WebKit hands IOSurface ownership to + WebContent. Not proven for the GPU process. +- A webview open on JS older than the server shows a malformed ↻ label until it reloads. diff --git a/periscope/agent_processes.py b/periscope/agent_processes.py index 001e51e9..d3097aff 100644 --- a/periscope/agent_processes.py +++ b/periscope/agent_processes.py @@ -93,7 +93,8 @@ def _is_codex_executable(proc: ProcessInfo) -> bool: return os.path.basename(proc.comm).lower() in {"codex", "codex.exe"} -def _descendants(root_pid: int, snapshot: dict[int, ProcessInfo]): +def descendants(root_pid: int, snapshot: dict[int, ProcessInfo]): + """`root_pid`'s process (when in the snapshot) and every process below it.""" children: dict[int, list[ProcessInfo]] = {} for proc in snapshot.values(): children.setdefault(proc.ppid, []).append(proc) @@ -143,7 +144,7 @@ def codex_process_for_pane(pane_id: str, pane_pid: int | str | None) -> bool | N return True _pane_cache.pop(pane_id, None) - for proc in _descendants(root_pid, snapshot): + for proc in descendants(root_pid, snapshot): if not proc.state.upper().startswith("Z") and _is_codex_executable(proc): _pane_cache[pane_id] = ( root_pid, diff --git a/periscope/config.py b/periscope/config.py index 00f895c4..80cdc887 100644 --- a/periscope/config.py +++ b/periscope/config.py @@ -152,12 +152,12 @@ def claude_subprocess_env(*, config_dir: str) -> dict[str, str]: return env -# Claude cycle-hint thresholds (rail ↻ chip): red when a pane's claude RSS -# crosses BAD, amber at WARN rss or WARN age. Healthy claudes idle around -# 0.3–0.6GB; the leak class that motivated this shows up as multi-GB RSS on -# multi-day processes. -MEM_BAD_RSS_KB = 4 * 1024 * 1024 # 4GB -MEM_WARN_RSS_KB = 2 * 1024 * 1024 # 2GB +# Claude cycle-hint thresholds (rail ↻ chip): red when a pane's claude +# footprint crosses BAD, amber at WARN footprint or WARN age. Healthy claudes +# sit at 0.25–0.55GB of footprint; the leak class that motivated this shows +# up as multi-GB on multi-day processes. +MEM_BAD_MB = 4 * 1024 # 4GB +MEM_WARN_MB = 2 * 1024 # 2GB MEM_WARN_AGE_S = 3 * 86400 # 3 days diff --git a/periscope/resources.py b/periscope/resources.py new file mode 100644 index 00000000..fbc8997b --- /dev/null +++ b/periscope/resources.py @@ -0,0 +1,287 @@ +"""Memory footprint and CPU per group: each pane, the periscope server, its +webview, and everything else on the machine. + +Footprint (`phys_footprint`, Activity Monitor's Memory), not RSS: RSS leaves +out compressed and swapped pages, which is where a machine deep in swap keeps +most of its memory — the webview read 276 MB resident against 2.8 GB of +footprint. Read through libproc/libSystem with ctypes: ~3 µs a process, no +subprocess. +""" + +from __future__ import annotations + +import ctypes +import os +import threading +from dataclasses import dataclass + +from periscope.agent_processes import ProcessInfo, descendants + +_u64 = ctypes.c_uint64 +_RUSAGE_INFO_V1 = 1 + +# The Tauri shell's executable (src-tauri), matched by `_name`. Its WebKit +# helpers have launchd as their parent, so they're found by responsible pid. +_APP_NAME = "periscope-app" + +# A previous sample older than this (a hub that idled with no subscribers) +# would average hours into one number; it counts as missing. Well past the +# slowest tick: a loaded machine was measured at 3–28 s a tick. +_STALE_NS = 60 * 1_000_000_000 + +# A delta over less than this reads noise (5 ms windows measured 0% for a +# server averaging 10%); a caller inside it with the same panes gets the previous measurement. +_MIN_INTERVAL_NS = 500_000_000 + +# CPU is a share of the whole machine: a group listed next to the others reads +# as a part of 100%, where per-core figures ran past it (2.25 cores = 225%). +_CORES = os.sysconf("SC_NPROCESSORS_ONLN") + + +class _RusageInfoV1(ctypes.Structure): + # rusage_info_v1: the v0 fields recycle.rs binds, plus + # the CPU time of reaped children (144 bytes). + _fields_ = [("uuid", ctypes.c_uint8 * 16)] + [ + (name, _u64) + for name in ( + "user_time", + "system_time", + "pkg_idle_wkups", + "interrupt_wkups", + "pageins", + "wired_size", + "resident_size", + "phys_footprint", + "proc_start_abstime", + "proc_exit_abstime", + "child_user_time", + "child_system_time", + "child_pkg_idle_wkups", + "child_interrupt_wkups", + "child_pageins", + "child_elapsed_abstime", + ) + ] + + +class _Timebase(ctypes.Structure): + _fields_ = [("numer", ctypes.c_uint32), ("denom", ctypes.c_uint32)] + + +class _SwapUsage(ctypes.Structure): + # struct xsw_usage + _fields_ = [ + ("total", _u64), + ("avail", _u64), + ("used", _u64), + ("pagesize", ctypes.c_uint32), + ("encrypted", ctypes.c_int32), + ] + + +_libproc = ctypes.CDLL("/usr/lib/libproc.dylib") +_libproc.proc_pid_rusage.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_void_p] +_libproc.proc_name.argtypes = [ctypes.c_int, ctypes.c_void_p, ctypes.c_uint32] +_libsystem = ctypes.CDLL("/usr/lib/libSystem.dylib") +_libsystem.responsibility_get_pid_responsible_for_pid.argtypes = [ctypes.c_int] +_libsystem.responsibility_get_pid_responsible_for_pid.restype = ctypes.c_int +_libsystem.mach_absolute_time.restype = _u64 +_timebase = _Timebase() +_libsystem.mach_timebase_info(ctypes.byref(_timebase)) +# rusage times are mach absolute units: 125/3 ns each on Apple silicon. +_NS_PER_TICK = _timebase.numer / _timebase.denom + + +@dataclass(frozen=True) +class Reading: + footprint: int # bytes + own_ns: int # CPU time, user + system + children_ns: int # its reaped children's CPU time + start: int # ns on _now()'s clock; (pid, start) is a process's identity + + +def _read(pid: int) -> Reading | None: + """One process's rusage, or None when it is gone or not the user's + (root-owned processes refuse).""" + info = _RusageInfoV1() + if _libproc.proc_pid_rusage(pid, _RUSAGE_INFO_V1, ctypes.byref(info)) != 0: + return None + return Reading( + info.phys_footprint, + int((info.user_time + info.system_time) * _NS_PER_TICK), + int((info.child_user_time + info.child_system_time) * _NS_PER_TICK), + int(info.proc_start_abstime * _NS_PER_TICK), + ) + + +def _responsible(pid: int) -> int: + """The pid macOS holds responsible for `pid`: for a WebKit helper, the app + hosting the webview. A private libSystem call, like the shell's + `_webProcessIdentifier`.""" + return _libsystem.responsibility_get_pid_responsible_for_pid(pid) + + +def _name(pid: int) -> str: + """The process's name from the kernel (up to 32 characters) — `ps`'s comm + column cuts it to 16, which loses "periscope-app".""" + buf = ctypes.create_string_buffer(64) + _libproc.proc_name(pid, buf, ctypes.sizeof(buf)) + return buf.value.decode(errors="replace") + + +def _now() -> int: + """ns on the clock `proc_start_abstime` counts on.""" + return int(_libsystem.mach_absolute_time() * _NS_PER_TICK) + + +def footprint_mb(pid: int) -> int | None: + reading = _read(pid) + return None if reading is None else reading.footprint >> 20 + + +def _sysctl(name: str, buf: ctypes.Structure | ctypes.c_int | ctypes.c_uint64) -> None: + size = ctypes.c_size_t(ctypes.sizeof(buf)) + _libsystem.sysctlbyname(name.encode(), ctypes.byref(buf), ctypes.byref(size), None, ctypes.c_size_t(0)) + + +def machine() -> dict: + """Load, RAM, swap and free memory, straight from the kernel. RAM is the + yardstick: footprints count compressed and swapped pages, so the groups can + add up past it. mem_free_pct is the figure `memory_pressure` prints.""" + ram = ctypes.c_uint64() + swap = _SwapUsage() + level = ctypes.c_int() + _sysctl("hw.memsize", ram) + _sysctl("vm.swapusage", swap) + _sysctl("kern.memorystatus_level", level) + return { + "load1": round(os.getloadavg()[0], 1), + "ram_mb": ram.value >> 20, + "swap_used_mb": swap.used >> 20, + "swap_total_mb": swap.total >> 20, + "mem_free_pct": level.value, + } + + +def _assign(snapshot: dict[int, ProcessInfo], panes: dict[str, int]) -> tuple[dict[str, set[int]], dict[str, set[int]]]: + """Every process in exactly one group: ({"server", "webview"?, "panes", + "elsewhere"} → pids, pane_id → pids). Claimed in that order, so a process + is never counted twice.""" + claimed: set[int] = set() + + def claim(pids: set[int]) -> set[int]: + fresh = pids - claimed + claimed.update(fresh) + return fresh + + def subtree(root: int) -> set[int]: + return {p.pid for p in descendants(root, snapshot)} + + named = {"server": claim(subtree(os.getpid()))} + apps = {pid for pid in snapshot if _name(pid) == _APP_NAME} + if apps: + named["webview"] = claim(apps | {pid for pid in snapshot if _responsible(pid) in apps}) + per_pane = {pane_id: claim(subtree(root)) for pane_id, root in panes.items()} + named["panes"] = set().union(*per_pane.values()) + named["elsewhere"] = set(snapshot) - claimed + return named, per_pane + + +@dataclass(frozen=True) +class _Proc: + start: int # (pid, start) is its identity + own_ns: int + children_ns: int + ppid: int # from the snapshot + + +@dataclass(frozen=True) +class _Sample: + at: int # ns, _now()'s clock + procs: dict[int, _Proc] # pid → every readable process + + +def _cpu_pcts(prev: _Sample | None, cur: _Sample, groups: dict[str, set[int]]) -> dict[str, float | None]: + """Each group's share of the machine's CPU since `prev` (100 = every core + busy), or None with no usable previous sample. + + A process that vanished was reaped, and its whole CPU time reappears in + its reaper's children time: its last total was counted already, so it + comes off the children time of its nearest surviving ancestor. That + floors at 0 per ancestor: an orphan launchd reaped never reaches it. + A group past every core for the whole interval holds CPU from outside + it: None.""" + if prev is None or cur.at - prev.at > _STALE_NS: + return dict.fromkeys(groups) + + def alive(pid: int) -> bool: + return pid in cur.procs and pid in prev.procs and cur.procs[pid].start == prev.procs[pid].start + + counted: dict[int, int] = {} # surviving pid → its vanished descendants' last totals + for pid, p in prev.procs.items(): + if alive(pid): + continue + ancestor = p.ppid + while ancestor in prev.procs and not alive(ancestor): + ancestor = prev.procs[ancestor].ppid + if ancestor in prev.procs: # else launchd or another unreadable process + counted[ancestor] = counted.get(ancestor, 0) + p.own_ns + p.children_ns + delta: dict[int, int] = {} + for pid, c in cur.procs.items(): + if alive(pid): + p = prev.procs[pid] + delta[pid] = c.own_ns - p.own_ns + max(0, c.children_ns - p.children_ns - counted.get(pid, 0)) + else: # none of it counted yet + delta[pid] = c.own_ns + c.children_ns + elapsed = cur.at - prev.at + out: dict[str, float | None] = {} + for key, pids in groups.items(): + ns = sum(delta.get(pid, 0) for pid in pids) + out[key] = None if ns > elapsed * _CORES else round(ns / elapsed / _CORES * 100, 1) + return out + + +@dataclass(frozen=True) +class Measurement: + panes: dict[str, dict] # pane_id → {mem_mb, cpu_pct} + totals: dict # server, webview (None without the app), panes, elsewhere: {mem_mb, cpu_pct}; machine + + +# build_state runs from the state hub, the REST fallback poll and other tabs at +# once; the lock makes each read-diff-write of _prev whole. +_lock = threading.Lock() +_prev: _Sample | None = None +_last: tuple[int, dict[str, int], Measurement] | None = None # at, panes, measurement + + +def measure(snapshot: dict[int, ProcessInfo] | None, panes: dict[str, int]) -> Measurement | None: + """Footprint and CPU for each pane (pane_id → its root pid, tmux's + pane_pid) and every other group, over the tick's process snapshot. None + when the snapshot failed: an empty tree would collapse every pane to its + shell and read as real.""" + global _prev, _last + if snapshot is None: + return None + with _lock: + # Only for the same panes: a pane new to this tick would have no res. + if _last is not None and _last[1] == panes and _now() - _last[0] < _MIN_INTERVAL_NS: + return _last[2] + named, per_pane = _assign(snapshot, panes) + # Stamped here, not before _assign: the sample is when it was read. + now = _now() + readings = {pid: r for pid in snapshot if (r := _read(pid)) is not None} + cur = _Sample( + now, {pid: _Proc(r.start, r.own_ns, r.children_ns, snapshot[pid].ppid) for pid, r in readings.items()} + ) + groups = named | {f"pane:{pane_id}": pids for pane_id, pids in per_pane.items()} + cpu = _cpu_pcts(_prev, cur, groups) + + def group(key: str) -> dict: + mem = sum(readings[pid].footprint for pid in groups[key] if pid in readings) + return {"mem_mb": mem >> 20, "cpu_pct": cpu[key]} + + totals: dict = {"webview": None} | {key: group(key) for key in named} + totals["machine"] = machine() + measurement = Measurement({pane_id: group(f"pane:{pane_id}") for pane_id in per_pane}, totals) + _prev, _last = cur, (now, panes, measurement) + return measurement diff --git a/periscope/routes/state.py b/periscope/routes/state.py index 961be0d7..175ed8e9 100644 --- a/periscope/routes/state.py +++ b/periscope/routes/state.py @@ -13,8 +13,9 @@ from fastapi import APIRouter -from periscope import store, updater, usage +from periscope import resources, store, updater, usage from periscope.activity import pane_status_lines +from periscope.agent_processes import process_snapshot from periscope.channels import _channel_gc from periscope.panes import ( RESUME_EXPIRY_S, @@ -69,6 +70,9 @@ def build_state() -> dict: update_focus_from_windows(windows) _attach_git_then_resolve_pids(windows, full_roster=True) now_ts = int(time.time()) + # Taken before the fan-out, whose codex_process_for_pane calls share its + # 1 s cache: measure below reads the same snapshot without a second `ps`. + snapshot = process_snapshot() # Parallel fan-out: capture()+parse per pane is the only per-poll # subprocess and dominates wall-clock. The serial git-warm + pid mint @@ -86,6 +90,12 @@ def build_state() -> dict: result = [view for view, _ in built] annotate_cost_pressure(result) + # Memory and CPU per group. Each row's pane_pid roots its pane's group; + # None when the snapshot failed. + measured = resources.measure(snapshot, {v["pane_id"]: int(v["pane_pid"]) for v in result if v.get("pane_pid")}) + for view in result: + view["res"] = measured.panes.get(view["pane_id"]) if measured else None + # Narrator status merge: ONE bulk read here, NOT per-pane inside # build_window_view — the 32-thread fan-out would serialize on # activity._LOCK. status_at lets the UI dim stale lines. @@ -192,6 +202,9 @@ def build_state() -> dict: # rather than re-scanning /Applications every poll — detection is only # needed at the Settings write boundary, which already validates it. "editor": (get_settings().get("editor") or ""), + # server / webview / panes / elsewhere / machine (resources.measure); + # the header pill and its popover. + "resources": measured.totals if measured else None, } diff --git a/periscope/session_status.py b/periscope/session_status.py index bdb66f09..4afa8847 100644 --- a/periscope/session_status.py +++ b/periscope/session_status.py @@ -23,8 +23,8 @@ the caller falls back to scraping. The schema is undocumented Claude Code internals (version-tagged), so every read degrades to None on a shape change. -Imports only stdlib — no periscope.* — so it stays a leaf the resolver layer -(turns.py / window_view.py) can depend on freely.""" +Imports only stdlib and periscope's leaf modules (config, resources), never +the resolver layer, so turns.py / window_view.py can depend on it freely.""" import contextlib import json @@ -34,7 +34,7 @@ from collections import deque from pathlib import Path -from periscope import config +from periscope import config, resources _SESSIONS_DIR = Path.home() / ".claude" / "sessions" @@ -51,9 +51,9 @@ # pid -> current sessionId). by_pid holds a LIST because the same OS pid can # have a file in more than one account's dir (recycled pid, account swap). _index_cache: tuple[float, dict, dict[int, list[dict]]] | None = None -# (built_at, {pid: (rss_kb, age_s)}) — one ps snapshot serves both pid -# liveness (the key set) and the memory/uptime cycle-hint. -_claude_procs_cache: tuple[float, dict[int, tuple[int, int]]] | None = None +# (built_at, {pid: age_s}) — one ps snapshot serves both pid liveness (the +# key set) and the uptime cycle-hint. +_claude_procs_cache: tuple[float, dict[int, int]] | None = None _proc_table_cache: tuple[float, tuple[dict[int, list[int]], dict[int, str]]] | None = None _pane_pids_cache: tuple[float, dict[str, int]] | None = None @@ -148,33 +148,33 @@ def parse_etime(s: str) -> int: return ((days * 24 + h) * 60 + m) * 60 + sec -def _claude_procs() -> dict[int, tuple[int, int]]: - """{pid: (rss_kb, age_s)} of running `claude` processes, snapshotted once - per poll. The key set guards against honoring a session file whose process - has exited or whose pid was recycled; rss/etime feed the memory cycle-hint. - `comm` is the full executable path; claude's launcher (`.../bin/claude`) - and versioned binary (`.../share/claude/versions/`) both contain - "claude". comm may itself contain spaces, hence maxsplit=3.""" +def _claude_procs() -> dict[int, int]: + """{pid: age_s} of running `claude` processes, snapshotted once per poll. + The key set guards against honoring a session file whose process has + exited or whose pid was recycled; age feeds the cycle-hint. `comm` is the + full executable path; claude's launcher (`.../bin/claude`) and versioned + binary (`.../share/claude/versions/`) both contain "claude". comm may + itself contain spaces, hence maxsplit=2.""" global _claude_procs_cache now = time.time() if _claude_procs_cache and now - _claude_procs_cache[0] < _CACHE_TTL_S: return _claude_procs_cache[1] - procs: dict[int, tuple[int, int]] = {} + procs: dict[int, int] = {} try: out = subprocess.run( - ["ps", "-axo", "pid=,rss=,etime=,comm="], + ["ps", "-axo", "pid=,etime=,comm="], capture_output=True, text=True, timeout=5, ).stdout for line in out.splitlines(): - parts = line.split(None, 3) - if len(parts) != 4: + parts = line.split(None, 2) + if len(parts) != 3: continue - pid_s, rss_s, etime, comm = parts + pid_s, etime, comm = parts if "claude" in comm.lower(): with contextlib.suppress(ValueError): - procs[int(pid_s)] = (int(rss_s), parse_etime(etime)) + procs[int(pid_s)] = parse_etime(etime) except (OSError, subprocess.SubprocessError): pass _claude_procs_cache = (now, procs) @@ -509,10 +509,11 @@ def live_session_id_for_pane(pane_id: str) -> str | None: def claude_proc_for(sid: str | None) -> dict | None: - """Process stats for a sessionId's claude: {"pid", "rss_kb", "age_s"}, or - None when unmapped or not a live claude. Measurement, not state — applies - even when the status is one session_state_for doesn't trust (a bloated - claude deserves the cycle-hint regardless of what it's doing).""" + """Process stats for a sessionId's claude: {"pid", "mem_mb", "age_s"}, or + None when unmapped or not a live claude (its footprint unreadable: exited + since the ps snapshot). mem_mb is its footprint. Measurement, not state — + applies even when the status is one session_state_for doesn't trust (a + bloated claude deserves the cycle-hint regardless of what it's doing).""" if not sid: return None d = _index().get(sid) @@ -522,10 +523,13 @@ def claude_proc_for(sid: str | None) -> dict | None: pid = int(d.get("pid")) except (TypeError, ValueError): return None - info = _claude_procs().get(pid) - if info is None: + age = _claude_procs().get(pid) + if age is None: return None - return {"pid": pid, "rss_kb": info[0], "age_s": info[1]} + mb = resources.footprint_mb(pid) + if mb is None: + return None + return {"pid": pid, "mem_mb": mb, "age_s": age} def session_state_for(sid: str | None) -> dict | None: diff --git a/periscope/window_view.py b/periscope/window_view.py index a3689910..f1814506 100644 --- a/periscope/window_view.py +++ b/periscope/window_view.py @@ -24,7 +24,7 @@ from periscope.channels import channel_state_for from periscope.codex_sessions import codex_home from periscope.codex_state import reconcile_codex_state, rollout_edge_for -from periscope.config import MEM_BAD_RSS_KB, MEM_WARN_AGE_S, MEM_WARN_RSS_KB +from periscope.config import MEM_BAD_MB, MEM_WARN_AGE_S, MEM_WARN_MB from periscope.git_pr import ( cached_git_state, cached_linked_pr_state, @@ -223,20 +223,22 @@ def _pane_env_labels() -> tuple[dict[str, str], dict[str, str], dict[str, str]]: def mem_signal(proc: dict | None) -> dict | None: """Cycle-hint for a claude process, from claude_proc_for's stats dict: - "bad" at ≥MEM_BAD_RSS_KB, "warn" at ≥MEM_WARN_RSS_KB or ≥MEM_WARN_AGE_S, - None otherwise — None renders nothing, so a healthy pane costs no rail - space. Policy lives here (config thresholds); measurement stays in - session_status, which is a stdlib-only leaf that can't import config.""" + "bad" at ≥MEM_BAD_MB of footprint, "warn" at ≥MEM_WARN_MB or + ≥MEM_WARN_AGE_S, None otherwise — None renders nothing, so a healthy pane + costs no rail space. `trigger` says which limit tripped, so the chip leads + with it. Policy (the config thresholds) lives here; + measurement in session_status and resources.""" if not proc: return None - rss, age = proc["rss_kb"], proc["age_s"] - if rss >= MEM_BAD_RSS_KB: - tier = "bad" - elif rss >= MEM_WARN_RSS_KB or age >= MEM_WARN_AGE_S: - tier = "warn" + mb, age = proc["mem_mb"], proc["age_s"] + if mb >= MEM_WARN_MB: + trigger = "mem" + elif age >= MEM_WARN_AGE_S: + trigger = "age" else: return None - return {"tier": tier, "rss_gb": round(rss / (1024 * 1024), 1), "age_s": age} + tier = "bad" if mb >= MEM_BAD_MB else "warn" + return {"tier": tier, "trigger": trigger, "gb": round(mb / 1024, 1), "age_s": age} # How far before needs_since the request's own row can be stamped. The hook diff --git a/static/dist/app.js b/static/dist/app.js index 353fa37b..3bbcee6a 100644 --- a/static/dist/app.js +++ b/static/dist/app.js @@ -1,48 +1,48 @@ -var Ti,le,nc,rc,ut,Za,ic,lc,tl,Or,jn,ac,la,El,Pl,ei={},ti=[],lh=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Ei=Array.isArray;function et(e,t){for(var n in t)e[n]=t[n];return e}function aa(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function ah(e,t,n){var i,l,a,s={};for(a in t)a=="key"?i=t[a]:a=="ref"?l=t[a]:s[a]=t[a];if(arguments.length>2&&(s.children=arguments.length>3?Ti.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(a in e.defaultProps)s[a]===void 0&&(s[a]=e.defaultProps[a]);return Dr(e,s,i,l,null)}function Dr(e,t,n,i,l){var a={type:e,props:t,key:n,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:l??++nc,__i:-1,__u:0};return l==null&&le.vnode!=null&&le.vnode(a),a}function V(e){return e.children}function Hn(e,t){this.props=e,this.context=t}function mn(e,t){if(t==null)return e.__?mn(e.__,e.__i+1):null;for(var n;tt&&ut.sort(lc),e=ut.shift(),t=ut.length,sh(e)}finally{ut.length=ni.__r=0}}function oc(e,t,n,i,l,a,s,o,u,c,f){var d,p,h,m,b,x,w,C=i&&i.__k||ti,y=t.length;for(u=oh(n,t,C,u,y),d=0;d0?s=e.__k[a]=Dr(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):e.__k[a]=s,u=a+p,s.__=e,s.__b=e.__b+1,o=null,(c=s.__i=ch(s,n,u,d))!=-1&&(d--,(o=n[c])&&(o.__u|=2)),o==null||o.__v==null?(c==-1&&(l>f?p--:lu?p--:p++,s.__u|=4))):e.__k[a]=null;if(d)for(a=0;a(f?1:0)){for(l=n-1,a=n+1;l>=0||a=0?l--:a++])!=null&&!(2&c.__u)&&o==c.key&&u==c.type)return s}return-1}function es(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||lh.test(t)?n:n+"px"}function xr(e,t,n,i,l){var a,s;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof i=="string"&&(e.style.cssText=i=""),i)for(t in i)n&&t in n||es(e.style,t,"");if(n)for(t in n)i&&n[t]==i[t]||es(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(ac,"$1")),s=t.toLowerCase(),t=s in e||t=="onFocusOut"||t=="onFocusIn"?s.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+a]=n,n?i?n[jn]=i[jn]:(n[jn]=la,e.addEventListener(t,a?Pl:El,a)):e.removeEventListener(t,a?Pl:El,a);else{if(l=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function ts(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[Or]==null)t[Or]=la++;else if(t[Or]0?e:Ei(e)?e.map(dc):e.constructor!==void 0?null:et({},e)}function uh(e,t,n,i,l,a,s,o,u){var c,f,d,p,h,m,b,x=n.props||ei,w=t.props,C=t.type;if(C=="svg"?l="http://www.w3.org/2000/svg":C=="math"?l="http://www.w3.org/1998/Math/MathML":l||(l="http://www.w3.org/1999/xhtml"),a!=null){for(c=0;c=n.__.length&&n.__.push({}),n.__[e]}function B(e){return Xn=1,ph(mc,e)}function ph(e,t,n){var i=ca(Zn++,2);if(i.t=e,!i.__c&&(i.__=[mc(void 0,t),function(o){var u=i.__N?i.__N[0]:i.__[0],c=i.t(u,o);u!==c&&(i.__N=[c,i.__[1]],i.__c.setState({}))}],i.__c=pe,!pe.__f)){var l=function(o,u,c){if(!i.__c.__H)return!0;var f=i.__c.__H.__.filter(function(p){return p.__c});if(f.every(function(p){return!p.__N}))return!a||a.call(this,o,u,c);var d=i.__c.props!==o;return f.some(function(p){if(p.__N){var h=p.__[0];p.__=p.__N,p.__N=void 0,h!==p.__[0]&&(d=!0)}}),a&&a.call(this,o,u,c)||d};pe.__f=!0;var a=pe.shouldComponentUpdate,s=pe.componentWillUpdate;pe.componentWillUpdate=function(o,u,c){if(this.__e){var f=a;a=void 0,l(o,u,c),a=f}s&&s.call(this,o,u,c)},pe.shouldComponentUpdate=l}return i.__N||i.__}function j(e,t){var n=ca(Zn++,3);!ge.__s&&pc(n.__H,t)&&(n.__=e,n.u=t,pe.__H.__h.push(n))}function ne(e){return Xn=5,mr(function(){return{current:e}},[])}function mr(e,t){var n=ca(Zn++,7);return pc(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function Pi(e,t){return Xn=8,mr(function(){return e},t)}function mh(){for(var e;e=fc.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Rr),t.__h.some(Ml),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){pe=null,rs&&rs(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),os&&os(e,t)},ge.__r=function(e){is&&is(e),Zn=0;var t=(pe=e.__c).__H;t&&(nl===pe?(t.__h=[],pe.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(Rr),t.__h.some(Ml),t.__h=[],Zn=0)),nl=pe},ge.diffed=function(e){ls&&ls(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(fc.push(t)!==1&&ns===ge.requestAnimationFrame||((ns=ge.requestAnimationFrame)||gh)(mh)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),nl=pe=null},ge.__c=function(e,t){t.some(function(n){try{n.__h.some(Rr),n.__h=n.__h.filter(function(i){return!i.__||Ml(i)})}catch(i){t.some(function(l){l.__h&&(l.__h=[])}),t=[],ge.__e(i,n.__v)}}),as&&as(e,t)},ge.unmount=function(e){ss&&ss(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(i){try{Rr(i)}catch(l){t=l}}),n.__H=void 0,t&&ge.__e(t,n.__v))};var cs=typeof requestAnimationFrame=="function";function gh(e){var t,n=function(){clearTimeout(i),cs&&cancelAnimationFrame(t),setTimeout(e)},i=setTimeout(n,35);cs&&(t=requestAnimationFrame(n))}function Rr(e){var t=pe,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),pe=t}function Ml(e){var t=pe;e.__c=e.__(),pe=t}function pc(e,t){return!e||e.length!==t.length||t.some(function(n,i){return n!==e[i]})}function mc(e,t){return typeof t=="function"?t(e):t}var yh=Symbol.for("preact-signals");function ua(){if(Rt>1)Rt--;else{var e,t=!1;for(function(){var l=ii;for(ii=void 0;l!==void 0;)l.S.v===l.v&&(l.S.i=l.i),l=l.o}();qn!==void 0;){var n=qn;for(qn=void 0,ri++;n!==void 0;){var i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&yc(n))try{n.c()}catch(l){t||(e=l,t=!0)}n=i}}if(ri=0,Rt--,t)throw e}}var se=void 0;function Ai(e){var t=se;se=void 0;try{return e()}finally{se=t}}var qn=void 0,Rt=0,ri=0,us=0,ii=void 0,li=0;function gc(e){if(se!==void 0){var t=e.n;if(t===void 0||t.t!==se)return t={i:0,S:e,p:se.s,n:void 0,t:se,e:void 0,x:void 0,r:t},se.s!==void 0&&(se.s.n=t),se.s=t,e.n=t,32&se.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=se.s,t.n=void 0,se.s.n=t,se.s=t),t}}function ve(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}ve.prototype.brand=yh;ve.prototype.h=function(){return!0};ve.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:Ai(function(){var i;(i=t.W)==null||i.call(t)}))};ve.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,i=e.x;n!==void 0&&(n.x=i,e.e=void 0),i!==void 0&&(i.e=n,e.x=void 0),e===this.t&&(this.t=i,i===void 0&&Ai(function(){var l;(l=t.Z)==null||l.call(t)}))}};ve.prototype.subscribe=function(e){var t=this;return lt(function(){var n=t.value,i=se;se=void 0;try{e(n)}finally{se=i}},{name:"sub"})};ve.prototype.valueOf=function(){return this.value};ve.prototype.toString=function(){return this.value+""};ve.prototype.toJSON=function(){return this.value};ve.prototype.peek=function(){var e=this;return Ai(function(){return e.value})};Object.defineProperty(ve.prototype,"value",{get:function(){var e=gc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ri>100)throw new Error("Cycle detected");(function(n){Rt!==0&&ri===0&&n.l!==us&&(n.l=us,ii={S:n,v:n.v,i:n.i,o:ii})})(this),this.v=e,this.i++,li++,Rt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{ua()}}}});function H(e,t){return new ve(e,t)}function yc(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function bc(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function kc(e){for(var t=e.s,n=void 0;t!==void 0;){var i=t.p;t.i===-1?(t.S.U(t),i!==void 0&&(i.n=t.n),t.n!==void 0&&(t.n.p=i)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=i}e.s=n}function Kt(e,t){ve.call(this,void 0),this.x=e,this.s=void 0,this.g=li-1,this.f=4,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}Kt.prototype=new ve;Kt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===li))return!0;if(this.g=li,this.f|=1,this.i>0&&!yc(this))return this.f&=-2,!0;var e=se;try{bc(this),se=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return se=e,kc(this),this.f&=-2,!0};Kt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}ve.prototype.S.call(this,e)};Kt.prototype.U=function(e){if(this.t!==void 0&&(ve.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};Kt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(Kt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=gc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Vt(e,t){return new Kt(e,t)}function wc(e){var t=e.m;if(e.m=void 0,typeof t=="function"){Rt++;var n=se;se=void 0;try{t()}catch(i){throw e.f&=-2,e.f|=8,da(e),i}finally{se=n,ua()}}}function da(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,wc(e)}function bh(e){if(se!==this)throw new Error("Out-of-order effect");kc(this),se=e,this.f&=-2,8&this.f&&da(this),ua()}function _n(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t==null?void 0:t.name}_n.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};_n.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,wc(this),bc(this),Rt++;var e=se;return se=this,bh.bind(this,e)};_n.prototype.N=function(){2&this.f||(this.f|=2,this.u=qn,qn=this)};_n.prototype.d=function(){this.f|=8,1&this.f||da(this)};_n.prototype.dispose=function(){this.d()};function lt(e,t){var n=new _n(e,t);try{n.c()}catch(l){throw n.d(),l}var i=n.d.bind(n);return i[Symbol.dispose]=i,i}var Mi,Sr;function xn(e,t){le[e]=t.bind(null,le[e]||function(){})}function ai(e){if(Sr){var t=Sr;Sr=void 0,t()}Sr=e&&e.S()}function vc(e){var t=this,n=e.data,i=_c(n);i.value=n;var l=mr(function(){for(var a=t.__v;a=a.__;)if(a.__c){a.__c.__$f|=4;break}return t.__$u.c=function(){var s,o=t.__$u.S(),u=l.value;o(),rc(u)||((s=t.base)==null?void 0:s.nodeType)!==3?(t.__$f|=1,t.setState({})):t.base.data=u},Vt(function(){var s=i.value.value;return s===0?0:s===!0?"":s||""})},[]);return l.value}vc.displayName="_st";Object.defineProperties(ve.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:vc},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});xn("__b",function(e,t){if(typeof t.type=="string"){var n,i=t.props;for(var l in i)if(l!=="children"){var a=i[l];a instanceof ve&&(n||(t.__np=n={}),n[l]=a,i[l]=a.peek())}}e(t)});xn("__r",function(e,t){e(t),ai();var n,i=t.__c;i&&(i.__$f&=-2,(n=i.__$u)===void 0&&(i.__$u=n=function(l){var a;return lt(function(){a=this}),a.c=function(){i.__$f|=1,i.setState({})},a}())),Mi=i,ai(n)});xn("__e",function(e,t,n,i){ai(),Mi=void 0,e(t,n,i)});xn("diffed",function(e,t){ai(),Mi=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var i=t.__np,l=t.props;if(i){var a=n.U;if(a)for(var s in a){var o=a[s];o!==void 0&&!(s in i)&&(o.d(),a[s]=void 0)}else n.U=a={};for(var u in i){var c=a[u],f=i[u];c===void 0?(c=kh(n,u,f,l),a[u]=c):c.o(f,l)}}}e(t)});function kh(e,t,n,i){var l=t in e&&e.ownerSVGElement===void 0,a=H(n);return{o:function(s,o){a.value=s,i=o},d:lt(function(){var s=a.value.value;i[t]!==s&&(i[t]=s,l?e[t]=s:s?e.setAttribute(t,s):e.removeAttribute(t))})}}xn("unmount",function(e,t){if(typeof t.type=="string"){var n=t.__e;if(n){var i=n.U;if(i){n.U=void 0;for(var l in i){var a=i[l];a&&a.d()}}}}else{var s=t.__c;if(s){var o=s.__$u;o&&(s.__$u=void 0,o.d())}}e(t)});xn("__h",function(e,t,n,i){(i<3||i===9)&&(t.__$f|=2),e(t,n,i)});Hn.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,i=n&&n.s!==void 0;for(var l in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){if(!(i||2&this.__$f||4&this.__$f)||1&this.__$f)return!0}else if(!(i||4&this.__$f)||3&this.__$f)return!0;for(var a in e)if(a!=="__source"&&e[a]!==this.props[a])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function _c(e){return mr(function(){return H(e)},[])}function rl(e){var t=ne(e);return t.current=e,Mi.__$f|=4,mr(function(){return Vt(function(){return t.current()})},[])}const de=H([]),Li=H([]),Ii=H([]),Bt=H([]),mt=H(null),ds=H(""),Ll=H(null),er=H(null),Il=H("all"),tr=H(null),ke=H(null),Et=H(null),Oi=H(null),ha=H(null),at=H([]),si=H({}),Un=H(null),Wn=H(null),Kn=H(null),xc=H(null),fa=H([]),sn=H(null),Sc=H(""),$c=H(0),pa=H(null),Fr=H({}),Ft=H({}),Ne=H({}),Re=H({}),hs=H(0);let Cc=0;function wh(e){if(Date.now()-Cc<3e3)return;const t={},n={};for(const i of e){if(!i.pid)continue;const l=i.open_tabs||[];l.length&&(t[i.pid]=l.map(a=>({...a,target:i.target}))),i.active_tab&&i.active_tab!=="pane"&&(n[i.pid]=i.active_tab)}Ne.value=t,Re.value=n}function ma(e,t){Cc=Date.now(),fetch(`/api/pane/tabs/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}).catch(()=>{})}function gr(e){const t=tr.value;if(!t)return;const n=(de.value||[]).find(s=>s.target===t);if(!n)return;const i=n.pid,l=Ne.value[i]||[],a=l.find(s=>s.path===e.path);a?e.line&&e.line!==a.line&&(Ne.value={...Ne.value,[i]:l.map(s=>s.path===e.path?{...s,line:e.line}:s)}):Ne.value={...Ne.value,[i]:[...l,{...e,target:t}]},Re.value={...Re.value,[i]:`file:${e.path}`},ma("open",{pid:i,path:e.path,line:e.line??null})}function Tc(e,t){const i=(Ne.value[e]||[]).filter(l=>l.path!==t);Ne.value={...Ne.value,[e]:i},Re.value[e]===`file:${t}`&&(Re.value={...Re.value,[e]:"pane"}),ma("close",{pid:e,path:t})}function Nr(e,t){Re.value={...Re.value,[e]:t},ma("activate",{pid:e,tab:t})}const nr=H(new Set),ht=H(new Set),ft=H(new Set);function gn(e,t=at.value){var n;return((n=t.find(i=>i.id===e))==null?void 0:n.label)||e}function Sn(e=at.value){return e.length>1}function vh(e,t=at.value,n=si.value){if(!(e.agent==="claude"||e.is_claude))return null;const i=e.account||"default";if(!t.some(a=>a.id===i))return null;const l=n==null?void 0:n[i];return t.find(a=>a.id===l&&l!==i)||null}const on=[];function _h(e){e.key==="Escape"&&on.length&&(e.stopPropagation(),on[on.length-1](e))}typeof window<"u"&&window.addEventListener("keydown",_h,!0);function He(e,t=!0){j(()=>{if(t)return on.push(e),()=>{const n=on.indexOf(e);n>=0&&on.splice(n,1)}},[e,t])}const xh={};function Sh(e,t){const n=xh,i=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,l=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Ec(e,i,l)}function Ec(e,t,n){if($h(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return fs(e.children,t,n)}return Array.isArray(e)?fs(e,t,n):""}function fs(e,t,n){const i=[];let l=-1;for(;++ll?0:l+t:t=t>l?l:t,n=n>0?n:0,i.length<1e4)s=Array.from(i),s.unshift(t,n),e.splice(...s);else for(n&&e.splice(t,n);a0?(Ie(e,e.length,0,t),e):t}const ms={}.hasOwnProperty;function Pc(e){const t={};let n=-1;for(;++n13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function je(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const xe=wt(/[A-Za-z]/),Ee=wt(/[\dA-Za-z]/),Eh=wt(/[#-'*+\--9=?A-Z^-~]/);function oi(e){return e!==null&&(e<32||e===127)}const Ol=wt(/\d/),Ph=wt(/[\dA-Fa-f]/),Ah=wt(/[!-/:-@[-`{-~]/);function U(e){return e!==null&&e<-2}function oe(e){return e!==null&&(e<0||e===32)}function ee(e){return e===-2||e===-1||e===32}const Di=wt(new RegExp("\\p{P}|\\p{S}","u")),zt=wt(/\s/);function wt(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function re(e,t,n,i){const l=i?i-1:Number.POSITIVE_INFINITY;let a=0;return s;function s(u){return ee(u)?(e.enter(n),o(u)):t(u)}function o(u){return ee(u)&&a++s))return;const E=t.events.length;let A=E,T,S;for(;A--;)if(t.events[A][0]==="exit"&&t.events[A][1].type==="chunkFlow"){if(T){S=t.events[A][1].end;break}T=!0}for(w(i),v=E;vy;){const $=n[g];t.containerState=$[1],$[0].exit.call(t,e)}n.length=y}function C(){l.write([null]),a=void 0,l=void 0,t.containerState._closeFlow=void 0}}function Dh(e,t,n){return re(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function ci(e){if(e===null||oe(e)||zt(e))return 1;if(Di(e))return 2}function Ri(e,t,n){const i=[];let l=-1;for(;++l1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const d={...e[i][1].end},p={...e[n][1].start};ys(d,-u),ys(p,u),s={type:u>1?"strongSequence":"emphasisSequence",start:d,end:{...e[i][1].end}},o={type:u>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:p},a={type:u>1?"strongText":"emphasisText",start:{...e[i][1].end},end:{...e[n][1].start}},l={type:u>1?"strong":"emphasis",start:{...s.start},end:{...o.end}},e[i][1].end={...s.start},e[n][1].start={...o.end},c=[],e[i][1].end.offset-e[i][1].start.offset&&(c=De(c,[["enter",e[i][1],t],["exit",e[i][1],t]])),c=De(c,[["enter",l,t],["enter",s,t],["exit",s,t],["enter",a,t]]),c=De(c,Ri(t.parser.constructs.insideSpan.null,e.slice(i+1,n),t)),c=De(c,[["exit",a,t],["enter",o,t],["exit",o,t],["exit",l,t]]),e[n][1].end.offset-e[n][1].start.offset?(f=2,c=De(c,[["enter",e[n][1],t],["exit",e[n][1],t]])):f=0,Ie(e,i-1,n-i+3,c),n=i+c.length-f-2;break}}for(n=-1;++n0&&ee(v)?re(e,C,"linePrefix",a+1)(v):C(v)}function C(v){return v===null||U(v)?e.check(bs,b,g)(v):(e.enter("codeFlowValue"),y(v))}function y(v){return v===null||U(v)?(e.exit("codeFlowValue"),C(v)):(e.consume(v),y)}function g(v){return e.exit("codeFenced"),t(v)}function $(v,E,A){let T=0;return S;function S(I){return v.enter("lineEnding"),v.consume(I),v.exit("lineEnding"),R}function R(I){return v.enter("codeFencedFence"),ee(I)?re(v,F,"linePrefix",i.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(I):F(I)}function F(I){return I===o?(v.enter("codeFencedFenceSequence"),q(I)):A(I)}function q(I){return I===o?(T++,v.consume(I),q):T>=s?(v.exit("codeFencedFenceSequence"),ee(I)?re(v,L,"whitespace")(I):L(I)):A(I)}function L(I){return I===null||U(I)?(v.exit("codeFencedFence"),E(I)):A(I)}}}function Vh(e,t,n){const i=this;return l;function l(s){return s===null?n(s):(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),a)}function a(s){return i.parser.lazy[i.now().line]?n(s):t(s)}}const il={name:"codeIndented",tokenize:Jh},Gh={partial:!0,tokenize:Qh};function Jh(e,t,n){const i=this;return l;function l(c){return e.enter("codeIndented"),re(e,a,"linePrefix",5)(c)}function a(c){const f=i.events[i.events.length-1];return f&&f[1].type==="linePrefix"&&f[2].sliceSerialize(f[1],!0).length>=4?s(c):n(c)}function s(c){return c===null?u(c):U(c)?e.attempt(Gh,s,u)(c):(e.enter("codeFlowValue"),o(c))}function o(c){return c===null||U(c)?(e.exit("codeFlowValue"),s(c)):(e.consume(c),o)}function u(c){return e.exit("codeIndented"),t(c)}}function Qh(e,t,n){const i=this;return l;function l(s){return i.parser.lazy[i.now().line]?n(s):U(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),l):re(e,a,"linePrefix",5)(s)}function a(s){const o=i.events[i.events.length-1];return o&&o[1].type==="linePrefix"&&o[2].sliceSerialize(o[1],!0).length>=4?t(s):U(s)?l(s):n(s)}}const Yh={name:"codeText",previous:Xh,resolve:Zh,tokenize:ef};function Zh(e){let t=e.length-4,n=3,i,l;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(i=n;++i=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return tthis.left.length?this.right.slice(this.right.length-i+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-i+this.left.length).reverse())}splice(t,n,i){const l=n||0;this.setCursor(Math.trunc(t));const a=this.right.splice(this.right.length-l,Number.POSITIVE_INFINITY);return i&&An(this.left,i),a.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),An(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),An(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t=4?t(s):e.interrupt(i.parser.constructs.flow,n,t)(s)}}function Dc(e,t,n,i,l,a,s,o,u){const c=u||Number.POSITIVE_INFINITY;let f=0;return d;function d(w){return w===60?(e.enter(i),e.enter(l),e.enter(a),e.consume(w),e.exit(a),p):w===null||w===32||w===41||oi(w)?n(w):(e.enter(i),e.enter(s),e.enter(o),e.enter("chunkString",{contentType:"string"}),b(w))}function p(w){return w===62?(e.enter(a),e.consume(w),e.exit(a),e.exit(l),e.exit(i),t):(e.enter(o),e.enter("chunkString",{contentType:"string"}),h(w))}function h(w){return w===62?(e.exit("chunkString"),e.exit(o),p(w)):w===null||w===60||U(w)?n(w):(e.consume(w),w===92?m:h)}function m(w){return w===60||w===62||w===92?(e.consume(w),h):h(w)}function b(w){return!f&&(w===null||w===41||oe(w))?(e.exit("chunkString"),e.exit(o),e.exit(s),e.exit(i),t(w)):f999||h===null||h===91||h===93&&!u||h===94&&!o&&"_hiddenFootnoteSupport"in s.parser.constructs?n(h):h===93?(e.exit(a),e.enter(l),e.consume(h),e.exit(l),e.exit(i),t):U(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),f):(e.enter("chunkString",{contentType:"string"}),d(h))}function d(h){return h===null||h===91||h===93||U(h)||o++>999?(e.exit("chunkString"),f(h)):(e.consume(h),u||(u=!ee(h)),h===92?p:d)}function p(h){return h===91||h===92||h===93?(e.consume(h),o++,d):d(h)}}function Fc(e,t,n,i,l,a){let s;return o;function o(p){return p===34||p===39||p===40?(e.enter(i),e.enter(l),e.consume(p),e.exit(l),s=p===40?41:p,u):n(p)}function u(p){return p===s?(e.enter(l),e.consume(p),e.exit(l),e.exit(i),t):(e.enter(a),c(p))}function c(p){return p===s?(e.exit(a),u(s)):p===null?n(p):U(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),re(e,c,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===s||p===null||U(p)?(e.exit("chunkString"),c(p)):(e.consume(p),p===92?d:f)}function d(p){return p===s||p===92?(e.consume(p),f):f(p)}}function Vn(e,t){let n;return i;function i(l){return U(l)?(e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),n=!0,i):ee(l)?re(e,i,n?"linePrefix":"lineSuffix")(l):t(l)}}const cf={name:"definition",tokenize:df},uf={partial:!0,tokenize:hf};function df(e,t,n){const i=this;let l;return a;function a(h){return e.enter("definition"),s(h)}function s(h){return Rc.call(i,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function o(h){return l=je(i.sliceSerialize(i.events[i.events.length-1][1]).slice(1,-1)),h===58?(e.enter("definitionMarker"),e.consume(h),e.exit("definitionMarker"),u):n(h)}function u(h){return oe(h)?Vn(e,c)(h):c(h)}function c(h){return Dc(e,f,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function f(h){return e.attempt(uf,d,d)(h)}function d(h){return ee(h)?re(e,p,"whitespace")(h):p(h)}function p(h){return h===null||U(h)?(e.exit("definition"),i.parser.defined.push(l),t(h)):n(h)}}function hf(e,t,n){return i;function i(o){return oe(o)?Vn(e,l)(o):n(o)}function l(o){return Fc(e,a,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(o)}function a(o){return ee(o)?re(e,s,"whitespace")(o):s(o)}function s(o){return o===null||U(o)?t(o):n(o)}}const ff={name:"hardBreakEscape",tokenize:pf};function pf(e,t,n){return i;function i(a){return e.enter("hardBreakEscape"),e.consume(a),l}function l(a){return U(a)?(e.exit("hardBreakEscape"),t(a)):n(a)}}const mf={name:"headingAtx",resolve:gf,tokenize:yf};function gf(e,t){let n=e.length-2,i=3,l,a;return e[i][1].type==="whitespace"&&(i+=2),n-2>i&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(i===n-1||n-4>i&&e[n-2][1].type==="whitespace")&&(n-=i+1===n?2:4),n>i&&(l={type:"atxHeadingText",start:e[i][1].start,end:e[n][1].end},a={type:"chunkText",start:e[i][1].start,end:e[n][1].end,contentType:"text"},Ie(e,i,n-i+1,[["enter",l,t],["enter",a,t],["exit",a,t],["exit",l,t]])),e}function yf(e,t,n){let i=0;return l;function l(f){return e.enter("atxHeading"),a(f)}function a(f){return e.enter("atxHeadingSequence"),s(f)}function s(f){return f===35&&i++<6?(e.consume(f),s):f===null||oe(f)?(e.exit("atxHeadingSequence"),o(f)):n(f)}function o(f){return f===35?(e.enter("atxHeadingSequence"),u(f)):f===null||U(f)?(e.exit("atxHeading"),t(f)):ee(f)?re(e,o,"whitespace")(f):(e.enter("atxHeadingText"),c(f))}function u(f){return f===35?(e.consume(f),u):(e.exit("atxHeadingSequence"),o(f))}function c(f){return f===null||f===35||oe(f)?(e.exit("atxHeadingText"),o(f)):(e.consume(f),c)}}const bf=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],ws=["pre","script","style","textarea"],kf={concrete:!0,name:"htmlFlow",resolveTo:_f,tokenize:xf},wf={partial:!0,tokenize:$f},vf={partial:!0,tokenize:Sf};function _f(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function xf(e,t,n){const i=this;let l,a,s,o,u;return c;function c(_){return f(_)}function f(_){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(_),d}function d(_){return _===33?(e.consume(_),p):_===47?(e.consume(_),a=!0,b):_===63?(e.consume(_),l=3,i.interrupt?t:k):xe(_)?(e.consume(_),s=String.fromCharCode(_),x):n(_)}function p(_){return _===45?(e.consume(_),l=2,h):_===91?(e.consume(_),l=5,o=0,m):xe(_)?(e.consume(_),l=4,i.interrupt?t:k):n(_)}function h(_){return _===45?(e.consume(_),i.interrupt?t:k):n(_)}function m(_){const X="CDATA[";return _===X.charCodeAt(o++)?(e.consume(_),o===X.length?i.interrupt?t:F:m):n(_)}function b(_){return xe(_)?(e.consume(_),s=String.fromCharCode(_),x):n(_)}function x(_){if(_===null||_===47||_===62||oe(_)){const X=_===47,he=s.toLowerCase();return!X&&!a&&ws.includes(he)?(l=1,i.interrupt?t(_):F(_)):bf.includes(s.toLowerCase())?(l=6,X?(e.consume(_),w):i.interrupt?t(_):F(_)):(l=7,i.interrupt&&!i.parser.lazy[i.now().line]?n(_):a?C(_):y(_))}return _===45||Ee(_)?(e.consume(_),s+=String.fromCharCode(_),x):n(_)}function w(_){return _===62?(e.consume(_),i.interrupt?t:F):n(_)}function C(_){return ee(_)?(e.consume(_),C):S(_)}function y(_){return _===47?(e.consume(_),S):_===58||_===95||xe(_)?(e.consume(_),g):ee(_)?(e.consume(_),y):S(_)}function g(_){return _===45||_===46||_===58||_===95||Ee(_)?(e.consume(_),g):$(_)}function $(_){return _===61?(e.consume(_),v):ee(_)?(e.consume(_),$):y(_)}function v(_){return _===null||_===60||_===61||_===62||_===96?n(_):_===34||_===39?(e.consume(_),u=_,E):ee(_)?(e.consume(_),v):A(_)}function E(_){return _===u?(e.consume(_),u=null,T):_===null||U(_)?n(_):(e.consume(_),E)}function A(_){return _===null||_===34||_===39||_===47||_===60||_===61||_===62||_===96||oe(_)?$(_):(e.consume(_),A)}function T(_){return _===47||_===62||ee(_)?y(_):n(_)}function S(_){return _===62?(e.consume(_),R):n(_)}function R(_){return _===null||U(_)?F(_):ee(_)?(e.consume(_),R):n(_)}function F(_){return _===45&&l===2?(e.consume(_),O):_===60&&l===1?(e.consume(_),Q):_===62&&l===4?(e.consume(_),W):_===63&&l===3?(e.consume(_),k):_===93&&l===5?(e.consume(_),z):U(_)&&(l===6||l===7)?(e.exit("htmlFlowData"),e.check(wf,Z,q)(_)):_===null||U(_)?(e.exit("htmlFlowData"),q(_)):(e.consume(_),F)}function q(_){return e.check(vf,L,Z)(_)}function L(_){return e.enter("lineEnding"),e.consume(_),e.exit("lineEnding"),I}function I(_){return _===null||U(_)?q(_):(e.enter("htmlFlowData"),F(_))}function O(_){return _===45?(e.consume(_),k):F(_)}function Q(_){return _===47?(e.consume(_),s="",M):F(_)}function M(_){if(_===62){const X=s.toLowerCase();return ws.includes(X)?(e.consume(_),W):F(_)}return xe(_)&&s.length<8?(e.consume(_),s+=String.fromCharCode(_),M):F(_)}function z(_){return _===93?(e.consume(_),k):F(_)}function k(_){return _===62?(e.consume(_),W):_===45&&l===2?(e.consume(_),k):F(_)}function W(_){return _===null||U(_)?(e.exit("htmlFlowData"),Z(_)):(e.consume(_),W)}function Z(_){return e.exit("htmlFlow"),t(_)}}function Sf(e,t,n){const i=this;return l;function l(s){return U(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),a):n(s)}function a(s){return i.parser.lazy[i.now().line]?n(s):t(s)}}function $f(e,t,n){return i;function i(l){return e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),e.attempt(yr,t,n)}}const Cf={name:"htmlText",tokenize:Tf};function Tf(e,t,n){const i=this;let l,a,s;return o;function o(k){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(k),u}function u(k){return k===33?(e.consume(k),c):k===47?(e.consume(k),$):k===63?(e.consume(k),y):xe(k)?(e.consume(k),A):n(k)}function c(k){return k===45?(e.consume(k),f):k===91?(e.consume(k),a=0,m):xe(k)?(e.consume(k),C):n(k)}function f(k){return k===45?(e.consume(k),h):n(k)}function d(k){return k===null?n(k):k===45?(e.consume(k),p):U(k)?(s=d,Q(k)):(e.consume(k),d)}function p(k){return k===45?(e.consume(k),h):d(k)}function h(k){return k===62?O(k):k===45?p(k):d(k)}function m(k){const W="CDATA[";return k===W.charCodeAt(a++)?(e.consume(k),a===W.length?b:m):n(k)}function b(k){return k===null?n(k):k===93?(e.consume(k),x):U(k)?(s=b,Q(k)):(e.consume(k),b)}function x(k){return k===93?(e.consume(k),w):b(k)}function w(k){return k===62?O(k):k===93?(e.consume(k),w):b(k)}function C(k){return k===null||k===62?O(k):U(k)?(s=C,Q(k)):(e.consume(k),C)}function y(k){return k===null?n(k):k===63?(e.consume(k),g):U(k)?(s=y,Q(k)):(e.consume(k),y)}function g(k){return k===62?O(k):y(k)}function $(k){return xe(k)?(e.consume(k),v):n(k)}function v(k){return k===45||Ee(k)?(e.consume(k),v):E(k)}function E(k){return U(k)?(s=E,Q(k)):ee(k)?(e.consume(k),E):O(k)}function A(k){return k===45||Ee(k)?(e.consume(k),A):k===47||k===62||oe(k)?T(k):n(k)}function T(k){return k===47?(e.consume(k),O):k===58||k===95||xe(k)?(e.consume(k),S):U(k)?(s=T,Q(k)):ee(k)?(e.consume(k),T):O(k)}function S(k){return k===45||k===46||k===58||k===95||Ee(k)?(e.consume(k),S):R(k)}function R(k){return k===61?(e.consume(k),F):U(k)?(s=R,Q(k)):ee(k)?(e.consume(k),R):T(k)}function F(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(e.consume(k),l=k,q):U(k)?(s=F,Q(k)):ee(k)?(e.consume(k),F):(e.consume(k),L)}function q(k){return k===l?(e.consume(k),l=void 0,I):k===null?n(k):U(k)?(s=q,Q(k)):(e.consume(k),q)}function L(k){return k===null||k===34||k===39||k===60||k===61||k===96?n(k):k===47||k===62||oe(k)?T(k):(e.consume(k),L)}function I(k){return k===47||k===62||oe(k)?T(k):n(k)}function O(k){return k===62?(e.consume(k),e.exit("htmlTextData"),e.exit("htmlText"),t):n(k)}function Q(k){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),M}function M(k){return ee(k)?re(e,z,"linePrefix",i.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):z(k)}function z(k){return e.enter("htmlTextData"),s(k)}}const ya={name:"labelEnd",resolveAll:Mf,resolveTo:Lf,tokenize:If},Ef={tokenize:Of},Pf={tokenize:Df},Af={tokenize:Rf};function Mf(e){let t=-1;const n=[];for(;++t=3&&(c===null||U(c))?(e.exit("thematicBreak"),t(c)):n(c)}function u(c){return c===l?(e.consume(c),i++,u):(e.exit("thematicBreakSequence"),ee(c)?re(e,o,"whitespace")(c):o(c))}}const Te={continuation:{tokenize:Kf},exit:Gf,name:"list",tokenize:Wf},qf={partial:!0,tokenize:Jf},Uf={partial:!0,tokenize:Vf};function Wf(e,t,n){const i=this,l=i.events[i.events.length-1];let a=l&&l[1].type==="linePrefix"?l[2].sliceSerialize(l[1],!0).length:0,s=0;return o;function o(h){const m=i.containerState.type||(h===42||h===43||h===45?"listUnordered":"listOrdered");if(m==="listUnordered"?!i.containerState.marker||h===i.containerState.marker:Ol(h)){if(i.containerState.type||(i.containerState.type=m,e.enter(m,{_container:!0})),m==="listUnordered")return e.enter("listItemPrefix"),h===42||h===45?e.check(Br,n,c)(h):c(h);if(!i.interrupt||h===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),u(h)}return n(h)}function u(h){return Ol(h)&&++s<10?(e.consume(h),u):(!i.interrupt||s<2)&&(i.containerState.marker?h===i.containerState.marker:h===41||h===46)?(e.exit("listItemValue"),c(h)):n(h)}function c(h){return e.enter("listItemMarker"),e.consume(h),e.exit("listItemMarker"),i.containerState.marker=i.containerState.marker||h,e.check(yr,i.interrupt?n:f,e.attempt(qf,p,d))}function f(h){return i.containerState.initialBlankLine=!0,a++,p(h)}function d(h){return ee(h)?(e.enter("listItemPrefixWhitespace"),e.consume(h),e.exit("listItemPrefixWhitespace"),p):n(h)}function p(h){return i.containerState.size=a+i.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(h)}}function Kf(e,t,n){const i=this;return i.containerState._closeFlow=void 0,e.check(yr,l,a);function l(o){return i.containerState.furtherBlankLines=i.containerState.furtherBlankLines||i.containerState.initialBlankLine,re(e,t,"listItemIndent",i.containerState.size+1)(o)}function a(o){return i.containerState.furtherBlankLines||!ee(o)?(i.containerState.furtherBlankLines=void 0,i.containerState.initialBlankLine=void 0,s(o)):(i.containerState.furtherBlankLines=void 0,i.containerState.initialBlankLine=void 0,e.attempt(Uf,t,s)(o))}function s(o){return i.containerState._closeFlow=!0,i.interrupt=void 0,re(e,e.attempt(Te,t,n),"linePrefix",i.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o)}}function Vf(e,t,n){const i=this;return re(e,l,"listItemIndent",i.containerState.size+1);function l(a){const s=i.events[i.events.length-1];return s&&s[1].type==="listItemIndent"&&s[2].sliceSerialize(s[1],!0).length===i.containerState.size?t(a):n(a)}}function Gf(e){e.exit(this.containerState.type)}function Jf(e,t,n){const i=this;return re(e,l,"listItemPrefixWhitespace",i.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function l(a){const s=i.events[i.events.length-1];return!ee(a)&&s&&s[1].type==="listItemPrefixWhitespace"?t(a):n(a)}}const vs={name:"setextUnderline",resolveTo:Qf,tokenize:Yf};function Qf(e,t){let n=e.length,i,l,a;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){i=n;break}e[n][1].type==="paragraph"&&(l=n)}else e[n][1].type==="content"&&e.splice(n,1),!a&&e[n][1].type==="definition"&&(a=n);const s={type:"setextHeading",start:{...e[i][1].start},end:{...e[e.length-1][1].end}};return e[l][1].type="setextHeadingText",a?(e.splice(l,0,["enter",s,t]),e.splice(a+1,0,["exit",e[i][1],t]),e[i][1].end={...e[a][1].end}):e[i][1]=s,e.push(["exit",s,t]),e}function Yf(e,t,n){const i=this;let l;return a;function a(c){let f=i.events.length,d;for(;f--;)if(i.events[f][1].type!=="lineEnding"&&i.events[f][1].type!=="linePrefix"&&i.events[f][1].type!=="content"){d=i.events[f][1].type==="paragraph";break}return!i.parser.lazy[i.now().line]&&(i.interrupt||d)?(e.enter("setextHeadingLine"),l=c,s(c)):n(c)}function s(c){return e.enter("setextHeadingLineSequence"),o(c)}function o(c){return c===l?(e.consume(c),o):(e.exit("setextHeadingLineSequence"),ee(c)?re(e,u,"lineSuffix")(c):u(c))}function u(c){return c===null||U(c)?(e.exit("setextHeadingLine"),t(c)):n(c)}}const Zf={tokenize:Xf};function Xf(e){const t=this,n=e.attempt(yr,i,e.attempt(this.parser.constructs.flowInitial,l,re(e,e.attempt(this.parser.constructs.flow,l,e.attempt(rf,l)),"linePrefix")));return n;function i(a){if(a===null){e.consume(a);return}return e.enter("lineEndingBlank"),e.consume(a),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function l(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const ep={resolveAll:Bc()},tp=Nc("string"),np=Nc("text");function Nc(e){return{resolveAll:Bc(e==="text"?rp:void 0),tokenize:t};function t(n){const i=this,l=this.parser.constructs[e],a=n.attempt(l,s,o);return s;function s(f){return c(f)?a(f):o(f)}function o(f){if(f===null){n.consume(f);return}return n.enter("data"),n.consume(f),u}function u(f){return c(f)?(n.exit("data"),a(f)):(n.consume(f),u)}function c(f){if(f===null)return!0;const d=l[f];let p=-1;if(d)for(;++p-1){const o=s[0];typeof o=="string"?s[0]=o.slice(i):s.shift()}a>0&&s.push(e[l].slice(0,a))}return s}function gp(e,t){let n=-1;const i=[];let l;for(;++n2&&(s.children=arguments.length>3?Ai.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(a in e.defaultProps)s[a]===void 0&&(s[a]=e.defaultProps[a]);return Nr(e,s,i,l,null)}function Nr(e,t,n,i,l){var a={type:e,props:t,key:n,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:l??++lc,__i:-1,__u:0};return l==null&&le.vnode!=null&&le.vnode(a),a}function K(e){return e.children}function Un(e,t){this.props=e,this.context=t}function gn(e,t){if(t==null)return e.__?gn(e.__,e.__i+1):null;for(var n;tt&&dt.sort(oc),e=dt.shift(),t=dt.length,hh(e)}finally{dt.length=li.__r=0}}function dc(e,t,n,i,l,a,s,o,u,c,p){var d,f,h,m,b,x,w,C=i&&i.__k||ii,y=t.length;for(u=fh(n,t,C,u,y),d=0;d0?s=e.__k[a]=Nr(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):e.__k[a]=s,u=a+f,s.__=e,s.__b=e.__b+1,o=null,(c=s.__i=ph(s,n,u,d))!=-1&&(d--,(o=n[c])&&(o.__u|=2)),o==null||o.__v==null?(c==-1&&(l>p?f--:lu?f--:f++,s.__u|=4))):e.__k[a]=null;if(d)for(a=0;a(p?1:0)){for(l=n-1,a=n+1;l>=0||a=0?l--:a++])!=null&&!(2&c.__u)&&o==c.key&&u==c.type)return s}return-1}function rs(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||uh.test(t)?n:n+"px"}function Cr(e,t,n,i,l){var a,s;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof i=="string"&&(e.style.cssText=i=""),i)for(t in i)n&&t in n||rs(e.style,t,"");if(n)for(t in n)i&&n[t]==i[t]||rs(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(cc,"$1")),s=t.toLowerCase(),t=s in e||t=="onFocusOut"||t=="onFocusIn"?s.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+a]=n,n?i?n[qn]=i[qn]:(n[qn]=oa,e.addEventListener(t,a?Ll:Ml,a)):e.removeEventListener(t,a?Ll:Ml,a);else{if(l=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function is(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[Fr]==null)t[Fr]=oa++;else if(t[Fr]0?e:Mi(e)?e.map(pc):e.constructor!==void 0?null:Xe({},e)}function mh(e,t,n,i,l,a,s,o,u){var c,p,d,f,h,m,b,x=n.props||ri,w=t.props,C=t.type;if(C=="svg"?l="http://www.w3.org/2000/svg":C=="math"?l="http://www.w3.org/1998/Math/MathML":l||(l="http://www.w3.org/1999/xhtml"),a!=null){for(c=0;c=n.__.length&&n.__.push({}),n.__[e]}function B(e){return tr=1,kh(bc,e)}function kh(e,t,n){var i=ha(er++,2);if(i.t=e,!i.__c&&(i.__=[bc(void 0,t),function(o){var u=i.__N?i.__N[0]:i.__[0],c=i.t(u,o);u!==c&&(i.__N=[c,i.__[1]],i.__c.setState({}))}],i.__c=pe,!pe.__f)){var l=function(o,u,c){if(!i.__c.__H)return!0;var p=i.__c.__H.__.filter(function(f){return f.__c});if(p.every(function(f){return!f.__N}))return!a||a.call(this,o,u,c);var d=i.__c.props!==o;return p.some(function(f){if(f.__N){var h=f.__[0];f.__=f.__N,f.__N=void 0,h!==f.__[0]&&(d=!0)}}),a&&a.call(this,o,u,c)||d};pe.__f=!0;var a=pe.shouldComponentUpdate,s=pe.componentWillUpdate;pe.componentWillUpdate=function(o,u,c){if(this.__e){var p=a;a=void 0,l(o,u,c),a=p}s&&s.call(this,o,u,c)},pe.shouldComponentUpdate=l}return i.__N||i.__}function j(e,t){var n=ha(er++,3);!ge.__s&&yc(n.__H,t)&&(n.__=e,n.u=t,pe.__H.__h.push(n))}function te(e){return tr=5,yr(function(){return{current:e}},[])}function yr(e,t){var n=ha(er++,7);return yc(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function br(e,t){return tr=8,yr(function(){return e},t)}function wh(){for(var e;e=gc.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Br),t.__h.some(Ol),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){pe=null,as&&as(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ds&&ds(e,t)},ge.__r=function(e){ss&&ss(e),er=0;var t=(pe=e.__c).__H;t&&(ll===pe?(t.__h=[],pe.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(Br),t.__h.some(Ol),t.__h=[],er=0)),ll=pe},ge.diffed=function(e){os&&os(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(gc.push(t)!==1&&ls===ge.requestAnimationFrame||((ls=ge.requestAnimationFrame)||vh)(wh)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ll=pe=null},ge.__c=function(e,t){t.some(function(n){try{n.__h.some(Br),n.__h=n.__h.filter(function(i){return!i.__||Ol(i)})}catch(i){t.some(function(l){l.__h&&(l.__h=[])}),t=[],ge.__e(i,n.__v)}}),cs&&cs(e,t)},ge.unmount=function(e){us&&us(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(i){try{Br(i)}catch(l){t=l}}),n.__H=void 0,t&&ge.__e(t,n.__v))};var hs=typeof requestAnimationFrame=="function";function vh(e){var t,n=function(){clearTimeout(i),hs&&cancelAnimationFrame(t),setTimeout(e)},i=setTimeout(n,35);hs&&(t=requestAnimationFrame(n))}function Br(e){var t=pe,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),pe=t}function Ol(e){var t=pe;e.__c=e.__(),pe=t}function yc(e,t){return!e||e.length!==t.length||t.some(function(n,i){return n!==e[i]})}function bc(e,t){return typeof t=="function"?t(e):t}var _h=Symbol.for("preact-signals");function fa(){if(Rt>1)Rt--;else{var e,t=!1;for(function(){var l=si;for(si=void 0;l!==void 0;)l.S.v===l.v&&(l.S.i=l.i),l=l.o}();Wn!==void 0;){var n=Wn;for(Wn=void 0,ai++;n!==void 0;){var i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&wc(n))try{n.c()}catch(l){t||(e=l,t=!0)}n=i}}if(ai=0,Rt--,t)throw e}}var se=void 0;function Li(e){var t=se;se=void 0;try{return e()}finally{se=t}}var Wn=void 0,Rt=0,ai=0,fs=0,si=void 0,oi=0;function kc(e){if(se!==void 0){var t=e.n;if(t===void 0||t.t!==se)return t={i:0,S:e,p:se.s,n:void 0,t:se,e:void 0,x:void 0,r:t},se.s!==void 0&&(se.s.n=t),se.s=t,e.n=t,32&se.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=se.s,t.n=void 0,se.s.n=t,se.s=t),t}}function ve(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}ve.prototype.brand=_h;ve.prototype.h=function(){return!0};ve.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:Li(function(){var i;(i=t.W)==null||i.call(t)}))};ve.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,i=e.x;n!==void 0&&(n.x=i,e.e=void 0),i!==void 0&&(i.e=n,e.x=void 0),e===this.t&&(this.t=i,i===void 0&&Li(function(){var l;(l=t.Z)==null||l.call(t)}))}};ve.prototype.subscribe=function(e){var t=this;return it(function(){var n=t.value,i=se;se=void 0;try{e(n)}finally{se=i}},{name:"sub"})};ve.prototype.valueOf=function(){return this.value};ve.prototype.toString=function(){return this.value+""};ve.prototype.toJSON=function(){return this.value};ve.prototype.peek=function(){var e=this;return Li(function(){return e.value})};Object.defineProperty(ve.prototype,"value",{get:function(){var e=kc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ai>100)throw new Error("Cycle detected");(function(n){Rt!==0&&ai===0&&n.l!==fs&&(n.l=fs,si={S:n,v:n.v,i:n.i,o:si})})(this),this.v=e,this.i++,oi++,Rt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{fa()}}}});function H(e,t){return new ve(e,t)}function wc(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function vc(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function _c(e){for(var t=e.s,n=void 0;t!==void 0;){var i=t.p;t.i===-1?(t.S.U(t),i!==void 0&&(i.n=t.n),t.n!==void 0&&(t.n.p=i)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=i}e.s=n}function Kt(e,t){ve.call(this,void 0),this.x=e,this.s=void 0,this.g=oi-1,this.f=4,this.W=t==null?void 0:t.watched,this.Z=t==null?void 0:t.unwatched,this.name=t==null?void 0:t.name}Kt.prototype=new ve;Kt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===oi))return!0;if(this.g=oi,this.f|=1,this.i>0&&!wc(this))return this.f&=-2,!0;var e=se;try{vc(this),se=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return se=e,_c(this),this.f&=-2,!0};Kt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}ve.prototype.S.call(this,e)};Kt.prototype.U=function(e){if(this.t!==void 0&&(ve.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};Kt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(Kt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=kc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Vt(e,t){return new Kt(e,t)}function xc(e){var t=e.m;if(e.m=void 0,typeof t=="function"){Rt++;var n=se;se=void 0;try{t()}catch(i){throw e.f&=-2,e.f|=8,pa(e),i}finally{se=n,fa()}}}function pa(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,xc(e)}function xh(e){if(se!==this)throw new Error("Out-of-order effect");_c(this),se=e,this.f&=-2,8&this.f&&pa(this),fa()}function xn(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t==null?void 0:t.name}xn.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};xn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,xc(this),vc(this),Rt++;var e=se;return se=this,xh.bind(this,e)};xn.prototype.N=function(){2&this.f||(this.f|=2,this.u=Wn,Wn=this)};xn.prototype.d=function(){this.f|=8,1&this.f||pa(this)};xn.prototype.dispose=function(){this.d()};function it(e,t){var n=new xn(e,t);try{n.c()}catch(l){throw n.d(),l}var i=n.d.bind(n);return i[Symbol.dispose]=i,i}var Ii,Tr;function Sn(e,t){le[e]=t.bind(null,le[e]||function(){})}function ci(e){if(Tr){var t=Tr;Tr=void 0,t()}Tr=e&&e.S()}function Sc(e){var t=this,n=e.data,i=$c(n);i.value=n;var l=yr(function(){for(var a=t.__v;a=a.__;)if(a.__c){a.__c.__$f|=4;break}return t.__$u.c=function(){var s,o=t.__$u.S(),u=l.value;o(),ac(u)||((s=t.base)==null?void 0:s.nodeType)!==3?(t.__$f|=1,t.setState({})):t.base.data=u},Vt(function(){var s=i.value.value;return s===0?0:s===!0?"":s||""})},[]);return l.value}Sc.displayName="_st";Object.defineProperties(ve.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Sc},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});Sn("__b",function(e,t){if(typeof t.type=="string"){var n,i=t.props;for(var l in i)if(l!=="children"){var a=i[l];a instanceof ve&&(n||(t.__np=n={}),n[l]=a,i[l]=a.peek())}}e(t)});Sn("__r",function(e,t){e(t),ci();var n,i=t.__c;i&&(i.__$f&=-2,(n=i.__$u)===void 0&&(i.__$u=n=function(l){var a;return it(function(){a=this}),a.c=function(){i.__$f|=1,i.setState({})},a}())),Ii=i,ci(n)});Sn("__e",function(e,t,n,i){ci(),Ii=void 0,e(t,n,i)});Sn("diffed",function(e,t){ci(),Ii=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var i=t.__np,l=t.props;if(i){var a=n.U;if(a)for(var s in a){var o=a[s];o!==void 0&&!(s in i)&&(o.d(),a[s]=void 0)}else n.U=a={};for(var u in i){var c=a[u],p=i[u];c===void 0?(c=Sh(n,u,p,l),a[u]=c):c.o(p,l)}}}e(t)});function Sh(e,t,n,i){var l=t in e&&e.ownerSVGElement===void 0,a=H(n);return{o:function(s,o){a.value=s,i=o},d:it(function(){var s=a.value.value;i[t]!==s&&(i[t]=s,l?e[t]=s:s?e.setAttribute(t,s):e.removeAttribute(t))})}}Sn("unmount",function(e,t){if(typeof t.type=="string"){var n=t.__e;if(n){var i=n.U;if(i){n.U=void 0;for(var l in i){var a=i[l];a&&a.d()}}}}else{var s=t.__c;if(s){var o=s.__$u;o&&(s.__$u=void 0,o.d())}}e(t)});Sn("__h",function(e,t,n,i){(i<3||i===9)&&(t.__$f|=2),e(t,n,i)});Un.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,i=n&&n.s!==void 0;for(var l in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){if(!(i||2&this.__$f||4&this.__$f)||1&this.__$f)return!0}else if(!(i||4&this.__$f)||3&this.__$f)return!0;for(var a in e)if(a!=="__source"&&e[a]!==this.props[a])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function $c(e){return yr(function(){return H(e)},[])}function al(e){var t=te(e);return t.current=e,Ii.__$f|=4,yr(function(){return Vt(function(){return t.current()})},[])}const ce=H([]),Oi=H([]),Di=H([]),Bt=H([]),gt=H(null),ps=H(""),Dl=H(null),nr=H(null),Rl=H("all"),rr=H(null),ke=H(null),Et=H(null),Ri=H(null),ma=H(null),Cc=H(null),lt=H([]),ui=H({}),Kn=H(null),Vn=H(null),Gn=H(null),Tc=H(null),ga=H([]),sn=H(null),Ec=H(""),Pc=H(0),ya=H(null),zr=H({}),Ft=H({}),Ne=H({}),Re=H({}),ms=H(0);let Ac=0;function $h(e){if(Date.now()-Ac<3e3)return;const t={},n={};for(const i of e){if(!i.pid)continue;const l=i.open_tabs||[];l.length&&(t[i.pid]=l.map(a=>({...a,target:i.target}))),i.active_tab&&i.active_tab!=="pane"&&(n[i.pid]=i.active_tab)}Ne.value=t,Re.value=n}function ba(e,t){Ac=Date.now(),fetch(`/api/pane/tabs/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}).catch(()=>{})}function kr(e){const t=rr.value;if(!t)return;const n=(ce.value||[]).find(s=>s.target===t);if(!n)return;const i=n.pid,l=Ne.value[i]||[],a=l.find(s=>s.path===e.path);a?e.line&&e.line!==a.line&&(Ne.value={...Ne.value,[i]:l.map(s=>s.path===e.path?{...s,line:e.line}:s)}):Ne.value={...Ne.value,[i]:[...l,{...e,target:t}]},Re.value={...Re.value,[i]:`file:${e.path}`},ba("open",{pid:i,path:e.path,line:e.line??null})}function Mc(e,t){const i=(Ne.value[e]||[]).filter(l=>l.path!==t);Ne.value={...Ne.value,[e]:i},Re.value[e]===`file:${t}`&&(Re.value={...Re.value,[e]:"pane"}),ba("close",{pid:e,path:t})}function jr(e,t){Re.value={...Re.value,[e]:t},ba("activate",{pid:e,tab:t})}const ir=H(new Set),ft=H(new Set),pt=H(new Set);function yn(e,t=lt.value){var n;return((n=t.find(i=>i.id===e))==null?void 0:n.label)||e}function $n(e=lt.value){return e.length>1}function Ch(e,t=lt.value,n=ui.value){if(!(e.agent==="claude"||e.is_claude))return null;const i=e.account||"default";if(!t.some(a=>a.id===i))return null;const l=n==null?void 0:n[i];return t.find(a=>a.id===l&&l!==i)||null}const on=[];function Th(e){e.key==="Escape"&&on.length&&(e.stopPropagation(),on[on.length-1](e))}typeof window<"u"&&window.addEventListener("keydown",Th,!0);function ot(e,t=!0){j(()=>{if(t)return on.push(e),()=>{const n=on.indexOf(e);n>=0&&on.splice(n,1)}},[e,t])}function Fi(e,t,n){ot(n,t),j(()=>{if(!t)return;function i(l){e.current&&!e.current.contains(l.target)&&n()}return document.addEventListener("click",i),()=>document.removeEventListener("click",i)},[t,n])}const Eh={};function Ph(e,t){const n=Eh,i=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,l=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Lc(e,i,l)}function Lc(e,t,n){if(Ah(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return gs(e.children,t,n)}return Array.isArray(e)?gs(e,t,n):""}function gs(e,t,n){const i=[];let l=-1;for(;++ll?0:l+t:t=t>l?l:t,n=n>0?n:0,i.length<1e4)s=Array.from(i),s.unshift(t,n),e.splice(...s);else for(n&&e.splice(t,n);a0?(Ie(e,e.length,0,t),e):t}const bs={}.hasOwnProperty;function Ic(e){const t={};let n=-1;for(;++n13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function je(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Se=wt(/[A-Za-z]/),Ee=wt(/[\dA-Za-z]/),Ih=wt(/[#-'*+\--9=?A-Z^-~]/);function di(e){return e!==null&&(e<32||e===127)}const Fl=wt(/\d/),Oh=wt(/[\dA-Fa-f]/),Dh=wt(/[!-/:-@[-`{-~]/);function U(e){return e!==null&&e<-2}function oe(e){return e!==null&&(e<0||e===32)}function ee(e){return e===-2||e===-1||e===32}const Ni=wt(new RegExp("\\p{P}|\\p{S}","u")),zt=wt(/\s/);function wt(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function re(e,t,n,i){const l=i?i-1:Number.POSITIVE_INFINITY;let a=0;return s;function s(u){return ee(u)?(e.enter(n),o(u)):t(u)}function o(u){return ee(u)&&a++s))return;const E=t.events.length;let M=E,T,S;for(;M--;)if(t.events[M][0]==="exit"&&t.events[M][1].type==="chunkFlow"){if(T){S=t.events[M][1].end;break}T=!0}for(w(i),v=E;vy;){const $=n[g];t.containerState=$[1],$[0].exit.call(t,e)}n.length=y}function C(){l.write([null]),a=void 0,l=void 0,t.containerState._closeFlow=void 0}}function zh(e,t,n){return re(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function hi(e){if(e===null||oe(e)||zt(e))return 1;if(Ni(e))return 2}function Bi(e,t,n){const i=[];let l=-1;for(;++l1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const d={...e[i][1].end},f={...e[n][1].start};ws(d,-u),ws(f,u),s={type:u>1?"strongSequence":"emphasisSequence",start:d,end:{...e[i][1].end}},o={type:u>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:f},a={type:u>1?"strongText":"emphasisText",start:{...e[i][1].end},end:{...e[n][1].start}},l={type:u>1?"strong":"emphasis",start:{...s.start},end:{...o.end}},e[i][1].end={...s.start},e[n][1].start={...o.end},c=[],e[i][1].end.offset-e[i][1].start.offset&&(c=De(c,[["enter",e[i][1],t],["exit",e[i][1],t]])),c=De(c,[["enter",l,t],["enter",s,t],["exit",s,t],["enter",a,t]]),c=De(c,Bi(t.parser.constructs.insideSpan.null,e.slice(i+1,n),t)),c=De(c,[["exit",a,t],["enter",o,t],["exit",o,t],["exit",l,t]]),e[n][1].end.offset-e[n][1].start.offset?(p=2,c=De(c,[["enter",e[n][1],t],["exit",e[n][1],t]])):p=0,Ie(e,i-1,n-i+3,c),n=i+c.length-p-2;break}}for(n=-1;++n0&&ee(v)?re(e,C,"linePrefix",a+1)(v):C(v)}function C(v){return v===null||U(v)?e.check(vs,b,g)(v):(e.enter("codeFlowValue"),y(v))}function y(v){return v===null||U(v)?(e.exit("codeFlowValue"),C(v)):(e.consume(v),y)}function g(v){return e.exit("codeFenced"),t(v)}function $(v,E,M){let T=0;return S;function S(I){return v.enter("lineEnding"),v.consume(I),v.exit("lineEnding"),R}function R(I){return v.enter("codeFencedFence"),ee(I)?re(v,F,"linePrefix",i.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(I):F(I)}function F(I){return I===o?(v.enter("codeFencedFenceSequence"),q(I)):M(I)}function q(I){return I===o?(T++,v.consume(I),q):T>=s?(v.exit("codeFencedFenceSequence"),ee(I)?re(v,L,"whitespace")(I):L(I)):M(I)}function L(I){return I===null||U(I)?(v.exit("codeFencedFence"),E(I)):M(I)}}}function Zh(e,t,n){const i=this;return l;function l(s){return s===null?n(s):(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),a)}function a(s){return i.parser.lazy[i.now().line]?n(s):t(s)}}const sl={name:"codeIndented",tokenize:ef},Xh={partial:!0,tokenize:tf};function ef(e,t,n){const i=this;return l;function l(c){return e.enter("codeIndented"),re(e,a,"linePrefix",5)(c)}function a(c){const p=i.events[i.events.length-1];return p&&p[1].type==="linePrefix"&&p[2].sliceSerialize(p[1],!0).length>=4?s(c):n(c)}function s(c){return c===null?u(c):U(c)?e.attempt(Xh,s,u)(c):(e.enter("codeFlowValue"),o(c))}function o(c){return c===null||U(c)?(e.exit("codeFlowValue"),s(c)):(e.consume(c),o)}function u(c){return e.exit("codeIndented"),t(c)}}function tf(e,t,n){const i=this;return l;function l(s){return i.parser.lazy[i.now().line]?n(s):U(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),l):re(e,a,"linePrefix",5)(s)}function a(s){const o=i.events[i.events.length-1];return o&&o[1].type==="linePrefix"&&o[2].sliceSerialize(o[1],!0).length>=4?t(s):U(s)?l(s):n(s)}}const nf={name:"codeText",previous:lf,resolve:rf,tokenize:af};function rf(e){let t=e.length-4,n=3,i,l;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(i=n;++i=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return tthis.left.length?this.right.slice(this.right.length-i+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-i+this.left.length).reverse())}splice(t,n,i){const l=n||0;this.setCursor(Math.trunc(t));const a=this.right.splice(this.right.length-l,Number.POSITIVE_INFINITY);return i&&Mn(this.left,i),a.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Mn(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Mn(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t=4?t(s):e.interrupt(i.parser.constructs.flow,n,t)(s)}}function Bc(e,t,n,i,l,a,s,o,u){const c=u||Number.POSITIVE_INFINITY;let p=0;return d;function d(w){return w===60?(e.enter(i),e.enter(l),e.enter(a),e.consume(w),e.exit(a),f):w===null||w===32||w===41||di(w)?n(w):(e.enter(i),e.enter(s),e.enter(o),e.enter("chunkString",{contentType:"string"}),b(w))}function f(w){return w===62?(e.enter(a),e.consume(w),e.exit(a),e.exit(l),e.exit(i),t):(e.enter(o),e.enter("chunkString",{contentType:"string"}),h(w))}function h(w){return w===62?(e.exit("chunkString"),e.exit(o),f(w)):w===null||w===60||U(w)?n(w):(e.consume(w),w===92?m:h)}function m(w){return w===60||w===62||w===92?(e.consume(w),h):h(w)}function b(w){return!p&&(w===null||w===41||oe(w))?(e.exit("chunkString"),e.exit(o),e.exit(s),e.exit(i),t(w)):p999||h===null||h===91||h===93&&!u||h===94&&!o&&"_hiddenFootnoteSupport"in s.parser.constructs?n(h):h===93?(e.exit(a),e.enter(l),e.consume(h),e.exit(l),e.exit(i),t):U(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),p):(e.enter("chunkString",{contentType:"string"}),d(h))}function d(h){return h===null||h===91||h===93||U(h)||o++>999?(e.exit("chunkString"),p(h)):(e.consume(h),u||(u=!ee(h)),h===92?f:d)}function f(h){return h===91||h===92||h===93?(e.consume(h),o++,d):d(h)}}function jc(e,t,n,i,l,a){let s;return o;function o(f){return f===34||f===39||f===40?(e.enter(i),e.enter(l),e.consume(f),e.exit(l),s=f===40?41:f,u):n(f)}function u(f){return f===s?(e.enter(l),e.consume(f),e.exit(l),e.exit(i),t):(e.enter(a),c(f))}function c(f){return f===s?(e.exit(a),u(s)):f===null?n(f):U(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),re(e,c,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),p(f))}function p(f){return f===s||f===null||U(f)?(e.exit("chunkString"),c(f)):(e.consume(f),f===92?d:p)}function d(f){return f===s||f===92?(e.consume(f),p):p(f)}}function Jn(e,t){let n;return i;function i(l){return U(l)?(e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),n=!0,i):ee(l)?re(e,i,n?"linePrefix":"lineSuffix")(l):t(l)}}const pf={name:"definition",tokenize:gf},mf={partial:!0,tokenize:yf};function gf(e,t,n){const i=this;let l;return a;function a(h){return e.enter("definition"),s(h)}function s(h){return zc.call(i,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function o(h){return l=je(i.sliceSerialize(i.events[i.events.length-1][1]).slice(1,-1)),h===58?(e.enter("definitionMarker"),e.consume(h),e.exit("definitionMarker"),u):n(h)}function u(h){return oe(h)?Jn(e,c)(h):c(h)}function c(h){return Bc(e,p,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function p(h){return e.attempt(mf,d,d)(h)}function d(h){return ee(h)?re(e,f,"whitespace")(h):f(h)}function f(h){return h===null||U(h)?(e.exit("definition"),i.parser.defined.push(l),t(h)):n(h)}}function yf(e,t,n){return i;function i(o){return oe(o)?Jn(e,l)(o):n(o)}function l(o){return jc(e,a,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(o)}function a(o){return ee(o)?re(e,s,"whitespace")(o):s(o)}function s(o){return o===null||U(o)?t(o):n(o)}}const bf={name:"hardBreakEscape",tokenize:kf};function kf(e,t,n){return i;function i(a){return e.enter("hardBreakEscape"),e.consume(a),l}function l(a){return U(a)?(e.exit("hardBreakEscape"),t(a)):n(a)}}const wf={name:"headingAtx",resolve:vf,tokenize:_f};function vf(e,t){let n=e.length-2,i=3,l,a;return e[i][1].type==="whitespace"&&(i+=2),n-2>i&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(i===n-1||n-4>i&&e[n-2][1].type==="whitespace")&&(n-=i+1===n?2:4),n>i&&(l={type:"atxHeadingText",start:e[i][1].start,end:e[n][1].end},a={type:"chunkText",start:e[i][1].start,end:e[n][1].end,contentType:"text"},Ie(e,i,n-i+1,[["enter",l,t],["enter",a,t],["exit",a,t],["exit",l,t]])),e}function _f(e,t,n){let i=0;return l;function l(p){return e.enter("atxHeading"),a(p)}function a(p){return e.enter("atxHeadingSequence"),s(p)}function s(p){return p===35&&i++<6?(e.consume(p),s):p===null||oe(p)?(e.exit("atxHeadingSequence"),o(p)):n(p)}function o(p){return p===35?(e.enter("atxHeadingSequence"),u(p)):p===null||U(p)?(e.exit("atxHeading"),t(p)):ee(p)?re(e,o,"whitespace")(p):(e.enter("atxHeadingText"),c(p))}function u(p){return p===35?(e.consume(p),u):(e.exit("atxHeadingSequence"),o(p))}function c(p){return p===null||p===35||oe(p)?(e.exit("atxHeadingText"),o(p)):(e.consume(p),c)}}const xf=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],xs=["pre","script","style","textarea"],Sf={concrete:!0,name:"htmlFlow",resolveTo:Tf,tokenize:Ef},$f={partial:!0,tokenize:Af},Cf={partial:!0,tokenize:Pf};function Tf(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function Ef(e,t,n){const i=this;let l,a,s,o,u;return c;function c(_){return p(_)}function p(_){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(_),d}function d(_){return _===33?(e.consume(_),f):_===47?(e.consume(_),a=!0,b):_===63?(e.consume(_),l=3,i.interrupt?t:k):Se(_)?(e.consume(_),s=String.fromCharCode(_),x):n(_)}function f(_){return _===45?(e.consume(_),l=2,h):_===91?(e.consume(_),l=5,o=0,m):Se(_)?(e.consume(_),l=4,i.interrupt?t:k):n(_)}function h(_){return _===45?(e.consume(_),i.interrupt?t:k):n(_)}function m(_){const X="CDATA[";return _===X.charCodeAt(o++)?(e.consume(_),o===X.length?i.interrupt?t:F:m):n(_)}function b(_){return Se(_)?(e.consume(_),s=String.fromCharCode(_),x):n(_)}function x(_){if(_===null||_===47||_===62||oe(_)){const X=_===47,he=s.toLowerCase();return!X&&!a&&xs.includes(he)?(l=1,i.interrupt?t(_):F(_)):xf.includes(s.toLowerCase())?(l=6,X?(e.consume(_),w):i.interrupt?t(_):F(_)):(l=7,i.interrupt&&!i.parser.lazy[i.now().line]?n(_):a?C(_):y(_))}return _===45||Ee(_)?(e.consume(_),s+=String.fromCharCode(_),x):n(_)}function w(_){return _===62?(e.consume(_),i.interrupt?t:F):n(_)}function C(_){return ee(_)?(e.consume(_),C):S(_)}function y(_){return _===47?(e.consume(_),S):_===58||_===95||Se(_)?(e.consume(_),g):ee(_)?(e.consume(_),y):S(_)}function g(_){return _===45||_===46||_===58||_===95||Ee(_)?(e.consume(_),g):$(_)}function $(_){return _===61?(e.consume(_),v):ee(_)?(e.consume(_),$):y(_)}function v(_){return _===null||_===60||_===61||_===62||_===96?n(_):_===34||_===39?(e.consume(_),u=_,E):ee(_)?(e.consume(_),v):M(_)}function E(_){return _===u?(e.consume(_),u=null,T):_===null||U(_)?n(_):(e.consume(_),E)}function M(_){return _===null||_===34||_===39||_===47||_===60||_===61||_===62||_===96||oe(_)?$(_):(e.consume(_),M)}function T(_){return _===47||_===62||ee(_)?y(_):n(_)}function S(_){return _===62?(e.consume(_),R):n(_)}function R(_){return _===null||U(_)?F(_):ee(_)?(e.consume(_),R):n(_)}function F(_){return _===45&&l===2?(e.consume(_),O):_===60&&l===1?(e.consume(_),Q):_===62&&l===4?(e.consume(_),W):_===63&&l===3?(e.consume(_),k):_===93&&l===5?(e.consume(_),z):U(_)&&(l===6||l===7)?(e.exit("htmlFlowData"),e.check($f,Z,q)(_)):_===null||U(_)?(e.exit("htmlFlowData"),q(_)):(e.consume(_),F)}function q(_){return e.check(Cf,L,Z)(_)}function L(_){return e.enter("lineEnding"),e.consume(_),e.exit("lineEnding"),I}function I(_){return _===null||U(_)?q(_):(e.enter("htmlFlowData"),F(_))}function O(_){return _===45?(e.consume(_),k):F(_)}function Q(_){return _===47?(e.consume(_),s="",A):F(_)}function A(_){if(_===62){const X=s.toLowerCase();return xs.includes(X)?(e.consume(_),W):F(_)}return Se(_)&&s.length<8?(e.consume(_),s+=String.fromCharCode(_),A):F(_)}function z(_){return _===93?(e.consume(_),k):F(_)}function k(_){return _===62?(e.consume(_),W):_===45&&l===2?(e.consume(_),k):F(_)}function W(_){return _===null||U(_)?(e.exit("htmlFlowData"),Z(_)):(e.consume(_),W)}function Z(_){return e.exit("htmlFlow"),t(_)}}function Pf(e,t,n){const i=this;return l;function l(s){return U(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),a):n(s)}function a(s){return i.parser.lazy[i.now().line]?n(s):t(s)}}function Af(e,t,n){return i;function i(l){return e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),e.attempt(wr,t,n)}}const Mf={name:"htmlText",tokenize:Lf};function Lf(e,t,n){const i=this;let l,a,s;return o;function o(k){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(k),u}function u(k){return k===33?(e.consume(k),c):k===47?(e.consume(k),$):k===63?(e.consume(k),y):Se(k)?(e.consume(k),M):n(k)}function c(k){return k===45?(e.consume(k),p):k===91?(e.consume(k),a=0,m):Se(k)?(e.consume(k),C):n(k)}function p(k){return k===45?(e.consume(k),h):n(k)}function d(k){return k===null?n(k):k===45?(e.consume(k),f):U(k)?(s=d,Q(k)):(e.consume(k),d)}function f(k){return k===45?(e.consume(k),h):d(k)}function h(k){return k===62?O(k):k===45?f(k):d(k)}function m(k){const W="CDATA[";return k===W.charCodeAt(a++)?(e.consume(k),a===W.length?b:m):n(k)}function b(k){return k===null?n(k):k===93?(e.consume(k),x):U(k)?(s=b,Q(k)):(e.consume(k),b)}function x(k){return k===93?(e.consume(k),w):b(k)}function w(k){return k===62?O(k):k===93?(e.consume(k),w):b(k)}function C(k){return k===null||k===62?O(k):U(k)?(s=C,Q(k)):(e.consume(k),C)}function y(k){return k===null?n(k):k===63?(e.consume(k),g):U(k)?(s=y,Q(k)):(e.consume(k),y)}function g(k){return k===62?O(k):y(k)}function $(k){return Se(k)?(e.consume(k),v):n(k)}function v(k){return k===45||Ee(k)?(e.consume(k),v):E(k)}function E(k){return U(k)?(s=E,Q(k)):ee(k)?(e.consume(k),E):O(k)}function M(k){return k===45||Ee(k)?(e.consume(k),M):k===47||k===62||oe(k)?T(k):n(k)}function T(k){return k===47?(e.consume(k),O):k===58||k===95||Se(k)?(e.consume(k),S):U(k)?(s=T,Q(k)):ee(k)?(e.consume(k),T):O(k)}function S(k){return k===45||k===46||k===58||k===95||Ee(k)?(e.consume(k),S):R(k)}function R(k){return k===61?(e.consume(k),F):U(k)?(s=R,Q(k)):ee(k)?(e.consume(k),R):T(k)}function F(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(e.consume(k),l=k,q):U(k)?(s=F,Q(k)):ee(k)?(e.consume(k),F):(e.consume(k),L)}function q(k){return k===l?(e.consume(k),l=void 0,I):k===null?n(k):U(k)?(s=q,Q(k)):(e.consume(k),q)}function L(k){return k===null||k===34||k===39||k===60||k===61||k===96?n(k):k===47||k===62||oe(k)?T(k):(e.consume(k),L)}function I(k){return k===47||k===62||oe(k)?T(k):n(k)}function O(k){return k===62?(e.consume(k),e.exit("htmlTextData"),e.exit("htmlText"),t):n(k)}function Q(k){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),A}function A(k){return ee(k)?re(e,z,"linePrefix",i.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):z(k)}function z(k){return e.enter("htmlTextData"),s(k)}}const wa={name:"labelEnd",resolveAll:Rf,resolveTo:Ff,tokenize:Nf},If={tokenize:Bf},Of={tokenize:zf},Df={tokenize:jf};function Rf(e){let t=-1;const n=[];for(;++t=3&&(c===null||U(c))?(e.exit("thematicBreak"),t(c)):n(c)}function u(c){return c===l?(e.consume(c),i++,u):(e.exit("thematicBreakSequence"),ee(c)?re(e,o,"whitespace")(c):o(c))}}const Te={continuation:{tokenize:Yf},exit:Xf,name:"list",tokenize:Qf},Gf={partial:!0,tokenize:ep},Jf={partial:!0,tokenize:Zf};function Qf(e,t,n){const i=this,l=i.events[i.events.length-1];let a=l&&l[1].type==="linePrefix"?l[2].sliceSerialize(l[1],!0).length:0,s=0;return o;function o(h){const m=i.containerState.type||(h===42||h===43||h===45?"listUnordered":"listOrdered");if(m==="listUnordered"?!i.containerState.marker||h===i.containerState.marker:Fl(h)){if(i.containerState.type||(i.containerState.type=m,e.enter(m,{_container:!0})),m==="listUnordered")return e.enter("listItemPrefix"),h===42||h===45?e.check(Hr,n,c)(h):c(h);if(!i.interrupt||h===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),u(h)}return n(h)}function u(h){return Fl(h)&&++s<10?(e.consume(h),u):(!i.interrupt||s<2)&&(i.containerState.marker?h===i.containerState.marker:h===41||h===46)?(e.exit("listItemValue"),c(h)):n(h)}function c(h){return e.enter("listItemMarker"),e.consume(h),e.exit("listItemMarker"),i.containerState.marker=i.containerState.marker||h,e.check(wr,i.interrupt?n:p,e.attempt(Gf,f,d))}function p(h){return i.containerState.initialBlankLine=!0,a++,f(h)}function d(h){return ee(h)?(e.enter("listItemPrefixWhitespace"),e.consume(h),e.exit("listItemPrefixWhitespace"),f):n(h)}function f(h){return i.containerState.size=a+i.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(h)}}function Yf(e,t,n){const i=this;return i.containerState._closeFlow=void 0,e.check(wr,l,a);function l(o){return i.containerState.furtherBlankLines=i.containerState.furtherBlankLines||i.containerState.initialBlankLine,re(e,t,"listItemIndent",i.containerState.size+1)(o)}function a(o){return i.containerState.furtherBlankLines||!ee(o)?(i.containerState.furtherBlankLines=void 0,i.containerState.initialBlankLine=void 0,s(o)):(i.containerState.furtherBlankLines=void 0,i.containerState.initialBlankLine=void 0,e.attempt(Jf,t,s)(o))}function s(o){return i.containerState._closeFlow=!0,i.interrupt=void 0,re(e,e.attempt(Te,t,n),"linePrefix",i.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o)}}function Zf(e,t,n){const i=this;return re(e,l,"listItemIndent",i.containerState.size+1);function l(a){const s=i.events[i.events.length-1];return s&&s[1].type==="listItemIndent"&&s[2].sliceSerialize(s[1],!0).length===i.containerState.size?t(a):n(a)}}function Xf(e){e.exit(this.containerState.type)}function ep(e,t,n){const i=this;return re(e,l,"listItemPrefixWhitespace",i.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function l(a){const s=i.events[i.events.length-1];return!ee(a)&&s&&s[1].type==="listItemPrefixWhitespace"?t(a):n(a)}}const Ss={name:"setextUnderline",resolveTo:tp,tokenize:np};function tp(e,t){let n=e.length,i,l,a;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){i=n;break}e[n][1].type==="paragraph"&&(l=n)}else e[n][1].type==="content"&&e.splice(n,1),!a&&e[n][1].type==="definition"&&(a=n);const s={type:"setextHeading",start:{...e[i][1].start},end:{...e[e.length-1][1].end}};return e[l][1].type="setextHeadingText",a?(e.splice(l,0,["enter",s,t]),e.splice(a+1,0,["exit",e[i][1],t]),e[i][1].end={...e[a][1].end}):e[i][1]=s,e.push(["exit",s,t]),e}function np(e,t,n){const i=this;let l;return a;function a(c){let p=i.events.length,d;for(;p--;)if(i.events[p][1].type!=="lineEnding"&&i.events[p][1].type!=="linePrefix"&&i.events[p][1].type!=="content"){d=i.events[p][1].type==="paragraph";break}return!i.parser.lazy[i.now().line]&&(i.interrupt||d)?(e.enter("setextHeadingLine"),l=c,s(c)):n(c)}function s(c){return e.enter("setextHeadingLineSequence"),o(c)}function o(c){return c===l?(e.consume(c),o):(e.exit("setextHeadingLineSequence"),ee(c)?re(e,u,"lineSuffix")(c):u(c))}function u(c){return c===null||U(c)?(e.exit("setextHeadingLine"),t(c)):n(c)}}const rp={tokenize:ip};function ip(e){const t=this,n=e.attempt(wr,i,e.attempt(this.parser.constructs.flowInitial,l,re(e,e.attempt(this.parser.constructs.flow,l,e.attempt(cf,l)),"linePrefix")));return n;function i(a){if(a===null){e.consume(a);return}return e.enter("lineEndingBlank"),e.consume(a),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function l(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const lp={resolveAll:qc()},ap=Hc("string"),sp=Hc("text");function Hc(e){return{resolveAll:qc(e==="text"?op:void 0),tokenize:t};function t(n){const i=this,l=this.parser.constructs[e],a=n.attempt(l,s,o);return s;function s(p){return c(p)?a(p):o(p)}function o(p){if(p===null){n.consume(p);return}return n.enter("data"),n.consume(p),u}function u(p){return c(p)?(n.exit("data"),a(p)):(n.consume(p),u)}function c(p){if(p===null)return!0;const d=l[p];let f=-1;if(d)for(;++f-1){const o=s[0];typeof o=="string"?s[0]=o.slice(i):s.shift()}a>0&&s.push(e[l].slice(0,a))}return s}function vp(e,t){let n=-1;const i=[];let l;for(;++n0){const Fe=J.tokenStack[J.tokenStack.length-1];(Fe[1]||$s).call(J,void 0,Fe[0])}for(D.position={start:ct(P.length>0?P[0][1].start:{line:1,column:1,offset:0}),end:ct(P.length>0?P[P.length-2][1].end:{line:1,column:1,offset:0})},ae=-1;++ae":""))+")"})}return p;function p(){let h=qc,m,b,x;if(a(u,c,f[f.length-1]||void 0)&&(h=Op(n(u,f)),h[0]===Ts))return h;if("children"in u&&u.children){const w=u;if(w.children&&h[0]!==Lp)for(b=-1+s,x=f.concat(w);b>-1&&b0?{type:"text",value:v}:void 0),v===!1?p.lastIndex=g+1:(m!==g&&C.push({type:"text",value:c.value.slice(m,g)}),Array.isArray(v)?C.push(...v):v&&C.push(v),m=g+y[0].length,w=!0),!p.global)break;y=p.exec(c.value)}return w?(m?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],i=n.indexOf(")");const l=Cs(e,"(");let a=Cs(e,")");for(;i!==-1&&l>a;)e+=n.slice(0,i+1),n=n.slice(i+1),i=n.indexOf(")"),a++;return[e,n]}function Uc(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||zt(n)||Di(n))&&(!t||n!==47)}function Qp(){this.buffer()}function Yp(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function Zp(){this.buffer()}function Xp(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function em(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=je(this.sliceSerialize(e)).toLowerCase(),n.label=t}function tm(e){this.exit(e)}function nm(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=je(this.sliceSerialize(e)).toLowerCase(),n.label=t}function rm(e){this.exit(e)}function im(){return{enter:{gfmFootnoteCallString:Qp,gfmFootnoteCall:Yp,gfmFootnoteDefinitionLabelString:Zp,gfmFootnoteDefinition:Xp},exit:{gfmFootnoteCallString:em,gfmFootnoteCall:tm,gfmFootnoteDefinitionLabelString:nm,gfmFootnoteDefinition:rm}}}function lm(){return{canContainEols:["delete"],enter:{strikethrough:am},exit:{strikethrough:sm}}}function am(e){this.enter({type:"delete",children:[]},e)}function sm(e){this.exit(e)}function om(){return{enter:{table:cm,tableData:Es,tableHeader:Es,tableRow:dm},exit:{codeText:hm,table:um,tableData:sl,tableHeader:sl,tableRow:sl}}}function cm(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function um(e){this.exit(e),this.data.inTable=void 0}function dm(e){this.enter({type:"tableRow",children:[]},e)}function sl(e){this.exit(e)}function Es(e){this.enter({type:"tableCell",children:[]},e)}function hm(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,fm));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function fm(e,t){return t==="|"?t:e}function pm(){return{exit:{taskListCheckValueChecked:Ps,taskListCheckValueUnchecked:Ps,paragraph:mm}}}function Ps(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function mm(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const i=n.children[0];if(i&&i.type==="text"){const l=t.children;let a=-1,s;for(;++a0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const Tm={tokenize:Dm,partial:!0};function Em(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Lm,continuation:{tokenize:Im},exit:Om}},text:{91:{name:"gfmFootnoteCall",tokenize:Mm},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Pm,resolveTo:Am}}}}function Pm(e,t,n){const i=this;let l=i.events.length;const a=i.parser.gfmFootnotes||(i.parser.gfmFootnotes=[]);let s;for(;l--;){const u=i.events[l][1];if(u.type==="labelImage"){s=u;break}if(u.type==="gfmFootnoteCall"||u.type==="labelLink"||u.type==="label"||u.type==="image"||u.type==="link")break}return o;function o(u){if(!s||!s._balanced)return n(u);const c=je(i.sliceSerialize({start:s.end,end:i.now()}));return c.codePointAt(0)!==94||!a.includes(c.slice(1))?n(u):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),t(u))}}function Am(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const i={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},l={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};l.end.column++,l.end.offset++,l.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},l.end),end:Object.assign({},e[e.length-1][1].start)},s={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},o=[e[n+1],e[n+2],["enter",i,t],e[n+3],e[n+4],["enter",l,t],["exit",l,t],["enter",a,t],["enter",s,t],["exit",s,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",i,t]];return e.splice(n,e.length-n+1,...o),e}function Mm(e,t,n){const i=this,l=i.parser.gfmFootnotes||(i.parser.gfmFootnotes=[]);let a=0,s;return o;function o(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),u}function u(d){return d!==94?n(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(d){if(a>999||d===93&&!s||d===null||d===91||oe(d))return n(d);if(d===93){e.exit("chunkString");const p=e.exit("gfmFootnoteCallString");return l.includes(je(i.sliceSerialize(p)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(d)}return oe(d)||(s=!0),a++,e.consume(d),d===92?f:c}function f(d){return d===91||d===92||d===93?(e.consume(d),a++,c):c(d)}}function Lm(e,t,n){const i=this,l=i.parser.gfmFootnotes||(i.parser.gfmFootnotes=[]);let a,s=0,o;return u;function u(m){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(m){return m===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",f):n(m)}function f(m){if(s>999||m===93&&!o||m===null||m===91||oe(m))return n(m);if(m===93){e.exit("chunkString");const b=e.exit("gfmFootnoteDefinitionLabelString");return a=je(i.sliceSerialize(b)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),p}return oe(m)||(o=!0),s++,e.consume(m),m===92?d:f}function d(m){return m===91||m===92||m===93?(e.consume(m),s++,f):f(m)}function p(m){return m===58?(e.enter("definitionMarker"),e.consume(m),e.exit("definitionMarker"),l.includes(a)||l.push(a),re(e,h,"gfmFootnoteDefinitionWhitespace")):n(m)}function h(m){return t(m)}}function Im(e,t,n){return e.check(yr,t,e.attempt(Tm,t,n))}function Om(e){e.exit("gfmFootnoteDefinition")}function Dm(e,t,n){const i=this;return re(e,l,"gfmFootnoteDefinitionIndent",5);function l(a){const s=i.events[i.events.length-1];return s&&s[1].type==="gfmFootnoteDefinitionIndent"&&s[2].sliceSerialize(s[1],!0).length===4?t(a):n(a)}}function Rm(e){let n={}.singleTilde;const i={name:"strikethrough",tokenize:a,resolveAll:l};return n==null&&(n=!0),{text:{126:i},insideSpan:{null:[i]},attentionMarkers:{null:[126]}};function l(s,o){let u=-1;for(;++u1?u(m):(s.consume(m),d++,h);if(d<2&&!n)return u(m);const x=s.exit("strikethroughSequenceTemporary"),w=ci(m);return x._open=!w||w===2&&!!b,x._close=!b||b===2&&!!w,o(m)}}}class Fm{constructor(){this.map=[]}add(t,n,i){Nm(this,t,n,i)}consume(t){if(this.map.sort(function(a,s){return a[0]-s[0]}),this.map.length===0)return;let n=this.map.length;const i=[];for(;n>0;)n-=1,i.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];i.push(t.slice()),t.length=0;let l=i.pop();for(;l;){for(const a of l)t.push(a);l=i.pop()}this.map.length=0}}function Nm(e,t,n,i){let l=0;if(!(n===0&&i.length===0)){for(;l-1;){const L=i.events[R][1].type;if(L==="lineEnding"||L==="linePrefix")R--;else break}const F=R>-1?i.events[R][1].type:null,q=F==="tableHead"||F==="tableRow"?v:u;return q===v&&i.parser.lazy[i.now().line]?n(S):q(S)}function u(S){return e.enter("tableHead"),e.enter("tableRow"),c(S)}function c(S){return S===124||(s=!0,a+=1),f(S)}function f(S){return S===null?n(S):U(S)?a>1?(a=0,i.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(S),e.exit("lineEnding"),h):n(S):ee(S)?re(e,f,"whitespace")(S):(a+=1,s&&(s=!1,l+=1),S===124?(e.enter("tableCellDivider"),e.consume(S),e.exit("tableCellDivider"),s=!0,f):(e.enter("data"),d(S)))}function d(S){return S===null||S===124||oe(S)?(e.exit("data"),f(S)):(e.consume(S),S===92?p:d)}function p(S){return S===92||S===124?(e.consume(S),d):d(S)}function h(S){return i.interrupt=!1,i.parser.lazy[i.now().line]?n(S):(e.enter("tableDelimiterRow"),s=!1,ee(S)?re(e,m,"linePrefix",i.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(S):m(S))}function m(S){return S===45||S===58?x(S):S===124?(s=!0,e.enter("tableCellDivider"),e.consume(S),e.exit("tableCellDivider"),b):$(S)}function b(S){return ee(S)?re(e,x,"whitespace")(S):x(S)}function x(S){return S===58?(a+=1,s=!0,e.enter("tableDelimiterMarker"),e.consume(S),e.exit("tableDelimiterMarker"),w):S===45?(a+=1,w(S)):S===null||U(S)?g(S):$(S)}function w(S){return S===45?(e.enter("tableDelimiterFiller"),C(S)):$(S)}function C(S){return S===45?(e.consume(S),C):S===58?(s=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(S),e.exit("tableDelimiterMarker"),y):(e.exit("tableDelimiterFiller"),y(S))}function y(S){return ee(S)?re(e,g,"whitespace")(S):g(S)}function g(S){return S===124?m(S):S===null||U(S)?!s||l!==a?$(S):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(S)):$(S)}function $(S){return n(S)}function v(S){return e.enter("tableRow"),E(S)}function E(S){return S===124?(e.enter("tableCellDivider"),e.consume(S),e.exit("tableCellDivider"),E):S===null||U(S)?(e.exit("tableRow"),t(S)):ee(S)?re(e,E,"whitespace")(S):(e.enter("data"),A(S))}function A(S){return S===null||S===124||oe(S)?(e.exit("data"),E(S)):(e.consume(S),S===92?T:A)}function T(S){return S===92||S===124?(e.consume(S),A):A(S)}}function Hm(e,t){let n=-1,i=!0,l=0,a=[0,0,0,0],s=[0,0,0,0],o=!1,u=0,c,f,d;const p=new Fm;for(;++nn[2]+1){const m=n[2]+1,b=n[3]-n[2]-1;e.add(m,b,[])}}e.add(n[3]+1,0,[["exit",d,t]])}return l!==void 0&&(a.end=Object.assign({},Xt(t.events,l)),e.add(l,0,[["exit",a,t]]),a=void 0),a}function As(e,t,n,i,l){const a=[],s=Xt(t.events,n);l&&(l.end=Object.assign({},s),a.push(["exit",l,t])),i.end=Object.assign({},s),a.push(["exit",i,t]),e.add(n+1,0,a)}function Xt(e,t){const n=e[t],i=n[0]==="enter"?"start":"end";return n[1][i]}const qm={name:"tasklistCheck",tokenize:Wm};function Um(){return{text:{91:qm}}}function Wm(e,t,n){const i=this;return l;function l(u){return i.previous!==null||!i._gfmTasklistFirstContentOfListItem?n(u):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(u),e.exit("taskListCheckMarker"),a)}function a(u){return oe(u)?(e.enter("taskListCheckValueUnchecked"),e.consume(u),e.exit("taskListCheckValueUnchecked"),s):u===88||u===120?(e.enter("taskListCheckValueChecked"),e.consume(u),e.exit("taskListCheckValueChecked"),s):n(u)}function s(u){return u===93?(e.enter("taskListCheckMarker"),e.consume(u),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),o):n(u)}function o(u){return U(u)?t(u):ee(u)?e.check({tokenize:Km},t,n)(u):n(u)}}function Km(e,t,n){return re(e,i,"whitespace");function i(l){return l===null?n(l):t(l)}}function eu(e){return Pc([bm(),Em(),Rm(),zm(),Um()])}const Vm={pr_title:"from the PR title",branch:"from the branch name"};function br(e){if(e!=null&&e.linked_linear){const t=e.linked_linear,n=e.linked_linear_title?`: ${e.linked_linear_title}`:"",i=e.linked_linear_status?` [${e.linked_linear_status}]`:"";return{id:t,href:`https://linear.app/issue/${t}`,tip:`Linear ${t}${n}${i}`,note:null,derived:!1}}if(e!=null&&e.linear_ticket){const t=e.linear_ticket,n=Vm[e.linear_ticket_source]||"derived";return{id:t,href:`https://linear.app/issue/${t}`,tip:`Linear ${t} (${n})`,note:n,derived:!0}}return null}const Gm=/^([a-z-]+): (.+)$/;function Nl(e,t){if((e==null?void 0:e.type)!=="blockquote"||typeof t!="string")return null;const n=t.slice(e.position.start.offset,e.position.end.offset),i=[];for(const l of n.split(` -`))for(const a of l.replace(/^\s*> ?/,"").split(" · ")){const s=Gm.exec(a.trim());if(!s)return null;i.push([s[1],s[2].trim()])}return i.length?i:null}function tu(e){return e.split(",").map(t=>t.trim().replace(/^`+|`+$/g,""))}const Jm=/^([\w.-]*[\w-]\/[\w./-]*[\w-]|[\w-]+(?:\.[\w-]+)*\.[A-Za-z][A-Za-z0-9]{1,5})(?::(\d+)(?:-(\d+))?)?$/;function Ni(e){const t=Jm.exec(e);if(!t)return null;const n=t[1];if(!/[A-Za-z]/.test(n)||!n.includes("/")&&t[2]==null)return null;const i=n.split("/").pop();if(t[2]==null&&n.includes("/")&&!/\.[A-Za-z][A-Za-z0-9]{0,5}$/.test(i)&&!/^[\w.-]+\/[\w.-]+\//.test(n))return null;const l=t[2]!=null?Number(t[2]):null;return{path:n,start:l,end:t[3]!=null?Number(t[3]):l,raw:e}}function Qm(e){const t=[];let n="";const i=/\S+/g;let l=0;for(let a=i.exec(e);a;a=i.exec(e)){const s=a[0],o=(s.match(/^[(["']+/)||[""])[0],u=s.slice(o.length).replace(/[.,;:)\]"']+$/,""),c=u?Ni(u):null;c?(n+=e.slice(l,a.index)+o,n&&t.push(n),n=s.slice(o.length+u.length),t.push(c)):n+=e.slice(l,a.index)+s,l=a.index+s.length}return n+=e.slice(l),n&&t.push(n),t}const Ym=new Set(["new-subsystem","extension","reuse","system-touch","behavior"]);function Zm(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"stop"}function jr(e){return e.type==="text"||e.type==="inlineCode"?e.value:(e.children||[]).map(jr).join("")}function Xm(e){var f,d,p;const t=String(e||""),i=jc(t,{extensions:[eu()],mdastExtensions:[Wc()]}).children;let l="",a=null,s="";const o=[],u=new Map;let c=0;if(((f=i[c])==null?void 0:f.type)==="heading"&&i[c].depth===1){l=jr(i[c]),c++;const h=((d=i[c])==null?void 0:d.type)==="blockquote"?Nl(i[c],t):null;if(h){const m=Object.fromEntries(h);m.branch&&m.head&&(a={branch:m.branch,head:m.head,pr:/^\d+$/.test(m.pr||"")?Number(m.pr):null,repo:m.repo??null}),c++}((p=i[c])==null?void 0:p.type)==="paragraph"&&(s=jr(i[c]),c++)}for(;cn.kind==="ctx"||n.kind==="add").length;return e.new_start+Math.max(t,1)-1}function tg(e,t){const n=new Map((t||[]).map(i=>[i.path,i]));return e.map(i=>{const l=n.get(i.path)||null;if(!l)return{ref:i,file:null,hunks:[],generated:!1};const a=i.start==null?l.hunks:l.hunks.filter(s=>s.new_start<=i.end&&eg(s)>=i.start);return{ref:i,file:l.path,hunks:a,generated:!!l.generated}})}const ui=e=>{var t;return((t=e.pr)==null?void 0:t.state)==="merged"};function Ms(e){if(ui(e))return 99;const t=e.owner?0:e.worktree?10:20;return e.unresolved>0?t:e.role==="review-requested"?t+1:e.pr&&!e.walkthrough?t+2:e.role==="local"?t+4:t+3}const Bi={branch:{label:"branch",what:"branch name",first:"asc",value:e=>e.branch},pr:{label:"PR",what:"PR number",first:"desc",value:e=>{var t;return((t=e.pr)==null?void 0:t.number)??null}},walkthrough:{label:"walkthrough",what:"staleness",first:"desc",value:e=>{var t;return((t=e.walkthrough)==null?void 0:t.stale_by)??null}},comments:{label:"comments",what:"open comments",first:"desc",value:e=>e.unresolved||null},who:{label:"who",what:"owner",first:"asc",value:e=>{var t,n;return((t=e.owner)==null?void 0:t.name)||((n=e.pr)==null?void 0:n.author)||null}}};function ng(e){if(!e.walkthrough)return null;const t=e.walkthrough.stale_by;return t>0?`stale ${t}`:t===0?"current":e.worktree?"stale: unknown":"no worktree"}const rg=(e,t)=>typeof e=="string"?e.localeCompare(t):e-t;function ig(e,t=null){const n=[...e||[]].sort((a,s)=>{var o,u;return Ms(a)-Ms(s)||(((o=s.pr)==null?void 0:o.number)||0)-(((u=a.pr)==null?void 0:u.number)||0)||a.branch.localeCompare(s.branch)}),i=t&&Bi[t.key];if(!i)return n;const l=t.dir==="asc"?1:-1;return n.sort((a,s)=>{const o=i.value(a),u=i.value(s);return ui(a)-ui(s)||(o===null)-(u===null)||(o===null?0:l*rg(o,u))})}function lg(e,t){const n=Bi[t].first;return(e==null?void 0:e.key)!==t?{key:t,dir:n}:e.dir===n?{key:t,dir:n==="asc"?"desc":"asc"}:null}function ag(e,t){const n=(t||"").toLowerCase().split(/\s+/).filter(Boolean);return n.length?(e||[]).filter(i=>{var a,s,o,u;const l=[i.branch,i.repo,i.pr?`#${i.pr.number}`:null,(a=i.pr)==null?void 0:a.title,(s=i.pr)==null?void 0:s.author,(o=i.owner)==null?void 0:o.name,(u=br(i))==null?void 0:u.id,i.linked_linear_title].filter(Boolean).join(" ").toLowerCase();return n.every(c=>l.includes(c))}):e||[]}function Ls(e){return(e||[]).filter(t=>!ui(t)).reduce((t,n)=>t+(n.unresolved||0),0)}const sg={scope:{name:"Scope",root:[{r:[11,1,2,6],a:{fill:"#2a86b3"}},{r:[11,1,5,2],a:{fill:"#2a86b3"}},{g:[{r:[16,1,1,2],a:{fill:"#ffd166"}}],anim:"crit-scope-1"},{r:[1,9,2,4],a:{fill:"#2a86b3"}},{r:[4,6,12,1],a:{fill:"#40b8ee"}},{r:[3,7,14,8],a:{fill:"#40b8ee"}},{r:[4,15,12,1],a:{fill:"#2a86b3"}},{r:[5,7,3,1],a:{fill:"#7fd0f5"}},{g:[{r:[6,9,2,2],a:{fill:"#0f1215"}}],anim:"crit-scope-2",role:"eye",shut:[6,10,2,.4]},{g:[{r:[12,9,2,2],a:{fill:"#0f1215"}}],anim:"crit-scope-3",role:"eye",shut:[12,10,2,.4]},{g:[{r:[6,9,.7,.7]},{r:[12,9,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[5.5,7.9,3,.7]},{r:[11.5,7.9,3,.7]},{r:[8.5,12.2,3,.7]}],a:{fill:"#16384a"},mood:"grumpy"},{g:[{r:[5.4,7.5,1.6,.7]},{r:[7,8.1,1.6,.7]},{r:[11.4,8.1,1.6,.7]},{r:[13,7.5,1.6,.7]},{r:[8.5,11.7,3,1.6]}],a:{fill:"#16384a"},mood:"furious"},{g:[{r:[8.4,11.6,.7,.7],a:{fill:"#16384a"}},{r:[9,12.2,2,.7],a:{fill:"#16384a"}},{r:[10.9,11.6,.7,.7],a:{fill:"#16384a"}},{r:[4.4,11.6,1.5,.8],a:{fill:"#f58967",opacity:"0.7"}},{r:[14.1,11.6,1.5,.8],a:{fill:"#f58967",opacity:"0.7"}}],mood:"calm"},{g:[{r:[5,16,2,2],a:{fill:"#2a86b3"}},{r:[13,16,2,2],a:{fill:"#2a86b3"}}],legs:!0},{g:[{g:[{r:[3,3,1,1]}],anim:"crit-scope-4"},{g:[{r:[6,2,1,1]}],anim:"crit-scope-5"}],a:{fill:"#8f9397"},mood:"furious"}],anchors:{eyes:[{x:6,y:9,w:2,h:2,role:"eye"},{x:12,y:9,w:2,h:2,role:"eye"}],head:{top:1,right:17},hat:{cx:10,top:6,w:12},neck:{y:13,x0:3,x1:17}},ink:"#0f1215",limb:{style:"arm",root:[17,10.6],width:1.2,color:"#2a86b3"}},faradaysie:{name:"Faradaysie",root:[{g:[{r:[12,0,1,1]},{r:[11,1,3,1]},{r:[10,2,5,1]},{r:[12,3,1,2]}],a:{fill:"#f72f96"}},{g:[{g:[{r:[7,0,1,2]}],anim:"crit-faradaysie-1"},{g:[{r:[5,2,5,1]}],anim:"crit-faradaysie-2"},{g:[{r:[6,3,3,1]}],anim:"crit-faradaysie-3"},{g:[{r:[7,4,1,1]}],anim:"crit-faradaysie-4"}],a:{fill:"#e4baff"}},{g:[{r:[7,5,6,1]},{r:[5,6,10,1]},{r:[4,7,12,7]},{r:[5,14,10,1]}],a:{fill:"#b641ff"}},{r:[6,15,8,1],a:{fill:"#6d1ba0"}},{r:[6,6,3,1],a:{fill:"#e4baff"}},{r:[5,7,1,2],a:{fill:"#e4baff"}},{r:[7,11.5,6,2.5],a:{fill:"#fcb0d7"}},{g:[{r:[3,9,1,2]},{g:[{r:[16,9,1,2]}],anim:"crit-faradaysie-5"}],arms:!0,a:{fill:"#6d1ba0"}},{g:[{r:[6,16,2,1]},{r:[12,16,2,1]}],legs:!0,a:{fill:"#6d1ba0"}},{g:[{r:[6,8,2,2],a:{fill:"#240835"}}],anim:"crit-faradaysie-6",role:"eye",shut:[6,9,2,.4]},{g:[{r:[12,8,2,2],a:{fill:"#240835"}}],anim:"crit-faradaysie-7",role:"eye",shut:[12,9,2,.4]},{g:[{r:[6,8,.7,.7]},{r:[12,8,.7,.7]}],a:{fill:"#fdfaff"},mood:"calm",role:"glint"},{g:[{r:[8.4,10.6,.7,.7],a:{fill:"#240835"}},{r:[9,11.2,2,.7],a:{fill:"#240835"}},{r:[10.9,10.6,.7,.7],a:{fill:"#240835"}},{r:[4.4,10.4,1.5,.8],a:{fill:"#f72f96",opacity:"0.75"}},{r:[14.1,10.4,1.5,.8],a:{fill:"#f72f96",opacity:"0.75"}}],mood:"calm"},{g:[{r:[5.5,6.9,3,.7]},{r:[11.5,6.9,3,.7]},{r:[8.5,11,3,.7]}],a:{fill:"#240835"},mood:"grumpy"},{g:[{r:[5.4,6.5,1.6,.7]},{r:[7,7.1,1.6,.7]},{r:[11.4,7.1,1.6,.7]},{r:[13,6.5,1.6,.7]},{r:[8.5,10.5,3,1.6]}],a:{fill:"#240835"},mood:"furious"},{g:[{g:[{r:[2,4,1,2]}],anim:"crit-faradaysie-8"},{g:[{r:[17,3,1,2]}],anim:"crit-faradaysie-9"},{g:[{r:[1,12,1,1]}],anim:"crit-faradaysie-10"},{g:[{r:[18,13,1,1]}],anim:"crit-faradaysie-11"}],a:{fill:"#f72f96"},mood:"furious"}],anchors:{eyes:[{x:6,y:8,w:2,h:2,role:"eye"},{x:12,y:8,w:2,h:2,role:"eye"}],head:{top:0,right:17},hat:{cx:10,top:6,w:10},neck:{y:12.8,x0:4,x1:16}},ink:"#240835",limb:{style:"arm",root:[16.4,9.4],width:1.2,color:"#6d1ba0"}},jelly:{name:"Jelly",root:[{r:[7,3,6,1],a:{fill:"#ab93ed"}},{r:[5,4,10,1],a:{fill:"#ab93ed"}},{r:[4,5,12,6],a:{fill:"#ab93ed"}},{r:[4,11,12,1],a:{fill:"#7d62c9"}},{g:[{r:[4,12,2,1]},{r:[7.3,12,2,1]},{r:[10.7,12,2,1]},{r:[14,12,2,1]}],a:{fill:"#7d62c9"}},{g:[{r:[7,4,3,1]},{r:[5,5,1,2]},{r:[13,5,1,1]},{r:[14,7,1,1]}],a:{fill:"#d4c6fa"}},{g:[{r:[6,13,1,2]},{r:[5,15,1,2]},{r:[6,17,1,1]},{r:[9.5,13,1,2]},{r:[10.5,15,1,2]},{r:[9.5,17,1,1]},{r:[13,13,1,2]},{r:[14,15,1,2]},{r:[13,17,1,1]}],legs:!0,keepSeated:!0,a:{fill:"#7d62c9"},anim:"crit-jelly-1"},{g:[{r:[7,7,2,2],a:{fill:"#2a1f45"}}],anim:"crit-jelly-2",role:"eye",shut:[7,8,2,.4]},{g:[{r:[11,7,2,2],a:{fill:"#2a1f45"}}],anim:"crit-jelly-3",role:"eye",shut:[11,8,2,.4]},{g:[{r:[7,7,.7,.7]},{r:[11,7,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[8.4,9.6,.7,.7],a:{fill:"#2a1f45"}},{r:[9,10.2,2,.7],a:{fill:"#2a1f45"}},{r:[10.9,9.6,.7,.7],a:{fill:"#2a1f45"}},{r:[5,9.2,1.5,.8],a:{fill:"#f2a7c3"}},{r:[13.5,9.2,1.5,.8],a:{fill:"#f2a7c3"}}],mood:"calm"},{g:[{r:[6.5,5.9,3,.7]},{r:[10.5,5.9,3,.7]},{r:[8.5,10,3,.7]}],a:{fill:"#2a1f45"},mood:"grumpy"},{g:[{r:[6.4,5.5,1.6,.7]},{r:[8,6.1,1.6,.7]},{r:[10.4,6.1,1.6,.7]},{r:[12,5.5,1.6,.7]},{r:[8.5,9.5,3,1.4]}],a:{fill:"#2a1f45"},mood:"furious"},{g:[{g:[{r:[2,4,1,1]}],anim:"crit-jelly-4"},{g:[{r:[17,6,1,1]}],anim:"crit-jelly-5"}],a:{fill:"#f3e9c6"},mood:"furious"}],anchors:{eyes:[{x:7,y:7,w:2,h:2,role:"eye"},{x:11,y:7,w:2,h:2,role:"eye"}],head:{top:3,right:16},hat:{cx:10,top:3,w:8},neck:{y:10.5,x0:4,x1:16}},ink:"#2a1f45",limb:{style:"tentacle",root:[16,10.2],width:1,color:"#7d62c9"}},nox:{name:"Nox",root:[{g:[{g:[{r:[15,16,3,1]},{r:[17,12,1,4]},{r:[16,11,1,1]}],a:{fill:"#1a1c20",stroke:"#4a4f57","stroke-width":"1"}},{g:[{r:[15,16,3,1]},{r:[17,12,1,4]},{r:[16,11,1,1]}],a:{fill:"#1a1c20"}}],rest:!0,anim:"crit-nox-1"},{g:[{r:[5,3,1,2]},{r:[6,4,1,1]},{r:[14,3,1,2]},{r:[13,4,1,1]},{r:[5,5,10,1]},{r:[4,6,12,5]},{r:[5,11,10,1]},{r:[6,12,8,1]},{r:[5,13,10,5]}],a:{fill:"#1a1c20",stroke:"#4a4f57","stroke-width":"1"}},{g:[{r:[5,3,1,2]},{r:[6,4,1,1]},{r:[14,3,1,2]},{r:[13,4,1,1]},{r:[5,5,10,1]},{r:[4,6,12,5]},{r:[5,11,10,1]},{r:[6,12,8,1]},{r:[5,13,10,5]}],a:{fill:"#1a1c20"}},{g:[{r:[5.2,4.2,.6,.7]},{r:[14.2,4.2,.6,.7]}],a:{fill:"#f2a7c3",opacity:"0.8"}},{r:[6,5,3,1],a:{fill:"#2c3036"}},{g:[{r:[6,17,2,1]},{r:[12,17,2,1]}],legs:!0,keepSeated:!0,a:{fill:"#3a3f46"}},{g:[{r:[1.8,8.8,2.2,.4]},{r:[1.8,10,2.2,.4]},{r:[16,8.8,2.2,.4]},{r:[16,10,2.2,.4]}],a:{fill:"#5c626b"}},{r:[6,6,3,3],a:{fill:"#c6e05a"}},{r:[11,6,3,3],a:{fill:"#c6e05a"}},{g:[{g:[{r:[7,6.5,1.4,2]}],anim:"crit-nox-2"},{g:[{r:[12,6.5,1.4,2]}],anim:"crit-nox-3"}],a:{fill:"#0b0c0e"}},{g:[{r:[6.3,6.3,.7,.7]},{r:[11.3,6.3,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm"},{g:[{g:[{r:[6,6,3,3]}],anim:"crit-nox-4",role:"lid",shut:[6,6,3,3]},{g:[{r:[11,6,3,3]}],anim:"crit-nox-5",role:"lid",shut:[11,6,3,3]}],a:{fill:"#1a1c20"}},{r:[9.5,9,1,.7],a:{fill:"#f2a7c3"}},{g:[{r:[9,9.9,.5,.5]},{r:[9.4,10.3,.6,.4]},{r:[10,10.3,.6,.4]},{r:[10.5,9.9,.5,.5]}],a:{fill:"#8f9397"},mood:"calm"},{g:[{r:[6,6,3,1.3],a:{fill:"#1a1c20"}},{r:[11,6,3,1.3],a:{fill:"#1a1c20"}},{r:[8.8,10.2,2.4,.5],a:{fill:"#8f9397"}}],mood:"grumpy"},{g:[{r:[8,6,1,1],a:{fill:"#1a1c20"}},{r:[11,6,1,1],a:{fill:"#1a1c20"}},{r:[8.8,9.8,2.4,1.3],a:{fill:"#f2a7c3"}},{r:[9,9.8,.5,.6],a:{fill:"#f3f5f8"}},{r:[10.5,9.8,.5,.6],a:{fill:"#f3f5f8"}},{g:[{g:[{r:[7.5,3.6,1,1.2]}],anim:"crit-nox-6"},{g:[{r:[9.5,3.2,1,1.6]}],anim:"crit-nox-7"},{g:[{r:[11.5,3.6,1,1.2]}],anim:"crit-nox-8"}],a:{fill:"#5c626b"}}],mood:"furious"}],anchors:{eyes:[{x:6,y:6,w:3,h:3,role:"lid"},{x:11,y:6,w:3,h:3,role:"lid"}],head:{top:3,right:18.2},hat:{cx:10,top:5,w:9},neck:{y:12,x0:6,x1:14}},ink:"#c6e05a",faces:{worried:[{g:[{r:[5.8,5.9,1.4,.6]},{r:[7.2,5.4,1.6,.6]},{r:[11.2,5.4,1.6,.6]},{r:[12.8,5.9,1.4,.6]}],a:{fill:"#d5d8dc"}}]},limb:{style:"tail",root:[15.2,16],width:1,color:"#1a1c20",outline:"#4a4f57"}},ember:{name:"Ember",root:[{g:[{r:[4,2,1,2]},{r:[5,3,1,2]},{r:[15,2,1,2]},{r:[14,3,1,2]}],a:{fill:"#ffd9a0"}},{r:[6,4,8,1],a:{fill:"#e8574f"}},{r:[5,5,10,1],a:{fill:"#e8574f"}},{r:[4,6,12,8],a:{fill:"#e8574f"}},{r:[5,14,10,1],a:{fill:"#e8574f"}},{r:[6,15,8,1],a:{fill:"#b8403a"}},{r:[8,11,4,3],a:{fill:"#ff9a8f"}},{r:[6,5,2,1],a:{fill:"#ff9a8f"}},{g:[{r:[3,9,1,2]},{r:[16,9,1,2]}],arms:!0,a:{fill:"#b8403a"}},{g:[{r:[6,16,2,1]},{r:[12,16,2,1]}],legs:!0,a:{fill:"#b8403a"}},{g:[{r:[16,13,1,1]},{r:[17,12,1,1]},{r:[18,10,1,2]},{r:[17,9,1,1]},{r:[19,9,1,1]},{r:[18,8,1,1]}],rest:!0,a:{fill:"#b8403a"},anim:"crit-ember-1"},{g:[{r:[7,7,2,2],a:{fill:"#3a1312"}}],anim:"crit-ember-2",role:"eye",shut:[7,8,2,.4]},{g:[{r:[11,7,2,2],a:{fill:"#3a1312"}}],anim:"crit-ember-3",role:"eye",shut:[11,8,2,.4]},{g:[{r:[7,7,.7,.7]},{r:[11,7,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[8.4,9.6,.7,.7],a:{fill:"#3a1312"}},{r:[9,10.2,2,.7],a:{fill:"#3a1312"}},{r:[10.9,9.6,.7,.7],a:{fill:"#3a1312"}},{r:[10.2,10.9,.7,.7],a:{fill:"#ffd9a0"}}],mood:"calm"},{g:[{r:[6.5,5.9,3,.7]},{r:[10.5,5.9,3,.7]},{r:[8.5,10,3,.7]}],a:{fill:"#3a1312"},mood:"grumpy"},{g:[{r:[6.4,5.6,1.6,.7]},{r:[8,6.2,1.6,.7]},{r:[10.4,6.2,1.6,.7]},{r:[12,5.6,1.6,.7]},{r:[8.5,9.5,3,1.5]}],a:{fill:"#3a1312"},mood:"furious"},{g:[{g:[{r:[9,1,2,2],a:{fill:"#ffd166"}}],anim:"crit-ember-4"},{r:[9.5,0,1,1],a:{fill:"#f58967"}}],mood:"furious"}],anchors:{eyes:[{x:7,y:7,w:2,h:2,role:"eye"},{x:11,y:7,w:2,h:2,role:"eye"}],head:{top:2,right:20},hat:{cx:10,top:5,w:10},neck:{y:13.4,x0:4,x1:16}},ink:"#3a1312",limb:{style:"tail",root:[16,13.4],width:1,color:"#b8403a",spade:!0}},volt:{name:"Volt",root:[{g:[{r:[9,4,1,2]},{r:[10,3,1,1]},{r:[9,2,1,1]},{r:[10,1,1,1]}],a:{fill:"#d1a92b"}},{g:[{r:[10,0,1,1],a:{fill:"#fff1a8"}}],anim:"crit-volt-1"},{r:[5,6,10,1],a:{fill:"#f5d547"}},{r:[3,7,14,7],a:{fill:"#f5d547"}},{r:[4,14,12,1],a:{fill:"#d1a92b"}},{r:[6,7,3,1],a:{fill:"#fff1a8"}},{g:[{r:[10,12,1,1]},{r:[9,13,1,1]}],a:{fill:"#fff1a8"}},{g:[{r:[2,9,1,2]},{r:[17,9,1,2]}],arms:!0,a:{fill:"#d1a92b"},anim:"crit-volt-2"},{g:[{r:[5,15,3,1]},{r:[12,15,3,1]}],legs:!0,a:{fill:"#d1a92b"}},{g:[{r:[6,8,2,2],a:{fill:"#3a2f10"}}],anim:"crit-volt-3",role:"eye",shut:[6,9,2,.4]},{g:[{r:[12,8,2,2],a:{fill:"#3a2f10"}}],anim:"crit-volt-4",role:"eye",shut:[12,9,2,.4]},{g:[{r:[6,8,.7,.7]},{r:[12,8,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[8.4,10.2,.7,.7],a:{fill:"#3a2f10"}},{r:[9,10.8,2,.7],a:{fill:"#3a2f10"}},{r:[10.9,10.2,.7,.7],a:{fill:"#3a2f10"}},{r:[4.2,10.2,1.5,.8],a:{fill:"#f58967",opacity:"0.7"}},{r:[14.3,10.2,1.5,.8],a:{fill:"#f58967",opacity:"0.7"}}],mood:"calm"},{g:[{r:[5.5,6.9,3,.7]},{r:[11.5,6.9,3,.7]},{r:[8.5,10.6,3,.7]}],a:{fill:"#3a2f10"},mood:"grumpy"},{g:[{r:[5.4,6.5,1.6,.7]},{r:[7,7.1,1.6,.7]},{r:[11.4,7.1,1.6,.7]},{r:[13,6.5,1.6,.7]},{r:[8.5,10,3,1.6]}],a:{fill:"#3a2f10"},mood:"furious"},{g:[{g:[{r:[1,3,1,2]}],anim:"crit-volt-5"},{g:[{r:[18,4,1,2]}],anim:"crit-volt-6"}],a:{fill:"#fff1a8"},mood:"furious"}],anchors:{eyes:[{x:6,y:8,w:2,h:2,role:"eye"},{x:12,y:8,w:2,h:2,role:"eye"}],head:{top:0,right:18},hat:{cx:10,top:6,w:10},neck:{y:12.4,x0:3,x1:17}},ink:"#3a2f10",limb:{style:"arm",root:[17.4,9.4],width:1.2,color:"#d1a92b"}},moss:{name:"Moss",root:[{g:[{r:[7,3,2,1]},{r:[9.5,2,1.5,2]},{r:[11.5,3,2,1]}],a:{fill:"#2e9a56"},anim:"crit-moss-1"},{r:[7,4,6,1],a:{fill:"#47cf79"}},{r:[6,5,8,1],a:{fill:"#47cf79"}},{r:[5,6,10,9],a:{fill:"#47cf79"}},{r:[6,15,8,1],a:{fill:"#2e9a56"}},{g:[{r:[6,6,1,1]},{r:[12,5,1,1]},{r:[13,12,1,1]},{r:[6,13,1,1]}],a:{fill:"#9ae8b6"}},{g:[{r:[4,10,1,3],a:{fill:"#2e9a56"}},{g:[{r:[15,10,1,3],a:{fill:"#2e9a56"}}],anim:"crit-moss-2"}],arms:!0},{g:[{r:[6,16,2,1]},{r:[12,16,2,1]}],legs:!0,a:{fill:"#2e9a56"}},{r:[8,7,4,3],a:{fill:"#f3f5f8"}},{g:[{r:[9,7.5,2,2],a:{fill:"#0f2e1b"}}],anim:"crit-moss-3"},{g:[{r:[8,7,4,3],a:{fill:"#47cf79"}}],anim:"crit-moss-4",role:"lid",shut:[8,7,4,3]},{g:[{r:[8.4,11.4,.7,.7],a:{fill:"#0f2e1b"}},{r:[9,12,2,.7],a:{fill:"#0f2e1b"}},{r:[10.9,11.4,.7,.7],a:{fill:"#0f2e1b"}},{r:[6,11,1.3,.7],a:{fill:"#f2a7c3"}},{r:[12.7,11,1.3,.7],a:{fill:"#f2a7c3"}}],mood:"calm"},{g:[{r:[8,7,4,1.3],a:{fill:"#2e9a56"}},{r:[8.5,12,3,.7],a:{fill:"#0f2e1b"}}],mood:"grumpy"},{g:[{r:[7.6,5.6,1.6,.7]},{r:[9.2,6.2,1.6,.7]},{r:[10.8,5.6,1.6,.7]},{r:[8.5,11.4,3,1.6]}],a:{fill:"#0f2e1b"},mood:"furious"}],anchors:{eyes:[{x:8,y:7,w:4,h:3,role:"lid"}],head:{top:2,right:16},hat:{cx:10,top:4,w:7},neck:{y:12.4,x0:5,x1:15}},ink:"#0f2e1b",limb:{style:"arm",root:[15.6,10.6],width:1.1,color:"#2e9a56"}},octocat:{name:"Octocat",root:[{g:[{g:[{r:[4,14,1,2]},{r:[3,16,2,1]},{r:[7,14,1,3]},{r:[6,17,2,1]},{r:[12,14,1,3]},{r:[12,17,2,1]},{r:[15,14,1,2]},{r:[15,16,2,1]}],a:{fill:"#24292f",stroke:"#6e7781","stroke-width":"1"}},{g:[{r:[4,14,1,2]},{r:[3,16,2,1]},{r:[7,14,1,3]},{r:[6,17,2,1]},{r:[12,14,1,3]},{r:[12,17,2,1]},{r:[15,14,1,2]},{r:[15,16,2,1]}],a:{fill:"#24292f"}}],legs:!0,anim:"crit-octocat-1"},{g:[{r:[4,2,1,2]},{r:[5,3,1,1]},{r:[15,2,1,2]},{r:[14,3,1,1]},{r:[4,4,12,1]},{r:[3,5,14,7]},{r:[4,12,12,2]}],a:{fill:"#24292f",stroke:"#6e7781","stroke-width":"1"}},{g:[{r:[4,2,1,2]},{r:[5,3,1,1]},{r:[15,2,1,2]},{r:[14,3,1,1]},{r:[4,4,12,1]},{r:[3,5,14,7]},{r:[4,12,12,2]}],a:{fill:"#24292f"}},{g:[{r:[6,6,8,1]},{r:[5,7,10,4]},{r:[6,11,8,1]}],a:{fill:"#f4c7ad"}},{g:[{r:[7,8,2,2],a:{fill:"#2b1d16"}}],anim:"crit-octocat-2",role:"eye",shut:[7,9,2,.4]},{g:[{r:[11,8,2,2],a:{fill:"#2b1d16"}}],anim:"crit-octocat-3",role:"eye",shut:[11,9,2,.4]},{g:[{r:[7,8,.7,.7]},{r:[11,8,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[9,10.4,2,.6],a:{fill:"#2b1d16"}},{r:[5.4,10,1.2,.6],a:{fill:"#e8909c"}},{r:[13.4,10,1.2,.6],a:{fill:"#e8909c"}}],mood:"calm"},{g:[{r:[6.5,6.8,3,.6]},{r:[10.5,6.8,3,.6]},{r:[8.5,10.6,3,.6]}],a:{fill:"#2b1d16"},mood:"grumpy"},{g:[{r:[6.4,6.4,1.6,.6]},{r:[8,7,1.6,.6]},{r:[10.4,7,1.6,.6]},{r:[12,6.4,1.6,.6]},{r:[8.5,10.2,3,1.2]}],a:{fill:"#2b1d16"},mood:"furious"},{g:[{g:[{r:[1,4,1,1]}],anim:"crit-octocat-4"},{g:[{r:[18,5,1,1]}],anim:"crit-octocat-5"}],a:{fill:"#f3e9c6"},mood:"furious"}],anchors:{eyes:[{x:7,y:8,w:2,h:2,role:"eye"},{x:11,y:8,w:2,h:2,role:"eye"}],head:{top:2,right:17},hat:{cx:10,top:4,w:12},neck:{y:11.6,x0:4,x1:16}},ink:"#2b1d16",limb:{style:"tentacle",root:[16.6,12.4],width:1,color:"#24292f"}}},di=[{id:"clawd",name:"Clawd",sprite:null},...Object.entries(sg).map(([e,t])=>({id:e,name:t.name,sprite:t}))];function nu(e){return di.find(t=>t.id===e)||di[0]}const ru=10,wa=12,og=19,cg=17,N=e=>Math.round(e*1e4)/1e4;function yn(e,{seated:t=!1}={}){let n=1/0,i=1/0,l=-1/0,a=-1/0;const s=o=>{if(!o.mood&&!(t&&o.legs&&!o.keepSeated)){if(o.r){const[u,c,f,d]=o.r;n=Math.min(n,u),i=Math.min(i,c),l=Math.max(l,u+f),a=Math.max(a,c+d);return}o.g.forEach(s)}};return e.root.forEach(s),{x:n,y:i,w:l-n,h:a-i}}function va(e,{x0:t,sitting:n,height:i=wa}){const l=yn(e),a=i/l.h,s=n?(({y:u,h:c})=>u+c)(yn(e,{seated:!0})):l.y+l.h,o=(n?cg:og)-a*s;return{scale:a,tx:N(t+8.5-a*(l.x+l.w/2)),ty:N(o),top:N(o+a*l.y),drop:n?N(a*(l.y+l.h-s)):0}}const ug=.75,ol=(e,t=ug)=>({fill:"none",stroke:e,"stroke-width":t,"stroke-linecap":"square"});function dg(e){const t=yn(e),n=t.x+t.w/2,i=l=>l.r?{...l,r:[N(l.r[0]+(l.r[0]+l.r[2]/2l.legs?[{g:[l],cls:"tama-legs-a"},{g:[i(l)],cls:"tama-legs-b"}]:[l])}const hg=new Set(["happy","x","down"]);function fg(e){if(e.length===1){const{x:n,y:i,w:l}=e[0];return[{p:`M${N(n-.3)} ${N(i-.7)} l${N(l/2+.3)} -0.8 l${N(l/2+.3)} 0.8`}]}const t=e.reduce((n,i)=>n+i.x+i.w/2,0)/e.length;return e.map(({x:n,y:i,w:l})=>n+l/2({p:`M${o} ${N(u+.75*f)} l${N(c/2)} ${N(-f/2)} l${N(c/2)} ${N(f/2)}`}))}]:t==="x"?[{a:ol(l),g:n.map(({x:o,y:u,w:c,h:f})=>({p:`M${N(o+.1)} ${N(u+.1)} L${N(o+c-.1)} ${N(u+f-.1)} M${N(o+c-.1)} ${N(u+.1)} L${N(o+.1)} ${N(u+f-.1)}`}))}]:t==="down"?[{a:{fill:l},g:n.map(({x:o,y:u,w:c,h:f})=>({r:[o,N(u+.45*f),c,N(.55*f)]}))}]:[]}function mg(e,t=!1){const{head:n}=e.anchors,i=N(t?yn(e).x-1.4:n.right+.4);return[{cls:"tama-startle",a:{fill:"#f2c14e"},g:[{r:[i,N(n.top+.5),1,3]},{r:[i,N(n.top+4.1),1,1]}]}]}function gg(e){const{cx:t,top:n,w:i}=e.anchors.hat;return`translate(${t} ${n}) scale(${N(i/12)}) translate(-9 -9)`}function yg(e,t){if(t==="goggles"){const{eyes:n}=e.anchors,i=n.reduce((o,u)=>o+u.y+u.h/2,0)/n.length,l=Math.min(...n.map(o=>o.x))-2,a=Math.max(...n.map(o=>o.x+o.w))+2,s={rx:1,fill:"#7fd1e6","fill-opacity":.45,stroke:"#2b2f36","stroke-width":.5};return[{cls:"tama-goggles",g:[{r:[N(l),N(i-.4),N(a-l),.8],a:{fill:"#2b2f36"}},...n.map(o=>({r:[N(o.x-.6),N(o.y-.6),N(o.w+1.2),N(o.h+1.2)],a:s}))]}]}if(t==="scarf"){const{y:n,x0:i,x1:l}=e.anchors.neck,a=[];for(let s=i+2;s+.7<=l;s+=3)a.push({r:[N(s),n,.7,1.6]});return[{cls:"tama-scarf",g:[{r:[i,n,N(l-i),1.6],a:{fill:"#d64541"}},{g:a,a:{fill:"#f4f4f6"}},{r:[N(i-3),N(n+.3),3.6,1.1],cls:"tama-scarf-tail",a:{fill:"#d64541"}}]}]}return[]}function Is(e,t){const n=/^#([0-9a-f]{6})$/i.exec(e||"");if(!n)return e;const i=Number.parseInt(n[1],16),[l,a,s]=[i>>16&255,i>>8&255,i&255].map(x=>x/255),o=Math.max(l,a,s),u=Math.min(l,a,s),c=o-u;if(c===0)return e.toLowerCase();const d=(((o===l?(a-s)/c%6:o===a?(s-l)/c+2:(l-a)/c+4)*60+t)%360+360)%360,p=c*(1-Math.abs(d/60%2-1)),[h,m,b]=d<60?[c,p,0]:d<120?[p,c,0]:d<180?[0,c,p]:d<240?[0,p,c]:d<300?[p,0,c]:[c,0,p];return`#${[h,m,b].map(x=>Math.round((x+u)*255).toString(16).padStart(2,"0")).join("")}`}const _a={pint:{reach:2.6,at:.42},mug:{reach:2.2,at:.55},spoon:{reach:2.4,at:.55},can:{reach:2.6,at:.45},leash:{reach:2.4,at:.65}};function zi(e,t){const n=yn(e),{reach:i,at:l}=_a[t];return[N(e.limb.root[0]+i),N(n.y+l*n.h)]}function bg(e,t,{scale:n,tx:i,ty:l}){const[a,s]=zi(e,t);return[N(i+n*a),N(l+n*s)]}function Os({scale:e,tx:t,ty:n},[i,l]){return[N((i-t)/e),N((l-n)/e)]}function Bl(e,t,n=zi(e,t)){const{style:i,root:[l,a],width:s,color:o,outline:u,spade:c}=e.limb,[f,d]=n,p=(m,b,x,w)=>({r:[N(m),N(b),N(x),N(w)]});if(i==="arm")return[{a:{fill:o},g:[p(l,a,f-l,s),p(f-s,Math.min(a,d),s,Math.abs(d-a)+s),p(f-s*1.1,d-s*.4,s*1.4,s)]}];if(i==="tentacle"){const m=Math.max(2,Math.ceil(Math.max(Math.abs(f-l),Math.abs(d-a))/(.75*s))),b=[];for(let x=0;x<=m;x++)b.push(p(l+(f-l)*x/m-.45*s,a+(d-a)*x/m-.45*s,.95*s,.95*s));return[{a:{fill:o},g:[...b,p(f+.3*s,d-.9*s,.8*s,.8*s)]}]}const h=[p(l,a,f-l,s),p(f-s,d,s,a-d+s),p(f-s,d-s*.2,s*1.6,s)];return[...u?[{a:{fill:o,stroke:u,"stroke-width":1},g:h}]:[],{a:{fill:o},g:[...h,...c?[p(f+.4,d-.9,1.2,1.2)]:[]]}]}function xa(e,t=!1,n=void 0){return e.flatMap(i=>{var a;if(i.mood)return[];const l=((a=i.a)==null?void 0:a.fill)??n;return i.r?t?[{r:i.r,fill:l}]:[]:xa(i.g,t||!!i.arms,l)})}function kg(e){return xa(e.root).length===0}function wg(e){const t=xa(e.root);if(t.length)return t.map(({r:[i,l,a],fill:s},o)=>({r:[i,N(l-4),a,4],a:{fill:s},cls:o?"tama-cheer tama-cheer2":"tama-cheer"}));const n=yn(e);return[{cls:"tama-cheer",g:Bl(e,null,[N(e.limb.root[0]+1.6),N(n.y+.12*n.h)])}]}const iu="#ff3b2f",vg="#f3f5f8";function _g(e){let t=null;const n=(d,p)=>{const h=p||d.mood==="furious";if(d.r){h&&d.r[2]>=2.4&&d.r[3]>=1.2&&(!t||d.r[2]>t[2])&&(t=d.r);return}(d.g||[]).forEach(m=>{n(m,h)})};if(e.root.forEach(d=>{n(d,!1)}),!t)return[];const[i,l,a,s]=t,o=l+s*.3,u=l+s*.7,c=a/4-.05;let f=`M${N(i+.1)} ${N(u)}`;for(let d=1;d<=4;d++)f+=` L${N(i+.1+c*d)} ${N(d%2?o:u)}`;return[{p:f,a:{fill:"none",stroke:vg,"stroke-width":.35,"stroke-linejoin":"miter"}}]}const hi=[{id:"hanken",name:"Hanken Grotesk",face:"Hanken Grotesk",stack:"'Hanken Grotesk', -apple-system, system-ui, sans-serif"},{id:"inter",name:"Inter",face:"Inter",stack:"'Inter', -apple-system, system-ui, sans-serif"},{id:"system-sans",name:"System sans",face:"system-ui",stack:"-apple-system, system-ui, sans-serif"},{id:"plex-mono",name:"IBM Plex Mono",face:"IBM Plex Mono",mono:!0,stack:"'IBM Plex Mono', ui-monospace, 'JetBrains Mono', Menlo, monospace"},{id:"jetbrains-mono",name:"JetBrains Mono",face:"JetBrains Mono",mono:!0,stack:"'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace"},{id:"sf-mono",name:"SF Mono",face:"SF Mono",mono:!0,stack:"'SF Mono', ui-monospace, Menlo, monospace"},{id:"menlo",name:"Menlo",face:"Menlo",mono:!0,stack:"Menlo, Monaco, monospace"}],lu={ui:"hanken",code:"plex-mono"};function au(e,t){return hi.find(n=>n.id===e)||hi.find(n=>n.id===lu[t])}const Ye=H([]);let xg=1;function bn(e,t="info",n=4e3){const i=xg++;return Ye.value=[...Ye.value,{id:i,message:e,kind:t,ms:n,show:!1}],requestAnimationFrame(()=>{Ye.value=Ye.value.map(l=>l.id===i?{...l,show:!0}:l)}),setTimeout(()=>{Ye.value=Ye.value.map(l=>l.id===i?{...l,show:!1}:l),setTimeout(()=>{Ye.value=Ye.value.filter(l=>l.id!==i)},200)},n),i}function Sg(){const e=Ye.value;return r("div",{id:"toast-container",children:e.map(t=>r("div",{class:`toast toast-${t.kind}${t.show?" toast-show":""}`,children:t.message},t.id))})}let Pt=[];function ye(e,t){Pt.push({name:e,detail:t||null,t:Math.floor(Date.now()/1e3)}),Pt.length>500&&(Pt=Pt.slice(-500))}function cl(e){if(!Pt.length)return;const t=JSON.stringify({events:Pt});Pt=[],e&&navigator.sendBeacon?navigator.sendBeacon("/api/events",new Blob([t],{type:"application/json"})):fetch("/api/events",{method:"POST",headers:{"Content-Type":"application/json"},body:t,keepalive:!0}).catch(()=>{})}typeof addEventListener=="function"&&(setInterval(()=>cl(!1),5e3),addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&cl(!0)}),addEventListener("pagehide",()=>cl(!0)));const zl={claude:{label:"Claude",glyph:"✻",className:"icon-claude"},codex:{label:"Codex",glyph:"⬡",className:"icon-codex"}};function kn(e,t,n=`${t}s`){return`${e} ${e===1?t:n}`}function Se(e){return(e==null?void 0:e.name)||(e==null?void 0:e.agent)||"shell"}function nt(e){const t=e.lastIndexOf(":"),n=e.slice(0,t),i=e.slice(t+1);return`session=${encodeURIComponent(n)}&index=${encodeURIComponent(i)}`}function $g(e){return`pane_id=${encodeURIComponent(e)}`}function Pe(e){if(!e)return"";const t=Math.max(0,Math.floor(Date.now()/1e3)-e);return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:`${Math.floor(t/86400)}d`}function Cg(e){return e?{"approve askuserquestion":"needs answer","permission prompt":"needs approval","dialog open":"needs input"}[e.toLowerCase()]||e.toLowerCase():"needs input"}function su(e){if(!e)return null;const t=e.toLowerCase();return t==="permission prompt"?"permission":t==="approve askuserquestion"?"question":"dialog"}function ou(e,t){if(!e)return e;const n=e.split("/");for(let i=1;is!==e&&s&&s.split("/").slice(-i).join("/")===l))return l}return e}function cu(e){if(!e)return null;const t=Math.floor(e.age_s/86400),n=Math.floor(e.age_s%86400/3600),i=t>0?`${t}d ${n}h`:`${n}h`;return{label:e.rss_gb>=2?`${e.rss_gb}G`:`${t}d`,title:`Claude is using ${e.rss_gb}GB after ${i} — consider exiting and resuming this session`,cls:`mem-${e.tier}`}}function rr(e,t){return e?`https://github.com/${e}/pull/${t}`:null}function ji(e){return e==="merged"?{cls:"is-merged",suffix:" (merged)"}:e==="closed"?{cls:"is-closed",suffix:" (closed)"}:{cls:"",suffix:""}}async function ie(e,t,n={}){const i=n.method||"GET";let l;try{l=await fetch(t,n)}catch(s){return ye(`api:${e}`,{path:t,method:i,ok:!1}),bn(`${e} failed: ${s.message}`,"bad",6e3),null}let a={};try{a=await l.json()}catch{}if(!l.ok||a.ok===!1){ye(`api:${e}`,{path:t,method:i,ok:!1});const s=a.error||a.detail||`HTTP ${l.status}`;return bn(`${e} failed: ${s}`,"bad",6e3),null}return ye(`api:${e}`,{path:t,method:i,ok:!0}),a}async function Tg(e,t){var a,s;let n;try{n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),...typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"?{signal:AbortSignal.timeout(1e4)}:{}})}catch(o){return{ok:!1,status:0,detail:(o==null?void 0:o.message)||String(o)}}let i={};try{i=await n.json()||{}}catch{}const l=typeof i.detail=="string"?i.detail:typeof i.error=="string"?i.error:((s=(a=i.detail)==null?void 0:a[0])==null?void 0:s.msg)||`HTTP ${n.status}`;return{ok:n.ok,status:n.status,detail:l}}const me=H({loaded:!1,ui:{},windows:{},commands:[]}),G=()=>me.value;async function Hi(){try{const e=await fetch("/api/prefs");if(!e.ok)throw new Error(`HTTP ${e.status}`);const t=await e.json();return me.value={...me.value,ui:t.ui||{},windows:t.windows||{},commands:t.commands||[],loaded:!0},await Og(),me.value}catch{return me.value={...me.value,loaded:!1},null}}function Hr(){return G().commands||[]}async function Eg({label:e,exec:t}){if(!G().loaded)return!1;const n=await ie("add command","/api/prefs/commands",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:e,exec:""})});return n?(me.value={...G(),commands:n.commands},!0):!1}async function Pg(e,{label:t,exec:n}){if(!G().loaded)return!1;const i=await ie("update command",`/api/prefs/commands/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:t,exec:n||""})});return i?(me.value={...G(),commands:i.commands},!0):!1}async function Ag(e){if(!G().loaded)return!1;const t=await ie("delete command",`/api/prefs/commands/${encodeURIComponent(e)}`,{method:"DELETE"});return t?(me.value={...G(),commands:t.commands},!0):!1}async function Mg(e){if(!G().loaded)return!1;const t=await ie("reorder commands","/api/prefs/commands",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({labels:e})});return t?(me.value={...G(),commands:t.commands},!0):!1}async function $e(e,t){if(!G().loaded&&(await Hi(),!G().loaded))return!1;const n={...G().ui};me.value={...G(),ui:{...G().ui,...e}};const i=await ie("save prefs","/api/prefs/ui",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{...e,writer:t}:e)});return i?(me.value={...G(),ui:i.ui},!0):(me.value={...G(),ui:n},!1)}function Lg(e){me.value={...G(),ui:e}}function Cr(e){if(!e)return null;const t=G().windows[e];if(!t)return null;const n=t.notes||"",i=t.tags||[],l=t.pinned_files||[];return!n&&!i.length&&!l.length?null:{notes:n,tags:i,pinned_files:l}}async function qr(e,{notes:t,tags:n,pinned_files:i}){if(!G().loaded&&(await Hi(),!G().loaded))return!1;const l=G().windows[e],a=l||{},s={...a,notes:t??a.notes,tags:n??a.tags,pinned_files:i??a.pinned_files};me.value={...G(),windows:{...G().windows,[e]:s}};const o={};t!==void 0&&(o.notes=t),n!==void 0&&(o.tags=n),i!==void 0&&(o.pinned_files=i);const u=await ie("save annotation",`/api/prefs/windows/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!u){const c={...G().windows};return l===void 0?delete c[e]:c[e]=l,me.value={...G(),windows:c},!1}return me.value={...G(),windows:{...G().windows,[e]:{...G().windows[e]||{},...u.annotation}}},!0}function uu(e){if(!e)return[];const t=G().windows[e];return[...(t==null?void 0:t.pinned_files)||[]]}function Ig(e,t){if(!e||!t)return Promise.resolve(!1);const n=uu(e),i=n.includes(t)?n.filter(l=>l!==t):[...n,t];return qr(e,{pinned_files:i})}async function Og(){const e={"periscope:sessionOrder":"session_order","periscope:collapsedSessions":"collapsed_sessions","periscope:view":"view"};if(!Object.keys(e).some(l=>localStorage.getItem(l)!==null))return;const n=G().ui;if(!n.session_order&&!n.collapsed_sessions&&!n.view){const l={};for(const[a,s]of Object.entries(e)){const o=localStorage.getItem(a);if(o!==null)try{l[s]=s==="view"?o:JSON.parse(o)}catch{}}if(Object.keys(l).length&&!await $e(l))return}for(const l of Object.keys(e))localStorage.removeItem(l)}function fi(){const e=G().ui||{};return[...e.track_order||e.repo_order||[]]}function Dg(e,t){return $e({track_order:e},t)}function ir(){return{...(G().ui||{}).tabs_by_track||{}}}function Rg(e){return $e({tabs_by_track:e})}function Sa(){var e;return{...((e=G().ui)==null?void 0:e.branch_order_by_track)||{}}}function lr(){var e;return{...((e=G().ui)==null?void 0:e.rail_collapsed)||{}}}function du(e,t){const n=lr();return n[e]=t,$e({rail_collapsed:n})}function Fg(){var e;return((e=G().ui)==null?void 0:e.last_selected)||null}function gt(e){return $e({last_selected:e})}function Ng(){var e;return((e=G().ui)==null?void 0:e.launch_profile)||"default"}function Bg(e){return $e({launch_profile:e})}function hu(){var e;return nu((e=G().ui)==null?void 0:e.tama_critter).id}function zg(e){return $e({tama_critter:e})}function ar(e){var t;return au((t=G().ui)==null?void 0:t[`${e}_font`],e)}function jg(e,t){return $e({[`${e}_font`]:t})}const Hg={needs_input:!0,done:!0,ci_failed:!0,pr_merged:!0,usage:!0,quiet_when_focused:!0,group:!0,badge:!0};function pi(){var e;return{...Hg,...((e=G().ui)==null?void 0:e.notify)||{}}}function qg(e,t){return $e({notify:{...pi(),[e]:t}})}function $a(){var e;return[...((e=G().ui)==null?void 0:e.pinned_pids)||[]]}function Ug(e){return $e({pinned_pids:e})}function Wg(e){const t=$a(),n=t.includes(e)?t.filter(i=>i!==e):[...t,e];return Ug(n)}function Kg(e){var t;return((t=G().ui)==null?void 0:t[e])??null}function Ds(e,t){return $e({[e]:t})}function Ca(e){var t;return!!((t=G().ui)!=null&&t[`${e}_hidden`])}function Vg(e,t){return $e({[`${e}_hidden`]:t})}function fu(e){var t,n;return((n=(t=G().ui)==null?void 0:t.detail_mode_by_pid)==null?void 0:n[e])||null}function jl(e,t){var i;const n={...((i=G().ui)==null?void 0:i.detail_mode_by_pid)||{}};return n[e]=t,$e({detail_mode_by_pid:n})}function Ta(){const e=G().ui||{};return{merged:e.clawd_merged,furious:e.clawd_furious}}async function pu(e,t){var n;return G().loaded||await Hi(),!G().loaded||((n=Ta()[e])==null?void 0:n.slice(0,10))===t.slice(0,10)?!1:$e({[`clawd_${e}`]:t})}function Ve(){return typeof window<"u"&&typeof window.__TAURI_INTERNALS__<"u"&&typeof window.__TAURI_INTERNALS__.invoke=="function"}function $n(e,t){return window.__TAURI_INTERNALS__.invoke(e,t||{})}async function Ea(e,t){const n=window.__TAURI_INTERNALS__.transformCallback(i=>{i!=null&&i.payload&&t(i.payload)});await $n("plugin:event|listen",{event:e,target:{kind:"Any"},handler:n})}async function Gg(e){if(Ve())try{const t=e>0?Math.floor(e):null;await $n("plugin:window|set_badge_count",{count:t})}catch(t){console.warn("[tauri] setBadgeCount failed:",t)}}async function mu({title:e,body:t,target:n="",...i}){if(Ve())try{await $n("plugin:event|emit",{event:"periscope:notify",payload:{title:e,body:t,target:n,...i}})}catch(l){console.warn("[tauri] notify failed:",l)}}async function Jg(e){if(Ve())try{await Ea("periscope:notification-clicked",e)}catch(t){console.warn("[tauri] notification-click listener failed:",t)}}async function Qg(e){if(Ve())try{await Ea("periscope:notification-opened",e)}catch(t){console.warn("[tauri] notification-opened listener failed:",t)}}async function Yg(e){if(Ve())try{await Ea("periscope:notification-action",e)}catch(t){console.warn("[tauri] notification-action listener failed:",t)}}async function Zg(e){if(Ve())try{await $n("plugin:event|emit",{event:"periscope:notify-categories",payload:e})}catch(t){console.warn("[tauri] setNotifyCategories failed:",t)}}function qi(e){if(Ve())return $n("plugin:opener|open_url",{url:e}).catch(t=>{console.warn("[tauri] open_url failed:",t)}),!0;try{if(window.open(e,"_blank","noopener,noreferrer"))return!0}catch(t){console.warn("[periscope] window.open threw:",t)}try{const t=document.createElement("a");return t.href=e,t.target="_blank",t.rel="noopener noreferrer",document.body.appendChild(t),t.click(),t.remove(),!0}catch(t){console.warn("[periscope] anchor-click fallback threw:",t)}return!1}function Xg(){Ve()&&document.addEventListener("click",e=>{const t=e.target.closest("a[href]");if(!t)return;let n;try{n=new URL(t.href)}catch{return}n.protocol!=="http:"&&n.protocol!=="https:"||n.origin!==location.origin&&(e.preventDefault(),e.stopPropagation(),$n("plugin:opener|open_url",{url:n.href}).catch(i=>{console.warn("[tauri] open_url failed:",i)}))},!0)}function e1(e){return!!(e!=null&&e.asked_question)&&!(e!=null&&e.waiting_for)}function Rs(e,t,n){const i=new Set((t||[]).filter(a=>a.state===n).map(a=>a.pid)),l=new Set;for(const a of e)i.has(a)&&l.add(a);return l}function Pa(e,t,n,i=new Set){const l=Ma(e),a=(e||[]).filter(o=>o.state==="needs-input").filter(o=>!i.has(o.pid)).map(o=>({kind:"live",pid:o.pid,w:o})),s=(t||[]).filter(o=>o.kind==="need_human").filter(o=>!n.has(o.id)).filter(o=>!Aa(o,l)).sort((o,u)=>u.ts-o.ts).map(o=>({kind:"event",id:o.id,pane_id:o.pane_id,target:o.target,w:l[o.target]||null,message:o.message,ts:o.ts,session:o.session,name:o.name}));return[...a,...s]}function gu(e,t,n,i=new Set){const l=Ma(e),a=(e||[]).filter(u=>u.state==="done").filter(u=>!i.has(u.pid)).map(u=>({kind:"live",pid:u.pid,w:u})),s=new Set(a.map(u=>u.w.target)),o=(t||[]).filter(u=>u.kind==="done").filter(u=>!n.has(u.id)).filter(u=>!s.has(u.target)).filter(u=>!Aa(u,l)).sort((u,c)=>c.ts-u.ts).map(u=>({kind:"event",id:u.id,pane_id:u.pane_id,target:u.target,w:l[u.target]||null,message:u.message,ts:u.ts,session:u.session,name:u.name}));return[...a,...o]}function Aa(e,t){const n=t[e.target];return n?Math.max(n.focused_at||0,n.acted_at||0)>e.ts:!1}function t1(e){return e.length}const n1=600,r1=3600;function yu(e,t){const n=(t||0)-(e||0);return n>=r1?"urgent":n>=n1?"stale":"fresh"}function bu(e,t,n=new Set){var a;const i=Ma(e),l=new Map;for(const s of t||[]){if(s.kind!=="need_human"||n.has(s.id)||Aa(s,i))continue;const o=(a=i[s.target])==null?void 0:a.pid;if(!o)continue;const u=l.get(o);(u===void 0||s.ts!0){var u,c;const s=bu(e,t,n),o=new Map;for(const f of Pa(e,t,n,i)){if(!a(f.w))continue;const d=((u=f.w)==null?void 0:u.pid)!=null?`pid:${f.w.pid}`:`target:${f.target}`,p=Math.min(f.kind==="event"?f.ts:f.w.needs_since||l,...((c=f.w)==null?void 0:c.pid)!=null&&s.has(f.w.pid)?[s.get(f.w.pid)]:[]),h=o.get(d);o.set(d,{row:(h==null?void 0:h.row.kind)==="live"?h.row:f,since:h?Math.min(h.since,p):p})}return o}function wu(e){return(e||[]).filter(t=>t.state==="working").map(t=>({kind:"live",pid:t.pid,w:t}))}function i1(e,t){const n={};for(const i of t||[])n[i.pid]=i;return(e||[]).map(i=>n[i]).filter(Boolean)}function l1(e){return(e||[]).filter(t=>t.kind==="done"||t.kind==="info")}function Ma(e){const t={};for(const n of e||[])t[n.target]=n;return t}const La=er;let Fs=!1;function jt(e){e&&yt((de.value||[]).find(t=>t.target===e))}function yt(e){e!=null&&e.pid&&(ke.value=`pane:${e.pid}`,gt({kind:"pane",pid:e.pid}))}function vu(e){e1(e)&&(ht.value=new Set([...ht.value,e.pid])),yt(e)}function _u(e){e!=null&&e.pid&&(ft.value=new Set([...ft.value,e.pid]))}function xu(e){_u(e),yt(e)}function a1(){Fs||(Fs=!0,Jg(e=>jt(e)))}function Su(e,t){!e||!t||(ke.value=`review:${e}/${t.replace(/\//g,"--")}`,gt({kind:"review",repo:e,branch:t}))}function Ia(){ke.value="reviews",gt({kind:"reviews"})}const ul=[{key:"all",label:"all"},{key:"needs-input",label:"needs input"},{key:"working",label:"working"},{key:"done",label:"done"},{key:"idle",label:"idle"},{key:"agents",label:"agents"},{key:"shell",label:"shells"},{key:"ci-bad",label:"CI ✗"}];function s1(){const[e,t]=B(!1),n=ne(null),i=Il.value,l=(ul.find(o=>o.key===i)||ul[0]).label,a=Pi(()=>t(!1),[]);He(a,e),j(()=>{if(!e)return;function o(u){n.current&&!n.current.contains(u.target)&&t(!1)}return document.addEventListener("click",o),()=>document.removeEventListener("click",o)},[e]);function s(o){Il.value=o,ye("filter.use"),t(!1)}return r("div",{class:"tb-dd","data-dd":"filter",ref:n,children:[r("button",{type:"button",class:"filter-btn tb-dd-toggle",id:"filter-dd-toggle","aria-haspopup":"menu","aria-expanded":e?"true":"false",title:"filter by state",onClick:o=>{o.stopPropagation(),t(u=>!u)},children:[r("span",{id:"filter-dd-label",children:l}),r("span",{class:"tb-dd-chev","aria-hidden":"true",children:"▾"})]}),r("div",{class:"tb-dd-menu",id:"filter-dd-menu",role:"menu",hidden:!e,children:ul.map(o=>r("button",{"data-filter":o.key,class:`tb-dd-item${o.key===i?" active":""}`,role:"menuitem",onClick:()=>s(o.key),children:o.label},o.key))})]})}const $u=Vt(()=>Ca("rail")),mi=Vt(()=>Ca("side"));function Hl(e){return Vg(e,!Ca(e))}function Ns({side:e,shown:t}){return r("svg",{width:"16",height:"12",viewBox:"0 0 16 12","aria-hidden":"true",children:[r("rect",{x:"0.5",y:"0.5",width:"15",height:"11",rx:"1.5",fill:"none",stroke:"currentColor"}),r("rect",{x:e==="left"?2:10,y:"2",width:"4",height:"8",rx:"0.5",fill:t?"currentColor":"none",stroke:"currentColor","stroke-width":"0.75"})]})}function o1(){const e=!$u.value,t=!mi.value;return r("span",{class:"panel-toggles",children:[r("button",{type:"button",class:"filter-btn is-action panel-toggle","aria-pressed":e,title:`${e?"Hide":"Show"} the navigator (⌘B)`,onClick:()=>Hl("rail"),children:r(Ns,{side:"left",shown:e})}),r("button",{type:"button",class:"filter-btn is-action panel-toggle","aria-pressed":t,title:`${t?"Hide":"Show"} the context column (⌥⌘B)`,onClick:()=>Hl("side"),children:r(Ns,{side:"right",shown:t})})]})}async function Cu(e){const t=Un.value;Un.value=e;const n=await ie("spawn account","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({spawn_account:e})});return n||(Un.value=t),!!n}function c1(){if(!Sn())return null;const e=[{id:null,label:"auto"},...at.value],t=Un.value||null,n=sn.value;return r("div",{class:"spawn-acct",title:`which account new Claude panes launch on +`;break}case-2:{s=t?" ":" ";break}case-1:{if(!t&&l)continue;s=" ";break}default:s=String.fromCharCode(a)}l=a===-2,i.push(s)}return i.join("")}function _p(e){const i={constructs:Ic([bp,...(e||{}).extensions||[]]),content:l(Rh),defined:[],document:l(Nh),flow:l(rp),lazy:{},string:l(ap),text:l(sp)};return i;function l(a){return s;function s(o){return kp(i,a,o)}}}function xp(e){for(;!Nc(e););return e}const $s=/[\0\t\n\r]/g;function Sp(){let e=1,t="",n=!0,i;return l;function l(a,s,o){const u=[];let c,p,d,f,h;for(a=t+(typeof a=="string"?a.toString():new TextDecoder(s||void 0).decode(a)),d=0,t="",n&&(a.charCodeAt(0)===65279&&d++,n=void 0);d0){const Fe=J.tokenStack[J.tokenStack.length-1];(Fe[1]||Es).call(J,void 0,Fe[0])}for(D.position={start:ut(P.length>0?P[0][1].start:{line:1,column:1,offset:0}),end:ut(P.length>0?P[P.length-2][1].end:{line:1,column:1,offset:0})},ae=-1;++ae":""))+")"})}return f;function f(){let h=Vc,m,b,x;if(a(u,c,p[p.length-1]||void 0)&&(h=Bp(n(u,p)),h[0]===As))return h;if("children"in u&&u.children){const w=u;if(w.children&&h[0]!==Fp)for(b=-1+s,x=p.concat(w);b>-1&&b0?{type:"text",value:v}:void 0),v===!1?f.lastIndex=g+1:(m!==g&&C.push({type:"text",value:c.value.slice(m,g)}),Array.isArray(v)?C.push(...v):v&&C.push(v),m=g+y[0].length,w=!0),!f.global)break;y=f.exec(c.value)}return w?(m?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],i=n.indexOf(")");const l=Ps(e,"(");let a=Ps(e,")");for(;i!==-1&&l>a;)e+=n.slice(0,i+1),n=n.slice(i+1),i=n.indexOf(")"),a++;return[e,n]}function Gc(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||zt(n)||Ni(n))&&(!t||n!==47)}function tm(){this.buffer()}function nm(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function rm(){this.buffer()}function im(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function lm(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=je(this.sliceSerialize(e)).toLowerCase(),n.label=t}function am(e){this.exit(e)}function sm(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=je(this.sliceSerialize(e)).toLowerCase(),n.label=t}function om(e){this.exit(e)}function cm(){return{enter:{gfmFootnoteCallString:tm,gfmFootnoteCall:nm,gfmFootnoteDefinitionLabelString:rm,gfmFootnoteDefinition:im},exit:{gfmFootnoteCallString:lm,gfmFootnoteCall:am,gfmFootnoteDefinitionLabelString:sm,gfmFootnoteDefinition:om}}}function um(){return{canContainEols:["delete"],enter:{strikethrough:dm},exit:{strikethrough:hm}}}function dm(e){this.enter({type:"delete",children:[]},e)}function hm(e){this.exit(e)}function fm(){return{enter:{table:pm,tableData:Ms,tableHeader:Ms,tableRow:gm},exit:{codeText:ym,table:mm,tableData:ul,tableHeader:ul,tableRow:ul}}}function pm(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function mm(e){this.exit(e),this.data.inTable=void 0}function gm(e){this.enter({type:"tableRow",children:[]},e)}function ul(e){this.exit(e)}function Ms(e){this.enter({type:"tableCell",children:[]},e)}function ym(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,bm));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function bm(e,t){return t==="|"?t:e}function km(){return{exit:{taskListCheckValueChecked:Ls,taskListCheckValueUnchecked:Ls,paragraph:wm}}}function Ls(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function wm(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const i=n.children[0];if(i&&i.type==="text"){const l=t.children;let a=-1,s;for(;++a0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const Lm={tokenize:zm,partial:!0};function Im(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Fm,continuation:{tokenize:Nm},exit:Bm}},text:{91:{name:"gfmFootnoteCall",tokenize:Rm},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Om,resolveTo:Dm}}}}function Om(e,t,n){const i=this;let l=i.events.length;const a=i.parser.gfmFootnotes||(i.parser.gfmFootnotes=[]);let s;for(;l--;){const u=i.events[l][1];if(u.type==="labelImage"){s=u;break}if(u.type==="gfmFootnoteCall"||u.type==="labelLink"||u.type==="label"||u.type==="image"||u.type==="link")break}return o;function o(u){if(!s||!s._balanced)return n(u);const c=je(i.sliceSerialize({start:s.end,end:i.now()}));return c.codePointAt(0)!==94||!a.includes(c.slice(1))?n(u):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),t(u))}}function Dm(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const i={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},l={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};l.end.column++,l.end.offset++,l.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},l.end),end:Object.assign({},e[e.length-1][1].start)},s={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},o=[e[n+1],e[n+2],["enter",i,t],e[n+3],e[n+4],["enter",l,t],["exit",l,t],["enter",a,t],["enter",s,t],["exit",s,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",i,t]];return e.splice(n,e.length-n+1,...o),e}function Rm(e,t,n){const i=this,l=i.parser.gfmFootnotes||(i.parser.gfmFootnotes=[]);let a=0,s;return o;function o(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),u}function u(d){return d!==94?n(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(d){if(a>999||d===93&&!s||d===null||d===91||oe(d))return n(d);if(d===93){e.exit("chunkString");const f=e.exit("gfmFootnoteCallString");return l.includes(je(i.sliceSerialize(f)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(d)}return oe(d)||(s=!0),a++,e.consume(d),d===92?p:c}function p(d){return d===91||d===92||d===93?(e.consume(d),a++,c):c(d)}}function Fm(e,t,n){const i=this,l=i.parser.gfmFootnotes||(i.parser.gfmFootnotes=[]);let a,s=0,o;return u;function u(m){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(m){return m===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",p):n(m)}function p(m){if(s>999||m===93&&!o||m===null||m===91||oe(m))return n(m);if(m===93){e.exit("chunkString");const b=e.exit("gfmFootnoteDefinitionLabelString");return a=je(i.sliceSerialize(b)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),f}return oe(m)||(o=!0),s++,e.consume(m),m===92?d:p}function d(m){return m===91||m===92||m===93?(e.consume(m),s++,p):p(m)}function f(m){return m===58?(e.enter("definitionMarker"),e.consume(m),e.exit("definitionMarker"),l.includes(a)||l.push(a),re(e,h,"gfmFootnoteDefinitionWhitespace")):n(m)}function h(m){return t(m)}}function Nm(e,t,n){return e.check(wr,t,e.attempt(Lm,t,n))}function Bm(e){e.exit("gfmFootnoteDefinition")}function zm(e,t,n){const i=this;return re(e,l,"gfmFootnoteDefinitionIndent",5);function l(a){const s=i.events[i.events.length-1];return s&&s[1].type==="gfmFootnoteDefinitionIndent"&&s[2].sliceSerialize(s[1],!0).length===4?t(a):n(a)}}function jm(e){let n={}.singleTilde;const i={name:"strikethrough",tokenize:a,resolveAll:l};return n==null&&(n=!0),{text:{126:i},insideSpan:{null:[i]},attentionMarkers:{null:[126]}};function l(s,o){let u=-1;for(;++u1?u(m):(s.consume(m),d++,h);if(d<2&&!n)return u(m);const x=s.exit("strikethroughSequenceTemporary"),w=hi(m);return x._open=!w||w===2&&!!b,x._close=!b||b===2&&!!w,o(m)}}}class Hm{constructor(){this.map=[]}add(t,n,i){qm(this,t,n,i)}consume(t){if(this.map.sort(function(a,s){return a[0]-s[0]}),this.map.length===0)return;let n=this.map.length;const i=[];for(;n>0;)n-=1,i.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];i.push(t.slice()),t.length=0;let l=i.pop();for(;l;){for(const a of l)t.push(a);l=i.pop()}this.map.length=0}}function qm(e,t,n,i){let l=0;if(!(n===0&&i.length===0)){for(;l-1;){const L=i.events[R][1].type;if(L==="lineEnding"||L==="linePrefix")R--;else break}const F=R>-1?i.events[R][1].type:null,q=F==="tableHead"||F==="tableRow"?v:u;return q===v&&i.parser.lazy[i.now().line]?n(S):q(S)}function u(S){return e.enter("tableHead"),e.enter("tableRow"),c(S)}function c(S){return S===124||(s=!0,a+=1),p(S)}function p(S){return S===null?n(S):U(S)?a>1?(a=0,i.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(S),e.exit("lineEnding"),h):n(S):ee(S)?re(e,p,"whitespace")(S):(a+=1,s&&(s=!1,l+=1),S===124?(e.enter("tableCellDivider"),e.consume(S),e.exit("tableCellDivider"),s=!0,p):(e.enter("data"),d(S)))}function d(S){return S===null||S===124||oe(S)?(e.exit("data"),p(S)):(e.consume(S),S===92?f:d)}function f(S){return S===92||S===124?(e.consume(S),d):d(S)}function h(S){return i.interrupt=!1,i.parser.lazy[i.now().line]?n(S):(e.enter("tableDelimiterRow"),s=!1,ee(S)?re(e,m,"linePrefix",i.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(S):m(S))}function m(S){return S===45||S===58?x(S):S===124?(s=!0,e.enter("tableCellDivider"),e.consume(S),e.exit("tableCellDivider"),b):$(S)}function b(S){return ee(S)?re(e,x,"whitespace")(S):x(S)}function x(S){return S===58?(a+=1,s=!0,e.enter("tableDelimiterMarker"),e.consume(S),e.exit("tableDelimiterMarker"),w):S===45?(a+=1,w(S)):S===null||U(S)?g(S):$(S)}function w(S){return S===45?(e.enter("tableDelimiterFiller"),C(S)):$(S)}function C(S){return S===45?(e.consume(S),C):S===58?(s=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(S),e.exit("tableDelimiterMarker"),y):(e.exit("tableDelimiterFiller"),y(S))}function y(S){return ee(S)?re(e,g,"whitespace")(S):g(S)}function g(S){return S===124?m(S):S===null||U(S)?!s||l!==a?$(S):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(S)):$(S)}function $(S){return n(S)}function v(S){return e.enter("tableRow"),E(S)}function E(S){return S===124?(e.enter("tableCellDivider"),e.consume(S),e.exit("tableCellDivider"),E):S===null||U(S)?(e.exit("tableRow"),t(S)):ee(S)?re(e,E,"whitespace")(S):(e.enter("data"),M(S))}function M(S){return S===null||S===124||oe(S)?(e.exit("data"),E(S)):(e.consume(S),S===92?T:M)}function T(S){return S===92||S===124?(e.consume(S),M):M(S)}}function Vm(e,t){let n=-1,i=!0,l=0,a=[0,0,0,0],s=[0,0,0,0],o=!1,u=0,c,p,d;const f=new Hm;for(;++nn[2]+1){const m=n[2]+1,b=n[3]-n[2]-1;e.add(m,b,[])}}e.add(n[3]+1,0,[["exit",d,t]])}return l!==void 0&&(a.end=Object.assign({},Xt(t.events,l)),e.add(l,0,[["exit",a,t]]),a=void 0),a}function Is(e,t,n,i,l){const a=[],s=Xt(t.events,n);l&&(l.end=Object.assign({},s),a.push(["exit",l,t])),i.end=Object.assign({},s),a.push(["exit",i,t]),e.add(n+1,0,a)}function Xt(e,t){const n=e[t],i=n[0]==="enter"?"start":"end";return n[1][i]}const Gm={name:"tasklistCheck",tokenize:Qm};function Jm(){return{text:{91:Gm}}}function Qm(e,t,n){const i=this;return l;function l(u){return i.previous!==null||!i._gfmTasklistFirstContentOfListItem?n(u):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(u),e.exit("taskListCheckMarker"),a)}function a(u){return oe(u)?(e.enter("taskListCheckValueUnchecked"),e.consume(u),e.exit("taskListCheckValueUnchecked"),s):u===88||u===120?(e.enter("taskListCheckValueChecked"),e.consume(u),e.exit("taskListCheckValueChecked"),s):n(u)}function s(u){return u===93?(e.enter("taskListCheckMarker"),e.consume(u),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),o):n(u)}function o(u){return U(u)?t(u):ee(u)?e.check({tokenize:Ym},t,n)(u):n(u)}}function Ym(e,t,n){return re(e,i,"whitespace");function i(l){return l===null?n(l):t(l)}}function iu(e){return Ic([xm(),Im(),jm(),Wm(),Jm()])}const Zm={pr_title:"from the PR title",branch:"from the branch name"};function vr(e){if(e!=null&&e.linked_linear){const t=e.linked_linear,n=e.linked_linear_title?`: ${e.linked_linear_title}`:"",i=e.linked_linear_status?` [${e.linked_linear_status}]`:"";return{id:t,href:`https://linear.app/issue/${t}`,tip:`Linear ${t}${n}${i}`,note:null,derived:!1}}if(e!=null&&e.linear_ticket){const t=e.linear_ticket,n=Zm[e.linear_ticket_source]||"derived";return{id:t,href:`https://linear.app/issue/${t}`,tip:`Linear ${t} (${n})`,note:n,derived:!0}}return null}const Xm=/^([a-z-]+): (.+)$/;function jl(e,t){if((e==null?void 0:e.type)!=="blockquote"||typeof t!="string")return null;const n=t.slice(e.position.start.offset,e.position.end.offset),i=[];for(const l of n.split(` +`))for(const a of l.replace(/^\s*> ?/,"").split(" · ")){const s=Xm.exec(a.trim());if(!s)return null;i.push([s[1],s[2].trim()])}return i.length?i:null}function lu(e){return e.split(",").map(t=>t.trim().replace(/^`+|`+$/g,""))}const eg=/^([\w.-]*[\w-]\/[\w./-]*[\w-]|[\w-]+(?:\.[\w-]+)*\.[A-Za-z][A-Za-z0-9]{1,5})(?::(\d+)(?:-(\d+))?)?$/;function ji(e){const t=eg.exec(e);if(!t)return null;const n=t[1];if(!/[A-Za-z]/.test(n)||!n.includes("/")&&t[2]==null)return null;const i=n.split("/").pop();if(t[2]==null&&n.includes("/")&&!/\.[A-Za-z][A-Za-z0-9]{0,5}$/.test(i)&&!/^[\w.-]+\/[\w.-]+\//.test(n))return null;const l=t[2]!=null?Number(t[2]):null;return{path:n,start:l,end:t[3]!=null?Number(t[3]):l,raw:e}}function tg(e){const t=[];let n="";const i=/\S+/g;let l=0;for(let a=i.exec(e);a;a=i.exec(e)){const s=a[0],o=(s.match(/^[(["']+/)||[""])[0],u=s.slice(o.length).replace(/[.,;:)\]"']+$/,""),c=u?ji(u):null;c?(n+=e.slice(l,a.index)+o,n&&t.push(n),n=s.slice(o.length+u.length),t.push(c)):n+=e.slice(l,a.index)+s,l=a.index+s.length}return n+=e.slice(l),n&&t.push(n),t}const ng=new Set(["new-subsystem","extension","reuse","system-touch","behavior"]);function rg(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"stop"}function Ur(e){return e.type==="text"||e.type==="inlineCode"?e.value:(e.children||[]).map(Ur).join("")}function ig(e){var p,d,f;const t=String(e||""),i=Wc(t,{extensions:[iu()],mdastExtensions:[Jc()]}).children;let l="",a=null,s="";const o=[],u=new Map;let c=0;if(((p=i[c])==null?void 0:p.type)==="heading"&&i[c].depth===1){l=Ur(i[c]),c++;const h=((d=i[c])==null?void 0:d.type)==="blockquote"?jl(i[c],t):null;if(h){const m=Object.fromEntries(h);m.branch&&m.head&&(a={branch:m.branch,head:m.head,pr:/^\d+$/.test(m.pr||"")?Number(m.pr):null,repo:m.repo??null}),c++}((f=i[c])==null?void 0:f.type)==="paragraph"&&(s=Ur(i[c]),c++)}for(;cn.kind==="ctx"||n.kind==="add").length;return e.new_start+Math.max(t,1)-1}function ag(e,t){const n=new Map((t||[]).map(i=>[i.path,i]));return e.map(i=>{const l=n.get(i.path)||null;if(!l)return{ref:i,file:null,hunks:[],generated:!1};const a=i.start==null?l.hunks:l.hunks.filter(s=>s.new_start<=i.end&&lg(s)>=i.start);return{ref:i,file:l.path,hunks:a,generated:!!l.generated}})}const fi=e=>{var t;return((t=e.pr)==null?void 0:t.state)==="merged"};function Os(e){if(fi(e))return 99;const t=e.owner?0:e.worktree?10:20;return e.unresolved>0?t:e.role==="review-requested"?t+1:e.pr&&!e.walkthrough?t+2:e.role==="local"?t+4:t+3}const Hi={branch:{label:"branch",what:"branch name",first:"asc",value:e=>e.branch},pr:{label:"PR",what:"PR number",first:"desc",value:e=>{var t;return((t=e.pr)==null?void 0:t.number)??null}},walkthrough:{label:"walkthrough",what:"staleness",first:"desc",value:e=>{var t;return((t=e.walkthrough)==null?void 0:t.stale_by)??null}},comments:{label:"comments",what:"open comments",first:"desc",value:e=>e.unresolved||null},who:{label:"who",what:"owner",first:"asc",value:e=>{var t,n;return((t=e.owner)==null?void 0:t.name)||((n=e.pr)==null?void 0:n.author)||null}}};function sg(e){if(!e.walkthrough)return null;const t=e.walkthrough.stale_by;return t>0?`stale ${t}`:t===0?"current":e.worktree?"stale: unknown":"no worktree"}const og=(e,t)=>typeof e=="string"?e.localeCompare(t):e-t;function cg(e,t=null){const n=[...e||[]].sort((a,s)=>{var o,u;return Os(a)-Os(s)||(((o=s.pr)==null?void 0:o.number)||0)-(((u=a.pr)==null?void 0:u.number)||0)||a.branch.localeCompare(s.branch)}),i=t&&Hi[t.key];if(!i)return n;const l=t.dir==="asc"?1:-1;return n.sort((a,s)=>{const o=i.value(a),u=i.value(s);return fi(a)-fi(s)||(o===null)-(u===null)||(o===null?0:l*og(o,u))})}function ug(e,t){const n=Hi[t].first;return(e==null?void 0:e.key)!==t?{key:t,dir:n}:e.dir===n?{key:t,dir:n==="asc"?"desc":"asc"}:null}function dg(e,t){const n=(t||"").toLowerCase().split(/\s+/).filter(Boolean);return n.length?(e||[]).filter(i=>{var a,s,o,u;const l=[i.branch,i.repo,i.pr?`#${i.pr.number}`:null,(a=i.pr)==null?void 0:a.title,(s=i.pr)==null?void 0:s.author,(o=i.owner)==null?void 0:o.name,(u=vr(i))==null?void 0:u.id,i.linked_linear_title].filter(Boolean).join(" ").toLowerCase();return n.every(c=>l.includes(c))}):e||[]}function Ds(e){return(e||[]).filter(t=>!fi(t)).reduce((t,n)=>t+(n.unresolved||0),0)}const hg={scope:{name:"Scope",root:[{r:[11,1,2,6],a:{fill:"#2a86b3"}},{r:[11,1,5,2],a:{fill:"#2a86b3"}},{g:[{r:[16,1,1,2],a:{fill:"#ffd166"}}],anim:"crit-scope-1"},{r:[1,9,2,4],a:{fill:"#2a86b3"}},{r:[4,6,12,1],a:{fill:"#40b8ee"}},{r:[3,7,14,8],a:{fill:"#40b8ee"}},{r:[4,15,12,1],a:{fill:"#2a86b3"}},{r:[5,7,3,1],a:{fill:"#7fd0f5"}},{g:[{r:[6,9,2,2],a:{fill:"#0f1215"}}],anim:"crit-scope-2",role:"eye",shut:[6,10,2,.4]},{g:[{r:[12,9,2,2],a:{fill:"#0f1215"}}],anim:"crit-scope-3",role:"eye",shut:[12,10,2,.4]},{g:[{r:[6,9,.7,.7]},{r:[12,9,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[5.5,7.9,3,.7]},{r:[11.5,7.9,3,.7]},{r:[8.5,12.2,3,.7]}],a:{fill:"#16384a"},mood:"grumpy"},{g:[{r:[5.4,7.5,1.6,.7]},{r:[7,8.1,1.6,.7]},{r:[11.4,8.1,1.6,.7]},{r:[13,7.5,1.6,.7]},{r:[8.5,11.7,3,1.6]}],a:{fill:"#16384a"},mood:"furious"},{g:[{r:[8.4,11.6,.7,.7],a:{fill:"#16384a"}},{r:[9,12.2,2,.7],a:{fill:"#16384a"}},{r:[10.9,11.6,.7,.7],a:{fill:"#16384a"}},{r:[4.4,11.6,1.5,.8],a:{fill:"#f58967",opacity:"0.7"}},{r:[14.1,11.6,1.5,.8],a:{fill:"#f58967",opacity:"0.7"}}],mood:"calm"},{g:[{r:[5,16,2,2],a:{fill:"#2a86b3"}},{r:[13,16,2,2],a:{fill:"#2a86b3"}}],legs:!0},{g:[{g:[{r:[3,3,1,1]}],anim:"crit-scope-4"},{g:[{r:[6,2,1,1]}],anim:"crit-scope-5"}],a:{fill:"#8f9397"},mood:"furious"}],anchors:{eyes:[{x:6,y:9,w:2,h:2,role:"eye"},{x:12,y:9,w:2,h:2,role:"eye"}],head:{top:1,right:17},hat:{cx:10,top:6,w:12},neck:{y:13,x0:3,x1:17}},ink:"#0f1215",limb:{style:"arm",root:[17,10.6],width:1.2,color:"#2a86b3"}},faradaysie:{name:"Faradaysie",root:[{g:[{r:[12,0,1,1]},{r:[11,1,3,1]},{r:[10,2,5,1]},{r:[12,3,1,2]}],a:{fill:"#f72f96"}},{g:[{g:[{r:[7,0,1,2]}],anim:"crit-faradaysie-1"},{g:[{r:[5,2,5,1]}],anim:"crit-faradaysie-2"},{g:[{r:[6,3,3,1]}],anim:"crit-faradaysie-3"},{g:[{r:[7,4,1,1]}],anim:"crit-faradaysie-4"}],a:{fill:"#e4baff"}},{g:[{r:[7,5,6,1]},{r:[5,6,10,1]},{r:[4,7,12,7]},{r:[5,14,10,1]}],a:{fill:"#b641ff"}},{r:[6,15,8,1],a:{fill:"#6d1ba0"}},{r:[6,6,3,1],a:{fill:"#e4baff"}},{r:[5,7,1,2],a:{fill:"#e4baff"}},{r:[7,11.5,6,2.5],a:{fill:"#fcb0d7"}},{g:[{r:[3,9,1,2]},{g:[{r:[16,9,1,2]}],anim:"crit-faradaysie-5"}],arms:!0,a:{fill:"#6d1ba0"}},{g:[{r:[6,16,2,1]},{r:[12,16,2,1]}],legs:!0,a:{fill:"#6d1ba0"}},{g:[{r:[6,8,2,2],a:{fill:"#240835"}}],anim:"crit-faradaysie-6",role:"eye",shut:[6,9,2,.4]},{g:[{r:[12,8,2,2],a:{fill:"#240835"}}],anim:"crit-faradaysie-7",role:"eye",shut:[12,9,2,.4]},{g:[{r:[6,8,.7,.7]},{r:[12,8,.7,.7]}],a:{fill:"#fdfaff"},mood:"calm",role:"glint"},{g:[{r:[8.4,10.6,.7,.7],a:{fill:"#240835"}},{r:[9,11.2,2,.7],a:{fill:"#240835"}},{r:[10.9,10.6,.7,.7],a:{fill:"#240835"}},{r:[4.4,10.4,1.5,.8],a:{fill:"#f72f96",opacity:"0.75"}},{r:[14.1,10.4,1.5,.8],a:{fill:"#f72f96",opacity:"0.75"}}],mood:"calm"},{g:[{r:[5.5,6.9,3,.7]},{r:[11.5,6.9,3,.7]},{r:[8.5,11,3,.7]}],a:{fill:"#240835"},mood:"grumpy"},{g:[{r:[5.4,6.5,1.6,.7]},{r:[7,7.1,1.6,.7]},{r:[11.4,7.1,1.6,.7]},{r:[13,6.5,1.6,.7]},{r:[8.5,10.5,3,1.6]}],a:{fill:"#240835"},mood:"furious"},{g:[{g:[{r:[2,4,1,2]}],anim:"crit-faradaysie-8"},{g:[{r:[17,3,1,2]}],anim:"crit-faradaysie-9"},{g:[{r:[1,12,1,1]}],anim:"crit-faradaysie-10"},{g:[{r:[18,13,1,1]}],anim:"crit-faradaysie-11"}],a:{fill:"#f72f96"},mood:"furious"}],anchors:{eyes:[{x:6,y:8,w:2,h:2,role:"eye"},{x:12,y:8,w:2,h:2,role:"eye"}],head:{top:0,right:17},hat:{cx:10,top:6,w:10},neck:{y:12.8,x0:4,x1:16}},ink:"#240835",limb:{style:"arm",root:[16.4,9.4],width:1.2,color:"#6d1ba0"}},jelly:{name:"Jelly",root:[{r:[7,3,6,1],a:{fill:"#ab93ed"}},{r:[5,4,10,1],a:{fill:"#ab93ed"}},{r:[4,5,12,6],a:{fill:"#ab93ed"}},{r:[4,11,12,1],a:{fill:"#7d62c9"}},{g:[{r:[4,12,2,1]},{r:[7.3,12,2,1]},{r:[10.7,12,2,1]},{r:[14,12,2,1]}],a:{fill:"#7d62c9"}},{g:[{r:[7,4,3,1]},{r:[5,5,1,2]},{r:[13,5,1,1]},{r:[14,7,1,1]}],a:{fill:"#d4c6fa"}},{g:[{r:[6,13,1,2]},{r:[5,15,1,2]},{r:[6,17,1,1]},{r:[9.5,13,1,2]},{r:[10.5,15,1,2]},{r:[9.5,17,1,1]},{r:[13,13,1,2]},{r:[14,15,1,2]},{r:[13,17,1,1]}],legs:!0,keepSeated:!0,a:{fill:"#7d62c9"},anim:"crit-jelly-1"},{g:[{r:[7,7,2,2],a:{fill:"#2a1f45"}}],anim:"crit-jelly-2",role:"eye",shut:[7,8,2,.4]},{g:[{r:[11,7,2,2],a:{fill:"#2a1f45"}}],anim:"crit-jelly-3",role:"eye",shut:[11,8,2,.4]},{g:[{r:[7,7,.7,.7]},{r:[11,7,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[8.4,9.6,.7,.7],a:{fill:"#2a1f45"}},{r:[9,10.2,2,.7],a:{fill:"#2a1f45"}},{r:[10.9,9.6,.7,.7],a:{fill:"#2a1f45"}},{r:[5,9.2,1.5,.8],a:{fill:"#f2a7c3"}},{r:[13.5,9.2,1.5,.8],a:{fill:"#f2a7c3"}}],mood:"calm"},{g:[{r:[6.5,5.9,3,.7]},{r:[10.5,5.9,3,.7]},{r:[8.5,10,3,.7]}],a:{fill:"#2a1f45"},mood:"grumpy"},{g:[{r:[6.4,5.5,1.6,.7]},{r:[8,6.1,1.6,.7]},{r:[10.4,6.1,1.6,.7]},{r:[12,5.5,1.6,.7]},{r:[8.5,9.5,3,1.4]}],a:{fill:"#2a1f45"},mood:"furious"},{g:[{g:[{r:[2,4,1,1]}],anim:"crit-jelly-4"},{g:[{r:[17,6,1,1]}],anim:"crit-jelly-5"}],a:{fill:"#f3e9c6"},mood:"furious"}],anchors:{eyes:[{x:7,y:7,w:2,h:2,role:"eye"},{x:11,y:7,w:2,h:2,role:"eye"}],head:{top:3,right:16},hat:{cx:10,top:3,w:8},neck:{y:10.5,x0:4,x1:16}},ink:"#2a1f45",limb:{style:"tentacle",root:[16,10.2],width:1,color:"#7d62c9"}},nox:{name:"Nox",root:[{g:[{g:[{r:[15,16,3,1]},{r:[17,12,1,4]},{r:[16,11,1,1]}],a:{fill:"#1a1c20",stroke:"#4a4f57","stroke-width":"1"}},{g:[{r:[15,16,3,1]},{r:[17,12,1,4]},{r:[16,11,1,1]}],a:{fill:"#1a1c20"}}],rest:!0,anim:"crit-nox-1"},{g:[{r:[5,3,1,2]},{r:[6,4,1,1]},{r:[14,3,1,2]},{r:[13,4,1,1]},{r:[5,5,10,1]},{r:[4,6,12,5]},{r:[5,11,10,1]},{r:[6,12,8,1]},{r:[5,13,10,5]}],a:{fill:"#1a1c20",stroke:"#4a4f57","stroke-width":"1"}},{g:[{r:[5,3,1,2]},{r:[6,4,1,1]},{r:[14,3,1,2]},{r:[13,4,1,1]},{r:[5,5,10,1]},{r:[4,6,12,5]},{r:[5,11,10,1]},{r:[6,12,8,1]},{r:[5,13,10,5]}],a:{fill:"#1a1c20"}},{g:[{r:[5.2,4.2,.6,.7]},{r:[14.2,4.2,.6,.7]}],a:{fill:"#f2a7c3",opacity:"0.8"}},{r:[6,5,3,1],a:{fill:"#2c3036"}},{g:[{r:[6,17,2,1]},{r:[12,17,2,1]}],legs:!0,keepSeated:!0,a:{fill:"#3a3f46"}},{g:[{r:[1.8,8.8,2.2,.4]},{r:[1.8,10,2.2,.4]},{r:[16,8.8,2.2,.4]},{r:[16,10,2.2,.4]}],a:{fill:"#5c626b"}},{r:[6,6,3,3],a:{fill:"#c6e05a"}},{r:[11,6,3,3],a:{fill:"#c6e05a"}},{g:[{g:[{r:[7,6.5,1.4,2]}],anim:"crit-nox-2"},{g:[{r:[12,6.5,1.4,2]}],anim:"crit-nox-3"}],a:{fill:"#0b0c0e"}},{g:[{r:[6.3,6.3,.7,.7]},{r:[11.3,6.3,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm"},{g:[{g:[{r:[6,6,3,3]}],anim:"crit-nox-4",role:"lid",shut:[6,6,3,3]},{g:[{r:[11,6,3,3]}],anim:"crit-nox-5",role:"lid",shut:[11,6,3,3]}],a:{fill:"#1a1c20"}},{r:[9.5,9,1,.7],a:{fill:"#f2a7c3"}},{g:[{r:[9,9.9,.5,.5]},{r:[9.4,10.3,.6,.4]},{r:[10,10.3,.6,.4]},{r:[10.5,9.9,.5,.5]}],a:{fill:"#8f9397"},mood:"calm"},{g:[{r:[6,6,3,1.3],a:{fill:"#1a1c20"}},{r:[11,6,3,1.3],a:{fill:"#1a1c20"}},{r:[8.8,10.2,2.4,.5],a:{fill:"#8f9397"}}],mood:"grumpy"},{g:[{r:[8,6,1,1],a:{fill:"#1a1c20"}},{r:[11,6,1,1],a:{fill:"#1a1c20"}},{r:[8.8,9.8,2.4,1.3],a:{fill:"#f2a7c3"}},{r:[9,9.8,.5,.6],a:{fill:"#f3f5f8"}},{r:[10.5,9.8,.5,.6],a:{fill:"#f3f5f8"}},{g:[{g:[{r:[7.5,3.6,1,1.2]}],anim:"crit-nox-6"},{g:[{r:[9.5,3.2,1,1.6]}],anim:"crit-nox-7"},{g:[{r:[11.5,3.6,1,1.2]}],anim:"crit-nox-8"}],a:{fill:"#5c626b"}}],mood:"furious"}],anchors:{eyes:[{x:6,y:6,w:3,h:3,role:"lid"},{x:11,y:6,w:3,h:3,role:"lid"}],head:{top:3,right:18.2},hat:{cx:10,top:5,w:9},neck:{y:12,x0:6,x1:14}},ink:"#c6e05a",faces:{worried:[{g:[{r:[5.8,5.9,1.4,.6]},{r:[7.2,5.4,1.6,.6]},{r:[11.2,5.4,1.6,.6]},{r:[12.8,5.9,1.4,.6]}],a:{fill:"#d5d8dc"}}]},limb:{style:"tail",root:[15.2,16],width:1,color:"#1a1c20",outline:"#4a4f57"}},ember:{name:"Ember",root:[{g:[{r:[4,2,1,2]},{r:[5,3,1,2]},{r:[15,2,1,2]},{r:[14,3,1,2]}],a:{fill:"#ffd9a0"}},{r:[6,4,8,1],a:{fill:"#e8574f"}},{r:[5,5,10,1],a:{fill:"#e8574f"}},{r:[4,6,12,8],a:{fill:"#e8574f"}},{r:[5,14,10,1],a:{fill:"#e8574f"}},{r:[6,15,8,1],a:{fill:"#b8403a"}},{r:[8,11,4,3],a:{fill:"#ff9a8f"}},{r:[6,5,2,1],a:{fill:"#ff9a8f"}},{g:[{r:[3,9,1,2]},{r:[16,9,1,2]}],arms:!0,a:{fill:"#b8403a"}},{g:[{r:[6,16,2,1]},{r:[12,16,2,1]}],legs:!0,a:{fill:"#b8403a"}},{g:[{r:[16,13,1,1]},{r:[17,12,1,1]},{r:[18,10,1,2]},{r:[17,9,1,1]},{r:[19,9,1,1]},{r:[18,8,1,1]}],rest:!0,a:{fill:"#b8403a"},anim:"crit-ember-1"},{g:[{r:[7,7,2,2],a:{fill:"#3a1312"}}],anim:"crit-ember-2",role:"eye",shut:[7,8,2,.4]},{g:[{r:[11,7,2,2],a:{fill:"#3a1312"}}],anim:"crit-ember-3",role:"eye",shut:[11,8,2,.4]},{g:[{r:[7,7,.7,.7]},{r:[11,7,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[8.4,9.6,.7,.7],a:{fill:"#3a1312"}},{r:[9,10.2,2,.7],a:{fill:"#3a1312"}},{r:[10.9,9.6,.7,.7],a:{fill:"#3a1312"}},{r:[10.2,10.9,.7,.7],a:{fill:"#ffd9a0"}}],mood:"calm"},{g:[{r:[6.5,5.9,3,.7]},{r:[10.5,5.9,3,.7]},{r:[8.5,10,3,.7]}],a:{fill:"#3a1312"},mood:"grumpy"},{g:[{r:[6.4,5.6,1.6,.7]},{r:[8,6.2,1.6,.7]},{r:[10.4,6.2,1.6,.7]},{r:[12,5.6,1.6,.7]},{r:[8.5,9.5,3,1.5]}],a:{fill:"#3a1312"},mood:"furious"},{g:[{g:[{r:[9,1,2,2],a:{fill:"#ffd166"}}],anim:"crit-ember-4"},{r:[9.5,0,1,1],a:{fill:"#f58967"}}],mood:"furious"}],anchors:{eyes:[{x:7,y:7,w:2,h:2,role:"eye"},{x:11,y:7,w:2,h:2,role:"eye"}],head:{top:2,right:20},hat:{cx:10,top:5,w:10},neck:{y:13.4,x0:4,x1:16}},ink:"#3a1312",limb:{style:"tail",root:[16,13.4],width:1,color:"#b8403a",spade:!0}},volt:{name:"Volt",root:[{g:[{r:[9,4,1,2]},{r:[10,3,1,1]},{r:[9,2,1,1]},{r:[10,1,1,1]}],a:{fill:"#d1a92b"}},{g:[{r:[10,0,1,1],a:{fill:"#fff1a8"}}],anim:"crit-volt-1"},{r:[5,6,10,1],a:{fill:"#f5d547"}},{r:[3,7,14,7],a:{fill:"#f5d547"}},{r:[4,14,12,1],a:{fill:"#d1a92b"}},{r:[6,7,3,1],a:{fill:"#fff1a8"}},{g:[{r:[10,12,1,1]},{r:[9,13,1,1]}],a:{fill:"#fff1a8"}},{g:[{r:[2,9,1,2]},{r:[17,9,1,2]}],arms:!0,a:{fill:"#d1a92b"},anim:"crit-volt-2"},{g:[{r:[5,15,3,1]},{r:[12,15,3,1]}],legs:!0,a:{fill:"#d1a92b"}},{g:[{r:[6,8,2,2],a:{fill:"#3a2f10"}}],anim:"crit-volt-3",role:"eye",shut:[6,9,2,.4]},{g:[{r:[12,8,2,2],a:{fill:"#3a2f10"}}],anim:"crit-volt-4",role:"eye",shut:[12,9,2,.4]},{g:[{r:[6,8,.7,.7]},{r:[12,8,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[8.4,10.2,.7,.7],a:{fill:"#3a2f10"}},{r:[9,10.8,2,.7],a:{fill:"#3a2f10"}},{r:[10.9,10.2,.7,.7],a:{fill:"#3a2f10"}},{r:[4.2,10.2,1.5,.8],a:{fill:"#f58967",opacity:"0.7"}},{r:[14.3,10.2,1.5,.8],a:{fill:"#f58967",opacity:"0.7"}}],mood:"calm"},{g:[{r:[5.5,6.9,3,.7]},{r:[11.5,6.9,3,.7]},{r:[8.5,10.6,3,.7]}],a:{fill:"#3a2f10"},mood:"grumpy"},{g:[{r:[5.4,6.5,1.6,.7]},{r:[7,7.1,1.6,.7]},{r:[11.4,7.1,1.6,.7]},{r:[13,6.5,1.6,.7]},{r:[8.5,10,3,1.6]}],a:{fill:"#3a2f10"},mood:"furious"},{g:[{g:[{r:[1,3,1,2]}],anim:"crit-volt-5"},{g:[{r:[18,4,1,2]}],anim:"crit-volt-6"}],a:{fill:"#fff1a8"},mood:"furious"}],anchors:{eyes:[{x:6,y:8,w:2,h:2,role:"eye"},{x:12,y:8,w:2,h:2,role:"eye"}],head:{top:0,right:18},hat:{cx:10,top:6,w:10},neck:{y:12.4,x0:3,x1:17}},ink:"#3a2f10",limb:{style:"arm",root:[17.4,9.4],width:1.2,color:"#d1a92b"}},moss:{name:"Moss",root:[{g:[{r:[7,3,2,1]},{r:[9.5,2,1.5,2]},{r:[11.5,3,2,1]}],a:{fill:"#2e9a56"},anim:"crit-moss-1"},{r:[7,4,6,1],a:{fill:"#47cf79"}},{r:[6,5,8,1],a:{fill:"#47cf79"}},{r:[5,6,10,9],a:{fill:"#47cf79"}},{r:[6,15,8,1],a:{fill:"#2e9a56"}},{g:[{r:[6,6,1,1]},{r:[12,5,1,1]},{r:[13,12,1,1]},{r:[6,13,1,1]}],a:{fill:"#9ae8b6"}},{g:[{r:[4,10,1,3],a:{fill:"#2e9a56"}},{g:[{r:[15,10,1,3],a:{fill:"#2e9a56"}}],anim:"crit-moss-2"}],arms:!0},{g:[{r:[6,16,2,1]},{r:[12,16,2,1]}],legs:!0,a:{fill:"#2e9a56"}},{r:[8,7,4,3],a:{fill:"#f3f5f8"}},{g:[{r:[9,7.5,2,2],a:{fill:"#0f2e1b"}}],anim:"crit-moss-3"},{g:[{r:[8,7,4,3],a:{fill:"#47cf79"}}],anim:"crit-moss-4",role:"lid",shut:[8,7,4,3]},{g:[{r:[8.4,11.4,.7,.7],a:{fill:"#0f2e1b"}},{r:[9,12,2,.7],a:{fill:"#0f2e1b"}},{r:[10.9,11.4,.7,.7],a:{fill:"#0f2e1b"}},{r:[6,11,1.3,.7],a:{fill:"#f2a7c3"}},{r:[12.7,11,1.3,.7],a:{fill:"#f2a7c3"}}],mood:"calm"},{g:[{r:[8,7,4,1.3],a:{fill:"#2e9a56"}},{r:[8.5,12,3,.7],a:{fill:"#0f2e1b"}}],mood:"grumpy"},{g:[{r:[7.6,5.6,1.6,.7]},{r:[9.2,6.2,1.6,.7]},{r:[10.8,5.6,1.6,.7]},{r:[8.5,11.4,3,1.6]}],a:{fill:"#0f2e1b"},mood:"furious"}],anchors:{eyes:[{x:8,y:7,w:4,h:3,role:"lid"}],head:{top:2,right:16},hat:{cx:10,top:4,w:7},neck:{y:12.4,x0:5,x1:15}},ink:"#0f2e1b",limb:{style:"arm",root:[15.6,10.6],width:1.1,color:"#2e9a56"}},octocat:{name:"Octocat",root:[{g:[{g:[{r:[4,14,1,2]},{r:[3,16,2,1]},{r:[7,14,1,3]},{r:[6,17,2,1]},{r:[12,14,1,3]},{r:[12,17,2,1]},{r:[15,14,1,2]},{r:[15,16,2,1]}],a:{fill:"#24292f",stroke:"#6e7781","stroke-width":"1"}},{g:[{r:[4,14,1,2]},{r:[3,16,2,1]},{r:[7,14,1,3]},{r:[6,17,2,1]},{r:[12,14,1,3]},{r:[12,17,2,1]},{r:[15,14,1,2]},{r:[15,16,2,1]}],a:{fill:"#24292f"}}],legs:!0,anim:"crit-octocat-1"},{g:[{r:[4,2,1,2]},{r:[5,3,1,1]},{r:[15,2,1,2]},{r:[14,3,1,1]},{r:[4,4,12,1]},{r:[3,5,14,7]},{r:[4,12,12,2]}],a:{fill:"#24292f",stroke:"#6e7781","stroke-width":"1"}},{g:[{r:[4,2,1,2]},{r:[5,3,1,1]},{r:[15,2,1,2]},{r:[14,3,1,1]},{r:[4,4,12,1]},{r:[3,5,14,7]},{r:[4,12,12,2]}],a:{fill:"#24292f"}},{g:[{r:[6,6,8,1]},{r:[5,7,10,4]},{r:[6,11,8,1]}],a:{fill:"#f4c7ad"}},{g:[{r:[7,8,2,2],a:{fill:"#2b1d16"}}],anim:"crit-octocat-2",role:"eye",shut:[7,9,2,.4]},{g:[{r:[11,8,2,2],a:{fill:"#2b1d16"}}],anim:"crit-octocat-3",role:"eye",shut:[11,9,2,.4]},{g:[{r:[7,8,.7,.7]},{r:[11,8,.7,.7]}],a:{fill:"#f3f5f8"},mood:"calm",role:"glint"},{g:[{r:[9,10.4,2,.6],a:{fill:"#2b1d16"}},{r:[5.4,10,1.2,.6],a:{fill:"#e8909c"}},{r:[13.4,10,1.2,.6],a:{fill:"#e8909c"}}],mood:"calm"},{g:[{r:[6.5,6.8,3,.6]},{r:[10.5,6.8,3,.6]},{r:[8.5,10.6,3,.6]}],a:{fill:"#2b1d16"},mood:"grumpy"},{g:[{r:[6.4,6.4,1.6,.6]},{r:[8,7,1.6,.6]},{r:[10.4,7,1.6,.6]},{r:[12,6.4,1.6,.6]},{r:[8.5,10.2,3,1.2]}],a:{fill:"#2b1d16"},mood:"furious"},{g:[{g:[{r:[1,4,1,1]}],anim:"crit-octocat-4"},{g:[{r:[18,5,1,1]}],anim:"crit-octocat-5"}],a:{fill:"#f3e9c6"},mood:"furious"}],anchors:{eyes:[{x:7,y:8,w:2,h:2,role:"eye"},{x:11,y:8,w:2,h:2,role:"eye"}],head:{top:2,right:17},hat:{cx:10,top:4,w:12},neck:{y:11.6,x0:4,x1:16}},ink:"#2b1d16",limb:{style:"tentacle",root:[16.6,12.4],width:1,color:"#24292f"}}},pi=[{id:"clawd",name:"Clawd",sprite:null},...Object.entries(hg).map(([e,t])=>({id:e,name:t.name,sprite:t}))];function au(e){return pi.find(t=>t.id===e)||pi[0]}const su=10,xa=12,fg=19,pg=17,N=e=>Math.round(e*1e4)/1e4;function bn(e,{seated:t=!1}={}){let n=1/0,i=1/0,l=-1/0,a=-1/0;const s=o=>{if(!o.mood&&!(t&&o.legs&&!o.keepSeated)){if(o.r){const[u,c,p,d]=o.r;n=Math.min(n,u),i=Math.min(i,c),l=Math.max(l,u+p),a=Math.max(a,c+d);return}o.g.forEach(s)}};return e.root.forEach(s),{x:n,y:i,w:l-n,h:a-i}}function Sa(e,{x0:t,sitting:n,height:i=xa}){const l=bn(e),a=i/l.h,s=n?(({y:u,h:c})=>u+c)(bn(e,{seated:!0})):l.y+l.h,o=(n?pg:fg)-a*s;return{scale:a,tx:N(t+8.5-a*(l.x+l.w/2)),ty:N(o),top:N(o+a*l.y),drop:n?N(a*(l.y+l.h-s)):0}}const mg=.75,dl=(e,t=mg)=>({fill:"none",stroke:e,"stroke-width":t,"stroke-linecap":"square"});function gg(e){const t=bn(e),n=t.x+t.w/2,i=l=>l.r?{...l,r:[N(l.r[0]+(l.r[0]+l.r[2]/2l.legs?[{g:[l],cls:"tama-legs-a"},{g:[i(l)],cls:"tama-legs-b"}]:[l])}const yg=new Set(["happy","x","down"]);function bg(e){if(e.length===1){const{x:n,y:i,w:l}=e[0];return[{p:`M${N(n-.3)} ${N(i-.7)} l${N(l/2+.3)} -0.8 l${N(l/2+.3)} 0.8`}]}const t=e.reduce((n,i)=>n+i.x+i.w/2,0)/e.length;return e.map(({x:n,y:i,w:l})=>n+l/2({p:`M${o} ${N(u+.75*p)} l${N(c/2)} ${N(-p/2)} l${N(c/2)} ${N(p/2)}`}))}]:t==="x"?[{a:dl(l),g:n.map(({x:o,y:u,w:c,h:p})=>({p:`M${N(o+.1)} ${N(u+.1)} L${N(o+c-.1)} ${N(u+p-.1)} M${N(o+c-.1)} ${N(u+.1)} L${N(o+.1)} ${N(u+p-.1)}`}))}]:t==="down"?[{a:{fill:l},g:n.map(({x:o,y:u,w:c,h:p})=>({r:[o,N(u+.45*p),c,N(.55*p)]}))}]:[]}function wg(e,t=!1){const{head:n}=e.anchors,i=N(t?bn(e).x-1.4:n.right+.4);return[{cls:"tama-startle",a:{fill:"#f2c14e"},g:[{r:[i,N(n.top+.5),1,3]},{r:[i,N(n.top+4.1),1,1]}]}]}function vg(e){const{cx:t,top:n,w:i}=e.anchors.hat;return`translate(${t} ${n}) scale(${N(i/12)}) translate(-9 -9)`}function _g(e,t){if(t==="goggles"){const{eyes:n}=e.anchors,i=n.reduce((o,u)=>o+u.y+u.h/2,0)/n.length,l=Math.min(...n.map(o=>o.x))-2,a=Math.max(...n.map(o=>o.x+o.w))+2,s={rx:1,fill:"#7fd1e6","fill-opacity":.45,stroke:"#2b2f36","stroke-width":.5};return[{cls:"tama-goggles",g:[{r:[N(l),N(i-.4),N(a-l),.8],a:{fill:"#2b2f36"}},...n.map(o=>({r:[N(o.x-.6),N(o.y-.6),N(o.w+1.2),N(o.h+1.2)],a:s}))]}]}if(t==="scarf"){const{y:n,x0:i,x1:l}=e.anchors.neck,a=[];for(let s=i+2;s+.7<=l;s+=3)a.push({r:[N(s),n,.7,1.6]});return[{cls:"tama-scarf",g:[{r:[i,n,N(l-i),1.6],a:{fill:"#d64541"}},{g:a,a:{fill:"#f4f4f6"}},{r:[N(i-3),N(n+.3),3.6,1.1],cls:"tama-scarf-tail",a:{fill:"#d64541"}}]}]}return[]}function Rs(e,t){const n=/^#([0-9a-f]{6})$/i.exec(e||"");if(!n)return e;const i=Number.parseInt(n[1],16),[l,a,s]=[i>>16&255,i>>8&255,i&255].map(x=>x/255),o=Math.max(l,a,s),u=Math.min(l,a,s),c=o-u;if(c===0)return e.toLowerCase();const d=(((o===l?(a-s)/c%6:o===a?(s-l)/c+2:(l-a)/c+4)*60+t)%360+360)%360,f=c*(1-Math.abs(d/60%2-1)),[h,m,b]=d<60?[c,f,0]:d<120?[f,c,0]:d<180?[0,c,f]:d<240?[0,f,c]:d<300?[f,0,c]:[c,0,f];return`#${[h,m,b].map(x=>Math.round((x+u)*255).toString(16).padStart(2,"0")).join("")}`}const $a={pint:{reach:2.6,at:.42},mug:{reach:2.2,at:.55},spoon:{reach:2.4,at:.55},can:{reach:2.6,at:.45},leash:{reach:2.4,at:.65}};function qi(e,t){const n=bn(e),{reach:i,at:l}=$a[t];return[N(e.limb.root[0]+i),N(n.y+l*n.h)]}function xg(e,t,{scale:n,tx:i,ty:l}){const[a,s]=qi(e,t);return[N(i+n*a),N(l+n*s)]}function Fs({scale:e,tx:t,ty:n},[i,l]){return[N((i-t)/e),N((l-n)/e)]}function Hl(e,t,n=qi(e,t)){const{style:i,root:[l,a],width:s,color:o,outline:u,spade:c}=e.limb,[p,d]=n,f=(m,b,x,w)=>({r:[N(m),N(b),N(x),N(w)]});if(i==="arm")return[{a:{fill:o},g:[f(l,a,p-l,s),f(p-s,Math.min(a,d),s,Math.abs(d-a)+s),f(p-s*1.1,d-s*.4,s*1.4,s)]}];if(i==="tentacle"){const m=Math.max(2,Math.ceil(Math.max(Math.abs(p-l),Math.abs(d-a))/(.75*s))),b=[];for(let x=0;x<=m;x++)b.push(f(l+(p-l)*x/m-.45*s,a+(d-a)*x/m-.45*s,.95*s,.95*s));return[{a:{fill:o},g:[...b,f(p+.3*s,d-.9*s,.8*s,.8*s)]}]}const h=[f(l,a,p-l,s),f(p-s,d,s,a-d+s),f(p-s,d-s*.2,s*1.6,s)];return[...u?[{a:{fill:o,stroke:u,"stroke-width":1},g:h}]:[],{a:{fill:o},g:[...h,...c?[f(p+.4,d-.9,1.2,1.2)]:[]]}]}function Ca(e,t=!1,n=void 0){return e.flatMap(i=>{var a;if(i.mood)return[];const l=((a=i.a)==null?void 0:a.fill)??n;return i.r?t?[{r:i.r,fill:l}]:[]:Ca(i.g,t||!!i.arms,l)})}function Sg(e){return Ca(e.root).length===0}function $g(e){const t=Ca(e.root);if(t.length)return t.map(({r:[i,l,a],fill:s},o)=>({r:[i,N(l-4),a,4],a:{fill:s},cls:o?"tama-cheer tama-cheer2":"tama-cheer"}));const n=bn(e);return[{cls:"tama-cheer",g:Hl(e,null,[N(e.limb.root[0]+1.6),N(n.y+.12*n.h)])}]}const ou="#ff3b2f",Cg="#f3f5f8";function Tg(e){let t=null;const n=(d,f)=>{const h=f||d.mood==="furious";if(d.r){h&&d.r[2]>=2.4&&d.r[3]>=1.2&&(!t||d.r[2]>t[2])&&(t=d.r);return}(d.g||[]).forEach(m=>{n(m,h)})};if(e.root.forEach(d=>{n(d,!1)}),!t)return[];const[i,l,a,s]=t,o=l+s*.3,u=l+s*.7,c=a/4-.05;let p=`M${N(i+.1)} ${N(u)}`;for(let d=1;d<=4;d++)p+=` L${N(i+.1+c*d)} ${N(d%2?o:u)}`;return[{p,a:{fill:"none",stroke:Cg,"stroke-width":.35,"stroke-linejoin":"miter"}}]}const mi=[{id:"hanken",name:"Hanken Grotesk",face:"Hanken Grotesk",stack:"'Hanken Grotesk', -apple-system, system-ui, sans-serif"},{id:"inter",name:"Inter",face:"Inter",stack:"'Inter', -apple-system, system-ui, sans-serif"},{id:"system-sans",name:"System sans",face:"system-ui",stack:"-apple-system, system-ui, sans-serif"},{id:"plex-mono",name:"IBM Plex Mono",face:"IBM Plex Mono",mono:!0,stack:"'IBM Plex Mono', ui-monospace, 'JetBrains Mono', Menlo, monospace"},{id:"jetbrains-mono",name:"JetBrains Mono",face:"JetBrains Mono",mono:!0,stack:"'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace"},{id:"sf-mono",name:"SF Mono",face:"SF Mono",mono:!0,stack:"'SF Mono', ui-monospace, Menlo, monospace"},{id:"menlo",name:"Menlo",face:"Menlo",mono:!0,stack:"Menlo, Monaco, monospace"}],cu={ui:"hanken",code:"plex-mono"};function uu(e,t){return mi.find(n=>n.id===e)||mi.find(n=>n.id===cu[t])}const Qe=H([]);let Eg=1;function kn(e,t="info",n=4e3){const i=Eg++;return Qe.value=[...Qe.value,{id:i,message:e,kind:t,ms:n,show:!1}],requestAnimationFrame(()=>{Qe.value=Qe.value.map(l=>l.id===i?{...l,show:!0}:l)}),setTimeout(()=>{Qe.value=Qe.value.map(l=>l.id===i?{...l,show:!1}:l),setTimeout(()=>{Qe.value=Qe.value.filter(l=>l.id!==i)},200)},n),i}function Pg(){const e=Qe.value;return r("div",{id:"toast-container",children:e.map(t=>r("div",{class:`toast toast-${t.kind}${t.show?" toast-show":""}`,children:t.message},t.id))})}let Pt=[];function ye(e,t){Pt.push({name:e,detail:t||null,t:Math.floor(Date.now()/1e3)}),Pt.length>500&&(Pt=Pt.slice(-500))}function hl(e){if(!Pt.length)return;const t=JSON.stringify({events:Pt});Pt=[],e&&navigator.sendBeacon?navigator.sendBeacon("/api/events",new Blob([t],{type:"application/json"})):fetch("/api/events",{method:"POST",headers:{"Content-Type":"application/json"},body:t,keepalive:!0}).catch(()=>{})}typeof addEventListener=="function"&&(setInterval(()=>hl(!1),5e3),addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&hl(!0)}),addEventListener("pagehide",()=>hl(!0)));const ql={claude:{label:"Claude",glyph:"✻",className:"icon-claude"},codex:{label:"Codex",glyph:"⬡",className:"icon-codex"}};function wn(e,t,n=`${t}s`){return`${e} ${e===1?t:n}`}function _e(e){return(e==null?void 0:e.name)||(e==null?void 0:e.agent)||"shell"}function tt(e){const t=e.lastIndexOf(":"),n=e.slice(0,t),i=e.slice(t+1);return`session=${encodeURIComponent(n)}&index=${encodeURIComponent(i)}`}function Ag(e){return`pane_id=${encodeURIComponent(e)}`}function Pe(e){if(!e)return"";const t=Math.max(0,Math.floor(Date.now()/1e3)-e);return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:`${Math.floor(t/86400)}d`}function Mg(e){return e?{"approve askuserquestion":"needs answer","permission prompt":"needs approval","dialog open":"needs input"}[e.toLowerCase()]||e.toLowerCase():"needs input"}function du(e){if(!e)return null;const t=e.toLowerCase();return t==="permission prompt"?"permission":t==="approve askuserquestion"?"question":"dialog"}function hu(e,t){if(!e)return e;const n=e.split("/");for(let i=1;is!==e&&s&&s.split("/").slice(-i).join("/")===l))return l}return e}function fu(e){if(!e)return null;const t=Math.floor(e.age_s/86400),n=Math.floor(e.age_s%86400/3600),i=t>0?`${t}d ${n}h`:`${n}h`;return{label:e.trigger==="mem"?`${e.gb}G`:`${t}d`,title:`Claude is using ${e.gb}GB after ${i} — consider exiting and resuming this session`,cls:`mem-${e.tier}`}}function lr(e,t){return e?`https://github.com/${e}/pull/${t}`:null}function Ui(e){return e==="merged"?{cls:"is-merged",suffix:" (merged)"}:e==="closed"?{cls:"is-closed",suffix:" (closed)"}:{cls:"",suffix:""}}async function ie(e,t,n={}){const i=n.method||"GET";let l;try{l=await fetch(t,n)}catch(s){return ye(`api:${e}`,{path:t,method:i,ok:!1}),kn(`${e} failed: ${s.message}`,"bad",6e3),null}let a={};try{a=await l.json()}catch{}if(!l.ok||a.ok===!1){ye(`api:${e}`,{path:t,method:i,ok:!1});const s=a.error||a.detail||`HTTP ${l.status}`;return kn(`${e} failed: ${s}`,"bad",6e3),null}return ye(`api:${e}`,{path:t,method:i,ok:!0}),a}async function Lg(e,t){var a,s;let n;try{n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),...typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"?{signal:AbortSignal.timeout(1e4)}:{}})}catch(o){return{ok:!1,status:0,detail:(o==null?void 0:o.message)||String(o)}}let i={};try{i=await n.json()||{}}catch{}const l=typeof i.detail=="string"?i.detail:typeof i.error=="string"?i.error:((s=(a=i.detail)==null?void 0:a[0])==null?void 0:s.msg)||`HTTP ${n.status}`;return{ok:n.ok,status:n.status,detail:l}}const me=H({loaded:!1,ui:{},windows:{},commands:[]}),G=()=>me.value;async function Wi(){try{const e=await fetch("/api/prefs");if(!e.ok)throw new Error(`HTTP ${e.status}`);const t=await e.json();return me.value={...me.value,ui:t.ui||{},windows:t.windows||{},commands:t.commands||[],loaded:!0},await Bg(),me.value}catch{return me.value={...me.value,loaded:!1},null}}function Wr(){return G().commands||[]}async function Ig({label:e,exec:t}){if(!G().loaded)return!1;const n=await ie("add command","/api/prefs/commands",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:e,exec:""})});return n?(me.value={...G(),commands:n.commands},!0):!1}async function Og(e,{label:t,exec:n}){if(!G().loaded)return!1;const i=await ie("update command",`/api/prefs/commands/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:t,exec:n||""})});return i?(me.value={...G(),commands:i.commands},!0):!1}async function Dg(e){if(!G().loaded)return!1;const t=await ie("delete command",`/api/prefs/commands/${encodeURIComponent(e)}`,{method:"DELETE"});return t?(me.value={...G(),commands:t.commands},!0):!1}async function Rg(e){if(!G().loaded)return!1;const t=await ie("reorder commands","/api/prefs/commands",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({labels:e})});return t?(me.value={...G(),commands:t.commands},!0):!1}async function $e(e,t){if(!G().loaded&&(await Wi(),!G().loaded))return!1;const n={...G().ui};me.value={...G(),ui:{...G().ui,...e}};const i=await ie("save prefs","/api/prefs/ui",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{...e,writer:t}:e)});return i?(me.value={...G(),ui:i.ui},!0):(me.value={...G(),ui:n},!1)}function Fg(e){me.value={...G(),ui:e}}function Pr(e){if(!e)return null;const t=G().windows[e];if(!t)return null;const n=t.notes||"",i=t.tags||[],l=t.pinned_files||[];return!n&&!i.length&&!l.length?null:{notes:n,tags:i,pinned_files:l}}async function Kr(e,{notes:t,tags:n,pinned_files:i}){if(!G().loaded&&(await Wi(),!G().loaded))return!1;const l=G().windows[e],a=l||{},s={...a,notes:t??a.notes,tags:n??a.tags,pinned_files:i??a.pinned_files};me.value={...G(),windows:{...G().windows,[e]:s}};const o={};t!==void 0&&(o.notes=t),n!==void 0&&(o.tags=n),i!==void 0&&(o.pinned_files=i);const u=await ie("save annotation",`/api/prefs/windows/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!u){const c={...G().windows};return l===void 0?delete c[e]:c[e]=l,me.value={...G(),windows:c},!1}return me.value={...G(),windows:{...G().windows,[e]:{...G().windows[e]||{},...u.annotation}}},!0}function pu(e){if(!e)return[];const t=G().windows[e];return[...(t==null?void 0:t.pinned_files)||[]]}function Ng(e,t){if(!e||!t)return Promise.resolve(!1);const n=pu(e),i=n.includes(t)?n.filter(l=>l!==t):[...n,t];return Kr(e,{pinned_files:i})}async function Bg(){const e={"periscope:sessionOrder":"session_order","periscope:collapsedSessions":"collapsed_sessions","periscope:view":"view"};if(!Object.keys(e).some(l=>localStorage.getItem(l)!==null))return;const n=G().ui;if(!n.session_order&&!n.collapsed_sessions&&!n.view){const l={};for(const[a,s]of Object.entries(e)){const o=localStorage.getItem(a);if(o!==null)try{l[s]=s==="view"?o:JSON.parse(o)}catch{}}if(Object.keys(l).length&&!await $e(l))return}for(const l of Object.keys(e))localStorage.removeItem(l)}function gi(){const e=G().ui||{};return[...e.track_order||e.repo_order||[]]}function zg(e,t){return $e({track_order:e},t)}function ar(){return{...(G().ui||{}).tabs_by_track||{}}}function jg(e){return $e({tabs_by_track:e})}function Ta(){var e;return{...((e=G().ui)==null?void 0:e.branch_order_by_track)||{}}}function sr(){var e;return{...((e=G().ui)==null?void 0:e.rail_collapsed)||{}}}function mu(e,t){const n=sr();return n[e]=t,$e({rail_collapsed:n})}function Hg(){var e;return((e=G().ui)==null?void 0:e.last_selected)||null}function yt(e){return $e({last_selected:e})}function qg(){var e;return((e=G().ui)==null?void 0:e.launch_profile)||"default"}function Ug(e){return $e({launch_profile:e})}function gu(){var e;return au((e=G().ui)==null?void 0:e.tama_critter).id}function Wg(e){return $e({tama_critter:e})}function or(e){var t;return uu((t=G().ui)==null?void 0:t[`${e}_font`],e)}function Kg(e,t){return $e({[`${e}_font`]:t})}const Vg={needs_input:!0,done:!0,ci_failed:!0,pr_merged:!0,usage:!0,quiet_when_focused:!0,group:!0,badge:!0};function yi(){var e;return{...Vg,...((e=G().ui)==null?void 0:e.notify)||{}}}function Gg(e,t){return $e({notify:{...yi(),[e]:t}})}function Ea(){var e;return[...((e=G().ui)==null?void 0:e.pinned_pids)||[]]}function Jg(e){return $e({pinned_pids:e})}function Qg(e){const t=Ea(),n=t.includes(e)?t.filter(i=>i!==e):[...t,e];return Jg(n)}function Yg(e){var t;return((t=G().ui)==null?void 0:t[e])??null}function Ns(e,t){return $e({[e]:t})}function Pa(e){var t;return!!((t=G().ui)!=null&&t[`${e}_hidden`])}function Zg(e,t){return $e({[`${e}_hidden`]:t})}function yu(e){var t,n;return((n=(t=G().ui)==null?void 0:t.detail_mode_by_pid)==null?void 0:n[e])||null}function Ul(e,t){var i;const n={...((i=G().ui)==null?void 0:i.detail_mode_by_pid)||{}};return n[e]=t,$e({detail_mode_by_pid:n})}function Aa(){const e=G().ui||{};return{merged:e.clawd_merged,furious:e.clawd_furious}}async function bu(e,t){var n;return G().loaded||await Wi(),!G().loaded||((n=Aa()[e])==null?void 0:n.slice(0,10))===t.slice(0,10)?!1:$e({[`clawd_${e}`]:t})}function Ke(){return typeof window<"u"&&typeof window.__TAURI_INTERNALS__<"u"&&typeof window.__TAURI_INTERNALS__.invoke=="function"}function Cn(e,t){return window.__TAURI_INTERNALS__.invoke(e,t||{})}async function Ma(e,t){const n=window.__TAURI_INTERNALS__.transformCallback(i=>{i!=null&&i.payload&&t(i.payload)});await Cn("plugin:event|listen",{event:e,target:{kind:"Any"},handler:n})}async function Xg(e){if(Ke())try{const t=e>0?Math.floor(e):null;await Cn("plugin:window|set_badge_count",{count:t})}catch(t){console.warn("[tauri] setBadgeCount failed:",t)}}async function ku({title:e,body:t,target:n="",...i}){if(Ke())try{await Cn("plugin:event|emit",{event:"periscope:notify",payload:{title:e,body:t,target:n,...i}})}catch(l){console.warn("[tauri] notify failed:",l)}}async function e1(e){if(Ke())try{await Ma("periscope:notification-clicked",e)}catch(t){console.warn("[tauri] notification-click listener failed:",t)}}async function t1(e){if(Ke())try{await Ma("periscope:notification-opened",e)}catch(t){console.warn("[tauri] notification-opened listener failed:",t)}}async function n1(e){if(Ke())try{await Ma("periscope:notification-action",e)}catch(t){console.warn("[tauri] notification-action listener failed:",t)}}async function r1(e){if(Ke())try{await Cn("plugin:event|emit",{event:"periscope:notify-categories",payload:e})}catch(t){console.warn("[tauri] setNotifyCategories failed:",t)}}function Ki(e){if(Ke())return Cn("plugin:opener|open_url",{url:e}).catch(t=>{console.warn("[tauri] open_url failed:",t)}),!0;try{if(window.open(e,"_blank","noopener,noreferrer"))return!0}catch(t){console.warn("[periscope] window.open threw:",t)}try{const t=document.createElement("a");return t.href=e,t.target="_blank",t.rel="noopener noreferrer",document.body.appendChild(t),t.click(),t.remove(),!0}catch(t){console.warn("[periscope] anchor-click fallback threw:",t)}return!1}function i1(){Ke()&&document.addEventListener("click",e=>{const t=e.target.closest("a[href]");if(!t)return;let n;try{n=new URL(t.href)}catch{return}n.protocol!=="http:"&&n.protocol!=="https:"||n.origin!==location.origin&&(e.preventDefault(),e.stopPropagation(),Cn("plugin:opener|open_url",{url:n.href}).catch(i=>{console.warn("[tauri] open_url failed:",i)}))},!0)}function l1(e){return!!(e!=null&&e.asked_question)&&!(e!=null&&e.waiting_for)}function Bs(e,t,n){const i=new Set((t||[]).filter(a=>a.state===n).map(a=>a.pid)),l=new Set;for(const a of e)i.has(a)&&l.add(a);return l}function La(e,t,n,i=new Set){const l=Oa(e),a=(e||[]).filter(o=>o.state==="needs-input").filter(o=>!i.has(o.pid)).map(o=>({kind:"live",pid:o.pid,w:o})),s=(t||[]).filter(o=>o.kind==="need_human").filter(o=>!n.has(o.id)).filter(o=>!Ia(o,l)).sort((o,u)=>u.ts-o.ts).map(o=>({kind:"event",id:o.id,pane_id:o.pane_id,target:o.target,w:l[o.target]||null,message:o.message,ts:o.ts,session:o.session,name:o.name}));return[...a,...s]}function wu(e,t,n,i=new Set){const l=Oa(e),a=(e||[]).filter(u=>u.state==="done").filter(u=>!i.has(u.pid)).map(u=>({kind:"live",pid:u.pid,w:u})),s=new Set(a.map(u=>u.w.target)),o=(t||[]).filter(u=>u.kind==="done").filter(u=>!n.has(u.id)).filter(u=>!s.has(u.target)).filter(u=>!Ia(u,l)).sort((u,c)=>c.ts-u.ts).map(u=>({kind:"event",id:u.id,pane_id:u.pane_id,target:u.target,w:l[u.target]||null,message:u.message,ts:u.ts,session:u.session,name:u.name}));return[...a,...o]}function Ia(e,t){const n=t[e.target];return n?Math.max(n.focused_at||0,n.acted_at||0)>e.ts:!1}function a1(e){return e.length}const s1=600,o1=3600;function vu(e,t){const n=(t||0)-(e||0);return n>=o1?"urgent":n>=s1?"stale":"fresh"}function _u(e,t,n=new Set){var a;const i=Oa(e),l=new Map;for(const s of t||[]){if(s.kind!=="need_human"||n.has(s.id)||Ia(s,i))continue;const o=(a=i[s.target])==null?void 0:a.pid;if(!o)continue;const u=l.get(o);(u===void 0||s.ts!0){var u,c;const s=_u(e,t,n),o=new Map;for(const p of La(e,t,n,i)){if(!a(p.w))continue;const d=((u=p.w)==null?void 0:u.pid)!=null?`pid:${p.w.pid}`:`target:${p.target}`,f=Math.min(p.kind==="event"?p.ts:p.w.needs_since||l,...((c=p.w)==null?void 0:c.pid)!=null&&s.has(p.w.pid)?[s.get(p.w.pid)]:[]),h=o.get(d);o.set(d,{row:(h==null?void 0:h.row.kind)==="live"?h.row:p,since:h?Math.min(h.since,f):f})}return o}function Su(e){return(e||[]).filter(t=>t.state==="working").map(t=>({kind:"live",pid:t.pid,w:t}))}function c1(e,t){const n={};for(const i of t||[])n[i.pid]=i;return(e||[]).map(i=>n[i]).filter(Boolean)}function u1(e){return(e||[]).filter(t=>t.kind==="done"||t.kind==="info")}function Oa(e){const t={};for(const n of e||[])t[n.target]=n;return t}const Da=nr;let zs=!1;function jt(e){e&&at((ce.value||[]).find(t=>t.target===e))}function at(e){e!=null&&e.pid&&(ke.value=`pane:${e.pid}`,yt({kind:"pane",pid:e.pid}))}function $u(e){l1(e)&&(ft.value=new Set([...ft.value,e.pid])),at(e)}function Cu(e){e!=null&&e.pid&&(pt.value=new Set([...pt.value,e.pid]))}function Tu(e){Cu(e),at(e)}function d1(){zs||(zs=!0,e1(e=>jt(e)))}function Eu(e,t){!e||!t||(ke.value=`review:${e}/${t.replace(/\//g,"--")}`,yt({kind:"review",repo:e,branch:t}))}function Ra(){ke.value="reviews",yt({kind:"reviews"})}const fl=[{key:"all",label:"all"},{key:"needs-input",label:"needs input"},{key:"working",label:"working"},{key:"done",label:"done"},{key:"idle",label:"idle"},{key:"agents",label:"agents"},{key:"shell",label:"shells"},{key:"ci-bad",label:"CI ✗"}];function h1(){const[e,t]=B(!1),n=te(null),i=Rl.value,l=(fl.find(o=>o.key===i)||fl[0]).label,a=br(()=>t(!1),[]);Fi(n,e,a);function s(o){Rl.value=o,ye("filter.use"),t(!1)}return r("div",{class:"tb-dd","data-dd":"filter",ref:n,children:[r("button",{type:"button",class:"filter-btn tb-dd-toggle",id:"filter-dd-toggle","aria-haspopup":"menu","aria-expanded":e?"true":"false",title:"filter by state",onClick:o=>{o.stopPropagation(),t(u=>!u)},children:[r("span",{id:"filter-dd-label",children:l}),r("span",{class:"tb-dd-chev","aria-hidden":"true",children:"▾"})]}),r("div",{class:"tb-dd-menu",id:"filter-dd-menu",role:"menu",hidden:!e,children:fl.map(o=>r("button",{"data-filter":o.key,class:`tb-dd-item${o.key===i?" active":""}`,role:"menuitem",onClick:()=>s(o.key),children:o.label},o.key))})]})}const Pu=Vt(()=>Pa("rail")),bi=Vt(()=>Pa("side"));function Wl(e){return Zg(e,!Pa(e))}function js({side:e,shown:t}){return r("svg",{width:"16",height:"12",viewBox:"0 0 16 12","aria-hidden":"true",children:[r("rect",{x:"0.5",y:"0.5",width:"15",height:"11",rx:"1.5",fill:"none",stroke:"currentColor"}),r("rect",{x:e==="left"?2:10,y:"2",width:"4",height:"8",rx:"0.5",fill:t?"currentColor":"none",stroke:"currentColor","stroke-width":"0.75"})]})}function f1(){const e=!Pu.value,t=!bi.value;return r("span",{class:"panel-toggles",children:[r("button",{type:"button",class:"filter-btn is-action panel-toggle","aria-pressed":e,title:`${e?"Hide":"Show"} the navigator (⌘B)`,onClick:()=>Wl("rail"),children:r(js,{side:"left",shown:e})}),r("button",{type:"button",class:"filter-btn is-action panel-toggle","aria-pressed":t,title:`${t?"Hide":"Show"} the context column (⌥⌘B)`,onClick:()=>Wl("side"),children:r(js,{side:"right",shown:t})})]})}function cn(e){return e>=1024?`${(e/1024).toFixed(1)}G`:`${e}M`}function Au(e){return e==null?"–":e<10?`${e.toFixed(1)}%`:`${Math.round(e)}%`}function p1(e){var t;return e.server.mem_mb+(((t=e.webview)==null?void 0:t.mem_mb)||0)+e.panes.mem_mb}function m1(e){return e.filter(t=>t.res).map(t=>({w:t,...t.res})).sort((t,n)=>n.mem_mb-t.mem_mb)}function g1(e){return`${cn(e.ram_mb)} RAM · swap ${cn(e.swap_used_mb)}/${cn(e.swap_total_mb)} · ${e.mem_free_pct}% free · load ${e.load1}`}const y1="share of the whole machine's CPU: 100% is every core busy";function Ln({label:e,group:t,onClick:n}){const i=r(K,{children:[r("span",{class:"res-label",children:e}),r("span",{class:"res-mem",children:cn(t.mem_mb)}),r("span",{class:"res-cpu",title:y1,children:Au(t.cpu_pct)})]});return n?r("button",{type:"button",class:"res-line is-pane",onClick:n,children:i}):r("div",{class:"res-line",children:i})}function b1({r:e}){const t=te(null),n=te(null),[i,l]=B(!1),a=br(()=>{var o,u;const s=(o=t.current)==null?void 0:o.contains(document.activeElement);l(!1),s&&((u=n.current)==null||u.focus())},[]);return Fi(t,i,a),r("div",{class:"pill-dd",ref:t,children:[r("button",{type:"button",class:"res-pill",ref:n,title:"memory held by periscope's server, its webview and its panes — click for each one's memory and CPU","aria-haspopup":"dialog","aria-expanded":i?"true":"false",onClick:()=>l(!i),children:["▣ ",cn(p1(e))]}),r("div",{class:"tb-dd-menu res-menu",role:"dialog","aria-label":"resource usage",hidden:!i,children:[r(Ln,{label:"periscope server",group:e.server}),e.webview&&r(Ln,{label:"webview",group:e.webview}),r(Ln,{label:"all panes",group:e.panes}),r("div",{class:"res-pane-lines",children:m1(ce.value||[]).map(({w:s,mem_mb:o,cpu_pct:u})=>r(Ln,{label:_e(s),group:{mem_mb:o,cpu_pct:u},onClick:()=>{at(s),a()}},s.pid))}),r(Ln,{label:"elsewhere",group:e.elsewhere}),r("div",{class:"res-machine",children:g1(e.machine)})]})]})}function k1(){const e=Cc.value;return e&&r(b1,{r:e})}async function Mu(e){const t=Kn.value;Kn.value=e;const n=await ie("spawn account","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({spawn_account:e})});return n||(Kn.value=t),!!n}function w1(){if(!$n())return null;const e=[{id:null,label:"auto"},...lt.value],t=Kn.value||null,n=sn.value;return r("div",{class:"spawn-acct",title:`which account new Claude panes launch on auto — the account whose weekly reset is soonest (drain it before it resets) -a letter — pin every spawn (New Tab, + new, spawned workers) to one subscription`,children:[r("span",{class:"spawn-acct-label",children:"spawn"}),e.map(i=>r("button",{type:"button",class:`spawn-acct-btn${t===i.id?" is-active":""}`,title:i.id===null?n==null?void 0:n.reason:void 0,onClick:()=>Cu(i.id),children:i.id===null&&t===null&&n?`auto → ${gn(n.account)}`:i.label},i.id??"auto"))]})}const Oa=["default","low","medium","high","xhigh","max"];async function u1(e){const t=Kn.value;Kn.value=e,await ie("spawn effort","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({spawn_effort:e})})||(Kn.value=t)}function d1(){const e=Kn.value||"default";return r("div",{class:"spawn-acct spawn-effort",title:`reasoning effort new Claude panes launch at +a letter — pin every spawn (New Tab, + new, spawned workers) to one subscription`,children:[r("span",{class:"spawn-acct-label",children:"spawn"}),e.map(i=>r("button",{type:"button",class:`spawn-acct-btn${t===i.id?" is-active":""}`,title:i.id===null?n==null?void 0:n.reason:void 0,onClick:()=>Mu(i.id),children:i.id===null&&t===null&&n?`auto → ${yn(n.account)}`:i.label},i.id??"auto"))]})}const Fa=["default","low","medium","high","xhigh","max"];async function v1(e){const t=Gn.value;Gn.value=e,await ie("spawn effort","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({spawn_effort:e})})||(Gn.value=t)}function _1(){const e=Gn.value||"default";return r("div",{class:"spawn-acct spawn-effort",title:`reasoning effort new Claude panes launch at default — Claude's own choice for the model -low … max — every new pane starts there (New Tab, + new, spawned workers); change a running pane from its own header`,children:[r("span",{class:"spawn-acct-label",children:"effort"}),Oa.map(t=>r("button",{type:"button",class:`spawn-acct-btn${e===t?" is-active":""}`,onClick:()=>u1(t),children:t},t))]})}const sr=[{id:"default",label:"default"},{id:"fable",label:"fable"},{id:"opus[1m]",label:"opus 1m"},{id:"sonnet",label:"sonnet"}],h1=[{id:"auto",label:"auto"},...sr];async function f1(e){const t=Wn.value;Wn.value=e,await ie("spawn model","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({spawn_model:e})})||(Wn.value=t)}function p1(){const e=Wn.value||"auto",t=sn.value;return r("div",{class:"spawn-acct spawn-model",title:`which model new Claude panes launch on +low … max — every new pane starts there (New Tab, + new, spawned workers); change a running pane from its own header`,children:[r("span",{class:"spawn-acct-label",children:"effort"}),Fa.map(t=>r("button",{type:"button",class:`spawn-acct-btn${e===t?" is-active":""}`,onClick:()=>v1(t),children:t},t))]})}const cr=[{id:"default",label:"default"},{id:"fable",label:"fable"},{id:"opus[1m]",label:"opus 1m"},{id:"sonnet",label:"sonnet"}],x1=[{id:"auto",label:"auto"},...cr];async function S1(e){const t=Vn.value;Vn.value=e,await ie("spawn model","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({spawn_model:e})})||(Vn.value=t)}function $1(){const e=Vn.value||"auto",t=sn.value;return r("div",{class:"spawn-acct spawn-model",title:`which model new Claude panes launch on auto — fable until its weekly sub-limit walls, then opus 1m (per account) default — whatever the account's settings.json picks -fable / opus 1m / sonnet — pin every spawn (New Tab, + new, spawned workers); the launcher can still override one launch`,children:[r("span",{class:"spawn-acct-label",children:"model"}),h1.map(n=>r("button",{type:"button",class:`spawn-acct-btn${e===n.id?" is-active":""}`,title:n.id==="auto"?t==null?void 0:t.reason:void 0,onClick:()=>f1(n.id),children:n.id==="auto"&&e==="auto"&&t?`auto → ${t.model??"default"}`:n.label},n.id))]})}const Tu={cols:0,rows:0,shrunkFrom:0},m1=4,g1=(e,t)=>e>0&&t>0?Math.min(e,t):e||t;function y1(e,t){return t>0&&Math.abs(e-t)<=m1?t:e}function b1(e,t,n,i){return{cols:e||n,rows:g1(t,i)}}function k1(e,t,n){return e.cols!==t.cols?e:n>0&&e.rows0&&e.rows>t.rows?{rows:Math.min(e.rows,t.shrunkFrom)}:null}function Eu(e,t){const n=e.shrunkFrom||e.rows;return{cols:t.cols??e.cols,rows:t.rows,shrunkFrom:t.rows0&&e.rows>0&&(Y.cols!==e.cols||Y.rows!==e.rows)&&Y.resize(e.cols,e.rows)}let Ze=null,tt=null;function x1(){ue&&ue.readyState===WebSocket.OPEN&&ue.send(JSON.stringify({type:"reconcile"}))}function S1(){if(!Y)return!0;const e=Y.buffer.active;return e.viewportY>=e.baseY}function Ou(e){Ze=e}let cr=null;function zs(e){cr=e}const Du=/\b(?:https?|wss?):\/\/[^\s)"'`<>]+/g,$1=new RegExp("(?=t.cols||o<0||o>=t.rows)return null;const u=t.buffer.active,c=u.getLine(u.viewportY+o);if(!c)return null;const f=c.translateToString(!0);for(const p of f.matchAll(Du)){const h=p.index,m=h+p[0].length;if(s>=h&&s{if(n.button!==0)return;const i=T1(n,e);i&&(Qt={url:i,x:n.clientX,y:n.clientY})},Hs=n=>{if(n.button!==0||!Qt)return;const i=Math.abs(n.clientX-Qt.x),l=Math.abs(n.clientY-Qt.y),{url:a}=Qt;if(Qt=null,i>4||l>4)return;qi(a)||e.writeln(`\r -\x1B[31m[periscope: failed to open ${a}]\x1B[0m`)},t.addEventListener("mousedown",js,!0),t.addEventListener("mouseup",Hs,!0))}function A1(e){e.registerLinkProvider({provideLinks(t,n){var s;const i=(s=e.buffer.active.getLine(t-1))==null?void 0:s.translateToString(!0);if(!i)return n(void 0);const l=[];function a(o,u){for(const c of i.matchAll(o)){const f=c[0],d=c.index+1,p=d+f.length-1;l.push({text:f,range:{start:{x:d,y:t},end:{x:p,y:t}},activate(h,m){u!=="url"&&(!h.metaKey&&!h.ctrlKey||u==="file"&&cr&&cr(m))},hover(){},leave(){}})}}a(Du,"url"),a($1,"file"),a(C1,"file"),n(l)}})}function M1(){try{return localStorage.getItem("periscope.noWebgl")==="1"}catch{return!1}}function L1(){var t,n;if(!Mt)return;const e=(t=Mt._renderer)==null?void 0:t._gl;try{Mt.dispose()}catch{}try{(n=e==null?void 0:e.getExtension("WEBGL_lose_context"))==null||n.loseContext()}catch{}Mt=null}function qs(e){var n;if(!((n=document.fonts)!=null&&n.load))return;const t=`${Pu.fontSize}px "${e.face}"`;Promise.all([document.fonts.load(t),document.fonts.load(`bold ${t}`)]).then(()=>{!Y||en!==e||(Y.options.fontFamily="monospace",Y.options.fontFamily=e.stack,kr())},()=>{})}function I1(){if(!Y){if(tt=document.createElement("div"),tt.className="xterm-host",en=ar("code"),Y=new Terminal({...Pu,fontFamily:en.stack,theme:w1,linkHandler:{allowNonHttpProtocols:!0,activate(e,t){if(t.startsWith("file://")){if(!e.metaKey&&!e.ctrlKey||!cr)return;let n=t.slice(7);n.startsWith("localhost/")&&(n=n.slice(9));try{n=decodeURIComponent(n)}catch{}cr(n);return}qi(t)}}}),Y.open(tt),qs(en),lt(()=>{const e=ar("code");e!==en&&(en=e,Y.options.fontFamily=e.stack,qs(e))}),Y.attachCustomWheelEventHandler(e=>{if(!Da||!e.deltaY)return!0;const t=E1(e,Y);if(!t)return!0;e.preventDefault();let n=e.deltaY;e.deltaMode===1?n*=t.cellH:e.deltaMode===2&&(n*=t.pageH),n<0!=tn<0&&(tn=0),tn+=n;const i=t.cellH*v1;let l=Math.trunc(tn/i);if(!l)return!1;tn-=l*i,l=Math.max(-8,Math.min(8,l));const a=l<0?64:65;return ue&&ue.readyState===WebSocket.OPEN&&ue.send(`\x1B[<${a};${t.col};${t.row}M`.repeat(Math.abs(l))),!1}),M1())console.warn("[periscope] WebGL renderer disabled via localStorage periscope.noWebgl");else try{Mt=new WebglAddon.WebglAddon,Mt.onContextLoss(()=>{L1()}),Y.loadAddon(Mt)}catch(e){console.warn("[periscope] WebGL terminal renderer unavailable; using the DOM renderer:",e)}bt=new SearchAddon.SearchAddon,Y.loadAddon(bt);try{Y.loadAddon(new Unicode11Addon.Unicode11Addon),Y.unicode.activeVersion="11"}catch(e){console.warn("[periscope] Unicode 11 widths unavailable; emoji will offset the cursor:",e)}A1(Y),P1(Y),or=new FitAddon.FitAddon,Y.loadAddon(or),Y.attachCustomKeyEventHandler(e=>{if(e.type!=="keydown")return!0;if(e.key==="Escape"&&e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey)return e.preventDefault(),e.stopPropagation(),ue&&ue.readyState===WebSocket.OPEN&&ue.send("\x1B"),!1;if(e.key==="Escape"&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey)return!1;if(e.key==="Enter"&&e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey)return e.preventDefault(),ue&&ue.readyState===WebSocket.OPEN&&ue.send("\x1B\r"),!1;if(!e.metaKey)return!0;const t=n=>{e.preventDefault(),ue&&ue.readyState===WebSocket.OPEN&&ue.send(n)};switch(e.key){case"Backspace":return t("".repeat(200)),!1;case"Delete":return t("\v"),!1;case"ArrowLeft":return t(""),!1;case"ArrowRight":return t(""),!1;case"r":case"R":return!1;default:return!0}}),Y.onData(e=>{ue&&ue.readyState===WebSocket.OPEN&&ue.send(e)}),Y.onBell(()=>{Ze&&(Ze.classList.add("bell-pulse"),setTimeout(()=>Ze.classList.remove("bell-pulse"),400))})}}function O1(e){ye("terminal.open",{target:e});const t=Y!==null;if(I1(),Ze&&tt.parentElement!==Ze&&Ze.appendChild(tt),t){try{Y.reset()}catch{}Da=!1,tn=0}if(Y.focus(),Iu(),Na(),Lt)try{Lt.disconnect()}catch{}Lt=new ResizeObserver(kr),Ze&&Lt.observe(Ze),gi=e,yi=!1,Fn=0,Ur=!1,Ru(e,st.cols,st.rows)}function Ru(e,t=0,n=0){let l=`${location.protocol==="https:"?"wss":"ws"}://${location.host}/ws/pane?${$g(e)}`;t>0&&n>0&&(l+=`&cols=${t}&rows=${n}`,cn=Eu(cn,{cols:t,rows:n}));const a=new WebSocket(l);a.binaryType="arraybuffer",ue=a,a.onopen=()=>{Fn>0&&Y&&Y.writeln(`\r -\x1B[32m[periscope: reconnected]\x1B[0m`),Fn=0,Ur=!1},a.onmessage=s=>{if(typeof s.data=="string")try{const o=JSON.parse(s.data);o.type==="size"?(Fa=o.cols,Ui=o.rows,Na(),kr()):o.type==="mouse"&&(Da=!!o.on)}catch{Y.write(Bs(s.data,ql))}else Y.write(Bs(new Uint8Array(s.data),ql))},a.onerror=()=>{},a.onclose=s=>{if(a!==ue||yi||!Y||gi!==e)return;Ur||(Y.writeln(`\r -\x1B[33m[periscope: reconnecting…]\x1B[0m`),Ur=!0);const o=[250,500,1e3,2e3],u=o[Math.min(Fn,o.length-1)]||4e3;Fn+=1,At&&clearTimeout(At),At=setTimeout(()=>{At=null,!(!Y||gi!==e||yi)&&Ru(e,st.cols,st.rows)},u)}}function kr(){It&&clearTimeout(It),It=setTimeout(()=>{if(It=null,!Y||!or||Ra||!Iu())return;Na();const e=k1(st,cn,Ui);e&&ue&&ue.readyState===WebSocket.OPEN&&(cn=Eu(cn,e),ue.send(JSON.stringify({type:"resize",...e})))},80)}function D1(){if(yi=!0,gi=null,At&&(clearTimeout(At),At=null),cn=Tu,Fa=0,Ui=0,It&&(clearTimeout(It),It=null),Lt){try{Lt.disconnect()}catch{}Lt=null}if(ue){try{ue.close()}catch{}ue=null}tt!=null&&tt.parentElement&&tt.remove()}function Us(e){Y&&Y.writeln(e)}function bi(){if(Y)try{Y.scrollToBottom()}catch{}}function R1(){!Y||!or||kr()}function F1(){Ra=!0}function N1(){Ra=!1,kr()}function Ws(e,t={}){return bt?bt.findNext(e,t):!1}function Ks(e,t={}){return bt?bt.findPrevious(e,t):!1}function B1(){bt&&bt.clearDecorations()}let Gn=null,Wr=null;function z1(e,t,n={}){Fu(),Ou(e),ql=n.agent||null,n.onPaste&&(Gn=n.onPaste,e.addEventListener("paste",Gn,!0)),Wr=e,O1(t),requestAnimationFrame(()=>requestAnimationFrame(()=>{R1(),bi()})),setTimeout(bi,300)}function Fu(){D1(),Wr&&Gn&&Wr.removeEventListener("paste",Gn,!0),Gn=null,Wr=null,Ou(null)}function Nu(e){return typeof e!="string"?null:e.startsWith("pane:")?e.slice(5):null}function j1(e,t){const n=Nu(e),i=n?t==null?void 0:t[n]:null;return typeof i=="string"&&i.startsWith("file:")?"document":"terminal"}function H1(e){return(e.metaKey||e.ctrlKey)&&(e.key==="r"||e.key==="R")}function q1(e){return e.repeat||!(e.metaKey||e.ctrlKey)||e.shiftKey||e.code!=="KeyB"?null:e.altKey?"side":"rail"}function U1(e=window){e.addEventListener("keydown",t=>{const n=q1(t);if(n){t.preventDefault(),Hl(n);return}if(H1(t)){if(t.preventDefault(),t.shiftKey){location.reload();return}if(j1(ke.value,Re.value)==="document"){hs.value=hs.value+1;return}x1()}})}function Er(e,t){if(!t||!e)return e;const n={...e};return e.fill&&(n.fill=Is(e.fill,t)),e.stroke&&(n.stroke=Is(e.stroke,t)),n}const Vs=e=>e!=null&&e.stroke?{stroke:iu,"stroke-width":e["stroke-width"]}:void 0;function Oe({n:e,mood:t,asleep:n,hide:i,tint:l,rest:a,paws:s,seated:o,flush:u}){if(u&&e.mood||e.mood&&e.mood!==t||a&&e.rest||s&&e.arms||o&&e.legs&&!e.keepSeated||(n||i)&&e.role==="glint"||i&&e.role==="eye")return null;if(e.r){const[c,f,d,p]=e.r;return u?r("rect",{class:e.cls,x:c,y:f,width:N(d+.02),height:N(p+.02),...Vs(e.a)}):r("rect",{class:e.cls,x:c,y:f,width:d,height:p,...Er(e.a,l)})}if(e.p)return u?null:r("path",{class:e.cls,d:e.p,...Er(e.a,l)});if(u){if((n||i)&&e.shut){const[c,f,d,p]=e.shut;return r("rect",{"data-role":"shut",x:c,y:f,width:N(d+.02),height:N(p+.02)})}return r("g",{class:e.anim||e.cls,...Vs(e.a),children:e.g.map((c,f)=>r(Oe,{n:c,mood:t,asleep:n,hide:i,rest:a,paws:s,seated:o,flush:!0},f))})}if((n||i)&&e.shut){const[c,f,d,p]=e.shut;return r("rect",{"data-role":"shut",x:c,y:f,width:d,height:p,...Er(e.g[0].a,l)})}return r("g",{class:e.anim||e.cls,"data-mood":e.mood,"data-role":e.role,...Er(e.a,l),children:e.g.map((c,f)=>r(Oe,{n:c,mood:t,asleep:n,hide:i,tint:l,rest:a,paws:s,seated:o},f))})}function Wi({sprite:e,mood:t="calm",asleep:n=!1,face:i=null,startle:l=!1,tint:a=0,worn:s=null,holding:o=null,tip:u=null,paws:c=!1,cheer:f=!1,seated:d=!1,stride:p=!1,children:h}){const m=hg.has(i),b=u??(o&&_a[o]?zi(e,o):null),x=!!b||f&&kg(e),w=t==="furious"&&!n,C=v=>v.role!==void 0||(v.g||[]).some(C),y=p?dg(e):e.root,g=w?e.root.filter(v=>v.mood==="furious"||C(v)):[],$=w?y.filter(v=>!g.includes(v)):y;return r("g",{class:"critter","data-face":i||void 0,"data-worn":s||void 0,"data-holding":o||void 0,children:[$.map((v,E)=>r(Oe,{n:v,mood:t,asleep:n,hide:m,tint:a,rest:x,paws:c,seated:d},E)),i&&pg(e,i).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`face-${E}`)),s&&yg(e,s).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`worn-${E}`)),l&&mg(e,!!b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`startle-${E}`)),h,b&&Bl(e,o,b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`hold-${E}`)),f&&wg(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`cheer-${E}`)),w&&r("g",{class:"tama-flush",fill:iu,opacity:"0.5",children:[y.map((v,E)=>r(Oe,{n:v,mood:t,hide:m,rest:x,paws:c,seated:d,flush:!0},E)),b&&Bl(e,o,b).map((v,E)=>r(Oe,{n:v,mood:t,flush:!0},`hold-${E}`))]}),w&&g.map((v,E)=>r(Oe,{n:v,mood:t,asleep:n,hide:m,tint:a,rest:x,paws:c,seated:d},`fu-${E}`)),w&&_g(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`teeth-${E}`))]},w?"furious":"calm")}function W1(e){return e==null?"":e>=80?" ctx-hot":e>=60?" ctx-warn":""}function Ul(e){return e.ctx_class&&e.ctx_class!=="none"?` ctx-${e.ctx_class}`:W1(e.context_pct)}const Gs=["bell","api","done","merged","ctx","ci","update"],Bu=600;function Js(e,t){const n=Math.floor((t-e)/60);return n<1?"":n<60?` (${n} min)`:` (${Math.floor(n/60)}h ${n%60}m)`}const Mn=(e,t,n={})=>({action:e,pid:t.pid,says:`open ${Se(t)}`,...n});function K1({windows:e=[],alerts:t=[],dismissedAlertIds:n=new Set,dismissedNeedsPids:i=new Set,dismissedReadyPids:l=new Set,selectedPid:a=null,parties:s=[],update:o=null,nowSec:u}){const c=[],f=g=>!g||a==null||String(g.pid)!==String(a),d=e.filter(f),p=new Map(e.map(g=>[String(g.pid),g])),h=ku(e,t,n,i,u,f);if(h.size){const g=[...h.values()].reduce((E,A)=>A.sinceg.api_error);m.length&&c.push({kind:"api",count:m.length,label:"API",phrase:`the Anthropic API is erroring in ${kn(m.length,"pane")}, not your code`,target:Mn("select",m[0])});const b=new Map;for(const g of e){if(g.ci!=="✗"||!g.pr||g.pr_state&&g.pr_state!=="open")continue;const $=`${g.repo_slug||g.repo_key||""}#${g.pr}`;b.has($)||b.set($,{pr:g.pr,panes:[]}),b.get($).panes.push(g)}const x=[...b.values()].filter(g=>g.panes.every(f));x.length&&c.push({kind:"ci",count:x.length,label:String(x.length),phrase:x.length===1?`PR #${x[0].pr} is failing CI`:`${x.length} PRs failing CI`,target:Mn("select",x[0].panes[0])});const w=gu(e,t,n,l).filter(g=>f(g.w));if(w.length){const g=w[0],$=g.w?Se(g.w):g.name||"a pane";c.push({kind:"done",count:w.length,label:String(w.length),phrase:w.length===1?`${$} finished`:`${w.length} panes finished`,target:g.kind==="live"?Mn("ready",g.w):{action:"reveal",target:g.target,says:`open ${$}`}})}const C=s.filter(g=>u-g.atUl(g)===" ctx-hot");if(y.length){const g=y.filter(A=>(A.context_pct??0)>=80),$=g.length?g.reduce((A,T)=>T.context_pct>A.context_pct?T:A):y[0],v=g.length?Math.round($.context_pct):null,E=y.length>1?`${y.length} panes worth compacting`:v!=null?`${Se($)} is running out of context (${v}%)`:`${Se($)} is costly to keep carrying${$.ctx_hint?`: ${$.ctx_hint}`:""}`;c.push({kind:"ctx",count:y.length,label:v!=null?`${v}%`:String(y.length),pct:v,cost:v==null,phrase:E,target:Mn("select",$)})}return(o==null?void 0:o.behind)>0&&!o.running&&c.push({kind:"update",count:1,label:"new",phrase:`periscope ${o.target} is out`,target:{action:"update",says:"see the update"}}),c.sort((g,$)=>Gs.indexOf(g.kind)-Gs.indexOf($.kind))}function V1(e){return e.slice(1).reduce((t,n)=>t+n.count,0)}const G1=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function J1(e,t){if(!e)return{day:null,time:"later"};const n=new Date(e*1e3),i=n.getHours(),l=n.getMinutes(),a=`${i%12||12}${l?`:${String(l).padStart(2,"0")}`:""}${i<12?"am":"pm"}`;return{day:e-t>20*3600?G1[n.getDay()]:null,time:a}}function Q1({day:e,time:t}){return`every account is at its limit until ${e?`${e} `:""}${t}`}const Y1=new Set(["done","merged","ci","api","ctx"]);function zu(e,t){const n=e==="code";return{atDesk:n,moodShown:n&&!t,showsPanes:n&&!Y1.has(t)}}function Z1({states:e,parties:t},n,i){const l={...e},a=t.filter(s=>i-s.atc.key===u)&&a.push({key:u,pid:s.pid,pr:s.pr,at:i})}return{states:l,parties:a}}const X1=600;function Ba(e,t){return!!(e!=null&&e.fetched_at)&&t-e.fetched_at>X1}function za(e){const t=[e==null?void 0:e.projected_percent,e==null?void 0:e.projected_recent].filter(i=>i!=null);if(!t.length)return!1;const n=Math.max(...t);return n>(e.percent??0)&&n>=100}function ju(e){return e!=null&&e.hot?"furious":za(e)?"grumpy":"calm"}const e0={session:"session",week_all:"week",week_opus:"opus",week_sonnet:"sonnet"};function ja(e){return e0[e]||e.replace(/^week_/,"")}const Hu=[{from:0,to:7,id:"sleep",label:"sleeping"},{from:7,to:9,id:"coffee",label:"having coffee"},{from:9,to:10,id:"code",label:"coding with a coffee",coffee:!0},{from:10,to:12,id:"code",label:"coding"},{from:12,to:13,id:"eat",meal:"lunch"},{from:13,to:17,id:"code",label:"coding"},{from:17,to:18,pastime:!0},{from:18,to:19,id:"eat",meal:"dinner"},{from:19,to:21,id:"read",label:"reading"},{from:21,to:24,id:"sleep",label:"sleeping"}],qu=[{from:0,to:9,id:"sleep",label:"sleeping"},{from:9,to:11,id:"eat",meal:"brunch"},{from:11,to:18,pastime:!0},{from:18,to:19,id:"eat",meal:"dinner"},{from:19,to:21,id:"read",label:"reading"},{from:21,to:24,id:"sleep",label:"sleeping"}],un=17,Qs=16,Be=.5,Ha=Hu.map(e=>{const t=e.id==="code"?{...e,id:"nap",label:"napping at the desk"}:e;return t.to===un?{...t,to:Qs}:t.from===un?{...t,from:Qs}:t}),Uu=e=>e.getDay()===0||e.getDay()===6,Ki=(e,t)=>e.find(n=>t>=n.from&&tKi(Uu(e)?qu:Ha,un),Ys=[{id:"run",label:"out for a run"},{id:"cycle",label:"out cycling",seasons:["spring","summer","autumn"]},{id:"music",label:"practicing bass"},{id:"beer",label:"having a beer with friends"},{id:"kids",label:"spending time with the kids"},{id:"game",label:"playing video games"},{id:"garden",label:"gardening",seasons:["spring","summer"]},{id:"cook",label:"cooking"},{id:"dog",label:"walking the dog"},{id:"swim",label:"out for a swim",seasons:["summer"]},{id:"sled",label:"out sledding",seasons:["winter"]}],n0={run:"trick-or-treating",kids:"trick-or-treating with the kids"},r0=[{id:"ramen",label:"ramen"},{id:"pizza",label:"pizza"},{id:"burger",label:"a burger"},{id:"sushi",label:"sushi"},{id:"tacos",label:"tacos"},{id:"pasta",label:"pasta"},{id:"salad",label:"a salad"},{id:"soup",label:"soup",seasons:["winter"]}],i0=[{id:"pancakes",label:"pancakes"},{id:"waffles",label:"waffles"},{id:"eggs",label:"eggs and bacon"}],l0={id:"roast",label:"a roast"},Zs={halloween:{id:"pie",label:"pumpkin pie"},summer:{id:"icecream",label:"ice cream"}},Wu=e=>t=>!t.seasons||t.seasons.includes(wr(e)),dn=e=>e.getHours()+e.getMinutes()/60;function Ku(e,t){let n=2166136261;for(const i of`${Vi(e)}|${t}`)n=Math.imul(n^i.charCodeAt(0),16777619);return n=Math.imul(n^n>>>16,2246822507),n=Math.imul(n^n>>>13,3266489909),(n^n>>>16)>>>0}function Kr(e,t,n,i=[]){let l=Ku(t,n)%e.length;for(;i.includes(e[l].id);)l=(l+1)%e.length;return e[l]}const a0=e=>Math.floor(e/6e4)*6e4,qa=e=>(e.walls||[]).map(t=>t.map(a0)).filter(([t,n])=>tqa(t).some(([n,i])=>n<=e.getTime()&&e.getTime()qa(e).map(t=>t.map(s0)).filter(([t,n])=>ti<=n&&n({...e,label:`having ${t.label} for ${n}`,dish:t.id});function o0(e,t){var u;if(e.meal==="brunch")return dl(e,Kr(i0,t,"brunch"),"brunch");const n=(u=Gi(t))==null?void 0:u.id,i=e.meal==="dinner"&&(Zs[n]||Zs[wr(t)]),l=e.from+Be;if(i&&dn(t)>=l)return{...dl(e,i,"dessert"),from:l};const a=r0.filter(Wu(t)),s=Kr(a,t,"lunch"),o=e.meal==="lunch"?s:n==="yearend"?l0:Kr(a,t,"dinner",[s.id]);return{...dl(e,o,e.meal),...i?{to:l}:{}}}function c0(e,t,n){var p;const i=h=>Ys.find(m=>m.id===h),l=(e.to-e.from)/Be,a=h=>(h-e.from)/Be,s=h=>e.from+h*Be,o=[un,un+Be].map(a),u=h=>!!Ki(Ju(ur(t,s(h)),n),s(h)).pastime,c=[],f=Ys.filter(Wu(t)),d=()=>{var m,b;const h=[];for(let x=0;x{const x=(h+b)%2?"kids":"run";c[m]={...i(x),label:n0[x],trick:!0}})}else{t.getDay()===5&&(c[a(un+Be)]=i("beer"));const h=[["furious","run"],["merged","beer"]].filter(([m])=>n[m]!=null).sort(([m],[b])=>n[m]-n[b]);for(const[m,b]of h){if(o.some(C=>{var y;return((y=c[C])==null?void 0:y.id)===b}))continue;const x=Math.floor(a(n[m]));if(x>=o[0]-1&&x!c[C]&&C>x);w!==void 0&&(c[w]=i(b))}}return d()}function dr(e,t={}){const n=Ki(Ju(e,t),e.getHours());if(n.meal)return o0(n,e);if(n.pastime){const o=t0(e),u=Math.floor((dn(e)-o.from)/Be),c=o.from+u*Be;return{...o,...c0(o,e,t)[u],from:c,to:c+Be}}if(n.id!=="code"&&n.id!=="nap")return n;const i=e.getTime(),l=Gu(t).flat(),a=Math.max(ur(e,n.from).getTime(),...l.filter(o=>o<=i)),s=Math.min(ur(e,n.to).getTime(),...l.filter(o=>o>i));return{...n,from:dn(new Date(a)),to:dn(new Date(s))}}function Qu(e,t={}){const n=e.getTime(),{to:i}=dr(e,t);return Math.min(ur(e,i).getTime(),...qa(t).flat().filter(l=>l>n))-n}function u0(e,t={}){const n=dr(e,t);let i=e;for(let l=0;l<8;l++){i=new Date(i.getTime()+Qu(i,t));const a=dr(i,t);if(a.id!==n.id||a.dish!==n.dish)return{at:i,activity:a}}return null}function Xs(e,t={}){var i;const n=dr(e,t);return`${n.from}|${n.id}|${n.dish||""}|${wr(e)}|${((i=Gi(e))==null?void 0:i.id)||""}|${nd(e)||""}|${Vu(e,t)}`}const ki=e=>String(e).padStart(2,"0");function Vi(e){return`${e.getFullYear()}-${ki(e.getMonth()+1)}-${ki(e.getDate())}`}function Yu(e){return`${Vi(e)}T${ki(e.getHours())}:${ki(e.getMinutes())}`}function Zu(e,t){const n=Vi(t),i=l=>{const a=/^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2})$/.exec(l||"");return(a==null?void 0:a[1])===n?Number(a[2])+Number(a[3])/60:null};return{merged:i(e==null?void 0:e.merged),furious:i(e==null?void 0:e.furious)}}const d0={spring:[245162380984e-5,365242.37404,.05169,-.00411,-57e-5],summer:[245171656767e-5,365241.62603,.00325,.00888,-3e-4],autumn:[245181021715e-5,365242.01767,-.11575,.00337,78e-5],winter:[245190005952e-5,365242.74049,-.06223,-.00823,32e-5]},h0=["spring","summer","autumn","winter"];function f0(e,t){const[n,i,l,a,s]=d0[e],o=(t-2e3)/1e3,u=n+i*o+l*o**2+a*o**3+s*o**4;return new Date((u-24405875e-1)*864e5)}const wi=e=>e.getFullYear()*1e4+(e.getMonth()+1)*100+e.getDate();function Xu(e){const t=e.getFullYear(),n=wi(e);return[t-1,t].flatMap(i=>h0.map(l=>({season:l,start:f0(l,i)}))).sort((i,l)=>i.start-l.start).filter(i=>wi(i.start)<=n).pop()}function wr(e){return Xu(e).season}function ed(e){return wi(Xu(e).start)===wi(e)}const p0={winter:"❄️ The winter solstice arrives — the longest night is upon us",spring:"🌱 The spring equinox arrives — light and dark stand in balance",summer:"☀️ The summer solstice arrives — the sun holds the sky the longest",autumn:"🍂 The autumn equinox arrives — the harvest season begins"},m0=[{id:"halloween",start:[10,24],end:[10,31],headline:"🎃 Halloween week — the veil is at its thinnest"},{id:"yearend",start:[12,18],end:[12,26],headline:"🌟 The year-end wind-down — code freeze, hearts warm"},{id:"newyear",start:[12,31],end:[1,2],headline:"🎆 The year turns — the ledger resets"}];function td(e){const t=(e.getMonth()+1)*100+e.getDate();return m0.find(({start:i,end:l})=>{const a=i[0]*100+i[1],s=l[0]*100+l[1];return a<=s?t>=a&&t<=s:t>=a||t<=s})||null}function Gi(e){return ed(e)?null:td(e)}function nd(e){var t;return ed(e)?p0[wr(e)]:((t=td(e))==null?void 0:t.headline)||null}const wn={calm:{rank:0},grumpy:{rank:1,adverb:"grumpily",why:"is on track to hit its limit"},furious:{rank:2,adverb:"furiously",why:"is burning 🔥"}};function eo(e,t="calm"){var a;const n=e.id==="code"&&((a=wn[t])==null?void 0:a.adverb);if(!n)return e.label;const[i,...l]=e.label.split(" ");return[i,n,...l].join(" ")}function g0(e,t){let n={mood:"calm",account:null,meter:null,atLimit:!1};for(const[i,l]of Object.entries(e||{}))if(!(!(l!=null&&l.available)||!l.meters||Ba(l,t)))for(const[a,s]of Object.entries(l.meters)){if(!s)continue;const o=ju(s);wn[o].rank>wn[n.mood].rank&&(n={mood:o,account:i,meter:a,atLimit:(s.percent??0)>=100})}return n}function y0({mood:e,meter:t,atLimit:n},i){var s;if(!((s=wn[e])!=null&&s.why)||!t)return null;const l=i?` on account ${i}`:"",a=e==="grumpy"&&n?"has hit its limit":wn[e].why;return`${ja(t)} usage${l} ${a}`}function Wl(e){if(e===0||e===24)return"midnight";if(e===12)return"noon";const t=Math.round(e%1*60);return`${Math.floor(e)%12||12}${t?`:${String(t).padStart(2,"0")}`:""}${e<12?"am":"pm"}`}function b0(e){return Wl(dn(e))}const K=9,Ht="#d97757",we="#2b1d16",Cn=["...############..","...############..",".################","...############.."],k0=[5,12],rd=["....#.#....#.#...",".....#.#..#.#...."];function qt(e){const t=[];return e.forEach((n,i)=>{for(let l=0;lt.key!==e)}function v0(){to||(to=!0,lt(()=>{const e=hr.peek(),t=Z1({states:no,parties:e},de.value,Date.now()/1e3);no=t.states,(t.parties.length!==e.length||t.parties.some((n,i)=>n.key!==e[i].key))&&(hr.value=t.parties),t.parties.some(n=>!e.some(i=>i.key===n.key))&&pu("merged",Yu(new Date))}))}const _0="modulepreload",x0=function(e){return"/"+e},ro={},Ji=function(t,n,i){let l=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const s=document.querySelector("meta[property=csp-nonce]"),o=(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"));l=Promise.allSettled(n.map(u=>{if(u=x0(u),u in ro)return;ro[u]=!0;const c=u.endsWith(".css"),f=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${f}`))return;const d=document.createElement("link");if(d.rel=c?"stylesheet":_0,c||(d.as="script"),d.crossOrigin="",d.href=u,o&&d.setAttribute("nonce",o),document.head.appendChild(d),c)return new Promise((p,h)=>{d.addEventListener("load",p),d.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${u}`)))})}))}function a(s){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=s,window.dispatchEvent(o),!o.defaultPrevented)throw s}return l.then(s=>{for(const o of s||[])o.status==="rejected"&&a(o.reason);return t().catch(a)})};let Pr=null;function S0(){return Pr||(Pr=Ji(()=>import("./chunks/mermaid.js"),[]).then(e=>{const t=e.default;return t.initialize({startOnLoad:!1,theme:"dark",securityLevel:"strict",suppressErrorRendering:!0}),t}).catch(e=>{throw Pr=null,e})),Pr}let $0=0;function C0({code:e}){const t=ne(null),[n,i]=B(null);return j(()=>{let l=!0;return i(null),S0().then(a=>a.render(`md-mermaid-${++$0}`,e)).then(({svg:a})=>{l&&t.current&&(t.current.innerHTML=a)}).catch(a=>{l&&(t.current&&(t.current.innerHTML=""),i(String((a==null?void 0:a.message)||a)))}),()=>{l=!1}},[e]),r("div",{class:"md-mermaid",children:[r("div",{ref:t,class:"md-mermaid-svg"}),n?r("pre",{class:"md-code md-mermaid-err",children:[e,` +fable / opus 1m / sonnet — pin every spawn (New Tab, + new, spawned workers); the launcher can still override one launch`,children:[r("span",{class:"spawn-acct-label",children:"model"}),x1.map(n=>r("button",{type:"button",class:`spawn-acct-btn${e===n.id?" is-active":""}`,title:n.id==="auto"?t==null?void 0:t.reason:void 0,onClick:()=>S1(n.id),children:n.id==="auto"&&e==="auto"&&t?`auto → ${t.model??"default"}`:n.label},n.id))]})}const Lu={cols:0,rows:0,shrunkFrom:0},C1=4,T1=(e,t)=>e>0&&t>0?Math.min(e,t):e||t;function E1(e,t){return t>0&&Math.abs(e-t)<=C1?t:e}function P1(e,t,n,i){return{cols:e||n,rows:T1(t,i)}}function A1(e,t,n){return e.cols!==t.cols?e:n>0&&e.rows0&&e.rows>t.rows?{rows:Math.min(e.rows,t.shrunkFrom)}:null}function Iu(e,t){const n=e.shrunkFrom||e.rows;return{cols:t.cols??e.cols,rows:t.rows,shrunkFrom:t.rows0&&e.rows>0&&(Y.cols!==e.cols||Y.rows!==e.rows)&&Y.resize(e.cols,e.rows)}let Ye=null,et=null;function O1(){de&&de.readyState===WebSocket.OPEN&&de.send(JSON.stringify({type:"reconcile"}))}function D1(){if(!Y)return!0;const e=Y.buffer.active;return e.viewportY>=e.baseY}function Bu(e){Ye=e}let dr=null;function qs(e){dr=e}const zu=/\b(?:https?|wss?):\/\/[^\s)"'`<>]+/g,R1=new RegExp("(?=t.cols||o<0||o>=t.rows)return null;const u=t.buffer.active,c=u.getLine(u.viewportY+o);if(!c)return null;const p=c.translateToString(!0);for(const f of p.matchAll(zu)){const h=f.index,m=h+f[0].length;if(s>=h&&s{if(n.button!==0)return;const i=N1(n,e);i&&(Qt={url:i,x:n.clientX,y:n.clientY})},Ws=n=>{if(n.button!==0||!Qt)return;const i=Math.abs(n.clientX-Qt.x),l=Math.abs(n.clientY-Qt.y),{url:a}=Qt;if(Qt=null,i>4||l>4)return;Ki(a)||e.writeln(`\r +\x1B[31m[periscope: failed to open ${a}]\x1B[0m`)},t.addEventListener("mousedown",Us,!0),t.addEventListener("mouseup",Ws,!0))}function j1(e){e.registerLinkProvider({provideLinks(t,n){var s;const i=(s=e.buffer.active.getLine(t-1))==null?void 0:s.translateToString(!0);if(!i)return n(void 0);const l=[];function a(o,u){for(const c of i.matchAll(o)){const p=c[0],d=c.index+1,f=d+p.length-1;l.push({text:p,range:{start:{x:d,y:t},end:{x:f,y:t}},activate(h,m){u!=="url"&&(!h.metaKey&&!h.ctrlKey||u==="file"&&dr&&dr(m))},hover(){},leave(){}})}}a(zu,"url"),a(R1,"file"),a(F1,"file"),n(l)}})}function H1(){try{return localStorage.getItem("periscope.noWebgl")==="1"}catch{return!1}}function q1(){var t,n;if(!Mt)return;const e=(t=Mt._renderer)==null?void 0:t._gl;try{Mt.dispose()}catch{}try{(n=e==null?void 0:e.getExtension("WEBGL_lose_context"))==null||n.loseContext()}catch{}Mt=null}function Ks(e){var n;if(!((n=document.fonts)!=null&&n.load))return;const t=`${Ou.fontSize}px "${e.face}"`;Promise.all([document.fonts.load(t),document.fonts.load(`bold ${t}`)]).then(()=>{!Y||en!==e||(Y.options.fontFamily="monospace",Y.options.fontFamily=e.stack,_r())},()=>{})}function U1(){if(!Y){if(et=document.createElement("div"),et.className="xterm-host",en=or("code"),Y=new Terminal({...Ou,fontFamily:en.stack,theme:M1,linkHandler:{allowNonHttpProtocols:!0,activate(e,t){if(t.startsWith("file://")){if(!e.metaKey&&!e.ctrlKey||!dr)return;let n=t.slice(7);n.startsWith("localhost/")&&(n=n.slice(9));try{n=decodeURIComponent(n)}catch{}dr(n);return}Ki(t)}}}),Y.open(et),Ks(en),it(()=>{const e=or("code");e!==en&&(en=e,Y.options.fontFamily=e.stack,Ks(e))}),Y.attachCustomWheelEventHandler(e=>{if(!Na||!e.deltaY)return!0;const t=B1(e,Y);if(!t)return!0;e.preventDefault();let n=e.deltaY;e.deltaMode===1?n*=t.cellH:e.deltaMode===2&&(n*=t.pageH),n<0!=tn<0&&(tn=0),tn+=n;const i=t.cellH*L1;let l=Math.trunc(tn/i);if(!l)return!1;tn-=l*i,l=Math.max(-8,Math.min(8,l));const a=l<0?64:65;return de&&de.readyState===WebSocket.OPEN&&de.send(`\x1B[<${a};${t.col};${t.row}M`.repeat(Math.abs(l))),!1}),H1())console.warn("[periscope] WebGL renderer disabled via localStorage periscope.noWebgl");else try{Mt=new WebglAddon.WebglAddon,Mt.onContextLoss(()=>{q1()}),Y.loadAddon(Mt)}catch(e){console.warn("[periscope] WebGL terminal renderer unavailable; using the DOM renderer:",e)}bt=new SearchAddon.SearchAddon,Y.loadAddon(bt);try{Y.loadAddon(new Unicode11Addon.Unicode11Addon),Y.unicode.activeVersion="11"}catch(e){console.warn("[periscope] Unicode 11 widths unavailable; emoji will offset the cursor:",e)}j1(Y),z1(Y),ur=new FitAddon.FitAddon,Y.loadAddon(ur),Y.attachCustomKeyEventHandler(e=>{if(e.type!=="keydown")return!0;if(e.key==="Escape"&&e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey)return e.preventDefault(),e.stopPropagation(),de&&de.readyState===WebSocket.OPEN&&de.send("\x1B"),!1;if(e.key==="Escape"&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey)return!1;if(e.key==="Enter"&&e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey)return e.preventDefault(),de&&de.readyState===WebSocket.OPEN&&de.send("\x1B\r"),!1;if(!e.metaKey)return!0;const t=n=>{e.preventDefault(),de&&de.readyState===WebSocket.OPEN&&de.send(n)};switch(e.key){case"Backspace":return t("".repeat(200)),!1;case"Delete":return t("\v"),!1;case"ArrowLeft":return t(""),!1;case"ArrowRight":return t(""),!1;case"r":case"R":return!1;default:return!0}}),Y.onData(e=>{de&&de.readyState===WebSocket.OPEN&&de.send(e)}),Y.onBell(()=>{Ye&&(Ye.classList.add("bell-pulse"),setTimeout(()=>Ye.classList.remove("bell-pulse"),400))})}}function W1(e){ye("terminal.open",{target:e});const t=Y!==null;if(U1(),Ye&&et.parentElement!==Ye&&Ye.appendChild(et),t){try{Y.reset()}catch{}Na=!1,tn=0}if(Y.focus(),Nu(),ja(),Lt)try{Lt.disconnect()}catch{}Lt=new ResizeObserver(_r),Ye&&Lt.observe(Ye),ki=e,wi=!1,Bn=0,Vr=!1,ju(e,st.cols,st.rows)}function ju(e,t=0,n=0){let l=`${location.protocol==="https:"?"wss":"ws"}://${location.host}/ws/pane?${Ag(e)}`;t>0&&n>0&&(l+=`&cols=${t}&rows=${n}`,un=Iu(un,{cols:t,rows:n}));const a=new WebSocket(l);a.binaryType="arraybuffer",de=a,a.onopen=()=>{Bn>0&&Y&&Y.writeln(`\r +\x1B[32m[periscope: reconnected]\x1B[0m`),Bn=0,Vr=!1},a.onmessage=s=>{if(typeof s.data=="string")try{const o=JSON.parse(s.data);o.type==="size"?(za=o.cols,Vi=o.rows,ja(),_r()):o.type==="mouse"&&(Na=!!o.on)}catch{Y.write(Hs(s.data,Kl))}else Y.write(Hs(new Uint8Array(s.data),Kl))},a.onerror=()=>{},a.onclose=s=>{if(a!==de||wi||!Y||ki!==e)return;Vr||(Y.writeln(`\r +\x1B[33m[periscope: reconnecting…]\x1B[0m`),Vr=!0);const o=[250,500,1e3,2e3],u=o[Math.min(Bn,o.length-1)]||4e3;Bn+=1,At&&clearTimeout(At),At=setTimeout(()=>{At=null,!(!Y||ki!==e||wi)&&ju(e,st.cols,st.rows)},u)}}function _r(){It&&clearTimeout(It),It=setTimeout(()=>{if(It=null,!Y||!ur||Ba||!Nu())return;ja();const e=A1(st,un,Vi);e&&de&&de.readyState===WebSocket.OPEN&&(un=Iu(un,e),de.send(JSON.stringify({type:"resize",...e})))},80)}function K1(){if(wi=!0,ki=null,At&&(clearTimeout(At),At=null),un=Lu,za=0,Vi=0,It&&(clearTimeout(It),It=null),Lt){try{Lt.disconnect()}catch{}Lt=null}if(de){try{de.close()}catch{}de=null}et!=null&&et.parentElement&&et.remove()}function Vs(e){Y&&Y.writeln(e)}function vi(){if(Y)try{Y.scrollToBottom()}catch{}}function V1(){!Y||!ur||_r()}function G1(){Ba=!0}function J1(){Ba=!1,_r()}function Gs(e,t={}){return bt?bt.findNext(e,t):!1}function Js(e,t={}){return bt?bt.findPrevious(e,t):!1}function Q1(){bt&&bt.clearDecorations()}let Qn=null,Gr=null;function Y1(e,t,n={}){Hu(),Bu(e),Kl=n.agent||null,n.onPaste&&(Qn=n.onPaste,e.addEventListener("paste",Qn,!0)),Gr=e,W1(t),requestAnimationFrame(()=>requestAnimationFrame(()=>{V1(),vi()})),setTimeout(vi,300)}function Hu(){K1(),Gr&&Qn&&Gr.removeEventListener("paste",Qn,!0),Qn=null,Gr=null,Bu(null)}function qu(e){return typeof e!="string"?null:e.startsWith("pane:")?e.slice(5):null}function Z1(e,t){const n=qu(e),i=n?t==null?void 0:t[n]:null;return typeof i=="string"&&i.startsWith("file:")?"document":"terminal"}function X1(e){return(e.metaKey||e.ctrlKey)&&(e.key==="r"||e.key==="R")}function e0(e){return e.repeat||!(e.metaKey||e.ctrlKey)||e.shiftKey||e.code!=="KeyB"?null:e.altKey?"side":"rail"}function t0(e=window){e.addEventListener("keydown",t=>{const n=e0(t);if(n){t.preventDefault(),Wl(n);return}if(X1(t)){if(t.preventDefault(),t.shiftKey){location.reload();return}if(Z1(ke.value,Re.value)==="document"){ms.value=ms.value+1;return}O1()}})}function Mr(e,t){if(!t||!e)return e;const n={...e};return e.fill&&(n.fill=Rs(e.fill,t)),e.stroke&&(n.stroke=Rs(e.stroke,t)),n}const Qs=e=>e!=null&&e.stroke?{stroke:ou,"stroke-width":e["stroke-width"]}:void 0;function Oe({n:e,mood:t,asleep:n,hide:i,tint:l,rest:a,paws:s,seated:o,flush:u}){if(u&&e.mood||e.mood&&e.mood!==t||a&&e.rest||s&&e.arms||o&&e.legs&&!e.keepSeated||(n||i)&&e.role==="glint"||i&&e.role==="eye")return null;if(e.r){const[c,p,d,f]=e.r;return u?r("rect",{class:e.cls,x:c,y:p,width:N(d+.02),height:N(f+.02),...Qs(e.a)}):r("rect",{class:e.cls,x:c,y:p,width:d,height:f,...Mr(e.a,l)})}if(e.p)return u?null:r("path",{class:e.cls,d:e.p,...Mr(e.a,l)});if(u){if((n||i)&&e.shut){const[c,p,d,f]=e.shut;return r("rect",{"data-role":"shut",x:c,y:p,width:N(d+.02),height:N(f+.02)})}return r("g",{class:e.anim||e.cls,...Qs(e.a),children:e.g.map((c,p)=>r(Oe,{n:c,mood:t,asleep:n,hide:i,rest:a,paws:s,seated:o,flush:!0},p))})}if((n||i)&&e.shut){const[c,p,d,f]=e.shut;return r("rect",{"data-role":"shut",x:c,y:p,width:d,height:f,...Mr(e.g[0].a,l)})}return r("g",{class:e.anim||e.cls,"data-mood":e.mood,"data-role":e.role,...Mr(e.a,l),children:e.g.map((c,p)=>r(Oe,{n:c,mood:t,asleep:n,hide:i,tint:l,rest:a,paws:s,seated:o},p))})}function Gi({sprite:e,mood:t="calm",asleep:n=!1,face:i=null,startle:l=!1,tint:a=0,worn:s=null,holding:o=null,tip:u=null,paws:c=!1,cheer:p=!1,seated:d=!1,stride:f=!1,children:h}){const m=yg.has(i),b=u??(o&&$a[o]?qi(e,o):null),x=!!b||p&&Sg(e),w=t==="furious"&&!n,C=v=>v.role!==void 0||(v.g||[]).some(C),y=f?gg(e):e.root,g=w?e.root.filter(v=>v.mood==="furious"||C(v)):[],$=w?y.filter(v=>!g.includes(v)):y;return r("g",{class:"critter","data-face":i||void 0,"data-worn":s||void 0,"data-holding":o||void 0,children:[$.map((v,E)=>r(Oe,{n:v,mood:t,asleep:n,hide:m,tint:a,rest:x,paws:c,seated:d},E)),i&&kg(e,i).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`face-${E}`)),s&&_g(e,s).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`worn-${E}`)),l&&wg(e,!!b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`startle-${E}`)),h,b&&Hl(e,o,b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`hold-${E}`)),p&&$g(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`cheer-${E}`)),w&&r("g",{class:"tama-flush",fill:ou,opacity:"0.5",children:[y.map((v,E)=>r(Oe,{n:v,mood:t,hide:m,rest:x,paws:c,seated:d,flush:!0},E)),b&&Hl(e,o,b).map((v,E)=>r(Oe,{n:v,mood:t,flush:!0},`hold-${E}`))]}),w&&g.map((v,E)=>r(Oe,{n:v,mood:t,asleep:n,hide:m,tint:a,rest:x,paws:c,seated:d},`fu-${E}`)),w&&Tg(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`teeth-${E}`))]},w?"furious":"calm")}function n0(e){return e==null?"":e>=80?" ctx-hot":e>=60?" ctx-warn":""}function Vl(e){return e.ctx_class&&e.ctx_class!=="none"?` ctx-${e.ctx_class}`:n0(e.context_pct)}const Ys=["bell","api","done","merged","ctx","ci","update"],Uu=600;function Zs(e,t){const n=Math.floor((t-e)/60);return n<1?"":n<60?` (${n} min)`:` (${Math.floor(n/60)}h ${n%60}m)`}const In=(e,t,n={})=>({action:e,pid:t.pid,says:`open ${_e(t)}`,...n});function r0({windows:e=[],alerts:t=[],dismissedAlertIds:n=new Set,dismissedNeedsPids:i=new Set,dismissedReadyPids:l=new Set,selectedPid:a=null,parties:s=[],update:o=null,nowSec:u}){const c=[],p=g=>!g||a==null||String(g.pid)!==String(a),d=e.filter(p),f=new Map(e.map(g=>[String(g.pid),g])),h=xu(e,t,n,i,u,p);if(h.size){const g=[...h.values()].reduce((E,M)=>M.sinceg.api_error);m.length&&c.push({kind:"api",count:m.length,label:"API",phrase:`the Anthropic API is erroring in ${wn(m.length,"pane")}, not your code`,target:In("select",m[0])});const b=new Map;for(const g of e){if(g.ci!=="✗"||!g.pr||g.pr_state&&g.pr_state!=="open")continue;const $=`${g.repo_slug||g.repo_key||""}#${g.pr}`;b.has($)||b.set($,{pr:g.pr,panes:[]}),b.get($).panes.push(g)}const x=[...b.values()].filter(g=>g.panes.every(p));x.length&&c.push({kind:"ci",count:x.length,label:String(x.length),phrase:x.length===1?`PR #${x[0].pr} is failing CI`:`${x.length} PRs failing CI`,target:In("select",x[0].panes[0])});const w=wu(e,t,n,l).filter(g=>p(g.w));if(w.length){const g=w[0],$=g.w?_e(g.w):g.name||"a pane";c.push({kind:"done",count:w.length,label:String(w.length),phrase:w.length===1?`${$} finished`:`${w.length} panes finished`,target:g.kind==="live"?In("ready",g.w):{action:"reveal",target:g.target,says:`open ${$}`}})}const C=s.filter(g=>u-g.atVl(g)===" ctx-hot");if(y.length){const g=y.filter(M=>(M.context_pct??0)>=80),$=g.length?g.reduce((M,T)=>T.context_pct>M.context_pct?T:M):y[0],v=g.length?Math.round($.context_pct):null,E=y.length>1?`${y.length} panes worth compacting`:v!=null?`${_e($)} is running out of context (${v}%)`:`${_e($)} is costly to keep carrying${$.ctx_hint?`: ${$.ctx_hint}`:""}`;c.push({kind:"ctx",count:y.length,label:v!=null?`${v}%`:String(y.length),pct:v,cost:v==null,phrase:E,target:In("select",$)})}return(o==null?void 0:o.behind)>0&&!o.running&&c.push({kind:"update",count:1,label:"new",phrase:`periscope ${o.target} is out`,target:{action:"update",says:"see the update"}}),c.sort((g,$)=>Ys.indexOf(g.kind)-Ys.indexOf($.kind))}function i0(e){return e.slice(1).reduce((t,n)=>t+n.count,0)}const l0=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function a0(e,t){if(!e)return{day:null,time:"later"};const n=new Date(e*1e3),i=n.getHours(),l=n.getMinutes(),a=`${i%12||12}${l?`:${String(l).padStart(2,"0")}`:""}${i<12?"am":"pm"}`;return{day:e-t>20*3600?l0[n.getDay()]:null,time:a}}function s0({day:e,time:t}){return`every account is at its limit until ${e?`${e} `:""}${t}`}const o0=new Set(["done","merged","ci","api","ctx"]);function Wu(e,t){const n=e==="code";return{atDesk:n,moodShown:n&&!t,showsPanes:n&&!o0.has(t)}}function c0({states:e,parties:t},n,i){const l={...e},a=t.filter(s=>i-s.atc.key===u)&&a.push({key:u,pid:s.pid,pr:s.pr,at:i})}return{states:l,parties:a}}const u0=600;function Ha(e,t){return!!(e!=null&&e.fetched_at)&&t-e.fetched_at>u0}function qa(e){const t=[e==null?void 0:e.projected_percent,e==null?void 0:e.projected_recent].filter(i=>i!=null);if(!t.length)return!1;const n=Math.max(...t);return n>(e.percent??0)&&n>=100}function Ku(e){return e!=null&&e.hot?"furious":qa(e)?"grumpy":"calm"}const d0={session:"session",week_all:"week",week_opus:"opus",week_sonnet:"sonnet"};function Ua(e){return d0[e]||e.replace(/^week_/,"")}const Vu=[{from:0,to:7,id:"sleep",label:"sleeping"},{from:7,to:9,id:"coffee",label:"having coffee"},{from:9,to:10,id:"code",label:"coding with a coffee",coffee:!0},{from:10,to:12,id:"code",label:"coding"},{from:12,to:13,id:"eat",meal:"lunch"},{from:13,to:17,id:"code",label:"coding"},{from:17,to:18,pastime:!0},{from:18,to:19,id:"eat",meal:"dinner"},{from:19,to:21,id:"read",label:"reading"},{from:21,to:24,id:"sleep",label:"sleeping"}],Gu=[{from:0,to:9,id:"sleep",label:"sleeping"},{from:9,to:11,id:"eat",meal:"brunch"},{from:11,to:18,pastime:!0},{from:18,to:19,id:"eat",meal:"dinner"},{from:19,to:21,id:"read",label:"reading"},{from:21,to:24,id:"sleep",label:"sleeping"}],dn=17,Xs=16,Be=.5,Wa=Vu.map(e=>{const t=e.id==="code"?{...e,id:"nap",label:"napping at the desk"}:e;return t.to===dn?{...t,to:Xs}:t.from===dn?{...t,from:Xs}:t}),Ju=e=>e.getDay()===0||e.getDay()===6,Ji=(e,t)=>e.find(n=>t>=n.from&&tJi(Ju(e)?Gu:Wa,dn),eo=[{id:"run",label:"out for a run"},{id:"cycle",label:"out cycling",seasons:["spring","summer","autumn"]},{id:"music",label:"practicing bass"},{id:"beer",label:"having a beer with friends"},{id:"kids",label:"spending time with the kids"},{id:"game",label:"playing video games"},{id:"garden",label:"gardening",seasons:["spring","summer"]},{id:"cook",label:"cooking"},{id:"dog",label:"walking the dog"},{id:"swim",label:"out for a swim",seasons:["summer"]},{id:"sled",label:"out sledding",seasons:["winter"]}],f0={run:"trick-or-treating",kids:"trick-or-treating with the kids"},p0=[{id:"ramen",label:"ramen"},{id:"pizza",label:"pizza"},{id:"burger",label:"a burger"},{id:"sushi",label:"sushi"},{id:"tacos",label:"tacos"},{id:"pasta",label:"pasta"},{id:"salad",label:"a salad"},{id:"soup",label:"soup",seasons:["winter"]}],m0=[{id:"pancakes",label:"pancakes"},{id:"waffles",label:"waffles"},{id:"eggs",label:"eggs and bacon"}],g0={id:"roast",label:"a roast"},to={halloween:{id:"pie",label:"pumpkin pie"},summer:{id:"icecream",label:"ice cream"}},Qu=e=>t=>!t.seasons||t.seasons.includes(xr(e)),hn=e=>e.getHours()+e.getMinutes()/60;function Yu(e,t){let n=2166136261;for(const i of`${Qi(e)}|${t}`)n=Math.imul(n^i.charCodeAt(0),16777619);return n=Math.imul(n^n>>>16,2246822507),n=Math.imul(n^n>>>13,3266489909),(n^n>>>16)>>>0}function Jr(e,t,n,i=[]){let l=Yu(t,n)%e.length;for(;i.includes(e[l].id);)l=(l+1)%e.length;return e[l]}const y0=e=>Math.floor(e/6e4)*6e4,Ka=e=>(e.walls||[]).map(t=>t.map(y0)).filter(([t,n])=>tKa(t).some(([n,i])=>n<=e.getTime()&&e.getTime()Ka(e).map(t=>t.map(b0)).filter(([t,n])=>ti<=n&&n({...e,label:`having ${t.label} for ${n}`,dish:t.id});function k0(e,t){var u;if(e.meal==="brunch")return pl(e,Jr(m0,t,"brunch"),"brunch");const n=(u=Yi(t))==null?void 0:u.id,i=e.meal==="dinner"&&(to[n]||to[xr(t)]),l=e.from+Be;if(i&&hn(t)>=l)return{...pl(e,i,"dessert"),from:l};const a=p0.filter(Qu(t)),s=Jr(a,t,"lunch"),o=e.meal==="lunch"?s:n==="yearend"?g0:Jr(a,t,"dinner",[s.id]);return{...pl(e,o,e.meal),...i?{to:l}:{}}}function w0(e,t,n){var f;const i=h=>eo.find(m=>m.id===h),l=(e.to-e.from)/Be,a=h=>(h-e.from)/Be,s=h=>e.from+h*Be,o=[dn,dn+Be].map(a),u=h=>!!Ji(ed(hr(t,s(h)),n),s(h)).pastime,c=[],p=eo.filter(Qu(t)),d=()=>{var m,b;const h=[];for(let x=0;x{const x=(h+b)%2?"kids":"run";c[m]={...i(x),label:f0[x],trick:!0}})}else{t.getDay()===5&&(c[a(dn+Be)]=i("beer"));const h=[["furious","run"],["merged","beer"]].filter(([m])=>n[m]!=null).sort(([m],[b])=>n[m]-n[b]);for(const[m,b]of h){if(o.some(C=>{var y;return((y=c[C])==null?void 0:y.id)===b}))continue;const x=Math.floor(a(n[m]));if(x>=o[0]-1&&x!c[C]&&C>x);w!==void 0&&(c[w]=i(b))}}return d()}function fr(e,t={}){const n=Ji(ed(e,t),e.getHours());if(n.meal)return k0(n,e);if(n.pastime){const o=h0(e),u=Math.floor((hn(e)-o.from)/Be),c=o.from+u*Be;return{...o,...w0(o,e,t)[u],from:c,to:c+Be}}if(n.id!=="code"&&n.id!=="nap")return n;const i=e.getTime(),l=Xu(t).flat(),a=Math.max(hr(e,n.from).getTime(),...l.filter(o=>o<=i)),s=Math.min(hr(e,n.to).getTime(),...l.filter(o=>o>i));return{...n,from:hn(new Date(a)),to:hn(new Date(s))}}function td(e,t={}){const n=e.getTime(),{to:i}=fr(e,t);return Math.min(hr(e,i).getTime(),...Ka(t).flat().filter(l=>l>n))-n}function v0(e,t={}){const n=fr(e,t);let i=e;for(let l=0;l<8;l++){i=new Date(i.getTime()+td(i,t));const a=fr(i,t);if(a.id!==n.id||a.dish!==n.dish)return{at:i,activity:a}}return null}function no(e,t={}){var i;const n=fr(e,t);return`${n.from}|${n.id}|${n.dish||""}|${xr(e)}|${((i=Yi(e))==null?void 0:i.id)||""}|${sd(e)||""}|${Zu(e,t)}`}const _i=e=>String(e).padStart(2,"0");function Qi(e){return`${e.getFullYear()}-${_i(e.getMonth()+1)}-${_i(e.getDate())}`}function nd(e){return`${Qi(e)}T${_i(e.getHours())}:${_i(e.getMinutes())}`}function rd(e,t){const n=Qi(t),i=l=>{const a=/^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2})$/.exec(l||"");return(a==null?void 0:a[1])===n?Number(a[2])+Number(a[3])/60:null};return{merged:i(e==null?void 0:e.merged),furious:i(e==null?void 0:e.furious)}}const _0={spring:[245162380984e-5,365242.37404,.05169,-.00411,-57e-5],summer:[245171656767e-5,365241.62603,.00325,.00888,-3e-4],autumn:[245181021715e-5,365242.01767,-.11575,.00337,78e-5],winter:[245190005952e-5,365242.74049,-.06223,-.00823,32e-5]},x0=["spring","summer","autumn","winter"];function S0(e,t){const[n,i,l,a,s]=_0[e],o=(t-2e3)/1e3,u=n+i*o+l*o**2+a*o**3+s*o**4;return new Date((u-24405875e-1)*864e5)}const xi=e=>e.getFullYear()*1e4+(e.getMonth()+1)*100+e.getDate();function id(e){const t=e.getFullYear(),n=xi(e);return[t-1,t].flatMap(i=>x0.map(l=>({season:l,start:S0(l,i)}))).sort((i,l)=>i.start-l.start).filter(i=>xi(i.start)<=n).pop()}function xr(e){return id(e).season}function ld(e){return xi(id(e).start)===xi(e)}const $0={winter:"❄️ The winter solstice arrives — the longest night is upon us",spring:"🌱 The spring equinox arrives — light and dark stand in balance",summer:"☀️ The summer solstice arrives — the sun holds the sky the longest",autumn:"🍂 The autumn equinox arrives — the harvest season begins"},C0=[{id:"halloween",start:[10,24],end:[10,31],headline:"🎃 Halloween week — the veil is at its thinnest"},{id:"yearend",start:[12,18],end:[12,26],headline:"🌟 The year-end wind-down — code freeze, hearts warm"},{id:"newyear",start:[12,31],end:[1,2],headline:"🎆 The year turns — the ledger resets"}];function ad(e){const t=(e.getMonth()+1)*100+e.getDate();return C0.find(({start:i,end:l})=>{const a=i[0]*100+i[1],s=l[0]*100+l[1];return a<=s?t>=a&&t<=s:t>=a||t<=s})||null}function Yi(e){return ld(e)?null:ad(e)}function sd(e){var t;return ld(e)?$0[xr(e)]:((t=ad(e))==null?void 0:t.headline)||null}const vn={calm:{rank:0},grumpy:{rank:1,adverb:"grumpily",why:"is on track to hit its limit"},furious:{rank:2,adverb:"furiously",why:"is burning 🔥"}};function ro(e,t="calm"){var a;const n=e.id==="code"&&((a=vn[t])==null?void 0:a.adverb);if(!n)return e.label;const[i,...l]=e.label.split(" ");return[i,n,...l].join(" ")}function T0(e,t){let n={mood:"calm",account:null,meter:null,atLimit:!1};for(const[i,l]of Object.entries(e||{}))if(!(!(l!=null&&l.available)||!l.meters||Ha(l,t)))for(const[a,s]of Object.entries(l.meters)){if(!s)continue;const o=Ku(s);vn[o].rank>vn[n.mood].rank&&(n={mood:o,account:i,meter:a,atLimit:(s.percent??0)>=100})}return n}function E0({mood:e,meter:t,atLimit:n},i){var s;if(!((s=vn[e])!=null&&s.why)||!t)return null;const l=i?` on account ${i}`:"",a=e==="grumpy"&&n?"has hit its limit":vn[e].why;return`${Ua(t)} usage${l} ${a}`}function Gl(e){if(e===0||e===24)return"midnight";if(e===12)return"noon";const t=Math.round(e%1*60);return`${Math.floor(e)%12||12}${t?`:${String(t).padStart(2,"0")}`:""}${e<12?"am":"pm"}`}function P0(e){return Gl(hn(e))}const V=9,Ht="#d97757",we="#2b1d16",Tn=["...############..","...############..",".################","...############.."],A0=[5,12],od=["....#.#....#.#...",".....#.#..#.#...."];function qt(e){const t=[];return e.forEach((n,i)=>{for(let l=0;lt.key!==e)}function L0(){io||(io=!0,it(()=>{const e=pr.peek(),t=c0({states:lo,parties:e},ce.value,Date.now()/1e3);lo=t.states,(t.parties.length!==e.length||t.parties.some((n,i)=>n.key!==e[i].key))&&(pr.value=t.parties),t.parties.some(n=>!e.some(i=>i.key===n.key))&&bu("merged",nd(new Date))}))}const I0="modulepreload",O0=function(e){return"/"+e},ao={},Zi=function(t,n,i){let l=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const s=document.querySelector("meta[property=csp-nonce]"),o=(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"));l=Promise.allSettled(n.map(u=>{if(u=O0(u),u in ao)return;ao[u]=!0;const c=u.endsWith(".css"),p=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${p}`))return;const d=document.createElement("link");if(d.rel=c?"stylesheet":I0,c||(d.as="script"),d.crossOrigin="",d.href=u,o&&d.setAttribute("nonce",o),document.head.appendChild(d),c)return new Promise((f,h)=>{d.addEventListener("load",f),d.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${u}`)))})}))}function a(s){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=s,window.dispatchEvent(o),!o.defaultPrevented)throw s}return l.then(s=>{for(const o of s||[])o.status==="rejected"&&a(o.reason);return t().catch(a)})};let Lr=null;function D0(){return Lr||(Lr=Zi(()=>import("./chunks/mermaid.js"),[]).then(e=>{const t=e.default;return t.initialize({startOnLoad:!1,theme:"dark",securityLevel:"strict",suppressErrorRendering:!0}),t}).catch(e=>{throw Lr=null,e})),Lr}let R0=0;function F0({code:e}){const t=te(null),[n,i]=B(null);return j(()=>{let l=!0;return i(null),D0().then(a=>a.render(`md-mermaid-${++R0}`,e)).then(({svg:a})=>{l&&t.current&&(t.current.innerHTML=a)}).catch(a=>{l&&(t.current&&(t.current.innerHTML=""),i(String((a==null?void 0:a.message)||a)))}),()=>{l=!1}},[e]),r("div",{class:"md-mermaid",children:[r("div",{ref:t,class:"md-mermaid-svg"}),n?r("pre",{class:"md-code md-mermaid-err",children:[e,` -`,n]}):null]})}const id=/^([a-z][a-z0-9+.-]*:|\/|#)/i;function io(e,t){return!t.resolveUrl||id.test(e)?e:t.resolveUrl(e)}function ze(e,t){return(e||[]).map((n,i)=>T0(n,t,i))}function T0(e,t,n){switch(e.type){case"text":{const i=t.softBreaks==="br"&&e.value.includes(` +`,n]}):null]})}const cd=/^([a-z][a-z0-9+.-]*:|\/|#)/i;function so(e,t){return!t.resolveUrl||cd.test(e)?e:t.resolveUrl(e)}function ze(e,t){return(e||[]).map((n,i)=>N0(n,t,i))}function N0(e,t,n){switch(e.type){case"text":{const i=t.softBreaks==="br"&&e.value.includes(` `)?e.value.split(` -`):[e.value],l=[];return i.forEach((a,s)=>{if(s&&l.push(r("br",{},`${n}b${s}`)),!t.cite){l.push(a);return}Qm(a).forEach((o,u)=>{if(typeof o=="string"){l.push(o);return}const c=t.cite(o);l.push(c==null?o.raw:r("span",{children:c},`${n}c${s}-${u}`))})}),l.length===1?l[0]:l}case"inlineCode":{const i=t.cite?Ni(e.value):null,l=i?t.cite(i):null;return l!=null?r("span",{children:l},n):r("code",{class:"md-icode",children:e.value},n)}case"strong":return r("strong",{children:ze(e.children,t)},n);case"emphasis":return r("em",{children:ze(e.children,t)},n);case"delete":return r("del",{children:ze(e.children,t)},n);case"link":return r("a",{class:"md-link",href:io(e.url,t),target:"_blank",rel:"noopener",children:ze(e.children,{...t,cite:null})},n);case"image":return!id.test(e.url)&&!t.resolveUrl?e.alt||e.url:r("img",{class:"md-img",src:io(e.url,t),alt:e.alt||""},n);case"break":return r("br",{},n);case"html":return e.value;case"footnoteReference":return r("sup",{children:["[",e.label||e.identifier,"]"]},n);default:return e.children?ze(e.children,t):e.value??null}}function E0(e,t,n){const i=(e.children||[]).map((l,a)=>l.type==="paragraph"&&!e.spread?ze(l.children,t):Ua(l,t,a));return e.checked==null?r("li",{children:i},n):r("li",{class:"md-task",children:[r("input",{type:"checkbox",checked:e.checked,disabled:!0})," ",i]},n)}function P0(e,t,n){const i=e.align||[],[l,...a]=e.children,s=l.children.length,o=c=>i[c]?`text-align:${i[c]}`:void 0,u=c=>Array.from({length:s},(f,d)=>c.children[d]??null);return r("table",{class:"md-table",children:[r("thead",{children:r("tr",{children:u(l).map((c,f)=>r("th",{style:o(f),children:c?ze(c.children,t):""},f))})}),r("tbody",{children:a.map((c,f)=>r("tr",{children:u(c).map((d,p)=>r("td",{style:o(p),children:d?ze(d.children,t):""},p))},f))})]},n)}function Ua(e,t,n,i){switch(e.type){case"paragraph":return r("p",{class:"md-p",children:ze(e.children,t)},n);case"heading":{const a=`h${t.demote?Math.min(e.depth+2,6):e.depth}`;return r(a,{class:`md-h md-h${e.depth}`,children:ze(e.children,t)},n)}case"code":return t.mermaid&&e.lang==="mermaid"?r(C0,{code:e.value},n):r("pre",{class:"md-code",children:r("code",{children:t.highlight&&e.lang?t.highlight(e.value,e.lang):e.value})},n);case"blockquote":{const l=t.meta&&(i==null?void 0:i.type)==="heading"?Nl(e,t.src):null;return l?r("div",{class:"md-meta",children:l.map(([a,s],o)=>r("span",{class:"md-meta-kv","data-key":a,children:[r("span",{class:"md-meta-k",children:a}),r("span",{class:"md-meta-v",children:a==="refs"&&t.cite?tu(s).map((u,c)=>{const f=Ni(u),d=f?t.cite(f):null;return r("span",{children:[c?", ":"",d??u]},c)}):s})]},o))},n):r("blockquote",{class:"md-quote",children:(e.children||[]).map((a,s)=>Ua(a,t,s))},n)}case"list":{const l=(e.children||[]).map((a,s)=>E0(a,t,s));return e.ordered?r("ol",{class:"md-ol",start:e.start!==1?e.start:void 0,children:l},n):r("ul",{class:"md-ul",children:l},n)}case"thematicBreak":return r("hr",{class:"md-hr"},n);case"table":return P0(e,t,n);case"html":return r("p",{class:"md-p",children:e.value},n);default:return e.children?r("p",{class:"md-p",children:ze(e.children,t)},n):e.value?r("p",{class:"md-p",children:e.value},n):null}}function fr(e,t={}){const n=String(e||""),i={src:n,demote:t.demote??!0,softBreaks:t.softBreaks??"br",highlight:t.highlight??null,resolveUrl:t.resolveUrl??null,meta:t.meta??!1,cite:t.cite??null,mermaid:t.mermaid??!1},l=jc(n,{extensions:[eu()],mdastExtensions:[Wc()]});return l.children.map((a,s)=>Ua(a,i,s,l.children[s-1]))}const A0=2e3,Vr=H(!1);let Kl=!1;function M0({focus:e=!1}={}){Kl=e,Vr.value=!0}const L0=12e4;function I0({releases:e}){return e?e==="error"?r("div",{class:"update-note-muted",children:"couldn't load the release notes"}):e.length?e.map(t=>r("div",{class:"update-release",children:[r("div",{class:"update-release-head",children:t.heading}),r("div",{class:"update-release-body",children:fr(t.body)})]},t.heading)):r("div",{class:"update-note-muted",children:"no release notes recorded — CHANGELOG.md was unreadable on the last check"}):r("div",{class:"update-note-muted",children:"loading…"})}function O0(){const[e,t]=B(!1),[n,i]=B(null),l=Vr.value,a=A=>{Vr.value=A},[s,o]=B(null),u=ne(null),c=ne(null),f=Pi(()=>{Vr.value=!1},[]);He(f,l),j(()=>{if(!l)return;function A(T){u.current&&!u.current.contains(T.target)&&a(!1)}return document.addEventListener("click",A),()=>document.removeEventListener("click",A)},[l]);const d=ha.value,p=(d==null?void 0:d.behind)||0,h=(d==null?void 0:d.ahead)||0;if(j(()=>{p||a(!1)},[p]),j(()=>{var T;if(!l)return;let A=!0;return o(null),Kl&&(Kl=!1,(T=c.current)==null||T.focus()),fetch("/api/update/status").then(async S=>{A&&o(S.ok?(await S.json()).releases||[]:"error")}).catch(()=>{A&&o("error")}),()=>{A=!1}},[l]),!d||!p&&!d.running&&!e&&!n)return null;function m(){a(!l)}async function b(){const A=Date.now()+L0;for(;Date.now()setTimeout(S,A0));let T;try{const S=await fetch("/api/update/status");if(!S.ok)continue;T=await S.json()}catch{continue}if(!T.running)return T.behind===0?t(!1):(t(!1),i((T.log||[]).filter(Boolean).slice(-3).join(` -`)||"update exited without applying — see ~/.config/periscope/update.log"))}t(!1),i("no response for 2 minutes — periscope may not have come back up.\ncheck `bin/periscope status` and ~/.config/periscope/update.log")}async function x(){if(a(!1),i(null),t(!0),!await ie("update","/api/update",{method:"POST"}))return t(!1);b()}const w=e||d.running,C=d.behind,y=d.target,g=`${y} is out — ${kn(C,"commit")} newer than this checkout`,$=C>0&&h>0,v=`${kn(h,"local commit")} not in ${y} — the update's fast-forward will refuse. Get them into a release, or off this checkout's main.`,E=n?`update failed: -${n}`:w?"updating — periscope will restart itself":$?`${g}, but ${v}`:`${g} — click to see what's new`;return r("div",{class:"update-dd",ref:u,children:[r("button",{type:"button",class:`update-pill${w?" is-running":""}${n?" is-error":""}`,title:E,"aria-haspopup":"dialog","aria-expanded":l?"true":"false",disabled:w,onClick:w?void 0:m,children:w?"updating…":n?"⚠ update failed":`↑ ${y}${$?" ⚠":""}`}),r("div",{class:"tb-dd-menu update-menu",role:"dialog",hidden:!l,children:[r("div",{class:"update-menu-head",children:g}),$&&r("div",{class:"update-menu-warn",children:v}),n&&r("pre",{class:"update-menu-error",children:n}),r("div",{class:"update-notes",children:r(I0,{releases:s})}),r("button",{type:"button",class:"update-pill update-menu-go",ref:c,onClick:x,children:[n?"retry — ":"","pull, re-provision and restart"]})]})]})}function D0(e){const t=e.pid!=null&&(de.value||[]).find(n=>String(n.pid)===String(e.pid))||null;if(e.action==="update")return M0({focus:!0});if(e.action==="needs")return vu(t);if(e.action==="ready")return xu(t);if(e.action==="reveal")return jt(e.target);e.action==="party"&&w0(e.key),yt(t)}const R0=250;function F0({target:e,pet:t,act:n=D0,schedule:i=setTimeout,cancel:l=clearTimeout}){let a=null;return{onClick(s){if(s.detail>1)return;const o=e();if(!o)return t();if(o.action==="update"){a=i(()=>n(o),R0);return}n(o)},onDblClick(){l(a),t()},dispose(){l(a)}}}const N0="geometricPrecision";function nn({x:e,y:t}){return r("g",{fill:"var(--fg-3)",children:[r("rect",{class:"tama-steam",x:e,y:t,width:"0.5",height:"1.6"}),r("rect",{class:"tama-steam tama-steam2",x:e+1.2,y:t-.6,width:"0.5",height:"1.6"})]})}function Ar({y:e=18.2}){return r("rect",{x:"25.8",y:e,width:"7.6",height:"0.8",rx:"0.4",fill:"#e8e2d4"})}const lo={ramen:()=>r("g",{children:[r("line",{x1:"29.2",y1:"10.4",x2:"28.1",y2:"15.6",stroke:"#b07a4f","stroke-width":"0.45"}),r("line",{x1:"30.4",y1:"10.7",x2:"29",y2:"15.6",stroke:"#b07a4f","stroke-width":"0.45"}),r("rect",{x:"26.8",y:"15.3",width:"4.9",height:"1.5",rx:"0.7",fill:"#f8f4ea"}),r("rect",{x:"26",y:"16.2",width:"6.5",height:"2.8",rx:"1.2",fill:"#e8e2d4"}),r("rect",{class:"tama-steam",x:"31.6",y:"12.2",width:"0.5",height:"1.6",fill:"var(--fg-3)"})]}),pizza:()=>r("g",{children:[r("rect",{x:"26",y:"12",width:"7.4",height:"5.4",fill:"#d8b384"}),r("rect",{x:"26.5",y:"12.5",width:"6.4",height:"4.4",fill:"#c9a06b"}),r("rect",{x:"25.6",y:"17.2",width:"8.2",height:"1.8",fill:"#c49a6c"}),r("ellipse",{cx:"29.7",cy:"17.3",rx:"3.6",ry:"1.1",fill:"#e0a94a"}),r("ellipse",{cx:"29.7",cy:"17.3",rx:"3",ry:"0.8",fill:"#f2c94c"}),r("path",{d:"M29.7 17.3 L33.4 17.1 L32.6 18.2 Z",fill:"#c49a6c"}),r("g",{fill:"#c0392b",children:[r("circle",{cx:"28",cy:"17.2",r:"0.35"}),r("circle",{cx:"29.6",cy:"16.9",r:"0.35"}),r("circle",{cx:"29.2",cy:"17.7",r:"0.35"}),r("circle",{cx:"31",cy:"16.9",r:"0.3"})]}),r(nn,{x:28.6,y:13.6})]}),burger:()=>r("g",{children:[r(Ar,{}),r("rect",{x:"27",y:"17.2",width:"5",height:"1",rx:"0.4",fill:"#d9913f"}),r("rect",{x:"26.8",y:"16.2",width:"5.4",height:"1.1",rx:"0.5",fill:"#6b3a22"}),r("path",{d:"M26.9 15.8 H32.1 V16.3 H29.2 L28.6 17 L28 16.3 H26.9 Z",fill:"#f2c94c"}),r("rect",{x:"27.1",y:"15.3",width:"4.8",height:"0.5",fill:"#e05252"}),r("rect",{x:"26.7",y:"14.9",width:"5.6",height:"0.5",rx:"0.25",fill:"#6fae5a"}),r("path",{d:"M26.9 15 Q26.9 12.4 29.5 12.4 Q32.1 12.4 32.1 15 Z",fill:"#e0a04a"}),r("g",{fill:"#f8f0d8",children:[r("rect",{x:"28.2",y:"13.4",width:"0.4",height:"0.25"}),r("rect",{x:"29.6",y:"13",width:"0.4",height:"0.25"}),r("rect",{x:"30.8",y:"13.6",width:"0.4",height:"0.25"})]})]}),sushi:()=>r("g",{children:[r("rect",{x:"25.4",y:"17.4",width:"8.4",height:"0.9",fill:"#c8955c"}),r("g",{fill:"#a5743f",children:[r("rect",{x:"26.2",y:"18.3",width:"0.8",height:"0.7"}),r("rect",{x:"32.2",y:"18.3",width:"0.8",height:"0.7"})]}),[[26,"#f28c6b"],[28.7,"#d64550"]].map(([e,t])=>r("g",{children:[r("rect",{x:e,y:"16.2",width:"2.4",height:"1.2",rx:"0.5",fill:"#f6f3ec"}),r("rect",{x:e-.2,y:"15.5",width:"2.8",height:"0.9",rx:"0.45",fill:t}),r("rect",{x:e+.7,y:"15.6",width:"0.15",height:"0.7",fill:"#fbd0c0",opacity:"0.8"}),r("rect",{x:e+1.5,y:"15.6",width:"0.15",height:"0.7",fill:"#fbd0c0",opacity:"0.8"})]},e)),r("rect",{x:"31.4",y:"15.6",width:"1.9",height:"1.8",rx:"0.3",fill:"#1f2a1f"}),r("rect",{x:"31.7",y:"15.9",width:"1.3",height:"1.2",fill:"#f6f3ec"}),r("rect",{x:"32.1",y:"16.25",width:"0.5",height:"0.5",fill:"#f28c6b"})]}),tacos:()=>r("g",{children:[r(Ar,{}),[26,29.8].map(e=>r("g",{children:[r("rect",{x:e+.2,y:"14.6",width:"3.2",height:"0.9",rx:"0.4",fill:"#6fae5a"}),r("rect",{x:e+.3,y:"15.2",width:"3",height:"0.5",fill:"#8a4b2a"}),r("rect",{x:e+.7,y:"14.4",width:"0.6",height:"0.6",fill:"#e05252"}),r("rect",{x:e+2.3,y:"14.3",width:"0.6",height:"0.6",fill:"#e05252"}),r("path",{d:`M${e} 15.4 h3.6 a1.8 2.6 0 0 1 -3.6 0 z`,fill:"#e8b84a"})]},e))]}),pasta:()=>r("g",{children:[r("line",{x1:"31.4",y1:"15.6",x2:"33",y2:"11.8",stroke:"#c9ced6","stroke-width":"0.35"}),r("rect",{x:"25.8",y:"17.6",width:"7.6",height:"1.2",rx:"0.6",fill:"#f8f4ea"}),r("rect",{x:"26.6",y:"18.4",width:"6",height:"0.6",fill:"#e8e2d4"}),r("path",{d:"M26.6 17.8 Q27 14.6 29.6 14.6 Q32.2 14.6 32.6 17.8 Z",fill:"#f2d27a"}),r("g",{fill:"none",stroke:"#d9b45a","stroke-width":"0.25",children:[r("path",{d:"M27.4 17.1 q0.6 -0.7 1.2 0 t1.2 0 t1.2 0 t1.2 0"}),r("path",{d:"M27.9 16.2 q0.6 -0.7 1.2 0 t1.2 0 t1.2 0"})]}),r("path",{d:"M28 15.4 Q29.6 14 31.2 15.4 Q29.6 16.2 28 15.4 Z",fill:"#c0392b"}),r("circle",{cx:"28.9",cy:"15",r:"0.55",fill:"#6b3a22"}),r("circle",{cx:"30.3",cy:"14.9",r:"0.55",fill:"#6b3a22"}),r(nn,{x:27.6,y:11.6})]}),salad:()=>r("g",{children:[r("line",{x1:"31.8",y1:"15.8",x2:"33.2",y2:"11.8",stroke:"#c9ced6","stroke-width":"0.35"}),r("ellipse",{cx:"27.8",cy:"15.6",rx:"1.4",ry:"1",fill:"#4f9a46"}),r("ellipse",{cx:"29.6",cy:"15.1",rx:"1.5",ry:"1.1",fill:"#6fae5a"}),r("ellipse",{cx:"31.4",cy:"15.6",rx:"1.3",ry:"0.9",fill:"#9be38f"}),r("circle",{cx:"28.6",cy:"15.2",r:"0.45",fill:"#e05252"}),r("circle",{cx:"30.9",cy:"15.4",r:"0.45",fill:"#e05252"}),r("rect",{x:"29.4",y:"14.3",width:"0.4",height:"1.2",fill:"#ef8a2c"}),r("path",{d:"M26 16 h7.2 q-0.4 3 -3.6 3 q-3.2 0 -3.6 -3 z",fill:"#b07a4f"}),r("rect",{x:"25.8",y:"15.8",width:"7.6",height:"0.5",rx:"0.25",fill:"#9a6a43"})]}),soup:()=>r("g",{children:[r("line",{x1:"31.4",y1:"15.8",x2:"33.4",y2:"12.4",stroke:"#c9ced6","stroke-width":"0.35"}),r("path",{d:"M26 15.6 h7 q-0.4 3.4 -3.5 3.4 q-3.1 0 -3.5 -3.4 z",fill:"#e8e2d4"}),r("ellipse",{cx:"29.5",cy:"15.7",rx:"3.4",ry:"0.55",fill:"#d9622b"}),r("g",{fill:"#e8b84a",children:[r("rect",{x:"28",y:"15.4",width:"0.6",height:"0.4"}),r("rect",{x:"30.2",y:"15.6",width:"0.6",height:"0.4"})]}),r("rect",{x:"25.6",y:"18.4",width:"7.8",height:"0.6",rx:"0.3",fill:"#d4ccbd"}),r(nn,{x:28.2,y:12.4})]}),roast:()=>r("g",{children:[r("ellipse",{cx:"29.6",cy:"18.4",rx:"4.1",ry:"0.7",fill:"#e8e2d4"}),r("g",{fill:"#4f9a46",children:[r("circle",{cx:"26",cy:"18.1",r:"0.4"}),r("circle",{cx:"33.2",cy:"18.1",r:"0.4"})]}),r("path",{d:"M26.6 18.2 Q26.4 14.6 29.6 14.4 Q32.8 14.6 32.6 18.2 Z",fill:"#b5733a"}),r("ellipse",{cx:"29",cy:"15.6",rx:"1.6",ry:"0.7",fill:"#d9913f"}),[[26.9,25.9],[32.3,33.3]].map(([e,t])=>r("g",{children:[r("ellipse",{cx:e,cy:"16.8",rx:"1",ry:"0.7",fill:"#a5642e"}),r("circle",{cx:t,cy:"16.3",r:"0.4",fill:"#f4efe6"})]},e)),r(nn,{x:28.4,y:11.4})]}),icecream:()=>r("g",{children:[r("rect",{x:"27.8",y:"18.4",width:"3.4",height:"0.6",rx:"0.3",fill:"#cfe3ef"}),r("rect",{x:"29.2",y:"16.6",width:"0.6",height:"1.8",fill:"#cfe3ef"}),r("circle",{cx:"28.3",cy:"13.8",r:"1.2",fill:"#f28ab2"}),r("circle",{cx:"30.7",cy:"13.8",r:"1.2",fill:"#9be38f"}),r("circle",{cx:"29.5",cy:"12.5",r:"1.2",fill:"#7a4e2d"}),r("path",{d:"M26.8 14.4 h5.4 q-0.4 2.4 -2.7 2.4 q-2.3 0 -2.7 -2.4z",fill:"#cfe3ef",opacity:"0.85"}),r("rect",{x:"31.4",y:"10.6",width:"0.7",height:"2.8",fill:"#e8b84a"}),r("path",{d:"M29.5 11 q0.3 -0.9 1 -1.2",fill:"none",stroke:"#4f7a2c","stroke-width":"0.2"}),r("circle",{cx:"29.5",cy:"11.1",r:"0.45",fill:"#e05252"})]}),pie:()=>r("g",{children:[r("ellipse",{cx:"29.6",cy:"18.4",rx:"4.1",ry:"0.7",fill:"#e8e2d4"}),r("rect",{x:"26.2",y:"17.3",width:"6.8",height:"0.9",fill:"#a5642e"}),r("ellipse",{cx:"29.6",cy:"18.2",rx:"3.4",ry:"0.5",fill:"#a5642e"}),r("ellipse",{cx:"29.6",cy:"17.3",rx:"3.4",ry:"1.1",fill:"#c8813a"}),r("ellipse",{cx:"29.6",cy:"17.3",rx:"2.8",ry:"0.8",fill:"#e07b39"}),r("path",{d:"M29.6 17.3 L33.1 17.2 L32.4 18.2 Z",fill:"#e8e2d4"}),r("g",{fill:"#fbf6ea",children:[r("circle",{cx:"28.2",cy:"17",r:"0.45"}),r("circle",{cx:"29.8",cy:"16.8",r:"0.45"}),r("circle",{cx:"28.9",cy:"17.6",r:"0.45"})]})]}),pancakes:()=>r("g",{children:[r(Ar,{}),[17.3,16.4,15.5,14.6].map((e,t)=>r("rect",{x:"26.6",y:e,width:"6",height:"0.95",rx:"0.45",fill:t%2?"#c8913a":"#d9a441"},e)),r("g",{fill:"#8a4b1a",children:[r("rect",{x:"26.9",y:"14.5",width:"5.4",height:"0.45",rx:"0.2"}),r("rect",{x:"27.4",y:"14.9",width:"0.45",height:"1.4",rx:"0.2"}),r("rect",{x:"31.5",y:"14.9",width:"0.45",height:"0.8",rx:"0.2"})]}),r("rect",{x:"28.9",y:"13.9",width:"1.4",height:"0.65",fill:"#fbe7a1"}),r(nn,{x:28.6,y:11})]}),waffles:()=>r("g",{children:[r(Ar,{}),r("rect",{x:"26.6",y:"15.8",width:"6",height:"2.4",rx:"0.3",fill:"#e0a94a"}),r("g",{fill:"#c8913a",children:[[27.8,29,30.2,31.4].map(e=>r("rect",{x:e,y:"15.8",width:"0.2",height:"2.4"},e)),r("rect",{x:"26.6",y:"16.6",width:"6",height:"0.2"}),r("rect",{x:"26.6",y:"17.4",width:"6",height:"0.2"})]}),r("circle",{cx:"28.4",cy:"15.6",r:"0.5",fill:"#3f5fb5"}),r("circle",{cx:"29.3",cy:"15.4",r:"0.5",fill:"#e05252"}),r("circle",{cx:"30.6",cy:"15.5",r:"0.6",fill:"#fbf6ea"})]}),eggs:()=>r("g",{children:[r("rect",{x:"31.6",y:"13.8",width:"2",height:"3.4",rx:"0.5",fill:"#d9a441",stroke:"#a5743f","stroke-width":"0.25"}),r("ellipse",{cx:"29.6",cy:"17.7",rx:"4.1",ry:"1.2",fill:"#f4f1ea"}),r("ellipse",{cx:"27.9",cy:"17.4",rx:"1.3",ry:"0.65",fill:"#ffffff"}),r("circle",{cx:"27.9",cy:"17.3",r:"0.42",fill:"#f2b52a"}),r("ellipse",{cx:"30.4",cy:"17.2",rx:"1.3",ry:"0.65",fill:"#ffffff"}),r("circle",{cx:"30.4",cy:"17.1",r:"0.42",fill:"#f2b52a"}),r("g",{fill:"none",stroke:"#b5452a","stroke-width":"0.45",children:[r("path",{d:"M26.6 18.2 q0.6 -0.4 1.2 0 t1.2 0 t1.2 0"}),r("path",{d:"M29.6 18.5 q0.6 -0.4 1.2 0 t1.2 0"})]})]})};function B0({dish:e}){const t=lo[e]?e:"ramen";return r("g",{"data-dish":t,"shape-rendering":N0,children:lo[t]()})}const _e="geometricPrecision",ao=e=>[...e].reverse().join("");function rt({cells:e,cls:t,x0:n,y0:i=K,w:l=1,h:a=2,fill:s=Ht}){return r("g",{class:t,children:e.map(({x:o,y:u})=>r("rect",{x:n+o*l,y:i+u*a,width:l+.02,height:a+.02,fill:s},`${o},${u}`))})}const ld=[rd[0]],so={body:qt(Cn),legs:qt(ld)},oo={body:qt(Cn.map(ao)),legs:qt(ld.map(ao))};function z0({season:e,trick:t}){return r(V,{children:[r("g",{class:"tama-motion",fill:"var(--fg-3)",children:[r("rect",{x:"1",y:"10.6",width:"4",height:"0.5"}),r("rect",{x:"2.4",y:"13.6",width:"3.6",height:"0.5"}),r("rect",{x:"0.6",y:"16.6",width:"4.6",height:"0.5"})]}),e!=="winter"&&!t&&r("path",{class:"tama-sweat",d:"M25 7.6 q1.1 1.7 0 2.5 q-1.1 -0.8 0 -2.5z",fill:"#7fb6e6"})]})}function co({cx:e}){return r("g",{children:[r("circle",{cx:e,cy:"16.7",r:"2.2",fill:"none",stroke:"#2b2f36","stroke-width":"0.55"}),r("g",{class:"tama-spokes",stroke:"#9aa3ae","stroke-width":"0.18",children:[r("line",{x1:e-2,y1:"16.7",x2:e+2,y2:"16.7"}),r("line",{x1:e,y1:"14.7",x2:e,y2:"18.7"}),r("line",{x1:e-1.4,y1:"15.3",x2:e+1.4,y2:"18.1"}),r("line",{x1:e-1.4,y1:"18.1",x2:e+1.4,y2:"15.3"})]}),r("circle",{cx:e,cy:"16.7",r:"0.35",fill:"#2b2f36"})]})}function j0(){return r("g",{class:"tama-bike","shape-rendering":_e,children:[r("g",{class:"tama-motion",fill:"var(--fg-3)",children:[r("rect",{x:"0.6",y:"9.2",width:"3.4",height:"0.5"}),r("rect",{x:"1.4",y:"11.6",width:"3",height:"0.5"}),r("rect",{x:"0.4",y:"13.6",width:"3.6",height:"0.5"})]}),r(co,{cx:7.2}),r(co,{cx:26.8}),r("g",{fill:"none",stroke:"#2a9d8f","stroke-width":"0.5","stroke-linecap":"round",children:[r("path",{d:"M7.2 16.7 L15.5 16.9 L24.4 13.2 L26.8 16.7"}),r("path",{d:"M7.2 16.7 L11.6 13.8"})]}),r("path",{d:"M24.4 13.2 L24 11.4 M23.2 11.5 H25.4",fill:"none",stroke:"#2b2f36","stroke-width":"0.45","stroke-linecap":"round"}),r("circle",{cx:"15.5",cy:"16.9",r:"0.8",fill:"none",stroke:"#5a6472","stroke-width":"0.3"}),r("g",{class:"tama-crank",fill:"#2b2f36",children:[r("path",{d:"M14.5 15.9 L16.5 17.9",stroke:"#2b2f36","stroke-width":"0.3"}),r("rect",{x:"14",y:"15.6",width:"0.9",height:"0.4"}),r("rect",{x:"16.1",y:"17.8",width:"0.9",height:"0.4"})]})]})}function H0({x0:e}){return r("g",{class:"tama-helmet","shape-rendering":_e,children:[r("path",{d:`M${e+3.6} ${K+.5} Q${e+3.6} ${K-1.6} ${e+9} ${K-1.6} Q${e+14.4} ${K-1.6} ${e+14.4} ${K+.5} Z`,fill:"#e05252"}),r("g",{fill:"#8f2a2a",children:[6.4,8.5,10.6].map(t=>r("rect",{x:e+t,y:K-.9,width:"0.9",height:"0.45",rx:"0.2"},t))}),r("rect",{x:e+13.2,y:K+.1,width:"2.4",height:"0.5",rx:"0.25",fill:"#8f2a2a"})]})}const uo={dx:18,y:11.7};function vn({limb:e,x:t,y:n,w:i,h:l,cls:a}){const s=e.style==="tentacle";return r("rect",{class:a,x:t,y:n,width:i,height:l,rx:s?l/2:.25,fill:e.color,stroke:e.outline||void 0,"stroke-width":e.outline?.25:void 0})}function ad({x0:e,limb:t}){return r("g",{class:"tama-bass","shape-rendering":_e,children:[r("path",{d:`M${e+9.6} 13.7 L${e+23} 9.6 L${e+23.3} 10.5 L${e+9.9} 14.6 Z`,fill:"#4a2c1a"}),r("g",{fill:"#efe6d8",children:[13.5,16.5,19.5].map(n=>r("circle",{cx:e+n,cy:14.15-.306*(n-9.75),r:"0.13"},n))}),r("path",{d:`M${e+23} 9.4 L${e+26.4} 8.2 L${e+26.7} 9.1 L${e+23.3} 10.7 Z`,fill:"#e3c48a"}),r("g",{fill:"#c9ced6",children:[23.9,24.7,25.5,26.2].map((n,i)=>r("circle",{cx:e+n,cy:9.1-i*.3,r:"0.25"},n))}),r("ellipse",{cx:e+5,cy:"15.3",rx:"3",ry:"2.1",fill:"#3f6fb5"}),r("ellipse",{cx:e+8.1,cy:"14.4",rx:"1.9",ry:"1.5",fill:"#3f6fb5"}),r("ellipse",{cx:e+9.4,cy:"13.4",rx:"1.1",ry:"0.6",fill:"#3f6fb5"}),r("ellipse",{cx:e+6.6,cy:"14.7",rx:"2",ry:"1.1",fill:"#f4f1ea"}),r("rect",{x:e+5.6,y:"14.1",width:"1.4",height:"0.9",rx:"0.2",fill:"#1d1f24"}),r("rect",{x:e+2.6,y:"14.9",width:"1.6",height:"0.7",fill:"#c9ced6"}),r("g",{stroke:"#e6e9ef","stroke-width":"0.1",children:[r("line",{x1:e+3.4,y1:"15.1",x2:e+23.1,y2:"9.9"}),r("line",{x1:e+3.4,y1:"15.4",x2:e+23.2,y2:"10.2"})]}),t?r(vn,{limb:t,x:e+7.3,y:14.5,w:1.3,h:1,cls:"tama-strum"}):r(V,{children:[r("rect",{x:e+17.5,y:"11.1",width:"1",height:"0.9",fill:Ht}),r("rect",{class:"tama-strum",x:e+7.4,y:"14.6",width:"1.1",height:"0.8",fill:Ht})]})]})}function ho({x:e,y:t,cls:n}){return r("g",{class:n,fill:"var(--fg-2)",children:[r("ellipse",{cx:e,cy:t+2.4,rx:"0.6",ry:"0.45"}),r("rect",{x:e+.35,y:t,width:"0.3",height:"2.4"}),r("path",{d:`M${e+.65} ${t} q1 0.5 0.6 1.6 q-0.1 -0.9 -0.6 -1`})]})}function q0(){return r("g",{class:"tama-amp","shape-rendering":_e,children:[r(ho,{x:24.4,y:6,cls:"tama-note"}),r(ho,{x:26.6,y:4.4,cls:"tama-note tama-note2"}),r("path",{d:"M9 17.2 C8.6 19, 12 18.9, 16 18.9 S26.4 18.9, 27.6 17.6",fill:"none",stroke:"#1d1f24","stroke-width":"0.3"}),r("rect",{x:"27.6",y:"12.6",width:"6",height:"6.4",rx:"0.3",fill:"#2b2f36"}),r("rect",{x:"27.6",y:"12.6",width:"6",height:"1.2",fill:"#3b404a"}),r("g",{fill:"#c9ced6",children:[28.4,29.3,30.2,31.1].map(e=>r("circle",{cx:e,cy:"13.2",r:"0.25"},e))}),r("circle",{cx:"32.8",cy:"13.2",r:"0.2",fill:"#e05252"}),r("rect",{x:"28",y:"14.2",width:"5.2",height:"4.4",fill:"#4a4f58"}),r("g",{class:"tama-speaker",children:[r("circle",{cx:"30.6",cy:"16.4",r:"1.8",fill:"#3b404a"}),r("circle",{cx:"30.6",cy:"16.4",r:"0.7",fill:"#2b2f36"})]})]})}const Ct=18,fo="#6f93d6",U0=150,pt=e=>Math.round(e*1e4)/1e4;function W0({sprite:e}){const{scale:t,tx:n,ty:i}=va(e,{x0:Ct,sitting:!1}),l=Ct+8.5;return r("g",{class:"tama-critter",style:"transform-box: view-box",transform:`translate(${pt(2*l-n)} ${pt(i)}) scale(${pt(-t)} ${pt(t)})`,children:[r(Wi,{sprite:e,face:"happy",tint:U0,holding:"pint"}),r(sd,{sprite:e,kind:"pint",scale:t})]})}function sd({sprite:e,kind:t,scale:n}){if(!_a[t])return null;const[i,l]=zi(e,t),a=pt(1/n),s=(o,u)=>r("g",{style:"transform-box: view-box",transform:`translate(${i} ${l}) scale(${a}) ${o}`,children:u});return t==="pint"?s("translate(0 -11.5)",r(Wa,{x:0,cls:"tama-pint tama-clink"})):t==="mug"?s("scale(-1 1) translate(-30.1 -14.2)",r(cd,{})):t==="can"?s("translate(-17.8 -11.7)",r(ud,{x0:0})):null}function Wa({x:e,cls:t}){return r("g",{class:t,children:[r("rect",{x:e,y:"10.4",width:"2",height:"2.8",fill:"#e8a92e"}),r("rect",{x:e+.3,y:"10.9",width:"0.3",height:"1.8",fill:"#ffd98a"}),r("rect",{x:e-.1,y:"9.8",width:"2.2",height:"0.9",rx:"0.4",fill:"#fbf6ea"})]})}function K0({x0:e}){return r(Wa,{x:e+15.2,cls:"tama-pint tama-clink"})}const V0=[["#ffd166",15.4],["#f28ab2",19.6],["#7fb6e6",23.8],["#9be38f",28],["#ffd166",32.2]];function G0({critter:e}){return r("g",{children:[r("path",{d:"M13.4 1.2 Q23.6 3.6 34 1.2",fill:"none",stroke:"var(--fg-3)","stroke-width":"0.2","shape-rendering":_e}),V0.map(([t,n],i)=>r("rect",{class:`tama-twinkle${i%2?" tama-twinkle2":""}`,x:n-.35,y:1.9+Math.sin((n-13.4)/6.5)*.9,width:"0.7",height:"0.9",rx:"0.3",fill:t},n)),r("g",{class:"tama-friend",children:e!=null&&e.sprite?r(W0,{sprite:e.sprite}):r(V,{children:[r(rt,{cells:oo.body,x0:Ct,fill:fo}),r(rt,{cells:oo.legs,x0:Ct,y0:K+2*Cn.length,fill:fo}),r("g",{fill:"none",stroke:we,"stroke-width":"0.45","stroke-linecap":"square",children:[r("path",{d:`M${Ct+3.8} ${K+3.5} l0.7 -0.9 l0.7 0.9`}),r("path",{d:`M${Ct+10.8} ${K+3.5} l0.7 -0.9 l0.7 0.9`})]}),r(Wa,{x:Ct+1.2,cls:"tama-pint tama-clink tama-clink2"})]})}),r("g",{class:"tama-cheers",fill:"#ffd166",children:[r("rect",{x:"18.1",y:"7.6",width:"0.4",height:"1.2"}),r("rect",{x:"16.6",y:"8.3",width:"0.9",height:"0.4"}),r("rect",{x:"19.1",y:"8.3",width:"0.9",height:"0.4"})]})]})}function J0({x:e}){const t=e+1.1,n=e+7.4,i=`q-${(n-t)/16} 0.55 -${(n-t)/8} 0 `.repeat(8);return r("g",{class:"tama-kid-sheet","shape-rendering":_e,children:[r("path",{fill:"#f5f5f7",d:`M${t} 18.8 V15.6 Q${t} 13.6 ${(t+n)/2} 13.6 Q${n} 13.6 ${n} 15.6 V18.8 ${i}Z`}),r("ellipse",{cx:e+3.1,cy:"15.6",rx:"0.35",ry:"0.5",fill:we}),r("ellipse",{cx:e+5.4,cy:"15.6",rx:"0.35",ry:"0.5",fill:we}),r("path",{d:`M${e+6.5} 17.2 q0.8 -1.2 1.6 0`,fill:"none",stroke:"#3a2a1a","stroke-width":"0.2"}),r("rect",{x:e+6.4,y:"17",width:"1.8",height:"1.5",rx:"0.5",fill:"#ef8a2c"})]})}function Q0({x:e,sprite:t,costume:n}){const{scale:i,tx:l,ty:a}=va(t,{x0:e-4.25,sitting:!1,height:(n?ru:wa)/2});return r("g",{class:"tama-critter",style:"transform-box: view-box",transform:`translate(${pt(l)} ${pt(a)}) scale(${pt(i)})`,children:r(Wi,{sprite:t})})}function po({x:e,cls:t,costume:n,sprite:i}){return r("g",{class:t,children:[i?r(Q0,{x:e,sprite:i,costume:n}):r(V,{children:[r(rt,{cells:so.body,x0:e,y0:14,w:.5,h:1}),r(rt,{cells:so.legs,x0:e,y0:18,w:.5,h:1})]}),n?r(J0,{x:e}):!i&&r("g",{fill:we,children:[r("rect",{x:e+2.5,y:"15",width:"0.5",height:"1"}),r("rect",{x:e+6,y:"15",width:"0.5",height:"1"})]})]})}function Y0({trick:e=!1,critter:t}){return r("g",{children:[r(po,{x:17.4,cls:"tama-kid",costume:e,sprite:t==null?void 0:t.sprite}),r(po,{x:25.4,cls:"tama-kid tama-kid2",costume:e,sprite:t==null?void 0:t.sprite})]})}function Z0(){return r("g",{children:[r("g",{fill:"#4d5f95",children:[r("rect",{x:"0.6",y:"8.4",width:"20.4",height:"9",rx:"1"}),r("rect",{x:"0.2",y:"13.4",width:"2.6",height:"5",rx:"0.8"})]}),r("rect",{x:"1",y:"16.6",width:"21",height:"1.6",rx:"0.6",fill:"#5f75b0"}),r("g",{fill:"#3a2a1a",children:[r("rect",{x:"1.6",y:"18.2",width:"0.9",height:"0.8"}),r("rect",{x:"20.2",y:"18.2",width:"0.9",height:"0.8"})]}),r("g",{class:"tama-tv",children:[r("rect",{x:"22.4",y:"15.6",width:"11.2",height:"3.4",fill:"#6f533c"}),r("rect",{x:"22.4",y:"17.1",width:"11.2",height:"0.3",fill:"#5a4230"}),r("rect",{x:"27.4",y:"14.6",width:"1.6",height:"1",fill:"#1d1f24"}),r("rect",{x:"23",y:"7.4",width:"10.4",height:"7.2",rx:"0.4",fill:"#1d1f24"}),r("rect",{x:"23.6",y:"8",width:"9.2",height:"6",fill:"#20304a"}),r("rect",{x:"23.6",y:"13",width:"9.2",height:"1",fill:"#4f9a46"}),r("rect",{x:"29.6",y:"10.8",width:"2.4",height:"0.5",fill:"#b5733a"}),r("circle",{class:"tama-twinkle",cx:"30.8",cy:"9.9",r:"0.35",fill:"#ffd166"}),r("rect",{class:"tama-hero",x:"25.2",y:"11.9",width:"0.8",height:"1.1",fill:"#e05252"})]})]})}const X0={style:"arm",color:Ht};function od({x0:e,limb:t=X0}){return r("g",{class:"tama-controller","shape-rendering":_e,children:[r("rect",{x:e+6.6,y:"14.2",width:"4.8",height:"1.4",rx:"0.6",fill:"#3b404a"}),r("rect",{x:e+6.4,y:"14.6",width:"1.4",height:"1.6",rx:"0.6",fill:"#3b404a"}),r("rect",{x:e+10.2,y:"14.6",width:"1.4",height:"1.6",rx:"0.6",fill:"#3b404a"}),r("path",{d:`M${e+7.4} 14.9 h0.9 M${e+7.85} 14.45 v0.9`,stroke:"#c9ced6","stroke-width":"0.25"}),r("circle",{cx:e+10.2,cy:"14.7",r:"0.22",fill:"#e05252"}),r("circle",{cx:e+10.7,cy:"15.1",r:"0.22",fill:"#5aa9e6"}),r(vn,{limb:t,x:e+6.2,y:14.3,w:1.6,h:1.3}),r(vn,{limb:t,x:e+10,y:14.3,w:1.6,h:1.3,cls:"tama-thumb"})]})}function ey(){return r("g",{"shape-rendering":_e,children:[r("rect",{x:"21.4",y:"18.2",width:"12.4",height:"1",fill:"#6b4a33"}),r("g",{class:"tama-flowers",children:[r("g",{fill:"#3f8238",children:[r("rect",{x:"23",y:"13.4",width:"0.4",height:"4.8"}),r("rect",{x:"23.4",y:"15.6",width:"1",height:"0.4"}),r("rect",{x:"26",y:"15.2",width:"0.4",height:"3"}),r("rect",{x:"29",y:"15.4",width:"0.4",height:"2.8"}),r("rect",{x:"31.6",y:"17",width:"0.4",height:"1.2"}),r("rect",{x:"31.9",y:"16.6",width:"0.8",height:"0.4"})]}),r("circle",{cx:"23.2",cy:"13",r:"1.2",fill:"#ffd166"}),r("circle",{cx:"23.2",cy:"13",r:"0.5",fill:"#7a4e2d"}),r("path",{d:"M25.4 15.4 V14.2 L25.9 14.7 L26.2 14 L26.5 14.7 L27 14.2 V15.4 Z",fill:"#e05252"}),r("circle",{cx:"29.2",cy:"15",r:"0.8",fill:"#f28ab2"}),r("circle",{cx:"29.2",cy:"15",r:"0.3",fill:"#ffd166"})]}),r("g",{fill:"#7fb6e6",children:[[23.4,0],[23.9,-.3],[24.4,-.6]].map(([e,t])=>r("rect",{class:"tama-drop",x:e,y:"12.2",width:"0.3",height:"0.5",style:{animationDelay:`${t}s`}},e))})]})}function cd(){return r(V,{children:[r("g",{fill:"#efe6d8",children:[r("rect",{x:"25.5",y:"12",width:"3.4",height:"4.6",rx:"0.4"}),r("rect",{x:"28.9",y:"12.9",width:"1.2",height:"0.6"}),r("rect",{x:"29.5",y:"12.9",width:"0.6",height:"2.6"}),r("rect",{x:"28.9",y:"14.9",width:"1.2",height:"0.6"})]}),r("rect",{x:"25.5",y:"12",width:"3.4",height:"0.9",fill:"#7a4e2d"}),r("rect",{class:"tama-steam",x:"26.4",y:"8.6",width:"0.6",height:"2",fill:"var(--fg-3)"}),r("rect",{class:"tama-steam tama-steam2",x:"27.7",y:"7.8",width:"0.6",height:"2",fill:"var(--fg-3)"})]})}function ud({x0:e}){return r("g",{class:"tama-can","shape-rendering":_e,children:[r("path",{d:`M${e+16.6} 12.6 Q${e+17.8} 10.8 ${e+19} 12.6`,fill:"none",stroke:"#3f7fb5","stroke-width":"0.4"}),r("line",{x1:e+19.2,y1:"13.6",x2:e+21.3,y2:"11.9",stroke:"#5aa9e6","stroke-width":"0.45"}),r("rect",{x:e+21.1,y:"11.5",width:"0.6",height:"0.7",fill:"#3f7fb5"}),r("rect",{x:e+16.2,y:"12.6",width:"3.2",height:"2.4",rx:"0.4",fill:"#5aa9e6"})]})}function ty(){return r("g",{class:"tama-stove","shape-rendering":_e,children:[r("rect",{x:"21",y:"12.8",width:"12.8",height:"6.2",fill:"#d9dde3"}),r("rect",{x:"20.8",y:"12.2",width:"13.2",height:"0.6",fill:"#3b404a"}),r("g",{fill:"#3b404a",children:[23,25,29.8,31.8].map(e=>r("circle",{cx:e,cy:"13.6",r:"0.35"},e))}),r("rect",{x:"22.4",y:"14.8",width:"10",height:"2.8",rx:"0.3",fill:"#2b2f36"}),r("rect",{class:"tama-glow",x:"23",y:"15.4",width:"8.8",height:"1.6",fill:"#ef8a2c",opacity:"0.18"}),r("rect",{x:"21.6",y:"9.4",width:"4.8",height:"2.8",rx:"0.3",fill:"#8a93a1"}),r("rect",{x:"21",y:"9.8",width:"0.6",height:"0.4",fill:"#5a6472"}),r("rect",{x:"26.4",y:"9.8",width:"0.6",height:"0.4",fill:"#5a6472"}),r("rect",{x:"21.6",y:"9.4",width:"4.8",height:"0.5",fill:"#6b7480"}),r(nn,{x:22.8,y:6.6}),r("rect",{x:"27.6",y:"11.6",width:"4",height:"0.6",rx:"0.2",fill:"#2b2f36"}),r("line",{x1:"31.6",y1:"11.8",x2:"33.8",y2:"11.2",stroke:"#2b2f36","stroke-width":"0.4"}),r("g",{fill:"#e8a92e",children:[r("rect",{class:"tama-steam",x:"28.4",y:"10.8",width:"0.5",height:"0.5"}),r("rect",{class:"tama-steam tama-steam2",x:"30.2",y:"10.6",width:"0.5",height:"0.5"})]})]})}function dd({x0:e,from:t}){return r("line",{class:"tama-spoon",x1:t?t[0]:e+16.8,y1:t?t[1]:"13.6",x2:e+21.6,y2:"9.6",stroke:"#b07a4f","stroke-width":"0.45"})}function ny({x0:e}){return r("g",{class:"tama-toque","shape-rendering":_e,children:[r("g",{fill:"#f4f4f6",children:[r("circle",{cx:e+6.4,cy:K-2.4,r:"1.5"}),r("circle",{cx:e+9,cy:K-3,r:"1.8"}),r("circle",{cx:e+11.6,cy:K-2.4,r:"1.5"}),r("rect",{x:e+5,y:K-1.6,width:"8",height:"1.9"})]}),r("g",{fill:"#d8dce2",children:[r("rect",{x:e+7,y:K-1.4,width:"0.25",height:"1.6"}),r("rect",{x:e+9,y:K-1.4,width:"0.25",height:"1.6"}),r("rect",{x:e+11,y:K-1.4,width:"0.25",height:"1.6"})]})]})}function ry({from:e}){const[t,n]=e??[18.2,14.2];return r("g",{"shape-rendering":_e,children:[r("path",{class:"tama-leash",d:`M${t} ${n} Q23 12.4 28.1 15`,fill:"none",stroke:"#e05252","stroke-width":"0.25"}),r("g",{class:"tama-dog",children:[r("path",{class:"tama-tail",d:"M23 15.4 L21.8 13.4",stroke:"#b07a4f","stroke-width":"0.55","stroke-linecap":"round"}),r("g",{fill:"#b07a4f",children:[r("rect",{class:"tama-dog-a",x:"23.4",y:"16.6",width:"0.6",height:"2.4"}),r("rect",{class:"tama-dog-a",x:"27.6",y:"16.6",width:"0.6",height:"2.4"}),r("rect",{class:"tama-dog-b",x:"24",y:"16.6",width:"0.6",height:"2.4"}),r("rect",{class:"tama-dog-b",x:"27",y:"16.6",width:"0.6",height:"2.4"}),r("rect",{x:"22.8",y:"14.8",width:"5.8",height:"2.2",rx:"0.6"}),r("rect",{x:"27.8",y:"13",width:"2.8",height:"2.8",rx:"0.6"})]}),r("rect",{x:"30.2",y:"14.4",width:"1.4",height:"1.2",rx:"0.3",fill:"#c8915e"}),r("rect",{x:"31.3",y:"14.4",width:"0.5",height:"0.5",fill:we}),r("rect",{x:"28.2",y:"12.8",width:"1",height:"2.2",rx:"0.3",fill:"#7a4e2d"}),r("rect",{x:"29.6",y:"13.8",width:"0.45",height:"0.5",fill:we}),r("rect",{x:"27.8",y:"14.6",width:"0.6",height:"1.2",fill:"#e05252"})]})]})}function iy(){return r("g",{"shape-rendering":_e,children:[r("rect",{x:"0",y:"0",width:"34",height:"24",fill:"#6fb4ea",opacity:"0.13"}),r("circle",{class:"tama-sun",cx:"4.5",cy:"4",r:"2.1",fill:"#ffd166"}),r("g",{class:"tama-ball",children:[r("circle",{cx:"29.5",cy:"13.8",r:"1.8",fill:"#f4f4f6"}),r("path",{d:"M29.5 12 A1.8 1.8 0 0 1 31.3 13.8 H29.5 Z",fill:"#e05252"}),r("path",{d:"M29.5 15.6 A1.8 1.8 0 0 1 27.7 13.8 H29.5 Z",fill:"#5aa9e6"})]})]})}function ly(){const e="q0.85 -0.6 1.7 0 ".repeat(21);return r("g",{"shape-rendering":_e,children:[r("g",{class:"tama-water",children:[r("path",{d:`M-1 14.6 ${e} V24 H-1 Z`,fill:"#3b8fd0",opacity:"0.9"}),r("g",{fill:"#cfe9fa",children:[r("rect",{x:"4",y:"17.4",width:"1.6",height:"0.3"}),r("rect",{x:"15",y:"19.6",width:"2",height:"0.3"}),r("rect",{x:"26",y:"18",width:"1.4",height:"0.3"})]})]}),r("g",{fill:"#cfe9fa",children:[r("rect",{class:"tama-splash",x:"6.4",y:"13",width:"0.5",height:"0.5"}),r("rect",{class:"tama-splash tama-splash2",x:"23.4",y:"13",width:"0.5",height:"0.5"})]})]})}function Ka({x0:e}){return r("g",{class:"tama-goggles","shape-rendering":_e,children:[r("rect",{x:e+3,y:K+2.6,width:"12",height:"0.5",fill:"#2b2f36"}),[4.3,11.3].map(t=>r("rect",{x:e+t,y:K+1.5,width:"2.4",height:"2.8",rx:"0.8",fill:"#7fd1e6","fill-opacity":"0.45",stroke:"#2b2f36","stroke-width":"0.35"},t))]})}function ay(){return r("g",{"shape-rendering":_e,children:[r("g",{class:"tama-motion",fill:"var(--fg-3)",children:[r("rect",{x:"0.6",y:"9.6",width:"3",height:"0.5"}),r("rect",{x:"1.2",y:"12",width:"2.6",height:"0.5"}),r("rect",{x:"0.4",y:"14.4",width:"3.2",height:"0.5"})]}),r("g",{fill:"#f4f8fb",children:[[3.6,0],[4.4,-.2],[3.2,-.4]].map(([e,t])=>r("rect",{class:"tama-kick",x:e,y:"17.8",width:"0.6",height:"0.6",style:{animationDelay:`${t}s`}},t))}),r("g",{class:"tama-sled",children:[r("path",{d:"M5.4 19 H23.4 Q25.8 19 25.4 16.8",fill:"none",stroke:"#8a93a1","stroke-width":"0.4"}),r("g",{fill:"#8a93a1",children:[7.6,14,20.4].map(e=>r("rect",{x:e,y:"17.8",width:"0.4",height:"1.2"},e))}),r("rect",{x:"5",y:"16.8",width:"18.8",height:"1.1",rx:"0.3",fill:"#b5452a"}),r("path",{d:"M25.2 17 Q24.4 15.4 22.6 14.6",fill:"none",stroke:"#e8b84a","stroke-width":"0.25"})]})]})}function Va({x0:e}){return r("g",{class:"tama-scarf",children:[r("rect",{x:e+3,y:K+4,width:"12",height:"1.1",fill:"#d64541"}),r("g",{fill:"#f4f4f6",children:[5,8,11,14].map(t=>r("rect",{x:e+t,y:K+4,width:"0.5",height:"1.1"},t))}),r("rect",{class:"tama-scarf-tail",x:e-1.4,y:K+4.2,width:"2.8",height:"0.8",fill:"#d64541"})]})}const sy={run:{tempo:.3,stride:!0,outdoors:!0,snowcap:!0,Behind:z0,trick:{pail:!0}},cycle:{pose:{x0:7,lift:2},tempo:.4,stride:!0,outdoors:!0,jack:{x:.6,y:16.4},Behind:j0,Headwear:H0},music:{pose:{x0:6},tempo:.5,jack:{x:1.5,y:16.4},Behind:q0,Held:ad},beer:{pose:{x0:1},tempo:.9,smile:!0,Behind:G0,Held:K0},kids:{pose:{x0:1},tempo:.7,smile:!0,Behind:Y0,trick:{outdoors:!0}},game:{pose:{x0:3,sitting:!0},tempo:1.2,Behind:Z0,Held:od,paws:!0},garden:{pose:{x0:2},tempo:.8,outdoors:!0,Behind:ey,Held:ud},cook:{pose:{x0:2},tempo:.6,Behind:ty,Held:dd,Headwear:ny},dog:{pose:{x0:1},tempo:.5,stride:!0,smile:!0,outdoors:!0,Behind:ry},swim:{pose:{x0:6,sitting:!0},tempo:1,Behind:iy,Held:Ka,Front:ly},sled:{pose:{x0:5,sitting:!0},tempo:.35,smile:!0,outdoors:!0,snowcap:!0,Behind:ay,Held:Va}},Ge="geometricPrecision";function kt({fill:e="#1d2026"}){return r("rect",{x:"23.4",y:"6",width:"8.2",height:"5.6",fill:e})}function We({x:e,y:t,size:n,fill:i,weight:l=700,anchor:a="start",children:s}){return r("text",{x:e,y:t,"font-size":n,"font-weight":l,"font-family":"var(--mono)","text-anchor":a,fill:i,children:s})}const oy={bell:r("g",{children:[r("rect",{x:"2.9",y:"1.35",width:"0.6",height:"0.55",fill:"#b8862a"}),r("path",{d:"M1.9 4.3 Q1.9 1.8 3.2 1.8 Q4.5 1.8 4.5 4.3 Z",fill:"#e8a92e"}),r("rect",{x:"1.55",y:"4.1",width:"3.3",height:"0.55",rx:"0.2",fill:"#e8a92e"}),r("circle",{cx:"3.2",cy:"4.95",r:"0.38",fill:"#8a5a1a"})]}),done:r("path",{d:"M1.7 3.4 l1.1 1.1 l2.1 -2.4",fill:"none",stroke:"#2f9a57","stroke-width":"0.8","stroke-linecap":"square"}),ci:r("path",{d:"M1.9 1.9 l2.6 2.6 M4.5 1.9 l-2.6 2.6",fill:"none",stroke:"#d64541","stroke-width":"0.8","stroke-linecap":"square"}),api:r("path",{d:"M3.8 1.3 L1.9 3.5 H3.1 L2.6 5.3 L4.6 2.9 H3.4 Z",fill:"#e8a92e"}),ctx:r("g",{children:[r("rect",{x:"2",y:"1.5",width:"2.4",height:"3.7",rx:"0.3",fill:"none",stroke:"#5a6472","stroke-width":"0.35"}),r("rect",{x:"2.35",y:"2.05",width:"1.7",height:"2.8",fill:"#e8892e"})]}),update:r("g",{children:[r("rect",{x:"1.6",y:"2.3",width:"3.2",height:"2.8",fill:"#c49a6c"}),r("rect",{x:"1.6",y:"2.3",width:"3.2",height:"0.65",fill:"#d8b384"}),r("rect",{x:"2.95",y:"2.3",width:"0.5",height:"2.8",fill:"#a57c4f"})]}),merged:r("g",{children:[r("path",{d:"M2.2 2 V4.6 M2.2 2.4 Q2.2 3.3 4.3 3.3",fill:"none",stroke:"#8957e5","stroke-width":"0.4"}),r("circle",{cx:"2.2",cy:"1.9",r:"0.55",fill:"#8957e5"}),r("circle",{cx:"2.2",cy:"4.7",r:"0.55",fill:"#8957e5"}),r("circle",{cx:"4.4",cy:"3.3",r:"0.55",fill:"#8957e5"})]})};function cy({kind:e,label:t,urgent:n,more:i,x0:l}){const a=4.6+t.length*2.16+.9,[s,o]=n?["#e05252","#ffffff"]:["#f4f4f6","#1b2028"],u=Math.max(l+3.6,9.4),c=.8+a+.7;return r("g",{class:`tama-bubble${n?" tama-bubble-urgent":""}`,"shape-rendering":Ge,children:[r("path",{d:`M6.4 5.6 L${u} 8.3 L8.4 5.6 Z`,fill:s}),r("rect",{x:"0.8",y:"0.8",width:a,height:"5",rx:"1.3",fill:s}),oy[e],r(We,{x:"5.3",y:"4.75",size:"3.6",fill:o,children:t}),i>0&&r("g",{class:"tama-more",children:[r("rect",{x:c,y:"1.9",width:"4.4",height:"2.8",rx:"1.4",fill:"#3b404a"}),r(We,{x:c+2.2,y:"3.95",size:"2.1",fill:"#e6e9ef",weight:600,anchor:"middle",children:`+${i}`})]})]})}function mo({x0:e}){return r("g",{class:"tama-happy-eyes",fill:"none",stroke:we,"stroke-width":"0.45","stroke-linecap":"square",children:[r("path",{d:`M${e+4.8} ${K+3.5} l0.7 -0.9 l0.7 0.9`}),r("path",{d:`M${e+11.8} ${K+3.5} l0.7 -0.9 l0.7 0.9`})]})}function uy({x0:e}){return r("g",{fill:"none",stroke:we,"stroke-width":"0.45","stroke-linecap":"square",children:[r("path",{d:`M${e+4.9} ${K+2.3} l1.2 1.5 M${e+6.1} ${K+2.3} l-1.2 1.5`}),r("path",{d:`M${e+11.9} ${K+2.3} l1.2 1.5 M${e+13.1} ${K+2.3} l-1.2 1.5`})]})}function dy({x0:e}){return r("g",{children:[r("g",{fill:"none",stroke:we,"stroke-width":"0.4",children:[r("path",{d:`M${e+4.4} ${K+1.5} l1.8 -0.6`}),r("path",{d:`M${e+11.8} ${K+.9} l1.8 0.6`})]}),r("path",{class:"tama-sweat",fill:"#7fb6e6",d:`M${e+2.2} ${K+.4} q0.8 1.2 0 1.8 q-0.8 -0.6 0 -1.8z`}),r("path",{class:"tama-sweat",style:{animationDelay:"-0.6s"},fill:"#7fb6e6",d:`M${e+15.9} ${K+.8} q0.8 1.2 0 1.8 q-0.8 -0.6 0 -1.8z`})]})}function Gr({x:e,y:t,cls:n="tama-sparkle",delay:i=0}){const l=[[0,-.9],[.25,-.25],[.9,0],[.25,.25],[0,.9],[-.25,.25],[-.9,0],[-.25,-.25]];return r("path",{class:n||void 0,style:i?{animationDelay:`${i}s`}:void 0,fill:"#ffd166","shape-rendering":Ge,d:`M${l.map(([a,s])=>`${(e+a).toFixed(2)} ${(t+s).toFixed(2)}`).join(" L")} Z`})}function hy({x0:e}){return r("g",{children:[[6,7.4,0],[9,6.6,-.6],[12,7.4,-1.2]].map(([t,n,i])=>r("g",{class:"tama-orbit",style:{animationDelay:`${i}s`},children:r(Gr,{x:e+t,y:n,cls:""})},t))})}function fy({x0:e}){return r("g",{class:"tama-startle",fill:"#f2c14e",children:[r("rect",{x:e+16.6,y:"5.8",width:"0.6",height:"1.8"}),r("rect",{x:e+16.6,y:"8",width:"0.6",height:"0.6"})]})}function py({x0:e}){return r("g",{fill:Ht,children:[r("rect",{class:"tama-cheer",x:e,y:"9.8",width:"1.02",height:"3.4"}),r("rect",{class:"tama-cheer tama-cheer2",x:e+16,y:"9.8",width:"1.02",height:"3.4"})]})}const hd=({d:e})=>r("g",{class:"tama-ding",fill:"none",stroke:"#f2c14e","stroke-width":"0.3","shape-rendering":Ge,children:r("path",{d:e})});function my(){return r("rect",{class:"tama-slap",x:"21.6",y:"8.7",width:"1.2",height:"0.9",fill:Ht})}const gy=[21.25,12.3],yy=[22.2,9.6];function by({limb:e}){return r("g",{children:[r(vn,{limb:e,x:20.7,y:11.9,w:1.1,h:.8,cls:"tama-hand"}),r(vn,{limb:e,x:22.7,y:11.9,w:1.1,h:.8,cls:"tama-hand tama-hand2"})]})}function ky({limb:e}){return r(vn,{limb:e,x:21.6,y:8.7,w:1.2,h:.9,cls:"tama-slap"})}function wy(){return r("g",{children:[r("g",{"shape-rendering":Ge,children:[r("rect",{x:"20.7",y:"12.6",width:"3",height:"0.6",rx:"0.2",fill:"#8b93a1"}),r("path",{d:"M20.95 12.65 Q20.95 10.9 22.2 10.9 Q23.45 10.9 23.45 12.65 Z",fill:"#f2c14e"}),r("rect",{x:"21.4",y:"11.4",width:"0.4",height:"0.5",fill:"#fff3c4"}),r("rect",{x:"21.95",y:"10.4",width:"0.5",height:"0.55",fill:"#c9a03a"})]}),r(hd,{d:"M20.3 10.4 l-1 -0.5 M20.6 9.5 l-0.6 -0.9 M24.1 10.4 l1 -0.5 M23.8 9.5 l0.6 -0.9"})]})}function vy(){return r("g",{children:[r("g",{class:"tama-alarm","shape-rendering":Ge,children:[r("rect",{x:"27.4",y:"18.2",width:"0.5",height:"0.8",fill:"#8b93a1"}),r("rect",{x:"30.1",y:"18.2",width:"0.5",height:"0.8",fill:"#8b93a1"}),r("circle",{cx:"27.4",cy:"14.3",r:"0.9",fill:"#e8a92e"}),r("circle",{cx:"30.6",cy:"14.3",r:"0.9",fill:"#e8a92e"}),r("rect",{x:"28.8",y:"13.4",width:"0.4",height:"1",fill:"#3b404a"}),r("circle",{cx:"29",cy:"16.4",r:"2.1",fill:"#e6e9ef",stroke:"#d03a3a","stroke-width":"0.45"}),r("path",{d:"M29 16.4 v-1.3 M29 16.4 h0.9",stroke:we,"stroke-width":"0.3",fill:"none"})]}),r(hd,{d:"M26 14 l-0.9 -0.6 M25.8 15.3 l-1 0 M32 14 l0.9 -0.6 M32.2 15.3 l1 0"})]})}function _y(){return r("g",{children:[r(Gr,{x:22.2,y:4.4}),r(Gr,{x:32.6,y:4.8,delay:-.5}),r(Gr,{x:20.6,y:7.2,delay:-1})]})}function xy(){return r("g",{children:[r(kt,{}),r("path",{d:"M25.3 8.8 l1.7 1.7 l3.4 -3.6",fill:"none",stroke:"#6fcf8f","stroke-width":"0.9","stroke-linecap":"square","shape-rendering":Ge})]})}function Sy(){return r("g",{children:[r(kt,{fill:"#1d1a26"}),r("g",{"shape-rendering":Ge,children:[r("path",{d:"M26.3 6.9 V9.4 M26.3 7.3 Q26.3 8.1 28.9 8.1",fill:"none",stroke:"#a371f7","stroke-width":"0.45"}),r("circle",{cx:"26.3",cy:"6.9",r:"0.6",fill:"#a371f7"}),r("circle",{cx:"26.3",cy:"9.5",r:"0.6",fill:"#a371f7"}),r("circle",{cx:"29",cy:"8.1",r:"0.6",fill:"#a371f7"})]}),r(We,{x:"27.5",y:"11.15",size:"1.35",fill:"#a371f7",weight:600,anchor:"middle",children:"merged"})]})}const go=({x:e})=>r("g",{children:[r("path",{class:"tama-flame",fill:"#f08a3c",d:`M${e} 5.6 q-0.5 -1.8 0.7 -3 q0.2 1.1 0.7 1.5 q0.3 -1 1 -1.6 q0.8 1.8 0.1 3.1z`}),r("path",{class:"tama-flame tama-flame2",fill:"#ffd166",d:`M${e+.5} 5.6 q-0.2 -1 0.6 -1.8 q0.2 0.7 0.6 0.9 q0.3 -0.5 0.4 -0.9 q0.6 1 0.1 1.8z`})]});function $y(){return r("g",{children:[r(kt,{fill:"#2a1416"}),r("g",{class:"tama-errors",children:[r("path",{d:"M25.4 7.1 l3.2 3.2 M28.6 7.1 l-3.2 3.2",fill:"none",stroke:"#e05252","stroke-width":"0.8","stroke-linecap":"square"}),r(We,{x:"29.4",y:"10.7",size:"1.8",fill:"#e05252",children:"CI"})]}),r(go,{x:24.6}),r(go,{x:28.4}),r("g",{fill:"#f4f4f6","shape-rendering":Ge,children:[r("circle",{class:"tama-spray",cx:"23",cy:"6",r:"0.5"}),r("circle",{class:"tama-spray tama-spray2",cx:"23",cy:"6",r:"0.6"}),r("circle",{class:"tama-spray tama-spray3",cx:"23",cy:"6",r:"0.45"})]})]})}function Cy(){return r("g",{"shape-rendering":Ge,children:[r("path",{d:"M20.4 9.2 q0.8 -1.6 2.3 -2.6",fill:"none",stroke:"#2b2f36","stroke-width":"0.35"}),r("rect",{x:"19.3",y:"9.3",width:"1.5",height:"3.8",rx:"0.55",fill:"#d03a3a"}),r("rect",{x:"19.6",y:"8.7",width:"0.9",height:"0.7",fill:"#3b404a"}),r("rect",{x:"19.5",y:"10.4",width:"1.1",height:"0.9",fill:"#f4f4f6"})]})}const Ty=Array.from({length:18},(e,t)=>[23.6+t*1.7%7.4,6.2+t*1.3%4.8]),Ey=Array.from({length:18},(e,t)=>[24.1+t*2.3%7.2,6.5+t*.9%4.8]);function Py(){const e=t=>t.map(([n,i])=>r("rect",{x:n.toFixed(1),y:i.toFixed(1),width:"0.6",height:"0.6"},`${n},${i}`));return r("g",{children:[r(kt,{fill:"#22252b"}),r("g",{class:"tama-static",fill:"#8b93a1",children:e(Ty)}),r("g",{class:"tama-static tama-static2",fill:"#5d6470",children:e(Ey)}),r("rect",{x:"25.2",y:"7.8",width:"4.6",height:"2.4",fill:"#22252b"}),r(We,{x:"27.5",y:"9.7",size:"2",fill:"#ffd166",anchor:"middle",children:"529"})]})}function Ay(){return r("g",{class:"tama-stack",children:Array.from({length:12},(e,t)=>r("rect",{x:20.5+(t%2?.35:0),y:(12.65-t*.68).toFixed(2),width:"2.6",height:"0.55",fill:t%2?"#f2ece0":"#e2dccf"},t))})}function My({pct:e,cost:t}){if(t)return r("g",{children:[r(kt,{}),r(We,{x:"27.5",y:"9.6",size:"1.7",fill:"#f2a33a",anchor:"middle",children:"compact?"})]});const n=Math.min(100,Math.max(0,e??90));return r("g",{children:[r(kt,{}),r(We,{x:"24.2",y:"7.9",size:"1.4",fill:"#a4acb9",weight:500,children:"context"}),r("rect",{x:"24.2",y:"8.6",width:"6.6",height:"1.5",fill:"none",stroke:"#707884","stroke-width":"0.25"}),r("rect",{class:"tama-fill",x:"24.4",y:"8.8",width:6.2*n/100,height:"1.1",fill:"#f2a33a"}),e!=null&&r(We,{x:"30.8",y:"11.3",size:"1.5",fill:"#f2a33a",anchor:"end",children:`${e}%`})]})}const Ly=["#52b4ea","#7fbf7f","#c792ea","#e6e9ef"],Iy=[.85,.55,.7,.4,.9,.6],Oy={1:[[23.4,6,8.2,5]],2:[[23.4,6,4.1,5],[27.5,6,4.1,5]],4:[[23.4,6,4.1,2.5],[27.5,6,4.1,2.5],[23.4,8.5,4.1,2.5],[27.5,8.5,4.1,2.5]]};function Dy({n:e}){const t=e===0?[]:Oy[e===1?1:e===2?2:4];let n=0;return r("g",{children:[r(kt,{}),r("rect",{x:"23.4",y:"11",width:"8.2",height:"0.6",fill:e?"#3d8f5a":"#2c4234"}),e===0&&r("rect",{class:"tama-cursor",x:"24",y:"6.6",width:"0.6",height:"0.6",fill:"#707884"}),t.length>=2&&r("rect",{x:"27.45",y:"6",width:"0.12",height:"5",fill:"#4b515c"}),t.length===4&&r("rect",{x:"23.4",y:"8.45",width:"8.2",height:"0.12",fill:"#4b515c"}),t.slice(0,Math.min(e,4)).flatMap(([i,l,a,s])=>Array.from({length:s>=5?3:2},(o,u)=>{const c=n++;return r("rect",{class:"tama-type",style:{animationDelay:`${(-.37*c).toFixed(2)}s`},x:(i+.5).toFixed(2),y:(l+.6+u*1.1).toFixed(2),width:((a-1)*Iy[c%6]).toFixed(2),height:"0.45",fill:Ly[c%4]},c)}))]})}function Ry({day:e,time:t}){const n=Math.min(3,7.6/(.6*t.length));return r("g",{children:[r(kt,{fill:"#16181d"}),r(We,{x:"24.1",y:"7.9",size:"1.3",fill:"#a4acb9",weight:500,children:e?`back ${e}`:"back at"}),r(We,{x:"27.5",y:"10.9",size:n.toFixed(2),fill:"#f2c14e",anchor:"middle",children:t}),r("circle",{cx:"30.85",cy:"6.95",r:"0.5",fill:"#f3e9c6"}),r("circle",{cx:"31.1",cy:"6.8",r:"0.42",fill:"#16181d"})]})}function Fy(){return r("g",{fill:"var(--fg-2)","font-family":"var(--mono)","font-weight":"700",children:[r("text",{class:"tama-z",x:"17.5",y:"8.4","font-size":"3",children:"z"}),r("text",{class:"tama-z tama-z2",x:"19.6",y:"6","font-size":"3.8",children:"Z"})]})}function Ny({x0:e}){return r("g",{fill:we,children:[r("rect",{x:e+5.5,y:K+2.6,width:"1",height:"1.6"}),r("rect",{x:e+12.5,y:K+2.6,width:"1",height:"1.6"})]})}function By(){return r("g",{class:"tama-parcel","shape-rendering":Ge,children:[r("rect",{x:"24.6",y:"15.6",width:"4.8",height:"3.4",fill:"#c49a6c"}),r("rect",{x:"24.6",y:"15.6",width:"4.8",height:"0.7",fill:"#d8b384"}),r("rect",{x:"26.75",y:"15.6",width:"0.5",height:"3.4",fill:"#a57c4f"}),r("rect",{x:"28.3",y:"14.4",width:"2.2",height:"1.8",rx:"0.25",fill:"#52b4ea"}),r("path",{d:"M29.4 14.75 v1 M28.95 15.3 l0.45 0.5 l0.45 -0.5",fill:"none",stroke:"#ffffff","stroke-width":"0.28"})]})}const zy={code:{x0:3,sitting:!0},nap:{x0:3,sitting:!0},read:{x0:4,sitting:!0}},jy={x0:8},fd=qt(Cn),Hy=qt(Cn.map((e,t)=>t===2?e.replace(/^.##/,"...").replace(/##$/,".."):e)),Vl=rd.map(e=>qt([e])),Gl=K+2*Cn.length;function qy(){return r("g",{children:[r(rt,{cells:fd,cls:"tama-body",x0:0}),r(Jl,{x0:0}),r(rt,{cells:Vl[0],cls:"tama-legs-a",x0:0,y0:Gl})]})}const Uy=new Set([Ka,Va]),Wy={beer:"pint",coffee:"mug",cook:"spoon",garden:"can",dog:"leash",music:"bass",game:"controller"};function Nn({dy:e,children:t}){return e?r("g",{transform:`translate(0 ${e})`,children:t}):t}function Jl({closed:e,x0:t}){return r("g",{class:e?"tama-eyes-closed":"tama-eyes",children:k0.map(n=>r("rect",{x:t+n,y:e?K+3.3:K+2,width:"1",height:e?.5:2,fill:we},n))})}const yo={spring:{sky:"#7fb3e0",ground:"#5c9a4c",canopy:["#6fae5a","#f2a7c3"],fall:"#f4b6cc"},summer:{sky:"#6fb4ea",ground:"#4f9443",canopy:["#4f9a46","#3f8238"]},autumn:{sky:"#c9a36b",ground:"#7a6a3a",canopy:["#d9822b","#b5452a"],fall:"#e07b39"},winter:{sky:"#9fb3c8",ground:"#e6edf3",fall:"#f4f8fb"}},Ky=[[3,0],[11,-.7],[18,-1.6],[25.5,-.3],[32,-1.1]];function Vy({season:e,night:t}){const n=yo[e]||yo.summer;return r("g",{class:"tama-scenery","data-season":e,children:[r("rect",{x:"0",y:"0",width:"34",height:"19.2",fill:n.sky,opacity:"0.13"}),r("rect",{x:"0",y:"19.4",width:"34",height:"4.6",fill:n.ground,opacity:e==="winter"?.85:.55}),t&&r("g",{children:[r("rect",{x:"0",y:"0",width:"34",height:"24",fill:"#0b0a1a",opacity:"0.5"}),r("g",{class:"tama-moon",children:[r("circle",{cx:"5",cy:"4.2",r:"2",fill:"#f3e9c6"}),r("circle",{cx:"4.3",cy:"3.7",r:"0.4",fill:"#d8ccaa"}),r("circle",{cx:"5.7",cy:"4.9",r:"0.3",fill:"#d8ccaa"})]}),r("g",{transform:"translate(19 3.2)",children:r("path",{class:"tama-bat",fill:"#1a1626",d:"M0 0.6 q1 -1 2 0 q0.4 -0.8 1 -0.2 q0.6 -0.6 1 0.2 q1 -1 2 0 q-1.2 0.1 -2 1 q-0.6 -0.4 -1 0 q-0.4 -0.4 -1 0 q-0.8 -0.9 -2 -1z"})})]}),e==="summer"&&!t&&r("circle",{class:"tama-sun",cx:"4.5",cy:"4",r:"2.1",fill:"#ffd166"}),r("rect",{x:"30.2",y:"11.6",width:"1.4",height:"7.6",fill:"#6b4a33"}),n.canopy?r("g",{children:[r("rect",{x:"27.4",y:"7.4",width:"6.6",height:"4.6",rx:"1.4",fill:n.canopy[0]}),r("rect",{x:"28.4",y:"5.8",width:"4.6",height:"2.2",rx:"1",fill:n.canopy[0]}),r("g",{fill:n.canopy[1],children:[r("rect",{x:"28.2",y:"8.2",width:"0.8",height:"0.8"}),r("rect",{x:"31.4",y:"7",width:"0.8",height:"0.8"}),r("rect",{x:"32.4",y:"9.8",width:"0.8",height:"0.8"}),r("rect",{x:"29.6",y:"10.4",width:"0.8",height:"0.8"})]})]}):r("g",{stroke:"#6b4a33","stroke-width":"0.5",children:[r("line",{x1:"30.9",y1:"12",x2:"28.4",y2:"8.2"}),r("line",{x1:"30.9",y1:"11",x2:"33.4",y2:"8"}),r("line",{x1:"30.9",y1:"9.6",x2:"30.4",y2:"6.2"})]}),e==="spring"&&r("g",{children:[r("rect",{x:"3",y:"19.8",width:"0.7",height:"0.7",fill:"#f2a7c3"}),r("rect",{x:"6.5",y:"20.6",width:"0.7",height:"0.7",fill:"#ffd166"}),r("rect",{x:"26",y:"20.2",width:"0.7",height:"0.7",fill:"#f2a7c3"})]}),e==="summer"&&r("g",{fill:"#3f8238",children:[r("rect",{x:"2.6",y:"18.4",width:"0.4",height:"1.2"}),r("rect",{x:"3.3",y:"18.1",width:"0.4",height:"1.5"}),r("rect",{x:"26.4",y:"18.3",width:"0.4",height:"1.3"})]}),e==="autumn"&&r("g",{fill:"#c2452d",children:[r("rect",{x:"4",y:"19.7",width:"1",height:"0.5"}),r("rect",{x:"24.8",y:"20.1",width:"1",height:"0.5"}),r("rect",{x:"27.6",y:"19.6",width:"1",height:"0.5",fill:"#e07b39"})]}),n.fall&&r("g",{fill:n.fall,children:Ky.map(([i,l])=>r("rect",{class:"tama-fall",x:i,y:"-1",width:"0.7",height:"0.7",style:{animationDelay:`${l}s`}},i))})]})}function Gy({x:e,y:t}){return r("g",{class:"tama-jack","shape-rendering":"geometricPrecision",children:[r("rect",{x:e+1.3,y:t,width:"0.5",height:"0.7",fill:"#4f7a2c"}),r("rect",{x:e,y:t+.4,width:"3.1",height:"2.2",rx:"1",fill:"#ef8a2c"}),r("rect",{x:e+1,y:t+.5,width:"0.15",height:"2",fill:"#d9741f"}),r("rect",{x:e+1.95,y:t+.5,width:"0.15",height:"2",fill:"#d9741f"}),r("path",{class:"tama-jack-face",fill:"#ffcf5a",d:`M${e+.6} ${t+1.4} l0.4 -0.6 l0.4 0.6z M${e+2.1} ${t+1.4} l0.4 -0.6 l0.4 0.6z M${e+.6} ${t+1.8} h1.9 l-0.3 0.5 h-1.3z`})]})}const Jy={sleep:{x:1.5,y:16.4},coffee:{x:1.5,y:16.4},eat:{x:1.5,y:16.4},code:{x:25.5,y:16.4},nap:{x:25.5,y:16.4},read:{x:24.6,y:3.4}};function Qy(){return r("g",{class:"tama-xmas-tree","shape-rendering":"geometricPrecision",children:[r("rect",{x:"2.9",y:"18.2",width:"1",height:"0.8",fill:"#5a3a26"}),r("polygon",{points:"3.4,12 7.6,18.2 -0.8,18.2",fill:"#276b3e"}),r("polygon",{points:"3.4,8.6 7.2,14.6 -0.4,14.6",fill:"#2f7d4a"}),r("polygon",{points:"3.4,5.2 6.8,10.8 0,10.8",fill:"#276b3e"}),r("polygon",{points:"3.4,2.4 6.2,7.2 0.6,7.2",fill:"#2f7d4a"}),r("polygon",{class:"tama-twinkle",points:"3.4,0.8 3.8,1.8 4.8,1.9 4,2.5 4.3,3.4 3.4,2.9 2.5,3.4 2.8,2.5 2,1.9 3,1.8",fill:"#ffd166"}),r("circle",{cx:"2.6",cy:"6.2",r:"0.42",fill:"#e05252"}),r("circle",{class:"tama-twinkle",cx:"4.6",cy:"9.4",r:"0.42",fill:"#7fb6e6"}),r("circle",{cx:"1.4",cy:"10",r:"0.42",fill:"#ffd166"}),r("circle",{class:"tama-twinkle tama-twinkle2",cx:"5.6",cy:"12.8",r:"0.42",fill:"#e05252"}),r("circle",{cx:"0.8",cy:"13.8",r:"0.42",fill:"#c792ea"}),r("circle",{cx:"6.6",cy:"16.6",r:"0.42",fill:"#ffd166"})]})}function Yy(){return r("g",{class:"tama-stocking",children:[25.4,30.2].map(e=>r("g",{children:[r("rect",{x:e,y:"7.1",width:"1.2",height:"2.1",fill:"#c0392b"}),r("rect",{x:e,y:"8.6",width:"2",height:"0.9",rx:"0.4",fill:"#c0392b"}),r("rect",{x:e-.1,y:"7.1",width:"1.4",height:"0.6",fill:"#f4f4f6"})]},e))})}function pd({x0:e}){return r("g",{class:"tama-hat-santa",children:[r("g",{fill:"#d03a3a",children:[r("rect",{x:e+4,y:"6.8",width:"10",height:"1.5"}),r("rect",{x:e+5.6,y:"5.6",width:"6.6",height:"1.3"}),r("rect",{x:e+7.4,y:"4.6",width:"3.6",height:"1.1"}),r("rect",{x:e+10.6,y:"4.6",width:"3",height:"1"}),r("rect",{x:e+13,y:"5.2",width:"1.2",height:"1"})]}),r("rect",{x:e+3,y:"8.2",width:"12",height:"1.3",rx:"0.5",fill:"#f4f4f6"}),r("rect",{x:e+13.6,y:"5.6",width:"1.6",height:"1.6",rx:"0.8",fill:"#f4f4f6"})]})}function md({x0:e}){return r("g",{class:"tama-hat-party","shape-rendering":"geometricPrecision",children:[r("polygon",{points:`${e+6.6},9 ${e+11.4},9 ${e+9},3.8`,fill:"#5aa9e6"}),r("rect",{x:e+7.5,y:"6.8",width:"3",height:"0.6",fill:"#ffd166"}),r("rect",{x:e+8.25,y:"5.2",width:"1.5",height:"0.5",fill:"#ffd166"}),r("circle",{cx:e+9,cy:"3.6",r:"0.8",fill:"#f28ab2"})]})}function Zy({sprite:e,p:t,hat:n,season:i,ghost:l}){const a=(t==null?void 0:t.Headwear)&&!n,s=(t==null?void 0:t.snowcap)&&i==="winter"&&!n&&!l;return!a&&!s&&!n?null:r("g",{class:"tama-hat-seat",style:"transform-box: view-box",transform:gg(e),children:[a&&r(t.Headwear,{x0:0}),s&&r("rect",{class:"tama-snowcap",x:"3",y:"8.4",width:"12",height:"0.7",rx:"0.3",fill:"#f4f8fb"}),n==="santa"&&r(pd,{x0:0}),n==="party"&&r(md,{x0:0})]})}function Xy({x0:e}){const t=e+2.2,n=e+15.8,i="q-0.85 1.1 -1.7 0 ".repeat(8);return r("g",{class:"tama-ghost","shape-rendering":"geometricPrecision",children:[r("path",{fill:"#f5f5f7",d:`M${t} 17.6 V10.4 Q${t} 7.6 ${(t+n)/2} 7.6 Q${n} 7.6 ${n} 10.4 V17.6 ${i}Z`}),r("ellipse",{cx:e+5.6,cy:"11.6",rx:"0.7",ry:"1",fill:we}),r("ellipse",{cx:e+12.4,cy:"11.6",rx:"0.7",ry:"1",fill:we}),r("ellipse",{cx:e+9,cy:"14",rx:"0.6",ry:"0.8",fill:we})]})}function e2({x0:e}){const t=e+16.4;return r("g",{class:"tama-pail","shape-rendering":"geometricPrecision",children:[r("path",{d:`M${t+.3} 13.8 Q${t+1.8} 11.2 ${t+3.3} 13.8`,fill:"none",stroke:"#3a2a1a","stroke-width":"0.35"}),r("rect",{x:t+.9,y:"13.1",width:"0.7",height:"0.7",fill:"#e05252"}),r("rect",{x:t+1.9,y:"12.9",width:"0.7",height:"0.7",fill:"#7fb6e6"}),r("rect",{x:t,y:"13.6",width:"3.6",height:"3.2",rx:"1.2",fill:"#ef8a2c"}),r("path",{fill:"#3a1e0e",d:`M${t+.7} 14.9 l0.5 -0.7 l0.5 0.7z M${t+2} 14.9 l0.5 -0.7 l0.5 0.7z M${t+.7} 15.5 h2.2 l-0.4 0.6 h-1.4z`})]})}const t2=[[5,4,"#ffd166",0],[22,2.6,"#f28ab2",-.9]],n2=[[17.4,2.8,"#ffd166",0],[24.6,2.1,"#f28ab2",-.6],[31.2,3,"#7fb6e6",-1.2]];function r2({clear:e}){const t=(n,i,l,a)=>r("g",{class:"tama-firework",style:{animationDelay:`${a}s`},fill:l,children:[[0,45,90,135,180,225,270,315].map(s=>{const o=s*Math.PI/180;return r("rect",{x:n+Math.cos(o)*1.8-.25,y:i+Math.sin(o)*1.8-.25,width:"0.5",height:"0.5"},s)}),r("rect",{x:n-.25,y:i-.25,width:"0.5",height:"0.5"})]},n);return r("g",{children:(e?n2:t2).map(([n,i,l,a])=>t(n,i,l,a))})}const bo=["#ffd166","#f28ab2","#7fb6e6","#9be38f","#c792ea"];function i2(){return r("g",{class:"tama-confetti",children:[[2.5,0],[9,-.6],[15,-1.4],[21,-.3],[27,-1.9],[32,-1]].map(([e,t],n)=>r("rect",{class:"tama-fall",x:e,y:"-1",width:"0.6",height:"0.6",fill:bo[n%bo.length],style:{animationDelay:`${t}s`}},e))})}function l2({mood:e}){return e==="furious"?r("g",{class:"tama-errors",fill:"#e05252",children:[r("rect",{x:"24",y:"7",width:"4.4",height:"0.6"}),r("rect",{x:"24",y:"8.4",width:"6.2",height:"0.6"}),r("rect",{x:"24.8",y:"9.8",width:"3.6",height:"0.6"}),r("rect",{x:"29.4",y:"9.8",width:"0.6",height:"0.6",fill:"#ffd166"})]}):r("g",{children:[r("rect",{x:"24",y:"7",width:"4.4",height:"0.6",fill:"var(--accent)"}),e==="grumpy"?r("rect",{class:"tama-red-line",x:"24",y:"8.4",width:"3",height:"0.6",fill:"#e05252"}):r("rect",{x:"24",y:"8.4",width:"3",height:"0.6",fill:"#7fbf7f"}),r("rect",{x:"24.8",y:"9.8",width:"3.4",height:"0.6",fill:"#c792ea"}),r("rect",{class:"tama-cursor",x:"28.6",y:"9.8",width:"0.6",height:"0.6",fill:"#e6e9ef"})]})}function a2({activity:e,occasion:t,coffee:n,ringing:i,keyboard:l=!0,mood:a="calm",screen:s=null,dish:o,mugHeld:u=!1}){switch(e){case"sleep":return i?null:r("g",{fill:"var(--fg-2)","font-family":"var(--mono)","font-weight":"700",children:[r("text",{class:"tama-z",x:"26",y:"10","font-size":"4",children:"z"}),r("text",{class:"tama-z tama-z2",x:"29",y:"7","font-size":"5",children:"Z"})]});case"coffee":return r("g",{children:!u&&r(cd,{})});case"code":return r("g",{children:[r("g",{class:"tama-chair",fill:"#4c525c",children:[r("rect",{x:"1.6",y:"9.6",width:"1.6",height:"8.4",rx:"0.5"}),r("rect",{x:"3.2",y:"16.9",width:"15",height:"1.3",rx:"0.4"}),r("rect",{x:"10",y:"18.2",width:"1.2",height:"0.8"}),r("rect",{x:"7",y:"18.6",width:"7.2",height:"0.5",rx:"0.25"})]}),r("g",{class:"tama-desk",children:[r("rect",{x:"20.2",y:"13.2",width:"13.6",height:"0.9",fill:"#8b6a4e"}),r("rect",{x:"21",y:"14.1",width:"0.9",height:"4.9",fill:"#6f533c"}),r("rect",{x:"32.2",y:"14.1",width:"0.9",height:"4.9",fill:"#6f533c"}),r("rect",{x:"26.9",y:"12",width:"1.2",height:"1.2",fill:"var(--fg-3)"}),r("rect",{x:"23",y:"5.6",width:"9",height:"6.4",rx:"0.4",fill:a==="furious"?"#2a1416":"#1d2026",stroke:"var(--fg-3)","stroke-width":"0.3"}),s||r(l2,{mood:a}),l&&r("rect",{x:"20.4",y:"12.6",width:"4.2",height:"0.6",rx:"0.2",fill:"#c9ced6"})]}),n&&r("g",{class:"tama-desk-mug",children:[r("rect",{class:"tama-steam",x:"25.2",y:"9.4",width:"0.4",height:"1.4",fill:"var(--fg-3)"}),r("rect",{class:"tama-steam tama-steam2",x:"25.9",y:"8.8",width:"0.4",height:"1.4",fill:"var(--fg-3)"}),r("g",{fill:"#efe6d8",children:[r("rect",{x:"24.9",y:"11.3",width:"1.5",height:"1.9",rx:"0.25"}),r("rect",{x:"26.4",y:"11.8",width:"0.5",height:"0.35"}),r("rect",{x:"26.6",y:"11.8",width:"0.3",height:"1"}),r("rect",{x:"26.4",y:"12.5",width:"0.5",height:"0.35"})]}),r("rect",{x:"24.9",y:"11.3",width:"1.5",height:"0.45",fill:"#7a4e2d"})]})]});case"read":return r("g",{children:[r("ellipse",{class:"tama-glow",cx:"28",cy:"19",rx:"9",ry:"2.4",fill:"#f0a24a",opacity:"0.18"}),r("g",{class:"tama-fire",children:[r("rect",{x:"23.4",y:"6",width:"10.6",height:"1.1",fill:"#8a7a6a"}),r("rect",{x:"24.2",y:"7.1",width:"9.8",height:"11.9",fill:"#7b4a3a"}),r("g",{fill:"#6a3e30",children:[r("rect",{x:"24.2",y:"9.4",width:"9.8",height:"0.3"}),r("rect",{x:"24.2",y:"11.8",width:"9.8",height:"0.3"}),r("rect",{x:"24.2",y:"14.2",width:"9.8",height:"0.3"}),r("rect",{x:"24.2",y:"16.6",width:"9.8",height:"0.3"})]}),r("rect",{x:"25.8",y:"11",width:"6.6",height:"8",rx:"2.4",fill:"#1a1110"}),r("path",{class:"tama-flame",d:"M27.2 19 q-0.6 -2.6 1 -4.4 q0.2 1.6 1 2.2 q0.4 -1.4 1.4 -2.4 q1 2.6 0.2 4.6z",fill:"#f08a3c"}),r("path",{class:"tama-flame tama-flame2",d:"M28 19 q-0.2 -1.6 0.9 -2.8 q0.3 1.1 0.9 1.4 q0.5 -0.8 0.6 -1.4 q0.9 1.6 0.2 2.8z",fill:"#ffd166"}),r("rect",{x:"26.6",y:"18.4",width:"5",height:"0.6",rx:"0.3",fill:"#5a3a26"})]}),t==="yearend"&&r(Yy,{}),t==="yearend"&&r(Qy,{}),r("g",{class:"tama-chair",fill:"#8e3b3b",children:[r("rect",{x:"1",y:"8.6",width:"3.2",height:"9.6",rx:"1"}),r("rect",{x:"3.6",y:"16.8",width:"16.8",height:"1.5",rx:"0.6"})]}),r("g",{class:"tama-chair-legs",fill:"#4a2f22",children:[r("rect",{x:"1.5",y:"18.2",width:"0.9",height:"0.8"}),r("rect",{x:"5",y:"18.2",width:"0.9",height:"0.8"}),r("rect",{x:"16.4",y:"18.2",width:"0.9",height:"0.8"})]})]});case"eat":return r(B0,{dish:o});default:return null}}function s2({p:e,season:t,trick:n,critter:i,from:l}){const a=r(e.Behind,{season:t,trick:n,critter:i,from:l});return e.outdoors?r("g",{children:[r(Vy,{season:t,night:n}),a]}):a}function o2({activity:e}){return e!=="read"?null:r("g",{children:[r("rect",{class:"tama-chair",x:"17.4",y:"13.6",width:"3.6",height:"4.7",rx:"0.8",fill:"#7a3030"}),r("rect",{class:"tama-chair-legs",x:"19.6",y:"18.2",width:"0.9",height:"0.8",fill:"#4a2f22"}),r("g",{class:"tama-book",children:[r("rect",{x:"17.4",y:"10.6",width:"2.9",height:"3.4",fill:"#f2ece0"}),r("rect",{x:"20.3",y:"10.6",width:"2.9",height:"3.4",fill:"#ebe3d3"}),r("g",{fill:"#c9bfae",children:[r("rect",{x:"17.9",y:"11.4",width:"1.9",height:"0.3"}),r("rect",{x:"17.9",y:"12.3",width:"1.6",height:"0.3"}),r("rect",{x:"20.8",y:"11.4",width:"1.9",height:"0.3"}),r("rect",{x:"20.8",y:"12.3",width:"1.5",height:"0.3"})]}),r("rect",{class:"tama-page",x:"20.3",y:"10.6",width:"2.9",height:"3.4",fill:"#f6f1e6"}),r("rect",{x:"20.15",y:"10.6",width:"0.3",height:"3.4",fill:"#b9ae9b"})]})]})}function c2({x0:e,mood:t}){return r("g",{class:"tama-mood",children:[t==="furious"&&r("g",{class:"tama-flush",fill:"#ff3b2f",opacity:"0.5",children:[r("rect",{x:e+3,y:K,width:"12",height:"4"}),r("rect",{x:e+1,y:K+4,width:"16",height:"2"}),r("rect",{x:e+3,y:K+6,width:"12",height:"2"})]}),r("g",{class:"tama-brows",fill:we,children:[r("rect",{x:e+5,y:K+2.9,width:"1",height:"1.1"}),r("rect",{x:e+12,y:K+2.9,width:"1",height:"1.1"}),r("rect",{x:e+3.9,y:K+1.5,width:"1.3",height:"0.55"}),r("rect",{x:e+5.1,y:K+2.05,width:"1.3",height:"0.55"}),r("rect",{x:e+11.6,y:K+2.05,width:"1.3",height:"0.55"}),r("rect",{x:e+12.8,y:K+1.5,width:"1.3",height:"0.55"})]}),t==="furious"&&r("path",{class:"tama-scowl",fill:"none",stroke:we,"stroke-width":"0.35","shape-rendering":"geometricPrecision",d:`M${e+7.4} ${K+6} l0.8 -0.6 l0.8 0.6 l0.8 -0.6 l0.8 0.6`}),r("g",{fill:Ht,children:[r("rect",{class:"tama-hand",x:"20.7",y:"11.9",width:"1.1",height:"0.8"}),r("rect",{class:"tama-hand tama-hand2",x:"22.7",y:"11.9",width:"1.1",height:"0.8"})]}),r("g",{class:"tama-clack",fill:"#e6e9ef",children:[r("rect",{x:"21.1",y:"10.9",width:"0.25",height:"0.55"}),r("rect",{x:"23.3",y:"10.8",width:"0.25",height:"0.55"})]})]})}function u2({mood:e,x0:t,coffee:n,hat:i,headDy:l}){return e!=="furious"?null:r("g",{children:[r("g",{fill:"#c9ced6",children:[r("rect",{class:"tama-flying-key",x:"21.4",y:"12",width:"0.7",height:"0.7"}),r("rect",{class:"tama-flying-key tama-flying-key2",x:"23.1",y:"12",width:"0.7",height:"0.7"}),r("rect",{class:"tama-flying-key tama-flying-key3",x:"22.3",y:"12",width:"0.6",height:"0.6"})]}),r("g",{fill:"#8b93a1","shape-rendering":"geometricPrecision",children:[r("circle",{class:"tama-smoke",cx:"21.6",cy:"12.2",r:"0.5"}),r("circle",{class:"tama-smoke tama-smoke2",cx:"23.4",cy:"12.2",r:"0.45"})]}),!i&&r(Nn,{dy:l,children:r("g",{class:"tama-shimmer",fill:"none",stroke:"#ff8a5c","stroke-width":"0.3",opacity:"0.8","shape-rendering":"geometricPrecision",children:[6,9,12].map((a,s)=>r("path",{class:s===1?"tama-shimmer2":void 0,d:`M${t+a} ${s===1?7.2:7.6} q0.5 -0.7 0 -1.4 q-0.5 -0.7 0 -1.4`},a))})}),n&&r("g",{class:"tama-spill",fill:"#7a4e2d","shape-rendering":"geometricPrecision",children:[r("circle",{cx:"25.4",cy:"11.1",r:"0.25"}),r("circle",{class:"tama-spill2",cx:"26",cy:"11",r:"0.22"})]})]})}const d2=new Set(["bell","done","merged","api","ctx"]);function h2({activity:e,view:t,kind:n,duty:i,working:l,walled:a,mirroring:s}){return e==="nap"?r(Ry,{...a}):t.atDesk?n==="done"?r(xy,{}):n==="merged"?r(Sy,{}):n==="ci"?r($y,{}):n==="api"?r(Py,{}):n==="ctx"?r(My,{pct:i==null?void 0:i.pct,cost:i==null?void 0:i.cost}):s?r(Dy,{n:l}):null:null}function f2({kind:e}){return r("g",{children:[e==="bell"&&r(wy,{}),e==="ctx"&&r(Ay,{}),e==="update"&&r(By,{})]})}function p2({activity:e,season:t="summer",occasion:n=null,coffee:i=!1,mood:l="calm",petted:a=!1,petKey:s=0,duty:o=null,working:u,walled:c=null,party:f=!1,dish:d,trick:p=!1,critter:h=di[0]}){var Me;const m=(o==null?void 0:o.kind)||null,b=zu(e,m),{atDesk:x}=b,w=p,C=sy[e],y=C&&p?{...C,...C.trick}:C,{x0:g,sitting:$=!1,lift:v=0}=(y==null?void 0:y.pose)||zy[e]||jy,E=y?y.jack:Jy[e],A=h.sprite,T=A&&va(A,{x0:g,sitting:$,height:w?ru:wa}),S=T?N(T.top-K):0,R=e==="sleep"||e==="nap",F=m==="bell"&&R,q=R&&!F,L=m==="bell"&&(x||e==="nap"),I=w||q?null:x||d2.has(m)?m:null,O=!w&&!q&&(I==="done"||I==="merged"),Q=I==="merged",M=f&&!w&&!q?"party":n==="yearend"?"santa":n==="newyear"?"party":null,z=b.moodShown&&((Me=wn[l])==null?void 0:Me.rank)>0,k=b.showsPanes&&u!=null&&!z,W=h2({activity:e,view:b,kind:m,duty:o,working:u,walled:c,mirroring:k}),Z=w?r(Xy,{x0:g}):A?null:z?r(c2,{x0:g,mood:l}):q?r(Jl,{closed:!0,x0:g}):O?r(mo,{x0:g}):I==="api"?r(uy,{x0:g}):I==="update"?r(Ny,{x0:g}):!I&&(y!=null&&y.smile)?r(mo,{x0:g}):r(Jl,{x0:g}),_=!A||w||q||z?null:O?"happy":I==="api"?"x":I==="update"?"down":I==="ctx"?"worried":!I&&(y!=null&&y.smile)?"happy":null,X=A&&(y==null?void 0:y.Held)===Ka?"goggles":A&&(y==null?void 0:y.Held)===Va?"scarf":null,he=A?Wy[e]??null:null,fe=he==="spoon"||he==="leash"?bg(A,he,T):null,qe=he==="bass"?Os(T,[g+uo.dx,uo.y]):null,Ae=A&&(z?gy:L?yy:null),ce=qe??(Ae?Os(T,Ae):null);return r("svg",{viewBox:"0 0 34 24","shape-rendering":"crispEdges","aria-hidden":"true","data-activity":e,"data-occasion":n||void 0,"data-mood":z?l:void 0,"data-duty":m||void 0,"data-pose":I||void 0,"data-urgent":o!=null&&o.urgent?"":void 0,"data-working":k?Math.min(u,4):void 0,"data-critter":A?h.id:void 0,"data-tempo":y==null?void 0:y.tempo,"data-stride":y!=null&&y.stride?"":void 0,style:y&&`--tama-tempo: ${y.tempo}s`,children:[r("rect",{x:"0",y:"19",width:"34",height:"0.4",fill:"var(--line)"}),(n==="newyear"||Q)&&r(r2,{clear:!!o}),y?r(s2,{p:y,season:t,trick:p,critter:h,from:fe}):r(a2,{activity:e==="nap"?"code":e,occasion:n,coffee:i,ringing:F,keyboard:!(L||x&&m==="ctx"),mood:z?l:"calm",screen:W,dish:d,mugHeld:he==="mug"}),n==="halloween"&&E&&r(Gy,{...E}),r("g",{transform:v?`translate(0 ${-v})`:void 0,children:r("g",{class:`tama-creature${a?" tama-hop":""}`,children:[A?r("g",{class:"tama-critter",style:"transform-box: view-box",transform:`translate(${T.tx} ${T.ty}) scale(${T.scale})`,children:[r(Wi,{sprite:A,mood:z?l:"calm",asleep:q,face:_,startle:I==="bell"&&!L,worn:X,holding:he,tip:ce,paws:!!(y!=null&&y.paws),cheer:x&&O,seated:$,stride:!!(y!=null&&y.stride),children:qe&&r("g",{style:"transform-box: view-box",transform:`scale(${1/T.scale}) translate(${-T.tx} ${-T.ty})`,children:r(ad,{x0:g,limb:A.limb})})}),r(Zy,{sprite:A,p:y,hat:M,season:t,ghost:w}),he&&r(sd,{sprite:A,kind:he,scale:T.scale})]}):r(rt,{cells:y!=null&&y.paws?Hy:fd,cls:"tama-body",x0:g}),Z,(y==null?void 0:y.Held)&&!(A&&(Uy.has(y.Held)||he))&&r(y.Held,{x0:g}),he==="spoon"&&r(dd,{x0:g,from:fe}),he==="controller"&&r("g",{transform:`translate(0 ${Math.min(T.drop,.8)})`,children:r(od,{x0:g,limb:A.limb})}),!A&&r(Nn,{dy:S,children:(y==null?void 0:y.Headwear)&&!M&&r(y.Headwear,{x0:g})}),r(Nn,{dy:S,children:I==="api"&&r(hy,{x0:g})}),!A&&I==="ctx"&&r(dy,{x0:g}),!A&&x&&O&&r(py,{x0:g}),x&&I==="ci"&&r(Cy,{}),!A&&L&&r(my,{}),A&&z&&r(by,{limb:A.limb}),A&&L&&r(ky,{limb:A.limb}),!A&&r(Nn,{dy:S,children:I==="bell"&&!L&&r(fy,{x0:g})}),!A&&!$&&r(rt,{cells:Vl[0],cls:"tama-legs-a",x0:g,y0:Gl}),!A&&(y==null?void 0:y.stride)&&r(rt,{cells:Vl[1],cls:"tama-legs-b",x0:g,y0:Gl}),w&&(y==null?void 0:y.pail)&&r(e2,{x0:g}),!A&&r(Nn,{dy:S,children:[(y==null?void 0:y.snowcap)&&t==="winter"&&!M&&!w&&r("rect",{class:"tama-snowcap",x:g+3,y:"8.4",width:"12",height:"0.7",rx:"0.3",fill:"#f4f8fb"}),M==="santa"&&r(pd,{x0:g}),M==="party"&&r(md,{x0:g})]})]},s)}),(y==null?void 0:y.Front)&&r(y.Front,{}),r(o2,{activity:e}),(x||L)&&r(f2,{kind:m}),e==="nap"&&!F&&r(Fy,{}),F&&e==="sleep"&&r(vy,{}),O&&r(_y,{}),z&&r(u2,{mood:l,x0:g,coffee:i,hat:M,headDy:S}),(n==="newyear"||Q)&&r(i2,{}),o&&r(cy,{kind:m,label:o.label,urgent:o.urgent,more:o.more,x0:g}),a&&r("g",{transform:`translate(${g-8} 0)`,children:r("path",{class:"tama-heart",fill:"#e8657a","shape-rendering":"geometricPrecision",d:"M17 7.2 l-2.3 -2.3 a1.25 1.25 0 0 1 2.3 -1.7 a1.25 1.25 0 0 1 2.3 1.7z"})},`heart-${s}`)]})}const m2=Vt(()=>nu(hu())),gd=e=>e.map(t=>[t.since*1e3,t.until==null?1/0:t.until*1e3]),ko=e=>({...Zu(Ta(),e),walls:gd(fa.value)});function g2(){const[e,t]=B(()=>new Date),[n,i]=B(0),[l,a]=B(!1),o=rl(()=>{const O=Ta();return JSON.stringify([O.merged??null,O.furious??null,fa.value])}).value,[u,c,f]=JSON.parse(o),d={...Zu({merged:u,furious:c},e),walls:gd(f)},p=ne(o);j(()=>{if(p.current!==o){p.current=o,t(new Date);return}const O=setTimeout(()=>t(new Date),Qu(e,d)+50);return()=>clearTimeout(O)},[e,o]),j(()=>{const O=setInterval(()=>{const Q=new Date;t(M=>Xs(Q,ko(Q))===Xs(M,ko(M))?M:Q)},6e4);return()=>clearInterval(O)},[]),j(()=>{if(!l)return;const O=setTimeout(()=>a(!1),900);return()=>clearTimeout(O)},[l,n]);const h=_c(0);j(()=>{const O=setInterval(()=>{h.value+=1},6e4);return()=>clearInterval(O)},[]),j(()=>{v0()},[]);const m=m2.value,b=rl(()=>{var z;h.value;const O=(z=Oi.value)==null?void 0:z.plan,Q=g0(O,Date.now()/1e3),M=Q.account&&Sn()?gn(Q.account):null;return JSON.stringify([Q.mood,y0(Q,M)])}),[x,w]=JSON.parse(b.value);j(()=>{x==="furious"&&pu("furious",Yu(new Date))},[x,Vi(e)]);const C=rl(()=>{h.value;const O=Date.now()/1e3,Q=K1({windows:de.value||[],alerts:er.value||[],dismissedAlertIds:nr.value,dismissedNeedsPids:ht.value,dismissedReadyPids:ft.value,selectedPid:Nu(ke.value),parties:hr.value,update:ha.value,nowSec:O}),M=xc.value;return JSON.stringify({items:Q,more:V1(Q),wall:M&&J1(M.until,O),working:er.value===null?null:wu(de.value).length})}),y=JSON.parse(C.value),g=y.items[0]||null,$=dr(e,d),v=u0(e,d),E=Gi(e),A=nd(e),T=zu($.id,g==null?void 0:g.kind),S=eo($,T.moodShown?x:"calm"),R=[...y.wall&&Vu(e,d)?[Q1(y.wall)]:[],...y.items.map(O=>O.phrase),...T.showsPanes&&y.working?[`${kn(y.working,"agent")} working`]:[],...T.moodShown&&w?[w]:[],...A?[A]:[],...v?[`up next at ${b0(v.at)}: ${eo(v.activity)}`]:[]],F=`${m.sprite?m.name:"Claude"} is ${S} (${Wl($.from)}–${Wl($.to)})${R.map(O=>` · ${O}`).join("")}`+(g!=null&&g.target?` · click to ${g.target.says}`:"");function q(){i(O=>O+1),a(!0)}const L=ne(g);L.current=g;const[I]=B(()=>F0({target:()=>{var O;return(O=L.current)==null?void 0:O.target},pet:q}));return j(()=>()=>I.dispose(),[]),r("button",{type:"button",class:"tama",title:F,"aria-label":F,onClick:I.onClick,onDblClick:I.onDblClick,children:r(p2,{activity:$.id,dish:$.dish,trick:!!$.trick,season:wr(e),occasion:E==null?void 0:E.id,coffee:!!$.coffee,mood:x,petted:l,petKey:n,duty:g&&{kind:g.kind,label:g.label,urgent:!!g.urgent,more:y.more,pct:g.pct,cost:g.cost},working:y.working,walled:y.wall,party:y.items.some(O=>O.kind==="merged"),critter:m})})}const wo=["session","week_all","week_opus","week_sonnet"];function y2(e){const t=Object.keys(e).filter(n=>!wo.includes(n)).sort();return[...wo,...t].filter(n=>e[n]).map(n=>({key:n,label:ja(n),m:e[n]}))}function b2(e){const t=at.value.map(i=>i.id).filter(i=>e.includes(i)),n=e.filter(i=>!t.includes(i)).sort();return[...t,...n]}function k2(e,t){return e?b2(Object.keys(e)).map(n=>{const i=e[n]||{},l=i.available&&i.meters?y2(i.meters):[],a=l.length>0,s=a?l.reduce((o,u)=>(u.m.percent||0)>(o.m.percent||0)?u:o):null;return{id:n,label:gn(n),available:a,stale:a&&Ba(i,t),fetchedAt:i.fetched_at||null,meters:l,headline:s}}):[]}function w2(e){const t=(e.meters||[]).filter(n=>n!==e.headline);return{hot:t.filter(n=>n.m.hot),blow:t.filter(n=>!n.m.hot&&za(n.m))}}const v2=48*3600;function yd(e){return e==="week_fable"||e.startsWith("week_fable_")}function _2(e,t){const n=(e==null?void 0:e.available)&&e.meters||{},i=Object.keys(n).find(yd),l=i&&n[i];if(!l||l.projected_percent==null||!l.resets_at)return!1;const a=l.resets_at-t;return l.projected_percent<100&&a>0&&al!=null);if(!t.length)return null;const n=Math.min(...t),i=Math.max(...t);return i<=e.percent?null:{text:i-n>10?`→${n}–${i}%`:`→${i}%`,blow:za(e)}}function S2({a:e}){const{hot:t,blow:n}=w2(e);if(!t.length&&!n.length)return null;const i=[...t.map(l=>`${l.label}: burning 🔥`),...n.map(l=>`${l.label}: on track to hit its limit`)];return r("span",{class:`usage-acct-more${t.length?"":" blow"}`,title:[...i,"(click to show every meter)"].join(` -`),children:t.length?"🔥":"→"})}function $2({label:e,m:t,resets:n,pace:i}){const l=t.percent,a=l>=90?"danger":l>=70?"warn":"ok",s=[`${e} — ${l}% used. ${n||""}`,...i].join(` -`),o=x2(t);return r("div",{class:"usage-item",title:s,children:[r("span",{class:"usage-item-label",children:e}),r("span",{class:"usage-item-bar",children:r("span",{class:`usage-item-fill ${a}`,style:`width:${l}%`})}),r("b",{children:[l,"%"]}),o&&r("span",{class:`usage-item-proj${o.blow?" blow":""}`,children:o.text}),t.hot&&r("span",{class:"usage-item-hot",children:"🔥"})]})}const Ql=H(!1);function vd(){Ql.value=!0}function C2(e,t,n,i){const l=e.meters.map(({m:a})=>[`${a.label}: ${a.percent}% used`,kd(a.resets_at),...wd(a)].filter(Boolean).join(` - `));if(n){const a=n.verified?`resets ${vi(n.resets_at)}`:"not anchored";l.push(`poked ${vi(n.at)} → ${a}`)}if(i){const a=e.meters.find(({key:s})=>yd(s));a&&l.push(`💤 fable on pace for ${a.m.projected_percent}% at reset — burn it or lose it`)}return e.stale&&l.push(`⚠ stale — last updated ${Pe(e.fetchedAt)} ago`),l.push(t?"(click to collapse)":"(click to show every meter)"),[`account ${e.label}`,...l].join(` +`):[e.value],l=[];return i.forEach((a,s)=>{if(s&&l.push(r("br",{},`${n}b${s}`)),!t.cite){l.push(a);return}tg(a).forEach((o,u)=>{if(typeof o=="string"){l.push(o);return}const c=t.cite(o);l.push(c==null?o.raw:r("span",{children:c},`${n}c${s}-${u}`))})}),l.length===1?l[0]:l}case"inlineCode":{const i=t.cite?ji(e.value):null,l=i?t.cite(i):null;return l!=null?r("span",{children:l},n):r("code",{class:"md-icode",children:e.value},n)}case"strong":return r("strong",{children:ze(e.children,t)},n);case"emphasis":return r("em",{children:ze(e.children,t)},n);case"delete":return r("del",{children:ze(e.children,t)},n);case"link":return r("a",{class:"md-link",href:so(e.url,t),target:"_blank",rel:"noopener",children:ze(e.children,{...t,cite:null})},n);case"image":return!cd.test(e.url)&&!t.resolveUrl?e.alt||e.url:r("img",{class:"md-img",src:so(e.url,t),alt:e.alt||""},n);case"break":return r("br",{},n);case"html":return e.value;case"footnoteReference":return r("sup",{children:["[",e.label||e.identifier,"]"]},n);default:return e.children?ze(e.children,t):e.value??null}}function B0(e,t,n){const i=(e.children||[]).map((l,a)=>l.type==="paragraph"&&!e.spread?ze(l.children,t):Va(l,t,a));return e.checked==null?r("li",{children:i},n):r("li",{class:"md-task",children:[r("input",{type:"checkbox",checked:e.checked,disabled:!0})," ",i]},n)}function z0(e,t,n){const i=e.align||[],[l,...a]=e.children,s=l.children.length,o=c=>i[c]?`text-align:${i[c]}`:void 0,u=c=>Array.from({length:s},(p,d)=>c.children[d]??null);return r("table",{class:"md-table",children:[r("thead",{children:r("tr",{children:u(l).map((c,p)=>r("th",{style:o(p),children:c?ze(c.children,t):""},p))})}),r("tbody",{children:a.map((c,p)=>r("tr",{children:u(c).map((d,f)=>r("td",{style:o(f),children:d?ze(d.children,t):""},f))},p))})]},n)}function Va(e,t,n,i){switch(e.type){case"paragraph":return r("p",{class:"md-p",children:ze(e.children,t)},n);case"heading":{const a=`h${t.demote?Math.min(e.depth+2,6):e.depth}`;return r(a,{class:`md-h md-h${e.depth}`,children:ze(e.children,t)},n)}case"code":return t.mermaid&&e.lang==="mermaid"?r(F0,{code:e.value},n):r("pre",{class:"md-code",children:r("code",{children:t.highlight&&e.lang?t.highlight(e.value,e.lang):e.value})},n);case"blockquote":{const l=t.meta&&(i==null?void 0:i.type)==="heading"?jl(e,t.src):null;return l?r("div",{class:"md-meta",children:l.map(([a,s],o)=>r("span",{class:"md-meta-kv","data-key":a,children:[r("span",{class:"md-meta-k",children:a}),r("span",{class:"md-meta-v",children:a==="refs"&&t.cite?lu(s).map((u,c)=>{const p=ji(u),d=p?t.cite(p):null;return r("span",{children:[c?", ":"",d??u]},c)}):s})]},o))},n):r("blockquote",{class:"md-quote",children:(e.children||[]).map((a,s)=>Va(a,t,s))},n)}case"list":{const l=(e.children||[]).map((a,s)=>B0(a,t,s));return e.ordered?r("ol",{class:"md-ol",start:e.start!==1?e.start:void 0,children:l},n):r("ul",{class:"md-ul",children:l},n)}case"thematicBreak":return r("hr",{class:"md-hr"},n);case"table":return z0(e,t,n);case"html":return r("p",{class:"md-p",children:e.value},n);default:return e.children?r("p",{class:"md-p",children:ze(e.children,t)},n):e.value?r("p",{class:"md-p",children:e.value},n):null}}function mr(e,t={}){const n=String(e||""),i={src:n,demote:t.demote??!0,softBreaks:t.softBreaks??"br",highlight:t.highlight??null,resolveUrl:t.resolveUrl??null,meta:t.meta??!1,cite:t.cite??null,mermaid:t.mermaid??!1},l=Wc(n,{extensions:[iu()],mdastExtensions:[Jc()]});return l.children.map((a,s)=>Va(a,i,s,l.children[s-1]))}const j0=2e3,Qr=H(!1);let Jl=!1;function H0({focus:e=!1}={}){Jl=e,Qr.value=!0}const q0=12e4;function U0({releases:e}){return e?e==="error"?r("div",{class:"update-note-muted",children:"couldn't load the release notes"}):e.length?e.map(t=>r("div",{class:"update-release",children:[r("div",{class:"update-release-head",children:t.heading}),r("div",{class:"update-release-body",children:mr(t.body)})]},t.heading)):r("div",{class:"update-note-muted",children:"no release notes recorded — CHANGELOG.md was unreadable on the last check"}):r("div",{class:"update-note-muted",children:"loading…"})}function W0(){const[e,t]=B(!1),[n,i]=B(null),l=Qr.value,a=M=>{Qr.value=M},[s,o]=B(null),u=te(null),c=te(null),p=br(()=>{Qr.value=!1},[]);Fi(u,l,p);const d=ma.value,f=(d==null?void 0:d.behind)||0,h=(d==null?void 0:d.ahead)||0;if(j(()=>{f||a(!1)},[f]),j(()=>{var T;if(!l)return;let M=!0;return o(null),Jl&&(Jl=!1,(T=c.current)==null||T.focus()),fetch("/api/update/status").then(async S=>{M&&o(S.ok?(await S.json()).releases||[]:"error")}).catch(()=>{M&&o("error")}),()=>{M=!1}},[l]),!d||!f&&!d.running&&!e&&!n)return null;function m(){a(!l)}async function b(){const M=Date.now()+q0;for(;Date.now()setTimeout(S,j0));let T;try{const S=await fetch("/api/update/status");if(!S.ok)continue;T=await S.json()}catch{continue}if(!T.running)return T.behind===0?t(!1):(t(!1),i((T.log||[]).filter(Boolean).slice(-3).join(` +`)||"update exited without applying — see ~/.config/periscope/update.log"))}t(!1),i("no response for 2 minutes — periscope may not have come back up.\ncheck `bin/periscope status` and ~/.config/periscope/update.log")}async function x(){if(a(!1),i(null),t(!0),!await ie("update","/api/update",{method:"POST"}))return t(!1);b()}const w=e||d.running,C=d.behind,y=d.target,g=`${y} is out — ${wn(C,"commit")} newer than this checkout`,$=C>0&&h>0,v=`${wn(h,"local commit")} not in ${y} — the update's fast-forward will refuse. Get them into a release, or off this checkout's main.`,E=n?`update failed: +${n}`:w?"updating — periscope will restart itself":$?`${g}, but ${v}`:`${g} — click to see what's new`;return r("div",{class:"pill-dd",ref:u,children:[r("button",{type:"button",class:`update-pill${w?" is-running":""}${n?" is-error":""}`,title:E,"aria-haspopup":"dialog","aria-expanded":l?"true":"false",disabled:w,onClick:w?void 0:m,children:w?"updating…":n?"⚠ update failed":`↑ ${y}${$?" ⚠":""}`}),r("div",{class:"tb-dd-menu update-menu",role:"dialog",hidden:!l,children:[r("div",{class:"update-menu-head",children:g}),$&&r("div",{class:"update-menu-warn",children:v}),n&&r("pre",{class:"update-menu-error",children:n}),r("div",{class:"update-notes",children:r(U0,{releases:s})}),r("button",{type:"button",class:"update-pill update-menu-go",ref:c,onClick:x,children:[n?"retry — ":"","pull, re-provision and restart"]})]})]})}function K0(e){const t=e.pid!=null&&(ce.value||[]).find(n=>String(n.pid)===String(e.pid))||null;if(e.action==="update")return H0({focus:!0});if(e.action==="needs")return $u(t);if(e.action==="ready")return Tu(t);if(e.action==="reveal")return jt(e.target);e.action==="party"&&M0(e.key),at(t)}const V0=250;function G0({target:e,pet:t,act:n=K0,schedule:i=setTimeout,cancel:l=clearTimeout}){let a=null;return{onClick(s){if(s.detail>1)return;const o=e();if(!o)return t();if(o.action==="update"){a=i(()=>n(o),V0);return}n(o)},onDblClick(){l(a),t()},dispose(){l(a)}}}const J0="geometricPrecision";function nn({x:e,y:t}){return r("g",{fill:"var(--fg-3)",children:[r("rect",{class:"tama-steam",x:e,y:t,width:"0.5",height:"1.6"}),r("rect",{class:"tama-steam tama-steam2",x:e+1.2,y:t-.6,width:"0.5",height:"1.6"})]})}function Ir({y:e=18.2}){return r("rect",{x:"25.8",y:e,width:"7.6",height:"0.8",rx:"0.4",fill:"#e8e2d4"})}const oo={ramen:()=>r("g",{children:[r("line",{x1:"29.2",y1:"10.4",x2:"28.1",y2:"15.6",stroke:"#b07a4f","stroke-width":"0.45"}),r("line",{x1:"30.4",y1:"10.7",x2:"29",y2:"15.6",stroke:"#b07a4f","stroke-width":"0.45"}),r("rect",{x:"26.8",y:"15.3",width:"4.9",height:"1.5",rx:"0.7",fill:"#f8f4ea"}),r("rect",{x:"26",y:"16.2",width:"6.5",height:"2.8",rx:"1.2",fill:"#e8e2d4"}),r("rect",{class:"tama-steam",x:"31.6",y:"12.2",width:"0.5",height:"1.6",fill:"var(--fg-3)"})]}),pizza:()=>r("g",{children:[r("rect",{x:"26",y:"12",width:"7.4",height:"5.4",fill:"#d8b384"}),r("rect",{x:"26.5",y:"12.5",width:"6.4",height:"4.4",fill:"#c9a06b"}),r("rect",{x:"25.6",y:"17.2",width:"8.2",height:"1.8",fill:"#c49a6c"}),r("ellipse",{cx:"29.7",cy:"17.3",rx:"3.6",ry:"1.1",fill:"#e0a94a"}),r("ellipse",{cx:"29.7",cy:"17.3",rx:"3",ry:"0.8",fill:"#f2c94c"}),r("path",{d:"M29.7 17.3 L33.4 17.1 L32.6 18.2 Z",fill:"#c49a6c"}),r("g",{fill:"#c0392b",children:[r("circle",{cx:"28",cy:"17.2",r:"0.35"}),r("circle",{cx:"29.6",cy:"16.9",r:"0.35"}),r("circle",{cx:"29.2",cy:"17.7",r:"0.35"}),r("circle",{cx:"31",cy:"16.9",r:"0.3"})]}),r(nn,{x:28.6,y:13.6})]}),burger:()=>r("g",{children:[r(Ir,{}),r("rect",{x:"27",y:"17.2",width:"5",height:"1",rx:"0.4",fill:"#d9913f"}),r("rect",{x:"26.8",y:"16.2",width:"5.4",height:"1.1",rx:"0.5",fill:"#6b3a22"}),r("path",{d:"M26.9 15.8 H32.1 V16.3 H29.2 L28.6 17 L28 16.3 H26.9 Z",fill:"#f2c94c"}),r("rect",{x:"27.1",y:"15.3",width:"4.8",height:"0.5",fill:"#e05252"}),r("rect",{x:"26.7",y:"14.9",width:"5.6",height:"0.5",rx:"0.25",fill:"#6fae5a"}),r("path",{d:"M26.9 15 Q26.9 12.4 29.5 12.4 Q32.1 12.4 32.1 15 Z",fill:"#e0a04a"}),r("g",{fill:"#f8f0d8",children:[r("rect",{x:"28.2",y:"13.4",width:"0.4",height:"0.25"}),r("rect",{x:"29.6",y:"13",width:"0.4",height:"0.25"}),r("rect",{x:"30.8",y:"13.6",width:"0.4",height:"0.25"})]})]}),sushi:()=>r("g",{children:[r("rect",{x:"25.4",y:"17.4",width:"8.4",height:"0.9",fill:"#c8955c"}),r("g",{fill:"#a5743f",children:[r("rect",{x:"26.2",y:"18.3",width:"0.8",height:"0.7"}),r("rect",{x:"32.2",y:"18.3",width:"0.8",height:"0.7"})]}),[[26,"#f28c6b"],[28.7,"#d64550"]].map(([e,t])=>r("g",{children:[r("rect",{x:e,y:"16.2",width:"2.4",height:"1.2",rx:"0.5",fill:"#f6f3ec"}),r("rect",{x:e-.2,y:"15.5",width:"2.8",height:"0.9",rx:"0.45",fill:t}),r("rect",{x:e+.7,y:"15.6",width:"0.15",height:"0.7",fill:"#fbd0c0",opacity:"0.8"}),r("rect",{x:e+1.5,y:"15.6",width:"0.15",height:"0.7",fill:"#fbd0c0",opacity:"0.8"})]},e)),r("rect",{x:"31.4",y:"15.6",width:"1.9",height:"1.8",rx:"0.3",fill:"#1f2a1f"}),r("rect",{x:"31.7",y:"15.9",width:"1.3",height:"1.2",fill:"#f6f3ec"}),r("rect",{x:"32.1",y:"16.25",width:"0.5",height:"0.5",fill:"#f28c6b"})]}),tacos:()=>r("g",{children:[r(Ir,{}),[26,29.8].map(e=>r("g",{children:[r("rect",{x:e+.2,y:"14.6",width:"3.2",height:"0.9",rx:"0.4",fill:"#6fae5a"}),r("rect",{x:e+.3,y:"15.2",width:"3",height:"0.5",fill:"#8a4b2a"}),r("rect",{x:e+.7,y:"14.4",width:"0.6",height:"0.6",fill:"#e05252"}),r("rect",{x:e+2.3,y:"14.3",width:"0.6",height:"0.6",fill:"#e05252"}),r("path",{d:`M${e} 15.4 h3.6 a1.8 2.6 0 0 1 -3.6 0 z`,fill:"#e8b84a"})]},e))]}),pasta:()=>r("g",{children:[r("line",{x1:"31.4",y1:"15.6",x2:"33",y2:"11.8",stroke:"#c9ced6","stroke-width":"0.35"}),r("rect",{x:"25.8",y:"17.6",width:"7.6",height:"1.2",rx:"0.6",fill:"#f8f4ea"}),r("rect",{x:"26.6",y:"18.4",width:"6",height:"0.6",fill:"#e8e2d4"}),r("path",{d:"M26.6 17.8 Q27 14.6 29.6 14.6 Q32.2 14.6 32.6 17.8 Z",fill:"#f2d27a"}),r("g",{fill:"none",stroke:"#d9b45a","stroke-width":"0.25",children:[r("path",{d:"M27.4 17.1 q0.6 -0.7 1.2 0 t1.2 0 t1.2 0 t1.2 0"}),r("path",{d:"M27.9 16.2 q0.6 -0.7 1.2 0 t1.2 0 t1.2 0"})]}),r("path",{d:"M28 15.4 Q29.6 14 31.2 15.4 Q29.6 16.2 28 15.4 Z",fill:"#c0392b"}),r("circle",{cx:"28.9",cy:"15",r:"0.55",fill:"#6b3a22"}),r("circle",{cx:"30.3",cy:"14.9",r:"0.55",fill:"#6b3a22"}),r(nn,{x:27.6,y:11.6})]}),salad:()=>r("g",{children:[r("line",{x1:"31.8",y1:"15.8",x2:"33.2",y2:"11.8",stroke:"#c9ced6","stroke-width":"0.35"}),r("ellipse",{cx:"27.8",cy:"15.6",rx:"1.4",ry:"1",fill:"#4f9a46"}),r("ellipse",{cx:"29.6",cy:"15.1",rx:"1.5",ry:"1.1",fill:"#6fae5a"}),r("ellipse",{cx:"31.4",cy:"15.6",rx:"1.3",ry:"0.9",fill:"#9be38f"}),r("circle",{cx:"28.6",cy:"15.2",r:"0.45",fill:"#e05252"}),r("circle",{cx:"30.9",cy:"15.4",r:"0.45",fill:"#e05252"}),r("rect",{x:"29.4",y:"14.3",width:"0.4",height:"1.2",fill:"#ef8a2c"}),r("path",{d:"M26 16 h7.2 q-0.4 3 -3.6 3 q-3.2 0 -3.6 -3 z",fill:"#b07a4f"}),r("rect",{x:"25.8",y:"15.8",width:"7.6",height:"0.5",rx:"0.25",fill:"#9a6a43"})]}),soup:()=>r("g",{children:[r("line",{x1:"31.4",y1:"15.8",x2:"33.4",y2:"12.4",stroke:"#c9ced6","stroke-width":"0.35"}),r("path",{d:"M26 15.6 h7 q-0.4 3.4 -3.5 3.4 q-3.1 0 -3.5 -3.4 z",fill:"#e8e2d4"}),r("ellipse",{cx:"29.5",cy:"15.7",rx:"3.4",ry:"0.55",fill:"#d9622b"}),r("g",{fill:"#e8b84a",children:[r("rect",{x:"28",y:"15.4",width:"0.6",height:"0.4"}),r("rect",{x:"30.2",y:"15.6",width:"0.6",height:"0.4"})]}),r("rect",{x:"25.6",y:"18.4",width:"7.8",height:"0.6",rx:"0.3",fill:"#d4ccbd"}),r(nn,{x:28.2,y:12.4})]}),roast:()=>r("g",{children:[r("ellipse",{cx:"29.6",cy:"18.4",rx:"4.1",ry:"0.7",fill:"#e8e2d4"}),r("g",{fill:"#4f9a46",children:[r("circle",{cx:"26",cy:"18.1",r:"0.4"}),r("circle",{cx:"33.2",cy:"18.1",r:"0.4"})]}),r("path",{d:"M26.6 18.2 Q26.4 14.6 29.6 14.4 Q32.8 14.6 32.6 18.2 Z",fill:"#b5733a"}),r("ellipse",{cx:"29",cy:"15.6",rx:"1.6",ry:"0.7",fill:"#d9913f"}),[[26.9,25.9],[32.3,33.3]].map(([e,t])=>r("g",{children:[r("ellipse",{cx:e,cy:"16.8",rx:"1",ry:"0.7",fill:"#a5642e"}),r("circle",{cx:t,cy:"16.3",r:"0.4",fill:"#f4efe6"})]},e)),r(nn,{x:28.4,y:11.4})]}),icecream:()=>r("g",{children:[r("rect",{x:"27.8",y:"18.4",width:"3.4",height:"0.6",rx:"0.3",fill:"#cfe3ef"}),r("rect",{x:"29.2",y:"16.6",width:"0.6",height:"1.8",fill:"#cfe3ef"}),r("circle",{cx:"28.3",cy:"13.8",r:"1.2",fill:"#f28ab2"}),r("circle",{cx:"30.7",cy:"13.8",r:"1.2",fill:"#9be38f"}),r("circle",{cx:"29.5",cy:"12.5",r:"1.2",fill:"#7a4e2d"}),r("path",{d:"M26.8 14.4 h5.4 q-0.4 2.4 -2.7 2.4 q-2.3 0 -2.7 -2.4z",fill:"#cfe3ef",opacity:"0.85"}),r("rect",{x:"31.4",y:"10.6",width:"0.7",height:"2.8",fill:"#e8b84a"}),r("path",{d:"M29.5 11 q0.3 -0.9 1 -1.2",fill:"none",stroke:"#4f7a2c","stroke-width":"0.2"}),r("circle",{cx:"29.5",cy:"11.1",r:"0.45",fill:"#e05252"})]}),pie:()=>r("g",{children:[r("ellipse",{cx:"29.6",cy:"18.4",rx:"4.1",ry:"0.7",fill:"#e8e2d4"}),r("rect",{x:"26.2",y:"17.3",width:"6.8",height:"0.9",fill:"#a5642e"}),r("ellipse",{cx:"29.6",cy:"18.2",rx:"3.4",ry:"0.5",fill:"#a5642e"}),r("ellipse",{cx:"29.6",cy:"17.3",rx:"3.4",ry:"1.1",fill:"#c8813a"}),r("ellipse",{cx:"29.6",cy:"17.3",rx:"2.8",ry:"0.8",fill:"#e07b39"}),r("path",{d:"M29.6 17.3 L33.1 17.2 L32.4 18.2 Z",fill:"#e8e2d4"}),r("g",{fill:"#fbf6ea",children:[r("circle",{cx:"28.2",cy:"17",r:"0.45"}),r("circle",{cx:"29.8",cy:"16.8",r:"0.45"}),r("circle",{cx:"28.9",cy:"17.6",r:"0.45"})]})]}),pancakes:()=>r("g",{children:[r(Ir,{}),[17.3,16.4,15.5,14.6].map((e,t)=>r("rect",{x:"26.6",y:e,width:"6",height:"0.95",rx:"0.45",fill:t%2?"#c8913a":"#d9a441"},e)),r("g",{fill:"#8a4b1a",children:[r("rect",{x:"26.9",y:"14.5",width:"5.4",height:"0.45",rx:"0.2"}),r("rect",{x:"27.4",y:"14.9",width:"0.45",height:"1.4",rx:"0.2"}),r("rect",{x:"31.5",y:"14.9",width:"0.45",height:"0.8",rx:"0.2"})]}),r("rect",{x:"28.9",y:"13.9",width:"1.4",height:"0.65",fill:"#fbe7a1"}),r(nn,{x:28.6,y:11})]}),waffles:()=>r("g",{children:[r(Ir,{}),r("rect",{x:"26.6",y:"15.8",width:"6",height:"2.4",rx:"0.3",fill:"#e0a94a"}),r("g",{fill:"#c8913a",children:[[27.8,29,30.2,31.4].map(e=>r("rect",{x:e,y:"15.8",width:"0.2",height:"2.4"},e)),r("rect",{x:"26.6",y:"16.6",width:"6",height:"0.2"}),r("rect",{x:"26.6",y:"17.4",width:"6",height:"0.2"})]}),r("circle",{cx:"28.4",cy:"15.6",r:"0.5",fill:"#3f5fb5"}),r("circle",{cx:"29.3",cy:"15.4",r:"0.5",fill:"#e05252"}),r("circle",{cx:"30.6",cy:"15.5",r:"0.6",fill:"#fbf6ea"})]}),eggs:()=>r("g",{children:[r("rect",{x:"31.6",y:"13.8",width:"2",height:"3.4",rx:"0.5",fill:"#d9a441",stroke:"#a5743f","stroke-width":"0.25"}),r("ellipse",{cx:"29.6",cy:"17.7",rx:"4.1",ry:"1.2",fill:"#f4f1ea"}),r("ellipse",{cx:"27.9",cy:"17.4",rx:"1.3",ry:"0.65",fill:"#ffffff"}),r("circle",{cx:"27.9",cy:"17.3",r:"0.42",fill:"#f2b52a"}),r("ellipse",{cx:"30.4",cy:"17.2",rx:"1.3",ry:"0.65",fill:"#ffffff"}),r("circle",{cx:"30.4",cy:"17.1",r:"0.42",fill:"#f2b52a"}),r("g",{fill:"none",stroke:"#b5452a","stroke-width":"0.45",children:[r("path",{d:"M26.6 18.2 q0.6 -0.4 1.2 0 t1.2 0 t1.2 0"}),r("path",{d:"M29.6 18.5 q0.6 -0.4 1.2 0 t1.2 0"})]})]})};function Q0({dish:e}){const t=oo[e]?e:"ramen";return r("g",{"data-dish":t,"shape-rendering":J0,children:oo[t]()})}const xe="geometricPrecision",co=e=>[...e].reverse().join("");function nt({cells:e,cls:t,x0:n,y0:i=V,w:l=1,h:a=2,fill:s=Ht}){return r("g",{class:t,children:e.map(({x:o,y:u})=>r("rect",{x:n+o*l,y:i+u*a,width:l+.02,height:a+.02,fill:s},`${o},${u}`))})}const ud=[od[0]],uo={body:qt(Tn),legs:qt(ud)},ho={body:qt(Tn.map(co)),legs:qt(ud.map(co))};function Y0({season:e,trick:t}){return r(K,{children:[r("g",{class:"tama-motion",fill:"var(--fg-3)",children:[r("rect",{x:"1",y:"10.6",width:"4",height:"0.5"}),r("rect",{x:"2.4",y:"13.6",width:"3.6",height:"0.5"}),r("rect",{x:"0.6",y:"16.6",width:"4.6",height:"0.5"})]}),e!=="winter"&&!t&&r("path",{class:"tama-sweat",d:"M25 7.6 q1.1 1.7 0 2.5 q-1.1 -0.8 0 -2.5z",fill:"#7fb6e6"})]})}function fo({cx:e}){return r("g",{children:[r("circle",{cx:e,cy:"16.7",r:"2.2",fill:"none",stroke:"#2b2f36","stroke-width":"0.55"}),r("g",{class:"tama-spokes",stroke:"#9aa3ae","stroke-width":"0.18",children:[r("line",{x1:e-2,y1:"16.7",x2:e+2,y2:"16.7"}),r("line",{x1:e,y1:"14.7",x2:e,y2:"18.7"}),r("line",{x1:e-1.4,y1:"15.3",x2:e+1.4,y2:"18.1"}),r("line",{x1:e-1.4,y1:"18.1",x2:e+1.4,y2:"15.3"})]}),r("circle",{cx:e,cy:"16.7",r:"0.35",fill:"#2b2f36"})]})}function Z0(){return r("g",{class:"tama-bike","shape-rendering":xe,children:[r("g",{class:"tama-motion",fill:"var(--fg-3)",children:[r("rect",{x:"0.6",y:"9.2",width:"3.4",height:"0.5"}),r("rect",{x:"1.4",y:"11.6",width:"3",height:"0.5"}),r("rect",{x:"0.4",y:"13.6",width:"3.6",height:"0.5"})]}),r(fo,{cx:7.2}),r(fo,{cx:26.8}),r("g",{fill:"none",stroke:"#2a9d8f","stroke-width":"0.5","stroke-linecap":"round",children:[r("path",{d:"M7.2 16.7 L15.5 16.9 L24.4 13.2 L26.8 16.7"}),r("path",{d:"M7.2 16.7 L11.6 13.8"})]}),r("path",{d:"M24.4 13.2 L24 11.4 M23.2 11.5 H25.4",fill:"none",stroke:"#2b2f36","stroke-width":"0.45","stroke-linecap":"round"}),r("circle",{cx:"15.5",cy:"16.9",r:"0.8",fill:"none",stroke:"#5a6472","stroke-width":"0.3"}),r("g",{class:"tama-crank",fill:"#2b2f36",children:[r("path",{d:"M14.5 15.9 L16.5 17.9",stroke:"#2b2f36","stroke-width":"0.3"}),r("rect",{x:"14",y:"15.6",width:"0.9",height:"0.4"}),r("rect",{x:"16.1",y:"17.8",width:"0.9",height:"0.4"})]})]})}function X0({x0:e}){return r("g",{class:"tama-helmet","shape-rendering":xe,children:[r("path",{d:`M${e+3.6} ${V+.5} Q${e+3.6} ${V-1.6} ${e+9} ${V-1.6} Q${e+14.4} ${V-1.6} ${e+14.4} ${V+.5} Z`,fill:"#e05252"}),r("g",{fill:"#8f2a2a",children:[6.4,8.5,10.6].map(t=>r("rect",{x:e+t,y:V-.9,width:"0.9",height:"0.45",rx:"0.2"},t))}),r("rect",{x:e+13.2,y:V+.1,width:"2.4",height:"0.5",rx:"0.25",fill:"#8f2a2a"})]})}const po={dx:18,y:11.7};function _n({limb:e,x:t,y:n,w:i,h:l,cls:a}){const s=e.style==="tentacle";return r("rect",{class:a,x:t,y:n,width:i,height:l,rx:s?l/2:.25,fill:e.color,stroke:e.outline||void 0,"stroke-width":e.outline?.25:void 0})}function dd({x0:e,limb:t}){return r("g",{class:"tama-bass","shape-rendering":xe,children:[r("path",{d:`M${e+9.6} 13.7 L${e+23} 9.6 L${e+23.3} 10.5 L${e+9.9} 14.6 Z`,fill:"#4a2c1a"}),r("g",{fill:"#efe6d8",children:[13.5,16.5,19.5].map(n=>r("circle",{cx:e+n,cy:14.15-.306*(n-9.75),r:"0.13"},n))}),r("path",{d:`M${e+23} 9.4 L${e+26.4} 8.2 L${e+26.7} 9.1 L${e+23.3} 10.7 Z`,fill:"#e3c48a"}),r("g",{fill:"#c9ced6",children:[23.9,24.7,25.5,26.2].map((n,i)=>r("circle",{cx:e+n,cy:9.1-i*.3,r:"0.25"},n))}),r("ellipse",{cx:e+5,cy:"15.3",rx:"3",ry:"2.1",fill:"#3f6fb5"}),r("ellipse",{cx:e+8.1,cy:"14.4",rx:"1.9",ry:"1.5",fill:"#3f6fb5"}),r("ellipse",{cx:e+9.4,cy:"13.4",rx:"1.1",ry:"0.6",fill:"#3f6fb5"}),r("ellipse",{cx:e+6.6,cy:"14.7",rx:"2",ry:"1.1",fill:"#f4f1ea"}),r("rect",{x:e+5.6,y:"14.1",width:"1.4",height:"0.9",rx:"0.2",fill:"#1d1f24"}),r("rect",{x:e+2.6,y:"14.9",width:"1.6",height:"0.7",fill:"#c9ced6"}),r("g",{stroke:"#e6e9ef","stroke-width":"0.1",children:[r("line",{x1:e+3.4,y1:"15.1",x2:e+23.1,y2:"9.9"}),r("line",{x1:e+3.4,y1:"15.4",x2:e+23.2,y2:"10.2"})]}),t?r(_n,{limb:t,x:e+7.3,y:14.5,w:1.3,h:1,cls:"tama-strum"}):r(K,{children:[r("rect",{x:e+17.5,y:"11.1",width:"1",height:"0.9",fill:Ht}),r("rect",{class:"tama-strum",x:e+7.4,y:"14.6",width:"1.1",height:"0.8",fill:Ht})]})]})}function mo({x:e,y:t,cls:n}){return r("g",{class:n,fill:"var(--fg-2)",children:[r("ellipse",{cx:e,cy:t+2.4,rx:"0.6",ry:"0.45"}),r("rect",{x:e+.35,y:t,width:"0.3",height:"2.4"}),r("path",{d:`M${e+.65} ${t} q1 0.5 0.6 1.6 q-0.1 -0.9 -0.6 -1`})]})}function ey(){return r("g",{class:"tama-amp","shape-rendering":xe,children:[r(mo,{x:24.4,y:6,cls:"tama-note"}),r(mo,{x:26.6,y:4.4,cls:"tama-note tama-note2"}),r("path",{d:"M9 17.2 C8.6 19, 12 18.9, 16 18.9 S26.4 18.9, 27.6 17.6",fill:"none",stroke:"#1d1f24","stroke-width":"0.3"}),r("rect",{x:"27.6",y:"12.6",width:"6",height:"6.4",rx:"0.3",fill:"#2b2f36"}),r("rect",{x:"27.6",y:"12.6",width:"6",height:"1.2",fill:"#3b404a"}),r("g",{fill:"#c9ced6",children:[28.4,29.3,30.2,31.1].map(e=>r("circle",{cx:e,cy:"13.2",r:"0.25"},e))}),r("circle",{cx:"32.8",cy:"13.2",r:"0.2",fill:"#e05252"}),r("rect",{x:"28",y:"14.2",width:"5.2",height:"4.4",fill:"#4a4f58"}),r("g",{class:"tama-speaker",children:[r("circle",{cx:"30.6",cy:"16.4",r:"1.8",fill:"#3b404a"}),r("circle",{cx:"30.6",cy:"16.4",r:"0.7",fill:"#2b2f36"})]})]})}const Ct=18,go="#6f93d6",ty=150,mt=e=>Math.round(e*1e4)/1e4;function ny({sprite:e}){const{scale:t,tx:n,ty:i}=Sa(e,{x0:Ct,sitting:!1}),l=Ct+8.5;return r("g",{class:"tama-critter",style:"transform-box: view-box",transform:`translate(${mt(2*l-n)} ${mt(i)}) scale(${mt(-t)} ${mt(t)})`,children:[r(Gi,{sprite:e,face:"happy",tint:ty,holding:"pint"}),r(hd,{sprite:e,kind:"pint",scale:t})]})}function hd({sprite:e,kind:t,scale:n}){if(!$a[t])return null;const[i,l]=qi(e,t),a=mt(1/n),s=(o,u)=>r("g",{style:"transform-box: view-box",transform:`translate(${i} ${l}) scale(${a}) ${o}`,children:u});return t==="pint"?s("translate(0 -11.5)",r(Ga,{x:0,cls:"tama-pint tama-clink"})):t==="mug"?s("scale(-1 1) translate(-30.1 -14.2)",r(pd,{})):t==="can"?s("translate(-17.8 -11.7)",r(md,{x0:0})):null}function Ga({x:e,cls:t}){return r("g",{class:t,children:[r("rect",{x:e,y:"10.4",width:"2",height:"2.8",fill:"#e8a92e"}),r("rect",{x:e+.3,y:"10.9",width:"0.3",height:"1.8",fill:"#ffd98a"}),r("rect",{x:e-.1,y:"9.8",width:"2.2",height:"0.9",rx:"0.4",fill:"#fbf6ea"})]})}function ry({x0:e}){return r(Ga,{x:e+15.2,cls:"tama-pint tama-clink"})}const iy=[["#ffd166",15.4],["#f28ab2",19.6],["#7fb6e6",23.8],["#9be38f",28],["#ffd166",32.2]];function ly({critter:e}){return r("g",{children:[r("path",{d:"M13.4 1.2 Q23.6 3.6 34 1.2",fill:"none",stroke:"var(--fg-3)","stroke-width":"0.2","shape-rendering":xe}),iy.map(([t,n],i)=>r("rect",{class:`tama-twinkle${i%2?" tama-twinkle2":""}`,x:n-.35,y:1.9+Math.sin((n-13.4)/6.5)*.9,width:"0.7",height:"0.9",rx:"0.3",fill:t},n)),r("g",{class:"tama-friend",children:e!=null&&e.sprite?r(ny,{sprite:e.sprite}):r(K,{children:[r(nt,{cells:ho.body,x0:Ct,fill:go}),r(nt,{cells:ho.legs,x0:Ct,y0:V+2*Tn.length,fill:go}),r("g",{fill:"none",stroke:we,"stroke-width":"0.45","stroke-linecap":"square",children:[r("path",{d:`M${Ct+3.8} ${V+3.5} l0.7 -0.9 l0.7 0.9`}),r("path",{d:`M${Ct+10.8} ${V+3.5} l0.7 -0.9 l0.7 0.9`})]}),r(Ga,{x:Ct+1.2,cls:"tama-pint tama-clink tama-clink2"})]})}),r("g",{class:"tama-cheers",fill:"#ffd166",children:[r("rect",{x:"18.1",y:"7.6",width:"0.4",height:"1.2"}),r("rect",{x:"16.6",y:"8.3",width:"0.9",height:"0.4"}),r("rect",{x:"19.1",y:"8.3",width:"0.9",height:"0.4"})]})]})}function ay({x:e}){const t=e+1.1,n=e+7.4,i=`q-${(n-t)/16} 0.55 -${(n-t)/8} 0 `.repeat(8);return r("g",{class:"tama-kid-sheet","shape-rendering":xe,children:[r("path",{fill:"#f5f5f7",d:`M${t} 18.8 V15.6 Q${t} 13.6 ${(t+n)/2} 13.6 Q${n} 13.6 ${n} 15.6 V18.8 ${i}Z`}),r("ellipse",{cx:e+3.1,cy:"15.6",rx:"0.35",ry:"0.5",fill:we}),r("ellipse",{cx:e+5.4,cy:"15.6",rx:"0.35",ry:"0.5",fill:we}),r("path",{d:`M${e+6.5} 17.2 q0.8 -1.2 1.6 0`,fill:"none",stroke:"#3a2a1a","stroke-width":"0.2"}),r("rect",{x:e+6.4,y:"17",width:"1.8",height:"1.5",rx:"0.5",fill:"#ef8a2c"})]})}function sy({x:e,sprite:t,costume:n}){const{scale:i,tx:l,ty:a}=Sa(t,{x0:e-4.25,sitting:!1,height:(n?su:xa)/2});return r("g",{class:"tama-critter",style:"transform-box: view-box",transform:`translate(${mt(l)} ${mt(a)}) scale(${mt(i)})`,children:r(Gi,{sprite:t})})}function yo({x:e,cls:t,costume:n,sprite:i}){return r("g",{class:t,children:[i?r(sy,{x:e,sprite:i,costume:n}):r(K,{children:[r(nt,{cells:uo.body,x0:e,y0:14,w:.5,h:1}),r(nt,{cells:uo.legs,x0:e,y0:18,w:.5,h:1})]}),n?r(ay,{x:e}):!i&&r("g",{fill:we,children:[r("rect",{x:e+2.5,y:"15",width:"0.5",height:"1"}),r("rect",{x:e+6,y:"15",width:"0.5",height:"1"})]})]})}function oy({trick:e=!1,critter:t}){return r("g",{children:[r(yo,{x:17.4,cls:"tama-kid",costume:e,sprite:t==null?void 0:t.sprite}),r(yo,{x:25.4,cls:"tama-kid tama-kid2",costume:e,sprite:t==null?void 0:t.sprite})]})}function cy(){return r("g",{children:[r("g",{fill:"#4d5f95",children:[r("rect",{x:"0.6",y:"8.4",width:"20.4",height:"9",rx:"1"}),r("rect",{x:"0.2",y:"13.4",width:"2.6",height:"5",rx:"0.8"})]}),r("rect",{x:"1",y:"16.6",width:"21",height:"1.6",rx:"0.6",fill:"#5f75b0"}),r("g",{fill:"#3a2a1a",children:[r("rect",{x:"1.6",y:"18.2",width:"0.9",height:"0.8"}),r("rect",{x:"20.2",y:"18.2",width:"0.9",height:"0.8"})]}),r("g",{class:"tama-tv",children:[r("rect",{x:"22.4",y:"15.6",width:"11.2",height:"3.4",fill:"#6f533c"}),r("rect",{x:"22.4",y:"17.1",width:"11.2",height:"0.3",fill:"#5a4230"}),r("rect",{x:"27.4",y:"14.6",width:"1.6",height:"1",fill:"#1d1f24"}),r("rect",{x:"23",y:"7.4",width:"10.4",height:"7.2",rx:"0.4",fill:"#1d1f24"}),r("rect",{x:"23.6",y:"8",width:"9.2",height:"6",fill:"#20304a"}),r("rect",{x:"23.6",y:"13",width:"9.2",height:"1",fill:"#4f9a46"}),r("rect",{x:"29.6",y:"10.8",width:"2.4",height:"0.5",fill:"#b5733a"}),r("circle",{class:"tama-twinkle",cx:"30.8",cy:"9.9",r:"0.35",fill:"#ffd166"}),r("rect",{class:"tama-hero",x:"25.2",y:"11.9",width:"0.8",height:"1.1",fill:"#e05252"})]})]})}const uy={style:"arm",color:Ht};function fd({x0:e,limb:t=uy}){return r("g",{class:"tama-controller","shape-rendering":xe,children:[r("rect",{x:e+6.6,y:"14.2",width:"4.8",height:"1.4",rx:"0.6",fill:"#3b404a"}),r("rect",{x:e+6.4,y:"14.6",width:"1.4",height:"1.6",rx:"0.6",fill:"#3b404a"}),r("rect",{x:e+10.2,y:"14.6",width:"1.4",height:"1.6",rx:"0.6",fill:"#3b404a"}),r("path",{d:`M${e+7.4} 14.9 h0.9 M${e+7.85} 14.45 v0.9`,stroke:"#c9ced6","stroke-width":"0.25"}),r("circle",{cx:e+10.2,cy:"14.7",r:"0.22",fill:"#e05252"}),r("circle",{cx:e+10.7,cy:"15.1",r:"0.22",fill:"#5aa9e6"}),r(_n,{limb:t,x:e+6.2,y:14.3,w:1.6,h:1.3}),r(_n,{limb:t,x:e+10,y:14.3,w:1.6,h:1.3,cls:"tama-thumb"})]})}function dy(){return r("g",{"shape-rendering":xe,children:[r("rect",{x:"21.4",y:"18.2",width:"12.4",height:"1",fill:"#6b4a33"}),r("g",{class:"tama-flowers",children:[r("g",{fill:"#3f8238",children:[r("rect",{x:"23",y:"13.4",width:"0.4",height:"4.8"}),r("rect",{x:"23.4",y:"15.6",width:"1",height:"0.4"}),r("rect",{x:"26",y:"15.2",width:"0.4",height:"3"}),r("rect",{x:"29",y:"15.4",width:"0.4",height:"2.8"}),r("rect",{x:"31.6",y:"17",width:"0.4",height:"1.2"}),r("rect",{x:"31.9",y:"16.6",width:"0.8",height:"0.4"})]}),r("circle",{cx:"23.2",cy:"13",r:"1.2",fill:"#ffd166"}),r("circle",{cx:"23.2",cy:"13",r:"0.5",fill:"#7a4e2d"}),r("path",{d:"M25.4 15.4 V14.2 L25.9 14.7 L26.2 14 L26.5 14.7 L27 14.2 V15.4 Z",fill:"#e05252"}),r("circle",{cx:"29.2",cy:"15",r:"0.8",fill:"#f28ab2"}),r("circle",{cx:"29.2",cy:"15",r:"0.3",fill:"#ffd166"})]}),r("g",{fill:"#7fb6e6",children:[[23.4,0],[23.9,-.3],[24.4,-.6]].map(([e,t])=>r("rect",{class:"tama-drop",x:e,y:"12.2",width:"0.3",height:"0.5",style:{animationDelay:`${t}s`}},e))})]})}function pd(){return r(K,{children:[r("g",{fill:"#efe6d8",children:[r("rect",{x:"25.5",y:"12",width:"3.4",height:"4.6",rx:"0.4"}),r("rect",{x:"28.9",y:"12.9",width:"1.2",height:"0.6"}),r("rect",{x:"29.5",y:"12.9",width:"0.6",height:"2.6"}),r("rect",{x:"28.9",y:"14.9",width:"1.2",height:"0.6"})]}),r("rect",{x:"25.5",y:"12",width:"3.4",height:"0.9",fill:"#7a4e2d"}),r("rect",{class:"tama-steam",x:"26.4",y:"8.6",width:"0.6",height:"2",fill:"var(--fg-3)"}),r("rect",{class:"tama-steam tama-steam2",x:"27.7",y:"7.8",width:"0.6",height:"2",fill:"var(--fg-3)"})]})}function md({x0:e}){return r("g",{class:"tama-can","shape-rendering":xe,children:[r("path",{d:`M${e+16.6} 12.6 Q${e+17.8} 10.8 ${e+19} 12.6`,fill:"none",stroke:"#3f7fb5","stroke-width":"0.4"}),r("line",{x1:e+19.2,y1:"13.6",x2:e+21.3,y2:"11.9",stroke:"#5aa9e6","stroke-width":"0.45"}),r("rect",{x:e+21.1,y:"11.5",width:"0.6",height:"0.7",fill:"#3f7fb5"}),r("rect",{x:e+16.2,y:"12.6",width:"3.2",height:"2.4",rx:"0.4",fill:"#5aa9e6"})]})}function hy(){return r("g",{class:"tama-stove","shape-rendering":xe,children:[r("rect",{x:"21",y:"12.8",width:"12.8",height:"6.2",fill:"#d9dde3"}),r("rect",{x:"20.8",y:"12.2",width:"13.2",height:"0.6",fill:"#3b404a"}),r("g",{fill:"#3b404a",children:[23,25,29.8,31.8].map(e=>r("circle",{cx:e,cy:"13.6",r:"0.35"},e))}),r("rect",{x:"22.4",y:"14.8",width:"10",height:"2.8",rx:"0.3",fill:"#2b2f36"}),r("rect",{class:"tama-glow",x:"23",y:"15.4",width:"8.8",height:"1.6",fill:"#ef8a2c",opacity:"0.18"}),r("rect",{x:"21.6",y:"9.4",width:"4.8",height:"2.8",rx:"0.3",fill:"#8a93a1"}),r("rect",{x:"21",y:"9.8",width:"0.6",height:"0.4",fill:"#5a6472"}),r("rect",{x:"26.4",y:"9.8",width:"0.6",height:"0.4",fill:"#5a6472"}),r("rect",{x:"21.6",y:"9.4",width:"4.8",height:"0.5",fill:"#6b7480"}),r(nn,{x:22.8,y:6.6}),r("rect",{x:"27.6",y:"11.6",width:"4",height:"0.6",rx:"0.2",fill:"#2b2f36"}),r("line",{x1:"31.6",y1:"11.8",x2:"33.8",y2:"11.2",stroke:"#2b2f36","stroke-width":"0.4"}),r("g",{fill:"#e8a92e",children:[r("rect",{class:"tama-steam",x:"28.4",y:"10.8",width:"0.5",height:"0.5"}),r("rect",{class:"tama-steam tama-steam2",x:"30.2",y:"10.6",width:"0.5",height:"0.5"})]})]})}function gd({x0:e,from:t}){return r("line",{class:"tama-spoon",x1:t?t[0]:e+16.8,y1:t?t[1]:"13.6",x2:e+21.6,y2:"9.6",stroke:"#b07a4f","stroke-width":"0.45"})}function fy({x0:e}){return r("g",{class:"tama-toque","shape-rendering":xe,children:[r("g",{fill:"#f4f4f6",children:[r("circle",{cx:e+6.4,cy:V-2.4,r:"1.5"}),r("circle",{cx:e+9,cy:V-3,r:"1.8"}),r("circle",{cx:e+11.6,cy:V-2.4,r:"1.5"}),r("rect",{x:e+5,y:V-1.6,width:"8",height:"1.9"})]}),r("g",{fill:"#d8dce2",children:[r("rect",{x:e+7,y:V-1.4,width:"0.25",height:"1.6"}),r("rect",{x:e+9,y:V-1.4,width:"0.25",height:"1.6"}),r("rect",{x:e+11,y:V-1.4,width:"0.25",height:"1.6"})]})]})}function py({from:e}){const[t,n]=e??[18.2,14.2];return r("g",{"shape-rendering":xe,children:[r("path",{class:"tama-leash",d:`M${t} ${n} Q23 12.4 28.1 15`,fill:"none",stroke:"#e05252","stroke-width":"0.25"}),r("g",{class:"tama-dog",children:[r("path",{class:"tama-tail",d:"M23 15.4 L21.8 13.4",stroke:"#b07a4f","stroke-width":"0.55","stroke-linecap":"round"}),r("g",{fill:"#b07a4f",children:[r("rect",{class:"tama-dog-a",x:"23.4",y:"16.6",width:"0.6",height:"2.4"}),r("rect",{class:"tama-dog-a",x:"27.6",y:"16.6",width:"0.6",height:"2.4"}),r("rect",{class:"tama-dog-b",x:"24",y:"16.6",width:"0.6",height:"2.4"}),r("rect",{class:"tama-dog-b",x:"27",y:"16.6",width:"0.6",height:"2.4"}),r("rect",{x:"22.8",y:"14.8",width:"5.8",height:"2.2",rx:"0.6"}),r("rect",{x:"27.8",y:"13",width:"2.8",height:"2.8",rx:"0.6"})]}),r("rect",{x:"30.2",y:"14.4",width:"1.4",height:"1.2",rx:"0.3",fill:"#c8915e"}),r("rect",{x:"31.3",y:"14.4",width:"0.5",height:"0.5",fill:we}),r("rect",{x:"28.2",y:"12.8",width:"1",height:"2.2",rx:"0.3",fill:"#7a4e2d"}),r("rect",{x:"29.6",y:"13.8",width:"0.45",height:"0.5",fill:we}),r("rect",{x:"27.8",y:"14.6",width:"0.6",height:"1.2",fill:"#e05252"})]})]})}function my(){return r("g",{"shape-rendering":xe,children:[r("rect",{x:"0",y:"0",width:"34",height:"24",fill:"#6fb4ea",opacity:"0.13"}),r("circle",{class:"tama-sun",cx:"4.5",cy:"4",r:"2.1",fill:"#ffd166"}),r("g",{class:"tama-ball",children:[r("circle",{cx:"29.5",cy:"13.8",r:"1.8",fill:"#f4f4f6"}),r("path",{d:"M29.5 12 A1.8 1.8 0 0 1 31.3 13.8 H29.5 Z",fill:"#e05252"}),r("path",{d:"M29.5 15.6 A1.8 1.8 0 0 1 27.7 13.8 H29.5 Z",fill:"#5aa9e6"})]})]})}function gy(){const e="q0.85 -0.6 1.7 0 ".repeat(21);return r("g",{"shape-rendering":xe,children:[r("g",{class:"tama-water",children:[r("path",{d:`M-1 14.6 ${e} V24 H-1 Z`,fill:"#3b8fd0",opacity:"0.9"}),r("g",{fill:"#cfe9fa",children:[r("rect",{x:"4",y:"17.4",width:"1.6",height:"0.3"}),r("rect",{x:"15",y:"19.6",width:"2",height:"0.3"}),r("rect",{x:"26",y:"18",width:"1.4",height:"0.3"})]})]}),r("g",{fill:"#cfe9fa",children:[r("rect",{class:"tama-splash",x:"6.4",y:"13",width:"0.5",height:"0.5"}),r("rect",{class:"tama-splash tama-splash2",x:"23.4",y:"13",width:"0.5",height:"0.5"})]})]})}function Ja({x0:e}){return r("g",{class:"tama-goggles","shape-rendering":xe,children:[r("rect",{x:e+3,y:V+2.6,width:"12",height:"0.5",fill:"#2b2f36"}),[4.3,11.3].map(t=>r("rect",{x:e+t,y:V+1.5,width:"2.4",height:"2.8",rx:"0.8",fill:"#7fd1e6","fill-opacity":"0.45",stroke:"#2b2f36","stroke-width":"0.35"},t))]})}function yy(){return r("g",{"shape-rendering":xe,children:[r("g",{class:"tama-motion",fill:"var(--fg-3)",children:[r("rect",{x:"0.6",y:"9.6",width:"3",height:"0.5"}),r("rect",{x:"1.2",y:"12",width:"2.6",height:"0.5"}),r("rect",{x:"0.4",y:"14.4",width:"3.2",height:"0.5"})]}),r("g",{fill:"#f4f8fb",children:[[3.6,0],[4.4,-.2],[3.2,-.4]].map(([e,t])=>r("rect",{class:"tama-kick",x:e,y:"17.8",width:"0.6",height:"0.6",style:{animationDelay:`${t}s`}},t))}),r("g",{class:"tama-sled",children:[r("path",{d:"M5.4 19 H23.4 Q25.8 19 25.4 16.8",fill:"none",stroke:"#8a93a1","stroke-width":"0.4"}),r("g",{fill:"#8a93a1",children:[7.6,14,20.4].map(e=>r("rect",{x:e,y:"17.8",width:"0.4",height:"1.2"},e))}),r("rect",{x:"5",y:"16.8",width:"18.8",height:"1.1",rx:"0.3",fill:"#b5452a"}),r("path",{d:"M25.2 17 Q24.4 15.4 22.6 14.6",fill:"none",stroke:"#e8b84a","stroke-width":"0.25"})]})]})}function Qa({x0:e}){return r("g",{class:"tama-scarf",children:[r("rect",{x:e+3,y:V+4,width:"12",height:"1.1",fill:"#d64541"}),r("g",{fill:"#f4f4f6",children:[5,8,11,14].map(t=>r("rect",{x:e+t,y:V+4,width:"0.5",height:"1.1"},t))}),r("rect",{class:"tama-scarf-tail",x:e-1.4,y:V+4.2,width:"2.8",height:"0.8",fill:"#d64541"})]})}const by={run:{tempo:.3,stride:!0,outdoors:!0,snowcap:!0,Behind:Y0,trick:{pail:!0}},cycle:{pose:{x0:7,lift:2},tempo:.4,stride:!0,outdoors:!0,jack:{x:.6,y:16.4},Behind:Z0,Headwear:X0},music:{pose:{x0:6},tempo:.5,jack:{x:1.5,y:16.4},Behind:ey,Held:dd},beer:{pose:{x0:1},tempo:.9,smile:!0,Behind:ly,Held:ry},kids:{pose:{x0:1},tempo:.7,smile:!0,Behind:oy,trick:{outdoors:!0}},game:{pose:{x0:3,sitting:!0},tempo:1.2,Behind:cy,Held:fd,paws:!0},garden:{pose:{x0:2},tempo:.8,outdoors:!0,Behind:dy,Held:md},cook:{pose:{x0:2},tempo:.6,Behind:hy,Held:gd,Headwear:fy},dog:{pose:{x0:1},tempo:.5,stride:!0,smile:!0,outdoors:!0,Behind:py},swim:{pose:{x0:6,sitting:!0},tempo:1,Behind:my,Held:Ja,Front:gy},sled:{pose:{x0:5,sitting:!0},tempo:.35,smile:!0,outdoors:!0,snowcap:!0,Behind:yy,Held:Qa}},Ve="geometricPrecision";function kt({fill:e="#1d2026"}){return r("rect",{x:"23.4",y:"6",width:"8.2",height:"5.6",fill:e})}function Ue({x:e,y:t,size:n,fill:i,weight:l=700,anchor:a="start",children:s}){return r("text",{x:e,y:t,"font-size":n,"font-weight":l,"font-family":"var(--mono)","text-anchor":a,fill:i,children:s})}const ky={bell:r("g",{children:[r("rect",{x:"2.9",y:"1.35",width:"0.6",height:"0.55",fill:"#b8862a"}),r("path",{d:"M1.9 4.3 Q1.9 1.8 3.2 1.8 Q4.5 1.8 4.5 4.3 Z",fill:"#e8a92e"}),r("rect",{x:"1.55",y:"4.1",width:"3.3",height:"0.55",rx:"0.2",fill:"#e8a92e"}),r("circle",{cx:"3.2",cy:"4.95",r:"0.38",fill:"#8a5a1a"})]}),done:r("path",{d:"M1.7 3.4 l1.1 1.1 l2.1 -2.4",fill:"none",stroke:"#2f9a57","stroke-width":"0.8","stroke-linecap":"square"}),ci:r("path",{d:"M1.9 1.9 l2.6 2.6 M4.5 1.9 l-2.6 2.6",fill:"none",stroke:"#d64541","stroke-width":"0.8","stroke-linecap":"square"}),api:r("path",{d:"M3.8 1.3 L1.9 3.5 H3.1 L2.6 5.3 L4.6 2.9 H3.4 Z",fill:"#e8a92e"}),ctx:r("g",{children:[r("rect",{x:"2",y:"1.5",width:"2.4",height:"3.7",rx:"0.3",fill:"none",stroke:"#5a6472","stroke-width":"0.35"}),r("rect",{x:"2.35",y:"2.05",width:"1.7",height:"2.8",fill:"#e8892e"})]}),update:r("g",{children:[r("rect",{x:"1.6",y:"2.3",width:"3.2",height:"2.8",fill:"#c49a6c"}),r("rect",{x:"1.6",y:"2.3",width:"3.2",height:"0.65",fill:"#d8b384"}),r("rect",{x:"2.95",y:"2.3",width:"0.5",height:"2.8",fill:"#a57c4f"})]}),merged:r("g",{children:[r("path",{d:"M2.2 2 V4.6 M2.2 2.4 Q2.2 3.3 4.3 3.3",fill:"none",stroke:"#8957e5","stroke-width":"0.4"}),r("circle",{cx:"2.2",cy:"1.9",r:"0.55",fill:"#8957e5"}),r("circle",{cx:"2.2",cy:"4.7",r:"0.55",fill:"#8957e5"}),r("circle",{cx:"4.4",cy:"3.3",r:"0.55",fill:"#8957e5"})]})};function wy({kind:e,label:t,urgent:n,more:i,x0:l}){const a=4.6+t.length*2.16+.9,[s,o]=n?["#e05252","#ffffff"]:["#f4f4f6","#1b2028"],u=Math.max(l+3.6,9.4),c=.8+a+.7;return r("g",{class:`tama-bubble${n?" tama-bubble-urgent":""}`,"shape-rendering":Ve,children:[r("path",{d:`M6.4 5.6 L${u} 8.3 L8.4 5.6 Z`,fill:s}),r("rect",{x:"0.8",y:"0.8",width:a,height:"5",rx:"1.3",fill:s}),ky[e],r(Ue,{x:"5.3",y:"4.75",size:"3.6",fill:o,children:t}),i>0&&r("g",{class:"tama-more",children:[r("rect",{x:c,y:"1.9",width:"4.4",height:"2.8",rx:"1.4",fill:"#3b404a"}),r(Ue,{x:c+2.2,y:"3.95",size:"2.1",fill:"#e6e9ef",weight:600,anchor:"middle",children:`+${i}`})]})]})}function bo({x0:e}){return r("g",{class:"tama-happy-eyes",fill:"none",stroke:we,"stroke-width":"0.45","stroke-linecap":"square",children:[r("path",{d:`M${e+4.8} ${V+3.5} l0.7 -0.9 l0.7 0.9`}),r("path",{d:`M${e+11.8} ${V+3.5} l0.7 -0.9 l0.7 0.9`})]})}function vy({x0:e}){return r("g",{fill:"none",stroke:we,"stroke-width":"0.45","stroke-linecap":"square",children:[r("path",{d:`M${e+4.9} ${V+2.3} l1.2 1.5 M${e+6.1} ${V+2.3} l-1.2 1.5`}),r("path",{d:`M${e+11.9} ${V+2.3} l1.2 1.5 M${e+13.1} ${V+2.3} l-1.2 1.5`})]})}function _y({x0:e}){return r("g",{children:[r("g",{fill:"none",stroke:we,"stroke-width":"0.4",children:[r("path",{d:`M${e+4.4} ${V+1.5} l1.8 -0.6`}),r("path",{d:`M${e+11.8} ${V+.9} l1.8 0.6`})]}),r("path",{class:"tama-sweat",fill:"#7fb6e6",d:`M${e+2.2} ${V+.4} q0.8 1.2 0 1.8 q-0.8 -0.6 0 -1.8z`}),r("path",{class:"tama-sweat",style:{animationDelay:"-0.6s"},fill:"#7fb6e6",d:`M${e+15.9} ${V+.8} q0.8 1.2 0 1.8 q-0.8 -0.6 0 -1.8z`})]})}function Yr({x:e,y:t,cls:n="tama-sparkle",delay:i=0}){const l=[[0,-.9],[.25,-.25],[.9,0],[.25,.25],[0,.9],[-.25,.25],[-.9,0],[-.25,-.25]];return r("path",{class:n||void 0,style:i?{animationDelay:`${i}s`}:void 0,fill:"#ffd166","shape-rendering":Ve,d:`M${l.map(([a,s])=>`${(e+a).toFixed(2)} ${(t+s).toFixed(2)}`).join(" L")} Z`})}function xy({x0:e}){return r("g",{children:[[6,7.4,0],[9,6.6,-.6],[12,7.4,-1.2]].map(([t,n,i])=>r("g",{class:"tama-orbit",style:{animationDelay:`${i}s`},children:r(Yr,{x:e+t,y:n,cls:""})},t))})}function Sy({x0:e}){return r("g",{class:"tama-startle",fill:"#f2c14e",children:[r("rect",{x:e+16.6,y:"5.8",width:"0.6",height:"1.8"}),r("rect",{x:e+16.6,y:"8",width:"0.6",height:"0.6"})]})}function $y({x0:e}){return r("g",{fill:Ht,children:[r("rect",{class:"tama-cheer",x:e,y:"9.8",width:"1.02",height:"3.4"}),r("rect",{class:"tama-cheer tama-cheer2",x:e+16,y:"9.8",width:"1.02",height:"3.4"})]})}const yd=({d:e})=>r("g",{class:"tama-ding",fill:"none",stroke:"#f2c14e","stroke-width":"0.3","shape-rendering":Ve,children:r("path",{d:e})});function Cy(){return r("rect",{class:"tama-slap",x:"21.6",y:"8.7",width:"1.2",height:"0.9",fill:Ht})}const Ty=[21.25,12.3],Ey=[22.2,9.6];function Py({limb:e}){return r("g",{children:[r(_n,{limb:e,x:20.7,y:11.9,w:1.1,h:.8,cls:"tama-hand"}),r(_n,{limb:e,x:22.7,y:11.9,w:1.1,h:.8,cls:"tama-hand tama-hand2"})]})}function Ay({limb:e}){return r(_n,{limb:e,x:21.6,y:8.7,w:1.2,h:.9,cls:"tama-slap"})}function My(){return r("g",{children:[r("g",{"shape-rendering":Ve,children:[r("rect",{x:"20.7",y:"12.6",width:"3",height:"0.6",rx:"0.2",fill:"#8b93a1"}),r("path",{d:"M20.95 12.65 Q20.95 10.9 22.2 10.9 Q23.45 10.9 23.45 12.65 Z",fill:"#f2c14e"}),r("rect",{x:"21.4",y:"11.4",width:"0.4",height:"0.5",fill:"#fff3c4"}),r("rect",{x:"21.95",y:"10.4",width:"0.5",height:"0.55",fill:"#c9a03a"})]}),r(yd,{d:"M20.3 10.4 l-1 -0.5 M20.6 9.5 l-0.6 -0.9 M24.1 10.4 l1 -0.5 M23.8 9.5 l0.6 -0.9"})]})}function Ly(){return r("g",{children:[r("g",{class:"tama-alarm","shape-rendering":Ve,children:[r("rect",{x:"27.4",y:"18.2",width:"0.5",height:"0.8",fill:"#8b93a1"}),r("rect",{x:"30.1",y:"18.2",width:"0.5",height:"0.8",fill:"#8b93a1"}),r("circle",{cx:"27.4",cy:"14.3",r:"0.9",fill:"#e8a92e"}),r("circle",{cx:"30.6",cy:"14.3",r:"0.9",fill:"#e8a92e"}),r("rect",{x:"28.8",y:"13.4",width:"0.4",height:"1",fill:"#3b404a"}),r("circle",{cx:"29",cy:"16.4",r:"2.1",fill:"#e6e9ef",stroke:"#d03a3a","stroke-width":"0.45"}),r("path",{d:"M29 16.4 v-1.3 M29 16.4 h0.9",stroke:we,"stroke-width":"0.3",fill:"none"})]}),r(yd,{d:"M26 14 l-0.9 -0.6 M25.8 15.3 l-1 0 M32 14 l0.9 -0.6 M32.2 15.3 l1 0"})]})}function Iy(){return r("g",{children:[r(Yr,{x:22.2,y:4.4}),r(Yr,{x:32.6,y:4.8,delay:-.5}),r(Yr,{x:20.6,y:7.2,delay:-1})]})}function Oy(){return r("g",{children:[r(kt,{}),r("path",{d:"M25.3 8.8 l1.7 1.7 l3.4 -3.6",fill:"none",stroke:"#6fcf8f","stroke-width":"0.9","stroke-linecap":"square","shape-rendering":Ve})]})}function Dy(){return r("g",{children:[r(kt,{fill:"#1d1a26"}),r("g",{"shape-rendering":Ve,children:[r("path",{d:"M26.3 6.9 V9.4 M26.3 7.3 Q26.3 8.1 28.9 8.1",fill:"none",stroke:"#a371f7","stroke-width":"0.45"}),r("circle",{cx:"26.3",cy:"6.9",r:"0.6",fill:"#a371f7"}),r("circle",{cx:"26.3",cy:"9.5",r:"0.6",fill:"#a371f7"}),r("circle",{cx:"29",cy:"8.1",r:"0.6",fill:"#a371f7"})]}),r(Ue,{x:"27.5",y:"11.15",size:"1.35",fill:"#a371f7",weight:600,anchor:"middle",children:"merged"})]})}const ko=({x:e})=>r("g",{children:[r("path",{class:"tama-flame",fill:"#f08a3c",d:`M${e} 5.6 q-0.5 -1.8 0.7 -3 q0.2 1.1 0.7 1.5 q0.3 -1 1 -1.6 q0.8 1.8 0.1 3.1z`}),r("path",{class:"tama-flame tama-flame2",fill:"#ffd166",d:`M${e+.5} 5.6 q-0.2 -1 0.6 -1.8 q0.2 0.7 0.6 0.9 q0.3 -0.5 0.4 -0.9 q0.6 1 0.1 1.8z`})]});function Ry(){return r("g",{children:[r(kt,{fill:"#2a1416"}),r("g",{class:"tama-errors",children:[r("path",{d:"M25.4 7.1 l3.2 3.2 M28.6 7.1 l-3.2 3.2",fill:"none",stroke:"#e05252","stroke-width":"0.8","stroke-linecap":"square"}),r(Ue,{x:"29.4",y:"10.7",size:"1.8",fill:"#e05252",children:"CI"})]}),r(ko,{x:24.6}),r(ko,{x:28.4}),r("g",{fill:"#f4f4f6","shape-rendering":Ve,children:[r("circle",{class:"tama-spray",cx:"23",cy:"6",r:"0.5"}),r("circle",{class:"tama-spray tama-spray2",cx:"23",cy:"6",r:"0.6"}),r("circle",{class:"tama-spray tama-spray3",cx:"23",cy:"6",r:"0.45"})]})]})}function Fy(){return r("g",{"shape-rendering":Ve,children:[r("path",{d:"M20.4 9.2 q0.8 -1.6 2.3 -2.6",fill:"none",stroke:"#2b2f36","stroke-width":"0.35"}),r("rect",{x:"19.3",y:"9.3",width:"1.5",height:"3.8",rx:"0.55",fill:"#d03a3a"}),r("rect",{x:"19.6",y:"8.7",width:"0.9",height:"0.7",fill:"#3b404a"}),r("rect",{x:"19.5",y:"10.4",width:"1.1",height:"0.9",fill:"#f4f4f6"})]})}const Ny=Array.from({length:18},(e,t)=>[23.6+t*1.7%7.4,6.2+t*1.3%4.8]),By=Array.from({length:18},(e,t)=>[24.1+t*2.3%7.2,6.5+t*.9%4.8]);function zy(){const e=t=>t.map(([n,i])=>r("rect",{x:n.toFixed(1),y:i.toFixed(1),width:"0.6",height:"0.6"},`${n},${i}`));return r("g",{children:[r(kt,{fill:"#22252b"}),r("g",{class:"tama-static",fill:"#8b93a1",children:e(Ny)}),r("g",{class:"tama-static tama-static2",fill:"#5d6470",children:e(By)}),r("rect",{x:"25.2",y:"7.8",width:"4.6",height:"2.4",fill:"#22252b"}),r(Ue,{x:"27.5",y:"9.7",size:"2",fill:"#ffd166",anchor:"middle",children:"529"})]})}function jy(){return r("g",{class:"tama-stack",children:Array.from({length:12},(e,t)=>r("rect",{x:20.5+(t%2?.35:0),y:(12.65-t*.68).toFixed(2),width:"2.6",height:"0.55",fill:t%2?"#f2ece0":"#e2dccf"},t))})}function Hy({pct:e,cost:t}){if(t)return r("g",{children:[r(kt,{}),r(Ue,{x:"27.5",y:"9.6",size:"1.7",fill:"#f2a33a",anchor:"middle",children:"compact?"})]});const n=Math.min(100,Math.max(0,e??90));return r("g",{children:[r(kt,{}),r(Ue,{x:"24.2",y:"7.9",size:"1.4",fill:"#a4acb9",weight:500,children:"context"}),r("rect",{x:"24.2",y:"8.6",width:"6.6",height:"1.5",fill:"none",stroke:"#707884","stroke-width":"0.25"}),r("rect",{class:"tama-fill",x:"24.4",y:"8.8",width:6.2*n/100,height:"1.1",fill:"#f2a33a"}),e!=null&&r(Ue,{x:"30.8",y:"11.3",size:"1.5",fill:"#f2a33a",anchor:"end",children:`${e}%`})]})}const qy=["#52b4ea","#7fbf7f","#c792ea","#e6e9ef"],Uy=[.85,.55,.7,.4,.9,.6],Wy={1:[[23.4,6,8.2,5]],2:[[23.4,6,4.1,5],[27.5,6,4.1,5]],4:[[23.4,6,4.1,2.5],[27.5,6,4.1,2.5],[23.4,8.5,4.1,2.5],[27.5,8.5,4.1,2.5]]};function Ky({n:e}){const t=e===0?[]:Wy[e===1?1:e===2?2:4];let n=0;return r("g",{children:[r(kt,{}),r("rect",{x:"23.4",y:"11",width:"8.2",height:"0.6",fill:e?"#3d8f5a":"#2c4234"}),e===0&&r("rect",{class:"tama-cursor",x:"24",y:"6.6",width:"0.6",height:"0.6",fill:"#707884"}),t.length>=2&&r("rect",{x:"27.45",y:"6",width:"0.12",height:"5",fill:"#4b515c"}),t.length===4&&r("rect",{x:"23.4",y:"8.45",width:"8.2",height:"0.12",fill:"#4b515c"}),t.slice(0,Math.min(e,4)).flatMap(([i,l,a,s])=>Array.from({length:s>=5?3:2},(o,u)=>{const c=n++;return r("rect",{class:"tama-type",style:{animationDelay:`${(-.37*c).toFixed(2)}s`},x:(i+.5).toFixed(2),y:(l+.6+u*1.1).toFixed(2),width:((a-1)*Uy[c%6]).toFixed(2),height:"0.45",fill:qy[c%4]},c)}))]})}function Vy({day:e,time:t}){const n=Math.min(3,7.6/(.6*t.length));return r("g",{children:[r(kt,{fill:"#16181d"}),r(Ue,{x:"24.1",y:"7.9",size:"1.3",fill:"#a4acb9",weight:500,children:e?`back ${e}`:"back at"}),r(Ue,{x:"27.5",y:"10.9",size:n.toFixed(2),fill:"#f2c14e",anchor:"middle",children:t}),r("circle",{cx:"30.85",cy:"6.95",r:"0.5",fill:"#f3e9c6"}),r("circle",{cx:"31.1",cy:"6.8",r:"0.42",fill:"#16181d"})]})}function Gy(){return r("g",{fill:"var(--fg-2)","font-family":"var(--mono)","font-weight":"700",children:[r("text",{class:"tama-z",x:"17.5",y:"8.4","font-size":"3",children:"z"}),r("text",{class:"tama-z tama-z2",x:"19.6",y:"6","font-size":"3.8",children:"Z"})]})}function Jy({x0:e}){return r("g",{fill:we,children:[r("rect",{x:e+5.5,y:V+2.6,width:"1",height:"1.6"}),r("rect",{x:e+12.5,y:V+2.6,width:"1",height:"1.6"})]})}function Qy(){return r("g",{class:"tama-parcel","shape-rendering":Ve,children:[r("rect",{x:"24.6",y:"15.6",width:"4.8",height:"3.4",fill:"#c49a6c"}),r("rect",{x:"24.6",y:"15.6",width:"4.8",height:"0.7",fill:"#d8b384"}),r("rect",{x:"26.75",y:"15.6",width:"0.5",height:"3.4",fill:"#a57c4f"}),r("rect",{x:"28.3",y:"14.4",width:"2.2",height:"1.8",rx:"0.25",fill:"#52b4ea"}),r("path",{d:"M29.4 14.75 v1 M28.95 15.3 l0.45 0.5 l0.45 -0.5",fill:"none",stroke:"#ffffff","stroke-width":"0.28"})]})}const Yy={code:{x0:3,sitting:!0},nap:{x0:3,sitting:!0},read:{x0:4,sitting:!0}},Zy={x0:8},bd=qt(Tn),Xy=qt(Tn.map((e,t)=>t===2?e.replace(/^.##/,"...").replace(/##$/,".."):e)),Ql=od.map(e=>qt([e])),Yl=V+2*Tn.length;function e2(){return r("g",{children:[r(nt,{cells:bd,cls:"tama-body",x0:0}),r(Zl,{x0:0}),r(nt,{cells:Ql[0],cls:"tama-legs-a",x0:0,y0:Yl})]})}const t2=new Set([Ja,Qa]),n2={beer:"pint",coffee:"mug",cook:"spoon",garden:"can",dog:"leash",music:"bass",game:"controller"};function zn({dy:e,children:t}){return e?r("g",{transform:`translate(0 ${e})`,children:t}):t}function Zl({closed:e,x0:t}){return r("g",{class:e?"tama-eyes-closed":"tama-eyes",children:A0.map(n=>r("rect",{x:t+n,y:e?V+3.3:V+2,width:"1",height:e?.5:2,fill:we},n))})}const wo={spring:{sky:"#7fb3e0",ground:"#5c9a4c",canopy:["#6fae5a","#f2a7c3"],fall:"#f4b6cc"},summer:{sky:"#6fb4ea",ground:"#4f9443",canopy:["#4f9a46","#3f8238"]},autumn:{sky:"#c9a36b",ground:"#7a6a3a",canopy:["#d9822b","#b5452a"],fall:"#e07b39"},winter:{sky:"#9fb3c8",ground:"#e6edf3",fall:"#f4f8fb"}},r2=[[3,0],[11,-.7],[18,-1.6],[25.5,-.3],[32,-1.1]];function i2({season:e,night:t}){const n=wo[e]||wo.summer;return r("g",{class:"tama-scenery","data-season":e,children:[r("rect",{x:"0",y:"0",width:"34",height:"19.2",fill:n.sky,opacity:"0.13"}),r("rect",{x:"0",y:"19.4",width:"34",height:"4.6",fill:n.ground,opacity:e==="winter"?.85:.55}),t&&r("g",{children:[r("rect",{x:"0",y:"0",width:"34",height:"24",fill:"#0b0a1a",opacity:"0.5"}),r("g",{class:"tama-moon",children:[r("circle",{cx:"5",cy:"4.2",r:"2",fill:"#f3e9c6"}),r("circle",{cx:"4.3",cy:"3.7",r:"0.4",fill:"#d8ccaa"}),r("circle",{cx:"5.7",cy:"4.9",r:"0.3",fill:"#d8ccaa"})]}),r("g",{transform:"translate(19 3.2)",children:r("path",{class:"tama-bat",fill:"#1a1626",d:"M0 0.6 q1 -1 2 0 q0.4 -0.8 1 -0.2 q0.6 -0.6 1 0.2 q1 -1 2 0 q-1.2 0.1 -2 1 q-0.6 -0.4 -1 0 q-0.4 -0.4 -1 0 q-0.8 -0.9 -2 -1z"})})]}),e==="summer"&&!t&&r("circle",{class:"tama-sun",cx:"4.5",cy:"4",r:"2.1",fill:"#ffd166"}),r("rect",{x:"30.2",y:"11.6",width:"1.4",height:"7.6",fill:"#6b4a33"}),n.canopy?r("g",{children:[r("rect",{x:"27.4",y:"7.4",width:"6.6",height:"4.6",rx:"1.4",fill:n.canopy[0]}),r("rect",{x:"28.4",y:"5.8",width:"4.6",height:"2.2",rx:"1",fill:n.canopy[0]}),r("g",{fill:n.canopy[1],children:[r("rect",{x:"28.2",y:"8.2",width:"0.8",height:"0.8"}),r("rect",{x:"31.4",y:"7",width:"0.8",height:"0.8"}),r("rect",{x:"32.4",y:"9.8",width:"0.8",height:"0.8"}),r("rect",{x:"29.6",y:"10.4",width:"0.8",height:"0.8"})]})]}):r("g",{stroke:"#6b4a33","stroke-width":"0.5",children:[r("line",{x1:"30.9",y1:"12",x2:"28.4",y2:"8.2"}),r("line",{x1:"30.9",y1:"11",x2:"33.4",y2:"8"}),r("line",{x1:"30.9",y1:"9.6",x2:"30.4",y2:"6.2"})]}),e==="spring"&&r("g",{children:[r("rect",{x:"3",y:"19.8",width:"0.7",height:"0.7",fill:"#f2a7c3"}),r("rect",{x:"6.5",y:"20.6",width:"0.7",height:"0.7",fill:"#ffd166"}),r("rect",{x:"26",y:"20.2",width:"0.7",height:"0.7",fill:"#f2a7c3"})]}),e==="summer"&&r("g",{fill:"#3f8238",children:[r("rect",{x:"2.6",y:"18.4",width:"0.4",height:"1.2"}),r("rect",{x:"3.3",y:"18.1",width:"0.4",height:"1.5"}),r("rect",{x:"26.4",y:"18.3",width:"0.4",height:"1.3"})]}),e==="autumn"&&r("g",{fill:"#c2452d",children:[r("rect",{x:"4",y:"19.7",width:"1",height:"0.5"}),r("rect",{x:"24.8",y:"20.1",width:"1",height:"0.5"}),r("rect",{x:"27.6",y:"19.6",width:"1",height:"0.5",fill:"#e07b39"})]}),n.fall&&r("g",{fill:n.fall,children:r2.map(([i,l])=>r("rect",{class:"tama-fall",x:i,y:"-1",width:"0.7",height:"0.7",style:{animationDelay:`${l}s`}},i))})]})}function l2({x:e,y:t}){return r("g",{class:"tama-jack","shape-rendering":"geometricPrecision",children:[r("rect",{x:e+1.3,y:t,width:"0.5",height:"0.7",fill:"#4f7a2c"}),r("rect",{x:e,y:t+.4,width:"3.1",height:"2.2",rx:"1",fill:"#ef8a2c"}),r("rect",{x:e+1,y:t+.5,width:"0.15",height:"2",fill:"#d9741f"}),r("rect",{x:e+1.95,y:t+.5,width:"0.15",height:"2",fill:"#d9741f"}),r("path",{class:"tama-jack-face",fill:"#ffcf5a",d:`M${e+.6} ${t+1.4} l0.4 -0.6 l0.4 0.6z M${e+2.1} ${t+1.4} l0.4 -0.6 l0.4 0.6z M${e+.6} ${t+1.8} h1.9 l-0.3 0.5 h-1.3z`})]})}const a2={sleep:{x:1.5,y:16.4},coffee:{x:1.5,y:16.4},eat:{x:1.5,y:16.4},code:{x:25.5,y:16.4},nap:{x:25.5,y:16.4},read:{x:24.6,y:3.4}};function s2(){return r("g",{class:"tama-xmas-tree","shape-rendering":"geometricPrecision",children:[r("rect",{x:"2.9",y:"18.2",width:"1",height:"0.8",fill:"#5a3a26"}),r("polygon",{points:"3.4,12 7.6,18.2 -0.8,18.2",fill:"#276b3e"}),r("polygon",{points:"3.4,8.6 7.2,14.6 -0.4,14.6",fill:"#2f7d4a"}),r("polygon",{points:"3.4,5.2 6.8,10.8 0,10.8",fill:"#276b3e"}),r("polygon",{points:"3.4,2.4 6.2,7.2 0.6,7.2",fill:"#2f7d4a"}),r("polygon",{class:"tama-twinkle",points:"3.4,0.8 3.8,1.8 4.8,1.9 4,2.5 4.3,3.4 3.4,2.9 2.5,3.4 2.8,2.5 2,1.9 3,1.8",fill:"#ffd166"}),r("circle",{cx:"2.6",cy:"6.2",r:"0.42",fill:"#e05252"}),r("circle",{class:"tama-twinkle",cx:"4.6",cy:"9.4",r:"0.42",fill:"#7fb6e6"}),r("circle",{cx:"1.4",cy:"10",r:"0.42",fill:"#ffd166"}),r("circle",{class:"tama-twinkle tama-twinkle2",cx:"5.6",cy:"12.8",r:"0.42",fill:"#e05252"}),r("circle",{cx:"0.8",cy:"13.8",r:"0.42",fill:"#c792ea"}),r("circle",{cx:"6.6",cy:"16.6",r:"0.42",fill:"#ffd166"})]})}function o2(){return r("g",{class:"tama-stocking",children:[25.4,30.2].map(e=>r("g",{children:[r("rect",{x:e,y:"7.1",width:"1.2",height:"2.1",fill:"#c0392b"}),r("rect",{x:e,y:"8.6",width:"2",height:"0.9",rx:"0.4",fill:"#c0392b"}),r("rect",{x:e-.1,y:"7.1",width:"1.4",height:"0.6",fill:"#f4f4f6"})]},e))})}function kd({x0:e}){return r("g",{class:"tama-hat-santa",children:[r("g",{fill:"#d03a3a",children:[r("rect",{x:e+4,y:"6.8",width:"10",height:"1.5"}),r("rect",{x:e+5.6,y:"5.6",width:"6.6",height:"1.3"}),r("rect",{x:e+7.4,y:"4.6",width:"3.6",height:"1.1"}),r("rect",{x:e+10.6,y:"4.6",width:"3",height:"1"}),r("rect",{x:e+13,y:"5.2",width:"1.2",height:"1"})]}),r("rect",{x:e+3,y:"8.2",width:"12",height:"1.3",rx:"0.5",fill:"#f4f4f6"}),r("rect",{x:e+13.6,y:"5.6",width:"1.6",height:"1.6",rx:"0.8",fill:"#f4f4f6"})]})}function wd({x0:e}){return r("g",{class:"tama-hat-party","shape-rendering":"geometricPrecision",children:[r("polygon",{points:`${e+6.6},9 ${e+11.4},9 ${e+9},3.8`,fill:"#5aa9e6"}),r("rect",{x:e+7.5,y:"6.8",width:"3",height:"0.6",fill:"#ffd166"}),r("rect",{x:e+8.25,y:"5.2",width:"1.5",height:"0.5",fill:"#ffd166"}),r("circle",{cx:e+9,cy:"3.6",r:"0.8",fill:"#f28ab2"})]})}function c2({sprite:e,p:t,hat:n,season:i,ghost:l}){const a=(t==null?void 0:t.Headwear)&&!n,s=(t==null?void 0:t.snowcap)&&i==="winter"&&!n&&!l;return!a&&!s&&!n?null:r("g",{class:"tama-hat-seat",style:"transform-box: view-box",transform:vg(e),children:[a&&r(t.Headwear,{x0:0}),s&&r("rect",{class:"tama-snowcap",x:"3",y:"8.4",width:"12",height:"0.7",rx:"0.3",fill:"#f4f8fb"}),n==="santa"&&r(kd,{x0:0}),n==="party"&&r(wd,{x0:0})]})}function u2({x0:e}){const t=e+2.2,n=e+15.8,i="q-0.85 1.1 -1.7 0 ".repeat(8);return r("g",{class:"tama-ghost","shape-rendering":"geometricPrecision",children:[r("path",{fill:"#f5f5f7",d:`M${t} 17.6 V10.4 Q${t} 7.6 ${(t+n)/2} 7.6 Q${n} 7.6 ${n} 10.4 V17.6 ${i}Z`}),r("ellipse",{cx:e+5.6,cy:"11.6",rx:"0.7",ry:"1",fill:we}),r("ellipse",{cx:e+12.4,cy:"11.6",rx:"0.7",ry:"1",fill:we}),r("ellipse",{cx:e+9,cy:"14",rx:"0.6",ry:"0.8",fill:we})]})}function d2({x0:e}){const t=e+16.4;return r("g",{class:"tama-pail","shape-rendering":"geometricPrecision",children:[r("path",{d:`M${t+.3} 13.8 Q${t+1.8} 11.2 ${t+3.3} 13.8`,fill:"none",stroke:"#3a2a1a","stroke-width":"0.35"}),r("rect",{x:t+.9,y:"13.1",width:"0.7",height:"0.7",fill:"#e05252"}),r("rect",{x:t+1.9,y:"12.9",width:"0.7",height:"0.7",fill:"#7fb6e6"}),r("rect",{x:t,y:"13.6",width:"3.6",height:"3.2",rx:"1.2",fill:"#ef8a2c"}),r("path",{fill:"#3a1e0e",d:`M${t+.7} 14.9 l0.5 -0.7 l0.5 0.7z M${t+2} 14.9 l0.5 -0.7 l0.5 0.7z M${t+.7} 15.5 h2.2 l-0.4 0.6 h-1.4z`})]})}const h2=[[5,4,"#ffd166",0],[22,2.6,"#f28ab2",-.9]],f2=[[17.4,2.8,"#ffd166",0],[24.6,2.1,"#f28ab2",-.6],[31.2,3,"#7fb6e6",-1.2]];function p2({clear:e}){const t=(n,i,l,a)=>r("g",{class:"tama-firework",style:{animationDelay:`${a}s`},fill:l,children:[[0,45,90,135,180,225,270,315].map(s=>{const o=s*Math.PI/180;return r("rect",{x:n+Math.cos(o)*1.8-.25,y:i+Math.sin(o)*1.8-.25,width:"0.5",height:"0.5"},s)}),r("rect",{x:n-.25,y:i-.25,width:"0.5",height:"0.5"})]},n);return r("g",{children:(e?f2:h2).map(([n,i,l,a])=>t(n,i,l,a))})}const vo=["#ffd166","#f28ab2","#7fb6e6","#9be38f","#c792ea"];function m2(){return r("g",{class:"tama-confetti",children:[[2.5,0],[9,-.6],[15,-1.4],[21,-.3],[27,-1.9],[32,-1]].map(([e,t],n)=>r("rect",{class:"tama-fall",x:e,y:"-1",width:"0.6",height:"0.6",fill:vo[n%vo.length],style:{animationDelay:`${t}s`}},e))})}function g2({mood:e}){return e==="furious"?r("g",{class:"tama-errors",fill:"#e05252",children:[r("rect",{x:"24",y:"7",width:"4.4",height:"0.6"}),r("rect",{x:"24",y:"8.4",width:"6.2",height:"0.6"}),r("rect",{x:"24.8",y:"9.8",width:"3.6",height:"0.6"}),r("rect",{x:"29.4",y:"9.8",width:"0.6",height:"0.6",fill:"#ffd166"})]}):r("g",{children:[r("rect",{x:"24",y:"7",width:"4.4",height:"0.6",fill:"var(--accent)"}),e==="grumpy"?r("rect",{class:"tama-red-line",x:"24",y:"8.4",width:"3",height:"0.6",fill:"#e05252"}):r("rect",{x:"24",y:"8.4",width:"3",height:"0.6",fill:"#7fbf7f"}),r("rect",{x:"24.8",y:"9.8",width:"3.4",height:"0.6",fill:"#c792ea"}),r("rect",{class:"tama-cursor",x:"28.6",y:"9.8",width:"0.6",height:"0.6",fill:"#e6e9ef"})]})}function y2({activity:e,occasion:t,coffee:n,ringing:i,keyboard:l=!0,mood:a="calm",screen:s=null,dish:o,mugHeld:u=!1}){switch(e){case"sleep":return i?null:r("g",{fill:"var(--fg-2)","font-family":"var(--mono)","font-weight":"700",children:[r("text",{class:"tama-z",x:"26",y:"10","font-size":"4",children:"z"}),r("text",{class:"tama-z tama-z2",x:"29",y:"7","font-size":"5",children:"Z"})]});case"coffee":return r("g",{children:!u&&r(pd,{})});case"code":return r("g",{children:[r("g",{class:"tama-chair",fill:"#4c525c",children:[r("rect",{x:"1.6",y:"9.6",width:"1.6",height:"8.4",rx:"0.5"}),r("rect",{x:"3.2",y:"16.9",width:"15",height:"1.3",rx:"0.4"}),r("rect",{x:"10",y:"18.2",width:"1.2",height:"0.8"}),r("rect",{x:"7",y:"18.6",width:"7.2",height:"0.5",rx:"0.25"})]}),r("g",{class:"tama-desk",children:[r("rect",{x:"20.2",y:"13.2",width:"13.6",height:"0.9",fill:"#8b6a4e"}),r("rect",{x:"21",y:"14.1",width:"0.9",height:"4.9",fill:"#6f533c"}),r("rect",{x:"32.2",y:"14.1",width:"0.9",height:"4.9",fill:"#6f533c"}),r("rect",{x:"26.9",y:"12",width:"1.2",height:"1.2",fill:"var(--fg-3)"}),r("rect",{x:"23",y:"5.6",width:"9",height:"6.4",rx:"0.4",fill:a==="furious"?"#2a1416":"#1d2026",stroke:"var(--fg-3)","stroke-width":"0.3"}),s||r(g2,{mood:a}),l&&r("rect",{x:"20.4",y:"12.6",width:"4.2",height:"0.6",rx:"0.2",fill:"#c9ced6"})]}),n&&r("g",{class:"tama-desk-mug",children:[r("rect",{class:"tama-steam",x:"25.2",y:"9.4",width:"0.4",height:"1.4",fill:"var(--fg-3)"}),r("rect",{class:"tama-steam tama-steam2",x:"25.9",y:"8.8",width:"0.4",height:"1.4",fill:"var(--fg-3)"}),r("g",{fill:"#efe6d8",children:[r("rect",{x:"24.9",y:"11.3",width:"1.5",height:"1.9",rx:"0.25"}),r("rect",{x:"26.4",y:"11.8",width:"0.5",height:"0.35"}),r("rect",{x:"26.6",y:"11.8",width:"0.3",height:"1"}),r("rect",{x:"26.4",y:"12.5",width:"0.5",height:"0.35"})]}),r("rect",{x:"24.9",y:"11.3",width:"1.5",height:"0.45",fill:"#7a4e2d"})]})]});case"read":return r("g",{children:[r("ellipse",{class:"tama-glow",cx:"28",cy:"19",rx:"9",ry:"2.4",fill:"#f0a24a",opacity:"0.18"}),r("g",{class:"tama-fire",children:[r("rect",{x:"23.4",y:"6",width:"10.6",height:"1.1",fill:"#8a7a6a"}),r("rect",{x:"24.2",y:"7.1",width:"9.8",height:"11.9",fill:"#7b4a3a"}),r("g",{fill:"#6a3e30",children:[r("rect",{x:"24.2",y:"9.4",width:"9.8",height:"0.3"}),r("rect",{x:"24.2",y:"11.8",width:"9.8",height:"0.3"}),r("rect",{x:"24.2",y:"14.2",width:"9.8",height:"0.3"}),r("rect",{x:"24.2",y:"16.6",width:"9.8",height:"0.3"})]}),r("rect",{x:"25.8",y:"11",width:"6.6",height:"8",rx:"2.4",fill:"#1a1110"}),r("path",{class:"tama-flame",d:"M27.2 19 q-0.6 -2.6 1 -4.4 q0.2 1.6 1 2.2 q0.4 -1.4 1.4 -2.4 q1 2.6 0.2 4.6z",fill:"#f08a3c"}),r("path",{class:"tama-flame tama-flame2",d:"M28 19 q-0.2 -1.6 0.9 -2.8 q0.3 1.1 0.9 1.4 q0.5 -0.8 0.6 -1.4 q0.9 1.6 0.2 2.8z",fill:"#ffd166"}),r("rect",{x:"26.6",y:"18.4",width:"5",height:"0.6",rx:"0.3",fill:"#5a3a26"})]}),t==="yearend"&&r(o2,{}),t==="yearend"&&r(s2,{}),r("g",{class:"tama-chair",fill:"#8e3b3b",children:[r("rect",{x:"1",y:"8.6",width:"3.2",height:"9.6",rx:"1"}),r("rect",{x:"3.6",y:"16.8",width:"16.8",height:"1.5",rx:"0.6"})]}),r("g",{class:"tama-chair-legs",fill:"#4a2f22",children:[r("rect",{x:"1.5",y:"18.2",width:"0.9",height:"0.8"}),r("rect",{x:"5",y:"18.2",width:"0.9",height:"0.8"}),r("rect",{x:"16.4",y:"18.2",width:"0.9",height:"0.8"})]})]});case"eat":return r(Q0,{dish:o});default:return null}}function b2({p:e,season:t,trick:n,critter:i,from:l}){const a=r(e.Behind,{season:t,trick:n,critter:i,from:l});return e.outdoors?r("g",{children:[r(i2,{season:t,night:n}),a]}):a}function k2({activity:e}){return e!=="read"?null:r("g",{children:[r("rect",{class:"tama-chair",x:"17.4",y:"13.6",width:"3.6",height:"4.7",rx:"0.8",fill:"#7a3030"}),r("rect",{class:"tama-chair-legs",x:"19.6",y:"18.2",width:"0.9",height:"0.8",fill:"#4a2f22"}),r("g",{class:"tama-book",children:[r("rect",{x:"17.4",y:"10.6",width:"2.9",height:"3.4",fill:"#f2ece0"}),r("rect",{x:"20.3",y:"10.6",width:"2.9",height:"3.4",fill:"#ebe3d3"}),r("g",{fill:"#c9bfae",children:[r("rect",{x:"17.9",y:"11.4",width:"1.9",height:"0.3"}),r("rect",{x:"17.9",y:"12.3",width:"1.6",height:"0.3"}),r("rect",{x:"20.8",y:"11.4",width:"1.9",height:"0.3"}),r("rect",{x:"20.8",y:"12.3",width:"1.5",height:"0.3"})]}),r("rect",{class:"tama-page",x:"20.3",y:"10.6",width:"2.9",height:"3.4",fill:"#f6f1e6"}),r("rect",{x:"20.15",y:"10.6",width:"0.3",height:"3.4",fill:"#b9ae9b"})]})]})}function w2({x0:e,mood:t}){return r("g",{class:"tama-mood",children:[t==="furious"&&r("g",{class:"tama-flush",fill:"#ff3b2f",opacity:"0.5",children:[r("rect",{x:e+3,y:V,width:"12",height:"4"}),r("rect",{x:e+1,y:V+4,width:"16",height:"2"}),r("rect",{x:e+3,y:V+6,width:"12",height:"2"})]}),r("g",{class:"tama-brows",fill:we,children:[r("rect",{x:e+5,y:V+2.9,width:"1",height:"1.1"}),r("rect",{x:e+12,y:V+2.9,width:"1",height:"1.1"}),r("rect",{x:e+3.9,y:V+1.5,width:"1.3",height:"0.55"}),r("rect",{x:e+5.1,y:V+2.05,width:"1.3",height:"0.55"}),r("rect",{x:e+11.6,y:V+2.05,width:"1.3",height:"0.55"}),r("rect",{x:e+12.8,y:V+1.5,width:"1.3",height:"0.55"})]}),t==="furious"&&r("path",{class:"tama-scowl",fill:"none",stroke:we,"stroke-width":"0.35","shape-rendering":"geometricPrecision",d:`M${e+7.4} ${V+6} l0.8 -0.6 l0.8 0.6 l0.8 -0.6 l0.8 0.6`}),r("g",{fill:Ht,children:[r("rect",{class:"tama-hand",x:"20.7",y:"11.9",width:"1.1",height:"0.8"}),r("rect",{class:"tama-hand tama-hand2",x:"22.7",y:"11.9",width:"1.1",height:"0.8"})]}),r("g",{class:"tama-clack",fill:"#e6e9ef",children:[r("rect",{x:"21.1",y:"10.9",width:"0.25",height:"0.55"}),r("rect",{x:"23.3",y:"10.8",width:"0.25",height:"0.55"})]})]})}function v2({mood:e,x0:t,coffee:n,hat:i,headDy:l}){return e!=="furious"?null:r("g",{children:[r("g",{fill:"#c9ced6",children:[r("rect",{class:"tama-flying-key",x:"21.4",y:"12",width:"0.7",height:"0.7"}),r("rect",{class:"tama-flying-key tama-flying-key2",x:"23.1",y:"12",width:"0.7",height:"0.7"}),r("rect",{class:"tama-flying-key tama-flying-key3",x:"22.3",y:"12",width:"0.6",height:"0.6"})]}),r("g",{fill:"#8b93a1","shape-rendering":"geometricPrecision",children:[r("circle",{class:"tama-smoke",cx:"21.6",cy:"12.2",r:"0.5"}),r("circle",{class:"tama-smoke tama-smoke2",cx:"23.4",cy:"12.2",r:"0.45"})]}),!i&&r(zn,{dy:l,children:r("g",{class:"tama-shimmer",fill:"none",stroke:"#ff8a5c","stroke-width":"0.3",opacity:"0.8","shape-rendering":"geometricPrecision",children:[6,9,12].map((a,s)=>r("path",{class:s===1?"tama-shimmer2":void 0,d:`M${t+a} ${s===1?7.2:7.6} q0.5 -0.7 0 -1.4 q-0.5 -0.7 0 -1.4`},a))})}),n&&r("g",{class:"tama-spill",fill:"#7a4e2d","shape-rendering":"geometricPrecision",children:[r("circle",{cx:"25.4",cy:"11.1",r:"0.25"}),r("circle",{class:"tama-spill2",cx:"26",cy:"11",r:"0.22"})]})]})}const _2=new Set(["bell","done","merged","api","ctx"]);function x2({activity:e,view:t,kind:n,duty:i,working:l,walled:a,mirroring:s}){return e==="nap"?r(Vy,{...a}):t.atDesk?n==="done"?r(Oy,{}):n==="merged"?r(Dy,{}):n==="ci"?r(Ry,{}):n==="api"?r(zy,{}):n==="ctx"?r(Hy,{pct:i==null?void 0:i.pct,cost:i==null?void 0:i.cost}):s?r(Ky,{n:l}):null:null}function S2({kind:e}){return r("g",{children:[e==="bell"&&r(My,{}),e==="ctx"&&r(jy,{}),e==="update"&&r(Qy,{})]})}function $2({activity:e,season:t="summer",occasion:n=null,coffee:i=!1,mood:l="calm",petted:a=!1,petKey:s=0,duty:o=null,working:u,walled:c=null,party:p=!1,dish:d,trick:f=!1,critter:h=pi[0]}){var Me;const m=(o==null?void 0:o.kind)||null,b=Wu(e,m),{atDesk:x}=b,w=f,C=by[e],y=C&&f?{...C,...C.trick}:C,{x0:g,sitting:$=!1,lift:v=0}=(y==null?void 0:y.pose)||Yy[e]||Zy,E=y?y.jack:a2[e],M=h.sprite,T=M&&Sa(M,{x0:g,sitting:$,height:w?su:xa}),S=T?N(T.top-V):0,R=e==="sleep"||e==="nap",F=m==="bell"&&R,q=R&&!F,L=m==="bell"&&(x||e==="nap"),I=w||q?null:x||_2.has(m)?m:null,O=!w&&!q&&(I==="done"||I==="merged"),Q=I==="merged",A=p&&!w&&!q?"party":n==="yearend"?"santa":n==="newyear"?"party":null,z=b.moodShown&&((Me=vn[l])==null?void 0:Me.rank)>0,k=b.showsPanes&&u!=null&&!z,W=x2({activity:e,view:b,kind:m,duty:o,working:u,walled:c,mirroring:k}),Z=w?r(u2,{x0:g}):M?null:z?r(w2,{x0:g,mood:l}):q?r(Zl,{closed:!0,x0:g}):O?r(bo,{x0:g}):I==="api"?r(vy,{x0:g}):I==="update"?r(Jy,{x0:g}):!I&&(y!=null&&y.smile)?r(bo,{x0:g}):r(Zl,{x0:g}),_=!M||w||q||z?null:O?"happy":I==="api"?"x":I==="update"?"down":I==="ctx"?"worried":!I&&(y!=null&&y.smile)?"happy":null,X=M&&(y==null?void 0:y.Held)===Ja?"goggles":M&&(y==null?void 0:y.Held)===Qa?"scarf":null,he=M?n2[e]??null:null,fe=he==="spoon"||he==="leash"?xg(M,he,T):null,He=he==="bass"?Fs(T,[g+po.dx,po.y]):null,Ae=M&&(z?Ty:L?Ey:null),ue=He??(Ae?Fs(T,Ae):null);return r("svg",{viewBox:"0 0 34 24","shape-rendering":"crispEdges","aria-hidden":"true","data-activity":e,"data-occasion":n||void 0,"data-mood":z?l:void 0,"data-duty":m||void 0,"data-pose":I||void 0,"data-urgent":o!=null&&o.urgent?"":void 0,"data-working":k?Math.min(u,4):void 0,"data-critter":M?h.id:void 0,"data-tempo":y==null?void 0:y.tempo,"data-stride":y!=null&&y.stride?"":void 0,style:y&&`--tama-tempo: ${y.tempo}s`,children:[r("rect",{x:"0",y:"19",width:"34",height:"0.4",fill:"var(--line)"}),(n==="newyear"||Q)&&r(p2,{clear:!!o}),y?r(b2,{p:y,season:t,trick:f,critter:h,from:fe}):r(y2,{activity:e==="nap"?"code":e,occasion:n,coffee:i,ringing:F,keyboard:!(L||x&&m==="ctx"),mood:z?l:"calm",screen:W,dish:d,mugHeld:he==="mug"}),n==="halloween"&&E&&r(l2,{...E}),r("g",{transform:v?`translate(0 ${-v})`:void 0,children:r("g",{class:`tama-creature${a?" tama-hop":""}`,children:[M?r("g",{class:"tama-critter",style:"transform-box: view-box",transform:`translate(${T.tx} ${T.ty}) scale(${T.scale})`,children:[r(Gi,{sprite:M,mood:z?l:"calm",asleep:q,face:_,startle:I==="bell"&&!L,worn:X,holding:he,tip:ue,paws:!!(y!=null&&y.paws),cheer:x&&O,seated:$,stride:!!(y!=null&&y.stride),children:He&&r("g",{style:"transform-box: view-box",transform:`scale(${1/T.scale}) translate(${-T.tx} ${-T.ty})`,children:r(dd,{x0:g,limb:M.limb})})}),r(c2,{sprite:M,p:y,hat:A,season:t,ghost:w}),he&&r(hd,{sprite:M,kind:he,scale:T.scale})]}):r(nt,{cells:y!=null&&y.paws?Xy:bd,cls:"tama-body",x0:g}),Z,(y==null?void 0:y.Held)&&!(M&&(t2.has(y.Held)||he))&&r(y.Held,{x0:g}),he==="spoon"&&r(gd,{x0:g,from:fe}),he==="controller"&&r("g",{transform:`translate(0 ${Math.min(T.drop,.8)})`,children:r(fd,{x0:g,limb:M.limb})}),!M&&r(zn,{dy:S,children:(y==null?void 0:y.Headwear)&&!A&&r(y.Headwear,{x0:g})}),r(zn,{dy:S,children:I==="api"&&r(xy,{x0:g})}),!M&&I==="ctx"&&r(_y,{x0:g}),!M&&x&&O&&r($y,{x0:g}),x&&I==="ci"&&r(Fy,{}),!M&&L&&r(Cy,{}),M&&z&&r(Py,{limb:M.limb}),M&&L&&r(Ay,{limb:M.limb}),!M&&r(zn,{dy:S,children:I==="bell"&&!L&&r(Sy,{x0:g})}),!M&&!$&&r(nt,{cells:Ql[0],cls:"tama-legs-a",x0:g,y0:Yl}),!M&&(y==null?void 0:y.stride)&&r(nt,{cells:Ql[1],cls:"tama-legs-b",x0:g,y0:Yl}),w&&(y==null?void 0:y.pail)&&r(d2,{x0:g}),!M&&r(zn,{dy:S,children:[(y==null?void 0:y.snowcap)&&t==="winter"&&!A&&!w&&r("rect",{class:"tama-snowcap",x:g+3,y:"8.4",width:"12",height:"0.7",rx:"0.3",fill:"#f4f8fb"}),A==="santa"&&r(kd,{x0:g}),A==="party"&&r(wd,{x0:g})]})]},s)}),(y==null?void 0:y.Front)&&r(y.Front,{}),r(k2,{activity:e}),(x||L)&&r(S2,{kind:m}),e==="nap"&&!F&&r(Gy,{}),F&&e==="sleep"&&r(Ly,{}),O&&r(Iy,{}),z&&r(v2,{mood:l,x0:g,coffee:i,hat:A,headDy:S}),(n==="newyear"||Q)&&r(m2,{}),o&&r(wy,{kind:m,label:o.label,urgent:o.urgent,more:o.more,x0:g}),a&&r("g",{transform:`translate(${g-8} 0)`,children:r("path",{class:"tama-heart",fill:"#e8657a","shape-rendering":"geometricPrecision",d:"M17 7.2 l-2.3 -2.3 a1.25 1.25 0 0 1 2.3 -1.7 a1.25 1.25 0 0 1 2.3 1.7z"})},`heart-${s}`)]})}const C2=Vt(()=>au(gu())),vd=e=>e.map(t=>[t.since*1e3,t.until==null?1/0:t.until*1e3]),_o=e=>({...rd(Aa(),e),walls:vd(ga.value)});function T2(){const[e,t]=B(()=>new Date),[n,i]=B(0),[l,a]=B(!1),o=al(()=>{const O=Aa();return JSON.stringify([O.merged??null,O.furious??null,ga.value])}).value,[u,c,p]=JSON.parse(o),d={...rd({merged:u,furious:c},e),walls:vd(p)},f=te(o);j(()=>{if(f.current!==o){f.current=o,t(new Date);return}const O=setTimeout(()=>t(new Date),td(e,d)+50);return()=>clearTimeout(O)},[e,o]),j(()=>{const O=setInterval(()=>{const Q=new Date;t(A=>no(Q,_o(Q))===no(A,_o(A))?A:Q)},6e4);return()=>clearInterval(O)},[]),j(()=>{if(!l)return;const O=setTimeout(()=>a(!1),900);return()=>clearTimeout(O)},[l,n]);const h=$c(0);j(()=>{const O=setInterval(()=>{h.value+=1},6e4);return()=>clearInterval(O)},[]),j(()=>{L0()},[]);const m=C2.value,b=al(()=>{var z;h.value;const O=(z=Ri.value)==null?void 0:z.plan,Q=T0(O,Date.now()/1e3),A=Q.account&&$n()?yn(Q.account):null;return JSON.stringify([Q.mood,E0(Q,A)])}),[x,w]=JSON.parse(b.value);j(()=>{x==="furious"&&bu("furious",nd(new Date))},[x,Qi(e)]);const C=al(()=>{h.value;const O=Date.now()/1e3,Q=r0({windows:ce.value||[],alerts:nr.value||[],dismissedAlertIds:ir.value,dismissedNeedsPids:ft.value,dismissedReadyPids:pt.value,selectedPid:qu(ke.value),parties:pr.value,update:ma.value,nowSec:O}),A=Tc.value;return JSON.stringify({items:Q,more:i0(Q),wall:A&&a0(A.until,O),working:nr.value===null?null:Su(ce.value).length})}),y=JSON.parse(C.value),g=y.items[0]||null,$=fr(e,d),v=v0(e,d),E=Yi(e),M=sd(e),T=Wu($.id,g==null?void 0:g.kind),S=ro($,T.moodShown?x:"calm"),R=[...y.wall&&Zu(e,d)?[s0(y.wall)]:[],...y.items.map(O=>O.phrase),...T.showsPanes&&y.working?[`${wn(y.working,"agent")} working`]:[],...T.moodShown&&w?[w]:[],...M?[M]:[],...v?[`up next at ${P0(v.at)}: ${ro(v.activity)}`]:[]],F=`${m.sprite?m.name:"Claude"} is ${S} (${Gl($.from)}–${Gl($.to)})${R.map(O=>` · ${O}`).join("")}`+(g!=null&&g.target?` · click to ${g.target.says}`:"");function q(){i(O=>O+1),a(!0)}const L=te(g);L.current=g;const[I]=B(()=>G0({target:()=>{var O;return(O=L.current)==null?void 0:O.target},pet:q}));return j(()=>()=>I.dispose(),[]),r("button",{type:"button",class:"tama",title:F,"aria-label":F,onClick:I.onClick,onDblClick:I.onDblClick,children:r($2,{activity:$.id,dish:$.dish,trick:!!$.trick,season:xr(e),occasion:E==null?void 0:E.id,coffee:!!$.coffee,mood:x,petted:l,petKey:n,duty:g&&{kind:g.kind,label:g.label,urgent:!!g.urgent,more:y.more,pct:g.pct,cost:g.cost},working:y.working,walled:y.wall,party:y.items.some(O=>O.kind==="merged"),critter:m})})}const xo=["session","week_all","week_opus","week_sonnet"];function E2(e){const t=Object.keys(e).filter(n=>!xo.includes(n)).sort();return[...xo,...t].filter(n=>e[n]).map(n=>({key:n,label:Ua(n),m:e[n]}))}function P2(e){const t=lt.value.map(i=>i.id).filter(i=>e.includes(i)),n=e.filter(i=>!t.includes(i)).sort();return[...t,...n]}function A2(e,t){return e?P2(Object.keys(e)).map(n=>{const i=e[n]||{},l=i.available&&i.meters?E2(i.meters):[],a=l.length>0,s=a?l.reduce((o,u)=>(u.m.percent||0)>(o.m.percent||0)?u:o):null;return{id:n,label:yn(n),available:a,stale:a&&Ha(i,t),fetchedAt:i.fetched_at||null,meters:l,headline:s}}):[]}function M2(e){const t=(e.meters||[]).filter(n=>n!==e.headline);return{hot:t.filter(n=>n.m.hot),blow:t.filter(n=>!n.m.hot&&qa(n.m))}}const L2=48*3600;function _d(e){return e==="week_fable"||e.startsWith("week_fable_")}function I2(e,t){const n=(e==null?void 0:e.available)&&e.meters||{},i=Object.keys(n).find(_d),l=i&&n[i];if(!l||l.projected_percent==null||!l.resets_at)return!1;const a=l.resets_at-t;return l.projected_percent<100&&a>0&&al!=null);if(!t.length)return null;const n=Math.min(...t),i=Math.max(...t);return i<=e.percent?null:{text:i-n>10?`→${n}–${i}%`:`→${i}%`,blow:qa(e)}}function D2({a:e}){const{hot:t,blow:n}=M2(e);if(!t.length&&!n.length)return null;const i=[...t.map(l=>`${l.label}: burning 🔥`),...n.map(l=>`${l.label}: on track to hit its limit`)];return r("span",{class:`usage-acct-more${t.length?"":" blow"}`,title:[...i,"(click to show every meter)"].join(` +`),children:t.length?"🔥":"→"})}function R2({label:e,m:t,resets:n,pace:i}){const l=t.percent,a=l>=90?"danger":l>=70?"warn":"ok",s=[`${e} — ${l}% used. ${n||""}`,...i].join(` +`),o=O2(t);return r("div",{class:"usage-item",title:s,children:[r("span",{class:"usage-item-label",children:e}),r("span",{class:"usage-item-bar",children:r("span",{class:`usage-item-fill ${a}`,style:`width:${l}%`})}),r("b",{children:[l,"%"]}),o&&r("span",{class:`usage-item-proj${o.blow?" blow":""}`,children:o.text}),t.hot&&r("span",{class:"usage-item-hot",children:"🔥"})]})}const Xl=H(!1);function Cd(){Xl.value=!0}function F2(e,t,n,i){const l=e.meters.map(({m:a})=>[`${a.label}: ${a.percent}% used`,Sd(a.resets_at),...$d(a)].filter(Boolean).join(` + `));if(n){const a=n.verified?`resets ${Si(n.resets_at)}`:"not anchored";l.push(`poked ${Si(n.at)} → ${a}`)}if(i){const a=e.meters.find(({key:s})=>_d(s));a&&l.push(`💤 fable on pace for ${a.m.projected_percent}% at reset — burn it or lose it`)}return e.stale&&l.push(`⚠ stale — last updated ${Pe(e.fetchedAt)} ago`),l.push(t?"(click to collapse)":"(click to show every meter)"),[`account ${e.label}`,...l].join(` -`)}function T2(){const e=Ql.value,t=Oi.value||{},n=t.fallback,i=Math.floor(Date.now()/1e3),l=k2(t.plan,i),a=Sn(),s=new Set(Object.keys(t.plan||{}).filter(c=>_2(t.plan[c],i)));if(l.some(c=>c.available))return r("div",{id:"usage",class:`usage${e?" is-expanded":""}`,onClick:()=>{Ql.value=!e},children:l.map(c=>{var f;return r("div",{class:`usage-acct${c.stale?" is-stale":""}`,title:C2(c,e,(f=t.poke)==null?void 0:f[c.id],s.has(c.id)),children:[a&&r("span",{class:"usage-acct-label",children:c.label}),c.available?(e?c.meters:[c.headline]).map(({key:d,label:p,m:h})=>r($2,{label:p,m:h,resets:kd(h.resets_at),pace:wd(h)},d)):r("span",{class:"usage-acct-off",title:"no usable credential for this account",children:"no data"}),!e&&c.available&&r(S2,{a:c}),c.stale&&r("span",{class:"usage-stale-mark",children:"⚠"}),s.has(c.id)&&r("span",{class:"usage-acct-waste",title:"Fable budget on pace to go unused at reset",children:"💤"})]},c.id)})});if(!(n!=null&&n.available))return r("div",{id:"usage",class:"usage"});const o=(n.input_tokens||0)+(n.cache_creation_tokens||0)+(n.output_tokens||0),u=`Claude Code plan usage estimate (JSONL-derived; plan fetch not yet ready) +`)}function N2(){const e=Xl.value,t=Ri.value||{},n=t.fallback,i=Math.floor(Date.now()/1e3),l=A2(t.plan,i),a=$n(),s=new Set(Object.keys(t.plan||{}).filter(c=>I2(t.plan[c],i)));if(l.some(c=>c.available))return r("div",{id:"usage",class:`usage${e?" is-expanded":""}`,onClick:()=>{Xl.value=!e},children:l.map(c=>{var p;return r("div",{class:`usage-acct${c.stale?" is-stale":""}`,title:F2(c,e,(p=t.poke)==null?void 0:p[c.id],s.has(c.id)),children:[a&&r("span",{class:"usage-acct-label",children:c.label}),c.available?(e?c.meters:[c.headline]).map(({key:d,label:f,m:h})=>r(R2,{label:f,m:h,resets:Sd(h.resets_at),pace:$d(h)},d)):r("span",{class:"usage-acct-off",title:"no usable credential for this account",children:"no data"}),!e&&c.available&&r(D2,{a:c}),c.stale&&r("span",{class:"usage-stale-mark",children:"⚠"}),s.has(c.id)&&r("span",{class:"usage-acct-waste",title:"Fable budget on pace to go unused at reset",children:"💤"})]},c.id)})});if(!(n!=null&&n.available))return r("div",{id:"usage",class:"usage"});const o=(n.input_tokens||0)+(n.cache_creation_tokens||0)+(n.output_tokens||0),u=`Claude Code plan usage estimate (JSONL-derived; plan fetch not yet ready) ${n.messages} assistant messages - ${hl(o)} active tokens - ${hl(n.cache_read_tokens)} cache reads (discounted)`;return r("div",{id:"usage",class:"usage usage-fallback",title:u,children:`5h: ${hl(o)} · ${bd(n.reset_at)}`})}function E2({id:e,toggleClass:t,toggleLabel:n,title:i,children:l}){const[a,s]=B(!1),o=ne(null),u=Pi(()=>s(!1),[]);return He(u,a),j(()=>{if(!a)return;function c(f){o.current&&!o.current.contains(f.target)&&s(!1)}return document.addEventListener("click",c),()=>document.removeEventListener("click",c)},[a]),r("div",{class:"tb-dd",ref:o,children:[r("button",{type:"button",class:t,id:e,"aria-haspopup":"menu","aria-expanded":a?"true":"false",title:i,onClick:c=>{c.stopPropagation(),s(f=>!f)},children:n}),r("div",{class:"tb-dd-menu",role:"menu",hidden:!a,onClick:()=>s(!1),children:l})]})}function P2(){const e=de.value,t=e.length,n=e.filter(o=>o.state==="needs-input").length,i=e.filter(o=>o.state==="working").length,l=e.filter(o=>o.state==="done").length,a=e.filter(o=>o.state==="idle").length,s=()=>r("span",{class:"count-sep",children:"·"});return r("span",{id:"counts",children:[r("span",{children:[r("b",{children:t})," windows"]}),n>0&&r(V,{children:[" ",r(s,{})," ",r("span",{class:"count-needs",children:[n," needs input"]})]})," ",r(s,{})," ",r("span",{class:"count-working",children:[i," working"]})," ",r(s,{})," ",r("span",{class:"count-done",children:[l," done"]})," ",r(s,{})," ",r("span",{class:"count-idle",children:[a," idle"]})]})}function A2(){j(()=>{function t(n){(n.metaKey||n.ctrlKey)&&n.key==="/"&&(ye("key.shortcut",{key:"cmd+/"}),n.preventDefault(),window.location.href="/history")}return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[]);const e=ne(null);return j(()=>{const t=e.current;if(!t)return;const n=()=>document.documentElement.style.setProperty("--header-h",`${t.offsetHeight}px`);n();const i=new ResizeObserver(n);return i.observe(t),()=>i.disconnect()},[]),r("header",{class:"periscope-header",ref:e,"data-pin-rows":Sn()?3:2,children:[r("div",{class:"topbar",children:[r("span",{class:"brand",children:["periscope",r("i",{class:"brand-cursor"})]}),r(T2,{}),r("div",{class:"spawn-pins",children:[r(c1,{}),r(p1,{}),r(d1,{})]}),r(O0,{})]}),r("nav",{class:"filters",id:"filters",children:[r("a",{href:"/history",class:"filter-btn is-action",id:"history-link",title:"search conversation history (⌘/)",children:["🔍 history ",r("span",{class:"ps-kbd",style:"margin-left:4px",children:"⌘"}),r("span",{class:"ps-kbd",children:"/"})]}),r("span",{class:"filters-sep"}),r(s1,{}),r("span",{class:"filters-sep"}),r("button",{type:"button",class:"filter-btn is-action",id:"new-open-btn",title:"open a repo, worktree, or PR",onClick:()=>{var t;return(t=window.__periscopeOpenOmnibox)==null?void 0:t.call(window)},children:"+ new"}),r("button",{type:"button",class:"filter-btn is-action",id:"reviews-btn",title:"open branches, walkthroughs, review comments",onClick:Ia,children:["◉ reviews",Ls(mt.value)?r("span",{class:"rail-review-badge",children:Ls(mt.value)}):null]}),r(E2,{id:"more-dd-toggle",toggleClass:"filter-btn is-action tb-dd-toggle",toggleLabel:"⋯",title:"more actions",children:[r("button",{id:"cleanup-btn",class:"tb-dd-item",role:"menuitem",title:"archive worktrees with merged PRs, deleted branches, or idle activity",children:"🧹 cleanup"}),r("button",{id:"settings-btn",class:"tb-dd-item",role:"menuitem",title:"settings",children:"🛠 settings"}),r("button",{id:"open-commands",class:"tb-dd-item",role:"menuitem",title:"edit + claude / + shell / + ... commands",children:"⚙ commands"})]}),r("span",{class:"filters-sep"}),r(o1,{}),r("div",{class:"meta",children:r(P2,{})})]}),r(g2,{})]})}const M2=3e3;let fl=null,Jr=!1,vo=!1,Bn=!1;function L2(){if(vo)return;vo=!0;const e=window.WebSocket;function t(){return{readyState:0,binaryType:"arraybuffer",send(){},close(){},onopen:null,onmessage:null,onerror:null,onclose:null}}function n(i,l){return Bn&&String(i).includes("/ws/pane")?t():l===void 0?new e(i):new e(i,l)}n.CONNECTING=e.CONNECTING,n.OPEN=e.OPEN,n.CLOSING=e.CLOSING,n.CLOSED=e.CLOSED,n.prototype=e.prototype,window.WebSocket=n}async function I2(e){var w,C;Jr=!0;const t=e.settleMs||2e3,n=e.switches||20,i=(e.kind||"claude")==="claude",l=(de.value||[]).filter(y=>y.agent==="claude"===i&&y.pid),a=Math.max(2,e.poolSize||(((w=e.pids)==null?void 0:w.length)??2)),s=((C=e.pids)==null?void 0:C.length)>=2?e.pids:l.slice(0,a).map(y=>y.pid),o=document.title;if(s.length<2){ye("memtest.abort",{nonce:e.nonce,reason:"need 2 pids"}),Jr=!1;return}const u=ke.value,c=s.map(y=>fu(y)),f=e.mode||"terminal";if(!e.realClick)for(const y of s)jl(y,f);Bn=!!e.blockWs,Bn&&L2();const d=document.getElementById("rail")||document.querySelector(".rail, #left");ye("memtest.start",{nonce:e.nonce,n,mode:f,blockWs:Bn,pids:s,realClick:!!e.realClick,scrollRail:!!e.scrollRail,hoverStorm:!!e.hoverStorm,railScroll:d?{sh:d.scrollHeight,ch:d.clientHeight}:null,noWebgl:(()=>{try{return localStorage.getItem("periscope.noWebgl")==="1"}catch{return null}})()});const p=e.tabPath||null,h=y=>new Promise(g=>setTimeout(g,y));let m=0,b=1;function x(){const y=document.querySelectorAll(".rail-row.pane-row");if(y.length<2)return;const g=Math.min(y.length,Math.max(2,e.poolSize||y.length));m>=g&&(m=g-1);const $=y[m];if(e.scrollRail&&$.scrollIntoView({behavior:"smooth",block:"center"}),e.hoverStorm)for(const v of y)v.dispatchEvent(new MouseEvent("mouseover",{bubbles:!0})),v.dispatchEvent(new MouseEvent("mouseout",{bubbles:!0}));$.click(),m+=b,(m>=g-1||m<=0)&&(b=-b)}for(let y=1;y<=n;y++){const g=s[y%s.length];e.realClick?x():ke.value=`pane:${g}`,document.title=`memtest ${y}/${n}`,await h(p?t/3:t),p&&(gr({path:p}),await h(t/3),Nr(g,"pane"),await h(t/3)),y%5===0&&ye("memtest.progress",{nonce:e.nonce,i:y})}if(p)for(const y of s)Tc(y,p);if(Bn=!1,!e.realClick)for(const[y,g]of s.entries())jl(g,c[y]||"terminal");ke.value=u,e.realClick&&(u!=null&&u.startsWith("pane:"))&>({kind:"pane",pid:u.slice(5)}),document.title=o,ye("memtest.done",{nonce:e.nonce,n,mode:f}),Jr=!1}async function _o(){try{const e=await fetch("/memtest.json",{cache:"no-store"});return e.ok?await e.json():null}catch{return null}}async function O2(){const e=await _o();e!==null&&(fl=e.nonce??null,setInterval(async()=>{if(Jr)return;const t=await _o();!t||t.nonce==null||t.nonce===fl||(fl=t.nonce,I2(t))},M2))}const hn=H([]);let D2=1;function R2(e){return new Promise(t=>{hn.value=[...hn.value,{...e,id:D2++,resolve:t}]})}function Ln(e,t){const n=hn.value.find(i=>i.id===e);hn.value=hn.value.filter(i=>i.id!==e),n&&n.resolve(t)}function Jn(e,t={}){return R2({type:"confirm",message:e,okLabel:t.okLabel||"OK",cancelLabel:t.cancelLabel||"Cancel",danger:!!t.danger})}function F2(e){return String(e??"").split(` -`).map((n,i)=>r(V,{children:[i>0?r("br",{}):null,n]}))}function N2({req:e}){const t=ne(null),n=ne(null),i=e.type==="confirm"&&e.danger,l=e.type==="confirm"?!1:e.type==="prompt"?null:void 0;He(()=>Ln(e.id,l)),j(()=>{var f,d;const c=t.current;if(c&&!c.open&&c.showModal(),e.type==="prompt"){const p=n.current;p&&(p.focus(),p.select())}else i?(f=c==null?void 0:c.querySelector(".confirm-dialog-cancel"))==null||f.focus():(d=c==null?void 0:c.querySelector(".confirm-dialog-ok"))==null||d.focus()},[]);const a=()=>{var c;e.type==="prompt"?Ln(e.id,((c=n.current)==null?void 0:c.value)??""):e.type==="alert"?Ln(e.id,void 0):Ln(e.id,!0)},s=()=>Ln(e.id,l),o=c=>{c.target===t.current&&s()},u=e.type==="prompt"?"confirm-dialog prompt-dialog":"confirm-dialog";return r("dialog",{ref:t,class:u,onClick:o,children:[r("p",{class:"confirm-dialog-msg",children:F2(e.message)}),e.type==="prompt"&&r("input",{ref:n,type:"text",class:"prompt-dialog-input",autocomplete:"off",spellcheck:!1,value:e.defaultValue,placeholder:e.placeholder||void 0,onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),a())}}),r("div",{class:"confirm-dialog-actions",children:[e.type!=="alert"&&r("button",{type:"button",class:"confirm-dialog-cancel",onClick:s,children:e.cancelLabel}),r("button",{type:"button",class:`confirm-dialog-ok${i?" is-danger":""}`,onClick:a,children:e.okLabel})]})]})}function B2(){const e=hn.value;return r(V,{children:e.map(t=>r(N2,{req:t},t.id))})}async function pr(e,t,n={}){let i;try{i=await fetch(t,n)}catch(a){return{error:`${e} failed: ${a.message}`,reason:a.message}}let l={};try{l=await i.json()}catch{}if(!i.ok){const a=l.detail||`HTTP ${i.status}`;return{error:l.detail||`${e} failed: ${a}`,reason:a,status:i.status}}return{data:l}}const rn=H(!1),Nt=H(null);function z2(e){return Array.isArray(e)?e.filter(Boolean):null}function j2(e,t){return e===t?!0:!e||!t?!1:e.length===t.length&&e.every((n,i)=>n===t[i])}function _d(e){const{paths:t}=e||{},n=z2(t);j2(n,Nt.value)||(Nt.value=n),rn.value=!0,ye("overlay.open",{which:"cleanup",scoped:!!Nt.value})}function H2(e){return e!=null&&e.length?`/api/cleanup/candidates?${e.map(t=>`paths=${encodeURIComponent(t)}`).join("&")}`:"/api/cleanup/candidates"}function In(){rn.value=!1,Nt.value=null}function q2(){He(In,rn.value);const[e,t]=B(""),[n,i]=B(!1),[l,a]=B([]),[s,o]=B({}),[u,c]=B(!1),[f,d]=B(!1),p=ne(0);j(()=>{const x=document.getElementById("cleanup-btn"),w=()=>_d();return x&&x.addEventListener("click",w),()=>{x&&x.removeEventListener("click",w)}},[]);async function h(){const x=++p.current;t(""),i(!0),a([]),o({});const w=Nt.peek();if(w&&w.length===0){i(!1);return}const{data:C,error:y}=await pr("load candidates",H2(w));if(x!==p.current)return;if(i(!1),y){t(y),a([]);return}const g=C.candidates||[];a(g);const $={};g.forEach((v,E)=>{$[E]=!v.dirty}),o($)}j(()=>{if(!rn.value){p.current++;return}c(!1),h()},[rn.value,Nt.value]);const m=Object.values(s).filter(Boolean).length;async function b(){t("");const x=[];if(l.forEach((y,g)=>{s[g]&&x.push({pinned_dir:y.pinned_dir,delete_branch:u})}),x.length===0)return;d(!0);const{data:w,error:C}=await pr("archive","/api/cleanup/archive",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({candidates:x})});if(d(!1),C){t(C);return}if(w.failed&&w.failed.length>0){const y=`Archived ${w.archived.length}, ${w.failed.length} failed: `+w.failed.map(g=>`${g.pinned_dir.split("/").pop()}: ${g.error}`).join("; ");await h(),t(g=>g||y);return}In()}return rn.value?r("div",{id:"cleanup-modal",class:"cleanup-modal-overlay",onClick:x=>{x.target.id==="cleanup-modal"&&In()},children:r("div",{class:"cleanup-modal-card",children:[r("header",{class:"cleanup-modal-head",children:[r("h2",{children:"🧹 cleanup"}),r("button",{id:"cleanup-modal-close",title:"close",onClick:In,children:"×"})]}),r("p",{class:"cleanup-modal-sub",children:"Worktrees with merged/closed PRs, deleted remote branches, or idle activity. Dirty worktrees are NOT auto-selected."}),r("div",{id:"cleanup-modal-controls",children:r("label",{class:"cleanup-delete-branches",children:[r("input",{type:"checkbox",id:"cleanup-delete-branches",checked:u,onChange:x=>c(x.currentTarget.checked)})," also delete local branches"]})}),r("div",{id:"cleanup-modal-list",children:n?r("div",{class:"cleanup-loading",children:"Walking worktrees…"}):l.length===0&&!e?r("div",{class:"cleanup-empty",children:Nt.value?"Nothing to clean up here. Cleanup only offers a worktree (never a main checkout) whose PR is merged or closed, whose remote branch is gone, or that sits idle.":"No cleanup candidates. 🎉"}):l.map((x,w)=>{const C=x.project_name||`(untracked: ${x.pinned_dir.split("/").pop()})`;return r("label",{class:x.dirty?"cleanup-row cleanup-row-dirty":"cleanup-row","data-i":w,children:[r("input",{type:"checkbox",class:"cleanup-row-check",checked:!!s[w],onChange:y=>o(g=>({...g,[w]:y.currentTarget.checked}))}),r("div",{class:"cleanup-row-body",children:[r("div",{class:"cleanup-row-title",children:C}),r("div",{class:"cleanup-row-meta",children:[x.branch," ",x.dirty?r("span",{class:"cleanup-dirty",children:"⚠ dirty"}):null]}),r("div",{class:"cleanup-row-signals",children:(x.signals||[]).map((y,g)=>r("span",{class:`cleanup-badge cleanup-badge-${y.kind}`,children:y.label},g))})]})]},x.pinned_dir)})}),r("div",{id:"cleanup-modal-error",class:"cleanup-modal-error",hidden:!e,children:e}),r("div",{class:"cleanup-modal-actions",children:[r("button",{type:"button",id:"cleanup-cancel",onClick:In,children:"cancel"}),r("button",{type:"button",id:"cleanup-submit",disabled:n||f||m===0,onClick:b,children:["archive selected (",m,")"]})]})]})}):null}const _i=H(!1);function xo(){_i.value=!0,ye("overlay.open",{which:"commands"})}function pl(){_i.value=!1}function U2({c:e,i:t,onDragState:n}){const i=ne(null);async function l(s){const o=i.current;if(!o)return;const u=o.querySelector(".commands-label").value.trim(),c=o.querySelector(".commands-exec").value;u&&await Pg(e.label,{label:u,exec:c})}async function a(){await Ag(e.label)}return r("div",{ref:i,class:"commands-row",draggable:!0,"data-label":e.label,"data-i":t,onDragStart:s=>{var o;n(e.label),(o=i.current)==null||o.classList.add("dragging"),s.dataTransfer.setData("text/plain",e.label),s.dataTransfer.effectAllowed="move"},onDragEnd:()=>n(null),onDragOver:s=>{s.preventDefault(),s.dataTransfer.dropEffect="move";const o=i.current.getBoundingClientRect(),u=s.clientY{var s;(s=i.current)==null||s.classList.remove("drag-over-top","drag-over-bottom")},onDrop:s=>{s.preventDefault();const o=i.current.getBoundingClientRect(),u=s.clientY{const l=document.getElementById("open-commands");return l&&l.addEventListener("click",xo),()=>{l&&l.removeEventListener("click",xo)}},[]);const e=ne(null),t=l=>{e.current=l};t.drop=(l,a)=>{const s=e.current;if(!s||l===s)return;const o=Hr().map(d=>d.label),u=o.indexOf(s);if(u<0)return;o.splice(u,1);const c=o.indexOf(l),f=a?c:c+1;o.splice(f,0,s),Mg(o)};async function n(){const l="command";let a=l,s=1;const o=new Set(Hr().map(u=>u.label));for(;o.has(a);)a=`${l}-${++s}`;await Eg({label:a,exec:""})}if(!_i.value)return null;const i=Hr();return r("div",{id:"commands-modal",class:"commands-modal-overlay",onClick:l=>{l.target.id==="commands-modal"&&pl()},children:r("div",{class:"commands-modal-card",children:[r("header",{class:"commands-modal-head",children:[r("h2",{children:"New-window commands"}),r("button",{id:"commands-modal-close",title:"close",onClick:pl,children:"×"})]}),r("p",{class:"commands-modal-sub",children:["First row is the primary button. Drag rows to reorder. Empty ",r("code",{children:"exec"})," = bare shell."]}),r("div",{id:"commands-modal-list",children:i.map((l,a)=>r(U2,{c:l,i:a,onDragState:t},l.label))}),r("button",{id:"commands-modal-add",class:"commands-modal-add",onClick:n,children:"+ add command"})]})})}const xd=[{id:"default",label:"default"},{id:"full",label:"full"}];function ml(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}function K2(e){return!e||e==="default"?null:e}function So(e){var t;return((t=xd.find(n=>n.id===e))==null?void 0:t.label)||e}const $o=["shell","idle","done","working","needs-input"];function Co(e){let t=-1;for(const n of e){const i=$o.indexOf(n);i>t&&(t=i)}return t>=0?$o[t]:"shell"}const Sd="";function Ga(e,t,n,i={},l=[]){const a=i.trackOrder||[],s=i.tabsByTrack||{},o=i.branchOrderByTrack||{},u=[],c={},f={},d={},p={};for(const v of e||[]){const E=v.track_id;if(!E)continue;const A=v.branch||Sd;c[E]||(u.push(E),c[E]=[],f[E]=[],d[E]={}),c[E].includes(v.pid)||c[E].push(v.pid),f[E].includes(A)||f[E].push(A),d[E][A]||(d[E][A]=[]),d[E][A].includes(v.pid)||d[E][A].push(v.pid),p[v.pid]=A}const h=(l||[]).filter(v=>v.id&&v.id!==v.repo).map(v=>v.id),m=new Set(h),b=new Set(u),x=a.filter(v=>b.has(v)||m.has(v)),w=new Set(x),C=[...x,...u.filter(v=>!w.has(v)),...h.filter(v=>!w.has(v)&&!b.has(v))],y={},g={},$={};for(const v of C){const E=c[v]||[],A=new Set(E),T=(s[v]||[]).filter(O=>A.has(O)),S=new Set(T);y[v]=[...T,...E.filter(O=>!S.has(O))];const R=f[v]||[],F=new Set(R),q=(o[v]||[]).filter(O=>F.has(O)),L=new Set(q),I=[...q,...R.filter(O=>!L.has(O))];if(I.length>=2){g[v]=I,$[v]={};for(const O of I)$[v][O]=[];for(const O of y[v]){const Q=p[O];$[v][Q]&&$[v][Q].push(O)}}else g[v]=[]}return{trackOrder:C,tabsByTrack:y,branchesByTrack:g,tabsByBranch:$}}function xi(e,t,n=[]){for(const l of t||[])if(l.track_id===e&&l.track_name)return l.track_name;for(const l of n||[])if(l.id===e&&l.name)return l.name;if(e==="loose")return"loose";const i=String(e||"").split("/").filter(Boolean);return i[i.length-1]||e}function V2(e,t,n=[]){if(e==="loose")return"loose";for(const i of t||[])if(i.track_id===e&&i.track_kind)return i.track_kind;for(const i of n||[])if(i.id===e)return i.repo===i.id?"repo":"goal";return"repo"}function G2(e){return String(e||"").replace(/^\/(?:Users|home)\/[^/]+/,"~")}function J2(e){const t=e.worktree_affiliation||{};if(t.kind==="sibling")return t.label||null;if(t.kind==="no-repo"||t.kind==="off-repo"){if(e.repo_key&&e.repo_label)return e.branch?`${e.repo_label}/${e.branch}`:e.repo_label;if(e.cwd)return G2(e.cwd)}return null}function Q2(e,t,n,i){const l={};for(const a of i||[])if(a.walkthrough){for(const s of e)if((t[s]||[]).map(u=>n[u]).find(u=>u&&u.repo_label===a.repo&&(u.branch||Sd)===a.branch)){l[s]||(l[s]={}),l[s][a.branch]||(l[s][a.branch]=[]),l[s][a.branch].push(a);break}}return l}const Ut=H(null),Ue=H(null),Xe=H(null),Tt=H(""),Qr=H("default"),Yr=H("default"),Zr=H("default"),Xr=H("default");function Y2(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}const Si=H(null);function $d(e,t){const n=new Map;for(const i of t||[]){if(i.track_id!==e)continue;const l=i.branch;l&&(n.has(l)||n.set(l,i.cwd||""))}return[...n.entries()].map(([i,l])=>({branch:i,cwd:l}))}function Z2(e,t,n,i){const l=[],a=new Set;for(const o of $d(e,t))a.add(o.branch),l.push({...o,live:!0});if(!n||!i)return l;for(const o of i.worktrees||[])o.repo!==n||!o.branch||a.has(o.branch)||(a.add(o.branch),l.push({branch:o.branch,cwd:o.path,live:!1}));const s=(i.repos||[]).find(o=>o.repo===n);for(const o of(s==null?void 0:s.branches)||[])!o||a.has(o)||(a.add(o),l.push({branch:o,cwd:"",live:!1}));return l}function X2(e,t,n=5){const i=[],l=new Set,a=s=>{!s||l.has(s.branch)||(l.add(s.branch),i.push(s))};a(e.find(s=>s.branch===t));for(const s of e)s.live&&a(s);for(const s of e){if(i.length>=n)break;a(s)}return i}function eb(e,t){const n=String(t||"").toLowerCase().split(/[\s/]+/).filter(Boolean);return n.length?e.filter(i=>{const l=i.branch.toLowerCase();return n.every(a=>l.includes(a))}):[]}function tb(e){const t=[{id:"claude",label:"Claude",mode:"agent",agent:"claude"},{id:"codex",label:"Codex",mode:"agent",agent:"codex"}],n=new Set(["claude","codex"]),i=(e||[]).filter(l=>!n.has((l.label||"").trim().toLowerCase())).map(l=>({id:`cmd:${l.label}`,label:l.label,mode:"shell",exec:l.exec||""}));return[...t,...i]}const nb=Vt(()=>Z2(Ut.value,de.value,Ja(Ut.value),Si.value));function Ja(e){var t;return((t=(Bt.value||[]).find(n=>n.id===e))==null?void 0:t.repo)||null}function rb(e){var n,i;const t=Ja(e);return t&&((i=(((n=Si.value)==null?void 0:n.repos)||[]).find(l=>l.repo===t))==null?void 0:i.default_branch)||null}function To(e){var n,i,l;Ut.value=e;const t=$d(e,de.value);Ue.value=t.length?t[0].branch:null,Xe.value=null,Tt.value="",Qr.value=((n=sn.value)==null?void 0:n.account)||"default",Zr.value=((i=sn.value)==null?void 0:i.model)||"default",Xr.value=((l=sn.value)==null?void 0:l.effort)||"default",Yr.value=Ng(),ye("overlay.open",{which:"launcher"}),Si.value=null,ie("open catalog","/api/open/catalog").then(a=>{Ut.value===e&&(Si.value=a)})}function Mr(){Ut.value=null,Ue.value=null,Xe.value=null,Tt.value=""}function Eo(e){Ue.value=e,Xe.value=null}function ib(){Ue.value=null,Xe.value=""}function lb(){He(Mr,Ut.value!=null),j(()=>(window.__periscopeOpenLauncher=To,()=>{window.__periscopeOpenLauncher===To&&delete window.__periscopeOpenLauncher}),[]);const e=Ut.value;if(e==null)return null;const t=Hr(),n=nb.value,i=Ja(e),l=n.length>0||Xe.value!=null||!!i;async function a(p){const h=new URLSearchParams({session:e,agent:p.agent||"claude",mode:p.mode});p.mode==="shell"&&p.exec&&h.set("exec",p.exec),Y2(p)&&h.set("account",Qr.value);const m=ml(p)?K2(Yr.value):null;m&&h.set("profile",m),ml(p)&&h.set("model",Zr.value),ml(p)&&h.set("effort",Xr.value);const b=Xe.value;if(b!=null&&b.trim())h.set("branch",b.trim());else if(Ue.value!=null){const x=n.find(w=>w.branch===Ue.value);x!=null&&x.cwd?h.set("cwd",x.cwd):x&&h.set("branch",x.branch)}await ie("new window",`/api/window/new?${h.toString()}`,{method:"POST"}),Mr()}const s=tb(t),o=s[0],u=Tt.value.trim(),c=u?eb(n,u).slice(0,24):X2(n,rb(e)),f=Ue.value!=null&&!c.some(p=>p.branch===Ue.value)?n.find(p=>p.branch===Ue.value):null,d=f?[f,...c]:c;return r("div",{id:"launcher-modal",class:"launcher-modal-overlay",onClick:p=>{p.target.id==="launcher-modal"&&Mr()},children:r("div",{class:"launcher-modal-card",children:[r("header",{class:"launcher-modal-head",children:[r("h2",{children:"+ New tab"}),r("button",{id:"launcher-close",title:"close",onClick:Mr,children:"×"})]}),r("p",{class:"launcher-modal-sub",id:"launcher-session-name",children:["Add to track: ",xi(e,de.value,Bt.value)]}),l&&r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-head",children:[r("div",{class:"launcher-section-label",children:"Branch"}),r("input",{class:"launcher-branch-search",type:"text",placeholder:n.length>1?`search ${n.length} branches…`:"search branches…",value:Tt.value,onInput:p=>{Tt.value=p.target.value},onKeyDown:p=>{if(p.key==="Escape"&&Tt.value)p.stopPropagation(),Tt.value="";else if(p.key==="Enter"){const h=d[0];h&&Eo(h.branch)}}})]}),r("div",{class:"launcher-branches",children:[d.map(p=>r("button",{class:`launcher-branch${Ue.value===p.branch?" is-active":""}${p.live?"":" is-dormant"}`,title:p.live?"running now":p.cwd||"no worktree yet",onClick:()=>Eo(p.branch),children:["⎇ ",p.branch]},p.branch)),Xe.value==null?r("button",{class:"launcher-branch launcher-branch-new",onClick:ib,children:"+ new branch…"}):r("input",{class:"launcher-branch-input is-active",type:"text",placeholder:"new-branch-name",ref:p=>p==null?void 0:p.focus(),value:Xe.value,onInput:p=>{Xe.value=p.target.value},onKeyDown:p=>{p.key==="Enter"&&o&&a(o)}})]}),u&&d.length===0&&r("div",{class:"launcher-empty",children:["No branch matches “",u,"”."]})]}),Sn()&&r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Account"}),r("div",{class:"launcher-branches",children:at.value.map(p=>r("button",{class:`launcher-branch${Qr.value===p.id?" is-active":""}`,onClick:()=>{Qr.value=p.id},children:p.label},p.id))})]}),r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Profile"}),r("div",{class:"launcher-branches",children:xd.map(p=>r("button",{class:`launcher-branch${Yr.value===p.id?" is-active":""}`,title:p.id==="full"?"the pipeline: superpowers, tom-workflow, codebase-health-check, plus the pipeline direction prompt":"tom-core alone, on the plugin set settings.json enables",onClick:()=>{Yr.value=p.id,Bg(p.id)},children:p.label},p.id))})]}),r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Model"}),r("div",{class:"launcher-branches",children:sr.map(p=>r("button",{class:`launcher-branch${Zr.value===p.id?" is-active":""}`,title:p.id==="default"?"no override — whatever the account's settings.json picks (this launch only; the header pin is the standing default)":`spawn this launch on ${p.label} (ANTHROPIC_MODEL on the pane — a hand re-run claude there keeps it)`,onClick:()=>{Zr.value=p.id},children:p.label},p.id))})]}),r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Effort"}),r("div",{class:"launcher-branches",children:Oa.map(p=>r("button",{class:`launcher-branch${Xr.value===p?" is-active":""}`,title:p==="default"?"no override — Claude's own choice for the model; /effort works in the pane (this launch only; the header pin is the standing default)":`spawn this launch at ${p} (--effort on the pane's claude; /effort can still change it later)`,onClick:()=>{Xr.value=p},children:p},p))})]}),r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Run"}),r("div",{id:"launcher-list",children:s.map((p,h)=>r("button",{class:`launcher-row${h===0?" is-default":""}`,"data-label":p.label,onClick:()=>a(p),children:[r("span",{class:"launcher-row-label",children:p.label}),h===0&&r("span",{class:"launcher-row-hint",children:"⏎"})]},p.id))})]})]})})}const ab=/github\.com\/([^/]+\/[^/]+)\/pull\/(\d+)/,sb=/^#?(\d+)$/;function ob(e){const t=e.match(ab);if(t)return{repo:t[1],pr:Number(t[2])};const n=e.trim().match(sb);return n?{repo:null,pr:Number(n[1])}:null}const cb=/^(~|\.{0,2}\/)/;function ub(e){const t=(e||"").trim();return!t||!cb.test(t)?null:t.replace(/\/+$/,"")||"/"}function Yt(e,t){return e.toLowerCase().includes(t.toLowerCase())}function db(e,t){var s;const n=(e||"").trim(),i=[];if(!n)return i;"reviews".startsWith(n.toLowerCase())&&n.length>=2&&i.push({kind:"reviews",label:"Reviews · open branches and walkthroughs",sub:"the review queue",descriptor:null});const l=ub(n);l&&!(t.worktrees||[]).some(o=>o.path===l)&&i.push({kind:"open",label:`open path: ${l}`,sub:"register + open",descriptor:{path:l}});for(const o of t.repos||[])(Yt(o.label,n)||Yt(o.repo,n))&&i.push({kind:"worktree",label:`${o.label} · new worktree…`,sub:`off origin/${o.default_branch||"HEAD"}`,repo:o.repo,branches:o.branches,descriptor:null});for(const o of t.repos||[])(Yt(o.label,n)||Yt(o.repo,n))&&i.push({kind:"track",label:`${o.label} · new track…`,sub:"goal-scoped group",repo:o.repo,descriptor:null});for(const o of t.worktrees||[])if(Yt(o.path,n)||Yt(o.branch||"",n)){const u=((s=t.repos.find(c=>c.repo===o.repo))==null?void 0:s.label)||o.repo;i.push({kind:"open",label:`${u} · ${o.branch||"detached"}`,sub:o.path,descriptor:{path:o.path}})}const a=ob(n);return a&&i.push({kind:"pr",label:a.repo?`review PR #${a.pr} in ${a.repo}`:`review PR #${a.pr}`,sub:a.repo||"choose a repo",needsRepo:!a.repo,pr:a}),i.push({kind:"command",label:`⚡ run: ${n}`,text:n}),i}const dt=H(!1);function Po(){dt.value=!0,ye("overlay.open",{which:"open"})}function St(){dt.value=!1}const Ao={open:{group:"Open",icon:"▸"},worktree:{group:"New worktree",icon:"✦"},pr:{group:"Review PR",icon:"◆"},branch:{group:"Branches",icon:"⎇"},newbranch:{group:"Branches",icon:"+"},repo:{group:"Repositories",icon:"◳"},track:{group:"New track",icon:"▧"},command:{group:"Command",icon:"⚡"},reviews:{group:"Reviews",icon:"◉"}},hb=3e3;function fb(e){const[t,n]=B([]);return j(()=>{if(!e)return;let i=!0,l=null;const a=async()=>{const s=await ie("jobs","/api/command/jobs");i&&(Array.isArray(s)&&n(s),l=setTimeout(a,hb))};return a(),()=>{i=!1,l&&clearTimeout(l)}},[e]),t}function pb(e){const[t,n]=B(null);return j(()=>{if(!e){n(null);return}let i=!0;return n(null),(async()=>{const l=await ie("job-turns",`/api/command/jobs/${encodeURIComponent(e)}/turns`);i&&n((l==null?void 0:l.messages)||[])})(),()=>{i=!1}},[e]),{messages:t,pending:t===null}}function mb(e){if(e.role==="system")return"— context compacted —";const t=e.role==="user"?"❯":"⏺",n=e.tool_uses||[];if(n.length){const l=n[0],a=l.input||{},s=a.command||a.file_path||a.path||a.pattern||a.description||a.query||a.url||"",o=n.length>1?` +${n.length-1}`:"";return`${t} ${l.name||"tool"}${s?`(${s})`:""}${o}`}const i=String(e.text||"").split(` -`).find(l=>l.trim())||"";return`${t} ${i}`}function gb(){He(St,dt.value);const[e,t]=B({repos:[],worktrees:[]}),[n,i]=B(""),[l,a]=B(null),[s,o]=B(!1),[u,c]=B(null),[f,d]=B(!1),[p,h]=B(""),[m,b]=B("claude");if(j(()=>{window.__periscopeOpenOmnibox=Po;function $(v){(v.metaKey||v.ctrlKey)&&(v.key==="k"||v.key==="p")&&(v.preventDefault(),dt.value=!dt.value)}return document.addEventListener("keydown",$),()=>{document.removeEventListener("keydown",$),window.__periscopeOpenOmnibox===Po&&delete window.__periscopeOpenOmnibox}},[]),j(()=>{dt.value&&(i(""),a(null),c(null),h(""),b("claude"),(async()=>{const $=await ie("open catalog","/api/open/catalog");$&&t($)})())},[dt.value]),!dt.value)return null;async function x($){if(f)return;d(!0),h("");const v=await ie("open","/api/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...$,agent:m})});if(d(!1),!v){h("open failed");return}Lg(v.ui),v.agent_pid&&(ke.value=`pane:${v.agent_pid}`,gt({kind:"pane",pid:v.agent_pid})),St()}async function w($,v){if(!v)return;d(!0),h("");const E=await ie("create track","/api/tracks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:$||null,name:v})});if(d(!1),!E){h("create track failed");return}St()}async function C($){d(!0),h("");const v=await ie("command","/api/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:$})});if(d(!1),!v){h("command failed");return}c(null),o(!0)}function y($){if($.kind==="reviews"){Ia(),St();return}if($.kind==="open")return x($.descriptor);if($.kind==="command")return C($.text);if($.kind==="pr"&&!$.needsRepo)return x({repo:$.pr.repo,pr:$.pr.pr});a({card:$})}const g=db(n,e).map($=>({...$,group:Ao[$.kind].group,icon:Ao[$.kind].icon,key:$.label}));return r("div",{id:"open-omnibox",class:"open-omnibox-overlay",onClick:$=>{$.target.id==="open-omnibox"&&St()},children:r("div",{class:"open-omnibox-card",children:[!s&&r("div",{class:"launcher-branches",children:["claude","codex"].map($=>r("button",{class:`launcher-branch${m===$?" is-active":""}`,onClick:()=>b($),children:$==="claude"?"Claude":"Codex"},$))}),!l&&!s&&r(Qi,{value:n,onInput:i,placeholder:"repo, path, #PR…",items:g,onPick:y,onClose:St,empty:n?"no matches":e.roots&&!e.repos.length?`no repos found under ${e.roots.join(", ")} — add roots in ⚙ settings, or type a path`:"type a repo, path, or #PR…"}),s&&r(yb,{selectedJob:u,onSelect:c,onBack:u?()=>c(null):()=>{o(!1),i("")},onClose:St}),l&&l.card.kind==="worktree"&&r(kb,{card:l.card,onPick:$=>x({repo:l.card.repo,branch:$}),onBack:()=>a(null)}),l&&l.card.kind==="track"&&r(wb,{card:l.card,onPick:$=>w(l.card.repo,$),onBack:()=>a(null)}),l&&l.card.kind==="pr"&&r(vb,{repos:e.repos,onPick:$=>x({repo:$,pr:l.card.pr.pr}),onBack:()=>a(null)}),p&&r("div",{class:"open-omnibox-error",children:p}),f&&r("div",{class:"open-omnibox-busy",children:"opening…"})]})})}function yb({selectedJob:e,onSelect:t,onBack:n}){const i=fb(!e);return He(n,!0),e?r(bb,{jobId:e,onBack:n}):r("div",{class:"open-omnibox-jobs",children:[r("div",{class:"open-omnibox-jobs-head",children:"Commands"}),r("div",{class:"open-omnibox-list",children:[i.length===0&&r("div",{class:"open-omnibox-empty",children:"no commands yet"}),i.map(l=>r("button",{class:"open-omnibox-row",onClick:()=>t(l.id),children:[r("span",{class:`open-omnibox-jobdot${l.status==="running"?" is-running":""}`,children:l.status==="running"?"●":"✓"}),r("span",{class:"open-omnibox-label",children:l.text}),r("span",{class:"open-omnibox-sub",children:Pe(l.started_at)})]},l.id))]}),r("div",{class:"open-omnibox-footer",children:r("span",{children:[r("kbd",{children:"esc"})," back"]})})]})}function bb({jobId:e,onBack:t}){const{messages:n,pending:i}=pb(e);return r("div",{class:"open-omnibox-console",children:[r("div",{class:"open-omnibox-console-cmd",children:r("button",{class:"open-omnibox-jobback",onClick:t,children:"← back"})}),r("div",{class:"open-omnibox-console-log",children:[i&&r("div",{class:"open-omnibox-console-spin",children:"no transcript yet — the commander is still starting…"}),!i&&n.length===0&&r("div",{class:"open-omnibox-console-spin",children:"no transcript yet"}),!i&&n.map((l,a)=>r("div",{class:"open-omnibox-console-line",children:mb(l)},l.uuid||a))]})]})}function Qi({value:e,onInput:t,placeholder:n,items:i,onPick:l,onBack:a,empty:s}){const[o,u]=B(0),c=ne(null),f=ne(null),d=i.length,p=Math.min(o,Math.max(0,d-1));j(()=>{const b=requestAnimationFrame(()=>{var x;return(x=f.current)==null?void 0:x.focus()});return()=>cancelAnimationFrame(b)},[]),j(()=>{u(0)},[e]),j(()=>{var b,x;(x=(b=c.current)==null?void 0:b.querySelector(".is-active"))==null||x.scrollIntoView({block:"nearest"})},[p,d]);function h(b){b.key==="ArrowDown"?(b.preventDefault(),u(Math.min(p+1,d-1))):b.key==="ArrowUp"?(b.preventDefault(),u(Math.max(p-1,0))):b.key==="Enter"?(b.preventDefault(),i[p]&&l(i[p])):b.key==="Escape"&&a&&(b.preventDefault(),b.stopPropagation(),a())}let m=null;return r(V,{children:[r("input",{class:"open-omnibox-input",ref:f,placeholder:n,value:e,onInput:b=>t(b.target.value),onKeyDown:h}),r("div",{class:"open-omnibox-list",ref:c,children:[d===0&&r("div",{class:"open-omnibox-empty",children:s}),i.map((b,x)=>{const w=b.group&&b.group!==m?r("div",{class:"open-omnibox-group",children:b.group},`g:${b.group}`):null;return m=b.group,r(V,{children:[w,r("button",{class:`open-omnibox-row${x===p?" is-active":""}`,onMouseMove:()=>u(x),onClick:()=>l(b),children:[b.icon&&r("span",{class:"open-omnibox-icon",children:b.icon}),r("span",{class:"open-omnibox-label",children:b.label}),b.sub&&r("span",{class:"open-omnibox-sub",children:b.sub})]},b.key||x)]})})]}),r("div",{class:"open-omnibox-footer",children:[r("span",{children:[r("kbd",{children:"↑"}),r("kbd",{children:"↓"})," navigate"]}),r("span",{children:[r("kbd",{children:"↵"})," ",a?"select":"open"]}),r("span",{children:[r("kbd",{children:"esc"})," ",a?"back":"close"]})]})]})}function kb({card:e,onPick:t,onBack:n}){const[i,l]=B(""),a=(e.branches||[]).filter(o=>o.toLowerCase().includes(i.toLowerCase())),s=a.map(o=>({key:o,group:"Branches",icon:"⎇",label:o,value:o}));return i&&!a.includes(i)&&s.push({key:`__new:${i}`,group:"Branches",icon:"+",label:`new branch "${i}"`,value:i}),r(Qi,{value:i,onInput:l,placeholder:`branch in ${e.repo}…`,items:s,onPick:o=>t(o.value),onBack:n,empty:"type a new branch name…"})}function wb({card:e,onPick:t,onBack:n}){const[i,l]=B(""),a=i.trim(),s=a?[{key:`__tk:${a}`,group:"New track",icon:"▧",label:`create track "${a}"`,sub:e.repo,value:a}]:[];return r(Qi,{value:i,onInput:l,placeholder:`name this track (repo: ${e.repo})…`,items:s,onPick:o=>t(o.value),onBack:n,empty:"type a track name…"})}function vb({repos:e,onPick:t,onBack:n}){const[i,l]=B(""),s=(e||[]).filter(o=>o.label.toLowerCase().includes(i.toLowerCase())||o.repo.toLowerCase().includes(i.toLowerCase())).map(o=>({key:o.repo,group:"Repositories",icon:"◳",label:o.label,sub:o.repo,value:o.repo}));return r(Qi,{value:i,onInput:l,placeholder:"repo for this PR…",items:s,onPick:o=>t(o.value),onBack:n,empty:"no matching repo"})}function Mo({which:e,label:t,fonts:n}){return r("label",{children:[t,r("select",{name:`font-${e}`,value:ar(e).id,onChange:i=>jg(e,i.currentTarget.value),children:n.map(i=>r("option",{value:i.id,children:i.name},i.id))})]})}function _b(){return r("fieldset",{class:"font-picker",children:[r("legend",{children:"Fonts"}),r(Mo,{which:"ui",label:"Interface",fonts:hi}),r(Mo,{which:"code",label:"Code & terminal",fonts:hi.filter(e=>e.mono)})]})}const xb=[["needs_input","A session needs input"],["done","A session finishes"],["ci_failed","CI fails on a session's PR"],["pr_merged","A linked PR merges"],["usage","Usage projected past a limit"],["quiet_when_focused","Stay quiet while the dashboard is focused"],["group","Group when more than 2 arrive at once"],["badge","Dock badge counts sessions waiting on you"]];function Sb(){const e=pi();return r("fieldset",{class:"notify-settings",children:[r("legend",{children:"Notifications"}),!Ve()&&r("p",{class:"settings-overrides-hint",children:"Notifications appear in the Periscope macOS app only."}),xb.map(([t,n])=>r("label",{class:"notify-option",children:[r("input",{type:"checkbox",name:`notify-${t}`,checked:e[t],onChange:i=>qg(t,i.currentTarget.checked)}),n]},t))]})}function $b({critter:e}){return r("svg",{class:"critter-preview",viewBox:e.sprite?"0 0 20 20":"-1.5 1 20 20",width:"40",height:"40","shape-rendering":"crispEdges","aria-hidden":"true",children:e.sprite?r(Wi,{sprite:e.sprite}):r(qy,{})})}function Cb(){const e=hu();return r("fieldset",{class:"tama-picker",children:[r("legend",{children:"Tamagotchi"}),r("div",{class:"tama-picker-options",children:di.map(t=>r("label",{class:"tama-picker-option",children:[r("input",{type:"radio",name:"tama-critter",value:t.id,checked:t.id===e,onChange:()=>zg(t.id)}),r($b,{critter:t}),r("span",{children:t.name})]},t.id))})]})}const ln=H(!1);function Lo(){ln.value=!0,ye("overlay.open",{which:"settings"})}function On(){ln.value=!1}function Tb(){He(On,ln.value);const[e,t]=B(""),[n,i]=B(!1),[l,a]=B(14),[s,o]=B("sibling"),[u,c]=B([]),[f,d]=B(""),[p,h]=B([]),[m,b]=B("");j(()=>{const w=document.getElementById("settings-btn");return w&&w.addEventListener("click",Lo),()=>{w&&w.removeEventListener("click",Lo)}},[]),j(()=>{ln.value&&(t(""),(async()=>{const{data:w,error:C}=await pr("load settings","/api/settings");if(C){t(C);return}const y=w.settings||{};a(y.cleanup_idle_days??14),o(y.worktree_layout_default??"sibling"),c(Object.entries(y.worktree_layout_overrides||{}).map(([g,$])=>({repo:g,layout:$}))),h(w.editors_available||[]),d(y.editor??""),b((y.repo_roots??["~/dev"]).join(` -`))})())},[ln.value]);async function x(w){w.preventDefault(),t("");const C=parseInt(l,10);if(!C||C<1){t("cleanup idle days must be a positive integer");return}const y={};for(const{repo:v,layout:E}of u)v&&E&&(y[v]=E);const g={cleanup_idle_days:C,worktree_layout_default:s,worktree_layout_overrides:y,editor:f||null,repo_roots:m.split(` -`).map(v=>v.trim()).filter(Boolean)};i(!0);const{error:$}=await pr("save settings","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(i(!1),$){t($);return}On()}return ln.value?r("div",{id:"settings-modal",class:"settings-modal-overlay",onClick:w=>{w.target.id==="settings-modal"&&On()},children:r("div",{class:"settings-modal-card",children:[r("header",{class:"settings-modal-head",children:[r("h2",{children:"🛠 settings"}),r("button",{id:"settings-modal-close",title:"close",onClick:On,children:"×"})]}),r("form",{id:"settings-form",onSubmit:x,children:[r(_b,{}),r(Cb,{}),r(Sb,{}),r("label",{children:["Cleanup idle threshold (days)",r("input",{id:"settings-cleanup-idle-days",type:"number",min:"1",value:l,onInput:w=>a(w.currentTarget.value)})]}),r("label",{children:["Preferred editor",r("select",{id:"settings-editor",value:f,onChange:w=>d(w.currentTarget.value),children:[r("option",{value:"",children:"(none — hides the rail's ↗ action)"}),p.map(w=>r("option",{value:w,children:w},w))]})]}),r("label",{children:["Repo roots",r("textarea",{id:"settings-repo-roots",rows:3,spellcheck:!1,value:m,onInput:w=>b(w.currentTarget.value)})]}),r("p",{class:"settings-overrides-hint",children:"One directory per line. Repos one level under each are offered in ⌘K; a repo elsewhere can be opened once by typing its path there."}),r("label",{children:["Default worktree layout",r("select",{id:"settings-worktree-default",value:s,onChange:w=>o(w.currentTarget.value),children:[r("option",{value:"sibling",children:"sibling — ~/dev/worktrees//"}),r("option",{value:"inline",children:"inline — /.worktrees/"})]})]}),r("fieldset",{children:[r("legend",{children:"Per-repo overrides"}),r("div",{id:"settings-overrides-list",children:u.length===0?r("div",{class:"settings-overrides-empty",children:"(none yet)"}):u.map((w,C)=>r("div",{class:"settings-overrides-row","data-repo":w.repo,children:[r("span",{class:"settings-overrides-repo",children:w.repo}),r("select",{class:"settings-overrides-layout",value:w.layout,onChange:y=>{const g=y.currentTarget.value;c($=>$.map((v,E)=>E===C?{...v,layout:g}:v))},children:[r("option",{value:"sibling",children:"sibling"}),r("option",{value:"inline",children:"inline"})]}),r("button",{type:"button",class:"settings-overrides-remove",title:"remove override",onClick:()=>c(y=>y.filter((g,$)=>$!==C)),children:"×"})]},w.repo))}),r("p",{class:"settings-overrides-hint",children:["Auto-detected on first ",r("code",{children:"+ project"})," per repo. Edit or remove rows here."]})]}),r("div",{id:"settings-modal-error",class:"settings-modal-error",hidden:!e,children:e}),r("div",{class:"settings-modal-actions",children:[r("button",{type:"button",id:"settings-cancel",onClick:On,children:"cancel"}),r("button",{type:"submit",id:"settings-submit",disabled:n,children:"save"})]})]})]})}):null}function Eb(){return j(()=>{Xg(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})},[]),r(V,{children:[r(W2,{}),r(q2,{}),r(Tb,{}),r(lb,{}),r(gb,{})]})}const Io=120,Pb=3600,Yl=e=>`${e.repo_slug||e.repo_key||""}#${e.pr}`;function Oo(e){let t=0;for(const n of e.message||"")t=t*31+n.codePointAt(0)|0;return`question:${e.pane_id||e.target}@${e.ts}:${(t>>>0).toString(36)}`}const Lr={calm:0,grumpy:1,furious:2};function Ab(e,t,n){const{windows:i=[],alerts:l=[],dismissedAlertIds:a=new Set,dismissedNeedsPids:s=new Set,dismissedReadyPids:o=new Set,plan:u={}}=t,c=!e,f=(e==null?void 0:e.pass)??0,d=f+1,p=(e==null?void 0:e.seen)||{},h=new Set;for(const[T,S]of Object.entries(p))typeof S=="number"&&S<=f&&f-S<=Io&&h.add(T);const m={},b=[],x=(T,S)=>{m[T]=d,!c&&!h.has(T)&&b.push({key:T,...S})},w=T=>{m[T]=d},C=Pa(i,l,a,s),y=new Set;for(const T of C)T.kind==="live"&&(y.add(T.w.pid),x(`needs:${T.w.pid}@${T.w.needs_since||0}`,{kind:"needs_input",w:T.w}));for(const T of i)T.state==="needs-input"&&s.has(T.pid)&&w(`needs:${T.pid}@${T.needs_since||0}`);for(const T of C){if(T.kind!=="event")continue;const S=Oo(T);T.w&&y.has(T.w.pid)?(c||h.has(S))&&w(S):x(S,{kind:"question",w:T.w,alert:T})}for(const T of l)T.kind==="need_human"&&a.has(T.id)&&w(Oo(T));for(const T of i){if(T.state!=="done")continue;const S=`done:${T.pid}@${T.completed_at||0}`;o.has(T.pid)?w(S):x(S,{kind:"done",w:T})}const g={};for(const[T,S]of Object.entries((e==null?void 0:e.prAt)||{}))d-S<=Pb&&(g[T]=S);const $={},v={};for(const T of Object.keys(g))T in((e==null?void 0:e.ci)||{})&&($[T]=e.ci[T]),T in((e==null?void 0:e.prs)||{})&&(v[T]=e.prs[T]);const E=new Map;for(const T of i){if(!T.pr||T.pr_linked&&!T.pr_state)continue;const S=Yl(T);(!E.has(S)||T.pr_state&&!E.get(S).pr_state)&&E.set(S,T)}for(const[T,S]of E){g[T]=d;const F=(!S.pr_state||S.pr_state==="open")&&S.ci||null;!c&&T in $&&$[T]!=="✗"&&F==="✗"&&b.push({key:`ci:${T}`,kind:"ci_failed",w:S}),$[T]=F,S.pr_state&&(!c&&v[T]==="open"&&S.pr_state==="merged"&&b.push({key:`merged:${T}`,kind:"pr_merged",w:S}),v[T]=S.pr_state)}const A={};for(const[T,S]of Object.entries((e==null?void 0:e.meters)||{}))Number(T.slice(T.lastIndexOf("/")+1))*60>n&&(A[T]=S);for(const[T,S]of Object.entries(u||{})){if(!(S!=null&&S.available)||!S.meters||!c&&Ba(S,n))continue;let R=null;for(const[F,q]of Object.entries(S.meters)){if(!(q!=null&&q.resets_at))continue;const L=ju(q),I=`${T}/${F}/${Math.round(q.resets_at/60)}`,O=A[I]??0;A[I]=Math.max(O,Lr[L]),!c&&Lr[L]>O&&(!R||Lr[L]>Lr[R.mood])&&(R={key:`usage:${I}:${L}`,kind:"usage",account:T,meter:F,m:q,mood:L})}R&&b.push(R)}for(const T of h)!(T in m)&&d-p[T]<=Io&&(m[T]=p[T]);return{state:{pass:d,seen:m,ci:$,prs:v,prAt:g,meters:A},events:b}}const Qn=(e,t)=>{const n=String(e||"").trim(),i=Array.from(n);return i.length>t?`${i.slice(0,t-1).join("")}…`:n},gl=e=>Qn(Se(e),26),Dn=e=>[e==null?void 0:e.session,e==null?void 0:e.branch].filter(Boolean).join(" · "),yl=e=>!!(e!=null&&e.pid&&e.agent==="claude"),Do=e=>{const t=/^mcp__(.+?)__(.+)$/.exec(e||"");return t?`${t[2]} (${t[1]})`:e||"this"};function Mb(e){const t=String(e||"").replace(/\s+/g," ").trim(),n=t.match(/^.*?[.!?](?=\s[A-Z0-9]|$)/);return Qn(n?n[0]:t,140)}const Ro={permission:"Waiting for your approval.",question:"Waiting for your answer.",dialog:"Waiting for your input."},Lb={failure:"✗",pending:"⟳",success:"✓"},Cd=e=>`usage_to_${e}`;function Td(e,t={}){var l,a;const n=e.w,i={kind:e.kind,thread:e.kind,target:(n==null?void 0:n.target)||"",data:{}};switch(e.kind){case"needs_input":{const s=n.pending_permission;return s!=null&&s.request_id&&n.pid?{...i,title:`${gl(n)} needs you`,subtitle:Dn(n),body:s.summary?`Allow ${Do(s.tool)}: ${s.summary}?`:`Allow ${Do(s.tool)}?`,category:"needs_permission",data:{open:"pane",pid:n.pid,request_id:s.request_id}}:{...i,title:`${gl(n)} needs you`,subtitle:Dn(n),body:Ro[su(n.waiting_for)]||Ro.dialog,category:"needs_dialog",data:{open:"pane",pid:n.pid}}}case"question":{const s=e.alert;return{...i,title:`${Qn(n?Se(n):s.name||s.session||"A session",26)} asks`,subtitle:n?Dn(n):s.session||"",body:Qn(s.message,180),target:s.target||i.target,...yl(n)?{category:"question"}:{},data:{open:"pane",pid:(n==null?void 0:n.pid)??null}}}case"done":return{...i,title:`${gl(n)} is done`,subtitle:n.pr&&n.pr_linked?`${n.session} · PR #${n.pr}`:Dn(n),body:Mb(n.last_reply||n.recap||n.last_line)||"Finished.",category:"done_seen",data:{open:"pane",pid:n.pid,session:n.session}};case"ci_failed":{const s=(n.ci_checks||[]).map(f=>`${Lb[f.state]||"·"} ${f.name}`).join(" · "),o=rr(n.repo_slug,n.pr),u=yl(n)?n:(t.windows||[]).find(f=>yl(f)&&Yl(f)===Yl(n));let c;return u!=null&&u.pid&&o?c="ci_failed":u!=null&&u.pid?c="ci_failed_fix":o&&(c="ci_failed_pr"),{...i,title:`CI failed on #${n.pr}`,subtitle:[n.session,Se(n)].filter(Boolean).join(" · "),body:s||"Checks are failing.",...c?{category:c}:{},data:{open:"url",url:o,pid:(u==null?void 0:u.pid)||n.pid,pr:n.pr,checks:(n.ci_checks||[]).filter(f=>f.state==="failure").map(f=>f.name)}}}case"pr_merged":{const s=rr(n.repo_slug,n.pr);let o;return n.cwd&&s?o="pr_merged":n.cwd?o="pr_merged_cleanup":s&&(o="pr_merged_pr"),{...i,title:`PR #${n.pr} merged`,subtitle:n.pr_base?`${n.session} · ${n.branch} → ${n.pr_base}`:Dn(n),body:"The worktree and its session can be cleaned up.",...o?{category:o}:{},data:{open:"url",url:s,pid:n.pid,cwd:n.cwd}}}case"usage":{const s=t.accounts||[],o=Qn(((l=s.find(h=>h.id===e.account))==null?void 0:l.label)||e.account,16),u=s.length>1,c=Math.max(...[e.m.projected_percent,e.m.projected_recent].filter(h=>h!=null),-1),f=(t.windows||[]).filter(h=>h.state==="working"&&h.account===e.account).length,d=(a=t.moveTargets)==null?void 0:a[e.account],p=d&&d!==e.account;return{...i,target:"",title:u?`Account ${o} is running hot`:"Usage is running hot",subtitle:`${ja(e.meter)} usage ${Math.round(e.m.percent??0)}%`+(c>=0?` · →${Math.round(c)}% at reset`:""),body:u?`${kn(f,"session")} working on ${o}.`:`${kn(f,"session")} working.`,category:p?Cd(d):"usage",data:p?{open:"usage",spawn_to:d}:{open:"usage"}}}default:return null}}const it=(e,t,n={})=>Object.freeze({id:e,title:t,...n}),Fo=it("open_pr","Open PR"),Ib=it("mark_seen","Mark seen"),No=it("cleanup","Clean up worktree",{foreground:!0}),Ob=it("details","Details",{foreground:!0}),Db=it("open","Open",{foreground:!0}),Bo=it("fix","Ask agent to fix",{auth:!0});function Rb({accounts:e=[],moveTargets:t={}}={}){const n=[{id:"done_seen",actions:[Ib]},{id:"ci_failed_pr",actions:[Fo]},{id:"pr_merged",actions:[No]},{id:"pr_merged_cleanup",actions:[No]},{id:"pr_merged_pr",actions:[Fo]},{id:"usage",actions:[Ob]},{id:"needs_permission",actions:[it("allow","Allow",{auth:!0})]},{id:"needs_dialog",actions:[Db]},{id:"question",actions:[it("send","Reply",{auth:!0,reply:{button:"Send",placeholder:"Reply…"}})]},{id:"ci_failed",actions:[Bo]},{id:"ci_failed_fix",actions:[Bo]}];for(const i of[...new Set(Object.values(t||{}))].sort())n.push({id:Cd(i),actions:[it("spawn_on",`Spawn on ${gn(i,e||[])}`)]});return n}const Fb=Object.freeze({openExternal:qi,openUsageDetails:vd,pickSpawnAccount:Cu,openCleanupModal:_d,markReadySeen:_u,selectPane:yt,revealPane:jt,post:Tg,toast:bn,notify:mu}),Nb={allow:"Allow",deny:"Deny",send:"Reply",fix:"Ask agent to fix"},Bb={allow:"Couldn't allow",deny:"Couldn't deny",send:"Couldn't send your reply",fix:"Couldn't ask the agent to fix"},zb=new Set(["allow","deny"]),jb={"/api/pane/permission":"The dialog changed — open the pane to answer it.","/api/pane/reply":"The pane has a dialog open, or isn't running an agent — open it to see why."};function Hb(e,t){return(t==null?void 0:t.status)===404?"The pane is gone.":(t==null?void 0:t.status)===0?"Periscope isn't answering.":(t==null?void 0:t.status)===409?typeof t.detail=="string"&&t.detail!==`HTTP ${t.status}`?t.detail:jb[e]:(t==null?void 0:t.detail)||"No answer"}const qb=e=>{const t=e.codePointAt(0);return t!==9&&t!==10&&(t<32||t>=127&&t<=159)},Ub=e=>[...String(e)].filter(t=>!qb(t)).join("").trim();function Wb(e,t){const n=(t||[]).map(Ub).filter(Boolean),i=n.length?`${n.join(" · ")}.`:"Checks are failing.";return`CI failed on #${e}: ${i} Please investigate and fix.`}async function bl({target:e,show:t},n,i,l,a){let s=!1;const o=u=>{s||(s=!0,Promise.resolve().then(()=>a.notify({kind:"notice",thread:"notice",title:Bb[n],body:u,target:e,data:{open:"pane",pid:l.pid},quiet_when_focused:!0})).catch(c=>console.error("[notify] follow-up failed",c)))};try{if(!l.pid||zb.has(n)&&!l.request_id){o("Open the pane to answer it."),t();return}const u=await a.post(i,l);if(u!=null&&u.ok)return;const c=Hb(i,u);o(c),t(),(u==null?void 0:u.status)!==409&&a.toast(`${Nb[n]} failed: ${(u==null?void 0:u.detail)||"no answer"}`,"bad",6e3)}catch(u){console.error("[notify] action failed",n,u),o((u==null?void 0:u.message)||"Periscope isn't answering.");try{t()}catch(c){console.error("[notify] reveal failed",c)}}}function Kb({target:e,action:t,text:n,data:i}={},l=Fb){i||(i={});let a;const s=()=>a?l.selectPane(a):e&&l.revealPane(e);try{switch(a=i.pid?(de.peek()||[]).find(o=>String(o.pid)===String(i.pid)):null,t){case"open_pr":i.url?l.openExternal(i.url):s();return;case"details":l.openUsageDetails();return;case"spawn_on":i.spawn_to&&l.pickSpawnAccount(i.spawn_to);return;case"mark_seen":a&&l.markReadySeen(a);return;case"cleanup":{const o=i.cwd||(a==null?void 0:a.cwd);o?l.openCleanupModal({paths:[o]}):s();return}case"allow":case"deny":return bl({target:e,show:s},t,"/api/pane/permission",{pid:i.pid,request_id:i.request_id,choice:t},l);case"send":{const o=String(n||"").trim();return o?bl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:o},l):void 0}case"fix":return bl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:Wb(i.pr,i.checks)},l);case"open":s();return;default:console.warn("[notify] unknown action",t)}}catch(o){console.error("[notify] action failed",t,o);try{s()}catch(u){console.error("[notify] reveal failed",u)}}}const Zl=3e3,Vb=2,Gb=new Set(["needs_input","question"]);function Jb(e,t,n,i=!0){const l=t.filter(o=>n-o{var t;return e.kind==="question"?"question":su((t=e.w)==null?void 0:t.waiting_for)==="permission"?"permission":"input"};function Yb(e){var n,i;const t=new Set(e.map((l,a)=>{var s,o;return((s=l.w)==null?void 0:s.pid)??((o=l.alert)==null?void 0:o.pane_id)??a})).size;return{kind:"summary",thread:"needs_you",target:"",data:{open:"pane",pid:((i=(n=e[0])==null?void 0:n.w)==null?void 0:i.pid)??null},title:t===1?"1 more session needs you":`${t} more sessions need you`,subtitle:"",body:e.map(l=>{var a;return`● ${l.w?Se(l.w):((a=l.alert)==null?void 0:a.name)||"a session"} · ${Qb(l)}`}).join(` -`)}}function Ed(e,t,n){if(e.length===1)try{const i=t(e[0],n);if(i)return i}catch(i){console.error("[notify] banner failed",e[0].key,i)}return Yb(e)}const Pd="periscope.notify.v1",Zb=15*60*1e3;function Xb(e,t){try{const n=JSON.parse((e==null?void 0:e.getItem(Pd))||"null");if(!(n!=null&&n.state)||!(n.at<=t)||t-n.at>Zb)return null;const i=Array.isArray(n.held)?n.held:[];return{state:n.state,held:i,heldSince:i.length?n.heldSince??n.at:null}}catch{return null}}function ek(e,t,n,i=[],l=null){try{e==null||e.setItem(Pd,JSON.stringify({at:n,state:t,held:i,heldSince:l}))}catch{}}const tk={question:"needs_input"},nk=(e,t)=>e[tk[t]||t]!==!1;function rk({target:e,data:t}={}){if(t||(t={}),t.open==="url"&&t.url){qi(t.url);return}if(t.open==="usage"){vd();return}const n=t.pid!=null&&(de.value||[]).find(i=>String(i.pid)===String(t.pid));n?yt(n):jt(e)}const ik={sends:[],flush:[],badge:null};function lk(e,t,n,i,l=Td){let{state:a,recent:s,held:o,heldSince:u,lastBadge:c,lastCategories:f}=e;const d={quiet_when_focused:n.quiet_when_focused},p=[],h={accounts:t.accounts,windows:t.windows,moveTargets:t.moveTargets};o.length&&i-u>=Zl&&(p.push({...Ed(o,l,h),...d}),o=[],u=null);let m=null;const b=g=>({state:a,recent:s,held:o,heldSince:u,lastBadge:c,lastCategories:f,...ik,flush:p,categories:m,timerAt:o.length?u+Zl:null,...g});if(t.alerts===null)return b();try{const g=Rb({accounts:t.accounts,moveTargets:t.moveTargets}),$=JSON.stringify(g);$!==f&&(m=g,f=$)}catch(g){console.error("[notify] category set failed",g)}const x=ku(t.windows,t.alerts,t.dismissedAlertIds,t.dismissedNeedsPids,i/1e3),w=n.badge?x.size:0,C=w===c?null:w;if(c=w,!a&&(!t.windows.length||e.editing))return b({badge:C});const y=[];if(!e.editing){const g=Ab(a,t,i/1e3);a=g.state;const $=Jb(g.events.filter(v=>nk(n,v.kind)),s,i,n.group);s=$.recent;for(const v of $.now){let E=null;try{E=l(v,h)}catch(A){console.error("[notify] banner failed",v.key,A)}E&&y.push({...E,...d})}$.held.length&&(o=[...o,...$.held],u??(u=i))}return b({sends:y,badge:C})}const ak=2e3;function sk(e={setNotifyCategories:Zg,notify:mu}){let t=Promise.resolve();return(n,i)=>{n&&(t=t.then(()=>Promise.race([e.setNotifyCategories(n),new Promise(l=>setTimeout(l,ak))])).catch(l=>console.error("[notify] registration failed",l))),i.length&&(t=t.then(()=>{for(const l of i)try{e.notify(l)}catch(a){console.error("[notify] post failed",a)}}))}}let zo=!1;function ok(){if(zo||!Ve())return;zo=!0;const e=typeof localStorage>"u"?null:localStorage,t=Xb(e,Date.now());let n={state:null,held:[],heldSince:null,...t,recent:[],lastBadge:void 0,lastCategories:void 0};const i=u=>ek(e,n.state,u,n.held,n.heldSince),l=sk();let a=null,s=null;const o=()=>{a=null,s=null;const u=n.held;if(n={...n,held:[],heldSince:null},!u.length)return;n.state&&i(Date.now());const c={accounts:at.peek(),windows:de.peek()||[],moveTargets:si.peek()};l(null,[{...Ed(u,Td,c),quiet_when_focused:pi().quiet_when_focused}])};Qg(rk),Yg(u=>Kb(u)),lt(()=>{$c.value,Ai(()=>{var u;try{const c={windows:de.peek()||[],alerts:er.peek(),dismissedAlertIds:nr.peek(),dismissedNeedsPids:ht.peek(),dismissedReadyPids:ft.peek(),plan:((u=Oi.peek())==null?void 0:u.plan)||{},accounts:at.peek(),moveTargets:si.peek()},f=!!(pa.peek()||Et.peek()),d=Date.now(),p=n,{sends:h,flush:m,badge:b,categories:x,timerAt:w,...C}=lk({...n,editing:f},c,pi(),d);n=C,n.state&&(n.state!==p.state||n.held!==p.held)&&i(d),l(x,[...m,...h]),w==null?(a&&clearTimeout(a),a=null,s=null):w!==s&&(a&&clearTimeout(a),s=w,a=setTimeout(o,Math.max(0,w-d))),b!==null&&Gg(b)}catch(c){console.error("[notify] pass failed",c)}})})}const ck=3e3,uk=2e3;let $i=0;function Ad(){return document.getElementById("connection-banner")}function Md(e){try{if(er.value=e.alerts||[],pa.value||Et.value)return;de.value=e.windows||[],Li.value=e.projects||[],Ii.value=e.workspaces||[],Bt.value=e.tracks||[],wh(de.value),Oi.value={plan:e.usage_plan,fallback:e.usage,poke:e.poke||{}},ha.value=e.update||null,at.value=e.accounts||[],si.value=e.move_targets||{},Un.value=e.spawn_account||null,Wn.value=e.spawn_model||null,Kn.value=e.spawn_effort||null,sn.value=e.launch_default||null,xc.value=e.walls||null,fa.value=e.wall_spans||[],Sc.value=e.editor||""}finally{$c.value+=1}}function Ld(){if($i>0){$i=0;const e=Ad();e&&(e.hidden=!0),document.body.classList.remove("disconnected")}}function Id(e){if($i+=1,$i>=2){const t=Ad();t&&(t.hidden=!1),document.body.classList.add("disconnected")}e&&console.warn("[periscope]",e)}async function dk(){if(!pa.value&&!Et.value)try{const e=await fetch("/api/state");if(!e.ok)throw new Error(`HTTP ${e.status}`);Md(await e.json()),Ld()}catch(e){Id(`poll failed: ${e.message}`)}}let kl=!1,Xl=!1,Yn=null,Ot=null,fn=null;function hk(){if(Ot)return;const e=async()=>{await dk(),Ot!==null&&(Ot=setTimeout(e,ck))};Ot=setTimeout(e,0)}function Od(){Ot&&(clearTimeout(Ot),Ot=null)}const fk=1e4;let Dt=null,jo=0;async function Yi(){const e=++jo;try{const t=await fetch("/api/reviews");if(!t.ok)return;const n=await t.json();e===jo&&(mt.value=n.rows||[])}catch{}}function pk(){if(Dt)return;const e=async()=>{await Yi(),Dt!==null&&(Dt=setTimeout(e,fk))};Dt=setTimeout(e,0)}function mk(){Dt&&(clearTimeout(Dt),Dt=null)}function Dd(){const e=location.protocol==="https:"?"wss:":"ws:",t=new WebSocket(`${e}//${location.host}/ws/state`);Yn=t,t.onmessage=n=>{Od();try{Md(JSON.parse(n.data)),Ld()}catch(i){Id(`bad frame: ${i.message}`)}},t.onclose=()=>{Xl||(Yn=null,hk(),fn||(fn=setTimeout(()=>{fn=null,Dd()},uk)))},t.onerror=()=>{try{t.close()}catch{}}}function gk(){return kl?()=>{}:(kl=!0,Xl=!1,Dd(),pk(),()=>{if(Xl=!0,mk(),kl=!1,Yn){try{Yn.close()}catch{}Yn=null}Od(),fn&&(clearTimeout(fn),fn=null)})}const yk=/[A-Za-z0-9_]+|\s+|[^A-Za-z0-9_\s]/g;function Ho(e){return String(e??"").match(yk)||[]}function bk(e,t){let n=0;for(;n{const b=[],x=(w,C)=>{if(!w)return;const y=b[b.length-1];y&&y.changed===C?y.text+=w:b.push({text:w,changed:C})};return x(p.slice(0,h).join(""),!1),x(p.slice(h,m).join(""),!0),x(p.slice(m).join(""),!1),b},f=c(i,a,i.length-s),d=c(l,a,l.length-s);return!f.some(p=>p.changed)&&!d.some(p=>p.changed)?null:{del:f,add:d}}function vk(e,t=.5){const n=e.map(l=>({...l}));let i=0;for(;i0&&s===o)for(let u=0;ui?a:i+1}return n}const _k=["dist/","build/","vendor/",".next/","target/debug/","target/release/"],xk=new Set(["package-lock.json","yarn.lock","pnpm-lock.yaml","uv.lock","poetry.lock","Cargo.lock","Gemfile.lock","composer.lock","go.sum"]),Sk=[".min.js",".min.css",".map",".snap"];function Rd(e){const t=String(e||"");if(!t)return!1;const n=t.split("/").pop()||"";if(xk.has(n)||Sk.some(l=>n.endsWith(l)))return!0;const i=`${t}/`;return _k.some(l=>i.includes(`/${l}`)||i.startsWith(l))}function $k(e){const t=[],n=[];for(const i of e||[])(Rd(i.path)?n:t).push(i);return t.concat(n)}const ea=H({}),Ck="\0";function Fd(e,t){return`${e}${Ck}${t}`}function Nd(e,t,n,i,l=!1){const a=e[Fd(t,n)];if(!a)return{collapsed:l,viewed:!1};const s=!!a.viewedSig&&a.viewedSig===i;return{collapsed:a.collapsed===void 0?l:a.collapsed,viewed:s}}function Bd(e,t,n){const i=Fd(e,t),l={...ea.value},a={...l[i]||{},...n};a.collapsed===void 0&&!a.viewedSig?delete l[i]:l[i]=a,ea.value=l}function Tk(e,t,n){Bd(e,t,{collapsed:n})}function Ek(e,t,n,i){Bd(e,t,{viewedSig:i?n:void 0,collapsed:!!i})}function Pk(e,t,n){return n.reduce((i,l)=>i+(Nd(e,t,l.path,l.sig).viewed?1:0),0)}const Ak=[["session","This session","Changes since the current Claude session started"],["branch","This branch","Changes vs where this branch forked"]],Mk={js:"js",mjs:"js",cjs:"js",jsx:"jsx",ts:"ts",tsx:"tsx",py:"py",rs:"rs",json:"json",css:"css",html:"html",htm:"html",md:"md",markdown:"md"};function zd(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0&&Mk[t.slice(n+1).toLowerCase()]||""}function qo({text:e,lang:t,hl:n}){if(!n||!t)return e||" ";try{return n(e,t)}catch{return e||" "}}function Lk({line:e,lang:t,hl:n}){return r("div",{class:`dl dl-${e.kind}`,children:r("span",{class:"dl-text",children:e.segs?e.segs.map((i,l)=>r("span",{class:i.changed?"dl-intra":"",children:r(qo,{text:i.text,lang:t,hl:n})},l)):r(qo,{text:e.text,lang:t,hl:n})})})}function jd({hunk:e,lang:t,hl:n,onOpen:i,title:l}){return r("div",{class:"dhunk",children:[r("button",{type:"button",class:"dhunk-head",disabled:!i,title:i?l:void 0,onClick:()=>i==null?void 0:i(e.new_start),children:[r("span",{class:"dhunk-range",children:["@@ ",e.new_start]}),e.header?r("span",{class:"dhunk-sym",children:e.header}):null]}),vk(e.lines).map((a,s)=>r(Lk,{line:a,lang:t,hl:n},s))]})}function Ik({file:e,repo:t,review:n,hl:i}){const l=Rd(e.path),{collapsed:a,viewed:s}=Nd(n,t,e.path,e.sig,l),o=!a,u=zd(e.path),c=t&&e.status!=="deleted"&&e.status!=="binary",f=(e.additions||0)+(e.deletions||0);return r("div",{class:`dfile dfile-${e.status}${s?" is-viewed":""}${l?" is-generated":""}`,children:[r("div",{class:"dfile-head",children:[r("button",{type:"button",class:"dfile-toggle",onClick:()=>Tk(t,e.path,o),children:[r("span",{class:"dfile-caret",children:o?"▾":"▸"}),r("span",{class:"dfile-path",children:e.path}),l?r("span",{class:"dfile-gen",title:"Generated artifact — folded by default and sorted last",children:"generated"}):null,r("span",{class:"dfile-status",children:e.status}),r("span",{class:"dfile-stat",children:[e.additions?r("span",{class:"dstat-add",children:["+",e.additions]}):null,e.deletions?r("span",{class:"dstat-del",children:["−",e.deletions]}):null,!f&&e.status==="binary"?r("span",{class:"dstat-bin",children:"binary"}):null]})]}),r("button",{type:"button",class:`dfile-viewed${s?" is-on":""}`,title:s?"Marked viewed — re-surfaces automatically if this file changes again":"Mark viewed (folds it away until it changes again)",onClick:()=>Ek(t,e.path,e.sig,!s),children:s?"✓ viewed":"viewed"})]}),o&&e.hunks.map((d,p)=>r(jd,{hunk:d,lang:u,hl:i,onOpen:c?h=>gr({path:`${t}/${e.path}`,line:h}):null,title:`Open ${e.path}:${d.new_start}`},p)),o&&e.truncated?r("div",{class:"dfile-trunc",children:"diff truncated — open the file to see the rest"}):null]})}const Ok=[3,10,25];function Dk({target:e,active:t,gitSig:n}){var x,w,C;const[i,l]=B("session"),[a,s]=B(3),[o,u]=B({loading:!0,error:null,data:null}),[c,f]=B(null);j(()=>{if(!t||c)return;let y=!0;return Ji(()=>import("./chunks/preview.js").then(g=>g.h),[]).then(g=>{y&&f(()=>g.highlightCode)}).catch(()=>{}),()=>{y=!1}},[t,c]),j(()=>{if(!t||!e)return;let y=!0;return(async()=>{try{const g=await fetch(`/api/fs/diff?${nt(e)}&scope=${i}&context=${a}`);if(!y)return;if(!g.ok){const $=await g.json().catch(()=>({}));u({loading:!1,error:$.detail||`HTTP ${g.status}`,data:null});return}u({loading:!1,error:null,data:await g.json()})}catch(g){y&&u({loading:!1,error:String(g),data:null})}})(),()=>{y=!1}},[e,i,t,n,a]);const d=$k(((x=o.data)==null?void 0:x.files)||[]),p=((w=o.data)==null?void 0:w.repo)||"",h=ea.value,m=Pk(h,p,d),b=d.reduce((y,g)=>({a:y.a+(g.additions||0),d:y.d+(g.deletions||0)}),{a:0,d:0});return r("div",{class:"changes-tab",children:[r("header",{class:"changes-head",children:[r("span",{class:"changes-scope",children:Ak.map(([y,g,$])=>r("button",{type:"button",class:i===y?"is-active":"",title:$,onClick:()=>l(y),children:g},y))}),r("span",{class:"changes-ctx",title:"Lines of context around each change",children:Ok.map(y=>r("button",{type:"button",class:a===y?"is-active":"",onClick:()=>s(y),children:y},y))}),!o.loading&&!o.error&&r("span",{class:"changes-summary",children:d.length?r(V,{children:[m?`${m}/${d.length} viewed · `:`${d.length} file${d.length===1?"":"s"} · `,r("span",{class:"dstat-add",children:["+",b.a]})," ",r("span",{class:"dstat-del",children:["−",b.d]})]}):"no changes"})]}),r("div",{class:"changes-body",children:[o.loading?r("div",{class:"changes-msg",children:"loading…"}):null,o.error?r("div",{class:"changes-msg changes-err",children:o.error}):null,!o.loading&&!o.error&&!d.length?r("div",{class:"changes-msg",children:i==="session"?"Nothing changed on disk since this session started.":"This branch matches its fork point."}):null,d.map(y=>r(Ik,{file:y,repo:p,review:h,hl:c},y.path)),(C=o.data)!=null&&C.truncated?r("div",{class:"changes-msg",children:[o.data.truncated," more file",o.data.truncated===1?"":"s"," not shown"]}):null]})]})}const Rk=new Set(["Read","Edit","Write","MultiEdit","NotebookEdit"]),Fk=new Set(["html","md"]);function Nk(e,t){const n=(t||"").trim();if(!n)return!0;const i=(e||"").toLowerCase();if(!/[*?]/.test(n))return i.includes(n.toLowerCase());const l=n.split("**").map(a=>a.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]")).join(".*");return new RegExp(`(?:^|/)${l}$`,"i").test(i)}function Bk(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0?t.slice(n+1).toLowerCase():""}function zk(e,t=Fk){const n=[],i=[];for(const l of e)(t.has(Bk(l.path))?n:i).push(l);return{priority:n,others:i}}function jk(e){if(!Array.isArray(e)||e.length===0)return[];const t=new Map;for(let n=e.length-1;n>=0;n--){const i=e[n],l=i==null?void 0:i.tool_uses;if(l!=null&&l.length)for(let a=l.length-1;a>=0;a--){const s=l[a];if(!s||!Rk.has(s.name))continue;const o=s.input&&(s.input.file_path||s.input.notebook_path);o&&(t.has(o)||t.set(o,s.name))}}return[...t.entries()].map(([n,i])=>({path:n,op:i}))}function Hk(e){return e==="need_human"?"var(--s-danger)":e==="done"?"var(--s-success)":"var(--fg-3)"}function qk(e,t){return e==="commit"?"var(--s-shell)":e==="ci"?t==="failed"?"var(--s-danger)":t==="running"?"var(--s-working)":"var(--s-success)":e==="open"?"var(--fg-3)":e==="reset"?"var(--s-working)":e==="rename"?"var(--accent)":"var(--fg-3)"}function Uk(e,t){return e==="commit"?"commit":e==="ci"?t?`ci ${t}`:"ci":e==="open"?"opened":e==="reset"?t==="compacted"?"compacted":"cleared":e==="rename"?"renamed":e}function Wk(e){return e?(e.replace(/[^A-Za-z0-9]/g,"").slice(0,2)||e.slice(0,1)).toUpperCase():"?"}const Kk={pr:"Please link the PR you're working on for this pane using the `link_pr` MCP tool. If there isn't one, ignore this.",linear:"Please link the relevant Linear ticket for this pane using the `link_linear` MCP tool. If there isn't one, ignore this."};function Vk({data:e,onLinkAsk:t}){if(!e.pr){if(e.agent!=="claude")return null;const o=!!e.channel_attached;return r("button",{class:"modal-side-link-btn",type:"button",disabled:!o,title:o?"Ask Claude to link the PR for this pane (via link_pr MCP tool)":"Channel not attached. Respawn Claude via + claude.",onClick:()=>t("pr"),children:"+ link pull request"})}const n=e.ci==="✓"?"passing":e.ci==="✗"?"failing":e.ci==="⟳"?"running":"—",i=e.ci==="✓"?"ci-passing":e.ci==="✗"?"ci-failing":e.ci==="⟳"?"ci-running":"",l=rr(e.repo_slug,e.pr),a=e.pr_additions||0,s=e.pr_deletions||0;return r("div",{class:"modal-card-inset",children:[r("div",{class:"pr-head",children:[l?r("a",{class:"pr-num",href:l,target:"_blank",rel:"noopener",onClick:o=>o.stopPropagation(),children:["#",e.pr]}):r("span",{class:"pr-num",children:["#",e.pr]}),r("span",{class:"pr-title",title:e.pr_title||"",children:e.pr_title||""})]}),r("div",{class:"pr-meta",children:[e.pr_draft?r("span",{class:"pr-mini pr-mini-draft",children:"draft"}):r("span",{class:"pr-mini pr-mini-open",children:"open"}),r("span",{class:"pr-diff",children:[r("span",{class:"diff-plus",children:["+",a]})," ",r("span",{class:"diff-minus",children:["−",s]})]}),r("span",{class:`pr-ci ${i}`,children:[r("span",{class:"ci-dot"}),"ci ",n]}),(e.pr_reviewers||[]).length>0&&r("span",{class:"pr-reviewers",children:(e.pr_reviewers||[]).map(o=>r("span",{class:"modal-avatar",title:o,children:Wk(o)}))})]})]})}function Gk({data:e,onLinkAsk:t}){if(e.linked_linear){const s=e.linked_linear,o=`https://linear.app/issue/${s}`,u=e.linked_linear_title||"linear ticket";return r("div",{class:"modal-card-inset",children:[r("div",{class:"pr-head",children:[r("a",{class:"pr-num",href:o,target:"_blank",rel:"noopener",onClick:c=>c.stopPropagation(),title:`Linear ticket ${s} (linked by claude)`,children:s}),r("span",{class:"pr-title",title:u,children:u})]}),e.linked_linear_status&&r("div",{class:"pr-meta",children:r("span",{class:"pr-mini",children:e.linked_linear_status})})]})}const n=br(e),i=n&&r("div",{class:"modal-card-inset",children:r("div",{class:"pr-head",children:[r("a",{class:"pr-num",href:n.href,target:"_blank",rel:"noopener",onClick:s=>s.stopPropagation(),title:n.tip,children:n.id}),r("span",{class:"pr-title",children:n.note})]})});if(e.agent!=="claude")return i||null;const l=!!e.channel_attached;return r(V,{children:[i,r("button",{class:"modal-side-link-btn",type:"button",disabled:!l,title:l?"Ask Claude to link a Linear ticket for this pane (via link_linear MCP tool)":"Channel not attached. Respawn Claude via + claude.",onClick:()=>t("linear"),children:"+ link Linear ticket"})]})}function Jk({e}){return e.src==="alert"?r("li",{class:"timeline-row timeline-row-alert","data-kind":e.kind,children:[r("span",{class:"timeline-dot",style:`background:${Hk(e.kind)}`}),r("div",{class:"timeline-body",children:[r("div",{class:"timeline-text",children:e.text}),r("div",{class:"timeline-when",children:["claude · ",e.kind," · ",Pe(e.at)," ago"]})]})]}):e.src==="channel"?r("li",{class:"timeline-row timeline-row-channel","data-kind":e.kind,children:[r("span",{class:"timeline-dot",style:"background:var(--accent)"}),r("div",{class:"timeline-body",children:[r("div",{class:"timeline-text",children:e.text}),r("div",{class:"timeline-when",children:["periscope · ",e.kind," · ",Pe(e.at)," ago"]})]})]}):r("li",{class:"timeline-row","data-kind":e.kind,children:[r("span",{class:"timeline-dot",style:`background:${qk(e.kind,e.state)}`}),r("div",{class:"timeline-body",children:[e.url?r("a",{class:"timeline-text timeline-link",href:e.url,target:"_blank",rel:"noopener",children:e.text}):r("div",{class:"timeline-text",children:e.text}),r("div",{class:"timeline-when",children:[Uk(e.kind,e.state)," · ",Pe(e.at)," ago"]})]})]})}function Qk({data:e,streamRef:t}){const n=e.activity||[],i=n.filter(s=>s.src==="alert").reduce((s,o)=>s&&s.at>=o.at?s:o,null),l=i&&i.kind==="need_human"?i:null,a=n.filter(s=>s!==l);return r(V,{children:[l&&r("div",{class:"activity-pinned",children:[r("div",{class:"activity-pinned-label",children:["needs you · ",Pe(l.at)," ago"]}),r("div",{class:"activity-pinned-text",children:l.text})]}),a.length?r("ol",{class:"timeline activity-stream",ref:t,children:a.map((s,o)=>r(Jk,{e:s},o))}):l?null:r("div",{class:"timeline-empty",children:"no recent activity"})]})}function Yk({pid:e,onRefresh:t,idPrefix:n}){const i=ne(null),l=ne(null),a=ne(null),s=e?Cr(e):null,o=(s==null?void 0:s.tags)||[];function u(){if(!e)return;const d=Cr(e)||{tags:[]};qr(e,{notes:i.current.value,tags:d.tags})}function c(){const d=(l.current.value||"").trim();if(!d||!e)return;const p=Cr(e)||{notes:i.current.value,tags:[]},h=d.split(/[\s,]+/).filter(Boolean);qr(e,{notes:i.current.value,tags:[...p.tags,...h]}),l.current.value="",t==null||t()}function f(d){const p=Cr(e)||{notes:i.current.value,tags:[]};qr(e,{notes:i.current.value,tags:p.tags.filter((h,m)=>m!==d)}),t==null||t()}return r(V,{children:[r("textarea",{ref:i,id:`${n}-notes`,class:"modal-notes",placeholder:e?"Notes — saves on blur":"Notes unavailable (no pid)",disabled:!e,defaultValue:(s==null?void 0:s.notes)||"",onInput:()=>{clearTimeout(a.current),a.current=setTimeout(u,600)},onBlur:()=>{clearTimeout(a.current),u()},onKeyDown:d=>d.stopPropagation()}),r("div",{class:"tag-row",children:[r("div",{class:"tag-chips",id:`${n}-tags`,children:o.map((d,p)=>r("span",{class:"tag-chip","data-tag-i":p,children:[d,r("button",{class:"tag-chip-x",title:"remove",onClick:()=>f(p),children:"×"})]}))}),r("input",{ref:l,id:`${n}-tag-input`,class:"modal-tag-input",type:"text",placeholder:"add tag, Enter or comma",disabled:!e,onKeyDown:d=>{d.stopPropagation(),(d.key==="Enter"||d.key===",")&&(d.preventDefault(),c())}})]})]})}function wl({it:e,label:t,priority:n,pinned:i,onTogglePin:l}){return r("li",{class:`files-row${n?" files-row-priority":""}${i?" files-row-pinned":""}`,onClick:()=>gr({path:e.path,line:null}),title:`Open ${e.path} as a preview tab`,children:[r("span",{class:"files-op",children:Xk(e.op)}),r("span",{class:"files-path",children:t}),r("button",{type:"button",class:`files-pin${i?" files-pin-on":""}`,title:i?"Unpin file":"Pin file","aria-label":i?"Unpin file":"Pin file","aria-pressed":i?"true":"false",onClick:a=>{a.stopPropagation(),l()},children:i?"★":"☆"})]})}function Zk({pid:e}){me.value;const[t,n]=B("");if(!e)return null;const l=Fr.value[e]?Ft.value[e]:null,a=l!=null&&l.messages?jk(l.messages):[],s=uu(e);if(!a.length&&!s.length)return null;const o=new Map(a.map(g=>[g.path,g])),u=s.map(g=>o.get(g)||{path:g,op:null}),c=new Set(s),f=a.filter(g=>!c.has(g.path)),d=[...s,...f.map(g=>g.path)],p=g=>ou(g,d),h=t.trim(),m=g=>Nk(g.path,h),b=u.filter(m),{priority:x,others:w}=zk(f.filter(m)),C=g=>()=>Ig(e,g),y=[{items:b,render:g=>r(wl,{it:g,label:p(g.path),pinned:!0,onTogglePin:C(g.path)},`pin:${g.path}`)},{items:x,render:g=>r(wl,{it:g,label:p(g.path),priority:!0,pinned:!1,onTogglePin:C(g.path)},`pri:${g.path}`)},{items:w,render:g=>r(wl,{it:g,label:p(g.path),pinned:!1,onTogglePin:C(g.path)},`oth:${g.path}`)}].filter(g=>g.items.length>0);return r("section",{class:"modal-side-section modal-side-files",children:[r("h4",{children:"Files"}),r("input",{class:"files-filter",type:"text",placeholder:"filter files — text or glob",value:t,onInput:g=>n(g.currentTarget.value),onKeyDown:g=>{g.stopPropagation(),g.key==="Escape"&&(g.preventDefault(),n(""))}}),r("ul",{class:"files-list",children:[y.map((g,$)=>r(V,{children:[$>0&&r("li",{class:"files-divider","aria-hidden":"true"}),g.items.map(g.render)]})),h&&!y.length&&r("li",{class:"files-nomatch",children:"no files match"})]})]})}function Xk(e){switch(e){case"Read":return"👁";case"Write":return"+";case"Edit":case"MultiEdit":case"NotebookEdit":return"✎";default:return"·"}}function ew({data:e,onRefresh:t,containerId:n,containerClass:i,idPrefix:l}){const a=ne(null),s=ne(0),o=(e==null?void 0:e.pid)||"";j(()=>{a.current&&s.current&&(a.current.scrollTop=s.current)});function u(c){const f=Kk[c];!f||!(e!=null&&e.pane_id)||fetch(`/api/channel/push?pane_id=${encodeURIComponent(e.pane_id)}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({content:f})}).catch(()=>{})}return a.current&&(s.current=a.current.scrollTop),r("aside",{id:n,class:i,children:[r("section",{class:"modal-side-section",children:[r("h4",{children:"Linked"}),r(Vk,{data:e,onLinkAsk:u}),r(Gk,{data:e,onLinkAsk:u})]}),r("section",{class:"modal-side-section modal-side-notes",children:[r("h4",{children:"Notes"}),r(Yk,{pid:o,idPrefix:l,onRefresh:t},o)]}),r(Zk,{pid:o}),r("section",{class:"modal-side-section modal-side-activity",children:[r("h4",{children:"Activity"}),r(Qk,{data:e,streamRef:a})]})]})}let pn=null,Ir=null;function tw(){return pn?Promise.resolve(pn):(Ir||(Ir=Ji(()=>import("./chunks/preview.js").then(e=>e.P),[]).then(e=>(pn=e,e)).catch(e=>{throw Ir=null,e})),Ir)}function nw({entry:e,active:t=!0}){const[n,i]=B(()=>(pn==null?void 0:pn.PreviewTabInner)||null),[l,a]=B(null);return j(()=>{if(n)return;let s=!0;return a(null),tw().then(o=>{s&&i(()=>o.PreviewTabInner)}).catch(o=>{s&&a((o==null?void 0:o.message)||String(o))}),()=>{s=!1}},[n]),l?r("div",{class:"preview-tab-content",role:"region","aria-label":"File preview",children:[r("header",{class:"preview-header",children:r("span",{class:"preview-path",children:e.path})}),r("div",{class:"preview-body",children:r("div",{class:"preview-error",children:[r("div",{children:"Failed to load preview module:"}),r("div",{class:"preview-error-code",children:l})]})})]}):n?r(n,{entry:e,active:t}):r("div",{class:"preview-tab-content",role:"region","aria-label":"File preview",children:[r("header",{class:"preview-header",children:r("span",{class:"preview-path",children:[e.path,e.line?`:${e.line}`:""]})}),r("div",{class:"preview-body",children:r("div",{class:"preview-loading",children:"loading…"})})]})}async function vl(e,t,n,i){i(!0);try{const l=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:t.repo,branch:t.branch})}),a=await l.json().catch(()=>({}));n(l.ok?a.mode==="spawned"?a.checked_out?"checked out the PR and spawned a pane to prepare":"spawned a pane to prepare":"sent":a.detail||`HTTP ${l.status}`),Yi()}catch(l){n(String(l))}finally{i(!1)}}function rw({row:e}){const t=br(e),n=t&&r("a",{class:"rq-linear",href:t.href,target:"_blank",rel:"noopener",title:t.tip,children:t.id});if(!e.pr)return n||"—";const i=ji(e.pr.state),l=`rq-pr-link ${i.cls}`;return r(V,{children:[e.pr.url?r("a",{class:l,href:e.pr.url,target:"_blank",rel:"noopener",children:["#",e.pr.number]}):r("span",{class:l,children:["#",e.pr.number]}),n?r(V,{children:[" · ",n]}):null,e.pr.draft?" draft":""," ",e.pr.state||""," ",e.pr.ci&&!i.cls?e.pr.ci:"",r("div",{class:"rq-repo",children:e.pr.title})]})}const Uo="filter branches, PRs, people, tickets";function iw({col:e}){const{label:t,what:n}=Bi[e],i=Ll.value,l=(i==null?void 0:i.key)===e,a=lg(i,e);return r("th",{"aria-sort":l?i.dir==="asc"?"ascending":"descending":void 0,children:r("button",{type:"button",class:`rq-sort${l?" is-active":""}`,title:a?l?"reverse the order":`sort by ${n}`:"back to the default order",onClick:()=>{Ll.value=a},children:[t,l?r("span",{class:"rq-sort-dir","aria-hidden":"true",children:i.dir==="asc"?"▲":"▼"}):null]})})}function lw({row:e}){var f,d,p;const[t,n]=B(""),[i,l]=B(!1),a=((f=e.pr)==null?void 0:f.state)==="merged",s=!!e.owner||!!e.worktree||((d=e.pr)==null?void 0:d.state)==="open",o=e.walkthrough,u=e.owner?"ask the owning pane to write the walkthrough":e.worktree?"spawn a pane in the worktree to write the walkthrough":s?`check out PR #${e.pr.number} and spawn a pane to write the walkthrough`:"open the branch first (⌘K)",c=e.unresolved>0?`${e.unresolved} unresolved comment${e.unresolved===1?"":"s"}`:e.owner?"ask the owning pane to merge":"no pane on this branch";return r("tr",{class:`rq-row rq-${e.role}${a?" is-merged":""}`,children:[r("td",{class:"rq-branch",children:[o?r("button",{type:"button",class:"rq-open",onClick:()=>Su(e.repo,e.branch),children:e.branch}):e.branch,r("div",{class:"rq-repo",children:[e.repo," · ",e.role==="review-requested"?"review requested":e.role]})]}),r("td",{class:"rq-pr",children:r(rw,{row:e})}),r("td",{class:"rq-wt",children:o?`${o.stops} stop${o.stops===1?"":"s"} · ${ng(e)}`:"none"}),r("td",{class:"rq-comments",children:e.unresolved?r("b",{children:[e.unresolved," open"]}):"—"}),r("td",{class:"rq-owner",children:[e.owner?e.owner.name:(p=e.pr)!=null&&p.author?`opened by ${e.pr.author}`:"—",e.owner?null:r("div",{class:"rq-repo",children:e.worktree?"no pane":"not checked out"})]}),r("td",{class:"rq-actions",children:[r("button",{type:"button",disabled:i||!s,title:u,onClick:()=>vl("/api/reviews/prepare",e,n,l),children:o?"re-prepare":"prepare"}),r("button",{type:"button",disabled:i||!e.owner||a||e.unresolved>0,title:c,onClick:async()=>{await Jn(`Ask the owning pane to merge ${e.branch}?`,{okLabel:"Merge"})&&vl("/api/reviews/merge",e,n,l)},children:"merge"}),(a||!e.worktree)&&(o||e.unresolved)?r("button",{type:"button",disabled:i,title:"remove this review's files",onClick:async()=>{await Jn(`Remove the walkthrough and comments for ${e.branch}? This can't be undone.`,{okLabel:"Clear",danger:!0})&&vl("/api/reviews/clear",e,n,l)},children:"clear"}):null,t?r("span",{class:"rq-note",children:t}):null]})]})}function aw(){j(()=>{Yi()},[]);const e=mt.value;if(e===null)return r("div",{class:"wt-empty",children:"loading…"});const t=ig(e,Ll.value),n=ds.value,i=ag(t,n),l=`branch${t.length===1?"":"es"}`;return r("div",{class:"reviews-queue",children:[r("header",{class:"wt-head",children:[r("h2",{children:"Reviews"}),r("input",{type:"search",class:"rq-search",placeholder:Uo,"aria-label":Uo,spellcheck:!1,autocomplete:"off",value:n,onInput:a=>{ds.value=a.currentTarget.value}}),r("span",{class:"wt-sub","aria-live":"polite",children:n.trim()?`${i.length} of ${t.length} ${l}`:`${t.length} ${l}`})]}),t.length===0?r("div",{class:"wt-empty",children:"nothing open"}):i.length===0?r("div",{class:"wt-empty",children:['no branches match "',n.trim(),'"']}):r("table",{class:"rq-table",children:[r("thead",{children:r("tr",{children:[Object.keys(Bi).map(a=>r(iw,{col:a},a)),r("th",{})]})}),r("tbody",{children:i.map(a=>r(lw,{row:a},`${a.repo}/${a.branch}`))})]})]})}async function sw(e,t){const n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),i=await n.json().catch(()=>({}));return{ok:n.ok,status:n.status,data:i}}function Hd({list:e}){return e.length?r("ul",{class:"wt-comments",children:e.map((t,n)=>r("li",{class:t.resolved?"is-resolved":"",children:[r("span",{class:"wt-comment-ts",children:t.ts}),r("span",{class:"wt-comment-state",children:t.resolved?"resolved":"open"}),r("div",{class:"wt-comment-body",children:fr(t.body,{demote:!1,softBreaks:"space"})})]},n))}):null}function ow({repo:e,branch:t,stop:n,onPosted:i}){const[l,a]=B(""),[s,o]=B(""),[u,c]=B(!1);async function f(){if(!(u||!l.trim())){c(!0);try{const d=await sw("/api/reviews/comment",{repo:e,branch:t,stop:n,body:l});d.ok?(a(""),o("sent to the owning pane")):d.status===409?(a(""),o(`saved, ${d.data.detail||"not delivered"}`)):o(d.data.detail||`HTTP ${d.status}`),i()}catch(d){o(String(d))}finally{c(!1)}}}return r("div",{class:"wt-comment-box",children:[r("textarea",{rows:2,value:l,placeholder:"comment on this stop…",onInput:d=>a(d.currentTarget.value),onKeyDown:d=>{d.key==="Enter"&&(d.metaKey||d.ctrlKey)&&f()}}),r("div",{class:"wt-comment-actions",children:[r("button",{type:"button",disabled:u||!l.trim(),onClick:f,children:"comment"}),s?r("span",{class:"wt-comment-note",children:s}):null]})]})}function cw({stop:e,diffFiles:t,comments:n,repo:i,branch:l,hl:a,onPosted:s}){const[o,u]=B(!1),c=tg(e.refs,t||[]),f=c.reduce((p,h)=>p+h.hunks.length,0),d=p=>{const h=c.find(m=>m.ref.raw===p.raw&&m.hunks.length);return r("button",{type:"button",class:`md-cite${h?"":" is-inert"}`,title:h?"show hunks":"no hunk in this branch's diff",onClick:()=>h&&u(!0),children:p.raw})};return r("section",{class:"wt-stop",id:`stop-${e.id}`,children:[r("h3",{class:"wt-stop-title",children:[e.kind?r("span",{class:`wt-kind wt-kind-${e.knownKind?e.kind:"other"}`,children:e.kind}):null,e.title]}),e.refs.length?r("div",{class:"md-meta",children:r("span",{class:"md-meta-kv","data-key":"refs",children:[r("span",{class:"md-meta-k",children:"refs"}),r("span",{class:"md-meta-v",children:e.refs.map((p,h)=>r("span",{children:[h?", ":"",d(p)]},h))})]})}):null,r("div",{class:"md-doc wt-stop-body",children:fr(e.bodyMarkdown,{demote:!1,softBreaks:"space",mermaid:!0,meta:!0,cite:d})}),t&&e.refs.length?r("div",{class:"wt-evidence",children:[r("button",{type:"button",class:"wt-evidence-toggle",onClick:()=>u(!o),children:[o?"▾":"▸"," ",f," hunk",f===1?"":"s"]}),o&&c.map((p,h)=>r("div",{class:"wt-evidence-file",children:[r("div",{class:"wt-evidence-path",children:[p.ref.raw,p.file?p.generated?" — generated, not shown":"":" — not in this diff"]}),p.hunks.map((m,b)=>r(jd,{hunk:m,lang:zd(p.ref.path),hl:a,onOpen:null},b))]},h))]}):null,r(Hd,{list:n}),r(ow,{repo:i,branch:l,stop:e.title,onPosted:s})]})}function uw({repo:e,branch:t,pr:n,sig:i}){var y;const[l,a]=B({loading:!0,error:null,data:null}),[s,o]=B(null),[u,c]=B(0);j(()=>{let g=!0;return Ji(()=>import("./chunks/preview.js").then($=>$.h),[]).then($=>{g&&o(()=>$.highlightCode)}).catch(()=>{}),()=>{g=!1}},[]),j(()=>{let g=!0;return(async()=>{try{const $=await fetch(`/api/reviews/walkthrough?repo=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}`),v=await $.json().catch(()=>({}));if(!g)return;if(!$.ok){a(E=>({loading:!1,error:v.detail||`HTTP ${$.status}`,data:E.data}));return}a({loading:!1,error:null,data:v})}catch($){g&&a(v=>({loading:!1,error:String($),data:v.data}))}})(),()=>{g=!1}},[e,t,u,i]);const f=()=>{c(g=>g+1),Yi()};if(l.loading)return r("div",{class:"wt-empty",children:"loading…"});if(!l.data)return r("div",{class:"wt-empty",children:l.error});const{text:d,comments:p,diff:h,stale_by:m}=l.data,b=Xm(d),x=new Map;for(const g of p)(x.get(g.stop)||x.set(g.stop,[]).get(g.stop)).push(g);const w=new Set(b.stops.map(g=>g.title)),C=p.filter(g=>!w.has(g.stop));return r("div",{class:"walkthrough",children:[l.error?r("div",{class:"wt-empty wt-error",children:["refresh failed: ",l.error]}):null,r("header",{class:"wt-head",children:[r("h2",{children:b.title||t}),r("span",{class:"wt-sub",children:[e," · ",t,(y=b.header)!=null&&y.pr?r(V,{children:[" · ",n!=null&&n.url&&n.number===b.header.pr?r("a",{class:`rq-pr-link ${ji(n.state).cls}`,href:n.url,target:"_blank",rel:"noopener",children:["PR #",b.header.pr]}):`PR #${b.header.pr}`]}):"",m==null&&b.header?h?"":" · no worktree — hunks unavailable":m>0?` · stale: ${m} commit${m===1?"":"s"} since`:""]})]}),b.problem?r("p",{class:"wt-problem",children:b.problem}):null,b.stops.map(g=>r(cw,{stop:g,diffFiles:(h==null?void 0:h.files)||null,comments:x.get(g.title)||[],repo:e,branch:t,hl:s,onPosted:f},g.id)),C.length?r("section",{class:"wt-stop",children:[r("h3",{class:"wt-stop-title",children:"unattached comments"}),r(Hd,{list:C})]}):null]})}function dw({target:e,agent:t,onPaste:n,class:i="modal-xterm",id:l}){const a=ne(null);return j(()=>(z1(a.current,e,{agent:t,onPaste:n}),Fu),[]),r("div",{ref:a,id:l,class:i})}function hw(){const e=ne(null),[t,n]=B(!1),[i,l]=B("");j(()=>{function o(u){(u.metaKey||u.ctrlKey)&&u.key==="f"&&(u.preventDefault(),n(!0),requestAnimationFrame(()=>{var c;return(c=e.current)==null?void 0:c.focus()}))}return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[]);const a=Pi(()=>{n(!1),l(""),B1()},[]);He(a,t);function s(o){o.preventDefault(),i&&(o.shiftKey?Ks(i):Ws(i))}return t?r("form",{class:"term-search",onSubmit:s,children:[r("input",{ref:e,class:"term-search-input",value:i,placeholder:"find in terminal",onInput:o=>{l(o.currentTarget.value)}}),r("button",{type:"button",class:"term-search-btn",title:"Previous (Shift+Enter)",onClick:()=>i&&Ks(i),children:"‹"}),r("button",{type:"button",class:"term-search-btn",title:"Next (Enter)",onClick:()=>i&&Ws(i),children:"›"}),r("button",{type:"button",class:"term-search-btn",title:"Close (Esc)",onClick:a,children:"✕"})]}):null}const qd={rail:{pref:"rail_width",cssVar:"--rail-w",columnId:"rail",def:320,min:180,dir:1},side:{pref:"side_width",cssVar:"--side-w",columnId:"detail-side",def:280,min:200,dir:-1}},fw=.5;function pw(e,t,n){return Math.round(Math.min(Math.max(e,t),Math.max(t,n)))}function mw(e,t,n,i){return pw(e+n.dir*t,n.min,i*fw)}function gw(e){return Number.isFinite(e)&&e>0?e:null}function Ud({which:e}){const t=qd[e];function n(i){if(i.button!==0)return;const l=i.currentTarget,a=document.getElementById("split-view"),s=document.getElementById(t.columnId),o=l.parentElement;if(!a||!s||!o)return;i.preventDefault();const u=i.clientX,c=Math.round(s.getBoundingClientRect().width),f=o.getBoundingClientRect().width;let d=c;l.setPointerCapture(i.pointerId),l.classList.add("dragging"),document.body.classList.add("col-resizing"),F1();const p=m=>{d=mw(c,m.clientX-u,t,f),a.style.setProperty(t.cssVar,`${d}px`)},h=()=>{l.removeEventListener("pointermove",p),l.removeEventListener("pointerup",h),l.removeEventListener("pointercancel",h),l.classList.remove("dragging"),document.body.classList.remove("col-resizing"),N1(),d!==c&&Ds(t.pref,d)};l.addEventListener("pointermove",p),l.addEventListener("pointerup",h),l.addEventListener("pointercancel",h)}return r("div",{class:`col-resize col-resize-${e}`,title:"Drag to resize · double-click to reset",onPointerDown:n,onDblClick:()=>Ds(t.pref,t.def)})}function yw(e){return(e==null?void 0:e.agent)!=="claude"?"not a Claude pane":e.state!=="idle"&&e.state!=="done"?`pane is ${e.state||"busy"}, try again when it's idle`:e.pending_input?"the pane has unsent text in its input box":null}function bw(e){return(e==null?void 0:e.session_effort)||(e==null?void 0:e.launch_effort)||"default"}function kw(e){var t;return e!=null&&e.model?e.model.replace(/\s*\(.*\)/,""):e!=null&&e.session_model?((t=sr.find(n=>n.id===e.session_model))==null?void 0:t.label)||e.session_model:"model"}function ww({w:e}){var c;const[t,n]=B({}),[i,l]=B(!1);j(()=>{n({})},[e.pid,e.session_model,e.session_effort]);const a=i?"waiting for the pane to confirm the last change":yw(e);async function s(f,d){const p=d.currentTarget.value;if(d.currentTarget.value="",!p||i)return;const h=`pid=${encodeURIComponent(e.pid)}&setting=${f}&value=${encodeURIComponent(p)}`;l(!0);let m;try{m=await ie(`set ${f}`,`/api/pane/session-setting?${h}`,{method:"POST"})}finally{l(!1)}m&&(m.result==="applied"?n(b=>({...b,[f]:p})):m.result==="confirm"?bn("Claude is asking to confirm the model switch in the pane — answer it there","info",7e3):bn(`Sent ${m.sent}, but Claude didn't confirm it took`,"info",5e3))}const o=t.model?((c=sr.find(f=>f.id===t.model))==null?void 0:c.label)||t.model:kw(e),u=t.effort||bw(e);return r("span",{class:"header-session-picks",children:[r("select",{class:"header-session-pick",value:"",disabled:!!a,title:a||"change this session's model (types /model into the pane)",onChange:f=>s("model",f),children:[r("option",{value:"",hidden:!0,children:o}),sr.map(f=>r("option",{value:f.id,children:f.label},f.id))]}),r("select",{class:"header-session-pick",value:"",disabled:!!a,title:a||"change this session's effort (types /effort into the pane)",onChange:f=>s("effort",f),children:[r("option",{value:"",hidden:!0,children:`effort ${u}`}),Oa.map(f=>r("option",{value:f,children:f},f))]})]})}const vw=2e3;function _w(e,t,n){j(()=>{if(!n||!e)return;let i=!0,l=null;async function a(){try{const o=await(await fetch(`/api/pane/turns?${nt(e)}`)).json();if(!i)return;const u=o&&o.turns===null?[]:o.messages||[],c=(o==null?void 0:o.session_id)||null;Ft.value={...Ft.value,[t]:{messages:u,sessionId:c}},u.length&&!Fr.value[t]&&(Fr.value={...Fr.value,[t]:!0})}catch{}i&&(l=setTimeout(a,vw))}return a(),()=>{i=!1,l&&clearTimeout(l)}},[e,t,n])}function xw(e){const t=e.input||{};switch(e.name){case"Bash":return t.command||"";case"Read":case"Edit":case"Write":case"MultiEdit":case"NotebookEdit":return t.file_path||t.notebook_path||"";case"Grep":return t.pattern||"";case"Glob":return t.pattern||"";case"Task":case"Agent":return t.description||"";case"TaskCreate":return t.subject||"";case"TaskUpdate":return t.taskId?`#${t.taskId}`:"";case"WebFetch":return t.url||"";case"WebSearch":return t.query||"";case"Skill":return t.skill||t.command||"";case"AskUserQuestion":{const n=t.questions||[];return n.length===1?n[0].question||n[0].header||"":n.length?`${n.length} questions`:""}default:{const n=JSON.stringify(t);return n==="{}"||n==="null"?"":n.length>120?`${n.slice(0,120)}…`:n}}}function Sw({input:e}){const t=String(e.old_string||"").split(` + ${ml(o)} active tokens + ${ml(n.cache_read_tokens)} cache reads (discounted)`;return r("div",{id:"usage",class:"usage usage-fallback",title:u,children:`5h: ${ml(o)} · ${xd(n.reset_at)}`})}function B2({id:e,toggleClass:t,toggleLabel:n,title:i,children:l}){const[a,s]=B(!1),o=te(null),u=br(()=>s(!1),[]);return Fi(o,a,u),r("div",{class:"tb-dd",ref:o,children:[r("button",{type:"button",class:t,id:e,"aria-haspopup":"menu","aria-expanded":a?"true":"false",title:i,onClick:c=>{c.stopPropagation(),s(p=>!p)},children:n}),r("div",{class:"tb-dd-menu",role:"menu",hidden:!a,onClick:()=>s(!1),children:l})]})}function z2(){const e=ce.value,t=e.length,n=e.filter(o=>o.state==="needs-input").length,i=e.filter(o=>o.state==="working").length,l=e.filter(o=>o.state==="done").length,a=e.filter(o=>o.state==="idle").length,s=()=>r("span",{class:"count-sep",children:"·"});return r("span",{id:"counts",children:[r("span",{children:[r("b",{children:t})," windows"]}),n>0&&r(K,{children:[" ",r(s,{})," ",r("span",{class:"count-needs",children:[n," needs input"]})]})," ",r(s,{})," ",r("span",{class:"count-working",children:[i," working"]})," ",r(s,{})," ",r("span",{class:"count-done",children:[l," done"]})," ",r(s,{})," ",r("span",{class:"count-idle",children:[a," idle"]})]})}function j2(){j(()=>{function t(n){(n.metaKey||n.ctrlKey)&&n.key==="/"&&(ye("key.shortcut",{key:"cmd+/"}),n.preventDefault(),window.location.href="/history")}return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[]);const e=te(null);return j(()=>{const t=e.current;if(!t)return;const n=()=>document.documentElement.style.setProperty("--header-h",`${t.offsetHeight}px`);n();const i=new ResizeObserver(n);return i.observe(t),()=>i.disconnect()},[]),r("header",{class:"periscope-header",ref:e,"data-pin-rows":$n()?3:2,children:[r("div",{class:"topbar",children:[r("span",{class:"brand",children:["periscope",r("i",{class:"brand-cursor"})]}),r(N2,{}),r(k1,{}),r("div",{class:"spawn-pins",children:[r(w1,{}),r($1,{}),r(_1,{})]}),r(W0,{})]}),r("nav",{class:"filters",id:"filters",children:[r("a",{href:"/history",class:"filter-btn is-action",id:"history-link",title:"search conversation history (⌘/)",children:["🔍 history ",r("span",{class:"ps-kbd",style:"margin-left:4px",children:"⌘"}),r("span",{class:"ps-kbd",children:"/"})]}),r("span",{class:"filters-sep"}),r(h1,{}),r("span",{class:"filters-sep"}),r("button",{type:"button",class:"filter-btn is-action",id:"new-open-btn",title:"open a repo, worktree, or PR",onClick:()=>{var t;return(t=window.__periscopeOpenOmnibox)==null?void 0:t.call(window)},children:"+ new"}),r("button",{type:"button",class:"filter-btn is-action",id:"reviews-btn",title:"open branches, walkthroughs, review comments",onClick:Ra,children:["◉ reviews",Ds(gt.value)?r("span",{class:"rail-review-badge",children:Ds(gt.value)}):null]}),r(B2,{id:"more-dd-toggle",toggleClass:"filter-btn is-action tb-dd-toggle",toggleLabel:"⋯",title:"more actions",children:[r("button",{id:"cleanup-btn",class:"tb-dd-item",role:"menuitem",title:"archive worktrees with merged PRs, deleted branches, or idle activity",children:"🧹 cleanup"}),r("button",{id:"settings-btn",class:"tb-dd-item",role:"menuitem",title:"settings",children:"🛠 settings"}),r("button",{id:"open-commands",class:"tb-dd-item",role:"menuitem",title:"edit + claude / + shell / + ... commands",children:"⚙ commands"})]}),r("span",{class:"filters-sep"}),r(f1,{}),r("div",{class:"meta",children:r(z2,{})})]}),r(T2,{})]})}const H2=3e3;let gl=null,Zr=!1,So=!1,jn=!1;function q2(){if(So)return;So=!0;const e=window.WebSocket;function t(){return{readyState:0,binaryType:"arraybuffer",send(){},close(){},onopen:null,onmessage:null,onerror:null,onclose:null}}function n(i,l){return jn&&String(i).includes("/ws/pane")?t():l===void 0?new e(i):new e(i,l)}n.CONNECTING=e.CONNECTING,n.OPEN=e.OPEN,n.CLOSING=e.CLOSING,n.CLOSED=e.CLOSED,n.prototype=e.prototype,window.WebSocket=n}async function U2(e){var w,C;Zr=!0;const t=e.settleMs||2e3,n=e.switches||20,i=(e.kind||"claude")==="claude",l=(ce.value||[]).filter(y=>y.agent==="claude"===i&&y.pid),a=Math.max(2,e.poolSize||(((w=e.pids)==null?void 0:w.length)??2)),s=((C=e.pids)==null?void 0:C.length)>=2?e.pids:l.slice(0,a).map(y=>y.pid),o=document.title;if(s.length<2){ye("memtest.abort",{nonce:e.nonce,reason:"need 2 pids"}),Zr=!1;return}const u=ke.value,c=s.map(y=>yu(y)),p=e.mode||"terminal";if(!e.realClick)for(const y of s)Ul(y,p);jn=!!e.blockWs,jn&&q2();const d=document.getElementById("rail")||document.querySelector(".rail, #left");ye("memtest.start",{nonce:e.nonce,n,mode:p,blockWs:jn,pids:s,realClick:!!e.realClick,scrollRail:!!e.scrollRail,hoverStorm:!!e.hoverStorm,railScroll:d?{sh:d.scrollHeight,ch:d.clientHeight}:null,noWebgl:(()=>{try{return localStorage.getItem("periscope.noWebgl")==="1"}catch{return null}})()});const f=e.tabPath||null,h=y=>new Promise(g=>setTimeout(g,y));let m=0,b=1;function x(){const y=document.querySelectorAll(".rail-row.pane-row");if(y.length<2)return;const g=Math.min(y.length,Math.max(2,e.poolSize||y.length));m>=g&&(m=g-1);const $=y[m];if(e.scrollRail&&$.scrollIntoView({behavior:"smooth",block:"center"}),e.hoverStorm)for(const v of y)v.dispatchEvent(new MouseEvent("mouseover",{bubbles:!0})),v.dispatchEvent(new MouseEvent("mouseout",{bubbles:!0}));$.click(),m+=b,(m>=g-1||m<=0)&&(b=-b)}for(let y=1;y<=n;y++){const g=s[y%s.length];e.realClick?x():ke.value=`pane:${g}`,document.title=`memtest ${y}/${n}`,await h(f?t/3:t),f&&(kr({path:f}),await h(t/3),jr(g,"pane"),await h(t/3)),y%5===0&&ye("memtest.progress",{nonce:e.nonce,i:y})}if(f)for(const y of s)Mc(y,f);if(jn=!1,!e.realClick)for(const[y,g]of s.entries())Ul(g,c[y]||"terminal");ke.value=u,e.realClick&&(u!=null&&u.startsWith("pane:"))&&yt({kind:"pane",pid:u.slice(5)}),document.title=o,ye("memtest.done",{nonce:e.nonce,n,mode:p}),Zr=!1}async function $o(){try{const e=await fetch("/memtest.json",{cache:"no-store"});return e.ok?await e.json():null}catch{return null}}async function W2(){const e=await $o();e!==null&&(gl=e.nonce??null,setInterval(async()=>{if(Zr)return;const t=await $o();!t||t.nonce==null||t.nonce===gl||(gl=t.nonce,U2(t))},H2))}const fn=H([]);let K2=1;function V2(e){return new Promise(t=>{fn.value=[...fn.value,{...e,id:K2++,resolve:t}]})}function On(e,t){const n=fn.value.find(i=>i.id===e);fn.value=fn.value.filter(i=>i.id!==e),n&&n.resolve(t)}function Yn(e,t={}){return V2({type:"confirm",message:e,okLabel:t.okLabel||"OK",cancelLabel:t.cancelLabel||"Cancel",danger:!!t.danger})}function G2(e){return String(e??"").split(` +`).map((n,i)=>r(K,{children:[i>0?r("br",{}):null,n]}))}function J2({req:e}){const t=te(null),n=te(null),i=e.type==="confirm"&&e.danger,l=e.type==="confirm"?!1:e.type==="prompt"?null:void 0;ot(()=>On(e.id,l)),j(()=>{var p,d;const c=t.current;if(c&&!c.open&&c.showModal(),e.type==="prompt"){const f=n.current;f&&(f.focus(),f.select())}else i?(p=c==null?void 0:c.querySelector(".confirm-dialog-cancel"))==null||p.focus():(d=c==null?void 0:c.querySelector(".confirm-dialog-ok"))==null||d.focus()},[]);const a=()=>{var c;e.type==="prompt"?On(e.id,((c=n.current)==null?void 0:c.value)??""):e.type==="alert"?On(e.id,void 0):On(e.id,!0)},s=()=>On(e.id,l),o=c=>{c.target===t.current&&s()},u=e.type==="prompt"?"confirm-dialog prompt-dialog":"confirm-dialog";return r("dialog",{ref:t,class:u,onClick:o,children:[r("p",{class:"confirm-dialog-msg",children:G2(e.message)}),e.type==="prompt"&&r("input",{ref:n,type:"text",class:"prompt-dialog-input",autocomplete:"off",spellcheck:!1,value:e.defaultValue,placeholder:e.placeholder||void 0,onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),a())}}),r("div",{class:"confirm-dialog-actions",children:[e.type!=="alert"&&r("button",{type:"button",class:"confirm-dialog-cancel",onClick:s,children:e.cancelLabel}),r("button",{type:"button",class:`confirm-dialog-ok${i?" is-danger":""}`,onClick:a,children:e.okLabel})]})]})}function Q2(){const e=fn.value;return r(K,{children:e.map(t=>r(J2,{req:t},t.id))})}async function gr(e,t,n={}){let i;try{i=await fetch(t,n)}catch(a){return{error:`${e} failed: ${a.message}`,reason:a.message}}let l={};try{l=await i.json()}catch{}if(!i.ok){const a=l.detail||`HTTP ${i.status}`;return{error:l.detail||`${e} failed: ${a}`,reason:a,status:i.status}}return{data:l}}const rn=H(!1),Nt=H(null);function Y2(e){return Array.isArray(e)?e.filter(Boolean):null}function Z2(e,t){return e===t?!0:!e||!t?!1:e.length===t.length&&e.every((n,i)=>n===t[i])}function Td(e){const{paths:t}=e||{},n=Y2(t);Z2(n,Nt.value)||(Nt.value=n),rn.value=!0,ye("overlay.open",{which:"cleanup",scoped:!!Nt.value})}function X2(e){return e!=null&&e.length?`/api/cleanup/candidates?${e.map(t=>`paths=${encodeURIComponent(t)}`).join("&")}`:"/api/cleanup/candidates"}function Dn(){rn.value=!1,Nt.value=null}function eb(){ot(Dn,rn.value);const[e,t]=B(""),[n,i]=B(!1),[l,a]=B([]),[s,o]=B({}),[u,c]=B(!1),[p,d]=B(!1),f=te(0);j(()=>{const x=document.getElementById("cleanup-btn"),w=()=>Td();return x&&x.addEventListener("click",w),()=>{x&&x.removeEventListener("click",w)}},[]);async function h(){const x=++f.current;t(""),i(!0),a([]),o({});const w=Nt.peek();if(w&&w.length===0){i(!1);return}const{data:C,error:y}=await gr("load candidates",X2(w));if(x!==f.current)return;if(i(!1),y){t(y),a([]);return}const g=C.candidates||[];a(g);const $={};g.forEach((v,E)=>{$[E]=!v.dirty}),o($)}j(()=>{if(!rn.value){f.current++;return}c(!1),h()},[rn.value,Nt.value]);const m=Object.values(s).filter(Boolean).length;async function b(){t("");const x=[];if(l.forEach((y,g)=>{s[g]&&x.push({pinned_dir:y.pinned_dir,delete_branch:u})}),x.length===0)return;d(!0);const{data:w,error:C}=await gr("archive","/api/cleanup/archive",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({candidates:x})});if(d(!1),C){t(C);return}if(w.failed&&w.failed.length>0){const y=`Archived ${w.archived.length}, ${w.failed.length} failed: `+w.failed.map(g=>`${g.pinned_dir.split("/").pop()}: ${g.error}`).join("; ");await h(),t(g=>g||y);return}Dn()}return rn.value?r("div",{id:"cleanup-modal",class:"cleanup-modal-overlay",onClick:x=>{x.target.id==="cleanup-modal"&&Dn()},children:r("div",{class:"cleanup-modal-card",children:[r("header",{class:"cleanup-modal-head",children:[r("h2",{children:"🧹 cleanup"}),r("button",{id:"cleanup-modal-close",title:"close",onClick:Dn,children:"×"})]}),r("p",{class:"cleanup-modal-sub",children:"Worktrees with merged/closed PRs, deleted remote branches, or idle activity. Dirty worktrees are NOT auto-selected."}),r("div",{id:"cleanup-modal-controls",children:r("label",{class:"cleanup-delete-branches",children:[r("input",{type:"checkbox",id:"cleanup-delete-branches",checked:u,onChange:x=>c(x.currentTarget.checked)})," also delete local branches"]})}),r("div",{id:"cleanup-modal-list",children:n?r("div",{class:"cleanup-loading",children:"Walking worktrees…"}):l.length===0&&!e?r("div",{class:"cleanup-empty",children:Nt.value?"Nothing to clean up here. Cleanup only offers a worktree (never a main checkout) whose PR is merged or closed, whose remote branch is gone, or that sits idle.":"No cleanup candidates. 🎉"}):l.map((x,w)=>{const C=x.project_name||`(untracked: ${x.pinned_dir.split("/").pop()})`;return r("label",{class:x.dirty?"cleanup-row cleanup-row-dirty":"cleanup-row","data-i":w,children:[r("input",{type:"checkbox",class:"cleanup-row-check",checked:!!s[w],onChange:y=>o(g=>({...g,[w]:y.currentTarget.checked}))}),r("div",{class:"cleanup-row-body",children:[r("div",{class:"cleanup-row-title",children:C}),r("div",{class:"cleanup-row-meta",children:[x.branch," ",x.dirty?r("span",{class:"cleanup-dirty",children:"⚠ dirty"}):null]}),r("div",{class:"cleanup-row-signals",children:(x.signals||[]).map((y,g)=>r("span",{class:`cleanup-badge cleanup-badge-${y.kind}`,children:y.label},g))})]})]},x.pinned_dir)})}),r("div",{id:"cleanup-modal-error",class:"cleanup-modal-error",hidden:!e,children:e}),r("div",{class:"cleanup-modal-actions",children:[r("button",{type:"button",id:"cleanup-cancel",onClick:Dn,children:"cancel"}),r("button",{type:"button",id:"cleanup-submit",disabled:n||p||m===0,onClick:b,children:["archive selected (",m,")"]})]})]})}):null}const $i=H(!1);function Co(){$i.value=!0,ye("overlay.open",{which:"commands"})}function yl(){$i.value=!1}function tb({c:e,i:t,onDragState:n}){const i=te(null);async function l(s){const o=i.current;if(!o)return;const u=o.querySelector(".commands-label").value.trim(),c=o.querySelector(".commands-exec").value;u&&await Og(e.label,{label:u,exec:c})}async function a(){await Dg(e.label)}return r("div",{ref:i,class:"commands-row",draggable:!0,"data-label":e.label,"data-i":t,onDragStart:s=>{var o;n(e.label),(o=i.current)==null||o.classList.add("dragging"),s.dataTransfer.setData("text/plain",e.label),s.dataTransfer.effectAllowed="move"},onDragEnd:()=>n(null),onDragOver:s=>{s.preventDefault(),s.dataTransfer.dropEffect="move";const o=i.current.getBoundingClientRect(),u=s.clientY{var s;(s=i.current)==null||s.classList.remove("drag-over-top","drag-over-bottom")},onDrop:s=>{s.preventDefault();const o=i.current.getBoundingClientRect(),u=s.clientY{const l=document.getElementById("open-commands");return l&&l.addEventListener("click",Co),()=>{l&&l.removeEventListener("click",Co)}},[]);const e=te(null),t=l=>{e.current=l};t.drop=(l,a)=>{const s=e.current;if(!s||l===s)return;const o=Wr().map(d=>d.label),u=o.indexOf(s);if(u<0)return;o.splice(u,1);const c=o.indexOf(l),p=a?c:c+1;o.splice(p,0,s),Rg(o)};async function n(){const l="command";let a=l,s=1;const o=new Set(Wr().map(u=>u.label));for(;o.has(a);)a=`${l}-${++s}`;await Ig({label:a,exec:""})}if(!$i.value)return null;const i=Wr();return r("div",{id:"commands-modal",class:"commands-modal-overlay",onClick:l=>{l.target.id==="commands-modal"&&yl()},children:r("div",{class:"commands-modal-card",children:[r("header",{class:"commands-modal-head",children:[r("h2",{children:"New-window commands"}),r("button",{id:"commands-modal-close",title:"close",onClick:yl,children:"×"})]}),r("p",{class:"commands-modal-sub",children:["First row is the primary button. Drag rows to reorder. Empty ",r("code",{children:"exec"})," = bare shell."]}),r("div",{id:"commands-modal-list",children:i.map((l,a)=>r(tb,{c:l,i:a,onDragState:t},l.label))}),r("button",{id:"commands-modal-add",class:"commands-modal-add",onClick:n,children:"+ add command"})]})})}const Ed=[{id:"default",label:"default"},{id:"full",label:"full"}];function bl(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}function rb(e){return!e||e==="default"?null:e}function To(e){var t;return((t=Ed.find(n=>n.id===e))==null?void 0:t.label)||e}const Eo=["shell","idle","done","working","needs-input"];function Po(e){let t=-1;for(const n of e){const i=Eo.indexOf(n);i>t&&(t=i)}return t>=0?Eo[t]:"shell"}const Pd="";function Ya(e,t,n,i={},l=[]){const a=i.trackOrder||[],s=i.tabsByTrack||{},o=i.branchOrderByTrack||{},u=[],c={},p={},d={},f={};for(const v of e||[]){const E=v.track_id;if(!E)continue;const M=v.branch||Pd;c[E]||(u.push(E),c[E]=[],p[E]=[],d[E]={}),c[E].includes(v.pid)||c[E].push(v.pid),p[E].includes(M)||p[E].push(M),d[E][M]||(d[E][M]=[]),d[E][M].includes(v.pid)||d[E][M].push(v.pid),f[v.pid]=M}const h=(l||[]).filter(v=>v.id&&v.id!==v.repo).map(v=>v.id),m=new Set(h),b=new Set(u),x=a.filter(v=>b.has(v)||m.has(v)),w=new Set(x),C=[...x,...u.filter(v=>!w.has(v)),...h.filter(v=>!w.has(v)&&!b.has(v))],y={},g={},$={};for(const v of C){const E=c[v]||[],M=new Set(E),T=(s[v]||[]).filter(O=>M.has(O)),S=new Set(T);y[v]=[...T,...E.filter(O=>!S.has(O))];const R=p[v]||[],F=new Set(R),q=(o[v]||[]).filter(O=>F.has(O)),L=new Set(q),I=[...q,...R.filter(O=>!L.has(O))];if(I.length>=2){g[v]=I,$[v]={};for(const O of I)$[v][O]=[];for(const O of y[v]){const Q=f[O];$[v][Q]&&$[v][Q].push(O)}}else g[v]=[]}return{trackOrder:C,tabsByTrack:y,branchesByTrack:g,tabsByBranch:$}}function Ci(e,t,n=[]){for(const l of t||[])if(l.track_id===e&&l.track_name)return l.track_name;for(const l of n||[])if(l.id===e&&l.name)return l.name;if(e==="loose")return"loose";const i=String(e||"").split("/").filter(Boolean);return i[i.length-1]||e}function ib(e,t,n=[]){if(e==="loose")return"loose";for(const i of t||[])if(i.track_id===e&&i.track_kind)return i.track_kind;for(const i of n||[])if(i.id===e)return i.repo===i.id?"repo":"goal";return"repo"}function lb(e){return String(e||"").replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ab(e){const t=e.worktree_affiliation||{};if(t.kind==="sibling")return t.label||null;if(t.kind==="no-repo"||t.kind==="off-repo"){if(e.repo_key&&e.repo_label)return e.branch?`${e.repo_label}/${e.branch}`:e.repo_label;if(e.cwd)return lb(e.cwd)}return null}function sb(e,t,n,i){const l={};for(const a of i||[])if(a.walkthrough){for(const s of e)if((t[s]||[]).map(u=>n[u]).find(u=>u&&u.repo_label===a.repo&&(u.branch||Pd)===a.branch)){l[s]||(l[s]={}),l[s][a.branch]||(l[s][a.branch]=[]),l[s][a.branch].push(a);break}}return l}const Ut=H(null),qe=H(null),Ze=H(null),Tt=H(""),Xr=H("default"),ei=H("default"),ti=H("default"),ni=H("default");function ob(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}const Ti=H(null);function Ad(e,t){const n=new Map;for(const i of t||[]){if(i.track_id!==e)continue;const l=i.branch;l&&(n.has(l)||n.set(l,i.cwd||""))}return[...n.entries()].map(([i,l])=>({branch:i,cwd:l}))}function cb(e,t,n,i){const l=[],a=new Set;for(const o of Ad(e,t))a.add(o.branch),l.push({...o,live:!0});if(!n||!i)return l;for(const o of i.worktrees||[])o.repo!==n||!o.branch||a.has(o.branch)||(a.add(o.branch),l.push({branch:o.branch,cwd:o.path,live:!1}));const s=(i.repos||[]).find(o=>o.repo===n);for(const o of(s==null?void 0:s.branches)||[])!o||a.has(o)||(a.add(o),l.push({branch:o,cwd:"",live:!1}));return l}function ub(e,t,n=5){const i=[],l=new Set,a=s=>{!s||l.has(s.branch)||(l.add(s.branch),i.push(s))};a(e.find(s=>s.branch===t));for(const s of e)s.live&&a(s);for(const s of e){if(i.length>=n)break;a(s)}return i}function db(e,t){const n=String(t||"").toLowerCase().split(/[\s/]+/).filter(Boolean);return n.length?e.filter(i=>{const l=i.branch.toLowerCase();return n.every(a=>l.includes(a))}):[]}function hb(e){const t=[{id:"claude",label:"Claude",mode:"agent",agent:"claude"},{id:"codex",label:"Codex",mode:"agent",agent:"codex"}],n=new Set(["claude","codex"]),i=(e||[]).filter(l=>!n.has((l.label||"").trim().toLowerCase())).map(l=>({id:`cmd:${l.label}`,label:l.label,mode:"shell",exec:l.exec||""}));return[...t,...i]}const fb=Vt(()=>cb(Ut.value,ce.value,Za(Ut.value),Ti.value));function Za(e){var t;return((t=(Bt.value||[]).find(n=>n.id===e))==null?void 0:t.repo)||null}function pb(e){var n,i;const t=Za(e);return t&&((i=(((n=Ti.value)==null?void 0:n.repos)||[]).find(l=>l.repo===t))==null?void 0:i.default_branch)||null}function Ao(e){var n,i,l;Ut.value=e;const t=Ad(e,ce.value);qe.value=t.length?t[0].branch:null,Ze.value=null,Tt.value="",Xr.value=((n=sn.value)==null?void 0:n.account)||"default",ti.value=((i=sn.value)==null?void 0:i.model)||"default",ni.value=((l=sn.value)==null?void 0:l.effort)||"default",ei.value=qg(),ye("overlay.open",{which:"launcher"}),Ti.value=null,ie("open catalog","/api/open/catalog").then(a=>{Ut.value===e&&(Ti.value=a)})}function Or(){Ut.value=null,qe.value=null,Ze.value=null,Tt.value=""}function Mo(e){qe.value=e,Ze.value=null}function mb(){qe.value=null,Ze.value=""}function gb(){ot(Or,Ut.value!=null),j(()=>(window.__periscopeOpenLauncher=Ao,()=>{window.__periscopeOpenLauncher===Ao&&delete window.__periscopeOpenLauncher}),[]);const e=Ut.value;if(e==null)return null;const t=Wr(),n=fb.value,i=Za(e),l=n.length>0||Ze.value!=null||!!i;async function a(f){const h=new URLSearchParams({session:e,agent:f.agent||"claude",mode:f.mode});f.mode==="shell"&&f.exec&&h.set("exec",f.exec),ob(f)&&h.set("account",Xr.value);const m=bl(f)?rb(ei.value):null;m&&h.set("profile",m),bl(f)&&h.set("model",ti.value),bl(f)&&h.set("effort",ni.value);const b=Ze.value;if(b!=null&&b.trim())h.set("branch",b.trim());else if(qe.value!=null){const x=n.find(w=>w.branch===qe.value);x!=null&&x.cwd?h.set("cwd",x.cwd):x&&h.set("branch",x.branch)}await ie("new window",`/api/window/new?${h.toString()}`,{method:"POST"}),Or()}const s=hb(t),o=s[0],u=Tt.value.trim(),c=u?db(n,u).slice(0,24):ub(n,pb(e)),p=qe.value!=null&&!c.some(f=>f.branch===qe.value)?n.find(f=>f.branch===qe.value):null,d=p?[p,...c]:c;return r("div",{id:"launcher-modal",class:"launcher-modal-overlay",onClick:f=>{f.target.id==="launcher-modal"&&Or()},children:r("div",{class:"launcher-modal-card",children:[r("header",{class:"launcher-modal-head",children:[r("h2",{children:"+ New tab"}),r("button",{id:"launcher-close",title:"close",onClick:Or,children:"×"})]}),r("p",{class:"launcher-modal-sub",id:"launcher-session-name",children:["Add to track: ",Ci(e,ce.value,Bt.value)]}),l&&r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-head",children:[r("div",{class:"launcher-section-label",children:"Branch"}),r("input",{class:"launcher-branch-search",type:"text",placeholder:n.length>1?`search ${n.length} branches…`:"search branches…",value:Tt.value,onInput:f=>{Tt.value=f.target.value},onKeyDown:f=>{if(f.key==="Escape"&&Tt.value)f.stopPropagation(),Tt.value="";else if(f.key==="Enter"){const h=d[0];h&&Mo(h.branch)}}})]}),r("div",{class:"launcher-branches",children:[d.map(f=>r("button",{class:`launcher-branch${qe.value===f.branch?" is-active":""}${f.live?"":" is-dormant"}`,title:f.live?"running now":f.cwd||"no worktree yet",onClick:()=>Mo(f.branch),children:["⎇ ",f.branch]},f.branch)),Ze.value==null?r("button",{class:"launcher-branch launcher-branch-new",onClick:mb,children:"+ new branch…"}):r("input",{class:"launcher-branch-input is-active",type:"text",placeholder:"new-branch-name",ref:f=>f==null?void 0:f.focus(),value:Ze.value,onInput:f=>{Ze.value=f.target.value},onKeyDown:f=>{f.key==="Enter"&&o&&a(o)}})]}),u&&d.length===0&&r("div",{class:"launcher-empty",children:["No branch matches “",u,"”."]})]}),$n()&&r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Account"}),r("div",{class:"launcher-branches",children:lt.value.map(f=>r("button",{class:`launcher-branch${Xr.value===f.id?" is-active":""}`,onClick:()=>{Xr.value=f.id},children:f.label},f.id))})]}),r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Profile"}),r("div",{class:"launcher-branches",children:Ed.map(f=>r("button",{class:`launcher-branch${ei.value===f.id?" is-active":""}`,title:f.id==="full"?"the pipeline: superpowers, tom-workflow, codebase-health-check, plus the pipeline direction prompt":"tom-core alone, on the plugin set settings.json enables",onClick:()=>{ei.value=f.id,Ug(f.id)},children:f.label},f.id))})]}),r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Model"}),r("div",{class:"launcher-branches",children:cr.map(f=>r("button",{class:`launcher-branch${ti.value===f.id?" is-active":""}`,title:f.id==="default"?"no override — whatever the account's settings.json picks (this launch only; the header pin is the standing default)":`spawn this launch on ${f.label} (ANTHROPIC_MODEL on the pane — a hand re-run claude there keeps it)`,onClick:()=>{ti.value=f.id},children:f.label},f.id))})]}),r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Effort"}),r("div",{class:"launcher-branches",children:Fa.map(f=>r("button",{class:`launcher-branch${ni.value===f?" is-active":""}`,title:f==="default"?"no override — Claude's own choice for the model; /effort works in the pane (this launch only; the header pin is the standing default)":`spawn this launch at ${f} (--effort on the pane's claude; /effort can still change it later)`,onClick:()=>{ni.value=f},children:f},f))})]}),r("div",{class:"launcher-section",children:[r("div",{class:"launcher-section-label",children:"Run"}),r("div",{id:"launcher-list",children:s.map((f,h)=>r("button",{class:`launcher-row${h===0?" is-default":""}`,"data-label":f.label,onClick:()=>a(f),children:[r("span",{class:"launcher-row-label",children:f.label}),h===0&&r("span",{class:"launcher-row-hint",children:"⏎"})]},f.id))})]})]})})}const yb=/github\.com\/([^/]+\/[^/]+)\/pull\/(\d+)/,bb=/^#?(\d+)$/;function kb(e){const t=e.match(yb);if(t)return{repo:t[1],pr:Number(t[2])};const n=e.trim().match(bb);return n?{repo:null,pr:Number(n[1])}:null}const wb=/^(~|\.{0,2}\/)/;function vb(e){const t=(e||"").trim();return!t||!wb.test(t)?null:t.replace(/\/+$/,"")||"/"}function Yt(e,t){return e.toLowerCase().includes(t.toLowerCase())}function _b(e,t){var s;const n=(e||"").trim(),i=[];if(!n)return i;"reviews".startsWith(n.toLowerCase())&&n.length>=2&&i.push({kind:"reviews",label:"Reviews · open branches and walkthroughs",sub:"the review queue",descriptor:null});const l=vb(n);l&&!(t.worktrees||[]).some(o=>o.path===l)&&i.push({kind:"open",label:`open path: ${l}`,sub:"register + open",descriptor:{path:l}});for(const o of t.repos||[])(Yt(o.label,n)||Yt(o.repo,n))&&i.push({kind:"worktree",label:`${o.label} · new worktree…`,sub:`off origin/${o.default_branch||"HEAD"}`,repo:o.repo,branches:o.branches,descriptor:null});for(const o of t.repos||[])(Yt(o.label,n)||Yt(o.repo,n))&&i.push({kind:"track",label:`${o.label} · new track…`,sub:"goal-scoped group",repo:o.repo,descriptor:null});for(const o of t.worktrees||[])if(Yt(o.path,n)||Yt(o.branch||"",n)){const u=((s=t.repos.find(c=>c.repo===o.repo))==null?void 0:s.label)||o.repo;i.push({kind:"open",label:`${u} · ${o.branch||"detached"}`,sub:o.path,descriptor:{path:o.path}})}const a=kb(n);return a&&i.push({kind:"pr",label:a.repo?`review PR #${a.pr} in ${a.repo}`:`review PR #${a.pr}`,sub:a.repo||"choose a repo",needsRepo:!a.repo,pr:a}),i.push({kind:"command",label:`⚡ run: ${n}`,text:n}),i}const ht=H(!1);function Lo(){ht.value=!0,ye("overlay.open",{which:"open"})}function St(){ht.value=!1}const Io={open:{group:"Open",icon:"▸"},worktree:{group:"New worktree",icon:"✦"},pr:{group:"Review PR",icon:"◆"},branch:{group:"Branches",icon:"⎇"},newbranch:{group:"Branches",icon:"+"},repo:{group:"Repositories",icon:"◳"},track:{group:"New track",icon:"▧"},command:{group:"Command",icon:"⚡"},reviews:{group:"Reviews",icon:"◉"}},xb=3e3;function Sb(e){const[t,n]=B([]);return j(()=>{if(!e)return;let i=!0,l=null;const a=async()=>{const s=await ie("jobs","/api/command/jobs");i&&(Array.isArray(s)&&n(s),l=setTimeout(a,xb))};return a(),()=>{i=!1,l&&clearTimeout(l)}},[e]),t}function $b(e){const[t,n]=B(null);return j(()=>{if(!e){n(null);return}let i=!0;return n(null),(async()=>{const l=await ie("job-turns",`/api/command/jobs/${encodeURIComponent(e)}/turns`);i&&n((l==null?void 0:l.messages)||[])})(),()=>{i=!1}},[e]),{messages:t,pending:t===null}}function Cb(e){if(e.role==="system")return"— context compacted —";const t=e.role==="user"?"❯":"⏺",n=e.tool_uses||[];if(n.length){const l=n[0],a=l.input||{},s=a.command||a.file_path||a.path||a.pattern||a.description||a.query||a.url||"",o=n.length>1?` +${n.length-1}`:"";return`${t} ${l.name||"tool"}${s?`(${s})`:""}${o}`}const i=String(e.text||"").split(` +`).find(l=>l.trim())||"";return`${t} ${i}`}function Tb(){ot(St,ht.value);const[e,t]=B({repos:[],worktrees:[]}),[n,i]=B(""),[l,a]=B(null),[s,o]=B(!1),[u,c]=B(null),[p,d]=B(!1),[f,h]=B(""),[m,b]=B("claude");if(j(()=>{window.__periscopeOpenOmnibox=Lo;function $(v){(v.metaKey||v.ctrlKey)&&(v.key==="k"||v.key==="p")&&(v.preventDefault(),ht.value=!ht.value)}return document.addEventListener("keydown",$),()=>{document.removeEventListener("keydown",$),window.__periscopeOpenOmnibox===Lo&&delete window.__periscopeOpenOmnibox}},[]),j(()=>{ht.value&&(i(""),a(null),c(null),h(""),b("claude"),(async()=>{const $=await ie("open catalog","/api/open/catalog");$&&t($)})())},[ht.value]),!ht.value)return null;async function x($){if(p)return;d(!0),h("");const v=await ie("open","/api/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...$,agent:m})});if(d(!1),!v){h("open failed");return}Fg(v.ui),v.agent_pid&&(ke.value=`pane:${v.agent_pid}`,yt({kind:"pane",pid:v.agent_pid})),St()}async function w($,v){if(!v)return;d(!0),h("");const E=await ie("create track","/api/tracks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:$||null,name:v})});if(d(!1),!E){h("create track failed");return}St()}async function C($){d(!0),h("");const v=await ie("command","/api/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:$})});if(d(!1),!v){h("command failed");return}c(null),o(!0)}function y($){if($.kind==="reviews"){Ra(),St();return}if($.kind==="open")return x($.descriptor);if($.kind==="command")return C($.text);if($.kind==="pr"&&!$.needsRepo)return x({repo:$.pr.repo,pr:$.pr.pr});a({card:$})}const g=_b(n,e).map($=>({...$,group:Io[$.kind].group,icon:Io[$.kind].icon,key:$.label}));return r("div",{id:"open-omnibox",class:"open-omnibox-overlay",onClick:$=>{$.target.id==="open-omnibox"&&St()},children:r("div",{class:"open-omnibox-card",children:[!s&&r("div",{class:"launcher-branches",children:["claude","codex"].map($=>r("button",{class:`launcher-branch${m===$?" is-active":""}`,onClick:()=>b($),children:$==="claude"?"Claude":"Codex"},$))}),!l&&!s&&r(Xi,{value:n,onInput:i,placeholder:"repo, path, #PR…",items:g,onPick:y,onClose:St,empty:n?"no matches":e.roots&&!e.repos.length?`no repos found under ${e.roots.join(", ")} — add roots in ⚙ settings, or type a path`:"type a repo, path, or #PR…"}),s&&r(Eb,{selectedJob:u,onSelect:c,onBack:u?()=>c(null):()=>{o(!1),i("")},onClose:St}),l&&l.card.kind==="worktree"&&r(Ab,{card:l.card,onPick:$=>x({repo:l.card.repo,branch:$}),onBack:()=>a(null)}),l&&l.card.kind==="track"&&r(Mb,{card:l.card,onPick:$=>w(l.card.repo,$),onBack:()=>a(null)}),l&&l.card.kind==="pr"&&r(Lb,{repos:e.repos,onPick:$=>x({repo:$,pr:l.card.pr.pr}),onBack:()=>a(null)}),f&&r("div",{class:"open-omnibox-error",children:f}),p&&r("div",{class:"open-omnibox-busy",children:"opening…"})]})})}function Eb({selectedJob:e,onSelect:t,onBack:n}){const i=Sb(!e);return ot(n,!0),e?r(Pb,{jobId:e,onBack:n}):r("div",{class:"open-omnibox-jobs",children:[r("div",{class:"open-omnibox-jobs-head",children:"Commands"}),r("div",{class:"open-omnibox-list",children:[i.length===0&&r("div",{class:"open-omnibox-empty",children:"no commands yet"}),i.map(l=>r("button",{class:"open-omnibox-row",onClick:()=>t(l.id),children:[r("span",{class:`open-omnibox-jobdot${l.status==="running"?" is-running":""}`,children:l.status==="running"?"●":"✓"}),r("span",{class:"open-omnibox-label",children:l.text}),r("span",{class:"open-omnibox-sub",children:Pe(l.started_at)})]},l.id))]}),r("div",{class:"open-omnibox-footer",children:r("span",{children:[r("kbd",{children:"esc"})," back"]})})]})}function Pb({jobId:e,onBack:t}){const{messages:n,pending:i}=$b(e);return r("div",{class:"open-omnibox-console",children:[r("div",{class:"open-omnibox-console-cmd",children:r("button",{class:"open-omnibox-jobback",onClick:t,children:"← back"})}),r("div",{class:"open-omnibox-console-log",children:[i&&r("div",{class:"open-omnibox-console-spin",children:"no transcript yet — the commander is still starting…"}),!i&&n.length===0&&r("div",{class:"open-omnibox-console-spin",children:"no transcript yet"}),!i&&n.map((l,a)=>r("div",{class:"open-omnibox-console-line",children:Cb(l)},l.uuid||a))]})]})}function Xi({value:e,onInput:t,placeholder:n,items:i,onPick:l,onBack:a,empty:s}){const[o,u]=B(0),c=te(null),p=te(null),d=i.length,f=Math.min(o,Math.max(0,d-1));j(()=>{const b=requestAnimationFrame(()=>{var x;return(x=p.current)==null?void 0:x.focus()});return()=>cancelAnimationFrame(b)},[]),j(()=>{u(0)},[e]),j(()=>{var b,x;(x=(b=c.current)==null?void 0:b.querySelector(".is-active"))==null||x.scrollIntoView({block:"nearest"})},[f,d]);function h(b){b.key==="ArrowDown"?(b.preventDefault(),u(Math.min(f+1,d-1))):b.key==="ArrowUp"?(b.preventDefault(),u(Math.max(f-1,0))):b.key==="Enter"?(b.preventDefault(),i[f]&&l(i[f])):b.key==="Escape"&&a&&(b.preventDefault(),b.stopPropagation(),a())}let m=null;return r(K,{children:[r("input",{class:"open-omnibox-input",ref:p,placeholder:n,value:e,onInput:b=>t(b.target.value),onKeyDown:h}),r("div",{class:"open-omnibox-list",ref:c,children:[d===0&&r("div",{class:"open-omnibox-empty",children:s}),i.map((b,x)=>{const w=b.group&&b.group!==m?r("div",{class:"open-omnibox-group",children:b.group},`g:${b.group}`):null;return m=b.group,r(K,{children:[w,r("button",{class:`open-omnibox-row${x===f?" is-active":""}`,onMouseMove:()=>u(x),onClick:()=>l(b),children:[b.icon&&r("span",{class:"open-omnibox-icon",children:b.icon}),r("span",{class:"open-omnibox-label",children:b.label}),b.sub&&r("span",{class:"open-omnibox-sub",children:b.sub})]},b.key||x)]})})]}),r("div",{class:"open-omnibox-footer",children:[r("span",{children:[r("kbd",{children:"↑"}),r("kbd",{children:"↓"})," navigate"]}),r("span",{children:[r("kbd",{children:"↵"})," ",a?"select":"open"]}),r("span",{children:[r("kbd",{children:"esc"})," ",a?"back":"close"]})]})]})}function Ab({card:e,onPick:t,onBack:n}){const[i,l]=B(""),a=(e.branches||[]).filter(o=>o.toLowerCase().includes(i.toLowerCase())),s=a.map(o=>({key:o,group:"Branches",icon:"⎇",label:o,value:o}));return i&&!a.includes(i)&&s.push({key:`__new:${i}`,group:"Branches",icon:"+",label:`new branch "${i}"`,value:i}),r(Xi,{value:i,onInput:l,placeholder:`branch in ${e.repo}…`,items:s,onPick:o=>t(o.value),onBack:n,empty:"type a new branch name…"})}function Mb({card:e,onPick:t,onBack:n}){const[i,l]=B(""),a=i.trim(),s=a?[{key:`__tk:${a}`,group:"New track",icon:"▧",label:`create track "${a}"`,sub:e.repo,value:a}]:[];return r(Xi,{value:i,onInput:l,placeholder:`name this track (repo: ${e.repo})…`,items:s,onPick:o=>t(o.value),onBack:n,empty:"type a track name…"})}function Lb({repos:e,onPick:t,onBack:n}){const[i,l]=B(""),s=(e||[]).filter(o=>o.label.toLowerCase().includes(i.toLowerCase())||o.repo.toLowerCase().includes(i.toLowerCase())).map(o=>({key:o.repo,group:"Repositories",icon:"◳",label:o.label,sub:o.repo,value:o.repo}));return r(Xi,{value:i,onInput:l,placeholder:"repo for this PR…",items:s,onPick:o=>t(o.value),onBack:n,empty:"no matching repo"})}function Oo({which:e,label:t,fonts:n}){return r("label",{children:[t,r("select",{name:`font-${e}`,value:or(e).id,onChange:i=>Kg(e,i.currentTarget.value),children:n.map(i=>r("option",{value:i.id,children:i.name},i.id))})]})}function Ib(){return r("fieldset",{class:"font-picker",children:[r("legend",{children:"Fonts"}),r(Oo,{which:"ui",label:"Interface",fonts:mi}),r(Oo,{which:"code",label:"Code & terminal",fonts:mi.filter(e=>e.mono)})]})}const Ob=[["needs_input","A session needs input"],["done","A session finishes"],["ci_failed","CI fails on a session's PR"],["pr_merged","A linked PR merges"],["usage","Usage projected past a limit"],["quiet_when_focused","Stay quiet while the dashboard is focused"],["group","Group when more than 2 arrive at once"],["badge","Dock badge counts sessions waiting on you"]];function Db(){const e=yi();return r("fieldset",{class:"notify-settings",children:[r("legend",{children:"Notifications"}),!Ke()&&r("p",{class:"settings-overrides-hint",children:"Notifications appear in the Periscope macOS app only."}),Ob.map(([t,n])=>r("label",{class:"notify-option",children:[r("input",{type:"checkbox",name:`notify-${t}`,checked:e[t],onChange:i=>Gg(t,i.currentTarget.checked)}),n]},t))]})}function Rb({critter:e}){return r("svg",{class:"critter-preview",viewBox:e.sprite?"0 0 20 20":"-1.5 1 20 20",width:"40",height:"40","shape-rendering":"crispEdges","aria-hidden":"true",children:e.sprite?r(Gi,{sprite:e.sprite}):r(e2,{})})}function Fb(){const e=gu();return r("fieldset",{class:"tama-picker",children:[r("legend",{children:"Tamagotchi"}),r("div",{class:"tama-picker-options",children:pi.map(t=>r("label",{class:"tama-picker-option",children:[r("input",{type:"radio",name:"tama-critter",value:t.id,checked:t.id===e,onChange:()=>Wg(t.id)}),r(Rb,{critter:t}),r("span",{children:t.name})]},t.id))})]})}const ln=H(!1);function Do(){ln.value=!0,ye("overlay.open",{which:"settings"})}function Rn(){ln.value=!1}function Nb(){ot(Rn,ln.value);const[e,t]=B(""),[n,i]=B(!1),[l,a]=B(14),[s,o]=B("sibling"),[u,c]=B([]),[p,d]=B(""),[f,h]=B([]),[m,b]=B("");j(()=>{const w=document.getElementById("settings-btn");return w&&w.addEventListener("click",Do),()=>{w&&w.removeEventListener("click",Do)}},[]),j(()=>{ln.value&&(t(""),(async()=>{const{data:w,error:C}=await gr("load settings","/api/settings");if(C){t(C);return}const y=w.settings||{};a(y.cleanup_idle_days??14),o(y.worktree_layout_default??"sibling"),c(Object.entries(y.worktree_layout_overrides||{}).map(([g,$])=>({repo:g,layout:$}))),h(w.editors_available||[]),d(y.editor??""),b((y.repo_roots??["~/dev"]).join(` +`))})())},[ln.value]);async function x(w){w.preventDefault(),t("");const C=parseInt(l,10);if(!C||C<1){t("cleanup idle days must be a positive integer");return}const y={};for(const{repo:v,layout:E}of u)v&&E&&(y[v]=E);const g={cleanup_idle_days:C,worktree_layout_default:s,worktree_layout_overrides:y,editor:p||null,repo_roots:m.split(` +`).map(v=>v.trim()).filter(Boolean)};i(!0);const{error:$}=await gr("save settings","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(i(!1),$){t($);return}Rn()}return ln.value?r("div",{id:"settings-modal",class:"settings-modal-overlay",onClick:w=>{w.target.id==="settings-modal"&&Rn()},children:r("div",{class:"settings-modal-card",children:[r("header",{class:"settings-modal-head",children:[r("h2",{children:"🛠 settings"}),r("button",{id:"settings-modal-close",title:"close",onClick:Rn,children:"×"})]}),r("form",{id:"settings-form",onSubmit:x,children:[r(Ib,{}),r(Fb,{}),r(Db,{}),r("label",{children:["Cleanup idle threshold (days)",r("input",{id:"settings-cleanup-idle-days",type:"number",min:"1",value:l,onInput:w=>a(w.currentTarget.value)})]}),r("label",{children:["Preferred editor",r("select",{id:"settings-editor",value:p,onChange:w=>d(w.currentTarget.value),children:[r("option",{value:"",children:"(none — hides the rail's ↗ action)"}),f.map(w=>r("option",{value:w,children:w},w))]})]}),r("label",{children:["Repo roots",r("textarea",{id:"settings-repo-roots",rows:3,spellcheck:!1,value:m,onInput:w=>b(w.currentTarget.value)})]}),r("p",{class:"settings-overrides-hint",children:"One directory per line. Repos one level under each are offered in ⌘K; a repo elsewhere can be opened once by typing its path there."}),r("label",{children:["Default worktree layout",r("select",{id:"settings-worktree-default",value:s,onChange:w=>o(w.currentTarget.value),children:[r("option",{value:"sibling",children:"sibling — ~/dev/worktrees//"}),r("option",{value:"inline",children:"inline — /.worktrees/"})]})]}),r("fieldset",{children:[r("legend",{children:"Per-repo overrides"}),r("div",{id:"settings-overrides-list",children:u.length===0?r("div",{class:"settings-overrides-empty",children:"(none yet)"}):u.map((w,C)=>r("div",{class:"settings-overrides-row","data-repo":w.repo,children:[r("span",{class:"settings-overrides-repo",children:w.repo}),r("select",{class:"settings-overrides-layout",value:w.layout,onChange:y=>{const g=y.currentTarget.value;c($=>$.map((v,E)=>E===C?{...v,layout:g}:v))},children:[r("option",{value:"sibling",children:"sibling"}),r("option",{value:"inline",children:"inline"})]}),r("button",{type:"button",class:"settings-overrides-remove",title:"remove override",onClick:()=>c(y=>y.filter((g,$)=>$!==C)),children:"×"})]},w.repo))}),r("p",{class:"settings-overrides-hint",children:["Auto-detected on first ",r("code",{children:"+ project"})," per repo. Edit or remove rows here."]})]}),r("div",{id:"settings-modal-error",class:"settings-modal-error",hidden:!e,children:e}),r("div",{class:"settings-modal-actions",children:[r("button",{type:"button",id:"settings-cancel",onClick:Rn,children:"cancel"}),r("button",{type:"submit",id:"settings-submit",disabled:n,children:"save"})]})]})]})}):null}function Bb(){return j(()=>{i1(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})},[]),r(K,{children:[r(nb,{}),r(eb,{}),r(Nb,{}),r(gb,{}),r(Tb,{})]})}const Ro=120,zb=3600,ea=e=>`${e.repo_slug||e.repo_key||""}#${e.pr}`;function Fo(e){let t=0;for(const n of e.message||"")t=t*31+n.codePointAt(0)|0;return`question:${e.pane_id||e.target}@${e.ts}:${(t>>>0).toString(36)}`}const Dr={calm:0,grumpy:1,furious:2};function jb(e,t,n){const{windows:i=[],alerts:l=[],dismissedAlertIds:a=new Set,dismissedNeedsPids:s=new Set,dismissedReadyPids:o=new Set,plan:u={}}=t,c=!e,p=(e==null?void 0:e.pass)??0,d=p+1,f=(e==null?void 0:e.seen)||{},h=new Set;for(const[T,S]of Object.entries(f))typeof S=="number"&&S<=p&&p-S<=Ro&&h.add(T);const m={},b=[],x=(T,S)=>{m[T]=d,!c&&!h.has(T)&&b.push({key:T,...S})},w=T=>{m[T]=d},C=La(i,l,a,s),y=new Set;for(const T of C)T.kind==="live"&&(y.add(T.w.pid),x(`needs:${T.w.pid}@${T.w.needs_since||0}`,{kind:"needs_input",w:T.w}));for(const T of i)T.state==="needs-input"&&s.has(T.pid)&&w(`needs:${T.pid}@${T.needs_since||0}`);for(const T of C){if(T.kind!=="event")continue;const S=Fo(T);T.w&&y.has(T.w.pid)?(c||h.has(S))&&w(S):x(S,{kind:"question",w:T.w,alert:T})}for(const T of l)T.kind==="need_human"&&a.has(T.id)&&w(Fo(T));for(const T of i){if(T.state!=="done")continue;const S=`done:${T.pid}@${T.completed_at||0}`;o.has(T.pid)?w(S):x(S,{kind:"done",w:T})}const g={};for(const[T,S]of Object.entries((e==null?void 0:e.prAt)||{}))d-S<=zb&&(g[T]=S);const $={},v={};for(const T of Object.keys(g))T in((e==null?void 0:e.ci)||{})&&($[T]=e.ci[T]),T in((e==null?void 0:e.prs)||{})&&(v[T]=e.prs[T]);const E=new Map;for(const T of i){if(!T.pr||T.pr_linked&&!T.pr_state)continue;const S=ea(T);(!E.has(S)||T.pr_state&&!E.get(S).pr_state)&&E.set(S,T)}for(const[T,S]of E){g[T]=d;const F=(!S.pr_state||S.pr_state==="open")&&S.ci||null;!c&&T in $&&$[T]!=="✗"&&F==="✗"&&b.push({key:`ci:${T}`,kind:"ci_failed",w:S}),$[T]=F,S.pr_state&&(!c&&v[T]==="open"&&S.pr_state==="merged"&&b.push({key:`merged:${T}`,kind:"pr_merged",w:S}),v[T]=S.pr_state)}const M={};for(const[T,S]of Object.entries((e==null?void 0:e.meters)||{}))Number(T.slice(T.lastIndexOf("/")+1))*60>n&&(M[T]=S);for(const[T,S]of Object.entries(u||{})){if(!(S!=null&&S.available)||!S.meters||!c&&Ha(S,n))continue;let R=null;for(const[F,q]of Object.entries(S.meters)){if(!(q!=null&&q.resets_at))continue;const L=Ku(q),I=`${T}/${F}/${Math.round(q.resets_at/60)}`,O=M[I]??0;M[I]=Math.max(O,Dr[L]),!c&&Dr[L]>O&&(!R||Dr[L]>Dr[R.mood])&&(R={key:`usage:${I}:${L}`,kind:"usage",account:T,meter:F,m:q,mood:L})}R&&b.push(R)}for(const T of h)!(T in m)&&d-f[T]<=Ro&&(m[T]=f[T]);return{state:{pass:d,seen:m,ci:$,prs:v,prAt:g,meters:M},events:b}}const Zn=(e,t)=>{const n=String(e||"").trim(),i=Array.from(n);return i.length>t?`${i.slice(0,t-1).join("")}…`:n},kl=e=>Zn(_e(e),26),Fn=e=>[e==null?void 0:e.session,e==null?void 0:e.branch].filter(Boolean).join(" · "),wl=e=>!!(e!=null&&e.pid&&e.agent==="claude"),No=e=>{const t=/^mcp__(.+?)__(.+)$/.exec(e||"");return t?`${t[2]} (${t[1]})`:e||"this"};function Hb(e){const t=String(e||"").replace(/\s+/g," ").trim(),n=t.match(/^.*?[.!?](?=\s[A-Z0-9]|$)/);return Zn(n?n[0]:t,140)}const Bo={permission:"Waiting for your approval.",question:"Waiting for your answer.",dialog:"Waiting for your input."},qb={failure:"✗",pending:"⟳",success:"✓"},Md=e=>`usage_to_${e}`;function Ld(e,t={}){var l,a;const n=e.w,i={kind:e.kind,thread:e.kind,target:(n==null?void 0:n.target)||"",data:{}};switch(e.kind){case"needs_input":{const s=n.pending_permission;return s!=null&&s.request_id&&n.pid?{...i,title:`${kl(n)} needs you`,subtitle:Fn(n),body:s.summary?`Allow ${No(s.tool)}: ${s.summary}?`:`Allow ${No(s.tool)}?`,category:"needs_permission",data:{open:"pane",pid:n.pid,request_id:s.request_id}}:{...i,title:`${kl(n)} needs you`,subtitle:Fn(n),body:Bo[du(n.waiting_for)]||Bo.dialog,category:"needs_dialog",data:{open:"pane",pid:n.pid}}}case"question":{const s=e.alert;return{...i,title:`${Zn(n?_e(n):s.name||s.session||"A session",26)} asks`,subtitle:n?Fn(n):s.session||"",body:Zn(s.message,180),target:s.target||i.target,...wl(n)?{category:"question"}:{},data:{open:"pane",pid:(n==null?void 0:n.pid)??null}}}case"done":return{...i,title:`${kl(n)} is done`,subtitle:n.pr&&n.pr_linked?`${n.session} · PR #${n.pr}`:Fn(n),body:Hb(n.last_reply||n.recap||n.last_line)||"Finished.",category:"done_seen",data:{open:"pane",pid:n.pid,session:n.session}};case"ci_failed":{const s=(n.ci_checks||[]).map(p=>`${qb[p.state]||"·"} ${p.name}`).join(" · "),o=lr(n.repo_slug,n.pr),u=wl(n)?n:(t.windows||[]).find(p=>wl(p)&&ea(p)===ea(n));let c;return u!=null&&u.pid&&o?c="ci_failed":u!=null&&u.pid?c="ci_failed_fix":o&&(c="ci_failed_pr"),{...i,title:`CI failed on #${n.pr}`,subtitle:[n.session,_e(n)].filter(Boolean).join(" · "),body:s||"Checks are failing.",...c?{category:c}:{},data:{open:"url",url:o,pid:(u==null?void 0:u.pid)||n.pid,pr:n.pr,checks:(n.ci_checks||[]).filter(p=>p.state==="failure").map(p=>p.name)}}}case"pr_merged":{const s=lr(n.repo_slug,n.pr);let o;return n.cwd&&s?o="pr_merged":n.cwd?o="pr_merged_cleanup":s&&(o="pr_merged_pr"),{...i,title:`PR #${n.pr} merged`,subtitle:n.pr_base?`${n.session} · ${n.branch} → ${n.pr_base}`:Fn(n),body:"The worktree and its session can be cleaned up.",...o?{category:o}:{},data:{open:"url",url:s,pid:n.pid,cwd:n.cwd}}}case"usage":{const s=t.accounts||[],o=Zn(((l=s.find(h=>h.id===e.account))==null?void 0:l.label)||e.account,16),u=s.length>1,c=Math.max(...[e.m.projected_percent,e.m.projected_recent].filter(h=>h!=null),-1),p=(t.windows||[]).filter(h=>h.state==="working"&&h.account===e.account).length,d=(a=t.moveTargets)==null?void 0:a[e.account],f=d&&d!==e.account;return{...i,target:"",title:u?`Account ${o} is running hot`:"Usage is running hot",subtitle:`${Ua(e.meter)} usage ${Math.round(e.m.percent??0)}%`+(c>=0?` · →${Math.round(c)}% at reset`:""),body:u?`${wn(p,"session")} working on ${o}.`:`${wn(p,"session")} working.`,category:f?Md(d):"usage",data:f?{open:"usage",spawn_to:d}:{open:"usage"}}}default:return null}}const rt=(e,t,n={})=>Object.freeze({id:e,title:t,...n}),zo=rt("open_pr","Open PR"),Ub=rt("mark_seen","Mark seen"),jo=rt("cleanup","Clean up worktree",{foreground:!0}),Wb=rt("details","Details",{foreground:!0}),Kb=rt("open","Open",{foreground:!0}),Ho=rt("fix","Ask agent to fix",{auth:!0});function Vb({accounts:e=[],moveTargets:t={}}={}){const n=[{id:"done_seen",actions:[Ub]},{id:"ci_failed_pr",actions:[zo]},{id:"pr_merged",actions:[jo]},{id:"pr_merged_cleanup",actions:[jo]},{id:"pr_merged_pr",actions:[zo]},{id:"usage",actions:[Wb]},{id:"needs_permission",actions:[rt("allow","Allow",{auth:!0})]},{id:"needs_dialog",actions:[Kb]},{id:"question",actions:[rt("send","Reply",{auth:!0,reply:{button:"Send",placeholder:"Reply…"}})]},{id:"ci_failed",actions:[Ho]},{id:"ci_failed_fix",actions:[Ho]}];for(const i of[...new Set(Object.values(t||{}))].sort())n.push({id:Md(i),actions:[rt("spawn_on",`Spawn on ${yn(i,e||[])}`)]});return n}const Gb=Object.freeze({openExternal:Ki,openUsageDetails:Cd,pickSpawnAccount:Mu,openCleanupModal:Td,markReadySeen:Cu,selectPane:at,revealPane:jt,post:Lg,toast:kn,notify:ku}),Jb={allow:"Allow",deny:"Deny",send:"Reply",fix:"Ask agent to fix"},Qb={allow:"Couldn't allow",deny:"Couldn't deny",send:"Couldn't send your reply",fix:"Couldn't ask the agent to fix"},Yb=new Set(["allow","deny"]),Zb={"/api/pane/permission":"The dialog changed — open the pane to answer it.","/api/pane/reply":"The pane has a dialog open, or isn't running an agent — open it to see why."};function Xb(e,t){return(t==null?void 0:t.status)===404?"The pane is gone.":(t==null?void 0:t.status)===0?"Periscope isn't answering.":(t==null?void 0:t.status)===409?typeof t.detail=="string"&&t.detail!==`HTTP ${t.status}`?t.detail:Zb[e]:(t==null?void 0:t.detail)||"No answer"}const ek=e=>{const t=e.codePointAt(0);return t!==9&&t!==10&&(t<32||t>=127&&t<=159)},tk=e=>[...String(e)].filter(t=>!ek(t)).join("").trim();function nk(e,t){const n=(t||[]).map(tk).filter(Boolean),i=n.length?`${n.join(" · ")}.`:"Checks are failing.";return`CI failed on #${e}: ${i} Please investigate and fix.`}async function vl({target:e,show:t},n,i,l,a){let s=!1;const o=u=>{s||(s=!0,Promise.resolve().then(()=>a.notify({kind:"notice",thread:"notice",title:Qb[n],body:u,target:e,data:{open:"pane",pid:l.pid},quiet_when_focused:!0})).catch(c=>console.error("[notify] follow-up failed",c)))};try{if(!l.pid||Yb.has(n)&&!l.request_id){o("Open the pane to answer it."),t();return}const u=await a.post(i,l);if(u!=null&&u.ok)return;const c=Xb(i,u);o(c),t(),(u==null?void 0:u.status)!==409&&a.toast(`${Jb[n]} failed: ${(u==null?void 0:u.detail)||"no answer"}`,"bad",6e3)}catch(u){console.error("[notify] action failed",n,u),o((u==null?void 0:u.message)||"Periscope isn't answering.");try{t()}catch(c){console.error("[notify] reveal failed",c)}}}function rk({target:e,action:t,text:n,data:i}={},l=Gb){i||(i={});let a;const s=()=>a?l.selectPane(a):e&&l.revealPane(e);try{switch(a=i.pid?(ce.peek()||[]).find(o=>String(o.pid)===String(i.pid)):null,t){case"open_pr":i.url?l.openExternal(i.url):s();return;case"details":l.openUsageDetails();return;case"spawn_on":i.spawn_to&&l.pickSpawnAccount(i.spawn_to);return;case"mark_seen":a&&l.markReadySeen(a);return;case"cleanup":{const o=i.cwd||(a==null?void 0:a.cwd);o?l.openCleanupModal({paths:[o]}):s();return}case"allow":case"deny":return vl({target:e,show:s},t,"/api/pane/permission",{pid:i.pid,request_id:i.request_id,choice:t},l);case"send":{const o=String(n||"").trim();return o?vl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:o},l):void 0}case"fix":return vl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:nk(i.pr,i.checks)},l);case"open":s();return;default:console.warn("[notify] unknown action",t)}}catch(o){console.error("[notify] action failed",t,o);try{s()}catch(u){console.error("[notify] reveal failed",u)}}}const ta=3e3,ik=2,lk=new Set(["needs_input","question"]);function ak(e,t,n,i=!0){const l=t.filter(o=>n-o{var t;return e.kind==="question"?"question":du((t=e.w)==null?void 0:t.waiting_for)==="permission"?"permission":"input"};function ok(e){var n,i;const t=new Set(e.map((l,a)=>{var s,o;return((s=l.w)==null?void 0:s.pid)??((o=l.alert)==null?void 0:o.pane_id)??a})).size;return{kind:"summary",thread:"needs_you",target:"",data:{open:"pane",pid:((i=(n=e[0])==null?void 0:n.w)==null?void 0:i.pid)??null},title:t===1?"1 more session needs you":`${t} more sessions need you`,subtitle:"",body:e.map(l=>{var a;return`● ${l.w?_e(l.w):((a=l.alert)==null?void 0:a.name)||"a session"} · ${sk(l)}`}).join(` +`)}}function Id(e,t,n){if(e.length===1)try{const i=t(e[0],n);if(i)return i}catch(i){console.error("[notify] banner failed",e[0].key,i)}return ok(e)}const Od="periscope.notify.v1",ck=15*60*1e3;function uk(e,t){try{const n=JSON.parse((e==null?void 0:e.getItem(Od))||"null");if(!(n!=null&&n.state)||!(n.at<=t)||t-n.at>ck)return null;const i=Array.isArray(n.held)?n.held:[];return{state:n.state,held:i,heldSince:i.length?n.heldSince??n.at:null}}catch{return null}}function dk(e,t,n,i=[],l=null){try{e==null||e.setItem(Od,JSON.stringify({at:n,state:t,held:i,heldSince:l}))}catch{}}const hk={question:"needs_input"},fk=(e,t)=>e[hk[t]||t]!==!1;function pk({target:e,data:t}={}){if(t||(t={}),t.open==="url"&&t.url){Ki(t.url);return}if(t.open==="usage"){Cd();return}const n=t.pid!=null&&(ce.value||[]).find(i=>String(i.pid)===String(t.pid));n?at(n):jt(e)}const mk={sends:[],flush:[],badge:null};function gk(e,t,n,i,l=Ld){let{state:a,recent:s,held:o,heldSince:u,lastBadge:c,lastCategories:p}=e;const d={quiet_when_focused:n.quiet_when_focused},f=[],h={accounts:t.accounts,windows:t.windows,moveTargets:t.moveTargets};o.length&&i-u>=ta&&(f.push({...Id(o,l,h),...d}),o=[],u=null);let m=null;const b=g=>({state:a,recent:s,held:o,heldSince:u,lastBadge:c,lastCategories:p,...mk,flush:f,categories:m,timerAt:o.length?u+ta:null,...g});if(t.alerts===null)return b();try{const g=Vb({accounts:t.accounts,moveTargets:t.moveTargets}),$=JSON.stringify(g);$!==p&&(m=g,p=$)}catch(g){console.error("[notify] category set failed",g)}const x=xu(t.windows,t.alerts,t.dismissedAlertIds,t.dismissedNeedsPids,i/1e3),w=n.badge?x.size:0,C=w===c?null:w;if(c=w,!a&&(!t.windows.length||e.editing))return b({badge:C});const y=[];if(!e.editing){const g=jb(a,t,i/1e3);a=g.state;const $=ak(g.events.filter(v=>fk(n,v.kind)),s,i,n.group);s=$.recent;for(const v of $.now){let E=null;try{E=l(v,h)}catch(M){console.error("[notify] banner failed",v.key,M)}E&&y.push({...E,...d})}$.held.length&&(o=[...o,...$.held],u??(u=i))}return b({sends:y,badge:C})}const yk=2e3;function bk(e={setNotifyCategories:r1,notify:ku}){let t=Promise.resolve();return(n,i)=>{n&&(t=t.then(()=>Promise.race([e.setNotifyCategories(n),new Promise(l=>setTimeout(l,yk))])).catch(l=>console.error("[notify] registration failed",l))),i.length&&(t=t.then(()=>{for(const l of i)try{e.notify(l)}catch(a){console.error("[notify] post failed",a)}}))}}let qo=!1;function kk(){if(qo||!Ke())return;qo=!0;const e=typeof localStorage>"u"?null:localStorage,t=uk(e,Date.now());let n={state:null,held:[],heldSince:null,...t,recent:[],lastBadge:void 0,lastCategories:void 0};const i=u=>dk(e,n.state,u,n.held,n.heldSince),l=bk();let a=null,s=null;const o=()=>{a=null,s=null;const u=n.held;if(n={...n,held:[],heldSince:null},!u.length)return;n.state&&i(Date.now());const c={accounts:lt.peek(),windows:ce.peek()||[],moveTargets:ui.peek()};l(null,[{...Id(u,Ld,c),quiet_when_focused:yi().quiet_when_focused}])};t1(pk),n1(u=>rk(u)),it(()=>{Pc.value,Li(()=>{var u;try{const c={windows:ce.peek()||[],alerts:nr.peek(),dismissedAlertIds:ir.peek(),dismissedNeedsPids:ft.peek(),dismissedReadyPids:pt.peek(),plan:((u=Ri.peek())==null?void 0:u.plan)||{},accounts:lt.peek(),moveTargets:ui.peek()},p=!!(ya.peek()||Et.peek()),d=Date.now(),f=n,{sends:h,flush:m,badge:b,categories:x,timerAt:w,...C}=gk({...n,editing:p},c,yi(),d);n=C,n.state&&(n.state!==f.state||n.held!==f.held)&&i(d),l(x,[...m,...h]),w==null?(a&&clearTimeout(a),a=null,s=null):w!==s&&(a&&clearTimeout(a),s=w,a=setTimeout(o,Math.max(0,w-d))),b!==null&&Xg(b)}catch(c){console.error("[notify] pass failed",c)}})})}const wk=3e3,vk=2e3;let Ei=0;function Dd(){return document.getElementById("connection-banner")}function Rd(e){try{if(nr.value=e.alerts||[],ya.value||Et.value)return;ce.value=e.windows||[],Oi.value=e.projects||[],Di.value=e.workspaces||[],Bt.value=e.tracks||[],$h(ce.value),Ri.value={plan:e.usage_plan,fallback:e.usage,poke:e.poke||{}},ma.value=e.update||null,Cc.value=e.resources||null,lt.value=e.accounts||[],ui.value=e.move_targets||{},Kn.value=e.spawn_account||null,Vn.value=e.spawn_model||null,Gn.value=e.spawn_effort||null,sn.value=e.launch_default||null,Tc.value=e.walls||null,ga.value=e.wall_spans||[],Ec.value=e.editor||""}finally{Pc.value+=1}}function Fd(){if(Ei>0){Ei=0;const e=Dd();e&&(e.hidden=!0),document.body.classList.remove("disconnected")}}function Nd(e){if(Ei+=1,Ei>=2){const t=Dd();t&&(t.hidden=!1),document.body.classList.add("disconnected")}e&&console.warn("[periscope]",e)}async function _k(){if(!ya.value&&!Et.value)try{const e=await fetch("/api/state");if(!e.ok)throw new Error(`HTTP ${e.status}`);Rd(await e.json()),Fd()}catch(e){Nd(`poll failed: ${e.message}`)}}let _l=!1,na=!1,Xn=null,Ot=null,pn=null;function xk(){if(Ot)return;const e=async()=>{await _k(),Ot!==null&&(Ot=setTimeout(e,wk))};Ot=setTimeout(e,0)}function Bd(){Ot&&(clearTimeout(Ot),Ot=null)}const Sk=1e4;let Dt=null,Uo=0;async function el(){const e=++Uo;try{const t=await fetch("/api/reviews");if(!t.ok)return;const n=await t.json();e===Uo&&(gt.value=n.rows||[])}catch{}}function $k(){if(Dt)return;const e=async()=>{await el(),Dt!==null&&(Dt=setTimeout(e,Sk))};Dt=setTimeout(e,0)}function Ck(){Dt&&(clearTimeout(Dt),Dt=null)}function zd(){const e=location.protocol==="https:"?"wss:":"ws:",t=new WebSocket(`${e}//${location.host}/ws/state`);Xn=t,t.onmessage=n=>{Bd();try{Rd(JSON.parse(n.data)),Fd()}catch(i){Nd(`bad frame: ${i.message}`)}},t.onclose=()=>{na||(Xn=null,xk(),pn||(pn=setTimeout(()=>{pn=null,zd()},vk)))},t.onerror=()=>{try{t.close()}catch{}}}function Tk(){return _l?()=>{}:(_l=!0,na=!1,zd(),$k(),()=>{if(na=!0,Ck(),_l=!1,Xn){try{Xn.close()}catch{}Xn=null}Bd(),pn&&(clearTimeout(pn),pn=null)})}const Ek=/[A-Za-z0-9_]+|\s+|[^A-Za-z0-9_\s]/g;function Wo(e){return String(e??"").match(Ek)||[]}function Pk(e,t){let n=0;for(;n{const b=[],x=(w,C)=>{if(!w)return;const y=b[b.length-1];y&&y.changed===C?y.text+=w:b.push({text:w,changed:C})};return x(f.slice(0,h).join(""),!1),x(f.slice(h,m).join(""),!0),x(f.slice(m).join(""),!1),b},p=c(i,a,i.length-s),d=c(l,a,l.length-s);return!p.some(f=>f.changed)&&!d.some(f=>f.changed)?null:{del:p,add:d}}function Lk(e,t=.5){const n=e.map(l=>({...l}));let i=0;for(;i0&&s===o)for(let u=0;ui?a:i+1}return n}const Ik=["dist/","build/","vendor/",".next/","target/debug/","target/release/"],Ok=new Set(["package-lock.json","yarn.lock","pnpm-lock.yaml","uv.lock","poetry.lock","Cargo.lock","Gemfile.lock","composer.lock","go.sum"]),Dk=[".min.js",".min.css",".map",".snap"];function jd(e){const t=String(e||"");if(!t)return!1;const n=t.split("/").pop()||"";if(Ok.has(n)||Dk.some(l=>n.endsWith(l)))return!0;const i=`${t}/`;return Ik.some(l=>i.includes(`/${l}`)||i.startsWith(l))}function Rk(e){const t=[],n=[];for(const i of e||[])(jd(i.path)?n:t).push(i);return t.concat(n)}const ra=H({}),Fk="\0";function Hd(e,t){return`${e}${Fk}${t}`}function qd(e,t,n,i,l=!1){const a=e[Hd(t,n)];if(!a)return{collapsed:l,viewed:!1};const s=!!a.viewedSig&&a.viewedSig===i;return{collapsed:a.collapsed===void 0?l:a.collapsed,viewed:s}}function Ud(e,t,n){const i=Hd(e,t),l={...ra.value},a={...l[i]||{},...n};a.collapsed===void 0&&!a.viewedSig?delete l[i]:l[i]=a,ra.value=l}function Nk(e,t,n){Ud(e,t,{collapsed:n})}function Bk(e,t,n,i){Ud(e,t,{viewedSig:i?n:void 0,collapsed:!!i})}function zk(e,t,n){return n.reduce((i,l)=>i+(qd(e,t,l.path,l.sig).viewed?1:0),0)}const jk=[["session","This session","Changes since the current Claude session started"],["branch","This branch","Changes vs where this branch forked"]],Hk={js:"js",mjs:"js",cjs:"js",jsx:"jsx",ts:"ts",tsx:"tsx",py:"py",rs:"rs",json:"json",css:"css",html:"html",htm:"html",md:"md",markdown:"md"};function Wd(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0&&Hk[t.slice(n+1).toLowerCase()]||""}function Ko({text:e,lang:t,hl:n}){if(!n||!t)return e||" ";try{return n(e,t)}catch{return e||" "}}function qk({line:e,lang:t,hl:n}){return r("div",{class:`dl dl-${e.kind}`,children:r("span",{class:"dl-text",children:e.segs?e.segs.map((i,l)=>r("span",{class:i.changed?"dl-intra":"",children:r(Ko,{text:i.text,lang:t,hl:n})},l)):r(Ko,{text:e.text,lang:t,hl:n})})})}function Kd({hunk:e,lang:t,hl:n,onOpen:i,title:l}){return r("div",{class:"dhunk",children:[r("button",{type:"button",class:"dhunk-head",disabled:!i,title:i?l:void 0,onClick:()=>i==null?void 0:i(e.new_start),children:[r("span",{class:"dhunk-range",children:["@@ ",e.new_start]}),e.header?r("span",{class:"dhunk-sym",children:e.header}):null]}),Lk(e.lines).map((a,s)=>r(qk,{line:a,lang:t,hl:n},s))]})}function Uk({file:e,repo:t,review:n,hl:i}){const l=jd(e.path),{collapsed:a,viewed:s}=qd(n,t,e.path,e.sig,l),o=!a,u=Wd(e.path),c=t&&e.status!=="deleted"&&e.status!=="binary",p=(e.additions||0)+(e.deletions||0);return r("div",{class:`dfile dfile-${e.status}${s?" is-viewed":""}${l?" is-generated":""}`,children:[r("div",{class:"dfile-head",children:[r("button",{type:"button",class:"dfile-toggle",onClick:()=>Nk(t,e.path,o),children:[r("span",{class:"dfile-caret",children:o?"▾":"▸"}),r("span",{class:"dfile-path",children:e.path}),l?r("span",{class:"dfile-gen",title:"Generated artifact — folded by default and sorted last",children:"generated"}):null,r("span",{class:"dfile-status",children:e.status}),r("span",{class:"dfile-stat",children:[e.additions?r("span",{class:"dstat-add",children:["+",e.additions]}):null,e.deletions?r("span",{class:"dstat-del",children:["−",e.deletions]}):null,!p&&e.status==="binary"?r("span",{class:"dstat-bin",children:"binary"}):null]})]}),r("button",{type:"button",class:`dfile-viewed${s?" is-on":""}`,title:s?"Marked viewed — re-surfaces automatically if this file changes again":"Mark viewed (folds it away until it changes again)",onClick:()=>Bk(t,e.path,e.sig,!s),children:s?"✓ viewed":"viewed"})]}),o&&e.hunks.map((d,f)=>r(Kd,{hunk:d,lang:u,hl:i,onOpen:c?h=>kr({path:`${t}/${e.path}`,line:h}):null,title:`Open ${e.path}:${d.new_start}`},f)),o&&e.truncated?r("div",{class:"dfile-trunc",children:"diff truncated — open the file to see the rest"}):null]})}const Wk=[3,10,25];function Kk({target:e,active:t,gitSig:n}){var x,w,C;const[i,l]=B("session"),[a,s]=B(3),[o,u]=B({loading:!0,error:null,data:null}),[c,p]=B(null);j(()=>{if(!t||c)return;let y=!0;return Zi(()=>import("./chunks/preview.js").then(g=>g.h),[]).then(g=>{y&&p(()=>g.highlightCode)}).catch(()=>{}),()=>{y=!1}},[t,c]),j(()=>{if(!t||!e)return;let y=!0;return(async()=>{try{const g=await fetch(`/api/fs/diff?${tt(e)}&scope=${i}&context=${a}`);if(!y)return;if(!g.ok){const $=await g.json().catch(()=>({}));u({loading:!1,error:$.detail||`HTTP ${g.status}`,data:null});return}u({loading:!1,error:null,data:await g.json()})}catch(g){y&&u({loading:!1,error:String(g),data:null})}})(),()=>{y=!1}},[e,i,t,n,a]);const d=Rk(((x=o.data)==null?void 0:x.files)||[]),f=((w=o.data)==null?void 0:w.repo)||"",h=ra.value,m=zk(h,f,d),b=d.reduce((y,g)=>({a:y.a+(g.additions||0),d:y.d+(g.deletions||0)}),{a:0,d:0});return r("div",{class:"changes-tab",children:[r("header",{class:"changes-head",children:[r("span",{class:"changes-scope",children:jk.map(([y,g,$])=>r("button",{type:"button",class:i===y?"is-active":"",title:$,onClick:()=>l(y),children:g},y))}),r("span",{class:"changes-ctx",title:"Lines of context around each change",children:Wk.map(y=>r("button",{type:"button",class:a===y?"is-active":"",onClick:()=>s(y),children:y},y))}),!o.loading&&!o.error&&r("span",{class:"changes-summary",children:d.length?r(K,{children:[m?`${m}/${d.length} viewed · `:`${d.length} file${d.length===1?"":"s"} · `,r("span",{class:"dstat-add",children:["+",b.a]})," ",r("span",{class:"dstat-del",children:["−",b.d]})]}):"no changes"})]}),r("div",{class:"changes-body",children:[o.loading?r("div",{class:"changes-msg",children:"loading…"}):null,o.error?r("div",{class:"changes-msg changes-err",children:o.error}):null,!o.loading&&!o.error&&!d.length?r("div",{class:"changes-msg",children:i==="session"?"Nothing changed on disk since this session started.":"This branch matches its fork point."}):null,d.map(y=>r(Uk,{file:y,repo:f,review:h,hl:c},y.path)),(C=o.data)!=null&&C.truncated?r("div",{class:"changes-msg",children:[o.data.truncated," more file",o.data.truncated===1?"":"s"," not shown"]}):null]})]})}const Vk=new Set(["Read","Edit","Write","MultiEdit","NotebookEdit"]),Gk=new Set(["html","md"]);function Jk(e,t){const n=(t||"").trim();if(!n)return!0;const i=(e||"").toLowerCase();if(!/[*?]/.test(n))return i.includes(n.toLowerCase());const l=n.split("**").map(a=>a.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,"[^/]*").replace(/\?/g,"[^/]")).join(".*");return new RegExp(`(?:^|/)${l}$`,"i").test(i)}function Qk(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0?t.slice(n+1).toLowerCase():""}function Yk(e,t=Gk){const n=[],i=[];for(const l of e)(t.has(Qk(l.path))?n:i).push(l);return{priority:n,others:i}}function Zk(e){if(!Array.isArray(e)||e.length===0)return[];const t=new Map;for(let n=e.length-1;n>=0;n--){const i=e[n],l=i==null?void 0:i.tool_uses;if(l!=null&&l.length)for(let a=l.length-1;a>=0;a--){const s=l[a];if(!s||!Vk.has(s.name))continue;const o=s.input&&(s.input.file_path||s.input.notebook_path);o&&(t.has(o)||t.set(o,s.name))}}return[...t.entries()].map(([n,i])=>({path:n,op:i}))}function Xk(e){return e==="need_human"?"var(--s-danger)":e==="done"?"var(--s-success)":"var(--fg-3)"}function ew(e,t){return e==="commit"?"var(--s-shell)":e==="ci"?t==="failed"?"var(--s-danger)":t==="running"?"var(--s-working)":"var(--s-success)":e==="open"?"var(--fg-3)":e==="reset"?"var(--s-working)":e==="rename"?"var(--accent)":"var(--fg-3)"}function tw(e,t){return e==="commit"?"commit":e==="ci"?t?`ci ${t}`:"ci":e==="open"?"opened":e==="reset"?t==="compacted"?"compacted":"cleared":e==="rename"?"renamed":e}function nw(e){return e?(e.replace(/[^A-Za-z0-9]/g,"").slice(0,2)||e.slice(0,1)).toUpperCase():"?"}const rw={pr:"Please link the PR you're working on for this pane using the `link_pr` MCP tool. If there isn't one, ignore this.",linear:"Please link the relevant Linear ticket for this pane using the `link_linear` MCP tool. If there isn't one, ignore this."};function iw({data:e,onLinkAsk:t}){if(!e.pr){if(e.agent!=="claude")return null;const o=!!e.channel_attached;return r("button",{class:"modal-side-link-btn",type:"button",disabled:!o,title:o?"Ask Claude to link the PR for this pane (via link_pr MCP tool)":"Channel not attached. Respawn Claude via + claude.",onClick:()=>t("pr"),children:"+ link pull request"})}const n=e.ci==="✓"?"passing":e.ci==="✗"?"failing":e.ci==="⟳"?"running":"—",i=e.ci==="✓"?"ci-passing":e.ci==="✗"?"ci-failing":e.ci==="⟳"?"ci-running":"",l=lr(e.repo_slug,e.pr),a=e.pr_additions||0,s=e.pr_deletions||0;return r("div",{class:"modal-card-inset",children:[r("div",{class:"pr-head",children:[l?r("a",{class:"pr-num",href:l,target:"_blank",rel:"noopener",onClick:o=>o.stopPropagation(),children:["#",e.pr]}):r("span",{class:"pr-num",children:["#",e.pr]}),r("span",{class:"pr-title",title:e.pr_title||"",children:e.pr_title||""})]}),r("div",{class:"pr-meta",children:[e.pr_draft?r("span",{class:"pr-mini pr-mini-draft",children:"draft"}):r("span",{class:"pr-mini pr-mini-open",children:"open"}),r("span",{class:"pr-diff",children:[r("span",{class:"diff-plus",children:["+",a]})," ",r("span",{class:"diff-minus",children:["−",s]})]}),r("span",{class:`pr-ci ${i}`,children:[r("span",{class:"ci-dot"}),"ci ",n]}),(e.pr_reviewers||[]).length>0&&r("span",{class:"pr-reviewers",children:(e.pr_reviewers||[]).map(o=>r("span",{class:"modal-avatar",title:o,children:nw(o)}))})]})]})}function lw({data:e,onLinkAsk:t}){if(e.linked_linear){const s=e.linked_linear,o=`https://linear.app/issue/${s}`,u=e.linked_linear_title||"linear ticket";return r("div",{class:"modal-card-inset",children:[r("div",{class:"pr-head",children:[r("a",{class:"pr-num",href:o,target:"_blank",rel:"noopener",onClick:c=>c.stopPropagation(),title:`Linear ticket ${s} (linked by claude)`,children:s}),r("span",{class:"pr-title",title:u,children:u})]}),e.linked_linear_status&&r("div",{class:"pr-meta",children:r("span",{class:"pr-mini",children:e.linked_linear_status})})]})}const n=vr(e),i=n&&r("div",{class:"modal-card-inset",children:r("div",{class:"pr-head",children:[r("a",{class:"pr-num",href:n.href,target:"_blank",rel:"noopener",onClick:s=>s.stopPropagation(),title:n.tip,children:n.id}),r("span",{class:"pr-title",children:n.note})]})});if(e.agent!=="claude")return i||null;const l=!!e.channel_attached;return r(K,{children:[i,r("button",{class:"modal-side-link-btn",type:"button",disabled:!l,title:l?"Ask Claude to link a Linear ticket for this pane (via link_linear MCP tool)":"Channel not attached. Respawn Claude via + claude.",onClick:()=>t("linear"),children:"+ link Linear ticket"})]})}function aw({e}){return e.src==="alert"?r("li",{class:"timeline-row timeline-row-alert","data-kind":e.kind,children:[r("span",{class:"timeline-dot",style:`background:${Xk(e.kind)}`}),r("div",{class:"timeline-body",children:[r("div",{class:"timeline-text",children:e.text}),r("div",{class:"timeline-when",children:["claude · ",e.kind," · ",Pe(e.at)," ago"]})]})]}):e.src==="channel"?r("li",{class:"timeline-row timeline-row-channel","data-kind":e.kind,children:[r("span",{class:"timeline-dot",style:"background:var(--accent)"}),r("div",{class:"timeline-body",children:[r("div",{class:"timeline-text",children:e.text}),r("div",{class:"timeline-when",children:["periscope · ",e.kind," · ",Pe(e.at)," ago"]})]})]}):r("li",{class:"timeline-row","data-kind":e.kind,children:[r("span",{class:"timeline-dot",style:`background:${ew(e.kind,e.state)}`}),r("div",{class:"timeline-body",children:[e.url?r("a",{class:"timeline-text timeline-link",href:e.url,target:"_blank",rel:"noopener",children:e.text}):r("div",{class:"timeline-text",children:e.text}),r("div",{class:"timeline-when",children:[tw(e.kind,e.state)," · ",Pe(e.at)," ago"]})]})]})}function sw({data:e,streamRef:t}){const n=e.activity||[],i=n.filter(s=>s.src==="alert").reduce((s,o)=>s&&s.at>=o.at?s:o,null),l=i&&i.kind==="need_human"?i:null,a=n.filter(s=>s!==l);return r(K,{children:[l&&r("div",{class:"activity-pinned",children:[r("div",{class:"activity-pinned-label",children:["needs you · ",Pe(l.at)," ago"]}),r("div",{class:"activity-pinned-text",children:l.text})]}),a.length?r("ol",{class:"timeline activity-stream",ref:t,children:a.map((s,o)=>r(aw,{e:s},o))}):l?null:r("div",{class:"timeline-empty",children:"no recent activity"})]})}function ow({pid:e,onRefresh:t,idPrefix:n}){const i=te(null),l=te(null),a=te(null),s=e?Pr(e):null,o=(s==null?void 0:s.tags)||[];function u(){if(!e)return;const d=Pr(e)||{tags:[]};Kr(e,{notes:i.current.value,tags:d.tags})}function c(){const d=(l.current.value||"").trim();if(!d||!e)return;const f=Pr(e)||{notes:i.current.value,tags:[]},h=d.split(/[\s,]+/).filter(Boolean);Kr(e,{notes:i.current.value,tags:[...f.tags,...h]}),l.current.value="",t==null||t()}function p(d){const f=Pr(e)||{notes:i.current.value,tags:[]};Kr(e,{notes:i.current.value,tags:f.tags.filter((h,m)=>m!==d)}),t==null||t()}return r(K,{children:[r("textarea",{ref:i,id:`${n}-notes`,class:"modal-notes",placeholder:e?"Notes — saves on blur":"Notes unavailable (no pid)",disabled:!e,defaultValue:(s==null?void 0:s.notes)||"",onInput:()=>{clearTimeout(a.current),a.current=setTimeout(u,600)},onBlur:()=>{clearTimeout(a.current),u()},onKeyDown:d=>d.stopPropagation()}),r("div",{class:"tag-row",children:[r("div",{class:"tag-chips",id:`${n}-tags`,children:o.map((d,f)=>r("span",{class:"tag-chip","data-tag-i":f,children:[d,r("button",{class:"tag-chip-x",title:"remove",onClick:()=>p(f),children:"×"})]}))}),r("input",{ref:l,id:`${n}-tag-input`,class:"modal-tag-input",type:"text",placeholder:"add tag, Enter or comma",disabled:!e,onKeyDown:d=>{d.stopPropagation(),(d.key==="Enter"||d.key===",")&&(d.preventDefault(),c())}})]})]})}function xl({it:e,label:t,priority:n,pinned:i,onTogglePin:l}){return r("li",{class:`files-row${n?" files-row-priority":""}${i?" files-row-pinned":""}`,onClick:()=>kr({path:e.path,line:null}),title:`Open ${e.path} as a preview tab`,children:[r("span",{class:"files-op",children:uw(e.op)}),r("span",{class:"files-path",children:t}),r("button",{type:"button",class:`files-pin${i?" files-pin-on":""}`,title:i?"Unpin file":"Pin file","aria-label":i?"Unpin file":"Pin file","aria-pressed":i?"true":"false",onClick:a=>{a.stopPropagation(),l()},children:i?"★":"☆"})]})}function cw({pid:e}){me.value;const[t,n]=B("");if(!e)return null;const l=zr.value[e]?Ft.value[e]:null,a=l!=null&&l.messages?Zk(l.messages):[],s=pu(e);if(!a.length&&!s.length)return null;const o=new Map(a.map(g=>[g.path,g])),u=s.map(g=>o.get(g)||{path:g,op:null}),c=new Set(s),p=a.filter(g=>!c.has(g.path)),d=[...s,...p.map(g=>g.path)],f=g=>hu(g,d),h=t.trim(),m=g=>Jk(g.path,h),b=u.filter(m),{priority:x,others:w}=Yk(p.filter(m)),C=g=>()=>Ng(e,g),y=[{items:b,render:g=>r(xl,{it:g,label:f(g.path),pinned:!0,onTogglePin:C(g.path)},`pin:${g.path}`)},{items:x,render:g=>r(xl,{it:g,label:f(g.path),priority:!0,pinned:!1,onTogglePin:C(g.path)},`pri:${g.path}`)},{items:w,render:g=>r(xl,{it:g,label:f(g.path),pinned:!1,onTogglePin:C(g.path)},`oth:${g.path}`)}].filter(g=>g.items.length>0);return r("section",{class:"modal-side-section modal-side-files",children:[r("h4",{children:"Files"}),r("input",{class:"files-filter",type:"text",placeholder:"filter files — text or glob",value:t,onInput:g=>n(g.currentTarget.value),onKeyDown:g=>{g.stopPropagation(),g.key==="Escape"&&(g.preventDefault(),n(""))}}),r("ul",{class:"files-list",children:[y.map((g,$)=>r(K,{children:[$>0&&r("li",{class:"files-divider","aria-hidden":"true"}),g.items.map(g.render)]})),h&&!y.length&&r("li",{class:"files-nomatch",children:"no files match"})]})]})}function uw(e){switch(e){case"Read":return"👁";case"Write":return"+";case"Edit":case"MultiEdit":case"NotebookEdit":return"✎";default:return"·"}}function dw({data:e,onRefresh:t,containerId:n,containerClass:i,idPrefix:l}){const a=te(null),s=te(0),o=(e==null?void 0:e.pid)||"";j(()=>{a.current&&s.current&&(a.current.scrollTop=s.current)});function u(c){const p=rw[c];!p||!(e!=null&&e.pane_id)||fetch(`/api/channel/push?pane_id=${encodeURIComponent(e.pane_id)}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({content:p})}).catch(()=>{})}return a.current&&(s.current=a.current.scrollTop),r("aside",{id:n,class:i,children:[r("section",{class:"modal-side-section",children:[r("h4",{children:"Linked"}),r(iw,{data:e,onLinkAsk:u}),r(lw,{data:e,onLinkAsk:u})]}),r("section",{class:"modal-side-section modal-side-notes",children:[r("h4",{children:"Notes"}),r(ow,{pid:o,idPrefix:l,onRefresh:t},o)]}),r(cw,{pid:o}),r("section",{class:"modal-side-section modal-side-activity",children:[r("h4",{children:"Activity"}),r(sw,{data:e,streamRef:a})]})]})}let mn=null,Rr=null;function hw(){return mn?Promise.resolve(mn):(Rr||(Rr=Zi(()=>import("./chunks/preview.js").then(e=>e.P),[]).then(e=>(mn=e,e)).catch(e=>{throw Rr=null,e})),Rr)}function fw({entry:e,active:t=!0}){const[n,i]=B(()=>(mn==null?void 0:mn.PreviewTabInner)||null),[l,a]=B(null);return j(()=>{if(n)return;let s=!0;return a(null),hw().then(o=>{s&&i(()=>o.PreviewTabInner)}).catch(o=>{s&&a((o==null?void 0:o.message)||String(o))}),()=>{s=!1}},[n]),l?r("div",{class:"preview-tab-content",role:"region","aria-label":"File preview",children:[r("header",{class:"preview-header",children:r("span",{class:"preview-path",children:e.path})}),r("div",{class:"preview-body",children:r("div",{class:"preview-error",children:[r("div",{children:"Failed to load preview module:"}),r("div",{class:"preview-error-code",children:l})]})})]}):n?r(n,{entry:e,active:t}):r("div",{class:"preview-tab-content",role:"region","aria-label":"File preview",children:[r("header",{class:"preview-header",children:r("span",{class:"preview-path",children:[e.path,e.line?`:${e.line}`:""]})}),r("div",{class:"preview-body",children:r("div",{class:"preview-loading",children:"loading…"})})]})}async function Sl(e,t,n,i){i(!0);try{const l=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repo:t.repo,branch:t.branch})}),a=await l.json().catch(()=>({}));n(l.ok?a.mode==="spawned"?a.checked_out?"checked out the PR and spawned a pane to prepare":"spawned a pane to prepare":"sent":a.detail||`HTTP ${l.status}`),el()}catch(l){n(String(l))}finally{i(!1)}}function pw({row:e}){const t=vr(e),n=t&&r("a",{class:"rq-linear",href:t.href,target:"_blank",rel:"noopener",title:t.tip,children:t.id});if(!e.pr)return n||"—";const i=Ui(e.pr.state),l=`rq-pr-link ${i.cls}`;return r(K,{children:[e.pr.url?r("a",{class:l,href:e.pr.url,target:"_blank",rel:"noopener",children:["#",e.pr.number]}):r("span",{class:l,children:["#",e.pr.number]}),n?r(K,{children:[" · ",n]}):null,e.pr.draft?" draft":""," ",e.pr.state||""," ",e.pr.ci&&!i.cls?e.pr.ci:"",r("div",{class:"rq-repo",children:e.pr.title})]})}const Vo="filter branches, PRs, people, tickets";function mw({col:e}){const{label:t,what:n}=Hi[e],i=Dl.value,l=(i==null?void 0:i.key)===e,a=ug(i,e);return r("th",{"aria-sort":l?i.dir==="asc"?"ascending":"descending":void 0,children:r("button",{type:"button",class:`rq-sort${l?" is-active":""}`,title:a?l?"reverse the order":`sort by ${n}`:"back to the default order",onClick:()=>{Dl.value=a},children:[t,l?r("span",{class:"rq-sort-dir","aria-hidden":"true",children:i.dir==="asc"?"▲":"▼"}):null]})})}function gw({row:e}){var p,d,f;const[t,n]=B(""),[i,l]=B(!1),a=((p=e.pr)==null?void 0:p.state)==="merged",s=!!e.owner||!!e.worktree||((d=e.pr)==null?void 0:d.state)==="open",o=e.walkthrough,u=e.owner?"ask the owning pane to write the walkthrough":e.worktree?"spawn a pane in the worktree to write the walkthrough":s?`check out PR #${e.pr.number} and spawn a pane to write the walkthrough`:"open the branch first (⌘K)",c=e.unresolved>0?`${e.unresolved} unresolved comment${e.unresolved===1?"":"s"}`:e.owner?"ask the owning pane to merge":"no pane on this branch";return r("tr",{class:`rq-row rq-${e.role}${a?" is-merged":""}`,children:[r("td",{class:"rq-branch",children:[o?r("button",{type:"button",class:"rq-open",onClick:()=>Eu(e.repo,e.branch),children:e.branch}):e.branch,r("div",{class:"rq-repo",children:[e.repo," · ",e.role==="review-requested"?"review requested":e.role]})]}),r("td",{class:"rq-pr",children:r(pw,{row:e})}),r("td",{class:"rq-wt",children:o?`${o.stops} stop${o.stops===1?"":"s"} · ${sg(e)}`:"none"}),r("td",{class:"rq-comments",children:e.unresolved?r("b",{children:[e.unresolved," open"]}):"—"}),r("td",{class:"rq-owner",children:[e.owner?e.owner.name:(f=e.pr)!=null&&f.author?`opened by ${e.pr.author}`:"—",e.owner?null:r("div",{class:"rq-repo",children:e.worktree?"no pane":"not checked out"})]}),r("td",{class:"rq-actions",children:[r("button",{type:"button",disabled:i||!s,title:u,onClick:()=>Sl("/api/reviews/prepare",e,n,l),children:o?"re-prepare":"prepare"}),r("button",{type:"button",disabled:i||!e.owner||a||e.unresolved>0,title:c,onClick:async()=>{await Yn(`Ask the owning pane to merge ${e.branch}?`,{okLabel:"Merge"})&&Sl("/api/reviews/merge",e,n,l)},children:"merge"}),(a||!e.worktree)&&(o||e.unresolved)?r("button",{type:"button",disabled:i,title:"remove this review's files",onClick:async()=>{await Yn(`Remove the walkthrough and comments for ${e.branch}? This can't be undone.`,{okLabel:"Clear",danger:!0})&&Sl("/api/reviews/clear",e,n,l)},children:"clear"}):null,t?r("span",{class:"rq-note",children:t}):null]})]})}function yw(){j(()=>{el()},[]);const e=gt.value;if(e===null)return r("div",{class:"wt-empty",children:"loading…"});const t=cg(e,Dl.value),n=ps.value,i=dg(t,n),l=`branch${t.length===1?"":"es"}`;return r("div",{class:"reviews-queue",children:[r("header",{class:"wt-head",children:[r("h2",{children:"Reviews"}),r("input",{type:"search",class:"rq-search",placeholder:Vo,"aria-label":Vo,spellcheck:!1,autocomplete:"off",value:n,onInput:a=>{ps.value=a.currentTarget.value}}),r("span",{class:"wt-sub","aria-live":"polite",children:n.trim()?`${i.length} of ${t.length} ${l}`:`${t.length} ${l}`})]}),t.length===0?r("div",{class:"wt-empty",children:"nothing open"}):i.length===0?r("div",{class:"wt-empty",children:['no branches match "',n.trim(),'"']}):r("table",{class:"rq-table",children:[r("thead",{children:r("tr",{children:[Object.keys(Hi).map(a=>r(mw,{col:a},a)),r("th",{})]})}),r("tbody",{children:i.map(a=>r(gw,{row:a},`${a.repo}/${a.branch}`))})]})]})}async function bw(e,t){const n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),i=await n.json().catch(()=>({}));return{ok:n.ok,status:n.status,data:i}}function Vd({list:e}){return e.length?r("ul",{class:"wt-comments",children:e.map((t,n)=>r("li",{class:t.resolved?"is-resolved":"",children:[r("span",{class:"wt-comment-ts",children:t.ts}),r("span",{class:"wt-comment-state",children:t.resolved?"resolved":"open"}),r("div",{class:"wt-comment-body",children:mr(t.body,{demote:!1,softBreaks:"space"})})]},n))}):null}function kw({repo:e,branch:t,stop:n,onPosted:i}){const[l,a]=B(""),[s,o]=B(""),[u,c]=B(!1);async function p(){if(!(u||!l.trim())){c(!0);try{const d=await bw("/api/reviews/comment",{repo:e,branch:t,stop:n,body:l});d.ok?(a(""),o("sent to the owning pane")):d.status===409?(a(""),o(`saved, ${d.data.detail||"not delivered"}`)):o(d.data.detail||`HTTP ${d.status}`),i()}catch(d){o(String(d))}finally{c(!1)}}}return r("div",{class:"wt-comment-box",children:[r("textarea",{rows:2,value:l,placeholder:"comment on this stop…",onInput:d=>a(d.currentTarget.value),onKeyDown:d=>{d.key==="Enter"&&(d.metaKey||d.ctrlKey)&&p()}}),r("div",{class:"wt-comment-actions",children:[r("button",{type:"button",disabled:u||!l.trim(),onClick:p,children:"comment"}),s?r("span",{class:"wt-comment-note",children:s}):null]})]})}function ww({stop:e,diffFiles:t,comments:n,repo:i,branch:l,hl:a,onPosted:s}){const[o,u]=B(!1),c=ag(e.refs,t||[]),p=c.reduce((f,h)=>f+h.hunks.length,0),d=f=>{const h=c.find(m=>m.ref.raw===f.raw&&m.hunks.length);return r("button",{type:"button",class:`md-cite${h?"":" is-inert"}`,title:h?"show hunks":"no hunk in this branch's diff",onClick:()=>h&&u(!0),children:f.raw})};return r("section",{class:"wt-stop",id:`stop-${e.id}`,children:[r("h3",{class:"wt-stop-title",children:[e.kind?r("span",{class:`wt-kind wt-kind-${e.knownKind?e.kind:"other"}`,children:e.kind}):null,e.title]}),e.refs.length?r("div",{class:"md-meta",children:r("span",{class:"md-meta-kv","data-key":"refs",children:[r("span",{class:"md-meta-k",children:"refs"}),r("span",{class:"md-meta-v",children:e.refs.map((f,h)=>r("span",{children:[h?", ":"",d(f)]},h))})]})}):null,r("div",{class:"md-doc wt-stop-body",children:mr(e.bodyMarkdown,{demote:!1,softBreaks:"space",mermaid:!0,meta:!0,cite:d})}),t&&e.refs.length?r("div",{class:"wt-evidence",children:[r("button",{type:"button",class:"wt-evidence-toggle",onClick:()=>u(!o),children:[o?"▾":"▸"," ",p," hunk",p===1?"":"s"]}),o&&c.map((f,h)=>r("div",{class:"wt-evidence-file",children:[r("div",{class:"wt-evidence-path",children:[f.ref.raw,f.file?f.generated?" — generated, not shown":"":" — not in this diff"]}),f.hunks.map((m,b)=>r(Kd,{hunk:m,lang:Wd(f.ref.path),hl:a,onOpen:null},b))]},h))]}):null,r(Vd,{list:n}),r(kw,{repo:i,branch:l,stop:e.title,onPosted:s})]})}function vw({repo:e,branch:t,pr:n,sig:i}){var y;const[l,a]=B({loading:!0,error:null,data:null}),[s,o]=B(null),[u,c]=B(0);j(()=>{let g=!0;return Zi(()=>import("./chunks/preview.js").then($=>$.h),[]).then($=>{g&&o(()=>$.highlightCode)}).catch(()=>{}),()=>{g=!1}},[]),j(()=>{let g=!0;return(async()=>{try{const $=await fetch(`/api/reviews/walkthrough?repo=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}`),v=await $.json().catch(()=>({}));if(!g)return;if(!$.ok){a(E=>({loading:!1,error:v.detail||`HTTP ${$.status}`,data:E.data}));return}a({loading:!1,error:null,data:v})}catch($){g&&a(v=>({loading:!1,error:String($),data:v.data}))}})(),()=>{g=!1}},[e,t,u,i]);const p=()=>{c(g=>g+1),el()};if(l.loading)return r("div",{class:"wt-empty",children:"loading…"});if(!l.data)return r("div",{class:"wt-empty",children:l.error});const{text:d,comments:f,diff:h,stale_by:m}=l.data,b=ig(d),x=new Map;for(const g of f)(x.get(g.stop)||x.set(g.stop,[]).get(g.stop)).push(g);const w=new Set(b.stops.map(g=>g.title)),C=f.filter(g=>!w.has(g.stop));return r("div",{class:"walkthrough",children:[l.error?r("div",{class:"wt-empty wt-error",children:["refresh failed: ",l.error]}):null,r("header",{class:"wt-head",children:[r("h2",{children:b.title||t}),r("span",{class:"wt-sub",children:[e," · ",t,(y=b.header)!=null&&y.pr?r(K,{children:[" · ",n!=null&&n.url&&n.number===b.header.pr?r("a",{class:`rq-pr-link ${Ui(n.state).cls}`,href:n.url,target:"_blank",rel:"noopener",children:["PR #",b.header.pr]}):`PR #${b.header.pr}`]}):"",m==null&&b.header?h?"":" · no worktree — hunks unavailable":m>0?` · stale: ${m} commit${m===1?"":"s"} since`:""]})]}),b.problem?r("p",{class:"wt-problem",children:b.problem}):null,b.stops.map(g=>r(ww,{stop:g,diffFiles:(h==null?void 0:h.files)||null,comments:x.get(g.title)||[],repo:e,branch:t,hl:s,onPosted:p},g.id)),C.length?r("section",{class:"wt-stop",children:[r("h3",{class:"wt-stop-title",children:"unattached comments"}),r(Vd,{list:C})]}):null]})}function _w({target:e,agent:t,onPaste:n,class:i="modal-xterm",id:l}){const a=te(null);return j(()=>(Y1(a.current,e,{agent:t,onPaste:n}),Hu),[]),r("div",{ref:a,id:l,class:i})}function xw(){const e=te(null),[t,n]=B(!1),[i,l]=B("");j(()=>{function o(u){(u.metaKey||u.ctrlKey)&&u.key==="f"&&(u.preventDefault(),n(!0),requestAnimationFrame(()=>{var c;return(c=e.current)==null?void 0:c.focus()}))}return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[]);const a=br(()=>{n(!1),l(""),Q1()},[]);ot(a,t);function s(o){o.preventDefault(),i&&(o.shiftKey?Js(i):Gs(i))}return t?r("form",{class:"term-search",onSubmit:s,children:[r("input",{ref:e,class:"term-search-input",value:i,placeholder:"find in terminal",onInput:o=>{l(o.currentTarget.value)}}),r("button",{type:"button",class:"term-search-btn",title:"Previous (Shift+Enter)",onClick:()=>i&&Js(i),children:"‹"}),r("button",{type:"button",class:"term-search-btn",title:"Next (Enter)",onClick:()=>i&&Gs(i),children:"›"}),r("button",{type:"button",class:"term-search-btn",title:"Close (Esc)",onClick:a,children:"✕"})]}):null}const Gd={rail:{pref:"rail_width",cssVar:"--rail-w",columnId:"rail",def:320,min:180,dir:1},side:{pref:"side_width",cssVar:"--side-w",columnId:"detail-side",def:280,min:200,dir:-1}},Sw=.5;function $w(e,t,n){return Math.round(Math.min(Math.max(e,t),Math.max(t,n)))}function Cw(e,t,n,i){return $w(e+n.dir*t,n.min,i*Sw)}function Tw(e){return Number.isFinite(e)&&e>0?e:null}function Jd({which:e}){const t=Gd[e];function n(i){if(i.button!==0)return;const l=i.currentTarget,a=document.getElementById("split-view"),s=document.getElementById(t.columnId),o=l.parentElement;if(!a||!s||!o)return;i.preventDefault();const u=i.clientX,c=Math.round(s.getBoundingClientRect().width),p=o.getBoundingClientRect().width;let d=c;l.setPointerCapture(i.pointerId),l.classList.add("dragging"),document.body.classList.add("col-resizing"),G1();const f=m=>{d=Cw(c,m.clientX-u,t,p),a.style.setProperty(t.cssVar,`${d}px`)},h=()=>{l.removeEventListener("pointermove",f),l.removeEventListener("pointerup",h),l.removeEventListener("pointercancel",h),l.classList.remove("dragging"),document.body.classList.remove("col-resizing"),J1(),d!==c&&Ns(t.pref,d)};l.addEventListener("pointermove",f),l.addEventListener("pointerup",h),l.addEventListener("pointercancel",h)}return r("div",{class:`col-resize col-resize-${e}`,title:"Drag to resize · double-click to reset",onPointerDown:n,onDblClick:()=>Ns(t.pref,t.def)})}function Ew(e){return(e==null?void 0:e.agent)!=="claude"?"not a Claude pane":e.state!=="idle"&&e.state!=="done"?`pane is ${e.state||"busy"}, try again when it's idle`:e.pending_input?"the pane has unsent text in its input box":null}function Pw(e){return(e==null?void 0:e.session_effort)||(e==null?void 0:e.launch_effort)||"default"}function Aw(e){var t;return e!=null&&e.model?e.model.replace(/\s*\(.*\)/,""):e!=null&&e.session_model?((t=cr.find(n=>n.id===e.session_model))==null?void 0:t.label)||e.session_model:"model"}function Mw({w:e}){var c;const[t,n]=B({}),[i,l]=B(!1);j(()=>{n({})},[e.pid,e.session_model,e.session_effort]);const a=i?"waiting for the pane to confirm the last change":Ew(e);async function s(p,d){const f=d.currentTarget.value;if(d.currentTarget.value="",!f||i)return;const h=`pid=${encodeURIComponent(e.pid)}&setting=${p}&value=${encodeURIComponent(f)}`;l(!0);let m;try{m=await ie(`set ${p}`,`/api/pane/session-setting?${h}`,{method:"POST"})}finally{l(!1)}m&&(m.result==="applied"?n(b=>({...b,[p]:f})):m.result==="confirm"?kn("Claude is asking to confirm the model switch in the pane — answer it there","info",7e3):kn(`Sent ${m.sent}, but Claude didn't confirm it took`,"info",5e3))}const o=t.model?((c=cr.find(p=>p.id===t.model))==null?void 0:c.label)||t.model:Aw(e),u=t.effort||Pw(e);return r("span",{class:"header-session-picks",children:[r("select",{class:"header-session-pick",value:"",disabled:!!a,title:a||"change this session's model (types /model into the pane)",onChange:p=>s("model",p),children:[r("option",{value:"",hidden:!0,children:o}),cr.map(p=>r("option",{value:p.id,children:p.label},p.id))]}),r("select",{class:"header-session-pick",value:"",disabled:!!a,title:a||"change this session's effort (types /effort into the pane)",onChange:p=>s("effort",p),children:[r("option",{value:"",hidden:!0,children:`effort ${u}`}),Fa.map(p=>r("option",{value:p,children:p},p))]})]})}const Lw=2e3;function Iw(e,t,n){j(()=>{if(!n||!e)return;let i=!0,l=null;async function a(){try{const o=await(await fetch(`/api/pane/turns?${tt(e)}`)).json();if(!i)return;const u=o&&o.turns===null?[]:o.messages||[],c=(o==null?void 0:o.session_id)||null;Ft.value={...Ft.value,[t]:{messages:u,sessionId:c}},u.length&&!zr.value[t]&&(zr.value={...zr.value,[t]:!0})}catch{}i&&(l=setTimeout(a,Lw))}return a(),()=>{i=!1,l&&clearTimeout(l)}},[e,t,n])}function Ow(e){const t=e.input||{};switch(e.name){case"Bash":return t.command||"";case"Read":case"Edit":case"Write":case"MultiEdit":case"NotebookEdit":return t.file_path||t.notebook_path||"";case"Grep":return t.pattern||"";case"Glob":return t.pattern||"";case"Task":case"Agent":return t.description||"";case"TaskCreate":return t.subject||"";case"TaskUpdate":return t.taskId?`#${t.taskId}`:"";case"WebFetch":return t.url||"";case"WebSearch":return t.query||"";case"Skill":return t.skill||t.command||"";case"AskUserQuestion":{const n=t.questions||[];return n.length===1?n[0].question||n[0].header||"":n.length?`${n.length} questions`:""}default:{const n=JSON.stringify(t);return n==="{}"||n==="null"?"":n.length>120?`${n.slice(0,120)}…`:n}}}function Dw({input:e}){const t=String(e.old_string||"").split(` `),n=String(e.new_string||"").split(` -`);return r("div",{class:"tc-diff",children:[t.map((i,l)=>r("div",{class:"tc-diff-del",children:i||" "},`d${l}`)),n.map((i,l)=>r("div",{class:"tc-diff-add",children:i||" "},`a${l}`))]})}function $w(e){const t=e.input||{};switch(e.name){case"Bash":return t.command||"";case"Write":return t.content||"";default:return""}}function Cw({input:e}){const t=e.questions||[];return r("div",{class:"tc-ask",children:t.map((n,i)=>r("div",{class:"tc-ask-q",children:[r("div",{class:"tc-ask-qhead",children:[n.header&&r("span",{class:"tc-ask-chip",children:n.header}),n.multiSelect&&r("span",{class:"tc-ask-multi",children:"multi-select"})]}),r("div",{class:"tc-ask-question",children:n.question}),r("div",{class:"tc-ask-options",children:(n.options||[]).map((l,a)=>r("div",{class:"tc-ask-opt",children:[r("span",{class:"tc-ask-opt-label",children:l.label}),l.description&&r("span",{class:"tc-ask-opt-desc",children:l.description})]},a))})]},i))})}function Tw({t:e}){var p;const[t,n]=B(!1),i=e.result==null,l=e.name==="Edit",a=e.name==="AskUserQuestion",s=e.name==="Agent"||e.name==="Task",o=$w(e),u=!i&&e.result!=null&&e.result!=="",c=l||a||!!o||u,f=xw(e),d=s&&((p=e.input)==null?void 0:p.subagent_type)||"";return r("div",{class:`tc${s?" tc-agent":""}`,children:[r("button",{class:`tc-head${c?" expandable":""}`,onClick:c?()=>n(!t):void 0,children:[r("span",{class:"tc-dot",children:s?"⚇":"⏺"}),r("span",{class:"tc-name",children:e.name}),d&&r("span",{class:"tc-agent-type",children:d}),f&&(e.name==="Read"||e.name==="Edit"||e.name==="Write"||e.name==="MultiEdit"||e.name==="NotebookEdit"?r("span",{class:"tc-arg tc-arg-clickable",title:"Cmd+click to preview",onClick:m=>{!m.metaKey&&!m.ctrlKey||(m.stopPropagation(),gr({path:f,line:null}))},children:f}):r("span",{class:"tc-arg",children:f})),i&&r("span",{class:"tc-running",children:"running…"}),c&&r("span",{class:"tc-caret",children:t?"▾":"▸"})]}),t&&r("div",{class:"tc-detail",children:[l?r(Sw,{input:e.input||{}}):a?r(Cw,{input:e.input||{}}):o&&r("pre",{class:"tc-cmd",children:o}),u&&r("pre",{class:"tc-out",children:e.result})]})]})}function Ew({m:e,current:t}){if(e.role==="user")return r("div",{class:`turn turn-user${t?" turn-current":""}`,children:[r("span",{class:"turn-user-mark",children:"›"}),r("div",{class:"turn-user-body",children:fr(e.text)})]});const n=e.tool_uses||[];return r("div",{class:`turn turn-assistant${t?" turn-current":""}`,children:[e.text&&r("div",{class:"turn-prose",children:fr(e.text)}),n.length>0&&r("div",{class:"turn-tools",children:n.map((i,l)=>r(Tw,{t:i},i.id||l))})]})}function Pw({target:e,composerRef:t}){const[n,i]=B(""),[l,a]=B(!1),s=ne(null);async function o(){const d=n;if(!d.trim()||l)return;a(!0),await ie("send",`/api/send?${nt(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paste:d})})&&(await new Promise(h=>setTimeout(h,250)),await ie("send",`/api/send?${nt(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({keys:["Enter"]})}),i(""),s.current&&(s.current.style.height="")),a(!1)}function u(d){d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),o())}function c(d){const p=d.currentTarget;i(p.value),p.style.height="0px",p.style.height=`${Math.min(p.scrollHeight,140)}px`}async function f(d){var h;const p=((h=d.clipboardData)==null?void 0:h.items)||[];for(const m of p){if(m.kind!=="file"||!m.type.startsWith("image/"))continue;const b=m.getAsFile();if(!b)continue;d.preventDefault();const w=await(await fetch(`/api/paste-image?${nt(e)}&deliver=false`,{method:"POST",headers:{"Content-Type":b.type||"image/png"},body:b})).json().catch(()=>({}));w.ok&&i(C=>`${C}${C&&!C.endsWith(" ")?" ":""}@${w.path} `);return}}return r("div",{class:"transcript-composer",ref:t,children:r("textarea",{ref:s,class:"transcript-composer-input",placeholder:"Message Claude… (Enter to send · Shift+Enter for newline · paste screenshots)",value:n,rows:1,onInput:c,onKeyDown:u,onPaste:f})})}function Aw({target:e,pid:t,selected:n,state:i,waitingFor:l,spinner:a}){var m;_w(e,t,n);const s=((m=Ft.value[t])==null?void 0:m.messages)||[],o=ne(null),u=ne(null),c=ne(!0),f=ne(""),d=()=>{const b=o.current;b&&c.current&&(b.scrollTop=b.scrollHeight)};j(()=>{const b=s[s.length-1],x=`${s.length}:${b?b.uuid:""}:${b?(b.tool_uses||[]).length:0}`;x!==f.current&&(f.current=x,d())},[s]),j(()=>{const b=u.current,x=o.current;if(!b||!x)return;const w=()=>{x.style.paddingBottom=`${b.offsetHeight+14}px`,requestAnimationFrame(d)};w();const C=new ResizeObserver(w);return C.observe(b),()=>C.disconnect()},[]),j(()=>{(i==="needs-input"||i==="working")&&d()},[i]);function p(b){const x=b.currentTarget;c.current=x.scrollHeight-x.scrollTop-x.clientHeight<80}let h="";for(let b=s.length-1;b>=0;b--)if(s[b].role!=="system"){h=s[b].uuid;break}return r(V,{children:[r("div",{class:"transcript",ref:o,onScroll:p,children:[s.length===0?r("div",{class:"transcript-empty",children:"No transcript yet."}):s.map(b=>b.role==="system"&&b.kind==="compact"?r("div",{class:"transcript-compact",children:r("span",{children:"context compacted"})},b.uuid):r(Ew,{m:b,current:b.uuid===h},b.uuid)),i==="needs-input"&&r("div",{class:"transcript-status transcript-status-waiting",children:[r("span",{class:"transcript-status-dot"}),r("span",{class:"transcript-status-text",children:["Waiting for your input",l?` — ${l}`:""]})]}),i==="working"&&r("div",{class:"transcript-working",children:[r("span",{class:"transcript-working-dot"}),r("span",{class:"transcript-working-verb",children:a?`${a.toLowerCase()}…`:"working…"})]})]}),r(Pw,{target:e,composerRef:u})]})}const Mw=1500;function Lw(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Iw({mode:e,onMode:t}){return r("span",{class:"detail-mode-toggle",children:[r("button",{class:e==="transcript"?"is-active":"",onClick:()=>t("transcript"),children:"Transcript"}),r("button",{class:e==="terminal"?"is-active":"",onClick:()=>t("terminal"),children:"Terminal"})]})}function Ow({pid:e,paneLabel:t}){const n=Ne.value[e]||[],i=Re.value[e]||"pane";return r("div",{class:"detail-tab-strip",role:"tablist",children:[r("button",{type:"button",role:"tab",class:`detail-tab${i==="pane"?" is-active":""}`,"aria-selected":i==="pane",onClick:()=>Nr(e,"pane"),title:t,children:r("span",{class:"detail-tab-label",children:t})}),r("button",{type:"button",role:"tab",class:`detail-tab${i==="changes"?" is-active":""}`,"aria-selected":i==="changes",onClick:()=>Nr(e,"changes"),title:"Changes in this worktree",children:r("span",{class:"detail-tab-label",children:"Changes"})}),n.map(l=>{const a=`file:${l.path}`,s=i===a;return r("button",{type:"button",role:"tab",class:`detail-tab${s?" is-active":""}`,"aria-selected":s,onClick:()=>Nr(e,a),title:l.path,children:[r("span",{class:"detail-tab-label",children:Lw(l.path)}),r("span",{class:"detail-tab-close",title:"Close tab",onClick:o=>{o.stopPropagation(),Tc(e,l.path)},children:"×"})]},a)})]})}function Wo(e){return(de.value||[]).find(t=>t.pid===e)||null}function Wd(e){return(e==null?void 0:e.agent)!=="claude"?"terminal":fu(e.pid)||"terminal"}async function Dw(e){var n;if(!tr.value)return;const t=((n=e.clipboardData)==null?void 0:n.items)||[];for(const i of t){if(i.kind!=="file"||!i.type.startsWith("image/"))continue;const l=i.getAsFile();if(l){e.preventDefault(),e.stopPropagation();try{const s=await(await fetch(`/api/paste-image?${nt(tr.value)}`,{method:"POST",headers:{"Content-Type":l.type||"image/png"},body:l})).json();s.ok||Us(`\r -\x1B[31m[periscope: image paste failed: ${s.error}]\x1B[0m`)}catch(a){Us(`\r -\x1B[31m[periscope: image paste error: ${a.message}]\x1B[0m`)}return}}}function Rw({w:e}){const t=!!e.spawned_by&&(de.value||[]).some(l=>l.pid===e.spawned_by),n=[];if(e.session&&e.session!==e.branch&&n.push(r("span",{children:r("b",{children:e.session})})),e.cwd){const l=e.cwd.split("/").filter(Boolean),a=l[l.length-1]||"",s=e.branch?e.branch.replace(/[/\\]/g,"-"):null;let o;s&&a===s&&l.length>=2?o=l[l.length-2]:o=l.length>=2?l.slice(-2).join("/"):l[0]||e.cwd,o&&n.push(r(V,{children:[n.length>0&&r("span",{class:"hsep",children:"·"}),r("span",{class:"header-cwd-reveal",title:`Reveal ${e.cwd} in Finder`,onClick:async()=>{try{await fetch(`/api/fs/open?session=${encodeURIComponent(e.session)}&index=${e.index}&path=.&action=reveal`,{method:"POST"})}catch{}},children:o})]}))}if(e.branch&&n.push(r(V,{children:[r("span",{class:"hsep",children:"·"}),r("span",{children:e.branch})]})),e.pr){const l=rr(e.repo_slug,e.pr),a=ji(e.pr_state),s=e.ci==="✓"?"ci-ok":e.ci==="✗"?"ci-bad":e.ci==="⟳"?"ci-running":"",o=e.ci&&!a.cls?r(V,{children:[" ",r("span",{class:`header-ci ${s}`,children:e.ci})]}):null,u=r(V,{children:["#",String(e.pr),a.suffix?r("span",{class:"header-pr-state",children:a.suffix}):null,o]}),c=l?r("a",{class:`header-pr ${a.cls}`,href:l,target:"_blank",rel:"noopener",children:u}):r("span",{class:`header-pr ${a.cls}`,children:u});n.push(r(V,{children:[r("span",{class:"hsep",children:"·"}),c]}))}const i=br(e);if(i&&n.push(r(V,{children:[r("span",{class:"hsep",children:"·"}),r("a",{class:"header-linear",href:i.href,target:"_blank",rel:"noopener",title:i.tip,children:i.id})]})),e.git&&e.git!=="clean"&&n.push(r(V,{children:[r("span",{class:"hsep",children:"·"}),r("span",{class:"header-git",children:e.git})]})),e.agent==="claude"?n.push(r(V,{children:[r("span",{class:"hsep",children:"·"}),r(ww,{w:e})]})):e.agent&&e.model&&n.push(r(V,{children:[r("span",{class:"hsep",children:"·"}),r("span",{children:e.model.replace(/\s*\(.*\)/,"")})]})),e.agent&&e.context_pct!=null&&n.push(r(V,{children:[r("span",{class:"hsep",children:"·"}),r("span",{children:[e.context_pct,"%"]})]})),e.agent==="claude"&&e.mem){const l=cu(e.mem);n.push(r(V,{children:[r("span",{class:"hsep",children:"·"}),r("span",{class:`header-mem ${l.cls}`,title:l.title,children:["↻ ",l.label]})]}))}return e.api_error&&n.push(r(V,{children:[r("span",{class:"hsep",children:"·"}),r("span",{class:"header-api-error",title:"last tool result was an API error",children:"⚠ API error"})]})),r("header",{id:"detail-pane-header",class:"detail-pane-header","data-agent":e.agent||void 0,children:[n.map((l,a)=>r(V,{children:l})),e.spawner_name&&r("span",{class:`header-lineage${t?"":" lineage-gone"}`,title:t?`spawned by ${e.spawner_name} — click to reveal`:`spawned by ${e.spawner_name}, which is no longer running`,onClick:t?()=>{ke.value=`pane:${e.spawned_by}`,gt({kind:"pane",pid:e.spawned_by})}:void 0,children:["↳ launched by ",e.spawner_name]}),e.status_line&&r("span",{class:"header-status",title:e.status_at?`as of ${Pe(e.status_at)} ago`:void 0,children:e.status_line})]})}function Fw({target:e}){const[t,n]=B(null);return j(()=>{if(!e)return;let i=!0;async function l(){try{const s=await fetch(`/api/pane?${nt(e)}&lines=80`);if(!s.ok)return;const o=await s.json();i&&n(o)}catch{}}l();const a=setInterval(l,Mw);return()=>{i=!1,clearInterval(a)}},[e]),t?r(ew,{data:t,onRefresh:()=>{},containerId:"detail-side",containerClass:"detail-side",idPrefix:"detail"}):r("aside",{id:"detail-side",class:"detail-side"})}function Nw({w:e}){const t=Wd(e);j(()=>{tr.value=e.target},[e.target]),j(()=>{e.pane_id&&(e.channel_unread||0)>0&&fetch(`/api/channel/clear-unread?pane_id=${encodeURIComponent(e.pane_id)}`,{method:"POST"})},[e.pane_id,e.channel_unread]),j(()=>(zs(c=>{let f=c,d=null;const p=f.match(/^(.*?):(\d+)$/);p&&(f=p[1],d=p[2]),gr({path:f,line:d})}),()=>zs(null)),[e.target]),j(()=>{const c=document.getElementById("detail-pane-header"),f=document.getElementById("detail-tab-bar"),d=document.getElementById("detail");if(!c||!d)return;const p=()=>d.style.setProperty("--detail-header-h",`${c.offsetHeight+((f==null?void 0:f.offsetHeight)||0)}px`);p();const h=new ResizeObserver(p);return h.observe(c),f&&h.observe(f),()=>h.disconnect()},[e.target]),j(()=>{if(t!=="terminal")return;const c=requestAnimationFrame(()=>requestAnimationFrame(bi));return()=>cancelAnimationFrame(c)},[t]);const[n,i]=B(!0);j(()=>{if(t!=="terminal")return;const c=()=>i(S1());c();const f=setInterval(c,250);return()=>clearInterval(f)},[t,e.pid]);const l=ne(e.state);j(()=>{const c=l.current==="working",f=e.state==="idle"||e.state==="done";if(c&&f&&e.agent){const d=document.getElementById("detail-xterm");d&&(d.classList.add("bell-pulse"),setTimeout(()=>d.classList.remove("bell-pulse"),400))}l.current=e.state},[e.state,e.agent]);const a=Ne.value[e.pid]||[],s=Re.value[e.pid]||"pane",o=s==="pane",u=e.track_name||Se(e);return r("div",{id:"detail-pane",class:"detail-pane",children:[r(Rw,{w:e}),r("div",{id:"detail-tab-bar",class:"detail-tab-bar",children:[r(Ow,{pid:e.pid,paneLabel:u}),e.agent==="claude"&&r(Iw,{mode:t,onMode:c=>{ye("view.switch",{view:c}),jl(e.pid,c)}})]}),r("div",{class:"detail-pane-body",children:[r("div",{class:"detail-term-host",style:o&&t==="terminal"?"display:contents":"display:none",children:r(dw,{id:"detail-xterm",class:"detail-xterm",target:e.pane_id,agent:e.agent,onPaste:Dw},e.pid)}),r("div",{class:"detail-changes-host",style:s==="changes"?"display:contents":"display:none",children:r(Dk,{target:e.target,active:s==="changes",gitSig:e.git||""})}),a.map(c=>{const f=`file:${c.path}`,d=s===f;return r("div",{class:"detail-preview-host",style:d?"display:contents":"display:none",children:r(nw,{entry:c,active:d})},f)}),!mi.value&&r(Fw,{target:e.target},e.target),!mi.value&&r(Ud,{which:"side"})]}),o&&t==="terminal"&&!n&&r("button",{class:"term-scroll-bottom",title:"Scroll to latest",onClick:bi,children:"⤓"}),o&&t==="terminal"&&r(hw,{})]})}function _l(){return r("div",{id:"detail-empty",class:"detail-empty",children:r("div",{class:"detail-empty-card",children:r("p",{children:["Select a tab on the left, or"," ",r("button",{id:"detail-empty-add",onClick:()=>{var e;return(e=window.__periscopeOpenOmnibox)==null?void 0:e.call(window)},children:"+ open"})," ","to add one."]})})})}function Bw(){var d,p;const e=ke.value,t=de.value||[],n=!!e&&e.startsWith("pane:"),i=!!e&&e.startsWith("review:"),l=e==="reviews";let a=null;if(i){const[h,m]=(()=>{const b=e.slice(7),x=b.indexOf("/");return x<0?[b,""]:[b.slice(0,x),b.slice(x+1)]})();a=(mt.value||[]).find(b=>b.repo===h&&b.slug===m)||null}j(()=>{(i||l)&&(tr.value=null)},[e]);const s=n?Wo(e.slice(5)):null,o=ne(new Set);n&&(s==null?void 0:s.agent)==="claude"&&o.current.add(s.pid);const u=new Set(t.map(h=>h.pid)),c=Wd(s);for(const h of[...o.current])if(!(n&&(s==null?void 0:s.pid)===h)&&!u.has(h)&&(o.current.delete(h),Ft.value[h])){const{[h]:b,...x}=Ft.value;Ft.value=x}const f=[...o.current];return r("section",{id:"detail",children:[!e&&r(_l,{}),n&&(s?r(Nw,{w:s}):r(_l,{})),l&&r(aw,{}),i&&(mt.value===null?r("div",{class:"wt-empty",children:"loading…"}):a?r(uw,{repo:a.repo,branch:a.branch,pr:a.pr,sig:`${(d=a.walkthrough)==null?void 0:d.head}|${(p=a.walkthrough)==null?void 0:p.stale_by}|${a.unresolved}|${a.comments}`},`${a.repo}/${a.branch}`):r(_l,{})),f.map(h=>{const m=Wo(h),b=n&&(s==null?void 0:s.pid)===h,x=(Re.value[h]||"pane")==="pane";return r("div",{class:"detail-transcript-host",style:b&&x&&c==="transcript"?"display:flex":"display:none",children:r(Aw,{target:m==null?void 0:m.target,pid:h,selected:b,state:m==null?void 0:m.state,waitingFor:m==null?void 0:m.waiting_for,spinner:m==null?void 0:m.spinner})},`tr:${h}`)})]})}function xl(e,t){return t==="all"?!0:t==="needs-input"?e.state==="needs-input":t==="working"?e.state==="working":t==="done"?e.state==="done":t==="idle"?e.state==="idle":t==="agents"?!!e.agent:t==="shell"?e.state==="shell":t==="ci-bad"?e.ci==="✗":!0}const ta=H(!1);function Sl(e,t,n,i=l=>l.key){const l=e||[];if(!n||!t)return l;const a=new Map(l.map(s=>[i(s),s]));return t.map(s=>a.get(i(s))||s)}function $l(e,t,n,i=l=>l.key){if(!n||!t)return!1;const l=(e||[]).map(i),a=t.map(i);if(l.length!==a.length)return!0;const s=new Set(a);return l.some(o=>!s.has(o))}function zw(e,t){return!!t&&!!(e!=null&&e.branch)}function jw(e,t){return`open ${e!=null&&e.branch?`${e.branch} `:""}worktree in ${t}`}const Hw=900;function Qa(e){return e==="needs-input"?"dot dot-alert dot-pulse":e==="working"?"dot dot-green":e==="done"?"dot dot-blue dot-pulse-done":e==="idle"?"dot dot-grey":"dot dot-none"}function qw(e){return e==="✓"?"ok":e==="✗"?"bad":e==="⟳"?"running":"neutral"}function Uw(e){return e?e.replace(/\s*\(.*$/,"").trim():null}function Ww(e){return`${Math.round(e/1e3)}k`}function Rn(e){return e.context_pct!=null?`${e.context_pct}%`:e.ctx_tokens!=null?Ww(e.ctx_tokens):null}function Kd({label:e,kind:t,renameable:n,onCommit:i}){const[l,a]=B(!1),s=ne(null),o=ne(!1);j(()=>{l&&s.current&&(s.current.focus(),s.current.select())},[l]);function u(d){n&&(d.preventDefault(),d.stopPropagation(),o.current=!1,a(!0))}function c(d){if(o.current)return;o.current=!0,a(!1);const p=(d||"").trim();p&&p!==e&&i(p)}function f(){o.current||(o.current=!0,a(!1))}return l?r("span",{class:"rail-label",children:r("input",{ref:s,type:"text",class:"rail-rename-input",defaultValue:e,spellcheck:!1,onClick:d=>d.stopPropagation(),onKeyDown:d=>{d.stopPropagation(),d.key==="Enter"?(d.preventDefault(),c(d.currentTarget.value)):d.key==="Escape"&&(d.preventDefault(),f())},onBlur:d=>c(d.currentTarget.value)})}):r("span",{class:"rail-label",onDblClick:n?u:void 0,children:t==="pane"?e:r("b",{children:e})})}function Kw({w:e,chip:t,selectedKey:n,onSelect:i,onClose:l,onRename:a,dim:s,dragProps:o,dropPos:u,pinned:c,onTogglePin:f,awaitingSince:d,onMoveAccount:p,onToggleNamePin:h,editor:m,onOpenInEditor:b}){const x=`pane:${e.pid}`,w=x===n,C=w||e.state==="needs-input",y=e.agent?e.state||"idle":"shell",g=s?"":" rail-dim",$=u?" drop-target":"",v=Se(e),E=e.agent||(e.is_claude?"claude":null),A=zl[E],T=e.status_rail||e.status_line,S=e.status_at&&Math.floor(Date.now()/1e3)-e.status_at>Hw,R=Uw(e.model),F=e.pr?rr(e.repo_slug,e.pr):null,q=cu(e.mem),L=d?yu(d,Math.floor(Date.now()/1e3)):null,I=vh(e),O=ji(e.pr_state),Q=`PR #${e.pr}${O.suffix}`,M=r(V,{children:["#",e.pr,e.ci&&!O.cls?r("span",{class:`pane-ci pane-ci-${qw(e.ci)}`,children:[" ",e.ci]}):null]}),z=e.pr&&(F?r("a",{class:`pane-pill pane-pill-pr ${O.cls}`,href:F,target:"_blank",rel:"noopener",onClick:X=>X.stopPropagation(),title:Q,children:M}):r("span",{class:`pane-pill pane-pill-pr ${O.cls}`,title:Q,children:M})),k=br(e),W=k&&r("a",{class:"pane-pill pane-pill-linear",href:k.href,target:"_blank",rel:"noopener",onClick:X=>X.stopPropagation(),title:k.tip,children:k.id}),Z=e.account&&e.account!=="default"&&(Sn()||e.account==="unknown")&&r("span",{class:"pane-pill pane-pill-acct",title:`running on Claude account ${gn(e.account)} — its usage bills that subscription`,children:["@",gn(e.account)]}),_=e.profile&&e.profile!=="default"&&r("span",{class:"rail-profile",title:`running the ${So(e.profile)} profile — a different plugin set and system prompt than a normal pane`,children:So(e.profile)});return r("div",{class:`rail-row child-row pane-row pane-state-${y}${C?" pane-expanded":""}${w?" selected":""}${g}${$}`,"data-drop-pos":u||void 0,draggable:!0,onClick:()=>i(x),...o,children:[r("span",{class:"pane-stripe","aria-hidden":"true"}),r("div",{class:"pane-row-main",children:[A?r("span",{class:`rail-icon ${A.className}`,title:A.label,children:A.glyph}):r("span",{class:"rail-icon icon-shell",children:"$"}),r(Kd,{label:v,kind:"pane",renameable:!0,onCommit:a}),C?R&&r("span",{class:"pane-model",title:e.model,children:R}):Rn(e)!=null&&r("span",{class:`pane-mini-ctx${Ul(e)}`,title:e.ctx_hint||"context window used",children:Rn(e)}),q&&r("span",{class:`rail-mem ${q.cls}`,title:q.title,children:["↻",q.label]}),L&&r("span",{class:`rail-await wait-${L}`,title:`asked you something ${Pe(d)} ago and has had no reply since`,children:["⚠",Pe(d)]}),c&&r("span",{class:"pane-pin-flag",title:"pinned",children:"★"})]}),(t||T||!C&&(z||W||Z||_))&&r("div",{class:`rail-meta${S?" stale":""}`,children:[t&&r("span",{class:"rail-chip",title:e.cwd,children:["⧉ ",t]}),T&&r("span",{class:"rail-status",title:e.status_line,children:T}),!C&&(z||W||Z||_)&&r("span",{class:"rail-chips",children:[z,W,Z,_]})]}),C&&(e.pr||k||Rn(e)!=null||Z||_)&&r("div",{class:"pane-foot",children:[z,W,r("span",{class:"pane-foot-spacer"}),Z,_,Rn(e)!=null&&r("span",{class:`pane-pill pane-pill-ctx${Ul(e)}`,title:e.ctx_hint||"context window used",children:Rn(e)}),e.status_at?r("span",{class:"pane-time",children:Pe(e.status_at)}):null]}),r("div",{class:"pane-actions",children:[I&&r("button",{class:"rail-move-acct",title:`re-open this session on Claude account ${I.label} — spawns a resumed pane there and leaves this one running`,onClick:X=>{X.stopPropagation(),p==null||p(I.id)},children:["→ ",I.label]}),r("button",{class:`rail-pin${c?" pinned":""}`,title:c?"unpin":"pin",onClick:X=>{X.stopPropagation(),f==null||f()},children:c?"★":"☆"}),r("button",{class:`rail-name-pin${e.name_pinned?" pinned":""}`,title:e.name_pinned?"name pinned — click to let periscope rename this tab again":"freeze this name — periscope won't rename this tab",onClick:X=>{X.stopPropagation(),h==null||h()},children:e.name_pinned?"🔒":"🔓"}),zw(e,m)&&r("button",{class:"rail-editor",title:jw(e,m),onClick:X=>{X.stopPropagation(),b==null||b()},children:"↗"}),r("button",{class:"rail-close",title:"kill this tab",onClick:X=>{X.stopPropagation(),l()},children:"×"})]})]})}function Vw({worktreeKey:e,onOpen:t}){return r("div",{class:"rail-row child-row newtab-row last-in-worktree",onClick:()=>t(e),children:[r("span",{class:"rail-icon",children:"+"}),r("span",{class:"rail-label",children:"New tab"})]})}function Gw({label:e,collapsed:t,childCount:n,rolledUp:i,dim:l,onToggle:a,dragProps:s,dropPos:o}){return r("div",{class:`rail-row wt-row${l?"":" rail-dim"}${o?" drop-target":""}`,"data-drop-pos":o||void 0,draggable:!0,onClick:d=>{d.target.closest("button")||d.target.closest("input")||a()},...s,children:[r("span",{class:"rail-chev",children:t?"▸":"▾"}),r("span",{class:"rail-icon icon-worktree",children:"⎇"}),r("span",{class:"rail-label",children:r("b",{children:e})}),t&&n>0?r("span",{class:"rail-count",children:n}):null,r("span",{class:Qa(i)})]})}function Ko({row:e,selectedKey:t,onSelect:n}){var s;const i=`review:${e.repo}/${e.slug}`,l=i===t?" selected":"",a=((s=e.walkthrough)==null?void 0:s.stale_by)>0;return r("div",{class:`rail-row child-row rail-review${l}`,onClick:()=>n(i),children:[r("span",{class:"rail-icon icon-review",children:"◉"}),r("span",{class:"rail-label",children:["review · ",e.walkthrough.stops," stop",e.walkthrough.stops===1?"":"s",a?" · stale":""]}),e.unresolved?r("span",{class:"rail-review-badge",children:e.unresolved}):null]})}function Jw({kind:e,label:t,collapsed:n,rolledUp:i,dim:l,onToggle:a,onRename:s,onDissolve:o,onTeardown:u,dragProps:c,dropPos:f}){const d=n?"▸":"▾",p=l?"":" rail-dim",h=f?" drop-target":"",[m,b]=B(!1),x=e==="loose"||e==="repo",w=e==="goal"?"⧉":"🗀";return j(()=>{if(!m)return;const C=g=>{g.target.closest(".track-menu")||b(!1)},y=g=>{g.key==="Escape"&&b(!1)};return document.addEventListener("click",C,!0),document.addEventListener("keydown",y),()=>{document.removeEventListener("click",C,!0),document.removeEventListener("keydown",y)}},[m]),r("div",{class:`rail-row repo-row${p}${h}`,"data-drop-pos":f||void 0,draggable:!0,onClick:C=>{C.target.closest("button")||C.target.closest("input")||a()},...c,children:[r("span",{class:"rail-chev",children:d}),r("span",{class:"rail-icon icon-effort",title:e==="goal"?"track":"project",children:w}),r(Kd,{label:t,kind:"track",renameable:e!=="loose",onCommit:s}),r("span",{class:"repo-rule","aria-hidden":"true"}),r("span",{class:Qa(i)}),!x&&r("span",{class:"track-menu",children:[r("button",{class:"rail-track-menu-btn",title:"track actions",onClick:C=>{C.stopPropagation(),b(y=>!y)},children:"⋯"}),m&&r("div",{class:"track-menu-pop",onClick:C=>C.stopPropagation(),children:[r("button",{class:"track-menu-item",onClick:()=>{b(!1),o()},children:["Dissolve ",r("span",{class:"track-menu-hint",children:"tabs survive"})]}),r("button",{class:"track-menu-item track-menu-danger",onClick:()=>{b(!1),u()},children:["Tear down ",r("span",{class:"track-menu-hint",children:"kills tabs"})]})]})]})]})}function an({icon:e,label:t,count:n,collapsed:i,onToggle:l,tone:a}){return r("div",{class:`rail-row section-header${a==="alert"?" section-header-alert":a==="ready"?" section-header-ready":a==="working"?" section-header-working":""}`,onClick:l,children:[r("span",{class:"rail-chev",children:i?"▸":"▾"}),e?r("span",{class:"section-header-icon",children:e}):null,r("span",{class:"section-header-label",children:t}),n!=null&&n>0?r("span",{class:"section-header-count",children:n}):null]})}function $t(e,t,n,i){const l=(e==null?void 0:e.session)||t||"",a=Se(e)||n||"";return`${i?i(l):l} · ${a}`}function Vd(e){const t=[...new Set((e||[]).map(n=>n.session).filter(Boolean))];return n=>ou(n,t)}function zn(e,t){du(e,!t)}function Zt(e){return`${e.kind}:${e.pid??e.id}`}function Qw(){var A,T,S,R,F,q;me.value;const e=de.value||[],t=La.value||[],n=nr.value,i=ht.value,l=lr(),a=Vd(e),s=Pa(e,t,n,i),o=l["sec:needs"]===!0,u=gu(e,t,n,ft.value),c=l["sec:ready"]===!0,f=wu(e),d=l["sec:running"]===!0,p=i1($a(),e),h=l["sec:pinned"]===!0,m=ta.value,b=ne(null),x=Sl(s,(A=b.current)==null?void 0:A.needs,m,Zt),w=Sl(u,(T=b.current)==null?void 0:T.ready,m,Zt),C=Sl(f,(S=b.current)==null?void 0:S.running,m,Zt),y=$l(s,(R=b.current)==null?void 0:R.needs,m,Zt)||$l(u,(F=b.current)==null?void 0:F.ready,m,Zt)||$l(f,(q=b.current)==null?void 0:q.running,m,Zt);j(()=>{m||(b.current={needs:s,ready:u,running:f})});function g(){b.current=null}j(()=>{const L=Rs(ht.value,e,"needs-input");L.size!==ht.value.size&&(ht.value=L);const I=Rs(ft.value,e,"done");I.size!==ft.value.size&&(ft.value=I)},[de.value]);function $(L){g();const I=new Set(n);I.add(L),nr.value=I}function v(L){g(),vu(L)}function E(L){g(),xu(L)}return r(V,{children:[y&&r("div",{class:"attn-frozen",title:"Move the pointer out of the rail to apply",children:"updates paused"}),x.length>0&&r(V,{children:[r(an,{icon:"⚠",label:"NEEDS YOU",tone:"alert",count:t1(x),collapsed:o,onToggle:()=>zn("sec:needs",o)}),!o&&x.map(L=>{var I;return L.kind==="live"?r("div",{class:"rail-row attn-row attn-needs",onClick:()=>v(L.w),children:[r("span",{class:"attn-dot dot dot-alert dot-pulse"}),r("span",{class:"attn-label",children:$t(L.w,null,null,a)}),r("span",{class:"attn-reason",children:Cg((I=L.w)==null?void 0:I.waiting_for)})]},`live:${L.pid}`):r("div",{class:"rail-row attn-row attn-needs attn-event",onClick:()=>jt(L.target),children:[r("span",{class:"attn-ico",children:"⚠"}),r("span",{class:"attn-label",children:$t(L.w,L.session,L.name,a)}),r("span",{class:"attn-reason",children:["need_human · ",Pe(L.ts)]}),r("button",{class:"attn-x",title:"dismiss",onClick:O=>{O.stopPropagation(),$(L.id)},children:"×"})]},`evt:${L.id}`)})]}),w.length>0&&r(V,{children:[r(an,{icon:"✓",label:"READY",tone:"ready",count:w.length,collapsed:c,onToggle:()=>zn("sec:ready",c)}),!c&&w.map(L=>{var I;return L.kind==="live"?r("div",{class:"rail-row attn-row attn-ready",onClick:()=>E(L.w),children:[r("span",{class:"attn-dot dot dot-blue dot-pulse-done"}),r("span",{class:"attn-label",children:$t(L.w,null,null,a)}),r("span",{class:"attn-reason",children:Pe((I=L.w)==null?void 0:I.completed_at)})]},`rlive:${L.pid}`):r("div",{class:"rail-row attn-row attn-ready attn-event",onClick:()=>jt(L.target),children:[r("span",{class:"attn-ico",children:"✓"}),r("span",{class:"attn-label",children:$t(L.w,L.session,L.name,a)}),r("span",{class:"attn-reason",children:["done · ",Pe(L.ts)]}),r("button",{class:"attn-x",title:"dismiss",onClick:O=>{O.stopPropagation(),$(L.id)},children:"×"})]},`revt:${L.id}`)})]}),C.length>0&&r(V,{children:[r(an,{icon:"⟳",label:"RUNNING",tone:"working",count:C.length,collapsed:d,onToggle:()=>zn("sec:running",d)}),!d&&C.map(L=>{var I;return r("div",{class:"rail-row attn-row attn-running",onClick:()=>yt(L.w),children:[r("span",{class:"attn-dot dot dot-green"}),r("span",{class:"attn-label",children:$t(L.w,null,null,a)}),r("span",{class:"attn-reason",children:`${((I=L.w)==null?void 0:I.spinner)||"working"}…`})]},`run:${L.pid}`)})]}),p.length>0&&r(V,{children:[r(an,{icon:"★",label:"PINNED",count:p.length,collapsed:h,onToggle:()=>zn("sec:pinned",h)}),!h&&p.map(L=>{var I,O;return r("div",{class:"rail-row attn-row attn-pinned",onClick:()=>yt(L),children:[r("span",{class:`attn-ico ${((I=zl[L.agent])==null?void 0:I.className)||""}`,children:((O=zl[L.agent])==null?void 0:O.glyph)||"$"}),r("span",{class:"attn-label",children:$t(L,null,null,a)}),r("span",{class:Qa(L.state),style:"margin-left:auto"})]},`pin:${L.pid}`)})]})]})}function Yw(){me.value;const e=La.value||[],t=lr(),n=Vd(de.value||[]),i=l1(e),l=t["sec:activity"]!==!1;return r(V,{children:[r(an,{label:"ACTIVITY",count:i.length||null,collapsed:l,onToggle:()=>zn("sec:activity",l)}),!l&&i.map(a=>r("div",{class:`rail-row attn-row attn-activity attn-${a.kind}`,onClick:()=>jt(a.target),children:[r("span",{class:"attn-ico",children:a.kind==="done"?"✓":"•"}),r("span",{class:"attn-label",children:$t(null,a.session,a.name,n)}),r("span",{class:"attn-reason",children:Pe(a.ts)})]},`act:${a.id}`))]})}const Zw="";function Xw(e){const t=window.__periscopeOpenLauncher;typeof t=="function"&&t(e)}function ev(e,t){return!t||t==="all"?e:e.filter(n=>n.track_id===t)}function tv({live:e,scope:t,onScope:n}){const i=[],l=new Set;for(const a of e)a.track_id&&!l.has(a.track_id)&&(l.add(a.track_id),i.push(a.track_id));return i.length<2?null:r("div",{class:"rail-filter-chips",role:"tablist","aria-label":"filter by track",children:[r("button",{class:`rail-filter-chip${!t||t==="all"?" is-active":""}`,onClick:()=>n("all"),children:"all"}),i.map(a=>r("button",{class:`rail-filter-chip${t===a?" is-active":""}`,onClick:()=>n(a),title:xi(a,e),children:xi(a,e)},a))]})}let Vo=0;function nv(){if(Date.now()-Vo<5e3)return;const e=de.value||[];if(e.length===0)return;Vo=Date.now();const t=Ga(e,Li.value,Ii.value,{trackOrder:fi(),tabsByTrack:ir(),branchOrderByTrack:Sa()},Bt.value),n=fi(),i=ir(),l=t.trackOrder,a={};for(const u of l)a[u]=t.tabsByTrack[u]||[];if(JSON.stringify(l)===JSON.stringify(n)&&JSON.stringify(a)===JSON.stringify(i))return;const s=[...new Set(e.map(u=>u.track_id))],o=(Bt.value||[]).map(u=>u.id);$e({track_order:l,tabs_by_track:a},`sync live=${JSON.stringify(s)} registry=${JSON.stringify(o)} cached=${JSON.stringify(n)}`)}function Gd(e,t,n,i){if(t<0||n<0)return e;const[l]=e.splice(t,1);let a=n-(tM.id===i),{trackOrder:b,tabsByTrack:x,branchesByTrack:w,tabsByBranch:C}=Ga(u,Li.value,Ii.value,{trackOrder:fi(),tabsByTrack:ir(),branchOrderByTrack:Sa()},m),y=Q2(b,x,d,mt.value||[]);function g(M){if(M==="reviews"){Ia();return}if(M.startsWith("review:")){const z=M.slice(7),k=z.indexOf("/"),W=(mt.value||[]).find(Z=>Z.repo===z.slice(0,k)&&Z.slug===z.slice(k+1));W&&Su(W.repo,W.branch);return}ke.value=M,ye("pane.focus",{key:M}),M.startsWith("pane:")&>({kind:"pane",pid:M.slice(5)})}function $(M){const z=lr()[M]===!0;du(M,!z)}async function v(M){await Jn(`Close tab "${Se(M)}"? +`);return r("div",{class:"tc-diff",children:[t.map((i,l)=>r("div",{class:"tc-diff-del",children:i||" "},`d${l}`)),n.map((i,l)=>r("div",{class:"tc-diff-add",children:i||" "},`a${l}`))]})}function Rw(e){const t=e.input||{};switch(e.name){case"Bash":return t.command||"";case"Write":return t.content||"";default:return""}}function Fw({input:e}){const t=e.questions||[];return r("div",{class:"tc-ask",children:t.map((n,i)=>r("div",{class:"tc-ask-q",children:[r("div",{class:"tc-ask-qhead",children:[n.header&&r("span",{class:"tc-ask-chip",children:n.header}),n.multiSelect&&r("span",{class:"tc-ask-multi",children:"multi-select"})]}),r("div",{class:"tc-ask-question",children:n.question}),r("div",{class:"tc-ask-options",children:(n.options||[]).map((l,a)=>r("div",{class:"tc-ask-opt",children:[r("span",{class:"tc-ask-opt-label",children:l.label}),l.description&&r("span",{class:"tc-ask-opt-desc",children:l.description})]},a))})]},i))})}function Nw({t:e}){var f;const[t,n]=B(!1),i=e.result==null,l=e.name==="Edit",a=e.name==="AskUserQuestion",s=e.name==="Agent"||e.name==="Task",o=Rw(e),u=!i&&e.result!=null&&e.result!=="",c=l||a||!!o||u,p=Ow(e),d=s&&((f=e.input)==null?void 0:f.subagent_type)||"";return r("div",{class:`tc${s?" tc-agent":""}`,children:[r("button",{class:`tc-head${c?" expandable":""}`,onClick:c?()=>n(!t):void 0,children:[r("span",{class:"tc-dot",children:s?"⚇":"⏺"}),r("span",{class:"tc-name",children:e.name}),d&&r("span",{class:"tc-agent-type",children:d}),p&&(e.name==="Read"||e.name==="Edit"||e.name==="Write"||e.name==="MultiEdit"||e.name==="NotebookEdit"?r("span",{class:"tc-arg tc-arg-clickable",title:"Cmd+click to preview",onClick:m=>{!m.metaKey&&!m.ctrlKey||(m.stopPropagation(),kr({path:p,line:null}))},children:p}):r("span",{class:"tc-arg",children:p})),i&&r("span",{class:"tc-running",children:"running…"}),c&&r("span",{class:"tc-caret",children:t?"▾":"▸"})]}),t&&r("div",{class:"tc-detail",children:[l?r(Dw,{input:e.input||{}}):a?r(Fw,{input:e.input||{}}):o&&r("pre",{class:"tc-cmd",children:o}),u&&r("pre",{class:"tc-out",children:e.result})]})]})}function Bw({m:e,current:t}){if(e.role==="user")return r("div",{class:`turn turn-user${t?" turn-current":""}`,children:[r("span",{class:"turn-user-mark",children:"›"}),r("div",{class:"turn-user-body",children:mr(e.text)})]});const n=e.tool_uses||[];return r("div",{class:`turn turn-assistant${t?" turn-current":""}`,children:[e.text&&r("div",{class:"turn-prose",children:mr(e.text)}),n.length>0&&r("div",{class:"turn-tools",children:n.map((i,l)=>r(Nw,{t:i},i.id||l))})]})}function zw({target:e,composerRef:t}){const[n,i]=B(""),[l,a]=B(!1),s=te(null);async function o(){const d=n;if(!d.trim()||l)return;a(!0),await ie("send",`/api/send?${tt(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paste:d})})&&(await new Promise(h=>setTimeout(h,250)),await ie("send",`/api/send?${tt(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({keys:["Enter"]})}),i(""),s.current&&(s.current.style.height="")),a(!1)}function u(d){d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),o())}function c(d){const f=d.currentTarget;i(f.value),f.style.height="0px",f.style.height=`${Math.min(f.scrollHeight,140)}px`}async function p(d){var h;const f=((h=d.clipboardData)==null?void 0:h.items)||[];for(const m of f){if(m.kind!=="file"||!m.type.startsWith("image/"))continue;const b=m.getAsFile();if(!b)continue;d.preventDefault();const w=await(await fetch(`/api/paste-image?${tt(e)}&deliver=false`,{method:"POST",headers:{"Content-Type":b.type||"image/png"},body:b})).json().catch(()=>({}));w.ok&&i(C=>`${C}${C&&!C.endsWith(" ")?" ":""}@${w.path} `);return}}return r("div",{class:"transcript-composer",ref:t,children:r("textarea",{ref:s,class:"transcript-composer-input",placeholder:"Message Claude… (Enter to send · Shift+Enter for newline · paste screenshots)",value:n,rows:1,onInput:c,onKeyDown:u,onPaste:p})})}function jw({target:e,pid:t,selected:n,state:i,waitingFor:l,spinner:a}){var m;Iw(e,t,n);const s=((m=Ft.value[t])==null?void 0:m.messages)||[],o=te(null),u=te(null),c=te(!0),p=te(""),d=()=>{const b=o.current;b&&c.current&&(b.scrollTop=b.scrollHeight)};j(()=>{const b=s[s.length-1],x=`${s.length}:${b?b.uuid:""}:${b?(b.tool_uses||[]).length:0}`;x!==p.current&&(p.current=x,d())},[s]),j(()=>{const b=u.current,x=o.current;if(!b||!x)return;const w=()=>{x.style.paddingBottom=`${b.offsetHeight+14}px`,requestAnimationFrame(d)};w();const C=new ResizeObserver(w);return C.observe(b),()=>C.disconnect()},[]),j(()=>{(i==="needs-input"||i==="working")&&d()},[i]);function f(b){const x=b.currentTarget;c.current=x.scrollHeight-x.scrollTop-x.clientHeight<80}let h="";for(let b=s.length-1;b>=0;b--)if(s[b].role!=="system"){h=s[b].uuid;break}return r(K,{children:[r("div",{class:"transcript",ref:o,onScroll:f,children:[s.length===0?r("div",{class:"transcript-empty",children:"No transcript yet."}):s.map(b=>b.role==="system"&&b.kind==="compact"?r("div",{class:"transcript-compact",children:r("span",{children:"context compacted"})},b.uuid):r(Bw,{m:b,current:b.uuid===h},b.uuid)),i==="needs-input"&&r("div",{class:"transcript-status transcript-status-waiting",children:[r("span",{class:"transcript-status-dot"}),r("span",{class:"transcript-status-text",children:["Waiting for your input",l?` — ${l}`:""]})]}),i==="working"&&r("div",{class:"transcript-working",children:[r("span",{class:"transcript-working-dot"}),r("span",{class:"transcript-working-verb",children:a?`${a.toLowerCase()}…`:"working…"})]})]}),r(zw,{target:e,composerRef:u})]})}const Hw=1500;function qw(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Uw({mode:e,onMode:t}){return r("span",{class:"detail-mode-toggle",children:[r("button",{class:e==="transcript"?"is-active":"",onClick:()=>t("transcript"),children:"Transcript"}),r("button",{class:e==="terminal"?"is-active":"",onClick:()=>t("terminal"),children:"Terminal"})]})}function Ww({pid:e,paneLabel:t}){const n=Ne.value[e]||[],i=Re.value[e]||"pane";return r("div",{class:"detail-tab-strip",role:"tablist",children:[r("button",{type:"button",role:"tab",class:`detail-tab${i==="pane"?" is-active":""}`,"aria-selected":i==="pane",onClick:()=>jr(e,"pane"),title:t,children:r("span",{class:"detail-tab-label",children:t})}),r("button",{type:"button",role:"tab",class:`detail-tab${i==="changes"?" is-active":""}`,"aria-selected":i==="changes",onClick:()=>jr(e,"changes"),title:"Changes in this worktree",children:r("span",{class:"detail-tab-label",children:"Changes"})}),n.map(l=>{const a=`file:${l.path}`,s=i===a;return r("button",{type:"button",role:"tab",class:`detail-tab${s?" is-active":""}`,"aria-selected":s,onClick:()=>jr(e,a),title:l.path,children:[r("span",{class:"detail-tab-label",children:qw(l.path)}),r("span",{class:"detail-tab-close",title:"Close tab",onClick:o=>{o.stopPropagation(),Mc(e,l.path)},children:"×"})]},a)})]})}function Go(e){return(ce.value||[]).find(t=>t.pid===e)||null}function Qd(e){return(e==null?void 0:e.agent)!=="claude"?"terminal":yu(e.pid)||"terminal"}async function Kw(e){var n;if(!rr.value)return;const t=((n=e.clipboardData)==null?void 0:n.items)||[];for(const i of t){if(i.kind!=="file"||!i.type.startsWith("image/"))continue;const l=i.getAsFile();if(l){e.preventDefault(),e.stopPropagation();try{const s=await(await fetch(`/api/paste-image?${tt(rr.value)}`,{method:"POST",headers:{"Content-Type":l.type||"image/png"},body:l})).json();s.ok||Vs(`\r +\x1B[31m[periscope: image paste failed: ${s.error}]\x1B[0m`)}catch(a){Vs(`\r +\x1B[31m[periscope: image paste error: ${a.message}]\x1B[0m`)}return}}}function Vw({w:e}){const t=!!e.spawned_by&&(ce.value||[]).some(l=>l.pid===e.spawned_by),n=[];if(e.session&&e.session!==e.branch&&n.push(r("span",{children:r("b",{children:e.session})})),e.cwd){const l=e.cwd.split("/").filter(Boolean),a=l[l.length-1]||"",s=e.branch?e.branch.replace(/[/\\]/g,"-"):null;let o;s&&a===s&&l.length>=2?o=l[l.length-2]:o=l.length>=2?l.slice(-2).join("/"):l[0]||e.cwd,o&&n.push(r(K,{children:[n.length>0&&r("span",{class:"hsep",children:"·"}),r("span",{class:"header-cwd-reveal",title:`Reveal ${e.cwd} in Finder`,onClick:async()=>{try{await fetch(`/api/fs/open?session=${encodeURIComponent(e.session)}&index=${e.index}&path=.&action=reveal`,{method:"POST"})}catch{}},children:o})]}))}if(e.branch&&n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),r("span",{children:e.branch})]})),e.pr){const l=lr(e.repo_slug,e.pr),a=Ui(e.pr_state),s=e.ci==="✓"?"ci-ok":e.ci==="✗"?"ci-bad":e.ci==="⟳"?"ci-running":"",o=e.ci&&!a.cls?r(K,{children:[" ",r("span",{class:`header-ci ${s}`,children:e.ci})]}):null,u=r(K,{children:["#",String(e.pr),a.suffix?r("span",{class:"header-pr-state",children:a.suffix}):null,o]}),c=l?r("a",{class:`header-pr ${a.cls}`,href:l,target:"_blank",rel:"noopener",children:u}):r("span",{class:`header-pr ${a.cls}`,children:u});n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),c]}))}const i=vr(e);if(i&&n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),r("a",{class:"header-linear",href:i.href,target:"_blank",rel:"noopener",title:i.tip,children:i.id})]})),e.git&&e.git!=="clean"&&n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),r("span",{class:"header-git",children:e.git})]})),e.agent==="claude"?n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),r(Mw,{w:e})]})):e.agent&&e.model&&n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),r("span",{children:e.model.replace(/\s*\(.*\)/,"")})]})),e.agent&&e.context_pct!=null&&n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),r("span",{children:[e.context_pct,"%"]})]})),e.agent==="claude"&&e.mem){const l=fu(e.mem);n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),r("span",{class:`header-mem ${l.cls}`,title:l.title,children:["↻ ",l.label]})]}))}return e.api_error&&n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),r("span",{class:"header-api-error",title:"last tool result was an API error",children:"⚠ API error"})]})),e.res&&n.push(r(K,{children:[r("span",{class:"hsep",children:"·"}),r("span",{class:"header-res",title:"this pane's whole process tree: memory footprint, and its share of the machine's CPU (100% = every core busy)",children:`${cn(e.res.mem_mb)} mem · ${Au(e.res.cpu_pct)} cpu`})]})),r("header",{id:"detail-pane-header",class:"detail-pane-header","data-agent":e.agent||void 0,children:[n.map((l,a)=>r(K,{children:l})),e.spawner_name&&r("span",{class:`header-lineage${t?"":" lineage-gone"}`,title:t?`spawned by ${e.spawner_name} — click to reveal`:`spawned by ${e.spawner_name}, which is no longer running`,onClick:t?()=>{ke.value=`pane:${e.spawned_by}`,yt({kind:"pane",pid:e.spawned_by})}:void 0,children:["↳ launched by ",e.spawner_name]}),e.status_line&&r("span",{class:"header-status",title:e.status_at?`as of ${Pe(e.status_at)} ago`:void 0,children:e.status_line})]})}function Gw({target:e}){const[t,n]=B(null);return j(()=>{if(!e)return;let i=!0;async function l(){try{const s=await fetch(`/api/pane?${tt(e)}&lines=80`);if(!s.ok)return;const o=await s.json();i&&n(o)}catch{}}l();const a=setInterval(l,Hw);return()=>{i=!1,clearInterval(a)}},[e]),t?r(dw,{data:t,onRefresh:()=>{},containerId:"detail-side",containerClass:"detail-side",idPrefix:"detail"}):r("aside",{id:"detail-side",class:"detail-side"})}function Jw({w:e}){const t=Qd(e);j(()=>{rr.value=e.target},[e.target]),j(()=>{e.pane_id&&(e.channel_unread||0)>0&&fetch(`/api/channel/clear-unread?pane_id=${encodeURIComponent(e.pane_id)}`,{method:"POST"})},[e.pane_id,e.channel_unread]),j(()=>(qs(c=>{let p=c,d=null;const f=p.match(/^(.*?):(\d+)$/);f&&(p=f[1],d=f[2]),kr({path:p,line:d})}),()=>qs(null)),[e.target]),j(()=>{const c=document.getElementById("detail-pane-header"),p=document.getElementById("detail-tab-bar"),d=document.getElementById("detail");if(!c||!d)return;const f=()=>d.style.setProperty("--detail-header-h",`${c.offsetHeight+((p==null?void 0:p.offsetHeight)||0)}px`);f();const h=new ResizeObserver(f);return h.observe(c),p&&h.observe(p),()=>h.disconnect()},[e.target]),j(()=>{if(t!=="terminal")return;const c=requestAnimationFrame(()=>requestAnimationFrame(vi));return()=>cancelAnimationFrame(c)},[t]);const[n,i]=B(!0);j(()=>{if(t!=="terminal")return;const c=()=>i(D1());c();const p=setInterval(c,250);return()=>clearInterval(p)},[t,e.pid]);const l=te(e.state);j(()=>{const c=l.current==="working",p=e.state==="idle"||e.state==="done";if(c&&p&&e.agent){const d=document.getElementById("detail-xterm");d&&(d.classList.add("bell-pulse"),setTimeout(()=>d.classList.remove("bell-pulse"),400))}l.current=e.state},[e.state,e.agent]);const a=Ne.value[e.pid]||[],s=Re.value[e.pid]||"pane",o=s==="pane",u=e.track_name||_e(e);return r("div",{id:"detail-pane",class:"detail-pane",children:[r(Vw,{w:e}),r("div",{id:"detail-tab-bar",class:"detail-tab-bar",children:[r(Ww,{pid:e.pid,paneLabel:u}),e.agent==="claude"&&r(Uw,{mode:t,onMode:c=>{ye("view.switch",{view:c}),Ul(e.pid,c)}})]}),r("div",{class:"detail-pane-body",children:[r("div",{class:"detail-term-host",style:o&&t==="terminal"?"display:contents":"display:none",children:r(_w,{id:"detail-xterm",class:"detail-xterm",target:e.pane_id,agent:e.agent,onPaste:Kw},e.pid)}),r("div",{class:"detail-changes-host",style:s==="changes"?"display:contents":"display:none",children:r(Kk,{target:e.target,active:s==="changes",gitSig:e.git||""})}),a.map(c=>{const p=`file:${c.path}`,d=s===p;return r("div",{class:"detail-preview-host",style:d?"display:contents":"display:none",children:r(fw,{entry:c,active:d})},p)}),!bi.value&&r(Gw,{target:e.target},e.target),!bi.value&&r(Jd,{which:"side"})]}),o&&t==="terminal"&&!n&&r("button",{class:"term-scroll-bottom",title:"Scroll to latest",onClick:vi,children:"⤓"}),o&&t==="terminal"&&r(xw,{})]})}function $l(){return r("div",{id:"detail-empty",class:"detail-empty",children:r("div",{class:"detail-empty-card",children:r("p",{children:["Select a tab on the left, or"," ",r("button",{id:"detail-empty-add",onClick:()=>{var e;return(e=window.__periscopeOpenOmnibox)==null?void 0:e.call(window)},children:"+ open"})," ","to add one."]})})})}function Qw(){var d,f;const e=ke.value,t=ce.value||[],n=!!e&&e.startsWith("pane:"),i=!!e&&e.startsWith("review:"),l=e==="reviews";let a=null;if(i){const[h,m]=(()=>{const b=e.slice(7),x=b.indexOf("/");return x<0?[b,""]:[b.slice(0,x),b.slice(x+1)]})();a=(gt.value||[]).find(b=>b.repo===h&&b.slug===m)||null}j(()=>{(i||l)&&(rr.value=null)},[e]);const s=n?Go(e.slice(5)):null,o=te(new Set);n&&(s==null?void 0:s.agent)==="claude"&&o.current.add(s.pid);const u=new Set(t.map(h=>h.pid)),c=Qd(s);for(const h of[...o.current])if(!(n&&(s==null?void 0:s.pid)===h)&&!u.has(h)&&(o.current.delete(h),Ft.value[h])){const{[h]:b,...x}=Ft.value;Ft.value=x}const p=[...o.current];return r("section",{id:"detail",children:[!e&&r($l,{}),n&&(s?r(Jw,{w:s}):r($l,{})),l&&r(yw,{}),i&&(gt.value===null?r("div",{class:"wt-empty",children:"loading…"}):a?r(vw,{repo:a.repo,branch:a.branch,pr:a.pr,sig:`${(d=a.walkthrough)==null?void 0:d.head}|${(f=a.walkthrough)==null?void 0:f.stale_by}|${a.unresolved}|${a.comments}`},`${a.repo}/${a.branch}`):r($l,{})),p.map(h=>{const m=Go(h),b=n&&(s==null?void 0:s.pid)===h,x=(Re.value[h]||"pane")==="pane";return r("div",{class:"detail-transcript-host",style:b&&x&&c==="transcript"?"display:flex":"display:none",children:r(jw,{target:m==null?void 0:m.target,pid:h,selected:b,state:m==null?void 0:m.state,waitingFor:m==null?void 0:m.waiting_for,spinner:m==null?void 0:m.spinner})},`tr:${h}`)})]})}function Cl(e,t){return t==="all"?!0:t==="needs-input"?e.state==="needs-input":t==="working"?e.state==="working":t==="done"?e.state==="done":t==="idle"?e.state==="idle":t==="agents"?!!e.agent:t==="shell"?e.state==="shell":t==="ci-bad"?e.ci==="✗":!0}const ia=H(!1);function Tl(e,t,n,i=l=>l.key){const l=e||[];if(!n||!t)return l;const a=new Map(l.map(s=>[i(s),s]));return t.map(s=>a.get(i(s))||s)}function El(e,t,n,i=l=>l.key){if(!n||!t)return!1;const l=(e||[]).map(i),a=t.map(i);if(l.length!==a.length)return!0;const s=new Set(a);return l.some(o=>!s.has(o))}function Yw(e,t){return!!t&&!!(e!=null&&e.branch)}function Zw(e,t){return`open ${e!=null&&e.branch?`${e.branch} `:""}worktree in ${t}`}const Xw=900;function Xa(e){return e==="needs-input"?"dot dot-alert dot-pulse":e==="working"?"dot dot-green":e==="done"?"dot dot-blue dot-pulse-done":e==="idle"?"dot dot-grey":"dot dot-none"}function ev(e){return e==="✓"?"ok":e==="✗"?"bad":e==="⟳"?"running":"neutral"}function tv(e){return e?e.replace(/\s*\(.*$/,"").trim():null}function nv(e){return`${Math.round(e/1e3)}k`}function Nn(e){return e.context_pct!=null?`${e.context_pct}%`:e.ctx_tokens!=null?nv(e.ctx_tokens):null}function Yd({label:e,kind:t,renameable:n,onCommit:i}){const[l,a]=B(!1),s=te(null),o=te(!1);j(()=>{l&&s.current&&(s.current.focus(),s.current.select())},[l]);function u(d){n&&(d.preventDefault(),d.stopPropagation(),o.current=!1,a(!0))}function c(d){if(o.current)return;o.current=!0,a(!1);const f=(d||"").trim();f&&f!==e&&i(f)}function p(){o.current||(o.current=!0,a(!1))}return l?r("span",{class:"rail-label",children:r("input",{ref:s,type:"text",class:"rail-rename-input",defaultValue:e,spellcheck:!1,onClick:d=>d.stopPropagation(),onKeyDown:d=>{d.stopPropagation(),d.key==="Enter"?(d.preventDefault(),c(d.currentTarget.value)):d.key==="Escape"&&(d.preventDefault(),p())},onBlur:d=>c(d.currentTarget.value)})}):r("span",{class:"rail-label",onDblClick:n?u:void 0,children:t==="pane"?e:r("b",{children:e})})}function rv({w:e,chip:t,selectedKey:n,onSelect:i,onClose:l,onRename:a,dim:s,dragProps:o,dropPos:u,pinned:c,onTogglePin:p,awaitingSince:d,onMoveAccount:f,onToggleNamePin:h,editor:m,onOpenInEditor:b}){const x=`pane:${e.pid}`,w=x===n,C=w||e.state==="needs-input",y=e.agent?e.state||"idle":"shell",g=s?"":" rail-dim",$=u?" drop-target":"",v=_e(e),E=e.agent||(e.is_claude?"claude":null),M=ql[E],T=e.status_rail||e.status_line,S=e.status_at&&Math.floor(Date.now()/1e3)-e.status_at>Xw,R=tv(e.model),F=e.pr?lr(e.repo_slug,e.pr):null,q=fu(e.mem),L=d?vu(d,Math.floor(Date.now()/1e3)):null,I=Ch(e),O=Ui(e.pr_state),Q=`PR #${e.pr}${O.suffix}`,A=r(K,{children:["#",e.pr,e.ci&&!O.cls?r("span",{class:`pane-ci pane-ci-${ev(e.ci)}`,children:[" ",e.ci]}):null]}),z=e.pr&&(F?r("a",{class:`pane-pill pane-pill-pr ${O.cls}`,href:F,target:"_blank",rel:"noopener",onClick:X=>X.stopPropagation(),title:Q,children:A}):r("span",{class:`pane-pill pane-pill-pr ${O.cls}`,title:Q,children:A})),k=vr(e),W=k&&r("a",{class:"pane-pill pane-pill-linear",href:k.href,target:"_blank",rel:"noopener",onClick:X=>X.stopPropagation(),title:k.tip,children:k.id}),Z=e.account&&e.account!=="default"&&($n()||e.account==="unknown")&&r("span",{class:"pane-pill pane-pill-acct",title:`running on Claude account ${yn(e.account)} — its usage bills that subscription`,children:["@",yn(e.account)]}),_=e.profile&&e.profile!=="default"&&r("span",{class:"rail-profile",title:`running the ${To(e.profile)} profile — a different plugin set and system prompt than a normal pane`,children:To(e.profile)});return r("div",{class:`rail-row child-row pane-row pane-state-${y}${C?" pane-expanded":""}${w?" selected":""}${g}${$}`,"data-drop-pos":u||void 0,draggable:!0,onClick:()=>i(x),...o,children:[r("span",{class:"pane-stripe","aria-hidden":"true"}),r("div",{class:"pane-row-main",children:[M?r("span",{class:`rail-icon ${M.className}`,title:M.label,children:M.glyph}):r("span",{class:"rail-icon icon-shell",children:"$"}),r(Yd,{label:v,kind:"pane",renameable:!0,onCommit:a}),C?R&&r("span",{class:"pane-model",title:e.model,children:R}):Nn(e)!=null&&r("span",{class:`pane-mini-ctx${Vl(e)}`,title:e.ctx_hint||"context window used",children:Nn(e)}),q&&r("span",{class:`rail-mem ${q.cls}`,title:q.title,children:["↻",q.label]}),L&&r("span",{class:`rail-await wait-${L}`,title:`asked you something ${Pe(d)} ago and has had no reply since`,children:["⚠",Pe(d)]}),c&&r("span",{class:"pane-pin-flag",title:"pinned",children:"★"})]}),(t||T||!C&&(z||W||Z||_))&&r("div",{class:`rail-meta${S?" stale":""}`,children:[t&&r("span",{class:"rail-chip",title:e.cwd,children:["⧉ ",t]}),T&&r("span",{class:"rail-status",title:e.status_line,children:T}),!C&&(z||W||Z||_)&&r("span",{class:"rail-chips",children:[z,W,Z,_]})]}),C&&(e.pr||k||Nn(e)!=null||Z||_)&&r("div",{class:"pane-foot",children:[z,W,r("span",{class:"pane-foot-spacer"}),Z,_,Nn(e)!=null&&r("span",{class:`pane-pill pane-pill-ctx${Vl(e)}`,title:e.ctx_hint||"context window used",children:Nn(e)}),e.status_at?r("span",{class:"pane-time",children:Pe(e.status_at)}):null]}),r("div",{class:"pane-actions",children:[I&&r("button",{class:"rail-move-acct",title:`re-open this session on Claude account ${I.label} — spawns a resumed pane there and leaves this one running`,onClick:X=>{X.stopPropagation(),f==null||f(I.id)},children:["→ ",I.label]}),r("button",{class:`rail-pin${c?" pinned":""}`,title:c?"unpin":"pin",onClick:X=>{X.stopPropagation(),p==null||p()},children:c?"★":"☆"}),r("button",{class:`rail-name-pin${e.name_pinned?" pinned":""}`,title:e.name_pinned?"name pinned — click to let periscope rename this tab again":"freeze this name — periscope won't rename this tab",onClick:X=>{X.stopPropagation(),h==null||h()},children:e.name_pinned?"🔒":"🔓"}),Yw(e,m)&&r("button",{class:"rail-editor",title:Zw(e,m),onClick:X=>{X.stopPropagation(),b==null||b()},children:"↗"}),r("button",{class:"rail-close",title:"kill this tab",onClick:X=>{X.stopPropagation(),l()},children:"×"})]})]})}function iv({worktreeKey:e,onOpen:t}){return r("div",{class:"rail-row child-row newtab-row last-in-worktree",onClick:()=>t(e),children:[r("span",{class:"rail-icon",children:"+"}),r("span",{class:"rail-label",children:"New tab"})]})}function lv({label:e,collapsed:t,childCount:n,rolledUp:i,dim:l,onToggle:a,dragProps:s,dropPos:o}){return r("div",{class:`rail-row wt-row${l?"":" rail-dim"}${o?" drop-target":""}`,"data-drop-pos":o||void 0,draggable:!0,onClick:d=>{d.target.closest("button")||d.target.closest("input")||a()},...s,children:[r("span",{class:"rail-chev",children:t?"▸":"▾"}),r("span",{class:"rail-icon icon-worktree",children:"⎇"}),r("span",{class:"rail-label",children:r("b",{children:e})}),t&&n>0?r("span",{class:"rail-count",children:n}):null,r("span",{class:Xa(i)})]})}function Jo({row:e,selectedKey:t,onSelect:n}){var s;const i=`review:${e.repo}/${e.slug}`,l=i===t?" selected":"",a=((s=e.walkthrough)==null?void 0:s.stale_by)>0;return r("div",{class:`rail-row child-row rail-review${l}`,onClick:()=>n(i),children:[r("span",{class:"rail-icon icon-review",children:"◉"}),r("span",{class:"rail-label",children:["review · ",e.walkthrough.stops," stop",e.walkthrough.stops===1?"":"s",a?" · stale":""]}),e.unresolved?r("span",{class:"rail-review-badge",children:e.unresolved}):null]})}function av({kind:e,label:t,collapsed:n,rolledUp:i,dim:l,onToggle:a,onRename:s,onDissolve:o,onTeardown:u,dragProps:c,dropPos:p}){const d=n?"▸":"▾",f=l?"":" rail-dim",h=p?" drop-target":"",[m,b]=B(!1),x=e==="loose"||e==="repo",w=e==="goal"?"⧉":"🗀";return j(()=>{if(!m)return;const C=g=>{g.target.closest(".track-menu")||b(!1)},y=g=>{g.key==="Escape"&&b(!1)};return document.addEventListener("click",C,!0),document.addEventListener("keydown",y),()=>{document.removeEventListener("click",C,!0),document.removeEventListener("keydown",y)}},[m]),r("div",{class:`rail-row repo-row${f}${h}`,"data-drop-pos":p||void 0,draggable:!0,onClick:C=>{C.target.closest("button")||C.target.closest("input")||a()},...c,children:[r("span",{class:"rail-chev",children:d}),r("span",{class:"rail-icon icon-effort",title:e==="goal"?"track":"project",children:w}),r(Yd,{label:t,kind:"track",renameable:e!=="loose",onCommit:s}),r("span",{class:"repo-rule","aria-hidden":"true"}),r("span",{class:Xa(i)}),!x&&r("span",{class:"track-menu",children:[r("button",{class:"rail-track-menu-btn",title:"track actions",onClick:C=>{C.stopPropagation(),b(y=>!y)},children:"⋯"}),m&&r("div",{class:"track-menu-pop",onClick:C=>C.stopPropagation(),children:[r("button",{class:"track-menu-item",onClick:()=>{b(!1),o()},children:["Dissolve ",r("span",{class:"track-menu-hint",children:"tabs survive"})]}),r("button",{class:"track-menu-item track-menu-danger",onClick:()=>{b(!1),u()},children:["Tear down ",r("span",{class:"track-menu-hint",children:"kills tabs"})]})]})]})]})}function an({icon:e,label:t,count:n,collapsed:i,onToggle:l,tone:a}){return r("div",{class:`rail-row section-header${a==="alert"?" section-header-alert":a==="ready"?" section-header-ready":a==="working"?" section-header-working":""}`,onClick:l,children:[r("span",{class:"rail-chev",children:i?"▸":"▾"}),e?r("span",{class:"section-header-icon",children:e}):null,r("span",{class:"section-header-label",children:t}),n!=null&&n>0?r("span",{class:"section-header-count",children:n}):null]})}function $t(e,t,n,i){const l=(e==null?void 0:e.session)||t||"",a=_e(e)||n||"";return`${i?i(l):l} · ${a}`}function Zd(e){const t=[...new Set((e||[]).map(n=>n.session).filter(Boolean))];return n=>hu(n,t)}function Hn(e,t){mu(e,!t)}function Zt(e){return`${e.kind}:${e.pid??e.id}`}function sv(){var M,T,S,R,F,q;me.value;const e=ce.value||[],t=Da.value||[],n=ir.value,i=ft.value,l=sr(),a=Zd(e),s=La(e,t,n,i),o=l["sec:needs"]===!0,u=wu(e,t,n,pt.value),c=l["sec:ready"]===!0,p=Su(e),d=l["sec:running"]===!0,f=c1(Ea(),e),h=l["sec:pinned"]===!0,m=ia.value,b=te(null),x=Tl(s,(M=b.current)==null?void 0:M.needs,m,Zt),w=Tl(u,(T=b.current)==null?void 0:T.ready,m,Zt),C=Tl(p,(S=b.current)==null?void 0:S.running,m,Zt),y=El(s,(R=b.current)==null?void 0:R.needs,m,Zt)||El(u,(F=b.current)==null?void 0:F.ready,m,Zt)||El(p,(q=b.current)==null?void 0:q.running,m,Zt);j(()=>{m||(b.current={needs:s,ready:u,running:p})});function g(){b.current=null}j(()=>{const L=Bs(ft.value,e,"needs-input");L.size!==ft.value.size&&(ft.value=L);const I=Bs(pt.value,e,"done");I.size!==pt.value.size&&(pt.value=I)},[ce.value]);function $(L){g();const I=new Set(n);I.add(L),ir.value=I}function v(L){g(),$u(L)}function E(L){g(),Tu(L)}return r(K,{children:[y&&r("div",{class:"attn-frozen",title:"Move the pointer out of the rail to apply",children:"updates paused"}),x.length>0&&r(K,{children:[r(an,{icon:"⚠",label:"NEEDS YOU",tone:"alert",count:a1(x),collapsed:o,onToggle:()=>Hn("sec:needs",o)}),!o&&x.map(L=>{var I;return L.kind==="live"?r("div",{class:"rail-row attn-row attn-needs",onClick:()=>v(L.w),children:[r("span",{class:"attn-dot dot dot-alert dot-pulse"}),r("span",{class:"attn-label",children:$t(L.w,null,null,a)}),r("span",{class:"attn-reason",children:Mg((I=L.w)==null?void 0:I.waiting_for)})]},`live:${L.pid}`):r("div",{class:"rail-row attn-row attn-needs attn-event",onClick:()=>jt(L.target),children:[r("span",{class:"attn-ico",children:"⚠"}),r("span",{class:"attn-label",children:$t(L.w,L.session,L.name,a)}),r("span",{class:"attn-reason",children:["need_human · ",Pe(L.ts)]}),r("button",{class:"attn-x",title:"dismiss",onClick:O=>{O.stopPropagation(),$(L.id)},children:"×"})]},`evt:${L.id}`)})]}),w.length>0&&r(K,{children:[r(an,{icon:"✓",label:"READY",tone:"ready",count:w.length,collapsed:c,onToggle:()=>Hn("sec:ready",c)}),!c&&w.map(L=>{var I;return L.kind==="live"?r("div",{class:"rail-row attn-row attn-ready",onClick:()=>E(L.w),children:[r("span",{class:"attn-dot dot dot-blue dot-pulse-done"}),r("span",{class:"attn-label",children:$t(L.w,null,null,a)}),r("span",{class:"attn-reason",children:Pe((I=L.w)==null?void 0:I.completed_at)})]},`rlive:${L.pid}`):r("div",{class:"rail-row attn-row attn-ready attn-event",onClick:()=>jt(L.target),children:[r("span",{class:"attn-ico",children:"✓"}),r("span",{class:"attn-label",children:$t(L.w,L.session,L.name,a)}),r("span",{class:"attn-reason",children:["done · ",Pe(L.ts)]}),r("button",{class:"attn-x",title:"dismiss",onClick:O=>{O.stopPropagation(),$(L.id)},children:"×"})]},`revt:${L.id}`)})]}),C.length>0&&r(K,{children:[r(an,{icon:"⟳",label:"RUNNING",tone:"working",count:C.length,collapsed:d,onToggle:()=>Hn("sec:running",d)}),!d&&C.map(L=>{var I;return r("div",{class:"rail-row attn-row attn-running",onClick:()=>at(L.w),children:[r("span",{class:"attn-dot dot dot-green"}),r("span",{class:"attn-label",children:$t(L.w,null,null,a)}),r("span",{class:"attn-reason",children:`${((I=L.w)==null?void 0:I.spinner)||"working"}…`})]},`run:${L.pid}`)})]}),f.length>0&&r(K,{children:[r(an,{icon:"★",label:"PINNED",count:f.length,collapsed:h,onToggle:()=>Hn("sec:pinned",h)}),!h&&f.map(L=>{var I,O;return r("div",{class:"rail-row attn-row attn-pinned",onClick:()=>at(L),children:[r("span",{class:`attn-ico ${((I=ql[L.agent])==null?void 0:I.className)||""}`,children:((O=ql[L.agent])==null?void 0:O.glyph)||"$"}),r("span",{class:"attn-label",children:$t(L,null,null,a)}),r("span",{class:Xa(L.state),style:"margin-left:auto"})]},`pin:${L.pid}`)})]})]})}function ov(){me.value;const e=Da.value||[],t=sr(),n=Zd(ce.value||[]),i=u1(e),l=t["sec:activity"]!==!1;return r(K,{children:[r(an,{label:"ACTIVITY",count:i.length||null,collapsed:l,onToggle:()=>Hn("sec:activity",l)}),!l&&i.map(a=>r("div",{class:`rail-row attn-row attn-activity attn-${a.kind}`,onClick:()=>jt(a.target),children:[r("span",{class:"attn-ico",children:a.kind==="done"?"✓":"•"}),r("span",{class:"attn-label",children:$t(null,a.session,a.name,n)}),r("span",{class:"attn-reason",children:Pe(a.ts)})]},`act:${a.id}`))]})}const cv="";function uv(e){const t=window.__periscopeOpenLauncher;typeof t=="function"&&t(e)}function dv(e,t){return!t||t==="all"?e:e.filter(n=>n.track_id===t)}function hv({live:e,scope:t,onScope:n}){const i=[],l=new Set;for(const a of e)a.track_id&&!l.has(a.track_id)&&(l.add(a.track_id),i.push(a.track_id));return i.length<2?null:r("div",{class:"rail-filter-chips",role:"tablist","aria-label":"filter by track",children:[r("button",{class:`rail-filter-chip${!t||t==="all"?" is-active":""}`,onClick:()=>n("all"),children:"all"}),i.map(a=>r("button",{class:`rail-filter-chip${t===a?" is-active":""}`,onClick:()=>n(a),title:Ci(a,e),children:Ci(a,e)},a))]})}let Qo=0;function fv(){if(Date.now()-Qo<5e3)return;const e=ce.value||[];if(e.length===0)return;Qo=Date.now();const t=Ya(e,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ar(),branchOrderByTrack:Ta()},Bt.value),n=gi(),i=ar(),l=t.trackOrder,a={};for(const u of l)a[u]=t.tabsByTrack[u]||[];if(JSON.stringify(l)===JSON.stringify(n)&&JSON.stringify(a)===JSON.stringify(i))return;const s=[...new Set(e.map(u=>u.track_id))],o=(Bt.value||[]).map(u=>u.id);$e({track_order:l,tabs_by_track:a},`sync live=${JSON.stringify(s)} registry=${JSON.stringify(o)} cached=${JSON.stringify(n)}`)}function Xd(e,t,n,i){if(t<0||n<0)return e;const[l]=e.splice(t,1);let a=n-(tA.id===i),{trackOrder:b,tabsByTrack:x,branchesByTrack:w,tabsByBranch:C}=Ya(u,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ar(),branchOrderByTrack:Ta()},m),y=sb(b,x,d,gt.value||[]);function g(A){if(A==="reviews"){Ra();return}if(A.startsWith("review:")){const z=A.slice(7),k=z.indexOf("/"),W=(gt.value||[]).find(Z=>Z.repo===z.slice(0,k)&&Z.slug===z.slice(k+1));W&&Eu(W.repo,W.branch);return}ke.value=A,ye("pane.focus",{key:A}),A.startsWith("pane:")&&yt({kind:"pane",pid:A.slice(5)})}function $(A){const z=sr()[A]===!0;mu(A,!z)}async function v(A){await Yn(`Close tab "${_e(A)}"? -This kills its tmux window.`,{okLabel:"Close",danger:!0})&&await ie("close tab",`/api/window?${nt(M.target)}`,{method:"DELETE"})}async function E(M,z,k=!1){const W=`/api/pane/move-account?pid=${encodeURIComponent(M.pid)}&account=${encodeURIComponent(z)}`+(k?"&force=1":""),{data:Z,error:_,reason:X,status:he}=await pr("move account",W,{method:"POST"});if(ye("api:move account",{path:W,method:"POST",ok:!!Z}),Z!=null&&Z.pid){ke.value=`pane:${Z.pid}`,gt({kind:"pane",pid:Z.pid});return}if(he===409&&!k&&(X!=null&&X.startsWith("session looks live"))){await Jn(`${_} +This kills its tmux window.`,{okLabel:"Close",danger:!0})&&await ie("close tab",`/api/window?${tt(A.target)}`,{method:"DELETE"})}async function E(A,z,k=!1){const W=`/api/pane/move-account?pid=${encodeURIComponent(A.pid)}&account=${encodeURIComponent(z)}`+(k?"&force=1":""),{data:Z,error:_,reason:X,status:he}=await gr("move account",W,{method:"POST"});if(ye("api:move account",{path:W,method:"POST",ok:!!Z}),Z!=null&&Z.pid){ke.value=`pane:${Z.pid}`,yt({kind:"pane",pid:Z.pid});return}if(he===409&&!k&&(X!=null&&X.startsWith("session looks live"))){await Yn(`${_} -Move anyway? The original pane stays open; if the session really is mid-turn, the two copies will interleave writes to one transcript.`,{okLabel:"Move anyway"})&&await E(M,z,!0);return}bn(`move account failed: ${X||"unknown error"}`,"bad",6e3)}async function A(M,z){M.target&&await ie("rename tab",`/api/rename?${nt(M.target)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:z})})}async function T(M){await ie("open in editor","/api/editor/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:M.pid})})}async function S(M){await ie("pin tab name","/api/name-pin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:M.pid,pinned:!M.name_pinned})})}async function R(M,z){await ie("rename track",`/api/tracks?track_id=${encodeURIComponent(M)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:z})})}async function F(M){await ie("dissolve track",`/api/tracks/dissolve?track_id=${encodeURIComponent(M)}`,{method:"POST"})}async function q(M,z){const k=(x[M]||[]).map(_=>d[_]).filter(Boolean).map(_=>Se(_)),W=k.length?` +Move anyway? The original pane stays open; if the session really is mid-turn, the two copies will interleave writes to one transcript.`,{okLabel:"Move anyway"})&&await E(A,z,!0);return}kn(`move account failed: ${X||"unknown error"}`,"bad",6e3)}async function M(A,z){A.target&&await ie("rename tab",`/api/rename?${tt(A.target)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:z})})}async function T(A){await ie("open in editor","/api/editor/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:A.pid})})}async function S(A){await ie("pin tab name","/api/name-pin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:A.pid,pinned:!A.name_pinned})})}async function R(A,z){await ie("rename track",`/api/tracks?track_id=${encodeURIComponent(A)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:z})})}async function F(A){await ie("dissolve track",`/api/tracks/dissolve?track_id=${encodeURIComponent(A)}`,{method:"POST"})}async function q(A,z){const k=(x[A]||[]).map(_=>d[_]).filter(Boolean).map(_=>_e(_)),W=k.length?` • ${k.join(` -• `)}`:"";await Jn(`Tear down track "${z}"? +• `)}`:"";await Yn(`Tear down track "${z}"? -This kills ${k.length} tab${k.length===1?"":"s"} (their tmux windows):${W}`,{okLabel:"Tear down",danger:!0})&&await ie("teardown track",`/api/tracks/teardown?track_id=${encodeURIComponent(M)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({delete_worktrees:!1})})}function L(M){return{onDragStart:z=>{e.current=M,Et.value={kind:M.kind},z.dataTransfer.effectAllowed="move",z.dataTransfer.setData("text/plain",M.key)},onDragOver:z=>{z.stopPropagation();const k=e.current;if(!k||k.key===M.key){n(null);return}if(!Jo(k,M)){n(null);return}const W=z.currentTarget.getBoundingClientRect(),Z=z.clientY-W.top>W.height/2;z.preventDefault(),z.dataTransfer.dropEffect="move",n({key:M.key,pos:Z?"after":"before"})},onDrop:async z=>{z.preventDefault(),z.stopPropagation();const k=e.current;if(n(null),Et.value=null,e.current=null,!k||k.key===M.key||!Jo(k,M))return;const W=z.currentTarget.getBoundingClientRect(),Z=z.clientY-W.top>W.height/2;if(k.kind==="track")await rv(k.key,M.key,Z);else{const _=M.kind==="track"?M.key.slice(6):M.trackKey;if(M.kind==="pane"&&k.trackKey===_)await iv(k.childKey,M.childKey,k.trackKey,Z);else{const X=d[k.childKey];X&&_&&await Go(X,_)}}},onDragEnd:()=>{n(null),Et.value=null,e.current=null}}}function I(M){return t&&t.key===M?t.pos:void 0}function O(M){const z=`card:${M}`;return{onDragOver:k=>{const W=e.current;!W||W.kind!=="pane"||W.trackKey===M||(k.preventDefault(),k.dataTransfer.dropEffect="move",n({key:z,pos:"into"}))},onDrop:async k=>{k.preventDefault();const W=e.current;if(n(null),Et.value=null,e.current=null,!W||W.kind!=="pane"||W.trackKey===M)return;const Z=d[W.childKey];Z&&await Go(Z,M)}}}function Q(M,z){return M.map(k=>d[k]).filter(Boolean).map(k=>r(Kw,{w:k,chip:J2(k),selectedKey:o,dim:xl(k,s),onSelect:g,onClose:()=>v(k),onRename:W=>A(k,W),onMoveAccount:W=>E(k,W),dragProps:L({kind:"pane",key:`pane:${k.pid}`,childKey:k.pid,trackKey:z}),dropPos:I(`pane:${k.pid}`),pinned:$a().includes(k.pid),onTogglePin:()=>Wg(k.pid),onToggleNamePin:()=>S(k),editor:Sc.value,onOpenInEditor:()=>T(k),awaitingSince:p.get(k.pid)},`pane:${k.pid}`))}return b.length===0?r("aside",{id:"rail","aria-label":"tracks rail",children:[r("div",{class:"rail-head",children:r("span",{children:"Tracks"})}),r("div",{class:"rail-empty",children:["No tmux windows found. Use ",r("code",{children:"+ new"})," to start one."]})]}):r("aside",{id:"rail","aria-label":"tracks rail",onMouseEnter:()=>{ta.value=!0},onMouseLeave:()=>{ta.value=!1},children:[r(Qw,{}),r(tv,{live:a,scope:i,onScope:l}),r(an,{label:"TRACKS",count:null,collapsed:f,onToggle:()=>$("sec:projects")}),!f&&b.map(M=>{const z=`track:${M}`,k=c[`repo:${M}`]===!0,W=w[M]||[],Z=W.length>=2,_=xi(M,u,h),X=x[M]||[],he=X.map(ce=>d[ce]).filter(Boolean),fe=he.map(ce=>ce.state||"shell"),qe=Co(fe),Ae=he.length===0||he.some(ce=>xl(ce,s));return r(av,{children:[r(Jw,{kind:V2(M,u,h),label:_,collapsed:k,rolledUp:qe,dim:Ae,onToggle:()=>$(`repo:${M}`),onRename:ce=>R(M,ce),onDissolve:()=>F(M),onTeardown:()=>q(M,_),dragProps:L({kind:"track",key:z}),dropPos:I(z)}),!k&&r("div",{class:`rail-group rail-track-card${I(`card:${M}`)?" drop-into":""}`,...O(M),children:[Z?W.map(ce=>{var Tn,_r;const Me=`${M}::${ce}`,vt=c[`wt:${Me}`]===!0,Gt=((Tn=C[M])==null?void 0:Tn[ce])||[],Zi=Q(Gt,M),Xi=Gt.map(Ce=>d[Ce]).filter(Boolean).map(Ce=>Ce.state||"shell"),vr=Gt.map(Ce=>d[Ce]).filter(Boolean).some(Ce=>xl(Ce,s));return r("div",{class:"rail-subgroup",children:[r(Gw,{label:ce===Zw?"(no branch)":ce,collapsed:vt,childCount:Gt.length,rolledUp:Co(Xi),dim:vr,onToggle:()=>$(`wt:${Me}`),dragProps:{},dropPos:void 0}),!vt&&r("div",{class:"rail-group-body",children:[(((_r=y[M])==null?void 0:_r[ce])||[]).map(Ce=>r(Ko,{row:Ce,selectedKey:o,onSelect:g},`review:${Ce.repo}/${Ce.slug}`)),Zi]})]},`wt:${Me}`)}):r(V,{children:[Object.values(y[M]||{}).flat().map(ce=>r("div",{class:"rail-group-body rail-review-head",children:r(Ko,{row:ce,selectedKey:o,onSelect:g})},`review:${ce.repo}/${ce.slug}`)),r("div",{class:"rail-group-body",children:Q(X,M)})]}),r("div",{class:"rail-group-body rail-track-newtab",children:r(Vw,{worktreeKey:M,onOpen:Xw},`newtab:${M}`)})]})]},z)}),r(Yw,{})]})}function av({children:e}){return r(V,{children:e})}function sv(){j(()=>{gk(),a1(),ok()},[]),j(()=>{document.body.dataset.view||(document.body.dataset.view="split")},[]);const e=ne(null);return j(()=>{const t=Object.values(qd).map(n=>{const i=Vt(()=>gw(Kg(n.pref)));return lt(()=>{var a,s;const l=i.value;l==null?(a=e.current)==null||a.style.removeProperty(n.cssVar):(s=e.current)==null||s.style.setProperty(n.cssVar,`${l}px`)})});return()=>{for(const n of t)n()}},[]),j(()=>lt(()=>{var t,n;(t=e.current)==null||t.toggleAttribute("data-rail-hidden",$u.value),(n=e.current)==null||n.toggleAttribute("data-side-hidden",mi.value)}),[]),r("div",{id:"split-view",ref:e,children:[r(lv,{}),r(Ud,{which:"rail"}),r(Bw,{})]})}function ov(){return r(V,{children:[r(A2,{}),r(sv,{}),r(Eb,{}),r(Sg,{}),r(B2,{})]})}async function cv(){await Hi(),ye("app.open"),lt(()=>{const t=document.documentElement.style;t.setProperty("--sans",ar("ui").stack),t.setProperty("--mono",ar("code").stack)});const e=Fg();(e==null?void 0:e.kind)==="pane"?ke.value=`pane:${e.pid}`:(e==null?void 0:e.kind)==="review"&&e.repo&&e.branch?ke.value=`review:${e.repo}/${e.branch.replace(/\//g,"--")}`:(e==null?void 0:e.kind)==="reviews"&&(ke.value="reviews"),hh(r(ov,{}),document.getElementById("app")),U1(),O2(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})}cv();var mv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function gv(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}let na=[],Qd=[];(()=>{let e="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let t=0,n=0;t>1;if(e=Qd[i])t=i+1;else return!0;if(t==n)return!1}}function Qo(e){return e>=127462&&e<=127487}const Yo=8205;function yv(e,t,n=!0,i=!0){return(n?Yd:dv)(e,t,i)}function Yd(e,t,n){if(t==e.length)return t;t&&Zd(e.charCodeAt(t))&&Xd(e.charCodeAt(t-1))&&t--;let i=Cl(e,t);for(t+=Zo(i);t=0&&Qo(Cl(e,s));)a++,s-=2;if(a%2==0)break;t+=2}else break}return t}function dv(e,t,n){for(;t>0;){let i=Yd(e,t-2,n);if(i=56320&&e<57344}function Xd(e){return e>=55296&&e<56320}function Zo(e){return e<65536?1:2}const ra="ͼ",Xo=typeof Symbol>"u"?"__"+ra:Symbol.for(ra),ia=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),ec=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class bv{constructor(t,n){this.rules=[];let{finish:i}=n||{};function l(s){return/^@/.test(s)?[s]:s.split(/,\s*/)}function a(s,o,u,c){let f=[],d=/^@(\w+)\b/.exec(s[0]),p=d&&d[1]=="keyframes";if(d&&o==null)return u.push(s[0]+";");for(let h in o){let m=o[h];if(/&/.test(h))a(h.split(/,\s*/).map(b=>s.map(x=>b.replace(/&/,x))).reduce((b,x)=>b.concat(x)),m,u);else if(m&&typeof m=="object"){if(!d)throw new RangeError("The value of a property ("+h+") should be a primitive value.");a(l(h),m,f,p)}else m!=null&&f.push(h.replace(/_.*/,"").replace(/[A-Z]/g,b=>"-"+b.toLowerCase())+": "+m+";")}(f.length||p)&&u.push((i&&!d&&!c?s.map(i):s).join(", ")+" {"+f.join(" ")+"}")}for(let s in t)a(l(s),t[s],this.rules)}getRules(){return this.rules.join(` -`)}static newName(){let t=ec[Xo]||1;return ec[Xo]=t+1,ra+t.toString(36)}static mount(t,n,i){let l=t[ia],a=i&&i.nonce;l?a&&l.setNonce(a):l=new hv(t,a),l.mount(Array.isArray(n)?n:[n],t)}}let tc=new Map;class hv{constructor(t,n){let i=t.ownerDocument||t,l=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&l.CSSStyleSheet){let a=tc.get(i);if(a)return t[ia]=a;this.sheet=new l.CSSStyleSheet,tc.set(i,this)}else this.styleTag=i.createElement("style"),n&&this.styleTag.setAttribute("nonce",n);this.modules=[],t[ia]=this}mount(t,n){let i=this.sheet,l=0,a=0;for(let s=0;s-1&&(this.modules.splice(u,1),a--,u=-1),u==-1){if(this.modules.splice(a++,0,o),i)for(let c=0;c",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},fv=typeof navigator<"u"&&/Mac/.test(navigator.platform),pv=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var be=0;be<10;be++)Wt[48+be]=Wt[96+be]=String(be);for(var be=1;be<=24;be++)Wt[be+111]="F"+be;for(var be=65;be<=90;be++)Wt[be]=String.fromCharCode(be+32),Ci[be]=String.fromCharCode(be);for(var Tl in Wt)Ci.hasOwnProperty(Tl)||(Ci[Tl]=Wt[Tl]);function kv(e){var t=fv&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||pv&&e.shiftKey&&e.key&&e.key.length==1||e.key=="Unidentified",n=!t&&e.key||(e.shiftKey?Ci:Wt)[e.keyCode]||e.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}export{ne as A,bv as S,Ji as _,tr as a,Wt as b,mv as c,B as d,hs as e,yv as f,gv as g,V as h,kv as k,gr as o,fr as r,Ci as s,r as u,j as y}; +This kills ${k.length} tab${k.length===1?"":"s"} (their tmux windows):${W}`,{okLabel:"Tear down",danger:!0})&&await ie("teardown track",`/api/tracks/teardown?track_id=${encodeURIComponent(A)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({delete_worktrees:!1})})}function L(A){return{onDragStart:z=>{e.current=A,Et.value={kind:A.kind},z.dataTransfer.effectAllowed="move",z.dataTransfer.setData("text/plain",A.key)},onDragOver:z=>{z.stopPropagation();const k=e.current;if(!k||k.key===A.key){n(null);return}if(!Zo(k,A)){n(null);return}const W=z.currentTarget.getBoundingClientRect(),Z=z.clientY-W.top>W.height/2;z.preventDefault(),z.dataTransfer.dropEffect="move",n({key:A.key,pos:Z?"after":"before"})},onDrop:async z=>{z.preventDefault(),z.stopPropagation();const k=e.current;if(n(null),Et.value=null,e.current=null,!k||k.key===A.key||!Zo(k,A))return;const W=z.currentTarget.getBoundingClientRect(),Z=z.clientY-W.top>W.height/2;if(k.kind==="track")await pv(k.key,A.key,Z);else{const _=A.kind==="track"?A.key.slice(6):A.trackKey;if(A.kind==="pane"&&k.trackKey===_)await mv(k.childKey,A.childKey,k.trackKey,Z);else{const X=d[k.childKey];X&&_&&await Yo(X,_)}}},onDragEnd:()=>{n(null),Et.value=null,e.current=null}}}function I(A){return t&&t.key===A?t.pos:void 0}function O(A){const z=`card:${A}`;return{onDragOver:k=>{const W=e.current;!W||W.kind!=="pane"||W.trackKey===A||(k.preventDefault(),k.dataTransfer.dropEffect="move",n({key:z,pos:"into"}))},onDrop:async k=>{k.preventDefault();const W=e.current;if(n(null),Et.value=null,e.current=null,!W||W.kind!=="pane"||W.trackKey===A)return;const Z=d[W.childKey];Z&&await Yo(Z,A)}}}function Q(A,z){return A.map(k=>d[k]).filter(Boolean).map(k=>r(rv,{w:k,chip:ab(k),selectedKey:o,dim:Cl(k,s),onSelect:g,onClose:()=>v(k),onRename:W=>M(k,W),onMoveAccount:W=>E(k,W),dragProps:L({kind:"pane",key:`pane:${k.pid}`,childKey:k.pid,trackKey:z}),dropPos:I(`pane:${k.pid}`),pinned:Ea().includes(k.pid),onTogglePin:()=>Qg(k.pid),onToggleNamePin:()=>S(k),editor:Ec.value,onOpenInEditor:()=>T(k),awaitingSince:f.get(k.pid)},`pane:${k.pid}`))}return b.length===0?r("aside",{id:"rail","aria-label":"tracks rail",children:[r("div",{class:"rail-head",children:r("span",{children:"Tracks"})}),r("div",{class:"rail-empty",children:["No tmux windows found. Use ",r("code",{children:"+ new"})," to start one."]})]}):r("aside",{id:"rail","aria-label":"tracks rail",onMouseEnter:()=>{ia.value=!0},onMouseLeave:()=>{ia.value=!1},children:[r(sv,{}),r(hv,{live:a,scope:i,onScope:l}),r(an,{label:"TRACKS",count:null,collapsed:p,onToggle:()=>$("sec:projects")}),!p&&b.map(A=>{const z=`track:${A}`,k=c[`repo:${A}`]===!0,W=w[A]||[],Z=W.length>=2,_=Ci(A,u,h),X=x[A]||[],he=X.map(ue=>d[ue]).filter(Boolean),fe=he.map(ue=>ue.state||"shell"),He=Po(fe),Ae=he.length===0||he.some(ue=>Cl(ue,s));return r(yv,{children:[r(av,{kind:ib(A,u,h),label:_,collapsed:k,rolledUp:He,dim:Ae,onToggle:()=>$(`repo:${A}`),onRename:ue=>R(A,ue),onDissolve:()=>F(A),onTeardown:()=>q(A,_),dragProps:L({kind:"track",key:z}),dropPos:I(z)}),!k&&r("div",{class:`rail-group rail-track-card${I(`card:${A}`)?" drop-into":""}`,...O(A),children:[Z?W.map(ue=>{var En,$r;const Me=`${A}::${ue}`,vt=c[`wt:${Me}`]===!0,Gt=((En=C[A])==null?void 0:En[ue])||[],tl=Q(Gt,A),nl=Gt.map(Ce=>d[Ce]).filter(Boolean).map(Ce=>Ce.state||"shell"),Sr=Gt.map(Ce=>d[Ce]).filter(Boolean).some(Ce=>Cl(Ce,s));return r("div",{class:"rail-subgroup",children:[r(lv,{label:ue===cv?"(no branch)":ue,collapsed:vt,childCount:Gt.length,rolledUp:Po(nl),dim:Sr,onToggle:()=>$(`wt:${Me}`),dragProps:{},dropPos:void 0}),!vt&&r("div",{class:"rail-group-body",children:[((($r=y[A])==null?void 0:$r[ue])||[]).map(Ce=>r(Jo,{row:Ce,selectedKey:o,onSelect:g},`review:${Ce.repo}/${Ce.slug}`)),tl]})]},`wt:${Me}`)}):r(K,{children:[Object.values(y[A]||{}).flat().map(ue=>r("div",{class:"rail-group-body rail-review-head",children:r(Jo,{row:ue,selectedKey:o,onSelect:g})},`review:${ue.repo}/${ue.slug}`)),r("div",{class:"rail-group-body",children:Q(X,A)})]}),r("div",{class:"rail-group-body rail-track-newtab",children:r(iv,{worktreeKey:A,onOpen:uv},`newtab:${A}`)})]})]},z)}),r(ov,{})]})}function yv({children:e}){return r(K,{children:e})}function bv(){j(()=>{Tk(),d1(),kk()},[]),j(()=>{document.body.dataset.view||(document.body.dataset.view="split")},[]);const e=te(null);return j(()=>{const t=Object.values(Gd).map(n=>{const i=Vt(()=>Tw(Yg(n.pref)));return it(()=>{var a,s;const l=i.value;l==null?(a=e.current)==null||a.style.removeProperty(n.cssVar):(s=e.current)==null||s.style.setProperty(n.cssVar,`${l}px`)})});return()=>{for(const n of t)n()}},[]),j(()=>it(()=>{var t,n;(t=e.current)==null||t.toggleAttribute("data-rail-hidden",Pu.value),(n=e.current)==null||n.toggleAttribute("data-side-hidden",bi.value)}),[]),r("div",{id:"split-view",ref:e,children:[r(gv,{}),r(Jd,{which:"rail"}),r(Qw,{})]})}function kv(){return r(K,{children:[r(j2,{}),r(bv,{}),r(Bb,{}),r(Pg,{}),r(Q2,{})]})}async function wv(){await Wi(),ye("app.open"),it(()=>{const t=document.documentElement.style;t.setProperty("--sans",or("ui").stack),t.setProperty("--mono",or("code").stack)});const e=Hg();(e==null?void 0:e.kind)==="pane"?ke.value=`pane:${e.pid}`:(e==null?void 0:e.kind)==="review"&&e.repo&&e.branch?ke.value=`review:${e.repo}/${e.branch.replace(/\//g,"--")}`:(e==null?void 0:e.kind)==="reviews"&&(ke.value="reviews"),yh(r(kv,{}),document.getElementById("app")),t0(),W2(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})}wv();var Cv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Tv(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}let la=[],th=[];(()=>{let e="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let t=0,n=0;t>1;if(e=th[i])t=i+1;else return!0;if(t==n)return!1}}function Xo(e){return e>=127462&&e<=127487}const ec=8205;function Ev(e,t,n=!0,i=!0){return(n?nh:_v)(e,t,i)}function nh(e,t,n){if(t==e.length)return t;t&&rh(e.charCodeAt(t))&&ih(e.charCodeAt(t-1))&&t--;let i=Pl(e,t);for(t+=tc(i);t=0&&Xo(Pl(e,s));)a++,s-=2;if(a%2==0)break;t+=2}else break}return t}function _v(e,t,n){for(;t>0;){let i=nh(e,t-2,n);if(i=56320&&e<57344}function ih(e){return e>=55296&&e<56320}function tc(e){return e<65536?1:2}const aa="ͼ",nc=typeof Symbol>"u"?"__"+aa:Symbol.for(aa),sa=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),rc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Pv{constructor(t,n){this.rules=[];let{finish:i}=n||{};function l(s){return/^@/.test(s)?[s]:s.split(/,\s*/)}function a(s,o,u,c){let p=[],d=/^@(\w+)\b/.exec(s[0]),f=d&&d[1]=="keyframes";if(d&&o==null)return u.push(s[0]+";");for(let h in o){let m=o[h];if(/&/.test(h))a(h.split(/,\s*/).map(b=>s.map(x=>b.replace(/&/,x))).reduce((b,x)=>b.concat(x)),m,u);else if(m&&typeof m=="object"){if(!d)throw new RangeError("The value of a property ("+h+") should be a primitive value.");a(l(h),m,p,f)}else m!=null&&p.push(h.replace(/_.*/,"").replace(/[A-Z]/g,b=>"-"+b.toLowerCase())+": "+m+";")}(p.length||f)&&u.push((i&&!d&&!c?s.map(i):s).join(", ")+" {"+p.join(" ")+"}")}for(let s in t)a(l(s),t[s],this.rules)}getRules(){return this.rules.join(` +`)}static newName(){let t=rc[nc]||1;return rc[nc]=t+1,aa+t.toString(36)}static mount(t,n,i){let l=t[sa],a=i&&i.nonce;l?a&&l.setNonce(a):l=new xv(t,a),l.mount(Array.isArray(n)?n:[n],t)}}let ic=new Map;class xv{constructor(t,n){let i=t.ownerDocument||t,l=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&l.CSSStyleSheet){let a=ic.get(i);if(a)return t[sa]=a;this.sheet=new l.CSSStyleSheet,ic.set(i,this)}else this.styleTag=i.createElement("style"),n&&this.styleTag.setAttribute("nonce",n);this.modules=[],t[sa]=this}mount(t,n){let i=this.sheet,l=0,a=0;for(let s=0;s-1&&(this.modules.splice(u,1),a--,u=-1),u==-1){if(this.modules.splice(a++,0,o),i)for(let c=0;c",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Sv=typeof navigator<"u"&&/Mac/.test(navigator.platform),$v=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var be=0;be<10;be++)Wt[48+be]=Wt[96+be]=String(be);for(var be=1;be<=24;be++)Wt[be+111]="F"+be;for(var be=65;be<=90;be++)Wt[be]=String.fromCharCode(be+32),Pi[be]=String.fromCharCode(be);for(var Al in Wt)Pi.hasOwnProperty(Al)||(Pi[Al]=Wt[Al]);function Av(e){var t=Sv&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||$v&&e.shiftKey&&e.key&&e.key.length==1||e.key=="Unidentified",n=!t&&e.key||(e.shiftKey?Pi:Wt)[e.keyCode]||e.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}export{te as A,Pv as S,Zi as _,rr as a,Wt as b,Cv as c,B as d,ms as e,Ev as f,Tv as g,K as h,Av as k,kr as o,mr as r,Pi as s,r as u,j as y}; diff --git a/static/src/__tests__/agent.test.js b/static/src/__tests__/agent.test.js index 90170713..43f877f0 100644 --- a/static/src/__tests__/agent.test.js +++ b/static/src/__tests__/agent.test.js @@ -31,7 +31,7 @@ describe("agent presentation", () => { it("keeps Codex in terminal mode without Claude-only header controls", () => { const w = { agent: "codex", pid: "codex-1", target: "dev:1", state: "idle", - mem: { rss_gb: 4, age_s: 86400 }, + mem: { tier: "bad", trigger: "mem", gb: 4, age_s: 86400 }, }; expect(computeMode(w)).toBe("terminal"); const html = render(h(PaneHeader, { w })); diff --git a/static/src/__tests__/memHint.test.js b/static/src/__tests__/memHint.test.js index 41ff6d93..d302f99a 100644 --- a/static/src/__tests__/memHint.test.js +++ b/static/src/__tests__/memHint.test.js @@ -8,16 +8,16 @@ describe("memHint", () => { expect(memHint(undefined)).toBeNull(); }); - it("rss-tripped tier leads with gigabytes", () => { - const h = memHint({ tier: "bad", rss_gb: 4.2, age_s: 2 * 86400 + 5 * 3600 }); + it("a footprint trip leads with gigabytes", () => { + const h = memHint({ tier: "bad", trigger: "mem", gb: 4.2, age_s: 2 * 86400 + 5 * 3600 }); expect(h.label).toBe("4.2G"); expect(h.cls).toBe("mem-bad"); expect(h.title).toContain("4.2GB"); expect(h.title).toContain("2d 5h"); }); - it("age-only trip leads with uptime days", () => { - const h = memHint({ tier: "warn", rss_gb: 0.5, age_s: 3 * 86400 }); + it("an age trip leads with uptime days", () => { + const h = memHint({ tier: "warn", trigger: "age", gb: 0.5, age_s: 3 * 86400 }); expect(h.label).toBe("3d"); expect(h.cls).toBe("mem-warn"); }); diff --git a/static/src/__tests__/paneHeaderRes.test.js b/static/src/__tests__/paneHeaderRes.test.js new file mode 100644 index 00000000..0dd87171 --- /dev/null +++ b/static/src/__tests__/paneHeaderRes.test.js @@ -0,0 +1,24 @@ +// The detail header's "6.8G mem · 58% cpu" part: the selected pane's whole +// process tree (the row's `res`). +import { h } from "preact"; +import render from "preact-render-to-string"; +import { describe, expect, it } from "vitest"; +import { PaneHeader } from "../split/Detail.jsx"; + +const base = { pid: "p1", target: "dev:1", state: "shell" }; + +describe("PaneHeader resources", () => { + it("labels memory and CPU", () => { + const html = render(h(PaneHeader, { w: { ...base, res: { mem_mb: 6963, cpu_pct: 57.6 } } })); + expect(html).toContain("6.8G mem · 58% cpu"); + }); + + it("shows a dash before the server has two samples", () => { + const html = render(h(PaneHeader, { w: { ...base, res: { mem_mb: 300, cpu_pct: null } } })); + expect(html).toContain("300M mem · – cpu"); + }); + + it("shows nothing without a measurement", () => { + expect(render(h(PaneHeader, { w: { ...base, res: null } }))).not.toContain("header-res"); + }); +}); diff --git a/static/src/chrome/FilterBar.jsx b/static/src/chrome/FilterBar.jsx index 10d1cfee..48fbeecc 100644 --- a/static/src/chrome/FilterBar.jsx +++ b/static/src/chrome/FilterBar.jsx @@ -8,8 +8,8 @@ // dropdown's open/close + outside-click + Escape mechanics mirror app.js's // openDropdown/closeDropdown, but Escape goes through the LIFO useEscape hook // instead of the old pushEscape/popEscape registry. -import { useCallback, useEffect, useRef, useState } from "preact/hooks"; -import { useEscape } from "../hooks/useEscape.js"; +import { useCallback, useRef, useState } from "preact/hooks"; +import { usePopoverDismiss } from "../hooks/usePopoverDismiss.js"; import { currentFilter } from "../store.js"; import { track } from "../track.js"; @@ -31,19 +31,7 @@ export function FilterBar() { const activeLabel = (FILTERS.find((f) => f.key === active) || FILTERS[0]).label; const close = useCallback(() => setOpen(false), []); - useEscape(close, open); - - // Outside-click closes the menu. Deferred-attach isn't needed here because - // the toggle's onClick stops propagation, so the opening click never - // reaches this document listener. - useEffect(() => { - if (!open) return; - function onDocClick(e) { - if (ddRef.current && !ddRef.current.contains(e.target)) setOpen(false); - } - document.addEventListener("click", onDocClick); - return () => document.removeEventListener("click", onDocClick); - }, [open]); + usePopoverDismiss(ddRef, open, close); function pick(key) { currentFilter.value = key; diff --git a/static/src/chrome/Header.jsx b/static/src/chrome/Header.jsx index 774543d4..0a55cf75 100644 --- a/static/src/chrome/Header.jsx +++ b/static/src/chrome/Header.jsx @@ -14,13 +14,14 @@ // those surfaces while only chrome is Preact-mounted. import { useCallback, useEffect, useRef, useState } from "preact/hooks"; import { multiAccount } from "../accounts.js"; -import { useEscape } from "../hooks/useEscape.js"; +import { usePopoverDismiss } from "../hooks/usePopoverDismiss.js"; import { unresolvedTotal } from "../review/walkthrough.js"; import { selectReviewsQueue } from "../split/alertFeed.js"; import { reviews, windows } from "../store.js"; import { track } from "../track.js"; import { FilterBar } from "./FilterBar.jsx"; import { PanelToggles } from "./PanelToggles.jsx"; +import { ResourcePill } from "./ResourcePill.jsx"; import { SpawnAccountPicker } from "./SpawnAccountPicker.jsx"; import { SpawnEffortPicker } from "./SpawnEffortPicker.jsx"; import { SpawnModelPicker } from "./SpawnModelPicker.jsx"; @@ -34,15 +35,7 @@ function Dropdown({ id, toggleClass, toggleLabel, title, children }) { const [open, setOpen] = useState(false); const ref = useRef(null); const close = useCallback(() => setOpen(false), []); - useEscape(close, open); - useEffect(() => { - if (!open) return; - function onDocClick(e) { - if (ref.current && !ref.current.contains(e.target)) setOpen(false); - } - document.addEventListener("click", onDocClick); - return () => document.removeEventListener("click", onDocClick); - }, [open]); + usePopoverDismiss(ref, open, close); return (
+ ); + } + return
{children}
; +} + +// The popover's open state lives here, not in , so a tick with +// no measurement (the pill vanishing) unmounts this and discards it — no +// separate close-when-hidden effect needed. +function ResourcePopover({ r }) { + const ref = useRef(null); + const btnRef = useRef(null); + const [open, setOpen] = useState(false); + const close = useCallback(() => { + // Hiding the menu drops focus to unless it moves first — send it + // back to the pill when a menu item or the pane list had it. + const hadFocus = ref.current?.contains(document.activeElement); + setOpen(false); + if (hadFocus) btnRef.current?.focus(); + }, []); + usePopoverDismiss(ref, open, close); + + return ( +
+ + +
+ ); +} + +export function ResourcePill() { + const r = resources.value; + return r && ; +} diff --git a/static/src/chrome/UpdatePill.jsx b/static/src/chrome/UpdatePill.jsx index b02aad88..06c8f70a 100644 --- a/static/src/chrome/UpdatePill.jsx +++ b/static/src/chrome/UpdatePill.jsx @@ -28,7 +28,7 @@ // property"). Warn, don't block. import { signal } from "@preact/signals"; import { useCallback, useEffect, useRef, useState } from "preact/hooks"; -import { useEscape } from "../hooks/useEscape.js"; +import { usePopoverDismiss } from "../hooks/usePopoverDismiss.js"; import { renderMarkdown } from "../split/markdown.jsx"; import { updateInfo } from "../store.js"; import { apiCall, plural } from "../util.js"; @@ -78,15 +78,7 @@ export function UpdatePill() { const ref = useRef(null); const goRef = useRef(null); const close = useCallback(() => { popoverOpen.value = false; }, []); - useEscape(close, open); - useEffect(() => { - if (!open) return; - function onDocClick(e) { - if (ref.current && !ref.current.contains(e.target)) setOpen(false); - } - document.addEventListener("click", onDocClick); - return () => document.removeEventListener("click", onDocClick); - }, [open]); + usePopoverDismiss(ref, open, close); const info = updateInfo.value; const behind = info?.behind || 0; const ahead = info?.ahead || 0; @@ -183,7 +175,7 @@ export function UpdatePill() { : `${behindText} — click to see what's new`; return ( -
+