@hansenexus/hud 0.4.0 → 0.5.1

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 (159) hide show
  1. package/README.md +634 -12
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
  5. package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
  6. package/dist/access-panel-CEfTr9ZI.js +123 -0
  7. package/dist/adapter-BYoxPYTI.d.ts +33 -0
  8. package/dist/adapter-hcwmJtNx.js +65 -0
  9. package/dist/auto/runtime.d.ts +65 -0
  10. package/dist/auto/runtime.js +50 -0
  11. package/dist/auto.d.ts +15 -0
  12. package/dist/auto.js +33 -0
  13. package/dist/capabilities-rDSKjXpq.js +110 -0
  14. package/dist/capture-CwrIwLqi.js +300 -0
  15. package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
  16. package/dist/cli.d.ts +1 -0
  17. package/dist/cli.js +275 -0
  18. package/dist/data-panel-DhxAmP91.js +817 -0
  19. package/dist/data-store-ChF1td_P.js +164 -0
  20. package/dist/define-hud-CHPedaQ5.d.ts +50 -0
  21. package/dist/design-D0kGgPoP.js +87 -0
  22. package/dist/detect-BxHZ0pxW.d.ts +25 -0
  23. package/dist/detect-CHZiSeZs.js +63 -0
  24. package/dist/dispatch-panel-B-xr_Giy.js +279 -0
  25. package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
  26. package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
  27. package/dist/file-xdSaQ2uR.js +103 -0
  28. package/dist/flags-DVtaJ8pQ.d.ts +58 -0
  29. package/dist/flags.d.ts +2 -0
  30. package/dist/flags.js +82 -0
  31. package/dist/force-state-panel-_otVYh9i.js +97 -0
  32. package/dist/generate-C8lQl3Eh.js +53 -0
  33. package/dist/handler-BpVhxEmU.js +106 -0
  34. package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
  35. package/dist/index-BAV_1W8a.d.ts +43 -0
  36. package/dist/index-BJ26pse9.d.ts +70 -0
  37. package/dist/index-BnQ0dTZf.d.ts +19 -0
  38. package/dist/index-CwfX-W87.d.ts +72 -0
  39. package/dist/index-DcH9V3cU.d.ts +48 -0
  40. package/dist/index-DqOyNf1u.d.ts +65 -0
  41. package/dist/index-DstI_ike.d.ts +66 -0
  42. package/dist/index-Dxz4fn4j.d.ts +42 -0
  43. package/dist/index-Hhh7OXzU.d.ts +129 -0
  44. package/dist/index-ReFbhQ9p.d.ts +25 -0
  45. package/dist/index-RgXfMBuW.d.ts +48 -0
  46. package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.js +710 -69
  49. package/dist/inspect-C9Ft8fqn.js +142 -0
  50. package/dist/inspect-root-BkaupBMp.js +429 -0
  51. package/dist/meta-Bv0sEao3.js +6 -0
  52. package/dist/meta-C_G7MB5w.d.ts +49 -0
  53. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  54. package/dist/mocks-ESiRqk9o.js +150 -0
  55. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  56. package/dist/next/config.cjs +201 -0
  57. package/dist/next/config.d.cts +87 -0
  58. package/dist/next/config.d.ts +64 -0
  59. package/dist/next/config.js +84 -0
  60. package/dist/next.d.ts +14 -4
  61. package/dist/next.js +5 -3
  62. package/dist/observe-CdDnDBRP.js +89 -0
  63. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  64. package/dist/ops-panel-CEqDe_UT.js +234 -0
  65. package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
  66. package/dist/plugins/a11y.d.ts +2 -0
  67. package/dist/plugins/a11y.js +2 -0
  68. package/dist/plugins/access/server.d.ts +5 -5
  69. package/dist/plugins/access/server.js +4 -3
  70. package/dist/plugins/access.d.ts +5 -5
  71. package/dist/plugins/access.js +16 -215
  72. package/dist/plugins/agent/server.d.ts +3 -38
  73. package/dist/plugins/agent/server.js +47 -21
  74. package/dist/plugins/agent.d.ts +4 -4
  75. package/dist/plugins/agent.js +6 -348
  76. package/dist/plugins/capture/server.d.ts +92 -0
  77. package/dist/plugins/capture/server.js +248 -0
  78. package/dist/plugins/capture.d.ts +24 -0
  79. package/dist/plugins/capture.js +70 -0
  80. package/dist/plugins/data/msw-browser.d.ts +2 -0
  81. package/dist/plugins/data/msw-browser.js +39 -0
  82. package/dist/plugins/data/msw-node.d.ts +36 -0
  83. package/dist/plugins/data/msw-node.js +68 -0
  84. package/dist/plugins/data/server.d.ts +257 -0
  85. package/dist/plugins/data/server.js +717 -0
  86. package/dist/plugins/data.d.ts +6 -0
  87. package/dist/plugins/data.js +51 -0
  88. package/dist/plugins/design/server.d.ts +54 -0
  89. package/dist/plugins/design/server.js +198 -0
  90. package/dist/plugins/design.d.ts +4 -124
  91. package/dist/plugins/design.js +4 -619
  92. package/dist/plugins/inspect/convex.d.ts +2 -0
  93. package/dist/plugins/inspect/convex.js +486 -0
  94. package/dist/plugins/inspect/react-query.d.ts +2 -0
  95. package/dist/plugins/inspect/react-query.js +237 -0
  96. package/dist/plugins/inspect/sockets.d.ts +51 -0
  97. package/dist/plugins/inspect/sockets.js +397 -0
  98. package/dist/plugins/inspect/swr.d.ts +2 -0
  99. package/dist/plugins/inspect/swr.js +218 -0
  100. package/dist/plugins/inspect.d.ts +4 -0
  101. package/dist/plugins/inspect.js +3 -0
  102. package/dist/plugins/observe.d.ts +4 -64
  103. package/dist/plugins/observe.js +1 -616
  104. package/dist/plugins/ops/server.d.ts +1 -1
  105. package/dist/plugins/ops/server.js +2 -1
  106. package/dist/plugins/ops.d.ts +2 -1
  107. package/dist/plugins/ops.js +15 -336
  108. package/dist/plugins/routes/server.d.ts +88 -0
  109. package/dist/plugins/routes/server.js +62 -0
  110. package/dist/plugins/routes.d.ts +3 -0
  111. package/dist/plugins/routes.js +216 -0
  112. package/dist/plugins/seo.d.ts +2 -0
  113. package/dist/plugins/seo.js +2 -0
  114. package/dist/plugins/vitals.d.ts +2 -25
  115. package/dist/plugins/vitals.js +3 -2
  116. package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
  117. package/dist/poll-CjKsWZi8.js +89 -0
  118. package/dist/requests-BwD6MKEq.js +282 -0
  119. package/dist/requests-CJrUf465.d.ts +50 -0
  120. package/dist/review.js +2 -2
  121. package/dist/same-origin-BGet22CC.js +21 -0
  122. package/dist/scan-DzJNXqOk.js +165 -0
  123. package/dist/seo-Dq9q_QkO.js +551 -0
  124. package/dist/seo-panel-CfiY-TnT.js +124 -0
  125. package/dist/server.d.ts +2 -2
  126. package/dist/server.js +2 -105
  127. package/dist/sessions-panel-COvhPAzv.js +98 -0
  128. package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
  129. package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
  130. package/dist/store/convex.d.ts +33 -0
  131. package/dist/store/convex.js +52 -0
  132. package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
  133. package/dist/store-Ync9eb1G.js +67 -0
  134. package/dist/store.d.ts +76 -0
  135. package/dist/store.js +188 -0
  136. package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
  137. package/dist/styles-DKU_P8MH.js +139 -0
  138. package/dist/styles-DPpDPmzi.js +68 -0
  139. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  140. package/dist/types-B-ulf2Jp.js +8 -0
  141. package/dist/types-BIgGf-0C.d.ts +25 -0
  142. package/dist/types-BIkI-qN8.js +30 -0
  143. package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
  144. package/dist/types-DIdPfjtV.js +6 -0
  145. package/dist/types-DaJcsEjO.d.ts +44 -0
  146. package/dist/types-Dn68psVz.d.ts +118 -0
  147. package/dist/types-szkr2QOF.d.ts +39 -0
  148. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  149. package/dist/variant-groups-TIfO3NIj.js +137 -0
  150. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  151. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  152. package/dist/variants-types-CcRf119M.d.ts +63 -0
  153. package/dist/variants.d.ts +43 -0
  154. package/dist/variants.js +83 -0
  155. package/dist/vitals-panel-BCmMUntW.js +30 -0
  156. package/dist/vite.d.ts +37 -0
  157. package/dist/vite.js +134 -0
  158. package/package.json +72 -5
  159. package/dist/define-hud-BBzsSl8b.d.ts +0 -36
