瀏覽代碼

add slweb

Johan Le Baut 1 周之前
父節點
當前提交
e74c5d3fc6

+ 16 - 3
README.md

@@ -39,7 +39,7 @@ This records the preparation already performed on `rigforge` and is a starting p
 - `scripts/midi_action_bridge.py`: translates declared ALSA MIDI note events into NAM model changes through mod-ui's WebSocket.
 - `scripts/run_mod_ui_service.py`: keeps mod-ui's backend session alive; mod-ui remains the sole owner of pedalboard connections.
 - `scripts/generate_mod_ui_pedalboard.py`: generates the reference NAM→IR pedalboard from the YAML.
-- `scripts/deploy.sh` and `scripts/deploy.py`: scoped user-level installation, removal, reload, and explicit mod-ui reset of declared services and LV2 bundles.
+- `scripts/deploy.sh` and `scripts/deploy.py`: scoped user-level installation, removal, reload, and explicit mod-ui reset of declared services, SLWeb source files, and LV2 bundles.
 - `tests/`: unit tests for desired-state validation, PipeWire observation/reconciliation, pedalboard generation, MIDI WebSocket control, the mod-ui/PipeWire boundary bridge, and deployment operations.
 - `artifacts/sooperlooper/arm64/`, `artifacts/mod-host/arm64/`, and `artifacts/mod-ui/arm64/`: generated binaries or runtime bundle, dependency reports, and build provenance; commit after reviewing licensing and repository size.
 
@@ -116,11 +116,12 @@ After a manual `git pull --ff-only`, run the deploy helper from any directory:
 ~/rigforge/scripts/deploy.sh install mod-host
 ~/rigforge/scripts/deploy.sh install mod-ui
 ~/rigforge/scripts/deploy.sh install sooperlooper
+~/rigforge/scripts/deploy.sh install slweb
 ~/rigforge/scripts/deploy.sh install reconcile
 ~/rigforge/scripts/deploy.sh install midi-bridge
 ```
 
-The helper accepts `install|uninstall|reload` plus `reset mod-ui`, and targets `all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host-ports|mod-host|mod-ui|reconcile|midi-bridge|sooperlooper`. `all` deliberately excludes the audio-host/UI/MIDI services and reconciliation, which are opt-in. Install in dependency order: ports, mod-host, then mod-ui; the MIDI bridge follows mod-ui. The ports service requires `/usr/bin/pw-loopback` from the target PipeWire tools; verify it exists before installation. It reads versions, paths, URLs, and settings from `config/desired-state.yaml`; its deployment registry is stored under `~/.local/state/rigforge/`, and any pre-existing unit backup is stored next to that unit. It does not use `sudo` or change files outside declared paths, adjacent backups, mod-ui's dedicated user-data directory, and the registry directory.
+The helper accepts `install|uninstall|reload` plus `reset mod-ui`, and targets `all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host-ports|mod-host|mod-ui|reconcile|midi-bridge|sooperlooper|slweb`. `all` deliberately excludes the audio-host/UI/MIDI services, reconciliation, and SooperLooper services, which are opt-in. Install in dependency order: ports, mod-host, then mod-ui; the MIDI bridge follows mod-ui. Install SooperLooper before SLWeb. The ports service requires `/usr/bin/pw-loopback` from the target PipeWire tools; verify it exists before installation. It reads versions, paths, URLs, and settings from `config/desired-state.yaml`; its deployment registry is stored under `~/.local/state/rigforge/`, and any pre-existing unit backup is stored next to that unit. It does not use `sudo` or change files outside declared paths, adjacent backups, the dedicated mod-ui and SLWeb user-data directories, and the registry directory.
 
 For PipeWire, install updates only the Rigforge filter fragment, applies the declared quantum as a runtime setting, and restarts `filter-chain.service` only when the fragment changes. It never restarts `pipewire.service` or WirePlumber. `reload pipewire` reapplies the quantum and restarts the filter-chain user service. This restart removes the filter-chain nodes and their graph links; the fragment recreates ports but not links. Reconciliation is a separate explicit target; installing `mod-host` alone does not install its timer. After a PipeWire/filter restart, inspect with `python3 scripts/observe_pipewire.py`. Uninstall removes only the unchanged managed fragment, restores a file that was present before the first install, returns quantum selection to automatic, and reloads the filter service. Local edits to managed files stop removal or replacement rather than being discarded. Runtime quantum is not persistent across a PipeWire daemon restart.
 
@@ -144,6 +145,18 @@ Install requires the built ARM64 artifact, the tracked `.slb` file, and target r
 
 Remove the service with `./scripts/deploy.sh uninstall sooperlooper`.
 
+### SooperLooper Web interface (SLWeb)
+
+`install slweb` downloads the `tools/` directory from the SooperLooper source archive declared by `deployment.sooperlooper.source_url` and `.tag`; it does not compile or replace either SooperLooper binary. The installed tree is kept at `~/.local/share/rigforge/sooperlooper-slweb/`, including the web assets. Its user unit requires and starts after `rigforge-sooperlooper.service`, and follows that service's stop/restart lifecycle. The Python server sends OSC to `127.0.0.1:9951` and binds HTTP only to `127.0.0.1:8080`; open `http://127.0.0.1:8080/` on the Pi itself. It is not exposed to the LAN.
+
+```sh
+./scripts/deploy.sh install slweb
+systemctl --user status rigforge-slweb.service
+journalctl --user -u rigforge-slweb.service -b
+```
+
+Remove SLWeb before SooperLooper with `./scripts/deploy.sh uninstall slweb`. The deploy helper fingerprints the downloaded tools, preserves a pre-existing install directory and service unit, and refuses to overwrite/remove locally modified managed files.
+
 ### mod-host ports and mod-ui guitar board
 
 `install mod-host-ports`, `install mod-host`, and `install mod-ui` are explicit targets and are deliberately excluded from `install all`. The desired four-channel `mod-host-ports` service starts a four-channel PipeWire input boundary (`rigforge.mod-host-input` with paired source `rigforge.mod-host-input.capture`) and a four-channel output boundary (`rigforge.mod-host-output.playback` with paired source `rigforge.mod-host-output`). Channel positions AUX0–AUX3 align with UMC capture channels 1–4. Rigforge's observer manages each UMC capture → input sink edge and each output source → its mixer/looper destinations. The generated mod-ui board shows the guitar path through NAM and IR, plus direct bass, microphone, and synth passthrough cables from `capture_2..4` to `playback_2..4`. mod-ui handles Connect/Disconnect for all boundary cables through the Rigforge PipeWire bridge; NAM→IR stays a normal mod-host connection. The service runner does not repair or override pedalboard links.
