@hansenexus/hud 0.3.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 (172) hide show
  1. package/README.md +782 -6
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/access-C7zlaqj6.js +100 -0
  5. package/dist/access-D_ewAEJG.d.ts +61 -0
  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-CApnbI0r.d.ts +19 -0
  26. package/dist/env-CaiFPIhF.js +31 -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-BaqWsmrf.js +153 -0
  32. package/dist/force-state-CCqoTfVB.d.ts +23 -0
  33. package/dist/force-state-panel-_otVYh9i.js +97 -0
  34. package/dist/generate-C8lQl3Eh.js +53 -0
  35. package/dist/handler-BpVhxEmU.js +106 -0
  36. package/dist/handler-DtYVCZY6.d.ts +39 -0
  37. package/dist/index-BAV_1W8a.d.ts +43 -0
  38. package/dist/index-BJ26pse9.d.ts +70 -0
  39. package/dist/index-BnQ0dTZf.d.ts +19 -0
  40. package/dist/index-CwfX-W87.d.ts +72 -0
  41. package/dist/index-DcH9V3cU.d.ts +48 -0
  42. package/dist/index-DqOyNf1u.d.ts +65 -0
  43. package/dist/index-DstI_ike.d.ts +66 -0
  44. package/dist/index-Dxz4fn4j.d.ts +42 -0
  45. package/dist/index-Hhh7OXzU.d.ts +129 -0
  46. package/dist/index-ReFbhQ9p.d.ts +25 -0
  47. package/dist/index-RgXfMBuW.d.ts +48 -0
  48. package/dist/index-gCZBO53s.d.ts +73 -0
  49. package/dist/index.d.ts +6 -36
  50. package/dist/index.js +798 -240
  51. package/dist/inspect-C9Ft8fqn.js +142 -0
  52. package/dist/inspect-root-BkaupBMp.js +429 -0
  53. package/dist/marker-C66LxOhJ.d.ts +9 -0
  54. package/dist/marker-CMrvxPmS.d.ts +12 -0
  55. package/dist/marker-DjeGvL-F.js +9 -0
  56. package/dist/marker-uZYPOJ4M.js +12 -0
  57. package/dist/markers.d.ts +3 -0
  58. package/dist/markers.js +3 -0
  59. package/dist/meta-Bv0sEao3.js +6 -0
  60. package/dist/meta-C_G7MB5w.d.ts +49 -0
  61. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  62. package/dist/mocks-ESiRqk9o.js +150 -0
  63. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  64. package/dist/next/config.d.ts +52 -0
  65. package/dist/next/config.js +78 -0
  66. package/dist/next.d.ts +14 -19
  67. package/dist/next.js +7 -30
  68. package/dist/observe-CdDnDBRP.js +89 -0
  69. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  70. package/dist/ops-panel-CEqDe_UT.js +234 -0
  71. package/dist/payload-MUQ9ciER.d.ts +92 -0
  72. package/dist/plugins/a11y.d.ts +2 -0
  73. package/dist/plugins/a11y.js +2 -0
  74. package/dist/plugins/access/server.d.ts +122 -0
  75. package/dist/plugins/access/server.js +340 -0
  76. package/dist/plugins/access.d.ts +41 -0
  77. package/dist/plugins/access.js +51 -0
  78. package/dist/plugins/agent/server.d.ts +94 -0
  79. package/dist/plugins/agent/server.js +455 -0
  80. package/dist/plugins/agent.d.ts +37 -0
  81. package/dist/plugins/agent.js +69 -0
  82. package/dist/plugins/capture/server.d.ts +92 -0
  83. package/dist/plugins/capture/server.js +248 -0
  84. package/dist/plugins/capture.d.ts +24 -0
  85. package/dist/plugins/capture.js +70 -0
  86. package/dist/plugins/data/msw-browser.d.ts +2 -0
  87. package/dist/plugins/data/msw-browser.js +39 -0
  88. package/dist/plugins/data/msw-node.d.ts +36 -0
  89. package/dist/plugins/data/msw-node.js +68 -0
  90. package/dist/plugins/data/server.d.ts +257 -0
  91. package/dist/plugins/data/server.js +717 -0
  92. package/dist/plugins/data.d.ts +6 -0
  93. package/dist/plugins/data.js +51 -0
  94. package/dist/plugins/design/server.d.ts +54 -0
  95. package/dist/plugins/design/server.js +198 -0
  96. package/dist/plugins/design.d.ts +5 -0
  97. package/dist/plugins/design.js +4 -0
  98. package/dist/plugins/inspect/convex.d.ts +2 -0
  99. package/dist/plugins/inspect/convex.js +486 -0
  100. package/dist/plugins/inspect/react-query.d.ts +2 -0
  101. package/dist/plugins/inspect/react-query.js +225 -0
  102. package/dist/plugins/inspect/sockets.d.ts +51 -0
  103. package/dist/plugins/inspect/sockets.js +397 -0
  104. package/dist/plugins/inspect/swr.d.ts +2 -0
  105. package/dist/plugins/inspect/swr.js +218 -0
  106. package/dist/plugins/inspect.d.ts +4 -0
  107. package/dist/plugins/inspect.js +3 -0
  108. package/dist/plugins/observe.d.ts +4 -0
  109. package/dist/plugins/observe.js +2 -0
  110. package/dist/plugins/ops/server.d.ts +82 -0
  111. package/dist/plugins/ops/server.js +381 -0
  112. package/dist/plugins/ops.d.ts +27 -0
  113. package/dist/plugins/ops.js +41 -0
  114. package/dist/plugins/routes/server.d.ts +88 -0
  115. package/dist/plugins/routes/server.js +62 -0
  116. package/dist/plugins/routes.d.ts +3 -0
  117. package/dist/plugins/routes.js +216 -0
  118. package/dist/plugins/seo.d.ts +2 -0
  119. package/dist/plugins/seo.js +2 -0
  120. package/dist/plugins/vitals.d.ts +2 -25
  121. package/dist/plugins/vitals.js +4 -86
  122. package/dist/plugins-BZvDqGx5.d.ts +144 -0
  123. package/dist/{plugins-CzUiTn_r.js → plugins-DVy_vaYr.js} +3 -1
  124. package/dist/poll-CjKsWZi8.js +89 -0
  125. package/dist/requests-BwD6MKEq.js +282 -0
  126. package/dist/requests-CJrUf465.d.ts +50 -0
  127. package/dist/review.d.ts +181 -0
  128. package/dist/review.js +1017 -0
  129. package/dist/same-origin-BGet22CC.js +21 -0
  130. package/dist/scan-DzJNXqOk.js +165 -0
  131. package/dist/selector-NSYSe7AZ.js +28 -0
  132. package/dist/seo-Dq9q_QkO.js +551 -0
  133. package/dist/seo-panel-CfiY-TnT.js +124 -0
  134. package/dist/server.d.ts +3 -39
  135. package/dist/server.js +2 -105
  136. package/dist/sessions-panel-COvhPAzv.js +98 -0
  137. package/dist/shortcut-s_mjGeU8.js +179 -0
  138. package/dist/state-CjjZPjPJ.js +40 -0
  139. package/dist/state-boundary.d.ts +26 -0
  140. package/dist/state-boundary.js +61 -0
  141. package/dist/store/convex.d.ts +33 -0
  142. package/dist/store/convex.js +52 -0
  143. package/dist/store-CQqIIKTc.js +59 -0
  144. package/dist/store-Ync9eb1G.js +67 -0
  145. package/dist/store.d.ts +76 -0
  146. package/dist/store.js +188 -0
  147. package/dist/styles-BA8ueHoV.js +342 -0
  148. package/dist/styles-DKU_P8MH.js +139 -0
  149. package/dist/styles-DPpDPmzi.js +68 -0
  150. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  151. package/dist/types-B-ulf2Jp.js +8 -0
  152. package/dist/types-BIgGf-0C.d.ts +25 -0
  153. package/dist/types-BIkI-qN8.js +30 -0
  154. package/dist/types-Cxh4twqc.d.ts +50 -0
  155. package/dist/types-DIdPfjtV.js +6 -0
  156. package/dist/types-DaJcsEjO.d.ts +44 -0
  157. package/dist/types-Dn68psVz.d.ts +118 -0
  158. package/dist/types-f3jlNxzw.d.ts +92 -0
  159. package/dist/types-szkr2QOF.d.ts +39 -0
  160. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  161. package/dist/variant-groups-TIfO3NIj.js +137 -0
  162. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  163. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  164. package/dist/variants-types-CcRf119M.d.ts +63 -0
  165. package/dist/variants.d.ts +43 -0
  166. package/dist/variants.js +83 -0
  167. package/dist/vitals-panel-BCmMUntW.js +30 -0
  168. package/dist/vite.d.ts +37 -0
  169. package/dist/vite.js +134 -0
  170. package/package.json +85 -5
  171. package/dist/define-hud-BHQR8Lbv.d.ts +0 -31
  172. package/dist/plugins-1QmTmZyL.d.ts +0 -76
