@rocket.chat/houston 0.27.0-next.2 → 2.1.8

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 (291) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +108 -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 +669 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/troubleshooting.md +193 -0
  12. package/data/docs/upgrading.md +84 -0
  13. package/data/docs/voice.md +253 -0
  14. package/data/iam/engineer-policy.json +11 -0
  15. package/data/iam/engineer-rbac.yaml +42 -0
  16. package/data/iam/operator-policy.json +211 -0
  17. package/data/loadtest/badbot.js +22 -0
  18. package/data/loadtest/common.js +168 -0
  19. package/data/loadtest/custom.js +20 -0
  20. package/data/loadtest/journey.js +58 -0
  21. package/data/loadtest/login.js +18 -0
  22. package/data/loadtest/messages.js +13 -0
  23. package/data/loadtest/mixed.js +39 -0
  24. package/data/loadtest/read.js +12 -0
  25. package/data/loadtest/webhook.js +20 -0
  26. package/data/monitoring/houston-logs.json +98 -0
  27. package/data/monitoring/k6-loadtest.json +610 -0
  28. package/data/monitoring/mongodb-exporter.json +3007 -0
  29. package/data/monitoring/node-exporter-full.json +16114 -0
  30. package/data/monitoring/rocketchat-metrics.json +6471 -0
  31. package/data/presets/airgapped.yaml +16 -0
  32. package/data/presets/default.yaml +9 -0
  33. package/data/seed/avatar-0.png +0 -0
  34. package/data/seed/avatar-1.png +0 -0
  35. package/data/seed/avatar-2.png +0 -0
  36. package/data/seed/avatar-3.png +0 -0
  37. package/data/seed/avatar-4.png +0 -0
  38. package/data/seed/avatar-5.png +0 -0
  39. package/data/seed/avatar-6.png +0 -0
  40. package/data/seed/avatar-7.png +0 -0
  41. package/data/seed/seed-metrics.csv +3 -0
  42. package/data/seed/seed-preview.png +0 -0
  43. package/data/seed/seed-report.pdf +32 -0
  44. package/data/seed/seed-runbook.txt +3 -0
  45. package/data/skill/SKILL.md +399 -0
  46. package/data/versions.yaml +55 -0
  47. package/data/voice/freeswitch/drachtio.xml +52 -0
  48. package/data/voice/freeswitch/public.xml +87 -0
  49. package/data/webui/app.css +2003 -0
  50. package/data/webui/index.html +678 -0
  51. package/data/webui/js/api.js +561 -0
  52. package/data/webui/js/boot.js +44 -0
  53. package/data/webui/js/clusters-tail.js +1377 -0
  54. package/data/webui/js/clusters.js +896 -0
  55. package/data/webui/js/create.js +276 -0
  56. package/data/webui/js/detail.js +507 -0
  57. package/data/webui/js/jobs.js +636 -0
  58. package/data/webui/js/logs.js +634 -0
  59. package/data/webui/js/main.js +14 -0
  60. package/data/webui/js/options.js +408 -0
  61. package/data/webui/js/people.js +438 -0
  62. package/data/webui/js/perf.js +303 -0
  63. package/data/webui/js/render.js +438 -0
  64. package/data/webui/js/shared.js +3 -0
  65. package/data/webui/js/state.js +583 -0
  66. package/data/webui/js/theme.js +123 -0
  67. package/data/webui/js/util.js +584 -0
  68. package/dist/cli/app.js +593 -0
  69. package/dist/cli/capabilities.js +76 -0
  70. package/dist/cli/cell-widths.js +495 -0
  71. package/dist/cli/entry.js +10 -0
  72. package/dist/cli/error-panel.js +492 -0
  73. package/dist/cli/handlers/actor.js +84 -0
  74. package/dist/cli/handlers/https.js +614 -0
  75. package/dist/cli/handlers/prompt.js +299 -0
  76. package/dist/cli/handlers/users.js +226 -0
  77. package/dist/cli/handlers.js +3678 -0
  78. package/dist/cli/help.js +183 -0
  79. package/dist/cli/index.js +15 -0
  80. package/dist/cli/perf.js +810 -0
  81. package/dist/cli/render.js +254 -0
  82. package/dist/cli/serve.js +858 -0
  83. package/dist/cli/spec-data.js +2593 -0
  84. package/dist/cli/spec-types.js +8 -0
  85. package/dist/cli/usage-error.js +520 -0
  86. package/dist/cli/wire.js +70 -0
  87. package/dist/core/audit.js +346 -0
  88. package/dist/core/backup-compat.js +85 -0
  89. package/dist/core/backup.js +1639 -0
  90. package/dist/core/cluster.js +1398 -0
  91. package/dist/core/configimport.js +344 -0
  92. package/dist/core/data.js +267 -0
  93. package/dist/core/database-of.js +82 -0
  94. package/dist/core/diagnose.js +159 -0
  95. package/dist/core/doctor.js +1518 -0
  96. package/dist/core/edge/acme.js +338 -0
  97. package/dist/core/edge/engine.js +500 -0
  98. package/dist/core/edge/networks.js +174 -0
  99. package/dist/core/edge/paths.js +107 -0
  100. package/dist/core/edge/routes.js +251 -0
  101. package/dist/core/edge/routeyml.js +195 -0
  102. package/dist/core/edge/runtime.js +493 -0
  103. package/dist/core/edge/spec.js +305 -0
  104. package/dist/core/edge/types.js +202 -0
  105. package/dist/core/eks-docs.js +135 -0
  106. package/dist/core/eks.js +2240 -0
  107. package/dist/core/envvars.js +562 -0
  108. package/dist/core/eventlog.js +541 -0
  109. package/dist/core/firstrun.js +153 -0
  110. package/dist/core/journal.js +691 -0
  111. package/dist/core/kube/ask.js +231 -0
  112. package/dist/core/kube/capabilities.js +269 -0
  113. package/dist/core/kube/certmanager.js +452 -0
  114. package/dist/core/kube/chart.js +413 -0
  115. package/dist/core/kube/cluster.js +196 -0
  116. package/dist/core/kube/context.js +545 -0
  117. package/dist/core/kube/endpoints.js +448 -0
  118. package/dist/core/kube/exec.js +195 -0
  119. package/dist/core/kube/forward.js +732 -0
  120. package/dist/core/kube/grafana-ingress.js +110 -0
  121. package/dist/core/kube/ingress.js +218 -0
  122. package/dist/core/kube/manifests.js +361 -0
  123. package/dist/core/kube/monitoring.js +768 -0
  124. package/dist/core/kube/names.js +237 -0
  125. package/dist/core/kube/namespace.js +678 -0
  126. package/dist/core/kube/operator.js +941 -0
  127. package/dist/core/kube/probe.js +202 -0
  128. package/dist/core/kube/reachability.js +163 -0
  129. package/dist/core/kube/release.js +439 -0
  130. package/dist/core/kube/replicaset.js +180 -0
  131. package/dist/core/kube/scale.js +398 -0
  132. package/dist/core/kube/status.js +633 -0
  133. package/dist/core/kube/tools.js +238 -0
  134. package/dist/core/kube/transfer.js +173 -0
  135. package/dist/core/kube/workspace.js +423 -0
  136. package/dist/core/lifecycle/admin.js +64 -0
  137. package/dist/core/lifecycle/create-docker.js +1533 -0
  138. package/dist/core/lifecycle/create-k8s.js +939 -0
  139. package/dist/core/lifecycle/destroy.js +339 -0
  140. package/dist/core/lifecycle/inspect.js +635 -0
  141. package/dist/core/lifecycle/naming.js +298 -0
  142. package/dist/core/lifecycle/notes.js +726 -0
  143. package/dist/core/lifecycle/ownership.js +313 -0
  144. package/dist/core/lifecycle/payload.js +401 -0
  145. package/dist/core/lifecycle/ports.js +388 -0
  146. package/dist/core/lifecycle/preconditions.js +367 -0
  147. package/dist/core/lifecycle/pruning.js +551 -0
  148. package/dist/core/lifecycle/ready.js +753 -0
  149. package/dist/core/lifecycle/request.js +525 -0
  150. package/dist/core/lifecycle/seeding.js +281 -0
  151. package/dist/core/lifecycle/sizing.js +392 -0
  152. package/dist/core/lifecycle/state.js +286 -0
  153. package/dist/core/lifecycle/tlsplan.js +704 -0
  154. package/dist/core/lifecycle/types.js +232 -0
  155. package/dist/core/loadtest.js +995 -0
  156. package/dist/core/migrate.js +612 -0
  157. package/dist/core/monitor.js +494 -0
  158. package/dist/core/postready.js +969 -0
  159. package/dist/core/promote.js +804 -0
  160. package/dist/core/rcapi.js +1285 -0
  161. package/dist/core/recovery.js +75 -0
  162. package/dist/core/runner/engine.js +394 -0
  163. package/dist/core/runner/host.js +298 -0
  164. package/dist/core/runner/locks.js +129 -0
  165. package/dist/core/runner/paths.js +173 -0
  166. package/dist/core/runner/ports.js +172 -0
  167. package/dist/core/runner/queries.js +612 -0
  168. package/dist/core/runner/record.js +563 -0
  169. package/dist/core/scaleseed.js +271 -0
  170. package/dist/core/seed-db.js +208 -0
  171. package/dist/core/sessions.js +472 -0
  172. package/dist/core/skill.js +326 -0
  173. package/dist/core/sso-identities.js +172 -0
  174. package/dist/core/sso.js +703 -0
  175. package/dist/core/tls-local.js +311 -0
  176. package/dist/core/tls.js +878 -0
  177. package/dist/core/topology.js +482 -0
  178. package/dist/core/upgrade.js +868 -0
  179. package/dist/core/users.js +739 -0
  180. package/dist/lib/audit.js +100 -0
  181. package/dist/lib/close-matches.js +238 -0
  182. package/dist/lib/compose.js +672 -0
  183. package/dist/lib/config.js +1398 -0
  184. package/dist/lib/context.js +18 -0
  185. package/dist/lib/errors.js +305 -0
  186. package/dist/lib/events.js +208 -0
  187. package/dist/lib/float-text.js +126 -0
  188. package/dist/lib/format.js +1320 -0
  189. package/dist/lib/home.js +325 -0
  190. package/dist/lib/journal.js +122 -0
  191. package/dist/lib/json-text.js +733 -0
  192. package/dist/lib/jsonout.js +382 -0
  193. package/dist/lib/lock.js +516 -0
  194. package/dist/lib/login-name.js +202 -0
  195. package/dist/lib/map-limit.js +29 -0
  196. package/dist/lib/mkdir-parents.js +90 -0
  197. package/dist/lib/mongo-kernel.js +67 -0
  198. package/dist/lib/monitoring.js +492 -0
  199. package/dist/lib/platform-name.js +59 -0
  200. package/dist/lib/presets/common.js +390 -0
  201. package/dist/lib/presets/composite.js +326 -0
  202. package/dist/lib/presets/e2ee.js +143 -0
  203. package/dist/lib/presets/email.js +172 -0
  204. package/dist/lib/presets/guides.js +27 -0
  205. package/dist/lib/presets/index.js +490 -0
  206. package/dist/lib/presets/keycloak.js +369 -0
  207. package/dist/lib/presets/ldap.js +1285 -0
  208. package/dist/lib/presets/livechat.js +220 -0
  209. package/dist/lib/presets/multi-instance.js +124 -0
  210. package/dist/lib/presets/oidc.js +161 -0
  211. package/dist/lib/presets/public.js +496 -0
  212. package/dist/lib/presets/registry.js +64 -0
  213. package/dist/lib/presets/s3-minio.js +300 -0
  214. package/dist/lib/presets/saml.js +149 -0
  215. package/dist/lib/presets/scenario.js +51 -0
  216. package/dist/lib/presets/types.js +86 -0
  217. package/dist/lib/presets/voice-pbx.js +320 -0
  218. package/dist/lib/presets/voice.js +345 -0
  219. package/dist/lib/presets/webhooks.js +182 -0
  220. package/dist/lib/redact.js +106 -0
  221. package/dist/lib/seed-options.js +68 -0
  222. package/dist/lib/seed-profiles.js +59 -0
  223. package/dist/lib/targz.js +1383 -0
  224. package/dist/lib/teammode.js +25 -0
  225. package/dist/lib/tempdir.js +162 -0
  226. package/dist/lib/unicode-tables.js +2335 -0
  227. package/dist/lib/version-spec.js +357 -0
  228. package/dist/lib/versions.js +463 -0
  229. package/dist/lib/yaml-dump.js +1361 -0
  230. package/dist/perf/baseline.js +168 -0
  231. package/dist/perf/constrain.js +296 -0
  232. package/dist/perf/k6.js +235 -0
  233. package/dist/perf/mongoprof.js +171 -0
  234. package/dist/perf/rcmetrics.js +178 -0
  235. package/dist/perf/report.js +386 -0
  236. package/dist/perf/resources.js +224 -0
  237. package/dist/perf/slo.js +111 -0
  238. package/dist/perf/timeline.js +187 -0
  239. package/dist/perf/timings.js +85 -0
  240. package/dist/perf/verdict.js +201 -0
  241. package/dist/seams/aws-cli.js +126 -0
  242. package/dist/seams/docker-cli.js +280 -0
  243. package/dist/seams/exec.js +861 -0
  244. package/dist/seams/fs/lock.js +528 -0
  245. package/dist/seams/kubectl.js +83 -0
  246. package/dist/seams/rc-http.js +921 -0
  247. package/dist/seed/apply.js +190 -0
  248. package/dist/seed/assets.js +76 -0
  249. package/dist/seed/check.js +391 -0
  250. package/dist/seed/client.js +172 -0
  251. package/dist/seed/executor.js +726 -0
  252. package/dist/seed/history.js +281 -0
  253. package/dist/seed/kinds.js +91 -0
  254. package/dist/seed/plan.js +432 -0
  255. package/dist/seed/receipt.js +339 -0
  256. package/dist/seed/repairs.js +75 -0
  257. package/dist/seed/verification.js +363 -0
  258. package/dist/seed/wording.js +248 -0
  259. package/dist/web/app.js +326 -0
  260. package/dist/web/jobs.js +510 -0
  261. package/dist/web/route-deps.js +211 -0
  262. package/dist/web/route-table.js +213 -0
  263. package/dist/web/routes/backup.js +244 -0
  264. package/dist/web/routes/clusters.js +303 -0
  265. package/dist/web/routes/data.js +187 -0
  266. package/dist/web/routes/edge.js +82 -0
  267. package/dist/web/routes/index.js +63 -0
  268. package/dist/web/routes/jobs.js +95 -0
  269. package/dist/web/routes/logs.js +297 -0
  270. package/dist/web/routes/meta.js +191 -0
  271. package/dist/web/routes/people.js +151 -0
  272. package/dist/web/routes/perf.js +95 -0
  273. package/dist/web/routes/repros.js +550 -0
  274. package/dist/web/routes/session.js +361 -0
  275. package/dist/web/routes/spa.js +198 -0
  276. package/dist/web/security.js +475 -0
  277. package/dist/web/signin.js +246 -0
  278. package/package.json +67 -32
  279. package/.eslintrc +0 -94
  280. package/.swcrc +0 -18
  281. package/dist/bin.js +0 -3
  282. package/dist/cli.js +0 -184
  283. package/dist/commands/createBranch.js +0 -192
  284. package/src/bin.js +0 -4
  285. package/src/cli.ts +0 -25
  286. package/src/commands/createBranch.ts +0 -25
  287. package/src-old/logs.js +0 -323
  288. package/src-old/md.js +0 -191
  289. package/src-old/release-table.js +0 -60
  290. package/src-old/set-version.js +0 -614
  291. package/src-old/utils.js +0 -15
