package app import ( "encoding/json" "log" "os" "path/filepath" "agent-system-backend/internal/cmdbus" "agent-system-backend/pkg/extension" core "agent-system-core" ) type compiledRegistry struct { skillsRoot string bus *cmdbus.Bus } func (r compiledRegistry) AddSkill(name, markdown string) error { if r.skillsRoot == "" || name == "" { return nil } dest := filepath.Join(r.skillsRoot, "compiled", name) if err := os.MkdirAll(dest, 0o755); err != nil { return err } return os.WriteFile(filepath.Join(dest, "SKILL.md"), []byte(markdown), 0o644) } func (r compiledRegistry) AddCommand(spec json.RawMessage) error { if r.bus == nil { return nil } return r.bus.RegisterPluginCommands([]json.RawMessage{spec}) } func (r compiledRegistry) Note(kind, name string, payload json.RawMessage) error { log.Printf("extension: note %s %s (%d bytes)", kind, name, len(payload)) return nil } func applyCompiled(skillsRoot string, bus *cmdbus.Bus) { reg := compiledRegistry{skillsRoot: skillsRoot, bus: bus} for _, e := range extension.Compiled() { if e.Register == nil { continue } if err := e.Register(reg); err != nil { log.Printf("extension: %s: %v", e.ID, err) } } } func mergeMCPServers(raw string, extra []core.PluginMCPServer) string { var base []json.RawMessage if raw != "" { if err := json.Unmarshal([]byte(raw), &base); err != nil { return raw } } for _, s := range extra { b, err := json.Marshal(s) if err != nil { continue } base = append(base, b) } if len(base) == 0 { return "" } out, err := json.Marshal(base) if err != nil { return raw } return string(out) }