@hansenexus/hud 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +42 -23
  2. package/dist/index.d.ts +39 -0
  3. package/dist/index.js +399 -0
  4. package/package.json +45 -136
  5. package/chunk-20zke7cs.js +0 -574
  6. package/chunk-24vrg16w.js +0 -39
  7. package/chunk-50pq4sg6.js +0 -41
  8. package/chunk-5gtx3pza.js +0 -9
  9. package/chunk-6cdpasm9.js +0 -79
  10. package/chunk-6jt8yg4m.js +0 -117
  11. package/chunk-6ngkpwz7.js +0 -127
  12. package/chunk-71se605m.js +0 -85
  13. package/chunk-82nm9wcg.js +0 -316
  14. package/chunk-9hw5r9y1.js +0 -67
  15. package/chunk-c5y856ad.js +0 -98
  16. package/chunk-edq4jqch.js +0 -89
  17. package/chunk-emfnvz4p.js +0 -166
  18. package/chunk-h0hmjdqa.js +0 -264
  19. package/chunk-hc2g0n35.js +0 -24
  20. package/chunk-hex3wqag.js +0 -179
  21. package/chunk-kvxve0hx.js +0 -140
  22. package/chunk-kyeb6qeq.js +0 -95
  23. package/chunk-mz55rvw3.js +0 -172
  24. package/chunk-nm82wr8r.js +0 -58
  25. package/chunk-q15xwpy8.js +0 -48
  26. package/chunk-q96mkjve.js +0 -68
  27. package/chunk-tczzx083.js +0 -26
  28. package/chunk-tf774c4w.js +0 -115
  29. package/chunk-v086j53b.js +0 -19
  30. package/chunk-vjh0d29g.js +0 -52
  31. package/chunk-xezxydm3.js +0 -47
  32. package/chunk-xztw0xyt.js +0 -113
  33. package/chunk-yn1d38pb.js +0 -172
  34. package/core/access.d.mts +0 -53
  35. package/core/access.js +0 -27
  36. package/core/api-types.d.mts +0 -146
  37. package/core/api-types.js +0 -9
  38. package/core/capabilities.d.mts +0 -27
  39. package/core/capabilities.js +0 -14
  40. package/core/capture-buffer.d.mts +0 -37
  41. package/core/capture-buffer.js +0 -9
  42. package/core/force-state.d.mts +0 -68
  43. package/core/force-state.js +0 -21
  44. package/core/mock-cookie.d.mts +0 -30
  45. package/core/mock-cookie.js +0 -15
  46. package/core/types.d.mts +0 -59
  47. package/core/types.js +0 -9
  48. package/hud-provider.d.mts +0 -38
  49. package/hud-provider.js +0 -15
  50. package/hud.d.mts +0 -15
  51. package/hud.js +0 -18
  52. package/index.d.mts +0 -94
  53. package/index.js +0 -170
  54. package/lazy-panel.d.mts +0 -28
  55. package/lazy-panel.js +0 -11
  56. package/panels/cicd-panel.d.mts +0 -9
  57. package/panels/cicd-panel.js +0 -13
  58. package/panels/debug-info-panel.d.mts +0 -21
  59. package/panels/debug-info-panel.js +0 -9
  60. package/panels/dispatch-panel.d.mts +0 -10
  61. package/panels/dispatch-panel.js +0 -14
  62. package/panels/env-info-panel.d.mts +0 -9
  63. package/panels/env-info-panel.js +0 -12
  64. package/panels/feature-flags-panel.d.mts +0 -26
  65. package/panels/feature-flags-panel.js +0 -9
  66. package/panels/force-state-panel.d.mts +0 -11
  67. package/panels/force-state-panel.js +0 -113
  68. package/panels/info-row.d.mts +0 -21
  69. package/panels/info-row.js +0 -14
  70. package/panels/mock-seed-panel.d.mts +0 -15
  71. package/panels/mock-seed-panel.js +0 -14
  72. package/panels/network-console-panel.d.mts +0 -6
  73. package/panels/network-console-panel.js +0 -9
  74. package/panels/role-switcher-panel.d.mts +0 -28
  75. package/panels/role-switcher-panel.js +0 -9
  76. package/panels/sessions-panel.d.mts +0 -6
  77. package/panels/sessions-panel.js +0 -13
  78. package/panels/tokens-panel.d.mts +0 -38
  79. package/panels/tokens-panel.js +0 -9
  80. package/panels/unlock-panel.d.mts +0 -33
  81. package/panels/unlock-panel.js +0 -14
  82. package/panels/variants-panel.d.mts +0 -51
  83. package/panels/variants-panel.js +0 -12
  84. package/panels/vitals-panel.d.mts +0 -11
  85. package/panels/vitals-panel.js +0 -15
  86. package/server/guard.d.mts +0 -42
  87. package/server/guard.js +0 -12
  88. package/server/unlock.d.mts +0 -28
  89. package/server/unlock.js +0 -108
  90. package/state-boundary.d.mts +0 -25
  91. package/state-boundary.js +0 -54
