mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-06 17:27: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:
@ -38,7 +38,7 @@ go env: CC=gcc CGO_ENABLED=1 GOOS=linux GOARCH=amd64
|
||||
|
||||
### 2.2 已有纯 C 先例,可直接复用
|
||||
|
||||
`third_party/homeagent-sdk/remotedevice/` 是一个**零外部依赖**的纯 C 库
|
||||
`third_party/hologramagentsdk/remotedevice/` 是一个**零外部依赖**的纯 C 库
|
||||
(1320 行),已含可复用组件:
|
||||
|
||||
| 文件 | 行数 | 能力 |
|
||||
@ -270,7 +270,7 @@ C 化的正确性**不能靠「跑起来没崩」**,必须有可复现的对
|
||||
| 打包脚本 | ✅ 不再需带 `.a`(编源码,无外部产物依赖)| 扩张到多文件 C 实现时重评 |
|
||||
|
||||
**仍未决(需 jianf 拍板)**:
|
||||
1. C 实现放**主仓 `csrc/`** 还是 **SDK `third_party/homeagent-sdk/`**?
|
||||
1. C 实现放**主仓 `csrc/`** 还是 **SDK `third_party/hologramagentsdk/`**?
|
||||
- 当前已在主仓 `csrc/`;若 SDK 侧也要复用,需定同步机制
|
||||
- 放 SDK:天然跨端复用,但要走 SDK 冻结与大版本流程
|
||||
2. `ha_json.c` 是**复用**(从 remotedevice 复制/提为公共)还是**新写**?
|
||||
|
||||
@ -251,7 +251,7 @@ ASSET_DIR=<产物目录> GITCODE_REPO=JianFeeeee/HologramAgent \
|
||||
# release 条目必须先存在(脚本向 releases/<tag>/upload_url 取 OBS 签名 URL)
|
||||
```
|
||||
|
||||
## 4. SDK 仓(third_party/homeagent-sdk)
|
||||
## 4. SDK 仓(third_party/hologramagentsdk)
|
||||
|
||||
与主仓同构,差异:
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
> - **[风险]** = 已知会让整套机制失效的点
|
||||
>
|
||||
> 撰写时间:2026-10-13。事实基线:TrueAgent `/home/program/TrueAgent`,
|
||||
> 生产实例 `/home/newqqagent`,SDK 仓 `third_party/homeagent-sdk`。
|
||||
> 生产实例 `/home/newqqagent`,SDK 仓 `third_party/hologramagentsdk`。
|
||||
|
||||
---
|
||||
|
||||
@ -873,7 +873,7 @@ pi -p --session-dir /tmp/sd-store --session-id sd-01 "…"
|
||||
ls /root/.pi/agent/sessions/ | grep -i sd-test # 期望无结果
|
||||
|
||||
# §1.3 可接入面
|
||||
grep -n "func (s \*PluginSDK) RegisterInputChannel" third_party/homeagent-sdk/sdk/plugin.go
|
||||
grep -n "func (s \*PluginSDK) RegisterInputChannel" third_party/hologramagentsdk/sdk/plugin.go
|
||||
grep -rn "resident_agents" internal/plugin/proc/ # 期望无结果 ⇒ 插件调不到
|
||||
|
||||
# §2.4 L4 归属
|
||||
|
||||
@ -124,7 +124,7 @@
|
||||
|
||||
| 事实 | 证据/位置 |
|
||||
|---|---|
|
||||
| 已有 `plugindev` 示例插件,含 `plugindev_status/init/build/sdk/projects` | `third_party/homeagent-sdk/example/plugindev/` |
|
||||
| 已有 `plugindev` 示例插件,含 `plugindev_status/init/build/sdk/projects` | `third_party/hologramagentsdk/example/plugindev/` |
|
||||
| 插件数据目录 API | `sdk.Settings().DataDir()`(`internal/sdk/settings_impl.go:24`) |
|
||||
| `hmapdev` 工具链已装 | `/usr/local/bin/hmapdev` |
|
||||
| SDK 无 HTTP/exec 能力面,但插件是编译型 Go,可自行 `os/exec` | `internal/sdk/plugin.go` 方法清单 |
|
||||
@ -895,7 +895,7 @@ cd /tmp/probe-a && pi -p --provider <可用provider> --model <可用model> \
|
||||
|
||||
# §3.4 a2a/acp 无 cwd
|
||||
grep -n "agent_url\|query\|session_id" \
|
||||
/home/program/TrueAgent/third_party/homeagent-sdk/example/a2a/plugin.go
|
||||
/home/program/TrueAgent/third_party/hologramagentsdk/example/a2a/plugin.go
|
||||
grep -n "cwd" /root/.pi/agent/extensions/pi-acp/index.ts # 期望无结果
|
||||
|
||||
# §3.5 端口归属
|
||||
@ -1039,7 +1039,7 @@ grep -n "phase,omitempty" cmd/waiter/state.go # 判据匹配的是
|
||||
复现命令:
|
||||
|
||||
```bash
|
||||
cd third_party/homeagent-sdk/example/commondev
|
||||
cd third_party/hologramagentsdk/example/commondev
|
||||
K=$(sqlite3 /home/newqqagent/config.db "select value from config where key='core.llm.api_key';")
|
||||
HA_E2E_LLM=1 HA_E2E_API_KEY="$K" HA_E2E_REAL_DB=/home/newqqagent/config.db \
|
||||
go test -count=1 ./...
|
||||
|
||||
@ -404,7 +404,7 @@ stage handler 入口自动加锁 + 锁不可重入所致,**插件侧问题**
|
||||
|
||||
| 站 | 本地源 | 线上位置 | 构建 |
|
||||
| --- | --- | --- | --- |
|
||||
| SDK 文档站 | `third_party/homeagent-sdk/site_build/` | `/vol1/docker/navi-data/sites/sdk` | 需 `tools/apidoc/build.sh`(§5.3 坑①) |
|
||||
| SDK 文档站 | `third_party/hologramagentsdk/site_build/` | `/vol1/docker/navi-data/sites/sdk` | 需 `tools/apidoc/build.sh`(§5.3 坑①) |
|
||||
| introduce | `site/`(排除 `README.md`) | `/vol1/docker/navi-data/sites/introduce` | 零构建,源即产物 |
|
||||
|
||||
两站部署在**同一台** 106 的同一 `sites/` 目录下。
|
||||
@ -465,7 +465,7 @@ find grep sed sort tr wc head tail stat file
|
||||
改完 SDK 文档的完整流程:
|
||||
|
||||
```bash
|
||||
cd third_party/homeagent-sdk
|
||||
cd third_party/hologramagentsdk
|
||||
# 1) 在 docs/guide/ 写文档
|
||||
# 2) 在 mkdocs.yml 的 nav 里登记 ← 漏了这步站点里找不到
|
||||
# 3) 重新生成(含 docs/api/* 与 llms.txt 同步)
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
> 分支:`feature/input-semantics`
|
||||
> 状态:**设计稿 v1**(待确认项见 §12,未确认处按 §12 的「默认取值」推进)
|
||||
> 影响面:`internal/agent/core`、`internal/agent/io`、`internal/sdk`(**仅内部**)
|
||||
> 公开 SDK:**v1 不改**(`third_party/homeagent-sdk/sdk/` diff 必须保持为 0,理由见 §13)
|
||||
> 公开 SDK:**v1 不改**(`third_party/hologramagentsdk/sdk/` diff 必须保持为 0,理由见 §13)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -661,7 +661,7 @@ loadOne(name):
|
||||
#### 2.6.7.5 SDK 兼容性:一个必须记住的**例外**
|
||||
|
||||
本轮给公开 SDK 的 `PluginMgrAPI` 新增 3 个方法。按 SDK 的版本纪律
|
||||
(`third_party/homeagent-sdk/docs/versions.md`),"插件调用、内核实现"的
|
||||
(`third_party/hologramagentsdk/docs/versions.md`),"插件调用、内核实现"的
|
||||
新增属**纯追加** ⇒ 存量插件不需要改、也不需要重编。
|
||||
|
||||
**但这次有一个例外,必须记住**:
|
||||
|
||||
@ -142,7 +142,7 @@ PluginContext(独立身份,共享管道)。
|
||||
|
||||
**证据**:
|
||||
- `internal/plugin/proc/plugin.go:134`(`Spawn`,逐插件起进程)
|
||||
- manifest 无 `worker_group` 键(`third_party/homeagent-sdk/example/a2a/plugin.json`
|
||||
- manifest 无 `worker_group` 键(`third_party/hologramagentsdk/example/a2a/plugin.json`
|
||||
的键集合为 `author/description/entry/name/name_en/name_zh/platforms/tags/version`)
|
||||
|
||||
**子任务**:
|
||||
@ -196,7 +196,7 @@ PluginContext(独立身份,共享管道)。
|
||||
**证据**:
|
||||
- `internal/plugin/proc/capability.go:149-150`(subscribe/unsubscribe 已授权)
|
||||
- `internal/plugin/proc/corehandler.go:46-58`(`EvtRingSubscriber` 接口)
|
||||
- `third_party/homeagent-sdk/example/` 下 21 个 example 中无事件订阅样例
|
||||
- `third_party/hologramagentsdk/example/` 下 21 个 example 中无事件订阅样例
|
||||
|
||||
**子任务**:
|
||||
1. 写一个订阅 `stage` / `tool_call` 事件的 example 插件,跑真实负载
|
||||
@ -503,7 +503,7 @@ SDK 的 `remotedevice/src/ha_json.c`(368 行)经实测有**三个对协议
|
||||
1. **C 实现放哪里 → 留在主仓 `csrc/`。** 用户澄清:C 实现本来就是**替换**内核的
|
||||
Go 实现(`csrc/` 是唯一权威源,Go 侧符号链接 + cgo 绑定,`codec_pure.go`
|
||||
已降级为黄金对照的规格基准)。SDK 从头到尾**未被触碰**
|
||||
(`git diff main -- third_party/homeagent-sdk/sdk/` = 0 行)。
|
||||
(`git diff main -- third_party/hologramagentsdk/sdk/` = 0 行)。
|
||||
所谓「进 SDK」只对**跨端复用**(鸿蒙/嵌入式/C SDK 也想调同一份实现)才有意义,
|
||||
而它们并不调用内核编解码层 ⇒ 该问题**关闭**,不作为待办。
|
||||
2. **`ha_json.c` 复用还是新写 → 新写。** 见上(三个致命缺陷 + 架构正交)。
|
||||
@ -515,7 +515,7 @@ SDK 的 `remotedevice/src/ha_json.c`(368 行)经实测有**三个对协议
|
||||
`docs/zh/c-core/llm-orchestration-c.md`)。基础设施门禁已建成(见上)。
|
||||
下阶段扩大前,**三处需 jianf 拍板**(建议已附,见上):
|
||||
|
||||
1. **C 实现放主仓 `csrc/` 还是 SDK `third_party/homeagent-sdk/`?**
|
||||
1. **C 实现放主仓 `csrc/` 还是 SDK `third_party/hologramagentsdk/`?**
|
||||
- 当前已在主仓 `csrc/`(`ha_codec.{c,h}` 是权威源,Go 侧符号链接过去)
|
||||
- 若 SDK / 鸿蒙 / C SDK 侧也要复用,需定同步机制;搬进 SDK 则要走 SDK 冻结流程
|
||||
2. **`ha_json.c` 复用还是新写?**(复用会动 SDK 目录结构)
|
||||
|
||||
@ -772,7 +772,7 @@ if ret, err := parent.ExecuteTool(name, args); err == nil {
|
||||
且注释明写"main 上此值始终是**下一个未发布中版本**";
|
||||
- 仓内**无 `release/v1.4.x` 分支**,最新 tag 是 `v1.3.12`
|
||||
⇒ 1.4.0 这一中版本**尚未发布**,正是承接本次改动的那个版本;
|
||||
- SDK `meta.Version` 同为 `1.4.0`(`third_party/homeagent-sdk/meta/meta.go`),
|
||||
- SDK `meta.Version` 同为 `1.4.0`(`third_party/hologramagentsdk/meta/meta.go`),
|
||||
两仓中版本已对齐 ⇒ **本次无需再次对齐动作**。
|
||||
|
||||
⇒ 动作只是把 `SDKCompatibleVersion`(`internal/meta/meta.go:54`)从 `1.3.0`
|
||||
|
||||
Reference in New Issue
Block a user