@@ -0,0 +1,612 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.runningWriterServices = runningWriterServices;
37
+ exports.removeVolumes = removeVolumes;
38
+ exports.dockerStats = dockerStats;
39
+ exports.rcState = rcState;
40
+ exports.composeLs = composeLs;
41
+ exports.projectStates = projectStates;
42
+ exports.projectConfigFiles = projectConfigFiles;
43
+ exports.projectDataVolumes = projectDataVolumes;
44
+ exports.rcContainerEnv = rcContainerEnv;
45
+ exports.networklessContainers = networklessContainers;
46
+ exports.startErrors = startErrors;
47
+ exports.oneShotSetups = oneShotSetups;
48
+ exports.rcRestartCount = rcRestartCount;
49
+ exports.servicesByProject = servicesByProject;
50
+ exports.servicesByProjectUncached = servicesByProjectUncached;
51
+ exports.rcStatusByProject = rcStatusByProject;
52
+ exports.containerDetails = containerDetails;
53
+ /**
54
+ * Read-only questions about what Docker is actually running.
55
+ *
56
+ * Two contracts recur and they are not the same: a function that returns `null` distinguishes
57
+ * "could not ask Docker" from "the answer is empty", and one that returns `{}` or `''` has
58
+ * decided those are the same. Which is which is load-bearing -- `prune` DELETES based on
59
+ * absence, so it must never read a failed query as "no projects".
60
+ */
61
+ const errors_1 = require("../../lib/errors");
62
+ const format_1 = require("../../lib/format");
63
+ const json_text_1 = require("../../lib/json-text");
64
+ const float_text_1 = require("../../lib/float-text");
65
+ const docker_cli_1 = require("../../seams/docker-cli");
66
+ const exec_1 = require("../../seams/exec");
67
+ const engine = __importStar(require("./engine"));
68
+ const record_1 = require("./record");
69
+ /** A strict writer query: failed or malformed discovery must never authorize a dump/drop. */
70
+ async function runningWriterServices(name, services) {
71
+ if (services.length === 0)
72
+ throw new errors_1.DockerError(`'${name}' has no Rocket.Chat services`);
73
+ const result = await engine.compose(name, ['ps', '--all', '--format', 'json', ...services], {
74
+ capture: true,
75
+ timeoutMs: 30000,
76
+ });
77
+ if (result.exitCode !== 0) {
78
+ throw new errors_1.DockerError(`could not inspect Rocket.Chat writers for '${name}': ${String(result.stderr ?? '').trim()}`);
79
+ }
80
+ const raw = String(result.stdout ?? '').trim();
81
+ let rows;
82
+ try {
83
+ let parsed;
84
+ try {
85
+ parsed = raw === '' ? [] : JSON.parse(raw);
86
+ }
87
+ catch {
88
+ parsed = raw.split('\n').map((line) => JSON.parse(line));
89
+ }
90
+ rows = Array.isArray(parsed) ? parsed : [parsed];
91
+ }
92
+ catch {
93
+ throw new errors_1.DockerError(`could not inspect Rocket.Chat writers for '${name}': invalid container list`);
94
+ }
95
+ const running = new Set();
96
+ for (const row of rows) {
97
+ if (typeof row !== 'object' || row === null || Array.isArray(row)) {
98
+ throw new errors_1.DockerError(`could not inspect Rocket.Chat writers for '${name}': invalid container row`);
99
+ }
100
+ const item = row;
101
+ if (typeof item.Service !== 'string' || typeof item.State !== 'string') {
102
+ throw new errors_1.DockerError(`could not inspect Rocket.Chat writers for '${name}': missing container state`);
103
+ }
104
+ if (!services.includes(item.Service))
105
+ continue;
106
+ if (item.State === 'running' || item.State === 'restarting')
107
+ running.add(item.Service);
108
+ else if (!['exited', 'dead', 'created'].includes(item.State)) {
109
+ throw new errors_1.DockerError(`could not inspect Rocket.Chat writers for '${name}': unsupported state '${item.State}'`);
110
+ }
111
+ }
112
+ return services.filter((service) => running.has(service));
113
+ }
114
+ /**
115
+ * Delete named volumes belonging to a repro's compose project.
116
+ *
117
+ * `docker compose down -v` only removes volumes DECLARED in the compose file, so a
118
+ * volume whose declaration is dropped (detaching monitoring, switching preset with
119
+ * --force) becomes unreachable and survives forever. Containers must be gone first.
120
+ * Returns the volume names that could not be removed.
121
+ */
122
+ async function removeVolumes(name, volumes) {
123
+ const project = await (0, record_1.projectName)(name);
124
+ const failed = [];
125
+ for (const volume of volumes) {
126
+ const full = `${project}_${volume}`;
127
+ try {
128
+ const result = await (0, docker_cli_1.docker)(['volume', 'rm', full], { capture: true, timeoutMs: 30000 });
129
+ // Already gone is success, not a failure.
130
+ if (result.exitCode !== 0 &&
131
+ !String(result.stderr ?? '')
132
+ .toLowerCase()
133
+ .includes('no such volume')) {
134
+ failed.push(full);
135
+ }
136
+ }
137
+ catch (error) {
138
+ if (error instanceof exec_1.Interrupted)
139
+ throw error; // Ctrl-C or a stopped job: unwind
140
+ failed.push(full);
141
+ }
142
+ }
143
+ return failed;
144
+ }
145
+ /**
146
+ * One `docker stats --no-stream` sample for the given containers, as tab-separated
147
+ * `name<TAB>cpu%<TAB>mem-usage` lines ('' on error or none).
148
+ *
149
+ * Timed out: this is polled once a second by a sampler, so a wedged daemon would
150
+ * otherwise block it forever.
151
+ */
152
+ async function dockerStats(containerIds) {
153
+ if (containerIds.length === 0)
154
+ return '';
155
+ try {
156
+ const result = await (0, docker_cli_1.docker)([
157
+ 'stats',
158
+ '--no-stream',
159
+ '--format',
160
+ '{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}',
161
+ ...containerIds,
162
+ ], { capture: true, timeoutMs: 30000 });
163
+ return result.exitCode === 0 ? String(result.stdout ?? '') : '';
164
+ }
165
+ catch {
166
+ return '';
167
+ }
168
+ }
169
+ /**
170
+ * Coarse state of the rocketchat service: running | exited | created | absent.
171
+ *
172
+ * One `docker compose ps` per call -- fine for a single repro. For listing many repros
173
+ * use `projectStates`, which is a single docker call for all of them.
174
+ */
175
+ async function rcState(name) {
176
+ for (const line of (await engine.ps(name)).split('\n')) {
177
+ const parts = line.split('\t');
178
+ const service = parts[0];
179
+ // "rocketchat" for a normal repro, "rocketchat-1"/"-2"/… for a multi-instance one —
180
+ // the first instance found is enough for readiness.
181
+ if (service !== undefined && (service === 'rocketchat' || service.startsWith('rocketchat-'))) {
182
+ return parts[1] ?? 'unknown';
183
+ }
184
+ }
185
+ return 'absent';
186
+ }
187
+ /**
188
+ * A compose `--format json` answer: one JSON document -- an object is one row, and anything
189
+ * else is handed back AS IT IS -- else NDJSON, one document per line. `null` when the whole
190
+ * answer is the JSON `null`: the listing then says the query failed, where wrapping it as
191
+ * `[null]` sent a null row to `item.Name` and crashed `list` (Go encodes a nil slice as
192
+ * `null`).
193
+ *
194
+ * EVERY ROW IS KEPT, whatever JSON it is, and `projectRows` reads each one as a mapping. This
195
+ * dropped the rows that were not objects, so an answer holding a stray one -- a WARN line on
196
+ * stdout, then the array, which the NDJSON reading takes as ONE row that is a list -- read as
197
+ * no projects at all: every workspace looked down, and `prune --yes` deleted one the listing
198
+ * called running. A row that is not a mapping throws there, before anything is pruned.
199
+ * Read with `loads` and stripped with `stripText`, as it always has been.
200
+ */
201
+ function parseJsonOrNdjson(raw) {
202
+ const trimmed = (0, float_text_1.stripText)(raw);
203
+ if (trimmed === '')
204
+ return [];
205
+ const decodeFailed = (error) => error instanceof json_text_1.JsonSyntaxError || error instanceof SyntaxError;
206
+ try {
207
+ const document = (0, json_text_1.loads)(trimmed);
208
+ return isMapping(document) ? [document] : document;
209
+ }
210
+ catch (error) {
211
+ if (!decodeFailed(error))
212
+ throw error;
213
+ // Newer compose emits a JSON array; older versions emit NDJSON, one object per
214
+ // line. Both are handled so callers work across compose versions.
215
+ const rows = [];
216
+ for (const line of (0, format_1.splitTextLines)(trimmed)) {
217
+ const stripped = (0, float_text_1.stripText)(line);
218
+ if (stripped === '')
219
+ continue;
220
+ try {
221
+ rows.push((0, json_text_1.loads)(stripped));
222
+ }
223
+ catch (lineError) {
224
+ if (!decodeFailed(lineError))
225
+ throw lineError;
226
+ }
227
+ }
228
+ return rows;
229
+ }
230
+ }
231
+ function isMapping(value) {
232
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
233
+ }
234
+ /**
235
+ * Each row keyed by its `Name` (`""` when it has none), as far as that decides anything:
236
+ * the rows of what the listing returned (a string iterates by characters, and a number or
237
+ * a boolean is not iterable), each read as a mapping, and its name used as a key. The
238
+ * first row that is not a mapping throws `expected an object, got ...`, and a list or
239
+ * mapping for a name `... cannot be a key`, both TypeErrors; `runCli` reports either
240
+ * through the contract's last line, as it always has.
241
+ */
242
+ function projectRows(data) {
243
+ let items;
244
+ if (typeof data === 'string')
245
+ items = [...data];
246
+ else if (Array.isArray(data))
247
+ items = data;
248
+ else
249
+ throw new TypeError((0, format_1.expectedText)('a list', data));
250
+ return items.map((item) => {
251
+ if (!isMapping(item)) {
252
+ throw new TypeError((0, format_1.expectedText)('an object', item));
253
+ }
254
+ const name = item.Name ?? '';
255
+ if (typeof name === 'object') {
256
+ throw new TypeError((0, format_1.keyRefusal)(name));
257
+ }
258
+ return [String(name), item];
259
+ });
260
+ }
261
+ /**
262
+ * Parsed `docker compose ls --all --format json`, or null if the query failed.
263
+ *
264
+ * Bounded: the GUI polls this every 4 s on a worker. A daemon that answers `docker info`
265
+ * (so `dockerAvailable` says yes) but then wedges on `compose ls` would otherwise park a
266
+ * worker per poll. Failing to null is already the "could not ask docker" path.
267
+ */
268
+ async function composeLs() {
269
+ try {
270
+ const result = await (0, docker_cli_1.docker)(['compose', 'ls', '--all', '--format', 'json'], {
271
+ capture: true,
272
+ timeoutMs: 30000,
273
+ });
274
+ if (result.exitCode !== 0)
275
+ return null;
276
+ return parseJsonOrNdjson(String(result.stdout ?? ''));
277
+ }
278
+ catch (error) {
279
+ if (error instanceof exec_1.Interrupted)
280
+ throw error; // Ctrl-C or a stopped job: unwind
281
+ return null;
282
+ }
283
+ }
284
+ /**
285
+ * Map compose project name -> status string for ALL projects, in one call.
286
+ *
287
+ * Status looks like "running(3)" / "exited(2)"; a fully `down`ed repro (no containers)
288
+ * is absent from the output. Returns null if the query itself failed -- callers that
289
+ * DELETE based on absence (prune) must not confuse "no projects" with "could not ask
290
+ * docker".
291
+ */
292
+ async function projectStates() {
293
+ return await (0, docker_cli_1.cachedQuery)('project_states', async () => {
294
+ const data = await composeLs();
295
+ if (data === null)
296
+ return null;
297
+ const out = {};
298
+ for (const [name, item] of projectRows(data))
299
+ out[name] = String(item.Status ?? '');
300
+ return out;
301
+ });
302
+ }
303
+ /**
304
+ * Map compose project name -> its ConfigFiles string (comma-joined paths).
305
+ *
306
+ * Used to detect a project-name COLLISION: two repro workspaces (a real one and a
307
+ * throwaway in a different HOUSTON_HOME) derive the same project name `houston-<name>`,
308
+ * and `docker compose up` would then reconcile the wrong workspace's containers. null if
309
+ * docker could not be queried.
310
+ */
311
+ async function projectConfigFiles() {
312
+ const data = await composeLs();
313
+ if (data === null)
314
+ return null;
315
+ const out = {};
316
+ for (const [name, item] of projectRows(data))
317
+ out[name] = String(item.ConfigFiles ?? '');
318
+ return out;
319
+ }
320
+ /**
321
+ * The MongoDB volume a Compose project left behind, [] for none; null if docker could not
322
+ * be asked. A project `down`ed without `--volumes` is absent from `compose ls`, and this is
323
+ * all of it that is left.
324
+ */
325
+ async function projectDataVolumes(project) {
326
+ try {
327
+ const result = await (0, docker_cli_1.docker)([
328
+ 'volume',
329
+ 'ls',
330
+ '-q',
331
+ '--filter',
332
+ `label=com.docker.compose.project=${project}`,
333
+ '--filter',
334
+ 'label=com.docker.compose.volume=mongodb_data',
335
+ ], { capture: true, timeoutMs: 30000 });
336
+ if (result.exitCode !== 0)
337
+ return null;
338
+ return (0, format_1.splitTextLines)(String(result.stdout ?? '')).filter((line) => line.trim() !== '');
339
+ }
340
+ catch (error) {
341
+ if (error instanceof exec_1.Interrupted)
342
+ throw error; // Ctrl-C or a stopped job: unwind
343
+ return null;
344
+ }
345
+ }
346
+ /**
347
+ * `serviceContainerIds` of `rocketchat`, else of `rocketchat-1`: ONE `docker compose ps -q`
348
+ * when the first answers. This asked the first twice -- once for the length, once for the
349
+ * value -- so every "still booting" tick of a readiness wait ran an extra docker process,
350
+ * about a hundred over a 300 s wait.
351
+ */
352
+ async function rcContainerId(name) {
353
+ const first = await engine.serviceContainerIds(name, 'rocketchat');
354
+ const ids = first.length > 0 ? first : await engine.serviceContainerIds(name, 'rocketchat-1');
355
+ return ids[0];
356
+ }
357
+ /**
358
+ * The RC container's ACTUAL environment, or null if it could not be read.
359
+ *
360
+ * The compose document is what a workspace was ASKED to run; this is what it IS
361
+ * running, and they diverge. MEASURED: an `env` apply interrupted mid-recreate left
362
+ * `OVERWRITE_SETTING_Accounts_RegistrationForm=Disabled` in both the compose file and
363
+ * `repro.json`, and absent from the container -- and neither `start`, `restart` nor a
364
+ * re-run `up` put it back, because none of them re-reads the compose config.
365
+ *
366
+ * NULL, NOT `{}`. "The container is not running" and "the container has no environment"
367
+ * are different facts, and the caller reports drift by comparing two sets -- so an empty
368
+ * one from a failed read would report every recorded variable as missing.
369
+ */
370
+ async function rcContainerEnv(name) {
371
+ const id = await rcContainerId(name);
372
+ if (id === undefined)
373
+ return null;
374
+ let rows;
375
+ try {
376
+ const result = await (0, docker_cli_1.docker)(['inspect', '--format', '{{json .Config.Env}}', id], {
377
+ capture: true,
378
+ timeoutMs: 15000,
379
+ });
380
+ if (result.exitCode !== 0)
381
+ return null;
382
+ rows = JSON.parse(String(result.stdout ?? 'null'));
383
+ }
384
+ catch (error) {
385
+ if (error instanceof exec_1.Interrupted)
386
+ throw error; // Ctrl-C or a stopped job: unwind
387
+ return null;
388
+ }
389
+ if (!Array.isArray(rows))
390
+ return null;
391
+ const out = {};
392
+ for (const row of rows) {
393
+ const text = String(row);
394
+ const at = text.indexOf('=');
395
+ // An item set on a mapping (`setItemChecked`): a container running `__proto__=x` has that
396
+ // variable. Assigned, it was dropped, and `houston env` reported the override it had
397
+ // just applied as NOT RUNNING.
398
+ if (at > 0)
399
+ (0, format_1.setItemChecked)(out, text.slice(0, at), text.slice(at + 1));
400
+ }
401
+ return out;
402
+ }
403
+ /**
404
+ * The running containers that have no network at all.
405
+ *
406
+ * A start that fails at its port binding leaves the container attached to nothing, and the
407
+ * next `compose start` "succeeds" with it so: Rocket.Chat up with only `lo`, no published
408
+ * port, and `getaddrinfo EAI_AGAIN mongodb`. Nothing short of recreating it gives it back.
409
+ */
410
+ async function networklessContainers(name) {
411
+ try {
412
+ const listed = await engine.compose(name, ['ps', '-q'], { capture: true });
413
+ const ids = String(listed.stdout ?? '')
414
+ .split('\n')
415
+ .map((line) => line.trim())
416
+ .filter((line) => line !== '');
417
+ if (listed.exitCode !== 0 || ids.length === 0)
418
+ return [];
419
+ const result = await (0, docker_cli_1.docker)(['inspect', '--format', '{{.Name}}\t{{len .NetworkSettings.Networks}}', ...ids], { capture: true, timeoutMs: 15000 });
420
+ if (result.exitCode !== 0)
421
+ return [];
422
+ return String(result.stdout ?? '')
423
+ .split('\n')
424
+ .map((line) => line.split('\t'))
425
+ .filter(([, count]) => (count ?? '').trim() === '0')
426
+ .map(([container]) => (container ?? '').replace(/^\//u, ''));
427
+ }
428
+ catch (error) {
429
+ if (error instanceof exec_1.Interrupted)
430
+ throw error;
431
+ return [];
432
+ }
433
+ }
434
+ /**
435
+ * What Docker recorded as each container's start error, `service: error`, for those that
436
+ * have one.
437
+ *
438
+ * `compose start` prints the reason (a port somebody else holds) on its own output and
439
+ * exits 1. In the GUI that went to serve's terminal, and the job said only "`docker compose
440
+ * start` failed" -- a port clash and a broken image read the same. Docker keeps the reason
441
+ * on the container, so it is asked afterwards rather than parsed out of the stream.
442
+ */
443
+ async function startErrors(name) {
444
+ try {
445
+ const listed = await engine.compose(name, ['ps', '--all', '-q'], { capture: true });
446
+ const ids = String(listed.stdout ?? '')
447
+ .split('\n')
448
+ .map((line) => line.trim())
449
+ .filter((line) => line !== '');
450
+ if (listed.exitCode !== 0 || ids.length === 0)
451
+ return [];
452
+ const result = await (0, docker_cli_1.docker)([
453
+ 'inspect',
454
+ '--format',
455
+ '{{index .Config.Labels "com.docker.compose.service"}}\t{{.State.Error}}',
456
+ ...ids,
457
+ ], { capture: true, timeoutMs: 15000 });
458
+ if (result.exitCode !== 0)
459
+ return [];
460
+ return String(result.stdout ?? '')
461
+ .split('\n')
462
+ .map((line) => line.split('\t'))
463
+ .filter(([, error]) => (error ?? '').trim() !== '')
464
+ .map(([service, error]) => `${service ?? '?'}: ${(error ?? '').trim()}`);
465
+ }
466
+ catch (error) {
467
+ if (error instanceof exec_1.Interrupted)
468
+ throw error;
469
+ return [];
470
+ }
471
+ }
472
+ /**
473
+ * The workspace's one-shot setup containers -- `mongo-init`, `minio-init` -- as they stand.
474
+ *
475
+ * By name and by policy: a `-init` service with no restart policy runs once and exits. An
476
+ * unreadable answer is none, so a box that cannot be asked waits for nothing extra.
477
+ */
478
+ async function oneShotSetups(name) {
479
+ try {
480
+ const listed = await engine.compose(name, ['ps', '--all', '-q'], { capture: true });
481
+ const ids = String(listed.stdout ?? '')
482
+ .split('\n')
483
+ .map((line) => line.trim())
484
+ .filter((line) => line !== '');
485
+ if (listed.exitCode !== 0 || ids.length === 0)
486
+ return [];
487
+ const result = await (0, docker_cli_1.docker)([
488
+ 'inspect',
489
+ '--format',
490
+ '{{index .Config.Labels "com.docker.compose.service"}}\t' +
491
+ '{{.HostConfig.RestartPolicy.Name}}\t{{.State.Status}}\t{{.State.ExitCode}}',
492
+ ...ids,
493
+ ], { capture: true, timeoutMs: 15000 });
494
+ if (result.exitCode !== 0)
495
+ return [];
496
+ return String(result.stdout ?? '')
497
+ .split('\n')
498
+ .map((line) => line.trim().split('\t'))
499
+ .filter(([service, policy]) => (service ?? '').endsWith('-init') && ['no', ''].includes(policy ?? ''))
500
+ .map(([service, , status, code]) => ({
501
+ service: service ?? '',
502
+ status: status ?? '',
503
+ exitCode: Number(code) || 0,
504
+ }));
505
+ }
506
+ catch (error) {
507
+ if (error instanceof exec_1.Interrupted)
508
+ throw error;
509
+ return [];
510
+ }
511
+ }
512
+ /**
513
+ * How many times the repro's rocketchat container has restarted -- a nonzero and
514
+ * climbing value signals a crash-loop, usually resource pressure. 0 if unknown.
515
+ */
516
+ async function rcRestartCount(name) {
517
+ const id = await rcContainerId(name);
518
+ if (id === undefined)
519
+ return 0;
520
+ try {
521
+ // Bounded for the same reason as composeLs: the detail panel refreshes this on a
522
+ // timer, and "unknown" (0) is already the documented fallback.
523
+ const result = await (0, docker_cli_1.docker)(['inspect', '--format', '{{.RestartCount}}', id], {
524
+ capture: true,
525
+ timeoutMs: 15000,
526
+ });
527
+ const count = Number.parseInt(String(result.stdout ?? '0').trim(), 10);
528
+ return Number.isFinite(count) ? count : 0;
529
+ }
530
+ catch (error) {
531
+ // Any failure to run or read the command, which an Interrupted is not: a
532
+ // Ctrl-C in `docker inspect` during `backup`'s wait for Rocket.Chat was a restart count
533
+ // of 0, one more `still booting` line, and the next wait ending the run.
534
+ if (error instanceof exec_1.Interrupted)
535
+ throw error;
536
+ return 0;
537
+ }
538
+ }
539
+ /**
540
+ * Map compose project -> {service: `Status` string} for EVERY container.
541
+ *
542
+ * The same single `docker ps`; it just stopped discarding the rest of the output.
543
+ * `rcStatusByProject` used to keep the rocketchat line and throw the others away, which
544
+ * is why a repro whose MONGODB had exited reported `running` and `healthy` -- both
545
+ * derived from the Rocket.Chat container alone, and Rocket.Chat serves /api/info
546
+ * perfectly well with no database behind it.
547
+ */
548
+ async function servicesByProject() {
549
+ return await (0, docker_cli_1.cachedQuery)('services_by_project', servicesByProjectUncached);
550
+ }
551
+ async function servicesByProjectUncached() {
552
+ let stdout;
553
+ try {
554
+ const result = await (0, docker_cli_1.docker)([
555
+ 'ps',
556
+ '--all',
557
+ '--format',
558
+ '{{.Label "com.docker.compose.project"}}\t{{.Label "com.docker.compose.service"}}\t{{.Status}}',
559
+ ], { capture: true, timeoutMs: 30000 });
560
+ // Same 4 s poll bound as composeLs; {} = "could not ask".
561
+ if (result.exitCode !== 0)
562
+ return {};
563
+ stdout = String(result.stdout ?? '');
564
+ }
565
+ catch (error) {
566
+ if (error instanceof exec_1.Interrupted)
567
+ throw error; // Ctrl-C or a stopped job: unwind
568
+ return {};
569
+ }
570
+ const out = {};
571
+ for (const line of stdout.split('\n')) {
572
+ const parts = line.split('\t');
573
+ const [project, service, status] = parts;
574
+ if (parts.length < 3 || project === undefined || project === '')
575
+ continue;
576
+ out[project] ?? (out[project] = {});
577
+ out[project][service ?? ''] = status ?? '';
578
+ }
579
+ return out;
580
+ }
581
+ /**
582
+ * Map compose project -> its rocketchat container `Status` string ("Up 2 hours
583
+ * (healthy)"), in ONE `docker ps` call. Used to show uptime and health per repro without
584
+ * an N-call fan-out.
585
+ */
586
+ async function rcStatusByProject(byProject) {
587
+ const servicesByName = byProject ?? (await servicesByProject());
588
+ const out = {};
589
+ for (const [project, services] of Object.entries(servicesByName)) {
590
+ out[project] = services.rocketchat ?? services['rocketchat-1'] ?? '';
591
+ }
592
+ return out;
593
+ }
594
+ /** Per-container `{service, state, status, health}` for a repro, including stopped. */
595
+ async function containerDetails(name) {
596
+ const result = await engine.compose(name, ['ps', '--all', '--format', 'json'], {
597
+ capture: true,
598
+ });
599
+ if (result.exitCode !== 0)
600
+ return [];
601
+ // The object rows only, as before `parseJsonOrNdjson` kept every row: the previous
602
+ // implementation reads each row as a mapping here too, but nothing has measured what a
603
+ // detail panel should do on the non-object answer compose never gives, so this reads it
604
+ // as it did.
605
+ const data = parseJsonOrNdjson(String(result.stdout ?? ''));
606
+ return (Array.isArray(data) ? data.filter(isMapping) : []).map((item) => ({
607
+ service: String(item.Service ?? ''),
608
+ state: String(item.State ?? ''),
609
+ status: String(item.Status ?? ''),
610
+ health: String(item.Health ?? ''),
611
+ }));
612
+ }