@tokenoftrust/storefront-runner 1.4.1 → 1.4.2-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/apps/storefront/astro.config.mjs +17 -1
  2. package/apps/storefront/integrations/materialize-guard.mjs +56 -0
  3. package/apps/storefront/migrations-apps/0002_good_switch.sql +26 -0
  4. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +12 -0
  5. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +1160 -0
  6. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +1235 -0
  7. package/apps/storefront/migrations-apps/meta/_journal.json +14 -0
  8. package/apps/storefront/public/js/dashboard-team.js +38 -2
  9. package/apps/storefront/src/components/Seo.astro +65 -1
  10. package/apps/storefront/src/components/admin/AdminBlogDetailRail.astro +878 -0
  11. package/apps/storefront/src/components/admin/AdminBlogTab.astro +1432 -0
  12. package/apps/storefront/src/components/admin/AdminCustomersTab.astro +3 -7
  13. package/apps/storefront/src/components/admin/AdminPublishTab.astro +1105 -2334
  14. package/apps/storefront/src/components/admin/AdminSubscriptionsTab.astro +1 -3
  15. package/apps/storefront/src/components/blog/BlogPaywall.astro +87 -0
  16. package/apps/storefront/src/components/blog/PostAccessBadge.astro +43 -0
  17. package/apps/storefront/src/components/blog/PostGrid.astro +57 -0
  18. package/apps/storefront/src/components/blog/ReactionBar.astro +214 -0
  19. package/apps/storefront/src/layouts/Layout.astro +48 -3
  20. package/apps/storefront/src/lib/activity/alerts.ts +17 -19
  21. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +3 -3
  22. package/apps/storefront/src/lib/activity/deployVersion.ts +19 -26
  23. package/apps/storefront/src/lib/activity/ingest.ts +8 -8
  24. package/apps/storefront/src/lib/activity/ingestAuth.ts +1 -1
  25. package/apps/storefront/src/lib/activity/killSwitch.ts +6 -6
  26. package/apps/storefront/src/lib/activity/query.ts +9 -9
  27. package/apps/storefront/src/lib/activity/recordActivity.ts +11 -15
  28. package/apps/storefront/src/lib/activity/store.ts +4 -6
  29. package/apps/storefront/src/lib/activity/uiActor.ts +12 -12
  30. package/apps/storefront/src/lib/activity/workerCommit.ts +6 -6
  31. package/apps/storefront/src/lib/admin/adminShell.ts +290 -0
  32. package/apps/storefront/src/lib/admin/ai/approvalMode.ts +2 -3
  33. package/apps/storefront/src/lib/admin/ai/audit.ts +3 -5
  34. package/apps/storefront/src/lib/admin/checkoutStyleInput.ts +7 -7
  35. package/apps/storefront/src/lib/admin/checkoutStyleTarget.ts +3 -3
  36. package/apps/storefront/src/lib/admin/orderClient.ts +3 -5
  37. package/apps/storefront/src/lib/admin/services/orders.ts +17 -19
  38. package/apps/storefront/src/lib/admin/viewmodels/aiWorkflows.ts +4 -6
  39. package/apps/storefront/src/lib/admin/viewmodels/settings.ts +1 -1
  40. package/apps/storefront/src/lib/apps/adminService.ts +4 -4
  41. package/apps/storefront/src/lib/apps/adminSession.ts +53 -44
  42. package/apps/storefront/src/lib/apps/apiAuth.ts +2 -2
  43. package/apps/storefront/src/lib/apps/apiRoute.ts +2 -2
  44. package/apps/storefront/src/lib/apps/catalogMapper.ts +1 -1
  45. package/apps/storefront/src/lib/apps/credentials.ts +2 -2
  46. package/apps/storefront/src/lib/apps/gatewayKeys.ts +4 -4
  47. package/apps/storefront/src/lib/apps/healthAggregate.ts +5 -5
  48. package/apps/storefront/src/lib/apps/orders/attributionService.ts +2 -2
  49. package/apps/storefront/src/lib/apps/orders/customerHash.ts +1 -1
  50. package/apps/storefront/src/lib/apps/orders/foxyOrderClient.ts +12 -12
  51. package/apps/storefront/src/lib/apps/orders/idempotency.ts +7 -7
  52. package/apps/storefront/src/lib/apps/orders/orderForwardReceiver.ts +1 -1
  53. package/apps/storefront/src/lib/apps/orders/orderMapper.ts +2 -2
  54. package/apps/storefront/src/lib/apps/orders/ordersStore.ts +6 -6
  55. package/apps/storefront/src/lib/apps/registryService.ts +6 -6
  56. package/apps/storefront/src/lib/apps/scopes.ts +2 -2
  57. package/apps/storefront/src/lib/apps/tokenIssuer.ts +4 -4
  58. package/apps/storefront/src/lib/apps/tokenVerifier.ts +6 -6
  59. package/apps/storefront/src/lib/apps/widgets/eligibility.ts +2 -2
  60. package/apps/storefront/src/lib/apps/widgets/frameProps.ts +3 -3
  61. package/apps/storefront/src/lib/apps/widgets/launchToken.ts +4 -4
  62. package/apps/storefront/src/lib/apps/widgets/placements.ts +2 -2
  63. package/apps/storefront/src/lib/apps/widgets/renderSlot.ts +1 -1
  64. package/apps/storefront/src/lib/auth/adminEntry.ts +9 -9
  65. package/apps/storefront/src/lib/auth/identityToken.ts +6 -14
  66. package/apps/storefront/src/lib/auth/loginGate.ts +75 -13
  67. package/apps/storefront/src/lib/auth/mcpClientAssertion.ts +2 -4
  68. package/apps/storefront/src/lib/auth/operatorSession.ts +113 -0
  69. package/apps/storefront/src/lib/auth/session.ts +7 -8
  70. package/apps/storefront/src/lib/auth/totAccessClient.ts +8 -18
  71. package/apps/storefront/src/lib/basePath.ts +9 -2
  72. package/apps/storefront/src/lib/blog/access.ts +29 -0
  73. package/apps/storefront/src/lib/blog/collection.ts +313 -0
  74. package/apps/storefront/src/lib/blog/markdown.ts +174 -0
  75. package/apps/storefront/src/lib/blog/provider.ts +5 -0
  76. package/apps/storefront/src/lib/blog/reactions.ts +87 -0
  77. package/apps/storefront/src/lib/blog/rss.ts +92 -0
  78. package/apps/storefront/src/lib/blog/teaser.ts +83 -0
  79. package/apps/storefront/src/lib/blog/types.ts +34 -0
  80. package/apps/storefront/src/lib/blog/viewCounts.ts +243 -0
  81. package/apps/storefront/src/lib/d1/catalog.ts +2 -2
  82. package/apps/storefront/src/lib/d1/schema-apps.ts +96 -17
  83. package/apps/storefront/src/lib/dev/activityIngestToken.ts +2 -4
  84. package/apps/storefront/src/lib/dev/activityStore.ts +3 -5
  85. package/apps/storefront/src/lib/dev/apiBase.ts +1 -4
  86. package/apps/storefront/src/lib/dev/cockpitStore.ts +1 -9
  87. package/apps/storefront/src/lib/dev/devDraft.ts +1 -1
  88. package/apps/storefront/src/lib/dev/previewStatus.ts +9 -21
  89. package/apps/storefront/src/lib/dev/rendezvousBroker.ts +9 -24
  90. package/apps/storefront/src/lib/edgeCache.ts +17 -0
  91. package/apps/storefront/src/lib/http/fetchTransport.ts +63 -0
  92. package/apps/storefront/src/lib/i18n.ts +25 -0
  93. package/apps/storefront/src/lib/jsonld.ts +118 -0
  94. package/apps/storefront/src/lib/monitoring/manifest.ts +11 -11
  95. package/apps/storefront/src/lib/newsletter/confirmationEmail.ts +30 -0
  96. package/apps/storefront/src/lib/newsletter/consent.ts +23 -0
  97. package/apps/storefront/src/lib/newsletter/digest.ts +117 -0
  98. package/apps/storefront/src/lib/newsletter/resendClient.ts +79 -0
  99. package/apps/storefront/src/lib/newsletter/send.ts +265 -0
  100. package/apps/storefront/src/lib/newsletter/subscribers.ts +156 -0
  101. package/apps/storefront/src/lib/publish/adminPublishTab.ts +3519 -0
  102. package/apps/storefront/src/lib/publish/apex-readiness.ts +41 -18
  103. package/apps/storefront/src/lib/publish/dispatchHealth.ts +5 -7
  104. package/apps/storefront/src/lib/publish/domainState.ts +22 -13
  105. package/apps/storefront/src/lib/publish/panelPolling.ts +78 -0
  106. package/apps/storefront/src/lib/publish/shipWorkspace.ts +100 -49
  107. package/apps/storefront/src/lib/publish/stageBundleUpload.ts +215 -0
  108. package/apps/storefront/src/lib/rate/kvWindow.ts +53 -0
  109. package/apps/storefront/src/lib/search/index.ts +2 -2
  110. package/apps/storefront/src/lib/seo/alternates.ts +42 -0
  111. package/apps/storefront/src/lib/seo/meta.ts +65 -0
  112. package/apps/storefront/src/lib/social/golive.ts +212 -0
  113. package/apps/storefront/src/lib/social/notify.ts +32 -0
  114. package/apps/storefront/src/lib/social/tokenStore.ts +171 -0
  115. package/apps/storefront/src/lib/the-build/provider.ts +27 -0
  116. package/apps/storefront/src/lib/the-build/readingTime.ts +35 -0
  117. package/apps/storefront/src/lib/the-build/toc.ts +95 -0
  118. package/apps/storefront/src/lib/tot/ToTClient.ts +1 -1
  119. package/apps/storefront/src/lib/tot/d1Client.ts +2 -2
  120. package/apps/storefront/src/lib/tot/totClientInterface.ts +3 -4
  121. package/apps/storefront/src/lib/webhooks/deliveryStore.ts +16 -17
  122. package/apps/storefront/src/middleware/index.ts +113 -2
  123. package/apps/storefront/src/pages/admin.astro +10 -1312
  124. package/apps/storefront/src/pages/api/blog/[collection]/[slug]/react.ts +104 -0
  125. package/apps/storefront/src/pages/api/newsletter/[collection]/subscribe.ts +146 -0
  126. package/apps/storefront/src/pages/api/newsletter/confirm.ts +75 -0
  127. package/apps/storefront/src/pages/api/newsletter/unsubscribe.ts +90 -0
  128. package/apps/storefront/src/pages/api/publish/stage-bundle.ts +70 -0
  129. package/apps/storefront/src/pages/api/rum/vitals.ts +21 -2
  130. package/apps/storefront/src/pages/blog/[slug].astro +96 -16
  131. package/apps/storefront/src/pages/blog/author/[author].astro +140 -0
  132. package/apps/storefront/src/pages/blog/category/[category].astro +67 -0
  133. package/apps/storefront/src/pages/blog/index.astro +2 -0
  134. package/apps/storefront/src/pages/blog/tag/[tag].astro +65 -0
  135. package/apps/storefront/src/pages/cockpit.astro +37 -12
  136. package/apps/storefront/src/pages/dashboard/[appDomain]/team.astro +15 -11
  137. package/apps/storefront/src/pages/search.astro +1 -1
  138. package/apps/storefront/src/pages/sitemap.xml.ts +20 -0
  139. package/apps/storefront/src/pages/the-build/[slug].astro +129 -0
  140. package/apps/storefront/src/pages/the-build/index.astro +146 -0
  141. package/apps/storefront/src/pages/the-build/rss.xml.ts +33 -0
  142. package/apps/storefront/src/styles/admin.css +1080 -0
  143. package/apps/storefront/tsconfig.json +5 -0
  144. package/package.json +1 -1
  145. package/packages/public-runtime/package.json +1 -0
  146. package/packages/public-runtime/src/activity/catalog.ts +52 -0
  147. package/packages/public-runtime/src/catalog-d1.ts +1 -1
  148. package/packages/public-runtime/src/customization-preview.ts +25 -2
  149. package/packages/public-runtime/src/customization-runtime.ts +125 -3
  150. package/packages/public-runtime/src/customization-versioning.ts +10 -0
  151. package/packages/public-runtime/src/index.ts +1 -0
  152. package/packages/public-runtime/src/static-bundle.ts +357 -0
  153. package/packages/public-runtime/src/tenant.ts +36 -8
  154. package/scripts/build/copy-tenant-assets.mjs +14 -4
  155. package/scripts/dev/ai-edit.mjs +1 -1
  156. package/scripts/dev/checkout-watch.mjs +2 -2
  157. package/scripts/dev/file-browser.mjs +2 -4
  158. package/scripts/dev/file-writer.mjs +1 -1
  159. package/scripts/dev/git-status.mjs +2 -2
  160. package/scripts/dev/locate-handler.mjs +3 -3
  161. package/scripts/dev/port-check.mjs +3 -3
  162. package/scripts/dev/publish.mjs +5 -9
  163. package/scripts/dev/shot.mjs +1 -1
  164. package/scripts/dev/unified-diff.mjs +8 -3
  165. package/scripts/tot-dev.mjs +6 -9
  166. package/apps/storefront/src/lib/dev/vcBinding.ts +0 -80
@@ -32,10 +32,12 @@ import { readViewerSession } from "@/lib/auth/route";
32
32
  import { withBase } from "@/lib/basePath";
33
33
  import { readEnv } from "@/lib/env";
34
34
  import { resolveViewerShipCapability } from "@/lib/change";
35
+ import { resolveLiveVersion } from "@/lib/change/liveVersion";
36
+ import { isPublicSiteCurrent } from "@/lib/change/liveDigest";
35
37
  import { isHostedStoreDomain, isInternalTestTenant } from "@tot/public-runtime";
36
38
 
37
39
  const { envelope } = Astro.props;
38
- const { tenant, basePath, cspNonce } = Astro.locals;
40
+ const { tenant, basePath } = Astro.locals;
39
41
 
40
42
  // Viewer capability, mirrored from the same session model the API routes gate
41
43
  // on (resolveOwnerSession admits capability owner|admin). UX-only: the server
@@ -78,6 +80,35 @@ const staticPublishEnabled = Boolean(
78
80
  // Presence-only signal for the T5 dispatch sink (never the value).
79
81
  const dispatchConfigured = Boolean((await readEnv("WWW_PUBLISH_DISPATCH_TOKEN"))?.trim());
80
82
 
83
+ // "What does the public site actually serve right now?" — the read-back half of
84
+ // the static-publish seam (resolveLiveVersion's staticLiveDigest), computed here
85
+ // so it's ALWAYS visible rather than only living in GET /api/changes JSON. This is
86
+ // the exact gap that let tokenoftrust.com's public site (preview.tokenoftrust.com)
87
+ // sit two days stale behind several accepted-but-unpublished changes with nothing
88
+ // in the console calling it out — going live and staying live for the PUBLIC
89
+ // static target are two different facts, and this card makes the second one
90
+ // honest instead of assumed. Best-effort: resolveLiveVersion never throws.
91
+ // BUDGETED: resolveLiveVersion chains several TENANT_CACHE reads (resolvePreviewTenant,
92
+ // resolveChannelVersion, readSiteVersion) that are pathologically slow + variable on the
93
+ // preview worker (measured 2-10s EACH, spiking together — a KV/storage-latency issue, not
94
+ // this code). It runs in blocking SSR frontmatter, so it gated the whole admin document
95
+ // stream. It's best-effort display chrome ("what does live/ serve right now"), and the
96
+ // client-side GET /api/changes already returns `current`, so cap it: on timeout the card
97
+ // renders from the client fetch instead of blocking first paint.
98
+ const liveVersion = staticPublishEnabled
99
+ ? await Promise.race([
100
+ resolveLiveVersion(tenant.appDomain),
101
+ new Promise<null>((resolve) => setTimeout(() => resolve(null), 1500)),
102
+ ])
103
+ : null;
104
+ const publicSiteDigest = liveVersion?.staticLiveDigest ?? null;
105
+ // The actual verdict: does the public target's manifest sha match what was last
106
+ // promoted to "live" here? Both are real tenant Gitea shas (dg5) — a direct,
107
+ // honest comparison, not a heuristic. See liveDigest.ts's isPublicSiteCurrent.
108
+ const publicSiteVerdict = publicSiteDigest
109
+ ? isPublicSiteCurrent(liveVersion?.versionId ?? null, publicSiteDigest)
110
+ : null;
111
+
81
112
  const changesEndpoint = withBase(basePath || "", "/api/changes");
82
113
  // b11 — the branch-integration lifecycle SPLIT of accept from publish:
83
114
  // - integrateEndpoint = b08's "accept = integrate into the protected preview
@@ -240,6 +271,59 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
240
271
  </div>
241
272
  )}
242
273
 
