CLI for agents: non-TTY safe run/confirmations, compact inspect, wait hints and exit codes

- Without a terminal, run behaves as --json, tui refuses and confirmations
  fail fast naming --yes instead of prompting.
- inspect prints a compact summary by default; --step N, --transcripts and
  --json give detail.
- wait names a failed run's stage and first diagnostic line, prints how to
  answer a run waiting on a person, and exits 2 when any run failed,
  was canceled or interrupted (1 stays for client errors).
- help describes the current # outcome / # handoff format.
- Task starter's Land stage drops edit to match format.md; skill docs
  document run --json --yes, retry --yes --json and the new behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 00:27:14 +00:00
parent accb9970b6
commit 2bde6b6344
16 changed files with 658 additions and 56 deletions
+83 -7
View File
@@ -36,6 +36,9 @@ type App struct {
// Install is the native installation manifest this CLI belongs to, or nil
// (Docker installation, or a development/Go-installed CLI).
Install *installation.Config
// Interactive overrides terminal detection (tests and embedders). Nil
// detects it: stdin (and stdout for full-screen views) must be terminals.
Interactive func() bool
}
type options struct {
outputFormat string
@@ -53,6 +56,8 @@ type options struct {
debugFiles bool
json, source, noOpen, yes, allow, createOnly, force, wait bool
archived bool
transcripts bool
step int
version, expected, limit, retryVisit int
timeout, waitTimeout time.Duration
stageModels stageModelFlags
@@ -185,6 +190,9 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
f.IntVar(&o.version, "version", 0, "Explicit published version of the same pipeline (default: source version)")
f.StringVar(&o.retryInputFile, "input-file", "", "JSON object merged into the selected stage input; '-' reads stdin")
f.StringVar(&o.notifyMode, "notify", "auto", "Notifications for this retry: auto, on, or off")
case "inspect":
f.IntVar(&o.step, "step", 0, "Show one step (its sequence number) in full, without its transcript")
f.BoolVar(&o.transcripts, "transcripts", false, "Include stage transcripts (long)")
case "cancel", "draft-delete":
f.BoolVar(&o.yes, "yes", false, "Confirm this action without an interactive prompt")
case "retention":
@@ -474,6 +482,9 @@ func (a App) Run(ctx context.Context, args []string) error {
if len(pos) > 0 {
return fmt.Errorf("tui takes no arguments")
}
if !a.terminalUI() {
return fmt.Errorf("the dashboard needs a terminal; use pipelines runs, inspect or wait instead")
}
_, err := tea.NewProgram(tui.New(ctx, o.url), tea.WithContext(ctx), tea.WithAltScreen()).Run()
return err
}
@@ -973,7 +984,7 @@ func (a App) Run(ctx context.Context, args []string) error {
}
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 {
if err := a.confirmAction(fmt.Sprintf("Retry run #%d (failed or interrupted) as a fresh run? Reuses original input/directory; side effects may repeat.", id), o.yes); err != nil {
return err
}
typeName = protocol.RetryRun
@@ -1041,6 +1052,7 @@ func (a App) Run(ctx context.Context, args []string) error {
for _, warning := range r.RunDetail.Warnings {
a.notice("warning: " + warning)
}
return a.inspect(r.RunDetail, o)
}
return a.output(r.RunDetail)
case "decide":
@@ -1361,6 +1373,11 @@ func (a App) run(ctx context.Context, pos []string, o *options, call callFunc, r
if o.yes && (o.name == "" || strings.TrimSpace(o.prompt) == "") {
return fmt.Errorf("--yes requires a pipeline and nonempty prompt")
}
// Without a terminal (an agent's Bash tool, a pipe, CI) the full-screen run
// view would hang; behave as --json, which never prompts without --yes.
if !o.json && !a.terminalUI() {
o.json = true
}
if !o.json {
if o.name != "" {
p, err := resolve(o.name)
@@ -1455,7 +1472,14 @@ func (a App) finishRun(ctx context.Context, r protocol.Message, o *options, call
return err
}
if o.wait && r.RunDetail.Status != "succeeded" {
return fmt.Errorf("run ended %s", r.RunDetail.Status)
message := fmt.Sprintf("run %d ended %s", r.RunDetail.ID, r.RunDetail.Status)
if note := failureNote(r.RunDetail); note != "" {
message += " (" + note + ")"
}
if hint := waitingHint(r.RunDetail); hint != "" {
message += "; " + hint
}
return &StatusError{Code: WaitRunsUnsuccessful, Message: message}
}
return nil
}
@@ -1496,6 +1520,21 @@ func (a App) wait(ctx context.Context, pos []string, o *options, call callFunc)
deadline = timer.C
}
terminal := make([]protocol.Message, 0, len(initial))
// A run parked on a human decision keeps the wait blocking; say once per
// waiting visit how to answer it, so an agent is not left guessing.
announced := map[int64]string{}
onActive := func(r protocol.Message) {
hint := waitingHint(r.RunDetail)
if hint == "" || announced[r.RunDetail.ID] == hint {
return
}
announced[r.RunDetail.ID] = hint
if o.json {
a.notice(hint)
return
}
fmt.Fprintln(a.Out, hint)
}
err := a.awaitRuns(ctx, initial, deadline, call, runUnfinished, func(r protocol.Message) error {
terminal = append(terminal, r)
if o.json {
@@ -1503,7 +1542,7 @@ func (a App) wait(ctx context.Context, pos []string, o *options, call callFunc)
}
_, writeErr := fmt.Fprintln(a.Out, waitLine(r.RunDetail))
return writeErr
})
}, onActive)
if err != nil {
var limit *waitLimitError
if errors.As(err, &limit) {
@@ -1512,12 +1551,32 @@ func (a App) wait(ctx context.Context, pos []string, o *options, call callFunc)
return err
}
if o.json {
var outputErr error
if len(terminal) == 1 {
return a.output(terminal[0])
outputErr = a.output(terminal[0])
} else {
outputErr = a.output(terminal)
}
if outputErr != nil {
return outputErr
}
return a.output(terminal)
}
return nil
return unsuccessfulRuns(terminal)
}
// unsuccessfulRuns is the wait's exit status: nil when every run succeeded,
// otherwise a StatusError (exit 2) naming the runs that did not.
func unsuccessfulRuns(runs []protocol.Message) error {
var failed []string
for _, r := range runs {
if r.RunDetail.Status != "succeeded" {
failed = append(failed, fmt.Sprintf("run %d %s", r.RunDetail.ID, r.RunDetail.Status))
}
}
if len(failed) == 0 {
return nil
}
return &StatusError{Code: WaitRunsUnsuccessful, Message: strings.Join(failed, ", ") + "; read pipelines inspect ID, then retry with pipelines retry ID --yes --json or fix directly"}
}
// awaitRuns polls unfinished runs using GetRun reattachment. Export waits remain
@@ -1526,10 +1585,16 @@ func (a App) wait(ctx context.Context, pos []string, o *options, call callFunc)
// entry, in the order supplied). A deadline that passes first returns a
// *waitLimitError naming the runs still active; ctx ending first returns
// ctx.Err(). It never cancels, retries or otherwise changes a run.
func (a App) awaitRuns(ctx context.Context, runs []protocol.Message, deadline <-chan time.Time, call callFunc, active func(string) bool, onTerminal func(protocol.Message) error) error {
func (a App) awaitRuns(ctx context.Context, runs []protocol.Message, deadline <-chan time.Time, call callFunc, active func(string) bool, onTerminal func(protocol.Message) error, onActive ...func(protocol.Message)) error {
progress := func(r protocol.Message) {
for _, f := range onActive {
f(r)
}
}
remaining := make([]protocol.Message, 0, len(runs))
for _, r := range runs {
if active(r.RunDetail.Status) || (r.RunDetail.Status == protocol.RunStatusWaiting && r.RunDetail.ExportPendingSequence > 0) {
progress(r)
remaining = append(remaining, r)
continue
}
@@ -1555,6 +1620,7 @@ func (a App) awaitRuns(ctx context.Context, runs []protocol.Message, deadline <-
return fmt.Errorf("server did not return run detail for %d", r.RunDetail.ID)
}
if active(refreshed.RunDetail.Status) || (refreshed.RunDetail.Status == protocol.RunStatusWaiting && refreshed.RunDetail.ExportPendingSequence > 0) {
progress(refreshed)
next = append(next, refreshed)
continue
}
@@ -1620,6 +1686,16 @@ func waitLine(d *protocol.RunDetail) string {
if elapsed := runElapsed(d.CreatedAt, d.FinishedAt); elapsed != "" {
line += " · " + elapsed
}
// An unsuccessful run also names the stage it stopped at (when that is not
// the stage already shown) and the first line of its diagnostic.
if failing, diagnostic := failureDetail(d); failing != "" || diagnostic != "" {
if failing != "" && failing != strings.TrimSpace(d.CurrentStage) {
line += " · failed at " + failing
}
if diagnostic != "" {
line += " · " + diagnostic
}
}
return line
}