Skip to main content
Glama

快速入门

npx speclock protect              # Install in your project (creates CLAUDE.md if missing)
speclock mcp install claude-code  # Wire up MCP for Claude Code (or cursor, windsurf, cline, codex)
speclock doctor                   # Verify everything is set up correctly

就是这样。你的 AI 现在有了它无法忽视的规则。默认模式为 WARN(仅发出响亮的警告,不进行拦截)。如需开启强制执行,请使用 speclock protect --strict

Related MCP server: @event4u/agent-config

v5.5.4 有什么新功能

  • 默认 WARN 模式 — 不再有误报拦截。改为响亮的警告。通过 --strictSPECLOCK_STRICT=1 开启严格模式。

  • speclock mcp install <client> — 适用于 Claude Code、Cursor、Windsurf、Cline、Codex 的自动安装程序。无需再手动编辑 JSON。

  • Greenfield 支持 — 在新项目中运行 speclock protect 会自动创建带有安全默认值的 CLAUDE.md。

  • speclock doctor — 健康检查,验证安装、git 钩子、规则文件和 MCP 集成。为任何问题打印精确的修复命令。

什么是 SpecLock?

SpecLock 是一个 AI 约束引擎,可在每次 AI 编码会话中强制执行你的项目规则。 你的 AI 总是在破坏你禁止它触碰的东西 —— SpecLock 让它停止。

命令参考

speclock protect                      # Install pre-commit hook + extract locks from rule files
speclock protect --strict             # Hard enforcement mode (blocks violations)
speclock doctor                       # Health check — verifies install, hooks, rules, MCP
speclock mcp install <client>         # Wire up MCP server (claude-code, cursor, windsurf, cline, codex)
speclock check "action description"   # Test if an action would conflict with locks
speclock add-lock "rule"              # Add a new lock
speclock list-locks                   # Show all locks
speclock enforce hard|advisory        # Change enforcement mode

完整命令参考:npx speclock help


You:    "Never touch the auth system"
AI:     🔒 Locked.

         ... 5 sessions later ...

You:    "Add social login to the login page"
AI:     ⚠️  BLOCKED — violates lock "Never touch the auth system"
        Matched: auth → authentication (synonym), login → auth (concept)
        Confidence: 100%
        Should I find another approach?

在 Claude 的独立测试套件中获得 100/100 分。19 个套件共 991 项测试。0 误报。每次检查耗时 15.7 毫秒。

问题所在

AI 编码工具现在有了记忆。Claude Code 有 CLAUDE.md。Cursor 有 .cursorrules。Mem0 也存在。

但没有强制执行的记忆是无用的。

你的 AI 记得 你使用 PostgreSQL —— 然后它切换到 MongoDB,因为它“看起来更好”。你的 AI 记得 你的身份验证设置 —— 然后在“修复”错误时重写了它。你在 3 次会话前说“永远不要触碰支付逻辑” —— AI 根本不在乎。

记住并不代表尊重。 没有现有的工具能阻止 AI 破坏你锁定的内容。

工作原理

你设置约束。SpecLock 强制执行它们 —— 跨会话、跨工具、跨团队。