274
+ <!-- Public-site status — the READ-BACK half of the static-publish seam
275
+ (resolveLiveVersion's staticLiveDigest), made visible instead of only
276
+ existing in API JSON. Distinct from "Live version" above: that's the
277
+ CONTROL-PLANE record of what was promoted; this is what the external
278
+ target (CloudFront/S3) is HONESTLY observed serving right now — the two
279
+ can diverge (a stale/failed republish job) with nothing else in this
280
+ console able to tell you. Answers "did going live actually reach the
281
+ public site?" without a manual curl. -->
282
+ {staticPublishEnabled && publicSiteDigest && publicSiteVerdict && (
283
+ <div
284
+ class={`risk-alert ${publicSiteVerdict.status === "current" ? "public-site-ok" : "amber"}`}
285
+ data-publish-public-site
286
+ >
287
+ <div class="risk-alert-main">
288
+ <svg><use href={publicSiteVerdict.status === "current" ? "#i-check" : "#i-alert"}></use></svg>
289
+ <div>
290
+ {publicSiteVerdict.status === "current" ? (
291
+ <>
292
+ <b>Public site is up to date</b>
293
+ <span>
294
+ <code>{tenant.appDomain}</code>'s public target is serving the same commit
295
+ (<code class="publish-mono">{liveVersion?.versionId?.slice(0, 12)}</code>)
296
+ as the hosted store's live pointer. Publishing live above
297
+ republishes it automatically — usually within a few minutes.
298
+ </span>
299
+ </>
300
+ ) : publicSiteVerdict.status === "behind" ? (
301
+ <>
302
+ <b>Public site is behind the hosted store's live pointer</b>
303
+ <span>
304
+ <code>{tenant.appDomain}</code>'s public target is still serving{" "}
305
+ <code class="publish-mono">{publicSiteVerdict.publishedSha.slice(0, 12)}</code>, but
306
+ the hosted store's live pointer has since moved to{" "}
307
+ <code class="publish-mono">{publicSiteVerdict.livePointerSha.slice(0, 12)}</code>.
308
+ The republish job hasn't caught up yet (or a go-live happened before it was enabled) —
309
+ check the workflow run, or trigger a fresh go-live to re-dispatch it.
310
+ </span>
311
+ </>
312
+ ) : (
313
+ <>
314
+ <b>Couldn't verify the public site is current</b>
315
+ <span>
316
+ Checked <code class="publish-mono">{publicSiteDigest.url}</code>: {publicSiteVerdict.reason}.
317
+ This does NOT mean the hosted store's own "Live version" above is wrong, only that the
318
+ separate public static target couldn't be confirmed current.
319
+ </span>
320
+ </>
321
+ )}
322
+ </div>
323
+ </div>
324
+ </div>
325
+ )}
326
+
243
327
  <div class="panel">
244
328
  <div class="panel-head">
245
329
  <h3><svg><use href="#i-export"></use></svg>Candidate queue</h3>
@@ -297,7 +381,7 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
297
381
  candidates integrate into, its combined evidence (the last integration
298
382
  run's honest state), and the exact-digest Publish (b09/b10 ship the
299
383
  reviewed pinned SHA + digest, never a rebuild). -->
300
- <div class="panel" data-publish-aggregate>
384
+ <div class="panel agg-console" data-publish-aggregate>
301
385
  <div class="panel-head">
302
386
  <h3><svg><use href="#i-box"></use></svg>Preview aggregate</h3>
303
387
  <span class="chip" data-aggregate-chip>Loading</span>
@@ -305,44 +389,137 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
305
389
  <div class="panel-body grid">
306
390
  <p class="note publish-status" data-aggregate-status role="status" aria-live="polite"></p>
307
391
 
308
- <div class="grid cols-3">
309
- <div class="field">
310
- <label>Aggregate build</label>
311
- <strong class="publish-mono" data-aggregate-sha>—</strong>
312
- <p data-aggregate-run-link>The current green preview build for this store.</p>
392
+ <!-- AI-assembled release summary — a plain-language "what am I about to
393
+ publish?" ahead of the technical trust chain. Rendered ONLY when the
394
+ server supplies data.releaseSummary; otherwise it stays hidden and the
395
+ panel degrades to today's behavior (graceful fallback). -->
396
+ <div class="agg-summary" data-aggregate-summary hidden>
397
+ <div class="agg-summary-head">
398
+ <span class="agg-summary-glyph" aria-hidden="true">
399
+ <svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2l1.9 4.7L18.5 8.6l-4.6 1.9L12 15.2l-1.9-4.7L5.5 8.6l4.6-1.9L12 2z"></path><path d="M18.5 14l.9 2.2 2.3.9-2.3.9-.9 2.2-.9-2.2-2.3-.9 2.3-.9.9-2.2z"></path></svg>
400
+ </span>
401
+ <span class="agg-summary-label">What&rsquo;s in this release</span>
402
+ <span class="agg-ai-chip">
403
+ <svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 2l1.9 4.7L18.5 8.6l-4.6 1.9L12 15.2l-1.9-4.7L5.5 8.6l4.6-1.9L12 2z"></path></svg>
404
+ AI summary
405
+ </span>
406
+ </div>
407
+ <p class="agg-summary-lead" data-aggregate-summary-lead></p>
408
+ <ul class="agg-summary-points" data-aggregate-summary-points></ul>
409
+ </div>
410
+
411
+ <!-- Chain of custody: the build that was verified → its combined evidence →
412
+ the digest that ships. The reviewed digest wears an accented token so
413
+ the eye can track that exactly what was reviewed is what goes live. The
414
+ three values keep their original data hooks (sha / evidence / digest). -->
415
+ <div class="agg-chain">
416
+ <div class="agg-stop">
417
+ <span class="agg-stop-label">Aggregate build</span>
418
+ <span class="agg-stop-val"><strong class="publish-mono" data-aggregate-sha>—</strong></span>
419
+ <p class="agg-stop-cap" data-aggregate-run-link>The current green preview build for this store.</p>
420
+ </div>
421
+ <div class="agg-link" aria-hidden="true">
422
+ <span class="agg-flowlabel">verified by</span>
423
+ <span class="agg-arrow"><svg viewBox="0 0 34 10" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M1 5h29m0 0-4-4m4 4-4 4"></path></svg></span>
313
424
  </div>
314
- <div class="field">
315
- <label>Combined evidence</label>
316
- <strong data-aggregate-evidence>—</strong>
317
- <p data-aggregate-evidence-detail>The last integration run's verdict.</p>
425
+ <div class="agg-stop">
426
+ <span class="agg-stop-label">Combined evidence</span>
427
+ <span class="agg-stop-val"><strong data-aggregate-evidence>—</strong></span>
428
+ <p class="agg-stop-cap" data-aggregate-evidence-detail>The last integration run's verdict.</p>
318
429
  </div>
319
- <div class="field">
320
- <label>Reviewed digest</label>
321
- <strong class="publish-mono" data-aggregate-digest>—</strong>
322
- <p>The content digest that will be published — exactly what you reviewed.</p>
430
+ <div class="agg-link" aria-hidden="true">
431
+ <span class="agg-flowlabel">produces</span>
432
+ <span class="agg-arrow"><svg viewBox="0 0 34 10" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M1 5h29m0 0-4-4m4 4-4 4"></path></svg></span>
433
+ </div>
434
+ <div class="agg-stop">
435
+ <span class="agg-stop-label">Reviewed digest</span>
436
+ <span class="agg-stop-val"><strong class="publish-mono agg-digest" data-aggregate-digest>—</strong></span>
437
+ <p class="agg-stop-cap">The content digest that will be published — exactly what you reviewed.</p>
323
438
  </div>
324
439
  </div>
325
440
 
326
- <!-- Included PRs — the batch this aggregate composes (b01 includedPrs). -->
327
- <div class="aggregate-prs" data-aggregate-prs-wrap hidden>
328
- <b>Included changes</b>
329
- <ul class="aggregate-prs-list" data-aggregate-prs></ul>
441
+ <!-- Included PRs — the batch this aggregate composes (b01 includedPrs). u14:
442
+ the "missing middle" this is the STAGED delta vs live. The title + note
443
+ narrate how far ahead of the live site the staged preview is, and each row
444
+ carries an Undo (per-change revert) to roll the staged preview backward. -->
445
+ <div class="aggregate-prs agg-staged" data-aggregate-prs-wrap hidden>
446
+ <div class="agg-staged-head">
447
+ <b data-aggregate-prs-title>Included changes</b>
448
+ <!-- Scope-of-change risk measure across the whole staged batch (total
449
+ files + lines). Populated by renderAggregate from data.stagedScope;
450
+ hidden when no staged change carries size stats. -->
451
+ <span class="agg-scope" data-aggregate-scope hidden></span>
452
+ </div>
453
+ <!-- Staged → live delta strip: staged aggregate sha ahead of the live
454
+ pointer. Populated by renderAggregate; hidden when nothing is ahead. -->
455
+ <div class="agg-delta-strip" data-aggregate-delta-strip hidden>
456
+ <span class="agg-delta-node">
457
+ <span class="agg-stop-label">Staged preview</span>
458
+ <span class="sha-token" data-agg-delta-staged>—</span>
459
+ </span>
460
+ <span class="agg-delta-mid" aria-hidden="true">
461
+ <span class="agg-delta-count" data-agg-delta-count></span>
462
+ <svg viewBox="0 0 26 10" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M1 5h21m0 0-4-4m4 4-4 4"></path></svg>
463
+ </span>
464
+ <span class="agg-delta-node">
465
+ <span class="agg-stop-label">Live site</span>
466
+ <span class="sha-token ghost" data-agg-delta-live>—</span>
467
+ </span>
468
+ </div>
469
+ <p class="note" data-aggregate-delta-note hidden></p>
470
+ <ul class="aggregate-prs-list agg-changes" data-aggregate-prs></ul>
330
471
  </div>
331
472
 
332
473
  <!-- The exact-digest Publish plan (b09 plan()): pinned SHA + digest +
333
474
  included PRs + rollback target + paywall verdict + run link. Shown
334
475
  inline (from GET /api/changes `plan`) so the confirm never POSTs to
335
476
  preview. Publish is refused until the plan is `ok`. -->
336
- <div class="aggregate-plan" data-aggregate-plan hidden>
337
- <div class="aggregate-plan-head">
338
- <b>Publish plan</b>
477
+ <div class="aggregate-plan agg-manifest" data-aggregate-plan hidden>
478
+ <div class="aggregate-plan-head agg-manifest-head">
479
+ <b><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 11l3 3L22 4"></path><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"></path></svg>Publish plan</b>
339
480
  <span class="chip" data-aggregate-plan-chip></span>
340
481
  </div>
341
482
  <dl class="aggregate-plan-grid" data-aggregate-plan-grid></dl>
483
+
484
+ <!-- Openable "Included changes": each accepted PR as a line item with its
485
+ human title, a one-line description of what it does, and meta (sha /
486
+ files / who + when). Populated by renderPlan; degrades to a bare count
487
+ when per-change titles/descriptions aren't available. The <details>
488
+ element is static so its open/closed state survives a poll re-render —
489
+ only the list contents are replaced. -->
490
+ <div class="agg-included" data-aggregate-plan-included hidden>
491
+ <details class="agg-included-details">
492
+ <summary>
493
+ <span class="agg-included-lead">Included changes</span>
494
+ <span class="agg-included-badge" data-aggregate-plan-included-count>0</span>
495
+ <span class="agg-included-hint" data-aggregate-plan-included-hint></span>
496
+ <span class="agg-chev" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 6l6 6-6 6"></path></svg></span>
497
+ </summary>
498
+ <ul class="agg-included-list" data-aggregate-plan-included-list></ul>
499
+ </details>
500
+ </div>
501
+
342
502
  <p class="note" data-aggregate-plan-note></p>
343
503
  </div>
344
504
 
345
- <div class="check-row">
505
+ <!-- u15 — retry a DEAD rebuild (no new merge). Shown only while the aggregate
506
+ is red: a candidate's PR already merged into preview, but the
507
+ build/evidence step that follows died (e.g. a transient MCP error) — this
508
+ retries ONLY that step, against the sha the forge already carries. -->
509
+ <div class="check-row" data-aggregate-retry-row hidden>
510
+ <div>
511
+ <b>Retry the build</b>
512
+ <p>
513
+ The last merge landed on preview, but rebuilding it failed. Retry re-runs
514
+ the build + evidence check alone — no new merge, no membership change.
515
+ </p>
516
+ </div>
517
+ <button class="btn" type="button" data-aggregate-retry-build>
518
+ <svg><use href="#i-refresh"></use></svg>Retry build
519
+ </button>
520
+ </div>
521
+
522
+ <div class="check-row agg-launch">
346
523
  <div>
347
524
  <b>Publish the reviewed build to your live store</b>
348
525
  <p data-aggregate-publish-detail>
@@ -350,7 +527,7 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
350
527
  aggregate is green and its integration run passed.
351
528
  </p>
352
529
  </div>
353
- <button class="btn primary" type="button" data-aggregate-publish disabled>
530
+ <button class="btn primary agg-publish-btn" type="button" data-aggregate-publish disabled>
354
531
  <svg><use href="#i-export"></use></svg>Publish live
355
532
  </button>
356
533
  </div>
@@ -367,6 +544,11 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
367
544
  <div class="panel-body grid">
368
545
  <p class="note publish-status" data-versions-status role="status" aria-live="polite"></p>
369
546
  <p class="note" data-versions-rollback-note hidden></p>
547
+ <!-- u14: orients the owner between the staged aggregate above and live versions
548
+ below — "N staged change(s) not yet published; Publish live creates the next
549
+ version here." Owned by renderAggregate (its own element, so its timing never
550
+ races renderVersions). -->
551
+ <p class="note" data-versions-orientation hidden></p>
370
552
  <div class="table-wrap">
371
553
  <table class="publish-table versions-table">
372
554
  <thead>
@@ -411,11 +593,14 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
411
593
  closed — a different action on a different object than <b>Retire</b> in
412
594
  the queue above, which only evicts a hosted preview build (rebuildable
413
595
  on demand, never a branch). Every classification below is a fresh
414
- dry-run; deleting always re-checks eligibility on the server and asks
415
- you to confirm before removing anything. Orphan branches (no PR record
416
- at all) are quarantined for your review, never deleted automatically.
596
+ dry-run; <b>Sweep dead branches</b> lists exactly what it will delete and
597
+ asks once to confirm, then the server re-checks each ref fresh before
598
+ removing it.
417
599
  </p>
418
600
  <p class="note publish-status" data-branches-status role="status" aria-live="polite"></p>
601
+ <div class="toolbar" data-branches-actions hidden>
602
+ <button type="button" class="btn" data-branches-sweep>Sweep dead branches</button>
603
+ </div>
419
604
  <div class="table-wrap">
420
605
  <table class="publish-table">
421
606
  <thead>
@@ -588,6 +773,74 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
588
773
  <div class="liftoff-seal" data-liftoff-seal aria-hidden="true"></div>
589
774
  <h3 class="liftoff-title" data-liftoff-outcome-title></h3>
590
775
  <p class="note" data-liftoff-outcome-detail></p>
776
+ <!-- Merge-conflict recovery (shown ONLY for reason "merge_failed") — decision
777
+ `automate-first-conflict-recovery` (u4): the refusal LEADS with one primary
778
+ action ("Update this change automatically" → /resolve strategy:"merge",
779
+ then auto-re-integrate). The three option cards appear only when diff3 hits
780
+ a genuine same-line overlap (RefreshResult.unresolved); the old terminal +
781
+ AI-agent guidance is demoted VERBATIM into the collapsed "Do it manually
782
+ instead" expert section (nothing removed). Decision logic lives in the
783
+ tested `resolveConflict.ts`; this glue mirrors it (verified on preview). -->
784
+ <div class="liftoff-conflict" data-liftoff-conflict hidden>
785
+ <p class="note liftoff-conflict-summary" data-conflict-summary hidden></p>
786
+
787
+ <!-- PRIMARY ACTION — always first when a candidate is refused not-mergeable. -->
788
+ <div class="liftoff-conflict-primary" data-conflict-primary>
789
+ <p class="note" data-conflict-primary-note>
790
+ We can rebuild your change on top of the store's current version and
791
+ re-integrate it for you — no terminal, no re-submit.
792
+ </p>
793
+ <button class="btn primary" type="button" data-conflict-auto>Update this change automatically</button>
794
+ <p class="note liftoff-conflict-primary-status" data-conflict-primary-status role="status" aria-live="polite" hidden></p>
795
+ </div>
796
+
797
+ <!-- OPTION CARDS — revealed only on a genuine same-line overlap diff3 can't
798
+ safely auto-pick. Static nodes mirror CONFLICT_OPTION_CARDS. -->
799
+ <div class="liftoff-conflict-cards" data-conflict-cards hidden>
800
+ <p class="note" data-conflict-cards-intro>
801
+ Some of the same lines were changed on both sides, so there's no single safe
802
+ answer. Pick how to resolve the overlap:
803
+ </p>
804
+ <ul class="liftoff-conflict-files publish-mono" data-conflict-files></ul>
805
+ <div class="liftoff-conflict-card-grid" role="group" aria-label="Resolve the overlap">
806
+ <button class="liftoff-option-card" type="button" data-conflict-card data-strategy="merge" data-recommended="1">
807
+ <b>Combine both</b>
808
+ <span>Recommended — weave both sets of edits together</span>
809
+ </button>
810
+ <button class="liftoff-option-card" type="button" data-conflict-card data-strategy="ours">
811
+ <b>Keep my change</b>
812
+ <span>Use your edits on the conflicting lines</span>
813
+ </button>
814
+ <button class="liftoff-option-card" type="button" data-conflict-card data-strategy="theirs">
815
+ <b>Keep the store's current version</b>
816
+ <span>Use the store's edits on the conflicting lines</span>
817
+ </button>
818
+ </div>
819
+ <p class="note liftoff-conflict-cards-status" data-conflict-cards-status role="status" aria-live="polite" hidden></p>
820
+ </div>
821
+
822
+ <!-- EXPERT FALLBACK — the ORIGINAL terminal + AI-agent guidance, verbatim,
823
+ collapsed. Nothing deleted; just demoted from primary to fallback. -->
824
+ <details class="liftoff-conflict-expert" data-conflict-expert>
825
+ <summary>Do it manually instead</summary>
826
+ <p class="note" data-conflict-intro>
827
+ From the store checkout that submitted this change, bring it up to date and
828
+ re-submit — the open PR updates in place. Once the new build is ready,
829
+ finish here with <b>Integrate into preview</b>, or from the terminal with
830
+ <code>tot accept --tenant &lt;store&gt; --pr &lt;N&gt;</code>.
831
+ Check <code>git status</code> first — abort any half-finished rebase from an
832
+ earlier attempt. Then <code>tot pr</code>: this change should be marked
833
+ <code>(active)</code>, proving you're in the right checkout and branch.
834
+ If git reports an authentication failure, run <code>tot login</code> and retry.
835
+ </p>
836
+ <pre class="liftoff-commands publish-mono" data-conflict-commands></pre>
837
+ <div class="liftoff-conflict-actions">
838
+ <button class="btn" type="button" data-conflict-copy-prompt>Copy prompt for your AI agent</button>
839
+ <button class="btn" type="button" data-conflict-copy>Copy commands</button>
840
+ </div>
841
+ <p class="liftoff-conflict-raw publish-mono" data-conflict-raw></p>
842
+ </details>
843
+ </div>
591
844
  <div class="liftoff-actions">
592
845
  <a class="btn" data-liftoff-review target="_blank" rel="noopener" hidden>Review the preview build</a>
593
846
  <button class="btn primary" type="button" data-liftoff-done>Done</button>
@@ -648,2310 +901,9 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
648
901
  </div>
649
902
  </section>
650
903
 
