@sssb/kit 0.0.0-stage → 0.2.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 (214) hide show
  1. package/LICENSE +21 -0
  2. package/dist/core/webhook-hmac.d.ts +69 -0
  3. package/dist/release.json +1 -0
  4. package/dist/testing/e2e.d.ts +15 -0
  5. package/dist/testing/e2e.js +195 -0
  6. package/package.json +209 -3
  7. package/src/adapters/README.md +6 -0
  8. package/src/adapters/dev-server.ts +21 -0
  9. package/src/adapters/fake/agreements.ts +81 -0
  10. package/src/adapters/fake/analytics.ts +93 -0
  11. package/src/adapters/fake/atomic-write.ts +161 -0
  12. package/src/adapters/fake/audit.ts +58 -0
  13. package/src/adapters/fake/auth.ts +312 -0
  14. package/src/adapters/fake/clock.ts +54 -0
  15. package/src/adapters/fake/data-dir.ts +27 -0
  16. package/src/adapters/fake/db.ts +88 -0
  17. package/src/adapters/fake/email.ts +46 -0
  18. package/src/adapters/fake/jobs.ts +270 -0
  19. package/src/adapters/fake/llm.ts +230 -0
  20. package/src/adapters/fake/pglite-dialect.ts +124 -0
  21. package/src/adapters/fake/service-auth.ts +145 -0
  22. package/src/adapters/fake/simulator-admin.ts +203 -0
  23. package/src/adapters/fake/simulator.ts +94 -0
  24. package/src/adapters/fake/sms.ts +43 -0
  25. package/src/adapters/fake/storage.ts +288 -0
  26. package/src/adapters/fake/webhooks.ts +98 -0
  27. package/src/adapters/index.ts +115 -0
  28. package/src/adapters/real/accept-invite-form.tsx +77 -0
  29. package/src/adapters/real/analytics.ts +28 -0
  30. package/src/adapters/real/auth.ts +216 -0
  31. package/src/adapters/real/contract-data-api.ts +104 -0
  32. package/src/adapters/real/contract-postgres.ts +167 -0
  33. package/src/adapters/real/database-transport.ts +34 -0
  34. package/src/adapters/real/db-data-api.ts +61 -0
  35. package/src/adapters/real/db.ts +88 -0
  36. package/src/adapters/real/email.ts +22 -0
  37. package/src/adapters/real/index.ts +89 -0
  38. package/src/adapters/real/jobs.ts +32 -0
  39. package/src/adapters/real/llm.ts +108 -0
  40. package/src/adapters/real/migrate-handler.ts +66 -0
  41. package/src/adapters/real/providers.tsx +12 -0
  42. package/src/adapters/real/rds-data-codec.ts +508 -0
  43. package/src/adapters/real/rds-data-dialect.ts +470 -0
  44. package/src/adapters/real/rds-data-emulator.ts +351 -0
  45. package/src/adapters/real/s3-storage.ts +233 -0
  46. package/src/adapters/real/sign-in-form.tsx +59 -0
  47. package/src/adapters/real/storage.ts +10 -0
  48. package/src/adapters/sentry/baseline.ts +90 -0
  49. package/src/adapters/sentry/client.ts +17 -0
  50. package/src/adapters/sentry/init.ts +17 -0
  51. package/src/authz/app-exemptions.ts +226 -0
  52. package/src/authz/authorize.ts +214 -0
  53. package/src/authz/route-policy.ts +153 -0
  54. package/src/authz/route-scan.ts +1516 -0
  55. package/src/components/agreements/acceptances-section.tsx +55 -0
  56. package/src/components/agreements/agreement-advisory-banner.tsx +33 -0
  57. package/src/components/agreements/agreement-body.tsx +34 -0
  58. package/src/components/agreements/agreement-gate.tsx +45 -0
  59. package/src/components/app-header.tsx +45 -0
  60. package/src/components/auth/accept-invite-screen.tsx +126 -0
  61. package/src/components/auth/auth-icons.tsx +68 -0
  62. package/src/components/auth/org-switcher.tsx +76 -0
  63. package/src/components/auth/people-picker.tsx +50 -0
  64. package/src/components/auth/preview-row.tsx +64 -0
  65. package/src/components/auth/sign-in-screen.tsx +24 -0
  66. package/src/components/auth/user-menu.tsx +64 -0
  67. package/src/components/demo-badge.tsx +20 -0
  68. package/src/components/demo-banner.tsx +14 -0
  69. package/src/components/gates/gate-interstitial.tsx +23 -0
  70. package/src/components/job-timeline.tsx +64 -0
  71. package/src/components/notifications/notification-bell.tsx +120 -0
  72. package/src/components/notifications/notification-prefs-section.tsx +112 -0
  73. package/src/components/org-screen.tsx +197 -0
  74. package/src/components/profile-screen.tsx +100 -0
  75. package/src/components/simulator/actor-runtime.ts +180 -0
  76. package/src/components/simulator/actor-shell.tsx +275 -0
  77. package/src/components/simulator/actors-app.tsx +119 -0
  78. package/src/components/simulator/errors-app.tsx +84 -0
  79. package/src/components/simulator/events-app.tsx +210 -0
  80. package/src/components/simulator/format-when.ts +20 -0
  81. package/src/components/simulator/hooks-app.tsx +319 -0
  82. package/src/components/simulator/inbound-app.tsx +210 -0
  83. package/src/components/simulator/jobs-app.tsx +471 -0
  84. package/src/components/simulator/mail-app.tsx +290 -0
  85. package/src/components/simulator/messages-app.tsx +64 -0
  86. package/src/components/simulator/people-app.tsx +140 -0
  87. package/src/components/simulator/people-dimensions.ts +16 -0
  88. package/src/components/simulator/simulator-panel.tsx +716 -0
  89. package/src/components/simulator/snapshots-app.tsx +398 -0
  90. package/src/components/simulator/tab-mount.ts +25 -0
  91. package/src/components/simulator/tours-app.tsx +105 -0
  92. package/src/components/webhook-endpoints-card.tsx +172 -0
  93. package/src/core/abilities.ts +459 -0
  94. package/src/core/agreements.ts +139 -0
  95. package/src/core/gates.ts +157 -0
  96. package/src/core/greeting.ts +11 -0
  97. package/src/core/inbound-email.ts +129 -0
  98. package/src/core/jobs.ts +51 -0
  99. package/src/core/keyset.ts +227 -0
  100. package/src/core/llm-models.ts +10 -0
  101. package/src/core/locale.ts +3 -0
  102. package/src/core/notifications.ts +182 -0
  103. package/src/core/presets.ts +456 -0
  104. package/src/core/roles.ts +47 -0
  105. package/src/core/schedules.ts +147 -0
  106. package/src/core/standard-schema.ts +56 -0
  107. package/src/core/state-machine.ts +43 -0
  108. package/src/core/webhook-events.ts +86 -0
  109. package/src/core/webhook-hmac.ts +248 -0
  110. package/src/core/webhook-signing.ts +27 -0
  111. package/src/cutover/rows.json +101 -0
  112. package/src/db/agreements.ts +176 -0
  113. package/src/db/app-roles.ts +197 -0
  114. package/src/db/audit.ts +356 -0
  115. package/src/db/inbound-email.ts +145 -0
  116. package/src/db/jobs.ts +300 -0
  117. package/src/db/jsonb.ts +18 -0
  118. package/src/db/keyset.ts +179 -0
  119. package/src/db/migrate.ts +73 -0
  120. package/src/db/migrations/0001_tenants.ts +25 -0
  121. package/src/db/migrations/0003_organizations.ts +27 -0
  122. package/src/db/migrations/0004_jobs.ts +64 -0
  123. package/src/db/migrations/0005_service_keys.ts +33 -0
  124. package/src/db/migrations/0008_audit_events.ts +51 -0
  125. package/src/db/migrations/0009_job_schedules.ts +52 -0
  126. package/src/db/migrations/0010_webhooks.ts +100 -0
  127. package/src/db/migrations/0011_notifications.ts +98 -0
  128. package/src/db/migrations/0012_inbound_email.ts +74 -0
  129. package/src/db/migrations/0013_agreements.ts +98 -0
  130. package/src/db/migrations/0014_audit_credential.ts +29 -0
  131. package/src/db/migrations/0015_app_user_grant.ts +67 -0
  132. package/src/db/migrations/0016_audit_detail.ts +26 -0
  133. package/src/db/migrations/index.ts +49 -0
  134. package/src/db/notifications.ts +185 -0
  135. package/src/db/org-lookup.ts +104 -0
  136. package/src/db/owner-pass.ts +252 -0
  137. package/src/db/rls-coverage.ts +259 -0
  138. package/src/db/rls-proof-runner.ts +94 -0
  139. package/src/db/rls-proofs.ts +1176 -0
  140. package/src/db/schedules.ts +187 -0
  141. package/src/db/schema.ts +235 -0
  142. package/src/db/seed.ts +176 -0
  143. package/src/db/service-keys.ts +50 -0
  144. package/src/db/tenant-lookup.ts +13 -0
  145. package/src/db/webhooks.ts +483 -0
  146. package/src/db/with-tenant.ts +26 -0
  147. package/src/demo-static/actor-drivers.ts +161 -0
  148. package/src/demo-static/assistant-replay.ts +61 -0
  149. package/src/demo-static/contracts.ts +282 -0
  150. package/src/demo-static/email-html.ts +58 -0
  151. package/src/demo-static/hash-route.ts +24 -0
  152. package/src/demo-static/rows.ts +105 -0
  153. package/src/demo-static/shell.tsx +440 -0
  154. package/src/demo-static/tour/contracts.ts +97 -0
  155. package/src/demo-static/tour/driver.ts +320 -0
  156. package/src/demo-static/tour/tour-overlay.tsx +226 -0
  157. package/src/demo-static/tour/use-tours.tsx +394 -0
  158. package/src/demo-static/world.ts +1479 -0
  159. package/src/email/send.ts +12 -0
  160. package/src/email/templates/digest-email.tsx +61 -0
  161. package/src/email/templates/invite-email.tsx +57 -0
  162. package/src/email/templates/notification-email.tsx +39 -0
  163. package/src/guide.md +118 -0
  164. package/src/i18n/messages/en.json +373 -0
  165. package/src/i18n/messages/es.json +373 -0
  166. package/src/i18n/messages.ts +34 -0
  167. package/src/i18n/namespaces.ts +32 -0
  168. package/src/i18n/request.ts +34 -0
  169. package/src/i18n/routing.ts +7 -0
  170. package/src/inbound-email/handlers.ts +67 -0
  171. package/src/inbound-email/intake.ts +180 -0
  172. package/src/jobs/digest-email.ts +97 -0
  173. package/src/observability/scrub.ts +42 -0
  174. package/src/ports/README.md +8 -0
  175. package/src/ports/analytics.ts +8 -0
  176. package/src/ports/auth.ts +87 -0
  177. package/src/ports/db.ts +27 -0
  178. package/src/ports/email.ts +14 -0
  179. package/src/ports/errors.ts +46 -0
  180. package/src/ports/jobs.ts +48 -0
  181. package/src/ports/llm.ts +85 -0
  182. package/src/ports/storage.ts +132 -0
  183. package/src/seed/contracts.ts +129 -0
  184. package/src/server-lib/assistant.ts +45 -0
  185. package/src/server-lib/defer.ts +53 -0
  186. package/src/server-lib/demo-presets.ts +85 -0
  187. package/src/server-lib/invite.ts +92 -0
  188. package/src/server-lib/notify-deps.ts +15 -0
  189. package/src/server-lib/notify.ts +252 -0
  190. package/src/server-lib/preset-operations.ts +121 -0
  191. package/src/server-lib/scheduled-tick.ts +38 -0
  192. package/src/server-lib/sms.ts +43 -0
  193. package/src/server-lib/webhook-dispatch.ts +75 -0
  194. package/src/service-auth/mailgun.ts +70 -0
  195. package/src/service-auth/verify.ts +73 -0
  196. package/src/service-auth/webhook.ts +60 -0
  197. package/src/testing/checks.json +103 -0
  198. package/src/testing/conformance/authz.ts +46 -0
  199. package/src/testing/conformance/db.ts +258 -0
  200. package/src/testing/conformance/demo-presets.ts +295 -0
  201. package/src/testing/conformance/i18n.ts +80 -0
  202. package/src/testing/conformance/register.ts +200 -0
  203. package/src/testing/conformance/seam-map.ts +205 -0
  204. package/src/testing/conformance/suite.ts +59 -0
  205. package/src/testing/conformance/types.ts +18 -0
  206. package/src/testing/contract.ts +200 -0
  207. package/src/testing/e2e.ts +15 -0
  208. package/src/testing/index.ts +6 -0
  209. package/src/testing/seam-specifiers.json +22 -0
  210. package/src/testing/tmp-dir-marker.d.mts +4 -0
  211. package/src/testing/tmp-dir-marker.mjs +5 -0
  212. package/src/testing/tmp-dir.ts +182 -0
  213. package/src/theme.ts +28 -0
  214. package/README.md +0 -3
