@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.
Files changed (172) hide show
  1. package/README.md +782 -6
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/access-C7zlaqj6.js +100 -0
  5. package/dist/access-D_ewAEJG.d.ts +61 -0
  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-CApnbI0r.d.ts +19 -0
  26. package/dist/env-CaiFPIhF.js +31 -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-BaqWsmrf.js +153 -0
  32. package/dist/force-state-CCqoTfVB.d.ts +23 -0
  33. package/dist/force-state-panel-_otVYh9i.js +97 -0
  34. package/dist/generate-C8lQl3Eh.js +53 -0
  35. package/dist/handler-BpVhxEmU.js +106 -0
  36. package/dist/handler-DtYVCZY6.d.ts +39 -0
  37. package/dist/index-BAV_1W8a.d.ts +43 -0
  38. package/dist/index-BJ26pse9.d.ts +70 -0
  39. package/dist/index-BnQ0dTZf.d.ts +19 -0
  40. package/dist/index-CwfX-W87.d.ts +72 -0
  41. package/dist/index-DcH9V3cU.d.ts +48 -0
  42. package/dist/index-DqOyNf1u.d.ts +65 -0
  43. package/dist/index-DstI_ike.d.ts +66 -0
  44. package/dist/index-Dxz4fn4j.d.ts +42 -0
  45. package/dist/index-Hhh7OXzU.d.ts +129 -0
  46. package/dist/index-ReFbhQ9p.d.ts +25 -0
  47. package/dist/index-RgXfMBuW.d.ts +48 -0
  48. package/dist/index-gCZBO53s.d.ts +73 -0
  49. package/dist/index.d.ts +6 -36
  50. package/dist/index.js +798 -240
  51. package/dist/inspect-C9Ft8fqn.js +142 -0
  52. package/dist/inspect-root-BkaupBMp.js +429 -0
  53. package/dist/marker-C66LxOhJ.d.ts +9 -0
  54. package/dist/marker-CMrvxPmS.d.ts +12 -0
  55. package/dist/marker-DjeGvL-F.js +9 -0
  56. package/dist/marker-uZYPOJ4M.js +12 -0
  57. package/dist/markers.d.ts +3 -0
  58. package/dist/markers.js +3 -0
  59. package/dist/meta-Bv0sEao3.js +6 -0
  60. package/dist/meta-C_G7MB5w.d.ts +49 -0
  61. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  62. package/dist/mocks-ESiRqk9o.js +150 -0
  63. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  64. package/dist/next/config.d.ts +52 -0
  65. package/dist/next/config.js +78 -0
  66. package/dist/next.d.ts +14 -19
  67. package/dist/next.js +7 -30
  68. package/dist/observe-CdDnDBRP.js +89 -0
  69. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  70. package/dist/ops-panel-CEqDe_UT.js +234 -0
  71. package/dist/payload-MUQ9ciER.d.ts +92 -0
  72. package/dist/plugins/a11y.d.ts +2 -0
  73. package/dist/plugins/a11y.js +2 -0
  74. package/dist/plugins/access/server.d.ts +122 -0
  75. package/dist/plugins/access/server.js +340 -0
  76. package/dist/plugins/access.d.ts +41 -0
  77. package/dist/plugins/access.js +51 -0
  78. package/dist/plugins/agent/server.d.ts +94 -0
  79. package/dist/plugins/agent/server.js +455 -0
  80. package/dist/plugins/agent.d.ts +37 -0
  81. package/dist/plugins/agent.js +69 -0
  82. package/dist/plugins/capture/server.d.ts +92 -0
  83. package/dist/plugins/capture/server.js +248 -0
  84. package/dist/plugins/capture.d.ts +24 -0
  85. package/dist/plugins/capture.js +70 -0
  86. package/dist/plugins/data/msw-browser.d.ts +2 -0
  87. package/dist/plugins/data/msw-browser.js +39 -0
  88. package/dist/plugins/data/msw-node.d.ts +36 -0
  89. package/dist/plugins/data/msw-node.js +68 -0
  90. package/dist/plugins/data/server.d.ts +257 -0
  91. package/dist/plugins/data/server.js +717 -0
  92. package/dist/plugins/data.d.ts +6 -0
  93. package/dist/plugins/data.js +51 -0
  94. package/dist/plugins/design/server.d.ts +54 -0
  95. package/dist/plugins/design/server.js +198 -0
  96. package/dist/plugins/design.d.ts +5 -0
  97. package/dist/plugins/design.js +4 -0
  98. package/dist/plugins/inspect/convex.d.ts +2 -0
  99. package/dist/plugins/inspect/convex.js +486 -0
  100. package/dist/plugins/inspect/react-query.d.ts +2 -0
  101. package/dist/plugins/inspect/react-query.js +225 -0
  102. package/dist/plugins/inspect/sockets.d.ts +51 -0
  103. package/dist/plugins/inspect/sockets.js +397 -0
  104. package/dist/plugins/inspect/swr.d.ts +2 -0
  105. package/dist/plugins/inspect/swr.js +218 -0
  106. package/dist/plugins/inspect.d.ts +4 -0
  107. package/dist/plugins/inspect.js +3 -0
  108. package/dist/plugins/observe.d.ts +4 -0
  109. package/dist/plugins/observe.js +2 -0
  110. package/dist/plugins/ops/server.d.ts +82 -0
  111. package/dist/plugins/ops/server.js +381 -0
  112. package/dist/plugins/ops.d.ts +27 -0
  113. package/dist/plugins/ops.js +41 -0
  114. package/dist/plugins/routes/server.d.ts +88 -0
  115. package/dist/plugins/routes/server.js +62 -0
  116. package/dist/plugins/routes.d.ts +3 -0
  117. package/dist/plugins/routes.js +216 -0
  118. package/dist/plugins/seo.d.ts +2 -0
  119. package/dist/plugins/seo.js +2 -0
  120. package/dist/plugins/vitals.d.ts +2 -25
  121. package/dist/plugins/vitals.js +4 -86
  122. package/dist/plugins-BZvDqGx5.d.ts +144 -0
  123. package/dist/{plugins-CzUiTn_r.js → plugins-DVy_vaYr.js} +3 -1
  124. package/dist/poll-CjKsWZi8.js +89 -0
  125. package/dist/requests-BwD6MKEq.js +282 -0
  126. package/dist/requests-CJrUf465.d.ts +50 -0
  127. package/dist/review.d.ts +181 -0
  128. package/dist/review.js +1017 -0
  129. package/dist/same-origin-BGet22CC.js +21 -0
  130. package/dist/scan-DzJNXqOk.js +165 -0
  131. package/dist/selector-NSYSe7AZ.js +28 -0
  132. package/dist/seo-Dq9q_QkO.js +551 -0
  133. package/dist/seo-panel-CfiY-TnT.js +124 -0
  134. package/dist/server.d.ts +3 -39
  135. package/dist/server.js +2 -105
  136. package/dist/sessions-panel-COvhPAzv.js +98 -0
  137. package/dist/shortcut-s_mjGeU8.js +179 -0
  138. package/dist/state-CjjZPjPJ.js +40 -0
  139. package/dist/state-boundary.d.ts +26 -0
  140. package/dist/state-boundary.js +61 -0
  141. package/dist/store/convex.d.ts +33 -0
  142. package/dist/store/convex.js +52 -0
  143. package/dist/store-CQqIIKTc.js +59 -0
  144. package/dist/store-Ync9eb1G.js +67 -0
  145. package/dist/store.d.ts +76 -0
  146. package/dist/store.js +188 -0
  147. package/dist/styles-BA8ueHoV.js +342 -0
  148. package/dist/styles-DKU_P8MH.js +139 -0
  149. package/dist/styles-DPpDPmzi.js +68 -0
  150. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  151. package/dist/types-B-ulf2Jp.js +8 -0
  152. package/dist/types-BIgGf-0C.d.ts +25 -0
  153. package/dist/types-BIkI-qN8.js +30 -0
  154. package/dist/types-Cxh4twqc.d.ts +50 -0
  155. package/dist/types-DIdPfjtV.js +6 -0
  156. package/dist/types-DaJcsEjO.d.ts +44 -0
  157. package/dist/types-Dn68psVz.d.ts +118 -0
  158. package/dist/types-f3jlNxzw.d.ts +92 -0
  159. package/dist/types-szkr2QOF.d.ts +39 -0
  160. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  161. package/dist/variant-groups-TIfO3NIj.js +137 -0
  162. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  163. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  164. package/dist/variants-types-CcRf119M.d.ts +63 -0
  165. package/dist/variants.d.ts +43 -0
  166. package/dist/variants.js +83 -0
  167. package/dist/vitals-panel-BCmMUntW.js +30 -0
  168. package/dist/vite.d.ts +37 -0
  169. package/dist/vite.js +134 -0
  170. package/package.json +85 -5
  171. package/dist/define-hud-BHQR8Lbv.d.ts +0 -31
  172. package/dist/plugins-1QmTmZyL.d.ts +0 -76
