Drift 标志

Drift

社区
dadbodgeoff

Codebase intelligence for AI. Detects patterns & conventions + remembers decisions across sessions. MCP server for any IDE. Offline CLI.

发布者dadbodgeoff
代码仓库drift
语言TypeScript
复刻数
64
星标数
791
可用工具
22
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    Drift 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 22 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 791 个星标和 64 个复刻。

Drift

Drift stops an AI agent from writing code that violates conventions your repo already follows. It runs entirely on your machine.

Beta install: build from source. Nothing is published to npm yet — npm install -g @drift/cli does not work, and the driftdetect package on npm is the unrelated v1 from January. Building needs a Rust toolchain (rustup) because the scan engine is Rust.

bash
git clone https://github.com/dadbodgeoff/drift.git && cd drift
pnpm install --frozen-lockfile
pnpm build && pnpm build:engine

# There is no `drift` binary yet; the entry point is the built CLI.
alias drift="node $PWD/packages/cli/dist/main.js"
drift doctor --repo-root .          # fails loudly if the toolchain is missing

Then, in the repository you want to protect:

bash
cd your-repo
drift start --repo-root . --accept-defaults

start prints whether the convention it accepted will actually block, and the command to make it a gate if it will not. Now have an agent add a route that queries the database directly, the way a hundred other routes in your repo do not, and check the change:

bash
drift check --diff HEAD~1...HEAD --scope changed-hunks

It names the file, the line, and the convention that was broken. In block mode it exits 2.

--diff main...HEAD only works once your branch has commits that main does not. On a freshly cloned repo you are on main, so that range is empty and Drift refuses rather than reporting a pass it cannot support — exit 3. That refusal is correct; give it a range with changes in it.

Scope — read this before adopting

Drift enforces one convention family well, and says so rather than implying more:

LanguagesTypeScript, JavaScript
FrameworksNext.js API routes (App Router and Pages)
ConventionAPI routes must not import data-access clients directly
StatusBeta — local CLI and a read-only MCP server

It does not review code generally, support other languages, modify your source, or sync anything to a server.

The data layer is recognised when its import specifier contains prisma, database, db or data-access. A repo naming its data layer store or supabase must declare it with --data-modules. Drift bootstraps and enforces a declared layering contract — it does not learn conventions in general, and the claims manifest blocks that claim explicitly.

Security heuristics exist behind --experimental-security and are not proofs. Their own audit is in docs/internal/architecture/security-heuristic-audit.md.

What it does on real repositories

Evaluated on seven open-source Next.js repos on every change (pnpm eval:external):

Onboards, learns the real data layer, catches an injected violation7 / 7
Correct file:line evidence7 / 7
A properly layered route falsely flagged0 / 7
False-positive rate (dub, 494 routes)3.1%
Evasion shapes caught, at the contract's mode (pnpm eval:evasion)66 / 66 testable cells

And, because the number that decides whether a first session is tolerable is not recall but how often Drift declines to answer — eight ordinary edits per repo, none of them a violation (pnpm eval:bench):

Ordinary edits refused rather than answered0 / 56
Local imports the resolver places96.1% – 99.9%

Every check reports its own coverage, so a clean result is never mistaken for full coverage. Where Drift cannot resolve something it says so, with the offending specifiers — see drift doctor and summary.import_coverage.

Why your repo might only warn

If findings appear but the check exits 0, the convention is in warn mode, deliberately.

Drift infers the convention from the violations themselves, so a repo where every route touches the database produces the same statement as one where a single route does. Enforcing both identically would reject new code written exactly like its neighbours. Instead the mode follows the evidence: a minority violating means new violations block; a majority violating means it is a refactor goal, and Drift warns until a human decides.

formbricks (1 route of 83) blocks. dub (~323 of 494) warns.

Documentation

First Five Minutes

From the repo you want Drift to inspect:

bash
drift doctor --repo-root .
drift start --repo-root . --accept-defaults
drift doctor --repo-root .

The first doctor run is a zero-write readiness check. After start, run it again as the ongoing local health gate: it validates SQLite migration compatibility, repo registration, contract compatibility, scan freshness, audit-chain integrity, and tracked backup artifacts, then prints the next upkeep commands.

