Skip to content

Refactor CLI parser to strict fail-closed architecture#3054

Open
MagersCode wants to merge 4 commits into
ultraworkers:mainfrom
MagersCode:main
Open

Refactor CLI parser to strict fail-closed architecture#3054
MagersCode wants to merge 4 commits into
ultraworkers:mainfrom
MagersCode:main

Conversation

@MagersCode
Copy link
Copy Markdown

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 --help requests to resolve instantly and prevent live runtime hanging bugs.

Anti-slop triage

  • Classification: actionable-fix
  • Evidence: Unit tests parses_bare_prompt_and_json_output_flag and resolves_model_aliases_in_args originally 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 --bins
  • Non-destructive review result: merge candidate

Verification

  • Targeted tests/docs checks ran, or the gap is explicitly recorded.
  • git diff --check passes.
  • No live secrets, tokens, private logs, or unrelated generated churn are included.

Resolution gate

  • If this PR resolves an issue, the issue number and fix evidence are linked. (Independent catch/contribution)
  • If this PR should not merge, the rejection/defer rationale is evidence-backed and does not rely on vibes.
  • I did not merge/close remote PRs or issues from an automation lane without owner approval.

Copy link
Copy Markdown
Collaborator

@code-yeongyu code-yeongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has merge conflicts with the base branch after recent merges. Please rebase onto main and resolve conflicts.

@code-yeongyu
Copy link
Copy Markdown
Collaborator

Please rebase onto main — this PR has merge conflicts. CI is otherwise being evaluated. Thanks!

@MagersCode
Copy link
Copy Markdown
Author

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!

@MagersCode MagersCode requested a review from code-yeongyu May 31, 2026 07:35
@MagersCode
Copy link
Copy Markdown
Author

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!

@1716775457damn
Copy link
Copy Markdown

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.

@MagersCode
Copy link
Copy Markdown
Author

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.

@1716775457damn
Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants