@serfab/cadre-host 1.13.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (352) hide show
  1. package/README.md +347 -423
  2. package/dist/bin/host.d.ts +6 -3
  3. package/dist/bin/host.js +332 -524
  4. package/dist/bin/host.js.map +1 -1
  5. package/dist/bin/join-output.d.ts +56 -0
  6. package/dist/bin/join-output.js +92 -0
  7. package/dist/bin/join-output.js.map +1 -0
  8. package/dist/bin/nat-output.d.ts +54 -0
  9. package/dist/bin/nat-output.js +138 -0
  10. package/dist/bin/nat-output.js.map +1 -0
  11. package/dist/bin/ui-access.d.ts +22 -0
  12. package/dist/bin/ui-access.js +44 -0
  13. package/dist/bin/ui-access.js.map +1 -0
  14. package/dist/hosted/claim-details.d.ts +66 -0
  15. package/dist/hosted/claim-details.js +60 -0
  16. package/dist/hosted/claim-details.js.map +1 -0
  17. package/dist/hosted/hosted-node-service.d.ts +325 -0
  18. package/dist/hosted/hosted-node-service.js +678 -0
  19. package/dist/hosted/hosted-node-service.js.map +1 -0
  20. package/dist/hosted/hosted-node-store.d.ts +40 -0
  21. package/dist/hosted/hosted-node-store.js +126 -0
  22. package/dist/hosted/hosted-node-store.js.map +1 -0
  23. package/dist/{donation/donation-supervisor.d.ts → hosted/hosted-node-supervisor.d.ts} +70 -53
  24. package/dist/hosted/hosted-node-supervisor.js +396 -0
  25. package/dist/hosted/hosted-node-supervisor.js.map +1 -0
  26. package/dist/hosted/hosted-node-watcher.d.ts +95 -0
  27. package/dist/hosted/hosted-node-watcher.js +260 -0
  28. package/dist/hosted/hosted-node-watcher.js.map +1 -0
  29. package/dist/hosted/index.d.ts +16 -0
  30. package/dist/hosted/index.js +13 -0
  31. package/dist/hosted/index.js.map +1 -0
  32. package/dist/hosted/node-status.d.ts +51 -0
  33. package/dist/hosted/node-status.js +77 -0
  34. package/dist/hosted/node-status.js.map +1 -0
  35. package/dist/hosted/types.d.ts +141 -0
  36. package/dist/hosted/types.js +22 -0
  37. package/dist/hosted/types.js.map +1 -0
  38. package/dist/index.d.ts +12 -24
  39. package/dist/index.js +9 -19
  40. package/dist/index.js.map +1 -1
  41. package/dist/installer/config.d.ts +27 -34
  42. package/dist/installer/config.js +46 -15
  43. package/dist/installer/config.js.map +1 -1
  44. package/dist/installer/index.d.ts +9 -19
  45. package/dist/installer/index.js +21 -85
  46. package/dist/installer/index.js.map +1 -1
  47. package/dist/installer/paths.d.ts +0 -2
  48. package/dist/installer/paths.js +0 -4
  49. package/dist/installer/paths.js.map +1 -1
  50. package/dist/installer/wizard.d.ts +12 -9
  51. package/dist/installer/wizard.js +15 -14
  52. package/dist/installer/wizard.js.map +1 -1
  53. package/dist/nat/address-resolver.d.ts +18 -17
  54. package/dist/nat/address-resolver.js +79 -25
  55. package/dist/nat/address-resolver.js.map +1 -1
  56. package/dist/nat/address-watch.d.ts +37 -0
  57. package/dist/nat/address-watch.js +84 -0
  58. package/dist/nat/address-watch.js.map +1 -0
  59. package/dist/nat/ddns/duckdns.d.ts +2 -1
  60. package/dist/nat/ddns/duckdns.js +5 -1
  61. package/dist/nat/ddns/duckdns.js.map +1 -1
  62. package/dist/nat/ddns/index.d.ts +6 -0
  63. package/dist/nat/ddns/index.js.map +1 -1
  64. package/dist/nat/index.d.ts +13 -9
  65. package/dist/nat/index.js +7 -5
  66. package/dist/nat/index.js.map +1 -1
  67. package/dist/nat/nat-service.d.ts +220 -77
  68. package/dist/nat/nat-service.js +653 -239
  69. package/dist/nat/nat-service.js.map +1 -1
  70. package/dist/nat/nat-store.d.ts +12 -5
  71. package/dist/nat/nat-store.js +124 -29
  72. package/dist/nat/nat-store.js.map +1 -1
  73. package/dist/nat/network-mode.d.ts +19 -0
  74. package/dist/nat/network-mode.js +32 -0
  75. package/dist/nat/network-mode.js.map +1 -0
  76. package/dist/nat/port-mapper.d.ts +83 -79
  77. package/dist/nat/port-mapper.js +148 -189
  78. package/dist/nat/port-mapper.js.map +1 -1
  79. package/dist/nat/reachability.d.ts +32 -15
  80. package/dist/nat/reachability.js +110 -22
  81. package/dist/nat/reachability.js.map +1 -1
  82. package/dist/nat/types.d.ts +98 -27
  83. package/dist/nat/types.js +8 -5
  84. package/dist/nat/types.js.map +1 -1
  85. package/dist/orchestrator/host-process-orchestrator.d.ts +32 -74
  86. package/dist/orchestrator/host-process-orchestrator.js +84 -233
  87. package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
  88. package/dist/{installer/identity.d.ts → orchestrator/identity-file.d.ts} +5 -5
  89. package/dist/{installer/identity.js → orchestrator/identity-file.js} +6 -6
  90. package/dist/orchestrator/identity-file.js.map +1 -0
  91. package/dist/orchestrator/index.d.ts +2 -3
  92. package/dist/orchestrator/index.js +1 -1
  93. package/dist/orchestrator/index.js.map +1 -1
  94. package/dist/orchestrator/node-identity.d.ts +6 -6
  95. package/dist/orchestrator/node-identity.js +7 -7
  96. package/dist/orchestrator/node-identity.js.map +1 -1
  97. package/dist/orchestrator/port-allocator.d.ts +5 -6
  98. package/dist/orchestrator/port-allocator.js +9 -11
  99. package/dist/orchestrator/port-allocator.js.map +1 -1
  100. package/dist/orchestrator/state-store.d.ts +3 -5
  101. package/dist/orchestrator/state-store.js +2 -10
  102. package/dist/orchestrator/state-store.js.map +1 -1
  103. package/dist/orchestrator/types.d.ts +33 -22
  104. package/dist/orchestrator/types.js.map +1 -1
  105. package/dist/package-version.d.ts +1 -0
  106. package/dist/package-version.js +4 -0
  107. package/dist/package-version.js.map +1 -0
  108. package/dist/server/error-handler.d.ts +5 -25
  109. package/dist/server/error-handler.js +11 -74
  110. package/dist/server/error-handler.js.map +1 -1
  111. package/dist/server/events/types.d.ts +7 -11
  112. package/dist/server/events/types.js +2 -1
  113. package/dist/server/events/types.js.map +1 -1
  114. package/dist/server/index.d.ts +11 -37
  115. package/dist/server/index.js +30 -48
  116. package/dist/server/index.js.map +1 -1
  117. package/dist/server/routes/hosted-nodes.d.ts +28 -0
  118. package/dist/server/routes/hosted-nodes.js +68 -0
  119. package/dist/server/routes/hosted-nodes.js.map +1 -0
  120. package/dist/server/routes/nat.d.ts +4 -1
  121. package/dist/server/routes/nat.js +13 -2
  122. package/dist/server/routes/nat.js.map +1 -1
  123. package/dist/server/routes/nodes.d.ts +6 -20
  124. package/dist/server/routes/nodes.js +7 -86
  125. package/dist/server/routes/nodes.js.map +1 -1
  126. package/dist/server/routes/settings.d.ts +3 -7
  127. package/dist/server/routes/settings.js +18 -8
  128. package/dist/server/routes/settings.js.map +1 -1
  129. package/dist/server/routes/status.d.ts +2 -25
  130. package/dist/server/routes/status.js +3 -43
  131. package/dist/server/routes/status.js.map +1 -1
  132. package/dist/server/server.js +8 -8
  133. package/dist/server/settings-store.d.ts +2 -2
  134. package/dist/server/settings-store.js +2 -2
  135. package/dist/server/static.js +1 -2
  136. package/dist/server/static.js.map +1 -1
  137. package/dist/ui/assets/index-BHd8CWZA.css +1 -0
  138. package/dist/ui/assets/index-Ccr2GjPT.js +23 -0
  139. package/dist/ui/assets/index-Ccr2GjPT.js.map +1 -0
  140. package/dist/ui/index.html +2 -2
  141. package/dist/update/index.d.ts +2 -2
  142. package/dist/update/index.js +2 -2
  143. package/dist/update/store.d.ts +1 -1
  144. package/dist/update/store.js +1 -1
  145. package/dist/update/types.d.ts +1 -1
  146. package/dist/update/types.js +1 -1
  147. package/package.json +5 -7
  148. package/src/__tests__/cli-nat.smoke.test.ts +219 -212
  149. package/src/__tests__/cli.smoke.test.ts +2 -2
  150. package/src/__tests__/global-setup.ts +2 -3
  151. package/src/__tests__/orchestrator-claim-secret.test.ts +111 -0
  152. package/src/__tests__/orchestrator-env-scrub.test.ts +160 -163
  153. package/src/__tests__/orchestrator-handle-contract.ts +134 -134
  154. package/src/__tests__/orchestrator-node-identity.test.ts +177 -203
  155. package/src/__tests__/orchestrator-ports.test.ts +124 -143
  156. package/src/__tests__/orchestrator-push.test.ts +138 -146
  157. package/src/__tests__/orchestrator.test.ts +1017 -1063
  158. package/src/__tests__/ui-access.test.ts +30 -0
  159. package/src/bin/host.ts +397 -572
  160. package/src/bin/join-output.ts +120 -0
  161. package/src/bin/nat-output.ts +188 -0
  162. package/src/bin/ui-access.ts +50 -0
  163. package/src/{donation → hosted}/__tests__/fake-orchestrator.test.ts +172 -173
  164. package/src/{donation → hosted}/__tests__/fake-orchestrator.ts +43 -23
  165. package/src/hosted/__tests__/hosted-node-service.test.ts +708 -0
  166. package/src/hosted/__tests__/hosted-node-supervisor.test.ts +475 -0
  167. package/src/hosted/__tests__/test-invitation.ts +33 -0
  168. package/src/hosted/claim-details.ts +103 -0
  169. package/src/hosted/hosted-node-service.ts +814 -0
  170. package/src/hosted/hosted-node-store.ts +144 -0
  171. package/src/hosted/hosted-node-supervisor.ts +439 -0
  172. package/src/hosted/hosted-node-watcher.ts +288 -0
  173. package/src/hosted/index.ts +53 -0
  174. package/src/hosted/node-status.ts +97 -0
  175. package/src/hosted/types.ts +160 -0
  176. package/src/index.ts +72 -91
  177. package/src/installer/__tests__/config.test.ts +15 -40
  178. package/src/installer/__tests__/installer.smoke.test.ts +184 -263
  179. package/src/installer/__tests__/wizard.test.ts +25 -13
  180. package/src/installer/config.ts +201 -175
  181. package/src/installer/index.ts +252 -327
  182. package/src/installer/paths.ts +104 -109
  183. package/src/installer/wizard.ts +24 -26
  184. package/src/nat/__tests__/address-resolver.test.ts +107 -82
  185. package/src/nat/__tests__/nat-service.test.ts +608 -515
  186. package/src/nat/__tests__/nat-store.test.ts +49 -12
  187. package/src/nat/__tests__/network-mode.test.ts +38 -0
  188. package/src/nat/__tests__/port-mapper.test.ts +30 -191
  189. package/src/nat/__tests__/reachability.test.ts +96 -13
  190. package/src/nat/address-resolver.ts +94 -52
  191. package/src/nat/address-watch.ts +92 -0
  192. package/src/nat/ddns/duckdns.ts +5 -1
  193. package/src/nat/ddns/index.ts +6 -0
  194. package/src/nat/index.ts +33 -13
  195. package/src/nat/nat-service.ts +942 -501
  196. package/src/nat/nat-store.ts +126 -31
  197. package/src/nat/network-mode.ts +36 -0
  198. package/src/nat/port-mapper.ts +241 -329
  199. package/src/nat/reachability.ts +155 -34
  200. package/src/nat/types.ts +110 -37
  201. package/src/{installer/__tests__/identity.test.ts → orchestrator/__tests__/identity-file.test.ts} +34 -34
  202. package/src/orchestrator/__tests__/node-identity.test.ts +62 -62
  203. package/src/orchestrator/host-process-orchestrator.ts +1089 -1260
  204. package/src/{installer/identity.ts → orchestrator/identity-file.ts} +56 -56
  205. package/src/orchestrator/index.ts +9 -10
  206. package/src/orchestrator/node-identity.ts +41 -41
  207. package/src/orchestrator/port-allocator.ts +71 -73
  208. package/src/orchestrator/state-store.ts +76 -90
  209. package/src/orchestrator/types.ts +34 -23
  210. package/src/package-version.ts +4 -0
  211. package/src/server/__tests__/bus.test.ts +38 -38
  212. package/src/server/__tests__/error-handler.test.ts +81 -118
  213. package/src/server/__tests__/fakes.ts +15 -18
  214. package/src/server/__tests__/hosted-nodes-route.test.ts +161 -0
  215. package/src/server/__tests__/nodes-route.test.ts +114 -283
  216. package/src/server/__tests__/publishers.test.ts +193 -180
  217. package/src/server/__tests__/server.smoke.test.ts +134 -223
  218. package/src/server/__tests__/settings-route.test.ts +210 -195
  219. package/src/server/__tests__/sse-route.test.ts +119 -119
  220. package/src/server/__tests__/status-route.test.ts +82 -121
  221. package/src/server/error-handler.ts +112 -178
  222. package/src/server/events/types.ts +20 -24
  223. package/src/server/index.ts +223 -267
  224. package/src/server/routes/hosted-nodes.ts +83 -0
  225. package/src/server/routes/nat.ts +75 -63
  226. package/src/server/routes/nodes.ts +96 -188
  227. package/src/server/routes/settings.ts +20 -15
  228. package/src/server/routes/status.ts +5 -67
  229. package/src/server/server.ts +8 -8
  230. package/src/server/settings-store.ts +2 -2
  231. package/src/server/static.ts +1 -2
  232. package/src/update/index.ts +2 -2
  233. package/src/update/store.ts +1 -1
  234. package/src/update/types.ts +1 -1
  235. package/dist/auth/duration.d.ts +0 -1
  236. package/dist/auth/duration.js +0 -32
  237. package/dist/auth/duration.js.map +0 -1
  238. package/dist/auth/index.d.ts +0 -11
  239. package/dist/auth/index.js +0 -9
  240. package/dist/auth/index.js.map +0 -1
  241. package/dist/auth/self-label.d.ts +0 -36
  242. package/dist/auth/self-label.js +0 -57
  243. package/dist/auth/self-label.js.map +0 -1
  244. package/dist/auth/trust-circle-store.d.ts +0 -26
  245. package/dist/auth/trust-circle-store.js +0 -129
  246. package/dist/auth/trust-circle-store.js.map +0 -1
  247. package/dist/auth/trust-circle.d.ts +0 -156
  248. package/dist/auth/trust-circle.js +0 -307
  249. package/dist/auth/trust-circle.js.map +0 -1
  250. package/dist/auth/types.d.ts +0 -84
  251. package/dist/auth/types.js +0 -24
  252. package/dist/auth/types.js.map +0 -1
  253. package/dist/donation/donation-service.d.ts +0 -389
  254. package/dist/donation/donation-service.js +0 -828
  255. package/dist/donation/donation-service.js.map +0 -1
  256. package/dist/donation/donation-store.d.ts +0 -51
  257. package/dist/donation/donation-store.js +0 -152
  258. package/dist/donation/donation-store.js.map +0 -1
  259. package/dist/donation/donation-supervisor.js +0 -364
  260. package/dist/donation/donation-supervisor.js.map +0 -1
  261. package/dist/donation/grant-service.d.ts +0 -80
  262. package/dist/donation/grant-service.js +0 -210
  263. package/dist/donation/grant-service.js.map +0 -1
  264. package/dist/donation/grant-store.d.ts +0 -38
  265. package/dist/donation/grant-store.js +0 -135
  266. package/dist/donation/grant-store.js.map +0 -1
  267. package/dist/donation/index.d.ts +0 -20
  268. package/dist/donation/index.js +0 -17
  269. package/dist/donation/index.js.map +0 -1
  270. package/dist/donation/types.d.ts +0 -224
  271. package/dist/donation/types.js +0 -40
  272. package/dist/donation/types.js.map +0 -1
  273. package/dist/installer/identity.js.map +0 -1
  274. package/dist/owner/index.d.ts +0 -11
  275. package/dist/owner/index.js +0 -11
  276. package/dist/owner/index.js.map +0 -1
  277. package/dist/owner/owner-node-client.d.ts +0 -110
  278. package/dist/owner/owner-node-client.js +0 -184
  279. package/dist/owner/owner-node-client.js.map +0 -1
  280. package/dist/server/routes/bootstrap-node-validation.d.ts +0 -115
  281. package/dist/server/routes/bootstrap-node-validation.js +0 -197
  282. package/dist/server/routes/bootstrap-node-validation.js.map +0 -1
  283. package/dist/server/routes/grants-admin.d.ts +0 -29
  284. package/dist/server/routes/grants-admin.js +0 -58
  285. package/dist/server/routes/grants-admin.js.map +0 -1
  286. package/dist/server/routes/grants.d.ts +0 -28
  287. package/dist/server/routes/grants.js +0 -165
  288. package/dist/server/routes/grants.js.map +0 -1
  289. package/dist/server/routes/provision-request-validation.d.ts +0 -45
  290. package/dist/server/routes/provision-request-validation.js +0 -97
  291. package/dist/server/routes/provision-request-validation.js.map +0 -1
  292. package/dist/server/routes/strands.d.ts +0 -20
  293. package/dist/server/routes/strands.js +0 -38
  294. package/dist/server/routes/strands.js.map +0 -1
  295. package/dist/server/routes/trust-circle.d.ts +0 -17
  296. package/dist/server/routes/trust-circle.js +0 -35
  297. package/dist/server/routes/trust-circle.js.map +0 -1
  298. package/dist/strands/index.d.ts +0 -7
  299. package/dist/strands/index.js +0 -6
  300. package/dist/strands/index.js.map +0 -1
  301. package/dist/strands/strand-service.d.ts +0 -50
  302. package/dist/strands/strand-service.js +0 -103
  303. package/dist/strands/strand-service.js.map +0 -1
  304. package/dist/strands/types.d.ts +0 -93
  305. package/dist/strands/types.js +0 -23
  306. package/dist/strands/types.js.map +0 -1
  307. package/dist/ui/assets/index-C6nELNfC.js +0 -23
  308. package/dist/ui/assets/index-C6nELNfC.js.map +0 -1
  309. package/dist/ui/assets/index-TtIYSeZO.css +0 -1
  310. package/src/__tests__/cli-invite.smoke.test.ts +0 -192
  311. package/src/__tests__/host-owner.smoke.test.ts +0 -123
  312. package/src/__tests__/orchestrator-owner.test.ts +0 -234
  313. package/src/__tests__/orchestrator-pin-keys.test.ts +0 -152
  314. package/src/auth/__tests__/duration.test.ts +0 -28
  315. package/src/auth/__tests__/self-label.test.ts +0 -85
  316. package/src/auth/__tests__/trust-circle-integration.test.ts +0 -152
  317. package/src/auth/__tests__/trust-circle-store.test.ts +0 -115
  318. package/src/auth/__tests__/trust-circle.test.ts +0 -445
  319. package/src/auth/duration.ts +0 -33
  320. package/src/auth/index.ts +0 -21
  321. package/src/auth/self-label.ts +0 -74
  322. package/src/auth/trust-circle-store.ts +0 -155
  323. package/src/auth/trust-circle.ts +0 -395
  324. package/src/auth/types.ts +0 -99
  325. package/src/donation/__tests__/donation-service.test.ts +0 -1193
  326. package/src/donation/__tests__/donation-supervisor.test.ts +0 -548
  327. package/src/donation/__tests__/grant-service.test.ts +0 -213
  328. package/src/donation/__tests__/grant-store.test.ts +0 -113
  329. package/src/donation/donation-service.ts +0 -1033
  330. package/src/donation/donation-store.ts +0 -176
  331. package/src/donation/donation-supervisor.ts +0 -411
  332. package/src/donation/grant-service.ts +0 -252
  333. package/src/donation/grant-store.ts +0 -152
  334. package/src/donation/index.ts +0 -65
  335. package/src/donation/types.ts +0 -260
  336. package/src/owner/__tests__/owner-node-client.test.ts +0 -194
  337. package/src/owner/index.ts +0 -12
  338. package/src/owner/owner-node-client.ts +0 -259
  339. package/src/server/__tests__/bootstrap-node-validation.test.ts +0 -138
  340. package/src/server/__tests__/grants-admin-route.test.ts +0 -171
  341. package/src/server/__tests__/grants-route.test.ts +0 -394
  342. package/src/server/__tests__/strands-route.test.ts +0 -234
  343. package/src/server/routes/bootstrap-node-validation.ts +0 -206
  344. package/src/server/routes/grants-admin.ts +0 -74
  345. package/src/server/routes/grants.ts +0 -193
  346. package/src/server/routes/provision-request-validation.ts +0 -105
  347. package/src/server/routes/strands.ts +0 -54
  348. package/src/server/routes/trust-circle.ts +0 -49
  349. package/src/strands/__tests__/strand-service.test.ts +0 -165
  350. package/src/strands/index.ts +0 -14
  351. package/src/strands/strand-service.ts +0 -135
  352. package/src/strands/types.ts +0 -102
