mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-06 09:17:31 +00:00
feat(security): 插件按工具声明内容策略 + 目录名统一
## 一、插件声明层(用户裁定)
> 「敏感词策略也应该是插件声明啊,每个插件声明自己轮次以及自己工具的
> 敏感词策略」
SecurityProfile 新增两个字段:
ToolSensitiveWords map[string][]string // key=工具名模式(尾 *),value=词表
DetectInjection bool // 开启内核内置注入迹象识别
语义是**追加不覆盖**:整轮 SensitiveWords 仍然生效。
取宽不取窄的理由:当前处置是 B 档(标记+警示,不阻断),
多标一条只是多一句警示,漏标则是安全缺口。
## 二、修掉我自己造的「莲藕式分层」
前一版把 *security.Round 从 runInputTask 一路搬到工具链
(prepareInputTask(evt, round) → TaskFrame.SecRound →
executeToolCallOutcomeWithRound),并在 rtchild 里另补一条。
那是把**分层策略实现成跨层传参**:每多一条工具执行路径就要求调用方
多传一次句柄。profileActivator 的设计注释早就写明了正路:
> 工具调用发生在 LLM 决定之后,此时插件已不在调用栈上。
> 唯一可靠的传递方式是**内核在输入进来时记住**,在该轮的工具判定里使用。
改为 security 自取:
Runtime.ScanContentForAgent(agentID, isChild, ins, text)
→ ForAgent(agentID, isChild) // per-agent 视图,天然不串档
→ EffectiveProfile() // session > longtime
→ 合并 全局词表 + 档位词表 + 工具词表 + DetectInjection
core 只递交**事实**(我是谁 / 哪个工具 / 什么文本),不认识 Round。
与 CheckToolForAgent 同一套身份推断,不引入第二个入口语义。
TaskFrame.SecRound / executeToolCallOutcomeWithRound 全部撤除。
## 三、目录名统一
third_party/homeagent-sdk → third_party/hologramagentsdk
module 与远端仓早已是 hologramagentsdk,只剩物理目录是遗留名。
同步改了 go.mod replace、构建/打包/部署脚本、5 处测试里的分段路径。
注意:这里改的是**主仓 vendored 的 SDK 源码路径**,example/ 由 SDK
独立仓自己跟踪,主仓不涉及。
## 判据
TestToolSensitiveWordsAppendOnlyForThatTool 词表只对目标工具生效 + 追加语义
TestToolSensitiveWordsUseAgentScope security 按 agent scope 自取生效
(变异验证:删掉 ForAgent 查询 → 红)
## 验证
go build ./... → 0
go vet ./... → 0
go test ./... -count=1 -race → 62 ok / 0 FAIL / 0 DATA RACE
gofmt -l internal/ → 干净
This commit is contained in:
@ -62,7 +62,7 @@ func publishedPluginMgrMethods(t *testing.T, sdkPath string) []string {
|
||||
// 这挡住了"SDK 加了方法但忘记登记能力" ⇒ 那种方法会被按 CapCore 放行,
|
||||
// 或者直接"未知 method"。
|
||||
func TestBridgeCoversEveryPublishedPluginMgrMethod(t *testing.T) {
|
||||
sdkPath := filepath.Join("..", "..", "..", "third_party", "homeagent-sdk", "sdk", "plugin.go")
|
||||
sdkPath := filepath.Join("..", "..", "..", "third_party", "hologramagentsdk", "sdk", "plugin.go")
|
||||
methods := publishedPluginMgrMethods(t, sdkPath)
|
||||
|
||||
// SDK 方法名 → proc method 值(命名约定:StopPlugin → plugin.mgrStop)
|
||||
@ -160,16 +160,16 @@ func TestBridgeDispatchesEveryPluginMethod(t *testing.T) {
|
||||
// 漏 ⇒ 新生成的 plugin.bin **编译不过**(procPluginMgr 不满足接口)。
|
||||
// 这是最晚才发现的一环(编译期才报,且只在用户执行 hmapdev build 时暴露)。
|
||||
func TestHmapdevTemplateImplementsAllPluginMgrMethods(t *testing.T) {
|
||||
sdkPath := filepath.Join("..", "..", "..", "third_party", "homeagent-sdk", "sdk", "plugin.go")
|
||||
sdkPath := filepath.Join("..", "..", "..", "third_party", "hologramagentsdk", "sdk", "plugin.go")
|
||||
methods := publishedPluginMgrMethods(t, sdkPath)
|
||||
|
||||
tmplPath := filepath.Join("..", "..", "..", "third_party", "homeagent-sdk",
|
||||
tmplPath := filepath.Join("..", "..", "..", "third_party", "hologramagentsdk",
|
||||
"tools", "hmapdev", "templates", "proc_main.go.tmpl")
|
||||
src, err := os.ReadFile(tmplPath)
|
||||
if err != nil {
|
||||
// ★ 文件缺失必须 **skip 而不是 fail**(2026-10-17 CI 实测):
|
||||
//
|
||||
// `third_party/homeagent-sdk/tools/` 在 .gitignore 里(SDK 仓自治,
|
||||
// `third_party/hologramagentsdk/tools/` 在 .gitignore 里(SDK 仓自治,
|
||||
// 本仓不跟踪)。所以:
|
||||
// · 本机(完整 SDK 检出)有该文件 ⇒ 判据能跑
|
||||
// · CI(只 checkout 本仓)没有该文件 ⇒ 原本 Fatalf ⇒ **CI 必红**
|
||||
@ -178,7 +178,7 @@ func TestHmapdevTemplateImplementsAllPluginMgrMethods(t *testing.T) {
|
||||
// "Go build / vet / test" 和 "Build linux/amd64" 双红,把 PR 卡住。
|
||||
//
|
||||
// skip 不是放弃检查:跨仓一致性由 **SDK 仓自己的判据**守着
|
||||
// (third_party/homeagent-sdk/tools/hmapdev/scaffold_stdout_test.go
|
||||
// (third_party/hologramagentsdk/tools/hmapdev/scaffold_stdout_test.go
|
||||
// 等),那边是模板的真实归属地。本判据在本机开发时仍然生效。
|
||||
t.Skipf("跳过:SDK 仓的 tools/ 不在本仓跟踪范围(.gitignore),"+
|
||||
"跨仓一致性由 SDK 仓判据守护。缺文件: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user