@@ -0,0 +1,122 @@
1
+ import { r as HudCapability } from "../../plugins-BZvDqGx5.js";
2
+ import { t as HudEnv } from "../../env-CApnbI0r.js";
3
+ import { a as signHudUnlockToken, c as CAPABILITY_MATRIX, d as hasCapability, f as isHudVisible, i as resolveHudAccess, l as CapabilityMatrixOverride, n as HudAccess, o as verifyHudUnlockToken, p as isProductionDenied, r as hudRequiresUnlock, s as ACCESS_UNLOCK_CAPABILITY, t as HUD_UNLOCK_COOKIE, u as HUD_CAPABILITIES } from "../../access-D_ewAEJG.js";
4
+ import { t as HudGuard } from "../../handler-DtYVCZY6.js";
5
+ //#region src/plugins/access/server/settings.d.ts
6
+ /** What the server half reads from its environment, per request. */
7
+ interface AccessSettings {
8
+ env: HudEnv;
9
+ /** `NEXT_PUBLIC_HUD_ENABLED=true`: the deployed tier opted in. */
10
+ enabled: boolean;
11
+ /** `HUD_ACCESS_PASSWORD`. Server only: never pass it to client code. */
12
+ password: string | undefined;
13
+ /**
14
+ * `HUD_ACCESS_SECRET`: optional, server only. When set, the unlock cookie is
15
+ * signed with it instead of the password, so a stolen cookie gives nothing
16
+ * to guess the password against.
17
+ */
18
+ secret?: string | undefined;
19
+ }
20
+ interface AccessServerOptions {
21
+ /** Path `createHudHandler` is mounted at, for the guard's unlock exemption. Default `/api/hud`. */
22
+ basePath?: string;
23
+ /** Replaces the default matrix's list for a deployed tier. Keep it equal to the client half's. */
24
+ matrix?: CapabilityMatrixOverride;
25
+ /** Default: `readAccessSettings`, i.e. `process.env`. A seam for tests and the playground. */
26
+ settings?: () => AccessSettings;
27
+ }
28
+ /**
29
+ * Reads the env ladder, the opt-in flag and the secrets, at call time.
30
+ * `HUD_DISABLED=true` is a runtime kill switch: unlike the `NEXT_PUBLIC_*`
31
+ * flags, which are inlined at build time, it takes effect on a restart
32
+ * without a rebuild, and turns every route into a 404.
33
+ */
34
+ export declare function readAccessSettings(): AccessSettings;
35
+ //#endregion
36
+ //#region src/plugins/access/server/guard.d.ts
37
+ interface HudGuardRequest {
38
+ headers: {
39
+ get(name: string): string | null;
40
+ };
41
+ }
42
+ type HudGuardResult = {
43
+ ok: true;
44
+ env: HudEnv;
45
+ } | {
46
+ ok: false;
47
+ status: 401 | 403 | 404;
48
+ error: string;
49
+ };
50
+ /**
51
+ * Whether this request may exercise `capability` right now.
52
+ *
53
+ * Order matters: a HUD that is not enabled answers 404 (nothing here), a
54
+ * denied capability answers 403 before any password is considered (the
55
+ * password must never be a way to widen the matrix), and only a permitted
56
+ * capability gets as far as the unlock check. A route without a capability
57
+ * is development-only: default-deny means undeclared is denied.
58
+ */
59
+ export declare function checkHudRequest(request: HudGuardRequest, capability: HudCapability | undefined, options?: AccessServerOptions): Promise<HudGuardResult>;
60
+ /** Whether the request already carries a valid unlock (the status route). */
61
+ export declare function isHudRequestUnlocked(request: HudGuardRequest, options?: AccessServerOptions): Promise<boolean>;
62
+ //#endregion
63
+ //#region src/plugins/access/server/unlock.d.ts
64
+ interface HudUnlockRequest extends HudGuardRequest {
65
+ json(): Promise<unknown>;
66
+ }
67
+ interface HudUnlockResult {
68
+ status: number;
69
+ body: Record<string, unknown>;
70
+ /** `Set-Cookie` value, when the attempt changed the unlock state. */
71
+ setCookie?: string;
72
+ }
73
+ /**
74
+ * GET: what the client needs to decide between the panels and the lock, and
75
+ * nothing more. The route is reachable while locked, so it names no tier.
76
+ */
77
+ export declare function handleHudUnlockStatus(request: HudGuardRequest, options?: AccessServerOptions): Promise<HudUnlockResult>;
78
+ /** POST: exchanges the password for a signed, expiring unlock cookie. */
79
+ export declare function handleHudUnlockAttempt(request: HudUnlockRequest, options?: AccessServerOptions): Promise<HudUnlockResult>;
80
+ /** Test seam: the attempt budget is process state, not request state. */
81
+ export declare function resetHudUnlockAttempts(): void;
82
+ /** Test seam: how many clients the attempt budget tracks. */
83
+ export declare function trackedHudUnlockClients(): number;
84
+ //#endregion
85
+ //#region src/plugins/access/server.d.ts
86
+ /**
87
+ * The guard for `createHudHandler({ guard })` on deployed tiers. It answers
88
+ * exactly like the old `checkHudRequest`: 404 while the tier has not opted in,
89
+ * 403 for a capability the tier's matrix denies (before any password is
90
+ * considered), 401 until the request carries a valid unlock cookie. In
91
+ * development it lets everything through, like `developmentOnly`.
92
+ *
93
+ * The unlock route itself is the one exemption, so a locked HUD can unlock.
94
+ * Pass the handler's `basePath` when it is not `/api/hud`.
95
+ */
96
+ export declare function accessGuard(options?: AccessServerOptions): HudGuard;
97
+ /**
98
+ * Server half of the access plugin: `GET|POST <basePath>/access/unlock`.
99
+ * GET reports `{ unlocked, configured }`; POST trades `{ password }` for an
100
+ * httpOnly cookie. Wrong passwords are budgeted: ten per client per ten
101
+ * minutes, and past a hundred overall every client with failures of its own
102
+ * is throttled; a throttled client gets 429 even for the right password.
103
+ *
104
+ * ```ts
105
+ * const options = {};
106
+ * export const { GET, POST } = createHudHandler([accessServer(options), ...], {
107
+ * guard: accessGuard(options),
108
+ * });
109
+ * ```
110
+ */
111
+ export declare function accessServer(options?: AccessServerOptions): {
112
+ readonly id: "access";
113
+ readonly capability: "access.unlock";
114
+ readonly routes: {
115
+ readonly "/unlock": {
116
+ readonly GET: (request: Request) => Promise<Response>;
117
+ readonly POST: (request: Request) => Promise<Response>;
118
+ };
119
+ };
120
+ };
121
+ //#endregion
122
+ export { ACCESS_UNLOCK_CAPABILITY, type AccessServerOptions, type AccessSettings, CAPABILITY_MATRIX, type CapabilityMatrixOverride, HUD_CAPABILITIES, HUD_UNLOCK_COOKIE, type HudAccess, type HudGuardResult, hasCapability, hudRequiresUnlock, isHudVisible, isProductionDenied, resolveHudAccess, signHudUnlockToken, verifyHudUnlockToken };
@@ -0,0 +1,340 @@
1
+ import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
2
+ import { n as resolveHudEnv } from "../../env-CaiFPIhF.js";
3
+ import { a as readCookie, c as timingSafeEqual, i as hudUnlockTtlMs, l as verifyHudUnlockToken, n as hudRequiresUnlock, o as resolveHudAccess, r as hudUnlockCookieString, s as signHudUnlockToken, t as HUD_UNLOCK_COOKIE } from "../../access-C7zlaqj6.js";
4
+ import { a as isHudVisible, i as hasCapability, n as CAPABILITY_MATRIX, o as isProductionDenied, r as HUD_CAPABILITIES, s as resolveMatrix, t as ACCESS_UNLOCK_CAPABILITY } from "../../capabilities-rDSKjXpq.js";
5
+ //#region src/plugins/access/server/settings.ts
6
+ /** The key material unlock cookies are signed with. */
7
+ function signingSecret({ secret, password }) {
8
+ return secret || password;
9
+ }
10
+ /**
11
+ * Reads the env ladder, the opt-in flag and the secrets, at call time.
12
+ * `HUD_DISABLED=true` is a runtime kill switch: unlike the `NEXT_PUBLIC_*`
13
+ * flags, which are inlined at build time, it takes effect on a restart
14
+ * without a rebuild, and turns every route into a 404.
15
+ */
16
+ function readAccessSettings() {
17
+ return {
18
+ env: process.env.HUD_DISABLED === "true" ? "disabled" : resolveHudEnv(),
19
+ enabled: process.env.NEXT_PUBLIC_HUD_ENABLED === "true",
20
+ password: process.env.HUD_ACCESS_PASSWORD || void 0,
21
+ secret: process.env.HUD_ACCESS_SECRET || void 0
22
+ };
23
+ }
24
+ //#endregion
25
+ //#region src/plugins/access/server/guard.ts
26
+ /**
27
+ * Whether this request may exercise `capability` right now.
28
+ *
29
+ * Order matters: a HUD that is not enabled answers 404 (nothing here), a
30
+ * denied capability answers 403 before any password is considered (the
31
+ * password must never be a way to widen the matrix), and only a permitted
32
+ * capability gets as far as the unlock check. A route without a capability
33
+ * is development-only: default-deny means undeclared is denied.
34
+ */
35
+ async function checkHudRequest(request, capability, options = {}) {
36
+ const settings = (options.settings ?? readAccessSettings)();
37
+ const { env, enabled, password } = settings;
38
+ if (!isHudVisible(env, enabled)) return {
39
+ ok: false,
40
+ status: 404,
41
+ error: "not found"
42
+ };
43
+ if (env !== "development" && (capability === void 0 || !hasCapability(env, capability, resolveMatrix(options.matrix)))) return {
44
+ ok: false,
45
+ status: 403,
46
+ error: "forbidden"
47
+ };
48
+ const access = resolveHudAccess(env);
49
+ if (!hudRequiresUnlock(access)) return {
50
+ ok: true,
51
+ env
52
+ };
53
+ if (!password) return {
54
+ ok: false,
55
+ status: 401,
56
+ error: "hud unlock is not configured"
57
+ };
58
+ const token = readCookie(request.headers.get("cookie"), HUD_UNLOCK_COOKIE);
59
+ if (!await verifyHudUnlockToken(token, signingSecret(settings), env, { ttlMs: hudUnlockTtlMs(access) })) return {
60
+ ok: false,
61
+ status: 401,
62
+ error: "hud is locked"
63
+ };
64
+ return {
65
+ ok: true,
66
+ env
67
+ };
68
+ }
69
+ /** Whether the request already carries a valid unlock (the status route). */
70
+ async function isHudRequestUnlocked(request, options = {}) {
71
+ const settings = (options.settings ?? readAccessSettings)();
72
+ const access = resolveHudAccess(settings.env);
73
+ if (access === "denied") return false;
74
+ if (!hudRequiresUnlock(access)) return true;
75
+ if (!settings.password) return false;
76
+ const token = readCookie(request.headers.get("cookie"), HUD_UNLOCK_COOKIE);
77
+ return verifyHudUnlockToken(token, signingSecret(settings), settings.env, { ttlMs: hudUnlockTtlMs(access) });
78
+ }
79
+ //#endregion
80
+ //#region src/plugins/access/server/unlock.ts
81
+ /**
82
+ * The unlock route, `<basePath>/access/unlock`. Verification is an HMAC over
83
+ * the tier and the token's own issue time (see ../access.ts), so nothing is
84
+ * stored server side apart from the failed-attempt budget.
85
+ */
86
+ /**
87
+ * Failed-attempt budget, per process. The password is the only barrier in
88
+ * front of a deployed HUD, and a pod lives long enough that unlimited
89
+ * guessing is a real risk. Deliberately crude: an in-memory counter is
90
+ * enough friction for an operator-facing surface, and it cannot fail open
91
+ * the way a shared store can when it is unreachable.
92
+ *
93
+ * The throttle is checked before the password, so a throttled client gets
94
+ * 429 even for the right one; a guess that lands while throttled is worth
95
+ * nothing. Two budgets:
96
+ *
97
+ * - ten failures per client;
98
+ * - a ceiling of a hundred across all clients, against address rotation.
99
+ * It blocks only clients with recent failures of their own, so an
100
+ * operator who has not mistyped still unlocks during an attack.
101
+ */
102
+ const ATTEMPT_WINDOW_MS = 6e5;
103
+ const MAX_FAILED_ATTEMPTS = 10;
104
+ const MAX_FAILED_GLOBAL = 100;
105
+ /** Most clients tracked at once. */
106
+ const MAX_TRACKED = 1e3;
107
+ /**
108
+ * Requests without client headers share this key. It has no per-client
109
+ * limit (it would let anyone lock out everyone), only the global ceiling.
110
+ */
111
+ const UNKNOWN_CLIENT = "unknown";
112
+ const failures = /* @__PURE__ */ new Map();
113
+ let globalFailures = {
114
+ count: 0,
115
+ firstAt: 0
116
+ };
117
+ function isLive(bucket, now) {
118
+ return now - bucket.firstAt <= ATTEMPT_WINDOW_MS;
119
+ }
120
+ /**
121
+ * `x-real-ip` when the proxy sets it, else the last `x-forwarded-for` entry:
122
+ * the one the trusted proxy appended. Entries before it are whatever the
123
+ * client sent, so keying on them would let a client pick its own bucket.
124
+ */
125
+ function clientKey(request) {
126
+ const realIp = request.headers.get("x-real-ip")?.trim();
127
+ if (realIp) return realIp;
128
+ return request.headers.get("x-forwarded-for")?.split(",").at(-1)?.trim() || UNKNOWN_CLIENT;
129
+ }
130
+ function isThrottled(key, now) {
131
+ const entry = failures.get(key);
132
+ if (!entry || !isLive(entry, now)) return false;
133
+ if (key !== UNKNOWN_CLIENT && entry.count >= MAX_FAILED_ATTEMPTS) return true;
134
+ return isLive(globalFailures, now) && globalFailures.count >= MAX_FAILED_GLOBAL;
135
+ }
136
+ /** Makes room for one more client without resetting a bucket close to its limit. */
137
+ function makeRoom(now) {
138
+ if (failures.size < MAX_TRACKED) return true;
139
+ for (const [key, tracked] of failures) if (!isLive(tracked, now)) failures.delete(key);
140
+ if (failures.size < MAX_TRACKED) return true;
141
+ for (const [key, tracked] of failures) if (tracked.count < MAX_FAILED_ATTEMPTS / 2) {
142
+ failures.delete(key);
143
+ return true;
144
+ }
145
+ return false;
146
+ }
147
+ function recordFailure(key, now) {
148
+ if (isLive(globalFailures, now)) globalFailures.count += 1;
149
+ else globalFailures = {
150
+ count: 1,
151
+ firstAt: now
152
+ };
153
+ const entry = failures.get(key);
154
+ if (entry && isLive(entry, now)) {
155
+ entry.count += 1;
156
+ return;
157
+ }
158
+ failures.delete(key);
159
+ if (makeRoom(now)) failures.set(key, {
160
+ count: 1,
161
+ firstAt: now
162
+ });
163
+ }
164
+ /**
165
+ * GET: what the client needs to decide between the panels and the lock, and
166
+ * nothing more. The route is reachable while locked, so it names no tier.
167
+ */
168
+ async function handleHudUnlockStatus(request, options = {}) {
169
+ const settings = (options.settings ?? readAccessSettings)();
170
+ const { env, enabled, password } = settings;
171
+ if (!isHudVisible(env, enabled)) return {
172
+ status: 404,
173
+ body: { error: "not found" }
174
+ };
175
+ const required = hudRequiresUnlock(resolveHudAccess(env));
176
+ return {
177
+ status: 200,
178
+ body: {
179
+ unlocked: await isHudRequestUnlocked(request, { settings: () => settings }),
180
+ configured: !required || Boolean(password)
181
+ }
182
+ };
183
+ }
184
+ /** POST: exchanges the password for a signed, expiring unlock cookie. */
185
+ async function handleHudUnlockAttempt(request, options = {}) {
186
+ const settings = (options.settings ?? readAccessSettings)();
187
+ const { env, enabled, password: expected } = settings;
188
+ if (!isHudVisible(env, enabled)) return {
189
+ status: 404,
190
+ body: { error: "not found" }
191
+ };
192
+ const access = resolveHudAccess(env);
193
+ if (!hudRequiresUnlock(access)) return {
194
+ status: 200,
195
+ body: {
196
+ unlocked: true,
197
+ required: false
198
+ }
199
+ };
200
+ const secret = signingSecret(settings);
201
+ if (!expected || !secret) return {
202
+ status: 503,
203
+ body: {
204
+ unlocked: false,
205
+ configured: false,
206
+ error: "hud unlock is not configured"
207
+ }
208
+ };
209
+ const now = Date.now();
210
+ const key = clientKey(request);
211
+ if (isThrottled(key, now)) return {
212
+ status: 429,
213
+ body: {
214
+ unlocked: false,
215
+ error: "too many attempts, try again later"
216
+ }
217
+ };
218
+ let submitted = "";
219
+ try {
220
+ const payload = await request.json();
221
+ if (typeof payload?.password === "string") submitted = payload.password;
222
+ } catch {}
223
+ if (!submitted || !timingSafeEqual(submitted, expected)) {
224
+ recordFailure(key, now);
225
+ return {
226
+ status: 401,
227
+ body: {
228
+ unlocked: false,
229
+ error: "wrong password"
230
+ }
231
+ };
232
+ }
233
+ failures.delete(key);
234
+ const ttlMs = hudUnlockTtlMs(access);
235
+ return {
236
+ status: 200,
237
+ body: {
238
+ unlocked: true,
239
+ expiresInMs: ttlMs
240
+ },
241
+ setCookie: hudUnlockCookieString(await signHudUnlockToken(secret, env, now), ttlMs)
242
+ };
243
+ }
244
+ /** Test seam: the attempt budget is process state, not request state. */
245
+ function resetHudUnlockAttempts() {
246
+ failures.clear();
247
+ globalFailures = {
248
+ count: 0,
249
+ firstAt: 0
250
+ };
251
+ }
252
+ /** Test seam: how many clients the attempt budget tracks. */
253
+ function trackedHudUnlockClients() {
254
+ return failures.size;
255
+ }
256
+ //#endregion
257
+ //#region src/plugins/access/server.ts
258
+ function toResponse({ status, body, setCookie }) {
259
+ const res = Response.json(body, {
260
+ status,
261
+ headers: { "cache-control": "no-store" }
262
+ });
263
+ if (setCookie) res.headers.append("set-cookie", setCookie);
264
+ return res;
265
+ }
266
+ function splitPath(path) {
267
+ return path.split("/").filter(Boolean);
268
+ }
269
+ /**
270
+ * The guard for `createHudHandler({ guard })` on deployed tiers. It answers
271
+ * exactly like the old `checkHudRequest`: 404 while the tier has not opted in,
272
+ * 403 for a capability the tier's matrix denies (before any password is
273
+ * considered), 401 until the request carries a valid unlock cookie. In
274
+ * development it lets everything through, like `developmentOnly`.
275
+ *
276
+ * The unlock route itself is the one exemption, so a locked HUD can unlock.
277
+ * Pass the handler's `basePath` when it is not `/api/hud`.
278
+ */
279
+ function accessGuard(options = {}) {
280
+ const settings = options.settings ?? readAccessSettings;
281
+ const unlockPath = [
282
+ ...splitPath(options.basePath ?? "/api/hud"),
283
+ "access",
284
+ "unlock"
285
+ ].join("/");
286
+ return async (request, capability) => {
287
+ const path = splitPath(new URL(request.url).pathname).join("/");
288
+ if (capability === "access.unlock" && path === unlockPath) {
289
+ const { env, enabled } = settings();
290
+ return isHudVisible(env, enabled) ? null : Response.json({
291
+ ok: false,
292
+ error: "not found"
293
+ }, { status: 404 });
294
+ }
295
+ const result = await checkHudRequest(request, capability, {
296
+ ...options,
297
+ settings
298
+ });
299
+ if (result.ok) return null;
300
+ return Response.json({
301
+ ok: false,
302
+ error: result.error
303
+ }, {
304
+ status: result.status,
305
+ headers: { "cache-control": "no-store" }
306
+ });
307
+ };
308
+ }
309
+ /**
310
+ * Server half of the access plugin: `GET|POST <basePath>/access/unlock`.
311
+ * GET reports `{ unlocked, configured }`; POST trades `{ password }` for an
312
+ * httpOnly cookie. Wrong passwords are budgeted: ten per client per ten
313
+ * minutes, and past a hundred overall every client with failures of its own
314
+ * is throttled; a throttled client gets 429 even for the right password.
315
+ *
316
+ * ```ts
317
+ * const options = {};
318
+ * export const { GET, POST } = createHudHandler([accessServer(options), ...], {
319
+ * guard: accessGuard(options),
320
+ * });
321
+ * ```
322
+ */
323
+ function accessServer(options = {}) {
324
+ return definePlugin({
325
+ id: "access",
326
+ capability: ACCESS_UNLOCK_CAPABILITY,
327
+ routes: { "/unlock": {
328
+ GET: async (request) => request.method === "GET" ? toResponse(await handleHudUnlockStatus(request, options)) : Response.json({
329
+ ok: false,
330
+ error: "method not allowed"
331
+ }, {
332
+ status: 405,
333
+ headers: { allow: "GET, POST" }
334
+ }),
335
+ POST: async (request) => toResponse(await handleHudUnlockAttempt(request, options))
336
+ } }
337
+ });
338
+ }
339
+ //#endregion
340
+ export { ACCESS_UNLOCK_CAPABILITY, CAPABILITY_MATRIX, HUD_CAPABILITIES, HUD_UNLOCK_COOKIE, accessGuard, accessServer, checkHudRequest, handleHudUnlockAttempt, handleHudUnlockStatus, hasCapability, hudRequiresUnlock, isHudRequestUnlocked, isHudVisible, isProductionDenied, readAccessSettings, resetHudUnlockAttempts, resolveHudAccess, signHudUnlockToken, trackedHudUnlockClients, verifyHudUnlockToken };
@@ -0,0 +1,41 @@
1
+ import { c as HudPluginProps, r as HudCapability } from "../plugins-BZvDqGx5.js";
2
+ import { c as CAPABILITY_MATRIX, d as hasCapability, i as resolveHudAccess, l as CapabilityMatrixOverride, n as HudAccess, p as isProductionDenied, r as hudRequiresUnlock, s as ACCESS_UNLOCK_CAPABILITY, u as HUD_CAPABILITIES } from "../access-D_ewAEJG.js";
3
+ //#region src/plugins/access/access-pill.d.ts
4
+ declare function AccessPill(): import("react").JSX.Element;
5
+ //#endregion
6
+ //#region src/plugins/access/unlock-store.d.ts
7
+ type UnlockStatus = "checking" | "locked" | "unlocked" | "unconfigured";
8
+ /**
9
+ * `HudAccessControl.useUnlocked`: development is open, a disabled or unknown
10
+ * tier never unlocks, every deployed tier asks the server once per mount.
11
+ */
12
+ declare function useUnlocked(envName: string, apiBase: string): boolean;
13
+ //#endregion
14
+ //#region src/plugins/access/index.d.ts
15
+ export interface AccessOptions {
16
+ /** Replaces the default matrix's list for a deployed tier. Keep it equal to the server half's. */
17
+ matrix?: CapabilityMatrixOverride;
18
+ }
19
+ /**
20
+ * Opt-in for deployed tiers. Without it `defineHud` renders nothing outside
21
+ * development. With it the HUD follows the env ladder: a tier's capability
22
+ * matrix narrows the plugins, and until the operator unlocks with the
23
+ * server's password only this plugin's lock shows.
24
+ *
25
+ * Client half; the password check lives in `@hansenexus/hud/plugins/access/server`
26
+ * (`accessServer()` + `accessGuard()`), and the password never reaches the browser.
27
+ */
28
+ export declare function access(options?: AccessOptions): {
29
+ readonly id: "access";
30
+ readonly title: "Access";
31
+ readonly capability: "access.unlock";
32
+ readonly pill: typeof AccessPill;
33
+ readonly pillPriority: 30;
34
+ readonly panel: ({ ctx }: HudPluginProps) => import("react").JSX.Element;
35
+ readonly access: {
36
+ readonly can: (env: string, capability: HudCapability) => boolean;
37
+ readonly useUnlocked: typeof useUnlocked;
38
+ };
39
+ };
40
+ //#endregion
41
+ export { ACCESS_UNLOCK_CAPABILITY, CAPABILITY_MATRIX, type CapabilityMatrixOverride, HUD_CAPABILITIES, type HudAccess, type UnlockStatus, hasCapability, hudRequiresUnlock, isProductionDenied, resolveHudAccess };
@@ -0,0 +1,51 @@
1
+ import { i as definePlugin } from "../plugins-DVy_vaYr.js";
2
+ import { n as hudRequiresUnlock, o as resolveHudAccess } from "../access-C7zlaqj6.js";
3
+ import { c as toHudEnv, i as hasCapability, n as CAPABILITY_MATRIX, o as isProductionDenied, r as HUD_CAPABILITIES, s as resolveMatrix, t as ACCESS_UNLOCK_CAPABILITY } from "../capabilities-rDSKjXpq.js";
4
+ import { n as useUnlockState, r as useUnlocked } from "../unlock-store-4V3vR4Eg.js";
5
+ import { lazy } from "react";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ //#region src/plugins/access/access-pill.tsx
8
+ function AccessPill() {
9
+ const { env, status } = useUnlockState();
10
+ const access = resolveHudAccess(env);
11
+ const unlocked = access === "open" || status === "unlocked";
12
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
13
+ className: "dot",
14
+ "data-rating": unlocked ? "good" : "poor"
15
+ }), access === "open" ? "Open" : unlocked ? "Unlocked" : "Locked"] });
16
+ }
17
+ //#endregion
18
+ //#region src/plugins/access/index.tsx
19
+ const Panel = lazy(() => import("../access-panel-CEfTr9ZI.js"));
20
+ /**
21
+ * Opt-in for deployed tiers. Without it `defineHud` renders nothing outside
22
+ * development. With it the HUD follows the env ladder: a tier's capability
23
+ * matrix narrows the plugins, and until the operator unlocks with the
24
+ * server's password only this plugin's lock shows.
25
+ *
26
+ * Client half; the password check lives in `@hansenexus/hud/plugins/access/server`
27
+ * (`accessServer()` + `accessGuard()`), and the password never reaches the browser.
28
+ */
29
+ function access(options = {}) {
30
+ const matrix = resolveMatrix(options.matrix);
31
+ function AccessPanel({ ctx }) {
32
+ return /* @__PURE__ */ jsx(Panel, {
33
+ ctx,
34
+ matrix
35
+ });
36
+ }
37
+ return definePlugin({
38
+ id: "access",
39
+ title: "Access",
40
+ capability: ACCESS_UNLOCK_CAPABILITY,
41
+ pill: AccessPill,
42
+ pillPriority: 30,
43
+ panel: AccessPanel,
44
+ access: {
45
+ can: (env, capability) => capability === "access.unlock" || hasCapability(toHudEnv(env), capability, matrix),
46
+ useUnlocked
47
+ }
48
+ });
49
+ }
50
+ //#endregion
51
+ export { ACCESS_UNLOCK_CAPABILITY, CAPABILITY_MATRIX, HUD_CAPABILITIES, access, hasCapability, hudRequiresUnlock, isProductionDenied, resolveHudAccess };
@@ -0,0 +1,94 @@
1
+ import { r as GrabPayload, t as ComponentHint } from "../../payload-MUQ9ciER.js";
2
+ import { a as DispatchTargetInfo, i as DispatchReceipt, n as AgentSessionStatus, o as SessionsResponse, r as DispatchBody, t as AgentSession } from "../../types-Cxh4twqc.js";
3
+ import { n as DispatchProvider, r as ProviderStatus, t as DispatchOrder } from "../../types-szkr2QOF.js";
4
+ import { ChildProcess, SpawnOptions } from "node:child_process";
5
+ //#region src/plugins/agent/prompt.d.ts
6
+ interface PromptInput {
7
+ note: string;
8
+ payload: GrabPayload | null;
9
+ hints?: readonly ComponentHint[] | undefined;
10
+ }
11
+ /** The task text every provider receives: grab context first, then the instruction. */
12
+ export declare function dispatchPrompt({ note, payload, hints }: PromptInput): string;
13
+ //#endregion
14
+ //#region src/plugins/agent/providers/claude-code.d.ts
15
+ interface ClaudeCodeOptions {
16
+ /** Repository the agent works in. Default `process.cwd()`, the dev server's root. */
17
+ cwd?: string;
18
+ /** Default `claude`. */
19
+ command?: string;
20
+ /**
21
+ * Arguments for one run. Default `["-p", prompt, "--permission-mode", "acceptEdits"]`:
22
+ * headless, may edit files, asks (and therefore stops) before running commands.
23
+ */
24
+ args?: (prompt: string) => string[];
25
+ label?: string;
26
+ /** Where each run's stdout and stderr go. Default `<tmpdir>/hud-agent`. */
27
+ logDir?: string;
28
+ /** How many recent transcripts the Sessions panel lists. Default 8. */
29
+ transcripts?: number;
30
+ /** Home directory holding `.claude/projects`. Default `os.homedir()`. */
31
+ home?: string;
32
+ /** Test seam. */
33
+ spawn?: (command: string, args: string[], options: SpawnOptions) => ChildProcess;
34
+ }
35
+ /**
36
+ * Dispatches to a local Claude Code: each run is `claude -p <prompt>` spawned
37
+ * (argv, no shell) in `cwd`, detached so it outlives a dev-server reload, with
38
+ * its output in a log file. Sessions are the runs started here plus the most
39
+ * recent Claude Code transcripts of `cwd`.
40
+ */
41
+ export declare function claudeCode({ cwd: cwdOption, command, args, label, logDir: logDirOption, transcripts, home: homeOption, spawn: spawnOption }?: ClaudeCodeOptions): DispatchProvider;
42
+ //#endregion
43
+ //#region src/plugins/agent/providers/hermes.d.ts
44
+ interface HermesOptions {
45
+ /** Hermes Agent API server, e.g. `http://hn-hub:8642`. */
46
+ baseUrl: string;
47
+ /** Bearer token, or a getter read per request. Missing: the target shows as unavailable. */
48
+ token: string | undefined | (() => string | undefined);
49
+ /** Sent as the run's `instructions` (an ephemeral system prompt), e.g. a playbook. */
50
+ instructions?: string;
51
+ label?: string;
52
+ /** Per-request timeout. Default 10 s. */
53
+ timeoutMs?: number;
54
+ /** Test seam. */
55
+ fetch?: typeof fetch;
56
+ }
57
+ /**
58
+ * Dispatches to a Hermes Agent API server: `POST /v1/runs` starts a
59
+ * background run (202 `{ run_id }`), `GET /v1/jobs` lists runs for the
60
+ * Sessions panel. The token never leaves the server.
61
+ */
62
+ export declare function hermes({ baseUrl, token, instructions, label, timeoutMs, fetch: fetchImpl }: HermesOptions): DispatchProvider;
63
+ //#endregion
64
+ //#region src/plugins/agent/server.d.ts
65
+ export interface AgentServerOptions {
66
+ /** Dispatch backends, first available is the panel's default target. */
67
+ providers: readonly DispatchProvider[];
68
+ }
69
+ /**
70
+ * Server half of `agentDispatch`: `GET /targets` lists the providers,
71
+ * `POST /dispatch` hands a grab plus instruction to one of them.
72
+ */
73
+ export declare function agentDispatch({ providers }: AgentServerOptions): {
74
+ readonly id: "agent-dispatch";
75
+ readonly routes: {
76
+ readonly "/targets": {
77
+ GET: () => Promise<Response>;
78
+ };
79
+ readonly "/dispatch": {
80
+ readonly POST: (request: Request) => Promise<Response>;
81
+ };
82
+ };
83
+ };
84
+ /** Server half of `agentSessions`: `GET /sessions` merges every provider's sessions. */
85
+ export declare function agentSessions({ providers }: AgentServerOptions): {
86
+ readonly id: "agent-sessions";
87
+ readonly routes: {
88
+ "/sessions": {
89
+ GET: () => Promise<Response>;
90
+ };
91
+ };
92
+ };
93
+ //#endregion
94
+ export type { AgentSession, AgentSessionStatus, ClaudeCodeOptions, DispatchBody, DispatchOrder, DispatchProvider, DispatchReceipt, DispatchTargetInfo, HermesOptions, ProviderStatus, SessionsResponse };