Documentation
¶
Overview ¶
Package agent wires the provider, core, tools, auth, and modes into a CLI.
Index ¶
- func AuthPath() string
- func AuthStoreFor() *auth.Store
- func BuildSystemPrompt(o SystemPromptOpts) string
- func CheckForUpdateAsync(zotHome, currentVersion string) <-chan UpdateInfo
- func ConfigPath() string
- func FetchChangelogAsync(version string) <-chan ChangelogInfo
- func KimiCLIFallbackDisabledPath() string
- func LoadCachedModels()
- func LoadUserModels()
- func LogsPath() string
- func MarkChangelogShown(version string) error
- func ModelCachePath() string
- func PrintHelp(version string)
- func RefreshModelsAsync()
- func ResolveCredential(provider, explicit string) (cred, method string, err error)
- func ResolveCredentialFull(provider, explicit string) (cred, method, accountID string, err error)
- func Run(rawArgs []string, version string) error
- func SaveConfig(c Config) error
- func SeedChangelogVersion(version string)
- func SessionsPath() string
- func SetKimiCLIFallbackDisabled(disabled bool) error
- func ShouldShowChangelog(currentVersion string, cfg Config) bool
- func UserModelsPath() string
- func WriteNewTranscript(ag *core.Agent, sess *core.Session, from int)
- func ZotHome() string
- type Args
- type ChangelogInfo
- type Config
- type ExtensionToolInfo
- type ExtensionToolSource
- type Mode
- type Resolved
- type SystemPromptOpts
- type ToolSummary
- type UpdateInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthStoreFor ¶
AuthStoreFor returns the auth.Store backed by AuthPath().
func BuildSystemPrompt ¶
func BuildSystemPrompt(o SystemPromptOpts) string
BuildSystemPrompt constructs the system prompt.
Design note: kept intentionally small. Every byte here is part of the cached prefix on every request, so bloat is cumulatively expensive. We ship only:
- A one-paragraph identity (who zot is, what the name means, what the TUI expects for output format).
- The date + cwd footer so the model has current-context.
Everything else (tool listing, operating guidelines, "don't run sudo", "prefer edit over write", etc.) is left out because the current-generation frontier models already internalise it, and the tool schemas sent alongside the request carry each tool's own description.
Users who want extra biasing can use --system-prompt (replace), --append-system-prompt (additive, repeatable), or drop a SYSTEM.md in $ZOT_HOME that overrides the default identity.
func CheckForUpdateAsync ¶ added in v0.0.5
func CheckForUpdateAsync(zotHome, currentVersion string) <-chan UpdateInfo
CheckForUpdateAsync runs CheckForUpdate in a goroutine, delivers the result to the returned channel, and never blocks startup. The channel is always closed; receivers should `ok`-check.
func FetchChangelogAsync ¶ added in v0.0.33
func FetchChangelogAsync(version string) <-chan ChangelogInfo
FetchChangelogAsync runs FetchChangelog on a goroutine and delivers the result on the returned channel. Channel always closes.
func KimiCLIFallbackDisabledPath ¶ added in v0.1.52
func KimiCLIFallbackDisabledPath() string
KimiCLIFallbackDisabledPath returns a sentinel that disables falling back to the official Kimi Code CLI token after `zot /logout kimi`.
func LoadCachedModels ¶
func LoadCachedModels()
LoadCachedModels loads the cache file and applies it to the provider package so FindModel / ModelsForProvider see live ids immediately. Safe to call before any credentials are known.
func LoadUserModels ¶ added in v0.1.4
func LoadUserModels()
LoadUserModels reads $ZOT_HOME/models.json and merges any user-defined models into the active catalog. User models take highest precedence.
func MarkChangelogShown ¶ added in v0.0.33
MarkChangelogShown persists the version whose changelog the user just dismissed. Idempotent; safe to call when the dialog wasn't actually shown (e.g. fetch failed) so we don't keep retrying.
func ModelCachePath ¶
func ModelCachePath() string
ModelCachePath returns the on-disk location of the merged model cache.
func PrintHelp ¶
func PrintHelp(version string)
PrintHelp writes the help text to stderr. When stderr is a TTY it uses the same palette as zot's TUI; when redirected it falls back to plain text with no ANSI escapes.
func RefreshModelsAsync ¶
func RefreshModelsAsync()
RefreshModelsAsync kicks a background discovery for every provider we have credentials for. Refreshed results are merged into the active catalog and persisted to the on-disk cache.
Silent on error: discovery is a nice-to-have. Callers can still use the baked-in catalog if this fails.
func ResolveCredential ¶
ResolveCredential returns the credential (api key or oauth access token), the method ("apikey"/"oauth"), and an error when no credential is available.
Lookup order:
- explicit (e.g. --api-key): treated as API key
- provider-specific env var: treated as API key
- auth.json: api key OR oauth, whichever is present
func ResolveCredentialFull ¶
ResolveCredentialFull is like ResolveCredential but also returns a provider-specific accountID when the credential is an OpenAI OAuth token (the ChatGPT account id extracted from the stored id_token). accountID is "" for API-key auth and for anthropic.
func SaveConfig ¶
SaveConfig writes the config file, creating parent dirs.
func SeedChangelogVersion ¶ added in v0.0.33
func SeedChangelogVersion(version string)
SeedChangelogVersion sets LastChangelogShown if it's currently empty. Called once on first-ever launch so future upgrades correctly trigger the dialog while THIS launch (which is also "first-ever") doesn't.
func SessionsPath ¶
func SessionsPath() string
SessionsPath returns the directory holding session files.
func SetKimiCLIFallbackDisabled ¶ added in v0.1.52
func ShouldShowChangelog ¶ added in v0.0.33
ShouldShowChangelog reports whether the running binary version differs from the last version whose changelog the user dismissed. Returns false on dev builds (version "" / "dev" / "0.0.0") and on the first-ever launch (no LastChangelogShown stored — we don't dump release notes at someone who just installed).
func UserModelsPath ¶ added in v0.1.4
func UserModelsPath() string
UserModelsPath returns the path to the user's models.json override.
func WriteNewTranscript ¶
WriteNewTranscript appends only messages after index `from` from the agent's transcript to the session. Used by callers that don't hold the persistMu (non-interactive print/json modes which run a single turn under their own goroutine).
Types ¶
type Args ¶
type Args struct {
Mode Mode
Provider string
Model string
APIKey string
BaseURL string // override provider base URL (for tests/self-hosted)
SystemPrompt string
AppendSystemPrompt []string
Reasoning string
Continue bool
Resume bool
Session string
NoSess bool
CWD string
NoTools bool
Tools []string
MaxSteps int
// Exts is a list of directory paths the user passed via --ext.
// Each must contain an extension.json. Loaded for one session
// only; never persisted. Take precedence over installed exts of
// the same name.
Exts []string
// NoExt disables extension discovery + spawn entirely for this
// run. --ext PATH still works (explicit beats implicit) so you
// can run "with only this one extension" via --no-ext --ext PATH.
NoExt bool
// NoSkill disables ALL skill discovery for this run, including
// the built-in skills compiled into the binary. The system
// prompt loses its "Available skills" manifest and the `skill`
// tool isn't registered. Useful for running zot without any
// extra context biasing the model.
NoSkill bool
// WithSkills opts into loading user-installed skills from
// $ZOT_HOME/skills/, .zot/skills/, .claude/skills/, and
// .agents/skills/. Without this flag only the built-in skills
// shipped with the zot binary are available, so a fresh install
// has a deterministic skill set regardless of what's lying
// around in the user's home directory.
WithSkills bool
// NoYolo turns on per-tool confirmation. Before each tool
// invocation the TUI prompts the user with the tool name + args
// and waits for an explicit yes/no. The user can also pick
// "always for this tool this session" or "always for anything
// this session" to stop being prompted again. Defaults off
// (yolo mode): tools run without asking.
//
// No effect in -p / --json / rpc modes, which have no
// interactive prompt. A warning is printed to stderr on startup
// so scripts know the flag is ignored, but tools still run
// freely so automated workflows keep working.
NoYolo bool
ListModels bool
Help bool
Version bool
Prompt string // concatenated positional args
}
Args holds parsed command-line options.
type ChangelogInfo ¶ added in v0.0.33
ChangelogInfo is what FetchChangelog returns. Body is the markdown from the GitHub release page; URL points back to that page so the dialog can offer "open in browser".
func FetchChangelog ¶ added in v0.0.33
func FetchChangelog(ctx context.Context, version string) (ChangelogInfo, error)
type Config ¶
type Config struct {
Provider string `json:"provider"`
Model string `json:"model"`
Reasoning string `json:"reasoning"`
Theme string `json:"theme"`
// InlineImagesEnabled controls whether zot draws screenshots inline
// when the terminal supports an image protocol. nil/missing means
// auto (enabled when supported); false disables; true forces the
// detected protocol when available.
InlineImagesEnabled *bool `json:"inline_images_enabled,omitempty"`
// LastChangelogShown is the version whose release-notes
// dialog the user has already seen. When the running binary's
// version differs, the next interactive run shows the
// changelog (fetched from the GitHub release page) once and
// updates this field. Empty means "never shown".
LastChangelogShown string `json:"last_changelog_shown,omitempty"`
}
Config is the persisted user configuration.
func LoadConfig ¶
LoadConfig reads the config file, returning defaults if missing.
type ExtensionToolInfo ¶ added in v0.0.23
ExtensionToolInfo mirrors extensions.ToolInfo so we can declare ExtensionToolSource here without importing the extensions package. The cli wires a tiny adapter to bridge them.
type ExtensionToolSource ¶ added in v0.0.23
type ExtensionToolSource interface {
Tools() []ExtensionToolInfo
NewExtensionTool(info ExtensionToolInfo) core.Tool
}
ExtensionToolSource is the slice of the extension manager that MergeExtensionTools needs. Lives here as an interface so the build package doesn't import internal/agent/extensions (which imports core, which imports... avoid the cycle).
type Resolved ¶
type Resolved struct {
Provider string
Model string
Credential string // api key or oauth access token
AuthMethod string // "apikey" | "oauth" | "" (no credential yet)
AccountID string // ChatGPT account id (for openai oauth), "" otherwise
BaseURL string
CWD string
Reasoning string
ToolRegistry core.Registry
ToolSummary []ToolSummary
SystemPrompt string
MaxSteps int
Sandbox *tools.Sandbox
// SkillTool is the on-demand skill loader registered with the
// agent's tool registry, or nil if no SKILL.md files were
// discovered. Exposed so the tui can list / preview skills.
SkillTool *skills.Tool
// contains filtered or unexported fields
}
Resolved is the effective configuration after merging CLI, config, defaults.
func Resolve ¶
Resolve merges args, config, and env into a Resolved set.
Unlike the earlier version, Resolve NEVER returns an error for missing credentials: the TUI can start without them and launch a login flow. requireCred controls whether missing credentials are a hard error (used by print/json modes).
func (Resolved) HasCredential ¶
HasCredential reports whether a credential was resolved.
func (*Resolved) MergeExtensionTools ¶ added in v0.0.23
func (r *Resolved) MergeExtensionTools(mgr ExtensionToolSource)
MergeExtensionTools folds every tool registered by an extension into r's ToolRegistry and re-renders the system prompt's tool summary so the model sees both built-in and extension tools.
Idempotent: calling twice with the same manager state has no effect on the second pass (existing names are preserved). Built-in tools always win on conflict.
func (Resolved) NewClient ¶
NewClient returns a provider.Client for r, choosing the auth mode based on r.AuthMethod. Panics if no credential is present; callers must check HasCredential() first.
func (*Resolved) UseSandbox ¶
UseSandbox replaces the sandbox pointer that every tool in r's registry references. Used to keep the /jail state stable across agent rebuilds (e.g. /login, /model switching providers).
type SystemPromptOpts ¶
type SystemPromptOpts struct {
CWD string
Tools []ToolSummary
Custom string // if set, replaces the default identity entirely
Append []string // extra text appended at the end
Now time.Time
}
SystemPromptOpts configures BuildSystemPrompt.
type ToolSummary ¶
ToolSummary is a name+one-line description. Kept as part of the public opts type for backwards compatibility with callers that still pass tool summaries in; the default prompt no longer lists them because the provider already advertises tools in the request body's tools[] array, so listing them again in prose is pure duplication.
type UpdateInfo ¶ added in v0.0.5
type UpdateInfo struct {
Current string // e.g. "0.0.4"
Latest string // e.g. "0.0.5"
Available bool // true when latest > current
URL string // release page url for the changelog link
}
UpdateInfo describes the result of an update check. Zero-value means "no update available, no error, don't show anything".
func CheckForUpdate ¶ added in v0.0.5
func CheckForUpdate(ctx context.Context, zotHome, currentVersion string) UpdateInfo
CheckForUpdate returns info about a newer release, using a cached result when one is fresh enough. Designed to be called at tui startup and rendered as a dismissible banner.
Always returns a usable UpdateInfo (zero-value on error). The banner renderer skips the display when Available is false, so a network failure silently no-ops; we never block startup on this.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package extensions implements the host side of zot's subprocess extension protocol.
|
Package extensions implements the host side of zot's subprocess extension protocol. |
|
Package modes implements zot's three run modes: print, json, interactive.
|
Package modes implements zot's three run modes: print, json, interactive. |
|
telegram
Package telegram implements zot's Telegram bot bridge.
|
Package telegram implements zot's Telegram bot bridge. |
|
Package tools implements zot's built-in tools: read, write, edit, bash.
|
Package tools implements zot's built-in tools: read, write, edit, bash. |