@@ -0,0 +1,66 @@
1
+ /**
2
+ * What the QR code of a node waiting to be claimed carries, and the address list behind it.
3
+ * `HostedNodeService.claimDetails` reads the child's `/status` and hands it here.
4
+ */
5
+ import type { ClaimAddressSettings } from '../installer/config.js';
6
+ import type { NetworkMode, NodeReachability } from '../nat/types.js';
7
+ import type { NodeStatus } from './node-status.js';
8
+ /** What `claimDetails` answers: the QR payload and its parts. */
9
+ export interface ClaimDetails {
10
+ /** `encodeNodeClaimPayload` of the three fields below — the text the QR code carries. */
11
+ payload: string;
12
+ peerId: string;
13
+ /** Public names (or public IPs when there is no name), then the one LAN address; see {@link dialAddressesFor}. */
14
+ multiaddrs: string[];
15
+ /** The NAT layer's verdict for the node, or null when it has no entry yet. A phone at home reaches the LAN address either way. */
16
+ reachability: NodeReachability | null;
17
+ }
18
+ /** The NAT layer's answers the claim details need. `NatService` satisfies this. */
19
+ export interface HostedNodeAddressSource {
20
+ /** The node's public multiaddrs (no `/p2p/` suffix), TCP then WebSocket. */
21
+ publicAddressesFor(nodeId: string, ports: {
22
+ p2p: number;
23
+ ws?: number;
24
+ }): string[];
25
+ /**
26
+ * `gateway.lanAddress` is this machine's address on the router's subnet, when a UPnP gateway
27
+ * answered; `network.mode` is whether it sits behind a router (`lan`) or holds a public IPv4.
28
+ */
29
+ getStatus(): {
30
+ nodes: NodeReachability[];
31
+ gateway: {
32
+ lanAddress: string | null;
33
+ };
34
+ network: {
35
+ mode: NetworkMode;
36
+ };
37
+ };
38
+ }
39
+ /** One node's claim details, from its record's secret, its `/status`, and its ports. */
40
+ export interface ClaimDetailsInput {
41
+ id: string;
42
+ secret: string;
43
+ status: NodeStatus;
44
+ /** The orchestrator handle's ports; absent, the code carries LAN addresses only. */
45
+ ports: {
46
+ p2p: number;
47
+ ws?: number;
48
+ } | undefined;
49
+ addresses: HostedNodeAddressSource;
50
+ /** `host.config.json`'s `claimAddresses.addrs`: exact addresses replacing the automatic choice. */
51
+ exactAddrs?: readonly string[];
52
+ /** The LAN address to keep, as {@link claimLanAddress} resolved it. */
53
+ lan: string | null | undefined;
54
+ }
55
+ /**
56
+ * The claim details for a node whose `/status` answered. `503 node_unavailable` while the
57
+ * node reports no address a phone could dial (callers poll).
58
+ */
59
+ export declare function buildClaimDetails(input: ClaimDetailsInput): ClaimDetails;
60
+ /**
61
+ * The LAN address a node code keeps (`selectNodeClaimAddresses`' `lan`), from `claimAddresses.lan`:
62
+ * `'none'` is null; an IP is itself; `'auto'` (default) is null in public-IP mode (no phone shares
63
+ * a LAN with a VPS), else the gateway's `lanAddress`, else the machine's primary address
64
+ * (`primaryLan`, probed only then), else undefined (keep every private address).
65
+ */
66
+ export declare function claimLanAddress(settings: ClaimAddressSettings | undefined, addresses: HostedNodeAddressSource, primaryLan: () => Promise<string | undefined>): Promise<string | null | undefined>;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * What the QR code of a node waiting to be claimed carries, and the address list behind it.
3
+ * `HostedNodeService.claimDetails` reads the child's `/status` and hands it here.
4
+ */
5
+ import { encodeNodeClaimPayload, selectNodeClaimAddresses, withClaimDestination } from '@serfab/cadre-core';
6
+ import { HostedNodeError } from './types.js';
7
+ /**
8
+ * The claim details for a node whose `/status` answered. `503 node_unavailable` while the
9
+ * node reports no address a phone could dial (callers poll).
10
+ */
11
+ export function buildClaimDetails(input) {
12
+ const { id, status, addresses } = input;
13
+ const multiaddrs = dialAddressesFor(input);
14
+ if (multiaddrs.length === 0) {
15
+ throw new HostedNodeError('node_unavailable', `Hosted node ${id} reports no address a phone could dial yet`);
16
+ }
17
+ return {
18
+ payload: encodeNodeClaimPayload({ peerId: status.peerId, multiaddrs, secret: input.secret }),
19
+ peerId: status.peerId,
20
+ multiaddrs,
21
+ reachability: addresses.getStatus().nodes.find((n) => n.nodeId === id) ?? null,
22
+ };
23
+ }
24
+ /**
25
+ * The LAN address a node code keeps (`selectNodeClaimAddresses`' `lan`), from `claimAddresses.lan`:
26
+ * `'none'` is null; an IP is itself; `'auto'` (default) is null in public-IP mode (no phone shares
27
+ * a LAN with a VPS), else the gateway's `lanAddress`, else the machine's primary address
28
+ * (`primaryLan`, probed only then), else undefined (keep every private address).
29
+ */
30
+ export async function claimLanAddress(settings, addresses, primaryLan) {
31
+ const lan = settings?.lan ?? 'auto';
32
+ if (lan === 'none')
33
+ return null;
34
+ if (lan !== 'auto')
35
+ return lan;
36
+ const { network, gateway } = addresses.getStatus();
37
+ if (network.mode === 'public')
38
+ return null;
39
+ return gateway.lanAddress ?? await primaryLan();
40
+ }
41
+ /**
42
+ * The addresses the QR code names, in dial order. A phone dials each in turn on its own
43
+ * timeout, so every address it cannot reach delays a failing claim and enlarges the code.
44
+ *
45
+ * - With `exactAddrs`, exactly those, each given the node's peer id.
46
+ * - Otherwise cadre-core's `selectNodeClaimAddresses` over the NAT layer's public addresses
47
+ * and the node's own (`/status`): WebSocket and relay only (a phone has no TCP), public
48
+ * names before raw public IPs, and of the private addresses only `lan`. Docker bridges,
49
+ * VPNs and other interfaces a phone cannot reach are left out.
50
+ */
51
+ function dialAddressesFor({ id, status, ports, addresses, exactAddrs, lan }) {
52
+ // NOTE: `claimAddresses.addrs` is host-wide, so every hosted node's code carries the same
53
+ // addresses with its own peer id; that reaches each node only if they route per node (one
54
+ // node, or a port per node). If several nodes behind one proxy is reported, make it per node.
55
+ if (exactAddrs && exactAddrs.length > 0)
56
+ return [...new Set(exactAddrs.map((a) => withClaimDestination(a, status.peerId)))];
57
+ const publicAddrs = ports ? addresses.publicAddressesFor(id, ports) : [];
58
+ return selectNodeClaimAddresses([...publicAddrs, ...status.multiaddrs], status.peerId, { lan });
59
+ }
60
+ //# sourceMappingURL=claim-details.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-details.js","sourceRoot":"","sources":["../../src/hosted/claim-details.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAK5G,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAsC7C;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAwB;IACxD,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACxC,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,eAAe,CAAC,kBAAkB,EAAE,eAAe,EAAE,4CAA4C,CAAC,CAAC;IAC/G,CAAC;IACD,OAAO;QACL,OAAO,EAAE,sBAAsB,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAC5F,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,UAAU;QACV,YAAY,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,IAAI,IAAI;KAC/E,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,QAA0C,EAC1C,SAAkC,EAClC,UAA6C;IAE7C,MAAM,GAAG,GAAG,QAAQ,EAAE,GAAG,IAAI,MAAM,CAAC;IACpC,IAAI,GAAG,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,GAAG,KAAK,MAAM;QAAE,OAAO,GAAG,CAAC;IAC/B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;IACnD,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3C,OAAO,OAAO,CAAC,UAAU,IAAI,MAAM,UAAU,EAAE,CAAC;AAClD,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,gBAAgB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAqB;IAC5F,0FAA0F;IAC1F,0FAA0F;IAC1F,8FAA8F;IAC9F,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5H,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzE,OAAO,wBAAwB,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;AAClG,CAAC"}
@@ -0,0 +1,325 @@
1
+ import type { Orchestrator, OrchestratorCreateResult } from '@serfab/cadre-provider';
2
+ import type { HostedSpawnRequest, ManagedNodeInfo, NodeStateListener } from '../orchestrator/types.js';
3
+ import type { ClaimAddressSettings } from '../installer/config.js';
4
+ import { type ClaimDetails, type HostedNodeAddressSource } from './claim-details.js';
5
+ import type { HostedNodeStore } from './hosted-node-store.js';
6
+ import type { HostedNodeChange, HostedNodeChangeListener, HostedNodeStatus, HostedNodeView } from './types.js';
7
+ /**
8
+ * Age after which a record still stuck in `spawning` is marked `error` and its
9
+ * child, if any, reclaimed: the host wrote the row before starting the child, and
10
+ * a crash/kill in that window (or during the spawn itself) leaves nothing to
11
+ * advance it across a restart. A real spawn (identity key read/gen, port
12
+ * allocation, process spawn) completes in well under a second normally, so 5
13
+ * minutes is generously past "any plausible spawn" without risking a false reap
14
+ * of one still genuinely in flight under heavy load.
15
+ */
16
+ export declare const HOSTED_NODE_SPAWNING_TTL_MS: number;
17
+ /** How often the stuck-`spawning` reap runs while cadre-host is up. 5 minutes. */
18
+ export declare const HOSTED_NODE_REAP_SWEEP_MS: number;
19
+ /**
20
+ * Outcome of {@link HostedNodeService.respawn}:
21
+ *
22
+ * - `respawned` — a new child is up and the record now names its handles.
23
+ * - `abandoned` — the record was removed, or went `error`, while the spawn was in
24
+ * flight. The ending wins: the record is left exactly as the ending wrote it and
25
+ * the new child is cleaned up. `status` is the status that won, absent when the
26
+ * row is gone entirely.
27
+ */
28
+ export type RespawnResult = {
29
+ outcome: 'respawned';
30
+ node: HostedNodeView;
31
+ } | {
32
+ outcome: 'abandoned';
33
+ status?: HostedNodeStatus;
34
+ };
35
+ /** Options for {@link HostedNodeService.respawn}. */
36
+ export interface RespawnOptions {
37
+ /**
38
+ * Whether this respawn spends one of the record's attempts. Default true: a crash
39
+ * respawn does, since the supervisor's backoff and give-up read the count. A
40
+ * deliberate restart of a running node (`HostedNodeSupervisor.restart`) passes false
41
+ * and leaves both the counters and `updatedAt` alone.
42
+ */
43
+ countAttempt?: boolean;
44
+ }
45
+ /**
46
+ * Orchestrator capabilities the service needs beyond the base `Orchestrator`.
47
+ * `createContainer` takes the claim secret. The rest are optional — only
48
+ * `HostProcessOrchestrator` implements them; absent on a test double or a future
49
+ * orchestrator, the cleanup degrades to terminalizing the record with nothing to
50
+ * reclaim, and the claim details carry LAN addresses only.
51
+ */
52
+ export interface HostedNodeOrchestrator extends Orchestrator {
53
+ createContainer(request: HostedSpawnRequest): Promise<OrchestratorCreateResult>;
54
+ /**
55
+ * Resolve a spawn's friendly containerId (== a hosted node's id) back to its
56
+ * current dockerId, so a stuck-`spawning` reap can find and reclaim a child that
57
+ * was actually spawned before the host died.
58
+ */
59
+ resolveDockerId?(containerId: string): string | undefined;
60
+ /**
61
+ * Remove the working directory a spawn created for `containerId` when no handle
62
+ * owns it — the cleanup of last resort for a record that never got a `dockerId`.
63
+ * Returns whether anything was removed. Refuses when a handle still resolves
64
+ * (that child's directory belongs to `removeContainer`).
65
+ */
66
+ reclaimWorkdir?(containerId: string): boolean;
67
+ /** The node's handle, for the ports its public addresses are built from. */
68
+ getNode?(idOrDockerId: string): ManagedNodeInfo | undefined;
69
+ /** The exit/start signal the status watcher follows. */
70
+ onStateChange?(listener: NodeStateListener): () => void;
71
+ }
72
+ /** What `join` takes: nothing for a node waiting to be claimed, or the invitation the node redeems. */
73
+ export interface JoinOptions {
74
+ /** An encoded cadre invitation (`encodeCadreInvitation`), as the owner's app copies it. */
75
+ invitation?: string;
76
+ }
77
+ /** Constructor options. */
78
+ export interface HostedNodeServiceOptions {
79
+ /** Orchestrator that spawns/stops the hosted child processes. */
80
+ orchestrator: HostedNodeOrchestrator;
81
+ /** Persistent record store (`hosted-nodes.json`). */
82
+ store: HostedNodeStore;
83
+ /** The NAT layer, for the node's public addresses and reachability verdict. */
84
+ addresses: HostedNodeAddressSource;
85
+ /** `host.config.json`'s `claimAddresses`, read on every claim-code request so an edit applies at once. */
86
+ claimAddressSettings?: () => ClaimAddressSettings | undefined;
87
+ /** The machine's primary address, the `lan: 'auto'` fallback when no UPnP gateway answered. */
88
+ primaryLan?: () => Promise<string | undefined>;
89
+ /** Clock override for tests. */
90
+ now?: () => Date;
91
+ }
92
+ /**
93
+ * HostedNodeService — the host's one action, "Join a cadre", and what follows from it.
94
+ *
95
+ * `join` starts a child waiting to be claimed, or one that redeems a cadre invitation;
96
+ * `claimDetails` reads a waiting node's addresses and builds the QR payload; the status
97
+ * watcher ({@link startWatching}) notices the claim or the redemption's outcome, and the
98
+ * node's liveness; `respawn` brings a dead child back as the same node with the same
99
+ * secret and ports; `retry` starts an invitation node again after no member could be
100
+ * reached; `remove` and `reset` end it. The host contributes capacity only: it never
101
+ * holds an owner key.
102
+ *
103
+ * **An ending that lands mid-operation wins.** Spawning a child takes seconds, and
104
+ * a `remove` can land inside that window. `hosted-nodes.json` is written a whole row
105
+ * at a time, so every long operation re-reads the record after its wait, decides
106
+ * against what is actually stored, and merges forward only the fields it itself
107
+ * produced — never the entry-time copy.
108
+ *
109
+ * **Respawns run one at a time** ({@link serializeRespawns}): the supervisor's passes and
110
+ * restarts and `retry` share one queue, since two overlapping respawns of one id both spawn
111
+ * a child and the second drops the first's orchestrator handle.
112
+ */
113
+ export declare class HostedNodeService {
114
+ private readonly orchestrator;
115
+ private readonly store;
116
+ private readonly addresses;
117
+ private readonly claimAddressSettings;
118
+ private readonly primaryLan;
119
+ private readonly now;
120
+ private readonly listeners;
121
+ private readonly watcher;
122
+ /** Serialization tail for `join`, so two joins at once cannot interleave their store writes. */
123
+ private joinTail;
124
+ /** Serialization tail for every respawn — see {@link serializeRespawns}. */
125
+ private respawnTail;
126
+ constructor(opts: HostedNodeServiceOptions);
127
+ /** Register a change listener (the server publishes each change as an SSE event). Returns an unsubscribe fn. */
128
+ onChange(listener: HostedNodeChangeListener): () => void;
129
+ /**
130
+ * Report a change to the listeners. Public for the supervisor's give-up, which
131
+ * writes the record itself; a listener that throws is logged, never propagated.
132
+ */
133
+ emit(change: HostedNodeChange): void;
134
+ /** Start following every node's `/status` (claims and liveness). Idempotent. */
135
+ startWatching(): void;
136
+ stopWatching(): void;
137
+ /** One status pass now, awaited — for tests and callers that need the result before going on. */
138
+ pollStatuses(): Promise<void>;
139
+ /**
140
+ * Start a node: write the record, spawn the child, and record its handles. Without an
141
+ * invitation the node waits to be claimed — a fresh claim secret, the placeholder
142
+ * party, `unclaimed`. With one it redeems the invitation — the invitation's party,
143
+ * `joining` — and an invitation that does not decode is `invalid_request` before
144
+ * anything is written. On any orchestrator failure the reserved resources are
145
+ * reclaimed and the record is marked `error`. Resolves once the child is spawned; its
146
+ * `/status` may take a few seconds more, which `claimDetails` reports as
147
+ * `node_unavailable`.
148
+ */
149
+ join(opts?: JoinOptions): Promise<HostedNodeView>;
150
+ private joinLocked;
151
+ /**
152
+ * Mark a still-`spawning` record as failed — and ONLY such a record. A row that
153
+ * was removed while the spawn was in flight must not be recreated.
154
+ *
155
+ * Best-effort (mirroring {@link storeRespawnAttempt}): we are already unwinding a
156
+ * spawn failure, and a store error here must not mask the error being reported
157
+ * to the caller.
158
+ */
159
+ private markSpawnFailed;
160
+ /**
161
+ * What the QR code carries for a node waiting to be claimed: its peer id, the
162
+ * addresses a phone may dial it at, and its claim secret — the only place the
163
+ * secret ever leaves the host. `409 invalid_state` unless the node is `unclaimed`;
164
+ * `503 node_unavailable` until the child's `/status` answers (callers poll).
165
+ */
166
+ claimDetails(id: string): Promise<ClaimDetails>;
167
+ /** Cache the peer id on the record, once. Best-effort: the claim details do not depend on it. */
168
+ private recordPeerId;
169
+ /**
170
+ * Re-spawn a node that is no longer running, replaying the record's party and
171
+ * claim secret, or its invitation while it is still `joining`. The node keeps its
172
+ * workdir — and with it its identity key and node-local stores — and comes back on
173
+ * the same ports, so it is the *same* peer at the same addresses: a QR code already
174
+ * shown stays valid, and a joined node's cadre finds it where it was. Keeping the
175
+ * secret after the claim is deliberate: `cadre-cli` honours `claim.json` and, with the
176
+ * secret still set, answers a rival `already-claimed`. A joined invitation node comes
177
+ * back without its invitation ({@link spawnRequestFor} says why).
178
+ *
179
+ * **Status is deliberately unchanged.** A `joined` node stays `joined`; an
180
+ * `unclaimed` one keeps waiting, a `joining` one redeems again. `connected` is
181
+ * dropped until the watcher reads the new child.
182
+ *
183
+ * **An ending that lands mid-spawn wins.** The record is re-read after the
184
+ * orchestrator returns; if it was removed (or went `error`) while the child was
185
+ * starting, that write stands and the new child is abandoned — see
186
+ * {@link abandonRespawn}. An abandoned respawn is a skip, not a failure, so a
187
+ * sweep over the store keeps going. Orchestrator failures DO throw; the caller
188
+ * owns backoff/give-up.
189
+ *
190
+ * Not serialized itself: callers run it on {@link serializeRespawns}. Two overlapping
191
+ * calls for the same id both spawn a child, and the second spawn drops the first's
192
+ * orchestrator handle — leaving an unmanaged process.
193
+ */
194
+ respawn(id: string, opts?: RespawnOptions): Promise<RespawnResult>;
195
+ /**
196
+ * Start an invitation node again after no member of its cadre could be reached: the
197
+ * `error` record goes back to `joining` and is respawned with its invitation, without
198
+ * spending a respawn attempt. On the respawn queue, so it never overlaps the
199
+ * supervisor's handling of the same node. `409 invalid_state` unless the node is `error`
200
+ * with `retryable` — a refused invitation stays refused, and the supervisor's give-up and
201
+ * the other failures are a reset's.
202
+ */
203
+ retry(id: string): Promise<HostedNodeView>;
204
+ private retryLocked;
205
+ /**
206
+ * Give up on a respawn whose record ended while the child was starting: stop
207
+ * the new child and, unless the record went `error`, reclaim it.
208
+ *
209
+ * Reclaim, not merely stop. The removal's own cleanup already ran and found
210
+ * nothing: `HostProcessOrchestrator.createContainer` calls `dropStaleHandle`
211
+ * *while* spawning, so by the time the concurrent `remove` reached its
212
+ * stop/reclaim the old handle was gone and both calls were swallowed as
213
+ * best-effort no-ops. The new handle is now the only thing holding that
214
+ * spawn's ports and workdir, so stopping alone would leak both.
215
+ *
216
+ * `error` is the deliberate exception: `removeContainer` deletes the workdir,
217
+ * and `HostedNodeSupervisor.giveUp` keeps it on purpose so the identity key the
218
+ * node's cadre approved survives. Since both spawns share one workdir
219
+ * (`<rootDir>/<containerId>`), reclaiming here would delete exactly what
220
+ * `giveUp` meant to keep.
221
+ *
222
+ * The `error` record is then pointed at the new child, the one that exists, so a
223
+ * later `remove` reclaims its ports and workdir. `giveUp` runs on the respawn queue
224
+ * and cannot overlap a respawn; the watcher's write of a failed invitation can, when
225
+ * a poll of the old child answers while the new one is starting.
226
+ */
227
+ private abandonRespawn;
228
+ /**
229
+ * Remove a hosted node: delete the row FIRST, then stop and reclaim the child
230
+ * (its workdir, identity key and data go with it). The node's cadre keeps the
231
+ * node's row until its owner removes it there.
232
+ *
233
+ * Order matters: stopping the child fires the orchestrator's `onStateChange`,
234
+ * and the supervisor's exit-triggered pass must find no record — otherwise it
235
+ * observes "node gone, record still `joined`" and brings back a node the admin
236
+ * just removed. The tradeoff: a crash between the delete and the stop leaves a
237
+ * running child no record names, which `remove` on its id still reclaims (below).
238
+ *
239
+ * A handle no record names — `hosted-nodes.json` lost, or a handle an older
240
+ * build persisted — is removed the same way, so `/api/nodes` cannot list a node
241
+ * for good that nothing can end.
242
+ */
243
+ remove(id: string): Promise<void>;
244
+ private removeOrphanHandle;
245
+ /**
246
+ * Remove a node and start a fresh one waiting to be claimed, with a new secret and
247
+ * identity. For the case where someone else photographed the QR code and claimed the
248
+ * node first, and for an `error` node the admin wants to try again. An invitation node
249
+ * is replaced by one waiting to be claimed too: its invitation may be spent, and the
250
+ * admin can join with a fresh one instead.
251
+ */
252
+ reset(id: string): Promise<HostedNodeView>;
253
+ /**
254
+ * Mark records stuck in `spawning` past `ttlMs` as `error` and reclaim whatever
255
+ * the orchestrator can still find for them — the record is written before the
256
+ * child spawn starts, so a host crash/kill anywhere in that window (including
257
+ * mid-spawn) leaves nothing to advance it across a restart. Run once at
258
+ * startup and on a periodic sweep. Age is measured from `updatedAt`, which for
259
+ * a genuinely-stuck row equals `createdAt` — `joinLocked` never touches a
260
+ * `spawning` record again except to advance it out of this predicate.
261
+ * Best-effort per record: a failed reap is logged and the sweep continues.
262
+ * Returns the reaped ids.
263
+ */
264
+ reapStuckSpawning(ttlMs?: number): Promise<string[]>;
265
+ /**
266
+ * Terminalize a stuck-`spawning` record as `error` and reclaim any child the
267
+ * orchestrator can still find for it. Status is written FIRST (same ordering
268
+ * rule as {@link remove}): reclaiming fires `onStateChange`, and anything
269
+ * listening must already see a terminal record.
270
+ *
271
+ * NOTE: the stop only reaches a child the orchestrator has a handle for.
272
+ * `HostProcessOrchestrator.launchChild` spawns the process and persists the
273
+ * handle in the same synchronous step, so the only child this misses is one
274
+ * whose host died between the OS spawn and that write — an orphan *process*
275
+ * this reap terminalizes the record for but cannot kill (its ports stay held
276
+ * until a reboot). Its working directory is reclaimed by container name when
277
+ * no handle resolves, which also covers the far commoner case of a host that
278
+ * died before any child existed at all.
279
+ */
280
+ private reclaimStuckSpawning;
281
+ /** One node (secret stripped), or undefined when unknown. */
282
+ get(id: string): HostedNodeView | undefined;
283
+ /** Every node (secret stripped). */
284
+ list(): HostedNodeView[];
285
+ private requireNode;
286
+ /** Best-effort stop; logs but never throws (cleanup path). */
287
+ private safeStop;
288
+ /**
289
+ * Persist a failed respawn's attempt counters (none for an uncounted restart) —
290
+ * plus, when the spawn itself succeeded and it was the record write that failed,
291
+ * the new child's handles. Merged onto whatever is on disk now, never written
292
+ * wholesale: the caller's copy predates the orchestrator round-trip.
293
+ *
294
+ * `status` and `updatedAt` are deliberately untouched — the attempt did not succeed.
295
+ *
296
+ * Recording `spawned` is what keeps the record pointing at the child that
297
+ * actually exists: `createContainer` already dropped the handle the record
298
+ * previously named, so leaving the old `dockerId` there would send every later
299
+ * stop/reclaim at an id the orchestrator cannot resolve — stranding the node's
300
+ * workdir on disk forever.
301
+ *
302
+ * Best-effort: we are already unwinding a respawn failure, and a store error
303
+ * here must not mask it. Losing the write costs the caller one extra attempt
304
+ * before backoff; the supervisor's next pass re-reads the record, finds the
305
+ * named child not running, and respawns again — which drops whatever handle is
306
+ * current, so the ports self-heal either way.
307
+ */
308
+ private storeRespawnAttempt;
309
+ /** Best-effort remove; logs but never throws (cleanup path). */
310
+ private safeReclaim;
311
+ /**
312
+ * Best-effort removal of the working directory of a node whose spawn never
313
+ * produced a `dockerId`; logs but never throws (cleanup path). A no-op on an
314
+ * orchestrator without the capability, and on one that refuses because a live
315
+ * handle still owns the directory.
316
+ */
317
+ private safeReclaimWorkdir;
318
+ /** Run `fn` after any in-flight join. */
319
+ private serializeJoin;
320
+ /**
321
+ * Run `fn` after every respawn already queued. Every caller of {@link respawn} goes
322
+ * through here: the supervisor's reconcile passes and restarts, and {@link retry}.
323
+ */
324
+ serializeRespawns<T>(fn: () => Promise<T>): Promise<T>;
325
+ }