Skip to content

Latest commit

 

History

History
305 lines (239 loc) · 13.8 KB

README.md

File metadata and controls

305 lines (239 loc) · 13.8 KB

Skill classes

A class is a set of rules, files and checks that many skills share. Each class is written once, here in classes/, and copied into every skill that joins it. This page explains how the system works today, for a contributor who wants to change a class or add a skill to one. It ends with a worked example.

The reasons behind the design are in ADR 0005 and in the Classes section of the skill design. This page does not repeat them.

What a class is

A class is one folder, classes/<name>/. Only class.yaml is required.

Path What it holds Copied into members?
class.yaml The class's name, parents, checks and hooks No
rules.md The class's rules, one - **<id>**: <text> line each Yes, into the SKILL.md marker block
references/ Markdown files only (.md) Yes, as references/<class>-<file>.md
scripts/ Flat .py and .sh files only Yes, as scripts/<class_with_underscores>_<file>
checks/ Check scripts that CI runs on each member No: CI runs them from classes/
hooks/ Plugin hook scripts and their test fixtures No: the hook scripts go to the plugin instead
evals/ Model-backed eval sets No: the eval runners read them from classes/
tests/ Test cases for the class's own scripts No

A class lists no members. A skill joins a class from its own SKILL.md.

How a skill joins a class

A skill names its classes in its frontmatter, as a space-separated string of class folder names:

metadata:
  apex-classes: "service-eks script"

Name leaf classes only. The sync refuses a class listed beside one of its own parents, and a class that is not under classes/. It also refuses a metadata key that is a near miss of apex-classes, so a typo does not leave the skill silently outside every class. A skill with no apex-classes line is not a member, and the sync never writes into it. No skill is a member today: each skill joins in its own pull request. A new skill picks its classes in the add-a-skill steps (Contributing, Creating a New Skill).

Parents and the chain

Each class.yaml names its parents. For each member the sync resolves the chain: every class the skill declares and all their parents, parents first, each class once. It uses the C3 order, reversed. A skill that declares script gets apex-base, platform, operator, script.

The sync fails on a cycle, on a parent order that contradicts the parents' own order, and on two classes in one chain that give the same rule id or the same copied file path. These class-text checks run on every class in both modes, whether or not any skill is a member, so a clash inside one class's chain is found today. A clash between two classes that no chain joins is found only when a skill declares both.

What the class sync copies

The sync is misc/sync-classes.py. Its docstring is the full contract; this is the short form. For each member skill it:

  1. Writes one marker block into SKILL.md, right after the frontmatter, between <!-- APEX_CLASSES_START --> and <!-- APEX_CLASSES_END -->. The block holds each chain class's rules.md, in chain order, each headed <!-- generated from classes/<class>/rules.md, do not edit -->. A class with no rules.md adds nothing.
  2. Copies each class reference to references/<class>-<file>.md. A file already named <class>-... keeps its name, and a file in a subfolder is flattened (a/b.md becomes <class>-a-b.md).
  3. Copies each class script to scripts/<class>_<file>, with - in the class name as _. A file that already carries the prefix keeps its name. It rewrites imports and source lines between class scripts to the flat names, and refuses an import it cannot rewrite safely.
  4. Heads every copy "generated from classes//, do not edit".

It also fails when copied class text points into the router skill's folder or names its slash command; a rule id such as apex.mcp-first is a label and passes. Copies are written without the execute bit, so run a class script with python3 or bash.

The sync also writes the plugin hook files. Each hooks: entry's script is copied once to plugins/apex/hooks/<class>/<hook>/<file>.py. Every entry is written into plugins/apex/hooks/hooks.json (Claude Code and Codex) and plugins/apex/kiro/apex-hooks.json (Kiro). See hooks and Hook switches below.

--check

python3 misc/sync-classes.py           # write the copies
python3 misc/sync-classes.py --check   # write nothing; exit 1 on any difference

--check builds every expected file in memory and compares it with the file on disk. It prints each difference and exits 1 on any: a missing copy, a hand edit, a stale marker block, a wrong header, or a plugin hook file that does not match the hooks: entries. It also fails on a hooks key in the plugin manifests. CI runs it in .github/workflows/class-sync.yml. Write mode runs every check before it writes anything, so a refusal leaves the tree as it was.

--check does not find orphans: a copy whose class file was removed or renamed, or the copies left in a skill that drops apex-classes. Delete those by hand.

class.yaml keys

The sync reads name, parents and hooks. The check runner reads parents and checks. class.schema.json refuses any key it does not list, at the top level and inside every entry, and CI runs it. Three class.yaml files break it today, the known gaps misc/tests/test_class_validators.py lists: the four keys under "Keys for one class" below, and a service-eks check with status exists and no run.

Key Read by Shape
name sync Must equal the folder name
parents sync, runner A list of class names, each a folder under classes/
checks runner A list of check entries (below)
hooks sync A list of hook entries (below)
data no tool yet A mapping of class facts for tools other than the sync; no class uses it today

checks

Each entry is one deterministic check that steward/scripts/run_checks.py runs on each member skill.

Field Meaning
id The check's name in the output
what What it checks, in one sentence
status exists (built) or planned (not built yet, never counted as a pass)
run For exists: the command, run from the repo root with the skill folder appended as the last argument
timeout Optional seconds; the comment block in apex-base/class.yaml gives the default and the cap

Exit 0 is a pass and exit 1 with a FAIL line is a fail. Any other exit, an exit 1 with no FAIL line, or a timeout is an error. An exists entry with no run string is an error too. Each check prints lines of the form <CHECK-ID> <PASS|FAIL> <path> <reason>.

hooks

