wizard

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package wizard implements the interactive setup wizard for Agent Layer.

TOML Parsing Strategy

This package uses custom line-based TOML parsing instead of the go-toml library's tree manipulation for config updates. This is intentional for several reasons:

  1. Comment preservation: go-toml's ToTomlString() loses inline comments and rearranges leading comments. Users expect their config formatting to be preserved.

  2. Deterministic output: The wizard rewrites config.toml in template-defined order (Decision f7a3c9d). Custom parsing lets us control exact output ordering.

  3. Key positioning: When clearing optional keys (like model=""), we convert them to commented lines rather than deleting them, preserving the template structure.

The go-toml library is still used for syntax validation before processing.

Index

Constants

View Source
const (
	AgentGemini       = "gemini"
	AgentClaude       = "claude"
	AgentClaudeVSCode = "claude-vscode"
	AgentCodex        = "codex"
	AgentVSCode       = "vscode"
	AgentAntigravity  = "antigravity"
)

AgentID constants matching config keys

View Source
const (
	ApprovalAll      = "all"
	ApprovalMCP      = "mcp"
	ApprovalCommands = "commands"
	ApprovalNone     = "none"
	ApprovalYOLO     = "yolo"
)

ApprovalMode constants

Variables

This section is empty.

Functions

func ApprovalModeFieldOptions added in v0.8.2

func ApprovalModeFieldOptions() []config.FieldOption

ApprovalModeFieldOptions returns approval mode options from the config field catalog. Panics if the approvals.mode field is not in the catalog (programming error).

func ClaudeModels

func ClaudeModels() []string

ClaudeModels returns supported Claude model values from the config field catalog.

func CleanupBackups added in v0.8.0

func CleanupBackups(root string) ([]string, error)

CleanupBackups removes wizard backup files and returns removed paths relative to repo root.

func CodexModels

func CodexModels() []string

CodexModels returns supported Codex model values from the config field catalog.

func CodexReasoningEfforts

func CodexReasoningEfforts() []string

CodexReasoningEfforts returns supported reasoning effort values from the config field catalog.

func GeminiModels

func GeminiModels() []string

GeminiModels returns supported Gemini model values from the config field catalog.

func IsTomlStateInMultiline

func IsTomlStateInMultiline(state tomlStringState) bool

IsTomlStateInMultiline returns true if the state indicates we're inside a multiline string.

func PatchConfig

func PatchConfig(content string, choices *Choices) (string, error)

PatchConfig applies wizard choices to TOML config content. content is the current config; choices holds selections; returns updated content or error.

func Run

func Run(root string, ui UI, runSync syncer, pinVersion string) error

Run starts the interactive wizard. pinVersion is written to .agent-layer/al.version when install is needed.

func RunProfile added in v0.8.0

func RunProfile(root string, runSync syncer, pinVersion string, profilePath string, apply bool, out io.Writer) error

RunProfile applies a non-interactive wizard profile from a TOML config file. root is the repo root; runSync executes sync after writes; pinVersion is used when install is required. profilePath points to a TOML file; apply controls whether writes are performed or preview-only output is shown.

func RunWithWriter added in v0.8.0

func RunWithWriter(root string, ui UI, runSync syncer, pinVersion string, out io.Writer) error

RunWithWriter starts the interactive wizard and writes user-facing output to out. pinVersion is written to .agent-layer/al.version when install is needed.

func ScanTomlLineForComment

func ScanTomlLineForComment(line string, state tomlStringState) (commentPos int, nextState tomlStringState)

ScanTomlLineForComment scans a TOML line and returns the position of any inline comment (or -1 if none) along with the next parser state for multiline string tracking. state is the current parser state from the previous line; line is the TOML line to scan.

func SupportedAgents

func SupportedAgents() []string

SupportedAgents returns the agent IDs the wizard can configure. Order matches the config field catalog registration order.

Types

type Choices

type Choices struct {
	// Approvals
	ApprovalMode        string
	ApprovalModeTouched bool

	// Agents
	EnabledAgents        map[string]bool
	EnabledAgentsTouched bool

	// Models
	GeminiModel        string
	GeminiModelTouched bool

	ClaudeModel        string
	ClaudeModelTouched bool

	CodexModel        string
	CodexModelTouched bool

	CodexReasoning        string
	CodexReasoningTouched bool

	// MCP
	EnabledMCPServers        map[string]bool
	EnabledMCPServersTouched bool
	DisabledMCPServers       map[string]bool
	MissingDefaultMCPServers []string
	RestoreMissingMCPServers bool
	DefaultMCPServers        []DefaultMCPServer

	// Secrets (Env vars)
	Secrets map[string]string

	// Warnings
	WarningsEnabled                bool
	WarningsEnabledTouched         bool
	InstructionTokenThreshold      int
	MCPServerThreshold             int
	MCPToolsTotalThreshold         int
	MCPServerToolsThreshold        int
	MCPSchemaTokensTotalThreshold  int
	MCPSchemaTokensServerThreshold int
}

Choices tracks user selections in the wizard.

func NewChoices

func NewChoices() *Choices

NewChoices returns a Choices struct initialized with defaults.

type DefaultMCPServer

type DefaultMCPServer struct {
	ID          string
	RequiredEnv []string
}

DefaultMCPServer describes a default MCP server and its required env vars.

type HuhUI

type HuhUI struct {
	// contains filtered or unexported fields
}

HuhUI implements UI using charmbracelet/huh.

func NewHuhUI

func NewHuhUI() *HuhUI

NewHuhUI creates a new HuhUI using the default terminal check. The default implementation uses terminal.IsInteractive().

func (*HuhUI) Confirm

func (ui *HuhUI) Confirm(title string, value *bool) error

Confirm renders a yes/no prompt.

func (*HuhUI) Input

func (ui *HuhUI) Input(title string, value *string) error

Input renders a plain text input prompt.

func (*HuhUI) MultiSelect

func (ui *HuhUI) MultiSelect(title string, options []string, selected *[]string) error

MultiSelect renders a multi-choice prompt.

func (*HuhUI) Note

func (ui *HuhUI) Note(title string, body string) error

Note renders an informational note screen.

func (*HuhUI) SecretInput

func (ui *HuhUI) SecretInput(title string, value *string) error

SecretInput renders a masked input prompt for secrets.

func (*HuhUI) Select

func (ui *HuhUI) Select(title string, options []string, current *string) error

Select renders a single-choice prompt.

type UI

type UI interface {
	Select(title string, options []string, current *string) error
	MultiSelect(title string, options []string, selected *[]string) error
	Confirm(title string, value *bool) error
	Input(title string, value *string) error
	SecretInput(title string, value *string) error
	Note(title string, body string) error
}

UI defines the interaction methods.

type WarningDefaults

type WarningDefaults struct {
	InstructionTokenThreshold      int
	MCPServerThreshold             int
	MCPToolsTotalThreshold         int
	MCPServerToolsThreshold        int
	MCPSchemaTokensTotalThreshold  int
	MCPSchemaTokensServerThreshold int
}

WarningDefaults holds wizard defaults sourced from the template config.

Jump to

Keyboard shortcuts

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