# The agent skills

> Install the three bundled agent skills, see what they do, and use their scripts and the guard hook.

The `editlet` package ships three agent skills for Claude Code and other agents that read `.agents/skills/`.

| Skill | Use it to |
|---|---|
| `editlet` | Edit content and the schema, validate, show changes in `?editlet`, publish through a pull request |
| `editlet-setup` | Install Editlet in Next.js or Astro, set up the live site, upgrade, find what is broken |
| `editlet-migrate` | Import content from Markdown or MDX folders, Astro collections, Decap, TinaCMS, Keystatic and others |

## Install the skills

Give your agent this prompt in the project:

```text
Install Editlet in this project: add the package `editlet` with the project's package manager, then read
node_modules/editlet/skills/editlet-setup/SKILL.md and follow it.
```

To link the skills by hand, run this from the project root after you install the package:

```bash
node node_modules/editlet/skills/editlet/scripts/link.mjs --hooks
```

It links each skill into `.claude/skills/` and `.agents/skills/` and adds the guard hook to `.claude/settings.json`.
Add `--check` to only report what is missing. In a monorepo, run it where you start Claude Code.

## What the agent does with content

1. It reads `cms/schema.json` and runs `git status`, so it keeps your own edits.
2. It tells you which files it will change, and asks again before it deletes data.
3. It edits, then runs `validate` until it passes. Schema changes get a dry run first.
4. If a dev server runs, it opens the matching `?editlet` screen.
5. When you ask to publish, it commits only its own files on an `editlet/<name>` branch and opens a pull request.
6. It merges only after you approve that pull request in the conversation.

## Run the scripts

Run them with `node .claude/skills/editlet/scripts/<script>` from the project root.

| Script | What it does |
|---|---|
| `validate.mjs` | Checks the schema and every entry, including references and images |
| `types.mjs` | Writes `.editlet/content.d.ts` |
| `style.mjs` | Prints branch names, commit messages and pull requests in your `git` style |
| `schema.mjs` | `json-schema <collection>`, `check <candidate.json>`, `rename-field`, `remove-field` |
| `refs.mjs` | `used-by`, `rename` and `remove` of an entry, with every reference to it |

The commands that rename or remove are dry runs until you add `--apply`.

## Set up and migrate

- Setup lists the files it will change, never writes a secret into a file, and asks before it changes anything
  outside the repo. It does not convert existing content. For roles, see [Roles for admins and editors](https://editlet.gunkin.dev/docs/roles.md).
- A migration shows the field mapping and writes nothing until you say yes. It keeps every field and slug, moves files
  with `git mv` on a `migrate/<source>` branch, and keeps your old CMS config.

## Check a setup

```bash
node .claude/skills/editlet-setup/scripts/doctor.mjs                            # the project
node .claude/skills/editlet-setup/scripts/doctor.mjs --url https://example.com  # also the live site
```

The doctor only reads, never prints a secret, and exits with `1` when a check fails. It checks the wiring, content,
env names and skill links. With `--url` it also checks the live site and the auth handler. With `--url`, or when
the config has `admin`, it checks the repository on GitHub: branch protection and branch deployments.

## The guard hook

The hook checks each Bash command the agent runs:

| Command | Result |
|---|---|
| `git push` to the base branch, `main` or `master`, also `--all`, `--mirror` and deletes | Blocked |
| `git commit` while `validate` fails | Blocked |
| `git commit` of content on a branch outside your prefix | Asks you |
| `gh pr merge --admin`, or a branch protection change with `gh api` | Blocked |
| Any other `gh pr merge` | Asks you |

The hook cannot see commands inside `bash -c "…"` or scripts, so protect the base branch on GitHub too.