start --accept-defaults is explicit onboarding confirmation. It accepts the deterministic default convention, materializes the repo contract, and baselines existing findings so legacy drift does not block the first check. Omit --accept-defaults when you want to review every candidate manually first.

drift start prints the local SQLite path:

bash
export DRIFT_DB=/path/to/drift.sqlite

Then use the printed repo id with the review loop:

bash
drift baseline status --repo <repo_id>
drift version --json
drift capabilities --json
drift conventions list --repo <repo_id> --status candidate --kind api_route_no_direct_data_access --capability deterministic_check --limit 20 --offset 0 --json
drift conventions accepted --repo <repo_id> --kind api_route_no_direct_data_access --capability deterministic_check --limit 20 --offset 0 --json
drift conventions show <candidate_id> --repo <repo_id> --json
drift ask "what should I know before changing this route?" --repo <repo_id> --path apps/web/app/api/users/route.ts --json
drift prepare "add user search endpoint" --repo <repo_id> --path apps/web/app/api/users/route.ts --json
drift repo map --repo <repo_id> --role api_route --json
drift repo map --repo <repo_id> --limit 50 --offset 0 --json
drift prepare "add user search endpoint" --repo <repo_id> --require-fresh --json
drift checks list --repo <repo_id> --limit 20 --offset 0 --json
drift checks run --repo <repo_id> --command "pnpm test" --timeout-ms 120000 --json
drift policy check-context --repo <repo_id> --path apps/web/app/api/users/route.ts --surface cli-preflight --require-fresh --json
drift check --diff main...HEAD --repo <repo_id> --scope changed-hunks
drift findings list --repo <repo_id>
drift findings list --repo <repo_id> --convention <convention_id> --json
drift findings list --repo <repo_id> --path apps/web/app/api/users/route.ts --require-fresh --json
drift findings list --repo <repo_id> --limit 25 --offset 0 --json
drift findings show <finding_id> --repo <repo_id> --require-fresh --json
drift backup create --repo <repo_id> --confirm
drift backup list --repo <repo_id> --json
drift backup list --repo <repo_id> --limit 20 --offset 0 --json
drift backup list --repo <repo_id> --artifact-status missing --json
drift audit list --repo <repo_id>
drift audit verify --repo <repo_id> --json
drift audit list --repo <repo_id> --target-id <repo_id> --limit 20 --offset 0 --json
drift audit list --repo <repo_id> --since 2026-05-10T00:00:00.000Z --until 2026-05-11T00:00:00.000Z

Backup output prints the verify and restore dry-run commands. Backup list, verify, and restore JSON also include compact summaries so setup scripts can see artifact health, checksum status, restore intent, and rescan requirements without parsing prose:

bash
drift backup verify <backup.sqlite> --repo <repo_id> --checksum <sha256>
drift backup verify <backup.sqlite> --repo <repo_id> --checksum <sha256> --require-checksum
drift --db <target.sqlite> restore <backup.sqlite> --repo <repo_id> --checksum <sha256> --dry-run
drift --db <target.sqlite> restore <backup.sqlite> --repo <repo_id> --checksum <sha256> --require-checksum --dry-run

For stricter restore identity checks, pass the expected repo fingerprint:

bash
drift backup verify <backup.sqlite> --repo <repo_id> --expect-repo-fingerprint <fingerprint>
drift --db <target.sqlite> restore <backup.sqlite> --repo <repo_id> --expect-repo-fingerprint <fingerprint> --dry-run

Contract exports can stay on stdout or be written to one approved artifact:

bash
drift contract export --repo <repo_id> --format json --output ./repo-contract.json --confirm
drift contract import ./repo-contract.json --dry-run
drift contract import ./repo-contract.json --checksum <sha256> --dry-run
drift contract import ./repo-contract.json --checksum <sha256> --require-checksum --dry-run

contract show, contract validate, contract export, contract import --dry-run, and MCP get_repo_contract expose a stable contract_fingerprint for compatibility checks. The fingerprint is computed from canonical contract content, so unordered governance lists do not create false drift.

scan status, prepare, MCP get_scan_status, and MCP get_task_preflight expose a stable scan_fingerprint for the indexed graph plus no-approval governance metadata, summary counts, indexed_file_count, source_change_count, audit integrity, and next commands. Agents can compare the fingerprint before acting and after rescans without reading source code.

