Feat v0.10.0 panel manifest lifecycle
Panels are a new kernel rendering tier between surfaces and block renderers, enabling composable companion views (e.g. notes panel inside chat). This version ships the plumbing layer: - Manifest validation for panels field (provider map + consumer array) - Soft-dep warning at install time for unresolved panel consumers - PanelMeta struct + resolvePanels() resolves consumers at surface load - window.__PANELS__ injected into base template - sw.panels SDK module (open/close/toggle/isOpen/isAvailable/list/active) - Lazy JS loading pipeline with module caching - 10 new tests (6 validation + 4 resolve) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -61,6 +61,20 @@ type SurfaceManifest struct {
|
||||
Source string `json:"source"` // "core" or "extension"
|
||||
}
|
||||
|
||||
// PanelMeta describes a resolved panel available to a surface.
|
||||
type PanelMeta struct {
|
||||
PanelID string `json:"panel_id"` // e.g. "notes.reference"
|
||||
PackageID string `json:"package_id"` // e.g. "notes"
|
||||
Entry string `json:"entry"` // e.g. "js/panels/reference.js"
|
||||
Title string `json:"title"` // human-readable
|
||||
Icon string `json:"icon,omitempty"` // emoji or icon key
|
||||
Description string `json:"description,omitempty"` // short description
|
||||
MinWidth int `json:"min_width,omitempty"` // minimum width in px
|
||||
MinHeight int `json:"min_height,omitempty"` // minimum height in px
|
||||
DefaultWidth int `json:"default_width,omitempty"` // default width in px
|
||||
DefaultHeight int `json:"default_height,omitempty"` // default height in px
|
||||
}
|
||||
|
||||
// BannerConfig holds environment banner settings.
|
||||
type BannerConfig struct {
|
||||
Text string `json:"text"`
|
||||
@@ -109,6 +123,8 @@ type PageData struct {
|
||||
|
||||
BrowserExtensions []string `json:"-"` // IDs of enabled browser-tier extensions (for script injection)
|
||||
|
||||
Panels []PanelMeta `json:"-"` // resolved panels available to this surface
|
||||
|
||||
InstanceName string // branding: instance display name
|
||||
LogoURL string // branding: custom logo URL
|
||||
Tagline string // branding: tagline under instance name
|
||||
@@ -237,6 +253,72 @@ func (e *Engine) browserExtensionIDs() []string {
|
||||
return ids
|
||||
}
|
||||
|
||||
// resolvePanels reads the consumer's panels array from the raw manifest and
|
||||
// resolves each reference against installed+enabled provider packages.
|
||||
// Returns nil if no panels are declared or no providers are available.
|
||||
func (e *Engine) resolvePanels(ctx context.Context, manifest map[string]any) []PanelMeta {
|
||||
if e.stores.Packages == nil {
|
||||
return nil
|
||||
}
|
||||
rawPanels, ok := manifest["panels"].([]any)
|
||||
if !ok || len(rawPanels) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var result []PanelMeta
|
||||
for _, raw := range rawPanels {
|
||||
ref, ok := raw.(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
parts := strings.SplitN(ref, ".", 2)
|
||||
if len(parts) != 2 {
|
||||
continue
|
||||
}
|
||||
pkgID, panelKey := parts[0], parts[1]
|
||||
|
||||
provPkg, err := e.stores.Packages.Get(ctx, pkgID)
|
||||
if err != nil || provPkg == nil || !provPkg.Enabled {
|
||||
continue
|
||||
}
|
||||
|
||||
provPanels, ok := provPkg.Manifest["panels"].(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
panelDef, ok := provPanels[panelKey].(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
meta := PanelMeta{
|
||||
PanelID: ref,
|
||||
PackageID: pkgID,
|
||||
}
|
||||
meta.Entry, _ = panelDef["entry"].(string)
|
||||
meta.Title, _ = panelDef["title"].(string)
|
||||
meta.Icon, _ = panelDef["icon"].(string)
|
||||
meta.Description, _ = panelDef["description"].(string)
|
||||
if v, ok := panelDef["min_width"].(float64); ok {
|
||||
meta.MinWidth = int(v)
|
||||
}
|
||||
if v, ok := panelDef["min_height"].(float64); ok {
|
||||
meta.MinHeight = int(v)
|
||||
}
|
||||
if v, ok := panelDef["default_width"].(float64); ok {
|
||||
meta.DefaultWidth = int(v)
|
||||
}
|
||||
if v, ok := panelDef["default_height"].(float64); ok {
|
||||
meta.DefaultHeight = int(v)
|
||||
}
|
||||
|
||||
if meta.Entry != "" && meta.Title != "" {
|
||||
result = append(result, meta)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// UserContext is the authenticated user's info available to templates.
|
||||
type UserContext struct {
|
||||
ID string `json:"id"`
|
||||
@@ -552,6 +634,7 @@ func (e *Engine) RenderExtensionSurface() gin.HandlerFunc {
|
||||
EnabledSurfaces: e.EnabledSurfaceIDs(),
|
||||
ExtensionSurfaces: e.extensionNavItems(),
|
||||
BrowserExtensions: e.browserExtensionIDs(),
|
||||
Panels: e.resolvePanels(c.Request.Context(), sr.Manifest),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
141
server/pages/panels_test.go
Normal file
141
server/pages/panels_test.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"armature/store"
|
||||
)
|
||||
|
||||
func TestResolvePanels_HappyPath(t *testing.T) {
|
||||
// Provider package with a panels map
|
||||
provider := &store.PackageRegistration{
|
||||
ID: "notes",
|
||||
Title: "Notes",
|
||||
Enabled: true,
|
||||
Source: "extension",
|
||||
Manifest: map[string]any{
|
||||
"panels": map[string]any{
|
||||
"reference": map[string]any{
|
||||
"entry": "js/panels/reference.js",
|
||||
"title": "Notes Reference",
|
||||
"icon": "📝",
|
||||
"description": "Searchable note list",
|
||||
"min_width": float64(280),
|
||||
"default_width": float64(400),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Consumer package that wants notes.reference
|
||||
consumer := &store.PackageRegistration{
|
||||
ID: "chat",
|
||||
Title: "Chat",
|
||||
Enabled: true,
|
||||
Source: "extension",
|
||||
Manifest: map[string]any{
|
||||
"panels": []any{"notes.reference"},
|
||||
},
|
||||
}
|
||||
|
||||
e := testEngine(t, provider, consumer)
|
||||
panels := e.resolvePanels(context.Background(), consumer.Manifest)
|
||||
|
||||
if len(panels) != 1 {
|
||||
t.Fatalf("expected 1 panel, got %d", len(panels))
|
||||
}
|
||||
p := panels[0]
|
||||
if p.PanelID != "notes.reference" {
|
||||
t.Errorf("expected panel_id 'notes.reference', got %q", p.PanelID)
|
||||
}
|
||||
if p.PackageID != "notes" {
|
||||
t.Errorf("expected package_id 'notes', got %q", p.PackageID)
|
||||
}
|
||||
if p.Entry != "js/panels/reference.js" {
|
||||
t.Errorf("expected entry 'js/panels/reference.js', got %q", p.Entry)
|
||||
}
|
||||
if p.Title != "Notes Reference" {
|
||||
t.Errorf("expected title 'Notes Reference', got %q", p.Title)
|
||||
}
|
||||
if p.Icon != "📝" {
|
||||
t.Errorf("expected icon '📝', got %q", p.Icon)
|
||||
}
|
||||
if p.MinWidth != 280 {
|
||||
t.Errorf("expected min_width 280, got %d", p.MinWidth)
|
||||
}
|
||||
if p.DefaultWidth != 400 {
|
||||
t.Errorf("expected default_width 400, got %d", p.DefaultWidth)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolvePanels_ProviderMissing(t *testing.T) {
|
||||
// Consumer references a package that doesn't exist
|
||||
consumer := &store.PackageRegistration{
|
||||
ID: "chat",
|
||||
Title: "Chat",
|
||||
Enabled: true,
|
||||
Source: "extension",
|
||||
Manifest: map[string]any{
|
||||
"panels": []any{"nonexistent.panel"},
|
||||
},
|
||||
}
|
||||
|
||||
e := testEngine(t, consumer)
|
||||
panels := e.resolvePanels(context.Background(), consumer.Manifest)
|
||||
|
||||
if len(panels) != 0 {
|
||||
t.Errorf("expected 0 panels for missing provider, got %d", len(panels))
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolvePanels_ProviderDisabled(t *testing.T) {
|
||||
provider := &store.PackageRegistration{
|
||||
ID: "notes",
|
||||
Title: "Notes",
|
||||
Enabled: false, // disabled
|
||||
Source: "extension",
|
||||
Manifest: map[string]any{
|
||||
"panels": map[string]any{
|
||||
"reference": map[string]any{
|
||||
"entry": "js/panels/reference.js",
|
||||
"title": "Notes Reference",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
consumer := &store.PackageRegistration{
|
||||
ID: "chat",
|
||||
Title: "Chat",
|
||||
Enabled: true,
|
||||
Source: "extension",
|
||||
Manifest: map[string]any{
|
||||
"panels": []any{"notes.reference"},
|
||||
},
|
||||
}
|
||||
|
||||
e := testEngine(t, provider, consumer)
|
||||
panels := e.resolvePanels(context.Background(), consumer.Manifest)
|
||||
|
||||
if len(panels) != 0 {
|
||||
t.Errorf("expected 0 panels for disabled provider, got %d", len(panels))
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolvePanels_NoPanelsField(t *testing.T) {
|
||||
consumer := &store.PackageRegistration{
|
||||
ID: "chat",
|
||||
Title: "Chat",
|
||||
Enabled: true,
|
||||
Source: "extension",
|
||||
Manifest: map[string]any{},
|
||||
}
|
||||
|
||||
e := testEngine(t, consumer)
|
||||
panels := e.resolvePanels(context.Background(), consumer.Manifest)
|
||||
|
||||
if panels != nil {
|
||||
t.Errorf("expected nil panels for manifest without panels field, got %v", panels)
|
||||
}
|
||||
}
|
||||
@@ -124,6 +124,7 @@
|
||||
{{if .Manifest}}window.__MANIFEST__ = {{.Manifest | toJSON}};{{end}}
|
||||
{{if .SurfacePath}}window.__SURFACE_PATH__ = '{{.SurfacePath}}';{{end}}
|
||||
{{if .SurfaceParams}}window.__SURFACE_PARAMS__ = {{.SurfaceParams | toJSON}};{{end}}
|
||||
{{if .Panels}}window.__PANELS__ = {{.Panels | toJSON}};{{end}}
|
||||
</script>
|
||||
|
||||
{{/* All surfaces use Preact SDK boot(). Legacy script includes removed.
|
||||
|
||||
Reference in New Issue
Block a user