@hansenexus/hud 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +634 -12
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
  5. package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
  6. package/dist/access-panel-CEfTr9ZI.js +123 -0
  7. package/dist/adapter-BYoxPYTI.d.ts +33 -0
  8. package/dist/adapter-hcwmJtNx.js +65 -0
  9. package/dist/auto/runtime.d.ts +65 -0
  10. package/dist/auto/runtime.js +50 -0
  11. package/dist/auto.d.ts +15 -0
  12. package/dist/auto.js +33 -0
  13. package/dist/capabilities-rDSKjXpq.js +110 -0
  14. package/dist/capture-CwrIwLqi.js +300 -0
  15. package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
  16. package/dist/cli.d.ts +1 -0
  17. package/dist/cli.js +275 -0
  18. package/dist/data-panel-DhxAmP91.js +817 -0
  19. package/dist/data-store-ChF1td_P.js +164 -0
  20. package/dist/define-hud-CHPedaQ5.d.ts +50 -0
  21. package/dist/design-D0kGgPoP.js +87 -0
  22. package/dist/detect-BxHZ0pxW.d.ts +25 -0
  23. package/dist/detect-CHZiSeZs.js +63 -0
  24. package/dist/dispatch-panel-B-xr_Giy.js +279 -0
  25. package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
  26. package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
  27. package/dist/file-xdSaQ2uR.js +103 -0
  28. package/dist/flags-DVtaJ8pQ.d.ts +58 -0
  29. package/dist/flags.d.ts +2 -0
  30. package/dist/flags.js +82 -0
  31. package/dist/force-state-panel-_otVYh9i.js +97 -0
  32. package/dist/generate-C8lQl3Eh.js +53 -0
  33. package/dist/handler-BpVhxEmU.js +106 -0
  34. package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
  35. package/dist/index-BAV_1W8a.d.ts +43 -0
  36. package/dist/index-BJ26pse9.d.ts +70 -0
  37. package/dist/index-BnQ0dTZf.d.ts +19 -0
  38. package/dist/index-CwfX-W87.d.ts +72 -0
  39. package/dist/index-DcH9V3cU.d.ts +48 -0
  40. package/dist/index-DqOyNf1u.d.ts +65 -0
  41. package/dist/index-DstI_ike.d.ts +66 -0
  42. package/dist/index-Dxz4fn4j.d.ts +42 -0
  43. package/dist/index-Hhh7OXzU.d.ts +129 -0
  44. package/dist/index-ReFbhQ9p.d.ts +25 -0
  45. package/dist/index-RgXfMBuW.d.ts +48 -0
  46. package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.js +710 -69
  49. package/dist/inspect-C9Ft8fqn.js +142 -0
  50. package/dist/inspect-root-BkaupBMp.js +429 -0
  51. package/dist/meta-Bv0sEao3.js +6 -0
  52. package/dist/meta-C_G7MB5w.d.ts +49 -0
  53. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  54. package/dist/mocks-ESiRqk9o.js +150 -0
  55. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  56. package/dist/next/config.cjs +201 -0
  57. package/dist/next/config.d.cts +87 -0
  58. package/dist/next/config.d.ts +64 -0
  59. package/dist/next/config.js +84 -0
  60. package/dist/next.d.ts +14 -4
  61. package/dist/next.js +5 -3
  62. package/dist/observe-CdDnDBRP.js +89 -0
  63. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  64. package/dist/ops-panel-CEqDe_UT.js +234 -0
  65. package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
  66. package/dist/plugins/a11y.d.ts +2 -0
  67. package/dist/plugins/a11y.js +2 -0
  68. package/dist/plugins/access/server.d.ts +5 -5
  69. package/dist/plugins/access/server.js +4 -3
  70. package/dist/plugins/access.d.ts +5 -5
  71. package/dist/plugins/access.js +16 -215
  72. package/dist/plugins/agent/server.d.ts +3 -38
  73. package/dist/plugins/agent/server.js +47 -21
  74. package/dist/plugins/agent.d.ts +4 -4
  75. package/dist/plugins/agent.js +6 -348
  76. package/dist/plugins/capture/server.d.ts +92 -0
  77. package/dist/plugins/capture/server.js +248 -0
  78. package/dist/plugins/capture.d.ts +24 -0
  79. package/dist/plugins/capture.js +70 -0
  80. package/dist/plugins/data/msw-browser.d.ts +2 -0
  81. package/dist/plugins/data/msw-browser.js +39 -0
  82. package/dist/plugins/data/msw-node.d.ts +36 -0
  83. package/dist/plugins/data/msw-node.js +68 -0
  84. package/dist/plugins/data/server.d.ts +257 -0
  85. package/dist/plugins/data/server.js +717 -0
  86. package/dist/plugins/data.d.ts +6 -0
  87. package/dist/plugins/data.js +51 -0
  88. package/dist/plugins/design/server.d.ts +54 -0
  89. package/dist/plugins/design/server.js +198 -0
  90. package/dist/plugins/design.d.ts +4 -124
  91. package/dist/plugins/design.js +4 -619
  92. package/dist/plugins/inspect/convex.d.ts +2 -0
  93. package/dist/plugins/inspect/convex.js +486 -0
  94. package/dist/plugins/inspect/react-query.d.ts +2 -0
  95. package/dist/plugins/inspect/react-query.js +237 -0
  96. package/dist/plugins/inspect/sockets.d.ts +51 -0
  97. package/dist/plugins/inspect/sockets.js +397 -0
  98. package/dist/plugins/inspect/swr.d.ts +2 -0
  99. package/dist/plugins/inspect/swr.js +218 -0
  100. package/dist/plugins/inspect.d.ts +4 -0
  101. package/dist/plugins/inspect.js +3 -0
  102. package/dist/plugins/observe.d.ts +4 -64
  103. package/dist/plugins/observe.js +1 -616
  104. package/dist/plugins/ops/server.d.ts +1 -1
  105. package/dist/plugins/ops/server.js +2 -1
  106. package/dist/plugins/ops.d.ts +2 -1
  107. package/dist/plugins/ops.js +15 -336
  108. package/dist/plugins/routes/server.d.ts +88 -0
  109. package/dist/plugins/routes/server.js +62 -0
  110. package/dist/plugins/routes.d.ts +3 -0
  111. package/dist/plugins/routes.js +216 -0
  112. package/dist/plugins/seo.d.ts +2 -0
  113. package/dist/plugins/seo.js +2 -0
  114. package/dist/plugins/vitals.d.ts +2 -25
  115. package/dist/plugins/vitals.js +3 -2
  116. package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
  117. package/dist/poll-CjKsWZi8.js +89 -0
  118. package/dist/requests-BwD6MKEq.js +282 -0
  119. package/dist/requests-CJrUf465.d.ts +50 -0
  120. package/dist/review.js +2 -2
  121. package/dist/same-origin-BGet22CC.js +21 -0
  122. package/dist/scan-DzJNXqOk.js +165 -0
  123. package/dist/seo-Dq9q_QkO.js +551 -0
  124. package/dist/seo-panel-CfiY-TnT.js +124 -0
  125. package/dist/server.d.ts +2 -2
  126. package/dist/server.js +2 -105
  127. package/dist/sessions-panel-COvhPAzv.js +98 -0
  128. package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
  129. package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
  130. package/dist/store/convex.d.ts +33 -0
  131. package/dist/store/convex.js +52 -0
  132. package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
  133. package/dist/store-Ync9eb1G.js +67 -0
  134. package/dist/store.d.ts +76 -0
  135. package/dist/store.js +188 -0
  136. package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
  137. package/dist/styles-DKU_P8MH.js +139 -0
  138. package/dist/styles-DPpDPmzi.js +68 -0
  139. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  140. package/dist/types-B-ulf2Jp.js +8 -0
  141. package/dist/types-BIgGf-0C.d.ts +25 -0
  142. package/dist/types-BIkI-qN8.js +30 -0
  143. package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
  144. package/dist/types-DIdPfjtV.js +6 -0
  145. package/dist/types-DaJcsEjO.d.ts +44 -0
  146. package/dist/types-Dn68psVz.d.ts +118 -0
  147. package/dist/types-szkr2QOF.d.ts +39 -0
  148. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  149. package/dist/variant-groups-TIfO3NIj.js +137 -0
  150. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  151. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  152. package/dist/variants-types-CcRf119M.d.ts +63 -0
  153. package/dist/variants.d.ts +43 -0
  154. package/dist/variants.js +83 -0
  155. package/dist/vitals-panel-BCmMUntW.js +30 -0
  156. package/dist/vite.d.ts +37 -0
  157. package/dist/vite.js +134 -0
  158. package/package.json +72 -5
  159. package/dist/define-hud-BBzsSl8b.d.ts +0 -36
