@hansenexus/hud 0.4.0 → 0.5.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 (157) hide show
  1. package/README.md +603 -9
  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.d.ts +52 -0
  57. package/dist/next/config.js +78 -0
  58. package/dist/next.d.ts +14 -4
  59. package/dist/next.js +5 -3
  60. package/dist/observe-CdDnDBRP.js +89 -0
  61. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  62. package/dist/ops-panel-CEqDe_UT.js +234 -0
  63. package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
  64. package/dist/plugins/a11y.d.ts +2 -0
  65. package/dist/plugins/a11y.js +2 -0
  66. package/dist/plugins/access/server.d.ts +5 -5
  67. package/dist/plugins/access/server.js +4 -3
  68. package/dist/plugins/access.d.ts +5 -5
  69. package/dist/plugins/access.js +16 -215
  70. package/dist/plugins/agent/server.d.ts +3 -38
  71. package/dist/plugins/agent/server.js +47 -21
  72. package/dist/plugins/agent.d.ts +4 -4
  73. package/dist/plugins/agent.js +6 -348
  74. package/dist/plugins/capture/server.d.ts +92 -0
  75. package/dist/plugins/capture/server.js +248 -0
  76. package/dist/plugins/capture.d.ts +24 -0
  77. package/dist/plugins/capture.js +70 -0
  78. package/dist/plugins/data/msw-browser.d.ts +2 -0
  79. package/dist/plugins/data/msw-browser.js +39 -0
  80. package/dist/plugins/data/msw-node.d.ts +36 -0
  81. package/dist/plugins/data/msw-node.js +68 -0
  82. package/dist/plugins/data/server.d.ts +257 -0
  83. package/dist/plugins/data/server.js +717 -0
  84. package/dist/plugins/data.d.ts +6 -0
  85. package/dist/plugins/data.js +51 -0
  86. package/dist/plugins/design/server.d.ts +54 -0
  87. package/dist/plugins/design/server.js +198 -0
  88. package/dist/plugins/design.d.ts +4 -124
  89. package/dist/plugins/design.js +4 -619
  90. package/dist/plugins/inspect/convex.d.ts +2 -0
  91. package/dist/plugins/inspect/convex.js +486 -0
  92. package/dist/plugins/inspect/react-query.d.ts +2 -0
  93. package/dist/plugins/inspect/react-query.js +225 -0
  94. package/dist/plugins/inspect/sockets.d.ts +51 -0
  95. package/dist/plugins/inspect/sockets.js +397 -0
  96. package/dist/plugins/inspect/swr.d.ts +2 -0
  97. package/dist/plugins/inspect/swr.js +218 -0
  98. package/dist/plugins/inspect.d.ts +4 -0
  99. package/dist/plugins/inspect.js +3 -0
  100. package/dist/plugins/observe.d.ts +4 -64
  101. package/dist/plugins/observe.js +1 -616
  102. package/dist/plugins/ops/server.d.ts +1 -1
  103. package/dist/plugins/ops/server.js +2 -1
  104. package/dist/plugins/ops.d.ts +2 -1
  105. package/dist/plugins/ops.js +15 -336
  106. package/dist/plugins/routes/server.d.ts +88 -0
  107. package/dist/plugins/routes/server.js +62 -0
  108. package/dist/plugins/routes.d.ts +3 -0
  109. package/dist/plugins/routes.js +216 -0
  110. package/dist/plugins/seo.d.ts +2 -0
  111. package/dist/plugins/seo.js +2 -0
  112. package/dist/plugins/vitals.d.ts +2 -25
  113. package/dist/plugins/vitals.js +3 -2
  114. package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
  115. package/dist/poll-CjKsWZi8.js +89 -0
  116. package/dist/requests-BwD6MKEq.js +282 -0
  117. package/dist/requests-CJrUf465.d.ts +50 -0
  118. package/dist/review.js +2 -2
  119. package/dist/same-origin-BGet22CC.js +21 -0
  120. package/dist/scan-DzJNXqOk.js +165 -0
  121. package/dist/seo-Dq9q_QkO.js +551 -0
  122. package/dist/seo-panel-CfiY-TnT.js +124 -0
  123. package/dist/server.d.ts +2 -2
  124. package/dist/server.js +2 -105
  125. package/dist/sessions-panel-COvhPAzv.js +98 -0
  126. package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
  127. package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
  128. package/dist/store/convex.d.ts +33 -0
  129. package/dist/store/convex.js +52 -0
  130. package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
  131. package/dist/store-Ync9eb1G.js +67 -0
  132. package/dist/store.d.ts +76 -0
  133. package/dist/store.js +188 -0
  134. package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
  135. package/dist/styles-DKU_P8MH.js +139 -0
  136. package/dist/styles-DPpDPmzi.js +68 -0
  137. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  138. package/dist/types-B-ulf2Jp.js +8 -0
  139. package/dist/types-BIgGf-0C.d.ts +25 -0
  140. package/dist/types-BIkI-qN8.js +30 -0
  141. package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
  142. package/dist/types-DIdPfjtV.js +6 -0
  143. package/dist/types-DaJcsEjO.d.ts +44 -0
  144. package/dist/types-Dn68psVz.d.ts +118 -0
  145. package/dist/types-szkr2QOF.d.ts +39 -0
  146. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  147. package/dist/variant-groups-TIfO3NIj.js +137 -0
  148. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  149. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  150. package/dist/variants-types-CcRf119M.d.ts +63 -0
  151. package/dist/variants.d.ts +43 -0
  152. package/dist/variants.js +83 -0
  153. package/dist/vitals-panel-BCmMUntW.js +30 -0
  154. package/dist/vite.d.ts +37 -0
  155. package/dist/vite.js +134 -0
  156. package/package.json +65 -5
  157. package/dist/define-hud-BBzsSl8b.d.ts +0 -36
@@ -0,0 +1,103 @@
1
+ import { a as assertId, i as assertCollection, o as assertValue, s as isStoreValue, t as HudStoreError } from "./types-BIkI-qN8.js";
2
+ //#region src/store/file.ts
3
+ /** `process.cwd()`, or undefined where there is none (a browser, an edge runtime). */
4
+ function currentDir() {
5
+ const proc = globalThis.process;
6
+ return typeof proc?.cwd === "function" ? proc.cwd() : void 0;
7
+ }
8
+ async function nodeModules() {
9
+ try {
10
+ const [fs, path] = await Promise.all([import("node:fs/promises"), import("node:path")]);
11
+ return {
12
+ fs,
13
+ path
14
+ };
15
+ } catch {
16
+ throw new HudStoreError("hud store: file() needs a Node runtime", 500);
17
+ }
18
+ }
19
+ function isNotFound(error) {
20
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
21
+ }
22
+ /**
23
+ * The default store: one JSON file per collection under `.hud/`, keyed by id,
24
+ * so a human or an agent can read and edit it (`.hud/variants.json`:
25
+ * `{ "hero:b": { "score": 8, "rationale": "…", "scoredBy": "claude" } }`).
26
+ *
27
+ * Server side only: the browser reaches it through `storeRoutes()` or a
28
+ * plugin's own routes. The collection name is validated and the resolved
29
+ * path checked against `dir`, so no request can name a file outside it.
30
+ * Writes go to a temporary file and are renamed into place, one at a time
31
+ * per collection.
32
+ */
33
+ function file({ dir } = {}) {
34
+ const queues = /* @__PURE__ */ new Map();
35
+ async function resolved(collection) {
36
+ assertCollection(collection);
37
+ const { fs, path } = await nodeModules();
38
+ const base = dir ?? (currentDir() === void 0 ? void 0 : `${currentDir()}/.hud`);
39
+ if (!base) throw new HudStoreError("hud store: file() has no directory (no cwd)", 500);
40
+ const root = path.resolve(base);
41
+ const target = path.resolve(root, `${collection}.json`);
42
+ if (!target.startsWith(root + path.sep)) throw new HudStoreError(`hud store: "${collection}" resolves outside ${root}`);
43
+ return {
44
+ fs,
45
+ path,
46
+ root,
47
+ target
48
+ };
49
+ }
50
+ async function read(collection) {
51
+ const { fs, target } = await resolved(collection);
52
+ let text;
53
+ try {
54
+ text = await fs.readFile(target, "utf8");
55
+ } catch (error) {
56
+ if (isNotFound(error)) return {};
57
+ throw error;
58
+ }
59
+ let parsed;
60
+ try {
61
+ parsed = JSON.parse(text);
62
+ } catch {
63
+ throw new HudStoreError(`hud store: ${target} is not valid JSON`, 500);
64
+ }
65
+ if (!isStoreValue(parsed)) throw new HudStoreError(`hud store: ${target} must hold a JSON object keyed by id`, 500);
66
+ const documents = {};
67
+ for (const [id, value] of Object.entries(parsed)) if (isStoreValue(value)) documents[id] = value;
68
+ return documents;
69
+ }
70
+ /** Runs `task` after every earlier write to the collection has finished. */
71
+ function serial(collection, task) {
72
+ const next = (queues.get(collection) ?? Promise.resolve()).then(task, task);
73
+ queues.set(collection, next.catch(() => void 0));
74
+ return next;
75
+ }
76
+ return {
77
+ async get(collection, id) {
78
+ assertId(id);
79
+ return (await read(collection))[id] ?? null;
80
+ },
81
+ async set(collection, id, value) {
82
+ assertId(id);
83
+ assertValue(value);
84
+ await serial(collection, async () => {
85
+ const { fs, root, target } = await resolved(collection);
86
+ const documents = await read(collection);
87
+ documents[id] = value;
88
+ await fs.mkdir(root, { recursive: true });
89
+ const tmp = `${target}.${Date.now().toString(36)}.tmp`;
90
+ await fs.writeFile(tmp, `${JSON.stringify(documents, null, 2)}\n`, "utf8");
91
+ await fs.rename(tmp, target);
92
+ });
93
+ },
94
+ async list(collection) {
95
+ return Object.entries(await read(collection)).map(([id, value]) => ({
96
+ id,
97
+ value
98
+ }));
99
+ }
100
+ };
101
+ }
102
+ //#endregion
103
+ export { file as t };
@@ -0,0 +1,58 @@
1
+ //#region src/plugins/data/flags.d.ts
2
+ /**
3
+ * `@hansenexus/hud/flags`: how an app reads the HUD's feature-flag overrides.
4
+ *
5
+ * Production-safe and dependency-free: it parses two small JSON documents the
6
+ * data plugin writes, one in the `hud-flags` cookie (scope `cookie`, read by
7
+ * the server and the client) and one in `localStorage["hud-flags"]` (scope
8
+ * `local`, client only). Nothing here knows whether the HUD exists; an
9
+ * override is whatever those two places say. Gate the read at the import
10
+ * site like the HUD itself (`NODE_ENV`, `NEXT_PUBLIC_HUD_ENABLED`), since a
11
+ * visitor can set a cookie by hand and production never gets one from the HUD.
12
+ */
13
+ type HudFlagValue = boolean | string | number;
14
+ /** Where an override lives, which decides who can read it. */
15
+ type HudFlagScope = "cookie" | "local";
16
+ declare const HUD_FLAG_SCOPES: readonly HudFlagScope[];
17
+ /** One override, as the data plugin stores it (`.hud/flags.json` with `file()`). */
18
+ interface HudFlagOverride {
19
+ key: string;
20
+ value: HudFlagValue;
21
+ scope: HudFlagScope;
22
+ }
23
+ /** Cookie carrying the `cookie`-scoped overrides, URL-encoded JSON `{ key: value }`. */
24
+ declare const FLAGS_COOKIE = "hud-flags";
25
+ /** `localStorage` key carrying the `local`-scoped overrides, JSON `{ key: value }`. */
26
+ declare const FLAGS_STORAGE_KEY = "hud-flags";
27
+ /** Flag keys are slugs with dots allowed (`checkout.new`), one line, bounded. */
28
+ declare const FLAG_KEY: RegExp;
29
+ declare function isFlagValue(value: unknown): value is HudFlagValue;
30
+ declare function isFlagScope(value: unknown): value is HudFlagScope;
31
+ /** Parses a `{ key: value }` document; anything malformed reads as no overrides. */
32
+ declare function parseFlagOverrides(text: string | null | undefined): Record<string, HudFlagValue>;
33
+ /** The `hud-flags` cookie out of a `Cookie:` header or `document.cookie`. */
34
+ declare function readFlagCookie(cookieHeader: string | null | undefined): string | undefined;
35
+ interface FlagOverrideSource {
36
+ /** A `Cookie:` request header on the server, `document.cookie` in the browser. */
37
+ cookie?: string | null | undefined;
38
+ /** `localStorage` (or anything with `getItem`) in the browser; omit on the server. */
39
+ storage?: Pick<Storage, "getItem"> | null | undefined;
40
+ }
41
+ /**
42
+ * Every override the app should honour, `local` winning over `cookie` when
43
+ * both name a key. On the server pass the request's cookie header; in the
44
+ * browser pass `document.cookie` and `localStorage`.
45
+ */
46
+ declare function readFlagOverrides({ cookie, storage }: FlagOverrideSource): Record<string, HudFlagValue>;
47
+ /** One flag's override, or `fallback` (the app's real value) when there is none. */
48
+ declare function flagOverride<T extends HudFlagValue>(key: string, source: FlagOverrideSource, fallback: T): HudFlagValue | T;
49
+ /** The JSON document for one scope: `{ key: value }`, keys sorted so the cookie is stable. */
50
+ declare function serializeFlagOverrides(overrides: readonly HudFlagOverride[], scope: HudFlagScope): string;
51
+ /**
52
+ * `Set-Cookie` value for the cookie scope: the document when there is one
53
+ * override, removal when there is none. Not httpOnly on purpose, since the
54
+ * app reads it in the browser too; `SameSite=Lax` so it survives navigation.
55
+ */
56
+ declare function flagCookieString(overrides: readonly HudFlagOverride[]): string;
57
+ //#endregion
58
+ export { HUD_FLAG_SCOPES as a, HudFlagValue as c, isFlagScope as d, isFlagValue as f, serializeFlagOverrides as g, readFlagOverrides as h, FlagOverrideSource as i, flagCookieString as l, readFlagCookie as m, FLAGS_STORAGE_KEY as n, HudFlagOverride as o, parseFlagOverrides as p, FLAG_KEY as r, HudFlagScope as s, FLAGS_COOKIE as t, flagOverride as u };
@@ -0,0 +1,2 @@
1
+ import { a as HUD_FLAG_SCOPES, c as HudFlagValue, d as isFlagScope, f as isFlagValue, g as serializeFlagOverrides, h as readFlagOverrides, i as FlagOverrideSource, l as flagCookieString, m as readFlagCookie, n as FLAGS_STORAGE_KEY, o as HudFlagOverride, p as parseFlagOverrides, r as FLAG_KEY, s as HudFlagScope, t as FLAGS_COOKIE, u as flagOverride } from "./flags-DVtaJ8pQ.js";
2
+ export { FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, FlagOverrideSource, HUD_FLAG_SCOPES, HudFlagOverride, HudFlagScope, HudFlagValue, flagCookieString, flagOverride, isFlagScope, isFlagValue, parseFlagOverrides, readFlagCookie, readFlagOverrides, serializeFlagOverrides };
package/dist/flags.js ADDED
@@ -0,0 +1,82 @@
1
+ //#region src/plugins/data/flags.ts
2
+ const HUD_FLAG_SCOPES = ["cookie", "local"];
3
+ /** Cookie carrying the `cookie`-scoped overrides, URL-encoded JSON `{ key: value }`. */
4
+ const FLAGS_COOKIE = "hud-flags";
5
+ /** `localStorage` key carrying the `local`-scoped overrides, JSON `{ key: value }`. */
6
+ const FLAGS_STORAGE_KEY = "hud-flags";
7
+ /** Flag keys are slugs with dots allowed (`checkout.new`), one line, bounded. */
8
+ const FLAG_KEY = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,99}$/;
9
+ function isFlagValue(value) {
10
+ return typeof value === "boolean" || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
11
+ }
12
+ function isFlagScope(value) {
13
+ return value === "cookie" || value === "local";
14
+ }
15
+ /** Parses a `{ key: value }` document; anything malformed reads as no overrides. */
16
+ function parseFlagOverrides(text) {
17
+ if (!text) return {};
18
+ let parsed;
19
+ try {
20
+ parsed = JSON.parse(text);
21
+ } catch {
22
+ return {};
23
+ }
24
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
25
+ const overrides = {};
26
+ for (const [key, value] of Object.entries(parsed)) if (FLAG_KEY.test(key) && isFlagValue(value)) overrides[key] = value;
27
+ return overrides;
28
+ }
29
+ /** The `hud-flags` cookie out of a `Cookie:` header or `document.cookie`. */
30
+ function readFlagCookie(cookieHeader) {
31
+ if (!cookieHeader) return void 0;
32
+ for (const part of cookieHeader.split(";")) {
33
+ const trimmed = part.trim();
34
+ if (trimmed.startsWith(`hud-flags=`)) try {
35
+ return decodeURIComponent(trimmed.slice(10));
36
+ } catch {
37
+ return;
38
+ }
39
+ }
40
+ }
41
+ /**
42
+ * Every override the app should honour, `local` winning over `cookie` when
43
+ * both name a key. On the server pass the request's cookie header; in the
44
+ * browser pass `document.cookie` and `localStorage`.
45
+ */
46
+ function readFlagOverrides({ cookie, storage }) {
47
+ const fromCookie = parseFlagOverrides(readFlagCookie(cookie));
48
+ let fromStorage = {};
49
+ if (storage) try {
50
+ fromStorage = parseFlagOverrides(storage.getItem(FLAGS_STORAGE_KEY));
51
+ } catch {
52
+ fromStorage = {};
53
+ }
54
+ return {
55
+ ...fromCookie,
56
+ ...fromStorage
57
+ };
58
+ }
59
+ /** One flag's override, or `fallback` (the app's real value) when there is none. */
60
+ function flagOverride(key, source, fallback) {
61
+ const value = readFlagOverrides(source)[key];
62
+ return value === void 0 ? fallback : value;
63
+ }
64
+ /** The JSON document for one scope: `{ key: value }`, keys sorted so the cookie is stable. */
65
+ function serializeFlagOverrides(overrides, scope) {
66
+ const document = {};
67
+ for (const override of [...overrides].sort((a, b) => a.key.localeCompare(b.key))) if (override.scope === scope) document[override.key] = override.value;
68
+ return JSON.stringify(document);
69
+ }
70
+ /**
71
+ * `Set-Cookie` value for the cookie scope: the document when there is one
72
+ * override, removal when there is none. Not httpOnly on purpose, since the
73
+ * app reads it in the browser too; `SameSite=Lax` so it survives navigation.
74
+ */
75
+ function flagCookieString(overrides) {
76
+ const document = serializeFlagOverrides(overrides, "cookie");
77
+ const base = `${FLAGS_COOKIE}=`;
78
+ if (document === "{}") return `${base}; Path=/; SameSite=Lax; Max-Age=0`;
79
+ return `${base}${encodeURIComponent(document)}; Path=/; SameSite=Lax; Max-Age=2592000`;
80
+ }
81
+ //#endregion
82
+ export { FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, HUD_FLAG_SCOPES, flagCookieString, flagOverride, isFlagScope, isFlagValue, parseFlagOverrides, readFlagCookie, readFlagOverrides, serializeFlagOverrides };
@@ -0,0 +1,97 @@
1
+ import { i as formatForceStateParam, o as getForceStateStore, r as FORCE_STATE_PARAM, s as resolveForcedState, t as FORCED_STATES } from "./force-state-BaqWsmrf.js";
2
+ import { i as useForceState } from "./design-D0kGgPoP.js";
3
+ import { t as DESIGN_CSS } from "./styles-DKU_P8MH.js";
4
+ import { useEffect } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ //#region src/plugins/design/force-state-panel.tsx
7
+ const CHOICES = [null, ...FORCED_STATES];
8
+ /**
9
+ * Toggles every mounted `StateBoundary` between its real state and a forced
10
+ * loading, empty or error. Toggles live in memory: a reload returns every
11
+ * boundary to auto, so a forgotten toggle cannot outlive the page.
12
+ */
13
+ function ForceStatePanel() {
14
+ const store = getForceStateStore();
15
+ const snapshot = useForceState();
16
+ const hasOverrides = Object.keys(snapshot.overrides).length > 0;
17
+ useEffect(() => store.syncSearch(window.location.search), [store]);
18
+ return /* @__PURE__ */ jsxs("div", {
19
+ className: "design",
20
+ "data-hud-force-state": "",
21
+ children: [
22
+ /* @__PURE__ */ jsx("style", { children: DESIGN_CSS }),
23
+ /* @__PURE__ */ jsxs("section", {
24
+ className: "design-section",
25
+ "aria-label": "State boundaries",
26
+ children: [/* @__PURE__ */ jsxs("div", {
27
+ className: "design-heading",
28
+ children: [/* @__PURE__ */ jsx("span", { children: "State boundaries" }), hasOverrides && /* @__PURE__ */ jsx("button", {
29
+ type: "button",
30
+ className: "design-link",
31
+ onClick: () => store.clearOverrides(),
32
+ children: "reset all"
33
+ })]
34
+ }), snapshot.boundaries.length === 0 ? /* @__PURE__ */ jsx("p", {
35
+ className: "design-hint",
36
+ children: "No state boundary on this page. Wrap a query branch in StateBoundary from @hansenexus/hud/state-boundary to list it here."
37
+ }) : snapshot.boundaries.map((boundary) => {
38
+ const override = snapshot.overrides[boundary.id] ?? null;
39
+ const effective = resolveForcedState(snapshot, boundary);
40
+ return /* @__PURE__ */ jsxs("div", {
41
+ className: "design-boundary",
42
+ children: [/* @__PURE__ */ jsxs("div", {
43
+ className: "design-row",
44
+ children: [/* @__PURE__ */ jsxs("span", {
45
+ className: "design-grow design-mono",
46
+ children: [boundary.parentId ? "↳ " : "", boundary.id]
47
+ }), /* @__PURE__ */ jsx("span", {
48
+ className: "design-badge",
49
+ "data-tone": effective ? "forced" : void 0,
50
+ children: effective ?? "real"
51
+ })]
52
+ }), /* @__PURE__ */ jsx("fieldset", {
53
+ className: "design-segments",
54
+ "aria-label": `${boundary.id} state`,
55
+ children: CHOICES.map((choice) => /* @__PURE__ */ jsx("button", {
56
+ type: "button",
57
+ className: "design-segment",
58
+ "aria-pressed": override === choice,
59
+ onClick: () => store.force(boundary.id, choice),
60
+ children: choice ?? "auto"
61
+ }, choice ?? "auto"))
62
+ })]
63
+ }, boundary.id);
64
+ })]
65
+ }),
66
+ /* @__PURE__ */ jsxs("section", {
67
+ className: "design-section",
68
+ "aria-label": "URL param",
69
+ children: [/* @__PURE__ */ jsxs("div", {
70
+ className: "design-row",
71
+ children: [/* @__PURE__ */ jsxs("span", {
72
+ className: "design-grow design-mono",
73
+ children: [
74
+ "?",
75
+ FORCE_STATE_PARAM,
76
+ "="
77
+ ]
78
+ }), /* @__PURE__ */ jsx("span", {
79
+ className: "design-mono",
80
+ children: snapshot.param ? formatForceStateParam(snapshot.param) : "not set"
81
+ })]
82
+ }), /* @__PURE__ */ jsxs("p", {
83
+ className: "design-hint",
84
+ children: [
85
+ "?",
86
+ FORCE_STATE_PARAM,
87
+ "=loading|empty|error forces the top-level boundaries; ?",
88
+ FORCE_STATE_PARAM,
89
+ "=<id>:error targets one. A toggle here wins over the param."
90
+ ]
91
+ })]
92
+ })
93
+ ]
94
+ });
95
+ }
96
+ //#endregion
97
+ export { ForceStatePanel, ForceStatePanel as default };
@@ -0,0 +1,53 @@
1
+ //#region src/auto/generate.ts
2
+ const PACKAGE = "@hansenexus/hud";
3
+ /** Which import each feature adds: `name` from `subpath`. */
4
+ const FEATURE_IMPORTS = {
5
+ configured: null,
6
+ next: ["routes", "plugins/routes"],
7
+ convex: ["inspectConvex", "plugins/inspect/convex"],
8
+ reactQuery: ["inspectReactQuery", "plugins/inspect/react-query"],
9
+ swr: ["inspectSwr", "plugins/inspect/swr"],
10
+ msw: ["data", "plugins/data"],
11
+ betterAuth: ["data", "plugins/data"],
12
+ convexAuth: ["data", "plugins/data"]
13
+ };
14
+ /** The base plugins every auto HUD carries. */
15
+ const BASE_IMPORTS = [
16
+ ["a11y", "plugins/a11y"],
17
+ ["forceState", "plugins/design"],
18
+ ["inspect", "plugins/inspect"],
19
+ ["observe", "plugins/observe"],
20
+ ["seo", "plugins/seo"],
21
+ ["vitals", "plugins/vitals"]
22
+ ];
23
+ /** The factories the generated module hands `assembleAuto`, in import order. */
24
+ function autoImports(detected) {
25
+ const imports = new Map(BASE_IMPORTS);
26
+ for (const [feature, entry] of Object.entries(FEATURE_IMPORTS)) if (entry && detected[feature]) imports.set(entry[0], entry[1]);
27
+ return imports;
28
+ }
29
+ /**
30
+ * The generated module. `source` names where detection read from, for the
31
+ * header comment. Exports match the stand-in in `src/auto/index.ts`
32
+ * (`detected`, `auto`, default), so the types in `dist/auto.d.ts` apply.
33
+ */
34
+ function generateAutoModule(detected, source = "package.json") {
35
+ const imports = [...autoImports(detected)].sort(([, a], [, b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, subpath]) => `import { ${name} } from "${PACKAGE}/${subpath}";`);
36
+ const factories = [...autoImports(detected).keys()].sort().join(", ");
37
+ return [
38
+ `// Generated by ${PACKAGE} from ${source}. Do not edit: it is rewritten on every start.`,
39
+ `import { assembleAuto } from "${PACKAGE}/auto/runtime";`,
40
+ ...imports,
41
+ "",
42
+ `export const detected = Object.freeze(${JSON.stringify(detected)});`,
43
+ "",
44
+ "export function auto(options) {",
45
+ ` return assembleAuto(detected, { ${factories} }, options);`,
46
+ "}",
47
+ "",
48
+ "export default auto;",
49
+ ""
50
+ ].join("\n");
51
+ }
52
+ //#endregion
53
+ export { generateAutoModule as t };
@@ -0,0 +1,106 @@
1
+ import { a as resolvePlugins, t as HUD_HTTP_METHODS } from "./plugins-DVy_vaYr.js";
2
+ //#region src/server/handler.ts
3
+ function json(status, body, headers) {
4
+ const res = Response.json(body, { status });
5
+ if (headers) for (const [key, value] of new Headers(headers)) res.headers.set(key, value);
6
+ return res;
7
+ }
8
+ function notFound() {
9
+ return json(404, {
10
+ ok: false,
11
+ error: "not found"
12
+ });
13
+ }
14
+ /**
15
+ * The default guard. Core assumes development, so a deployed build that
16
+ * mounts the route without an `access` guard serves nothing and reveals
17
+ * nothing about which plugins exist.
18
+ */
19
+ const developmentOnly = () => {
20
+ return (typeof process === "undefined" ? void 0 : process.env.NODE_ENV) === "development" ? null : notFound();
21
+ };
22
+ function splitPath(path) {
23
+ return path.split("/").filter(Boolean);
24
+ }
25
+ function compile(plugin) {
26
+ return Object.entries(plugin.routes ?? {}).map(([path, methods]) => ({
27
+ segments: splitPath(path),
28
+ methods
29
+ }));
30
+ }
31
+ function match(route, segments) {
32
+ if (route.segments.length !== segments.length) return null;
33
+ const params = {};
34
+ for (const [i, pattern] of route.segments.entries()) {
35
+ const segment = segments[i] ?? "";
36
+ if (!pattern.startsWith(":")) {
37
+ if (pattern !== segment) return null;
38
+ continue;
39
+ }
40
+ try {
41
+ params[pattern.slice(1)] = decodeURIComponent(segment);
42
+ } catch {
43
+ return null;
44
+ }
45
+ }
46
+ return params;
47
+ }
48
+ function isMethod(method) {
49
+ return HUD_HTTP_METHODS.includes(method);
50
+ }
51
+ /**
52
+ * Serves every plugin's routes from one catch-all route
53
+ * (`app/api/hud/[...hud]/route.ts` in Next). A request to
54
+ * `<basePath>/<plugin id>/<path>` reaches that plugin's `routes[path][method]`;
55
+ * unknown plugin or path answers 404, a known path with another method 405.
56
+ *
57
+ * Pass the server halves (`@hansenexus/hud/plugins/<id>/server`): they carry
58
+ * `routes` and no React.
59
+ */
60
+ function createHudHandler(plugins, options = {}) {
61
+ const basePath = splitPath(options.basePath ?? "/api/hud");
62
+ const guard = options.guard ?? developmentOnly;
63
+ const table = new Map(resolvePlugins(plugins, options.can ?? (() => true)).map((plugin) => [plugin.id, {
64
+ plugin,
65
+ routes: compile(plugin)
66
+ }]));
67
+ const handle = async (request) => {
68
+ const segments = splitPath(new URL(request.url).pathname);
69
+ if (!basePath.every((segment, i) => segments[i] === segment)) return notFound();
70
+ const [pluginId, ...rest] = segments.slice(basePath.length);
71
+ const entry = pluginId === void 0 ? void 0 : table.get(pluginId);
72
+ const refusal = await guard(request, entry?.plugin.capability);
73
+ if (refusal) return refusal;
74
+ if (!entry) return notFound();
75
+ for (const route of entry.routes) {
76
+ const params = match(route, rest);
77
+ if (!params) continue;
78
+ const method = request.method === "HEAD" ? "GET" : request.method;
79
+ const fn = isMethod(method) ? route.methods[method] : void 0;
80
+ if (!fn) return json(405, {
81
+ ok: false,
82
+ error: "method not allowed"
83
+ }, { allow: HUD_HTTP_METHODS.filter((m) => route.methods[m]).join(", ") });
84
+ try {
85
+ return await fn(request, { params });
86
+ } catch (error) {
87
+ console.error(`hud: ${entry.plugin.id} ${request.method} /${rest.join("/")} failed`, error);
88
+ return json(500, {
89
+ ok: false,
90
+ error: "plugin route failed"
91
+ });
92
+ }
93
+ }
94
+ return notFound();
95
+ };
96
+ return {
97
+ handle,
98
+ GET: handle,
99
+ POST: handle,
100
+ PUT: handle,
101
+ PATCH: handle,
102
+ DELETE: handle
103
+ };
104
+ }
105
+ //#endregion
106
+ export { developmentOnly as n, createHudHandler as t };
@@ -1,4 +1,4 @@
1
- import { a as HudHttpMethod, o as HudPlugin, r as HudCapability } from "./plugins-CQ_0w1ot.js";
1
+ import { a as HudHttpMethod, o as HudPlugin, r as HudCapability } from "./plugins-BZvDqGx5.js";
2
2
  //#region src/server/handler.d.ts
