Documentation
¶
Overview ¶
Package config owns ChannelTerm's persisted connection configuration, connection policy, and user preferences.
Configuration is intentionally separate from transports and Sessions. The application layer translates a resolved connection profile into the concrete transport configuration it needs; user preferences never take part in that translation.
Index ¶
- Variables
- func DefaultHTTPAuthTokenPath() (string, error)
- func DefaultPath() (string, error)
- func DefaultStatePath() (string, error)
- func LoadOrCreateHTTPAuthToken(path string) (string, error)
- func RequireSerialPort(profile SerialProfile) error
- func Save(path string, file File) error
- func Update(path string, update func(*File) error) error
- type Connection
- type File
- type Preferences
- type Serial
- type SerialOverrides
- type SerialProfile
Constants ¶
This section is empty.
Variables ¶
var ( // ErrProfileNotFound is returned when a named serial profile does not exist. ErrProfileNotFound = errors.New("serial profile not found") // ErrSerialPortRequired is returned when the final serial settings have no port. ErrSerialPortRequired = errors.New("serial port is required") )
Functions ¶
func DefaultHTTPAuthTokenPath ¶
DefaultHTTPAuthTokenPath returns the per-user credential path used by the local Streamable HTTP Host and ChannelTerm's built-in HTTP clients.
func DefaultPath ¶
DefaultPath returns the platform's normal location for config.toml.
The path is based on os.UserConfigDir, which uses the appropriate Windows or Unix user configuration directory. It does not create files or directories.
func DefaultStatePath ¶
DefaultStatePath returns the platform's normal location for state.json.
State is kept beside the user configuration but has a separate lifecycle: it is maintained by ChannelTerm to retain discovered device identities and must never be treated as user connection configuration.
func LoadOrCreateHTTPAuthToken ¶
LoadOrCreateHTTPAuthToken returns a stable random bearer token from path. Creation is serialized across processes and installs only a complete 32-byte Base64URL credential. New files use owner-only permissions where the operating system honors them.
func RequireSerialPort ¶
func RequireSerialPort(profile SerialProfile) error
RequireSerialPort returns an error when profile does not name a serial port.
Types ¶
type Connection ¶
type Connection struct {
DefaultPolicy string `toml:"default_policy,omitempty"`
}
Connection contains global behavior for clients reacting to device discovery.
DefaultPolicy does not identify a device and never authorizes or prevents an explicit user-requested connection. It controls only the default reaction to a newly discovered endpoint.
type File ¶
type File struct {
Serial Serial `toml:"serial"`
Connection Connection `toml:"connection"`
Preferences Preferences `toml:"preferences,omitempty"`
}
File is the complete ChannelTerm configuration file.
Serial stores connection profiles, Connection stores discovery policy, and Preferences stores adapter-local user preferences. All three share one config.toml lifecycle, while their responsibilities remain independent.
Preferences is omitted from TOML until it contains persisted fields, so adding this boundary does not rewrite existing configuration into a new schema section.
func Load ¶
Load reads and decodes a TOML configuration file at path.
It begins with DefaultPreferences so fields added in future releases can default correctly when absent from an existing config.toml. It validates the connection discovery policy but leaves serial value validation to the serial opening boundary, preserving the existing resolution lifecycle.
func LoadOrCreate ¶
LoadOrCreate loads a TOML configuration file, creating the minimal template when it does not exist. Existing configuration files are read only.
The template intentionally contains no preferences section because the current Preferences model has no persisted fields.
func (File) ConnectionPolicy ¶
func (file File) ConnectionPolicy() (connectionpolicy.Policy, error)
ConnectionPolicy resolves the configured default discovery policy.
An omitted default_policy resolves to ask. Any non-empty unsupported value returns a clear validation error so callers never silently fall back to a different discovery behavior.
func (File) ResolveSerial ¶
func (file File) ResolveSerial(name string) (SerialProfile, error)
ResolveSerial selects a named profile, or the configured default when name is empty, and applies built-in serial defaults to omitted profile fields.
With neither a requested nor configured name, it returns only the built-in serial defaults. It reads only Serial and never consults Preferences.
func (*File) SaveSerialProfile ¶
func (file *File) SaveSerialProfile(name string, profile SerialProfile)
SaveSerialProfile stores a resolved serial profile under name.
It initializes the profile map when necessary and selects name as the default only when no default profile is configured. It preserves name exactly so established --save profile-key behavior remains unchanged. It changes only the connection-profile portion of File; callers persist the result with Save.
type Preferences ¶
type Preferences struct{}
Preferences contains user-owned presentation preferences.
It deliberately has no fields yet. Future terminal-display, UI, TUI, and GUI preferences belong here, are loaded and saved through File, and must not affect connection profile resolution or Transport construction. Its empty value is omitted from TOML, preserving existing config.toml output until a concrete preference is introduced.
func DefaultPreferences ¶
func DefaultPreferences() Preferences
DefaultPreferences returns the default user preferences.
The current model has no configurable values. Keeping a constructor makes defaults explicit at the configuration boundary: Load starts from this value before decoding TOML, so later defaulted fields can remain absent from older configuration files.
type Serial ¶
type Serial struct {
Default string `toml:"default,omitempty"`
Profiles map[string]SerialProfile `toml:"profiles,omitempty"`
}
Serial contains named serial connection profiles and an optional default.
It is connection configuration only. It does not contain presentation preferences or own a live serial Transport.
type SerialOverrides ¶
type SerialOverrides struct {
Port *string
BaudRate *int
DataBits *int
Parity *string
StopBits *string
FlowControl *string
Wake *bool
}
SerialOverrides represents serial values explicitly supplied by an adapter. Nil fields leave the resolved profile unchanged, preserving the distinction between an omitted CLI flag or MCP property and one set to its default value.
type SerialProfile ¶
type SerialProfile struct {
Port string `toml:"port,omitempty"`
BaudRate int `toml:"baud,omitempty"`
DataBits int `toml:"data_bits,omitempty"`
Parity string `toml:"parity,omitempty"`
StopBits string `toml:"stop_bits,omitempty"`
FlowControl string `toml:"flow_control,omitempty"`
Wake bool `toml:"wake"`
}
SerialProfile contains serial connection settings stored in a named profile.
Empty numeric and string fields inherit the built-in conventional settings when the profile is resolved. Wake is false unless explicitly enabled.
func ApplySerialOverrides ¶
func ApplySerialOverrides(profile SerialProfile, overrides SerialOverrides) SerialProfile
ApplySerialOverrides applies explicitly supplied adapter settings to profile.