cli

package
v0.85.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

pi: src/cli/args.ts — CLI argument parsing and help display.

pi: src/cli/auth-check.ts — provider auth readiness checks for `pig auth check`.

pi: src/cli/auth-command.ts — auth subcommand parsing and validation.

pi: src/cli/credential-print.ts — resolve one configured provider credential for `auth print-api-key` / `auth print-bearer-token`.

Package cli corresponds to pi's packages/coding-agent/src/cli.

pi: src/cli/file-processor.ts — Process @file CLI arguments into text content and image attachments

pi: src/cli/initial-message.ts

pi: src/cli/list-models.ts — list available models with optional fuzzy search.

session_picker.go (pi: cli/session-picker.ts) — TUI session selector for the --resume flag. Runs in a temporary startup TUI before interactive mode mounts; returns the selected session path (ok=false when cancelled).

startup_ui.go (pi: src/cli/startup-ui.ts) — startup TUI composition: theme registration, first-time setup, and blocking startup selectors/ inputs used before interactive mode mounts.

Index

Constants

View Source
const (
	ArgDiagnosticWarning = "warning"
	ArgDiagnosticError   = "error"
)

Variables

This section is empty.

Functions

func CreateAuthCheckModelRuntime

func CreateAuthCheckModelRuntime(credentials auth.CredentialStore) *core.ModelRuntime

CreateAuthCheckModelRuntime builds the no-network runtime used by auth checks (pi: createAuthCheckModelRuntime).

func CreateStartupTui

func CreateStartupTui(settingsManager *core.SettingsManager) *tui.TuiMainScreen

CreateStartupTui builds the startup renderer with registered themes and keybindings (pi: createStartupTui).

func GetAuthCommandName

func GetAuthCommandName(kind AuthCommandKind) string

GetAuthCommandName returns the display name of an auth command (pi: getAuthCommandName).

func GetAuthCommandUsage

func GetAuthCommandUsage(kind AuthCommandKind) string

GetAuthCommandUsage returns the usage line of an auth command (pi: getAuthCommandUsage).

func GetAuthCredential

func GetAuthCredential(authResult *auth.AuthResult) string

GetAuthCredential extracts the printable credential from an auth result (pi: getAuthCredential). Header lookup uses a deterministic scan (pi's Object.entries order is insertion order; pig's header map is unordered, and at most one Authorization header exists in practice).

func GetProviderCredential

func GetProviderCredential(ctx context.Context, providerID string, modelRuntime *core.ModelRuntime, credentials auth.CredentialStore, options *GetProviderCredentialOptions) (string, bool, error)

GetProviderCredential reads the current credential for a provider (pi: getProviderCredential). ok=false = no credential available.

func IsAuthCommandHelp

func IsAuthCommandHelp(args []string) bool

IsAuthCommandHelp reports whether the args invoke auth help (pi: isAuthCommandHelp).

func IsValidThinkingLevel

func IsValidThinkingLevel(level string) bool

IsValidThinkingLevel reports whether level is one of the valid thinking levels (pi: isValidThinkingLevel). The vocabulary lives in the constants package (see constants/thinking.go for the relocation rationale); the CLI keeps the name consumers previously used.

func ListModels

func ListModels(ctx context.Context, modelRuntime *core.ModelRuntime, searchPattern string) error

ListModels prints the available models, optionally filtered by a fuzzy search pattern (pi: listModels).

func NormalizeSessionName

func NormalizeSessionName(value string) (string, bool)

NormalizeSessionName trims a session name; ok is false when the trimmed value is empty (pi: normalizeSessionName returns string | undefined).

func PrintAuthCommandHelp

func PrintAuthCommandHelp()

PrintAuthCommandHelp prints auth command usage (pi: printAuthCommandHelp).

func PrintHelp

func PrintHelp(extensionFlags []core.ExtensionFlag)

PrintHelp prints the CLI help text (pi: printHelp). pi colors the headings with chalk; pig drops the coloring (non-interactive text, same words).

func ResolveCredentialForPrint

func ResolveCredentialForPrint(ctx context.Context, args *Args, modelRuntime *core.ModelRuntime, kind credentialPrintKind, minExpiryMs *int64) (string, error)

ResolveCredentialForPrint resolves one configured provider credential.

This intentionally calls ModelRuntime.GetAuth, which refreshes and persists OAuth credentials with less than five minutes remaining through the normal request-auth path (pi: resolveCredentialForPrint).

func SelectSession

func SelectSession(currentSessionsLoader SessionsLoader, allSessionsLoader SessionsLoader,
	settingsManager *core.SettingsManager) (string, bool)

