Files
kandev/apps/backend/internal/backendapp/plugins.go
T
Kandev Agent c53f699714 feat: add plugin system with grpc runtime and native ui plugins
- go plugin backends ship as release tarballs (per-platform binaries, checksums) that
  kandev installs from url/upload or filesystem sideload+sync, then spawns and
  supervises via hashicorp/go-plugin (unix socket / loopback tcp+automtls)
- strict typed grpc contract (kandev.plugin.v1): DeliverEvent/InvokeTool/HandleWebhook
  plus a capability-gated host service (state, secrets, emit); author sdk in
  pkg/pluginsdk; packaging cli in cmd/plugin-pack
- native frontend bundles: window.registerKandevPlugin + registry/host loader with
  dynamic routes, nav items, slots and ws handlers; plugins settings page with
  install dialog, sync button and enable/disable/uninstall
- gated behind the plugins feature flag (prod off, dev/e2e on); covered by unit and
  integration tests plus playwright e2e against a real packaged fixture plugin

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 17:55:45 +01:00

57 lines
2.2 KiB
Go

package backendapp
import (
"context"
"github.com/kandev/kandev/internal/common/logger"
"github.com/kandev/kandev/internal/events/bus"
"github.com/kandev/kandev/internal/plugins"
"github.com/kandev/kandev/internal/plugins/delivery"
pluginstore "github.com/kandev/kandev/internal/plugins/store"
)
// pluginActivePluginsAdapter adapts *plugins.Service to delivery.PluginLister
// so the Deliverer can track which plugins should receive live deliveries
// (StatusActive) or buffer them (StatusError) without internal/plugins/delivery
// importing internal/plugins — see that package's doc comment ("backendapp
// adapts *plugins.Service to satisfy them").
type pluginActivePluginsAdapter struct {
svc *plugins.Service
}
// ActivePlugins implements delivery.PluginLister.
func (a pluginActivePluginsAdapter) ActivePlugins() []delivery.PluginRecord {
records := a.svc.Registry().List()
out := make([]delivery.PluginRecord, 0, len(records))
for _, rec := range records {
if rec.Status != pluginstore.StatusActive && rec.Status != pluginstore.StatusError {
continue
}
out = append(out, delivery.PluginRecord{
ID: rec.ID,
EventSubjects: rec.Capabilities.Events,
Status: rec.Status,
})
}
return out
}
// startPluginsSubsystems attaches event delivery to svc and spawns every
// already-active, runtime-managed plugin (resuming plugins that were active
// before a backend restart), registering shutdown via addCleanup. Mirrors
// how the Jira/Linear/Sentry pollers are started in
// startAgentInfrastructure: construction happens in initPluginsService
// (services.go), lifecycle start happens here once ctx/addCleanup exist.
func startPluginsSubsystems(ctx context.Context, svc *plugins.Service, eventBus bus.EventBus, log *logger.Logger, addCleanup func(func() error)) {
transport := plugins.NewRuntimeTransport(svc.Runtime())
deliverer := delivery.New(eventBus, transport, pluginActivePluginsAdapter{svc: svc}, log)
svc.SetDeliverer(deliverer)
deliverer.Refresh()
addCleanup(func() error { deliverer.Stop(); return nil })
addCleanup(func() error { svc.Shutdown(); return nil })
svc.StartActivePlugins(ctx)
log.Info("Plugins subsystems started (event delivery + active plugin spawn)")
}