package/README.md CHANGED
@@ -11,6 +11,7 @@ client site's CSS cannot touch it and it cannot touch the site.
11
11
  bun install
12
12
  bun run dev # playground on http://localhost:5173, HUD imported from source (HMR)
13
13
  bun run check # lint, typecheck, test, build
14
+ bun run test:e2e # Playwright against the playground (pill, overflow, drag, variants) and both fixtures (plugin routes, auto-config)
14
15
  ```
15
16
 
16
17
  The playground (`playground/`) is a fake client site with every element that has fought a dev
@@ -40,7 +41,19 @@ export default defineHud({ app: "my-app", plugins: [vitals()] });
40
41
  ```
41
42
 
42
43
  The loader, with the build gate as a literal expression around the `import()`. Next inlines both
43
- env reads, so a production build folds the ternary to `null` and emits no HUD chunk:
44
+ env reads, so a production build folds the ternary to `null` and emits no HUD chunk. That holds
45
+ only when `NEXT_PUBLIC_HUD_ENABLED` is a build-time literal: Turbopack leaves an **unset**
46
+ `NEXT_PUBLIC_*` variable as a runtime `process.env` read, the ternary does not fold, and the whole
47
+ dev HUD ships as an unreachable production chunk. Wrap the config in `withHud` (see
48
+ [Auto-config](#auto-config-hansenexushudauto)), which pins the HUD's variables to `""` when they are unset, or pin it
49
+ yourself:
50
+
51
+ ```js
52
+ // next.config.js, without withHud
53
+ export default {
54
+ env: { NEXT_PUBLIC_HUD_ENABLED: process.env.NEXT_PUBLIC_HUD_ENABLED ?? "" },
55
+ };
56
+ ```
44
57
 
45
58
  ```tsx
46
59
  // src/components/dev/hud-loader.tsx
@@ -67,6 +80,140 @@ export const { GET, POST, PUT, PATCH, DELETE } = createHudHandler([/* plugins/<i
67
80
  `createHudHandler` answers 404 to everything unless `NODE_ENV` is `development`; pass `guard` to
68
81
  open deployed tiers deliberately. `HUD_DEV_MARKER` is rendered on the HUD root for a CI grep.
69
82
 
83
+ ## Use (Vite)
84
+
85
+ The same `hud.tsx`. The plugin routes come from `@hansenexus/hud/vite`: `hud()` runs
86
+ `createHudHandler` as dev-server middleware under `/api/hud/*`, ahead of Vite's own middlewares,
87
+ and is inert in `vite build` and `vite preview`:
88
+
89
+ ```ts
90
+ // vite.config.ts
91
+ import { ops } from "@hansenexus/hud/plugins/ops/server";
92
+ import { hud } from "@hansenexus/hud/vite";
93
+ import react from "@vitejs/plugin-react";
94
+ import { defineConfig } from "vite";
95
+
96
+ export default defineConfig({
97
+ plugins: [react(), hud({ plugins: [ops({ /* providers */ })] })],
98
+ });
99
+ ```
100
+
101
+ `hud()` takes the same `basePath`, `guard` and `can` as `createHudHandler`; the default guard
102
+ answers 404 unless `NODE_ENV` is `development`, which `vite dev` sets. `vite` is an optional peer
103
+ dependency (6 or newer).
104
+
105
+ A Vite client has no `process`, so gate the loader on `import.meta.env.DEV` and hand it the tier.
106
+ Both are literals Vite folds, so a production build drops the `import()` and emits no HUD chunk:
107
+
108
+ ```tsx
109
+ // src/hud-loader.tsx
110
+ import { createHudLoader } from "@hansenexus/hud/next";
111
+
112
+ export const HudLoader = createHudLoader(import.meta.env.DEV ? () => import("./hud") : null, {
113
+ env: import.meta.env.DEV ? "development" : "production",
114
+ });
115
+ ```
116
+
117
+ Without `env`, `resolveHudEnv()` answers `production` where `process` is missing, so no
118
+ `define: { "process.env.NEXT_PUBLIC_HUD_…" }` shim is needed. `fixtures/vite-app` is a complete
119
+ example, CI-gated like the Next fixture (see Bundle gate).
120
+
121
+ ## Auto-config (`@hansenexus/hud/auto`)
122
+
123
+ Instead of the hand-written plugin list, let the bundler pick plugins from the app's
124
+ dependencies. `@hansenexus/hud/auto` is a module the Vite plugin or the Next config wrapper
125
+ generates from `package.json` at build time, in dev and build alike; it imports only what the
126
+ dependencies call for, so an undetected plugin is not in the module graph at all (no chunk, in
127
+ dev or build). Hand it to `defineHud` as `auto`:
128
+
129
+ ```tsx
130
+ // hud.tsx
131
+ import { defineHud } from "@hansenexus/hud";
132
+ import { auto } from "@hansenexus/hud/auto";
133
+ import { ops } from "@hansenexus/hud/plugins/ops";
134
+
135
+ export default defineHud({
136
+ app: "my-app",
137
+ auto: auto({ convex }), // or just `auto`, when no detected adapter needs an instance
138
+ plugins: [ops()], // explicit: replaces a detected plugin with the same id, in place; the rest are appended
139
+ });
140
+ ```
141
+
142
+ What `auto` turns on:
143
+
144
+ | detected package | plugin |
145
+ | --------------------------------------------- | ----------------------------------------------------------------- |
146
+ | always | `vitals`, `observe`, `inspect`, `forceState` (states), `a11y`, `seo` |
147
+ | `next` | `routes` |
148
+ | `convex` | Convex tab of `inspect`; pass `auto({ convex: client })` |
149
+ | `@tanstack/react-query` | Query tab; pass `auto({ queryClient })` |
150
+ | `swr` | SWR tab; pass `auto({ swr: { cache, mutate } })` |
151
+ | `msw`, `better-auth`, `@convex-dev/auth` | `data` |
152
+
153
+ Any dependency section counts (`devDependencies` included). A detected adapter whose instance
154
+ was not passed shows a tab saying what to pass instead of hiding. `auto()` also takes `observe`,
155
+ `inspect` (`ignore`) and `a11y` options for the base plugins. Server halves stay explicit: mount
156
+ `routes()`, `dataServer()` and the rest in `createHudHandler` or `hud({ plugins })` as before.
157
+ Plugins that need server config or secrets (`access`, `ops`, `agent`, `capture`) are never picked;
158
+ list them in `plugins`.
159
+
160
+ Vite: `hud()` from `@hansenexus/hud/vite` (see above) serves the module and watches
161
+ `package.json`; nothing else to configure (`packageJson` overrides the path). Next: wrap the
162
+ config, which writes `.hud/auto.mjs` next to `package.json` on every start and aliases the
163
+ import for Turbopack and webpack. Add `.hud/auto.mjs` to `.gitignore`.
164
+
165
+ ```js
166
+ // next.config.js
167
+ import { withHud } from "@hansenexus/hud/next/config";
168
+
169
+ export default withHud({ reactStrictMode: true });
170
+ ```
171
+
172
+ `withHud` takes and returns the app's own config type (`NextConfig` included) and also pins
173
+ `NEXT_PUBLIC_HUD_ENABLED`, `NEXT_PUBLIC_HUD_DISABLED` and `NEXT_PUBLIC_HUD_ENV` through `env` to
174
+ their build-time value, `""` when unset; an `env` entry of the app's own wins. The entry ships as
175
+ ESM and CommonJS, so a `next.config.ts` that Next compiles to CommonJS (a package without
176
+ `"type": "module"`) loads it through `require()` too:
177
+
178
+ ```ts
179
+ // next.config.ts
180
+ import type { NextConfig } from "next";
181
+ import { withHud } from "@hansenexus/hud/next/config";
182
+
183
+ const config: NextConfig = { reactStrictMode: true };
184
+ export default withHud(config);
185
+ ```
186
+
187
+ Without either, `@hansenexus/hud/auto` resolves to the package's stand-in: the base plugins,
188
+ nothing dependency-driven, and a console warning once. `auto` works as the whole `plugins` value
189
+ too (`plugins: auto()`); `defineHud` needs one of `plugins` and `auto`.
190
+
191
+ ## Use (Hono, Bun.serve, any Fetch server)
192
+
193
+ `createHudHandler(...).handle` is a plain `(Request) => Promise<Response>`, so any server that
194
+ speaks Fetch mounts it. It checks `basePath` itself, so mount it at the same prefix:
195
+
196
+ ```ts
197
+ import { createHudHandler } from "@hansenexus/hud/server";
198
+
199
+ const hud = createHudHandler([/* plugins/<id>/server */]);
200
+
201
+ // Hono
202
+ app.all("/api/hud/*", (c) => hud.handle(c.req.raw));
203
+
204
+ // Bun.serve
205
+ Bun.serve({
206
+ fetch(request) {
207
+ if (new URL(request.url).pathname.startsWith("/api/hud/")) return hud.handle(request);
208
+ return app.fetch(request);
209
+ },
210
+ });
211
+ ```
212
+
213
+ The default guard applies here too: 404 unless `NODE_ENV` is `development`. Pass `guard`
214
+ (`accessGuard()` from the access plugin) to open a deployed tier. The client side is the Vite
215
+ loader above; an app served this way is a Vite app at build time.
216
+
70
217
  ## Deployed tiers (access plugin)
71
218
 
72
219
  Core assumes development: without the `access` plugin `defineHud` renders nothing on any other
@@ -103,6 +250,9 @@ The denial comes before the lock, so a password never widens the matrix. Every 4
103
250
  same `{ "error": "forbidden" }` body, naming neither tier nor capability. The matrix is
104
251
  default-deny; production grants `observe.app`, `observe.estate` and `cicd.read`. Pass the same
105
252
  `{ matrix: { staging: [...] } }` to `access()` and `accessGuard()` to replace a tier's list.
253
+ `data.*` (`data.read`, `data.write`: the data plugin and `storeServer()`) is hard-denied on
254
+ production: a production list naming it is stripped, and the guard answers 403 whatever the matrix
255
+ says. Staging and preview get it only through the matrix.
106
256
  Until the operator unlocks (12 h on preview/staging, 2 h on production), the pill shows only the
107
257
  lock. Client-side hiding is display only; the guard is what enforces the tier.
108
258
 
@@ -129,10 +279,22 @@ In the playground, `?env=staging` runs this flow with the password `playground`.
129
279
 
130
280
  ## Write a plugin
131
281
 
132
- A plugin is `{ id, title?, capability?, panel?, pill?, commands?, routes? }`, shipped as two
282
+ A plugin is `{ id, title?, capability?, panel?, pill?, pillPriority?, commands?, routes? }`, shipped as two
133
283
  halves with the same `id`: the client half (`panel`, `pill`, `commands`) and the server half
134
284
  (`routes`), so route code never reaches a client bundle. The panel is a plain React component
135
- receiving `ctx`:
285
+ receiving `ctx`. Make it a dynamic import, so its code loads on first open and the pill stays
286
+ light; the shell shows "Loading…" meanwhile and contains a panel that fails to load or throws:
287
+
288
+ ```tsx
289
+ import { lazy } from "react";
290
+ import { definePlugin } from "@hansenexus/hud";
291
+
292
+ export const notes = () =>
293
+ definePlugin({ id: "notes", title: "Notes", panel: lazy(() => import("./notes-panel")) });
294
+ ```
295
+
296
+ Only what the pill needs runs at HUD mount (a store, a capture hook); every built-in panel
297
+ follows this split, see [Bundle budget](#bundle-budget).
136
298
 
137
299
  | `ctx` | does |
138
300
  | ------------- | --------------------------------------------------------------------- |
@@ -141,7 +303,7 @@ receiving `ctx`:
141
303
  | `pin(edge)` | pin the panel to `left`, `right` or `bottom` |
142
304
  | `close()` | close the panel |
143
305
  | `open()` | open the panel |
144
- | `grab` | the element grabber: `start()`, `cancel()`, `clear()`; read it with `useGrab(ctx.grab)` |
306
+ | `grab` | the element grabber: `start()`, `cancel()`, `clear()`, `amend(patch)`, `highlight(el, label)`, `clearHighlight()`; read it with `useGrab(ctx.grab)` |
145
307
 
146
308
  Routes are keyed by path, then method: `routes: { "/runs/:id": { GET: (req, { params }) => ... } }`.
147
309
  An unknown path answers 404, a known path with another method 405.
@@ -149,6 +311,21 @@ An unknown path answers 404, a known path with another method 405.
149
311
  `playground/src/plugins/server-info` is a working example: the playground serves its routes
150
312
  through MSW with the same `createHudHandler` an app mounts.
151
313
 
314
+ ## Pill
315
+
316
+ - The pill starts bottom-left. It scans the page for `position: fixed` and `sticky` elements
317
+ (cookie banners, chat launchers, booking CTAs, sticky navs) and takes the first corner none of
318
+ them covers; when every corner is covered, it shifts off the edge that needs the smallest move,
319
+ bottom corners preferred. Backdrops covering more than half the viewport are ignored.
320
+ - When the pill is wider than the viewport, items move into the `⋯` menu (the badge counts
321
+ them). `pillPriority` decides what stays: `access` 30, `observe` (errors) 20, `ops` (CI) 10,
322
+ everything else 0, then pill order. When no corner is free even after shifting, the pill
323
+ turns compact and keeps only prioritised items.
324
+ - Drag the env badge to another corner to keep the pill there; it still shifts within that
325
+ corner to clear host elements. `⋯ → Reset layout` forgets the corner.
326
+ - On a phone, a page wider than the screen grows the layout viewport past what is visible; the
327
+ pill places itself in the visible area instead.
328
+
152
329
  ## Panels and shortcuts
153
330
 
154
331
  - Open panels from the pill (`⋯` lists every panel and command). Drag by the title bar; a click
@@ -171,9 +348,15 @@ component and file that rendered it, a click picks it, `Esc` cancels. Open panel
171
348
  and usable meanwhile. The pick becomes a `GrabPayload` (route, selector, label, component,
172
349
  viewport) handed to every plugin's `onGrab(payload, ctx)` and kept in `ctx.grab`. The source line
173
350
  comes from React's dev stack and points into the dev server's transformed module, so it can sit a
174
- few lines below the original.
351
+ few lines below the original. A plugin that enriches a grab after the fact (the `capture` plugin
352
+ attaching a screenshot) merges into it with `ctx.grab.amend(patch)`.
353
+
354
+ `ctx.grab.highlight(element, label)` draws the same outline on an element without entering grab
355
+ mode, for a panel that points at the page (the a11y findings do this). It follows scrolling and
356
+ goes away on `Esc`, on a click on the page, on the next grab or with `clearHighlight()`.
175
357
 
176
- `ElementPicker` is exported on its own and carries no dev marker, for the review entrypoint.
358
+ `ElementPicker` and `ElementOutline` are exported on their own and carry no dev marker, for the
359
+ review entrypoint.
177
360
 
178
361
  ## Agent plugins
179
362
 
@@ -202,6 +385,86 @@ task text. `POST /dispatch` refuses cross-site requests (`Sec-Fetch-Site`) and a
202
385
  `claudeCode()` loads Node built-ins on first use, so the server entry also imports where `node:`
203
386
  modules are missing.
204
387
 
388
+ ## Capture plugin (screenshot)
389
+
390
+ `@hansenexus/hud/plugins/capture` attaches a screenshot to every grab, so a dispatched agent sees
391
+ what was meant. `screenshot()` has no panel: on a grab it posts the page URL, the grabbed selector
392
+ and the viewport to its server half, which renders the page headless with Playwright and answers
393
+ the PNG; the Dispatch panel shows the thumbnail and sends it with the dispatch
394
+ (`payload.screenshot`), and `claudeCode()` writes it beside the run's log and names the file in
395
+ the prompt.
396
+
397
+ ```tsx
398
+ import { screenshot } from "@hansenexus/hud/plugins/capture";
399
+ defineHud({ app: "my-app", plugins: [agentDispatch(), screenshot()] });
400
+ ```
401
+
402
+ ```ts
403
+ import { screenshot } from "@hansenexus/hud/plugins/capture/server";
404
+ export const { GET, POST } = createHudHandler([agentDispatch({ providers }), screenshot()]);
405
+ ```
406
+
407
+ - `POST /api/hud/capture/screenshot` takes `{ url, selector?, viewport? }`. The URL must share
408
+ the request's origin (or the page's `Origin`) and be `http(s)`; anything else answers 400, and
409
+ cross-site or non-JSON requests are refused, so the dev server never renders the web for
410
+ someone else. The page loads at the grab's viewport with the request's cookies, so it renders
411
+ the developer's session; the HUD itself is hidden. When the selector is not there headless
412
+ (hover state, hydration) the answer is the viewport, marked `scope: "viewport"`.
413
+ - `playwright` is an optional peer dependency, loaded on first use. Without it, or without its
414
+ Chromium, the route answers 503 with a setup hint
415
+ (`bun add -d playwright && bunx playwright install chromium`); the grab carries the reason, the
416
+ Dispatch panel shows the hint and the dispatch goes on without an image. Apps that already pin
417
+ `@playwright/test` have `playwright` through it. Next externalises `playwright` on the server by
418
+ default; pass `launch` to use another browser or an existing one.
419
+ - Needs `capture.screenshot`: granted in development only. A dispatch waits up to 30 s for a
420
+ screenshot still rendering.
421
+
422
+ ## Routes plugin and `hud sweep`
423
+
424
+ Every page of the app's `app/` tree, one click away, and a CI sweep over the same list.
425
+
426
+ ```tsx
427
+ // hud.tsx
428
+ import { routes } from "@hansenexus/hud/plugins/routes";
429
+ export default defineHud({ app: "my-app", plugins: [routes(), /* ... */] });
430
+ ```
431
+
432
+ ```ts
433
+ // app/api/hud/[...hud]/route.ts
434
+ import { routes } from "@hansenexus/hud/plugins/routes/server";
435
+
436
+ export const { GET, POST, PUT, PATCH, DELETE } = createHudHandler([
437
+ routes({ fixtures: { slug: ["hello", "welt"], locale: "" }, exclude: ["/(admin)/*"] }),
438
+ ]);
439
+ ```
440
+
441
+ The server half walks `app/` (or `src/app/`, or `dir`) on every request: `page.{tsx,jsx,ts,js,mdx}`
442
+ folders become routes, route groups drop out of the URL, private `_x`, parallel `@x` and
443
+ intercepting `(.)x` folders are skipped. Dynamic segments are filled from `fixtures`, keyed by
444
+ param name: a string, several strings (one URL each) or a function returning either, called per
445
+ route. A catch-all takes `a/b`; the empty string drops the segment (an `as-needed` default
446
+ locale); an optional catch-all without a fixture resolves to its parent. A segment without a
447
+ fixture leaves its route listed but unresolved. Capability: `routes.read` (development, staging,
448
+ preview).
449
+
450
+ The panel groups routes by route group, filters by path, marks the current page and navigates on
451
+ click. `GET /api/hud/routes/routes` answers the same list as JSON.
452
+
453
+ `hud sweep` visits that list headless and fails the build on a 5xx answer, an uncaught error or a
454
+ console error on any page. It needs Playwright in the app (`playwright` or `@playwright/test`,
455
+ with `npx playwright install chromium`) and the dev server running:
456
+
457
+ ```sh
458
+ npx hud sweep --base http://localhost:3000 # lines per route, exit 1 on failure
459
+ npx hud sweep --base http://localhost:3000 --json # the report as JSON, for CI
460
+ npx hud sweep --base http://localhost:3000 --exclude "/broken" --ignore-console "Warning: .*key"
461
+ ```
462
+
463
+ `--api` names another `createHudHandler` mount, `--timeout` and `--wait` tune navigation and
464
+ settle time. Console errors the HUD's own routes cause (a plugin route the app has not mounted)
465
+ are not counted; `favicon.ico`, React DevTools and Fast Refresh messages are ignored. Exit codes:
466
+ 0 clean, 1 at least one route failed, 2 usage or setup error. `fixtures/next-app` runs this in CI.
467
+
205
468
  ## Design plugin
206
469
 
207
470
  `@hansenexus/hud/plugins/design` exports three client-only plugins:
@@ -216,15 +479,16 @@ tokens({
216
479
  ],
217
480
  sourceHint: "src/app/globals.css",
218
481
  });
219
- variants({ categories: async () => loadCategories(), reviewHref: "/dev/review" });
482
+ variants();
220
483
  forceState();
221
484
  ```
