Add repos from the page, answer actions in place, Expo-style redesign

Add repository:
- New remote verb `add-repo KEY OWNER/NAME`. Off unless config.toml has
  [repo_add] (base_url + owners). Only listed owners; the dev box builds
  the URL itself, checks it with `git ls-remote` (bot access), then
  appends to [repos] under the lock. No URL crosses the SSH link.
- `repos` also reports where adding is allowed, so the page shows the
  form only when it's on and rejects other hosts before calling SSH.
- set_toml_string inserts after the section's last key, not after
  trailing blank lines / the next section's comments.

Responsiveness:
- web/static/app.js (progressive enhancement; every form still works
  without JS): forms go via fetch and get a JSON answer instead of
  POST-redirect-GET; buttons/cards show the change immediately; the
  list refreshes itself (15 s, 3 s while something is starting).
- `repos` is cached for 5 min (refreshed on add-repo), so a page view
  is one SSH call instead of two.
- `list` reads all unit states with one `systemctl show` instead of one
  per session: 676 -> 374 ms on the dev box with 21 sessions.
- Static assets are content-hashed and cached immutably.

Design: slate greys, hairline borders, black primary action, tinted
status badges, monospace repo/branch, two columns on desktop, stacked
on phones, light and dark.

Docs: README security model, AGENTS.md (JS convention, add-repo
invariant), config.example.toml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MCUMXh8zZConC75Mptbeou
This commit is contained in:
agent 2026-11-10 22:17:37 +00:00
parent 39997de1e8
commit 1b3172bd50
10 changed files with 1084 additions and 92 deletions

View file

@ -243,6 +243,120 @@ class TomlEdit(unittest.TestCase):
sc.set_toml_string("", "s", "k", 'a" \nx = "y')
def test_new_key_goes_after_last_key_not_into_next_sections_comments(self):
text = '[repos]\na = "x"\n\n# about ssh\n[ssh_access]\nk = "v"\n'
out = sc.set_toml_string(text, "repos", "b", "y")
self.assertEqual(out, '[repos]\na = "x"\nb = "y"\n\n# about ssh\n[ssh_access]\nk = "v"\n')
self.assertEqual(sc.set_toml_string("[repos]\n# none yet\n", "repos", "b", "y"), '[repos]\nb = "y"\n# none yet\n')
class UnitStates(unittest.TestCase):
def test_one_call_matched_by_id(self):
from unittest import mock
out = ("Id=claude-session@b.service\nActiveState=active\nSubState=running\nUnitFileState=enabled\nNRestarts=2\n\n"
"Id=claude-session@a.service\nActiveState=inactive\nSubState=dead\nUnitFileState=disabled\nNRestarts=0\n")
calls = []
def systemctl(*args, check=True):
calls.append(args)
return mock.Mock(stdout=out)
with mock.patch.object(sc, "systemctl", systemctl):
states = sc.unit_states(["a", "b", "c"])
self.assertEqual(len(calls), 1)
self.assertEqual(states["a"]["active"], "inactive")
self.assertEqual(states["b"], {"active": "active", "sub": "running", "enabled": True, "restarts": 2})
self.assertEqual(states["c"]["active"], "unknown") # missing block: unknown, not someone else's state
with mock.patch.object(sc, "systemctl", systemctl):
self.assertEqual(sc.unit_states([]), {})
self.assertEqual(len(calls), 1)
class AddRepo(unittest.TestCase):
"""add-repo with git and the config file in a temp dir."""
BASE = "ssh://git@git.example:14922/"
def setUp(self):
from unittest import mock
d = tempfile.TemporaryDirectory()
self.addCleanup(d.cleanup)
self.cfg_path = Path(d.name) / "config.toml"
self.cfg_path.write_text(
'max_running = 2\n\n[repos]\nold = "ssh://git@git.example:14922/team/Old.git"\n\n'
f'[repo_add]\nbase_url = "{self.BASE}"\nowners = ["team"]\n\n[ssh_access]\nallow_from_host = "x"\n')
self.cfg_path.chmod(0o600)
self.git = []
self.git_rc = 0
def run(cmd, **kw):
self.git.append(cmd)
return mock.Mock(returncode=self.git_rc, stdout="", stderr="")
for target, value in (("CONFIG_PATH", self.cfg_path), ("STATE_DIR", Path(d.name) / "state")):
p = mock.patch.object(sc, target, value)
p.start()
self.addCleanup(p.stop)
p = mock.patch.object(sc.subprocess, "run", run)
p.start()
self.addCleanup(p.stop)
def add(self, *args):
return sc.cmd_add_repo(sc.load_config(self.cfg_path), list(args))
def test_adds_and_keeps_the_rest(self):
import os, stat
before = self.cfg_path.read_text()
out = self.add("elorasmus", "team/elorasmus")
self.assertEqual(out["repos"], ["elorasmus", "old"])
self.assertEqual(self.git, [["git", "ls-remote", "--", f"{self.BASE}team/elorasmus.git", "HEAD"]])
after = self.cfg_path.read_text()
self.assertEqual(after, before.replace('Old.git"\n', f'Old.git"\nelorasmus = "{self.BASE}team/elorasmus.git"\n'))
self.assertEqual(stat.S_IMODE(os.stat(self.cfg_path).st_mode), 0o600)
self.assertEqual(sc.cmd_repos(sc.load_config(self.cfg_path), [])["add"],
{"base_url": self.BASE, "owners": ["team"]})
def test_strips_dot_git(self):
self.add("x", "team/x.git")
self.assertIn(f'x = "{self.BASE}team/x.git"', self.cfg_path.read_text())
def test_rejects_before_touching_git_or_config(self):
before = self.cfg_path.read_text()
bad = [
("Bad", "team/x"), ("x", "other/x"), ("x", "team"), ("x", "team/"), ("x", "team/a/b"),
("x", "team/../x"), ("x", "team/-x"), ("x", "team/x y"), ("x", "team/x\n"), ("x", "../team/x"),
("old", "team/new"), # key taken
("again", "team/old"), # URL already listed (case-insensitive)
]
for args in bad:
with self.assertRaises(sc.UserError, msg=args):
self.add(*args)
with self.assertRaises(sc.UserError):
self.add("x")
self.assertEqual(self.git, [])
self.assertEqual(self.cfg_path.read_text(), before)
def test_unreachable_repo_is_not_added(self):
before = self.cfg_path.read_text()
self.git_rc = 128
with self.assertRaises(sc.UserError):
self.add("x", "team/x")
self.assertEqual(self.cfg_path.read_text(), before)
def test_off_without_repo_add_section(self):
cfg = sc.load_config(self.cfg_path)
cfg["repo_add"] = {}
with self.assertRaises(sc.UserError):
sc.cmd_add_repo(cfg, ["x", "team/x"])
self.assertNotIn("add", sc.cmd_repos(cfg, []))
cfg["repo_add"] = {"base_url": "file:///tmp/", "owners": ["team"]}
with self.assertRaises(sc.UserError):
sc.cmd_add_repo(cfg, ["x", "team/x"])
def test_is_a_remote_verb(self):
self.assertEqual(sc.parse_remote("add-repo x team/x"), ["add-repo", "x", "team/x"])
class Keygen(unittest.TestCase):
def test_keygen_end_to_end_in_temp_dirs(self):
import base64, os