651
- <script is:inline nonce={cspNonce}>
652
- (() => {
653
- const root = document.getElementById("publish");
654
- if (!root) return;
655
- const ds = root.dataset;
656
- const canShip = ds.canShip === "true";
657
- const repo = ds.repo || "";
658
- const appDomain = ds.appDomain || "";
659
-
660
- const statusEl = root.querySelector("[data-publish-status]");
661
- const queueBody = root.querySelector("[data-publish-queue-body]");
662
- const queueChip = root.querySelector("[data-publish-queue-chip]");
663
- const queueCount = root.querySelector("[data-publish-queue-count]");
664
- const degradedStrip = root.querySelector("[data-publish-degraded]");
665
-
666
- // rux7 — in-flight UI state the auto-refresh poll must preserve across a
667
- // re-render. These are the AUTHORITATIVE source of truth (never scraped
668
- // back out of the DOM): an action's async closure holds a reference to the
669
- // OLD button, so after a poll swaps the row the completion signal lands on a
670
- // detached node — reading `disabled`/`data-building` off the fresh DOM would
671
- // wedge forever. buildPreview/integrate/reject/retire add on start and
672
- // delete in `finally` (before their own loadQueue), so the next render
673
- // reflects the true busy set. Open diff panes are the exception: the DOM IS
674
- // their source of truth (toggleDiff owns open/close), so renderQueue detaches
675
- // and re-attaches the actual pane node — see renderQueue.
676
- const inflightBuilds = new Set(); // prNumber currently building
677
- const busyChanges = new Set(); // changeId with an in-flight integrate/reject/retire
678
- let aggregatePublishing = false; // the aggregate Publish POST is in flight
679
-
680
- const setStatus = (el, message, state) => {
681
- if (!el) return;
682
- el.textContent = message || "";
683
- if (state) el.dataset.state = state;
684
- else delete el.dataset.state;
685
- };
686
-
687
- const shortSha = (sha) => (sha ? String(sha).slice(0, 8) : "—");
688
-
689
- // Inline mirror of `candidatePrUrl` (lib/preview/candidateDashboard.ts) — an
690
- // is:inline script can't import a module, so the pure URL shape is mirrored
691
- // here (same pattern as `shortSha`). The friendly `/preview/<tenant>/pr/<N>`
692
- // route handles every state (ready, not-built, …), so a row with a PR number
693
- // always has a working preview link even when `previewUrl` is still null.
694
- const candidatePrUrl = (prNumber) =>
695
- prNumber != null ? "/preview/" + encodeURIComponent(appDomain) + "/pr/" + prNumber : null;
696
-
697
- const age = (iso) => {
698
- if (!iso) return "—";
699
- const ms = Date.now() - new Date(iso).getTime();
700
- if (!Number.isFinite(ms) || ms < 0) return "—";
701
- const mins = Math.floor(ms / 60000);
702
- if (mins < 1) return "just now";
703
- if (mins < 60) return mins + "m ago";
704
- const hours = Math.floor(mins / 60);
705
- if (hours < 48) return hours + "h ago";
706
- return Math.floor(hours / 24) + "d ago";
707
- };
708
-
709
- const STATUS_CHIP = {
710
- queued: "",
711
- reconciling: "blue",
712
- ready: "green",
713
- blocked: "red",
714
- };
715
-
716
- const chip = (text, tone) => {
717
- const el = document.createElement("span");
718
- el.className = "chip" + (tone ? " " + tone : "");
719
- el.textContent = text;
720
- return el;
721
- };
722
-
723
- const cell = (...children) => {
724
- const td = document.createElement("td");
725
- for (const child of children) {
726
- if (child == null) continue;
727
- td.append(typeof child === "string" ? document.createTextNode(child) : child);
728
- }
729
- return td;
730
- };
731
-
732
- const subtle = (text) => {
733
- const el = document.createElement("span");
734
- el.className = "subtle";
735
- el.textContent = text;
736
- return el;
737
- };
738
-
739
- // ---- ?pr=N deep link ---------------------------------------------------
740
- // A deep link like /admin#publish?pr=42 asks us to surface a specific PR's
741
- // row once the queue has loaded. The param rides in the hash fragment
742
- // (after the tab anchor) because that's how the admin shell routes tabs;
743
- // fall back to a real query string too. Resolve exactly once — so the
744
- // scroll/highlight never re-fires on the reloads that follow every ship
745
- // action — and until it resolves, keep an honest "not in the queue yet"
746
- // callout up rather than silently doing nothing.
747
-
748
- const readRequestedPr = () => {
749
- const hash = window.location.hash || "";
750
- const q = hash.indexOf("?");
751
- let raw = new URLSearchParams(q >= 0 ? hash.slice(q + 1) : "").get("pr");
752
- if (raw == null) raw = new URLSearchParams(window.location.search).get("pr");
753
- if (raw == null) return null;
754
- const n = Number.parseInt(raw, 10);
755
- return Number.isInteger(n) && n > 0 ? n : null;
756
- };
757
-
758
- const requestedPr = readRequestedPr();
759
- let prDeeplinkResolved = false;
760
-
761
- const applyPrDeeplink = () => {
762
- if (requestedPr == null || prDeeplinkResolved) return;
763
- const callout = root.querySelector("[data-publish-pr-callout]");
764
- const row = queueBody.querySelector('tr[data-pr-number="' + requestedPr + '"]');
765
- if (!row) {
766
- if (callout) {
767
- callout.hidden = false;
768
- callout.textContent = "PR #" + requestedPr + " isn't in the queue yet.";
769
- }
770
- return;
771
- }
772
- prDeeplinkResolved = true;
773
- if (callout) {
774
- callout.hidden = true;
775
- callout.textContent = "";
776
- }
777
- row.scrollIntoView({ block: "center", behavior: "smooth" });
778
- row.classList.remove("publish-row-highlight");
779
- void row.offsetWidth; // restart the flash animation if re-applied
780
- row.classList.add("publish-row-highlight");
781
- window.setTimeout(() => row.classList.remove("publish-row-highlight"), 2600);
782
- };
783
-
784
- // ---- Open change queue -------------------------------------------------
785
-
786
- const renderQueue = (payload) => {
787
- const changes = Array.isArray(payload.changes) ? payload.changes : [];
788
- // rux1: surface a forge-listing failure as a visible strip — never let a
789
- // degraded (short) list read as a genuine empty queue.
790
- if (degradedStrip) degradedStrip.hidden = payload.degraded !== true;
791
- // rux7: capture any open diff panes BEFORE wiping so a poll re-render
792
- // re-attaches the exact node (with its already-fetched content) under the
793
- // matching new row, instead of blowing the expanded pane away. Keyed by
794
- // changeId (== the diff row's data-publish-diff-row). Wiping detaches them
795
- // from the DOM but the Map keeps them alive for re-attachment.
796
- const openDiffNodes = new Map();
797
- queueBody.querySelectorAll("tr[data-publish-diff-row]").forEach((node) => {
798
- openDiffNodes.set(node.dataset.publishDiffRow, node);
799
- });
800
- queueBody.textContent = "";
801
- if (queueCount) queueCount.textContent = String(changes.length);
802
- if (queueChip) {
803
- queueChip.textContent = changes.length === 1 ? "1 open" : changes.length + " open";
804
- queueChip.className = "chip" + (changes.length ? " blue" : "");
805
- }
806
-
807
- if (!changes.length) {
808
- const tr = document.createElement("tr");
809
- const td = cell(
810
- subtle(
811
- "No open changes. New store changes appear here when a developer submits them for review.",
812
- ),
813
- );
814
- td.colSpan = 6;
815
- tr.append(td);
816
- queueBody.append(tr);
817
- return;
818
- }
819
-
820
- for (const change of changes) {
821
- const tr = document.createElement("tr");
822
- if (change.prNumber != null) tr.dataset.prNumber = String(change.prNumber);
823
-
824
- // Change id + branch / PR + preview link.
825
- const idCell = document.createElement("td");
826
- const idStrong = document.createElement("strong");
827
- idStrong.textContent = change.changeId || "—";
828
- idCell.append(idStrong);
829
- const meta = [];
830
- if (change.branch) meta.push(change.branch);
831
- if (change.prNumber != null) meta.push("PR #" + change.prNumber);
832
- if (meta.length) idCell.append(subtle(meta.join(" · ")));
833
- // Owner-facing "who did this" — accept takes priority over build (a
834
- // candidate that's been accepted-to-preview is more meaningfully
835
- // "acted on" than merely built). Reject never shows here: a rejected
836
- // candidate is closed and has already left the open queue.
837
- const actorRecord = change.actors && (change.actors.accept || change.actors.build);
838
- if (actorRecord) {
839
- const label = change.actors.accept ? "Accepted by " : "Built by ";
840
- idCell.append(subtle(label + (actorRecord.name || actorRecord.email)));
841
- }
842
- // Prefer the synthesized friendly per-PR route (handles every state);
843
- // fall back to any server-provided previewUrl for change-first rows
844
- // that have no PR number yet.
845
- const previewUrl = candidatePrUrl(change.prNumber) || change.previewUrl;
846
- if (previewUrl) {
847
- const preview = document.createElement("a");
848
- preview.href = previewUrl;
849
- preview.target = "_blank";
850
- preview.rel = "noopener";
851
- preview.textContent = "Open preview";
852
- const wrap = document.createElement("span");
853
- wrap.className = "subtle";
854
- wrap.append(preview);
855
- idCell.append(wrap);
856
- }
857
- tr.append(idCell);
858
-
859
- // Reconcile status.
860
- const statusCell = cell(
861
- chip(change.status || "unknown", STATUS_CHIP[change.status] ?? "amber"),
862
- );
863
- if (change.lastError) statusCell.append(subtle(change.lastError));
864
- tr.append(statusCell);
865
-
866
- // Evidence / compliance verdict.
867
- const checks = (change.evidence && change.evidence.checks) || [];
868
- const failing = checks.filter((c) => c.status === "fail");
869
- const promotable = Boolean(change.evidence && change.evidence.promotable);
870
- const checksCell = cell(
871
- promotable ? chip("Checks passed", "green") : chip("Checks blocked", "amber"),
872
- );
873
- if (failing.length) {
874
- checksCell.append(subtle("Failing: " + failing.map((c) => c.label || c.id).join(", ")));
875
- } else if (!checks.length) {
876
- checksCell.append(subtle("No checks reported yet"));
877
- }
878
- tr.append(checksCell);
879
-
880
- // Head sha + age.
881
- const headCell = cell(shortSha(change.headSha));
882
- headCell.classList.add("publish-mono");
883
- tr.append(headCell);
884
- tr.append(cell(age(change.updatedAt)));
885
-
886
- // Actions.
887
- const actions = document.createElement("td");
888
- actions.className = "action publish-actions";
889
-
890
- // rux5 — a synthetic not-built forge PR row (built:false / status
891
- // "not-built") has NO built candidate: changeId is null, so the built-only
892
- // actions below (Diff/Accept/Reject/Retire, all keyed on changeId) do not
893
- // apply. Its one action is Build preview — materialize the PR's hosted
894
- // preview on demand. Capability-gated: the button is SHOWN only to a
895
- // ship-capable operator, and the server (buildGate) re-authorizes — the UI
896
- // check is UX, not the real gate.
897
- if (change.built === false || change.status === "not-built") {
898
- if (canShip) {
899
- const build = document.createElement("button");
900
- build.type = "button";
901
- build.className = "btn primary";
902
- build.title = "Materialize this PR's hosted preview on demand (does not go live)";
903
- // rux7: if a build for this PR is mid-flight, a poll re-render must
904
- // reflect the spinner/disabled state (not a fresh clickable button
905
- // that would let the operator double-submit). The in-flight closure
906
- // re-renders on completion, clearing this.
907
- if (change.prNumber != null && inflightBuilds.has(change.prNumber)) {
908
- build.textContent = "Building…";
909
- build.disabled = true;
910
- build.dataset.building = "true";
911
- } else {
912
- build.textContent = "Build preview";
913
- }
914
- build.addEventListener("click", () => buildPreview(change, build));
915
- actions.append(build);
916
- } else {
917
- actions.append(subtle("Owner/admin sign-in required to build"));
918
- }
919
- tr.append(actions);
920
- queueBody.append(tr);
921
- continue;
922
- }
923
-
924
- // rux7: while an integrate/reject/retire for this change is in flight,
925
- // keep its mutating actions disabled across a poll re-render so the
926
- // operator can't double-submit against a freshly-minted button.
927
- const changeBusy = busyChanges.has(change.changeId);
928
-
929
- // rux6 Review: expand the row into a single "review moment" pane —
930
- // preview iframe + evidence chips + diff + Accept/Reject — so a reviewer
931
- // never leaves the queue. Supersedes the standalone Diff button (the dg7
932
- // diff now lives inside the pane, reusing renderDiff). The row's own
933
- // Accept/Reject/Retire buttons below are unchanged.
934
- const reviewBtn = document.createElement("button");
935
- reviewBtn.type = "button";
936
- reviewBtn.className = "btn";
937
- reviewBtn.textContent = "Review";
938
- reviewBtn.setAttribute("aria-expanded", "false");
939
- reviewBtn.title = "Open one pane to preview, diff, and act on this change";
940
- reviewBtn.addEventListener("click", () => toggleReview(change, reviewBtn, tr));
941
- actions.append(reviewBtn);
942
- // b11 SPLIT: the candidate-queue primary action is now ACCEPT TO PREVIEW
943
- // (b08 integrate = advance the shared preview aggregate), NOT go-live.
944
- // Integrate flips NO live channel, so it has NO paywall (entitled) gate —
945
- // it holds only the ship-on-behalf capability floor. Going live is the
946
- // aggregate card's Publish action, once the aggregate is green.
947
- const accept = document.createElement("button");
948
- accept.type = "button";
949
- accept.className = "btn primary";
950
- accept.textContent = "Accept to preview";
951
- accept.disabled = !canShip || !change.mergeable || changeBusy;
952
- accept.title = !canShip
953
- ? "Requires an owner or admin sign-in"
954
- : !change.mergeable
955
- ? "This change is not ready to integrate"
956
- : "Integrate this change into the preview aggregate (does not go live)";
957
- accept.addEventListener("click", () => integrateCandidate(change, accept));
958
- actions.append(accept);
959
- const reject = document.createElement("button");
960
- reject.type = "button";
961
- reject.className = "btn";
962
- reject.textContent = "Reject";
963
- reject.disabled = !canShip || changeBusy;
964
- reject.title = canShip ? "Close this change without publishing" : "Requires an owner or admin sign-in";
965
- reject.addEventListener("click", () => rejectChange(change, reject));
966
- actions.append(reject);
967
-
968
- // U7 Retire/GC: evict this candidate's preview environment + version to
969
- // reclaim space. DISTINCT from Reject — retire is reversible-by-rebuild
970
- // (U1 build-on-demand + the U2 fallback page rematerialize it), so a
971
- // retired PR degrades to "not built yet", not a dead 404.
972
- const retire = document.createElement("button");
973
- retire.type = "button";
974
- retire.className = "btn";
975
- retire.textContent = "Retire";
976
- retire.disabled = !canShip || changeBusy;
977
- retire.title = canShip
978
- ? "Evict this preview to reclaim space — rebuildable on demand (not the same as Reject)"
979
- : "Requires an owner or admin sign-in";
980
- retire.addEventListener("click", () => retireChange(change, retire));
981
- actions.append(retire);
982
- tr.append(actions);
983
-
984
- queueBody.append(tr);
985
-
986
- // rux7: re-attach a diff pane that was open before this re-render. The
987
- // pane node carries its already-fetched content; restore the expanded
988
- // state + the "Hide diff" toggle affordance so a poll never collapses it.
989
- const openDiff = openDiffNodes.get(change.changeId);
990
- if (openDiff) {
991
- tr.dataset.changeRowId = change.changeId;
992
- diffBtn.textContent = "Hide diff";
993
- tr.after(openDiff);
994
- }
995
- }
996
- };
997
-
998
- const renderCurrent = (current, shippedBy) => {
999
- const versionEl = root.querySelector("[data-publish-live-version]");
1000
- const sourceEl = root.querySelector("[data-publish-live-source]");
1001
- const atEl = root.querySelector("[data-publish-live-at]");
1002
- const shippedByEl = root.querySelector("[data-publish-live-shipped-by]");
1003
- if (current && current.versionId) {
1004
- if (versionEl) versionEl.textContent = shortSha(current.versionId);
1005
- if (sourceEl) {
1006
- sourceEl.textContent =
1007
- (current.source === "commit" ? "Published from a change" : "Published version") +
1008
- (current.artifactCount != null ? " · " + current.artifactCount + " files" : "");
1009
- }
1010
- if (atEl) atEl.textContent = current.createdAt ? age(current.createdAt) : "—";
1011
- // Owner-facing "who did this" — see changeActorAttribution.ts. Absent for
1012
- // any version published before this attribution existed, which is honest,
1013
- // not a bug.
1014
- if (shippedByEl) {
1015
- shippedByEl.textContent = shippedBy ? "Shipped by " + (shippedBy.name || shippedBy.email) : "";
1016
- }
1017
- } else {
1018
- if (versionEl) versionEl.textContent = "Not live yet";
1019
- if (sourceEl) sourceEl.textContent = "Nothing has been published for this store";
1020
- if (atEl) atEl.textContent = "—";
1021
- if (shippedByEl) shippedByEl.textContent = "";
1022
- }
1023
- };
1024
-
1025
- // ---- rux7: auto-refresh (poll GET /api/changes) ------------------------
1026
- // Keep the queue + aggregate live without a manual reload: poll on an
1027
- // interval that BACKS OFF while nothing changes (grow the delay up to a cap)
1028
- // and SNAPS BACK to the base the moment something does. Pause entirely while
1029
- // the tab is hidden (document.hidden) — a backgrounded admin tab must not
1030
- // hammer the endpoint — and refresh promptly on return. A poll re-render
1031
- // reuses renderQueue/renderAggregate, which already preserve open diff panes
1032
- // and in-flight actions (inflightBuilds / busyChanges / aggregatePublishing),
1033
- // and applyPrDeeplink stays a one-time effect (prDeeplinkResolved), so the
1034
- // ?pr scroll never re-fires on a tick.
1035
- const POLL_BASE_MS = 8000;
1036
- const POLL_MAX_MS = 60000;
1037
- const POLL_GROWTH = 1.6;
1038
- let pollDelay = POLL_BASE_MS;
1039
- let pollTimer = null;
1040
- let pollBusy = false;
1041
- let lastChangesSignature = null;
1042
-
1043
- // A compact projection of everything the queue/aggregate render VISIBLY off,
1044
- // so a no-op poll (identical data) neither re-renders nor interrupts a text
1045
- // selection — it just backs off. Relative ages are intentionally excluded;
1046
- // they drift at most one backoff interval and refresh on any real change.
1047
- const changesSignature = (data) => {
1048
- const cur = data.current || {};
1049
- const agg = data.aggregate || {};
1050
- const run = agg.activeRun || agg.lastRun || {};
1051
- const plan = data.plan || {};
1052
- const rows = (Array.isArray(data.changes) ? data.changes : []).map((c) => [
1053
- c.changeId,
1054
- c.prNumber,
1055
- c.status,
1056
- c.headSha,
1057
- c.mergeable,
1058
- c.built,
1059
- c.lastError || null,
1060
- !!(c.evidence && c.evidence.promotable),
1061
- c.actors ? Object.keys(c.actors).sort().join(",") : "",
1062
- ]);
1063
- return JSON.stringify({
1064
- degraded: data.degraded === true,
1065
- current: [cur.versionId || null, cur.createdAt || null, cur.artifactCount ?? null],
1066
- shippedBy: (data.shippedBy && data.shippedBy.email) || null,
1067
- aggregate: [
1068
- agg.queueState || null,
1069
- agg.aggregateSha || null,
1070
- run.state || null,
1071
- run.finishedAt || null,
1072
- (agg.includedPrs || []).length,
1073
- ],
1074
- plan: [plan.ok === true, plan.pinnedSha || null, plan.artifactDigest || null, plan.alreadyShipped === true],
1075
- rows,
1076
- });
1077
- };
1078
-
1079
- const clearPoll = () => {
1080
- if (pollTimer) {
1081
- clearTimeout(pollTimer);
1082
- pollTimer = null;
1083
- }
1084
- };
1085
-
1086
- const schedulePoll = () => {
1087
- clearPoll();
1088
- if (document.hidden) return; // paused while hidden; visibilitychange resumes
1089
- pollTimer = setTimeout(runPoll, pollDelay);
1090
- };
1091
-
1092
- // One poll tick: fetch, and only re-render when the projection actually
1093
- // changed. Returns an outcome the caller uses to size the next interval.
1094
- const pollChanges = async () => {
1095
- let res;
1096
- try {
1097
- res = await fetch(ds.changesEndpoint, { headers: { accept: "application/json" } });
1098
- } catch {
1099
- return "error"; // network blip — keep the last good view, just back off
1100
- }
1101
- if (res.status === 401 || res.status === 403) return "auth"; // session gone
1102
- const data = await res.json().catch(() => null);
1103
- if (!res.ok || !data) return "error";
1104
- const sig = changesSignature(data);
1105
- if (sig === lastChangesSignature) return "unchanged";
1106
- lastChangesSignature = sig;
1107
- renderCurrent(data.current, data.shippedBy);
1108
- renderQueue(data);
1109
- applyPrDeeplink();
1110
- renderAggregate(data);
1111
- return "changed";
1112
- };
1113
-
1114
- const runPoll = async () => {
1115
- pollTimer = null;
1116
- if (document.hidden || pollBusy) {
1117
- schedulePoll();
1118
- return;
1119
- }
1120
- pollBusy = true;
1121
- let outcome;
1122
- try {
1123
- outcome = await pollChanges();
1124
- } finally {
1125
- pollBusy = false;
1126
- }
1127
- if (outcome === "auth") {
1128
- clearPoll(); // stop polling — a sign-in is required; a manual refresh retries
1129
- return;
1130
- }
1131
- pollDelay =
1132
- outcome === "changed"
1133
- ? POLL_BASE_MS
1134
- : Math.min(POLL_MAX_MS, Math.round(pollDelay * POLL_GROWTH));
1135
- schedulePoll();
1136
- };
1137
-
1138
- const loadQueue = async () => {
1139
- try {
1140
- const res = await fetch(ds.changesEndpoint, { headers: { accept: "application/json" } });
1141
- if (res.status === 401 || res.status === 403) {
1142
- if (queueChip) queueChip.textContent = "Sign-in required";
1143
- if (degradedStrip) degradedStrip.hidden = true;
1144
- queueBody.textContent = "";
1145
- const tr = document.createElement("tr");
1146
- const td = cell(subtle("Sign in as a store owner or admin to view the publish queue."));
1147
- td.colSpan = 6;
1148
- tr.append(td);
1149
- queueBody.append(tr);
1150
- return;
1151
- }
1152
- const data = await res.json();
1153
- if (!res.ok) {
1154
- setStatus(statusEl, data.error || "Could not load the change queue (" + res.status + ")", "err");
1155
- return;
1156
- }
1157
- renderCurrent(data.current, data.shippedBy);
1158
- renderQueue(data);
1159
- applyPrDeeplink();
1160
- renderAggregate(data);
1161
- // rux7: this is fresh authoritative data — resync the poll clock so the
1162
- // next tick dedupes against it, and reset the cadence to responsive
1163
- // (a manual refresh / a just-completed action likely means more coming).
1164
- lastChangesSignature = changesSignature(data);
1165
- pollDelay = POLL_BASE_MS;
1166
- schedulePoll();
1167
- } catch {
1168
- setStatus(statusEl, "Could not load the change queue — network error", "err");
1169
- }
1170
- };
1171
-
1172
- // ---- b11: the aggregate card + exact-digest Publish ---------------------
1173
- // Reads the aggregate/runs/plan projection GET /api/changes now returns
1174
- // (AggregateCardView + AggregateShipPlanView, built by aggregateView.ts):
1175
- // - the aggregate's queueState + build sha + reviewed digest,
1176
- // - the COMBINED EVIDENCE = the last integration run's honest state +
1177
- // statusMessage (never re-derived),
1178
- // - the included-PR batch,
1179
- // - the b09 ship PLAN (pinned SHA/digest/PRs/rollback/paywall + run link),
1180
- // shown inline so the confirm never has to POST to preview it.
1181
-
1182
- const aggPanel = root.querySelector("[data-publish-aggregate]");
1183
- const AGG_STATE_CHIP = {
1184
- empty: "",
1185
- queued: "amber",
1186
- integrating: "blue",
1187
- green: "green",
1188
- red: "red",
1189
- shipped: "green",
1190
- };
1191
- // The plan we last rendered — the exact-digest guard the Publish POST sends
1192
- // back so a stale plan (queue moved / artifact changed) is refused, never
1193
- // shipped blind.
1194
- let currentPlan = null;
1195
-
1196
- const runLink = (revHref, label) => {
1197
- if (!revHref) return null;
1198
- const a = document.createElement("a");
1199
- a.href = revHref;
1200
- a.target = "_blank";
1201
- a.rel = "noopener";
1202
- a.textContent = label || "Open build";
1203
- return a;
1204
- };
1205
-
1206
- const renderAggregate = (data) => {
1207
- if (!aggPanel) return;
1208
- const agg = data.aggregate || null;
1209
- const plan = data.plan || null;
1210
- currentPlan = plan && plan.ok ? plan : null;
1211
-
1212
- const chipEl = aggPanel.querySelector("[data-aggregate-chip]");
1213
- const shaEl = aggPanel.querySelector("[data-aggregate-sha]");
1214
- const runLinkEl = aggPanel.querySelector("[data-aggregate-run-link]");
1215
- const evEl = aggPanel.querySelector("[data-aggregate-evidence]");
1216
- const evDetailEl = aggPanel.querySelector("[data-aggregate-evidence-detail]");
1217
- const digestEl = aggPanel.querySelector("[data-aggregate-digest]");
1218
- const prsWrap = aggPanel.querySelector("[data-aggregate-prs-wrap]");
1219
- const prsList = aggPanel.querySelector("[data-aggregate-prs]");
1220
- const publishBtn = aggPanel.querySelector("[data-aggregate-publish]");
1221
- const publishDetail = aggPanel.querySelector("[data-aggregate-publish-detail]");
1222
-
1223
- const state = (agg && agg.queueState) || "empty";
1224
- if (chipEl) {
1225
- chipEl.textContent = state;
1226
- chipEl.className = "chip " + (AGG_STATE_CHIP[state] || "");
1227
- }
1228
- if (shaEl) shaEl.textContent = agg && agg.aggregateSha ? shortSha(agg.aggregateSha) : "—";
1229
- if (runLinkEl) {
1230
- runLinkEl.textContent = "";
1231
- const link = agg && runLink(agg.revHref, "Open build");
1232
- if (link) runLinkEl.append(link);
1233
- else runLinkEl.append(document.createTextNode("The current green preview build for this store."));
1234
- }
1235
-
1236
- // Combined evidence = the last (or in-flight) integration run's honest state.
1237
- const lastRun = agg && (agg.activeRun || agg.lastRun);
1238
- if (evEl) {
1239
- if (!lastRun) {
1240
- evEl.textContent = "No runs yet";
1241
- } else if (lastRun.state === "passed") {
1242
- evEl.textContent = "Passed";
1243
- } else if (lastRun.state === "failed") {
1244
- evEl.textContent = "Failed";
1245
- } else {
1246
- evEl.textContent = "Integrating…";
1247
- }
1248
- }
1249
- if (evDetailEl) {
1250
- evDetailEl.textContent = "";
1251
- if (lastRun) {
1252
- const parts = [];
1253
- if (lastRun.statusMessage) parts.push(lastRun.statusMessage);
1254
- else if (lastRun.state === "passed") parts.push("Combined evidence passed.");
1255
- else if (lastRun.state === "failed") parts.push("Combined evidence did not pass.");
1256
- if (lastRun.finishedAt) parts.push(age(lastRun.finishedAt));
1257
- evDetailEl.append(document.createTextNode(parts.join(" · ")));
1258
- const rl = runLink(lastRun.revHref, "Run build");
1259
- if (rl) {
1260
- evDetailEl.append(document.createTextNode(" · "));
1261
- evDetailEl.append(rl);
1262
- }
1263
- } else {
1264
- evDetailEl.append(document.createTextNode("The last integration run's verdict."));
1265
- }
1266
- }
1267
-
1268
- // Reviewed digest: only known once the plan pins it (b09). Never fabricated.
1269
- if (digestEl) {
1270
- digestEl.textContent = currentPlan ? shortSha(currentPlan.artifactDigest.replace(/^sha256:/, "")) : "—";
1271
- }
1272
-
1273
- // Included PRs.
1274
- const prs = (agg && agg.includedPrs) || [];
1275
- if (prsWrap) prsWrap.hidden = prs.length === 0;
1276
- if (prsList) {
1277
- prsList.textContent = "";
1278
- for (const pr of prs) {
1279
- const li = document.createElement("li");
1280
- const label = document.createElement("span");
1281
- label.textContent = pr.prNumber != null ? "PR #" + pr.prNumber : pr.changeId;
1282
- const sha = document.createElement("span");
1283
- sha.className = "publish-mono subtle";
1284
- sha.textContent = shortSha(pr.headSha);
1285
- li.append(label, sha);
1286
- prsList.append(li);
1287
- }
1288
- }
1289
-
1290
- renderPlan(data.plan);
1291
-
1292
- // The Publish button: enabled only for a shippable, paywall-cleared plan and
1293
- // a viewer who can ship. A paywalled plan is SHOWN (upsell), never hidden.
1294
- if (publishBtn) {
1295
- const shippable = Boolean(currentPlan);
1296
- const paywalled = currentPlan && currentPlan.paywall && !currentPlan.paywall.allowed;
1297
- // rux7: never re-enable the Publish button while its POST is in flight —
1298
- // a poll refresh landing mid-publish must not open a double-submit.
1299
- publishBtn.disabled =
1300
- aggregatePublishing || !canShip || !shippable || paywalled || currentPlan.alreadyShipped;
1301
- publishBtn.title = !canShip
1302
- ? "Requires an owner or admin sign-in"
1303
- : !shippable
1304
- ? "The aggregate is not green / has no passed run to publish yet"
1305
- : paywalled
1306
- ? "Publishing to your live store is part of the paid plan"
1307
- : currentPlan.alreadyShipped
1308
- ? "This reviewed build is already live"
1309
- : "Publish the exact reviewed digest to your live store";
1310
- }
1311
- if (publishDetail) {
1312
- if (currentPlan && currentPlan.alreadyShipped) {
1313
- publishDetail.textContent =
1314
- "This reviewed build (" + shortSha(currentPlan.pinnedSha) + ") is already live. ";
1315
- const view = document.createElement("a");
1316
- view.href = ds.liveHref || "/";
1317
- view.target = "_blank";
1318
- view.rel = "noopener";
1319
- view.textContent = "View your live store →";
1320
- publishDetail.append(view);
1321
- } else if (currentPlan) {
1322
- publishDetail.textContent =
1323
- "Publishes the exact reviewed digest " + shortSha(currentPlan.artifactDigest.replace(/^sha256:/, "")) +
1324
- " (build " + shortSha(currentPlan.pinnedSha) + ") — no rebuild.";
1325
- } else {
1326
- publishDetail.textContent =
1327
- "Publishes the exact reviewed digest — no rebuild. Available once the aggregate is green and its integration run passed.";
1328
- }
1329
- }
1330
- };
1331
-
1332
- const renderPlan = (plan) => {
1333
- const planBox = aggPanel && aggPanel.querySelector("[data-aggregate-plan]");
1334
- if (!planBox) return;
1335
- const chipEl = planBox.querySelector("[data-aggregate-plan-chip]");
1336
- const grid = planBox.querySelector("[data-aggregate-plan-grid]");
1337
- const note = planBox.querySelector("[data-aggregate-plan-note]");
1338
- if (grid) grid.textContent = "";
1339
-
1340
- // No plan at all (degenerate: no store bound) — hide the box.
1341
- if (!plan) {
1342
- planBox.hidden = true;
1343
- return;
1344
- }
1345
- planBox.hidden = false;
1346
-
1347
- if (!plan.ok) {
1348
- // An honest refusal — show WHY it isn't shippable, never a fake plan.
1349
- if (chipEl) {
1350
- chipEl.textContent = "Not shippable";
1351
- chipEl.className = "chip amber";
1352
- }
1353
- if (note) note.textContent = plan.message || ("Not shippable (" + (plan.reason || "refused") + ").");
1354
- return;
1355
- }
1356
-
1357
- const paywalled = plan.paywall && !plan.paywall.allowed;
1358
- if (chipEl) {
1359
- chipEl.textContent = plan.alreadyShipped ? "Already live" : paywalled ? "Upgrade required" : "Ready to publish";
1360
- chipEl.className = "chip " + (plan.alreadyShipped ? "green" : paywalled ? "amber" : "green");
1361
- }
1362
-
1363
- const row = (term, value, mono) => {
1364
- const dt = document.createElement("dt");
1365
- dt.textContent = term;
1366
- const dd = document.createElement("dd");
1367
- if (value instanceof Node) dd.append(value);
1368
- else {
1369
- dd.textContent = value;
1370
- if (mono) dd.className = "publish-mono";
1371
- }
1372
- grid.append(dt, dd);
1373
- };
1374
-
1375
- row("Reviewed build", shortSha(plan.pinnedSha), true);
1376
- row("Reviewed digest", shortSha(plan.artifactDigest.replace(/^sha256:/, "")), true);
1377
- row("Included changes", String((plan.includedPrs || []).length) + " change" + ((plan.includedPrs || []).length === 1 ? "" : "s"));
1378
- const runCell = document.createElement("span");
1379
- runCell.append(document.createTextNode(plan.integrationRunId));
1380
- const planRunLink = runLink(plan.pinnedRevHref, "Open build");
1381
- if (planRunLink) {
1382
- runCell.append(document.createTextNode(" · "));
1383
- runCell.append(planRunLink);
1384
- }
1385
- row("Integration run", runCell);
1386
- if (plan.rollbackTarget) {
1387
- row("Rollback to", shortSha(plan.rollbackTarget.aggregateSha), true);
1388
- } else {
1389
- row("Rollback to", "None (first publish)");
1390
- }
1391
- row("Subscription", plan.paywall && plan.paywall.allowed ? "Enabled" : "Not enabled");
1392
-
1393
- if (note) {
1394
- note.textContent = paywalled
1395
- ? (plan.paywall.message || "Publishing to your live store requires the paid plan.")
1396
- : plan.alreadyShipped
1397
- ? "This reviewed build is already live — nothing to publish."
1398
- : "Publish sends the exact reviewed digest above to your live store. No rebuild.";
1399
- }
1400
- };
1401
-
1402
- // The exact-digest Publish (b10 ship = b09 orchestrator.ship). Confirms the
1403
- // pinned plan, then POSTs { confirmGoLive, expectedAggregateSha,
1404
- // expectedArtifactDigest } — the reviewed-digest guard: a stale plan (queue
1405
- // moved / artifact changed) is refused by the server, never shipped blind.
1406
- // ── Publish-live ceremony (shipoff) ──────────────────────────────────────
1407
- // The go-live counterpart of the accept liftoff below (shares its shell,
1408
- // styles, planRow + celebrate helpers — referenced at runtime, defined a few
1409
- // sections down). One honest in-flight state: ship is a single POST that
1410
- // promotes the pinned digest, so no staged theater — just plan → publishing →
1411
- // outcome with a real "View your live store" link.
1412
- const shipoff = root.querySelector("[data-shipoff]");
1413
- const shipoffCard = shipoff && shipoff.querySelector(".liftoff-card");
1414
- const shipoffEls = shipoff
1415
- ? {
1416
- plan: shipoff.querySelector("[data-shipoff-plan]"),
1417
- flight: shipoff.querySelector("[data-shipoff-flight]"),
1418
- outcome: shipoff.querySelector("[data-shipoff-outcome]"),
1419
- grid: shipoff.querySelector("[data-shipoff-grid]"),
1420
- proceed: shipoff.querySelector("[data-shipoff-proceed]"),
1421
- cancel: shipoff.querySelector("[data-shipoff-cancel]"),
1422
- live: shipoff.querySelector("[data-shipoff-live]"),
1423
- elapsed: shipoff.querySelector("[data-shipoff-elapsed]"),
1424
- seal: shipoff.querySelector("[data-shipoff-seal]"),
1425
- outcomeTitle: shipoff.querySelector("[data-shipoff-outcome-title]"),
1426
- outcomeDetail: shipoff.querySelector("[data-shipoff-outcome-detail]"),
1427
- view: shipoff.querySelector("[data-shipoff-view]"),
1428
- done: shipoff.querySelector("[data-shipoff-done]"),
1429
- confetti: shipoff.querySelector("[data-shipoff-confetti]"),
1430
- }
1431
- : null;
1432
- let shipoffTimer = null;
1433
- const closeShipoff = () => {
1434
- if (shipoffTimer) { clearInterval(shipoffTimer); shipoffTimer = null; }
1435
- if (shipoff) shipoff.hidden = true;
1436
- if (shipoffEls) shipoffEls.confetti.textContent = "";
1437
- };
1438
- const showShipoffPhase = (phase) => {
1439
- if (!shipoffEls) return;
1440
- shipoffEls.plan.hidden = phase !== "plan";
1441
- shipoffEls.flight.hidden = phase !== "flight";
1442
- shipoffEls.outcome.hidden = phase !== "outcome";
1443
- if (shipoffCard) shipoffCard.dataset.mode = phase;
1444
- };
1445
-
1446
- const buildPublishPlanText = (plan) => {
1447
- const lines = ["Publish plan (exact reviewed digest — no rebuild):"];
1448
- lines.push(" tenant: " + (appDomain || repo));
1449
- lines.push(" build: " + shortSha(plan.pinnedSha));
1450
- lines.push(" digest: " + plan.artifactDigest);
1451
- lines.push(" changes: " + (plan.includedPrs || []).length + " included");
1452
- if (plan.rollbackTarget) lines.push(" rollback: " + shortSha(plan.rollbackTarget.aggregateSha));
1453
- lines.push(" effect: publish this exact digest to your LIVE store.");
1454
- return lines.join("\n");
1455
- };
1456
-
1457
- const shortDigest = (digest) => {
1458
- const d = String(digest || "").replace(/^sha256:/, "");
1459
- return d ? "sha256:" + d.slice(0, 12) + "…" : "—";
1460
- };
1461
-
1462
- const publishAggregate = (button) => {
1463
- if (!currentPlan) return;
1464
- const plan = currentPlan;
1465
- if (!shipoff || !shipoffEls) {
1466
- // No-markup fallback only — the ceremony IS the confirm now.
1467
- if (!window.confirm(buildPublishPlanText(plan) + "\n\nPublish live?")) return;
1468
- runShip(plan, button);
1469
- return;
1470
- }
1471
- shipoffEls.grid.textContent = "";
1472
- shipoffEls.grid.append(
1473
- ...planRow("Store", appDomain || repo),
1474
- ...planRow("Build", shortSha(plan.pinnedSha), true),
1475
- ...planRow("Digest", shortDigest(plan.artifactDigest), true),
1476
- ...planRow("Changes", (plan.includedPrs || []).length + " included"),
1477
- ...(plan.rollbackTarget
1478
- ? planRow("Rollback to", shortSha(plan.rollbackTarget.aggregateSha), true)
1479
- : []),
1480
- );
1481
- showShipoffPhase("plan");
1482
- shipoff.hidden = false;
1483
- shipoffEls.proceed.focus();
1484
- shipoffEls.cancel.onclick = () => closeShipoff();
1485
- shipoffEls.done.onclick = () => closeShipoff();
1486
- shipoffEls.proceed.onclick = () => runShip(plan, button);
1487
- };
1488
-
1489
- const runShip = async (plan, button) => {
1490
- if (button) button.disabled = true;
1491
- aggregatePublishing = true; // rux7: hold the button disabled across polls
1492
- setStatus(aggStatusEl, "Publishing the reviewed build (" + shortSha(plan.pinnedSha) + ") live…");
1493
- const startedAt = Date.now();
1494
- if (shipoffEls) {
1495
- showShipoffPhase("flight");
1496
- shipoffTimer = setInterval(() => {
1497
- const s = Math.floor((Date.now() - startedAt) / 1000);
1498
- shipoffEls.elapsed.textContent = Math.floor(s / 60) + ":" + String(s % 60).padStart(2, "0");
1499
- }, 1000);
1500
- }
1501
- const outcome = (state, title, detail, showView) => {
1502
- if (!shipoffEls) return;
1503
- if (shipoffTimer) { clearInterval(shipoffTimer); shipoffTimer = null; }
1504
- shipoffEls.seal.dataset.state = state;
1505
- shipoffEls.outcomeTitle.textContent = title;
1506
- shipoffEls.outcomeDetail.textContent = detail;
1507
- shipoffEls.view.hidden = !showView;
1508
- if (showView) shipoffEls.view.href = ds.liveHref || "/";
1509
- showShipoffPhase("outcome");
1510
- shipoffEls.done.focus();
1511
- if (state === "ok") celebrate(shipoffEls.confetti);
1512
- };
1513
- try {
1514
- const res = await fetch(ds.shipEndpoint, {
1515
- method: "POST",
1516
- headers: { "content-type": "application/json", "x-tot-capability": "ship-on-behalf" },
1517
- body: JSON.stringify({
1518
- aggregateId: plan.aggregateId,
1519
- // The HUMAN go-live gate + the reviewed-digest guards (b09 ship input).
1520
- confirmGoLive: true,
1521
- expectedAggregateSha: plan.pinnedSha,
1522
- expectedArtifactDigest: plan.artifactDigest,
1523
- }),
1524
- });
1525
- const data = await res.json().catch(() => ({}));
1526
- // b09 AggregateShipResult: the ONLY live claim is state === "shipped".
1527
- if (data.state === "shipped") {
1528
- setStatus(
1529
- aggStatusEl,
1530
- "Published live · build " + shortSha(data.pinnedSha) + " (receipt " + (data.receiptId || "—") + ").",
1531
- "ok",
1532
- );
1533
- outcome(
1534
- "ok",
1535
- "Your store is live",
1536
- "Build " + shortSha(data.pinnedSha) + " — the exact digest you reviewed — is now serving" +
1537
- (data.receiptId ? " (receipt " + data.receiptId + ")." : "."),
1538
- true,
1539
- );
1540
- } else {
1541
- let message;
1542
- if (data.state === "promote_failed" || data.state === "record_failed") {
1543
- // Honest partial-failure truth — recoverable, never a false "shipped".
1544
- message = data.message || "Publish did not complete (" + data.state + "). Retry.";
1545
- } else if (data.reason === "paywall") {
1546
- message = data.message || "Publishing to your live store is part of the paid plan.";
1547
- } else {
1548
- message = data.message || data.error || "Publish refused (" + (data.reason || res.status) + ")";
1549
- }
1550
- setStatus(aggStatusEl, message, "err");
1551
- outcome("err", "Publish did not complete", message + " Your live store is unchanged.", false);
1552
- }
1553
- } catch {
1554
- setStatus(aggStatusEl, "Publish failed — network error", "err");
1555
- outcome(
1556
- "err",
1557
- "Publish did not complete",
1558
- "Network error mid-publish — refresh to see the honest state; your live store serves the last published version.",
1559
- false,
1560
- );
1561
- } finally {
1562
- aggregatePublishing = false;
1563
- if (button) button.disabled = false;
1564
- loadQueue();
1565
- loadVersions();
1566
- }
1567
- };
1568
-
1569
- const aggStatusEl = aggPanel && aggPanel.querySelector("[data-aggregate-status]");
1570
- aggPanel
1571
- ?.querySelector("[data-aggregate-publish]")
1572
- ?.addEventListener("click", (event) => publishAggregate(event.currentTarget));
1573
-
1574
- // ── Accept-to-preview LIFTOFF ─────────────────────────────────────────────
1575
- // The plan confirm + live integration flight + outcome ceremony (replaces
1576
- // the old window.confirm plan popup). Same b11 contract as before: accept =
1577
- // `POST /api/changes/integrate` (b08) → integrate into the protected
1578
- // `preview` aggregate, rebuild + combined-evidence it (b05). Flips NO live
1579
- // channel — going live is the aggregate card's Publish.
1580
- //
1581
- // HONESTY RULE for the stage rail: a stage only advances on a REAL signal —
1582
- // the outcome POST resolving, or GET /api/changes polling showing the
1583
- // candidate inside `aggregate.includedPrs` (merge landed) / an `activeRun`
1584
- // (build+evidence running, statusMessage relayed verbatim). No timers ever
1585
- // fake progress.
1586
- const liftoff = root.querySelector("[data-liftoff]");
1587
- const liftoffCard = liftoff && liftoff.querySelector(".liftoff-card");
1588
- const liftoffEls = liftoff
1589
- ? {
1590
- plan: liftoff.querySelector("[data-liftoff-plan]"),
1591
- flight: liftoff.querySelector("[data-liftoff-flight]"),
1592
- outcome: liftoff.querySelector("[data-liftoff-outcome]"),
1593
- title: liftoff.querySelector("[data-liftoff-title]"),
1594
- grid: liftoff.querySelector("[data-liftoff-grid]"),
1595
- proceed: liftoff.querySelector("[data-liftoff-proceed]"),
1596
- cancel: liftoff.querySelector("[data-liftoff-cancel]"),
1597
- flightTitle: liftoff.querySelector("[data-liftoff-flight-title]"),
1598
- live: liftoff.querySelector("[data-liftoff-live]"),
1599
- elapsed: liftoff.querySelector("[data-liftoff-elapsed]"),
1600
- hide: liftoff.querySelector("[data-liftoff-hide]"),
1601
- seal: liftoff.querySelector("[data-liftoff-seal]"),
1602
- outcomeTitle: liftoff.querySelector("[data-liftoff-outcome-title]"),
1603
- outcomeDetail: liftoff.querySelector("[data-liftoff-outcome-detail]"),
1604
- review: liftoff.querySelector("[data-liftoff-review]"),
1605
- done: liftoff.querySelector("[data-liftoff-done]"),
1606
- confetti: liftoff.querySelector("[data-liftoff-confetti]"),
1607
- }
1608
- : null;
1609
-
1610
- const liftoffStage = (name) =>
1611
- liftoff && liftoff.querySelector('[data-liftoff-stage="' + name + '"]');
1612
- const LIFTOFF_STAGES = ["merge", "build", "evidence", "green"];
1613
- const setStage = (name, state) => {
1614
- const el = liftoffStage(name);
1615
- if (el) el.dataset.state = state; // pending | active | done | fail
1616
- };
1617
- // Advance the rail so everything before `name` is done and `name` is active.
1618
- const railTo = (name) => {
1619
- const idx = LIFTOFF_STAGES.indexOf(name);
1620
- LIFTOFF_STAGES.forEach((s, i) => {
1621
- const el = liftoffStage(s);
1622
- const cur = el && el.dataset.state;
1623
- if (cur === "fail") return; // never un-fail
1624
- setStage(s, i < idx ? "done" : i === idx ? "active" : "pending");
1625
- });
1626
- };
1627
-
1628
- let liftoffTimer = null;
1629
- let liftoffPoll = null;
1630
- let liftoffOpenedFrom = null;
1631
- const stopLiftoffLoops = () => {
1632
- if (liftoffTimer) { clearInterval(liftoffTimer); liftoffTimer = null; }
1633
- if (liftoffPoll) { clearInterval(liftoffPoll); liftoffPoll = null; }
1634
- };
1635
- const closeLiftoff = () => {
1636
- stopLiftoffLoops();
1637
- if (liftoff) liftoff.hidden = true;
1638
- if (liftoffEls) liftoffEls.confetti.textContent = "";
1639
- if (liftoffOpenedFrom && document.contains(liftoffOpenedFrom)) liftoffOpenedFrom.focus();
1640
- liftoffOpenedFrom = null;
1641
- };
1642
- const showPhase = (phase) => {
1643
- if (!liftoffEls) return;
1644
- liftoffEls.plan.hidden = phase !== "plan";
1645
- liftoffEls.flight.hidden = phase !== "flight";
1646
- liftoffEls.outcome.hidden = phase !== "outcome";
1647
- if (liftoffCard) liftoffCard.dataset.mode = phase;
1648
- };
1649
-
1650
- const planRow = (dt, dd, mono) => {
1651
- const t = document.createElement("dt");
1652
- t.textContent = dt;
1653
- const d = document.createElement("dd");
1654
- d.textContent = dd;
1655
- if (mono) d.className = "publish-mono";
1656
- return [t, d];
1657
- };
1658
-
1659
- const celebrate = (container) => {
1660
- if (!container) return;
1661
- if (window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
1662
- const colors = ["#0f9d8f", "#25b8a8", "#f4b942", "#5b8def", "#e2634f"];
1663
- for (let i = 0; i < 42; i++) {
1664
- const p = document.createElement("i");
1665
- p.style.left = Math.random() * 100 + "%";
1666
- p.style.background = colors[i % colors.length];
1667
- p.style.animationDelay = Math.random() * 0.35 + "s";
1668
- p.style.animationDuration = 0.9 + Math.random() * 0.9 + "s";
1669
- p.style.setProperty("--liftoff-drift", (Math.random() * 160 - 80).toFixed(0) + "px");
1670
- p.style.setProperty("--liftoff-spin", (Math.random() * 640 - 320).toFixed(0) + "deg");
1671
- container.append(p);
1672
- }
1673
- setTimeout(() => { container.textContent = ""; }, 2400);
1674
- };
1675
-
1676
- // The live poll during flight: reflect the server's REAL progress.
1677
- const startFlightPoll = (change, preFlightSha) => {
1678
- let inAggregate = false;
1679
- liftoffPoll = setInterval(async () => {
1680
- try {
1681
- const res = await fetch(ds.changesEndpoint, { headers: { accept: "application/json" } });
1682
- if (!res.ok) return;
1683
- const data = await res.json();
1684
- const agg = data.aggregate || {};
1685
- const included = (agg.includedPrs || []).some((p) => p.changeId === change.changeId);
1686
- const shaMoved = agg.aggregateSha && agg.aggregateSha !== preFlightSha;
1687
- const run = agg.activeRun || null;
1688
- if (!inAggregate && (included || shaMoved)) {
1689
- inAggregate = true;
1690
- railTo("build");
1691
- if (liftoffEls) liftoffEls.live.textContent =
1692
- "Merged into preview — rebuilding the combined aggregate…";
1693
- }
1694
- if (run) {
1695
- railTo("evidence");
1696
- if (liftoffEls) liftoffEls.live.textContent =
1697
- run.statusMessage || "Combined evidence is running…";
1698
- }
1699
- } catch { /* polling is best-effort; the POST outcome is authoritative */ }
1700
- }, 2500);
1701
- };
1702
-
1703
- const openLiftoff = (change, button) => {
1704
- if (!liftoff || !liftoffEls) return false;
1705
- liftoffOpenedFrom = button || null;
1706
- const target = change.prNumber != null ? "PR #" + change.prNumber : change.changeId;
1707
- liftoffEls.title.textContent = "Integrate " + target + " into preview";
1708
- liftoffEls.grid.textContent = "";
1709
- liftoffEls.grid.append(
1710
- ...planRow("Store", appDomain || repo),
1711
- ...(change.prNumber != null ? planRow("Pull request", "#" + change.prNumber) : []),
1712
- ...planRow("Change", change.changeId, true),
1713
- ...(change.headSha ? planRow("Head", shortSha(change.headSha), true) : []),
1714
- );
1715
- LIFTOFF_STAGES.forEach((s) => setStage(s, "pending"));
1716
- liftoffEls.live.textContent = "Working…";
1717
- liftoffEls.elapsed.textContent = "0:00";
1718
- showPhase("plan");
1719
- liftoff.hidden = false;
1720
- liftoffEls.proceed.focus();
1721
-
1722
- liftoffEls.cancel.onclick = () => closeLiftoff();
1723
- liftoffEls.done.onclick = () => closeLiftoff();
1724
- liftoffEls.hide.onclick = () => { liftoff.hidden = true; }; // flight keeps running
1725
- liftoffEls.proceed.onclick = () => runIntegration(change, button);
1726
- return true;
1727
- };
1728
-
1729
- // Esc: close in plan/outcome; during flight just hide (the POST keeps going).
1730
- // Handles BOTH ceremonies (accept liftoff + publish shipoff).
1731
- document.addEventListener("keydown", (ev) => {
1732
- if (ev.key !== "Escape") return;
1733
- if (liftoff && !liftoff.hidden) {
1734
- const mode = liftoffCard && liftoffCard.dataset.mode;
1735
- if (mode === "flight") liftoff.hidden = true;
1736
- else closeLiftoff();
1737
- }
1738
- if (shipoff && !shipoff.hidden) {
1739
- const mode = shipoffCard && shipoffCard.dataset.mode;
1740
- if (mode === "flight") shipoff.hidden = true;
1741
- else closeShipoff();
1742
- }
1743
- });
1744
-
1745
- // b08 integrate returns an IntegrateOutcome — { ok, queueState, runState,
1746
- // aggregateSha, pointerMoved, statusMessage, reason? } — NEVER a bare
1747
- // merged:true. Render it honestly: green advances the aggregate; red left it
1748
- // exactly where it was and names the failing stage.
1749
- const runIntegration = async (change, button) => {
1750
- const target = change.prNumber != null ? "PR #" + change.prNumber : change.changeId;
1751
- if (button) button.disabled = true;
1752
- busyChanges.add(change.changeId); // rux7: survive a poll re-render as busy
1753
- setStatus(statusEl, "Integrating " + change.changeId + " into preview…");
1754
- const startedAt = Date.now();
1755
- let preFlightSha = null;
1756
- if (liftoffEls) {
1757
- showPhase("flight");
1758
- liftoffEls.flightTitle.textContent = "Integrating " + target + " into preview";
1759
- railTo("merge");
1760
- liftoffEls.live.textContent = "Squash-merging the candidate into preview…";
1761
- liftoffTimer = setInterval(() => {
1762
- const s = Math.floor((Date.now() - startedAt) / 1000);
1763
- liftoffEls.elapsed.textContent = Math.floor(s / 60) + ":" + String(s % 60).padStart(2, "0");
1764
- }, 1000);
1765
- }
1766
- try {
1767
- // Snapshot the pre-flight aggregate sha so the poll can detect the merge
1768
- // landing (sha moved) even before includedPrs reflects it.
1769
- try {
1770
- const pre = await fetch(ds.changesEndpoint, { headers: { accept: "application/json" } });
1771
- if (pre.ok) preFlightSha = ((await pre.json()).aggregate || {}).aggregateSha || null;
1772
- } catch { /* best-effort */ }
1773
- startFlightPoll(change, preFlightSha);
1774
-
1775
- const res = await fetch(ds.integrateEndpoint, {
1776
- method: "POST",
1777
- headers: {
1778
- "content-type": "application/json",
1779
- // Mirror of the server-side capability model (UX): the server
1780
- // re-derives capability and stays authoritative.
1781
- "x-tot-capability": "ship-on-behalf",
1782
- },
1783
- body: JSON.stringify({
1784
- repo,
1785
- changeId: change.changeId,
1786
- prNumber: change.prNumber ?? undefined,
1787
- expectedHeadSha: change.headSha || undefined,
1788
- }),
1789
- });
1790
- const data = await res.json().catch(() => ({}));
1791
- stopLiftoffLoops();
1792
- if (res.ok && data.ok) {
1793
- setStatus(
1794
- statusEl,
1795
- "Integrated " + change.changeId + " — preview aggregate is green (" +
1796
- shortSha(data.aggregateSha) + "). Review the aggregate, then Publish to go live.",
1797
- "ok",
1798
- );
1799
- if (liftoffEls) {
1800
- LIFTOFF_STAGES.forEach((s) => setStage(s, "done"));
1801
- liftoffEls.seal.dataset.state = "ok";
1802
- liftoffEls.outcomeTitle.textContent = "The preview aggregate is green";
1803
- liftoffEls.outcomeDetail.textContent =
1804
- target + " is in. Aggregate build " + shortSha(data.aggregateSha) +
1805
- " passed its combined evidence — this exact build is what you review, and what " +
1806
- "Publish would take live. Nothing is live yet.";
1807
- if (data.aggregateSha) {
1808
- liftoffEls.review.href =
1809
- "/preview/" + encodeURIComponent(appDomain) + "/rev/" + data.aggregateSha + "/";
1810
- liftoffEls.review.hidden = false;
1811
- } else {
1812
- liftoffEls.review.hidden = true;
1813
- }
1814
- if (liftoff.hidden) liftoff.hidden = false; // surface the payoff even if backgrounded
1815
- showPhase("outcome");
1816
- liftoffEls.done.focus();
1817
- celebrate(liftoffEls.confetti);
1818
- }
1819
- } else {
1820
- let message;
1821
- let failStage = "merge";
1822
- if (res.ok && data.queueState === "red") {
1823
- // The queue ran but the aggregate did not go green — the candidate did
1824
- // NOT advance the shippable set. Name the honest failing stage.
1825
- failStage = "evidence";
1826
- message =
1827
- "Integration of " + change.changeId + " failed (" + (data.reason || "red") + "): " +
1828
- (data.statusMessage || "the aggregate did not pass its combined evidence.") +
1829
- " The aggregate is unchanged.";
1830
- } else if (data.reason === "not_preview_base") {
1831
- message =
1832
- "Not integrated: " + change.changeId + " does not target the preview branch " +
1833
- "(base is not \"preview\"). " + (data.statusMessage || "");
1834
- } else {
1835
- message = data.statusMessage || data.error || "Integrate failed (" + res.status + ")";
1836
- }
1837
- setStatus(statusEl, message, "err");
1838
- if (liftoffEls) {
1839
- setStage(failStage, "fail");
1840
- liftoffEls.seal.dataset.state = "err";
1841
- liftoffEls.outcomeTitle.textContent = "Integration did not land";
1842
- liftoffEls.outcomeDetail.textContent = message;
1843
- liftoffEls.review.hidden = true;
1844
- if (liftoff.hidden) liftoff.hidden = false;
1845
- showPhase("outcome");
1846
- liftoffEls.done.focus();
1847
- }
1848
- }
1849
- } catch {
1850
- stopLiftoffLoops();
1851
- setStatus(statusEl, "Integrate failed — network error", "err");
1852
- if (liftoffEls) {
1853
- liftoffEls.seal.dataset.state = "err";
1854
- liftoffEls.outcomeTitle.textContent = "Integration did not land";
1855
- liftoffEls.outcomeDetail.textContent =
1856
- "Network error mid-flight — refresh the queue to see the aggregate's honest state.";
1857
- liftoffEls.review.hidden = true;
1858
- if (liftoff.hidden) liftoff.hidden = false;
1859
- showPhase("outcome");
1860
- }
1861
- } finally {
1862
- busyChanges.delete(change.changeId);
1863
- if (button) button.disabled = false;
1864
- loadQueue();
1865
- }
1866
- };
1867
-
1868
- const integrateCandidate = (change, button) => {
1869
- // The liftoff dialog IS the plan confirm now; window.confirm stays only as
1870
- // the no-dialog fallback (markup missing = fail open to the old popup).
1871
- if (openLiftoff(change, button)) return;
1872
- const target = change.prNumber != null ? "PR #" + change.prNumber : change.changeId;
1873
- const plan =
1874
- "Accept-to-preview plan:\n tenant: " + (appDomain || repo) +
1875
- (change.prNumber != null ? "\n PR: #" + change.prNumber : "") +
1876
- "\n change id: " + change.changeId +
1877
- (change.headSha ? "\n head sha: " + shortSha(change.headSha) : "") +
1878
- "\n effect: integrate " + target + " into the preview aggregate, then rebuild + " +
1879
- "re-evidence it. Does NOT go live — publish the reviewed build separately.";
1880
- if (!window.confirm(plan + "\n\nProceed?")) return;
1881
- runIntegration(change, button);
1882
- };
1883
-
1884
- const rejectChange = async (change, button) => {
1885
- const reason = window.prompt(
1886
- "Reject " + change.changeId + " — add a short note for the submitter:",
1887
- );
1888
- if (reason == null) return;
1889
- if (!reason.trim()) {
1890
- setStatus(statusEl, "A reject note is required.", "err");
1891
- return;
1892
- }
1893
- button.disabled = true;
1894
- busyChanges.add(change.changeId); // rux7: survive a poll re-render as busy
1895
- setStatus(statusEl, "Rejecting " + change.changeId + "…");
1896
- try {
1897
- const res = await fetch(
1898
- ds.changesEndpoint + "/" + encodeURIComponent(change.changeId) + "/reject",
1899
- {
1900
- method: "POST",
1901
- headers: {
1902
- "content-type": "application/json",
1903
- "x-tot-capability": "ship-on-behalf",
1904
- },
1905
- body: JSON.stringify({ repo, reason: reason.trim() }),
1906
- },
1907
- );
1908
- const data = await res.json().catch(() => ({}));
1909
- if (res.ok) {
1910
- setStatus(statusEl, "Change " + change.changeId + " rejected.", "ok");
1911
- } else {
1912
- setStatus(statusEl, data.error || "Reject failed (" + res.status + ")", "err");
1913
- }
1914
- } catch {
1915
- setStatus(statusEl, "Reject failed — network error", "err");
1916
- } finally {
1917
- busyChanges.delete(change.changeId);
1918
- button.disabled = false;
1919
- loadQueue();
1920
- }
1921
- };
1922
-
1923
- // U7 — retire/GC. Mirror of the accept plan affordance (decision
1924
- // operator-verb-and-hosting-model): state EXACTLY what retire does — evict the
1925
- // candidate's preview environment + immutable version — and that it is
1926
- // REBUILDABLE (degrades to "not built yet", not a 404), so an operator can't
1927
- // confuse it with Reject. Same shape as `tot retire`'s CLI plan for parity.
1928
- const buildRetirePlan = (change) => {
1929
- const target = change.prNumber != null ? "PR #" + change.prNumber : change.changeId;
1930
- const lines = ["Retire plan:", " tenant: " + (appDomain || repo)];
1931
- if (change.prNumber != null) lines.push(" PR: #" + change.prNumber);
1932
- lines.push(" change id: " + change.changeId);
1933
- if (change.headSha) lines.push(" head sha: " + shortSha(change.headSha));
1934
- lines.push(
1935
- " effect: evict " + target + "'s preview environment + version to reclaim space.",
1936
- );
1937
- lines.push(
1938
- " rebuild: REVERSIBLE — rebuild it any time (this is NOT Reject; the change stays open).",
1939
- );
1940
- return lines.join("\n");
1941
- };
1942
-
1943
- const retireChange = async (change, button) => {
1944
- if (!window.confirm(buildRetirePlan(change) + "\n\nProceed?")) return;
1945
- button.disabled = true;
1946
- busyChanges.add(change.changeId); // rux7: survive a poll re-render as busy
1947
- setStatus(statusEl, "Retiring " + change.changeId + "…");
1948
- try {
1949
- const res = await fetch(ds.retireEndpoint, {
1950
- method: "POST",
1951
- headers: {
1952
- "content-type": "application/json",
1953
- // Mirror of the server-side capability model (UX); the server
1954
- // re-derives capability and stays authoritative.
1955
- "x-tot-capability": "ship-on-behalf",
1956
- },
1957
- body: JSON.stringify({
1958
- changeId: change.changeId,
1959
- pr: change.prNumber ?? undefined,
1960
- }),
1961
- });
1962
- const data = await res.json().catch(() => ({}));
1963
- if (res.ok && data.ok) {
1964
- setStatus(
1965
- statusEl,
1966
- data.evicted
1967
- ? "Retired " + change.changeId + " — the preview was evicted (rebuildable on demand)."
1968
- : "Retire " + change.changeId + ": nothing to evict (already retired).",
1969
- "ok",
1970
- );
1971
- } else {
1972
- setStatus(statusEl, data.error || "Retire failed (" + res.status + ")", "err");
1973
- }
1974
- } catch {
1975
- setStatus(statusEl, "Retire failed — network error", "err");
1976
- } finally {
1977
- busyChanges.delete(change.changeId);
1978
- button.disabled = false;
1979
- loadQueue();
1980
- }
1981
- };
1982
-
1983
- // ---- rux5: build-on-demand for a synthetic not-built PR ------------------
1984
- // Mirror of the integrate/retire plan affordances: state EXACTLY what build
1985
- // does — materialize this PR's hosted preview at its forge head — and that it
1986
- // is INERT (flips no live channel). POSTs { pr, headSha?, baseSha? }; the row
1987
- // already carries the head sha GET /api/changes resolved via forge PR-read, and
1988
- // the server re-resolves it authoritatively when the body omits it. Shows an
1989
- // in-progress state (disabled + "Building…") while the build runs, then reloads
1990
- // the queue so the freshly-built PR reappears as a built candidate.
1991
-
1992
- const buildPreviewPlan = (change) => {
1993
- const lines = ["Build preview plan:", " tenant: " + (appDomain || repo)];
1994
- lines.push(" PR: #" + change.prNumber);
1995
- if (change.headSha) lines.push(" head sha: " + shortSha(change.headSha));
1996
- lines.push(
1997
- " effect: materialize this PR's hosted preview at its head — INERT " +
1998
- "(does NOT go live).",
1999
- );
2000
- return lines.join("\n");
2001
- };
2002
-
2003
- const buildPreview = async (change, button) => {
2004
- const label = "PR #" + change.prNumber;
2005
- if (!window.confirm(buildPreviewPlan(change) + "\n\nBuild the preview now?")) return;
2006
- button.disabled = true;
2007
- const originalText = button.textContent;
2008
- button.textContent = "Building…";
2009
- button.dataset.building = "true";
2010
- // rux7: record the in-flight build so a poll re-render preserves the
2011
- // spinner/disabled state on the freshly-rendered button (cleared in finally).
2012
- if (change.prNumber != null) inflightBuilds.add(change.prNumber);
2013
- setStatus(statusEl, "Building preview for " + label + "…");
2014
- try {
2015
- const res = await fetch(ds.buildEndpoint, {
2016
- method: "POST",
2017
- headers: {
2018
- "content-type": "application/json",
2019
- // Mirror of the server-side capability model (UX); the server
2020
- // re-derives capability (buildGate) and stays authoritative.
2021
- "x-tot-capability": "ship-on-behalf",
2022
- },
2023
- body: JSON.stringify({
2024
- pr: change.prNumber,
2025
- headSha: change.headSha || undefined,
2026
- baseSha: change.baseSha || undefined,
2027
- }),
2028
- });
2029
- const data = await res.json().catch(() => ({}));
2030
- if (res.ok && data.ok) {
2031
- setStatus(
2032
- statusEl,
2033
- "Built preview for " + label +
2034
- " — it now appears as a built change in the queue.",
2035
- "ok",
2036
- );
2037
- } else if (data && data.ok === false) {
2038
- // reconcileCandidate returned a blocked/failed candidate (e.g. a safety
2039
- // finding with no override) — the honest reason, never a false success.
2040
- setStatus(
2041
- statusEl,
2042
- "Build did not complete for " + label + ": " +
2043
- ((data.errors && data.errors.join("; ")) || data.error || "blocked"),
2044
- "err",
2045
- );
2046
- } else {
2047
- setStatus(statusEl, data.error || "Build failed (" + res.status + ")", "err");
2048
- }
2049
- } catch {
2050
- setStatus(statusEl, "Build failed — network error", "err");
2051
- } finally {
2052
- if (change.prNumber != null) inflightBuilds.delete(change.prNumber);
2053
- button.disabled = false;
2054
- button.textContent = originalText;
2055
- delete button.dataset.building;
2056
- loadQueue();
2057
- }
2058
- };
2059
-
2060
- // ---- rux6: unified review pane -----------------------------------------
2061
- // "One review moment": expanding a candidate row reveals a single pane with
2062
- // the live preview (iframed SAME-ORIGIN — the /preview/<tenant>/pr/<N> route
2063
- // serves `frame-ancestors 'self'` + `X-Frame-Options: SAMEORIGIN`, so a
2064
- // same-origin admin embed is permitted; a cross-origin embed is refused,
2065
- // which is why the pane also always offers an "Open in new tab" link), the
2066
- // evidence chips the row already carries (change.evidence), the dg7 diff
2067
- // (reusing renderDiff below — GET /api/changes/<id>/diff, which never invents
2068
- // a diff for a non-renderable candidate), and the SAME Accept-to-preview /
2069
- // Reject actions. The reviewer never leaves the queue to review and act; the
2070
- // server stays authoritative for every action (this is UI consolidation only).
2071
-
2072
- const diffBase = ds.diffEndpointBase;
2073
-
2074
- const reviewRowFor = (tr) => {
2075
- const next = tr.nextElementSibling;
2076
- return next && next.dataset && next.dataset.publishReviewRow === tr.dataset.changeRowId
2077
- ? next
2078
- : null;
2079
- };
2080
-
2081
- const closeReview = (tr, button) => {
2082
- const existing = reviewRowFor(tr);
2083
- if (existing) existing.remove();
2084
- if (button) {
2085
- button.textContent = "Review";
2086
- button.setAttribute("aria-expanded", "false");
2087
- }
2088
- };
2089
-
2090
- // Evidence chips from the data the row already carries (change.evidence):
2091
- // an overall promotable verdict + one chip per reported check.
2092
- const renderEvidenceChips = (container, change) => {
2093
- const checks = (change.evidence && change.evidence.checks) || [];
2094
- const promotable = Boolean(change.evidence && change.evidence.promotable);
2095
- container.append(
2096
- promotable ? chip("Checks passed", "green") : chip("Checks blocked", "amber"),
2097
- );
2098
- for (const c of checks) {
2099
- const tone = c.status === "pass" ? "green" : c.status === "fail" ? "red" : "amber";
2100
- const label = (c.label || c.id || "check") + (c.status && c.status !== "pass" ? " · " + c.status : "");
2101
- const el = chip(label, tone);
2102
- if (c.detail) el.title = c.detail;
2103
- container.append(el);
2104
- }
2105
- if (!checks.length) container.append(subtle("No checks reported yet"));
2106
- };
2107
-
2108
- // Build the split pane. Returns the pane node + the diff container so the
2109
- // caller can populate the diff asynchronously (reusing renderDiff).
2110
- const buildReviewPane = (change) => {
2111
- const pane = document.createElement("div");
2112
- pane.className = "review-pane";
2113
-
2114
- // Preview column — same-origin iframe of the friendly per-PR route (it
2115
- // handles every state: ready render, or the not-built page). Falls back to
2116
- // any server-provided previewUrl for a change-first row with no PR number.
2117
- const previewUrl = candidatePrUrl(change.prNumber) || change.previewUrl;
2118
- const previewCol = document.createElement("div");
2119
- previewCol.className = "review-preview";
2120
- const pHead = document.createElement("div");
2121
- pHead.className = "review-pane-head";
2122
- const pTitle = document.createElement("b");
2123
- pTitle.textContent = "Preview";
2124
- pHead.append(pTitle);
2125
- if (previewUrl) {
2126
- const openLink = document.createElement("a");
2127
- openLink.href = previewUrl;
2128
- openLink.target = "_blank";
2129
- openLink.rel = "noopener";
2130
- openLink.textContent = "Open in new tab ↗";
2131
- pHead.append(openLink);
2132
- }
2133
- previewCol.append(pHead);
2134
- if (previewUrl) {
2135
- const frame = document.createElement("iframe");
2136
- frame.className = "review-frame";
2137
- frame.src = previewUrl;
2138
- frame.loading = "lazy";
2139
- frame.title =
2140
- change.prNumber != null
2141
- ? "Preview of PR #" + change.prNumber
2142
- : "Preview of " + change.changeId;
2143
- previewCol.append(frame);
2144
- } else {
2145
- previewCol.append(subtle("No preview is available for this change yet."));
2146
- }
2147
-
2148
- // Detail column — evidence chips + diff + the same Accept/Reject actions.
2149
- const detailCol = document.createElement("div");
2150
- detailCol.className = "review-detail";
2151
-
2152
- const evSection = document.createElement("div");
2153
- evSection.className = "review-section";
2154
- const evTitle = document.createElement("b");
2155
- evTitle.textContent = "Checks";
2156
- const evChips = document.createElement("div");
2157
- evChips.className = "review-chips";
2158
- renderEvidenceChips(evChips, change);
2159
- evSection.append(evTitle, evChips);
2160
- detailCol.append(evSection);
2161
-
2162
- const diffSection = document.createElement("div");
2163
- diffSection.className = "review-section";
2164
- const diffTitle = document.createElement("b");
2165
- diffTitle.textContent = "Diff";
2166
- const diffTarget = document.createElement("div");
2167
- diffTarget.className = "review-diff-target";
2168
- diffTarget.append(subtle("Loading the diff…"));
2169
- diffSection.append(diffTitle, diffTarget);
2170
- detailCol.append(diffSection);
2171
-
2172
- // The SAME actions as the row — same handlers, same gates. Not a new authz
2173
- // path: integrateCandidate/rejectChange POST to the same endpoints, and the
2174
- // server re-authorizes.
2175
- const actionRow = document.createElement("div");
2176
- actionRow.className = "review-actions";
2177
- const accept = document.createElement("button");
2178
- accept.type = "button";
2179
- accept.className = "btn primary";
2180
- accept.textContent = "Accept to preview";
2181
- accept.disabled = !canShip || !change.mergeable;
2182
- accept.title = !canShip
2183
- ? "Requires an owner or admin sign-in"
2184
- : !change.mergeable
2185
- ? "This change is not ready to integrate"
2186
- : "Integrate this change into the preview aggregate (does not go live)";
2187
- accept.addEventListener("click", () => integrateCandidate(change, accept));
2188
- const reject = document.createElement("button");
2189
- reject.type = "button";
2190
- reject.className = "btn";
2191
- reject.textContent = "Reject";
2192
- reject.disabled = !canShip;
2193
- reject.title = canShip
2194
- ? "Close this change without publishing"
2195
- : "Requires an owner or admin sign-in";
2196
- reject.addEventListener("click", () => rejectChange(change, reject));
2197
- actionRow.append(accept, reject);
2198
- detailCol.append(actionRow);
2199
-
2200
- pane.append(previewCol, detailCol);
2201
- return { pane, diffTarget };
2202
- };
2203
-
2204
- const loadReviewDiff = async (change, diffTarget) => {
2205
- try {
2206
- const res = await fetch(diffBase + "/" + encodeURIComponent(change.changeId) + "/diff", {
2207
- headers: { accept: "application/json" },
2208
- });
2209
- const data = await res.json().catch(() => ({}));
2210
- diffTarget.textContent = "";
2211
- if (!res.ok) {
2212
- diffTarget.append(subtle(data.error || "Could not load the diff (" + res.status + ")"));
2213
- } else {
2214
- renderDiff(diffTarget, data.diff || {});
2215
- }
2216
- } catch {
2217
- diffTarget.textContent = "";
2218
- diffTarget.append(subtle("Could not load the diff — network error"));
2219
- }
2220
- };
2221
-
2222
- const toggleReview = (change, button, tr) => {
2223
- if (!tr.dataset.changeRowId) tr.dataset.changeRowId = change.changeId;
2224
- if (reviewRowFor(tr)) {
2225
- closeReview(tr, button);
2226
- return;
2227
- }
2228
- const detailTr = document.createElement("tr");
2229
- detailTr.dataset.publishReviewRow = tr.dataset.changeRowId;
2230
- const td = document.createElement("td");
2231
- td.colSpan = 6;
2232
- td.className = "publish-review-cell";
2233
- const { pane, diffTarget } = buildReviewPane(change);
2234
- td.append(pane);
2235
- detailTr.append(td);
2236
- tr.after(detailTr);
2237
- button.textContent = "Hide review";
2238
- button.setAttribute("aria-expanded", "true");
2239
- loadReviewDiff(change, diffTarget);
2240
- };
2241
-
2242
- const CHANGE_MARK = { added: "+", changed: "~", removed: "−" };
2243
-
2244
- const renderDiff = (td, diff) => {
2245
- td.textContent = "";
2246
- const head = document.createElement("div");
2247
- head.className = "publish-diff-head";
2248
-
2249
- // Authority: honest label of whether the diff describes the exact head.
2250
- const authority = diff.authority || {};
2251
- const authChip = chip(
2252
- authority.authoritative
2253
- ? "Reviewed at head"
2254
- : authority.stale
2255
- ? "Last-good preview (stale vs head)"
2256
- : authority.missing
2257
- ? "No evidence yet"
2258
- : "Head",
2259
- authority.authoritative ? "green" : authority.stale ? "amber" : "",
2260
- );
2261
- head.append(authChip);
2262
-
2263
- if (diff.headSha) {
2264
- const sha = document.createElement("span");
2265
- sha.className = "publish-mono subtle";
2266
- sha.textContent = "head " + shortSha(diff.headSha);
2267
- head.append(sha);
2268
- }
2269
- if (diff.revHref) {
2270
- const rev = document.createElement("a");
2271
- rev.href = diff.revHref;
2272
- rev.target = "_blank";
2273
- rev.rel = "noopener";
2274
- rev.textContent = "Open reviewed revision";
2275
- head.append(rev);
2276
- }
2277
- td.append(head);
2278
-
2279
- if (!diff.renderable) {
2280
- // Honest: a candidate that can't render has NO diff — say why (dg3), no fake.
2281
- const reason = document.createElement("p");
2282
- reason.className = "note publish-diff-blocked";
2283
- reason.textContent =
2284
- diff.blockedReason || "This candidate has no renderable version to diff yet.";
2285
- td.append(reason);
2286
- return;
2287
- }
2288
-
2289
- const files = Array.isArray(diff.files) ? diff.files : [];
2290
- if (!files.length) {
2291
- td.append(subtle("No file changes vs the current live version."));
2292
- return;
2293
- }
2294
- const list = document.createElement("ul");
2295
- list.className = "publish-diff-list";
2296
- for (const f of files) {
2297
- const li = document.createElement("li");
2298
- li.className = "publish-diff-" + f.change;
2299
- const mark = document.createElement("span");
2300
- mark.className = "publish-diff-mark";
2301
- mark.textContent = CHANGE_MARK[f.change] || "•";
2302
- const path = document.createElement("code");
2303
- path.textContent = f.path;
2304
- li.append(mark, path);
2305
- list.append(li);
2306
- }
2307
- td.append(list);
2308
- };
2309
-
2310
- // ---- dg7: versions / promotion history + rollback ----------------------
2311
- // The promotion history (u2/u3 promotion_status) with the tenant Gitea SHA,
2312
- // its /rev link (u5), and the current-live marker; a prior version rolls back
2313
- // THROUGH the one orchestrator (/api/changes/rollback → u8), rendering only the
2314
- // HONEST terminal state (rolled_back only when verified).
2315
-
2316
- const versionsPanel = root.querySelector("[data-publish-versions]");
2317
- const versionsBody = versionsPanel?.querySelector("[data-versions-body]");
2318
- const versionsChip = versionsPanel?.querySelector("[data-versions-chip]");
2319
- const versionsStatus = versionsPanel?.querySelector("[data-versions-status]");
2320
- const versionsRollbackNote = versionsPanel?.querySelector("[data-versions-rollback-note]");
2321
- let rollbackMode = "control-plane";
2322
-
2323
- const renderVersions = (view) => {
2324
- if (!versionsBody) return;
2325
- const versions = Array.isArray(view.versions) ? view.versions : [];
2326
- rollbackMode = view.rollbackMode || "control-plane";
2327
- versionsBody.textContent = "";
2328
-
2329
- if (versionsChip) {
2330
- versionsChip.textContent = versions.length === 1 ? "1 version" : versions.length + " versions";
2331
- versionsChip.className = "chip" + (versions.length ? " blue" : "");
2332
- }
2333
-
2334
- // Static tenants (rux13): per-version rollback is an HONEST ONE-DISPATCH.
2335
- // The console can't enumerate the S3 versions archive digest, so it dispatches
2336
- // by the tenant version id and CI resolves the digest + re-publishes — it
2337
- // completes via CI, not instantly (never implied one-click).
2338
- if (versionsRollbackNote) {
2339
- if (rollbackMode === "static-archive") {
2340
- versionsRollbackNote.hidden = false;
2341
- versionsRollbackNote.textContent =
2342
- "This store publishes to a static public site. Rolling back DISPATCHES a CI job that " +
2343
- "re-publishes the prior version from the S3 versions archive — it completes via CI, not " +
2344
- "instantly. The store keeps serving the current version until the re-publish is verified live.";
2345
- } else {
2346
- versionsRollbackNote.hidden = true;
2347
- }
2348
- }
2349
-
2350
- if (!versions.length) {
2351
- const tr = document.createElement("tr");
2352
- const td = cell(subtle("No versions have been promoted to live yet."));
2353
- td.colSpan = 6;
2354
- tr.append(td);
2355
- versionsBody.append(tr);
2356
- return;
2357
- }
2358
-
2359
- for (const v of versions) {
2360
- const tr = document.createElement("tr");
2361
-
2362
- // Version identity: the tenant Gitea SHA (content authority) + source.
2363
- const idCell = document.createElement("td");
2364
- const strong = document.createElement("strong");
2365
- strong.className = "publish-mono";
2366
- strong.textContent = shortSha(v.versionId);
2367
- idCell.append(strong);
2368
- if (v.source) idCell.append(subtle(v.source === "commit" ? "From a commit" : "Content hash"));
2369
- tr.append(idCell);
2370
-
2371
- // Digest (static current only — never fabricated for priors).
2372
- const digestCell = cell(v.digest ? shortSha(v.digest) : "—");
2373
- digestCell.classList.add("publish-mono");
2374
- if (!v.digest) digestCell.classList.add("subtle");
2375
- tr.append(digestCell);
2376
-
2377
- tr.append(cell(age(v.promotedAt)));
2378
-
2379
- // Preview: the u5 immutable /rev/<sha> link.
2380
- const revCell = document.createElement("td");
2381
- if (v.revHref) {
2382
- const a = document.createElement("a");
2383
- a.href = v.revHref;
2384
- a.target = "_blank";
2385
- a.rel = "noopener";
2386
- a.textContent = "Revision";
2387
- revCell.append(a);
2388
- } else {
2389
- revCell.append(subtle("—"));
2390
- }
2391
- tr.append(revCell);
2392
-
2393
- // State: current live vs prior.
2394
- tr.append(cell(v.isCurrent ? chip("Current live", "green") : chip("Prior", "")));
2395
-
2396
- // Action: roll back to a PRIOR version (never the current one).
2397
- const act = document.createElement("td");
2398
- act.className = "action publish-actions";
2399
- if (!v.isCurrent) {
2400
- const rollbackBtn = document.createElement("button");
2401
- rollbackBtn.type = "button";
2402
- rollbackBtn.className = "btn";
2403
- const isStatic = rollbackMode === "static-archive";
2404
- // Honest label: a static rollback completes via CI, not instantly (rux13).
2405
- rollbackBtn.textContent = isStatic ? "Roll back via CI" : "Roll back";
2406
- rollbackBtn.disabled = !canShip;
2407
- rollbackBtn.title = !canShip
2408
- ? "Requires an owner or ship-on-behalf sign-in"
2409
- : isStatic
2410
- ? "Dispatch a rollback to this version — completes via CI (not instant)"
2411
- : "Roll the live site back to this version";
2412
- rollbackBtn.addEventListener("click", () => rollbackVersion(v, rollbackBtn));
2413
- act.append(rollbackBtn);
2414
- }
2415
- tr.append(act);
2416
-
2417
- versionsBody.append(tr);
2418
- }
2419
- };
2420
-
2421
- const loadVersions = async () => {
2422
- if (!versionsBody) return;
2423
- try {
2424
- const res = await fetch(ds.versionsEndpoint, { headers: { accept: "application/json" } });
2425
- if (res.status === 401 || res.status === 403) {
2426
- if (versionsChip) versionsChip.textContent = "Sign-in required";
2427
- versionsBody.textContent = "";
2428
- const tr = document.createElement("tr");
2429
- const td = cell(subtle("Sign in as a store owner or admin to view published versions."));
2430
- td.colSpan = 6;
2431
- tr.append(td);
2432
- versionsBody.append(tr);
2433
- return;
2434
- }
2435
- const data = await res.json().catch(() => ({}));
2436
- if (!res.ok) {
2437
- setStatus(versionsStatus, data.error || "Could not load versions (" + res.status + ")", "err");
2438
- return;
2439
- }
2440
- renderVersions(data.view || {});
2441
- } catch {
2442
- setStatus(versionsStatus, "Could not load versions — network error", "err");
2443
- }
2444
- };
2445
-
2446
- // Interpret the rollback response into ONE honest terminal state (mirrors the
2447
- // pure lib/publish/shipWorkspace `interpretRollbackResponse`; duplicated in
2448
- // plain JS because is:inline scripts can't import modules). `rolledBack` is
2449
- // true ONLY for a verified `rolled_back` — a `publish_pending` is NEVER a
2450
- // rolled-back claim.
2451
- const interpretRollback = (httpOk, body) => {
2452
- const toVersionId = typeof body.toVersionId === "string" ? body.toVersionId : null;
2453
- if (typeof body.state === "string") {
2454
- const state = ["rolled_back", "publish_pending", "publish_failed", "blocked"].includes(body.state)
2455
- ? body.state
2456
- : "error";
2457
- return {
2458
- state,
2459
- rolledBack: state === "rolled_back",
2460
- message: body.message || body.error || "Rollback returned state " + state + ".",
2461
- };
2462
- }
2463
- if (httpOk && body.rolledBack === true) {
2464
- return {
2465
- state: "rolled_back",
2466
- rolledBack: true,
2467
- message: toVersionId ? "Rolled back live to " + shortSha(toVersionId) + "." : "Rolled back live.",
2468
- };
2469
- }
2470
- return {
2471
- state: "blocked",
2472
- rolledBack: false,
2473
- message: (body.error || "Rollback failed") + (body.reason ? " (" + body.reason + ")" : ""),
2474
- };
2475
- };
2476
-
2477
- const rollbackVersion = async (version, button) => {
2478
- // Static rollback (rux13) is an honest one-DISPATCH — completes via CI, not
2479
- // instantly; the confirm/status copy must never imply an instant flip.
2480
- const isStatic = rollbackMode === "static-archive";
2481
- const confirmMsg = isStatic
2482
- ? "Roll the static public site back to version " + shortSha(version.versionId) +
2483
- "? This DISPATCHES a rollback that completes via CI (not instantly) — the store keeps " +
2484
- "serving the current version until CI re-publishes the prior one."
2485
- : "Roll the live store back to version " + shortSha(version.versionId) +
2486
- "? This publishes that prior version to the live site.";
2487
- if (!window.confirm(confirmMsg)) return;
2488
- button.disabled = true;
2489
- setStatus(
2490
- versionsStatus,
2491
- isStatic
2492
- ? "Dispatching rollback to " + shortSha(version.versionId) + " (completes via CI)…"
2493
- : "Rolling back to " + shortSha(version.versionId) + "…",
2494
- );
2495
- try {
2496
- // The console dispatches by version id only; a static prior version's
2497
- // archive digest lives only in S3 (CI resolves it). Pass a digest ONLY when
2498
- // we honestly have one (never for a static prior — its digest is always null).
2499
- const payload = { targetVersionId: version.versionId };
2500
- if (version.digest) payload.targetDigest = version.digest;
2501
- const res = await fetch(ds.rollbackEndpoint, {
2502
- method: "POST",
2503
- headers: { "content-type": "application/json", "x-tot-capability": "ship-on-behalf" },
2504
- body: JSON.stringify(payload),
2505
- });
2506
- const data = await res.json().catch(() => ({}));
2507
- const outcome = interpretRollback(res.ok, data);
2508
- setStatus(versionsStatus, outcome.message, outcome.rolledBack ? "ok" : outcome.state === "publish_pending" ? "ok" : "err");
2509
- } catch {
2510
- setStatus(versionsStatus, "Rollback failed — network error", "err");
2511
- } finally {
2512
- button.disabled = false;
2513
- loadVersions();
2514
- loadQueue();
2515
- }
2516
- };
2517
-
2518
- // ---- Domain section ----------------------------------------------------
2519
-
2520
- const domainPanel = root.querySelector("[data-publish-domain]");
2521
- let domainPollTimer = null;
2522
-
2523
- const renderDomain = (payload) => {
2524
- if (!domainPanel) return;
2525
- const domain = payload.domain || {};
2526
- const stateEl = domainPanel.querySelector("[data-domain-state]");
2527
- const stateChip = domainPanel.querySelector("[data-domain-state-chip]");
2528
- const sinceEl = domainPanel.querySelector("[data-domain-since]");
2529
- const captureEl = domainPanel.querySelector("[data-domain-capture]");
2530
- const runEl = domainPanel.querySelector("[data-domain-run]");
2531
- const runDetailEl = domainPanel.querySelector("[data-domain-run-detail]");
2532
- const rollbackBtn = domainPanel.querySelector("[data-domain-rollback]");
2533
- const rollbackDetail = domainPanel.querySelector("[data-domain-rollback-detail]");
2534
- const connected = domain.state === "cloudfront";
2535
-
2536
- if (stateEl) {
2537
- stateEl.textContent = connected
2538
- ? "Storefront CDN (cloudfront)"
2539
- : "Previous host (pantheon)";
2540
- }
2541
- if (stateChip) {
2542
- stateChip.textContent = connected ? "Connected" : "Not connected";
2543
- stateChip.className = "chip " + (connected ? "green" : "amber");
2544
- }
2545
- if (sinceEl) {
2546
- sinceEl.textContent = domain.since
2547
- ? "Since " + new Date(domain.since).toLocaleString()
2548
- : "Current host for " + (payload.appDomain || ds.appDomain);
2549
- }
2550
- if (captureEl) {
2551
- captureEl.textContent = domain.priorCapturedAt
2552
- ? "Captured " + new Date(domain.priorCapturedAt).toLocaleString()
2553
- : "None captured";
2554
- }
2555
-
2556
- const run = domain.lastRun;
2557
- // "dispatched" = awaiting the CI completion callback (terminal-only wire).
2558
- const inFlight = run && run.status === "dispatched";
2559
- if (runEl) {
2560
- runEl.textContent = run
2561
- ? run.action + (run.rehearsal ? " (rehearsal)" : "") + " · " + run.status
2562
- : "None";
2563
- }
2564
- if (runDetailEl) {
2565
- runDetailEl.textContent = "";
2566
- if (run) {
2567
- const parts = [];
2568
- if (run.actor) parts.push("by " + run.actor);
2569
- if (run.startedAt) parts.push(age(run.startedAt));
2570
- runDetailEl.append(document.createTextNode(parts.join(" · ")));
2571
- if (run.runUrl) {
2572
- const link = document.createElement("a");
2573
- link.href = run.runUrl;
2574
- link.target = "_blank";
2575
- link.rel = "noopener";
2576
- link.textContent = "View run";
2577
- runDetailEl.append(document.createTextNode(" · "));
2578
- runDetailEl.append(link);
2579
- }
2580
- if (run.status === "failed" && run.error) {
2581
- const err = document.createElement("span");
2582
- err.className = "publish-error-detail";
2583
- err.textContent = run.error;
2584
- runDetailEl.append(document.createElement("br"));
2585
- runDetailEl.append(err);
2586
- }
2587
- } else {
2588
- runDetailEl.textContent = "Connect and rollback runs appear here.";
2589
- }
2590
- }
2591
- if (rollbackBtn) {
2592
- rollbackBtn.disabled =
2593
- !canShip || inFlight || !domain.priorRecordsKey;
2594
- }
2595
- if (rollbackDetail && domain.priorCapturedAt) {
2596
- rollbackDetail.textContent =
2597
- "Restores the DNS records captured " +
2598
- new Date(domain.priorCapturedAt).toLocaleString() + ".";
2599
- }
2600
-
2601
- // Poll while a run is in flight so completion lands without a manual refresh.
2602
- if (domainPollTimer) {
2603
- clearTimeout(domainPollTimer);
2604
- domainPollTimer = null;
2605
- }
2606
- if (inFlight) domainPollTimer = setTimeout(loadDomain, 15000);
2607
- };
2608
-
2609
- const loadDomain = async () => {
2610
- if (!domainPanel) return;
2611
- try {
2612
- const res = await fetch(ds.domainStatusEndpoint, {
2613
- headers: { accept: "application/json" },
2614
- });
2615
- if (!res.ok) return;
2616
- renderDomain(await res.json());
2617
- } catch {
2618
- /* leave the last rendered state */
2619
- }
2620
- // u9: refresh the readiness itemization alongside the status.
2621
- loadReadiness();
2622
- };
2623
-
2624
- // ---- Cutover readiness (u9) --------------------------------------------
2625
- // Reads the SAME server gate `tot go-live` reads (/api/domain/readiness) and
2626
- // itemizes the preconditions. The Connect button additionally requires the
2627
- // server to report ready — the display and the enforcement can't diverge.
2628
- const readinessBox = domainPanel?.querySelector("[data-domain-readiness]");
2629
- const connectBtn = domainPanel?.querySelector("[data-domain-connect]");
2630
- let domainReady = false;
2631
-
2632
- const renderReadiness = (payload) => {
2633
- if (!readinessBox) return;
2634
- const readiness = (payload && payload.readiness) || {};
2635
- const checks = Array.isArray(readiness.checks) ? readiness.checks : [];
2636
- domainReady = readiness.ready === true;
2637
- readinessBox.hidden = false;
2638
-
2639
- const chip = readinessBox.querySelector("[data-domain-readiness-chip]");
2640
- if (chip) {
2641
- chip.textContent = domainReady ? "Ready" : "Not ready";
2642
- chip.className = "chip " + (domainReady ? "green" : "amber");
2643
- }
2644
- const list = readinessBox.querySelector("[data-domain-readiness-list]");
2645
- if (list) {
2646
- list.textContent = "";
2647
- for (const c of checks) {
2648
- const li = document.createElement("li");
2649
- li.className = c.ok ? "ok" : "blocked";
2650
- const mark = document.createElement("span");
2651
- mark.className = "domain-readiness-mark";
2652
- mark.textContent = c.ok ? "✓" : "✗";
2653
- const label = document.createElement("b");
2654
- label.textContent = c.label || c.id || "";
2655
- li.append(mark, label);
2656
- if (c.detail) {
2657
- const detail = document.createElement("span");
2658
- detail.className = "domain-readiness-detail";
2659
- detail.textContent = c.detail;
2660
- li.append(detail);
2661
- }
2662
- list.append(li);
2663
- }
2664
- }
2665
- const note = readinessBox.querySelector("[data-domain-readiness-note]");
2666
- if (note) {
2667
- note.textContent = payload && payload.ownerCapable === false
2668
- ? "Apex cutover is owner-only — sign in as the store owner to connect the domain."
2669
- : domainReady
2670
- ? "All preconditions are green — the cutover is permitted."
2671
- : "Clear the failing preconditions above before connecting the apex.";
2672
- }
2673
- // Gate the Connect button on server readiness in ADDITION to owner (the
2674
- // markup already disables it for non-owners); never enable it when blocked.
2675
- if (connectBtn && !connectBtn.dataset.ownerLocked) {
2676
- connectBtn.disabled = !domainReady;
2677
- }
2678
- };
2679
-
2680
- const loadReadiness = async () => {
2681
- if (!readinessBox || !ds.domainReadinessEndpoint) return;
2682
- try {
2683
- const res = await fetch(ds.domainReadinessEndpoint, {
2684
- headers: { accept: "application/json", "x-tot-capability": "ship-on-behalf" },
2685
- });
2686
- if (!res.ok) return;
2687
- renderReadiness(await res.json());
2688
- } catch {
2689
- /* leave the last rendered readiness */
2690
- }
2691
- };
2692
-
2693
- const domainStatusEl = domainPanel?.querySelector("[data-domain-status]");
2694
-
2695
- const domainAction = async (body, button) => {
2696
- button.disabled = true;
2697
- setStatus(domainStatusEl, (body.action === "connect" ? "Connecting" : "Rolling back") + "…");
2698
- try {
2699
- const res = await fetch(ds.domainDispatchEndpoint, {
2700
- method: "POST",
2701
- headers: {
2702
- "content-type": "application/json",
2703
- "x-tot-capability": "ship-on-behalf",
2704
- },
2705
- body: JSON.stringify(body),
2706
- });
2707
- const data = await res.json().catch(() => ({}));
2708
- if (res.ok && data.dispatched) {
2709
- setStatus(
2710
- domainStatusEl,
2711
- (body.action === "connect" ? "Connect" : "Rollback") +
2712
- (body.rehearsal ? " rehearsal" : "") +
2713
- " dispatched — the run status updates below as it progresses.",
2714
- "ok",
2715
- );
2716
- } else {
2717
- setStatus(domainStatusEl, data.error || "Request failed (" + res.status + ")", "err");
2718
- }
2719
- } catch {
2720
- setStatus(domainStatusEl, "Request failed — network error", "err");
2721
- } finally {
2722
- button.disabled = false;
2723
- loadDomain();
2724
- }
2725
- };
2726
-
2727
- domainPanel?.querySelector("[data-domain-connect]")?.addEventListener("click", (event) => {
2728
- const confirmInput = domainPanel.querySelector("[data-domain-confirm]");
2729
- const rehearsal = Boolean(domainPanel.querySelector("[data-domain-rehearsal]")?.checked);
2730
- domainAction(
2731
- {
2732
- action: "connect",
2733
- confirmDomain: (confirmInput?.value || "").trim(),
2734
- rehearsal,
2735
- },
2736
- event.currentTarget,
2737
- );
2738
- });
2739
-
2740
- domainPanel?.querySelector("[data-domain-rollback]")?.addEventListener("click", (event) => {
2741
- if (
2742
- !window.confirm(
2743
- "Roll back " + ds.appDomain + " to the previous host? DNS returns to the captured records in about a minute.",
2744
- )
2745
- ) {
2746
- return;
2747
- }
2748
- domainAction({ action: "rollback" }, event.currentTarget);
2749
- });
2750
-
2751
- // ---- b17: branch retention ----------------------------------------------
2752
- // Renders the GET /api/changes/branches dry-run classification (already
2753
- // projected server-side by branchRetentionView.ts — this script only
2754
- // paints it, same division of labor as renderQueue/renderVersions above)
2755
- // and drives the guarded delete. The server (candidate_delete, b13)
2756
- // re-classifies fresh on every delete, so the confirm below is the HUMAN
2757
- // gate, not the safety guarantee — the safety guarantee is server-side.
2758
-
2759
- const branchesPanel = root.querySelector("[data-publish-branches]");
2760
- const branchesBody = branchesPanel?.querySelector("[data-branches-body]");
2761
- const branchesChip = branchesPanel?.querySelector("[data-branches-chip]");
2762
- const branchesStatus = branchesPanel?.querySelector("[data-branches-status]");
2763
-
2764
- const BRANCH_TONE = {
2765
- protected: "",
2766
- "active-open": "green",
2767
- "stale-open": "amber",
2768
- integrated: "blue",
2769
- "closed-or-rejected": "blue",
2770
- orphan: "red",
2771
- };
2772
-
2773
- const buildCleanupPlan = (row) => {
2774
- return [
2775
- "Delete branch plan:",
2776
- " repo: " + (appDomain || repo),
2777
- " branch: " + row.ref,
2778
- " tip sha: " + row.shortSha,
2779
- " classification: " + row.classificationLabel,
2780
- " reason: " + row.reason,
2781
- "",
2782
- "This deletes the Git BRANCH only — it never evicts a hosted preview build",
2783
- "(that is Retire, a separate action above). The server re-classifies this",
2784
- "branch fresh before deleting; a moved tip or a branch that is no longer",
2785
- "integrated/closed-or-rejected is refused, not silently skipped.",
2786
- ].join("\n");
2787
- };
2788
-
2789
- const cleanupBranch = async (row, button) => {
2790
- if (!window.confirm(buildCleanupPlan(row) + "\n\nDelete this branch?")) return;
2791
- button.disabled = true;
2792
- setStatus(branchesStatus, "Deleting " + row.shortRef + "…");
2793
- try {
2794
- const res = await fetch(ds.branchesEndpoint, {
2795
- method: "POST",
2796
- headers: { "content-type": "application/json", "x-tot-capability": "ship-on-behalf" },
2797
- body: JSON.stringify({ ref: row.ref, expectedSha: row.sha }),
2798
- });
2799
- const data = await res.json().catch(() => ({}));
2800
- if (res.ok && data.ok) {
2801
- setStatus(
2802
- branchesStatus,
2803
- data.alreadyAbsent
2804
- ? row.shortRef + " was already gone (nothing to delete)."
2805
- : "Deleted " + row.shortRef + ".",
2806
- "ok",
2807
- );
2808
- } else {
2809
- setStatus(branchesStatus, data.error || "Delete refused (" + res.status + ")", "err");
2810
- }
2811
- } catch {
2812
- setStatus(branchesStatus, "Delete failed — network error", "err");
2813
- } finally {
2814
- button.disabled = false;
2815
- loadBranches();
2816
- }
2817
- };
2818
-
2819
- const renderBranches = (view) => {
2820
- if (!branchesBody) return;
2821
- const rows = Array.isArray(view.rows) ? view.rows : [];
2822
- if (branchesChip) {
2823
- const needsReview = rows.filter((r) => r.quarantine || r.eligibleForDelete).length;
2824
- branchesChip.textContent = needsReview
2825
- ? needsReview + " to review"
2826
- : rows.length
2827
- ? rows.length + " branches"
2828
- : "0 branches";
2829
- branchesChip.className = "chip" + (needsReview ? " amber" : "");
2830
- }
2831
- branchesBody.textContent = "";
2832
- if (!rows.length) {
2833
- const tr = document.createElement("tr");
2834
- const td = cell(subtle("No candidate branches found for this repo."));
2835
- td.colSpan = 7;
2836
- tr.append(td);
2837
- branchesBody.append(tr);
2838
- return;
2839
- }
2840
-
2841
- for (const row of rows) {
2842
- const tr = document.createElement("tr");
2843
-
2844
- const branchCell = document.createElement("td");
2845
- const branchStrong = document.createElement("strong");
2846
- branchStrong.textContent = row.shortRef;
2847
- branchCell.append(branchStrong, subtle(row.ref + " @ " + row.shortSha));
2848
- tr.append(branchCell);
2849
-
2850
- tr.append(cell(chip(row.classificationLabel, BRANCH_TONE[row.classification] || "")));
2851
-
2852
- const prCell = document.createElement("td");
2853
- if (row.prNumber != null) {
2854
- // Link to the INTERNAL friendly PR route (/preview/<tenant>/pr/<N>), never
2855
- // the server-provided `row.prUrl` — that is the raw Gitea forge html_url the
2856
- // MCP candidate_list projection emits (<forge-host>/<org>/<repo>/pulls/N),
2857
- // and surfacing a raw forge link to an owner is exactly the boundary
2858
- // noGiteaLinks.test.ts guards (the source scan can't catch a host that
2859
- // arrives in data, so we refuse it here at render). Mirrors the candidate
2860
- // queue, which already builds its preview link this way.
2861
- const prHref = candidatePrUrl(row.prNumber);
2862
- if (prHref) {
2863
- const a = document.createElement("a");
2864
- a.href = prHref;
2865
- a.target = "_blank";
2866
- a.rel = "noopener";
2867
- a.textContent = "PR #" + row.prNumber;
2868
- prCell.append(a);
2869
- } else {
2870
- prCell.append(document.createTextNode("PR #" + row.prNumber));
2871
- }
2872
- prCell.append(subtle((row.prState || "") + (row.integratedIntoAggregate ? " · in aggregate" : "")));
2873
- } else {
2874
- prCell.append(subtle("No PR record"));
2875
- }
2876
- tr.append(prCell);
2877
-
2878
- tr.append(cell(row.commitTimestampDisplay));
2879
- tr.append(cell(row.ageLabel));
2880
- tr.append(cell(row.evidenceSummary));
2881
-
2882
- const actionsCell = document.createElement("td");
2883
- actionsCell.className = "action";
2884
- if (row.quarantine) {
2885
- actionsCell.append(chip("Needs owner review", "red"));
2886
- } else if (row.eligibleForDelete) {
2887
- const btn = document.createElement("button");
2888
- btn.type = "button";
2889
- btn.className = "btn";
2890
- btn.disabled = !canShip;
2891
- btn.title = canShip ? "" : "Requires an owner/admin sign-in.";
2892
- btn.textContent = "Clean up";
2893
- btn.addEventListener("click", () => cleanupBranch(row, btn));
2894
- actionsCell.append(btn);
2895
- } else {
2896
- actionsCell.append(subtle("Keep"));
2897
- }
2898
- tr.append(actionsCell);
2899
-
2900
- branchesBody.append(tr);
2901
- }
2902
- };
2903
-
2904
- const loadBranches = async () => {
2905
- if (!branchesBody) return;
2906
- try {
2907
- const res = await fetch(ds.branchesEndpoint, { headers: { accept: "application/json" } });
2908
- if (res.status === 401 || res.status === 403) {
2909
- if (branchesChip) branchesChip.textContent = "Sign-in required";
2910
- branchesBody.textContent = "";
2911
- const tr = document.createElement("tr");
2912
- const td = cell(subtle("Sign in as a store owner or admin to view branch retention."));
2913
- td.colSpan = 7;
2914
- tr.append(td);
2915
- branchesBody.append(tr);
2916
- return;
2917
- }
2918
- const data = await res.json().catch(() => ({}));
2919
- if (!res.ok) {
2920
- setStatus(branchesStatus, data.error || "Could not load branch classification (" + res.status + ")", "err");
2921
- return;
2922
- }
2923
- renderBranches(data.report || {});
2924
- } catch {
2925
- setStatus(branchesStatus, "Could not load branch classification — network error", "err");
2926
- }
2927
- };
2928
-
2929
- // ---- Wiring ------------------------------------------------------------
2930
-
2931
- root.querySelector("[data-publish-refresh]")?.addEventListener("click", () => {
2932
- setStatus(statusEl, "");
2933
- loadQueue();
2934
- loadVersions();
2935
- loadDomain();
2936
- loadBranches();
2937
- });
2938
-
2939
- // rux7: pause polling while hidden; on return, refresh immediately (loadQueue
2940
- // re-renders + resyncs the poll clock) rather than waiting out the interval.
2941
- document.addEventListener("visibilitychange", () => {
2942
- if (document.hidden) {
2943
- clearPoll();
2944
- } else {
2945
- loadQueue();
2946
- }
2947
- });
2948
-
2949
- // loadQueue starts the poll cadence via its tail (schedulePoll).
2950
- loadQueue();
2951
- loadVersions();
2952
- loadDomain();
2953
- loadBranches();
2954
- })();
904
+ <script>
905
+ import { initAdminPublishTab } from "@/lib/publish/adminPublishTab";
906
+ initAdminPublishTab();
2955
907
  </script>
2956
908
 
2957
909
  <style>
@@ -2972,6 +924,19 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
2972
924
  margin-left: 6px;
2973
925
  }
