A skill to create a new snippet from existing project code.
Trigger
Use this when the user wants to extract a snippet from existing code, such as "I want to turn this code into a snippet" or "I want to templatize it".
Procedure
- Confirm with the user the range of code they want to extract as a snippet
- Target files/directories
- Snippet name
- Snippet purpose/description
- Exhaustively search the entire project for the specified source code
- Also collect related files (type definitions, tests, config files, etc.)
- Identify project-specific information and either extract it as variables or delete it
- Project name, package name →
{{ project-name }}Replace with variables such as - Specific paths, URLs → convert to variables
- Hardcoded config values → convert to variables (set the default value to the original value)
- Project name, package name →
.mir/Confirm with the user the management policy for :- Share with the team:
.mir/Include in git - Use only for yourself:
.mir/Do not include in git (private-mirguide the skill)
- Share with the team:
mir create <name>Create the snippet template withnpx mir create <name>- Place the template file in
.mir/snippets/<name>/place in- Replace variable parts using Handlebars template syntax
- Use variables in file names as well (e.g.,
{{ kebabCase name }}.ts) - Use template helpers (camelCase, pascalCase, kebabCase, etc.)
.mir/snippets/<name>.yamlWrite the variable definitions in- Set description, schema (type, default, enum), and suggests for each variable
- For values derived from other variables, use a template expression as the default (e.g.,
default: "{{ replace packageDir '/' '.' }}") - Available helpers: lowercase, uppercase, capitalize, uncapitalize, camelCase, pascalCase, snakeCase, kebabCase, dotCase, pathCase, replace, concat, slice, trim, contains, startsWith, endsWith, length
- Add a maintenance comment at the end of the snippet definition YAML
- Record the original file path for each template file
- Leave the intent of the snippet and the background of design decisions
- Example:
# 参考にしたファイル # <name>/component.tsx ... from src/components/Button.tsx # <name>/styles.css ... from src/styles/button.css # # 設計メモ # - コンポーネント名を変数化して再利用可能にした
mir sync <name>Synchronize variable definitions withnpx mir sync <name>- Operation check: install into a temporary directory and verify the expanded result
npx mir install <name> --out-dir=/tmp/mir-test-<name>
Notes
- Always convert project-specific import paths and module names into variables
- Use template helpers to automate naming convention conversion
- Keep the original code in a working state (the generated code must be able to build and run as-is)
- The snippet name may contain only alphanumeric characters and hyphens (
^[a-zA-Z0-9][a-zA-Z0-9-]*$)