Skip to main content

AppState

Struct AppState 

Source
pub struct AppState {
    pub global_config: Option<OpenCodeConfig>,
    pub project_config: Option<OpenCodeConfig>,
    pub custom_config: Option<OpenCodeConfig>,
    pub merged_config: OpenCodeConfig,
    pub paths: ConfigPaths,
    pub mode: AppMode,
    pub dirty: bool,
    pub edit_layer: ConfigLayer,
    /* private fields */
}
Expand description

The application state.

Fields§

§global_config: Option<OpenCodeConfig>

Loaded global config.

§project_config: Option<OpenCodeConfig>

Loaded project config.

§custom_config: Option<OpenCodeConfig>

Loaded custom config (from –config / OPENCODE_CONFIG).

§merged_config: OpenCodeConfig

Merged config (global + custom + project, per documented precedence).

§paths: ConfigPaths

Resolved config paths.

§mode: AppMode

Current UI state.

§dirty: bool

Whether any config layer has unsaved changes (OR of all dirty_* flags).

§edit_layer: ConfigLayer

Currently selected layer for edits.

Implementations§

Source§

impl AppState

Actions the user can perform on the app state.

Source

pub fn add_provider( &mut self, provider_id: String, config: ProviderConfig, layer: ConfigLayer, ) -> Result<()>

Add a new provider to the config at the specified layer.

Source

pub fn remove_provider( &mut self, provider_id: &str, layer: ConfigLayer, ) -> Result<()>

Remove a provider from the config at the specified layer.

Source

pub fn edit_provider_field( &mut self, provider_id: &str, field: &str, value: Value, layer: ConfigLayer, ) -> Result<()>

Edit a provider field in the config at the specified layer.

Source

pub fn add_model( &mut self, provider_id: &str, model_id: String, model_config: ModelConfig, layer: ConfigLayer, ) -> Result<()>

Add a model to a provider.

Source

pub fn remove_model( &mut self, provider_id: &str, model_id: &str, layer: ConfigLayer, ) -> Result<()>

Remove a model from a provider.

Source

pub fn copy_provider_to_global(&mut self, provider_id: &str) -> Result<()>

Copy a provider from the current edit_layer to the global config (merge if already present).

The incoming provider (from edit_layer) is treated as higher priority: its fields override the existing global entry for the same provider, but models that only exist in global are preserved. Only the Global layer is marked dirty — edit_layer’s dirty state is unchanged.

Source

pub fn save(&mut self, layer: ConfigLayer) -> Result<()>

Save the config at the specified layer to disk.

For the Project layer, falls back to ./opencode.json in the current directory when no project file was discovered, so that new project configs can be created.

Source

pub fn recompute_merged(&mut self)

Source§

impl AppState

Source

pub fn new() -> Result<Self>

Create a new app state by discovering config paths.

Source

pub fn load_configs(&mut self) -> Result<()>

Load all config layers and merge them.

Merge order follows the documented OpenCode precedence: global < custom (OPENCODE_CONFIG) < project.

Source

pub fn get_provider(&self, provider_id: &str) -> Option<&ProviderConfig>

Get a provider from the merged config.

Source

pub fn provider_ids(&self) -> Vec<String>

Get the list of configured provider IDs.

Source

pub fn mark_dirty(&mut self, layer: ConfigLayer)

Mark a specific config layer as having unsaved changes.

Source

pub fn mark_clean(&mut self, layer: ConfigLayer)

Mark a specific config layer as clean (saved). Recomputes the overall dirty flag.

Trait Implementations§

Source§

impl Debug for AppState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more