speclock lock "Never modify auth files"           → auto-guards src/auth/*.ts
speclock lock "Database must stay PostgreSQL"      → catches "migrate to MongoDB"
speclock lock "Never delete patient records"       → catches "clean up old data"
speclock lock "Don't touch the payment flow"       → catches "streamline checkout"

语义引擎不进行关键词匹配。它理解:

  • “清理旧数据” = 删除(委婉语检测)

  • “简化结账流程” = 修改支付流程(同义词 + 概念映射)

  • “暂时禁用日志记录” = 禁用日志记录(时间规避检测)

  • “更新 UI 并删除用户表” = 隐藏违规(复合句拆分)

并且它知道什么是安全的:

  • “启用审计日志” 当锁定的规则说“永远不要禁用审计日志”时 → 无冲突(意图对齐)

各平台快速入门

Bolt.new / Aider / 任何 npm 平台

npx speclock setup --goal "Build my app" --template nextjs

创建 SPECLOCK.md,将规则注入 package.json,生成 .speclock/context/latest.md。AI 会自动读取这些文件。

Claude Code

添加到 .mcp.json

{
  "mcpServers": {
    "speclock": {
      "command": "npx",
      "args": ["-y", "speclock", "serve", "--project", "."]
    }
  }
}

Cursor / Windsurf / Cline

相同的配置 —— 添加到 .cursor/mcp.json 或等效文件。

Lovable (无需安装)

  1. 前往 Settings → Connectors → New MCP server

  2. 输入 URL: https://speclock-mcp-production.up.railway.app/mcp

  3. 项目说明 粘贴到 Knowledge 中


为什么选择 SpecLock 而不是替代品?

Claude Memory

Mem0

.cursorrules

SpecLock

记住上下文

手动

阻止 AI 破坏内容

语义冲突检测

100/100 分,0% 误报

防篡改审计追踪

HMAC-SHA256 链

强制执行 (AI 无法继续)

SOC 2 / HIPAA 合规导出

加密存储 (AES-256-GCM)

RBAC + API 密钥认证

4 种角色

代码即策略 DSL

YAML 规则

适用于 Bolt.new, Lovable 等

其他工具只是记住。SpecLock 负责强制执行。


语义引擎

不是关键词匹配 —— 而是通过 Gemini Flash 混合模型进行真正的语义分析,实现通用领域覆盖。在 Claude 的独立对抗性测试电池(7 个套件,包括误报、问题框架、补丁网关和差异分析)中得分 100/100

底层技术: 65+ 同义词组 · 80+ 委婉语映射 · 领域概念图(金融科技、电子商务、物联网、医疗保健、SaaS、支付、游戏、电信、政府) · 意图分类器 · 复合句拆分器 · 时间规避检测器 · 动词时态归一化 · UI 美化检测 · 安全意图模式 · 被动语态解析 —— 全部使用纯 JavaScript。Gemini Flash 混合模型用于灰色地带情况 ($0.01/1000 次检查)。


强制执行

两种模式:

Advisory (default):  AI gets a warning, decides what to do
Hard mode:           AI is BLOCKED — MCP returns isError, AI cannot proceed
speclock enforce hard   # Enable hard mode — violations above threshold are blocked
  • 可配置阈值 — 默认 70%。仅高置信度冲突会被拦截。

  • 附带理由覆盖speclock override <lockId> "JIRA-1234: 由 CTO 批准"(记录到审计追踪)

  • 自动升级 — 锁定被覆盖 3 次以上 → 自动标记以供审查


企业安全

API 密钥认证 + RBAC

speclock auth create-key --role developer --name "CI Bot"
# → sk_speclock_a1b2c3... (shown once, stored as SHA-256 hash)

角色

读取

写入锁定

覆盖

管理员

viewer

developer

附带理由

architect

admin

AES-256-GCM 加密

export SPECLOCK_ENCRYPTION_KEY="your-secret"
speclock encrypt   # Encrypts brain.json + events.log at rest

PBKDF2 密钥派生 (100K 次迭代)。认证加密。符合 HIPAA 2026 标准。

HMAC 审计链

每个事件都会获得一个链接到前一个事件的 HMAC-SHA256 哈希。修改任何内容 —— 链条就会断裂。

$ speclock audit-verify

✓ Audit chain VALID — 247 events, 0 broken links, no tampering detected.

合规导出

speclock export --format soc2    # SOC 2 Type II report (JSON)
speclock export --format hipaa   # HIPAA PHI protection report
speclock export --format csv     # All events for auditor spreadsheets

代码即策略

用于组织范围强制执行的声明式 YAML 规则:

# .speclock/policy.yml
rules:
  - name: "HIPAA PHI Protection"
    match:
      files: ["**/patient/**", "**/medical/**"]
      actions: [delete, modify, export]
    enforce: block
    severity: critical

  - name: "No direct DB mutations"
    match:
      files: ["**/models/**"]
      actions: [delete]
    enforce: warn
    severity: high

在项目之间导入和导出策略。在整个组织内共享约束模板。


REST API v2

实时约束检查、补丁审查和自主系统:

# Patch Gateway (v5.1)
POST /api/v2/gateway/review        { description, files, useLLM }

# AI Patch Firewall (v5.2)
POST /api/v2/gateway/review-diff   { description, files, diff, options }
POST /api/v2/gateway/parse-diff    { diff }

# Typed constraint checking
POST /api/v2/check-typed    { metric, value, entity }
POST /api/v2/check-batch    { checks: [...] }

# SSE streaming (real-time violations)
GET  /api/v2/stream

# Spec Compiler
POST /api/v2/compiler/compile  { text, autoApply }

# Code Graph
GET  /api/v2/graph/blast-radius?file=src/core/memory.js
GET  /api/v2/graph/lock-map
POST /api/v2/graph/build

51 个 MCP 工具

工具

功能

speclock_init

在项目中初始化 SpecLock

speclock_get_context

完整上下文包(核心工具)

speclock_set_goal

设置项目目标

speclock_add_lock

添加约束 + 自动保护文件

speclock_remove_lock

软删除锁定

speclock_add_decision

记录架构决策

speclock_add_note

添加固定笔记

speclock_set_deploy_facts

记录部署配置

工具

功能

speclock_check_conflict

针对所有锁定的语义冲突检查

speclock_set_enforcement

切换建议/强制模式

speclock_override_lock

附带理由覆盖(记录审计)

speclock_override_history

查看覆盖审计追踪

speclock_semantic_audit

分析 git diff 针对锁定的情况

speclock_detect_drift

扫描约束违规

speclock_audit

预提交时审计暂存文件

工具

功能

speclock_session_briefing

开始会话 + 完整简报

speclock_session_summary

结束会话 + 记录摘要

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

Maintenance

Maintainers
Response time
6dRelease cycle
7Releases (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
    F
    maintenance
    Governance kernel for AI agents — policy enforcement, code safety verification, multi-model hallucination detection (CMVK), trust attestation (IATP), and immutable audit trails. Works with Claude Desktop, Cursor, and any MCP client.
    72
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    Universal AI Agent OS — governed skills, rules, and commands for AI coding assistants (Claude Code, Augment, Cursor, Copilot, Windsurf). Read-only MCP bridge serves prompts and resources from a release-pinned content bundle.
    6
    20
    3,005
    7
    MIT
  • F
    license
    -
    quality
    A
    maintenance
    Analyzes repositories, explains architecture, calculates change impact, and enforces guardrails for AI Agents like Claude Code, Cursor, and Codex via MCP tools.

View all related MCP servers

Related MCP Connectors

  • 33 tools that make AI write, implement, and verify intent against explicit, testable constraints.

  • Zero-install security baseline for AI coding agents — OWASP/CWE-cited rules over MCP.

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

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/sgroy10/speclock'

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