Skip to content

chore: add write-codemod skill for create-plugin codemods - #2782

Merged
jackw merged 2 commits into
mainfrom
jackw/add-write-codemod-skill
Jul 16, 2026
Merged

chore: add write-codemod skill for create-plugin codemods#2782
jackw merged 2 commits into
mainfrom
jackw/add-write-codemod-skill

Conversation

@jackw

@jackw jackw commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

What this PR does

Adds a write-codemod Claude Code skill at .claude/skills/write-codemod/, alongside the existing bump-plugin-e2e and diagnose-plugin-e2e-incompatibility skills, so every contributor working with an AI agent gets it automatically. It originated as a private skill that has been producing good results; this version is restructured and expanded for shared use.

The skill teaches an agent how to author codemods for packages/create-plugin/src/codemods/:

  • The migration vs. addition decision, registration conventions, and the version-gating rule (.config/.cprc.json, next-patch versioning)
  • The runner.ts execution pipeline and the reasoning behind the core rules (Context-only file access, graceful degradation, idempotency)
  • CLI flags via valibot schema exports, debug logging, and renderTemplate for scaffolding files from the templates
  • A workflow for deriving a migration from an already-made change to templates/ (path mapping, Handlebars rendering, divergent user files)
  • Testing requirements including the toBeIdempotent matcher, and local verification steps

Detailed per-format manipulation patterns (JSON/JSONC, TypeScript AST via recast, YAML) live in references/ files that agents load only when relevant, keeping the main skill lean.

All API signatures and behaviours described in the skill were verified against the current source.

🤖 Generated with Claude Code

@jackw
jackw requested review from a team as code owners July 15, 2026 10:36
@jackw
jackw removed the request for review from a team July 15, 2026 10:36
@jackw
jackw requested review from Ukochka, ashharrison90, joshhunt, leventebalogh and toddtreece and removed request for a team July 15, 2026 10:36
@grafana-catalog-project-bot grafana-catalog-project-bot Bot moved this from 📬 Triage to 🔬 In review in Grafana Catalog Team Jul 15, 2026
leventebalogh
leventebalogh previously approved these changes Jul 15, 2026

@leventebalogh leventebalogh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Use the `yaml` npm package for structured manipulation of `.yml` / `.yaml` files. Never use string replacement on YAML — it breaks on formatting and comment differences.

```ts
import { parseDocument, stringify, visit, YAMLMap, YAMLSeq, Scalar, Pair, type Document } from 'yaml';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am wrong here, but looks like type Document is not used in the examples below? Maybe import type visitorFn instead (line 47)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct as ever @leventebalogh . Fixed in d417541

@jackw
jackw merged commit 931e1e1 into main Jul 16, 2026
29 checks passed
@jackw
jackw deleted the jackw/add-write-codemod-skill branch July 16, 2026 08:01
@github-project-automation github-project-automation Bot moved this from 🔬 In review to 🚀 Shipped in Grafana Catalog Team Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants