Communitygithub.com

codehealth-mcp

通过 CodeScene MCP 提供实时的结构性代码健康检查 —— 在编辑前审查代码,在修改后验证分数变化,并在提交和 PR 时设置关卡。当需要审查代码质量、进行重构、检查 AI 修改是否降低了文件健康度,或在提交/PR 前都可使用。

codehealth-mcp 是什么?

本技能(Code Health MCP)基于 CodeScene 的结构性可维护性分析能力,为 AI 辅助编码提供实时的代码健康反馈。它与代码风格/检查技能(如 `coding-standards`、`plankton-code-quality`)互补,重点检测设计层面的健康分数和回归门禁。 技能提供四个独立工具:`code_health_review` 用于修改前进行完整结构性分析,`code_health_score` 用于每次修改后快速获取分数(对比基线),`pre_commit_code_health_safeguard` 用于阻止引入健康度回归的提交,以及 `analyze_change_set` 用于分支级别的 PR 前检查。分数范围为 1-10 分,绿色(9-10)表示健康,黄色(4-8.9)表示有技术债务,红色(1-3.9)表示严重债务。 平台支持:通过 MCP 协议集成,可配合 Claude Code、Cursor 等开发工具使用。需要用户自行设置 `CS_ACCESS_TOKEN` 环境变量,无捆绑凭证。该技能在独立模式下不需要付费的 CodeScene 平台账号。 最佳实践包括:每次修改文件前先获取基线分数,每次编辑后验证分数未下降,在提交和 PR 前强制执行检查。当 MCP 不可用时,不应虚构分数,而是跳过检查并仅在有用户明确许可时继续。建议与 `verification-loop`、`tdd-workflow` 或 `/quality-gate` 等技能配合使用,作为结构性检查的补充,而不是替代测试和 Lint。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/codehealth-mcp

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Code Health MCP (CodeScene)

针对 AI 辅助编码的结构性可维护性反馈。与风格/Lint 类技能(coding-standards、plankton-code-quality)互补,提供设计层面的健康分数和回归门禁。

上游仓库: codescene-oss/codescene-mcp-server 包名: @codescene/codehealth-mcp(通过 npx 的 stdio 方式运行)

安全与边界

选择性加入 (ECC): mcp-configs/mcp-servers.json 中的 codescene 块仅为模板。ECC 插件安装时不会自动启用捆绑的 MCP 服务器。只有在你确实需要时才将该条目复制到你的配置中。你可以在 ECC 安装/同步期间通过 ECC_DISABLED_MCPS=codescene,... 来排除它。

凭证: 无捆绑令牌。请自行设置 CS_ACCESS_TOKEN(参见上游仓库中的 getting-a-personal-access-token.md)。切勿将令牌提交到仓库。

工具读取内容: 调用时,工具会分析你指定的本地仓库中的文件和 git 状态(通过你传递的路径以及 analyze_change_set 的分支上下文)。它们不会自动运行。对于独立模式,请遵循上游隐私文档:codescene-mcp-server README 和 CodeScene 政策。请勿使用本技能分析你不希望被分析的机密、凭证或路径。

如果 MCP 不可用(离线、令牌无效、服务器崩溃): 请勿虚构 Code Health 分数。告知用户检查已被跳过。仅在获得用户明确许可后继续。当 MCP 宕机时,优先使用 Lint/测试/验证循环作为门禁。当服务器重新连接后,再恢复检查。

何时使用

  • 用户要求审查代码质量、重构文件,或检查 AI 修改是否降低了可维护性
  • 在编辑一个热区、遗留模块或不熟悉的文件之前
  • 在提交或拉取请求之前,需要可维护性保障
  • 在大型 Agent 编写的 diff 之后 —— 验证 Code Health 没有退化
  • 与 verification-loop、tdd-workflow 或 /quality-gate 配合使用,作为结构性检查(不是替代测试/Lint)

何时激活

与上述何时使用的触发条件相同 —— 此标题是 ECC 用于技能自动激活的依据。

工作原理

1. 连接 MCP 服务器

将 mcp-configs/mcp-servers.json 中的 codescene 条目复制到你的主环境 MCP 配置中。

Claude Code (~/.claude.json → mcpServers):

"codescene": {
  "command": "npx",
  "args": ["-y", "@codescene/codehealth-mcp"],
  "env": {
    "CS_ACCESS_TOKEN": "YOUR_CS_ACCESS_TOKEN_HERE"
  }
}

项目级配置: 将相同的块合并到仓库根目录下的 .mcp.json 中。

令牌设置在上游仓库中有文档说明(链接见上文)。独立模式下,下面列出的四个工具不需要付费的 CodeScene 平台账户。在依赖分数之前,请重新启动会话并确认 codescene 服务器已连接。

2. 仅调用独立工具

工具何时使用
code_health_review修改前进行完整结构性分析
code_health_score每次修改后快速获取数值分数(Delta 检查)
pre_commit_code_health_safeguard阻止引入 Code Health 回归的提交
analyze_change_set打开 PR 前进行分支级别检查

请不要调用仅平台工具(例如仓库级技术债务热点列表)。请不要引用 delta_analysis —— 该工具在独立模式下不可用。

3. 解读分数 (1–10)

范围含义Agent 行为
9.0–10.0绿色 —— 健康扩展更安全;但仍倾向垂直切片
4.0–8.9黄色 —— 债务谨慎操作;不做附带重构
1.0–3.9红色 —— 严重债务仅做最窄范围的修改

4. 运行反馈循环

在接触文件之前

  1. 对目标路径运行 code_health_review。
  2. 记录基线分数和列出的代码异味。
  3. 规划能够完成任务的最小修改。

按分数界定范围:低于 5 —— 仅做最小 diff;5–7 —— 不要做广泛重构;高于 7 —— 重构相对安全,但每次编辑后仍需验证。

每次修改之后

  1. 对同一文件运行 code_health_score。
  2. 与 code_health_review 得到的基线分数进行比较。
  3. 如果分数下降了,先修复再继续。在分数低于起始时,绝不要宣布任务完成。

每次提交之前 —— 对仓库路径运行 pre_commit_code_health_safeguard。

在 PR 之前 —— 针对基础分支(例如 main)运行 analyze_change_set。

示例

示例:Flask 可维护性改进

在 pallets/flask 上,仅使用独立工具的 Agent 循环:

  1. 对目标模块运行 code_health_review(基线 4.82)
  2. 针对列出的异味进行定向重构
  3. 每次编辑后运行 code_health_score
  4. 提交前运行 pre_commit_code_health_safeguard
  5. PR 前运行 analyze_change_set

结果:Code Health 4.82 → 9.1(仅限免费独立令牌)。

示例:AGENTS.md 强制执行块

粘贴到项目 AGENTS.md 或 CLAUDE.md 中:

## Code Health (CodeScene MCP)

在修改任何文件之前:运行 `code_health_review`,记录分数和问题。

- 分数低于 5:问题范围 —— 窄范围限定修改。
- 分数 5–7:警告范围 —— 不做广泛重构。

每次修改后:运行 `code_health_score` 验证 Delta。

- 如果分数下降:修复后再继续;分数下降时绝不要声明完成。

每次提交前:运行 `pre_commit_code_health_safeguard`。

PR 前:运行 `analyze_change_set`。

示例:反模式 vs 正确循环

# 错误:先编辑,后检查
[不运行 code_health_review 就进行大规模重构]

# 错误:忽略分数下降
"测试通过了" → 在 Code Health 下降时标记任务完成

# 错误:在低分文件(低于 5)上做广泛重构
跨模块进行附带清理

# 正确:审查 → 小修改 → 分数 → 提交保障 → analyze_change_set

与 ECC 配合使用

ECC 技能/流程Code Health MCP 角色
coding-standards风格/命名;Code Health = 结构/复杂度
plankton-code-quality编写时 Lint/格式化;Code Health = 编辑前后结构性门禁
verification-loop / /quality-gate在声明“完成”前增加结构性回归检查
security-review安全 vs 可维护性 —— 在相关时同时使用
tdd-workflow测试通过 ≠ 设计健康 —— 重构后检查分数

上下文提示: ECC 建议保持较少的 MCP 数量。在执行实质性编辑时启用 codescene;不需要时禁用它。

相关技能

  • coding-standards —— 基础约定
  • plankton-code-quality —— 编写时 Lint/格式化钩子
  • verification-loop —— 构建/测试/Lint 门禁
  • tdd-workflow —— 测试驱动开发
  • security-review —— 安全检查清单
  • documentation-lookup —— 通过 Context7 查找库文档(正交)

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相关技能