config

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AIModeAct  = "act"
	AIModePlan = "plan"
)
View Source
const (
	AIProviderWebSearchModeDisabled      = "disabled"
	AIProviderWebSearchModeOpenAIBuiltin = "openai_builtin"
	AIProviderWebSearchModeBrave         = "brave"
)
View Source
const (
	DefaultLocalEnvironmentID = "local"
)

Variables

View Source
var ErrHomeDirUnavailable = errors.New("user home directory is unavailable")

Functions

func BootstrapConfig

func BootstrapConfig(ctx context.Context, args BootstrapArgs) (writtenPath string, err error)

func DefaultConfigPath

func DefaultConfigPath() (string, error)

func IsCuratedNativeAIProviderModel

func IsCuratedNativeAIProviderModel(providerType string, modelName string) bool

func ResolveStateRoot

func ResolveStateRoot(override string) (string, error)

func Save

func Save(path string, cfg *Config) error

func WriteEnvironmentCatalogRecord

func WriteEnvironmentCatalogRecord(layout StateLayout, cfg *Config, localUIBind string, passwordConfigured bool) error

Types

type AIConfig

type AIConfig struct {
	// Providers is the provider registry available to the runtime and UI.
	//
	// Notes:
	// - Providers own their allowed model list (provider + model are always configured together).
	Providers []AIProvider `json:"providers,omitempty"`

	// CurrentModelID points to the model used by default for new chats.
	//
	// Format: <provider_id>/<model_name>
	CurrentModelID string `json:"current_model_id"`

	// Mode controls the AI runtime behavior.
	//
	// Supported values:
	// - "act": full tool execution flow (default)
	// - "plan": planning-first mode with strict readonly execution (mutating actions are blocked)
	Mode string `json:"mode,omitempty"`

	// ToolRecoveryEnabled controls runtime-level recovery orchestration.
	//
	// When enabled, the Go runtime can continue attempts after recoverable tool failures
	// instead of ending the turn immediately.
	ToolRecoveryEnabled *bool `json:"tool_recovery_enabled,omitempty"`

	// ToolRecoveryMaxSteps limits how many recovery continuations can happen in one run.
	//
	// Defaults to 3.
	ToolRecoveryMaxSteps *int `json:"tool_recovery_max_steps,omitempty"`

	// ToolRecoveryAllowPathRewrite controls deterministic path normalization/rewrite strategies.
	ToolRecoveryAllowPathRewrite *bool `json:"tool_recovery_allow_path_rewrite,omitempty"`

	// ToolRecoveryAllowProbeTools is reserved for strategy diversification retries in runtime recovery.
	ToolRecoveryAllowProbeTools *bool `json:"tool_recovery_allow_probe_tools,omitempty"`

	// ToolRecoveryFailOnRepeatedSignature controls fail-fast behavior when the same failure signature
	// repeats across recovery attempts.
	ToolRecoveryFailOnRepeatedSignature *bool `json:"tool_recovery_fail_on_repeated_signature,omitempty"`

	// ExecutionPolicy controls runtime execution guardrails.
	//
	// Defaults are intentionally permissive:
	// - no user approval requirement
	// - no dangerous-command hard block
	ExecutionPolicy *AIExecutionPolicy `json:"execution_policy,omitempty"`

	// TerminalExecPolicy controls the bounded execution policy for terminal.exec.
	//
	// The built-in defaults intentionally mimic Claude-style shell behavior:
	// - default timeout: 2 minutes
	// - maximum timeout cap: 10 minutes
	TerminalExecPolicy *AITerminalExecPolicy `json:"terminal_exec_policy,omitempty"`
}

AIConfig configures the optional Flower (AI assistant) feature (Go Native runtime).

Notes:

  • Secrets (api keys) must never be stored in this config. Keys are managed via a separate local secrets file.
  • Field names are snake_case to match the rest of the runtime config surface.

func (*AIConfig) EffectiveBlockDangerousCommands

func (c *AIConfig) EffectiveBlockDangerousCommands() bool