@@ -1,4 +1,5 @@
1
1
  import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
2
+ import { t as refuseCrossSite } from "../../same-origin-BGet22CC.js";
2
3
  //#region src/plugins/agent/prompt.ts
3
4
  /** The task text every provider receives: grab context first, then the instruction. */
4
5
  function dispatchPrompt({ note, payload, hints = [] }) {
@@ -21,7 +22,13 @@ function dispatchPrompt({ note, payload, hints = [] }) {
21
22
  }
22
23
  if (hints.length > 0) lines.push(`Component manifest matches (best effort, verify): ${hints.map((h) => h.path).join(", ")}`);
23
24
  if (!component?.source && hints.length === 0) lines.push("No source hint: locate the component from the route and selector.");
24
- lines.push(`Viewport: ${payload.viewport.width}×${payload.viewport.height}`, `Instruction: ${instruction}`, "", "Task: locate the element's source, apply the instruction, and run the project's checks.");
25
+ lines.push(`Viewport: ${payload.viewport.width}×${payload.viewport.height}`);
26
+ const shot = payload.screenshot;
27
+ if (shot?.status === "ready") {
28
+ const what = shot.scope === "element" ? "the grabbed element" : "the viewport (element not found headless)";
29
+ lines.push(`Screenshot: PNG ${shot.width}×${shot.height} of ${what}, attached to this dispatch.`);
30
+ } else if (shot?.status === "unavailable") lines.push(`Screenshot: none (${shot.reason}).`);
31
+ lines.push(`Instruction: ${instruction}`, "", "Task: locate the element's source, apply the instruction, and run the project's checks.");
25
32
  return lines.join("\n");
26
33
  }