ask, prepare, and MCP get_task_preflight can target a specific repo-relative --path, which pins that file into the preflight packet with a requested path reason. Agent-facing context commands also support --require-fresh / require_fresh; when set, Drift refuses stale scan context and tells the agent which drift scan command to run. repo map and MCP get_repo_map include per-file impact annotations for matching conventions, risky areas, and open findings, plus an impact_summary.

policy check-context and MCP get_allowed_context are the path-level gate for agent context access. They return the policy decision, no-approval governance metadata, summary counts, next commands, freshness requirement, scan status, redaction caps, and indexed file impact metadata without reading or emitting source snippets.

findings list --path, findings list --convention, findings list --limit --offset, findings show, and MCP get_findings({ path, convention_id, limit, offset }) give agents and humans bounded review queues plus a drill-down view for one finding. Add --require-fresh / require_fresh when stale findings should be refused before an agent acts.

conventions list --kind --capability --limit --offset keeps the human approval queue bounded and machine-checkable. Use it to separate deterministic blocking candidates from heuristic briefing candidates before accepting anything into the repo contract.

ask, repo map, and MCP get_repo_map are deterministic local context surfaces. They answer from approved contracts, findings, file roles, imports, exports, calls, scan metadata, and policy state; they do not call an LLM, do not mutate Drift state, and do not include source snippets. repo map and MCP get_repo_map support limit/offset pagination so large repo maps stay scriptable.

audit verify --json and MCP get_audit_status check the local audit hash chain and report summary counts, next commands, and the current head hash. Backup verification and restore dry-runs also validate the audit chain and expose summary fields for schema support, checksum checks, artifact size, write intent, and stale-graph rescan guidance.

audit list --target-id --limit --offset keeps governance timelines scriptable as local state grows. Audit events are returned in deterministic created-time order, with total, filtered, returned, and next-offset metadata.

doctor --json includes the same production-state signals in one automation-friendly payload: applied migrations, unsupported/missing migrations, contract schema/fingerprint, scan staleness, audit integrity, backup count, backup artifact problems, and next_commands for initialized repos.

State Model

Drift stores product state in SQLite, not a folder full of JSON files.

The database owns:

  • repo identity
  • scan manifests
  • file snapshots and hashes
  • extracted facts
  • convention candidates and accepted conventions
  • repo contracts
  • findings
  • baselines
  • policies
  • audit events
  • backup manifests

JSON is only an interface format for CLI automation, MCP responses, contract import/export, and tests.

What Requires Approval

Commands that do not require governance approval:

bash
drift doctor
drift scan
drift scan status
drift prepare
drift check
drift findings list
drift audit list

Some of these commands write local Drift state, such as scan, start, and check. The important boundary is that they do not mutate source code or approve governance decisions.

Governance changes require explicit human intent:

bash
drift conventions accept <candidate_id> --confirm
drift conventions reject <candidate_id> --reason "..." --confirm
drift conventions edit <candidate_id> --statement "..." --confirm
drift conventions exception add <convention_id> --path <glob> --reason "..." --confirm
drift findings mark-fixed <finding_id> --evidence <file:line> --confirm
drift findings mark-needs-review <finding_id> --reason "..." --confirm
drift findings suppress <finding_id> --reason "..." --confirm
drift findings accept-drift <finding_id> --reason "..." --confirm
drift findings mark-false-positive <finding_id> --reason "..." --confirm
drift baseline create --from main --confirm
drift baseline clear --convention <convention_id> --confirm
drift policy set-egress ... --confirm
drift policy agent grant ... --confirm
drift policy agent revoke ... --confirm
drift contract export ... --confirm
drift contract import <path> --confirm
drift contract waiver add ... --confirm
drift contract waiver remove ... --confirm
drift backup create --confirm
drift restore <backup.sqlite> --confirm

Architecture

Rust owns the bounded-memory scanning and rule-critical engine pieces.

TypeScript owns the CLI, MCP server, SQLite storage boundary, policy enforcement, onboarding, and packaging.

The product boundary is intentionally CLI-first. The desktop UI comes after the CLI review loop is stable.

Core Wedge Support Matrix

