pub struct SettingsManager { /* private fields */ }Expand description
Settings manager: loads, migrates, merges, and persists global and trust-gated project settings.
Internally documents are raw JSON objects; merges and migrations operate at
the JSON level exactly like the TypeScript implementation. Writes are
performed synchronously inside setters; storage errors are recorded and
surfaced through Self::drain_errors. The only methods that return
errors are project writes while untrusted and the timeout getter/setter
validations.
Implementations§
Source§impl SettingsManager
impl SettingsManager
Sourcepub fn create(
cwd: impl AsRef<Path>,
agent_dir: Option<impl AsRef<Path>>,
options: SettingsManagerCreateOptions,
) -> Self
pub fn create( cwd: impl AsRef<Path>, agent_dir: Option<impl AsRef<Path>>, options: SettingsManagerCreateOptions, ) -> Self
Create a manager backed by settings files under agent_dir
(default: get_agent_dir) and {cwd}/.pi.
Sourcepub fn from_storage(
storage: Box<dyn SettingsStorage>,
options: SettingsManagerCreateOptions,
) -> Self
pub fn from_storage( storage: Box<dyn SettingsStorage>, options: SettingsManagerCreateOptions, ) -> Self
Create a manager from an arbitrary storage backend.
Sourcepub fn in_memory(
settings: &Settings,
options: SettingsManagerCreateOptions,
) -> Self
pub fn in_memory( settings: &Settings, options: SettingsManagerCreateOptions, ) -> Self
Create an in-memory manager (no file I/O) seeded with settings.
Sourcepub fn get_global_settings(&self) -> Settings
pub fn get_global_settings(&self) -> Settings
Typed view of the global settings document.
Sourcepub fn get_project_settings(&self) -> Settings
pub fn get_project_settings(&self) -> Settings
Typed view of the project settings document (empty while untrusted).
Sourcepub const fn is_project_trusted(&self) -> bool
pub const fn is_project_trusted(&self) -> bool
Whether the project is currently trusted.
Sourcepub fn set_project_trusted(&mut self, trusted: bool)
pub fn set_project_trusted(&mut self, trusted: bool)
Change project trust. false discards project data; true reloads it.
Sourcepub fn apply_overrides(&mut self, overrides: &Map<String, Value>)
pub fn apply_overrides(&mut self, overrides: &Map<String, Value>)
Apply additional overrides on top of the merged settings.
Overrides are not persisted and are discarded by the next save (TS parity).
Sourcepub fn flush(&self)
pub fn flush(&self)
Wait for any in-process write to finish.
Setters acquire the same mutex around persistence, so this blocks until
concurrent writers (if any) complete, matching TypeScript flush after
the write queue drains.
Sourcepub fn drain_errors(&mut self) -> Vec<SettingsError>
pub fn drain_errors(&mut self) -> Vec<SettingsError>
Take all recorded errors, leaving the error list empty.
Sourcepub fn get_last_changelog_version(&self) -> Option<String>
pub fn get_last_changelog_version(&self) -> Option<String>
lastChangelogVersion from merged settings.
Sourcepub fn set_last_changelog_version(&mut self, version: &str)
pub fn set_last_changelog_version(&mut self, version: &str)
Set lastChangelogVersion (global).
Sourcepub fn get_session_dir(&self) -> Option<String>
pub fn get_session_dir(&self) -> Option<String>
sessionDir with ~ expansion; empty string returned verbatim.
Sourcepub fn get_default_provider(&self) -> Option<String>
pub fn get_default_provider(&self) -> Option<String>
defaultProvider from merged settings.
Sourcepub fn get_default_model(&self) -> Option<String>
pub fn get_default_model(&self) -> Option<String>
defaultModel from merged settings.
Sourcepub fn set_default_provider(&mut self, provider: &str)
pub fn set_default_provider(&mut self, provider: &str)
Set defaultProvider (global).
Sourcepub fn set_default_model(&mut self, model_id: &str)
pub fn set_default_model(&mut self, model_id: &str)
Set defaultModel (global).
Sourcepub fn set_default_model_and_provider(&mut self, provider: &str, model_id: &str)
pub fn set_default_model_and_provider(&mut self, provider: &str, model_id: &str)
Set both defaultProvider and defaultModel with one save (global).
Sourcepub fn get_default_thinking_level(&self) -> Option<ModelThinkingLevel>
pub fn get_default_thinking_level(&self) -> Option<ModelThinkingLevel>
defaultThinkingLevel from merged settings.
Sourcepub fn set_default_thinking_level(&mut self, level: ModelThinkingLevel)
pub fn set_default_thinking_level(&mut self, level: ModelThinkingLevel)
Set defaultThinkingLevel (global).
Sourcepub fn get_enabled_models(&self) -> Option<Vec<String>>
pub fn get_enabled_models(&self) -> Option<Vec<String>>
enabledModels from merged settings.
Sourcepub fn set_enabled_models(&mut self, patterns: Option<Vec<String>>)
pub fn set_enabled_models(&mut self, patterns: Option<Vec<String>>)
Set enabledModels; None removes the key (global).
Sourcepub fn get_thinking_budgets(&self) -> Option<ThinkingBudgetsSettings>
pub fn get_thinking_budgets(&self) -> Option<ThinkingBudgetsSettings>
thinkingBudgets from merged settings.
Sourcepub fn get_steering_mode(&self) -> QueueMode
pub fn get_steering_mode(&self) -> QueueMode
Steering queue drain mode (default: one-at-a-time).
Sourcepub fn set_steering_mode(&mut self, mode: QueueMode)
pub fn set_steering_mode(&mut self, mode: QueueMode)
Set steeringMode (global).
Sourcepub fn get_follow_up_mode(&self) -> QueueMode
pub fn get_follow_up_mode(&self) -> QueueMode
Follow-up queue drain mode (default: one-at-a-time).
Sourcepub fn set_follow_up_mode(&mut self, mode: QueueMode)
pub fn set_follow_up_mode(&mut self, mode: QueueMode)
Set followUpMode (global).
Sourcepub fn get_transport(&self) -> Transport
pub fn get_transport(&self) -> Transport
Streaming transport preference (default: auto).
Sourcepub fn set_transport(&mut self, transport: Transport)
pub fn set_transport(&mut self, transport: Transport)
Set transport (global).
Sourcepub fn get_theme_setting(&self) -> Option<String>
pub fn get_theme_setting(&self) -> Option<String>
Raw theme setting when it is a string.
Sourcepub fn get_theme(&self) -> Option<String>
pub fn get_theme(&self) -> Option<String>
Theme name; None when unset or path-like (contains /).
Sourcepub fn get_theme_paths(&self) -> Vec<String>
pub fn get_theme_paths(&self) -> Vec<String>
themes resource paths from merged settings.
Sourcepub fn set_theme_paths(&mut self, paths: Vec<String>)
pub fn set_theme_paths(&mut self, paths: Vec<String>)
Set themes resource paths (global).
Sourcepub fn set_project_theme_paths(
&mut self,
paths: Vec<String>,
) -> Result<(), SettingsManagerError>
pub fn set_project_theme_paths( &mut self, paths: Vec<String>, ) -> Result<(), SettingsManagerError>
Set themes resource paths in the project file.
§Errors
Returns SettingsManagerError::ProjectNotTrusted when untrusted.
Sourcepub fn get_compaction_enabled(&self) -> bool
pub fn get_compaction_enabled(&self) -> bool
compaction.enabled (default: true).
Sourcepub fn set_compaction_enabled(&mut self, enabled: bool)
pub fn set_compaction_enabled(&mut self, enabled: bool)
Set compaction.enabled (global, nested merge).
Sourcepub fn get_compaction_reserve_tokens(&self) -> u64
pub fn get_compaction_reserve_tokens(&self) -> u64
compaction.reserveTokens (default: 16384).
Sourcepub fn get_compaction_keep_recent_tokens(&self) -> u64
pub fn get_compaction_keep_recent_tokens(&self) -> u64
compaction.keepRecentTokens (default: 20000).
Sourcepub fn get_compaction_settings(&self) -> ResolvedCompactionSettings
pub fn get_compaction_settings(&self) -> ResolvedCompactionSettings
Fully-resolved compaction settings.
Sourcepub fn get_branch_summary_settings(&self) -> ResolvedBranchSummarySettings
pub fn get_branch_summary_settings(&self) -> ResolvedBranchSummarySettings
Fully-resolved branch-summary settings.
Sourcepub fn get_branch_summary_skip_prompt(&self) -> bool
pub fn get_branch_summary_skip_prompt(&self) -> bool
branchSummary.skipPrompt (default: false).
Sourcepub fn get_retry_enabled(&self) -> bool
pub fn get_retry_enabled(&self) -> bool
retry.enabled (default: true).
Sourcepub fn set_retry_enabled(&mut self, enabled: bool)
pub fn set_retry_enabled(&mut self, enabled: bool)
Set retry.enabled (global, nested merge).
Sourcepub fn get_retry_settings(&self) -> ResolvedRetrySettings
pub fn get_retry_settings(&self) -> ResolvedRetrySettings
Fully-resolved automatic retry settings.
Sourcepub fn get_provider_retry_settings(&self) -> ResolvedProviderRetrySettings
pub fn get_provider_retry_settings(&self) -> ResolvedProviderRetrySettings
Fully-resolved provider retry settings (maxRetryDelayMs default 60000).
Sourcepub fn get_http_idle_timeout_ms(&self) -> Result<u64, SettingsManagerError>
pub fn get_http_idle_timeout_ms(&self) -> Result<u64, SettingsManagerError>
httpIdleTimeoutMs (default: 300000).
§Errors
Returns SettingsManagerError::InvalidSetting when a stored value is
present but not a usable timeout.
Sourcepub fn set_http_idle_timeout_ms(
&mut self,
timeout_ms: f64,
) -> Result<(), SettingsManagerError>
pub fn set_http_idle_timeout_ms( &mut self, timeout_ms: f64, ) -> Result<(), SettingsManagerError>
Set httpIdleTimeoutMs (global); the value is floored.
§Errors
Returns SettingsManagerError::InvalidSetting when non-finite or negative.
Sourcepub fn get_web_socket_connect_timeout_ms(
&self,
) -> Result<Option<u64>, SettingsManagerError>
pub fn get_web_socket_connect_timeout_ms( &self, ) -> Result<Option<u64>, SettingsManagerError>
websocketConnectTimeoutMs; None when unset.
§Errors
Returns SettingsManagerError::InvalidSetting when a stored value is
present but not a usable timeout.
Sourcepub fn get_hide_thinking_block(&self) -> bool
pub fn get_hide_thinking_block(&self) -> bool
hideThinkingBlock (default: false).
Sourcepub fn get_show_cache_miss_notices(&self) -> bool
pub fn get_show_cache_miss_notices(&self) -> bool
showCacheMissNotices (default: false).
Sourcepub fn get_external_editor_command(&self) -> String
pub fn get_external_editor_command(&self) -> String
External editor command: configured → VISUAL → EDITOR → notepad/nano.
Sourcepub fn set_hide_thinking_block(&mut self, hide: bool)
pub fn set_hide_thinking_block(&mut self, hide: bool)
Set hideThinkingBlock (global).
Sourcepub fn set_show_cache_miss_notices(&mut self, show: bool)
pub fn set_show_cache_miss_notices(&mut self, show: bool)
Set showCacheMissNotices (global).
Sourcepub fn get_quiet_startup(&self) -> bool
pub fn get_quiet_startup(&self) -> bool
quietStartup (default: false).
Sourcepub fn set_quiet_startup(&mut self, quiet: bool)
pub fn set_quiet_startup(&mut self, quiet: bool)
Set quietStartup (global).
Sourcepub fn get_double_escape_action(&self) -> DoubleEscapeAction
pub fn get_double_escape_action(&self) -> DoubleEscapeAction
doubleEscapeAction (default: tree).
Sourcepub fn set_double_escape_action(&mut self, action: DoubleEscapeAction)
pub fn set_double_escape_action(&mut self, action: DoubleEscapeAction)
Set doubleEscapeAction (global).
Sourcepub fn get_tree_filter_mode(&self) -> TreeFilterMode
pub fn get_tree_filter_mode(&self) -> TreeFilterMode
treeFilterMode; an unrecognized stored value yields default.
Sourcepub fn set_tree_filter_mode(&mut self, mode: TreeFilterMode)
pub fn set_tree_filter_mode(&mut self, mode: TreeFilterMode)
Set treeFilterMode (global).
Sourcepub fn get_show_hardware_cursor(&self) -> bool
pub fn get_show_hardware_cursor(&self) -> bool
showHardwareCursor; falls back to PI_HARDWARE_CURSOR === "1".
Sourcepub fn set_show_hardware_cursor(&mut self, enabled: bool)
pub fn set_show_hardware_cursor(&mut self, enabled: bool)
Set showHardwareCursor (global).
Sourcepub fn get_editor_padding_x(&self) -> u64
pub fn get_editor_padding_x(&self) -> u64
editorPaddingX (default: 0; the setter clamps to 0..=3).
Sourcepub fn set_editor_padding_x(&mut self, padding: f64)
pub fn set_editor_padding_x(&mut self, padding: f64)
Set editorPaddingX (global), clamped to 0..=3 after flooring.
Sourcepub fn get_output_pad(&self) -> OutputPad
pub fn get_output_pad(&self) -> OutputPad
outputPad; only an exact numeric 0 yields OutputPad::Zero.
Sourcepub fn set_output_pad(&mut self, padding: OutputPad)
pub fn set_output_pad(&mut self, padding: OutputPad)
Set outputPad (global).
Sourcepub fn get_autocomplete_max_visible(&self) -> u64
pub fn get_autocomplete_max_visible(&self) -> u64
autocompleteMaxVisible (default: 5; the setter clamps to 3..=20).
Sourcepub fn set_autocomplete_max_visible(&mut self, max_visible: f64)
pub fn set_autocomplete_max_visible(&mut self, max_visible: f64)
Set autocompleteMaxVisible (global), clamped to 3..=20 after flooring.
Sourcepub fn get_shell_path(&self) -> Option<String>
pub fn get_shell_path(&self) -> Option<String>
shellPath with ~ expansion; empty string returned verbatim.
Sourcepub fn set_shell_path(&mut self, path: Option<String>)
pub fn set_shell_path(&mut self, path: Option<String>)
Set shellPath; None removes the key (global).
Sourcepub fn get_shell_command_prefix(&self) -> Option<String>
pub fn get_shell_command_prefix(&self) -> Option<String>
shellCommandPrefix from merged settings.
Sourcepub fn set_shell_command_prefix(&mut self, prefix: Option<String>)
pub fn set_shell_command_prefix(&mut self, prefix: Option<String>)
Set shellCommandPrefix; None removes the key (global).
Sourcepub fn get_npm_command(&self) -> Option<Vec<String>>
pub fn get_npm_command(&self) -> Option<Vec<String>>
npmCommand argv from merged settings.
Sourcepub fn set_npm_command(&mut self, command: Option<Vec<String>>)
pub fn set_npm_command(&mut self, command: Option<Vec<String>>)
Set npmCommand; None removes the key (global).
Sourcepub fn get_default_project_trust(&self) -> DefaultProjectTrust
pub fn get_default_project_trust(&self) -> DefaultProjectTrust
defaultProjectTrust from the global settings only.
Sourcepub fn set_default_project_trust(
&mut self,
default_project_trust: DefaultProjectTrust,
)
pub fn set_default_project_trust( &mut self, default_project_trust: DefaultProjectTrust, )
Set defaultProjectTrust (global).
Sourcepub fn get_collapse_changelog(&self) -> bool
pub fn get_collapse_changelog(&self) -> bool
collapseChangelog (default: false).
Sourcepub fn set_collapse_changelog(&mut self, collapse: bool)
pub fn set_collapse_changelog(&mut self, collapse: bool)
Set collapseChangelog (global).
Sourcepub fn get_enable_install_telemetry(&self) -> bool
pub fn get_enable_install_telemetry(&self) -> bool
enableInstallTelemetry (default: true).
Sourcepub fn set_enable_install_telemetry(&mut self, enabled: bool)
pub fn set_enable_install_telemetry(&mut self, enabled: bool)
Set enableInstallTelemetry (global).
Sourcepub fn get_enable_analytics(&self) -> bool
pub fn get_enable_analytics(&self) -> bool
enableAnalytics (default: false).
Sourcepub fn get_tracking_id(&self) -> Option<String>
pub fn get_tracking_id(&self) -> Option<String>
trackingId from merged settings.
Sourcepub fn set_enable_analytics(&mut self, enabled: bool)
pub fn set_enable_analytics(&mut self, enabled: bool)
Set analytics opt-in; generates a UUIDv4 tracking id on first opt-in.
Sourcepub fn get_packages(&self) -> Vec<PackageSource>
pub fn get_packages(&self) -> Vec<PackageSource>
packages from merged settings.
Sourcepub fn set_packages(&mut self, packages: &[PackageSource])
pub fn set_packages(&mut self, packages: &[PackageSource])
Set packages (global).
Sourcepub fn set_project_packages(
&mut self,
packages: &[PackageSource],
) -> Result<(), SettingsManagerError>
pub fn set_project_packages( &mut self, packages: &[PackageSource], ) -> Result<(), SettingsManagerError>
Set packages in the project file.
§Errors
Returns SettingsManagerError::ProjectNotTrusted when untrusted.
Sourcepub fn get_extension_paths(&self) -> Vec<String>
pub fn get_extension_paths(&self) -> Vec<String>
extensions resource paths from merged settings.
Sourcepub fn set_extension_paths(&mut self, paths: Vec<String>)
pub fn set_extension_paths(&mut self, paths: Vec<String>)
Set extensions resource paths (global).
Sourcepub fn set_project_extension_paths(
&mut self,
paths: Vec<String>,
) -> Result<(), SettingsManagerError>
pub fn set_project_extension_paths( &mut self, paths: Vec<String>, ) -> Result<(), SettingsManagerError>
Set extensions resource paths in the project file.
§Errors
Returns SettingsManagerError::ProjectNotTrusted when untrusted.
Sourcepub fn get_skill_paths(&self) -> Vec<String>
pub fn get_skill_paths(&self) -> Vec<String>
skills resource paths from merged settings.
Sourcepub fn set_skill_paths(&mut self, paths: Vec<String>)
pub fn set_skill_paths(&mut self, paths: Vec<String>)
Set skills resource paths (global).
Sourcepub fn set_project_skill_paths(
&mut self,
paths: Vec<String>,
) -> Result<(), SettingsManagerError>
pub fn set_project_skill_paths( &mut self, paths: Vec<String>, ) -> Result<(), SettingsManagerError>
Set skills resource paths in the project file.
§Errors
Returns SettingsManagerError::ProjectNotTrusted when untrusted.
Sourcepub fn get_prompt_template_paths(&self) -> Vec<String>
pub fn get_prompt_template_paths(&self) -> Vec<String>
prompts resource paths from merged settings.
Sourcepub fn set_prompt_template_paths(&mut self, paths: Vec<String>)
pub fn set_prompt_template_paths(&mut self, paths: Vec<String>)
Set prompts resource paths (global).
Sourcepub fn set_project_prompt_template_paths(
&mut self,
paths: Vec<String>,
) -> Result<(), SettingsManagerError>
pub fn set_project_prompt_template_paths( &mut self, paths: Vec<String>, ) -> Result<(), SettingsManagerError>
Set prompts resource paths in the project file.
§Errors
Returns SettingsManagerError::ProjectNotTrusted when untrusted.
Sourcepub fn get_enable_skill_commands(&self) -> bool
pub fn get_enable_skill_commands(&self) -> bool
enableSkillCommands (default: true).
Sourcepub fn set_enable_skill_commands(&mut self, enabled: bool)
pub fn set_enable_skill_commands(&mut self, enabled: bool)
Set enableSkillCommands (global).
Sourcepub fn get_show_images(&self) -> bool
pub fn get_show_images(&self) -> bool
terminal.showImages (default: true).
Sourcepub fn set_show_images(&mut self, show: bool)
pub fn set_show_images(&mut self, show: bool)
Set terminal.showImages (global, nested merge).
Sourcepub fn get_image_width_cells(&self) -> u64
pub fn get_image_width_cells(&self) -> u64
terminal.imageWidthCells (default: 60; floored, min 1).
Sourcepub fn set_image_width_cells(&mut self, width: f64)
pub fn set_image_width_cells(&mut self, width: f64)
Set terminal.imageWidthCells (global, nested merge); floored, min 1.
Sourcepub fn get_clear_on_shrink(&self) -> bool
pub fn get_clear_on_shrink(&self) -> bool
terminal.clearOnShrink; falls back to PI_CLEAR_ON_SHRINK === "1".
Sourcepub fn set_clear_on_shrink(&mut self, enabled: bool)
pub fn set_clear_on_shrink(&mut self, enabled: bool)
Set terminal.clearOnShrink (global, nested merge).
Sourcepub fn get_show_terminal_progress(&self) -> bool
pub fn get_show_terminal_progress(&self) -> bool
terminal.showTerminalProgress (default: false).
Sourcepub fn set_show_terminal_progress(&mut self, enabled: bool)
pub fn set_show_terminal_progress(&mut self, enabled: bool)
Set terminal.showTerminalProgress (global, nested merge).
Sourcepub fn get_image_auto_resize(&self) -> bool
pub fn get_image_auto_resize(&self) -> bool
images.autoResize (default: true).
Sourcepub fn set_image_auto_resize(&mut self, enabled: bool)
pub fn set_image_auto_resize(&mut self, enabled: bool)
Set images.autoResize (global, nested merge).
Sourcepub fn get_block_images(&self) -> bool
pub fn get_block_images(&self) -> bool
images.blockImages (default: false).
Sourcepub fn set_block_images(&mut self, blocked: bool)
pub fn set_block_images(&mut self, blocked: bool)
Set images.blockImages (global, nested merge).
Sourcepub fn get_code_block_indent(&self) -> String
pub fn get_code_block_indent(&self) -> String
markdown.codeBlockIndent (default: two spaces).
Sourcepub fn get_warnings(&self) -> WarningSettings
pub fn get_warnings(&self) -> WarningSettings
warnings object (empty when absent).
Sourcepub fn set_warnings(&mut self, warnings: &WarningSettings)
pub fn set_warnings(&mut self, warnings: &WarningSettings)
Set warnings (global, full overlay).
Auto Trait Implementations§
impl !Freeze for SettingsManager
impl !RefUnwindSafe for SettingsManager
impl !UnwindSafe for SettingsManager
impl Send for SettingsManager
impl Sync for SettingsManager
impl Unpin for SettingsManager
impl UnsafeUnpin for SettingsManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more