@@ -215,7 +228,7 @@ On the target, `install pipewire` applied quantum 128 and reported that the inst
 
 ## Development PC
 
-The development host can be Ubuntu AMD64 or WSL2 with Docker Buildx and ARM64 emulation available. The shared image under `build/arm64/` uses Debian 13 ARM64 tools. Source URLs and tags are declared in `config/desired-state.yaml` and validated before each build. SooperLooper uses `v1.7.9-mods.1`, resolving to `946b92e342bfb31c731671463995d31daf79fc0e`; mod-host uses `v1.15.0.3371`, resolving to `956e13e538a440a6ee87fd350e6b510ec5e7a1b6`; mod-ui uses `v1.15.0.3371`, resolving to `391c1eddefaf9dd624c19f2cfd50efc3a3e83592`.
+The development host can be Ubuntu AMD64 or WSL2 with Docker Buildx and ARM64 emulation available. The shared image under `build/arm64/` uses Debian 13 ARM64 tools. Source URLs and tags are declared in `config/desired-state.yaml` and validated before each build. The currently tracked SooperLooper binary was built from `abarker/sooperlooper-mods` tag `v1.7.9-mods.1` (commit `946b92e342bfb31c731671463995d31daf79fc0e`); the desired source is now `jojolb/sooperlooper-mods` tag `v1.7.9-mods.1-slweb`. Deploying SLWeb only downloads that tag's `tools/` directory and does not rebuild the binary. Mod-host uses `v1.15.0.3371`, resolving to `956e13e538a440a6ee87fd350e6b510ec5e7a1b6`; mod-ui uses `v1.15.0.3371`, resolving to `391c1eddefaf9dd624c19f2cfd50efc3a3e83592`.
 
 Build the common image once from the rigforge repository root, then select a build task:
 

+ 11 - 2
config/desired-state.yaml

@@ -57,8 +57,8 @@ deployment:
       DragonflyPlateReverb.lv2: dragonfly-reverb-3.2.10/DragonflyPlateReverb.lv2
       DragonflyRoomReverb.lv2: dragonfly-reverb-3.2.10/DragonflyRoomReverb.lv2
   sooperlooper:
-    source_url: https://github.com/abarker/sooperlooper-mods
-    tag: v1.7.9-mods.1
+    source_url: https://github.com/jojolb/sooperlooper-mods
+    tag: v1.7.9-mods.1-slweb
     binary_source: artifacts/sooperlooper/arm64/current/sooperlooper
     service_source: config/systemd/user/rigforge-sooperlooper.service.in
     service_destination: .config/systemd/user/rigforge-sooperlooper.service
@@ -72,6 +72,15 @@ deployment:
       port: 9951
       post_start_delay_seconds: 4
       discrete_prefader: 0
