SuperAPI AI Directory

mir-extract-snippet

General & other

View repository

Updated 10-16 08:48

About this skill

extract-snippet

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

  1. Confirm with the user the range of code they want to extract as a snippet
    • Target files/directories
    • Snippet name
    • Snippet purpose/description
  2. Exhaustively search the entire project for the specified source code
    • Also collect related files (type definitions, tests, config files, etc.)
  3. 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)
  4. .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-mir guide the skill)
  5. mir create <name> Create the snippet template with
    npx mir create <name>
    
  6. 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.)
  7. .mir/snippets/<name>.yaml Write 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
  8. 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
      #
      # 設計メモ
      # - コンポーネント名を変数化して再利用可能にした
      
  9. mir sync <name> Synchronize variable definitions with
    npx mir sync <name>
    
  10. 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-]*$)