knowledge-bridge

知识桥接,公司规范索引,反模式库

⭐26stars🔀6forks📁View on GitHub🕐Updated Jan 9, 2026

When & Why to Use This Skill

The Knowledge Bridge skill serves as a centralized intelligence hub that aligns development workflows with company-wide standards and project-specific conventions. By indexing external specifications and maintaining a comprehensive anti-pattern library, it enables AI agents to enforce best practices in security, performance, and architecture, significantly reducing technical debt and improving code maintainability.

Use Cases

  • Automated Code Auditing: Use the anti-pattern library to detect and resolve common issues like N+1 database queries, SQL injection risks, and improper type usage (e.g., 'any' in TypeScript).
  • Standardized Onboarding: Provide new team members with instant access to company-specific frontend, backend, and API standards, ensuring consistent output from day one.
  • Project Convention Enforcement: Maintain structural integrity by automatically checking code against project-specific naming conventions, file organization, and Git commit protocols.
  • Continuous Quality Improvement: Capture recurring code review feedback and transform it into executable rules within the anti-pattern library to create a self-improving development lifecycle.
nameknowledge-bridge
description知识桥接,公司规范索引,反模式库

Knowledge Bridge Skill

知识桥接,连接外部规范和项目约定。

🔗 外部规范索引

注意: 请将以下路径修改为你实际的本地路径。

## 公司规范

- **前端规范**: ~/.claude/references/frontend-standards.md
- **后端规范**: ~/.claude/references/backend-standards.md
- **API规范**: ~/.claude/references/api-standards.md
- **UI组件库**: ~/.claude/references/design-system.md

🚫 反模式库 (Anti-Patterns)

通用反模式

// ❌ 禁止: 使用 any 类型
const data: any = response.data;

// ✅ 正确: 明确类型
const data: UserResponse = response.data;
// ❌ 禁止: 硬编码 Secret/Token
const apiKey = 'sk-xxx';

// ✅ 正确: 环境变量
const apiKey = process.env.API_KEY;

数据库反模式

// ❌ 禁止: 循环中数据库查询 (N+1问题)
for (const user of users) {
  const orders = await db.query('SELECT * FROM orders WHERE user_id = ?', [user.id]);
}

// ✅ 正确: 批量查询
const orders = await db.query('SELECT * FROM orders WHERE user_id IN (?)', [userIds]);

安全反模式

// ❌ 禁止: SQL拼接
const sql = `SELECT * FROM users WHERE id = ${userId}`;

// ✅ 正确: 参数化查询
const user = await db.query('SELECT * FROM users WHERE id = $1', [userId]);
// ❌ 禁止: 直接输出用户输入
element.innerHTML = userInput;

// ✅ 正确: 转义输出
element.textContent = userInput;

架构反模式

// ❌ 禁止: 过度抽象
abstract class AbstractFactory<T extends BaseEntity> { }

// ✅ 正确: 简单直接
function createUser(data: CreateUserDTO): User { }

📝 项目约定

在项目 .ai_state/conventions.md 中记录:

## 项目约定

### 命名规范
- 组件: PascalCase
- 函数: camelCase
- 常量: UPPER_SNAKE_CASE

### 文件结构
- 组件: src/components/
- 页面: src/pages/
- 工具: src/utils/

### Git规范
- feat: 新功能
- fix: 修复
- refactor: 重构

🔄 规范更新

代码审查意见应沉淀为可执行的规则:

1. 发现问题
2. 记录到反模式库
3. 更新自动化检查
4. 形成持续改进闭环

使用方式

// 加载知识桥接
skill.load("knowledge-bridge");

// 检查代码是否违反反模式
knowledge.checkAntiPatterns(code);

// 获取项目约定
knowledge.getConventions();