3
3
  /**
4
4
  * Decides whether a request may reach a plugin route. Return a `Response` to
@@ -0,0 +1,43 @@
1
+ import { c as HudPluginProps } from "./plugins-BZvDqGx5.js";
2
+ import { a as CaptureOptions } from "./requests-CJrUf465.js";
3
+ //#region src/plugins/observe/info-tab.d.ts
4
+ /** The signed-in user as the app knows it. Every field is optional. */
5
+ interface HudUserInfo {
6
+ name?: string;
7
+ email?: string;
8
+ id?: string;
9
+ role?: string;
10
+ /** App-specific extras (organization, tier, locale ...). */
11
+ extra?: Record<string, string>;
12
+ }
13
+ //#endregion
14
+ //#region src/plugins/observe/index.d.ts
15
+ interface ObserveOptions extends CaptureOptions {
16
+ /**
17
+ * Values for the Info tab, read at the app's import site so Next can inline
18
+ * them: `{ NODE_ENV: process.env.NODE_ENV, CONVEX_URL: process.env.NEXT_PUBLIC_CONVEX_URL }`.
19
+ * `undefined` shows as "not set".
20
+ */
21
+ env?: Readonly<Record<string, string | undefined>>;
22
+ /** A hook returning the signed-in user, called inside the Info tab. */
23
+ useUser?: () => HudUserInfo | null | undefined;
24
+ }
25
+ /**
26
+ * Console and network capture, an app/build/browser/user snapshot and the
27
+ * page's Web Vitals. The pill counts errors; opening the panel while there are
28
+ * any lands on the console filtered to them.
29
+ */
30
+ declare function observe({ env, useUser, ignore }?: ObserveOptions): {
31
+ readonly id: "observe";
32
+ readonly title: "Observe";
33
+ readonly pill: () => import("react").JSX.Element;
34
+ readonly pillPriority: 20;
35
+ readonly panel: ({ ctx }: HudPluginProps) => import("react").JSX.Element;
36
+ readonly commands: readonly [{
37
+ readonly id: "clear";
38
+ readonly title: "Clear console capture";
39
+ readonly run: () => void;
40
+ }];
41
+ };
42
+ //#endregion
43
+ export { observe as n, HudUserInfo as r, ObserveOptions as t };
@@ -0,0 +1,70 @@
1
+ import { n as Preview, t as InspectAdapter } from "./adapter-BYoxPYTI.js";
2
+ //#region src/plugins/inspect/convex/store.d.ts
3
+ interface ConvexQueryEntry {
4
+ id: number;
5
+ /** `messages:list` */
6
+ name: string;
7
+ /** Name plus serialised args; one entry per distinct subscription. */
8
+ key: string;
9
+ args: Preview;
10
+ subscribedAt: number;
11
+ /** Time from the first subscription to the first result; 0 when it was cached. */
12
+ firstResultMs?: number;
13
+ /** Results received after the first. */
14
+ updates: number;
15
+ updatedAt?: number;
16
+ /** Live `onUpdate` callbacks; 0 once everything unsubscribed. */
17
+ subscribers: number;
18
+ value?: Preview;
19
+ error?: string;
20
+ }
21
+ type ConvexCallKind = "mutation" | "action" | "query";
22
+ interface ConvexCall {
23
+ id: number;
24
+ ts: number;
25
+ kind: ConvexCallKind;
26
+ name: string;
27
+ args: Preview;
28
+ status: "pending" | "ok" | "error";
29
+ durationMs?: number;
30
+ result?: Preview;
31
+ error?: string;
32
+ }
33
+ interface ConvexSnapshot {
34
+ queries: readonly ConvexQueryEntry[];
35
+ calls: readonly ConvexCall[];
36
+ }
37
+ //#endregion
38
+ //#region src/plugins/inspect/convex/index.d.ts
39
+ interface WatchLike {
40
+ onUpdate(callback: () => void): () => void;
41
+ localQueryResult(): unknown;
42
+ }
43
+ /**
44
+ * The surface the adapter wraps, structurally: `ConvexReactClient`
45
+ * (`watchQuery`, behind `useQuery`/`useQueries`/`usePaginatedQuery`),
46
+ * `ConvexClient` (`onUpdate`) and `ConvexHttpClient` (`query`) all fit.
47
+ * Method syntax keeps the generic signatures assignable.
48
+ */
49
+ interface ConvexClientLike {
50
+ watchQuery?(query: any, ...argsAndOptions: any[]): WatchLike;
51
+ onUpdate?(query: any, args: any, callback: (result: any) => unknown, onError?: (error: Error) => unknown): any;
52
+ mutation?(mutation: any, ...args: any[]): Promise<any>;
53
+ action?(action: any, ...args: any[]): Promise<any>;
54
+ query?(query: any, ...args: any[]): Promise<any>;
55
+ }
56
+ interface InspectConvexOptions {
57
+ /** The app's client; its query, mutation and action methods are wrapped in place. */
58
+ client: ConvexClientLike;
59
+ }
60
+ /**
61
+ * Convex tab for the inspect plugin: every live query with its latency to
62
+ * the first result, update count and subscriber count, and every mutation,
63
+ * action and one-shot query with its duration and result. Args and results
64
+ * are redacted like request bodies. Wraps the client's methods when called,
65
+ * so subscriptions made before the HUD mounts are seen; `dispose()` restores
66
+ * the client.
67
+ */
68
+ declare function inspectConvex({ client }: InspectConvexOptions): InspectAdapter;
69
+ //#endregion
70
+ export { ConvexQueryEntry as a, ConvexCall as i, InspectConvexOptions as n, ConvexSnapshot as o, inspectConvex as r, ConvexClientLike as t };
@@ -0,0 +1,19 @@
1
+ import { c as HudPluginProps } from "./plugins-BZvDqGx5.js";
2
+ //#region src/plugins/routes/routes-panel.d.ts
3
+ declare function RoutesPanel({ ctx }: HudPluginProps): import("react").JSX.Element;
4
+ //#endregion
5
+ //#region src/plugins/routes/index.d.ts
6
+ /**
7
+ * Route index: every page of the app's `app/` tree, dynamic segments filled
8
+ * from the fixtures the server half knows, one click away. Client half; the
9
+ * scanner lives in `@hansenexus/hud/plugins/routes/server`, which also feeds
10
+ * the `hud sweep` CLI.
11
+ */
12
+ declare function routes(): {
13
+ readonly id: "routes";
14
+ readonly title: "Routes";
15
+ readonly capability: "routes.read";
16
+ readonly panel: typeof RoutesPanel;
17
+ };
18
+ //#endregion
19
+ export { routes as t };