setup

package
v0.7.33 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

TTYPrompter: the CLI's Prompter over stdin/stderr. Secrets are read with terminal echo disabled via stty against the controlling terminal — stdlib-only, unix-only, and honest when it cannot: the fallback prompts visibly and says so rather than silently echoing what the operator believed was hidden. The desktop app implements Prompter as a form and never comes through here.

Package setup implements the operator-experience flows: first-run machine setup with LLM-provider configuration, the guided MCP-profile setup that collects a QuickAgent's keys and identities, and the model catalog — one read of a provider's models listing with the operator's key, so a form can offer the models rather than ask for one to be typed, which is also the endpoint test the form gets for free (models.go). Everything works through the Prompter interface so the CLI (a TTY) and the desktop app (a form) drive the same logic — no parallel implementations; the provider table below is the one place that knows a provider's endpoints and how its key is sent.

Index

Constants

View Source
const AgentryModelName = "agentry"

AgentryModelName is the model name a provider-agentry policy records: the registry forwards every request to the model its staff chose, so the name the harness sends is only a label.

View Source
const AnthropicKeyCredits = "" /* 143-byte string literal not displayed */

AnthropicKeyCredits is what the API-key choice for Anthropic says: the plans whose included API credits a key spends.

View Source
const ClaudeSignInLabel = "Use your Claude subscription (runs Claude Code)"

ClaudeSignInLabel is the Claude choice's wording everywhere: plain text that runs use Claude Code, no logo, no "Sign in with Claude".

View Source
const ConnectLabel = "Connect your account"

ConnectLabel is the connect choice's wording.

View Source
const ContextProbeBudget = 30 * time.Second

ContextProbeBudget bounds the whole of a context-window probe, setup's or a run's.

View Source
const CopilotAuto = "auto"

CopilotAuto is the Copilot model that lets Copilot choose, the only one a Copilot Free plan has; it is always offered.

View Source
const CopilotSignInLabel = "Sign in with GitHub"

CopilotSignInLabel is the Copilot choice's wording.

Variables

This section is empty.

Functions

func ConfigureModel

func ConfigureModel(p Prompter, pol *policy.Policy, opts ModelOpts) error

ConfigureModel resolves the operator's LLM provider preference (req 5) into the policy's model block, prompting through p where opts leave gaps. Everything outside `model:` is untouched.

func GuidedProfile

func GuidedProfile(p Prompter, opts GuidedProfileOpts) (*profile.Profile, error)

GuidedProfile runs the guided conversation and returns the new profile. Empty secret answers are recorded as absent (resolve from the environment at run time), not as empty strings.

func IsConnectProvider

func IsConnectProvider(provider string) bool

IsConnectProvider reports whether provider's account can be connected.

func IsLoopbackHost

func IsLoopbackHost(host string) bool

IsLoopbackHost is true for localhost, a *.localhost name, and a loopback address: a server on the operator's own machine.

func PlainHTTPWarning

func PlainHTTPWarning(endpoint string) string

PlainHTTPWarning is the sentence a caller shows for a model endpoint the key would reach over plain http off this machine, and "" for https, for loopback http, and for anything that is not an http URL. It is the one wording the CLI's setup, doctor and the desktop share.

func Providers

func Providers() []string

Providers lists the selectable provider names (agentry, paid with Agentry credits, and copilot, paid by a Copilot plan alone, then custom last).

func UnknownWindowSentence added in v0.7.9

func UnknownWindowSentence(model string) string

UnknownWindowSentence says what an unset window costs a run on model.

Types

type Catalog

type Catalog struct {
	Provider string
	Models   []Model
	Warning  string
}

Catalog is what a provider's models endpoint listed, in the provider's own order. Warning, when set, is PlainHTTPWarning's sentence for the endpoint the key was sent to: the caller shows it beside the listing.

func ListModels

func ListModels(ctx context.Context, provider, baseURL, key string) (*Catalog, error)

ListModels asks provider's models endpoint with key and returns what it listed. baseURL is required for custom and ignored for the table providers. A scheme other than http or https is refused before a request is made; plain http off loopback, which only a custom endpoint can be, is the operator's choice and is carried out with the warning on the Catalog; no redirect is followed; the key is scrubbed from any error, the provider's own message included. An empty listing is an error: a form offering nothing is worse than one saying so.

type ChatGPTOffer

type ChatGPTOffer struct {
	// Kept is the account of a kept ChatGPT sign-in that still works, ""
	// when there is none.
	Kept func() string
	// SignIn signs in (fresh, or when none is kept) or refreshes the kept
	// sign-in, and returns its account and the models its plan offers.
	SignIn func(fresh bool) (account string, models []string, err error)
}

