Feat v0.6.3 dead code sweep (#38)
All checks were successful
All checks were successful
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #38.
This commit is contained in:
@@ -27,12 +27,12 @@ import (
|
||||
var validPackageID = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$`)
|
||||
|
||||
// PackageHandler manages unified package lifecycle (admin-only).
|
||||
// Replaces SurfaceHandler (v0.28.7).
|
||||
// Replaces SurfaceHandler.
|
||||
type PackageHandler struct {
|
||||
stores store.Stores
|
||||
packagesDir string // e.g. /data/packages — where archives are extracted
|
||||
sandbox *sandbox.Sandbox // v0.30.0: for schema migration scripts
|
||||
runner *sandbox.Runner // v0.38.2: for test-tool execution
|
||||
sandbox *sandbox.Sandbox
|
||||
runner *sandbox.Runner
|
||||
}
|
||||
|
||||
func NewPackageHandler(s store.Stores, packagesDir ...string) *PackageHandler {
|
||||
@@ -43,12 +43,12 @@ func NewPackageHandler(s store.Stores, packagesDir ...string) *PackageHandler {
|
||||
return &PackageHandler{stores: s, packagesDir: dir}
|
||||
}
|
||||
|
||||
// SetSandbox attaches a Starlark sandbox for schema migrations (v0.30.0).
|
||||
// SetSandbox attaches a Starlark sandbox for schema migrations.
|
||||
func (h *PackageHandler) SetSandbox(sb *sandbox.Sandbox) {
|
||||
h.sandbox = sb
|
||||
}
|
||||
|
||||
// SetRunner attaches the Starlark runner for test-tool execution (v0.38.2).
|
||||
// SetRunner attaches the Starlark runner for test-tool execution.
|
||||
func (h *PackageHandler) SetRunner(r *sandbox.Runner) {
|
||||
h.runner = r
|
||||
}
|
||||
@@ -95,7 +95,6 @@ func (h *PackageHandler) GetPackage(c *gin.Context) {
|
||||
func (h *PackageHandler) EnablePackage(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
// v0.3.7: Block enabling dormant packages (unmet requires).
|
||||
pkg, err := h.stores.Packages.Get(c.Request.Context(), id)
|
||||
if err != nil || pkg == nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "package not found"})
|
||||
@@ -149,7 +148,6 @@ func (h *PackageHandler) DeletePackage(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// v0.38.2: Libraries with active consumers cannot be uninstalled.
|
||||
if pkg.Type == "library" && h.stores.Dependencies != nil {
|
||||
hasConsumers, _ := h.stores.Dependencies.HasConsumers(c.Request.Context(), id)
|
||||
if hasConsumers {
|
||||
@@ -158,12 +156,10 @@ func (h *PackageHandler) DeletePackage(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// v0.38.2: Clean up dependency records when uninstalling a consumer.
|
||||
if h.stores.Dependencies != nil {
|
||||
h.stores.Dependencies.DeleteAllForConsumer(c.Request.Context(), id)
|
||||
}
|
||||
|
||||
// v0.29.2: Drop namespaced DB tables before removing the package record.
|
||||
if err := DropExtTables(c.Request.Context(), database.DB, h.stores, id); err != nil {
|
||||
log.Printf("[ext-db] schema drop failed for %s: %v", id, err)
|
||||
}
|
||||
@@ -195,7 +191,6 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
var tmpPath string
|
||||
var cleanupTmp bool
|
||||
|
||||
// v0.30.0: Check for pre-downloaded file from registry install
|
||||
if regFile, ok := c.Get("_registry_file"); ok {
|
||||
tmpPath = regFile.(string)
|
||||
// Don't remove — caller manages lifecycle
|
||||
@@ -278,7 +273,6 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// v0.38.0: Entry point validation for starlark-tier packages.
|
||||
// Scripts are loaded from disk at runtime — no _starlark_script injection.
|
||||
if manifestTier, _ := manifest["tier"].(string); manifestTier == "starlark" {
|
||||
entryPoint := "script.star"
|
||||
@@ -380,7 +374,6 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "full packages require a route"})
|
||||
return
|
||||
}
|
||||
// v0.31.0: full packages need either server-side behavior (tools/pipes/hooks)
|
||||
// or a settings schema. A surface-with-settings is a valid "full" package
|
||||
// (e.g. editor: browser-tier surface + admin-configurable settings).
|
||||
if !hasExtBehavior && !hasSettings {
|
||||
@@ -393,7 +386,6 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
case "library":
|
||||
// v0.38.2: Libraries must declare exports, cannot have tools/pipes/route.
|
||||
exports, _ := manifest["exports"].([]any)
|
||||
if len(exports) == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "library packages require an 'exports' array"})
|
||||
@@ -471,7 +463,6 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
|
||||
userID := c.GetString("user_id")
|
||||
|
||||
// v0.30.0: use registry source if set by registry install handler
|
||||
pkgSource := "extension"
|
||||
if src, ok := c.Get("_registry_source"); ok {
|
||||
pkgSource = src.(string)
|
||||
@@ -509,22 +500,18 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
log.Printf("[packages] Failed to update package metadata for %s: %v", pkgID, err)
|
||||
}
|
||||
|
||||
// v0.29.2: Create namespaced DB tables declared in the manifest.
|
||||
if tables, ok := ParseDBTables(manifest); ok {
|
||||
if err := CreateExtTables(c.Request.Context(), database.DB, database.IsPostgres(), h.stores, pkgID, tables); err != nil {
|
||||
log.Printf("[ext-db] schema create failed for %s: %v", pkgID, err)
|
||||
}
|
||||
}
|
||||
|
||||
// v0.38.5: Declare manifest permissions (same as AdminInstallExtension).
|
||||
// This creates the permission rows and sets status to pending_review
|
||||
// if the package declares permissions.
|
||||
SyncManifestPermissions(c, h.stores, pkgID, manifest)
|
||||
|
||||
// v0.2.2: Sync triggers from manifest
|
||||
SyncManifestTriggers(c.Request.Context(), h.stores, triggers.GlobalEngine(), pkgID, manifest)
|
||||
|
||||
// v0.30.0: Run schema migrations if declared.
|
||||
newSchemaVersion := ParseSchemaVersion(manifest)
|
||||
if newSchemaVersion > 0 && h.sandbox != nil {
|
||||
oldSchemaVersion := 0
|
||||
@@ -553,7 +540,6 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// v0.30.2: Install workflow definition from package manifest.
|
||||
if pkgType == "workflow" {
|
||||
if err := InstallWorkflowFromManifest(c, h.stores, pkgID, manifest); err != nil {
|
||||
log.Printf("[packages] workflow install failed for %s: %v", pkgID, err)
|
||||
@@ -562,7 +548,6 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// v0.38.2: Create dependency records from manifest "dependencies" map.
|
||||
// Libraries must be installed first; consumers declare them.
|
||||
if deps, ok := manifest["dependencies"].(map[string]any); ok && len(deps) > 0 {
|
||||
// Clear stale dependency records from a previous install of the same consumer.
|
||||
@@ -603,7 +588,6 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
log.Printf("[packages] %s: %d dependencies recorded", pkgID, len(deps))
|
||||
}
|
||||
|
||||
// v0.2.1: Auto-set default_surface when the first extension surface is installed.
|
||||
if (pkgType == "surface" || pkgType == "full") && pkgSource != "core" {
|
||||
if raw, err := h.stores.GlobalConfig.Get(c.Request.Context(), "default_surface"); err != nil || raw == nil {
|
||||
dflt := models.JSONMap{"id": pkgID}
|
||||
@@ -615,7 +599,6 @@ func (h *PackageHandler) InstallPackage(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// v0.3.7: Auto-set dormant for packages with unmet requires.
|
||||
// Known capabilities: (none yet — chat and legacy-sdk are future/removed).
|
||||
knownCaps := map[string]bool{}
|
||||
var unmetReqs []string
|
||||
@@ -689,7 +672,7 @@ func extractableRelPath(name string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// ── Package settings (v0.30.0 CS2) ──────────────
|
||||
// ── Package settings ──────────────
|
||||
|
||||
// GetPackageSettings returns the settings schema from the manifest merged
|
||||
// with current admin-configured values.
|
||||
@@ -823,7 +806,7 @@ func (h *PackageHandler) ListEnabledSurfaces(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"data": enabled})
|
||||
}
|
||||
|
||||
// ── Test Tool (v0.38.2) ─────────────────────────
|
||||
// ── Test Tool ─────────────────────────
|
||||
// POST /admin/packages/:id/test-tool
|
||||
// Invokes a starlark extension's on_tool_call entry point directly,
|
||||
// without going through the AI chat loop. Admin-only test harness.
|
||||
@@ -898,7 +881,7 @@ func (h *PackageHandler) TestTool(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// ── Package update (v0.5.4) ──────────────────────
|
||||
// ── Package update ──────────────────────
|
||||
|
||||
// UpdatePackage applies an in-place update to an existing package.
|
||||
// POST /api/v1/admin/packages/:id/update
|
||||
@@ -1175,7 +1158,7 @@ func mergePackageSettings(existing *store.PackageRegistration, manifest map[stri
|
||||
return data
|
||||
}
|
||||
|
||||
// ── Package export (v0.5.4) ──────────────────────
|
||||
// ── Package export ──────────────────────
|
||||
|
||||
// ExportPackage exports an installed package as a downloadable .pkg archive.
|
||||
// GET /api/v1/admin/packages/:id/export
|
||||
|
||||
Reference in New Issue
Block a user