-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[codex] Load user instructions through an injected provider #27101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,358
−557
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
86c3be8
add user instructions provider extension
anp-oai 6058bbf
codex: fix CI failure on PR #27101
anp-oai db55f39
codex: fix argument comment lint
anp-oai c75787f
codex: address user instructions review feedback
anp-oai ae76664
codex: simplify project instruction loading
anp-oai 9d05624
codex: address instruction loading review
anp-oai 5ab337b
codex: clarify instruction inheritance lookup
anp-oai 991be42
codex: address PR review feedback (#27101)
anp-oai 56e0175
codex: refresh user instructions branch
anp-oai 802d4ca
codex: restore mainline Bazel lockfile
anp-oai 1ce912e
codex: colocate user instruction integration test
anp-oai 02f04f2
codex: cover global instruction warnings in exec
anp-oai 493e005
codex: fix provider tests after restack
anp-oai 8aca78f
codex: fix CI failure on PR #27101
anp-oai 922a7f2
codex: make warning source assertion Windows-safe
anp-oai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| load("//:defs.bzl", "codex_rust_crate") | ||
|
|
||
| codex_rust_crate( | ||
| name = "codex-home", | ||
| crate_name = "codex_home", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| [package] | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| name = "codex-home" | ||
| version.workspace = true | ||
|
|
||
| [lib] | ||
| doctest = false | ||
|
|
||
| [lints] | ||
| workspace = true | ||
|
|
||
| [dependencies] | ||
| codex-extension-api = { workspace = true } | ||
| codex-utils-absolute-path = { workspace = true } | ||
| tokio = { workspace = true, features = ["fs"] } | ||
|
|
||
| [dev-dependencies] | ||
| pretty_assertions = { workspace = true } | ||
| tempfile = { workspace = true } | ||
| tokio = { workspace = true, features = ["macros", "rt"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| use std::io; | ||
|
|
||
| use codex_extension_api::LoadUserInstructionsFuture; | ||
| use codex_extension_api::LoadedUserInstructions; | ||
| use codex_extension_api::UserInstructions; | ||
| use codex_extension_api::UserInstructionsProvider; | ||
| use codex_utils_absolute_path::AbsolutePathBuf; | ||
|
|
||
| const DEFAULT_AGENTS_MD_FILENAME: &str = "AGENTS.md"; | ||
| const LOCAL_AGENTS_MD_FILENAME: &str = "AGENTS.override.md"; | ||
|
|
||
| /// Loads user instructions from a Codex home directory. | ||
| #[derive(Clone, Debug)] | ||
| pub struct CodexHomeUserInstructionsProvider { | ||
| codex_home: AbsolutePathBuf, | ||
| } | ||
|
|
||
| impl CodexHomeUserInstructionsProvider { | ||
| /// Creates a provider rooted at the supplied absolute Codex home directory. | ||
| pub fn new(codex_home: AbsolutePathBuf) -> Self { | ||
| Self { codex_home } | ||
| } | ||
|
|
||
| async fn load_from_codex_home(&self) -> LoadedUserInstructions { | ||
| let mut warnings = Vec::new(); | ||
| for candidate in [LOCAL_AGENTS_MD_FILENAME, DEFAULT_AGENTS_MD_FILENAME] { | ||
| let path = self.codex_home.join(candidate); | ||
| match tokio::fs::metadata(path.as_path()).await { | ||
| Ok(metadata) if !metadata.is_file() => continue, | ||
| Ok(_) => {} | ||
| Err(err) if err.kind() == io::ErrorKind::NotFound => continue, | ||
| Err(err) => { | ||
| warnings.push(format!( | ||
| "Failed to read global AGENTS.md instructions from `{}`: {err}", | ||
| path.display() | ||
| )); | ||
| continue; | ||
| } | ||
| } | ||
| let data = match tokio::fs::read(path.as_path()).await { | ||
| Ok(data) => data, | ||
| Err(err) if err.kind() == io::ErrorKind::NotFound => continue, | ||
| Err(err) => { | ||
| warnings.push(format!( | ||
| "Failed to read global AGENTS.md instructions from `{}`: {err}", | ||
| path.display() | ||
| )); | ||
| continue; | ||
| } | ||
| }; | ||
| if let Err(err) = std::str::from_utf8(&data) { | ||
| warnings.push(format!( | ||
| "Global AGENTS.md instructions from `{}` contain invalid UTF-8: {err}. Invalid byte sequences were replaced.", | ||
| path.display() | ||
| )); | ||
| } | ||
| let contents = String::from_utf8_lossy(&data); | ||
| let trimmed = contents.trim(); | ||
| if !trimmed.is_empty() { | ||
| return LoadedUserInstructions { | ||
| instructions: Some(UserInstructions { | ||
| text: trimmed.to_string(), | ||
| source: path, | ||
| }), | ||
| warnings, | ||
| }; | ||
| } | ||
| } | ||
| LoadedUserInstructions { | ||
| instructions: None, | ||
| warnings, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl UserInstructionsProvider for CodexHomeUserInstructionsProvider { | ||
| fn load_user_instructions(&self) -> LoadUserInstructionsFuture<'_> { | ||
| Box::pin(self.load_from_codex_home()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.