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

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 (362) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +158 -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 +30756 -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 +256 -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 +41 -0
  109. package/src/command/before.js +237 -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 +17 -0
  193. package/src/command/trial.js +92 -0
  194. package/src/command/vouch.d.ts +1 -0
  195. package/src/command/vouch.js +15 -0
  196. package/src/command/windows-processes.d.ts +2 -0
  197. package/src/command/windows-processes.js +22 -0
  198. package/src/command/wipe.d.ts +9 -0
  199. package/src/command/wipe.js +105 -0
  200. package/src/command/words.d.ts +5 -0
  201. package/src/command/words.js +53 -0
  202. package/src/door/claim.d.ts +5 -0
  203. package/src/door/claim.js +21 -0
  204. package/src/door/claimed.d.ts +7 -0
  205. package/src/door/claimed.js +110 -0
  206. package/src/door/configuration.d.ts +40 -0
  207. package/src/door/configuration.js +206 -0
  208. package/src/door/design.d.ts +13 -0
  209. package/src/door/design.js +71 -0
  210. package/src/door/digests.d.ts +7 -0
  211. package/src/door/digests.js +36 -0
  212. package/src/door/distribution.d.ts +25 -0
  213. package/src/door/distribution.js +88 -0
  214. package/src/door/door.d.ts +41 -0
  215. package/src/door/door.js +219 -0
  216. package/src/door/dressed.d.ts +34 -0
  217. package/src/door/dressed.js +182 -0
  218. package/src/door/faculties.d.ts +29 -0
  219. package/src/door/faculties.js +88 -0
  220. package/src/door/longest.d.ts +6 -0
  221. package/src/door/longest.js +25 -0
  222. package/src/fills/account-only.d.ts +3 -0
  223. package/src/fills/account-only.js +24 -0
  224. package/src/fills/boot-key.d.ts +21 -0
  225. package/src/fills/boot-key.js +70 -0
  226. package/src/fills/boot-move.d.ts +25 -0
  227. package/src/fills/boot-move.js +86 -0
  228. package/src/fills/bridge.d.ts +13 -0
  229. package/src/fills/bridge.js +86 -0
  230. package/src/fills/chance.d.ts +2 -0
  231. package/src/fills/chance.js +7 -0
  232. package/src/fills/crypto.d.ts +2 -0
  233. package/src/fills/crypto.js +94 -0
  234. package/src/fills/flushed.d.ts +9 -0
  235. package/src/fills/flushed.js +80 -0
  236. package/src/fills/hardware.d.ts +18 -0
  237. package/src/fills/hardware.js +70 -0
  238. package/src/fills/held.d.ts +31 -0
  239. package/src/fills/held.js +171 -0
  240. package/src/fills/keepers.d.ts +23 -0
  241. package/src/fills/keepers.js +151 -0
  242. package/src/fills/keyring.d.ts +19 -0
  243. package/src/fills/keyring.js +131 -0
  244. package/src/fills/pages.d.ts +3 -0
  245. package/src/fills/pages.js +260 -0
  246. package/src/fills/reserve.d.ts +11 -0
  247. package/src/fills/reserve.js +72 -0
  248. package/src/fills/time.d.ts +2 -0
  249. package/src/fills/time.js +29 -0
  250. package/src/fills/unlocker.d.ts +6 -0
  251. package/src/fills/unlocker.js +26 -0
  252. package/src/fills/vitals.d.ts +8 -0
  253. package/src/fills/vitals.js +100 -0
  254. package/src/fills/windows-start.d.ts +2 -0
  255. package/src/fills/windows-start.js +21 -0
  256. package/src/halves/build.d.ts +10 -0
  257. package/src/halves/build.js +219 -0
  258. package/src/halves/end.d.ts +17 -0
  259. package/src/halves/end.js +157 -0
  260. package/src/halves/genome.d.ts +3 -0
  261. package/src/halves/genome.js +21 -0
  262. package/src/halves/handler.d.ts +8 -0
  263. package/src/halves/handler.js +40 -0
  264. package/src/halves/index.d.ts +5 -0
  265. package/src/halves/index.js +6 -0
  266. package/src/halves/laid.d.ts +12 -0
  267. package/src/halves/laid.js +103 -0
  268. package/src/halves/lent.d.ts +6 -0
  269. package/src/halves/lent.js +147 -0
  270. package/src/halves/native.d.ts +12 -0
  271. package/src/halves/native.js +53 -0
  272. package/src/halves/statements.d.ts +23 -0
  273. package/src/halves/statements.js +165 -0
  274. package/src/halves/tokens.d.ts +22 -0
  275. package/src/halves/tokens.js +135 -0
  276. package/src/link/link.d.ts +4 -0
  277. package/src/link/link.js +4 -0
  278. package/src/link/placeholder.d.ts +1 -0
  279. package/src/link/placeholder.js +21 -0
  280. package/src/link/steps.d.ts +52 -0
  281. package/src/link/steps.js +118 -0
  282. package/src/lobes/calls.d.ts +76 -0
  283. package/src/lobes/calls.js +61 -0
  284. package/src/lobes/channel.d.ts +76 -0
  285. package/src/lobes/channel.js +202 -0
  286. package/src/lobes/index.d.ts +1 -0
  287. package/src/lobes/index.js +2 -0
  288. package/src/lobes/lobes.d.ts +15 -0
  289. package/src/lobes/lobes.js +244 -0
  290. package/src/lobes/main.js +107 -0
  291. package/src/lobes/thread.d.ts +22 -0
  292. package/src/lobes/thread.js +270 -0
  293. package/src/organism/act.d.ts +8 -0
  294. package/src/organism/act.js +63 -0
  295. package/src/organism/beat.d.ts +5 -0
  296. package/src/organism/beat.js +45 -0
  297. package/src/organism/compiled.d.ts +2 -0
  298. package/src/organism/compiled.js +24 -0
  299. package/src/organism/folder.d.ts +88 -0
  300. package/src/organism/folder.js +259 -0
  301. package/src/organism/main.d.ts +1 -0
  302. package/src/organism/main.js +11 -0
  303. package/src/organism/organism.d.ts +1 -0
  304. package/src/organism/organism.js +219 -0
  305. package/src/organism/said.d.ts +12 -0
  306. package/src/organism/said.js +30 -0
  307. package/src/organism/told.d.ts +5 -0
  308. package/src/organism/told.js +110 -0
  309. package/src/organism/unlock.d.ts +8 -0
  310. package/src/organism/unlock.js +95 -0
  311. package/src/organism/upgrade.d.ts +24 -0
  312. package/src/organism/upgrade.js +145 -0
  313. package/src/organism/via.d.ts +7 -0
  314. package/src/organism/via.js +20 -0
  315. package/src/service/body.d.ts +8 -0
  316. package/src/service/body.js +34 -0
  317. package/src/service/handler.d.ts +20 -0
  318. package/src/service/handler.js +128 -0
  319. package/src/service/index.d.ts +4 -0
  320. package/src/service/index.js +16 -0
  321. package/src/service/manager.d.ts +18 -0
  322. package/src/service/manager.js +185 -0
  323. package/src/service/service.d.ts +24 -0
  324. package/src/service/service.js +200 -0
  325. package/src/service/swap.d.ts +12 -0
  326. package/src/service/swap.js +74 -0
  327. package/src/service/watchdog.d.ts +6 -0
  328. package/src/service/watchdog.js +31 -0
  329. package/src/tcp/crowd.d.ts +18 -0
  330. package/src/tcp/crowd.js +85 -0
  331. package/src/tcp/dial.d.ts +23 -0
  332. package/src/tcp/dial.js +102 -0
  333. package/src/tcp/frame.d.ts +23 -0
  334. package/src/tcp/frame.js +159 -0
  335. package/src/tcp/listen.d.ts +50 -0
  336. package/src/tcp/listen.js +207 -0
  337. package/src/tcp/source.d.ts +2 -0
  338. package/src/tcp/source.js +26 -0
  339. package/src/version/index.d.ts +1 -0
  340. package/src/version/index.js +2 -0
  341. package/src/version/version.d.ts +1 -0
  342. package/src/version/version.js +2 -0
  343. package/src/work/first.d.ts +11 -0
  344. package/src/work/first.js +91 -0
  345. package/src/work/index.d.ts +2 -0
  346. package/src/work/index.js +15 -0
  347. package/src/work/work.d.ts +20 -0
  348. package/src/work/work.js +136 -0
  349. package/src/ws/dial.d.ts +7 -0
  350. package/src/ws/dial.js +252 -0
  351. package/src/ws/dialing.d.ts +50 -0
  352. package/src/ws/dialing.js +72 -0
  353. package/src/ws/frame.d.ts +32 -0
  354. package/src/ws/frame.js +124 -0
  355. package/src/ws/handshake.d.ts +4 -0
  356. package/src/ws/handshake.js +27 -0
  357. package/src/ws/line.d.ts +45 -0
  358. package/src/ws/line.js +250 -0
  359. package/src/ws/listen.d.ts +42 -0
  360. package/src/ws/listen.js +272 -0
  361. package/src/ws/rfc6455.d.ts +18 -0
  362. package/src/ws/rfc6455.js +187 -0
