@rocket.chat/houston 0.27.0-next.3 → 2.1.9

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 (294) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +109 -15
  3. package/bin/houston +62 -0
  4. package/data/docs/ARCHITECTURE.md +387 -0
  5. package/data/docs/automation.md +107 -0
  6. package/data/docs/e2ee.md +76 -0
  7. package/data/docs/eks.md +258 -0
  8. package/data/docs/gui.md +282 -0
  9. package/data/docs/guide.md +642 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/loadtest.md +264 -0
  12. package/data/docs/troubleshooting.md +203 -0
  13. package/data/docs/upgrading.md +84 -0
  14. package/data/docs/voice.md +253 -0
  15. package/data/iam/engineer-policy.json +11 -0
  16. package/data/iam/engineer-rbac.yaml +42 -0
  17. package/data/iam/operator-policy.json +211 -0
  18. package/data/loadtest/badbot.js +22 -0
  19. package/data/loadtest/common.js +170 -0
  20. package/data/loadtest/custom.js +20 -0
  21. package/data/loadtest/journey.js +58 -0
  22. package/data/loadtest/login.js +18 -0
  23. package/data/loadtest/messages.js +13 -0
  24. package/data/loadtest/mixed.js +57 -0
  25. package/data/loadtest/read.js +12 -0
  26. package/data/loadtest/webhook.js +20 -0
  27. package/data/monitoring/houston-logs.json +98 -0
  28. package/data/monitoring/k6-loadtest.json +610 -0
  29. package/data/monitoring/mongodb-exporter.json +3007 -0
  30. package/data/monitoring/node-exporter-full.json +16114 -0
  31. package/data/monitoring/rocketchat-metrics.json +6471 -0
  32. package/data/presets/airgapped.yaml +16 -0
  33. package/data/presets/default.yaml +9 -0
  34. package/data/seed/avatar-0.png +0 -0
  35. package/data/seed/avatar-1.png +0 -0
  36. package/data/seed/avatar-2.png +0 -0
  37. package/data/seed/avatar-3.png +0 -0
  38. package/data/seed/avatar-4.png +0 -0
  39. package/data/seed/avatar-5.png +0 -0
  40. package/data/seed/avatar-6.png +0 -0
  41. package/data/seed/avatar-7.png +0 -0
  42. package/data/seed/seed-metrics.csv +3 -0
  43. package/data/seed/seed-preview.png +0 -0
  44. package/data/seed/seed-report.pdf +32 -0
  45. package/data/seed/seed-runbook.txt +3 -0
  46. package/data/skill/SKILL.md +399 -0
  47. package/data/versions.yaml +55 -0
  48. package/data/voice/freeswitch/drachtio.xml +52 -0
  49. package/data/voice/freeswitch/public.xml +87 -0
  50. package/data/webui/app.css +2003 -0
  51. package/data/webui/index.html +678 -0
  52. package/data/webui/js/api.js +561 -0
  53. package/data/webui/js/boot.js +44 -0
  54. package/data/webui/js/clusters-tail.js +1377 -0
  55. package/data/webui/js/clusters.js +896 -0
  56. package/data/webui/js/create.js +276 -0
  57. package/data/webui/js/detail.js +507 -0
  58. package/data/webui/js/jobs.js +636 -0
  59. package/data/webui/js/logs.js +634 -0
  60. package/data/webui/js/main.js +14 -0
  61. package/data/webui/js/options.js +408 -0
  62. package/data/webui/js/people.js +438 -0
  63. package/data/webui/js/perf.js +303 -0
  64. package/data/webui/js/render.js +438 -0
  65. package/data/webui/js/shared.js +3 -0
  66. package/data/webui/js/state.js +583 -0
  67. package/data/webui/js/theme.js +123 -0
  68. package/data/webui/js/util.js +584 -0
  69. package/dist/cli/app.js +593 -0
  70. package/dist/cli/capabilities.js +76 -0
  71. package/dist/cli/cell-widths.js +495 -0
  72. package/dist/cli/entry.js +10 -0
  73. package/dist/cli/error-panel.js +492 -0
  74. package/dist/cli/handlers/actor.js +84 -0
  75. package/dist/cli/handlers/https.js +614 -0
  76. package/dist/cli/handlers/prompt.js +299 -0
  77. package/dist/cli/handlers/users.js +226 -0
  78. package/dist/cli/handlers.js +3694 -0
  79. package/dist/cli/help.js +183 -0
  80. package/dist/cli/index.js +15 -0
  81. package/dist/cli/perf.js +814 -0
  82. package/dist/cli/render.js +254 -0
  83. package/dist/cli/serve.js +858 -0
  84. package/dist/cli/spec-data.js +2599 -0
  85. package/dist/cli/spec-types.js +8 -0
  86. package/dist/cli/usage-error.js +520 -0
  87. package/dist/cli/wire.js +70 -0
  88. package/dist/core/audit.js +346 -0
  89. package/dist/core/backup-compat.js +85 -0
  90. package/dist/core/backup.js +1639 -0
  91. package/dist/core/cluster.js +1398 -0
  92. package/dist/core/configimport.js +345 -0
  93. package/dist/core/data.js +267 -0
  94. package/dist/core/database-of.js +82 -0
  95. package/dist/core/diagnose.js +159 -0
  96. package/dist/core/doctor.js +1518 -0
  97. package/dist/core/edge/acme.js +338 -0
  98. package/dist/core/edge/engine.js +500 -0
  99. package/dist/core/edge/networks.js +174 -0
  100. package/dist/core/edge/paths.js +107 -0
  101. package/dist/core/edge/routes.js +251 -0
  102. package/dist/core/edge/routeyml.js +195 -0
  103. package/dist/core/edge/runtime.js +493 -0
  104. package/dist/core/edge/spec.js +305 -0
  105. package/dist/core/edge/types.js +202 -0
  106. package/dist/core/eks-docs.js +135 -0
  107. package/dist/core/eks.js +2240 -0
  108. package/dist/core/envvars.js +562 -0
  109. package/dist/core/eventlog.js +541 -0
  110. package/dist/core/firstrun.js +153 -0
  111. package/dist/core/journal.js +694 -0
  112. package/dist/core/kube/ask.js +231 -0
  113. package/dist/core/kube/capabilities.js +269 -0
  114. package/dist/core/kube/certmanager.js +452 -0
  115. package/dist/core/kube/chart.js +413 -0
  116. package/dist/core/kube/cluster.js +196 -0
  117. package/dist/core/kube/context.js +545 -0
  118. package/dist/core/kube/endpoints.js +448 -0
  119. package/dist/core/kube/exec.js +195 -0
  120. package/dist/core/kube/forward.js +732 -0
  121. package/dist/core/kube/grafana-ingress.js +110 -0
  122. package/dist/core/kube/ingress.js +218 -0
  123. package/dist/core/kube/manifests.js +361 -0
  124. package/dist/core/kube/monitoring.js +768 -0
  125. package/dist/core/kube/names.js +237 -0
  126. package/dist/core/kube/namespace.js +678 -0
  127. package/dist/core/kube/operator.js +941 -0
  128. package/dist/core/kube/probe.js +202 -0
  129. package/dist/core/kube/reachability.js +163 -0
  130. package/dist/core/kube/release.js +439 -0
  131. package/dist/core/kube/replicaset.js +180 -0
  132. package/dist/core/kube/scale.js +398 -0
  133. package/dist/core/kube/status.js +633 -0
  134. package/dist/core/kube/tools.js +238 -0
  135. package/dist/core/kube/transfer.js +173 -0
  136. package/dist/core/kube/workspace.js +423 -0
  137. package/dist/core/lifecycle/admin.js +64 -0
  138. package/dist/core/lifecycle/create-docker.js +1549 -0
  139. package/dist/core/lifecycle/create-k8s.js +960 -0
  140. package/dist/core/lifecycle/destroy.js +339 -0
  141. package/dist/core/lifecycle/inspect.js +636 -0
  142. package/dist/core/lifecycle/naming.js +298 -0
  143. package/dist/core/lifecycle/notes.js +862 -0
  144. package/dist/core/lifecycle/ownership.js +313 -0
  145. package/dist/core/lifecycle/payload.js +401 -0
  146. package/dist/core/lifecycle/ports.js +388 -0
  147. package/dist/core/lifecycle/preconditions.js +367 -0
  148. package/dist/core/lifecycle/pruning.js +551 -0
  149. package/dist/core/lifecycle/ready.js +818 -0
  150. package/dist/core/lifecycle/request.js +510 -0
  151. package/dist/core/lifecycle/seeding.js +281 -0
  152. package/dist/core/lifecycle/sizing.js +392 -0
  153. package/dist/core/lifecycle/state.js +286 -0
  154. package/dist/core/lifecycle/tlsplan.js +704 -0
  155. package/dist/core/lifecycle/types.js +232 -0
  156. package/dist/core/loadtest.js +1051 -0
  157. package/dist/core/migrate.js +612 -0
  158. package/dist/core/monitor.js +494 -0
  159. package/dist/core/postready.js +976 -0
  160. package/dist/core/promote.js +804 -0
  161. package/dist/core/rcapi.js +1336 -0
  162. package/dist/core/recovery.js +75 -0
  163. package/dist/core/runner/engine.js +394 -0
  164. package/dist/core/runner/host.js +298 -0
  165. package/dist/core/runner/locks.js +129 -0
  166. package/dist/core/runner/paths.js +173 -0
  167. package/dist/core/runner/ports.js +172 -0
  168. package/dist/core/runner/queries.js +612 -0
  169. package/dist/core/runner/record.js +563 -0
  170. package/dist/core/scaleseed.js +271 -0
  171. package/dist/core/seed-db.js +208 -0
  172. package/dist/core/sessions.js +472 -0
  173. package/dist/core/skill.js +326 -0
  174. package/dist/core/sso-identities.js +172 -0
  175. package/dist/core/sso.js +703 -0
  176. package/dist/core/tls-local.js +311 -0
  177. package/dist/core/tls.js +878 -0
  178. package/dist/core/topology.js +482 -0
  179. package/dist/core/upgrade.js +877 -0
  180. package/dist/core/users.js +739 -0
  181. package/dist/lib/audit.js +100 -0
  182. package/dist/lib/close-matches.js +238 -0
  183. package/dist/lib/compose.js +672 -0
  184. package/dist/lib/config.js +1398 -0
  185. package/dist/lib/context.js +18 -0
  186. package/dist/lib/errors.js +305 -0
  187. package/dist/lib/events.js +208 -0
  188. package/dist/lib/float-text.js +126 -0
  189. package/dist/lib/format.js +1320 -0
  190. package/dist/lib/home.js +325 -0
  191. package/dist/lib/journal.js +122 -0
  192. package/dist/lib/json-text.js +733 -0
  193. package/dist/lib/jsonout.js +382 -0
  194. package/dist/lib/lock.js +516 -0
  195. package/dist/lib/login-name.js +202 -0
  196. package/dist/lib/map-limit.js +29 -0
  197. package/dist/lib/mkdir-parents.js +90 -0
  198. package/dist/lib/mongo-kernel.js +67 -0
  199. package/dist/lib/monitoring.js +492 -0
  200. package/dist/lib/platform-name.js +59 -0
  201. package/dist/lib/presets/common.js +390 -0
  202. package/dist/lib/presets/composite.js +326 -0
  203. package/dist/lib/presets/e2ee.js +143 -0
  204. package/dist/lib/presets/email.js +172 -0
  205. package/dist/lib/presets/guides.js +27 -0
  206. package/dist/lib/presets/index.js +490 -0
  207. package/dist/lib/presets/keycloak.js +371 -0
  208. package/dist/lib/presets/ldap.js +1285 -0
  209. package/dist/lib/presets/livechat.js +220 -0
  210. package/dist/lib/presets/multi-instance.js +124 -0
  211. package/dist/lib/presets/oidc.js +161 -0
  212. package/dist/lib/presets/public.js +496 -0
  213. package/dist/lib/presets/registry.js +64 -0
  214. package/dist/lib/presets/s3-minio.js +300 -0
  215. package/dist/lib/presets/saml.js +149 -0
  216. package/dist/lib/presets/scenario.js +51 -0
  217. package/dist/lib/presets/types.js +86 -0
  218. package/dist/lib/presets/voice-pbx.js +320 -0
  219. package/dist/lib/presets/voice.js +345 -0
  220. package/dist/lib/presets/webhooks.js +182 -0
  221. package/dist/lib/redact.js +106 -0
  222. package/dist/lib/seed-options.js +68 -0
  223. package/dist/lib/seed-profiles.js +59 -0
  224. package/dist/lib/targz.js +1383 -0
  225. package/dist/lib/teammode.js +25 -0
  226. package/dist/lib/tempdir.js +162 -0
  227. package/dist/lib/unicode-tables.js +2335 -0
  228. package/dist/lib/version-spec.js +357 -0
  229. package/dist/lib/versions.js +463 -0
  230. package/dist/lib/yaml-dump.js +1361 -0
  231. package/dist/perf/baseline.js +168 -0
  232. package/dist/perf/constrain.js +299 -0
  233. package/dist/perf/k6.js +235 -0
  234. package/dist/perf/mongoprof.js +171 -0
  235. package/dist/perf/rcmetrics.js +191 -0
  236. package/dist/perf/report.js +386 -0
  237. package/dist/perf/resources.js +236 -0
  238. package/dist/perf/slo.js +111 -0
  239. package/dist/perf/timeline.js +187 -0
  240. package/dist/perf/timings.js +85 -0
  241. package/dist/perf/verdict.js +201 -0
  242. package/dist/seams/aws-cli.js +126 -0
  243. package/dist/seams/docker-cli.js +280 -0
  244. package/dist/seams/exec.js +861 -0
  245. package/dist/seams/fs/lock.js +528 -0
  246. package/dist/seams/kubectl.js +83 -0
  247. package/dist/seams/rc-http.js +921 -0
  248. package/dist/seed/apply.js +190 -0
  249. package/dist/seed/assets.js +76 -0
  250. package/dist/seed/check.js +391 -0
  251. package/dist/seed/client.js +172 -0
  252. package/dist/seed/executor.js +726 -0
  253. package/dist/seed/history.js +281 -0
  254. package/dist/seed/kinds.js +91 -0
  255. package/dist/seed/plan.js +432 -0
  256. package/dist/seed/receipt.js +339 -0
  257. package/dist/seed/repairs.js +75 -0
  258. package/dist/seed/verification.js +363 -0
  259. package/dist/seed/wording.js +248 -0
  260. package/dist/web/app.js +326 -0
  261. package/dist/web/jobs.js +510 -0
  262. package/dist/web/route-deps.js +211 -0
  263. package/dist/web/route-table.js +213 -0
  264. package/dist/web/routes/backup.js +244 -0
  265. package/dist/web/routes/clusters.js +303 -0
  266. package/dist/web/routes/data.js +187 -0
  267. package/dist/web/routes/edge.js +82 -0
  268. package/dist/web/routes/index.js +63 -0
  269. package/dist/web/routes/jobs.js +95 -0
  270. package/dist/web/routes/logs.js +297 -0
  271. package/dist/web/routes/meta.js +191 -0
  272. package/dist/web/routes/people.js +151 -0
  273. package/dist/web/routes/perf.js +95 -0
  274. package/dist/web/routes/repros.js +550 -0
  275. package/dist/web/routes/session.js +361 -0
  276. package/dist/web/routes/spa.js +198 -0
  277. package/dist/web/security.js +475 -0
  278. package/dist/web/signin.js +246 -0
  279. package/package.json +70 -32
  280. package/.eslintrc +0 -94
  281. package/.swcrc +0 -18
  282. package/dist/bin.js +0 -3
  283. package/dist/cli.js +0 -184
  284. package/dist/commands/createBranch.js +0 -194
  285. package/dist/outputCI.js +0 -59
  286. package/src/bin.js +0 -4
  287. package/src/cli.ts +0 -25
  288. package/src/commands/createBranch.ts +0 -28
  289. package/src/outputCI.ts +0 -12
  290. package/src-old/logs.js +0 -323
  291. package/src-old/md.js +0 -191
  292. package/src-old/release-table.js +0 -60
  293. package/src-old/set-version.js +0 -614
  294. package/src-old/utils.js +0 -15
