Configure full Docker setup and confirm consequential actions

This commit is contained in:
2026-10-09 21:34:47 +01:00
parent f60599230c
commit f700d1beb2
31 changed files with 587 additions and 49 deletions
+3
View File
@@ -29,6 +29,9 @@ Do not edit repositories or shared OpenCode configuration while authoring.
5. Summarize the change, validation outcome, edit/tool permissions, and any schedule
activation. Give the user the exact `pipelines submit DRAFT_PATH` command.
6. **Do not submit or run by default.** Leave a retained draft for human review.
Publication, execution, retry, cancellation and draft deletion ask for confirmation.
Use `--yes` for these CLI commands only after the user explicitly approves the
specific action; never treat approval of editing as approval of publishing/running.
Submit only when the user explicitly asks you to submit. Run only when asked.
The CLI supports `list`, `show`, `versions`, `export`, `templates`, `template`,
+20 -1
View File
@@ -59,6 +59,7 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
case "template":
f.BoolVar(&o.source, "source", false, "Print original Markdown instead of metadata")
case "submit":
f.BoolVar(&o.yes, "yes", false, "Confirm publication without an interactive prompt")
f.StringVar(&o.name, "name", "", "Name for an external Markdown file (managed drafts already know their name)")
f.BoolVar(&o.createOnly, "create-only", false, "Reject existing names rather than creating another version")
f.IntVar(&o.expected, "expected-version", 0, "Reject if the latest version changed")
@@ -67,7 +68,7 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
f.StringVar(&o.name, "pipeline", "", "Exact registered pipeline name or ID")
f.StringVar(&o.prompt, "prompt", "", "Task prompt; omitted opens a multiline composer")
f.StringVar(&o.workspace, "workspace", "", "Run directory (default: current directory)")
f.BoolVar(&o.yes, "yes", false, "Compatibility flag; supplied name/prompt already start immediately")
f.BoolVar(&o.yes, "yes", false, "Confirm execution without an interactive prompt")
f.BoolVar(&o.allow, "allow-tools", false, "Compatibility flag; stage-declared tools are enabled automatically")
f.StringVar(&o.paths, "write-paths", "", "Optional narrower edit scope; default is all files in the run directory")
f.StringVar(&o.key, "request-key", "", "Idempotency key (default: generated unique key)")
@@ -76,8 +77,11 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
case "runs":
f.StringVar(&o.name, "pipeline", "", "Filter by exact pipeline name or ID")
case "retry":
f.BoolVar(&o.yes, "yes", false, "Confirm retry without an interactive prompt")
f.StringVar(&o.key, "request-key", "", "Idempotency key (default: generated unique key)")
f.BoolVar(&o.wait, "wait", false, "Wait for the new run to finish")
case "cancel", "draft-delete":
f.BoolVar(&o.yes, "yes", false, "Confirm this action without an interactive prompt")
case "debug":
f.StringVar(&o.opencode, "opencode", envOr("PIPELINES_OPENCODE", "opencode"), "Host OpenCode executable")
f.BoolVar(&o.noOpen, "no-open", false, "Print the investigation prompt without launching OpenCode")
@@ -202,6 +206,9 @@ func (a App) Run(ctx context.Context, args []string) error {
if len(pos) != 1 {
return fmt.Errorf("draft-delete requires one retained draft path")
}
if err := a.confirmAction("Delete retained draft "+pos[0]+"?", o.yes); err != nil {
return err
}
if err := draft.Delete(pos[0]); err != nil {
return err
}
@@ -396,6 +403,9 @@ func (a App) Run(ctx context.Context, args []string) error {
expected = 0
}
request = protocol.Message{Type: protocol.Submit, Name: name, Source: source, CreateOnly: d.CreateOnly || o.createOnly, ExpectedVersion: expected}
if err := a.confirmAction("Publish "+name+" as an immutable version? Included schedules activate on acceptance.", o.yes); err != nil {
return err
}
}
r, err := call(request)
if err != nil {
@@ -524,10 +534,16 @@ func (a App) Run(ctx context.Context, args []string) error {
}
typeName := protocol.GetRun
if command == "cancel" {
if err := a.confirmAction(fmt.Sprintf("Cancel run #%d? Previous side effects are not undone.", id), o.yes); err != nil {
return err
}
typeName = protocol.CancelRun
}
key := ""
if command == "retry" {
if err := a.confirmAction(fmt.Sprintf("Retry failed run #%d as a fresh run? Reuses original input/directory; side effects may repeat.", id), o.yes); err != nil {
return err
}
typeName = protocol.RetryRun
key = o.key
if key == "" {
@@ -759,6 +775,9 @@ func (a App) run(ctx context.Context, pos []string, o *options, call callFunc, r
if version == 0 {
version = p.Version
}
if err := a.confirmAction(fmt.Sprintf("Run %s v%d in %s? This may edit files, execute commands and publish notifications.", p.Name, version, workspace), o.yes); err != nil {
return err
}
key := o.key
if key == "" {
key = fmt.Sprintf("cli-%d-%d", os.Getpid(), time.Now().UnixNano())
+3
View File
@@ -32,6 +32,9 @@ func setup(t *testing.T) (func(...string) (string, error), *pipeline.Store, stri
url := "ws" + strings.TrimPrefix(http.URL, "http") + "/connect"
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
return func(args ...string) (string, error) {
if len(args) > 0 && args[0] == "submit" {
args = append(args, "--yes")
}
var out, stderr bytes.Buffer
app := cli.App{Out: &out, Err: &stderr, In: strings.NewReader("")}
err := app.Run(ctx, append([]string{"--url", url}, args...))
+3 -3
View File
@@ -7,7 +7,7 @@ var usage = map[string]string{
"drafts": "drafts [--json]",
"draft-delete": "draft-delete <draft.md> [--json]",
"validate": "validate <draft.md> [--json]",
"submit": "submit <draft.md> [--name NAME] [--create-only] [--json]",
"submit": "submit <draft.md> [--name NAME] [--create-only] [--yes] [--json]",
"list": "list [--json]",
"show": "show <name|id> [--version N] [--json]",
"versions": "versions <name|id> [--json]",
@@ -32,8 +32,8 @@ var notes = map[string]string{
"new": "Create an optional template copy or a one-stage starter. Opens OpenCode with @pipelines; the skill asks any missing questions, including the name. No submission is performed.",
"edit": "Omit the name to open fuzzy selection. Original immutable source is copied to a private draft. OpenCode edits that draft, never the live definition.",
"validate": "Uses the same server parser as submission. Does not persist or activate schedules. Structural validity does not prove runtime/tool availability.",
"submit": "This command is explicit approval to publish; schedules activate on acceptance. Managed drafts provide the name and base-version guard. --force never bypasses validation.",
"run": "Runs in your current directory. Supplied name/prompt start immediately; otherwise select a pipeline and send a multiline task with Ctrl+S. Stage tools are enabled automatically; no file list or RUN confirmation. Cancellation does not undo edits.",
"submit": "Confirm publication at the prompt, or use --yes for explicit automation; schedules activate on acceptance. Managed drafts provide the name and base-version guard. --force never bypasses validation.",
"run": "Runs in your current directory after action confirmation (--yes skips it). Select a pipeline and compose a multiline task with Ctrl+S. Stage tools are enabled automatically; no file list or typed RUN confirmation. Cancellation does not undo edits.",
"retry": "Start a new attempt of a failed run with the same initial input, directory, pipeline version, and edit scope. Original history is retained. Already-completed side effects are not undone.",
"debug": "Open a fresh OpenCode conversation to investigate a run using inspect/show/runs CLI queries. Does not resume the implementing session or retry the run. --json returns the investigation prompt without opening OpenCode.",
"rpc": "Accepts a JSON protocol envelope; '-' reads stdin. Every TUI server operation is available here too. Mutating commands are not dry runs.",
+19
View File
@@ -0,0 +1,19 @@
package cli
import (
"bufio"
"fmt"
"strings"
)
func (a App) confirmAction(question string, yes bool) error {
if yes {
return nil
}
fmt.Fprint(a.Err, question+" [y/N]: ")
line, _ := bufio.NewReader(a.In).ReadString('\n')
if answer := strings.ToLower(strings.TrimSpace(line)); answer != "y" && answer != "yes" {
return fmt.Errorf("action canceled; use --yes for explicit non-interactive confirmation")
}
return nil
}
+38
View File
@@ -0,0 +1,38 @@
package cli
import (
"bytes"
"context"
"git.a-wan.net/alan/pipelines/internal/draft"
"os"
"strings"
"testing"
)
func TestActionConfirmationDefaultsToNoAndKeepsJSONOutputClean(t *testing.T) {
for _, answer := range []string{"", "\n", "no\n", "yes\n", "y\n"} {
var out, stderr bytes.Buffer
a := App{Out: &out, Err: &stderr, In: strings.NewReader(answer)}
err := a.confirmAction("Retry run #42?", false)
want := answer == "yes\n" || answer == "y\n"
if (err == nil) != want || out.Len() != 0 || !strings.Contains(stderr.String(), "[y/N]") {
t.Fatal("unsafe confirmation", answer, err)
}
}
}
func TestDraftDeletionNeedsConfirmation(t *testing.T) {
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
d, err := draft.Create("keep", "source", "server", true, 0)
if err != nil {
t.Fatal(err)
}
var out bytes.Buffer
a := App{Out: &out, Err: &out, In: strings.NewReader("\n")}
if err := a.Run(context.Background(), []string{"draft-delete", d.Path}); err == nil {
t.Fatal("unconfirmed deletion accepted")
}
if _, err := os.Stat(d.Path); err != nil {
t.Fatal("unconfirmed draft removed", err)
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ func TestDraftDeleteWorksWithoutServerConnection(t *testing.T) {
}
var out bytes.Buffer
a := App{Out: &out, Err: &out, In: strings.NewReader("")}
if err := a.Run(context.Background(), []string{"draft-delete", d.Path, "--json", "--url", "not-a-server"}); err != nil {
if err := a.Run(context.Background(), []string{"draft-delete", d.Path, "--yes", "--json", "--url", "not-a-server"}); err != nil {
t.Fatal(err)
}
if !strings.Contains(out.String(), "deleted") {
+2 -2
View File
@@ -42,7 +42,7 @@ func TestCLIHeadlessRunInspectionCancellationAndRPC(t *testing.T) {
err := app.Run(ctx, append([]string{"--url", url}, args...))
return out.String(), err
}
output, err := run("run", "workflow", "exact task", "--json", "--request-key", "same-key")
output, err := run("run", "workflow", "exact task", "--yes", "--json", "--request-key", "same-key")
if err != nil {
t.Fatal(err)
}
@@ -88,7 +88,7 @@ func TestCLIHeadlessRunInspectionCancellationAndRPC(t *testing.T) {
if _, err = run("run", "workflow", "exact task", "--yes", "--json", "--request-key", "same-key", "--wait", "--timeout", "100ms"); err == nil || !strings.Contains(err.Error(), "remains active") {
t.Fatal("wait timeout canceled or incorrectly succeeded", err)
}
if _, err = run("cancel", "1", "--json"); err != nil {
if _, err = run("cancel", "1", "--yes", "--json"); err != nil {
t.Fatal(err)
}
r.wg.Wait()
+10 -3
View File
@@ -166,7 +166,14 @@ func TestRetryReplaysInitialInputAndPinnedVersionThroughCLI(t *testing.T) {
}
return result, err
}
result, err := runCLI("retry", fmt.Sprint(original.ID), "--json", "--wait", "--timeout", "5s", "--request-key", "retry-key")
if _, err := runCLI("retry", fmt.Sprint(original.ID), "--json"); err == nil || !strings.Contains(err.Error(), "action canceled") {
t.Fatal("unconfirmed retry accepted", err)
}
beforeRetry, err := store.ListRuns(ctx)
if err != nil || len(beforeRetry) != 1 {
t.Fatal("unconfirmed retry created a run", err)
}
result, err := runCLI("retry", fmt.Sprint(original.ID), "--yes", "--json", "--wait", "--timeout", "5s", "--request-key", "retry-key")
if err != nil {
t.Fatal(err)
}
@@ -175,7 +182,7 @@ func TestRetryReplaysInitialInputAndPinnedVersionThroughCLI(t *testing.T) {
t.Fatal("retry did not preserve recorded run settings", retried)
}
r.wg.Wait()
again, err := runCLI("retry", fmt.Sprint(original.ID), "--json", "--request-key", "retry-key")
again, err := runCLI("retry", fmt.Sprint(original.ID), "--yes", "--json", "--request-key", "retry-key")
if err != nil || again.RunDetail.ID != retried.ID {
t.Fatal("retry lost idempotency", again, err)
}
@@ -183,7 +190,7 @@ func TestRetryReplaysInitialInputAndPinnedVersionThroughCLI(t *testing.T) {
if err != nil || !reflect.DeepEqual(original, unchanged) {
t.Fatal("retry modified failed history", unchanged, err)
}
if _, err := runCLI("retry", fmt.Sprint(retried.ID), "--json"); err == nil {
if _, err := runCLI("retry", fmt.Sprint(retried.ID), "--yes", "--json"); err == nil {
t.Fatal("succeeded run accepted for retry")
}
if _, err := r.retry(protocol.Message{RunID: original.ID}); err == nil {
+34
View File
@@ -0,0 +1,34 @@
package tui
import (
"fmt"
"git.a-wan.net/alan/pipelines/internal/protocol"
tea "github.com/charmbracelet/bubbletea"
)
func (m Model) updateActionConfirm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "esc", "n":
m.actionConfirm = nil
return m, nil
case "y":
request := *m.actionConfirm
m.actionConfirm = nil
return m.sendRunRequest(request)
}
return m, nil
}
func (m Model) actionConfirmView(height int) string {
r := m.actionConfirm
lines := []string{"Start pipeline run?", fmt.Sprintf("Pipeline #%d · v%d", r.PipelineID, r.Version), "Directory: " + r.Workspace,
"This may edit files, execute commands and publish notifications."}
if r.Type == protocol.RetryRun {
lines = []string{fmt.Sprintf("Retry failed run #%d?", r.RunID), "Starts a NEW run from the entry stage with fresh OpenCode sessions.",
"Reuses the original input, directory, pinned version and edit scope.", "Previous side effects are not undone; commands/notifications may repeat."}
}
if r.Type == protocol.CancelRun {
lines = []string{fmt.Sprintf("Cancel run #%d?", r.RunID), "Stops execution and interrupts its active agent.", "Sessions/history are retained; previous side effects are not undone."}
}
return popup(m.width, height, 96, append(lines, "", "y confirm · n / Esc cancel"))
}
+35
View File
@@ -0,0 +1,35 @@
package tui
import (
"context"
"git.a-wan.net/alan/pipelines/internal/protocol"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
"strings"
"testing"
)
func TestConsequentialRunActionsRequireExplicitYes(t *testing.T) {
for _, action := range []string{protocol.RunPipeline, protocol.RetryRun, protocol.CancelRun} {
for _, cancel := range []string{"n", "esc"} {
m := New(context.Background(), "")
updated, cmd := m.runRequest(protocol.Message{Type: action, RunID: 42, PipelineID: 3, Version: 2, Workspace: "/original"})
m = updated.(Model)
if cmd != nil || m.nextID != 0 || m.actionConfirm == nil {
t.Fatal("action sent before approval", action)
}
if !strings.Contains(ansi.Strip(m.View()), "y confirm") {
t.Fatal("missing confirmation", action)
}
updated, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
m = updated.(Model)
if cmd != nil || m.actionConfirm == nil {
t.Fatal("Enter must not approve by default")
}
m = press(m, cancel)
if m.actionConfirm != nil || m.nextID != 0 || m.runStartRequest != "" {
t.Fatal("canceled action was sent")
}
}
}
}
+3 -3
View File
@@ -61,12 +61,12 @@ func TestDashboardRunUsesInvocationDirectory(t *testing.T) {
}
}
func TestCLISuppliedArgumentsStartWithoutConfirmation(t *testing.T) {
func TestCLISuppliedArgumentsRequireConfirmation(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}}
updated, _ := m.configureCLIRun()
m = updated.(Model)
if m.runForm != 0 || !m.runOpen || m.runTask != "task" || m.runWorkspace != "/repos/a" {
t.Fatal("supplied task did not start immediately or lost repository")
if m.runForm != 0 || !m.runOpen || m.runTask != "task" || m.runWorkspace != "/repos/a" || m.actionConfirm == nil || m.actionConfirm.Workspace != "/repos/a" || m.runStartRequest != "" {
t.Fatal("supplied task bypassed confirmation or lost repository")
}
}
+2 -2
View File
@@ -49,8 +49,8 @@ func TestHomeShortcutOpensAllRunsAndDisplaysHintInBothPanels(t *testing.T) {
m.runIndex = 1
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}})
m = updated.(Model)
if cmd == nil || m.runStartRequest == "" {
t.Fatal("r on failed list no longer retries")
if cmd != nil || m.actionConfirm == nil || m.actionConfirm.Type != protocol.RetryRun {
t.Fatal("r on failed list should request retry confirmation")
}
m.closeRuns()
if m.runFailedOnly {
+8 -3
View File
@@ -132,6 +132,7 @@ type Model struct {
versionsOpen bool
versionIndex int
confirmOpen bool
actionConfirm *protocol.Message
pendingDraft *editedMsg
submitID string
submitNotice string
@@ -192,7 +193,7 @@ func New(ctx context.Context, url string) Model {
enter: key.NewBinding(key.WithKeys("enter"), key.WithHelp("enter", "continue")),
cancel: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "cancel")),
ping: key.NewBinding(key.WithKeys("t"), key.WithHelp("t", "test ping")),
quit: key.NewBinding(key.WithKeys("q", "ctrl+c"), key.WithHelp("q", "quit")),
quit: key.NewBinding(key.WithKeys(":quit"), key.WithHelp(":quit", "quit")),
},
}
}
@@ -486,6 +487,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.String() == "ctrl+c" {
return m, tea.Quit
}
if m.actionConfirm != nil {
return m.updateActionConfirm(msg)
}
if m.editorChecking {
return m, nil
}
@@ -547,8 +551,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.commandInput.SetValue(":")
}
return m, m.commandInput.Focus()
case m.homePage() && key.Matches(msg, m.keys.quit):
return m, tea.Quit
case m.homePage() && key.Matches(msg, m.keys.create):
if m.conn == nil {
m.appendLine("not connected")
@@ -712,6 +714,9 @@ func (m Model) View() string {
if m.statusOpen {
content = m.statusView(bodyHeight)
}
if m.actionConfirm != nil {
content = m.actionConfirmView(bodyHeight)
}
if m.editorChecking {
content = popup(m.width, bodyHeight, 76, []string{"Checking published edits", m.loading("Refreshing pipeline information…"), "Local draft remains retained."})
}
+2 -2
View File
@@ -47,8 +47,8 @@ func TestTKeyPingRoundTrip(t *testing.T) {
t.Fatalf("missing responses: %s", text)
}
_, quit := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}})
if _, ok := quit().(tea.QuitMsg); !ok {
t.Fatal("q did not quit")
if quit != nil {
t.Fatal("q should not quit")
}
}
+5
View File
@@ -66,6 +66,11 @@ func TestRetryShortcutAndPaletteSendServerRetryWithoutReplacingDirectory(t *test
updated, send = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}})
}
m = updated.(Model)
if send != nil || m.actionConfirm == nil || m.actionConfirm.RunID != id || m.runStartRequest != "" {
t.Fatal("retry must ask before sending")
}
updated, send = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}})
m = updated.(Model)
if send == nil || m.runStartRequest == "" || m.runDetail != nil || m.requestedRunID != 0 {
t.Fatal("retry did not start cleanly")
}
+16 -1
View File
@@ -16,6 +16,14 @@ type runTick struct{}
func runPoll() tea.Cmd { return tea.Tick(time.Second, func(time.Time) tea.Msg { return runTick{} }) }
func (m Model) runRequest(request protocol.Message) (tea.Model, tea.Cmd) {
if request.Type == protocol.RunPipeline || request.Type == protocol.RetryRun || request.Type == protocol.CancelRun {
m.actionConfirm = &request
return m, nil
}
return m.sendRunRequest(request)
}
func (m Model) sendRunRequest(request protocol.Message) (tea.Model, tea.Cmd) {
if m.conn == nil {
m.appendLine("not connected")
return m, nil
@@ -112,7 +120,14 @@ func (m *Model) startSelectedRun() tea.Cmd {
m.runCollapsed = nil
m.runDetail = nil
m.runTop = 0
updated, cmd := m.runRequest(protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace})
request := protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace}
updated, cmd := m.runRequest(request)
if m.cliRun && m.cliOptions.Yes {
updated, cmd = m.sendRunRequest(request)
after := updated.(Model)
after.cliOptions.Yes = false
updated = after
}
*m = updated.(Model)
return cmd
}
+21
View File
@@ -81,3 +81,24 @@ func TestCtrlCRemainsGlobal(t *testing.T) {
t.Fatal("Ctrl+C did not quit")
}
}
func TestQuitUsesCommandInsteadOfQ(t *testing.T) {
for _, m := range []Model{New(context.Background(), ""), panelModel(t), runInspectionModel()} {
_, cmd := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}})
if cmd != nil {
t.Fatal("q must not quit")
}
if !slices.Contains(m.pageCommands(), ":quit") {
t.Fatal("quit command missing")
}
m = press(m, ":")
m = press(m, "quit")
_, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
if cmd == nil {
t.Fatal("quit command did not exit")
}
if _, ok := cmd().(tea.QuitMsg); !ok {
t.Fatal("quit command did not return QuitMsg")
}
}
}