重构: 插件自注册 + .so 动态加载 + 中断打断机制

- 所有内置插件 init() 自注册 (plugin.RegisterFactory), 移除 main.go 硬编码
- 新增 .so 动态加载器 (internal/plugin/dynamic.go), 插件可编译为 plugin.so
- 新增 plugin.json 元数据 (internal/plugin/manifest.go)
- 新增 interceptLoop 独立 goroutine:
  (a) cancelLLM() 取消进行中的 HTTP 请求
  (b) interceptCh → drainInterrupt() 注入 [打断消息] 到 LLM 上下文
  (c) InjectInput 空闲时触发新处理循环
- 新增 internal/plugins/all.go 空白导入触发所有内置插件 init()
- internal/sdk/ 作为 PluginSDK 正式 Go API
- internal/api/ → internal/plugins/webui/ 迁移
- 删除旧 cmd/cli/, 使用 cmd/waiter/ 替代
- 更新 PLAN.md / ARCHITECTURE.md / README.md 文档
This commit is contained in:
root
2026-07-03 16:53:34 +08:00
parent 4442c9cea4
commit 2d314b3e9c
37 changed files with 3376 additions and 1576 deletions

View File

@ -14,14 +14,25 @@ type Indexer struct {
vec *vector.Store
veczer *vector.TFIDFVectorizer
mu sync.RWMutex
trained bool
trained bool
recalled map[string]bool // 已通过工具调用显式召回的实体名,自动注入时跳过
}
func NewIndexer(db *GraphDB) *Indexer {
return &Indexer{
db: db,
vec: vector.NewStore(),
veczer: vector.NewTFIDFVectorizer(2),
db: db,
vec: vector.NewStore(),
veczer: vector.NewTFIDFVectorizer(2),
recalled: make(map[string]bool),
}
}
// MarkRecalled 标记实体名已被工具调用显式召回,后续自动注入时跳过
func (idx *Indexer) MarkRecalled(names ...string) {
idx.mu.Lock()
defer idx.mu.Unlock()
for _, name := range names {
idx.recalled[name] = true
}
}
@ -100,15 +111,25 @@ func (idx *Indexer) BuildContext(userInput string) *InjectedContext {
return &InjectedContext{Summary: ""}
}
// 过滤已被工具调用显式召回的实体,避免重复注入
idx.mu.RLock()
filtered := result.Entities[:0]
for _, e := range result.Entities {
if !idx.recalled[e.Name] {
filtered = append(filtered, e)
}
}
idx.mu.RUnlock()
ctx := &InjectedContext{
Entities: result.Entities,
Entities: filtered,
Relations: nil,
}
if len(result.Entities) > 0 {
summary := buildIndexSummary(result.Entities)
if len(filtered) > 0 {
summary := buildIndexSummary(filtered)
ctx.Summary = summary
ctx.TokenEstimate = estimateTokens(summary) + len(result.Entities)*8
ctx.TokenEstimate = estimateTokens(summary) + len(filtered)*8
} else {
ctx.Summary = ""
}