fix(ai): warn 'missing shfmt/safecmd' instead of 'Missing ai addon' + ship shfmt via the ai addon#1274
Merged
Merged
Conversation
…ia addon The guardrail shell parser (_parse_subcommands) shells out to shfmt via safecmd. When either was absent it printed a misleading Error "Missing ai addon" (the ai addon = litellm, which can be present without the shell parser) on the ImportError path, and was SILENT on the shfmt-binary-missing path (FileNotFoundError swallowed by `except Exception`). Both left the user confused while the guardrail quietly fell back to whole-command approval. - Emit a clear one-shot Warning naming the actual missing piece — "Missing safecmd shell parser" (ImportError) or "Missing shfmt binary" (FileNotFoundError) — and fall back to the non-shfmt path (empty sub-command list -> caller asks for whole-command approval). Warn once per process, no per-command spam. - Make shfmt an explicit ai-addon dependency (`shfmt-py` in the `ai` extra) so `secator install addons ai` always ships the binary, not just the safecmd package. Also fixes the ADDONS_ENABLED['ai'] blind spot in practice: a litellm-only install no longer masquerades as a fully-working ai addon at the guardrail layer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NNjPggRSVZ2xnLb7ZxWP5H
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem (hit during CLI testing)
In attack mode every shell command the LLM issues hit the guardrail shell parser, which printed:
…even though the ai addon was installed.
_parse_subcommands(guardrails.py) shells out toshfmtviasafecmd; the misleading message came from itsImportErrorbranch. The env hadlitellm(soADDONS_ENABLED['ai']=True) but notsafecmd/shfmt— a partial ai install. Worse, the other failure mode (safecmd present,shfmtbinary not on PATH) was silent (FileNotFoundErrorswallowed byexcept Exception: return []).Fix
Error("Missing ai addon")with a one-shotWarningthat names the real gap:"Missing safecmd shell parser"(ImportError) or"Missing shfmt binary"(FileNotFoundError). Both fall back to the non-shfmt path — an empty sub-command list, so_check_action_typeasks the user to approve the whole command (safe, just coarser). Warn once per process (no per-command spam).shfmt-pyexplicitly to theaiextra sosecator install addons ai(pip install secator[ai]) always ships theshfmtbinary, not just thesafecmdPython package (which only pulled it transitively).Tests
TestShellParserFallback: safecmd-missing →Warningnamingsafecmd, never"ai addon"; shfmt-binary-missing →Warningnamingshfmt; warn-once across multiple commands. Full AI suite: no new failures vs branch baseline.Found while testing
ai-testing; targetsai-resiliency(#1241).🤖 Generated with Claude Code