examples: add skills-based code review agent example (#92) - #268
examples: add skills-based code review agent example (#92)#268xiyue1753 wants to merge 3 commits into
Conversation
Add a skills_code_review_agent example under examples/ that composes Skill loading, deterministic rule engine (10 rules covering security, resource leaks, error handling, and testing), Docker container/local subprocess sandbox with timeout/output limits, three-level Filter governance (deny/ask/needs_human_review), SQLite persistence (6 tables), and JSON/Markdown dual-format structured reports. Supports --diff-file, --repo-path, and --files input modes. Agent mode via LlmAgent + SkillToolSet with FakeModel (no API key required) or real LLM (OpenAI-compatible). Includes 40 unit tests and 8 diff fixtures covering clean code, security issues, resource leaks, DB lifecycle, missing tests, deduplication, sandbox failure, and sensitive info. Fixes trpc-group#92 RELEASE NOTES: New code review agent example integrates Skills, sandbox execution, SQLite persistence, and three-level Filter governance for automated Python diff review. Signed-off-by: xiyue1753 <xiyuekl@qq.com>
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
AI Code ReviewDocker 在沙箱环境中不可用。我很确定 现在我已经有足够的信息来撰写审查报告了。让我完成最终定稿。 发现的问题🚨 Critical
|
| args = part.function_call.args or {} | ||
| command = str(args.get('command', '') or args.get('cmd', '')) | ||
| if command: | ||
| level, pattern = classify_command(command) |
There was a problem hiding this comment.
三级命令治理仅拦截 deny,ask/needs_human_review 被放行
安全过滤器对 deny 级仅设置 is_continue=False 并写 error,但 ask/needs_human_review(sudo、pip install、curl 等)仅 pass 放行,未阻断或确认。建议在 _before 中对 ask 至少设置 rsp.is_continue=False 并触发人工确认,或由编排层在执行前强制校验 filter_action。
- filter_agent: block ask-level commands in Agent mode - sandbox/runner: replace docker --timeout with timeout command - parse_diff.py: accept stdin when no file argument (Docker compat) - run_review: pass diff via stdin to sandbox scripts - run_review: save sandbox_run records in Agent event loop - static_check.py: fix open() without with statement - filter.py: remove duplicate chmod/chown from REVIEW_PATTERNS - run_review: drop redundant hasattr() in input_source logic Signed-off-by: xiyue1753 <xiyuekl@qq.com>
|
I have read the CLA Document and I hereby sign the CLA |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #268 +/- ##
==========================================
Coverage ? 88.43489%
==========================================
Files ? 491
Lines ? 46035
Branches ? 0
==========================================
Hits ? 40711
Misses ? 5324
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AI Code Review这确认了 发现的问题🚨 Critical
|
…eptance gaps
Three-level tool filter (deny block / ask+needs_human_review confirm)
attached to skill_run via SkillToolSet run_tool_kwargs. Token-level
command classifier replaces naive substring matching.
Agent-mode safety gap closed: per-command timeout, global budget,
--strict-env whitelist, --non-interactive flag, local runtime
isolation warning, cube backend (sync + agent, clear error without
credentials), cube sandbox destroy on cleanup.
LLM findings merged (FINDINGS_JSON parse + dedup) into report findings.
Hard truncation replaced with size-capped full capture.
Fixes: filter wiring, env/budget passthrough, de-truncation,
token classification, cube sandbox leak
Closes: acceptance criteria trpc-group#2 / trpc-group#4 / trpc-group#7 / trpc-group#8
Signed-off-by: xiyue1753 <xiyuekl@qq.com>
概述
基于 trpc-agent-python 的 Skill 体系、CodeExecutor 沙箱、SQLite 持久化和
Filter 治理能力,构建一个面向 Python 项目的自动代码评审 Agent 示例。
该示例不依赖 LLM API 即可在 dry-run 模式下运行,也可通过 --model 接入
OpenAI 兼容的 LLM(如 DeepSeek)实现 Agent 驱动的 skill_load / skill_run 编排。
主要修改
新增 examples/skills_code_review_agent/ 目录,包含:
Filter 治理语义与验收标准 #7
验收标准 #7 要求 "deny / needs_human_review 不能直接进入沙箱执行":本示例严格满足——deny 始终拦截,ask/needs_human_review 必须经人工确认(或 --non-interactive 自动拒绝)后才可能执行,所有决策完整落库供审计。confirm/record 回调可注入,便于测试与自动化接入。
验证
python -m pytest test_code_review_agent.py→ 88 passed + 3 skipped(无 trpc_agent_sdk 环境跳过框架依赖 e2e)python run_review.py --diff-file fixtures/<name>.diff→ 8/8 通过python run_review.py --agent --model deepseek-chat→ skill_load ✅python run_review.py --repo-path <repo>→ git diff HEAD → review ✅python run_review.py --files a.py b.py→ synthetic diff ✅python storage/init_db.py --db-path review.db→ 6 张业务表, foreign keys ON关联 Issue
Fixes #92
提交清单
RELEASE NOTES: 新增 skills_code_review_agent 示例,集成 Skills、Docker/Cube 沙箱执行、SQLite 持久化和三级 Filter 治理(deny/ask/needs_human_review 执行前人工决策),支持自动 Python diff 代码评审。