27
34
  //#endregion
@@ -146,10 +153,17 @@ function claudeCode({ cwd: cwdOption, command = "claude", args = defaultArgs, la
146
153
  await api.fsp.mkdir(logDir, { recursive: true });
147
154
  const id = `run-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
148
155
  const log = path.join(logDir, `${id}.log`);
156
+ let prompt = order.prompt;
157
+ const shot = order.payload?.screenshot;
158
+ if (shot?.status === "ready") {
159
+ const image = path.join(logDir, `${id}.png`);
160
+ await api.fsp.writeFile(image, Buffer.from(shot.base64, "base64"), { mode: 384 });
161
+ prompt += `\nScreenshot file (PNG of the grabbed element): ${image}`;
162
+ }
149
163
  const fd = fs.openSync(log, "a", 384);
150
164
  let child;
151
165
  try {
152
- child = spawn(command, args(order.prompt), {
166
+ child = spawn(command, args(prompt), {
153
167
  cwd: cwdOf(api),
154
168
  detached: true,
155
169
  stdio: [
@@ -271,27 +285,30 @@ function hermes({ baseUrl, token, instructions, label = "Hermes", timeoutMs = 1e
271
285
  function message(error) {
272
286
  return error instanceof Error ? error.message : String(error);
273
287
  }
274
- /**
275
- * A dispatch spawns an agent, so a page on another origin must not be able to
276
- * trigger one through the developer's browser. A JSON content type forces a
277
- * CORS preflight that this route never answers, and `Sec-Fetch-Site` rejects
278
- * cross-site requests outright where the browser sends it.
279
- */
280
- function refuseCrossSite(request) {
281
- const site = request.headers.get("sec-fetch-site");
282
- if (site && site !== "same-origin" && site !== "none") return Response.json({
283
- ok: false,
284
- error: "cross-site request refused"
285
- }, { status: 403 });
286
- if (!request.headers.get("content-type")?.toLowerCase().startsWith("application/json")) return Response.json({
287
- ok: false,
288
- error: "expected application/json"
289
- }, { status: 415 });
290
- return null;
291
- }
292
288
  function isRecord(value) {
293
289
  return typeof value === "object" && value !== null && !Array.isArray(value);
294
290
  }
291
+ /**
292
+ * The grab's screenshot as the `capture` plugin attached it: a PNG, or the
293
+ * reason there is none. A `pending` one (the panel waits for it, but a raw
294
+ * client may not) is dropped.
295
+ */
296
+ function parseScreenshot(value) {
297
+ if (!isRecord(value)) return void 0;
298
+ if (value.status === "ready" && value.mime === "image/png" && typeof value.base64 === "string" && /^[A-Za-z0-9+/]*={0,2}$/.test(value.base64) && typeof value.width === "number" && typeof value.height === "number" && (value.scope === "element" || value.scope === "viewport")) return {
299
+ status: "ready",
300
+ mime: "image/png",
301
+ base64: value.base64,
302
+ width: value.width,
303
+ height: value.height,
304
+ scope: value.scope
305
+ };
306
+ if (value.status === "unavailable" && typeof value.reason === "string") return {
307
+ status: "unavailable",
308
+ reason: value.reason,
309
+ ...typeof value.hint === "string" ? { hint: value.hint } : {}
310
+ };
311
+ }
295
312
  /** Shape check, not a schema: enough that the prompt builder cannot throw on it. */
296
313
  function parseBody(value) {
297
314
  if (!isRecord(value) || typeof value.target !== "string") return null;
@@ -300,10 +317,19 @@ function parseBody(value) {
300
317
  const validPayload = isRecord(payload) && typeof payload.app === "string" && typeof payload.route === "string" && isRecord(payload.anchor) && typeof payload.anchor.label === "string" && typeof payload.anchor.selector === "string" && isRecord(payload.viewport) && typeof payload.viewport.width === "number" && typeof payload.viewport.height === "number" && (payload.component == null || isRecord(payload.component) && typeof payload.component.name === "string" && Array.isArray(payload.component.owners));
301
318
  if (payload != null && !validPayload) return null;
302
319
  const hints = Array.isArray(value.hints) ? value.hints.filter((h) => isRecord(h) && typeof h.name === "string" && typeof h.path === "string") : [];
320
+ let grab = null;
321
+ if (validPayload) {
322
+ const { screenshot: raw, ...rest } = payload;
323
+ const screenshot = parseScreenshot(raw);
324
+ grab = {
325
+ ...rest,
326
+ ...screenshot ? { screenshot } : {}
327
+ };
328
+ }
303
329
  return {
304
330
  target: value.target,
305
331
  note,
306
- payload: validPayload ? payload : null,
332
+ payload: grab,
307
333
  hints
308
334
  };
309
335
  }
@@ -1,7 +1,7 @@
1
- import { r as GrabPayload, t as ComponentHint } from "../payload-CLKDVZWl.js";
2
- import { c as HudPluginProps, s as HudPluginContext } from "../plugins-CQ_0w1ot.js";
3
- import "../index-BYsdS-7d.js";
4
- import { a as DispatchTargetInfo, i as DispatchReceipt, n as AgentSessionStatus, o as SessionsResponse, r as DispatchBody, t as AgentSession } from "../types-DADBRiGk.js";
1
+ import { r as GrabPayload, t as ComponentHint } from "../payload-MUQ9ciER.js";
2
+ import { c as HudPluginProps, s as HudPluginContext } from "../plugins-BZvDqGx5.js";
3
+ import "../index-gCZBO53s.js";
4
+ import { a as DispatchTargetInfo, i as DispatchReceipt, n as AgentSessionStatus, o as SessionsResponse, r as DispatchBody, t as AgentSession } from "../types-Cxh4twqc.js";
5
5
  //#region src/plugins/agent/index.d.ts
6
6
  export interface AgentDispatchOptions {
7
7
  /**
@@ -1,64 +1,7 @@
1
- import { i as parseShortcut, l as useGrab, n as isApplePlatform, s as matchComponentHints, t as formatShortcut } from "../shortcut-U6ftVY06.js";
2
- import { i as definePlugin, n as HudApiError } from "../plugins-DVy_vaYr.js";
3
- import { useCallback, useEffect, useState, useSyncExternalStore } from "react";
4
- import { jsx, jsxs } from "react/jsx-runtime";
5
- //#region src/plugins/agent/styles.ts
6
- /**
7
- * The agent panels' styles. Each panel renders them in a `<style>` inside the
8
- * HUD's shadow root, so the plugin brings its CSS without touching core's.
9
- */
10
- const AGENT_CSS = `
11
- .agent { display: grid; gap: 10px; }
12
- .agent-row { display: flex; align-items: center; gap: 8px; }
13
- .agent-grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
14
- .agent-muted { color: var(--hud-fg-muted); }
15
- .agent-mono { font-family: var(--hud-mono); font-size: 11px; }
16
- .hud .agent-btn {
17
- padding: 3px 10px;
18
- border: 1px solid var(--hud-border);
19
- border-radius: 6px;
20
- background: var(--hud-bg-subtle);
21
- }
22
- .hud .agent-btn[data-primary] { background: var(--hud-accent); color: var(--hud-accent-fg); border-color: transparent; }
23
- .hud .agent-btn:disabled { opacity: 0.5; cursor: not-allowed; }
24
- .agent-card {
25
- display: grid;
26
- gap: 2px;
27
- padding: 6px 8px;
28
- border: 1px solid var(--hud-border);
29
- border-radius: 6px;
30
- background: var(--hud-bg-subtle);
31
- }
32
- .agent textarea {
33
- font: inherit;
34
- color: inherit;
35
- background: var(--hud-bg);
36
- border: 1px solid var(--hud-border);
37
- border-radius: 6px;
38
- padding: 6px 8px;
39
- min-height: 56px;
40
- resize: vertical;
41
- }
42
- .agent fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 4px; }
43
- .agent label.agent-target { display: flex; gap: 6px; align-items: flex-start; cursor: pointer; }
44
- .agent label.agent-target[data-disabled] { opacity: 0.55; cursor: not-allowed; }
45
- .agent-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
46
- .agent-badge {
47
- flex: none;
48
- padding: 0 6px;
49
- border-radius: 999px;
50
- border: 1px solid currentColor;
51
- font-size: 10px;
52
- line-height: 16px;
53
- color: var(--hud-fg-muted);
54
- }
55
- .agent-badge[data-status="running"], .agent-badge[data-status="dispatched"] { color: var(--hud-good); }
56
- .agent-badge[data-status="sending"], .agent-badge[data-status="queued"] { color: var(--hud-warn); }
57
- .agent-badge[data-status="failed"] { color: var(--hud-poor); }
58
- .agent details pre { max-height: 160px; overflow: auto; margin: 4px 0 0; font-size: 10px; }
59
- `;
60
- //#endregion
61
- //#region src/plugins/agent/dispatch-panel.tsx
1
+ import { i as definePlugin } from "../plugins-DVy_vaYr.js";
2
+ import { lazy } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region src/plugins/agent/run-log.ts
62
5
  /**
63
6
  * Runs dispatched from this page. It outlives the panel (closing it unmounts
64
7
  * the component), so it lives with the plugin instance.
@@ -83,295 +26,10 @@ function createRunLog() {
83
26
  } : run))
84
27
  };
85
28
  }
86
- function errorText(error) {
87
- if (error instanceof HudApiError) return error.body?.error ?? `HTTP ${error.status}`;
88
- return error instanceof Error ? error.message : String(error);
89
- }
90
- function DispatchPanel({ ctx, log, componentHints }) {
91
- const { grabbing, payload } = useGrab(ctx.grab);
92
- const runs = useSyncExternalStore(log.subscribe, log.get, log.get);
93
- const [targets, setTargets] = useState(null);
94
- const [targetsError, setTargetsError] = useState(null);
95
- const [target, setTarget] = useState(null);
96
- const [note, setNote] = useState("");
97
- useEffect(() => {
98
- let cancelled = false;
99
- ctx.api("/targets").then((list) => {
100
- if (cancelled) return;
101
- setTargets(list);
102
- setTarget((current) => current ?? list.find((t) => t.available)?.id ?? null);
103
- }).catch((error) => {
104
- if (!cancelled) setTargetsError(errorText(error));
105
- });
106
- return () => {
107
- cancelled = true;
108
- };
109
- }, [ctx]);
110
- const hints = payload ? matchComponentHints(componentHints, payload.route, payload.anchor.label) : [];
111
- const canSend = target !== null && (payload !== null || note.trim() !== "");
112
- async function send() {
113
- if (!target || !canSend) return;
114
- const id = `${Date.now()}`;
115
- const title = [payload?.anchor.label, note.trim().split("\n")[0]].filter(Boolean).join(" · ");
116
- const body = {
117
- target,
118
- note,
119
- payload,
120
- hints
121
- };
122
- log.add({
123
- id,
124
- title: title || "dispatch",
125
- target,
126
- status: "sending"
127
- });
128
- ctx.grab.clear();
129
- setNote("");
130
- try {
131
- const receipt = await ctx.api("/dispatch", {
132
- method: "POST",
133
- headers: { "content-type": "application/json" },
134
- body: JSON.stringify(body)
135
- });
136
- log.update(id, {
137
- status: "dispatched",
138
- detail: [receipt.runId, receipt.detail].filter(Boolean).join(" · ")
139
- });
140
- } catch (error) {
141
- log.update(id, {
142
- status: "failed",
143
- detail: errorText(error)
144
- });
145
- }
146
- }
147
- return /* @__PURE__ */ jsxs("div", {
148
- className: "agent",
149
- children: [
150
- /* @__PURE__ */ jsx("style", { children: AGENT_CSS }),
151
- payload ? /* @__PURE__ */ jsxs("div", {
152
- className: "agent-card",
153
- children: [
154
- /* @__PURE__ */ jsxs("div", {
155
- className: "agent-row",
156
- children: [/* @__PURE__ */ jsxs("strong", {
157
- className: "agent-grow",
158
- title: payload.anchor.label,
159
- children: [payload.component ? `<${payload.component.name}> ` : "", payload.anchor.label]
160
- }), /* @__PURE__ */ jsx("button", {
161
- type: "button",
162
- className: "agent-btn",
163
- "aria-label": "Discard grab",
164
- onClick: ctx.grab.clear,
165
- children: "✕"
166
- })]
167
- }),
168
- payload.component?.source && /* @__PURE__ */ jsx("span", {
169
- className: "agent-mono agent-muted",
170
- children: payload.component.source
171
- }),
172
- /* @__PURE__ */ jsxs("span", {
173
- className: "agent-mono agent-muted agent-grow",
174
- title: payload.anchor.selector,
175
- children: [
176
- payload.route,
177
- " · ",
178
- payload.anchor.selector || payload.anchor.tag
179
- ]
180
- }),
181
- /* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx("summary", {
182
- className: "agent-muted",
183
- children: "Payload"
184
- }), /* @__PURE__ */ jsx("pre", {
185
- className: "agent-mono",
186
- children: JSON.stringify({
187
- ...payload,
188
- hints
189
- }, null, 2)
190
- })] })
191
- ]
192
- }) : /* @__PURE__ */ jsxs("div", {
193
- className: "agent-row",
194
- children: [/* @__PURE__ */ jsx("button", {
195
- type: "button",
196
- className: "agent-btn",
197
- "data-primary": "",
198
- "aria-pressed": grabbing,
199
- onClick: grabbing ? ctx.grab.cancel : ctx.grab.start,
200
- children: grabbing ? "Cancel grab" : "⌖ Grab element"
201
- }), /* @__PURE__ */ jsxs("span", {
202
- className: "agent-muted",
203
- children: [
204
- "or ",
205
- formatShortcut(parseShortcut("mod+shift+g"), isApplePlatform()),
206
- ", then click anything on the page"
207
- ]
208
- })]
209
- }),
210
- /* @__PURE__ */ jsx("textarea", {
211
- "aria-label": "Instruction",
212
- placeholder: "Instruction, e.g. the CTA feels heavy, try the ghost variant",
213
- value: note,
214
- onChange: (e) => setNote(e.target.value)
215
- }),
216
- targetsError && /* @__PURE__ */ jsxs("p", {
217
- className: "empty",
218
- children: ["Targets unavailable: ", targetsError]
219
- }),
220
- targets && targets.length === 0 && /* @__PURE__ */ jsx("p", {
221
- className: "empty",
222
- children: "No dispatch provider configured on the server."
223
- }),
224
- targets && targets.length > 0 && /* @__PURE__ */ jsx("fieldset", { children: targets.map((t) => /* @__PURE__ */ jsxs("label", {
225
- className: "agent-target",
226
- ...t.available ? {} : { "data-disabled": "" },
227
- children: [/* @__PURE__ */ jsx("input", {
228
- type: "radio",
229
- name: "agent-target",
230
- checked: target === t.id,
231
- disabled: !t.available,
232
- onChange: () => setTarget(t.id)
233
- }), /* @__PURE__ */ jsxs("span", { children: [
234
- /* @__PURE__ */ jsx("span", { children: t.label }),
235
- /* @__PURE__ */ jsx("br", {}),
236
- /* @__PURE__ */ jsx("span", {
237
- className: "agent-muted",
238
- children: t.available ? t.description ?? t.id : t.reason
239
- })
240
- ] })]
241
- }, t.id)) }),
242
- /* @__PURE__ */ jsx("div", {
243
- className: "agent-row",
244
- children: /* @__PURE__ */ jsx("button", {
245
- type: "button",
246
- className: "agent-btn",
247
- "data-primary": "",
248
- disabled: !canSend,
249
- onClick: send,
250
- children: "Dispatch"
251
- })
252
- }),
253
- runs.length > 0 && /* @__PURE__ */ jsx("ul", {
254
- className: "agent-list",
255
- "aria-label": "Dispatched runs",
256
- children: runs.map((run) => /* @__PURE__ */ jsxs("li", {
257
- className: "agent-row agent-mono",
258
- children: [
259
- /* @__PURE__ */ jsx("span", {
260
- className: "agent-badge",
261
- "data-status": run.status,
262
- children: run.status
263
- }),
264
- /* @__PURE__ */ jsx("span", {
265
- className: "agent-grow",
266
- title: run.title,
267
- children: run.title
268
- }),
269
- /* @__PURE__ */ jsxs("span", {
270
- className: "agent-muted agent-grow",
271
- title: run.detail,
272
- children: [run.target, run.detail ? ` · ${run.detail}` : ""]
273
- })
274
- ]
275
- }, run.id))
276
- })
277
- ]
278
- });
279
- }
280
- //#endregion
281
- //#region src/plugins/agent/sessions-panel.tsx
282
- function age(iso) {
283
- if (!iso) return "";
284
- const seconds = Math.max(0, Math.round((Date.now() - Date.parse(iso)) / 1e3));
285
- if (seconds < 60) return `${seconds}s`;
286
- if (seconds < 3600) return `${Math.round(seconds / 60)}m`;
287
- if (seconds < 86400) return `${Math.round(seconds / 3600)}h`;
288
- return `${Math.round(seconds / 86400)}d`;
289
- }
290
- function SessionRow({ session }) {
291
- return /* @__PURE__ */ jsxs("li", {
292
- className: "agent-row agent-mono",
293
- title: session.detail ?? session.id,
294
- children: [
295
- /* @__PURE__ */ jsx("span", {
296
- className: "agent-badge",
297
- "data-status": session.status,
298
- children: session.status
299
- }),
300
- /* @__PURE__ */ jsx("span", {
301
- className: "agent-grow",
302
- children: session.title
303
- }),
304
- /* @__PURE__ */ jsxs("span", {
305
- className: "agent-muted",
306
- children: [
307
- session.provider,
308
- " ",
309
- age(session.updatedAt ?? session.startedAt)
310
- ]
311
- })
312
- ]
313
- });
314
- }
315
- function SessionsPanel({ ctx, intervalMs }) {
316
- const [data, setData] = useState(null);
317
- const [error, setError] = useState(null);
318
- const load = useCallback(async () => {
319
- try {
320
- setData(await ctx.api("/sessions"));
321
- setError(null);
322
- } catch (e) {
323
- setError(e instanceof HudApiError ? `HTTP ${e.status}` : String(e));
324
- }
325
- }, [ctx]);
326
- useEffect(() => {
327
- load();
328
- const timer = setInterval(() => {
329
- if (!document.hidden) load();
330
- }, intervalMs);
331
- return () => clearInterval(timer);
332
- }, [load, intervalMs]);
333
- return /* @__PURE__ */ jsxs("div", {
334
- className: "agent",
335
- children: [
336
- /* @__PURE__ */ jsx("style", { children: AGENT_CSS }),
337
- /* @__PURE__ */ jsxs("div", {
338
- className: "agent-row",
339
- children: [/* @__PURE__ */ jsx("span", {
340
- className: "agent-grow agent-muted",
341
- children: data ? `${data.sessions.length} sessions` : "Loading…"
342
- }), /* @__PURE__ */ jsx("button", {
343
- type: "button",
344
- className: "agent-btn",
345
- onClick: () => void load(),
346
- children: "Refresh"
347
- })]
348
- }),
349
- error && /* @__PURE__ */ jsxs("p", {
350
- className: "empty",
351
- children: ["Sessions unavailable: ", error]
352
- }),
353
- data?.errors.map((e) => /* @__PURE__ */ jsxs("p", {
354
- className: "empty",
355
- children: [
356
- e.provider,
357
- ": ",
358
- e.error
359
- ]
360
- }, e.provider)),
361
- data && data.sessions.length === 0 && /* @__PURE__ */ jsx("p", {
362
- className: "empty",
363
- children: "No sessions."
364
- }),
365
- data && data.sessions.length > 0 && /* @__PURE__ */ jsx("ul", {
366
- className: "agent-list",
367
- "aria-label": "Agent sessions",
368
- children: data.sessions.map((session) => /* @__PURE__ */ jsx(SessionRow, { session }, `${session.provider}:${session.id}`))
369
- })
370
- ]
371
- });
372
- }
373
29
  //#endregion
374
30
  //#region src/plugins/agent/index.tsx
31
+ const DispatchPanel = lazy(() => import("../dispatch-panel-B-xr_Giy.js"));
32
+ const SessionsPanel = lazy(() => import("../sessions-panel-COvhPAzv.js"));
375
33
  /**
376
34
  * Dispatch panel: the last grab plus an instruction, sent to one of the
377
35
  * server's providers (`hermes()`, `claudeCode()`). Mount the server half from
@@ -0,0 +1,92 @@
1
+ import { n as ScreenshotRequest, r as ScreenshotResponse, t as CAPTURE_CAPABILITY } from "../../types-BIgGf-0C.js";
2
+ //#region src/plugins/capture/server.d.ts
3
+ /**
4
+ * The slice of Playwright the route uses, declared structurally so the
5
+ * package's types never depend on `playwright` being installed. A real
6
+ * `Browser` satisfies it; tests pass a fake.
7
+ */
8
+ export interface ScreenshotBrowser {
9
+ newContext(options: {
10
+ viewport: {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ deviceScaleFactor: number;
15
+ }): Promise<ScreenshotContext>;
16
+ close(): Promise<unknown>;
17
+ }
18
+ export interface ScreenshotContext {
19
+ addCookies(cookies: {
20
+ name: string;
21
+ value: string;
22
+ url: string;
23
+ }[]): Promise<unknown>;
24
+ newPage(): Promise<ScreenshotPage>;
25
+ }
26
+ export interface ScreenshotPage {
27
+ goto(url: string, options: {
28
+ waitUntil: "load" | "networkidle";
29
+ timeout: number;
30
+ }): Promise<unknown>;
31
+ addStyleTag(options: {
32
+ content: string;
33
+ }): Promise<unknown>;
34
+ locator(selector: string): ScreenshotLocator;
35
+ screenshot(options: {
36
+ type: "png";
37
+ timeout: number;
38
+ }): Promise<Uint8Array>;
39
+ }
40
+ export interface ScreenshotLocator {
41
+ first(): ScreenshotLocator;
42
+ screenshot(options: {
43
+ type: "png";
44
+ timeout: number;
45
+ }): Promise<Uint8Array>;
46
+ }
47
+ export interface ScreenshotServerOptions {
48
+ /**
49
+ * Starts the browser for one screenshot. Default: `chromium.launch()` from
50
+ * `playwright`, loaded on first use; without the package, or without its
51
+ * Chromium, the route answers 503 with a setup hint.
52
+ */
53
+ launch?: () => Promise<ScreenshotBrowser>;
54
+ /** Page load budget. Default 15 s. */
55
+ loadTimeoutMs?: number;
56
+ /** How long to wait for the grabbed element before falling back to the viewport. Default 5 s. */
57
+ elementTimeoutMs?: number;
58
+ }
59
+ export declare const INSTALL_HINT = "bun add -d playwright && bunx playwright install chromium";
60
+ export declare const BROWSER_HINT = "bunx playwright install chromium";
61
+ /** A screenshot cannot be taken on this server; the hint says what to install. */
62
+ export declare class ScreenshotUnavailable extends Error {
63
+ readonly hint: string;
64
+ constructor(message: string, hint: string);
65
+ }
66
+ /** Same-origin only, http(s) only. */
67
+ export declare function sameOriginUrl(url: string, request: Request): URL | null;
68
+ /** Width and height from a PNG's IHDR chunk; 0×0 when the bytes are not a PNG. */
69
+ export declare function pngSize(png: Uint8Array): {
70
+ width: number;
71
+ height: number;
72
+ };
73
+ /**
74
+ * Server half of the `capture` plugin: `POST /screenshot` renders a
75
+ * same-origin URL in headless Chromium at the grab's viewport, with the
76
+ * request's cookies, crops to the grabbed selector (the viewport when the
77
+ * element is not there) and answers the PNG base64 encoded. Non-same-origin
78
+ * URLs answer 400; a server without Playwright answers 503 with a setup hint,
79
+ * which the Dispatch panel shows while the dispatch itself goes on without
80
+ * an image.
81
+ */
82
+ export declare function screenshot({ launch, loadTimeoutMs, elementTimeoutMs }?: ScreenshotServerOptions): {
83
+ readonly id: "capture";
84
+ readonly capability: "capture.screenshot";
85
+ readonly routes: {
86
+ readonly "/screenshot": {
87
+ readonly POST: (request: Request) => Promise<Response>;
88
+ };
89
+ };
90
+ };
91
+ //#endregion
92
+ export { CAPTURE_CAPABILITY, type ScreenshotRequest, type ScreenshotResponse };