Remove workspace-root configuration and use client run directories

This commit is contained in:
2026-10-09 00:32:00 +01:00
parent 4697bb4465
commit c5a5521015
17 changed files with 97 additions and 116 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ var notes = map[string]string{
}
var serviceHelp = map[string]string{
"service": "Configure per-user OS autostart: pipelines service enable --workspace-root DIR. Use --print to preview, service status to inspect, and service disable before uninstalling. Linux uses systemd; macOS uses launchd. No sudo.",
"service": "Configure per-user OS autostart: pipelines service enable. Runs use the directory you invoke pipelines run from. Use --print to preview, service status to inspect, and service disable before uninstalling. Linux uses systemd; macOS uses launchd. No sudo.",
"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.",
+1 -1
View File
@@ -31,7 +31,7 @@ EXECUTE
SERVER / INTERFACE
tui Open the dashboard (default with no command)
serve Start native server in the foreground (Ctrl+C stops it)
service enable Configure user autostart; requires --workspace-root DIR
service enable Configure user autostart
service disable | status Stop/remove autostart, or inspect OS service status
uninstall [--yes] Remove verified Go binaries; retain data and drafts
+7 -26
View File
@@ -162,7 +162,7 @@ func ServerExecutable(executable string) (string, error) {
// ServiceCommand uses the OS service manager directly, without a second supervisor.
func ServiceCommand(ctx context.Context, executable string, args []string, out, stderr io.Writer) error {
help := "Usage: pipelines service enable --workspace-root DIR [--workspace-root DIR] [--db FILE] [--addr HOST:PORT] [--print]\n pipelines service disable | status\nAutostart is per-user, at login. enable starts the server now; --print only previews.\n"
help := "Usage: pipelines service enable [--db FILE] [--addr HOST:PORT] [--print]\n pipelines service disable | status\nAutostart is per-user, at login. enable starts the server now; --print only previews.\nRuns use the directory you invoke pipelines run from.\n"
if len(args) == 0 || args[0] == "--help" || args[0] == "help" {
_, err := io.WriteString(out, help)
return err
@@ -192,34 +192,14 @@ func ServiceCommand(ctx context.Context, executable string, args []string, out,
}
db := f.String("db", defaultDB, "SQLite database file")
addr := f.String("addr", "127.0.0.1:8080", "Server listen address")
var roots []string
f.Func("workspace-root", "Trusted repository root (required; repeatable)", func(value string) error {
path, err := filepath.Abs(value)
if err != nil {
return err
}
path, err = filepath.EvalSymlinks(path)
if err != nil {
return err
}
info, err := os.Stat(path)
if err != nil {
return err
}
if !info.IsDir() {
return fmt.Errorf("workspace root must be a directory")
}
roots = append(roots, path)
return nil
})
if err := f.Parse(args[1:]); err != nil {
if err == flag.ErrHelp {
return nil
}
return err
}
if len(f.Args()) != 0 || len(roots) == 0 {
return fmt.Errorf("service enable requires --workspace-root DIR; no positional arguments")
if len(f.Args()) != 0 {
return fmt.Errorf("service enable takes no positional arguments")
}
if os.Getenv("PIPELINES_NTFY_TOKEN") != "" {
return fmt.Errorf("use PIPELINES_NTFY_TOKEN_FILE for autostart; inline tokens are not saved")
@@ -232,10 +212,11 @@ func ServiceCommand(ctx context.Context, executable string, args []string, out,
if err != nil {
return err
}
d := serviceDefinition{Binary: binary, Directory: roots[0], Args: []string{"-db", database, "-addr", *addr}, Environment: map[string]string{}}
for _, root := range roots {
d.Args = append(d.Args, "-workspace-root", root)
home, err := os.UserHomeDir()
if err != nil {
return err
}
d := serviceDefinition{Binary: binary, Directory: home, Args: []string{"-db", database, "-addr", *addr}, Environment: map[string]string{}}
for _, key := range serviceEnvironmentKeys {
if value, ok := os.LookupEnv(key); ok {
d.Environment[key] = value
+3 -7
View File
@@ -13,7 +13,7 @@ import (
)
func TestServiceDefinitionsQuotePathsAndKeepEnvironmentLimited(t *testing.T) {
d := serviceDefinition{Binary: `/some bin/server`, Directory: `/repo "quoted" 100% $USER`, Args: []string{"-workspace-root", `/repo "quoted" 100% $USER`}, Environment: map[string]string{"PATH": "/usr/bin:/custom bin", "PIPELINES_NTFY_TOKEN_FILE": "/secret & token", "PROVIDER_SECRET": "must-not-export"}}
d := serviceDefinition{Binary: `/some bin/server`, Directory: `/repo "quoted" 100% $USER`, Args: []string{"-db", `/repo "quoted" 100% $USER/data.db`}, Environment: map[string]string{"PATH": "/usr/bin:/custom bin", "PIPELINES_NTFY_TOKEN_FILE": "/secret & token", "PROVIDER_SECRET": "must-not-export"}}
for _, platform := range []string{"linux", "darwin"} {
text, err := d.render(platform)
if err != nil {
@@ -86,8 +86,7 @@ func TestServiceConfigurationPreviewAndLifecycleWithMockOSManager(t *testing.T)
}
home := t.TempDir()
bin := filepath.Join(home, "bin")
root := filepath.Join(home, "repo with spaces")
for _, dir := range []string{bin, root} {
for _, dir := range []string{bin} {
if err := os.MkdirAll(dir, 0700); err != nil {
t.Fatal(err)
}
@@ -115,10 +114,7 @@ func TestServiceConfigurationPreviewAndLifecycleWithMockOSManager(t *testing.T)
if err != nil {
t.Fatal(err)
}
if err := ServiceCommand(ctx, server, []string{"enable"}, &out, &out); err == nil {
t.Fatal("workspace scope must be explicit")
}
args := []string{"enable", "--workspace-root", root}
args := []string{"enable"}
if err := ServiceCommand(ctx, server, append(args, "--print"), &out, &out); err != nil {
t.Fatal(err)
}
+12
View File
@@ -9,6 +9,7 @@ import (
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/stage"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
@@ -49,6 +50,17 @@ func TestCLIHeadlessRunInspectionCancellationAndRPC(t *testing.T) {
if response.RunDetail.Input["prompt"] != "exact task" || response.RunDetail.AllowTools {
t.Fatal("prompt or approval changed", response)
}
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
cwd, err = filepath.EvalSymlinks(cwd)
if err != nil {
t.Fatal(err)
}
if response.RunDetail.Workspace != cwd {
t.Fatal("CLI did not use invocation directory", response.RunDetail.Workspace, cwd)
}
output, err = run("run", "workflow", "exact task", "--yes", "--json", "--request-key", "same-key")
if err != nil {
t.Fatal(err)
+7 -26
View File
@@ -16,14 +16,13 @@ import (
)
type runner struct {
ctx context.Context
store *pipeline.Store
mu sync.Mutex
active map[int64]context.CancelFunc
execute func(context.Context, stage.Definition, stage.Values) (stage.Result, error)
wg sync.WaitGroup
schedulerWG sync.WaitGroup
workspaceRoots []string
ctx context.Context
store *pipeline.Store
mu sync.Mutex
active map[int64]context.CancelFunc
execute func(context.Context, stage.Definition, stage.Values) (stage.Result, error)
wg sync.WaitGroup
schedulerWG sync.WaitGroup
}
func newRunner(ctx context.Context, s *pipeline.Store) (*runner, error) {
@@ -69,24 +68,6 @@ func (r *runner) start(request protocol.Message) (*protocol.RunDetail, error) {
if err != nil || !info.IsDir() {
return nil, fmt.Errorf("run workspace must be a directory")
}
allowed := selected == workspace
for _, root := range r.workspaceRoots {
root, err = filepath.Abs(root)
if err != nil {
return nil, err
}
root, err = filepath.EvalSymlinks(root)
if err != nil {
return nil, fmt.Errorf("configured workspace root is unavailable")
}
rel, err := filepath.Rel(root, selected)
if err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
allowed = true
}
}
if !allowed {
return nil, fmt.Errorf("run workspace is outside the server's allowed workspace roots")
}
workspace = selected
}
if len(request.WritePaths) > 20 {
-10
View File
@@ -17,22 +17,12 @@ import (
// Handler serves the persistent connection. Canceling ctx stops active clients.
func Handler(ctx context.Context, stores ...*pipeline.Store) http.Handler {
return handler(ctx, nil, stores...)
}
// HandlerForWorkspaces permits run workspaces only below explicitly configured roots.
func HandlerForWorkspaces(ctx context.Context, store *pipeline.Store, roots []string) http.Handler {
return handler(ctx, roots, store)
}
func handler(ctx context.Context, roots []string, stores ...*pipeline.Store) http.Handler {
mux := http.NewServeMux()
var runs *runner
var runErr error
if len(stores) > 0 {
runs, runErr = newRunner(ctx, stores[0])
if runErr == nil {
runs.workspaceRoots = append([]string(nil), roots...)
runs.schedulerWG.Add(1)
go runs.scheduleLoop()
}
+9 -6
View File
@@ -10,7 +10,7 @@ import (
"testing"
)
func TestRepositoryWorkspaceAllowlistAndAudit(t *testing.T) {
func TestClientSelectedRepositoryWorkspaceAndAudit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
store, err := pipeline.Open(filepath.Join(t.TempDir(), "workspace.db"))
@@ -32,11 +32,11 @@ func TestRepositoryWorkspaceAllowlistAndAudit(t *testing.T) {
if err != nil {
t.Fatal(err)
}
r.workspaceRoots = []string{root}
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
return stage.Result{Outcome: "success", Output: stage.Values{"done": true}}, nil
}
for i, path := range []string{a, b} {
os.Symlink(outside, filepath.Join(root, "linked-repo"))
for i, path := range []string{a, b, outside, filepath.Join(root, "linked-repo")} {
detail, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: path, Input: map[string]any{"prompt": "task"}, Workspace: path})
if err != nil {
t.Fatal(err)
@@ -51,10 +51,13 @@ func TestRepositoryWorkspaceAllowlistAndAudit(t *testing.T) {
t.Fatal("incorrect workspace audit", i, detail)
}
}
os.Symlink(outside, filepath.Join(root, "escape"))
for _, path := range []string{outside, filepath.Join(root, "escape"), "relative/repo"} {
file := filepath.Join(root, "file")
if err := os.WriteFile(file, []byte("not a directory"), 0600); err != nil {
t.Fatal(err)
}
for _, path := range []string{filepath.Join(root, "missing"), file, "relative/repo"} {
if _, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: path, Input: map[string]any{"prompt": "task"}, Workspace: path}); err == nil {
t.Fatal("unauthorized workspace accepted", path)
t.Fatal("invalid run directory accepted", path)
}
}
}
+16
View File
@@ -6,6 +6,7 @@ import (
"git.a-wan.net/alan/pipelines/internal/protocol"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
"os"
"strings"
"testing"
)
@@ -45,6 +46,21 @@ func TestCLIPickerAndMultilinePrompt(t *testing.T) {
}
}
func TestDashboardRunUsesInvocationDirectory(t *testing.T) {
ctx := context.Background()
m := New(ctx, "")
m.detail = &protocol.PipelineDetail{PipelineSummary: protocol.PipelineSummary{ID: 1, Name: "test", Version: 1}}
updated, _ := m.beginRun()
m = updated.(Model)
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if m.runWorkspace != cwd {
t.Fatal("dashboard did not use invocation directory", m.runWorkspace, cwd)
}
}
func TestCLISuppliedArgumentsStillRequireConfirmation(t *testing.T) {
m := NewRun(context.Background(), "", RunOptions{Pipeline: "test", Prompt: "task", Workspace: "/repos/a"})
m.detail = &protocol.PipelineDetail{PipelineSummary: protocol.PipelineSummary{ID: 1, Name: "test", Version: 1}}
+17
View File
@@ -2,6 +2,7 @@ package tui
import (
"fmt"
"os"
"strings"
"time"
@@ -32,6 +33,14 @@ func (m Model) runRequest(request protocol.Message) (tea.Model, tea.Cmd) {
m.runError = ""
}
if request.Type == protocol.RunPipeline {
if request.Workspace == "" {
cwd, err := os.Getwd()
if err != nil {
m.appendLine("cannot determine current directory: " + err.Error())
return m, nil
}
request.Workspace = cwd
}
m.runStartRequest = request.ID
m.keys.runs = true
m.runError = ""
@@ -44,6 +53,14 @@ func (m Model) beginRun() (tea.Model, tea.Cmd) {
m.appendLine("open an exact pipeline version first")
return m, nil
}
if m.runWorkspace == "" {
cwd, err := os.Getwd()
if err != nil {
m.appendLine("cannot determine current directory: " + err.Error())
return m, nil
}
m.runWorkspace = cwd
}
m.runForm = 1
m.runInput = newInput()
m.runPrompt = textarea.New()