@hansenexus/hud 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +634 -12
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
  5. package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
  6. package/dist/access-panel-CEfTr9ZI.js +123 -0
  7. package/dist/adapter-BYoxPYTI.d.ts +33 -0
  8. package/dist/adapter-hcwmJtNx.js +65 -0
  9. package/dist/auto/runtime.d.ts +65 -0
  10. package/dist/auto/runtime.js +50 -0
  11. package/dist/auto.d.ts +15 -0
  12. package/dist/auto.js +33 -0
  13. package/dist/capabilities-rDSKjXpq.js +110 -0
  14. package/dist/capture-CwrIwLqi.js +300 -0
  15. package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
  16. package/dist/cli.d.ts +1 -0
  17. package/dist/cli.js +275 -0
  18. package/dist/data-panel-DhxAmP91.js +817 -0
  19. package/dist/data-store-ChF1td_P.js +164 -0
  20. package/dist/define-hud-CHPedaQ5.d.ts +50 -0
  21. package/dist/design-D0kGgPoP.js +87 -0
  22. package/dist/detect-BxHZ0pxW.d.ts +25 -0
  23. package/dist/detect-CHZiSeZs.js +63 -0
  24. package/dist/dispatch-panel-B-xr_Giy.js +279 -0
  25. package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
  26. package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
  27. package/dist/file-xdSaQ2uR.js +103 -0
  28. package/dist/flags-DVtaJ8pQ.d.ts +58 -0
  29. package/dist/flags.d.ts +2 -0
  30. package/dist/flags.js +82 -0
  31. package/dist/force-state-panel-_otVYh9i.js +97 -0
  32. package/dist/generate-C8lQl3Eh.js +53 -0
  33. package/dist/handler-BpVhxEmU.js +106 -0
  34. package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
  35. package/dist/index-BAV_1W8a.d.ts +43 -0
  36. package/dist/index-BJ26pse9.d.ts +70 -0
  37. package/dist/index-BnQ0dTZf.d.ts +19 -0
  38. package/dist/index-CwfX-W87.d.ts +72 -0
  39. package/dist/index-DcH9V3cU.d.ts +48 -0
  40. package/dist/index-DqOyNf1u.d.ts +65 -0
  41. package/dist/index-DstI_ike.d.ts +66 -0
  42. package/dist/index-Dxz4fn4j.d.ts +42 -0
  43. package/dist/index-Hhh7OXzU.d.ts +129 -0
  44. package/dist/index-ReFbhQ9p.d.ts +25 -0
  45. package/dist/index-RgXfMBuW.d.ts +48 -0
  46. package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.js +710 -69
  49. package/dist/inspect-C9Ft8fqn.js +142 -0
  50. package/dist/inspect-root-BkaupBMp.js +429 -0
  51. package/dist/meta-Bv0sEao3.js +6 -0
  52. package/dist/meta-C_G7MB5w.d.ts +49 -0
  53. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  54. package/dist/mocks-ESiRqk9o.js +150 -0
  55. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  56. package/dist/next/config.cjs +201 -0
  57. package/dist/next/config.d.cts +87 -0
  58. package/dist/next/config.d.ts +64 -0
  59. package/dist/next/config.js +84 -0
  60. package/dist/next.d.ts +14 -4
  61. package/dist/next.js +5 -3
  62. package/dist/observe-CdDnDBRP.js +89 -0
  63. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  64. package/dist/ops-panel-CEqDe_UT.js +234 -0
  65. package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
  66. package/dist/plugins/a11y.d.ts +2 -0
  67. package/dist/plugins/a11y.js +2 -0
  68. package/dist/plugins/access/server.d.ts +5 -5
  69. package/dist/plugins/access/server.js +4 -3
  70. package/dist/plugins/access.d.ts +5 -5
  71. package/dist/plugins/access.js +16 -215
  72. package/dist/plugins/agent/server.d.ts +3 -38
  73. package/dist/plugins/agent/server.js +47 -21
  74. package/dist/plugins/agent.d.ts +4 -4
  75. package/dist/plugins/agent.js +6 -348
  76. package/dist/plugins/capture/server.d.ts +92 -0
  77. package/dist/plugins/capture/server.js +248 -0
  78. package/dist/plugins/capture.d.ts +24 -0
  79. package/dist/plugins/capture.js +70 -0
  80. package/dist/plugins/data/msw-browser.d.ts +2 -0
  81. package/dist/plugins/data/msw-browser.js +39 -0
  82. package/dist/plugins/data/msw-node.d.ts +36 -0
  83. package/dist/plugins/data/msw-node.js +68 -0
  84. package/dist/plugins/data/server.d.ts +257 -0
  85. package/dist/plugins/data/server.js +717 -0
  86. package/dist/plugins/data.d.ts +6 -0
  87. package/dist/plugins/data.js +51 -0
  88. package/dist/plugins/design/server.d.ts +54 -0
  89. package/dist/plugins/design/server.js +198 -0
  90. package/dist/plugins/design.d.ts +4 -124
  91. package/dist/plugins/design.js +4 -619
  92. package/dist/plugins/inspect/convex.d.ts +2 -0
  93. package/dist/plugins/inspect/convex.js +486 -0
  94. package/dist/plugins/inspect/react-query.d.ts +2 -0
  95. package/dist/plugins/inspect/react-query.js +237 -0
  96. package/dist/plugins/inspect/sockets.d.ts +51 -0
  97. package/dist/plugins/inspect/sockets.js +397 -0
  98. package/dist/plugins/inspect/swr.d.ts +2 -0
  99. package/dist/plugins/inspect/swr.js +218 -0
  100. package/dist/plugins/inspect.d.ts +4 -0
  101. package/dist/plugins/inspect.js +3 -0
  102. package/dist/plugins/observe.d.ts +4 -64
  103. package/dist/plugins/observe.js +1 -616
  104. package/dist/plugins/ops/server.d.ts +1 -1
  105. package/dist/plugins/ops/server.js +2 -1
  106. package/dist/plugins/ops.d.ts +2 -1
  107. package/dist/plugins/ops.js +15 -336
  108. package/dist/plugins/routes/server.d.ts +88 -0
  109. package/dist/plugins/routes/server.js +62 -0
  110. package/dist/plugins/routes.d.ts +3 -0
  111. package/dist/plugins/routes.js +216 -0
  112. package/dist/plugins/seo.d.ts +2 -0
  113. package/dist/plugins/seo.js +2 -0
  114. package/dist/plugins/vitals.d.ts +2 -25
  115. package/dist/plugins/vitals.js +3 -2
  116. package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
  117. package/dist/poll-CjKsWZi8.js +89 -0
  118. package/dist/requests-BwD6MKEq.js +282 -0
  119. package/dist/requests-CJrUf465.d.ts +50 -0
  120. package/dist/review.js +2 -2
  121. package/dist/same-origin-BGet22CC.js +21 -0
  122. package/dist/scan-DzJNXqOk.js +165 -0
  123. package/dist/seo-Dq9q_QkO.js +551 -0
  124. package/dist/seo-panel-CfiY-TnT.js +124 -0
  125. package/dist/server.d.ts +2 -2
  126. package/dist/server.js +2 -105
  127. package/dist/sessions-panel-COvhPAzv.js +98 -0
  128. package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
  129. package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
  130. package/dist/store/convex.d.ts +33 -0
  131. package/dist/store/convex.js +52 -0
  132. package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
  133. package/dist/store-Ync9eb1G.js +67 -0
  134. package/dist/store.d.ts +76 -0
  135. package/dist/store.js +188 -0
  136. package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
  137. package/dist/styles-DKU_P8MH.js +139 -0
  138. package/dist/styles-DPpDPmzi.js +68 -0
  139. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  140. package/dist/types-B-ulf2Jp.js +8 -0
  141. package/dist/types-BIgGf-0C.d.ts +25 -0
  142. package/dist/types-BIkI-qN8.js +30 -0
  143. package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
  144. package/dist/types-DIdPfjtV.js +6 -0
  145. package/dist/types-DaJcsEjO.d.ts +44 -0
  146. package/dist/types-Dn68psVz.d.ts +118 -0
  147. package/dist/types-szkr2QOF.d.ts +39 -0
  148. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  149. package/dist/variant-groups-TIfO3NIj.js +137 -0
  150. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  151. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  152. package/dist/variants-types-CcRf119M.d.ts +63 -0
  153. package/dist/variants.d.ts +43 -0
  154. package/dist/variants.js +83 -0
  155. package/dist/vitals-panel-BCmMUntW.js +30 -0
  156. package/dist/vite.d.ts +37 -0
  157. package/dist/vite.js +134 -0
  158. package/package.json +72 -5
  159. package/dist/define-hud-BBzsSl8b.d.ts +0 -36