@@ -0,0 +1,216 @@
1
+ import { i as definePlugin, n as HudApiError } from "../plugins-DVy_vaYr.js";
2
+ import { n as ROUTES_ID, t as ROUTES_CAPABILITY } from "../meta-Bv0sEao3.js";
3
+ import { useCallback, useEffect, useState } from "react";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/plugins/routes/styles.ts
6
+ /** Panel styles, rendered as a `<style>` inside the panel, so inside the shadow root. */
7
+ const ROUTES_CSS = `
8
+ .routes { display: grid; gap: 10px; min-width: 260px; }
9
+ .routes .head { display: flex; align-items: center; gap: 6px; }
10
+ .routes .head input {
11
+ flex: 1;
12
+ min-width: 0;
13
+ font: inherit;
14
+ color: inherit;
15
+ padding: 3px 8px;
16
+ background: var(--hud-bg);
17
+ border: 1px solid var(--hud-border);
18
+ border-radius: 6px;
19
+ }
20
+ .routes .head .count { color: var(--hud-fg-muted); font-family: var(--hud-mono); white-space: nowrap; }
21
+ .routes button.chip { padding: 1px 6px; border-radius: 999px; font-family: var(--hud-mono); }
22
+ .routes button.chip:hover { background: var(--hud-bg-subtle); }
23
+ .routes section { display: grid; gap: 2px; }
24
+ .routes h3 {
25
+ margin: 0 0 2px;
26
+ font-size: 10px;
27
+ font-weight: 600;
28
+ letter-spacing: 0.06em;
29
+ text-transform: uppercase;
30
+ color: var(--hud-fg-muted);
31
+ }
32
+ .routes ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
33
+ .routes li a, .routes li > span {
34
+ display: grid;
35
+ grid-template-columns: minmax(0, 1fr) auto;
36
+ align-items: center;
37
+ gap: 8px;
38
+ padding: 3px 6px;
39
+ border-radius: 4px;
40
+ font-family: var(--hud-mono);
41
+ color: inherit;
42
+ text-decoration: none;
43
+ overflow: hidden;
44
+ text-overflow: ellipsis;
45
+ white-space: nowrap;
46
+ }
47
+ .routes li a:hover { background: var(--hud-bg-subtle); }
48
+ .routes li a[aria-current="page"] { color: var(--hud-accent); font-weight: 600; }
49
+ .routes li > span { color: var(--hud-fg-muted); }
50
+ .routes li small { color: var(--hud-fg-muted); font-family: var(--hud-font); }
51
+ .routes .warn { color: var(--hud-warn); margin: 0; }
52
+ .routes .muted { color: var(--hud-fg-muted); margin: 0; }
53
+ `;
54
+ //#endregion
55
+ //#region src/plugins/routes/routes-panel.tsx
56
+ /** A readable message for a failed request; the route's own 500 bodies carry one. */
57
+ function describeError(error) {
58
+ if (error instanceof HudApiError) {
59
+ if (error.status === 404) return "route not mounted: add routes() to createHudHandler";
60
+ const body = error.body;
61
+ if (typeof body?.error === "string") return body.error;
62
+ return `HTTP ${error.status}`;
63
+ }
64
+ return error instanceof Error ? error.message : "request failed";
65
+ }
66
+ /** Loads the route list once per panel mount; `refresh` scans again. */
67
+ function useRoutes(ctx) {
68
+ const [state, setState] = useState({ loading: true });
69
+ const load = useCallback(() => {
70
+ let live = true;
71
+ setState((prev) => ({
72
+ ...prev,
73
+ loading: true
74
+ }));
75
+ ctx.api("/routes").then((data) => live && setState({
76
+ data,
77
+ loading: false
78
+ }), (error) => live && setState((prev) => ({
79
+ ...prev,
80
+ error: describeError(error),
81
+ loading: false
82
+ })));
83
+ return () => {
84
+ live = false;
85
+ };
86
+ }, [ctx]);
87
+ useEffect(load, [load]);
88
+ const refresh = useCallback(() => void load(), [load]);
89
+ return {
90
+ ...state,
91
+ refresh
92
+ };
93
+ }
94
+ function groupLabel(group) {
95
+ return group ?? "root";
96
+ }
97
+ /**
98
+ * Routes whose path or pattern contains the query, case-insensitive. A query
99
+ * that only matches some of a route's URLs narrows the route to those.
100
+ */
101
+ function filterRoutes(routes, query) {
102
+ const q = query.trim().toLowerCase();
103
+ if (!q) return [...routes];
104
+ return routes.flatMap((route) => {
105
+ if (route.path.toLowerCase().includes(q) || route.pattern.toLowerCase().includes(q)) return [route];
106
+ const urls = route.urls.filter(({ url }) => url.toLowerCase().includes(q));
107
+ return urls.length > 0 ? [{
108
+ ...route,
109
+ urls
110
+ }] : [];
111
+ });
112
+ }
113
+ function currentPath() {
114
+ return typeof location === "undefined" ? void 0 : location.pathname;
115
+ }
116
+ function RouteRow({ route, here }) {
117
+ if (route.unresolved.length > 0) return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("span", {
118
+ title: `${route.pattern}: no fixture for ${route.unresolved.join(", ")}`,
119
+ children: [route.path, /* @__PURE__ */ jsxs("small", { children: ["no fixture: ", route.unresolved.join(", ")] })]
120
+ }) });
121
+ return /* @__PURE__ */ jsx(Fragment, { children: route.urls.map(({ url, params }) => {
122
+ const values = Object.values(params).filter(Boolean);
123
+ return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("a", {
124
+ href: url,
125
+ title: route.pattern,
126
+ "aria-current": url === here ? "page" : void 0,
127
+ children: [url, values.length > 0 && /* @__PURE__ */ jsx("small", { children: route.path })]
128
+ }) }, url);
129
+ }) });
130
+ }
131
+ function RoutesPanel({ ctx }) {
132
+ const { data, error, loading, refresh } = useRoutes(ctx);
133
+ const [query, setQuery] = useState("");
134
+ const here = currentPath();
135
+ const routes = data ? filterRoutes(data.routes, query) : [];
136
+ const groups = [...new Set(routes.map((route) => groupLabel(route.group)))].sort();
137
+ const urlCount = data ? data.routes.reduce((n, route) => n + route.urls.length, 0) : 0;
138
+ return /* @__PURE__ */ jsxs("div", {
139
+ className: "routes",
140
+ children: [
141
+ /* @__PURE__ */ jsx("style", { children: ROUTES_CSS }),
142
+ /* @__PURE__ */ jsxs("div", {
143
+ className: "head",
144
+ children: [
145
+ /* @__PURE__ */ jsx("input", {
146
+ type: "search",
147
+ value: query,
148
+ onChange: (e) => setQuery(e.target.value),
149
+ placeholder: "Filter routes…",
150
+ "aria-label": "Filter routes"
151
+ }),
152
+ data && /* @__PURE__ */ jsxs("span", {
153
+ className: "count",
154
+ title: `${data.routes.length} routes in ${data.dir}`,
155
+ children: [
156
+ routes.length,
157
+ "/",
158
+ data.routes.length,
159
+ " · ",
160
+ urlCount,
161
+ " urls"
162
+ ]
163
+ }),
164
+ /* @__PURE__ */ jsx("button", {
165
+ type: "button",
166
+ className: "chip",
167
+ onClick: refresh,
168
+ title: "Scan the app directory again",
169
+ children: "rescan"
170
+ })
171
+ ]
172
+ }),
173
+ loading && !data && /* @__PURE__ */ jsx("p", {
174
+ className: "muted",
175
+ children: "Scanning…"
176
+ }),
177
+ error && /* @__PURE__ */ jsx("p", {
178
+ className: "warn",
179
+ children: error
180
+ }),
181
+ data && data.routes.length === 0 && /* @__PURE__ */ jsxs("p", {
182
+ className: "muted",
183
+ children: [
184
+ "No pages under ",
185
+ data.dir,
186
+ "."
187
+ ]
188
+ }),
189
+ groups.map((group) => /* @__PURE__ */ jsxs("section", {
190
+ "aria-label": group,
191
+ children: [/* @__PURE__ */ jsx("h3", { children: group }), /* @__PURE__ */ jsx("ul", { children: routes.filter((route) => groupLabel(route.group) === group).map((route) => /* @__PURE__ */ jsx(RouteRow, {
192
+ route,
193
+ here
194
+ }, route.pattern)) })]
195
+ }, group))
196
+ ]
197
+ });
198
+ }
199
+ //#endregion
200
+ //#region src/plugins/routes/index.tsx
201
+ /**
202
+ * Route index: every page of the app's `app/` tree, dynamic segments filled
203
+ * from the fixtures the server half knows, one click away. Client half; the
204
+ * scanner lives in `@hansenexus/hud/plugins/routes/server`, which also feeds
205
+ * the `hud sweep` CLI.
206
+ */
207
+ function routes() {
208
+ return definePlugin({
209
+ id: ROUTES_ID,
210
+ title: "Routes",
211
+ capability: ROUTES_CAPABILITY,
212
+ panel: RoutesPanel
213
+ });
214
+ }
215
+ //#endregion
216
+ export { ROUTES_CAPABILITY, ROUTES_ID, routes };
@@ -0,0 +1,2 @@
1
+ import { a as SeoLevel, i as SeoGroup, n as SeoSnapshot, o as runSeoChecks, r as SeoCheck, t as seo } from "../index-DcH9V3cU.js";
2
+ export { type SeoCheck, type SeoGroup, type SeoLevel, type SeoSnapshot, runSeoChecks, seo };
@@ -0,0 +1,2 @@
1
+ import { a as runSeoChecks, t as seo } from "../seo-Dq9q_QkO.js";
2
+ export { runSeoChecks, seo };
@@ -1,25 +1,2 @@
1
- import { Metric } from "web-vitals";
2
- //#region src/plugins/vitals/vitals-panel.d.ts
3
- declare function VitalsPanel(): import("react").JSX.Element;
4
- //#endregion
5
- //#region src/plugins/vitals/store.d.ts
6
- type VitalName = Metric["name"];
7
- type VitalRating = Metric["rating"];
8
- interface Vital {
9
- name: VitalName;
10
- value: number;
11
- rating: VitalRating;
12
- }
13
- type VitalsSnapshot = Partial<Record<VitalName, Vital>>;
14
- //#endregion
15
- //#region src/plugins/vitals/index.d.ts
16
- declare function VitalsPill(): import("react").JSX.Element;
17
- /** Core Web Vitals: LCP in the pill, all five metrics in the panel. Client only. */
18
- export declare function vitals(): {
19
- readonly id: "vitals";
20
- readonly title: "Vitals";
21
- readonly pill: typeof VitalsPill;
22
- readonly panel: typeof VitalsPanel;
23
- };
24
- //#endregion
25
- export type { Vital, VitalName, VitalRating, VitalsSnapshot };
1
+ import { a as VitalsSnapshot, i as VitalRating, n as Vital, r as VitalName, t as vitals } from "../index-ReFbhQ9p.js";
2
+ export { type Vital, type VitalName, type VitalRating, type VitalsSnapshot, vitals };
@@ -1,91 +1,9 @@
1
- import { i as definePlugin } from "../plugins-CzUiTn_r.js";
2
- import { useEffect, useSyncExternalStore } from "react";
1
+ import { i as definePlugin } from "../plugins-DVy_vaYr.js";
2
+ import { i as useVitals, n as formatVital, r as startVitals } from "../store-CQqIIKTc.js";
3
+ import { lazy, useEffect } from "react";
3
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
- import { onCLS, onFCP, onINP, onLCP, onTTFB } from "web-vitals";
5
- //#region src/plugins/vitals/store.ts
6
- /** Display order: the three Core Web Vitals first, then the diagnostics. */
7
- const VITAL_ORDER = [
8
- "LCP",
9
- "INP",
10
- "CLS",
11
- "FCP",
12
- "TTFB"
13
- ];
14
- let snapshot = {};
15
- const listeners = /* @__PURE__ */ new Set();
16
- let started = false;
17
- function record(metric) {
18
- snapshot = {
19
- ...snapshot,
20
- [metric.name]: {
21
- name: metric.name,
22
- value: metric.value,
23
- rating: metric.rating
24
- }
25
- };
26
- for (const listener of listeners) listener();
27
- }
28
- /**
29
- * Starts collection once per page. Called when the HUD mounts, not when the
30
- * panel opens: LCP and FCP are only reported for the initial load, so a lazy
31
- * start would miss them.
32
- */
33
- function startVitals() {
34
- if (started) return;
35
- started = true;
36
- const opts = { reportAllChanges: true };
37
- try {
38
- onLCP(record, opts);
39
- onINP(record, opts);
40
- onCLS(record, opts);
41
- onFCP(record, opts);
42
- onTTFB(record, opts);
43
- } catch {}
44
- }
45
- function getVitals() {
46
- return snapshot;
47
- }
48
- function subscribeVitals(listener) {
49
- listeners.add(listener);
50
- return () => listeners.delete(listener);
51
- }
52
- function useVitals() {
53
- return useSyncExternalStore(subscribeVitals, getVitals, getVitals);
54
- }
55
- function formatVital(name, value) {
56
- if (name === "CLS") return value.toFixed(2);
57
- if (value >= 1e3) return `${(value / 1e3).toFixed(1)} s`;
58
- return `${Math.round(value)} ms`;
59
- }
60
- //#endregion
61
- //#region src/plugins/vitals/vitals-panel.tsx
62
- function VitalsPanel() {
63
- const vitals = useVitals();
64
- const rows = VITAL_ORDER.flatMap((name) => {
65
- const vital = vitals[name];
66
- return vital ? [vital] : [];
67
- });
68
- if (rows.length === 0) return /* @__PURE__ */ jsx("p", {
69
- className: "empty",
70
- children: "No metrics yet. LCP reports after the first interaction or tab switch."
71
- });
72
- return /* @__PURE__ */ jsx("table", {
73
- className: "vitals",
74
- children: /* @__PURE__ */ jsx("tbody", { children: rows.map((vital) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("td", {
75
- className: "label",
76
- children: vital.name
77
- }), /* @__PURE__ */ jsxs("td", { children: [/* @__PURE__ */ jsx("span", {
78
- className: "dot",
79
- "data-rating": vital.rating,
80
- style: {
81
- display: "inline-block",
82
- marginRight: 6
83
- }
84
- }), formatVital(vital.name, vital.value)] })] }, vital.name)) })
85
- });
86
- }
87
- //#endregion
88
5
  //#region src/plugins/vitals/index.tsx