+  slweb:
+    source_directory: tools
+    install_directory: .local/share/rigforge/sooperlooper-slweb
+    service_source: config/systemd/user/rigforge-slweb.service.in
+    service_destination: .config/systemd/user/rigforge-slweb.service
+    user_service: rigforge-slweb.service
+    python_path: /usr/bin/python3
+    http_host: 127.0.0.1
+    http_port: 8080
   mod_host:
     source_url: https://github.com/mod-audio/mod-host
     tag: v1.15.0.3371

+ 16 - 0
config/systemd/user/rigforge-slweb.service.in

@@ -0,0 +1,16 @@
+[Unit]
+Description=Rigforge SooperLooper Web interface
+Requires=rigforge-sooperlooper.service
+After=rigforge-sooperlooper.service
+PartOf=rigforge-sooperlooper.service
+
+[Service]
+Type=simple
+WorkingDirectory=@SLWEB_DIRECTORY@
+ExecStart=@PYTHON@ tools/slweb.py --osc-host @OSC_HOST@ --osc-port @OSC_PORT@ --http-host @HTTP_HOST@ --http-port @HTTP_PORT@
+Restart=on-failure
+RestartSec=2
+TimeoutStopSec=10
+
+[Install]
+WantedBy=default.target

+ 290 - 2
scripts/deploy.py

@@ -38,6 +38,7 @@ def load_deployment():
         raise ValueError("deployment must be a mapping")
     namlv2 = deployment.get("namlv2")
     sooperlooper = deployment.get("sooperlooper")
+    slweb = deployment.get("slweb")
     pipewire = deployment.get("pipewire")
     reconcile = deployment.get("reconcile")
     midi_bridge = deployment.get("midi_bridge")
@@ -46,6 +47,7 @@ def load_deployment():
     if (
         not isinstance(namlv2, dict)
         or not isinstance(sooperlooper, dict)
+        or not isinstance(slweb, dict)
         or not isinstance(pipewire, dict)
         or not isinstance(reconcile, dict)
         or not isinstance(midi_bridge, dict)
@@ -53,8 +55,9 @@ def load_deployment():
         or not isinstance(mod_ui, dict)
     ):
         raise ValueError(
-            "deployment.namlv2, deployment.sooperlooper, deployment.pipewire, deployment.reconcile, "
-            "deployment.midi_bridge, deployment.mod_host_ports, and deployment.mod_ui must be mappings"
+            "deployment.namlv2, deployment.sooperlooper, deployment.slweb, deployment.pipewire, "
+            "deployment.reconcile, deployment.midi_bridge, deployment.mod_host_ports, and deployment.mod_ui "
+            "must be mappings"
         )
     for component, archive_format in PLUGIN_ARCHIVES.items():
         plugin = deployment.get(component)
@@ -1230,6 +1233,252 @@ def render_sooperlooper_service(config, state):
     }
 
 
