spec-rules-init
npx skills add https://github.com/anyoneanderson/agent-skills --skill spec-rules-init
Agent 安装分布
Skill 文档
spec-rules-init â Coding Rules Generator
Extract project conventions and generate a unified coding-rules.md for use as a quality gate during implementation.
Language Rules
- Auto-detect input language â output in the same language
- Japanese input â Japanese output, use
references/rules-template.ja.md - English input â English output, use
references/rules-template.md - Explicit override takes priority (e.g., “in English”, “æ¥æ¬èªã§”)
Execution Flow
Step 0: Initial Context Check
BEFORE any interaction, execute these checks:
-
Check current directory:
pwd ls -la -
Detect convention files (parallel where possible):
# Convention files ls CLAUDE.md src/CLAUDE.md AGENTS.md test/CLAUDE.md 2>/dev/null ls -d .claude/ 2>/dev/null # Config files ls package.json go.mod requirements.txt Cargo.toml 2>/dev/null ls .eslintrc* biome.json tsconfig.json .prettierrc* 2>/dev/null -
Detect existing source code:
find . -maxdepth 3 -type f \( -name "*.ts" -o -name "*.js" -o -name "*.py" -o -name "*.go" -o -name "*.java" -o -name "*.rs" \) 2>/dev/null | head -30 -
Scan installed skills:
ls ~/.claude/skills/*/SKILL.md .claude/skills/*/SKILL.md 2>/dev/null -
Check for existing coding-rules.md:
find . -name "coding-rules.md" -type f 2>/dev/null
Step 1: Rule Extraction from Convention Files
Read detected convention files and extract rules by category.
Detection targets (by priority):
| File | Content to Extract | Priority |
|---|---|---|
CLAUDE.md (root) |
Project-wide rules | High |
src/CLAUDE.md |
Source-specific rules | High |
AGENTS.md |
Agent-oriented rules | High |
.claude/ contents |
Project settings | Medium |
package.json |
lint/test script presence | Medium |
test/CLAUDE.md |
Test-specific rules | Medium |
.eslintrc* / biome.json |
Lint rules | Low |
tsconfig.json |
TypeScript strict settings | Low |
.prettierrc* |
Format settings | Low |
Extraction categories and keywords:
- Testing Standards: “coverage”, “test”, “spec”, “E2E”, “ã«ãã¬ã㸔, “ãã¹ã”
- Code Quality: “lint”, “typecheck”, “strict”, “import”, “naming”, “å½å”
- Error Handling: “try/catch”, “Logger”, “error”, “throw”, “ä¾å¤”
- Documentation: “JSDoc”, “TSDoc”, “@ApiProperty”, “comment”, “ã³ã¡ã³ã”
- Security: “secret”, “password”, “hash”, “HTTPS”, “ãã°ã«åºåããªã”
- Git: “commit”, “branch”, “ã³ãããã¡ãã»ã¼ã¸”, “feature branch”
For each extracted rule, record:
- Category (one of the 6 above)
- Content (the rule text)
- Severity:
[MUST](explicit requirement),[SHOULD](recommended),[MAY](optional) - Source file and line reference
Rules from CLAUDE.md / AGENTS.md are Priority 1 and default to [MUST].
Step 2: Codebase Analysis
If source code exists, analyze the codebase to detect implicit conventions. Skip this step entirely if no source files are found (new project).
2a. Directory structure analysis:
- Scan directory tree (up to 3 levels deep)
- Detect patterns: feature-based (
modules/{feature}/), layer-based (controllers/,services/), co-located tests vs separatetests/directory
2b. File naming convention detection:
- Collect file names under
src/(or primary source directory) - Classify each name: kebab-case, camelCase, PascalCase, snake_case
- If one pattern is 60%+ of files â propose as
[MUST] - Minority patterns â propose as
[SHOULD]for unification
2c. Library analysis:
- Read dependency file (
package.json,go.mod,requirements.txt, etc.) - Identify major libraries:
- Frameworks: NestJS, Next.js, Express, Fastify, Django, Flask, Gin, etc.
- Testing: Jest, Vitest, Playwright, pytest, etc.
- Validation: Zod, class-validator, Joi, etc.
- ORM: Prisma, TypeORM, Drizzle, SQLAlchemy, GORM, etc.
- Linters: ESLint, Biome, ruff, golint, etc.
- Add library-specific best practice recommendations as
[SHOULD]rules- Example: Prisma detected â
[SHOULD] Use Prisma Client for all DB access - Example: Zod detected â
[SHOULD] Use Zod for runtime validation
- Example: Prisma detected â
2d. Code pattern analysis (if code intelligence tools are available):
- Import style: relative (
./) vs path alias (@/) - Export style: named exports vs default exports
- Error handling patterns in use
2e. Shared utility and library detection:
- Scan the codebase for shared utility modules, helper functions, and internal libraries:
- Look for directories named
utils/,helpers/,lib/,shared/,common/ - Identify frequently imported internal modules
- Look for directories named
- Cross-reference with dependency file to identify commonly used libraries
- Present a summary of detected shared utilities and libraries to the user:
Detected shared utilities and libraries: Internal: utils/logger.ts, lib/validation.ts, helpers/date.ts External: Zod (validation), Prisma (DB), date-fns (dates) - For each detected shared utility or library, generate a
[SHOULD]rule:- Example:
[SHOULD] Use lib/validation.ts for input validation - Example:
[SHOULD] Use Zod for runtime validation - Example:
[SHOULD] Use utils/logger.ts instead of console.log
- Example:
- Include the detected list in the generated coding-rules.md under a “Shared Utilities” section
Codebase analysis results are Priority 2 and assigned [MUST] (for 60%+ majority patterns) or [SHOULD].
Step 3: Installed Skills Analysis
Scan installed skills for framework-specific best practices.
3a. Skill detection:
- Scan
~/.claude/skills/(global skills) - Scan
.claude/skills/(project skills) - Read each
SKILL.mdfrontmatter description and body
3b. Framework match: Compare detected project tech stack (from Steps 1-2) with skill keywords:
| Project Tech | Matching Keywords |
|---|---|
| Next.js | next, next.js, vercel, react, RSC, server component |
| NestJS | nest, nestjs, express, fastify, typescript backend |
| React | react, hooks, component, jsx, tsx |
| Go | go, golang, goroutine |
| Python | python, django, flask, fastapi |
3c. User confirmation (if matching skills found):
Use AskUserQuestion:
question: "The following installed skills were detected. Use them for rule extraction?" / "以ä¸ã®ã¤ã³ã¹ãã¼ã«æ¸ã¿ã¹ãã«ãæ¤åºããã¾ãããã«ã¼ã«æ½åºã«ä½¿ç¨ãã¾ããï¼"
header: "Skills"
multiSelect: true
options:
- "{skill-name} â {description} (Recommended)" / "{skill-name} â {説æ}"
3d. Priority mapping:
- Skill-derived rules are Priority 3 â
[SHOULD]or[MAY] - If a skill rule contradicts Priority 1 or 2 rules â keep higher priority, show warning
- Record source as
Source: skill/{skill-name}in coding-rules.md
3e. No matching skills: If no matching skills are installed, optionally inform the user:
"Matching skills may be available on skills.sh for your tech stack.
Install and re-run to incorporate best practices."
/ "æè¡ã¹ã¿ãã¯ã«é©åããã¹ãã«ã skills.sh ã«ããå¯è½æ§ãããã¾ãã
ã¤ã³ã¹ãã¼ã«å¾ã«åå®è¡ããã¨ããã¹ããã©ã¯ãã£ã¹ãåãè¾¼ãã¾ãã"
Step 4: Interactive Dialogue
4a. Present extraction results:
Display detected rules summary by category:
Extraction Results:
Testing Standards: {n} rules
Code Quality: {n} rules
Error Handling: {n} rules
Documentation: {n} rules
Security: {n} rules
Git: {n} rules
Total: {total} rules (Priority 1: {n}, Priority 2: {n}, Priority 3: {n})
If any category has 0 rules, highlight it for user attention.
4b. Output path selection (AskUserQuestion):
question: "Where to save coding-rules.md?" / "coding-rules.md ã®åºåå
ã¯ï¼"
header: "Output"
options:
- "docs/coding-rules.md (Recommended)" / "docs/coding-rules.mdï¼æ¨å¥¨ï¼"
- "docs/development/coding-rules.md"
If user selects “Other”, accept any valid file path.
4c. Rule supplementation (AskUserQuestion):
For categories with missing or insufficient rules, ask targeted questions:
question: "Any additional testing rules?" / "ãã¹ãåºæºã«ã¤ãã¦è¿½å ã«ã¼ã«ã¯ããã¾ããï¼"
header: "Testing"
options:
- "Require 80%+ coverage (Recommended)" / "ã«ãã¬ãã¸80%以ä¸ãå¿
é ã«ãã"
- "Specify E2E test patterns" / "E2Eãã¹ããã¿ã¼ã³ãæå®ãã"
- "No additions needed" / "追å ä¸è¦"
question: "Commit message language?" / "ã³ãããã¡ãã»ã¼ã¸ã®è¨èªã¯ï¼"
header: "Git"
options:
- "Japanese only" / "æ¥æ¬èªã®ã¿"
- "English only" / "è±èªã®ã¿"
- "Conventional Commits (English)" / "Conventional Commitsï¼è±èªï¼"
Suggest project-type-specific rules based on detected frameworks. Refer to the Project-Type Recommendations section in the reference template.
Step 5: Existing File Detection and Idempotency
If an existing coding-rules.md was found in Step 0:
- Read the existing file
- Compare with newly extracted rules (additions, changes, removals)
- Use AskUserQuestion:
question: "Existing coding-rules.md found. How to proceed?" / "æ¢åã® coding-rules.md ãè¦ã¤ããã¾ãããã©ããã¾ããï¼" header: "Existing File" options: - "Overwrite" / "䏿¸ããã" - "Merge differences" / "å·®åã®ã¿ãã¼ã¸" - "Cancel" / "ãã£ã³ã»ã«" - If “Cancel” â exit without changes
Step 6: Generate coding-rules.md
- Load the appropriate reference template (based on Language Rules)
- Fill in extracted rules by category
- Apply severity tags:
[MUST],[SHOULD],[MAY] - Add source attribution for each rule
- Include the Sources summary table at the end
- Create output directory if it does not exist
- Write the file
Step 7: Update AGENTS.md / CLAUDE.md References
After generating coding-rules.md, append a reference to project convention files.
Procedure:
-
Check if
AGENTS.mdexists at project root -
Check if
CLAUDE.mdexists (skip if it is a symlink to AGENTS.md) -
Use AskUserQuestion:
question: "Add reference to coding-rules.md in AGENTS.md / CLAUDE.md?" / "AGENTS.md / CLAUDE.md ã« coding-rules.md ã®åç §ã追è¨ãã¾ããï¼" header: "Update" options: - "Yes, add reference (Recommended)" / "ã¯ãã追è¨ããï¼æ¨å¥¨ï¼" - "No, skip" / "ããããã¹ããã" -
If approved, append to the end of each file (or after an existing “Coding Rules” section):
English version:
## Coding Rules Follow the coding rules in this file during implementation: - [{output_path}]({output_path}) â Quality rules generated by spec-rules-initJapanese version:
## ã³ã¼ãã£ã³ã°ã«ã¼ã« å®è£ æã®ã³ã¼ãã£ã³ã°ã«ã¼ã«ã¯ä»¥ä¸ã®ãã¡ã¤ã«ã«å¾ã£ã¦ãã ãã: - [{output_path}]({output_path}) â spec-rules-init ã§çæãããå質ã«ã¼ã«é -
If neither file exists â skip with a warning message:
"Warning: No AGENTS.md or CLAUDE.md found. Skipping reference update." / "è¦å: AGENTS.md ã CLAUDE.md ãè¦ã¤ããã¾ãããåç §è¿½è¨ãã¹ããããã¾ãã"
Step 8: spec-series Integration Notice
After completing generation, inform the user about integration with other spec-series skills:
"coding-rules.md has been generated. The following spec-series skills now reference it:
- spec-generator: Uses coding-rules.md as design constraints during the design phase
- spec-inspect: Checks [MUST] rules in Check 13 (Project Rule Compliance)
- spec-implement: Uses coding-rules.md as a quality gate during implementation"
/ "coding-rules.md ãçæãã¾ããã以ä¸ã® spec-series ã¹ãã«ãåç
§ããããã«ãªã£ã¦ãã¾ã:
- spec-generator: design ãã§ã¼ãºã§ coding-rules.md ãè¨è¨å¶ç´ã¨ãã¦ä½¿ç¨
- spec-inspect: Check 13ï¼ããã¸ã§ã¯ãã«ã¼ã«æºæ ï¼ã§ [MUST] ã«ã¼ã«ããã§ãã¯
- spec-implement: å®è£
æã®å質ã²ã¼ãã¨ã㦠coding-rules.md ã使ç¨"
Options
| Option | Description |
|---|---|
--force |
Overwrite existing coding-rules.md without confirmation |
--category <name> |
Generate rules for a specific category only (e.g., --category testing) |
Error Handling
-
Convention file unreadable: Warn and skip the file, continue with remaining files
"Warning: Could not read {filename}. Skipping." / "è¦å: {filename} ãèªã¿åãã¾ãããã¹ããããã¾ãã" -
Output directory does not exist: Create it automatically
mkdir -p {output_directory} -
Write permission denied: Show error and suggest an alternative path
"Error: Cannot write to {path}. Try a different location." / "ã¨ã©ã¼: {path} ã«æ¸ãè¾¼ãã¾ãããå¥ã®ãã¹ãæå®ãã¦ãã ããã" -
No convention files found: Fall back to dialogue-only mode
"No convention files (CLAUDE.md, AGENTS.md, etc.) found. Proceeding with dialogue-only mode." / "è¦ç´ãã¡ã¤ã«ï¼CLAUDE.md, AGENTS.mdçï¼ãè¦ã¤ããã¾ããã対話ã®ã¿ã¢ã¼ãã§é²ã¿ã¾ãã"
Usage Examples
# Generate coding rules from project conventions
"Generate coding rules"
ãã³ã¼ãã£ã³ã°ã«ã¼ã«ãçæãã¦ã
# Create coding-rules.md with forced overwrite
"Create coding-rules.md --force"
ãcoding-rules.md ã使 --forceã
# Extract rules for a specific category
"Extract project rules --category testing"
ããã¹ãã«ã¼ã«ã ãæ½åºãã¦ã
# After generating, re-run to update
"Update coding-rules.md"
ãcoding-rules.md ãæ´æ°ãã¦ã
Post-Completion Actions
After generating coding-rules.md, suggest next actions with AskUserQuestion:
question: "coding-rules.md generated. What's next?" / "coding-rules.md ãçæãã¾ãããæ¬¡ã®ã¢ã¯ã·ã§ã³ã¯ï¼"
header: "Next"
options:
- "Generate specifications (spec-generator)" / "仿§æ¸ãçæããï¼spec-generatorï¼"
- "Set up development workflow (spec-workflow-init)" / "éçºã¯ã¼ã¯ããã¼ãè¨å®ããï¼spec-workflow-initï¼"
- "Done for now" / "å®äº"