@hansenexus/hud 0.6.0 → 0.8.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 (102) hide show
  1. package/README.md +172 -25
  2. package/dist/{a11y-B5DUaiCs.js → a11y-BGWw4jBr.js} +14 -2
  3. package/dist/{a11y-panel-p_t4eD7p.js → a11y-panel-DcfXnPHk.js} +1 -1
  4. package/dist/{access-D_ewAEJG.d.ts → access-CwPCPsv0.d.ts} +1 -1
  5. package/dist/{access-panel-CEfTr9ZI.js → access-panel-grAsMEDk.js} +1 -1
  6. package/dist/auto/runtime.d.ts +9 -9
  7. package/dist/auto.d.ts +2 -2
  8. package/dist/auto.js +5 -5
  9. package/dist/cli.js +34 -1
  10. package/dist/{data-panel-BmcHCQnM.js → data-panel-B6WPNmV6.js} +1 -1
  11. package/dist/{data-store-ChF1td_P.js → data-store-FNTQKMkG.js} +1 -1
  12. package/dist/{define-hud-CHPedaQ5.d.ts → define-hud-B0aFXrcK.d.ts} +15 -5
  13. package/dist/{design-D0kGgPoP.js → design-BIXY1-Ex.js} +45 -11
  14. package/dist/{dispatch-panel-B-xr_Giy.js → dispatch-panel-BDHgMhOk.js} +1 -1
  15. package/dist/{force-state-panel-_otVYh9i.js → force-state-panel-D5oDydLs.js} +1 -1
  16. package/dist/{handler-BpVhxEmU.js → handler-BKzaOhlJ.js} +1 -1
  17. package/dist/{handler-DtYVCZY6.d.ts → handler-BmFhaA2D.d.ts} +1 -1
  18. package/dist/icons-ByDyNq_E.js +71 -0
  19. package/dist/index-5B7foZut.d.ts +116 -0
  20. package/dist/{index-ReFbhQ9p.d.ts → index-B2KCKkN0.d.ts} +5 -0
  21. package/dist/index-B7qaEUgh.d.ts +44 -0
  22. package/dist/{index-DcH9V3cU.d.ts → index-BGFyuJyN.d.ts} +3 -0
  23. package/dist/{index-Hhh7OXzU.d.ts → index-BeqWehuh.d.ts} +44 -10
  24. package/dist/{index-DstI_ike.d.ts → index-BqKysxTq.d.ts} +5 -1
  25. package/dist/{index-DqOyNf1u.d.ts → index-D97Fnoie.d.ts} +4 -2
  26. package/dist/{index-CwfX-W87.d.ts → index-DS0yT0c-.d.ts} +3 -0
  27. package/dist/{index-BAV_1W8a.d.ts → index-DvlCkGB1.d.ts} +3 -1
  28. package/dist/index.d.ts +4 -4
  29. package/dist/index.js +1226 -256
  30. package/dist/{inspect-C9Ft8fqn.js → inspect-CSkm8tn3.js} +14 -2
  31. package/dist/{inspect-root-BkaupBMp.js → inspect-root-CmiFX0e5.js} +1 -1
  32. package/dist/navigation-CX6AXm7H.js +176 -0
  33. package/dist/next.d.ts +4 -1
  34. package/dist/next.js +12 -1
  35. package/dist/{observe-CdDnDBRP.js → observe-CBNLU148.js} +12 -2
  36. package/dist/{observe-panel-Cgp1M8oT.js → observe-panel-zU5LD-U9.js} +1 -1
  37. package/dist/obstacles-CCmRFTcZ.js +176 -0
  38. package/dist/{ops-panel-CEqDe_UT.js → ops-panel-DHhAnChL.js} +1 -1
  39. package/dist/plugins/a11y.d.ts +1 -1
  40. package/dist/plugins/a11y.js +1 -1
  41. package/dist/plugins/access/server.d.ts +3 -3
  42. package/dist/plugins/access/server.js +1 -1
  43. package/dist/plugins/access.d.ts +5 -2
  44. package/dist/plugins/access.js +18 -5
  45. package/dist/plugins/agent/server.js +2 -2
  46. package/dist/plugins/agent.d.ts +4 -2
  47. package/dist/plugins/agent.js +6 -3
  48. package/dist/plugins/capture/server.js +1 -1
  49. package/dist/plugins/capture.d.ts +2 -2
  50. package/dist/plugins/capture.js +1 -1
  51. package/dist/plugins/data/server.d.ts +1 -1
  52. package/dist/plugins/data/server.js +2 -2
  53. package/dist/plugins/data.d.ts +1 -1
  54. package/dist/plugins/data.js +30 -9
  55. package/dist/plugins/design/server.d.ts +55 -15
  56. package/dist/plugins/design/server.js +188 -123
  57. package/dist/plugins/design.d.ts +3 -3
  58. package/dist/plugins/design.js +1 -1
  59. package/dist/plugins/inspect.d.ts +1 -1
  60. package/dist/plugins/inspect.js +1 -1
  61. package/dist/plugins/observe.d.ts +1 -1
  62. package/dist/plugins/observe.js +1 -1
  63. package/dist/plugins/ops/server.d.ts +1 -1
  64. package/dist/plugins/ops/server.js +1 -1
  65. package/dist/plugins/ops.d.ts +5 -1
  66. package/dist/plugins/ops.js +16 -4
  67. package/dist/plugins/routes/server.d.ts +1 -1
  68. package/dist/plugins/routes/server.js +1 -1
  69. package/dist/plugins/routes.d.ts +3 -3
  70. package/dist/plugins/routes.js +384 -53
  71. package/dist/plugins/seo.d.ts +1 -1
  72. package/dist/plugins/seo.js +1 -1
  73. package/dist/plugins/vitals.d.ts +1 -1
  74. package/dist/plugins/vitals.js +9 -1
  75. package/dist/{plugins-DVy_vaYr.js → plugins-CcW_K7c2.js} +9 -1
  76. package/dist/{plugins-BZvDqGx5.d.ts → plugins-pL2CoWzI.d.ts} +39 -3
  77. package/dist/{poll-CjKsWZi8.js → poll-Dm0OijM4.js} +1 -1
  78. package/dist/same-origin-BHuZO1_H.js +36 -0
  79. package/dist/{seo-Dq9q_QkO.js → seo-BnnGq_vj.js} +13 -2
  80. package/dist/{seo-panel-CfiY-TnT.js → seo-panel-BThx56KM.js} +1 -1
  81. package/dist/server.d.ts +2 -2
  82. package/dist/server.js +2 -2
  83. package/dist/{sessions-panel-COvhPAzv.js → sessions-panel-MknKsTge.js} +1 -1
  84. package/dist/store.d.ts +1 -1
  85. package/dist/store.js +2 -2
  86. package/dist/{meta-C_G7MB5w.d.ts → types-Dc6JWZR7.d.ts} +6 -6
  87. package/dist/{unlock-store-4V3vR4Eg.js → unlock-store-CrGXQx1V.js} +1 -1
  88. package/dist/variant-bar-BzZ0ln-C.js +768 -0
  89. package/dist/variant-picks-Byc0hC8a.js +144 -0
  90. package/dist/variants-export-vEtZ-OGC.js +75 -0
  91. package/dist/{variants-panel-BDoSkwBJ.js → variants-panel-D23v5KIp.js} +72 -55
  92. package/dist/variants-types-BOsZ5fDz.js +65 -0
  93. package/dist/variants-types-VkW7vFZF.d.ts +139 -0
  94. package/dist/variants.d.ts +1 -1
  95. package/dist/variants.js +1 -1
  96. package/dist/vite.d.ts +2 -2
  97. package/dist/vite.js +1 -1
  98. package/package.json +1 -1
  99. package/dist/index-BnQ0dTZf.d.ts +0 -19
  100. package/dist/index-gCZBO53s.d.ts +0 -73
  101. package/dist/same-origin-BGet22CC.js +0 -21
  102. package/dist/variants-types-CcRf119M.d.ts +0 -63