+def slweb_tools_path(config):
+    relative = PurePosixPath(config.get("install_directory", ""))
+    if relative.is_absolute() or ".." in relative.parts or not relative.parts:
+        raise RuntimeError("SLWeb install directory must be a safe relative path")
+    destination = Path.home() / Path(*relative.parts)
+    validate_user_destination(destination)
+    return destination
+
+
+def extract_slweb_tools(archive_path, destination, source_directory):
+    source_root = PurePosixPath(source_directory)
+    if source_root.is_absolute() or ".." in source_root.parts or len(source_root.parts) != 1:
+        raise RuntimeError("SLWeb source directory must be one safe repository directory")
+
+    with tarfile.open(archive_path, "r:gz") as archive:
+        selected = []
+        roots = set()
+        for member in archive.getmembers():
+            member_path = PurePosixPath(member.name)
+            if (
+                member_path.is_absolute()
+                or ".." in member_path.parts
+                or len(member_path.parts) < 2
+                or member_path.parts[1] != source_root.name
+            ):
+                continue
+            roots.add(member_path.parts[0])
+            if not (member.isdir() or member.isfile()):
+                raise RuntimeError(f"unsupported SLWeb source member: {member.name}")
+            selected.append((member, member_path))
+
+        if len(roots) != 1:
+            raise RuntimeError("SooperLooper archive does not contain one tools directory")
+        if not selected:
+            raise RuntimeError("SooperLooper archive has no tools directory")
+
+        tools_root = destination / source_root.name
+        tools_root.mkdir(parents=True, exist_ok=True)
+        for member, member_path in selected:
+            relative = PurePosixPath(*member_path.parts[2:])
+            if not relative.parts:
+                continue
+            output_path = tools_root.joinpath(*relative.parts)
+            if member.isdir():
+                output_path.mkdir(parents=True, exist_ok=True)
+                output_path.chmod(0o755)
+                continue
+            output_path.parent.mkdir(parents=True, exist_ok=True)
+            source = archive.extractfile(member)
+            if source is None:
+                raise RuntimeError(f"unable to read SLWeb source member: {member.name}")
+            with source, output_path.open("wb") as output:
+                shutil.copyfileobj(source, output)
+            output_path.chmod(0o755 if member.mode & 0o111 else 0o644)
+
+    required_files = (
+        tools_root / "slweb.py",
+        tools_root / "slweb_web" / "index.html",
+        tools_root / "slweb_web" / "app.css",
+        tools_root / "slweb_web" / "app.js",
+    )
+    if any(not path.is_file() for path in required_files):
+        raise RuntimeError("SooperLooper tools directory is missing SLWeb or its web assets")
+
+
+def install_slweb_tools(config, source_config, registry):
+    destination = slweb_tools_path(config)
+    managed = registry.get("slweb")
+    if managed is not None:
+        if managed.get("destination") != str(destination):
+            raise RuntimeError("recorded SLWeb installation path changed")
+        if managed.get("pending_uninstall"):
+            raise RuntimeError("SLWeb uninstall is incomplete; retry uninstall slweb first")
+        backup = validate_backup_path(
+            managed.get("backup"), destination, is_directory=True
+        )
+        if (backup is None) != (managed.get("backup_sha256") is None):
+            raise RuntimeError("invalid SLWeb backup record")
+        if backup is not None and backup.exists():
+            if not backup.is_dir() or tree_sha256(backup) != managed.get("backup_sha256"):
+                raise RuntimeError(f"recorded SLWeb backup changed locally: {backup}")
+        elif backup is not None:
+            raise RuntimeError(f"recorded SLWeb backup is missing: {backup}")
+        if not destination.is_dir():
+            raise RuntimeError(f"managed SLWeb tools directory is missing: {destination}")
+        if tree_sha256(destination) != managed.get("installed_sha256"):
+            raise RuntimeError(f"managed SLWeb tools changed locally; refusing overwrite: {destination}")
+        if managed.get("tag") == source_config["tag"]:
+            print(f"SLWeb tools from SooperLooper tag {source_config['tag']} are already installed and unchanged.")
+            return managed
+
+    backup_path = destination.with_name(destination.name + ".rigforge-backup")
+    if managed is None and (backup_path.exists() or backup_path.is_symlink()):
+        raise RuntimeError(f"SLWeb backup path already exists: {backup_path}")
+    if destination.exists() and not destination.is_dir():
+        raise RuntimeError(f"SLWeb destination is not a directory: {destination}")
+
+    staged = destination.with_name(destination.name + ".rigforge-new")
+    previous = destination.with_name(destination.name + ".rigforge-old")
+    if staged.exists() or staged.is_symlink() or previous.exists() or previous.is_symlink():
+        raise RuntimeError(f"SLWeb staging or recovery path already exists: {destination}")
+
+    source_url = source_config["source_url"].rstrip("/")
+    tag = source_config["tag"]
+    if (
+        source_url != "https://github.com/jojolb/sooperlooper-mods"
+        or not isinstance(tag, str)
+        or not re.fullmatch(r"[A-Za-z0-9._-]+", tag)
+    ):
+        raise RuntimeError("SLWeb requires the approved SooperLooper GitHub source and tag")
+    archive_url = f"{source_url}/archive/refs/tags/{tag}.tar.gz"
+
+    try:
+        with tempfile.TemporaryDirectory(prefix="rigforge-slweb-") as temporary_dir:
+            temporary = Path(temporary_dir)
+            archive_path = temporary / "sooperlooper-source.tar.gz"
+            download_archive(archive_url, archive_path)
+            archive_digest = hashlib.sha256(archive_path.read_bytes()).hexdigest()
+            extracted = temporary / "source"
+            extracted.mkdir()
+            extract_slweb_tools(archive_path, extracted, config["source_directory"])
+            shutil.copytree(extracted, staged)
+    except Exception:
+        if staged.exists():
+            shutil.rmtree(staged)
+        raise
+
+    backup = managed.get("backup") if managed is not None else None
+    backup_digest = managed.get("backup_sha256") if managed is not None else None
+    backup_created = False
+    moved_previous = False
+    try:
+        if managed is None and destination.exists():
+            shutil.copytree(destination, backup_path, symlinks=True)
+            backup = str(backup_path)
+            backup_digest = tree_sha256(backup_path)
+            backup_created = True
+        destination.parent.mkdir(parents=True, exist_ok=True)
+        if destination.exists():
+            os.replace(destination, previous)
+            moved_previous = True
+        os.replace(staged, destination)
+        installed_digest = tree_sha256(destination)
+        record = {
+            "destination": str(destination),
+            "source_url": source_url,
+            "tag": tag,
+            "archive_sha256": archive_digest,
+            "installed_sha256": installed_digest,
+            "backup": backup,
+            "backup_sha256": backup_digest,
+        }
+        registry["slweb"] = record
+        write_registry(registry)
+    except (OSError, shutil.Error):
+        if destination.exists() and moved_previous:
+            shutil.rmtree(destination)
+        if moved_previous and previous.exists():
+            os.replace(previous, destination)
+        if backup_created and backup_path.exists():
+            shutil.rmtree(backup_path)
+        if staged.exists():
+            shutil.rmtree(staged)
+        raise
+    if previous.exists():
+        shutil.rmtree(previous)
+    print(f"Installed SLWeb tools from {tag} at {destination}.")
+    print(f"Downloaded SooperLooper source archive SHA-256 (identity only): {archive_digest}")
+    return record
+
+
+def uninstall_slweb_tools(config, registry):
+    managed = registry.get("slweb")
+    if managed is None:
+        print("No managed SLWeb tools to uninstall.")
+        return
+    destination = slweb_tools_path(config)
+    if managed.get("destination") != str(destination):
+        raise RuntimeError("recorded SLWeb installation path changed")
+    backup = validate_backup_path(managed.get("backup"), destination, is_directory=True)
+    backup_digest = managed.get("backup_sha256")
+    if (backup is None) != (backup_digest is None):
+        raise RuntimeError("invalid SLWeb backup record")
+    if backup is not None and backup.exists():
+        if not backup.is_dir() or tree_sha256(backup) != backup_digest:
+            raise RuntimeError(f"recorded SLWeb backup changed locally: {backup}")
+
+    current_digest = tree_sha256(destination) if destination.is_dir() else None
+    if destination.exists() and not destination.is_dir():
+        raise RuntimeError(f"SLWeb destination has the wrong type: {destination}")
+    if managed.get("pending_uninstall"):
+        if current_digest not in {managed.get("installed_sha256"), backup_digest, None}:
+            raise RuntimeError(f"unexpected SLWeb files block uninstall: {destination}")
+    elif current_digest != managed.get("installed_sha256"):
+        raise RuntimeError(f"managed SLWeb tools changed locally; refusing removal: {destination}")
+    if backup is not None and not backup.exists() and current_digest == managed.get("installed_sha256"):
+        raise RuntimeError(f"recorded SLWeb backup is missing: {backup}")
+
+    managed["pending_uninstall"] = True
+    registry["slweb"] = managed
+    write_registry(registry)
+    if current_digest == managed.get("installed_sha256"):
+        shutil.rmtree(destination)
+    if backup is not None and backup.exists():
+        if destination.exists():
+            raise RuntimeError(f"unexpected destination blocks SLWeb backup restore: {destination}")
+        os.replace(backup, destination)
+    registry.pop("slweb")
+    write_registry(registry)
+    print("SLWeb tools removed; prior directory restored if present.")
+
+
+def render_slweb_service(config, source_config, tools_digest):
+    destination = slweb_tools_path(config)
+    service_template = ROOT / config["service_source"]
+    if not service_template.is_file():
+        raise RuntimeError(f"SLWeb service template is missing: {service_template}")
+    replacements = {
+        "@SLWEB_DIRECTORY@": systemd_quote(destination),
+        "@PYTHON@": systemd_quote(config["python_path"]),
+        "@OSC_HOST@": source_config["osc"]["host"],
+        "@OSC_PORT@": str(source_config["osc"]["port"]),
+        "@HTTP_HOST@": config["http_host"],
+        "@HTTP_PORT@": str(config["http_port"]),
+    }
+    content = service_template.read_text(encoding="utf-8")
+    for placeholder, replacement in replacements.items():
+        content = content.replace(placeholder, replacement)
+    if re.search(r"@[A-Z_]+@", content):
+        raise RuntimeError("unexpanded placeholder remains in SLWeb service template")
+    fingerprint = hashlib.sha256(
+        json.dumps(
+            {"slweb": config, "sooperlooper_source": source_config, "tools_sha256": tools_digest},
+            sort_keys=True,
+            separators=(",", ":"),
+        ).encode("utf-8")
+        + content.encode("utf-8")
+    ).hexdigest()
+    content += f"\n# Rigforge runtime fingerprint: {fingerprint}\n"
+    return {
+        "name": config["user_service"],
+        "destination": Path.home() / config["service_destination"],
+        "content": content.encode("utf-8"),
+    }
+
+
 def atomic_install_bytes(content, destination):
     destination.parent.mkdir(parents=True, exist_ok=True)
     fd, temporary_name = tempfile.mkstemp(prefix=f".{destination.name}.", dir=destination.parent)