Each entry is one opt-in hook for the APEX plugin. The comment block in apex-base/class.yaml describes the fields; the sync's hook_entries function enforces them.

Field Meaning
id Stable key: the rule it backs (the Stop gate's id names the hook; it backs two rules), and its switch
what What it blocks or asks
event The hook event, such as PreToolUse or Stop
script hooks/<hook>/<file>.py, or ../<class>/hooks/<hook>/<file>.py for another class's script
mode One of the script's own --mode choices, read from its source
enabled true or false; every entry ships false
matchers One tool-name pattern each for claude-code, codex and kiro; the first two must be equal. Not used for Stop
kiro_timeout Optional whole seconds; class.schema.json gives the floor
title Required: the switch's label
description Required: the switch's text

The sync refuses a duplicate id, two ids with one switch key, and two entries with the same event, script and mode. The script must have one --id argument that is not required.

Keys for one class

These four keys are known gaps: the schema refuses them.

Class Key What it is
apex-base evals A record of the class's model-backed evals, same fields as checks. No runner reads it yet
steward generators Each repo generator's run and check command, with a status and an optional note
steward hand_kept Files kept by hand, not generated
steward add_a_skill Where the add-a-skill steps live

The class tree

Each class's parents and purpose are in its own classes/<name>/class.yaml (parents, and the comment at the top).

Checks and tests

run_checks.py finds every skill under skills/ and devops-agent/ whose frontmatter names classes. It walks each member's chain and runs every checks: entry. It never stops at the first fail. Then it prints <n> checks on <m> skills, <f> failed, <e> errors and runs the hook tests.

python3 classes/steward/scripts/run_checks.py                     # every member, then the hook tests
python3 classes/steward/scripts/run_checks.py --report apex-base  # as if every skill were a member; exits 0
python3 classes/steward/scripts/run_checks.py --self-test         # cases in steward/tests/cases.json

The apex-base checks live in apex-base/checks/, one script per check. CI runs all three commands in .github/workflows/class-checks.yml.

Hook tests

steward/scripts/run_hook_tests.py feeds fixture events to each class hook script. A fixture is classes/<class>/hooks/<hook>/tests/<harness>-<case>.event.json, with <harness>-<case>.expected.json beside it; <harness> is claude-code, codex or kiro. The expected file needs an exit code and may give a decision (block, none or ask), stderr_contains, stdout_contains, args, env and timeout. The runner drops every CLAUDE_PLUGIN_OPTION_* variable before it sets env, so each fixture states its own switch.

The Script class's Stop gate and token-tag hooks also have pytest tests under script/hooks/*/tests/. CI runs them, with misc/tests/test_class_validators.py, in .github/workflows/class-validators.yml. The sync's own tests are misc/tests/test_sync_classes.py.

Hook switches

Every hook ships off. The comment block above hooks: in apex-base/class.yaml gives the switch rule for each harness and what a PreToolUse hook does with a value other than true or false. The Stop gate ends the turn on such a value (exit 3, its stop_gate.py docstring).

The userConfig booleans in plugin.json are kept by hand. A new hook entry needs its boolean added there, or Claude Code shows no switch for it; --check does not compare them.

The class language

The class format is being written down as a standard, so that every class reads the same way and a tool can check it. The JSON Schema for class.yaml sits at classes/class.schema.json, checked by misc/tests/test_class_validators.py. Until the standard is complete, the code named on this page is the reference.

Worked example: add a rule to a class

Say the Script class needs a new rule: a script exits non-zero when it fails.

1. Pick the id. A rule line is - **<class>.<rule>**: <text>, one line, in the class's rules.md. The sync reads any id with no space or * (misc/sync-classes.py, RULE_LINE). The apex-base check reads apex-base ids in a stricter shape (apex-base/checks/ab-rule.py). Write every id in that stricter shape: lower case, digits and hyphens, a prefix, a dot, a name. By convention the prefix is the class name (apex-base uses apex); no check enforces the prefix today. A line that does not start - **<id>**: is not read as a rule at all.

The id must be new in every chain that holds the class. List the ids in Script's chain:

grep -h '^- \*\*' classes/apex-base/rules.md classes/operator/rules.md classes/script/rules.md

2. Add the line. Append to script/rules.md:

- **script.exit-on-failure**: The skill's scripts exit non-zero when they fail, and name the failure on stderr.

3. Run the sync, then check it.

python3 misc/sync-classes.py
python3 misc/sync-classes.py --check

The class-text checks run first, on every class. A duplicate id fails both commands with duplicate rule id <id> from classes/<a> and classes/<b>, and nothing is written. With no members today, the write prints sync-classes: 0 member skill(s) (none), 0 file(s) changed. Commit the class change and every regenerated copy in one pull request; never edit a copy by hand, since --check reports it as a hand edit.

4. What a member gets. A skill that declares apex-classes: "script" gets this block after its frontmatter, with the new line at the end of the Script part (platform has no rules.md, so it adds nothing):

<!-- APEX_CLASSES_START -->
<!-- generated from classes/apex-base/rules.md, do not edit -->
...

<!-- generated from classes/operator/rules.md, do not edit -->
...

<!-- generated from classes/script/rules.md, do not edit -->
...
- **script.exit-on-failure**: The skill's scripts exit non-zero when they fail, and name the failure on stderr.
<!-- APEX_CLASSES_END -->

The member's SKILL.md changed, so raise its metadata.version: the apex-base check metadata-version-bumped fails otherwise.

5. Back the rule, if you can. A written rule is the floor. If a script can check it, add a checks: entry to script/class.yaml (start it as status: planned until the check is built). If a hook can enforce it, add a hooks: entry whose id is the rule id, its fixtures under hooks/<hook>/tests/, and its userConfig boolean in plugin.json.