AgentSkillsCN

cli

基于点击的 CLI 入口——psi new 命令与 psi run 命令

SKILL.md
--- frontmatter
name: cli
description: Click-based CLI entry points — psi new and psi run commands

CLI

Click command group in src/psi/cli.py. Two commands: psi new and psi run.

Overview

Entry point configured in pyproject.toml:

toml
[project.scripts]
psi = "psi.cli:cli"

Also runnable as python -m psi via __main__.py.

Commands

psi new <directory> "<description>"

Scaffolds a new project:

  • directoryclick.Path(file_okay=False) — target path (must not exist or be empty)
  • description — app description passed to Claude for template filling

Calls scaffold.scaffold_project(). Fails with click.ClickException if directory exists and is non-empty.

psi run [directory] [options]

Runs the orchestrator loop:

  • directoryclick.Path(exists=True, file_okay=False) — project root (default: ".")
  • --max-iterations, -mtype=int, default=30 — max iterations per phase
  • --timeout, -ttype=int, default=600 — seconds per iteration
  • --no-weaveis_flag=True — disable Weave tracing

Creates a Psi instance and calls run(). Exit code 0 on success, 1 on failure.

Patterns

Lazy Imports

Both commands use lazy imports inside the command function to avoid loading heavy modules (orchestrator, scaffold) at CLI parse time:

python
@cli.command()
def new(directory, description):
    from psi.scaffold import scaffold_project  # lazy
    scaffold_project(...)

Exit Handling

psi run uses raise SystemExit(code) instead of sys.exit() — works cleanly with Click's exception handling.

Related Files

  • src/psi/cli.py — Click commands
  • src/psi/__main__.pypython -m psi entry
  • src/psi/scaffold.py — Called by psi new
  • src/psi/orchestrator.py — Called by psi run
  • pyproject.toml[project.scripts] entry