2974
926
 
927
+ /* The per-row orphan "Delete this branch" action — a deliberate, destructive,
928
+ one-at-a-time HUMAN delete, styled distinct from the neutral "Clean up" and the
929
+ bulk "Sweep dead branches" so it never reads as a routine cleanup. */
930
+ .btn.branch-delete-orphan {
931
+ border-color: var(--admin-danger, #b3261e);
932
+ color: var(--admin-danger, #b3261e);
933
+ }
934
+
935
+ .btn.branch-delete-orphan:not(:disabled):hover {
936
+ background: var(--admin-danger, #b3261e);
937
+ color: #fff;
938
+ }
939
+
2975
940
  .publish-status {
2976
941
  min-height: 0;
2977
942
  }
@@ -2988,6 +953,17 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
2988
953
  color: var(--admin-red);
2989
954
  }
2990
955
 
956
+ /* Public-site status card, verified-current tone — .risk-alert defaults to an
957
+ amber/warning look (admin.astro), wrong for "this is fine, confirmed fresh". */
958
+ .risk-alert.public-site-ok {
959
+ border-color: var(--admin-green);
960
+ background: var(--admin-green-soft);
961
+ }
962
+
963
+ .risk-alert.public-site-ok svg {
964
+ color: var(--admin-green);
965
+ }
966
+
2991
967
  /* ?pr=N deep link: "not in the queue" callout + row flash */
2992
968
  .publish-pr-callout {
2993
969
  border: 1px solid var(--admin-line-strong);
@@ -3127,6 +1103,126 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
3127
1103
  margin-top: 16px;
3128
1104
  }
3129
1105
 
1106
+ /* Merge-conflict guidance (outcome phase, reason "merge_failed" only) —
1107
+ directions, not mood: the terminal recovery front and center, the forge's
1108
+ raw refusal kept small underneath for support/diagnosis. Left-aligned
1109
+ inside the centered outcome phase: commands and prose read as
1110
+ instructions, not ceremony. */
1111
+ .liftoff-conflict {
1112
+ margin-top: 10px;
1113
+ text-align: left;
1114
+ }
1115
+
1116
+ .liftoff-commands {
1117
+ margin: 10px 0 8px;
1118
+ padding: 10px 12px;
1119
+ border: 1px solid var(--admin-line-strong);
1120
+ border-radius: var(--admin-radius-sm);
1121
+ background: var(--admin-surface-soft);
1122
+ font-size: 12px;
1123
+ line-height: 1.55;
1124
+ overflow-x: auto;
1125
+ white-space: pre;
1126
+ }
1127
+
1128
+ .liftoff-conflict-actions {
1129
+ display: flex;
1130
+ justify-content: flex-end;
1131
+ gap: 8px;
1132
+ flex-wrap: wrap;
1133
+ }
1134
+
1135
+ .liftoff-conflict-raw {
1136
+ margin: 10px 0 0;
1137
+ font-size: 11px;
1138
+ color: var(--admin-muted);
1139
+ overflow-wrap: anywhere;
1140
+ }
1141
+
1142
+ /* u4 — automate-first recovery: the primary action leads, option cards appear
1143
+ only on a genuine overlap, the terminal guidance is a collapsed fallback. */
1144
+ .liftoff-conflict-summary {
1145
+ margin: 0 0 10px;
1146
+ }
1147
+ .liftoff-conflict-primary {
1148
+ display: flex;
1149
+ flex-direction: column;
1150
+ align-items: flex-start;
1151
+ gap: 8px;
1152
+ margin-bottom: 12px;
1153
+ }
1154
+ .liftoff-conflict-primary .btn.primary {
1155
+ align-self: flex-start;
1156
+ }
1157
+ .liftoff-conflict-primary-status[data-state="err"],
1158
+ .liftoff-conflict-cards-status[data-state="err"] {
1159
+ color: var(--admin-danger, #b3261e);
1160
+ }
1161
+ .liftoff-conflict-cards {
1162
+ margin: 4px 0 12px;
1163
+ padding: 12px;
1164
+ border: 1px solid var(--admin-line-strong);
1165
+ border-radius: var(--admin-radius-sm);
1166
+ background: var(--admin-surface-soft);
1167
+ }
1168
+ .liftoff-conflict-files {
1169
+ list-style: none;
1170
+ margin: 8px 0 12px;
1171
+ padding: 8px 10px;
1172
+ border-radius: var(--admin-radius-sm);
1173
+ background: var(--admin-surface, #fff);
1174
+ font-size: 12px;
1175
+ line-height: 1.6;
1176
+ overflow-x: auto;
1177
+ }
1178
+ .liftoff-conflict-card-grid {
1179
+ display: grid;
1180
+ grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
1181
+ gap: 8px;
1182
+ }
1183
+ .liftoff-option-card {
1184
+ display: flex;
1185
+ flex-direction: column;
1186
+ gap: 4px;
1187
+ text-align: left;
1188
+ padding: 12px;
1189
+ border: 1px solid var(--admin-line-strong);
1190
+ border-radius: var(--admin-radius-sm);
1191
+ background: var(--admin-surface, #fff);
1192
+ cursor: pointer;
1193
+ font: inherit;
1194
+ color: inherit;
1195
+ }
1196
+ .liftoff-option-card:hover:not(:disabled) {
1197
+ border-color: var(--admin-accent, #0f9d8f);
1198
+ }
1199
+ .liftoff-option-card:disabled {
1200
+ opacity: 0.55;
1201
+ cursor: default;
1202
+ }
1203
+ .liftoff-option-card[data-recommended="1"] {
1204
+ border-color: var(--admin-accent, #0f9d8f);
1205
+ box-shadow: inset 0 0 0 1px var(--admin-accent, #0f9d8f);
1206
+ }
1207
+ .liftoff-option-card b {
1208
+ font-size: 13px;
1209
+ }
1210
+ .liftoff-option-card span {
1211
+ font-size: 11px;
1212
+ color: var(--admin-muted);
1213
+ }
1214
+ .liftoff-conflict-expert {
1215
+ margin-top: 10px;
1216
+ border-top: 1px solid var(--admin-line, #e5e5e5);
1217
+ padding-top: 8px;
1218
+ }
1219
+ .liftoff-conflict-expert > summary {
1220
+ cursor: pointer;
1221
+ font-size: 12px;
1222
+ color: var(--admin-muted);
1223
+ user-select: none;
1224
+ }
1225
+
3130
1226
  .liftoff-stages {
3131
1227
  list-style: none;
3132
1228
  margin: 6px 0 4px;
@@ -3369,14 +1465,19 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
3369
1465
  gap: 0.25rem;
3370
1466
  }
3371
1467
  .domain-readiness-list li {
1468
+ display: grid;
1469
+ gap: 0.1rem;
1470
+ font-size: 0.9em;
1471
+ }
1472
+ .domain-readiness-item-head {
3372
1473
  display: flex;
3373
1474
  align-items: baseline;
3374
1475
  gap: 0.4rem;
3375
- font-size: 0.9em;
3376
1476
  }
3377
1477
  .domain-readiness-mark {
3378
1478
  font-weight: 700;
3379
1479
  width: 1em;
1480
+ flex: 0 0 auto;
3380
1481
  }
3381
1482
  .domain-readiness-list li.ok .domain-readiness-mark {
3382
1483
  color: var(--good, #1a7f37);
@@ -3384,9 +1485,20 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
3384
1485
  .domain-readiness-list li.blocked .domain-readiness-mark {
3385
1486
  color: var(--bad, #b42318);
3386
1487
  }
1488
+ /* detail + remedy sit on their OWN lines, indented under the label (past the
1489
+ mark) so neither runs together with the bold label above it. */
1490
+ .domain-readiness-detail,
1491
+ .domain-readiness-remedy {
1492
+ margin: 0;
1493
+ padding-left: 1.4em;
1494
+ }
3387
1495
  .domain-readiness-detail {
3388
1496
  opacity: 0.75;
3389
1497
  }
1498
+ .domain-readiness-remedy {
1499
+ color: var(--accent, #0b6bcb);
1500
+ opacity: 0.95;
1501
+ }
3390
1502
 
3391
1503
  /* b11: aggregate card + ship plan */
3392
1504
  .aggregate-prs {
@@ -3404,11 +1516,24 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
3404
1516
 
3405
1517
  .aggregate-prs-list li {
3406
1518
  display: flex;
3407
- align-items: baseline;
3408
- gap: 10px;
1519
+ align-items: center;
1520
+ gap: 8px;
3409
1521
  font-size: 13px;
3410
1522
  }
3411
1523
 
1524
+ /* u14 — provenance ("integrated <age> by <email>") sits after the sha, subtle. */
1525
+ .aggregate-pr-meta {
1526
+ font-size: 12px;
1527
+ }
1528
+
1529
+ /* u14 — the per-change Undo (revert) button is pushed to the row's trailing edge
1530
+ and kept compact so the batch reads as a list, not a stack of buttons. */
1531
+ .aggregate-prs-list .btn-compact {
1532
+ margin-left: auto;
1533
+ padding: 2px 10px;
1534
+ font-size: 12px;
1535
+ }
1536
+
3412
1537
  .aggregate-plan {
3413
1538
  padding: 0.75rem 1rem;
3414
1539
  border: 1px solid var(--hairline, rgba(0, 0, 0, 0.12));
@@ -3441,6 +1566,652 @@ const domainReadinessEndpoint = withBase(basePath || "", "/api/domain/readiness"
3441
1566
  overflow-wrap: anywhere;
3442
1567
  }
3443
1568
 
1569
+ /* ── Preview-aggregate console — the go-live surface ─────────────────────
1570
+ Everything here is scoped under [data-publish-aggregate] / .agg-* so it
1571
+ never leaks into the other panels (candidate queue, versions, branches)
1572
+ that share .panel / .field / .check-row / .chip. */
1573
+ .agg-console .panel-body {
1574
+ gap: 16px;
1575
+ }
1576
+
1577
+ [data-publish-aggregate] .sha-token {
1578
+ display: inline-flex;
1579
+ align-items: center;
1580
+ padding: 2px 8px;
1581
+ border: 1px solid var(--admin-line-strong);
1582
+ border-radius: 5px;
1583
+ background: var(--admin-surface-soft);
1584
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
1585
+ font-size: 12.5px;
1586
+ color: var(--admin-ink);
1587
+ }
1588
+ [data-publish-aggregate] .sha-token.ghost {
1589
+ background: transparent;
1590
+ color: var(--admin-muted);
1591
+ border-style: dashed;
1592
+ }
1593
+
1594
+ /* AI-assembled release summary */
1595
+ .agg-summary {
1596
+ display: grid;
1597
+ gap: 11px;
1598
+ padding: 15px 16px;
1599
+ border: 1px solid var(--admin-line);
1600
+ border-radius: var(--admin-radius);
1601
+ background:
1602
+ linear-gradient(180deg, var(--admin-teal-soft), transparent 62%),
1603
+ var(--admin-surface);
1604
+ }
1605
+ .agg-summary[hidden] {
1606
+ display: none;
1607
+ }
1608
+ .agg-summary-head {
1609
+ display: flex;
1610
+ align-items: center;
1611
+ gap: 10px;
1612
+ }
1613
+ .agg-summary-glyph {
1614
+ flex: none;
1615
+ width: 26px;
1616
+ height: 26px;
1617
+ display: grid;
1618
+ place-items: center;
1619
+ border-radius: 7px;
1620
+ background: var(--admin-surface);
1621
+ color: var(--admin-teal-dark);
1622
+ border: 1px solid color-mix(in srgb, var(--admin-teal) 30%, transparent);
1623
+ }
1624
+ /* The sparkle glyphs are filled shapes; opt out of the global stroked-svg rule. */
1625
+ .agg-summary-glyph svg,
1626
+ .agg-ai-chip svg {
1627
+ fill: currentColor;
1628
+ stroke: none;
1629
+ }
1630
+ .agg-summary-glyph svg {
1631
+ width: 15px;
1632
+ height: 15px;
1633
+ }
1634
+ .agg-summary-label {
1635
+ flex: 1;
1636
+ font-size: 11px;
1637
+ font-weight: 760;
1638
+ letter-spacing: 0.08em;
1639
+ text-transform: uppercase;
1640
+ color: var(--admin-muted);
1641
+ }
1642
+ .agg-ai-chip {
1643
+ display: inline-flex;
1644
+ align-items: center;
1645
+ gap: 5px;
1646
+ padding: 3px 9px;
1647
+ border-radius: 999px;
1648
+ background: var(--admin-teal-soft);
1649
+ color: #007973;
1650
+ font-size: 10px;
1651
+ font-weight: 760;
1652
+ letter-spacing: 0.06em;
1653
+ text-transform: uppercase;
1654
+ }
1655
+ .agg-ai-chip svg {
1656
+ width: 10px;
1657
+ height: 10px;
1658
+ }
1659
+ .agg-summary-lead {
1660
+ margin: 0;
1661
+ font-size: 15px;
1662
+ line-height: 1.55;
1663
+ color: var(--admin-ink);
1664
+ max-width: 68ch;
1665
+ }
1666
+ .agg-summary-points {
1667
+ list-style: none;
1668
+ margin: 0;
1669
+ padding: 0;
1670
+ display: grid;
1671
+ gap: 7px;
1672
+ }
1673
+ .agg-summary-points[hidden] {
1674
+ display: none;
1675
+ }
1676
+ .agg-summary-points li {
1677
+ display: flex;
1678
+ align-items: flex-start;
1679
+ gap: 9px;
1680
+ font-size: 13px;
1681
+ color: var(--admin-muted);
1682
+ line-height: 1.45;
1683
+ }
1684
+ .agg-summary-points .agg-tick {
1685
+ flex: none;
1686
+ margin-top: 1px;
1687
+ width: 16px;
1688
+ height: 16px;
1689
+ border-radius: 50%;
1690
+ display: grid;
1691
+ place-items: center;
1692
+ background: var(--admin-green-soft);
1693
+ color: var(--admin-green);
1694
+ }
1695
+ .agg-summary-points .agg-tick svg {
1696
+ width: 10px;
1697
+ height: 10px;
1698
+ }
1699
+ .agg-summary-points b {
1700
+ color: var(--admin-ink);
1701
+ font-weight: 640;
1702
+ }
1703
+
1704
+ /* Chain of custody: build → evidence → digest */
1705
+ .agg-chain {
1706
+ display: grid;
1707
+ grid-template-columns: 1fr auto 1fr auto 1fr;
1708
+ align-items: stretch;
1709
+ padding: 16px;
1710
+ border: 1px solid var(--admin-line);
1711
+ border-radius: var(--admin-radius);
1712
+ background: var(--admin-surface-soft);
1713
+ }
1714
+ .agg-stop {
1715
+ display: flex;
1716
+ flex-direction: column;
1717
+ gap: 7px;
1718
+ padding: 2px 12px;
1719
+ min-width: 0;
1720
+ }
1721
+ .agg-stop:first-child {
1722
+ padding-left: 2px;
1723
+ }
1724
+ .agg-stop:last-child {
1725
+ padding-right: 2px;
1726
+ }
1727
+ .agg-stop-label {
1728
+ font-size: 10.5px;
1729
+ font-weight: 760;
1730
+ letter-spacing: 0.08em;
1731
+ text-transform: uppercase;
1732
+ color: var(--admin-muted);
1733
+ }
1734
+ .agg-stop-val {
1735
+ display: flex;
1736
+ align-items: center;
1737
+ gap: 8px;
1738
+ font-size: 15px;
1739
+ font-weight: 680;
1740
+ }
1741
+ .agg-stop-val strong {
1742
+ font-size: 15px;
1743
+ }
1744
+ .agg-stop-cap {
1745
+ margin: 0;
1746
+ font-size: 12px;
1747
+ color: var(--admin-muted);
1748
+ line-height: 1.45;
1749
+ }
1750
+ .agg-stop-cap a {
1751
+ white-space: nowrap;
1752
+ }
1753
+ .agg-digest {
1754
+ padding: 2px 8px;
1755
+ border: 1px solid color-mix(in srgb, var(--admin-teal) 55%, var(--admin-line-strong));
1756
+ border-radius: 5px;
1757
+ background: var(--admin-teal-soft);
1758
+ color: #007973;
1759
+ }
1760
+ [data-publish-aggregate] [data-aggregate-evidence][data-state="passed"] {
1761
+ color: var(--admin-green);
1762
+ }
1763
+ [data-publish-aggregate] [data-aggregate-evidence][data-state="failed"] {
1764
+ color: var(--admin-red);
1765
+ }
1766
+ .agg-link {
1767
+ display: flex;
1768
+ flex-direction: column;
1769
+ align-items: center;
1770
+ justify-content: center;
1771
+ gap: 6px;
1772
+ padding: 0 2px;
1773
+ align-self: center;
1774
+ }
1775
+ .agg-flowlabel {
1776
+ font-size: 9px;
1777
+ font-weight: 720;
1778
+ letter-spacing: 0.06em;
1779
+ text-transform: uppercase;
1780
+ color: var(--admin-muted-2);
1781
+ }
1782
+ .agg-arrow {
1783
+ display: grid;
1784
+ place-items: center;
1785
+ color: var(--admin-teal);
1786
+ }
1787
+ .agg-arrow svg {
1788
+ width: 32px;
1789
+ height: 10px;
1790
+ }
1791
+
1792
+ /* Staged → live delta strip */
1793
+ .agg-delta-strip {
1794
+ display: flex;
1795
+ align-items: center;
1796
+ gap: 12px;
1797
+ flex-wrap: wrap;
1798
+ padding: 10px 13px;
1799
+ border: 1px solid var(--admin-line);
1800
+ border-radius: var(--admin-radius-sm);
1801
+ background: var(--admin-surface-soft);
1802
+ }
1803
+ .agg-delta-strip[hidden] {
1804
+ display: none;
1805
+ }
1806
+ .agg-delta-node {
1807
+ display: flex;
1808
+ flex-direction: column;
1809
+ gap: 3px;
1810
+ }
1811
+ .agg-delta-mid {
1812
+ display: flex;
1813
+ align-items: center;
1814
+ gap: 8px;
1815
+ color: var(--admin-teal);
1816
+ }
1817
+ .agg-delta-mid svg {
1818
+ width: 24px;
1819
+ height: 10px;
1820
+ }
1821
+ .agg-delta-count {
1822
+ padding: 2px 9px;
1823
+ border-radius: 999px;
1824
+ background: var(--admin-teal-soft);
1825
+ color: #007973;
1826
+ font-size: 11.5px;
1827
+ font-weight: 720;
1828
+ }
1829
+
1830
+ /* Staged change rows (richer than the plain PR list) */
1831
+ .agg-changes li.agg-change {
1832
+ display: grid;
1833
+ grid-template-columns: 1fr auto;
1834
+ align-items: center;
1835
+ gap: 12px;
1836
+ padding: 10px 12px;
1837
+ border: 1px solid var(--admin-line);
1838
+ border-radius: var(--admin-radius-sm);
1839
+ background: var(--admin-surface);
1840
+ }
1841
+ .agg-change-main {
1842
+ display: grid;
1843
+ gap: 4px;
1844
+ min-width: 0;
1845
+ }
1846
+ .agg-change-line {
1847
+ display: flex;
1848
+ align-items: center;
1849
+ gap: 10px;
1850
+ flex-wrap: wrap;
1851
+ }
1852
+ .agg-change-pr {
1853
+ font-weight: 720;
1854
+ font-size: 13px;
1855
+ }
1856
+ .agg-change-title {
1857
+ font-weight: 600;
1858
+ font-size: 13.5px;
1859
+ }
1860
+ .agg-change-sub {
1861
+ color: var(--admin-muted);
1862
+ font-size: 12px;
1863
+ }
1864
+
1865
+ /* Publish plan → launch manifest */
1866
+ [data-publish-aggregate] .agg-manifest {
1867
+ display: block;
1868
+ padding: 0;
1869
+ overflow: hidden;
1870
+ background:
1871
+ linear-gradient(180deg, var(--admin-surface-tint), transparent 46px),
1872
+ var(--admin-surface);
1873
+ }
1874
+ .agg-manifest-head {
1875
+ padding: 12px 15px;
1876
+ border-bottom: 1px dashed var(--admin-line-strong);
1877
+ }
1878
+ .agg-manifest-head b {
1879
+ display: flex;
1880
+ align-items: center;
1881
+ gap: 8px;
1882
+ font-size: 13px;
1883
+ }
1884
+ .agg-manifest-head b svg {
1885
+ width: 15px;
1886
+ height: 15px;
1887
+ color: var(--admin-teal);
1888
+ }
1889
+ [data-publish-aggregate] .agg-manifest .aggregate-plan-grid {
1890
+ padding: 8px 15px 12px;
1891
+ }
1892
+ [data-publish-aggregate] .agg-manifest > .note {
1893
+ margin: 0;
1894
+ padding: 11px 15px;
1895
+ border-top: 1px dashed var(--admin-line-strong);
1896
+ background: var(--admin-surface-soft);
1897
+ }
1898
+
1899
+ /* Openable "Included changes" */
1900
+ .agg-included {
1901
+ border-top: 1px dashed var(--admin-line-strong);
1902
+ }
1903
+ .agg-included[hidden] {
1904
+ display: none;
1905
+ }
1906
+ .agg-included-details > summary {
1907
+ list-style: none;
1908
+ cursor: pointer;
1909
+ display: flex;
1910
+ align-items: center;
1911
+ gap: 10px;
1912
+ padding: 11px 15px;
1913
+ font-size: 12px;
1914
+ color: var(--admin-muted);
1915
+ }
1916
+ .agg-included-details > summary::-webkit-details-marker {
1917
+ display: none;
1918
+ }
1919
+ .agg-included-details > summary::marker {
1920
+ content: "";
1921
+ }
1922
+ .agg-included-details > summary:focus-visible {
1923
+ outline: 2px solid var(--admin-teal);
1924
+ outline-offset: -2px;
1925
+ }
1926
+ .agg-included-lead {
1927
+ font-size: 11px;
1928
+ font-weight: 740;
1929
+ letter-spacing: 0.03em;
1930
+ text-transform: uppercase;
1931
+ color: var(--admin-ink);
1932
+ }
1933
+ .agg-included-badge {
1934
+ padding: 1px 8px;
1935
+ border-radius: 999px;
1936
+ background: var(--admin-surface-tint);
1937
+ color: #3f4d49;
1938
+ font-size: 11.5px;
1939
+ font-weight: 720;
1940
+ }
1941
+ .agg-included-hint {
1942
+ color: var(--admin-muted-2);
1943
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
1944
+ font-size: 11.5px;
1945
+ overflow: hidden;
1946
+ text-overflow: ellipsis;
1947
+ white-space: nowrap;
1948
+ }
1949
+ .agg-chev {
1950
+ margin-left: auto;
1951
+ display: inline-flex;
1952
+ color: var(--admin-muted-2);
1953
+ transition: transform 0.18s ease;
1954
+ }
1955
+ .agg-chev svg {
1956
+ width: 14px;
1957
+ height: 14px;
1958
+ }
1959
+ .agg-included-details[open] > summary .agg-chev {
1960
+ transform: rotate(90deg);
1961
+ }
1962
+ @media (prefers-reduced-motion: reduce) {
1963
+ .agg-chev {
1964
+ transition: none;
1965
+ }
1966
+ }
1967
+ .agg-included-list {
1968
+ list-style: none;
1969
+ margin: 0;
1970
+ padding: 0 15px 14px;
1971
+ display: grid;
1972
+ gap: 8px;
1973
+ }
1974
+ .agg-included-item {
1975
+ display: grid;
1976
+ gap: 5px;
1977
+ padding: 11px 12px;
1978
+ border: 1px solid var(--admin-line);
1979
+ border-radius: var(--admin-radius-sm);
1980
+ background: var(--admin-surface-soft);
1981
+ }
1982
+ .agg-included-top {
1983
+ display: flex;
1984
+ align-items: center;
1985
+ gap: 10px;
1986
+ flex-wrap: wrap;
1987
+ }
1988
+ .agg-included-pr {
1989
+ font-weight: 720;
1990
+ font-size: 13px;
1991
+ }
1992
+ .agg-included-title {
1993
+ font-weight: 600;
1994
+ font-size: 13.5px;
1995
+ }
1996
+ .agg-included-desc {
1997
+ margin: 0;
1998
+ color: var(--admin-muted);
1999
+ font-size: 12.5px;
2000
+ line-height: 1.5;
2001
+ }
2002
+ .agg-included-meta {
2003
+ display: flex;
2004
+ align-items: center;
2005
+ gap: 6px;
2006
+ flex-wrap: wrap;
2007
+ color: var(--admin-muted-2);
2008
+ font-size: 11.5px;
2009
+ }
2010
+ .agg-included-meta > span + span::before {
2011
+ content: "·";
2012
+ padding-right: 6px;
2013
+ color: var(--admin-line-strong);
2014
+ }
2015
+ .agg-included-meta .sha-token {
2016
+ font-size: 11px;
2017
+ padding: 1px 6px;
2018
+ }
2019
+
2020
+ /* Published-versions "what shipped": the release summary lead + openable
2021
+ per-change list, inline in the Version cell. Reuses the .agg-included-*
2022
+ item markup; only the container chrome is retuned for a table cell. */
2023
+ .ver-summary {
2024
+ margin: 6px 0 0;
2025
+ color: var(--admin-muted);
2026
+ font-size: 12.5px;
2027
+ line-height: 1.5;
2028
+ max-width: 48ch;
2029
+ }
2030
+ .ver-changes {
2031
+ margin-top: 8px;
2032
+ border: 1px solid var(--admin-line);
2033
+ border-radius: var(--admin-radius-sm);
2034
+ background: var(--admin-surface-soft);
2035
+ }
2036
+ .ver-changes > summary {
2037
+ padding: 8px 10px;
2038
+ }
2039
+ .ver-changes .agg-included-list {
2040
+ padding: 0 10px 10px;
2041
+ }
2042
+
2043
+ /* Branch-retention "what this branch changes": the PR title + one-line
2044
+ description + scope meta, inline under the branch ref. */
2045
+ .branch-pr-title {
2046
+ margin: 6px 0 0;
2047
+ font-weight: 600;
2048
+ font-size: 13px;
2049
+ color: var(--admin-ink);
2050
+ max-width: 46ch;
2051
+ }
2052
+ .branch-pr-desc {
2053
+ margin: 3px 0 0;
2054
+ color: var(--admin-muted);
2055
+ font-size: 12.5px;
2056
+ line-height: 1.5;
2057
+ max-width: 46ch;
2058
+ }
2059
+ .branch-pr-meta {
2060
+ margin-top: 5px;
2061
+ }
2062
+ .branch-pr-ai {
2063
+ color: var(--admin-teal-dark);
2064
+ font-weight: 640;
2065
+ }
2066
+
2067
+ /* Scope-of-change: lines added/removed (green/red), + the top-level readout */
2068
+ .agg-lines {
2069
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
2070
+ font-variant-numeric: tabular-nums;
2071
+ white-space: nowrap;
2072
+ }
2073
+ .agg-add {
2074
+ color: var(--admin-green);
2075
+ }
2076
+ .agg-del {
2077
+ color: var(--admin-red);
2078
+ }
2079
+
2080
+ /* "View diff" disclosure for a trivial change (the diff IS its summary). */
2081
+ .agg-diff {
2082
+ margin-top: 2px;
2083
+ }
2084
+ .agg-diff > summary {
2085
+ cursor: pointer;
2086
+ font-size: 11.5px;
2087
+ font-weight: 640;
2088
+ color: var(--admin-teal-dark);
2089
+ width: max-content;
2090
+ }
2091
+ .agg-diff[open] > summary {
2092
+ margin-bottom: 6px;
2093
+ }
2094
+ .agg-diff-file {
2095
+ margin-top: 6px;
2096
+ }
2097
+ .agg-diff-path {
2098
+ font-size: 11px;
2099
+ color: var(--admin-muted);
2100
+ margin-bottom: 3px;
2101
+ }
2102
+ .agg-diff-patch {
2103
+ margin: 0;
2104
+ padding: 8px 10px;
2105
+ border: 1px solid var(--admin-line);
2106
+ border-radius: var(--admin-radius-sm);
2107
+ background: var(--admin-surface);
2108
+ font-size: 11.5px;
2109
+ line-height: 1.5;
2110
+ overflow-x: auto;
2111
+ white-space: pre;
2112
+ }
2113
+ .agg-diff-add {
2114
+ color: var(--admin-green);
2115
+ background: var(--admin-green-soft);
2116
+ }
2117
+ .agg-diff-del {
2118
+ color: var(--admin-red);
2119
+ background: var(--admin-red-soft);
2120
+ }
2121
+ .agg-diff-hunk {
2122
+ color: var(--admin-muted-2);
2123
+ }
2124
+
2125
+ .agg-staged-head {
2126
+ display: flex;
2127
+ align-items: baseline;
2128
+ justify-content: space-between;
2129
+ gap: 12px;
2130
+ flex-wrap: wrap;
2131
+ }
2132
+ .agg-scope {
2133
+ display: inline-flex;
2134
+ align-items: center;
2135
+ gap: 8px;
2136
+ padding: 3px 10px;
2137
+ border: 1px solid var(--admin-line);
2138
+ border-radius: 999px;
2139
+ background: var(--admin-surface-soft);
2140
+ font-size: 11.5px;
2141
+ color: var(--admin-ink);
2142
+ }
2143
+ .agg-scope[hidden] {
2144
+ display: none;
2145
+ }
2146
+ .agg-scope > span + span::before {
2147
+ content: "·";
2148
+ padding-right: 8px;
2149
+ color: var(--admin-line-strong);
2150
+ }
2151
+ .agg-scope-label {
2152
+ font-size: 10px;
2153
+ font-weight: 760;
2154
+ letter-spacing: 0.08em;
2155
+ text-transform: uppercase;
2156
+ color: var(--admin-muted);
2157
+ }
2158
+ .agg-scope-partial {
2159
+ color: var(--admin-muted-2);
2160
+ font-style: italic;
2161
+ cursor: help;
2162
+ }
2163
+
2164
+ /* Publish action — stack the copy above a full-width, weighted CTA */
2165
+ [data-publish-aggregate] .agg-launch {
2166
+ display: grid;
2167
+ grid-template-columns: 1fr;
2168
+ gap: 12px;
2169
+ padding: 14px 0 2px;
2170
+ }
2171
+ /* Extra selector weight so the gradient/shadow beat the .btn.primary base. */
2172
+ [data-publish-aggregate] .btn.agg-publish-btn {
2173
+ width: 100%;
2174
+ justify-content: center;
2175
+ min-height: 50px;
2176
+ gap: 9px;
2177
+ font-size: 15px;
2178
+ border-radius: var(--admin-radius-sm);
2179
+ background: linear-gradient(178deg, var(--admin-teal), var(--admin-teal-dark));
2180
+ box-shadow: 0 8px 22px color-mix(in srgb, var(--admin-teal) 26%, transparent);
2181
+ }
2182
+ .agg-publish-btn svg {
2183
+ width: 18px;
2184
+ height: 18px;
2185
+ }
2186
+ [data-publish-aggregate] .btn.agg-publish-btn:not(:disabled):hover {
2187
+ filter: brightness(1.05);
2188
+ }
2189
+ [data-publish-aggregate] .btn.agg-publish-btn:disabled {
2190
+ background: var(--admin-surface-tint);
2191
+ border-color: var(--admin-line-strong);
2192
+ color: var(--admin-muted);
2193
+ box-shadow: none;
2194
+ cursor: not-allowed;
2195
+ }
2196
+
2197
+ @media (max-width: 760px) {
2198
+ .agg-chain {
2199
+ grid-template-columns: 1fr;
2200
+ gap: 4px;
2201
+ }
2202
+ .agg-link {
2203
+ flex-direction: row;
2204
+ gap: 10px;
2205
+ padding: 4px 12px;
2206
+ }
2207
+ .agg-link .agg-arrow svg {
2208
+ transform: rotate(90deg);
2209
+ }
2210
+ .agg-stop {
2211
+ padding: 8px 2px;
2212
+ }
2213
+ }
2214
+
3444
2215
  /* dg7: versions + diff */
3445
2216
  .versions-table {
3446
2217
  min-width: 780px;