cli

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvModel                  = "YOTTACODE_MODEL"
	EnvBaseURL                = "YOTTACODE_BASE_URL"
	EnvAPIKey                 = "YOTTACODE_API_KEY"
	EnvAllowPaths             = "YOTTACODE_ALLOW_PATHS"
	EnvProvider               = "YOTTACODE_PROVIDER"
	EnvReasoningEffort        = "YOTTACODE_REASONING_EFFORT"
	EnvEnableWebSearch        = "YOTTACODE_ENABLE_WEB_SEARCH"
	EnvDisableWebSearch       = "YOTTACODE_DISABLE_WEB_SEARCH"
	EnvEnableXSearch          = "YOTTACODE_ENABLE_X_SEARCH"
	EnvEnableCodeInterpreter  = "YOTTACODE_ENABLE_CODE_INTERPRETER"
	EnvSearchAllowedDomains   = "YOTTACODE_SEARCH_ALLOWED_DOMAINS"
	EnvSearchExcludedDomains  = "YOTTACODE_SEARCH_EXCLUDED_DOMAINS"
	EnvXSearchAllowedHandles  = "YOTTACODE_X_SEARCH_ALLOWED_HANDLES"
	EnvXSearchExcludedHandles = "YOTTACODE_X_SEARCH_EXCLUDED_HANDLES"
	EnvXSearchFromDate        = "YOTTACODE_X_SEARCH_FROM_DATE"
	EnvXSearchToDate          = "YOTTACODE_X_SEARCH_TO_DATE"
	// EnvExperimental is a comma-separated list of experimental
	// feature names to enable (see internal/experimental). Merges
	// with --experimental flags and the [experimental] config
	// section. CLI > env > config; later sources don't disable
	// what earlier ones enabled.
	EnvExperimental = "YOTTACODE_EXPERIMENTAL"
)

Env var names that back the flags. Exported so tests and the TUI splash can reference them without hand-typing the strings.

View Source
const WorktreeAutoGenerate = "@auto@"

WorktreeAutoGenerate is the sentinel ChatOptions.Worktree takes when the user passes `--worktree` without a value. The CLI layer detects the sentinel before launch and replaces it with a freshly-generated name (e.g. "bright-running-fox"). Downstream code (tui.Run / oneshot.Run) never sees this sentinel — it's already resolved to a concrete name by then.

Variables

View Source
var ValidPermissionModes = []string{"", "default", "plan", "auto"}

ValidPermissionModes is the closed set the --permission-mode flag accepts. Exported so the flag-registration site and tests can keep the list in one place.

Functions

func BuildRouter

func BuildRouter(cfg config.Config, opts ChatOptions) (adapter.Client, error)

BuildRouter returns a multi-provider router as adapter.Client when cfg.Router.Enabled, otherwise returns (nil, nil) to signal "use the single-adapter dispatch path." Errors only on misconfiguration that Validate didn't catch (e.g., an env-backed API key is missing at runtime even though api_key_env was declared).

Each candidate's adapter is built via adapter.NewWithConfig with the same builtin-tool / search flags that the primary adapter would have received. Capability gating across heterogeneous providers is a Phase 2 concern; the first candidate's profile is the representative one returned by router.Profile().

func IsValidPermissionMode added in v0.2.0

func IsValidPermissionMode(s string) bool

IsValidPermissionMode reports whether s names a recognized startup permission mode. The empty string and "default" are both accepted (both mean "no startup mode") so users can omit the flag or pass it explicitly without an error.

func Resolve

func Resolve(opts *ChatOptions) error

Resolve fills empty fields from environment variables and configured provider profiles, then errors out when required config (model, base URL) is still missing.

Resolution order, lowest precedence first:

  1. Configured provider profile (from ~/.yottacode/config.toml)
  2. Generic env vars (YOTTACODE_MODEL / _BASE_URL / _API_KEY)
  3. CLI flags (already populated on opts when this is called)

Stated as fill-in-blanks: any field already set on opts wins; an empty field is filled from env, then from the matching profile.

Before reading any env, .env files at ~/.yottacode/.env and <cwd>/.yottacode/.env are loaded into the process environment (cwd wins, OS env always wins over both). This is how API keys reach Resolve without ever living in config.toml.

We deliberately do NOT bake in defaults like qwen3.5:latest or localhost:11434 — silently dialing localhost when the user forgot to set up Ollama is a worse failure mode than a clear "set --model or $YOTTACODE_MODEL" message.

Types

type ChatOptions

