cli

package
v0.54.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 50 Imported by: 0

Documentation

Overview

Package cli defines the suga command tree; cmd/suga only assembles and runs it.

Index

Constants

View Source
const (
	LintDuplicate = "duplicate" // same text after normalization, or nearly the same
	LintConflict  = "conflict"  // same title, different content: the two may contradict each other
	LintStale     = "stale"     // not updated for a long time
)

Candidate kinds reported by `suga memory lint`.

View Source
const (
	LintActionMerge  = "merge"
	LintActionDelete = "delete"
	LintActionReview = "review"
)

Suggested actions attached to a candidate; the command never executes them.

View Source
const (
	// DefaultVerifyRounds is how many fix rounds a failing check gets when
	// --verify-rounds is not given (the first check does not count).
	DefaultVerifyRounds = 2
	// MaxVerifyRounds caps --verify-rounds: an unbounded loop would just burn
	// tokens on a command the model cannot fix.
	MaxVerifyRounds = 5
	// DefaultVerifyTimeout bounds one verify command (--verify-timeout).
	DefaultVerifyTimeout = 10 * time.Minute
)

The --verify delivery check (design docs/design/2026-10-21-run-verify-design.md): after a normally finished turn the caller's command decides whether the delivery is done; a failure is handed back to the model as an injected turn.

Variables

View Source
var ErrInputRequired = errors.New("turn requires more input")
View Source
var ErrOutputContract = errors.New("回答不符合调用方的输出契约")

ErrOutputContract ends a run with exit code 6: after one correction round the answer still does not satisfy the caller's schema. It is kept apart from ErrVerifyFailed (5): "the delivery did not pass its check" is not the same failure as "the answer's shape is wrong".

View Source
var ErrVerifyFailed = errors.New("验证未通过")

ErrVerifyFailed ends a run with exit code 5: the --verify command never passed within --verify-rounds fix rounds. Its value stays the sentinel text: errors.Is answers it, machine lines keep reading it (verifyFailedError).

Functions

func ErrorText

func ErrorText(err error, tr i18n.Translator) string

ErrorText is the line text mode prints for err: the localized rendering when the error has one, else err.Error(). A nil translator keeps err.Error(), so a caller without a catalog never loses the message.

func ExitCode

func ExitCode(err error) int

ExitCode maps a command error to the process exit code: the error's own ExitCode() when it has one, else 1.

func New

func New(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, build Build) *capp.App

New builds the root command with all subcommands registered.

func NewPersonalCommand

func NewPersonalCommand(ctx context.Context, mode string, stdin io.Reader, stdout, stderr io.Writer) *capp.Cmd

NewPersonalCommand owns the flags and validation shared by direct CLI calls and the root command registry.

func NormalizeArgs

func NormalizeArgs(args []string) []string

NormalizeArgs turns an invocation whose first argument is a chat option into the explicit `suga chat …` form (design D6). Old top-level commands are left alone: they fail as unknown commands, see RunArgs.

func RunArgs

func RunArgs(app *capp.App, args []string) error

RunArgs runs the command tree with args. A pre-v0.36 top-level command form (removed in v0.38) fails as an ordinary unknown command; the returned error then also names the new spelling, so the user is not left guessing.

func RunPersonalACP

func RunPersonalACP(ctx context.Context, input io.Reader, output io.Writer) error

RunPersonalACP serves the same persistent personal runner used by CLI over stdio.

func RunPersonalCLI

func RunPersonalCLI(ctx context.Context, mode string, args []string, stdin io.Reader, stdout, stderr io.Writer) error

RunPersonalCLI is the shared headless and interactive entry, independent of the old Web host.

func RunPersonalChat

func RunPersonalChat(ctx context.Context, args []string) error

RunPersonalChat gives the terminal REPL the same persistent session engine as run mode.

func Translator

func Translator() i18n.Translator

Translator resolves the startup language for the process itself: commands that do not assemble a wiring.Runtime and cmd/suga's closing error line use it.

Types

type Build

type Build struct {
	// Version is the semantic version shown by the root app.
	Version string
	// VersionLine is the full "suga <version> (<commit>)" line printed by
	// `suga version` and --version.
	VersionLine string
}

Build carries the binary's version metadata injected by cmd/suga.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL