patchwork — Codebase Conventions for AI Agents

io.github.SaiNarayana-B由 GitHub 帳號 SaiNarayana-B 發布v0.1.7更新於 Oct 24, 2026

Scan any codebase, generate CONVENTIONS.md, expose conventions as MCP tools for AI agents.

發布方自己的服務:Codebase

已驗證STDIO僅桌面知識與記憶開發者工具

概覽

AI 產生的概覽

掃描本機程式碼庫,挖掘其編碼慣例,並透過 MCP 工具提供給 AI 代理,讓它遵循專案真正的風格。

可以做什麼
patchwork 以 AST 解析(tree-sitter)搭配設定檔與 git 歷史分析原始碼,偵測命名、匯入、結構、錯誤處理、測試、API 與 git 慣例,並附上信心分數與真實範例。它會產生 CONVENTIONS.md(或 AGENTS.md,或附加到 CLAUDE.md),也能以 MCP 伺服器執行,提供 patchwork_scan、patchwork_naming、patchwork_structure、patchwork_stack、patchwork_errors、patchwork_testing、patchwork_git 與 patchwork_check 等八個工具。另外還有 scan、update、diff、show、watch 指令以及 Python API。
適用情境
當 AI 編碼助理老是編出與專案不符的命名、檔案配置、錯誤處理或提交風格時使用。它適合希望代理讀取程式碼庫實際慣例、而非依賴手寫且很快過時的風格指南的團隊。
執行需求
以本機 stdio 程序在使用者機器上執行(僅桌面端)。需以 pip 安裝 PyPI 套件 patchwork-conventions,需要 Python;Go、Rust、Java 的完整 AST 支援來自 'full' 附加套件。未宣告任何帳號、API 金鑰、環境變數或標頭,也不需要網路存取。
安裝前請注意
掃描會讀取原始碼樹與 git 歷史,也就是在本機處理儲存庫內容;README 表示分析完全在本機進行,沒有 API 呼叫與遙測。update、watch 及 CI 範例等指令會寫入或提交 CONVENTIONS.md,提交前請先檢查產生的檔案。不會要求任何憑證。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 patchwork — Codebase Conventions for AI Agents,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

patchwork

Mine your codebase. Generate CONVENTIONS.md. Stop AI agents from making up your style.

[PyPI] [License: MIT] [Python 3.9+] [agent-skills] [MCP]


Every team that uses AI coding assistants hits the same wall: Claude writes getUserById in a codebase that uses get_user_by_id. Cursor creates components/userCard.tsx in a project that uses user-card.tsx. The agent invented a response shape that doesn't match the rest of the API.

You write a CLAUDE.md manually. It goes stale in two weeks. You write it again.

patchwork automates this. It scans your actual source code using AST analysis and detects what your team really does — not what you think you do.


What it detects

CategoryWhat's mined
NamingFunctions, classes, variables, constants, files — with confidence score and real examples
ImportsAbsolute vs relative, path aliases (@/, src/), barrel files, destructuring style
StructureSource root, test layout, feature vs layer organisation, monorepo detection
Error Handlingtry/except vs Result types, logging framework, custom exception naming, propagation style
TestingFramework, assertion style, mocking library, coverage tool, fixture patterns
API PatternsResponse shape, route param style, ORM, async pattern, GraphQL/gRPC presence
Git WorkflowCommit message style, branch naming, co-change file pairs
Tech StackFrameworks, package manager, linters, formatters, type checker, build tool, scripts

Quick start

bash
pip install patchwork-conventionscd your-projectpatchwork scan

That's it. You'll get a CONVENTIONS.md like this:

markdown
# CONVENTIONS.md> Auto-generated by patchwork on 2026-06-25
## Tech Stack**Language:** python**Runtime:** Python >=3.11**Package Manager:** uv**Frameworks:** fastapi, sqlalchemy**Linters:** ruff**Formatters:** ruff, black
## Naming Conventions
### Python- **Functions:** `snake_case` (97% consistent)  - Examples: `get_user`, `parse_response`, `create_session`- **Classes:** `PascalCase` (100% consistent)  - Examples: `UserService`, `AuthHandler`, `DatabaseClient`- **Constants:** `SCREAMING_SNAKE`  - Examples: `MAX_RETRIES`, `API_BASE_URL`- **Files:** `snake_case`- **Private prefix:** `_`- **Test functions:** prefix `test_`
## Project Structure**Source root:** `src/`**Organisation:** layer-based**Tests:** separate (`tests/`)
**Key directories:**  - `src/` — source root  - `tests/` — test suite  - `migrations/` — database migrations
## Error Handling
### Python- **Pattern:** try/except- **Propagation:** raise- **Logging:** `structlog`- **Custom exception naming:** Error suffix  - `ValidationError`, `AuthError`, `NotFoundError`
## Testing Conventions
### Python- **Framework:** pytest- **Coverage:** 34 test files / 89 source files (38% ratio)- **Assertions:** `assert(...)`- **Coverage tool:** `pytest-cov`- **Patterns:** fixtures, factories
## Git Conventions- **Commit style:** conventional commits- **Examples:** `feat(auth): add JWT refresh`, `fix(api): handle null user`- **Branch naming:** feature/name + fix/name

Why not argus or sourcebook?

Featurepatchworkargussourcebook
AST-based naming analysis✅ tree-sitter❌ filesystem only❌ not done
Confidence scores✅ per-category❌❌
Real examples from your code✅❌❌
Counter-examples (inconsistencies)✅❌❌
Error handling pattern mining✅❌❌
API response shape detection✅❌❌
Co-change file pairs✅❌✅
Convention checking (check cmd)✅❌❌
MCP server with 8 tools✅❌✅ (4 tools)
Watch mode✅✅ (sync)✅
Zero LLM required✅✅✅ (layer A)
Open source / MIT✅✅❌ BSL

