Refactor CLI parser to strict fail-closed architecture#3054
Conversation
code-yeongyu
left a comment
There was a problem hiding this comment.
This PR has merge conflicts with the base branch after recent merges. Please rebase onto main and resolve conflicts.
|
Please rebase onto |
|
Hey @code-yeongyu! I've successfully rebased onto main, resolved all conflicts manually, and updated the unit tests to match the new strict architecture. Ready for another look when you have a moment. Thanks! |
|
Hey @code-yeongyu! The merge conflicts with main are completely resolved. I also double-checked the tests, and the fail-closed test updates you requested were successfully pulled in and verified during the conflict resolution. Can you approve the workflow runs when you get a chance so we get green CI checks? Thanks! |
|
Good change — fail-closed is the right default for a CLI that can silently forward unintended arguments to the LLM prompt. The --help short-circuit fix is also a nice bonus. One question: are there any common user commands or shell aliases that might have been relying on the old leaky behavior and would now break with the strict parser? Worth a quick check before merge. |
|
Hey @1716775457damn and @code-yeongyu! I did a full audit of the changes using local smoke tests (cargo run). The main 'breaking' changes successfully plug unintentional leaks: Single-word typos (e.g. claw sttaus) cleanly throw a command_not_found error with a "Did you mean?" suggestion. Empty strings (claw "") safely fail locally with a usage hint. Trailing garbage args (like claw status --bogus) explicitly fail. Missing slashes on reserved tools (like claw explain this) intercept the typo and remind the user to use the /explain slash command. Standard natural language prompts (e.g., claw write a python script) still fall through to the LLM perfectly. Standard usage isn't negatively impacted; we just stop the tool from burning tokens on malformed inputs! Everything is pushed and passing locally. |
|
The fail-closed parsing approach is the right direction. The new strict error messages should guide users toward correct invocation formats. The --help short-circuit preventing unnecessary runtime init is a nice efficiency touch as well. |
Summary
Refactored the CLI parser from a fail-open structure to a strict, fail-closed architecture. This prevents unrecognized subcommand trailing arguments or keywords (like passing raw keywords into the prompt path) from silently dropping through to the LLM prompt fallback, protecting against accidental network calls and unwanted token usage. Additionally, implemented short-circuiting logic for
--helprequests to resolve instantly and prevent live runtime hanging bugs.Anti-slop triage
parses_bare_prompt_and_json_output_flagandresolves_model_aliases_in_argsoriginally failed under the strict parsing behavior because they expected leaky drop-through prompts, until they were updated to assert for the new secure boundary guidance error. Local verification command ran successfully:cargo test -p rusty-claude-cli --binsVerification
git diff --checkpasses.Resolution gate