222
485
 
223
486
  - **Tokens** reads each value from the host document (a hidden probe in `<body>` carrying the
224
487
  group's `scope` attribute), so themed and scoped tokens show what the page renders. It re-reads
225
488
  when `<html>`/`<body>` attributes, stylesheets or the OS color scheme change.
226
- - **Variants** lists the app's variant categories through an adapter (a list or an async loader)
227
- and queues generate briefs when the tier grants `variants.generate`.
489
+ - **Variants** lists the page's live variant groups (below) with a switcher, agent scores and
490
+ Decide. An optional adapter (`variants({ categories, generate })`) adds the app's own variant
491
+ registry and the generate-brief queue (`variants.generate`).
228
492
  - **States** toggles every mounted `StateBoundary` between real, loading, empty and error. It
229
493
  needs `state.force`.
230
494
 
@@ -243,6 +507,342 @@ import { StateBoundary } from "@hansenexus/hud/state-boundary";
243
507
  `FORCE_STATE_MARKER` (`__HANSENEXUS_HUD_FORCE_STATE__`) is the store's global key; grep production
244
508
  chunks for it to prove the fold.
245
509
 
510
+ ### Variant groups
511
+
512
+ Design work happens on real pages with real data, not on fixture pages. `VariantGroup` from
513
+ `@hansenexus/hud/variants` wraps a region of a page with several alternatives; the choice lives in
514
+ the URL, so a link to `?variant=hero:bold` shows a colleague exactly that state:
515
+
516
+ ```tsx
517
+ import { VariantGroup } from "@hansenexus/hud/variants";
518
+
519
+ <VariantGroup
520
+ id="hero"
521
+ label="Hero"
522
+ default="current"
523
+ variants={{
524
+ current: { label: "Current", render: () => <Hero /> },
525
+ bold: { label: "Bold claim", render: () => <HeroBold /> },
526
+ }}
527
+ />;
528
+ ```
529
+
530
+ `VariantGroup` is a client component; use it from client code, since the render functions
531
+ cannot cross a server/client boundary as props. Several groups go in one param:
532
+ `?variant=hero:bold,cta:short`. The Variants panel lists every
533
+ mounted group under "Live on this page"; clicking a variant rewrites `?variant=` in place (no
534
+ history entry) and re-renders the group. Production-safe to import: outside development the
535
+ component renders the default and the bundler drops the registry and the URL parsing
536
+ (`VARIANT_MARKER`, `__HANSENEXUS_HUD_VARIANTS__`, is the global key to grep for).
537
+
538
+ Agents score variants, a human decides. The panel reads `score`, `rationale` and `scoredBy` per
539
+ variant through the storage seam and ranks them; with `file()` that is `.hud/variants.json`,
540
+ keyed `<group>:<id>`, which an agent writes by hand:
541
+
542
+ ```json
543
+ {
544
+ "hero:bold": { "score": 8.5, "scoredBy": "claude-code", "rationale": "Clear promise, concrete next step." },
545
+ "hero:current": { "score": 6, "scoredBy": "claude-code", "rationale": "Informative but generic." }
546
+ }
547
+ ```
548
+
549
+ **Decide** (needs `variants.decide`, granted on development only by default) writes
550
+ `status: "decided"` and `decidedAt` on the winner and `status: "rejected"` on the rest, then queues
551
+ a cleanup brief ("inline the winner, delete the losers and the wrapper, run the checks") through
552
+ the dispatch seam. The server half:
553
+
554
+ ```ts
555
+ import { variantsServer } from "@hansenexus/hud/plugins/design/server";
556
+ import { claudeCode } from "@hansenexus/hud/plugins/agent/server";
557
+ import { file } from "@hansenexus/hud/store";
558
+
559
+ export const { GET, POST } = createHudHandler([
560
+ variantsServer({ store: file(), dispatch: claudeCode() }),
561
+ ]);
562
+ ```
563
+
564
+ Without `dispatch` the decision is recorded and nothing is queued. `GET <apiBase>/variants/` lists
565
+ the records, `POST <apiBase>/variants/<group>/decide` decides; both answer only to same-origin
566
+ JSON requests. In the playground the hero is a variant group with seeded scores, and Decide logs
567
+ the brief to the browser console through the echo provider.
568
+
569
+ ## Storage seam
570
+
571
+ Plugins that keep state (variant scores and decisions, flag overrides) go through
572
+ `HudStore { get, set, list }` from `@hansenexus/hud/store`: named collections of JSON documents
573
+ keyed by id, values are plain objects. Three adapters implement it:
574
+
575
+ | adapter | where the bytes live |
576
+ | ---------- | ------------------------------------------------------------------------------------------------- |
577
+ | `file()` | default. One pretty-printed `<collection>.json` per collection under `.hud/` in the dev server's cwd (`{ dir }` to move it). Server side only; collection names are slugs and the resolved path is checked against the directory, so no request can name a file outside it. Writes are atomic and serialised per collection |
578
+ | `http()` | `{ baseUrl }` of `storeRoutes()` or `storeServer()`: `GET <base>/<collection>`, `GET`/`PUT <base>/<collection>/<id>`. Runs in the browser or on a server |
579
+ | `convex()` | `@hansenexus/hud/store/convex`, the one module in the package that imports the Convex client (optional peer). `{ url }` plus the deployment's `hudStore:get`, `hudStore:set` and `hudStore:list` functions (`{ functions }` renames them) |
580
+
581
+ `memory()` is the fourth, for tests and the playground. `storeServer({ store })` exposes a store
582
+ at `<apiBase>/store/…` and carries `data.write`, which the deployed-tier matrix never grants;
583
+ `storeRoutes(store)` are the same routes for a plugin's own `routes`. Writes refuse cross-site
584
+ requests.
585
+
586
+ ## Inspect plugin
587
+
588
+ `@hansenexus/hud/plugins/inspect` is a data inspector on top of the observe capture. The pill
589
+ counts requests; the panel lists every `fetch`, XHR and Next Server Action with method, status,
590
+ timing, request and response headers and bodies, and replays one on demand.
591
+
592
+ ```tsx
593
+ import { inspect } from "@hansenexus/hud/plugins/inspect";
594
+ defineHud({ app: "my-app", plugins: [inspect()] });
595
+ ```
596
+
597
+ - Capture starts when the HUD mounts (with or without `observe()`), so requests made before the
598
+ panel opens are already listed. The last 200 requests are kept; bodies are capped at 16 KB.
599
+ - A Server Action is recognised by its `Next-Action` header and shown with the action id; the
600
+ `actions` filter lists only those.
601
+ - **Redaction** happens before anything is stored: `authorization`, `cookie`, `set-cookie` and
602
+ every header, query parameter, JSON key, form field or multipart part whose name looks like a
603
+ token (`token`, `secret`, `password`, `api-key`, `auth`, `jwt`, …) shows as `[redacted]`, as do
604
+ bearer tokens and JWTs inside text bodies. `redactHeaders`, `redactBody` and `redactUrl` are
605
+ exported for tests.
606
+ - **Replay** sends the request again through the page's `fetch` (cookies included) and lists the
607
+ result tagged `replay`. Redacted headers and fields are not resent: their values are gone. A
608
+ request whose body could only be described (a file upload, a stream, a truncated body) cannot
609
+ be replayed; the button says why.
610
+ - Needs `inspect.read`: granted in development, preview and staging, not production.
611
+
612
+ ### Inspect adapters
613
+
614
+ Adapters add a tab each to the Inspect panel. Every adapter is its own subpath export, so an
615
+ app that omits one ships none of its code (`src/bundle.test.ts` proves it); the React Query and
616
+ SWR adapters read their caches structurally and import nothing from the libraries.
617
+
618
+ ```tsx
619
+ import { inspect } from "@hansenexus/hud/plugins/inspect";
620
+ import { inspectConvex } from "@hansenexus/hud/plugins/inspect/convex";
621
+ import { inspectReactQuery } from "@hansenexus/hud/plugins/inspect/react-query";
622
+ import { inspectSockets } from "@hansenexus/hud/plugins/inspect/sockets";
623
+ import { inspectSwr } from "@hansenexus/hud/plugins/inspect/swr";
624
+ import { mutate } from "swr";
625
+ import { cache } from "swr/_internal";
626
+
627
+ inspect({
628
+ adapters: [
629
+ inspectConvex({ client: convex }), // the app's ConvexReactClient (or ConvexClient / ConvexHttpClient)
630
+ inspectReactQuery({ queryClient }),
631
+ inspectSwr({ cache, mutate }), // the default cache; with a provider, pass that cache and its scoped mutate
632
+ inspectSockets(),
633
+ ],
634
+ });
635
+ ```
636
+
637
+ - **Convex** wraps the client's `watchQuery`, `onUpdate`, `mutation`, `action` and `query` in
638
+ place, so `useQuery`, `useQueries` and `usePaginatedQuery` are covered. Live queries list with
639
+ the latency to their first result, update count, subscriber count and last result; mutations,
640
+ actions and one-shot queries with their duration, result or error. Args and results are
641
+ redacted like request bodies. Needs the `convex` peer.
642
+ - **Query** (React Query) lists every cache entry with its key, status, freshness (`fetching`,
643
+ `inactive`, `invalidated`, `stale`, `fresh`), observer count and age, the data redacted, and
644
+ offers Invalidate (exact key) and Remove per entry plus invalidate-all.
645
+ - **SWR** lists every cache key with its validation state, age and data (redacted); Revalidate
646
+ calls `mutate` with the key the app passed, tuple keys included. The cache's `set` and `delete`
647
+ are wrapped in place to timestamp writes.
648
+ - **Sockets** patches `WebSocket` and `EventSource` when the factory runs and checks again when
649
+ the HUD mounts: a mock layer that wrapped them in between (MSW's `worker.start()`) is wrapped
650
+ in turn, so the socket the app holds is the one recorded. Connections show state, time to
651
+ open, protocol and close code; frames in both directions show size and redacted text (named SSE
652
+ events included), binaries as a note. `ignore` leaves URLs out; the HUD's own routes are
653
+ ignored by default.
654
+
655
+ Each factory returns an `InspectAdapter` (`{ id, title, Panel, useCount?, install?, dispose? }`),
656
+ the whole contract an adapter of your own needs. `dispose()` restores what the factory wrapped.
657
+ The playground (`bun run dev`) carries a demo per adapter in the page's "Daten" section.
658
+
659
+ ## A11y and SEO plugins
660
+
661
+ Both are client only and need no server half.
662
+
663
+ ```tsx
664
+ import { a11y } from "@hansenexus/hud/plugins/a11y";
665
+ import { seo } from "@hansenexus/hud/plugins/seo";
666
+
667
+ defineHud({ app: "my-app", plugins: [a11y(), seo()] });
668
+ ```
669
+
670
+ - **A11y** runs [axe-core](https://github.com/dequelabs/axe-core) on demand. Nothing is fetched
671
+ until Run (or the `Run accessibility audit` command): by default the plugin appends a script
672
+ from jsDelivr (`AXE_URL`, pinned to `AXE_VERSION`); pass
673
+ `a11y({ load: () => import("axe-core") })` to serve the package you installed as its own chunk
674
+ instead, or `axeUrl` for another host. The HUD's own host is excluded from the audit. Findings
675
+ list one row per element, highest impact first; clicking one outlines the element with the
676
+ grabber overlay and `?` opens the rule's documentation. The pill shows the count after a run.
677
+ - **SEO** checks the page from mount on and again whenever `<head>` changes (client-side routers,
678
+ `document.title`) or history moves: `<title>` and `meta description` present and within length,
679
+ `rel=canonical` absolute and pointing at this page, Open Graph title/description/image (url and
680
+ type recommended), every JSON-LD script parses and carries `@context` and `@type`, `hreflang`
681
+ links are absolute, valid tags with `x-default` and a self-reference, and `robots`/`googlebot`
682
+ directives that keep the page out of results. The pill counts the errors; the panel lists every
683
+ check with its value or what is wrong. `runSeoChecks(document, url)` is exported for tests and
684
+ CI scripts.
685
+
686
+ The playground's `index.html` and the "Newsletter" section carry deliberately broken meta and
687
+ markup for both panels.
688
+ ## Data plugin
689
+
690
+ `@hansenexus/hud/plugins/data` switches who the page is signed in as and overrides feature flags
691
+ from one panel. The pill shows the current user and the number of overridden flags.
692
+
693
+ ```tsx
694
+ import { data } from "@hansenexus/hud/plugins/data";
695
+ defineHud({ app: "my-app", plugins: [data()] });
696
+ ```
697
+
698
+ ```ts
699
+ import { cookieImpersonation, dataServer } from "@hansenexus/hud/plugins/data/server";
700
+ import { file } from "@hansenexus/hud/store";
701
+
702
+ const users = [
703
+ { id: "u_ada", label: "Ada (admin)", role: "admin" },
704
+ { id: "u_cleo", label: "Cleo (customer)", role: "customer" },
705
+ ];
706
+ export const { GET, POST, PUT, DELETE } = createHudHandler([
707
+ dataServer({
708
+ auth: cookieImpersonation({ users }),
709
+ flags: [
710
+ { key: "new-checkout", label: "New checkout", value: false },
711
+ { key: "promo-text", type: "string", value: "", scope: "local" },
712
+ ],
713
+ store: file(),
714
+ }),
715
+ ]);
716
+ ```
717
+
718
+ Both halves carry `data.write`, which `access` grants in development, on staging or preview only
719
+ through the matrix, and never on production (see Deployed tiers).
720
+
721
+ ### Role switch (auth seam)
722
+
723
+ Picking a user signs the browser in as that fixture user and reloads the page. The adapter knows
724
+ where its library keeps the session; the app supplies the one thing only it can, a session for a
725
+ fixture user:
726
+
727
+ | adapter | signs in by | the app honours it through |
728
+ | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
729
+ | `convexAuth({ users, mint })` | `mint(user)` → `{ token, refreshToken }` from the app's development-only Convex action; written to `__convexAuthJWT`/`__convexAuthRefreshToken` (`__Host-` off localhost) and, with `storageNamespace`, into Convex Auth's `localStorage` keys for the Vite flavour | `@convex-dev/auth` reads them like any session |
730
+ | `betterAuth({ users, auth })` | `auth.api.signInEmail({ email, password })` for the fixture user's credentials; the cookies better-auth sets are forwarded | better-auth reads its own session cookie |
731
+ | `cookieImpersonation({ users })` | a signed `hud-impersonate` cookie naming the user (signed with `HUD_ACCESS_SECRET` or `HUD_ACCESS_PASSWORD` when set, unsigned in development) | `readImpersonation(request)` in the app's auth layer: when it names a user, act as that user |
732
+
733
+ `users` is the fixture list (`{ id, label, role?, email?, password? }`; passwords never reach the
734
+ browser) or a loader. "Signed in as" asks the adapter for the current user on every panel load.
735
+ A `HudAuthAdapter` of your own is `{ id, label, users, current, signIn, signOut }`.
736
+
737
+ ### Feature flags
738
+
739
+ `flags` is the flag source: the definitions themselves, or `{ list(request) }` over the app's real
740
+ source (PostHog, Unleash, a table). The panel shows each flag's real value and sets an override
741
+ in one of two scopes:
742
+
743
+ | scope | lives in | read by |
744
+ | -------- | ---------------------------------------------------------- | -------------------------------------------------- |
745
+ | `cookie` | the `hud-flags` cookie (URL-encoded JSON, not httpOnly) | the server (SSR, Server Actions, routes) and the client |
746
+ | `local` | `localStorage["hud-flags"]` | the client |
747
+
748
+ The override persists through the storage seam (`.hud/flags.json` with `file()`, one document
749
+ `{ "overrides": { "new-checkout": { "value": true, "scope": "cookie" } } }`) until reset; every panel
750
+ load re-emits the cookie and mirrors the local scope, so a fresh browser is in step with the file.
751
+ The app reads overrides through the production-safe, dependency-free `@hansenexus/hud/flags`:
752
+
753
+ ```ts
754
+ import { flagOverride, readFlagOverrides } from "@hansenexus/hud/flags";
755
+
756
+ // server: the request's cookie header
757
+ const newCheckout = flagOverride("new-checkout", { cookie: request.headers.get("cookie") }, flags.newCheckout);
758
+ // client: cookie and localStorage, local winning
759
+ const all = readFlagOverrides({ cookie: document.cookie, storage: localStorage });
760
+ ```
761
+
762
+ Gate the read like the HUD itself (`NODE_ENV`, `NEXT_PUBLIC_HUD_ENABLED`): a visitor can set a
763
+ cookie by hand, and production never gets one from the HUD. In the playground, `?auth=convex` and
764
+ `?auth=better` run the role switch through the other two adapters against stand-in backends; the
765
+ CTA text, a promo banner and the number of content sections follow the three demo flags.
766
+
767
+ ### Seeds
768
+
769
+ `seeds` are functions the panel runs on the server, with the request (so a seed can act as the
770
+ user the role switch signed in): fill a table, reset the database, put an account into a state.
771
+
772
+ ```ts
773
+ dataServer({
774
+ seeds: [
775
+ { id: "orders:sample", label: "Seed 20 orders", run: () => seedOrders(20) },
776
+ { id: "reset", label: "Reset database", danger: true, run: () => resetDatabase() },
777
+ ],
778
+ });
779
+ ```
780
+
781
+ Run posts `POST <apiBase>/data/seeds/:id`; what the seed returns is shown as JSON next to the
782
+ duration, a throw as the failure. A `danger` seed asks for a second click (Confirm).
783
+
784
+ ### Mock scenarios (MSW)
785
+
786
+ Scenarios are alternative answers per endpoint, `real | empty | error | slow` in the panel, at most
787
+ one active per endpoint. They are declared msw-free, in one module every side imports:
788
+
789
+ ```ts
790
+ // hud/scenarios.ts
791
+ import type { HudMockScenario } from "@hansenexus/hud/plugins/data";
792
+
793
+ export const scenarios: HudMockScenario[] = [
794
+ { id: "orders:empty", endpoint: "GET /api/orders", label: "empty", json: [] },
795
+ { id: "orders:error", endpoint: "GET /api/orders", label: "error", status: 503, json: { error: "down" } },
796
+ { id: "orders:slow", endpoint: "GET /api/orders", label: "slow", delay: 2000 },
797
+ {
798
+ id: "order:missing",
799
+ endpoint: "GET /api/orders/:id",
800
+ label: "missing",
801
+ respond: (_request, { params }) => Response.json({ error: `no order ${params.id}` }, { status: 404 }),
802
+ },
803
+ ];
804
+ ```
805
+
806
+ `endpoint` is `METHOD path`: a relative path matches on every origin, an absolute URL on that
807
+ origin only, `:name` captures a segment, a trailing `*` the rest, `*` as the method any method.
808
+ `json`/`status`/`headers` build the answer, `respond` takes over, `delay` waits first; a scenario
809
+ with only `delay` passes the real answer through late. The active set is one document in the store
810
+ (`.hud/mocks.json`: `{ "active": { "GET /api/orders": "orders:empty" } }`) and toggles through
811
+ `PUT|DELETE <apiBase>/data/mocks/:id` and `DELETE <apiBase>/data/mocks`.
812
+
813
+ Three places take the list:
814
+
815
+ ```ts
816
+ // app/api/hud/[...hud]/route.ts: lists and toggles them
817
+ dataServer({ mocks: scenarios, store: file() });
818
+
819
+ // app/hud.tsx: client fetches, through an MSW worker loaded on demand
820
+ data({ mocks: { scenarios, worker: () => import("@hansenexus/hud/plugins/data/msw-browser") } });
821
+
822
+ // instrumentation.ts: server fetches (RSC, Server Actions, route handlers), through msw/node
823
+ export async function register() {
824
+ if (process.env.NEXT_RUNTIME === "nodejs" && process.env.NODE_ENV === "development") {
825
+ const { startMockServer } = await import("@hansenexus/hud/plugins/data/msw-node");
826
+ const { scenarios } = await import("./hud/scenarios");
827
+ await startMockServer({ scenarios, store: file() });
828
+ }
829
+ }
830
+ ```
831
+
832
+ `msw` is an optional peer; only the two `msw-*` entries load it, at run time, so the panel, the
833
+ route and the scenario module never depend on it. Install it with `bun add -d msw` and put its
834
+ worker script in `public/` with `npx msw init public/` (the fixture copies it in its `dev` script).
835
+ The panel shows a `client` and a `server` badge: `live` when that side intercepts, `off` with a
836
+ setup hint when the loader or `startMockServer()` is missing, `failed` with the reason when a
837
+ start rejected (no worker script, `msw` not installed). Nothing crashes either way; toggles keep
838
+ working for the side that is live. The worker starts when the HUD mounts, after the page's own
839
+ first fetches, which go to the network; the Node side covers the initial server render. An app
840
+ that already runs an MSW worker passes its own `{ startMockWorker }` module and registers the
841
+ HUD's catch-all on that worker (`worker.use(http.all("*", ({ request }) => resolve(request)))`),
842
+ as the playground does in `plugins/data-mocks.ts`. `fixtures/next-app` wires every side: `/orders`
843
+ renders the orders count through a React Server Component, a Server Action and a client fetch,
844
+ and `e2e/data-fixture.spec.ts` toggles the scenarios against all three.
845
+
246
846
  ## Review entrypoint (production)
247
847
 
248
848
  `@hansenexus/hud/review` is the client review widget: a pill on the right edge, the element
@@ -282,9 +882,31 @@ dependencies so a Node gate script can import it:
282
882
  | `HUD_REVIEW_MARKER` | `__HANSENEXUS_HUD_REVIEW__` | only where `/review` is meant to ship |
283
883
 
284
884
  CI proves both on every PR: `fixtures/next-app` mounts the dev HUD behind the loader's build gate
285
- and `<Review>` beside it, installs the packed tarball, runs `next build` and fails on any dev
286
- marker or dev-only string in `.next/static` (`bun run build && bun run --cwd fixtures/next-app
287
- gate`). `fixtures/next-app/scripts/check-bundle.js` is a starting point for an app's own gate.
885
+ and `<Review>` beside it, installs the packed tarball, loads `withHud` from a CommonJS config
886
+ through `require()`, runs `next build --turbopack` with `NEXT_PUBLIC_HUD_ENABLED` unset and fails
887
+ on any dev marker or dev-only string in `.next/static` (`bun run build && bun run --cwd
888
+ fixtures/next-app gate`). `fixtures/vite-app` does the same for Vite: `hud()` in its config, the
889
+ `import.meta.env.DEV` loader gate, the packed tarball, `vite build`, no dev marker in `dist`
890
+ (`bun run --cwd fixtures/vite-app gate`). Both fixtures define their HUD through
891
+ `@hansenexus/hud/auto`, so the gate covers the generated module too. Either fixture's
892
+ `scripts/check-bundle.js` is a starting point for an app's own gate.
893
+
894
+ ### Bundle budget
895
+
896
+ `bun run check:size` (part of `bun run check` and CI) bundles each entry from `dist/` the way an
897
+ app would, React external and minified, and splits the output into what runs at HUD mount (the
898
+ entry and its static imports) and what sits behind `import()`. The eager part is the budget, gzip:
899
+
900
+ | entry | eager budget | also required |
901
+ | -------------------- | --------------------- | ----------------------------------- |
902
+ | core (`defineHud`) | 40 KB | |
903
+ | each `plugins/<id>` | 8 KB on top of core | at least one lazy chunk (the panel) |
904
+ | `auto` (stand-in) | 24 KB on top of core | at least one lazy chunk |
905
+
906
+ The dev core sits at about 13 KB; a plugin's eager cost is its pill and whatever must run from
907
+ mount (console capture, request capture, the SEO check). The script prints a row per entry with
908
+ the lazy chunk sizes, so a panel that slips into the eager graph shows up as a missing lazy chunk
909
+ and a growing eager number.
288
910
 
289
911
  ## Release
290
912