agentleFS
LNSDLNSD/lorecraft/.agents/skills/code-gen/SKILL.md

code-gen

Skill0 starsChanged 16 days agoApache-2.0View on GitHub

Regenerate the committed generated files, such as the JSON Schemas under docs/schemas/, the rulebook pages under docs/rulebook/ and the rule index under src/lorecraft/rules/index.py, after changing the package types or the rule declarations and docstrings they are rendered from, or a gen-* recipe in the justfile or a generator in gen/src/lorecraft_gen/. Use after editing such a type, recipe or generator, before running tests or committing, or when CI's `gen-check` job fails with "Generated code is out of date". Not for formatting or linting; see /code-format and /code-check.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Run just gen when a change touches:

    line 18
  2. Very specific:

    Run it after /code-format and /code-check, and before /code-test: the schema tests read the committed schemas, so a stale one fails them …

    line 79

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Generation Skill

Some files in this repository are generated and committed: the JSON Schemas under docs/schemas/, which editors validate the spec files against, the rulebook pages under docs/rulebook/, one per rule code, and the rule index, src/lorecraft/rules/index.py, the identity of every rule as strings and tuples. Each is rendered from what the package declares, so a change to it leaves the committed file stale until it is regenerated.

When to Run

Run just gen when a change touches:

  • A type a generator imports. The generators are the modules of the private lorecraft_gen package in gen/src/lorecraft_gen/, each run by a gen-* recipe of the justfile, which installs it on the fly: just sync does not. A generator imports what it renders from the packages, so its imports are its inputs:

    grep -nE '^from lorecraft[. ]' gen/src/lorecraft_gen/*.py

    A change to a module those lines import, or to anything that module's types are built from, changes the output. Their field docstrings and their SchemaInfo metadata are rendered too, so a reworded docstring is a change to the output.

  • A rule. The rulebook generator renders every rule's class: its code, name, release and aliases, and the sections of its docstring. A new, renamed or removed rule, or a reworded docstring, changes a page. The rule index, written by its own generator, records each rule's code, name, kind, level or severity, aliases and group, so a change to any of them changes it too.
  • A generator or its recipe itself: a module of gen/src/lorecraft_gen/, or a gen-* recipe.

Nothing else needs it. When unsure, run it: a generator with nothing to change leaves the tree as it was.

Commands

just sync   # first, when the environment may be stale: the generators import the package
just gen    # every generator; `just gen-schemas`, `just gen-rulebook` and `just gen-rule-index` run one alone

Then look at what changed, and read the diff as a review of the change that caused it:

git status --short docs/schemas docs/rulebook src/lorecraft/rules/index.py
git diff docs/schemas docs/rulebook src/lorecraft/rules/index.py

A description that reads badly in the diff reads badly in an editor too: fix the docstring, not the output. A rulebook page is generated output too: fix its rule's docstring and regenerate, never the page. No spec governs the pages, so just check-docs does not read them; gen-check keeps them current.

Rules

  • Commit the output with the change that caused it. CI's gen-check job runs just gen and fails on any difference from the committed tree, a new file included.
  • Never edit a generated file by hand. The next just gen undoes it, and CI rejects it before that.
  • A generator restates nothing. It imports the types it renders; a field, a description or an example written into a generator is a second copy that drifts. Add it to the package's type instead.
  • Generation code lives in lorecraft_gen, never in lorecraft. A recipe is one uv run --with-editable ./gen python -m lorecraft_gen.<module> --outdir <dir> line, where the justfile variable names the directory and the module keeps the same path as the default of --outdir. Nothing in lorecraft imports the generators, so none ships in the wheel. The package's responsibility is docs/code/package-lorecraft-gen.md.
  • A generator carries no tests. The check on a generator is just gen leaving the tree clean, which CI's gen-check job enforces. Ruff and ty cover gen/; pytest and coverage do not.
  • A schema is rendered from the model that validates the file. The package deserializes each file with the same pydantic model the generator renders, so the schema an editor applies and the check's validation cannot disagree about a shape. A test beside each model, such as tests/it/test_structure_spec_schema.py, holds the committed schema to every file this repository writes. When it fails, fix the model or the file. Never loosen the test.

Where It Fits

Run it after /code-format and /code-check, and before /code-test: the schema tests read the committed schemas, so a stale one fails them for a reason that has nothing to do with the code under test.

Common Mistakes to Avoid

  • Fixing a failed gen-check job by hand-editing the file to match what CI printed. Run just gen.
  • Running a generator's code another way, such as a copy of it in a scratch script. The recipe is the one place that writes the output, and the one CI checks.
  • Adding a generator to lorecraft because it is the package that holds the types. Add a module to lorecraft_gen and a gen-* recipe that runs it.

Next Steps

After regenerating:

  1. Run targeted tests → use /code-test; the schema tests are in the integration tier, just test-it
  2. Commit the generated files with the change → use /commit

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.