@@ -1,9 +0,0 @@
1
- import {
2
- TokensPanel
3
- } from "../chunk-nm82wr8r.js";
4
- import"../chunk-kyeb6qeq.js";
5
- import"../chunk-xztw0xyt.js";
6
- import"../chunk-5gtx3pza.js";
7
- export {
8
- TokensPanel
9
- };
@@ -1,33 +0,0 @@
1
- import * as react from 'react';
2
- import { HudAccess } from '../core/access.mjs';
3
- import { HudEnv } from '../core/types.mjs';
4
- import 'lucide-react';
5
-
6
- type HudUnlockState = "checking" | "locked" | "unlocked" | "unconfigured";
7
- /**
8
- * Unlock state for a deployed hud.
9
- *
10
- * The browser never sees the password or the token: the cookie is httpOnly
11
- * and only the server can judge it, so this hook asks `${apiBase}/unlock`
12
- * rather than reading anything locally. On a tier that needs no unlock it
13
- * settles on `unlocked` without a request.
14
- */
15
- declare function useHudUnlock(apiBase: string, access: HudAccess): {
16
- state: HudUnlockState;
17
- error: string | null;
18
- unlock: (password: string) => Promise<boolean>;
19
- };
20
- interface HudUnlockPanelProps {
21
- env: HudEnv;
22
- state: HudUnlockState;
23
- error: string | null;
24
- onUnlock: (password: string) => Promise<boolean>;
25
- }
26
- /**
27
- * The only panel a locked deployed hud shows. Everything else, including
28
- * the read-only production panels, stays behind it, because the panels
29
- * themselves fetch from `/api/hud/*` routes that would refuse anyway.
30
- */
31
- declare function HudUnlockPanel({ env, state, error, onUnlock }: HudUnlockPanelProps): react.JSX.Element;
32
-
33
- export { HudUnlockPanel, type HudUnlockPanelProps, type HudUnlockState, useHudUnlock };
@@ -1,14 +0,0 @@
1
- import {
2
- HudUnlockPanel,
3
- useHudUnlock
4
- } from "../chunk-kvxve0hx.js";
5
- import"../chunk-6cdpasm9.js";
6
- import"../chunk-kyeb6qeq.js";
7
- import"../chunk-xztw0xyt.js";
8
- import"../chunk-vjh0d29g.js";
9
- import"../chunk-v086j53b.js";
10
- import"../chunk-5gtx3pza.js";
11
- export {
12
- useHudUnlock,
13
- HudUnlockPanel
14
- };
@@ -1,51 +0,0 @@
1
- import * as react from 'react';
2
-
3
- interface HudVariantCategory {
4
- id: string;
5
- name: string;
6
- /** Registry status — "active" renders as votable, "decided" as settled. */
7
- status: string;
8
- alternativeCount: number;
9
- /** Domain bucket (marketing / admin / shared, …) for grouping. */
10
- domain?: string;
11
- }
12
- interface HudGenerateRequest {
13
- /** Repo-relative component path (apps/… or packages/…). */
14
- path: string;
15
- brief: string;
16
- count: number;
17
- }
18
- interface HudGenerateResult {
19
- ok: boolean;
20
- /** Repo-relative queue marker path on success. */
21
- markerPath?: string;
22
- error?: string;
23
- }
24
- interface HudVariantsAdapter {
25
- categories: HudVariantCategory[];
26
- /** Deep link to the full review dashboard (e.g. /dev/review/console). */
27
- reviewHref: string;
28
- /** Deep link for one category's drill-in page. */
29
- categoryHref?: (categoryId: string) => string;
30
- /**
31
- * Open the in-page preview drawer, when the app has a PreviewProvider
32
- * mounted on the current route. Omit to fall back to deep links.
33
- */
34
- openPreview?: (categoryId: string) => void;
35
- /**
36
- * Queue a variant-generation brief (console: /api/dev/generate-variants →
37
- * .claude/queue marker — human stays in the loop, no autonomous dispatch).
38
- */
39
- generate?: (request: HudGenerateRequest) => Promise<HudGenerateResult>;
40
- }
41
- /**
42
- * Variant-voting overview over an app-provided adapter: registered preview
43
- * categories with status, drill-in links (or the in-page drawer when
44
- * mounted), and the generate-brief queue. Voting itself stays on the review
45
- * dashboard — it needs the showcase to judge alternatives.
46
- */
47
- declare function VariantsPanel({ adapter }: {
48
- adapter: HudVariantsAdapter;
49
- }): react.JSX.Element;
50
-
51
- export { type HudGenerateRequest, type HudGenerateResult, type HudVariantCategory, type HudVariantsAdapter, VariantsPanel };
@@ -1,12 +0,0 @@
1
- import {
2
- VariantsPanel
3
- } from "../chunk-emfnvz4p.js";
4
- import"../chunk-9hw5r9y1.js";
5
- import"../chunk-kyeb6qeq.js";
6
- import"../chunk-xztw0xyt.js";
7
- import"../chunk-vjh0d29g.js";
8
- import"../chunk-v086j53b.js";
9
- import"../chunk-5gtx3pza.js";
10
- export {
11
- VariantsPanel
12
- };
@@ -1,11 +0,0 @@
1
- import * as react from 'react';
2
-
3
- /** Current values as a plain record — consumed by the dispatch payload. */
4
- declare function getVitalsSnapshot(): Record<string, number>;
5
- /**
6
- * Live Core Web Vitals of the current page (web-vitals, in-memory) plus the
7
- * app's server-side SigNoz snapshot via the hud hub.
8
- */
9
- declare function VitalsPanel(): react.JSX.Element;
10
-
11
- export { VitalsPanel, getVitalsSnapshot };
@@ -1,15 +0,0 @@
1
- import {
2
- VitalsPanel,
3
- getVitalsSnapshot
4
- } from "../chunk-yn1d38pb.js";
5
- import"../chunk-xezxydm3.js";
6
- import"../chunk-9hw5r9y1.js";
7
- import"../chunk-kyeb6qeq.js";
8
- import"../chunk-xztw0xyt.js";
9
- import"../chunk-vjh0d29g.js";
10
- import"../chunk-v086j53b.js";
11
- import"../chunk-5gtx3pza.js";
12
- export {
13
- getVitalsSnapshot,
14
- VitalsPanel
15
- };
@@ -1,42 +0,0 @@
1
- import { HudEnv, HudCapability } from '../core/types.mjs';
2
- import 'lucide-react';
3
- import 'react';
4
-
5
- /**
6
- * Server-side hud gate: layer two of the three the hud architecture calls
7
- * for (client render gate · per-app route gate · hub token).
8
- *
9
- * Client capability filtering is convenience: the panels a browser cannot see
10
- * are still reachable by typing the URL. Every `/api/hud/*` route therefore
11
- * re-derives the env itself and refuses anything the tier's matrix denies,
12
- * which is what makes production genuinely read-only rather than
13
- * read-only-by-UI. Deliberately framework-free (it takes anything with
14
- * `headers.get`) so the route decides how to render the failure.
15
- */
16
-
17
- interface HudGuardRequest {
18
- headers: {
19
- get(name: string): string | null;
20
- };
21
- }
22
- type HudGuardResult = {
23
- ok: true;
24
- env: HudEnv;
25
- } | {
26
- ok: false;
27
- status: 401 | 403 | 404;
28
- error: string;
29
- };
30
- /**
31
- * Whether this request may exercise `capability` right now.
32
- *
33
- * Order matters: a hud that is not enabled at all answers 404 (nothing here),
34
- * a denied capability answers 403 before any password is considered (the
35
- * password must never be a way to widen the matrix), and only a permitted
36
- * capability gets as far as the unlock check.
37
- */
38
- declare function checkHudRequest(request: HudGuardRequest, capability: HudCapability): Promise<HudGuardResult>;
39
- /** Whether the current request already carries a valid unlock (status route). */
40
- declare function isHudRequestUnlocked(request: HudGuardRequest): Promise<boolean>;
41
-
42
- export { type HudGuardRequest, type HudGuardResult, checkHudRequest, isHudRequestUnlocked };
package/server/guard.js DELETED
@@ -1,12 +0,0 @@
1
- import {
2
- checkHudRequest,
3
- isHudRequestUnlocked
4
- } from "../chunk-q15xwpy8.js";
5
- import"../chunk-6cdpasm9.js";
6
- import"../chunk-vjh0d29g.js";
7
- import"../chunk-v086j53b.js";
8
- import"../chunk-5gtx3pza.js";
9
- export {
10
- isHudRequestUnlocked,
11
- checkHudRequest
12
- };
@@ -1,28 +0,0 @@
1
- /**
2
- * The `/api/hud/unlock` handler, shared by every app that mounts the hud.
3
- *
4
- * Framework-free on purpose (it takes anything with `headers.get` and a
5
- * `json()`), so each app's route file is four lines of Next glue and the
6
- * policy lives in one place. Verification is HMAC over the token's own issue
7
- * time (see core/access.ts), so nothing server-side needs to be stored.
8
- */
9
- interface HudUnlockRequest {
10
- headers: {
11
- get(name: string): string | null;
12
- };
13
- json(): Promise<unknown>;
14
- }
15
- interface HudUnlockResult {
16
- status: number;
17
- body: Record<string, unknown>;
18
- /** `Set-Cookie` value, when the attempt changed the unlock state. */
19
- setCookie?: string;
20
- }
21
- /** GET: what the client needs to decide between the panels and the lock. */
22
- declare function handleHudUnlockStatus(request: HudUnlockRequest): Promise<HudUnlockResult>;
23
- /** POST: exchange the password for a signed, expiring unlock cookie. */
24
- declare function handleHudUnlockAttempt(request: HudUnlockRequest): Promise<HudUnlockResult>;
25
- /** Test seam: the attempt budget is process state, not request state. */
26
- declare function resetHudUnlockAttempts(): void;
27
-
28
- export { type HudUnlockRequest, type HudUnlockResult, handleHudUnlockAttempt, handleHudUnlockStatus, resetHudUnlockAttempts };
package/server/unlock.js DELETED
@@ -1,108 +0,0 @@
1
- import {
2
- isHudRequestUnlocked
3
- } from "../chunk-q15xwpy8.js";
4
- import {
5
- hudRequiresUnlock,
6
- hudUnlockCookieString,
7
- hudUnlockTtlMs,
8
- resolveHudAccess,
9
- signHudUnlockToken,
10
- timingSafeEqual
11
- } from "../chunk-6cdpasm9.js";
12
- import {
13
- isHudVisible,
14
- resolveHudEnv
15
- } from "../chunk-vjh0d29g.js";
16
- import"../chunk-v086j53b.js";
17
- import"../chunk-5gtx3pza.js";
18
-
19
- // server/unlock.ts
20
- var ATTEMPT_WINDOW_MS = 10 * 60 * 1000;
21
- var MAX_FAILED_ATTEMPTS = 10;
22
- var failures = new Map;
23
- function clientKey(request) {
24
- const forwarded = request.headers.get("x-forwarded-for");
25
- return forwarded?.split(",")[0]?.trim() || request.headers.get("x-real-ip") || "unknown";
26
- }
27
- function isThrottled(key, now) {
28
- const entry = failures.get(key);
29
- if (!entry)
30
- return false;
31
- if (now - entry.firstAt > ATTEMPT_WINDOW_MS) {
32
- failures.delete(key);
33
- return false;
34
- }
35
- return entry.count >= MAX_FAILED_ATTEMPTS;
36
- }
37
- function recordFailure(key, now) {
38
- const entry = failures.get(key);
39
- if (!entry || now - entry.firstAt > ATTEMPT_WINDOW_MS) {
40
- failures.set(key, { count: 1, firstAt: now });
41
- return;
42
- }
43
- entry.count += 1;
44
- }
45
- async function handleHudUnlockStatus(request) {
46
- const env = resolveHudEnv();
47
- if (!isHudVisible(env)) {
48
- return { status: 404, body: { error: "not found" } };
49
- }
50
- const access = resolveHudAccess(env);
51
- return {
52
- status: 200,
53
- body: {
54
- env,
55
- access,
56
- required: hudRequiresUnlock(access),
57
- configured: !hudRequiresUnlock(access) || Boolean(process.env.HUD_ACCESS_PASSWORD),
58
- unlocked: await isHudRequestUnlocked(request)
59
- }
60
- };
61
- }
62
- async function handleHudUnlockAttempt(request) {
63
- const env = resolveHudEnv();
64
- if (!isHudVisible(env)) {
65
- return { status: 404, body: { error: "not found" } };
66
- }
67
- const access = resolveHudAccess(env);
68
- if (!hudRequiresUnlock(access)) {
69
- return { status: 200, body: { unlocked: true, required: false } };
70
- }
71
- const expected = process.env.HUD_ACCESS_PASSWORD;
72
- if (!expected) {
73
- return {
74
- status: 503,
75
- body: { unlocked: false, configured: false, error: "hud unlock is not configured" }
76
- };
77
- }
78
- const now = Date.now();
79
- const key = clientKey(request);
80
- if (isThrottled(key, now)) {
81
- return { status: 429, body: { unlocked: false, error: "too many attempts, try again later" } };
82
- }
83
- let submitted = "";
84
- try {
85
- const payload = await request.json();
86
- if (typeof payload?.password === "string")
87
- submitted = payload.password;
88
- } catch {}
89
- if (!submitted || !timingSafeEqual(submitted, expected)) {
90
- recordFailure(key, now);
91
- return { status: 401, body: { unlocked: false, error: "wrong password" } };
92
- }
93
- failures.delete(key);
94
- const ttlMs = hudUnlockTtlMs(access);
95
- return {
96
- status: 200,
97
- body: { unlocked: true, env, access, expiresInMs: ttlMs },
98
- setCookie: hudUnlockCookieString(await signHudUnlockToken(expected, now), ttlMs)
99
- };
100
- }
101
- function resetHudUnlockAttempts() {
102
- failures.clear();
103
- }
104
- export {
105
- resetHudUnlockAttempts,
106
- handleHudUnlockStatus,
107
- handleHudUnlockAttempt
108
- };
@@ -1,25 +0,0 @@
1
- import * as react from 'react';
2
- import { ReactNode } from 'react';
3
- import { ForcedState } from './core/force-state.mjs';
4
-
5
- interface StateBoundaryProps {
6
- /** Stable, page-unique id; the HUD force-state panel lists boundaries by it. */
7
- id: string;
8
- /** Renders the boundary; `forced` is the state to show instead of the real one, or null. */
9
- children: (forced: ForcedState | null) => ReactNode;
10
- }
11
- /**
12
- * Registers a loading/empty/error boundary with the HUD force-state panel and
13
- * `?__state=`. Wrap the part of a page that branches on a query result:
14
- *
15
- * ```tsx
16
- * <StateBoundary id="blog-post">
17
- * {(forced) => forced === "loading" || post === undefined ? <Skeleton /> : …}
18
- * </StateBoundary>
19
- * ```
20
- *
21
- * In production it renders `children(null)` and nothing else.
22
- */
23
- declare function StateBoundary({ id, children }: StateBoundaryProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | react.JSX.Element | null | undefined;
24
-
25
- export { StateBoundary, type StateBoundaryProps };
package/state-boundary.js DELETED
@@ -1,54 +0,0 @@
1
- import {
2
- getForceStateStore,
3
- resolveForcedState
4
- } from "./chunk-c5y856ad.js";
5
- import"./chunk-5gtx3pza.js";
6
-
7
- // state-boundary.tsx
8
- import { createContext, useContext, useEffect, useSyncExternalStore } from "react";
9
- import { jsx } from "react/jsx-runtime";
10
- "use client";
11
- var FORCE_STATE_ENABLED = process.env.NODE_ENV === "development";
12
- function StateBoundary({ id, children }) {
13
- if (!FORCE_STATE_ENABLED)
14
- return children(null);
15
- return /* @__PURE__ */ jsx(DevStateBoundary, {
16
- id,
17
- children
18
- });
19
- }
20
- var ParentBoundary = /* @__PURE__ */ createContext(null);
21
- var SERVER_SNAPSHOT = { boundaries: [], overrides: {}, param: null };
22
- function subscribe(listener) {
23
- const store = getForceStateStore();
24
- const onPopState = () => store.syncSearch(window.location.search);
25
- window.addEventListener("popstate", onPopState);
26
- const unsubscribe = store.subscribe(listener);
27
- return () => {
28
- window.removeEventListener("popstate", onPopState);
29
- unsubscribe();
30
- };
31
- }
32
- function getSnapshot() {
33
- return getForceStateStore().getSnapshot();
34
- }
35
- function getServerSnapshot() {
36
- return SERVER_SNAPSHOT;
37
- }
38
- function DevStateBoundary({ id, children }) {
39
- const parentId = useContext(ParentBoundary);
40
- const snapshot = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
41
- useEffect(() => {
42
- const store = getForceStateStore();
43
- store.syncSearch(window.location.search);
44
- return store.register(id, parentId);
45
- }, [id, parentId]);
46
- const forced = resolveForcedState(snapshot, { id, parentId });
47
- return /* @__PURE__ */ jsx(ParentBoundary.Provider, {
48
- value: id,
49
- children: children(forced)
50
- });
51
- }
52
- export {
53
- StateBoundary
54
- };