Skip to main content

AI 编码守门员 — 零配置 + 实时拦截 + 处方化提示 + 精准拦截 + 性能飞跃 + 测试覆盖率优化 + Bug 修复

Project description

Moat — AI 编码护城河 🛡️

版本: v1.1.5 · PyPI: pip install moat-ai · GitHub: wang-jie-git/moat

PyPI version License Python Tests CI

"AI 时代的首席架构官" — 不是 Linter,不是 SAST,是代码库的自动驾驶防碰撞系统。

AI 改代码很快。AI 搞坏系统也很快。Moat 在改代码前/后各跑一次,几秒内告诉你系统有没有被搞坏。


⚔️ Killer 对比:Moat vs 传统工具

Moat 不是 Linter 的替代品,是全新品类:AI Engineering OS Linter 检查语法,SAST 扫描漏洞,Moat 治理架构。

维度 🛡️ Moat 🔧 传统 Linter 📊 SonarQube
核心定位 AI Engineering OS 代码风格检查 代码质量平台
架构治理 ✅ 8 步验收闭环 ❌ 仅语法/风格 ⚠️ 仅代码气味
分层执行 ✅ 内置 5 层规则 + 自定义
增量审计 --diff 2 秒出结果 ⚠️ 仅文件级 ❌ 全量扫描
门禁模式 --fail-on-score 拦截 ⚠️ 部分支持
证据链 ✅ Reason → File → Line ❌ 仅行号
安全注入拦截 ✅ 零误报 ❌ 高噪音
AI 上下文集成 ✅ MCP / Claude Code Hook
性能 < 0.2s / 次 中等 慢(全量扫描)
测试覆盖率 99.8%+ (1020 tests)
配置 零配置 需配置 需配置

✨ 三大独家差异点

🔍 Diff-Aware Audit(增量验收)

全量扫描 4160 个文件?太慢。moat accept --diff 只扫描本次修改的 5 个文件,2 秒完成架构级审计。

# 改了几个文件后,增量验收
moat accept --diff --fail-on-score 60

# 全量验收
moat accept --output ACCEPTANCE_REPORT.md

🧱 Layer-Enforcer(分层执行者)

内置标准 MVC/DDD 分层规则,自动检测 routes/ 直接调用 db/ 等跨层违规。

# 默认 5 层规则:routes → services → db / models / utils
moat accept --diff

通过 architect.yml 自定义任意分层规则。

📋 Evidence-Based(证据驱动)

所有拦截都有完整的证据链,不是黑盒报错:

❌ LAYER_VIOLATION: routes/ 不应直接导入 db/
  → Reason: 分层违规(routes → services → db)
  → File: app/routes/user.py:15
  → Detail: 直接 import db.session

🚀 快速开始

# 安装
pip install moat-ai

# 零配置初始化
moat init

# 基本检查
moat check --quick       # 秒级检查
moat check --full        # 完整检查(含架构审计)

# 架构验收(v1.1.4+)
moat accept              # 8 步架构验收
moat accept --diff       # 增量验收(2 秒)
moat accept --output report.md  # 生成报告

# 门禁模式
moat accept --diff --fail-on-score 60  # 低于 60 分拦截

📍 安装方式

Moat 是一个标准 Python 包,运行在你的本地机器上,代码绝不离开你的机器。

pip install moat-ai       # 项目 venv 或全局安装

与 Claude/Cursor 配合

方式 1:直接调用 CLI(推荐)

Claude 直接在终端中执行 Moat 命令,就像人类开发者一样:

moat check --full              # 完整检查
moat accept                    # 架构验收
moat gatekeeper check --file app.py  # 单文件检查

方式 2:Sidecar 守护进程

moat sidecar start             # 启动守护进程
curl http://localhost:7777/api/health  # REST API

方式 3:静态规则注入

moat adapter claude            # 生成 CLAUDE.md
moat adapter all               # 生成所有 AI 工具规则

📋 完整命令参考

# 核心检查
moat check [--quick|--full|--diff]  # 4 种检查模式
moat init                           # 零配置初始化
moat watch                          # 实时监控日志
moat report                         # 生成检查报告
moat baseline [save|show|diff]      # 基线管理

# 架构验收(v1.1.4+)
moat accept                         # 8 步架构验收
moat accept --diff                  # 增量验收
moat accept --output report.md      # 生成报告
moat accept --fail-on-score 60      # 门禁模式

# 优化检查
moat check --quick --optimize       # 快速 + 优化规则
moat check --full --optimize        # 完整 + 优化规则

# 进化指标
moat evolution report               # 查看进化报告
moat evolution adjust               # 自动调整配置

# Sidecar 守护进程
moat sidecar start                  # 启动守护进程
moat sidecar status                 # 查看状态
moat sidecar stop                   # 停止守护进程

# AI 适配器
moat adapter claude                 # 安装 Claude Code 适配器
moat adapter all                    # 安装所有 AI 工具适配器
moat adapter precommit              # 安装 pre-commit hook

📚 文档


🔑 核心哲学

AI 是一个会撒谎、会贪快、会产生幻觉的个体。

Moat 真正的价值在于:它是 AI 的"刹车片"。

无论 AI 怎么进化,物理定律不变——高速运动需要刹车,复杂系统需要检查点,连续输出需要暂停验证。

为什么这个定位重要

  • 玩具 vs 工具:如果定义为"AI 工程操作系统",它是玩具。如果定义为"刹车片",它是工具。
  • AI 会变强,但不会变诚实:未来 AI 能力更强,但仍有"偷懒倾向"和"记忆盲区"。
  • "刹车"的永恒价值:高速运动需要刹车,复杂系统需要检查点。

You own the code, you own the guard.


🏷️ 标签

ai-agent architecture-guard security-tool code-review static-analysis python gatekeeper devtools lint architecture mcp


许可

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moat_ai-1.1.6.tar.gz (310.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moat_ai-1.1.6-py3-none-any.whl (288.9 kB view details)

Uploaded Python 3

File details

Details for the file moat_ai-1.1.6.tar.gz.

File metadata

  • Download URL: moat_ai-1.1.6.tar.gz
  • Upload date:
  • Size: 310.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for moat_ai-1.1.6.tar.gz
Algorithm Hash digest
SHA256 1c5871bb060914c7d62bbd300733a3b3c930bf915080534ebd95eccb59c29fe4
MD5 d62cb1c99ab17740684055df67e2c376
BLAKE2b-256 0058dfb630bb940ccffb18c9858d808215ce6792d01e2274797773c5a153a6fe

See more details on using hashes here.

File details

Details for the file moat_ai-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: moat_ai-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 288.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for moat_ai-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 15f31cea0665bac73c46fb47de7ad8f9cd48035c5e7ea6d175506bef9a9a7838
MD5 2fbb7c726930a01a7f1fef71ba2a28ac
BLAKE2b-256 25d2903a95e12760acb478d1b299c009e03e61d98c14de54eb1701559046ec13

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page