Remove ntfy: notifications go only through the app notification stream

Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat
tool notify, auto-switch and schedule notices), the chat push outbox (its
table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*.
The app_notifications stream, subscribe/clear and kinds are unchanged.
Notification settings keep run_finished/chat_needs_you/chat_reply_finished;
ntfy_enabled is accepted and ignored and its stored row is never read.

Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to
the Pipelines apps — use the stage notify hook". The notify hook remains.

Installer: no ntfy build, accounts, config or supervisor child; manifest
gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an
old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log,
with a note in logs/install.log); uninstall cleans leftovers.

App: ntfy settings section replaced by "Notification events"; texts updated.
Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli,
author skill references updated; security review M1 marked resolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 23:24:24 +00:00
parent 806b5eca46
commit fc7dbb0ac0
138 changed files with 1958 additions and 4651 deletions
+57 -235
View File
@@ -1,15 +1,13 @@
#!/usr/bin/env python3
"""Install Pipelines natively on the host (macOS and Linux).
The installer only detects the tools it needs (go, python3, node, git, curl and a C
compiler for ntfy's SQLite driver); it never installs or upgrades them, and it
never installs, upgrades or downloads OpenCode or Pi. It builds the server, CLI
and ntfy from source into a per-user prefix, generates an ntfy configuration that
mirrors compose.yaml, creates the publishing/phone accounts and writes the
manifest scripts/manage.py loads. ntfy is compiled from its pinned Go module on
every host because upstream publishes no macOS server binary. It reuses existing
host OpenCode configuration; it writes host (non-Docker) harness profiles for the
harnesses it detects and never invents a model.
The installer only detects the tools it needs (go, python3, node, git and curl);
it never installs or upgrades them, and it never installs, upgrades or downloads
OpenCode or Pi. It builds the server and CLI from source into a per-user prefix
and writes the manifest scripts/manage.py loads. Reinstalling over an install
from before ntfy was removed stops and removes that ntfy (see docs/install.md).
It reuses existing host OpenCode configuration; it writes host (non-Docker)
harness profiles for the harnesses it detects and never invents a model.
"""
import argparse
import importlib.util
@@ -41,8 +39,7 @@ def module(name, file):
configure = module("configure_compose", "configure-compose.py")
lan = module("lan_address", "lan-address.py")
release_lookup = module("resolve_releases", "resolve-releases.py")
tokens = module("save_ntfy_token", "save-ntfy-token.py")
manage = module("pipelines_manage", "manage.py")
app_build = module("app_build", "app_build.py")
web_access = module("web_access", "web_access.py")
web_password = module("pipelines_password", "password.py")
@@ -52,25 +49,16 @@ MARKER = "pipelines-install.json"
LABEL = "net.a-wan.pipelines"
SERVICE_MARKER = "Managed by Pipelines native installer"
REQUIRED_TOOLS = ("go", "python3", "git", "curl", "node")
# ntfy's SQLite driver (mattn/go-sqlite3) is cgo, so a C compiler is required to
# build the server. Upstream's macOS release asset is client-only, so both
# platforms compile ntfy from the pinned Go module.
C_COMPILERS = ("cc", "clang", "gcc")
NTFY_BUILD_TAGS = "sqlite_omit_load_extension,osusergo,netgo"
DEFAULT_NTFY_PORT = 8090
DEFAULT_SERVER_PORT = 8080
# Only the authenticated web proxy is exposed; the control API stays loopback.
DEFAULT_BIND_ADDRESS = "127.0.0.1"
class Setup:
def __init__(self, directory, prefix=None, runner=subprocess.run, resolver=None, environ=None,
popen=subprocess.Popen):
def __init__(self, directory, prefix=None, runner=subprocess.run, environ=None):
self.directory = Path(directory)
self.prefix_argument = prefix
self.runner = runner
self.popen = popen
self.resolver = resolver or release_lookup.resolve_ntfy
self.environ = environ if environ is not None else os.environ
self.verbose = False
self.install_log = None
@@ -98,17 +86,6 @@ class Setup:
# --- detection -------------------------------------------------------
def require_compiler(self):
"""ntfy is built locally, so a C toolchain must already be present."""
for compiler in C_COMPILERS:
path = shutil.which(compiler)
if path:
return str(Path(path).resolve())
raise ValueError(
"No C compiler found (tried " + ", ".join(C_COMPILERS)
+ "). ntfy's SQLite driver is cgo, so the server is compiled locally; "
"install a C toolchain (Xcode Command Line Tools on macOS, gcc or clang on Linux) and rerun.")
def require_tools(self):
found, missing = {}, []
for tool in REQUIRED_TOOLS:
@@ -333,7 +310,6 @@ class Setup:
existing = json.loads(path.read_text())
web = existing.get("web") or {}
saved = {"port": existing.get("server_port"),
"ntfy_port": existing.get("ntfy_port"),
"bind_address": existing.get("bind_address"),
"web_port": web.get("port"), "web_host": web.get("host"),
"web_lan": web.get("lan"), "web_lan_plain_login": web.get("lan_plain_login")}
@@ -584,167 +560,6 @@ class Setup:
if result.returncode:
raise ValueError("pipelines skill install failed; the native install is incomplete")
# --- ntfy server build and configuration ----------------------------
def resolve_ntfy(self):
try:
return self.resolver()
except release_lookup.ReleaseError as error:
raise ValueError(
f"Could not resolve the ntfy release ({error}); refusing to build an unverified version") from None
def build_ntfy(self, prefix, resolution):
"""Compile the ntfy server from the pinned Go module on this host.
Upstream publishes no macOS server binary (its darwin asset is built with
``-tags noserver``), so every platform builds here. The module is fetched
through the Go toolchain, which verifies it against the public checksum
database, and cgo is required for ntfy's SQLite driver.
"""
path = prefix / "bin/ntfy"
if path.is_symlink():
raise ValueError("Refusing to replace a symlinked bin/ntfy")
version = resolution.get("tag") or resolution.get("version")
module = resolution.get("module") or release_lookup.NTFY_MODULE
# A previously built binary for the same resolved version is reused.
if path.is_file() and self._existing_ntfy_version(prefix) == version:
return path
self.require_compiler()
pinned = f"{module}@{version}"
result = self.command(["go", "mod", "download", pinned], cwd=str(self.directory))
if result.returncode:
raise ValueError(f"go mod download {pinned} failed; the native install is incomplete")
cache = self.command(["go", "env", "GOMODCACHE"], cwd=str(self.directory),
capture_output=True, text=True)
if cache.returncode or not (cache.stdout or "").strip():
raise ValueError("Could not locate the Go module cache to build ntfy from")
source = Path(cache.stdout.strip()) / f"{module}@{version}"
if not source.is_dir():
raise ValueError(f"the Go module cache has no source for {pinned}")
# Keep source work in the system temp directory, but stage the output
# beside the destination: /tmp may be a different filesystem on Linux.
with tempfile.TemporaryDirectory(prefix="pipelines-ntfy-") as temporary, \
tempfile.TemporaryDirectory(prefix=".ntfy-", dir=path.parent) as staging:
checkout = Path(temporary) / "src"
shutil.copytree(source, checkout, symlinks=True)
# The module cache is read-only and carries no built web assets; the
# upstream Makefile creates the same placeholders for local builds.
self.command(["chmod", "-R", "u+w", str(checkout)])
(checkout / "server/docs").mkdir(parents=True, exist_ok=True)
(checkout / "server/site").mkdir(parents=True, exist_ok=True)
(checkout / "server/docs/index.html").touch()
(checkout / "server/site/app.html").touch()
built = Path(staging) / "ntfy"
env = dict(self.environ)
env["CGO_ENABLED"] = "1"
build = self.command(
["go", "build", "-trimpath", "-tags", NTFY_BUILD_TAGS,
"-ldflags", f"-s -w -X main.version={version}", "-o", str(built), "."],
cwd=str(checkout), env=env)
if build.returncode:
raise ValueError(
"ntfy server build failed; a working C compiler is required for its SQLite driver")
if not built.is_file():
raise ValueError("ntfy server build produced no binary")
os.chmod(built, 0o755)
os.replace(built, path)
return path
def _existing_ntfy_version(self, prefix):
manifest = prefix / MARKER
if manifest.is_symlink() or not manifest.is_file():
return None
try:
data = json.loads(manifest.read_text())
except (OSError, ValueError):
return None
return (data.get("ntfy") or {}).get("version") if isinstance(data, dict) else None
def write_ntfy_config(self, prefix, base_url, ntfy_port):
directory = prefix / "data/ntfy"
directory.mkdir(mode=0o700, exist_ok=True)
directory.chmod(0o700)
path = directory / "server.yml"
if path.is_symlink():
raise ValueError("Refusing to replace a symlinked ntfy configuration")
text = (
f'base-url: "{base_url}"\n'
f'listen-http: ":{ntfy_port}"\n'
f'cache-file: "{directory}/cache.db"\n'
'cache-duration: "168h"\n'
f'auth-file: "{directory}/auth.db"\n'
'auth-default-access: "deny-all"\n'
'enable-login: true\n'
f'attachment-cache-dir: "{directory}/attachments"\n'
'attachment-expiry-duration: "168h"\n'
'attachment-total-size-limit: "1G"\n'
'attachment-file-size-limit: "1M"\n'
)
self._write_atomic(path, text.encode(), 0o600)
return path
# --- ntfy users and publishing token --------------------------------
def ntfy(self, prefix, config_path, args, capture=False, password=None):
# The account subcommands locate the server configuration through
# NTFY_CONFIG_FILE; --config is a `serve`-only flag.
env = dict(self.environ)
env["NTFY_CONFIG_FILE"] = str(config_path)
if password is not None:
# `ntfy user add` takes the password from here instead of a prompt.
env["NTFY_PASSWORD"] = password
result = self.command([str(prefix / "bin/ntfy"), *args], capture_output=capture, text=True, env=env)
if result.returncode:
step = " ".join(args[:2])
raise ValueError(f"ntfy {step} failed; the native install is incomplete")
return result
def ensure_ntfy_auth_db(self, prefix, config_path):
"""ntfy creates its account database the first time its server runs;
the account commands refuse to run before that, so a fresh install
runs it once."""
auth = config_path.parent / "auth.db"
if auth.exists():
return
env = dict(self.environ)
process = self.popen([str(prefix / "bin/ntfy"), "serve", "--config", str(config_path)], env=env)
try:
deadline = time.monotonic() + 20
while not auth.exists():
if process.poll() is not None or time.monotonic() > deadline:
raise ValueError("ntfy did not create its account database; is its port free?")
time.sleep(0.2)
finally:
if process.poll() is None:
process.terminate()
try:
process.wait(timeout=10)
except subprocess.TimeoutExpired:
process.kill()
process.wait()
def reader_password(self, web):
"""The phone's ntfy password, which matches the web password: the one
chosen during this install, else a not yet migrated plaintext file. A
hashed file has no plaintext; an existing ntfy account keeps its own
password and a new one is asked for on the terminal."""
chosen = getattr(self, "chosen_web_password", None)
if chosen is not None:
return chosen
legacy = json.loads(Path(web["auth_file"]).read_text()).get("password")
return legacy if isinstance(legacy, str) else None
def bootstrap_ntfy(self, prefix, config_path, reader_password=None):
def run_ntfy(args, capture=False, interactive=False, password=None):
return self.ntfy(prefix, config_path, list(args), capture=capture, password=password)
self.ensure_ntfy_auth_db(prefix, config_path)
# The publisher authenticates with its token; its password is never
# needed, so it is random. The phone signs in with the web password.
tokens.bootstrap_accounts(run_ntfy, prefix / "secrets/publisher-token", 0o600,
publisher_password=secrets.token_urlsafe(24),
reader_password=reader_password)
# --- Docker migration ------------------------------------------------
def docker_volumes(self):
@@ -763,7 +578,7 @@ class Setup:
raise ValueError(
"Could not inspect Docker volumes for migration; refusing a possibly empty start")
names = set(result.stdout.split())
return tuple(name for name in ("pipelines_pipelines-data", "pipelines_ntfy-data") if name in names)
return tuple(name for name in ("pipelines_pipelines-data",) if name in names)
def _migration_image(self):
result = self.command(["docker", "image", "ls", "--format", "{{.Repository}}:{{.Tag}}"],
@@ -818,14 +633,40 @@ class Setup:
if "pipelines_pipelines-data" in volumes:
self._docker_copy_out(image, "pipelines_pipelines-data", "pipelines.db",
prefix / "data/pipelines.db", replace)
if "pipelines_ntfy-data" in volumes:
directory = prefix / "data/ntfy"
directory.mkdir(mode=0o700, exist_ok=True)
self._docker_copy_out(image, "pipelines_ntfy-data", "auth.db",
directory / "auth.db", replace)
print("Existing Docker data was migrated where it did not already exist.")
return True
# --- retired ntfy ----------------------------------------------------
def previous_manifest(self, prefix):
"""The installed manifest before this run, or {} for a fresh prefix."""
path = prefix / MARKER
if path.is_symlink() or not path.is_file():
return {}
try:
data = json.loads(path.read_text())
except (OSError, ValueError):
return {}
return data if isinstance(data, dict) else {}
def retire_ntfy(self, prefix, previous):
"""Stops and removes the ntfy an older install ran (idempotent).
The install log records what was removed and the old ntfy version first;
no credential is ever written there."""
def note(line):
if self.install_log:
self.install_log.parent.mkdir(parents=True, exist_ok=True)
with self.install_log.open("a") as log:
log.write(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] {line}\n")
removed = manage.retire_ntfy(dict(previous, prefix=str(prefix)), note=note)
if removed:
where = f" (details in {self.install_log})" if self.install_log else ""
self.step("Retired the old ntfy notification server; notifications now come through the Pipelines apps"
+ where)
return removed
# --- manifest --------------------------------------------------------
def write_manifest(self, prefix, values):
@@ -858,12 +699,8 @@ class Setup:
self.preserve_network_settings(prefix, args)
if not 1024 <= args.port <= 65535:
raise ValueError("Invalid server port; choose a value between 1024 and 65535")
if not 1024 <= args.ntfy_port <= 65535:
raise ValueError("Invalid ntfy port; choose a value between 1024 and 65535")
if args.ntfy_port == args.port:
raise ValueError("The server and ntfy ports must differ")
if not 1024 <= args.web_port <= 65535 or args.web_port in (args.port, args.ntfy_port):
raise ValueError("Web port must be between 1024 and 65535 and differ from server/ntfy ports")
if not 1024 <= args.web_port <= 65535 or args.web_port == args.port:
raise ValueError("Web port must be between 1024 and 65535 and differ from the server port")
try:
ipaddress.IPv4Address(args.bind_address)
except ValueError:
@@ -884,14 +721,7 @@ class Setup:
raise ValueError("PIPELINES_WEB_PUBLIC_URL must be an HTTP(S) web origin without credentials, path, query or fragment")
harness = self.harness()
service_path = self.service_path()
# Reuse an already built ntfy binary and skip the release lookup, so a
# reinstall with the same version makes no network requests at all.
installed = self._existing_ntfy_version(prefix)
if (prefix / "bin/ntfy").is_file() and installed:
resolution = {"module": release_lookup.NTFY_MODULE, "version": installed, "tag": installed}
else:
self.require_compiler()
resolution = self.resolve_ntfy()
previous_manifest = self.previous_manifest(prefix)
# All or nothing: the web app and the server are both built before
# either is installed, and a failed build leaves the old pair running.
self.step("Building the web app")
@@ -910,19 +740,18 @@ class Setup:
harness_path = self.configure_harnesses(harness, args.model or "")
harness_config = json.loads(harness_path.read_text())
pipeline_model = harness_config["profiles"][harness_config["default"]]["pipeline_model"]
lan_ip = lan.detect_lan()
base_url = args.ntfy_url or f"http://{lan_ip}:{args.ntfy_port}"
config_path = self.write_ntfy_config(prefix, base_url, args.ntfy_port)
self.build_ntfy(prefix, resolution)
# Migrate existing Docker data before creating native ntfy accounts so a
# migrated auth store (the phone's credentials) is preserved rather than
# shadowed by a freshly bootstrapped one.
try:
lan_ip = lan.detect_lan()
except ValueError:
# Only the printed LAN web address needs it.
lan_ip = "127.0.0.1"
if args.fresh:
print("Starting empty (--fresh); existing Docker volumes are left untouched.")
else:
self.migrate_docker(prefix, args.replace_data)
self.bootstrap_ntfy(prefix, config_path,
reader_password=self.reader_password(web))
# The new server and web app are in place: the old ntfy goes now,
# before the new manifest (which has no ntfy) replaces the old one.
self.retire_ntfy(prefix, previous_manifest)
timezone = args.timezone
if not timezone:
try:
@@ -940,19 +769,17 @@ class Setup:
path_value = str(prefix / "bin") + os.pathsep + self.environ.get("PATH", "")
manifest = {
"format": 1,
# Marks the native installer (older manifests used ntfy.mode).
"mode": "native",
"allow_authoring": allow_authoring,
"prefix": str(prefix),
"python": python,
"server_port": args.port,
"bind_address": args.bind_address,
"ntfy_port": args.ntfy_port,
"opencode": harness["opencode"],
"pi": harness["pi"],
"opencode_env": opencode_env,
"path": path_value,
"topic": "pipelines",
"public_url": base_url,
"username": "phone-reader",
"workspace": str(Path.home()),
"launcher": str(prefix / "bin/pipelines"),
"registration": None,
@@ -960,9 +787,6 @@ class Setup:
"docker": "docker",
"project": "pipelines",
"timezone": timezone,
"ntfy": {"mode": "native", "bin": str(prefix / "bin/ntfy"),
"config": str(config_path), "base_url": base_url,
"version": resolution.get("tag") or resolution.get("version")},
"web": web,
# `pipelines update` re-runs this installer from here, the same way.
"source": str(self.directory),
@@ -976,14 +800,14 @@ class Setup:
endpoint = f"ws://127.0.0.1:{args.port}/connect"
client_path = configure.configure_client(endpoint, self.environ)
self.step("Starting the services")
# Parity with the Docker installer: leave the server and ntfy running.
# Parity with the Docker installer: leave the server and web proxy running.
started = self.command([python, str(prefix / "lib/manage.py"), "start", "--prefix", str(prefix)])
if started.returncode:
raise ValueError(
"The native services were installed but could not be started; run "
f"'PIPELINES_PREFIX={prefix} {prefix}/bin/pipelines start' to see the error. "
"Check your login service manager and that ports "
f"{args.port}, {args.ntfy_port} and {args.web_port} are free (a running Docker installation may use them).")
f"{args.port} and {args.web_port} are free (a running Docker installation may use them).")
self.retire_legacy_web()
self.serve_on_tailnet(opencode_env["PIPELINES_WEB_PUBLIC_URL"], args.web_port)
print("\nPipelines installed")
@@ -1003,7 +827,6 @@ class Setup:
def arguments(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--prefix", type=Path, help="Installation prefix (default: ~/.local/share/pipelines)")
parser.add_argument("--ntfy-url", help="Override the auto-detected LAN ntfy address")
parser.add_argument("--timezone", help="Override the detected timezone (fallback: UTC)")
parser.add_argument("--port", type=int, default=DEFAULT_SERVER_PORT, help="Pipelines server port")
parser.add_argument("--web-port", type=int, default=8082, help="Authenticated web proxy port (default 8082)")
@@ -1018,7 +841,6 @@ def arguments(argv=None):
"(unencrypted; only on a trusted network)")
parser.add_argument("--bind-address", default=DEFAULT_BIND_ADDRESS,
help="Unauthenticated server bind address (default 127.0.0.1; expose only the web proxy)")
parser.add_argument("--ntfy-port", type=int, default=DEFAULT_NTFY_PORT, help="ntfy listen port")
parser.add_argument("--model", help="Explicit PROVIDER/MODEL for starter defaults and missing profile fields; "
"otherwise reuse saved/default OpenCode models or choose within this installer")
role = parser.add_mutually_exclusive_group()
@@ -1029,7 +851,7 @@ def arguments(argv=None):
parser.add_argument("--fresh", action="store_true",
help="Start with empty data even when an earlier Docker installation's volumes exist")
parser.add_argument("--replace-data", action="store_true",
help="Allow Docker migration to replace an existing native database/auth store")
help="Allow Docker migration to replace an existing native database")
parser.add_argument("--verbose", action="store_true", help="Show full build and tool output")
parsed = parser.parse_args(argv)
parsed.argv = list(sys.argv[1:] if argv is None else argv)