mirror of
https://github.com/val1813/kwcode.git
synced 2026-09-03 06:34:30 +08:00
feat: v1.0.0 — 5 meta-experts + 15 SKILL.md knowledge layer, architecture finalized
Meta-expert system (atomic capabilities, fixed): 1. Locator — BM25+AST call graph code localization 2. Generator — LLM code generation with domain knowledge injection 3. Verifier — syntax check + pytest validation 4. Debugger — runtime variable capture via sys.settrace 5. Reviewer — requirement alignment check (LLM compares intent vs changes) Knowledge layer (SKILL.md progressive disclosure, extensible): 15 domain experts converted from YAML to SKILL.md directory format - Level 1 (Gate): name+keywords ~100 tokens/expert - Level 2 (Generator): full instructions loaded only for matched expert - Level 3 (on-demand): deterministic scripts, never enter LLM context Key decisions based on 2025-2026 research: - Experts split by atomic capability, not business domain (arXiv:2604.09780) - Progressive disclosure prevents noise (Anthropic Agent Skills) - Only specific domain knowledge helps; generic rules hurt (SWE-Skills-Bench) - 5 atomic skills compose into all complex tasks (GitHub Copilot paper) Changes: - Add kaiwu/experts/reviewer.py (Reviewer meta-expert) - Convert all 15 experts from .yaml to SKILL.md directories - Delete all .yaml expert files - Add CHANGELOG.md - Update README (meta-expert architecture, version badge) - Bump version to 1.0.0 - 311 tests passing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
102
CHANGELOG.md
Normal file
102
CHANGELOG.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to KWCode are documented here.
|
||||
|
||||
---
|
||||
|
||||
## [1.0.0] - 2026-04-29
|
||||
|
||||
### Architecture: 元专家体系定稿
|
||||
|
||||
KWCode 的专家系统从"按业务领域枚举"升级为"按原子能力分层 + 领域知识注入"。
|
||||
|
||||
**5 个元专家(原子能力层,固定不变):**
|
||||
|
||||
| 元专家 | 能力 | 文件 |
|
||||
|--------|------|------|
|
||||
| Locator | 代码定位(BM25+AST调用图) | `experts/locator.py` |
|
||||
| Generator | 代码生成/编辑 | `experts/generator.py` |
|
||||
| Verifier | 测试验证(pytest) | `experts/verifier.py` |
|
||||
| Debugger | 运行时调试(sys.settrace) | `experts/debug_subagent.py` |
|
||||
| Reviewer | 需求对齐审查 | `experts/reviewer.py` |
|
||||
|
||||
**15 个领域知识(SKILL.md 注入层,可扩展):**
|
||||
|
||||
BugFix · FastAPI · TestGen · API · DeepSeekAPI · Docstring · MyBatis · OfficeDocx · OfficePptx · OfficeXlsx · Refactor · SpringBoot · SQLOpt · TypeHint · UniApp
|
||||
|
||||
领域知识不改变流水线结构,只注入 Generator 的 system_prompt。
|
||||
|
||||
### Added
|
||||
|
||||
- **Reviewer 元专家** (`experts/reviewer.py`):Verifier 通过后用 LLM 对比用户意图和实际变更,判断需求是否对齐
|
||||
- **SKILL.md 渐进式加载**:全部 15 个专家从 YAML 升级为 SKILL.md 目录格式
|
||||
- Level 1(Gate):name + keywords,~100 token/专家
|
||||
- Level 2(Generator):完整领域知识,仅命中专家加载
|
||||
- Level 3(on-demand):确定性脚本,不进 LLM context
|
||||
- **DAG TaskCompiler** (`core/task_compiler.py`):串行+并行多任务调度
|
||||
- **`/multi` 命令**:CLI 多任务模式(分号并行、箭头串行、交互式混合)
|
||||
- **Debug Subagent** (`experts/debug_subagent.py`):verifier 失败后 sys.settrace 捕获运行时变量
|
||||
- **Prompt Optimizer** (`flywheel/prompt_optimizer.py`):飞轮优化 YAML/SKILL.md 的领域知识内容
|
||||
- **Cross-Encoder 重排** (`search/reranker.py`):可选搜索结果精排
|
||||
- **Reflexion 持久化** (`memory/pattern_md.py`):REFLECTION.md 结构化记录 + /plan 风险注入
|
||||
|
||||
### Changed
|
||||
|
||||
- 专家格式从 flat YAML 升级为 SKILL.md 目录(向后兼容已移除,全量迁移)
|
||||
- 版本号从 0.7.0 → 1.0.0
|
||||
- 测试数量:282 → 311
|
||||
|
||||
### Removed
|
||||
|
||||
- 15 个旧 `.yaml` 专家文件(已全部转为 SKILL.md 目录)
|
||||
- Python 专家系统(ExpertBase、BugFixExpert.py、SelfImprovingOptimizer)— 方向错误,v0.8.0 加入后 v0.9.0 移除
|
||||
|
||||
### Architecture Decisions
|
||||
|
||||
- **元专家按原子能力分,不按业务领域分**:研究证明 MoE 路由反映隐状态几何结构而非领域专业性(arXiv:2604.09780)
|
||||
- **领域知识是注入层,不是独立流水线**:所有任务走同一条 Locator→Generator→Verifier 管线,区别只在 system_prompt
|
||||
- **渐进式加载解决噪音问题**:Gate 只看 metadata(~1500 token/15专家),不全量加载所有知识
|
||||
- **Reviewer 非阻塞**:审查结果不回滚代码,只提示用户注意 gap
|
||||
|
||||
---
|
||||
|
||||
## [0.9.0] - 2026-04-29
|
||||
|
||||
### Added
|
||||
- DAG TaskCompiler + /multi 命令
|
||||
- Debug Subagent(基于 Debug2Fix 论文)
|
||||
- Prompt Optimizer(优化 YAML system_prompt)
|
||||
- Reflexion 持久化 + Cross-Encoder 重排
|
||||
|
||||
### Removed
|
||||
- Python 专家系统(ExpertBase、BugFixExpert.py、SelfImprovingOptimizer)
|
||||
- Registry Python 专家加载逻辑
|
||||
|
||||
---
|
||||
|
||||
## [0.7.0] - 2026-04-29
|
||||
|
||||
### Added
|
||||
- UI 全面优化(spinner、结果摘要、重影大字 Header)
|
||||
- 意图感知搜索
|
||||
- 搜索模块重构(四级提取管道)
|
||||
- P2 三大功能(模型自适应、飞轮通知、价值仪表盘)
|
||||
- P1 四大功能(KWCODE.md、/plan、Checkpoint、DocReader)
|
||||
- MVP 核心流水线(Gate→Locator→Generator→Verifier→Search)
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
|
||||
| 论文 | 对 KWCode 的影响 |
|
||||
|------|-----------------|
|
||||
| Agentless (ICSE 2025) | 整体确定性流水线架构 |
|
||||
| CodeCompass (2026) | AST 调用图定位 |
|
||||
| Debug2Fix (ICML 2026) | Debug Subagent |
|
||||
| LLMCompiler (ICML 2024) | DAG 任务调度 |
|
||||
| Reflexion (NeurIPS 2023) | 失败模式持久化 |
|
||||
| SICA (2025) | Prompt 自动优化 |
|
||||
| GitHub Copilot Atomic Skills (2025) | 5 原子能力分层 |
|
||||
| SWE-Skills-Bench (2026) | 80% 泛泛 skill 无效,具体知识才有效 |
|
||||
| MoE Routing Geometry (2026) | 专家不按领域分,按能力分 |
|
||||
| Agent Skills Progressive Disclosure (Anthropic 2026) | 渐进式加载架构 |
|
||||
24
README.md
24
README.md
@@ -9,8 +9,8 @@
|
||||
[](LICENSE)
|
||||
[](https://python.org)
|
||||
[]()
|
||||
[]()
|
||||
[]()
|
||||
[]()
|
||||
[]()
|
||||
|
||||
</div>
|
||||
|
||||
@@ -58,20 +58,28 @@ Claude Code、Cursor 把代码发到海外服务器。公司代码、内网项
|
||||
|
||||
## 核心技术原理
|
||||
|
||||
### 原理一:确定性专家流水线
|
||||
### 原理一:确定性专家流水线 + 5 元专家体系
|
||||
|
||||
**理论来源**:Agentless(ICSE 2025)——确定性流水线在 SWE-bench 上同时达到最高通过率和最低成本,优于复杂 agent 架构。
|
||||
**理论来源**:
|
||||
- Agentless(ICSE 2025)——确定性流水线优于复杂 agent
|
||||
- GitHub Copilot Atomic Skills(2025)——5 原子能力组合出所有复杂任务
|
||||
- MoE Routing Geometry(arXiv:2604.09780)——专家按能力分,不按领域分
|
||||
|
||||
KWCode 的 5 个元专家(原子能力层,固定不变):
|
||||
|
||||
```
|
||||
用户输入
|
||||
└─► Gate 任务分类,毫秒级路由
|
||||
└─► Gate 任务分类,毫秒级路由 + 领域知识匹配
|
||||
└─► Locator 精准定位文件和函数(BM25+调用图,不调LLM)
|
||||
└─► Generator 只生成修改部分(从文件读original,LLM只写modified)
|
||||
└─► Generator 只生成修改部分 + 领域知识注入(SKILL.md Level 2)
|
||||
└─► Verifier 语法检查 + pytest 自动验证
|
||||
└─► DebugSubagent 失败时捕获运行时变量值
|
||||
└─► SearchAugmentor 搜索补充信息
|
||||
└─► Debugger 失败时捕获运行时变量值(sys.settrace)
|
||||
└─► Reviewer 需求对齐审查(LLM对比意图vs变更)
|
||||
```
|
||||
|
||||
15 个领域知识(SKILL.md 注入层,可扩展,不改变流水线):
|
||||
BugFix · FastAPI · TestGen · API · DeepSeekAPI · Docstring · MyBatis · Office(3) · Refactor · SpringBoot · SQLOpt · TypeHint · UniApp
|
||||
|
||||
### 原理二:BM25 + AST 调用图定位
|
||||
|
||||
**理论来源**:
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
name: APIExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- api
|
||||
- endpoint
|
||||
- rest
|
||||
- restful
|
||||
- swagger
|
||||
- openapi
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是REST API专家。专注于:
|
||||
|
||||
1. 设计符合RESTful规范的接口(资源命名、HTTP方法、状态码)
|
||||
|
||||
2. 生成请求/响应模型和参数校验
|
||||
|
||||
3. 处理认证、分页、错误响应等通用模式
|
||||
|
||||
4. 自动适配Flask/FastAPI/Express等主流框架
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令(包括ssh、git、pip、curl等)
|
||||
|
||||
- ast_parse:解析代码AST结构
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
- ast_parse
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
23
kaiwu/builtin_experts/api/SKILL.md
Normal file
23
kaiwu/builtin_experts/api/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: APIExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [api, endpoint, rest, restful, swagger, openapi]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [locator, generator, verifier]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- 资源命名用复数名词(/users, /orders),避免动词
|
||||
- HTTP方法语义:GET查询、POST创建、PUT全量更新、PATCH部分更新、DELETE删除
|
||||
- 状态码:200成功、201已创建、204无内容、400参数错误、401未认证、403无权限、404不存在、409冲突、422验证失败、500服务端错误
|
||||
- 分页:支持 ?page=1&size=20,响应包含 total/pages/current 元数据
|
||||
- 错误响应统一格式:{"code": int, "message": str, "details": [...]}
|
||||
- 认证:Bearer Token 放 Authorization header,不放 URL 参数
|
||||
- 版本控制:URL前缀 /api/v1/ 或 Accept header
|
||||
- 自动检测框架(Flask/FastAPI/Express/Spring)并适配对应路由注册方式
|
||||
- FastAPI 优先用 Pydantic model 做请求/响应校验
|
||||
- Express 用 router.route() 链式注册同路径不同方法
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,83 +0,0 @@
|
||||
name: BugFixExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- 报错
|
||||
- error
|
||||
- exception
|
||||
- traceback
|
||||
- 修复
|
||||
- fix
|
||||
- bug
|
||||
- 崩溃
|
||||
- crash
|
||||
- 失败
|
||||
trigger_min_confidence: 0.95
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是bug修复专家。专注于:
|
||||
|
||||
1. 理解错误信息和堆栈跟踪
|
||||
|
||||
2. 定位根本原因,不只是症状
|
||||
|
||||
3. 生成最小改动的修复方案
|
||||
|
||||
4. 验证修复不破坏现有功能
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令(包括ssh、git、pip、curl等)
|
||||
|
||||
- ast_parse:解析代码AST结构
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
- ast_parse
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
@@ -1,75 +0,0 @@
|
||||
name: DeepSeekAPIExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- deepseek
|
||||
- qwen
|
||||
- 通义千问
|
||||
- 大模型api
|
||||
- llm api
|
||||
- 模型调用
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是大模型API调用专家。专注于:
|
||||
|
||||
1. DeepSeek/Qwen等国产大模型的API接入和参数调优
|
||||
|
||||
2. 流式响应处理、token计数和费用控制
|
||||
|
||||
3. 提示词工程:system/user/assistant角色设计
|
||||
|
||||
4. 错误重试、速率限制和并发请求管理
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令(包括ssh、git、pip、curl等)
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
pipeline:
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
23
kaiwu/builtin_experts/deepseekapi/SKILL.md
Normal file
23
kaiwu/builtin_experts/deepseekapi/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: DeepSeekAPIExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [deepseek, qwen, 通义千问, 大模型api, llm api, 模型调用]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [generator, verifier]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- 国产LLM统一用 OpenAI 兼容接口格式(/v1/chat/completions)
|
||||
- DeepSeek base_url: https://api.deepseek.com,Qwen: https://dashscope.aliyuncs.com/compatible-mode/v1
|
||||
- 流式响应:stream=True + SSE解析,逐chunk拼接content字段
|
||||
- token计费:输入/输出分别计价,用tiktoken或API返回的usage字段统计
|
||||
- 限流处理:捕获429状态码,指数退避重试(1s/2s/4s),最多3次
|
||||
- 超时设置:连接超时10s,读取超时60s(长文本生成可加到120s)
|
||||
- prompt工程:system message定角色,few-shot放user/assistant交替
|
||||
- 温度参数:代码生成用0.0-0.3,创意文本用0.7-1.0
|
||||
- 错误处理:区分可重试错误(429/500/503)和不可重试错误(400/401)
|
||||
- 长文本:超过模型max_tokens时自动截断或分段处理
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,74 +0,0 @@
|
||||
name: DocstringExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- docstring
|
||||
- 注释
|
||||
- comment
|
||||
- 代码注释
|
||||
- 函数注释
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是代码文档专家。专注于:
|
||||
|
||||
1. 为函数和类生成清晰的docstring(Google/NumPy风格)
|
||||
|
||||
2. 描述参数、返回值、异常和使用示例
|
||||
|
||||
3. 保持文档与代码逻辑一致
|
||||
|
||||
4. 中英文项目自动适配语言
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- ast_parse:解析代码AST结构
|
||||
|
||||
你拥有完整的文件系统访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- ast_parse
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
23
kaiwu/builtin_experts/docstring/SKILL.md
Normal file
23
kaiwu/builtin_experts/docstring/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: DocstringExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [docstring, 注释, comment, 代码注释, 函数注释]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [locator, generator]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- 默认用Google风格docstring,项目已有NumPy风格则跟随
|
||||
- 一行摘要用祈使句("计算xxx"而非"这个函数计算xxx")
|
||||
- Args段:每个参数一行,格式 `name (type): 描述`
|
||||
- Returns段:写明类型和含义,多返回值用tuple说明各元素
|
||||
- Raises段:只列主动raise的异常,不列底层传播的
|
||||
- 示例(Examples):给出可直接运行的doctest片段
|
||||
- 类docstring写在class行下方,描述职责而非实现
|
||||
- 中文项目用中文写docstring,英文项目用英文,混合项目跟随已有风格
|
||||
- 私有方法(_前缀)可省略docstring,公开API必须有
|
||||
- 装饰器不影响docstring位置,始终写在def下一行
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,81 +0,0 @@
|
||||
name: FastAPIExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- fastapi
|
||||
- pydantic
|
||||
- uvicorn
|
||||
- fastapi接口
|
||||
- fastapi路由
|
||||
- starlette
|
||||
- depends
|
||||
- APIRouter
|
||||
trigger_min_confidence: 0.5
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是FastAPI专家。专注于:
|
||||
|
||||
1. 路由定义、Pydantic模型校验和依赖注入
|
||||
|
||||
2. 异步endpoint和后台任务的正确使用
|
||||
|
||||
3. 中间件、CORS、认证(OAuth2/JWT)配置
|
||||
|
||||
4. OpenAPI文档自动生成和响应模型规范
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令(包括ssh、git、pip、curl等)
|
||||
|
||||
- ast_parse:解析代码AST结构
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
- ast_parse
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
@@ -1,75 +0,0 @@
|
||||
name: MybatisExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- mybatis
|
||||
- mapper
|
||||
- xml映射
|
||||
- sql映射
|
||||
- dao
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是Mybatis专家。专注于:
|
||||
|
||||
1. Mapper接口与XML映射文件的生成和修改
|
||||
|
||||
2. 动态SQL(if/choose/foreach/where)的正确使用
|
||||
|
||||
3. ResultMap映射、关联查询和分页处理
|
||||
|
||||
4. 防止SQL注入,区分#{}和${}的使用场景
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令(包括ssh、git、mvn等)
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
23
kaiwu/builtin_experts/mybatis/SKILL.md
Normal file
23
kaiwu/builtin_experts/mybatis/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: MybatisExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [mybatis, mapper, xml映射, sql映射, dao]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [locator, generator, verifier]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- Mapper接口方法名与XML中id一一对应,namespace为接口全限定名
|
||||
- 动态SQL标签:<if test=""> 条件拼接、<choose>/<when>/<otherwise> 多分支、<foreach> 集合遍历
|
||||
- ResultMap:一对一用<association>,一对多用<collection>,嵌套查询用select属性
|
||||
- 参数传递:单参数直接用#{param},多参数用@Param注解或封装DTO
|
||||
- #{} 预编译防注入,${} 字符串替换仅用于动态表名/列名
|
||||
- 分页:配合PageHelper插件,Mapper方法前调用PageHelper.startPage()
|
||||
- 批量操作:insert用<foreach>拼接VALUES,update用<foreach>+CASE WHEN
|
||||
- 缓存:一级缓存SqlSession级别默认开启,二级缓存需在XML加<cache/>
|
||||
- 通用字段(create_time/update_time)用拦截器自动填充
|
||||
- XML文件放在 resources/mapper/ 目录,与接口包路径对应
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,76 +0,0 @@
|
||||
name: OfficeDocxExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-27'
|
||||
trigger_keywords:
|
||||
- docx
|
||||
- .docx
|
||||
- word文档
|
||||
- word模板
|
||||
- 报告
|
||||
- 申请
|
||||
- 合同
|
||||
- 方案
|
||||
- 公文
|
||||
- 简历
|
||||
- 总结
|
||||
- 述职
|
||||
- 策划
|
||||
- 请示
|
||||
- 批复
|
||||
- 通知
|
||||
trigger_min_confidence: 0.4
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是Word文档生成专家。用python-docx生成专业.docx文件。
|
||||
|
||||
规范:中文正文首行缩进2字符,表格表头深蓝背景#1B2A4A白色粗体,
|
||||
|
||||
正文仿宋12pt,标题黑体,落款右对齐。
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
pipeline:
|
||||
- office
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: new
|
||||
24
kaiwu/builtin_experts/office_docx/SKILL.md
Normal file
24
kaiwu/builtin_experts/office_docx/SKILL.md
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: OfficeDocxExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [word, docx, word文档, 技术方案, 报告]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [office]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- 使用python-docx库生成,Document()创建空文档
|
||||
- 中文正文字体:宋体/仿宋,标题:微软雅黑/黑体,英文:Times New Roman
|
||||
- 正文字号:小四(12pt),标题逐级递增(二号→小三→四号)
|
||||
- 首行缩进:paragraph_format.first_line_indent = Cm(0.74)(两个中文字符)
|
||||
- 行距:1.5倍行距,paragraph_format.line_spacing = 1.5
|
||||
- 页边距:上下2.54cm,左右3.17cm(Word默认值)
|
||||
- 表格:Table(rows, cols),首行深色背景+白色加粗文字,内容行交替底色
|
||||
- 页眉页脚:section.header.paragraphs[0] 设置文字,页码用WD_ALIGN_PARAGRAPH.CENTER
|
||||
- 标题层级:add_heading(text, level=1/2/3),自动生成目录结构
|
||||
- 图片插入:add_picture(path, width=Cm(14)) 居中显示
|
||||
- 保存前不要忘记 document.save(filename)
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,70 +0,0 @@
|
||||
name: OfficePptxExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-27'
|
||||
trigger_keywords:
|
||||
- ppt
|
||||
- pptx
|
||||
- 演示文稿
|
||||
- 幻灯片
|
||||
- slide
|
||||
- deck
|
||||
- presentation
|
||||
- 汇报材料
|
||||
trigger_min_confidence: 0.4
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是PPT生成专家。用python-pptx生成专业演示文稿。
|
||||
|
||||
规范:slide_layouts[6]空白版式,深-浅-深三明治结构,
|
||||
|
||||
主色#1B2A4A,强调色#E8A838,标题36-44pt,正文14-16pt,
|
||||
|
||||
禁止标题下加装饰横线,每页必须有视觉元素。
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
pipeline:
|
||||
- office
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: new
|
||||
23
kaiwu/builtin_experts/office_pptx/SKILL.md
Normal file
23
kaiwu/builtin_experts/office_pptx/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: OfficePptxExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [ppt, pptx, 幻灯片, 演示文稿, 汇报]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [office]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- 使用python-pptx库,Presentation()创建,slide_layouts选择版式
|
||||
- 三明治结构:封面页(标题+副标题+日期)→ 内容页 → 总结页
|
||||
- 不用默认白底,设置深蓝/深灰背景或渐变填充提升质感
|
||||
- 商务配色:主色深蓝#003366,辅色#0066CC,强调色#FF6600,文字白色或浅灰
|
||||
- 每页内容不超过5个要点,每个要点一行不超过15字
|
||||
- 字号:标题28-36pt,正文18-24pt,注释14pt
|
||||
- 图表嵌入:用chart_data构建,优先柱状图/饼图/折线图
|
||||
- 布局:标题在顶部1/5区域,内容占中间3/5,底部留白或放页码
|
||||
- 动画/切换:代码生成时不加动画(python-pptx不支持),提示用户手动添加
|
||||
- 母版:如有企业模板.pptx,用Presentation(template_path)加载
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,68 +0,0 @@
|
||||
name: OfficeXlsxExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-27'
|
||||
trigger_keywords:
|
||||
- excel
|
||||
- xlsx
|
||||
- 表格
|
||||
- 报表
|
||||
- 电子表格
|
||||
- 数据表
|
||||
- 财务表格
|
||||
- csv
|
||||
trigger_min_confidence: 0.4
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是Excel文档生成专家。用openpyxl生成专业.xlsx文件。
|
||||
|
||||
规范:用Excel公式不硬编码,表头#1B2A4A白色粗体居中,
|
||||
|
||||
交替行色#F0F4FA,冻结表头,列宽自适应,汇总行双线上边框。
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
pipeline:
|
||||
- office
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: new
|
||||
24
kaiwu/builtin_experts/office_xlsx/SKILL.md
Normal file
24
kaiwu/builtin_experts/office_xlsx/SKILL.md
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: OfficeXlsxExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [excel, xlsx, 表格, 报表, 数据表]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [office]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- 使用openpyxl库,Workbook()创建,ws = wb.active获取活动sheet
|
||||
- 表头样式:深色背景(#003366)+白色加粗字体+居中对齐
|
||||
- 斑马纹:奇偶行交替浅灰(#F2F2F2)和白色背景
|
||||
- 冻结首行:ws.freeze_panes = 'A2',冻结首行+首列用'B2'
|
||||
- 列宽自适应:遍历列取max(len(str(cell.value)))设置column_dimensions
|
||||
- 数据验证:DataValidation(type="list", formula1='"选项1,选项2"')
|
||||
- 条件格式:ColorScaleRule/CellIsRule高亮异常值
|
||||
- 公式:直接写Excel公式字符串如'=SUM(B2:B100)',不用Python计算
|
||||
- 数字格式:金额'#,##0.00',百分比'0.00%',日期'YYYY-MM-DD'
|
||||
- 合并单元格:ws.merge_cells('A1:D1') 用于标题行
|
||||
- 边框:thin边框包围数据区域,表头用medium底边框
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,78 +0,0 @@
|
||||
name: RefactorExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- 重构
|
||||
- refactor
|
||||
- 去重
|
||||
- deduplicate
|
||||
- 代码重构
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是代码重构专家。专注于:
|
||||
|
||||
1. 识别代码坏味道(重复、过长函数、深层嵌套)
|
||||
|
||||
2. 应用设计模式和SOLID原则进行重构
|
||||
|
||||
3. 保证重构前后行为完全一致
|
||||
|
||||
4. 每次只做一种重构,便于review和回滚
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令(包括ssh、git、pip、curl等)
|
||||
|
||||
- ast_parse:解析代码AST结构
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
- ast_parse
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
23
kaiwu/builtin_experts/refactor/SKILL.md
Normal file
23
kaiwu/builtin_experts/refactor/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: RefactorExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [重构, refactor, 去重, deduplicate, 代码重构]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [locator, generator, verifier]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- 每次只做一种重构,不混合多种变更,便于验证行为一致
|
||||
- 代码坏味道识别:重复代码→提取函数、过长函数→拆分、深层嵌套→提前返回/卫语句
|
||||
- SOLID原则:单一职责(类只做一件事)、开闭(扩展开放修改关闭)、依赖倒置(依赖抽象不依赖具体)
|
||||
- 提取函数:3行以上重复代码或逻辑独立片段,命名体现意图而非实现
|
||||
- 简化条件:复杂if/else链改为策略模式或查表法
|
||||
- 消除魔法数字:提取为命名常量,放在文件顶部或配置中
|
||||
- 参数过多(>4个):封装为数据类/字典/配置对象
|
||||
- 重构前确保有测试覆盖,重构后运行测试验证行为不变
|
||||
- 不改变公开API签名,除非调用方也在重构范围内
|
||||
- 大范围重构分步提交:先提取→再替换调用→最后删除旧代码
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,78 +0,0 @@
|
||||
name: SpringBootExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- spring
|
||||
- springboot
|
||||
- spring boot
|
||||
- 注解
|
||||
- '@Controller'
|
||||
- '@Service'
|
||||
- '@Repository'
|
||||
- 配置
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是Spring Boot专家。专注于:
|
||||
|
||||
1. Controller/Service/Repository三层架构的代码生成和修改
|
||||
|
||||
2. 正确使用Spring注解(@Autowired, @Transactional, @Valid等)
|
||||
|
||||
3. application.yml配置和Bean生命周期管理
|
||||
|
||||
4. 常见问题排查:循环依赖、事务失效、自动装配失败
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令(包括ssh、git、mvn、gradle等)
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
23
kaiwu/builtin_experts/springboot/SKILL.md
Normal file
23
kaiwu/builtin_experts/springboot/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: SpringBootExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [springboot, spring, spring boot, 注解, autowired, bean]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [locator, generator, verifier]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- 分层架构:Controller→Service→Mapper/Repository,每层只依赖下一层
|
||||
- 注解:@RestController处理请求、@Service业务逻辑、@Mapper数据访问、@Configuration配置类
|
||||
- 依赖注入:优先构造器注入(不用@Autowired字段注入),便于测试
|
||||
- 配置文件:application.yml分环境(dev/test/prod),敏感信息用环境变量${DB_PASSWORD}
|
||||
- AOP切面:@Aspect+@Around做日志/权限/耗时统计,切点表达式精确匹配
|
||||
- 异常处理:@ControllerAdvice+@ExceptionHandler全局捕获,返回统一错误格式
|
||||
- Starter自动配置:@ConditionalOnClass/OnProperty控制Bean加载条件
|
||||
- Mapper接口对应XML:接口在java目录,XML在resources/mapper/,namespace全限定名匹配
|
||||
- 事务:@Transactional加在Service方法上,只读查询加readOnly=true
|
||||
- 启动类:@SpringBootApplication放在根包下,确保组件扫描覆盖所有子包
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,77 +0,0 @@
|
||||
name: SQLOptExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- sql
|
||||
- 查询优化
|
||||
- 慢查询
|
||||
- slow query
|
||||
- 索引
|
||||
- index
|
||||
- 数据库优化
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是SQL优化专家。专注于:
|
||||
|
||||
1. 分析慢查询的执行计划,识别全表扫描和低效JOIN
|
||||
|
||||
2. 建议合适的索引策略(覆盖索引、联合索引)
|
||||
|
||||
3. 重写SQL以减少子查询和临时表
|
||||
|
||||
4. 兼顾MySQL/PostgreSQL语法差异
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令(包括ssh、mysql、psql等)
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
23
kaiwu/builtin_experts/sqlopt/SKILL.md
Normal file
23
kaiwu/builtin_experts/sqlopt/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: SQLOptExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [sql优化, 慢查询, explain, 索引, sql性能]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [locator, generator, verifier]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- EXPLAIN分析:关注type列(ALL全表扫描→需优化,ref/range/const为佳)、rows估算、Extra中的Using filesort/temporary
|
||||
- 索引设计:WHERE条件列建索引,联合索引遵循最左前缀原则,区分度高的列放前面
|
||||
- 覆盖索引:SELECT的列都在索引中,避免回表(Extra显示Using index)
|
||||
- 避免索引失效:不在索引列上用函数/运算、不用前导%LIKE、注意隐式类型转换
|
||||
- 子查询改JOIN:IN子查询改为INNER JOIN,EXISTS改为LEFT JOIN + IS NOT NULL判断
|
||||
- 分页优化:深分页用WHERE id > last_id LIMIT n代替OFFSET,或延迟关联
|
||||
- 批量操作:INSERT用批量VALUES(每批500-1000条),UPDATE用CASE WHEN批量
|
||||
- COUNT优化:COUNT(*)让引擎选最小索引,不要COUNT(列名)除非需排除NULL
|
||||
- 大表JOIN:确保JOIN字段有索引且类型一致,小表驱动大表
|
||||
- 锁优化:长事务拆短、避免SELECT...FOR UPDATE范围过大
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,99 +0,0 @@
|
||||
name: TestGenExpert
|
||||
version: 1.1.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: "2026-04-26"
|
||||
trigger_keywords:
|
||||
- 测试
|
||||
- test
|
||||
- 单元测试
|
||||
- unittest
|
||||
- pytest
|
||||
- 测试用例
|
||||
- mock
|
||||
- 集成测试
|
||||
- TDD
|
||||
- assert
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: |
|
||||
## 基础质量规则
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
## 中文环境注意
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
## 测试用例专家规范
|
||||
|
||||
你是单元测试专家。遵循以下规范生成高质量测试。
|
||||
|
||||
### AAA 模式
|
||||
每个测试严格分为 Arrange(准备数据)→ Act(执行操作)→ Assert(验证结果)三段,用空行分隔。
|
||||
|
||||
### 命名规范
|
||||
test_<被测函数>_<场景>_<期望结果>,例如 test_login_wrong_password_returns_401。
|
||||
禁止 test_1 / test_case_a 等无意义命名。
|
||||
|
||||
### 隔离性
|
||||
每个测试独立运行,不依赖其他测试的执行顺序或副作用。
|
||||
共享状态用 fixture(scope='function')重置。禁止测试间共享可变全局变量。
|
||||
|
||||
### Mock 策略
|
||||
外部依赖(网络请求/文件系统/数据库/时间)必须 mock。
|
||||
mock 的 patch 路径指向被测模块里的名字,非原始库路径。
|
||||
例:被测函数 from requests import get → patch('mymodule.get'),不是 patch('requests.get')。
|
||||
|
||||
### 边界覆盖
|
||||
每个函数至少测试:正常输入、空输入(None/空字符串/空列表)、边界值(0/1/最大值)、异常输入。
|
||||
批量场景用 @pytest.mark.parametrize。
|
||||
|
||||
### 断言精确
|
||||
一个测试一个核心断言。
|
||||
用 assert x == y 而非 assert (x == y) is True。
|
||||
异常测试用 pytest.raises(ExceptionType)。
|
||||
浮点比较用 pytest.approx。
|
||||
|
||||
### 常见坑
|
||||
1. mock 打错位置:必须 patch 被测模块里的名字,非原始库路径
|
||||
2. 不 mock 时间/随机数:用 mock.patch 或 freezegun 固定
|
||||
3. 测试文件用相对路径读文件:改用 Path(__file__).parent 定位
|
||||
4. 一个测试多个核心断言:拆分为多个小测试或用 parametrize
|
||||
|
||||
### 自检清单
|
||||
- 每个测试遵循 AAA 模式
|
||||
- 测试名格式 test_<函数>_<场景>_<期望>
|
||||
- 外部依赖已全部 mock
|
||||
- 覆盖正常/空/边界/异常四类输入
|
||||
- 浮点用 pytest.approx,异常用 pytest.raises()
|
||||
- fixture scope 尽量小,无可变全局共享状态
|
||||
|
||||
你可以使用以下工具:
|
||||
- read_file:读取本地文件内容
|
||||
- write_file:写入/创建文件
|
||||
- run_bash:执行任意shell命令(包括ssh、git、pip、curl等)
|
||||
- ast_parse:解析代码AST结构
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
- ast_parse
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
@@ -1,76 +0,0 @@
|
||||
name: TypeHintExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- 类型注解
|
||||
- type hint
|
||||
- 类型标注
|
||||
- 类型提示
|
||||
- annotation
|
||||
- mypy
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是Python类型注解专家。专注于:
|
||||
|
||||
1. 为函数参数和返回值添加准确的类型注解
|
||||
|
||||
2. 使用typing模块的高级类型(Optional, Union, Generic等)
|
||||
|
||||
3. 保持与mypy/pyright的兼容性
|
||||
|
||||
4. 不改变原有逻辑,只添加类型信息
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- ast_parse:解析代码AST结构
|
||||
|
||||
你拥有完整的文件系统访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- ast_parse
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
23
kaiwu/builtin_experts/typehint/SKILL.md
Normal file
23
kaiwu/builtin_experts/typehint/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: TypeHintExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [类型注解, type hint, typing, 类型标注, mypy]
|
||||
trigger_min_confidence: 0.7
|
||||
pipeline: [locator, generator]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- Python 3.10+用内置类型(list[str], dict[str, int], str | None),低版本用typing模块
|
||||
- Optional[X]等价于X | None,表示可能为None,不表示"可选参数"
|
||||
- 函数签名:所有公开函数标注参数类型和返回类型,内部函数可省略
|
||||
- 泛型:TypeVar定义类型变量,Generic[T]创建泛型类,bound限制上界
|
||||
- Protocol:结构化子类型(鸭子类型的静态版),定义接口不需要继承
|
||||
- TypedDict:字典的精确类型,每个key有独立类型,total=False允许可选key
|
||||
- Literal:限制值为几个字面量之一,如Literal["read", "write"]
|
||||
- Callable[[参数类型], 返回类型]标注回调函数,参数多时用Protocol替代
|
||||
- overload装饰器:同一函数不同参数组合返回不同类型时使用
|
||||
- TYPE_CHECKING:避免运行时循环导入,仅在类型检查时导入
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -1,77 +0,0 @@
|
||||
name: UniAppExpert
|
||||
version: 1.0.0
|
||||
type: builtin
|
||||
author: kaiwu-team
|
||||
created_at: '2026-04-26'
|
||||
trigger_keywords:
|
||||
- uniapp
|
||||
- uni-app
|
||||
- 小程序
|
||||
- 微信
|
||||
- wxml
|
||||
- wxss
|
||||
- miniprogram
|
||||
trigger_min_confidence: 0.7
|
||||
system_prompt: '## 基础质量规则
|
||||
|
||||
1. 修改前先读取目标文件,确认内容。
|
||||
|
||||
2. 匹配已有代码风格,不要引入新风格。
|
||||
|
||||
3. 改完后运行一次验证,不要重复验证。
|
||||
|
||||
4. 只修改任务要求的部分,不要动无关代码。
|
||||
|
||||
5. 重构命名必须来自用户描述,禁止自行替换同义词。
|
||||
|
||||
|
||||
## 中文环境注意
|
||||
|
||||
- 文件读写必须指定 encoding="utf-8"
|
||||
|
||||
- Windows 终端输出禁止 Unicode 符号(✓✗❌🎉),改用 [OK] [FAIL] [DONE]
|
||||
|
||||
- pip 慢时用清华镜像:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
- npm 慢时用淘宝镜像:npm config set registry https://registry.npmmirror.com
|
||||
|
||||
- subprocess 调用加 encoding="utf-8", errors="replace"
|
||||
|
||||
|
||||
你是uni-app/微信小程序专家。专注于:
|
||||
|
||||
1. Vue语法的页面和组件开发,兼顾多端兼容性
|
||||
|
||||
2. 小程序生命周期、路由跳转和数据通信
|
||||
|
||||
3. 条件编译(#ifdef)处理平台差异
|
||||
|
||||
4. 常见问题:样式rpx适配、API权限、包体积优化
|
||||
|
||||
你可以使用以下工具:
|
||||
|
||||
- read_file:读取本地文件内容
|
||||
|
||||
- write_file:写入/创建文件
|
||||
|
||||
- run_bash:执行任意shell命令(包括ssh、git、npm等)
|
||||
|
||||
你拥有完整的文件系统和命令行访问权限。
|
||||
|
||||
'
|
||||
tool_whitelist:
|
||||
- read_file
|
||||
- write_file
|
||||
- run_bash
|
||||
pipeline:
|
||||
- locator
|
||||
- generator
|
||||
- verifier
|
||||
tested_models:
|
||||
- deepseek-r1:8b
|
||||
- qwen3:14b
|
||||
performance:
|
||||
success_rate: 0.0
|
||||
avg_latency_s: 0
|
||||
task_count: 0
|
||||
lifecycle: mature
|
||||
23
kaiwu/builtin_experts/uniapp/SKILL.md
Normal file
23
kaiwu/builtin_experts/uniapp/SKILL.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: UniAppExpert
|
||||
version: 1.0.0
|
||||
trigger_keywords: [uniapp, uni-app, 小程序, 跨端, vue3小程序]
|
||||
trigger_min_confidence: 0.5
|
||||
pipeline: [locator, generator, verifier]
|
||||
lifecycle: mature
|
||||
---
|
||||
|
||||
## 领域知识
|
||||
|
||||
- 基于Vue3组合式API(setup语法糖),ref/reactive管理状态,computed派生数据
|
||||
- 条件编译:#ifdef MP-WEIXIN 微信专属代码 #endif,支持H5/MP-WEIXIN/MP-ALIPAY/APP
|
||||
- 生命周期:页面用onLoad(接收参数)/onShow/onHide,组件用onMounted/onUnmounted
|
||||
- 路由:uni.navigateTo跳转保留当前页,uni.redirectTo关闭当前页,uni.switchTab切Tab
|
||||
- 网络请求:封装uni.request为Promise,统一拦截添加token、处理401跳登录
|
||||
- 存储:uni.setStorageSync/getStorageSync同步操作,大数据用异步版本
|
||||
- 样式:rpx自适应单位(750rpx=屏幕宽),不用px;scoped样式避免污染
|
||||
- 组件通信:props向下传、emit向上传、provide/inject跨层级、Pinia全局状态
|
||||
- 分包:subPackages配置分包加载,主包控制在2MB内
|
||||
- 兼容性:避免直接操作DOM,不用window/document,用uni API替代Web API
|
||||
|
||||
## 经验规则(自动生成)
|
||||
@@ -191,6 +191,10 @@ class PipelineOrchestrator:
|
||||
if success:
|
||||
elapsed = time.time() - start_time
|
||||
checkpoint.discard() # Clean up snapshot on success
|
||||
|
||||
# Reviewer: 需求对齐审查(非阻塞,不影响成功判定)
|
||||
review_result = self._do_review(ctx, on_status)
|
||||
|
||||
# Save to memory on success (with elapsed for expert/pattern tracking)
|
||||
self.memory.save(project_root, ctx, elapsed=elapsed)
|
||||
# Update expert registry stats
|
||||
@@ -426,6 +430,23 @@ class PipelineOrchestrator:
|
||||
except Exception as e:
|
||||
logger.debug("Debug subagent failed (non-blocking): %s", e)
|
||||
|
||||
def _do_review(self, ctx: TaskContext, on_status) -> dict:
|
||||
"""Reviewer: 需求对齐审查(非阻塞)。成功后检查代码是否真正满足用户意图。"""
|
||||
try:
|
||||
from kaiwu.experts.reviewer import ReviewerExpert
|
||||
reviewer = ReviewerExpert(llm=self.generator.llm)
|
||||
self._emit(on_status, "review", "审查需求对齐...")
|
||||
result = reviewer.review(ctx)
|
||||
if result.get("aligned"):
|
||||
self._emit(on_status, "review_done", "需求对齐确认")
|
||||
else:
|
||||
gap = result.get("gap", "")
|
||||
self._emit(on_status, "review_gap", f"注意:{gap}")
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.debug("Reviewer failed (non-blocking): %s", e)
|
||||
return {"aligned": True, "confidence": 0.0, "gap": ""}
|
||||
|
||||
@staticmethod
|
||||
def _emit(callback, stage: str, detail: str):
|
||||
"""Emit status update if callback provided."""
|
||||
|
||||
122
kaiwu/experts/reviewer.py
Normal file
122
kaiwu/experts/reviewer.py
Normal file
@@ -0,0 +1,122 @@
|
||||
"""
|
||||
Reviewer expert: 需求对齐验证(第二层回检)。
|
||||
验证 Generator 输出是否真正满足用户意图,而不只是"能跑通"。
|
||||
|
||||
元专家体系第5个原子能力:
|
||||
Locator(定位)→ Generator(生成)→ Verifier(测试)→ Debugger(调试)→ Reviewer(审查)
|
||||
|
||||
Reviewer 在 Verifier 通过后执行,用 LLM 对比:
|
||||
- 用户原始意图
|
||||
- 实际代码变更
|
||||
判断是否对齐,输出 {aligned: bool, gap: str}
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
from kaiwu.core.context import TaskContext
|
||||
from kaiwu.llm.llama_backend import LLMBackend
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
REVIEW_PROMPT = """你是代码审查专家。判断以下代码修改是否真正满足了用户的需求。
|
||||
|
||||
## 用户需求
|
||||
{user_input}
|
||||
|
||||
## 实际代码变更
|
||||
{changes}
|
||||
|
||||
## 判断标准
|
||||
1. 修改是否解决了用户描述的核心问题?
|
||||
2. 是否有遗漏(用户要求了但没做的)?
|
||||
3. 是否有多余(用户没要求但做了的,可能引入风险)?
|
||||
|
||||
## 输出格式(JSON,不要解释)
|
||||
{{"aligned": true/false, "confidence": 0.0-1.0, "gap": "如果不对齐,说明差距是什么(一句话)"}}"""
|
||||
|
||||
|
||||
class ReviewerExpert:
|
||||
"""
|
||||
需求对齐审查。Verifier 通过后执行。
|
||||
用 LLM 对比用户意图和实际变更,判断是否真正完成了任务。
|
||||
非阻塞:审查失败不回滚,只记录 gap 供用户参考。
|
||||
"""
|
||||
|
||||
def __init__(self, llm: LLMBackend):
|
||||
self.llm = llm
|
||||
|
||||
def review(self, ctx: TaskContext) -> dict:
|
||||
"""
|
||||
审查 Generator 输出是否对齐用户需求。
|
||||
返回 {"aligned": bool, "confidence": float, "gap": str}
|
||||
失败时返回 {"aligned": True, "confidence": 0.0, "gap": ""} (乐观降级)
|
||||
"""
|
||||
try:
|
||||
# 提取变更摘要
|
||||
changes = self._extract_changes(ctx)
|
||||
if not changes:
|
||||
return {"aligned": True, "confidence": 0.0, "gap": ""}
|
||||
|
||||
# LLM 审查
|
||||
prompt = REVIEW_PROMPT.format(
|
||||
user_input=ctx.user_input[:200],
|
||||
changes=changes[:800],
|
||||
)
|
||||
|
||||
response = self.llm.generate(
|
||||
prompt=prompt,
|
||||
system="你是代码审查专家,只输出JSON判断,不要解释。",
|
||||
max_tokens=150,
|
||||
temperature=0.0,
|
||||
)
|
||||
|
||||
# 解析结果
|
||||
return self._parse_response(response)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning("[reviewer] review failed: %s", e)
|
||||
return {"aligned": True, "confidence": 0.0, "gap": ""}
|
||||
|
||||
@staticmethod
|
||||
def _extract_changes(ctx: TaskContext) -> str:
|
||||
"""从 ctx 提取代码变更摘要。"""
|
||||
if not ctx.generator_output:
|
||||
return ""
|
||||
|
||||
parts = []
|
||||
patches = ctx.generator_output.get("patches", [])
|
||||
for patch in patches[:3]: # 最多看3个文件
|
||||
file_path = patch.get("file", "unknown")
|
||||
modified = patch.get("modified", "")[:300]
|
||||
original = patch.get("original", "")[:200]
|
||||
if modified:
|
||||
parts.append(f"文件: {file_path}\n修改后:\n{modified}")
|
||||
if original:
|
||||
parts.append(f"修改前:\n{original}")
|
||||
|
||||
explanation = ctx.generator_output.get("explanation", "")
|
||||
if explanation:
|
||||
parts.append(f"说明: {explanation[:200]}")
|
||||
|
||||
return "\n\n".join(parts)
|
||||
|
||||
@staticmethod
|
||||
def _parse_response(response: str) -> dict:
|
||||
"""解析 LLM 的 JSON 审查结果。"""
|
||||
# 提取 JSON
|
||||
json_match = re.search(r'\{[^}]+\}', response)
|
||||
if not json_match:
|
||||
return {"aligned": True, "confidence": 0.0, "gap": ""}
|
||||
|
||||
try:
|
||||
result = json.loads(json_match.group())
|
||||
return {
|
||||
"aligned": bool(result.get("aligned", True)),
|
||||
"confidence": float(result.get("confidence", 0.0)),
|
||||
"gap": str(result.get("gap", ""))[:100],
|
||||
}
|
||||
except (json.JSONDecodeError, ValueError, TypeError):
|
||||
return {"aligned": True, "confidence": 0.0, "gap": ""}
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "kwcode"
|
||||
version = "0.9.0"
|
||||
version = "1.0.0"
|
||||
description = "KwCode - Local-model coding agent with MoE expert pipeline"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user