Files
HomeAgent/internal/plugins/skillmgr/builtin_desc_test.go
JianFeeeee 55fa2685ae 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 包全绿
2026-10-26 20:55:25 +08:00

61 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package skillmgr
// 内核自带 skill 的**描述必须能整条进索引**。
//
// ## 为什么这是判据而不是"注意一下"
//
// `SkillIndex()` 每行截断到 80 runes(见 truncateDesc)。内置 skill 的
// 描述一旦超过 80,尾巴会被切掉 —— 而尾巴恰好是"什么时候该读它",
// 于是模型只看到半句机制名,不知道何时适用,也就不会去 skill_info。
//
// 实测(2026-10-26):四条内置描述分别是 94/96/106/108 字符,
// **全部**被截断。这正是用户说的"要巧妙切分 skill 文本"——
// 索引行要自带"机制 + 最关键那条规则 + 何时展开"。
import (
"os"
"path/filepath"
"strings"
"testing"
)
// maxIndexRunes 与 truncateDesc 的上限保持一致(改了这里也必须改那里)。
const maxIndexRunes = 80
func TestBuiltinSkillDescriptionsFitSkillIndex(t *testing.T) {
dirs, err := os.ReadDir(builtinSkillDir)
if err != nil {
t.Fatalf("读不到内置 skill 目录 %s: %v", builtinSkillDir, err)
}
checked := 0
for _, d := range dirs {
if !d.IsDir() {
continue
}
path := filepath.Join(builtinSkillDir, d.Name(), skillFileName)
b, err := os.ReadFile(path)
if err != nil {
t.Fatalf("读不到 %s: %v", path, err)
}
var desc string
for _, ln := range strings.Split(string(b), "\n") {
if strings.HasPrefix(ln, "description:") {
desc = strings.TrimSpace(strings.TrimPrefix(ln, "description:"))
break
}
}
if desc == "" {
t.Fatalf("%s 没有 description(索引行会是空的,模型看不到它能干什么)", path)
}
if n := len([]rune(desc)); n > maxIndexRunes {
t.Errorf("★ %s 的 description 有 %d 字符(上限 %d)—— "+
"进索引会被截断,尾巴(何时该读)会丢:\n %q",
d.Name(), n, maxIndexRunes, desc)
}
checked++
}
if checked == 0 {
t.Fatal("没有检查到任何内置 skill —— 目录结构变了?")
}
}