@hansenexus/hud 0.1.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/LICENSE +21 -0
- package/README.md +48 -0
- package/chunk-0cj8dkk7.js +127 -0
- package/chunk-1atxwdhw.js +48 -0
- package/chunk-24vrg16w.js +39 -0
- package/chunk-3j9sm249.js +26 -0
- package/chunk-50pq4sg6.js +41 -0
- package/chunk-5gtx3pza.js +9 -0
- package/chunk-6gw4x08j.js +264 -0
- package/chunk-6jt8yg4m.js +117 -0
- package/chunk-71se605m.js +85 -0
- package/chunk-82nm9wcg.js +316 -0
- package/chunk-8tam7r3h.js +68 -0
- package/chunk-babjpqkb.js +52 -0
- package/chunk-c5y856ad.js +98 -0
- package/chunk-ghxh8926.js +172 -0
- package/chunk-hc2g0n35.js +24 -0
- package/chunk-k0vr8dsy.js +179 -0
- package/chunk-k50yfp5d.js +166 -0
- package/chunk-kyeb6qeq.js +95 -0
- package/chunk-msqkkqw7.js +140 -0
- package/chunk-nm82wr8r.js +58 -0
- package/chunk-r06bpmy6.js +79 -0
- package/chunk-t9eh4t0b.js +89 -0
- package/chunk-tf774c4w.js +115 -0
- package/chunk-v086j53b.js +19 -0
- package/chunk-wspz08q7.js +67 -0
- package/chunk-xezxydm3.js +47 -0
- package/chunk-xjn0896g.js +574 -0
- package/chunk-xztw0xyt.js +113 -0
- package/chunk-zzrpd92r.js +172 -0
- package/core/access.d.mts +53 -0
- package/core/access.js +27 -0
- package/core/api-types.d.mts +146 -0
- package/core/api-types.js +9 -0
- package/core/capabilities.d.mts +27 -0
- package/core/capabilities.js +14 -0
- package/core/capture-buffer.d.mts +37 -0
- package/core/capture-buffer.js +9 -0
- package/core/force-state.d.mts +68 -0
- package/core/force-state.js +21 -0
- package/core/mock-cookie.d.mts +30 -0
- package/core/mock-cookie.js +15 -0
- package/core/types.d.mts +59 -0
- package/core/types.js +9 -0
- package/hud-provider.d.mts +38 -0
- package/hud-provider.js +15 -0
- package/hud.d.mts +15 -0
- package/hud.js +18 -0
- package/index.d.mts +94 -0
- package/index.js +170 -0
- package/lazy-panel.d.mts +28 -0
- package/lazy-panel.js +11 -0
- package/package.json +153 -0
- package/panels/cicd-panel.d.mts +9 -0
- package/panels/cicd-panel.js +13 -0
- package/panels/debug-info-panel.d.mts +21 -0
- package/panels/debug-info-panel.js +9 -0
- package/panels/dispatch-panel.d.mts +10 -0
- package/panels/dispatch-panel.js +14 -0
- package/panels/env-info-panel.d.mts +9 -0
- package/panels/env-info-panel.js +12 -0
- package/panels/feature-flags-panel.d.mts +26 -0
- package/panels/feature-flags-panel.js +9 -0
- package/panels/force-state-panel.d.mts +11 -0
- package/panels/force-state-panel.js +113 -0
- package/panels/info-row.d.mts +21 -0
- package/panels/info-row.js +14 -0
- package/panels/mock-seed-panel.d.mts +15 -0
- package/panels/mock-seed-panel.js +14 -0
- package/panels/network-console-panel.d.mts +6 -0
- package/panels/network-console-panel.js +9 -0
- package/panels/role-switcher-panel.d.mts +28 -0
- package/panels/role-switcher-panel.js +9 -0
- package/panels/sessions-panel.d.mts +6 -0
- package/panels/sessions-panel.js +13 -0
- package/panels/tokens-panel.d.mts +38 -0
- package/panels/tokens-panel.js +9 -0
- package/panels/unlock-panel.d.mts +33 -0
- package/panels/unlock-panel.js +14 -0
- package/panels/variants-panel.d.mts +51 -0
- package/panels/variants-panel.js +12 -0
- package/panels/vitals-panel.d.mts +11 -0
- package/panels/vitals-panel.js +15 -0
- package/server/guard.d.mts +42 -0
- package/server/guard.js +12 -0
- package/server/unlock.d.mts +28 -0
- package/server/unlock.js +108 -0
- package/state-boundary.d.mts +25 -0
- package/state-boundary.js +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hansenexus GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @hansenexus/hud
|
|
2
|
+
|
|
3
|
+
A dev HUD for React apps. It gives you a drawer with panels (vitals, network and console
|
|
4
|
+
capture, env info, feature flags, forced UI states and more), and capability-gated access
|
|
5
|
+
that stays observe-only in production.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @hansenexus/hud
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The host provides the peers `react` and `react-dom` 19. `next` is optional: without Next,
|
|
14
|
+
alias `next/link` to a plain anchor component in your bundler.
|
|
15
|
+
|
|
16
|
+
## Use
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { Hud, type HudPanel, NetworkConsolePanel, VitalsPanel } from "@hansenexus/hud";
|
|
20
|
+
import { Activity, Terminal } from "lucide-react";
|
|
21
|
+
|
|
22
|
+
const panels: HudPanel[] = [
|
|
23
|
+
{ id: "vitals", label: "Vitals", icon: Activity, capability: "observe.app", content: <VitalsPanel />, order: 1 },
|
|
24
|
+
{ id: "net", label: "Net / Console", icon: Terminal, capability: "observe.app", content: <NetworkConsolePanel />, order: 2 },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export function DevHud() {
|
|
28
|
+
return <Hud config={{ appSlug: "my-app" }} panels={panels} />;
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Mount it only in development builds, for example behind `import.meta.env.DEV` and a lazy import.
|
|
33
|
+
|
|
34
|
+
## Tailwind v4
|
|
35
|
+
|
|
36
|
+
The panels use Tailwind utilities, and Tailwind does not scan `node_modules` on its own. Add
|
|
37
|
+
the package as a source in the stylesheet that imports Tailwind:
|
|
38
|
+
|
|
39
|
+
```css
|
|
40
|
+
@source "../node_modules/@hansenexus/hud";
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The path is relative to that stylesheet. If a panel renders unstyled, this line is missing
|
|
44
|
+
or points at the wrong place.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useHud
|
|
3
|
+
} from "./chunk-wspz08q7.js";
|
|
4
|
+
import {
|
|
5
|
+
InfoRow,
|
|
6
|
+
PanelSection,
|
|
7
|
+
ShortcutRow
|
|
8
|
+
} from "./chunk-kyeb6qeq.js";
|
|
9
|
+
import {
|
|
10
|
+
Badge
|
|
11
|
+
} from "./chunk-xztw0xyt.js";
|
|
12
|
+
import {
|
|
13
|
+
CAPABILITY_MATRIX
|
|
14
|
+
} from "./chunk-babjpqkb.js";
|
|
15
|
+
import {
|
|
16
|
+
HUD_CAPABILITIES
|
|
17
|
+
} from "./chunk-v086j53b.js";
|
|
18
|
+
|
|
19
|
+
// panels/env-info-panel.tsx
|
|
20
|
+
import { Boxes, Info, Monitor, ShieldCheck } from "lucide-react";
|
|
21
|
+
import { version as reactVersion } from "react";
|
|
22
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
23
|
+
"use client";
|
|
24
|
+
function EnvInfoPanel() {
|
|
25
|
+
const { config, env, can } = useHud();
|
|
26
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
27
|
+
className: "space-y-4",
|
|
28
|
+
children: [
|
|
29
|
+
/* @__PURE__ */ jsxs(PanelSection, {
|
|
30
|
+
icon: Boxes,
|
|
31
|
+
title: "App",
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsx(InfoRow, {
|
|
34
|
+
label: "App",
|
|
35
|
+
value: config.appSlug
|
|
36
|
+
}),
|
|
37
|
+
/* @__PURE__ */ jsxs("div", {
|
|
38
|
+
className: "flex items-center justify-between px-2 py-1",
|
|
39
|
+
children: [
|
|
40
|
+
/* @__PURE__ */ jsx("span", {
|
|
41
|
+
className: "text-[10px] text-muted-foreground",
|
|
42
|
+
children: "hud env"
|
|
43
|
+
}),
|
|
44
|
+
/* @__PURE__ */ jsx(Badge, {
|
|
45
|
+
variant: "outline",
|
|
46
|
+
className: "h-4 px-1.5 font-mono text-[10px] uppercase",
|
|
47
|
+
children: env
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
}),
|
|
51
|
+
/* @__PURE__ */ jsx(InfoRow, {
|
|
52
|
+
label: "Origin",
|
|
53
|
+
value: typeof window !== "undefined" ? window.location.origin : "—",
|
|
54
|
+
copyable: true
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ jsxs(PanelSection, {
|
|
59
|
+
icon: Monitor,
|
|
60
|
+
title: "Build",
|
|
61
|
+
children: [
|
|
62
|
+
/* @__PURE__ */ jsx(InfoRow, {
|
|
63
|
+
label: "NODE_ENV",
|
|
64
|
+
value: "production"
|
|
65
|
+
}),
|
|
66
|
+
/* @__PURE__ */ jsx(InfoRow, {
|
|
67
|
+
label: "React",
|
|
68
|
+
value: reactVersion
|
|
69
|
+
}),
|
|
70
|
+
/* @__PURE__ */ jsx(InfoRow, {
|
|
71
|
+
label: "Convex URL",
|
|
72
|
+
value: process.env.NEXT_PUBLIC_CONVEX_URL ?? "not set",
|
|
73
|
+
copyable: true
|
|
74
|
+
}),
|
|
75
|
+
/* @__PURE__ */ jsx(InfoRow, {
|
|
76
|
+
label: "App URL",
|
|
77
|
+
value: process.env.NEXT_PUBLIC_APP_URL ?? "not set"
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
}),
|
|
81
|
+
/* @__PURE__ */ jsxs(PanelSection, {
|
|
82
|
+
icon: ShieldCheck,
|
|
83
|
+
title: `Capabilities · ${env}`,
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ jsx("div", {
|
|
86
|
+
className: "grid grid-cols-2 gap-x-4",
|
|
87
|
+
children: HUD_CAPABILITIES.map((capability) => {
|
|
88
|
+
const granted = can(capability);
|
|
89
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
90
|
+
className: "flex items-center justify-between px-2 py-0.5",
|
|
91
|
+
title: granted ? undefined : `denied in ${env} (see CAPABILITY_MATRIX in core/capabilities.ts)`,
|
|
92
|
+
children: [
|
|
93
|
+
/* @__PURE__ */ jsx("span", {
|
|
94
|
+
className: `font-mono text-[10px] ${granted ? "" : "text-muted-foreground/50 line-through"}`,
|
|
95
|
+
children: capability
|
|
96
|
+
}),
|
|
97
|
+
/* @__PURE__ */ jsx("span", {
|
|
98
|
+
className: `h-1.5 w-1.5 rounded-full ${granted ? "bg-emerald-500" : "bg-muted-foreground/20"}`
|
|
99
|
+
})
|
|
100
|
+
]
|
|
101
|
+
}, capability);
|
|
102
|
+
})
|
|
103
|
+
}),
|
|
104
|
+
/* @__PURE__ */ jsxs("p", {
|
|
105
|
+
className: "px-2 text-[10px] text-muted-foreground/60",
|
|
106
|
+
children: [
|
|
107
|
+
CAPABILITY_MATRIX[env].length,
|
|
108
|
+
"/",
|
|
109
|
+
HUD_CAPABILITIES.length,
|
|
110
|
+
" granted — default deny, server routes re-check independently."
|
|
111
|
+
]
|
|
112
|
+
})
|
|
113
|
+
]
|
|
114
|
+
}),
|
|
115
|
+
/* @__PURE__ */ jsx(PanelSection, {
|
|
116
|
+
icon: Info,
|
|
117
|
+
title: "Shortcuts",
|
|
118
|
+
children: /* @__PURE__ */ jsx(ShortcutRow, {
|
|
119
|
+
keys: ["⌘", "⇧", "H"],
|
|
120
|
+
label: "Toggle hud"
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { EnvInfoPanel };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HUD_UNLOCK_COOKIE,
|
|
3
|
+
hudRequiresUnlock,
|
|
4
|
+
hudUnlockTtlMs,
|
|
5
|
+
readCookie,
|
|
6
|
+
resolveHudAccess,
|
|
7
|
+
verifyHudUnlockToken
|
|
8
|
+
} from "./chunk-r06bpmy6.js";
|
|
9
|
+
import {
|
|
10
|
+
hasCapability,
|
|
11
|
+
isHudVisible,
|
|
12
|
+
resolveHudEnv
|
|
13
|
+
} from "./chunk-babjpqkb.js";
|
|
14
|
+
|
|
15
|
+
// server/guard.ts
|
|
16
|
+
async function checkHudRequest(request, capability) {
|
|
17
|
+
const env = resolveHudEnv();
|
|
18
|
+
if (!isHudVisible(env)) {
|
|
19
|
+
return { ok: false, status: 404, error: "not found" };
|
|
20
|
+
}
|
|
21
|
+
if (!hasCapability(env, capability)) {
|
|
22
|
+
return { ok: false, status: 403, error: `capability ${capability} is denied in ${env}` };
|
|
23
|
+
}
|
|
24
|
+
const access = resolveHudAccess(env);
|
|
25
|
+
if (!hudRequiresUnlock(access)) {
|
|
26
|
+
return { ok: true, env };
|
|
27
|
+
}
|
|
28
|
+
const password = process.env.HUD_ACCESS_PASSWORD;
|
|
29
|
+
if (!password) {
|
|
30
|
+
return { ok: false, status: 401, error: "hud unlock is not configured" };
|
|
31
|
+
}
|
|
32
|
+
const token = readCookie(request.headers.get("cookie"), HUD_UNLOCK_COOKIE);
|
|
33
|
+
const unlocked = await verifyHudUnlockToken(token, password, { ttlMs: hudUnlockTtlMs(access) });
|
|
34
|
+
if (!unlocked) {
|
|
35
|
+
return { ok: false, status: 401, error: "hud is locked" };
|
|
36
|
+
}
|
|
37
|
+
return { ok: true, env };
|
|
38
|
+
}
|
|
39
|
+
async function isHudRequestUnlocked(request) {
|
|
40
|
+
const access = resolveHudAccess();
|
|
41
|
+
if (!hudRequiresUnlock(access))
|
|
42
|
+
return true;
|
|
43
|
+
const password = process.env.HUD_ACCESS_PASSWORD;
|
|
44
|
+
const token = readCookie(request.headers.get("cookie"), HUD_UNLOCK_COOKIE);
|
|
45
|
+
return verifyHudUnlockToken(token, password, { ttlMs: hudUnlockTtlMs(access) });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { checkHudRequest, isHudRequestUnlocked };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// core/capture-buffer.ts
|
|
2
|
+
class CaptureBuffer {
|
|
3
|
+
entries = [];
|
|
4
|
+
snapshot = [];
|
|
5
|
+
listeners = new Set;
|
|
6
|
+
nextId = 1;
|
|
7
|
+
maxEntries;
|
|
8
|
+
constructor(maxEntries = 500) {
|
|
9
|
+
this.maxEntries = maxEntries;
|
|
10
|
+
}
|
|
11
|
+
push(input) {
|
|
12
|
+
const entry = { id: this.nextId++, ts: Date.now(), ...input };
|
|
13
|
+
this.entries.push(entry);
|
|
14
|
+
if (this.entries.length > this.maxEntries) {
|
|
15
|
+
this.entries.splice(0, this.entries.length - this.maxEntries);
|
|
16
|
+
}
|
|
17
|
+
this.emit();
|
|
18
|
+
return entry;
|
|
19
|
+
}
|
|
20
|
+
clear() {
|
|
21
|
+
if (this.entries.length === 0)
|
|
22
|
+
return;
|
|
23
|
+
this.entries = [];
|
|
24
|
+
this.emit();
|
|
25
|
+
}
|
|
26
|
+
getSnapshot = () => this.snapshot;
|
|
27
|
+
subscribe = (listener) => {
|
|
28
|
+
this.listeners.add(listener);
|
|
29
|
+
return () => this.listeners.delete(listener);
|
|
30
|
+
};
|
|
31
|
+
emit() {
|
|
32
|
+
this.snapshot = [...this.entries];
|
|
33
|
+
for (const listener of this.listeners)
|
|
34
|
+
listener();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
var captureBuffer = new CaptureBuffer(500);
|
|
38
|
+
|
|
39
|
+
export { CaptureBuffer, captureBuffer };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LoadingSpinner
|
|
3
|
+
} from "./chunk-kyeb6qeq.js";
|
|
4
|
+
import {
|
|
5
|
+
hasCapability,
|
|
6
|
+
resolveHudEnv
|
|
7
|
+
} from "./chunk-babjpqkb.js";
|
|
8
|
+
|
|
9
|
+
// lazy-panel.tsx
|
|
10
|
+
import { lazy, Suspense } from "react";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
"use client";
|
|
13
|
+
function hudLazyPanel(meta, load, env = resolveHudEnv()) {
|
|
14
|
+
if (!hasCapability(env, meta.capability))
|
|
15
|
+
return null;
|
|
16
|
+
const Panel = lazy(async () => ({ default: await load() }));
|
|
17
|
+
return {
|
|
18
|
+
...meta,
|
|
19
|
+
content: /* @__PURE__ */ jsx(Suspense, {
|
|
20
|
+
fallback: /* @__PURE__ */ jsx(LoadingSpinner, {}),
|
|
21
|
+
children: /* @__PURE__ */ jsx(Panel, {})
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { hudLazyPanel };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// bridge-client.ts
|
|
2
|
+
var cached;
|
|
3
|
+
async function getBridgeInfo(apiBase) {
|
|
4
|
+
if (cached !== undefined)
|
|
5
|
+
return cached;
|
|
6
|
+
try {
|
|
7
|
+
const res = await fetch(`${apiBase}/bridge-info`, {
|
|
8
|
+
headers: { "x-hud-internal": "1" }
|
|
9
|
+
});
|
|
10
|
+
if (!res.ok) {
|
|
11
|
+
cached = null;
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const info = await res.json();
|
|
15
|
+
const health = await fetch(`http://127.0.0.1:${info.port}/health`, {
|
|
16
|
+
headers: { "x-hud-internal": "1" },
|
|
17
|
+
signal: AbortSignal.timeout(1500)
|
|
18
|
+
}).catch(() => null);
|
|
19
|
+
cached = health?.ok ? info : null;
|
|
20
|
+
return cached;
|
|
21
|
+
} catch {
|
|
22
|
+
cached = null;
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function resetBridgeInfo() {
|
|
27
|
+
cached = undefined;
|
|
28
|
+
}
|
|
29
|
+
async function bridgeFetch(info, path, init) {
|
|
30
|
+
return fetch(`http://127.0.0.1:${info.port}${path}`, {
|
|
31
|
+
...init,
|
|
32
|
+
headers: {
|
|
33
|
+
...init?.headers,
|
|
34
|
+
Authorization: `Bearer ${info.token}`,
|
|
35
|
+
"x-hud-internal": "1",
|
|
36
|
+
...init?.body ? { "Content-Type": "application/json" } : {}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { getBridgeInfo, resetBridgeInfo, bridgeFetch };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export { __require };
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bridgeFetch,
|
|
3
|
+
getBridgeInfo
|
|
4
|
+
} from "./chunk-50pq4sg6.js";
|
|
5
|
+
import {
|
|
6
|
+
clearGrabbedPayload,
|
|
7
|
+
getGrabberState,
|
|
8
|
+
startGrab,
|
|
9
|
+
subscribeGrabber,
|
|
10
|
+
useDevDrawer
|
|
11
|
+
} from "./chunk-82nm9wcg.js";
|
|
12
|
+
import {
|
|
13
|
+
useHud
|
|
14
|
+
} from "./chunk-wspz08q7.js";
|
|
15
|
+
import {
|
|
16
|
+
LoadingSpinner,
|
|
17
|
+
PanelSection
|
|
18
|
+
} from "./chunk-kyeb6qeq.js";
|
|
19
|
+
import {
|
|
20
|
+
Badge,
|
|
21
|
+
Button
|
|
22
|
+
} from "./chunk-xztw0xyt.js";
|
|
23
|
+
|
|
24
|
+
// panels/dispatch-panel.tsx
|
|
25
|
+
import { Crosshair, Send, X } from "lucide-react";
|
|
26
|
+
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
27
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
28
|
+
"use client";
|
|
29
|
+
function DispatchPanel() {
|
|
30
|
+
const { config } = useHud();
|
|
31
|
+
const { closeDrawer } = useDevDrawer();
|
|
32
|
+
const grabber = useSyncExternalStore(subscribeGrabber, getGrabberState, getGrabberState);
|
|
33
|
+
const [bridge, setBridge] = useState(undefined);
|
|
34
|
+
const [target, setTarget] = useState("docket");
|
|
35
|
+
const [note, setNote] = useState("");
|
|
36
|
+
const [runs, setRuns] = useState([]);
|
|
37
|
+
const apiBase = config.apiBase ?? "/api/hud";
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
let cancelled = false;
|
|
40
|
+
getBridgeInfo(apiBase).then((info) => {
|
|
41
|
+
if (cancelled)
|
|
42
|
+
return;
|
|
43
|
+
setBridge(info);
|
|
44
|
+
if (!info)
|
|
45
|
+
setTarget("hermes");
|
|
46
|
+
});
|
|
47
|
+
return () => {
|
|
48
|
+
cancelled = true;
|
|
49
|
+
};
|
|
50
|
+
}, [apiBase]);
|
|
51
|
+
const payload = grabber.payload;
|
|
52
|
+
const targets = useMemo(() => [
|
|
53
|
+
{
|
|
54
|
+
id: "docket",
|
|
55
|
+
label: "Local Claude session (docket)",
|
|
56
|
+
detail: "worktree + claude -p via the bridge — events land on the docket board",
|
|
57
|
+
enabled: bridge != null,
|
|
58
|
+
disabledReason: "bridge not reachable (run `bun hud:bridge` in the repo)"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "queue",
|
|
62
|
+
label: "Queue marker (.claude/queue)",
|
|
63
|
+
detail: "human in the loop — the next Claude session picks it up",
|
|
64
|
+
enabled: bridge != null,
|
|
65
|
+
disabledReason: "bridge not reachable"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: "hermes",
|
|
69
|
+
label: "Hermes (remote)",
|
|
70
|
+
detail: "via the console hub → hermes-dispatch workflow, tier balanced",
|
|
71
|
+
enabled: true,
|
|
72
|
+
disabledReason: ""
|
|
73
|
+
}
|
|
74
|
+
], [bridge]);
|
|
75
|
+
async function send() {
|
|
76
|
+
if (!payload)
|
|
77
|
+
return;
|
|
78
|
+
const title = `${payload.anchor.label} — ${note.slice(0, 60) || "hud dispatch"}`;
|
|
79
|
+
const localId = `local-${Date.now()}`;
|
|
80
|
+
setRuns((prev) => [{ id: localId, title, target, status: "sending" }, ...prev]);
|
|
81
|
+
clearGrabbedPayload();
|
|
82
|
+
setNote("");
|
|
83
|
+
try {
|
|
84
|
+
let res;
|
|
85
|
+
if (target === "hermes") {
|
|
86
|
+
res = await fetch(`${apiBase}/dispatch`, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: { "Content-Type": "application/json", "x-hud-internal": "1" },
|
|
89
|
+
body: JSON.stringify({ target, note, payload })
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
if (!bridge)
|
|
93
|
+
throw new Error("bridge not reachable");
|
|
94
|
+
res = await bridgeFetch(bridge, "/dispatch", {
|
|
95
|
+
method: "POST",
|
|
96
|
+
body: JSON.stringify({ target, note, payload })
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const body = await res.json();
|
|
100
|
+
setRuns((prev) => prev.map((run) => run.id === localId ? {
|
|
101
|
+
...run,
|
|
102
|
+
status: body.ok ? "dispatched" : "failed",
|
|
103
|
+
detail: body.runId ?? body.markerPath ?? body.error
|
|
104
|
+
} : run));
|
|
105
|
+
} catch (error) {
|
|
106
|
+
setRuns((prev) => prev.map((run) => run.id === localId ? {
|
|
107
|
+
...run,
|
|
108
|
+
status: "failed",
|
|
109
|
+
detail: error instanceof Error ? error.message : "dispatch failed"
|
|
110
|
+
} : run));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
114
|
+
className: "space-y-4",
|
|
115
|
+
children: [
|
|
116
|
+
!payload && /* @__PURE__ */ jsx(PanelSection, {
|
|
117
|
+
icon: Crosshair,
|
|
118
|
+
title: "Grab an element",
|
|
119
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
120
|
+
className: "px-2",
|
|
121
|
+
children: [
|
|
122
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
123
|
+
size: "sm",
|
|
124
|
+
className: "h-7 text-xs",
|
|
125
|
+
onClick: () => {
|
|
126
|
+
closeDrawer();
|
|
127
|
+
startGrab();
|
|
128
|
+
},
|
|
129
|
+
children: [
|
|
130
|
+
/* @__PURE__ */ jsx(Crosshair, {
|
|
131
|
+
className: "mr-1.5 h-3.5 w-3.5"
|
|
132
|
+
}),
|
|
133
|
+
"Grab element"
|
|
134
|
+
]
|
|
135
|
+
}),
|
|
136
|
+
/* @__PURE__ */ jsx("p", {
|
|
137
|
+
className: "mt-2 text-[10px] text-muted-foreground/60",
|
|
138
|
+
children: "Click any element on the page — selector, source hints, recent errors, and vitals become the dispatch payload."
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
})
|
|
142
|
+
}),
|
|
143
|
+
payload && /* @__PURE__ */ jsx(PanelSection, {
|
|
144
|
+
icon: Send,
|
|
145
|
+
title: "Dispatch",
|
|
146
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
147
|
+
className: "space-y-2 px-2",
|
|
148
|
+
children: [
|
|
149
|
+
/* @__PURE__ */ jsx(PayloadPreview, {
|
|
150
|
+
payload,
|
|
151
|
+
onDiscard: clearGrabbedPayload
|
|
152
|
+
}),
|
|
153
|
+
/* @__PURE__ */ jsx("textarea", {
|
|
154
|
+
value: note,
|
|
155
|
+
onChange: (e) => setNote(e.target.value),
|
|
156
|
+
placeholder: "Instruction, e.g.: button feels heavy — try a ghost variant",
|
|
157
|
+
className: "min-h-[52px] w-full rounded-md border bg-muted/20 p-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-ring"
|
|
158
|
+
}),
|
|
159
|
+
/* @__PURE__ */ jsx("div", {
|
|
160
|
+
className: "space-y-1",
|
|
161
|
+
children: targets.map((t) => /* @__PURE__ */ jsxs("label", {
|
|
162
|
+
className: `flex cursor-pointer items-start gap-2 rounded-md border p-2 ${target === t.id ? "border-primary/60 bg-muted/30" : "border-border/50"} ${t.enabled ? "" : "cursor-not-allowed opacity-50"}`,
|
|
163
|
+
children: [
|
|
164
|
+
/* @__PURE__ */ jsx("input", {
|
|
165
|
+
type: "radio",
|
|
166
|
+
name: "hud-dispatch-target",
|
|
167
|
+
checked: target === t.id,
|
|
168
|
+
disabled: !t.enabled,
|
|
169
|
+
onChange: () => setTarget(t.id),
|
|
170
|
+
className: "mt-0.5"
|
|
171
|
+
}),
|
|
172
|
+
/* @__PURE__ */ jsxs("span", {
|
|
173
|
+
children: [
|
|
174
|
+
/* @__PURE__ */ jsx("span", {
|
|
175
|
+
className: "block text-xs font-medium",
|
|
176
|
+
children: t.label
|
|
177
|
+
}),
|
|
178
|
+
/* @__PURE__ */ jsx("span", {
|
|
179
|
+
className: "block text-[10px] text-muted-foreground",
|
|
180
|
+
children: t.enabled ? t.detail : t.disabledReason
|
|
181
|
+
})
|
|
182
|
+
]
|
|
183
|
+
})
|
|
184
|
+
]
|
|
185
|
+
}, t.id))
|
|
186
|
+
}),
|
|
187
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
188
|
+
size: "sm",
|
|
189
|
+
className: "h-7 text-xs",
|
|
190
|
+
onClick: send,
|
|
191
|
+
children: [
|
|
192
|
+
/* @__PURE__ */ jsx(Send, {
|
|
193
|
+
className: "mr-1.5 h-3 w-3"
|
|
194
|
+
}),
|
|
195
|
+
"Dispatch"
|
|
196
|
+
]
|
|
197
|
+
})
|
|
198
|
+
]
|
|
199
|
+
})
|
|
200
|
+
}),
|
|
201
|
+
bridge === undefined && /* @__PURE__ */ jsx(LoadingSpinner, {}),
|
|
202
|
+
runs.length > 0 && /* @__PURE__ */ jsx(PanelSection, {
|
|
203
|
+
title: "Dispatched from this session",
|
|
204
|
+
children: runs.map((run) => /* @__PURE__ */ jsxs("div", {
|
|
205
|
+
className: "flex items-center gap-2 px-2 py-1 font-mono text-[10.5px]",
|
|
206
|
+
children: [
|
|
207
|
+
/* @__PURE__ */ jsx(Badge, {
|
|
208
|
+
variant: "outline",
|
|
209
|
+
className: `h-4 px-1.5 text-[9px] ${run.status === "dispatched" ? "text-emerald-500" : run.status === "failed" ? "text-red-500" : "text-amber-500"}`,
|
|
210
|
+
children: run.status
|
|
211
|
+
}),
|
|
212
|
+
/* @__PURE__ */ jsx("span", {
|
|
213
|
+
className: "min-w-0 flex-1 truncate",
|
|
214
|
+
children: run.title
|
|
215
|
+
}),
|
|
216
|
+
/* @__PURE__ */ jsx("span", {
|
|
217
|
+
className: "text-muted-foreground/60",
|
|
218
|
+
children: run.target
|
|
219
|
+
}),
|
|
220
|
+
run.detail && /* @__PURE__ */ jsx("span", {
|
|
221
|
+
className: "max-w-[180px] truncate text-muted-foreground/60",
|
|
222
|
+
title: run.detail,
|
|
223
|
+
children: run.detail
|
|
224
|
+
})
|
|
225
|
+
]
|
|
226
|
+
}, run.id))
|
|
227
|
+
})
|
|
228
|
+
]
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function PayloadPreview({
|
|
232
|
+
payload,
|
|
233
|
+
onDiscard
|
|
234
|
+
}) {
|
|
235
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
236
|
+
className: "rounded-md border bg-muted/20 p-2",
|
|
237
|
+
children: [
|
|
238
|
+
/* @__PURE__ */ jsxs("div", {
|
|
239
|
+
className: "flex items-center gap-2",
|
|
240
|
+
children: [
|
|
241
|
+
/* @__PURE__ */ jsx("span", {
|
|
242
|
+
className: "min-w-0 flex-1 truncate font-mono text-[11px]",
|
|
243
|
+
children: payload.anchor.label
|
|
244
|
+
}),
|
|
245
|
+
/* @__PURE__ */ jsx(Button, {
|
|
246
|
+
variant: "ghost",
|
|
247
|
+
size: "icon",
|
|
248
|
+
className: "h-5 w-5",
|
|
249
|
+
onClick: onDiscard,
|
|
250
|
+
children: /* @__PURE__ */ jsx(X, {
|
|
251
|
+
className: "h-3 w-3"
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
]
|
|
255
|
+
}),
|
|
256
|
+
/* @__PURE__ */ jsx("pre", {
|
|
257
|
+
className: "mt-1 max-h-40 overflow-auto text-[9.5px] leading-relaxed text-muted-foreground",
|
|
258
|
+
children: JSON.stringify(payload, null, 2)
|
|
259
|
+
})
|
|
260
|
+
]
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export { DispatchPanel };
|