code-agent-manager icon indicating copy to clipboard operation
code-agent-manager copied to clipboard

Critical: TypeError on CLI initialization - 'Secondary flag is not valid for non-boolean flag'

Open Vadiml1024 opened this issue 10 months ago • 1 comments

Bug Report: TypeError on CLI initialization - "Secondary flag is not valid for non-boolean flag"

Description

CAM fails to initialize with a TypeError when running any command, including cam --help. The error occurs during Typer/Click CLI initialization due to incorrect use of short flags on non-boolean options.

Error Message

TypeError: Secondary flag is not valid for non-boolean flag.

Root Cause

Throughout the codebase, non-boolean typer.Option() definitions incorrectly include short flags (e.g., -c, -s, -n, -o, -b, -f, -d, -a, -l, -m).

In Click/Typer, only boolean flags can have both a long form (--flag) and short form (-f). Non-boolean options (strings, paths, integers, etc.) can only use long-form flags.

Affected Files

The issue affects at least 12 files across the codebase:

  • cli/agents_commands.py
  • cli/app.py
  • cli/options.py
  • cli/plugins/plugin_discovery_commands.py
  • cli/plugins/plugin_install_commands.py
  • cli/plugins/plugin_management_commands.py
  • cli/plugins/plugin_marketplace_commands.py
  • cli/prompts_commands.py
  • cli/skills_commands.py
  • mcp/cli.py
  • mcp/install_commands.py
  • mcp/server_commands.py

Example Problematic Code

# INCORRECT - non-boolean option with short flag
CONFIG_FILE_OPTION = typer.Option(None, "--config", "-c", help="Path to config file")
SCOPE_OPTION = typer.Option("user", "--scope", "-s", help="Configuration scope")
OWNER_OPTION = typer.Option(..., "--owner", "-o", help="Repository owner")

# CORRECT - only long flag for non-boolean options
CONFIG_FILE_OPTION = typer.Option(None, "--config", help="Path to config file")
SCOPE_OPTION = typer.Option("user", "--scope", help="Configuration scope")
OWNER_OPTION = typer.Option(..., "--owner", help="Repository owner")

# CORRECT - boolean options can have short flags
DEBUG_OPTION = typer.Option(False, "--debug", "-d", help="Enable debug logging")
FORCE_OPTION = typer.Option(False, "--force", "-f", help="Skip confirmation prompt")

Additional Issue: Boolean Flag with Parameter Name Conflict

In cli/prompts_commands.py, there's also an issue where a boolean flag uses the Python parameter name in the CLI declaration:

# INCORRECT - parameter name included in param_decls
default: Optional[bool] = typer.Option(None, "--default/--no-default", help="...")

# This creates param_decls = ['default', '--default/--no-default']
# where 'default' is treated as a short flag

Steps to Reproduce

  1. Install CAM from the repository (commit 0f79489a8abac6cd298442c7a7c3f67ce215bc6b or tag 1.3.0)
  2. Run cam --help or any CAM command
  3. Observe the TypeError

Environment

  • CAM Version: 0.0.0 (tag 1.3.0, commit 0f79489a8abac6cd298442c7a7c3f67ce215bc6b)
  • Python Version: 3.11
  • Typer Version: 0.12.5
  • Click Version: 8.3.1
  • OS: macOS (Darwin 25.2.0)

Expected Behavior

CAM should initialize successfully and display help or execute commands.

Actual Behavior

CAM fails during initialization with a TypeError before any command can execute.

Suggested Fix

Remove all short flags from non-boolean typer.Option() definitions throughout the codebase. The pattern to fix is:

# Find and replace pattern:
typer.Option(value, "--long-flag", "-s", help=...)
# Replace with:
typer.Option(value, "--long-flag", help=...)

Only boolean options (with True/False as the first argument or is_flag=True) should retain short flags.

Workaround

Users can manually patch the installed package by removing short flags from the affected files, but this requires post-installation modifications to the site-packages directory.

Impact

Critical - The tool is completely unusable without patching. No commands can execute, including --help.

Additional Notes

This appears to be a systemic issue suggesting the original development may have used an older version of Click/Typer with different flag behavior, or the flag definitions were never tested with the current versions of these dependencies.

Vadiml1024 avatar Feb 01 '26 15:02 Vadiml1024

thank you for the PR i have tested and merged it.

zhujian0805 avatar Feb 26 '26 03:02 zhujian0805