@@ -1814,6 +2063,10 @@ def reset_mod_ui_reference(config, registry):
 
 
 def deploy_sooperlooper(action, config, registry, state=None):
+    if action == "uninstall" and (
+        "slweb" in registry or "slweb_service" in registry
+    ):
+        raise RuntimeError("uninstall slweb before uninstalling SooperLooper")
     if state is None:
         state = yaml.safe_load(
             (ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8")
@@ -1824,6 +2077,36 @@ def deploy_sooperlooper(action, config, registry, state=None):
     )
 
 
+def deploy_slweb(action, config, source_config, registry):
+    if action == "install" and "sooperlooper" not in registry:
+        raise RuntimeError("install sooperlooper before installing slweb")
+    if action == "uninstall" and "slweb" not in registry and "slweb_service" not in registry:
+        print("No managed SLWeb service or tools to uninstall.")
+        return
+
+    if action == "install":
+        tools = install_slweb_tools(config, source_config, registry)
+    else:
+        tools = registry.get("slweb")
+        if action == "reload" and tools is None:
+            raise RuntimeError("SLWeb tools are not managed; install slweb before reloading it")
+        if tools is not None:
+            destination = slweb_tools_path(config)
+            if destination.is_dir() and tree_sha256(destination) != tools.get("installed_sha256"):
+                raise RuntimeError(
+                    f"managed SLWeb tools changed locally; refusing service operation: {destination}"
+                )
+        if tools is None:
+            raise RuntimeError("SLWeb tools are not managed; install slweb first")
+
+    unit = render_slweb_service(
+        config, source_config, tools.get("installed_sha256", "unmanaged")
+    )
+    deploy_single_user_service(action, "slweb_service", "slweb", "SLWeb", unit, registry)
+    if action == "uninstall":
+        uninstall_slweb_tools(config, registry)
+
+
 def file_sha256(path):
     return hashlib.sha256(path.read_bytes()).hexdigest() if path.is_file() else None
 
@@ -2340,6 +2623,7 @@ def main(argv=None):
             "reconcile",
             "midi-bridge",
             "sooperlooper",
+            "slweb",
         ),
     )
     parser.add_argument(
@@ -2382,6 +2666,10 @@ def main(argv=None):
             deploy_sooperlooper(
                 args.action, deployment["sooperlooper"], registry, state=state
             )
+        elif args.target == "slweb":
+            deploy_slweb(
+                args.action, deployment["slweb"], deployment["sooperlooper"], registry
+            )
         else:
             component = "dragonfly_reverb" if args.target == "dragonfly-reverb" else args.target
             deploy_lv2_archives(args.action, component, deployment[component], registry)

+ 2 - 2
scripts/deploy.sh

@@ -2,7 +2,7 @@
 set -u
 
 usage() {
-    printf 'Usage: %s install|uninstall|reload|reset all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host-ports|mod-host|mod-ui|reconcile|midi-bridge|sooperlooper [--force-reference (install mod-ui only)]\n' "$0" >&2
+    printf 'Usage: %s install|uninstall|reload|reset all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host-ports|mod-host|mod-ui|reconcile|midi-bridge|sooperlooper|slweb [--force-reference (install mod-ui only)]\n' "$0" >&2
     exit 2
 }
 
@@ -20,7 +20,7 @@ case "$action" in
 esac
 case "$target" in
     all) targets=(pipewire namlv2 lsp dragonfly-reverb) ;;
