sourcebook

sourcebook

Live codebase intelligence for AI agents. Import graph PageRank for file importance, git forensics for co-change coupling and fragile code, convention detection across 16 domains, and blast radius analysis.

Category
访问服务器

README

<p align="center"> <img src="logo.png" alt="sourcebook" width="120" /> </p>

sourcebook

AI can read your code. It still doesn't know how your project works.

sourcebook captures the project knowledge your team carries in its head — conventions, patterns, traps, and where things actually go — and turns it into context your coding agent can use.

npx sourcebook init

<p align="center"> <img src="demo-hono.gif" alt="sourcebook demo" width="820" /> </p>

Tools like Repomix give AI your entire codebase. sourcebook gives it your project knowledge.

Why

AI coding agents spend most of their context window orienting — reading files to build a mental model before doing real work. Most context files (CLAUDE.md, .cursorrules) are generic and go stale fast.

Research shows auto-generated context that restates obvious information actually makes agents worse by 2-3%. The only context that helps is non-discoverable information — the project knowledge agents can't figure out by reading code alone.

sourcebook extracts only what agents keep missing: the conventions, hidden dependencies, fragile areas, and dominant patterns that live in your team's heads — not in the code.

What It Finds

  • Import graph + PageRank — ranks files by structural importance, identifies hub files with the widest blast radius
  • Git history forensics — reverted commits ("don't do this" signals), co-change coupling (invisible dependencies), rapid re-edits (code that was hard to get right), anti-patterns from abandoned approaches
  • Convention detection — naming patterns, export style, import organization, barrel exports, path aliases, type hint usage, error handling style
  • Framework detection — Next.js, Expo, Supabase, Tailwind, Express, TypeScript, Django, FastAPI, Flask, Go (Gin, Echo, Fiber)
  • Context-rot-aware formatting — critical constraints at the top, reference info in the middle, action prompts at the bottom (optimized for LLM attention patterns)
  • Smart budget enforcement — when context exceeds your token budget, drops low-priority sections first (keeps critical constraints always)

Quick Start

# Generate CLAUDE.md + AGENTS.md for your project
npx sourcebook init

# Generate for a specific tool
npx sourcebook init --format claude,agents  # CLAUDE.md + AGENTS.md (default)
npx sourcebook init --format cursor         # .cursor/rules/sourcebook.mdc + .cursorrules
npx sourcebook init --format copilot        # .github/copilot-instructions.md
npx sourcebook init --format agents         # AGENTS.md only
npx sourcebook init --format all            # All of the above

# Re-analyze while preserving your manual edits
npx sourcebook update

# See what changed since last generation (exit code 1 = changes found)
npx sourcebook diff

# Limit output to a token budget (drops low-priority sections first)
npx sourcebook init --budget 1000

Commands

Command What it does
sourcebook init Analyze codebase and generate context files (CLAUDE.md + AGENTS.md by default)
sourcebook update Re-analyze while preserving sections you added manually
sourcebook diff Show what would change without writing files (exit code 1 if changes found — useful for CI)
sourcebook ask <query> Query codebase knowledge in natural language
sourcebook watch Auto-regenerate context files when source changes
sourcebook serve Start an MCP server exposing live codebase intelligence

Options

Flag Description Default
-d, --dir <path> Target directory .
-f, --format <formats> Output formats: claude, agents, cursor, copilot, all claude,agents
--budget <tokens> Max token budget for output 4000
--dry-run Preview findings without writing files

Language Support

Language Framework Detection Convention Detection Import Graph Git Analysis
TypeScript/JavaScript Next.js, Expo, Vite, React, Express, Tailwind, Supabase Barrel exports, path aliases, export style, error handling Full Full
Python Django, FastAPI, Flask, pytest Type hints, __init__.py barrels Full Full
Go Gin, Echo, Fiber Module path, cmd/pkg/internal layout, error wrapping, interfaces Full Full

GitHub Action

Auto-update context files on every merge:

# .github/workflows/sourcebook.yml
name: Update context files
on:
  push:
    branches: [main]

jobs:
  sourcebook:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: maroondlabs/sourcebook@main
        with:
          format: all

Example Output

Running on cal.com (10,456 files):

sourcebook
Extracting repo truths...

✓ Scanned project structure
  10,456 files, 3 frameworks detected
✓ Extracted 11 findings

  ● Core modules: types.ts imported by 183 files — widest blast radius
  ● Circular deps: bookingScenario.ts ↔ getMockRequestData.ts
  ● Co-change: auth/provider.ts ↔ middleware/session.ts (88% correlation)
  ● Dead code: 1,907 orphan files detected
  ● Conventions: named exports preferred (26:2 ratio)
  ● Barrel exports: 40 index.ts re-export files
  ● Commit style: Conventional Commits (feat/fix/docs)

✓ Wrote CLAUDE.md
✓ Wrote AGENTS.md

How It Works

sourcebook runs five analysis passes, all deterministic and local — no LLM, no API keys, no network calls:

  1. Static analysis — framework detection, build commands, project structure, environment variables
  2. Import graph — builds a directed graph of all imports, runs PageRank to find the most structurally important files
  3. Git forensics — mines commit history for reverts, anti-patterns, co-change coupling, churn hotspots, and abandoned approaches
  4. Convention inference — samples source files to detect naming, import, export, error handling, and type annotation patterns
  5. Budget enforcement — if output exceeds your token budget, intelligently drops low-priority sections (supplementary findings first, critical constraints never)

Then applies a discoverability filter: for every finding, asks "can an agent figure this out by reading the code?" If yes, drops it. Only non-discoverable information makes it to the output.

Output is formatted for context-rot resistance — critical constraints go at the top and bottom of the file (where LLMs pay the most attention), lightweight reference info goes in the middle.

MCP Server

sourcebook serve starts a local MCP (Model Context Protocol) server that exposes live codebase intelligence to any MCP-compatible AI client — Claude Desktop, Cursor, and others.

Instead of a static context file, your AI agent can query your project's architecture on demand: look up blast radius before editing, check conventions before writing code, mine git history for anti-patterns.

Installation

Add sourcebook to your MCP client config:

{
  "mcpServers": {
    "sourcebook": {
      "command": "npx",
      "args": ["-y", "sourcebook", "serve", "--dir", "/path/to/your/project"]
    }
  }
}

Claude Code — run in your terminal:

claude mcp add sourcebook -- npx -y sourcebook serve --dir /path/to/your/project

Or add manually to ~/.claude/claude_desktop_config.json.

Claude Desktop — add to ~/Library/Application Support/Claude/claude_desktop_config.json.

Cursor — add to .cursor/mcp.json in your project or ~/.cursor/mcp.json globally.

Other MCP clients — any client that supports STDIO transport works with the same config block above.

Restart your client after updating the config.

Available Tools

Tool What it does
analyze_codebase Full analysis: languages, frameworks, findings, top files by PageRank importance
get_file_context File-level context: importance score, hub status, co-change partners, applicable conventions
get_blast_radius Risk assessment for editing a file: dependents, co-change coupling, fragility, circular deps
query_conventions All detected project conventions: import style, error handling, naming, commit format
get_import_graph Dependency architecture: hub files, circular deps, dead code, PageRank rankings
get_git_insights Git history mining: fragile files, reverted commits, anti-patterns, active dev areas
get_pressing_questions Pre-edit briefing: everything important to know before touching a specific file
search_codebase_context Keyword search across all findings, conventions, structure, and frameworks

The server caches the scan in memory — subsequent tool calls are fast. Pass refresh: true to analyze_codebase to force a re-scan.

Roadmap

  • [x] .cursor/rules/sourcebook.mdc + legacy .cursorrules output
  • [x] .github/copilot-instructions.md output
  • [x] sourcebook update — re-analyze while preserving manual edits
  • [x] sourcebook diff — show what changed (CI-friendly exit codes)
  • [x] --budget <tokens> — smart PageRank-based prioritization
  • [x] Anti-pattern detection from reverted commits and deleted files
  • [x] Python support (Django, FastAPI, Flask, pytest)
  • [x] Go support (Gin, Echo, Fiber, module layout)
  • [x] GitHub Action for CI
  • [x] sourcebook serve — MCP server mode
  • [ ] Framework knowledge packs (community-contributed)
  • [ ] Tree-sitter AST parsing for deeper convention detection
  • [ ] Hosted dashboard with context quality scores

Research Foundation

Built on findings from:

  • ETH Zurich AGENTS.md study — auto-generated obvious context hurts agent performance
  • Karpathy's autoresearch — curated context (program.md) is the #1 lever for agent effectiveness
  • Aider's repo-map — PageRank on import graphs for structural importance
  • Chroma's context-rot research — LLMs show 30%+ accuracy drops for middle-of-context information

License

BSL-1.1 — source-available, free to use, cannot be offered as a hosted service. Converts to MIT on 2030-03-25. See LICENSE for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选