ChatGPTOffer is how setup reaches the ChatGPT sign-in, which the caller owns (the store, the browser, the network).

type ClaudeOffer

type ClaudeOffer struct {
	// Kept is the account of the Claude Code image's kept sign-in, ""
	// when there is none.
	Kept func() string
	// SignIn runs Claude Code's own sign-in and returns its account.
	SignIn func() (account string, err error)
}

ClaudeOffer is how setup reaches Claude Code's own sign-in, which the caller owns (the image, docker, the terminal).

type ConnectOffer

type ConnectOffer struct {
	// Kept is how a kept connect for provider is named ("Connected as …"),
	// "" when none is kept.
	Kept func(provider string) string
	// Connect connects the person's account in their browser, keeps the
	// key it minted in the OS keychain, and returns how the account is
	// named.
	Connect func(provider string) (account string, err error)
	// Forget forgets the connect kept for provider once a pasted key has
	// replaced its key in the keychain, and says what became of it (""
	// when none was kept).
	Forget func(provider string) (outcome string, err error)
}

ConnectOffer is how setup reaches a connect, which the caller owns (the browser, the network, the keychain). Each takes the policy's provider.

type ContextWindow added in v0.7.9

type ContextWindow struct {
	Tokens int64
	Source string
}

ContextWindow is a model's context window as an endpoint reported it: the tokens, and the URL that said so (scheme, host and path only). Tokens 0 is an endpoint that did not say.

func ProbeContextWindow added in v0.7.9

func ProbeContextWindow(ctx context.Context, baseURL, model, key string) (ContextWindow, error)

ProbeContextWindow asks an OpenAI-compatible endpoint how large model's context window is, in the shapes the common servers publish, and returns the first it finds:

  • the model's entry in <baseURL>/models: max_model_len (vLLM), loaded_context_length, context_length, max_context_length or context_window;
  • LM Studio's /api/v0/models/<model>: the loaded window, else the model's largest;
  • llama.cpp's /props: the window the server was started with;
  • Ollama's /api/ps (the running model's window), then /api/show's num_ctx parameter.

The server paths are read beside the base URL's /v1, on the same host. A training window (llama.cpp's n_ctx_train, Ollama's <arch>.context_length) is not read: a server runs with less, and a window larger than the one it enforces would hold compaction back past the point it refuses a request.

The requests follow ListModels' rules: http or https only, no redirect followed, the key (when there is one) sent as a bearer to the endpoint's host alone and scrubbed from any error. Only a base URL that cannot be asked is an error; an endpoint that answers none of the shapes is a zero ContextWindow.

type CopilotOffer

type CopilotOffer struct {
	// Kept is the account of a kept Copilot sign-in that still works, ""
	// when there is none.
	Kept func() string
	// SignIn signs in with GitHub and returns the account.
	SignIn func() (account string, err error)
	// Models lists the model ids the Copilot plan named offers the signed-in
	// account, asked of Copilot CLI, in its order; nil lists none. Setup asks
	// it only when it is about to ask for the model.
	Models func(plan string) ([]string, error)
}

CopilotOffer is how setup reaches the Copilot sign-in, which the caller owns (the store, the browser, the network).

type GuidedProfileOpts

type GuidedProfileOpts struct {
	Ref    string
	Digest string
	// CapabilityLines is the contract display (what the keys are FOR).
	CapabilityLines []string
	// Secrets are the manifest-declared env names to collect.
	Secrets []string
	// Optional are the ones a run may go without (the manifest's
	// optionalSecrets): asked the same way, and said so.
	Optional []string
	// DefaultKeep seeds the keep question (policy default or flag).
	DefaultKeep bool
	// KeepDecided suppresses the keep question (the flag already chose).
	KeepDecided bool
	// Help is the release guide's connect help per secret name:
	// where to create the key, which scopes it needs, in markdown that may
	// span lines. Printed as text before the question for that
	// key, beneath its name behind termtext's gutter when it spans lines.
	Help map[string]string
}

GuidedProfileOpts parameterizes the guided profile flow.

type Model

type Model struct {
	ID          string
	DisplayName string
	InputUSD    string
	OutputUSD   string
}

Model is one listed model: the id a policy names, the name a person reads where the provider gives one, and its price where the provider lists one, in US dollars a million tokens ("0.10"; "" where none is given).

type ModelOpts