-    namlv2|lsp|dragonfly-reverb|pipewire|mod-host-ports|mod-host|mod-ui|reconcile|midi-bridge|sooperlooper) targets=("$target") ;;
+    namlv2|lsp|dragonfly-reverb|pipewire|mod-host-ports|mod-host|mod-ui|reconcile|midi-bridge|sooperlooper|slweb) targets=("$target") ;;
     *) usage ;;
 esac
 if [[ "$action" == reset && "$target" != mod-ui ]]; then

+ 18 - 1
scripts/validate_desired_state.py

@@ -533,7 +533,7 @@ def validate_state(state):
             errors.append("deployment.sooperlooper must be a mapping")
         else:
             source_url = sooperlooper.get("source_url")
-            if source_url != "https://github.com/abarker/sooperlooper-mods":
+            if source_url != "https://github.com/jojolb/sooperlooper-mods":
                 errors.append("deployment.sooperlooper.source_url must match the approved GitHub repository")
             tag = sooperlooper.get("tag")
             if not isinstance(tag, str) or not tag or any(
@@ -596,6 +596,23 @@ def validate_state(state):
                         "deployment.sooperlooper.osc.discrete_prefader must be 0 or 1"
                     )
 
+        slweb = deployment.get("slweb")
+        if not isinstance(slweb, dict):
+            errors.append("deployment.slweb must be a mapping")
+        else:
+            for key, expected in (
+                ("source_directory", "tools"),
+                ("install_directory", ".local/share/rigforge/sooperlooper-slweb"),
+                ("service_source", "config/systemd/user/rigforge-slweb.service.in"),
+                ("service_destination", ".config/systemd/user/rigforge-slweb.service"),
+                ("user_service", "rigforge-slweb.service"),
+                ("python_path", "/usr/bin/python3"),
+                ("http_host", "127.0.0.1"),
+                ("http_port", 8080),
+            ):
+                if slweb.get(key) != expected:
+                    errors.append(f"deployment.slweb.{key} must be {expected}")
+
         mod_host = deployment.get("mod_host")
         if not isinstance(mod_host, dict):
             errors.append("deployment.mod_host must be a mapping")

