SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Add explicit help text for run-single
Kilian Liereta284180fd626
diff --git a/sweagent/run/common.py b/sweagent/run/common.pyindex 87f6932b..0f04ce99 100644--- a/sweagent/run/common.py+++ b/sweagent/run/common.py@@ -54,7 +54,9 @@ one after the other and reporting the failures for each of them."""_SETTING_ERROR_HINTS = """-[red][bold]Hint: Run sweagent <subcommand> --print-options for a complete overview of all available options.[/bold][/red]+[red][bold]Hints:[/bold][/red]+- Run `sweagent <subcommand> --print-options` for a complete overview of all available options.+- Run `sweagent <subcommand> --help` for examples[red][bold]Common mistakes:[/bold][/red]- You used dahses instead of underscores (`--num-workers` instead of `--num_workers`).@@ -64,15 +66,16 @@ _SETTING_ERROR_HINTS = """# todo: Parameterize type hintsclass BasicCLI:- def __init__(self, arg_type: type[BaseSettings], default_settings: bool = True):+ def __init__(self, arg_type: type[BaseSettings], default_settings: bool = True, help_text: str | None = None):self.arg_type = arg_typeself.default_settings = default_settingsself.logger = get_logger("swea-cli", emoji="🔧")+ self.help_text = help_textdef get_args(self, args=None) -> BaseSettings:# The defaults if no config file is provided# Otherwise, the configs from the respective classes will be used- parser = ArgumentParser(description=__doc__)+ parser = ArgumentParser(description=__doc__, add_help=not self.help_text)parser.add_argument("--config",type=str,@@ -83,6 +86,13 @@ class BasicCLI:"multiple files, e.g., --config config1.yaml --config config2.yaml"),)+ if self.help_text:+ parser.add_argument(+ "-h",+ "--help",+ action="store_true",+ help="Show help text and exit",+ )if self.default_settings:parser.add_argument("--no-config-file",@@ -97,6 +107,10 @@ class BasicCLI:parser.add_argument("--print-config", action="store_true", help="Print the final config and exit")cli_args, remaining_args = parser.parse_known_args(args)+ if cli_args.help:+ rich_print(self.help_text)+ exit(0)+if cli_args.print_options:CliApp.run(self.arg_type, ["--help"])exit(0)diff --git a/sweagent/run/run_single.py b/sweagent/run/run_single.pyindex 300c6ee0..f18782d3 100644--- a/sweagent/run/run_single.py+++ b/sweagent/run/run_single.py@@ -1,4 +1,39 @@-"""Run on a single instance taken from github or similar."""+"""[cyan][bold]Run SWE-agent on a single instance taken from github or similar.[/bold][/cyan]++[cyan][bold]=== OPTIONS ===[/bold][/cyan]++ -h --help Show help text and exit+ --config CONFIG Load additional config files. Use this option multiple times to load+ multiple files, e.g., --config config1.yaml --config config2.yaml+ --no-config-file Do not load default config file when no config file is provided+ --print-options Print all additional configuration options that can be set via CLI and exit+ [cyan][bold]--... Many more options[/cyan][/bold] (run `sweagent run --print-options` for a complete overview)++[cyan][bold]=== EXAMPLES ===[/bold][/cyan]++Basic usage: Run over a [bold][cyan]github issue[/bold][/cyan][green]:++sweagent run --config config/config.yaml --agent.model.name "gpt-4o" \\+ --env.repo.url=https://github.com/SWE-agent/test-repo/ \\+ --problem_statement.url=https://github.com/SWE-agent/test-repo/issues/1+[/green]++By default this will start a docker container and run the agent in there.+You can set the image with [green]--env.docker.image[/green].++Here's an example that uses [bold][cyan]modal[/bold][/cyan] instead of docker and also a [bold][cyan]local repository[/bold][/cyan]:++[green]sweagent run --config config/config.yaml --agent.model.name "gpt-4o" \\+ --env.deployment.type=modal --env.repo.path /path/to/repo \\+ --problem_statement.path=path/to/problem_statement.md+[/green]++[cyan][bold]=== MORE ===[/bold][/cyan]++To find out all command line options, run [green]sweagent run --print-options[/green]!++Want to run over more than one issue? Check out the [bold][cyan]batch mode[/bold][/cyan]: [green]sweagnet run-batch --help[/green]!+"""import getpassimport sys@@ -156,7 +191,7 @@ def run_from_config(args: RunSingleConfig):def run_from_cli(args: list[str] | None = None):if args is None:args = sys.argv[1:]- run_from_config(BasicCLI(RunSingleConfig).get_args(args)) # type: ignore+ run_from_config(BasicCLI(RunSingleConfig, help_text=__doc__).get_args(args)) # type: ignoreif __name__ == "__main__":