func (*AIConfig) EffectiveMode

func (c *AIConfig) EffectiveMode() string

func (*AIConfig) EffectiveRequireUserApproval

func (c *AIConfig) EffectiveRequireUserApproval() bool

func (*AIConfig) EffectiveTerminalExecDefaultTimeoutMS

func (c *AIConfig) EffectiveTerminalExecDefaultTimeoutMS() int64

func (*AIConfig) EffectiveTerminalExecMaxTimeoutMS

func (c *AIConfig) EffectiveTerminalExecMaxTimeoutMS() int64

func (*AIConfig) EffectiveToolRecoveryAllowPathRewrite

func (c *AIConfig) EffectiveToolRecoveryAllowPathRewrite() bool

func (*AIConfig) EffectiveToolRecoveryAllowProbeTools

func (c *AIConfig) EffectiveToolRecoveryAllowProbeTools() bool

func (*AIConfig) EffectiveToolRecoveryEnabled

func (c *AIConfig) EffectiveToolRecoveryEnabled() bool

func (*AIConfig) EffectiveToolRecoveryFailOnRepeatedSignature

func (c *AIConfig) EffectiveToolRecoveryFailOnRepeatedSignature() bool

func (*AIConfig) EffectiveToolRecoveryMaxSteps

func (c *AIConfig) EffectiveToolRecoveryMaxSteps() int

func (*AIConfig) FirstModelID

func (c *AIConfig) FirstModelID() (string, bool)

FirstModelID returns the first available model wire id (<provider_id>/<model_name>) from providers[].models[] order.

func (*AIConfig) IsAllowedModelID

func (c *AIConfig) IsAllowedModelID(modelID string) bool

IsAllowedModelID reports whether the given model wire id (<provider_id>/<model_name>) exists in the config allow-list.

func (*AIConfig) NormalizeCurrentModelID

func (c *AIConfig) NormalizeCurrentModelID() bool

NormalizeCurrentModelID rewrites current_model_id to a valid value.

It returns true when a valid model exists and current_model_id was set.

func (*AIConfig) ResolvedCurrentModelID

func (c *AIConfig) ResolvedCurrentModelID() (string, bool)

ResolvedCurrentModelID returns the current model when valid; otherwise it falls back to the first available model.

func (*AIConfig) Validate

func (c *AIConfig) Validate() error

type AIExecutionPolicy

type AIExecutionPolicy struct {
	// RequireUserApproval controls whether mutating tool invocations require user approval.
	RequireUserApproval bool `json:"require_user_approval"`

	// BlockDangerousCommands controls whether dangerous terminal commands are hard-blocked.
	BlockDangerousCommands bool `json:"block_dangerous_commands"`
}

type AIProvider

type AIProvider struct {
	// ID is a stable internal id (primary key). It must not change once used for secrets/model routing.
	ID string `json:"id"`

	// Name is a human-friendly display name (safe to rename at any time).
	Name string `json:"name,omitempty"`

	// Type is one of:
	// - "openai"
	// - "anthropic"
	// - "moonshot"
	// - "chatglm"
	// - "deepseek"
	// - "qwen"
	// - "openai_compatible"
	Type string `json:"type"`

	// BaseURL overrides the provider endpoint (example: "https://api.openai.com/v1").
	// When empty, provider defaults apply.
	//
	// Required provider types:
	// - moonshot
	// - chatglm
	// - deepseek
	// - qwen
	// - openai_compatible
	BaseURL string `json:"base_url,omitempty"`

	// StrictToolSchema overrides provider tool schema strictness.
	//
	// When unset, runtime falls back to built-in policy:
	// - openai official endpoints: strict
	// - openai custom gateways: non-strict
	// - openai_compatible: non-strict
	// - moonshot/chatglm/deepseek/qwen: non-strict
	StrictToolSchema *bool `json:"strict_tool_schema,omitempty"`

	// WebSearch configures optional web search behavior for generic OpenAI-compatible providers.
	//
	// Native providers (OpenAI, Moonshot, ChatGLM/GLM, DeepSeek, and Qwen) derive their web-search
	// behavior from the provider type and explicit model allow-list, so this field is ignored for them.
	WebSearch *AIProviderWebSearch `json:"web_search,omitempty"`

	// Models is the allowed model list for this provider (shown in the Chat UI).
	Models []AIProviderModel `json:"models,omitempty"`
}

