Skip to content

fix: batch fix for cortex-cli bugs (exit codes, conflicting flags, JSON output, security)#564

Open
echobt wants to merge 9 commits intomasterfrom
fix/cortex-cli-issue-batch-1
Open

fix: batch fix for cortex-cli bugs (exit codes, conflicting flags, JSON output, security)#564
echobt wants to merge 9 commits intomasterfrom
fix/cortex-cli-issue-batch-1

Conversation

@echobt
Copy link
Contributor

@echobt echobt commented Feb 2, 2026

Summary

This PR addresses multiple open issues from the PlatformNetwork/bounty-challenge repository affecting cortex-cli.

Issues Fixed

Exit Code Issues

  • #3896: cortex debug file now returns non-zero exit code when file does not exist
  • #3891: whoami command now returns error when checking login status fails
  • #3843: upgrade command now returns error for invalid channel (stable/beta/nightly)
  • #3820: config get/unset now return error when key not found

Conflicting Flags Validation

  • #3885: exec command validates that --enabled-tools and --disabled-tools cannot both be specified
  • #3857: mcp logout validates that --name and --all cannot both be specified
  • #3856: agent list validates that --primary and --subagents cannot both be specified
  • #3855: plugin list validates that --enabled and --disabled cannot both be specified
  • #3819: mcp add validates that --url and --sse cannot both be specified
  • #3814: login validates that only one auth method can be specified

JSON Output Issues

  • #3879: debug config --diff --json now outputs pure JSON
  • #3838: dag run --strategy dry-run respects --format flag
  • #3826: compact run --dry-run --json outputs JSON
  • #3738: dag list --format json outputs proper JSON
  • #3735: alias show --json outputs JSON on errors
  • #3723: plugin show --json outputs JSON on errors
  • #947: debug wait --json outputs JSON on errors
  • #948: mcp get --json outputs JSON on errors
  • #952: run --format json outputs JSON on auth errors

Security Fix

  • #3851: Fixed allows_risk() to pass actual command to is_read_only_command() instead of risk level

Input Validation Issues

  • #3815: DAG validation now rejects duplicate task IDs
  • #3722: models list --sort validates sort values (name, provider, context, created, id)
  • #3716: dag run --jobs 0 now errors instead of hanging
  • #3700: plugin install "" now returns proper error for empty name
  • #3696: lock add now validates session ID format (UUID or 8-char prefix)

User Experience Fixes

  • #3646: resume command now accepts 'last' as SESSION_ID per help text
  • #3651: upgrade --changelog now fetches raw content instead of HTML
  • #3150: debug config now correctly detects config.json files
  • #3682: uninstall --backup now creates backup after user confirmation
  • #3678: Fixed help text to reference correct GitHub repository URL
  • #3792: Removed emoji from pr command output (replaced with text alternatives)

Changes

  • Multiple files modified across cortex-cli
  • All error paths return proper exit codes using bail!() macro
  • All commands with --json flag output valid JSON even on errors
  • Mutually exclusive flags produce validation errors when both specified
  • Security bug fixed in autonomy level checking

Testing

  • cargo check -p cortex-cli passes
  • cargo fmt --all applied
  • All changes follow existing codebase patterns and conventions

Note

This PR is for review only - DO NOT MERGE until reviewed.

Replace emoji characters with ASCII text alternatives:
- 🔀 → [PR]
- ⏳ → [WAIT]

Fixes #3792
…nd jobs=0

- Issue #3815: Reject duplicate task IDs in DAG specification
- Issue #3722: Validate --sort flag values in models list command
- Issue #3716: Reject --jobs 0 which would cause hang
SECURITY FIX: The allows_risk() function was incorrectly passing the risk
level string to is_read_only_command() instead of the actual command.

This bug meant that in read-only mode, is_read_only_command("low") was
always returning false (since "low" doesn't match any read-only patterns),
which could allow non-read-only commands to be auto-approved.

Changes:
- Added 'command' parameter to allows_risk() function
- Fixed the call to is_read_only_command(command) instead of (risk)
- Added comprehensive tests for allows_risk() function

Fixes #3851
- file.rs: run_file now returns error when file doesn't exist (#3896)
- handlers.rs: run_whoami now returns Result<()> with proper error (#3891)
- handlers.rs: config get/unset now return errors on key not found (#3820)
- upgrade_cmd.rs: invalid channel now returns error instead of Ok(()) (#3843)
- exec_cmd: Check --enabled-tools and --disabled-tools are not both specified
- mcp_cmd/auth: Check --name and --all are not both specified for logout
- agent_cmd: Check --primary and --subagents are not both specified for list
- plugin_cmd: Check --enabled and --disabled are not both specified for list
- mcp_cmd/handlers: Check --url and --sse are not both specified for add
- cli/handlers: Check only one auth method (--token, --sso, --device-auth, --with-api-key) is specified for login

Issues: #3885, #3857, #3856, #3855, #3819, #3814
- config.rs: Pure JSON output when --json with --diff (Issue #3879)
- compact_cmd.rs: JSON output for dry-run with --json (Issue #3826)
- alias_cmd.rs: JSON error when alias not found with --json (Issue #3735)
- plugin_cmd.rs: JSON error when plugin not installed with --json (Issue #3723)
- Fix debug config to detect config.json instead of only config.toml (#3150)
- Fix uninstall --backup to create backup after confirmation, not before (#3682)
- Fix plugin install to validate empty plugin names (#3700)
- Fix lock add to validate session ID format (#3696)
- Fix resume command to accept 'last' as SESSION_ID per help text (#3646)
- Fix help text to reference correct GitHub repo URL (#3678)
- Fix upgrade --changelog to fetch raw content instead of HTML (#3651)
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.

1 participant