How to Regenerate the GPT-Image-2 Agent Skill Markdown from style-library.json

Regenerate the agent skill Markdown by running node scripts/generate-style-skill.mjs, which validates data/style-library.json and outputs agents/skills/gpt-image-2-style-library/references/style-library.md.

The freestylefly/awesome-gpt-image-2 repository manages prompt-template metadata in a centralized JSON file. When you modify templates, categories, styles, or scenes, you must regenerate the agent skill Markdown to keep the GPT-Image-2 agent's knowledge base synchronized. This guide explains the complete regeneration workflow based on the actual source code implementation.

The Regeneration Pipeline

The script scripts/generate-style-skill.mjs orchestrates a five-step pipeline to transform JSON data into structured Markdown.

Step 1: Load Source Files

The script reads two critical inputs:

  • data/style-library.json — The master data store containing templates, categories, styles, and scenes
  • docs/templates.md — The template documentation file containing HTML anchors referenced by templates
// Line 11-13: Load the JSON library
const library = await readJson(libraryFile);

// Line 38: Load templates.md for anchor validation
const templatesContent = readFileSync(templatesFile, 'utf-8');

Step 2: Validate Data Integrity

The validateLibrary() function (lines 37-74) enforces three critical constraints:

Validation Purpose Implementation
Unique IDs Prevent duplicate template identifiers assertUnique() helper
Anchor existence Ensure every template's anchor appears in templates.md String search against loaded content
Cover image presence Verify referenced image files exist on disk existsSync() filesystem checks

The script also runs assertNoPattern to block a specific Chinese contrast pattern, ensuring content safety before generation.

Step 3: Render Markdown Content

The renderReference() function (lines 94-162) builds the output using formatter helpers:

  • label() — Formats field names with translations
  • list() — Renders comma-separated values
  • bulletList() — Creates bulleted guidance and pitfalls lists

The generated Markdown includes:

  • Library header and description
  • Selection Rules cheat-sheet for template selection
  • Template Index with complete metadata (ID, category, styles, scenes, tags, cover, source link, example cases, usage notes, guidance, pitfalls)
  • Summarized Categories, Styles, and Scenes with bilingual titles

Step 4: Write Output File

The script creates the target directory if needed and writes the final Markdown:

// Lines 67-68: Ensure directory exists and write output
mkdirSync(dirname(referenceFile), { recursive: true });
writeFileSync(referenceFile, reference);

Step 5: Confirm Completion

Line 69 prints the output path for verification:

console.log(`✅ Generated: ${referenceFile}`);

Running the Regeneration Command

Execute the script from the repository root:

node scripts/generate-style-skill.mjs

Success Output


✅ Generated: agents/skills/gpt-image-2-style-library/references/style-library.md

Failure Modes

The script aborts with descriptive errors when validation fails:


# Duplicate template cover image

Error: template cover is duplicated: /images/case17.jpg

# Missing template anchor in templates.md

Error: template anchor not found: tpl-nonexistent

# Missing cover image file

Error: cover image not found: /images/missing.jpg

Fix the underlying issue in data/style-library.json or docs/templates.md, then re-run the command.

When to Regenerate the Agent Skill

Trigger regeneration after any of these changes to maintain synchronization:

  • Template modifications — Adding, removing, or editing entries in data/style-library.json
  • Category/Style/Scene updates — Renaming or restructuring the taxonomy
  • Anchor changes — Moving or renaming template anchors in docs/templates.md
  • Asset updates — Changing cover image paths or adding new images under data/images/

Skipping regeneration causes the agent to reference stale template metadata, leading to incorrect prompt suggestions.

Practical Examples

Adding a New Template

Append to data/style-library.json:

{
  "id": "new-template",
  "anchor": "tpl-new",
  "cover": "/images/case999.jpg",
  "title": { "en": "New Template", "zh": "新模板" },
  "description": { "en": "A fresh template for …", "zh": "一个新模板,用于…" },
  "category": "UI & Interfaces",
  "styles": ["UI"],
  "scenes": ["Tech"],
  "tags": ["UI", "New"],
  "useWhen": {
    "en": "Use when you need a …",
    "zh": "当需要 … 时使用"
  },
  "guidance": {
    "en": ["Lock platform", "Define layout"],
    "zh": ["锁定平台", "定义布局"]
  },
  "pitfalls": {
    "en": ["Avoid vague wording"],
    "zh": ["避免模糊描述"]
  },
  "exampleCases": [999]
}

Then regenerate:

node scripts/generate-style-skill.mjs

The new template appears automatically in the Template Index section.

Resolving a Validation Error

If you reuse a cover image path:

node scripts/generate-style-skill.mjs

# → Error: template cover is duplicated: /images/case17.jpg

Update the duplicate entry to reference a unique image path, then re-run the script.

Key Files and Their Roles

File Purpose Location
data/style-library.json Master data store for all template metadata Repository root
docs/templates.md Template documentation with HTML anchors /docs/
scripts/generate-style-skill.mjs Regeneration script with validation and rendering logic /scripts/
agents/skills/gpt-image-2-style-library/references/style-library.md Generated agent skill Markdown (output) Auto-created path

Summary

  • Single-command regeneration — Run node scripts/generate-style-skill.mjs to rebuild the agent skill
  • Strict validation — The script enforces unique IDs, valid anchors, and existing cover images before generating output
  • Automatic formatting — Bilingual content renders with consistent structure using helper functions label(), list(), and bulletList()
  • Failure prevention — Clear error messages pinpoint exactly which validation check failed
  • Synchronization requirement — Regenerate after every modification to data/style-library.json, docs/templates.md, or cover images

Frequently Asked Questions

What happens if I forget to regenerate after editing style-library.json?

The GPT-Image-2 agent continues using the stale skill Markdown, causing it to suggest templates with outdated metadata, missing new entries, or referencing removed templates. Always regenerate immediately after any JSON changes.

Can I run the script if templates.md has syntax errors?

Yes, but validation will fail if template anchors are missing or malformed. The script checks that every template's anchor value exists as an <a name="..."></a> tag in templates.md. Fix the anchor reference or the templates.md file before retrying.

How does the script handle bilingual content?

The renderReference() function iterates over nested objects with en and zh keys, using the label() helper to format both languages side-by-side. All titled sections include English and Chinese variants automatically.

What validation ensures content safety before generation?

The assertNoPattern function scans all text fields for a specific Chinese contrast pattern that could cause rendering issues. If detected, the script aborts with an error, preventing problematic content from reaching the generated skill.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →