Skip to main content
Glama
Kaifazad

Style DNA Ghostwriter

by Kaifazad

Style DNA Ghostwriter

学习代码库中未成文的约定。写出真正属于这里的代码。

License: MIT Python Tests


问题

风格指南和代码检查工具只能强制团队写下来的规则。 而代码库真正的个性——错误如何处理、组件如何组织、偏好箭头函数还是函数声明、如何使用 Tailwind 工具类或 CSS 模块、文档字符串实际有多详细——只存在于代码本身。AI 生成的代码忽略了所有这些,默认采用通用的教科书式风格,这正是它显得格格不入的原因。

Style DNA Ghostwriter 通过像资深工程师那样学习约定来解决这个问题:阅读代码,而不是没人更新的维基页面。

$ style-dna analyze ./my_web_app

Analyzed 42 files from './my_web_app' (0 Python, 42 Web).
Style profile saved to: style_profile.json

## Web Conventions
- Detected frameworks/tools: Next.js, React, Tailwind CSS, TypeScript.

### JavaScript / TypeScript
- Use single quotes for JS/TS strings.
- Omit semicolons at end of statements.
- Prefer arrow functions (`const fn = () => {}`).
- Prefer named exports.
- Use path aliases (`@/...`) for imports instead of deep relative paths.
- Prefer `interface` over `type` for object shapes in TypeScript.

### React / Next.js
- Next.js routing: App Router (`app/`).
- Define React components as arrow functions (`const Button = () => ...`).
- Component file naming: PascalCase.
- ~40% of components use 'use client' directive.
- State management: zustand.

### CSS / Styling
- Styling approach: Tailwind CSS utility classes.
- Uses CSS custom properties (`var(--token-name)`) for design tokens.
- Preferred color format: HSL.

Related MCP server: Coding Standards MCP Server

与任何编码代理兼容

一条命令即可将提取的风格注入团队使用的每个代理——无需插件,无需逐个工具配置:

style-dna init

这会将规则直接写入代理在会话开始时自动读取的约定文件:

文件

自动读取方

GEMINI.md

Google Antigravity & Gemini Code Assist

CLAUDE.md

Claude Code

AGENTS.md

Google Antigravity, Codex, OpenCode 以及遵循 AGENTS 标准的工具

.cursorrules

Cursor

.windsurfrules

Windsurf

.github/copilot-instructions.md

GitHub Copilot

对于支持模型上下文协议(Model Context Protocol)的代理(Claude Code、Cursor 等),style-dna init 还会打印一份可直接粘贴的 MCP 配置,使代理能够实时拉取规则,而非使用静态文件:

{
  "mcpServers": {
    "style-dna": {
      "command": "style-dna",
      "args": ["mcp"]
    }
  }
}

暴露的 MCP 工具:analyze_repoget_style_rulesrefresh_style_profile


提取的内容

栈 / 类别

提取的信号

Python

函数/变量命名风格、私有前缀使用率(_name)、文档字符串风格(Google/NumPy/reST/plain)及覆盖率、类型注解使用率、错误处理(宽泛 vs 具体 vs 自定义异常)、引号风格、导入顺序、平均函数长度、常见模式(@dataclassProtocolasync 等)

JavaScript / TypeScript

分号(always vs never)、引号风格(single / double)、箭头函数 vs 函数声明、命名导出 vs 默认导出、导入路径别名(@/...)、TypeScript interface vs type 偏好、类型注解覆盖率、注释风格(JSDoc/行内/块注释)

React / Next.js

App Routerapp/)vs Pages Routerpages/)、服务端组件 vs 客户端组件('use client' 使用率)、服务端操作('use server')、组件风格、自定义 Hook 模式(use*)、状态管理(Zustand、Redux、Context、TanStack Query、SWR、Jotai、Recoil)、框架检测

CSS 与样式

Tailwind CSS vs CSS Modules*.module.css)vs CSS-in-JS vs 原生 CSS、类命名约定(BEM / kebab-case / camelCase)、CSS 自定义属性设计令牌(var(--token))、颜色格式(HEX、HSL、RGB)

HTML

缩进风格(2 空格 / 4 空格 / 制表符)、属性引号风格(" vs ')、语义化标记使用率(<header><main><section> 等)


工作原理

  1. analyze 遍历代码库,分析每个源文件,无需外部二进制或编译器依赖。一组可插拔的专用提取器在解析树和源码标记上运行,生成一个 StyleProfile——一个结构化的、可版本化的指纹,保存为 style_profile.json

  2. init 运行 analyze,然后将该配置文件注入标准的代理约定文件(CLAUDE.mdAGENTS.md.cursorrules 等),并用清晰的更新标记(<!-- style-dna:start --> ... <!-- style-dna:end -->)包围。

  3. generate(可选)将配置文件转换为系统提示,并直接调用 Claude API,适用于希望从终端获得代写代码的团队。

style-dna-ghostwriter/
├── style_dna/
│   ├── analyzer.py         # multi-language codebase scanner
│   ├── profile.py          # StyleProfile data model + save/load + multi-stack rules
│   ├── generator.py        # profile -> system prompt -> Claude API call
│   ├── mcp_server.py       # MCP server exposing tools for agents
│   ├── conventions.py      # upserts rules into CLAUDE.md/AGENTS.md/.cursorrules/etc.
│   ├── cli.py              # `style-dna` CLI (init, analyze, show, generate, mcp)
│   └── extractors/         # Python, JS/TS, React/Next.js, CSS/Tailwind, HTML
├── examples/
│   ├── sample_repo/        # Python test fixture
│   └── sample_web_repo/    # Next.js 14 + React TSX + Tailwind test fixture
└── tests/                  # Complete test suite

安装

# Core only (zero external dependencies):
pip install -e .

# With MCP server support:
pip install -e ".[mcp]"

# With direct Claude code generation support:
pip install -e ".[generate]"

# All features:
pip install -e ".[all]"

使用

# One-shot setup for any repo (Python, React, Next.js, etc.):
style-dna init

# Inspect codebase style rules:
style-dna analyze ./my_repo --out style_profile.json
style-dna show style_profile.json
style-dna show style_profile.json --format json

# Direct generation (requires ANTHROPIC_API_KEY):
export ANTHROPIC_API_KEY=sk-...
style-dna generate style_profile.json \
  "Write a React component that displays a product card with add to cart button" \
  --out ProductCard.tsx

作为 Python 库使用:

from style_dna import analyze_codebase
from style_dna.generator import generate_code

profile = analyze_codebase("./my_repo")
code = generate_code(profile, "Add a custom hook to manage user favorites")

测试

pip install -e ".[dev]"
python -m pytest tests/ -v

许可证

基于 MIT 许可证 发布。


Kaifazad 创建 — kaifazad.in

A
license - permissive license
-
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
1Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    D
    maintenance
    Code linting and style checking tools for AI agents, exposed as an MCP server. Supports style checks, naming conventions, complexity analysis, dead code detection, and import analysis.
    55
    MIT
  • A
    license
    -
    quality
    D
    maintenance
    Provides a CLI and MCP server for scanning repositories to generate evidence-backed, project-specific instruction files for AI coding assistants, ensuring AI behavior aligns with existing codebase conventions.
    1
    15
    Apache 2.0
  • A
    license
    -
    quality
    B
    maintenance
    Scans your source code using AST analysis to detect coding conventions, error handling, API patterns, and more, then generates a CONVENTIONS.md file to help AI agents follow your project's style.
    MIT

View all related MCP servers

Related MCP Connectors

  • Lints + auto-fixes how AI coding agents discover any new product. 24 rules, 6 tools, score 0-100.

  • Repo intel for AI coding agents: overview, PRs, contributors, hot files, CI, deps. Remote MCP.

  • Hosted MCP server for structured code review passes on human- and AI-written code. Free tier.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Kaifazad/Style-DNA-Ghostwriter'

If you have feedback or need assistance with the MCP directory API, please join our Discord server