@@ -0,0 +1,398 @@
1
+ 'use client'
2
+
3
+ import { Button, Group, Stack, Switch, Text, TextInput, UnstyledButton } from '@mantine/core'
4
+ import { useLocale, useTranslations } from 'next-intl'
5
+ import { useState } from 'react'
6
+ import { presets as appPresets } from '@sssb/app-config/presets'
7
+ import { flags as appSimulatorFlags } from '@sssb/app-config/simulator'
8
+ import { isReservedWorldStartName, WORLD_START_NAME_PATTERN } from '../../core/presets'
9
+ import { formatWhen } from './format-when'
10
+
11
+ export interface Snapshot {
12
+ name: string
13
+ at: string
14
+ }
15
+
16
+ export interface FeatureFlag {
17
+ flag: string
18
+ enabled: boolean
19
+ }
20
+
21
+ /** One agreement row for the Snapshots Agreements section — the world-view god shape. */
22
+ export interface SnapshotAgreement {
23
+ id: string
24
+ tenantSlug: string
25
+ kind: string
26
+ title: string
27
+ version: number
28
+ gating: string
29
+ currentAcceptances: number
30
+ totalAcceptances: number
31
+ }
32
+
33
+ const snapshotActionStyle = {
34
+ fontSize: 12,
35
+ fontWeight: 600,
36
+ color: '#f8f9fa',
37
+ border: '1px solid #373a40',
38
+ borderRadius: 6,
39
+ padding: '4px 10px',
40
+ } as const
41
+
42
+ /**
43
+ * Router-agnostic Snapshots tab (ADR-0006 twin lives in @sssb/kit/demo-static, reset+flags only — see its
44
+ * own doc comment): the world's control knobs in one place. Reset wipes the simulated world back
45
+ * to its seeded state — how many people that is belongs to the app, so the copy here must not say;
46
+ * feature flags gate app behavior (they moved here from the Events tab
47
+ * so Events stays purely observational); save/restore/delete manage named checkpoints. The reset
48
+ * button is a two-step confirm (no browser `confirm()` — this whole app avoids blocking dialogs).
49
+ * When `snapshots` is undefined the caller has no server-side snapshot store to talk to (the static
50
+ * shell), so the snapshot half doesn't render.
51
+ *
52
+ * DEMO PRESETS (@sssb/kit/core/presets.ts) render on EVERY host that passes `onLoadPreset`: a preset is a
53
+ * script each host replays its own way, not a directory copy, so unlike a saved snapshot it needs no
54
+ * server. The list comes from the seam (`@sssb/app-config/presets`), read here as the flags are
55
+ * (`@sssb/app-config/simulator`), and the section disappears for an app that registers none.
56
+ */
57
+ export function SnapshotsApp({
58
+ snapshots,
59
+ onReset,
60
+ onSave,
61
+ onRestore,
62
+ onDelete,
63
+ busy,
64
+ busySnapshot,
65
+ flags,
66
+ onToggleFlag,
67
+ agreements,
68
+ onBumpAgreement,
69
+ busyAgreement,
70
+ onLoadPreset,
71
+ busyPreset,
72
+ }: {
73
+ snapshots?: Snapshot[] | undefined
74
+ onReset: () => void
75
+ onSave?: (name: string) => void
76
+ onRestore?: (name: string) => void
77
+ onDelete?: (name: string) => void
78
+ busy?: boolean
79
+ /** Name of the snapshot a restore/delete is currently running for — that row shows as busy. */
80
+ busySnapshot?: string | null
81
+ flags?: FeatureFlag[]
82
+ onToggleFlag?: (flag: string, enabled: boolean) => void
83
+ /** Access-gate agreements. Undefined ⇒ the section doesn't render (a host without it). */
84
+ agreements?: SnapshotAgreement[]
85
+ onBumpAgreement?: (id: string) => void
86
+ /** Id of the agreement a bump is currently running for — that row shows as busy. */
87
+ busyAgreement?: string | null
88
+ /** Load a registered demo preset. Undefined ⇒ the presets section doesn't render. */
89
+ onLoadPreset?: (id: string) => void
90
+ /** Id of the preset a load is currently running for — that row shows as busy. */
91
+ busyPreset?: string | null
92
+ }) {
93
+ const t = useTranslations('simulator')
94
+ // Root translator: an app-registered flag's label lives in the APP's catalog (see flagLabel).
95
+ const tRoot = useTranslations()
96
+ const locale = useLocale()
97
+ const [confirmingReset, setConfirmingReset] = useState(false)
98
+ const [name, setName] = useState('')
99
+ // A saved snapshot may not shadow 'reset' or a preset (the server refuses it too): a tour names its
100
+ // starting world by that one string, and it must mean the same world on every host.
101
+ const nameReserved = isReservedWorldStartName(name, appPresets)
102
+ const nameValid = WORLD_START_NAME_PATTERN.test(name) && !nameReserved
103
+ // Reset, restore and a preset load each rewrite the whole world, so one in flight disables the others:
104
+ // a second one starting mid-replay would wipe the world underneath the first.
105
+ const worldBusy = Boolean(busy) || busySnapshot != null || busyPreset != null
106
+
107
+ // Known flags get a friendly label; anything new falls back to its raw key instead of silently
108
+ // borrowing another flag's label. Framework flags (demo-banner, jobs-held) are labelled here, from
109
+ // the framework's own `simulator` namespace. An APP-registered flag carries a FULLY-QUALIFIED
110
+ // message path on the seam (@sssb/app-config/simulator `flags`) — `namespace.key`, resolved with the
111
+ // root translator — because its copy belongs in the app's catalog, not this one.
112
+ function flagLabel(flag: string): string {
113
+ if (flag === 'demo-banner') return t('flagLabelDemoBanner')
114
+ if (flag === 'jobs-held') return t('flagLabelJobsHeld')
115
+ const registered = appSimulatorFlags.find((entry) => entry.id === flag)
116
+ if (registered) return tRoot(registered.labelKey)
117
+ return flag
118
+ }
119
+
120
+ function gatingLabel(gating: string): string {
121
+ return gating === 'advisory' ? t('agreementsGatingAdvisory') : t('agreementsGatingBlock')
122
+ }
123
+
124
+ function confirmReset() {
125
+ setConfirmingReset(false)
126
+ onReset()
127
+ }
128
+
129
+ function submitSave() {
130
+ if (!nameValid) return
131
+ onSave?.(name)
132
+ setName('')
133
+ }
134
+
135
+ return (
136
+ <Stack gap="md" data-testid="simulator-snapshots">
137
+ <Stack gap="xs">
138
+ <Text size="sm" fw={700} c="gray.0">
139
+ {t('snapshotsResetHeading')}
140
+ </Text>
141
+ <Text size="xs" c="gray.5">
142
+ {t('snapshotsResetHint')}
143
+ </Text>
144
+ {confirmingReset ? (
145
+ <Group gap="xs">
146
+ <Button
147
+ color="red.8"
148
+ size="xs"
149
+ loading={busy === true}
150
+ data-testid="snapshots-reset-confirm"
151
+ onClick={confirmReset}
152
+ >
153
+ {t('snapshotsResetConfirm')}
154
+ </Button>
155
+ <Button
156
+ variant="default"
157
+ size="xs"
158
+ data-testid="snapshots-reset-cancel"
159
+ onClick={() => setConfirmingReset(false)}
160
+ >
161
+ {t('snapshotsResetCancel')}
162
+ </Button>
163
+ </Group>
164
+ ) : (
165
+ <Button
166
+ // red.8 (the filled confirm's AA-safe shade) is too dim as outline TEXT on
167
+ // the dark panel (3.81:1); red.4 clears 4.5:1 against #1a1b1e.
168
+ color="red.4"
169
+ variant="outline"
170
+ size="xs"
171
+ disabled={worldBusy}
172
+ data-testid="snapshots-reset"
173
+ onClick={() => setConfirmingReset(true)}
174
+ >
175
+ {t('snapshotsResetButton')}
176
+ </Button>
177
+ )}
178
+ </Stack>
179
+
180
+ {onLoadPreset !== undefined && appPresets.length > 0 ? (
181
+ <Stack gap="xs" data-testid="simulator-presets">
182
+ <Text size="sm" fw={700} c="gray.0">
183
+ {t('presetsHeading')}
184
+ </Text>
185
+ <Text size="xs" c="gray.5">
186
+ {t('presetsHint')}
187
+ </Text>
188
+ {appPresets.map((preset) => {
189
+ const rowBusy = busyPreset === preset.id
190
+ return (
191
+ <Group
192
+ key={preset.id}
193
+ justify="space-between"
194
+ wrap="nowrap"
195
+ data-testid={`preset-row-${preset.id}`}
196
+ style={{
197
+ borderRadius: 8,
198
+ padding: '6px 10px',
199
+ border: '1px solid rgba(255,255,255,0.15)',
200
+ opacity: rowBusy ? 0.6 : 1,
201
+ }}
202
+ >
203
+ <Stack gap={0}>
204
+ <Text size="sm" fw={600} c="gray.0">
205
+ {tRoot(preset.titleKey)}
206
+ </Text>
207
+ <Text size="xs" c="gray.5">
208
+ {rowBusy ? t('snapshotsWorking') : tRoot(preset.summaryKey)}
209
+ </Text>
210
+ </Stack>
211
+ <UnstyledButton
212
+ data-testid={`preset-load-${preset.id}`}
213
+ disabled={worldBusy}
214
+ onClick={() => onLoadPreset(preset.id)}
215
+ style={snapshotActionStyle}
216
+ >
217
+ {t('presetsLoad')}
218
+ </UnstyledButton>
219
+ </Group>
220
+ )
221
+ })}
222
+ </Stack>
223
+ ) : null}
224
+
225
+ {flags !== undefined ? (
226
+ <Stack gap="xs">
227
+ <Text size="sm" fw={700} c="gray.0">
228
+ {t('flagsHeading')}
229
+ </Text>
230
+ <Text size="xs" c="gray.5">
231
+ {t('flagHint')}
232
+ </Text>
233
+ {flags.map((flag) => (
234
+ <Switch
235
+ key={flag.flag}
236
+ label={flagLabel(flag.flag)}
237
+ checked={flag.enabled}
238
+ size="xs"
239
+ styles={{ label: { color: '#f8f9fa' } }}
240
+ data-testid={`flag-toggle-${flag.flag}`}
241
+ onChange={(event) => onToggleFlag?.(flag.flag, event.currentTarget.checked)}
242
+ />
243
+ ))}
244
+ </Stack>
245
+ ) : null}
246
+
247
+ {agreements !== undefined ? (
248
+ <Stack gap="xs" data-testid="simulator-agreements">
249
+ <Text size="sm" fw={700} c="gray.0">
250
+ {t('agreementsHeading')}
251
+ </Text>
252
+ <Text size="xs" c="gray.5">
253
+ {t('agreementsHint')}
254
+ </Text>
255
+ {agreements.length === 0 ? (
256
+ <Text size="xs" c="gray.5" data-testid="simulator-agreements-empty">
257
+ {t('agreementsEmpty')}
258
+ </Text>
259
+ ) : (
260
+ agreements.map((agreement) => {
261
+ const rowBusy = busyAgreement === agreement.id
262
+ return (
263
+ <Group
264
+ key={agreement.id}
265
+ justify="space-between"
266
+ wrap="nowrap"
267
+ data-testid={`simulator-agreement-${agreement.id}`}
268
+ style={{
269
+ borderRadius: 8,
270
+ padding: '6px 10px',
271
+ border: '1px solid rgba(255,255,255,0.15)',
272
+ opacity: rowBusy ? 0.6 : 1,
273
+ }}
274
+ >
275
+ <Stack gap={0}>
276
+ <Text size="sm" fw={600} c="gray.0">
277
+ {t('agreementsRowTitle', {
278
+ tenant: agreement.tenantSlug,
279
+ title: agreement.title,
280
+ })}
281
+ </Text>
282
+ <Text size="xs" c="gray.5" data-testid={`agreement-meta-${agreement.id}`}>
283
+ {t('agreementsRowMeta', {
284
+ version: agreement.version,
285
+ gating: gatingLabel(agreement.gating),
286
+ current: agreement.currentAcceptances,
287
+ total: agreement.totalAcceptances,
288
+ })}
289
+ </Text>
290
+ </Stack>
291
+ <UnstyledButton
292
+ data-testid={`agreement-bump-${agreement.id}`}
293
+ disabled={rowBusy}
294
+ onClick={() => onBumpAgreement?.(agreement.id)}
295
+ style={snapshotActionStyle}
296
+ >
297
+ {t('agreementsBump')}
298
+ </UnstyledButton>
299
+ </Group>
300
+ )
301
+ })
302
+ )}
303
+ </Stack>
304
+ ) : null}
305
+
306
+ {snapshots !== undefined ? (
307
+ <Stack gap="xs">
308
+ <Text size="sm" fw={700} c="gray.0">
309
+ {t('snapshotsSaveHeading')}
310
+ </Text>
311
+ <Text size="xs" c="gray.5">
312
+ {t('snapshotsSaveHint')}
313
+ </Text>
314
+ <Group gap="xs" align="end">
315
+ <TextInput
316
+ size="xs"
317
+ flex={1}
318
+ placeholder={t('snapshotsNamePlaceholder')}
319
+ data-testid="snapshot-name"
320
+ value={name}
321
+ onChange={(event) => setName(event.currentTarget.value)}
322
+ />
323
+ <Button
324
+ size="xs"
325
+ loading={busy === true}
326
+ disabled={!nameValid}
327
+ data-testid="snapshots-save"
328
+ onClick={submitSave}
329
+ >
330
+ {t('snapshotsSaveButton')}
331
+ </Button>
332
+ </Group>
333
+ {name.length > 0 && !nameValid ? (
334
+ <Text size="xs" c="red.4" data-testid="snapshot-name-error">
335
+ {nameReserved ? t('snapshotsNameReserved') : t('snapshotsNameInvalid')}
336
+ </Text>
337
+ ) : null}
338
+
339
+ <Text size="sm" fw={700} c="gray.0" mt="sm">
340
+ {t('snapshotsListHeading')}
341
+ </Text>
342
+ {snapshots.length === 0 ? (
343
+ <Text size="xs" c="gray.5" data-testid="snapshots-empty">
344
+ {t('snapshotsEmpty')}
345
+ </Text>
346
+ ) : (
347
+ <Stack gap={4} data-testid="snapshots-list">
348
+ {snapshots.map((snapshot) => {
349
+ const rowBusy = busySnapshot === snapshot.name
350
+ return (
351
+ <Group
352
+ key={snapshot.name}
353
+ justify="space-between"
354
+ wrap="nowrap"
355
+ data-testid={`snapshots-row-${snapshot.name}`}
356
+ style={{
357
+ borderRadius: 8,
358
+ padding: '6px 10px',
359
+ border: '1px solid rgba(255,255,255,0.15)',
360
+ opacity: rowBusy ? 0.6 : 1,
361
+ }}
362
+ >
363
+ <Stack gap={0}>
364
+ <Text size="sm" fw={600} c="gray.0">
365
+ {snapshot.name}
366
+ </Text>
367
+ <Text size="xs" c="gray.5">
368
+ {rowBusy ? t('snapshotsWorking') : formatWhen(snapshot.at, locale)}
369
+ </Text>
370
+ </Stack>
371
+ <Group gap={6} wrap="nowrap">
372
+ <UnstyledButton
373
+ data-testid={`snapshots-restore-${snapshot.name}`}
374
+ disabled={worldBusy}
375
+ onClick={() => onRestore?.(snapshot.name)}
376
+ style={snapshotActionStyle}
377
+ >
378
+ {t('snapshotsRestoreButton')}
379
+ </UnstyledButton>
380
+ <UnstyledButton
381
+ data-testid={`snapshots-delete-${snapshot.name}`}
382
+ disabled={rowBusy}
383
+ onClick={() => onDelete?.(snapshot.name)}
384
+ style={{ ...snapshotActionStyle, color: '#ffa8a8' }}
385
+ >
386
+ {t('snapshotsDeleteButton')}
387
+ </UnstyledButton>
388
+ </Group>
389
+ </Group>
390
+ )
391
+ })}
392
+ </Stack>
393
+ )}
394
+ </Stack>
395
+ ) : null}
396
+ </Stack>
397
+ )
398
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * How the Simulator panel renders one host `extraTabs` entry. Pure so the rule is unit-testable
3
+ * without a DOM.
4
+ *
5
+ * An ordinary tab exists only while it is the active tab of an expanded panel. A `keepMounted` tab
6
+ * (the Actors tab, whose content runs the actors' tick loops) is mounted from page load and never
7
+ * unmounted — shown when it is the active tab of an expanded panel, hidden otherwise — because the
8
+ * counterparties it hosts are part of the world, and the world doesn't wait for someone to open a
9
+ * tab. (Pausing them is a world switch the host wires in, e.g. the showcase's `actors-held` flag.) It
10
+ * never moves in the DOM either: moving an iframe reloads it.
11
+ *
12
+ * "From page load" means just AFTER the host page's own `load` event, not during it: a document's
13
+ * `load` waits for every iframe in it, so actor frames in the server-rendered HTML made every page —
14
+ * and every e2e `waitForURL` — wait on two more dev-server page builds. Opening the tab before then
15
+ * shows it at once.
16
+ */
17
+ export type TabMount = 'shown' | 'hidden' | 'none'
18
+
19
+ export function tabMount(
20
+ tab: { id: string; keepMounted?: boolean },
21
+ state: { activeTab: string; collapsed: boolean; pageLoaded: boolean },
22
+ ): TabMount {
23
+ if (!state.collapsed && state.activeTab === tab.id) return 'shown'
24
+ return tab.keepMounted && state.pageLoaded ? 'hidden' : 'none'
25
+ }
@@ -0,0 +1,105 @@
1
+ 'use client'
2
+
3
+ import { Group, Stack, Switch, Text, UnstyledButton } from '@mantine/core'
4
+ import { useTranslations } from 'next-intl'
5
+
6
+ /** One registered tour, with its copy already resolved by the host (the seam carries keys, the host
7
+ * translates — the same contract every other app registration on this panel uses). */
8
+ export interface TourListing {
9
+ id: string
10
+ title: string
11
+ summary: string
12
+ }
13
+
14
+ export interface ToursAppProps {
15
+ tours: TourListing[]
16
+ /** The tour currently running, if any — its row says so, and the others are unavailable. */
17
+ activeId: string | null
18
+ /** Preview speed: the ghost cursor stops pausing for a human to read. */
19
+ fast: boolean
20
+ onFastChange: (fast: boolean) => void
21
+ onStart: (id: string) => void
22
+ }
23
+
24
+ const tourActionStyle = {
25
+ fontSize: 12,
26
+ fontWeight: 600,
27
+ color: '#f8f9fa',
28
+ border: '1px solid #373a40',
29
+ borderRadius: 6,
30
+ padding: '4px 10px',
31
+ } as const
32
+
33
+ /**
34
+ * Router-agnostic Tours tab: the world's SCRIPTED WALKTHROUGHS, beside Snapshots because they are the same
35
+ * idea in two dimensions — a snapshot is world state, a tour is world narrative, and a tour starts by
36
+ * restoring a snapshot.
37
+ *
38
+ * Why it exists: `dist-demo/index.html` is one file you can email to a stakeholder, and until now
39
+ * seeing the product in it meant reading a runbook and clicking fifteen things in the right order.
40
+ * Here they press Start and read.
41
+ *
42
+ * The tab renders only when the app registers at least one tour (@sssb/kit/demo-static/tour/use-tours), so
43
+ * an adopter who registers none never sees it.
44
+ */
45
+ export function ToursApp({ tours, activeId, fast, onFastChange, onStart }: ToursAppProps) {
46
+ const t = useTranslations('simulator')
47
+
48
+ return (
49
+ <Stack gap="md" data-testid="simulator-tours">
50
+ <Stack gap="xs">
51
+ <Text size="sm" fw={700} c="gray.0">
52
+ {t('toursHeading')}
53
+ </Text>
54
+ <Text size="xs" c="gray.5">
55
+ {t('toursHint')}
56
+ </Text>
57
+ <Switch
58
+ label={t('toursFastLabel')}
59
+ checked={fast}
60
+ size="xs"
61
+ styles={{ label: { color: '#f8f9fa' } }}
62
+ data-testid="tour-fast"
63
+ onChange={(event) => onFastChange(event.currentTarget.checked)}
64
+ />
65
+ </Stack>
66
+
67
+ <Stack gap="xs" data-testid="tours-list">
68
+ {tours.map((tour) => {
69
+ const running = activeId === tour.id
70
+ return (
71
+ <Group
72
+ key={tour.id}
73
+ justify="space-between"
74
+ wrap="nowrap"
75
+ align="start"
76
+ data-testid={`tour-row-${tour.id}`}
77
+ style={{
78
+ borderRadius: 8,
79
+ padding: '6px 10px',
80
+ border: '1px solid rgba(255,255,255,0.15)',
81
+ }}
82
+ >
83
+ <Stack gap={0} style={{ minWidth: 0 }}>
84
+ <Text size="sm" fw={600} c="gray.0">
85
+ {tour.title}
86
+ </Text>
87
+ <Text size="xs" c="gray.5">
88
+ {tour.summary}
89
+ </Text>
90
+ </Stack>
91
+ <UnstyledButton
92
+ data-testid={`tour-start-${tour.id}`}
93
+ disabled={activeId !== null}
94
+ onClick={() => onStart(tour.id)}
95
+ style={{ ...tourActionStyle, flexShrink: 0, opacity: activeId !== null ? 0.6 : 1 }}
96
+ >
97
+ {running ? t('toursRunning') : t('toursStart')}
98
+ </UnstyledButton>
99
+ </Group>
100
+ )
101
+ })}
102
+ </Stack>
103
+ </Stack>
104
+ )
105
+ }