@@ -0,0 +1,6 @@
1
+ import { i as HudMockClientStatus, n as data, r as HudMockClientOptions, t as DataOptions } from "../index-DstI_ike.js";
2
+ import { c as HudMockScenarioInfo, i as HudMockNodeStatus, n as HudMockContext, o as HudMockResolve, r as HudMockMethod, s as HudMockScenario, t as HudMockActive } from "../mocks-CA-wM2SB.js";
3
+ import { n as HudMockWorkerModule, r as MockWorkerOptions, t as HudMockWorkerHandle } from "../msw-browser-wjaYgkB7.js";
4
+ import { c as HudFlagValue, h as readFlagOverrides, n as FLAGS_STORAGE_KEY, o as HudFlagOverride, r as FLAG_KEY, s as HudFlagScope, t as FLAGS_COOKIE, u as flagOverride } from "../flags-DVtaJ8pQ.js";
5
+ import { a as FlagsResponse, c as HudFlagDefinition, d as HudSeedInfo, f as MocksResponse, h as SeedRunResponse, i as FlagOverrideBody, l as HudFlagType, m as RoleSwitchResponse, p as RoleSwitchBody, s as HudAuthUserInfo, t as DataStateResponse } from "../types-Dn68psVz.js";
6
+ export { DataOptions, type DataStateResponse, FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, type FlagOverrideBody, type FlagsResponse, type HudAuthUserInfo, type HudFlagDefinition, type HudFlagOverride, type HudFlagScope, type HudFlagType, type HudFlagValue, type HudMockActive, type HudMockClientOptions, type HudMockClientStatus, type HudMockContext, type HudMockMethod, type HudMockNodeStatus, type HudMockResolve, type HudMockScenario, type HudMockScenarioInfo, type HudMockWorkerHandle, type HudMockWorkerModule, type HudSeedInfo, type MockWorkerOptions, type MocksResponse, type RoleSwitchBody, type RoleSwitchResponse, type SeedRunResponse, data, flagOverride, readFlagOverrides };
@@ -0,0 +1,51 @@
1
+ import { i as definePlugin } from "../plugins-DVy_vaYr.js";
2
+ import { FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, flagOverride, readFlagOverrides } from "../flags.js";
3
+ import { a as useDataState, o as configureMockClient } from "../data-store-ChF1td_P.js";
4
+ import { lazy } from "react";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ //#region src/plugins/data/data-pill.tsx
7
+ /** The pill item: who the page is signed in as, how many flags are overridden and how many endpoints are mocked. */
8
+ function DataPill({ ctx }) {
9
+ const state = useDataState(ctx);
10
+ if (state.status !== "ready") return /* @__PURE__ */ jsx(Fragment, { children: "Data" });
11
+ const { auth, flags, mocks } = state.data;
12
+ const overridden = flags?.overrides.length ?? 0;
13
+ const mocked = mocks ? Object.keys(mocks.active).length : 0;
14
+ const who = auth ? auth.current?.label ?? "anonymous" : null;
15
+ const busy = Boolean(auth?.current) || overridden > 0 || mocked > 0;
16
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
17
+ /* @__PURE__ */ jsx("span", {
18
+ className: "dot",
19
+ "data-rating": busy ? "needs-improvement" : "good"
20
+ }),
21
+ who ?? "Data",
22
+ overridden > 0 ? ` · ${overridden} flag${overridden === 1 ? "" : "s"}` : "",
23
+ mocked > 0 ? ` · ${mocked} mock${mocked === 1 ? "" : "s"}` : ""
24
+ ] });
25
+ }
26
+ //#endregion
27
+ //#region src/plugins/data/index.tsx
28
+ const Panel = lazy(() => import("../data-panel-DhxAmP91.js"));
29
+ /**
30
+ * Role switch, feature-flag overrides, seeds and mock scenarios. The pill
31
+ * shows who the page is signed in as, how many flags are overridden and how
32
+ * many endpoints are mocked; the panel picks a fixture user (the page
33
+ * reloads signed in as them, through the auth seam on the server), sets
34
+ * overrides in cookie or localStorage scope, runs the app's seed functions
35
+ * and toggles one scenario per endpoint, persisted through the storage seam
36
+ * until reset. Client half; the server half is `dataServer()` from
37
+ * `@hansenexus/hud/plugins/data/server`. Needs `data.write`, which `access`
38
+ * hard-denies on production.
39
+ */
40
+ function data({ mocks } = {}) {
41
+ configureMockClient(mocks);
42
+ return definePlugin({
43
+ id: "data",
44
+ title: "Data",
45
+ capability: "data.write",
46
+ pill: DataPill,
47
+ panel: Panel
48
+ });
49
+ }
50
+ //#endregion
51
+ export { FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, data, flagOverride, readFlagOverrides };
@@ -0,0 +1,54 @@
1
+ import { l as HudRouteContext } from "../../plugins-BZvDqGx5.js";
2
+ import { a as VariantStatus, c as toVariantRecord, i as VariantRecord, n as DecideResponse, o as VariantsListResponse, r as VARIANTS_COLLECTION, s as recordKey, t as DecideBody } from "../../variants-types-CcRf119M.js";
3
+ import { n as DispatchProvider } from "../../types-szkr2QOF.js";
4
+ import { t as HudStore } from "../../types-DaJcsEjO.js";
5
+ import "../../server.js";
6
+ //#region src/plugins/design/server.d.ts
7
+ export interface VariantDecision {
8
+ group: string;
9
+ label: string;
10
+ winner: {
11
+ id: string;
12
+ label: string;
13
+ };
14
+ losers: {
15
+ id: string;
16
+ label: string;
17
+ }[];
18
+ decidedAt: string;
19
+ }
20
+ export interface VariantsServerOptions {
21
+ /** Where scores and decisions live. `file()` keeps them in `.hud/variants.json`. */
22
+ store: HudStore;
23
+ /**
24
+ * The dispatch seam: Decide queues a cleanup brief here (`claudeCode()`,
25
+ * `hermes()` from `@hansenexus/hud/plugins/agent/server`, or anything with
26
+ * the same shape). Without it a decision is recorded and nothing is queued.
27
+ */
28
+ dispatch?: DispatchProvider;
29
+ /** The brief's text. Default: `cleanupBrief`. */
30
+ brief?: (decision: VariantDecision) => string;
31
+ }
32
+ /** The cleanup brief Decide hands the dispatch seam. */
33
+ export declare function cleanupBrief({ group, label, winner, losers, decidedAt }: VariantDecision): string;
34
+ /**
35
+ * Server half of `variants()`: `GET /` lists every record of the store's
36
+ * `variants` collection, `POST /:group/decide` marks a winner (`decidedAt`,
37
+ * `status: "decided"`; the others `rejected`) through the storage seam and
38
+ * queues a cleanup brief through the dispatch seam. Carries `variants.decide`,
39
+ * which only development grants by default.
40
+ */
41
+ export declare function variantsServer({ store, dispatch, brief }: VariantsServerOptions): {
42
+ readonly id: "variants";
43
+ readonly capability: "variants.decide";
44
+ readonly routes: {
45
+ readonly "/": {
46
+ GET: () => Promise<Response>;
47
+ };
48
+ readonly "/:group/decide": {
49
+ readonly POST: (request: Request, { params }: HudRouteContext) => Promise<Response>;
50
+ };
51
+ };
52
+ };
53
+ //#endregion
54
+ export { type DecideBody, type DecideResponse, VARIANTS_COLLECTION, type VariantRecord, type VariantStatus, type VariantsListResponse, recordKey, toVariantRecord };
@@ -0,0 +1,198 @@
1
+ import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
2
+ import { t as refuseCrossSite } from "../../same-origin-BGet22CC.js";
3
+ import { t as HudStoreError } from "../../types-BIkI-qN8.js";
4
+ //#region src/plugins/design/variants-types.ts
5
+ /** Wire types shared by the Variants panel and `variantsServer()`. */
6
+ /** The store collection scores and decisions live in: `.hud/variants.json` with `file()`. */
7
+ const VARIANTS_COLLECTION = "variants";
8
+ function recordKey(group, id) {
9
+ return `${group}:${id}`;
10
+ }
11
+ function isRecord$1(value) {
12
+ return typeof value === "object" && value !== null && !Array.isArray(value);
13
+ }
14
+ const STATUSES = [
15
+ "open",
16
+ "decided",
17
+ "rejected"
18
+ ];
19
+ /**
20
+ * A store entry as a `VariantRecord`: group and id come from the fields, or
21
+ * from a `<group>:<id>` key when the file omits them. Unknown fields are
22
+ * dropped, wrong types ignored; null when neither names the variant.
23
+ */
24
+ function toVariantRecord(id, value) {
25
+ if (!isRecord$1(value)) return null;
26
+ const separator = id.indexOf(":");
27
+ const group = typeof value.group === "string" ? value.group : separator > 0 ? id.slice(0, separator) : "";
28
+ const variant = typeof value.id === "string" ? value.id : separator > 0 ? id.slice(separator + 1) : "";
29
+ if (!group || !variant) return null;
30
+ const record = {
31
+ group,
32
+ id: variant
33
+ };
34
+ if (typeof value.label === "string") record.label = value.label;
35
+ if (typeof value.status === "string" && STATUSES.includes(value.status)) record.status = value.status;
36
+ if (typeof value.score === "number" && Number.isFinite(value.score)) record.score = value.score;
37
+ if (typeof value.rationale === "string") record.rationale = value.rationale;
38
+ if (typeof value.scoredBy === "string") record.scoredBy = value.scoredBy;
39
+ if (typeof value.decidedAt === "string") record.decidedAt = value.decidedAt;
40
+ return record;
41
+ }
42
+ //#endregion
43
+ //#region src/plugins/design/server.ts
44
+ const NO_STORE = { "cache-control": "no-store" };
45
+ function isRecord(value) {
46
+ return typeof value === "object" && value !== null && !Array.isArray(value);
47
+ }
48
+ function message(error) {
49
+ return error instanceof Error ? error.message : String(error);
50
+ }
51
+ function failed(error, what) {
52
+ if (error instanceof HudStoreError) return Response.json({
53
+ ok: false,
54
+ error: error.message
55
+ }, { status: error.status });
56
+ console.error(`hud variants: ${what} failed`, error);
57
+ return Response.json({
58
+ ok: false,
59
+ error: `${what} failed`
60
+ }, { status: 500 });
61
+ }
62
+ function parseDecide(value) {
63
+ if (!isRecord(value) || typeof value.id !== "string" || !value.id) return null;
64
+ const body = { id: value.id };
65
+ if (typeof value.label === "string") body.label = value.label;
66
+ if (Array.isArray(value.variants)) body.variants = value.variants.flatMap((v) => isRecord(v) && typeof v.id === "string" && v.id ? [{
67
+ id: v.id,
68
+ label: typeof v.label === "string" ? v.label : v.id
69
+ }] : []);
70
+ return body;
71
+ }
72
+ const quote = (v) => v.label === v.id ? `"${v.id}"` : `"${v.id}" (${v.label})`;
73
+ /** The cleanup brief Decide hands the dispatch seam. */
74
+ function cleanupBrief({ group, label, winner, losers, decidedAt }) {
75
+ const name = label === group ? `"${group}"` : `"${group}" (${label})`;
76
+ const remove = losers.length > 0 ? `remove ${losers.map(quote).join(", ")}` : "there are no other variants";
77
+ return [
78
+ `Variant group ${name} was decided on ${decidedAt}: keep ${quote(winner)}, ${remove}.`,
79
+ "",
80
+ `Task: find <VariantGroup id="${group}"> in the app, inline the winning variant's markup where the group renders, delete the losing variants and the VariantGroup wrapper, remove the group's entries from .hud/variants.json, and run the project's checks.`
81
+ ].join("\n");
82
+ }
83
+ async function listRecords(store) {
84
+ return (await store.list(VARIANTS_COLLECTION)).flatMap((entry) => {
85
+ const record = toVariantRecord(entry.id, entry.value);
86
+ return record ? [record] : [];
87
+ });
88
+ }
89
+ /**
90
+ * Server half of `variants()`: `GET /` lists every record of the store's
91
+ * `variants` collection, `POST /:group/decide` marks a winner (`decidedAt`,
92
+ * `status: "decided"`; the others `rejected`) through the storage seam and
93
+ * queues a cleanup brief through the dispatch seam. Carries `variants.decide`,
94
+ * which only development grants by default.
95
+ */
96
+ function variantsServer({ store, dispatch, brief = cleanupBrief }) {
97
+ return definePlugin({
98
+ id: "variants",
99
+ capability: "variants.decide",
100
+ routes: {
101
+ "/": { GET: async () => {
102
+ try {
103
+ const body = {
104
+ ok: true,
105
+ records: await listRecords(store)
106
+ };
107
+ return Response.json(body, { headers: NO_STORE });
108
+ } catch (error) {
109
+ return failed(error, "list");
110
+ }
111
+ } },
112
+ "/:group/decide": { POST: async (request, { params }) => {
113
+ const refusal = refuseCrossSite(request);
114
+ if (refusal) return refusal;
115
+ const group = params.group ?? "";
116
+ const body = parseDecide(await request.json().catch(() => null));
117
+ if (!group || !body) return Response.json({
118
+ ok: false,
119
+ error: "invalid decision"
120
+ }, { status: 400 });
121
+ try {
122
+ const existing = (await listRecords(store)).filter((r) => r.group === group);
123
+ const byId = new Map(existing.map((r) => [r.id, r]));
124
+ const known = /* @__PURE__ */ new Map();
125
+ for (const r of existing) known.set(r.id, r.label ?? r.id);
126
+ for (const v of body.variants ?? []) known.set(v.id, v.label);
127
+ if (!known.has(body.id)) known.set(body.id, body.id);
128
+ const decidedAt = (/* @__PURE__ */ new Date()).toISOString();
129
+ for (const [id, label] of known) {
130
+ const { decidedAt: _previous, ...rest } = byId.get(id) ?? {
131
+ group,
132
+ id
133
+ };
134
+ const record = id === body.id ? {
135
+ ...rest,
136
+ group,
137
+ id,
138
+ label,
139
+ status: "decided",
140
+ decidedAt
141
+ } : {
142
+ ...rest,
143
+ group,
144
+ id,
145
+ label,
146
+ status: "rejected"
147
+ };
148
+ await store.set(VARIANTS_COLLECTION, recordKey(group, id), { ...record });
149
+ }
150
+ const winnerLabel = known.get(body.id) ?? body.id;
151
+ const decision = {
152
+ group,
153
+ label: body.label ?? group,
154
+ winner: {
155
+ id: body.id,
156
+ label: winnerLabel
157
+ },
158
+ losers: [...known].filter(([id]) => id !== body.id).map(([id, label]) => ({
159
+ id,
160
+ label
161
+ })),
162
+ decidedAt
163
+ };
164
+ const response = {
165
+ ok: true,
166
+ group,
167
+ id: body.id,
168
+ decidedAt,
169
+ queued: null
170
+ };
171
+ if (dispatch) try {
172
+ const status = await dispatch.status?.() ?? { available: true };
173
+ if (!status.available) throw new Error(status.reason);
174
+ const prompt = brief(decision);
175
+ const run = await dispatch.dispatch({
176
+ note: `Clean up variant group "${group}": keep "${body.id}"`,
177
+ payload: null,
178
+ hints: [],
179
+ prompt
180
+ });
181
+ response.queued = {
182
+ target: dispatch.id,
183
+ runId: run.runId
184
+ };
185
+ if (run.detail) response.queued.detail = run.detail;
186
+ } catch (error) {
187
+ response.queueError = message(error);
188
+ }
189
+ return Response.json(response);
190
+ } catch (error) {
191
+ return failed(error, "decide");
192
+ }
193
+ } }
194
+ }
195
+ });
196
+ }
197
+ //#endregion
198
+ export { VARIANTS_COLLECTION, cleanupBrief, recordKey, toVariantRecord, variantsServer };
@@ -1,125 +1,5 @@
1
- import { c as HudPluginProps } from "../plugins-CQ_0w1ot.js";
1
+ import { a as HudGenerateResult, c as HudTokenDescriptor, d as HudTokensAdapter, i as HudGenerateRequest, l as HudTokenGroup, n as tokens, o as HudVariantCategory, r as variants, s as HudVariantsAdapter, t as forceState, u as HudTokenScope } from "../index-Hhh7OXzU.js";
2
+ import { a as formatVariantParam, i as VariantOption, n as VARIANT_PARAM, o as parseVariantParam, r as VariantGroupInfo, t as VARIANT_MARKER } from "../variant-groups-aAIrcNK5.js";
3
+ import { a as VariantStatus, i as VariantRecord, n as DecideResponse, o as VariantsListResponse, t as DecideBody } from "../variants-types-CcRf119M.js";
2
4
  import { i as ForcedState, n as FORCE_STATE_MARKER, r as FORCE_STATE_PARAM, t as FORCED_STATES } from "../force-state-CCqoTfVB.js";