@@ -0,0 +1,276 @@
1
+ import { ctx } from "./shared.js";
2
+
3
+ // ---- load-test diagnosis rendering -----------------------------------------
4
+ function resultTable(headers, rows) {
5
+ const t = ctx.el("table", { class: "dtable" }, ctx.el("tr", {}, ...headers.map((h) => ctx.el("th", {}, h))));
6
+ for (const row of rows) {
7
+ t.append(ctx.el("tr", {}, ...row.map((cell, i) =>
8
+ ctx.el("td", i ? { class: "v" } : {}, String(cell)))));
9
+ }
10
+ return t;
11
+ }
12
+ const ms = (v) => (v == null ? "-" : `${Math.round(v)}ms`);
13
+
14
+ // p95 per bucket as a sparkline, with error buckets marked. timeline.render_ascii
15
+ // is terminal art; this reuses the SVG approach from the live stats chart.
16
+ function timelineSvg(tl) {
17
+ const b = tl.buckets || [];
18
+ if (b.length < 2) return null;
19
+ const W = 560, H = 74, pad = 4;
20
+ const max = Math.max(...b.map((x) => x.p95), 1);
21
+ const x = (i) => pad + (i / (b.length - 1)) * (W - 2 * pad);
22
+ const y = (v) => H - 18 - (v / max) * (H - 26);
23
+ const line = b.map((x_, i) => `${x(i).toFixed(1)},${y(x_.p95).toFixed(1)}`).join(" ");
24
+ const marks = b.map((x_, i) => x_.errors
25
+ ? `<rect x="${(x(i) - 1.5).toFixed(1)}" y="${H - 14}" width="3" height="8" fill="var(--red)"/>` : "").join("");
26
+ const wrap = ctx.el("div", { class: "spark" });
27
+ wrap.innerHTML =
28
+ `<svg viewBox="0 0 ${W} ${H}" width="100%" style="height:auto;display:block" font-size="9">` +
29
+ `<polyline points="${line}" fill="none" stroke="var(--blue)" stroke-width="1.6"/>${marks}` +
30
+ `<text x="${pad}" y="${H - 3}" fill="var(--muted)">0s</text>` +
31
+ `<text x="${W - pad}" y="${H - 3}" fill="var(--muted)" text-anchor="end">${Math.round(tl.span_s || 0)}s</text>` +
32
+ `<text x="${pad}" y="9" fill="var(--muted)">peak p95 ${Math.round(max)}ms</text></svg>`;
33
+ return wrap;
34
+ }
35
+
36
+ function renderDiagnosis(pre, r) {
37
+ const s = r.summary || {}, d = r.diag || {};
38
+ const section = (label, node) => {
39
+ if (!node) return;
40
+ pre.append(ctx.el("div", { class: "section-label" }, label));
41
+ pre.append(node);
42
+ };
43
+
44
+ if (r.slo && r.slo.length) {
45
+ section("SLO rules", resultTable(["rule", "threshold", "actual", ""], r.slo.map((x) => [
46
+ x.key, `${x.op} ${x.raw}`,
47
+ x.measured === false ? "not measured" : (x.key === "error" ? `${x.actual.toFixed(2)}%`
48
+ : x.key === "rps" ? x.actual.toFixed(1) : ms(x.actual)),
49
+ x.ok ? "PASS" : "FAIL"])));
50
+ }
51
+ // Per-step latency is the single most useful table for a journey run: it names
52
+ // the slow step instead of leaving you with one aggregate p95.
53
+ const steps = s.steps || {};
54
+ const order = ["login", "rooms", "open", "post", "sync", "read"];
55
+ const names = Object.keys(steps).sort((a, b) => {
56
+ const ia = order.indexOf(a), ib = order.indexOf(b);
57
+ return (ia < 0 ? 99 : ia) - (ib < 0 ? 99 : ib) || a.localeCompare(b);
58
+ });
59
+ if (names.length) {
60
+ section("Per-step latency", resultTable(["step", "count", "p50", "p95", "p99"],
61
+ names.map((n) => [n, Math.round(steps[n].count || 0), ms(steps[n].p50), ms(steps[n].p95), ms(steps[n].p99)])));
62
+ }
63
+ const st = s.status || {};
64
+ const codes = ["2xx", "429", "4xx", "5xx", "other"].filter((k) => st[k]);
65
+ if (codes.length) {
66
+ section("Responses", resultTable(["class", "count"], codes.map((k) => [k, Math.round(st[k])])));
67
+ }
68
+ if (d.rcmetrics && Object.keys(d.rcmetrics).length) {
69
+ section("RC internals", resultTable(["instance", "event-loop lag peak", "lag p99", "heap peak", "ddp users"],
70
+ Object.keys(d.rcmetrics).sort().map((svc) => {
71
+ const m = d.rcmetrics[svc];
72
+ const peak = m.eventloop_lag_max_s || m.eventloop_lag_s, p99 = m.eventloop_lag_p99_s;
73
+ return [svc, peak ? ms(peak.max * 1000) : "-", p99 ? ms(p99.max * 1000) : "-",
74
+ m.heap_used_bytes ? `${Math.round(m.heap_used_bytes.max / 1e6)}MB` : "-",
75
+ m.ddp_users ? Math.round(m.ddp_users.max) : "-"];
76
+ })));
77
+ }
78
+ const mg = d.mongo;
79
+ if (mg && (mg.total || (mg.slow || []).length)) {
80
+ section(`Slow MongoDB queries (${mg.total} profiled, ${mg.collscan} COLLSCAN)`,
81
+ resultTable(["time", "namespace", "op", "plan", "docs", "returned"],
82
+ (mg.slow || []).map((q) => [ms(q.millis), q.ns, q.op, q.plan || "?", q.docs, q.ret])));
83
+ }
84
+ if (d.timeline) {
85
+ const spark = timelineSvg(d.timeline);
86
+ if (spark) {
87
+ section(`Latency over time (${d.timeline.buckets.length} buckets of ${d.timeline.width_s}s)`, spark);
88
+ if (d.timeline.first_error_s != null) {
89
+ pre.append(ctx.el("div", { class: "inline-note" }, `errors began ~${d.timeline.first_error_s}s in`));
90
+ }
91
+ }
92
+ }
93
+ if (r.resources && Object.keys(r.resources).length) {
94
+ section("Resource cost", resultTable(["container", "idle CPU", "peak CPU", "peak RAM"],
95
+ Object.keys(r.resources).sort().map((c) => {
96
+ const x = r.resources[c];
97
+ return [c, `${Math.round(x.idle_cpu)}%`, `${Math.round(x.peak_cpu)}%`,
98
+ `${Math.round(x.peak_mem / 1e6)}MB`];
99
+ })));
100
+ }
101
+ pre.scrollTop = pre.scrollHeight;
102
+ }
103
+
104
+ // ---- capacity dialog --------------------------------------------------------
105
+ let CAP_TARGET = null;
106
+ function openCap(name) { CAP_TARGET = name; ctx.$("#cap-title").textContent = `Capacity search: ${name}`; ctx.$("#cap-dialog").showModal(); }
107
+ async function submitCap() {
108
+ const f = ctx.$("#cap-form");
109
+ const req = {
110
+ scenario: f.scenario.value, slo: f.slo.value.trim(),
111
+ start: parseInt(f.start.value, 10) || 10, max_vus: parseInt(f.max_vus.value, 10) || 640,
112
+ step_duration: f.step_duration.value.trim() || "20s", users_n: parseInt(f.users_n.value, 10) || 0,
113
+ constrain: f.constrain.value.trim(),
114
+ };
115
+ ctx.$("#cap-dialog").close();
116
+ try { const { job_id } = await ctx.api(`/api/repros/${CAP_TARGET}/capacity`, { method: "POST", body: JSON.stringify(req) });
117
+ ctx.streamJob(job_id, `Capacity: ${CAP_TARGET}`, renderCapResult); }
118
+ catch (e) { ctx.toast(e.message); }
119
+ }
120
+ function renderCapResult(r) {
121
+ const pre = ctx.$("#job-log");
122
+ const box = ctx.el("div", { class: "result" });
123
+ box.innerHTML = `<hr><b>Capacity: ${ctx.escapeHtml(r.result)}</b>` + (r.why ? `<br><span class="warn">${ctx.escapeHtml(r.why)}</span>` : "");
124
+ const t = ctx.el("table", { class: "dtable" }, ctx.el("tr", {}, ctx.el("th", {}, "VUs"), ctx.el("th", {}, "req/s"), ctx.el("th", {}, "p95"), ctx.el("th", {}, "err"), ctx.el("th", {}, "lag peak"), ctx.el("th", {}, "result")));
125
+ for (const s of (r.steps || [])) t.append(ctx.el("tr", {},
126
+ ctx.el("td", {}, s.vus), ctx.el("td", { class: "v" }, (s.rps || 0).toFixed(1)),
127
+ ctx.el("td", { class: "v" }, (s.p95 || 0).toFixed(0) + "ms"), ctx.el("td", { class: "v" }, ((s.error_rate || 0) * 100).toFixed(2) + "%"),
128
+ ctx.el("td", { class: "v" }, s.lag_max_s ? `${Math.round(s.lag_max_s * 1000)}ms` : "-"),
129
+ ctx.el("td", { class: s.ok ? "" : "v" }, s.ok ? "PASS" : "FAIL")));
130
+ pre.append(box, t); pre.scrollTop = pre.scrollHeight;
131
+ }
132
+
133
+ function doDefault(name) {
134
+ return ctx.runAction(name, "Make default", async () => {
135
+ await ctx.api(`/api/repros/${name}/default`, { method: "POST" });
136
+ ctx.toast(`${name} is now the default workspace for CLI commands`, "ok");
137
+ });
138
+ }
139
+ let PAT_HEADERS = "";
140
+ // Through runAction, not a bare fetch: this is a login plus a 2FA-guarded POST
141
+ // against a workspace that may still be booting, so it can sit there for tens of
142
+ // seconds. Silent, it looked like a dead button -- and the second click would
143
+ // *regenerate* the token, invalidating the one the first click was about to show.
144
+ function doPat(name) {
145
+ return ctx.runAction(name, "API token", async () => {
146
+ const r = await ctx.api(`/api/repros/${name}/pat`, { method: "POST", body: JSON.stringify({}) });
147
+ PAT_HEADERS = `-H "X-Auth-Token: ${r.token}" -H "X-User-Id: ${r.user_id}"`;
148
+ ctx.$("#pat-title").textContent = `PAT and Token: ${name}`;
149
+ ctx.$("#pat-body").textContent =
150
+ `# ${r.root_url} (label: ${r.label}, bypass_2fa: ${r.bypass_2fa})\n`
151
+ + `X-Auth-Token: ${r.token}\nX-User-Id: ${r.user_id}\n\n`
152
+ + `curl ${PAT_HEADERS} ${r.root_url}/api/v1/me\n`;
153
+ ctx.$("#pat-dialog").showModal();
154
+ });
155
+ }
156
+
157
+ // ---- API call console -------------------------------------------------------
158
+ // `houston api` in the GUI: pick a method and path, get the status and body
159
+ // back in place. Not routed through runAction like the buttons above -- this
160
+ // dialog is meant to be used repeatedly, so it disables its own Send button for
161
+ // the duration instead of freezing every other action on the repro.
162
+ let CALL_TARGET = null;
163
+ let CALL_TEXT = "";
164
+ // Rocket.Chat answers with JSON on one unbroken line -- a users.list is a single
165
+ // wrapped blob you cannot read. Indent it. Two things it must not do: choke on a
166
+ // body that isn't JSON (a proxy's HTML error page, a bare 204), and freeze the
167
+ // tab re-serialising a huge one, so both fall through to the raw text with the
168
+ // reason shown next to the status.
169
+ const PRETTY_MAX = 512 * 1024;
170
+ function prettyJson(text) {
171
+ if (text.length > PRETTY_MAX) return { text, note: "too large to indent" };
172
+ try { return { text: JSON.stringify(JSON.parse(text), null, 2), note: "" }; }
173
+ catch (_) { return { text, note: "not JSON — shown raw" }; }
174
+ }
175
+ function openCall(name) {
176
+ CALL_TARGET = name;
177
+ CALL_TEXT = "";
178
+ ctx.$("#call-title").textContent = `API call: ${name}`;
179
+ const out = ctx.$("#call-out");
180
+ out.textContent = "";
181
+ out.hidden = true; // no stale response from the last repro
182
+ ctx.$("#call-dialog").showModal();
183
+ }
184
+ async function submitCall() {
185
+ // Through .elements, not `f.method` -- `method` is a real HTMLFormElement
186
+ // property (the form's own HTTP method). A control named `method` only shadows
187
+ // it by the legacy override rule, so `f.method` would quietly become the string
188
+ // "get" the day this field is renamed. .elements has no such collision.
189
+ const f = ctx.$("#call-form").elements;
190
+ const req = {
191
+ method: f.method.value, path: f.path.value.trim(), data: f.data.value.trim(),
192
+ pat: f.pat.checked, two_fa: f.two_fa.checked,
193
+ };
194
+ if (!req.path) { ctx.toast("enter an API path, e.g. /api/v1/me"); return; }
195
+ const btn = ctx.$("#call-send");
196
+ const out = ctx.$("#call-out");
197
+ btn.disabled = true; btn.textContent = "Sending…";
198
+ out.hidden = false;
199
+ out.textContent = `${req.method} ${req.path} …`;
200
+ try {
201
+ const r = await ctx.api(`/api/repros/${CALL_TARGET}/call`, { method: "POST", body: JSON.stringify(req) });
202
+ // A 4xx/5xx from Rocket.Chat arrives here as a successful call with a
203
+ // failing status -- colour it red, but show it as a response, not an error.
204
+ const shown = r.text ? prettyJson(r.text) : { text: "", note: "empty body" };
205
+ CALL_TEXT = shown.text; // copy what is on screen, indentation and all
206
+ out.textContent = "";
207
+ out.append(
208
+ ctx.el("span", { class: r.status < 400 ? "done" : "error" },
209
+ `${req.method} ${r.url}\nHTTP ${r.status} [${r.tag}] in ${r.elapsed_ms}ms`
210
+ + (shown.note ? ` · ${shown.note}` : "") + "\n\n"),
211
+ shown.text);
212
+ } catch (e) {
213
+ CALL_TEXT = e.message;
214
+ out.textContent = "";
215
+ out.append(ctx.el("span", { class: "error" }, e.message));
216
+ } finally {
217
+ btn.disabled = false; btn.textContent = "Send";
218
+ out.scrollTop = 0;
219
+ }
220
+ }
221
+
222
+ // ---- doctor -----------------------------------------------------------------
223
+ // The badge could only say docker up/down. When it said down, every card showed
224
+ // "docker unavailable — actions disabled" and nothing said WHY or what to do,
225
+ // while `houston doctor` had known the answer all along.
226
+ const DOCTOR_MARK = { ok: "✓", warn: "⚠", fail: "✗" };
227
+ const DOCTOR_VERDICT = {
228
+ ok: ["ok", "All good — houston is ready."],
229
+ warn: ["warn", "Usable, with warnings above."],
230
+ fail: ["bad", "Not ready — fix the ✗ item(s) above."],
231
+ };
232
+ async function openDoctor() {
233
+ const body = ctx.$("#doctor-body");
234
+ body.innerHTML = "";
235
+ body.append(ctx.el("div", { class: "kv" }, "Checking…"));
236
+ if (!ctx.$("#doctor-dialog").open) ctx.$("#doctor-dialog").showModal();
237
+ let rep;
238
+ try { rep = await ctx.api("/api/doctor"); }
239
+ catch (e) { body.innerHTML = ""; body.append(ctx.el("p", { class: "banner bad" }, e.message)); return; }
240
+ body.innerHTML = "";
241
+ for (const c of rep.checks || []) {
242
+ body.append(ctx.el("div", { class: "dcheck " + c.status },
243
+ ctx.el("span", { class: "dmark" }, DOCTOR_MARK[c.status] || "·"),
244
+ ctx.el("span", {}, c.message)));
245
+ }
246
+ // No repro tally. `houston doctor` prints one because a terminal has nowhere
247
+ // else to say it; here the rail lists every workspace by name and the status bar
248
+ // counts them, both of them permanently and both of them behind this dialog.
249
+ const [cls, text] = DOCTOR_VERDICT[rep.verdict] || DOCTOR_VERDICT.warn;
250
+ body.append(ctx.el("p", { class: "banner " + cls }, text));
251
+ }
252
+
253
+
254
+ Object.defineProperties(ctx, {
255
+ "resultTable": { enumerable: true, get: () => resultTable },
256
+ "ms": { enumerable: true, get: () => ms },
257
+ "timelineSvg": { enumerable: true, get: () => timelineSvg },
258
+ "renderDiagnosis": { enumerable: true, get: () => renderDiagnosis },
259
+ "CAP_TARGET": { enumerable: true, get: () => CAP_TARGET, set: value => { CAP_TARGET = value; } },
260
+ "openCap": { enumerable: true, get: () => openCap },
261
+ "submitCap": { enumerable: true, get: () => submitCap },
262
+ "renderCapResult": { enumerable: true, get: () => renderCapResult },
263
+ "doDefault": { enumerable: true, get: () => doDefault },
264
+ "PAT_HEADERS": { enumerable: true, get: () => PAT_HEADERS, set: value => { PAT_HEADERS = value; } },
265
+ "doPat": { enumerable: true, get: () => doPat },
266
+ "CALL_TARGET": { enumerable: true, get: () => CALL_TARGET, set: value => { CALL_TARGET = value; } },
267
+ "CALL_TEXT": { enumerable: true, get: () => CALL_TEXT, set: value => { CALL_TEXT = value; } },
268
+ "PRETTY_MAX": { enumerable: true, get: () => PRETTY_MAX },
269
+ "prettyJson": { enumerable: true, get: () => prettyJson },
270
+ "openCall": { enumerable: true, get: () => openCall },
271
+ "submitCall": { enumerable: true, get: () => submitCall },
272
+ "DOCTOR_MARK": { enumerable: true, get: () => DOCTOR_MARK },
273
+ "DOCTOR_VERDICT": { enumerable: true, get: () => DOCTOR_VERDICT },
274
+ "openDoctor": { enumerable: true, get: () => openDoctor },
275
+ });
276
+ export { resultTable, ms, timelineSvg, renderDiagnosis, CAP_TARGET, openCap, submitCap, renderCapResult, doDefault, PAT_HEADERS, doPat, CALL_TARGET, CALL_TEXT, PRETTY_MAX, prettyJson, openCall, submitCall, DOCTOR_MARK, DOCTOR_VERDICT, openDoctor };