Use in-process parsing for PowerShell command classification (#39602)

## What changed

- Route PowerShell wrapper extraction and Windows safe-command classification through the tree-sitter lowerer.
- Compile the PowerShell AST subprocess parser only in tests, where it remains available as an oracle.

GitOrigin-RevId: 3690bc32e8987ac9de820ef39ff7401d98ea8d83
This commit is contained in:
iceweasel-oai
2026-08-20 05:45:13 +00:00
committed by copyberry
parent 198f42067a
commit 8e7f646974
3 changed files with 11 additions and 59 deletions
+4 -5
View File
@@ -2,7 +2,6 @@ use std::path::PathBuf;
use codex_utils_absolute_path::AbsolutePathBuf;
use crate::command_safety::try_parse_powershell_ast_commands;
use crate::command_safety::try_parse_powershell_commands;
use crate::shell_detect::ShellType;
use crate::shell_detect::detect_shell_type;
@@ -74,13 +73,13 @@ pub fn extract_powershell_command(command: &[String]) -> Option<(&str, &str)> {
/// Parse the script body from a top-level PowerShell wrapper into argv-like commands.
///
/// This is intentionally narrower than the Windows safe-command parser: it only unwraps the
/// `-Command`/`-c` body from a PowerShell invocation we already recognize, then delegates the
/// script itself to the PowerShell AST parser.
/// `-Command`/`-c` body from a PowerShell invocation we already recognize, then lowers the
/// script in-process.
pub fn parse_powershell_command_into_plain_commands(
command: &[String],
) -> Option<Vec<Vec<String>>> {
let (executable, script) = extract_powershell_command(command)?;
try_parse_powershell_ast_commands(executable, script)
let (_, script) = extract_powershell_command(command)?;
try_parse_powershell_commands(script)
}
/// Parse literal PowerShell commands without starting a PowerShell executable.