new-pattern
GitHub指导创建符合项目规范的新设计模式文档。涵盖主题验证、源码核实、文档编写(含图表与多语言实现)、代码测试及练习设计,确保内容真实、跨语言且无重复。
Trigger Scenarios
Install
npx skills add Totoro-jam/battle-tested-patterns --skill new-pattern -g -y
SKILL.md
Frontmatter
{
"name": "new-pattern",
"description": "Guided workflow to create a new pattern following the project template and quality standards. Walks through topic validation, source verification, implementation, exercises, challenge questions, and bilingual docs."
}
Create a New Pattern
You are creating a new pattern for battle-tested-patterns. Follow each step in order. Do NOT skip source verification. Reference SOP 01 for the full checklist.
Step 1: Topic Validation
Ask these questions before proceeding:
- What is the pattern name?
- Can you name ≥ 2 production projects that use it (with source links)?
- Is it cross-language (not specific to one language/framework)?
- Is it a code-level technique (not purely architectural)?
- Does it NOT duplicate an existing pattern in
docs/patterns/?
If any answer is "no", stop and explain why this pattern doesn't fit.
Step 2: Source Code Location
For each production project:
- Search the project repo for the exact usage
- Get the GitHub URL with line numbers:
https://github.com/{org}/{repo}/blob/main/{path}#L{start}-L{end} - Verify with
curl -sI <url> | head -1— must return HTTP 200 - Read the code to confirm your understanding
- Write a Production Proof description specific enough to learn WITHOUT clicking the link
CRITICAL: Never fabricate a URL. If you cannot verify a link, write <!-- TODO: verify source link --> instead.
Step 3: Write the Document
Create docs/patterns/<pattern-name>/index.md with ALL required sections:
# Pattern: [Name]
## One Liner ← ≤ 30 English words, capture WHY not just WHAT
## Core Idea ← concept + diagram (choose best representation for this pattern)
## Production Proof ← table with ≥ 2 verified URLs, descriptions show HOW not just WHAT
## Implementation ← TypeScript (required) + ≥ 1 other language in ::: code-group
## Exercises ← table with basic + intermediate exercise links
## When to Use ← ≥ 3 concrete scenarios
## When NOT to Use ← ≥ 2 concrete alternatives
## More Production Uses ← bullet list with repo links
## Challenge Questions ← 3-4 scenario Q&A using ::: details syntax
Diagram Guidelines
- Choose the representation that best matches the pattern's nature:
- Ring/circular → for hash rings, ring buffers
- Timeline → for temporal patterns (WAL, MVCC, retry)
- State diagram → for state machines, circuit breakers (use mermaid)
- Tree → for tries, heaps, B-trees
- Box-and-arrow → for data structures (LRU, skip list)
- ASCII
textblocks: every box border must be vertically aligned - ZH docs: CJK characters = 2 display columns; compensate with fewer spaces
- Verify alignment in a monospace font before committing
Step 4: Implement
In the ::: code-group block:
- TypeScript (required) — idiomatic, strict types, no
any - At least one of: Rust / Go / Python
- Each implementation must be idiomatic, not a line-by-line translation
- Go: do NOT add
importblocks — the verify-code script auto-detects imports - Rust: wrap standalone code in
fn main()or usepub struct/pub fn - Verify:
pnpm verify-code
Step 5: Design Exercises
Create in exercises/typescript/<pattern>/:
01-basic.test.ts— basic pattern mechanics (required)02-intermediate.test.ts— real-world application scenario (required)- Use TODO-stub format with
// TODO: implementmarkers - Include working implementations so CI passes
- Separator:
// ─── Tests (do not modify below this line) ─────────────────────── - 4-5 meaningful test cases per exercise
- Verify:
pnpm test:exercisesANDpnpm typecheck
Step 6: Write Challenge Questions
Add ## Challenge Questions at the end of the EN doc:
- 3-4 questions using
::: details Q1: [question]...:::syntax - Questions test understanding through production scenarios
- Verify factual accuracy of all answers
- Escape
|in table cells, use×instead of*for multiplication - Copy to ZH doc with header
## 挑战题, translate Q&A to Chinese (keep technical terms and code in English)
Step 7: Create Chinese Translation
Create docs/zh/patterns/<pattern-name>/index.md:
- Translate structural content (headings, explanations, When to Use)
- Keep code blocks identical to English
- Keep Production Proof links identical
- Challenge Questions: translate questions + answers to Chinese, keep technical terms/code in English
- ASCII diagrams: use English labels inside box-drawing diagrams (no CJK in diagrams)
Step 8: Update Navigation
All of these must be updated:
-
docs/.vitepress/config.ts— BOTH English and Chinese sidebar -
docs/index.md— English homepage pattern table -
docs/zh/index.md— Chinese homepage pattern table -
README.md— pattern table + cheat sheet table -
README.zh-CN.md— pattern table + cheat sheet table -
docs/by-project/*.md— add to ALL relevant project pages (React, Linux, Go, Redis, etc.) -
docs/by-project/more-projects.md— add if project not covered by specific pages -
docs/zh/by-project/*.md— sync Chinese versions -
README.mdcheat sheet — add to correct category table -
README.zh-CN.mdcheat sheet — sync Chinese version -
docs/guide/pattern-connections.md+ ZH — update if pattern fits a system case study
Step 9: Full Verification
Run ALL checks before committing:
pnpm check # All checks (lint + typecheck + test + verify-code + verify-mermaid + check:content)
pnpm build # VitePress builds
Step 10: Site Accessibility Verification
After build, verify all new pages are reachable:
ls docs/.vitepress/dist/patterns/<name>/index.html— EN page existsls docs/.vitepress/dist/zh/patterns/<name>/index.html— ZH page exists- After deploy, spot-check live URLs in both languages
Step 11: Commit and Tag
- Commit message:
feat: add <pattern-name> pattern - If adding multiple patterns: one commit per batch with list
- Push and verify CI is green before tagging
- Tag:
git tag -a v1.X.0 -m "description"+git push origin v1.X.0
Version History
- 0307be9 Current 2026-07-05 14:53