SelectSession shows the TUI session selector and returns the selected session path (ok=false if cancelled). The onExit callback exits the process like pi (ui.stop + process.exit(0) inside the component's exit handler).

func ShouldRunFirstTimeSetup

func ShouldRunFirstTimeSetup(settingsPath string) bool

ShouldRunFirstTimeSetup reports whether the first-time setup dialog should run. First-time setup runs when all of these hold:

  • this is the official Pi distribution (not a fork/rebrand)
  • experimental features are enabled (PI_EXPERIMENTAL=1)
  • the default agent directory is used (no custom agent dir override)
  • setup was not completed before (settings.json does not exist)

func ShowFirstTimeSetup

func ShowFirstTimeSetup(settingsManager *core.SettingsManager)

ShowFirstTimeSetup shows the first-time setup dialog and persists the result (pi: showFirstTimeSetup).

func ShowStartupInput

func ShowStartupInput(settingsManager *core.SettingsManager, title string, placeholder *string) *string

ShowStartupInput shows a blocking text prompt (pi: showStartupInput).

func ShowStartupSelector

func ShowStartupSelector(settingsManager *core.SettingsManager, title string, options []StartupOption) *string

ShowStartupSelector shows a blocking option list (pi: showStartupSelector).

func StartStartupTui

func StartStartupTui(ui *tui.TuiMainScreen, settingsManager *core.SettingsManager)

StartStartupTui starts the renderer and applies the detected auto theme (pi: startStartupTui).

Types

type ArgDiagnostic

type ArgDiagnostic struct {
	Type    string
	Message string
}

ArgDiagnostic is one CLI parse diagnostic (pi: Args.diagnostics members, `{ type: "warning" | "error"; message: string }`).

type Args

type Args struct {
	Provider           *string
	Model              *string
	APIKey             *string
	SystemPrompt       *string
	AppendSystemPrompt []string
	Thinking           *agent.ThinkingLevel
	Continue           *bool
	Resume             *bool
	Help               *bool
	Version            *bool
	Mode               *Mode
	Name               *string
	NoSession          *bool
	Session            *string
	SessionID          *string
	Fork               *string
	SessionDir         *string
	Models             []string
	Tools              []string
	ExcludeTools       []string
	NoTools            *bool
	NoBuiltinTools     *bool
	Extensions         []string
	NoExtensions       *bool
	Print              *bool
	Export             *string
	NoSkills           *bool
	Skills             []string
	PromptTemplates    []string
	NoPromptTemplates  *bool
	Themes             []string
	UseTheme           *string
	NoThemes           *bool
	NoContextFiles     *bool
	ListModels         any // pi: string | true — provider filter string, or true for all
	Offline            *bool
	// TuiMode selects the interactive renderer mode (pi: tuiMode?: TuiMode
	// from core/settings-manager). pi's import is type-only (erased at
	// runtime); Go has no type-only imports and core already imports cli for
	// the thinking-level vocabulary, so the field is a plain string —
	// core.TuiMode is a `= string` alias and values interoperate directly.
	TuiMode              *string
	Verbose              *bool
	ProjectTrustOverride *bool
	Messages             []string
	FileArgs             []string
	// UnknownFlags are unknown flags (potentially extension flags) - map of
	// flag name to value (pi: Map<string, boolean | string>). JS Maps keep
	// insertion order; the parallel UnknownFlagKeys slice carries it (pi's
	// validateAuthCommandArgs reports the first-inserted unknown flag).
	UnknownFlags    map[string]any
	UnknownFlagKeys []string
	Diagnostics     []ArgDiagnostic
}

Args is the parsed CLI invocation (pi: Args). Optional fields stay pointers: distinguishing "flag absent" from the zero value is part of the CLI semantics.

func ParseArgs

func ParseArgs(args []string) Args

ParseArgs parses CLI arguments (pi: parseArgs).

type AuthCheckReason

type AuthCheckReason = string

AuthCheckReason explains a non-ready check (pi: AuthCheckReason).

const (
	AuthCheckProviderNotFound         AuthCheckReason = "provider_not_found"
	AuthCheckCredentialsNotConfigured AuthCheckReason = "credentials_not_configured"
	AuthCheckCredentialNotAvailable   AuthCheckReason = "credential_not_available"
	AuthCheckInvalidState             AuthCheckReason = "invalid_state"
)

type AuthCheckResult

type AuthCheckResult struct {
	Status   AuthCheckStatus `json:"status"`
	Provider string          `json:"provider"`
	Reason   AuthCheckReason `json:"reason,omitempty"`
	// AuthType is "api_key" | "oauth"; "" = not provided (pi: authType?).
	AuthType auth.AuthType `json:"authType,omitempty"`
}

AuthCheckResult is the outcome of a provider auth check (pi: AuthCheckResult).

func CheckProviderAuth

func CheckProviderAuth(ctx context.Context, args *Args, modelRuntime *core.ModelRuntime, options *CheckProviderAuthOptions) (AuthCheckResult, error)

CheckProviderAuth checks whether a provider is ready for requests (pi: checkProviderAuth).

type AuthCheckStatus

type AuthCheckStatus = string

AuthCheckStatus is one of the auth check outcomes (pi: AuthCheckStatus).

const (
	AuthCheckReady    AuthCheckStatus = "ready"
	AuthCheckNotReady AuthCheckStatus = "not_ready"
	AuthCheckInvalid  AuthCheckStatus = "invalid"
)

type AuthCommand

type AuthCommand struct {
	Kind       AuthCommandKind
	Args       []string
	JSON       bool
	Credential bool
	NoRefresh  bool
	// MinExpiryMs is the --min-expiry duration; nil = not provided (pi:
	// minExpiryMs?: number).
	MinExpiryMs *int64
}

AuthCommand is a parsed auth subcommand (pi: AuthCommand).

func ParseAuthCommand

func ParseAuthCommand(args []string) (*AuthCommand, error)

ParseAuthCommand parses an auth subcommand; ok=false when args are not an auth command at all (pi: parseAuthCommand returns undefined). Errors are reported as *AuthCommandError.

type AuthCommandError

type AuthCommandError struct {
	Message string
}

AuthCommandError is an auth command parse/validation failure (pi: AuthCommandError).

func (*AuthCommandError) Error

func (e *AuthCommandError) Error() string

type AuthCommandKind

type AuthCommandKind = string

AuthCommandKind is one auth subcommand (pi: AuthCommandKind).

const (
	AuthCommandCheck       AuthCommandKind = "check"
	AuthCommandAPIKey      AuthCommandKind = "api_key"
	AuthCommandBearerToken AuthCommandKind = "bearer_token"
)

type AuthCommandTarget

type AuthCommandTarget struct {
	Provider string
	Model    string
}

AuthCommandTarget is validateAuthCommandArgs' resolved provider/model (pi: the inline `{ provider?: string; model?: string }`).

func ValidateAuthCommandArgs

func ValidateAuthCommandArgs(args *Args, kind AuthCommandKind) (AuthCommandTarget, error)

ValidateAuthCommandArgs validates auth command arguments (pi: validateAuthCommandArgs). Errors are *AuthCommandError.

type CheckProviderAuthOptions

type CheckProviderAuthOptions struct {
	Refresh bool
}

CheckProviderAuthOptions carries checkProviderAuth's option (pi: options).

type GetProviderCredentialOptions

type GetProviderCredentialOptions struct {
	Refresh bool
}

GetProviderCredentialOptions carries getProviderCredential's option (pi: options).

type InitialMessageInput

type InitialMessageInput struct {
	Parsed *Args
	// FileText is the @file text; "" = not provided (pi: fileText?: string,
	// consumed behind a truthy check so "" is indistinguishable from absent).
	FileText string
	// FileImages are the @file image attachments (pi: fileImages?:
	// ImageContent[]).
	FileImages []ai.ImageContent
	// StdinContent is the piped stdin; nil = not provided (pi: stdinContent?:
	// string, consumed behind an `!== undefined` check, so "" from an empty
	// pipe is meaningful and stays a pointer).
	StdinContent *string
}

InitialMessageInput carries the sources for the non-interactive initial prompt (pi: InitialMessageInput).

type InitialMessageResult

type InitialMessageResult struct {
	InitialMessage *string
	InitialImages  []ai.ImageContent
}

InitialMessageResult is the assembled initial prompt (pi: InitialMessageResult; optional members nil = undefined).

func BuildInitialMessage

func BuildInitialMessage(input InitialMessageInput) InitialMessageResult

BuildInitialMessage combines stdin content, @file text, and the first CLI message into a single initial prompt for non-interactive mode.

type Mode

type Mode = string

Mode selects the CLI output mode (pi: Mode = "text" | "json" | "rpc").

const (
	ModeText Mode = "text"
	ModeJSON Mode = "json"
	ModeRPC  Mode = "rpc"
)

type ProcessFileOptions

type ProcessFileOptions struct {
	// AutoResizeImages resizes images to 2000x2000 max. Default: true
	AutoResizeImages *bool
}

ProcessFileOptions carries the @file processing switches (pi: ProcessFileOptions).

type ProcessedFiles

type ProcessedFiles struct {
	Text   string
	Images []ai.ImageContent
}

ProcessedFiles is the combined text content and image attachments (pi: ProcessedFiles).

func ProcessFileArguments

func ProcessFileArguments(fileArgs []string, options *ProcessFileOptions) ProcessedFiles

ProcessFileArguments processes @file arguments into text content and image attachments.

type SessionsLoader

type SessionsLoader = func(onProgress func(loaded, total int)) []core.SessionInfo

SessionsLoader loads the session list (pi: SessionsLoader).

type StartupOption

type StartupOption struct {
	Label string
	Value string
}

StartupOption is one labeled selector entry (pi: the Array<{ label, value }> parameter).

Jump to

Keyboard shortcuts

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