@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,691 @@
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.OUTLIVE_THE_WORKSPACE = exports.WORKSPACE_KINDS = exports.ADVISORY = exports.EMAIL_2FA_SETTING = exports.KINDS = exports.CLUSTER_UNFINISHED = exports.DATABASE_DROPPED = exports.E2EE_DEFAULT_OFF = exports.EMAIL_2FA_OFF = exports.MONGO_PROFILER_ON = exports.RC_METRICS_ON = exports.CREATE_UNFINISHED = exports.CONSTRAINTS_APPLIED = exports.BENCH_WORKSPACE = exports.ROCKETCHAT_STOPPED = exports.RATE_LIMITER_OFF = exports.DIRNAME = void 0;
37
+ exports.journalDir = journalDir;
38
+ exports.procStarted = procStarted;
39
+ exports.ownerAlive = ownerAlive;
40
+ exports.record = record;
41
+ exports.clear = clear;
42
+ exports.clearKind = clearKind;
43
+ exports.clearWorkspace = clearWorkspace;
44
+ exports.sideEffect = sideEffect;
45
+ exports.openEntries = openEntries;
46
+ exports.registerSubjectPredicate = registerSubjectPredicate;
47
+ exports.subjectPredicateKinds = subjectPredicateKinds;
48
+ exports.stillThere = stillThere;
49
+ exports.abandoned = abandoned;
50
+ exports.describe = describe;
51
+ exports.registerRepair = registerRepair;
52
+ exports.repairKinds = repairKinds;
53
+ exports.recover = recover;
54
+ exports.pendingSeed = pendingSeed;
55
+ exports.installSink = installSink;
56
+ /**
57
+ * Durable notes about side effects that must be undone, so a killed process does not
58
+ * leave them behind.
59
+ *
60
+ * WHY A FILE AND NOT A `finally`. The GUI runs long operations in the background, so
61
+ * `systemctl restart`, an OOM kill or a plain SIGKILL ends them where they stand and skips
62
+ * every `finally` they were relying on. Those blocks are doing real work: `backup` stops
63
+ * Rocket.Chat for the duration of the dump, `loadtest` turns the API rate limiter OFF,
64
+ * `capacity` arms the Mongo profiler and applies container CPU/RAM caps. Interrupted, all
65
+ * of that outlives the process -- a workspace that silently is not serving, a rate limiter
66
+ * left off -- with nothing anywhere recording that it happened.
67
+ *
68
+ * Cooperative cancellation cannot fix this. It helps a graceful shutdown; the dangerous
69
+ * exit is the one where no code runs at all. What survives that is a note written BEFORE
70
+ * the risky change and removed AFTER it is undone.
71
+ *
72
+ * THE HARD PART IS NOT WRITING IT, IT IS KNOWING WHOSE IT IS. An open entry belongs either
73
+ * to a job still running or to a process that died. Repairing the first would re-enable the
74
+ * rate limiter underneath a load test that is still going. So each entry records the pid
75
+ * AND that process's start time, and recovery touches an entry only when its owner is
76
+ * provably gone -- pid alone is not enough, because the OS recycles them.
77
+ *
78
+ * ## This module is the SINK; `lib/journal.ts` is the registry
79
+ *
80
+ * `core/eks` writes the most expensive note in the product and sits BELOW this file, so the
81
+ * registry is the dependency inversion. This installs itself at import, and replays any
82
+ * subject predicate registered before it arrived -- which is why that queue exists.
83
+ *
84
+ * ## `record` and `clear` are SYNCHRONOUS, and that is a deliberate departure
85
+ *
86
+ * Atomic filesystem helpers expose asynchronous APIs, so that nothing blocks the event
87
+ * loop. This module is the exception, and the reason is the thing it exists for.
88
+ *
89
+ * `core/eks` writes CLUSTER_UNFINISHED on the line BEFORE `eksctl create cluster` -- a
90
+ * twenty-minute call that builds a VPC, a NAT gateway and a control plane. An awaited write
91
+ * yields the event loop between "decided to write the note" and "the note is on disk", and
92
+ * that gap is precisely the window the note exists to cover: a SIGKILL landing in it leaves
93
+ * a billing cluster with no record anywhere that it was ever started. It has always been
94
+ * synchronous here for that reason, and `lib/journal.ts`'s registry is declared
95
+ * synchronous and id-returning because `eks` has to be able to clear the note it wrote.
96
+ *
97
+ * So the write is `writeFileSync` + `renameSync` -- the same temp-file-then-rename
98
+ * `runner/paths.atomicWrite` does, spelled synchronously. It is one small file, not a
99
+ * subprocess or a network call, which is the class of work the async rule is about.
100
+ */
101
+ const node_crypto_1 = require("node:crypto");
102
+ const fs = __importStar(require("node:fs"));
103
+ const path = __importStar(require("node:path"));
104
+ const config = __importStar(require("../lib/config"));
105
+ const events_1 = require("../lib/events");
106
+ const home_1 = require("../lib/home");
107
+ const journal_1 = require("../lib/journal");
108
+ const mkdir_parents_1 = require("../lib/mkdir-parents");
109
+ const engine_1 = require("./runner/engine");
110
+ const paths_1 = require("./runner/paths");
111
+ /**
112
+ * One file per open side effect. A DIRECTORY rather than a single log, because entries are
113
+ * created and cleared concurrently by unrelated jobs, and an unlink is atomic where a
114
+ * rewrite of a shared file is a lost-update race.
115
+ */
116
+ exports.DIRNAME = 'journal';
117
+ exports.RATE_LIMITER_OFF = 'rate_limiter_off';
118
+ exports.ROCKETCHAT_STOPPED = 'rocketchat_stopped';
119
+ /**
120
+ * A throwaway workspace the deleted `benchmark` command meant to delete.
121
+ *
122
+ * NOTHING RECORDS THIS ANY MORE and it stays anyway. `benchmark` is gone, but a
123
+ * journal note is durable state on somebody's disk, and the entire purpose of this module
124
+ * is that a killed process's side effects are recoverable LATER -- by a build that may be
125
+ * newer than the one that made the mess. Dropping the kind from a closed vocabulary would
126
+ * strand exactly the notes it exists to honour.
127
+ */
128
+ exports.BENCH_WORKSPACE = 'bench_workspace';
129
+ exports.CONSTRAINTS_APPLIED = 'constraints_applied';
130
+ exports.CREATE_UNFINISHED = 'create_unfinished';
131
+ exports.RC_METRICS_ON = 'rc_metrics_on';
132
+ exports.MONGO_PROFILER_ON = 'mongo_profiler_on';
133
+ exports.EMAIL_2FA_OFF = 'email_2fa_off';
134
+ /** One of `config.E2EE_ROOM_DEFAULT_SETTINGS`, named in `detail.setting`, off for a seed. */
135
+ exports.E2EE_DEFAULT_OFF = 'e2ee_default_off';
136
+ exports.DATABASE_DROPPED = 'database_dropped';
137
+ exports.CLUSTER_UNFINISHED = 'cluster_unfinished';
138
+ /**
139
+ * Kinds, CLOSED on purpose: recovery has to know how to undo each one, so a kind nothing
140
+ * can repair is a note that would sit there forever looking like a fault.
141
+ */
142
+ exports.KINDS = Object.freeze([
143
+ exports.RATE_LIMITER_OFF,
144
+ exports.ROCKETCHAT_STOPPED,
145
+ exports.BENCH_WORKSPACE,
146
+ exports.CONSTRAINTS_APPLIED,
147
+ exports.CREATE_UNFINISHED,
148
+ exports.RC_METRICS_ON,
149
+ exports.MONGO_PROFILER_ON,
150
+ exports.EMAIL_2FA_OFF,
151
+ exports.DATABASE_DROPPED,
152
+ exports.CLUSTER_UNFINISHED,
153
+ exports.E2EE_DEFAULT_OFF,
154
+ ]);
155
+ /** Named once so the seed path and the repair cannot disagree about which key they mean. */
156
+ exports.EMAIL_2FA_SETTING = 'Accounts_TwoFactorAuthentication_By_Email_Enabled';
157
+ /**
158
+ * Kinds recovery REPORTS but does not undo by itself.
159
+ *
160
+ * `CREATE_UNFINISHED` is here for a timing reason: finishing a create means waiting for
161
+ * Rocket.Chat to serve and then running the preset's self-configuration, which can take the
162
+ * full readiness timeout, and doing that inside `serve`'s startup would hold the GUI shut
163
+ * for minutes on a workspace nobody asked about. The other two are here because acting on
164
+ * them is destructive and a process that already crashed is not what should decide to.
165
+ */
166
+ exports.ADVISORY = Object.freeze([
167
+ exports.CREATE_UNFINISHED,
168
+ exports.DATABASE_DROPPED,
169
+ exports.CLUSTER_UNFINISHED,
170
+ ]);
171
+ /**
172
+ * Kinds whose note is ABOUT A WORKSPACE, and so goes when that workspace's record does.
173
+ *
174
+ * `down --volumes` and `prune` delete the containers, the data and the record, and nothing
175
+ * cleared the notes about them: only a create that finishes and `ready` ever closed a
176
+ * `CREATE_UNFINISHED`, and both need the workspace to exist. Seen as 28 notes for one
177
+ * workspace that `down --volumes` had removed, and `doctor` went on advising `houston ready
178
+ * --name <it>` -- advice that cannot work on a workspace that is gone. `serve`'s recovery
179
+ * drops such notes at its next start, but a CLI-only box never starts one, and `doctor` is
180
+ * what tells that box.
181
+ *
182
+ * Each one, and why it goes with the workspace:
183
+ * RATE_LIMITER_OFF, EMAIL_2FA_OFF, RC_METRICS_ON, MONGO_PROFILER_ON, E2EE_DEFAULT_OFF -- a
184
+ * setting held in the workspace's database, which the deletion took with its volume.
185
+ * ROCKETCHAT_STOPPED, CONSTRAINTS_APPLIED -- the state of a container, and the containers
186
+ * are gone.
187
+ * BENCH_WORKSPACE -- its repair IS deleting the workspace, which has just happened.
188
+ * CREATE_UNFINISHED -- `ready` completes a workspace; there is none left to complete.
189
+ * DATABASE_DROPPED -- the half-loaded database went with the volume.
190
+ */
191
+ exports.WORKSPACE_KINDS = Object.freeze([
192
+ exports.RATE_LIMITER_OFF,
193
+ exports.ROCKETCHAT_STOPPED,
194
+ exports.BENCH_WORKSPACE,
195
+ exports.CONSTRAINTS_APPLIED,
196
+ exports.CREATE_UNFINISHED,
197
+ exports.RC_METRICS_ON,
198
+ exports.MONGO_PROFILER_ON,
199
+ exports.EMAIL_2FA_OFF,
200
+ exports.DATABASE_DROPPED,
201
+ exports.E2EE_DEFAULT_OFF,
202
+ ]);
203
+ /**
204
+ * The kinds that must OUTLIVE a workspace of the same name, and why.
205
+ * CLUSTER_UNFINISHED -- its `workspace` field carries a CLUSTER name, and the cluster may
206
+ * be billing now. A workspace called the same is not that cluster, and deleting it
207
+ * says nothing about whether an interrupted `eksctl create` left a VPC and a NAT
208
+ * gateway behind.
209
+ * Every kind is in exactly one of the two, so a new kind has to be decided here rather than
210
+ * fall into whichever default was nearest.
211
+ */
212
+ exports.OUTLIVE_THE_WORKSPACE = Object.freeze([exports.CLUSTER_UNFINISHED]);
213
+ function journalDir() {
214
+ // Joined component by component, a `..` kept, as every path under the home is.
215
+ return (0, home_1.joinPath)(config.home(), exports.DIRNAME);
216
+ }
217
+ /**
218
+ * A process's start time as a stable string, or null if it is not running.
219
+ *
220
+ * Field 22 of `/proc/<pid>/stat`, in clock ticks since boot. Read from the raw bytes and
221
+ * split from the RIGHT of the last ')', because field 2 is the executable name and may
222
+ * itself contain spaces or brackets.
223
+ *
224
+ * Returns '' for "running, but the start time could not be read", which is a different
225
+ * answer from null and is what `ownerAlive` leans on.
226
+ *
227
+ * Off Linux there is no /proc, and reading it answered null -- "not running" -- for every
228
+ * pid, this process's own included: on a Mac a CLI cluster build in another terminal read as
229
+ * "failed part-way", and `serve`'s startup recovery would undo work still in progress. There
230
+ * the answer is liveness alone, '' for a pid that exists: kill(0) succeeds, or is refused for
231
+ * someone else's process.
232
+ *
233
+ * ponytail: pid only, so a recycled pid keeps a dead owner's note alive (left alone, never
234
+ * undone). `ps -o lstart=` would add the start time, at the cost of an async `record`.
235
+ */
236
+ function procStarted(pid) {
237
+ if (process.platform !== 'linux') {
238
+ // kill(0) and kill(-n) address process GROUPS, which are always "running".
239
+ if (!(Math.trunc(pid) > 0))
240
+ return null;
241
+ try {
242
+ process.kill(Math.trunc(pid), 0);
243
+ }
244
+ catch (error) {
245
+ if (error.code !== 'EPERM')
246
+ return null;
247
+ }
248
+ return '';
249
+ }
250
+ let raw;
251
+ try {
252
+ raw = fs.readFileSync(`/proc/${Math.trunc(pid)}/stat`, 'utf8');
253
+ }
254
+ catch {
255
+ return null;
256
+ }
257
+ const close = raw.lastIndexOf(')');
258
+ if (close < 0)
259
+ return '';
260
+ const fields = raw
261
+ .slice(close + 1)
262
+ .trim()
263
+ .split(/\s+/u);
264
+ return fields[19] ?? '';
265
+ }
266
+ /**
267
+ * Whether the process that wrote this is still running.
268
+ *
269
+ * pid AND start time, because a recycled pid is a different process. An unknowable start
270
+ * time falls back to pid liveness, which is the conservative direction: it means "assume
271
+ * the owner is alive", so recovery leaves the entry alone rather than undoing live work.
272
+ */
273
+ function ownerAlive(entry) {
274
+ const current = procStarted(entry.pid);
275
+ if (current === null)
276
+ return false;
277
+ if (!entry.started)
278
+ return true;
279
+ return current === entry.started;
280
+ }
281
+ /**
282
+ * The current UTC time as `YYYY-MM-DDTHH:MM:SSZ`.
283
+ *
284
+ * UTC, LIKE EVERY OTHER TIMESTAMP HERE. `strftime` with no argument is LOCAL time, so one
285
+ * event once read 22:29 in a journal note and 16:59 in the `repro.json` written beside it
286
+ * -- and a note is read next to `doctor`, `list` and an audit line, all of which are UTC.
287
+ */
288
+ function stamp() {
289
+ return `${new Date().toISOString().slice(0, 19)}Z`;
290
+ }
291
+ /**
292
+ * Note a side effect that must be undone. Returns the entry id, or '' if unwritable.
293
+ *
294
+ * Best-effort by design: a journal that cannot be written must not stop the operation it
295
+ * was describing. The operation's own `finally` is still the primary cleanup -- this is
296
+ * only what covers the case where no `finally` runs.
297
+ */
298
+ function record(kind, workspace, detail = {}) {
299
+ if (!exports.KINDS.includes(kind)) {
300
+ throw new Error(`unknown journal kind '${kind}' (want: ${exports.KINDS.join(', ')})`);
301
+ }
302
+ const entry = {
303
+ id: (0, node_crypto_1.randomBytes)(8).toString('hex'),
304
+ kind,
305
+ workspace,
306
+ pid: process.pid,
307
+ started: procStarted(process.pid) ?? '',
308
+ at: stamp(),
309
+ detail: { ...detail },
310
+ };
311
+ try {
312
+ const dir = journalDir();
313
+ // Made with its parents, the mode 0700 on the leaf only.
314
+ (0, mkdir_parents_1.mkdirParents)(dir, 0o700);
315
+ atomicWriteSync((0, home_1.joinPath)(dir, `${entry.id}.json`), JSON.stringify(entry, null, 2));
316
+ }
317
+ catch {
318
+ return '';
319
+ }
320
+ return entry.id;
321
+ }
322
+ /**
323
+ * `runner/paths.atomicWrite`, spelled synchronously. See the module docstring for why.
324
+ *
325
+ * The temp name is unique per call for the reason the async one gives: a fixed
326
+ * `<name>.tmp` meant two concurrent writers shared one path and clobbered each other,
327
+ * defeating the atomicity it exists to provide.
328
+ */
329
+ function atomicWriteSync(target, content) {
330
+ const unique = `${String(process.pid)}.${(0, node_crypto_1.randomBytes)(4).toString('hex')}`;
331
+ const temporary = (0, home_1.joinPath)(path.dirname(target), `${path.basename(target)}.${unique}.tmp`);
332
+ try {
333
+ fs.writeFileSync(temporary, content, { encoding: 'utf8' });
334
+ fs.renameSync(temporary, target);
335
+ }
336
+ finally {
337
+ // A no-op after a successful rename; the cleanup that matters is the failed one.
338
+ try {
339
+ fs.rmSync(temporary, { force: true });
340
+ }
341
+ catch {
342
+ /* already renamed away */
343
+ }
344
+ }
345
+ }
346
+ /** Forget an entry, because whatever it described has been undone. */
347
+ function clear(entryId) {
348
+ if (!entryId)
349
+ return;
350
+ try {
351
+ fs.rmSync((0, home_1.joinPath)(journalDir(), `${entryId}.json`), { force: true });
352
+ }
353
+ catch {
354
+ /* best-effort */
355
+ }
356
+ }
357
+ /**
358
+ * Forget EVERY note of one kind for one workspace. Returns how many went.
359
+ *
360
+ * Some facts invalidate other processes' notes, not just your own. "This workspace's create
361
+ * finished" is one: a create that failed left a `CREATE_UNFINISHED` note behind, and a
362
+ * later create of the same name that succeeded cleared only the note it had written itself
363
+ * -- so the stale one went on claiming a complete workspace had never finished. Seen
364
+ * exactly that way, when a failed attempt was followed by a good one.
365
+ */
366
+ function clearKind(kind, workspace) {
367
+ let gone = 0;
368
+ for (const entry of openEntries()) {
369
+ if (entry.kind === kind && entry.workspace === workspace) {
370
+ clear(entry.id);
371
+ gone += 1;
372
+ }
373
+ }
374
+ return gone;
375
+ }
376
+ /**
377
+ * Forget every note ABOUT one workspace, because its record is being deleted.
378
+ *
379
+ * Whoever owns the note, alive or not -- unlike recovery, which touches abandoned ones only.
380
+ * A live owner's note describes work on a workspace that is going away, so there is nothing
381
+ * left for it to put back. Every caller holds the workspace's `reproLock`, which is where a
382
+ * create writes its note, so no create can have one here for a workspace it has not made
383
+ * yet. See `WORKSPACE_KINDS` for which kinds go.
384
+ */
385
+ function clearWorkspace(workspace, kinds = exports.WORKSPACE_KINDS) {
386
+ let gone = 0;
387
+ for (const entry of openEntries()) {
388
+ if (kinds.includes(entry.kind) && entry.workspace === workspace) {
389
+ clear(entry.id);
390
+ gone += 1;
391
+ }
392
+ }
393
+ return gone;
394
+ }
395
+ /**
396
+ * Record on the way in, clear on the way out -- however that happens.
397
+ *
398
+ * Wraps an existing `finally` rather than replacing it: the note is cleared when the normal
399
+ * cleanup has run, so a surviving entry means precisely "the cleanup did not happen".
400
+ */
401
+ async function sideEffect(kind, workspace, body, detail = {}) {
402
+ const entryId = record(kind, workspace, detail);
403
+ try {
404
+ return await body(entryId);
405
+ }
406
+ finally {
407
+ clear(entryId);
408
+ }
409
+ }
410
+ /** Every entry on disk, newest last. Unreadable files are skipped, not raised. */
411
+ function openEntries() {
412
+ const out = [];
413
+ let names;
414
+ try {
415
+ names = fs
416
+ .readdirSync(journalDir())
417
+ .filter((n) => n.endsWith('.json'))
418
+ .sort();
419
+ }
420
+ catch {
421
+ return out;
422
+ }
423
+ for (const name of names) {
424
+ try {
425
+ const data = JSON.parse(fs.readFileSync((0, home_1.joinPath)(journalDir(), name), 'utf8'));
426
+ const rawDetail = data.detail;
427
+ out.push({
428
+ id: String(data.id ?? '') || name.replace(/\.json$/u, ''),
429
+ kind: String(data.kind ?? ''),
430
+ workspace: String(data.workspace ?? ''),
431
+ pid: Number.parseInt(String(data.pid ?? 0), 10) || 0,
432
+ started: String(data.started ?? ''),
433
+ at: String(data.at ?? ''),
434
+ detail: typeof rawDetail === 'object' && rawDetail !== null && !Array.isArray(rawDetail)
435
+ ? { ...rawDetail }
436
+ : {},
437
+ });
438
+ }
439
+ catch {
440
+ continue;
441
+ }
442
+ }
443
+ return out;
444
+ }
445
+ /**
446
+ * How to ask "is the thing this note is ABOUT still here", per kind.
447
+ *
448
+ * `recover()` clears an advisory note whose subject is gone, and it used to ask that as
449
+ * `exists(entry.workspace)`. That is the right question for every kind today,
450
+ * because every one of them is about a workspace -- and it is only ACCIDENTALLY right. A
451
+ * note whose subject is NOT a workspace -- a cluster, say -- would find that false always,
452
+ * and be cleared silently at the next `serve` startup. The most expensive note in the
453
+ * product would be the one guaranteed not to survive.
454
+ *
455
+ * The fix is to keep ONE rule and make the rule true, rather than special-casing a kind out
456
+ * of a rule stated as general -- which is the shape that produced this.
457
+ */
458
+ const SUBJECT_EXISTS = new Map();
459
+ /** Register the owning module's way to ask whether a journal subject exists. */
460
+ function registerSubjectPredicate(kind, predicate) {
461
+ const current = SUBJECT_EXISTS.get(kind);
462
+ if (current !== undefined && current !== predicate) {
463
+ throw new Error(`journal subject predicate already registered for ${kind}`);
464
+ }
465
+ SUBJECT_EXISTS.set(kind, predicate);
466
+ }
467
+ function subjectPredicateKinds() {
468
+ return [...SUBJECT_EXISTS.keys()].sort();
469
+ }
470
+ /**
471
+ * Whether the thing an advisory note is about still exists.
472
+ *
473
+ * A predicate that THROWS answers true, and that direction is deliberate: "I could not ask"
474
+ * is not "it is gone", and the cost of the two mistakes is not symmetric. Keeping a stale
475
+ * note wastes a line of output; dropping a live one loses the only record that something is
476
+ * still running -- and for a cloud cluster, still billing.
477
+ */
478
+ async function stillThere(entry) {
479
+ const ask = SUBJECT_EXISTS.get(entry.kind);
480
+ if (ask === undefined)
481
+ return await (0, paths_1.exists)(entry.workspace);
482
+ try {
483
+ return await ask(entry);
484
+ }
485
+ catch {
486
+ return true;
487
+ }
488
+ }
489
+ /** Entries whose owning process is gone -- the ones safe to act on. */
490
+ function abandoned() {
491
+ return openEntries().filter((e) => !ownerAlive(e));
492
+ }
493
+ /** One line a human can act on, whether or not recovery can. */
494
+ function describe(entry) {
495
+ const w = `'${entry.workspace}'`;
496
+ switch (entry.kind) {
497
+ case exports.RATE_LIMITER_OFF:
498
+ // A seed and a settings import turn it off too, and say so; a note without a
499
+ // purpose is a load test's, as every earlier one was taken to be.
500
+ return (`${w}: the API rate limiter was turned off for ` +
501
+ `${String(entry.detail.purpose ?? 'a performance run')} at ${entry.at} and never ` +
502
+ 'turned back on');
503
+ case exports.ROCKETCHAT_STOPPED:
504
+ return `${w}: Rocket.Chat was stopped for a backup at ${entry.at} and never started again`;
505
+ case exports.BENCH_WORKSPACE:
506
+ return (`${w}: a throwaway benchmark workspace from ${entry.at} is still here, ` +
507
+ 'holding a Rocket.Chat and a MongoDB');
508
+ case exports.CONSTRAINTS_APPLIED: {
509
+ const applied = Array.isArray(entry.detail.applied)
510
+ ? entry.detail.applied
511
+ : [];
512
+ const caps = applied
513
+ .slice(0, 3)
514
+ .map((a) => String(a.service ?? '?'))
515
+ .join(', ');
516
+ return (`${w}: CPU/RAM limits from a performance run at ${entry.at} are still ` +
517
+ `applied (${caps || 'unknown services'})`);
518
+ }
519
+ case exports.DATABASE_DROPPED:
520
+ return (`${w}: a restore from ${String(entry.detail.bundle ?? 'a bundle')} dropped ` +
521
+ `the database at ${entry.at} and never finished loading it — the workspace ` +
522
+ `is running against an EMPTY or partial database. \`houston restore ` +
523
+ `${String(entry.detail.bundle ?? '<bundle>')} --name ${entry.workspace}\` ` +
524
+ 'again is what completes it');
525
+ case exports.CLUSTER_UNFINISHED: {
526
+ const name = entry.workspace;
527
+ const region = String(entry.detail.region ?? '<region>');
528
+ const account = String(entry.detail.account ?? 'unknown account');
529
+ // CloudFormation-shaped, because the obvious advice is the advice that fails: a
530
+ // rolled-back `eksctl create` can leave its stack behind, and `eksctl delete` then
531
+ // reports that the cluster does not exist while a VPC and a NAT gateway carry on
532
+ // billing.
533
+ return (`an \`eksctl create cluster\` for '${name}' in ${region} (account ${account}) ` +
534
+ `was interrupted at ${entry.at} and never returned. It may have created a VPC, ` +
535
+ 'a NAT gateway and a control plane, which are BILLING NOW. houston will not ' +
536
+ 'delete a cloud cluster it did not see finish — that is minutes of destructive ' +
537
+ 'work on your AWS account decided by a process that already crashed. Run ' +
538
+ `\`eksctl delete cluster --name ${name} --region ${region} --wait\`; if that ` +
539
+ 'says the cluster does not exist, the CloudFormation stack may have rolled back ' +
540
+ `and SURVIVED, so check \`aws cloudformation describe-stacks --stack-name ` +
541
+ `eksctl-${name}-cluster --region ${region}\` and delete it directly`);
542
+ }
543
+ case exports.EMAIL_2FA_OFF:
544
+ return (`${w}: email two-factor authentication was turned off for a seed at ` +
545
+ `${entry.at} and never turned back on — seeded users are loginable and real ` +
546
+ 'ones may not be');
547
+ case exports.E2EE_DEFAULT_OFF:
548
+ return (`${w}: ${String(entry.detail.setting ?? 'an end-to-end encryption default')} was ` +
549
+ `turned off for a seed at ${entry.at} and never turned back on — new rooms it ` +
550
+ 'covers are not created encrypted');
551
+ case exports.RC_METRICS_ON:
552
+ return (`${w}: Rocket.Chat's Prometheus metrics endpoint was turned on for a ` +
553
+ `diagnostic run at ${entry.at} and never turned off`);
554
+ case exports.MONGO_PROFILER_ON:
555
+ return (`${w}: Mongo's query profiler was armed for a diagnostic run at ${entry.at} ` +
556
+ 'and never disarmed — it is still writing a system.profile document for every ' +
557
+ 'slow operation');
558
+ case exports.CREATE_UNFINISHED: {
559
+ const seeded = entry.detail.seed === undefined || entry.detail.seed === null || entry.detail.seed === ''
560
+ ? ''
561
+ : ' and its seed';
562
+ return (`${w}: the create started at ${entry.at} never finished, so it may be running ` +
563
+ `WITHOUT its preset configuration${seeded || ' or seed data'} — ` +
564
+ `\`houston ready --name ${entry.workspace}\` completes it`);
565
+ }
566
+ default:
567
+ return `${w}: ${entry.kind} since ${entry.at}`;
568
+ }
569
+ }
570
+ const REPAIR_HANDLERS = new Map();
571
+ /** Register one side-effect owner's recovery handler, idempotently. */
572
+ function registerRepair(kind, handler) {
573
+ const current = REPAIR_HANDLERS.get(kind);
574
+ if (current !== undefined && current !== handler) {
575
+ throw new Error(`journal repair handler already registered for ${kind}`);
576
+ }
577
+ REPAIR_HANDLERS.set(kind, handler);
578
+ }
579
+ function repairKinds() {
580
+ return [...REPAIR_HANDLERS.keys()].sort();
581
+ }
582
+ /** Retained for durable notes written by the removed benchmark command. */
583
+ async function repairBench(entry) {
584
+ await (0, engine_1.down)(entry.workspace, { volumes: true });
585
+ await (0, paths_1.remove)(entry.workspace);
586
+ return true;
587
+ }
588
+ registerRepair(exports.BENCH_WORKSPACE, repairBench);
589
+ /** Dispatch to the side-effect owner without importing that owner. */
590
+ async function repairOne(entry, emit, login) {
591
+ if (!(await (0, paths_1.exists)(entry.workspace)))
592
+ return true;
593
+ const handler = REPAIR_HANDLERS.get(entry.kind);
594
+ if (handler === undefined)
595
+ return false;
596
+ return Boolean(await handler(entry, emit, login));
597
+ }
598
+ /**
599
+ * Undo what abandoned entries describe. Returns one result per entry.
600
+ *
601
+ * NEVER throws: this runs at `serve` startup, and a box that cannot be repaired still has
602
+ * to be able to serve. Each result carries `repaired` so a caller can say what is still
603
+ * outstanding.
604
+ */
605
+ async function recover(emit = events_1.nullEmit, { dryRun = false, login = null } = {}) {
606
+ const results = [];
607
+ for (const entry of abandoned()) {
608
+ const row = {
609
+ id: entry.id,
610
+ kind: entry.kind,
611
+ workspace: entry.workspace,
612
+ what: describe(entry),
613
+ repaired: false,
614
+ why: '',
615
+ };
616
+ if (exports.ADVISORY.includes(entry.kind) && !(await stillThere(entry))) {
617
+ // The thing the note is about is gone, so an unfinished create is no longer
618
+ // anybody's problem. Advisory notes are never repaired, so without this they would
619
+ // warn forever about something that cannot be acted on.
620
+ //
621
+ // UNDER dryRun THIS IS A READ. The clear used to sit above the dry-run check, so a
622
+ // dry run over two notes reported one and DELETED the other -- and a dry run is the
623
+ // only way to inspect the journal without repairing it, which makes mutating one a
624
+ // contradiction in terms.
625
+ if (dryRun) {
626
+ row.why = 'the thing it is about is gone; would be dropped';
627
+ results.push(row);
628
+ continue;
629
+ }
630
+ clear(entry.id);
631
+ continue;
632
+ }
633
+ if (dryRun || exports.ADVISORY.includes(entry.kind)) {
634
+ // Reported and left alone. See ADVISORY: undoing this one means waiting for a
635
+ // workspace to serve, which is not something a GUI startup may spend.
636
+ row.why = exports.ADVISORY.includes(entry.kind) ? 'needs `houston ready`' : '';
637
+ results.push(row);
638
+ if (exports.ADVISORY.includes(entry.kind))
639
+ (0, events_1.warn)(emit, row.what, { phase: 'preflight' });
640
+ continue;
641
+ }
642
+ try {
643
+ row.repaired = await repairOne(entry, emit, login);
644
+ }
645
+ catch (error) {
646
+ // Recovery must not break startup.
647
+ row.why = error instanceof Error ? error.message : String(error);
648
+ }
649
+ if (row.repaired) {
650
+ clear(entry.id);
651
+ (0, events_1.info)(emit, `repaired: ${row.what}`, { phase: 'preflight' });
652
+ }
653
+ else {
654
+ (0, events_1.warn)(emit, `could NOT repair — ${row.what}${row.why ? ` (${row.why})` : ''}`, {
655
+ phase: 'preflight',
656
+ });
657
+ }
658
+ results.push(row);
659
+ }
660
+ return results;
661
+ }
662
+ /**
663
+ * The seed an interrupted create asked for and never ran, or {}.
664
+ *
665
+ * Read from the NOTE rather than from the workspace's metadata, because that is the only
666
+ * place it survives: the `CreateReq` died with the process, and `meta.extra.seed` is
667
+ * written only after a seed has already succeeded -- so metadata can say "seeded" or say
668
+ * nothing, and "nothing" covers both "none was asked for" and "one was asked for and lost".
669
+ *
670
+ * Only OPEN notes count. A note whose owner is still alive belongs to a create that is
671
+ * still running, and finishing its seed underneath it would seed twice.
672
+ */
673
+ function pendingSeed(workspace) {
674
+ for (const entry of abandoned()) {
675
+ if (entry.kind === exports.CREATE_UNFINISHED && entry.workspace === workspace) {
676
+ const seed = entry.detail.seed;
677
+ if (seed === true || (typeof seed === 'string' && seed !== ''))
678
+ return { ...entry.detail };
679
+ }
680
+ }
681
+ return {};
682
+ }
683
+ /** Install this module as the journal `lib/journal.ts` reaches. */
684
+ function installSink() {
685
+ return (0, journal_1.installJournalSink)({
686
+ record,
687
+ clear,
688
+ registerSubjectPredicate,
689
+ });
690
+ }
691
+ installSink();