mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-01 06:47:29 +00:00
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 包全绿
93 lines
3.5 KiB
Go
93 lines
3.5 KiB
Go
package toolroute
|
||
|
||
// 内置工具的**分发**(路由)归属 device。
|
||
//
|
||
// ## 这一步搬的是什么
|
||
//
|
||
// 原先 `agent/core/toolcall.go` 的 `executeToolCallInner` 自己写了一张
|
||
// "工具名前缀 → 族处理器"的 switch。那张表是本模块的第一份事实来源,
|
||
// 现在搬到这里:
|
||
//
|
||
// device.Dispatch(handlers, tc) → 选族 → handlers.ExecuteXxx(tc)
|
||
//
|
||
// 第二阶段再把**族实现**(memory_* / knowledge_* / coldcontext_* …)
|
||
// 从 core 搬进 device(依赖改为显式 Deps),路由这一段不用再动。
|
||
//
|
||
// ## 为什么保留族粒度
|
||
//
|
||
// 族内工具共享同一批依赖,按族传接口让 device 在不认识 Agent 内部字段的
|
||
// 前提下完整接管路由;逐工具传接口会让 30+ 个方法散成一张大表。
|
||
|
||
import (
|
||
"strings"
|
||
|
||
"github.com/JianFeeeee/HologramAgent/internal/agent/api"
|
||
)
|
||
|
||
// Dispatch 按工具名选出族处理器并执行。
|
||
//
|
||
// 返回 (结果文本, 是否属于内置工具):
|
||
// - handled=false 表示"不是内置工具",调用方应继续走插件/设备路径。
|
||
// 这是关键语义:**device 不吞掉未知工具**,否则插件工具会消失。
|
||
func Dispatch(h api.BuiltinToolHandlers, tc api.ToolCall, turnScenes []string) (string, bool) {
|
||
if h == nil {
|
||
return "", false
|
||
}
|
||
switch {
|
||
case tc.Name == "persona_set":
|
||
return h.ExecutePersonaTool(tc), true
|
||
case strings.HasPrefix(tc.Name, "memory_"):
|
||
return h.ExecuteMemoryTool(tc, turnScenes), true
|
||
case strings.HasPrefix(tc.Name, "social_"):
|
||
return h.ExecuteSocialTool(tc), true
|
||
case strings.HasPrefix(tc.Name, "knowledge_"):
|
||
return h.ExecuteKnowledgeTool(tc), true
|
||
case strings.HasPrefix(tc.Name, "coldcontext_"):
|
||
// doc_* 是旧前缀(工具已改名),保留兼容:插件/测试仍有旧调用。
|
||
return h.ExecuteColdContextTool(tc), true
|
||
case strings.HasPrefix(tc.Name, "doc_"):
|
||
return h.ExecuteColdContextTool(tc), true
|
||
case strings.HasPrefix(tc.Name, "secret_"):
|
||
return h.ExecuteSecretTool(tc), true
|
||
case strings.HasPrefix(tc.Name, "output_send__") && strings.HasSuffix(tc.Name, "_help"):
|
||
return h.ExecuteOutputSendHelp(tc), true
|
||
case strings.HasPrefix(tc.Name, "output_send__"):
|
||
return h.ExecuteOutputSend(tc), true
|
||
case tc.Name == "output_list_channels":
|
||
return h.ExecuteOutputListChannels(), true
|
||
case tc.Name == "input_channels":
|
||
return h.ExecuteInputChannels(tc), true
|
||
case tc.Name == "resident_agents":
|
||
return h.ExecuteResidentAgents(tc), true
|
||
case tc.Name == "notify_parent":
|
||
return h.ExecuteNotifyParent(tc), true
|
||
case tc.Name == "inputch_note":
|
||
return h.ExecuteInputchNote(tc), true
|
||
case tc.Name == "plgreload":
|
||
return h.ExecutePluginReload(), true
|
||
case tc.Name == "get_plugin_tools":
|
||
name, _ := tc.Arguments["plugin_name"].(string)
|
||
return h.ExecuteGetPluginTools(name), true
|
||
}
|
||
return "", false
|
||
}
|
||
|
||
// IsBuiltinTool 报告某名字是否会由 Dispatch 处理(供诊断与提示词使用)。
|
||
//
|
||
// ★ 与 Dispatch 共用同一套前缀常量,避免"两套语义"(历史上出现过
|
||
// "模型看得到但插件查不到"的漂移)。
|
||
func IsBuiltinTool(name string) bool {
|
||
switch {
|
||
case name == "persona_set", name == "output_list_channels", name == "input_channels",
|
||
name == "resident_agents", name == "notify_parent", name == "inputch_note",
|
||
name == "plgreload", name == "get_plugin_tools":
|
||
return true
|
||
}
|
||
for _, p := range []string{"memory_", "social_", "knowledge_", "coldcontext_", "doc_", "secret_", "output_send__"} {
|
||
if strings.HasPrefix(name, p) {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|