mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-01 06:47:29 +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:
@ -151,12 +151,25 @@ func kernelDataDir(p *Plugin) string {
|
||||
// 算成 /home —— pending 标记落到 /home/kernel-upgrade-pending.json,
|
||||
// 而第 0 层 update 模块从 ks.DataDir 读 ⇒ **永远读不到标记** ⇒
|
||||
// agent 发起的升级一旦启动失败就**不会回滚**(静默失效)。
|
||||
// ★ 不再写死生产路径(2026-10-26 迁移教训):
|
||||
// 硬编码 /home/newqqagent 在目录/用户迁移后会让 pending 标记落到一个
|
||||
// **已经不存在的目录**,而第 0 层 update 从 ks.DataDir 读 ⇒ 永远读不到
|
||||
// ⇒ agent 发起的升级失败时静默不回滚。
|
||||
//
|
||||
// 优先级:显式环境变量(部署方声明自己在哪)→ 从 pluginDir 反推 → 空。
|
||||
// 空表示"不知道",由调用方拒绝执行并报错,而不是猜一个路径。
|
||||
if d := os.Getenv(dataDirEnv); d != "" {
|
||||
return d
|
||||
}
|
||||
if p.pluginDir != "" {
|
||||
return filepath.Dir(p.pluginDir)
|
||||
}
|
||||
return "/home/newqqagent"
|
||||
return ""
|
||||
}
|
||||
|
||||
// dataDirEnv 是部署方声明数据目录的环境变量(与 webui 侧同名)。
|
||||
const dataDirEnv = "HOMEAGENT_DATA_DIR"
|
||||
|
||||
// currentKernelVersion 读本机 homed 自报版本(尽力而为)。
|
||||
func currentKernelVersion(p *Plugin) *update.BinVersion {
|
||||
v, err := update.ReadBinVersion(kernelBinPath(p))
|
||||
|
||||
@ -243,8 +243,20 @@ func (p *Plugin) registerTools(s *sdk.PluginSDK) {
|
||||
})
|
||||
|
||||
s.RegisterTool("plugin_list", sdk.ToolDef{
|
||||
Name: "plugin_list",
|
||||
Description: "列出已安装的所有外部插件及其版本。同时返回运行状态(loaded/alive/pid/崩溃次数),子进程插件死了在此体现为 alive=false。",
|
||||
Name: "plugin_list",
|
||||
Description: "List every installed plugin with its version and runtime state.\n\n" +
|
||||
"**Read the lifecycle flags correctly — they are not the same thing:**\n" +
|
||||
"- `auto_start`: whether the plugin boots with the kernel. **false = on-demand**, " +
|
||||
"i.e. installed and available but deliberately NOT running until someone needs it.\n" +
|
||||
"- `loaded` / `alive`: whether it is running **right now**. " +
|
||||
"`alive=false` on an `auto_start=false` plugin is the **normal idle state**, not an error.\n" +
|
||||
"- `disabled`: persisted switch turned off. Only this one means \"not allowed\".\n" +
|
||||
"- `crash_count` / `runtime_stopped`: it was running and died.\n\n" +
|
||||
"**So: never conclude \"this capability does not exist\" from alive=false.** " +
|
||||
"An on-demand plugin's tools appear only after it starts — call `plugin_start` " +
|
||||
"(start now, keeps auto_start setting) or `plugin_enable` (start now AND enable at boot) " +
|
||||
"and its tools become callable. Use `get_plugin_tools(\"<name>\")` first to see what it offers.\n\n" +
|
||||
"`plugin_stop` stops without changing the boot setting; `plugin_disable` is the persistent off switch.",
|
||||
Parameters: map[string]interface{}{
|
||||
"type": "object",
|
||||
"properties": map[string]interface{}{},
|
||||
|
||||
@ -85,8 +85,8 @@ func (f *fakePluginMgr) StartPlugin(name string) error {
|
||||
f.starts = append(f.starts, name)
|
||||
return nil
|
||||
}
|
||||
func (f *fakePluginMgr) IsPluginRuntimeStopped(string) bool { return false }
|
||||
func (f *fakePluginMgr) RemovePlugin(string) error { return nil }
|
||||
func (f *fakePluginMgr) IsPluginRuntimeStopped(string) bool { return false }
|
||||
func (f *fakePluginMgr) RemovePlugin(string) error { return nil }
|
||||
func (f *fakePluginMgr) StopAndUnload(name string) error {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user