type AIProviderModel

type AIProviderModel struct {
	ModelName                     string `json:"model_name"`
	ContextWindow                 int    `json:"context_window,omitempty"`
	MaxOutputTokens               int    `json:"max_output_tokens,omitempty"`
	EffectiveContextWindowPercent int    `json:"effective_context_window_percent,omitempty"`
}

func (AIProviderModel) EffectiveContextWindowPercentValue

func (m AIProviderModel) EffectiveContextWindowPercentValue() int

func (AIProviderModel) EffectiveInputWindowTokens

func (m AIProviderModel) EffectiveInputWindowTokens() int

type AIProviderWebSearch

type AIProviderWebSearch struct {
	// Mode is only honored for openai_compatible providers.
	//
	// Supported values:
	// - "disabled": do not expose any web-search capability
	// - "openai_builtin": attach OpenAI Responses-style hosted web search
	// - "brave": expose Flower's external Brave-backed web.search tool
	Mode string `json:"mode,omitempty"`
}

type AITerminalExecPolicy

type AITerminalExecPolicy struct {
	// DefaultTimeoutMS is the timeout applied when terminal.exec does not specify timeout_ms.
	DefaultTimeoutMS *int `json:"default_timeout_ms,omitempty"`

	// MaxTimeoutMS is the hard upper cap for any terminal.exec timeout_ms request.
	MaxTimeoutMS *int `json:"max_timeout_ms,omitempty"`
}

type BootstrapArgs

type BootstrapArgs struct {
	ControlplaneBaseURL    string
	ControlplaneProviderID string
	EnvironmentID          string
	BootstrapTicket        string
	RuntimeVersion         string

	StateRoot string

	AgentHomeDir string
	Shell        string
	LogFormat    string
	LogLevel     string

	// PermissionPolicyPreset is an optional preset used to write permission_policy into the config.
	// If empty, bootstrap preserves the existing permission_policy when possible, otherwise uses defaults.
	PermissionPolicyPreset string
}

type Config

type Config struct {
	ControlplaneBaseURL      string                      `json:"controlplane_base_url"`
	ControlplaneProviderID   string                      `json:"controlplane_provider_id,omitempty"`
	EnvironmentID            string                      `json:"environment_id"`
	LocalEnvironmentPublicID string                      `json:"local_environment_public_id"`
	BindingGeneration        int64                       `json:"binding_generation,omitempty"`
	AgentInstanceID          string                      `json:"agent_instance_id"`
	Direct                   *directv1.DirectConnectInfo `json:"direct"`

	// AI config controls optional native AI assistant features.
	AI *AIConfig `json:"ai,omitempty"`

	// PermissionPolicy is the local permission cap applied on the endpoint.
	// It is designed to limit the effective permissions even if the control-plane grants more.
	PermissionPolicy *PermissionPolicy `json:"permission_policy,omitempty"`

	// AgentHomeDir is the configured filesystem scope for user-facing features.
	// If empty, the runtime picks a safe default (the current user home dir).
	AgentHomeDir string `json:"agent_home_dir,omitempty"`

	// Shell is the shell command used for terminal sessions.
	// If empty, the runtime picks a default (SHELL or /bin/bash).
	Shell string `json:"shell,omitempty"`

	// LogFormat is "json" or "text".
	LogFormat string `json:"log_format,omitempty"`
	// LogLevel is "debug|info|warn|error".
	LogLevel string `json:"log_level,omitempty"`

	// CodeServerPortMin/Max configures the dynamic port range used for code-server processes.
	// If unset/invalid, the runtime uses a safe default range.
	CodeServerPortMin int `json:"code_server_port_min,omitempty"`
	CodeServerPortMax int `json:"code_server_port_max,omitempty"`
}

