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:
parent
e1cae5ffda
commit
12ae870b3c
|
|
@ -111,11 +111,11 @@ def run_ai_scrutiny_review(scrutiny_report: dict, config: dict, tool_name: str,
|
||||||
if not cmdforge_exe:
|
if not cmdforge_exe:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Run the tool
|
# Run the tool (use -- to separate cmdforge args from tool args)
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
[
|
[
|
||||||
cmdforge_exe, "run", "scrutiny-ai-review",
|
cmdforge_exe, "run", "scrutiny-ai-review", "--",
|
||||||
"--warnings", json.dumps(warnings),
|
"--warnings", json.dumps(warnings),
|
||||||
"--tool-config", json.dumps(tool_config),
|
"--tool-config", json.dumps(tool_config),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -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("--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("--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("-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)
|
p_run.set_defaults(func=cmd_run)
|
||||||
|
|
||||||
# 'ui' command (explicit)
|
# 'ui' command (explicit)
|
||||||
|
|
|
||||||
|
|
@ -202,26 +202,48 @@ def cmd_run(args):
|
||||||
|
|
||||||
# Collect custom args from remaining arguments
|
# Collect custom args from remaining arguments
|
||||||
custom_args = {}
|
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:
|
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
|
# Parse tool-specific arguments
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(args.tool_args):
|
while i < len(tool_args):
|
||||||
arg = args.tool_args[i]
|
arg = tool_args[i]
|
||||||
if arg.startswith('--'):
|
if arg.startswith('--'):
|
||||||
key = arg[2:].replace('-', '_')
|
flag_key = arg[2:].replace('-', '_')
|
||||||
if i + 1 < len(args.tool_args) and not args.tool_args[i + 1].startswith('--'):
|
# Map flag name to variable name (use flag_key as fallback for unknown flags)
|
||||||
custom_args[key] = args.tool_args[i + 1]
|
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
|
i += 2
|
||||||
else:
|
else:
|
||||||
custom_args[key] = True
|
custom_args[var_name] = True
|
||||||
i += 1
|
i += 1
|
||||||
elif arg.startswith('-'):
|
elif arg.startswith('-'):
|
||||||
key = arg[1:].replace('-', '_')
|
flag_key = arg[1:].replace('-', '_')
|
||||||
if i + 1 < len(args.tool_args) and not args.tool_args[i + 1].startswith('-'):
|
var_name = flag_to_var.get(flag_key, flag_key)
|
||||||
custom_args[key] = args.tool_args[i + 1]
|
if i + 1 < len(tool_args) and not tool_args[i + 1].startswith('-'):
|
||||||
|
custom_args[var_name] = tool_args[i + 1]
|
||||||
i += 2
|
i += 2
|
||||||
else:
|
else:
|
||||||
custom_args[key] = True
|
custom_args[var_name] = True
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
|
||||||
|
|
@ -251,11 +251,11 @@ def run_ai_scrutiny_review(scrutiny_report: dict, config: dict, tool_name: str,
|
||||||
if not cmdforge_exe:
|
if not cmdforge_exe:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Run the tool
|
# Run the tool (use -- to separate cmdforge args from tool args)
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
[
|
[
|
||||||
cmdforge_exe, "run", "scrutiny-ai-review",
|
cmdforge_exe, "run", "scrutiny-ai-review", "--",
|
||||||
"--warnings", json.dumps(warnings),
|
"--warnings", json.dumps(warnings),
|
||||||
"--tool-config", json.dumps(tool_config),
|
"--tool-config", json.dumps(tool_config),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue