|
| 1 | +import subprocess |
| 2 | +import sys |
| 3 | + |
| 4 | +import click |
| 5 | + |
| 6 | +from .agent import prompt_agent |
| 7 | + |
| 8 | + |
| 9 | +@click.command() |
| 10 | +@click.argument("packages", nargs=-1, required=True) |
| 11 | +@click.option( |
| 12 | + "--agent-command", |
| 13 | + envvar="PLAIN_AGENT_COMMAND", |
| 14 | + help="Run command with generated prompt", |
| 15 | +) |
| 16 | +def install(packages: tuple[str, ...], agent_command: str | None = None) -> None: |
| 17 | + """Install Plain packages with the help of an agent.""" |
| 18 | + # Validate all package names |
| 19 | + invalid_packages = [pkg for pkg in packages if not pkg.startswith("plain")] |
| 20 | + if invalid_packages: |
| 21 | + raise click.UsageError( |
| 22 | + f"The following packages do not start with 'plain': {', '.join(invalid_packages)}\n" |
| 23 | + "This command is only for Plain framework packages." |
| 24 | + ) |
| 25 | + |
| 26 | + # Install all packages first |
| 27 | + if len(packages) == 1: |
| 28 | + click.secho(f"Installing {packages[0]}...", bold=True, err=True) |
| 29 | + else: |
| 30 | + click.secho(f"Installing {len(packages)} packages...", bold=True, err=True) |
| 31 | + for pkg in packages: |
| 32 | + click.secho(f" - {pkg}", err=True) |
| 33 | + click.echo(err=True) |
| 34 | + |
| 35 | + install_cmd = ["uv", "add"] + list(packages) |
| 36 | + result = subprocess.run(install_cmd, check=False, stderr=sys.stderr) |
| 37 | + |
| 38 | + if result.returncode != 0: |
| 39 | + raise click.ClickException("Failed to install packages") |
| 40 | + |
| 41 | + click.echo(err=True) |
| 42 | + if len(packages) == 1: |
| 43 | + click.secho(f"✓ {packages[0]} installed successfully", fg="green", err=True) |
| 44 | + else: |
| 45 | + click.secho(f"✓ {len(packages)} packages installed successfully", fg="green", err=True) |
| 46 | + click.echo(err=True) |
| 47 | + |
| 48 | + # Build the prompt for the agent to complete setup |
| 49 | + lines = [ |
| 50 | + f"Complete the setup for the following Plain packages that were just installed: {', '.join(packages)}", |
| 51 | + "", |
| 52 | + "## Instructions", |
| 53 | + "", |
| 54 | + "For each package:", |
| 55 | + "1. Run `uv run plain docs <package>` and follow any setup instructions", |
| 56 | + "2. If the docs point out that it is a --dev tool, move it to dev dependencies: `uv remove <package> && uv add <package> --dev`", |
| 57 | + "", |
| 58 | + "DO NOT commit any changes", |
| 59 | + "", |
| 60 | + "Report back with:", |
| 61 | + "- Whether the setup completed successfully", |
| 62 | + "- Any manual steps that still need to be completed", |
| 63 | + "- Any issues or errors encountered", |
| 64 | + ] |
| 65 | + |
| 66 | + prompt = "\n".join(lines) |
| 67 | + success = prompt_agent(prompt, agent_command) |
| 68 | + if not success: |
| 69 | + raise click.Abort() |
0 commit comments