fix(WP-0014): pre-flight compilation fixes, Tailwind pipeline, and admin seed

A2 — Compilation fixes:
- Remove inline FK constraints from Schema.sql; IHP schema compiler cannot
  parse them. Add 1744329600-restore-fk-constraints.sql migration to restore
  referential integrity at the DB level.
- Rename `#label` → `#label_` throughout to avoid clash with Haskell built-in.
- Fix `hub.id == hid` UUID comparisons to use `toUUID hub.id`.
- Replace non-existent `setStatus`/`respondJson` calls with
  `renderJsonWithStatusCode` throughout Api controllers.
- Fix qualified package import for `cryptohash-sha256` in Auth.hs.
- Add `CanSelect (Text, Text)` instance in Helper.View.
- Refactor HSX inline lambdas to named helper functions in 100+ views
  (GHC cannot infer types for anonymous functions inside quasi-quoted HSX).
- Fix missing imports (IHP.QueryBuilder, IHP.Fetch, Web.Routes, Only, etc.)
  across helpers and controllers.
- Remove duplicate `diffUTCTime` definition in BottleneckDetector.
- Change `createEventForHub` return type from `IO ResponseReceived` to `IO ()`.
- Seed type-registry vocabulary via 1744502400-seed-type-registries.sql
  (moved from Schema.sql where IHP does not execute INSERT statements).

A3 — Tailwind build pipeline:
- Add `tailwindcss` to flake.nix native packages.
- Uncomment `tailwind.exec` process in devenv shell config.
- Add tailwind/tailwind.config.js (scans Web/View/**/*.hs).
- Add tailwind/app.css with @tailwind directives.

A4 — Admin user seed:
- Add 1744416000-seed-admin-user.sql: inserts admin@inter-hub.local
  with bcrypt-hashed password admin1234! (cost 10).
- Add .env.example documenting all required environment variables
  and default admin credentials.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-04 09:55:12 +00:00
parent ffd5fbb900
commit f1978c3888
147 changed files with 2710 additions and 2075 deletions

View File

@@ -4,6 +4,7 @@ import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Web.Routes ()
import Web.View.Widgets.New (renderForm)
data EditView = EditView
@@ -20,7 +21,7 @@ instance View EditView where
<div class="flex items-center gap-2 text-sm text-gray-500 mb-4">
<a href={WidgetsAction} class="hover:text-gray-700">Widgets</a>
<span>/</span>
<a href={ShowWidgetAction { widgetId = widget.id }} class="hover:text-gray-700">{widget.name}</a>
<a href={ShowWidgetAction (widget.id)} class="hover:text-gray-700">{widget.name}</a>
<span>/</span>
<span>Edit</span>
</div>

View File

