Feat/code review agent 92 clean#201
Conversation
端到端 CR Agent: 解析→规则(正则+AST/taint)→LLM增强(降噪+补召回)→四元组去重→Filter前置→沙箱(fake/local/container/cube)→脱敏→SQLite七表落库→JSON/MD/SARIF报告 Closes trpc-group#92
…trpc-group#92) 修复 PR trpc-group#200 reviewer(CongkeChen)发现的 Critical bug: - DENOISING_PROMPT 要求 LLM 返回 "verdict":"TP|FP"(TP=真问题, FP=误报) - 原 _apply_verdicts 只在 verdict == "false_positive" 时剔除 - 真 LLM 返回 "FP" 不匹配 "false_positive" → 降噪失效 - 现在兼容多种格式:FP, false_positive, false positive, False Positive, 误报 新增测试:test_real_mode_fp_verdict_compatibility() 验证真 LLM 返回 "FP" 格式时正确剔除误报
…c-group#200 review) - Critical 2: 修复 Cube 沙箱超时异常捕获,优先捕获 subprocess.TimeoutExpired - 隐患1: 修复 Filter 预算 off-by-one,call_index >= max_sandbox_runs 时 deny - 隐患2: 修复 Filter 子串误匹配,路径使用边界匹配避免 .environment 命中 .env - 隐患3: 修复沙箱脚本未落盘,pipeline 在执行前把脚本复制到 workspace - 隐患4: 修复存储 save 与 start_task 断链,pipeline 在开始时调用 start_task - 补充严格测试:Cube 超时断言 status==timeout、Filter off-by-one 和边界匹配测试
- 回退 .flake8 的 ignore 配置,移除 E126, E128(恢复为 ignore = E402, W503) - 重构 llm_layer.py 两处 create() 调用,提取 messages 变量解决 continuation line 缩进问题 - _call_llm_with_openai_client() + _call_llm_with_openai_client_supplementary() - 验证:flake8 零错误(无 E126/E128) + pytest 全绿
|
#200 Critical 修复 LLM 降噪 verdict 不一致(llm_layer.py _apply_verdicts):normalize 后兼容 false_positive/FP/false/误报(c547448)。补充了真模式返回 "FP" 的测试——此前只测 false_positive 才漏掉,正是您指出的关键。 Filter 预算 off-by-one:> → >= |
AI Code Review我已经有了足够的上下文。让我来整理一下审查意见。 发现的问题🚨 Critical
|
| duration_ms = int((time.time() - start_time) * 1000) | ||
|
|
||
| # 尝试获取部分输出 | ||
| stdout = e.stdout.decode('utf-8', errors='ignore') if e.stdout else "" |
There was a problem hiding this comment.
超时分支对 str 调 .decode 必崩
subprocess.run 使用 text=True 时 e.stdout/e.stderr 为 str,调用 .decode('utf-8') 会抛 AttributeError,使超时分支本身崩溃并被外层 except 转为 failed,违反“永不抛”原则。修复:去掉 .decode 或按 text 分支处理。
|
|
||
| # 9. 落库(内含脱敏,使用已存在的 task_id) | ||
| try: | ||
| store.save(report) |
There was a problem hiding this comment.
start_task 失败降级后仍无条件 store.save 致外键孤儿
run_review 在 try/except 中创建 store,若 start_task 失败走 UUID 降级,store 可能未定义或仍指向失败实例,:233 又无条件调用 store.save(report),导致 review_tasks 无记录时落库数据被外键约束静默丢弃产生孤儿。建议降级分支重新构造可用 store 或显式置 None 并在 save 前判空。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #201 +/- ##
==========================================
Coverage ? 87.54280%
==========================================
Files ? 467
Lines ? 44103
Branches ? 0
==========================================
Hits ? 38609
Misses ? 5494
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
概述
实现一个端到端、可验证的自动代码评审 Agent 原型。输入 git diff / 文件列表 / git 工作区变更,Agent 通过 code-review Skill 加载规则与脚本,经 Filter 治理后进入沙箱执行必要检查,把发现的问题按严重级别 / 文件 / 行号 / 证据 / 修复建议结构化输出,并将审查任务、拦截记录、监控摘要与结果写入 SQLite。
核心设计取舍:确定性规则保检出下限 + LLM 提准确率上限。规则层(正则 + AST/taint + 外部扫描器)保证 dry-run 可跑、可测;LLM 层做降噪(剔除误报)与补召回(补语义问题),可降级、可关闭。
架构
关键设计 / 创新点
(file, line, category, rule_id)保留同类不同子问题的证据(优于三元组)。SECRET_KV_KEYS单一真相源),杜绝“检出未脱 / 脱了未检”。验收对照(issue #92 八条)
evaluate.py跑全部 fixture,生成 JSON/MD/SARIFget_task_details聚合BaseFilter._before短路 + pipeline allow 才进沙箱使用方法
测试
pytest tests/ -v:187 项全通过python evaluate.py:量化评测yapf+flake8(max-line-length=120)全绿文件结构
examples/skills_code_review_agent/:agent(pipeline/rule_engine/ast_analyzer/redaction/dedup/llm_layer/report/telemetry)/ storage(七表+迁移)/ sandbox(四后端)/ filters / fixtures(8公开+12隐藏)/ tests / CLI + evaluate + READMEskills/code-review/:SKILL.md + 6 类规则 + 沙箱脚本Closes #92