V0.7.0 shell contract (#54)
All checks were successful
CI/CD / detect-changes (push) Successful in 3s
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-sqlite (push) Successful in 2m54s
CI/CD / test-go-pg (push) Successful in 2m55s
CI/CD / build-and-deploy (push) Successful in 1m5s

This commit was merged in pull request #54.
This commit is contained in:
2026-04-01 20:19:45 +00:00
parent 1236220302
commit e916ed41ea
151 changed files with 3250 additions and 684 deletions

View File

@@ -11,11 +11,13 @@ import (
"path/filepath"
"regexp"
"strings"
"time"
"github.com/gin-gonic/gin"
"go.starlark.net/starlark"
"armature/database"
"armature/events"
"armature/models"
"armature/sandbox"
"armature/store"
@@ -34,6 +36,7 @@ type PackageHandler struct {
bundledDir string // e.g. /app/bundled-packages — .pkg archive source
sandbox *sandbox.Sandbox
runner *sandbox.Runner
hub *events.Hub
}
func NewPackageHandler(s store.Stores, packagesDir ...string) *PackageHandler {
@@ -60,6 +63,23 @@ func (h *PackageHandler) SetRunner(r *sandbox.Runner) {
h.runner = r
}
// SetHub attaches the event hub for broadcasting package lifecycle events.
func (h *PackageHandler) SetHub(hub *events.Hub) {
h.hub = hub
}
// broadcastPackageChanged emits a package.changed event to all clients.
func (h *PackageHandler) broadcastPackageChanged(action, id string) {
if h.hub == nil {
return
}
h.hub.Broadcast(events.Event{
Label: "package.changed",
Payload: events.MustJSON(map[string]string{"action": action, "id": id}),
Ts: time.Now().UnixMilli(),
})
}
// ListPackages returns all registered packages.
// GET /api/v1/admin/packages
func (h *PackageHandler) ListPackages(c *gin.Context) {
@@ -116,6 +136,7 @@ func (h *PackageHandler) EnablePackage(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{"id": id, "enabled": true})
h.broadcastPackageChanged("enabled", id)
}
// DisablePackage disables a package. Admin cannot be disabled.
@@ -133,6 +154,7 @@ func (h *PackageHandler) DisablePackage(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{"id": id, "enabled": false})
h.broadcastPackageChanged("disabled", id)
}
// DeletePackage uninstalls a package. Core packages cannot be deleted.
@@ -180,6 +202,7 @@ func (h *PackageHandler) DeletePackage(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{"id": id, "deleted": true})
h.broadcastPackageChanged("deleted", id)
}
// InstallPackage uploads and installs a .pkg/.surface archive.
@@ -586,6 +609,7 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
resp["status"] = "dormant"
}
c.JSON(http.StatusOK, resp)
h.broadcastPackageChanged("installed", pkgID)
}
// extractableRelPath returns the relative path for a zip entry if it
@@ -1073,6 +1097,7 @@ func (h *PackageHandler) UpdatePackage(c *gin.Context) {
"previous_version": previousVersion,
"changes": schemaChanges,
})
h.broadcastPackageChanged("updated", pkgID)
}
// mergePackageSettings merges existing settings with a new manifest's settings schema.