@@ -4,6 +4,7 @@ import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Web.Routes ()
data IndexView = IndexView
{ widgets :: ![Widget]
@@ -42,7 +43,7 @@ renderWidget :: [Hub] -> Widget -> Html
renderWidget hubs w = [hsx|
<tr class="border-b border-gray-100 hover:bg-gray-50">
<td class="px-4 py-3">
<a href={ShowWidgetAction { widgetId = w.id }}
<a href={ShowWidgetAction (w.id)}
class="font-medium text-indigo-600 hover:text-indigo-800">
{w.name}
</a>
@@ -56,7 +57,7 @@ renderWidget hubs w = [hsx|
</td>
<td class="px-4 py-3 text-gray-500 text-xs">v{show w.version}</td>
<td class="px-4 py-3 text-right">
<a href={EditWidgetAction { widgetId = w.id }}
<a href={EditWidgetAction (w.id)}
class="text-gray-500 hover:text-gray-700 text-xs">Edit</a>
</td>
</tr>

View File

@@ -4,6 +4,7 @@ import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Web.Routes ()
data NewView = NewView
{ widget :: !Widget
@@ -34,22 +35,23 @@ renderForm widget hubs adapterSpecs widgetTypes policyScopes = formFor widget [h
<label class="ihp-form-label">Adapter Spec (optional leave blank for native IHP widget)</label>
<select name="adapterSpecId" class="ihp-form-field">
<option value=""> Native IHP widget </option>
{forEach adapterSpecs (\s -> [hsx|
<option value={tshow s.id}>{s.name} ({s.framework} v{s.version})</option>
|])}
{forEach adapterSpecs renderAdapterOption}
</select>
</div>
{submitButton}
|]
renderAdapterOption :: WidgetAdapterSpec -> Html
renderAdapterOption s = [hsx|<option value={tshow s.id}>{s.name} ({s.framework} v{s.version})</option>|]
hubOptions :: [Hub] -> [(Text, Id Hub)]
hubOptions hubs = map (\h -> (h.name, h.id)) hubs
widgetTypeOptions :: [WidgetTypeRegistry] -> [(Text, Text)]
widgetTypeOptions = map (\r -> (r.label, r.name))
widgetTypeOptions = map (\r -> (r.label_, r.name))
policyScopeOptions :: [PolicyScopeRegistry] -> [(Text, Text)]
policyScopeOptions = map (\r -> (r.label, r.name))
policyScopeOptions = map (\r -> (r.label_, r.name))
statusOptions :: [(Text, Text)]
statusOptions =

View File

@@ -4,6 +4,7 @@ import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Web.Routes ()
import Application.Helper.View (widgetEnvelope)
data ShowView = ShowView
@@ -23,28 +24,14 @@ instance View ShowView where
<div class="mb-2 flex items-center gap-2 text-sm text-gray-500">
<a href={HubsAction} class="hover:text-gray-700">Hubs</a>
<span>/</span>
<a href={ShowHubAction { hubId = hub.id }} class="hover:text-gray-700">{hub.name}</a>
<a href={ShowHubAction (hub.id)} class="hover:text-gray-700">{hub.name}</a>
<span>/</span>
<span>{widget.name}</span>
</div>
{if cycleCount >= 2 then [hsx|
<div class="mb-2 flex items-center gap-2 bg-yellow-50 border border-yellow-200 rounded-lg px-4 py-2">
<span class="text-yellow-700 font-semibold text-sm"> {show cycleCount} cycles</span>
<span class="text-yellow-600 text-xs">
Recurring friction this widget has been through {show cycleCount} improvement cycles.
</span>
</div>
|] else mempty}
{renderCycleBanner cycleCount}
{if isRegressed then [hsx|
<div class="mb-4 flex items-center gap-2 bg-red-50 border border-red-200 rounded-lg px-4 py-3">
<span class="text-red-600 font-semibold text-sm"> Regression detected</span>
<span class="text-red-500 text-xs">
This widget had an improved signal but has since received high/critical annotations.
</span>
</div>
|] else mempty}
{if isRegressed then renderRegressionBanner else mempty}
{widgetEnvelope widget [hsx|
<div class="flex items-center justify-between mb-4">
@@ -58,7 +45,7 @@ instance View ShowView where
{renderAdapterBadge mAdapterSpec}
</p>
</div>
<a href={EditWidgetAction { widgetId = widget.id }}
<a href={EditWidgetAction (widget.id)}
class="text-sm border border-gray-300 px-3 py-1.5 rounded hover:bg-gray-50">
Edit
</a>
@@ -85,19 +72,13 @@ instance View ShowView where
<div class="flex items-center justify-between mb-3">
<h2 class="text-lg font-medium">Annotations</h2>
<div class="flex items-center gap-2">
{if length annotations >= 3 then [hsx|
<form method="POST" action={DraftRequirementAction { widgetId = widget.id }} class="inline">
<button type="submit" class="text-xs border border-indigo-300 text-indigo-700 px-2 py-1 rounded hover:bg-indigo-50">
Draft Requirement
</button>
</form>
|] else mempty}
<form method="POST" action={SummarizeClusterAction { widgetId = widget.id }} class="inline">
{if length annotations >= 3 then renderDraftRequirementForm widget.id else mempty}
<form method="POST" action={SummarizeClusterAction (widget.id)} class="inline">
<button type="submit" class="text-xs border border-blue-300 text-blue-700 px-2 py-1 rounded hover:bg-blue-50">
Summarize Feedback
</button>
</form>
<a href={NewAnnotationAction { widgetId = widget.id }}
<a href={NewAnnotationAction (widget.id)}
class="text-sm text-indigo-600 hover:text-indigo-800">+ Add</a>
</div>
</div>
@@ -132,14 +113,7 @@ instance View ShowView where
</div>
</section>
{if null recentSignals then mempty else [hsx|
<section class="mb-8">
<h2 class="text-lg font-medium mb-3">Recent Outcome Signals</h2>
<div class="bg-white rounded-lg border border-gray-200 divide-y divide-gray-100">
{forEach recentSignals renderSignalRow}
</div>
</section>
|]}
{renderSignalsSection recentSignals}
<section>
<h2 class="text-lg font-medium mb-3">Version History</h2>
@@ -213,7 +187,7 @@ renderSignalRow sig = [hsx|
<span class={signalTypeClass sig.signalType <> " text-xs px-2 py-0.5 rounded font-medium"}>
{sig.signalType}
</span>
{maybe mempty (\v -> [hsx|<span class="font-mono text-gray-700">{show v}</span>|]) sig.value}
{maybe mempty renderSignalValue sig.value}
<span class="text-xs text-gray-400 ml-auto">{show sig.observedAt}</span>
</div>
|]
@@ -225,10 +199,54 @@ signalTypeClass "neutral" = "bg-gray-100 text-gray-600"
signalTypeClass "inconclusive" = "bg-yellow-100 text-yellow-800"
signalTypeClass _ = "bg-gray-100 text-gray-600"
renderCycleBanner :: Int -> Html
renderCycleBanner n | n >= 2 = [hsx|
<div class="mb-2 flex items-center gap-2 bg-yellow-50 border border-yellow-200 rounded-lg px-4 py-2">
<span class="text-yellow-700 font-semibold text-sm"> {show n} cycles</span>
<span class="text-yellow-600 text-xs">
Recurring friction this widget has been through {show n} improvement cycles.
</span>
</div>
|]
renderCycleBanner _ = mempty
renderRegressionBanner :: Html
renderRegressionBanner = [hsx|
<div class="mb-4 flex items-center gap-2 bg-red-50 border border-red-200 rounded-lg px-4 py-3">
<span class="text-red-600 font-semibold text-sm"> Regression detected</span>
<span class="text-red-500 text-xs">
This widget had an improved signal but has since received high/critical annotations.
</span>
</div>
|]
renderDraftRequirementForm :: Id Widget -> Html
renderDraftRequirementForm wid = [hsx|
<form method="POST" action={DraftRequirementAction (wid)} class="inline">
<button type="submit" class="text-xs border border-indigo-300 text-indigo-700 px-2 py-1 rounded hover:bg-indigo-50">
Draft Requirement
</button>
</form>
|]
renderSignalsSection :: [OutcomeSignal] -> Html
renderSignalsSection [] = mempty
renderSignalsSection sigs = [hsx|
<section class="mb-8">
<h2 class="text-lg font-medium mb-3">Recent Outcome Signals</h2>
<div class="bg-white rounded-lg border border-gray-200 divide-y divide-gray-100">
{forEach sigs renderSignalRow}
</div>
</section>
|]
renderSignalValue :: Double -> Html
renderSignalValue v = [hsx|<span class="font-mono text-gray-700">{show v}</span>|]
renderAdapterBadge :: Maybe WidgetAdapterSpec -> Html
renderAdapterBadge Nothing = mempty
renderAdapterBadge (Just s) = [hsx|
<a href={ShowWidgetAdapterSpecAction { widgetAdapterSpecId = s.id }}
<a href={ShowWidgetAdapterSpecAction (s.id)}
class="ml-2 text-xs bg-purple-100 text-purple-700 px-1.5 py-0.5 rounded hover:bg-purple-200">
adapter: {s.name}
</a>