type ChatOptions struct {
	Model        string
	BaseURL      string
	APIKey       string
	SystemPrompt string
	Resume       string
	// Continue requests that, when set, the CLI resume the most recent
	// session in the current working directory (mirroring Claude
	// Code's --continue / -c flag). Mutually exclusive with Resume:
	// passing both is a user error and main.go errors out before
	// either path runs. The cwd lookup happens at command-dispatch
	// time, not in Resolve, because Resolve doesn't know cwd.
	Continue bool
	// Summarized requests that, when Resume is non-empty, the session
	// be loaded with its prior transcript replaced by a structured
	// summary (the same path /resume --summarized takes inside the
	// TUI). Defaults to false; only the `resume` subcommand sets it.
	Summarized bool
	// BypassPermissions is the internal name for what the user-facing
	// CLI exposes as --yolo: auto-approve every
	// tool call without prompting. DANGEROUS — model-emitted commands
	// run without a human in the loop. Explicit `deny` rules in
	// .yottacode/permissions.json are still honored, but every other
	// approval gate is skipped. Reserved for trusted CI / scripted
	// contexts; never enable in shared shells.
	BypassPermissions bool
	MaxIterations     int
	Provider          string
	// ProviderKind is the adapter kind (e.g. "copilot") resolved from
	// the config profile. May differ from Provider (the profile name,
	// e.g. "copilot-auth"). Set by applyProviderProfile; used by the
	// adapter ProviderOverride so routing works correctly.
	ProviderKind           string
	ReasoningEffort        string
	EnableWebSearch        bool
	DisableWebSearch       bool
	EnableXSearch          bool
	EnableCodeInterpreter  bool
	SearchAllowedDomains   string
	SearchExcludedDomains  string
	XSearchAllowedHandles  string
	XSearchExcludedHandles string
	XSearchFromDate        string
	XSearchToDate          string

	// AllowPaths is a comma-separated list of additional roots the
	// model's filesystem write tools are allowed to mutate, beyond the
	// session's cwd. Useful when legitimate work spans sibling repos
	// or shared dirs. Empty by default — writes confine to cwd.
	AllowPaths string

	// PermissionMode selects the startup permission mode, mirroring
	// Claude Code's --permission-mode flag. Valid values:
	//
	//   ""        — same as "default": no mode at startup.
	//   "default" — explicit form of the empty default.
	//   "plan"    — enter plan mode (read-only research; describe the
	//               task as your first message). Equivalent to typing
	//               /plan immediately after launch.
	//   "auto"    — enter auto mode (edits auto-allow; run_bash and
	//               git mutations still prompt). Reachable mid-session
	//               via Shift+Tab.
	//
	// No-op for oneshot (`yottacode run`) since the interactive modes
	// require an approval surface.
	PermissionMode string

	// PlanResume is a slug or substring matched against existing
	// plan files under ~/.yottacode/plans/. When set, the TUI
	// enters plan mode with the matched plan file attached so the
	// model picks up where it (or you) left off. Empty means "start
	// fresh"; an unmatched value falls back to fresh entry with a
	// log line so the user sees what happened. Implies
	// --permission-mode plan.
	PlanResume string

	// Worktree is the yottacode worktree name the session should be
	// launched inside (via the --worktree / -w flag). Empty for the
	// main checkout (default). The sentinel WorktreeAutoGenerate marks
	// "flag was passed without a value, auto-generate a name." Resolved
	// to a concrete name by ensureWorktree() before tui.Run / oneshot.Run
	// sees it; from those layers' perspective, an empty value means "no
	// worktree" and a non-empty value is always a concrete name.
	Worktree string

	// Experimental enables not-yet-stable features gated by the
	// internal/experimental package. The CLI flag is repeatable so
	// users can stack multiple opt-ins: `--experimental foo
	// --experimental bar`. Names also accept comma-separated lists
	// for symmetry with the $YOTTACODE_EXPERIMENTAL env var. The
	// config-file [experimental] section provides a third source;
	// they merge at startup. Unknown names land in the Set's
	// UnknownNames and surface as a startup warning rather than
	// fatal errors — so a typo or graduated feature doesn't lock
	// the user out.
	Experimental []string
}

ChatOptions carries the flags the root TUI and `run` subcommand share. Lives in this package because both internal/tui and internal/oneshot consume it.

type RouterAdapters added in v0.3.0

type RouterAdapters struct {
	Fast       adapter.Client
	Smart      adapter.Client
	FastModel  string
	SmartModel string
	// Resolve returns an adapter for an arbitrary configured model
	// name, or nil when the name matches no configured provider model
	// (the caller then inherits the parent/smart adapter). Adapters are
	// memoized so repeated dispatches of the same agent type reuse one
	// client.
	Resolve func(model string) adapter.Streamer
}

RouterAdapters bundles the resolved fast/smart adapters for cache-safe task routing, plus a resolver for an agent's explicit `model:` frontmatter override. These adapters drive only isolated contexts (subagents, summarization) — never the main-thread model mid-conversation — so swapping a task onto Fast never invalidates the parent's prompt cache.

func BuildRouterAdapters added in v0.3.0

func BuildRouterAdapters(cfg config.Config, opts ChatOptions) (*RouterAdapters, error)

BuildRouterAdapters resolves the [router].fast_model / smart_model pair and returns their adapters plus an on-demand resolver. Returns (nil, nil) when task routing is disabled (mode "off"/absent). Errors only on misconfiguration Validate didn't catch.

Jump to

Keyboard shortcuts

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