Fix tool argument passing for flag-style arguments

- Change nargs="*" to REMAINDER for tool_args to stop argparse from
  intercepting --flag style arguments meant for the tool
- Add -- separator handling to distinguish cmdforge args from tool args
- Map flag names to variable names using tool argument definitions
- Update AI review subprocess calls to use -- separator

Fixes scrutiny-ai-review tool arguments not being passed correctly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
rob 2026-01-16 16:39:36 -04:00
parent e1cae5ffda
commit 12ae870b3c
4 changed files with 37 additions and 15 deletions

View File

@ -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),
],

View File

@ -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)

View File

@ -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

View File

@ -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),
],