feat: ConfigRegistry + SettingsAPI for plugin config access

Core exposes a unified settings interface through Plugin SDK:
- internal/config/registry.go: thread-safe namespaced KV store
  - Register/Get/Set/List/Delete with JSON persistence
  - Flush() for explicit save to disk
- SettingsAPI in SDK: plugins call plugin.Settings().Get/Set/List
  - Full access: read/write any key (core.*, plugin.<name>.*)
- plugin.Registry.SetConfigRegistry() wires it into SDK plugins
- main.go registers core.* keys at startup, flushes on shutdown
- 7 tests for ConfigRegistry
This commit is contained in:
root
2026-07-03 08:32:41 +08:00
parent ee811fb308
commit 9c33b3b149
5 changed files with 304 additions and 1 deletions

View File

@ -72,6 +72,12 @@ type ToolDef struct {
Parameters map[string]interface{} `json:"parameters"`
}
type SettingsAPI interface {
Get(key string) (interface{}, error)
Set(key string, value interface{}) error
List(prefix string) ([]string, error)
}
type MemoryAPI interface {
Recall(query string, topK int) ([]MemItem, error)
Commit(triples []map[string]string) error
@ -98,6 +104,7 @@ type PluginAPI struct {
eventBus EventBus
memAPI MemoryAPI
knowAPI KnowledgeAPI
settAPI SettingsAPI
}
func NewPluginAPI(name, version string, bus EventBus, mem MemoryAPI, know KnowledgeAPI) *PluginAPI {
@ -153,8 +160,10 @@ func (p *PluginAPI) StageHandlers(stage Stage) []StageHandler {
return p.stages[stage]
}
func (p *PluginAPI) Memory() MemoryAPI { return p.memAPI }
func (p *PluginAPI) Memory() MemoryAPI { return p.memAPI }
func (p *PluginAPI) Knowledge() KnowledgeAPI { return p.knowAPI }
func (p *PluginAPI) Settings() SettingsAPI { return p.settAPI }
func (p *PluginAPI) SetSettings(s SettingsAPI) { p.settAPI = s }
func AllStages() map[Stage]bool {
return map[Stage]bool{