Skip to content

Commit 70382ad

Browse files
matt2eclaude
andcommitted
feat: add Config::init_global(path) to support custom config directories
Add Config::init_global(config_dir) that initializes the global singleton with a caller-provided config directory instead of the default. This addresses PR feedback that Config::global() silently ignored the config_dir field from AcpServerFactoryConfig. The server factory now calls init_global(config_dir) so that if a non-default config directory is ever passed, the global Config will use the correct path while still providing the singleton mutex serialization benefit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 36d4ff2 commit 70382ad

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

crates/goose/src/acp/server_factory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl AcpServer {
2121
}
2222

2323
pub async fn create_agent(&self) -> Result<Arc<GooseAcpAgent>> {
24-
let config = crate::config::Config::global();
24+
let config = crate::config::Config::init_global(self.config.config_dir.clone());
2525

2626
let goose_mode = config
2727
.get_goose_mode()

crates/goose/src/config/base.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,38 @@ impl Config {
265265
GLOBAL_CONFIG.get_or_init(Config::default)
266266
}
267267

268+
/// Initialize the global configuration with a custom config directory.
269+
///
270+
/// If the global instance has already been initialized (e.g. by a prior call
271+
/// to `global()` or `init_global()`), this returns the existing instance and
272+
/// the provided path is ignored. This is safe because Goose runs one ACP
273+
/// server per process.
274+
pub fn init_global(config_dir: PathBuf) -> &'static Config {
275+
GLOBAL_CONFIG.get_or_init(|| {
276+
let config_path = config_dir.join(CONFIG_YAML_NAME);
277+
278+
let secrets =
279+
if env::var("GOOSE_DISABLE_KEYRING").is_ok()
280+
|| keyring_disabled_in_config(&config_path)
281+
{
282+
SecretStorage::File {
283+
path: config_dir.join("secrets.yaml"),
284+
}
285+
} else {
286+
SecretStorage::Keyring {
287+
service: KEYRING_SERVICE.to_string(),
288+
}
289+
};
290+
291+
Config {
292+
config_path,
293+
secrets,
294+
guard: Mutex::new(()),
295+
secrets_cache: Arc::new(Mutex::new(None)),
296+
}
297+
})
298+
}
299+
268300
/// Create a new configuration instance with custom paths
269301
///
270302
/// This is primarily useful for testing or for applications that need

0 commit comments

Comments
 (0)