+ 143 - 0
tests/test_deploy.py

@@ -29,6 +29,8 @@ class DeploymentTests(unittest.TestCase):
         self.home_patcher.start()
         patch.object(deploy, "user_unit_is_active", return_value=False).start()
         patch.object(deploy, "user_unit_is_enabled", return_value=False).start()
+        patch.object(deploy, "mod_host_port_is_open", return_value=False).start()
+        patch.object(deploy, "mod_ui_port_is_open", return_value=False).start()
         self.root_patcher = patch.object(deploy, "ROOT", ROOT)
         self.root_patcher.start()
         self.registry_patcher = patch.object(deploy, "STATE_PATH", self.registry_path)
@@ -119,6 +121,9 @@ class DeploymentTests(unittest.TestCase):
     def sooperlooper_config(self):
         return deploy.load_deployment()["sooperlooper"]
 
+    def slweb_config(self):
+        return deploy.load_deployment()["slweb"]
+
     def reconcile_config(self):
         return deploy.load_deployment()["reconcile"]
 
@@ -139,6 +144,24 @@ class DeploymentTests(unittest.TestCase):
                 info.size = len(content)
                 archive.addfile(info, io.BytesIO(content))
 
+    def make_slweb_archive(self, destination):
+        files = {
+            "tools/slweb.py": b"print('slweb')\n",
+            "tools/slweb_web/index.html": b"<!doctype html>\n",
+            "tools/slweb_web/app.css": b"body {}\n",
+            "tools/slweb_web/app.js": b"// UI\n",
+            "tools/other-tool.py": b"print('other tool')\n",
+        }
+        with tarfile.open(destination, "w:gz") as archive:
+            root = tarfile.TarInfo("sooperlooper-mods-tag")
+            root.type = tarfile.DIRTYPE
+            archive.addfile(root)
+            for relative_path, content in files.items():
+                info = tarfile.TarInfo(f"sooperlooper-mods-tag/{relative_path}")
+                info.size = len(content)
+                info.mode = 0o644
+                archive.addfile(info, io.BytesIO(content))
+
     def install_nam(self, config=None):
         config = config or self.nam_config()
 
@@ -543,6 +566,126 @@ class DeploymentTests(unittest.TestCase):
         self.assertEqual(destination.read_text(encoding="utf-8"), "local change")
         self.assertEqual(self.commands, [])
 
