Merge: archive and unarchive pipelines

# Conflicts:
#	internal/cli/commands.go
#	internal/pipeline/store.go
This commit is contained in:
2026-11-04 23:39:02 +00:00
30 changed files with 1206 additions and 78 deletions
+24 -4
View File
@@ -52,6 +52,7 @@ type options struct {
all bool
debugFiles bool
json, source, noOpen, yes, allow, createOnly, force, wait bool
archived bool
version, expected, limit, retryVisit int
timeout, waitTimeout time.Duration
stageModels stageModelFlags
@@ -138,6 +139,11 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
f.BoolVar(&o.yes, "yes", false, "Confirm publication (schedules may activate)")
case "template":
f.BoolVar(&o.source, "source", false, "Print original Markdown instead of metadata")
case "list":
f.BoolVar(&o.archived, "archived", false, "List only archived pipelines")
f.BoolVar(&o.all, "all", false, "List active and archived pipelines (archived ones are marked)")
case "archive":
f.BoolVar(&o.yes, "yes", false, "Confirm archiving without an interactive prompt")
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)")
@@ -513,8 +519,10 @@ func (a App) Run(ctx context.Context, args []string) error {
defer cancel()
return c.Call(requestCtx, request)
}
// Resolution includes archived pipelines so history, show and unarchive
// still address them; the server refuses runs and publications for them.
resolve := func(value string) (protocol.PipelineSummary, error) {
r, err := call(protocol.Message{Type: protocol.List})
r, err := call(protocol.Message{Type: protocol.List, IncludeArchived: true})
if err != nil {
return protocol.PipelineSummary{}, err
}
@@ -760,6 +768,8 @@ func (a App) Run(ctx context.Context, args []string) error {
}
}
return nil
case "archive", "unarchive":
return a.archive(command, pos, o, call, resolve)
case "list", "templates", "runs", "ping", "connection":
if command == "runs" && len(pos) > 0 && pos[0] == "rm" {
return a.removeRuns(o, pos[1:], call)
@@ -768,10 +778,13 @@ func (a App) Run(ctx context.Context, args []string) error {
return fmt.Errorf("%s takes no positional arguments", command)
}
typeName := map[string]string{"list": protocol.List, "templates": protocol.ListTemplates, "runs": protocol.ListRuns, "ping": protocol.Ping, "connection": protocol.List}[command]
r, err := call(protocol.Message{Type: typeName})
r, err := call(protocol.Message{Type: typeName, IncludeArchived: command == "list" && (o.all || o.archived)})
if err != nil {
return err
}
if command == "list" && o.archived && !o.all {
r.Pipelines = archivedOnly(r.Pipelines)
}
if command == "runs" && o.name != "" {
p, err := resolve(o.name)
if err != nil {
@@ -791,7 +804,11 @@ func (a App) Run(ctx context.Context, args []string) error {
switch command {
case "list":
for _, p := range r.Pipelines {
fmt.Fprintf(a.Out, "%d\t%s\tv%d\t%d stages\n", p.ID, p.Name, p.Version, p.Stages)
note := ""
if p.ArchivedAt != "" {
note = "\tarchived " + p.ArchivedAt
}
fmt.Fprintf(a.Out, "%d\t%s\tv%d\t%d stages%s\n", p.ID, p.Name, p.Version, p.Stages, note)
}
case "templates":
for _, t := range r.Templates {
@@ -1207,11 +1224,14 @@ func (a App) author(ctx context.Context, command string, pos []string, o *option
if (o.name != "" && strings.TrimSpace(o.name) == "") || len(o.name) > 200 || strings.ContainsAny(o.name, "\r\n\x00") {
return fmt.Errorf("name must be 1–200 bytes without line breaks or NUL")
}
r, err := call(protocol.Message{Type: protocol.List})
r, err := call(protocol.Message{Type: protocol.List, IncludeArchived: true})
if err != nil {
return err
}
for _, p := range r.Pipelines {
if p.Name == o.name && p.ArchivedAt != "" {
return &pipeline.ArchivedError{Name: p.Name}
}
if p.Name == o.name {
return fmt.Errorf("pipeline already exists; use edit or choose another name")
}
+52
View File
@@ -0,0 +1,52 @@
package cli
import (
"fmt"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// archive implements `pipelines archive` and `pipelines unarchive`. The
// server keeps every version and run; the latest version is the guard.
func (a App) archive(command string, pos []string, o *options, call callFunc, resolve resolveFunc) error {
if len(pos) != 1 {
return fmt.Errorf("%s requires one pipeline name or ID; use pipelines help %s", command, command)
}
p, err := resolve(pos[0])
if err != nil {
return err
}
request := protocol.Message{Type: protocol.UnarchivePipeline, PipelineID: p.ID, ExpectedVersion: p.Version}
if command == "archive" {
request.Type = protocol.ArchivePipeline
if err := a.confirmAction("Archive "+p.Name+"? It leaves the pipeline list and cannot start runs; its versions, runs and artifacts are kept and it can be unarchived.", o.yes); err != nil {
return err
}
}
r, err := call(request)
if err != nil {
return err
}
if r.Detail == nil {
return fmt.Errorf("server did not return the pipeline; update pipelines-server")
}
if o.json {
return a.output(r.Detail.PipelineSummary)
}
if command == "archive" {
fmt.Fprintf(a.Out, "Archived %s (history kept; pipelines unarchive %d restores it)\n", r.Detail.Name, r.Detail.ID)
} else {
fmt.Fprintf(a.Out, "Unarchived %s\n", r.Detail.Name)
}
return nil
}
func archivedOnly(items []protocol.PipelineSummary) []protocol.PipelineSummary {
kept := []protocol.PipelineSummary{}
for _, p := range items {
if p.ArchivedAt != "" {
kept = append(kept, p)
}
}
return kept
}
+6 -1
View File
@@ -10,7 +10,9 @@ var usage = map[string]string{
"draft-delete": "draft-delete <draft.md> [--json]",
"validate": "validate <draft.md> [--json]",
"submit": "submit <draft.md> [--name NAME] [--create-only] [--yes] [--json]",
"list": "list [--json]",
"list": "list [--archived | --all] [--json]",
"archive": "archive <name|id> [--yes] [--json]",
"unarchive": "unarchive <name|id> [--json]",
"search": "search QUERY [--type KIND] [--limit N] [--debug-files] [--json]",
"show": "show <name|id> [--version N] [--json]",
"versions": "versions <name|id> [--json]",
@@ -52,6 +54,9 @@ var notes = map[string]string{
"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. --title sets an explicit run title; without it the title is derived from the prompt. --model PROVIDER/MODEL overrides the model for every stage of that run; --stage-model STAGE=PROVIDER/MODEL overrides one stage and is repeatable, with a repeated key last-wins. Precedence is per-stage > whole-run > the model pinned in the pipeline version; overrides apply to that run only and never change the pinned definition. An unknown stage key or a malformed provider/model is refused before the run starts, naming the valid stage keys. In JSON mode --wait polls until terminal; --wait-timeout bounds only the client wait after admission and is independent of per-request --timeout. A reached wait limit leaves the run active: inspect read-only with `inspect <run-id> --json`, or reattach with --wait reusing the original --request-key (never an automatic replay or cancel).",
"retry": "Resume a failed stage by default, restoring the completed prefix handoff; use --mode=restart to start at entry. --stage selects a recorded stage (use --visit for repeated stages). --input-file accepts a bounded JSON object, merged with replacement at the selected stage; '-' reads stdin. Original history and pinned identity are retained; --version selects an explicit published version of the same pipeline only. --wait-timeout leaves an active retry for later read-only inspection or reattachment with the original --request-key, rather than starting a duplicate retry.",
"list": "Lists active pipelines. Archived pipelines are hidden; --archived lists only them and --all lists both, marking archived ones with their archive time.",
"archive": "Retire a pipeline from lists after confirmation (--yes for scripts). Nothing is deleted: versions, runs, artifacts and search history stay and keep its name. An archived pipeline cannot start runs and its name stays reserved (new/submit say so). Archiving is refused while an enabled schedule points at it, naming the schedule; pause or repoint it first. The latest version is sent as a guard, so a publication in between is refused.",
"unarchive": "Return an archived pipeline to lists; it can run and take new versions again. Schedules stay paused until you enable them.",
"runs": "Lists runs newest first; --json includes each run's size_bytes (bytes on disk: artifacts, session exports, server-created Pi session directories and an estimate of its database rows; 0 until first measured) and, when any model stage recorded usage, its usage total (tokens_total, split and cache components, cost). `runs rm <id...>` permanently deletes finished runs (succeeded, failed, canceled, interrupted) with every database row and server-owned file for them, after confirmation (--yes for scripts). Active runs, runs an unfinished retry depends on and unknown ids are refused individually with a reason, and the command then exits 1. User workspaces are never touched. Database pages are reused by SQLite; `retention apply` additionally VACUUMs to shrink the file.",
"title": "Rename a run's operator-facing title after the fact without touching its input, steps or execution. The title is collapsed to a single bounded line and recorded as explicitly set. `pipelines runs` and `pipelines inspect` then show it.",
"wait": "Block until each named run reaches a terminal status - succeeded, failed, canceled or interrupted, and also through a run waiting on a person - then print one line per run with its id, status and outcome, its stage and how long it took, and exit 0 even for a run that finished unsuccessfully. Several ids wait together in one command. The exit is non-zero only for a client-side failure: an unknown run id, a connection that could not be established, or --timeout expiring while a run is still active; a timeout says so plainly, never cancels, retries or otherwise touches a run, and is never reported as its outcome. Read-only: it needs no workspace, is not refused by the workspace guard and writes nothing. --json prints the final run envelope instead of the line (one envelope for one id, an array for several).",
+3 -1
View File
@@ -25,7 +25,7 @@ EXECUTE
rpc <request.json|-> Send any protocol command (automation escape hatch)
BROWSE
list List registered pipelines
list List active pipelines; --archived/--all show archived ones
search QUERY Search pipelines, versions, runs, steps, field text, artifacts
show <name|id> Inspect graph, settings, source and history
versions <name|id> List immutable versions
@@ -42,6 +42,8 @@ AUTHORING — only when the user explicitly asks to create or change a definitio
import [FILE.zip] Select/import definitions; explicitly resolve conflicts
MAINTAIN
archive <name|id> Hide an unused pipeline; versions and runs are kept
unarchive <name|id> Return an archived pipeline to lists and runs
retention report Show what a run-history policy would remove (read-only)
retention apply Remove it after approval; artifacts go with their run
+2 -1
View File
@@ -139,7 +139,8 @@ func (a App) importBundle(ctx context.Context, o *options, pos []string, call ca
entries = keep
}
// All selected sources/names are checked before any publication.
existing, err := call(protocol.Message{Type: protocol.List})
// Archived names stay reserved, so they count as existing here.
existing, err := call(protocol.Message{Type: protocol.List, IncludeArchived: true})
if err != nil {
return err
}