6
+ const VitalsPanel = lazy(() => import("../vitals-panel-BCmMUntW.js"));
89
7
  function VitalsPill() {
90
8
  useEffect(() => {
91
9
  startVitals();
@@ -0,0 +1,144 @@
1
+ import { r as GrabPayload } from "./payload-MUQ9ciER.js";
2
+ import { ComponentType } from "react";
3
+ //#region src/core/grabber/store.d.ts
4
+ /** An element a plugin asked the shell to outline, with the label shown beside it. */
5
+ interface HudHighlight {
6
+ element: Element;
7
+ label: string;
8
+ }
9
+ interface HudGrabState {
10
+ /** The picker is active: the next click on the page completes the grab. */
11
+ grabbing: boolean;
12
+ /** The last completed grab, until a plugin clears it. */
13
+ payload: GrabPayload | null;
14
+ /** The element the grabber overlay currently outlines on a plugin's behalf. */
15
+ highlight: HudHighlight | null;
16
+ }
17
+ /** Grab mode for one HUD, shared by the shell and every plugin's `ctx.grab`. */
18
+ interface HudGrab {
19
+ start: () => void;
20
+ cancel: () => void;
21
+ /** Forgets the last payload, e.g. once it has been dispatched. */
22
+ clear: () => void;
23
+ /**
24
+ * Merges `patch` into the last payload (no-op without one). For plugins that
25
+ * enrich a grab after the fact, such as `capture` attaching a screenshot;
26
+ * compare `grabbedAt` first so a late result never lands on a newer grab.
27
+ */
28
+ amend: (patch: Partial<GrabPayload>) => void;
29
+ /**
30
+ * Outlines `element` with the grabber overlay and scrolls it into view, until
31
+ * `clearHighlight`, Escape, a click on the page or the next grab.
32
+ */
33
+ highlight: (element: Element, label?: string) => void;
34
+ clearHighlight: () => void;
35
+ getState: () => HudGrabState;
36
+ subscribe: (listener: () => void) => () => void;
37
+ }
38
+ /** Subscribes a component to a HUD's grab state: `useGrab(ctx.grab)`. */
39
+ declare function useGrab(grab: HudGrab): HudGrabState;
40
+ //#endregion
41
+ //#region src/core/plugins.d.ts
42
+ /**
43
+ * A capability a plugin needs, such as `"cicd.read"`. Core assumes development
44
+ * and grants everything; the `access` plugin brings a matrix for deployed tiers.
45
+ */
46
+ type HudCapability = string;
47
+ type PinEdge = "left" | "right" | "bottom";
48
+ /** What a plugin's panel and pill receive from the shell. */
49
+ interface HudPluginContext {
50
+ /** App slug from `defineHud({ app })`. */
51
+ app: string;
52
+ /** Whether the current tier grants `capability`. */
53
+ can: (capability: HudCapability) => boolean;
54
+ /**
55
+ * Fetches JSON from this plugin's server routes: `api("/runs")` requests
56
+ * `<apiBase>/<plugin id>/runs`. Rejects with `HudApiError` on a non-2xx status.
57
+ */
58
+ api: <T = unknown>(path: string, init?: RequestInit) => Promise<T>;
59
+ /** Pins this plugin's panel to an edge. Below 768 px the pin is kept but not applied. */
60
+ pin: (edge: PinEdge) => void;
61
+ /** Closes this plugin's panel. */
62
+ close: () => void;
63
+ /** Opens this plugin's panel. */
64
+ open: () => void;
65
+ /** The HUD's element grabber: start a grab, read or clear the last payload. See `useGrab`. */
66
+ grab: HudGrab;
67
+ }
68
+ interface HudPluginProps {
69
+ ctx: HudPluginContext;
70
+ }
71
+ interface HudCommand {
72
+ /** Unique within the plugin. */
73
+ id: string;
74
+ title: string;
75
+ /** Shortcut in `mod+shift+k` form; `mod` is ⌘ on macOS and Ctrl elsewhere. */
76
+ shortcut?: string;
77
+ run: (ctx: HudPluginContext) => void;
78
+ }
79
+ type HudHttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
80
+ interface HudRouteContext {
81
+ /** Values of `:name` segments in the matched path. */
82
+ params: Record<string, string>;
83
+ }
84
+ type HudRouteHandler = (request: Request, ctx: HudRouteContext) => Response | Promise<Response>;
85
+ /**
86
+ * Server routes keyed by path below the plugin's prefix, then by method:
87
+ * `{ "/runs/:id": { GET } }` serves `GET <apiBase>/<plugin id>/runs/42`.
88
+ */
89
+ type HudRoutes = Record<string, Partial<Record<HudHttpMethod, HudRouteHandler>>>;
90
+ /**
91
+ * The plugin contract. A plugin ships as two subpath exports that share this
92
+ * type: `@hansenexus/hud/plugins/<id>` carries the client half (`panel`,
93
+ * `pill`, `commands`) and `@hansenexus/hud/plugins/<id>/server` the server half
94
+ * (`routes`), so route code never reaches a client bundle and React never
95
+ * reaches the route handler. Both halves carry the same `id` and `capability`.
96
+ */
97
+ interface HudPlugin {
98
+ /** Unique per HUD; also the URL segment of the plugin's routes. */
99
+ id: string;
100
+ /** Panel title and pill label when the plugin has no `pill`. Defaults to `id`. */
101
+ title?: string;
102
+ /** Without it the plugin is dropped, client and server side. */
103
+ capability?: HudCapability;
104
+ /**
105
+ * Floating panel content, opened from the plugin's pill item. Make it a
106
+ * dynamic import, `lazy(() => import("./panel"))`, so its code loads on
107
+ * first open and stays out of the eager HUD bundle; the shell renders the
108
+ * loading state and contains a panel that fails.
109
+ */
110
+ panel?: ComponentType<HudPluginProps>;
111
+ /** Live content inside the plugin's pill item. Keep it inline and non-interactive. */
112
+ pill?: ComponentType<HudPluginProps>;
113
+ /**
114
+ * When the pill runs out of room, items with a higher priority stay visible
115
+ * longest; the rest move into the pill menu. Above 0 the item also survives
116
+ * compact mode. Default 0.
117
+ */
118
+ pillPriority?: number;
119
+ commands?: readonly HudCommand[];
120
+ /** Called when a grab (⌘⇧G or the pill's crosshair) completes. */
121
+ onGrab?: (payload: GrabPayload, ctx: HudPluginContext) => void;
122
+ routes?: HudRoutes;
123
+ /** Opens deployed tiers (the `access` plugin). Without one the HUD renders only in development. */
124
+ access?: HudAccessControl;
125
+ }
126
+ /**
127
+ * What the `access` plugin hands `defineHud`. `env` is the loader's tier
128
+ * (`development`, `preview`, `staging`, `production`, `disabled`).
129
+ */
130
+ interface HudAccessControl {
131
+ /** Capability check for the tier; outside development it narrows `can`. */
132
+ can: (env: string, capability: HudCapability) => boolean;
133
+ /** Hook: whether the operator has unlocked this tier. Until then only the access plugin shows. */
134
+ useUnlocked: (env: string, apiBase: string) => boolean;
135
+ }
136
+ /** Identity helper that types a plugin object without widening it. */
137
+ declare function definePlugin<const P extends HudPlugin>(plugin: P): P;
138
+ declare class HudApiError extends Error {
139
+ readonly status: number;
140
+ readonly body: unknown;
141
+ constructor(status: number, body: unknown, url: string);
142
+ }
143
+ //#endregion
144
+ export { useGrab as _, HudHttpMethod as a, HudPluginProps as c, HudRoutes as d, PinEdge as f, HudHighlight as g, HudGrabState as h, HudCommand as i, HudRouteContext as l, HudGrab as m, HudApiError as n, HudPlugin as o, definePlugin as p, HudCapability as r, HudPluginContext as s, HudAccessControl as t, HudRouteHandler as u };
@@ -34,13 +34,15 @@ var HudApiError = class extends Error {
34
34
  this.name = "HudApiError";
35
35
  }
36
36
  };
37
- function createPluginContext(plugin, { app, apiBase, can, pin, close }) {
37
+ function createPluginContext(plugin, { app, apiBase, can, pin, close, open, grab }) {
38
38
  const prefix = `${apiBase.replace(/\/+$/, "")}/${plugin.id}`;
39
39
  return {
40
40
  app,
41
41
  can,
42
42
  pin,
43
43
  close,
44
+ open,
45
+ grab,
44
46
  api: async (path, init) => {
45
47
  const url = `${prefix}/${path.replace(/^\/+/, "")}`;
46
48
  const headers = new Headers(init?.headers);
@@ -0,0 +1,89 @@
1
+ import { n as HudApiError } from "./plugins-DVy_vaYr.js";
2
+ import { useCallback, useSyncExternalStore } from "react";
3
+ //#region src/plugins/ops/poll.ts
4
+ /** Entries per plugin context, so the pill and the panel share one poller per path. */
5
+ const entries = /* @__PURE__ */ new WeakMap();
6
+ function entryFor(ctx, path) {
7
+ let byPath = entries.get(ctx);
8
+ if (!byPath) {
9
+ byPath = /* @__PURE__ */ new Map();
10
+ entries.set(ctx, byPath);
11
+ }
12
+ let entry = byPath.get(path);
13
+ if (!entry) {
14
+ entry = {
15
+ state: { loading: true },
16
+ listeners: /* @__PURE__ */ new Set(),
17
+ inflight: false
18
+ };
19
+ byPath.set(path, entry);
20
+ }
21
+ return entry;
22
+ }
23
+ /** A readable message for a failed poll; 502 bodies carry the provider's own. */
24
+ function describeError(error) {
25
+ if (error instanceof HudApiError) {
26
+ if (error.status === 404) return "route not mounted: add ops() to createHudHandler";
27
+ const body = error.body;
28
+ if (typeof body?.error === "string") return body.error;
29
+ return `HTTP ${error.status}`;
30
+ }
31
+ return error instanceof Error ? error.message : "request failed";
32
+ }
33
+ function set(entry, state) {
34
+ entry.state = state;
35
+ for (const listener of entry.listeners) listener();
36
+ }
37
+ async function tick(ctx, path, entry, force = false) {
38
+ if (entry.inflight || !force && typeof document !== "undefined" && document.hidden) return;
39
+ entry.inflight = true;
40
+ try {
41
+ set(entry, {
42
+ data: await ctx.api(path),
43
+ loading: false
44
+ });
45
+ } catch (error) {
46
+ set(entry, {
47
+ ...entry.state,
48
+ error: describeError(error),
49
+ loading: false
50
+ });
51
+ } finally {
52
+ entry.inflight = false;
53
+ }
54
+ }
55
+ /**
56
+ * Polls one of the plugin's routes while anything renders it. Pauses while
57
+ * the tab is hidden; subscribers of the same path share one request.
58
+ */
59
+ function usePoll(ctx, path, intervalMs) {
60
+ const entry = entryFor(ctx, path);
61
+ const subscribe = useCallback((listener) => {
62
+ entry.listeners.add(listener);
63
+ if (entry.listeners.size === 1) {
64
+ tick(ctx, path, entry);
65
+ entry.timer = setInterval(() => void tick(ctx, path, entry), intervalMs);
66
+ }
67
+ return () => {
68
+ entry.listeners.delete(listener);
69
+ if (entry.listeners.size === 0) clearInterval(entry.timer);
70
+ };
71
+ }, [
72
+ ctx,
73
+ path,
74
+ entry,
75
+ intervalMs
76
+ ]);
77
+ const state = useSyncExternalStore(subscribe, () => entry.state, () => entry.state);
78
+ const refresh = useCallback(() => void tick(ctx, path, entry, true), [
79
+ ctx,
80
+ path,
81
+ entry
82
+ ]);
83
+ return {
84
+ ...state,
85
+ refresh
86
+ };
87
+ }
88
+ //#endregion
89
+ export { usePoll as t };