Why: Downstream products must extend the base through a public package and host API instead of editing internal code. Evidence: go test ./... passed, including plugin v2 assets, sidecar startup, migration v13, pending confirms, HITL timeout, hash embedder, command pairs, and the extension surface snapshot. Impact: apiVersion 2.0-experimental rejects empty network allowlists for declarative HTTP. Hash embeddings stay opt-in via models.embedding.provider=hash. Plugin secrets resolve per owner at execution time. Refs: docs/proposals/2026-10-01-plugin-contract-v2.md Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
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)
|
|
}
|