SurfaceStatus
TypeScript/JavaScript API route layeringSupported
Local SQLite stateSupported
CLI review loopSupported
Read-only MCP contextSupported
Backup/restore of Drift stateSupported
Python adapterDeferred
Desktop UIDeferred
Cloud syncDeferred
Duplicate helper detectionDeferred

Drift does not mutate source code. It stores repo intelligence locally, guides humans and agents with evidence, and requires explicit human confirmation for governance changes.

Use drift capabilities --json or MCP get_capabilities to discover the supported command surface, no-approval agent tools, human-confirmed governance mutations, and deferred surfaces.

Package Smoke

The e2e suite packs and installs the workspace packages into a clean consumer project, then runs:

  • installed drift doctor
  • installed drift scan
  • installed drift conventions list --kind --capability --limit --offset
  • installed drift conventions accepted --kind --capability --limit --offset
  • installed drift start --accept-defaults
  • installed drift scan status
  • installed drift ask
  • installed drift prepare
  • installed drift repo map
  • installed drift repo map --limit --offset
  • installed drift checks list --limit --offset
  • installed drift checks run
  • installed drift baseline status
  • installed drift contract show
  • installed drift check
  • installed drift findings list
  • installed drift findings list --convention
  • installed drift findings list --limit --offset
  • installed drift findings list --path --require-fresh
  • installed drift findings show
  • installed drift findings mark-needs-review --confirm
  • installed drift findings mark-fixed --confirm
  • installed drift audit list
  • installed drift audit list --target-id --limit --offset
  • installed drift audit verify
  • installed drift backup create --confirm
  • installed drift backup list
  • installed drift backup list --artifact-status --limit --offset
  • installed drift backup verify
  • installed drift restore --dry-run
  • installed drift restore --confirm
  • installed drift version --json
  • installed drift capabilities --json
  • installed MCP get_runtime_info
  • installed MCP get_capabilities
  • installed MCP get_audit_status
  • installed MCP get_scan_status
  • installed MCP get_repo_contract
  • installed MCP get_repo_map
  • installed MCP get_task_preflight
  • installed MCP get_conventions
  • installed MCP get_findings
  • installed MCP get_required_check_executions
  • installed MCP get_allowed_context
  • installed drift-mcp
  • pnpm beta:proof

Run the full gate:

bash
pnpm verify:full

verify:full is two gates. pnpm verify:ci is the half a hosted runner can execute and is what GitHub Actions runs on every PR. pnpm verify:evals is the external-repo battery — it requires the seven pinned evaluation repos cloned locally and is not run by CI.

pnpm verify:ci includes pnpm beta:proof, which proves a fresh Rust scan, an accepted contract, a service-delegated route passing, a new direct data-access route blocking, evidence-complete findings, full schema-stable CLI/MCP parity, and audit hash-chain verification.

安装

TypingMind
前提条件:

Node.js 18+

{
  "mcpServers": {
    "dadbodgeoff-drift": {
      "command": "npx",
      "args": [
        "-y",
        "drift"
      ]
    }
  }
}

