@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,213 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { execFileSync, spawn } from 'node:child_process';
3
+ import { closeSync, existsSync, openSync, readdirSync, readFileSync } from 'node:fs';
4
+
5
+ import { extname } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { LONGEST_WAIT } from '../door/longest.js';
8
+ import { logOf, pidOf, stoppedOf, stoppedSaid, typedFor } from '../organism/folder.js';
9
+ import { unlockOf } from '../organism/unlock.js';
10
+ import { saidOf, } from '../organism/said.js';
11
+
12
+ import { windowsProcesses } from './windows-processes.js';
13
+
14
+ const MAIN = fileURLToPath(new URL(`../organism/main${extname(import.meta.url)}`, import.meta.url));
15
+ const TAIL = 20;
16
+
17
+ export const endedUnasked = (code , signal , log ) => {
18
+ const how = signal === null ? `with code ${String(code)}` : `killed by ${signal}`;
19
+ const lines = existsSync(log) ? readFileSync(log, 'utf8').trimEnd().split('\n').slice(-TAIL) : [];
20
+ return lines.length === 0 || lines[0] === ''
21
+ ? `the organism ended before it started, ${how}, and wrote no log at ${log}`
22
+ : `the organism ended before it started, ${how}; the last of its log at ${log}:\n${lines.join('\n')}`;
23
+ };
24
+
25
+ export const LOADING = process.platform === 'win32' ? 120_000 : 30_000;
26
+
27
+ const wordsOf = (pid ) => {
28
+ try {
29
+ if (process.platform === 'linux') return readFileSync(`/proc/${pid}/cmdline`, 'utf8').split('\0').slice(0, -1);
30
+ if (process.platform === 'win32') return windowsProcesses(` AND ProcessId=${pid}`)[0]?.[1] ?? null;
31
+ return execFileSync('ps', ['-ww', '-o', 'command=', '-p', String(pid)], {
32
+ encoding: 'utf8',
33
+ }).trim();
34
+ } catch {
35
+ return null;
36
+ }
37
+ };
38
+
39
+ const initOf = (after ) =>
40
+ ['boot', 'first-install'].includes(after[0] ?? '') ? after : null;
41
+
42
+ const wordsOn = (words , home ) => {
43
+ if (typeof words === 'string') {
44
+ const at = words.indexOf(` ${home} `);
45
+ return at < 0 ? null : initOf(words.slice(at + home.length + 2).split(' '));
46
+ }
47
+ const at = words.indexOf(home);
48
+ return at < 1 ? null : initOf(words.slice(at + 1));
49
+ };
50
+
51
+ const startedOn = (pid , home ) => {
52
+ const words = wordsOf(pid);
53
+ return words === null ? null : wordsOn(words, home);
54
+ };
55
+
56
+ export const processesTold = () => {
57
+ try {
58
+ if (process.platform === 'linux')
59
+ return readdirSync('/proc')
60
+ .map(Number)
61
+ .filter((pid) => Number.isInteger(pid) && pid > 0)
62
+ .flatMap((pid) => {
63
+ const words = wordsOf(pid);
64
+ return words === null ? [] : [[pid, words] ];
65
+ });
66
+ if (process.platform === 'win32') return windowsProcesses();
67
+ return execFileSync('ps', ['-ax', '-ww', '-o', 'pid=,command='], { encoding: 'utf8' })
68
+ .split('\n')
69
+ .flatMap((line) => {
70
+ const read = /^\s*(\d+)\s(.*)$/u.exec(line);
71
+ return read === null ? [] : [[Number(read[1]), read[2] ?? ''] ];
72
+ });
73
+ } catch {
74
+ return null;
75
+ }
76
+ };
77
+
78
+ export const alive = (pid ) => {
79
+ try {
80
+ process.kill(pid, 0);
81
+ return true;
82
+ } catch (failed) {
83
+ return typeof failed === 'object' && failed !== null && 'code' in failed && failed.code === 'EPERM';
84
+ }
85
+ };
86
+
87
+ export const HOST_PROCESSES = { told: processesTold, own: new Set([process.pid, process.ppid]) };
88
+
89
+ export const startsOn = (home ) =>
90
+ (processesTold() ?? []).flatMap(([pid, words]) =>
91
+ pid !== process.pid && wordsOn(words, home) !== null ? [pid] : [],
92
+ );
93
+
94
+ export const runningOf = (home ) => {
95
+ let said ;
96
+ try {
97
+ said = readFileSync(pidOf(home), 'utf8');
98
+ } catch {
99
+ return null;
100
+ }
101
+ const pid = Number(said);
102
+ return Number.isInteger(pid) && pid > 0 && startedOn(pid, home) !== null ? pid : null;
103
+ };
104
+
105
+ export const notRunningWhy = (organism ) => {
106
+ if (existsSync(stoppedOf(organism))) return stoppedSaid(organism);
107
+ if (existsSync(unlockOf(organism)))
108
+ return `the organism is not running yet: its service started it, and it waits for its passphrase, which ${typedFor(organism)('start')} asks and gives it`;
109
+ return 'the organism is not running';
110
+ };
111
+
112
+ export const runsAtBoot = (home ) => {
113
+ const pid = runningOf(home);
114
+ return pid !== null && startedOn(pid, home)?.[1] === '--at-boot';
115
+ };
116
+
117
+ const hearing = (
118
+ stdout ,
119
+ finish ,
120
+ moves ,
121
+ beat ,
122
+ ) => {
123
+ let started = false;
124
+ let held = '';
125
+ stdout.setEncoding('utf8');
126
+ stdout.on('data', (chunk ) => {
127
+ beat();
128
+ held += chunk;
129
+ const lines = held.split('\n');
130
+ held = lines.pop() ?? '';
131
+ for (const said of lines.map(saidOf)) {
132
+ if (said === null) continue;
133
+ if ('why' in said) return finish(said);
134
+ started = true;
135
+ moves(said);
136
+ return finish(null);
137
+ }
138
+ });
139
+ return { started: () => started };
140
+ };
141
+
142
+ export const startOrganism = (
143
+ home ,
144
+ kind ,
145
+ key ,
146
+ moves = () => undefined,
147
+ ) => {
148
+ const log = openSync(logOf(home), 'a', 0o600);
149
+ const child = spawn(process.execPath, [MAIN, home, ...(kind === 'trial' ? ['boot', '--trial'] : [kind])], {
150
+ detached: true,
151
+ stdio: ['pipe', 'pipe', log],
152
+ });
153
+ closeSync(log);
154
+ const { stdin, stdout } = child;
155
+ if (stdin === null || stdout === null) return Promise.resolve({ why: 'the organism was started with no pipes' });
156
+ if (key === null) stdin.end();
157
+ else stdin.end(key);
158
+ return heardFrom(
159
+ { stdout, on: (event, listener) => child.on(event, listener), unref: () => child.unref() },
160
+ home,
161
+ moves,
162
+ );
163
+ };
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+ export const heardFrom = (
172
+ child ,
173
+ home ,
174
+ moves ,
175
+ ) =>
176
+ new Promise((done) => {
177
+ let waited = LOADING;
178
+ let over = false;
179
+ let ended = false;
180
+ let refused = null;
181
+ const finish = (heard ) => {
182
+ if (over) return;
183
+ over = true;
184
+ clearTimeout(timer);
185
+ child.stdout.destroy();
186
+ child.unref();
187
+ done(heard);
188
+ };
189
+ const silent = () =>
190
+ finish({ why: `the organism said nothing for ${waited / 1000} s; its log is ${logOf(home)}` });
191
+ let timer = setTimeout(silent, waited);
192
+ const told = (heard ) => {
193
+ if (heard === null || ended) return finish(heard);
194
+ if (refused !== null) return;
195
+ refused = heard;
196
+ clearTimeout(timer);
197
+ timer = setTimeout(
198
+ () => finish({ why: `${heard.why}; and its process did not end in ${LONGEST_WAIT / 1000} s` }),
199
+ LONGEST_WAIT,
200
+ );
201
+ };
202
+ const heard = hearing(child.stdout, told, moves, () => {
203
+ if (refused !== null) return;
204
+ clearTimeout(timer);
205
+ waited = LONGEST_WAIT;
206
+ timer = setTimeout(silent, waited);
207
+ });
208
+ child.on('exit', (code, signal) => {
209
+ ended = true;
210
+ if (refused !== null) finish(refused);
211
+ else if (!heard.started()) finish({ why: endedUnasked(code, signal, logOf(home)) });
212
+ });
213
+ });
@@ -0,0 +1,34 @@
1
+ import { type Laid } from '../organism/folder.js';
2
+ import { toldAt } from '../organism/told.js';
3
+ import { type Given, type Outcome } from './given.js';
4
+ import { runningOf, startOrganism } from './spawn.js';
5
+ declare const askedToEnd: (home: string, running: number) => Promise<null | {
6
+ readonly why: string;
7
+ }>;
8
+ export declare const signalled: (_home: string, running: number) => Promise<null>;
9
+ export declare const stopped: (home: string, running: number, asking?: typeof askedToEnd, waiting?: typeof toldAt) => Promise<null | {
10
+ readonly why: string;
11
+ }>;
12
+ export declare const runningWithin: (home: string, waiting?: typeof toldAt) => Promise<null | {
13
+ readonly why: string;
14
+ }>;
15
+ export declare const askedKey: (given: Given, laid: Laid) => Promise<Uint8Array | null | {
16
+ readonly why: string;
17
+ }>;
18
+ export declare const keptAtBoot: (given: Given, home: string, key: Uint8Array | null | undefined) => Promise<null | {
19
+ readonly why: string;
20
+ }>;
21
+ export type Reaches = {
22
+ readonly runs: typeof runningOf;
23
+ readonly begin: typeof startOrganism;
24
+ };
25
+ export declare const start: (given: Given, reaches?: Reaches) => Promise<Outcome>;
26
+ export declare const startedAgain: (given: Given, home: string, laid: Laid) => Promise<null | {
27
+ readonly why: string;
28
+ }>;
29
+ export declare const startedOn: (home: string, key: Uint8Array | null) => Promise<null | {
30
+ readonly why: string;
31
+ }>;
32
+ export declare const stop: ({ home, print }: Given) => Promise<Outcome>;
33
+ export declare const gone: (running: number) => Promise<void>;
34
+ export {};
@@ -0,0 +1,246 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { existsSync, writeFileSync } from 'node:fs';
3
+ import { typeLine } from '../../organs/console/node/index.js';
4
+ import { LONGEST_WAIT } from '../door/longest.js';
5
+ import { heardOf } from '../organism/beat.js';
6
+ import { admitHere, custodyOf, hostHands, humanEnds } from '../fills/held.js';
7
+ import { bootKeyOf } from '../fills/unlocker.js';
8
+ import { logOf, pidOf, readFolder, stoppedOf, stoppedSaid, } from '../organism/folder.js';
9
+ import { toldAt } from '../organism/told.js';
10
+ import { unlockOf } from '../organism/unlock.js';
11
+ import {
12
+ laidAlike,
13
+ laidService,
14
+ layLinkHandler,
15
+ layService,
16
+ serviceFor,
17
+ startService,
18
+ stopService,
19
+
20
+ } from '../service/index.js';
21
+ import { hex } from '@nervur.org/genome/standard';
22
+ import { floorOf } from './before.js';
23
+ import { packageRoot } from './channel.js';
24
+ import { treeFlushed } from '../fills/flushed.js';
25
+ import { organismOf, } from './given.js';
26
+ import { laidHalves } from './laid.js';
27
+ import { LOADING, runningOf, runsAtBoot, startOrganism } from './spawn.js';
28
+
29
+ const askedToEnd = async (home , running ) => {
30
+ const service = runsAtBoot(home) ? laidService(home) : null;
31
+ if (service !== null) {
32
+ const asked = await stopService(service, home);
33
+ if (asked !== null || service.manager !== 'schtasks') return asked;
34
+ }
35
+ try {
36
+ process.kill(running, 'SIGTERM');
37
+ } catch {
38
+ }
39
+ return null;
40
+ };
41
+
42
+ export const signalled = (_home , running ) => {
43
+ try {
44
+ process.kill(running, 'SIGTERM');
45
+ } catch {
46
+ }
47
+ return Promise.resolve(null);
48
+ };
49
+
50
+ export const stopped = async (
51
+ home ,
52
+ running ,
53
+ asking = askedToEnd,
54
+ waiting = toldAt,
55
+ ) => {
56
+ const asked = await asking(home, running);
57
+ if (asked !== null) return asked;
58
+ const ended = await waiting(pidOf(home), () => (runningOf(home) === null ? true : null), LONGEST_WAIT, heardOf(home));
59
+ return ended === null
60
+ ? { why: `the organism, process ${running}, did not stop, and told nothing for ${LONGEST_WAIT / 1000} s` }
61
+ : null;
62
+ };
63
+
64
+ export const runningWithin = async (
65
+ home ,
66
+ waiting = toldAt,
67
+ ) =>
68
+ (await waiting(pidOf(home), () => runningOf(home), LOADING, heardOf(home))) === null
69
+ ? { why: `the organism did not start, and told nothing for ${LONGEST_WAIT / 1000} s; its log is ${logOf(home)}` }
70
+ : null;
71
+
72
+ const keyGiven = async (home , key ) => {
73
+ const heard = await typeLine(unlockOf(home), [hex(key)], LOADING, LONGEST_WAIT);
74
+ if ('why' in heard) return heard;
75
+ return 'error' in heard.answer ? { why: heard.answer.error.message } : null;
76
+ };
77
+
78
+ const startedByService = async (
79
+ service ,
80
+ home ,
81
+ key ,
82
+ ) => {
83
+ const started = startService(service);
84
+ if (started !== null) return started;
85
+ return key === null ? runningWithin(home) : keyGiven(home, key);
86
+ };
87
+
88
+ const startsWhen = (service ) =>
89
+ service.manager === 'launchd'
90
+ ? `starts as this account logs in, through launchd: ${service.file}`
91
+ : `starts at boot through ${service.manager}: ${service.file}`;
92
+
93
+ const printRunning = (given , service ) =>
94
+ given.print(`The organism is running, and ${startsWhen(service)}.`);
95
+
96
+ export const askedKey = async (given , laid ) => {
97
+ if (laid.bootMode === 'remote') return keeperKey(given, laid);
98
+ if (laid.bootMode !== 'present') return null;
99
+ const passphrase = await given.asker.ask('The passphrase of the organism: ');
100
+ if (passphrase === null) return { why: 'no passphrase was given' };
101
+ return bootKeyOf(passphrase, laid.salt);
102
+ };
103
+
104
+ const keeperKey = async (
105
+ given ,
106
+ laid ,
107
+ ) => {
108
+ const hands = given.hands ?? hostHands();
109
+ const home = organismOf(given.home);
110
+ const admitted = await admitHere(home, laid, hands);
111
+ if (admitted !== null && !humanEnds(laid)) return admitted;
112
+ if (!humanEnds(laid)) return null;
113
+ const opened = await custodyOf(home, laid, hands).open();
114
+ if (opened !== null && 'key' in opened) return null;
115
+ const passphrase = await given.asker.ask('Every keeper is out. The passphrase of the organism: ');
116
+ if (passphrase === null) return { why: 'no passphrase was given' };
117
+ if (laid.salt === undefined) return { why: 'the folder holds no salt for its passphrase' };
118
+ return bootKeyOf(passphrase, laid.salt);
119
+ };
120
+
121
+ const byService = async (
122
+ given ,
123
+ service ,
124
+ home ,
125
+ key ,
126
+ ) => {
127
+ const root = await packageRoot();
128
+ if (typeof root === 'string') treeFlushed(root);
129
+ const laid = await layService(service, home);
130
+ if ('why' in laid) return laid;
131
+ if (laid.warning !== null) given.print(laid.warning);
132
+ const running = runningOf(home);
133
+ const ended = running === null ? null : await stopped(home, running);
134
+ if (ended !== null) return ended;
135
+ const started = await startedByService(service, home, key);
136
+ if (started !== null) return started;
137
+ printRunning(given, service);
138
+ return null;
139
+ };
140
+
141
+ const keptByService = async (
142
+ given ,
143
+ home ,
144
+ key ,
145
+ ) => {
146
+ const service = serviceFor(home);
147
+ if ('why' in service) return service;
148
+ if (runsAtBoot(home) && laidAlike(service)) {
149
+ given.print(`The organism runs already, and ${startsWhen(service)}.`);
150
+ return null;
151
+ }
152
+ if (key !== undefined) return byService(given, service, home, key);
153
+ const folder = readFolder(home);
154
+ if ('why' in folder) return folder;
155
+ const asked = await askedKey(given, folder.laid);
156
+ if (asked !== null && 'why' in asked) return asked;
157
+ return byService(given, service, home, asked);
158
+ };
159
+
160
+ export const keptAtBoot = async (
161
+ given ,
162
+ home ,
163
+ key ,
164
+ ) => {
165
+ const served = await keptByService(given, home, key);
166
+ if (served !== null) return served;
167
+ const handed = layLinkHandler(given.home);
168
+ if (handed !== null) given.print(`A web+quo: link is not handed to the installer on this host: ${handed.why}`);
169
+ return null;
170
+ };
171
+
172
+
173
+
174
+
175
+
176
+
177
+ export const start = async (
178
+ given ,
179
+ reaches = { runs: runningOf, begin: startOrganism },
180
+ ) => {
181
+ const home = organismOf(given.home);
182
+ const folder = readFolder(home);
183
+ if ('why' in folder) return folder;
184
+ if (existsSync(stoppedOf(home))) return { why: stoppedSaid(home) };
185
+ const service = laidService(home);
186
+ const running = reaches.runs(home);
187
+ if (running !== null) return { why: `the organism already runs, as process ${running}` };
188
+ const halves = laidHalves(home, folder.laid.work);
189
+ if (halves !== null) return halves;
190
+ const key = await askedKey(given, folder.laid);
191
+ if (key !== null && 'why' in key) return key;
192
+ if (given.floor) writeFileSync(floorOf(home), '', { mode: 0o600 });
193
+ if (service === null) {
194
+ const started = await reaches.begin(home, 'boot', key);
195
+ if (started !== null) return started;
196
+ given.print('The organism is running.');
197
+ return null;
198
+ }
199
+ const started = await startedByService(service, home, key);
200
+ if (started !== null) return started;
201
+ printRunning(given, service);
202
+ return null;
203
+ };
204
+
205
+ export const startedAgain = async (
206
+ given ,
207
+ home ,
208
+ laid ,
209
+ ) => {
210
+ const key = await askedKey(given, laid);
211
+ if (key !== null && 'why' in key) return key;
212
+ const service = laidService(home);
213
+ const relaid = service === null || laidAlike(service) ? { warning: null } : await layService(service, home);
214
+ if ('why' in relaid) return relaid;
215
+ if (relaid.warning !== null) given.print(relaid.warning);
216
+ const running = runningOf(home);
217
+ const ended = running === null ? null : await stopped(home, running);
218
+ if (ended !== null) return ended;
219
+ return service === null ? startOrganism(home, 'boot', key) : startedByService(service, home, key);
220
+ };
221
+
222
+ export const startedOn = (home , key ) => {
223
+ const service = laidService(home);
224
+ return service === null ? startOrganism(home, 'boot', key) : startedByService(service, home, key);
225
+ };
226
+
227
+ export const stop = async ({ home, print } ) => {
228
+ const organism = organismOf(home);
229
+ const running = runningOf(organism);
230
+ if (running === null) return { why: 'the organism is not running' };
231
+ const ended = await stopped(organism, running);
232
+ if (ended !== null) return ended;
233
+ print('The organism stopped.');
234
+ return null;
235
+ };
236
+
237
+ export const gone = async (running ) => {
238
+ for (let tried = 0; tried < 200; tried += 1) {
239
+ try {
240
+ process.kill(running, 0);
241
+ } catch {
242
+ return;
243
+ }
244
+ await new Promise((done) => setTimeout(done, 50));
245
+ }
246
+ };
@@ -0,0 +1,5 @@
1
+ import { typeLine } from '../../organs/console/node/index.js';
2
+ import { type Given, type Outcome } from './given.js';
3
+ export type Typing = (words: readonly string[]) => ReturnType<typeof typeLine>;
4
+ export declare const stateTold: (type: Typing, typed: (words: string) => string, { json, print, answer }: Pick<Given, 'json' | 'print' | 'answer'>) => Promise<Outcome>;
5
+ export declare const state: (given: Given) => Promise<Outcome>;
@@ -0,0 +1,39 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { dataText } from '@nervur.org/genome/standard';
3
+ import { socketOf, typeLine } from '../../organs/console/node/index.js';
4
+ import { LONGEST_TIMEOUT } from '../door/longest.js';
5
+ import { typedFor } from '../organism/folder.js';
6
+ import { shown } from './answers.js';
7
+ import { stateOf } from './asked.js';
8
+ import { organismOf, } from './given.js';
9
+ import { notRunningWhy, runningOf } from './spawn.js';
10
+
11
+
12
+
13
+ export const stateTold = async (
14
+ type ,
15
+ typed ,
16
+ { json, print, answer } ,
17
+ ) => {
18
+ let refused = null;
19
+ const whole = await stateOf(async (words) => {
20
+ const heard = await type(words);
21
+ if ('why' in heard) return heard;
22
+ if ('error' in heard.answer) {
23
+ refused = heard.text;
24
+ return { why: heard.text };
25
+ }
26
+ return { data: heard.answer.result };
27
+ });
28
+ const text = 'data' in whole ? dataText({ result: whole.data }) : refused;
29
+ if (text === null) return 'why' in whole ? whole : null;
30
+ if (json) answer(text);
31
+ else for (const one of shown(['ask', 'brain', 'state'], text, typed)) print(one);
32
+ return 'data' in whole ? null : { exit: 1 };
33
+ };
34
+
35
+ export const state = async (given ) => {
36
+ const organism = organismOf(given.home);
37
+ if (runningOf(organism) === null) return { why: notRunningWhy(organism) };
38
+ return stateTold((words) => typeLine(socketOf(organism), words, LONGEST_TIMEOUT), typedFor(organism), given);
39
+ };
@@ -0,0 +1 @@
1
+ export declare const tokened: (env: NodeJS.ProcessEnv, registry: string | null) => NodeJS.ProcessEnv;
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+
3
+ export const tokened = (env , registry ) => {
4
+ const token = env['NPM_TOKEN'];
5
+ if (token === undefined || token === '' || registry === null) return env;
6
+ const { host, pathname } = new URL(registry);
7
+ const key = `npm_config_//${host}${pathname.endsWith('/') ? pathname : `${pathname}/`}:_authToken`;
8
+ return Object.assign({}, env, { [key]: token });
9
+ };
@@ -0,0 +1,17 @@
1
+ import { type Laid } from '../organism/folder.js';
2
+ import type { Moves } from '../organism/said.js';
3
+ import type { Given, Outcome } from './given.js';
4
+ type Why = {
5
+ readonly why: string;
6
+ };
7
+ export type Trying = {
8
+ readonly ran: (home: string) => string | null;
9
+ readonly stop: (home: string) => Promise<null | Why>;
10
+ readonly copy: (home: string) => null | Why;
11
+ readonly floor: (given: Given, home: string) => Promise<null | Why>;
12
+ readonly start: (home: string, key: Uint8Array | null, moves: (said: Moves) => void) => Promise<null | Why>;
13
+ };
14
+ export declare const TRYING: Trying;
15
+ export declare const tried: (given: Given, home: string, laid: Laid, installer: string, reaches?: Trying) => Promise<Outcome>;
16
+ export declare const moves: (home: string, installer: string) => boolean;
17
+ export {};
@@ -0,0 +1,92 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { existsSync } from 'node:fs';
3
+ import { storeOf } from '../door/door.js';
4
+ import { ranOn, } from '../organism/folder.js';
5
+
6
+ import { beforeOf, committed, halvesBack, keptAside, storeAside, storeBack, storeCopied, wentBack } from './before.js';
7
+
8
+ import { laidHalves } from './laid.js';
9
+ import { runningOf, startOrganism } from './spawn.js';
10
+ import { askedKey, stopped } from './start.js';
11
+
12
+
13
+
14
+ const checkOf = (home , installer , reaches ) => {
15
+ const ran = reaches.ran(home);
16
+ return ran === installer
17
+ ? null
18
+ : { why: `the trial runs on installer-node ${ran ?? 'none'}, where ${installer} was asked` };
19
+ };
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+ const ended = async (home ) => {
34
+ const running = runningOf(home);
35
+ return running === null ? null : stopped(home, running);
36
+ };
37
+
38
+ export const TRYING = {
39
+ ran: ranOn,
40
+ stop: ended,
41
+ copy: storeCopied,
42
+ floor: () => Promise.resolve(null),
43
+ start: (home, key, moves) => startOrganism(home, 'trial', key, moves),
44
+ };
45
+
46
+ export const tried = async (
47
+ given ,
48
+ home ,
49
+ laid ,
50
+ installer ,
51
+ reaches = TRYING,
52
+ ) => {
53
+ const key = await askedKey(given, laid);
54
+ if (key !== null && 'why' in key) return key;
55
+ const own = !existsSync(beforeOf(home));
56
+ if (own) {
57
+ const kept = keptAside(home, null);
58
+ if (kept !== null) return kept;
59
+ }
60
+ const back = (why ) => {
61
+ if (own) wentBack(home);
62
+ else {
63
+ storeBack(home);
64
+ halvesBack(home);
65
+ }
66
+ return why;
67
+ };
68
+ const halves = laidHalves(home, laid.work);
69
+ if (halves !== null) return back(halves);
70
+ const down = await reaches.stop(home);
71
+ if (down !== null) return back({ why: `the organism did not stop for the trial: ${down.why}` });
72
+ if (existsSync(storeOf(home))) storeAside(home);
73
+ const copied = reaches.copy(home);
74
+ if (copied !== null) return back(copied);
75
+ const floor = await reaches.floor(given, home);
76
+ if (floor !== null) return back(floor);
77
+ let moves = { moved: [], refused: [] };
78
+ const started = await reaches.start(home, key, (said) => {
79
+ moves = said;
80
+ });
81
+ const failed = started ?? checkOf(home, installer, reaches);
82
+ const stoppedTrial = await ended(home);
83
+ const why = failed ?? stoppedTrial;
84
+ if (why !== null) return back({ why: `the new version failed its trial: ${why.why}` });
85
+ committed(home);
86
+ given.print(`The trial of installer-node ${installer} passed, and it is kept.`);
87
+ for (const line of moves.moved) given.print(`${line.charAt(0).toUpperCase()}${line.slice(1)}.`);
88
+ return null;
89
+ };
90
+
91
+ export const moves = (home , installer ) =>
92
+ existsSync(storeOf(home)) && ranOn(home) !== installer;
@@ -0,0 +1 @@
1
+ export declare const vouchOf: (domain: string) => Promise<string | null>;
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { LONGEST_TIMEOUT } from '../door/longest.js';
3
+
4
+ export const vouchOf = async (domain ) => {
5
+ try {
6
+ const response = await fetch(`https://${domain}/.well-known/quo`, {
7
+ credentials: 'omit',
8
+ cache: 'no-store',
9
+ signal: AbortSignal.timeout(LONGEST_TIMEOUT),
10
+ });
11
+ return response.status === 200 ? await response.text() : null;
12
+ } catch {
13
+ return null;
14
+ }
15
+ };