@nervur.org/installer-node 0.0.0-stage → 0.37.2

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 (364) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +159 -2
  3. package/SECURITY.md +8 -0
  4. package/bin/nervur.js +5 -0
  5. package/cargo/emscripten-module.wasm +0 -0
  6. package/cargo/manifest.json +1 -0
  7. package/cargo/sqlite3.wasm +0 -0
  8. package/cargo/table-i-i.wasm +0 -0
  9. package/cargo/table-i-ii.wasm +0 -0
  10. package/cargo/table-i-iii.wasm +0 -0
  11. package/cargo/table-i-iiii.wasm +0 -0
  12. package/cargo/table-i-iiiii.wasm +0 -0
  13. package/cargo/table-i-iiij.wasm +0 -0
  14. package/cargo/table-i-ij.wasm +0 -0
  15. package/cargo/table-v-ii.wasm +0 -0
  16. package/cargo/table-v-iii.wasm +0 -0
  17. package/cargo/worker.js +30808 -0
  18. package/organs/console/node/guard.d.ts +10 -0
  19. package/organs/console/node/guard.js +52 -0
  20. package/organs/console/node/index.d.ts +4 -0
  21. package/organs/console/node/index.js +5 -0
  22. package/organs/console/node/line.d.ts +16 -0
  23. package/organs/console/node/line.js +150 -0
  24. package/organs/console/node/main.js +51 -0
  25. package/organs/console/node/program.d.ts +1 -0
  26. package/organs/console/node/program.js +5 -0
  27. package/organs/console/node/proof.d.ts +15 -0
  28. package/organs/console/node/proof.js +84 -0
  29. package/organs/console/node/socket.d.ts +15 -0
  30. package/organs/console/node/socket.js +99 -0
  31. package/organs/disk/index.d.ts +1 -0
  32. package/organs/disk/index.js +2 -0
  33. package/organs/disk/node/files.js +162 -0
  34. package/organs/disk/node/main.js +20 -0
  35. package/organs/disk/node/program.d.ts +1 -0
  36. package/organs/disk/node/program.js +5 -0
  37. package/organs/disk/organ.d.ts +5 -0
  38. package/organs/disk/organ.js +69 -0
  39. package/organs/network/node/fill.d.ts +21 -0
  40. package/organs/network/node/fill.js +195 -0
  41. package/organs/network/node/flows.js +66 -0
  42. package/organs/network/node/half.js +260 -0
  43. package/organs/network/node/lines.d.ts +29 -0
  44. package/organs/network/node/lines.js +236 -0
  45. package/organs/network/node/link.d.ts +24 -0
  46. package/organs/network/node/link.js +215 -0
  47. package/organs/network/node/main.js +41 -0
  48. package/organs/network/node/moved.d.ts +2 -0
  49. package/organs/network/node/moved.js +20 -0
  50. package/organs/network/node/near.d.ts +63 -0
  51. package/organs/network/node/near.js +263 -0
  52. package/organs/network/node/program.d.ts +1 -0
  53. package/organs/network/node/program.js +5 -0
  54. package/organs/network/node/schemes.d.ts +1 -0
  55. package/organs/network/node/schemes.js +2 -0
  56. package/organs/network/node/sent.d.ts +13 -0
  57. package/organs/network/node/sent.js +101 -0
  58. package/organs/network/node/served.d.ts +19 -0
  59. package/organs/network/node/served.js +237 -0
  60. package/organs/screen/node/client.js +3 -0
  61. package/organs/screen/node/follow.js +266 -0
  62. package/organs/screen/node/frames.js +26 -0
  63. package/organs/screen/node/held.js +27 -0
  64. package/organs/screen/node/http.js +179 -0
  65. package/organs/screen/node/lay.js +116 -0
  66. package/organs/screen/node/leave.js +27 -0
  67. package/organs/screen/node/linked.js +69 -0
  68. package/organs/screen/node/listen.js +61 -0
  69. package/organs/screen/node/look.js +121 -0
  70. package/organs/screen/node/loop.js +154 -0
  71. package/organs/screen/node/main.js +74 -0
  72. package/organs/screen/node/mirror.js +112 -0
  73. package/organs/screen/node/notice.js +44 -0
  74. package/organs/screen/node/presser.js +11 -0
  75. package/organs/screen/node/presses.js +108 -0
  76. package/organs/screen/node/program.d.ts +1 -0
  77. package/organs/screen/node/program.js +5 -0
  78. package/organs/screen/node/shown.js +205 -0
  79. package/organs/screen/node/standing.js +29 -0
  80. package/organs/screen/node/state.js +80 -0
  81. package/organs/screen/node/tell.js +47 -0
  82. package/organs/screen/node/uid.js +65 -0
  83. package/organs/screen/node/worn.js +23 -0
  84. package/organs/shell/index.d.ts +1 -0
  85. package/organs/shell/index.js +2 -0
  86. package/organs/shell/node/main.js +26 -0
  87. package/organs/shell/node/output.js +70 -0
  88. package/organs/shell/node/pressure.js +14 -0
  89. package/organs/shell/node/program.d.ts +1 -0
  90. package/organs/shell/node/program.js +5 -0
  91. package/organs/shell/node/runs.js +220 -0
  92. package/organs/shell/node/told.js +70 -0
  93. package/organs/shell/organ.d.ts +5 -0
  94. package/organs/shell/organ.js +59 -0
  95. package/package.json +43 -4
  96. package/src/command/act.d.ts +31 -0
  97. package/src/command/act.js +261 -0
  98. package/src/command/answers.d.ts +3 -0
  99. package/src/command/answers.js +232 -0
  100. package/src/command/args.d.ts +14 -0
  101. package/src/command/args.js +220 -0
  102. package/src/command/arrive.d.ts +2 -0
  103. package/src/command/arrive.js +21 -0
  104. package/src/command/asked.d.ts +18 -0
  105. package/src/command/asked.js +49 -0
  106. package/src/command/backup.d.ts +18 -0
  107. package/src/command/backup.js +261 -0
  108. package/src/command/before.d.ts +40 -0
  109. package/src/command/before.js +249 -0
  110. package/src/command/born.d.ts +27 -0
  111. package/src/command/born.js +103 -0
  112. package/src/command/bridge.d.ts +19 -0
  113. package/src/command/bridge.js +152 -0
  114. package/src/command/chain.d.ts +9 -0
  115. package/src/command/chain.js +48 -0
  116. package/src/command/channel.d.ts +29 -0
  117. package/src/command/channel.js +263 -0
  118. package/src/command/choices.d.ts +35 -0
  119. package/src/command/choices.js +173 -0
  120. package/src/command/claim.d.ts +12 -0
  121. package/src/command/claim.js +46 -0
  122. package/src/command/commands.d.ts +16 -0
  123. package/src/command/commands.js +257 -0
  124. package/src/command/ends.d.ts +16 -0
  125. package/src/command/ends.js +78 -0
  126. package/src/command/follow.d.ts +12 -0
  127. package/src/command/follow.js +66 -0
  128. package/src/command/given.d.ts +39 -0
  129. package/src/command/given.js +53 -0
  130. package/src/command/held.d.ts +15 -0
  131. package/src/command/held.js +56 -0
  132. package/src/command/index.d.ts +1 -0
  133. package/src/command/index.js +203 -0
  134. package/src/command/jailer.d.ts +28 -0
  135. package/src/command/jailer.js +135 -0
  136. package/src/command/laid.d.ts +6 -0
  137. package/src/command/laid.js +31 -0
  138. package/src/command/left.d.ts +9 -0
  139. package/src/command/left.js +34 -0
  140. package/src/command/line.d.ts +7 -0
  141. package/src/command/line.js +39 -0
  142. package/src/command/link.d.ts +30 -0
  143. package/src/command/link.js +123 -0
  144. package/src/command/lobes.d.ts +1 -0
  145. package/src/command/lobes.js +10 -0
  146. package/src/command/locks.d.ts +17 -0
  147. package/src/command/locks.js +76 -0
  148. package/src/command/mcp/calls.d.ts +27 -0
  149. package/src/command/mcp/calls.js +155 -0
  150. package/src/command/mcp/notices.d.ts +22 -0
  151. package/src/command/mcp/notices.js +203 -0
  152. package/src/command/mcp/resources.d.ts +31 -0
  153. package/src/command/mcp/resources.js +108 -0
  154. package/src/command/mcp/server.d.ts +19 -0
  155. package/src/command/mcp/server.js +149 -0
  156. package/src/command/mcp/tools.d.ts +39 -0
  157. package/src/command/mcp/tools.js +131 -0
  158. package/src/command/mcp.d.ts +8 -0
  159. package/src/command/mcp.js +39 -0
  160. package/src/command/noticed.d.ts +11 -0
  161. package/src/command/noticed.js +55 -0
  162. package/src/command/older.d.ts +11 -0
  163. package/src/command/older.js +45 -0
  164. package/src/command/open.d.ts +24 -0
  165. package/src/command/open.js +107 -0
  166. package/src/command/passphrase.d.ts +6 -0
  167. package/src/command/passphrase.js +82 -0
  168. package/src/command/reclaim.d.ts +7 -0
  169. package/src/command/reclaim.js +47 -0
  170. package/src/command/refused.d.ts +4 -0
  171. package/src/command/refused.js +27 -0
  172. package/src/command/release.d.ts +27 -0
  173. package/src/command/release.js +153 -0
  174. package/src/command/repo.d.ts +31 -0
  175. package/src/command/repo.js +133 -0
  176. package/src/command/rewrap.d.ts +16 -0
  177. package/src/command/rewrap.js +175 -0
  178. package/src/command/runtime.d.ts +25 -0
  179. package/src/command/runtime.js +175 -0
  180. package/src/command/salvage.d.ts +4 -0
  181. package/src/command/salvage.js +42 -0
  182. package/src/command/screen.d.ts +14 -0
  183. package/src/command/screen.js +62 -0
  184. package/src/command/spawn.d.ts +23 -0
  185. package/src/command/spawn.js +213 -0
  186. package/src/command/start.d.ts +34 -0
  187. package/src/command/start.js +246 -0
  188. package/src/command/state.d.ts +5 -0
  189. package/src/command/state.js +39 -0
  190. package/src/command/token.d.ts +1 -0
  191. package/src/command/token.js +9 -0
  192. package/src/command/trial.d.ts +18 -0
  193. package/src/command/trial.js +108 -0
  194. package/src/command/undone.d.ts +3 -0
  195. package/src/command/undone.js +21 -0
  196. package/src/command/vouch.d.ts +1 -0
  197. package/src/command/vouch.js +15 -0
  198. package/src/command/windows-processes.d.ts +2 -0
  199. package/src/command/windows-processes.js +22 -0
  200. package/src/command/wipe.d.ts +9 -0
  201. package/src/command/wipe.js +105 -0
  202. package/src/command/words.d.ts +5 -0
  203. package/src/command/words.js +53 -0
  204. package/src/door/claim.d.ts +5 -0
  205. package/src/door/claim.js +21 -0
  206. package/src/door/claimed.d.ts +7 -0
  207. package/src/door/claimed.js +110 -0
  208. package/src/door/configuration.d.ts +40 -0
  209. package/src/door/configuration.js +206 -0
  210. package/src/door/design.d.ts +13 -0
  211. package/src/door/design.js +71 -0
  212. package/src/door/digests.d.ts +7 -0
  213. package/src/door/digests.js +36 -0
  214. package/src/door/distribution.d.ts +25 -0
  215. package/src/door/distribution.js +88 -0
  216. package/src/door/door.d.ts +41 -0
  217. package/src/door/door.js +219 -0
  218. package/src/door/dressed.d.ts +34 -0
  219. package/src/door/dressed.js +182 -0
  220. package/src/door/faculties.d.ts +29 -0
  221. package/src/door/faculties.js +88 -0
  222. package/src/door/longest.d.ts +6 -0
  223. package/src/door/longest.js +25 -0
  224. package/src/fills/account-only.d.ts +3 -0
  225. package/src/fills/account-only.js +24 -0
  226. package/src/fills/boot-key.d.ts +21 -0
  227. package/src/fills/boot-key.js +70 -0
  228. package/src/fills/boot-move.d.ts +25 -0
  229. package/src/fills/boot-move.js +86 -0
  230. package/src/fills/bridge.d.ts +13 -0
  231. package/src/fills/bridge.js +86 -0
  232. package/src/fills/chance.d.ts +2 -0
  233. package/src/fills/chance.js +7 -0
  234. package/src/fills/crypto.d.ts +2 -0
  235. package/src/fills/crypto.js +94 -0
  236. package/src/fills/flushed.d.ts +9 -0
  237. package/src/fills/flushed.js +80 -0
  238. package/src/fills/hardware.d.ts +18 -0
  239. package/src/fills/hardware.js +70 -0
  240. package/src/fills/held.d.ts +31 -0
  241. package/src/fills/held.js +171 -0
  242. package/src/fills/keepers.d.ts +23 -0
  243. package/src/fills/keepers.js +151 -0
  244. package/src/fills/keyring.d.ts +19 -0
  245. package/src/fills/keyring.js +131 -0
  246. package/src/fills/pages.d.ts +3 -0
  247. package/src/fills/pages.js +260 -0
  248. package/src/fills/reserve.d.ts +11 -0
  249. package/src/fills/reserve.js +72 -0
  250. package/src/fills/time.d.ts +2 -0
  251. package/src/fills/time.js +29 -0
  252. package/src/fills/unlocker.d.ts +6 -0
  253. package/src/fills/unlocker.js +26 -0
  254. package/src/fills/vitals.d.ts +8 -0
  255. package/src/fills/vitals.js +100 -0
  256. package/src/fills/windows-start.d.ts +2 -0
  257. package/src/fills/windows-start.js +21 -0
  258. package/src/halves/build.d.ts +10 -0
  259. package/src/halves/build.js +219 -0
  260. package/src/halves/end.d.ts +17 -0
  261. package/src/halves/end.js +157 -0
  262. package/src/halves/genome.d.ts +3 -0
  263. package/src/halves/genome.js +21 -0
  264. package/src/halves/handler.d.ts +8 -0
  265. package/src/halves/handler.js +40 -0
  266. package/src/halves/index.d.ts +5 -0
  267. package/src/halves/index.js +6 -0
  268. package/src/halves/laid.d.ts +12 -0
  269. package/src/halves/laid.js +103 -0
  270. package/src/halves/lent.d.ts +6 -0
  271. package/src/halves/lent.js +147 -0
  272. package/src/halves/native.d.ts +12 -0
  273. package/src/halves/native.js +53 -0
  274. package/src/halves/statements.d.ts +23 -0
  275. package/src/halves/statements.js +165 -0
  276. package/src/halves/tokens.d.ts +22 -0
  277. package/src/halves/tokens.js +135 -0
  278. package/src/link/link.d.ts +4 -0
  279. package/src/link/link.js +4 -0
  280. package/src/link/placeholder.d.ts +1 -0
  281. package/src/link/placeholder.js +21 -0
  282. package/src/link/steps.d.ts +52 -0
  283. package/src/link/steps.js +118 -0
  284. package/src/lobes/calls.d.ts +76 -0
  285. package/src/lobes/calls.js +61 -0
  286. package/src/lobes/channel.d.ts +76 -0
  287. package/src/lobes/channel.js +202 -0
  288. package/src/lobes/index.d.ts +1 -0
  289. package/src/lobes/index.js +2 -0
  290. package/src/lobes/lobes.d.ts +15 -0
  291. package/src/lobes/lobes.js +244 -0
  292. package/src/lobes/main.js +107 -0
  293. package/src/lobes/thread.d.ts +22 -0
  294. package/src/lobes/thread.js +270 -0
  295. package/src/organism/act.d.ts +8 -0
  296. package/src/organism/act.js +63 -0
  297. package/src/organism/beat.d.ts +5 -0
  298. package/src/organism/beat.js +45 -0
  299. package/src/organism/compiled.d.ts +2 -0
  300. package/src/organism/compiled.js +24 -0
  301. package/src/organism/folder.d.ts +88 -0
  302. package/src/organism/folder.js +259 -0
  303. package/src/organism/main.d.ts +1 -0
  304. package/src/organism/main.js +11 -0
  305. package/src/organism/organism.d.ts +1 -0
  306. package/src/organism/organism.js +220 -0
  307. package/src/organism/said.d.ts +12 -0
  308. package/src/organism/said.js +30 -0
  309. package/src/organism/told.d.ts +5 -0
  310. package/src/organism/told.js +110 -0
  311. package/src/organism/unlock.d.ts +8 -0
  312. package/src/organism/unlock.js +95 -0
  313. package/src/organism/upgrade.d.ts +24 -0
  314. package/src/organism/upgrade.js +145 -0
  315. package/src/organism/via.d.ts +7 -0
  316. package/src/organism/via.js +20 -0
  317. package/src/service/body.d.ts +8 -0
  318. package/src/service/body.js +34 -0
  319. package/src/service/handler.d.ts +20 -0
  320. package/src/service/handler.js +128 -0
  321. package/src/service/index.d.ts +4 -0
  322. package/src/service/index.js +16 -0
  323. package/src/service/manager.d.ts +18 -0
  324. package/src/service/manager.js +185 -0
  325. package/src/service/service.d.ts +24 -0
  326. package/src/service/service.js +200 -0
  327. package/src/service/swap.d.ts +12 -0
  328. package/src/service/swap.js +74 -0
  329. package/src/service/watchdog.d.ts +6 -0
  330. package/src/service/watchdog.js +31 -0
  331. package/src/tcp/crowd.d.ts +18 -0
  332. package/src/tcp/crowd.js +85 -0
  333. package/src/tcp/dial.d.ts +23 -0
  334. package/src/tcp/dial.js +102 -0
  335. package/src/tcp/frame.d.ts +23 -0
  336. package/src/tcp/frame.js +159 -0
  337. package/src/tcp/listen.d.ts +50 -0
  338. package/src/tcp/listen.js +207 -0
  339. package/src/tcp/source.d.ts +2 -0
  340. package/src/tcp/source.js +26 -0
  341. package/src/version/index.d.ts +1 -0
  342. package/src/version/index.js +2 -0
  343. package/src/version/version.d.ts +1 -0
  344. package/src/version/version.js +2 -0
  345. package/src/work/first.d.ts +11 -0
  346. package/src/work/first.js +91 -0
  347. package/src/work/index.d.ts +2 -0
  348. package/src/work/index.js +15 -0
  349. package/src/work/work.d.ts +20 -0
  350. package/src/work/work.js +136 -0
  351. package/src/ws/dial.d.ts +7 -0
  352. package/src/ws/dial.js +252 -0
  353. package/src/ws/dialing.d.ts +50 -0
  354. package/src/ws/dialing.js +72 -0
  355. package/src/ws/frame.d.ts +32 -0
  356. package/src/ws/frame.js +124 -0
  357. package/src/ws/handshake.d.ts +4 -0
  358. package/src/ws/handshake.js +27 -0
  359. package/src/ws/line.d.ts +45 -0
  360. package/src/ws/line.js +250 -0
  361. package/src/ws/listen.d.ts +42 -0
  362. package/src/ws/listen.js +272 -0
  363. package/src/ws/rfc6455.d.ts +18 -0
  364. package/src/ws/rfc6455.js +187 -0