@@ -1,5 +1,5 @@
1
1
  import { n as HUD_HOST_TAG } from "../../marker-uZYPOJ4M.js";
2
- import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
2
+ import { i as definePlugin } from "../../plugins-CcW_K7c2.js";
3
3
  import { n as CAPTURE_ID, t as CAPTURE_CAPABILITY } from "../../types-DIdPfjtV.js";
4
4
  //#region src/plugins/capture/server.ts
5
5
  const INSTALL_HINT = "bun add -d playwright && bunx playwright install chromium";
@@ -1,6 +1,6 @@
1
1
  import { r as GrabPayload } from "../payload-MUQ9ciER.js";
2
- import { s as HudPluginContext } from "../plugins-BZvDqGx5.js";
3
- import "../index-gCZBO53s.js";
2
+ import { l as HudPluginContext } from "../plugins-pL2CoWzI.js";
3
+ import "../index-5B7foZut.js";
4
4
  import { n as ScreenshotRequest, r as ScreenshotResponse, t as CAPTURE_CAPABILITY } from "../types-BIgGf-0C.js";
5
5
  //#region src/plugins/capture/index.d.ts
6
6
  export interface ScreenshotOptions {
@@ -1,4 +1,4 @@
1
- import { i as definePlugin, n as HudApiError } from "../plugins-DVy_vaYr.js";
1
+ import { i as definePlugin, n as HudApiError } from "../plugins-CcW_K7c2.js";
2
2
  import { n as CAPTURE_ID, t as CAPTURE_CAPABILITY } from "../types-DIdPfjtV.js";
3
3
  //#region src/plugins/capture/index.tsx
4
4
  function failure(error) {
@@ -1,4 +1,4 @@
1
- import { l as HudRouteContext } from "../../plugins-BZvDqGx5.js";
1
+ import { d as HudRouteContext } from "../../plugins-pL2CoWzI.js";
2
2
  import { _ as validateScenarios, a as HudMockRegistry, c as HudMockScenarioInfo, d as MOCK_SCENARIO_ID, f as createMockResolver, g as toMockActive, h as readMockRegistry, i as HudMockNodeStatus, l as MOCKS_COLLECTION, m as parseEndpoint, n as HudMockContext, o as HudMockResolve, p as matchEndpoint, r as HudMockMethod, s as HudMockScenario, t as HudMockActive, u as MOCKS_DOCUMENT } from "../../mocks-CA-wM2SB.js";
3
3
  import { c as HudFlagValue, g as serializeFlagOverrides, h as readFlagOverrides, l as flagCookieString, n as FLAGS_STORAGE_KEY, o as HudFlagOverride, r as FLAG_KEY, s as HudFlagScope, t as FLAGS_COOKIE } from "../../flags-DVtaJ8pQ.js";
4
4
  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, n as FLAGS_COLLECTION, o as HudAuthUser, p as RoleSwitchBody, r as FLAGS_DOCUMENT, s as HudAuthUserInfo, t as DataStateResponse, u as HudSeed } from "../../types-Dn68psVz.js";
@@ -1,7 +1,7 @@
1
- import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
1
+ import { i as definePlugin } from "../../plugins-CcW_K7c2.js";
2
2
  import { FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, flagCookieString, isFlagScope, isFlagValue, readFlagOverrides, serializeFlagOverrides } from "../../flags.js";
3
3
  import { a as matchEndpoint, c as readMockRegistry, d as validateScenarios, i as createMockResolver, l as scenarioInfo, n as MOCKS_DOCUMENT, o as nodeMockStatus, r as MOCK_SCENARIO_ID, s as parseEndpoint, t as MOCKS_COLLECTION, u as toMockActive } from "../../mocks-ESiRqk9o.js";
4
- import { t as refuseCrossSite } from "../../same-origin-BGet22CC.js";
4
+ import { t as refuseCrossSite } from "../../same-origin-BHuZO1_H.js";
5
5
  import { t as HudStoreError } from "../../types-BIkI-qN8.js";
6
6
  import { t as file } from "../../file-xdSaQ2uR.js";
7
7
  import { a as readCookie, c as timingSafeEqual } from "../../access-C7zlaqj6.js";
@@ -1,4 +1,4 @@
1
- import { i as HudMockClientStatus, n as data, r as HudMockClientOptions, t as DataOptions } from "../index-DstI_ike.js";
1
+ import { i as HudMockClientStatus, n as data, r as HudMockClientOptions, t as DataOptions } from "../index-BqKysxTq.js";
2
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
3
  import { n as HudMockWorkerModule, r as MockWorkerOptions, t as HudMockWorkerHandle } from "../msw-browser-wjaYgkB7.js";
4
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";
@@ -1,18 +1,27 @@
1
- import { i as definePlugin } from "../plugins-DVy_vaYr.js";
1
+ import { i as hudIcon } from "../icons-ByDyNq_E.js";
2
+ import { i as definePlugin } from "../plugins-CcW_K7c2.js";
2
3
  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 { a as useDataState, o as configureMockClient } from "../data-store-FNTQKMkG.js";
4
5
  import { lazy } from "react";
5
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
7
  //#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" });
8
+ function summarize(state) {
9
+ if (state.status !== "ready") return null;
11
10
  const { auth, flags, mocks } = state.data;
12
11
  const overridden = flags?.overrides.length ?? 0;
13
12
  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;
13
+ return {
14
+ who: auth ? auth.current?.label ?? "anonymous" : null,
15
+ overridden,
16
+ mocked,
17
+ busy: Boolean(auth?.current) || overridden > 0 || mocked > 0
18
+ };
19
+ }
20
+ /** The pill item: who the page is signed in as, how many flags are overridden and how many endpoints are mocked. */
21
+ function DataPill({ ctx }) {
22
+ const summary = summarize(useDataState(ctx));
23
+ if (!summary) return /* @__PURE__ */ jsx(Fragment, { children: "Data" });
24
+ const { who, overridden, mocked, busy } = summary;
16
25
  return /* @__PURE__ */ jsxs(Fragment, { children: [
17
26
  /* @__PURE__ */ jsx("span", {
18
27
  className: "dot",
@@ -23,9 +32,19 @@ function DataPill({ ctx }) {
23
32
  mocked > 0 ? ` · ${mocked} mock${mocked === 1 ? "" : "s"}` : ""
24
33
  ] });
25
34
  }
35
+ /** The rail badge: warn while anything is overridden, counting the overrides and mocks. */
36
+ function useDataBadge({ ctx }) {
37
+ const summary = summarize(useDataState(ctx));
38
+ if (!summary) return null;
39
+ const count = summary.overridden + summary.mocked;
40
+ return summary.busy ? {
41
+ tone: "warn",
42
+ ...count > 0 ? { count } : {}
43
+ } : { tone: "good" };
44
+ }
26
45
  //#endregion
27
46
  //#region src/plugins/data/index.tsx
28
- const Panel = lazy(() => import("../data-panel-BmcHCQnM.js"));
47
+ const Panel = lazy(() => import("../data-panel-B6WPNmV6.js"));
29
48
  /**
30
49
  * Role switch, feature-flag overrides, seeds and mock scenarios. The pill
31
50
  * shows who the page is signed in as, how many flags are overridden and how
@@ -43,6 +62,8 @@ function data({ mocks } = {}) {
43
62
  id: "data",
44
63
  title: "Data",
45
64
  capability: "data.write",
65
+ icon: hudIcon("database"),
66
+ badge: useDataBadge,
46
67
  pill: DataPill,
47
68
  panel: Panel
48
69
  });
@@ -1,8 +1,37 @@
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";
1
+ import { d as HudRouteContext } from "../../plugins-pL2CoWzI.js";
2
+ import { a as VariantGroupRecord, c as VariantStatus, d as toGroupRecord, f as toVariantRecord, i as VARIANTS_COLLECTION, l as VariantsListResponse, n as PickBody, o as VariantLogEntry, r as PickResponse, s as VariantRecord, t as CleanupResponse, u as recordKey } from "../../variants-types-VkW7vFZF.js";
3
3
  import { n as DispatchProvider } from "../../types-szkr2QOF.js";
4
4
  import { t as HudStore } from "../../types-DaJcsEjO.js";
5
5
  import "../../server.js";
6
+ //#region src/plugins/design/variants-export.d.ts
7
+ /** One group's decision, as `hud variants` prints it. */
8
+ interface VariantGroupExport {
9
+ group: string;
10
+ label: string;
11
+ /** The picked variant, or null while the group is open. */
12
+ pick: {
13
+ id: string;
14
+ label: string;
15
+ decidedAt?: string;
16
+ } | null;
17
+ note: string;
18
+ variants: {
19
+ id: string;
20
+ label: string;
21
+ status: string;
22
+ score?: number;
23
+ rationale?: string;
24
+ }[];
25
+ log: VariantLogEntry[];
26
+ }
27
+ interface VariantsExport {
28
+ groups: VariantGroupExport[];
29
+ }
30
+ /** Every group of the store's `variants` collection with its pick, note and log, by group id. */
31
+ export declare function readVariants(store: HudStore): Promise<VariantsExport>;
32
+ /** The decisions as Markdown, for an issue comment or an agent's context. */
33
+ export declare function formatVariantsMarkdown({ groups }: VariantsExport): string;
34
+ //#endregion
6
35
  //#region src/plugins/design/server.d.ts
7
36
  export interface VariantDecision {
8
37
  group: string;
@@ -16,27 +45,35 @@ export interface VariantDecision {
16
45
  label: string;
17
46
  }[];
18
47
  decidedAt: string;
48
+ /** The owner's note on the pick; empty when there is none. */
49
+ note?: string;
19
50
  }
20
51
  export interface VariantsServerOptions {
21
- /** Where scores and decisions live. `file()` keeps them in `.hud/variants.json`. */
52
+ /** Where scores, picks and notes live. `file()` keeps them in `.hud/variants.json`. */
22
53
  store: HudStore;
23
54
  /**
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.
55
+ * The dispatch seam: "Queue cleanup" hands the brief for a picked group to
56
+ * it (`claudeCode()`, `hermes()` from `@hansenexus/hud/plugins/agent/server`,
57
+ * or anything with the same shape). A pick never reaches it.
27
58
  */
28
59
  dispatch?: DispatchProvider;
29
60
  /** The brief's text. Default: `cleanupBrief`. */
30
61
  brief?: (decision: VariantDecision) => string;
31
62
  }
32
- /** The cleanup brief Decide hands the dispatch seam. */
33
- export declare function cleanupBrief({ group, label, winner, losers, decidedAt }: VariantDecision): string;
63
+ /** The cleanup brief "Queue cleanup" hands the dispatch seam. */
64
+ export declare function cleanupBrief({ group, label, winner, losers, decidedAt, note }: VariantDecision): string;
34
65
  /**
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.
66
+ * Server half of `variants()`.
67
+ *
68
+ * - `GET /` lists every record of the store's `variants` collection, with the
69
+ * groups' notes and logs.
70
+ * - `POST /:group/pick` records a pick and a note through the storage seam
71
+ * (`status` and `decidedAt` on the variants, note and log on the group).
72
+ * It never touches the dispatch seam.
73
+ * - `POST /:group/cleanup` queues the cleanup brief of a picked group through
74
+ * the dispatch seam; the panel's "Queue cleanup" button is the only caller.
75
+ *
76
+ * Carries `variants.decide`, which only development grants by default.
40
77
  */
41
78
  export declare function variantsServer({ store, dispatch, brief }: VariantsServerOptions): {
42
79
  readonly id: "variants";
@@ -45,10 +82,13 @@ export declare function variantsServer({ store, dispatch, brief }: VariantsServe
45
82
  readonly "/": {
46
83
  GET: () => Promise<Response>;
47
84
  };
48
- readonly "/:group/decide": {
85
+ readonly "/:group/pick": {
86
+ readonly POST: (request: Request, { params }: HudRouteContext) => Promise<Response>;
87
+ };
88
+ readonly "/:group/cleanup": {
49
89
  readonly POST: (request: Request, { params }: HudRouteContext) => Promise<Response>;
50
90
  };
51
91
  };
52
92
  };
53
93
  //#endregion
54
- export { type DecideBody, type DecideResponse, VARIANTS_COLLECTION, type VariantRecord, type VariantStatus, type VariantsListResponse, recordKey, toVariantRecord };
94
+ export { type CleanupResponse, type PickBody, type PickResponse, VARIANTS_COLLECTION, type VariantGroupExport, type VariantGroupRecord, type VariantLogEntry, type VariantRecord, type VariantStatus, type VariantsExport, type VariantsListResponse, recordKey, toGroupRecord, toVariantRecord };
@@ -1,45 +1,8 @@
1
- import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
2
- import { t as refuseCrossSite } from "../../same-origin-BGet22CC.js";
1
+ import { i as definePlugin } from "../../plugins-CcW_K7c2.js";
2
+ import { t as refuseCrossSite } from "../../same-origin-BHuZO1_H.js";
3
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
4
+ import { a as toGroupRecord, i as recordKey, n as VARIANTS_COLLECTION, o as toVariantRecord, r as pickedRecord } from "../../variants-types-BOsZ5fDz.js";
5
+ import { n as readVariants, t as formatVariantsMarkdown } from "../../variants-export-vEtZ-OGC.js";
43
6
  //#region src/plugins/design/server.ts
44
7
  const NO_STORE = { "cache-control": "no-store" };
45
8
  function isRecord(value) {
@@ -59,41 +22,162 @@ function failed(error, what) {
59
22
  error: `${what} failed`
60
23
  }, { status: 500 });
61
24
  }
62
- function parseDecide(value) {
63
- if (!isRecord(value) || typeof value.id !== "string" || !value.id) return null;
64
- const body = { id: value.id };
25
+ const ID_MAX = 100;
26
+ const BODY_MAX = 65536;
27
+ const isId = (value) => typeof value === "string" && value.length > 0 && value.length <= ID_MAX;
28
+ function parsePick(value) {
29
+ if (!isRecord(value)) return null;
30
+ const body = {};
31
+ if (value.id === null || isId(value.id)) body.id = value.id;
32
+ else if (value.id !== void 0) return null;
33
+ if (typeof value.note === "string") body.note = value.note.trim();
34
+ else if (value.note !== void 0) return null;
35
+ if (body.note !== void 0 && body.note.length > 4e3) return null;
36
+ if (body.id === void 0 && body.note === void 0) return null;
65
37
  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 ? [{
38
+ if (Array.isArray(value.variants)) body.variants = value.variants.flatMap((v) => isRecord(v) && isId(v.id) ? [{
67
39
  id: v.id,
68
40
  label: typeof v.label === "string" ? v.label : v.id
69
41
  }] : []);
70
42
  return body;
71
43
  }
44
+ async function readJson(request) {
45
+ const text = await request.text().catch(() => "");
46
+ if (text.length > BODY_MAX) return null;
47
+ try {
48
+ return JSON.parse(text);
49
+ } catch {
50
+ return null;
51
+ }
52
+ }
53
+ /** A group id the store can key and a `<group>:<id>` record cannot collide with. */
54
+ const isGroup = (group) => isId(group) && !group.includes(":");
55
+ const invalid = (error, status = 400) => Response.json({
56
+ ok: false,
57
+ error
58
+ }, { status });
72
59
  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 }) {
60
+ /** The cleanup brief "Queue cleanup" hands the dispatch seam. */
61
+ function cleanupBrief({ group, label, winner, losers, decidedAt, note }) {
75
62
  const name = label === group ? `"${group}"` : `"${group}" (${label})`;
76
63
  const remove = losers.length > 0 ? `remove ${losers.map(quote).join(", ")}` : "there are no other variants";
77
64
  return [
78
- `Variant group ${name} was decided on ${decidedAt}: keep ${quote(winner)}, ${remove}.`,
65
+ `Variant group ${name} was decided on ${decidedAt || "an unknown date"}: keep ${quote(winner)}, ${remove}.`,
79
66
  "",
67
+ ...note ? [`Note on the pick: ${note}`, ""] : [],
80
68
  `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
69
  ].join("\n");
82
70
  }
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] : [];
71
+ async function readAll(store) {
72
+ const entries = await store.list(VARIANTS_COLLECTION);
73
+ const stored = {
74
+ records: [],
75
+ groups: []
76
+ };
77
+ for (const { id, value } of entries) {
78
+ const record = toVariantRecord(id, value);
79
+ if (record) stored.records.push(record);
80
+ else {
81
+ const group = toGroupRecord(id, value);
82
+ if (group) stored.groups.push(group);
83
+ }
84
+ }
85
+ return stored;
86
+ }
87
+ /** Writes the pick onto the group's variant records: winner, rejected, or all open again. */
88
+ async function writePick(store, group, id, records, variants, at) {
89
+ const byId = new Map(records.map((r) => [r.id, r]));
90
+ const known = /* @__PURE__ */ new Map();
91
+ for (const r of records) known.set(r.id, r.label ?? r.id);
92
+ for (const v of variants ?? []) known.set(v.id, v.label);
93
+ if (id !== null && !known.has(id)) known.set(id, id);
94
+ for (const [variant, label] of known) {
95
+ const { decidedAt: _previous, ...rest } = byId.get(variant) ?? {
96
+ group,
97
+ id: variant
98
+ };
99
+ const record = {
100
+ ...rest,
101
+ group,
102
+ id: variant,
103
+ label,
104
+ status: "open"
105
+ };
106
+ if (id !== null) record.status = variant === id ? "decided" : "rejected";
107
+ if (variant === id) record.decidedAt = at;
108
+ await store.set(VARIANTS_COLLECTION, recordKey(group, variant), { ...record });
109
+ }
110
+ }
111
+ /** Applies a pick: variant records, then the group's note and log. Reads and writes the store only. */
112
+ async function applyPick(store, group, body) {
113
+ const stored = await readAll(store);
114
+ const records = stored.records.filter((r) => r.group === group);
115
+ const previous = stored.groups.find((g) => g.group === group);
116
+ const current = pickedRecord(records, group);
117
+ const before = {
118
+ pick: current?.id ?? null,
119
+ note: previous?.note ?? ""
120
+ };
121
+ const pick = body.id === void 0 ? before.pick : body.id;
122
+ const note = body.note ?? before.note;
123
+ if (pick === before.pick && note === before.note) {
124
+ const response = {
125
+ ok: true,
126
+ group,
127
+ pick,
128
+ note,
129
+ changed: false
130
+ };
131
+ if (current?.decidedAt) response.decidedAt = current.decidedAt;
132
+ return response;
133
+ }
134
+ const at = (/* @__PURE__ */ new Date()).toISOString();
135
+ if (pick !== before.pick) await writePick(store, group, pick, records, body.variants, at);
136
+ const label = body.label ?? previous?.label;
137
+ await store.set(VARIANTS_COLLECTION, group, {
138
+ ...label === void 0 ? {} : { label },
139
+ note,
140
+ log: [...previous?.log ?? [], {
141
+ at,
142
+ pick,
143
+ note
144
+ }].map((entry) => ({ ...entry }))
87
145
  });
146
+ const response = {
147
+ ok: true,
148
+ group,
149
+ pick,
150
+ note,
151
+ changed: true
152
+ };
153
+ const decidedAt = pick === null ? void 0 : pick === before.pick ? current?.decidedAt : at;
154
+ if (decidedAt) response.decidedAt = decidedAt;
155
+ return response;
88
156
  }
89
157
  /**
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.
158
+ * Server half of `variants()`.
159
+ *
160
+ * - `GET /` lists every record of the store's `variants` collection, with the
161
+ * groups' notes and logs.
162
+ * - `POST /:group/pick` records a pick and a note through the storage seam
163
+ * (`status` and `decidedAt` on the variants, note and log on the group).
164
+ * It never touches the dispatch seam.
165
+ * - `POST /:group/cleanup` queues the cleanup brief of a picked group through
166
+ * the dispatch seam; the panel's "Queue cleanup" button is the only caller.
167
+ *
168
+ * Carries `variants.decide`, which only development grants by default.
95
169
  */
96
170
  function variantsServer({ store, dispatch, brief = cleanupBrief }) {
171
+ const queues = /* @__PURE__ */ new Map();
172
+ const serial = (group, run) => {
173
+ const result = (queues.get(group) ?? Promise.resolve()).then(run, run);
174
+ const settled = result.catch(() => {});
175
+ queues.set(group, settled);
176
+ settled.then(() => {
177
+ if (queues.get(group) === settled) queues.delete(group);
178
+ });
179
+ return result;
180
+ };
97
181
  return definePlugin({
98
182
  id: "variants",
99
183
  capability: "variants.decide",
@@ -102,97 +186,78 @@ function variantsServer({ store, dispatch, brief = cleanupBrief }) {
102
186
  try {
103
187
  const body = {
104
188
  ok: true,
105
- records: await listRecords(store)
189
+ ...await readAll(store),
190
+ dispatch: dispatch?.id ?? null
106
191
  };
107
192
  return Response.json(body, { headers: NO_STORE });
108
193
  } catch (error) {
109
194
  return failed(error, "list");
110
195
  }
111
196
  } },
112
- "/:group/decide": { POST: async (request, { params }) => {
197
+ "/:group/pick": { POST: async (request, { params }) => {
113
198
  const refusal = refuseCrossSite(request);
114
199
  if (refusal) return refusal;
115
200
  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 });
201
+ const body = parsePick(await readJson(request));
202
+ if (!isGroup(group) || !body) return invalid("invalid pick");
121
203
  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,
204
+ return Response.json(await serial(group, () => applyPick(store, group, body)), { headers: NO_STORE });
205
+ } catch (error) {
206
+ return failed(error, "pick");
207
+ }
208
+ } },
209
+ "/:group/cleanup": { POST: async (request, { params }) => {
210
+ const refusal = refuseCrossSite(request);
211
+ if (refusal) return refusal;
212
+ const group = params.group ?? "";
213
+ if (!isGroup(group)) return invalid("invalid group");
214
+ if (!dispatch) return invalid("no dispatch provider configured", 409);
215
+ try {
216
+ const stored = await readAll(store);
217
+ const records = stored.records.filter((r) => r.group === group);
218
+ const winner = pickedRecord(records, group);
219
+ if (!winner) return invalid(`nothing is picked in "${group}"`, 409);
220
+ const named = (r) => ({
221
+ id: r.id,
222
+ label: r.label ?? r.id
223
+ });
224
+ const prompt = brief({
166
225
  group,
167
- id: body.id,
168
- decidedAt,
169
- queued: null
170
- };
171
- if (dispatch) try {
226
+ label: stored.groups.find((g) => g.group === group)?.label ?? group,
227
+ winner: named(winner),
228
+ losers: records.filter((r) => r.id !== winner.id).map(named),
229
+ decidedAt: winner.decidedAt ?? "",
230
+ note: stored.groups.find((g) => g.group === group)?.note ?? ""
231
+ });
232
+ try {
172
233
  const status = await dispatch.status?.() ?? { available: true };
173
234
  if (!status.available) throw new Error(status.reason);
174
- const prompt = brief(decision);
175
235
  const run = await dispatch.dispatch({
176
- note: `Clean up variant group "${group}": keep "${body.id}"`,
236
+ note: `Clean up variant group "${group}": keep "${winner.id}"`,
177
237
  payload: null,
178
238
  hints: [],
179
239
  prompt
180
240
  });
181
- response.queued = {
182
- target: dispatch.id,
183
- runId: run.runId
241
+ const response = {
242
+ ok: true,
243
+ group,
244
+ id: winner.id,
245
+ queued: {
246
+ target: dispatch.id,
247
+ runId: run.runId,
248
+ ...run.detail ? { detail: run.detail } : {}
249
+ }
184
250
  };
185
- if (run.detail) response.queued.detail = run.detail;
251
+ return Response.json(response);
186
252
  } catch (error) {
187
- response.queueError = message(error);
253
+ return invalid(`brief not queued: ${message(error)}`, 502);
188
254
  }
189
- return Response.json(response);
190
255
  } catch (error) {
191
- return failed(error, "decide");
256
+ return failed(error, "cleanup");
192
257
  }
193
258
  } }
194
259
  }
195
260
  });
196
261
  }
197
262
  //#endregion
198
- export { VARIANTS_COLLECTION, cleanupBrief, recordKey, toVariantRecord, variantsServer };
263
+ export { VARIANTS_COLLECTION, cleanupBrief, formatVariantsMarkdown, readVariants, recordKey, toGroupRecord, toVariantRecord, variantsServer };
@@ -1,5 +1,5 @@
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";
1
+ import { a as HudGenerateRequest, c as HudVariantsAdapter, d as HudTokenGroup, f as HudTokenScope, i as variants, l as HudVariantPage, n as forceState, o as HudGenerateResult, p as HudTokensAdapter, r as tokens, s as HudVariantCategory, t as HudVariantsOptions, u as HudTokenDescriptor } from "../index-BeqWehuh.js";
2
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";
3
+ import { a as VariantGroupRecord, c as VariantStatus, l as VariantsListResponse, n as PickBody, o as VariantLogEntry, r as PickResponse, s as VariantRecord, t as CleanupResponse } from "../variants-types-VkW7vFZF.js";
4
4
  import { i as ForcedState, n as FORCE_STATE_MARKER, r as FORCE_STATE_PARAM, t as FORCED_STATES } from "../force-state-CCqoTfVB.js";
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 };
5
+ export { type CleanupResponse, 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 HudVariantPage, type HudVariantsAdapter, HudVariantsOptions, type PickBody, type PickResponse, VARIANT_MARKER, VARIANT_PARAM, type VariantGroupInfo, type VariantGroupRecord, type VariantLogEntry, type VariantOption, type VariantRecord, type VariantStatus, type VariantsListResponse, forceState, formatVariantParam, parseVariantParam, tokens, variants };
@@ -1,4 +1,4 @@
1
1
  import { n as FORCE_STATE_MARKER, r as FORCE_STATE_PARAM, t as FORCED_STATES } from "../force-state-BaqWsmrf.js";
2
- import { n as tokens, r as variants, t as forceState } from "../design-D0kGgPoP.js";
2
+ import { n as tokens, r as variants, t as forceState } from "../design-BIXY1-Ex.js";
3
3
  import { n as VARIANT_PARAM, o as parseVariantParam, r as formatVariantParam, t as VARIANT_MARKER } from "../variant-groups-TIfO3NIj.js";
4
4
  export { FORCED_STATES, FORCE_STATE_MARKER, FORCE_STATE_PARAM, VARIANT_MARKER, VARIANT_PARAM, forceState, formatVariantParam, parseVariantParam, tokens, variants };
@@ -1,4 +1,4 @@
1
1
  import { i as requestBuffer, n as RequestPayload, r as RequestTransport, t as InspectRequest } from "../requests-CJrUf465.js";
2
2
  import { t as InspectAdapter } from "../adapter-BYoxPYTI.js";
3
- import { a as replay, c as isSensitiveKey, d as redactUrl, i as InspectFilter, l as redactBody, n as InspectOptions, o as replayBlocker, r as inspect, s as REDACTED, t as INSPECT_CAPABILITY, u as redactHeaders } from "../index-CwfX-W87.js";
3
+ import { a as replay, c as isSensitiveKey, d as redactUrl, i as InspectFilter, l as redactBody, n as InspectOptions, o as replayBlocker, r as inspect, s as REDACTED, t as INSPECT_CAPABILITY, u as redactHeaders } from "../index-DS0yT0c-.js";
4
4
  export { INSPECT_CAPABILITY, type InspectAdapter, type InspectFilter, InspectOptions, type InspectRequest, REDACTED, type RequestPayload, type RequestTransport, inspect, isSensitiveKey, redactBody, redactHeaders, redactUrl, replay, replayBlocker, requestBuffer };
@@ -1,3 +1,3 @@
1
1
  import { d as REDACTED, f as isSensitiveKey, h as redactUrl, l as requestBuffer, m as redactHeaders, p as redactBody } from "../requests-BwD6MKEq.js";
2
- import { i as replayBlocker, n as inspect, r as replay, t as INSPECT_CAPABILITY } from "../inspect-C9Ft8fqn.js";
2
+ import { i as replayBlocker, n as inspect, r as replay, t as INSPECT_CAPABILITY } from "../inspect-CSkm8tn3.js";
3
3
  export { INSPECT_CAPABILITY, REDACTED, inspect, isSensitiveKey, redactBody, redactHeaders, redactUrl, replay, replayBlocker, requestBuffer };
@@ -1,4 +1,4 @@
1
1
  import { a as CaptureOptions, n as RequestPayload, r as RequestTransport, t as InspectRequest } from "../requests-CJrUf465.js";
2
2
  import { n as CaptureKind, t as CaptureEntry } from "../capture-buffer-Bbbo6omF.js";
3
- import { n as observe, r as HudUserInfo, t as ObserveOptions } from "../index-BAV_1W8a.js";
3
+ import { n as observe, r as HudUserInfo, t as ObserveOptions } from "../index-DvlCkGB1.js";
4
4
  export { type CaptureEntry, type CaptureKind, type CaptureOptions, type HudUserInfo, type InspectRequest, ObserveOptions, type RequestPayload, type RequestTransport, observe };
@@ -1,2 +1,2 @@
1
- import { t as observe } from "../observe-CdDnDBRP.js";
1
+ import { t as observe } from "../observe-CBNLU148.js";
2
2
  export { observe };