dh-code-ruler
Interview + code analysis to generate {project_root}/CODE_RULES.md (style guide, design patterns, security/performance constraints, stack best practices; websearch allowed). Executed by the selected architecture agent; dh-coding runs it when absent. Use to create or refresh code rules.
- License 许可
- MIT
- 最近更新
- 2026-11-10
- Stars
- ★ 8
- Forks
- 1
01 前言 Front Matter
- name
- dh-code-ruler
- license
- MIT
- metadata
- { "audience": "developers", "workflow": "design" }
- description
- Interview + code analysis to generate {project_root}/CODE_RULES.md (style guide, design patterns, security/performance constraints, stack best practices; websearch allowed). Executed by the selected architecture agent; dh-coding runs it when absent. Use to create or refresh code rules.
- allowed-tools
- read, write, edit, bash, glob, websearch
- compatibility
- opencode
03 SKILL.md 正文
Code Ruler
Produce the project's strict rules contract at {project_root}/CODE_RULES.md
by grilling the user and analyzing the codebase. dh-coding enforces this
file; dh-code-ruler is executed by the selected architecture agent (or
invoked by dh-coding when the file is missing).
When to use
{project_root}/CODE_RULES.mddoes not exist → create it (dh-coding step 2).- The rules have drifted from the code or the stack changed → refresh it.
- The architect needs a precise rule contract before planning/implementation.
Workflow
- Locate
{project_root}/CODE_RULES.md. If it exists and is fresh, offer a refresh instead of a rewrite; if it is missing, create mode. - Grill (interview) — ask ONLY what is missing, numbered and focused:
- Stack & tooling: languages, frameworks, package manager, build/lint/test setup.
- Style: formatting preferences, naming conventions, file/module layout, import rules, comments policy.
- Patterns: patterns to enforce, patterns to forbid (anti-patterns), layering/bounded-context constraints.
- Security-sensitive areas: auth, user data, uploads, secrets, external integrations, deployment/pipeline concerns.
- Performance-sensitive paths: hot endpoints, large data operations, caching, concurrency, budgets.
- Enforcement: which checks/linters must back each rule, and hard numbers (limits, thresholds).
- Analyze the code before writing: sample representative modules, tests,
configs, and docs. When the project graph is indexed, use the
dh-code-queryskill (stats,graph importers/callers,duplicates) to inventory modules and spot repeated patterns before sampling files. Extract de-facto conventions (naming, structure, import style, error handling, test patterns) and existing constraints from linter/formatter configs (biome/eslint, ruff, phpcs/phpstan...),tsconfig/pyproject.toml/composer.json,AGENTS.md, README, anddocs/. Mark anything inferred as an assumption; never invent rules the codebase does not support. - Research stack best practices — websearch when needed and possible: official/community guides for the detected stack (e.g. JS/TS: biome + TypeScript conventions; Python: PEP 8/ruff; PHP: PSR-12/phpstan; Go: gofmt/effective go) and fold the relevant recommendations into the rules.
- Generate
{project_root}/CODE_RULES.mdwith the MANDATORY sections below. Keep it concise and enforceable (aim ≤ 200 lines; rules are backed by concrete checks or commands). - Verify: the file parses, each rule maps to a check where possible, and the configured QA gate (qa:check / lint / tests) still reflects the rules.
CODE_RULES.md structure (mandatory)
# CODE_RULES.md — <project>
> Source of truth for this project's coding rules (dh-code-ruler).
> `dh-coding` enforces this file; keep it updated via `dh-create-documentation`.
## Code Style Guide
- <naming, formatting, file layout, imports, comments, line limits (<300 code-only)>
## Design Patterns
- <patterns to enforce; patterns to forbid; layering/bounded-context rules>
## Security Constraints and Checks
- <constraints + the checks that enforce them (osv/semgrep/bandit, validation, secrets)>
## Performance Constraints and Checks
- <constraints + the checks/budgets that enforce them (N+1, pagination, caching, memory)>
## Best Practices for the Stack
- <stack-specific recommended practices, with sources when researched>
Rules
- Never copy whole guideline documents: distill strict, project-specific rules backed by the interview, the code analysis, or the researched guide.
- Preserve user statements verbatim where they define constraints or scope.
- Every rule should be actionable: either a check/command exists to enforce it, or the rule names the review gate that validates it.
- If the user has no preference, derive the rule from observed code convention and mark it as inferred.
Verification Checklist
- [ ]
{project_root}/CODE_RULES.mdexists with all 5 mandatory sections - [ ] Rules traceable to interview answers, code analysis, or researched sources
- [ ] Enforcement mapped (commands/gates) per rule where possible
- [ ] No invented rules; assumptions marked
- [ ] Mirrors the project's actual configs (linters, toolchain, docs)
Doc search
Documentation management: delegate create / update / delete / retrieve of generated documents (excluding docs/plans) to the best available documentation agent (bundled documentation capability as fallback) — the main and only documentation owner (see dh-create-documentation).
Search generated documentation quickly: notesmd-cli search-content "<term>" --vault "<project-name>" or obsidian search query="<term>" (fallback: rg --glob '*.md' "<term>" docs/).
04 同仓库更多 Skills
dh-simplify
Review changed code for reuse, quality, and efficiency (three parallel reviews), then fix findings directly. Use after making changes or when asked to clean up, refactor, simplify, or improve this code.
dh-setup
Audit system software, configure user MCPs/plugins, scaffold project QA (hooks + per-stack tools), bootstrap docs/architecture with the selected architecture agent, and write harness directives into AGENTS.md. Use to check requirements or setup the environment.
dh-semver
Apply strict Semantic Versioning — analyze commits since the last tag to determine the bump type (major/minor/patch from conventional commit prefixes), generate an automated changelog grouped by breaking changes, features, fixes, and chores, and create a git tag locally without pushing until confirmed, handling both conventional commits and manual version decisions. Use when preparing a release, invoked by dh-execute-plan after plan completion and dh-final-review for release readiness, or when the user asks "what version is next?", "bump version", "generate changelog", "tag release", or "what changed since last release?".
dh-review
Verify a plan sub-task against acceptance criteria, scope, done-when; review diff, validation, regression risk; structured verdict to tasks/review.md. Plan Alignment Mode (fast execution) is a separate mode: no sub-task selection, no diff review, no code review — it compares plan.md with plan_fast.md and writes tasks/review-fast.md (pre-execution) or tasks/review-fast-final.md (plan-end). Use after implementation, to review/verify the sub-task, or to check fast-plan alignment.
dh-resume-plan
Resume a paused phased plan from docs/plans/<slug>/handoff.md: validate the contract, detect drift, rehydrate context, mark the handoff resumed, and continue via dh-execute-plan resume mode. Use when the user says "resume the plan", "continue where we stopped", "pick up the plan", or "resume after a pause".
dh-preflight
Run tests, linters, static analysis as a release gate: auto-detect tooling, check dirty state, pass/fail verdict with actionable failures (no auto-fixes). Use to run preflight, pre-release check, or validate before release.