Use when building a new CLI tool that needs one-line install via uv or npm, subcommand dispatch with a default action, or 3-tier config resolution (CLI flags, config file, hardcoded defaults).
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "cli-packaging-patterns" 技能: 1. 下载 https://raw.githubusercontent.com/microsoft/amplifier-bundle-skills/main/skills/cli-packaging-patterns/SKILL.md 2. 保存为 ~/.claude/skills/cli-packaging-patterns/SKILL.md 3. 装好后重载技能,告诉我可以用了
Problem: You want a CLI tool that installs cleanly from a git URL with zero manual steps — no cloning, no virtual env, no PATH fiddling.
Approach: Combine pyproject.toml [project.scripts] with hatchling build backend, a __main__.py dual entry point, and argparse with a default-action subcommand design so mytool and mytool serve do the same thing.
Pattern proven in production across multiple Python CLI tools and web services.
This skill assumes a pure Python CLI distributed via uv tool install. If your project does not fit that profile, use a different pattern:
| Project shape | Use instead |
|---|---|
| Multi-language stack (Python + Node + Docker) | one-line-installer-patterns |
| Raw TS/React app with no Python wrapper | one-line-installer-patterns (or publish to npm) |
| Tool that bootstraps system prerequisites | one-line-installer-patterns |
| Containerized multi-service app | Ship docker-compose.yml; see container-orchestration-patterns |
| Single static binary (Go/Rust) | GitHub releases + curl -L .../bin -o ~/.local/bin/tool |
If the project IS a pure Python CLI, the rest of this skill applies.
[project.scripts] — Not setuptoolsUse hatchling as the build backend. The entry point declaration is:
[project.scripts]
my-tool = "my_tool.cli:main"
Why hatchling: simpler than setuptools, no setup.py, no MANIFEST.in. The [tool.hatch.build.targets.wheel] section lets you exclude test files from the published wheel:
[tool.hatch.build.targets.wheel]
packages = ["my_tool"]
exclude = ["my_tool/tests", "my_tool/frontend/tests"]
__main__.py dual entry — python -m always worksInclude a minimal __main__.py so the tool works even when the script entry point isn't on PATH:
# my_tool/__main__.py
"""Allow running as: python -m my_tool"""
from my_tool.cli import main
main()
This matters because uv tool install creates a wrapper script, but during development or in edge cases, python -m my_tool is a reliable fallback. Service management code should use this as a fallback too:
def _resolve_tool_bin() -> str:
which = shutil.which("my-tool")
if which:
return which
return f"{sys.executable} -m my_tool"
tool equals tool serveUse argparse with shared flags on the root parser AND on the serve subcommand, so the bare command runs the server:
def main() -> None:
parser = argparse.ArgumentParser(prog="my-tool", ...)
_add_serve_flags(parser) # flags on root parser
sub = parser.add_subparsers(dest="command")
serve_parser = sub.add_parser("serve", help="Start the server (default)")
_add_serve_flags(serve_parser) # same flags on 'serve' subcommand
The dispatch at the bottom falls through to serve() when no subcommand is given:
else:
serve(host=args.host, port=args.port, ...)
The serve() function resolves every setting with the same pattern — CLI flag wins, then settings file, then hardcoded default:
settings = load_settings()
host = host if host is not None else settings.get("host", "127.0.0.1")
port = port if port is not None else settings.get("port", 8088)
log_level = log_level if log_level is not None else settings.get("log_level", "info")
Using None as the argparse default (not a value like "127.0.0.1") is critical — it distinguishes "user didn't pass a flag" from "user explicitly set it."
uv tool install git+https://... compatibilityNo special config needed — hatchling + [project.scripts] is all uv requires. The install command is:
uv tool install git+https://github.com/yourorg/your-tool
…
Guide for creating new Amplifier modules including protocol implementation, entry points, mount functions, and testing patterns. Use when creating new modules or understanding module architecture.
Python coding standards for Amplifier including type hints, async patterns, error handling, and formatting. Use when writing Python code for Amplifier modules.
Adapt a skill written for another AI coding assistant (Claude Code, Cursor, etc.) into a properly structured Amplifier SKILL.md file. Reads the source skill, identifies platform-specific conventions, researches the source platform if needed, and produces an Amplifier-native skill conforming to the Agent Skills specification with Amplifier extensions. Use when the user wants to adapt a skill, port a skill, convert a skill to amplifier, translate a skill, or has a SKILL.md from another platform they want to bring into Amplifier.
Use when your service needs authentication that works without friction locally but secures remote access, automatic TLS certificate setup, or token-based auth with auto-generation and localhost bypass.
Review changed code for reuse, quality, and efficiency, then fix any issues found.
Amplifier design philosophy using Linux kernel metaphor. Covers mechanism vs policy, module architecture, event-driven design, and kernel principles. Use when designing new modules or making architectural decisions.