feat: add support for file_opener option in Rust, similiar to #911

This commit is contained in:
Michael Bolin
2025-05-16 09:52:13 -07:00
parent 3d9f4fcd8a
commit baa92fc9c3
10 changed files with 215 additions and 14 deletions
+30 -1
View File
@@ -84,6 +84,10 @@ pub struct Config {
/// Settings that govern if and what will be written to `~/.codex/history.jsonl`.
pub history: History,
/// Optional URI-based file opener. If set, citations to files in the model
/// output will be hyperlinked using the specified URI scheme.
pub file_opener: Option<UriBasedFileOpener>,
}
/// Settings that govern if and what will be written to `~/.codex/history.jsonl`.
@@ -97,7 +101,7 @@ pub struct History {
pub max_bytes: Option<usize>,
}
#[derive(Deserialize, Debug, Clone, PartialEq, Default)]
#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Default)]
#[serde(rename_all = "kebab-case")]
pub enum HistoryPersistence {
/// Save all history entries to disk.
@@ -107,6 +111,21 @@ pub enum HistoryPersistence {
None,
}
#[derive(Deserialize, Debug, Copy, Clone, PartialEq)]
pub enum UriBasedFileOpener {
#[serde(rename = "vscode")]
VsCode,
#[serde(rename = "vscode-insiders")]
VsCodeInsiders,
#[serde(rename = "windsurf")]
Windsurf,
#[serde(rename = "cursor")]
Cursor,
}
/// Base config deserialized from ~/.codex/config.toml.
#[derive(Deserialize, Debug, Clone, Default)]
pub struct ConfigToml {
@@ -158,6 +177,10 @@ pub struct ConfigToml {
/// Settings that govern if and what will be written to `~/.codex/history.jsonl`.
#[serde(default)]
pub history: Option<History>,
/// Optional URI-based file opener. If set, citations to files in the model
/// output will be hyperlinked using the specified URI scheme.
pub file_opener: Option<UriBasedFileOpener>,
}
impl ConfigToml {
@@ -351,6 +374,9 @@ impl Config {
project_doc_max_bytes: cfg.project_doc_max_bytes.unwrap_or(PROJECT_DOC_MAX_BYTES),
codex_home,
history,
// TODO(mbolin): Check if user has VS Code installed before
// defaulting to it?
file_opener: cfg.file_opener.or(Some(UriBasedFileOpener::VsCode)),
};
Ok(config)
}
@@ -686,6 +712,7 @@ disable_response_storage = true
project_doc_max_bytes: PROJECT_DOC_MAX_BYTES,
codex_home: fixture.codex_home(),
history: History::default(),
file_opener: Some(UriBasedFileOpener::VsCode),
},
o3_profile_config
);
@@ -721,6 +748,7 @@ disable_response_storage = true
project_doc_max_bytes: PROJECT_DOC_MAX_BYTES,
codex_home: fixture.codex_home(),
history: History::default(),
file_opener: Some(UriBasedFileOpener::VsCode),
};
assert_eq!(expected_gpt3_profile_config, gpt3_profile_config);
@@ -771,6 +799,7 @@ disable_response_storage = true
project_doc_max_bytes: PROJECT_DOC_MAX_BYTES,
codex_home: fixture.codex_home(),
history: History::default(),
file_opener: Some(UriBasedFileOpener::VsCode),
};
assert_eq!(expected_zdr_profile_config, zdr_profile_config);