Detect implicit skill invocations from PowerShell reads (#38228)

## What changed

- Recognize `Get-Content` reads of indexed `SKILL.md` files as implicit skill invocations.
- Support the optional `-Raw` flag, quoted paths containing spaces, and Windows paths without stripping backslashes.

## Testing

- Add unit coverage for the supported `Get-Content` forms and Windows path parsing.

GitOrigin-RevId: 681f2e2fff9a597326bc94b97a31e311ef21b949
This commit is contained in:
ryanleeoai authored and copyberry committed 2026-08-12 18:04:20 +00:00
1 parent 1ad4397821
commit 9df9ff6ad9
2 files changed
+83

No files matched your search

+44
View File
@@ -64,6 +64,50 @@ fn script_run_detection_excludes_python_c() {
assert!(script_run_token(&tokens).is_none());
}
#[test]
fn powershell_skill_doc_read_matches_common_forms() {
let skill_doc_path = test_path_buf("/tmp/skill-test/SKILL.md").abs();
let spaced_skill_doc_path = test_path_buf("/tmp/skill test/SKILL.md").abs();
let skill = test_skill_metadata(skill_doc_path.clone());
let spaced_skill = test_skill_metadata(spaced_skill_doc_path.clone());
let outcome = TestLookup {
by_doc_path: HashMap::from([
(canonicalize_if_exists(&skill_doc_path), skill),
(canonicalize_if_exists(&spaced_skill_doc_path), spaced_skill),
]),
..Default::default()
};
let path = skill_doc_path.display();
let spaced_path = spaced_skill_doc_path.display();
for command in [
format!("Get-Content {path}"),
format!("Get-Content -Raw {path}"),
format!("Get-Content \"{spaced_path}\""),
format!("Get-Content -Raw \"{spaced_path}\""),
] {
let found = detect_implicit_skill_invocation_for_command(
&outcome,
&command,
&test_path_buf("/tmp").abs(),
);
assert_eq!(
found.map(|value| value.name),
Some("test-skill".to_string()),
"command: {command}"
);
}
}
#[test]
fn powershell_get_content_path_preserves_windows_backslashes() {
assert_eq!(
powershell_get_content_path(r#"Get-Content C:\skills\example\SKILL.md"#),
Some(r#"C:\skills\example\SKILL.md"#)
);
}
#[test]
fn skill_doc_read_detection_matches_absolute_path() {
let skill_doc_path = test_path_buf("/tmp/skill-test/SKILL.md").abs();