tonyandrewmeyer/charming-with-claude/action-classes

Claude Code and agent skill by tonyandrewmeyer/charming-with-claude

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Install

npx vskill@latest install tonyandrewmeyer/charming-with-claude/action-classes

SKILL.md

The same SKILL.md was published earlier as tonyandrewmeyer/charming-with-claude/action-classes.

Skill: Adopt Action Classes

Replace raw event.params dictionary access with typed Python classes using ActionEvent.load_params().

When to Use

Use this when a charm has actions with parameters accessed via event.params["key"] or event.params.get("key").

Prerequisites

  • ops >= 2.23.0
  • The charm has actions defined in charmcraft.yaml (or actions.yaml)

Step 1: Audit Current Action Usage

  1. Read the charm's action definitions to understand all actions and their parameters.
  2. Search charm code for action handlers (methods observing self.on.*_action).
  3. For each handler, note how event.params is accessed and any manual validation.

Step 2: Define Action Parameter Classes

Create a class for each action's parameters. Use @dataclasses.dataclass(frozen=True, kw_only=True).

python
import dataclasses
@dataclasses.dataclass(frozen=True, kw_only=True)
class BackupParams:
"""Parameters for the backup action."""
target: str = "/data"
compress: bool = True
max_size: int = 0

Or with Pydantic for richer validation:

python
import pydantic
class BackupParams(pydantic.BaseModel):
target: str = pydantic.Field(default="/data", description="Backup target path.")
compress: bool = True
max_size: int = pydantic.Field(default=0, ge=0, description="Max size in MB.")
Field Naming

Same rules as config: dashes become underscores automatically. Use aliases for exceptions.

Where to Put Them

For charms with several actions, create a separate src/action_types.py module. For one or two simple actions, inline in the charm module is fine.

Step 3: Update Action Handlers

python
# Before:
def _on_backup_action(self, event: ops.ActionEvent):
target = event.params.get("target", "/data")
compress = event.params.get("compress", True)
if not target.startswith("/"):
event.fail("Target must be an absolute path")
return
# ...
# After:
def _on_backup_action(self, event: ops.ActionEvent):
params = event.load_params(BackupParams, errors="fail")
# params is None if validation failed (event.fail() already called)
# ...use params.target, params.compress, params.max_size...

Key: always use errors="fail" for actions. This automatically calls event.fail() with the validation error message if parameters are invalid.

Step 4: Update Tests

Action tests that set params via the testing framework should continue to work:

python
def test_backup_action():
ctx = testing.Context(MyCharm)
state_out = ctx.run(
ctx.on.action("backup", params={"target": "/data", "compress": True}),
testing.State(),
)

Step 5: Verify

  1. Run linting and unit tests.
  2. Check that juju run <unit> <action> --param key=value still works as expected.

Exemplar Charms

  • [ubuntu-autopkgtest-operators](https://github.com/canonical/ubuntu-autopkgtest-operators) (charms/autopkgtest-dispatcher-operator) — Pydantic with Field(description=), Enum types, errors="fail". Separate src/action_types.py.
  • [canonical/operator](https://github.com/canonical/operator) (examples/k8s-4-action) — Official tutorial example with dataclasses.

Common Mistakes

  • Don't forget errors="fail" — the default errors="raise" will cause an unhandled exception.
  • Don't add params classes for actions that take no parameters.
  • Don't change action result keys or formats — only the input parameter handling is changing.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
3
7-day trend score
0

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/tonyandrewmeyer/charming-with-claude/action-classes/badge)](https://verified-skill.com/skills/tonyandrewmeyer/charming-with-claude/action-classes)

Something wrong with this skill or its page? Tell us.