端侧隐私保护 Skill 套件 —— 智能打码 · 行为监控 · 规则自进化
MaskClaw 是一个基于端侧 Tool-Use 的隐私前置代理框架,充当云端 Agent (AutoGLM) 与手机/桌面 UI 之间的"安全保镖"。
系统通过端侧 MiniCPM-V 大模型调度一组原子化工具 (Skills),在执行前对敏感数据进行实时识别、动态脱敏,并通过用户行为反馈实现隐私防护策略的 自进化。
text
┌────────────────────────────────────────────────────────────────┐
│ MaskClaw 四层协同架构 │
├────────────────────────────────────────────────────────────────┤
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ 感知层 │ → │ 认知层 │ → │ 工具层 │ → │ 进化层 │ │
│ │Perception│ │Cognition │ │Tool-Use │ │Evolution │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
│ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ ChromaDB RAG 规则知识库 │ │
│ └────────────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────────────┘
Skill功能核心能力Smart_Masker智能视觉打码基于 RapidOCR 识别敏感文本,支持高斯模糊/马赛克/色块覆盖Behavior_Monitor行为监控持续监听 Agent 操作,捕获用户主动干预动作Skill_Evolution规则自进化基于爬山法持续优化 SOP,沙盒测试验证后自动挂载
bash
# Python >= 3.10
pip install rapidocr opencv-python numpy transformers chromadb
bash
cd model_server
python minicpm_api.py
# 模型服务将监听 http://127.0.0.1:8000
python
from skills.smart_masker import VisualMasker
masker = VisualMasker()
keywords = ["手机号", "身份证", "银行卡"]
result = masker.process_image(
image_path="test.jpg",
sensitive_keywords=keywords,
method="blur"
)
print(f"检测到 {result['regions_count']} 个敏感区域")
print(f"脱敏图片: {result['masked_image_path']}")
python
from skills.behavior_monitor import log_action_to_chain
log_action_to_chain(
user_id="user_001",
action="share_or_send",
resolution="block",
scenario_tag="钉钉发送病历截图",
app_context="钉钉",
field="medical_record",
pii_type="MedicalRecord",
correction_type="user_denied",
auto_flush=True,
)
python
from skills.evolution_mechanic import SOPEvolution
engine = SOPEvolution()
result = engine.run_pipeline(
user_id="user_001",
draft_name="钉钉隐私规则",
step="all",
)
text
maskclaw-core/
├── SKILL.md # 本文件
├── scripts/
│ ├── smart_masker.py # 智能打码核心模块
│ ├── smart_masker_demo.py # 打码演示脚本
│ ├── behavior_monitor.py # 行为监控核心模块
│ ├── behavior_monitor_demo.py # 监控演示脚本
│ ├── evolution_mechanic.py # 进化引擎核心模块
│ └── evolution_demo.py # 进化演示脚本
├── references/
│ ├── ARCHITECTURE.md # 系统架构文档
│ ├── SKILLS_API.md # Skills API 契约
│ ├── RAG_SCHEMA.md # 向量数据库设计
│ ├── PROMPT_TEMPLATES.md # Prompt 模板
│ └── SELF_EVOLUTION.md # 自进化机制设计
├── assets/
│ ├── rule_schema.json # 规则 Schema 模板
│ └── sop_template.md # SOP 模板
└── evals/
└── evals.json # 测试用例定义
方法: process_image(image_path, sensitive_keywords, method='blur')
参数类型必填说明image_path``str✅图片路径sensitive_keywords``List[str]✅敏感关键词列表method``str❌blur(默认) / mosaic / block
返回值:
json
{
"success": true,
"masked_image_path": "temp/masked_xxx.jpg",
"detected_regions": [{"text": "138****5678", "bbox": [x1, y1, x2, y2]}],
"regions_count": 1,
"processing_time_ms": 45
}
方法: log_action_to_chain(user_id, action, resolution, scenario_tag, ...)
参数类型必填说明user_id``str✅用户标识action``str✅操作类型resolution``str✅决策结果scenario_tag``str✅场景标签correction_type``str❌纠错类型
返回值:
json
{
"chain_id": "user_001_钉钉发送病历_1700000001",
"action_count": 1,
"has_correction": false
}
方法: run_pipeline(user_id, draft_name, step='all', ...)
参数类型必填说明user_id``str✅用户标识draft_name``str✅草稿名称step``str❌rebuild/ init/ evolve/ sandbox/ publish/ all
返回值:
json
{
"success": true,
"evolve": {
"total_iterations": 5,
"final_score": 92.5,
"reached_threshold": true
},
"sandbox": {"passed": true},
"publish": {"skill_name": "dingtalk-privacy-rule", "version": "v1.0.0"}
}
判决条件系统行为Allow规则库完整匹配,安全直接放行Block规则库完整匹配,风险明确直接拦截Mask规则库完整匹配,需脱敏执行打码后放行Ask规则库信息不完整主动向用户确认Unsure新场景无记录标记并等待用户教授
text
┌─────────────────────────────────────────────────────────────┐
│ 第 1 步:agent 对 skill 做一个小改动 │
│ (比如:加一条"必须核对输入数据"的规则) │
├─────────────────────────────────────────────────────────────┤
│ 第 2 步:用改动后的 skill 跑 10 个测试用例 │
├─────────────────────────────────────────────────────────────┤
│ 第 3 步:用 checklist 给每个输出打分 │
│ (4 个检查项全过 = 100 分,3 个过 = 75 分...) │
├─────────────────────────────────────────────────────────────┤
│ 第 4 步:算平均分 │
│ - 比上一轮高 → 保留改动 │
│ - 比上一轮低 → 撤销改动 │
├─────────────────────────────────────────────────────────────┤
│ 第 5 步:重复,直到连续 3 轮分数超过 90% 或你喊停 │
└─────────────────────────────────────────────────────────────┘
错误码说明处理建议MASK_001图片解码失败检查图片格式MASK_002图片过大压缩后重试MASK_003OCR 识别失败检查图片质量MONITOR_001日志写入失败检查存储权限EVOLUTION_001规则生成失败减少测试用例批次EVOLUTION_002沙盒测试超时检查测试环境
MIT License