diff --git a/scripts/fabric_sync.py b/scripts/fabric_sync.py index fb0c02e..0a26ff1 100755 --- a/scripts/fabric_sync.py +++ b/scripts/fabric_sync.py @@ -111,11 +111,11 @@ def run_ai_scrutiny_review(scrutiny_report: dict, config: dict, tool_name: str, if not cmdforge_exe: return None - # Run the tool + # Run the tool (use -- to separate cmdforge args from tool args) try: result = subprocess.run( [ - cmdforge_exe, "run", "scrutiny-ai-review", + cmdforge_exe, "run", "scrutiny-ai-review", "--", "--warnings", json.dumps(warnings), "--tool-config", json.dumps(tool_config), ], diff --git a/src/cmdforge/cli/__init__.py b/src/cmdforge/cli/__init__.py index 07ff350..7e0721d 100644 --- a/src/cmdforge/cli/__init__.py +++ b/src/cmdforge/cli/__init__.py @@ -67,7 +67,7 @@ def main(): p_run.add_argument("--dry-run", action="store_true", help="Show what would happen without executing") p_run.add_argument("--show-prompt", action="store_true", help="Show prompts in addition to output") p_run.add_argument("-v", "--verbose", action="store_true", help="Show debug information") - p_run.add_argument("tool_args", nargs="*", help="Additional tool-specific arguments") + p_run.add_argument("tool_args", nargs=argparse.REMAINDER, help="Additional tool-specific arguments (use -- to separate)") p_run.set_defaults(func=cmd_run) # 'ui' command (explicit) diff --git a/src/cmdforge/cli/tool_commands.py b/src/cmdforge/cli/tool_commands.py index 6e94f8b..d313b79 100644 --- a/src/cmdforge/cli/tool_commands.py +++ b/src/cmdforge/cli/tool_commands.py @@ -202,26 +202,48 @@ def cmd_run(args): # Collect custom args from remaining arguments custom_args = {} + + # Build a map from flag names to variable names for proper argument mapping + flag_to_var = {} + for tool_arg in tool.arguments: + # Handle both --flag and -f style flags + flag = tool_arg.flag + if flag.startswith('--'): + flag_key = flag[2:].replace('-', '_') + elif flag.startswith('-'): + flag_key = flag[1:].replace('-', '_') + else: + flag_key = flag.replace('-', '_') + flag_to_var[flag_key] = tool_arg.variable + if args.tool_args: + # Remove leading '--' separator if present (used to separate cmdforge args from tool args) + tool_args = list(args.tool_args) + if tool_args and tool_args[0] == '--': + tool_args = tool_args[1:] + # Parse tool-specific arguments i = 0 - while i < len(args.tool_args): - arg = args.tool_args[i] + while i < len(tool_args): + arg = tool_args[i] if arg.startswith('--'): - key = arg[2:].replace('-', '_') - if i + 1 < len(args.tool_args) and not args.tool_args[i + 1].startswith('--'): - custom_args[key] = args.tool_args[i + 1] + flag_key = arg[2:].replace('-', '_') + # Map flag name to variable name (use flag_key as fallback for unknown flags) + var_name = flag_to_var.get(flag_key, flag_key) + if i + 1 < len(tool_args) and not tool_args[i + 1].startswith('--'): + custom_args[var_name] = tool_args[i + 1] i += 2 else: - custom_args[key] = True + custom_args[var_name] = True i += 1 elif arg.startswith('-'): - key = arg[1:].replace('-', '_') - if i + 1 < len(args.tool_args) and not args.tool_args[i + 1].startswith('-'): - custom_args[key] = args.tool_args[i + 1] + flag_key = arg[1:].replace('-', '_') + var_name = flag_to_var.get(flag_key, flag_key) + if i + 1 < len(tool_args) and not tool_args[i + 1].startswith('-'): + custom_args[var_name] = tool_args[i + 1] i += 2 else: - custom_args[key] = True + custom_args[var_name] = True i += 1 else: i += 1 diff --git a/src/cmdforge/registry/app.py b/src/cmdforge/registry/app.py index be9fc87..ce07a4d 100644 --- a/src/cmdforge/registry/app.py +++ b/src/cmdforge/registry/app.py @@ -251,11 +251,11 @@ def run_ai_scrutiny_review(scrutiny_report: dict, config: dict, tool_name: str, if not cmdforge_exe: return None - # Run the tool + # Run the tool (use -- to separate cmdforge args from tool args) try: result = subprocess.run( [ - cmdforge_exe, "run", "scrutiny-ai-review", + cmdforge_exe, "run", "scrutiny-ai-review", "--", "--warnings", json.dumps(warnings), "--tool-config", json.dumps(tool_config), ],