@hansenexus/hud 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +782 -6
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/access-C7zlaqj6.js +100 -0
- package/dist/access-D_ewAEJG.d.ts +61 -0
- package/dist/access-panel-CEfTr9ZI.js +123 -0
- package/dist/adapter-BYoxPYTI.d.ts +33 -0
- package/dist/adapter-hcwmJtNx.js +65 -0
- package/dist/auto/runtime.d.ts +65 -0
- package/dist/auto/runtime.js +50 -0
- package/dist/auto.d.ts +15 -0
- package/dist/auto.js +33 -0
- package/dist/capabilities-rDSKjXpq.js +110 -0
- package/dist/capture-CwrIwLqi.js +300 -0
- package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +275 -0
- package/dist/data-panel-DhxAmP91.js +817 -0
- package/dist/data-store-ChF1td_P.js +164 -0
- package/dist/define-hud-CHPedaQ5.d.ts +50 -0
- package/dist/design-D0kGgPoP.js +87 -0
- package/dist/detect-BxHZ0pxW.d.ts +25 -0
- package/dist/detect-CHZiSeZs.js +63 -0
- package/dist/dispatch-panel-B-xr_Giy.js +279 -0
- package/dist/env-CApnbI0r.d.ts +19 -0
- package/dist/env-CaiFPIhF.js +31 -0
- package/dist/file-xdSaQ2uR.js +103 -0
- package/dist/flags-DVtaJ8pQ.d.ts +58 -0
- package/dist/flags.d.ts +2 -0
- package/dist/flags.js +82 -0
- package/dist/force-state-BaqWsmrf.js +153 -0
- package/dist/force-state-CCqoTfVB.d.ts +23 -0
- package/dist/force-state-panel-_otVYh9i.js +97 -0
- package/dist/generate-C8lQl3Eh.js +53 -0
- package/dist/handler-BpVhxEmU.js +106 -0
- package/dist/handler-DtYVCZY6.d.ts +39 -0
- package/dist/index-BAV_1W8a.d.ts +43 -0
- package/dist/index-BJ26pse9.d.ts +70 -0
- package/dist/index-BnQ0dTZf.d.ts +19 -0
- package/dist/index-CwfX-W87.d.ts +72 -0
- package/dist/index-DcH9V3cU.d.ts +48 -0
- package/dist/index-DqOyNf1u.d.ts +65 -0
- package/dist/index-DstI_ike.d.ts +66 -0
- package/dist/index-Dxz4fn4j.d.ts +42 -0
- package/dist/index-Hhh7OXzU.d.ts +129 -0
- package/dist/index-ReFbhQ9p.d.ts +25 -0
- package/dist/index-RgXfMBuW.d.ts +48 -0
- package/dist/index-gCZBO53s.d.ts +73 -0
- package/dist/index.d.ts +6 -36
- package/dist/index.js +798 -240
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/marker-C66LxOhJ.d.ts +9 -0
- package/dist/marker-CMrvxPmS.d.ts +12 -0
- package/dist/marker-DjeGvL-F.js +9 -0
- package/dist/marker-uZYPOJ4M.js +12 -0
- package/dist/markers.d.ts +3 -0
- package/dist/markers.js +3 -0
- package/dist/meta-Bv0sEao3.js +6 -0
- package/dist/meta-C_G7MB5w.d.ts +49 -0
- package/dist/mocks-CA-wM2SB.d.ts +109 -0
- package/dist/mocks-ESiRqk9o.js +150 -0
- package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
- package/dist/next/config.d.ts +52 -0
- package/dist/next/config.js +78 -0
- package/dist/next.d.ts +14 -19
- package/dist/next.js +7 -30
- package/dist/observe-CdDnDBRP.js +89 -0
- package/dist/observe-panel-Cgp1M8oT.js +347 -0
- package/dist/ops-panel-CEqDe_UT.js +234 -0
- package/dist/payload-MUQ9ciER.d.ts +92 -0
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +122 -0
- package/dist/plugins/access/server.js +340 -0
- package/dist/plugins/access.d.ts +41 -0
- package/dist/plugins/access.js +51 -0
- package/dist/plugins/agent/server.d.ts +94 -0
- package/dist/plugins/agent/server.js +455 -0
- package/dist/plugins/agent.d.ts +37 -0
- package/dist/plugins/agent.js +69 -0
- package/dist/plugins/capture/server.d.ts +92 -0
- package/dist/plugins/capture/server.js +248 -0
- package/dist/plugins/capture.d.ts +24 -0
- package/dist/plugins/capture.js +70 -0
- package/dist/plugins/data/msw-browser.d.ts +2 -0
- package/dist/plugins/data/msw-browser.js +39 -0
- package/dist/plugins/data/msw-node.d.ts +36 -0
- package/dist/plugins/data/msw-node.js +68 -0
- package/dist/plugins/data/server.d.ts +257 -0
- package/dist/plugins/data/server.js +717 -0
- package/dist/plugins/data.d.ts +6 -0
- package/dist/plugins/data.js +51 -0
- package/dist/plugins/design/server.d.ts +54 -0
- package/dist/plugins/design/server.js +198 -0
- package/dist/plugins/design.d.ts +5 -0
- package/dist/plugins/design.js +4 -0
- package/dist/plugins/inspect/convex.d.ts +2 -0
- package/dist/plugins/inspect/convex.js +486 -0
- package/dist/plugins/inspect/react-query.d.ts +2 -0
- package/dist/plugins/inspect/react-query.js +225 -0
- package/dist/plugins/inspect/sockets.d.ts +51 -0
- package/dist/plugins/inspect/sockets.js +397 -0
- package/dist/plugins/inspect/swr.d.ts +2 -0
- package/dist/plugins/inspect/swr.js +218 -0
- package/dist/plugins/inspect.d.ts +4 -0
- package/dist/plugins/inspect.js +3 -0
- package/dist/plugins/observe.d.ts +4 -0
- package/dist/plugins/observe.js +2 -0
- package/dist/plugins/ops/server.d.ts +82 -0
- package/dist/plugins/ops/server.js +381 -0
- package/dist/plugins/ops.d.ts +27 -0
- package/dist/plugins/ops.js +41 -0
- package/dist/plugins/routes/server.d.ts +88 -0
- package/dist/plugins/routes/server.js +62 -0
- package/dist/plugins/routes.d.ts +3 -0
- package/dist/plugins/routes.js +216 -0
- package/dist/plugins/seo.d.ts +2 -0
- package/dist/plugins/seo.js +2 -0
- package/dist/plugins/vitals.d.ts +2 -25
- package/dist/plugins/vitals.js +4 -86
- package/dist/plugins-BZvDqGx5.d.ts +144 -0
- package/dist/{plugins-CzUiTn_r.js → plugins-DVy_vaYr.js} +3 -1
- package/dist/poll-CjKsWZi8.js +89 -0
- package/dist/requests-BwD6MKEq.js +282 -0
- package/dist/requests-CJrUf465.d.ts +50 -0
- package/dist/review.d.ts +181 -0
- package/dist/review.js +1017 -0
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/selector-NSYSe7AZ.js +28 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +3 -39
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/shortcut-s_mjGeU8.js +179 -0
- package/dist/state-CjjZPjPJ.js +40 -0
- package/dist/state-boundary.d.ts +26 -0
- package/dist/state-boundary.js +61 -0
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/store-CQqIIKTc.js +59 -0
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/styles-BA8ueHoV.js +342 -0
- package/dist/styles-DKU_P8MH.js +139 -0
- package/dist/styles-DPpDPmzi.js +68 -0
- package/dist/tokens-panel-CbMQfasZ.js +142 -0
- package/dist/types-B-ulf2Jp.js +8 -0
- package/dist/types-BIgGf-0C.d.ts +25 -0
- package/dist/types-BIkI-qN8.js +30 -0
- package/dist/types-Cxh4twqc.d.ts +50 -0
- package/dist/types-DIdPfjtV.js +6 -0
- package/dist/types-DaJcsEjO.d.ts +44 -0
- package/dist/types-Dn68psVz.d.ts +118 -0
- package/dist/types-f3jlNxzw.d.ts +92 -0
- package/dist/types-szkr2QOF.d.ts +39 -0
- package/dist/unlock-store-4V3vR4Eg.js +96 -0
- package/dist/variant-groups-TIfO3NIj.js +137 -0
- package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
- package/dist/variants-panel-BDoSkwBJ.js +457 -0
- package/dist/variants-types-CcRf119M.d.ts +63 -0
- package/dist/variants.d.ts +43 -0
- package/dist/variants.js +83 -0
- package/dist/vitals-panel-BCmMUntW.js +30 -0
- package/dist/vite.d.ts +37 -0
- package/dist/vite.js +134 -0
- package/package.json +85 -5
- package/dist/define-hud-BHQR8Lbv.d.ts +0 -31
- package/dist/plugins-1QmTmZyL.d.ts +0 -76
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
|
|
2
|
+
import { t as refuseCrossSite } from "../../same-origin-BGet22CC.js";
|
|
3
|
+
//#region src/plugins/agent/prompt.ts
|
|
4
|
+
/** The task text every provider receives: grab context first, then the instruction. */
|
|
5
|
+
function dispatchPrompt({ note, payload, hints = [] }) {
|
|
6
|
+
const instruction = note.trim() || "Improve the grabbed element (see context).";
|
|
7
|
+
if (!payload) return [
|
|
8
|
+
`Instruction: ${instruction}`,
|
|
9
|
+
"",
|
|
10
|
+
"Task: apply the instruction and run the project's checks."
|
|
11
|
+
].join("\n");
|
|
12
|
+
const { component, anchor } = payload;
|
|
13
|
+
const lines = [
|
|
14
|
+
`HUD dispatch from ${payload.app}, page ${payload.url || payload.route}.`,
|
|
15
|
+
`Grabbed element: ${anchor.label}`,
|
|
16
|
+
`Selector (from <body>): ${anchor.selector}`
|
|
17
|
+
];
|
|
18
|
+
if (component) {
|
|
19
|
+
const owners = component.owners.length > 0 ? ` inside ${component.owners.join(" < ")}` : "";
|
|
20
|
+
lines.push(`React component: <${component.name}>${owners}`);
|
|
21
|
+
if (component.source) lines.push(`Source hint (from React; line approximate): ${component.source}`);
|
|
22
|
+
}
|
|
23
|
+
if (hints.length > 0) lines.push(`Component manifest matches (best effort, verify): ${hints.map((h) => h.path).join(", ")}`);
|
|
24
|
+
if (!component?.source && hints.length === 0) lines.push("No source hint: locate the component from the route and selector.");
|
|
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.");
|
|
32
|
+
return lines.join("\n");
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/plugins/agent/providers/claude-code.ts
|
|
36
|
+
/** A transcript touched within this window counts as a running session. */
|
|
37
|
+
const ACTIVE_MS = 12e4;
|
|
38
|
+
/** Enough of a transcript to find its summary or first prompt without reading megabytes. */
|
|
39
|
+
const HEAD_BYTES = 65536;
|
|
40
|
+
const defaultArgs = (prompt) => [
|
|
41
|
+
"-p",
|
|
42
|
+
prompt,
|
|
43
|
+
"--permission-mode",
|
|
44
|
+
"acceptEdits"
|
|
45
|
+
];
|
|
46
|
+
/** Claude Code keeps transcripts in `~/.claude/projects/<cwd with every non-alphanumeric as ->`. */
|
|
47
|
+
function projectDirName(cwd) {
|
|
48
|
+
return cwd.replace(/[^a-zA-Z0-9]/g, "-");
|
|
49
|
+
}
|
|
50
|
+
/** Summary line, else first plain user prompt, from the head of a transcript. */
|
|
51
|
+
function transcriptTitle(head) {
|
|
52
|
+
let prompt;
|
|
53
|
+
for (const line of head.split("\n")) {
|
|
54
|
+
let entry;
|
|
55
|
+
try {
|
|
56
|
+
entry = JSON.parse(line);
|
|
57
|
+
} catch {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (entry.type === "summary" && typeof entry.summary === "string") return entry.summary;
|
|
61
|
+
if (prompt || entry.type !== "user") continue;
|
|
62
|
+
const content = entry.message?.content;
|
|
63
|
+
const text = typeof content === "string" ? content : Array.isArray(content) ? content.find((c) => c?.type === "text")?.text : void 0;
|
|
64
|
+
if (typeof text === "string" && text.trim() && !text.trimStart().startsWith("<")) prompt = text.trim().split("\n")[0];
|
|
65
|
+
}
|
|
66
|
+
return prompt?.slice(0, 120);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Node built-ins, loaded on first use. A static import would make the whole
|
|
70
|
+
* server entry unloadable wherever `node:` modules are missing (an edge
|
|
71
|
+
* route, the playground's MSW worker), even for apps that only use `hermes()`.
|
|
72
|
+
*/
|
|
73
|
+
async function loadNode() {
|
|
74
|
+
const [childProcess, fs, fsp, os, path, proc] = await Promise.all([
|
|
75
|
+
import("node:child_process"),
|
|
76
|
+
import("node:fs"),
|
|
77
|
+
import("node:fs/promises"),
|
|
78
|
+
import("node:os"),
|
|
79
|
+
import("node:path"),
|
|
80
|
+
import("node:process")
|
|
81
|
+
]);
|
|
82
|
+
return {
|
|
83
|
+
childProcess,
|
|
84
|
+
fs,
|
|
85
|
+
fsp,
|
|
86
|
+
os,
|
|
87
|
+
path,
|
|
88
|
+
env: proc.env
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async function readHead({ fsp }, path) {
|
|
92
|
+
const file = await fsp.open(path, "r");
|
|
93
|
+
try {
|
|
94
|
+
const buffer = new Uint8Array(HEAD_BYTES);
|
|
95
|
+
const { bytesRead } = await file.read(buffer, 0, HEAD_BYTES, 0);
|
|
96
|
+
return new TextDecoder().decode(buffer.subarray(0, bytesRead));
|
|
97
|
+
} finally {
|
|
98
|
+
await file.close();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Dispatches to a local Claude Code: each run is `claude -p <prompt>` spawned
|
|
103
|
+
* (argv, no shell) in `cwd`, detached so it outlives a dev-server reload, with
|
|
104
|
+
* its output in a log file. Sessions are the runs started here plus the most
|
|
105
|
+
* recent Claude Code transcripts of `cwd`.
|
|
106
|
+
*/
|
|
107
|
+
function claudeCode({ cwd: cwdOption, command = "claude", args = defaultArgs, label = "Claude Code (local)", logDir: logDirOption, transcripts = 8, home: homeOption, spawn: spawnOption } = {}) {
|
|
108
|
+
const runs = /* @__PURE__ */ new Map();
|
|
109
|
+
let node;
|
|
110
|
+
const nodeApi = () => {
|
|
111
|
+
node ??= loadNode();
|
|
112
|
+
return node;
|
|
113
|
+
};
|
|
114
|
+
const cwdOf = ({ path }) => cwdOption ?? path.resolve();
|
|
115
|
+
async function listTranscripts() {
|
|
116
|
+
const api = await nodeApi();
|
|
117
|
+
const { fsp, path } = api;
|
|
118
|
+
const home = homeOption ?? api.os.homedir();
|
|
119
|
+
const dir = path.join(home, ".claude", "projects", projectDirName(cwdOf(api)));
|
|
120
|
+
let names;
|
|
121
|
+
try {
|
|
122
|
+
names = (await fsp.readdir(dir)).filter((name) => name.endsWith(".jsonl"));
|
|
123
|
+
} catch {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
const recent = (await Promise.all(names.map(async (name) => {
|
|
127
|
+
const file = path.join(dir, name);
|
|
128
|
+
return {
|
|
129
|
+
file,
|
|
130
|
+
mtime: (await fsp.stat(file)).mtimeMs
|
|
131
|
+
};
|
|
132
|
+
}))).sort((a, b) => b.mtime - a.mtime).slice(0, transcripts);
|
|
133
|
+
return Promise.all(recent.map(async ({ file, mtime }) => {
|
|
134
|
+
const id = path.basename(file, ".jsonl");
|
|
135
|
+
return {
|
|
136
|
+
provider: "claude-code",
|
|
137
|
+
id,
|
|
138
|
+
title: transcriptTitle(await readHead(api, file).catch(() => "")) ?? id.slice(0, 8),
|
|
139
|
+
status: Date.now() - mtime < ACTIVE_MS ? "running" : "idle",
|
|
140
|
+
updatedAt: new Date(mtime).toISOString()
|
|
141
|
+
};
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
id: "claude-code",
|
|
146
|
+
label,
|
|
147
|
+
description: cwdOption ? `claude -p in ${cwdOption}` : "claude -p in the dev server's directory",
|
|
148
|
+
async dispatch(order) {
|
|
149
|
+
const api = await nodeApi();
|
|
150
|
+
const { fs, path } = api;
|
|
151
|
+
const logDir = logDirOption ?? path.join(api.os.tmpdir(), "hud-agent");
|
|
152
|
+
const spawn = spawnOption ?? api.childProcess.spawn;
|
|
153
|
+
await api.fsp.mkdir(logDir, { recursive: true });
|
|
154
|
+
const id = `run-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
|
|
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
|
+
}
|
|
163
|
+
const fd = fs.openSync(log, "a", 384);
|
|
164
|
+
let child;
|
|
165
|
+
try {
|
|
166
|
+
child = spawn(command, args(prompt), {
|
|
167
|
+
cwd: cwdOf(api),
|
|
168
|
+
detached: true,
|
|
169
|
+
stdio: [
|
|
170
|
+
"ignore",
|
|
171
|
+
fd,
|
|
172
|
+
fd
|
|
173
|
+
],
|
|
174
|
+
env: api.env
|
|
175
|
+
});
|
|
176
|
+
await new Promise((resolve, reject) => {
|
|
177
|
+
child.once("spawn", resolve);
|
|
178
|
+
child.once("error", reject);
|
|
179
|
+
});
|
|
180
|
+
} finally {
|
|
181
|
+
fs.closeSync(fd);
|
|
182
|
+
}
|
|
183
|
+
const run = {
|
|
184
|
+
id,
|
|
185
|
+
title: order.note.trim().split("\n")[0] || order.payload?.anchor.label || "dispatch",
|
|
186
|
+
status: "running",
|
|
187
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
188
|
+
log
|
|
189
|
+
};
|
|
190
|
+
runs.set(id, run);
|
|
191
|
+
child.once("exit", (code) => {
|
|
192
|
+
run.status = code === 0 ? "done" : "failed";
|
|
193
|
+
run.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
194
|
+
});
|
|
195
|
+
child.unref();
|
|
196
|
+
return {
|
|
197
|
+
runId: id,
|
|
198
|
+
detail: log
|
|
199
|
+
};
|
|
200
|
+
},
|
|
201
|
+
async sessions() {
|
|
202
|
+
return [...[...runs.values()].map((run) => ({
|
|
203
|
+
provider: "claude-code",
|
|
204
|
+
id: run.id,
|
|
205
|
+
title: run.title,
|
|
206
|
+
status: run.status,
|
|
207
|
+
startedAt: run.startedAt,
|
|
208
|
+
...run.updatedAt ? { updatedAt: run.updatedAt } : {},
|
|
209
|
+
detail: run.log
|
|
210
|
+
})).reverse(), ...await listTranscripts()];
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/plugins/agent/providers/hermes.ts
|
|
216
|
+
const STATUS = {
|
|
217
|
+
queued: "queued",
|
|
218
|
+
running: "running",
|
|
219
|
+
succeeded: "done",
|
|
220
|
+
failed: "failed"
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Dispatches to a Hermes Agent API server: `POST /v1/runs` starts a
|
|
224
|
+
* background run (202 `{ run_id }`), `GET /v1/jobs` lists runs for the
|
|
225
|
+
* Sessions panel. The token never leaves the server.
|
|
226
|
+
*/
|
|
227
|
+
function hermes({ baseUrl, token, instructions, label = "Hermes", timeoutMs = 1e4, fetch: fetchImpl = globalThis.fetch }) {
|
|
228
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
229
|
+
const bearer = () => (typeof token === "function" ? token() : token)?.trim() || void 0;
|
|
230
|
+
async function call(path, init) {
|
|
231
|
+
const auth = bearer();
|
|
232
|
+
if (!auth) throw new Error("no Hermes token configured");
|
|
233
|
+
const res = await fetchImpl(`${base}${path}`, {
|
|
234
|
+
...init,
|
|
235
|
+
headers: {
|
|
236
|
+
Accept: "application/json",
|
|
237
|
+
Authorization: `Bearer ${auth}`,
|
|
238
|
+
...init?.body ? { "Content-Type": "application/json" } : {}
|
|
239
|
+
},
|
|
240
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
241
|
+
});
|
|
242
|
+
if (!res.ok) throw new Error(`Hermes answered ${res.status}`);
|
|
243
|
+
return res.json();
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
id: "hermes",
|
|
247
|
+
label,
|
|
248
|
+
description: "Remote Hermes Agent run",
|
|
249
|
+
status: () => bearer() ? { available: true } : {
|
|
250
|
+
available: false,
|
|
251
|
+
reason: "no Hermes token configured"
|
|
252
|
+
},
|
|
253
|
+
async dispatch(order) {
|
|
254
|
+
const body = await call("/v1/runs", {
|
|
255
|
+
method: "POST",
|
|
256
|
+
body: JSON.stringify({
|
|
257
|
+
input: order.prompt,
|
|
258
|
+
...instructions ? { instructions } : {}
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
if (typeof body?.run_id !== "string" || !body.run_id) throw new Error("Hermes accepted the run but returned no run_id");
|
|
262
|
+
return { runId: body.run_id };
|
|
263
|
+
},
|
|
264
|
+
async sessions() {
|
|
265
|
+
const jobs = await call("/v1/jobs");
|
|
266
|
+
if (!Array.isArray(jobs)) throw new Error("Hermes /v1/jobs: expected an array");
|
|
267
|
+
return jobs.map((job) => {
|
|
268
|
+
const session = {
|
|
269
|
+
provider: "hermes",
|
|
270
|
+
id: job.id,
|
|
271
|
+
title: job.task?.split("\n")[0]?.slice(0, 120) || job.id,
|
|
272
|
+
status: STATUS[job.status] ?? "idle"
|
|
273
|
+
};
|
|
274
|
+
if (typeof job.createdAt === "number") {
|
|
275
|
+
session.startedAt = new Date(job.createdAt).toISOString();
|
|
276
|
+
if (typeof job.durationMs === "number") session.updatedAt = new Date(job.createdAt + job.durationMs).toISOString();
|
|
277
|
+
}
|
|
278
|
+
return session;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/plugins/agent/server.ts
|
|
285
|
+
function message(error) {
|
|
286
|
+
return error instanceof Error ? error.message : String(error);
|
|
287
|
+
}
|
|
288
|
+
function isRecord(value) {
|
|
289
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
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
|
+
}
|
|
312
|
+
/** Shape check, not a schema: enough that the prompt builder cannot throw on it. */
|
|
313
|
+
function parseBody(value) {
|
|
314
|
+
if (!isRecord(value) || typeof value.target !== "string") return null;
|
|
315
|
+
const note = typeof value.note === "string" ? value.note : "";
|
|
316
|
+
const payload = value.payload;
|
|
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));
|
|
318
|
+
if (payload != null && !validPayload) return null;
|
|
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
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
target: value.target,
|
|
331
|
+
note,
|
|
332
|
+
payload: grab,
|
|
333
|
+
hints
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function checkUnique(providers) {
|
|
337
|
+
const ids = /* @__PURE__ */ new Set();
|
|
338
|
+
for (const provider of providers) {
|
|
339
|
+
if (ids.has(provider.id)) throw new Error(`hud agent: duplicate provider id "${provider.id}"`);
|
|
340
|
+
ids.add(provider.id);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Server half of `agentDispatch`: `GET /targets` lists the providers,
|
|
345
|
+
* `POST /dispatch` hands a grab plus instruction to one of them.
|
|
346
|
+
*/
|
|
347
|
+
function agentDispatch({ providers }) {
|
|
348
|
+
checkUnique(providers);
|
|
349
|
+
const byId = new Map(providers.map((provider) => [provider.id, provider]));
|
|
350
|
+
return definePlugin({
|
|
351
|
+
id: "agent-dispatch",
|
|
352
|
+
routes: {
|
|
353
|
+
"/targets": { GET: async () => {
|
|
354
|
+
const targets = await Promise.all(providers.map(async (provider) => {
|
|
355
|
+
const info = {
|
|
356
|
+
id: provider.id,
|
|
357
|
+
label: provider.label,
|
|
358
|
+
available: true
|
|
359
|
+
};
|
|
360
|
+
if (provider.description) info.description = provider.description;
|
|
361
|
+
try {
|
|
362
|
+
const status = await provider.status?.() ?? { available: true };
|
|
363
|
+
if (!status.available) return {
|
|
364
|
+
...info,
|
|
365
|
+
available: false,
|
|
366
|
+
reason: status.reason
|
|
367
|
+
};
|
|
368
|
+
} catch (error) {
|
|
369
|
+
return {
|
|
370
|
+
...info,
|
|
371
|
+
available: false,
|
|
372
|
+
reason: message(error)
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
return info;
|
|
376
|
+
}));
|
|
377
|
+
return Response.json(targets);
|
|
378
|
+
} },
|
|
379
|
+
"/dispatch": { POST: async (request) => {
|
|
380
|
+
const refusal = refuseCrossSite(request);
|
|
381
|
+
if (refusal) return refusal;
|
|
382
|
+
const body = parseBody(await request.json().catch(() => null));
|
|
383
|
+
if (!body) return Response.json({
|
|
384
|
+
ok: false,
|
|
385
|
+
error: "invalid dispatch"
|
|
386
|
+
}, { status: 400 });
|
|
387
|
+
const fail = (status, error) => Response.json({
|
|
388
|
+
ok: false,
|
|
389
|
+
target: body.target,
|
|
390
|
+
error
|
|
391
|
+
}, { status });
|
|
392
|
+
if (!body.note.trim() && !body.payload) return fail(400, "nothing to dispatch");
|
|
393
|
+
const provider = byId.get(body.target);
|
|
394
|
+
if (!provider) return fail(404, `unknown target "${body.target}"`);
|
|
395
|
+
try {
|
|
396
|
+
const status = await provider.status?.() ?? { available: true };
|
|
397
|
+
if (!status.available) return fail(409, status.reason);
|
|
398
|
+
const hints = body.hints ?? [];
|
|
399
|
+
const prompt = dispatchPrompt({
|
|
400
|
+
note: body.note,
|
|
401
|
+
payload: body.payload,
|
|
402
|
+
hints
|
|
403
|
+
});
|
|
404
|
+
const run = await provider.dispatch({
|
|
405
|
+
note: body.note,
|
|
406
|
+
payload: body.payload,
|
|
407
|
+
hints,
|
|
408
|
+
prompt
|
|
409
|
+
});
|
|
410
|
+
const receipt = {
|
|
411
|
+
ok: true,
|
|
412
|
+
target: provider.id,
|
|
413
|
+
runId: run.runId
|
|
414
|
+
};
|
|
415
|
+
if (run.detail) receipt.detail = run.detail;
|
|
416
|
+
return Response.json(receipt);
|
|
417
|
+
} catch (error) {
|
|
418
|
+
return fail(502, message(error));
|
|
419
|
+
}
|
|
420
|
+
} }
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/** Server half of `agentSessions`: `GET /sessions` merges every provider's sessions. */
|
|
425
|
+
function agentSessions({ providers }) {
|
|
426
|
+
checkUnique(providers);
|
|
427
|
+
const listing = providers.filter((provider) => provider.sessions);
|
|
428
|
+
return definePlugin({
|
|
429
|
+
id: "agent-sessions",
|
|
430
|
+
routes: { "/sessions": { GET: async () => {
|
|
431
|
+
const results = await Promise.allSettled(listing.map(async (provider) => {
|
|
432
|
+
return (await provider.status?.() ?? { available: true }).available ? await provider.sessions?.() ?? [] : [];
|
|
433
|
+
}));
|
|
434
|
+
const response = {
|
|
435
|
+
sessions: [],
|
|
436
|
+
errors: []
|
|
437
|
+
};
|
|
438
|
+
for (const [i, result] of results.entries()) {
|
|
439
|
+
const provider = listing[i]?.id ?? "unknown";
|
|
440
|
+
if (result.status === "fulfilled") response.sessions.push(...result.value);
|
|
441
|
+
else response.errors.push({
|
|
442
|
+
provider,
|
|
443
|
+
error: message(result.reason)
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
response.sessions.sort((a, b) => sortKey(b).localeCompare(sortKey(a)));
|
|
447
|
+
return Response.json(response);
|
|
448
|
+
} } }
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
function sortKey(session) {
|
|
452
|
+
return session.updatedAt ?? session.startedAt ?? "";
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
455
|
+
export { agentDispatch, agentSessions, claudeCode, dispatchPrompt, hermes };
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
//#region src/plugins/agent/index.d.ts
|
|
6
|
+
export interface AgentDispatchOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The app's component manifest. A grab is matched against it by route and
|
|
9
|
+
* label and the matches travel with the dispatch as extra source hints.
|
|
10
|
+
*/
|
|
11
|
+
componentHints?: readonly ComponentHint[];
|
|
12
|
+
/** Open the Dispatch panel when a grab completes. Default true. */
|
|
13
|
+
openOnGrab?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Dispatch panel: the last grab plus an instruction, sent to one of the
|
|
17
|
+
* server's providers (`hermes()`, `claudeCode()`). Mount the server half from
|
|
18
|
+
* `@hansenexus/hud/plugins/agent/server` in the catch-all route.
|
|
19
|
+
*/
|
|
20
|
+
export declare function agentDispatch({ componentHints, openOnGrab }?: AgentDispatchOptions): {
|
|
21
|
+
readonly id: "agent-dispatch";
|
|
22
|
+
readonly title: "Dispatch";
|
|
23
|
+
readonly panel: ({ ctx }: HudPluginProps) => import("react").JSX.Element;
|
|
24
|
+
readonly onGrab?: (_payload: GrabPayload, ctx: HudPluginContext) => void;
|
|
25
|
+
};
|
|
26
|
+
export interface AgentSessionsOptions {
|
|
27
|
+
/** Refresh interval while the panel is open and the tab visible. Default 10 s. */
|
|
28
|
+
intervalMs?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Sessions panel: runs and sessions of every provider that lists them. */
|
|
31
|
+
export declare function agentSessions({ intervalMs }?: AgentSessionsOptions): {
|
|
32
|
+
readonly id: "agent-sessions";
|
|
33
|
+
readonly title: "Sessions";
|
|
34
|
+
readonly panel: ({ ctx }: HudPluginProps) => import("react").JSX.Element;
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export type { AgentSession, AgentSessionStatus, DispatchBody, DispatchReceipt, DispatchTargetInfo, SessionsResponse };
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
|
5
|
+
/**
|
|
6
|
+
* Runs dispatched from this page. It outlives the panel (closing it unmounts
|
|
7
|
+
* the component), so it lives with the plugin instance.
|
|
8
|
+
*/
|
|
9
|
+
function createRunLog() {
|
|
10
|
+
let runs = [];
|
|
11
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
12
|
+
const set = (next) => {
|
|
13
|
+
runs = next;
|
|
14
|
+
for (const listener of listeners) listener();
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
get: () => runs,
|
|
18
|
+
subscribe: (listener) => {
|
|
19
|
+
listeners.add(listener);
|
|
20
|
+
return () => listeners.delete(listener);
|
|
21
|
+
},
|
|
22
|
+
add: (run) => set([run, ...runs].slice(0, 20)),
|
|
23
|
+
update: (id, patch) => set(runs.map((run) => run.id === id ? {
|
|
24
|
+
...run,
|
|
25
|
+
...patch
|
|
26
|
+
} : run))
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
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"));
|
|
33
|
+
/**
|
|
34
|
+
* Dispatch panel: the last grab plus an instruction, sent to one of the
|
|
35
|
+
* server's providers (`hermes()`, `claudeCode()`). Mount the server half from
|
|
36
|
+
* `@hansenexus/hud/plugins/agent/server` in the catch-all route.
|
|
37
|
+
*/
|
|
38
|
+
function agentDispatch({ componentHints, openOnGrab = true } = {}) {
|
|
39
|
+
const log = createRunLog();
|
|
40
|
+
function Panel({ ctx }) {
|
|
41
|
+
return /* @__PURE__ */ jsx(DispatchPanel, {
|
|
42
|
+
ctx,
|
|
43
|
+
log,
|
|
44
|
+
componentHints
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return definePlugin({
|
|
48
|
+
id: "agent-dispatch",
|
|
49
|
+
title: "Dispatch",
|
|
50
|
+
panel: Panel,
|
|
51
|
+
...openOnGrab ? { onGrab: (_payload, ctx) => ctx.open() } : {}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** Sessions panel: runs and sessions of every provider that lists them. */
|
|
55
|
+
function agentSessions({ intervalMs = 1e4 } = {}) {
|
|
56
|
+
function Panel({ ctx }) {
|
|
57
|
+
return /* @__PURE__ */ jsx(SessionsPanel, {
|
|
58
|
+
ctx,
|
|
59
|
+
intervalMs
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return definePlugin({
|
|
63
|
+
id: "agent-sessions",
|
|
64
|
+
title: "Sessions",
|
|
65
|
+
panel: Panel
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { agentDispatch, agentSessions };
|
|
@@ -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 };
|