type ModelOpts struct {
	Provider  string
	Model     string
	APIKeyEnv string
	// APIKeySource is "" (keep what the policy has for the same provider, else
	// env), "env" or "keyring": where the key comes from when the variable is
	// unset. Interactive setup offers to store the key in the keychain and sets
	// keyring itself.
	APIKeySource string
	// StoreKey puts a key into the OS keychain (nil: modelkey.Store). A
	// seam: tests have no keychain, and a form-driven caller stores the
	// key itself before calling.
	StoreKey func(provider, key string) error
	// APIKeyKind is what the credential is (policy apiKeyKind): "" (keep what
	// the policy has for the same provider, else api), "api" or "subscription".
	// A form-driven caller that stored the key itself passes
	// policy.CredentialKindOf's answer; an interactive setup derives it from
	// the key it stores; a variable-only setup takes --api-key-kind.
	APIKeyKind string
	BaseURL    string
	// ContextWindow is the model's context window in tokens (the policy's
	// model.contextWindow). 0 keeps what the policy has for the same model
	// at the same endpoint; for custom, what ProbeContextWindow finds is the
	// question's default and, under Yes, the answer.
	ContextWindow int64
	// ProbeContextWindow asks a custom endpoint for the model's window
	// (setup.ProbeContextWindow); nil asks nothing. A seam: tests do not
	// reach the endpoints they name.
	ProbeContextWindow func(ctx context.Context, baseURL, model, key string) (ContextWindow, error)
	// ChatGPT offers Sign in with ChatGPT for provider openai: nil offers none.
	// APIKeyKind chatgpt-plan asks for it without the question.
	ChatGPT ChatGPTOffer
	// Claude offers ClaudeSignInLabel for provider anthropic: nil offers none.
	// APIKeyKind claude-signin asks for it without the question.
	Claude ClaudeOffer
	// Copilot offers Sign in with GitHub for provider copilot, its one way
	// to pay.
	Copilot CopilotOffer
	// AgentryRegistry is the SecureAgentry registry this computer is signed
	// in to, which provider agentry pays through with the account's
	// credits; "" when it is signed in to none, and then that provider is
	// refused.
	AgentryRegistry string
	// Connect offers Connect your account for OpenRouter, Poe and Hugging Face:
	// nil offers none. ConnectAccount asks for it without the question.
	Connect        ConnectOffer
	ConnectAccount bool
	// CopilotPlan is the Copilot plan the account is on (policy.CopilotPlans:
	// individual, business, enterprise), which names the Copilot API host
	// runs reach; "" keeps the policy's, else asks, else individual.
	CopilotPlan string
	// Yes suppresses prompting entirely: table defaults fill the gaps, the
	// same provider's policy fills what it customized, and a custom
	// provider with no BaseURL left is an error rather than a question.
	Yes bool
}

ModelOpts carries non-interactive answers (flags / desktop form); empty fields are asked for or defaulted.

type Prompter

type Prompter interface {
	// Ask shows a prompt with a default and returns the answer ("" keeps
	// the default).
	Ask(prompt, def string) (string, error)
	// AskSecret reads a value without echoing it. An empty answer means
	// "leave unset" and is not an error.
	AskSecret(prompt string) (string, error)
	// Confirm asks a yes/no question with a default.
	Confirm(prompt string, def bool) (bool, error)
	// Say emits informational text.
	Say(text string)
}

Prompter is the interaction surface guided flows run through.

type ProviderDefault

type ProviderDefault struct {
	Provider   string
	Model      string
	APIKeyEnv  string
	ProxyAllow []string
	// ModelsURL is the provider's models listing; KeyHeader the header
	// its key rides in (keyHeaderBearer is "Authorization: Bearer").
	ModelsURL string
	KeyHeader string
}

ProviderDefault is one row of the provider table.

func DefaultsFor

func DefaultsFor(provider string) *ProviderDefault

DefaultsFor returns the table row for a provider (nil for custom or unknown).

type TTYPrompter

type TTYPrompter struct {
	In  io.Reader
	Err io.Writer
	// contains filtered or unexported fields
}

TTYPrompter prompts on Err (stderr, keeping stdout pipeline-clean) and reads answers from In.

func (*TTYPrompter) Ask

func (t *TTYPrompter) Ask(prompt, def string) (string, error)

Ask implements Prompter.

func (*TTYPrompter) AskSecret

func (t *TTYPrompter) AskSecret(prompt string) (string, error)

AskSecret implements Prompter with echo disabled where possible.

func (*TTYPrompter) Confirm

func (t *TTYPrompter) Confirm(prompt string, def bool) (bool, error)

Confirm implements Prompter.

func (*TTYPrompter) Say

func (t *TTYPrompter) Say(text string)

Say implements Prompter.

Jump to

Keyboard shortcuts

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