360 Secure SkillHub
360 安全技能中心

Tetra Scar Code Review

对源码文件或 diff 做安全、性能、正确性、可维护性四维启发式检查;当审查漏掉某类缺陷后,可用 record-miss 记录模式形成瘢痕,之后检查时反射弧会匹配相似模式并报警,无需调用 LLM。纯标准库实现,记录以 JSONL 保存。

aibenyclaude-coder
aibenyclaude-coder
热度 39.59
最近更新 2026-05-11 17:34:36
分类:开发依赖:代码执行 / 读写文件应用场景:代码审查 / 调试排错

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add tetra-scar-code-review
Metadata
name
scar-code-review
description
Code review that learns from failures. Reflex arc blocks repeat mistakes without LLM calls. Combines systematic checklist review (security, performance, correctness, maintainability) with scar memory — when a review misses a bug, record a scar, and the reflex arc automatically flags similar patterns next time.
version
0.1.0
author
b-button-corp
tags
["code-review","safety","memory","learning","scar"]
requires
{"binaries":["python3"]}

scar-code-review

What this does

A code review system that learns from its own misses. Two layers work together:

  1. Checklist review — Regex/heuristic checks across 4 dimensions:

    • Security: SQL injection, hardcoded secrets, XSS, eval/exec
    • Performance: N+1 queries, missing pagination, unbounded SELECTs
    • Correctness: Unchecked nulls, off-by-one patterns, unhandled promises
    • Maintainability: Long functions, deep nesting, magic numbers
  2. Scar reflex arc — Pattern-matching against past review misses. When a review fails to catch a bug that later causes an incident, record a scar. Next time, the reflex fires before the LLM even looks at the diff.

No external dependencies. stdlib only. Python 3.9+.

Quick start

Review a file:

python3 scar_code_review.py review path/to/file.py

Check a diff against past scars:

python3 scar_code_review.py check-diff path/to/changes.diff

Record a missed review finding:

python3 scar_code_review.py record-miss \
  --what-missed "Missed SQL injection in user input handler" \
  --pattern "execute.*format.*user" \
  --severity critical

File format

JSONL, compatible with tetra-scar:

{"id":"rscar_1234","what_missed":"...","pattern":"...","severity":"critical","created_at":"..."}

Integration

from scar_code_review import review, reflex_check, record_miss, load_review_scars

# Review a file
findings = review("app/views.py")
for f in findings:
    print(f"{f['severity']} [{f['dimension']}] {f['message']} (line {f['line']})")

# Check diff against past scars
scars = load_review_scars()
blocks = reflex_check(diff_text, scars)
for b in blocks:
    print(f"BLOCKED: {b}")

# Record a miss after an incident
record_miss(
    what_missed="Missed unvalidated redirect",
    pattern="redirect.*request\\.GET",
    severity="high",
)