-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Use ConfigLayerStack for skills discovery. #8497
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
Conversation
c31928f to
fc55aa5
Compare
| outcome | ||
| .skills | ||
| .sort_by(|a, b| a.name.cmp(&b.name).then_with(|| a.path.cmp(&b.path))); | ||
| fn scope_rank(scope: SkillScope) -> u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this internal only, it's fine, but if you want some breathing room, consider at least i16?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The set of scopes should be small and relatively stable.
| outcome | ||
| } | ||
| outcome.skills.sort_by(|a, b| { | ||
| scope_rank(a.scope) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider defining PartialOrd or Ord on SkillMetadata?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ordering is only used locally in the loader to make the output deterministic, so keeping the scope_rank + sort_by here is the simplest and most straightforward approach.
codex-rs/core/src/skills/loader.rs
Outdated
|
|
||
| let system_folder = tmp.path().join("etc/codex"); | ||
| let user_folder = tmp.path().join("home/codex"); | ||
| fs::create_dir_all(&system_folder).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
up to you, but you can change the return type to anyhow::Result<()> and then you can use ? instead of unwrap() throughout, but have to add Ok(() at the end.
codex-rs/core/src/skills/loader.rs
Outdated
| async fn deduplicates_by_name_preferring_nearest_project_codex_dir() { | ||
| let codex_home = tempfile::tempdir().expect("tempdir"); | ||
| let repo_dir = tempfile::tempdir().expect("tempdir"); | ||
| let status = Command::new("git") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note you can use a marker file or just write .git with the contents "gitdir: fake" or something.
codex-rs/core/src/skills/loader.rs
Outdated
| assert!( | ||
| outcome.errors.is_empty(), | ||
| "unexpected errors: {:?}", | ||
| outcome.errors | ||
| ); | ||
| assert_eq!(outcome.skills.len(), 1); | ||
| assert_eq!(outcome.skills[0].name, "dupe-skill"); | ||
| assert_eq!(outcome.skills[0].description, "from nested"); | ||
| assert_eq!(outcome.skills[0].scope, SkillScope::Repo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer:
assert_eq!(
vec!(
SkillMetadata {
// ...
}
),
outcome.skills,
)test failures are far more informative when you do it this way.
Use ConfigLayerStack to get all folders while loading skills.