From 7447008cbb1b20f2d626692323cd5e1057c7a0c9 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 19:55:46 -0400 Subject: [PATCH 01/52] =?UTF-8?q?docs(specs):=20resource=20monitor=20desig?= =?UTF-8?q?n=20=E2=80=94=20footprint=20and=20CPU=20per=20session,=20server?= =?UTF-8?q?=20and=20webview=20(THI-448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) --- .../2026-10-30-resource-monitor-design.md | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 docs/superpowers/specs/2026-10-30-resource-monitor-design.md 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..6cdfc509 --- /dev/null +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -0,0 +1,132 @@ +# Resource monitor + +The dashboard shows how much memory and CPU each owner uses (agent sessions, the periscope server, its webview) +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 | +|---|---|---| +| Machine (16 GB RAM, 10 cores) | ~48 GB; 16.5 of 17.4 GB swap used | load avg 50–70 | +| Agent sessions, whole pane subtrees | 12.8 GB | 112% | +| ↳ heaviest pane | 6.8 GB, mostly `tsc`/`prettier`/`eslint`; its claude 446 MB | 58% | +| Webview (WebKit `WebContent`) | 2.9 GB, peaked at 7.7 GB the same day | ~40% | +| Periscope server + tmux control clients | 176 MB | ~7% | + +`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. `proc_pid_rusage` read footprint and CPU time for 6 pids in ~1 ms without a fork, and +its CPU deltas matched `top`. + +## Scope + +In: measurement, the header pill and popover, the detail-header numbers, the webview through the shell. +Out, each its own later PR: dashboard freshness (`build_state` time, `/ws/state` frame gap), a 1 h history, a +"recycle pending" marker for the webview. THI-449 (recycle gate) 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; RSS hides exactly the pressure this +feature exists to show. CPU% is per core like `top` (100% = one core), computed over the interval since the previous +sample of the same process. Called through `ctypes` on `/usr/lib/libproc.dylib` with the `RUSAGE_INFO_V0` flavor +(the struct the shell binds in `recycle.rs`); CPU times are mach absolute units, scaled by `mach_timebase_info`. +Stdlib only, so `uv run server.py`'s PEP-723 header doesn't change. + +**D2 — Measurement runs inside `build_state`, once per hub tick, and adds no subprocess.** It reuses the process +table (`session_status.proc_table()`) and the tmux pane roots (`_tmux_pane_pids()`) that each tick already forks +for; the pane roots get cached alongside `pane_claude_pids()`'s result so they are read, not re-forked. A tick +costs ~0.2 ms per process for the `proc_pid_rusage` calls (~25 ms at today's ~120 processes in pane subtrees). A +separate sampler thread was rejected: it would need its own process table (another `ps`, or a larger `libproc` +binding) and a thread under `docs/testing.md`'s rules, for steadier CPU windows nobody asked for yet. + +**D3 — A process is identified by (pid, start time).** The previous CPU sample is keyed by the pair, using +`ri_proc_start_abstime` from the same struct, so a recycled pid starts a fresh delta instead of reporting the +difference between two unrelated processes. A process seen for the first time has no CPU% yet; it counts as 0 in +sums. Entries for processes absent from a tick are dropped. + +**D4 — A session's numbers cover the pane's whole process subtree.** Rooted at the pane's `pane_pid`, walked with +the same `proc_table()` children map `pane_claude_pids()` uses. The claude process alone undercounts a busy session +(446 MB against 6.8 GB above). `sessions` is the total over every tmux pane, including panes that run no agent. + +**D5 — The periscope server is its own process plus its children.** That covers the tmux control-mode clients and +whatever `git`/`gh`/`ps` is running at that instant. The tmux server is not counted anywhere: it is shared, and it +measured 74 MB and 0.4%. + +**D6 — The webview is measured by the server from a pid the shell writes to a file.** The shell already reads the +`WebContent` pid every 60 s (`refresh_webcontent_pid`); it also writes it to `~/.config/periscope/webcontent.pid`, +next to `shell.log` and `zoom`. The server reads the file each tick and measures that pid itself, but only when the +file is less than 3 minutes old and `proc_pidpath` names a `com.apple.WebKit.WebContent` executable. Otherwise +`webview` is `null`: an older `.app`, a quit app, or a dashboard viewed in a browser tab all just omit the line. +The webview's `WebContent` has launchd as its parent and no sockets of its own (WebKit's networking process holds +them), so the server cannot find it without the shell. + +**D7 — The machine line reads the kernel directly, with no fork.** Load average from `os.getloadavg()`; swap used +and total from `sysctlbyname("vm.swapusage")`; free memory percent from `kern.memorystatus_level` (the figure +`memory_pressure` prints). + +**D8 — The ↻ cycle hint keeps watching the claude process alone, measured as footprint.** The leak it targets lives +in claude, not in its tool children. `mem_signal` reads footprint instead of RSS, the thresholds are renamed to +`MEM_BAD_FOOTPRINT_KB` / `MEM_WARN_FOOTPRINT_KB` and keep their values (4 GB / 2 GB), and the chip's `rss_gb` becomes +`mem_gb`. Today's claudes sit at 250–550 MB of footprint, so nothing new trips. `_claude_procs()` keeps its `ps` +call for liveness and age; moving that off `ps` belongs to THI-450. + +**D9 — Without `libproc` (not macOS), measurement is off.** One warning at first use; `res` and `resources` are +absent from `/api/state`, and the UI renders nothing for them. A pid that exits or refuses access between the +process table and the `proc_pid_rusage` call drops out of the sums; nothing in this path raises into `build_state`. + +## Server + +`periscope/resources.py` — stdlib only, no periscope imports, like `session_status`: + +- `usage(pids)` → `{pid: (footprint_bytes, cpu_ns, start)}` for the pids it could read. +- `sample(pids)` — reads `usage`, diffs against the previous sample per (pid, start), returns `{pid: (footprint_bytes, + cpu_pct)}`, and updates the stored samples. +- `subtree(root, kids)` → the root and all its descendants. +- `machine()` → `{load1, swap_used_mb, swap_total_mb, mem_free_pct}`. +- `webview_pid()` → the validated pid from D6, or `None`. + +`build_state` calls one function in `resources` that samples every pid it needs in a single pass (all pane +subtrees, the server subtree, the webview), then: + +- each window row gets `res: {mem_mb, cpu_pct}` for its pane's subtree; +- the blob gets `resources: {server, webview, sessions, machine}`, where `server`, `webview` and `sessions` are + `{mem_mb, cpu_pct}` (`webview` may be `null`) and `machine` is D7's dict. + +`/api/healthz` adds `resources: {server}` with the server's `{mem_mb, cpu_pct, children}`. It samples the server +subtree itself and shares the stored CPU samples with `build_state`. + +## Shell + +`recycle.rs`: after `refresh_webcontent_pid` stores a pid, write it to `~/.config/periscope/webcontent.pid` +(overwriting, so the mtime is the freshness signal), including right after a recycle rebuilds the webview. Failure +to write is ignored, like `shell_log`. `docs/tauri-shell.md` gains a sentence on the file. The change needs an `.app` +rebuild; until then D6's fallback applies. + +## UI + +- **Header pill** after `UsagePill`: `▣ 18.1G · 165%`, the sum of server, webview and sessions. Hidden when + `resources` is absent. +- **Popover** on click: periscope server, webview, then every session sorted by memory (a row selects its pane), + then the machine line: `load 52 · swap 16.5/17.4G · 27% free`. The CPU column's tooltip says 100% = one core. +- **Detail header**: a `· 6.8G · 58%` part after the context %, for the selected pane. +- Formatting (MB→`0.6G`/`512M`, percent rounding) and sorting go in a pure `static/src/chrome/resources.js`, tested + with vitest, the way `usageSummary.js` backs `UsagePill`. +- `memHint` reads `mem_gb`. + +## Tests + +- `tests/test_resources.py`: CPU% on a first sample (0), on a second, after a pid reuse (new start time → fresh + sample), and for a pid gone from the tick (dropped); subtree sums over a fake children map; `webview_pid` for a + missing file, a stale file, a pid whose path isn't `WebContent`, and a valid one; the no-`libproc` path. The + `proc_pid_rusage` call is behind one function the tests replace; one smoke test reads the test process itself. +- `tests/test_window_view.py`: `mem_signal` on footprint at each tier. +- `tests/routes/`: `/api/state` carries `res` and `resources`; `/api/healthz` carries `resources.server`. +- vitest: `resources.js` formatting and ordering; `memHint` with `mem_gb`. + +## Assumptions + +- Every process measured belongs to the user running periscope; `proc_pid_rusage` on a root-owned pid fails and the + pid is skipped (D9). Verified for claude, the server and `WebContent`. +- ~120 processes per tick stays cheap enough at ~0.2 ms each; if a tick's measurement grows past ~50 ms, that shows + up in the freshness slice. From 2cedca15f0a0f398ff914b0e15217ee0ce10323c Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:20:50 -0400 Subject: [PATCH 02/52] =?UTF-8?q?docs(specs):=20resource=20monitor=20?= =?UTF-8?q?=E2=80=94=20webview=20by=20responsible=20pid,=20an=20elsewhere?= =?UTF-8?q?=20group,=20child=20CPU,=20sampling=20lock;=20no=20healthz=20or?= =?UTF-8?q?=20shell=20change=20(THI-448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) --- .../2026-10-30-resource-monitor-design.md | 204 +++++++++--------- 1 file changed, 104 insertions(+), 100 deletions(-) diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index 6cdfc509..ed67739d 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -1,132 +1,136 @@ # Resource monitor -The dashboard shows how much memory and CPU each owner uses (agent sessions, the periscope server, its webview) -so that lag with ~10 agents can be traced to an owner before anything is optimized. THI-448, first slice. +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 | |---|---|---| | Machine (16 GB RAM, 10 cores) | ~48 GB; 16.5 of 17.4 GB swap used | load avg 50–70 | -| Agent sessions, whole pane subtrees | 12.8 GB | 112% | +| Panes, whole process subtrees | 12.8 GB | 112% | | ↳ heaviest pane | 6.8 GB, mostly `tsc`/`prettier`/`eslint`; its claude 446 MB | 58% | -| Webview (WebKit `WebContent`) | 2.9 GB, peaked at 7.7 GB the same day | ~40% | -| Periscope server + tmux control clients | 176 MB | ~7% | +| 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. `proc_pid_rusage` read footprint and CPU time for 6 pids in ~1 ms without a fork, and -its CPU deltas matched `top`. +claude 111 MB against 460 MB. ## Scope -In: measurement, the header pill and popover, the detail-header numbers, the webview through the shell. -Out, each its own later PR: dashboard freshness (`build_state` time, `/ws/state` frame gap), a 1 h history, a -"recycle pending" marker for the webview. THI-449 (recycle gate) and THI-450 (subprocesses per tick) are separate -tickets. +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. +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; RSS hides exactly the pressure this -feature exists to show. CPU% is per core like `top` (100% = one core), computed over the interval since the previous -sample of the same process. Called through `ctypes` on `/usr/lib/libproc.dylib` with the `RUSAGE_INFO_V0` flavor -(the struct the shell binds in `recycle.rs`); CPU times are mach absolute units, scaled by `mach_timebase_info`. -Stdlib only, so `uv run server.py`'s PEP-723 header doesn't change. - -**D2 — Measurement runs inside `build_state`, once per hub tick, and adds no subprocess.** It reuses the process -table (`session_status.proc_table()`) and the tmux pane roots (`_tmux_pane_pids()`) that each tick already forks -for; the pane roots get cached alongside `pane_claude_pids()`'s result so they are read, not re-forked. A tick -costs ~0.2 ms per process for the `proc_pid_rusage` calls (~25 ms at today's ~120 processes in pane subtrees). A -separate sampler thread was rejected: it would need its own process table (another `ps`, or a larger `libproc` -binding) and a thread under `docs/testing.md`'s rules, for steadier CPU windows nobody asked for yet. - -**D3 — A process is identified by (pid, start time).** The previous CPU sample is keyed by the pair, using -`ri_proc_start_abstime` from the same struct, so a recycled pid starts a fresh delta instead of reporting the -difference between two unrelated processes. A process seen for the first time has no CPU% yet; it counts as 0 in -sums. Entries for processes absent from a tick are dropped. - -**D4 — A session's numbers cover the pane's whole process subtree.** Rooted at the pane's `pane_pid`, walked with -the same `proc_table()` children map `pane_claude_pids()` uses. The claude process alone undercounts a busy session -(446 MB against 6.8 GB above). `sessions` is the total over every tmux pane, including panes that run no agent. - -**D5 — The periscope server is its own process plus its children.** That covers the tmux control-mode clients and -whatever `git`/`gh`/`ps` is running at that instant. The tmux server is not counted anywhere: it is shared, and it -measured 74 MB and 0.4%. - -**D6 — The webview is measured by the server from a pid the shell writes to a file.** The shell already reads the -`WebContent` pid every 60 s (`refresh_webcontent_pid`); it also writes it to `~/.config/periscope/webcontent.pid`, -next to `shell.log` and `zoom`. The server reads the file each tick and measures that pid itself, but only when the -file is less than 3 minutes old and `proc_pidpath` names a `com.apple.WebKit.WebContent` executable. Otherwise -`webview` is `null`: an older `.app`, a quit app, or a dashboard viewed in a browser tab all just omit the line. -The webview's `WebContent` has launchd as its parent and no sockets of its own (WebKit's networking process holds -them), so the server cannot find it without the shell. - -**D7 — The machine line reads the kernel directly, with no fork.** Load average from `os.getloadavg()`; swap used -and total from `sysctlbyname("vm.swapusage")`; free memory percent from `kern.memorystatus_level` (the figure -`memory_pressure` prints). - -**D8 — The ↻ cycle hint keeps watching the claude process alone, measured as footprint.** The leak it targets lives -in claude, not in its tool children. `mem_signal` reads footprint instead of RSS, the thresholds are renamed to -`MEM_BAD_FOOTPRINT_KB` / `MEM_WARN_FOOTPRINT_KB` and keep their values (4 GB / 2 GB), and the chip's `rss_gb` becomes -`mem_gb`. Today's claudes sit at 250–550 MB of footprint, so nothing new trips. `_claude_procs()` keeps its `ps` -call for liveness and age; moving that off `ps` belongs to THI-450. - -**D9 — Without `libproc` (not macOS), measurement is off.** One warning at first use; `res` and `resources` are -absent from `/api/state`, and the UI renders nothing for them. A pid that exits or refuses access between the -process table and the `proc_pid_rusage` call drops out of the sums; nothing in this path raises into `build_state`. +**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 per core like `top` and +Activity Monitor (100% = one core). Measured cost: ~3 µs per process, ~2 ms for every process on the machine. + +**D2 — Measurement runs inside `build_state`, once per tick, on the tick's existing process snapshot.** It reads +`agent_processes.process_snapshot()`, which the fan-out already takes every tick (`codex_process_for_pane`), so it +adds no subprocess. When the snapshot is `None` (a `ps` failure), `res` and `resources` are omitted 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 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. A process's CPU total is +its own time plus its reaped children's. A group's CPU over the interval is: +- for each member present in both samples, the change in its total; +- plus the whole total of a member that started after the previous sample; +- minus the last total of each member that vanished since the previous sample, because when it is reaped its whole + CPU time reappears in its parent's children time. +The result is clamped at 0: a vanished process reaped outside the group would otherwise subtract time the group +never gains back. 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 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 10 s (a hub that idled with no subscribers) counts as +missing. With no usable previous sample, `cpu_pct` is `null`, never 0, so a zero always means "measured idle". + +**D6 — The machine line reads the kernel directly, with no fork.** Load average from `os.getloadavg()`; swap used +and total from `sysctlbyname("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. `mem_signal` reads the claude's footprint from the +tick's measurement, and 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 only, no periscope imports, like `session_status`: +`periscope/resources.py`, stdlib only, no periscope imports: -- `usage(pids)` → `{pid: (footprint_bytes, cpu_ns, start)}` for the pids it could read. -- `sample(pids)` — reads `usage`, diffs against the previous sample per (pid, start), returns `{pid: (footprint_bytes, - cpu_pct)}`, and updates the stored samples. -- `subtree(root, kids)` → the root and all its descendants. -- `machine()` → `{load1, swap_used_mb, swap_total_mb, mem_free_pct}`. -- `webview_pid()` → the validated pid from D6, or `None`. +- `measure(snapshot, rows)` → `(per_row, totals)`. It reads every process once, assigns each to a group + (D3), computes footprint and CPU per group (D4, D5), and returns `{pane_id: {mem_mb, cpu_pct}}` for the rows and + `{server, webview, panes, elsewhere, machine}`. Each group is `{mem_mb, cpu_pct}`; `webview` may be `null`; + `machine` is D6's `{load1, swap_used_mb, swap_total_mb, mem_free_pct}`. +- It also returns each claude's footprint for `mem_signal` (D7). -`build_state` calls one function in `resources` that samples every pid it needs in a single pass (all pane -subtrees, the server subtree, the webview), then: +`build_state` calls `measure` after the fan-out and before the narrator merge. Each row gets `res`; the blob gets +`resources`. The claude footprint reaches `mem_signal` after the fan-out, so the `mem` field is set there rather +than inside `build_window_view`. -- each window row gets `res: {mem_mb, cpu_pct}` for its pane's subtree; -- the blob gets `resources: {server, webview, sessions, machine}`, where `server`, `webview` and `sessions` are - `{mem_mb, cpu_pct}` (`webview` may be `null`) and `machine` is D7's dict. - -`/api/healthz` adds `resources: {server}` with the server's `{mem_mb, cpu_pct, children}`. It samples the server -subtree itself and shares the stored CPU samples with `build_state`. - -## Shell - -`recycle.rs`: after `refresh_webcontent_pid` stores a pid, write it to `~/.config/periscope/webcontent.pid` -(overwriting, so the mtime is the freshness signal), including right after a recycle rebuilds the webview. Failure -to write is ignored, like `shell_log`. `docs/tauri-shell.md` gains a sentence on the file. The change needs an `.app` -rebuild; until then D6's fallback applies. +`/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 · 165%`, the sum of server, webview and sessions. Hidden when - `resources` is absent. -- **Popover** on click: periscope server, webview, then every session sorted by memory (a row selects its pane), - then the machine line: `load 52 · swap 16.5/17.4G · 27% free`. The CPU column's tooltip says 100% = one core. -- **Detail header**: a `· 6.8G · 58%` part after the context %, for the selected pane. -- Formatting (MB→`0.6G`/`512M`, percent rounding) and sorting go in a pure `static/src/chrome/resources.js`, tested - with vitest, the way `usageSummary.js` backs `UsagePill`. -- `memHint` reads `mem_gb`. +- **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, then every pane sorted by + memory (a line selects its pane), then elsewhere, then the machine line: `load 52 · swap 16.5/17.4G · 27% free`. + The CPU column's tooltip says 100% = one core. A `null` CPU shows `–`. +- **Detail header**: `· 6.8G mem · 58% cpu` after the context %, for the selected pane. +- 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/test_resources.py`: CPU% on a first sample (0), on a second, after a pid reuse (new start time → fresh - sample), and for a pid gone from the tick (dropped); subtree sums over a fake children map; `webview_pid` for a - missing file, a stale file, a pid whose path isn't `WebContent`, and a valid one; the no-`libproc` path. The - `proc_pid_rusage` call is behind one function the tests replace; one smoke test reads the test process itself. -- `tests/test_window_view.py`: `mem_signal` on footprint at each tier. -- `tests/routes/`: `/api/state` carries `res` and `resources`; `/api/healthz` carries `resources.server`. -- vitest: `resources.js` formatting and ordering; `memHint` with `mem_gb`. +- `tests/conftest.py`: an autouse fixture stubs `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 and a process outside every group; + - CPU: first sample (`null`), steady second sample, pid reuse, a child started after the previous sample, a child + that exits and is reaped by a member, a member reaped outside the group (clamped); + - the 0.5 s and 10 s rules, and two threads sampling at once; + - a `None` snapshot; + - one smoke test that reads the test process itself through the real `proc_pid_rusage`. +- `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 -- Every process measured belongs to the user running periscope; `proc_pid_rusage` on a root-owned pid fails and the - pid is skipped (D9). Verified for claude, the server and `WebContent`. -- ~120 processes per tick stays cheap enough at ~0.2 ms each; if a tick's measurement grows past ~50 ms, that shows - up in the freshness slice. +- 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. From cde6b151078cd58eb5e960de7e43e44a2fc2ce28 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:29:27 -0400 Subject: [PATCH 03/52] docs(plans): resource monitor implementation plan, 11 tasks (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- .../plans/2026-10-30-resource-monitor.md | 1549 +++++++++++++++++ 1 file changed, 1549 insertions(+) create mode 100644 docs/superpowers/plans/2026-10-30-resource-monitor.md 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:`). From 47072719c68e0e308c41aae9e9aad93e71891f74 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:32:04 -0400 Subject: [PATCH 04/52] resources: footprint, CPU time and machine figures through libproc/sysctl, no subprocess (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- periscope/resources.py | 125 ++++++++++++++++++++++++++++++++++++++++ tests/test_resources.py | 34 +++++++++++ 2 files changed, 159 insertions(+) create mode 100644 periscope/resources.py create mode 100644 tests/test_resources.py diff --git a/periscope/resources.py b/periscope/resources.py new file mode 100644 index 00000000..2f3bc907 --- /dev/null +++ b/periscope/resources.py @@ -0,0 +1,125 @@ +"""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, + } diff --git a/tests/test_resources.py b/tests/test_resources.py new file mode 100644 index 00000000..871ee99a --- /dev/null +++ b/tests/test_resources.py @@ -0,0 +1,34 @@ +"""resources: footprint and CPU per owner. Everything except the smoke tests +runs on fake snapshots and fake rusage readings.""" + +import os + +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 From ffcadd0eb7e9a3f24c09f62b198c519ea021023b Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:37:17 -0400 Subject: [PATCH 05/52] =?UTF-8?q?resources:=20every=20process=20lands=20in?= =?UTF-8?q?=20one=20group=20=E2=80=94=20server,=20webview=20by=20responsib?= =?UTF-8?q?le=20pid,=20each=20pane's=20subtree,=20elsewhere=20(THI-448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5 --- periscope/agent_processes.py | 5 ++-- periscope/resources.py | 30 +++++++++++++++++++++++ tests/test_resources.py | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) 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/resources.py b/periscope/resources.py index 2f3bc907..d3dfdb95 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -14,9 +14,15 @@ import os 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). Its WebKit helpers have launchd as +# their parent, so they're found by responsible pid instead. +_APP_NAME = "periscope-app" + class _RusageInfoV1(ctypes.Structure): # rusage_info_v1: the v0 fields recycle.rs binds, plus @@ -123,3 +129,27 @@ def machine() -> dict: "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 = {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 diff --git a/tests/test_resources.py b/tests/test_resources.py index 871ee99a..dd2c7539 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -32,3 +32,50 @@ def test_machine_reads_the_kernel(): def test_responsible_pid_of_this_process_is_a_pid(): assert resources._responsible(os.getpid()) > 0 + + +# ── 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"] From 26c9bb7414b642ac27bb4823858caf68e537f20c Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:40:41 -0400 Subject: [PATCH 06/52] resources: a group's CPU counts children reaped within it and never diffs a reused pid (THI-448) Co-Authored-By: Claude Sonnet 5 --- periscope/resources.py | 31 ++++++++++++++++++++++++++ tests/test_resources.py | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/periscope/resources.py b/periscope/resources.py index d3dfdb95..1b9cf890 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -23,6 +23,10 @@ # their parent, so they're found by responsible pid instead. _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. +_STALE_NS = 10 * 1_000_000_000 + class _RusageInfoV1(ctypes.Structure): # rusage_info_v1: the v0 fields recycle.rs binds, plus @@ -153,3 +157,30 @@ def subtree(root: int) -> set[int]: named["panes"] = set().union(*per_pane.values()) named["elsewhere"] = set(snapshot) - claimed return named, per_pane + + +@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) diff --git a/tests/test_resources.py b/tests/test_resources.py index dd2c7539..c37e4205 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -79,3 +79,52 @@ def test_assign_without_the_app_has_no_webview(monkeypatch): named, _ = resources._assign(snap, {"%1": 100}) assert "webview" not in named assert 600 in named["elsewhere"] + + +# ── 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 From c995876b93a57d440ae599b0e7f4a7cc1e6d3ec5 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:45:14 -0400 Subject: [PATCH 07/52] resources: measure() reads every process once per tick under a lock, at most every 0.5 s (THI-448) Co-Authored-By: Claude Sonnet 5 --- periscope/resources.py | 55 +++++++++++++++++++++- tests/test_resources.py | 100 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) diff --git a/periscope/resources.py b/periscope/resources.py index 1b9cf890..047ca049 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -12,9 +12,10 @@ import ctypes import os +import threading from dataclasses import dataclass -from periscope.agent_processes import ProcessInfo, descendants +from periscope.agent_processes import ProcessInfo, descendants, process_snapshot _u64 = ctypes.c_uint64 _RUSAGE_INFO_V1 = 1 @@ -27,6 +28,10 @@ # would average hours into one number; it counts as missing. _STALE_NS = 10 * 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 gets the previous measurement. +_MIN_INTERVAL_NS = 500_000_000 + class _RusageInfoV1(ctypes.Structure): # rusage_info_v1: the v0 fields recycle.rs binds, plus @@ -184,3 +189,51 @@ def _cpu_pct(prev: _Sample | None, cur: _Sample) -> float | None: if ident not in cur.totals: delta -= total return round(max(delta, 0) / (cur.at - prev.at) * 100, 1) + + +@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 diff --git a/tests/test_resources.py b/tests/test_resources.py index c37e4205..c09223be 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -3,6 +3,8 @@ import os +import pytest + from periscope import resources # ── the real system calls ──────────────────────────────────────────────── @@ -128,3 +130,101 @@ def test_cpu_never_diffs_a_reused_pid_against_its_predecessor(): def test_cpu_treats_a_stale_previous_sample_as_missing(): assert _cpu(0, {(1, 0): S}, 11 * S, {(1, 0): 2 * S}) is None + + +# ── 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 = dict.fromkeys(_snapshot(), 0) + 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 From a4f1aee5f2784c3e226ce87341c6deea9397c124 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:47:40 -0400 Subject: [PATCH 08/52] tests: an autouse stub keeps resources off the real machine (THI-448) Co-Authored-By: Claude Sonnet 5 --- tests/conftest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index ca51bc8a..9a1603cd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -82,6 +82,25 @@ def _no_live_session_scan(monkeypatch): monkeypatch.setattr(session_status, "_config_dirs_cache", None, raising=False) +@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) + + @pytest.fixture(scope="session", autouse=True) def _session_activity_db_guard(tmp_path_factory): """Session-wide floor that the real periscope.db is NEVER the active From e4fd04d319a80c03233a0a1707375ece02c1f254 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:51:13 -0400 Subject: [PATCH 09/52] =?UTF-8?q?resources:=20find=20periscope-app=20by=20?= =?UTF-8?q?the=20kernel's=20process=20name=20=E2=80=94=20ps=20truncates=20?= =?UTF-8?q?comm=20to=2016=20characters=20(THI-448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5 --- periscope/resources.py | 17 ++++++++++++++--- tests/conftest.py | 1 + tests/test_resources.py | 20 +++++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/periscope/resources.py b/periscope/resources.py index 047ca049..1d86cfdc 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -20,8 +20,10 @@ _u64 = ctypes.c_uint64 _RUSAGE_INFO_V1 = 1 -# The Tauri shell's executable (src-tauri). Its WebKit helpers have launchd as -# their parent, so they're found by responsible pid instead. +# The Tauri shell's executable (src-tauri), matched against the kernel's +# process name via `_name` — `ps`'s comm column truncates to 16 characters, +# which cuts the real name off. Its WebKit helpers have launchd as their +# parent, so they're found by responsible pid instead. _APP_NAME = "periscope-app" # A previous sample older than this (a hub that idled with no subscribers) @@ -76,6 +78,7 @@ class _SwapUsage(ctypes.Structure): _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 @@ -110,6 +113,14 @@ def _responsible(pid: int) -> int: return _libsystem.responsibility_get_pid_responsible_for_pid(pid) +def _name(pid: int) -> str: + """The process's name from the kernel, untruncated — `ps`'s comm column + cuts it to 16 characters.""" + 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) @@ -155,7 +166,7 @@ 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} + 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()} diff --git a/tests/conftest.py b/tests/conftest.py index 9a1603cd..b92c2113 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -94,6 +94,7 @@ def _no_live_resources(monkeypatch): monkeypatch.setattr(resources, "process_snapshot", dict) monkeypatch.setattr(resources, "_read", lambda pid: None) monkeypatch.setattr(resources, "_responsible", lambda pid: 0) + monkeypatch.setattr(resources, "_name", lambda pid: "") monkeypatch.setattr( resources, "machine", lambda: {"load1": 0.0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 100} ) diff --git a/tests/test_resources.py b/tests/test_resources.py index c09223be..779d25da 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -36,6 +36,12 @@ def test_responsible_pid_of_this_process_is_a_pid(): assert resources._responsible(os.getpid()) > 0 +def test_name_of_this_process_is_a_nonempty_str(): + name = resources._name(os.getpid()) + assert isinstance(name, str) + assert name + + # ── group assignment ───────────────────────────────────────────────────── from periscope.agent_processes import ProcessInfo @@ -43,8 +49,8 @@ def test_responsible_pid_of_this_process_is_a_pid(): 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 _proc(pid, ppid, comm="/bin/zsh", argv=None): + return ProcessInfo(pid=pid, ppid=ppid, started_at=0, comm=comm, argv=argv if argv is not None else comm, state="S") def _snapshot(): @@ -54,7 +60,13 @@ def _snapshot(): _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"), + # ps truncates comm= to 16 chars when it isn't the last column. + _proc( + 500, + 1, + comm="/Applications/Pe", + argv="/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"), @@ -67,6 +79,7 @@ def _snapshot(): def test_assign_puts_every_process_in_one_group(monkeypatch): monkeypatch.setattr(resources, "_responsible", {600: 500}.get) + monkeypatch.setattr(resources, "_name", lambda pid: {500: "periscope-app"}.get(pid, "")) 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 @@ -164,6 +177,7 @@ def fake(monkeypatch): cpu = dict.fromkeys(_snapshot(), 0) monkeypatch.setattr(resources, "process_snapshot", _snapshot) monkeypatch.setattr(resources, "_responsible", {600: 500}.get) + monkeypatch.setattr(resources, "_name", lambda pid: {500: "periscope-app"}.get(pid, "")) monkeypatch.setattr(resources, "machine", lambda: MACHINE) monkeypatch.setattr(resources, "_now", clock) monkeypatch.setattr( From cb9462217f8f7a85cd64bd13919e9c3b6d87ec0b Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:52:06 -0400 Subject: [PATCH 10/52] resources: measure() commits its samples and the throttle clock together, so a failed pass leaves no half-built state (THI-448) Co-Authored-By: Claude Sonnet 5 --- periscope/resources.py | 8 ++++---- tests/test_resources.py | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/periscope/resources.py b/periscope/resources.py index 1d86cfdc..e84a675b 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -230,15 +230,15 @@ def measure(panes: dict[str, int]) -> Measurement | None: 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, {} + samples: dict[str, _Sample] = {} 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 + samples[key] = cur return { "mem_mb": sum(r.footprint for r in members.values()) >> 20, - "cpu_pct": _cpu_pct(prev.get(key), cur), + "cpu_pct": _cpu_pct(_prev.get(key), cur), } totals: dict = {"webview": None} | {key: group(key, pids) for key, pids in named.items()} @@ -246,5 +246,5 @@ def group(key: str, pids: set[int]) -> dict: measurement = Measurement( {pane_id: group(f"pane:{pane_id}", pids) for pane_id, pids in per_pane.items()}, totals ) - _last = (now, measurement) + _prev, _last = samples, (now, measurement) return measurement diff --git a/tests/test_resources.py b/tests/test_resources.py index 779d25da..ccbc76e7 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -2,6 +2,7 @@ runs on fake snapshots and fake rusage readings.""" import os +import threading import pytest @@ -147,8 +148,6 @@ def test_cpu_treats_a_stale_previous_sample_as_missing(): # ── measure ────────────────────────────────────────────────────────────── -import threading - @pytest.fixture(autouse=True) def _no_live_resources(monkeypatch): @@ -242,3 +241,19 @@ def test_measure_from_many_threads_at_once(fake): t.join() assert len(out) == 8 assert all(m is out[0] for m in out) # one computed, the rest inside 0.5 s + + +def test_measure_leaves_no_state_when_a_pass_fails(fake, monkeypatch): + resources.measure(PANES) + clock, _ = fake + clock.t += S + prev_before, last_before = resources._prev, resources._last + + def boom(): + raise RuntimeError("boom") + + monkeypatch.setattr(resources, "machine", boom) + with pytest.raises(RuntimeError): + resources.measure(PANES) + assert resources._prev == prev_before + assert resources._last == last_before From 404bdb9a38649b0ffd5c40226addc5193773e7ca Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:55:13 -0400 Subject: [PATCH 11/52] resources: _APP_NAME's comment points at _name instead of repeating it; _name's docstring states proc_name's 32-character cap (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- periscope/resources.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/periscope/resources.py b/periscope/resources.py index e84a675b..a1117c78 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -20,10 +20,8 @@ _u64 = ctypes.c_uint64 _RUSAGE_INFO_V1 = 1 -# The Tauri shell's executable (src-tauri), matched against the kernel's -# process name via `_name` — `ps`'s comm column truncates to 16 characters, -# which cuts the real name off. Its WebKit helpers have launchd as their -# parent, so they're found by responsible pid instead. +# 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) @@ -114,8 +112,8 @@ def _responsible(pid: int) -> int: def _name(pid: int) -> str: - """The process's name from the kernel, untruncated — `ps`'s comm column - cuts it to 16 characters.""" + """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") From 4c81905c4972895448db5ade8e7feefb8af24502 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 20:57:25 -0400 Subject: [PATCH 12/52] state: each row carries its pane's res and the blob the resources totals (THI-448) Co-Authored-By: Claude Sonnet 5 --- periscope/routes/state.py | 11 ++++++- tests/routes/test_state.py | 62 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/periscope/routes/state.py b/periscope/routes/state.py index 961be0d7..438042cb 100644 --- a/periscope/routes/state.py +++ b/periscope/routes/state.py @@ -13,7 +13,7 @@ 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.channels import _channel_gc from periscope.panes import ( @@ -86,6 +86,12 @@ def build_state() -> dict: result = [view for view, _ in built] annotate_cost_pressure(result) + # 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 + # 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 +198,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/tests/routes/test_state.py b/tests/routes/test_state.py index 9cb57347..128b6eae 100644 --- a/tests/routes/test_state.py +++ b/tests/routes/test_state.py @@ -104,7 +104,11 @@ def test_state_preserves_window_order_across_fanout(client, mocker, clean_state) _patch(mocker, "update_focus_from_windows") _patch(mocker, "_attach_git_then_resolve_pids") _patch(mocker, "all_projects", return_value={}) - _patch(mocker, "build_window_view", side_effect=lambda w, now_ts: ({"index": w["index"]}, None)) + _patch( + mocker, + "build_window_view", + side_effect=lambda w, now_ts: ({"index": w["index"], "pane_id": w["pane_id"]}, None), + ) resp = client.get("/api/state") assert [v["index"] for v in resp.json()["windows"]] == [0, 1, 2, 3, 4] @@ -122,7 +126,7 @@ def test_state_writes_stamps_once_after_join(client, mocker, clean_state): _patch( mocker, "build_window_view", - side_effect=lambda w, now_ts: ({"index": w["index"]}, (f"pid{w['index']}", 10, 5, 0)), + side_effect=lambda w, now_ts: ({"index": w["index"], "pane_id": w["pane_id"]}, (f"pid{w['index']}", 10, 5, 0)), ) bulk = _patch(mocker, "set_window_fields_bulk") client.get("/api/state") @@ -146,7 +150,7 @@ def test_state_isolates_one_pane_build_failure(client, mocker, clean_state): def fake_build(w, now_ts): if w["index"] == 0: raise RuntimeError("git blew up mid-build") # NOT a capture error - return ({"index": 1, "state": "idle"}, None) + return ({"index": 1, "state": "idle", "pane_id": w["pane_id"]}, None) _patch(mocker, "build_window_view", side_effect=fake_build) resp = client.get("/api/state") @@ -384,3 +388,55 @@ def test_state_keeps_the_walls_stretch_past_the_refresh_that_drops_them(client, body = client.get("/api/state").json() assert body["walls"] is None assert body["wall_spans"] == [{"since": 1_792_598_460, "until": 1_792_603_799}] + + +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 From 1dc320d36862793f8e57d5d3567be9824eb90258 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:02:21 -0400 Subject: [PATCH 13/52] =?UTF-8?q?cycle=20hint:=20the=20=E2=86=BB=20chip=20?= =?UTF-8?q?reads=20claude's=20footprint,=20not=20RSS,=20and=20says=20which?= =?UTF-8?q?=20limit=20tripped=20(THI-448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5 --- periscope/config.py | 12 ++++----- periscope/session_status.py | 49 ++++++++++++++++++------------------ periscope/window_view.py | 24 ++++++++++-------- tests/test_session_status.py | 21 ++++++++-------- tests/test_window_view.py | 25 +++++++++++------- 5 files changed, 71 insertions(+), 60 deletions(-) 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/session_status.py b/periscope/session_status.py index bdb66f09..f0c88cb3 100644 --- a/periscope/session_status.py +++ b/periscope/session_status.py @@ -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. 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) @@ -522,10 +523,10 @@ 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]} + return {"pid": pid, "mem_mb": resources.footprint_mb(pid), "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..7846d391 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 lives here (config thresholds); measurement stays in + session_status, which can't import config.""" 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 is not None and 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 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} # How far before needs_since the request's own row can be stamped. The hook diff --git a/tests/test_session_status.py b/tests/test_session_status.py index 2121507e..1e236d7f 100644 --- a/tests/test_session_status.py +++ b/tests/test_session_status.py @@ -122,10 +122,10 @@ def test_missing_sessions_dir_returns_none(tmp_path, monkeypatch): # ── live-claude pid detection parses ps output ─────────────────────────── _PS_SAMPLE = ( - " 9448 473120 01-02:08:58 /Users/tom/.local/bin/claude\n" - " 9876 605744 22:09:53 /Users/tom/.local/share/claude/versions/2.1.161\n" - " 329 1024 05:33 /usr/libexec/logd\n" - " 1 512 91-10:00:00 /sbin/launchd\n" + " 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" ) @@ -138,15 +138,15 @@ class _R: assert ss._live_claude_pids() == {9448, 9876} -def test_claude_procs_carry_rss_and_age(monkeypatch): +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: (473120, 26 * 3600 + 8 * 60 + 58), - 9876: (605744, 22 * 3600 + 9 * 60 + 53), + 9448: 26 * 3600 + 8 * 60 + 58, + 9876: 22 * 3600 + 9 * 60 + 53, } @@ -181,8 +181,9 @@ def _seed_procs(tmp_path, monkeypatch, session, procs): 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_500_000, 4 * 86400)}) - assert ss.claude_proc_for("sid-m") == {"pid": 300, "rss_kb": 4_500_000, "age_s": 4 * 86400} + _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} def test_claude_proc_for_dead_pid_none(tmp_path, monkeypatch): @@ -191,7 +192,7 @@ def test_claude_proc_for_dead_pid_none(tmp_path, monkeypatch): def test_claude_proc_for_unmapped_none(tmp_path, monkeypatch): - _seed_procs(tmp_path, monkeypatch, _sess(302, "sid-k", "busy"), {302: (1, 1)}) + _seed_procs(tmp_path, monkeypatch, _sess(302, "sid-k", "busy"), {302: 1}) assert ss.claude_proc_for("sid-nope") is None assert ss.claude_proc_for(None) is None diff --git a/tests/test_window_view.py b/tests/test_window_view.py index f31acb6d..a27ecb42 100644 --- a/tests/test_window_view.py +++ b/tests/test_window_view.py @@ -806,30 +806,37 @@ 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, "rss_kb": 600_000, "age_s": 3600}) is None + assert mem_signal({"pid": 1, "mem_mb": 600, "age_s": 3600}) is None -def test_mem_signal_warn_on_rss(): +def test_mem_signal_warn_on_footprint(): from periscope.window_view import mem_signal - out = mem_signal({"pid": 1, "rss_kb": 2 * 1024 * 1024, "age_s": 60}) - assert out == {"tier": "warn", "rss_gb": 2.0, "age_s": 60} + 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, "rss_kb": 500_000, "age_s": 3 * 86400}) - assert out["tier"] == "warn" - assert out["rss_gb"] == 0.5 + 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, "rss_kb": 4_400_000, "age_s": 60}) + out = mem_signal({"pid": 1, "mem_mb": 4300, "age_s": 60}) assert out["tier"] == "bad" - assert out["rss_gb"] == 4.2 + 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} def test_view_surfaces_spawned_by_lineage(mocker, clean_state): From 08d252981d9c09da09de2998a3c3ba0b29e5eb52 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:04:25 -0400 Subject: [PATCH 14/52] ui: resources formatting, and memHint labels from the server's trigger (THI-448) Co-Authored-By: Claude Sonnet 5 --- static/src/__tests__/agent.test.js | 2 +- static/src/__tests__/memHint.test.js | 14 ++++-- static/src/chrome/__tests__/resources.test.js | 46 +++++++++++++++++++ static/src/chrome/resources.js | 31 +++++++++++++ static/src/util.js | 14 +++--- 5 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 static/src/chrome/__tests__/resources.test.js create mode 100644 static/src/chrome/resources.js 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..f9ce0690 100644 --- a/static/src/__tests__/memHint.test.js +++ b/static/src/__tests__/memHint.test.js @@ -8,17 +8,23 @@ 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"); }); + + 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"); + }); }); diff --git a/static/src/chrome/__tests__/resources.test.js b/static/src/chrome/__tests__/resources.test.js new file mode 100644 index 00000000..fed1c6ee --- /dev/null +++ b/static/src/chrome/__tests__/resources.test.js @@ -0,0 +1,46 @@ +// 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"); + }); +}); diff --git a/static/src/chrome/resources.js b/static/src/chrome/resources.js new file mode 100644 index 00000000..3a0c85d1 --- /dev/null +++ b/static/src/chrome/resources.js @@ -0,0 +1,31 @@ +// 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`; +} diff --git a/static/src/util.js b/static/src/util.js index 8b26646a..a03b0279 100644 --- a/static/src/util.js +++ b/static/src/util.js @@ -102,18 +102,20 @@ export function shortestUniqueSuffix(name, allNames) { // GitHub PR URL for a pane's repo. `slug` ("owner/repo") is derived // server-side from `git remote get-url origin`; null when the repo's origin // isn't a GitHub remote — callers then render the PR badge unlinked. -// Cycle-hint chip content for a bloated/aged Claude process. `mem` is the -// server's `w.mem` ({tier: "warn"|"bad", rss_gb, age_s}) or null/undefined — -// the server only sends it when a threshold tripped, so null → no chip. -// Label leads with RSS when memory tripped the tier, uptime days otherwise. +// 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.rss_gb >= 2 ? `${mem.rss_gb}G` : `${days}d`, - title: `Claude is using ${mem.rss_gb}GB after ${up} — consider exiting and resuming this session`, + label: mem.trigger === "mem" ? `${mem.gb}G` : `${days}d`, + title: `${what} — consider exiting and resuming this session`, cls: `mem-${mem.tier}`, }; } From c1a1087bc3dda7dd031c1cb1d2629ae42c7a62cc Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:07:16 -0400 Subject: [PATCH 15/52] ui: a header pill with each owner's memory and CPU, panes heaviest first (THI-448) Co-Authored-By: Claude Sonnet 5 --- static/src/chrome/Header.jsx | 2 + static/src/chrome/ResourcePill.jsx | 76 +++++++++++++++++++ .../__tests__/resourcePillRender.test.jsx | 53 +++++++++++++ static/src/poll.js | 2 + static/src/store.js | 1 + static/styles.css | 22 ++++++ 6 files changed, 156 insertions(+) create mode 100644 static/src/chrome/ResourcePill.jsx create mode 100644 static/src/chrome/__tests__/resourcePillRender.test.jsx diff --git a/static/src/chrome/Header.jsx b/static/src/chrome/Header.jsx index 774543d4..592491f7 100644 --- a/static/src/chrome/Header.jsx +++ b/static/src/chrome/Header.jsx @@ -21,6 +21,7 @@ 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"; @@ -136,6 +137,7 @@ export function Header() { periscope + {/* The spawn pins stack as one block to the right of the usage meters (.usage flexes, so this block sits at the meters' far edge): account, model, effort, labels aligned so the chips read as a diff --git a/static/src/chrome/ResourcePill.jsx b/static/src/chrome/ResourcePill.jsx new file mode 100644 index 00000000..647e17cf --- /dev/null +++ b/static/src/chrome/ResourcePill.jsx @@ -0,0 +1,76 @@ +// "▣ 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 ( +
+ + +
+ ); +} diff --git a/static/src/chrome/__tests__/resourcePillRender.test.jsx b/static/src/chrome/__tests__/resourcePillRender.test.jsx new file mode 100644 index 00000000..15f7c36b --- /dev/null +++ b/static/src/chrome/__tests__/resourcePillRender.test.jsx @@ -0,0 +1,53 @@ +// 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<"); + }); +}); diff --git a/static/src/poll.js b/static/src/poll.js index 822c2220..6ba5754f 100644 --- a/static/src/poll.js +++ b/static/src/poll.js @@ -17,6 +17,7 @@ import { launchDefault, moveTargets, projects, + resources, reviews, spawnAccount, spawnEffort, @@ -65,6 +66,7 @@ function applyState(data) { // UsagePill reads { plan, fallback, poke }. usage.value = { plan: data.usage_plan, fallback: data.usage, poke: data.poke || {} }; updateInfo.value = data.update || null; + resources.value = data.resources || null; accounts.value = data.accounts || []; moveTargets.value = data.move_targets || {}; spawnAccount.value = data.spawn_account || null; diff --git a/static/src/store.js b/static/src/store.js index ff75cc36..8691335c 100644 --- a/static/src/store.js +++ b/static/src/store.js @@ -33,6 +33,7 @@ export const railSelection = signal(null); // string highlight-key: "pane: move destination id export const spawnAccount = signal(null); // pinned spawn account id, null = auto (launch_policy) diff --git a/static/styles.css b/static/styles.css index 2e34203b..470a22ab 100644 --- a/static/styles.css +++ b/static/styles.css @@ -300,6 +300,28 @@ button, input, textarea, select { font-family: inherit; } .update-menu-warn { margin: 0 0 6px; padding: 4px 6px; border-radius: var(--r-sm); font-size: 11px; line-height: 1.4; color: var(--s-danger); background: color-mix(in oklch, var(--s-danger) 12%, transparent); } .update-menu-error { margin: 0 0 6px; padding: 4px 6px; font-size: 11px; white-space: pre-wrap; color: var(--s-danger); } +/* 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); } .update-notes { max-height: 50vh; overflow-y: auto; padding: 0 6px; font-size: 12px; line-height: 1.5; color: var(--fg-1); } .update-release + .update-release { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-soft); } .update-release-head { margin-bottom: 4px; font-weight: 600; color: var(--fg-0); } From 2d977938a09e1e097e91e9ac1d4047f81ee5387c Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:08:50 -0400 Subject: [PATCH 16/52] session_status, window_view: docstrings state what each imports and where measurement lives (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- periscope/session_status.py | 8 ++++---- periscope/window_view.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/periscope/session_status.py b/periscope/session_status.py index f0c88cb3..0e582b22 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 @@ -510,8 +510,8 @@ 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", "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 + None when unmapped or not a live claude. mem_mb is its footprint, None when + unreadable (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: diff --git a/periscope/window_view.py b/periscope/window_view.py index 7846d391..f60bc1c9 100644 --- a/periscope/window_view.py +++ b/periscope/window_view.py @@ -226,8 +226,8 @@ def mem_signal(proc: dict | None) -> dict | None: "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.""" + with it. Policy (the config thresholds) lives here; + measurement in session_status and resources.""" if not proc: return None mb, age = proc["mem_mb"], proc["age_s"] From d9f11d135b1baae7549b7d40572e53c8606a043a Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:10:02 -0400 Subject: [PATCH 17/52] ui: the detail header shows the pane's memory and CPU, labelled (THI-448) Co-Authored-By: Claude Sonnet 5 --- static/src/__tests__/paneHeaderRes.test.js | 24 ++++++++++++++++++++++ static/src/split/Detail.jsx | 11 ++++++++++ 2 files changed, 35 insertions(+) create mode 100644 static/src/__tests__/paneHeaderRes.test.js 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/split/Detail.jsx b/static/src/split/Detail.jsx index bfb808c7..27822af7 100644 --- a/static/src/split/Detail.jsx +++ b/static/src/split/Detail.jsx @@ -17,6 +17,7 @@ // hsep, header-pr/-linear/-ci/-git/-api-error, side-section/-label/-pending/ // -prompt/-mono. No class renamed. import { useEffect, useRef, useState } from "preact/hooks"; +import { fmtCpu, fmtMem } from "../chrome/resources.js"; import { ChangesTab } from "../diff/ChangesTab.jsx"; import { Inspector } from "../inspector/Inspector.jsx"; import { getDetailMode, setDetailMode, setLastSelected } from "../prefs.js"; @@ -258,6 +259,16 @@ export function PaneHeader({ w }) { if (w.agent && w.context_pct != null) { parts.push(<>·{w.context_pct}%); } + if (w.res) { + parts.push( + <> + · + + {`${fmtMem(w.res.mem_mb)} mem · ${fmtCpu(w.res.cpu_pct)} cpu`} + + + ); + } if (w.agent === "claude" && w.mem) { const mh = memHint(w.mem); parts.push(<>·↻ {mh.label}); From f02e8b2aaade05bcd4a13b64ae051aa962aaf433 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:11:05 -0400 Subject: [PATCH 18/52] ui: the resource pill's own wrapper class, keyboard-reachable pane lines, and local open state (THI-448) Co-Authored-By: Claude Sonnet 5 --- static/src/chrome/Header.jsx | 5 ++--- static/src/chrome/ResourcePill.jsx | 29 ++++++++++++++++++----------- static/styles.css | 2 ++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/static/src/chrome/Header.jsx b/static/src/chrome/Header.jsx index 592491f7..2db90ed4 100644 --- a/static/src/chrome/Header.jsx +++ b/static/src/chrome/Header.jsx @@ -139,9 +139,8 @@ export function Header() { {/* The spawn pins stack as one block to the right of the usage - meters (.usage flexes, so this block sits at the meters' far edge): - account, model, effort, labels aligned so the chips read as a - 3-row table. */} + meters and the resource pill: account, model, effort, labels + aligned so the chips read as a 3-row table. */}
diff --git a/static/src/chrome/ResourcePill.jsx b/static/src/chrome/ResourcePill.jsx index 647e17cf..4f1ecef9 100644 --- a/static/src/chrome/ResourcePill.jsx +++ b/static/src/chrome/ResourcePill.jsx @@ -3,32 +3,38 @@ // 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 { useCallback, useEffect, useRef, useState } 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 ( -
+ const children = ( + <> {label} {fmtMem(group.mem_mb)} {fmtCpu(group.cpu_pct)} -
+ ); + if (onClick) { + return ( + + ); + } + return
{children}
; } export function ResourcePill() { const ref = useRef(null); - const open = popoverOpen.value; + const [open, setOpen] = useState(false); const r = resources.value; - const close = useCallback(() => { popoverOpen.value = false; }, []); + const close = useCallback(() => setOpen(false), []); useEscape(close, open); useEffect(() => { if (!open) return; @@ -39,21 +45,22 @@ export function ResourcePill() { 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. + // close it, or Escape stays bound to an invisible popover — returning null + // below doesn't unmount this component, so the open state would survive. useEffect(() => { if (!r && open) close(); }, [r, open]); if (!r) return null; return ( -
+
diff --git a/static/styles.css b/static/styles.css index 470a22ab..888f392c 100644 --- a/static/styles.css +++ b/static/styles.css @@ -301,6 +301,7 @@ button, input, textarea, select { font-family: inherit; } color: var(--s-danger); background: color-mix(in oklch, var(--s-danger) 12%, transparent); } .update-menu-error { margin: 0 0 6px; padding: 4px 6px; font-size: 11px; white-space: pre-wrap; color: var(--s-danger); } /* Resource pill (ResourcePill.jsx): neutral, it reports rather than calls to action. */ +.res-dd { position: relative; display: inline-flex; align-self: center; } .res-pill { flex: 0 0 auto; align-self: center; @@ -316,6 +317,7 @@ button, input, textarea, select { font-family: inherit; } .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); } +button.res-line { font: inherit; color: inherit; background: none; border: 0; text-align: left; width: 100%; } .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; } From 4ad74b77b4cc76650086a55a17ccf9451bd56858 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:11:55 -0400 Subject: [PATCH 19/52] util: the PR-URL comment sits on prUrl, not on memHint (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- static/src/util.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/static/src/util.js b/static/src/util.js index a03b0279..b7fc05c0 100644 --- a/static/src/util.js +++ b/static/src/util.js @@ -99,9 +99,6 @@ export function shortestUniqueSuffix(name, allNames) { return name; } -// GitHub PR URL for a pane's repo. `slug` ("owner/repo") is derived -// server-side from `git remote get-url origin`; null when the repo's origin -// isn't a GitHub remote — callers then render the PR badge unlinked. // 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 @@ -120,6 +117,9 @@ export function memHint(mem) { }; } +// GitHub PR URL for a pane's repo. `slug` ("owner/repo") is derived +// server-side from `git remote get-url origin`; null when the repo's origin +// isn't a GitHub remote — callers then render the PR badge unlinked. export function prUrl(slug, pr) { return slug ? `https://github.com/${slug}/pull/${pr}` : null; } From 0c55e362745d376d20fad2c7171673b4571297cd Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:12:15 -0400 Subject: [PATCH 20/52] build: static/dist with the resource pill (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- static/dist/app.js | 60 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/static/dist/app.js b/static/dist/app.js index 353fa37b..5301dc13 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??++ic,__i:-1,__u:0};return l==null&&le.vnode!=null&&le.vnode(a),a}function K(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&&dt.sort(sc),e=dt.shift(),t=dt.length,dh(e)}finally{dt.length=li.__r=0}}function uc(e,t,n,i,l,a,s,o,u,c,f){var d,p,h,m,b,x,w,C=i&&i.__k||ii,y=t.length;for(u=hh(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+p,s.__=e,s.__b=e.__b+1,o=null,(c=s.__i=fh(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 ns(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||ch.test(t)?n:n+"px"}function $r(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||ns(e.style,t,"");if(n)for(t in n)i&&n[t]==i[t]||ns(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(oc,"$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]=sa,e.addEventListener(t,a?Ml:Al,a)):e.removeEventListener(t,a?Ml:Al,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 rs(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[Fr]==null)t[Fr]=sa++;else if(t[Fr]0?e:Mi(e)?e.map(fc):e.constructor!==void 0?null:et({},e)}function ph(e,t,n,i,l,a,s,o,u){var c,f,d,p,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 Xn=1,bh(yc,e)}function bh(e,t,n){var i=da(Zn++,2);if(i.t=e,!i.__c&&(i.__=[yc(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=da(Zn++,3);!ge.__s&&gc(n.__H,t)&&(n.__=e,n.u=t,pe.__H.__h.push(n))}function te(e){return Xn=5,gr(function(){return{current:e}},[])}function gr(e,t){var n=da(Zn++,7);return gc(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function yr(e,t){return Xn=8,gr(function(){return e},t)}function kh(){for(var e;e=mc.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Br),t.__h.some(Il),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){pe=null,ls&&ls(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),us&&us(e,t)},ge.__r=function(e){as&&as(e),Zn=0;var t=(pe=e.__c).__H;t&&(il===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(Il),t.__h=[],Zn=0)),il=pe},ge.diffed=function(e){ss&&ss(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(mc.push(t)!==1&&is===ge.requestAnimationFrame||((is=ge.requestAnimationFrame)||wh)(kh)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),il=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.__||Il(i)})}catch(i){t.some(function(l){l.__h&&(l.__h=[])}),t=[],ge.__e(i,n.__v)}}),os&&os(e,t)},ge.unmount=function(e){cs&&cs(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 ds=typeof requestAnimationFrame=="function";function wh(e){var t,n=function(){clearTimeout(i),ds&&cancelAnimationFrame(t),setTimeout(e)},i=setTimeout(n,35);ds&&(t=requestAnimationFrame(n))}function Br(e){var t=pe,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),pe=t}function Il(e){var t=pe;e.__c=e.__(),pe=t}function gc(e,t){return!e||e.length!==t.length||t.some(function(n,i){return n!==e[i]})}function yc(e,t){return typeof t=="function"?t(e):t}var vh=Symbol.for("preact-signals");function ha(){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}();qn!==void 0;){var n=qn;for(qn=void 0,ai++;n!==void 0;){var i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&kc(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 qn=void 0,Rt=0,ai=0,hs=0,si=void 0,oi=0;function bc(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=vh;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 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 Li(function(){return e.value})};Object.defineProperty(ve.prototype,"value",{get:function(){var e=bc(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!==hs&&(n.l=hs,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{ha()}}}});function H(e,t){return new ve(e,t)}function kc(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 wc(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 vc(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&&!kc(this))return this.f&=-2,!0;var e=se;try{wc(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,vc(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=bc(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 _c(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,fa(e),i}finally{se=n,ha()}}}function fa(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,_c(e)}function _h(e){if(se!==this)throw new Error("Out-of-order effect");vc(this),se=e,this.f&=-2,8&this.f&&fa(this),ha()}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,_c(this),wc(this),Rt++;var e=se;return se=this,_h.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||fa(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 Ii,Cr;function xn(e,t){le[e]=t.bind(null,le[e]||function(){})}function ci(e){if(Cr){var t=Cr;Cr=void 0,t()}Cr=e&&e.S()}function xc(e){var t=this,n=e.data,i=Sc(n);i.value=n;var l=gr(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(),lc(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}xc.displayName="_st";Object.defineProperties(ve.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:xc},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),ci();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}())),Ii=i,ci(n)});xn("__e",function(e,t,n,i){ci(),Ii=void 0,e(t,n,i)});xn("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],f=i[u];c===void 0?(c=xh(n,u,f,l),a[u]=c):c.o(f,l)}}}e(t)});function xh(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 Sc(e){return gr(function(){return H(e)},[])}function ll(e){var t=te(e);return t.current=e,Ii.__$f|=4,gr(function(){return Vt(function(){return t.current()})},[])}const ce=H([]),Oi=H([]),Di=H([]),Bt=H([]),gt=H(null),fs=H(""),Ol=H(null),er=H(null),Dl=H("all"),tr=H(null),ke=H(null),Et=H(null),Ri=H(null),pa=H(null),$c=H(null),at=H([]),ui=H({}),Un=H(null),Wn=H(null),Kn=H(null),Cc=H(null),ma=H([]),sn=H(null),Tc=H(""),Ec=H(0),ga=H(null),zr=H({}),Ft=H({}),Be=H({}),Re=H({}),ps=H(0);let Pc=0;function Sh(e){if(Date.now()-Pc<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)}Be.value=t,Re.value=n}function ya(e,t){Pc=Date.now(),fetch(`/api/pane/tabs/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}).catch(()=>{})}function br(e){const t=tr.value;if(!t)return;const n=(ce.value||[]).find(s=>s.target===t);if(!n)return;const i=n.pid,l=Be.value[i]||[],a=l.find(s=>s.path===e.path);a?e.line&&e.line!==a.line&&(Be.value={...Be.value,[i]:l.map(s=>s.path===e.path?{...s,line:e.line}:s)}):Be.value={...Be.value,[i]:[...l,{...e,target:t}]},Re.value={...Re.value,[i]:`file:${e.path}`},ya("open",{pid:i,path:e.path,line:e.line??null})}function Ac(e,t){const i=(Be.value[e]||[]).filter(l=>l.path!==t);Be.value={...Be.value,[e]:i},Re.value[e]===`file:${t}`&&(Re.value={...Re.value,[e]:"pane"}),ya("close",{pid:e,path:t})}function jr(e,t){Re.value={...Re.value,[e]:t},ya("activate",{pid:e,tab:t})}const nr=H(new Set),ft=H(new Set),pt=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 $h(e,t=at.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 Ch(e){e.key==="Escape"&&on.length&&(e.stopPropagation(),on[on.length-1](e))}typeof window<"u"&&window.addEventListener("keydown",Ch,!0);function Fe(e,t=!0){j(()=>{if(t)return on.push(e),()=>{const n=on.indexOf(e);n>=0&&on.splice(n,1)}},[e,t])}const Th={};function Eh(e,t){const n=Th,i=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,l=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Mc(e,i,l)}function Mc(e,t,n){if(Ph(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 ms(e.children,t,n)}return Array.isArray(e)?ms(e,t,n):""}function ms(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 ys={}.hasOwnProperty;function Lc(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 He(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Se=wt(/[A-Za-z]/),Ee=wt(/[\dA-Za-z]/),Lh=wt(/[#-'*+\--9=?A-Z^-~]/);function di(e){return e!==null&&(e<32||e===127)}const Rl=wt(/\d/),Ih=wt(/[\dA-Fa-f]/),Oh=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 Fi=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 Bh(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(Fi(e))return 2}function Ni(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};ks(d,-u),ks(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,Ni(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(ws,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 Yh(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 al={name:"codeIndented",tokenize:Xh},Zh={partial:!0,tokenize:ef};function Xh(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(Zh,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 ef(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 tf={name:"codeText",previous:rf,resolve:nf,tokenize:lf};function nf(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 Nc(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||di(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 zc(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 ff={name:"definition",tokenize:mf},pf={partial:!0,tokenize:gf};function mf(e,t,n){const i=this;let l;return a;function a(h){return e.enter("definition"),s(h)}function s(h){return Bc.call(i,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function o(h){return l=He(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 Nc(e,f,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function f(h){return e.attempt(pf,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 gf(e,t,n){return i;function i(o){return oe(o)?Vn(e,l)(o):n(o)}function l(o){return zc(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 yf={name:"hardBreakEscape",tokenize:bf};function bf(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 kf={name:"headingAtx",resolve:wf,tokenize:vf};function wf(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 vf(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 _f=["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"],_s=["pre","script","style","textarea"],xf={concrete:!0,name:"htmlFlow",resolveTo:Cf,tokenize:Tf},Sf={partial:!0,tokenize:Pf},$f={partial:!0,tokenize:Ef};function Cf(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 Tf(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):Se(_)?(e.consume(_),s=String.fromCharCode(_),x):n(_)}function p(_){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&&_s.includes(he)?(l=1,i.interrupt?t(_):F(_)):_f.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):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(Sf,Z,q)(_)):_===null||U(_)?(e.exit("htmlFlowData"),q(_)):(e.consume(_),F)}function q(_){return e.check($f,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 _s.includes(X)?(e.consume(_),W):F(_)}return Se(_)&&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 Ef(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 Pf(e,t,n){return i;function i(l){return e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),e.attempt(kr,t,n)}}const Af={name:"htmlText",tokenize:Mf};function Mf(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),A):n(k)}function c(k){return k===45?(e.consume(k),f):k===91?(e.consume(k),a=0,m):Se(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 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 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||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"),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 ka={name:"labelEnd",resolveAll:Df,resolveTo:Rf,tokenize:Ff},Lf={tokenize:Nf},If={tokenize:Bf},Of={tokenize:zf};function Df(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:Qf},exit:Zf,name:"list",tokenize:Jf},Vf={partial:!0,tokenize:Xf},Gf={partial:!0,tokenize:Yf};function Jf(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:Rl(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 Rl(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(kr,i.interrupt?n:f,e.attempt(Vf,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 Qf(e,t,n){const i=this;return i.containerState._closeFlow=void 0,e.check(kr,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(Gf,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 Yf(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 Zf(e){e.exit(this.containerState.type)}function Xf(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 xs={name:"setextUnderline",resolveTo:ep,tokenize:tp};function ep(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 tp(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 np={tokenize:rp};function rp(e){const t=this,n=e.attempt(kr,i,e.attempt(this.parser.constructs.flowInitial,l,re(e,e.attempt(this.parser.constructs.flow,l,e.attempt(of,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 ip={resolveAll:Hc()},lp=jc("string"),ap=jc("text");function jc(e){return{resolveAll:Hc(e==="text"?sp: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 wp(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 vp(e){const i={constructs:Lc([yp,...(e||{}).extensions||[]]),content:l(Dh),defined:[],document:l(Fh),flow:l(np),lazy:{},string:l(lp),text:l(ap)};return i;function l(a){return s;function s(o){return bp(i,a,o)}}}function _p(e){for(;!Fc(e););return e}const Ss=/[\0\t\n\r]/g;function xp(){let e=1,t="",n=!0,i;return l;function l(a,s,o){const u=[];let c,f,d,p,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 Ne=J.tokenStack[J.tokenStack.length-1];(Ne[1]||Ts).call(J,void 0,Ne[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 p;function p(){let h=Kc,m,b,x;if(a(u,c,f[f.length-1]||void 0)&&(h=Np(n(u,f)),h[0]===Ps))return h;if("children"in u&&u.children){const w=u;if(w.children&&h[0]!==Rp)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=Es(e,"(");let a=Es(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 Vc(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||zt(n)||Fi(n))&&(!t||n!==47)}function em(){this.buffer()}function tm(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function nm(){this.buffer()}function rm(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function im(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=He(this.sliceSerialize(e)).toLowerCase(),n.label=t}function lm(e){this.exit(e)}function am(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=He(this.sliceSerialize(e)).toLowerCase(),n.label=t}function sm(e){this.exit(e)}function om(){return{enter:{gfmFootnoteCallString:em,gfmFootnoteCall:tm,gfmFootnoteDefinitionLabelString:nm,gfmFootnoteDefinition:rm},exit:{gfmFootnoteCallString:im,gfmFootnoteCall:lm,gfmFootnoteDefinitionLabelString:am,gfmFootnoteDefinition:sm}}}function cm(){return{canContainEols:["delete"],enter:{strikethrough:um},exit:{strikethrough:dm}}}function um(e){this.enter({type:"delete",children:[]},e)}function dm(e){this.exit(e)}function hm(){return{enter:{table:fm,tableData:As,tableHeader:As,tableRow:mm},exit:{codeText:gm,table:pm,tableData:cl,tableHeader:cl,tableRow:cl}}}function fm(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 pm(e){this.exit(e),this.data.inTable=void 0}function mm(e){this.enter({type:"tableRow",children:[]},e)}function cl(e){this.exit(e)}function As(e){this.enter({type:"tableCell",children:[]},e)}function gm(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,ym));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function ym(e,t){return t==="|"?t:e}function bm(){return{exit:{taskListCheckValueChecked:Ms,taskListCheckValueUnchecked:Ms,paragraph:km}}}function Ms(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function km(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 Mm={tokenize:Bm,partial:!0};function Lm(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Rm,continuation:{tokenize:Fm},exit:Nm}},text:{91:{name:"gfmFootnoteCall",tokenize:Dm},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Im,resolveTo:Om}}}}function Im(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=He(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 Om(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 Dm(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(He(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 Rm(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=He(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 Fm(e,t,n){return e.check(kr,t,e.attempt(Mm,t,n))}function Nm(e){e.exit("gfmFootnoteDefinition")}function Bm(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 zm(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 jm{constructor(){this.map=[]}add(t,n,i){Hm(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 Hm(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 Km(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 jm;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 Ls(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 Vm={name:"tasklistCheck",tokenize:Jm};function Gm(){return{text:{91:Vm}}}function Jm(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:Qm},t,n)(u):n(u)}}function Qm(e,t,n){return re(e,i,"whitespace");function i(l){return l===null?n(l):t(l)}}function ru(e){return Lc([_m(),Lm(),zm(),Um(),Gm()])}const Ym={pr_title:"from the PR title",branch:"from the branch name"};function wr(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=Ym[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 Zm=/^([a-z-]+): (.+)$/;function zl(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=Zm.exec(a.trim());if(!s)return null;i.push([s[1],s[2].trim()])}return i.length?i:null}function iu(e){return e.split(",").map(t=>t.trim().replace(/^`+|`+$/g,""))}const Xm=/^([\w.-]*[\w-]\/[\w./-]*[\w-]|[\w-]+(?:\.[\w-]+)*\.[A-Za-z][A-Za-z0-9]{1,5})(?::(\d+)(?:-(\d+))?)?$/;function zi(e){const t=Xm.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 eg(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?zi(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 tg=new Set(["new-subsystem","extension","reuse","system-touch","behavior"]);function ng(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 rg(e){var f,d,p;const t=String(e||""),i=Uc(t,{extensions:[ru()],mdastExtensions:[Gc()]}).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=Ur(i[c]),c++;const h=((d=i[c])==null?void 0:d.type)==="blockquote"?zl(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=Ur(i[c]),c++)}for(;cn.kind==="ctx"||n.kind==="add").length;return e.new_start+Math.max(t,1)-1}function lg(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&&ig(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 Is(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 ji={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 ag(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 sg=(e,t)=>typeof e=="string"?e.localeCompare(t):e-t;function og(e,t=null){const n=[...e||[]].sort((a,s)=>{var o,u;return Is(a)-Is(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&&ji[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*sg(o,u))})}function cg(e,t){const n=ji[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 ug(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=wr(i))==null?void 0:u.id,i.linked_linear_title].filter(Boolean).join(" ").toLowerCase();return n.every(c=>l.includes(c))}):e||[]}function Os(e){return(e||[]).filter(t=>!fi(t)).reduce((t,n)=>t+(n.unresolved||0),0)}const dg={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(dg).map(([e,t])=>({id:e,name:t.name,sprite:t}))];function lu(e){return pi.find(t=>t.id===e)||pi[0]}const au=10,_a=12,hg=19,fg=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 xa(e,{x0:t,sitting:n,height:i=_a}){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?fg:hg)-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 pg=.75,ul=(e,t=pg)=>({fill:"none",stroke:e,"stroke-width":t,"stroke-linecap":"square"});function mg(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 gg=new Set(["happy","x","down"]);function yg(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:ul(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 kg(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 wg(e){const{cx:t,top:n,w:i}=e.anchors.hat;return`translate(${t} ${n}) scale(${N(i/12)}) translate(-9 -9)`}function vg(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 Ds(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 Sa={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 Hi(e,t){const n=yn(e),{reach:i,at:l}=Sa[t];return[N(e.limb.root[0]+i),N(n.y+l*n.h)]}function _g(e,t,{scale:n,tx:i,ty:l}){const[a,s]=Hi(e,t);return[N(i+n*a),N(l+n*s)]}function Rs({scale:e,tx:t,ty:n},[i,l]){return[N((i-t)/e),N((l-n)/e)]}function jl(e,t,n=Hi(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 $a(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}]:[]:$a(i.g,t||!!i.arms,l)})}function xg(e){return $a(e.root).length===0}function Sg(e){const t=$a(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:jl(e,null,[N(e.limb.root[0]+1.6),N(n.y+.12*n.h)])}]}const su="#ff3b2f",$g="#f3f5f8";function Cg(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:$g,"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"}],ou={ui:"hanken",code:"plex-mono"};function cu(e,t){return mi.find(n=>n.id===e)||mi.find(n=>n.id===ou[t])}const Ye=H([]);let Tg=1;function bn(e,t="info",n=4e3){const i=Tg++;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 Eg(){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 dl(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(()=>dl(!1),5e3),addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&dl(!0)}),addEventListener("pagehide",()=>dl(!0)));const Hl={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 _e(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 Pg(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 Ag(e){return e?{"approve askuserquestion":"needs answer","permission prompt":"needs approval","dialog open":"needs input"}[e.toLowerCase()]||e.toLowerCase():"needs input"}function uu(e){if(!e)return null;const t=e.toLowerCase();return t==="permission prompt"?"permission":t==="approve askuserquestion"?"question":"dialog"}function du(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 hu(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`,l=e.gb==null?`Claude has been running ${i}`:`Claude is using ${e.gb}GB after ${i}`;return{label:e.trigger==="mem"?`${e.gb}G`:`${t}d`,title:`${l} — consider exiting and resuming this session`,cls:`mem-${e.tier}`}}function rr(e,t){return e?`https://github.com/${e}/pull/${t}`:null}function qi(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 Mg(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 Ui(){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 Ng(),me.value}catch{return me.value={...me.value,loaded:!1},null}}function Wr(){return G().commands||[]}async function Lg({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 Ig(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 Og(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 Dg(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 Ui(),!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 Rg(e){me.value={...G(),ui:e}}function Er(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 Ui(),!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 fu(e){if(!e)return[];const t=G().windows[e];return[...(t==null?void 0:t.pinned_files)||[]]}function Fg(e,t){if(!e||!t)return Promise.resolve(!1);const n=fu(e),i=n.includes(t)?n.filter(l=>l!==t):[...n,t];return Kr(e,{pinned_files:i})}async function Ng(){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 Bg(e,t){return $e({track_order:e},t)}function ir(){return{...(G().ui||{}).tabs_by_track||{}}}function zg(e){return $e({tabs_by_track:e})}function Ca(){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 pu(e,t){const n=lr();return n[e]=t,$e({rail_collapsed:n})}function jg(){var e;return((e=G().ui)==null?void 0:e.last_selected)||null}function yt(e){return $e({last_selected:e})}function Hg(){var e;return((e=G().ui)==null?void 0:e.launch_profile)||"default"}function qg(e){return $e({launch_profile:e})}function mu(){var e;return lu((e=G().ui)==null?void 0:e.tama_critter).id}function Ug(e){return $e({tama_critter:e})}function ar(e){var t;return cu((t=G().ui)==null?void 0:t[`${e}_font`],e)}function Wg(e,t){return $e({[`${e}_font`]:t})}const Kg={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{...Kg,...((e=G().ui)==null?void 0:e.notify)||{}}}function Vg(e,t){return $e({notify:{...yi(),[e]:t}})}function Ta(){var e;return[...((e=G().ui)==null?void 0:e.pinned_pids)||[]]}function Gg(e){return $e({pinned_pids:e})}function Jg(e){const t=Ta(),n=t.includes(e)?t.filter(i=>i!==e):[...t,e];return Gg(n)}function Qg(e){var t;return((t=G().ui)==null?void 0:t[e])??null}function Fs(e,t){return $e({[e]:t})}function Ea(e){var t;return!!((t=G().ui)!=null&&t[`${e}_hidden`])}function Yg(e,t){return $e({[`${e}_hidden`]:t})}function gu(e){var t,n;return((n=(t=G().ui)==null?void 0:t.detail_mode_by_pid)==null?void 0:n[e])||null}function ql(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 Pa(){const e=G().ui||{};return{merged:e.clawd_merged,furious:e.clawd_furious}}async function yu(e,t){var n;return G().loaded||await Ui(),!G().loaded||((n=Pa()[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 Aa(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 Zg(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 bu({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 Xg(e){if(Ve())try{await Aa("periscope:notification-clicked",e)}catch(t){console.warn("[tauri] notification-click listener failed:",t)}}async function e1(e){if(Ve())try{await Aa("periscope:notification-opened",e)}catch(t){console.warn("[tauri] notification-opened listener failed:",t)}}async function t1(e){if(Ve())try{await Aa("periscope:notification-action",e)}catch(t){console.warn("[tauri] notification-action listener failed:",t)}}async function n1(e){if(Ve())try{await $n("plugin:event|emit",{event:"periscope:notify-categories",payload:e})}catch(t){console.warn("[tauri] setNotifyCategories failed:",t)}}function Wi(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 r1(){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 i1(e){return!!(e!=null&&e.asked_question)&&!(e!=null&&e.waiting_for)}function Ns(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 Ma(e,t,n,i=new Set){const l=Ia(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=>!La(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 ku(e,t,n,i=new Set){const l=Ia(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=>!La(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 La(e,t){const n=t[e.target];return n?Math.max(n.focused_at||0,n.acted_at||0)>e.ts:!1}function l1(e){return e.length}const a1=600,s1=3600;function wu(e,t){const n=(t||0)-(e||0);return n>=s1?"urgent":n>=a1?"stale":"fresh"}function vu(e,t,n=new Set){var a;const i=Ia(e),l=new Map;for(const s of t||[]){if(s.kind!=="need_human"||n.has(s.id)||La(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=vu(e,t,n),o=new Map;for(const f of Ma(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 xu(e){return(e||[]).filter(t=>t.state==="working").map(t=>({kind:"live",pid:t.pid,w:t}))}function o1(e,t){const n={};for(const i of t||[])n[i.pid]=i;return(e||[]).map(i=>n[i]).filter(Boolean)}function c1(e){return(e||[]).filter(t=>t.kind==="done"||t.kind==="info")}function Ia(e){const t={};for(const n of e||[])t[n.target]=n;return t}const Oa=er;let Bs=!1;function jt(e){e&&st((ce.value||[]).find(t=>t.target===e))}function st(e){e!=null&&e.pid&&(ke.value=`pane:${e.pid}`,yt({kind:"pane",pid:e.pid}))}function Su(e){i1(e)&&(ft.value=new Set([...ft.value,e.pid])),st(e)}function $u(e){e!=null&&e.pid&&(pt.value=new Set([...pt.value,e.pid]))}function Cu(e){$u(e),st(e)}function u1(){Bs||(Bs=!0,Xg(e=>jt(e)))}function Tu(e,t){!e||!t||(ke.value=`review:${e}/${t.replace(/\//g,"--")}`,yt({kind:"review",repo:e,branch:t}))}function Da(){ke.value="reviews",yt({kind:"reviews"})}const hl=[{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 d1(){const[e,t]=B(!1),n=te(null),i=Dl.value,l=(hl.find(o=>o.key===i)||hl[0]).label,a=yr(()=>t(!1),[]);Fe(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){Dl.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:hl.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 Eu=Vt(()=>Ea("rail")),bi=Vt(()=>Ea("side"));function Ul(e){return Yg(e,!Ea(e))}function zs({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 h1(){const e=!Eu.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:()=>Ul("rail"),children:r(zs,{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:()=>Ul("side"),children:r(zs,{side:"right",shown:t})})]})}function sr(e){return e>=1024?`${(e/1024).toFixed(1)}G`:`${e}M`}function Pu(e){return e==null?"–":`${Math.round(e)}%`}function f1(e){var t;return e.server.mem_mb+(((t=e.webview)==null?void 0:t.mem_mb)||0)+e.panes.mem_mb}function p1(e){return e.filter(t=>t.res).map(t=>({w:t,...t.res})).sort((t,n)=>n.mem_mb-t.mem_mb)}function m1(e){return`load ${e.load1} · swap ${sr(e.swap_used_mb)}/${sr(e.swap_total_mb)} · ${e.mem_free_pct}% free`}const g1="CPU per core: 100% is one core fully busy";function Pr({label:e,group:t,onClick:n}){const i=r(K,{children:[r("span",{class:"res-label",children:e}),r("span",{class:"res-mem",children:sr(t.mem_mb)}),r("span",{class:"res-cpu",title:g1,children:Pu(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 y1(){const e=te(null),[t,n]=B(!1),i=$c.value,l=yr(()=>n(!1),[]);return Fe(l,t),j(()=>{if(!t)return;function a(s){e.current&&!e.current.contains(s.target)&&l()}return document.addEventListener("click",a),()=>document.removeEventListener("click",a)},[t]),j(()=>{!i&&t&&l()},[i,t]),i?r("div",{class:"res-dd",ref:e,children:[r("button",{type:"button",class:"res-pill",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":t?"true":"false",onClick:()=>n(!t),children:["▣ ",sr(f1(i))]}),r("div",{class:"tb-dd-menu res-menu",role:"dialog",hidden:!t,children:[r(Pr,{label:"periscope server",group:i.server}),i.webview&&r(Pr,{label:"webview",group:i.webview}),p1(ce.value||[]).map(({w:a,mem_mb:s,cpu_pct:o})=>r(Pr,{label:_e(a),group:{mem_mb:s,cpu_pct:o},onClick:()=>{st(a),l()}},a.pid)),r(Pr,{label:"elsewhere",group:i.elsewhere}),r("div",{class:"res-machine",children:m1(i.machine)})]})]}):null}async function Au(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 b1(){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 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:()=>Au(i.id),children:i.id===null&&t===null&&n?`auto → ${gn(n.account)}`:i.label},i.id??"auto"))]})}const Ra=["default","low","medium","high","xhigh","max"];async function k1(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 w1(){const e=Kn.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"}),Ra.map(t=>r("button",{type:"button",class:`spawn-acct-btn${e===t?" is-active":""}`,onClick:()=>k1(t),children:t},t))]})}const or=[{id:"default",label:"default"},{id:"fable",label:"fable"},{id:"opus[1m]",label:"opus 1m"},{id:"sonnet",label:"sonnet"}],v1=[{id:"auto",label:"auto"},...or];async function _1(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 x1(){const e=Wn.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"}),v1.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:()=>_1(n.id),children:n.id==="auto"&&e==="auto"&&t?`auto → ${t.model??"default"}`:n.label},n.id))]})}const Mu={cols:0,rows:0,shrunkFrom:0},S1=4,$1=(e,t)=>e>0&&t>0?Math.min(e,t):e||t;function C1(e,t){return t>0&&Math.abs(e-t)<=S1?t:e}function T1(e,t,n,i){return{cols:e||n,rows:$1(t,i)}}function E1(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 Lu(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 L1(){de&&de.readyState===WebSocket.OPEN&&de.send(JSON.stringify({type:"reconcile"}))}function I1(){if(!Y)return!0;const e=Y.buffer.active;return e.viewportY>=e.baseY}function Nu(e){Ze=e}let ur=null;function Hs(e){ur=e}const Bu=/\b(?:https?|wss?):\/\/[^\s)"'`<>]+/g,O1=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(Bu)){const h=p.index,m=h+p[0].length;if(s>=h&&s{if(n.button!==0)return;const i=R1(n,e);i&&(Qt={url:i,x:n.clientX,y:n.clientY})},Us=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;Wi(a)||e.writeln(`\r +\x1B[31m[periscope: failed to open ${a}]\x1B[0m`)},t.addEventListener("mousedown",qs,!0),t.addEventListener("mouseup",Us,!0))}function B1(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"&&ur&&ur(m))},hover(){},leave(){}})}}a(Bu,"url"),a(O1,"file"),a(D1,"file"),n(l)}})}function z1(){try{return localStorage.getItem("periscope.noWebgl")==="1"}catch{return!1}}function j1(){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 Ws(e){var n;if(!((n=document.fonts)!=null&&n.load))return;const t=`${Iu.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,vr())},()=>{})}function H1(){if(!Y){if(tt=document.createElement("div"),tt.className="xterm-host",en=ar("code"),Y=new Terminal({...Iu,fontFamily:en.stack,theme:P1,linkHandler:{allowNonHttpProtocols:!0,activate(e,t){if(t.startsWith("file://")){if(!e.metaKey&&!e.ctrlKey||!ur)return;let n=t.slice(7);n.startsWith("localhost/")&&(n=n.slice(9));try{n=decodeURIComponent(n)}catch{}ur(n);return}Wi(t)}}}),Y.open(tt),Ws(en),lt(()=>{const e=ar("code");e!==en&&(en=e,Y.options.fontFamily=e.stack,Ws(e))}),Y.attachCustomWheelEventHandler(e=>{if(!Fa||!e.deltaY)return!0;const t=F1(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*A1;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}),z1())console.warn("[periscope] WebGL renderer disabled via localStorage periscope.noWebgl");else try{Mt=new WebglAddon.WebglAddon,Mt.onContextLoss(()=>{j1()}),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)}B1(Y),N1(Y),cr=new FitAddon.FitAddon,Y.loadAddon(cr),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(()=>{Ze&&(Ze.classList.add("bell-pulse"),setTimeout(()=>Ze.classList.remove("bell-pulse"),400))})}}function q1(e){ye("terminal.open",{target:e});const t=Y!==null;if(H1(),Ze&&tt.parentElement!==Ze&&Ze.appendChild(tt),t){try{Y.reset()}catch{}Fa=!1,tn=0}if(Y.focus(),Fu(),za(),Lt)try{Lt.disconnect()}catch{}Lt=new ResizeObserver(vr),Ze&&Lt.observe(Ze),ki=e,wi=!1,Fn=0,Vr=!1,zu(e,ot.cols,ot.rows)}function zu(e,t=0,n=0){let l=`${location.protocol==="https:"?"wss":"ws"}://${location.host}/ws/pane?${Pg(e)}`;t>0&&n>0&&(l+=`&cols=${t}&rows=${n}`,cn=Lu(cn,{cols:t,rows:n}));const a=new WebSocket(l);a.binaryType="arraybuffer",de=a,a.onopen=()=>{Fn>0&&Y&&Y.writeln(`\r +\x1B[32m[periscope: reconnected]\x1B[0m`),Fn=0,Vr=!1},a.onmessage=s=>{if(typeof s.data=="string")try{const o=JSON.parse(s.data);o.type==="size"?(Ba=o.cols,Ki=o.rows,za(),vr()):o.type==="mouse"&&(Fa=!!o.on)}catch{Y.write(js(s.data,Wl))}else Y.write(js(new Uint8Array(s.data),Wl))},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(Fn,o.length-1)]||4e3;Fn+=1,At&&clearTimeout(At),At=setTimeout(()=>{At=null,!(!Y||ki!==e||wi)&&zu(e,ot.cols,ot.rows)},u)}}function vr(){It&&clearTimeout(It),It=setTimeout(()=>{if(It=null,!Y||!cr||Na||!Fu())return;za();const e=E1(ot,cn,Ki);e&&de&&de.readyState===WebSocket.OPEN&&(cn=Lu(cn,e),de.send(JSON.stringify({type:"resize",...e})))},80)}function U1(){if(wi=!0,ki=null,At&&(clearTimeout(At),At=null),cn=Mu,Ba=0,Ki=0,It&&(clearTimeout(It),It=null),Lt){try{Lt.disconnect()}catch{}Lt=null}if(de){try{de.close()}catch{}de=null}tt!=null&&tt.parentElement&&tt.remove()}function Ks(e){Y&&Y.writeln(e)}function vi(){if(Y)try{Y.scrollToBottom()}catch{}}function W1(){!Y||!cr||vr()}function K1(){Na=!0}function V1(){Na=!1,vr()}function Vs(e,t={}){return bt?bt.findNext(e,t):!1}function Gs(e,t={}){return bt?bt.findPrevious(e,t):!1}function G1(){bt&&bt.clearDecorations()}let Gn=null,Gr=null;function J1(e,t,n={}){ju(),Nu(e),Wl=n.agent||null,n.onPaste&&(Gn=n.onPaste,e.addEventListener("paste",Gn,!0)),Gr=e,q1(t),requestAnimationFrame(()=>requestAnimationFrame(()=>{W1(),vi()})),setTimeout(vi,300)}function ju(){U1(),Gr&&Gn&&Gr.removeEventListener("paste",Gn,!0),Gn=null,Gr=null,Nu(null)}function Hu(e){return typeof e!="string"?null:e.startsWith("pane:")?e.slice(5):null}function Q1(e,t){const n=Hu(e),i=n?t==null?void 0:t[n]:null;return typeof i=="string"&&i.startsWith("file:")?"document":"terminal"}function Y1(e){return(e.metaKey||e.ctrlKey)&&(e.key==="r"||e.key==="R")}function Z1(e){return e.repeat||!(e.metaKey||e.ctrlKey)||e.shiftKey||e.code!=="KeyB"?null:e.altKey?"side":"rail"}function X1(e=window){e.addEventListener("keydown",t=>{const n=Z1(t);if(n){t.preventDefault(),Ul(n);return}if(Y1(t)){if(t.preventDefault(),t.shiftKey){location.reload();return}if(Q1(ke.value,Re.value)==="document"){ps.value=ps.value+1;return}L1()}})}function Mr(e,t){if(!t||!e)return e;const n={...e};return e.fill&&(n.fill=Ds(e.fill,t)),e.stroke&&(n.stroke=Ds(e.stroke,t)),n}const Js=e=>e!=null&&e.stroke?{stroke:su,"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),...Js(e.a)}):r("rect",{class:e.cls,x:c,y:f,width:d,height:p,...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,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,...Js(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,...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,f)=>r(Oe,{n:c,mood:t,asleep:n,hide:i,tint:l,rest:a,paws:s,seated:o},f))})}function Vi({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=gg.has(i),b=u??(o&&Sa[o]?Hi(e,o):null),x=!!b||f&&xg(e),w=t==="furious"&&!n,C=v=>v.role!==void 0||(v.g||[]).some(C),y=p?mg(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&&bg(e,i).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`face-${E}`)),s&&vg(e,s).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`worn-${E}`)),l&&kg(e,!!b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`startle-${E}`)),h,b&&jl(e,o,b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`hold-${E}`)),f&&Sg(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`cheer-${E}`)),w&&r("g",{class:"tama-flush",fill:su,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&&jl(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&&Cg(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`teeth-${E}`))]},w?"furious":"calm")}function e0(e){return e==null?"":e>=80?" ctx-hot":e>=60?" ctx-warn":""}function Kl(e){return e.ctx_class&&e.ctx_class!=="none"?` ctx-${e.ctx_class}`:e0(e.context_pct)}const Qs=["bell","api","done","merged","ctx","ci","update"],qu=600;function Ys(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 ${_e(t)}`,...n});function t0({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=_u(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=ku(e,t,n,l).filter(g=>f(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"?Mn("ready",g.w):{action:"reveal",target:g.target,says:`open ${$}`}})}const C=s.filter(g=>u-g.atKl(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?`${_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: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,$)=>Qs.indexOf(g.kind)-Qs.indexOf($.kind))}function n0(e){return e.slice(1).reduce((t,n)=>t+n.count,0)}const r0=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function i0(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?r0[n.getDay()]:null,time:a}}function l0({day:e,time:t}){return`every account is at its limit until ${e?`${e} `:""}${t}`}const a0=new Set(["done","merged","ci","api","ctx"]);function Uu(e,t){const n=e==="code";return{atDesk:n,moodShown:n&&!t,showsPanes:n&&!a0.has(t)}}function s0({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 o0=600;function ja(e,t){return!!(e!=null&&e.fetched_at)&&t-e.fetched_at>o0}function Ha(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 Wu(e){return e!=null&&e.hot?"furious":Ha(e)?"grumpy":"calm"}const c0={session:"session",week_all:"week",week_opus:"opus",week_sonnet:"sonnet"};function qa(e){return c0[e]||e.replace(/^week_/,"")}const Ku=[{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"}],Vu=[{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,Zs=16,ze=.5,Ua=Ku.map(e=>{const t=e.id==="code"?{...e,id:"nap",label:"napping at the desk"}:e;return t.to===un?{...t,to:Zs}:t.from===un?{...t,from:Zs}:t}),Gu=e=>e.getDay()===0||e.getDay()===6,Gi=(e,t)=>e.find(n=>t>=n.from&&tGi(Gu(e)?Vu:Ua,un),Xs=[{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"]}],d0={run:"trick-or-treating",kids:"trick-or-treating with the kids"},h0=[{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"]}],f0=[{id:"pancakes",label:"pancakes"},{id:"waffles",label:"waffles"},{id:"eggs",label:"eggs and bacon"}],p0={id:"roast",label:"a roast"},eo={halloween:{id:"pie",label:"pumpkin pie"},summer:{id:"icecream",label:"ice cream"}},Ju=e=>t=>!t.seasons||t.seasons.includes(_r(e)),dn=e=>e.getHours()+e.getMinutes()/60;function Qu(e,t){let n=2166136261;for(const i of`${Ji(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=Qu(t,n)%e.length;for(;i.includes(e[l].id);)l=(l+1)%e.length;return e[l]}const m0=e=>Math.floor(e/6e4)*6e4,Wa=e=>(e.walls||[]).map(t=>t.map(m0)).filter(([t,n])=>tWa(t).some(([n,i])=>n<=e.getTime()&&e.getTime()Wa(e).map(t=>t.map(g0)).filter(([t,n])=>ti<=n&&n({...e,label:`having ${t.label} for ${n}`,dish:t.id});function y0(e,t){var u;if(e.meal==="brunch")return fl(e,Jr(f0,t,"brunch"),"brunch");const n=(u=Qi(t))==null?void 0:u.id,i=e.meal==="dinner"&&(eo[n]||eo[_r(t)]),l=e.from+ze;if(i&&dn(t)>=l)return{...fl(e,i,"dessert"),from:l};const a=h0.filter(Ju(t)),s=Jr(a,t,"lunch"),o=e.meal==="lunch"?s:n==="yearend"?p0:Jr(a,t,"dinner",[s.id]);return{...fl(e,o,e.meal),...i?{to:l}:{}}}function b0(e,t,n){var p;const i=h=>Xs.find(m=>m.id===h),l=(e.to-e.from)/ze,a=h=>(h-e.from)/ze,s=h=>e.from+h*ze,o=[un,un+ze].map(a),u=h=>!!Gi(Xu(dr(t,s(h)),n),s(h)).pastime,c=[],f=Xs.filter(Ju(t)),d=()=>{var m,b;const h=[];for(let x=0;x{const x=(h+b)%2?"kids":"run";c[m]={...i(x),label:d0[x],trick:!0}})}else{t.getDay()===5&&(c[a(un+ze)]=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 hr(e,t={}){const n=Gi(Xu(e,t),e.getHours());if(n.meal)return y0(n,e);if(n.pastime){const o=u0(e),u=Math.floor((dn(e)-o.from)/ze),c=o.from+u*ze;return{...o,...b0(o,e,t)[u],from:c,to:c+ze}}if(n.id!=="code"&&n.id!=="nap")return n;const i=e.getTime(),l=Zu(t).flat(),a=Math.max(dr(e,n.from).getTime(),...l.filter(o=>o<=i)),s=Math.min(dr(e,n.to).getTime(),...l.filter(o=>o>i));return{...n,from:dn(new Date(a)),to:dn(new Date(s))}}function ed(e,t={}){const n=e.getTime(),{to:i}=hr(e,t);return Math.min(dr(e,i).getTime(),...Wa(t).flat().filter(l=>l>n))-n}function k0(e,t={}){const n=hr(e,t);let i=e;for(let l=0;l<8;l++){i=new Date(i.getTime()+ed(i,t));const a=hr(i,t);if(a.id!==n.id||a.dish!==n.dish)return{at:i,activity:a}}return null}function to(e,t={}){var i;const n=hr(e,t);return`${n.from}|${n.id}|${n.dish||""}|${_r(e)}|${((i=Qi(e))==null?void 0:i.id)||""}|${ad(e)||""}|${Yu(e,t)}`}const _i=e=>String(e).padStart(2,"0");function Ji(e){return`${e.getFullYear()}-${_i(e.getMonth()+1)}-${_i(e.getDate())}`}function td(e){return`${Ji(e)}T${_i(e.getHours())}:${_i(e.getMinutes())}`}function nd(e,t){const n=Ji(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 w0={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]},v0=["spring","summer","autumn","winter"];function _0(e,t){const[n,i,l,a,s]=w0[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 rd(e){const t=e.getFullYear(),n=xi(e);return[t-1,t].flatMap(i=>v0.map(l=>({season:l,start:_0(l,i)}))).sort((i,l)=>i.start-l.start).filter(i=>xi(i.start)<=n).pop()}function _r(e){return rd(e).season}function id(e){return xi(rd(e).start)===xi(e)}const x0={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"},S0=[{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 ld(e){const t=(e.getMonth()+1)*100+e.getDate();return S0.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 Qi(e){return id(e)?null:ld(e)}function ad(e){var t;return id(e)?x0[_r(e)]:((t=ld(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 no(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 $0(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||ja(l,t)))for(const[a,s]of Object.entries(l.meters)){if(!s)continue;const o=Wu(s);wn[o].rank>wn[n.mood].rank&&(n={mood:o,account:i,meter:a,atLimit:(s.percent??0)>=100})}return n}function C0({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`${qa(t)} usage${l} ${a}`}function Vl(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 T0(e){return Vl(dn(e))}const V=9,Ht="#d97757",we="#2b1d16",Cn=["...############..","...############..",".################","...############.."],E0=[5,12],sd=["....#.#....#.#...",".....#.#..#.#...."];function qt(e){const t=[];return e.forEach((n,i)=>{for(let l=0;lt.key!==e)}function A0(){ro||(ro=!0,lt(()=>{const e=fr.peek(),t=s0({states:io,parties:e},ce.value,Date.now()/1e3);io=t.states,(t.parties.length!==e.length||t.parties.some((n,i)=>n.key!==e[i].key))&&(fr.value=t.parties),t.parties.some(n=>!e.some(i=>i.key===n.key))&&yu("merged",td(new Date))}))}const M0="modulepreload",L0=function(e){return"/"+e},lo={},Yi=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=L0(u),u in lo)return;lo[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":M0,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 Lr=null;function I0(){return Lr||(Lr=Yi(()=>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 O0=0;function D0({code:e}){const t=te(null),[n,i]=B(null);return j(()=>{let l=!0;return i(null),I0().then(a=>a.render(`md-mermaid-${++O0}`,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 od=/^([a-z][a-z0-9+.-]*:|\/|#)/i;function ao(e,t){return!t.resolveUrl||od.test(e)?e:t.resolveUrl(e)}function je(e,t){return(e||[]).map((n,i)=>R0(n,t,i))}function R0(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(` +`):[e.value],l=[];return i.forEach((a,s)=>{if(s&&l.push(r("br",{},`${n}b${s}`)),!t.cite){l.push(a);return}eg(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?zi(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:je(e.children,t)},n);case"emphasis":return r("em",{children:je(e.children,t)},n);case"delete":return r("del",{children:je(e.children,t)},n);case"link":return r("a",{class:"md-link",href:ao(e.url,t),target:"_blank",rel:"noopener",children:je(e.children,{...t,cite:null})},n);case"image":return!od.test(e.url)&&!t.resolveUrl?e.alt||e.url:r("img",{class:"md-img",src:ao(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?je(e.children,t):e.value??null}}function F0(e,t,n){const i=(e.children||[]).map((l,a)=>l.type==="paragraph"&&!e.spread?je(l.children,t):Ka(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 N0(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?je(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?je(d.children,t):""},p))},f))})]},n)}function Ka(e,t,n,i){switch(e.type){case"paragraph":return r("p",{class:"md-p",children:je(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:je(e.children,t)},n)}case"code":return t.mermaid&&e.lang==="mermaid"?r(D0,{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"?zl(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?iu(s).map((u,c)=>{const f=zi(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)=>Ka(a,t,s))},n)}case"list":{const l=(e.children||[]).map((a,s)=>F0(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 N0(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:je(e.children,t)},n):e.value?r("p",{class:"md-p",children:e.value},n):null}}function pr(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=Uc(n,{extensions:[ru()],mdastExtensions:[Gc()]});return l.children.map((a,s)=>Ka(a,i,s,l.children[s-1]))}const B0=2e3,Qr=H(!1);let Gl=!1;function z0({focus:e=!1}={}){Gl=e,Qr.value=!0}const j0=12e4;function H0({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:pr(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 q0(){const[e,t]=B(!1),[n,i]=B(null),l=Qr.value,a=A=>{Qr.value=A},[s,o]=B(null),u=te(null),c=te(null),f=yr(()=>{Qr.value=!1},[]);Fe(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=pa.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),Gl&&(Gl=!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()+j0;for(;Date.now()setTimeout(S,B0));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(` +${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(H0,{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 U0(e){const t=e.pid!=null&&(ce.value||[]).find(n=>String(n.pid)===String(e.pid))||null;if(e.action==="update")return z0({focus:!0});if(e.action==="needs")return Su(t);if(e.action==="ready")return Cu(t);if(e.action==="reveal")return jt(e.target);e.action==="party"&&P0(e.key),st(t)}const W0=250;function K0({target:e,pet:t,act:n=U0,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),W0);return}n(o)},onDblClick(){l(a),t()},dispose(){l(a)}}}const V0="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 so={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 G0({dish:e}){const t=so[e]?e:"ramen";return r("g",{"data-dish":t,"shape-rendering":V0,children:so[t]()})}const xe="geometricPrecision",oo=e=>[...e].reverse().join("");function rt({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 cd=[sd[0]],co={body:qt(Cn),legs:qt(cd)},uo={body:qt(Cn.map(oo)),legs:qt(cd.map(oo))};function J0({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 ho({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 Q0(){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(ho,{cx:7.2}),r(ho,{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 Y0({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 fo={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 ud({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(vn,{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 po({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 Z0(){return r("g",{class:"tama-amp","shape-rendering":xe,children:[r(po,{x:24.4,y:6,cls:"tama-note"}),r(po,{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,mo="#6f93d6",X0=150,mt=e=>Math.round(e*1e4)/1e4;function ey({sprite:e}){const{scale:t,tx:n,ty:i}=xa(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(Vi,{sprite:e,face:"happy",tint:X0,holding:"pint"}),r(dd,{sprite:e,kind:"pint",scale:t})]})}function dd({sprite:e,kind:t,scale:n}){if(!Sa[t])return null;const[i,l]=Hi(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(Va,{x:0,cls:"tama-pint tama-clink"})):t==="mug"?s("scale(-1 1) translate(-30.1 -14.2)",r(fd,{})):t==="can"?s("translate(-17.8 -11.7)",r(pd,{x0:0})):null}function Va({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 ty({x0:e}){return r(Va,{x:e+15.2,cls:"tama-pint tama-clink"})}const ny=[["#ffd166",15.4],["#f28ab2",19.6],["#7fb6e6",23.8],["#9be38f",28],["#ffd166",32.2]];function ry({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}),ny.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(ey,{sprite:e.sprite}):r(K,{children:[r(rt,{cells:uo.body,x0:Ct,fill:mo}),r(rt,{cells:uo.legs,x0:Ct,y0:V+2*Cn.length,fill:mo}),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(Va,{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 iy({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 ly({x:e,sprite:t,costume:n}){const{scale:i,tx:l,ty:a}=xa(t,{x0:e-4.25,sitting:!1,height:(n?au:_a)/2});return r("g",{class:"tama-critter",style:"transform-box: view-box",transform:`translate(${mt(l)} ${mt(a)}) scale(${mt(i)})`,children:r(Vi,{sprite:t})})}function go({x:e,cls:t,costume:n,sprite:i}){return r("g",{class:t,children:[i?r(ly,{x:e,sprite:i,costume:n}):r(K,{children:[r(rt,{cells:co.body,x0:e,y0:14,w:.5,h:1}),r(rt,{cells:co.legs,x0:e,y0:18,w:.5,h:1})]}),n?r(iy,{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 ay({trick:e=!1,critter:t}){return r("g",{children:[r(go,{x:17.4,cls:"tama-kid",costume:e,sprite:t==null?void 0:t.sprite}),r(go,{x:25.4,cls:"tama-kid tama-kid2",costume:e,sprite:t==null?void 0:t.sprite})]})}function sy(){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 oy={style:"arm",color:Ht};function hd({x0:e,limb:t=oy}){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(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 cy(){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 fd(){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 pd({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 uy(){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 md({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 dy({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 hy({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 fy(){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 py(){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 Ga({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 my(){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 Ja({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 gy={run:{tempo:.3,stride:!0,outdoors:!0,snowcap:!0,Behind:J0,trick:{pail:!0}},cycle:{pose:{x0:7,lift:2},tempo:.4,stride:!0,outdoors:!0,jack:{x:.6,y:16.4},Behind:Q0,Headwear:Y0},music:{pose:{x0:6},tempo:.5,jack:{x:1.5,y:16.4},Behind:Z0,Held:ud},beer:{pose:{x0:1},tempo:.9,smile:!0,Behind:ry,Held:ty},kids:{pose:{x0:1},tempo:.7,smile:!0,Behind:ay,trick:{outdoors:!0}},game:{pose:{x0:3,sitting:!0},tempo:1.2,Behind:sy,Held:hd,paws:!0},garden:{pose:{x0:2},tempo:.8,outdoors:!0,Behind:cy,Held:pd},cook:{pose:{x0:2},tempo:.6,Behind:uy,Held:md,Headwear:dy},dog:{pose:{x0:1},tempo:.5,stride:!0,smile:!0,outdoors:!0,Behind:hy},swim:{pose:{x0:6,sitting:!0},tempo:1,Behind:fy,Held:Ga,Front:py},sled:{pose:{x0:5,sitting:!0},tempo:.35,smile:!0,outdoors:!0,snowcap:!0,Behind:my,Held:Ja}},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 yy={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 by({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}),yy[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 yo({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 ky({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 wy({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":Ge,d:`M${l.map(([a,s])=>`${(e+a).toFixed(2)} ${(t+s).toFixed(2)}`).join(" L")} Z`})}function vy({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 _y({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 xy({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 gd=({d:e})=>r("g",{class:"tama-ding",fill:"none",stroke:"#f2c14e","stroke-width":"0.3","shape-rendering":Ge,children:r("path",{d:e})});function Sy(){return r("rect",{class:"tama-slap",x:"21.6",y:"8.7",width:"1.2",height:"0.9",fill:Ht})}const $y=[21.25,12.3],Cy=[22.2,9.6];function Ty({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 Ey({limb:e}){return r(vn,{limb:e,x:21.6,y:8.7,w:1.2,h:.9,cls:"tama-slap"})}function Py(){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(gd,{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 Ay(){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(gd,{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 My(){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 Ly(){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 Iy(){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 bo=({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 Oy(){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(bo,{x:24.6}),r(bo,{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 Dy(){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 Ry=Array.from({length:18},(e,t)=>[23.6+t*1.7%7.4,6.2+t*1.3%4.8]),Fy=Array.from({length:18},(e,t)=>[24.1+t*2.3%7.2,6.5+t*.9%4.8]);function Ny(){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(Ry)}),r("g",{class:"tama-static tama-static2",fill:"#5d6470",children:e(Fy)}),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 By(){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 zy({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 jy=["#52b4ea","#7fbf7f","#c792ea","#e6e9ef"],Hy=[.85,.55,.7,.4,.9,.6],qy={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 Uy({n:e}){const t=e===0?[]:qy[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)*Hy[c%6]).toFixed(2),height:"0.45",fill:jy[c%4]},c)}))]})}function Wy({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 Ky(){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 Vy({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 Gy(){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 Jy={code:{x0:3,sitting:!0},nap:{x0:3,sitting:!0},read:{x0:4,sitting:!0}},Qy={x0:8},yd=qt(Cn),Yy=qt(Cn.map((e,t)=>t===2?e.replace(/^.##/,"...").replace(/##$/,".."):e)),Jl=sd.map(e=>qt([e])),Ql=V+2*Cn.length;function Zy(){return r("g",{children:[r(rt,{cells:yd,cls:"tama-body",x0:0}),r(Yl,{x0:0}),r(rt,{cells:Jl[0],cls:"tama-legs-a",x0:0,y0:Ql})]})}const Xy=new Set([Ga,Ja]),e2={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 Yl({closed:e,x0:t}){return r("g",{class:e?"tama-eyes-closed":"tama-eyes",children:E0.map(n=>r("rect",{x:t+n,y:e?V+3.3:V+2,width:"1",height:e?.5:2,fill:we},n))})}const ko={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"}},t2=[[3,0],[11,-.7],[18,-1.6],[25.5,-.3],[32,-1.1]];function n2({season:e,night:t}){const n=ko[e]||ko.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:t2.map(([i,l])=>r("rect",{class:"tama-fall",x:i,y:"-1",width:"0.7",height:"0.7",style:{animationDelay:`${l}s`}},i))})]})}function r2({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 i2={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 l2(){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 a2(){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 bd({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 kd({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 s2({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:wg(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(bd,{x0:0}),n==="party"&&r(kd,{x0:0})]})}function o2({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 c2({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 u2=[[5,4,"#ffd166",0],[22,2.6,"#f28ab2",-.9]],d2=[[17.4,2.8,"#ffd166",0],[24.6,2.1,"#f28ab2",-.6],[31.2,3,"#7fb6e6",-1.2]];function h2({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?d2:u2).map(([n,i,l,a])=>t(n,i,l,a))})}const wo=["#ffd166","#f28ab2","#7fb6e6","#9be38f","#c792ea"];function f2(){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:wo[n%wo.length],style:{animationDelay:`${t}s`}},e))})}function p2({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 m2({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(fd,{})});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(p2,{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(a2,{}),t==="yearend"&&r(l2,{}),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(G0,{dish:o});default:return null}}function g2({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(n2,{season:t,night:n}),a]}):a}function y2({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 b2({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 k2({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 w2=new Set(["bell","done","merged","api","ctx"]);function v2({activity:e,view:t,kind:n,duty:i,working:l,walled:a,mirroring:s}){return e==="nap"?r(Wy,{...a}):t.atDesk?n==="done"?r(Ly,{}):n==="merged"?r(Iy,{}):n==="ci"?r(Oy,{}):n==="api"?r(Ny,{}):n==="ctx"?r(zy,{pct:i==null?void 0:i.pct,cost:i==null?void 0:i.cost}):s?r(Uy,{n:l}):null:null}function _2({kind:e}){return r("g",{children:[e==="bell"&&r(Py,{}),e==="ctx"&&r(By,{}),e==="update"&&r(Gy,{})]})}function x2({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=pi[0]}){var Me;const m=(o==null?void 0:o.kind)||null,b=Uu(e,m),{atDesk:x}=b,w=p,C=gy[e],y=C&&p?{...C,...C.trick}:C,{x0:g,sitting:$=!1,lift:v=0}=(y==null?void 0:y.pose)||Jy[e]||Qy,E=y?y.jack:i2[e],A=h.sprite,T=A&&xa(A,{x0:g,sitting:$,height:w?au:_a}),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||w2.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=v2({activity:e,view:b,kind:m,duty:o,working:u,walled:c,mirroring:k}),Z=w?r(o2,{x0:g}):A?null:z?r(b2,{x0:g,mood:l}):q?r(Yl,{closed:!0,x0:g}):O?r(yo,{x0:g}):I==="api"?r(ky,{x0:g}):I==="update"?r(Vy,{x0:g}):!I&&(y!=null&&y.smile)?r(yo,{x0:g}):r(Yl,{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)===Ga?"goggles":A&&(y==null?void 0:y.Held)===Ja?"scarf":null,he=A?e2[e]??null:null,fe=he==="spoon"||he==="leash"?_g(A,he,T):null,qe=he==="bass"?Rs(T,[g+fo.dx,fo.y]):null,Ae=A&&(z?$y:L?Cy:null),ue=qe??(Ae?Rs(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(h2,{clear:!!o}),y?r(g2,{p:y,season:t,trick:p,critter:h,from:fe}):r(m2,{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(r2,{...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(Vi,{sprite:A,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:qe&&r("g",{style:"transform-box: view-box",transform:`scale(${1/T.scale}) translate(${-T.tx} ${-T.ty})`,children:r(ud,{x0:g,limb:A.limb})})}),r(s2,{sprite:A,p:y,hat:M,season:t,ghost:w}),he&&r(dd,{sprite:A,kind:he,scale:T.scale})]}):r(rt,{cells:y!=null&&y.paws?Yy:yd,cls:"tama-body",x0:g}),Z,(y==null?void 0:y.Held)&&!(A&&(Xy.has(y.Held)||he))&&r(y.Held,{x0:g}),he==="spoon"&&r(md,{x0:g,from:fe}),he==="controller"&&r("g",{transform:`translate(0 ${Math.min(T.drop,.8)})`,children:r(hd,{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(vy,{x0:g})}),!A&&I==="ctx"&&r(wy,{x0:g}),!A&&x&&O&&r(xy,{x0:g}),x&&I==="ci"&&r(Dy,{}),!A&&L&&r(Sy,{}),A&&z&&r(Ty,{limb:A.limb}),A&&L&&r(Ey,{limb:A.limb}),!A&&r(Nn,{dy:S,children:I==="bell"&&!L&&r(_y,{x0:g})}),!A&&!$&&r(rt,{cells:Jl[0],cls:"tama-legs-a",x0:g,y0:Ql}),!A&&(y==null?void 0:y.stride)&&r(rt,{cells:Jl[1],cls:"tama-legs-b",x0:g,y0:Ql}),w&&(y==null?void 0:y.pail)&&r(c2,{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(bd,{x0:g}),M==="party"&&r(kd,{x0:g})]})]},s)}),(y==null?void 0:y.Front)&&r(y.Front,{}),r(y2,{activity:e}),(x||L)&&r(_2,{kind:m}),e==="nap"&&!F&&r(Ky,{}),F&&e==="sleep"&&r(Ay,{}),O&&r(My,{}),z&&r(k2,{mood:l,x0:g,coffee:i,hat:M,headDy:S}),(n==="newyear"||Q)&&r(f2,{}),o&&r(by,{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 S2=Vt(()=>lu(mu())),wd=e=>e.map(t=>[t.since*1e3,t.until==null?1/0:t.until*1e3]),vo=e=>({...nd(Pa(),e),walls:wd(ma.value)});function $2(){const[e,t]=B(()=>new Date),[n,i]=B(0),[l,a]=B(!1),o=ll(()=>{const O=Pa();return JSON.stringify([O.merged??null,O.furious??null,ma.value])}).value,[u,c,f]=JSON.parse(o),d={...nd({merged:u,furious:c},e),walls:wd(f)},p=te(o);j(()=>{if(p.current!==o){p.current=o,t(new Date);return}const O=setTimeout(()=>t(new Date),ed(e,d)+50);return()=>clearTimeout(O)},[e,o]),j(()=>{const O=setInterval(()=>{const Q=new Date;t(M=>to(Q,vo(Q))===to(M,vo(M))?M:Q)},6e4);return()=>clearInterval(O)},[]),j(()=>{if(!l)return;const O=setTimeout(()=>a(!1),900);return()=>clearTimeout(O)},[l,n]);const h=Sc(0);j(()=>{const O=setInterval(()=>{h.value+=1},6e4);return()=>clearInterval(O)},[]),j(()=>{A0()},[]);const m=S2.value,b=ll(()=>{var z;h.value;const O=(z=Ri.value)==null?void 0:z.plan,Q=$0(O,Date.now()/1e3),M=Q.account&&Sn()?gn(Q.account):null;return JSON.stringify([Q.mood,C0(Q,M)])}),[x,w]=JSON.parse(b.value);j(()=>{x==="furious"&&yu("furious",td(new Date))},[x,Ji(e)]);const C=ll(()=>{h.value;const O=Date.now()/1e3,Q=t0({windows:ce.value||[],alerts:er.value||[],dismissedAlertIds:nr.value,dismissedNeedsPids:ft.value,dismissedReadyPids:pt.value,selectedPid:Hu(ke.value),parties:fr.value,update:pa.value,nowSec:O}),M=Cc.value;return JSON.stringify({items:Q,more:n0(Q),wall:M&&i0(M.until,O),working:er.value===null?null:xu(ce.value).length})}),y=JSON.parse(C.value),g=y.items[0]||null,$=hr(e,d),v=k0(e,d),E=Qi(e),A=ad(e),T=Uu($.id,g==null?void 0:g.kind),S=no($,T.moodShown?x:"calm"),R=[...y.wall&&Yu(e,d)?[l0(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 ${T0(v.at)}: ${no(v.activity)}`]:[]],F=`${m.sprite?m.name:"Claude"} is ${S} (${Vl($.from)}–${Vl($.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(()=>K0({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(x2,{activity:$.id,dish:$.dish,trick:!!$.trick,season:_r(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 _o=["session","week_all","week_opus","week_sonnet"];function C2(e){const t=Object.keys(e).filter(n=>!_o.includes(n)).sort();return[..._o,...t].filter(n=>e[n]).map(n=>({key:n,label:qa(n),m:e[n]}))}function T2(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 E2(e,t){return e?T2(Object.keys(e)).map(n=>{const i=e[n]||{},l=i.available&&i.meters?C2(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&&ja(i,t),fetchedAt:i.fetched_at||null,meters:l,headline:s}}):[]}function P2(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&&Ha(n.m))}}const A2=48*3600;function vd(e){return e==="week_fable"||e.startsWith("week_fable_")}function M2(e,t){const n=(e==null?void 0:e.available)&&e.meters||{},i=Object.keys(n).find(vd),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:Ha(e)}}function I2({a:e}){const{hot:t,blow:n}=P2(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 O2({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=L2(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 Zl=H(!1);function $d(){Zl.value=!0}function D2(e,t,n,i){const l=e.meters.map(({m:a})=>[`${a.label}: ${a.percent}% used`,xd(a.resets_at),...Sd(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})=>vd(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 R2(){const e=Zl.value,t=Ri.value||{},n=t.fallback,i=Math.floor(Date.now()/1e3),l=E2(t.plan,i),a=Sn(),s=new Set(Object.keys(t.plan||{}).filter(c=>M2(t.plan[c],i)));if(l.some(c=>c.available))return r("div",{id:"usage",class:`usage${e?" is-expanded":""}`,onClick:()=>{Zl.value=!e},children:l.map(c=>{var f;return r("div",{class:`usage-acct${c.stale?" is-stale":""}`,title:D2(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(O2,{label:p,m:h,resets:xd(h.resets_at),pace:Sd(h)},d)):r("span",{class:"usage-acct-off",title:"no usable credential for this account",children:"no data"}),!e&&c.available&&r(I2,{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(` + ${pl(o)} active tokens + ${pl(n.cache_read_tokens)} cache reads (discounted)`;return r("div",{id:"usage",class:"usage usage-fallback",title:u,children:`5h: ${pl(o)} · ${_d(n.reset_at)}`})}function F2({id:e,toggleClass:t,toggleLabel:n,title:i,children:l}){const[a,s]=B(!1),o=te(null),u=yr(()=>s(!1),[]);return Fe(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 N2(){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 B2(){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":Sn()?3:2,children:[r("div",{class:"topbar",children:[r("span",{class:"brand",children:["periscope",r("i",{class:"brand-cursor"})]}),r(R2,{}),r(y1,{}),r("div",{class:"spawn-pins",children:[r(b1,{}),r(x1,{}),r(w1,{})]}),r(q0,{})]}),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(d1,{}),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:Da,children:["◉ reviews",Os(gt.value)?r("span",{class:"rail-review-badge",children:Os(gt.value)}):null]}),r(F2,{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(h1,{}),r("div",{class:"meta",children:r(N2,{})})]}),r($2,{})]})}const z2=3e3;let ml=null,Zr=!1,xo=!1,Bn=!1;function j2(){if(xo)return;xo=!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 H2(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=>gu(y)),f=e.mode||"terminal";if(!e.realClick)for(const y of s)ql(y,f);Bn=!!e.blockWs,Bn&&j2();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&&(br({path:p}),await h(t/3),jr(g,"pane"),await h(t/3)),y%5===0&&ye("memtest.progress",{nonce:e.nonce,i:y})}if(p)for(const y of s)Ac(y,p);if(Bn=!1,!e.realClick)for(const[y,g]of s.entries())ql(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:f}),Zr=!1}async function So(){try{const e=await fetch("/memtest.json",{cache:"no-store"});return e.ok?await e.json():null}catch{return null}}async function q2(){const e=await So();e!==null&&(ml=e.nonce??null,setInterval(async()=>{if(Zr)return;const t=await So();!t||t.nonce==null||t.nonce===ml||(ml=t.nonce,H2(t))},z2))}const hn=H([]);let U2=1;function W2(e){return new Promise(t=>{hn.value=[...hn.value,{...e,id:U2++,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 W2({type:"confirm",message:e,okLabel:t.okLabel||"OK",cancelLabel:t.cancelLabel||"Cancel",danger:!!t.danger})}function K2(e){return String(e??"").split(` +`).map((n,i)=>r(K,{children:[i>0?r("br",{}):null,n]}))}function V2({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;Fe(()=>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:K2(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 G2(){const e=hn.value;return r(K,{children:e.map(t=>r(V2,{req:t},t.id))})}async function mr(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 J2(e){return Array.isArray(e)?e.filter(Boolean):null}function Q2(e,t){return e===t?!0:!e||!t?!1:e.length===t.length&&e.every((n,i)=>n===t[i])}function Cd(e){const{paths:t}=e||{},n=J2(t);Q2(n,Nt.value)||(Nt.value=n),rn.value=!0,ye("overlay.open",{which:"cleanup",scoped:!!Nt.value})}function Y2(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 Z2(){Fe(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=te(0);j(()=>{const x=document.getElementById("cleanup-btn"),w=()=>Cd();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 mr("load candidates",Y2(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 mr("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 $o(){$i.value=!0,ye("overlay.open",{which:"commands"})}function gl(){$i.value=!1}function X2({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 Ig(e.label,{label:u,exec:c})}async function a(){await Og(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",$o),()=>{l&&l.removeEventListener("click",$o)}},[]);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),f=a?c:c+1;o.splice(f,0,s),Dg(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 Lg({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"&&gl()},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:gl,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(X2,{c:l,i:a,onDragState:t},l.label))}),r("button",{id:"commands-modal-add",class:"commands-modal-add",onClick:n,children:"+ add command"})]})})}const Td=[{id:"default",label:"default"},{id:"full",label:"full"}];function yl(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}function tb(e){return!e||e==="default"?null:e}function Co(e){var t;return((t=Td.find(n=>n.id===e))==null?void 0:t.label)||e}const To=["shell","idle","done","working","needs-input"];function Eo(e){let t=-1;for(const n of e){const i=To.indexOf(n);i>t&&(t=i)}return t>=0?To[t]:"shell"}const Ed="";function Qa(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||Ed;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 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 nb(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 rb(e){return String(e||"").replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ib(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 rb(e.cwd)}return null}function lb(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||Ed)===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(""),Xr=H("default"),ei=H("default"),ti=H("default"),ni=H("default");function ab(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}const Ti=H(null);function Pd(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 sb(e,t,n,i){const l=[],a=new Set;for(const o of Pd(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 ob(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 cb(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 ub(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 db=Vt(()=>sb(Ut.value,ce.value,Ya(Ut.value),Ti.value));function Ya(e){var t;return((t=(Bt.value||[]).find(n=>n.id===e))==null?void 0:t.repo)||null}function hb(e){var n,i;const t=Ya(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 Po(e){var n,i,l;Ut.value=e;const t=Pd(e,ce.value);Ue.value=t.length?t[0].branch:null,Xe.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=Hg(),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,Ue.value=null,Xe.value=null,Tt.value=""}function Ao(e){Ue.value=e,Xe.value=null}function fb(){Ue.value=null,Xe.value=""}function pb(){Fe(Or,Ut.value!=null),j(()=>(window.__periscopeOpenLauncher=Po,()=>{window.__periscopeOpenLauncher===Po&&delete window.__periscopeOpenLauncher}),[]);const e=Ut.value;if(e==null)return null;const t=Wr(),n=db.value,i=Ya(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),ab(p)&&h.set("account",Xr.value);const m=yl(p)?tb(ei.value):null;m&&h.set("profile",m),yl(p)&&h.set("model",ti.value),yl(p)&&h.set("effort",ni.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"}),Or()}const s=ub(t),o=s[0],u=Tt.value.trim(),c=u?cb(n,u).slice(0,24):ob(n,hb(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"&&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: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&&Ao(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:()=>Ao(p.branch),children:["⎇ ",p.branch]},p.branch)),Xe.value==null?r("button",{class:"launcher-branch launcher-branch-new",onClick:fb,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${Xr.value===p.id?" is-active":""}`,onClick:()=>{Xr.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:Td.map(p=>r("button",{class:`launcher-branch${ei.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:()=>{ei.value=p.id,qg(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:or.map(p=>r("button",{class:`launcher-branch${ti.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:()=>{ti.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:Ra.map(p=>r("button",{class:`launcher-branch${ni.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:()=>{ni.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 mb=/github\.com\/([^/]+\/[^/]+)\/pull\/(\d+)/,gb=/^#?(\d+)$/;function yb(e){const t=e.match(mb);if(t)return{repo:t[1],pr:Number(t[2])};const n=e.trim().match(gb);return n?{repo:null,pr:Number(n[1])}:null}const bb=/^(~|\.{0,2}\/)/;function kb(e){const t=(e||"").trim();return!t||!bb.test(t)?null:t.replace(/\/+$/,"")||"/"}function Yt(e,t){return e.toLowerCase().includes(t.toLowerCase())}function wb(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=kb(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=yb(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 Mo(){ht.value=!0,ye("overlay.open",{which:"open"})}function St(){ht.value=!1}const Lo={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:"◉"}},vb=3e3;function _b(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,vb))};return a(),()=>{i=!1,l&&clearTimeout(l)}},[e]),t}function xb(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 Sb(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 $b(){Fe(St,ht.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=Mo;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===Mo&&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(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}Rg(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"){Da(),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=wb(n,e).map($=>({...$,group:Lo[$.kind].group,icon:Lo[$.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(Zi,{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(Cb,{selectedJob:u,onSelect:c,onBack:u?()=>c(null):()=>{o(!1),i("")},onClose:St}),l&&l.card.kind==="worktree"&&r(Eb,{card:l.card,onPick:$=>x({repo:l.card.repo,branch:$}),onBack:()=>a(null)}),l&&l.card.kind==="track"&&r(Pb,{card:l.card,onPick:$=>w(l.card.repo,$),onBack:()=>a(null)}),l&&l.card.kind==="pr"&&r(Ab,{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 Cb({selectedJob:e,onSelect:t,onBack:n}){const i=_b(!e);return Fe(n,!0),e?r(Tb,{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 Tb({jobId:e,onBack:t}){const{messages:n,pending:i}=xb(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:Sb(l)},l.uuid||a))]})]})}function Zi({value:e,onInput:t,placeholder:n,items:i,onPick:l,onBack:a,empty:s}){const[o,u]=B(0),c=te(null),f=te(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(K,{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(K,{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 Eb({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(Zi,{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 Pb({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(Zi,{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 Ab({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(Zi,{value:i,onInput:l,placeholder:"repo for this PR…",items:s,onPick:o=>t(o.value),onBack:n,empty:"no matching repo"})}function Io({which:e,label:t,fonts:n}){return r("label",{children:[t,r("select",{name:`font-${e}`,value:ar(e).id,onChange:i=>Wg(e,i.currentTarget.value),children:n.map(i=>r("option",{value:i.id,children:i.name},i.id))})]})}function Mb(){return r("fieldset",{class:"font-picker",children:[r("legend",{children:"Fonts"}),r(Io,{which:"ui",label:"Interface",fonts:mi}),r(Io,{which:"code",label:"Code & terminal",fonts:mi.filter(e=>e.mono)})]})}const Lb=[["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 Ib(){const e=yi();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."}),Lb.map(([t,n])=>r("label",{class:"notify-option",children:[r("input",{type:"checkbox",name:`notify-${t}`,checked:e[t],onChange:i=>Vg(t,i.currentTarget.checked)}),n]},t))]})}function Ob({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(Vi,{sprite:e.sprite}):r(Zy,{})})}function Db(){const e=mu();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:()=>Ug(t.id)}),r(Ob,{critter:t}),r("span",{children:t.name})]},t.id))})]})}const ln=H(!1);function Oo(){ln.value=!0,ye("overlay.open",{which:"settings"})}function On(){ln.value=!1}function Rb(){Fe(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",Oo),()=>{w&&w.removeEventListener("click",Oo)}},[]),j(()=>{ln.value&&(t(""),(async()=>{const{data:w,error:C}=await mr("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(` +`).map(v=>v.trim()).filter(Boolean)};i(!0);const{error:$}=await mr("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(Mb,{}),r(Db,{}),r(Ib,{}),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 Fb(){return j(()=>{r1(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})},[]),r(K,{children:[r(eb,{}),r(Z2,{}),r(Rb,{}),r(pb,{}),r($b,{})]})}const Do=120,Nb=3600,Xl=e=>`${e.repo_slug||e.repo_key||""}#${e.pr}`;function Ro(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 Bb(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<=Do&&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=Ma(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=Ro(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(Ro(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<=Nb&&(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=Xl(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&&ja(S,n))continue;let R=null;for(const[F,q]of Object.entries(S.meters)){if(!(q!=null&&q.resets_at))continue;const L=Wu(q),I=`${T}/${F}/${Math.round(q.resets_at/60)}`,O=A[I]??0;A[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-p[T]<=Do&&(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},bl=e=>Qn(_e(e),26),Dn=e=>[e==null?void 0:e.session,e==null?void 0:e.branch].filter(Boolean).join(" · "),kl=e=>!!(e!=null&&e.pid&&e.agent==="claude"),Fo=e=>{const t=/^mcp__(.+?)__(.+)$/.exec(e||"");return t?`${t[2]} (${t[1]})`:e||"this"};function zb(e){const t=String(e||"").replace(/\s+/g," ").trim(),n=t.match(/^.*?[.!?](?=\s[A-Z0-9]|$)/);return Qn(n?n[0]:t,140)}const No={permission:"Waiting for your approval.",question:"Waiting for your answer.",dialog:"Waiting for your input."},jb={failure:"✗",pending:"⟳",success:"✓"},Ad=e=>`usage_to_${e}`;function Md(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:`${bl(n)} needs you`,subtitle:Dn(n),body:s.summary?`Allow ${Fo(s.tool)}: ${s.summary}?`:`Allow ${Fo(s.tool)}?`,category:"needs_permission",data:{open:"pane",pid:n.pid,request_id:s.request_id}}:{...i,title:`${bl(n)} needs you`,subtitle:Dn(n),body:No[uu(n.waiting_for)]||No.dialog,category:"needs_dialog",data:{open:"pane",pid:n.pid}}}case"question":{const s=e.alert;return{...i,title:`${Qn(n?_e(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,...kl(n)?{category:"question"}:{},data:{open:"pane",pid:(n==null?void 0:n.pid)??null}}}case"done":return{...i,title:`${bl(n)} is done`,subtitle:n.pr&&n.pr_linked?`${n.session} · PR #${n.pr}`:Dn(n),body:zb(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=>`${jb[f.state]||"·"} ${f.name}`).join(" · "),o=rr(n.repo_slug,n.pr),u=kl(n)?n:(t.windows||[]).find(f=>kl(f)&&Xl(f)===Xl(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(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:`${qa(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?Ad(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}),Bo=it("open_pr","Open PR"),Hb=it("mark_seen","Mark seen"),zo=it("cleanup","Clean up worktree",{foreground:!0}),qb=it("details","Details",{foreground:!0}),Ub=it("open","Open",{foreground:!0}),jo=it("fix","Ask agent to fix",{auth:!0});function Wb({accounts:e=[],moveTargets:t={}}={}){const n=[{id:"done_seen",actions:[Hb]},{id:"ci_failed_pr",actions:[Bo]},{id:"pr_merged",actions:[zo]},{id:"pr_merged_cleanup",actions:[zo]},{id:"pr_merged_pr",actions:[Bo]},{id:"usage",actions:[qb]},{id:"needs_permission",actions:[it("allow","Allow",{auth:!0})]},{id:"needs_dialog",actions:[Ub]},{id:"question",actions:[it("send","Reply",{auth:!0,reply:{button:"Send",placeholder:"Reply…"}})]},{id:"ci_failed",actions:[jo]},{id:"ci_failed_fix",actions:[jo]}];for(const i of[...new Set(Object.values(t||{}))].sort())n.push({id:Ad(i),actions:[it("spawn_on",`Spawn on ${gn(i,e||[])}`)]});return n}const Kb=Object.freeze({openExternal:Wi,openUsageDetails:$d,pickSpawnAccount:Au,openCleanupModal:Cd,markReadySeen:$u,selectPane:st,revealPane:jt,post:Mg,toast:bn,notify:bu}),Vb={allow:"Allow",deny:"Deny",send:"Reply",fix:"Ask agent to fix"},Gb={allow:"Couldn't allow",deny:"Couldn't deny",send:"Couldn't send your reply",fix:"Couldn't ask the agent to fix"},Jb=new Set(["allow","deny"]),Qb={"/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 Yb(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:Qb[e]:(t==null?void 0:t.detail)||"No answer"}const Zb=e=>{const t=e.codePointAt(0);return t!==9&&t!==10&&(t<32||t>=127&&t<=159)},Xb=e=>[...String(e)].filter(t=>!Zb(t)).join("").trim();function ek(e,t){const n=(t||[]).map(Xb).filter(Boolean),i=n.length?`${n.join(" · ")}.`:"Checks are failing.";return`CI failed on #${e}: ${i} Please investigate and fix.`}async function wl({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:Gb[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||Jb.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=Yb(i,u);o(c),t(),(u==null?void 0:u.status)!==409&&a.toast(`${Vb[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 tk({target:e,action:t,text:n,data:i}={},l=Kb){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 wl({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?wl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:o},l):void 0}case"fix":return wl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:ek(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 ea=3e3,nk=2,rk=new Set(["needs_input","question"]);function ik(e,t,n,i=!0){const l=t.filter(o=>n-o{var t;return e.kind==="question"?"question":uu((t=e.w)==null?void 0:t.waiting_for)==="permission"?"permission":"input"};function ak(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"} · ${lk(l)}`}).join(` +`)}}function Ld(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 ak(e)}const Id="periscope.notify.v1",sk=15*60*1e3;function ok(e,t){try{const n=JSON.parse((e==null?void 0:e.getItem(Id))||"null");if(!(n!=null&&n.state)||!(n.at<=t)||t-n.at>sk)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 ck(e,t,n,i=[],l=null){try{e==null||e.setItem(Id,JSON.stringify({at:n,state:t,held:i,heldSince:l}))}catch{}}const uk={question:"needs_input"},dk=(e,t)=>e[uk[t]||t]!==!1;function hk({target:e,data:t}={}){if(t||(t={}),t.open==="url"&&t.url){Wi(t.url);return}if(t.open==="usage"){$d();return}const n=t.pid!=null&&(ce.value||[]).find(i=>String(i.pid)===String(t.pid));n?st(n):jt(e)}const fk={sends:[],flush:[],badge:null};function pk(e,t,n,i,l=Md){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>=ea&&(p.push({...Ld(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,...fk,flush:p,categories:m,timerAt:o.length?u+ea:null,...g});if(t.alerts===null)return b();try{const g=Wb({accounts:t.accounts,moveTargets:t.moveTargets}),$=JSON.stringify(g);$!==f&&(m=g,f=$)}catch(g){console.error("[notify] category set failed",g)}const x=_u(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=Bb(a,t,i/1e3);a=g.state;const $=ik(g.events.filter(v=>dk(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 mk=2e3;function gk(e={setNotifyCategories:n1,notify:bu}){let t=Promise.resolve();return(n,i)=>{n&&(t=t.then(()=>Promise.race([e.setNotifyCategories(n),new Promise(l=>setTimeout(l,mk))])).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 Ho=!1;function yk(){if(Ho||!Ve())return;Ho=!0;const e=typeof localStorage>"u"?null:localStorage,t=ok(e,Date.now());let n={state:null,held:[],heldSince:null,...t,recent:[],lastBadge:void 0,lastCategories:void 0};const i=u=>ck(e,n.state,u,n.held,n.heldSince),l=gk();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:ce.peek()||[],moveTargets:ui.peek()};l(null,[{...Ld(u,Md,c),quiet_when_focused:yi().quiet_when_focused}])};e1(hk),t1(u=>tk(u)),lt(()=>{Ec.value,Li(()=>{var u;try{const c={windows:ce.peek()||[],alerts:er.peek(),dismissedAlertIds:nr.peek(),dismissedNeedsPids:ft.peek(),dismissedReadyPids:pt.peek(),plan:((u=Ri.peek())==null?void 0:u.plan)||{},accounts:at.peek(),moveTargets:ui.peek()},f=!!(ga.peek()||Et.peek()),d=Date.now(),p=n,{sends:h,flush:m,badge:b,categories:x,timerAt:w,...C}=pk({...n,editing:f},c,yi(),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&&Zg(b)}catch(c){console.error("[notify] pass failed",c)}})})}const bk=3e3,kk=2e3;let Ei=0;function Od(){return document.getElementById("connection-banner")}function Dd(e){try{if(er.value=e.alerts||[],ga.value||Et.value)return;ce.value=e.windows||[],Oi.value=e.projects||[],Di.value=e.workspaces||[],Bt.value=e.tracks||[],Sh(ce.value),Ri.value={plan:e.usage_plan,fallback:e.usage,poke:e.poke||{}},pa.value=e.update||null,$c.value=e.resources||null,at.value=e.accounts||[],ui.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,Cc.value=e.walls||null,ma.value=e.wall_spans||[],Tc.value=e.editor||""}finally{Ec.value+=1}}function Rd(){if(Ei>0){Ei=0;const e=Od();e&&(e.hidden=!0),document.body.classList.remove("disconnected")}}function Fd(e){if(Ei+=1,Ei>=2){const t=Od();t&&(t.hidden=!1),document.body.classList.add("disconnected")}e&&console.warn("[periscope]",e)}async function wk(){if(!ga.value&&!Et.value)try{const e=await fetch("/api/state");if(!e.ok)throw new Error(`HTTP ${e.status}`);Dd(await e.json()),Rd()}catch(e){Fd(`poll failed: ${e.message}`)}}let vl=!1,ta=!1,Yn=null,Ot=null,fn=null;function vk(){if(Ot)return;const e=async()=>{await wk(),Ot!==null&&(Ot=setTimeout(e,bk))};Ot=setTimeout(e,0)}function Nd(){Ot&&(clearTimeout(Ot),Ot=null)}const _k=1e4;let Dt=null,qo=0;async function Xi(){const e=++qo;try{const t=await fetch("/api/reviews");if(!t.ok)return;const n=await t.json();e===qo&&(gt.value=n.rows||[])}catch{}}function xk(){if(Dt)return;const e=async()=>{await Xi(),Dt!==null&&(Dt=setTimeout(e,_k))};Dt=setTimeout(e,0)}function Sk(){Dt&&(clearTimeout(Dt),Dt=null)}function Bd(){const e=location.protocol==="https:"?"wss:":"ws:",t=new WebSocket(`${e}//${location.host}/ws/state`);Yn=t,t.onmessage=n=>{Nd();try{Dd(JSON.parse(n.data)),Rd()}catch(i){Fd(`bad frame: ${i.message}`)}},t.onclose=()=>{ta||(Yn=null,vk(),fn||(fn=setTimeout(()=>{fn=null,Bd()},kk)))},t.onerror=()=>{try{t.close()}catch{}}}function $k(){return vl?()=>{}:(vl=!0,ta=!1,Bd(),xk(),()=>{if(ta=!0,Sk(),vl=!1,Yn){try{Yn.close()}catch{}Yn=null}Nd(),fn&&(clearTimeout(fn),fn=null)})}const Ck=/[A-Za-z0-9_]+|\s+|[^A-Za-z0-9_\s]/g;function Uo(e){return String(e??"").match(Ck)||[]}function Tk(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 Ak(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 Mk=["dist/","build/","vendor/",".next/","target/debug/","target/release/"],Lk=new Set(["package-lock.json","yarn.lock","pnpm-lock.yaml","uv.lock","poetry.lock","Cargo.lock","Gemfile.lock","composer.lock","go.sum"]),Ik=[".min.js",".min.css",".map",".snap"];function zd(e){const t=String(e||"");if(!t)return!1;const n=t.split("/").pop()||"";if(Lk.has(n)||Ik.some(l=>n.endsWith(l)))return!0;const i=`${t}/`;return Mk.some(l=>i.includes(`/${l}`)||i.startsWith(l))}function Ok(e){const t=[],n=[];for(const i of e||[])(zd(i.path)?n:t).push(i);return t.concat(n)}const na=H({}),Dk="\0";function jd(e,t){return`${e}${Dk}${t}`}function Hd(e,t,n,i,l=!1){const a=e[jd(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 qd(e,t,n){const i=jd(e,t),l={...na.value},a={...l[i]||{},...n};a.collapsed===void 0&&!a.viewedSig?delete l[i]:l[i]=a,na.value=l}function Rk(e,t,n){qd(e,t,{collapsed:n})}function Fk(e,t,n,i){qd(e,t,{viewedSig:i?n:void 0,collapsed:!!i})}function Nk(e,t,n){return n.reduce((i,l)=>i+(Hd(e,t,l.path,l.sig).viewed?1:0),0)}const Bk=[["session","This session","Changes since the current Claude session started"],["branch","This branch","Changes vs where this branch forked"]],zk={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 Ud(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0&&zk[t.slice(n+1).toLowerCase()]||""}function Wo({text:e,lang:t,hl:n}){if(!n||!t)return e||" ";try{return n(e,t)}catch{return e||" "}}function jk({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(Wo,{text:i.text,lang:t,hl:n})},l)):r(Wo,{text:e.text,lang:t,hl:n})})})}function Wd({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]}),Ak(e.lines).map((a,s)=>r(jk,{line:a,lang:t,hl:n},s))]})}function Hk({file:e,repo:t,review:n,hl:i}){const l=zd(e.path),{collapsed:a,viewed:s}=Hd(n,t,e.path,e.sig,l),o=!a,u=Ud(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:()=>Rk(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:()=>Fk(t,e.path,e.sig,!s),children:s?"✓ viewed":"viewed"})]}),o&&e.hunks.map((d,p)=>r(Wd,{hunk:d,lang:u,hl:i,onOpen:c?h=>br({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 qk=[3,10,25];function Uk({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 Yi(()=>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=Ok(((x=o.data)==null?void 0:x.files)||[]),p=((w=o.data)==null?void 0:w.repo)||"",h=na.value,m=Nk(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:Bk.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:qk.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(Hk,{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 Wk=new Set(["Read","Edit","Write","MultiEdit","NotebookEdit"]),Kk=new Set(["html","md"]);function Vk(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 Gk(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0?t.slice(n+1).toLowerCase():""}function Jk(e,t=Kk){const n=[],i=[];for(const l of e)(t.has(Gk(l.path))?n:i).push(l);return{priority:n,others:i}}function Qk(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||!Wk.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 Yk(e){return e==="need_human"?"var(--s-danger)":e==="done"?"var(--s-success)":"var(--fg-3)"}function Zk(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 Xk(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 ew(e){return e?(e.replace(/[^A-Za-z0-9]/g,"").slice(0,2)||e.slice(0,1)).toUpperCase():"?"}const tw={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 nw({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:ew(o)}))})]})]})}function rw({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=wr(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 iw({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:${Yk(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:${Zk(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:[Xk(e.kind,e.state)," · ",Pe(e.at)," ago"]})]})]})}function lw({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(iw,{e:s},o))}):l?null:r("div",{class:"timeline-empty",children:"no recent activity"})]})}function aw({pid:e,onRefresh:t,idPrefix:n}){const i=te(null),l=te(null),a=te(null),s=e?Er(e):null,o=(s==null?void 0:s.tags)||[];function u(){if(!e)return;const d=Er(e)||{tags:[]};Kr(e,{notes:i.current.value,tags:d.tags})}function c(){const d=(l.current.value||"").trim();if(!d||!e)return;const p=Er(e)||{notes:i.current.value,tags:[]},h=d.split(/[\s,]+/).filter(Boolean);Kr(e,{notes:i.current.value,tags:[...p.tags,...h]}),l.current.value="",t==null||t()}function f(d){const p=Er(e)||{notes:i.current.value,tags:[]};Kr(e,{notes:i.current.value,tags:p.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,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 _l({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:()=>br({path:e.path,line:null}),title:`Open ${e.path} as a preview tab`,children:[r("span",{class:"files-op",children:ow(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 sw({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?Qk(l.messages):[],s=fu(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=>du(g,d),h=t.trim(),m=g=>Vk(g.path,h),b=u.filter(m),{priority:x,others:w}=Jk(f.filter(m)),C=g=>()=>Fg(e,g),y=[{items:b,render:g=>r(_l,{it:g,label:p(g.path),pinned:!0,onTogglePin:C(g.path)},`pin:${g.path}`)},{items:x,render:g=>r(_l,{it:g,label:p(g.path),priority:!0,pinned:!1,onTogglePin:C(g.path)},`pri:${g.path}`)},{items:w,render:g=>r(_l,{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(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 ow(e){switch(e){case"Read":return"👁";case"Write":return"+";case"Edit":case"MultiEdit":case"NotebookEdit":return"✎";default:return"·"}}function cw({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 f=tw[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(nw,{data:e,onLinkAsk:u}),r(rw,{data:e,onLinkAsk:u})]}),r("section",{class:"modal-side-section modal-side-notes",children:[r("h4",{children:"Notes"}),r(aw,{pid:o,idPrefix:l,onRefresh:t},o)]}),r(sw,{pid:o}),r("section",{class:"modal-side-section modal-side-activity",children:[r("h4",{children:"Activity"}),r(lw,{data:e,streamRef:a})]})]})}let pn=null,Rr=null;function uw(){return pn?Promise.resolve(pn):(Rr||(Rr=Yi(()=>import("./chunks/preview.js").then(e=>e.P),[]).then(e=>(pn=e,e)).catch(e=>{throw Rr=null,e})),Rr)}function dw({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),uw().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 xl(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}`),Xi()}catch(l){n(String(l))}finally{i(!1)}}function hw({row:e}){const t=wr(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=qi(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 Ko="filter branches, PRs, people, tickets";function fw({col:e}){const{label:t,what:n}=ji[e],i=Ol.value,l=(i==null?void 0:i.key)===e,a=cg(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:()=>{Ol.value=a},children:[t,l?r("span",{class:"rq-sort-dir","aria-hidden":"true",children:i.dir==="asc"?"▲":"▼"}):null]})})}function pw({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:()=>Tu(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(hw,{row:e})}),r("td",{class:"rq-wt",children:o?`${o.stops} stop${o.stops===1?"":"s"} · ${ag(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:()=>xl("/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"})&&xl("/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})&&xl("/api/reviews/clear",e,n,l)},children:"clear"}):null,t?r("span",{class:"rq-note",children:t}):null]})]})}function mw(){j(()=>{Xi()},[]);const e=gt.value;if(e===null)return r("div",{class:"wt-empty",children:"loading…"});const t=og(e,Ol.value),n=fs.value,i=ug(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:Ko,"aria-label":Ko,spellcheck:!1,autocomplete:"off",value:n,onInput:a=>{fs.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(ji).map(a=>r(fw,{col:a},a)),r("th",{})]})}),r("tbody",{children:i.map(a=>r(pw,{row:a},`${a.repo}/${a.branch}`))})]})]})}async function gw(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 Kd({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:pr(t.body,{demote:!1,softBreaks:"space"})})]},n))}):null}function yw({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 gw("/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 bw({stop:e,diffFiles:t,comments:n,repo:i,branch:l,hl:a,onPosted:s}){const[o,u]=B(!1),c=lg(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:pr(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(Wd,{hunk:m,lang:Ud(p.ref.path),hl:a,onOpen:null},b))]},h))]}):null,r(Kd,{list:n}),r(yw,{repo:i,branch:l,stop:e.title,onPosted:s})]})}function kw({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 Yi(()=>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),Xi()};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=rg(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(K,{children:[" · ",n!=null&&n.url&&n.number===b.header.pr?r("a",{class:`rq-pr-link ${qi(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(bw,{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(Kd,{list:C})]}):null]})}function ww({target:e,agent:t,onPaste:n,class:i="modal-xterm",id:l}){const a=te(null);return j(()=>(J1(a.current,e,{agent:t,onPaste:n}),ju),[]),r("div",{ref:a,id:l,class:i})}function vw(){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=yr(()=>{n(!1),l(""),G1()},[]);Fe(a,t);function s(o){o.preventDefault(),i&&(o.shiftKey?Gs(i):Vs(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&&Gs(i),children:"‹"}),r("button",{type:"button",class:"term-search-btn",title:"Next (Enter)",onClick:()=>i&&Vs(i),children:"›"}),r("button",{type:"button",class:"term-search-btn",title:"Close (Esc)",onClick:a,children:"✕"})]}):null}const Vd={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}},_w=.5;function xw(e,t,n){return Math.round(Math.min(Math.max(e,t),Math.max(t,n)))}function Sw(e,t,n,i){return xw(e+n.dir*t,n.min,i*_w)}function $w(e){return Number.isFinite(e)&&e>0?e:null}function Gd({which:e}){const t=Vd[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"),K1();const p=m=>{d=Sw(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"),V1(),d!==c&&Fs(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:()=>Fs(t.pref,t.def)})}function Cw(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 Tw(e){return(e==null?void 0:e.session_effort)||(e==null?void 0:e.launch_effort)||"default"}function Ew(e){var t;return e!=null&&e.model?e.model.replace(/\s*\(.*\)/,""):e!=null&&e.session_model?((t=or.find(n=>n.id===e.session_model))==null?void 0:t.label)||e.session_model:"model"}function Pw({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":Cw(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=or.find(f=>f.id===t.model))==null?void 0:c.label)||t.model:Ew(e),u=t.effort||Tw(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}),or.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}`}),Ra.map(f=>r("option",{value:f,children:f},f))]})]})}const Aw=2e3;function Mw(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&&!zr.value[t]&&(zr.value={...zr.value,[t]:!0})}catch{}i&&(l=setTimeout(a,Aw))}return a(),()=>{i=!1,l&&clearTimeout(l)}},[e,t,n])}function Lw(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 Iw({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 Ow(e){const t=e.input||{};switch(e.name){case"Bash":return t.command||"";case"Write":return t.content||"";default:return""}}function Dw({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 Rw({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=Ow(e),u=!i&&e.result!=null&&e.result!=="",c=l||a||!!o||u,f=Lw(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(),br({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(Iw,{input:e.input||{}}):a?r(Dw,{input:e.input||{}}):o&&r("pre",{class:"tc-cmd",children:o}),u&&r("pre",{class:"tc-out",children:e.result})]})]})}function Fw({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:pr(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:pr(e.text)}),n.length>0&&r("div",{class:"turn-tools",children:n.map((i,l)=>r(Rw,{t:i},i.id||l))})]})}function Nw({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?${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 Bw({target:e,pid:t,selected:n,state:i,waitingFor:l,spinner:a}){var m;Mw(e,t,n);const s=((m=Ft.value[t])==null?void 0:m.messages)||[],o=te(null),u=te(null),c=te(!0),f=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!==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(K,{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(Fw,{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(Nw,{target:e,composerRef:u})]})}const zw=1500;function jw(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Hw({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 qw({pid:e,paneLabel:t}){const n=Be.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:jw(l.path)}),r("span",{class:"detail-tab-close",title:"Close tab",onClick:o=>{o.stopPropagation(),Ac(e,l.path)},children:"×"})]},a)})]})}function Vo(e){return(ce.value||[]).find(t=>t.pid===e)||null}function Jd(e){return(e==null?void 0:e.agent)!=="claude"?"terminal":gu(e.pid)||"terminal"}async function Uw(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||Ks(`\r +\x1B[31m[periscope: image paste failed: ${s.error}]\x1B[0m`)}catch(a){Ks(`\r +\x1B[31m[periscope: image paste error: ${a.message}]\x1B[0m`)}return}}}function Ww({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=rr(e.repo_slug,e.pr),a=qi(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=wr(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(Pw,{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.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 CPU per core (100% = one core)",children:`${sr(e.res.mem_mb)} mem · ${Pu(e.res.cpu_pct)} cpu`})]})),e.agent==="claude"&&e.mem){const l=hu(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"})]})),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 Kw({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,zw);return()=>{i=!1,clearInterval(a)}},[e]),t?r(cw,{data:t,onRefresh:()=>{},containerId:"detail-side",containerClass:"detail-side",idPrefix:"detail"}):r("aside",{id:"detail-side",class:"detail-side"})}function Vw({w:e}){const t=Jd(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(()=>(Hs(c=>{let f=c,d=null;const p=f.match(/^(.*?):(\d+)$/);p&&(f=p[1],d=p[2]),br({path:f,line:d})}),()=>Hs(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(vi));return()=>cancelAnimationFrame(c)},[t]);const[n,i]=B(!0);j(()=>{if(t!=="terminal")return;const c=()=>i(I1());c();const f=setInterval(c,250);return()=>clearInterval(f)},[t,e.pid]);const l=te(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=Be.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(Ww,{w:e}),r("div",{id:"detail-tab-bar",class:"detail-tab-bar",children:[r(qw,{pid:e.pid,paneLabel:u}),e.agent==="claude"&&r(Hw,{mode:t,onMode:c=>{ye("view.switch",{view:c}),ql(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(ww,{id:"detail-xterm",class:"detail-xterm",target:e.pane_id,agent:e.agent,onPaste:Uw},e.pid)}),r("div",{class:"detail-changes-host",style:s==="changes"?"display:contents":"display:none",children:r(Uk,{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(dw,{entry:c,active:d})},f)}),!bi.value&&r(Kw,{target:e.target},e.target),!bi.value&&r(Gd,{which:"side"})]}),o&&t==="terminal"&&!n&&r("button",{class:"term-scroll-bottom",title:"Scroll to latest",onClick:vi,children:"⤓"}),o&&t==="terminal"&&r(vw,{})]})}function Sl(){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 Gw(){var d,p;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)&&(tr.value=null)},[e]);const s=n?Vo(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=Jd(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(Sl,{}),n&&(s?r(Vw,{w:s}):r(Sl,{})),l&&r(mw,{}),i&&(gt.value===null?r("div",{class:"wt-empty",children:"loading…"}):a?r(kw,{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(Sl,{})),f.map(h=>{const m=Vo(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(Bw,{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 $l(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 ra=H(!1);function Cl(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 Tl(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 Jw(e,t){return!!t&&!!(e!=null&&e.branch)}function Qw(e,t){return`open ${e!=null&&e.branch?`${e.branch} `:""}worktree in ${t}`}const Yw=900;function Za(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 Zw(e){return e==="✓"?"ok":e==="✗"?"bad":e==="⟳"?"running":"neutral"}function Xw(e){return e?e.replace(/\s*\(.*$/,"").trim():null}function ev(e){return`${Math.round(e/1e3)}k`}function Rn(e){return e.context_pct!=null?`${e.context_pct}%`:e.ctx_tokens!=null?ev(e.ctx_tokens):null}function Qd({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 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 tv({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=_e(e),E=e.agent||(e.is_claude?"claude":null),A=Hl[E],T=e.status_rail||e.status_line,S=e.status_at&&Math.floor(Date.now()/1e3)-e.status_at>Yw,R=Xw(e.model),F=e.pr?rr(e.repo_slug,e.pr):null,q=hu(e.mem),L=d?wu(d,Math.floor(Date.now()/1e3)):null,I=$h(e),O=qi(e.pr_state),Q=`PR #${e.pr}${O.suffix}`,M=r(K,{children:["#",e.pr,e.ci&&!O.cls?r("span",{class:`pane-ci pane-ci-${Zw(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=wr(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 ${Co(e.profile)} profile — a different plugin set and system prompt than a normal pane`,children:Co(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(Qd,{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${Kl(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${Kl(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?"🔒":"🔓"}),Jw(e,m)&&r("button",{class:"rail-editor",title:Qw(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 nv({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 rv({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:Za(i)})]})}function Go({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 iv({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(Qd,{label:t,kind:"track",renameable:e!=="loose",onCommit:s}),r("span",{class:"repo-rule","aria-hidden":"true"}),r("span",{class:Za(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 Yd(e){const t=[...new Set((e||[]).map(n=>n.session).filter(Boolean))];return n=>du(n,t)}function zn(e,t){pu(e,!t)}function Zt(e){return`${e.kind}:${e.pid??e.id}`}function lv(){var A,T,S,R,F,q;me.value;const e=ce.value||[],t=Oa.value||[],n=nr.value,i=ft.value,l=lr(),a=Yd(e),s=Ma(e,t,n,i),o=l["sec:needs"]===!0,u=ku(e,t,n,pt.value),c=l["sec:ready"]===!0,f=xu(e),d=l["sec:running"]===!0,p=o1(Ta(),e),h=l["sec:pinned"]===!0,m=ra.value,b=te(null),x=Cl(s,(A=b.current)==null?void 0:A.needs,m,Zt),w=Cl(u,(T=b.current)==null?void 0:T.ready,m,Zt),C=Cl(f,(S=b.current)==null?void 0:S.running,m,Zt),y=Tl(s,(R=b.current)==null?void 0:R.needs,m,Zt)||Tl(u,(F=b.current)==null?void 0:F.ready,m,Zt)||Tl(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=Ns(ft.value,e,"needs-input");L.size!==ft.value.size&&(ft.value=L);const I=Ns(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),nr.value=I}function v(L){g(),Su(L)}function E(L){g(),Cu(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:l1(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:Ag((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:()=>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(K,{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:()=>st(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(K,{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:()=>st(L),children:[r("span",{class:`attn-ico ${((I=Hl[L.agent])==null?void 0:I.className)||""}`,children:((O=Hl[L.agent])==null?void 0:O.glyph)||"$"}),r("span",{class:"attn-label",children:$t(L,null,null,a)}),r("span",{class:Za(L.state),style:"margin-left:auto"})]},`pin:${L.pid}`)})]})]})}function av(){me.value;const e=Oa.value||[],t=lr(),n=Yd(ce.value||[]),i=c1(e),l=t["sec:activity"]!==!1;return r(K,{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 sv="";function ov(e){const t=window.__periscopeOpenLauncher;typeof t=="function"&&t(e)}function cv(e,t){return!t||t==="all"?e:e.filter(n=>n.track_id===t)}function uv({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 Jo=0;function dv(){if(Date.now()-Jo<5e3)return;const e=ce.value||[];if(e.length===0)return;Jo=Date.now();const t=Qa(e,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ir(),branchOrderByTrack:Ca()},Bt.value),n=gi(),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 Zd(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}=Qa(u,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ir(),branchOrderByTrack:Ca()},m),y=lb(b,x,d,gt.value||[]);function g(M){if(M==="reviews"){Da();return}if(M.startsWith("review:")){const z=M.slice(7),k=z.indexOf("/"),W=(gt.value||[]).find(Z=>Z.repo===z.slice(0,k)&&Z.slug===z.slice(k+1));W&&Tu(W.repo,W.branch);return}ke.value=M,ye("pane.focus",{key:M}),M.startsWith("pane:")&&yt({kind:"pane",pid:M.slice(5)})}function $(M){const z=lr()[M]===!0;pu(M,!z)}async function v(M){await Jn(`Close tab "${_e(M)}"? -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?${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 mr("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 Jn(`${_} -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(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(_=>_e(_)),W=k.length?` • ${k.join(` • `)}`:"";await Jn(`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(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(!Yo(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||!Yo(k,M))return;const W=z.currentTarget.getBoundingClientRect(),Z=z.clientY-W.top>W.height/2;if(k.kind==="track")await hv(k.key,M.key,Z);else{const _=M.kind==="track"?M.key.slice(6):M.trackKey;if(M.kind==="pane"&&k.trackKey===_)await fv(k.childKey,M.childKey,k.trackKey,Z);else{const X=d[k.childKey];X&&_&&await Qo(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 Qo(Z,M)}}}function Q(M,z){return M.map(k=>d[k]).filter(Boolean).map(k=>r(tv,{w:k,chip:ib(k),selectedKey:o,dim:$l(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:Ta().includes(k.pid),onTogglePin:()=>Jg(k.pid),onToggleNamePin:()=>S(k),editor:Tc.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:()=>{ra.value=!0},onMouseLeave:()=>{ra.value=!1},children:[r(lv,{}),r(uv,{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,_=Ci(M,u,h),X=x[M]||[],he=X.map(ue=>d[ue]).filter(Boolean),fe=he.map(ue=>ue.state||"shell"),qe=Eo(fe),Ae=he.length===0||he.some(ue=>$l(ue,s));return r(mv,{children:[r(iv,{kind:nb(M,u,h),label:_,collapsed:k,rolledUp:qe,dim:Ae,onToggle:()=>$(`repo:${M}`),onRename:ue=>R(M,ue),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(ue=>{var Tn,Sr;const Me=`${M}::${ue}`,vt=c[`wt:${Me}`]===!0,Gt=((Tn=C[M])==null?void 0:Tn[ue])||[],el=Q(Gt,M),tl=Gt.map(Ce=>d[Ce]).filter(Boolean).map(Ce=>Ce.state||"shell"),xr=Gt.map(Ce=>d[Ce]).filter(Boolean).some(Ce=>$l(Ce,s));return r("div",{class:"rail-subgroup",children:[r(rv,{label:ue===sv?"(no branch)":ue,collapsed:vt,childCount:Gt.length,rolledUp:Eo(tl),dim:xr,onToggle:()=>$(`wt:${Me}`),dragProps:{},dropPos:void 0}),!vt&&r("div",{class:"rail-group-body",children:[(((Sr=y[M])==null?void 0:Sr[ue])||[]).map(Ce=>r(Go,{row:Ce,selectedKey:o,onSelect:g},`review:${Ce.repo}/${Ce.slug}`)),el]})]},`wt:${Me}`)}):r(K,{children:[Object.values(y[M]||{}).flat().map(ue=>r("div",{class:"rail-group-body rail-review-head",children:r(Go,{row:ue,selectedKey:o,onSelect:g})},`review:${ue.repo}/${ue.slug}`)),r("div",{class:"rail-group-body",children:Q(X,M)})]}),r("div",{class:"rail-group-body rail-track-newtab",children:r(nv,{worktreeKey:M,onOpen:ov},`newtab:${M}`)})]})]},z)}),r(av,{})]})}function mv({children:e}){return r(K,{children:e})}function gv(){j(()=>{$k(),u1(),yk()},[]),j(()=>{document.body.dataset.view||(document.body.dataset.view="split")},[]);const e=te(null);return j(()=>{const t=Object.values(Vd).map(n=>{const i=Vt(()=>$w(Qg(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",Eu.value),(n=e.current)==null||n.toggleAttribute("data-side-hidden",bi.value)}),[]),r("div",{id:"split-view",ref:e,children:[r(pv,{}),r(Gd,{which:"rail"}),r(Gw,{})]})}function yv(){return r(K,{children:[r(B2,{}),r(gv,{}),r(Fb,{}),r(Eg,{}),r(G2,{})]})}async function bv(){await Ui(),ye("app.open"),lt(()=>{const t=document.documentElement.style;t.setProperty("--sans",ar("ui").stack),t.setProperty("--mono",ar("code").stack)});const e=jg();(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"),gh(r(yv,{}),document.getElementById("app")),X1(),q2(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})}bv();var Sv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $v(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}let ia=[],eh=[];(()=>{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=eh[i])t=i+1;else return!0;if(t==n)return!1}}function Zo(e){return e>=127462&&e<=127487}const Xo=8205;function Cv(e,t,n=!0,i=!0){return(n?th:wv)(e,t,i)}function th(e,t,n){if(t==e.length)return t;t&&nh(e.charCodeAt(t))&&rh(e.charCodeAt(t-1))&&t--;let i=El(e,t);for(t+=ec(i);t=0&&Zo(El(e,s));)a++,s-=2;if(a%2==0)break;t+=2}else break}return t}function wv(e,t,n){for(;t>0;){let i=th(e,t-2,n);if(i=56320&&e<57344}function rh(e){return e>=55296&&e<56320}function ec(e){return e<65536?1:2}const la="ͼ",tc=typeof Symbol>"u"?"__"+la:Symbol.for(la),aa=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),nc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Tv{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=nc[tc]||1;return nc[tc]=t+1,la+t.toString(36)}static mount(t,n,i){let l=t[aa],a=i&&i.nonce;l?a&&l.setNonce(a):l=new vv(t,a),l.mount(Array.isArray(n)?n:[n],t)}}let rc=new Map;class vv{constructor(t,n){let i=t.ownerDocument||t,l=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&l.CSSStyleSheet){let a=rc.get(i);if(a)return t[aa]=a;this.sheet=new l.CSSStyleSheet,rc.set(i,this)}else this.styleTag=i.createElement("style"),n&&this.styleTag.setAttribute("nonce",n);this.modules=[],t[aa]=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:'"'},_v=typeof navigator<"u"&&/Mac/.test(navigator.platform),xv=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 Pl in Wt)Pi.hasOwnProperty(Pl)||(Pi[Pl]=Wt[Pl]);function Ev(e){var t=_v&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||xv&&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,Tv as S,Yi as _,tr as a,Wt as b,Sv as c,B as d,ps as e,Cv as f,$v as g,K as h,Ev as k,br as o,pr as r,Pi as s,r as u,j as y}; From 7f64680c19171eeee57e54c94bf41b35f2cba667 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:17:10 -0400 Subject: [PATCH 21/52] docs: resources.py in the module table; the spec describes what was built (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- CLAUDE.md | 1 + .../2026-10-30-resource-monitor-design.md | 24 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 4bab870e..19eef378 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 | diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index ed67739d..1fb4f301 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -35,7 +35,7 @@ Activity Monitor (100% = one core). Measured cost: ~3 µs per process, ~2 ms for **D2 — Measurement runs inside `build_state`, once per tick, on the tick's existing process snapshot.** It reads `agent_processes.process_snapshot()`, which the fan-out already takes every tick (`codex_process_for_pane`), so it -adds no subprocess. When the snapshot is `None` (a `ps` failure), `res` and `resources` are omitted for that tick +adds no subprocess. 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. @@ -43,7 +43,8 @@ was rejected: it would need its own process table and a thread under `docs/testi - **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 and every process whose responsible pid is that app, found through +- **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 @@ -76,24 +77,23 @@ and total from `sysctlbyname("vm.swapusage")`; free memory percent from `kern.me **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. `mem_signal` reads the claude's footprint from the -tick's measurement, and the chip sends `{tier, gb, age_s, trigger}` where `trigger` is `"mem"` or `"age"`, so +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; 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 only, no periscope imports: +`periscope/resources.py`, stdlib plus `agent_processes` (itself stdlib-only) for the snapshot and `descendants`: -- `measure(snapshot, rows)` → `(per_row, totals)`. It reads every process once, assigns each to a group - (D3), computes footprint and CPU per group (D4, D5), and returns `{pane_id: {mem_mb, cpu_pct}}` for the rows and - `{server, webview, panes, elsewhere, machine}`. Each group is `{mem_mb, cpu_pct}`; `webview` may be `null`; - `machine` is D6's `{load1, swap_used_mb, swap_total_mb, mem_free_pct}`. -- It also returns each claude's footprint for `mem_signal` (D7). +- `measure(panes)` → `Measurement | None`, given `{pane_id: pane_pid}`. It reads every process once, assigns each + to a group (D3), 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, swap_used_mb, swap_total_mb, mem_free_pct}`. `None` when the snapshot failed. +- `footprint_mb(pid)` — one process's footprint, for the ↻ hint (D7). `build_state` calls `measure` after the fan-out and before the narrator merge. Each row gets `res`; the blob gets -`resources`. The claude footprint reaches `mem_signal` after the fan-out, so the `mem` field is set there rather -than inside `build_window_view`. +`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. From f28465b36118f42a647b173c1d4c6a60132e25f2 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:23:50 -0400 Subject: [PATCH 22/52] resources: measure() takes the process snapshot only after the throttle, and the no-app test stubs _name (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- periscope/resources.py | 8 +++++--- tests/test_resources.py | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/periscope/resources.py b/periscope/resources.py index a1117c78..0a8c62e9 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -219,13 +219,15 @@ def measure(panes: dict[str, int]) -> Measurement | None: 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] + # After the throttle: an expired snapshot cache would otherwise fork + # `ps` for a call that returns the previous measurement anyway. + snapshot = process_snapshot() + if snapshot is None: + return None named, per_pane = _assign(snapshot, panes) readings = {pid: r for pid in snapshot if (r := _read(pid)) is not None} samples: dict[str, _Sample] = {} diff --git a/tests/test_resources.py b/tests/test_resources.py index ccbc76e7..7ee56654 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -91,6 +91,7 @@ def test_assign_puts_every_process_in_one_group(monkeypatch): def test_assign_without_the_app_has_no_webview(monkeypatch): monkeypatch.setattr(resources, "_responsible", lambda pid: pid) + monkeypatch.setattr(resources, "_name", lambda pid: "") snap = {pid: p for pid, p in _snapshot().items() if pid != 500} named, _ = resources._assign(snap, {"%1": 100}) assert "webview" not in named @@ -217,6 +218,14 @@ def test_measure_within_half_a_second_returns_the_previous_measurement(fake): assert resources.measure(PANES) is first +def test_measure_within_half_a_second_takes_no_snapshot(fake, monkeypatch): + clock, _ = fake + resources.measure(PANES) + monkeypatch.setattr(resources, "process_snapshot", lambda: pytest.fail("snapshot taken inside the throttle")) + clock.t += S // 10 + resources.measure(PANES) + + 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 From b5db04a56711a4fcea0a34946a770725157025f1 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Fri, 30 Oct 2026 21:23:51 -0400 Subject: [PATCH 23/52] docs: CLAUDE.md lists the resource pill; the spec states when measuring forks ps and what a 0% can mean (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- CLAUDE.md | 2 +- docs/superpowers/specs/2026-10-30-resource-monitor-design.md | 5 +++-- periscope/session_status.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 19eef378..a72ae1ad 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -144,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/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index 1fb4f301..67e9a144 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -35,7 +35,7 @@ Activity Monitor (100% = one core). Measured cost: ~3 µs per process, ~2 ms for **D2 — Measurement runs inside `build_state`, once per tick, on the tick's existing process snapshot.** It reads `agent_processes.process_snapshot()`, which the fan-out already takes every tick (`codex_process_for_pane`), so it -adds no subprocess. When the snapshot is `None` (a `ps` failure), `res` and `resources` are `null` for that tick +adds no subprocess while the fan-out finishes within the snapshot's 1 s cache; a slower tick forks one more `ps`. 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. @@ -69,7 +69,8 @@ sampling would count as 0. 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 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 10 s (a hub that idled with no subscribers) counts as -missing. With no usable previous sample, `cpu_pct` is `null`, never 0, so a zero always means "measured idle". +missing. With no usable previous sample, `cpu_pct` is `null`, never 0. A 0 is either measured idle or an interval D4 clamped (a member reaped +outside its group, e.g. a closed pane's shell). **D6 — The machine line reads the kernel directly, with no fork.** Load average from `os.getloadavg()`; swap used and total from `sysctlbyname("vm.swapusage")`; free memory percent from `kern.memorystatus_level`, the figure diff --git a/periscope/session_status.py b/periscope/session_status.py index 0e582b22..e99d78b1 100644 --- a/periscope/session_status.py +++ b/periscope/session_status.py @@ -51,8 +51,8 @@ # 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: age_s}) — one ps snapshot serves both pid -# liveness (the key set) and the uptime cycle-hint. +# (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 From c75f34815232915ca18d2a3302f3f8cb7617bb75 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 08:23:15 -0400 Subject: [PATCH 24/52] =?UTF-8?q?resources:=20CPU=20is=20a=20share=20of=20?= =?UTF-8?q?the=20whole=20machine,=20not=20per=20core=20=E2=80=94=20owners?= =?UTF-8?q?=20listed=20side=20by=20side=20no=20longer=20read=20past=20100%?= =?UTF-8?q?=20(THI-448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) --- .../specs/2026-10-30-resource-monitor-design.md | 9 +++++---- periscope/resources.py | 10 +++++++--- static/src/chrome/ResourcePill.jsx | 2 +- static/src/chrome/__tests__/resources.test.js | 5 +++-- static/src/chrome/resources.js | 10 +++++++--- static/src/split/Detail.jsx | 2 +- tests/test_resources.py | 8 ++++++++ 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index 67e9a144..aeee0db0 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -6,7 +6,7 @@ slice. ## What the measurements showed (2026-10-30, 11 panes) -| Owner | Footprint | CPU | +| 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% | @@ -30,8 +30,9 @@ THI-449 (recycle gate, unreaped WebContent) and THI-450 (subprocesses per tick) 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 per core like `top` and -Activity Monitor (100% = one core). Measured cost: ~3 µs per process, ~2 ms for every process on the machine. +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: ~3 µs per process, ~2 ms for every process on the machine. **D2 — Measurement runs inside `build_state`, once per tick, on the tick's existing process snapshot.** It reads `agent_processes.process_snapshot()`, which the fan-out already takes every tick (`codex_process_for_pane`), so it @@ -105,7 +106,7 @@ there would disturb the CPU history of every other group. the pill. Hidden when `resources` is absent. - **Popover** on click, one line each with memory and CPU: periscope server, webview, then every pane sorted by memory (a line selects its pane), then elsewhere, then the machine line: `load 52 · swap 16.5/17.4G · 27% free`. - The CPU column's tooltip says 100% = one core. A `null` CPU 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 · 58% cpu` after the context %, for the selected pane. - 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`. diff --git a/periscope/resources.py b/periscope/resources.py index 0a8c62e9..319e6a47 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -32,6 +32,10 @@ # server averaging 10%); a caller inside it 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 @@ -180,8 +184,8 @@ class _Sample: 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. + """The group's share of the machine's CPU since `prev` (100 = every core + busy), 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 @@ -197,7 +201,7 @@ def _cpu_pct(prev: _Sample | None, cur: _Sample) -> float | None: 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) + return round(max(delta, 0) / (cur.at - prev.at) / _CORES * 100, 1) @dataclass(frozen=True) diff --git a/static/src/chrome/ResourcePill.jsx b/static/src/chrome/ResourcePill.jsx index 4f1ecef9..b056d5c9 100644 --- a/static/src/chrome/ResourcePill.jsx +++ b/static/src/chrome/ResourcePill.jsx @@ -10,7 +10,7 @@ import { resources, windows } from "../store.js"; import { paneLabel } from "../util.js"; import { fmtCpu, fmtMem, machineLine, ownedMb, paneLines } from "./resources.js"; -const CPU_TIP = "CPU per core: 100% is one core fully busy"; +const CPU_TIP = "share of the whole machine's CPU: 100% is every core busy"; function Line({ label, group, onClick }) { const children = ( diff --git a/static/src/chrome/__tests__/resources.test.js b/static/src/chrome/__tests__/resources.test.js index fed1c6ee..7ccbbfc3 100644 --- a/static/src/chrome/__tests__/resources.test.js +++ b/static/src/chrome/__tests__/resources.test.js @@ -12,9 +12,10 @@ describe("fmtMem", () => { }); describe("fmtCpu", () => { - it("rounds per-core percent; unknown is a dash, never 0", () => { + it("one decimal under 10%, whole above; unknown is a dash, never 0", () => { expect(fmtCpu(57.6)).toBe("58%"); - expect(fmtCpu(0)).toBe("0%"); + expect(fmtCpu(4.66)).toBe("4.7%"); + expect(fmtCpu(0)).toBe("0.0%"); expect(fmtCpu(null)).toBe("–"); }); }); diff --git a/static/src/chrome/resources.js b/static/src/chrome/resources.js index 3a0c85d1..a49a2b0e 100644 --- a/static/src/chrome/resources.js +++ b/static/src/chrome/resources.js @@ -1,14 +1,18 @@ // 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. +// { mem_mb, cpu_pct }: memory footprint, and the share of the whole +// machine's CPU (100 = every 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)}%`; + if (pct == null) return "–"; + // A pane is often a fraction of a percent of the machine; whole numbers + // would round it to 0. + return pct < 10 ? `${pct.toFixed(1)}%` : `${Math.round(pct)}%`; } // The pill's figure: what periscope and its panes hold. Elsewhere is the rest diff --git a/static/src/split/Detail.jsx b/static/src/split/Detail.jsx index 27822af7..d2715b5b 100644 --- a/static/src/split/Detail.jsx +++ b/static/src/split/Detail.jsx @@ -263,7 +263,7 @@ export function PaneHeader({ w }) { parts.push( <> · - + {`${fmtMem(w.res.mem_mb)} mem · ${fmtCpu(w.res.cpu_pct)} cpu`} diff --git a/tests/test_resources.py b/tests/test_resources.py index 7ee56654..2e3195b3 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -143,6 +143,12 @@ def test_cpu_never_diffs_a_reused_pid_against_its_predecessor(): assert _cpu(S, prev, 2 * S, cur) == 10.0 +def test_cpu_is_a_share_of_every_core(monkeypatch): + monkeypatch.setattr(resources, "_CORES", 10) + # 2.5 cores busy for a second on a 10-core machine: a quarter of it. + assert _cpu(0, {(1, 0): 0}, S, {(1, 0): 5 * S // 2}) == 25.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 @@ -156,6 +162,8 @@ def _no_live_resources(monkeypatch): own fakes, and the smoke tests read the real test process.""" monkeypatch.setattr(resources, "_prev", {}) monkeypatch.setattr(resources, "_last", None) + # One core, so the CPU cases read in whole-core terms. + monkeypatch.setattr(resources, "_CORES", 1) MACHINE = {"load1": 1.0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 50} From 53cfd5d1db038a35e873e8261fe176b6397fc33d Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 08:23:23 -0400 Subject: [PATCH 25/52] build: static/dist with machine-share CPU (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- static/dist/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/dist/app.js b/static/dist/app.js index 5301dc13..fdff8320 100644 --- a/static/dist/app.js +++ b/static/dist/app.js @@ -1,7 +1,7 @@ var Ai,le,ic,lc,dt,es,ac,sc,rl,Fr,jn,oc,sa,Al,Ml,ri={},ii=[],ch=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Mi=Array.isArray;function et(e,t){for(var n in t)e[n]=t[n];return e}function oa(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function uh(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?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??++ic,__i:-1,__u:0};return l==null&&le.vnode!=null&&le.vnode(a),a}function K(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&&dt.sort(sc),e=dt.shift(),t=dt.length,dh(e)}finally{dt.length=li.__r=0}}function uc(e,t,n,i,l,a,s,o,u,c,f){var d,p,h,m,b,x,w,C=i&&i.__k||ii,y=t.length;for(u=hh(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+p,s.__=e,s.__b=e.__b+1,o=null,(c=s.__i=fh(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 ns(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||ch.test(t)?n:n+"px"}function $r(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||ns(e.style,t,"");if(n)for(t in n)i&&n[t]==i[t]||ns(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(oc,"$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]=sa,e.addEventListener(t,a?Ml:Al,a)):e.removeEventListener(t,a?Ml:Al,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 rs(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[Fr]==null)t[Fr]=sa++;else if(t[Fr]0?e:Mi(e)?e.map(fc):e.constructor!==void 0?null:et({},e)}function ph(e,t,n,i,l,a,s,o,u){var c,f,d,p,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 Xn=1,bh(yc,e)}function bh(e,t,n){var i=da(Zn++,2);if(i.t=e,!i.__c&&(i.__=[yc(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=da(Zn++,3);!ge.__s&&gc(n.__H,t)&&(n.__=e,n.u=t,pe.__H.__h.push(n))}function te(e){return Xn=5,gr(function(){return{current:e}},[])}function gr(e,t){var n=da(Zn++,7);return gc(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function yr(e,t){return Xn=8,gr(function(){return e},t)}function kh(){for(var e;e=mc.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Br),t.__h.some(Il),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){pe=null,ls&&ls(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),us&&us(e,t)},ge.__r=function(e){as&&as(e),Zn=0;var t=(pe=e.__c).__H;t&&(il===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(Il),t.__h=[],Zn=0)),il=pe},ge.diffed=function(e){ss&&ss(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(mc.push(t)!==1&&is===ge.requestAnimationFrame||((is=ge.requestAnimationFrame)||wh)(kh)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),il=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.__||Il(i)})}catch(i){t.some(function(l){l.__h&&(l.__h=[])}),t=[],ge.__e(i,n.__v)}}),os&&os(e,t)},ge.unmount=function(e){cs&&cs(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 ds=typeof requestAnimationFrame=="function";function wh(e){var t,n=function(){clearTimeout(i),ds&&cancelAnimationFrame(t),setTimeout(e)},i=setTimeout(n,35);ds&&(t=requestAnimationFrame(n))}function Br(e){var t=pe,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),pe=t}function Il(e){var t=pe;e.__c=e.__(),pe=t}function gc(e,t){return!e||e.length!==t.length||t.some(function(n,i){return n!==e[i]})}function yc(e,t){return typeof t=="function"?t(e):t}var vh=Symbol.for("preact-signals");function ha(){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}();qn!==void 0;){var n=qn;for(qn=void 0,ai++;n!==void 0;){var i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&kc(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 qn=void 0,Rt=0,ai=0,hs=0,si=void 0,oi=0;function bc(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=vh;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 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 Li(function(){return e.value})};Object.defineProperty(ve.prototype,"value",{get:function(){var e=bc(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!==hs&&(n.l=hs,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{ha()}}}});function H(e,t){return new ve(e,t)}function kc(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 wc(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 vc(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&&!kc(this))return this.f&=-2,!0;var e=se;try{wc(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,vc(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=bc(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 _c(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,fa(e),i}finally{se=n,ha()}}}function fa(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,_c(e)}function _h(e){if(se!==this)throw new Error("Out-of-order effect");vc(this),se=e,this.f&=-2,8&this.f&&fa(this),ha()}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,_c(this),wc(this),Rt++;var e=se;return se=this,_h.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||fa(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 Ii,Cr;function xn(e,t){le[e]=t.bind(null,le[e]||function(){})}function ci(e){if(Cr){var t=Cr;Cr=void 0,t()}Cr=e&&e.S()}function xc(e){var t=this,n=e.data,i=Sc(n);i.value=n;var l=gr(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(),lc(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}xc.displayName="_st";Object.defineProperties(ve.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:xc},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),ci();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}())),Ii=i,ci(n)});xn("__e",function(e,t,n,i){ci(),Ii=void 0,e(t,n,i)});xn("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],f=i[u];c===void 0?(c=xh(n,u,f,l),a[u]=c):c.o(f,l)}}}e(t)});function xh(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 Sc(e){return gr(function(){return H(e)},[])}function ll(e){var t=te(e);return t.current=e,Ii.__$f|=4,gr(function(){return Vt(function(){return t.current()})},[])}const ce=H([]),Oi=H([]),Di=H([]),Bt=H([]),gt=H(null),fs=H(""),Ol=H(null),er=H(null),Dl=H("all"),tr=H(null),ke=H(null),Et=H(null),Ri=H(null),pa=H(null),$c=H(null),at=H([]),ui=H({}),Un=H(null),Wn=H(null),Kn=H(null),Cc=H(null),ma=H([]),sn=H(null),Tc=H(""),Ec=H(0),ga=H(null),zr=H({}),Ft=H({}),Be=H({}),Re=H({}),ps=H(0);let Pc=0;function Sh(e){if(Date.now()-Pc<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)}Be.value=t,Re.value=n}function ya(e,t){Pc=Date.now(),fetch(`/api/pane/tabs/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}).catch(()=>{})}function br(e){const t=tr.value;if(!t)return;const n=(ce.value||[]).find(s=>s.target===t);if(!n)return;const i=n.pid,l=Be.value[i]||[],a=l.find(s=>s.path===e.path);a?e.line&&e.line!==a.line&&(Be.value={...Be.value,[i]:l.map(s=>s.path===e.path?{...s,line:e.line}:s)}):Be.value={...Be.value,[i]:[...l,{...e,target:t}]},Re.value={...Re.value,[i]:`file:${e.path}`},ya("open",{pid:i,path:e.path,line:e.line??null})}function Ac(e,t){const i=(Be.value[e]||[]).filter(l=>l.path!==t);Be.value={...Be.value,[e]:i},Re.value[e]===`file:${t}`&&(Re.value={...Re.value,[e]:"pane"}),ya("close",{pid:e,path:t})}function jr(e,t){Re.value={...Re.value,[e]:t},ya("activate",{pid:e,tab:t})}const nr=H(new Set),ft=H(new Set),pt=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 $h(e,t=at.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 Ch(e){e.key==="Escape"&&on.length&&(e.stopPropagation(),on[on.length-1](e))}typeof window<"u"&&window.addEventListener("keydown",Ch,!0);function Fe(e,t=!0){j(()=>{if(t)return on.push(e),()=>{const n=on.indexOf(e);n>=0&&on.splice(n,1)}},[e,t])}const Th={};function Eh(e,t){const n=Th,i=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,l=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Mc(e,i,l)}function Mc(e,t,n){if(Ph(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 ms(e.children,t,n)}return Array.isArray(e)?ms(e,t,n):""}function ms(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 ys={}.hasOwnProperty;function Lc(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 He(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Se=wt(/[A-Za-z]/),Ee=wt(/[\dA-Za-z]/),Lh=wt(/[#-'*+\--9=?A-Z^-~]/);function di(e){return e!==null&&(e<32||e===127)}const Rl=wt(/\d/),Ih=wt(/[\dA-Fa-f]/),Oh=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 Fi=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 Bh(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(Fi(e))return 2}function Ni(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};ks(d,-u),ks(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,Ni(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(ws,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 Yh(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 al={name:"codeIndented",tokenize:Xh},Zh={partial:!0,tokenize:ef};function Xh(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(Zh,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 ef(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 tf={name:"codeText",previous:rf,resolve:nf,tokenize:lf};function nf(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 Nc(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||di(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 zc(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 ff={name:"definition",tokenize:mf},pf={partial:!0,tokenize:gf};function mf(e,t,n){const i=this;let l;return a;function a(h){return e.enter("definition"),s(h)}function s(h){return Bc.call(i,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function o(h){return l=He(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 Nc(e,f,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function f(h){return e.attempt(pf,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 gf(e,t,n){return i;function i(o){return oe(o)?Vn(e,l)(o):n(o)}function l(o){return zc(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 yf={name:"hardBreakEscape",tokenize:bf};function bf(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 kf={name:"headingAtx",resolve:wf,tokenize:vf};function wf(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 vf(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 _f=["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"],_s=["pre","script","style","textarea"],xf={concrete:!0,name:"htmlFlow",resolveTo:Cf,tokenize:Tf},Sf={partial:!0,tokenize:Pf},$f={partial:!0,tokenize:Ef};function Cf(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 Tf(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):Se(_)?(e.consume(_),s=String.fromCharCode(_),x):n(_)}function p(_){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&&_s.includes(he)?(l=1,i.interrupt?t(_):F(_)):_f.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):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(Sf,Z,q)(_)):_===null||U(_)?(e.exit("htmlFlowData"),q(_)):(e.consume(_),F)}function q(_){return e.check($f,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 _s.includes(X)?(e.consume(_),W):F(_)}return Se(_)&&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 Ef(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 Pf(e,t,n){return i;function i(l){return e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),e.attempt(kr,t,n)}}const Af={name:"htmlText",tokenize:Mf};function Mf(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),A):n(k)}function c(k){return k===45?(e.consume(k),f):k===91?(e.consume(k),a=0,m):Se(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 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 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||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"),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 ka={name:"labelEnd",resolveAll:Df,resolveTo:Rf,tokenize:Ff},Lf={tokenize:Nf},If={tokenize:Bf},Of={tokenize:zf};function Df(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:Qf},exit:Zf,name:"list",tokenize:Jf},Vf={partial:!0,tokenize:Xf},Gf={partial:!0,tokenize:Yf};function Jf(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:Rl(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 Rl(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(kr,i.interrupt?n:f,e.attempt(Vf,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 Qf(e,t,n){const i=this;return i.containerState._closeFlow=void 0,e.check(kr,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(Gf,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 Yf(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 Zf(e){e.exit(this.containerState.type)}function Xf(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 xs={name:"setextUnderline",resolveTo:ep,tokenize:tp};function ep(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 tp(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 np={tokenize:rp};function rp(e){const t=this,n=e.attempt(kr,i,e.attempt(this.parser.constructs.flowInitial,l,re(e,e.attempt(this.parser.constructs.flow,l,e.attempt(of,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 ip={resolveAll:Hc()},lp=jc("string"),ap=jc("text");function jc(e){return{resolveAll:Hc(e==="text"?sp: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 wp(e,t){let n=-1;const i=[];let l;for(;++n0){const Ne=J.tokenStack[J.tokenStack.length-1];(Ne[1]||Ts).call(J,void 0,Ne[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 p;function p(){let h=Kc,m,b,x;if(a(u,c,f[f.length-1]||void 0)&&(h=Np(n(u,f)),h[0]===Ps))return h;if("children"in u&&u.children){const w=u;if(w.children&&h[0]!==Rp)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=Es(e,"(");let a=Es(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 Vc(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||zt(n)||Fi(n))&&(!t||n!==47)}function em(){this.buffer()}function tm(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function nm(){this.buffer()}function rm(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function im(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=He(this.sliceSerialize(e)).toLowerCase(),n.label=t}function lm(e){this.exit(e)}function am(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=He(this.sliceSerialize(e)).toLowerCase(),n.label=t}function sm(e){this.exit(e)}function om(){return{enter:{gfmFootnoteCallString:em,gfmFootnoteCall:tm,gfmFootnoteDefinitionLabelString:nm,gfmFootnoteDefinition:rm},exit:{gfmFootnoteCallString:im,gfmFootnoteCall:lm,gfmFootnoteDefinitionLabelString:am,gfmFootnoteDefinition:sm}}}function cm(){return{canContainEols:["delete"],enter:{strikethrough:um},exit:{strikethrough:dm}}}function um(e){this.enter({type:"delete",children:[]},e)}function dm(e){this.exit(e)}function hm(){return{enter:{table:fm,tableData:As,tableHeader:As,tableRow:mm},exit:{codeText:gm,table:pm,tableData:cl,tableHeader:cl,tableRow:cl}}}function fm(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 pm(e){this.exit(e),this.data.inTable=void 0}function mm(e){this.enter({type:"tableRow",children:[]},e)}function cl(e){this.exit(e)}function As(e){this.enter({type:"tableCell",children:[]},e)}function gm(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,ym));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function ym(e,t){return t==="|"?t:e}function bm(){return{exit:{taskListCheckValueChecked:Ms,taskListCheckValueUnchecked:Ms,paragraph:km}}}function Ms(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function km(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 Mm={tokenize:Bm,partial:!0};function Lm(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Rm,continuation:{tokenize:Fm},exit:Nm}},text:{91:{name:"gfmFootnoteCall",tokenize:Dm},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Im,resolveTo:Om}}}}function Im(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=He(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 Om(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 Dm(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(He(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 Rm(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=He(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 Fm(e,t,n){return e.check(kr,t,e.attempt(Mm,t,n))}function Nm(e){e.exit("gfmFootnoteDefinition")}function Bm(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 zm(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 jm{constructor(){this.map=[]}add(t,n,i){Hm(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 Hm(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 Km(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 jm;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 Ls(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 Vm={name:"tasklistCheck",tokenize:Jm};function Gm(){return{text:{91:Vm}}}function Jm(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:Qm},t,n)(u):n(u)}}function Qm(e,t,n){return re(e,i,"whitespace");function i(l){return l===null?n(l):t(l)}}function ru(e){return Lc([_m(),Lm(),zm(),Um(),Gm()])}const Ym={pr_title:"from the PR title",branch:"from the branch name"};function wr(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=Ym[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 Zm=/^([a-z-]+): (.+)$/;function zl(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=Zm.exec(a.trim());if(!s)return null;i.push([s[1],s[2].trim()])}return i.length?i:null}function iu(e){return e.split(",").map(t=>t.trim().replace(/^`+|`+$/g,""))}const Xm=/^([\w.-]*[\w-]\/[\w./-]*[\w-]|[\w-]+(?:\.[\w-]+)*\.[A-Za-z][A-Za-z0-9]{1,5})(?::(\d+)(?:-(\d+))?)?$/;function zi(e){const t=Xm.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 eg(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?zi(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 tg=new Set(["new-subsystem","extension","reuse","system-touch","behavior"]);function ng(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 rg(e){var f,d,p;const t=String(e||""),i=Uc(t,{extensions:[ru()],mdastExtensions:[Gc()]}).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=Ur(i[c]),c++;const h=((d=i[c])==null?void 0:d.type)==="blockquote"?zl(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=Ur(i[c]),c++)}for(;cn.kind==="ctx"||n.kind==="add").length;return e.new_start+Math.max(t,1)-1}function lg(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&&ig(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 Is(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 ji={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 ag(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 sg=(e,t)=>typeof e=="string"?e.localeCompare(t):e-t;function og(e,t=null){const n=[...e||[]].sort((a,s)=>{var o,u;return Is(a)-Is(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&&ji[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*sg(o,u))})}function cg(e,t){const n=ji[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 ug(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=wr(i))==null?void 0:u.id,i.linked_linear_title].filter(Boolean).join(" ").toLowerCase();return n.every(c=>l.includes(c))}):e||[]}function Os(e){return(e||[]).filter(t=>!fi(t)).reduce((t,n)=>t+(n.unresolved||0),0)}const dg={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(dg).map(([e,t])=>({id:e,name:t.name,sprite:t}))];function lu(e){return pi.find(t=>t.id===e)||pi[0]}const au=10,_a=12,hg=19,fg=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 xa(e,{x0:t,sitting:n,height:i=_a}){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?fg:hg)-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 pg=.75,ul=(e,t=pg)=>({fill:"none",stroke:e,"stroke-width":t,"stroke-linecap":"square"});function mg(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 gg=new Set(["happy","x","down"]);function yg(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:ul(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 kg(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 wg(e){const{cx:t,top:n,w:i}=e.anchors.hat;return`translate(${t} ${n}) scale(${N(i/12)}) translate(-9 -9)`}function vg(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 Ds(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 Sa={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 Hi(e,t){const n=yn(e),{reach:i,at:l}=Sa[t];return[N(e.limb.root[0]+i),N(n.y+l*n.h)]}function _g(e,t,{scale:n,tx:i,ty:l}){const[a,s]=Hi(e,t);return[N(i+n*a),N(l+n*s)]}function Rs({scale:e,tx:t,ty:n},[i,l]){return[N((i-t)/e),N((l-n)/e)]}function jl(e,t,n=Hi(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 $a(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}]:[]:$a(i.g,t||!!i.arms,l)})}function xg(e){return $a(e.root).length===0}function Sg(e){const t=$a(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:jl(e,null,[N(e.limb.root[0]+1.6),N(n.y+.12*n.h)])}]}const su="#ff3b2f",$g="#f3f5f8";function Cg(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:$g,"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"}],ou={ui:"hanken",code:"plex-mono"};function cu(e,t){return mi.find(n=>n.id===e)||mi.find(n=>n.id===ou[t])}const Ye=H([]);let Tg=1;function bn(e,t="info",n=4e3){const i=Tg++;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 Eg(){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 dl(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(()=>dl(!1),5e3),addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&dl(!0)}),addEventListener("pagehide",()=>dl(!0)));const Hl={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 _e(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 Pg(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 Ag(e){return e?{"approve askuserquestion":"needs answer","permission prompt":"needs approval","dialog open":"needs input"}[e.toLowerCase()]||e.toLowerCase():"needs input"}function uu(e){if(!e)return null;const t=e.toLowerCase();return t==="permission prompt"?"permission":t==="approve askuserquestion"?"question":"dialog"}function du(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 hu(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`,l=e.gb==null?`Claude has been running ${i}`:`Claude is using ${e.gb}GB after ${i}`;return{label:e.trigger==="mem"?`${e.gb}G`:`${t}d`,title:`${l} — consider exiting and resuming this session`,cls:`mem-${e.tier}`}}function rr(e,t){return e?`https://github.com/${e}/pull/${t}`:null}function qi(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 Mg(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 Ui(){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 Ng(),me.value}catch{return me.value={...me.value,loaded:!1},null}}function Wr(){return G().commands||[]}async function Lg({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 Ig(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 Og(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 Dg(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 Ui(),!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 Rg(e){me.value={...G(),ui:e}}function Er(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 Ui(),!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 fu(e){if(!e)return[];const t=G().windows[e];return[...(t==null?void 0:t.pinned_files)||[]]}function Fg(e,t){if(!e||!t)return Promise.resolve(!1);const n=fu(e),i=n.includes(t)?n.filter(l=>l!==t):[...n,t];return Kr(e,{pinned_files:i})}async function Ng(){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 Bg(e,t){return $e({track_order:e},t)}function ir(){return{...(G().ui||{}).tabs_by_track||{}}}function zg(e){return $e({tabs_by_track:e})}function Ca(){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 pu(e,t){const n=lr();return n[e]=t,$e({rail_collapsed:n})}function jg(){var e;return((e=G().ui)==null?void 0:e.last_selected)||null}function yt(e){return $e({last_selected:e})}function Hg(){var e;return((e=G().ui)==null?void 0:e.launch_profile)||"default"}function qg(e){return $e({launch_profile:e})}function mu(){var e;return lu((e=G().ui)==null?void 0:e.tama_critter).id}function Ug(e){return $e({tama_critter:e})}function ar(e){var t;return cu((t=G().ui)==null?void 0:t[`${e}_font`],e)}function Wg(e,t){return $e({[`${e}_font`]:t})}const Kg={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{...Kg,...((e=G().ui)==null?void 0:e.notify)||{}}}function Vg(e,t){return $e({notify:{...yi(),[e]:t}})}function Ta(){var e;return[...((e=G().ui)==null?void 0:e.pinned_pids)||[]]}function Gg(e){return $e({pinned_pids:e})}function Jg(e){const t=Ta(),n=t.includes(e)?t.filter(i=>i!==e):[...t,e];return Gg(n)}function Qg(e){var t;return((t=G().ui)==null?void 0:t[e])??null}function Fs(e,t){return $e({[e]:t})}function Ea(e){var t;return!!((t=G().ui)!=null&&t[`${e}_hidden`])}function Yg(e,t){return $e({[`${e}_hidden`]:t})}function gu(e){var t,n;return((n=(t=G().ui)==null?void 0:t.detail_mode_by_pid)==null?void 0:n[e])||null}function ql(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 Pa(){const e=G().ui||{};return{merged:e.clawd_merged,furious:e.clawd_furious}}async function yu(e,t){var n;return G().loaded||await Ui(),!G().loaded||((n=Pa()[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 Aa(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 Zg(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 bu({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 Xg(e){if(Ve())try{await Aa("periscope:notification-clicked",e)}catch(t){console.warn("[tauri] notification-click listener failed:",t)}}async function e1(e){if(Ve())try{await Aa("periscope:notification-opened",e)}catch(t){console.warn("[tauri] notification-opened listener failed:",t)}}async function t1(e){if(Ve())try{await Aa("periscope:notification-action",e)}catch(t){console.warn("[tauri] notification-action listener failed:",t)}}async function n1(e){if(Ve())try{await $n("plugin:event|emit",{event:"periscope:notify-categories",payload:e})}catch(t){console.warn("[tauri] setNotifyCategories failed:",t)}}function Wi(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 r1(){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 i1(e){return!!(e!=null&&e.asked_question)&&!(e!=null&&e.waiting_for)}function Ns(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 Ma(e,t,n,i=new Set){const l=Ia(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=>!La(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 ku(e,t,n,i=new Set){const l=Ia(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=>!La(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 La(e,t){const n=t[e.target];return n?Math.max(n.focused_at||0,n.acted_at||0)>e.ts:!1}function l1(e){return e.length}const a1=600,s1=3600;function wu(e,t){const n=(t||0)-(e||0);return n>=s1?"urgent":n>=a1?"stale":"fresh"}function vu(e,t,n=new Set){var a;const i=Ia(e),l=new Map;for(const s of t||[]){if(s.kind!=="need_human"||n.has(s.id)||La(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=vu(e,t,n),o=new Map;for(const f of Ma(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 xu(e){return(e||[]).filter(t=>t.state==="working").map(t=>({kind:"live",pid:t.pid,w:t}))}function o1(e,t){const n={};for(const i of t||[])n[i.pid]=i;return(e||[]).map(i=>n[i]).filter(Boolean)}function c1(e){return(e||[]).filter(t=>t.kind==="done"||t.kind==="info")}function Ia(e){const t={};for(const n of e||[])t[n.target]=n;return t}const Oa=er;let Bs=!1;function jt(e){e&&st((ce.value||[]).find(t=>t.target===e))}function st(e){e!=null&&e.pid&&(ke.value=`pane:${e.pid}`,yt({kind:"pane",pid:e.pid}))}function Su(e){i1(e)&&(ft.value=new Set([...ft.value,e.pid])),st(e)}function $u(e){e!=null&&e.pid&&(pt.value=new Set([...pt.value,e.pid]))}function Cu(e){$u(e),st(e)}function u1(){Bs||(Bs=!0,Xg(e=>jt(e)))}function Tu(e,t){!e||!t||(ke.value=`review:${e}/${t.replace(/\//g,"--")}`,yt({kind:"review",repo:e,branch:t}))}function Da(){ke.value="reviews",yt({kind:"reviews"})}const hl=[{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 d1(){const[e,t]=B(!1),n=te(null),i=Dl.value,l=(hl.find(o=>o.key===i)||hl[0]).label,a=yr(()=>t(!1),[]);Fe(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){Dl.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:hl.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 Eu=Vt(()=>Ea("rail")),bi=Vt(()=>Ea("side"));function Ul(e){return Yg(e,!Ea(e))}function zs({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 h1(){const e=!Eu.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:()=>Ul("rail"),children:r(zs,{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:()=>Ul("side"),children:r(zs,{side:"right",shown:t})})]})}function sr(e){return e>=1024?`${(e/1024).toFixed(1)}G`:`${e}M`}function Pu(e){return e==null?"–":`${Math.round(e)}%`}function f1(e){var t;return e.server.mem_mb+(((t=e.webview)==null?void 0:t.mem_mb)||0)+e.panes.mem_mb}function p1(e){return e.filter(t=>t.res).map(t=>({w:t,...t.res})).sort((t,n)=>n.mem_mb-t.mem_mb)}function m1(e){return`load ${e.load1} · swap ${sr(e.swap_used_mb)}/${sr(e.swap_total_mb)} · ${e.mem_free_pct}% free`}const g1="CPU per core: 100% is one core fully busy";function Pr({label:e,group:t,onClick:n}){const i=r(K,{children:[r("span",{class:"res-label",children:e}),r("span",{class:"res-mem",children:sr(t.mem_mb)}),r("span",{class:"res-cpu",title:g1,children:Pu(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 y1(){const e=te(null),[t,n]=B(!1),i=$c.value,l=yr(()=>n(!1),[]);return Fe(l,t),j(()=>{if(!t)return;function a(s){e.current&&!e.current.contains(s.target)&&l()}return document.addEventListener("click",a),()=>document.removeEventListener("click",a)},[t]),j(()=>{!i&&t&&l()},[i,t]),i?r("div",{class:"res-dd",ref:e,children:[r("button",{type:"button",class:"res-pill",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":t?"true":"false",onClick:()=>n(!t),children:["▣ ",sr(f1(i))]}),r("div",{class:"tb-dd-menu res-menu",role:"dialog",hidden:!t,children:[r(Pr,{label:"periscope server",group:i.server}),i.webview&&r(Pr,{label:"webview",group:i.webview}),p1(ce.value||[]).map(({w:a,mem_mb:s,cpu_pct:o})=>r(Pr,{label:_e(a),group:{mem_mb:s,cpu_pct:o},onClick:()=>{st(a),l()}},a.pid)),r(Pr,{label:"elsewhere",group:i.elsewhere}),r("div",{class:"res-machine",children:m1(i.machine)})]})]}):null}async function Au(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 b1(){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 +`))for(const a of l.replace(/^\s*> ?/,"").split(" · ")){const s=Zm.exec(a.trim());if(!s)return null;i.push([s[1],s[2].trim()])}return i.length?i:null}function iu(e){return e.split(",").map(t=>t.trim().replace(/^`+|`+$/g,""))}const Xm=/^([\w.-]*[\w-]\/[\w./-]*[\w-]|[\w-]+(?:\.[\w-]+)*\.[A-Za-z][A-Za-z0-9]{1,5})(?::(\d+)(?:-(\d+))?)?$/;function zi(e){const t=Xm.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 eg(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?zi(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 tg=new Set(["new-subsystem","extension","reuse","system-touch","behavior"]);function ng(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 rg(e){var f,d,p;const t=String(e||""),i=Uc(t,{extensions:[ru()],mdastExtensions:[Gc()]}).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=Ur(i[c]),c++;const h=((d=i[c])==null?void 0:d.type)==="blockquote"?zl(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=Ur(i[c]),c++)}for(;cn.kind==="ctx"||n.kind==="add").length;return e.new_start+Math.max(t,1)-1}function lg(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&&ig(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 Is(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 ji={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 ag(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 sg=(e,t)=>typeof e=="string"?e.localeCompare(t):e-t;function og(e,t=null){const n=[...e||[]].sort((a,s)=>{var o,u;return Is(a)-Is(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&&ji[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*sg(o,u))})}function cg(e,t){const n=ji[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 ug(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=wr(i))==null?void 0:u.id,i.linked_linear_title].filter(Boolean).join(" ").toLowerCase();return n.every(c=>l.includes(c))}):e||[]}function Os(e){return(e||[]).filter(t=>!fi(t)).reduce((t,n)=>t+(n.unresolved||0),0)}const dg={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(dg).map(([e,t])=>({id:e,name:t.name,sprite:t}))];function lu(e){return pi.find(t=>t.id===e)||pi[0]}const au=10,_a=12,hg=19,fg=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 xa(e,{x0:t,sitting:n,height:i=_a}){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?fg:hg)-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 pg=.75,ul=(e,t=pg)=>({fill:"none",stroke:e,"stroke-width":t,"stroke-linecap":"square"});function mg(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 gg=new Set(["happy","x","down"]);function yg(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:ul(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 kg(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 wg(e){const{cx:t,top:n,w:i}=e.anchors.hat;return`translate(${t} ${n}) scale(${N(i/12)}) translate(-9 -9)`}function vg(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 Ds(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 Sa={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 Hi(e,t){const n=yn(e),{reach:i,at:l}=Sa[t];return[N(e.limb.root[0]+i),N(n.y+l*n.h)]}function _g(e,t,{scale:n,tx:i,ty:l}){const[a,s]=Hi(e,t);return[N(i+n*a),N(l+n*s)]}function Rs({scale:e,tx:t,ty:n},[i,l]){return[N((i-t)/e),N((l-n)/e)]}function jl(e,t,n=Hi(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 $a(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}]:[]:$a(i.g,t||!!i.arms,l)})}function xg(e){return $a(e.root).length===0}function Sg(e){const t=$a(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:jl(e,null,[N(e.limb.root[0]+1.6),N(n.y+.12*n.h)])}]}const su="#ff3b2f",$g="#f3f5f8";function Cg(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:$g,"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"}],ou={ui:"hanken",code:"plex-mono"};function cu(e,t){return mi.find(n=>n.id===e)||mi.find(n=>n.id===ou[t])}const Ye=H([]);let Tg=1;function bn(e,t="info",n=4e3){const i=Tg++;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 Eg(){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 dl(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(()=>dl(!1),5e3),addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&dl(!0)}),addEventListener("pagehide",()=>dl(!0)));const Hl={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 _e(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 Pg(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 Ag(e){return e?{"approve askuserquestion":"needs answer","permission prompt":"needs approval","dialog open":"needs input"}[e.toLowerCase()]||e.toLowerCase():"needs input"}function uu(e){if(!e)return null;const t=e.toLowerCase();return t==="permission prompt"?"permission":t==="approve askuserquestion"?"question":"dialog"}function du(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 hu(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`,l=e.gb==null?`Claude has been running ${i}`:`Claude is using ${e.gb}GB after ${i}`;return{label:e.trigger==="mem"?`${e.gb}G`:`${t}d`,title:`${l} — consider exiting and resuming this session`,cls:`mem-${e.tier}`}}function rr(e,t){return e?`https://github.com/${e}/pull/${t}`:null}function qi(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 Mg(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 Ui(){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 Ng(),me.value}catch{return me.value={...me.value,loaded:!1},null}}function Wr(){return G().commands||[]}async function Lg({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 Ig(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 Og(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 Dg(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 Ui(),!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 Rg(e){me.value={...G(),ui:e}}function Er(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 Ui(),!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 fu(e){if(!e)return[];const t=G().windows[e];return[...(t==null?void 0:t.pinned_files)||[]]}function Fg(e,t){if(!e||!t)return Promise.resolve(!1);const n=fu(e),i=n.includes(t)?n.filter(l=>l!==t):[...n,t];return Kr(e,{pinned_files:i})}async function Ng(){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 Bg(e,t){return $e({track_order:e},t)}function ir(){return{...(G().ui||{}).tabs_by_track||{}}}function zg(e){return $e({tabs_by_track:e})}function Ca(){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 pu(e,t){const n=lr();return n[e]=t,$e({rail_collapsed:n})}function jg(){var e;return((e=G().ui)==null?void 0:e.last_selected)||null}function yt(e){return $e({last_selected:e})}function Hg(){var e;return((e=G().ui)==null?void 0:e.launch_profile)||"default"}function qg(e){return $e({launch_profile:e})}function mu(){var e;return lu((e=G().ui)==null?void 0:e.tama_critter).id}function Ug(e){return $e({tama_critter:e})}function ar(e){var t;return cu((t=G().ui)==null?void 0:t[`${e}_font`],e)}function Wg(e,t){return $e({[`${e}_font`]:t})}const Kg={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{...Kg,...((e=G().ui)==null?void 0:e.notify)||{}}}function Vg(e,t){return $e({notify:{...yi(),[e]:t}})}function Ta(){var e;return[...((e=G().ui)==null?void 0:e.pinned_pids)||[]]}function Gg(e){return $e({pinned_pids:e})}function Jg(e){const t=Ta(),n=t.includes(e)?t.filter(i=>i!==e):[...t,e];return Gg(n)}function Qg(e){var t;return((t=G().ui)==null?void 0:t[e])??null}function Fs(e,t){return $e({[e]:t})}function Ea(e){var t;return!!((t=G().ui)!=null&&t[`${e}_hidden`])}function Yg(e,t){return $e({[`${e}_hidden`]:t})}function gu(e){var t,n;return((n=(t=G().ui)==null?void 0:t.detail_mode_by_pid)==null?void 0:n[e])||null}function ql(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 Pa(){const e=G().ui||{};return{merged:e.clawd_merged,furious:e.clawd_furious}}async function yu(e,t){var n;return G().loaded||await Ui(),!G().loaded||((n=Pa()[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 Aa(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 Zg(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 bu({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 Xg(e){if(Ve())try{await Aa("periscope:notification-clicked",e)}catch(t){console.warn("[tauri] notification-click listener failed:",t)}}async function e1(e){if(Ve())try{await Aa("periscope:notification-opened",e)}catch(t){console.warn("[tauri] notification-opened listener failed:",t)}}async function t1(e){if(Ve())try{await Aa("periscope:notification-action",e)}catch(t){console.warn("[tauri] notification-action listener failed:",t)}}async function n1(e){if(Ve())try{await $n("plugin:event|emit",{event:"periscope:notify-categories",payload:e})}catch(t){console.warn("[tauri] setNotifyCategories failed:",t)}}function Wi(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 r1(){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 i1(e){return!!(e!=null&&e.asked_question)&&!(e!=null&&e.waiting_for)}function Ns(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 Ma(e,t,n,i=new Set){const l=Ia(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=>!La(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 ku(e,t,n,i=new Set){const l=Ia(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=>!La(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 La(e,t){const n=t[e.target];return n?Math.max(n.focused_at||0,n.acted_at||0)>e.ts:!1}function l1(e){return e.length}const a1=600,s1=3600;function wu(e,t){const n=(t||0)-(e||0);return n>=s1?"urgent":n>=a1?"stale":"fresh"}function vu(e,t,n=new Set){var a;const i=Ia(e),l=new Map;for(const s of t||[]){if(s.kind!=="need_human"||n.has(s.id)||La(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=vu(e,t,n),o=new Map;for(const f of Ma(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 xu(e){return(e||[]).filter(t=>t.state==="working").map(t=>({kind:"live",pid:t.pid,w:t}))}function o1(e,t){const n={};for(const i of t||[])n[i.pid]=i;return(e||[]).map(i=>n[i]).filter(Boolean)}function c1(e){return(e||[]).filter(t=>t.kind==="done"||t.kind==="info")}function Ia(e){const t={};for(const n of e||[])t[n.target]=n;return t}const Oa=er;let Bs=!1;function jt(e){e&&st((ce.value||[]).find(t=>t.target===e))}function st(e){e!=null&&e.pid&&(ke.value=`pane:${e.pid}`,yt({kind:"pane",pid:e.pid}))}function Su(e){i1(e)&&(ft.value=new Set([...ft.value,e.pid])),st(e)}function $u(e){e!=null&&e.pid&&(pt.value=new Set([...pt.value,e.pid]))}function Cu(e){$u(e),st(e)}function u1(){Bs||(Bs=!0,Xg(e=>jt(e)))}function Tu(e,t){!e||!t||(ke.value=`review:${e}/${t.replace(/\//g,"--")}`,yt({kind:"review",repo:e,branch:t}))}function Da(){ke.value="reviews",yt({kind:"reviews"})}const hl=[{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 d1(){const[e,t]=B(!1),n=te(null),i=Dl.value,l=(hl.find(o=>o.key===i)||hl[0]).label,a=yr(()=>t(!1),[]);Fe(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){Dl.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:hl.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 Eu=Vt(()=>Ea("rail")),bi=Vt(()=>Ea("side"));function Ul(e){return Yg(e,!Ea(e))}function zs({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 h1(){const e=!Eu.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:()=>Ul("rail"),children:r(zs,{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:()=>Ul("side"),children:r(zs,{side:"right",shown:t})})]})}function sr(e){return e>=1024?`${(e/1024).toFixed(1)}G`:`${e}M`}function Pu(e){return e==null?"–":e<10?`${e.toFixed(1)}%`:`${Math.round(e)}%`}function f1(e){var t;return e.server.mem_mb+(((t=e.webview)==null?void 0:t.mem_mb)||0)+e.panes.mem_mb}function p1(e){return e.filter(t=>t.res).map(t=>({w:t,...t.res})).sort((t,n)=>n.mem_mb-t.mem_mb)}function m1(e){return`load ${e.load1} · swap ${sr(e.swap_used_mb)}/${sr(e.swap_total_mb)} · ${e.mem_free_pct}% free`}const g1="share of the whole machine's CPU: 100% is every core busy";function Pr({label:e,group:t,onClick:n}){const i=r(K,{children:[r("span",{class:"res-label",children:e}),r("span",{class:"res-mem",children:sr(t.mem_mb)}),r("span",{class:"res-cpu",title:g1,children:Pu(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 y1(){const e=te(null),[t,n]=B(!1),i=$c.value,l=yr(()=>n(!1),[]);return Fe(l,t),j(()=>{if(!t)return;function a(s){e.current&&!e.current.contains(s.target)&&l()}return document.addEventListener("click",a),()=>document.removeEventListener("click",a)},[t]),j(()=>{!i&&t&&l()},[i,t]),i?r("div",{class:"res-dd",ref:e,children:[r("button",{type:"button",class:"res-pill",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":t?"true":"false",onClick:()=>n(!t),children:["▣ ",sr(f1(i))]}),r("div",{class:"tb-dd-menu res-menu",role:"dialog",hidden:!t,children:[r(Pr,{label:"periscope server",group:i.server}),i.webview&&r(Pr,{label:"webview",group:i.webview}),p1(ce.value||[]).map(({w:a,mem_mb:s,cpu_pct:o})=>r(Pr,{label:_e(a),group:{mem_mb:s,cpu_pct:o},onClick:()=>{st(a),l()}},a.pid)),r(Pr,{label:"elsewhere",group:i.elsewhere}),r("div",{class:"res-machine",children:m1(i.machine)})]})]}):null}async function Au(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 b1(){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 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:()=>Au(i.id),children:i.id===null&&t===null&&n?`auto → ${gn(n.account)}`:i.label},i.id??"auto"))]})}const Ra=["default","low","medium","high","xhigh","max"];async function k1(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 w1(){const e=Kn.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 @@ -34,7 +34,7 @@ ${n}`:w?"updating — periscope will restart itself":$?`${g}, but ${v}`:`${g} `),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 Ow(e){const t=e.input||{};switch(e.name){case"Bash":return t.command||"";case"Write":return t.content||"";default:return""}}function Dw({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 Rw({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=Ow(e),u=!i&&e.result!=null&&e.result!=="",c=l||a||!!o||u,f=Lw(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(),br({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(Iw,{input:e.input||{}}):a?r(Dw,{input:e.input||{}}):o&&r("pre",{class:"tc-cmd",children:o}),u&&r("pre",{class:"tc-out",children:e.result})]})]})}function Fw({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:pr(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:pr(e.text)}),n.length>0&&r("div",{class:"turn-tools",children:n.map((i,l)=>r(Rw,{t:i},i.id||l))})]})}function Nw({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?${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 Bw({target:e,pid:t,selected:n,state:i,waitingFor:l,spinner:a}){var m;Mw(e,t,n);const s=((m=Ft.value[t])==null?void 0:m.messages)||[],o=te(null),u=te(null),c=te(!0),f=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!==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(K,{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(Fw,{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(Nw,{target:e,composerRef:u})]})}const zw=1500;function jw(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Hw({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 qw({pid:e,paneLabel:t}){const n=Be.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:jw(l.path)}),r("span",{class:"detail-tab-close",title:"Close tab",onClick:o=>{o.stopPropagation(),Ac(e,l.path)},children:"×"})]},a)})]})}function Vo(e){return(ce.value||[]).find(t=>t.pid===e)||null}function Jd(e){return(e==null?void 0:e.agent)!=="claude"?"terminal":gu(e.pid)||"terminal"}async function Uw(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||Ks(`\r \x1B[31m[periscope: image paste failed: ${s.error}]\x1B[0m`)}catch(a){Ks(`\r -\x1B[31m[periscope: image paste error: ${a.message}]\x1B[0m`)}return}}}function Ww({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=rr(e.repo_slug,e.pr),a=qi(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=wr(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(Pw,{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.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 CPU per core (100% = one core)",children:`${sr(e.res.mem_mb)} mem · ${Pu(e.res.cpu_pct)} cpu`})]})),e.agent==="claude"&&e.mem){const l=hu(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"})]})),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 Kw({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,zw);return()=>{i=!1,clearInterval(a)}},[e]),t?r(cw,{data:t,onRefresh:()=>{},containerId:"detail-side",containerClass:"detail-side",idPrefix:"detail"}):r("aside",{id:"detail-side",class:"detail-side"})}function Vw({w:e}){const t=Jd(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(()=>(Hs(c=>{let f=c,d=null;const p=f.match(/^(.*?):(\d+)$/);p&&(f=p[1],d=p[2]),br({path:f,line:d})}),()=>Hs(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(vi));return()=>cancelAnimationFrame(c)},[t]);const[n,i]=B(!0);j(()=>{if(t!=="terminal")return;const c=()=>i(I1());c();const f=setInterval(c,250);return()=>clearInterval(f)},[t,e.pid]);const l=te(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=Be.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(Ww,{w:e}),r("div",{id:"detail-tab-bar",class:"detail-tab-bar",children:[r(qw,{pid:e.pid,paneLabel:u}),e.agent==="claude"&&r(Hw,{mode:t,onMode:c=>{ye("view.switch",{view:c}),ql(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(ww,{id:"detail-xterm",class:"detail-xterm",target:e.pane_id,agent:e.agent,onPaste:Uw},e.pid)}),r("div",{class:"detail-changes-host",style:s==="changes"?"display:contents":"display:none",children:r(Uk,{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(dw,{entry:c,active:d})},f)}),!bi.value&&r(Kw,{target:e.target},e.target),!bi.value&&r(Gd,{which:"side"})]}),o&&t==="terminal"&&!n&&r("button",{class:"term-scroll-bottom",title:"Scroll to latest",onClick:vi,children:"⤓"}),o&&t==="terminal"&&r(vw,{})]})}function Sl(){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 Gw(){var d,p;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)&&(tr.value=null)},[e]);const s=n?Vo(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=Jd(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(Sl,{}),n&&(s?r(Vw,{w:s}):r(Sl,{})),l&&r(mw,{}),i&&(gt.value===null?r("div",{class:"wt-empty",children:"loading…"}):a?r(kw,{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(Sl,{})),f.map(h=>{const m=Vo(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(Bw,{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 $l(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 ra=H(!1);function Cl(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 Tl(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 Jw(e,t){return!!t&&!!(e!=null&&e.branch)}function Qw(e,t){return`open ${e!=null&&e.branch?`${e.branch} `:""}worktree in ${t}`}const Yw=900;function Za(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 Zw(e){return e==="✓"?"ok":e==="✗"?"bad":e==="⟳"?"running":"neutral"}function Xw(e){return e?e.replace(/\s*\(.*$/,"").trim():null}function ev(e){return`${Math.round(e/1e3)}k`}function Rn(e){return e.context_pct!=null?`${e.context_pct}%`:e.ctx_tokens!=null?ev(e.ctx_tokens):null}function Qd({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 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 tv({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=_e(e),E=e.agent||(e.is_claude?"claude":null),A=Hl[E],T=e.status_rail||e.status_line,S=e.status_at&&Math.floor(Date.now()/1e3)-e.status_at>Yw,R=Xw(e.model),F=e.pr?rr(e.repo_slug,e.pr):null,q=hu(e.mem),L=d?wu(d,Math.floor(Date.now()/1e3)):null,I=$h(e),O=qi(e.pr_state),Q=`PR #${e.pr}${O.suffix}`,M=r(K,{children:["#",e.pr,e.ci&&!O.cls?r("span",{class:`pane-ci pane-ci-${Zw(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=wr(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 ${Co(e.profile)} profile — a different plugin set and system prompt than a normal pane`,children:Co(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(Qd,{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${Kl(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${Kl(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?"🔒":"🔓"}),Jw(e,m)&&r("button",{class:"rail-editor",title:Qw(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 nv({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 rv({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:Za(i)})]})}function Go({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 iv({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(Qd,{label:t,kind:"track",renameable:e!=="loose",onCommit:s}),r("span",{class:"repo-rule","aria-hidden":"true"}),r("span",{class:Za(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 Yd(e){const t=[...new Set((e||[]).map(n=>n.session).filter(Boolean))];return n=>du(n,t)}function zn(e,t){pu(e,!t)}function Zt(e){return`${e.kind}:${e.pid??e.id}`}function lv(){var A,T,S,R,F,q;me.value;const e=ce.value||[],t=Oa.value||[],n=nr.value,i=ft.value,l=lr(),a=Yd(e),s=Ma(e,t,n,i),o=l["sec:needs"]===!0,u=ku(e,t,n,pt.value),c=l["sec:ready"]===!0,f=xu(e),d=l["sec:running"]===!0,p=o1(Ta(),e),h=l["sec:pinned"]===!0,m=ra.value,b=te(null),x=Cl(s,(A=b.current)==null?void 0:A.needs,m,Zt),w=Cl(u,(T=b.current)==null?void 0:T.ready,m,Zt),C=Cl(f,(S=b.current)==null?void 0:S.running,m,Zt),y=Tl(s,(R=b.current)==null?void 0:R.needs,m,Zt)||Tl(u,(F=b.current)==null?void 0:F.ready,m,Zt)||Tl(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=Ns(ft.value,e,"needs-input");L.size!==ft.value.size&&(ft.value=L);const I=Ns(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),nr.value=I}function v(L){g(),Su(L)}function E(L){g(),Cu(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:l1(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:Ag((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:()=>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(K,{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:()=>st(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(K,{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:()=>st(L),children:[r("span",{class:`attn-ico ${((I=Hl[L.agent])==null?void 0:I.className)||""}`,children:((O=Hl[L.agent])==null?void 0:O.glyph)||"$"}),r("span",{class:"attn-label",children:$t(L,null,null,a)}),r("span",{class:Za(L.state),style:"margin-left:auto"})]},`pin:${L.pid}`)})]})]})}function av(){me.value;const e=Oa.value||[],t=lr(),n=Yd(ce.value||[]),i=c1(e),l=t["sec:activity"]!==!1;return r(K,{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 sv="";function ov(e){const t=window.__periscopeOpenLauncher;typeof t=="function"&&t(e)}function cv(e,t){return!t||t==="all"?e:e.filter(n=>n.track_id===t)}function uv({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 Jo=0;function dv(){if(Date.now()-Jo<5e3)return;const e=ce.value||[];if(e.length===0)return;Jo=Date.now();const t=Qa(e,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ir(),branchOrderByTrack:Ca()},Bt.value),n=gi(),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 Zd(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}=Qa(u,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ir(),branchOrderByTrack:Ca()},m),y=lb(b,x,d,gt.value||[]);function g(M){if(M==="reviews"){Da();return}if(M.startsWith("review:")){const z=M.slice(7),k=z.indexOf("/"),W=(gt.value||[]).find(Z=>Z.repo===z.slice(0,k)&&Z.slug===z.slice(k+1));W&&Tu(W.repo,W.branch);return}ke.value=M,ye("pane.focus",{key:M}),M.startsWith("pane:")&&yt({kind:"pane",pid:M.slice(5)})}function $(M){const z=lr()[M]===!0;pu(M,!z)}async function v(M){await Jn(`Close tab "${_e(M)}"? +\x1B[31m[periscope: image paste error: ${a.message}]\x1B[0m`)}return}}}function Ww({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=rr(e.repo_slug,e.pr),a=qi(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=wr(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(Pw,{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.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:`${sr(e.res.mem_mb)} mem · ${Pu(e.res.cpu_pct)} cpu`})]})),e.agent==="claude"&&e.mem){const l=hu(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"})]})),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 Kw({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,zw);return()=>{i=!1,clearInterval(a)}},[e]),t?r(cw,{data:t,onRefresh:()=>{},containerId:"detail-side",containerClass:"detail-side",idPrefix:"detail"}):r("aside",{id:"detail-side",class:"detail-side"})}function Vw({w:e}){const t=Jd(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(()=>(Hs(c=>{let f=c,d=null;const p=f.match(/^(.*?):(\d+)$/);p&&(f=p[1],d=p[2]),br({path:f,line:d})}),()=>Hs(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(vi));return()=>cancelAnimationFrame(c)},[t]);const[n,i]=B(!0);j(()=>{if(t!=="terminal")return;const c=()=>i(I1());c();const f=setInterval(c,250);return()=>clearInterval(f)},[t,e.pid]);const l=te(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=Be.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(Ww,{w:e}),r("div",{id:"detail-tab-bar",class:"detail-tab-bar",children:[r(qw,{pid:e.pid,paneLabel:u}),e.agent==="claude"&&r(Hw,{mode:t,onMode:c=>{ye("view.switch",{view:c}),ql(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(ww,{id:"detail-xterm",class:"detail-xterm",target:e.pane_id,agent:e.agent,onPaste:Uw},e.pid)}),r("div",{class:"detail-changes-host",style:s==="changes"?"display:contents":"display:none",children:r(Uk,{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(dw,{entry:c,active:d})},f)}),!bi.value&&r(Kw,{target:e.target},e.target),!bi.value&&r(Gd,{which:"side"})]}),o&&t==="terminal"&&!n&&r("button",{class:"term-scroll-bottom",title:"Scroll to latest",onClick:vi,children:"⤓"}),o&&t==="terminal"&&r(vw,{})]})}function Sl(){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 Gw(){var d,p;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)&&(tr.value=null)},[e]);const s=n?Vo(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=Jd(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(Sl,{}),n&&(s?r(Vw,{w:s}):r(Sl,{})),l&&r(mw,{}),i&&(gt.value===null?r("div",{class:"wt-empty",children:"loading…"}):a?r(kw,{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(Sl,{})),f.map(h=>{const m=Vo(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(Bw,{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 $l(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 ra=H(!1);function Cl(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 Tl(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 Jw(e,t){return!!t&&!!(e!=null&&e.branch)}function Qw(e,t){return`open ${e!=null&&e.branch?`${e.branch} `:""}worktree in ${t}`}const Yw=900;function Za(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 Zw(e){return e==="✓"?"ok":e==="✗"?"bad":e==="⟳"?"running":"neutral"}function Xw(e){return e?e.replace(/\s*\(.*$/,"").trim():null}function ev(e){return`${Math.round(e/1e3)}k`}function Rn(e){return e.context_pct!=null?`${e.context_pct}%`:e.ctx_tokens!=null?ev(e.ctx_tokens):null}function Qd({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 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 tv({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=_e(e),E=e.agent||(e.is_claude?"claude":null),A=Hl[E],T=e.status_rail||e.status_line,S=e.status_at&&Math.floor(Date.now()/1e3)-e.status_at>Yw,R=Xw(e.model),F=e.pr?rr(e.repo_slug,e.pr):null,q=hu(e.mem),L=d?wu(d,Math.floor(Date.now()/1e3)):null,I=$h(e),O=qi(e.pr_state),Q=`PR #${e.pr}${O.suffix}`,M=r(K,{children:["#",e.pr,e.ci&&!O.cls?r("span",{class:`pane-ci pane-ci-${Zw(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=wr(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 ${Co(e.profile)} profile — a different plugin set and system prompt than a normal pane`,children:Co(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(Qd,{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${Kl(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${Kl(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?"🔒":"🔓"}),Jw(e,m)&&r("button",{class:"rail-editor",title:Qw(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 nv({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 rv({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:Za(i)})]})}function Go({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 iv({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(Qd,{label:t,kind:"track",renameable:e!=="loose",onCommit:s}),r("span",{class:"repo-rule","aria-hidden":"true"}),r("span",{class:Za(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 Yd(e){const t=[...new Set((e||[]).map(n=>n.session).filter(Boolean))];return n=>du(n,t)}function zn(e,t){pu(e,!t)}function Zt(e){return`${e.kind}:${e.pid??e.id}`}function lv(){var A,T,S,R,F,q;me.value;const e=ce.value||[],t=Oa.value||[],n=nr.value,i=ft.value,l=lr(),a=Yd(e),s=Ma(e,t,n,i),o=l["sec:needs"]===!0,u=ku(e,t,n,pt.value),c=l["sec:ready"]===!0,f=xu(e),d=l["sec:running"]===!0,p=o1(Ta(),e),h=l["sec:pinned"]===!0,m=ra.value,b=te(null),x=Cl(s,(A=b.current)==null?void 0:A.needs,m,Zt),w=Cl(u,(T=b.current)==null?void 0:T.ready,m,Zt),C=Cl(f,(S=b.current)==null?void 0:S.running,m,Zt),y=Tl(s,(R=b.current)==null?void 0:R.needs,m,Zt)||Tl(u,(F=b.current)==null?void 0:F.ready,m,Zt)||Tl(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=Ns(ft.value,e,"needs-input");L.size!==ft.value.size&&(ft.value=L);const I=Ns(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),nr.value=I}function v(L){g(),Su(L)}function E(L){g(),Cu(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:l1(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:Ag((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:()=>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(K,{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:()=>st(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(K,{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:()=>st(L),children:[r("span",{class:`attn-ico ${((I=Hl[L.agent])==null?void 0:I.className)||""}`,children:((O=Hl[L.agent])==null?void 0:O.glyph)||"$"}),r("span",{class:"attn-label",children:$t(L,null,null,a)}),r("span",{class:Za(L.state),style:"margin-left:auto"})]},`pin:${L.pid}`)})]})]})}function av(){me.value;const e=Oa.value||[],t=lr(),n=Yd(ce.value||[]),i=c1(e),l=t["sec:activity"]!==!1;return r(K,{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 sv="";function ov(e){const t=window.__periscopeOpenLauncher;typeof t=="function"&&t(e)}function cv(e,t){return!t||t==="all"?e:e.filter(n=>n.track_id===t)}function uv({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 Jo=0;function dv(){if(Date.now()-Jo<5e3)return;const e=ce.value||[];if(e.length===0)return;Jo=Date.now();const t=Qa(e,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ir(),branchOrderByTrack:Ca()},Bt.value),n=gi(),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 Zd(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}=Qa(u,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ir(),branchOrderByTrack:Ca()},m),y=lb(b,x,d,gt.value||[]);function g(M){if(M==="reviews"){Da();return}if(M.startsWith("review:")){const z=M.slice(7),k=z.indexOf("/"),W=(gt.value||[]).find(Z=>Z.repo===z.slice(0,k)&&Z.slug===z.slice(k+1));W&&Tu(W.repo,W.branch);return}ke.value=M,ye("pane.focus",{key:M}),M.startsWith("pane:")&&yt({kind:"pane",pid:M.slice(5)})}function $(M){const z=lr()[M]===!0;pu(M,!z)}async function v(M){await Jn(`Close tab "${_e(M)}"? 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 mr("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 Jn(`${_} From 9af1432c24019fa60e175a0ca907b6dd61593b4d Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 08:27:45 -0400 Subject: [PATCH 26/52] resources: the machine line leads with physical RAM, so owners adding up past it read as overcommitment (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- .../specs/2026-10-30-resource-monitor-design.md | 9 +++++---- periscope/resources.py | 10 +++++++--- .../src/chrome/__tests__/resourcePillRender.test.jsx | 4 ++-- static/src/chrome/__tests__/resources.test.js | 6 +++--- static/src/chrome/resources.js | 2 +- tests/conftest.py | 2 +- tests/test_resources.py | 5 +++-- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index aeee0db0..404bc768 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -73,8 +73,8 @@ for a server averaging 10%). A previous sample older than 10 s (a hub that idled missing. With no usable previous sample, `cpu_pct` is `null`, never 0. A 0 is either measured idle or an interval D4 clamped (a member reaped outside its group, e.g. a closed pane's shell). -**D6 — The machine line reads the kernel directly, with no fork.** Load average from `os.getloadavg()`; swap used -and total from `sysctlbyname("vm.swapusage")`; free memory percent from `kern.memorystatus_level`, the figure +**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 @@ -91,7 +91,7 @@ liveness and age but drops `rss=`; moving liveness off `ps` belongs to THI-450. - `measure(panes)` → `Measurement | None`, given `{pane_id: pane_pid}`. It reads every process once, assigns each to a group (D3), 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, swap_used_mb, swap_total_mb, mem_free_pct}`. `None` when the snapshot failed. + `null`; `machine` is D6's `{load1, ram_mb, swap_used_mb, swap_total_mb, mem_free_pct}`. `None` when the snapshot failed. - `footprint_mb(pid)` — one process's footprint, for the ↻ hint (D7). `build_state` calls `measure` after the fan-out and before the narrator merge. Each row gets `res`; the blob gets @@ -105,7 +105,8 @@ there would disturb the CPU history of every other group. - **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, then every pane sorted by - memory (a line selects its pane), then elsewhere, then the machine line: `load 52 · swap 16.5/17.4G · 27% free`. + memory (a line selects its pane), then elsewhere, then the machine line: `16.0G RAM · swap 16.5G/17.4G · 27% free · load 52`. RAM leads because footprints count + compressed and swapped pages: the owners 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 · 58% cpu` after the context %, for the selected pane. - Formatting (MB → `0.6G` / `512M`, CPU rounding, `null`) and the sort go in a pure `static/src/chrome/resources.js`, diff --git a/periscope/resources.py b/periscope/resources.py index 319e6a47..0bc6b24e 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -133,20 +133,24 @@ def footprint_mb(pid: int) -> int | None: return None if reading is None else reading.footprint >> 20 -def _sysctl(name: str, buf: ctypes.Structure | ctypes.c_int) -> None: +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, swap and free memory, straight from the kernel. mem_free_pct is the - figure `memory_pressure` prints.""" + """Load, RAM, swap and free memory, straight from the kernel. RAM is the + yardstick: footprints count compressed and swapped pages, so the owners 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, diff --git a/static/src/chrome/__tests__/resourcePillRender.test.jsx b/static/src/chrome/__tests__/resourcePillRender.test.jsx index 15f7c36b..77d46742 100644 --- a/static/src/chrome/__tests__/resourcePillRender.test.jsx +++ b/static/src/chrome/__tests__/resourcePillRender.test.jsx @@ -12,7 +12,7 @@ const R = { 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 }, + machine: { load1: 52.3, ram_mb: 16384, swap_used_mb: 16896, swap_total_mb: 17818, mem_free_pct: 27 }, }; afterEach(() => { @@ -38,7 +38,7 @@ describe("", () => { { pid: "b", name: "heavy", res: g(6963, 58) }, ]; const html = render(); - const order = [">periscope server<", ">webview<", ">heavy<", ">light<", ">elsewhere<", "load 52.3"]; + const order = [">periscope server<", ">webview<", ">heavy<", ">light<", ">elsewhere<", "16.0G RAM"]; 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); diff --git a/static/src/chrome/__tests__/resources.test.js b/static/src/chrome/__tests__/resources.test.js index 7ccbbfc3..4433e327 100644 --- a/static/src/chrome/__tests__/resources.test.js +++ b/static/src/chrome/__tests__/resources.test.js @@ -40,8 +40,8 @@ describe("paneLines", () => { }); 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"); + it("RAM first, so owners adding up past it read as overcommitment", () => { + expect(machineLine({ load1: 52.3, ram_mb: 16384, swap_used_mb: 16896, swap_total_mb: 17818, mem_free_pct: 27 })) + .toBe("16.0G RAM · swap 16.5G/17.4G · 27% free · load 52.3"); }); }); diff --git a/static/src/chrome/resources.js b/static/src/chrome/resources.js index a49a2b0e..ad6b934c 100644 --- a/static/src/chrome/resources.js +++ b/static/src/chrome/resources.js @@ -31,5 +31,5 @@ export function paneLines(windows) { } export function machineLine(m) { - return `load ${m.load1} · swap ${fmtMem(m.swap_used_mb)}/${fmtMem(m.swap_total_mb)} · ${m.mem_free_pct}% free`; + return `${fmtMem(m.ram_mb)} RAM · swap ${fmtMem(m.swap_used_mb)}/${fmtMem(m.swap_total_mb)} · ${m.mem_free_pct}% free · load ${m.load1}`; } diff --git a/tests/conftest.py b/tests/conftest.py index b92c2113..f17c23e1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -96,7 +96,7 @@ def _no_live_resources(monkeypatch): monkeypatch.setattr(resources, "_responsible", lambda pid: 0) monkeypatch.setattr(resources, "_name", lambda pid: "") monkeypatch.setattr( - resources, "machine", lambda: {"load1": 0.0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 100} + resources, "machine", lambda: {"load1": 0.0, "ram_mb": 0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 100} ) monkeypatch.setattr(resources, "_prev", {}) monkeypatch.setattr(resources, "_last", None) diff --git a/tests/test_resources.py b/tests/test_resources.py index 2e3195b3..6787cb73 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -28,7 +28,8 @@ def test_footprint_mb_of_this_process(): def test_machine_reads_the_kernel(): m = resources.machine() - assert set(m) == {"load1", "swap_used_mb", "swap_total_mb", "mem_free_pct"} + assert set(m) == {"load1", "ram_mb", "swap_used_mb", "swap_total_mb", "mem_free_pct"} + assert m["ram_mb"] > 1024 assert 0 <= m["swap_used_mb"] <= m["swap_total_mb"] assert 0 <= m["mem_free_pct"] <= 100 @@ -166,7 +167,7 @@ def _no_live_resources(monkeypatch): monkeypatch.setattr(resources, "_CORES", 1) -MACHINE = {"load1": 1.0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 50} +MACHINE = {"load1": 1.0, "ram_mb": 16384, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 50} MB = 1 << 20 From a380f2b0470d01e55b45bf1c4c26c40d31064664 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 08:27:53 -0400 Subject: [PATCH 27/52] build: static/dist with RAM on the machine line (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- static/dist/app.js | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/static/dist/app.js b/static/dist/app.js index fdff8320..7e45bd90 100644 --- a/static/dist/app.js +++ b/static/dist/app.js @@ -1,48 +1,48 @@ -var Ai,le,ic,lc,dt,es,ac,sc,rl,Fr,jn,oc,sa,Al,Ml,ri={},ii=[],ch=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Mi=Array.isArray;function et(e,t){for(var n in t)e[n]=t[n];return e}function oa(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function uh(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?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??++ic,__i:-1,__u:0};return l==null&&le.vnode!=null&&le.vnode(a),a}function K(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&&dt.sort(sc),e=dt.shift(),t=dt.length,dh(e)}finally{dt.length=li.__r=0}}function uc(e,t,n,i,l,a,s,o,u,c,f){var d,p,h,m,b,x,w,C=i&&i.__k||ii,y=t.length;for(u=hh(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+p,s.__=e,s.__b=e.__b+1,o=null,(c=s.__i=fh(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 ns(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||ch.test(t)?n:n+"px"}function $r(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||ns(e.style,t,"");if(n)for(t in n)i&&n[t]==i[t]||ns(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(oc,"$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]=sa,e.addEventListener(t,a?Ml:Al,a)):e.removeEventListener(t,a?Ml:Al,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 rs(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[Fr]==null)t[Fr]=sa++;else if(t[Fr]0?e:Mi(e)?e.map(fc):e.constructor!==void 0?null:et({},e)}function ph(e,t,n,i,l,a,s,o,u){var c,f,d,p,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 Xn=1,bh(yc,e)}function bh(e,t,n){var i=da(Zn++,2);if(i.t=e,!i.__c&&(i.__=[yc(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=da(Zn++,3);!ge.__s&&gc(n.__H,t)&&(n.__=e,n.u=t,pe.__H.__h.push(n))}function te(e){return Xn=5,gr(function(){return{current:e}},[])}function gr(e,t){var n=da(Zn++,7);return gc(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function yr(e,t){return Xn=8,gr(function(){return e},t)}function kh(){for(var e;e=mc.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Br),t.__h.some(Il),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){pe=null,ls&&ls(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),us&&us(e,t)},ge.__r=function(e){as&&as(e),Zn=0;var t=(pe=e.__c).__H;t&&(il===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(Il),t.__h=[],Zn=0)),il=pe},ge.diffed=function(e){ss&&ss(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(mc.push(t)!==1&&is===ge.requestAnimationFrame||((is=ge.requestAnimationFrame)||wh)(kh)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),il=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.__||Il(i)})}catch(i){t.some(function(l){l.__h&&(l.__h=[])}),t=[],ge.__e(i,n.__v)}}),os&&os(e,t)},ge.unmount=function(e){cs&&cs(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 ds=typeof requestAnimationFrame=="function";function wh(e){var t,n=function(){clearTimeout(i),ds&&cancelAnimationFrame(t),setTimeout(e)},i=setTimeout(n,35);ds&&(t=requestAnimationFrame(n))}function Br(e){var t=pe,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),pe=t}function Il(e){var t=pe;e.__c=e.__(),pe=t}function gc(e,t){return!e||e.length!==t.length||t.some(function(n,i){return n!==e[i]})}function yc(e,t){return typeof t=="function"?t(e):t}var vh=Symbol.for("preact-signals");function ha(){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}();qn!==void 0;){var n=qn;for(qn=void 0,ai++;n!==void 0;){var i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&kc(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 qn=void 0,Rt=0,ai=0,hs=0,si=void 0,oi=0;function bc(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=vh;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 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 Li(function(){return e.value})};Object.defineProperty(ve.prototype,"value",{get:function(){var e=bc(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!==hs&&(n.l=hs,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{ha()}}}});function H(e,t){return new ve(e,t)}function kc(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 wc(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 vc(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&&!kc(this))return this.f&=-2,!0;var e=se;try{wc(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,vc(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=bc(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 _c(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,fa(e),i}finally{se=n,ha()}}}function fa(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,_c(e)}function _h(e){if(se!==this)throw new Error("Out-of-order effect");vc(this),se=e,this.f&=-2,8&this.f&&fa(this),ha()}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,_c(this),wc(this),Rt++;var e=se;return se=this,_h.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||fa(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 Ii,Cr;function xn(e,t){le[e]=t.bind(null,le[e]||function(){})}function ci(e){if(Cr){var t=Cr;Cr=void 0,t()}Cr=e&&e.S()}function xc(e){var t=this,n=e.data,i=Sc(n);i.value=n;var l=gr(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(),lc(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}xc.displayName="_st";Object.defineProperties(ve.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:xc},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),ci();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}())),Ii=i,ci(n)});xn("__e",function(e,t,n,i){ci(),Ii=void 0,e(t,n,i)});xn("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],f=i[u];c===void 0?(c=xh(n,u,f,l),a[u]=c):c.o(f,l)}}}e(t)});function xh(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 Sc(e){return gr(function(){return H(e)},[])}function ll(e){var t=te(e);return t.current=e,Ii.__$f|=4,gr(function(){return Vt(function(){return t.current()})},[])}const ce=H([]),Oi=H([]),Di=H([]),Bt=H([]),gt=H(null),fs=H(""),Ol=H(null),er=H(null),Dl=H("all"),tr=H(null),ke=H(null),Et=H(null),Ri=H(null),pa=H(null),$c=H(null),at=H([]),ui=H({}),Un=H(null),Wn=H(null),Kn=H(null),Cc=H(null),ma=H([]),sn=H(null),Tc=H(""),Ec=H(0),ga=H(null),zr=H({}),Ft=H({}),Be=H({}),Re=H({}),ps=H(0);let Pc=0;function Sh(e){if(Date.now()-Pc<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)}Be.value=t,Re.value=n}function ya(e,t){Pc=Date.now(),fetch(`/api/pane/tabs/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}).catch(()=>{})}function br(e){const t=tr.value;if(!t)return;const n=(ce.value||[]).find(s=>s.target===t);if(!n)return;const i=n.pid,l=Be.value[i]||[],a=l.find(s=>s.path===e.path);a?e.line&&e.line!==a.line&&(Be.value={...Be.value,[i]:l.map(s=>s.path===e.path?{...s,line:e.line}:s)}):Be.value={...Be.value,[i]:[...l,{...e,target:t}]},Re.value={...Re.value,[i]:`file:${e.path}`},ya("open",{pid:i,path:e.path,line:e.line??null})}function Ac(e,t){const i=(Be.value[e]||[]).filter(l=>l.path!==t);Be.value={...Be.value,[e]:i},Re.value[e]===`file:${t}`&&(Re.value={...Re.value,[e]:"pane"}),ya("close",{pid:e,path:t})}function jr(e,t){Re.value={...Re.value,[e]:t},ya("activate",{pid:e,tab:t})}const nr=H(new Set),ft=H(new Set),pt=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 $h(e,t=at.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 Ch(e){e.key==="Escape"&&on.length&&(e.stopPropagation(),on[on.length-1](e))}typeof window<"u"&&window.addEventListener("keydown",Ch,!0);function Fe(e,t=!0){j(()=>{if(t)return on.push(e),()=>{const n=on.indexOf(e);n>=0&&on.splice(n,1)}},[e,t])}const Th={};function Eh(e,t){const n=Th,i=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,l=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Mc(e,i,l)}function Mc(e,t,n){if(Ph(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 ms(e.children,t,n)}return Array.isArray(e)?ms(e,t,n):""}function ms(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 ys={}.hasOwnProperty;function Lc(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 He(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Se=wt(/[A-Za-z]/),Ee=wt(/[\dA-Za-z]/),Lh=wt(/[#-'*+\--9=?A-Z^-~]/);function di(e){return e!==null&&(e<32||e===127)}const Rl=wt(/\d/),Ih=wt(/[\dA-Fa-f]/),Oh=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 Fi=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 Bh(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(Fi(e))return 2}function Ni(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};ks(d,-u),ks(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,Ni(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(ws,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 Yh(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 al={name:"codeIndented",tokenize:Xh},Zh={partial:!0,tokenize:ef};function Xh(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(Zh,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 ef(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 tf={name:"codeText",previous:rf,resolve:nf,tokenize:lf};function nf(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 Nc(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||di(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 zc(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 ff={name:"definition",tokenize:mf},pf={partial:!0,tokenize:gf};function mf(e,t,n){const i=this;let l;return a;function a(h){return e.enter("definition"),s(h)}function s(h){return Bc.call(i,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function o(h){return l=He(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 Nc(e,f,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function f(h){return e.attempt(pf,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 gf(e,t,n){return i;function i(o){return oe(o)?Vn(e,l)(o):n(o)}function l(o){return zc(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 yf={name:"hardBreakEscape",tokenize:bf};function bf(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 kf={name:"headingAtx",resolve:wf,tokenize:vf};function wf(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 vf(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 _f=["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"],_s=["pre","script","style","textarea"],xf={concrete:!0,name:"htmlFlow",resolveTo:Cf,tokenize:Tf},Sf={partial:!0,tokenize:Pf},$f={partial:!0,tokenize:Ef};function Cf(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 Tf(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):Se(_)?(e.consume(_),s=String.fromCharCode(_),x):n(_)}function p(_){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&&_s.includes(he)?(l=1,i.interrupt?t(_):F(_)):_f.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):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(Sf,Z,q)(_)):_===null||U(_)?(e.exit("htmlFlowData"),q(_)):(e.consume(_),F)}function q(_){return e.check($f,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 _s.includes(X)?(e.consume(_),W):F(_)}return Se(_)&&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 Ef(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 Pf(e,t,n){return i;function i(l){return e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),e.attempt(kr,t,n)}}const Af={name:"htmlText",tokenize:Mf};function Mf(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),A):n(k)}function c(k){return k===45?(e.consume(k),f):k===91?(e.consume(k),a=0,m):Se(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 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 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||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"),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 ka={name:"labelEnd",resolveAll:Df,resolveTo:Rf,tokenize:Ff},Lf={tokenize:Nf},If={tokenize:Bf},Of={tokenize:zf};function Df(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:Qf},exit:Zf,name:"list",tokenize:Jf},Vf={partial:!0,tokenize:Xf},Gf={partial:!0,tokenize:Yf};function Jf(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:Rl(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 Rl(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(kr,i.interrupt?n:f,e.attempt(Vf,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 Qf(e,t,n){const i=this;return i.containerState._closeFlow=void 0,e.check(kr,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(Gf,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 Yf(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 Zf(e){e.exit(this.containerState.type)}function Xf(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 xs={name:"setextUnderline",resolveTo:ep,tokenize:tp};function ep(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 tp(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 np={tokenize:rp};function rp(e){const t=this,n=e.attempt(kr,i,e.attempt(this.parser.constructs.flowInitial,l,re(e,e.attempt(this.parser.constructs.flow,l,e.attempt(of,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 ip={resolveAll:Hc()},lp=jc("string"),ap=jc("text");function jc(e){return{resolveAll:Hc(e==="text"?sp: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 wp(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??++ic,__i:-1,__u:0};return l==null&&le.vnode!=null&&le.vnode(a),a}function K(e){return e.children}function qn(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(sc),e=dt.shift(),t=dt.length,dh(e)}finally{dt.length=li.__r=0}}function uc(e,t,n,i,l,a,s,o,u,c,f){var d,p,h,m,b,x,w,C=i&&i.__k||ii,y=t.length;for(u=hh(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+p,s.__=e,s.__b=e.__b+1,o=null,(c=s.__i=fh(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 ns(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||ch.test(t)?n:n+"px"}function $r(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||ns(e.style,t,"");if(n)for(t in n)i&&n[t]==i[t]||ns(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(oc,"$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[Hn]=i[Hn]:(n[Hn]=sa,e.addEventListener(t,a?Ml:Al,a)):e.removeEventListener(t,a?Ml:Al,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 rs(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t[Fr]==null)t[Fr]=sa++;else if(t[Fr]0?e:Mi(e)?e.map(fc):e.constructor!==void 0?null:et({},e)}function ph(e,t,n,i,l,a,s,o,u){var c,f,d,p,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 er=1,bh(yc,e)}function bh(e,t,n){var i=da(Xn++,2);if(i.t=e,!i.__c&&(i.__=[yc(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=da(Xn++,3);!ge.__s&&gc(n.__H,t)&&(n.__=e,n.u=t,pe.__H.__h.push(n))}function te(e){return er=5,gr(function(){return{current:e}},[])}function gr(e,t){var n=da(Xn++,7);return gc(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function yr(e,t){return er=8,gr(function(){return e},t)}function kh(){for(var e;e=mc.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Br),t.__h.some(Il),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){pe=null,ls&&ls(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),us&&us(e,t)},ge.__r=function(e){as&&as(e),Xn=0;var t=(pe=e.__c).__H;t&&(il===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(Il),t.__h=[],Xn=0)),il=pe},ge.diffed=function(e){ss&&ss(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(mc.push(t)!==1&&is===ge.requestAnimationFrame||((is=ge.requestAnimationFrame)||wh)(kh)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),il=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.__||Il(i)})}catch(i){t.some(function(l){l.__h&&(l.__h=[])}),t=[],ge.__e(i,n.__v)}}),os&&os(e,t)},ge.unmount=function(e){cs&&cs(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 ds=typeof requestAnimationFrame=="function";function wh(e){var t,n=function(){clearTimeout(i),ds&&cancelAnimationFrame(t),setTimeout(e)},i=setTimeout(n,35);ds&&(t=requestAnimationFrame(n))}function Br(e){var t=pe,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),pe=t}function Il(e){var t=pe;e.__c=e.__(),pe=t}function gc(e,t){return!e||e.length!==t.length||t.some(function(n,i){return n!==e[i]})}function yc(e,t){return typeof t=="function"?t(e):t}var vh=Symbol.for("preact-signals");function ha(){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}();Un!==void 0;){var n=Un;for(Un=void 0,ai++;n!==void 0;){var i=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&kc(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 Un=void 0,Rt=0,ai=0,hs=0,si=void 0,oi=0;function bc(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=vh;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 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 Li(function(){return e.value})};Object.defineProperty(ve.prototype,"value",{get:function(){var e=bc(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!==hs&&(n.l=hs,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{ha()}}}});function H(e,t){return new ve(e,t)}function kc(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 wc(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 vc(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&&!kc(this))return this.f&=-2,!0;var e=se;try{wc(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,vc(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=bc(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 _c(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,fa(e),i}finally{se=n,ha()}}}function fa(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,_c(e)}function _h(e){if(se!==this)throw new Error("Out-of-order effect");vc(this),se=e,this.f&=-2,8&this.f&&fa(this),ha()}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,_c(this),wc(this),Rt++;var e=se;return se=this,_h.bind(this,e)};xn.prototype.N=function(){2&this.f||(this.f|=2,this.u=Un,Un=this)};xn.prototype.d=function(){this.f|=8,1&this.f||fa(this)};xn.prototype.dispose=function(){this.d()};function lt(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,Cr;function Sn(e,t){le[e]=t.bind(null,le[e]||function(){})}function ci(e){if(Cr){var t=Cr;Cr=void 0,t()}Cr=e&&e.S()}function xc(e){var t=this,n=e.data,i=Sc(n);i.value=n;var l=gr(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(),lc(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}xc.displayName="_st";Object.defineProperties(ve.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:xc},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 lt(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],f=i[u];c===void 0?(c=xh(n,u,f,l),a[u]=c):c.o(f,l)}}}e(t)});function xh(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))})}}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)});qn.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 Sc(e){return gr(function(){return H(e)},[])}function ll(e){var t=te(e);return t.current=e,Ii.__$f|=4,gr(function(){return Vt(function(){return t.current()})},[])}const ce=H([]),Oi=H([]),Di=H([]),Bt=H([]),gt=H(null),fs=H(""),Ol=H(null),tr=H(null),Dl=H("all"),nr=H(null),ke=H(null),Et=H(null),Ri=H(null),pa=H(null),$c=H(null),at=H([]),ui=H({}),Wn=H(null),Kn=H(null),Vn=H(null),Cc=H(null),ma=H([]),sn=H(null),Tc=H(""),Ec=H(0),ga=H(null),zr=H({}),Ft=H({}),Be=H({}),Re=H({}),ps=H(0);let Pc=0;function Sh(e){if(Date.now()-Pc<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)}Be.value=t,Re.value=n}function ya(e,t){Pc=Date.now(),fetch(`/api/pane/tabs/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}).catch(()=>{})}function br(e){const t=nr.value;if(!t)return;const n=(ce.value||[]).find(s=>s.target===t);if(!n)return;const i=n.pid,l=Be.value[i]||[],a=l.find(s=>s.path===e.path);a?e.line&&e.line!==a.line&&(Be.value={...Be.value,[i]:l.map(s=>s.path===e.path?{...s,line:e.line}:s)}):Be.value={...Be.value,[i]:[...l,{...e,target:t}]},Re.value={...Re.value,[i]:`file:${e.path}`},ya("open",{pid:i,path:e.path,line:e.line??null})}function Ac(e,t){const i=(Be.value[e]||[]).filter(l=>l.path!==t);Be.value={...Be.value,[e]:i},Re.value[e]===`file:${t}`&&(Re.value={...Re.value,[e]:"pane"}),ya("close",{pid:e,path:t})}function jr(e,t){Re.value={...Re.value,[e]:t},ya("activate",{pid:e,tab:t})}const rr=H(new Set),ft=H(new Set),pt=H(new Set);function yn(e,t=at.value){var n;return((n=t.find(i=>i.id===e))==null?void 0:n.label)||e}function $n(e=at.value){return e.length>1}function $h(e,t=at.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 Ch(e){e.key==="Escape"&&on.length&&(e.stopPropagation(),on[on.length-1](e))}typeof window<"u"&&window.addEventListener("keydown",Ch,!0);function Fe(e,t=!0){j(()=>{if(t)return on.push(e),()=>{const n=on.indexOf(e);n>=0&&on.splice(n,1)}},[e,t])}const Th={};function Eh(e,t){const n=Th,i=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,l=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Mc(e,i,l)}function Mc(e,t,n){if(Ph(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 ms(e.children,t,n)}return Array.isArray(e)?ms(e,t,n):""}function ms(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 ys={}.hasOwnProperty;function Lc(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 He(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Se=wt(/[A-Za-z]/),Ee=wt(/[\dA-Za-z]/),Lh=wt(/[#-'*+\--9=?A-Z^-~]/);function di(e){return e!==null&&(e<32||e===127)}const Rl=wt(/\d/),Ih=wt(/[\dA-Fa-f]/),Oh=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 Fi=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 Bh(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(Fi(e))return 2}function Ni(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};ks(d,-u),ks(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,Ni(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(ws,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 Yh(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 al={name:"codeIndented",tokenize:Xh},Zh={partial:!0,tokenize:ef};function Xh(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(Zh,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 ef(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 tf={name:"codeText",previous:rf,resolve:nf,tokenize:lf};function nf(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 Nc(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||di(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 zc(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 Gn(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 ff={name:"definition",tokenize:mf},pf={partial:!0,tokenize:gf};function mf(e,t,n){const i=this;let l;return a;function a(h){return e.enter("definition"),s(h)}function s(h){return Bc.call(i,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function o(h){return l=He(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)?Gn(e,c)(h):c(h)}function c(h){return Nc(e,f,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function f(h){return e.attempt(pf,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 gf(e,t,n){return i;function i(o){return oe(o)?Gn(e,l)(o):n(o)}function l(o){return zc(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 yf={name:"hardBreakEscape",tokenize:bf};function bf(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 kf={name:"headingAtx",resolve:wf,tokenize:vf};function wf(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 vf(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 _f=["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"],_s=["pre","script","style","textarea"],xf={concrete:!0,name:"htmlFlow",resolveTo:Cf,tokenize:Tf},Sf={partial:!0,tokenize:Pf},$f={partial:!0,tokenize:Ef};function Cf(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 Tf(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):Se(_)?(e.consume(_),s=String.fromCharCode(_),x):n(_)}function p(_){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&&_s.includes(he)?(l=1,i.interrupt?t(_):F(_)):_f.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):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(Sf,Z,q)(_)):_===null||U(_)?(e.exit("htmlFlowData"),q(_)):(e.consume(_),F)}function q(_){return e.check($f,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 _s.includes(X)?(e.consume(_),W):F(_)}return Se(_)&&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 Ef(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 Pf(e,t,n){return i;function i(l){return e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),e.attempt(kr,t,n)}}const Af={name:"htmlText",tokenize:Mf};function Mf(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),A):n(k)}function c(k){return k===45?(e.consume(k),f):k===91?(e.consume(k),a=0,m):Se(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 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 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||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"),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 ka={name:"labelEnd",resolveAll:Df,resolveTo:Rf,tokenize:Ff},Lf={tokenize:Nf},If={tokenize:Bf},Of={tokenize:zf};function Df(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:Qf},exit:Zf,name:"list",tokenize:Jf},Vf={partial:!0,tokenize:Xf},Gf={partial:!0,tokenize:Yf};function Jf(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:Rl(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 Rl(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(kr,i.interrupt?n:f,e.attempt(Vf,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 Qf(e,t,n){const i=this;return i.containerState._closeFlow=void 0,e.check(kr,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(Gf,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 Yf(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 Zf(e){e.exit(this.containerState.type)}function Xf(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 xs={name:"setextUnderline",resolveTo:ep,tokenize:tp};function ep(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 tp(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 np={tokenize:rp};function rp(e){const t=this,n=e.attempt(kr,i,e.attempt(this.parser.constructs.flowInitial,l,re(e,e.attempt(this.parser.constructs.flow,l,e.attempt(of,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 ip={resolveAll:Hc()},lp=jc("string"),ap=jc("text");function jc(e){return{resolveAll:Hc(e==="text"?sp: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 wp(e,t){let n=-1;const i=[];let l;for(;++n0){const Ne=J.tokenStack[J.tokenStack.length-1];(Ne[1]||Ts).call(J,void 0,Ne[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 p;function p(){let h=Kc,m,b,x;if(a(u,c,f[f.length-1]||void 0)&&(h=Np(n(u,f)),h[0]===Ps))return h;if("children"in u&&u.children){const w=u;if(w.children&&h[0]!==Rp)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=Es(e,"(");let a=Es(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 Vc(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||zt(n)||Fi(n))&&(!t||n!==47)}function em(){this.buffer()}function tm(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function nm(){this.buffer()}function rm(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function im(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=He(this.sliceSerialize(e)).toLowerCase(),n.label=t}function lm(e){this.exit(e)}function am(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=He(this.sliceSerialize(e)).toLowerCase(),n.label=t}function sm(e){this.exit(e)}function om(){return{enter:{gfmFootnoteCallString:em,gfmFootnoteCall:tm,gfmFootnoteDefinitionLabelString:nm,gfmFootnoteDefinition:rm},exit:{gfmFootnoteCallString:im,gfmFootnoteCall:lm,gfmFootnoteDefinitionLabelString:am,gfmFootnoteDefinition:sm}}}function cm(){return{canContainEols:["delete"],enter:{strikethrough:um},exit:{strikethrough:dm}}}function um(e){this.enter({type:"delete",children:[]},e)}function dm(e){this.exit(e)}function hm(){return{enter:{table:fm,tableData:As,tableHeader:As,tableRow:mm},exit:{codeText:gm,table:pm,tableData:cl,tableHeader:cl,tableRow:cl}}}function fm(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 pm(e){this.exit(e),this.data.inTable=void 0}function mm(e){this.enter({type:"tableRow",children:[]},e)}function cl(e){this.exit(e)}function As(e){this.enter({type:"tableCell",children:[]},e)}function gm(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,ym));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function ym(e,t){return t==="|"?t:e}function bm(){return{exit:{taskListCheckValueChecked:Ms,taskListCheckValueUnchecked:Ms,paragraph:km}}}function Ms(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function km(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 Mm={tokenize:Bm,partial:!0};function Lm(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Rm,continuation:{tokenize:Fm},exit:Nm}},text:{91:{name:"gfmFootnoteCall",tokenize:Dm},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Im,resolveTo:Om}}}}function Im(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=He(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 Om(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 Dm(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(He(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 Rm(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=He(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 Fm(e,t,n){return e.check(kr,t,e.attempt(Mm,t,n))}function Nm(e){e.exit("gfmFootnoteDefinition")}function Bm(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 zm(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 jm{constructor(){this.map=[]}add(t,n,i){Hm(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 Hm(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 Km(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 jm;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 Ls(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 Vm={name:"tasklistCheck",tokenize:Jm};function Gm(){return{text:{91:Vm}}}function Jm(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:Qm},t,n)(u):n(u)}}function Qm(e,t,n){return re(e,i,"whitespace");function i(l){return l===null?n(l):t(l)}}function ru(e){return Lc([_m(),Lm(),zm(),Um(),Gm()])}const Ym={pr_title:"from the PR title",branch:"from the branch name"};function wr(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=Ym[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 Zm=/^([a-z-]+): (.+)$/;function zl(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=Zm.exec(a.trim());if(!s)return null;i.push([s[1],s[2].trim()])}return i.length?i:null}function iu(e){return e.split(",").map(t=>t.trim().replace(/^`+|`+$/g,""))}const Xm=/^([\w.-]*[\w-]\/[\w./-]*[\w-]|[\w-]+(?:\.[\w-]+)*\.[A-Za-z][A-Za-z0-9]{1,5})(?::(\d+)(?:-(\d+))?)?$/;function zi(e){const t=Xm.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 eg(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?zi(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 tg=new Set(["new-subsystem","extension","reuse","system-touch","behavior"]);function ng(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 rg(e){var f,d,p;const t=String(e||""),i=Uc(t,{extensions:[ru()],mdastExtensions:[Gc()]}).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=Ur(i[c]),c++;const h=((d=i[c])==null?void 0:d.type)==="blockquote"?zl(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=Ur(i[c]),c++)}for(;cn.kind==="ctx"||n.kind==="add").length;return e.new_start+Math.max(t,1)-1}function lg(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&&ig(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 Is(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 ji={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 ag(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 sg=(e,t)=>typeof e=="string"?e.localeCompare(t):e-t;function og(e,t=null){const n=[...e||[]].sort((a,s)=>{var o,u;return Is(a)-Is(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&&ji[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*sg(o,u))})}function cg(e,t){const n=ji[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 ug(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=wr(i))==null?void 0:u.id,i.linked_linear_title].filter(Boolean).join(" ").toLowerCase();return n.every(c=>l.includes(c))}):e||[]}function Os(e){return(e||[]).filter(t=>!fi(t)).reduce((t,n)=>t+(n.unresolved||0),0)}const dg={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(dg).map(([e,t])=>({id:e,name:t.name,sprite:t}))];function lu(e){return pi.find(t=>t.id===e)||pi[0]}const au=10,_a=12,hg=19,fg=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 xa(e,{x0:t,sitting:n,height:i=_a}){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?fg:hg)-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 pg=.75,ul=(e,t=pg)=>({fill:"none",stroke:e,"stroke-width":t,"stroke-linecap":"square"});function mg(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 gg=new Set(["happy","x","down"]);function yg(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:ul(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 kg(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 wg(e){const{cx:t,top:n,w:i}=e.anchors.hat;return`translate(${t} ${n}) scale(${N(i/12)}) translate(-9 -9)`}function vg(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 Ds(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 Sa={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 Hi(e,t){const n=yn(e),{reach:i,at:l}=Sa[t];return[N(e.limb.root[0]+i),N(n.y+l*n.h)]}function _g(e,t,{scale:n,tx:i,ty:l}){const[a,s]=Hi(e,t);return[N(i+n*a),N(l+n*s)]}function Rs({scale:e,tx:t,ty:n},[i,l]){return[N((i-t)/e),N((l-n)/e)]}function jl(e,t,n=Hi(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 $a(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}]:[]:$a(i.g,t||!!i.arms,l)})}function xg(e){return $a(e.root).length===0}function Sg(e){const t=$a(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:jl(e,null,[N(e.limb.root[0]+1.6),N(n.y+.12*n.h)])}]}const su="#ff3b2f",$g="#f3f5f8";function Cg(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:$g,"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"}],ou={ui:"hanken",code:"plex-mono"};function cu(e,t){return mi.find(n=>n.id===e)||mi.find(n=>n.id===ou[t])}const Ye=H([]);let Tg=1;function bn(e,t="info",n=4e3){const i=Tg++;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 Eg(){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 dl(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(()=>dl(!1),5e3),addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&dl(!0)}),addEventListener("pagehide",()=>dl(!0)));const Hl={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 _e(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 Pg(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 Ag(e){return e?{"approve askuserquestion":"needs answer","permission prompt":"needs approval","dialog open":"needs input"}[e.toLowerCase()]||e.toLowerCase():"needs input"}function uu(e){if(!e)return null;const t=e.toLowerCase();return t==="permission prompt"?"permission":t==="approve askuserquestion"?"question":"dialog"}function du(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 hu(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`,l=e.gb==null?`Claude has been running ${i}`:`Claude is using ${e.gb}GB after ${i}`;return{label:e.trigger==="mem"?`${e.gb}G`:`${t}d`,title:`${l} — consider exiting and resuming this session`,cls:`mem-${e.tier}`}}function rr(e,t){return e?`https://github.com/${e}/pull/${t}`:null}function qi(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 Mg(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 Ui(){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 Ng(),me.value}catch{return me.value={...me.value,loaded:!1},null}}function Wr(){return G().commands||[]}async function Lg({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 Ig(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 Og(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 Dg(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 Ui(),!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 Rg(e){me.value={...G(),ui:e}}function Er(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 Ui(),!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 fu(e){if(!e)return[];const t=G().windows[e];return[...(t==null?void 0:t.pinned_files)||[]]}function Fg(e,t){if(!e||!t)return Promise.resolve(!1);const n=fu(e),i=n.includes(t)?n.filter(l=>l!==t):[...n,t];return Kr(e,{pinned_files:i})}async function Ng(){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 Bg(e,t){return $e({track_order:e},t)}function ir(){return{...(G().ui||{}).tabs_by_track||{}}}function zg(e){return $e({tabs_by_track:e})}function Ca(){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 pu(e,t){const n=lr();return n[e]=t,$e({rail_collapsed:n})}function jg(){var e;return((e=G().ui)==null?void 0:e.last_selected)||null}function yt(e){return $e({last_selected:e})}function Hg(){var e;return((e=G().ui)==null?void 0:e.launch_profile)||"default"}function qg(e){return $e({launch_profile:e})}function mu(){var e;return lu((e=G().ui)==null?void 0:e.tama_critter).id}function Ug(e){return $e({tama_critter:e})}function ar(e){var t;return cu((t=G().ui)==null?void 0:t[`${e}_font`],e)}function Wg(e,t){return $e({[`${e}_font`]:t})}const Kg={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{...Kg,...((e=G().ui)==null?void 0:e.notify)||{}}}function Vg(e,t){return $e({notify:{...yi(),[e]:t}})}function Ta(){var e;return[...((e=G().ui)==null?void 0:e.pinned_pids)||[]]}function Gg(e){return $e({pinned_pids:e})}function Jg(e){const t=Ta(),n=t.includes(e)?t.filter(i=>i!==e):[...t,e];return Gg(n)}function Qg(e){var t;return((t=G().ui)==null?void 0:t[e])??null}function Fs(e,t){return $e({[e]:t})}function Ea(e){var t;return!!((t=G().ui)!=null&&t[`${e}_hidden`])}function Yg(e,t){return $e({[`${e}_hidden`]:t})}function gu(e){var t,n;return((n=(t=G().ui)==null?void 0:t.detail_mode_by_pid)==null?void 0:n[e])||null}function ql(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 Pa(){const e=G().ui||{};return{merged:e.clawd_merged,furious:e.clawd_furious}}async function yu(e,t){var n;return G().loaded||await Ui(),!G().loaded||((n=Pa()[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 Aa(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 Zg(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 bu({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 Xg(e){if(Ve())try{await Aa("periscope:notification-clicked",e)}catch(t){console.warn("[tauri] notification-click listener failed:",t)}}async function e1(e){if(Ve())try{await Aa("periscope:notification-opened",e)}catch(t){console.warn("[tauri] notification-opened listener failed:",t)}}async function t1(e){if(Ve())try{await Aa("periscope:notification-action",e)}catch(t){console.warn("[tauri] notification-action listener failed:",t)}}async function n1(e){if(Ve())try{await $n("plugin:event|emit",{event:"periscope:notify-categories",payload:e})}catch(t){console.warn("[tauri] setNotifyCategories failed:",t)}}function Wi(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 r1(){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 i1(e){return!!(e!=null&&e.asked_question)&&!(e!=null&&e.waiting_for)}function Ns(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 Ma(e,t,n,i=new Set){const l=Ia(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=>!La(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 ku(e,t,n,i=new Set){const l=Ia(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=>!La(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 La(e,t){const n=t[e.target];return n?Math.max(n.focused_at||0,n.acted_at||0)>e.ts:!1}function l1(e){return e.length}const a1=600,s1=3600;function wu(e,t){const n=(t||0)-(e||0);return n>=s1?"urgent":n>=a1?"stale":"fresh"}function vu(e,t,n=new Set){var a;const i=Ia(e),l=new Map;for(const s of t||[]){if(s.kind!=="need_human"||n.has(s.id)||La(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=vu(e,t,n),o=new Map;for(const f of Ma(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 xu(e){return(e||[]).filter(t=>t.state==="working").map(t=>({kind:"live",pid:t.pid,w:t}))}function o1(e,t){const n={};for(const i of t||[])n[i.pid]=i;return(e||[]).map(i=>n[i]).filter(Boolean)}function c1(e){return(e||[]).filter(t=>t.kind==="done"||t.kind==="info")}function Ia(e){const t={};for(const n of e||[])t[n.target]=n;return t}const Oa=er;let Bs=!1;function jt(e){e&&st((ce.value||[]).find(t=>t.target===e))}function st(e){e!=null&&e.pid&&(ke.value=`pane:${e.pid}`,yt({kind:"pane",pid:e.pid}))}function Su(e){i1(e)&&(ft.value=new Set([...ft.value,e.pid])),st(e)}function $u(e){e!=null&&e.pid&&(pt.value=new Set([...pt.value,e.pid]))}function Cu(e){$u(e),st(e)}function u1(){Bs||(Bs=!0,Xg(e=>jt(e)))}function Tu(e,t){!e||!t||(ke.value=`review:${e}/${t.replace(/\//g,"--")}`,yt({kind:"review",repo:e,branch:t}))}function Da(){ke.value="reviews",yt({kind:"reviews"})}const hl=[{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 d1(){const[e,t]=B(!1),n=te(null),i=Dl.value,l=(hl.find(o=>o.key===i)||hl[0]).label,a=yr(()=>t(!1),[]);Fe(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){Dl.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:hl.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 Eu=Vt(()=>Ea("rail")),bi=Vt(()=>Ea("side"));function Ul(e){return Yg(e,!Ea(e))}function zs({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 h1(){const e=!Eu.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:()=>Ul("rail"),children:r(zs,{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:()=>Ul("side"),children:r(zs,{side:"right",shown:t})})]})}function sr(e){return e>=1024?`${(e/1024).toFixed(1)}G`:`${e}M`}function Pu(e){return e==null?"–":e<10?`${e.toFixed(1)}%`:`${Math.round(e)}%`}function f1(e){var t;return e.server.mem_mb+(((t=e.webview)==null?void 0:t.mem_mb)||0)+e.panes.mem_mb}function p1(e){return e.filter(t=>t.res).map(t=>({w:t,...t.res})).sort((t,n)=>n.mem_mb-t.mem_mb)}function m1(e){return`load ${e.load1} · swap ${sr(e.swap_used_mb)}/${sr(e.swap_total_mb)} · ${e.mem_free_pct}% free`}const g1="share of the whole machine's CPU: 100% is every core busy";function Pr({label:e,group:t,onClick:n}){const i=r(K,{children:[r("span",{class:"res-label",children:e}),r("span",{class:"res-mem",children:sr(t.mem_mb)}),r("span",{class:"res-cpu",title:g1,children:Pu(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 y1(){const e=te(null),[t,n]=B(!1),i=$c.value,l=yr(()=>n(!1),[]);return Fe(l,t),j(()=>{if(!t)return;function a(s){e.current&&!e.current.contains(s.target)&&l()}return document.addEventListener("click",a),()=>document.removeEventListener("click",a)},[t]),j(()=>{!i&&t&&l()},[i,t]),i?r("div",{class:"res-dd",ref:e,children:[r("button",{type:"button",class:"res-pill",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":t?"true":"false",onClick:()=>n(!t),children:["▣ ",sr(f1(i))]}),r("div",{class:"tb-dd-menu res-menu",role:"dialog",hidden:!t,children:[r(Pr,{label:"periscope server",group:i.server}),i.webview&&r(Pr,{label:"webview",group:i.webview}),p1(ce.value||[]).map(({w:a,mem_mb:s,cpu_pct:o})=>r(Pr,{label:_e(a),group:{mem_mb:s,cpu_pct:o},onClick:()=>{st(a),l()}},a.pid)),r(Pr,{label:"elsewhere",group:i.elsewhere}),r("div",{class:"res-machine",children:m1(i.machine)})]})]}):null}async function Au(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 b1(){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 vp(e){const i={constructs:Lc([yp,...(e||{}).extensions||[]]),content:l(Dh),defined:[],document:l(Fh),flow:l(np),lazy:{},string:l(lp),text:l(ap)};return i;function l(a){return s;function s(o){return bp(i,a,o)}}}function _p(e){for(;!Fc(e););return e}const Ss=/[\0\t\n\r]/g;function xp(){let e=1,t="",n=!0,i;return l;function l(a,s,o){const u=[];let c,f,d,p,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 Ne=J.tokenStack[J.tokenStack.length-1];(Ne[1]||Ts).call(J,void 0,Ne[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 p;function p(){let h=Kc,m,b,x;if(a(u,c,f[f.length-1]||void 0)&&(h=Np(n(u,f)),h[0]===Ps))return h;if("children"in u&&u.children){const w=u;if(w.children&&h[0]!==Rp)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=Es(e,"(");let a=Es(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 Vc(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||zt(n)||Fi(n))&&(!t||n!==47)}function em(){this.buffer()}function tm(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function nm(){this.buffer()}function rm(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function im(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=He(this.sliceSerialize(e)).toLowerCase(),n.label=t}function lm(e){this.exit(e)}function am(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=He(this.sliceSerialize(e)).toLowerCase(),n.label=t}function sm(e){this.exit(e)}function om(){return{enter:{gfmFootnoteCallString:em,gfmFootnoteCall:tm,gfmFootnoteDefinitionLabelString:nm,gfmFootnoteDefinition:rm},exit:{gfmFootnoteCallString:im,gfmFootnoteCall:lm,gfmFootnoteDefinitionLabelString:am,gfmFootnoteDefinition:sm}}}function cm(){return{canContainEols:["delete"],enter:{strikethrough:um},exit:{strikethrough:dm}}}function um(e){this.enter({type:"delete",children:[]},e)}function dm(e){this.exit(e)}function hm(){return{enter:{table:fm,tableData:As,tableHeader:As,tableRow:mm},exit:{codeText:gm,table:pm,tableData:cl,tableHeader:cl,tableRow:cl}}}function fm(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 pm(e){this.exit(e),this.data.inTable=void 0}function mm(e){this.enter({type:"tableRow",children:[]},e)}function cl(e){this.exit(e)}function As(e){this.enter({type:"tableCell",children:[]},e)}function gm(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,ym));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function ym(e,t){return t==="|"?t:e}function bm(){return{exit:{taskListCheckValueChecked:Ms,taskListCheckValueUnchecked:Ms,paragraph:km}}}function Ms(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function km(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 Mm={tokenize:Bm,partial:!0};function Lm(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Rm,continuation:{tokenize:Fm},exit:Nm}},text:{91:{name:"gfmFootnoteCall",tokenize:Dm},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Im,resolveTo:Om}}}}function Im(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=He(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 Om(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 Dm(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(He(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 Rm(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=He(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 Fm(e,t,n){return e.check(kr,t,e.attempt(Mm,t,n))}function Nm(e){e.exit("gfmFootnoteDefinition")}function Bm(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 zm(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 jm{constructor(){this.map=[]}add(t,n,i){Hm(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 Hm(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 Km(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 jm;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 Ls(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 Vm={name:"tasklistCheck",tokenize:Jm};function Gm(){return{text:{91:Vm}}}function Jm(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:Qm},t,n)(u):n(u)}}function Qm(e,t,n){return re(e,i,"whitespace");function i(l){return l===null?n(l):t(l)}}function ru(e){return Lc([_m(),Lm(),zm(),Um(),Gm()])}const Ym={pr_title:"from the PR title",branch:"from the branch name"};function wr(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=Ym[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 Zm=/^([a-z-]+): (.+)$/;function zl(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=Zm.exec(a.trim());if(!s)return null;i.push([s[1],s[2].trim()])}return i.length?i:null}function iu(e){return e.split(",").map(t=>t.trim().replace(/^`+|`+$/g,""))}const Xm=/^([\w.-]*[\w-]\/[\w./-]*[\w-]|[\w-]+(?:\.[\w-]+)*\.[A-Za-z][A-Za-z0-9]{1,5})(?::(\d+)(?:-(\d+))?)?$/;function zi(e){const t=Xm.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 eg(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?zi(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 tg=new Set(["new-subsystem","extension","reuse","system-touch","behavior"]);function ng(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 rg(e){var f,d,p;const t=String(e||""),i=Uc(t,{extensions:[ru()],mdastExtensions:[Gc()]}).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=Ur(i[c]),c++;const h=((d=i[c])==null?void 0:d.type)==="blockquote"?zl(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=Ur(i[c]),c++)}for(;cn.kind==="ctx"||n.kind==="add").length;return e.new_start+Math.max(t,1)-1}function lg(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&&ig(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 Is(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 ji={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 ag(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 sg=(e,t)=>typeof e=="string"?e.localeCompare(t):e-t;function og(e,t=null){const n=[...e||[]].sort((a,s)=>{var o,u;return Is(a)-Is(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&&ji[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*sg(o,u))})}function cg(e,t){const n=ji[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 ug(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=wr(i))==null?void 0:u.id,i.linked_linear_title].filter(Boolean).join(" ").toLowerCase();return n.every(c=>l.includes(c))}):e||[]}function Os(e){return(e||[]).filter(t=>!fi(t)).reduce((t,n)=>t+(n.unresolved||0),0)}const dg={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(dg).map(([e,t])=>({id:e,name:t.name,sprite:t}))];function lu(e){return pi.find(t=>t.id===e)||pi[0]}const au=10,_a=12,hg=19,fg=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,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 xa(e,{x0:t,sitting:n,height:i=_a}){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?fg:hg)-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 pg=.75,ul=(e,t=pg)=>({fill:"none",stroke:e,"stroke-width":t,"stroke-linecap":"square"});function mg(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 gg=new Set(["happy","x","down"]);function yg(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:ul(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 kg(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 wg(e){const{cx:t,top:n,w:i}=e.anchors.hat;return`translate(${t} ${n}) scale(${N(i/12)}) translate(-9 -9)`}function vg(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 Ds(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 Sa={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 Hi(e,t){const n=bn(e),{reach:i,at:l}=Sa[t];return[N(e.limb.root[0]+i),N(n.y+l*n.h)]}function _g(e,t,{scale:n,tx:i,ty:l}){const[a,s]=Hi(e,t);return[N(i+n*a),N(l+n*s)]}function Rs({scale:e,tx:t,ty:n},[i,l]){return[N((i-t)/e),N((l-n)/e)]}function jl(e,t,n=Hi(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 $a(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}]:[]:$a(i.g,t||!!i.arms,l)})}function xg(e){return $a(e.root).length===0}function Sg(e){const t=$a(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:jl(e,null,[N(e.limb.root[0]+1.6),N(n.y+.12*n.h)])}]}const su="#ff3b2f",$g="#f3f5f8";function Cg(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:$g,"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"}],ou={ui:"hanken",code:"plex-mono"};function cu(e,t){return mi.find(n=>n.id===e)||mi.find(n=>n.id===ou[t])}const Ye=H([]);let Tg=1;function kn(e,t="info",n=4e3){const i=Tg++;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 Eg(){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 dl(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(()=>dl(!1),5e3),addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&dl(!0)}),addEventListener("pagehide",()=>dl(!0)));const Hl={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 nt(e){const t=e.lastIndexOf(":"),n=e.slice(0,t),i=e.slice(t+1);return`session=${encodeURIComponent(n)}&index=${encodeURIComponent(i)}`}function Pg(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 Ag(e){return e?{"approve askuserquestion":"needs answer","permission prompt":"needs approval","dialog open":"needs input"}[e.toLowerCase()]||e.toLowerCase():"needs input"}function uu(e){if(!e)return null;const t=e.toLowerCase();return t==="permission prompt"?"permission":t==="approve askuserquestion"?"question":"dialog"}function du(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 hu(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`,l=e.gb==null?`Claude has been running ${i}`:`Claude is using ${e.gb}GB after ${i}`;return{label:e.trigger==="mem"?`${e.gb}G`:`${t}d`,title:`${l} — consider exiting and resuming this session`,cls:`mem-${e.tier}`}}function ir(e,t){return e?`https://github.com/${e}/pull/${t}`:null}function qi(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 Mg(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 Ui(){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 Ng(),me.value}catch{return me.value={...me.value,loaded:!1},null}}function Wr(){return G().commands||[]}async function Lg({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 Ig(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 Og(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 Dg(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 Ui(),!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 Rg(e){me.value={...G(),ui:e}}function Er(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 Ui(),!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 fu(e){if(!e)return[];const t=G().windows[e];return[...(t==null?void 0:t.pinned_files)||[]]}function Fg(e,t){if(!e||!t)return Promise.resolve(!1);const n=fu(e),i=n.includes(t)?n.filter(l=>l!==t):[...n,t];return Kr(e,{pinned_files:i})}async function Ng(){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 Bg(e,t){return $e({track_order:e},t)}function lr(){return{...(G().ui||{}).tabs_by_track||{}}}function zg(e){return $e({tabs_by_track:e})}function Ca(){var e;return{...((e=G().ui)==null?void 0:e.branch_order_by_track)||{}}}function ar(){var e;return{...((e=G().ui)==null?void 0:e.rail_collapsed)||{}}}function pu(e,t){const n=ar();return n[e]=t,$e({rail_collapsed:n})}function jg(){var e;return((e=G().ui)==null?void 0:e.last_selected)||null}function yt(e){return $e({last_selected:e})}function Hg(){var e;return((e=G().ui)==null?void 0:e.launch_profile)||"default"}function qg(e){return $e({launch_profile:e})}function mu(){var e;return lu((e=G().ui)==null?void 0:e.tama_critter).id}function Ug(e){return $e({tama_critter:e})}function sr(e){var t;return cu((t=G().ui)==null?void 0:t[`${e}_font`],e)}function Wg(e,t){return $e({[`${e}_font`]:t})}const Kg={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{...Kg,...((e=G().ui)==null?void 0:e.notify)||{}}}function Vg(e,t){return $e({notify:{...yi(),[e]:t}})}function Ta(){var e;return[...((e=G().ui)==null?void 0:e.pinned_pids)||[]]}function Gg(e){return $e({pinned_pids:e})}function Jg(e){const t=Ta(),n=t.includes(e)?t.filter(i=>i!==e):[...t,e];return Gg(n)}function Qg(e){var t;return((t=G().ui)==null?void 0:t[e])??null}function Fs(e,t){return $e({[e]:t})}function Ea(e){var t;return!!((t=G().ui)!=null&&t[`${e}_hidden`])}function Yg(e,t){return $e({[`${e}_hidden`]:t})}function gu(e){var t,n;return((n=(t=G().ui)==null?void 0:t.detail_mode_by_pid)==null?void 0:n[e])||null}function ql(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 Pa(){const e=G().ui||{};return{merged:e.clawd_merged,furious:e.clawd_furious}}async function yu(e,t){var n;return G().loaded||await Ui(),!G().loaded||((n=Pa()[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 Cn(e,t){return window.__TAURI_INTERNALS__.invoke(e,t||{})}async function Aa(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 Zg(e){if(Ve())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 bu({title:e,body:t,target:n="",...i}){if(Ve())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 Xg(e){if(Ve())try{await Aa("periscope:notification-clicked",e)}catch(t){console.warn("[tauri] notification-click listener failed:",t)}}async function e1(e){if(Ve())try{await Aa("periscope:notification-opened",e)}catch(t){console.warn("[tauri] notification-opened listener failed:",t)}}async function t1(e){if(Ve())try{await Aa("periscope:notification-action",e)}catch(t){console.warn("[tauri] notification-action listener failed:",t)}}async function n1(e){if(Ve())try{await Cn("plugin:event|emit",{event:"periscope:notify-categories",payload:e})}catch(t){console.warn("[tauri] setNotifyCategories failed:",t)}}function Wi(e){if(Ve())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 r1(){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(),Cn("plugin:opener|open_url",{url:n.href}).catch(i=>{console.warn("[tauri] open_url failed:",i)}))},!0)}function i1(e){return!!(e!=null&&e.asked_question)&&!(e!=null&&e.waiting_for)}function Ns(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 Ma(e,t,n,i=new Set){const l=Ia(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=>!La(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 ku(e,t,n,i=new Set){const l=Ia(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=>!La(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 La(e,t){const n=t[e.target];return n?Math.max(n.focused_at||0,n.acted_at||0)>e.ts:!1}function l1(e){return e.length}const a1=600,s1=3600;function wu(e,t){const n=(t||0)-(e||0);return n>=s1?"urgent":n>=a1?"stale":"fresh"}function vu(e,t,n=new Set){var a;const i=Ia(e),l=new Map;for(const s of t||[]){if(s.kind!=="need_human"||n.has(s.id)||La(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=vu(e,t,n),o=new Map;for(const f of Ma(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 xu(e){return(e||[]).filter(t=>t.state==="working").map(t=>({kind:"live",pid:t.pid,w:t}))}function o1(e,t){const n={};for(const i of t||[])n[i.pid]=i;return(e||[]).map(i=>n[i]).filter(Boolean)}function c1(e){return(e||[]).filter(t=>t.kind==="done"||t.kind==="info")}function Ia(e){const t={};for(const n of e||[])t[n.target]=n;return t}const Oa=tr;let Bs=!1;function jt(e){e&&st((ce.value||[]).find(t=>t.target===e))}function st(e){e!=null&&e.pid&&(ke.value=`pane:${e.pid}`,yt({kind:"pane",pid:e.pid}))}function Su(e){i1(e)&&(ft.value=new Set([...ft.value,e.pid])),st(e)}function $u(e){e!=null&&e.pid&&(pt.value=new Set([...pt.value,e.pid]))}function Cu(e){$u(e),st(e)}function u1(){Bs||(Bs=!0,Xg(e=>jt(e)))}function Tu(e,t){!e||!t||(ke.value=`review:${e}/${t.replace(/\//g,"--")}`,yt({kind:"review",repo:e,branch:t}))}function Da(){ke.value="reviews",yt({kind:"reviews"})}const hl=[{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 d1(){const[e,t]=B(!1),n=te(null),i=Dl.value,l=(hl.find(o=>o.key===i)||hl[0]).label,a=yr(()=>t(!1),[]);Fe(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){Dl.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:hl.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 Eu=Vt(()=>Ea("rail")),bi=Vt(()=>Ea("side"));function Ul(e){return Yg(e,!Ea(e))}function zs({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 h1(){const e=!Eu.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:()=>Ul("rail"),children:r(zs,{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:()=>Ul("side"),children:r(zs,{side:"right",shown:t})})]})}function cn(e){return e>=1024?`${(e/1024).toFixed(1)}G`:`${e}M`}function Pu(e){return e==null?"–":e<10?`${e.toFixed(1)}%`:`${Math.round(e)}%`}function f1(e){var t;return e.server.mem_mb+(((t=e.webview)==null?void 0:t.mem_mb)||0)+e.panes.mem_mb}function p1(e){return e.filter(t=>t.res).map(t=>({w:t,...t.res})).sort((t,n)=>n.mem_mb-t.mem_mb)}function m1(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 g1="share of the whole machine's CPU: 100% is every core busy";function Pr({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:g1,children:Pu(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 y1(){const e=te(null),[t,n]=B(!1),i=$c.value,l=yr(()=>n(!1),[]);return Fe(l,t),j(()=>{if(!t)return;function a(s){e.current&&!e.current.contains(s.target)&&l()}return document.addEventListener("click",a),()=>document.removeEventListener("click",a)},[t]),j(()=>{!i&&t&&l()},[i,t]),i?r("div",{class:"res-dd",ref:e,children:[r("button",{type:"button",class:"res-pill",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":t?"true":"false",onClick:()=>n(!t),children:["▣ ",cn(f1(i))]}),r("div",{class:"tb-dd-menu res-menu",role:"dialog",hidden:!t,children:[r(Pr,{label:"periscope server",group:i.server}),i.webview&&r(Pr,{label:"webview",group:i.webview}),p1(ce.value||[]).map(({w:a,mem_mb:s,cpu_pct:o})=>r(Pr,{label:_e(a),group:{mem_mb:s,cpu_pct:o},onClick:()=>{st(a),l()}},a.pid)),r(Pr,{label:"elsewhere",group:i.elsewhere}),r("div",{class:"res-machine",children:m1(i.machine)})]})]}):null}async function Au(e){const t=Wn.value;Wn.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||(Wn.value=t),!!n}function b1(){if(!$n())return null;const e=[{id:null,label:"auto"},...at.value],t=Wn.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:()=>Au(i.id),children:i.id===null&&t===null&&n?`auto → ${gn(n.account)}`:i.label},i.id??"auto"))]})}const Ra=["default","low","medium","high","xhigh","max"];async function k1(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 w1(){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:()=>Au(i.id),children:i.id===null&&t===null&&n?`auto → ${yn(n.account)}`:i.label},i.id??"auto"))]})}const Ra=["default","low","medium","high","xhigh","max"];async function k1(e){const t=Vn.value;Vn.value=e,await ie("spawn effort","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({spawn_effort:e})})||(Vn.value=t)}function w1(){const e=Vn.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"}),Ra.map(t=>r("button",{type:"button",class:`spawn-acct-btn${e===t?" is-active":""}`,onClick:()=>k1(t),children:t},t))]})}const or=[{id:"default",label:"default"},{id:"fable",label:"fable"},{id:"opus[1m]",label:"opus 1m"},{id:"sonnet",label:"sonnet"}],v1=[{id:"auto",label:"auto"},...or];async function _1(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 x1(){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"}),Ra.map(t=>r("button",{type:"button",class:`spawn-acct-btn${e===t?" is-active":""}`,onClick:()=>k1(t),children:t},t))]})}const or=[{id:"default",label:"default"},{id:"fable",label:"fable"},{id:"opus[1m]",label:"opus 1m"},{id:"sonnet",label:"sonnet"}],v1=[{id:"auto",label:"auto"},...or];async function _1(e){const t=Kn.value;Kn.value=e,await ie("spawn model","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({spawn_model:e})})||(Kn.value=t)}function x1(){const e=Kn.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"}),v1.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:()=>_1(n.id),children:n.id==="auto"&&e==="auto"&&t?`auto → ${t.model??"default"}`:n.label},n.id))]})}const Mu={cols:0,rows:0,shrunkFrom:0},S1=4,$1=(e,t)=>e>0&&t>0?Math.min(e,t):e||t;function C1(e,t){return t>0&&Math.abs(e-t)<=S1?t:e}function T1(e,t,n,i){return{cols:e||n,rows:$1(t,i)}}function E1(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 Lu(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 L1(){de&&de.readyState===WebSocket.OPEN&&de.send(JSON.stringify({type:"reconcile"}))}function I1(){if(!Y)return!0;const e=Y.buffer.active;return e.viewportY>=e.baseY}function Nu(e){Ze=e}let ur=null;function Hs(e){ur=e}const Bu=/\b(?:https?|wss?):\/\/[^\s)"'`<>]+/g,O1=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(Bu)){const h=p.index,m=h+p[0].length;if(s>=h&&s{if(n.button!==0)return;const i=R1(n,e);i&&(Qt={url:i,x:n.clientX,y:n.clientY})},Us=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;Wi(a)||e.writeln(`\r -\x1B[31m[periscope: failed to open ${a}]\x1B[0m`)},t.addEventListener("mousedown",qs,!0),t.addEventListener("mouseup",Us,!0))}function B1(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"&&ur&&ur(m))},hover(){},leave(){}})}}a(Bu,"url"),a(O1,"file"),a(D1,"file"),n(l)}})}function z1(){try{return localStorage.getItem("periscope.noWebgl")==="1"}catch{return!1}}function j1(){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 Ws(e){var n;if(!((n=document.fonts)!=null&&n.load))return;const t=`${Iu.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,vr())},()=>{})}function H1(){if(!Y){if(tt=document.createElement("div"),tt.className="xterm-host",en=ar("code"),Y=new Terminal({...Iu,fontFamily:en.stack,theme:P1,linkHandler:{allowNonHttpProtocols:!0,activate(e,t){if(t.startsWith("file://")){if(!e.metaKey&&!e.ctrlKey||!ur)return;let n=t.slice(7);n.startsWith("localhost/")&&(n=n.slice(9));try{n=decodeURIComponent(n)}catch{}ur(n);return}Wi(t)}}}),Y.open(tt),Ws(en),lt(()=>{const e=ar("code");e!==en&&(en=e,Y.options.fontFamily=e.stack,Ws(e))}),Y.attachCustomWheelEventHandler(e=>{if(!Fa||!e.deltaY)return!0;const t=F1(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*A1;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}),z1())console.warn("[periscope] WebGL renderer disabled via localStorage periscope.noWebgl");else try{Mt=new WebglAddon.WebglAddon,Mt.onContextLoss(()=>{j1()}),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)}B1(Y),N1(Y),cr=new FitAddon.FitAddon,Y.loadAddon(cr),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(()=>{Ze&&(Ze.classList.add("bell-pulse"),setTimeout(()=>Ze.classList.remove("bell-pulse"),400))})}}function q1(e){ye("terminal.open",{target:e});const t=Y!==null;if(H1(),Ze&&tt.parentElement!==Ze&&Ze.appendChild(tt),t){try{Y.reset()}catch{}Fa=!1,tn=0}if(Y.focus(),Fu(),za(),Lt)try{Lt.disconnect()}catch{}Lt=new ResizeObserver(vr),Ze&&Lt.observe(Ze),ki=e,wi=!1,Fn=0,Vr=!1,zu(e,ot.cols,ot.rows)}function zu(e,t=0,n=0){let l=`${location.protocol==="https:"?"wss":"ws"}://${location.host}/ws/pane?${Pg(e)}`;t>0&&n>0&&(l+=`&cols=${t}&rows=${n}`,cn=Lu(cn,{cols:t,rows:n}));const a=new WebSocket(l);a.binaryType="arraybuffer",de=a,a.onopen=()=>{Fn>0&&Y&&Y.writeln(`\r -\x1B[32m[periscope: reconnected]\x1B[0m`),Fn=0,Vr=!1},a.onmessage=s=>{if(typeof s.data=="string")try{const o=JSON.parse(s.data);o.type==="size"?(Ba=o.cols,Ki=o.rows,za(),vr()):o.type==="mouse"&&(Fa=!!o.on)}catch{Y.write(js(s.data,Wl))}else Y.write(js(new Uint8Array(s.data),Wl))},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(Fn,o.length-1)]||4e3;Fn+=1,At&&clearTimeout(At),At=setTimeout(()=>{At=null,!(!Y||ki!==e||wi)&&zu(e,ot.cols,ot.rows)},u)}}function vr(){It&&clearTimeout(It),It=setTimeout(()=>{if(It=null,!Y||!cr||Na||!Fu())return;za();const e=E1(ot,cn,Ki);e&&de&&de.readyState===WebSocket.OPEN&&(cn=Lu(cn,e),de.send(JSON.stringify({type:"resize",...e})))},80)}function U1(){if(wi=!0,ki=null,At&&(clearTimeout(At),At=null),cn=Mu,Ba=0,Ki=0,It&&(clearTimeout(It),It=null),Lt){try{Lt.disconnect()}catch{}Lt=null}if(de){try{de.close()}catch{}de=null}tt!=null&&tt.parentElement&&tt.remove()}function Ks(e){Y&&Y.writeln(e)}function vi(){if(Y)try{Y.scrollToBottom()}catch{}}function W1(){!Y||!cr||vr()}function K1(){Na=!0}function V1(){Na=!1,vr()}function Vs(e,t={}){return bt?bt.findNext(e,t):!1}function Gs(e,t={}){return bt?bt.findPrevious(e,t):!1}function G1(){bt&&bt.clearDecorations()}let Gn=null,Gr=null;function J1(e,t,n={}){ju(),Nu(e),Wl=n.agent||null,n.onPaste&&(Gn=n.onPaste,e.addEventListener("paste",Gn,!0)),Gr=e,q1(t),requestAnimationFrame(()=>requestAnimationFrame(()=>{W1(),vi()})),setTimeout(vi,300)}function ju(){U1(),Gr&&Gn&&Gr.removeEventListener("paste",Gn,!0),Gn=null,Gr=null,Nu(null)}function Hu(e){return typeof e!="string"?null:e.startsWith("pane:")?e.slice(5):null}function Q1(e,t){const n=Hu(e),i=n?t==null?void 0:t[n]:null;return typeof i=="string"&&i.startsWith("file:")?"document":"terminal"}function Y1(e){return(e.metaKey||e.ctrlKey)&&(e.key==="r"||e.key==="R")}function Z1(e){return e.repeat||!(e.metaKey||e.ctrlKey)||e.shiftKey||e.code!=="KeyB"?null:e.altKey?"side":"rail"}function X1(e=window){e.addEventListener("keydown",t=>{const n=Z1(t);if(n){t.preventDefault(),Ul(n);return}if(Y1(t)){if(t.preventDefault(),t.shiftKey){location.reload();return}if(Q1(ke.value,Re.value)==="document"){ps.value=ps.value+1;return}L1()}})}function Mr(e,t){if(!t||!e)return e;const n={...e};return e.fill&&(n.fill=Ds(e.fill,t)),e.stroke&&(n.stroke=Ds(e.stroke,t)),n}const Js=e=>e!=null&&e.stroke?{stroke:su,"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),...Js(e.a)}):r("rect",{class:e.cls,x:c,y:f,width:d,height:p,...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,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,...Js(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,...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,f)=>r(Oe,{n:c,mood:t,asleep:n,hide:i,tint:l,rest:a,paws:s,seated:o},f))})}function Vi({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=gg.has(i),b=u??(o&&Sa[o]?Hi(e,o):null),x=!!b||f&&xg(e),w=t==="furious"&&!n,C=v=>v.role!==void 0||(v.g||[]).some(C),y=p?mg(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&&bg(e,i).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`face-${E}`)),s&&vg(e,s).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`worn-${E}`)),l&&kg(e,!!b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`startle-${E}`)),h,b&&jl(e,o,b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`hold-${E}`)),f&&Sg(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`cheer-${E}`)),w&&r("g",{class:"tama-flush",fill:su,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&&jl(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&&Cg(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`teeth-${E}`))]},w?"furious":"calm")}function e0(e){return e==null?"":e>=80?" ctx-hot":e>=60?" ctx-warn":""}function Kl(e){return e.ctx_class&&e.ctx_class!=="none"?` ctx-${e.ctx_class}`:e0(e.context_pct)}const Qs=["bell","api","done","merged","ctx","ci","update"],qu=600;function Ys(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 ${_e(t)}`,...n});function t0({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=_u(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=ku(e,t,n,l).filter(g=>f(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"?Mn("ready",g.w):{action:"reveal",target:g.target,says:`open ${$}`}})}const C=s.filter(g=>u-g.atKl(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?`${_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: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,$)=>Qs.indexOf(g.kind)-Qs.indexOf($.kind))}function n0(e){return e.slice(1).reduce((t,n)=>t+n.count,0)}const r0=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function i0(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?r0[n.getDay()]:null,time:a}}function l0({day:e,time:t}){return`every account is at its limit until ${e?`${e} `:""}${t}`}const a0=new Set(["done","merged","ci","api","ctx"]);function Uu(e,t){const n=e==="code";return{atDesk:n,moodShown:n&&!t,showsPanes:n&&!a0.has(t)}}function s0({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 o0=600;function ja(e,t){return!!(e!=null&&e.fetched_at)&&t-e.fetched_at>o0}function Ha(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 Wu(e){return e!=null&&e.hot?"furious":Ha(e)?"grumpy":"calm"}const c0={session:"session",week_all:"week",week_opus:"opus",week_sonnet:"sonnet"};function qa(e){return c0[e]||e.replace(/^week_/,"")}const Ku=[{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"}],Vu=[{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,Zs=16,ze=.5,Ua=Ku.map(e=>{const t=e.id==="code"?{...e,id:"nap",label:"napping at the desk"}:e;return t.to===un?{...t,to:Zs}:t.from===un?{...t,from:Zs}:t}),Gu=e=>e.getDay()===0||e.getDay()===6,Gi=(e,t)=>e.find(n=>t>=n.from&&tGi(Gu(e)?Vu:Ua,un),Xs=[{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"]}],d0={run:"trick-or-treating",kids:"trick-or-treating with the kids"},h0=[{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"]}],f0=[{id:"pancakes",label:"pancakes"},{id:"waffles",label:"waffles"},{id:"eggs",label:"eggs and bacon"}],p0={id:"roast",label:"a roast"},eo={halloween:{id:"pie",label:"pumpkin pie"},summer:{id:"icecream",label:"ice cream"}},Ju=e=>t=>!t.seasons||t.seasons.includes(_r(e)),dn=e=>e.getHours()+e.getMinutes()/60;function Qu(e,t){let n=2166136261;for(const i of`${Ji(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=Qu(t,n)%e.length;for(;i.includes(e[l].id);)l=(l+1)%e.length;return e[l]}const m0=e=>Math.floor(e/6e4)*6e4,Wa=e=>(e.walls||[]).map(t=>t.map(m0)).filter(([t,n])=>tWa(t).some(([n,i])=>n<=e.getTime()&&e.getTime()Wa(e).map(t=>t.map(g0)).filter(([t,n])=>ti<=n&&n({...e,label:`having ${t.label} for ${n}`,dish:t.id});function y0(e,t){var u;if(e.meal==="brunch")return fl(e,Jr(f0,t,"brunch"),"brunch");const n=(u=Qi(t))==null?void 0:u.id,i=e.meal==="dinner"&&(eo[n]||eo[_r(t)]),l=e.from+ze;if(i&&dn(t)>=l)return{...fl(e,i,"dessert"),from:l};const a=h0.filter(Ju(t)),s=Jr(a,t,"lunch"),o=e.meal==="lunch"?s:n==="yearend"?p0:Jr(a,t,"dinner",[s.id]);return{...fl(e,o,e.meal),...i?{to:l}:{}}}function b0(e,t,n){var p;const i=h=>Xs.find(m=>m.id===h),l=(e.to-e.from)/ze,a=h=>(h-e.from)/ze,s=h=>e.from+h*ze,o=[un,un+ze].map(a),u=h=>!!Gi(Xu(dr(t,s(h)),n),s(h)).pastime,c=[],f=Xs.filter(Ju(t)),d=()=>{var m,b;const h=[];for(let x=0;x{const x=(h+b)%2?"kids":"run";c[m]={...i(x),label:d0[x],trick:!0}})}else{t.getDay()===5&&(c[a(un+ze)]=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 hr(e,t={}){const n=Gi(Xu(e,t),e.getHours());if(n.meal)return y0(n,e);if(n.pastime){const o=u0(e),u=Math.floor((dn(e)-o.from)/ze),c=o.from+u*ze;return{...o,...b0(o,e,t)[u],from:c,to:c+ze}}if(n.id!=="code"&&n.id!=="nap")return n;const i=e.getTime(),l=Zu(t).flat(),a=Math.max(dr(e,n.from).getTime(),...l.filter(o=>o<=i)),s=Math.min(dr(e,n.to).getTime(),...l.filter(o=>o>i));return{...n,from:dn(new Date(a)),to:dn(new Date(s))}}function ed(e,t={}){const n=e.getTime(),{to:i}=hr(e,t);return Math.min(dr(e,i).getTime(),...Wa(t).flat().filter(l=>l>n))-n}function k0(e,t={}){const n=hr(e,t);let i=e;for(let l=0;l<8;l++){i=new Date(i.getTime()+ed(i,t));const a=hr(i,t);if(a.id!==n.id||a.dish!==n.dish)return{at:i,activity:a}}return null}function to(e,t={}){var i;const n=hr(e,t);return`${n.from}|${n.id}|${n.dish||""}|${_r(e)}|${((i=Qi(e))==null?void 0:i.id)||""}|${ad(e)||""}|${Yu(e,t)}`}const _i=e=>String(e).padStart(2,"0");function Ji(e){return`${e.getFullYear()}-${_i(e.getMonth()+1)}-${_i(e.getDate())}`}function td(e){return`${Ji(e)}T${_i(e.getHours())}:${_i(e.getMinutes())}`}function nd(e,t){const n=Ji(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 w0={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]},v0=["spring","summer","autumn","winter"];function _0(e,t){const[n,i,l,a,s]=w0[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 rd(e){const t=e.getFullYear(),n=xi(e);return[t-1,t].flatMap(i=>v0.map(l=>({season:l,start:_0(l,i)}))).sort((i,l)=>i.start-l.start).filter(i=>xi(i.start)<=n).pop()}function _r(e){return rd(e).season}function id(e){return xi(rd(e).start)===xi(e)}const x0={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"},S0=[{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 ld(e){const t=(e.getMonth()+1)*100+e.getDate();return S0.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 Qi(e){return id(e)?null:ld(e)}function ad(e){var t;return id(e)?x0[_r(e)]:((t=ld(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 no(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 $0(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||ja(l,t)))for(const[a,s]of Object.entries(l.meters)){if(!s)continue;const o=Wu(s);wn[o].rank>wn[n.mood].rank&&(n={mood:o,account:i,meter:a,atLimit:(s.percent??0)>=100})}return n}function C0({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`${qa(t)} usage${l} ${a}`}function Vl(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 T0(e){return Vl(dn(e))}const V=9,Ht="#d97757",we="#2b1d16",Cn=["...############..","...############..",".################","...############.."],E0=[5,12],sd=["....#.#....#.#...",".....#.#..#.#...."];function qt(e){const t=[];return e.forEach((n,i)=>{for(let l=0;lt.key!==e)}function A0(){ro||(ro=!0,lt(()=>{const e=fr.peek(),t=s0({states:io,parties:e},ce.value,Date.now()/1e3);io=t.states,(t.parties.length!==e.length||t.parties.some((n,i)=>n.key!==e[i].key))&&(fr.value=t.parties),t.parties.some(n=>!e.some(i=>i.key===n.key))&&yu("merged",td(new Date))}))}const M0="modulepreload",L0=function(e){return"/"+e},lo={},Yi=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=L0(u),u in lo)return;lo[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":M0,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 Lr=null;function I0(){return Lr||(Lr=Yi(()=>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 O0=0;function D0({code:e}){const t=te(null),[n,i]=B(null);return j(()=>{let l=!0;return i(null),I0().then(a=>a.render(`md-mermaid-${++O0}`,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"}),v1.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:()=>_1(n.id),children:n.id==="auto"&&e==="auto"&&t?`auto → ${t.model??"default"}`:n.label},n.id))]})}const Mu={cols:0,rows:0,shrunkFrom:0},S1=4,$1=(e,t)=>e>0&&t>0?Math.min(e,t):e||t;function C1(e,t){return t>0&&Math.abs(e-t)<=S1?t:e}function T1(e,t,n,i){return{cols:e||n,rows:$1(t,i)}}function E1(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 Lu(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 L1(){de&&de.readyState===WebSocket.OPEN&&de.send(JSON.stringify({type:"reconcile"}))}function I1(){if(!Y)return!0;const e=Y.buffer.active;return e.viewportY>=e.baseY}function Nu(e){Ze=e}let ur=null;function Hs(e){ur=e}const Bu=/\b(?:https?|wss?):\/\/[^\s)"'`<>]+/g,O1=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(Bu)){const h=p.index,m=h+p[0].length;if(s>=h&&s{if(n.button!==0)return;const i=R1(n,e);i&&(Qt={url:i,x:n.clientX,y:n.clientY})},Us=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;Wi(a)||e.writeln(`\r +\x1B[31m[periscope: failed to open ${a}]\x1B[0m`)},t.addEventListener("mousedown",qs,!0),t.addEventListener("mouseup",Us,!0))}function B1(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"&&ur&&ur(m))},hover(){},leave(){}})}}a(Bu,"url"),a(O1,"file"),a(D1,"file"),n(l)}})}function z1(){try{return localStorage.getItem("periscope.noWebgl")==="1"}catch{return!1}}function j1(){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 Ws(e){var n;if(!((n=document.fonts)!=null&&n.load))return;const t=`${Iu.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,vr())},()=>{})}function H1(){if(!Y){if(tt=document.createElement("div"),tt.className="xterm-host",en=sr("code"),Y=new Terminal({...Iu,fontFamily:en.stack,theme:P1,linkHandler:{allowNonHttpProtocols:!0,activate(e,t){if(t.startsWith("file://")){if(!e.metaKey&&!e.ctrlKey||!ur)return;let n=t.slice(7);n.startsWith("localhost/")&&(n=n.slice(9));try{n=decodeURIComponent(n)}catch{}ur(n);return}Wi(t)}}}),Y.open(tt),Ws(en),lt(()=>{const e=sr("code");e!==en&&(en=e,Y.options.fontFamily=e.stack,Ws(e))}),Y.attachCustomWheelEventHandler(e=>{if(!Fa||!e.deltaY)return!0;const t=F1(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*A1;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}),z1())console.warn("[periscope] WebGL renderer disabled via localStorage periscope.noWebgl");else try{Mt=new WebglAddon.WebglAddon,Mt.onContextLoss(()=>{j1()}),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)}B1(Y),N1(Y),cr=new FitAddon.FitAddon,Y.loadAddon(cr),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(()=>{Ze&&(Ze.classList.add("bell-pulse"),setTimeout(()=>Ze.classList.remove("bell-pulse"),400))})}}function q1(e){ye("terminal.open",{target:e});const t=Y!==null;if(H1(),Ze&&tt.parentElement!==Ze&&Ze.appendChild(tt),t){try{Y.reset()}catch{}Fa=!1,tn=0}if(Y.focus(),Fu(),za(),Lt)try{Lt.disconnect()}catch{}Lt=new ResizeObserver(vr),Ze&&Lt.observe(Ze),ki=e,wi=!1,Nn=0,Vr=!1,zu(e,ot.cols,ot.rows)}function zu(e,t=0,n=0){let l=`${location.protocol==="https:"?"wss":"ws"}://${location.host}/ws/pane?${Pg(e)}`;t>0&&n>0&&(l+=`&cols=${t}&rows=${n}`,un=Lu(un,{cols:t,rows:n}));const a=new WebSocket(l);a.binaryType="arraybuffer",de=a,a.onopen=()=>{Nn>0&&Y&&Y.writeln(`\r +\x1B[32m[periscope: reconnected]\x1B[0m`),Nn=0,Vr=!1},a.onmessage=s=>{if(typeof s.data=="string")try{const o=JSON.parse(s.data);o.type==="size"?(Ba=o.cols,Ki=o.rows,za(),vr()):o.type==="mouse"&&(Fa=!!o.on)}catch{Y.write(js(s.data,Wl))}else Y.write(js(new Uint8Array(s.data),Wl))},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(Nn,o.length-1)]||4e3;Nn+=1,At&&clearTimeout(At),At=setTimeout(()=>{At=null,!(!Y||ki!==e||wi)&&zu(e,ot.cols,ot.rows)},u)}}function vr(){It&&clearTimeout(It),It=setTimeout(()=>{if(It=null,!Y||!cr||Na||!Fu())return;za();const e=E1(ot,un,Ki);e&&de&&de.readyState===WebSocket.OPEN&&(un=Lu(un,e),de.send(JSON.stringify({type:"resize",...e})))},80)}function U1(){if(wi=!0,ki=null,At&&(clearTimeout(At),At=null),un=Mu,Ba=0,Ki=0,It&&(clearTimeout(It),It=null),Lt){try{Lt.disconnect()}catch{}Lt=null}if(de){try{de.close()}catch{}de=null}tt!=null&&tt.parentElement&&tt.remove()}function Ks(e){Y&&Y.writeln(e)}function vi(){if(Y)try{Y.scrollToBottom()}catch{}}function W1(){!Y||!cr||vr()}function K1(){Na=!0}function V1(){Na=!1,vr()}function Vs(e,t={}){return bt?bt.findNext(e,t):!1}function Gs(e,t={}){return bt?bt.findPrevious(e,t):!1}function G1(){bt&&bt.clearDecorations()}let Jn=null,Gr=null;function J1(e,t,n={}){ju(),Nu(e),Wl=n.agent||null,n.onPaste&&(Jn=n.onPaste,e.addEventListener("paste",Jn,!0)),Gr=e,q1(t),requestAnimationFrame(()=>requestAnimationFrame(()=>{W1(),vi()})),setTimeout(vi,300)}function ju(){U1(),Gr&&Jn&&Gr.removeEventListener("paste",Jn,!0),Jn=null,Gr=null,Nu(null)}function Hu(e){return typeof e!="string"?null:e.startsWith("pane:")?e.slice(5):null}function Q1(e,t){const n=Hu(e),i=n?t==null?void 0:t[n]:null;return typeof i=="string"&&i.startsWith("file:")?"document":"terminal"}function Y1(e){return(e.metaKey||e.ctrlKey)&&(e.key==="r"||e.key==="R")}function Z1(e){return e.repeat||!(e.metaKey||e.ctrlKey)||e.shiftKey||e.code!=="KeyB"?null:e.altKey?"side":"rail"}function X1(e=window){e.addEventListener("keydown",t=>{const n=Z1(t);if(n){t.preventDefault(),Ul(n);return}if(Y1(t)){if(t.preventDefault(),t.shiftKey){location.reload();return}if(Q1(ke.value,Re.value)==="document"){ps.value=ps.value+1;return}L1()}})}function Mr(e,t){if(!t||!e)return e;const n={...e};return e.fill&&(n.fill=Ds(e.fill,t)),e.stroke&&(n.stroke=Ds(e.stroke,t)),n}const Js=e=>e!=null&&e.stroke?{stroke:su,"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),...Js(e.a)}):r("rect",{class:e.cls,x:c,y:f,width:d,height:p,...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,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,...Js(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,...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,f)=>r(Oe,{n:c,mood:t,asleep:n,hide:i,tint:l,rest:a,paws:s,seated:o},f))})}function Vi({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=gg.has(i),b=u??(o&&Sa[o]?Hi(e,o):null),x=!!b||f&&xg(e),w=t==="furious"&&!n,C=v=>v.role!==void 0||(v.g||[]).some(C),y=p?mg(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&&bg(e,i).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`face-${E}`)),s&&vg(e,s).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`worn-${E}`)),l&&kg(e,!!b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`startle-${E}`)),h,b&&jl(e,o,b).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`hold-${E}`)),f&&Sg(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`cheer-${E}`)),w&&r("g",{class:"tama-flush",fill:su,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&&jl(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&&Cg(e).map((v,E)=>r(Oe,{n:v,mood:t,tint:a},`teeth-${E}`))]},w?"furious":"calm")}function e0(e){return e==null?"":e>=80?" ctx-hot":e>=60?" ctx-warn":""}function Kl(e){return e.ctx_class&&e.ctx_class!=="none"?` ctx-${e.ctx_class}`:e0(e.context_pct)}const Qs=["bell","api","done","merged","ctx","ci","update"],qu=600;function Ys(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 Ln=(e,t,n={})=>({action:e,pid:t.pid,says:`open ${_e(t)}`,...n});function t0({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=_u(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 ${wn(m.length,"pane")}, not your code`,target:Ln("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:Ln("select",x[0].panes[0])});const w=ku(e,t,n,l).filter(g=>f(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"?Ln("ready",g.w):{action:"reveal",target:g.target,says:`open ${$}`}})}const C=s.filter(g=>u-g.atKl(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?`${_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:Ln("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,$)=>Qs.indexOf(g.kind)-Qs.indexOf($.kind))}function n0(e){return e.slice(1).reduce((t,n)=>t+n.count,0)}const r0=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function i0(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?r0[n.getDay()]:null,time:a}}function l0({day:e,time:t}){return`every account is at its limit until ${e?`${e} `:""}${t}`}const a0=new Set(["done","merged","ci","api","ctx"]);function Uu(e,t){const n=e==="code";return{atDesk:n,moodShown:n&&!t,showsPanes:n&&!a0.has(t)}}function s0({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 o0=600;function ja(e,t){return!!(e!=null&&e.fetched_at)&&t-e.fetched_at>o0}function Ha(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 Wu(e){return e!=null&&e.hot?"furious":Ha(e)?"grumpy":"calm"}const c0={session:"session",week_all:"week",week_opus:"opus",week_sonnet:"sonnet"};function qa(e){return c0[e]||e.replace(/^week_/,"")}const Ku=[{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"}],Vu=[{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,Zs=16,ze=.5,Ua=Ku.map(e=>{const t=e.id==="code"?{...e,id:"nap",label:"napping at the desk"}:e;return t.to===dn?{...t,to:Zs}:t.from===dn?{...t,from:Zs}:t}),Gu=e=>e.getDay()===0||e.getDay()===6,Gi=(e,t)=>e.find(n=>t>=n.from&&tGi(Gu(e)?Vu:Ua,dn),Xs=[{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"]}],d0={run:"trick-or-treating",kids:"trick-or-treating with the kids"},h0=[{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"]}],f0=[{id:"pancakes",label:"pancakes"},{id:"waffles",label:"waffles"},{id:"eggs",label:"eggs and bacon"}],p0={id:"roast",label:"a roast"},eo={halloween:{id:"pie",label:"pumpkin pie"},summer:{id:"icecream",label:"ice cream"}},Ju=e=>t=>!t.seasons||t.seasons.includes(_r(e)),hn=e=>e.getHours()+e.getMinutes()/60;function Qu(e,t){let n=2166136261;for(const i of`${Ji(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=Qu(t,n)%e.length;for(;i.includes(e[l].id);)l=(l+1)%e.length;return e[l]}const m0=e=>Math.floor(e/6e4)*6e4,Wa=e=>(e.walls||[]).map(t=>t.map(m0)).filter(([t,n])=>tWa(t).some(([n,i])=>n<=e.getTime()&&e.getTime()Wa(e).map(t=>t.map(g0)).filter(([t,n])=>ti<=n&&n({...e,label:`having ${t.label} for ${n}`,dish:t.id});function y0(e,t){var u;if(e.meal==="brunch")return fl(e,Jr(f0,t,"brunch"),"brunch");const n=(u=Qi(t))==null?void 0:u.id,i=e.meal==="dinner"&&(eo[n]||eo[_r(t)]),l=e.from+ze;if(i&&hn(t)>=l)return{...fl(e,i,"dessert"),from:l};const a=h0.filter(Ju(t)),s=Jr(a,t,"lunch"),o=e.meal==="lunch"?s:n==="yearend"?p0:Jr(a,t,"dinner",[s.id]);return{...fl(e,o,e.meal),...i?{to:l}:{}}}function b0(e,t,n){var p;const i=h=>Xs.find(m=>m.id===h),l=(e.to-e.from)/ze,a=h=>(h-e.from)/ze,s=h=>e.from+h*ze,o=[dn,dn+ze].map(a),u=h=>!!Gi(Xu(dr(t,s(h)),n),s(h)).pastime,c=[],f=Xs.filter(Ju(t)),d=()=>{var m,b;const h=[];for(let x=0;x{const x=(h+b)%2?"kids":"run";c[m]={...i(x),label:d0[x],trick:!0}})}else{t.getDay()===5&&(c[a(dn+ze)]=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 hr(e,t={}){const n=Gi(Xu(e,t),e.getHours());if(n.meal)return y0(n,e);if(n.pastime){const o=u0(e),u=Math.floor((hn(e)-o.from)/ze),c=o.from+u*ze;return{...o,...b0(o,e,t)[u],from:c,to:c+ze}}if(n.id!=="code"&&n.id!=="nap")return n;const i=e.getTime(),l=Zu(t).flat(),a=Math.max(dr(e,n.from).getTime(),...l.filter(o=>o<=i)),s=Math.min(dr(e,n.to).getTime(),...l.filter(o=>o>i));return{...n,from:hn(new Date(a)),to:hn(new Date(s))}}function ed(e,t={}){const n=e.getTime(),{to:i}=hr(e,t);return Math.min(dr(e,i).getTime(),...Wa(t).flat().filter(l=>l>n))-n}function k0(e,t={}){const n=hr(e,t);let i=e;for(let l=0;l<8;l++){i=new Date(i.getTime()+ed(i,t));const a=hr(i,t);if(a.id!==n.id||a.dish!==n.dish)return{at:i,activity:a}}return null}function to(e,t={}){var i;const n=hr(e,t);return`${n.from}|${n.id}|${n.dish||""}|${_r(e)}|${((i=Qi(e))==null?void 0:i.id)||""}|${ad(e)||""}|${Yu(e,t)}`}const _i=e=>String(e).padStart(2,"0");function Ji(e){return`${e.getFullYear()}-${_i(e.getMonth()+1)}-${_i(e.getDate())}`}function td(e){return`${Ji(e)}T${_i(e.getHours())}:${_i(e.getMinutes())}`}function nd(e,t){const n=Ji(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 w0={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]},v0=["spring","summer","autumn","winter"];function _0(e,t){const[n,i,l,a,s]=w0[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 rd(e){const t=e.getFullYear(),n=xi(e);return[t-1,t].flatMap(i=>v0.map(l=>({season:l,start:_0(l,i)}))).sort((i,l)=>i.start-l.start).filter(i=>xi(i.start)<=n).pop()}function _r(e){return rd(e).season}function id(e){return xi(rd(e).start)===xi(e)}const x0={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"},S0=[{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 ld(e){const t=(e.getMonth()+1)*100+e.getDate();return S0.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 Qi(e){return id(e)?null:ld(e)}function ad(e){var t;return id(e)?x0[_r(e)]:((t=ld(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 no(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 $0(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||ja(l,t)))for(const[a,s]of Object.entries(l.meters)){if(!s)continue;const o=Wu(s);vn[o].rank>vn[n.mood].rank&&(n={mood:o,account:i,meter:a,atLimit:(s.percent??0)>=100})}return n}function C0({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`${qa(t)} usage${l} ${a}`}function Vl(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 T0(e){return Vl(hn(e))}const V=9,Ht="#d97757",we="#2b1d16",Tn=["...############..","...############..",".################","...############.."],E0=[5,12],sd=["....#.#....#.#...",".....#.#..#.#...."];function qt(e){const t=[];return e.forEach((n,i)=>{for(let l=0;lt.key!==e)}function A0(){ro||(ro=!0,lt(()=>{const e=fr.peek(),t=s0({states:io,parties:e},ce.value,Date.now()/1e3);io=t.states,(t.parties.length!==e.length||t.parties.some((n,i)=>n.key!==e[i].key))&&(fr.value=t.parties),t.parties.some(n=>!e.some(i=>i.key===n.key))&&yu("merged",td(new Date))}))}const M0="modulepreload",L0=function(e){return"/"+e},lo={},Yi=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=L0(u),u in lo)return;lo[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":M0,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 Lr=null;function I0(){return Lr||(Lr=Yi(()=>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 O0=0;function D0({code:e}){const t=te(null),[n,i]=B(null);return j(()=>{let l=!0;return i(null),I0().then(a=>a.render(`md-mermaid-${++O0}`,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 od=/^([a-z][a-z0-9+.-]*:|\/|#)/i;function ao(e,t){return!t.resolveUrl||od.test(e)?e:t.resolveUrl(e)}function je(e,t){return(e||[]).map((n,i)=>R0(n,t,i))}function R0(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}eg(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?zi(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:je(e.children,t)},n);case"emphasis":return r("em",{children:je(e.children,t)},n);case"delete":return r("del",{children:je(e.children,t)},n);case"link":return r("a",{class:"md-link",href:ao(e.url,t),target:"_blank",rel:"noopener",children:je(e.children,{...t,cite:null})},n);case"image":return!od.test(e.url)&&!t.resolveUrl?e.alt||e.url:r("img",{class:"md-img",src:ao(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?je(e.children,t):e.value??null}}function F0(e,t,n){const i=(e.children||[]).map((l,a)=>l.type==="paragraph"&&!e.spread?je(l.children,t):Ka(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 N0(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?je(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?je(d.children,t):""},p))},f))})]},n)}function Ka(e,t,n,i){switch(e.type){case"paragraph":return r("p",{class:"md-p",children:je(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:je(e.children,t)},n)}case"code":return t.mermaid&&e.lang==="mermaid"?r(D0,{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"?zl(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?iu(s).map((u,c)=>{const f=zi(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)=>Ka(a,t,s))},n)}case"list":{const l=(e.children||[]).map((a,s)=>F0(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 N0(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:je(e.children,t)},n):e.value?r("p",{class:"md-p",children:e.value},n):null}}function pr(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=Uc(n,{extensions:[ru()],mdastExtensions:[Gc()]});return l.children.map((a,s)=>Ka(a,i,s,l.children[s-1]))}const B0=2e3,Qr=H(!1);let Gl=!1;function z0({focus:e=!1}={}){Gl=e,Qr.value=!0}const j0=12e4;function H0({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:pr(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 q0(){const[e,t]=B(!1),[n,i]=B(null),l=Qr.value,a=A=>{Qr.value=A},[s,o]=B(null),u=te(null),c=te(null),f=yr(()=>{Qr.value=!1},[]);Fe(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=pa.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),Gl&&(Gl=!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()+j0;for(;Date.now()setTimeout(S,B0));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(H0,{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 U0(e){const t=e.pid!=null&&(ce.value||[]).find(n=>String(n.pid)===String(e.pid))||null;if(e.action==="update")return z0({focus:!0});if(e.action==="needs")return Su(t);if(e.action==="ready")return Cu(t);if(e.action==="reveal")return jt(e.target);e.action==="party"&&P0(e.key),st(t)}const W0=250;function K0({target:e,pet:t,act:n=U0,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),W0);return}n(o)},onDblClick(){l(a),t()},dispose(){l(a)}}}const V0="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 so={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 G0({dish:e}){const t=so[e]?e:"ramen";return r("g",{"data-dish":t,"shape-rendering":V0,children:so[t]()})}const xe="geometricPrecision",oo=e=>[...e].reverse().join("");function rt({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 cd=[sd[0]],co={body:qt(Cn),legs:qt(cd)},uo={body:qt(Cn.map(oo)),legs:qt(cd.map(oo))};function J0({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 ho({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 Q0(){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(ho,{cx:7.2}),r(ho,{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 Y0({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 fo={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 ud({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(vn,{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 po({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 Z0(){return r("g",{class:"tama-amp","shape-rendering":xe,children:[r(po,{x:24.4,y:6,cls:"tama-note"}),r(po,{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,mo="#6f93d6",X0=150,mt=e=>Math.round(e*1e4)/1e4;function ey({sprite:e}){const{scale:t,tx:n,ty:i}=xa(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(Vi,{sprite:e,face:"happy",tint:X0,holding:"pint"}),r(dd,{sprite:e,kind:"pint",scale:t})]})}function dd({sprite:e,kind:t,scale:n}){if(!Sa[t])return null;const[i,l]=Hi(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(Va,{x:0,cls:"tama-pint tama-clink"})):t==="mug"?s("scale(-1 1) translate(-30.1 -14.2)",r(fd,{})):t==="can"?s("translate(-17.8 -11.7)",r(pd,{x0:0})):null}function Va({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 ty({x0:e}){return r(Va,{x:e+15.2,cls:"tama-pint tama-clink"})}const ny=[["#ffd166",15.4],["#f28ab2",19.6],["#7fb6e6",23.8],["#9be38f",28],["#ffd166",32.2]];function ry({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}),ny.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(ey,{sprite:e.sprite}):r(K,{children:[r(rt,{cells:uo.body,x0:Ct,fill:mo}),r(rt,{cells:uo.legs,x0:Ct,y0:V+2*Cn.length,fill:mo}),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(Va,{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 iy({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 ly({x:e,sprite:t,costume:n}){const{scale:i,tx:l,ty:a}=xa(t,{x0:e-4.25,sitting:!1,height:(n?au:_a)/2});return r("g",{class:"tama-critter",style:"transform-box: view-box",transform:`translate(${mt(l)} ${mt(a)}) scale(${mt(i)})`,children:r(Vi,{sprite:t})})}function go({x:e,cls:t,costume:n,sprite:i}){return r("g",{class:t,children:[i?r(ly,{x:e,sprite:i,costume:n}):r(K,{children:[r(rt,{cells:co.body,x0:e,y0:14,w:.5,h:1}),r(rt,{cells:co.legs,x0:e,y0:18,w:.5,h:1})]}),n?r(iy,{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 ay({trick:e=!1,critter:t}){return r("g",{children:[r(go,{x:17.4,cls:"tama-kid",costume:e,sprite:t==null?void 0:t.sprite}),r(go,{x:25.4,cls:"tama-kid tama-kid2",costume:e,sprite:t==null?void 0:t.sprite})]})}function sy(){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 oy={style:"arm",color:Ht};function hd({x0:e,limb:t=oy}){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(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 cy(){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 fd(){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 pd({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 uy(){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 md({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 dy({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 hy({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 fy(){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 py(){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 Ga({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 my(){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 Ja({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 gy={run:{tempo:.3,stride:!0,outdoors:!0,snowcap:!0,Behind:J0,trick:{pail:!0}},cycle:{pose:{x0:7,lift:2},tempo:.4,stride:!0,outdoors:!0,jack:{x:.6,y:16.4},Behind:Q0,Headwear:Y0},music:{pose:{x0:6},tempo:.5,jack:{x:1.5,y:16.4},Behind:Z0,Held:ud},beer:{pose:{x0:1},tempo:.9,smile:!0,Behind:ry,Held:ty},kids:{pose:{x0:1},tempo:.7,smile:!0,Behind:ay,trick:{outdoors:!0}},game:{pose:{x0:3,sitting:!0},tempo:1.2,Behind:sy,Held:hd,paws:!0},garden:{pose:{x0:2},tempo:.8,outdoors:!0,Behind:cy,Held:pd},cook:{pose:{x0:2},tempo:.6,Behind:uy,Held:md,Headwear:dy},dog:{pose:{x0:1},tempo:.5,stride:!0,smile:!0,outdoors:!0,Behind:hy},swim:{pose:{x0:6,sitting:!0},tempo:1,Behind:fy,Held:Ga,Front:py},sled:{pose:{x0:5,sitting:!0},tempo:.35,smile:!0,outdoors:!0,snowcap:!0,Behind:my,Held:Ja}},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 yy={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 by({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}),yy[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 yo({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 ky({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 wy({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":Ge,d:`M${l.map(([a,s])=>`${(e+a).toFixed(2)} ${(t+s).toFixed(2)}`).join(" L")} Z`})}function vy({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 _y({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 xy({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 gd=({d:e})=>r("g",{class:"tama-ding",fill:"none",stroke:"#f2c14e","stroke-width":"0.3","shape-rendering":Ge,children:r("path",{d:e})});function Sy(){return r("rect",{class:"tama-slap",x:"21.6",y:"8.7",width:"1.2",height:"0.9",fill:Ht})}const $y=[21.25,12.3],Cy=[22.2,9.6];function Ty({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 Ey({limb:e}){return r(vn,{limb:e,x:21.6,y:8.7,w:1.2,h:.9,cls:"tama-slap"})}function Py(){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(gd,{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 Ay(){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(gd,{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 My(){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 Ly(){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 Iy(){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 bo=({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 Oy(){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(bo,{x:24.6}),r(bo,{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 Dy(){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 Ry=Array.from({length:18},(e,t)=>[23.6+t*1.7%7.4,6.2+t*1.3%4.8]),Fy=Array.from({length:18},(e,t)=>[24.1+t*2.3%7.2,6.5+t*.9%4.8]);function Ny(){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(Ry)}),r("g",{class:"tama-static tama-static2",fill:"#5d6470",children:e(Fy)}),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 By(){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 zy({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 jy=["#52b4ea","#7fbf7f","#c792ea","#e6e9ef"],Hy=[.85,.55,.7,.4,.9,.6],qy={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 Uy({n:e}){const t=e===0?[]:qy[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)*Hy[c%6]).toFixed(2),height:"0.45",fill:jy[c%4]},c)}))]})}function Wy({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 Ky(){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 Vy({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 Gy(){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 Jy={code:{x0:3,sitting:!0},nap:{x0:3,sitting:!0},read:{x0:4,sitting:!0}},Qy={x0:8},yd=qt(Cn),Yy=qt(Cn.map((e,t)=>t===2?e.replace(/^.##/,"...").replace(/##$/,".."):e)),Jl=sd.map(e=>qt([e])),Ql=V+2*Cn.length;function Zy(){return r("g",{children:[r(rt,{cells:yd,cls:"tama-body",x0:0}),r(Yl,{x0:0}),r(rt,{cells:Jl[0],cls:"tama-legs-a",x0:0,y0:Ql})]})}const Xy=new Set([Ga,Ja]),e2={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 Yl({closed:e,x0:t}){return r("g",{class:e?"tama-eyes-closed":"tama-eyes",children:E0.map(n=>r("rect",{x:t+n,y:e?V+3.3:V+2,width:"1",height:e?.5:2,fill:we},n))})}const ko={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"}},t2=[[3,0],[11,-.7],[18,-1.6],[25.5,-.3],[32,-1.1]];function n2({season:e,night:t}){const n=ko[e]||ko.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:t2.map(([i,l])=>r("rect",{class:"tama-fall",x:i,y:"-1",width:"0.7",height:"0.7",style:{animationDelay:`${l}s`}},i))})]})}function r2({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 i2={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 l2(){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 a2(){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 bd({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 kd({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 s2({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:wg(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(bd,{x0:0}),n==="party"&&r(kd,{x0:0})]})}function o2({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 c2({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 u2=[[5,4,"#ffd166",0],[22,2.6,"#f28ab2",-.9]],d2=[[17.4,2.8,"#ffd166",0],[24.6,2.1,"#f28ab2",-.6],[31.2,3,"#7fb6e6",-1.2]];function h2({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?d2:u2).map(([n,i,l,a])=>t(n,i,l,a))})}const wo=["#ffd166","#f28ab2","#7fb6e6","#9be38f","#c792ea"];function f2(){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:wo[n%wo.length],style:{animationDelay:`${t}s`}},e))})}function p2({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 m2({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(fd,{})});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(p2,{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(a2,{}),t==="yearend"&&r(l2,{}),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(G0,{dish:o});default:return null}}function g2({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(n2,{season:t,night:n}),a]}):a}function y2({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 b2({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 k2({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 w2=new Set(["bell","done","merged","api","ctx"]);function v2({activity:e,view:t,kind:n,duty:i,working:l,walled:a,mirroring:s}){return e==="nap"?r(Wy,{...a}):t.atDesk?n==="done"?r(Ly,{}):n==="merged"?r(Iy,{}):n==="ci"?r(Oy,{}):n==="api"?r(Ny,{}):n==="ctx"?r(zy,{pct:i==null?void 0:i.pct,cost:i==null?void 0:i.cost}):s?r(Uy,{n:l}):null:null}function _2({kind:e}){return r("g",{children:[e==="bell"&&r(Py,{}),e==="ctx"&&r(By,{}),e==="update"&&r(Gy,{})]})}function x2({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=pi[0]}){var Me;const m=(o==null?void 0:o.kind)||null,b=Uu(e,m),{atDesk:x}=b,w=p,C=gy[e],y=C&&p?{...C,...C.trick}:C,{x0:g,sitting:$=!1,lift:v=0}=(y==null?void 0:y.pose)||Jy[e]||Qy,E=y?y.jack:i2[e],A=h.sprite,T=A&&xa(A,{x0:g,sitting:$,height:w?au:_a}),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||w2.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=v2({activity:e,view:b,kind:m,duty:o,working:u,walled:c,mirroring:k}),Z=w?r(o2,{x0:g}):A?null:z?r(b2,{x0:g,mood:l}):q?r(Yl,{closed:!0,x0:g}):O?r(yo,{x0:g}):I==="api"?r(ky,{x0:g}):I==="update"?r(Vy,{x0:g}):!I&&(y!=null&&y.smile)?r(yo,{x0:g}):r(Yl,{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)===Ga?"goggles":A&&(y==null?void 0:y.Held)===Ja?"scarf":null,he=A?e2[e]??null:null,fe=he==="spoon"||he==="leash"?_g(A,he,T):null,qe=he==="bass"?Rs(T,[g+fo.dx,fo.y]):null,Ae=A&&(z?$y:L?Cy:null),ue=qe??(Ae?Rs(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(h2,{clear:!!o}),y?r(g2,{p:y,season:t,trick:p,critter:h,from:fe}):r(m2,{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(r2,{...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(Vi,{sprite:A,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:qe&&r("g",{style:"transform-box: view-box",transform:`scale(${1/T.scale}) translate(${-T.tx} ${-T.ty})`,children:r(ud,{x0:g,limb:A.limb})})}),r(s2,{sprite:A,p:y,hat:M,season:t,ghost:w}),he&&r(dd,{sprite:A,kind:he,scale:T.scale})]}):r(rt,{cells:y!=null&&y.paws?Yy:yd,cls:"tama-body",x0:g}),Z,(y==null?void 0:y.Held)&&!(A&&(Xy.has(y.Held)||he))&&r(y.Held,{x0:g}),he==="spoon"&&r(md,{x0:g,from:fe}),he==="controller"&&r("g",{transform:`translate(0 ${Math.min(T.drop,.8)})`,children:r(hd,{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(vy,{x0:g})}),!A&&I==="ctx"&&r(wy,{x0:g}),!A&&x&&O&&r(xy,{x0:g}),x&&I==="ci"&&r(Dy,{}),!A&&L&&r(Sy,{}),A&&z&&r(Ty,{limb:A.limb}),A&&L&&r(Ey,{limb:A.limb}),!A&&r(Nn,{dy:S,children:I==="bell"&&!L&&r(_y,{x0:g})}),!A&&!$&&r(rt,{cells:Jl[0],cls:"tama-legs-a",x0:g,y0:Ql}),!A&&(y==null?void 0:y.stride)&&r(rt,{cells:Jl[1],cls:"tama-legs-b",x0:g,y0:Ql}),w&&(y==null?void 0:y.pail)&&r(c2,{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(bd,{x0:g}),M==="party"&&r(kd,{x0:g})]})]},s)}),(y==null?void 0:y.Front)&&r(y.Front,{}),r(y2,{activity:e}),(x||L)&&r(_2,{kind:m}),e==="nap"&&!F&&r(Ky,{}),F&&e==="sleep"&&r(Ay,{}),O&&r(My,{}),z&&r(k2,{mood:l,x0:g,coffee:i,hat:M,headDy:S}),(n==="newyear"||Q)&&r(f2,{}),o&&r(by,{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 S2=Vt(()=>lu(mu())),wd=e=>e.map(t=>[t.since*1e3,t.until==null?1/0:t.until*1e3]),vo=e=>({...nd(Pa(),e),walls:wd(ma.value)});function $2(){const[e,t]=B(()=>new Date),[n,i]=B(0),[l,a]=B(!1),o=ll(()=>{const O=Pa();return JSON.stringify([O.merged??null,O.furious??null,ma.value])}).value,[u,c,f]=JSON.parse(o),d={...nd({merged:u,furious:c},e),walls:wd(f)},p=te(o);j(()=>{if(p.current!==o){p.current=o,t(new Date);return}const O=setTimeout(()=>t(new Date),ed(e,d)+50);return()=>clearTimeout(O)},[e,o]),j(()=>{const O=setInterval(()=>{const Q=new Date;t(M=>to(Q,vo(Q))===to(M,vo(M))?M:Q)},6e4);return()=>clearInterval(O)},[]),j(()=>{if(!l)return;const O=setTimeout(()=>a(!1),900);return()=>clearTimeout(O)},[l,n]);const h=Sc(0);j(()=>{const O=setInterval(()=>{h.value+=1},6e4);return()=>clearInterval(O)},[]),j(()=>{A0()},[]);const m=S2.value,b=ll(()=>{var z;h.value;const O=(z=Ri.value)==null?void 0:z.plan,Q=$0(O,Date.now()/1e3),M=Q.account&&Sn()?gn(Q.account):null;return JSON.stringify([Q.mood,C0(Q,M)])}),[x,w]=JSON.parse(b.value);j(()=>{x==="furious"&&yu("furious",td(new Date))},[x,Ji(e)]);const C=ll(()=>{h.value;const O=Date.now()/1e3,Q=t0({windows:ce.value||[],alerts:er.value||[],dismissedAlertIds:nr.value,dismissedNeedsPids:ft.value,dismissedReadyPids:pt.value,selectedPid:Hu(ke.value),parties:fr.value,update:pa.value,nowSec:O}),M=Cc.value;return JSON.stringify({items:Q,more:n0(Q),wall:M&&i0(M.until,O),working:er.value===null?null:xu(ce.value).length})}),y=JSON.parse(C.value),g=y.items[0]||null,$=hr(e,d),v=k0(e,d),E=Qi(e),A=ad(e),T=Uu($.id,g==null?void 0:g.kind),S=no($,T.moodShown?x:"calm"),R=[...y.wall&&Yu(e,d)?[l0(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 ${T0(v.at)}: ${no(v.activity)}`]:[]],F=`${m.sprite?m.name:"Claude"} is ${S} (${Vl($.from)}–${Vl($.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(()=>K0({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(x2,{activity:$.id,dish:$.dish,trick:!!$.trick,season:_r(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 _o=["session","week_all","week_opus","week_sonnet"];function C2(e){const t=Object.keys(e).filter(n=>!_o.includes(n)).sort();return[..._o,...t].filter(n=>e[n]).map(n=>({key:n,label:qa(n),m:e[n]}))}function T2(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 E2(e,t){return e?T2(Object.keys(e)).map(n=>{const i=e[n]||{},l=i.available&&i.meters?C2(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&&ja(i,t),fetchedAt:i.fetched_at||null,meters:l,headline:s}}):[]}function P2(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&&Ha(n.m))}}const A2=48*3600;function vd(e){return e==="week_fable"||e.startsWith("week_fable_")}function M2(e,t){const n=(e==null?void 0:e.available)&&e.meters||{},i=Object.keys(n).find(vd),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:Ha(e)}}function I2({a:e}){const{hot:t,blow:n}=P2(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(` +`)||"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:"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(H0,{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 U0(e){const t=e.pid!=null&&(ce.value||[]).find(n=>String(n.pid)===String(e.pid))||null;if(e.action==="update")return z0({focus:!0});if(e.action==="needs")return Su(t);if(e.action==="ready")return Cu(t);if(e.action==="reveal")return jt(e.target);e.action==="party"&&P0(e.key),st(t)}const W0=250;function K0({target:e,pet:t,act:n=U0,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),W0);return}n(o)},onDblClick(){l(a),t()},dispose(){l(a)}}}const V0="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 so={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 G0({dish:e}){const t=so[e]?e:"ramen";return r("g",{"data-dish":t,"shape-rendering":V0,children:so[t]()})}const xe="geometricPrecision",oo=e=>[...e].reverse().join("");function rt({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 cd=[sd[0]],co={body:qt(Tn),legs:qt(cd)},uo={body:qt(Tn.map(oo)),legs:qt(cd.map(oo))};function J0({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 ho({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 Q0(){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(ho,{cx:7.2}),r(ho,{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 Y0({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 fo={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 ud({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 po({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 Z0(){return r("g",{class:"tama-amp","shape-rendering":xe,children:[r(po,{x:24.4,y:6,cls:"tama-note"}),r(po,{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,mo="#6f93d6",X0=150,mt=e=>Math.round(e*1e4)/1e4;function ey({sprite:e}){const{scale:t,tx:n,ty:i}=xa(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(Vi,{sprite:e,face:"happy",tint:X0,holding:"pint"}),r(dd,{sprite:e,kind:"pint",scale:t})]})}function dd({sprite:e,kind:t,scale:n}){if(!Sa[t])return null;const[i,l]=Hi(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(Va,{x:0,cls:"tama-pint tama-clink"})):t==="mug"?s("scale(-1 1) translate(-30.1 -14.2)",r(fd,{})):t==="can"?s("translate(-17.8 -11.7)",r(pd,{x0:0})):null}function Va({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 ty({x0:e}){return r(Va,{x:e+15.2,cls:"tama-pint tama-clink"})}const ny=[["#ffd166",15.4],["#f28ab2",19.6],["#7fb6e6",23.8],["#9be38f",28],["#ffd166",32.2]];function ry({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}),ny.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(ey,{sprite:e.sprite}):r(K,{children:[r(rt,{cells:uo.body,x0:Ct,fill:mo}),r(rt,{cells:uo.legs,x0:Ct,y0:V+2*Tn.length,fill:mo}),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(Va,{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 iy({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 ly({x:e,sprite:t,costume:n}){const{scale:i,tx:l,ty:a}=xa(t,{x0:e-4.25,sitting:!1,height:(n?au:_a)/2});return r("g",{class:"tama-critter",style:"transform-box: view-box",transform:`translate(${mt(l)} ${mt(a)}) scale(${mt(i)})`,children:r(Vi,{sprite:t})})}function go({x:e,cls:t,costume:n,sprite:i}){return r("g",{class:t,children:[i?r(ly,{x:e,sprite:i,costume:n}):r(K,{children:[r(rt,{cells:co.body,x0:e,y0:14,w:.5,h:1}),r(rt,{cells:co.legs,x0:e,y0:18,w:.5,h:1})]}),n?r(iy,{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 ay({trick:e=!1,critter:t}){return r("g",{children:[r(go,{x:17.4,cls:"tama-kid",costume:e,sprite:t==null?void 0:t.sprite}),r(go,{x:25.4,cls:"tama-kid tama-kid2",costume:e,sprite:t==null?void 0:t.sprite})]})}function sy(){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 oy={style:"arm",color:Ht};function hd({x0:e,limb:t=oy}){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 cy(){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 fd(){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 pd({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 uy(){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 md({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 dy({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 hy({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 fy(){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 py(){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 Ga({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 my(){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 Ja({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 gy={run:{tempo:.3,stride:!0,outdoors:!0,snowcap:!0,Behind:J0,trick:{pail:!0}},cycle:{pose:{x0:7,lift:2},tempo:.4,stride:!0,outdoors:!0,jack:{x:.6,y:16.4},Behind:Q0,Headwear:Y0},music:{pose:{x0:6},tempo:.5,jack:{x:1.5,y:16.4},Behind:Z0,Held:ud},beer:{pose:{x0:1},tempo:.9,smile:!0,Behind:ry,Held:ty},kids:{pose:{x0:1},tempo:.7,smile:!0,Behind:ay,trick:{outdoors:!0}},game:{pose:{x0:3,sitting:!0},tempo:1.2,Behind:sy,Held:hd,paws:!0},garden:{pose:{x0:2},tempo:.8,outdoors:!0,Behind:cy,Held:pd},cook:{pose:{x0:2},tempo:.6,Behind:uy,Held:md,Headwear:dy},dog:{pose:{x0:1},tempo:.5,stride:!0,smile:!0,outdoors:!0,Behind:hy},swim:{pose:{x0:6,sitting:!0},tempo:1,Behind:fy,Held:Ga,Front:py},sled:{pose:{x0:5,sitting:!0},tempo:.35,smile:!0,outdoors:!0,snowcap:!0,Behind:my,Held:Ja}},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 yy={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 by({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}),yy[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 yo({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 ky({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 wy({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":Ge,d:`M${l.map(([a,s])=>`${(e+a).toFixed(2)} ${(t+s).toFixed(2)}`).join(" L")} Z`})}function vy({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 _y({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 xy({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 gd=({d:e})=>r("g",{class:"tama-ding",fill:"none",stroke:"#f2c14e","stroke-width":"0.3","shape-rendering":Ge,children:r("path",{d:e})});function Sy(){return r("rect",{class:"tama-slap",x:"21.6",y:"8.7",width:"1.2",height:"0.9",fill:Ht})}const $y=[21.25,12.3],Cy=[22.2,9.6];function Ty({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 Ey({limb:e}){return r(_n,{limb:e,x:21.6,y:8.7,w:1.2,h:.9,cls:"tama-slap"})}function Py(){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(gd,{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 Ay(){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(gd,{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 My(){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 Ly(){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 Iy(){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 bo=({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 Oy(){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(bo,{x:24.6}),r(bo,{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 Dy(){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 Ry=Array.from({length:18},(e,t)=>[23.6+t*1.7%7.4,6.2+t*1.3%4.8]),Fy=Array.from({length:18},(e,t)=>[24.1+t*2.3%7.2,6.5+t*.9%4.8]);function Ny(){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(Ry)}),r("g",{class:"tama-static tama-static2",fill:"#5d6470",children:e(Fy)}),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 By(){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 zy({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 jy=["#52b4ea","#7fbf7f","#c792ea","#e6e9ef"],Hy=[.85,.55,.7,.4,.9,.6],qy={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 Uy({n:e}){const t=e===0?[]:qy[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)*Hy[c%6]).toFixed(2),height:"0.45",fill:jy[c%4]},c)}))]})}function Wy({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 Ky(){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 Vy({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 Gy(){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 Jy={code:{x0:3,sitting:!0},nap:{x0:3,sitting:!0},read:{x0:4,sitting:!0}},Qy={x0:8},yd=qt(Tn),Yy=qt(Tn.map((e,t)=>t===2?e.replace(/^.##/,"...").replace(/##$/,".."):e)),Jl=sd.map(e=>qt([e])),Ql=V+2*Tn.length;function Zy(){return r("g",{children:[r(rt,{cells:yd,cls:"tama-body",x0:0}),r(Yl,{x0:0}),r(rt,{cells:Jl[0],cls:"tama-legs-a",x0:0,y0:Ql})]})}const Xy=new Set([Ga,Ja]),e2={beer:"pint",coffee:"mug",cook:"spoon",garden:"can",dog:"leash",music:"bass",game:"controller"};function Bn({dy:e,children:t}){return e?r("g",{transform:`translate(0 ${e})`,children:t}):t}function Yl({closed:e,x0:t}){return r("g",{class:e?"tama-eyes-closed":"tama-eyes",children:E0.map(n=>r("rect",{x:t+n,y:e?V+3.3:V+2,width:"1",height:e?.5:2,fill:we},n))})}const ko={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"}},t2=[[3,0],[11,-.7],[18,-1.6],[25.5,-.3],[32,-1.1]];function n2({season:e,night:t}){const n=ko[e]||ko.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:t2.map(([i,l])=>r("rect",{class:"tama-fall",x:i,y:"-1",width:"0.7",height:"0.7",style:{animationDelay:`${l}s`}},i))})]})}function r2({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 i2={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 l2(){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 a2(){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 bd({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 kd({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 s2({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:wg(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(bd,{x0:0}),n==="party"&&r(kd,{x0:0})]})}function o2({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 c2({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 u2=[[5,4,"#ffd166",0],[22,2.6,"#f28ab2",-.9]],d2=[[17.4,2.8,"#ffd166",0],[24.6,2.1,"#f28ab2",-.6],[31.2,3,"#7fb6e6",-1.2]];function h2({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?d2:u2).map(([n,i,l,a])=>t(n,i,l,a))})}const wo=["#ffd166","#f28ab2","#7fb6e6","#9be38f","#c792ea"];function f2(){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:wo[n%wo.length],style:{animationDelay:`${t}s`}},e))})}function p2({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 m2({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(fd,{})});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(p2,{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(a2,{}),t==="yearend"&&r(l2,{}),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(G0,{dish:o});default:return null}}function g2({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(n2,{season:t,night:n}),a]}):a}function y2({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 b2({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 k2({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(Bn,{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 w2=new Set(["bell","done","merged","api","ctx"]);function v2({activity:e,view:t,kind:n,duty:i,working:l,walled:a,mirroring:s}){return e==="nap"?r(Wy,{...a}):t.atDesk?n==="done"?r(Ly,{}):n==="merged"?r(Iy,{}):n==="ci"?r(Oy,{}):n==="api"?r(Ny,{}):n==="ctx"?r(zy,{pct:i==null?void 0:i.pct,cost:i==null?void 0:i.cost}):s?r(Uy,{n:l}):null:null}function _2({kind:e}){return r("g",{children:[e==="bell"&&r(Py,{}),e==="ctx"&&r(By,{}),e==="update"&&r(Gy,{})]})}function x2({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=pi[0]}){var Me;const m=(o==null?void 0:o.kind)||null,b=Uu(e,m),{atDesk:x}=b,w=p,C=gy[e],y=C&&p?{...C,...C.trick}:C,{x0:g,sitting:$=!1,lift:v=0}=(y==null?void 0:y.pose)||Jy[e]||Qy,E=y?y.jack:i2[e],A=h.sprite,T=A&&xa(A,{x0:g,sitting:$,height:w?au:_a}),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||w2.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=vn[l])==null?void 0:Me.rank)>0,k=b.showsPanes&&u!=null&&!z,W=v2({activity:e,view:b,kind:m,duty:o,working:u,walled:c,mirroring:k}),Z=w?r(o2,{x0:g}):A?null:z?r(b2,{x0:g,mood:l}):q?r(Yl,{closed:!0,x0:g}):O?r(yo,{x0:g}):I==="api"?r(ky,{x0:g}):I==="update"?r(Vy,{x0:g}):!I&&(y!=null&&y.smile)?r(yo,{x0:g}):r(Yl,{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)===Ga?"goggles":A&&(y==null?void 0:y.Held)===Ja?"scarf":null,he=A?e2[e]??null:null,fe=he==="spoon"||he==="leash"?_g(A,he,T):null,qe=he==="bass"?Rs(T,[g+fo.dx,fo.y]):null,Ae=A&&(z?$y:L?Cy:null),ue=qe??(Ae?Rs(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(h2,{clear:!!o}),y?r(g2,{p:y,season:t,trick:p,critter:h,from:fe}):r(m2,{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(r2,{...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(Vi,{sprite:A,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:qe&&r("g",{style:"transform-box: view-box",transform:`scale(${1/T.scale}) translate(${-T.tx} ${-T.ty})`,children:r(ud,{x0:g,limb:A.limb})})}),r(s2,{sprite:A,p:y,hat:M,season:t,ghost:w}),he&&r(dd,{sprite:A,kind:he,scale:T.scale})]}):r(rt,{cells:y!=null&&y.paws?Yy:yd,cls:"tama-body",x0:g}),Z,(y==null?void 0:y.Held)&&!(A&&(Xy.has(y.Held)||he))&&r(y.Held,{x0:g}),he==="spoon"&&r(md,{x0:g,from:fe}),he==="controller"&&r("g",{transform:`translate(0 ${Math.min(T.drop,.8)})`,children:r(hd,{x0:g,limb:A.limb})}),!A&&r(Bn,{dy:S,children:(y==null?void 0:y.Headwear)&&!M&&r(y.Headwear,{x0:g})}),r(Bn,{dy:S,children:I==="api"&&r(vy,{x0:g})}),!A&&I==="ctx"&&r(wy,{x0:g}),!A&&x&&O&&r(xy,{x0:g}),x&&I==="ci"&&r(Dy,{}),!A&&L&&r(Sy,{}),A&&z&&r(Ty,{limb:A.limb}),A&&L&&r(Ey,{limb:A.limb}),!A&&r(Bn,{dy:S,children:I==="bell"&&!L&&r(_y,{x0:g})}),!A&&!$&&r(rt,{cells:Jl[0],cls:"tama-legs-a",x0:g,y0:Ql}),!A&&(y==null?void 0:y.stride)&&r(rt,{cells:Jl[1],cls:"tama-legs-b",x0:g,y0:Ql}),w&&(y==null?void 0:y.pail)&&r(c2,{x0:g}),!A&&r(Bn,{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(bd,{x0:g}),M==="party"&&r(kd,{x0:g})]})]},s)}),(y==null?void 0:y.Front)&&r(y.Front,{}),r(y2,{activity:e}),(x||L)&&r(_2,{kind:m}),e==="nap"&&!F&&r(Ky,{}),F&&e==="sleep"&&r(Ay,{}),O&&r(My,{}),z&&r(k2,{mood:l,x0:g,coffee:i,hat:M,headDy:S}),(n==="newyear"||Q)&&r(f2,{}),o&&r(by,{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 S2=Vt(()=>lu(mu())),wd=e=>e.map(t=>[t.since*1e3,t.until==null?1/0:t.until*1e3]),vo=e=>({...nd(Pa(),e),walls:wd(ma.value)});function $2(){const[e,t]=B(()=>new Date),[n,i]=B(0),[l,a]=B(!1),o=ll(()=>{const O=Pa();return JSON.stringify([O.merged??null,O.furious??null,ma.value])}).value,[u,c,f]=JSON.parse(o),d={...nd({merged:u,furious:c},e),walls:wd(f)},p=te(o);j(()=>{if(p.current!==o){p.current=o,t(new Date);return}const O=setTimeout(()=>t(new Date),ed(e,d)+50);return()=>clearTimeout(O)},[e,o]),j(()=>{const O=setInterval(()=>{const Q=new Date;t(M=>to(Q,vo(Q))===to(M,vo(M))?M:Q)},6e4);return()=>clearInterval(O)},[]),j(()=>{if(!l)return;const O=setTimeout(()=>a(!1),900);return()=>clearTimeout(O)},[l,n]);const h=Sc(0);j(()=>{const O=setInterval(()=>{h.value+=1},6e4);return()=>clearInterval(O)},[]),j(()=>{A0()},[]);const m=S2.value,b=ll(()=>{var z;h.value;const O=(z=Ri.value)==null?void 0:z.plan,Q=$0(O,Date.now()/1e3),M=Q.account&&$n()?yn(Q.account):null;return JSON.stringify([Q.mood,C0(Q,M)])}),[x,w]=JSON.parse(b.value);j(()=>{x==="furious"&&yu("furious",td(new Date))},[x,Ji(e)]);const C=ll(()=>{h.value;const O=Date.now()/1e3,Q=t0({windows:ce.value||[],alerts:tr.value||[],dismissedAlertIds:rr.value,dismissedNeedsPids:ft.value,dismissedReadyPids:pt.value,selectedPid:Hu(ke.value),parties:fr.value,update:pa.value,nowSec:O}),M=Cc.value;return JSON.stringify({items:Q,more:n0(Q),wall:M&&i0(M.until,O),working:tr.value===null?null:xu(ce.value).length})}),y=JSON.parse(C.value),g=y.items[0]||null,$=hr(e,d),v=k0(e,d),E=Qi(e),A=ad(e),T=Uu($.id,g==null?void 0:g.kind),S=no($,T.moodShown?x:"calm"),R=[...y.wall&&Yu(e,d)?[l0(y.wall)]:[],...y.items.map(O=>O.phrase),...T.showsPanes&&y.working?[`${wn(y.working,"agent")} working`]:[],...T.moodShown&&w?[w]:[],...A?[A]:[],...v?[`up next at ${T0(v.at)}: ${no(v.activity)}`]:[]],F=`${m.sprite?m.name:"Claude"} is ${S} (${Vl($.from)}–${Vl($.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(()=>K0({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(x2,{activity:$.id,dish:$.dish,trick:!!$.trick,season:_r(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 _o=["session","week_all","week_opus","week_sonnet"];function C2(e){const t=Object.keys(e).filter(n=>!_o.includes(n)).sort();return[..._o,...t].filter(n=>e[n]).map(n=>({key:n,label:qa(n),m:e[n]}))}function T2(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 E2(e,t){return e?T2(Object.keys(e)).map(n=>{const i=e[n]||{},l=i.available&&i.meters?C2(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&&ja(i,t),fetchedAt:i.fetched_at||null,meters:l,headline:s}}):[]}function P2(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&&Ha(n.m))}}const A2=48*3600;function vd(e){return e==="week_fable"||e.startsWith("week_fable_")}function M2(e,t){const n=(e==null?void 0:e.available)&&e.meters||{},i=Object.keys(n).find(vd),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:Ha(e)}}function I2({a:e}){const{hot:t,blow:n}=P2(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 O2({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=L2(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 Zl=H(!1);function $d(){Zl.value=!0}function D2(e,t,n,i){const l=e.meters.map(({m:a})=>[`${a.label}: ${a.percent}% used`,xd(a.resets_at),...Sd(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})=>vd(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 R2(){const e=Zl.value,t=Ri.value||{},n=t.fallback,i=Math.floor(Date.now()/1e3),l=E2(t.plan,i),a=Sn(),s=new Set(Object.keys(t.plan||{}).filter(c=>M2(t.plan[c],i)));if(l.some(c=>c.available))return r("div",{id:"usage",class:`usage${e?" is-expanded":""}`,onClick:()=>{Zl.value=!e},children:l.map(c=>{var f;return r("div",{class:`usage-acct${c.stale?" is-stale":""}`,title:D2(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(O2,{label:p,m:h,resets:xd(h.resets_at),pace:Sd(h)},d)):r("span",{class:"usage-acct-off",title:"no usable credential for this account",children:"no data"}),!e&&c.available&&r(I2,{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 R2(){const e=Zl.value,t=Ri.value||{},n=t.fallback,i=Math.floor(Date.now()/1e3),l=E2(t.plan,i),a=$n(),s=new Set(Object.keys(t.plan||{}).filter(c=>M2(t.plan[c],i)));if(l.some(c=>c.available))return r("div",{id:"usage",class:`usage${e?" is-expanded":""}`,onClick:()=>{Zl.value=!e},children:l.map(c=>{var f;return r("div",{class:`usage-acct${c.stale?" is-stale":""}`,title:D2(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(O2,{label:p,m:h,resets:xd(h.resets_at),pace:Sd(h)},d)):r("span",{class:"usage-acct-off",title:"no usable credential for this account",children:"no data"}),!e&&c.available&&r(I2,{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 ${pl(o)} active tokens - ${pl(n.cache_read_tokens)} cache reads (discounted)`;return r("div",{id:"usage",class:"usage usage-fallback",title:u,children:`5h: ${pl(o)} · ${_d(n.reset_at)}`})}function F2({id:e,toggleClass:t,toggleLabel:n,title:i,children:l}){const[a,s]=B(!1),o=te(null),u=yr(()=>s(!1),[]);return Fe(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 N2(){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 B2(){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":Sn()?3:2,children:[r("div",{class:"topbar",children:[r("span",{class:"brand",children:["periscope",r("i",{class:"brand-cursor"})]}),r(R2,{}),r(y1,{}),r("div",{class:"spawn-pins",children:[r(b1,{}),r(x1,{}),r(w1,{})]}),r(q0,{})]}),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(d1,{}),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:Da,children:["◉ reviews",Os(gt.value)?r("span",{class:"rail-review-badge",children:Os(gt.value)}):null]}),r(F2,{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(h1,{}),r("div",{class:"meta",children:r(N2,{})})]}),r($2,{})]})}const z2=3e3;let ml=null,Zr=!1,xo=!1,Bn=!1;function j2(){if(xo)return;xo=!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 H2(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=>gu(y)),f=e.mode||"terminal";if(!e.realClick)for(const y of s)ql(y,f);Bn=!!e.blockWs,Bn&&j2();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&&(br({path:p}),await h(t/3),jr(g,"pane"),await h(t/3)),y%5===0&&ye("memtest.progress",{nonce:e.nonce,i:y})}if(p)for(const y of s)Ac(y,p);if(Bn=!1,!e.realClick)for(const[y,g]of s.entries())ql(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:f}),Zr=!1}async function So(){try{const e=await fetch("/memtest.json",{cache:"no-store"});return e.ok?await e.json():null}catch{return null}}async function q2(){const e=await So();e!==null&&(ml=e.nonce??null,setInterval(async()=>{if(Zr)return;const t=await So();!t||t.nonce==null||t.nonce===ml||(ml=t.nonce,H2(t))},z2))}const hn=H([]);let U2=1;function W2(e){return new Promise(t=>{hn.value=[...hn.value,{...e,id:U2++,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 W2({type:"confirm",message:e,okLabel:t.okLabel||"OK",cancelLabel:t.cancelLabel||"Cancel",danger:!!t.danger})}function K2(e){return String(e??"").split(` -`).map((n,i)=>r(K,{children:[i>0?r("br",{}):null,n]}))}function V2({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;Fe(()=>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:K2(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 G2(){const e=hn.value;return r(K,{children:e.map(t=>r(V2,{req:t},t.id))})}async function mr(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 J2(e){return Array.isArray(e)?e.filter(Boolean):null}function Q2(e,t){return e===t?!0:!e||!t?!1:e.length===t.length&&e.every((n,i)=>n===t[i])}function Cd(e){const{paths:t}=e||{},n=J2(t);Q2(n,Nt.value)||(Nt.value=n),rn.value=!0,ye("overlay.open",{which:"cleanup",scoped:!!Nt.value})}function Y2(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 Z2(){Fe(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=te(0);j(()=>{const x=document.getElementById("cleanup-btn"),w=()=>Cd();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 mr("load candidates",Y2(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 mr("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 $o(){$i.value=!0,ye("overlay.open",{which:"commands"})}function gl(){$i.value=!1}function X2({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 Ig(e.label,{label:u,exec:c})}async function a(){await Og(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",$o),()=>{l&&l.removeEventListener("click",$o)}},[]);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),f=a?c:c+1;o.splice(f,0,s),Dg(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 Lg({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"&&gl()},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:gl,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(X2,{c:l,i:a,onDragState:t},l.label))}),r("button",{id:"commands-modal-add",class:"commands-modal-add",onClick:n,children:"+ add command"})]})})}const Td=[{id:"default",label:"default"},{id:"full",label:"full"}];function yl(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}function tb(e){return!e||e==="default"?null:e}function Co(e){var t;return((t=Td.find(n=>n.id===e))==null?void 0:t.label)||e}const To=["shell","idle","done","working","needs-input"];function Eo(e){let t=-1;for(const n of e){const i=To.indexOf(n);i>t&&(t=i)}return t>=0?To[t]:"shell"}const Ed="";function Qa(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||Ed;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 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 nb(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 rb(e){return String(e||"").replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ib(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 rb(e.cwd)}return null}function lb(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||Ed)===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(""),Xr=H("default"),ei=H("default"),ti=H("default"),ni=H("default");function ab(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}const Ti=H(null);function Pd(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 sb(e,t,n,i){const l=[],a=new Set;for(const o of Pd(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 ob(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 cb(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 ub(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 db=Vt(()=>sb(Ut.value,ce.value,Ya(Ut.value),Ti.value));function Ya(e){var t;return((t=(Bt.value||[]).find(n=>n.id===e))==null?void 0:t.repo)||null}function hb(e){var n,i;const t=Ya(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 Po(e){var n,i,l;Ut.value=e;const t=Pd(e,ce.value);Ue.value=t.length?t[0].branch:null,Xe.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=Hg(),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,Ue.value=null,Xe.value=null,Tt.value=""}function Ao(e){Ue.value=e,Xe.value=null}function fb(){Ue.value=null,Xe.value=""}function pb(){Fe(Or,Ut.value!=null),j(()=>(window.__periscopeOpenLauncher=Po,()=>{window.__periscopeOpenLauncher===Po&&delete window.__periscopeOpenLauncher}),[]);const e=Ut.value;if(e==null)return null;const t=Wr(),n=db.value,i=Ya(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),ab(p)&&h.set("account",Xr.value);const m=yl(p)?tb(ei.value):null;m&&h.set("profile",m),yl(p)&&h.set("model",ti.value),yl(p)&&h.set("effort",ni.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"}),Or()}const s=ub(t),o=s[0],u=Tt.value.trim(),c=u?cb(n,u).slice(0,24):ob(n,hb(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"&&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: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&&Ao(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:()=>Ao(p.branch),children:["⎇ ",p.branch]},p.branch)),Xe.value==null?r("button",{class:"launcher-branch launcher-branch-new",onClick:fb,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${Xr.value===p.id?" is-active":""}`,onClick:()=>{Xr.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:Td.map(p=>r("button",{class:`launcher-branch${ei.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:()=>{ei.value=p.id,qg(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:or.map(p=>r("button",{class:`launcher-branch${ti.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:()=>{ti.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:Ra.map(p=>r("button",{class:`launcher-branch${ni.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:()=>{ni.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 mb=/github\.com\/([^/]+\/[^/]+)\/pull\/(\d+)/,gb=/^#?(\d+)$/;function yb(e){const t=e.match(mb);if(t)return{repo:t[1],pr:Number(t[2])};const n=e.trim().match(gb);return n?{repo:null,pr:Number(n[1])}:null}const bb=/^(~|\.{0,2}\/)/;function kb(e){const t=(e||"").trim();return!t||!bb.test(t)?null:t.replace(/\/+$/,"")||"/"}function Yt(e,t){return e.toLowerCase().includes(t.toLowerCase())}function wb(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=kb(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=yb(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 Mo(){ht.value=!0,ye("overlay.open",{which:"open"})}function St(){ht.value=!1}const Lo={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:"◉"}},vb=3e3;function _b(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,vb))};return a(),()=>{i=!1,l&&clearTimeout(l)}},[e]),t}function xb(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 Sb(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 $b(){Fe(St,ht.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=Mo;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===Mo&&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(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}Rg(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"){Da(),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=wb(n,e).map($=>({...$,group:Lo[$.kind].group,icon:Lo[$.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(Zi,{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(Cb,{selectedJob:u,onSelect:c,onBack:u?()=>c(null):()=>{o(!1),i("")},onClose:St}),l&&l.card.kind==="worktree"&&r(Eb,{card:l.card,onPick:$=>x({repo:l.card.repo,branch:$}),onBack:()=>a(null)}),l&&l.card.kind==="track"&&r(Pb,{card:l.card,onPick:$=>w(l.card.repo,$),onBack:()=>a(null)}),l&&l.card.kind==="pr"&&r(Ab,{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 Cb({selectedJob:e,onSelect:t,onBack:n}){const i=_b(!e);return Fe(n,!0),e?r(Tb,{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 Tb({jobId:e,onBack:t}){const{messages:n,pending:i}=xb(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:Sb(l)},l.uuid||a))]})]})}function Zi({value:e,onInput:t,placeholder:n,items:i,onPick:l,onBack:a,empty:s}){const[o,u]=B(0),c=te(null),f=te(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(K,{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(K,{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 Eb({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(Zi,{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 Pb({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(Zi,{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 Ab({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(Zi,{value:i,onInput:l,placeholder:"repo for this PR…",items:s,onPick:o=>t(o.value),onBack:n,empty:"no matching repo"})}function Io({which:e,label:t,fonts:n}){return r("label",{children:[t,r("select",{name:`font-${e}`,value:ar(e).id,onChange:i=>Wg(e,i.currentTarget.value),children:n.map(i=>r("option",{value:i.id,children:i.name},i.id))})]})}function Mb(){return r("fieldset",{class:"font-picker",children:[r("legend",{children:"Fonts"}),r(Io,{which:"ui",label:"Interface",fonts:mi}),r(Io,{which:"code",label:"Code & terminal",fonts:mi.filter(e=>e.mono)})]})}const Lb=[["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 Ib(){const e=yi();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."}),Lb.map(([t,n])=>r("label",{class:"notify-option",children:[r("input",{type:"checkbox",name:`notify-${t}`,checked:e[t],onChange:i=>Vg(t,i.currentTarget.checked)}),n]},t))]})}function Ob({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(Vi,{sprite:e.sprite}):r(Zy,{})})}function Db(){const e=mu();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:()=>Ug(t.id)}),r(Ob,{critter:t}),r("span",{children:t.name})]},t.id))})]})}const ln=H(!1);function Oo(){ln.value=!0,ye("overlay.open",{which:"settings"})}function On(){ln.value=!1}function Rb(){Fe(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",Oo),()=>{w&&w.removeEventListener("click",Oo)}},[]),j(()=>{ln.value&&(t(""),(async()=>{const{data:w,error:C}=await mr("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(` + ${pl(n.cache_read_tokens)} cache reads (discounted)`;return r("div",{id:"usage",class:"usage usage-fallback",title:u,children:`5h: ${pl(o)} · ${_d(n.reset_at)}`})}function F2({id:e,toggleClass:t,toggleLabel:n,title:i,children:l}){const[a,s]=B(!1),o=te(null),u=yr(()=>s(!1),[]);return Fe(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 N2(){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 B2(){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(R2,{}),r(y1,{}),r("div",{class:"spawn-pins",children:[r(b1,{}),r(x1,{}),r(w1,{})]}),r(q0,{})]}),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(d1,{}),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:Da,children:["◉ reviews",Os(gt.value)?r("span",{class:"rail-review-badge",children:Os(gt.value)}):null]}),r(F2,{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(h1,{}),r("div",{class:"meta",children:r(N2,{})})]}),r($2,{})]})}const z2=3e3;let ml=null,Zr=!1,xo=!1,zn=!1;function j2(){if(xo)return;xo=!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 zn&&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 H2(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=>gu(y)),f=e.mode||"terminal";if(!e.realClick)for(const y of s)ql(y,f);zn=!!e.blockWs,zn&&j2();const d=document.getElementById("rail")||document.querySelector(".rail, #left");ye("memtest.start",{nonce:e.nonce,n,mode:f,blockWs:zn,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&&(br({path:p}),await h(t/3),jr(g,"pane"),await h(t/3)),y%5===0&&ye("memtest.progress",{nonce:e.nonce,i:y})}if(p)for(const y of s)Ac(y,p);if(zn=!1,!e.realClick)for(const[y,g]of s.entries())ql(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:f}),Zr=!1}async function So(){try{const e=await fetch("/memtest.json",{cache:"no-store"});return e.ok?await e.json():null}catch{return null}}async function q2(){const e=await So();e!==null&&(ml=e.nonce??null,setInterval(async()=>{if(Zr)return;const t=await So();!t||t.nonce==null||t.nonce===ml||(ml=t.nonce,H2(t))},z2))}const fn=H([]);let U2=1;function W2(e){return new Promise(t=>{fn.value=[...fn.value,{...e,id:U2++,resolve:t}]})}function In(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 Qn(e,t={}){return W2({type:"confirm",message:e,okLabel:t.okLabel||"OK",cancelLabel:t.cancelLabel||"Cancel",danger:!!t.danger})}function K2(e){return String(e??"").split(` +`).map((n,i)=>r(K,{children:[i>0?r("br",{}):null,n]}))}function V2({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;Fe(()=>In(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"?In(e.id,((c=n.current)==null?void 0:c.value)??""):e.type==="alert"?In(e.id,void 0):In(e.id,!0)},s=()=>In(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:K2(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 G2(){const e=fn.value;return r(K,{children:e.map(t=>r(V2,{req:t},t.id))})}async function mr(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 J2(e){return Array.isArray(e)?e.filter(Boolean):null}function Q2(e,t){return e===t?!0:!e||!t?!1:e.length===t.length&&e.every((n,i)=>n===t[i])}function Cd(e){const{paths:t}=e||{},n=J2(t);Q2(n,Nt.value)||(Nt.value=n),rn.value=!0,ye("overlay.open",{which:"cleanup",scoped:!!Nt.value})}function Y2(e){return e!=null&&e.length?`/api/cleanup/candidates?${e.map(t=>`paths=${encodeURIComponent(t)}`).join("&")}`:"/api/cleanup/candidates"}function On(){rn.value=!1,Nt.value=null}function Z2(){Fe(On,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=te(0);j(()=>{const x=document.getElementById("cleanup-btn"),w=()=>Cd();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 mr("load candidates",Y2(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 mr("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}On()}return rn.value?r("div",{id:"cleanup-modal",class:"cleanup-modal-overlay",onClick:x=>{x.target.id==="cleanup-modal"&&On()},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:On,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:On,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 $o(){$i.value=!0,ye("overlay.open",{which:"commands"})}function gl(){$i.value=!1}function X2({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 Ig(e.label,{label:u,exec:c})}async function a(){await Og(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",$o),()=>{l&&l.removeEventListener("click",$o)}},[]);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),f=a?c:c+1;o.splice(f,0,s),Dg(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 Lg({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"&&gl()},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:gl,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(X2,{c:l,i:a,onDragState:t},l.label))}),r("button",{id:"commands-modal-add",class:"commands-modal-add",onClick:n,children:"+ add command"})]})})}const Td=[{id:"default",label:"default"},{id:"full",label:"full"}];function yl(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}function tb(e){return!e||e==="default"?null:e}function Co(e){var t;return((t=Td.find(n=>n.id===e))==null?void 0:t.label)||e}const To=["shell","idle","done","working","needs-input"];function Eo(e){let t=-1;for(const n of e){const i=To.indexOf(n);i>t&&(t=i)}return t>=0?To[t]:"shell"}const Ed="";function Qa(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||Ed;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 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 nb(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 rb(e){return String(e||"").replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ib(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 rb(e.cwd)}return null}function lb(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||Ed)===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(""),Xr=H("default"),ei=H("default"),ti=H("default"),ni=H("default");function ab(e){return(e==null?void 0:e.mode)==="agent"&&(e.agent||"claude")==="claude"}const Ti=H(null);function Pd(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 sb(e,t,n,i){const l=[],a=new Set;for(const o of Pd(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 ob(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 cb(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 ub(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 db=Vt(()=>sb(Ut.value,ce.value,Ya(Ut.value),Ti.value));function Ya(e){var t;return((t=(Bt.value||[]).find(n=>n.id===e))==null?void 0:t.repo)||null}function hb(e){var n,i;const t=Ya(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 Po(e){var n,i,l;Ut.value=e;const t=Pd(e,ce.value);Ue.value=t.length?t[0].branch:null,Xe.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=Hg(),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,Ue.value=null,Xe.value=null,Tt.value=""}function Ao(e){Ue.value=e,Xe.value=null}function fb(){Ue.value=null,Xe.value=""}function pb(){Fe(Or,Ut.value!=null),j(()=>(window.__periscopeOpenLauncher=Po,()=>{window.__periscopeOpenLauncher===Po&&delete window.__periscopeOpenLauncher}),[]);const e=Ut.value;if(e==null)return null;const t=Wr(),n=db.value,i=Ya(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),ab(p)&&h.set("account",Xr.value);const m=yl(p)?tb(ei.value):null;m&&h.set("profile",m),yl(p)&&h.set("model",ti.value),yl(p)&&h.set("effort",ni.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"}),Or()}const s=ub(t),o=s[0],u=Tt.value.trim(),c=u?cb(n,u).slice(0,24):ob(n,hb(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"&&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: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&&Ao(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:()=>Ao(p.branch),children:["⎇ ",p.branch]},p.branch)),Xe.value==null?r("button",{class:"launcher-branch launcher-branch-new",onClick:fb,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,"”."]})]}),$n()&&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${Xr.value===p.id?" is-active":""}`,onClick:()=>{Xr.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:Td.map(p=>r("button",{class:`launcher-branch${ei.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:()=>{ei.value=p.id,qg(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:or.map(p=>r("button",{class:`launcher-branch${ti.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:()=>{ti.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:Ra.map(p=>r("button",{class:`launcher-branch${ni.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:()=>{ni.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 mb=/github\.com\/([^/]+\/[^/]+)\/pull\/(\d+)/,gb=/^#?(\d+)$/;function yb(e){const t=e.match(mb);if(t)return{repo:t[1],pr:Number(t[2])};const n=e.trim().match(gb);return n?{repo:null,pr:Number(n[1])}:null}const bb=/^(~|\.{0,2}\/)/;function kb(e){const t=(e||"").trim();return!t||!bb.test(t)?null:t.replace(/\/+$/,"")||"/"}function Yt(e,t){return e.toLowerCase().includes(t.toLowerCase())}function wb(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=kb(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=yb(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 Mo(){ht.value=!0,ye("overlay.open",{which:"open"})}function St(){ht.value=!1}const Lo={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:"◉"}},vb=3e3;function _b(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,vb))};return a(),()=>{i=!1,l&&clearTimeout(l)}},[e]),t}function xb(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 Sb(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 $b(){Fe(St,ht.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=Mo;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===Mo&&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(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}Rg(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"){Da(),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=wb(n,e).map($=>({...$,group:Lo[$.kind].group,icon:Lo[$.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(Zi,{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(Cb,{selectedJob:u,onSelect:c,onBack:u?()=>c(null):()=>{o(!1),i("")},onClose:St}),l&&l.card.kind==="worktree"&&r(Eb,{card:l.card,onPick:$=>x({repo:l.card.repo,branch:$}),onBack:()=>a(null)}),l&&l.card.kind==="track"&&r(Pb,{card:l.card,onPick:$=>w(l.card.repo,$),onBack:()=>a(null)}),l&&l.card.kind==="pr"&&r(Ab,{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 Cb({selectedJob:e,onSelect:t,onBack:n}){const i=_b(!e);return Fe(n,!0),e?r(Tb,{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 Tb({jobId:e,onBack:t}){const{messages:n,pending:i}=xb(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:Sb(l)},l.uuid||a))]})]})}function Zi({value:e,onInput:t,placeholder:n,items:i,onPick:l,onBack:a,empty:s}){const[o,u]=B(0),c=te(null),f=te(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(K,{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(K,{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 Eb({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(Zi,{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 Pb({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(Zi,{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 Ab({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(Zi,{value:i,onInput:l,placeholder:"repo for this PR…",items:s,onPick:o=>t(o.value),onBack:n,empty:"no matching repo"})}function Io({which:e,label:t,fonts:n}){return r("label",{children:[t,r("select",{name:`font-${e}`,value:sr(e).id,onChange:i=>Wg(e,i.currentTarget.value),children:n.map(i=>r("option",{value:i.id,children:i.name},i.id))})]})}function Mb(){return r("fieldset",{class:"font-picker",children:[r("legend",{children:"Fonts"}),r(Io,{which:"ui",label:"Interface",fonts:mi}),r(Io,{which:"code",label:"Code & terminal",fonts:mi.filter(e=>e.mono)})]})}const Lb=[["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 Ib(){const e=yi();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."}),Lb.map(([t,n])=>r("label",{class:"notify-option",children:[r("input",{type:"checkbox",name:`notify-${t}`,checked:e[t],onChange:i=>Vg(t,i.currentTarget.checked)}),n]},t))]})}function Ob({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(Vi,{sprite:e.sprite}):r(Zy,{})})}function Db(){const e=mu();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:()=>Ug(t.id)}),r(Ob,{critter:t}),r("span",{children:t.name})]},t.id))})]})}const ln=H(!1);function Oo(){ln.value=!0,ye("overlay.open",{which:"settings"})}function Dn(){ln.value=!1}function Rb(){Fe(Dn,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",Oo),()=>{w&&w.removeEventListener("click",Oo)}},[]),j(()=>{ln.value&&(t(""),(async()=>{const{data:w,error:C}=await mr("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 mr("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(Mb,{}),r(Db,{}),r(Ib,{}),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 Fb(){return j(()=>{r1(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})},[]),r(K,{children:[r(eb,{}),r(Z2,{}),r(Rb,{}),r(pb,{}),r($b,{})]})}const Do=120,Nb=3600,Xl=e=>`${e.repo_slug||e.repo_key||""}#${e.pr}`;function Ro(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 Bb(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<=Do&&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=Ma(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=Ro(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(Ro(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<=Nb&&(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=Xl(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&&ja(S,n))continue;let R=null;for(const[F,q]of Object.entries(S.meters)){if(!(q!=null&&q.resets_at))continue;const L=Wu(q),I=`${T}/${F}/${Math.round(q.resets_at/60)}`,O=A[I]??0;A[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-p[T]<=Do&&(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},bl=e=>Qn(_e(e),26),Dn=e=>[e==null?void 0:e.session,e==null?void 0:e.branch].filter(Boolean).join(" · "),kl=e=>!!(e!=null&&e.pid&&e.agent==="claude"),Fo=e=>{const t=/^mcp__(.+?)__(.+)$/.exec(e||"");return t?`${t[2]} (${t[1]})`:e||"this"};function zb(e){const t=String(e||"").replace(/\s+/g," ").trim(),n=t.match(/^.*?[.!?](?=\s[A-Z0-9]|$)/);return Qn(n?n[0]:t,140)}const No={permission:"Waiting for your approval.",question:"Waiting for your answer.",dialog:"Waiting for your input."},jb={failure:"✗",pending:"⟳",success:"✓"},Ad=e=>`usage_to_${e}`;function Md(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:`${bl(n)} needs you`,subtitle:Dn(n),body:s.summary?`Allow ${Fo(s.tool)}: ${s.summary}?`:`Allow ${Fo(s.tool)}?`,category:"needs_permission",data:{open:"pane",pid:n.pid,request_id:s.request_id}}:{...i,title:`${bl(n)} needs you`,subtitle:Dn(n),body:No[uu(n.waiting_for)]||No.dialog,category:"needs_dialog",data:{open:"pane",pid:n.pid}}}case"question":{const s=e.alert;return{...i,title:`${Qn(n?_e(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,...kl(n)?{category:"question"}:{},data:{open:"pane",pid:(n==null?void 0:n.pid)??null}}}case"done":return{...i,title:`${bl(n)} is done`,subtitle:n.pr&&n.pr_linked?`${n.session} · PR #${n.pr}`:Dn(n),body:zb(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=>`${jb[f.state]||"·"} ${f.name}`).join(" · "),o=rr(n.repo_slug,n.pr),u=kl(n)?n:(t.windows||[]).find(f=>kl(f)&&Xl(f)===Xl(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(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:`${qa(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?Ad(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}),Bo=it("open_pr","Open PR"),Hb=it("mark_seen","Mark seen"),zo=it("cleanup","Clean up worktree",{foreground:!0}),qb=it("details","Details",{foreground:!0}),Ub=it("open","Open",{foreground:!0}),jo=it("fix","Ask agent to fix",{auth:!0});function Wb({accounts:e=[],moveTargets:t={}}={}){const n=[{id:"done_seen",actions:[Hb]},{id:"ci_failed_pr",actions:[Bo]},{id:"pr_merged",actions:[zo]},{id:"pr_merged_cleanup",actions:[zo]},{id:"pr_merged_pr",actions:[Bo]},{id:"usage",actions:[qb]},{id:"needs_permission",actions:[it("allow","Allow",{auth:!0})]},{id:"needs_dialog",actions:[Ub]},{id:"question",actions:[it("send","Reply",{auth:!0,reply:{button:"Send",placeholder:"Reply…"}})]},{id:"ci_failed",actions:[jo]},{id:"ci_failed_fix",actions:[jo]}];for(const i of[...new Set(Object.values(t||{}))].sort())n.push({id:Ad(i),actions:[it("spawn_on",`Spawn on ${gn(i,e||[])}`)]});return n}const Kb=Object.freeze({openExternal:Wi,openUsageDetails:$d,pickSpawnAccount:Au,openCleanupModal:Cd,markReadySeen:$u,selectPane:st,revealPane:jt,post:Mg,toast:bn,notify:bu}),Vb={allow:"Allow",deny:"Deny",send:"Reply",fix:"Ask agent to fix"},Gb={allow:"Couldn't allow",deny:"Couldn't deny",send:"Couldn't send your reply",fix:"Couldn't ask the agent to fix"},Jb=new Set(["allow","deny"]),Qb={"/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 Yb(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:Qb[e]:(t==null?void 0:t.detail)||"No answer"}const Zb=e=>{const t=e.codePointAt(0);return t!==9&&t!==10&&(t<32||t>=127&&t<=159)},Xb=e=>[...String(e)].filter(t=>!Zb(t)).join("").trim();function ek(e,t){const n=(t||[]).map(Xb).filter(Boolean),i=n.length?`${n.join(" · ")}.`:"Checks are failing.";return`CI failed on #${e}: ${i} Please investigate and fix.`}async function wl({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:Gb[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||Jb.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=Yb(i,u);o(c),t(),(u==null?void 0:u.status)!==409&&a.toast(`${Vb[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 tk({target:e,action:t,text:n,data:i}={},l=Kb){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 wl({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?wl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:o},l):void 0}case"fix":return wl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:ek(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 ea=3e3,nk=2,rk=new Set(["needs_input","question"]);function ik(e,t,n,i=!0){const l=t.filter(o=>n-o{var t;return e.kind==="question"?"question":uu((t=e.w)==null?void 0:t.waiting_for)==="permission"?"permission":"input"};function ak(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"} · ${lk(l)}`}).join(` -`)}}function Ld(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 ak(e)}const Id="periscope.notify.v1",sk=15*60*1e3;function ok(e,t){try{const n=JSON.parse((e==null?void 0:e.getItem(Id))||"null");if(!(n!=null&&n.state)||!(n.at<=t)||t-n.at>sk)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 ck(e,t,n,i=[],l=null){try{e==null||e.setItem(Id,JSON.stringify({at:n,state:t,held:i,heldSince:l}))}catch{}}const uk={question:"needs_input"},dk=(e,t)=>e[uk[t]||t]!==!1;function hk({target:e,data:t}={}){if(t||(t={}),t.open==="url"&&t.url){Wi(t.url);return}if(t.open==="usage"){$d();return}const n=t.pid!=null&&(ce.value||[]).find(i=>String(i.pid)===String(t.pid));n?st(n):jt(e)}const fk={sends:[],flush:[],badge:null};function pk(e,t,n,i,l=Md){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>=ea&&(p.push({...Ld(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,...fk,flush:p,categories:m,timerAt:o.length?u+ea:null,...g});if(t.alerts===null)return b();try{const g=Wb({accounts:t.accounts,moveTargets:t.moveTargets}),$=JSON.stringify(g);$!==f&&(m=g,f=$)}catch(g){console.error("[notify] category set failed",g)}const x=_u(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=Bb(a,t,i/1e3);a=g.state;const $=ik(g.events.filter(v=>dk(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 mk=2e3;function gk(e={setNotifyCategories:n1,notify:bu}){let t=Promise.resolve();return(n,i)=>{n&&(t=t.then(()=>Promise.race([e.setNotifyCategories(n),new Promise(l=>setTimeout(l,mk))])).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 Ho=!1;function yk(){if(Ho||!Ve())return;Ho=!0;const e=typeof localStorage>"u"?null:localStorage,t=ok(e,Date.now());let n={state:null,held:[],heldSince:null,...t,recent:[],lastBadge:void 0,lastCategories:void 0};const i=u=>ck(e,n.state,u,n.held,n.heldSince),l=gk();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:ce.peek()||[],moveTargets:ui.peek()};l(null,[{...Ld(u,Md,c),quiet_when_focused:yi().quiet_when_focused}])};e1(hk),t1(u=>tk(u)),lt(()=>{Ec.value,Li(()=>{var u;try{const c={windows:ce.peek()||[],alerts:er.peek(),dismissedAlertIds:nr.peek(),dismissedNeedsPids:ft.peek(),dismissedReadyPids:pt.peek(),plan:((u=Ri.peek())==null?void 0:u.plan)||{},accounts:at.peek(),moveTargets:ui.peek()},f=!!(ga.peek()||Et.peek()),d=Date.now(),p=n,{sends:h,flush:m,badge:b,categories:x,timerAt:w,...C}=pk({...n,editing:f},c,yi(),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&&Zg(b)}catch(c){console.error("[notify] pass failed",c)}})})}const bk=3e3,kk=2e3;let Ei=0;function Od(){return document.getElementById("connection-banner")}function Dd(e){try{if(er.value=e.alerts||[],ga.value||Et.value)return;ce.value=e.windows||[],Oi.value=e.projects||[],Di.value=e.workspaces||[],Bt.value=e.tracks||[],Sh(ce.value),Ri.value={plan:e.usage_plan,fallback:e.usage,poke:e.poke||{}},pa.value=e.update||null,$c.value=e.resources||null,at.value=e.accounts||[],ui.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,Cc.value=e.walls||null,ma.value=e.wall_spans||[],Tc.value=e.editor||""}finally{Ec.value+=1}}function Rd(){if(Ei>0){Ei=0;const e=Od();e&&(e.hidden=!0),document.body.classList.remove("disconnected")}}function Fd(e){if(Ei+=1,Ei>=2){const t=Od();t&&(t.hidden=!1),document.body.classList.add("disconnected")}e&&console.warn("[periscope]",e)}async function wk(){if(!ga.value&&!Et.value)try{const e=await fetch("/api/state");if(!e.ok)throw new Error(`HTTP ${e.status}`);Dd(await e.json()),Rd()}catch(e){Fd(`poll failed: ${e.message}`)}}let vl=!1,ta=!1,Yn=null,Ot=null,fn=null;function vk(){if(Ot)return;const e=async()=>{await wk(),Ot!==null&&(Ot=setTimeout(e,bk))};Ot=setTimeout(e,0)}function Nd(){Ot&&(clearTimeout(Ot),Ot=null)}const _k=1e4;let Dt=null,qo=0;async function Xi(){const e=++qo;try{const t=await fetch("/api/reviews");if(!t.ok)return;const n=await t.json();e===qo&&(gt.value=n.rows||[])}catch{}}function xk(){if(Dt)return;const e=async()=>{await Xi(),Dt!==null&&(Dt=setTimeout(e,_k))};Dt=setTimeout(e,0)}function Sk(){Dt&&(clearTimeout(Dt),Dt=null)}function Bd(){const e=location.protocol==="https:"?"wss:":"ws:",t=new WebSocket(`${e}//${location.host}/ws/state`);Yn=t,t.onmessage=n=>{Nd();try{Dd(JSON.parse(n.data)),Rd()}catch(i){Fd(`bad frame: ${i.message}`)}},t.onclose=()=>{ta||(Yn=null,vk(),fn||(fn=setTimeout(()=>{fn=null,Bd()},kk)))},t.onerror=()=>{try{t.close()}catch{}}}function $k(){return vl?()=>{}:(vl=!0,ta=!1,Bd(),xk(),()=>{if(ta=!0,Sk(),vl=!1,Yn){try{Yn.close()}catch{}Yn=null}Nd(),fn&&(clearTimeout(fn),fn=null)})}const Ck=/[A-Za-z0-9_]+|\s+|[^A-Za-z0-9_\s]/g;function Uo(e){return String(e??"").match(Ck)||[]}function Tk(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 Ak(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 Mk=["dist/","build/","vendor/",".next/","target/debug/","target/release/"],Lk=new Set(["package-lock.json","yarn.lock","pnpm-lock.yaml","uv.lock","poetry.lock","Cargo.lock","Gemfile.lock","composer.lock","go.sum"]),Ik=[".min.js",".min.css",".map",".snap"];function zd(e){const t=String(e||"");if(!t)return!1;const n=t.split("/").pop()||"";if(Lk.has(n)||Ik.some(l=>n.endsWith(l)))return!0;const i=`${t}/`;return Mk.some(l=>i.includes(`/${l}`)||i.startsWith(l))}function Ok(e){const t=[],n=[];for(const i of e||[])(zd(i.path)?n:t).push(i);return t.concat(n)}const na=H({}),Dk="\0";function jd(e,t){return`${e}${Dk}${t}`}function Hd(e,t,n,i,l=!1){const a=e[jd(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 qd(e,t,n){const i=jd(e,t),l={...na.value},a={...l[i]||{},...n};a.collapsed===void 0&&!a.viewedSig?delete l[i]:l[i]=a,na.value=l}function Rk(e,t,n){qd(e,t,{collapsed:n})}function Fk(e,t,n,i){qd(e,t,{viewedSig:i?n:void 0,collapsed:!!i})}function Nk(e,t,n){return n.reduce((i,l)=>i+(Hd(e,t,l.path,l.sig).viewed?1:0),0)}const Bk=[["session","This session","Changes since the current Claude session started"],["branch","This branch","Changes vs where this branch forked"]],zk={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 Ud(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0&&zk[t.slice(n+1).toLowerCase()]||""}function Wo({text:e,lang:t,hl:n}){if(!n||!t)return e||" ";try{return n(e,t)}catch{return e||" "}}function jk({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(Wo,{text:i.text,lang:t,hl:n})},l)):r(Wo,{text:e.text,lang:t,hl:n})})})}function Wd({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]}),Ak(e.lines).map((a,s)=>r(jk,{line:a,lang:t,hl:n},s))]})}function Hk({file:e,repo:t,review:n,hl:i}){const l=zd(e.path),{collapsed:a,viewed:s}=Hd(n,t,e.path,e.sig,l),o=!a,u=Ud(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:()=>Rk(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:()=>Fk(t,e.path,e.sig,!s),children:s?"✓ viewed":"viewed"})]}),o&&e.hunks.map((d,p)=>r(Wd,{hunk:d,lang:u,hl:i,onOpen:c?h=>br({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 qk=[3,10,25];function Uk({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 Yi(()=>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=Ok(((x=o.data)==null?void 0:x.files)||[]),p=((w=o.data)==null?void 0:w.repo)||"",h=na.value,m=Nk(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:Bk.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:qk.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(Hk,{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 Wk=new Set(["Read","Edit","Write","MultiEdit","NotebookEdit"]),Kk=new Set(["html","md"]);function Vk(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 Gk(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0?t.slice(n+1).toLowerCase():""}function Jk(e,t=Kk){const n=[],i=[];for(const l of e)(t.has(Gk(l.path))?n:i).push(l);return{priority:n,others:i}}function Qk(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||!Wk.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 Yk(e){return e==="need_human"?"var(--s-danger)":e==="done"?"var(--s-success)":"var(--fg-3)"}function Zk(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 Xk(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 ew(e){return e?(e.replace(/[^A-Za-z0-9]/g,"").slice(0,2)||e.slice(0,1)).toUpperCase():"?"}const tw={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 nw({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:ew(o)}))})]})]})}function rw({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=wr(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 iw({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:${Yk(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:${Zk(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:[Xk(e.kind,e.state)," · ",Pe(e.at)," ago"]})]})]})}function lw({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(iw,{e:s},o))}):l?null:r("div",{class:"timeline-empty",children:"no recent activity"})]})}function aw({pid:e,onRefresh:t,idPrefix:n}){const i=te(null),l=te(null),a=te(null),s=e?Er(e):null,o=(s==null?void 0:s.tags)||[];function u(){if(!e)return;const d=Er(e)||{tags:[]};Kr(e,{notes:i.current.value,tags:d.tags})}function c(){const d=(l.current.value||"").trim();if(!d||!e)return;const p=Er(e)||{notes:i.current.value,tags:[]},h=d.split(/[\s,]+/).filter(Boolean);Kr(e,{notes:i.current.value,tags:[...p.tags,...h]}),l.current.value="",t==null||t()}function f(d){const p=Er(e)||{notes:i.current.value,tags:[]};Kr(e,{notes:i.current.value,tags:p.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,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 _l({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:()=>br({path:e.path,line:null}),title:`Open ${e.path} as a preview tab`,children:[r("span",{class:"files-op",children:ow(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 sw({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?Qk(l.messages):[],s=fu(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=>du(g,d),h=t.trim(),m=g=>Vk(g.path,h),b=u.filter(m),{priority:x,others:w}=Jk(f.filter(m)),C=g=>()=>Fg(e,g),y=[{items:b,render:g=>r(_l,{it:g,label:p(g.path),pinned:!0,onTogglePin:C(g.path)},`pin:${g.path}`)},{items:x,render:g=>r(_l,{it:g,label:p(g.path),priority:!0,pinned:!1,onTogglePin:C(g.path)},`pri:${g.path}`)},{items:w,render:g=>r(_l,{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(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 ow(e){switch(e){case"Read":return"👁";case"Write":return"+";case"Edit":case"MultiEdit":case"NotebookEdit":return"✎";default:return"·"}}function cw({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 f=tw[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(nw,{data:e,onLinkAsk:u}),r(rw,{data:e,onLinkAsk:u})]}),r("section",{class:"modal-side-section modal-side-notes",children:[r("h4",{children:"Notes"}),r(aw,{pid:o,idPrefix:l,onRefresh:t},o)]}),r(sw,{pid:o}),r("section",{class:"modal-side-section modal-side-activity",children:[r("h4",{children:"Activity"}),r(lw,{data:e,streamRef:a})]})]})}let pn=null,Rr=null;function uw(){return pn?Promise.resolve(pn):(Rr||(Rr=Yi(()=>import("./chunks/preview.js").then(e=>e.P),[]).then(e=>(pn=e,e)).catch(e=>{throw Rr=null,e})),Rr)}function dw({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),uw().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 xl(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}`),Xi()}catch(l){n(String(l))}finally{i(!1)}}function hw({row:e}){const t=wr(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=qi(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 Ko="filter branches, PRs, people, tickets";function fw({col:e}){const{label:t,what:n}=ji[e],i=Ol.value,l=(i==null?void 0:i.key)===e,a=cg(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:()=>{Ol.value=a},children:[t,l?r("span",{class:"rq-sort-dir","aria-hidden":"true",children:i.dir==="asc"?"▲":"▼"}):null]})})}function pw({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:()=>Tu(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(hw,{row:e})}),r("td",{class:"rq-wt",children:o?`${o.stops} stop${o.stops===1?"":"s"} · ${ag(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:()=>xl("/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"})&&xl("/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})&&xl("/api/reviews/clear",e,n,l)},children:"clear"}):null,t?r("span",{class:"rq-note",children:t}):null]})]})}function mw(){j(()=>{Xi()},[]);const e=gt.value;if(e===null)return r("div",{class:"wt-empty",children:"loading…"});const t=og(e,Ol.value),n=fs.value,i=ug(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:Ko,"aria-label":Ko,spellcheck:!1,autocomplete:"off",value:n,onInput:a=>{fs.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(ji).map(a=>r(fw,{col:a},a)),r("th",{})]})}),r("tbody",{children:i.map(a=>r(pw,{row:a},`${a.repo}/${a.branch}`))})]})]})}async function gw(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 Kd({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:pr(t.body,{demote:!1,softBreaks:"space"})})]},n))}):null}function yw({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 gw("/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 bw({stop:e,diffFiles:t,comments:n,repo:i,branch:l,hl:a,onPosted:s}){const[o,u]=B(!1),c=lg(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:pr(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(Wd,{hunk:m,lang:Ud(p.ref.path),hl:a,onOpen:null},b))]},h))]}):null,r(Kd,{list:n}),r(yw,{repo:i,branch:l,stop:e.title,onPosted:s})]})}function kw({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 Yi(()=>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),Xi()};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=rg(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(K,{children:[" · ",n!=null&&n.url&&n.number===b.header.pr?r("a",{class:`rq-pr-link ${qi(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(bw,{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(Kd,{list:C})]}):null]})}function ww({target:e,agent:t,onPaste:n,class:i="modal-xterm",id:l}){const a=te(null);return j(()=>(J1(a.current,e,{agent:t,onPaste:n}),ju),[]),r("div",{ref:a,id:l,class:i})}function vw(){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=yr(()=>{n(!1),l(""),G1()},[]);Fe(a,t);function s(o){o.preventDefault(),i&&(o.shiftKey?Gs(i):Vs(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&&Gs(i),children:"‹"}),r("button",{type:"button",class:"term-search-btn",title:"Next (Enter)",onClick:()=>i&&Vs(i),children:"›"}),r("button",{type:"button",class:"term-search-btn",title:"Close (Esc)",onClick:a,children:"✕"})]}):null}const Vd={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}},_w=.5;function xw(e,t,n){return Math.round(Math.min(Math.max(e,t),Math.max(t,n)))}function Sw(e,t,n,i){return xw(e+n.dir*t,n.min,i*_w)}function $w(e){return Number.isFinite(e)&&e>0?e:null}function Gd({which:e}){const t=Vd[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"),K1();const p=m=>{d=Sw(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"),V1(),d!==c&&Fs(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:()=>Fs(t.pref,t.def)})}function Cw(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 Tw(e){return(e==null?void 0:e.session_effort)||(e==null?void 0:e.launch_effort)||"default"}function Ew(e){var t;return e!=null&&e.model?e.model.replace(/\s*\(.*\)/,""):e!=null&&e.session_model?((t=or.find(n=>n.id===e.session_model))==null?void 0:t.label)||e.session_model:"model"}function Pw({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":Cw(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=or.find(f=>f.id===t.model))==null?void 0:c.label)||t.model:Ew(e),u=t.effort||Tw(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}),or.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}`}),Ra.map(f=>r("option",{value:f,children:f},f))]})]})}const Aw=2e3;function Mw(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&&!zr.value[t]&&(zr.value={...zr.value,[t]:!0})}catch{}i&&(l=setTimeout(a,Aw))}return a(),()=>{i=!1,l&&clearTimeout(l)}},[e,t,n])}function Lw(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 Iw({input:e}){const t=String(e.old_string||"").split(` +`).map(v=>v.trim()).filter(Boolean)};i(!0);const{error:$}=await mr("save settings","/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(i(!1),$){t($);return}Dn()}return ln.value?r("div",{id:"settings-modal",class:"settings-modal-overlay",onClick:w=>{w.target.id==="settings-modal"&&Dn()},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:Dn,children:"×"})]}),r("form",{id:"settings-form",onSubmit:x,children:[r(Mb,{}),r(Db,{}),r(Ib,{}),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:Dn,children:"cancel"}),r("button",{type:"submit",id:"settings-submit",disabled:n,children:"save"})]})]})]})}):null}function Fb(){return j(()=>{r1(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})},[]),r(K,{children:[r(eb,{}),r(Z2,{}),r(Rb,{}),r(pb,{}),r($b,{})]})}const Do=120,Nb=3600,Xl=e=>`${e.repo_slug||e.repo_key||""}#${e.pr}`;function Ro(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 Bb(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<=Do&&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=Ma(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=Ro(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(Ro(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<=Nb&&(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=Xl(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&&ja(S,n))continue;let R=null;for(const[F,q]of Object.entries(S.meters)){if(!(q!=null&&q.resets_at))continue;const L=Wu(q),I=`${T}/${F}/${Math.round(q.resets_at/60)}`,O=A[I]??0;A[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-p[T]<=Do&&(m[T]=p[T]);return{state:{pass:d,seen:m,ci:$,prs:v,prAt:g,meters:A},events:b}}const Yn=(e,t)=>{const n=String(e||"").trim(),i=Array.from(n);return i.length>t?`${i.slice(0,t-1).join("")}…`:n},bl=e=>Yn(_e(e),26),Rn=e=>[e==null?void 0:e.session,e==null?void 0:e.branch].filter(Boolean).join(" · "),kl=e=>!!(e!=null&&e.pid&&e.agent==="claude"),Fo=e=>{const t=/^mcp__(.+?)__(.+)$/.exec(e||"");return t?`${t[2]} (${t[1]})`:e||"this"};function zb(e){const t=String(e||"").replace(/\s+/g," ").trim(),n=t.match(/^.*?[.!?](?=\s[A-Z0-9]|$)/);return Yn(n?n[0]:t,140)}const No={permission:"Waiting for your approval.",question:"Waiting for your answer.",dialog:"Waiting for your input."},jb={failure:"✗",pending:"⟳",success:"✓"},Ad=e=>`usage_to_${e}`;function Md(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:`${bl(n)} needs you`,subtitle:Rn(n),body:s.summary?`Allow ${Fo(s.tool)}: ${s.summary}?`:`Allow ${Fo(s.tool)}?`,category:"needs_permission",data:{open:"pane",pid:n.pid,request_id:s.request_id}}:{...i,title:`${bl(n)} needs you`,subtitle:Rn(n),body:No[uu(n.waiting_for)]||No.dialog,category:"needs_dialog",data:{open:"pane",pid:n.pid}}}case"question":{const s=e.alert;return{...i,title:`${Yn(n?_e(n):s.name||s.session||"A session",26)} asks`,subtitle:n?Rn(n):s.session||"",body:Yn(s.message,180),target:s.target||i.target,...kl(n)?{category:"question"}:{},data:{open:"pane",pid:(n==null?void 0:n.pid)??null}}}case"done":return{...i,title:`${bl(n)} is done`,subtitle:n.pr&&n.pr_linked?`${n.session} · PR #${n.pr}`:Rn(n),body:zb(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=>`${jb[f.state]||"·"} ${f.name}`).join(" · "),o=ir(n.repo_slug,n.pr),u=kl(n)?n:(t.windows||[]).find(f=>kl(f)&&Xl(f)===Xl(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(f=>f.state==="failure").map(f=>f.name)}}}case"pr_merged":{const s=ir(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}`:Rn(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=Yn(((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:`${qa(e.meter)} usage ${Math.round(e.m.percent??0)}%`+(c>=0?` · →${Math.round(c)}% at reset`:""),body:u?`${wn(f,"session")} working on ${o}.`:`${wn(f,"session")} working.`,category:p?Ad(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}),Bo=it("open_pr","Open PR"),Hb=it("mark_seen","Mark seen"),zo=it("cleanup","Clean up worktree",{foreground:!0}),qb=it("details","Details",{foreground:!0}),Ub=it("open","Open",{foreground:!0}),jo=it("fix","Ask agent to fix",{auth:!0});function Wb({accounts:e=[],moveTargets:t={}}={}){const n=[{id:"done_seen",actions:[Hb]},{id:"ci_failed_pr",actions:[Bo]},{id:"pr_merged",actions:[zo]},{id:"pr_merged_cleanup",actions:[zo]},{id:"pr_merged_pr",actions:[Bo]},{id:"usage",actions:[qb]},{id:"needs_permission",actions:[it("allow","Allow",{auth:!0})]},{id:"needs_dialog",actions:[Ub]},{id:"question",actions:[it("send","Reply",{auth:!0,reply:{button:"Send",placeholder:"Reply…"}})]},{id:"ci_failed",actions:[jo]},{id:"ci_failed_fix",actions:[jo]}];for(const i of[...new Set(Object.values(t||{}))].sort())n.push({id:Ad(i),actions:[it("spawn_on",`Spawn on ${yn(i,e||[])}`)]});return n}const Kb=Object.freeze({openExternal:Wi,openUsageDetails:$d,pickSpawnAccount:Au,openCleanupModal:Cd,markReadySeen:$u,selectPane:st,revealPane:jt,post:Mg,toast:kn,notify:bu}),Vb={allow:"Allow",deny:"Deny",send:"Reply",fix:"Ask agent to fix"},Gb={allow:"Couldn't allow",deny:"Couldn't deny",send:"Couldn't send your reply",fix:"Couldn't ask the agent to fix"},Jb=new Set(["allow","deny"]),Qb={"/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 Yb(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:Qb[e]:(t==null?void 0:t.detail)||"No answer"}const Zb=e=>{const t=e.codePointAt(0);return t!==9&&t!==10&&(t<32||t>=127&&t<=159)},Xb=e=>[...String(e)].filter(t=>!Zb(t)).join("").trim();function ek(e,t){const n=(t||[]).map(Xb).filter(Boolean),i=n.length?`${n.join(" · ")}.`:"Checks are failing.";return`CI failed on #${e}: ${i} Please investigate and fix.`}async function wl({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:Gb[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||Jb.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=Yb(i,u);o(c),t(),(u==null?void 0:u.status)!==409&&a.toast(`${Vb[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 tk({target:e,action:t,text:n,data:i}={},l=Kb){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 wl({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?wl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:o},l):void 0}case"fix":return wl({target:e,show:s},t,"/api/pane/reply",{pid:i.pid,text:ek(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 ea=3e3,nk=2,rk=new Set(["needs_input","question"]);function ik(e,t,n,i=!0){const l=t.filter(o=>n-o{var t;return e.kind==="question"?"question":uu((t=e.w)==null?void 0:t.waiting_for)==="permission"?"permission":"input"};function ak(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"} · ${lk(l)}`}).join(` +`)}}function Ld(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 ak(e)}const Id="periscope.notify.v1",sk=15*60*1e3;function ok(e,t){try{const n=JSON.parse((e==null?void 0:e.getItem(Id))||"null");if(!(n!=null&&n.state)||!(n.at<=t)||t-n.at>sk)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 ck(e,t,n,i=[],l=null){try{e==null||e.setItem(Id,JSON.stringify({at:n,state:t,held:i,heldSince:l}))}catch{}}const uk={question:"needs_input"},dk=(e,t)=>e[uk[t]||t]!==!1;function hk({target:e,data:t}={}){if(t||(t={}),t.open==="url"&&t.url){Wi(t.url);return}if(t.open==="usage"){$d();return}const n=t.pid!=null&&(ce.value||[]).find(i=>String(i.pid)===String(t.pid));n?st(n):jt(e)}const fk={sends:[],flush:[],badge:null};function pk(e,t,n,i,l=Md){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>=ea&&(p.push({...Ld(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,...fk,flush:p,categories:m,timerAt:o.length?u+ea:null,...g});if(t.alerts===null)return b();try{const g=Wb({accounts:t.accounts,moveTargets:t.moveTargets}),$=JSON.stringify(g);$!==f&&(m=g,f=$)}catch(g){console.error("[notify] category set failed",g)}const x=_u(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=Bb(a,t,i/1e3);a=g.state;const $=ik(g.events.filter(v=>dk(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 mk=2e3;function gk(e={setNotifyCategories:n1,notify:bu}){let t=Promise.resolve();return(n,i)=>{n&&(t=t.then(()=>Promise.race([e.setNotifyCategories(n),new Promise(l=>setTimeout(l,mk))])).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 Ho=!1;function yk(){if(Ho||!Ve())return;Ho=!0;const e=typeof localStorage>"u"?null:localStorage,t=ok(e,Date.now());let n={state:null,held:[],heldSince:null,...t,recent:[],lastBadge:void 0,lastCategories:void 0};const i=u=>ck(e,n.state,u,n.held,n.heldSince),l=gk();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:ce.peek()||[],moveTargets:ui.peek()};l(null,[{...Ld(u,Md,c),quiet_when_focused:yi().quiet_when_focused}])};e1(hk),t1(u=>tk(u)),lt(()=>{Ec.value,Li(()=>{var u;try{const c={windows:ce.peek()||[],alerts:tr.peek(),dismissedAlertIds:rr.peek(),dismissedNeedsPids:ft.peek(),dismissedReadyPids:pt.peek(),plan:((u=Ri.peek())==null?void 0:u.plan)||{},accounts:at.peek(),moveTargets:ui.peek()},f=!!(ga.peek()||Et.peek()),d=Date.now(),p=n,{sends:h,flush:m,badge:b,categories:x,timerAt:w,...C}=pk({...n,editing:f},c,yi(),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&&Zg(b)}catch(c){console.error("[notify] pass failed",c)}})})}const bk=3e3,kk=2e3;let Ei=0;function Od(){return document.getElementById("connection-banner")}function Dd(e){try{if(tr.value=e.alerts||[],ga.value||Et.value)return;ce.value=e.windows||[],Oi.value=e.projects||[],Di.value=e.workspaces||[],Bt.value=e.tracks||[],Sh(ce.value),Ri.value={plan:e.usage_plan,fallback:e.usage,poke:e.poke||{}},pa.value=e.update||null,$c.value=e.resources||null,at.value=e.accounts||[],ui.value=e.move_targets||{},Wn.value=e.spawn_account||null,Kn.value=e.spawn_model||null,Vn.value=e.spawn_effort||null,sn.value=e.launch_default||null,Cc.value=e.walls||null,ma.value=e.wall_spans||[],Tc.value=e.editor||""}finally{Ec.value+=1}}function Rd(){if(Ei>0){Ei=0;const e=Od();e&&(e.hidden=!0),document.body.classList.remove("disconnected")}}function Fd(e){if(Ei+=1,Ei>=2){const t=Od();t&&(t.hidden=!1),document.body.classList.add("disconnected")}e&&console.warn("[periscope]",e)}async function wk(){if(!ga.value&&!Et.value)try{const e=await fetch("/api/state");if(!e.ok)throw new Error(`HTTP ${e.status}`);Dd(await e.json()),Rd()}catch(e){Fd(`poll failed: ${e.message}`)}}let vl=!1,ta=!1,Zn=null,Ot=null,pn=null;function vk(){if(Ot)return;const e=async()=>{await wk(),Ot!==null&&(Ot=setTimeout(e,bk))};Ot=setTimeout(e,0)}function Nd(){Ot&&(clearTimeout(Ot),Ot=null)}const _k=1e4;let Dt=null,qo=0;async function Xi(){const e=++qo;try{const t=await fetch("/api/reviews");if(!t.ok)return;const n=await t.json();e===qo&&(gt.value=n.rows||[])}catch{}}function xk(){if(Dt)return;const e=async()=>{await Xi(),Dt!==null&&(Dt=setTimeout(e,_k))};Dt=setTimeout(e,0)}function Sk(){Dt&&(clearTimeout(Dt),Dt=null)}function Bd(){const e=location.protocol==="https:"?"wss:":"ws:",t=new WebSocket(`${e}//${location.host}/ws/state`);Zn=t,t.onmessage=n=>{Nd();try{Dd(JSON.parse(n.data)),Rd()}catch(i){Fd(`bad frame: ${i.message}`)}},t.onclose=()=>{ta||(Zn=null,vk(),pn||(pn=setTimeout(()=>{pn=null,Bd()},kk)))},t.onerror=()=>{try{t.close()}catch{}}}function $k(){return vl?()=>{}:(vl=!0,ta=!1,Bd(),xk(),()=>{if(ta=!0,Sk(),vl=!1,Zn){try{Zn.close()}catch{}Zn=null}Nd(),pn&&(clearTimeout(pn),pn=null)})}const Ck=/[A-Za-z0-9_]+|\s+|[^A-Za-z0-9_\s]/g;function Uo(e){return String(e??"").match(Ck)||[]}function Tk(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 Ak(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 Mk=["dist/","build/","vendor/",".next/","target/debug/","target/release/"],Lk=new Set(["package-lock.json","yarn.lock","pnpm-lock.yaml","uv.lock","poetry.lock","Cargo.lock","Gemfile.lock","composer.lock","go.sum"]),Ik=[".min.js",".min.css",".map",".snap"];function zd(e){const t=String(e||"");if(!t)return!1;const n=t.split("/").pop()||"";if(Lk.has(n)||Ik.some(l=>n.endsWith(l)))return!0;const i=`${t}/`;return Mk.some(l=>i.includes(`/${l}`)||i.startsWith(l))}function Ok(e){const t=[],n=[];for(const i of e||[])(zd(i.path)?n:t).push(i);return t.concat(n)}const na=H({}),Dk="\0";function jd(e,t){return`${e}${Dk}${t}`}function Hd(e,t,n,i,l=!1){const a=e[jd(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 qd(e,t,n){const i=jd(e,t),l={...na.value},a={...l[i]||{},...n};a.collapsed===void 0&&!a.viewedSig?delete l[i]:l[i]=a,na.value=l}function Rk(e,t,n){qd(e,t,{collapsed:n})}function Fk(e,t,n,i){qd(e,t,{viewedSig:i?n:void 0,collapsed:!!i})}function Nk(e,t,n){return n.reduce((i,l)=>i+(Hd(e,t,l.path,l.sig).viewed?1:0),0)}const Bk=[["session","This session","Changes since the current Claude session started"],["branch","This branch","Changes vs where this branch forked"]],zk={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 Ud(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0&&zk[t.slice(n+1).toLowerCase()]||""}function Wo({text:e,lang:t,hl:n}){if(!n||!t)return e||" ";try{return n(e,t)}catch{return e||" "}}function jk({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(Wo,{text:i.text,lang:t,hl:n})},l)):r(Wo,{text:e.text,lang:t,hl:n})})})}function Wd({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]}),Ak(e.lines).map((a,s)=>r(jk,{line:a,lang:t,hl:n},s))]})}function Hk({file:e,repo:t,review:n,hl:i}){const l=zd(e.path),{collapsed:a,viewed:s}=Hd(n,t,e.path,e.sig,l),o=!a,u=Ud(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:()=>Rk(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:()=>Fk(t,e.path,e.sig,!s),children:s?"✓ viewed":"viewed"})]}),o&&e.hunks.map((d,p)=>r(Wd,{hunk:d,lang:u,hl:i,onOpen:c?h=>br({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 qk=[3,10,25];function Uk({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 Yi(()=>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=Ok(((x=o.data)==null?void 0:x.files)||[]),p=((w=o.data)==null?void 0:w.repo)||"",h=na.value,m=Nk(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:Bk.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:qk.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(Hk,{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 Wk=new Set(["Read","Edit","Write","MultiEdit","NotebookEdit"]),Kk=new Set(["html","md"]);function Vk(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 Gk(e){const t=(e||"").split("/").pop()||"",n=t.lastIndexOf(".");return n>0?t.slice(n+1).toLowerCase():""}function Jk(e,t=Kk){const n=[],i=[];for(const l of e)(t.has(Gk(l.path))?n:i).push(l);return{priority:n,others:i}}function Qk(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||!Wk.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 Yk(e){return e==="need_human"?"var(--s-danger)":e==="done"?"var(--s-success)":"var(--fg-3)"}function Zk(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 Xk(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 ew(e){return e?(e.replace(/[^A-Za-z0-9]/g,"").slice(0,2)||e.slice(0,1)).toUpperCase():"?"}const tw={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 nw({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=ir(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:ew(o)}))})]})]})}function rw({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=wr(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 iw({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:${Yk(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:${Zk(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:[Xk(e.kind,e.state)," · ",Pe(e.at)," ago"]})]})]})}function lw({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(iw,{e:s},o))}):l?null:r("div",{class:"timeline-empty",children:"no recent activity"})]})}function aw({pid:e,onRefresh:t,idPrefix:n}){const i=te(null),l=te(null),a=te(null),s=e?Er(e):null,o=(s==null?void 0:s.tags)||[];function u(){if(!e)return;const d=Er(e)||{tags:[]};Kr(e,{notes:i.current.value,tags:d.tags})}function c(){const d=(l.current.value||"").trim();if(!d||!e)return;const p=Er(e)||{notes:i.current.value,tags:[]},h=d.split(/[\s,]+/).filter(Boolean);Kr(e,{notes:i.current.value,tags:[...p.tags,...h]}),l.current.value="",t==null||t()}function f(d){const p=Er(e)||{notes:i.current.value,tags:[]};Kr(e,{notes:i.current.value,tags:p.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,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 _l({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:()=>br({path:e.path,line:null}),title:`Open ${e.path} as a preview tab`,children:[r("span",{class:"files-op",children:ow(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 sw({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?Qk(l.messages):[],s=fu(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=>du(g,d),h=t.trim(),m=g=>Vk(g.path,h),b=u.filter(m),{priority:x,others:w}=Jk(f.filter(m)),C=g=>()=>Fg(e,g),y=[{items:b,render:g=>r(_l,{it:g,label:p(g.path),pinned:!0,onTogglePin:C(g.path)},`pin:${g.path}`)},{items:x,render:g=>r(_l,{it:g,label:p(g.path),priority:!0,pinned:!1,onTogglePin:C(g.path)},`pri:${g.path}`)},{items:w,render:g=>r(_l,{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(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 ow(e){switch(e){case"Read":return"👁";case"Write":return"+";case"Edit":case"MultiEdit":case"NotebookEdit":return"✎";default:return"·"}}function cw({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 f=tw[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(nw,{data:e,onLinkAsk:u}),r(rw,{data:e,onLinkAsk:u})]}),r("section",{class:"modal-side-section modal-side-notes",children:[r("h4",{children:"Notes"}),r(aw,{pid:o,idPrefix:l,onRefresh:t},o)]}),r(sw,{pid:o}),r("section",{class:"modal-side-section modal-side-activity",children:[r("h4",{children:"Activity"}),r(lw,{data:e,streamRef:a})]})]})}let mn=null,Rr=null;function uw(){return mn?Promise.resolve(mn):(Rr||(Rr=Yi(()=>import("./chunks/preview.js").then(e=>e.P),[]).then(e=>(mn=e,e)).catch(e=>{throw Rr=null,e})),Rr)}function dw({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),uw().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 xl(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}`),Xi()}catch(l){n(String(l))}finally{i(!1)}}function hw({row:e}){const t=wr(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=qi(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 Ko="filter branches, PRs, people, tickets";function fw({col:e}){const{label:t,what:n}=ji[e],i=Ol.value,l=(i==null?void 0:i.key)===e,a=cg(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:()=>{Ol.value=a},children:[t,l?r("span",{class:"rq-sort-dir","aria-hidden":"true",children:i.dir==="asc"?"▲":"▼"}):null]})})}function pw({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:()=>Tu(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(hw,{row:e})}),r("td",{class:"rq-wt",children:o?`${o.stops} stop${o.stops===1?"":"s"} · ${ag(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:()=>xl("/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 Qn(`Ask the owning pane to merge ${e.branch}?`,{okLabel:"Merge"})&&xl("/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 Qn(`Remove the walkthrough and comments for ${e.branch}? This can't be undone.`,{okLabel:"Clear",danger:!0})&&xl("/api/reviews/clear",e,n,l)},children:"clear"}):null,t?r("span",{class:"rq-note",children:t}):null]})]})}function mw(){j(()=>{Xi()},[]);const e=gt.value;if(e===null)return r("div",{class:"wt-empty",children:"loading…"});const t=og(e,Ol.value),n=fs.value,i=ug(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:Ko,"aria-label":Ko,spellcheck:!1,autocomplete:"off",value:n,onInput:a=>{fs.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(ji).map(a=>r(fw,{col:a},a)),r("th",{})]})}),r("tbody",{children:i.map(a=>r(pw,{row:a},`${a.repo}/${a.branch}`))})]})]})}async function gw(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 Kd({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:pr(t.body,{demote:!1,softBreaks:"space"})})]},n))}):null}function yw({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 gw("/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 bw({stop:e,diffFiles:t,comments:n,repo:i,branch:l,hl:a,onPosted:s}){const[o,u]=B(!1),c=lg(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:pr(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(Wd,{hunk:m,lang:Ud(p.ref.path),hl:a,onOpen:null},b))]},h))]}):null,r(Kd,{list:n}),r(yw,{repo:i,branch:l,stop:e.title,onPosted:s})]})}function kw({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 Yi(()=>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),Xi()};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=rg(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(K,{children:[" · ",n!=null&&n.url&&n.number===b.header.pr?r("a",{class:`rq-pr-link ${qi(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(bw,{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(Kd,{list:C})]}):null]})}function ww({target:e,agent:t,onPaste:n,class:i="modal-xterm",id:l}){const a=te(null);return j(()=>(J1(a.current,e,{agent:t,onPaste:n}),ju),[]),r("div",{ref:a,id:l,class:i})}function vw(){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=yr(()=>{n(!1),l(""),G1()},[]);Fe(a,t);function s(o){o.preventDefault(),i&&(o.shiftKey?Gs(i):Vs(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&&Gs(i),children:"‹"}),r("button",{type:"button",class:"term-search-btn",title:"Next (Enter)",onClick:()=>i&&Vs(i),children:"›"}),r("button",{type:"button",class:"term-search-btn",title:"Close (Esc)",onClick:a,children:"✕"})]}):null}const Vd={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}},_w=.5;function xw(e,t,n){return Math.round(Math.min(Math.max(e,t),Math.max(t,n)))}function Sw(e,t,n,i){return xw(e+n.dir*t,n.min,i*_w)}function $w(e){return Number.isFinite(e)&&e>0?e:null}function Gd({which:e}){const t=Vd[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"),K1();const p=m=>{d=Sw(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"),V1(),d!==c&&Fs(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:()=>Fs(t.pref,t.def)})}function Cw(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 Tw(e){return(e==null?void 0:e.session_effort)||(e==null?void 0:e.launch_effort)||"default"}function Ew(e){var t;return e!=null&&e.model?e.model.replace(/\s*\(.*\)/,""):e!=null&&e.session_model?((t=or.find(n=>n.id===e.session_model))==null?void 0:t.label)||e.session_model:"model"}function Pw({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":Cw(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"?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=or.find(f=>f.id===t.model))==null?void 0:c.label)||t.model:Ew(e),u=t.effort||Tw(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}),or.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}`}),Ra.map(f=>r("option",{value:f,children:f},f))]})]})}const Aw=2e3;function Mw(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&&!zr.value[t]&&(zr.value={...zr.value,[t]:!0})}catch{}i&&(l=setTimeout(a,Aw))}return a(),()=>{i=!1,l&&clearTimeout(l)}},[e,t,n])}function Lw(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 Iw({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 Ow(e){const t=e.input||{};switch(e.name){case"Bash":return t.command||"";case"Write":return t.content||"";default:return""}}function Dw({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 Rw({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=Ow(e),u=!i&&e.result!=null&&e.result!=="",c=l||a||!!o||u,f=Lw(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(),br({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(Iw,{input:e.input||{}}):a?r(Dw,{input:e.input||{}}):o&&r("pre",{class:"tc-cmd",children:o}),u&&r("pre",{class:"tc-out",children:e.result})]})]})}function Fw({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:pr(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:pr(e.text)}),n.length>0&&r("div",{class:"turn-tools",children:n.map((i,l)=>r(Rw,{t:i},i.id||l))})]})}function Nw({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?${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 Bw({target:e,pid:t,selected:n,state:i,waitingFor:l,spinner:a}){var m;Mw(e,t,n);const s=((m=Ft.value[t])==null?void 0:m.messages)||[],o=te(null),u=te(null),c=te(!0),f=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!==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(K,{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(Fw,{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(Nw,{target:e,composerRef:u})]})}const zw=1500;function jw(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Hw({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 qw({pid:e,paneLabel:t}){const n=Be.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:jw(l.path)}),r("span",{class:"detail-tab-close",title:"Close tab",onClick:o=>{o.stopPropagation(),Ac(e,l.path)},children:"×"})]},a)})]})}function Vo(e){return(ce.value||[]).find(t=>t.pid===e)||null}function Jd(e){return(e==null?void 0:e.agent)!=="claude"?"terminal":gu(e.pid)||"terminal"}async function Uw(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||Ks(`\r +`);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 Ow(e){const t=e.input||{};switch(e.name){case"Bash":return t.command||"";case"Write":return t.content||"";default:return""}}function Dw({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 Rw({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=Ow(e),u=!i&&e.result!=null&&e.result!=="",c=l||a||!!o||u,f=Lw(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(),br({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(Iw,{input:e.input||{}}):a?r(Dw,{input:e.input||{}}):o&&r("pre",{class:"tc-cmd",children:o}),u&&r("pre",{class:"tc-out",children:e.result})]})]})}function Fw({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:pr(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:pr(e.text)}),n.length>0&&r("div",{class:"turn-tools",children:n.map((i,l)=>r(Rw,{t:i},i.id||l))})]})}function Nw({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?${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 Bw({target:e,pid:t,selected:n,state:i,waitingFor:l,spinner:a}){var m;Mw(e,t,n);const s=((m=Ft.value[t])==null?void 0:m.messages)||[],o=te(null),u=te(null),c=te(!0),f=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!==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(K,{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(Fw,{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(Nw,{target:e,composerRef:u})]})}const zw=1500;function jw(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Hw({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 qw({pid:e,paneLabel:t}){const n=Be.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:jw(l.path)}),r("span",{class:"detail-tab-close",title:"Close tab",onClick:o=>{o.stopPropagation(),Ac(e,l.path)},children:"×"})]},a)})]})}function Vo(e){return(ce.value||[]).find(t=>t.pid===e)||null}function Jd(e){return(e==null?void 0:e.agent)!=="claude"?"terminal":gu(e.pid)||"terminal"}async function Uw(e){var n;if(!nr.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(nr.value)}`,{method:"POST",headers:{"Content-Type":l.type||"image/png"},body:l})).json();s.ok||Ks(`\r \x1B[31m[periscope: image paste failed: ${s.error}]\x1B[0m`)}catch(a){Ks(`\r -\x1B[31m[periscope: image paste error: ${a.message}]\x1B[0m`)}return}}}function Ww({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=rr(e.repo_slug,e.pr),a=qi(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=wr(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(Pw,{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.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:`${sr(e.res.mem_mb)} mem · ${Pu(e.res.cpu_pct)} cpu`})]})),e.agent==="claude"&&e.mem){const l=hu(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"})]})),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 Kw({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,zw);return()=>{i=!1,clearInterval(a)}},[e]),t?r(cw,{data:t,onRefresh:()=>{},containerId:"detail-side",containerClass:"detail-side",idPrefix:"detail"}):r("aside",{id:"detail-side",class:"detail-side"})}function Vw({w:e}){const t=Jd(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(()=>(Hs(c=>{let f=c,d=null;const p=f.match(/^(.*?):(\d+)$/);p&&(f=p[1],d=p[2]),br({path:f,line:d})}),()=>Hs(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(vi));return()=>cancelAnimationFrame(c)},[t]);const[n,i]=B(!0);j(()=>{if(t!=="terminal")return;const c=()=>i(I1());c();const f=setInterval(c,250);return()=>clearInterval(f)},[t,e.pid]);const l=te(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=Be.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(Ww,{w:e}),r("div",{id:"detail-tab-bar",class:"detail-tab-bar",children:[r(qw,{pid:e.pid,paneLabel:u}),e.agent==="claude"&&r(Hw,{mode:t,onMode:c=>{ye("view.switch",{view:c}),ql(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(ww,{id:"detail-xterm",class:"detail-xterm",target:e.pane_id,agent:e.agent,onPaste:Uw},e.pid)}),r("div",{class:"detail-changes-host",style:s==="changes"?"display:contents":"display:none",children:r(Uk,{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(dw,{entry:c,active:d})},f)}),!bi.value&&r(Kw,{target:e.target},e.target),!bi.value&&r(Gd,{which:"side"})]}),o&&t==="terminal"&&!n&&r("button",{class:"term-scroll-bottom",title:"Scroll to latest",onClick:vi,children:"⤓"}),o&&t==="terminal"&&r(vw,{})]})}function Sl(){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 Gw(){var d,p;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)&&(tr.value=null)},[e]);const s=n?Vo(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=Jd(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(Sl,{}),n&&(s?r(Vw,{w:s}):r(Sl,{})),l&&r(mw,{}),i&&(gt.value===null?r("div",{class:"wt-empty",children:"loading…"}):a?r(kw,{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(Sl,{})),f.map(h=>{const m=Vo(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(Bw,{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 $l(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 ra=H(!1);function Cl(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 Tl(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 Jw(e,t){return!!t&&!!(e!=null&&e.branch)}function Qw(e,t){return`open ${e!=null&&e.branch?`${e.branch} `:""}worktree in ${t}`}const Yw=900;function Za(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 Zw(e){return e==="✓"?"ok":e==="✗"?"bad":e==="⟳"?"running":"neutral"}function Xw(e){return e?e.replace(/\s*\(.*$/,"").trim():null}function ev(e){return`${Math.round(e/1e3)}k`}function Rn(e){return e.context_pct!=null?`${e.context_pct}%`:e.ctx_tokens!=null?ev(e.ctx_tokens):null}function Qd({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 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 tv({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=_e(e),E=e.agent||(e.is_claude?"claude":null),A=Hl[E],T=e.status_rail||e.status_line,S=e.status_at&&Math.floor(Date.now()/1e3)-e.status_at>Yw,R=Xw(e.model),F=e.pr?rr(e.repo_slug,e.pr):null,q=hu(e.mem),L=d?wu(d,Math.floor(Date.now()/1e3)):null,I=$h(e),O=qi(e.pr_state),Q=`PR #${e.pr}${O.suffix}`,M=r(K,{children:["#",e.pr,e.ci&&!O.cls?r("span",{class:`pane-ci pane-ci-${Zw(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=wr(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 ${Co(e.profile)} profile — a different plugin set and system prompt than a normal pane`,children:Co(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(Qd,{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${Kl(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${Kl(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?"🔒":"🔓"}),Jw(e,m)&&r("button",{class:"rail-editor",title:Qw(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 nv({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 rv({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:Za(i)})]})}function Go({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 iv({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(Qd,{label:t,kind:"track",renameable:e!=="loose",onCommit:s}),r("span",{class:"repo-rule","aria-hidden":"true"}),r("span",{class:Za(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 Yd(e){const t=[...new Set((e||[]).map(n=>n.session).filter(Boolean))];return n=>du(n,t)}function zn(e,t){pu(e,!t)}function Zt(e){return`${e.kind}:${e.pid??e.id}`}function lv(){var A,T,S,R,F,q;me.value;const e=ce.value||[],t=Oa.value||[],n=nr.value,i=ft.value,l=lr(),a=Yd(e),s=Ma(e,t,n,i),o=l["sec:needs"]===!0,u=ku(e,t,n,pt.value),c=l["sec:ready"]===!0,f=xu(e),d=l["sec:running"]===!0,p=o1(Ta(),e),h=l["sec:pinned"]===!0,m=ra.value,b=te(null),x=Cl(s,(A=b.current)==null?void 0:A.needs,m,Zt),w=Cl(u,(T=b.current)==null?void 0:T.ready,m,Zt),C=Cl(f,(S=b.current)==null?void 0:S.running,m,Zt),y=Tl(s,(R=b.current)==null?void 0:R.needs,m,Zt)||Tl(u,(F=b.current)==null?void 0:F.ready,m,Zt)||Tl(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=Ns(ft.value,e,"needs-input");L.size!==ft.value.size&&(ft.value=L);const I=Ns(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),nr.value=I}function v(L){g(),Su(L)}function E(L){g(),Cu(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:l1(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:Ag((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:()=>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(K,{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:()=>st(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(K,{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:()=>st(L),children:[r("span",{class:`attn-ico ${((I=Hl[L.agent])==null?void 0:I.className)||""}`,children:((O=Hl[L.agent])==null?void 0:O.glyph)||"$"}),r("span",{class:"attn-label",children:$t(L,null,null,a)}),r("span",{class:Za(L.state),style:"margin-left:auto"})]},`pin:${L.pid}`)})]})]})}function av(){me.value;const e=Oa.value||[],t=lr(),n=Yd(ce.value||[]),i=c1(e),l=t["sec:activity"]!==!1;return r(K,{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 sv="";function ov(e){const t=window.__periscopeOpenLauncher;typeof t=="function"&&t(e)}function cv(e,t){return!t||t==="all"?e:e.filter(n=>n.track_id===t)}function uv({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 Jo=0;function dv(){if(Date.now()-Jo<5e3)return;const e=ce.value||[];if(e.length===0)return;Jo=Date.now();const t=Qa(e,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ir(),branchOrderByTrack:Ca()},Bt.value),n=gi(),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 Zd(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}=Qa(u,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:ir(),branchOrderByTrack:Ca()},m),y=lb(b,x,d,gt.value||[]);function g(M){if(M==="reviews"){Da();return}if(M.startsWith("review:")){const z=M.slice(7),k=z.indexOf("/"),W=(gt.value||[]).find(Z=>Z.repo===z.slice(0,k)&&Z.slug===z.slice(k+1));W&&Tu(W.repo,W.branch);return}ke.value=M,ye("pane.focus",{key:M}),M.startsWith("pane:")&&yt({kind:"pane",pid:M.slice(5)})}function $(M){const z=lr()[M]===!0;pu(M,!z)}async function v(M){await Jn(`Close tab "${_e(M)}"? +\x1B[31m[periscope: image paste error: ${a.message}]\x1B[0m`)}return}}}function Ww({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=ir(e.repo_slug,e.pr),a=qi(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=wr(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(Pw,{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.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 · ${Pu(e.res.cpu_pct)} cpu`})]})),e.agent==="claude"&&e.mem){const l=hu(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"})]})),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 Kw({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,zw);return()=>{i=!1,clearInterval(a)}},[e]),t?r(cw,{data:t,onRefresh:()=>{},containerId:"detail-side",containerClass:"detail-side",idPrefix:"detail"}):r("aside",{id:"detail-side",class:"detail-side"})}function Vw({w:e}){const t=Jd(e);j(()=>{nr.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(()=>(Hs(c=>{let f=c,d=null;const p=f.match(/^(.*?):(\d+)$/);p&&(f=p[1],d=p[2]),br({path:f,line:d})}),()=>Hs(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(vi));return()=>cancelAnimationFrame(c)},[t]);const[n,i]=B(!0);j(()=>{if(t!=="terminal")return;const c=()=>i(I1());c();const f=setInterval(c,250);return()=>clearInterval(f)},[t,e.pid]);const l=te(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=Be.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(Ww,{w:e}),r("div",{id:"detail-tab-bar",class:"detail-tab-bar",children:[r(qw,{pid:e.pid,paneLabel:u}),e.agent==="claude"&&r(Hw,{mode:t,onMode:c=>{ye("view.switch",{view:c}),ql(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(ww,{id:"detail-xterm",class:"detail-xterm",target:e.pane_id,agent:e.agent,onPaste:Uw},e.pid)}),r("div",{class:"detail-changes-host",style:s==="changes"?"display:contents":"display:none",children:r(Uk,{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(dw,{entry:c,active:d})},f)}),!bi.value&&r(Kw,{target:e.target},e.target),!bi.value&&r(Gd,{which:"side"})]}),o&&t==="terminal"&&!n&&r("button",{class:"term-scroll-bottom",title:"Scroll to latest",onClick:vi,children:"⤓"}),o&&t==="terminal"&&r(vw,{})]})}function Sl(){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 Gw(){var d,p;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)&&(nr.value=null)},[e]);const s=n?Vo(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=Jd(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(Sl,{}),n&&(s?r(Vw,{w:s}):r(Sl,{})),l&&r(mw,{}),i&&(gt.value===null?r("div",{class:"wt-empty",children:"loading…"}):a?r(kw,{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(Sl,{})),f.map(h=>{const m=Vo(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(Bw,{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 $l(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 ra=H(!1);function Cl(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 Tl(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 Jw(e,t){return!!t&&!!(e!=null&&e.branch)}function Qw(e,t){return`open ${e!=null&&e.branch?`${e.branch} `:""}worktree in ${t}`}const Yw=900;function Za(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 Zw(e){return e==="✓"?"ok":e==="✗"?"bad":e==="⟳"?"running":"neutral"}function Xw(e){return e?e.replace(/\s*\(.*$/,"").trim():null}function ev(e){return`${Math.round(e/1e3)}k`}function Fn(e){return e.context_pct!=null?`${e.context_pct}%`:e.ctx_tokens!=null?ev(e.ctx_tokens):null}function Qd({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 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 tv({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=_e(e),E=e.agent||(e.is_claude?"claude":null),A=Hl[E],T=e.status_rail||e.status_line,S=e.status_at&&Math.floor(Date.now()/1e3)-e.status_at>Yw,R=Xw(e.model),F=e.pr?ir(e.repo_slug,e.pr):null,q=hu(e.mem),L=d?wu(d,Math.floor(Date.now()/1e3)):null,I=$h(e),O=qi(e.pr_state),Q=`PR #${e.pr}${O.suffix}`,M=r(K,{children:["#",e.pr,e.ci&&!O.cls?r("span",{class:`pane-ci pane-ci-${Zw(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=wr(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 ${Co(e.profile)} profile — a different plugin set and system prompt than a normal pane`,children:Co(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(Qd,{label:v,kind:"pane",renameable:!0,onCommit:a}),C?R&&r("span",{class:"pane-model",title:e.model,children:R}):Fn(e)!=null&&r("span",{class:`pane-mini-ctx${Kl(e)}`,title:e.ctx_hint||"context window used",children:Fn(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||Fn(e)!=null||Z||_)&&r("div",{class:"pane-foot",children:[z,W,r("span",{class:"pane-foot-spacer"}),Z,_,Fn(e)!=null&&r("span",{class:`pane-pill pane-pill-ctx${Kl(e)}`,title:e.ctx_hint||"context window used",children:Fn(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?"🔒":"🔓"}),Jw(e,m)&&r("button",{class:"rail-editor",title:Qw(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 nv({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 rv({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:Za(i)})]})}function Go({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 iv({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(Qd,{label:t,kind:"track",renameable:e!=="loose",onCommit:s}),r("span",{class:"repo-rule","aria-hidden":"true"}),r("span",{class:Za(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 Yd(e){const t=[...new Set((e||[]).map(n=>n.session).filter(Boolean))];return n=>du(n,t)}function jn(e,t){pu(e,!t)}function Zt(e){return`${e.kind}:${e.pid??e.id}`}function lv(){var A,T,S,R,F,q;me.value;const e=ce.value||[],t=Oa.value||[],n=rr.value,i=ft.value,l=ar(),a=Yd(e),s=Ma(e,t,n,i),o=l["sec:needs"]===!0,u=ku(e,t,n,pt.value),c=l["sec:ready"]===!0,f=xu(e),d=l["sec:running"]===!0,p=o1(Ta(),e),h=l["sec:pinned"]===!0,m=ra.value,b=te(null),x=Cl(s,(A=b.current)==null?void 0:A.needs,m,Zt),w=Cl(u,(T=b.current)==null?void 0:T.ready,m,Zt),C=Cl(f,(S=b.current)==null?void 0:S.running,m,Zt),y=Tl(s,(R=b.current)==null?void 0:R.needs,m,Zt)||Tl(u,(F=b.current)==null?void 0:F.ready,m,Zt)||Tl(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=Ns(ft.value,e,"needs-input");L.size!==ft.value.size&&(ft.value=L);const I=Ns(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),rr.value=I}function v(L){g(),Su(L)}function E(L){g(),Cu(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:l1(x),collapsed:o,onToggle:()=>jn("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:Ag((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:()=>jn("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:()=>jn("sec:running",d)}),!d&&C.map(L=>{var I;return r("div",{class:"rail-row attn-row attn-running",onClick:()=>st(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(K,{children:[r(an,{icon:"★",label:"PINNED",count:p.length,collapsed:h,onToggle:()=>jn("sec:pinned",h)}),!h&&p.map(L=>{var I,O;return r("div",{class:"rail-row attn-row attn-pinned",onClick:()=>st(L),children:[r("span",{class:`attn-ico ${((I=Hl[L.agent])==null?void 0:I.className)||""}`,children:((O=Hl[L.agent])==null?void 0:O.glyph)||"$"}),r("span",{class:"attn-label",children:$t(L,null,null,a)}),r("span",{class:Za(L.state),style:"margin-left:auto"})]},`pin:${L.pid}`)})]})]})}function av(){me.value;const e=Oa.value||[],t=ar(),n=Yd(ce.value||[]),i=c1(e),l=t["sec:activity"]!==!1;return r(K,{children:[r(an,{label:"ACTIVITY",count:i.length||null,collapsed:l,onToggle:()=>jn("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 sv="";function ov(e){const t=window.__periscopeOpenLauncher;typeof t=="function"&&t(e)}function cv(e,t){return!t||t==="all"?e:e.filter(n=>n.track_id===t)}function uv({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 Jo=0;function dv(){if(Date.now()-Jo<5e3)return;const e=ce.value||[];if(e.length===0)return;Jo=Date.now();const t=Qa(e,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:lr(),branchOrderByTrack:Ca()},Bt.value),n=gi(),i=lr(),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 Zd(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}=Qa(u,Oi.value,Di.value,{trackOrder:gi(),tabsByTrack:lr(),branchOrderByTrack:Ca()},m),y=lb(b,x,d,gt.value||[]);function g(M){if(M==="reviews"){Da();return}if(M.startsWith("review:")){const z=M.slice(7),k=z.indexOf("/"),W=(gt.value||[]).find(Z=>Z.repo===z.slice(0,k)&&Z.slug===z.slice(k+1));W&&Tu(W.repo,W.branch);return}ke.value=M,ye("pane.focus",{key:M}),M.startsWith("pane:")&&yt({kind:"pane",pid:M.slice(5)})}function $(M){const z=ar()[M]===!0;pu(M,!z)}async function v(M){await Qn(`Close tab "${_e(M)}"? -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 mr("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 Jn(`${_} +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 mr("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 Qn(`${_} -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(_=>_e(_)),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(M,z,!0);return}kn(`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(_=>_e(_)),W=k.length?` • ${k.join(` -• `)}`:"";await Jn(`Tear down track "${z}"? +• `)}`:"";await Qn(`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(!Yo(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||!Yo(k,M))return;const W=z.currentTarget.getBoundingClientRect(),Z=z.clientY-W.top>W.height/2;if(k.kind==="track")await hv(k.key,M.key,Z);else{const _=M.kind==="track"?M.key.slice(6):M.trackKey;if(M.kind==="pane"&&k.trackKey===_)await fv(k.childKey,M.childKey,k.trackKey,Z);else{const X=d[k.childKey];X&&_&&await Qo(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 Qo(Z,M)}}}function Q(M,z){return M.map(k=>d[k]).filter(Boolean).map(k=>r(tv,{w:k,chip:ib(k),selectedKey:o,dim:$l(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:Ta().includes(k.pid),onTogglePin:()=>Jg(k.pid),onToggleNamePin:()=>S(k),editor:Tc.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:()=>{ra.value=!0},onMouseLeave:()=>{ra.value=!1},children:[r(lv,{}),r(uv,{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,_=Ci(M,u,h),X=x[M]||[],he=X.map(ue=>d[ue]).filter(Boolean),fe=he.map(ue=>ue.state||"shell"),qe=Eo(fe),Ae=he.length===0||he.some(ue=>$l(ue,s));return r(mv,{children:[r(iv,{kind:nb(M,u,h),label:_,collapsed:k,rolledUp:qe,dim:Ae,onToggle:()=>$(`repo:${M}`),onRename:ue=>R(M,ue),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(ue=>{var Tn,Sr;const Me=`${M}::${ue}`,vt=c[`wt:${Me}`]===!0,Gt=((Tn=C[M])==null?void 0:Tn[ue])||[],el=Q(Gt,M),tl=Gt.map(Ce=>d[Ce]).filter(Boolean).map(Ce=>Ce.state||"shell"),xr=Gt.map(Ce=>d[Ce]).filter(Boolean).some(Ce=>$l(Ce,s));return r("div",{class:"rail-subgroup",children:[r(rv,{label:ue===sv?"(no branch)":ue,collapsed:vt,childCount:Gt.length,rolledUp:Eo(tl),dim:xr,onToggle:()=>$(`wt:${Me}`),dragProps:{},dropPos:void 0}),!vt&&r("div",{class:"rail-group-body",children:[(((Sr=y[M])==null?void 0:Sr[ue])||[]).map(Ce=>r(Go,{row:Ce,selectedKey:o,onSelect:g},`review:${Ce.repo}/${Ce.slug}`)),el]})]},`wt:${Me}`)}):r(K,{children:[Object.values(y[M]||{}).flat().map(ue=>r("div",{class:"rail-group-body rail-review-head",children:r(Go,{row:ue,selectedKey:o,onSelect:g})},`review:${ue.repo}/${ue.slug}`)),r("div",{class:"rail-group-body",children:Q(X,M)})]}),r("div",{class:"rail-group-body rail-track-newtab",children:r(nv,{worktreeKey:M,onOpen:ov},`newtab:${M}`)})]})]},z)}),r(av,{})]})}function mv({children:e}){return r(K,{children:e})}function gv(){j(()=>{$k(),u1(),yk()},[]),j(()=>{document.body.dataset.view||(document.body.dataset.view="split")},[]);const e=te(null);return j(()=>{const t=Object.values(Vd).map(n=>{const i=Vt(()=>$w(Qg(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",Eu.value),(n=e.current)==null||n.toggleAttribute("data-side-hidden",bi.value)}),[]),r("div",{id:"split-view",ref:e,children:[r(pv,{}),r(Gd,{which:"rail"}),r(Gw,{})]})}function yv(){return r(K,{children:[r(B2,{}),r(gv,{}),r(Fb,{}),r(Eg,{}),r(G2,{})]})}async function bv(){await Ui(),ye("app.open"),lt(()=>{const t=document.documentElement.style;t.setProperty("--sans",ar("ui").stack),t.setProperty("--mono",ar("code").stack)});const e=jg();(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"),gh(r(yv,{}),document.getElementById("app")),X1(),q2(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})}bv();var Sv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $v(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}let ia=[],eh=[];(()=>{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=eh[i])t=i+1;else return!0;if(t==n)return!1}}function Zo(e){return e>=127462&&e<=127487}const Xo=8205;function Cv(e,t,n=!0,i=!0){return(n?th:wv)(e,t,i)}function th(e,t,n){if(t==e.length)return t;t&&nh(e.charCodeAt(t))&&rh(e.charCodeAt(t-1))&&t--;let i=El(e,t);for(t+=ec(i);t=0&&Zo(El(e,s));)a++,s-=2;if(a%2==0)break;t+=2}else break}return t}function wv(e,t,n){for(;t>0;){let i=th(e,t-2,n);if(i=56320&&e<57344}function rh(e){return e>=55296&&e<56320}function ec(e){return e<65536?1:2}const la="ͼ",tc=typeof Symbol>"u"?"__"+la:Symbol.for(la),aa=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),nc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Tv{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(` +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(!Yo(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||!Yo(k,M))return;const W=z.currentTarget.getBoundingClientRect(),Z=z.clientY-W.top>W.height/2;if(k.kind==="track")await hv(k.key,M.key,Z);else{const _=M.kind==="track"?M.key.slice(6):M.trackKey;if(M.kind==="pane"&&k.trackKey===_)await fv(k.childKey,M.childKey,k.trackKey,Z);else{const X=d[k.childKey];X&&_&&await Qo(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 Qo(Z,M)}}}function Q(M,z){return M.map(k=>d[k]).filter(Boolean).map(k=>r(tv,{w:k,chip:ib(k),selectedKey:o,dim:$l(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:Ta().includes(k.pid),onTogglePin:()=>Jg(k.pid),onToggleNamePin:()=>S(k),editor:Tc.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:()=>{ra.value=!0},onMouseLeave:()=>{ra.value=!1},children:[r(lv,{}),r(uv,{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,_=Ci(M,u,h),X=x[M]||[],he=X.map(ue=>d[ue]).filter(Boolean),fe=he.map(ue=>ue.state||"shell"),qe=Eo(fe),Ae=he.length===0||he.some(ue=>$l(ue,s));return r(mv,{children:[r(iv,{kind:nb(M,u,h),label:_,collapsed:k,rolledUp:qe,dim:Ae,onToggle:()=>$(`repo:${M}`),onRename:ue=>R(M,ue),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(ue=>{var En,Sr;const Me=`${M}::${ue}`,vt=c[`wt:${Me}`]===!0,Gt=((En=C[M])==null?void 0:En[ue])||[],el=Q(Gt,M),tl=Gt.map(Ce=>d[Ce]).filter(Boolean).map(Ce=>Ce.state||"shell"),xr=Gt.map(Ce=>d[Ce]).filter(Boolean).some(Ce=>$l(Ce,s));return r("div",{class:"rail-subgroup",children:[r(rv,{label:ue===sv?"(no branch)":ue,collapsed:vt,childCount:Gt.length,rolledUp:Eo(tl),dim:xr,onToggle:()=>$(`wt:${Me}`),dragProps:{},dropPos:void 0}),!vt&&r("div",{class:"rail-group-body",children:[(((Sr=y[M])==null?void 0:Sr[ue])||[]).map(Ce=>r(Go,{row:Ce,selectedKey:o,onSelect:g},`review:${Ce.repo}/${Ce.slug}`)),el]})]},`wt:${Me}`)}):r(K,{children:[Object.values(y[M]||{}).flat().map(ue=>r("div",{class:"rail-group-body rail-review-head",children:r(Go,{row:ue,selectedKey:o,onSelect:g})},`review:${ue.repo}/${ue.slug}`)),r("div",{class:"rail-group-body",children:Q(X,M)})]}),r("div",{class:"rail-group-body rail-track-newtab",children:r(nv,{worktreeKey:M,onOpen:ov},`newtab:${M}`)})]})]},z)}),r(av,{})]})}function mv({children:e}){return r(K,{children:e})}function gv(){j(()=>{$k(),u1(),yk()},[]),j(()=>{document.body.dataset.view||(document.body.dataset.view="split")},[]);const e=te(null);return j(()=>{const t=Object.values(Vd).map(n=>{const i=Vt(()=>$w(Qg(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",Eu.value),(n=e.current)==null||n.toggleAttribute("data-side-hidden",bi.value)}),[]),r("div",{id:"split-view",ref:e,children:[r(pv,{}),r(Gd,{which:"rail"}),r(Gw,{})]})}function yv(){return r(K,{children:[r(B2,{}),r(gv,{}),r(Fb,{}),r(Eg,{}),r(G2,{})]})}async function bv(){await Ui(),ye("app.open"),lt(()=>{const t=document.documentElement.style;t.setProperty("--sans",sr("ui").stack),t.setProperty("--mono",sr("code").stack)});const e=jg();(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"),gh(r(yv,{}),document.getElementById("app")),X1(),q2(),"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js",{scope:"/"}).catch(()=>{})}bv();var Sv=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $v(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}let ia=[],eh=[];(()=>{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=eh[i])t=i+1;else return!0;if(t==n)return!1}}function Zo(e){return e>=127462&&e<=127487}const Xo=8205;function Cv(e,t,n=!0,i=!0){return(n?th:wv)(e,t,i)}function th(e,t,n){if(t==e.length)return t;t&&nh(e.charCodeAt(t))&&rh(e.charCodeAt(t-1))&&t--;let i=El(e,t);for(t+=ec(i);t=0&&Zo(El(e,s));)a++,s-=2;if(a%2==0)break;t+=2}else break}return t}function wv(e,t,n){for(;t>0;){let i=th(e,t-2,n);if(i=56320&&e<57344}function rh(e){return e>=55296&&e<56320}function ec(e){return e<65536?1:2}const la="ͼ",tc=typeof Symbol>"u"?"__"+la:Symbol.for(la),aa=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),nc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Tv{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=nc[tc]||1;return nc[tc]=t+1,la+t.toString(36)}static mount(t,n,i){let l=t[aa],a=i&&i.nonce;l?a&&l.setNonce(a):l=new vv(t,a),l.mount(Array.isArray(n)?n:[n],t)}}let rc=new Map;class vv{constructor(t,n){let i=t.ownerDocument||t,l=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&l.CSSStyleSheet){let a=rc.get(i);if(a)return t[aa]=a;this.sheet=new l.CSSStyleSheet,rc.set(i,this)}else this.styleTag=i.createElement("style"),n&&this.styleTag.setAttribute("nonce",n);this.modules=[],t[aa]=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:'"'},_v=typeof navigator<"u"&&/Mac/.test(navigator.platform),xv=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 Pl in Wt)Pi.hasOwnProperty(Pl)||(Pi[Pl]=Wt[Pl]);function Ev(e){var t=_v&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||xv&&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,Tv as S,Yi as _,tr as a,Wt as b,Sv as c,B as d,ps as e,Cv as f,$v as g,K as h,Ev as k,br as o,pr as r,Pi as s,r as u,j as y}; +`;this.styleTag.textContent=s;let o=n.head||n;this.styleTag.parentNode!=o&&o.insertBefore(this.styleTag,o.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}var Wt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Pi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},_v=typeof navigator<"u"&&/Mac/.test(navigator.platform),xv=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 Pl in Wt)Pi.hasOwnProperty(Pl)||(Pi[Pl]=Wt[Pl]);function Ev(e){var t=_v&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||xv&&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,Tv as S,Yi as _,nr as a,Wt as b,Sv as c,B as d,ps as e,Cv as f,$v as g,K as h,Ev as k,br as o,pr as r,Pi as s,r as u,j as y}; From 2d0eb6cd32f9bdd0d3e109ddce16310a96ba1f27 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 08:28:17 -0400 Subject: [PATCH 28/52] tests: ruff-format the conftest machine stub (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- tests/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index f17c23e1..8903afc4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -96,7 +96,9 @@ def _no_live_resources(monkeypatch): monkeypatch.setattr(resources, "_responsible", lambda pid: 0) monkeypatch.setattr(resources, "_name", lambda pid: "") monkeypatch.setattr( - resources, "machine", lambda: {"load1": 0.0, "ram_mb": 0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 100} + resources, + "machine", + lambda: {"load1": 0.0, "ram_mb": 0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 100}, ) monkeypatch.setattr(resources, "_prev", {}) monkeypatch.setattr(resources, "_last", None) From d76784a4ef6e260d5bfe94446c0d909a7c2d558e Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:00:46 -0400 Subject: [PATCH 29/52] resources: _Sample.cpu_ns, not totals, and 'group' throughout (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- periscope/resources.py | 16 ++++++++-------- tests/test_resources.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/periscope/resources.py b/periscope/resources.py index 0bc6b24e..b0333f16 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -1,4 +1,4 @@ -"""Memory footprint and CPU per owner: each pane, the periscope server, its +"""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 @@ -140,7 +140,7 @@ def _sysctl(name: str, buf: ctypes.Structure | ctypes.c_int | ctypes.c_uint64) - 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 owners can + 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() @@ -184,7 +184,7 @@ def subtree(root: int) -> set[int]: @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 + cpu_ns: dict[tuple[int, int], int] # (pid, start) → cpu_ns, the group's members def _cpu_pct(prev: _Sample | None, cur: _Sample) -> float | None: @@ -197,13 +197,13 @@ def _cpu_pct(prev: _Sample | None, cur: _Sample) -> float | None: 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] + for ident, total in cur.cpu_ns.items(): + if ident in prev.cpu_ns: + delta += total - prev.cpu_ns[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: + for ident, total in prev.cpu_ns.items(): + if ident not in cur.cpu_ns: delta -= total return round(max(delta, 0) / (cur.at - prev.at) / _CORES * 100, 1) diff --git a/tests/test_resources.py b/tests/test_resources.py index 6787cb73..3f631cc6 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -1,4 +1,4 @@ -"""resources: footprint and CPU per owner. Everything except the smoke tests +"""resources: footprint and CPU per group. Everything except the smoke tests runs on fake snapshots and fake rusage readings.""" import os From 992283c363430186e66616efbb7ac2d8a3d8a04f Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:02:50 -0400 Subject: [PATCH 30/52] resources: build_state takes the tick's snapshot once, before the fan-out, and measure stamps its sample when it reads (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- periscope/resources.py | 22 +++++++--------- periscope/routes/state.py | 10 ++++--- tests/conftest.py | 10 +++---- tests/routes/test_state.py | 5 +++- tests/test_resources.py | 54 ++++++++++++++++++++++++-------------- 5 files changed, 60 insertions(+), 41 deletions(-) diff --git a/periscope/resources.py b/periscope/resources.py index b0333f16..dca536d2 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -15,7 +15,7 @@ import threading from dataclasses import dataclass -from periscope.agent_processes import ProcessInfo, descendants, process_snapshot +from periscope.agent_processes import ProcessInfo, descendants _u64 = ctypes.c_uint64 _RUSAGE_INFO_V1 = 1 @@ -221,22 +221,20 @@ class Measurement: _last: tuple[int, Measurement] | None = None -def measure(panes: dict[str, int]) -> Measurement | None: +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. None when this tick's process snapshot - failed: an empty tree would collapse every pane to its shell and read as - real.""" + 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: - now = _now() - if _last is not None and now - _last[0] < _MIN_INTERVAL_NS: + if _last is not None and _now() - _last[0] < _MIN_INTERVAL_NS: return _last[1] - # After the throttle: an expired snapshot cache would otherwise fork - # `ps` for a call that returns the previous measurement anyway. - snapshot = process_snapshot() - if snapshot is None: - return None 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} samples: dict[str, _Sample] = {} diff --git a/periscope/routes/state.py b/periscope/routes/state.py index 438042cb..175ed8e9 100644 --- a/periscope/routes/state.py +++ b/periscope/routes/state.py @@ -15,6 +15,7 @@ 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,9 +90,9 @@ def build_state() -> dict: result = [view for view, _ in built] annotate_cost_pressure(result) - # 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")}) + # 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 diff --git a/tests/conftest.py b/tests/conftest.py index 8903afc4..97fdd409 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -85,13 +85,13 @@ def _no_live_session_scan(monkeypatch): @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.""" + rusage reads, no sysctl. Every /api/state build takes a snapshot and + measures 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("periscope.routes.state.process_snapshot", dict) monkeypatch.setattr(resources, "_read", lambda pid: None) monkeypatch.setattr(resources, "_responsible", lambda pid: 0) monkeypatch.setattr(resources, "_name", lambda pid: "") diff --git a/tests/routes/test_state.py b/tests/routes/test_state.py index 128b6eae..281c78d0 100644 --- a/tests/routes/test_state.py +++ b/tests/routes/test_state.py @@ -424,9 +424,12 @@ def test_state_carries_each_panes_resources_and_the_totals(client, mocker, clean 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)) + snapshot = {4242: "the tick's snapshot"} + take = _patch(mocker, "process_snapshot", return_value=snapshot) body = client.get("/api/state").json() - measure.assert_called_once_with({"%7": 4242}) + take.assert_called_once_with() + measure.assert_called_once_with(snapshot, {"%7": 4242}) assert body["windows"][0]["res"] == group assert body["resources"] == totals diff --git a/tests/test_resources.py b/tests/test_resources.py index 3f631cc6..7ba666d5 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -184,7 +184,6 @@ def fake(monkeypatch): """A machine of _snapshot()'s processes, each 100 MB, CPU set per test.""" clock = _Clock() cpu = dict.fromkeys(_snapshot(), 0) - monkeypatch.setattr(resources, "process_snapshot", _snapshot) monkeypatch.setattr(resources, "_responsible", {600: 500}.get) monkeypatch.setattr(resources, "_name", lambda pid: {500: "periscope-app"}.get(pid, "")) monkeypatch.setattr(resources, "machine", lambda: MACHINE) @@ -199,7 +198,7 @@ def fake(monkeypatch): def test_measure_first_pass_has_memory_and_unknown_cpu(fake): - m = resources.measure(PANES) + m = resources.measure(_snapshot(), 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} @@ -210,10 +209,10 @@ def test_measure_first_pass_has_memory_and_unknown_cpu(fake): def test_measure_second_pass_has_cpu(fake): clock, cpu = fake - resources.measure(PANES) + resources.measure(_snapshot(), PANES) clock.t += S cpu[102] += S // 2 # the pane's tool child: half a core - m = resources.measure(PANES) + m = resources.measure(_snapshot(), 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 @@ -222,37 +221,52 @@ def test_measure_second_pass_has_cpu(fake): def test_measure_within_half_a_second_returns_the_previous_measurement(fake): clock, _ = fake - first = resources.measure(PANES) + first = resources.measure(_snapshot(), PANES) clock.t += S // 10 - assert resources.measure(PANES) is first + assert resources.measure(_snapshot(), PANES) is first -def test_measure_within_half_a_second_takes_no_snapshot(fake, monkeypatch): +def test_measure_within_half_a_second_reads_nothing(fake, monkeypatch): clock, _ = fake - resources.measure(PANES) - monkeypatch.setattr(resources, "process_snapshot", lambda: pytest.fail("snapshot taken inside the throttle")) + resources.measure(_snapshot(), PANES) + monkeypatch.setattr(resources, "_read", lambda pid: pytest.fail("read inside the throttle")) clock.t += S // 10 - resources.measure(PANES) + resources.measure(_snapshot(), PANES) + + +def test_measure_stamps_the_sample_when_it_reads(fake, monkeypatch): + # Assigning groups took a second: the reads, and so the sample, come after. + clock, cpu = fake + resources.measure(_snapshot(), PANES) + clock.t += S + + def slow_name(pid): + if pid == 1: + clock.t += S + return {500: "periscope-app"}.get(pid, "") + + monkeypatch.setattr(resources, "_name", slow_name) + cpu[102] += S # one core for the two seconds since the first sample + assert resources.measure(_snapshot(), PANES).panes["%1"]["cpu_pct"] == 50.0 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 + assert resources.measure(_snapshot(), 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_without_the_app_sends_no_webview(fake): + snapshot = {p: v for p, v in _snapshot().items() if p != 500} + assert resources.measure(snapshot, 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_is_none_when_the_snapshot_failed(fake): + assert resources.measure(None, 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)] + threads = [threading.Thread(target=lambda: out.append(resources.measure(_snapshot(), PANES))) for _ in range(8)] for t in threads: t.start() for t in threads: @@ -262,7 +276,7 @@ def test_measure_from_many_threads_at_once(fake): def test_measure_leaves_no_state_when_a_pass_fails(fake, monkeypatch): - resources.measure(PANES) + resources.measure(_snapshot(), PANES) clock, _ = fake clock.t += S prev_before, last_before = resources._prev, resources._last @@ -272,6 +286,6 @@ def boom(): monkeypatch.setattr(resources, "machine", boom) with pytest.raises(RuntimeError): - resources.measure(PANES) + resources.measure(_snapshot(), PANES) assert resources._prev == prev_before assert resources._last == last_before From e08581e0f0a55676c8196712385dd085a40ca948 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:04:13 -0400 Subject: [PATCH 31/52] resources: CPU is accounted per process across the tick, a reaped process charged to its parent's group, and a delta past every core is null (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- .../2026-10-30-resource-monitor-design.md | 27 ++++--- periscope/resources.py | 74 ++++++++++--------- tests/conftest.py | 2 +- tests/test_resources.py | 59 ++++++++++----- 4 files changed, 97 insertions(+), 65 deletions(-) diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index 404bc768..087db984 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -57,21 +57,25 @@ was rejected: it would need its own process table and a thread under `docs/testi **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. A process's CPU total is -its own time plus its reaped children's. A group's CPU over the interval is: -- for each member present in both samples, the change in its total; -- plus the whole total of a member that started after the previous sample; -- minus the last total of each member that vanished since the previous sample, because when it is reaped its whole - CPU time reappears in its parent's children time. -The result is clamped at 0: a vanished process reaped outside the group would otherwise subtract time the group -never gains back. This catches the short-lived `git`/`gh`/`tsc` runs that live less than a tick, which own-time -sampling would count as 0. +its own time plus its reaped children's. Accounting is per process across the whole machine, then summed per group: +- a process present in both samples counts the change in its total; +- a process that started after the previous sample counts its whole total; +- a process that vanished since the previous sample was reaped, and its whole CPU time reappears in its parent's + children time, so its last total comes off its parent (the parent pid it had in the previous snapshot), in + whichever group the parent sits now. A parent that is gone or unreadable (launchd, which reaps orphans) takes + nothing. +So a closed pane's shell, reaped by the tmux server, is charged to elsewhere where the server gained it, and its +orphaned claude (measured: the shell exits first and launchd reaps the claude) is charged to no one. A group's +result is clamped at 0 (a child orphaned after the previous sample, whose parent never gains it), and 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 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 10 s (a hub that idled with no subscribers) counts as -missing. With no usable previous sample, `cpu_pct` is `null`, never 0. A 0 is either measured idle or an interval D4 clamped (a member reaped -outside its group, e.g. a closed pane's shell). +missing. With no usable previous sample, or an impossible delta (D4), `cpu_pct` is `null`, never 0. A 0 is either +measured idle or an interval D4 clamped (a child orphaned before it exited). **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 @@ -120,7 +124,8 @@ there would disturb the CPU history of every other group. - `tests/test_resources.py`, over a fake snapshot and fake rusage: - group assignment, including a WebKit helper found by responsible pid and a process outside every group; - CPU: first sample (`null`), steady second sample, pid reuse, a child started after the previous sample, a child - that exits and is reaped by a member, a member reaped outside the group (clamped); + that exits and is reaped by its parent, a closed pane's shell reaped by the tmux server in another group, a + child its parent never reaped (clamped), a delta past every core (`null`); - the 0.5 s and 10 s rules, and two threads sampling at once; - a `None` snapshot; - one smoke test that reads the test process itself through the real `proc_pid_rusage`. diff --git a/periscope/resources.py b/periscope/resources.py index dca536d2..796c460a 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -184,28 +184,37 @@ def subtree(root: int) -> set[int]: @dataclass(frozen=True) class _Sample: at: int # ns, _now()'s clock - cpu_ns: dict[tuple[int, int], int] # (pid, start) → cpu_ns, the group's members + cpu_ns: dict[tuple[int, int], int] # (pid, start) → cpu_ns, every readable process + ppid: dict[int, int] # pid → parent pid, from the snapshot -def _cpu_pct(prev: _Sample | None, cur: _Sample) -> float | None: - """The group's share of the machine's CPU since `prev` (100 = every core +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 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.""" + A process that vanished was reaped, and its whole CPU time reappears in + its parent's children time, so its last total comes off the parent; an + orphan reaped by launchd (unreadable) comes off nothing. 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 None - delta = 0 - for ident, total in cur.cpu_ns.items(): - if ident in prev.cpu_ns: - delta += total - prev.cpu_ns[ident] - elif ident[1] > prev.at: # started since the previous sample - delta += total - for ident, total in prev.cpu_ns.items(): - if ident not in cur.cpu_ns: - delta -= total - return round(max(delta, 0) / (cur.at - prev.at) / _CORES * 100, 1) + return dict.fromkeys(groups) + delta: dict[int, int] = {} + for (pid, start), ns in cur.cpu_ns.items(): + if (pid, start) in prev.cpu_ns: + delta[pid] = ns - prev.cpu_ns[(pid, start)] + elif start > prev.at: # started since the previous sample + delta[pid] = ns + alive = {pid for pid, _ in cur.cpu_ns} + for (pid, start), ns in prev.cpu_ns.items(): + if (pid, start) not in cur.cpu_ns and (parent := prev.ppid[pid]) in alive: + delta[parent] = delta.get(parent, 0) - 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) + # Below 0: a child its parent never reaped (orphaned before it exited). + out[key] = None if ns > elapsed * _CORES else round(max(ns, 0) / elapsed / _CORES * 100, 1) + return out @dataclass(frozen=True) @@ -217,7 +226,7 @@ class Measurement: # 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 +_prev: _Sample | None = None _last: tuple[int, Measurement] | None = None @@ -236,21 +245,18 @@ def measure(snapshot: dict[int, ProcessInfo] | None, panes: dict[str, int]) -> M # 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} - samples: dict[str, _Sample] = {} - - 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()}) - samples[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 + cur = _Sample( + now, {(pid, r.start): r.cpu_ns for pid, r in readings.items()}, {pid: snapshot[pid].ppid for pid in readings} ) - _prev, _last = samples, (now, measurement) + 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, measurement) return measurement diff --git a/tests/conftest.py b/tests/conftest.py index 97fdd409..8a523261 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -100,7 +100,7 @@ def _no_live_resources(monkeypatch): "machine", lambda: {"load1": 0.0, "ram_mb": 0, "swap_used_mb": 0, "swap_total_mb": 0, "mem_free_pct": 100}, ) - monkeypatch.setattr(resources, "_prev", {}) + monkeypatch.setattr(resources, "_prev", None) monkeypatch.setattr(resources, "_last", None) diff --git a/tests/test_resources.py b/tests/test_resources.py index 7ba666d5..df0fc586 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -104,54 +104,75 @@ def test_assign_without_the_app_has_no_webview(monkeypatch): 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 _sample(at, *procs): + """A tick's sample of (pid, start, cpu_ns, ppid) processes.""" + return resources._Sample(at, {(pid, start): ns for pid, start, ns, _ in procs}, {p[0]: p[3] for p in procs}) + + +def _cpu(prev, cur, pids): + return resources._cpu_pcts(prev, cur, {"g": pids})["g"] def test_cpu_is_unknown_without_a_previous_sample(): - assert resources._cpu_pct(None, resources._Sample(S, {(1, 0): S})) is None + assert _cpu(None, _sample(S, (1, 0, S, 0)), {1}) is None def test_cpu_steady_process(): - assert _cpu(0, {(1, 0): S}, S, {(1, 0): S + S // 2}) == 50.0 + assert _cpu(_sample(0, (1, 0, S, 0)), _sample(S, (1, 0, S + S // 2, 0)), {1}) == 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 + assert _cpu(_sample(S), _sample(2 * S, (2, S + S // 2, S // 5, 1)), {2}) == 20.0 -def test_cpu_ignores_an_old_process_new_to_the_group(): +def test_cpu_ignores_an_old_process_new_to_the_sample(): # Started before the previous sample: its total isn't this interval's. - assert _cpu(S, {}, 2 * S, {(2, S // 2): 7 * S}) == 0.0 + assert _cpu(_sample(S), _sample(2 * S, (2, S // 2, 7 * S, 1)), {2}) == 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 + prev = _sample(0, (1, 0, S, 0), (2, 0, 3 * S // 10, 1)) + cur = _sample(S, (1, 0, S + 4 * S // 10 + S // 10, 0)) + assert _cpu(prev, cur, {1, 2}) == 20.0 + + +def test_cpu_charges_a_closed_panes_shell_to_its_reaper(): + # Pane %1 closes: tmux server 50 (elsewhere) reaps its shell 100 (2 s) and + # gains it, plus 0.1 s of its own. The shell's claude 101 (30 s) was + # orphaned to launchd, which isn't readable: it comes off nothing. + prev = _sample(0, (50, 0, S, 1), (100, 0, 2 * S, 50), (101, 0, 30 * S, 100)) + cur = _sample(S, (50, 0, 3 * S + S // 10, 1)) + assert _cpu(prev, cur, {1, 50}) == 10.0 + + +def test_cpu_clamps_a_child_its_parent_never_reaped(): + # Child 2 was orphaned before it exited: parent 1 never gains its 5 s. + prev = _sample(0, (1, 0, S, 0), (2, 0, 5 * S, 1)) + assert _cpu(prev, _sample(S, (1, 0, S + S // 10, 0)), {1}) == 0.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_is_unknown_past_every_core_for_the_whole_interval(): + # Two seconds of CPU in one second on one core came from outside it. + assert _cpu(_sample(0, (1, 0, 0, 0)), _sample(S, (1, 0, 2 * S, 0)), {1}) is None 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 + # pid 1 exited (5 s, reaped by 9) and a new pid 1 started since. + prev = _sample(S, (1, 0, 5 * S, 9), (9, 0, S, 0)) + cur = _sample(2 * S, (9, 0, 6 * S, 0), (1, S + S // 2, S // 10, 9)) + assert _cpu(prev, cur, {1, 9}) == 10.0 def test_cpu_is_a_share_of_every_core(monkeypatch): monkeypatch.setattr(resources, "_CORES", 10) # 2.5 cores busy for a second on a 10-core machine: a quarter of it. - assert _cpu(0, {(1, 0): 0}, S, {(1, 0): 5 * S // 2}) == 25.0 + assert _cpu(_sample(0, (1, 0, 0, 0)), _sample(S, (1, 0, 5 * S // 2, 0)), {1}) == 25.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 + assert _cpu(_sample(0, (1, 0, S, 0)), _sample(11 * S, (1, 0, 2 * S, 0)), {1}) is None # ── measure ────────────────────────────────────────────────────────────── @@ -161,7 +182,7 @@ def test_cpu_treats_a_stale_previous_sample_as_missing(): 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, "_prev", None) monkeypatch.setattr(resources, "_last", None) # One core, so the CPU cases read in whole-core terms. monkeypatch.setattr(resources, "_CORES", 1) From 66d9e86f08e97fb74ab87b3bae08ecedf4e14144 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:04:31 -0400 Subject: [PATCH 32/52] resources: the 0.5 s throttle reuses the previous measurement only for the same panes (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- .../specs/2026-10-30-resource-monitor-design.md | 2 +- periscope/resources.py | 11 ++++++----- tests/test_resources.py | 7 +++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index 087db984..1a495cfe 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -72,7 +72,7 @@ short-lived `git`/`gh`/`tsc` runs that live less than a tick, which own-time sam **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 gets the previous measurement back instead of a new delta (5 ms windows measured 0% +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 10 s (a hub that idled with no subscribers) counts as missing. With no usable previous sample, or an impossible delta (D4), `cpu_pct` is `null`, never 0. A 0 is either measured idle or an interval D4 clamped (a child orphaned before it exited). diff --git a/periscope/resources.py b/periscope/resources.py index 796c460a..9f633b02 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -29,7 +29,7 @@ _STALE_NS = 10 * 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 gets the previous measurement. +# 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 @@ -227,7 +227,7 @@ class Measurement: # once; the lock makes each read-diff-write of _prev whole. _lock = threading.Lock() _prev: _Sample | None = None -_last: tuple[int, Measurement] | 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: @@ -239,8 +239,9 @@ def measure(snapshot: dict[int, ProcessInfo] | None, panes: dict[str, int]) -> M if snapshot is None: return None with _lock: - if _last is not None and _now() - _last[0] < _MIN_INTERVAL_NS: - return _last[1] + # 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() @@ -258,5 +259,5 @@ def group(key: str) -> dict: 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, measurement) + _prev, _last = cur, (now, panes, measurement) return measurement diff --git a/tests/test_resources.py b/tests/test_resources.py index df0fc586..e853537d 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -247,6 +247,13 @@ def test_measure_within_half_a_second_returns_the_previous_measurement(fake): assert resources.measure(_snapshot(), PANES) is first +def test_measure_within_half_a_second_measures_a_new_pane(fake): + clock, _ = fake + resources.measure(_snapshot(), {"%1": 100}) + clock.t += S // 10 + assert resources.measure(_snapshot(), PANES).panes["%2"]["mem_mb"] == 100 + + def test_measure_within_half_a_second_reads_nothing(fake, monkeypatch): clock, _ = fake resources.measure(_snapshot(), PANES) From 28a9cafbe21eacc2503ac9f0436f0ef91ecc3424 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:04:49 -0400 Subject: [PATCH 33/52] resources: a previous sample goes stale after 60 s, not 10, so slow ticks on a loaded machine still read CPU (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- .../specs/2026-10-30-resource-monitor-design.md | 6 +++--- periscope/resources.py | 5 +++-- tests/test_resources.py | 7 ++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index 1a495cfe..a0825244 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -73,8 +73,8 @@ short-lived `git`/`gh`/`tsc` runs that live less than a tick, which own-time sam **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 10 s (a hub that idled with no subscribers) counts as -missing. With no usable previous sample, or an impossible delta (D4), `cpu_pct` is `null`, never 0. A 0 is either +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 an interval D4 clamped (a child orphaned before it exited). **D6 — The machine line reads the kernel directly, with no fork.** Load average from `os.getloadavg()`; physical RAM @@ -126,7 +126,7 @@ there would disturb the CPU history of every other group. - CPU: first sample (`null`), steady second sample, pid reuse, a child started after the previous sample, a child that exits and is reaped by its parent, a closed pane's shell reaped by the tmux server in another group, a child its parent never reaped (clamped), a delta past every core (`null`); - - the 0.5 s and 10 s rules, and two threads sampling at once; + - the 0.5 s and 60 s rules, and two threads sampling at once; - a `None` snapshot; - one smoke test that reads the test process itself through the real `proc_pid_rusage`. - `tests/test_window_view.py`: `mem_signal` on footprint, each tier and trigger (updating today's RSS cases). diff --git a/periscope/resources.py b/periscope/resources.py index 9f633b02..9810e018 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -25,8 +25,9 @@ _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. -_STALE_NS = 10 * 1_000_000_000 +# 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. diff --git a/tests/test_resources.py b/tests/test_resources.py index e853537d..58c26d00 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -171,8 +171,13 @@ def test_cpu_is_a_share_of_every_core(monkeypatch): assert _cpu(_sample(0, (1, 0, 0, 0)), _sample(S, (1, 0, 5 * S // 2, 0)), {1}) == 25.0 +def test_cpu_spans_a_slow_tick(): + # A loaded machine was measured at 3–28 s a tick. + assert _cpu(_sample(0, (1, 0, S, 0)), _sample(30 * S, (1, 0, 4 * S, 0)), {1}) == 10.0 + + def test_cpu_treats_a_stale_previous_sample_as_missing(): - assert _cpu(_sample(0, (1, 0, S, 0)), _sample(11 * S, (1, 0, 2 * S, 0)), {1}) is None + assert _cpu(_sample(0, (1, 0, S, 0)), _sample(61 * S, (1, 0, 2 * S, 0)), {1}) is None # ── measure ────────────────────────────────────────────────────────────── From 060cd1ad166354c3ec3db26ecf1e5c22256f2da8 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:05:17 -0400 Subject: [PATCH 34/52] session_status: an unreadable claude footprint is no live claude, so mem_signal's gb is always a number (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- .../specs/2026-10-30-resource-monitor-design.md | 3 ++- periscope/session_status.py | 13 ++++++++----- periscope/window_view.py | 6 +++--- tests/test_session_status.py | 7 +++++++ tests/test_window_view.py | 8 -------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index a0825244..23e4701e 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -84,7 +84,8 @@ from `sysctlbyname("hw.memsize")`; swap used and total from `vm.swapusage`; free **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; the chip sends `{tier, gb, age_s, trigger}` where `trigger` is `"mem"` or `"age"`, so +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. diff --git a/periscope/session_status.py b/periscope/session_status.py index e99d78b1..4afa8847 100644 --- a/periscope/session_status.py +++ b/periscope/session_status.py @@ -510,10 +510,10 @@ 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", "mem_mb", "age_s"}, or - None when unmapped or not a live claude. mem_mb is its footprint, None when - unreadable (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).""" + 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) @@ -526,7 +526,10 @@ def claude_proc_for(sid: str | None) -> dict | None: age = _claude_procs().get(pid) if age is None: return None - return {"pid": pid, "mem_mb": resources.footprint_mb(pid), "age_s": age} + 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 f60bc1c9..f1814506 100644 --- a/periscope/window_view.py +++ b/periscope/window_view.py @@ -231,14 +231,14 @@ def mem_signal(proc: dict | None) -> dict | None: if not proc: return None mb, age = proc["mem_mb"], proc["age_s"] - if mb is not None and mb >= MEM_WARN_MB: + if 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} + 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/tests/test_session_status.py b/tests/test_session_status.py index 1e236d7f..0bf9d47b 100644 --- a/tests/test_session_status.py +++ b/tests/test_session_status.py @@ -186,6 +186,13 @@ def test_claude_proc_for_returns_stats(tmp_path, monkeypatch): assert ss.claude_proc_for("sid-m") == {"pid": 300, "mem_mb": 4400, "age_s": 4 * 86400} +def test_claude_proc_for_unreadable_footprint_none(tmp_path, monkeypatch): + # Exited since the ps snapshot: the next tick drops it from _claude_procs. + _seed_procs(tmp_path, monkeypatch, _sess(303, "sid-x", "busy"), {303: 60}) + monkeypatch.setattr(ss.resources, "footprint_mb", lambda pid: None) + assert ss.claude_proc_for("sid-x") is None + + def test_claude_proc_for_dead_pid_none(tmp_path, monkeypatch): _seed_procs(tmp_path, monkeypatch, _sess(301, "sid-d", "busy"), {}) assert ss.claude_proc_for("sid-d") is None diff --git a/tests/test_window_view.py b/tests/test_window_view.py index a27ecb42..9fd4a072 100644 --- a/tests/test_window_view.py +++ b/tests/test_window_view.py @@ -831,14 +831,6 @@ def test_mem_signal_bad_overrides_warn(): 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} - - def test_view_surfaces_spawned_by_lineage(mocker, clean_state): """spawn_claude has recorded spawned_by since the tool shipped, but the payload never carried it — so a chain of delegated sessions rendered as From a4249630ca5169be747c0202cfc5a3dc4abfe1f0 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:08:42 -0400 Subject: [PATCH 35/52] tests: two measure callers forced to overlap, so the lock test fails without the lock (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- .../2026-10-30-resource-monitor-design.md | 2 +- tests/test_resources.py | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index 23e4701e..b8914620 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -127,7 +127,7 @@ there would disturb the CPU history of every other group. - CPU: first sample (`null`), steady second sample, pid reuse, a child started after the previous sample, a child that exits and is reaped by its parent, a closed pane's shell reaped by the tmux server in another group, a child its parent never reaped (clamped), a delta past every core (`null`); - - the 0.5 s and 60 s rules, and two threads sampling at once; + - 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; - one smoke test that reads the test process itself through the real `proc_pid_rusage`. - `tests/test_window_view.py`: `mem_signal` on footprint, each tier and trigger (updating today's RSS cases). diff --git a/tests/test_resources.py b/tests/test_resources.py index 58c26d00..526941ed 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -297,15 +297,29 @@ def test_measure_is_none_when_the_snapshot_failed(fake): assert resources.measure(None, PANES) is None -def test_measure_from_many_threads_at_once(fake): +def test_measure_from_two_threads_at_once(fake, monkeypatch): + # Without the lock both callers compute and meet at the barrier; with it + # the barrier times out alone and the second caller gets the first's result. + barrier = threading.Barrier(2, timeout=0.5) + computed = [] + + def machine(): + computed.append(1) + try: + barrier.wait() + except threading.BrokenBarrierError: + pass + return MACHINE + + monkeypatch.setattr(resources, "machine", machine) out = [] - threads = [threading.Thread(target=lambda: out.append(resources.measure(_snapshot(), PANES))) for _ in range(8)] + threads = [threading.Thread(target=lambda: out.append(resources.measure(_snapshot(), PANES))) for _ in range(2)] 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 + assert len(computed) == 1 + assert out[0] is out[1] def test_measure_leaves_no_state_when_a_pass_fails(fake, monkeypatch): From aa1aa96c0e2fed5ebb035f5d37ed79537459cc72 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:08:54 -0400 Subject: [PATCH 36/52] tests: the failed-pass test compares state by value, so an in-place change to it fails (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- tests/test_resources.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_resources.py b/tests/test_resources.py index 526941ed..39da9394 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -1,6 +1,7 @@ """resources: footprint and CPU per group. Everything except the smoke tests runs on fake snapshots and fake rusage readings.""" +import copy import os import threading @@ -326,7 +327,7 @@ def test_measure_leaves_no_state_when_a_pass_fails(fake, monkeypatch): resources.measure(_snapshot(), PANES) clock, _ = fake clock.t += S - prev_before, last_before = resources._prev, resources._last + prev_before, last_before = copy.deepcopy(resources._prev), copy.deepcopy(resources._last) def boom(): raise RuntimeError("boom") From a2cb793a8faf99881f668348c9817ea0964f7e16 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:09:10 -0400 Subject: [PATCH 37/52] tests: a server inside a pane's subtree is counted once, in server (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- tests/test_resources.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_resources.py b/tests/test_resources.py index 39da9394..3e028b65 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -91,6 +91,17 @@ def test_assign_puts_every_process_in_one_group(monkeypatch): assert named["elsewhere"] == {1, 700} +def test_assign_counts_a_server_inside_a_pane_once(monkeypatch): + # Periscope run from pane %1's shell: the server claims its subtree first. + monkeypatch.setattr(resources, "_responsible", {600: 500}.get) + monkeypatch.setattr(resources, "_name", lambda pid: {500: "periscope-app"}.get(pid, "")) + snapshot = _snapshot() | {SERVER: _proc(SERVER, 100, "/usr/bin/python3")} + named, per_pane = resources._assign(snapshot, {"%1": 100, "%2": 200}) + assert named["server"] == {SERVER, 900} + assert per_pane["%1"] == {100, 101, 102} + assert sum(len(pids) for pids in named.values()) == len(snapshot) + + def test_assign_without_the_app_has_no_webview(monkeypatch): monkeypatch.setattr(resources, "_responsible", lambda pid: pid) monkeypatch.setattr(resources, "_name", lambda pid: "") From 44263866467f288b1b18c94176298989bd6ecdd5 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:09:23 -0400 Subject: [PATCH 38/52] tests: a reaped child's CPU shows up in the real rusage read (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- tests/test_resources.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_resources.py b/tests/test_resources.py index 3e028b65..eb71f2b6 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -3,6 +3,8 @@ import copy import os +import subprocess +import sys import threading import pytest @@ -19,6 +21,15 @@ def test_read_measures_this_process(): assert 0 < r.start <= resources._now() +def test_read_counts_reaped_children(): + # A child that burned 0.2 s of CPU and was reaped shows up in our total: + # rusage_info_v1's child_* fields are where D4's reaped CPU comes from. + before = resources._read(os.getpid()).cpu_ns + burn = "import time\nt = time.process_time()\nwhile time.process_time() - t < 0.2: pass" + subprocess.run([sys.executable, "-c", burn], check=True) + assert resources._read(os.getpid()).cpu_ns - before >= 150_000_000 + + def test_read_gone_pid_is_none(): assert resources._read(99_999_999) is None From 7be98d2fd9ae96486b295f40c88f866f32ef85c1 Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:10:17 -0400 Subject: [PATCH 39/52] docs: resource monitor spec matches the rendered strings, one measured cost, the all-panes line and measure(snapshot, panes) (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- .../2026-10-30-resource-monitor-design.md | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md index b8914620..4d6a8caf 100644 --- a/docs/superpowers/specs/2026-10-30-resource-monitor-design.md +++ b/docs/superpowers/specs/2026-10-30-resource-monitor-design.md @@ -21,7 +21,8 @@ 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. +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 @@ -32,11 +33,13 @@ what Activity Monitor calls Memory and what the shell's recycle already uses. Re 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: ~3 µs per process, ~2 ms for every process on the machine. +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.** It reads -`agent_processes.process_snapshot()`, which the fan-out already takes every tick (`codex_process_for_pane`), so it -adds no subprocess while the fan-out finishes within the snapshot's 1 s cache; a slower tick forks one more `ps`. When the snapshot is `None` (a `ps` failure), `res` and `resources` are `null` for that tick +**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. @@ -93,14 +96,15 @@ liveness and age but drops `rss=`; moving liveness off `ps` belongs to THI-450. `periscope/resources.py`, stdlib plus `agent_processes` (itself stdlib-only) for the snapshot and `descendants`: -- `measure(panes)` → `Measurement | None`, given `{pane_id: pane_pid}`. It reads every process once, assigns each - to a group (D3), 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 failed. +- `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` calls `measure` after the fan-out and before the narrator merge. Each row gets `res`; the blob gets -`resources`. +`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. @@ -109,27 +113,32 @@ there would disturb the CPU history of every other group. - **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, 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`. RAM leads because footprints count - compressed and swapped pages: the owners can add up past it, and that overcommitment is what the line shows. +- **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 · 58% cpu` after the context %, for the selected pane. +- **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 `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/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 and a process outside every group; + - 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 child started after the previous sample, a child that exits and is reaped by its parent, a closed pane's shell reaped by the tmux server in another group, a child its parent never reaped (clamped), 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; - - one smoke test that reads the test process itself through the real `proc_pid_rusage`. + - 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 From 25a15edb330eca930b81380bdcdf54dfb78e619c Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:12:01 -0400 Subject: [PATCH 40/52] resources: ruff format, and contextlib.suppress in the lock test (THI-448) Co-Authored-By: Claude Opus 5.5 (1M context) --- periscope/resources.py | 4 +++- tests/test_resources.py | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/periscope/resources.py b/periscope/resources.py index 9810e018..c7ae54c5 100644 --- a/periscope/resources.py +++ b/periscope/resources.py @@ -248,7 +248,9 @@ def measure(snapshot: dict[int, ProcessInfo] | None, panes: dict[str, int]) -> M now = _now() readings = {pid: r for pid in snapshot if (r := _read(pid)) is not None} cur = _Sample( - now, {(pid, r.start): r.cpu_ns for pid, r in readings.items()}, {pid: snapshot[pid].ppid for pid in readings} + now, + {(pid, r.start): r.cpu_ns for pid, r in readings.items()}, + {pid: snapshot[pid].ppid for pid in readings}, ) groups = named | {f"pane:{pane_id}": pids for pane_id, pids in per_pane.items()} cpu = _cpu_pcts(_prev, cur, groups) diff --git a/tests/test_resources.py b/tests/test_resources.py index eb71f2b6..ce1f7ad2 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -1,6 +1,7 @@ """resources: footprint and CPU per group. Everything except the smoke tests runs on fake snapshots and fake rusage readings.""" +import contextlib import copy import os import subprocess @@ -328,10 +329,8 @@ def test_measure_from_two_threads_at_once(fake, monkeypatch): def machine(): computed.append(1) - try: + with contextlib.suppress(threading.BrokenBarrierError): barrier.wait() - except threading.BrokenBarrierError: - pass return MACHINE monkeypatch.setattr(resources, "machine", machine) From a1713bd9d990dd3cd28aaa77e4fa2697618c1b4e Mon Sep 17 00:00:00 2001 From: Thibault Dody Date: Sat, 31 Oct 2026 09:17:58 -0400 Subject: [PATCH 41/52] ui: extract usePopoverDismiss, share .pill-dd across the four header popovers (THI-448) ResourcePill, Header's Dropdown, FilterBar and UpdatePill each repeated open/Escape/outside-click wiring; ResourcePill also closed itself when the pill vanished instead of unmounting. Split ResourcePopover out so its open state unmounts with the pill, and replace .update-dd/.res-dd with one neutral .pill-dd class. Co-Authored-By: Claude Sonnet 5 --- static/src/chrome/FilterBar.jsx | 18 +++----------- static/src/chrome/Header.jsx | 12 ++-------- static/src/chrome/ResourcePill.jsx | 34 ++++++++++----------------- static/src/chrome/UpdatePill.jsx | 14 +++-------- static/src/hooks/usePopoverDismiss.js | 18 ++++++++++++++ static/styles.css | 8 +++---- 6 files changed, 43 insertions(+), 61 deletions(-) create mode 100644 static/src/hooks/usePopoverDismiss.js 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 2db90ed4..0a55cf75 100644 --- a/static/src/chrome/Header.jsx +++ b/static/src/chrome/Header.jsx @@ -14,7 +14,7 @@ // 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"; @@ -35,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 (
; } -export function ResourcePill() { +// 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 [open, setOpen] = useState(false); - const r = resources.value; const close = useCallback(() => setOpen(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 — returning null - // below doesn't unmount this component, so the open state would survive. - useEffect(() => { - if (!r && open) close(); - }, [r, open]); - if (!r) return null; + usePopoverDismiss(ref, open, close); return ( -
+
-