mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-23 02:18:06 +00:00
refactor(plugin)!: 重编提示与模板路径改用 hmapdev;文档全面对齐 1.2.0
工具链在 SDK 1.2.0 更名为 hmapdev(原 plugindev)。核心侧三处功能耦合同步:
1. 用户可见报错:旧 C ABI 产物 / 协议版本不匹配 / 共享段版本不匹配
三处「请用配套 plugindev 重编」→ hmapdev(对应两条测试断言同步)
2. e2e_template_test 的模板路径改为 tools/hmapdev/templates,
并保留旧路径回退(旧 SDK 检出仍能跑测试)
3. 注释与文档同步
文档更新(用户可见面):
- assets/docs/{zh,en}/PLUGIN_DEV.md:工具链章节整体改为 hmapdev,
补改名说明与 SDK 存储目录迁移;命令示例全部更新
- assets/docs/{zh,en}/ARCHITECTURE.md:**流程图与章节对齐 v1.2.0** ——
· 向量化章节改为三层降级:统一多模态空间(主)→ 词嵌入 → TF-IDF(回退),
写明「同指纹且同维度才参与融合」
· 媒体记忆章节重写:媒体是一等记忆块(无独立 GC / 无引用计数 / 无描述式索引 /
正文不再写 media marker),并写明 reembedStaleMedia 的跨空间迁移与写回
- README{,_EN}.md、docs/zh/plugin-interface-matrix.md:工具名与模板路径同步
(历史条目标注「当时名为 plugindev」)
验证:go test ./internal/plugin/ ./internal/plugin/proc/ ok,
含 4 条真实模板 E2E(模板路径切换后仍通过)。
This commit is contained in:
@ -17,7 +17,7 @@ const (
|
||||
//
|
||||
// 保留这张表只为**给出明确错误**:插件目录里躺着 plugin.so 而内核不再认它时,
|
||||
// 静默跳过会让「目录在但插件没加载」看起来像配置问题,而实际原因是需要用
|
||||
// 新版 plugindev 重编。
|
||||
// 新版 hmapdev 重编。
|
||||
var legacyCABIEntries = []string{"plugin.so", "plugin.dll", "plugin.dylib"}
|
||||
|
||||
// entryKind 描述插件入口归属的加载通道。
|
||||
|
||||
@ -115,7 +115,7 @@ func TestHasLegacyCABIEntry(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// 旧 .so 插件必须报「用新 plugindev 重编」而非静默跳过。
|
||||
// 旧 .so 插件必须报「用新 hmapdev 重编」而非静默跳过。
|
||||
func TestTryDynamic_LegacyCABIGivesActionableError(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
defer r.closeProcHost()
|
||||
@ -129,7 +129,7 @@ func TestTryDynamic_LegacyCABIGivesActionableError(t *testing.T) {
|
||||
}
|
||||
// 错误消息须指向解决办法,且明确业务代码无需改
|
||||
msg := err.Error()
|
||||
for _, want := range []string{"plugindev", "plugin.bin", "业务代码"} {
|
||||
for _, want := range []string{"hmapdev", "plugin.bin", "业务代码"} {
|
||||
if !strings.Contains(msg, want) {
|
||||
t.Errorf("错误消息应含 %q,实际: %v", want, err)
|
||||
}
|
||||
|
||||
@ -10,11 +10,11 @@ import (
|
||||
pubsdk "gitcode.com/JianFeeeee/homeagent-sdk/sdk"
|
||||
)
|
||||
|
||||
// 端到端:用**真实 plugindev 模板**编译的插件,经内核 proc 通道加载运行。
|
||||
// 端到端:用**真实 hmapdev 模板**编译的插件,经内核 proc 通道加载运行。
|
||||
//
|
||||
// 与 plugin_test.go 中 testdata/*.go 假插件的区别:
|
||||
// 那些是手写的最简 RPC 实现,只验证内核侧逻辑;
|
||||
// 这里用的是 tools/plugindev/templates/proc_main.go.tmpl —— 外部插件作者
|
||||
// 这里用的是 tools/hmapdev/templates/proc_main.go.tmpl —— 外部插件作者
|
||||
// 真正会拿到的那份运行时。它验证的是「模板 ↔ 内核」两侧协议/布局真的对齐,
|
||||
// 而不只是内核自己跟自己对齐。
|
||||
//
|
||||
@ -101,9 +101,9 @@ func (p *e2ePlugin) Start(s *sdk.PluginSDK) error {
|
||||
func (p *e2ePlugin) Stop() error { return nil }
|
||||
`
|
||||
|
||||
// procRuntimeTemplates 列出 plugindev 会生成到插件目录的运行时文件。
|
||||
// procRuntimeTemplates 列出 hmapdev 会生成到插件目录的运行时文件。
|
||||
//
|
||||
// 必须与 SDK 仓 tools/plugindev/proc_runtime.go 的 procRuntimeFiles 一致:
|
||||
// 必须与 SDK 仓 tools/hmapdev/proc_runtime.go 的 procRuntimeFiles 一致:
|
||||
// 共享段与事件通知的传递机制按平台不同(Unix 继承 fd,Windows 命名
|
||||
// 内核对象),故拆成带 build tag 的文件;只写主模板会编译失败。
|
||||
var procRuntimeTemplates = []struct {
|
||||
@ -115,15 +115,21 @@ var procRuntimeTemplates = []struct {
|
||||
{"proc_shm_windows.go.tmpl", "z_proc_shm_windows.go"},
|
||||
}
|
||||
|
||||
// buildPluginWithRealTemplate 用 plugindev 的真实模板编译一个插件二进制。
|
||||
// buildPluginWithRealTemplate 用 hmapdev 的真实模板编译一个插件二进制。
|
||||
func buildPluginWithRealTemplate(t *testing.T, businessCode string) string {
|
||||
t.Helper()
|
||||
if _, err := exec.LookPath("go"); err != nil {
|
||||
t.Skip("环境无 go 工具链,跳过端到端测试")
|
||||
}
|
||||
|
||||
// 工具链在 SDK 1.2.0 起改名 hmapdev(原 plugindev)。两个目录都接受:
|
||||
// 旧检出(软链或旧版 SDK 仓)仍能跑本测试,新检出走新路径。
|
||||
tmplDir := filepath.Join("..", "..", "..",
|
||||
"third_party", "homeagent-sdk", "tools", "plugindev", "templates")
|
||||
"third_party", "homeagent-sdk", "tools", "hmapdev", "templates")
|
||||
if _, err := os.Stat(tmplDir); err != nil {
|
||||
tmplDir = filepath.Join("..", "..", "..",
|
||||
"third_party", "homeagent-sdk", "tools", "plugindev", "templates")
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
mustWriteFile(t, filepath.Join(dir, "plugin.go"), businessCode)
|
||||
@ -131,7 +137,7 @@ func buildPluginWithRealTemplate(t *testing.T, businessCode string) string {
|
||||
for _, rt := range procRuntimeTemplates {
|
||||
data, err := os.ReadFile(filepath.Join(tmplDir, rt.tmpl))
|
||||
if err != nil {
|
||||
t.Skipf("plugindev 模板 %s 不可读(SDK 仓可能未就位): %v", rt.tmpl, err)
|
||||
t.Skipf("hmapdev 模板 %s 不可读(SDK 仓可能未就位): %v", rt.tmpl, err)
|
||||
}
|
||||
mustWriteFile(t, filepath.Join(dir, rt.out), string(data))
|
||||
}
|
||||
|
||||
@ -260,7 +260,7 @@ func (p *Process) handshake(timeout time.Duration) error {
|
||||
return fmt.Errorf("proc: %s 握手应答解析失败: %w", p.name, err)
|
||||
}
|
||||
if res.Protocol != ProtocolVersion {
|
||||
return fmt.Errorf("proc: %s 协议版本不匹配(插件 %d,内核 %d)——请用配套 plugindev 重编",
|
||||
return fmt.Errorf("proc: %s 协议版本不匹配(插件 %d,内核 %d)——请用配套 hmapdev 重编",
|
||||
p.name, res.Protocol, ProtocolVersion)
|
||||
}
|
||||
log.Printf("[proc] %s 已建链(pid=%d protocol=%d sdk=%s)",
|
||||
|
||||
@ -331,7 +331,7 @@ func TestProcess_ProtocolMismatchRejected(t *testing.T) {
|
||||
}
|
||||
// 运维可读性:光报“不匹配”不能定位到行动。生产上碰到它的现场是
|
||||
// “只更新了内核没重编插件”,所以错误里必须带出这条修复指令。
|
||||
if !strings.Contains(err.Error(), "plugindev") || !strings.Contains(err.Error(), "重编") {
|
||||
if !strings.Contains(err.Error(), "hmapdev") || !strings.Contains(err.Error(), "重编") {
|
||||
t.Errorf("错误应给出重编插件的修复指令,实际: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ func AttachSegment(data []byte) (*Segment, error) {
|
||||
return nil, fmt.Errorf("proc: 共享段魔数不匹配(0x%x,期望 0x%x)", got, shmMagic)
|
||||
}
|
||||
if got := binary.LittleEndian.Uint32(data[offVersion:]); got != shmVersion {
|
||||
return nil, fmt.Errorf("proc: 共享段版本不匹配(%d,本内核 %d)——插件需用配套 plugindev 重编",
|
||||
return nil, fmt.Errorf("proc: 共享段版本不匹配(%d,本内核 %d)——插件需用配套 hmapdev 重编",
|
||||
got, shmVersion)
|
||||
}
|
||||
return &Segment{data: data}, nil
|
||||
|
||||
2
internal/plugin/proc/testdata/stageplugin.go
vendored
2
internal/plugin/proc/testdata/stageplugin.go
vendored
@ -4,7 +4,7 @@
|
||||
// stage 处理经共享内存读改写(模拟 sanitizer 的清洗行为)。
|
||||
//
|
||||
// 它手写 RPC 与共享段访问,不依赖公开 SDK——因为 SDK 侧的 proc 支持
|
||||
// 属于 Part 3(plugindev 工具链)的内容。这里只验证内核侧机制。
|
||||
// 属于 Part 3(hmapdev 工具链)的内容。这里只验证内核侧机制。
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@ -1175,11 +1175,11 @@ func (r *Registry) tryDynamic(plgDir, name string, config map[string]interface{}
|
||||
|
||||
// 旧 .so/.dll 插件给明确错误,不静默跳过。
|
||||
// 静默跳过会让「插件目录在但没加载」看起来像配置问题,
|
||||
// 而实际原因是需要用新 plugindev 重编。
|
||||
// 而实际原因是需要用新 hmapdev 重编。
|
||||
if hasLegacyCABIEntry(plgDir) {
|
||||
return nil, fmt.Errorf(
|
||||
"plugin %s: 检测到旧 C ABI 产物(plugin.so/.dll/.dylib)。"+
|
||||
"外部插件已改为子进程模式,请用新版 plugindev 重编产出 %s"+
|
||||
"外部插件已改为子进程模式,请用新版 hmapdev 重编产出 %s"+
|
||||
"(业务代码无需修改)", name, binEntry)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user