Simplify Go installation and support standard OpenCode releases
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN CGO_ENABLED=0 go build -trimpath -o /out/pipelines-server ./cmd/server
|
||||
RUN CGO_ENABLED=0 go build -trimpath -o /out/pipelines-server ./cmd/pipelines-server
|
||||
|
||||
FROM ghcr.io/anomalyco/opencode:2.0.20
|
||||
USER root
|
||||
|
||||
@@ -5,28 +5,34 @@ server reuse your OpenCode login; Docker ntfy handles phone notifications.
|
||||
|
||||
## Install
|
||||
|
||||
Requires **Go 1.27+**, Python 3, Docker with Compose running, and OpenCode V2
|
||||
connected to OpenCode Go.
|
||||
Requires **Go 1.27+** to install. Use your existing OpenCode for model stages;
|
||||
Docker/ntfy notifications are optional.
|
||||
|
||||
```sh
|
||||
git clone https://git.a-wan.net/alan/pipelines.git
|
||||
cd pipelines
|
||||
./install.sh --system-command
|
||||
go install ./cmd/...
|
||||
pipelines help
|
||||
```
|
||||
|
||||
The installer builds with `go install` and exposes the Go `pipelines` binary in `/usr/local/bin`.
|
||||
Run as your normal user: sudo is used only for the system command link. Services
|
||||
and credentials remain per-user. Setup asks for your phone username, password,
|
||||
and notification topic. Fresh installations contain no pipelines.
|
||||
Go uses `GOBIN` or its normal `GOPATH/bin` default; put that directory on PATH.
|
||||
`./install.sh` runs the same installation. It installs binaries only—no login
|
||||
checks, dependency installers, hardcoded install paths, or automatic services.
|
||||
For system-wide use, install the binaries into your chosen system bin directory
|
||||
with the appropriate permissions. Configuration and data remain per-user.
|
||||
|
||||
Prefer a user-local command? Use `./install.sh` instead (`~/.local/bin/pipelines`).
|
||||
Start explicitly; fresh databases contain no pipelines:
|
||||
|
||||
```sh
|
||||
pipelines serve -workspace-root "$HOME" # foreground server
|
||||
# In another terminal:
|
||||
pipelines
|
||||
```
|
||||
|
||||
## Uninstall
|
||||
|
||||
```sh
|
||||
pipelines uninstall # keep history, credentials, and ntfy data
|
||||
pipelines uninstall --purge # explicitly delete this installation's data
|
||||
pipelines uninstall # remove Go binaries; keep history, drafts, and ntfy data
|
||||
```
|
||||
|
||||
## A three-stage pipeline
|
||||
@@ -89,9 +95,8 @@ pipelines validate /path/to/draft.md
|
||||
pipelines submit /path/to/draft.md # explicit publication
|
||||
pipelines runs
|
||||
pipelines inspect 1
|
||||
pipelines start # manages server + ntfy together
|
||||
pipelines stop
|
||||
pipelines doctor
|
||||
pipelines serve # foreground server; Ctrl+C stops it
|
||||
pipelines ping
|
||||
pipelines help edit
|
||||
```
|
||||
|
||||
|
||||
@@ -12,13 +12,18 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/server"
|
||||
"git.a-wan.net/alan/pipelines/internal/paths"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
addr := flag.String("addr", "127.0.0.1:8080", "HTTP/WebSocket listen address")
|
||||
db := flag.String("db", "pipelines.db", "SQLite database path")
|
||||
defaultDB, err := paths.Database()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
db := flag.String("db", defaultDB, "SQLite database path (honors XDG_DATA_HOME)")
|
||||
var roots []string
|
||||
flag.Func("workspace-root", "Allow repository runs below this directory (repeatable; default is server working directory)", func(value string) error {
|
||||
absolute, err := filepath.Abs(value)
|
||||
@@ -40,6 +45,9 @@ func main() {
|
||||
return nil
|
||||
})
|
||||
flag.Parse()
|
||||
if err := os.MkdirAll(filepath.Dir(*db), 0700); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
store, err := pipeline.Open(*db)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"pipelines/internal/tui"
|
||||
"git.a-wan.net/alan/pipelines/internal/tui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
+27
-3
@@ -4,11 +4,12 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/cli"
|
||||
"git.a-wan.net/alan/pipelines/internal/installation"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"pipelines/internal/cli"
|
||||
"pipelines/internal/installation"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
@@ -31,8 +32,31 @@ func main() {
|
||||
args = []string{"tui"}
|
||||
}
|
||||
}
|
||||
if err == nil && config == nil && len(args) > 0 && args[0] == "uninstall" {
|
||||
err = installation.Uninstall(executable, args[1:], os.Stdin, os.Stdout)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err == nil && config == nil && len(args) > 0 && args[0] == "serve" {
|
||||
server, findErr := exec.LookPath("pipelines-server")
|
||||
if findErr != nil {
|
||||
resolved, resolveErr := filepath.EvalSymlinks(executable)
|
||||
if resolveErr != nil {
|
||||
err = resolveErr
|
||||
} else {
|
||||
server = filepath.Join(filepath.Dir(resolved), "pipelines-server")
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
err = syscall.Exec(server, append([]string{server}, args[1:]...), os.Environ())
|
||||
}
|
||||
}
|
||||
if err == nil && len(args) > 0 && installation.Service(args[0]) {
|
||||
err = fmt.Errorf("%s requires a managed installation; run install.sh first", args[0])
|
||||
err = fmt.Errorf("%s is a legacy managed-service command; use pipelines serve, or select an existing installation with PIPELINES_PREFIX", args[0])
|
||||
}
|
||||
if err == nil && len(args) == 0 {
|
||||
args = []string{"tui"}
|
||||
}
|
||||
if err == nil {
|
||||
err = app.Run(ctx, args)
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ To reuse your host OpenCode login without container authentication:
|
||||
docker compose up -d ntfy
|
||||
# Bootstrap ntfy users/token as described below, then:
|
||||
sh scripts/run-local-server.sh
|
||||
go run ./cmd/tui -url ws://127.0.0.1:8080/connect
|
||||
go run ./cmd/pipelines-tui -url ws://127.0.0.1:8080/connect
|
||||
```
|
||||
|
||||
Do not run `docker compose up -d` for this mode: that starts the pipeline container
|
||||
@@ -100,7 +100,7 @@ The Docker workspace is persistent and separate from your host checkout.
|
||||
Connect the native TUI:
|
||||
|
||||
```sh
|
||||
go run ./cmd/tui -url ws://127.0.0.1:8081/connect
|
||||
go run ./cmd/pipelines-tui -url ws://127.0.0.1:8081/connect
|
||||
```
|
||||
|
||||
If the TUI is on another machine, use an SSH/VPN tunnel instead of exposing the
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# Installation review
|
||||
|
||||
Two independent reviewers examined installation conventions and stable OpenCode
|
||||
compatibility. Both agreed that removing the V2 gate alone would hide real API
|
||||
incompatibility rather than fix it.
|
||||
|
||||
## Findings addressed
|
||||
|
||||
- Installation mixed binary building with Docker provisioning, provider login,
|
||||
private npm installation, service registration, and startup. It is now a thin
|
||||
standard `go install ./cmd/...` operation, with no runtime checks or side effects.
|
||||
- Go's repository import path did not match `go.mod`. The module now matches the
|
||||
repository, enabling normal module installation (with `GOPRIVATE` for private access).
|
||||
- Generic `server`/`tui` commands required renaming and a custom layout. They are
|
||||
now `pipelines-server` and `pipelines-tui`, installed directly by Go.
|
||||
- Runtime configuration was guessed relative to the binary, and a saved PATH
|
||||
overrode the caller. Standard locations/explicit flags now select data; legacy
|
||||
setup requires an explicit `PIPELINES_PREFIX`, and the caller's PATH is preserved.
|
||||
- Native stable OpenCode has no equivalent to the V2 CLI/API contract. It now has
|
||||
a separate HTTP adapter, using the existing executable/account, strict JSON
|
||||
contracts, explicit models, translated scoped permissions, and an owned loopback
|
||||
service. The existing V2 adapter is retained rather than pretending APIs match.
|
||||
- Crash ownership must include the backend and native service. Additive metadata
|
||||
records those references without rewriting immutable definitions or histories.
|
||||
- The skill name did not match its directory. It is now `pipelines`. Native
|
||||
authoring preloads the skill/reference text without inference; V2 activates it.
|
||||
- Ownership persistence failure and authoring `SESSION` write failure could leak
|
||||
created sessions. Those failure paths now clean up only their owned sessions.
|
||||
|
||||
## Deliberately removed from default installation
|
||||
|
||||
Private dependency installs, login prompts, mandatory notifications, automatic
|
||||
LAN HTTP exposure, generated system bin symlinks, private binary prefixes, and a
|
||||
second background supervisor. Configure optional services separately using normal
|
||||
OS tools. The old managed installation helper remains only for explicit legacy
|
||||
data/lifecycle access; it is not the standard installer.
|
||||
|
||||
## Verification limitations
|
||||
|
||||
The reviewer checked official stable OpenCode 1.18.35 in isolation and found V2
|
||||
bridge URLs that return HTTP 200 **HTML**. The adapter rejects non-JSON responses.
|
||||
No live inference or real model tool-permission enforcement was run. See
|
||||
[verification scope](installation-verification.md); do not confuse successful
|
||||
installation or stored permission rules with proven model execution.
|
||||
+78
-75
@@ -1,101 +1,104 @@
|
||||
# Install and test
|
||||
# Installation
|
||||
|
||||
Run as your normal user, **not** with sudo. Requires Python 3, a running Docker
|
||||
daemon with Compose, and OpenCode V2 connected to OpenCode Go. Source installs
|
||||
also require Go 1.27+. Platform archives contain the server, CLI, and TUI binaries. If OpenCode
|
||||
is absent and npm is available, the installer offers a private pinned CLI install;
|
||||
Docker itself is not installed automatically.
|
||||
Installation requires **Go only**. OpenCode is needed when authoring or executing
|
||||
model stages. Docker/ntfy is optional and is configured separately.
|
||||
|
||||
```sh
|
||||
./install.sh
|
||||
# Optional: expose the command in /usr/local/bin (sudo for the symlink only):
|
||||
./install.sh --system-command
|
||||
git clone https://git.a-wan.net/alan/pipelines.git
|
||||
cd pipelines
|
||||
go install ./cmd/...
|
||||
# ./install.sh is a thin wrapper around the same command.
|
||||
```
|
||||
|
||||
Setup prompts for phone username, password, and global notification topic. Blank
|
||||
password generates one. `--yes` accepts defaults and generates a password;
|
||||
`--password-file PATH` supplies one without putting it in shell arguments.
|
||||
Phone connection details are saved privately in
|
||||
`~/.local/share/pipelines/secrets/phone-login.txt`. Configure the ntfy phone app
|
||||
with those credentials and subscribe to that topic. Phone delivery still needs
|
||||
an actual device test. Prefer Tailscale or HTTPS; HTTP exposes credentials on an
|
||||
untrusted network.
|
||||
This installs `pipelines`, `pipelines-server`, and `pipelines-tui`. Go chooses the
|
||||
destination using `GOBIN`, or the usual `GOPATH/bin` default. Put that directory
|
||||
on PATH. No privileged operations, private dependency installation, login prompts,
|
||||
Docker provisioning, service registration, or background processes are involved.
|
||||
Re-running installation updates the binaries without changing data or configuration.
|
||||
|
||||
The native server and Docker ntfy are managed together:
|
||||
For a private repository, use your normal Git credentials and `GOPRIVATE`:
|
||||
|
||||
```sh
|
||||
pipelines # dashboard; b opens rendered templates
|
||||
pipelines status
|
||||
pipelines doctor
|
||||
pipelines stop
|
||||
pipelines start
|
||||
pipelines restart
|
||||
pipelines logs
|
||||
GOPRIVATE=git.a-wan.net go install git.a-wan.net/alan/pipelines/cmd/...@latest
|
||||
```
|
||||
|
||||
Default command path is `~/.local/bin/pipelines`; add `~/.local/bin` to PATH if
|
||||
needed. It points directly to a compiled Go binary, not a shell launcher.
|
||||
Source installation builds all binaries with `go install`. Service registration uses
|
||||
per-user launchd on macOS or systemd on Linux.
|
||||
`--no-autostart` uses background supervision instead. Services retain the current
|
||||
user's OpenCode config/login, without exporting credentials into Docker.
|
||||
`--system-command` is a system PATH shortcut to this user's install, **not** a
|
||||
shared multi-user service. Other users should install their own instance.
|
||||
For a system-wide command, build as your normal user and install the three binaries
|
||||
into an administrator-selected bin directory using your normal system permissions.
|
||||
Services and OpenCode accounts still run as the logged-in user, never as root.
|
||||
The installer does not hardcode a system destination or run sudo.
|
||||
|
||||
## Run in a repository
|
||||
## Start explicitly
|
||||
|
||||
```sh
|
||||
cd ~/repos/my-project
|
||||
pipelines run # fuzzy pipeline picker, then prompt
|
||||
pipelines run "bug fix" # prompt composer
|
||||
pipelines run "bug fix" "Fix the layout" # explicit execution confirmation
|
||||
pipelines run "bug fix" "Fix the layout" --yes
|
||||
pipelines serve -workspace-root "$HOME" # foreground server; Ctrl+C stops it
|
||||
# In another terminal:
|
||||
pipelines
|
||||
```
|
||||
|
||||
The composer supports multiline typing/paste: **Enter** adds a newline,
|
||||
**Ctrl+S** or **Alt+Enter** continues. The current directory is recorded as the
|
||||
run workspace. After confirmation, the live run inspector opens.
|
||||
`--yes` requires a supplied name and nonempty prompt and does not approve tools.
|
||||
Use `--allow-tools` with `--yes` to explicitly approve declared tools;
|
||||
`--write-paths "internal/example.go"` grants exact existing Go-file edits.
|
||||
Current edit tooling is Go-specific, not arbitrary repository editing.
|
||||
The server listens on loopback. Limit `-workspace-root` to trusted repositories;
|
||||
repeat the flag for multiple roots. Omission permits only the server's working
|
||||
directory. Runtime repository requests cannot escape these roots via symlinks.
|
||||
|
||||
Installer workspace roots default to the user's home directory. Restrict them
|
||||
using repeatable `--workspace-root ~/repos` on initial setup. Runs outside those
|
||||
roots (including symlink escapes) are rejected by the server. Raw native servers
|
||||
default to their working directory; add `-workspace-root` to permit other repos.
|
||||
Do not expose the unauthenticated pipeline server to untrusted users.
|
||||
The SQLite database uses the standard user data location, honoring `XDG_DATA_HOME`
|
||||
when set. On macOS it uses the user Application Support directory. `-db FILE`
|
||||
selects another database, including an existing one; nothing is imported or moved
|
||||
automatically. `pipelines serve --help` prints the actual defaults on your machine.
|
||||
Drafts use the OS user cache; `PIPELINES_DRAFT_DIR` overrides that location.
|
||||
|
||||
## Templates and data
|
||||
Use your OS's normal service manager if you want autostart. Pipelines does not
|
||||
install a second supervisor. Native foreground startup is the default.
|
||||
|
||||
New databases are empty. Press **b** on Home or use `:templates` to browse optional
|
||||
examples, with rendered Markdown previews and **v** for source. Select a template,
|
||||
choose a unique name, edit it in `$VISUAL`/`$EDITOR` (or an available fallback),
|
||||
then explicitly submit. Existing names cannot be overwritten by this flow.
|
||||
Submitting a scheduled template activates its schedule; previewing never does.
|
||||
## OpenCode
|
||||
|
||||
Uninstall retains pipeline history, credentials, and the isolated ntfy volume:
|
||||
Use your existing `opencode` on PATH, or set `PIPELINES_OPENCODE` to an explicit
|
||||
executable. No OpenCode version is required just to install binaries. At runtime:
|
||||
|
||||
- The standard/native API release uses an owned, authenticated loopback
|
||||
`opencode serve` process, scoped to the requested repository and using the
|
||||
existing user's configuration/login. The API, not a version number, is checked.
|
||||
- A CLI advertising `api` uses the V2 command interface and its normal discovery.
|
||||
- Both adapters select the pipeline's configured model explicitly and preserve
|
||||
stage tool permissions. Native `shell` permissions map to OpenCode's `bash`.
|
||||
- Audited native sessions record their backend and a private service reference
|
||||
so recovery addresses the same service, rather than a new unrelated instance.
|
||||
- `new`/`edit` preload authoring instructions before opening the normal interface.
|
||||
Native preloading uses `noReply=true`; V2 uses explicit skill activation.
|
||||
|
||||
The bundled examples retain `opencode-go/deepseek-v4.1-flash`. Availability and
|
||||
authentication for that model are runtime requirements, not installation checks.
|
||||
No login or provider credentials are copied or exported by Pipelines.
|
||||
|
||||
## Optional notifications
|
||||
|
||||
Use an existing ntfy server or the optional Docker setup in [docs/ntfy.md](ntfy.md).
|
||||
Configure `PIPELINES_NTFY_URL`, `PIPELINES_NTFY_PUBLIC_URL`, and a publishing token
|
||||
via `PIPELINES_NTFY_TOKEN_FILE` in the server's environment. Keep secrets out of
|
||||
pipeline definitions. Use HTTPS or an encrypted VPN for phone access; do not
|
||||
expose an unauthenticated pipeline server or HTTP credentials to untrusted networks.
|
||||
|
||||
## Uninstall
|
||||
|
||||
Stop the foreground server first, then:
|
||||
|
||||
```sh
|
||||
./uninstall.sh
|
||||
# Explicitly delete this installation's retained data too:
|
||||
./uninstall.sh --purge
|
||||
pipelines uninstall
|
||||
# or pipelines uninstall --yes
|
||||
```
|
||||
|
||||
Reinstall at the same prefix to reuse retained data. Host OpenCode remains
|
||||
separate. Partial installations require inspection or explicit purge before retry.
|
||||
Use `--prefix PATH --bin-dir PATH --server-port PORT --ntfy-port PORT` for isolated
|
||||
testing; each prefix has its own Compose project and volume.
|
||||
Only Go binaries whose embedded build metadata matches this repository are
|
||||
removed from the current command's bin directory. History, drafts, OpenCode,
|
||||
and optional ntfy data remain untouched. Use the permissions appropriate to your
|
||||
chosen bin directory. Custom database paths cannot be inferred, so uninstallation
|
||||
does not purge data.
|
||||
|
||||
## Tester archives
|
||||
## Existing managed installations
|
||||
|
||||
```sh
|
||||
python3 scripts/package.py --platform darwin-arm64 --version 0.1.0-beta.1
|
||||
# Also: darwin-amd64, linux-amd64, linux-arm64, source
|
||||
```
|
||||
The previous Python-supervised setup is retained only for explicit legacy use.
|
||||
Set `PIPELINES_PREFIX` to its existing directory for its lifecycle commands;
|
||||
no command infers that directory from an executable location. The old
|
||||
`--system-command`, provisioning, and autostart installer flags have been removed.
|
||||
|
||||
Outputs go to `dist/` with a SHA-256 checksum. Archives include only allowlisted
|
||||
source, examples, docs, installation scripts, and optional release binaries—no
|
||||
databases, runtime drafts, `.env`, logs, or secrets. Extract, then run `./install.sh`.
|
||||
Cross-built Linux binaries, Linux systemd, system PATH installation, and automatic
|
||||
npm installation require separate execution tests; build success is not a runtime test.
|
||||
To migrate, stop the old server first, install normal Go binaries, and start with
|
||||
`pipelines serve -db EXISTING_DATABASE -workspace-root TRUSTED_ROOT`. Keep the old
|
||||
data and credentials until you have verified the new setup. There is no automatic
|
||||
purge, database move, login migration, or shared OpenCode service modification.
|
||||
|
||||
@@ -1,52 +1,26 @@
|
||||
# Installation verification
|
||||
# Verification scope
|
||||
|
||||
Executed on macOS (arm64), using an isolated prefix and ports 18080/18090;
|
||||
the development database and services were not targets of these checks.
|
||||
Regression commands:
|
||||
|
||||
- `go test -race -count=1 ./...`: passed, including fresh empty database,
|
||||
template catalog/create-only protection, workspace allowlisting and symlink
|
||||
rejection, multiline prompt, and run-state regressions.
|
||||
- `go vet ./...`: passed.
|
||||
- `python3 -m unittest discover -s scripts -p 'test_*.py'`: 14 passed (including
|
||||
unchanged argument forwarding to the shared CLI).
|
||||
- `./install.sh --yes --no-autostart --prefix <isolated> --bin-dir <isolated>`:
|
||||
installed native binaries plus isolated Docker ntfy, with private credentials.
|
||||
- Isolated `pipelines doctor`: both health endpoints and host OpenCode API passed.
|
||||
- Actual pseudo-terminal check (`check-install-cli.py` in the session's temporary
|
||||
storage): rendered template browser, editor return without automatic submission,
|
||||
explicit submission, fuzzy CLI selection, multiline composer, and supplied
|
||||
name/prompt confirmation passed.
|
||||
- Isolated `pipelines restart`, retained-data uninstall, reinstall, and a second
|
||||
terminal check: passed; the submitted pipeline survived reinstall.
|
||||
- Authenticated HTTP publication and phone-reader polling: passed. Actual Android
|
||||
app reception is **not tested**.
|
||||
```sh
|
||||
go test -race -count=1 ./...
|
||||
go vet ./...
|
||||
python3 -m unittest discover -s scripts -p 'test_*.py'
|
||||
```
|
||||
|
||||
Full model-driven repository changes, launchd autostart, Linux systemd, privileged
|
||||
`--system-command`, and automatic npm CLI installation are **not tested**.
|
||||
Existing Go-file edit-scope restrictions still apply.
|
||||
Optional no-inference stable OpenCode checks:
|
||||
|
||||
## CLI authoring checks
|
||||
```sh
|
||||
PIPELINES_TEST_OPENCODE_V1=/path/to/opencode \
|
||||
go test ./internal/opencode ./internal/author -run TestStable -count=1 -v
|
||||
```
|
||||
|
||||
- `check-author-cli.py` (session temporary storage): isolated installed help,
|
||||
JSON draft/validate/submit/export/history, and real OpenCode session/skill
|
||||
activation passed. Interactive launch arguments were captured without a model turn.
|
||||
- `check-author-picker.py`: actual terminal fuzzy `edit` selection, draft creation,
|
||||
and real skill preload passed, again without a model turn.
|
||||
- CLI/server regression tests cover stale-version rejection, invalid submission
|
||||
rejection even with `--force`, create-only collisions, headless run idempotency,
|
||||
inspection/cancellation, and bounded waiting that leaves an active run intact
|
||||
on timeout. Execution is controlled in these tests, not a live model.
|
||||
The stable checks use isolated home/config/data/cache directories; they never
|
||||
copy login credentials or invoke a model. They exercise session creation, explicit
|
||||
model selection, stored scoped permissions, abort on the same owned service,
|
||||
session deletion, and authoring instruction preload with `noReply=true`.
|
||||
|
||||
Full interactive model-driven pipeline authoring is **not tested**.
|
||||
|
||||
## Compiled Go command
|
||||
|
||||
- `GOBIN=<isolated> go install ./cmd/pipelines ./cmd/server ./cmd/tui`: passed.
|
||||
- Source installer now uses `go install`; isolated installation and retained-data
|
||||
reinstall passed. The command symlink resolved to a Mach-O Go binary, not a script.
|
||||
- Compiled command `help`, `list --json`, README three-stage example validation /
|
||||
submission, `doctor`, and `restart`: passed against isolated services.
|
||||
- A separately Go-installed CLI selected the same installation using
|
||||
`PIPELINES_PREFIX` and read the retained pipeline successfully.
|
||||
|
||||
Privileged `/usr/local/bin` linking, launchd, and Linux remain **not tested**.
|
||||
Native generation/assistant completion parsing is regression-tested against a
|
||||
controlled HTTP server. Full live inference, permission enforcement by real model
|
||||
tool calls, cancellation during inference, optional Docker deployment, privileged
|
||||
system-wide copying, and OS service-manager registration are **not tested**.
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ Configure the **pipeline server process** outside the pipeline file:
|
||||
```sh
|
||||
export PIPELINES_NTFY_ANIME_URL='https://ntfy.your-domain.example/anime'
|
||||
# Set PIPELINES_NTFY_ANIME_TOKEN securely to a publishing user's access token.
|
||||
go run ./cmd/server
|
||||
go run ./cmd/pipelines-server
|
||||
```
|
||||
|
||||
The URL includes one topic, without credentials, query parameters, or a fragment.
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package examples
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package examples_test
|
||||
|
||||
import (
|
||||
"git.a-wan.net/alan/pipelines/examples"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"os"
|
||||
"pipelines/examples"
|
||||
"pipelines/internal/pipeline"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module pipelines
|
||||
module git.a-wan.net/alan/pipelines
|
||||
|
||||
go 1.27.0
|
||||
|
||||
|
||||
+6
-1
@@ -1,3 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
exec python3 "$(dirname "$0")/scripts/install.py" "$@"
|
||||
if [ "$#" -ne 0 ]; then
|
||||
echo 'Usage: ./install.sh (honors GOBIN and GOPATH; installs binaries only)' >&2
|
||||
exit 2
|
||||
fi
|
||||
cd "$(dirname "$0")"
|
||||
exec go install -trimpath ./cmd/...
|
||||
|
||||
@@ -5,11 +5,13 @@ import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"pipelines/internal/draft"
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:embed skill/SKILL.md skill/references/format.md
|
||||
@@ -47,6 +49,14 @@ func Workspace(d draft.Draft) (string, error) {
|
||||
// PrepareSession explicitly loads the skill without starting a model turn.
|
||||
// The existing user's CLI handles discovery and authentication; no auth is exported.
|
||||
func PrepareSession(ctx context.Context, executable, workspace, name string) (string, error) {
|
||||
connection, err := opencode.Open(ctx, executable, workspace, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer connection.Close()
|
||||
if connection.Backend == "v1" {
|
||||
return prepareNative(ctx, connection, workspace, name)
|
||||
}
|
||||
call := func(method, path string, body any) ([]byte, error) {
|
||||
args := []string{"api", method, path}
|
||||
if body != nil {
|
||||
@@ -82,11 +92,41 @@ func PrepareSession(ctx context.Context, executable, workspace, name string) (st
|
||||
return "", err
|
||||
}
|
||||
if err = os.WriteFile(filepath.Join(workspace, "SESSION"), []byte(id+"\n"), 0600); err != nil {
|
||||
_, _ = call("delete", "/api/session/"+id, nil)
|
||||
return "", err
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func prepareNative(ctx context.Context, connection *opencode.Connection, workspace, name string) (id string, err error) {
|
||||
data, err := connection.Native(ctx, "post", "/session", map[string]string{"title": "Pipeline draft: " + name})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var result struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
if json.Unmarshal(data, &result) != nil || !regexp.MustCompile(`^ses[a-zA-Z0-9_-]+$`).MatchString(result.ID) {
|
||||
return "", fmt.Errorf("invalid OpenCode native session")
|
||||
}
|
||||
id = result.ID
|
||||
defer func() {
|
||||
if err != nil {
|
||||
cleanup, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
|
||||
defer cancel()
|
||||
_, _ = connection.Native(cleanup, "delete", "/session/"+id, nil)
|
||||
}
|
||||
}()
|
||||
skill, _ := content.ReadFile("skill/SKILL.md")
|
||||
reference, _ := content.ReadFile("skill/references/format.md")
|
||||
instructions := "Pipeline authoring skill (preloaded; no inference requested):\n" + string(skill) + "\nDefinition reference:\n" + string(reference)
|
||||
if _, err = connection.Native(ctx, "post", "/session/"+id+"/message", map[string]any{"noReply": true, "parts": []map[string]string{{"type": "text", "text": instructions}}}); err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = os.WriteFile(filepath.Join(workspace, "SESSION"), []byte(id+"\n"), 0600)
|
||||
return id, err
|
||||
}
|
||||
|
||||
func Prompt(d draft.Draft, request, command string) string {
|
||||
if request == "" {
|
||||
request = "Ask me what this pipeline should do or what to change, then help me edit its draft."
|
||||
|
||||
@@ -2,9 +2,9 @@ package author
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"pipelines/internal/draft"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -21,7 +21,7 @@ func TestSkillActivationIsExplicitAndNoResume(t *testing.T) {
|
||||
}
|
||||
capture := filepath.Join(t.TempDir(), "calls")
|
||||
script := filepath.Join(t.TempDir(), "opencode")
|
||||
os.WriteFile(script, []byte("#!/bin/sh\nprintf '%s\\n' \"$@\" >> '"+capture+"'\nif [ \"$3\" = /api/session ]; then printf '%s' '{\"data\":{\"id\":\"ses_test\"}}'; fi\n"), 0700)
|
||||
os.WriteFile(script, []byte("#!/bin/sh\nif [ \"$1\" = --help ]; then printf '%s\\n' ' api commands'; exit 0; fi\nprintf '%s\\n' \"$@\" >> '"+capture+"'\nif [ \"$3\" = /api/session ]; then printf '%s' '{\"data\":{\"id\":\"ses_test\"}}'; fi\n"), 0700)
|
||||
id, err := PrepareSession(context.Background(), script, workspace, d.Name)
|
||||
if err != nil || id != "ses_test" {
|
||||
t.Fatal(id, err)
|
||||
@@ -40,7 +40,7 @@ func TestSkillFailureDoesNotLaunchAndCleansOnlyCreatedSession(t *testing.T) {
|
||||
workspace := t.TempDir()
|
||||
capture := filepath.Join(workspace, "calls")
|
||||
script := filepath.Join(workspace, "opencode")
|
||||
os.WriteFile(script, []byte("#!/bin/sh\nprintf '%s\\n' \"$@\" >> '"+capture+"'\nif [ \"$3\" = /api/session ]; then printf '%s' '{\"data\":{\"id\":\"ses_new\"}}'; exit 0; fi\nif [ \"$2\" = delete ]; then exit 0; fi\nexit 1\n"), 0700)
|
||||
os.WriteFile(script, []byte("#!/bin/sh\nif [ \"$1\" = --help ]; then printf '%s\\n' ' api commands'; exit 0; fi\nprintf '%s\\n' \"$@\" >> '"+capture+"'\nif [ \"$3\" = /api/session ]; then printf '%s' '{\"data\":{\"id\":\"ses_new\"}}'; exit 0; fi\nif [ \"$2\" = delete ]; then exit 0; fi\nexit 1\n"), 0700)
|
||||
if _, err := PrepareSession(context.Background(), script, workspace, "name"); err == nil {
|
||||
t.Fatal("missing skill allowed")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package author
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStableAuthoringInstructionsPreloadedWithoutInference(t *testing.T) {
|
||||
executable := os.Getenv("PIPELINES_TEST_OPENCODE_V1")
|
||||
if executable == "" {
|
||||
t.Skip("set PIPELINES_TEST_OPENCODE_V1 for no-inference authoring preload test")
|
||||
}
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", home+"/config")
|
||||
t.Setenv("XDG_DATA_HOME", home+"/data")
|
||||
t.Setenv("XDG_CACHE_HOME", home+"/cache")
|
||||
t.Setenv("XDG_STATE_HOME", home+"/state")
|
||||
t.Setenv("PIPELINES_DRAFT_DIR", home+"/drafts")
|
||||
d, err := draft.Create("native authoring", "draft source", "ws://localhost", true, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
workspace, err := Workspace(d)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
id, err := PrepareSession(ctx, executable, workspace, d.Name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c, err := opencode.Open(ctx, executable, workspace, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
defer c.Native(context.Background(), "delete", "/session/"+id, nil)
|
||||
data, err := c.Native(ctx, "get", "/session/"+id+"/message", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var messages []struct {
|
||||
Info struct {
|
||||
Role string `json:"role"`
|
||||
} `json:"info"`
|
||||
Parts []struct{ Type, Text string } `json:"parts"`
|
||||
}
|
||||
if json.Unmarshal(data, &messages) != nil || len(messages) != 1 || messages[0].Info.Role != "user" {
|
||||
t.Fatal("preload ran inference or missing message", string(data))
|
||||
}
|
||||
text := messages[0].Parts[0].Text
|
||||
if !strings.Contains(text, "Do not submit or run by default") && !strings.Contains(text, "Do not submit or run") {
|
||||
if !strings.Contains(text, "Do not submit") {
|
||||
t.Fatal("draft-only instruction not preloaded", text)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(text, "Definition reference") || !strings.Contains(text, "provider=opencode-go") {
|
||||
t.Fatal("format reference not preloaded")
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
name: Pipeline authoring
|
||||
name: pipelines
|
||||
description: Create or edit validated pipeline Markdown drafts with the pipelines CLI; preserve immutable versions and require explicit submission.
|
||||
---
|
||||
|
||||
|
||||
+6
-6
@@ -15,13 +15,13 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/author"
|
||||
"git.a-wan.net/alan/pipelines/internal/client"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/tui"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"pipelines/internal/author"
|
||||
"pipelines/internal/client"
|
||||
"pipelines/internal/draft"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/tui"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"pipelines/internal/cli"
|
||||
"pipelines/internal/draft"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/server"
|
||||
"git.a-wan.net/alan/pipelines/internal/cli"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/server"
|
||||
)
|
||||
|
||||
func setup(t *testing.T) (func(...string) (string, error), *pipeline.Store, string) {
|
||||
@@ -145,7 +145,7 @@ func TestCLIAuthorOpenCodeGetsScopedSkillAndLeavesDraft(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
capture := filepath.Join(root, "invocation")
|
||||
script := filepath.Join(root, "opencode")
|
||||
os.WriteFile(script, []byte("#!/bin/sh\nif [ \"$1\" = api ]; then\n if [ \"$3\" = /api/session ]; then printf '%s' '{\"data\":{\"id\":\"ses_test\"}}'; fi\n exit 0\nfi\nprintf '%s\\n' \"$@\" > "+"'"+capture+"'"+"\n"), 0700)
|
||||
os.WriteFile(script, []byte("#!/bin/sh\nif [ \"$1\" = --help ]; then printf '%s\\n' ' api commands'; exit 0; fi\nif [ \"$1\" = api ]; then\n if [ \"$3\" = /api/session ]; then printf '%s' '{\"data\":{\"id\":\"ses_test\"}}'; fi\n exit 0\nfi\nprintf '%s\\n' \"$@\" > "+"'"+capture+"'"+"\n"), 0700)
|
||||
if _, err := run("new", "scoped skill", "Make a digest", "--opencode", script); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -33,11 +33,12 @@ var notes = map[string]string{
|
||||
}
|
||||
|
||||
var serviceHelp = map[string]string{
|
||||
"serve": "Run the native server in the foreground. Its flags are documented by pipelines serve --help. Installation never starts it automatically.",
|
||||
"start": "Start the per-user native pipeline server and this installation's Docker ntfy together.",
|
||||
"stop": "Stop both services. Active execution is interrupted; file changes are not rolled back.",
|
||||
"restart": "Stop, then start both services, retaining definitions, run history, and credentials.",
|
||||
"status": "Show pipeline/ntfy health and the public phone connection (no credentials).",
|
||||
"doctor": "Check both health endpoints and host OpenCode API discovery; does not execute a model.",
|
||||
"logs": "Follow the native server log. Press Ctrl+C to stop following.",
|
||||
"uninstall": "Remove this installation; retain data by default. --purge explicitly deletes this installation and its ntfy volume; --yes skips prompts.",
|
||||
"uninstall": "Remove verified Go binaries from this command's bin directory; retain data and drafts. --yes skips confirmation. Existing managed installations can be selected explicitly with PIPELINES_PREFIX.",
|
||||
}
|
||||
|
||||
@@ -28,11 +28,13 @@ EXECUTE
|
||||
ping Check the server connection
|
||||
rpc <request.json|-> Send any protocol command (automation escape hatch)
|
||||
|
||||
SERVICE / INTERFACE (managed installation)
|
||||
SERVER / INTERFACE
|
||||
tui Open the dashboard (default with no command)
|
||||
start | stop | restart Manage the native server + Docker ntfy together
|
||||
status | doctor | logs Health, OpenCode discovery, server logs
|
||||
uninstall [--purge] Remove app; retain data unless explicitly purged
|
||||
serve Start native server in the foreground (Ctrl+C stops it)
|
||||
uninstall [--yes] Remove verified Go binaries; retain data and drafts
|
||||
|
||||
Legacy managed installs: select PIPELINES_PREFIX explicitly for start/stop,
|
||||
restart/status/doctor/logs and retained-data or --purge uninstallation.
|
||||
|
||||
Options: --url ws://127.0.0.1:8080/connect --json --help
|
||||
Use pipelines help <command> for its flags. Names with spaces must be quoted.
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/coder/websocket"
|
||||
"github.com/coder/websocket/wsjson"
|
||||
"pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func Dial(ctx context.Context, url string) (*websocket.Conn, error) {
|
||||
|
||||
@@ -19,18 +19,13 @@ type Config struct {
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
// Load finds the manifest next to the actual Go binary, including via a system PATH symlink.
|
||||
// A standalone go-installed CLI can also select a prefix with PIPELINES_PREFIX.
|
||||
// Load selects a legacy managed installation only via an explicit PIPELINES_PREFIX.
|
||||
func Load(executable string) (*Config, error) {
|
||||
resolved, err := filepath.EvalSymlinks(executable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prefix := os.Getenv("PIPELINES_PREFIX")
|
||||
if prefix == "" {
|
||||
prefix = filepath.Dir(filepath.Dir(resolved))
|
||||
return nil, nil
|
||||
}
|
||||
prefix, err = filepath.Abs(prefix)
|
||||
prefix, err := filepath.Abs(prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,8 +55,8 @@ func (c Config) Environment() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
for key, value := range map[string]string{"PIPELINES_URL": "ws://127.0.0.1:" + strconv.Itoa(c.ServerPort) + "/connect", "PIPELINES_OPENCODE": c.OpenCode, "PATH": c.Path} {
|
||||
if key != "PATH" && os.Getenv(key) != "" {
|
||||
for key, value := range map[string]string{"PIPELINES_URL": "ws://127.0.0.1:" + strconv.Itoa(c.ServerPort) + "/connect", "PIPELINES_OPENCODE": c.OpenCode} {
|
||||
if os.Getenv(key) != "" {
|
||||
continue
|
||||
}
|
||||
if err := os.Setenv(key, value); err != nil {
|
||||
|
||||
@@ -18,6 +18,7 @@ func TestCompiledCommandFindsManifestThroughSystemLink(t *testing.T) {
|
||||
os.WriteFile(filepath.Join(root, "pipelines-install.json"), data, 0600)
|
||||
link := filepath.Join(t.TempDir(), "pipelines")
|
||||
os.Symlink(binary, link)
|
||||
t.Setenv("PIPELINES_PREFIX", root)
|
||||
loaded, err := Load(link)
|
||||
if err != nil || loaded == nil || loaded.Prefix != root {
|
||||
t.Fatal(loaded, err)
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package installation
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"debug/buildinfo"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Uninstall removes only verified binaries from the current command's Go bin directory.
|
||||
// Data is deliberately retained: custom server database paths cannot be safely inferred.
|
||||
func Uninstall(executable string, args []string, in io.Reader, out io.Writer) error {
|
||||
f := flag.NewFlagSet("uninstall", flag.ContinueOnError)
|
||||
f.SetOutput(out)
|
||||
yes := f.Bool("yes", false, "Skip confirmation")
|
||||
if err := f.Parse(args); err != nil {
|
||||
if err == flag.ErrHelp {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if len(f.Args()) > 0 {
|
||||
return fmt.Errorf("uninstall takes no positional arguments")
|
||||
}
|
||||
resolved, err := filepath.EvalSymlinks(executable)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dir := filepath.Dir(resolved)
|
||||
var files []string
|
||||
for _, command := range []string{"pipelines", "pipelines-server", "pipelines-tui"} {
|
||||
path := filepath.Join(dir, command)
|
||||
info, err := buildinfo.ReadFile(path)
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot verify %s; no binaries removed: %w", path, err)
|
||||
}
|
||||
if info.Path != "git.a-wan.net/alan/pipelines/cmd/"+command {
|
||||
return fmt.Errorf("%s is not a Pipelines Go binary; no binaries removed", path)
|
||||
}
|
||||
files = append(files, path)
|
||||
}
|
||||
if !*yes {
|
||||
fmt.Fprintf(out, "Remove %s? Data and drafts are retained. [y/N] ", strings.Join(files, ", "))
|
||||
answer, err := bufio.NewReader(in).ReadString('\n')
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(strings.ToLower(answer)) != "y" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
for _, path := range files {
|
||||
if err := os.Remove(path); err != nil {
|
||||
return fmt.Errorf("remove %s: %w (use the permissions appropriate to your bin directory)", path, err)
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(out, "Removed Go binaries. Pipeline history, drafts, and OpenCode configuration were retained.")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
// Package opencode adapts the two published OpenCode API families without installing a CLI.
|
||||
package opencode
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
const MaxRequest = 64 << 10
|
||||
const MaxResponse = 1 << 20
|
||||
|
||||
type Connection struct {
|
||||
Backend, Executable, Directory string
|
||||
URL string
|
||||
password string
|
||||
process *exec.Cmd
|
||||
done chan error
|
||||
models map[string]map[string]string
|
||||
responses map[string][]byte
|
||||
}
|
||||
|
||||
// Reference records only our ephemeral loopback service credentials, never provider auth.
|
||||
// The private file lets crash recovery abort the same owned service, not a new instance.
|
||||
func (c *Connection) Reference() (string, error) {
|
||||
cache, err := os.UserCacheDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
dir := filepath.Join(cache, "pipelines", "private")
|
||||
if err = os.MkdirAll(dir, 0700); err != nil {
|
||||
return "", err
|
||||
}
|
||||
f, err := os.CreateTemp(dir, "opencode-connection-*.json")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
data, _ := json.Marshal(map[string]string{"url": c.URL, "password": c.password, "directory": c.Directory})
|
||||
_, writeErr := f.Write(data)
|
||||
closeErr := f.Close()
|
||||
if writeErr != nil {
|
||||
return "", writeErr
|
||||
}
|
||||
if closeErr != nil {
|
||||
return "", closeErr
|
||||
}
|
||||
return f.Name(), nil
|
||||
}
|
||||
|
||||
func FromReference(path string) (*Connection, error) {
|
||||
info, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !info.Mode().IsRegular() || info.Mode().Perm() != 0600 || info.Size()>MaxRequest {
|
||||
return nil, fmt.Errorf("invalid private OpenCode connection reference")
|
||||
}
|
||||
if stat, ok := info.Sys().(*syscall.Stat_t); !ok || stat.Uid != uint32(os.Getuid()) {
|
||||
return nil, fmt.Errorf("OpenCode reference belongs to another user")
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var reference struct{ URL, Password, Directory string }
|
||||
if err = json.Unmarshal(data, &reference); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u, err := url.Parse(reference.URL)
|
||||
if err != nil || u.Scheme != "http" || u.Hostname() != "127.0.0.1" || u.Port() == "" || u.Path != "" || u.User != nil || u.RawQuery != "" || u.Fragment != "" || len(reference.Password) != 64 {
|
||||
return nil, fmt.Errorf("invalid owned OpenCode service endpoint")
|
||||
}
|
||||
return &Connection{Backend: "v1", URL: reference.URL, password: reference.Password, Directory: reference.Directory}, nil
|
||||
}
|
||||
|
||||
func Executable() string {
|
||||
if path := os.Getenv("PIPELINES_OPENCODE"); path != "" {
|
||||
return path
|
||||
}
|
||||
return "opencode"
|
||||
}
|
||||
|
||||
// Detect checks the advertised command interface, not an assumed release number.
|
||||
func Detect(ctx context.Context, executable string) (string, error) {
|
||||
cmd := exec.CommandContext(ctx, executable, "--help")
|
||||
data, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot run the selected OpenCode CLI: %w", err)
|
||||
}
|
||||
if regexp.MustCompile(`(?m)^\s*(?:opencode\s+)?api\s`).Match(data) {
|
||||
return "v2", nil
|
||||
}
|
||||
if regexp.MustCompile(`(?m)^\s*(?:opencode\s+)?serve\s`).Match(data) {
|
||||
return "v1", nil
|
||||
}
|
||||
return "", fmt.Errorf("selected OpenCode CLI advertises neither api nor serve")
|
||||
}
|
||||
|
||||
func Open(ctx context.Context, executable, directory, backend string) (*Connection, error) {
|
||||
if executable == "" {
|
||||
executable = Executable()
|
||||
}
|
||||
if directory == "" {
|
||||
var err error
|
||||
directory, err = os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if backend == "" {
|
||||
var err error
|
||||
backend, err = Detect(ctx, executable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c := &Connection{Backend: backend, Executable: executable, Directory: directory, models: map[string]map[string]string{}, responses: map[string][]byte{}}
|
||||
if backend == "v2" {
|
||||
return c, nil
|
||||
}
|
||||
if backend != "v1" {
|
||||
return nil, fmt.Errorf("unknown OpenCode backend %q", backend)
|
||||
}
|
||||
secret := make([]byte, 32)
|
||||
if _, err := rand.Read(secret); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.password = hex.EncodeToString(secret)
|
||||
c.process = exec.Command(executable, "serve", "--hostname", "127.0.0.1", "--port", "0")
|
||||
c.process.Dir = directory
|
||||
for _, entry := range os.Environ() {
|
||||
if !strings.HasPrefix(entry, "OPENCODE_SERVER_PASSWORD=") && !strings.HasPrefix(entry, "OPENCODE_SERVER_USERNAME=") {
|
||||
c.process.Env = append(c.process.Env, entry)
|
||||
}
|
||||
}
|
||||
c.process.Env = append(c.process.Env, "OPENCODE_SERVER_PASSWORD="+c.password, "OPENCODE_SERVER_USERNAME=pipelines")
|
||||
stdout, err := c.process.StdoutPipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.process.Stderr = io.Discard
|
||||
if err = c.process.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.done = make(chan error, 1)
|
||||
go func() { c.done <- c.process.Wait() }()
|
||||
address := make(chan string, 1)
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(stdout)
|
||||
pattern := regexp.MustCompile(`http://127\.0\.0\.1:[0-9]+`)
|
||||
sent := false
|
||||
for scanner.Scan() {
|
||||
if !sent {
|
||||
if found := pattern.FindString(scanner.Text()); found != "" {
|
||||
address <- found
|
||||
sent = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
startup, stop := context.WithTimeout(ctx, 20*time.Second)
|
||||
defer stop()
|
||||
select {
|
||||
case c.URL = <-address:
|
||||
case <-c.done:
|
||||
c.process = nil
|
||||
return nil, fmt.Errorf("OpenCode serve exited before becoming ready")
|
||||
case <-startup.Done():
|
||||
c.Close()
|
||||
return nil, fmt.Errorf("OpenCode serve startup: %w", startup.Err())
|
||||
}
|
||||
health, err := c.Native(startup, "get", "/global/health", nil)
|
||||
var result struct {
|
||||
Healthy bool `json:"healthy"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
if err != nil || json.Unmarshal(health, &result) != nil || !result.Healthy || result.Version == "" {
|
||||
c.Close()
|
||||
return nil, fmt.Errorf("OpenCode serve did not return the expected native health contract")
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *Connection) Close() {
|
||||
if c.process == nil {
|
||||
return
|
||||
}
|
||||
_ = c.process.Process.Signal(syscall.SIGTERM)
|
||||
select {
|
||||
case <-c.done:
|
||||
case <-time.After(5 * time.Second):
|
||||
_ = c.process.Process.Kill()
|
||||
<-c.done
|
||||
}
|
||||
c.process = nil
|
||||
}
|
||||
|
||||
func (c *Connection) Native(ctx context.Context, method, path string, body any) ([]byte, error) {
|
||||
u, err := url.Parse(c.URL + path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
query := u.Query()
|
||||
query.Set("directory", c.Directory)
|
||||
u.RawQuery = query.Encode()
|
||||
var data []byte
|
||||
if body != nil {
|
||||
data, err = json.Marshal(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(data) > MaxRequest {
|
||||
return nil, fmt.Errorf("OpenCode request exceeds 64 KiB")
|
||||
}
|
||||
}
|
||||
request, err := http.NewRequestWithContext(ctx, strings.ToUpper(method), u.String(), bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
request.SetBasicAuth("pipelines", c.password)
|
||||
response, err := http.DefaultClient.Do(request)
|
||||
if err != nil {
|
||||
if ctx.Err() != nil {
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
return nil, fmt.Errorf("OpenCode native API request failed")
|
||||
}
|
||||
defer response.Body.Close()
|
||||
if response.StatusCode < 200 || response.StatusCode >= 300 {
|
||||
return nil, fmt.Errorf("OpenCode %s %s failed (HTTP %d)", method, path, response.StatusCode)
|
||||
}
|
||||
if !strings.HasPrefix(response.Header.Get("Content-Type"), "application/json") {
|
||||
return nil, fmt.Errorf("OpenCode %s %s returned a non-JSON API response", method, path)
|
||||
}
|
||||
data, err = io.ReadAll(io.LimitReader(response.Body, MaxResponse+1))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(data) > MaxResponse {
|
||||
return nil, fmt.Errorf("OpenCode response exceeds 1 MiB")
|
||||
}
|
||||
if !json.Valid(data) {
|
||||
return nil, fmt.Errorf("OpenCode returned invalid JSON")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package opencode
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// This test does no inference and never uses or copies the user's login.
|
||||
func TestStableNativeSessionContractLive(t *testing.T) {
|
||||
executable := os.Getenv("PIPELINES_TEST_OPENCODE_V1")
|
||||
if executable == "" {
|
||||
t.Skip("set PIPELINES_TEST_OPENCODE_V1 for no-inference stable CLI contract test")
|
||||
}
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", home+"/config")
|
||||
t.Setenv("XDG_DATA_HOME", home+"/data")
|
||||
t.Setenv("XDG_CACHE_HOME", home+"/cache")
|
||||
t.Setenv("XDG_STATE_HOME", home+"/state")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
|
||||
defer cancel()
|
||||
c, err := Open(ctx, executable, home, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
if c.Backend != "v1" {
|
||||
t.Fatal("expected native serve backend")
|
||||
}
|
||||
data, err := c.Call(ctx, "post", "/api/session", map[string]any{"title": "Pipelines contract test", "model": map[string]string{"providerID": "opencode-go", "id": "deepseek-v4.1-flash"}, "permissions": []map[string]string{{"action": "*", "resource": "*", "effect": "deny"}, {"action": "read", "resource": "*", "effect": "allow"}, {"action": "shell", "resource": "go test ./...", "effect": "allow"}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var result struct {
|
||||
Data struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"data"`
|
||||
}
|
||||
json.Unmarshal(data, &result)
|
||||
defer c.Call(context.Background(), "delete", "/api/session/"+result.Data.ID, nil)
|
||||
data, err = c.Native(ctx, "get", "/session/"+result.Data.ID, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var session struct {
|
||||
Permission []map[string]string `json:"permission"`
|
||||
}
|
||||
json.Unmarshal(data, &session)
|
||||
if len(session.Permission) != 3 || session.Permission[2]["permission"] != "bash" {
|
||||
t.Fatal("scoped native permission contract not retained", string(data))
|
||||
}
|
||||
ref, err := c.Reference()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(ref)
|
||||
recovered, err := FromReference(ref)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = recovered.Call(ctx, "post", "/api/session/"+result.Data.ID+"/interrupt", nil); err != nil {
|
||||
t.Fatal("cannot abort same owned service via durable reference", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package opencode
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var sessionID = regexp.MustCompile(`^ses[A-Za-z0-9_-]+$`)
|
||||
|
||||
func Permissions(rules []map[string]string) []map[string]string {
|
||||
result := make([]map[string]string, 0, len(rules))
|
||||
for _, rule := range rules {
|
||||
permission := rule["action"]
|
||||
if permission == "shell" {
|
||||
permission = "bash"
|
||||
}
|
||||
result = append(result, map[string]string{"permission": permission, "pattern": rule["resource"], "action": rule["effect"]})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func messageText(data []byte) (string, error) {
|
||||
var message struct {
|
||||
Info struct {
|
||||
Role string `json:"role"`
|
||||
Finish string `json:"finish"`
|
||||
Error json.RawMessage `json:"error"`
|
||||
Time struct {
|
||||
Completed int64 `json:"completed"`
|
||||
} `json:"time"`
|
||||
} `json:"info"`
|
||||
Parts []struct{ Type, Text string } `json:"parts"`
|
||||
}
|
||||
if json.Unmarshal(data, &message) != nil || message.Info.Role != "assistant" || message.Info.Finish != "stop" || message.Info.Time.Completed == 0 {
|
||||
return "", fmt.Errorf("OpenCode returned no completed assistant result")
|
||||
}
|
||||
if len(message.Info.Error) > 0 && string(message.Info.Error) != "null" {
|
||||
return "", fmt.Errorf("OpenCode agent reported an execution error")
|
||||
}
|
||||
var text string
|
||||
for _, part := range message.Parts {
|
||||
if part.Type == "text" {
|
||||
text += part.Text
|
||||
}
|
||||
}
|
||||
if text == "" {
|
||||
return "", fmt.Errorf("OpenCode returned no assistant text")
|
||||
}
|
||||
return text, nil
|
||||
}
|
||||
|
||||
// Call adapts the pipeline's existing V2 command contract to the native stable API.
|
||||
// Sessions still use the same account/database; only our loopback serve process is owned.
|
||||
func (c *Connection) Call(ctx context.Context, method, path string, body any) ([]byte, error) {
|
||||
if c.Backend != "v1" {
|
||||
return nil, fmt.Errorf("native adapter requires the serve backend")
|
||||
}
|
||||
if path == "/api/session" && method == "post" {
|
||||
data, _ := json.Marshal(body)
|
||||
var request struct {
|
||||
Title, Agent string
|
||||
Model map[string]string
|
||||
Permissions []map[string]string
|
||||
}
|
||||
if err := json.Unmarshal(data, &request); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rules := request.Permissions
|
||||
if rules == nil {
|
||||
rules = []map[string]string{{"action": "*", "resource": "*", "effect": "deny"}}
|
||||
}
|
||||
nativeRules:=Permissions(rules)
|
||||
// V1 tool implementations can match absolute file paths; preserve the exact
|
||||
// approved scope in both forms, never grant a workspace-wide edit wildcard.
|
||||
var scoped []map[string]string
|
||||
for _,rule:=range nativeRules{scoped=append(scoped,rule);if rule["permission"]=="edit"&&rule["action"]=="allow"&&!filepath.IsAbs(rule["pattern"]){scoped=append(scoped,map[string]string{"permission":"edit","action":"allow","pattern":filepath.Join(c.Directory,rule["pattern"])})}}
|
||||
payload := map[string]any{"title": request.Title, "permission": scoped, "model": request.Model}
|
||||
if request.Agent != "" {
|
||||
payload["agent"] = request.Agent
|
||||
}
|
||||
created, err := c.Native(ctx, "post", "/session", payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var session struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
if json.Unmarshal(created, &session) != nil || !sessionID.MatchString(session.ID) {
|
||||
return nil, fmt.Errorf("OpenCode returned an invalid native session")
|
||||
}
|
||||
c.models[session.ID] = map[string]string{"providerID": request.Model["providerID"], "modelID": request.Model["id"]}
|
||||
return json.Marshal(map[string]any{"data": map[string]string{"id": session.ID}})
|
||||
}
|
||||
clean := strings.SplitN(path, "?", 2)[0]
|
||||
parts := strings.Split(strings.TrimPrefix(clean, "/api/session/"), "/")
|
||||
if strings.HasPrefix(clean, "/api/experimental/session/") {
|
||||
parts = strings.Split(strings.TrimPrefix(clean, "/api/experimental/session/"), "/")
|
||||
}
|
||||
if len(parts) == 0 || !sessionID.MatchString(parts[0]) {
|
||||
return nil, fmt.Errorf("unsupported native OpenCode operation")
|
||||
}
|
||||
id := parts[0]
|
||||
if len(parts) == 1 && method == "delete" {
|
||||
data, err := c.Native(ctx, "delete", "/session/"+id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var confirmed bool
|
||||
if json.Unmarshal(data,&confirmed)!=nil||!confirmed {
|
||||
return nil, fmt.Errorf("OpenCode session deletion was not confirmed")
|
||||
}
|
||||
delete(c.models, id)
|
||||
delete(c.responses, id)
|
||||
return nil, nil
|
||||
}
|
||||
if len(parts) != 2 {
|
||||
return nil, fmt.Errorf("unsupported native OpenCode operation")
|
||||
}
|
||||
switch parts[1] {
|
||||
case "interrupt":
|
||||
data, err := c.Native(ctx, "post", "/session/"+id+"/abort", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var confirmed bool
|
||||
if json.Unmarshal(data,&confirmed)!=nil||!confirmed {
|
||||
return nil, fmt.Errorf("OpenCode abort was not confirmed")
|
||||
}
|
||||
return nil, nil
|
||||
case "generate", "prompt":
|
||||
data, _ := json.Marshal(body)
|
||||
var request map[string]string
|
||||
if err := json.Unmarshal(data, &request); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
text := request["prompt"]
|
||||
if text == "" {
|
||||
text = request["text"]
|
||||
}
|
||||
response, err := c.Native(ctx, "post", "/session/"+id+"/message", map[string]any{"model": c.models[id], "parts": []map[string]string{{"type": "text", "text": text}}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.responses[id] = response
|
||||
if parts[1] == "prompt" {
|
||||
return nil, nil
|
||||
}
|
||||
result, err := messageText(response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(map[string]any{"data": map[string]string{"text": result}})
|
||||
case "wait":
|
||||
_, err := messageText(c.responses[id])
|
||||
return nil, err
|
||||
case "message":
|
||||
data, err := c.Native(ctx, "get", "/session/"+id+"/message", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var messages []struct {
|
||||
Info map[string]any `json:"info"`
|
||||
Parts []map[string]any `json:"parts"`
|
||||
}
|
||||
if json.Unmarshal(data, &messages) != nil {
|
||||
return nil, fmt.Errorf("invalid native messages")
|
||||
}
|
||||
var converted []map[string]any
|
||||
for i := len(messages) - 1; i >= 0; i-- {
|
||||
m := messages[i]
|
||||
if m.Info["role"] != "assistant" {
|
||||
continue
|
||||
}
|
||||
converted = append(converted, map[string]any{"finish": m.Info["finish"], "error": m.Info["error"], "content": m.Parts, "native_info": m.Info})
|
||||
}
|
||||
return json.Marshal(map[string]any{"data": converted})
|
||||
}
|
||||
return nil, fmt.Errorf("unsupported native OpenCode operation")
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package opencode
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNativeSessionModelPermissionsGenerationAndAbort(t *testing.T) {
|
||||
var created, prompted, deleted, aborted bool
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if r.URL.Query().Get("directory") != "/repo" {
|
||||
t.Error("workspace lost")
|
||||
}
|
||||
switch r.Method + " " + r.URL.Path {
|
||||
case "POST /session":
|
||||
var body struct {
|
||||
Model map[string]string
|
||||
Permission []map[string]string
|
||||
}
|
||||
json.NewDecoder(r.Body).Decode(&body)
|
||||
if body.Model["id"] != "model" || body.Model["providerID"] != "provider" || body.Permission[0]["action"] != "deny" || body.Permission[1]["permission"] != "bash" {
|
||||
t.Error("model or scoped permissions lost", body)
|
||||
}
|
||||
created = true
|
||||
w.Write([]byte(`{"id":"ses_native"}`))
|
||||
case "POST /session/ses_native/message":
|
||||
var body struct {
|
||||
Model map[string]string
|
||||
Parts []map[string]string
|
||||
}
|
||||
json.NewDecoder(r.Body).Decode(&body)
|
||||
if body.Model["modelID"] != "model" || body.Parts[0]["text"] != "exact prompt" {
|
||||
t.Error("prompt or message model changed", body)
|
||||
}
|
||||
prompted = true
|
||||
w.Write([]byte(`{"info":{"role":"assistant","finish":"stop","time":{"completed":1}},"parts":[{"type":"text","text":"result"}]}`))
|
||||
case "GET /session/ses_native/message":
|
||||
w.Write([]byte(`[{"info":{"role":"assistant","finish":"stop","time":{"completed":1}},"parts":[{"type":"text","text":"result"}]}]`))
|
||||
case "POST /session/ses_native/abort":
|
||||
aborted = true
|
||||
w.Write([]byte("true"))
|
||||
case "DELETE /session/ses_native":
|
||||
deleted = true
|
||||
w.Write([]byte("true"))
|
||||
default:
|
||||
t.Error("unexpected native operation", r.Method, r.URL.Path)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
c := &Connection{Backend: "v1", URL: server.URL, Directory: "/repo", models: map[string]map[string]string{}, responses: map[string][]byte{}}
|
||||
ctx := context.Background()
|
||||
_, err := c.Call(ctx, "post", "/api/session", map[string]any{"model": map[string]string{"providerID": "provider", "id": "model"}, "permissions": []map[string]string{{"action": "*", "resource": "*", "effect": "deny"}, {"action": "shell", "resource": "go test ./...", "effect": "allow"}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := c.Call(ctx, "post", "/api/session/ses_native/generate", map[string]string{"prompt": "exact prompt"})
|
||||
if err != nil || !strings.Contains(string(data), "result") {
|
||||
t.Fatal(string(data), err)
|
||||
}
|
||||
if _, err = c.Call(ctx, "post", "/api/experimental/session/ses_native/wait", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = c.Call(ctx, "get", "/api/session/ses_native/message?order=desc", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = c.Call(ctx, "post", "/api/session/ses_native/interrupt", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = c.Call(ctx, "delete", "/api/session/ses_native", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !created || !prompted || !deleted || !aborted {
|
||||
t.Fatal("native lifecycle incomplete")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTMLBridgeIsNotAnAPIAndErrorsAreRedacted(t *testing.T) {
|
||||
for _, status := range []int{200, 500} {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.WriteHeader(status)
|
||||
w.Write([]byte("secret-token HTML"))
|
||||
}))
|
||||
c := &Connection{URL: server.URL}
|
||||
_, err := c.Native(context.Background(), "get", "/api/session", nil)
|
||||
server.Close()
|
||||
if err == nil || strings.Contains(err.Error(), "secret-token") {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, body := range []string{`{"info":{"role":"assistant","finish":"tool-calls","time":{"completed":1}},"parts":[]}`, `{"info":{"role":"assistant","finish":"stop"},"parts":[{"type":"text","text":"unfinished"}]}`, `{"info":{"role":"assistant","finish":"stop","time":{"completed":1},"error":{"message":"bad"}},"parts":[{"type":"text","text":"failed"}]}`} {
|
||||
if _, err := messageText([]byte(body)); err == nil {
|
||||
t.Fatal("unfinished/error response accepted")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Package paths centralizes standard user locations; callers can override them.
|
||||
package paths
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func Data() (string, error) {
|
||||
if dir := os.Getenv("XDG_DATA_HOME"); dir != "" {
|
||||
return filepath.Abs(filepath.Join(dir, "pipelines"))
|
||||
}
|
||||
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
|
||||
dir, err := os.UserConfigDir()
|
||||
return filepath.Join(dir, "pipelines"), err
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
return filepath.Join(home, ".local", "share", "pipelines"), err
|
||||
}
|
||||
func Database() (string, error) { dir, err := Data(); return filepath.Join(dir, "pipelines.db"), err }
|
||||
@@ -0,0 +1,15 @@
|
||||
package paths
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDataLocationIsIndependentOfExecutable(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("XDG_DATA_HOME", dir)
|
||||
db, err := Database()
|
||||
if err != nil || db != filepath.Join(dir, "pipelines", "pipelines.db") {
|
||||
t.Fatal(db, err)
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package pipeline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func TestShowcaseDefinitions(t *testing.T) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"os"
|
||||
"pipelines/internal/protocol"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package pipeline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func (s *Store) initRuns() error {
|
||||
@@ -27,6 +27,9 @@ started_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, finished_at TEXT, PRIMARY KE
|
||||
CREATE INDEX IF NOT EXISTS run_latest ON pipeline_runs(id DESC);
|
||||
CREATE TABLE IF NOT EXISTS step_notifications (
|
||||
run_id INTEGER NOT NULL, sequence INTEGER NOT NULL, receipts_json TEXT NOT NULL,
|
||||
PRIMARY KEY(run_id,sequence), FOREIGN KEY(run_id,sequence) REFERENCES run_steps(run_id,sequence));
|
||||
CREATE TABLE IF NOT EXISTS run_session_owners (
|
||||
run_id INTEGER NOT NULL, sequence INTEGER NOT NULL, backend TEXT NOT NULL, reference TEXT NOT NULL DEFAULT '',
|
||||
PRIMARY KEY(run_id,sequence), FOREIGN KEY(run_id,sequence) REFERENCES run_steps(run_id,sequence));`)
|
||||
return err
|
||||
}
|
||||
@@ -211,8 +214,49 @@ func (s *Store) BeginStep(ctx context.Context, id int64, sequence int, key strin
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (s *Store) RunSession(ctx context.Context, id int64, sequence int, session string, active bool) error {
|
||||
return affected(s.db.ExecContext(ctx, "UPDATE run_steps SET session_id=?,agent_active=? WHERE run_id=? AND sequence=? AND status='running'", session, active, id, sequence))
|
||||
func (s *Store) RunSession(ctx context.Context, id int64, sequence int, session string, active bool, metadata ...string) error {
|
||||
tx, err := s.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if err = affected(tx.ExecContext(ctx, "UPDATE run_steps SET session_id=?,agent_active=? WHERE run_id=? AND sequence=? AND status='running'", session, active, id, sequence)); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(metadata) > 0 {
|
||||
backend := metadata[0]
|
||||
if backend == "" {
|
||||
backend = "v2"
|
||||
}
|
||||
reference := ""
|
||||
if len(metadata) > 1 {
|
||||
reference = metadata[1]
|
||||
}
|
||||
if _, err = tx.ExecContext(ctx, "INSERT INTO run_session_owners(run_id,sequence,backend,reference) VALUES(?,?,?,?) ON CONFLICT(run_id,sequence) DO UPDATE SET backend=excluded.backend,reference=excluded.reference", id, sequence, backend, reference); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
type SessionOwner struct{ ID, Backend, Directory, Reference string }
|
||||
|
||||
func (s *Store) ActiveSessionOwners(ctx context.Context) ([]SessionOwner, error) {
|
||||
rows, err := s.db.QueryContext(ctx, `SELECT s.session_id,COALESCE(o.backend,'v2'),r.workspace,COALESCE(o.reference,'')
|
||||
FROM run_steps s JOIN pipeline_runs r ON r.id=s.run_id LEFT JOIN run_session_owners o ON o.run_id=s.run_id AND o.sequence=s.sequence WHERE s.agent_active=1 AND s.session_id<>''`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var owners []SessionOwner
|
||||
for rows.Next() {
|
||||
var owner SessionOwner
|
||||
if err = rows.Scan(&owner.ID, &owner.Backend, &owner.Directory, &owner.Reference); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
owners = append(owners, owner)
|
||||
}
|
||||
return owners, rows.Err()
|
||||
}
|
||||
|
||||
func (s *Store) FinishStep(ctx context.Context, id int64, step protocol.RunStep) error {
|
||||
|
||||
@@ -2,7 +2,7 @@ package pipeline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"pipelines/internal/stage"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
)
|
||||
|
||||
// StageDefinition adapts normalized/persisted graph data for type implementations.
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
)
|
||||
|
||||
type constantStage struct{}
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -3,9 +3,9 @@ package pipeline
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"path/filepath"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
@@ -2,8 +2,8 @@ package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"path/filepath"
|
||||
"pipelines/internal/stage"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"git.a-wan.net/alan/pipelines/internal/cli"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"pipelines/internal/cli"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"net/url"
|
||||
"os"
|
||||
"pipelines/internal/protocol"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -3,12 +3,12 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@@ -4,15 +4,15 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
|
||||
@@ -2,12 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"github.com/coder/websocket"
|
||||
"github.com/coder/websocket/wsjson"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
)
|
||||
|
||||
func TestRunWebSocketRemainsResponsiveAndAuditable(t *testing.T) {
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
)
|
||||
|
||||
type runner struct {
|
||||
@@ -27,16 +27,16 @@ type runner struct {
|
||||
}
|
||||
|
||||
func newRunner(ctx context.Context, s *pipeline.Store) (*runner, error) {
|
||||
sessions, err := s.ActiveAgentSessions(ctx)
|
||||
sessions, err := s.ActiveSessionOwners(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, id := range sessions {
|
||||
for _, owner := range sessions {
|
||||
stop, cancel := context.WithTimeout(ctx, 20*time.Second)
|
||||
err := (stage.OpenCodeClient{}).Interrupt(stop, id)
|
||||
err := (stage.OpenCodeClient{Backend: owner.Backend, Directory: owner.Directory, Reference: owner.Reference}).Interrupt(stop, owner.ID)
|
||||
cancel()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot interrupt previously active agent %s: %w", id, err)
|
||||
return nil, fmt.Errorf("cannot interrupt previously active agent %s: %w", owner.ID, err)
|
||||
}
|
||||
}
|
||||
if err := s.RecoverRuns(ctx); err != nil {
|
||||
@@ -241,7 +241,7 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail,
|
||||
client.OnSession = func(session string, active bool) error {
|
||||
c, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
return r.store.RunSession(c, id, sequence, session, active)
|
||||
return r.store.RunSession(c, id, sequence, session, active, client.Backend, client.Reference)
|
||||
}
|
||||
var result stage.Result
|
||||
var err error
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
)
|
||||
|
||||
func TestRunnerRoutingPersistenceAndIdempotency(t *testing.T) {
|
||||
|
||||
@@ -2,12 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/coder/websocket"
|
||||
"github.com/coder/websocket/wsjson"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -2,9 +2,9 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"log"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/stage"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -2,12 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/coder/websocket"
|
||||
"github.com/coder/websocket/wsjson"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -2,10 +2,10 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"path/filepath"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"github.com/coder/websocket"
|
||||
"github.com/coder/websocket/wsjson"
|
||||
|
||||
"pipelines/examples"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/examples"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// Handler serves the persistent connection. Canceling ctx stops active clients.
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/coder/websocket"
|
||||
"github.com/coder/websocket/wsjson"
|
||||
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
type logBuffer struct {
|
||||
|
||||
@@ -2,11 +2,11 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/stage"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -23,11 +25,35 @@ func (c OpenCodeClient) Interrupt(ctx context.Context, id string) error {
|
||||
if !sessionIDPattern.MatchString(id) {
|
||||
return fmt.Errorf("invalid session ID")
|
||||
}
|
||||
if c.command == nil && c.connection == nil {
|
||||
var connection *opencode.Connection
|
||||
var err error
|
||||
if c.Backend == "v1" && c.Reference != "" {
|
||||
connection, err = opencode.FromReference(c.Reference)
|
||||
} else {
|
||||
connection, err = opencode.Open(ctx, opencode.Executable(), c.Directory, c.Backend)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer connection.Close()
|
||||
c.connection = connection
|
||||
c.Backend = connection.Backend
|
||||
}
|
||||
_, err := c.call(ctx, "post", "/api/session/"+id+"/interrupt", map[string]any{})
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *AgentClient) Generate(ctx context.Context, config ModelConfig, prompt string) (text string, err error) {
|
||||
if c.command == nil {
|
||||
connection, err := opencode.Open(ctx, opencode.Executable(), c.Directory, c.Backend)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer connection.Close()
|
||||
c.connection = connection
|
||||
c.Backend = connection.Backend
|
||||
}
|
||||
rules := c.permissionRules()
|
||||
data, err := c.call(ctx, "post", "/api/session", map[string]any{"title": "Pipeline audited agent stage", "agent": "build", "location": map[string]string{"directory": c.Directory}, "model": map[string]string{"providerID": config.Provider, "id": config.Model}, "permissions": rules})
|
||||
if err != nil {
|
||||
@@ -42,8 +68,22 @@ func (c *AgentClient) Generate(ctx context.Context, config ModelConfig, prompt s
|
||||
return "", fmt.Errorf("invalid agent session")
|
||||
}
|
||||
c.SessionID = created.Data.ID
|
||||
if c.connection != nil && c.Backend == "v1" {
|
||||
c.Reference, err = c.connection.Reference()
|
||||
if err != nil {
|
||||
cleanup, cancel := context.WithTimeout(context.WithoutCancel(ctx), 15*time.Second)
|
||||
defer cancel()
|
||||
_, _ = c.call(cleanup, "delete", "/api/session/"+c.SessionID, nil)
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
if c.OnSession != nil {
|
||||
if err := c.OnSession(c.SessionID, true); err != nil {
|
||||
cleanup, cancel := context.WithTimeout(context.WithoutCancel(ctx), 15*time.Second)
|
||||
defer cancel()
|
||||
if _, cleanupErr := c.call(cleanup, "delete", "/api/session/"+c.SessionID, nil); cleanupErr != nil {
|
||||
return "", fmt.Errorf("agent ownership could not be recorded and session cleanup failed")
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
@@ -60,8 +100,12 @@ func (c *AgentClient) Generate(ctx context.Context, config ModelConfig, prompt s
|
||||
if persistErr := c.OnSession(c.SessionID, false); persistErr != nil {
|
||||
err = persistErr
|
||||
text = ""
|
||||
return
|
||||
}
|
||||
}
|
||||
if c.Reference != "" {
|
||||
_ = os.Remove(c.Reference)
|
||||
}
|
||||
}()
|
||||
tools := c.Tools
|
||||
if tools == nil {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -17,12 +18,15 @@ import (
|
||||
const maxModelRequest = 64 << 10 // CLI request body is passed as one OS argument.
|
||||
const maxModelResponse = 1 << 20
|
||||
|
||||
// OpenCodeClient reuses OpenCode V2's service discovery and authenticated accounts.
|
||||
// OpenCodeClient reuses the selected OpenCode CLI and its authenticated accounts.
|
||||
// No API keys are copied into pipeline definitions, subprocess arguments, or logs.
|
||||
// A fresh location-scoped session avoids unrelated user conversation history and
|
||||
// is deleted after generation. Generation is text-only: no agent tools are run.
|
||||
type OpenCodeClient struct {
|
||||
Directory string // empty uses the pipeline server's working directory
|
||||
Backend string
|
||||
Reference string
|
||||
connection *opencode.Connection
|
||||
command func(context.Context, string, ...string) ([]byte, error)
|
||||
}
|
||||
|
||||
@@ -48,6 +52,20 @@ var sessionIDPattern = regexp.MustCompile(`^ses[A-Za-z0-9_-]+$`)
|
||||
var httpStatusPattern = regexp.MustCompile(`HTTP (\d{3})`)
|
||||
|
||||
func (c OpenCodeClient) call(ctx context.Context, method, path string, body any) ([]byte, error) {
|
||||
if c.connection != nil && c.connection.Backend == "v1" {
|
||||
data, err := c.connection.Call(ctx, method, path, body)
|
||||
if err != nil {
|
||||
status := 0
|
||||
if match := httpStatusPattern.FindStringSubmatch(err.Error()); len(match) > 0 {
|
||||
status, _ = strconv.Atoi(match[1])
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
return nil, &openCodeError{operation: method + " " + path, status: status, cause: err}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
args := []string{"api", method, path}
|
||||
if body != nil {
|
||||
data, err := json.Marshal(body)
|
||||
@@ -70,7 +88,7 @@ func (c OpenCodeClient) call(ctx context.Context, method, path string, body any)
|
||||
if c.command != nil {
|
||||
return c.command(ctx, directory, args...)
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "opencode", args...)
|
||||
cmd := exec.CommandContext(ctx, opencode.Executable(), args...)
|
||||
cmd.Dir = directory
|
||||
stdout := &boundedBuffer{limit: maxModelResponse}
|
||||
stderr := &boundedBuffer{limit: 8 << 10}
|
||||
@@ -94,6 +112,15 @@ func (c OpenCodeClient) call(ctx context.Context, method, path string, body any)
|
||||
}
|
||||
|
||||
func (c OpenCodeClient) Generate(ctx context.Context, config ModelConfig, prompt string) (text string, err error) {
|
||||
if c.command == nil {
|
||||
connection, err := opencode.Open(ctx, opencode.Executable(), c.Directory, c.Backend)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer connection.Close()
|
||||
c.connection = connection
|
||||
c.Backend = connection.Backend
|
||||
}
|
||||
directory := c.Directory
|
||||
if directory == "" {
|
||||
directory, err = os.Getwd()
|
||||
|
||||
@@ -33,7 +33,7 @@ func ToolNames(def Definition) ([]string, bool, error) {
|
||||
return tools, true, nil
|
||||
}
|
||||
|
||||
var verificationCommands = []string{"go test ./...", "go test -count=1 ./...", "go test -race ./...", "go test -race -count=1 ./...", "go vet ./...", "go build ./cmd/server ./cmd/tui"}
|
||||
var verificationCommands = []string{"go test ./...", "go test -count=1 ./...", "go test -race ./...", "go test -race -count=1 ./...", "go vet ./...", "go build ./cmd/..."}
|
||||
|
||||
func (c *AgentClient) permissionRules() []map[string]string {
|
||||
rules := []map[string]string{{"action": "*", "resource": "*", "effect": "deny"}}
|
||||
|
||||
@@ -3,9 +3,9 @@ package tui
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/sahilm/fuzzy"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
|
||||
"pipelines/internal/client"
|
||||
"pipelines/internal/draft"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/client"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
type editedMsg struct {
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/server"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/server"
|
||||
)
|
||||
|
||||
func TestCreateAndSubmit(t *testing.T) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"github.com/sahilm/fuzzy"
|
||||
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
var commands = []string{":logs", ":new", ":templates", ":refresh", ":ping", ":edit", ":submit", ":versions", ":run", ":runs", ":home", ":quit"}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func press(m Model, key string) Model {
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"pipelines/internal/pipeline"
|
||||
)
|
||||
|
||||
func TestShowcaseGraphsRender(t *testing.T) {
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func outcomes(stage protocol.Stage) []string {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"sort"
|
||||
)
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func nestedForkGraph(t *testing.T) protocol.Graph {
|
||||
|
||||
@@ -2,7 +2,7 @@ package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"sort"
|
||||
)
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func TestRenderGraphWithCyclesAndDefaults(t *testing.T) {
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"github.com/muesli/termenv"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
var sgr = regexp.MustCompile(`\x1b\[([0-9;]*)m`)
|
||||
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"github.com/coder/websocket"
|
||||
|
||||
"pipelines/internal/client"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/client"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
type connectedMsg struct{ conn *websocket.Conn }
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
|
||||
"pipelines/internal/server"
|
||||
"git.a-wan.net/alan/pipelines/internal/server"
|
||||
)
|
||||
|
||||
func TestTKeyPingRoundTrip(t *testing.T) {
|
||||
|
||||
@@ -2,8 +2,8 @@ package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
type paneGeometry struct {
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"github.com/muesli/termenv"
|
||||
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func panelModel(t *testing.T) Model {
|
||||
|
||||
@@ -3,10 +3,10 @@ package tui
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/sahilm/fuzzy"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/sahilm/fuzzy"
|
||||
|
||||
"pipelines/internal/draft"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func selectionWindow(count, index, capacity int) (int, int) {
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/server"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/server"
|
||||
)
|
||||
|
||||
func TestSearchVersionsAndEditSubmission(t *testing.T) {
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func (m *Model) closeRuns() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// Animation is driven by a local timer, never by extra server requests.
|
||||
|
||||
@@ -2,13 +2,13 @@ package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/server"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"pipelines/internal/server"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/bubbles/textarea"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
type runTick struct{}
|
||||
|
||||
@@ -2,10 +2,10 @@ package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -2,12 +2,12 @@ package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/glamour"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"pipelines/internal/draft"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/examples"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"pipelines/examples"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"pipelines/internal/protocol"
|
||||
"sort"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ package tui
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"pipelines/internal/pipeline"
|
||||
"pipelines/internal/protocol"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
+4
-300
@@ -1,306 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Install a clean native Pipelines service and authenticated Docker ntfy."""
|
||||
import argparse
|
||||
import getpass
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
"""Compatibility entry point: install Go binaries only, with standard Go paths."""
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import plistlib
|
||||
import re
|
||||
import secrets
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from manage import DEFAULT_PREFIX, MARKER, compose, load, run, start, wait_health
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[1]
|
||||
NAME = re.compile(r"^[A-Za-z][A-Za-z0-9_-]{0,63}$")
|
||||
TOPIC = re.compile(r"^[-_A-Za-z0-9]{1,64}$")
|
||||
|
||||
|
||||
def choose_port(preferred):
|
||||
for port in range(preferred, min(preferred + 100, 65536)):
|
||||
with socket.socket() as sock:
|
||||
try:
|
||||
sock.bind(("0.0.0.0", port))
|
||||
return port
|
||||
except OSError:
|
||||
pass
|
||||
raise ValueError("No available local service port")
|
||||
|
||||
|
||||
def default_host():
|
||||
tailscale = shutil.which("tailscale")
|
||||
if tailscale:
|
||||
try:
|
||||
data = json.loads(run([tailscale, "status", "--json"], quiet=True, timeout=10).stdout)
|
||||
if data.get("BackendState") == "Running":
|
||||
return next(ip for ip in data["TailscaleIPs"] if ":" not in ip)
|
||||
except (RuntimeError, ValueError, KeyError, StopIteration, subprocess.SubprocessError):
|
||||
pass
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
||||
try:
|
||||
sock.connect(("192.0.2.1", 80))
|
||||
return sock.getsockname()[0]
|
||||
except OSError:
|
||||
return "127.0.0.1"
|
||||
|
||||
|
||||
def timezone():
|
||||
spec = importlib.util.spec_from_file_location("configure", SOURCE / "scripts/configure-compose.py")
|
||||
module = importlib.util.module_from_spec(spec); spec.loader.exec_module(module)
|
||||
return module.host_timezone()
|
||||
|
||||
|
||||
def write_private(path, text):
|
||||
path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
with path.open("x") as file:
|
||||
file.write(text)
|
||||
path.chmod(0o600)
|
||||
|
||||
|
||||
def ntfy_compose(config):
|
||||
# JSON scalars are valid YAML scalars and prevent interpolation/injection.
|
||||
q = lambda value: json.dumps(str(value))
|
||||
return f'''services:
|
||||
ntfy:
|
||||
image: binwiederhier/ntfy:v2.29.0
|
||||
command: serve
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
TZ: {q(config['timezone'])}
|
||||
NTFY_BASE_URL: {q(config['public_url'])}
|
||||
NTFY_LISTEN_HTTP: ":80"
|
||||
NTFY_CACHE_FILE: /var/lib/ntfy/cache.db
|
||||
NTFY_CACHE_DURATION: 168h
|
||||
NTFY_AUTH_FILE: /var/lib/ntfy/auth.db
|
||||
NTFY_AUTH_DEFAULT_ACCESS: deny-all
|
||||
NTFY_ENABLE_LOGIN: "true"
|
||||
NTFY_ATTACHMENT_CACHE_DIR: /var/lib/ntfy/attachments
|
||||
NTFY_ATTACHMENT_EXPIRY_DURATION: 168h
|
||||
NTFY_ATTACHMENT_TOTAL_SIZE_LIMIT: 1G
|
||||
NTFY_ATTACHMENT_FILE_SIZE_LIMIT: 1M
|
||||
ports:
|
||||
- "0.0.0.0:{config['ntfy_port']}:80"
|
||||
volumes:
|
||||
- ntfy-data:/var/lib/ntfy
|
||||
volumes:
|
||||
ntfy-data:
|
||||
'''
|
||||
|
||||
|
||||
def make_registration(config):
|
||||
root = Path(config["prefix"])
|
||||
command = [config["python"], str(root / "lib/manage.py"), "supervise", "--prefix", str(root)]
|
||||
if platform.system() == "Darwin":
|
||||
path = Path.home() / "Library/LaunchAgents" / (config["label"] + ".plist")
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if path.exists():
|
||||
raise ValueError("Service registration already exists; refusing to overwrite")
|
||||
with path.open("wb") as file:
|
||||
plistlib.dump({"Label": config["label"], "ProgramArguments": command,
|
||||
"RunAtLoad": True, "KeepAlive": {"SuccessfulExit": False},
|
||||
"ExitTimeOut": 75, "ThrottleInterval": 10,
|
||||
"StandardOutPath": str(root / "logs/supervisor.log"),
|
||||
"StandardErrorPath": str(root / "logs/supervisor.log")}, file)
|
||||
else:
|
||||
path = Path.home() / ".config/systemd/user" / (config["label"] + ".service")
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if path.exists():
|
||||
raise ValueError("Service registration already exists; refusing to overwrite")
|
||||
# systemd quotes its own command arguments, not shell strings.
|
||||
quote = lambda value: '"' + value.replace("\\", "\\\\").replace('"', '\\"').replace("%", "%%") + '"'
|
||||
path.write_text("[Unit]\nDescription=Pipelines server and ntfy\nAfter=default.target\n\n"
|
||||
"[Service]\nType=simple\nExecStart=" + " ".join(map(quote, command)) +
|
||||
"\nRestart=on-failure\nRestartSec=10\nTimeoutStopSec=90\n\n[Install]\nWantedBy=default.target\n")
|
||||
return str(path)
|
||||
|
||||
|
||||
def install(args):
|
||||
if platform.system() not in ("Darwin", "Linux"):
|
||||
raise ValueError("Supported: macOS and Linux (run as your normal user, not root)")
|
||||
if os.getuid() == 0:
|
||||
raise ValueError("Do not use sudo: this install reuses your user's OpenCode account")
|
||||
root = args.prefix.expanduser().resolve()
|
||||
if root in (Path("/"), Path.home().resolve(), SOURCE):
|
||||
raise ValueError("Choose a dedicated installation directory")
|
||||
docker = shutil.which("docker")
|
||||
if not docker:
|
||||
raise ValueError("Install/start Docker Desktop or Docker Engine first")
|
||||
run([docker, "info", "--format", "{{.ServerVersion}}"], quiet=True, timeout=15)
|
||||
run([docker, "compose", "version"], quiet=True, timeout=15)
|
||||
if (root / MARKER).exists() and not load(root).get("uninstalled"):
|
||||
config = load(root)
|
||||
if not config.get("bootstrapped"):
|
||||
raise ValueError("A partial installation exists; inspect it or run uninstall.sh --prefix ... --purge before retrying")
|
||||
start(config)
|
||||
print(f"Existing installation started; settings/history preserved: {root}")
|
||||
return
|
||||
retained = load(root) if (root / MARKER).exists() else None
|
||||
if root.exists() and any(root.iterdir()) and retained is None:
|
||||
raise ValueError("Installation directory is not empty; refusing to overwrite unrelated files")
|
||||
if not args.no_autostart and platform.system() == "Linux":
|
||||
run(["systemctl", "--user", "show-environment"], quiet=True)
|
||||
opencode = args.opencode or shutil.which("opencode") or shutil.which("opencode2")
|
||||
if not opencode:
|
||||
npm=shutil.which("npm")
|
||||
if not npm:
|
||||
raise ValueError("Install OpenCode V2 first (npm install -g @opencode/cli), or install npm for automatic CLI setup")
|
||||
if not args.yes and input("OpenCode V2 is missing. Install its pinned CLI privately using npm? [Y/n] ").strip().lower()=="n":
|
||||
raise ValueError("OpenCode installation canceled")
|
||||
root.mkdir(parents=True,exist_ok=True,mode=0o700)
|
||||
run([npm,"install","--prefix",str(root / "tools"),"@opencode/cli@2.0.20"],quiet=True,timeout=240)
|
||||
opencode=str(root / "tools/node_modules/.bin/opencode")
|
||||
opencode = str(Path(opencode).resolve())
|
||||
version = run([opencode, "--version"], quiet=True, timeout=15).stdout
|
||||
if not re.search(r"(?:^|\s)v?2\.\d+", version):
|
||||
raise ValueError("OpenCode V2 is required; your existing login/config will be reused, never exported")
|
||||
auth = run([opencode, "auth", "list"], quiet=True, timeout=30).stdout
|
||||
if "OpenCode Go" not in auth:
|
||||
if args.yes:
|
||||
raise ValueError("Connect OpenCode Go first: opencode auth login")
|
||||
print("OpenCode Go is not connected. Complete your existing OpenCode login now.")
|
||||
subprocess.run([opencode, "auth", "login"], check=True)
|
||||
auth = run([opencode, "auth", "list"], quiet=True, timeout=30).stdout
|
||||
if "OpenCode Go" not in auth:
|
||||
raise ValueError("OpenCode Go login not confirmed; installation canceled")
|
||||
# This exercises discovery/start as the same user, without generating model output.
|
||||
run([opencode, "api", "get", "/api/info"], quiet=True, timeout=30)
|
||||
root.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
root.chmod(0o700)
|
||||
for directory in ("bin", "lib", "data", "logs", "secrets", "workspace"):
|
||||
(root / directory).mkdir(exist_ok=True, mode=0o700)
|
||||
packaged = SOURCE / "release-bin"
|
||||
if packaged.is_dir():
|
||||
metadata = json.loads((packaged / "platform.json").read_text())
|
||||
if metadata != {"os": platform.system(), "arch": platform.machine()}:
|
||||
raise ValueError("Release archive is for a different OS/CPU")
|
||||
for name in ("pipelines-server", "pipelines-tui", "pipelines"):
|
||||
shutil.copy2(packaged / name, root / "bin" / name)
|
||||
else:
|
||||
go = shutil.which("go")
|
||||
if not go:
|
||||
raise ValueError("Source install needs Go 1.27+; alternatively use a platform release archive")
|
||||
run([go, "install", "-trimpath", "./cmd/server", "./cmd/tui", "./cmd/pipelines"],
|
||||
env=dict(os.environ, GOBIN=str(root / "bin")), quiet=True, timeout=240)
|
||||
for command in ("server", "tui"):
|
||||
(root / "bin" / command).replace(root / "bin" / ("pipelines-" + command))
|
||||
username = retained["username"] if retained else (args.username or ("phone-reader" if args.yes else input("Phone username [phone-reader]: ").strip() or "phone-reader"))
|
||||
topic = retained["topic"] if retained else (args.topic or ("pipelines" if args.yes else input("Notification topic [pipelines]: ").strip() or "pipelines"))
|
||||
if not NAME.fullmatch(username) or username == "pipeline-publisher" or not TOPIC.fullmatch(topic):
|
||||
raise ValueError("Use safe alphanumeric usernames/topics; pipeline-publisher is reserved")
|
||||
server_port = retained["server_port"] if retained else choose_port(args.server_port)
|
||||
ntfy_port = retained["ntfy_port"] if retained else choose_port(args.ntfy_port)
|
||||
if server_port == ntfy_port:
|
||||
ntfy_port = choose_port(ntfy_port + 1)
|
||||
public_url = retained["public_url"] if retained else args.public_url or f"http://{default_host()}:{ntfy_port}"
|
||||
from urllib.parse import urlparse
|
||||
url = urlparse(public_url)
|
||||
if url.scheme not in ("http", "https") or not url.hostname or url.username or url.password or url.path not in ("", "/") or url.query or url.fragment or any(c in public_url for c in "$\n\r\x00"):
|
||||
raise ValueError("Phone URL must be an HTTP(S) base URL without credentials, topic, query, or interpolation")
|
||||
chosen_workspace=args.workspace or (Path(retained["workspace"]) if retained else root / "workspace")
|
||||
workspace = str(chosen_workspace.expanduser().resolve())
|
||||
if not Path(workspace).is_dir():
|
||||
raise ValueError("Workspace directory must exist")
|
||||
suffix = hashlib.sha256(str(root).encode()).hexdigest()[:12]
|
||||
bindir = Path("/usr/local/bin") if args.system_command else args.bin_dir.expanduser().resolve()
|
||||
launcher = bindir / "pipelines"
|
||||
if launcher.exists() or launcher.is_symlink():
|
||||
if not launcher.is_symlink() or launcher.resolve() != root / "bin/pipelines":
|
||||
raise ValueError("A pipelines command already exists in the target bin directory; choose --bin-dir")
|
||||
# Only explicit server-selection variables are copied; never API keys/tokens.
|
||||
opencode_env = {key: value for key, value in os.environ.items() if key in ("XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "OPENCODE_SERVER", "OPENCODE_DB")}
|
||||
config = dict(format=1, prefix=str(root), docker=docker, python=sys.executable,
|
||||
opencode=opencode, opencode_env=opencode_env, path=os.pathsep.join([str(root / "bin"), str(Path(opencode).parent), os.environ.get("PATH", "")]),
|
||||
project="pipelines-" + suffix, label="io.pipelines." + suffix,
|
||||
server_port=server_port, ntfy_port=ntfy_port, public_url=public_url.rstrip("/"),
|
||||
topic=topic, username=username, timezone=timezone(), workspace=workspace,
|
||||
workspace_roots=[str(path.expanduser().resolve()) for path in (args.workspace_root or ([Path(p) for p in retained["workspace_roots"]] if retained else [Path.home()]))],
|
||||
launcher=str(launcher), registration=None, bootstrapped=bool(retained and retained.get("bootstrapped")))
|
||||
manifest = root / MARKER
|
||||
manifest.write_text(json.dumps(config, indent=2)); manifest.chmod(0o600)
|
||||
(root / "compose.yaml").write_text(ntfy_compose(config))
|
||||
shutil.copy2(SOURCE / "scripts/manage.py", root / "lib/manage.py")
|
||||
alias = root / "bin/opencode"
|
||||
if not alias.exists():
|
||||
alias.symlink_to(opencode)
|
||||
# The PATH command is the compiled Go binary, not a shell/Python launcher.
|
||||
if not config["bootstrapped"]:
|
||||
if args.password_file:
|
||||
password = args.password_file.read_text().strip()
|
||||
elif args.yes:
|
||||
password = secrets.token_urlsafe(18)
|
||||
else:
|
||||
password = getpass.getpass("Phone password (blank = generate): ") or secrets.token_urlsafe(18)
|
||||
if len(password) < 8 or any(c in password for c in "\r\n\x00"):
|
||||
raise ValueError("Phone password must have at least 8 characters and no line breaks")
|
||||
compose(config, "up", "-d", "ntfy", quiet=True)
|
||||
wait_health(f"http://127.0.0.1:{ntfy_port}/v1/health")
|
||||
for user, secret in (("pipeline-publisher", secrets.token_urlsafe(32)), (username, password)):
|
||||
compose(config, "exec", "-T", "-e", "NTFY_PASSWORD", "ntfy", "ntfy", "user", "add", user,
|
||||
env=dict(os.environ, NTFY_PASSWORD=secret), quiet=True)
|
||||
compose(config, "exec", "-T", "ntfy", "ntfy", "access", "pipeline-publisher", topic, "write-only", quiet=True)
|
||||
compose(config, "exec", "-T", "ntfy", "ntfy", "access", username, topic, "read-only", quiet=True)
|
||||
output = compose(config, "exec", "-T", "ntfy", "ntfy", "token", "add", "pipeline-publisher", quiet=True).stdout
|
||||
tokens = re.findall(r"\btk_[A-Za-z0-9]{29}\b", output)
|
||||
if len(tokens) != 1:
|
||||
raise RuntimeError("Could not extract the publishing token; credentials were not printed")
|
||||
write_private(root / "secrets/publisher-token", tokens[0] + "\n")
|
||||
write_private(root / "secrets/phone-login.txt", f"Server: {public_url}\nTopic: {topic}\nUsername: {username}\nPassword: {password}\n")
|
||||
config["bootstrapped"] = True
|
||||
if not args.no_autostart:
|
||||
config["registration"] = make_registration(config)
|
||||
manifest.write_text(json.dumps(config, indent=2))
|
||||
if args.system_command and not bindir.exists():
|
||||
subprocess.run(["sudo", "mkdir", "-p", str(bindir)], check=True)
|
||||
else:
|
||||
bindir.mkdir(parents=True, exist_ok=True)
|
||||
if not launcher.is_symlink():
|
||||
if args.system_command and not os.access(bindir, os.W_OK):
|
||||
# Privilege is used ONLY for this command symlink, never for the server/auth.
|
||||
subprocess.run(["sudo", "ln", "-s", str(root / "bin/pipelines"), str(launcher)], check=True)
|
||||
else:
|
||||
launcher.symlink_to(root / "bin/pipelines")
|
||||
start(config)
|
||||
print(f"Installed. Run: {launcher}\nManage both services: pipelines start|stop|restart|status|doctor|logs")
|
||||
print(f"Phone server: {config['public_url']}\nTopic: {topic}\nUsername: {username}")
|
||||
print(f"Password is private: {root / 'secrets/phone-login.txt'}")
|
||||
print("Fresh installations have no pipelines. In the TUI press b for rendered examples/templates.")
|
||||
print("ntfy is exposed on LAN/VPN with authentication. Use HTTPS or an encrypted VPN outside a trusted LAN.")
|
||||
if str(bindir) not in os.environ.get("PATH", "").split(os.pathsep):
|
||||
print(f"Add {bindir} to PATH, or use the full command path above.")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--prefix", type=Path, default=DEFAULT_PREFIX)
|
||||
parser.add_argument("--bin-dir", type=Path, default=Path.home() / ".local/bin")
|
||||
parser.add_argument("--system-command",action="store_true",help="Put the command in /usr/local/bin (sudo only for the symlink; services remain per-user)")
|
||||
parser.add_argument("--username")
|
||||
parser.add_argument("--topic")
|
||||
parser.add_argument("--password-file", type=Path)
|
||||
parser.add_argument("--public-url")
|
||||
parser.add_argument("--workspace", type=Path)
|
||||
parser.add_argument("--workspace-root",type=Path,action="append",help="Allowed repository root; repeatable (default: your home)")
|
||||
parser.add_argument("--opencode", help="Path to the host OpenCode V2 CLI")
|
||||
parser.add_argument("--server-port", type=int, default=8080)
|
||||
parser.add_argument("--ntfy-port", type=int, default=8090)
|
||||
parser.add_argument("--no-autostart", action="store_true", help="Use a managed background process rather than launchd/systemd")
|
||||
parser.add_argument("--yes", action="store_true", help="Accept defaults and generate a private phone password")
|
||||
args = parser.parse_args()
|
||||
if not 1024 <= args.server_port <= 65535 or not 1024 <= args.ntfy_port <= 65535:
|
||||
parser.error("Use unprivileged ports 1024–65535")
|
||||
os.chdir(SOURCE)
|
||||
install(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except (ValueError, RuntimeError, OSError, subprocess.SubprocessError) as error:
|
||||
sys.exit(str(error))
|
||||
if len(sys.argv) != 1:
|
||||
sys.exit("Install binaries with go install ./cmd/...; set GOBIN to choose the destination. Configure and start services separately.")
|
||||
sys.exit(subprocess.call(["go", "install", "-trimpath", "./cmd/..."], cwd=Path(__file__).resolve().parents[1]))
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ def package(output, version, target):
|
||||
if system not in ("darwin", "linux") or arch not in ("arm64", "amd64"):
|
||||
raise ValueError("Supported: source, darwin-arm64/amd64, linux-arm64/amd64")
|
||||
env = dict(os.environ, GOOS=system, GOARCH=arch, CGO_ENABLED="0")
|
||||
for command, binary in (("server", "pipelines-server"), ("tui", "pipelines-tui"), ("pipelines", "pipelines")):
|
||||
for command, binary in (("pipelines-server", "pipelines-server"), ("pipelines-tui", "pipelines-tui"), ("pipelines", "pipelines")):
|
||||
subprocess.run(["go", "build", "-trimpath", "-o", str(binaries / binary), "./cmd/" + command],
|
||||
cwd=ROOT, env=env, check=True)
|
||||
(binaries / "platform.json").write_text(json.dumps({"os": "Darwin" if system == "darwin" else "Linux", "arch": "arm64" if arch == "arm64" and system == "darwin" else "aarch64" if arch == "arm64" else "x86_64"}))
|
||||
|
||||
@@ -10,4 +10,4 @@ export PIPELINES_NTFY_URL="${PIPELINES_NTFY_URL:-http://127.0.0.1:8090/pipelines
|
||||
if [ -z "${PIPELINES_NTFY_TOKEN:-}" ]; then
|
||||
export PIPELINES_NTFY_TOKEN_FILE="${PIPELINES_NTFY_TOKEN_FILE:-$(pwd)/secrets/ntfy-token.txt}"
|
||||
fi
|
||||
exec go run ./cmd/server "$@"
|
||||
exec go run ./cmd/pipelines-server "$@"
|
||||
|
||||
@@ -1,90 +1,36 @@
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
import install
|
||||
import manage
|
||||
|
||||
|
||||
class InstallationTests(unittest.TestCase):
|
||||
def test_launcher_forwards_application_arguments_unchanged(self):
|
||||
config = dict(prefix="/owned", server_port=12345, opencode="/host/opencode", path="/owned/bin:/usr/bin")
|
||||
for command in (["edit", "a name", "change X", "--json"], ["--url", "ws://other/connect", "list", "--json"], ["--help"], ["run", "workflow", "task", "--yes", "--json"]):
|
||||
with mock.patch.object(manage,"load",return_value=config), mock.patch.object(manage.sys,"argv",["manage.py","--prefix","/owned",*command]), mock.patch.object(manage.os,"execve") as execute:
|
||||
manage.main()
|
||||
binary,args,env=execute.call_args.args
|
||||
self.assertEqual(args,["/owned/bin/pipelines",*command])
|
||||
self.assertEqual(env["PIPELINES_URL"],"ws://127.0.0.1:12345/connect")
|
||||
def test_compose_has_only_ntfy_and_no_credentials(self):
|
||||
config = dict(timezone="Europe/London", public_url="http://100.1.2.3:8090", ntfy_port=8090)
|
||||
text = install.ntfy_compose(config)
|
||||
self.assertIn("binwiederhier/ntfy:v2.29.0", text)
|
||||
self.assertIn("deny-all", text)
|
||||
self.assertNotIn("opencode", text)
|
||||
self.assertNotIn("password", text.lower())
|
||||
self.assertNotIn("pipelines:", text)
|
||||
|
||||
def test_detect_free_port_avoids_listener(self):
|
||||
with socket.socket() as listener:
|
||||
listener.bind(("0.0.0.0", 0)); listener.listen()
|
||||
occupied = listener.getsockname()[1]
|
||||
self.assertNotEqual(install.choose_port(occupied), occupied)
|
||||
|
||||
def test_secret_files_private_and_not_overwritten(self):
|
||||
def test_standard_installer_needs_only_go_and_honors_gobin(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path = Path(directory, "secrets/token")
|
||||
install.write_private(path, "private")
|
||||
self.assertEqual(path.stat().st_mode & 0o777, 0o600)
|
||||
with self.assertRaises(FileExistsError):
|
||||
install.write_private(path, "replacement")
|
||||
self.assertEqual(path.read_text(), "private")
|
||||
root=Path(directory)
|
||||
capture=root/"args"
|
||||
executable=root/"go"
|
||||
executable.write_text('#!/bin/sh\nprintf "%s\\n" "$GOBIN" "$@" > "'+str(capture)+'"\n')
|
||||
executable.chmod(0o700)
|
||||
env=dict(os.environ,PATH=str(root)+os.pathsep+os.environ["PATH"],GOBIN=str(root/"bin"))
|
||||
subprocess.run([str(Path(__file__).resolve().parents[1]/"install.sh")],env=env,check=True)
|
||||
self.assertEqual(capture.read_text().splitlines(),[str(root/"bin"),"install","-trimpath","./cmd/..."])
|
||||
self.assertFalse((root/"bin").exists())
|
||||
|
||||
def test_management_requires_owned_installation_marker(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
with self.assertRaises(ValueError):
|
||||
manage.load(directory)
|
||||
root = Path(directory).resolve()
|
||||
(root / manage.MARKER).write_text(json.dumps(dict(format=1, prefix=str(root))))
|
||||
self.assertEqual(manage.load(root)["prefix"], str(root))
|
||||
(root / manage.MARKER).write_text(json.dumps(dict(format=1, prefix="/")))
|
||||
with self.assertRaises(ValueError):
|
||||
manage.load(root)
|
||||
def test_standard_installer_rejects_legacy_provisioning_flags(self):
|
||||
result=subprocess.run([str(Path(__file__).resolve().parents[1]/"install.sh"),"--system-command"],capture_output=True,text=True)
|
||||
self.assertEqual(result.returncode,2)
|
||||
self.assertIn("GOBIN",result.stderr)
|
||||
|
||||
def test_pid_reuse_cannot_signal_unrelated_process(self):
|
||||
def test_legacy_management_requires_owned_marker(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
Path(directory, "supervisor.pid").write_text(str(os.getpid()))
|
||||
with self.assertRaises(ValueError):manage.load(directory)
|
||||
|
||||
def test_legacy_pid_reuse_cannot_signal_unrelated_process(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
Path(directory,"supervisor.pid").write_text(str(os.getpid()))
|
||||
self.assertIsNone(manage.managed_pid(dict(prefix=directory)))
|
||||
|
||||
def test_default_uninstall_preserves_data_and_open_code(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory, "app"); root.mkdir()
|
||||
for name in ("bin", "lib", "data", "secrets"):
|
||||
(root / name).mkdir()
|
||||
(root / "data/pipelines.db").write_text("history")
|
||||
(root / "secrets/publisher-token").write_text("credential")
|
||||
config = dict(format=1, prefix=str(root), launcher=str(Path(directory, "pipelines")), registration=None)
|
||||
Path(config["launcher"]).symlink_to(root / "bin/pipelines")
|
||||
with mock.patch.object(manage, "stop"), mock.patch.object(manage, "compose") as compose:
|
||||
manage.uninstall(config, yes=True)
|
||||
compose.assert_called_once_with(config, "down", quiet=True)
|
||||
self.assertEqual((root / "data/pipelines.db").read_text(), "history")
|
||||
self.assertEqual((root / "secrets/publisher-token").read_text(), "credential")
|
||||
self.assertFalse((root / "bin").exists())
|
||||
self.assertFalse(Path(config["launcher"]).is_symlink())
|
||||
|
||||
def test_service_registration_quotes_paths(self):
|
||||
with tempfile.TemporaryDirectory(prefix="path with spaces ") as directory:
|
||||
root = Path(directory);(root / "logs").mkdir()
|
||||
config = dict(prefix=str(root), python="/usr/bin/python3", label="io.pipelines.test")
|
||||
with mock.patch.object(install.platform,"system",return_value="Linux"),mock.patch.object(install.Path,"home",return_value=root):
|
||||
path = Path(install.make_registration(config))
|
||||
self.assertIn('"'+str(root / 'lib/manage.py')+'"', path.read_text())
|
||||
self.assertIn("Restart=on-failure", path.read_text())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
if __name__=="__main__":unittest.main()
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user