@hansenexus/hud 0.7.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.
- package/README.md +111 -14
- package/dist/{access-Bc709qpl.d.ts → access-CwPCPsv0.d.ts} +1 -1
- package/dist/auto/runtime.d.ts +9 -9
- package/dist/auto.d.ts +2 -2
- package/dist/auto.js +1 -1
- package/dist/cli.js +34 -1
- package/dist/{define-hud-DTv3njuU.d.ts → define-hud-B0aFXrcK.d.ts} +1 -1
- package/dist/{design-BXG1a4we.js → design-BIXY1-Ex.js} +26 -8
- package/dist/{force-state-panel-mu-txJnA.js → force-state-panel-D5oDydLs.js} +1 -1
- package/dist/{handler-DMzSTqyG.d.ts → handler-BmFhaA2D.d.ts} +1 -1
- package/dist/{index-C3wzZS3o.d.ts → index-5B7foZut.d.ts} +2 -2
- package/dist/{index-D-hI-DRJ.d.ts → index-B2KCKkN0.d.ts} +1 -1
- package/dist/index-B7qaEUgh.d.ts +44 -0
- package/dist/{index-CQXiuMZQ.d.ts → index-BGFyuJyN.d.ts} +1 -1
- package/dist/{index-Caohnz3B.d.ts → index-BeqWehuh.d.ts} +38 -10
- package/dist/{index-BJJoAXJ2.d.ts → index-BqKysxTq.d.ts} +1 -1
- package/dist/{index-DLCSLWW4.d.ts → index-D97Fnoie.d.ts} +2 -2
- package/dist/{index-BR5OB7DO.d.ts → index-DS0yT0c-.d.ts} +1 -1
- package/dist/{index-BNoPbSYD.d.ts → index-DvlCkGB1.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +45 -196
- package/dist/navigation-CX6AXm7H.js +176 -0
- package/dist/next.d.ts +4 -1
- package/dist/next.js +12 -1
- package/dist/obstacles-CCmRFTcZ.js +176 -0
- package/dist/plugins/a11y.d.ts +1 -1
- package/dist/plugins/access/server.d.ts +3 -3
- package/dist/plugins/access.d.ts +2 -2
- package/dist/plugins/agent/server.js +1 -1
- package/dist/plugins/agent.d.ts +2 -2
- package/dist/plugins/capture.d.ts +2 -2
- package/dist/plugins/data/server.d.ts +1 -1
- package/dist/plugins/data/server.js +1 -1
- package/dist/plugins/data.d.ts +1 -1
- package/dist/plugins/design/server.d.ts +55 -15
- package/dist/plugins/design/server.js +187 -122
- package/dist/plugins/design.d.ts +3 -3
- package/dist/plugins/design.js +1 -1
- package/dist/plugins/inspect.d.ts +1 -1
- package/dist/plugins/observe.d.ts +1 -1
- package/dist/plugins/ops/server.d.ts +1 -1
- package/dist/plugins/ops.d.ts +1 -1
- package/dist/plugins/routes/server.d.ts +1 -1
- package/dist/plugins/routes.d.ts +3 -3
- package/dist/plugins/routes.js +381 -52
- package/dist/plugins/seo.d.ts +1 -1
- package/dist/plugins/vitals.d.ts +1 -1
- package/dist/{plugins-BZT-1LBe.d.ts → plugins-pL2CoWzI.d.ts} +7 -0
- package/dist/same-origin-BHuZO1_H.js +36 -0
- package/dist/server.d.ts +2 -2
- package/dist/store.d.ts +1 -1
- package/dist/store.js +1 -1
- package/dist/{meta-C_G7MB5w.d.ts → types-Dc6JWZR7.d.ts} +6 -6
- package/dist/variant-bar-BzZ0ln-C.js +768 -0
- package/dist/variant-picks-Byc0hC8a.js +144 -0
- package/dist/variants-export-vEtZ-OGC.js +75 -0
- package/dist/{variants-panel-B6zWcknV.js → variants-panel-D23v5KIp.js} +71 -54
- package/dist/variants-types-BOsZ5fDz.js +65 -0
- package/dist/variants-types-VkW7vFZF.d.ts +139 -0
- package/dist/variants.d.ts +1 -1
- package/dist/variants.js +1 -1
- package/dist/vite.d.ts +2 -2
- package/package.json +1 -1
- package/dist/index-B1vHAY9p.d.ts +0 -20
- package/dist/same-origin-BGet22CC.js +0 -21
- package/dist/variants-types-CcRf119M.d.ts +0 -63
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { n as HudApiError } from "./plugins-CcW_K7c2.js";
|
|
2
|
+
import { r as pickedRecord } from "./variants-types-BOsZ5fDz.js";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
//#region src/plugins/design/variant-picks.ts
|
|
5
|
+
const NO_PICK = {
|
|
6
|
+
pick: null,
|
|
7
|
+
note: ""
|
|
8
|
+
};
|
|
9
|
+
const NO_SERVER = "Picks need variantsServer() in the HUD route";
|
|
10
|
+
/** What the server said, else the status: "403: cross-site request refused". */
|
|
11
|
+
function apiErrorText(error, fallback) {
|
|
12
|
+
if (error instanceof HudApiError) {
|
|
13
|
+
const body = error.body;
|
|
14
|
+
const detail = typeof body === "object" && body !== null && "error" in body && typeof body.error === "string" ? body.error : "";
|
|
15
|
+
return detail ? `${error.status}: ${detail}` : `status ${error.status}`;
|
|
16
|
+
}
|
|
17
|
+
return error instanceof Error ? error.message : fallback;
|
|
18
|
+
}
|
|
19
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
20
|
+
/** Tells the bar and the Variants panel about each other's writes. */
|
|
21
|
+
function announcePicks(source) {
|
|
22
|
+
for (const listener of listeners) listener(source);
|
|
23
|
+
}
|
|
24
|
+
function subscribePicks(listener) {
|
|
25
|
+
listeners.add(listener);
|
|
26
|
+
return () => {
|
|
27
|
+
listeners.delete(listener);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function toPicks({ records, groups = [] }) {
|
|
31
|
+
const picks = {};
|
|
32
|
+
for (const group of /* @__PURE__ */ new Set([...records.map((r) => r.group), ...groups.map((g) => g.group)])) picks[group] = {
|
|
33
|
+
pick: pickedRecord(records, group)?.id ?? null,
|
|
34
|
+
note: groups.find((g) => g.group === group)?.note ?? ""
|
|
35
|
+
};
|
|
36
|
+
return picks;
|
|
37
|
+
}
|
|
38
|
+
/** Records a change on the server. Nothing is dispatched; see `variantsServer()`. */
|
|
39
|
+
function postPick(ctx, group, change) {
|
|
40
|
+
const body = {
|
|
41
|
+
label: group.label,
|
|
42
|
+
variants: group.variants.map(({ id, label }) => ({
|
|
43
|
+
id,
|
|
44
|
+
label
|
|
45
|
+
}))
|
|
46
|
+
};
|
|
47
|
+
if (change.pick !== void 0) body.id = change.pick;
|
|
48
|
+
if (change.note !== void 0) body.note = change.note;
|
|
49
|
+
return ctx.api(`/${encodeURIComponent(group.id)}/pick`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: { "content-type": "application/json" },
|
|
52
|
+
body: JSON.stringify(body),
|
|
53
|
+
keepalive: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The recorded picks, shown at once and saved in order. A save that fails
|
|
58
|
+
* puts the last recorded state back and says why. Picks are read again when the
|
|
59
|
+
* window gets focus: an agent or a second tab may have written.
|
|
60
|
+
*/
|
|
61
|
+
function usePicks(ctx) {
|
|
62
|
+
const [byGroup, setByGroup] = useState({});
|
|
63
|
+
const [error, setError] = useState(null);
|
|
64
|
+
/** What the server last said: a failed save falls back to it. */
|
|
65
|
+
const confirmed = useRef({});
|
|
66
|
+
const pending = useRef(0);
|
|
67
|
+
const chain = useRef(Promise.resolve());
|
|
68
|
+
const self = useRef({});
|
|
69
|
+
const live = useRef(true);
|
|
70
|
+
const load = useCallback(async () => {
|
|
71
|
+
try {
|
|
72
|
+
const body = await ctx.api("/");
|
|
73
|
+
if (!live.current || pending.current > 0) return true;
|
|
74
|
+
confirmed.current = toPicks(body);
|
|
75
|
+
setByGroup(confirmed.current);
|
|
76
|
+
return true;
|
|
77
|
+
} catch (failure) {
|
|
78
|
+
const missing = failure instanceof HudApiError && (failure.status === 404 || failure.status === 403);
|
|
79
|
+
if (live.current) setError(missing ? NO_SERVER : `Picks not loaded: ${apiErrorText(failure, "no answer")}`);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}, [ctx]);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
live.current = true;
|
|
85
|
+
const reload = () => {
|
|
86
|
+
if (pending.current > 0) return;
|
|
87
|
+
load().then((ok) => {
|
|
88
|
+
if (ok && live.current) setError(null);
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
reload();
|
|
92
|
+
window.addEventListener("focus", reload);
|
|
93
|
+
const unsubscribe = subscribePicks((source) => {
|
|
94
|
+
if (source !== self.current) reload();
|
|
95
|
+
});
|
|
96
|
+
return () => {
|
|
97
|
+
live.current = false;
|
|
98
|
+
window.removeEventListener("focus", reload);
|
|
99
|
+
unsubscribe();
|
|
100
|
+
};
|
|
101
|
+
}, [load]);
|
|
102
|
+
return {
|
|
103
|
+
byGroup,
|
|
104
|
+
error,
|
|
105
|
+
save: useCallback((group, change) => {
|
|
106
|
+
setByGroup((previous) => {
|
|
107
|
+
const before = previous[group.id] ?? NO_PICK;
|
|
108
|
+
const next = {
|
|
109
|
+
pick: change.pick === void 0 ? before.pick : change.pick,
|
|
110
|
+
note: change.note ?? before.note
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
...previous,
|
|
114
|
+
[group.id]: next
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
pending.current += 1;
|
|
118
|
+
chain.current = chain.current.then(async () => {
|
|
119
|
+
let failure = null;
|
|
120
|
+
try {
|
|
121
|
+
const { pick, note } = await postPick(ctx, group, change);
|
|
122
|
+
confirmed.current = {
|
|
123
|
+
...confirmed.current,
|
|
124
|
+
[group.id]: {
|
|
125
|
+
pick,
|
|
126
|
+
note
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
} catch (reason) {
|
|
130
|
+
failure = `Not saved: ${apiErrorText(reason, "dev server unreachable")}`;
|
|
131
|
+
}
|
|
132
|
+
pending.current -= 1;
|
|
133
|
+
announcePicks(self.current);
|
|
134
|
+
if (!live.current) return;
|
|
135
|
+
if (failure) {
|
|
136
|
+
setByGroup(confirmed.current);
|
|
137
|
+
setError(failure);
|
|
138
|
+
} else if (pending.current === 0) setError(null);
|
|
139
|
+
});
|
|
140
|
+
}, [ctx])
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
export { subscribePicks as a, postPick as i, announcePicks as n, usePicks as o, apiErrorText as r, NO_PICK as t };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { a as toGroupRecord, n as VARIANTS_COLLECTION, o as toVariantRecord } from "./variants-types-BOsZ5fDz.js";
|
|
2
|
+
//#region src/plugins/design/variants-export.ts
|
|
3
|
+
function toExport(group, records, meta) {
|
|
4
|
+
const winner = records.find((record) => record.status === "decided");
|
|
5
|
+
return {
|
|
6
|
+
group,
|
|
7
|
+
label: meta?.label ?? group,
|
|
8
|
+
pick: winner ? {
|
|
9
|
+
id: winner.id,
|
|
10
|
+
label: winner.label ?? winner.id,
|
|
11
|
+
...winner.decidedAt ? { decidedAt: winner.decidedAt } : {}
|
|
12
|
+
} : null,
|
|
13
|
+
note: meta?.note ?? "",
|
|
14
|
+
variants: records.map((record) => ({
|
|
15
|
+
id: record.id,
|
|
16
|
+
label: record.label ?? record.id,
|
|
17
|
+
status: record.status ?? "open",
|
|
18
|
+
...record.score === void 0 ? {} : { score: record.score },
|
|
19
|
+
...record.rationale === void 0 ? {} : { rationale: record.rationale }
|
|
20
|
+
})),
|
|
21
|
+
log: meta?.log ?? []
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Every group of the store's `variants` collection with its pick, note and log, by group id. */
|
|
25
|
+
async function readVariants(store) {
|
|
26
|
+
const records = /* @__PURE__ */ new Map();
|
|
27
|
+
const metas = /* @__PURE__ */ new Map();
|
|
28
|
+
for (const { id, value } of await store.list(VARIANTS_COLLECTION)) {
|
|
29
|
+
const record = toVariantRecord(id, value);
|
|
30
|
+
if (record) {
|
|
31
|
+
records.set(record.group, [...records.get(record.group) ?? [], record]);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const meta = toGroupRecord(id, value);
|
|
35
|
+
if (meta) metas.set(meta.group, meta);
|
|
36
|
+
}
|
|
37
|
+
return { groups: [.../* @__PURE__ */ new Set([...records.keys(), ...metas.keys()])].sort().map((group) => toExport(group, records.get(group) ?? [], metas.get(group))) };
|
|
38
|
+
}
|
|
39
|
+
/** Text in a Markdown line: one line, with no characters that would break a list or a table. */
|
|
40
|
+
const inline = (text) => text.replace(/\s+/g, " ").trim();
|
|
41
|
+
const named = (variant) => variant.label === variant.id ? `\`${variant.id}\`` : `\`${variant.id}\` (${inline(variant.label)})`;
|
|
42
|
+
function logLine(entry) {
|
|
43
|
+
const pick = entry.pick === null ? "no pick" : `picked \`${entry.pick}\``;
|
|
44
|
+
return ` - ${entry.at}: ${pick}${entry.note ? `, note: ${inline(entry.note)}` : ""}`;
|
|
45
|
+
}
|
|
46
|
+
function formatGroup(group) {
|
|
47
|
+
const { pick } = group;
|
|
48
|
+
const title = group.label === group.group ? group.group : `${inline(group.label)} (${group.group})`;
|
|
49
|
+
const others = group.variants.filter((variant) => variant.id !== pick?.id);
|
|
50
|
+
return [
|
|
51
|
+
`## ${title}`,
|
|
52
|
+
"",
|
|
53
|
+
pick ? `- Pick: ${named(pick)}${pick.decidedAt ? `, ${pick.decidedAt}` : ""}` : "- Pick: none yet",
|
|
54
|
+
...others.length > 0 ? [`- ${pick ? "Not picked" : "Variants"}: ${others.map(named).join(", ")}`] : [],
|
|
55
|
+
...group.note ? [
|
|
56
|
+
"- Note:",
|
|
57
|
+
"",
|
|
58
|
+
...group.note.split("\n").map((line) => ` > ${line}`.trimEnd()),
|
|
59
|
+
""
|
|
60
|
+
] : [],
|
|
61
|
+
...group.log.length > 0 ? ["- Log:", ...group.log.map(logLine)] : []
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
/** The decisions as Markdown, for an issue comment or an agent's context. */
|
|
65
|
+
function formatVariantsMarkdown({ groups }) {
|
|
66
|
+
if (groups.length === 0) return "# Design variants\n\nNo picks, notes or scores recorded.";
|
|
67
|
+
return [
|
|
68
|
+
"# Design variants",
|
|
69
|
+
"",
|
|
70
|
+
`${groups.filter((group) => group.pick).length} of ${groups.length} groups picked.`,
|
|
71
|
+
...groups.flatMap((group) => ["", ...formatGroup(group)])
|
|
72
|
+
].join("\n");
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { readVariants as n, formatVariantsMarkdown as t };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { n as HudApiError } from "./plugins-CcW_K7c2.js";
|
|
2
2
|
import { a as getVariantGroupsSnapshot, c as subscribeVariantGroups, i as getVariantGroupStore, s as resolveVariant } from "./variant-groups-TIfO3NIj.js";
|
|
3
|
+
import { r as pickedRecord } from "./variants-types-BOsZ5fDz.js";
|
|
3
4
|
import { t as DESIGN_CSS } from "./styles-DKU_P8MH.js";
|
|
5
|
+
import { a as subscribePicks, i as postPick, n as announcePicks, r as apiErrorText } from "./variant-picks-Byc0hC8a.js";
|
|
4
6
|
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
5
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
8
|
//#region src/plugins/design/variants-panel.tsx
|
|
@@ -54,7 +56,9 @@ function useRecords(ctx) {
|
|
|
54
56
|
};
|
|
55
57
|
ctx.api("/").then((body) => settle({
|
|
56
58
|
state: "ready",
|
|
57
|
-
records: body.records ?? []
|
|
59
|
+
records: body.records ?? [],
|
|
60
|
+
notes: Object.fromEntries((body.groups ?? []).map((g) => [g.group, g.note])),
|
|
61
|
+
dispatch: body.dispatch ?? null
|
|
58
62
|
}), (error) => {
|
|
59
63
|
if (error instanceof HudApiError && (error.status === 404 || error.status === 403)) settle({ state: "unavailable" });
|
|
60
64
|
else settle({
|
|
@@ -65,11 +69,13 @@ function useRecords(ctx) {
|
|
|
65
69
|
}, [ctx]);
|
|
66
70
|
useEffect(() => {
|
|
67
71
|
load();
|
|
72
|
+
const unsubscribe = subscribePicks(load);
|
|
68
73
|
return () => {
|
|
74
|
+
unsubscribe();
|
|
69
75
|
token.current += 1;
|
|
70
76
|
};
|
|
71
77
|
}, [load]);
|
|
72
|
-
return
|
|
78
|
+
return records;
|
|
73
79
|
}
|
|
74
80
|
const EMPTY_SNAPSHOT = {
|
|
75
81
|
groups: [],
|
|
@@ -80,12 +86,13 @@ const getEmptySnapshot = () => EMPTY_SNAPSHOT;
|
|
|
80
86
|
* Variants panel. "Live on this page" lists every mounted `VariantGroup`
|
|
81
87
|
* (`@hansenexus/hud/variants`) with a switcher that rewrites `?variant=`,
|
|
82
88
|
* the agent-written score and rationale per variant from the storage seam,
|
|
83
|
-
* ranked, and
|
|
84
|
-
*
|
|
89
|
+
* ranked, and Pick (needs `variants.decide` and the server half). A pick only
|
|
90
|
+
* records; "Queue cleanup" hands a picked group's brief to the dispatch seam.
|
|
91
|
+
* An adapter adds the app's own registry and the generate-brief queue.
|
|
85
92
|
*/
|
|
86
93
|
function VariantsPanel({ adapter, ctx }) {
|
|
87
94
|
const snapshot = useSyncExternalStore(subscribeVariantGroups, getVariantGroupsSnapshot, getEmptySnapshot);
|
|
88
|
-
const
|
|
95
|
+
const records = useRecords(ctx);
|
|
89
96
|
const stored = records.state === "ready" ? records.records : [];
|
|
90
97
|
const liveIds = new Set(snapshot.groups.map((group) => group.id));
|
|
91
98
|
const elsewhere = stored.filter((record) => !liveIds.has(record.group));
|
|
@@ -121,14 +128,15 @@ function VariantsPanel({ adapter, ctx }) {
|
|
|
121
128
|
group,
|
|
122
129
|
choices: snapshot.choices,
|
|
123
130
|
records: stored.filter((record) => record.group === group.id),
|
|
124
|
-
|
|
125
|
-
ctx,
|
|
126
|
-
|
|
131
|
+
note: records.state === "ready" ? records.notes[group.id] ?? "" : "",
|
|
132
|
+
canPick: records.state === "ready" && ctx.can("variants.decide"),
|
|
133
|
+
dispatch: records.state === "ready" ? records.dispatch : null,
|
|
134
|
+
ctx
|
|
127
135
|
}, group.id)),
|
|
128
136
|
snapshot.groups.length > 0 && records.state === "unavailable" && /* @__PURE__ */ jsxs("p", {
|
|
129
137
|
className: "design-hint",
|
|
130
138
|
children: [
|
|
131
|
-
"Scores and
|
|
139
|
+
"Scores and picks need ",
|
|
132
140
|
/* @__PURE__ */ jsx("code", { children: "variantsServer()" }),
|
|
133
141
|
" in the HUD route."
|
|
134
142
|
]
|
|
@@ -136,7 +144,10 @@ function VariantsPanel({ adapter, ctx }) {
|
|
|
136
144
|
]
|
|
137
145
|
}),
|
|
138
146
|
elsewhere.length > 0 && /* @__PURE__ */ jsx(Elsewhere, { records: elsewhere }),
|
|
139
|
-
adapter && /* @__PURE__ */ jsx(Categories, {
|
|
147
|
+
adapter?.categories && /* @__PURE__ */ jsx(Categories, {
|
|
148
|
+
adapter,
|
|
149
|
+
categories: adapter.categories
|
|
150
|
+
}),
|
|
140
151
|
adapter?.generate && ctx.can("variants.generate") && /* @__PURE__ */ jsx(GenerateForm, { generate: adapter.generate })
|
|
141
152
|
]
|
|
142
153
|
});
|
|
@@ -164,53 +175,44 @@ function formatDate(iso) {
|
|
|
164
175
|
const date = new Date(iso);
|
|
165
176
|
return Number.isNaN(date.getTime()) ? iso : date.toISOString().slice(0, 10);
|
|
166
177
|
}
|
|
167
|
-
function LiveGroup({ group, choices, records,
|
|
178
|
+
function LiveGroup({ group, choices, records, note, canPick, dispatch, ctx }) {
|
|
168
179
|
const chosen = resolveVariant(group, choices);
|
|
169
180
|
const ranked = rankVariants(group, records);
|
|
170
|
-
const
|
|
171
|
-
const [
|
|
181
|
+
const picked = pickedRecord(records, group.id);
|
|
182
|
+
const [busy, setBusy] = useState(false);
|
|
172
183
|
const [result, setResult] = useState(null);
|
|
173
|
-
const
|
|
174
|
-
|
|
184
|
+
const run = async (action, what) => {
|
|
185
|
+
setBusy(true);
|
|
175
186
|
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
187
|
try {
|
|
185
|
-
const
|
|
186
|
-
|
|
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({
|
|
188
|
+
const text = await action();
|
|
189
|
+
if (text) setResult({
|
|
201
190
|
ok: true,
|
|
202
|
-
text
|
|
191
|
+
text
|
|
203
192
|
});
|
|
204
|
-
onDecided();
|
|
205
193
|
} catch (error) {
|
|
206
194
|
setResult({
|
|
207
195
|
ok: false,
|
|
208
|
-
text:
|
|
196
|
+
text: apiErrorText(error, `${what} failed`)
|
|
209
197
|
});
|
|
210
198
|
} finally {
|
|
211
|
-
|
|
199
|
+
setBusy(false);
|
|
212
200
|
}
|
|
213
201
|
};
|
|
202
|
+
const pick = () => run(async () => {
|
|
203
|
+
await postPick(ctx, group, { pick: picked?.id === chosen ? null : chosen });
|
|
204
|
+
announcePicks(group);
|
|
205
|
+
return null;
|
|
206
|
+
}, "pick");
|
|
207
|
+
const cleanup = () => run(async () => {
|
|
208
|
+
const { queued } = await ctx.api(`/${encodeURIComponent(group.id)}/cleanup`, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
headers: { "content-type": "application/json" },
|
|
211
|
+
body: "{}"
|
|
212
|
+
});
|
|
213
|
+
const { target, runId, detail } = queued;
|
|
214
|
+
return `brief queued → ${target} ${runId}${detail ? ` (${detail})` : ""}`;
|
|
215
|
+
}, "cleanup");
|
|
214
216
|
return /* @__PURE__ */ jsxs("div", {
|
|
215
217
|
className: "design-group",
|
|
216
218
|
"data-group": group.id,
|
|
@@ -222,14 +224,14 @@ function LiveGroup({ group, choices, records, canDecide, ctx, onDecided }) {
|
|
|
222
224
|
className: "design-grow",
|
|
223
225
|
children: group.label
|
|
224
226
|
}),
|
|
225
|
-
|
|
227
|
+
picked && /* @__PURE__ */ jsxs("span", {
|
|
226
228
|
className: "design-badge",
|
|
227
229
|
"data-tone": "active",
|
|
228
|
-
title:
|
|
230
|
+
title: picked.decidedAt,
|
|
229
231
|
children: [
|
|
230
|
-
"
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
"picked: ",
|
|
233
|
+
picked.label ?? picked.id,
|
|
234
|
+
picked.decidedAt ? ` · ${formatDate(picked.decidedAt)}` : ""
|
|
233
235
|
]
|
|
234
236
|
}),
|
|
235
237
|
/* @__PURE__ */ jsx("span", {
|
|
@@ -269,12 +271,12 @@ function LiveGroup({ group, choices, records, canDecide, ctx, onDecided }) {
|
|
|
269
271
|
className: "design-badge",
|
|
270
272
|
children: "rejected"
|
|
271
273
|
}),
|
|
272
|
-
|
|
274
|
+
canPick && id === chosen && /* @__PURE__ */ jsx("button", {
|
|
273
275
|
type: "button",
|
|
274
276
|
className: "design-button",
|
|
275
|
-
disabled:
|
|
276
|
-
onClick:
|
|
277
|
-
children: "
|
|
277
|
+
disabled: busy,
|
|
278
|
+
onClick: pick,
|
|
279
|
+
children: picked?.id === id ? "Take back" : "Pick"
|
|
278
280
|
})
|
|
279
281
|
]
|
|
280
282
|
}), record?.rationale && /* @__PURE__ */ jsx("p", {
|
|
@@ -283,6 +285,21 @@ function LiveGroup({ group, choices, records, canDecide, ctx, onDecided }) {
|
|
|
283
285
|
})]
|
|
284
286
|
}, id))
|
|
285
287
|
}),
|
|
288
|
+
note && /* @__PURE__ */ jsxs("p", {
|
|
289
|
+
className: "design-rationale",
|
|
290
|
+
children: ["Note: ", note]
|
|
291
|
+
}),
|
|
292
|
+
canPick && picked && dispatch && /* @__PURE__ */ jsx("div", {
|
|
293
|
+
className: "design-row",
|
|
294
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
295
|
+
type: "button",
|
|
296
|
+
className: "design-button",
|
|
297
|
+
disabled: busy,
|
|
298
|
+
title: `Hands ${dispatch} the brief to keep the picked variant and delete the others`,
|
|
299
|
+
onClick: cleanup,
|
|
300
|
+
children: "Queue cleanup"
|
|
301
|
+
})
|
|
302
|
+
}),
|
|
286
303
|
result && /* @__PURE__ */ jsx("p", {
|
|
287
304
|
className: "design-result design-mono",
|
|
288
305
|
"data-ok": result.ok,
|
|
@@ -323,8 +340,8 @@ function Elsewhere({ records }) {
|
|
|
323
340
|
}, `${record.group}:${record.id}`))]
|
|
324
341
|
});
|
|
325
342
|
}
|
|
326
|
-
function Categories({ adapter }) {
|
|
327
|
-
const loaded = useCategories(
|
|
343
|
+
function Categories({ adapter, categories }) {
|
|
344
|
+
const loaded = useCategories(categories);
|
|
328
345
|
const { reviewHref, categoryHref, openPreview } = adapter;
|
|
329
346
|
return /* @__PURE__ */ jsxs("section", {
|
|
330
347
|
className: "design-section",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//#region src/plugins/design/variants-types.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
|
+
const VARIANTS_COLLECTION = "variants";
|
|
5
|
+
const NOTE_MAX = 4e3;
|
|
6
|
+
function recordKey(group, id) {
|
|
7
|
+
return `${group}:${id}`;
|
|
8
|
+
}
|
|
9
|
+
function isRecord(value) {
|
|
10
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
const STATUSES = [
|
|
13
|
+
"open",
|
|
14
|
+
"decided",
|
|
15
|
+
"rejected"
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* A store entry as a `VariantRecord`: group and id come from the fields, or
|
|
19
|
+
* from a `<group>:<id>` key when the file omits them. Unknown fields are
|
|
20
|
+
* dropped, wrong types ignored; null when neither names the variant.
|
|
21
|
+
*/
|
|
22
|
+
function toVariantRecord(id, value) {
|
|
23
|
+
if (!isRecord(value)) return null;
|
|
24
|
+
const separator = id.indexOf(":");
|
|
25
|
+
const group = typeof value.group === "string" ? value.group : separator > 0 ? id.slice(0, separator) : "";
|
|
26
|
+
const variant = typeof value.id === "string" ? value.id : separator > 0 ? id.slice(separator + 1) : "";
|
|
27
|
+
if (!group || !variant) return null;
|
|
28
|
+
const record = {
|
|
29
|
+
group,
|
|
30
|
+
id: variant
|
|
31
|
+
};
|
|
32
|
+
if (typeof value.label === "string") record.label = value.label;
|
|
33
|
+
if (typeof value.status === "string" && STATUSES.includes(value.status)) record.status = value.status;
|
|
34
|
+
if (typeof value.score === "number" && Number.isFinite(value.score)) record.score = value.score;
|
|
35
|
+
if (typeof value.rationale === "string") record.rationale = value.rationale;
|
|
36
|
+
if (typeof value.scoredBy === "string") record.scoredBy = value.scoredBy;
|
|
37
|
+
if (typeof value.decidedAt === "string") record.decidedAt = value.decidedAt;
|
|
38
|
+
return record;
|
|
39
|
+
}
|
|
40
|
+
/** The picked variant's record of a group, if it has one. */
|
|
41
|
+
function pickedRecord(records, group) {
|
|
42
|
+
return records.find((record) => record.group === group && record.status === "decided");
|
|
43
|
+
}
|
|
44
|
+
function toLogEntry(value) {
|
|
45
|
+
if (!isRecord(value) || typeof value.at !== "string") return [];
|
|
46
|
+
return [{
|
|
47
|
+
at: value.at,
|
|
48
|
+
pick: typeof value.pick === "string" && value.pick ? value.pick : null,
|
|
49
|
+
note: typeof value.note === "string" ? value.note : ""
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
52
|
+
/** A store entry as a `VariantGroupRecord`; null for a variant's entry or anything else. */
|
|
53
|
+
function toGroupRecord(id, value) {
|
|
54
|
+
if (!isRecord(value) || id.includes(":") || value.id !== void 0) return null;
|
|
55
|
+
if (typeof value.note !== "string" && !Array.isArray(value.log)) return null;
|
|
56
|
+
const record = {
|
|
57
|
+
group: id,
|
|
58
|
+
note: typeof value.note === "string" ? value.note : "",
|
|
59
|
+
log: Array.isArray(value.log) ? value.log.flatMap(toLogEntry) : []
|
|
60
|
+
};
|
|
61
|
+
if (typeof value.label === "string") record.label = value.label;
|
|
62
|
+
return record;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { toGroupRecord as a, recordKey as i, VARIANTS_COLLECTION as n, toVariantRecord as o, pickedRecord as r, NOTE_MAX as t };
|
|
@@ -0,0 +1,139 @@
|
|
|
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`, a pick 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 the pick on the winner. */
|
|
22
|
+
decidedAt?: string;
|
|
23
|
+
}
|
|
24
|
+
/** One change to a group's pick or note. The log only grows. */
|
|
25
|
+
interface VariantLogEntry {
|
|
26
|
+
/** ISO timestamp. */
|
|
27
|
+
at: string;
|
|
28
|
+
/** The picked variant after the change, null when the pick was taken back. */
|
|
29
|
+
pick: string | null;
|
|
30
|
+
/** The note after the change. */
|
|
31
|
+
note: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What a pick knows about the group as a whole. The store keys it `<group>`
|
|
35
|
+
* (no colon) in the same collection; which variant is picked stays on the
|
|
36
|
+
* variant records (`status: "decided"`).
|
|
37
|
+
*/
|
|
38
|
+
interface VariantGroupRecord {
|
|
39
|
+
group: string;
|
|
40
|
+
label?: string;
|
|
41
|
+
note: string;
|
|
42
|
+
log: VariantLogEntry[];
|
|
43
|
+
}
|
|
44
|
+
/** One change to a group's pick or note. The log only grows. */
|
|
45
|
+
interface VariantLogEntry {
|
|
46
|
+
/** ISO timestamp. */
|
|
47
|
+
at: string;
|
|
48
|
+
/** The picked variant after the change, null when the pick was taken back. */
|
|
49
|
+
pick: string | null;
|
|
50
|
+
/** The note after the change. */
|
|
51
|
+
note: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What a pick knows about the group as a whole. The store keys it `<group>`
|
|
55
|
+
* (no colon) in the same collection; which variant is picked stays on the
|
|
56
|
+
* variant records (`status: "decided"`).
|
|
57
|
+
*/
|
|
58
|
+
interface VariantGroupRecord {
|
|
59
|
+
group: string;
|
|
60
|
+
label?: string;
|
|
61
|
+
note: string;
|
|
62
|
+
log: VariantLogEntry[];
|
|
63
|
+
}
|
|
64
|
+
/** One change to a group's pick or note. The log only grows. */
|
|
65
|
+
interface VariantLogEntry {
|
|
66
|
+
/** ISO timestamp. */
|
|
67
|
+
at: string;
|
|
68
|
+
/** The picked variant after the change, null when the pick was taken back. */
|
|
69
|
+
pick: string | null;
|
|
70
|
+
/** The note after the change. */
|
|
71
|
+
note: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* What a pick knows about the group as a whole. The store keys it `<group>`
|
|
75
|
+
* (no colon) in the same collection; which variant is picked stays on the
|
|
76
|
+
* variant records (`status: "decided"`).
|
|
77
|
+
*/
|
|
78
|
+
interface VariantGroupRecord {
|
|
79
|
+
group: string;
|
|
80
|
+
label?: string;
|
|
81
|
+
note: string;
|
|
82
|
+
log: VariantLogEntry[];
|
|
83
|
+
}
|
|
84
|
+
/** `GET <apiBase>/variants/`. */
|
|
85
|
+
interface VariantsListResponse {
|
|
86
|
+
ok: true;
|
|
87
|
+
records: VariantRecord[];
|
|
88
|
+
/** Notes and logs, one per group that was ever picked or noted. */
|
|
89
|
+
groups?: VariantGroupRecord[];
|
|
90
|
+
/** The dispatch provider's id, or null when none is configured. */
|
|
91
|
+
dispatch?: string | null;
|
|
92
|
+
}
|
|
93
|
+
/** `POST <apiBase>/variants/:group/pick`. Leave `id` or `note` out to keep it. */
|
|
94
|
+
interface PickBody {
|
|
95
|
+
/** The picked variant, or null to take the pick back. */
|
|
96
|
+
id?: string | null;
|
|
97
|
+
note?: string;
|
|
98
|
+
/** The group's label, for the export and the brief. */
|
|
99
|
+
label?: string;
|
|
100
|
+
/** Every variant of the group as the page registers it, so losers get a record too. */
|
|
101
|
+
variants?: {
|
|
102
|
+
id: string;
|
|
103
|
+
label: string;
|
|
104
|
+
}[];
|
|
105
|
+
}
|
|
106
|
+
/** Recorded, nothing else: no brief is queued and no agent started. */
|
|
107
|
+
interface PickResponse {
|
|
108
|
+
ok: true;
|
|
109
|
+
group: string;
|
|
110
|
+
/** The picked variant now, or null. */
|
|
111
|
+
pick: string | null;
|
|
112
|
+
/** ISO timestamp of the pick. */
|
|
113
|
+
decidedAt?: string;
|
|
114
|
+
note: string;
|
|
115
|
+
/** False when the request changed nothing; the log is untouched then. */
|
|
116
|
+
changed: boolean;
|
|
117
|
+
}
|
|
118
|
+
/** `POST <apiBase>/variants/:group/cleanup`: queues the brief for a picked group. */
|
|
119
|
+
interface CleanupResponse {
|
|
120
|
+
ok: true;
|
|
121
|
+
group: string;
|
|
122
|
+
id: string;
|
|
123
|
+
queued: {
|
|
124
|
+
target: string;
|
|
125
|
+
runId: string;
|
|
126
|
+
detail?: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
declare function recordKey(group: string, id: string): string;
|
|
130
|
+
/**
|
|
131
|
+
* A store entry as a `VariantRecord`: group and id come from the fields, or
|
|
132
|
+
* from a `<group>:<id>` key when the file omits them. Unknown fields are
|
|
133
|
+
* dropped, wrong types ignored; null when neither names the variant.
|
|
134
|
+
*/
|
|
135
|
+
declare function toVariantRecord(id: string, value: unknown): VariantRecord | null;
|
|
136
|
+
/** A store entry as a `VariantGroupRecord`; null for a variant's entry or anything else. */
|
|
137
|
+
declare function toGroupRecord(id: string, value: unknown): VariantGroupRecord | null;
|
|
138
|
+
//#endregion
|
|
139
|
+
export { VariantGroupRecord as a, VariantStatus as c, toGroupRecord as d, toVariantRecord as f, VARIANTS_COLLECTION as i, VariantsListResponse as l, PickBody as n, VariantLogEntry as o, PickResponse as r, VariantRecord as s, CleanupResponse as t, recordKey as u };
|
package/dist/variants.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface VariantGroupProps {
|
|
|
32
32
|
*
|
|
33
33
|
* In development `?variant=hero:bold` renders that variant and the HUD's
|
|
34
34
|
* Variants panel (`variants()` from `@hansenexus/hud/plugins/design`) lists
|
|
35
|
-
* the group with a switcher, agent scores and
|
|
35
|
+
* the group with a switcher, agent scores and picks. Production-safe to
|
|
36
36
|
* import: outside development it renders the default and nothing else.
|
|
37
37
|
*
|
|
38
38
|
* A client component: use it from client code, since the render functions
|
package/dist/variants.js
CHANGED
|
@@ -26,7 +26,7 @@ const VARIANTS_ENABLED = process.env.NODE_ENV === "development";
|
|
|
26
26
|
*
|
|
27
27
|
* In development `?variant=hero:bold` renders that variant and the HUD's
|
|
28
28
|
* Variants panel (`variants()` from `@hansenexus/hud/plugins/design`) lists
|
|
29
|
-
* the group with a switcher, agent scores and
|
|
29
|
+
* the group with a switcher, agent scores and picks. Production-safe to
|
|
30
30
|
* import: outside development it renders the default and nothing else.
|
|
31
31
|
*
|
|
32
32
|
* A client component: use it from client code, since the render functions
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as HudPlugin } from "./plugins-
|
|
2
|
-
import { r as HudHandlerOptions, t as HudGuard } from "./handler-
|
|
1
|
+
import { c as HudPlugin } from "./plugins-pL2CoWzI.js";
|
|
2
|
+
import { r as HudHandlerOptions, t as HudGuard } from "./handler-BmFhaA2D.js";
|
|
3
3
|
import { Plugin } from "vite";
|
|
4
4
|
//#region src/vite/index.d.ts
|
|
5
5
|
export interface HudViteOptions extends HudHandlerOptions {
|