+    def test_slweb_install_fetches_tools_and_activates_after_sooperlooper(self):
+        config = self.slweb_config()
+        sooperlooper = self.sooperlooper_config()
+        registry = deploy.read_registry()
+        registry["sooperlooper"] = {"installed_sha256": "engine"}
+        deploy.write_registry(registry)
+        archive_urls = []
+
+        def download(url, destination):
+            archive_urls.append(url)
+            self.make_slweb_archive(destination)
+
+        with patch.object(deploy, "download_archive", side_effect=download):
+            deploy.deploy_slweb("install", config, sooperlooper, deploy.read_registry())
+
+        installed_dir = self.home / config["install_directory"]
+        self.assertTrue((installed_dir / "tools/slweb.py").is_file())
+        self.assertTrue((installed_dir / "tools/slweb_web/index.html").is_file())
+        self.assertTrue((installed_dir / "tools/other-tool.py").is_file())
+        self.assertFalse((installed_dir / "src").exists())
+        self.assertEqual(
+            archive_urls,
+            [
+                "https://github.com/jojolb/sooperlooper-mods/archive/refs/tags/"
+                "v1.7.9-mods.1-slweb.tar.gz"
+            ],
+        )
+
+        unit_path = self.home / config["service_destination"]
+        unit = unit_path.read_text(encoding="utf-8")
+        self.assertIn("Requires=rigforge-sooperlooper.service", unit)
+        self.assertIn("After=rigforge-sooperlooper.service", unit)
+        self.assertIn("PartOf=rigforge-sooperlooper.service", unit)
+        self.assertIn(f'WorkingDirectory="{installed_dir}"', unit)
+        self.assertIn(
+            f'ExecStart="/usr/bin/python3" tools/slweb.py --osc-host 127.0.0.1 '
+            f'--osc-port {sooperlooper["osc"]["port"]} --http-host 127.0.0.1 --http-port 8080',
+            unit,
+        )
+        self.assertEqual(
+            self.commands,
+            [
+                ["systemctl", "--user", "daemon-reload"],
+                ["systemctl", "--user", "enable", "rigforge-slweb.service"],
+                ["systemctl", "--user", "restart", "rigforge-slweb.service"],
+                ["systemctl", "--user", "is-active", "--quiet", "rigforge-slweb.service"],
+            ],
+        )
+        self.assertIn("slweb", deploy.read_registry())
+        self.assertIn("slweb_service", deploy.read_registry())
+
+        self.commands.clear()
+        with patch.object(deploy, "download_archive") as download:
+            deploy.deploy_slweb("install", config, sooperlooper, deploy.read_registry())
+        download.assert_not_called()
+        self.assertEqual(
+            self.commands,
+            [
+                ["systemctl", "--user", "daemon-reload"],
+                ["systemctl", "--user", "enable", "rigforge-slweb.service"],
+                ["systemctl", "--user", "start", "rigforge-slweb.service"],
+                ["systemctl", "--user", "is-active", "--quiet", "rigforge-slweb.service"],
+            ],
+        )
+
+        self.commands.clear()
+        deploy.deploy_slweb("uninstall", config, sooperlooper, deploy.read_registry())
+        self.assertFalse(installed_dir.exists())
+        self.assertNotIn("slweb", deploy.read_registry())
+        self.assertNotIn("slweb_service", deploy.read_registry())
+        self.assertEqual(
+            self.commands,
+            [
+                ["systemctl", "--user", "disable", "--now", "rigforge-slweb.service"],
+                ["systemctl", "--user", "daemon-reload"],
+            ],
+        )
+
+    def test_slweb_preserves_prior_tools_and_refuses_local_changes(self):
+        config = self.slweb_config()
+        sooperlooper = self.sooperlooper_config()
+        destination = self.home / config["install_directory"]
+        destination.mkdir(parents=True)
+        (destination / "owner-file").write_text("keep me", encoding="utf-8")
+        registry = deploy.read_registry()
+        registry["sooperlooper"] = {"installed_sha256": "engine"}
+        deploy.write_registry(registry)
+
+        with patch.object(
+            deploy, "download_archive", side_effect=lambda _url, path: self.make_slweb_archive(path)
+        ):
+            deploy.deploy_slweb("install", config, sooperlooper, deploy.read_registry())
+
+        backup = destination.with_name(destination.name + ".rigforge-backup")
+        self.assertEqual((backup / "owner-file").read_text(encoding="utf-8"), "keep me")
+        (destination / "tools/slweb.py").write_text("local modification", encoding="utf-8")
+        self.commands.clear()
+
+        with self.assertRaisesRegex(RuntimeError, "changed locally"):
+            deploy.deploy_slweb("uninstall", config, sooperlooper, deploy.read_registry())
+
+        self.assertTrue((destination / "tools/slweb.py").exists())
+        self.assertTrue(backup.is_dir())
+        self.assertEqual(self.commands, [])
+        (destination / "tools/slweb.py").write_text("print('slweb')\n", encoding="utf-8")
+        deploy.deploy_slweb("uninstall", config, sooperlooper, deploy.read_registry())
+        self.assertFalse((destination / "tools/slweb.py").exists())
+        self.assertEqual((destination / "owner-file").read_text(encoding="utf-8"), "keep me")
+
+    def test_slweb_install_requires_sooperlooper_service(self):
+        with patch.object(deploy, "download_archive") as download:
+            with self.assertRaisesRegex(RuntimeError, "install sooperlooper before"):
+                deploy.deploy_slweb(
+                    "install",
+                    self.slweb_config(),
+                    self.sooperlooper_config(),
+                    deploy.read_registry(),
+                )
+        download.assert_not_called()
+
     def test_mod_host_install_and_uninstall_do_not_manage_reconcile_timer(self):
         reconcile_config = self.reconcile_config()
         mod_host_config = self.mod_host_config()

+ 8 - 0
tests/test_desired_state.py

@@ -197,6 +197,14 @@ class DesiredStateValidationTests(unittest.TestCase):
         state["deployment"]["sooperlooper"]["source_url"] = "https://example.invalid/source"
         self.assertTrue(any("source_url must match" in error for error in validate_state(state)))
 
+        state = copy.deepcopy(self.state)
+        state["deployment"]["slweb"]["http_host"] = "0.0.0.0"
+        self.assertIn("deployment.slweb.http_host must be 127.0.0.1", validate_state(state))
+
+        state = copy.deepcopy(self.state)
+        state["deployment"]["slweb"]["http_port"] = 8081
+        self.assertIn("deployment.slweb.http_port must be 8080", validate_state(state))
+
         state = copy.deepcopy(self.state)
         state["deployment"]["sooperlooper"]["tag"] = "../latest"
         self.assertTrue(any("sooperlooper.tag must be a simple version tag" in error for error in validate_state(state)))