Install
openclaw skills install multi-user-privacyAutomatically identifies users, isolates memories, filters sensitive content, manages sessions and sub-agents, and enforces role-based privacy and quota cont...
openclaw skills install multi-user-privacy版本:v0.9.0 - Gateway 自动创建子代理版
定位: ClawHub 首个多用户隐私保护技能
状态: ✅ 生产环境验证
更新: 2026-03-12 - 实现 Gateway 自动创建子代理功能
┌─────────────────────────────────────────────────────────┐
│ 主代理 (路由器) │
├─────────────────────────────────────────────────────────┤
│ │
│ 1️⃣ 身份识别层 │
│ └── 读取 sender_id │
│ ├── 管理员 (ou_b96f5424607baf3a0455b55e0f4a2213)│
│ └── 普通用户 │
│ ↓ │
│ 2️⃣ Session 管理层 │
│ └── 查找或创建用户专属 session │
│ ├── session_laoliu │
│ ├── session_sun │
│ └── session_xie │
│ ↓ │
│ 3️⃣ 记忆隔离层 │
│ └── 加载对应记忆文件 │
│ ├── 管理员:MEMORY.md + 当日记忆 │
│ └── 普通用户:users/{user_id}.md + 当日记忆 │
│ ↓ │
│ 4️⃣ 隐私检查层 │
│ └── 回复前检查 │
│ ├── 敏感词检查 │
│ ├── 账号 ID 检查 │
│ └── 角色称呼检查 │
│ ↓ │
│ 5️⃣ 子代理路由层 │
│ └── 转发到对应子代理 │
│ ├── 子代理处理 │
│ └── 返回回复 │
│ │
└─────────────────────────────────────────────────────────┘
// privacy-guard.js
function getUserIdFromContext(context) {
const chatId = context.chat_id || context.user_id || context.sender_id;
if (!chatId) return null;
const match = chatId.match(/(ou_[a-z0-9]+)/);
return match ? match[1] : null;
}
function isAdmin(userId) {
return userId === ADMIN_ID; // ou_b96f5424607baf3a0455b55e0f4a2213
}
// privacy-guard.js
function loadMemory(userId) {
const results = { loaded: [], missing: [] };
const today = new Date().toISOString().split('T')[0];
const USER_MEMORY_DIR = path.join(MEMORY_DIR, 'users');
// 管理员:加载完整记忆
if (isAdmin(userId)) {
if (fs.existsSync(MEMORY_PATH)) {
results.loaded.push(MEMORY_PATH);
}
} else {
// 普通用户:只能访问自己的记忆
const userMemoryPath = path.join(USER_MEMORY_DIR, `${userId}.md`);
if (fs.existsSync(userMemoryPath)) {
results.loaded.push(userMemoryPath);
}
}
// 所有用户都可以访问当日记忆
const todayPath = path.join(MEMORY_DIR, `${today}.md`);
if (fs.existsSync(todayPath)) {
results.loaded.push(todayPath);
}
return results;
}
// privacy-guard.js
function enhancedCheck(message, userId) {
const issues = [];
// 如果不是管理员,检查敏感词
if (!isAdmin(userId)) {
const forbiddenTerms = ['老刘', '主人', '管理员', '主账号'];
for (const term of forbiddenTerms) {
if (message.includes(term)) {
issues.push({
type: 'forbidden_term',
value: term,
severity: 'high',
message: `检测到敏感词汇:${term}`
});
}
}
// 检查是否暗示其他账号存在
const otherAccountPatterns = [
/其他账号/g,
/另一个用户/g,
/还有人/g,
/除了你之外/g
];
for (const pattern of otherAccountPatterns) {
if (pattern.test(message)) {
issues.push({
type: 'isolation_breach',
value: pattern.toString(),
severity: 'medium',
message: '暗示其他账号存在'
});
}
}
}
return {
passed: issues.length === 0,
issues,
blocked: issues.some(i => i.severity === 'high')
};
}
// session-guard.js
class SessionManager {
constructor() {
this.sessions = this.loadSessionDB();
}
async getSession(userId) {
// 检查是否已有 session
if (this.sessions[userId]) {
return this.sessions[userId];
}
// 创建新 session
const session = {
userId,
createdAt: new Date().toISOString(),
lastActiveAt: new Date().toISOString(),
messageCount: 0
};
this.sessions[userId] = session;
this.saveSessionDB();
return session;
}
checkSessionMatch(currentUserId, expectedUserId) {
return currentUserId === expectedUserId;
}
}
// subagent-router.js
class SubAgentRouter {
constructor() {
this.userSessions = this.loadRouterDB();
}
async getUserSession(userId) {
// 检查是否已有子代理
if (this.userSessions[userId]) {
return this.userSessions[userId];
}
// 创建新子代理
const session = await sessions_spawn({
label: userId,
task: `${userId} 的专属子代理`,
mode: 'session',
thread: true
});
this.userSessions[userId] = session;
this.saveRouterDB();
return session;
}
}
# 通过 ClawHub 安装
npx clawhub install multi-user-privacy
# 或手动安装
git clone https://github.com/your-repo/multi-user-privacy.git
cp -r multi-user-privacy ~/.openclaw/skills/
1. 创建隐私配置文件
cat > ~/.openclaw/workspace/.privacy-config.json << 'EOF'
{
"admin": {
"id": "ou_b96f5424607baf3a0455b55e0f4a2213",
"name": "管理员",
"role": "admin"
},
"privacy": {
"mode": "strict",
"forbiddenTerms": ["敏感词 1", "敏感词 2"]
}
}
EOF
2. 创建项目配置文件
cat > ~/.openclaw/workspace/.projects-config.json << 'EOF'
{
"projects": {
"your-project": {
"name": "你的项目",
"owner": "your_user_id",
"collaborators": ["collab_id_1", "collab_id_2"]
}
}
}
EOF
3. 启用自动注入
在 OpenClaw 主入口添加:
// ~/.openclaw/runtime/main.js 开头
require('./skills/multi-user-privacy/scripts/auto-inject');
node scripts/session-guard.js stats
node scripts/view-logs.js
node scripts/subagent-router.js list
node scripts/session-guard.js clear
MIT License