Files
inter-hub/Web/Controller/HubRegistry.hs
Bernd Worsch 6e8972f828
Some checks failed
Test / test (push) Has been cancelled
feat(WP-0011): IHF Phase 10 — Hub Registry and Widget Marketplace
Delivers the hub registry discovery UI, widget pattern library,
governance template library, and marketplace dashboard.

Key changes:
- Schema: widget_patterns (widget_type FK to registry), widget_pattern_versions,
  pattern_adoptions, governance_templates (categories JSONB, validated at
  controller), governance_template_clones — all GAAF-compliant, no bare TEXT
  type discriminators
- Migration: 1743897600-ihf-phase10-hub-registry.sql
- HubRegistry controller + views: browsable view over hub_capability_manifests,
  hub_health_snapshots, hubs with per-hub GAAF compliance indicator
- WidgetPatterns controller + views: publish, version, adopt; adoption
  triggers manifest amendment draft when new types are introduced
- GovernanceTemplates controller + views: CRUD, clone with category
  validation against annotation_category_registry
- MarketplaceDashboard controller + view: full-text search, widget-type
  filter, sort, trending panel, autoRefresh
- API v2: /api/v2/hub-registry, /api/v2/widget-patterns (+ adopt endpoint)
- OpenAPI spec updated with Phase 10 paths
- GAAF scorecard: Customization 2.5 → 3.2; overall 3.41 → 3.56 (Strong)
- CLAUDE.md: Phase 10 complete; active workplan → Phase 11

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-01 20:14:43 +00:00

76 lines
2.8 KiB
Haskell

module Web.Controller.HubRegistry where
-- Hub Registry: browsable view over hub_capability_manifests + hub_health_snapshots + hubs
-- No HubRegistry table — this is a view over existing Phase 9 data.
import Web.Types
import Web.View.HubRegistry.Index
import Web.View.HubRegistry.Show
import Generated.Types
import IHP.Prelude
import IHP.ControllerPrelude
-- | Aggregated row for the hub registry index.
data HubRegistryRow = HubRegistryRow
{ hub :: !Hub
, mManifest :: !(Maybe HubCapabilityManifest)
, mLatestSnapshot :: !(Maybe HubHealthSnapshot)
}
-- | GAAF compliance status derived from manifest and registry.
data GaafStatus
= GaafCompliant -- active manifest, all declared types registered
| GaafNoManifest -- hub has no active manifest
| GaafDraftOnly -- hub has a draft but no active manifest
deriving (Eq, Show)
gaafStatus :: Maybe HubCapabilityManifest -> GaafStatus
gaafStatus Nothing = GaafNoManifest
gaafStatus (Just m)
| m.status == "active" = GaafCompliant
| m.status == "draft" = GaafDraftOnly
| otherwise = GaafNoManifest
instance Controller HubRegistryController where
beforeAction = ensureIsUser
action HubRegistryAction = autoRefresh do
hubs <- query @Hub |> orderByAsc #name |> fetch
registryRows <- mapM buildRow hubs
render IndexView { registryRows }
action ShowHubRegistryAction { hubId } = do
hub <- fetch hubId
mManifest <- query @HubCapabilityManifest
|> filterWhere (#hubId, hubId)
|> filterWhere (#status, "active")
|> fetchOneOrNothing
healthHistory <- query @HubHealthSnapshot
|> filterWhere (#hubId, hubId)
|> orderByDesc #computedAt
|> limit 10
|> fetch
adoptedPatterns <- sqlQuery
"SELECT wp.id, wp.name, wp.widget_type, wp.hub_id, \
\ pa.id AS adoption_id, pa.is_version_pinned, pa.adopted_at \
\ FROM pattern_adoptions pa \
\ JOIN widget_patterns wp ON wp.id = pa.widget_pattern_id \
\ WHERE pa.adopting_hub_id = ? \
\ ORDER BY pa.adopted_at DESC"
(Only hubId)
render ShowView { hub, mManifest, healthHistory, adoptedPatterns }
-- | Build a HubRegistryRow for a hub by fetching its active manifest and latest snapshot.
buildRow :: (?modelContext :: ModelContext) => Hub -> IO HubRegistryRow
buildRow hub = do
mManifest <- query @HubCapabilityManifest
|> filterWhere (#hubId, hub.id)
|> filterWhere (#status, "active")
|> fetchOneOrNothing
mLatestSnapshot <- query @HubHealthSnapshot
|> filterWhere (#hubId, hub.id)
|> orderByDesc #computedAt
|> limit 1
|> fetchOneOrNothing
pure HubRegistryRow { hub, mManifest, mLatestSnapshot }