feat(sdk): 受限事件总线的内核实现 + clawhubadapter 改用它

- internal/sdk/events.go:实现 pubsdk.EventsAPI
  · publishAllowed:白名单精确匹配 或 本插件命名空间 plugin.<name>.<后缀>
  · subscribeAllowed:只开只读事件(tools_ready/security_ready/device_ready)
  · 载荷出向经 security.PrepareOutbound(明文→@{别名}),入向经 ScrubInbound
  · 键数上限 64;越界**报错**不静默
  · Source 由 SDK 固定成插件名(插件不能冒名)
- PluginSDK.Events() 访问器
- clawhubadapter 的 skill_detected 改走 s.Events().Publish,不再 import internal/events
  ⇒ 它为外部化的唯一阻塞项(事件发布)已消除

判据(internal/sdk/events_test.go,6 条):
白名单放行 / 越界拒绝(raw_input、agent_output、update_request、stage、system、
别的插件命名空间、空类型)/ 自己命名空间放行 / 订阅越界拒绝 / 载荷凭据被替换成别名 / 键数上限
This commit is contained in:
JianFeeeee
2026-10-27 11:16:40 +08:00
parent ffffb94005
commit 981b969f58
4 changed files with 313 additions and 9 deletions

View File

@ -18,7 +18,6 @@ import (
"sync"
"time"
"github.com/JianFeeeee/HologramAgent/internal/events"
"github.com/JianFeeeee/HologramAgent/internal/plugin"
safeclose "github.com/JianFeeeee/HologramAgent/internal/safeclose"
sdk "github.com/JianFeeeee/HologramAgent/internal/sdk"
@ -1305,12 +1304,15 @@ func (p *Plugin) Stop() error {
// publishSkillDetected 发布 skill_detected 事件,将纯 SKILL 条目移交原生
// skillmgr 插件注册。OpenClaw 兼容层不持有 native skill 状态。
func (p *Plugin) publishSkillDetected(s *sdk.PluginSDK, path string) {
s.Publish(&events.Event{
Type: events.EventSkillDetected,
Source: p.name,
Payload: map[string]interface{}{"path": path},
Timestamp: time.Now().Unix(),
})
// ★ 走**受限** SDK 事件面,而不是内核私有总线(2026-10-27)。
//
// 这样 clawhubadapter 对外部化不再有阻塞项:它只需要 SDK 的
// Events().Publish,而不需要 internal/events。事件类型仍是 skill_detected
// (白名单内),载荷出向会经 security 过闸,Source 由 SDK 固定成本插件名。
if err := s.Events().Publish("skill_detected", map[string]interface{}{"path": path}); err != nil {
log.Printf("[clawhubadapter] publish skill_detected failed: %v", err)
return
}
log.Printf("[clawhubadapter] skill %s detected, handed off to skillmgr", filepath.Base(path))
}