mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-06 17:27:31 +00:00
feat(security,device): security 成为独立内核模块(闸门+策略+限式),device 接管内置工具路由
security(新模块 internal/kernelmod/security)
- 凭据闸门:出向拦截成 @{别名}、入向清洗、执行前回填(internal/security/{gate,runtime}.go)
- 工具黑白名单 + 沙箱(读写根、网络、.. 逃逸):internal/security/policy.go
- 敏感词过滤 + 提示词注入预警(Finding 不带原文):internal/security/content.go
- 按主体授权(hard-private 对非内部主体永久拒绝):internal/security/principal.go
- 插件命名限式(可选档位,插件声明/内核执行,只能收窄):internal/security/profile.go
- 启动装配从 cmd/homed 迁入模块;启动顺序判据改盯真实装配点
device(新模块)
- 正式内核模块,Provides FacDevice,KernelState.Device
- 内置工具路由表下沉到 internal/toolroute(避免 core↔kernelboot 环),
device 保留对外入口;agent 未挂载时退化本地 switch
- Agent 侧只留 api.ToolHost/DeviceSurface 适配层
SDK
- InjectOptions.SecurityProfile:插件按 inputch 声明本轮安全档位(可选)
- InjectOptions.TurnHint:插件注入**本轮事实**,内核以独立 system 消息注入,
不混进用户正文(人设负责怎么说话,TurnHint 只放这一轮成立的事实)
- FacilitySecurity / FacilityDevice
提示词
- 内核自带 prompt/skill/工具返回全面英文化(中文提示会让模型行为漂移)
- 机制解释下沉到 4 个内置 skill(memory/output/tool-order/plugins),
skill 描述压到 80 runes 内(原来 94–108 全被索引截断)
- 默认人格模板英文化;[Voice] 段删除,规则并入 persona 块(单一段落)
- 历史记忆工具改名 coldcontext_query/commit,图记忆语义改称 stable memory
修复
- tracker: exec mount → unix.Mount(降权运行 + AmbientCapabilities 下才能挂)、
区分 EPERM 与不支持;启动日志说明后果与恢复方式
- healthcheck_kernel 输出瘦身:status.Tools 只给摘要(原 98,989 tokens/151% 预算)
- plugin_list 描述讲清 auto_start(按需)与 alive(此刻是否在跑),
明确不能由 alive=false 推断能力不存在
- pluginmgr/webui 去掉写死的 /home/newqqagent 回退路径(env → pluginDir 反推 → 报错)
- lua: 盘上适配器与内置版本不一致且无基线时响亮告警(deepseek 流式丢失
tool_calls 导致'模型不调工具'的真因)
测试:go build ./... 通过;go test ./... 60 包全绿
This commit is contained in:
@ -293,7 +293,7 @@ func TestResolveMediaRefs(t *testing.T) {
|
||||
// ---------- 文档持有的一等记忆块 ----------
|
||||
|
||||
func TestDocCommit_StoresBlocks(t *testing.T) {
|
||||
// doc_commit 带媒体时,媒体应作为一等块直接存在文档上,
|
||||
// coldcontext_commit with media stores blocks directly in cold context,
|
||||
// 并随 doc 一起持久化(块自带字节,不靠外部引用保活)。
|
||||
dir := t.TempDir()
|
||||
ds := document.NewStore(filepath.Join(dir, "docs"), memory.TokenizeWords)
|
||||
@ -323,7 +323,7 @@ func TestDocCommit_StoresBlocks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 文档持有块标签(doc_query 展示用) ----------
|
||||
// ---------- 文档持有块标签(coldcontext_query 展示用) ----------
|
||||
|
||||
func TestBlockLabelsForDoc(t *testing.T) {
|
||||
a := newInputTestAgent(t)
|
||||
@ -363,7 +363,7 @@ func TestBlockLabel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 模型工具端到端:memory_commit / doc_commit / doc_query ----------
|
||||
// ---------- model tool end-to-end: memory_commit / coldcontext_commit / coldcontext_query ----------
|
||||
|
||||
func newToolTestAgent(t *testing.T) *Agent {
|
||||
t.Helper()
|
||||
@ -412,7 +412,7 @@ func TestToolMemoryCommit_BindsMedia(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
if !strings.Contains(out, "关联") {
|
||||
if !strings.Contains(out, "linked") && !strings.Contains(out, "media") {
|
||||
t.Errorf("返回值应告知模型媒体已关联: %q", out)
|
||||
}
|
||||
|
||||
@ -485,7 +485,7 @@ func TestToolMemoryCommit_CarriesSentenceText(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// doc_commit 带 media_refs:媒体成为文档直接持有的一等块;正文保持原样。
|
||||
// coldcontext_commit with media_refs: media becomes a first-class block held by cold context;
|
||||
func TestToolDocCommit_BindsMedia(t *testing.T) {
|
||||
a := newToolTestAgent(t)
|
||||
b := mediaBlock("image/png", []byte("doc-commit-bytes"))
|
||||
@ -494,14 +494,14 @@ func TestToolDocCommit_BindsMedia(t *testing.T) {
|
||||
}
|
||||
|
||||
out := a.executeDocTool(agentAPI.ToolCall{
|
||||
Name: "doc_commit",
|
||||
Name: "coldcontext_commit",
|
||||
Arguments: map[string]interface{}{
|
||||
"content": "这是一篇带图的笔记正文。",
|
||||
"summary": "带图笔记",
|
||||
"media_digests": []interface{}{b.ID[:12]},
|
||||
},
|
||||
})
|
||||
if !strings.Contains(out, "关联") {
|
||||
if !strings.Contains(out, "linked") && !strings.Contains(out, "media") {
|
||||
t.Errorf("返回值应告知模型媒体已关联: %q", out)
|
||||
}
|
||||
|
||||
@ -524,7 +524,7 @@ func TestToolDocCommit_BindsMedia(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// doc_query 必须把媒体说明附在返回值里,否则模型检索到带图文档也不知道有图。
|
||||
// coldcontext_query 必须把媒体说明附在返回值里,否则模型检索到带图文档也不知道有图。
|
||||
func TestToolDocQuery_ShowsMedia(t *testing.T) {
|
||||
a := newToolTestAgent(t)
|
||||
b := mediaBlock("image/png", []byte("query-bytes"))
|
||||
@ -533,7 +533,7 @@ func TestToolDocQuery_ShowsMedia(t *testing.T) {
|
||||
}
|
||||
|
||||
a.executeDocTool(agentAPI.ToolCall{
|
||||
Name: "doc_commit",
|
||||
Name: "coldcontext_commit",
|
||||
Arguments: map[string]interface{}{
|
||||
"content": "紫蓝红三色带配色说明正文",
|
||||
"summary": "紫蓝红三色带",
|
||||
@ -542,7 +542,7 @@ func TestToolDocQuery_ShowsMedia(t *testing.T) {
|
||||
})
|
||||
|
||||
a.executeDocTool(agentAPI.ToolCall{
|
||||
Name: "doc_query",
|
||||
Name: "coldcontext_query",
|
||||
Arguments: map[string]interface{}{"query": "紫蓝红三色带 配色说明", "top_k": float64(3)},
|
||||
})
|
||||
|
||||
@ -554,7 +554,7 @@ func TestToolDocQuery_ShowsMedia(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Error("doc_query 未把媒体说明带进上下文 —— 模型不知道这篇文档带过图")
|
||||
t.Error("coldcontext_query 未把媒体说明带进上下文 —— 模型不知道这篇文档带过图")
|
||||
}
|
||||
}
|
||||
|
||||
@ -578,7 +578,7 @@ func TestTools_UnknownRefDegrades(t *testing.T) {
|
||||
}
|
||||
|
||||
out = a.executeDocTool(agentAPI.ToolCall{
|
||||
Name: "doc_commit",
|
||||
Name: "coldcontext_commit",
|
||||
Arguments: map[string]interface{}{
|
||||
"content": "引用未知块的文档",
|
||||
"media_digests": []interface{}{"aabbccddeeff"},
|
||||
|
||||
Reference in New Issue
Block a user