M5:百工与司命——能力注册表、授契行契请命、禁域裁决与观察标证
- 百工域 domains/baigong:capabilities(统一能力契约:执行类型 builtin/qiankun/mcp/http + 四维风险标注 + 来源版本)、mandates(授契 grant / 行契 charter 预算时间窗,撤销立即生效)、tool_calls(净化摘要 + 观察标证);请命复用 pending_confirmations 加 expires_at/brief_json(超时=拒绝执行 HJ-1302,六要素说明) - 司命裁决器 siming.py:四维取最高档(能力/数据/后果/情境);禁域为代码常量不可配置(递归删根/格式化/写裸设备/fork 炸弹、file:// 协议、密钥材料外发)——专项测试断言恶意标注与篡改对象仍拒 HJ-1301 - 执行链:禁域→裁决(HJ-1303 未授契拒且双留痕)→请命→执行(乾坤经 SandboxClient HMAC;MCP 经 call_tool;内置无副作用)→净化标证(观察非事实,敏感遮蔽+体量截断)→行动账 - MCP 登记/启停/刷新自动派生与撤下 capabilities(博闻登记接入点);内置能力种子(echo/datetime/qiankun.shell/web.fetch) - 端点:/capabilities /mandates /petitions /tool-calls + /tools 兼容投影;前端百工页四区(能力目录四维标注/授契行契/请命批准拒绝/行动账观察标证) - 退役:modules/safety|skills|tool_runtime|agent、application/tool_runtime、services/skills|safety、tool_policies/skills/model_endpoint_overrides 表(迁移 006)、前端 SkillManager/ToolsConsole/旧 tools 页 - 验收(test_baigong_siming 四用例):未授契被拒留痕、请命超时不执行、禁域不可关闭、结果为观察不入忆;后端 454、前端 220、BFF 4、神识 5 包全绿(2 个预存环境失败不变)
This commit is contained in:
1 parent
144415247e
commit
684261f4b4
97 files changed
+3075
-5554
No files matched your search
@@ -82,6 +82,151 @@ export function resolveMock(
|
||||
// —— 健康检查 ——
|
||||
if (m === "GET" && path === "/health") return ok(data.health);
|
||||
|
||||
// —— 百工:能力目录 / 授契 / 请命 / 行动账 ——
|
||||
if (m === "GET" && path === "/capabilities") {
|
||||
return ok([
|
||||
{
|
||||
id: "cap_mock_001",
|
||||
name: "builtin.echo",
|
||||
description: "回显输入(无副作用演示能力)",
|
||||
executor_type: "builtin",
|
||||
executor_ref: "echo",
|
||||
risk_dims: {
|
||||
capability: "L0",
|
||||
data: "L0",
|
||||
consequence: "L0",
|
||||
context: "L0",
|
||||
},
|
||||
data_scope: "",
|
||||
destinations: "",
|
||||
source: "builtin",
|
||||
version: "1",
|
||||
consent_mode: "allow",
|
||||
enabled: true,
|
||||
mandated: true,
|
||||
},
|
||||
{
|
||||
id: "cap_mock_002",
|
||||
name: "qiankun.shell",
|
||||
description: "在乾坤沙箱中执行命令(隔离执行,HMAC 授契)",
|
||||
executor_type: "qiankun",
|
||||
executor_ref: "",
|
||||
risk_dims: {
|
||||
capability: "L2",
|
||||
data: "L1",
|
||||
consequence: "L3",
|
||||
context: "L1",
|
||||
},
|
||||
data_scope: "沙箱工作目录",
|
||||
destinations: "本机沙箱进程",
|
||||
source: "builtin",
|
||||
version: "1",
|
||||
consent_mode: "ask",
|
||||
enabled: true,
|
||||
mandated: false,
|
||||
},
|
||||
]);
|
||||
}
|
||||
if (m === "GET" && path === "/mandates") {
|
||||
return ok([
|
||||
{
|
||||
id: "mdt_mock_001",
|
||||
capability_id: "cap_mock_001",
|
||||
character_id: null,
|
||||
kind: "charter",
|
||||
scope: {},
|
||||
budget_total: 20,
|
||||
budget_used: 3,
|
||||
status: "active",
|
||||
granted_at: "2026-08-27T10:00:00Z",
|
||||
expires_at: null,
|
||||
},
|
||||
]);
|
||||
}
|
||||
if (m === "POST" && path === "/mandates") {
|
||||
return ok({ id: "mdt_mock_002", status: "active" }, 201);
|
||||
}
|
||||
if (m === "DELETE" && path.startsWith("/mandates/")) {
|
||||
return ok(null, 204);
|
||||
}
|
||||
if (m === "GET" && path === "/petitions") {
|
||||
return ok([
|
||||
{
|
||||
id: "confirm_mock_001",
|
||||
capability: "qiankun.shell",
|
||||
risk_level: "L3",
|
||||
reason: "请命:高风险动作需当次确认",
|
||||
brief: {
|
||||
who: "character:character_mock",
|
||||
what: "在乾坤沙箱中执行命令",
|
||||
capability: "qiankun.shell",
|
||||
executor: "qiankun",
|
||||
destinations: "本机沙箱进程",
|
||||
consequences: "风险等级 L3",
|
||||
alternatives: "拒绝后可调整参数或改用低风险能力",
|
||||
},
|
||||
run_id: "run_mock_001",
|
||||
character_id: "character_mock",
|
||||
created_at: "2026-08-27T10:05:00Z",
|
||||
expires_at: "2026-08-27T10:15:00Z",
|
||||
},
|
||||
]);
|
||||
}
|
||||
if (
|
||||
m === "POST" &&
|
||||
path.startsWith("/petitions/") &&
|
||||
path.endsWith("/approve")
|
||||
) {
|
||||
return ok({ status: "resolved", approved: true });
|
||||
}
|
||||
if (
|
||||
m === "POST" &&
|
||||
path.startsWith("/petitions/") &&
|
||||
path.endsWith("/deny")
|
||||
) {
|
||||
return ok({ status: "cancelled", approved: false });
|
||||
}
|
||||
if (m === "GET" && path === "/tool-calls") {
|
||||
return ok([
|
||||
{
|
||||
id: "tc_mock_001",
|
||||
capability_id: "cap_mock_001",
|
||||
run_id: "run_mock_001",
|
||||
character_id: "character_mock",
|
||||
trace_id: "trace_mock_001",
|
||||
decision: "allow",
|
||||
mandate_id: "mdt_mock_001",
|
||||
status: "ok",
|
||||
error_code: null,
|
||||
input_digest: '{"text":"琉璃之镜"}',
|
||||
output_digest: "[echo] 琉璃之镜",
|
||||
evidence: {
|
||||
kind: "observation",
|
||||
capability: "builtin.echo",
|
||||
epistemic: "observation_not_fact",
|
||||
},
|
||||
duration_ms: 3,
|
||||
created_at: "2026-08-27T10:06:00Z",
|
||||
},
|
||||
{
|
||||
id: "tc_mock_002",
|
||||
capability_id: "cap_mock_002",
|
||||
run_id: null,
|
||||
character_id: null,
|
||||
trace_id: null,
|
||||
decision: "denied_unmandated",
|
||||
mandate_id: null,
|
||||
status: "rejected",
|
||||
error_code: "HJ-1303",
|
||||
input_digest: '{"command":"ls"}',
|
||||
output_digest: "",
|
||||
evidence: { kind: "observation", capability: "qiankun.shell" },
|
||||
duration_ms: 0,
|
||||
created_at: "2026-08-27T10:07:00Z",
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
// —— 神识阁:BYOK 密钥(脱敏)——
|
||||
if (m === "GET" && path === "/me/byok-keys") {
|
||||
return ok({
|
||||
|
||||
Reference in new issue
Block a user