Files
pipelines/internal/installation/installation.go
T
alan fc7dbb0ac0 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>
2026-12-03 23:24:24 +00:00

123 lines
3.9 KiB
Go

// Package installation binds the compiled CLI to its per-user managed services.
package installation
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strconv"
)
type Config struct {
Format int `json:"format"`
Prefix string `json:"prefix"`
Python string `json:"python"`
ServerPort int `json:"server_port"`
OpenCode string `json:"opencode"`
OpenCodeEnv map[string]string `json:"opencode_env"`
Path string `json:"path"`
// Mode is "native" for a native installation (the per-user supervisor)
// and "docker" or empty for Compose.
Mode string `json:"mode"`
// LegacyNtfy is read only for its mode: manifests written before ntfy was
// removed recorded a native installation as ntfy.mode "native".
LegacyNtfy struct {
Mode string `json:"mode"`
} `json:"ntfy"`
Web struct {
// ServerTokenFile is the shared server secret (internal/servertoken).
ServerTokenFile string `json:"server_token_file"`
} `json:"web"`
}
// Load selects an explicit prefix, or a native installation containing this exact
// executable. It never guesses a default prefix for an unrelated Go-installed CLI.
func Load(executable string) (*Config, error) {
prefix := os.Getenv("PIPELINES_PREFIX")
inferred := prefix == ""
if prefix == "" {
resolved, err := filepath.EvalSymlinks(executable)
if err != nil || filepath.Base(resolved) != "pipelines" || filepath.Base(filepath.Dir(resolved)) != "bin" {
return nil, nil
}
prefix = filepath.Dir(filepath.Dir(resolved))
}
prefix, err := filepath.Abs(prefix)
if err != nil {
return nil, err
}
// The native installer and scripts/manage.py record the symlink-resolved
// prefix, so resolve the same way here instead of rejecting a symlinked
// HOME or prefix as "invalid".
if resolved, err := filepath.EvalSymlinks(prefix); err == nil {
prefix = resolved
}
manifest := filepath.Join(prefix, "pipelines-install.json")
info, err := os.Lstat(manifest)
if os.IsNotExist(err) {
return nil, nil
}
if err != nil {
return nil, err
}
if !info.Mode().IsRegular() || !ownedByUser(info) {
return nil, fmt.Errorf("refusing installation manifest not a regular file owned by this user")
}
data, err := os.ReadFile(manifest)
if err != nil {
return nil, err
}
var config Config
if err = json.Unmarshal(data, &config); err != nil {
return nil, err
}
if config.Format != 1 || config.Prefix != prefix || config.ServerPort < 1024 || config.ServerPort > 65535 {
return nil, fmt.Errorf("invalid managed installation manifest")
}
if inferred && !config.Native() {
return nil, nil
}
if inferred {
binary, err := os.Stat(filepath.Join(prefix, "bin", "pipelines"))
if err != nil || !binary.Mode().IsRegular() || binary.Mode().Perm()&0111 == 0 || !ownedByUser(binary) {
return nil, fmt.Errorf("native installation executable must be owned by this user")
}
}
return &config, nil
}
// Native reports whether the manifest describes a native installation, in the
// current form or the one written before ntfy was removed.
func (c Config) Native() bool {
return c.Mode == "native" || (c.Mode == "" && c.LegacyNtfy.Mode == "native")
}
func (c Config) Environment() error {
for key, value := range c.OpenCodeEnv {
switch key {
case "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "OPENCODE_SERVER", "OPENCODE_DB":
if err := os.Setenv(key, value); err != nil {
return err
}
}
}
for key, value := range map[string]string{"PIPELINES_URL": "ws://127.0.0.1:" + strconv.Itoa(c.ServerPort) + "/connect", "PIPELINES_OPENCODE": c.OpenCode, "PIPELINES_SERVER_TOKEN_FILE": c.Web.ServerTokenFile} {
if os.Getenv(key) != "" || value == "" {
continue
}
if err := os.Setenv(key, value); err != nil {
return err
}
}
return nil
}
func Service(action string) bool {
switch action {
case "start", "stop", "restart", "doctor", "logs", "uninstall", "update":
return true
}
return false
}