/angreal:angreal-patternsfrom angreal
Provides testing patterns (unit testing, mocking subprocess and angreal.get_root()), debug logging (ANGREAL_DEBUG), and development patterns for angreal tasks.
Ships in angreal. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Common patterns for testing, documenting, and developing angreal tasks.
# tests/test_build.py
import sys
sys.path.insert(0, ".angreal")
from task_build import build
def test_build_debug_mode():
result = build(release=False)
assert result == 0
def test_build_release_mode():
result = build(release=True)
assert result == 0
from unittest.mock import patch, MagicMock
def test_run_tests_success():
with patch("subprocess.run") as mock_run:
mock_run.return_value = MagicMock(returncode=0)
from task_test import run_tests
result = run_tests()
assert result == 0
# tests/conftest.py
import pytest
from pathlib import Path
@pytest.fixture
def temp_project(tmp_path):
"""Create temporary project structure."""
angreal_dir = tmp_path / ".angreal"
angreal_dir.mkdir()
(tmp_path / "src").mkdir()
return tmp_path
@pytest.fixture
def mock_root(temp_project, monkeypatch):
"""Mock get_root() to return .angreal/ directory."""
import angreal
angreal_dir = temp_project / ".angreal"
monkeypatch.setattr(angreal, "get_root", lambda: angreal_dir)
return temp_project # Return project root for assertions
def test_task_output(capsys):
from task_status import status
status()
captured = capsys.readouterr()
assert "Project Status" in captured.out
ANGREAL_DEBUG)For debugging Angreal itself (task discovery, command registration, argument parsing, template rendering) — independent of any task-internal -v flag your task author wired up:
ANGREAL_DEBUG=true angreal test rust --unit-only
ANGREAL_DEBUG=true forces debug-level logging from the Angreal runtime and overrides CLI -v/-vv flags. Output goes to stderr. Use this when a task isn't being discovered, an argument isn't parsing as expected, or a template render fails silently.
In CI, also set ANGREAL_NO_AUTO_COMPLETION=1 to suppress the auto-install of shell completion on first run.
import angreal
@angreal.command(name="build", about="Build project")
@angreal.argument(name="verbose", short="v", long="verbose",
is_flag=True, takes_value=False)
def build(verbose=False):
if verbose:
print("Starting build...")
do_build()
if verbose:
print("Build complete!")
@angreal.command(name="check", about="Run checks")
@angreal.argument(name="quiet", short="q", long="quiet",
is_flag=True, takes_value=False)
def check(quiet=False):
issues = run_checks()
if not issues:
if not quiet:
print("All checks passed!")
return 0
if not quiet:
for issue in issues:
print(f" - {issue}")
return 1
import angreal
import shutil
import os
@angreal.command(name="clean", about="Clean build artifacts")
@angreal.argument(name="dry_run", short="n", long="dry-run",
is_flag=True, takes_value=False)
def clean(dry_run=False):
project_root = angreal.get_root().parent
targets = ["dist/", "build/", ".cache/"]
for target in targets:
path = project_root / target
if path.exists():
if dry_run:
print(f"Would remove: {path}")
else:
print(f"Removing: {path}")
shutil.rmtree(path)
if dry_run:
print("\nDry run - no changes made.")
@angreal.command(name="test", about="Run tests")
def test():
tests = discover_tests()
for i, test in enumerate(tests, 1):
print(f"[{i}/{len(tests)}] Running {test}...")
run_test(test)
print("All tests complete!")
import subprocess
import angreal
def run_in_project(cmd, **kwargs):
"""Run command in project root."""
project_root = angreal.get_root().parent
defaults = {
"cwd": project_root,
"capture_output": True,
"text": True
}
defaults.update(kwargs)
return subprocess.run(cmd, **defaults)
@angreal.command(name="test", about="Run tests")
def test():
project_root = angreal.get_root().parent
process = subprocess.Popen(
["pytest", "-v"],
cwd=project_root,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True
)
for line in process.stdout:
print(line, end="")
return process.wait()
def run_or_fail(cmd, error_msg):
"""Run command, exit on failure."""
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
print(f"Error: {error_msg}")
if result.stderr:
print(result.stderr)
return 1
return 0
@angreal.command(name="deploy", about="Deploy application")
def deploy():
# Check all prerequisites first
if not check_credentials():
print("Error: Missing credentials")
return 1
if not check_build_exists():
print("Error: No build. Run 'angreal build' first.")
return 1
# Only proceed if everything ready
do_deploy()
return 0
def validate_env(env):
valid = ["development", "staging", "production"]
if env not in valid:
print(f"Error: Invalid environment '{env}'")
print(f"Valid options: {', '.join(valid)}")
return False
return True
import os
@angreal.command(name="deploy", about="Deploy")
def deploy():
required = ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"]
missing = [v for v in required if not os.environ.get(v)]
if missing:
print("Error: Missing environment variables:")
for var in missing:
print(f" - {var}")
return 1
do_deploy()
return 0
| Layer | Audience | Location |
|---|---|---|
about | CLI users | --help output |
long_about | CLI users | Detailed help |
help (args) | CLI users | Argument help |
ToolDescription | AI agents | angreal tree --long |
| Docstrings | Developers | Source code |
@angreal.command(
name="deploy",
about="Deploy to environment", # Short for listings
long_about="""
Deploy the application to a specified environment.
Handles: building, uploading, migrations, health checks.
Supported environments: development, staging, production
""", # Detailed for --help
tool=angreal.ToolDescription("""
Deploy application to environment.
## When to use
- After tests pass
- When release is approved
## Examples
```
angreal deploy --env staging
```
""", risk_level="destructive") # For AI agents
)
def deploy():
"""Deploy application. (For developers reading code)"""
pass
# Bad
config = open("/Users/me/project/config.yaml")
# Good
project_root = angreal.get_root().parent
config = open(project_root / "config.yaml")
# Bad
subprocess.run(["npm", "install"])
subprocess.run(["npm", "test"]) # Runs even if install failed
# Good
result = subprocess.run(["npm", "install"])
if result.returncode != 0:
return 1
subprocess.run(["npm", "test"])
# Bad
try:
do_something()
except:
pass
# Good
try:
do_something()
except SpecificError as e:
print(f"Error: {e}")
return 1
# Bad - breaks CI/automation
name = input("Enter name: ")
# Good - use arguments
@angreal.argument(name="name", long="name", required=True)
def cmd(name):
pass
These imports only resolve when .angreal/ is on sys.path (Angreal puts it there during task execution, but pytest does not — see the pytest.ini snippet below to make tests work the same way):
from task_test import test_all
from task_lint import lint_check
@angreal.command(name="ci", about="Run CI pipeline")
def ci():
print("Running linter...")
if lint_check() != 0:
return 1
print("Running tests...")
if test_all() != 0:
return 1
print("CI passed!")
return 0
[pytest]
testpaths = tests
pythonpath = .angreal
markers =
unit: Unit tests
integration: Integration tests
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub angreal/angreal --plugin angreal10 skills in this plugin
/angreal-argumentsThis skill should be used when the user asks to "add arguments to a task", "use @angreal.argument", "add flags to command", "add -v flag to angreal task", "make argument required", "add optional parameter", "use python_type", "handle multiple values", "argparse for angreal task", "angreal cli args", or needs guidance on the @argument decorator, argument types, flags, default values, or CLI argument handling in angreal tasks./angreal-authoringThis skill should be used when the user asks to "create an angreal task", "write a task file", "add a command to angreal", "make a new task", "organize tasks with groups", "use @angreal.command", "use command_group", "use angreal.group decorator", "add long_about to a task", "require an angreal version", "same command name in different groups", or needs guidance on task file structure, the @command decorator, command groups (`command_group` and `@group(...)`), `required_version()`, naming conventions, or task organization within an existing angreal project./angreal-initThis skill should be used when the user asks to "create an angreal project", "initialize angreal", "set up angreal", "add angreal to project", "start new angreal project", "create .angreal directory", "scaffold into existing project", "angreal init --in-place", "add angreal to existing repo", or needs guidance on setting up angreal in a new or existing project (hand-rolled `.angreal/` or via an official template), or the initial task file structure./angreal-integrationsThis skill should be used when the user asks to "use Git in a task", "manage virtual environments", "use Docker Compose", "use the Docker class", "run docker container from task", "list docker containers in angreal", "clone a repository", "create a venv", "run docker-compose", "use angreal.integrations", "render a template", "scaffold files", "generate files from template", "use render_template", "use render_directory", "use Flox", "flox environment", "cross-language environment", "flox services", "@flox_required", or needs guidance on the built-in Git, VirtualEnv, Docker (compose or low-level client), Flox, or Tera templating integrations available in angreal tasks./angreal-mcpThis skill should be used when the user asks to "start the angreal mcp server", "expose angreal tasks to Claude / Cursor / an AI agent", "configure .mcp.json for angreal", "set up MCP for my angreal project", "connect angreal to an AI assistant", "what does angreal mcp do", "AI agent integration with angreal", or needs guidance on the built-in Model Context Protocol server (`angreal mcp`), what it exposes, how MCP clients should be configured to connect to it, and how `ToolDescription` and `risk_level` flow into agent context./angreal-pre-commitThis skill should be used when the user asks to "add a pre-commit hook for angreal", "run angreal tasks before commit", "run angreal on pre-push", "set up pre-commit for tests/lint", "configure .pre-commit-config.yaml for angreal", "make tests run automatically before commit", or needs guidance on wiring [pre-commit](https://pre-commit.com/) to invoke angreal tasks (test, lint, format, etc.) at git lifecycle stages.Other plugins' skills for the same job