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.
process_cwd.go — pig-only helper for the process working directory (pi: `process.cwd()` in main.ts).
Deviation being fixed (S10-4 bidirectional-compat finding): bun/node's `process.cwd()` returns the kernel getcwd(3) result, which resolves symlinks (macOS: `cd /tmp/x` → "/private/tmp/x"). Go's os.Getwd() prefers $PWD when it matches ".", so it keeps the symlinked spelling ("/tmp/x"). The session directory name is encoded from the cwd, so the two spellings put pig and pi sessions in different directories and `--continue` never finds the other CLI's sessions. Resolving symlinks restores the shared directory name; on failure the raw value falls back like pi's canonicalizePath.
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
- func CreateAuthCheckModelRuntime(credentials auth.CredentialStore) *core.ModelRuntime
- func CreateStartupTui(settingsManager *core.SettingsManager) *tui.TuiMainScreen
- func GetAuthCommandName(kind AuthCommandKind) string
- func GetAuthCommandUsage(kind AuthCommandKind) string
- func GetAuthCredential(authResult *auth.AuthResult) string
- func GetProviderCredential(ctx context.Context, providerID string, modelRuntime *core.ModelRuntime, ...) (string, bool, error)
- func IsAuthCommandHelp(args []string) bool
- func IsValidThinkingLevel(level string) bool
- func ListModels(ctx context.Context, modelRuntime *core.ModelRuntime, searchPattern string) error
- func NormalizeSessionName(value string) (string, bool)
- func PrintAuthCommandHelp()
- func PrintHelp(extensionFlags []core.ExtensionFlag)
- func ProcessCwd() (string, error)
- func ResolveCredentialForPrint(ctx context.Context, args *Args, modelRuntime *core.ModelRuntime, ...) (string, error)
- func SelectSession(currentSessionsLoader SessionsLoader, allSessionsLoader SessionsLoader, ...) (string, bool)
- func ShouldRunFirstTimeSetup(settingsPath string) bool
- func ShowFirstTimeSetup(settingsManager *core.SettingsManager)
- func ShowStartupInput(settingsManager *core.SettingsManager, title string, placeholder *string) *string
- func ShowStartupSelector(settingsManager *core.SettingsManager, title string, options []StartupOption) *string
- func StartStartupTui(ui *tui.TuiMainScreen, settingsManager *core.SettingsManager)
- type ArgDiagnostic
- type Args
- type AuthCheckReason
- type AuthCheckResult
- type AuthCheckStatus
- type AuthCommand
- type AuthCommandError
- type AuthCommandKind
- type AuthCommandTarget
- type CheckProviderAuthOptions
- type GetProviderCredentialOptions
- type InitialMessageInput
- type InitialMessageResult
- type Mode
- type ProcessFileOptions
- type ProcessedFiles
- type SessionsLoader
- type StartupOption
Constants ¶
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 ¶
IsAuthCommandHelp reports whether the args invoke auth help (pi: isAuthCommandHelp).
func IsValidThinkingLevel ¶
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 ¶
ListModels prints the available models, optionally filtered by a fuzzy search pattern (pi: listModels).
func NormalizeSessionName ¶
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 ProcessCwd ¶ added in v1.0.0
ProcessCwd returns the working directory with symlinks resolved, matching bun's process.cwd() on darwin/linux. Windows keeps the raw os.Getwd value: its getcwd equivalent does not resolve junctions, and pi behaves the same.
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 ¶
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 queries the terminal colors, which re-resolve the theme (including the generated system theme) when they arrive (pi: startStartupTui).
Types ¶
type ArgDiagnostic ¶
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
NoMcp *bool
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.
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 ¶
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").
type ProcessFileOptions ¶
type ProcessFileOptions struct {
// AutoResizeImages resizes images to the inline provider limits.
// 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(ctx context.Context, onProgress core.SessionListProgress) []core.SessionInfo
SessionsLoader loads the session list (pi: SessionsLoader; v0.86.0 adds the signal parameter — pig threads the load's context).
type StartupOption ¶
StartupOption is one labeled selector entry (pi: the Array<{ label, value }> parameter).