可用工具

  • drift_context

    Get curated context for a specific task. This is the RECOMMENDED STARTING POINT for any code generation task.

    Instead of calling multiple tools and synthesizing results yourself, tell drift_context what you're trying to do and it will return everything you need:

    • Relevant patterns with examples
    • Files you'll likely need to modify
    • Guidance on how to approach the task
    • Warnings about potential issues
    • Confidence signals so you know when to verify

    WHEN TO USE:

    • Starting any code generation task
    • Before making changes to unfamiliar code
    • When you need to understand how something is done in this codebase

    MULTI-PROJECT SUPPORT:

    • Use the optional "project" parameter to target a specific registered project
    • Projects are registered via "drift projects add "
    • Use drift_projects action="list" to see available projects

    EXAMPLE: intent: "add_feature", focus: "user authentication" → Returns auth patterns, example code, files to modify, security warnings

    intent: "fix_

  • drift_status

    Get codebase health snapshot. Call this first to understand the current state. Returns pattern counts, health score, and critical issues. Always fast, always lightweight.

  • drift_capabilities

    List all Drift capabilities and when to use each tool. Returns a guide to available tools organized by purpose. Use this when unsure which tool to use.

  • drift_projects

    List and manage registered drift projects. Enables working across multiple codebases. Actions: list (show all), info (project details), switch (change active), recent (recently used), register (add new).

  • drift_patterns_list

    List patterns with summaries. Returns pattern IDs for use with drift_pattern_get. Supports filtering by category, status, and confidence.

  • drift_security_summary

    Get security posture overview. Shows sensitive data access patterns, security issues, and data flow summary. Use before working on security-sensitive code.

  • drift_contracts_list

    List API contracts between frontend and backend. Shows verified contracts, mismatches, and discovered endpoints.

  • drift_trends

    Get pattern trend analysis. Shows how patterns have changed over time, regressions, and improvements.

  • drift_pattern_get

    Get complete details for a specific pattern. Includes all locations, outliers, confidence breakdown, and examples. Use pattern ID from drift_patterns_list.

  • drift_code_examples

    Get real code examples for patterns. Shows how patterns are implemented in this codebase. Essential before generating new code.

  • drift_files_list

    List files with patterns matching a glob pattern. Shows pattern counts and categories per file. Supports pagination.

  • drift_file_patterns

    Get all patterns found in a specific file. Shows pattern details, locations within the file, and outliers.

  • drift_impact_analysis

    Analyze the impact of changing a file or function. Shows affected callers, entry points, and sensitive data paths. Use before making changes to understand blast radius.

  • drift_reachability

    Analyze data reachability. Forward: "What data can this code access?" Inverse: "Who can access this data?" Essential for security analysis.

  • drift_dna_profile

    Get the complete styling DNA profile. Shows how components are styled (variants, responsive, states, theming, spacing, animation) with confidence scores.

  • drift_wrappers

    Detect framework wrapper patterns. Identifies custom abstractions built on top of framework primitives (React hooks, Express middleware, etc.). Shows clusters of similar wrappers with confidence scores.

  • drift_test_topology

    Analyze test-to-code mappings, mock patterns, and test quality. Actions: status (overview), coverage (file coverage), uncovered (find gaps), mocks (mock analysis), affected (minimum test set), quality (test quality metrics).

  • drift_coupling

    Analyze module dependencies, detect cycles, and calculate coupling metrics (Robert C. Martin metrics). Actions: status (overview), cycles (dependency cycles), hotspots (highly coupled modules), analyze (specific module), refactor-impact (change impact), unused-exports (dead exports).

  • drift_error_handling

    Analyze error handling patterns, boundaries, and gaps. Detects unhandled error paths and swallowed exceptions. Actions: status (overview), gaps (find issues), boundaries (error boundaries), unhandled (unhandled paths), analyze (specific function).

  • drift_suggest_changes

    Get AI-guided suggestions for fixing pattern violations, security issues, or code quality problems. Returns specific code changes with before/after examples and rationale.

  • drift_validate_change

    Validate proposed code changes against codebase patterns. Returns compliance score, violations, and suggestions. Use before committing changes to ensure consistency.

  • drift_explain

    Get a comprehensive explanation of code in context of the codebase. Combines pattern analysis, call graph, security implications, and dependencies into a coherent narrative.

将 Drift MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Drift 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请勿关闭终端窗口或停止其中的连接器进程。
3

将 Drift 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Drift MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "dadbodgeoff-drift": {
      "command": "npx",
      "args": [
        "-y",
        "drift"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Drift MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Drift MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Drift 帮我完成这项任务吗?
Drift
当然,我看过了。
以下是我使用 Drift 得到的结果。

常见问题

Drift MCP 服务器有什么用途?

Drift 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Drift MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您无需为每个模型单独配置 MCP 服务器,就能在 Claude、ChatGPT、Gemini 或您在 TypingMind 中配置的其他 AI 模型中使用 Drift。

为什么在 TypingMind 中使用 Drift MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是最出色的大语言模型聊天前端之一。连接 Drift 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Drift MCP 连接到 TypingMind?

Drift 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Drift MCP 在 TypingMind 中提供哪些工具?

Drift 提供 22 个 MCP 工具,您可以在 TypingMind 的插件页面启用这些工具,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Drift MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行选择模型提供商,并自行管理 API 密钥、提示词和 MCP 配置。如果 Drift 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