Skip to main content

normalize_command_for_dispatch

Function normalize_command_for_dispatch 

Source
pub fn normalize_command_for_dispatch(command: &str) -> Option<String>
Expand description

Normalize a shell command for compressor dispatch by walking past common shell-prefix idioms so the REAL command head is what matchers see. Returns Some(normalized) if a prefix was stripped, None if the input was already a bare command.

Handles:

  • cd /path && cmd ...cmd ...
  • cd /path; cmd ...cmd ...
  • env FOO=bar [BAR=baz ...] cmdcmd ...
  • timeout 30 cmd ...cmd ...
  • nohup cmd ...cmd ...
  • (cd /path && cmd ...)cmd ... (trailing ) is kept; harmless for matchers)

Real agent invocations almost always wrap their actual command in cd "$ROOT" && .... Without this normalization, BunCompressor / NpmCompressor / PnpmCompressor (head-token matchers) and the pkg-manager filters silently fall through to GenericCompressor for the majority of agent bash calls.

The normalizer is conservative: it only strips well-defined idioms and bails on anything ambiguous, so a malformed command degrades to the same dispatch behaviour as before this helper existed.