session-board 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- session_board-0.1.0/LICENSE +21 -0
- session_board-0.1.0/PKG-INFO +118 -0
- session_board-0.1.0/README.md +96 -0
- session_board-0.1.0/pyproject.toml +36 -0
- session_board-0.1.0/session_board/__init__.py +308 -0
- session_board-0.1.0/session_board/__main__.py +3 -0
- session_board-0.1.0/session_board/index.html +452 -0
- session_board-0.1.0/session_board.egg-info/PKG-INFO +118 -0
- session_board-0.1.0/session_board.egg-info/SOURCES.txt +11 -0
- session_board-0.1.0/session_board.egg-info/dependency_links.txt +1 -0
- session_board-0.1.0/session_board.egg-info/entry_points.txt +2 -0
- session_board-0.1.0/session_board.egg-info/top_level.txt +1 -0
- session_board-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Maxime U Garcia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: session-board
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local browser view of Claude Code and opencode sessions
|
|
5
|
+
Author: Maxime U Garcia
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/maxulysse/session-board
|
|
8
|
+
Project-URL: Issues, https://github.com/maxulysse/session-board/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/maxulysse/session-board/blob/main/CHANGELOG.md
|
|
10
|
+
Keywords: claude-code,opencode,dashboard,sessions
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Web Environment
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Software Development
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
<img src="https://raw.githubusercontent.com/maxulysse/session-board/main/logo.svg" width="96" alt="">
|
|
24
|
+
|
|
25
|
+
# session-board
|
|
26
|
+
|
|
27
|
+
Local browser view of Claude Code and opencode sessions on this machine: who is waiting on you, what is working, and what ran recently.
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
Linux or macOS, Python 3.10 or newer. No dependencies.
|
|
34
|
+
|
|
35
|
+
Try it without installing, with [uv](https://docs.astral.sh/uv/):
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
uvx session-board
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`uvx` reuses the copy it downloaded first; `uvx session-board@latest` gets the newest release.
|
|
42
|
+
|
|
43
|
+
Install the `session-board` command, with uv or [pipx](https://pipx.pypa.io/):
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
uv tool install session-board
|
|
47
|
+
pipx install session-board
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Update with `uv tool upgrade session-board` or `pipx upgrade session-board`; uninstall with `uv tool uninstall session-board` or `pipx uninstall session-board`.
|
|
51
|
+
|
|
52
|
+
Unreleased changes: `uvx --from git+https://github.com/maxulysse/session-board session-board`, or from a clone, no install needed:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
git clone https://github.com/maxulysse/session-board
|
|
56
|
+
cd session-board
|
|
57
|
+
python3 -m session_board
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
session-board # opens the board in your browser; Ctrl-C to stop
|
|
64
|
+
session-board --no-open --port 8765 --days 7
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- `--port N`: port to listen on; default, a free one
|
|
68
|
+
- `--days N`: how far back History goes; default 14
|
|
69
|
+
- `--no-open`: print the URL instead of opening a browser
|
|
70
|
+
|
|
71
|
+
On a remote machine, run `session-board --no-open --port 8765` there and `ssh -L 8765:127.0.0.1:8765 <host>` locally, then open the printed URL.
|
|
72
|
+
|
|
73
|
+
## What it reads
|
|
74
|
+
|
|
75
|
+
It reads, never writes:
|
|
76
|
+
|
|
77
|
+
- running Claude Code sessions: `<config>/sessions/*.json` (`pid`, `procStart`, `startedAt`, `status`, `cwd`)
|
|
78
|
+
- recent Claude Code transcripts: `<config>/projects/*/*.jsonl` (`ai-title` records, first prompt, `cwd`) and `<config>/projects/*/*/subagents/*.meta.json`
|
|
79
|
+
- opencode sessions: `$XDG_DATA_HOME/opencode/opencode.db` (default `~/.local/share`), read-only
|
|
80
|
+
|
|
81
|
+
`<config>` is every `~/.claude*` folder and `$CLAUDE_CONFIG_DIR`.
|
|
82
|
+
These are Claude Code's internal files, last checked with Claude Code 2.1.334; a missing field shows less on the board but never stops it.
|
|
83
|
+
On macOS, a crashed session whose PID a new process reuses can show as running: the PID-reuse check needs Linux's `/proc`.
|
|
84
|
+
|
|
85
|
+
The server listens on `127.0.0.1` only. Every request needs the random key in the printed URL.
|
|
86
|
+
|
|
87
|
+
## The board
|
|
88
|
+
|
|
89
|
+
The page refreshes every 5 s while its tab is visible. Pick what to show (**Now** or **History**) and how (**Map** or **Kanban**); the URL hash keeps the choice, e.g. `#history/kanban`.
|
|
90
|
+
|
|
91
|
+
- **Now**: running sessions. Sessions that are not `busy` or running a shell command are waiting on you (amber, pulsing). Subagents show as small dots, blue while they run.
|
|
92
|
+
- **History**: sessions of the last `--days` that are no longer running, fading with age.
|
|
93
|
+
- **Map**: one graph of everything: projects (the outermost git work tree around the session's folder, so a checkout nested inside a repo joins it) on a ring, their sessions fanned out behind them. The side table lists projects: click a column to sort, again to reverse; click a project for its details.
|
|
94
|
+
- **Kanban**: one card per session. Now has columns waiting on you and working; History has today, yesterday, this week and older.
|
|
95
|
+
|
|
96
|
+

|
|
97
|
+
|
|
98
|
+
The tab icon counts the sessions waiting on you (amber), turns green when none wait, and grey on History.
|
|
99
|
+
|
|
100
|
+
The filter box keeps sessions whose title, project or folder contains its text. The sun/moon switch picks a light or dark theme; until you use it, the page follows the system.
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
Both files live in `$XDG_CONFIG_HOME/session-board/` (default `~/.config/session-board/`), are optional, and are read on every refresh.
|
|
105
|
+
|
|
106
|
+
Renamed a folder? Map the old path to the new one in `aliases.json`, and its old sessions join the new project:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{ "~/workspace/old-name": "~/workspace/new-name" }
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Hide sessions in `ignore.json`: folder patterns, matched after aliases (a folder includes its subfolders), and session ids, shown in each session's tooltip:
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{ "folders": ["~/workspace/tmp-*"], "sessions": ["<session id>"] }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Tests: `python3 -m unittest`
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<img src="https://raw.githubusercontent.com/maxulysse/session-board/main/logo.svg" width="96" alt="">
|
|
2
|
+
|
|
3
|
+
# session-board
|
|
4
|
+
|
|
5
|
+
Local browser view of Claude Code and opencode sessions on this machine: who is waiting on you, what is working, and what ran recently.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Linux or macOS, Python 3.10 or newer. No dependencies.
|
|
12
|
+
|
|
13
|
+
Try it without installing, with [uv](https://docs.astral.sh/uv/):
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
uvx session-board
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`uvx` reuses the copy it downloaded first; `uvx session-board@latest` gets the newest release.
|
|
20
|
+
|
|
21
|
+
Install the `session-board` command, with uv or [pipx](https://pipx.pypa.io/):
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
uv tool install session-board
|
|
25
|
+
pipx install session-board
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Update with `uv tool upgrade session-board` or `pipx upgrade session-board`; uninstall with `uv tool uninstall session-board` or `pipx uninstall session-board`.
|
|
29
|
+
|
|
30
|
+
Unreleased changes: `uvx --from git+https://github.com/maxulysse/session-board session-board`, or from a clone, no install needed:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
git clone https://github.com/maxulysse/session-board
|
|
34
|
+
cd session-board
|
|
35
|
+
python3 -m session_board
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
session-board # opens the board in your browser; Ctrl-C to stop
|
|
42
|
+
session-board --no-open --port 8765 --days 7
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- `--port N`: port to listen on; default, a free one
|
|
46
|
+
- `--days N`: how far back History goes; default 14
|
|
47
|
+
- `--no-open`: print the URL instead of opening a browser
|
|
48
|
+
|
|
49
|
+
On a remote machine, run `session-board --no-open --port 8765` there and `ssh -L 8765:127.0.0.1:8765 <host>` locally, then open the printed URL.
|
|
50
|
+
|
|
51
|
+
## What it reads
|
|
52
|
+
|
|
53
|
+
It reads, never writes:
|
|
54
|
+
|
|
55
|
+
- running Claude Code sessions: `<config>/sessions/*.json` (`pid`, `procStart`, `startedAt`, `status`, `cwd`)
|
|
56
|
+
- recent Claude Code transcripts: `<config>/projects/*/*.jsonl` (`ai-title` records, first prompt, `cwd`) and `<config>/projects/*/*/subagents/*.meta.json`
|
|
57
|
+
- opencode sessions: `$XDG_DATA_HOME/opencode/opencode.db` (default `~/.local/share`), read-only
|
|
58
|
+
|
|
59
|
+
`<config>` is every `~/.claude*` folder and `$CLAUDE_CONFIG_DIR`.
|
|
60
|
+
These are Claude Code's internal files, last checked with Claude Code 2.1.334; a missing field shows less on the board but never stops it.
|
|
61
|
+
On macOS, a crashed session whose PID a new process reuses can show as running: the PID-reuse check needs Linux's `/proc`.
|
|
62
|
+
|
|
63
|
+
The server listens on `127.0.0.1` only. Every request needs the random key in the printed URL.
|
|
64
|
+
|
|
65
|
+
## The board
|
|
66
|
+
|
|
67
|
+
The page refreshes every 5 s while its tab is visible. Pick what to show (**Now** or **History**) and how (**Map** or **Kanban**); the URL hash keeps the choice, e.g. `#history/kanban`.
|
|
68
|
+
|
|
69
|
+
- **Now**: running sessions. Sessions that are not `busy` or running a shell command are waiting on you (amber, pulsing). Subagents show as small dots, blue while they run.
|
|
70
|
+
- **History**: sessions of the last `--days` that are no longer running, fading with age.
|
|
71
|
+
- **Map**: one graph of everything: projects (the outermost git work tree around the session's folder, so a checkout nested inside a repo joins it) on a ring, their sessions fanned out behind them. The side table lists projects: click a column to sort, again to reverse; click a project for its details.
|
|
72
|
+
- **Kanban**: one card per session. Now has columns waiting on you and working; History has today, yesterday, this week and older.
|
|
73
|
+
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+
The tab icon counts the sessions waiting on you (amber), turns green when none wait, and grey on History.
|
|
77
|
+
|
|
78
|
+
The filter box keeps sessions whose title, project or folder contains its text. The sun/moon switch picks a light or dark theme; until you use it, the page follows the system.
|
|
79
|
+
|
|
80
|
+
## Configuration
|
|
81
|
+
|
|
82
|
+
Both files live in `$XDG_CONFIG_HOME/session-board/` (default `~/.config/session-board/`), are optional, and are read on every refresh.
|
|
83
|
+
|
|
84
|
+
Renamed a folder? Map the old path to the new one in `aliases.json`, and its old sessions join the new project:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{ "~/workspace/old-name": "~/workspace/new-name" }
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Hide sessions in `ignore.json`: folder patterns, matched after aliases (a folder includes its subfolders), and session ids, shown in each session's tooltip:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{ "folders": ["~/workspace/tmp-*"], "sessions": ["<session id>"] }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Tests: `python3 -m unittest`
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "session-board"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Local browser view of Claude Code and opencode sessions"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Maxime U Garcia" }]
|
|
13
|
+
keywords = ["claude-code", "opencode", "dashboard", "sessions"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Environment :: Web Environment",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: MacOS",
|
|
19
|
+
"Operating System :: POSIX :: Linux",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Topic :: Software Development",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/maxulysse/session-board"
|
|
26
|
+
Issues = "https://github.com/maxulysse/session-board/issues"
|
|
27
|
+
Changelog = "https://github.com/maxulysse/session-board/blob/main/CHANGELOG.md"
|
|
28
|
+
|
|
29
|
+
[project.scripts]
|
|
30
|
+
session-board = "session_board:main"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools]
|
|
33
|
+
packages = ["session_board"]
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.package-data]
|
|
36
|
+
session_board = ["index.html"]
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"""Local browser view of Claude Code and opencode sessions.
|
|
2
|
+
|
|
3
|
+
session-board [--port N] [--days N] [--no-open]
|
|
4
|
+
|
|
5
|
+
Reads only local files: live sessions from <config>/sessions/*.json and transcripts
|
|
6
|
+
from <config>/projects, for ~/.claude* and $CLAUDE_CONFIG_DIR; opencode sessions from its SQLite DB
|
|
7
|
+
(read-only). Serves one page on 127.0.0.1; every request needs the random key
|
|
8
|
+
printed in the URL.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import glob
|
|
13
|
+
import hmac
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import secrets
|
|
17
|
+
import sqlite3
|
|
18
|
+
import sys
|
|
19
|
+
import time
|
|
20
|
+
import webbrowser
|
|
21
|
+
from contextlib import closing
|
|
22
|
+
from fnmatch import fnmatch
|
|
23
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from urllib.parse import parse_qs, urlsplit
|
|
26
|
+
|
|
27
|
+
HOME = Path.home()
|
|
28
|
+
PAGE = Path(__file__).with_name("index.html")
|
|
29
|
+
OPENCODE_DB = Path(os.environ.get("XDG_DATA_HOME") or HOME / ".local/share") / "opencode/opencode.db"
|
|
30
|
+
CONFIG = Path(os.environ.get("XDG_CONFIG_HOME") or HOME / ".config") / "session-board"
|
|
31
|
+
ALIASES = CONFIG / "aliases.json"
|
|
32
|
+
IGNORE = CONFIG / "ignore.json"
|
|
33
|
+
_title_cache = {}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def start_time(pid):
|
|
37
|
+
"""Process start time, field 22 of /proc/<pid>/stat; Claude Code records it as procStart."""
|
|
38
|
+
return Path(f"/proc/{pid}/stat").read_text().rsplit(")", 1)[1].split()[19]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def pid_alive(pid, proc_start=None):
|
|
42
|
+
"""True if pid runs. On Linux it must also be the session's process: a crashed session's PID can be reused."""
|
|
43
|
+
if Path("/proc/self").exists():
|
|
44
|
+
try:
|
|
45
|
+
if proc_start:
|
|
46
|
+
return start_time(pid) == str(proc_start)
|
|
47
|
+
return b"claude" in Path(f"/proc/{pid}/cmdline").read_bytes()
|
|
48
|
+
except OSError:
|
|
49
|
+
return False
|
|
50
|
+
try:
|
|
51
|
+
os.kill(pid, 0)
|
|
52
|
+
except ProcessLookupError:
|
|
53
|
+
return False
|
|
54
|
+
except PermissionError: # runs, under another user
|
|
55
|
+
pass
|
|
56
|
+
return True
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def live_claude(config_dirs):
|
|
60
|
+
"""Running Claude Code sessions, from each config dir's sessions/*.json."""
|
|
61
|
+
out = []
|
|
62
|
+
for cfg in config_dirs:
|
|
63
|
+
for f in glob.glob(str(cfg / "sessions/*.json")):
|
|
64
|
+
try:
|
|
65
|
+
d = json.loads(Path(f).read_text())
|
|
66
|
+
except (OSError, ValueError):
|
|
67
|
+
continue
|
|
68
|
+
if not isinstance(d.get("pid"), int) or not pid_alive(d["pid"], d.get("procStart")):
|
|
69
|
+
continue
|
|
70
|
+
changed = d.get("statusUpdatedAt") or d.get("updatedAt")
|
|
71
|
+
out.append({
|
|
72
|
+
"tool": "claude", "account": cfg.name.lstrip("."), "id": d.get("sessionId"),
|
|
73
|
+
"name": d.get("name"), "cwd": d.get("cwd"),
|
|
74
|
+
"state": "working" if d.get("status") in ("busy", "shell") else "waiting",
|
|
75
|
+
"time": changed / 1000 if changed else None, "started": (d.get("startedAt") or 0) / 1000,
|
|
76
|
+
})
|
|
77
|
+
return out
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def transcript_info(path):
|
|
81
|
+
"""Title and cwd of one transcript."""
|
|
82
|
+
title = first_prompt = cwd = None
|
|
83
|
+
with open(path, encoding="utf-8", errors="replace") as fh:
|
|
84
|
+
for line in fh:
|
|
85
|
+
# cheap substring test first: most lines are never parsed (~30 ms for a 60 MB transcript)
|
|
86
|
+
if '"ai-title"' not in line and (first_prompt or '"user"' not in line):
|
|
87
|
+
continue
|
|
88
|
+
try:
|
|
89
|
+
d = json.loads(line)
|
|
90
|
+
except ValueError:
|
|
91
|
+
continue
|
|
92
|
+
if d.get("type") == "ai-title":
|
|
93
|
+
title = d.get("aiTitle") or title
|
|
94
|
+
elif d.get("type") == "user" and not d.get("isSidechain"):
|
|
95
|
+
cwd = cwd or d.get("cwd")
|
|
96
|
+
content = (d.get("message") or {}).get("content")
|
|
97
|
+
# tool results and injected <command-...> blocks are not prompts
|
|
98
|
+
if isinstance(content, str) and content.strip() and not content.startswith("<"):
|
|
99
|
+
first_prompt = content.strip().splitlines()[0][:100]
|
|
100
|
+
return {"title": title or first_prompt, "cwd": cwd}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def recent_claude(projects, since):
|
|
104
|
+
"""Top-level transcripts touched after `since` (subagent transcripts live in subfolders).
|
|
105
|
+
|
|
106
|
+
Titles are cached by mtime and size; the cache holds only this scan's transcripts."""
|
|
107
|
+
global _title_cache
|
|
108
|
+
out = []
|
|
109
|
+
cache = {}
|
|
110
|
+
for d in projects:
|
|
111
|
+
for f in glob.glob(str(d / "*/*.jsonl")):
|
|
112
|
+
path = Path(f)
|
|
113
|
+
try:
|
|
114
|
+
st = path.stat()
|
|
115
|
+
if st.st_mtime < since:
|
|
116
|
+
continue
|
|
117
|
+
stamp = (st.st_mtime, st.st_size)
|
|
118
|
+
hit = _title_cache.get(path)
|
|
119
|
+
cache[path] = hit if hit and hit[0] == stamp else (stamp, transcript_info(path))
|
|
120
|
+
except OSError: # deleted by Claude Code's cleanup since the glob, or unreadable
|
|
121
|
+
continue
|
|
122
|
+
info = cache[path][1]
|
|
123
|
+
out.append({"tool": "claude", "id": path.stem, "name": info["title"], "cwd": info["cwd"],
|
|
124
|
+
"state": "recent", "time": st.st_mtime})
|
|
125
|
+
_title_cache = cache
|
|
126
|
+
return out
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def claude_subagents(projects, since, live):
|
|
130
|
+
"""Parent session id -> its subagents, from <project>/<session>/subagents/*.meta.json.
|
|
131
|
+
|
|
132
|
+
"finished" appears only once an agent ends, and a session that died mid-agent never writes it:
|
|
133
|
+
an agent runs if it has no "finished", its session is in `live` (id -> process start), and it wrote since
|
|
134
|
+
that start: a resumed session keeps the id of its dead run's agents."""
|
|
135
|
+
out = {}
|
|
136
|
+
for d in projects:
|
|
137
|
+
for f in glob.glob(str(d / "*/*/subagents/agent-*.meta.json")):
|
|
138
|
+
path = Path(f)
|
|
139
|
+
try:
|
|
140
|
+
mtime = path.with_name(path.name.replace(".meta.json", ".jsonl")).stat().st_mtime
|
|
141
|
+
if mtime < since:
|
|
142
|
+
continue
|
|
143
|
+
meta = json.loads(path.read_text())
|
|
144
|
+
except (OSError, ValueError):
|
|
145
|
+
continue
|
|
146
|
+
parent = path.parent.parent.name
|
|
147
|
+
out.setdefault(parent, []).append({
|
|
148
|
+
"type": meta.get("agentType"), "description": meta.get("description"),
|
|
149
|
+
"running": parent in live and mtime >= live[parent] and not meta.get("finished")})
|
|
150
|
+
return out
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def claude_sessions(config_dirs, since):
|
|
154
|
+
"""Running sessions, then the other recent ones, with transcript titles and subagents."""
|
|
155
|
+
# ~/.claude-pro/projects may be a symlink to ~/.claude/projects: scan each folder once
|
|
156
|
+
projects = list(dict.fromkeys((cfg / "projects").resolve() for cfg in config_dirs))
|
|
157
|
+
recent = {s["id"]: s for s in recent_claude(projects, since)}
|
|
158
|
+
sessions = live_claude(config_dirs)
|
|
159
|
+
agents = claude_subagents(projects, since, {s["id"]: s.pop("started") for s in sessions})
|
|
160
|
+
for s in sessions:
|
|
161
|
+
s["name"] = recent.pop(s["id"], {}).get("name") or s["name"]
|
|
162
|
+
sessions += recent.values()
|
|
163
|
+
for s in sessions:
|
|
164
|
+
s["agents"] = agents.get(s["id"], [])
|
|
165
|
+
return sessions
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def recent_opencode(db, since):
|
|
169
|
+
if not db.is_file():
|
|
170
|
+
return []
|
|
171
|
+
try: # a lock, or a schema change in a new opencode version, must not break the board
|
|
172
|
+
with closing(sqlite3.connect(f"file:{db}?mode=ro", uri=True, timeout=1)) as con:
|
|
173
|
+
tables = {r[0] for r in con.execute("select name from sqlite_master where type='table'")}
|
|
174
|
+
union = " union all ".join(f"select id, parent_id, title, directory, time_updated from {t}"
|
|
175
|
+
for t in ("session", "session_v2") if t in tables)
|
|
176
|
+
# a session in both tables: max() picks the newer row's columns
|
|
177
|
+
rows = con.execute(f"select id, parent_id, title, directory, max(time_updated) from ({union}) "
|
|
178
|
+
"where time_updated >= ? group by id", (int(since * 1000),)).fetchall()
|
|
179
|
+
except sqlite3.Error:
|
|
180
|
+
return []
|
|
181
|
+
children = {}
|
|
182
|
+
for _, parent, title, _, _ in rows:
|
|
183
|
+
if parent is not None:
|
|
184
|
+
children.setdefault(parent, []).append(title)
|
|
185
|
+
return [{"tool": "opencode", "id": sid, "name": title, "cwd": directory, "state": "recent",
|
|
186
|
+
"time": updated / 1000,
|
|
187
|
+
"agents": [{"type": "subsession", "description": t, "running": False} for t in children.get(sid, [])]}
|
|
188
|
+
for sid, parent, title, directory, updated in rows if parent is None]
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def read_config(path, default):
|
|
192
|
+
"""JSON from path, or default when the file is missing, broken or of another type."""
|
|
193
|
+
try:
|
|
194
|
+
raw = json.loads(path.read_text())
|
|
195
|
+
except (OSError, ValueError):
|
|
196
|
+
return default
|
|
197
|
+
return raw if isinstance(raw, type(default)) else default
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def load_aliases(path=ALIASES):
|
|
201
|
+
"""{"~/old/folder": "~/new/folder"}: sessions under a renamed folder count as the new one."""
|
|
202
|
+
return {os.path.expanduser(k).rstrip("/"): os.path.expanduser(v).rstrip("/")
|
|
203
|
+
for k, v in read_config(path, {}).items() if isinstance(v, str)}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def apply_alias(cwd, aliases):
|
|
207
|
+
for old in sorted(aliases, key=len, reverse=True): # the most specific alias wins
|
|
208
|
+
if cwd == old or cwd.startswith(old + "/"):
|
|
209
|
+
return aliases[old] + cwd[len(old):]
|
|
210
|
+
return cwd
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def load_ignore(path=IGNORE):
|
|
214
|
+
"""{"folders": ["~/workspace/tmp-*"], "sessions": ["<session id>"]}: a test for sessions to leave off the board.
|
|
215
|
+
|
|
216
|
+
The test takes a session id and its folder after aliases; a folder pattern also covers its subfolders."""
|
|
217
|
+
raw = read_config(path, {})
|
|
218
|
+
strings = lambda v: [x for x in v if isinstance(x, str)] if isinstance(v, list) else []
|
|
219
|
+
folders = [os.path.expanduser(f).rstrip("/") for f in strings(raw.get("folders"))]
|
|
220
|
+
ids = set(strings(raw.get("sessions")))
|
|
221
|
+
|
|
222
|
+
def ignored(sid, folder):
|
|
223
|
+
if sid in ids:
|
|
224
|
+
return True
|
|
225
|
+
return bool(folder) and any(fnmatch(folder, f) or fnmatch(folder, f + "/*") for f in folders)
|
|
226
|
+
return ignored
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def project_of(cwd):
|
|
230
|
+
"""The outermost git work tree holding cwd, else cwd itself.
|
|
231
|
+
|
|
232
|
+
A checkout nested in a repo, like Delta's .delta/worktrees/<id>/<repo>, joins that repo."""
|
|
233
|
+
if not cwd:
|
|
234
|
+
return "?"
|
|
235
|
+
p = Path(cwd)
|
|
236
|
+
repos = [str(d) for d in (p, *p.parents) if (d / ".git").exists() and d != HOME]
|
|
237
|
+
return repos[-1] if repos else cwd
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def snapshot(config_dirs, days, opencode_db=OPENCODE_DB, aliases_file=ALIASES, ignore_file=IGNORE):
|
|
241
|
+
"""Every session to show: state is waiting, working or recent; time is when that state began."""
|
|
242
|
+
now = time.time()
|
|
243
|
+
since = now - days * 86400
|
|
244
|
+
aliases = load_aliases(aliases_file) # config is read every time, so edits apply without a restart
|
|
245
|
+
ignored = load_ignore(ignore_file)
|
|
246
|
+
sessions = []
|
|
247
|
+
for s in claude_sessions(config_dirs, since) + recent_opencode(opencode_db, since):
|
|
248
|
+
folder = apply_alias(s["cwd"], aliases) if s["cwd"] else None
|
|
249
|
+
if not ignored(s["id"], folder):
|
|
250
|
+
s["project"] = project_of(folder)
|
|
251
|
+
sessions.append(s)
|
|
252
|
+
sessions.sort(key=lambda s: -(s["time"] or 0))
|
|
253
|
+
return {"now": now, "home": str(HOME), "days": days, "sessions": sessions}
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class Handler(BaseHTTPRequestHandler):
|
|
257
|
+
def log_message(self, *args):
|
|
258
|
+
pass
|
|
259
|
+
|
|
260
|
+
def _send(self, code, body, ctype="text/plain; charset=utf-8"):
|
|
261
|
+
self.send_response(code)
|
|
262
|
+
self.send_header("Content-Type", ctype)
|
|
263
|
+
self.send_header("Content-Length", str(len(body)))
|
|
264
|
+
self.send_header("Cache-Control", "no-store")
|
|
265
|
+
self.end_headers()
|
|
266
|
+
self.wfile.write(body)
|
|
267
|
+
|
|
268
|
+
def do_GET(self):
|
|
269
|
+
url = urlsplit(self.path)
|
|
270
|
+
given = self.headers.get("X-Key") or parse_qs(url.query).get("key", [""])[0]
|
|
271
|
+
if not hmac.compare_digest(given.encode(), self.server.key.encode()):
|
|
272
|
+
return self._send(403, b"forbidden")
|
|
273
|
+
if url.path == "/":
|
|
274
|
+
return self._send(200, PAGE.read_bytes(), "text/html; charset=utf-8")
|
|
275
|
+
if url.path == "/api/snapshot":
|
|
276
|
+
data = snapshot(self.server.config_dirs, self.server.days)
|
|
277
|
+
return self._send(200, json.dumps(data).encode(), "application/json")
|
|
278
|
+
self._send(404, b"not found")
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def config_dirs():
|
|
282
|
+
"""Claude Code config folders: ~/.claude*, and $CLAUDE_CONFIG_DIR if set."""
|
|
283
|
+
dirs = set(HOME.glob(".claude*"))
|
|
284
|
+
if os.environ.get("CLAUDE_CONFIG_DIR"):
|
|
285
|
+
dirs.add(Path(os.environ["CLAUDE_CONFIG_DIR"]).expanduser())
|
|
286
|
+
return sorted(d for d in dirs if (d / "projects").is_dir())
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def main():
|
|
290
|
+
if os.name == "nt": # os.kill(pid, 0) in pid_alive ends the process on Windows
|
|
291
|
+
sys.exit("session-board runs on Linux and macOS")
|
|
292
|
+
p = argparse.ArgumentParser(prog="session-board", description=__doc__.splitlines()[0])
|
|
293
|
+
p.add_argument("--port", type=int, default=0, help="default: a free port")
|
|
294
|
+
p.add_argument("--days", type=float, default=14, help="how far back recent sessions go")
|
|
295
|
+
p.add_argument("--no-open", action="store_true", help="print the URL, do not open a browser")
|
|
296
|
+
args = p.parse_args()
|
|
297
|
+
server = ThreadingHTTPServer(("127.0.0.1", args.port), Handler)
|
|
298
|
+
server.key = secrets.token_urlsafe(24)
|
|
299
|
+
server.days = args.days
|
|
300
|
+
server.config_dirs = config_dirs()
|
|
301
|
+
url = f"http://127.0.0.1:{server.server_address[1]}/?key={server.key}"
|
|
302
|
+
print(url, flush=True)
|
|
303
|
+
if not args.no_open:
|
|
304
|
+
webbrowser.open(url)
|
|
305
|
+
try:
|
|
306
|
+
server.serve_forever()
|
|
307
|
+
except KeyboardInterrupt:
|
|
308
|
+
pass
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Session board</title>
|
|
7
|
+
<link rel="icon" id="icon" href="data:,">
|
|
8
|
+
<script> // before the first paint: the saved theme, else the system's
|
|
9
|
+
const savedTheme = () => { try { const t = localStorage.getItem("theme"); return t === "light" || t === "dark" ? t : null; } catch { return null; } };
|
|
10
|
+
const systemDark = matchMedia("(prefers-color-scheme: dark)");
|
|
11
|
+
document.documentElement.dataset.theme = savedTheme() || (systemDark.matches ? "dark" : "light");
|
|
12
|
+
</script>
|
|
13
|
+
<style>
|
|
14
|
+
:root {
|
|
15
|
+
--bg: #f5f5f4; --card: #ffffff; --fg: #1c1917; --muted: #78716c; --line: #e7e5e4;
|
|
16
|
+
--wait: #d97706; --busy: #16a34a; --past: #a8a29e; --hub: #e7e5e4; --agent: #2563eb; color-scheme: light;
|
|
17
|
+
}
|
|
18
|
+
:root[data-theme="dark"] {
|
|
19
|
+
--bg: #0c0a09; --card: #1c1917; --fg: #f5f5f4; --muted: #a8a29e; --line: #292524;
|
|
20
|
+
--wait: #fbbf24; --busy: #4ade80; --past: #57534e; --hub: #292524; --agent: #60a5fa; color-scheme: dark;
|
|
21
|
+
}
|
|
22
|
+
body { margin: 0; padding: 16px; background: var(--bg); color: var(--fg); font: 14px/1.4 system-ui, sans-serif; }
|
|
23
|
+
header { margin-bottom: 14px; }
|
|
24
|
+
header .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }
|
|
25
|
+
header .status { gap: 4px 20px; margin-top: 8px; }
|
|
26
|
+
.end { margin-left: auto; display: flex; align-items: center; gap: 16px; }
|
|
27
|
+
h1 { font-size: 18px; margin: 0; }
|
|
28
|
+
nav button { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--fg); padding: 4px 12px; border-radius: 999px; cursor: pointer; }
|
|
29
|
+
nav button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
|
|
30
|
+
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
|
|
31
|
+
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
|
|
32
|
+
.switch span { width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; }
|
|
33
|
+
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--fg); transition: transform .15s; }
|
|
34
|
+
.switch input:checked + span { background: var(--fg); }
|
|
35
|
+
.switch input:checked + span::after { transform: translateX(14px); background: var(--bg); }
|
|
36
|
+
.switch input:focus-visible + span { outline: 2px solid var(--agent); outline-offset: 2px; }
|
|
37
|
+
.icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
|
38
|
+
#q { font: inherit; flex: 1 1 180px; max-width: 320px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--fg); }
|
|
39
|
+
#meta, .legend { color: var(--muted); font-size: 12px; }
|
|
40
|
+
.gh { color: var(--muted); display: inline-flex; }
|
|
41
|
+
.gh:hover { color: var(--fg); }
|
|
42
|
+
.gh svg { width: 18px; height: 18px; fill: currentColor; }
|
|
43
|
+
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; }
|
|
44
|
+
.legend span { white-space: nowrap; }
|
|
45
|
+
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
|
|
46
|
+
.legend i.waiting { background: var(--wait); box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--wait); margin: 0 7px 0 3px; }
|
|
47
|
+
.legend i.working { background: var(--busy); }
|
|
48
|
+
.legend i.recent { background: var(--past); }
|
|
49
|
+
.legend i.agent { width: 5px; height: 5px; background: var(--past); }
|
|
50
|
+
.legend i.agent.run { background: var(--agent); }
|
|
51
|
+
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
|
|
52
|
+
.tile.has-wait { border-color: var(--wait); box-shadow: 0 0 0 1px var(--wait); }
|
|
53
|
+
.tile h3 { font-size: 14px; margin: 0; overflow-wrap: anywhere; }
|
|
54
|
+
.tile .counts { color: var(--muted); font-size: 12px; }
|
|
55
|
+
.tile svg { display: block; width: 100%; height: auto; overflow: visible; }
|
|
56
|
+
.tile ul { margin: 4px 0 0; padding: 0; list-style: none; font-size: 12px; }
|
|
57
|
+
.tile li { display: flex; gap: 6px; padding: 2px 0; border-top: 1px solid var(--line); }
|
|
58
|
+
.tile li .age { color: var(--muted); margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
|
|
59
|
+
.empty { color: var(--muted); padding: 24px 0; }
|
|
60
|
+
.mapview { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
|
|
61
|
+
@media (max-width: 800px) { .mapview { grid-template-columns: 1fr; } }
|
|
62
|
+
svg.global { width: 100%; max-height: calc(100vh - 90px); }
|
|
63
|
+
svg .proj circle { fill: var(--card); stroke: var(--muted); stroke-width: 2; cursor: pointer; }
|
|
64
|
+
svg .proj.has-wait circle { stroke: var(--wait); stroke-width: 3; }
|
|
65
|
+
svg .proj.sel circle { fill: var(--fg); }
|
|
66
|
+
svg .proj.sel .pn { fill: var(--bg); }
|
|
67
|
+
svg .proj:focus-visible { outline: none; }
|
|
68
|
+
svg .proj:focus-visible circle { stroke: var(--agent); stroke-width: 3; }
|
|
69
|
+
svg .pn { font-weight: 700; pointer-events: none; }
|
|
70
|
+
svg .plabel { font-size: 14px; font-weight: 600; paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }
|
|
71
|
+
svg .leader { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
|
|
72
|
+
aside .tile { position: sticky; top: 16px; }
|
|
73
|
+
.hint { color: var(--muted); font-size: 13px; }
|
|
74
|
+
.hint a { color: var(--fg); }
|
|
75
|
+
.projects { width: 100%; border-collapse: collapse; margin-top: 8px; }
|
|
76
|
+
.projects th, .projects td { padding: 3px 0; border-top: 1px solid var(--line); text-align: left; }
|
|
77
|
+
.projects td:first-child { overflow-wrap: anywhere; }
|
|
78
|
+
.projects .num { text-align: right; padding-left: 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
|
|
79
|
+
.projects th button { font: inherit; font-weight: 600; color: var(--muted); background: none; border: 0; padding: 0; cursor: pointer; }
|
|
80
|
+
.projects th[aria-sort] button { color: var(--fg); }
|
|
81
|
+
.tile a.more { color: var(--agent); text-decoration: underline; text-underline-offset: 2px; }
|
|
82
|
+
svg text { fill: var(--fg); font: 11px system-ui, sans-serif; }
|
|
83
|
+
svg .hub { fill: var(--hub); }
|
|
84
|
+
svg .hub-n { font-size: 20px; font-weight: 700; }
|
|
85
|
+
svg .link { stroke: var(--line); stroke-width: 2; }
|
|
86
|
+
svg .waiting { fill: var(--wait); }
|
|
87
|
+
svg .working { fill: var(--busy); }
|
|
88
|
+
svg .recent { fill: var(--past); }
|
|
89
|
+
svg .agent { fill: var(--agent); }
|
|
90
|
+
svg .agent.done { fill: var(--past); }
|
|
91
|
+
svg .timer { fill: #fff; font-weight: 700; font-size: 10px; }
|
|
92
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
93
|
+
svg .pulse { animation: pulse 1.6s ease-out infinite; transform-box: fill-box; transform-origin: center; }
|
|
94
|
+
svg .agent.run { animation: blink 1.2s ease-in-out infinite; }
|
|
95
|
+
}
|
|
96
|
+
svg .pulse { fill: none; stroke: var(--wait); stroke-width: 2; }
|
|
97
|
+
@keyframes pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(1.8); opacity: 0; } }
|
|
98
|
+
@keyframes blink { 50% { opacity: .35; } }
|
|
99
|
+
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items: start; }
|
|
100
|
+
.col { background: var(--line); border-radius: 12px; padding: 8px; }
|
|
101
|
+
.col h2 { font-size: 13px; margin: 2px 4px 8px; display: flex; gap: 6px; align-items: center; }
|
|
102
|
+
.col h2 .n { color: var(--muted); font-weight: 400; }
|
|
103
|
+
.col .cards { display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 140px); overflow-y: auto; }
|
|
104
|
+
.card { background: var(--card); border-radius: 8px; padding: 7px 9px; border-left: 4px solid var(--past); font-size: 12px; }
|
|
105
|
+
.card.waiting { border-left-color: var(--wait); }
|
|
106
|
+
.card.working { border-left-color: var(--busy); }
|
|
107
|
+
.card .t { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
|
|
108
|
+
.card .m { display: flex; flex-wrap: wrap; gap: 4px 8px; color: var(--muted); margin-top: 3px; align-items: center; }
|
|
109
|
+
.card .proj { background: var(--hub); color: var(--fg); border-radius: 999px; padding: 0 7px; }
|
|
110
|
+
.card .age { margin-left: auto; font-variant-numeric: tabular-nums; }
|
|
111
|
+
.card.waiting .age { color: var(--wait); font-weight: 700; }
|
|
112
|
+
.card .dots i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--past); margin-right: 2px; }
|
|
113
|
+
.card .dots i.run { background: var(--agent); }
|
|
114
|
+
@media (max-width: 600px) {
|
|
115
|
+
body { padding: 12px; }
|
|
116
|
+
#q { max-width: none; }
|
|
117
|
+
.col .cards { max-height: none; } /* stacked columns: let the page scroll, not each column */
|
|
118
|
+
}
|
|
119
|
+
</style>
|
|
120
|
+
</head>
|
|
121
|
+
<body>
|
|
122
|
+
<header>
|
|
123
|
+
<div class="row">
|
|
124
|
+
<h1>Session board</h1>
|
|
125
|
+
<nav aria-label="Sessions"><button data-scope="now">Now</button> <button data-scope="history">History</button></nav>
|
|
126
|
+
<nav aria-label="Layout"><button data-layout="map">Map</button> <button data-layout="kanban">Kanban</button></nav>
|
|
127
|
+
<input id="q" type="search" placeholder="Filter projects and sessions" aria-label="Filter projects and sessions">
|
|
128
|
+
<span class="end">
|
|
129
|
+
<label class="switch" title="Light or dark theme"><svg class="icon" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>
|
|
130
|
+
<input type="checkbox" role="switch" id="dark" aria-label="Dark theme"><span></span>
|
|
131
|
+
<svg class="icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg></label>
|
|
132
|
+
<!-- noreferrer: the page URL holds the key -->
|
|
133
|
+
<a class="gh" href="https://github.com/maxulysse/session-board" target="_blank" rel="noopener noreferrer" title="session-board on GitHub" aria-label="session-board on GitHub"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg></a>
|
|
134
|
+
</span>
|
|
135
|
+
</div>
|
|
136
|
+
<div class="row status"><span id="meta">loading…</span><span class="legend" id="legend"></span></div>
|
|
137
|
+
</header>
|
|
138
|
+
<main id="view"></main>
|
|
139
|
+
<script>
|
|
140
|
+
const key = new URLSearchParams(location.search).get("key");
|
|
141
|
+
// favicon, like a mail count: amber with the number of sessions waiting on you, green when none wait, grey on History
|
|
142
|
+
let shown = null;
|
|
143
|
+
function setIcon(state) { // a waiting count, or "history"
|
|
144
|
+
if (state === shown) return;
|
|
145
|
+
shown = state;
|
|
146
|
+
const fill = state === "history" ? "#a8a29e" : state ? "#fbbf24" : "#4ade80";
|
|
147
|
+
const count = state > 0 ? '<text x="50" y="50" text-anchor="middle" dominant-baseline="central" font-family="system-ui, sans-serif" ' +
|
|
148
|
+
`font-weight="800" font-size="${state > 9 ? 52 : 68}" fill="#0c0a09">${state > 9 ? "9+" : state}</text>` : "";
|
|
149
|
+
document.getElementById("icon").href = "data:image/svg+xml," + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">' +
|
|
150
|
+
`<circle cx="50" cy="50" r="50" fill="${fill}"/>${count}</svg>`);
|
|
151
|
+
}
|
|
152
|
+
// view in the URL hash: #<scope>/<layout>, default now/map
|
|
153
|
+
const [hScope, hLayout] = location.hash.slice(1).split("/");
|
|
154
|
+
let scope = hScope === "history" ? "history" : "now", layout = hLayout === "kanban" ? "kanban" : "map", last = null;
|
|
155
|
+
let selected = null; // project shown in the map's side panel
|
|
156
|
+
const expanded = new Set(); // projects whose full session list is shown; survives the 5 s re-render
|
|
157
|
+
let sort = "recent", dir = -1; // the map's project table: column, and 1 ascending or -1 descending
|
|
158
|
+
document.getElementById("view").addEventListener("keydown", e => {
|
|
159
|
+
if ((e.key === "Enter" || e.key === " ") && e.target.matches("g.proj")) { e.preventDefault(); e.target.dispatchEvent(new MouseEvent("click", {bubbles: true})); }
|
|
160
|
+
});
|
|
161
|
+
document.getElementById("view").addEventListener("click", e => {
|
|
162
|
+
const sb = e.target.closest("[data-sort]");
|
|
163
|
+
if (sb) {
|
|
164
|
+
dir = sort === sb.dataset.sort ? -dir : COLUMNS[sb.dataset.sort].first;
|
|
165
|
+
sort = sb.dataset.sort;
|
|
166
|
+
return render();
|
|
167
|
+
}
|
|
168
|
+
const pn = e.target.closest("g.proj, a.pick");
|
|
169
|
+
if (pn) {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
selected = selected === pn.dataset.project ? null : pn.dataset.project;
|
|
172
|
+
return render();
|
|
173
|
+
}
|
|
174
|
+
const b = e.target.closest("a.more");
|
|
175
|
+
if (!b) return;
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
expanded.has(b.dataset.project) ? expanded.delete(b.dataset.project) : expanded.add(b.dataset.project);
|
|
178
|
+
render();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({"&": "&", "<": "<", ">": ">", '"': """}[c]));
|
|
182
|
+
const base = p => p.replace(/\/+$/, "").split("/").pop() || p;
|
|
183
|
+
const fit = (t, n) => t.length > n ? t.slice(0, Math.max(1, Math.floor(n) - 1)) + "…" : t;
|
|
184
|
+
const timeAgo = (s, now) => s.time ? ago(now - s.time) : ""; // a live session's status time can be missing
|
|
185
|
+
const plural = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
|
|
186
|
+
const latest = ss => Math.max(...ss.map(s => s.time || 0));
|
|
187
|
+
// project table columns: cmp sorts ascending; first is the direction a first click picks
|
|
188
|
+
const COLUMNS = {
|
|
189
|
+
name: {label: "Project", cmp: (a, b) => base(a[0]).localeCompare(base(b[0])), first: 1},
|
|
190
|
+
sessions: {label: "Sessions", cmp: (a, b) => a[1].length - b[1].length, first: -1, num: true},
|
|
191
|
+
recent: {label: "Last used", cmp: (a, b) => latest(a[1]) - latest(b[1]), first: -1, num: true},
|
|
192
|
+
};
|
|
193
|
+
function projectTable(groups, now) {
|
|
194
|
+
const th = ([k, c]) => `<th${c.num ? ' class="num"' : ""}${k === sort ? ` aria-sort="${dir > 0 ? "ascending" : "descending"}"` : ""}>` +
|
|
195
|
+
`<button type="button" data-sort="${k}" data-focus="sort:${k}">${c.label}${k === sort ? (dir > 0 ? " ↑" : " ↓") : ""}</button></th>`;
|
|
196
|
+
const rows = groups.slice().sort((a, b) => dir * COLUMNS[sort].cmp(a, b)).map(([p, ss]) =>
|
|
197
|
+
`<tr><td><a href="#" class="pick" data-project="${esc(p)}" data-focus="pick:${esc(p)}" title="${esc(p)}">${esc(base(p))}</a></td>` +
|
|
198
|
+
`<td class="num">${ss.length}</td><td class="num">${latest(ss) ? ago(now - latest(ss)) : ""}</td></tr>`).join("");
|
|
199
|
+
return `<table class="projects"><thead><tr>${Object.entries(COLUMNS).map(th).join("")}</tr></thead><tbody>${rows}</tbody></table>`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// the status line; counts follow the filter
|
|
203
|
+
function metaText(sessions, groups, d, query) {
|
|
204
|
+
const projects = plural(groups.length, "project");
|
|
205
|
+
return (query ? "filtered: " : "") + (scope === "now"
|
|
206
|
+
? `${sessions.filter(s => s.state === "waiting").length} waiting on you · ${plural(sessions.length, "session")} running in ${projects}` +
|
|
207
|
+
` · updated ${new Date(d.now * 1000).toLocaleTimeString()}`
|
|
208
|
+
: `${plural(sessions.length, "ended session")} in ${projects} · last ${d.days} days`);
|
|
209
|
+
}
|
|
210
|
+
const sw = (cls, text) => `<span><i class="${cls}"></i>${text}</span>`;
|
|
211
|
+
const LEGEND = {
|
|
212
|
+
now: sw("waiting", "waiting on you") + sw("working", "working") + sw("agent run", "agent running") + sw("agent", "agent done"),
|
|
213
|
+
history: sw("recent", "ended session, fades with age") + sw("agent", "agent"),
|
|
214
|
+
};
|
|
215
|
+
function ago(sec) {
|
|
216
|
+
if (sec < 60) return Math.round(sec) + "s";
|
|
217
|
+
if (sec < 3600) return Math.round(sec / 60) + "m";
|
|
218
|
+
if (sec < 86400) return (sec / 3600).toFixed(1) + "h";
|
|
219
|
+
return Math.round(sec / 86400) + "d";
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// One session circle with its agents around it; `a` is the direction the agent ring starts from.
|
|
223
|
+
function sessionNode(s, x, y, r, a, now) {
|
|
224
|
+
const age = timeAgo(s, now);
|
|
225
|
+
const tip = `${s.name || "(untitled)"}\n${base(s.project)} · ${s.tool}${s.account ? " · " + s.account : ""} · ${s.state} ${age}\n${s.cwd ?? ""}\n${s.id}` +
|
|
226
|
+
(s.agents.length ? `\n${plural(s.agents.length, "agent")}: ` + s.agents.map(g => (g.running ? "▶ " : "") + (g.type || "") + (g.description ? " " + g.description : "")).join("; ") : "");
|
|
227
|
+
let g = `<g><title>${esc(tip)}</title>`;
|
|
228
|
+
if (s.state === "waiting") g += `<circle class="pulse" cx="${x}" cy="${y}" r="${r}"/>`;
|
|
229
|
+
// older history sessions fade out, down to 35% at the edge of the window
|
|
230
|
+
const fade = s.state === "recent" ? Math.max(0.35, 1 - (now - s.time) / (last.days * 86400)) : 1;
|
|
231
|
+
g += `<circle class="${s.state}" cx="${x}" cy="${y}" r="${r}" opacity="${fade.toFixed(2)}"/>`;
|
|
232
|
+
if (s.state !== "recent") g += `<text class="timer" x="${x}" y="${y + 3.5}" text-anchor="middle">${age}</text>`;
|
|
233
|
+
const m = Math.min(s.agents.length, 24), ar = r + 6;
|
|
234
|
+
s.agents.slice(0, 24).forEach((ag, j) => {
|
|
235
|
+
const b = a + Math.PI / 2 + (2 * Math.PI * j) / m;
|
|
236
|
+
g += `<circle class="agent ${ag.running ? "run" : "done"}" cx="${x + ar * Math.cos(b)}" cy="${y + ar * Math.sin(b)}" r="2.6"/>`;
|
|
237
|
+
});
|
|
238
|
+
return g + "</g>";
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Everything at once: projects on a ring, each project's sessions fanned out behind it.
|
|
242
|
+
// A project's wedge of the circle grows with its session count.
|
|
243
|
+
// Big projects go to the top and bottom, small ones to the sides, where their horizontal names stack without clashing.
|
|
244
|
+
function ringOrder(groups) {
|
|
245
|
+
const halves = [[], []];
|
|
246
|
+
[...groups].sort((a, b) => b[1].length - a[1].length).forEach((g, i) => halves[i % 2].push(g));
|
|
247
|
+
const bigEnds = h => [...h.filter((_, i) => i % 2 === 0), ...h.filter((_, i) => i % 2).reverse()];
|
|
248
|
+
return [...bigEnds(halves[0]), ...bigEnds(halves[1])];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function globalSvg(groups, now, total) {
|
|
252
|
+
groups = ringOrder(groups);
|
|
253
|
+
const S = 1000, c = S / 2, many = total > 20;
|
|
254
|
+
const r = many ? 12 : 20, R1 = groups.length === 1 ? 0 : (many ? 270 : 190), R2 = R1 + (many ? 75 : 110), gap = 2 * r + 10;
|
|
255
|
+
const weight = ([, ss]) => ss.length + 1.5;
|
|
256
|
+
const sum = groups.reduce((t, g) => t + weight(g), 0);
|
|
257
|
+
let links = "", nodes = "", labels = "", start = -Math.PI / 2 - Math.PI * weight(groups[0]) / sum, reach = R1 + 40;
|
|
258
|
+
const placed = [];
|
|
259
|
+
for (const g of groups) {
|
|
260
|
+
const [project, ss] = g, wedge = (2 * Math.PI * weight(g)) / sum, mid = start + wedge / 2;
|
|
261
|
+
const px = c + R1 * Math.cos(mid), py = c + R1 * Math.sin(mid), pr = 9 + 4 * Math.sqrt(ss.length);
|
|
262
|
+
// sessions on rings beyond the project, as many per ring as fit in the wedge
|
|
263
|
+
let i = 0, ring = 0;
|
|
264
|
+
while (i < ss.length) {
|
|
265
|
+
const R = R2 + ring * gap, span = Math.max(wedge - 0.04, 0.01);
|
|
266
|
+
const fit = Math.max(1, Math.floor((span * R) / gap)), k = Math.min(fit, ss.length - i);
|
|
267
|
+
for (let j = 0; j < k; j++, i++) {
|
|
268
|
+
const a = k === 1 ? mid : mid - span / 2 + (span * (j + 0.5)) / k;
|
|
269
|
+
const x = c + R * Math.cos(a), y = c + R * Math.sin(a);
|
|
270
|
+
links += `<line class="link" x1="${px}" y1="${py}" x2="${x}" y2="${y}"/>`;
|
|
271
|
+
nodes += sessionNode(ss[i], x, y, r, a, now);
|
|
272
|
+
reach = Math.max(reach, R + 1.8 * r + 2); // room for the waiting pulse, which grows to 1.8 r
|
|
273
|
+
}
|
|
274
|
+
ring++;
|
|
275
|
+
}
|
|
276
|
+
const waiting = ss.some(s => s.state === "waiting");
|
|
277
|
+
nodes += `<g class="proj${project === selected ? " sel" : ""}${waiting ? " has-wait" : ""}" data-project="${esc(project)}" data-focus="proj:${esc(project)}" tabindex="0" role="button" aria-label="${esc(base(project))}, ${plural(ss.length, "session")}">` +
|
|
278
|
+
`<title>${esc(base(project))}: ${plural(ss.length, "session")}</title><circle cx="${px}" cy="${py}" r="${pr}"/>` +
|
|
279
|
+
`<text class="pn" x="${px}" y="${py + 4}" text-anchor="middle">${ss.length}</text></g>`;
|
|
280
|
+
// project name, horizontal, on the inner side of the project (the middle of the ring is empty)
|
|
281
|
+
const text = fit(base(project), 26), wide = text.length * 8.2;
|
|
282
|
+
if (!R1) placed.push({px, py, x: px, y: py - pr - 10, anchor: "middle", text, x0: px - wide / 2, x1: px + wide / 2});
|
|
283
|
+
else if (Math.abs(Math.sin(mid)) > 0.7) {
|
|
284
|
+
// near the top or bottom: beside the project, pointing away from the vertical axis
|
|
285
|
+
const right = Math.cos(mid) >= 0, lx = px + (right ? pr + 6 : -pr - 6), ly = py + 5;
|
|
286
|
+
placed.push({px, py, x: lx, y: ly, anchor: right ? "start" : "end", text, x0: right ? lx : lx - wide, x1: right ? lx + wide : lx});
|
|
287
|
+
} else {
|
|
288
|
+
const right = Math.cos(mid) >= 0, lx = px - Math.cos(mid) * (pr + 8), ly = py - Math.sin(mid) * (pr + 8) + 5;
|
|
289
|
+
placed.push({px, py, x: lx, y: ly, anchor: right ? "end" : "start", text, x0: right ? lx - wide : lx, x1: right ? lx : lx + wide});
|
|
290
|
+
}
|
|
291
|
+
start += wedge;
|
|
292
|
+
}
|
|
293
|
+
// nudge overlapping names towards the middle, one line at a time
|
|
294
|
+
const done = [];
|
|
295
|
+
for (const l of placed) {
|
|
296
|
+
const step = l.y < c ? 17 : -17;
|
|
297
|
+
for (let tries = 0; tries < 12 && done.some(o => o.x0 < l.x1 && l.x0 < o.x1 && Math.abs(o.y - l.y) < 16); tries++) l.y += step;
|
|
298
|
+
done.push(l);
|
|
299
|
+
const moved = Math.abs(l.y - l.py) > 30; // far from its project: draw a leader line
|
|
300
|
+
if (moved && R1) labels += `<line class="leader" x1="${l.px}" y1="${l.py}" x2="${l.anchor === "end" ? l.x1 + 3 : l.x0 - 3}" y2="${l.y - 5}"/>`;
|
|
301
|
+
labels += `<text class="plabel" x="${l.x}" y="${l.y}" text-anchor="${l.anchor}">${esc(l.text)}</text>`;
|
|
302
|
+
}
|
|
303
|
+
const v = c - reach, w = 2 * reach; // frame fits the drawing
|
|
304
|
+
return `<svg class="global" viewBox="${v} ${v} ${w} ${w}" role="img" aria-label="${plural(total, "session")} in ${plural(groups.length, "project")}">${links}${labels}${nodes}</svg>`;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// One project: a hub in the middle, its sessions around it, each session's agents around the session.
|
|
308
|
+
function projectSvg(sessions, now) {
|
|
309
|
+
const n = sessions.length, W = 280;
|
|
310
|
+
const R = n === 1 ? 0 : Math.min(95, 46 + n * 6), r = n > 8 ? 13 : 17;
|
|
311
|
+
const H = 2 * (R + r + 26) + (n === 1 ? 40 : 0);
|
|
312
|
+
const cx = W / 2, cy = H / 2;
|
|
313
|
+
let links = "", nodes = "";
|
|
314
|
+
sessions.forEach((s, i) => {
|
|
315
|
+
const a = -Math.PI / 2 + (2 * Math.PI * i) / n;
|
|
316
|
+
const x = cx + R * Math.cos(a), y = cy + (n === 1 ? 0 : R * Math.sin(a));
|
|
317
|
+
links += `<line class="link" x1="${cx}" y1="${cy}" x2="${x}" y2="${y}"/>`;
|
|
318
|
+
nodes += sessionNode(s, x, y, r, a, now);
|
|
319
|
+
const label = (s.name || "(untitled)").slice(0, 22);
|
|
320
|
+
const ly = n === 1 ? y + r + 18 : y + (Math.sin(a) >= -0.2 ? r + 16 : -r - 9);
|
|
321
|
+
if (n <= 6) nodes += `<text x="${x}" y="${ly}" text-anchor="middle">${esc(label)}</text>`; // more would overlap
|
|
322
|
+
});
|
|
323
|
+
const hub = n === 1 ? "" : `<circle class="hub" cx="${cx}" cy="${cy}" r="22"/><text class="hub-n" x="${cx}" y="${cy + 7}" text-anchor="middle">${n}</text>`;
|
|
324
|
+
return `<svg viewBox="0 0 ${W} ${H}" role="img" aria-label="${plural(n, "session")}">${links}${hub}${nodes}</svg>`;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function groupByProject(sessions) {
|
|
328
|
+
const map = new Map();
|
|
329
|
+
for (const s of sessions) {
|
|
330
|
+
if (!map.has(s.project)) map.set(s.project, []);
|
|
331
|
+
map.get(s.project).push(s);
|
|
332
|
+
}
|
|
333
|
+
return [...map];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function tile(project, sessions, now, home, list) {
|
|
337
|
+
const waiting = sessions.filter(s => s.state === "waiting").length;
|
|
338
|
+
const agents = sessions.reduce((t, s) => t + s.agents.length, 0);
|
|
339
|
+
const running = sessions.reduce((t, s) => t + s.agents.filter(g => g.running).length, 0);
|
|
340
|
+
const counts = [plural(sessions.length, "session"), agents && plural(agents, "agent") + (running ? ` (${running} running)` : ""),
|
|
341
|
+
waiting && `${waiting} waiting`].filter(Boolean).join(" · ");
|
|
342
|
+
const open = expanded.has(project);
|
|
343
|
+
const items = list ? "<ul>" + sessions.slice(0, open ? undefined : 8).map(s =>
|
|
344
|
+
`<li><span>${esc(s.name || "(untitled)")}${s.agents.length ? ` <span class="age">+${s.agents.length}</span>` : ""}</span><span class="age">${timeAgo(s, now)}</span></li>`).join("") +
|
|
345
|
+
(sessions.length > 8 ? `<li><a href="#" class="more" data-project="${esc(project)}" data-focus="more:${esc(project)}" aria-expanded="${open}">${open ? "show less" : `+${sessions.length - 8} more`}</a></li>` : "") + "</ul>" : "";
|
|
346
|
+
const path = home && project.startsWith(home) ? "~" + project.slice(home.length) : project;
|
|
347
|
+
return `<section class="tile${waiting ? " has-wait" : ""}"><h3 title="${esc(path)}">${esc(base(project))}</h3>
|
|
348
|
+
<div class="counts">${counts}</div>${projectSvg(sessions, now)}${items}</section>`;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// The 5 s refresh replaces the view's HTML, so the focused control (by its data-focus key) is refocused in the new one.
|
|
352
|
+
function redraw(html) {
|
|
353
|
+
const view = document.getElementById("view"), f = document.activeElement, key = view.contains(f) && f.dataset.focus;
|
|
354
|
+
view.innerHTML = html;
|
|
355
|
+
if (key) [...view.querySelectorAll("[data-focus]")].find(e => e.dataset.focus === key)?.focus();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function render() {
|
|
359
|
+
const d = last;
|
|
360
|
+
if (!d) return;
|
|
361
|
+
const live = d.sessions.filter(s => s.state !== "recent"), recent = d.sessions.filter(s => s.state === "recent");
|
|
362
|
+
const waiting = live.filter(s => s.state === "waiting").length;
|
|
363
|
+
setIcon(scope === "history" ? "history" : waiting);
|
|
364
|
+
const query = document.getElementById("q").value.trim().toLowerCase();
|
|
365
|
+
const sessions = (scope === "now" ? live : recent)
|
|
366
|
+
.filter(s => !query || [s.name, s.project, s.cwd].some(v => v && v.toLowerCase().includes(query)));
|
|
367
|
+
const groups = groupByProject(sessions); // recent is newest first, so projects come in order of last use
|
|
368
|
+
if (scope === "now") groups.sort((a, b) => b[1].filter(s => s.state === "waiting").length - a[1].filter(s => s.state === "waiting").length || b[1].length - a[1].length);
|
|
369
|
+
const empty = query ? "No session matches the filter." : scope === "now" ? "No session running." : `No session in the last ${d.days} days.`;
|
|
370
|
+
if (layout === "kanban") kanban(sessions, d);
|
|
371
|
+
else if (!groups.length) redraw(`<div class="empty">${empty}</div>`);
|
|
372
|
+
else {
|
|
373
|
+
const sel = groups.find(([p]) => p === selected);
|
|
374
|
+
const side = sel ? tile(sel[0], sel[1], d.now, d.home, true)
|
|
375
|
+
: `<div class="hint">Click a project to see its sessions. Click a column to sort; again to reverse.${projectTable(groups, d.now)}</div>`;
|
|
376
|
+
redraw(`<div class="mapview">${globalSvg(groups, d.now, sessions.length)}<aside>${side}</aside></div>`);
|
|
377
|
+
}
|
|
378
|
+
document.getElementById("meta").textContent = metaText(sessions, groups, d, query);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function card(s, now) {
|
|
382
|
+
const age = timeAgo(s, now);
|
|
383
|
+
const running = s.agents.filter(g => g.running).length;
|
|
384
|
+
const dots = s.agents.length ? `<span class="dots" title="${plural(s.agents.length, "agent")}${running ? `, ${running} running` : ""}">` +
|
|
385
|
+
s.agents.slice(0, 12).map(g => `<i class="${g.running ? "run" : ""}"></i>`).join("") +
|
|
386
|
+
(s.agents.length > 12 ? `+${s.agents.length - 12}` : "") + "</span>" : "";
|
|
387
|
+
return `<div class="card ${s.state}" title="${esc(s.cwd)} ${esc(s.id)}">
|
|
388
|
+
<div class="t">${esc(s.name || "(untitled)")}</div>
|
|
389
|
+
<div class="m"><span class="proj">${esc(base(s.project))}</span>${s.tool === "opencode" ? "<span>opencode</span>" : ""}${dots}<span class="age">${age}</span></div>
|
|
390
|
+
</div>`;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function kanban(sessions, d) {
|
|
394
|
+
const day = new Date(d.now * 1000).setHours(0, 0, 0, 0) / 1000; // local midnight
|
|
395
|
+
const oldestFirst = list => list.sort((a, b) => a.time - b.time);
|
|
396
|
+
const cols = scope === "now" ? [
|
|
397
|
+
["Waiting on you", oldestFirst(sessions.filter(s => s.state === "waiting"))],
|
|
398
|
+
["Working", oldestFirst(sessions.filter(s => s.state === "working"))],
|
|
399
|
+
] : [
|
|
400
|
+
["Today", sessions.filter(s => s.time >= day)],
|
|
401
|
+
["Yesterday", sessions.filter(s => s.time < day && s.time >= day - 86400)],
|
|
402
|
+
["This week", sessions.filter(s => s.time < day - 86400 && s.time >= day - 6 * 86400)],
|
|
403
|
+
["Older", sessions.filter(s => s.time < day - 6 * 86400)],
|
|
404
|
+
];
|
|
405
|
+
redraw(`<div class="board">` +
|
|
406
|
+
cols.map(([title, list]) =>
|
|
407
|
+
`<section class="col"><h2>${esc(title)} <span class="n">${list.length}</span></h2><div class="cards">` +
|
|
408
|
+
(list.length ? list.map(s => card(s, d.now)).join("") : '<div class="empty">none</div>') + "</div></section>").join("") + "</div>");
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function setView(newScope, newLayout) {
|
|
412
|
+
scope = newScope;
|
|
413
|
+
layout = newLayout;
|
|
414
|
+
const hash = scope === "now" && layout === "map" ? "" : `#${scope}/${layout}`;
|
|
415
|
+
history.replaceState(null, "", location.pathname + location.search + hash);
|
|
416
|
+
for (const b of document.querySelectorAll("[data-scope]")) b.setAttribute("aria-pressed", b.dataset.scope === scope);
|
|
417
|
+
for (const b of document.querySelectorAll("[data-layout]")) b.setAttribute("aria-pressed", b.dataset.layout === layout);
|
|
418
|
+
document.getElementById("legend").innerHTML = LEGEND[scope];
|
|
419
|
+
render();
|
|
420
|
+
}
|
|
421
|
+
for (const b of document.querySelectorAll("[data-scope]")) b.onclick = () => setView(b.dataset.scope, layout);
|
|
422
|
+
for (const b of document.querySelectorAll("[data-layout]")) b.onclick = () => setView(scope, b.dataset.layout);
|
|
423
|
+
setView(scope, layout);
|
|
424
|
+
document.getElementById("q").oninput = render;
|
|
425
|
+
|
|
426
|
+
// theme switch: a saved choice wins, remembered per browser and port; until then the page follows the system
|
|
427
|
+
const dark = document.getElementById("dark");
|
|
428
|
+
const setTheme = t => { document.documentElement.dataset.theme = t; dark.checked = t === "dark"; };
|
|
429
|
+
dark.onchange = () => {
|
|
430
|
+
setTheme(dark.checked ? "dark" : "light");
|
|
431
|
+
try { localStorage.setItem("theme", document.documentElement.dataset.theme); } catch {}
|
|
432
|
+
};
|
|
433
|
+
systemDark.addEventListener("change", e => savedTheme() || setTheme(e.matches ? "dark" : "light"));
|
|
434
|
+
setTheme(document.documentElement.dataset.theme);
|
|
435
|
+
|
|
436
|
+
async function poll() {
|
|
437
|
+
try {
|
|
438
|
+
const r = await fetch("/api/snapshot", {headers: {"X-Key": key}});
|
|
439
|
+
if (!r.ok) throw new Error(r.status + " " + r.statusText);
|
|
440
|
+
last = await r.json();
|
|
441
|
+
render();
|
|
442
|
+
} catch (e) {
|
|
443
|
+
document.getElementById("meta").textContent = "server not reachable: " + e.message;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
poll();
|
|
447
|
+
const tick = () => document.hidden || poll(); // no scans while the tab is hidden
|
|
448
|
+
setInterval(tick, 5000);
|
|
449
|
+
document.addEventListener("visibilitychange", tick);
|
|
450
|
+
</script>
|
|
451
|
+
</body>
|
|
452
|
+
</html>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: session-board
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local browser view of Claude Code and opencode sessions
|
|
5
|
+
Author: Maxime U Garcia
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/maxulysse/session-board
|
|
8
|
+
Project-URL: Issues, https://github.com/maxulysse/session-board/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/maxulysse/session-board/blob/main/CHANGELOG.md
|
|
10
|
+
Keywords: claude-code,opencode,dashboard,sessions
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Web Environment
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Software Development
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
<img src="https://raw.githubusercontent.com/maxulysse/session-board/main/logo.svg" width="96" alt="">
|
|
24
|
+
|
|
25
|
+
# session-board
|
|
26
|
+
|
|
27
|
+
Local browser view of Claude Code and opencode sessions on this machine: who is waiting on you, what is working, and what ran recently.
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
Linux or macOS, Python 3.10 or newer. No dependencies.
|
|
34
|
+
|
|
35
|
+
Try it without installing, with [uv](https://docs.astral.sh/uv/):
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
uvx session-board
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`uvx` reuses the copy it downloaded first; `uvx session-board@latest` gets the newest release.
|
|
42
|
+
|
|
43
|
+
Install the `session-board` command, with uv or [pipx](https://pipx.pypa.io/):
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
uv tool install session-board
|
|
47
|
+
pipx install session-board
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Update with `uv tool upgrade session-board` or `pipx upgrade session-board`; uninstall with `uv tool uninstall session-board` or `pipx uninstall session-board`.
|
|
51
|
+
|
|
52
|
+
Unreleased changes: `uvx --from git+https://github.com/maxulysse/session-board session-board`, or from a clone, no install needed:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
git clone https://github.com/maxulysse/session-board
|
|
56
|
+
cd session-board
|
|
57
|
+
python3 -m session_board
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
session-board # opens the board in your browser; Ctrl-C to stop
|
|
64
|
+
session-board --no-open --port 8765 --days 7
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- `--port N`: port to listen on; default, a free one
|
|
68
|
+
- `--days N`: how far back History goes; default 14
|
|
69
|
+
- `--no-open`: print the URL instead of opening a browser
|
|
70
|
+
|
|
71
|
+
On a remote machine, run `session-board --no-open --port 8765` there and `ssh -L 8765:127.0.0.1:8765 <host>` locally, then open the printed URL.
|
|
72
|
+
|
|
73
|
+
## What it reads
|
|
74
|
+
|
|
75
|
+
It reads, never writes:
|
|
76
|
+
|
|
77
|
+
- running Claude Code sessions: `<config>/sessions/*.json` (`pid`, `procStart`, `startedAt`, `status`, `cwd`)
|
|
78
|
+
- recent Claude Code transcripts: `<config>/projects/*/*.jsonl` (`ai-title` records, first prompt, `cwd`) and `<config>/projects/*/*/subagents/*.meta.json`
|
|
79
|
+
- opencode sessions: `$XDG_DATA_HOME/opencode/opencode.db` (default `~/.local/share`), read-only
|
|
80
|
+
|
|
81
|
+
`<config>` is every `~/.claude*` folder and `$CLAUDE_CONFIG_DIR`.
|
|
82
|
+
These are Claude Code's internal files, last checked with Claude Code 2.1.334; a missing field shows less on the board but never stops it.
|
|
83
|
+
On macOS, a crashed session whose PID a new process reuses can show as running: the PID-reuse check needs Linux's `/proc`.
|
|
84
|
+
|
|
85
|
+
The server listens on `127.0.0.1` only. Every request needs the random key in the printed URL.
|
|
86
|
+
|
|
87
|
+
## The board
|
|
88
|
+
|
|
89
|
+
The page refreshes every 5 s while its tab is visible. Pick what to show (**Now** or **History**) and how (**Map** or **Kanban**); the URL hash keeps the choice, e.g. `#history/kanban`.
|
|
90
|
+
|
|
91
|
+
- **Now**: running sessions. Sessions that are not `busy` or running a shell command are waiting on you (amber, pulsing). Subagents show as small dots, blue while they run.
|
|
92
|
+
- **History**: sessions of the last `--days` that are no longer running, fading with age.
|
|
93
|
+
- **Map**: one graph of everything: projects (the outermost git work tree around the session's folder, so a checkout nested inside a repo joins it) on a ring, their sessions fanned out behind them. The side table lists projects: click a column to sort, again to reverse; click a project for its details.
|
|
94
|
+
- **Kanban**: one card per session. Now has columns waiting on you and working; History has today, yesterday, this week and older.
|
|
95
|
+
|
|
96
|
+

|
|
97
|
+
|
|
98
|
+
The tab icon counts the sessions waiting on you (amber), turns green when none wait, and grey on History.
|
|
99
|
+
|
|
100
|
+
The filter box keeps sessions whose title, project or folder contains its text. The sun/moon switch picks a light or dark theme; until you use it, the page follows the system.
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
Both files live in `$XDG_CONFIG_HOME/session-board/` (default `~/.config/session-board/`), are optional, and are read on every refresh.
|
|
105
|
+
|
|
106
|
+
Renamed a folder? Map the old path to the new one in `aliases.json`, and its old sessions join the new project:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{ "~/workspace/old-name": "~/workspace/new-name" }
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Hide sessions in `ignore.json`: folder patterns, matched after aliases (a folder includes its subfolders), and session ids, shown in each session's tooltip:
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{ "folders": ["~/workspace/tmp-*"], "sessions": ["<session id>"] }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Tests: `python3 -m unittest`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
session_board/__init__.py
|
|
5
|
+
session_board/__main__.py
|
|
6
|
+
session_board/index.html
|
|
7
|
+
session_board.egg-info/PKG-INFO
|
|
8
|
+
session_board.egg-info/SOURCES.txt
|
|
9
|
+
session_board.egg-info/dependency_links.txt
|
|
10
|
+
session_board.egg-info/entry_points.txt
|
|
11
|
+
session_board.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
session_board
|