Config is the on-disk configuration for the Redeven runtime.

NOTE: This file contains secrets (PSK). Always keep it chmod 0600.

func Load

func Load(path string) (*Config, error)

func (*Config) ValidateLocalMinimal

func (c *Config) ValidateLocalMinimal() error

ValidateLocalMinimal validates config fields required to start the runtime in local-only mode.

Local-only mode is enabled by `redeven run --mode local` and must work even when the controlplane credentials are missing (no bootstrap yet).

func (*Config) ValidateRemoteStrict

func (c *Config) ValidateRemoteStrict() error

ValidateRemoteStrict validates the fields required to connect to the remote control channel.

This is the standard mode requirements: the runtime must be fully bootstrapped.

type LocalEnvironmentBinding

type LocalEnvironmentBinding struct {
	LocalEnvironmentPublicID string `json:"local_environment_public_id"`
	UserPublicID             string `json:"user_public_id,omitempty"`
	EnvPublicID              string `json:"env_public_id"`
	Generation               int64  `json:"generation"`
	Hostname                 string `json:"hostname,omitempty"`
	OS                       string `json:"os,omitempty"`
	Arch                     string `json:"arch,omitempty"`
	RuntimeVersion           string `json:"runtime_version,omitempty"`
	LastSeenAtUnixMS         int64  `json:"last_seen_at_unix_ms,omitempty"`
}

type PermissionPolicy

type PermissionPolicy struct {
	SchemaVersion int `json:"schema_version"`

	// LocalMax is the global cap. It must be present for schema_version=1.
	LocalMax *PermissionSet `json:"local_max"`

	// ByUser and ByApp are optional additional caps. They can only further reduce LocalMax.
	ByUser map[string]*PermissionSet `json:"by_user,omitempty"`
	ByApp  map[string]*PermissionSet `json:"by_app,omitempty"`
}

PermissionPolicy is the local permission cap configuration stored on the runtime endpoint.

It is used to clamp control-plane granted permissions ("session_meta") to a user-approved maximum.

func ParsePermissionPolicyPreset

func ParsePermissionPolicyPreset(preset string) (*PermissionPolicy, error)

func (*PermissionPolicy) ResolveCap

func (p *PermissionPolicy) ResolveCap(userPublicID string, floeApp string) PermissionSet

ResolveCap returns the local cap to apply for the given user/app pair.

The resolution model is: - start from LocalMax - intersect with by_user[user_public_id] if present - intersect with by_app[floe_app] if present

func (*PermissionPolicy) Validate

func (p *PermissionPolicy) Validate() error

type PermissionSet

type PermissionSet struct {
	Read    bool `json:"read"`
	Write   bool `json:"write"`
	Execute bool `json:"execute"`
}

PermissionSet is the 3-bit permission model used by Redeven runtimes.

func ResolvePermissionCapFromConfigPath

func ResolvePermissionCapFromConfigPath(
	configPath string,
	userPublicID string,
	floeApp string,
	fallback PermissionSet,
) PermissionSet

ResolvePermissionCapFromConfigPath loads configPath and resolves the effective local cap for the given user/app pair. When the config cannot be loaded, it falls back to fallback.

func (PermissionSet) Intersect

func (p PermissionSet) Intersect(other PermissionSet) PermissionSet

type StateLayout

type StateLayout struct {
	StateRoot        string
	ConfigPath       string
	SecretsPath      string
	LockPath         string
	StateDir         string
	RuntimeStatePath string
	DiagnosticsDir   string
	AuditDir         string
	AppsDir          string
	GatewayDir       string
}

func DefaultStateLayout

func DefaultStateLayout() (StateLayout, error)

DefaultStateLayout returns the single Local Environment layout rooted under the resolved state root.

func LocalEnvironmentStateLayout

func LocalEnvironmentStateLayout(stateRoot string) (StateLayout, error)

Jump to

Keyboard shortcuts

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