@@ -0,0 +1,257 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { existsSync, rmSync } from 'node:fs';
3
+ import { socketOf, socketTooLong } from '../../organs/console/node/index.js';
4
+ import { state } from './state.js';
5
+ import { bootKeyFileOf, layBootKey, nextBootKeyFileOf } from '../fills/boot-key.js';
6
+ import { bornHeld, keptHeld } from './born.js';
7
+ import { bootKeyOf, saltOf } from '../fills/unlocker.js';
8
+
9
+ import { designIn } from '../door/design.js';
10
+
11
+
12
+ import { costOf, homeOpened, recoveryCostOf, networkStarts, workHalvesOf, workOf, } from '../work/index.js';
13
+ import { RECOVERY_KEY_DELAY } from '../door/configuration.js';
14
+ import { chosenOf, wordsOf, } from './choices.js';
15
+ import { INSTALLER_VERSION, layFolder, ranOn, readFolder, typedFor, } from '../organism/folder.js';
16
+ import { keepChannel } from '../organism/via.js';
17
+ import { removeService, serviceFor, swapSaid, unitsOf } from '../service/index.js';
18
+ import { laidHalves } from './laid.js';
19
+ import { floorTaken } from './channel.js';
20
+ import { laidAgain } from './choices.js';
21
+ import { addressAt } from '../tcp/frame.js';
22
+
23
+ import { organismOf, } from './given.js';
24
+ import { runningOf, startOrganism } from './spawn.js';
25
+ import { gone, keptAtBoot, signalled, startedAgain, stopped } from './start.js';
26
+ import { bodyOf, removedLaid } from './wipe.js';
27
+ import { leftIn } from './before.js';
28
+ import { claimSaid } from './claim.js';
29
+
30
+ const SHORTEST = 8;
31
+
32
+ export const passphraseTwice = async (asker , short = false) => {
33
+ const first = await asker.ask('A passphrase for the organism: ');
34
+ if (first === null) return { why: 'no passphrase was given' };
35
+ if (first.length === 0 || (!short && first.length < SHORTEST))
36
+ return { why: `a passphrase holds at least ${SHORTEST} characters, or any by --short` };
37
+ const again = await asker.ask('The passphrase again: ');
38
+ return again === first ? first : { why: 'the two passphrases differ' };
39
+ };
40
+
41
+ const fileModeSaid = (home ) =>
42
+ `The boot key stands in ${bootKeyFileOf(home)}, read by your account alone: whoever reads that file owns the organism. Keep a copy off this device, since a backup opens by it alone. A passphrase in its place: ${typedFor(home)('install --boot present')}.`;
43
+
44
+ const takenAt = async (
45
+ given ,
46
+ home ,
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+ ) => {
56
+ if (given.work !== null) homeOpened(home);
57
+ const work = given.work === null ? null : workOf(given.work);
58
+ if (work !== null && 'why' in work) return work;
59
+ const floor = given.faculties === null ? undefined : await floorTaken(given.faculties, given.channel);
60
+ if (floor !== undefined && 'why' in floor) return floor;
61
+ const design = given.design === null ? undefined : await designIn(given.design);
62
+ if (design !== undefined && 'why' in design) return design;
63
+ return {
64
+ ...(work === null ? {} : { work }),
65
+ ...(floor === undefined ? {} : { floor }),
66
+ ...(design === undefined ? {} : design),
67
+ };
68
+ };
69
+
70
+ export const bornKey = async (
71
+ given ,
72
+ home ,
73
+ ) => {
74
+ const worked = await takenAt(given, home);
75
+ if ('why' in worked) return worked;
76
+ given.print(swapSaid());
77
+ if (given.bootMode === 'file') {
78
+ const laid = layFolder(home, {
79
+ port: given.port,
80
+ bootMode: 'file',
81
+ ...wordsOf(given),
82
+ ...worked,
83
+ });
84
+ if (laid !== null) return laid;
85
+ const key = layBootKey(home);
86
+ if ('why' in key) return key;
87
+ given.print(fileModeSaid(home));
88
+ return { key: null };
89
+ }
90
+ if (given.bootMode !== 'present') return bornHeld(given, home, { ...wordsOf(given), ...worked });
91
+ const passphrase = await passphraseTwice(given.asker, given.short);
92
+ if (typeof passphrase !== 'string') return passphrase;
93
+ const salt = saltOf();
94
+ const laid = layFolder(home, {
95
+ port: given.port,
96
+ bootMode: 'present',
97
+ salt,
98
+ ...wordsOf(given),
99
+ ...worked,
100
+ });
101
+ if (laid !== null) return laid;
102
+ given.print(
103
+ `At every boot the organism waits for this passphrase, and runs nothing until someone gives it: ${typedFor(home)('start')} asks it. A boot with no one present: ${typedFor(home)('install --boot file')}.`,
104
+ );
105
+ return { key: await bootKeyOf(passphrase, salt) };
106
+ };
107
+
108
+ export const printLines = (given , laid ) => {
109
+ const at = laid.port === 0 ? 0 : laid.port + 2;
110
+ for (const address of [laid.ws, laid.wss])
111
+ if (address !== undefined)
112
+ given.print(
113
+ address.startsWith('wss:')
114
+ ? `It accepts held lines at ${address}: the machine's proxy forwards it to ws://127.0.0.1:${at}/quo.`
115
+ : `It accepts held lines at ${address}: open port ${at} to whoever should reach it.`,
116
+ );
117
+ };
118
+
119
+ const keptKey = async (
120
+ given ,
121
+ home ,
122
+ laid ,
123
+ ) => {
124
+ if (laid.bootMode === 'file') {
125
+ if (existsSync(bootKeyFileOf(home)) || existsSync(nextBootKeyFileOf(home))) return { key: null };
126
+ const key = layBootKey(home);
127
+ if ('why' in key) return key;
128
+ given.print(fileModeSaid(home));
129
+ return { key: null };
130
+ }
131
+ if (laid.bootMode !== 'present') return keptHeld(given, home, laid);
132
+ const passphrase = await passphraseTwice(given.asker, given.short);
133
+ if (typeof passphrase !== 'string') return passphrase;
134
+ return { key: await bootKeyOf(passphrase, laid.salt) };
135
+ };
136
+
137
+ const finished = async (
138
+ given ,
139
+ home ,
140
+ laid ,
141
+ ) => {
142
+ const key = await keptKey(given, home, laid);
143
+ if ('why' in key) return key;
144
+ const first = await startOrganism(home, 'first-install', key.key);
145
+ if (first === null) return key;
146
+ const booted = await startOrganism(home, 'boot', key.key);
147
+ return booted === null
148
+ ? key
149
+ : { why: `the install was not finished, ${first.why}, nor did its store boot, ${booted.why}` };
150
+ };
151
+
152
+ const broughtToThis = async (
153
+ given ,
154
+ home ,
155
+ laid ,
156
+ moved ,
157
+ ) => {
158
+ const halves = laidHalves(home, laid.work);
159
+ if (halves !== null) return halves;
160
+ const starts = await networkStarts(home, laid);
161
+ if (starts !== null) return starts;
162
+ if (runningOf(home) === null) return finished(given, home, laid);
163
+ const ran = ranOn(home);
164
+ if (ran === INSTALLER_VERSION && !moved && leftIn(home).length === 0) {
165
+ given.print(`The organism is installed already at ${home}, and running.`);
166
+ return { key: undefined };
167
+ }
168
+ const again = await startedAgain(given, home, laid);
169
+ if (again !== null) return again;
170
+ given.print(`The organism is started again on this installer, ${ran ?? 'an older one'} to ${INSTALLER_VERSION}.`);
171
+ return { key: undefined };
172
+ };
173
+
174
+ const firstInstall = async (
175
+ given ,
176
+ home ,
177
+ ) => {
178
+ const work = workHalvesOf(home);
179
+ const stood = { home: existsSync(home), work: existsSync(work) };
180
+ const leftNothing = (why ) => {
181
+ if (runningOf(home) !== null) return why;
182
+ if (!stood.work) rmSync(work, { recursive: true, force: true });
183
+ if (!stood.home) removedLaid(home, bodyOf(home, undefined).lent);
184
+ return why;
185
+ };
186
+ const born = await bornKey(chosenOf(given), home);
187
+ if ('why' in born) return leftNothing(born);
188
+ const read = readFolder(home);
189
+ if ('why' in read) return leftNothing(read);
190
+ const halves = laidHalves(home, read.laid.work);
191
+ if (halves !== null) return leftNothing(halves);
192
+ const started = await startOrganism(home, 'first-install', born.key);
193
+ if (started !== null) return leftNothing(started);
194
+ given.print(`The organism is installed at ${home}, and running.`);
195
+ given.print(costOf(read.laid.work));
196
+ given.print(recoveryCostOf(RECOVERY_KEY_DELAY));
197
+ return { key: born.key, laid: read.laid };
198
+ };
199
+
200
+ const undone = async (home , why ) => {
201
+ const service = serviceFor(home);
202
+ if (!('why' in service)) {
203
+ await removeService(service);
204
+ for (const unit of unitsOf(service)) rmSync(unit.file, { force: true });
205
+ }
206
+ const running = runningOf(home);
207
+ if (running !== null) {
208
+ await stopped(home, running, signalled);
209
+ await gone(running);
210
+ }
211
+ removedLaid(home, workHalvesOf(home), bodyOf(home, undefined).lent);
212
+ return why;
213
+ };
214
+
215
+ export const install = async (given ) => {
216
+ const home = organismOf(given.home);
217
+ const tooLong = socketTooLong(socketOf(home));
218
+ if (tooLong !== null) return { why: tooLong };
219
+ if (given.served) {
220
+ const service = serviceFor(home);
221
+ if ('why' in service) return service;
222
+ }
223
+ const folder = readFolder(home);
224
+ let key ;
225
+ let laid ;
226
+ if ('laid' in folder) {
227
+ laid = folder.laid;
228
+ const again = await laidAgain(given, home, laid);
229
+ if ('why' in again) return again;
230
+ ({ laid } = again);
231
+ const brought = await broughtToThis(given, home, laid, again.restarts);
232
+ if ('why' in brought) return brought;
233
+ key = again.key === undefined ? brought.key : again.key;
234
+ if (key !== undefined) given.print(`The organism is installed at ${home}, and running.`);
235
+ } else {
236
+ const first = await firstInstall(given, home);
237
+ if ('why' in first) return first;
238
+ ({ key, laid } = first);
239
+ }
240
+ keepChannel(home, given.package === null && (given.served || given.take) ? { named: given.channel } : false);
241
+ if (given.served) {
242
+ const served = await keptAtBoot(given, home, key);
243
+ if (served !== null) return 'laid' in folder ? served : undone(home, served);
244
+ }
245
+ if (laid.publicHost !== undefined)
246
+ given.print(`It listens on every interface, and announces ${addressAt(laid.publicHost, laid.port)}.`);
247
+ printLines(given, laid);
248
+ if (laid.claim !== undefined) {
249
+ given.print(claimSaid(laid));
250
+ return null;
251
+ }
252
+ given.print(`Whoever is present at this account owns it at its console: \`${typedFor(home)('state')}\` shows it.`);
253
+ return state(given);
254
+ };
255
+
256
+ export { organismOf, } from './given.js';
257
+ export { start, stop } from './start.js';
@@ -0,0 +1,16 @@
1
+ import { type Data } from '@nervur.org/genome/standard';
2
+ import { type Given, type Outcome } from './given.js';
3
+ declare const COLUMNS: readonly ['lobe', 'far', 'side', 'status', 'note'];
4
+ export type Row = {
5
+ readonly [column in (typeof COLUMNS)[number]]: string;
6
+ };
7
+ export declare const rowsOf: (ends: readonly Data[]) => readonly Row[];
8
+ export declare const tableOf: (rows: readonly Row[]) => readonly string[];
9
+ export declare const pageIn: (result: Data) => {
10
+ readonly ends: readonly Data[];
11
+ readonly cursor: string | null;
12
+ } | {
13
+ readonly why: string;
14
+ };
15
+ export declare const ends: ({ home, words, json, print, answer }: Given) => Promise<Outcome>;
16
+ export {};
@@ -0,0 +1,78 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { dataText, isFields, } from '@nervur.org/genome/standard';
3
+ import { socketOf, typeLine } from '../../organs/console/node/index.js';
4
+ import { organismOf, } from './given.js';
5
+ import { runningOf } from './spawn.js';
6
+ import { LONGEST_TIMEOUT } from '../door/longest.js';
7
+
8
+ const PAGES = 1000;
9
+ const COLUMNS = ['lobe', 'far', 'side', 'status', 'note'] ;
10
+
11
+
12
+
13
+ const cellOf = (value , json = false) => {
14
+ if (value === undefined || value === null) return '-';
15
+ return !json && typeof value === 'string' ? value : dataText(value);
16
+ };
17
+
18
+ export const rowsOf = (ends ) =>
19
+ ends.flatMap((one) =>
20
+ isFields(one)
21
+ ? [
22
+ {
23
+ lobe: cellOf(one['lobe']),
24
+ far: cellOf(one['far']),
25
+ side: cellOf(one['side']),
26
+ status: cellOf(one['status']),
27
+ note: cellOf(one['note'], true),
28
+ },
29
+ ]
30
+ : [],
31
+ );
32
+
33
+ export const tableOf = (rows ) => {
34
+ if (rows.length === 0) return ['no occupant or standing is held'];
35
+ const widths = COLUMNS.map((column) => Math.max(column.length, ...rows.map((row) => row[column].length)));
36
+ const lineOf = (cells ) =>
37
+ cells
38
+ .map((cell, at) => (at === cells.length - 1 ? cell : cell.padEnd(widths[at] ?? 0)))
39
+ .join(' ')
40
+ .trimEnd();
41
+ return [lineOf(COLUMNS), ...rows.map((row) => lineOf(COLUMNS.map((column) => row[column])))];
42
+ };
43
+
44
+ export const pageIn = (
45
+ result ,
46
+ ) => {
47
+ if (!isFields(result) || !Array.isArray(result['ends'])) return { why: 'ends: the brain answered no list of ends' };
48
+ return { ends: result['ends'], cursor: typeof result['cursor'] === 'string' ? result['cursor'] : null };
49
+ };
50
+
51
+ const pageOf = async (
52
+ home ,
53
+ lobe ,
54
+ cursor ,
55
+ ) => {
56
+ const args = { ...(lobe === undefined ? {} : { lobe }), ...(cursor === null ? {} : { cursor }) };
57
+ const heard = await typeLine(socketOf(organismOf(home)), ['ask', 'brain', 'ends', dataText(args)], LONGEST_TIMEOUT);
58
+ if ('why' in heard) return heard;
59
+ if ('error' in heard.answer) return { why: `ends: ${heard.answer.error.message}` };
60
+ return pageIn(heard.answer.result);
61
+ };
62
+
63
+ export const ends = async ({ home, words, json, print, answer } ) => {
64
+ if (runningOf(organismOf(home)) === null) return { why: 'the organism is not running' };
65
+ const lobe = words[1];
66
+ const all = [];
67
+ let cursor = null;
68
+ for (let page = 0; page < PAGES; page += 1) {
69
+ const read = await pageOf(home, lobe, cursor);
70
+ if ('why' in read) return read;
71
+ all.push(...read.ends);
72
+ cursor = read.cursor;
73
+ if (cursor === null) break;
74
+ }
75
+ if (json) answer(dataText(all));
76
+ else for (const one of tableOf(rowsOf(all))) print(one);
77
+ return null;
78
+ };
@@ -0,0 +1,12 @@
1
+ import type { Heard, Watch } from '../../organs/console/node/index.js';
2
+ type Why = {
3
+ readonly why: string;
4
+ };
5
+ export type Following = {
6
+ readonly type: (words: readonly string[]) => Promise<Heard | Why>;
7
+ readonly watch: Watch;
8
+ };
9
+ export declare const jobOf: ({ answer }: Heard) => string | null;
10
+ export declare const followed: (following: Following, at: readonly string[], heard: Heard) => Promise<Heard | Why>;
11
+ export declare const exitOf: ({ answer }: Heard) => number;
12
+ export {};
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { dataText, isFields } from '@nervur.org/genome/standard';
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+ export const jobOf = ({ answer } ) => {
13
+ if (!('result' in answer) || !isFields(answer.result)) return null;
14
+ const { job, ended } = answer.result;
15
+ return typeof job === 'string' && (ended === undefined || ended === null) ? job : null;
16
+ };
17
+
18
+ const over = ({ answer } ) =>
19
+ !('result' in answer) || !isFields(answer.result) || (answer.result['ended'] ?? null) !== null;
20
+
21
+ export const followed = async (following , at , heard ) => {
22
+ const job = jobOf(heard);
23
+ if (job === null) return heard;
24
+ const read = [...at.slice(0, 2), 'job', dataText({ job })];
25
+ return new Promise((done) => {
26
+ let ended = false;
27
+ let reading = Promise.resolve();
28
+ let watching = null;
29
+ const end = (outcome ) => {
30
+ if (ended) return;
31
+ ended = true;
32
+ watching?.close();
33
+ done(outcome);
34
+ };
35
+ const again = () => {
36
+ reading = reading.then(async () => {
37
+ if (ended) return;
38
+ const now = await following.type(read);
39
+ if ('why' in now || over(now)) end(now);
40
+ });
41
+ };
42
+ void following
43
+ .watch(
44
+ ({ lobes }) => {
45
+ if (lobes.length > 0) again();
46
+ },
47
+ () =>
48
+ void reading.then(() =>
49
+ end({ why: `the organism stopped before the job ${job} ended; ${read.join(' ')} reads it once it runs` }),
50
+ ),
51
+ )
52
+ .then((watched) => {
53
+ if ('why' in watched) return end({ why: `the job ${job} is not followed: ${watched.why}` });
54
+ if (ended) return watched.close();
55
+ watching = watched;
56
+ again();
57
+ });
58
+ });
59
+ };
60
+
61
+ export const exitOf = ({ answer } ) => {
62
+ if (!('result' in answer)) return 1;
63
+ const ended = isFields(answer.result) ? (answer.result['ended'] ?? null) : null;
64
+ const code = isFields(ended) ? ended['code'] : 0;
65
+ return typeof code === 'number' && Number.isInteger(code) && code > 0 ? Math.min(code, 255) : 0;
66
+ };
@@ -0,0 +1,39 @@
1
+ import type { BootMode } from '../door/configuration.js';
2
+ import type { Hands } from '../fills/held.js';
3
+ import type { Asker } from './passphrase.js';
4
+ export type Given = {
5
+ readonly home: string;
6
+ readonly served: boolean;
7
+ readonly port: number | null;
8
+ readonly bootMode: BootMode | null;
9
+ readonly keepers: readonly string[];
10
+ readonly end: 'present' | 'keyring' | 'file' | 'hardware' | null;
11
+ readonly hands?: Hands;
12
+ readonly publicHost: string | null;
13
+ readonly screen?: boolean;
14
+ readonly reserve?: number;
15
+ readonly ws: string | null;
16
+ readonly work: string | null;
17
+ readonly take: boolean;
18
+ readonly channel: string | null;
19
+ readonly package: string | null;
20
+ readonly short: boolean;
21
+ readonly faculties: string | null;
22
+ readonly design: string | null;
23
+ readonly floor: boolean;
24
+ readonly cipher: string | null;
25
+ readonly claim: string | null;
26
+ readonly words: readonly string[];
27
+ readonly json: boolean;
28
+ readonly follow: boolean;
29
+ readonly starter?: boolean;
30
+ readonly asker: Asker;
31
+ readonly print: (line: string) => void;
32
+ readonly answer: (text: string) => void;
33
+ };
34
+ export type Outcome = null | {
35
+ readonly why: string;
36
+ } | {
37
+ readonly exit: number;
38
+ };
39
+ export declare const organismOf: (home: string) => string;
@@ -0,0 +1,53 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { join } from 'node:path';
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+ export const organismOf = (home ) => join(home, 'organism');
@@ -0,0 +1,15 @@
1
+ import type { Init } from '@nervur.org/genome/seams';
2
+ import { type Door } from '../door/door.js';
3
+ import { type Laid } from '../organism/folder.js';
4
+ import type { Given } from './given.js';
5
+ type Why = {
6
+ readonly why: string;
7
+ };
8
+ export declare const bootKeyIn: (given: Given, home: string, laid: Laid) => Promise<{
9
+ readonly key: Uint8Array;
10
+ } | Why>;
11
+ export declare const stoppedHere: (home: string) => Promise<null | Why>;
12
+ export declare const doorHere: (given: Given, home: string, laid: Laid, init: Init, key: Uint8Array) => Promise<{
13
+ readonly door: Door;
14
+ } | Why>;
15
+ export {};
@@ -0,0 +1,56 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+
3
+
4
+ import { configurationOf } from '../door/configuration.js';
5
+ import { openDoor, } from '../door/door.js';
6
+ import { readBootKey, readNextBootKey } from '../fills/boot-key.js';
7
+ import { custodyOf, hostHands } from '../fills/held.js';
8
+ import { presentUnlocker } from '../fills/unlocker.js';
9
+ import { typedFor, } from '../organism/folder.js';
10
+
11
+ import { runningOf } from './spawn.js';
12
+ import { askedKey, stopped } from './start.js';
13
+
14
+
15
+
16
+ export const bootKeyIn = async (
17
+ given ,
18
+ home ,
19
+ laid ,
20
+ ) => {
21
+ if (readNextBootKey(home) !== null)
22
+ return {
23
+ why: `a rewrap cut short left a new boot key beside the old: ${typedFor(home)('start')} settles it first`,
24
+ };
25
+ if (laid.bootMode === 'file') return readBootKey(home);
26
+ if (laid.bootMode !== 'present') {
27
+ const opened = await custodyOf(home, laid, given.hands ?? hostHands()).open();
28
+ if (opened !== null) return opened;
29
+ }
30
+ const asked = await askedKey(given, laid);
31
+ if (asked === null) return { why: 'no boot key was given' };
32
+ return 'why' in asked ? asked : { key: asked };
33
+ };
34
+
35
+ export const stoppedHere = async (home ) => {
36
+ const running = runningOf(home);
37
+ return running === null ? null : stopped(home, running);
38
+ };
39
+
40
+ export const doorHere = (
41
+ given ,
42
+ home ,
43
+ laid ,
44
+ init ,
45
+ key ,
46
+ ) =>
47
+ openDoor({
48
+ home,
49
+ init,
50
+ unlocker: presentUnlocker(() => Promise.resolve(key)),
51
+ configuration: configurationOf(laid, home),
52
+ stopped: (why) => given.print(`The organism stopped itself: ${why}`),
53
+ warned: (why) => given.print(`The boot refused something the configuration named: ${why}`),
54
+ firstInvitation: (invitation ) =>
55
+ given.print(`The organism's first invitation, for its owner alone: ${JSON.stringify(invitation)}`),
56
+ });
@@ -0,0 +1 @@
1
+ export declare const nervur: (argv: readonly string[]) => Promise<number>;