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:
JianFeeeee
2026-10-26 20:55:25 +08:00
parent ca956f69bf
commit 55fa2685ae
92 changed files with 3932 additions and 596 deletions

View File

@ -291,40 +291,42 @@ func (idx *Indexer) vectorSearchEntities(query string) []Entity {
}
func (idx *Indexer) BuildToolPrompt() string {
return `## 图记忆工具
return `## Stable memory tools
你有以下工具可以操作长期图记忆系统:
You have these tools for the long-term stable memory:
### memory_recall
检索与关键词相关的实体和关系。
参数:
- query_intent: 查询关键词,逗号分隔
- depth: 遍历深度(默认2)
- sort: 排序方式。relevance=相关性(默认);recent=时间倒序最新在前
(问"最近/最新/现在是什么"时必须用 —— 答案常是新值覆盖旧值)
Retrieve entities and relations related to keywords.
Parameters:
- query_intent: keywords, comma separated
- depth: traversal depth (default 2)
- sort: relevance (default) or recent (newest first).
Use recent when asked "latest / current value" - the answer is usually the newest value
superseding an older one.
### memory_commit
将三元组写入图记忆。
参数:
- triples: [{"subject": "实体名", "relation": "关系类型", "object": "目标实体",
"sentence_text": "原始句子(可选)", "media_digests": ["图片digest(可选)"],
"scene": "场景键(可选)"}]
填了 media_digests,日后从这条记忆就能取回当时那张图/那段音频。
填了 scene,这条记忆就挂在那个**场面**上:场面重现时(如又来一条 QQ 消息)
不靠字面命中也会被召回。「在什么场合该怎么做」这类约定/规则都该填,
例如回 QQ 消息的格式约定 → scene="chan:qq"。
- scene: 本批次默认场景键(可选,逐条 triples 里的 scene 优先)。
Write triples into stable memory.
Parameters:
- triples: [{"subject": "entity", "relation": "type", "object": "target entity",
"sentence_text": "original sentence (optional)",
"media_digests": ["media digest (optional)"],
"scene": "scene key (optional)"}]
With media_digests, the image/audio can be retrieved from this memory later.
With scene, the memory hangs on that **scene**: when the scene recurs (e.g. another QQ
message arrives) it is recalled without a literal match. Put conventions and rules here,
e.g. the QQ reply format -> scene="chan:qq".
- scene: default scene key for this batch (optional; per-triple scene wins).
### memory_introspect
查看记忆统计信息。
Show memory statistics.
### memory_purge
删除或修正记忆。
参数:
Delete or fix memories.
Parameters:
- criteria: {"subject_contains": "...", "relation_type": "..."}
- mode: "soft" | "supersede"
使用方法:在推理过程中调用对应的 tool,系统会自动执行并返回结果。`
Usage: call the tool during reasoning; the kernel executes it and returns the result.`
}
func (idx *Indexer) FormatContext(ctx *InjectedContext) string {