2bde6b6344
- 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>
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
func (a App) confirmAction(question string, yes bool) error {
|
|
if yes {
|
|
return nil
|
|
}
|
|
// An agent's Bash tool has no terminal: a prompt would block on a pipe that
|
|
// never answers. Fail at once with the flag that makes the command
|
|
// non-interactive instead.
|
|
if !a.stdinInteractive() {
|
|
return fmt.Errorf("%s\nconfirmation required but stdin is not a terminal; rerun with --yes to confirm non-interactively", question)
|
|
}
|
|
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
|
|
}
|
|
|
|
// stdinInteractive reports whether a person can answer a prompt. A real file
|
|
// must be a terminal; a nil reader cannot answer. Any other reader is an
|
|
// embedder- or test-supplied answer stream and counts as interactive.
|
|
func (a App) stdinInteractive() bool {
|
|
if a.Interactive != nil {
|
|
return a.Interactive()
|
|
}
|
|
return isTerminal(a.In)
|
|
}
|
|
|
|
// terminalUI reports whether a full-screen terminal UI can run: both stdin and
|
|
// stdout must be terminals. Without one the CLI uses its JSON paths instead.
|
|
func (a App) terminalUI() bool {
|
|
if a.Interactive != nil {
|
|
return a.Interactive()
|
|
}
|
|
return isTerminal(a.In) && isTerminal(a.Out)
|
|
}
|
|
|
|
func isTerminal(stream any) bool {
|
|
switch s := stream.(type) {
|
|
case nil:
|
|
return false
|
|
case *os.File:
|
|
return s != nil && term.IsTerminal(int(s.Fd()))
|
|
case io.Reader, io.Writer:
|
|
return true
|
|
}
|
|
return false
|
|
}
|