@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,164 @@
1
+ import { n as HudApiError } from "./plugins-DVy_vaYr.js";
2
+ import { FLAGS_STORAGE_KEY, serializeFlagOverrides } from "./flags.js";
3
+ import { d as validateScenarios, i as createMockResolver } from "./mocks-ESiRqk9o.js";
4
+ import { useEffect, useSyncExternalStore } from "react";
5
+ //#region src/plugins/data/mocks-client.ts
6
+ const UNCONFIGURED_HINT = "Client fetches are not mocked: pass mocks: { scenarios, worker } to data().";
7
+ const NO_WORKER_HINT = "Client fetches are not mocked: install msw, run \"npx msw init public/\" and pass worker: () => import(\"@hansenexus/hud/plugins/data/msw-browser\") to data({ mocks }).";
8
+ let options;
9
+ let active = {};
10
+ let status = {
11
+ status: "unconfigured",
12
+ hint: UNCONFIGURED_HINT
13
+ };
14
+ let handle = null;
15
+ let starting = null;
16
+ const listeners$1 = /* @__PURE__ */ new Set();
17
+ function setStatus(next) {
18
+ status = next;
19
+ for (const listener of listeners$1) listener();
20
+ }
21
+ function subscribe$1(listener) {
22
+ listeners$1.add(listener);
23
+ return () => listeners$1.delete(listener);
24
+ }
25
+ const getStatus = () => status;
26
+ /** Called by `data()`; the scenarios are validated here so a typo fails at HUD definition. */
27
+ function configureMockClient(next) {
28
+ options = next;
29
+ if (next) validateScenarios(next.scenarios);
30
+ setStatus(next === void 0 ? {
31
+ status: "unconfigured",
32
+ hint: UNCONFIGURED_HINT
33
+ } : next.worker ? { status: "off" } : {
34
+ status: "off",
35
+ hint: NO_WORKER_HINT
36
+ });
37
+ }
38
+ /** The active set as the server last reported it; the resolver reads it on every request. */
39
+ function activeMocks() {
40
+ return active;
41
+ }
42
+ /**
43
+ * Takes the server's active set and, the first time, starts the worker when
44
+ * a loader is configured: the worker runs for the page's lifetime so a later
45
+ * toggle applies to the next fetch without another start.
46
+ */
47
+ function syncMockActive(next) {
48
+ active = next;
49
+ if (!options?.worker || handle || starting) return;
50
+ const { worker, scenarios, workerOptions } = options;
51
+ const resolve = createMockResolver(validateScenarios(scenarios), activeMocks);
52
+ setStatus({ status: "starting" });
53
+ starting = worker().then((module) => module.startMockWorker(resolve, workerOptions)).then((started) => {
54
+ handle = started;
55
+ setStatus({ status: "live" });
56
+ }, (error) => {
57
+ setStatus({
58
+ status: "failed",
59
+ hint: `Client fetches are not mocked: ${error instanceof Error ? error.message : String(error)}`
60
+ });
61
+ }).finally(() => {
62
+ starting = null;
63
+ });
64
+ }
65
+ function useMockClientStatus() {
66
+ return useSyncExternalStore(subscribe$1, getStatus, getStatus);
67
+ }
68
+ //#endregion
69
+ //#region src/plugins/data/data-store.ts
70
+ let state = { status: "loading" };
71
+ const listeners = /* @__PURE__ */ new Set();
72
+ let inflight = null;
73
+ function set(next) {
74
+ state = next;
75
+ for (const listener of listeners) listener();
76
+ }
77
+ function subscribe(listener) {
78
+ listeners.add(listener);
79
+ return () => listeners.delete(listener);
80
+ }
81
+ const getState = () => state;
82
+ function errorMessage(error, fallback) {
83
+ if (error instanceof HudApiError) {
84
+ const body = error.body;
85
+ if (body && typeof body === "object" && "error" in body && typeof body.error === "string") return body.error;
86
+ return `${fallback} (${error.status})`;
87
+ }
88
+ return error instanceof Error ? error.message : fallback;
89
+ }
90
+ /**
91
+ * `local`-scoped overrides live in `localStorage`, which only the browser can
92
+ * write: every response that carries overrides is mirrored there, so the app
93
+ * reads the store's truth through `readFlagOverrides({ storage: localStorage })`.
94
+ */
95
+ function syncLocalOverrides(overrides) {
96
+ try {
97
+ const document = serializeFlagOverrides(overrides, "local");
98
+ if (document === "{}") localStorage.removeItem(FLAGS_STORAGE_KEY);
99
+ else localStorage.setItem(FLAGS_STORAGE_KEY, document);
100
+ } catch {}
101
+ }
102
+ /** Loads (or reloads) the state; concurrent calls share one request. */
103
+ function loadDataState(ctx) {
104
+ if (inflight) return inflight;
105
+ inflight = ctx.api("/").then((data) => {
106
+ if (data.flags) syncLocalOverrides(data.flags.overrides);
107
+ if (data.mocks) syncMockActive(data.mocks.active);
108
+ set({
109
+ status: "ready",
110
+ data
111
+ });
112
+ }, (error) => {
113
+ if (error instanceof HudApiError && (error.status === 404 || error.status === 403)) set({
114
+ status: "unavailable",
115
+ code: error.status
116
+ });
117
+ else set({
118
+ status: "failed",
119
+ error: errorMessage(error, "loading failed")
120
+ });
121
+ }).finally(() => {
122
+ inflight = null;
123
+ });
124
+ return inflight;
125
+ }
126
+ /** Replaces the overrides in a ready state after a write, without a reload. */
127
+ function applyOverrides(overrides) {
128
+ if (state.status !== "ready" || !state.data.flags) return;
129
+ syncLocalOverrides(overrides);
130
+ set({
131
+ status: "ready",
132
+ data: {
133
+ ...state.data,
134
+ flags: {
135
+ ...state.data.flags,
136
+ overrides
137
+ }
138
+ }
139
+ });
140
+ }
141
+ /** Replaces the active scenarios in a ready state after a write; the browser's resolver sees them at once. */
142
+ function applyMocks(active) {
143
+ if (state.status !== "ready" || !state.data.mocks) return;
144
+ syncMockActive(active);
145
+ set({
146
+ status: "ready",
147
+ data: {
148
+ ...state.data,
149
+ mocks: {
150
+ ...state.data.mocks,
151
+ active
152
+ }
153
+ }
154
+ });
155
+ }
156
+ function useDataState(ctx) {
157
+ const current = useSyncExternalStore(subscribe, getState, getState);
158
+ useEffect(() => {
159
+ if (state.status === "loading") loadDataState(ctx);
160
+ }, [ctx]);
161
+ return current;
162
+ }
163
+ //#endregion
164
+ export { useDataState as a, syncLocalOverrides as i, applyOverrides as n, configureMockClient as o, errorMessage as r, useMockClientStatus as s, applyMocks as t };
@@ -0,0 +1,50 @@
1
+ import { o as HudPlugin, r as HudCapability } from "./plugins-BZvDqGx5.js";
2
+ import { ComponentType } from "react";
3
+ //#region src/core/define-hud.d.ts
4
+ /** `auto` from `@hansenexus/hud/auto`: the list, or the function itself. */
5
+ type HudAutoPlugins = readonly HudPlugin[] | (() => readonly HudPlugin[]);
6
+ interface DefineHudOptions {
7
+ /** App slug: labels the pill and keys the persisted layout. */
8
+ app: string;
9
+ /**
10
+ * Client halves (`@hansenexus/hud/plugins/<id>`), in pill order. With
11
+ * `auto`, a plugin here replaces the detected one with the same id, in
12
+ * place; the rest are appended. One of `plugins` and `auto` is required.
13
+ */
14
+ plugins?: readonly HudPlugin[];
15
+ /**
16
+ * Plugins picked from the app's dependencies: `auto` from
17
+ * `@hansenexus/hud/auto`, as is or called with the instances the detected
18
+ * adapters wrap (`auto({ convex: client })`). Needs `hud()` in vite.config
19
+ * or `withHud()` around next.config; without them the stand-in module
20
+ * supplies the base plugins and warns.
21
+ */
22
+ auto?: HudAutoPlugins;
23
+ /** Base path of the catch-all route serving `createHudHandler`. Default "/api/hud". */
24
+ apiBase?: string;
25
+ /** Capability check. Default: grant all (core assumes development). */
26
+ can?: (capability: HudCapability) => boolean;
27
+ }
28
+ /** Props the loader passes in at mount time. */
29
+ interface HudMountProps {
30
+ /** Badge at the start of the pill. Default "DEV". */
31
+ envLabel?: string;
32
+ /**
33
+ * Tier the loader resolved. Default "development". Any other tier renders
34
+ * nothing unless a plugin brings `access`.
35
+ */
36
+ env?: string;
37
+ }
38
+ /**
39
+ * The app's one HUD file:
40
+ *
41
+ * ```tsx
42
+ * export default defineHud({ app: "hansenexus", plugins: [vitals()] });
43
+ * ```
44
+ *
45
+ * Returns a component. The plugin list is frozen here, so the shell sees a
46
+ * stable array across renders.
47
+ */
48
+ declare function defineHud({ app, plugins, auto, apiBase, can }: DefineHudOptions): ComponentType<HudMountProps>;
49
+ //#endregion
50
+ export { defineHud as i, HudAutoPlugins as n, HudMountProps as r, DefineHudOptions as t };
@@ -0,0 +1,87 @@
1
+ import { i as definePlugin } from "./plugins-DVy_vaYr.js";
2
+ import { a as getForceStateSnapshot, c as subscribeForceState, o as getForceStateStore, s as resolveForcedState } from "./force-state-BaqWsmrf.js";
3
+ import { lazy, useSyncExternalStore } from "react";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/plugins/design/use-force-state.ts
6
+ function useForceState() {
7
+ return useSyncExternalStore(subscribeForceState, getForceStateSnapshot, getForceStateSnapshot);
8
+ }
9
+ //#endregion
10
+ //#region src/plugins/design/force-state-pill.tsx
11
+ /**
12
+ * Pill content: how many boundaries are forced, by toggle or param. Uses the
13
+ * core `.dot`, since the plugin stylesheet only loads with the panel.
14
+ */
15
+ function ForceStatePill() {
16
+ const snapshot = useForceState();
17
+ const forced = snapshot.boundaries.filter((b) => resolveForcedState(snapshot, b)).length;
18
+ if (forced === 0) return /* @__PURE__ */ jsx(Fragment, { children: "States" });
19
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
20
+ /* @__PURE__ */ jsx("span", {
21
+ className: "dot",
22
+ "data-rating": "needs-improvement"
23
+ }),
24
+ "States ",
25
+ forced
26
+ ] });
27
+ }
28
+ //#endregion
29
+ //#region src/plugins/design/index.tsx
30
+ const TokensPanel = lazy(() => import("./tokens-panel-CbMQfasZ.js"));
31
+ const VariantsPanel = lazy(() => import("./variants-panel-BDoSkwBJ.js"));
32
+ const ForceStatePanel = lazy(() => import("./force-state-panel-_otVYh9i.js"));
33
+ /**
34
+ * Live swatches of the host app's design tokens. Values are read from the
35
+ * host document, outside the HUD's shadow root, so scoped and themed tokens
36
+ * show what the page actually renders. Client only.
37
+ */
38
+ function tokens(adapter) {
39
+ function Panel() {
40
+ return /* @__PURE__ */ jsx(TokensPanel, { adapter });
41
+ }
42
+ return definePlugin({
43
+ id: "tokens",
44
+ title: "Tokens",
45
+ panel: Panel
46
+ });
47
+ }
48
+ /**
49
+ * The page's live variant groups (`VariantGroup` from `@hansenexus/hud/variants`)
50
+ * with a switcher, agent scores from the storage seam and Decide, which
51
+ * needs `variants.decide` and `variantsServer()` from
52
+ * `@hansenexus/hud/plugins/design/server`. An adapter adds the app's own
53
+ * variant registry and the generate-brief queue (`variants.generate`). Client only.
54
+ */
55
+ function variants(adapter) {
56
+ function Panel({ ctx }) {
57
+ return /* @__PURE__ */ jsx(VariantsPanel, {
58
+ adapter,
59
+ ctx
60
+ });
61
+ }
62
+ return definePlugin({
63
+ id: "variants",
64
+ title: "Variants",
65
+ panel: Panel
66
+ });
67
+ }
68
+ /**
69
+ * Forces the page's `StateBoundary`s (`@hansenexus/hud/state-boundary`) to
70
+ * loading, empty or error. The pill shows how many are forced. Client only.
71
+ */
72
+ function forceState() {
73
+ return definePlugin({
74
+ id: "states",
75
+ title: "States",
76
+ capability: "state.force",
77
+ pill: ForceStatePill,
78
+ panel: ForceStatePanel,
79
+ commands: [{
80
+ id: "reset",
81
+ title: "Reset forced states",
82
+ run: () => getForceStateStore().clearOverrides()
83
+ }]
84
+ });
85
+ }
86
+ //#endregion
87
+ export { useForceState as i, tokens as n, variants as r, forceState as t };
@@ -0,0 +1,25 @@
1
+ //#region src/auto/detect.d.ts
2
+ /** What the bundler plugin found in the app's package.json. */
3
+ interface HudAutoDetected {
4
+ /**
5
+ * False in the stand-in module the package ships: no bundler plugin read the
6
+ * app's package.json, so only the base plugins are on.
7
+ */
8
+ configured: boolean;
9
+ /** `next`: the routes plugin (route index, `hud sweep`). */
10
+ next: boolean;
11
+ /** `convex`: the Convex tab of the inspect plugin. */
12
+ convex: boolean;
13
+ /** `@tanstack/react-query`: the Query tab. */
14
+ reactQuery: boolean;
15
+ /** `swr`: the SWR tab. */
16
+ swr: boolean;
17
+ /** `msw`: the data plugin (mock scenarios). */
18
+ msw: boolean;
19
+ /** `better-auth`: the data plugin (role switch). */
20
+ betterAuth: boolean;
21
+ /** `@convex-dev/auth`: the data plugin (role switch). */
22
+ convexAuth: boolean;
23
+ }
24
+ //#endregion
25
+ export { HudAutoDetected as t };
@@ -0,0 +1,63 @@
1
+ //#region src/auto/detect.ts
2
+ /** Which package turns on which feature. */
3
+ const AUTO_RULES = {
4
+ next: "next",
5
+ convex: "convex",
6
+ reactQuery: "@tanstack/react-query",
7
+ swr: "swr",
8
+ msw: "msw",
9
+ betterAuth: "better-auth",
10
+ convexAuth: "@convex-dev/auth"
11
+ };
12
+ const AUTO_FEATURES = Object.keys(AUTO_RULES);
13
+ /** The stand-in: nothing detected, nothing configured. */
14
+ const NOTHING_DETECTED = Object.freeze({
15
+ configured: false,
16
+ next: false,
17
+ convex: false,
18
+ reactQuery: false,
19
+ swr: false,
20
+ msw: false,
21
+ betterAuth: false,
22
+ convexAuth: false
23
+ });
24
+ const SECTIONS = [
25
+ "dependencies",
26
+ "devDependencies",
27
+ "peerDependencies",
28
+ "optionalDependencies"
29
+ ];
30
+ /** Every package the manifest names, whatever the section. */
31
+ function listDependencies(pkg) {
32
+ const names = /* @__PURE__ */ new Set();
33
+ for (const section of SECTIONS) {
34
+ const entries = pkg[section];
35
+ if (typeof entries !== "object" || entries === null) continue;
36
+ for (const name of Object.keys(entries)) names.add(name);
37
+ }
38
+ return names;
39
+ }
40
+ /**
41
+ * Detection from a parsed package.json: a feature is on when its package is
42
+ * listed in any dependency section (dev dependencies count: `msw` lives there).
43
+ */
44
+ function detectHudAuto(pkg) {
45
+ const names = listDependencies(pkg);
46
+ const detected = {
47
+ ...NOTHING_DETECTED,
48
+ configured: true
49
+ };
50
+ for (const feature of AUTO_FEATURES) detected[feature] = names.has(AUTO_RULES[feature]);
51
+ return Object.freeze(detected);
52
+ }
53
+ /** Parses package.json text; a broken file detects nothing rather than crashing the dev server. */
54
+ function parsePackageJson(text) {
55
+ try {
56
+ const parsed = JSON.parse(text);
57
+ return typeof parsed === "object" && parsed !== null ? parsed : {};
58
+ } catch {
59
+ return {};
60
+ }
61
+ }
62
+ //#endregion
63
+ export { detectHudAuto as n, parsePackageJson as r, NOTHING_DETECTED as t };
@@ -0,0 +1,279 @@
1
+ import { n as useGrab } from "./store-Ync9eb1G.js";
2
+ import { n as HudApiError } from "./plugins-DVy_vaYr.js";
3
+ import { i as parseShortcut, n as isApplePlatform, s as matchComponentHints, t as formatShortcut } from "./shortcut-s_mjGeU8.js";
4
+ import { t as AGENT_CSS } from "./styles-DPpDPmzi.js";
5
+ import { useEffect, useState, useSyncExternalStore } from "react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ //#region src/plugins/agent/dispatch-panel.tsx
8
+ /** How long a dispatch waits for a screenshot still rendering. */
9
+ const SCREENSHOT_WAIT_MS = 3e4;
10
+ /**
11
+ * The payload to send: the current one once its screenshot (if the `capture`
12
+ * plugin is attaching one) is no longer pending, or the grab was cleared, or
13
+ * the wait ran out. A newer grab replaces it.
14
+ */
15
+ function settledPayload(grab, waitMs = SCREENSHOT_WAIT_MS) {
16
+ const pending = (payload) => payload?.screenshot?.status === "pending";
17
+ const current = grab.getState().payload;
18
+ if (!pending(current)) return Promise.resolve(current);
19
+ return new Promise((resolve) => {
20
+ const finish = () => {
21
+ unsubscribe();
22
+ clearTimeout(timer);
23
+ resolve(grab.getState().payload);
24
+ };
25
+ const unsubscribe = grab.subscribe(() => {
26
+ if (!pending(grab.getState().payload)) finish();
27
+ });
28
+ const timer = setTimeout(finish, waitMs);
29
+ });
30
+ }
31
+ function ScreenshotPreview({ screenshot }) {
32
+ if (screenshot.status === "pending") return /* @__PURE__ */ jsx("span", {
33
+ className: "agent-muted agent-shot",
34
+ "data-screenshot": "pending",
35
+ children: "Screenshot: rendering…"
36
+ });
37
+ if (screenshot.status === "unavailable") return /* @__PURE__ */ jsxs("span", {
38
+ className: "agent-shot",
39
+ "data-screenshot": "unavailable",
40
+ children: [/* @__PURE__ */ jsxs("span", {
41
+ className: "agent-muted",
42
+ children: ["No screenshot: ", screenshot.reason]
43
+ }), screenshot.hint && /* @__PURE__ */ jsx("code", {
44
+ className: "agent-mono agent-hint",
45
+ children: screenshot.hint
46
+ })]
47
+ });
48
+ return /* @__PURE__ */ jsxs("span", {
49
+ className: "agent-shot",
50
+ "data-screenshot": "ready",
51
+ children: [/* @__PURE__ */ jsx("img", {
52
+ className: "agent-thumb",
53
+ alt: `Screenshot, ${screenshot.width}×${screenshot.height}`,
54
+ src: `data:${screenshot.mime};base64,${screenshot.base64}`
55
+ }), /* @__PURE__ */ jsxs("span", {
56
+ className: "agent-muted",
57
+ children: [
58
+ screenshot.width,
59
+ "×",
60
+ screenshot.height,
61
+ " ·",
62
+ " ",
63
+ screenshot.scope === "element" ? "element" : "viewport (element not found)"
64
+ ]
65
+ })]
66
+ });
67
+ }
68
+ function errorText(error) {
69
+ if (error instanceof HudApiError) return error.body?.error ?? `HTTP ${error.status}`;
70
+ return error instanceof Error ? error.message : String(error);
71
+ }
72
+ /** The payload as text, the PNG's base64 replaced by its size. */
73
+ function payloadPreview(payload, hints) {
74
+ const shot = payload.screenshot;
75
+ if (shot?.status !== "ready") return {
76
+ ...payload,
77
+ hints
78
+ };
79
+ return {
80
+ ...payload,
81
+ screenshot: {
82
+ ...shot,
83
+ base64: `<${shot.base64.length} base64 chars>`
84
+ },
85
+ hints
86
+ };
87
+ }
88
+ function DispatchPanel({ ctx, log, componentHints }) {
89
+ const { grabbing, payload } = useGrab(ctx.grab);
90
+ const runs = useSyncExternalStore(log.subscribe, log.get, log.get);
91
+ const [targets, setTargets] = useState(null);
92
+ const [targetsError, setTargetsError] = useState(null);
93
+ const [target, setTarget] = useState(null);
94
+ const [note, setNote] = useState("");
95
+ useEffect(() => {
96
+ let cancelled = false;
97
+ ctx.api("/targets").then((list) => {
98
+ if (cancelled) return;
99
+ setTargets(list);
100
+ setTarget((current) => current ?? list.find((t) => t.available)?.id ?? null);
101
+ }).catch((error) => {
102
+ if (!cancelled) setTargetsError(errorText(error));
103
+ });
104
+ return () => {
105
+ cancelled = true;
106
+ };
107
+ }, [ctx]);
108
+ const hints = payload ? matchComponentHints(componentHints, payload.route, payload.anchor.label) : [];
109
+ const canSend = target !== null && (payload !== null || note.trim() !== "");
110
+ async function send() {
111
+ if (!target || !canSend) return;
112
+ const id = `${Date.now()}`;
113
+ const title = [payload?.anchor.label, note.trim().split("\n")[0]].filter(Boolean).join(" · ");
114
+ log.add({
115
+ id,
116
+ title: title || "dispatch",
117
+ target,
118
+ status: "sending"
119
+ });
120
+ const instruction = note;
121
+ setNote("");
122
+ try {
123
+ const grab = await settledPayload(ctx.grab);
124
+ ctx.grab.clear();
125
+ const body = {
126
+ target,
127
+ note: instruction,
128
+ payload: grab,
129
+ hints
130
+ };
131
+ const receipt = await ctx.api("/dispatch", {
132
+ method: "POST",
133
+ headers: { "content-type": "application/json" },
134
+ body: JSON.stringify(body)
135
+ });
136
+ log.update(id, {
137
+ status: "dispatched",
138
+ detail: [receipt.runId, receipt.detail].filter(Boolean).join(" · ")
139
+ });
140
+ } catch (error) {
141
+ log.update(id, {
142
+ status: "failed",
143
+ detail: errorText(error)
144
+ });
145
+ }
146
+ }
147
+ return /* @__PURE__ */ jsxs("div", {
148
+ className: "agent",
149
+ children: [
150
+ /* @__PURE__ */ jsx("style", { children: AGENT_CSS }),
151
+ payload ? /* @__PURE__ */ jsxs("div", {
152
+ className: "agent-card",
153
+ children: [
154
+ /* @__PURE__ */ jsxs("div", {
155
+ className: "agent-row",
156
+ children: [/* @__PURE__ */ jsxs("strong", {
157
+ className: "agent-grow",
158
+ title: payload.anchor.label,
159
+ children: [payload.component ? `<${payload.component.name}> ` : "", payload.anchor.label]
160
+ }), /* @__PURE__ */ jsx("button", {
161
+ type: "button",
162
+ className: "agent-btn",
163
+ "aria-label": "Discard grab",
164
+ onClick: ctx.grab.clear,
165
+ children: "✕"
166
+ })]
167
+ }),
168
+ payload.component?.source && /* @__PURE__ */ jsx("span", {
169
+ className: "agent-mono agent-muted",
170
+ children: payload.component.source
171
+ }),
172
+ /* @__PURE__ */ jsxs("span", {
173
+ className: "agent-mono agent-muted agent-grow",
174
+ title: payload.anchor.selector,
175
+ children: [
176
+ payload.route,
177
+ " · ",
178
+ payload.anchor.selector || payload.anchor.tag
179
+ ]
180
+ }),
181
+ payload.screenshot && /* @__PURE__ */ jsx(ScreenshotPreview, { screenshot: payload.screenshot }),
182
+ /* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx("summary", {
183
+ className: "agent-muted",
184
+ children: "Payload"
185
+ }), /* @__PURE__ */ jsx("pre", {
186
+ className: "agent-mono",
187
+ children: JSON.stringify(payloadPreview(payload, hints), null, 2)
188
+ })] })
189
+ ]
190
+ }) : /* @__PURE__ */ jsxs("div", {
191
+ className: "agent-row",
192
+ children: [/* @__PURE__ */ jsx("button", {
193
+ type: "button",
194
+ className: "agent-btn",
195
+ "data-primary": "",
196
+ "aria-pressed": grabbing,
197
+ onClick: grabbing ? ctx.grab.cancel : ctx.grab.start,
198
+ children: grabbing ? "Cancel grab" : "⌖ Grab element"
199
+ }), /* @__PURE__ */ jsxs("span", {
200
+ className: "agent-muted",
201
+ children: [
202
+ "or ",
203
+ formatShortcut(parseShortcut("mod+shift+g"), isApplePlatform()),
204
+ ", then click anything on the page"
205
+ ]
206
+ })]
207
+ }),
208
+ /* @__PURE__ */ jsx("textarea", {
209
+ "aria-label": "Instruction",
210
+ placeholder: "Instruction, e.g. the CTA feels heavy, try the ghost variant",
211
+ value: note,
212
+ onChange: (e) => setNote(e.target.value)
213
+ }),
214
+ targetsError && /* @__PURE__ */ jsxs("p", {
215
+ className: "empty",
216
+ children: ["Targets unavailable: ", targetsError]
217
+ }),
218
+ targets && targets.length === 0 && /* @__PURE__ */ jsx("p", {
219
+ className: "empty",
220
+ children: "No dispatch provider configured on the server."
221
+ }),
222
+ targets && targets.length > 0 && /* @__PURE__ */ jsx("fieldset", { children: targets.map((t) => /* @__PURE__ */ jsxs("label", {
223
+ className: "agent-target",
224
+ ...t.available ? {} : { "data-disabled": "" },
225
+ children: [/* @__PURE__ */ jsx("input", {
226
+ type: "radio",
227
+ name: "agent-target",
228
+ checked: target === t.id,
229
+ disabled: !t.available,
230
+ onChange: () => setTarget(t.id)
231
+ }), /* @__PURE__ */ jsxs("span", { children: [
232
+ /* @__PURE__ */ jsx("span", { children: t.label }),
233
+ /* @__PURE__ */ jsx("br", {}),
234
+ /* @__PURE__ */ jsx("span", {
235
+ className: "agent-muted",
236
+ children: t.available ? t.description ?? t.id : t.reason
237
+ })
238
+ ] })]
239
+ }, t.id)) }),
240
+ /* @__PURE__ */ jsx("div", {
241
+ className: "agent-row",
242
+ children: /* @__PURE__ */ jsx("button", {
243
+ type: "button",
244
+ className: "agent-btn",
245
+ "data-primary": "",
246
+ disabled: !canSend,
247
+ onClick: send,
248
+ children: "Dispatch"
249
+ })
250
+ }),
251
+ runs.length > 0 && /* @__PURE__ */ jsx("ul", {
252
+ className: "agent-list",
253
+ "aria-label": "Dispatched runs",
254
+ children: runs.map((run) => /* @__PURE__ */ jsxs("li", {
255
+ className: "agent-row agent-mono",
256
+ children: [
257
+ /* @__PURE__ */ jsx("span", {
258
+ className: "agent-badge",
259
+ "data-status": run.status,
260
+ children: run.status
261
+ }),
262
+ /* @__PURE__ */ jsx("span", {
263
+ className: "agent-grow",
264
+ title: run.title,
265
+ children: run.title
266
+ }),
267
+ /* @__PURE__ */ jsxs("span", {
268
+ className: "agent-muted agent-grow",
269
+ title: run.detail,
270
+ children: [run.target, run.detail ? ` · ${run.detail}` : ""]
271
+ })
272
+ ]
273
+ }, run.id))
274
+ })
275
+ ]
276
+ });
277
+ }
278
+ //#endregion
279
+ export { DispatchPanel, DispatchPanel as default, settledPayload };
@@ -0,0 +1,19 @@
1
+ //#region src/next/env.d.ts
2
+ /**
3
+ * Where the HUD believes it runs. An explicit `NEXT_PUBLIC_HUD_ENV` wins over
4
+ * heuristics because k3s deploys have no `VERCEL_ENV`.
5
+ */
6
+ type HudEnv = "development" | "preview" | "staging" | "production" | "disabled";
7
+ /**
8
+ * Env ladder: kill switch → `NODE_ENV` (inlined by Next, so production
9
+ * bundles fold the development branch) → `NEXT_PUBLIC_HUD_ENV` (k8s overlays)
10
+ * → `VERCEL_ENV` → production.
11
+ *
12
+ * Each read is a literal `process.env.X` so Next can inline it in client code.
13
+ * Where there is no `process` at all (a Vite client) the ladder has nothing to
14
+ * read and answers production; pass the tier to `createHudLoader` instead.
15
+ */
16
+ declare function resolveHudEnv(): HudEnv;
17
+ declare function hudEnvLabel(env?: HudEnv): string;
18
+ //#endregion
19
+ export { hudEnvLabel as n, resolveHudEnv as r, HudEnv as t };