@hansenexus/hud 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +603 -9
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
- package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
- package/dist/access-panel-CEfTr9ZI.js +123 -0
- package/dist/adapter-BYoxPYTI.d.ts +33 -0
- package/dist/adapter-hcwmJtNx.js +65 -0
- package/dist/auto/runtime.d.ts +65 -0
- package/dist/auto/runtime.js +50 -0
- package/dist/auto.d.ts +15 -0
- package/dist/auto.js +33 -0
- package/dist/capabilities-rDSKjXpq.js +110 -0
- package/dist/capture-CwrIwLqi.js +300 -0
- package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +275 -0
- package/dist/data-panel-DhxAmP91.js +817 -0
- package/dist/data-store-ChF1td_P.js +164 -0
- package/dist/define-hud-CHPedaQ5.d.ts +50 -0
- package/dist/design-D0kGgPoP.js +87 -0
- package/dist/detect-BxHZ0pxW.d.ts +25 -0
- package/dist/detect-CHZiSeZs.js +63 -0
- package/dist/dispatch-panel-B-xr_Giy.js +279 -0
- package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
- package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
- package/dist/file-xdSaQ2uR.js +103 -0
- package/dist/flags-DVtaJ8pQ.d.ts +58 -0
- package/dist/flags.d.ts +2 -0
- package/dist/flags.js +82 -0
- package/dist/force-state-panel-_otVYh9i.js +97 -0
- package/dist/generate-C8lQl3Eh.js +53 -0
- package/dist/handler-BpVhxEmU.js +106 -0
- package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
- package/dist/index-BAV_1W8a.d.ts +43 -0
- package/dist/index-BJ26pse9.d.ts +70 -0
- package/dist/index-BnQ0dTZf.d.ts +19 -0
- package/dist/index-CwfX-W87.d.ts +72 -0
- package/dist/index-DcH9V3cU.d.ts +48 -0
- package/dist/index-DqOyNf1u.d.ts +65 -0
- package/dist/index-DstI_ike.d.ts +66 -0
- package/dist/index-Dxz4fn4j.d.ts +42 -0
- package/dist/index-Hhh7OXzU.d.ts +129 -0
- package/dist/index-ReFbhQ9p.d.ts +25 -0
- package/dist/index-RgXfMBuW.d.ts +48 -0
- package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +710 -69
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/meta-Bv0sEao3.js +6 -0
- package/dist/meta-C_G7MB5w.d.ts +49 -0
- package/dist/mocks-CA-wM2SB.d.ts +109 -0
- package/dist/mocks-ESiRqk9o.js +150 -0
- package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
- package/dist/next/config.d.ts +52 -0
- package/dist/next/config.js +78 -0
- package/dist/next.d.ts +14 -4
- package/dist/next.js +5 -3
- package/dist/observe-CdDnDBRP.js +89 -0
- package/dist/observe-panel-Cgp1M8oT.js +347 -0
- package/dist/ops-panel-CEqDe_UT.js +234 -0
- package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +5 -5
- package/dist/plugins/access/server.js +4 -3
- package/dist/plugins/access.d.ts +5 -5
- package/dist/plugins/access.js +16 -215
- package/dist/plugins/agent/server.d.ts +3 -38
- package/dist/plugins/agent/server.js +47 -21
- package/dist/plugins/agent.d.ts +4 -4
- package/dist/plugins/agent.js +6 -348
- package/dist/plugins/capture/server.d.ts +92 -0
- package/dist/plugins/capture/server.js +248 -0
- package/dist/plugins/capture.d.ts +24 -0
- package/dist/plugins/capture.js +70 -0
- package/dist/plugins/data/msw-browser.d.ts +2 -0
- package/dist/plugins/data/msw-browser.js +39 -0
- package/dist/plugins/data/msw-node.d.ts +36 -0
- package/dist/plugins/data/msw-node.js +68 -0
- package/dist/plugins/data/server.d.ts +257 -0
- package/dist/plugins/data/server.js +717 -0
- package/dist/plugins/data.d.ts +6 -0
- package/dist/plugins/data.js +51 -0
- package/dist/plugins/design/server.d.ts +54 -0
- package/dist/plugins/design/server.js +198 -0
- package/dist/plugins/design.d.ts +4 -124
- package/dist/plugins/design.js +4 -619
- package/dist/plugins/inspect/convex.d.ts +2 -0
- package/dist/plugins/inspect/convex.js +486 -0
- package/dist/plugins/inspect/react-query.d.ts +2 -0
- package/dist/plugins/inspect/react-query.js +225 -0
- package/dist/plugins/inspect/sockets.d.ts +51 -0
- package/dist/plugins/inspect/sockets.js +397 -0
- package/dist/plugins/inspect/swr.d.ts +2 -0
- package/dist/plugins/inspect/swr.js +218 -0
- package/dist/plugins/inspect.d.ts +4 -0
- package/dist/plugins/inspect.js +3 -0
- package/dist/plugins/observe.d.ts +4 -64
- package/dist/plugins/observe.js +1 -616
- package/dist/plugins/ops/server.d.ts +1 -1
- package/dist/plugins/ops/server.js +2 -1
- package/dist/plugins/ops.d.ts +2 -1
- package/dist/plugins/ops.js +15 -336
- package/dist/plugins/routes/server.d.ts +88 -0
- package/dist/plugins/routes/server.js +62 -0
- package/dist/plugins/routes.d.ts +3 -0
- package/dist/plugins/routes.js +216 -0
- package/dist/plugins/seo.d.ts +2 -0
- package/dist/plugins/seo.js +2 -0
- package/dist/plugins/vitals.d.ts +2 -25
- package/dist/plugins/vitals.js +3 -2
- package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
- package/dist/poll-CjKsWZi8.js +89 -0
- package/dist/requests-BwD6MKEq.js +282 -0
- package/dist/requests-CJrUf465.d.ts +50 -0
- package/dist/review.js +2 -2
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
- package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
- package/dist/styles-DKU_P8MH.js +139 -0
- package/dist/styles-DPpDPmzi.js +68 -0
- package/dist/tokens-panel-CbMQfasZ.js +142 -0
- package/dist/types-B-ulf2Jp.js +8 -0
- package/dist/types-BIgGf-0C.d.ts +25 -0
- package/dist/types-BIkI-qN8.js +30 -0
- package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
- package/dist/types-DIdPfjtV.js +6 -0
- package/dist/types-DaJcsEjO.d.ts +44 -0
- package/dist/types-Dn68psVz.d.ts +118 -0
- package/dist/types-szkr2QOF.d.ts +39 -0
- package/dist/unlock-store-4V3vR4Eg.js +96 -0
- package/dist/variant-groups-TIfO3NIj.js +137 -0
- package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
- package/dist/variants-panel-BDoSkwBJ.js +457 -0
- package/dist/variants-types-CcRf119M.d.ts +63 -0
- package/dist/variants.d.ts +43 -0
- package/dist/variants.js +83 -0
- package/dist/vitals-panel-BCmMUntW.js +30 -0
- package/dist/vite.d.ts +37 -0
- package/dist/vite.js +134 -0
- package/package.json +65 -5
- package/dist/define-hud-BBzsSl8b.d.ts +0 -36
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { n as HudApiError } from "./plugins-DVy_vaYr.js";
|
|
2
|
+
import { a as getVariantGroupsSnapshot, c as subscribeVariantGroups, i as getVariantGroupStore, s as resolveVariant } from "./variant-groups-TIfO3NIj.js";
|
|
3
|
+
import { t as DESIGN_CSS } from "./styles-DKU_P8MH.js";
|
|
4
|
+
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region src/plugins/design/variants-panel.tsx
|
|
7
|
+
function errorMessage(error, fallback) {
|
|
8
|
+
return error instanceof Error ? error.message : fallback;
|
|
9
|
+
}
|
|
10
|
+
function useCategories(source) {
|
|
11
|
+
const [loaded, setLoaded] = useState(() => typeof source === "function" ? { state: "loading" } : {
|
|
12
|
+
state: "ready",
|
|
13
|
+
categories: source
|
|
14
|
+
});
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (typeof source !== "function") {
|
|
17
|
+
setLoaded({
|
|
18
|
+
state: "ready",
|
|
19
|
+
categories: source
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let live = true;
|
|
24
|
+
setLoaded({ state: "loading" });
|
|
25
|
+
source().then((categories) => live && setLoaded({
|
|
26
|
+
state: "ready",
|
|
27
|
+
categories
|
|
28
|
+
}), (error) => live && setLoaded({
|
|
29
|
+
state: "failed",
|
|
30
|
+
error: errorMessage(error, "loading failed")
|
|
31
|
+
}));
|
|
32
|
+
return () => {
|
|
33
|
+
live = false;
|
|
34
|
+
};
|
|
35
|
+
}, [source]);
|
|
36
|
+
return loaded;
|
|
37
|
+
}
|
|
38
|
+
function groupByDomain(categories) {
|
|
39
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const category of categories) {
|
|
41
|
+
const key = category.domain ?? "shared";
|
|
42
|
+
grouped.set(key, [...grouped.get(key) ?? [], category]);
|
|
43
|
+
}
|
|
44
|
+
return [...grouped];
|
|
45
|
+
}
|
|
46
|
+
function useRecords(ctx) {
|
|
47
|
+
const [records, setRecords] = useState({ state: "loading" });
|
|
48
|
+
const token = useRef(0);
|
|
49
|
+
const load = useCallback(() => {
|
|
50
|
+
token.current += 1;
|
|
51
|
+
const mine = token.current;
|
|
52
|
+
const settle = (next) => {
|
|
53
|
+
if (mine === token.current) setRecords(next);
|
|
54
|
+
};
|
|
55
|
+
ctx.api("/").then((body) => settle({
|
|
56
|
+
state: "ready",
|
|
57
|
+
records: body.records ?? []
|
|
58
|
+
}), (error) => {
|
|
59
|
+
if (error instanceof HudApiError && (error.status === 404 || error.status === 403)) settle({ state: "unavailable" });
|
|
60
|
+
else settle({
|
|
61
|
+
state: "failed",
|
|
62
|
+
error: errorMessage(error, "loading scores failed")
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}, [ctx]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
load();
|
|
68
|
+
return () => {
|
|
69
|
+
token.current += 1;
|
|
70
|
+
};
|
|
71
|
+
}, [load]);
|
|
72
|
+
return [records, load];
|
|
73
|
+
}
|
|
74
|
+
const EMPTY_SNAPSHOT = {
|
|
75
|
+
groups: [],
|
|
76
|
+
choices: {}
|
|
77
|
+
};
|
|
78
|
+
const getEmptySnapshot = () => EMPTY_SNAPSHOT;
|
|
79
|
+
/**
|
|
80
|
+
* Variants panel. "Live on this page" lists every mounted `VariantGroup`
|
|
81
|
+
* (`@hansenexus/hud/variants`) with a switcher that rewrites `?variant=`,
|
|
82
|
+
* the agent-written score and rationale per variant from the storage seam,
|
|
83
|
+
* ranked, and Decide (needs `variants.decide` and the server half). An
|
|
84
|
+
* adapter adds the app's own registry and the generate-brief queue.
|
|
85
|
+
*/
|
|
86
|
+
function VariantsPanel({ adapter, ctx }) {
|
|
87
|
+
const snapshot = useSyncExternalStore(subscribeVariantGroups, getVariantGroupsSnapshot, getEmptySnapshot);
|
|
88
|
+
const [records, reload] = useRecords(ctx);
|
|
89
|
+
const stored = records.state === "ready" ? records.records : [];
|
|
90
|
+
const liveIds = new Set(snapshot.groups.map((group) => group.id));
|
|
91
|
+
const elsewhere = stored.filter((record) => !liveIds.has(record.group));
|
|
92
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
93
|
+
className: "design",
|
|
94
|
+
children: [
|
|
95
|
+
/* @__PURE__ */ jsx("style", { children: DESIGN_CSS }),
|
|
96
|
+
/* @__PURE__ */ jsxs("section", {
|
|
97
|
+
className: "design-section",
|
|
98
|
+
"aria-label": "Live variants",
|
|
99
|
+
children: [
|
|
100
|
+
/* @__PURE__ */ jsxs("span", {
|
|
101
|
+
className: "design-heading",
|
|
102
|
+
children: ["Live on this page", snapshot.groups.length > 0 ? ` (${snapshot.groups.length})` : ""]
|
|
103
|
+
}),
|
|
104
|
+
snapshot.groups.length === 0 && /* @__PURE__ */ jsxs("p", {
|
|
105
|
+
className: "design-hint",
|
|
106
|
+
children: [
|
|
107
|
+
"No variant groups on this page. Wrap a region in ",
|
|
108
|
+
/* @__PURE__ */ jsx("code", { children: "VariantGroup" }),
|
|
109
|
+
" from",
|
|
110
|
+
" ",
|
|
111
|
+
/* @__PURE__ */ jsx("code", { children: "@hansenexus/hud/variants" }),
|
|
112
|
+
"."
|
|
113
|
+
]
|
|
114
|
+
}),
|
|
115
|
+
records.state === "failed" && /* @__PURE__ */ jsx("p", {
|
|
116
|
+
className: "design-result",
|
|
117
|
+
"data-ok": "false",
|
|
118
|
+
children: records.error
|
|
119
|
+
}),
|
|
120
|
+
snapshot.groups.map((group) => /* @__PURE__ */ jsx(LiveGroup, {
|
|
121
|
+
group,
|
|
122
|
+
choices: snapshot.choices,
|
|
123
|
+
records: stored.filter((record) => record.group === group.id),
|
|
124
|
+
canDecide: records.state === "ready" && ctx.can("variants.decide"),
|
|
125
|
+
ctx,
|
|
126
|
+
onDecided: reload
|
|
127
|
+
}, group.id)),
|
|
128
|
+
snapshot.groups.length > 0 && records.state === "unavailable" && /* @__PURE__ */ jsxs("p", {
|
|
129
|
+
className: "design-hint",
|
|
130
|
+
children: [
|
|
131
|
+
"Scores and Decide need ",
|
|
132
|
+
/* @__PURE__ */ jsx("code", { children: "variantsServer()" }),
|
|
133
|
+
" in the HUD route."
|
|
134
|
+
]
|
|
135
|
+
})
|
|
136
|
+
]
|
|
137
|
+
}),
|
|
138
|
+
elsewhere.length > 0 && /* @__PURE__ */ jsx(Elsewhere, { records: elsewhere }),
|
|
139
|
+
adapter && /* @__PURE__ */ jsx(Categories, { adapter }),
|
|
140
|
+
adapter?.generate && ctx.can("variants.generate") && /* @__PURE__ */ jsx(GenerateForm, { generate: adapter.generate })
|
|
141
|
+
]
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/** Variants ranked by score, highest first; unscored ones keep page order after them. */
|
|
145
|
+
function rankVariants(group, records) {
|
|
146
|
+
const byId = new Map(records.map((record) => [record.id, record]));
|
|
147
|
+
return group.variants.map((variant, index) => ({
|
|
148
|
+
...variant,
|
|
149
|
+
record: byId.get(variant.id),
|
|
150
|
+
index
|
|
151
|
+
})).sort((a, b) => {
|
|
152
|
+
const sa = a.record?.score;
|
|
153
|
+
const sb = b.record?.score;
|
|
154
|
+
if (sa === void 0 && sb === void 0) return a.index - b.index;
|
|
155
|
+
if (sa === void 0) return 1;
|
|
156
|
+
if (sb === void 0) return -1;
|
|
157
|
+
return sb - sa || a.index - b.index;
|
|
158
|
+
}).map(({ index: _index, ...variant }) => variant);
|
|
159
|
+
}
|
|
160
|
+
function formatScore(score) {
|
|
161
|
+
return Number.isInteger(score) ? String(score) : score.toFixed(1);
|
|
162
|
+
}
|
|
163
|
+
function formatDate(iso) {
|
|
164
|
+
const date = new Date(iso);
|
|
165
|
+
return Number.isNaN(date.getTime()) ? iso : date.toISOString().slice(0, 10);
|
|
166
|
+
}
|
|
167
|
+
function LiveGroup({ group, choices, records, canDecide, ctx, onDecided }) {
|
|
168
|
+
const chosen = resolveVariant(group, choices);
|
|
169
|
+
const ranked = rankVariants(group, records);
|
|
170
|
+
const decided = records.find((record) => record.status === "decided");
|
|
171
|
+
const [deciding, setDeciding] = useState(false);
|
|
172
|
+
const [result, setResult] = useState(null);
|
|
173
|
+
const decide = async () => {
|
|
174
|
+
setDeciding(true);
|
|
175
|
+
setResult(null);
|
|
176
|
+
const body = {
|
|
177
|
+
id: chosen,
|
|
178
|
+
label: group.label,
|
|
179
|
+
variants: group.variants.map(({ id, label }) => ({
|
|
180
|
+
id,
|
|
181
|
+
label
|
|
182
|
+
}))
|
|
183
|
+
};
|
|
184
|
+
try {
|
|
185
|
+
const response = await ctx.api(`/${encodeURIComponent(group.id)}/decide`, {
|
|
186
|
+
method: "POST",
|
|
187
|
+
headers: { "content-type": "application/json" },
|
|
188
|
+
body: JSON.stringify(body)
|
|
189
|
+
});
|
|
190
|
+
if (response.queueError) setResult({
|
|
191
|
+
ok: false,
|
|
192
|
+
text: `decided, brief not queued: ${response.queueError}`
|
|
193
|
+
});
|
|
194
|
+
else if (response.queued) {
|
|
195
|
+
const { target, runId, detail } = response.queued;
|
|
196
|
+
setResult({
|
|
197
|
+
ok: true,
|
|
198
|
+
text: `brief queued → ${target} ${runId}${detail ? ` (${detail})` : ""}`
|
|
199
|
+
});
|
|
200
|
+
} else setResult({
|
|
201
|
+
ok: true,
|
|
202
|
+
text: "decided; no dispatch provider configured, nothing queued"
|
|
203
|
+
});
|
|
204
|
+
onDecided();
|
|
205
|
+
} catch (error) {
|
|
206
|
+
setResult({
|
|
207
|
+
ok: false,
|
|
208
|
+
text: errorMessage(error, "decide failed")
|
|
209
|
+
});
|
|
210
|
+
} finally {
|
|
211
|
+
setDeciding(false);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
215
|
+
className: "design-group",
|
|
216
|
+
"data-group": group.id,
|
|
217
|
+
children: [
|
|
218
|
+
/* @__PURE__ */ jsxs("div", {
|
|
219
|
+
className: "design-row",
|
|
220
|
+
children: [
|
|
221
|
+
/* @__PURE__ */ jsx("span", {
|
|
222
|
+
className: "design-grow",
|
|
223
|
+
children: group.label
|
|
224
|
+
}),
|
|
225
|
+
decided && /* @__PURE__ */ jsxs("span", {
|
|
226
|
+
className: "design-badge",
|
|
227
|
+
"data-tone": "active",
|
|
228
|
+
title: decided.decidedAt,
|
|
229
|
+
children: [
|
|
230
|
+
"decided: ",
|
|
231
|
+
decided.label ?? decided.id,
|
|
232
|
+
decided.decidedAt ? ` · ${formatDate(decided.decidedAt)}` : ""
|
|
233
|
+
]
|
|
234
|
+
}),
|
|
235
|
+
/* @__PURE__ */ jsx("span", {
|
|
236
|
+
className: "design-muted design-mono",
|
|
237
|
+
children: group.id
|
|
238
|
+
})
|
|
239
|
+
]
|
|
240
|
+
}),
|
|
241
|
+
/* @__PURE__ */ jsx("ul", {
|
|
242
|
+
className: "design-variants",
|
|
243
|
+
children: ranked.map(({ id, label, record }) => /* @__PURE__ */ jsxs("li", {
|
|
244
|
+
className: "design-variant",
|
|
245
|
+
"data-group": group.id,
|
|
246
|
+
"data-variant": id,
|
|
247
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
248
|
+
className: "design-row",
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ jsxs("button", {
|
|
251
|
+
type: "button",
|
|
252
|
+
className: "design-segment design-grow",
|
|
253
|
+
"aria-pressed": id === chosen,
|
|
254
|
+
onClick: () => getVariantGroupStore().choose(group.id, id === group.defaultId ? null : id),
|
|
255
|
+
children: [label, id === group.defaultId ? /* @__PURE__ */ jsx("span", {
|
|
256
|
+
className: "design-muted",
|
|
257
|
+
children: " (default)"
|
|
258
|
+
}) : null]
|
|
259
|
+
}),
|
|
260
|
+
record?.score !== void 0 && /* @__PURE__ */ jsxs("span", {
|
|
261
|
+
className: "design-badge design-score",
|
|
262
|
+
title: record.scoredBy ? `scored by ${record.scoredBy}` : void 0,
|
|
263
|
+
children: [formatScore(record.score), record.scoredBy ? /* @__PURE__ */ jsxs("span", {
|
|
264
|
+
className: "design-muted",
|
|
265
|
+
children: [" · ", record.scoredBy]
|
|
266
|
+
}) : null]
|
|
267
|
+
}),
|
|
268
|
+
record?.status === "rejected" && /* @__PURE__ */ jsx("span", {
|
|
269
|
+
className: "design-badge",
|
|
270
|
+
children: "rejected"
|
|
271
|
+
}),
|
|
272
|
+
canDecide && id === chosen && /* @__PURE__ */ jsx("button", {
|
|
273
|
+
type: "button",
|
|
274
|
+
className: "design-button",
|
|
275
|
+
disabled: deciding,
|
|
276
|
+
onClick: decide,
|
|
277
|
+
children: "Decide"
|
|
278
|
+
})
|
|
279
|
+
]
|
|
280
|
+
}), record?.rationale && /* @__PURE__ */ jsx("p", {
|
|
281
|
+
className: "design-rationale",
|
|
282
|
+
children: record.rationale
|
|
283
|
+
})]
|
|
284
|
+
}, id))
|
|
285
|
+
}),
|
|
286
|
+
result && /* @__PURE__ */ jsx("p", {
|
|
287
|
+
className: "design-result design-mono",
|
|
288
|
+
"data-ok": result.ok,
|
|
289
|
+
children: result.text
|
|
290
|
+
})
|
|
291
|
+
]
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
/** Records whose group is not mounted on this page, so an agent's work elsewhere still shows. */
|
|
295
|
+
function Elsewhere({ records }) {
|
|
296
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
297
|
+
className: "design-section",
|
|
298
|
+
"aria-label": "Scored elsewhere",
|
|
299
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
300
|
+
className: "design-heading",
|
|
301
|
+
children: "Scored elsewhere"
|
|
302
|
+
}), records.map((record) => /* @__PURE__ */ jsxs("div", {
|
|
303
|
+
className: "design-row",
|
|
304
|
+
children: [
|
|
305
|
+
/* @__PURE__ */ jsxs("span", {
|
|
306
|
+
className: "design-mono design-grow",
|
|
307
|
+
children: [
|
|
308
|
+
record.group,
|
|
309
|
+
":",
|
|
310
|
+
record.id
|
|
311
|
+
]
|
|
312
|
+
}),
|
|
313
|
+
record.status && record.status !== "open" && /* @__PURE__ */ jsx("span", {
|
|
314
|
+
className: "design-badge",
|
|
315
|
+
"data-tone": record.status === "decided" ? "active" : void 0,
|
|
316
|
+
children: record.status
|
|
317
|
+
}),
|
|
318
|
+
record.score !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
319
|
+
className: "design-badge design-score",
|
|
320
|
+
children: formatScore(record.score)
|
|
321
|
+
})
|
|
322
|
+
]
|
|
323
|
+
}, `${record.group}:${record.id}`))]
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
function Categories({ adapter }) {
|
|
327
|
+
const loaded = useCategories(adapter.categories);
|
|
328
|
+
const { reviewHref, categoryHref, openPreview } = adapter;
|
|
329
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
330
|
+
className: "design-section",
|
|
331
|
+
"aria-label": "Categories",
|
|
332
|
+
children: [
|
|
333
|
+
/* @__PURE__ */ jsxs("div", {
|
|
334
|
+
className: "design-heading",
|
|
335
|
+
children: [/* @__PURE__ */ jsxs("span", { children: ["Categories", loaded.state === "ready" ? ` (${loaded.categories.length})` : ""] }), reviewHref && /* @__PURE__ */ jsx("a", {
|
|
336
|
+
className: "design-link",
|
|
337
|
+
href: reviewHref,
|
|
338
|
+
children: "review ↗"
|
|
339
|
+
})]
|
|
340
|
+
}),
|
|
341
|
+
loaded.state === "loading" && /* @__PURE__ */ jsx("p", {
|
|
342
|
+
className: "design-hint",
|
|
343
|
+
children: "Loading…"
|
|
344
|
+
}),
|
|
345
|
+
loaded.state === "failed" && /* @__PURE__ */ jsx("p", {
|
|
346
|
+
className: "design-result",
|
|
347
|
+
"data-ok": "false",
|
|
348
|
+
children: loaded.error
|
|
349
|
+
}),
|
|
350
|
+
loaded.state === "ready" && loaded.categories.length === 0 && /* @__PURE__ */ jsx("p", {
|
|
351
|
+
className: "design-hint",
|
|
352
|
+
children: "No variant categories registered for this app."
|
|
353
|
+
}),
|
|
354
|
+
loaded.state === "ready" && groupByDomain(loaded.categories).map(([domain, list]) => /* @__PURE__ */ jsxs("div", {
|
|
355
|
+
className: "design-section",
|
|
356
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
357
|
+
className: "design-heading",
|
|
358
|
+
children: domain
|
|
359
|
+
}), list.map((category) => /* @__PURE__ */ jsxs("div", {
|
|
360
|
+
className: "design-row",
|
|
361
|
+
children: [
|
|
362
|
+
/* @__PURE__ */ jsx("span", {
|
|
363
|
+
className: "design-badge",
|
|
364
|
+
"data-tone": category.status === "active" ? "active" : void 0,
|
|
365
|
+
children: category.status
|
|
366
|
+
}),
|
|
367
|
+
/* @__PURE__ */ jsx("span", {
|
|
368
|
+
className: "design-grow",
|
|
369
|
+
children: category.name
|
|
370
|
+
}),
|
|
371
|
+
/* @__PURE__ */ jsxs("span", {
|
|
372
|
+
className: "design-muted",
|
|
373
|
+
children: [
|
|
374
|
+
category.alternativeCount,
|
|
375
|
+
" alt",
|
|
376
|
+
category.alternativeCount === 1 ? "" : "s"
|
|
377
|
+
]
|
|
378
|
+
}),
|
|
379
|
+
openPreview ? /* @__PURE__ */ jsx("button", {
|
|
380
|
+
type: "button",
|
|
381
|
+
className: "design-link",
|
|
382
|
+
onClick: () => openPreview(category.id),
|
|
383
|
+
children: "open"
|
|
384
|
+
}) : categoryHref ? /* @__PURE__ */ jsx("a", {
|
|
385
|
+
className: "design-link",
|
|
386
|
+
href: categoryHref(category.id),
|
|
387
|
+
children: "open ↗"
|
|
388
|
+
}) : null
|
|
389
|
+
]
|
|
390
|
+
}, category.id))]
|
|
391
|
+
}, domain))
|
|
392
|
+
]
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
function GenerateForm({ generate }) {
|
|
396
|
+
const [path, setPath] = useState("");
|
|
397
|
+
const [brief, setBrief] = useState("");
|
|
398
|
+
const [sending, setSending] = useState(false);
|
|
399
|
+
const [result, setResult] = useState(null);
|
|
400
|
+
const submit = async () => {
|
|
401
|
+
if (!path.trim()) return;
|
|
402
|
+
setSending(true);
|
|
403
|
+
setResult(null);
|
|
404
|
+
try {
|
|
405
|
+
setResult(await generate({
|
|
406
|
+
path: path.trim(),
|
|
407
|
+
brief: brief.trim(),
|
|
408
|
+
count: 3
|
|
409
|
+
}));
|
|
410
|
+
} catch (error) {
|
|
411
|
+
setResult({
|
|
412
|
+
ok: false,
|
|
413
|
+
error: errorMessage(error, "generate failed")
|
|
414
|
+
});
|
|
415
|
+
} finally {
|
|
416
|
+
setSending(false);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
420
|
+
className: "design-section",
|
|
421
|
+
"aria-label": "Generate variants",
|
|
422
|
+
children: [
|
|
423
|
+
/* @__PURE__ */ jsx("span", {
|
|
424
|
+
className: "design-heading",
|
|
425
|
+
children: "Generate variants"
|
|
426
|
+
}),
|
|
427
|
+
/* @__PURE__ */ jsx("input", {
|
|
428
|
+
className: "design-field",
|
|
429
|
+
"aria-label": "Component path",
|
|
430
|
+
placeholder: "src/components/… (repo-relative)",
|
|
431
|
+
value: path,
|
|
432
|
+
onChange: (e) => setPath(e.target.value)
|
|
433
|
+
}),
|
|
434
|
+
/* @__PURE__ */ jsx("textarea", {
|
|
435
|
+
className: "design-field",
|
|
436
|
+
"aria-label": "Brief",
|
|
437
|
+
placeholder: "Brief, e.g. three denser table treatments",
|
|
438
|
+
value: brief,
|
|
439
|
+
onChange: (e) => setBrief(e.target.value)
|
|
440
|
+
}),
|
|
441
|
+
/* @__PURE__ */ jsx("button", {
|
|
442
|
+
type: "button",
|
|
443
|
+
className: "design-button",
|
|
444
|
+
disabled: sending || !path.trim(),
|
|
445
|
+
onClick: submit,
|
|
446
|
+
children: "Queue 3 variants"
|
|
447
|
+
}),
|
|
448
|
+
result && /* @__PURE__ */ jsx("p", {
|
|
449
|
+
className: "design-result design-mono",
|
|
450
|
+
"data-ok": result.ok,
|
|
451
|
+
children: result.ok ? `queued → ${result.markerPath ?? "ok"}` : result.error ?? "failed"
|
|
452
|
+
})
|
|
453
|
+
]
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
//#endregion
|
|
457
|
+
export { VariantsPanel, VariantsPanel as default, rankVariants };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region src/plugins/design/variants-types.d.ts
|
|
2
|
+
/** Wire types shared by the Variants panel and `variantsServer()`. */
|
|
3
|
+
/** The store collection scores and decisions live in: `.hud/variants.json` with `file()`. */
|
|
4
|
+
declare const VARIANTS_COLLECTION = "variants";
|
|
5
|
+
type VariantStatus = "open" | "decided" | "rejected";
|
|
6
|
+
/**
|
|
7
|
+
* One variant's record. The store keys it `<group>:<id>`; an agent writes
|
|
8
|
+
* `score`, `rationale` and `scoredBy`, Decide writes `status` and `decidedAt`.
|
|
9
|
+
* Everything but `group` and `id` is optional, since the file is edited by hand.
|
|
10
|
+
*/
|
|
11
|
+
interface VariantRecord {
|
|
12
|
+
group: string;
|
|
13
|
+
id: string;
|
|
14
|
+
label?: string;
|
|
15
|
+
status?: VariantStatus;
|
|
16
|
+
/** Higher is better; the panel ranks by it. */
|
|
17
|
+
score?: number;
|
|
18
|
+
rationale?: string;
|
|
19
|
+
/** Who scored it, e.g. `claude-code`. */
|
|
20
|
+
scoredBy?: string;
|
|
21
|
+
/** ISO timestamp set by Decide on the winner. */
|
|
22
|
+
decidedAt?: string;
|
|
23
|
+
}
|
|
24
|
+
/** `GET <apiBase>/variants/`. */
|
|
25
|
+
interface VariantsListResponse {
|
|
26
|
+
ok: true;
|
|
27
|
+
records: VariantRecord[];
|
|
28
|
+
}
|
|
29
|
+
/** `POST <apiBase>/variants/:group/decide`. */
|
|
30
|
+
interface DecideBody {
|
|
31
|
+
/** The winner. */
|
|
32
|
+
id: string;
|
|
33
|
+
/** The group's label, for the brief. */
|
|
34
|
+
label?: string;
|
|
35
|
+
/** Every variant of the group as the page registers it, so losers get a record too. */
|
|
36
|
+
variants?: {
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
}[];
|
|
40
|
+
}
|
|
41
|
+
interface DecideResponse {
|
|
42
|
+
ok: true;
|
|
43
|
+
group: string;
|
|
44
|
+
id: string;
|
|
45
|
+
decidedAt: string;
|
|
46
|
+
/** The queued cleanup brief, or null when no dispatch provider is configured. */
|
|
47
|
+
queued: {
|
|
48
|
+
target: string;
|
|
49
|
+
runId: string;
|
|
50
|
+
detail?: string;
|
|
51
|
+
} | null;
|
|
52
|
+
/** The decision stuck but the brief did not go out. */
|
|
53
|
+
queueError?: string;
|
|
54
|
+
}
|
|
55
|
+
declare function recordKey(group: string, id: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* A store entry as a `VariantRecord`: group and id come from the fields, or
|
|
58
|
+
* from a `<group>:<id>` key when the file omits them. Unknown fields are
|
|
59
|
+
* dropped, wrong types ignored; null when neither names the variant.
|
|
60
|
+
*/
|
|
61
|
+
declare function toVariantRecord(id: string, value: unknown): VariantRecord | null;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { VariantStatus as a, toVariantRecord as c, VariantRecord as i, DecideResponse as n, VariantsListResponse as o, VARIANTS_COLLECTION as r, recordKey as s, DecideBody as t };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { i as VariantOption, r as VariantGroupInfo } from "./variant-groups-aAIrcNK5.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/plugins/design/variant-group.d.ts
|
|
4
|
+
export interface VariantDefinition {
|
|
5
|
+
/** Shown in the switcher. Default: the id. */
|
|
6
|
+
label?: string;
|
|
7
|
+
render: () => ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export interface VariantGroupProps {
|
|
10
|
+
/** Stable, page-unique id; `?variant=<id>:<variant>` and the Variants panel address the group by it. */
|
|
11
|
+
id: string;
|
|
12
|
+
/** Shown in the switcher. Default: the id. */
|
|
13
|
+
label?: string;
|
|
14
|
+
/** The variant rendered when the URL names none (and the only one in production). Default: the first key. */
|
|
15
|
+
default?: string;
|
|
16
|
+
variants: Record<string, VariantDefinition>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A region of a real page with several alternatives, switchable in place:
|
|
20
|
+
*
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <VariantGroup
|
|
23
|
+
* id="hero"
|
|
24
|
+
* label="Hero"
|
|
25
|
+
* default="current"
|
|
26
|
+
* variants={{
|
|
27
|
+
* current: { label: "Current", render: () => <Hero /> },
|
|
28
|
+
* bold: { label: "Bold claim", render: () => <HeroBold /> },
|
|
29
|
+
* }}
|
|
30
|
+
* />
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* In development `?variant=hero:bold` renders that variant and the HUD's
|
|
34
|
+
* Variants panel (`variants()` from `@hansenexus/hud/plugins/design`) lists
|
|
35
|
+
* the group with a switcher, agent scores and Decide. Production-safe to
|
|
36
|
+
* import: outside development it renders the default and nothing else.
|
|
37
|
+
*
|
|
38
|
+
* A client component: use it from client code, since the render functions
|
|
39
|
+
* cannot cross a server/client boundary as props.
|
|
40
|
+
*/
|
|
41
|
+
export declare function VariantGroup(props: VariantGroupProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | null | undefined;
|
|
42
|
+
//#endregion
|
|
43
|
+
export type { VariantGroupInfo, VariantOption };
|
package/dist/variants.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { a as getVariantGroupsSnapshot, c as subscribeVariantGroups, i as getVariantGroupStore, s as resolveVariant } from "./variant-groups-TIfO3NIj.js";
|
|
3
|
+
import { useEffect, useMemo, useSyncExternalStore } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/plugins/design/variant-group.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Build-time gate. A literal once the consumer's bundler inlines NODE_ENV, so
|
|
8
|
+
* a production build folds `VariantGroup` to the default variant and drops
|
|
9
|
+
* the registry, the URL parsing and the losing variants' wiring with it.
|
|
10
|
+
*/
|
|
11
|
+
const VARIANTS_ENABLED = process.env.NODE_ENV === "development";
|
|
12
|
+
/**
|
|
13
|
+
* A region of a real page with several alternatives, switchable in place:
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <VariantGroup
|
|
17
|
+
* id="hero"
|
|
18
|
+
* label="Hero"
|
|
19
|
+
* default="current"
|
|
20
|
+
* variants={{
|
|
21
|
+
* current: { label: "Current", render: () => <Hero /> },
|
|
22
|
+
* bold: { label: "Bold claim", render: () => <HeroBold /> },
|
|
23
|
+
* }}
|
|
24
|
+
* />
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* In development `?variant=hero:bold` renders that variant and the HUD's
|
|
28
|
+
* Variants panel (`variants()` from `@hansenexus/hud/plugins/design`) lists
|
|
29
|
+
* the group with a switcher, agent scores and Decide. Production-safe to
|
|
30
|
+
* import: outside development it renders the default and nothing else.
|
|
31
|
+
*
|
|
32
|
+
* A client component: use it from client code, since the render functions
|
|
33
|
+
* cannot cross a server/client boundary as props.
|
|
34
|
+
*/
|
|
35
|
+
function VariantGroup(props) {
|
|
36
|
+
if (!VARIANTS_ENABLED) return renderVariant(props, fallbackId(props));
|
|
37
|
+
return /* @__PURE__ */ jsx(DevVariantGroup, { ...props });
|
|
38
|
+
}
|
|
39
|
+
function fallbackId({ default: preferred, variants }) {
|
|
40
|
+
if (preferred !== void 0 && preferred in variants) return preferred;
|
|
41
|
+
return Object.keys(variants)[0] ?? "";
|
|
42
|
+
}
|
|
43
|
+
function renderVariant({ variants }, id) {
|
|
44
|
+
return variants[id]?.render() ?? null;
|
|
45
|
+
}
|
|
46
|
+
const SERVER_SNAPSHOT = {
|
|
47
|
+
groups: [],
|
|
48
|
+
choices: {}
|
|
49
|
+
};
|
|
50
|
+
function getServerSnapshot() {
|
|
51
|
+
return SERVER_SNAPSHOT;
|
|
52
|
+
}
|
|
53
|
+
function DevVariantGroup(props) {
|
|
54
|
+
const { id, label, variants } = props;
|
|
55
|
+
const defaultId = fallbackId(props);
|
|
56
|
+
const snapshot = useSyncExternalStore(subscribeVariantGroups, getVariantGroupsSnapshot, getServerSnapshot);
|
|
57
|
+
const signature = Object.entries(variants).map(([key, v]) => `${key}\u0000${v.label ?? key}`).join("");
|
|
58
|
+
const info = useMemo(() => ({
|
|
59
|
+
id,
|
|
60
|
+
label: label ?? id,
|
|
61
|
+
defaultId,
|
|
62
|
+
variants: signature.split("").filter(Boolean).map((pair) => {
|
|
63
|
+
const [key = "", text = key] = pair.split("\0");
|
|
64
|
+
return {
|
|
65
|
+
id: key,
|
|
66
|
+
label: text
|
|
67
|
+
};
|
|
68
|
+
})
|
|
69
|
+
}), [
|
|
70
|
+
id,
|
|
71
|
+
label,
|
|
72
|
+
defaultId,
|
|
73
|
+
signature
|
|
74
|
+
]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const store = getVariantGroupStore();
|
|
77
|
+
store.syncSearch(window.location.search);
|
|
78
|
+
return store.register(info);
|
|
79
|
+
}, [info]);
|
|
80
|
+
return renderVariant(props, snapshot.groups.some((group) => group.id === id) ? resolveVariant(info, snapshot.choices) : defaultId);
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { VariantGroup };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { i as useVitals, n as formatVital, t as VITAL_ORDER } from "./store-CQqIIKTc.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
//#region src/plugins/vitals/vitals-panel.tsx
|
|
4
|
+
function VitalsPanel() {
|
|
5
|
+
const vitals = useVitals();
|
|
6
|
+
const rows = VITAL_ORDER.flatMap((name) => {
|
|
7
|
+
const vital = vitals[name];
|
|
8
|
+
return vital ? [vital] : [];
|
|
9
|
+
});
|
|
10
|
+
if (rows.length === 0) return /* @__PURE__ */ jsx("p", {
|
|
11
|
+
className: "empty",
|
|
12
|
+
children: "No metrics yet. LCP reports after the first interaction or tab switch."
|
|
13
|
+
});
|
|
14
|
+
return /* @__PURE__ */ jsx("table", {
|
|
15
|
+
className: "vitals",
|
|
16
|
+
children: /* @__PURE__ */ jsx("tbody", { children: rows.map((vital) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("td", {
|
|
17
|
+
className: "label",
|
|
18
|
+
children: vital.name
|
|
19
|
+
}), /* @__PURE__ */ jsxs("td", { children: [/* @__PURE__ */ jsx("span", {
|
|
20
|
+
className: "dot",
|
|
21
|
+
"data-rating": vital.rating,
|
|
22
|
+
style: {
|
|
23
|
+
display: "inline-block",
|
|
24
|
+
marginRight: 6
|
|
25
|
+
}
|
|
26
|
+
}), formatVital(vital.name, vital.value)] })] }, vital.name)) })
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { VitalsPanel, VitalsPanel as default };
|