Hierarchical policy inheritance system for OpenClaw agents. Enables policies to be defined at organization, team, project, and session levels with automatic inheritance, override rules, and conflict resolution. Use when setting up governance policies that need to cascade across multiple sessions, when defining policy hierarchies, or when resolving policy conflicts between parent and child contexts. Required tools - exec, read, write. Environment variables - GOVERNANCE_ROOT (default ~/.openclaw/g
该技能提供了一种分层策略继承系统,允许在多个层级定义策略,并由子上下文自动继承。
策略从宽泛到具体逐级传递:
组织(最宽泛)
↓
团队
↓
项目
↓
会话(最具体)
每个层级包含一个policies.yaml文件:
yaml
shell:
- command: git *
action: allow
- command: rm -rf /*
action: deny
reason: 破坏性命令已被阻止
- command: *
action: require_approval
file:
read:
- path: ~/workspace/*
action: allow
- path: /etc/*
action: deny
write:
- path: ~/workspace/*
action: allow
- path: *
action: require_approval
bash
python scripts/init_governance.py --level organization --path ~/.openclaw/governance
bash
python scripts/init_governance.py --level team --name engineering --parent ~/.openclaw/governance/organization
typescript
const result = await context.tools.governanceInheritance.evaluate({
action: http,
details: { method: GET, url: https://api.example.com/data },
context: {
sessionId: sess_123,
project: my-project,
team: engineering
}
});
// result: { allowed: true } | { allowed: false, reason: ..., level: organization }
评估操作时,系统会:
| 父级 | 子级 | 结果 |
|---|---|---|
| allow | allow | allow |
| allow |
策略根据会话上下文自动加载:
yaml
根据继承的策略链评估操作。
参数:
返回:
typescript
{
allowed: boolean,
reason?: string,
level: string, // 做出决定的策略层级
policy?: string, // 匹配的具体策略
requiresApproval?: boolean
}
初始化新的策略层级。
参数:
验证策略链是否存在冲突或错误。
参数:
返回:
typescript
{
valid: boolean,
errors: string[],
warnings: string[]
}
在环境中设置治理根目录:
bash
export GOVERNANCE_ROOT=~/.openclaw/governance
或者在openclaw.json中:
json
{
skills: {
governance-inheritance: {
env: {
GOVERNANCE_ROOT: ~/.openclaw/governance
}
}
}
}
yaml
level: organization
policies:
http:
- pattern: *.company.internal
action: allow
- pattern: *
action: require_approval
shell:
- command: *
action: require_approval
yaml
level: team
parent: ../organization
inheritance:
mode: merge
policies:
http:
- pattern: *.github.com
action: allow
- pattern: *.npmjs.com
action: allow
shell:
- command: git *
action: allow
- command: npm *
action: allow
- command: docker *
action: allow
yaml
level: project
parent: ../engineering
inheritance:
mode: merge
policies:
http:
- pattern: api.stripe.com
action: allow # 该项目使用Stripe
file:
write:
- path: ./dist/*
action: allow
该技能与governclaw-middleware协同工作:
typescript
// governclaw-middleware调用governance-inheritance进行策略解析
const policyResult = await context.tools.governanceInheritance.evaluate({
action: http,
details: { method, url, headers },
context: sessionContext
});
if (!policyResult.allowed) {
return { blocked: true, reason: policyResult.reason };
}
始终检查策略评估错误:
typescript
const result = await context.tools.governanceInheritance.evaluate({...});
if (result.error) {
// 策略链配置错误
console.error(策略错误:, result.error);
return { error: 治理配置错误 };
}
if (!result.allowed) {
// 策略阻止了操作
console.log(被, result.level, 策略阻止:, result.reason);
}
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 governance-inheritance-1776117673 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 governance-inheritance-1776117673 技能
skillhub install governance-inheritance-1776117673
文件大小: 13.09 KB | 发布时间: 2026-4-14 13:31