@@ -0,0 +1,220 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { existsSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { flushCompileCache } from 'node:module';
4
+ import { dirname } from 'node:path';
5
+ import { fileUnlocker, readNextBootKey } from '../fills/boot-key.js';
6
+ import { nextFolderOf, nodeFiles, openedBeside } from '../fills/boot-move.js';
7
+
8
+ import { custodyOf, heldUnlocker, hostHands, humanEnds, } from '../fills/held.js';
9
+ import { presentUnlocker } from '../fills/unlocker.js';
10
+ import { configurationOf } from '../door/configuration.js';
11
+ import { openDoor } from '../door/door.js';
12
+ import { bodyOf } from '../service/body.js';
13
+ import { laidService } from '../service/manager.js';
14
+ import { toldAlive, watchdogOf } from '../service/watchdog.js';
15
+ import { MOVED } from '@nervur.org/genome';
16
+ import { INSTALLER_VERSION, pidOf, ranOn, readFolder, stoppedOf, stoppedSaid, versionOf } from './folder.js';
17
+ import { listenAct } from './act.js';
18
+ import { beginBeat, endBeat } from './beat.js';
19
+ import { lineOf, STOPPED, } from './said.js';
20
+ import { keyAtSocket } from './unlock.js';
21
+ import { checking, upgradeOf } from './upgrade.js';
22
+ import { actLives, beforeOf, bootOf, floorOf, stayOf, wentBack } from '../command/before.js';
23
+ import { leftAt, leftOf } from '../command/undone.js';
24
+ import { prunedBeside } from '../command/laid.js';
25
+
26
+ const KEY = 32;
27
+
28
+ process.stdout.on('error', () => undefined);
29
+ const say = (said ) => {
30
+ endBeat();
31
+ flushCompileCache();
32
+ process.stdout.write(lineOf(said));
33
+ };
34
+
35
+ const keyFromPipe = () =>
36
+ new Promise((done) => {
37
+ let held = new Uint8Array(0);
38
+ process.stdin.on('data', (chunk ) => {
39
+ held = Uint8Array.from([...held, ...chunk]);
40
+ if (held.length >= KEY) {
41
+ process.stdin.destroy();
42
+ done(held.slice(0, KEY));
43
+ }
44
+ });
45
+ process.stdin.on('end', () => done(null));
46
+ });
47
+
48
+ const watchdog = watchdogOf(process.env, process.pid);
49
+ if (watchdog !== null) {
50
+ const path = process.env['PATH'] ?? '/usr/bin:/bin';
51
+ toldAlive(watchdog, path);
52
+ setInterval(() => toldAlive(watchdog, path), watchdog.every).unref();
53
+ }
54
+
55
+ const [home, kind, atBoot] = process.argv.slice(2);
56
+ const folder = home === undefined ? null : readFolder(home);
57
+ if (
58
+ home === undefined ||
59
+ folder === null ||
60
+ 'why' in folder ||
61
+ (kind !== 'first-install' && kind !== 'boot') ||
62
+ (atBoot !== undefined && atBoot !== '--at-boot' && atBoot !== '--trial')
63
+ ) {
64
+ say({
65
+ why:
66
+ folder !== null && 'why' in folder
67
+ ? folder.why
68
+ : 'the organism is started with its folder and its init, and --at-boot by its service',
69
+ });
70
+ process.exit(1);
71
+ }
72
+
73
+ if (existsSync(stoppedOf(home))) {
74
+ console.error(stoppedSaid(home));
75
+ say({ why: stoppedSaid(home) });
76
+ process.exit(0);
77
+ }
78
+ const trial = atBoot === '--trial';
79
+ const actRuns = actLives(dirname(home));
80
+ const went = !trial && kind === 'boot' && !actRuns ? wentBack(home) : null;
81
+ if (went?.why !== undefined) console.error(went.why);
82
+ if (went?.package === true) {
83
+ console.error('an update was cut: the old package and the store went back');
84
+ say({ why: 'an update was cut: the old package and the store went back; start it again' });
85
+ process.exit(STOPPED);
86
+ }
87
+ const stoppedHere = () => {
88
+ if (existsSync(beforeOf(home))) return;
89
+ writeFileSync(stoppedOf(home), `${stoppedSaid(home)}\n`, { mode: 0o600 });
90
+ console.error(stoppedSaid(home));
91
+ };
92
+
93
+ const update = kind === 'boot' && (ranOn(home) !== INSTALLER_VERSION || existsSync(leftOf(home)));
94
+
95
+ const refusals = [];
96
+ const hands = hostHands();
97
+ const service = atBoot === '--at-boot' ? laidService(home) : null;
98
+ const body = bodyOf(service);
99
+ if (service?.body !== undefined && body === null)
100
+ console.error("the body runs unbounded: systemd-run found no slice of this account's manager that bounds its memory");
101
+ const ending = Promise.withResolvers ();
102
+ const openWith = (opening , laid = folder.laid) =>
103
+ openDoor({
104
+ home,
105
+ ...(body === null ? {} : { body }),
106
+ init: kind === 'boot' ? { ...bootOf(home, trial), ...(update ? { update: true } : {}) } : { kind },
107
+ unlocker: opening,
108
+ ...(laid.reserve === undefined ? {} : { reserve: laid.reserve }),
109
+ configuration: configurationOf(laid, home),
110
+ ...(laid.claim === undefined ? {} : { claim: laid.claim }),
111
+ stopped: (why) => {
112
+ console.error(`the organism stopped itself: ${why}`);
113
+ if (why === MOVED) stoppedHere();
114
+ ending.resolve(why === MOVED ? 0 : STOPPED);
115
+ },
116
+ upgrade: upgradeOf(home),
117
+ });
118
+ const humanWaited = async () =>
119
+ humanEnds(folder.laid) && folder.laid.bootMode !== 'remote' && atBoot === '--at-boot' ? keyAtSocket(home) : null;
120
+ let waited = null;
121
+ const answering = async (why ) => {
122
+ if (waited !== null && !('why' in waited)) await waited.answered(why);
123
+ };
124
+ const openHeld = async (laid ) => {
125
+ const custody = custodyOf(home, laid, hands);
126
+ if (humanEnds(laid)) {
127
+ const given = await humanOrKeepers(custody);
128
+ if (given !== null)
129
+ return openWith(
130
+ presentUnlocker(() => Promise.resolve(given)),
131
+ laid,
132
+ );
133
+ }
134
+ return openWith(
135
+ heldUnlocker(home, laid, hands, (why) => refusals.push(why)),
136
+ laid,
137
+ );
138
+ };
139
+ const humanOrKeepers = async (custody ) => {
140
+ if (atBoot !== '--at-boot') return keyFromPipe();
141
+ const heard = await custody.open();
142
+ if (heard !== null && 'key' in heard) return heard.key;
143
+ waited = await keyAtSocket(home);
144
+ if ('why' in waited) {
145
+ refusals.push(waited.why);
146
+ return null;
147
+ }
148
+ return waited.key;
149
+ };
150
+ const plain = async () => {
151
+ waited = await humanWaited();
152
+ if (waited !== null && 'why' in waited) return waited;
153
+ const { key } = waited ?? { key: null };
154
+ if (folder.laid.bootMode === 'file') return openWith(fileUnlocker(home, (why) => refusals.push(why)));
155
+ if (folder.laid.bootMode !== 'present') return openHeld(folder.laid);
156
+ return openWith(presentUnlocker(key === null ? keyFromPipe : () => Promise.resolve(key)));
157
+ };
158
+ const beside = kind === 'boot' ? readNextBootKey(home) : null;
159
+ const moving = readFolder(home, nextFolderOf(home));
160
+ const laid = 'laid' in moving ? moving.laid : folder.laid;
161
+ const opened = await openedBeside(
162
+ nodeFiles,
163
+ home,
164
+ beside !== null && 'key' in beside ? beside.key : null,
165
+ laid.bootMode === 'file' ? 'file' : 'present',
166
+ (key) =>
167
+ openWith(
168
+ presentUnlocker(() => Promise.resolve(key)),
169
+ laid,
170
+ ),
171
+ plain,
172
+ laid.bootMode === 'file' || laid.bootMode === 'present'
173
+ ? undefined
174
+ : (next) => custodyOf(home, laid, hands).keep(next),
175
+ );
176
+ if ('why' in opened) {
177
+ if (opened.why.includes(MOVED)) stoppedHere();
178
+ const why = refusals[0] ?? opened.why;
179
+ await answering(why);
180
+ say({ why });
181
+ process.exit(1);
182
+ }
183
+ const living = setInterval(() => undefined, 2 ** 31 - 1);
184
+ let acting = null;
185
+ void ending.promise.then(async (code) => {
186
+ clearInterval(living);
187
+ beginBeat(home, null);
188
+ await acting?.close();
189
+ await opened.door.stop();
190
+ flushCompileCache();
191
+ rmSync(pidOf(home), { force: true });
192
+ endBeat();
193
+ console.error(code === 0 ? 'the organism stopped' : `the organism's process ends with ${code}`);
194
+ process.exit(code);
195
+ });
196
+ process.on('SIGTERM', () => ending.resolve(0));
197
+ process.on('SIGINT', () => ending.resolve(0));
198
+
199
+ const failed = trial ? null : await Promise.race([opened.door.reached.then(() => null), opened.door.failed]);
200
+ if (failed !== null) {
201
+ await opened.door.stop();
202
+ say({ why: `the organism listens nowhere: ${failed}` });
203
+ process.exit(1);
204
+ }
205
+ rmSync(stayOf(home), { force: true });
206
+ rmSync(floorOf(home), { force: true });
207
+ if (update) leftAt(home, opened.shipped.refused);
208
+ const pruned = trial || actRuns ? [] : prunedBeside(home, laid, opened.halves);
209
+ if (pruned.length > 0) console.error(`the halves no organ names removed: ${pruned.join(', ')}`);
210
+ if (!trial) {
211
+ const listening = await listenAct(home, opened.door);
212
+ if ('why' in listening) console.error(`the organism hears no move: ${listening.why}`);
213
+ else acting = listening;
214
+ }
215
+ writeFileSync(pidOf(home), String(process.pid), { mode: 0o600 });
216
+ writeFileSync(versionOf(home), `${INSTALLER_VERSION}\n`, { mode: 0o600 });
217
+ await answering(null);
218
+ say({ started: true, ...opened.shipped });
219
+ console.error(`the organism started, ${kind}, process ${process.pid}`);
220
+ if (!trial) checking(home);
@@ -0,0 +1,12 @@
1
+ export type Moves = {
2
+ readonly moved: readonly string[];
3
+ readonly refused: readonly string[];
4
+ };
5
+ export type Said = ({
6
+ readonly started: true;
7
+ } & Moves) | {
8
+ readonly why: string;
9
+ };
10
+ export declare const lineOf: (said: Said) => string;
11
+ export declare const saidOf: (line: string) => Said | null;
12
+ export declare const STOPPED = 75;
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+
3
+
4
+
5
+
6
+
7
+ export const lineOf = (said ) => `${JSON.stringify(said)}\n`;
8
+
9
+ const textsIn = (list ) =>
10
+ Array.isArray(list) ? list.filter((one) => typeof one === 'string') : [];
11
+
12
+ export const saidOf = (line ) => {
13
+ let value ;
14
+ try {
15
+ value = JSON.parse(line);
16
+ } catch {
17
+ return null;
18
+ }
19
+ if (typeof value !== 'object' || value === null) return null;
20
+ if ('started' in value && value.started === true)
21
+ return {
22
+ started: true,
23
+ moved: textsIn('moved' in value ? value.moved : null),
24
+ refused: textsIn('refused' in value ? value.refused : null),
25
+ };
26
+ if ('why' in value && typeof value.why === 'string') return { why: value.why };
27
+ return null;
28
+ };
29
+
30
+ export const STOPPED = 75;
@@ -0,0 +1,5 @@
1
+ export type Beating = {
2
+ readonly of: () => string | null;
3
+ readonly quiet: number;
4
+ };
5
+ export declare const toldAt: <T>(path: string, look: () => T | null | Promise<T | null>, within: number, beat?: Beating) => Promise<T | null>;
@@ -0,0 +1,110 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { randomBytes } from 'node:crypto';
3
+ import { rmSync, watch, writeFileSync, } from 'node:fs';
4
+ import { dirname } from 'node:path';
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+ const looked = async (waiting ) => {
16
+ if (waiting.ended) return;
17
+ if (waiting.looking) {
18
+ waiting.again = true;
19
+ return;
20
+ }
21
+ waiting.looking = true;
22
+ for (;;) {
23
+ waiting.again = false;
24
+ const last = waiting.bounded;
25
+ const found = await waiting.look();
26
+ if (found !== null || last) {
27
+ waiting.looking = false;
28
+ waiting.end(found);
29
+ return;
30
+ }
31
+ if (!waiting.again || waiting.ended) break;
32
+ }
33
+ waiting.looking = false;
34
+ };
35
+
36
+ const MARKS = 5000;
37
+
38
+ const marked = (mark ) => {
39
+ try {
40
+ writeFileSync(mark, '');
41
+ return true;
42
+ } catch {
43
+ return false;
44
+ }
45
+ };
46
+
47
+
48
+
49
+ const spanOf = (beat , within , silent ) => {
50
+ let timer = setTimeout(silent, within);
51
+ let heard = beat?.of() ?? null;
52
+ return {
53
+ stop: () => clearTimeout(timer),
54
+ told: (bounded ) => {
55
+ const now = beat?.of() ?? null;
56
+ if (beat !== undefined && now !== heard && !bounded) {
57
+ clearTimeout(timer);
58
+ timer = setTimeout(silent, beat.quiet);
59
+ }
60
+ heard = now;
61
+ },
62
+ };
63
+ };
64
+
65
+ export const toldAt = (
66
+ path ,
67
+ look ,
68
+ within ,
69
+ beat ,
70
+ ) =>
71
+ new Promise((done) => {
72
+ let watcher = null;
73
+ const mark = `${path}.${process.pid}.${randomBytes(4).toString('hex')}`;
74
+ let told = false;
75
+ const laying = (left ) => {
76
+ if (!told && !waiting.ended && left > 0 && marked(mark)) setImmediate(laying, left - 1);
77
+ };
78
+ const waiting = {
79
+ ended: false,
80
+ looking: false,
81
+ again: false,
82
+ bounded: false,
83
+ look,
84
+ end: (found) => {
85
+ waiting.ended = true;
86
+ span.stop();
87
+ watcher?.close();
88
+ rmSync(mark, { force: true });
89
+ done(found);
90
+ },
91
+ };
92
+ const silent = () => {
93
+ waiting.bounded = true;
94
+ void looked(waiting);
95
+ };
96
+ const span = spanOf(beat, within, silent);
97
+ try {
98
+ watcher = watch(dirname(path), () => {
99
+ told = true;
100
+ if (!waiting.ended) span.told(waiting.bounded);
101
+ void looked(waiting);
102
+ });
103
+ watcher.on('error', silent);
104
+ laying(MARKS);
105
+ } catch {
106
+ silent();
107
+ return;
108
+ }
109
+ void looked(waiting);
110
+ });
@@ -0,0 +1,8 @@
1
+ export declare const unlockOf: (home: string) => string;
2
+ export type Given = {
3
+ readonly key: Uint8Array;
4
+ readonly answered: (why: string | null) => Promise<void>;
5
+ };
6
+ export declare const keyAtSocket: (home: string, quiet?: number) => Promise<Given | {
7
+ readonly why: string;
8
+ }>;
@@ -0,0 +1,95 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { chmodSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { createServer, } from 'node:net';
4
+ import { join } from 'node:path';
5
+ import { dataText, error, readText, result, unhex, } from '@nervur.org/genome/standard';
6
+ import {
7
+ provingFirst,
8
+ clearedSocket,
9
+ pipeForListen,
10
+ reachedByAnother,
11
+ socketTooLong,
12
+ toldOf,
13
+ } from '../../organs/console/node/index.js';
14
+ import { BEAT, LONGEST_TIMEOUT } from '../door/longest.js';
15
+
16
+ const KEY = 32;
17
+ const LONGEST = 1024;
18
+
19
+ export const unlockOf = (home ) => join(home, 'unlock.sock');
20
+
21
+
22
+
23
+
24
+
25
+
26
+ const keyIn = (line ) => {
27
+ const read = readText(line);
28
+ const words = 'data' in read ? read.data : null;
29
+ const [word] = Array.isArray(words) && words.length === 1 ? words : [];
30
+ const key = typeof word === 'string' && word.length === KEY * 2 ? unhex(word) : null;
31
+ return key === null || 'why' in key ? null : key.bytes;
32
+ };
33
+
34
+ const written = (socket , answer ) =>
35
+ new Promise((done) => {
36
+ socket.end(`${dataText(answer)}\n`, () => done());
37
+ });
38
+
39
+ const served = (take , quiet ) => (socket ) => {
40
+ let held = '';
41
+ socket.setEncoding('utf8');
42
+ socket.on('error', () => socket.destroy());
43
+ socket.setTimeout(quiet, () => socket.destroy());
44
+ socket.on('data', (chunk ) => {
45
+ held += chunk;
46
+ const at = held.indexOf('\n');
47
+ if (at === -1 && held.length <= LONGEST) return;
48
+ socket.removeAllListeners('data');
49
+ socket.setTimeout(0);
50
+ const key = at === -1 ? null : keyIn(held.slice(0, at));
51
+ if (key === null || !take(key, socket))
52
+ void written(socket, error('refused', 'the organism waits for one key, as hex'));
53
+ });
54
+ };
55
+
56
+ export const keyAtSocket = (home , quiet = LONGEST_TIMEOUT) => {
57
+ const path = unlockOf(home);
58
+ const why = socketTooLong(path) ?? reachedByAnother(home) ?? clearedSocket(path);
59
+ if (why !== null) return Promise.resolve({ why });
60
+ const given = Promise.withResolvers ();
61
+ const taken = new Set ();
62
+ const pipe = pipeForListen();
63
+ const server = createServer(
64
+ provingFirst(
65
+ pipe?.secret ?? null,
66
+ served((key, socket) => {
67
+ if (taken.size > 0) return false;
68
+ taken.add(socket);
69
+ const beating = setInterval(() => socket.write('\n'), BEAT);
70
+ beating.unref();
71
+ socket.on('close', () => clearInterval(beating));
72
+ given.resolve({
73
+ key,
74
+ answered: async (failed) => {
75
+ clearInterval(beating);
76
+ server.close();
77
+ rmSync(path, { force: true });
78
+ await written(socket, failed === null ? result(null) : error('refused', failed));
79
+ },
80
+ });
81
+ return true;
82
+ }, quiet),
83
+ ),
84
+ );
85
+ return new Promise((done) => {
86
+ server.once('error', (failed) =>
87
+ done({ why: `the organism cannot wait for its key at ${path}: ${failed.message}` }),
88
+ );
89
+ server.listen(pipe?.at ?? path, () => {
90
+ if (pipe !== null) writeFileSync(path, toldOf(pipe));
91
+ else chmodSync(path, 0o600);
92
+ done(given.promise);
93
+ });
94
+ });
95
+ };
@@ -0,0 +1,24 @@
1
+ import type { PureStart } from '@nervur.org/genome/seams';
2
+ import { commandScript, digestOn, viewed } from '../command/channel.js';
3
+ import { channelKept } from './via.js';
4
+ type Upgrade = NonNullable<PureStart['upgrade']>;
5
+ export type Reaches = {
6
+ readonly view: typeof viewed;
7
+ readonly digest: typeof digestOn;
8
+ readonly command: typeof commandScript;
9
+ readonly start: (script: string, args: readonly string[], log: string) => void;
10
+ };
11
+ export declare const apartOf: (env: NodeJS.ProcessEnv, program: readonly [string, ...string[]], args: readonly string[], log: string) => readonly [string, ...string[]];
12
+ export declare const startApart: (env: NodeJS.ProcessEnv, started: readonly [string, ...string[]], args: readonly string[], log: string) => void;
13
+ export declare const actWords: (home: string, version: string, digest: string | null, channel: string | null) => readonly string[];
14
+ export declare const upgradeOf: (home: string, reaches?: Reaches) => Upgrade;
15
+ export declare const CHECK_EVERY = 3600000;
16
+ export type Checks = Pick<Reaches, 'view' | 'command' | 'start'> & {
17
+ readonly kept: typeof channelKept;
18
+ readonly busy: (home: string) => boolean;
19
+ readonly installer: string;
20
+ readonly every: (ms: number, run: () => void) => void;
21
+ readonly said: (line: string) => void;
22
+ };
23
+ export declare const checking: (home: string, reaches?: Checks) => void;
24
+ export {};
@@ -0,0 +1,145 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { spawn } from 'node:child_process';
3
+ import { appendFileSync, openSync } from 'node:fs';
4
+ import { dirname, resolve } from 'node:path';
5
+
6
+ import { commandScript, digestOn, viewed } from '../command/channel.js';
7
+ import { actLives } from '../command/before.js';
8
+ import { isOlder } from '../command/lobes.js';
9
+ import { INSTALLER_VERSION, logOf, ownHome } from './folder.js';
10
+ import { channelKept } from './via.js';
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+ export const apartOf = (
23
+ env ,
24
+ program ,
25
+ args ,
26
+ log ,
27
+ ) =>
28
+ env['INVOCATION_ID'] === undefined
29
+ ? [...program, ...args]
30
+ : [
31
+ 'systemd-run',
32
+ '--user',
33
+ '--collect',
34
+ '--quiet',
35
+ `--setenv=PATH=${env['PATH'] ?? ''}`,
36
+ `--property=StandardOutput=append:${log}`,
37
+ `--property=StandardError=append:${log}`,
38
+ ...program,
39
+ ...args,
40
+ ];
41
+
42
+ export const startApart = (
43
+ env ,
44
+ started ,
45
+ args ,
46
+ log ,
47
+ ) => {
48
+ const out = openSync(log, 'a');
49
+ const said = (why ) => appendFileSync(log, `the upgrade did not start: ${why}\n`);
50
+ const [program, ...words] = apartOf(env, started, args, log);
51
+ const child = spawn(program, words, { detached: true, stdio: ['ignore', out, out] });
52
+ child.on('error', (error) => said(error.message));
53
+ child.on('exit', (code) => {
54
+ if (code !== 0 && code !== null) said(`${program} ended ${code}`);
55
+ });
56
+ child.unref();
57
+ };
58
+
59
+ const REAL = {
60
+ view: viewed,
61
+ digest: digestOn,
62
+ command: commandScript,
63
+ start: (script, args, log) => startApart(process.env, [process.execPath, script], args, log),
64
+ };
65
+
66
+ export const actWords = (
67
+ home ,
68
+ version ,
69
+ digest ,
70
+ channel ,
71
+ ) => [
72
+ 'update',
73
+ version,
74
+ ...(digest === null ? [] : [digest]),
75
+ ...(channel === null ? [] : ['--channel', channel]),
76
+ ...(resolve(dirname(home)) === ownHome() ? [] : ['--home', dirname(home), '--take']),
77
+ ];
78
+
79
+ export const upgradeOf =
80
+ (home , reaches = REAL) =>
81
+ async ({ version, digest, channel }) => {
82
+ const on = channel ?? null;
83
+ const found = await reaches.view(`nervur@${version}`, on);
84
+ if ('why' in found) return found;
85
+ const held = await reaches.digest(version, on);
86
+ if (typeof held !== 'string') return held;
87
+ if (held !== digest) return { why: `nervur@${version} on its channel is ${held}, where ${digest} was named` };
88
+ const bin = await reaches.command();
89
+ if (typeof bin !== 'string') return bin;
90
+ return {
91
+ version: found.installer,
92
+ restart: () => reaches.start(bin, actWords(home, found.version, digest, on), logOf(home)),
93
+ };
94
+ };
95
+
96
+ export const CHECK_EVERY = 3_600_000;
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ const REAL_CHECKS = {
111
+ view: viewed,
112
+ command: commandScript,
113
+ start: REAL.start,
114
+ kept: channelKept,
115
+ busy: actLives,
116
+ installer: INSTALLER_VERSION,
117
+ every: (ms, run) => {
118
+ run();
119
+ setInterval(run, ms).unref();
120
+ },
121
+ said: (line) => console.error(line),
122
+ };
123
+
124
+ const looked = async (home , reaches ) => {
125
+ const kept = reaches.kept(home);
126
+ if (kept === null || reaches.busy(home)) return;
127
+ const found = await reaches.view('nervur@latest', kept.channel);
128
+ if ('why' in found) return reaches.said(`the organism asked its channel for a newer version and heard: ${found.why}`);
129
+ if (!isOlder(reaches.installer, found.installer)) return;
130
+ const bin = await reaches.command();
131
+ if (typeof bin !== 'string') return reaches.said(`the organism did not update to ${found.version}: ${bin.why}`);
132
+ reaches.said(
133
+ `nervur@${found.version} carries installer-node ${found.installer}, newer than ${reaches.installer}: the organism updates itself`,
134
+ );
135
+ reaches.start(bin, actWords(home, found.version, null, kept.channel), logOf(home));
136
+ };
137
+
138
+ export const checking = (home , reaches = REAL_CHECKS) =>
139
+ reaches.every(CHECK_EVERY, () => {
140
+ looked(home, reaches).catch((thrown ) =>
141
+ reaches.said(
142
+ `the organism's check of its channel failed: ${thrown instanceof Error ? thrown.message : String(thrown)}`,
143
+ ),
144
+ );
145
+ });
@@ -0,0 +1,7 @@
1
+ export declare const channelFileOf: (home: string) => string;
2
+ export declare const channelKept: (home: string) => {
3
+ readonly channel: string | null;
4
+ } | null;
5
+ export declare const keepChannel: (home: string, channel: false | {
6
+ readonly named: string | null;
7
+ }) => void;
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { readFileSync, rmSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { laidWhole } from '../fills/flushed.js';
5
+
6
+ export const channelFileOf = (home ) => join(home, 'organism.channel');
7
+
8
+ export const channelKept = (home ) => {
9
+ try {
10
+ const named = readFileSync(channelFileOf(home), 'utf8').trim();
11
+ return { channel: named === '' ? null : named };
12
+ } catch {
13
+ return null;
14
+ }
15
+ };
16
+
17
+ export const keepChannel = (home , channel ) => {
18
+ if (channel === false) rmSync(channelFileOf(home), { force: true });
19
+ else laidWhole(channelFileOf(home), channel.named === null ? '' : `${channel.named}\n`, 0o600);
20
+ };