3
- //#region src/plugins/design/force-state-panel.d.ts
4
- /**
5
- * Pill content: how many boundaries are forced, by toggle or param. Uses the
6
- * core `.dot`, since the plugin stylesheet only loads with the panel.
7
- */
8
- declare function ForceStatePill(): import("react").JSX.Element;
9
- /**
10
- * Toggles every mounted `StateBoundary` between its real state and a forced
11
- * loading, empty or error. Toggles live in memory: a reload returns every
12
- * boundary to auto, so a forgotten toggle cannot outlive the page.
13
- */
14
- declare function ForceStatePanel(): import("react").JSX.Element;
15
- //#endregion
16
- //#region src/plugins/design/tokens.d.ts
17
- interface HudTokenDescriptor {
18
- /** CSS custom property, including the leading dashes (e.g. `--primary`). */
19
- cssVar: string;
20
- /** Short display label; defaults to the var name without its leading dashes. */
21
- label?: string;
22
- }
23
- /**
24
- * Scope attribute the design system hangs its tokens on, with an optional
25
- * value: `{ attribute: "data-theme", value: "brand" }` matches
26
- * `[data-theme="brand"] { --primary: … }`. Omit for `:root`-scoped tokens.
27
- */
28
- interface HudTokenScope {
29
- attribute: string;
30
- value?: string;
31
- }
32
- interface HudTokenGroup {
33
- label: string;
34
- /** Var names (`"--primary"`) or descriptors with a label. */
35
- tokens: readonly (string | HudTokenDescriptor)[];
36
- scope?: HudTokenScope;
37
- }
38
- /** What an app tells the Tokens panel about its design system. */
39
- interface HudTokensAdapter {
40
- groups: readonly HudTokenGroup[];
41
- /** Where the tokens live, shown as a hint (e.g. `src/app/globals.css`). */
42
- sourceHint?: string;
43
- }
44
- //#endregion
45
- //#region src/plugins/design/variants-panel.d.ts
46
- interface HudVariantCategory {
47
- id: string;
48
- name: string;
49
- /** Registry status: "active" renders as votable, "decided" as settled. */
50
- status: string;
51
- alternativeCount: number;
52
- /** Domain bucket (marketing, admin, shared …) for grouping. Default "shared". */
53
- domain?: string;
54
- }
55
- interface HudGenerateRequest {
56
- /** Repo-relative component path. */
57
- path: string;
58
- brief: string;
59
- count: number;
60
- }
61
- interface HudGenerateResult {
62
- ok: boolean;
63
- /** Where the queued brief landed, on success. */
64
- markerPath?: string;
65
- error?: string;
66
- }
67
- /**
68
- * What an app tells the Variants panel about its variant registry. The HUD
69
- * owns no registry: an app maps its own (a static list, or a loader against
70
- * hn-monorepo#2552's variant groups) onto this shape.
71
- */
72
- interface HudVariantsAdapter {
73
- /** The categories, or a loader the panel calls each time it opens. */
74
- categories: readonly HudVariantCategory[] | (() => Promise<readonly HudVariantCategory[]>);
75
- /** Deep link to the full review dashboard, where voting happens. */
76
- reviewHref?: string;
77
- /** Deep link for one category's drill-in page. */
78
- categoryHref?: (categoryId: string) => string;
79
- /** Opens an in-page preview for a category; wins over `categoryHref`. */
80
- openPreview?: (categoryId: string) => void;
81
- /**
82
- * Queues a variant-generation brief. Shown only when the tier grants
83
- * `variants.generate`. The human stays in the loop: queue, not dispatch.
84
- */
85
- generate?: (request: HudGenerateRequest) => Promise<HudGenerateResult>;
86
- }
87
- //#endregion
88
- //#region src/plugins/design/index.d.ts
89
- /**
90
- * Live swatches of the host app's design tokens. Values are read from the
91
- * host document, outside the HUD's shadow root, so scoped and themed tokens
92
- * show what the page actually renders. Client only.
93
- */
94
- export declare function tokens(adapter: HudTokensAdapter): {
95
- readonly id: "tokens";
96
- readonly title: "Tokens";
97
- readonly panel: () => import("react").JSX.Element;
98
- };
99
- /**
100
- * The app's variant categories and the generate-brief queue, over an adapter
101
- * onto the app's own registry. Generating needs `variants.generate`. Client only.
102
- */
103
- export declare function variants(adapter: HudVariantsAdapter): {
104
- readonly id: "variants";
105
- readonly title: "Variants";
106
- readonly panel: ({ ctx }: HudPluginProps) => import("react").JSX.Element;
107
- };
108
- /**
109
- * Forces the page's `StateBoundary`s (`@hansenexus/hud/state-boundary`) to
110
- * loading, empty or error. The pill shows how many are forced. Client only.
111
- */
112
- export declare function forceState(): {
113
- readonly id: "states";
114
- readonly title: "States";
115
- readonly capability: "state.force";
116
- readonly pill: typeof ForceStatePill;
117
- readonly panel: typeof ForceStatePanel;
118
- readonly commands: readonly [{
119
- readonly id: "reset";
120
- readonly title: "Reset forced states";
121
- readonly run: () => void;
122
- }];
123
- };
124
- //#endregion
125
- export { FORCED_STATES, FORCE_STATE_MARKER, FORCE_STATE_PARAM, type ForcedState, type HudGenerateRequest, type HudGenerateResult, type HudTokenDescriptor, type HudTokenGroup, type HudTokenScope, type HudTokensAdapter, type HudVariantCategory, type HudVariantsAdapter };
5
+ export { type DecideBody, type DecideResponse, FORCED_STATES, FORCE_STATE_MARKER, FORCE_STATE_PARAM, type ForcedState, type HudGenerateRequest, type HudGenerateResult, type HudTokenDescriptor, type HudTokenGroup, type HudTokenScope, type HudTokensAdapter, type HudVariantCategory, type HudVariantsAdapter, VARIANT_MARKER, VARIANT_PARAM, type VariantGroupInfo, type VariantOption, type VariantRecord, type VariantStatus, type VariantsListResponse, forceState, formatVariantParam, parseVariantParam, tokens, variants };