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
+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") {