Commands

bash
# Generate CONVENTIONS.mdpatchwork scan
# Generate for a specific pathpatchwork scan /path/to/project
# Generate AGENTS.mdpatchwork scan --agents-md
# Append to CLAUDE.mdpatchwork scan --claude-md
# Output JSON (for programmatic use)patchwork scan --json
# Print to stdout (don't write file)patchwork scan --stdout
# Limit to specific languagespatchwork scan --lang python --lang typescript
# Re-scan and update, preserving manual editspatchwork update
# Show what would changepatchwork diff
# Print detected conventions to terminalpatchwork show
# Auto-watch mode (regenerate on change)patchwork watch
# Start MCP serverpatchwork serve --stdio    # for Claude Codepatchwork serve --port 3742  # HTTP mode

Claude Code integration

Option 1: CONVENTIONS.md (recommended)

bash
patchwork scan      # run once# CONVENTIONS.md is automatically read by Claude Code

Option 2: Append to CLAUDE.md

bash
patchwork scan --claude-md

Option 3: MCP server

Claude Code — add to ~/.claude.json (or run claude mcp add interactively):

json
{  "mcpServers": {    "patchwork": {      "command": "patchwork",      "args": ["serve", "/path/to/your/project", "--stdio"]    }  }}

Claude Desktop — add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

json
{  "mcpServers": {    "patchwork": {      "command": "patchwork",      "args": ["serve", "/path/to/your/project", "--stdio"]    }  }}

Cursor — add to .cursor/mcp.json in your project root:

json
{  "mcpServers": {    "patchwork": {      "command": "patchwork",      "args": ["serve", ".", "--stdio"]    }  }}

Then your AI agent can use 8 on-demand tools:

ToolWhen to use
patchwork_scanGet complete conventions overview
patchwork_namingBefore writing new identifiers
patchwork_structureBefore creating new files/directories
patchwork_stackWhen choosing libraries or commands
patchwork_errorsBefore writing error handling
patchwork_testingBefore writing test files
patchwork_gitBefore writing commit messages
patchwork_checkValidate a proposed name

Option 4: Claude Code skill (SKILL.md)

Copy SKILL.md from this repo to ~/.claude/skills/patchwork/SKILL.md to get /patchwork slash commands.


Watch mode (CI/auto-update)

bash
# Keep CONVENTIONS.md updated as you codepatchwork watch &
# Or in CI — fail if conventions changedpatchwork diff || (patchwork update && git add CONVENTIONS.md && git commit -m "chore: update conventions")

Python API

python
from patchwork import scanfrom patchwork.scanner import ScanOptionsfrom pathlib import Path
# Full scanreport = scan(ScanOptions(root=Path(".")))
# Render to markdownprint(report.to_markdown())
# Render to JSONimport jsondata = json.loads(report.to_json())
# Access specific resultsnaming = report.naming.get("python")print(f"Functions: {naming.functions.style} ({naming.functions.confidence:.0%})")print(f"Examples: {naming.functions.examples}")
structure = report.structureprint(f"Source root: {structure.source_root}")print(f"Organisation: {structure.organisation}")

Supported languages

LanguageAST (tree-sitter)Fallback regex
Python✅ full✅
TypeScript✅ full✅
JavaScript✅ full✅
Go✅ (with full extra)✅
Rust✅ (with full extra)✅
Java✅ (with full extra)✅
Ruby, PHP, C#, C++❌✅ regex only

Install full language support:

bash
pip install 'patchwork-conventions[full]'

How it works

your codebase     │     ▼ConfigDetector        ← reads package.json, pyproject.toml, go.mod, Cargo.toml     │     ▼File discovery        ← respects .gitignore, skips node_modules etc.     │     ▼Per-language AST      ← tree-sitter parses every file into a syntax tree     │     ├── NamingMiner       → extracts function/class/variable names, classifies style     ├── ImportMiner        → detects import patterns, aliases, barrel files     ├── StructureMiner     → analyses directory layout, test co-location     ├── ErrorHandlingMiner → detects try/catch patterns, logging, custom exceptions     ├── TestingMiner       → identifies framework, assertion style, mocking     ├── APIPatternMiner    → finds response shapes, ORMs, route styles     └── GitPatternMiner    → mines commit history, branches, co-change pairs          │          ▼     ConventionReport          │          ├── CONVENTIONS.md  (default)          ├── AGENTS.md       (--agents-md)          ├── CLAUDE.md       (--claude-md, appends)          └── JSON            (--json)

All analysis is 100% local — no API calls, no telemetry, no data leaves your machine.


Performance

On a 1,000-file TypeScript monorepo:

  • Without tree-sitter: ~0.8s
  • With tree-sitter (full AST): ~2.1s

On a 500-file Python project:

  • ~1.1s

Results are deterministic — same codebase always produces the same output.


Contributing

bash
git clone https://github.com/yourusername/patchworkcd patchworkpip install -e '.[dev]'pytest

Pull requests welcome. See CONTRIBUTING.md.


License

MIT — free for personal and commercial use.


Topics

claude-code · agent-skills · mcp · context-engineering · hallucination-detection · code-conventions · static-analysis · tree-sitter · developer-tools · ai-coding

來源:README.md,提交 595de70

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.7最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

其他 Codebase 整合