Skip to content

feat(examples): add sandboxed code review agent - #243

Open
Wsp030914 wants to merge 4 commits into
trpc-group:mainfrom
Wsp030914:feat/skills-code-review-agent
Open

feat(examples): add sandboxed code review agent#243
Wsp030914 wants to merge 4 commits into
trpc-group:mainfrom
Wsp030914:feat/skills-code-review-agent

Conversation

@Wsp030914

Copy link
Copy Markdown

Add a Skills-based code review agent with policy-gated container execution, unified diff parsing, structured findings, SQLite audit storage, and JSON/Markdown reports.

Provide eight fixtures, fake-model and dry-run modes, deduplication, secret redaction, execution limits, and integration tests.

Fixes #92

RELEASE NOTES: Added a sandboxed code review agent example.

Fixes trpc-group#92

RELEASE NOTES: Added a sandboxed code review agent example.
Avoid Docker initialization during dry-run and clean staged skill links safely across POSIX and Windows runtimes.
@helloopenworld

Copy link
Copy Markdown
Contributor

AI Code Review

发现的问题

🚨 Critical

未发现 Critical 问题。

⚠️ Warning

  • examples/skills_code_review_agent/agent/sandbox.py:316-338:成功路径下输出先截断再脱敏,可能突破字节上限

    • _normalize_result 中先用 _bounded_outputsoutput_limit_bytes 截断 stdout/stderr/output,随后再 redact_text;而 _failuresandbox.py:366)的顺序是先脱敏再截断。脱敏会把 ≥8 字符的密钥替换为 [REDACTED]/Bearer [REDACTED](更长),导致最终持久化与上报的 stdout/stderr 略超 output_limit_bytes,破坏“bounded output”契约且无测试覆盖。建议统一为“先脱敏、后截断”或在脱敏后再做一次截断。
  • tests/examples/skills_code_review_agent/test_acceptance.py:197-217test_python_source_meets_static_limitsscan_rules.py 等技能脚本纳入 AST 复杂度/行数检查

    • 该静态限制测试遍历 EXAMPLE_ROOT.rglob("*.py"),其中包含 skills/code-review/scripts/scan_rules.py(442 行、含大型 RULES 元组)。若后续向扫描器追加规则使函数体增长,会直接阻塞 CI(MAX_FUNCTION_LINES/MAX_FUNCTION_STATEMENTS),把扫描器内部演进与示例源码风格约束耦合在一起。建议将技能脚本排除在静态限制范围外,或单独放宽其阈值。

💡 Suggestion

  • examples/skills_code_review_agent/agent/sandbox.py:267-274_within_budgetremaining <= 0 时手动 operation.close() 再抛 TimeoutError,依赖协程对象有 close 方法;可统一通过 asyncio.wait_for(对 remaining<=0 直接抛错)处理,减少分支、避免对底层 awaitable 形态的隐式假设。

总结

整体安全模型(固定 argv、摘要校验、路径白名单、网络隔离、fail-closed 过滤、脱敏)设计完整且测试覆盖较充分。未发现必须修复的阻塞问题;主要风险是成功路径下“截断后脱敏”可能使输出轻微超出声明上限,以及静态限制测试把技能脚本纳入 CI 门槛,建议修复。

测试建议

  • 建议补一条成功路径测试:构造含真实密钥形态的 sandbox stdout,断言 _normalize_result 产出的 stdout+stderr+output 字节数 ≤ output_limit_bytes,覆盖“先截断后脱敏”的边界。

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@6a2f7f9). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             main        #243   +/-   ##
==========================================
  Coverage        ?   87.93985%           
==========================================
  Files           ?         482           
  Lines           ?       45157           
  Branches        ?           0           
==========================================
  Hits            ?       39711           
  Misses          ?        5446           
  Partials        ?           0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

基于 Skills + 沙箱 + 数据库存储构建自动代码评审 Agent

2 participants