@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,261 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { existsSync } from 'node:fs';
3
+ import { FLOOR } from '@nervur.org/genome';
4
+ import { socketOf, socketTooLong } from '../../organs/console/node/index.js';
5
+ import { INSTALLER_VERSION, ranOn, readFolder } from '../organism/folder.js';
6
+ import { beforeOf, committed, keptOld, wentBack } from './before.js';
7
+ import { leftIn } from './undone.js';
8
+ import { BRIDGING, floorsAside, floored, } from './bridge.js';
9
+ import { atHand, handedOver, taken, viewed, } from './channel.js';
10
+ import { accountHeld, locked } from './locks.js';
11
+ import { designWordOf, floorWordOf } from './choices.js';
12
+ import { claimWordOf } from './claim.js';
13
+ import { install } from './commands.js';
14
+ import { organismOf, } from './given.js';
15
+ import { isOlder } from './lobes.js';
16
+ import { sealedBack } from './older.js';
17
+ import { askedOnce } from './passphrase.js';
18
+ import { alive, runningOf } from './spawn.js';
19
+ import { nodeFinished } from './runtime.js';
20
+ import { askedKey, startedOn } from './start.js';
21
+ import { moves, tried, TRYING } from './trial.js';
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
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+ const VERSION = /^\d+\.\d+\.\d+$/;
67
+ const DIGEST = /^[0-9a-f]{64}$/;
68
+
69
+ const goneBack = async (given , home ) => {
70
+ if (!existsSync(beforeOf(home))) return false;
71
+ const went = wentBack(home);
72
+ if (went.why !== undefined) return { why: went.why };
73
+ const folder = readFolder(home);
74
+ if ('why' in folder || runningOf(home) !== null) return true;
75
+ const key = await askedKey(given, folder.laid);
76
+ if (key !== null && 'why' in key) return key;
77
+ return (await startedOn(home, key)) ?? true;
78
+ };
79
+
80
+ export const REAL = {
81
+ view: (spec, taking) =>
82
+ Promise.resolve(taking.package === undefined ? viewed(spec, taking.channel ?? null) : atHand(taking.package)),
83
+ take: taken,
84
+ keep: keptOld,
85
+ moves,
86
+ tried: (given, home, installer, floor) => {
87
+ const folder = readFolder(home);
88
+ if ('why' in folder) return Promise.resolve(folder);
89
+ return tried(given, home, folder.laid, installer, { ...TRYING, floor });
90
+ },
91
+ ...BRIDGING,
92
+ back: goneBack,
93
+ handOver: handedOver,
94
+ sealed: (_given, home, genome) => sealedBack(home, genome),
95
+ commit: committed,
96
+ left: leftIn,
97
+ ran: (home) => (runningOf(home) === null ? null : (ranOn(home) ?? '0.0.0')),
98
+ install,
99
+ account: (print) => accountHeld(print),
100
+ node: () => nodeFinished(),
101
+ handed: process.env['NERVUR_HANDED'] ?? null,
102
+ alive,
103
+ pid: process.pid,
104
+ parent: process.ppid,
105
+ };
106
+
107
+ const checked = (home , installer , reaches ) => {
108
+ const ran = reaches.ran(home);
109
+ if (ran !== installer)
110
+ return { why: `the organism runs on installer-node ${ran ?? 'none'}, where ${installer} was asked` };
111
+ return null;
112
+ };
113
+
114
+ const finished = async (given , reaches , installer , taking ) => {
115
+ const home = organismOf(given.home);
116
+ if (installer !== INSTALLER_VERSION)
117
+ return { why: `installer-node ${installer} was asked, and the command that runs carries ${INSTALLER_VERSION}` };
118
+ const ran = reaches.ran(home);
119
+ if (ran !== null && isOlder(installer, ran))
120
+ return {
121
+ why: `installer-node ${installer} is older than ${ran}, which the organism runs: a genome never carries memory backwards`,
122
+ };
123
+ const once = { ...given, asker: askedOnce(given.asker) };
124
+ if (reaches.moves(home, installer)) {
125
+ const floors = await floorsAside(once, reaches, home, taking);
126
+ if ('why' in floors) return floors;
127
+ const floor =
128
+ floors.length === 0
129
+ ? null
130
+ : (asked , at ) => floored(asked, reaches, at, floors);
131
+ const trial = await reaches.tried(once, home, installer, floor);
132
+ if (trial !== null) return trial;
133
+ }
134
+ const done = await reaches.install(once);
135
+ const end = done ?? checked(home, installer, reaches);
136
+ if (end !== null) return end;
137
+ const left = reaches.left(home);
138
+ if (left.length > 0)
139
+ return {
140
+ why: `the organism runs on installer-node ${installer}, and the update is not finished, so run it again: ${left.join('; ')}`,
141
+ };
142
+ given.print(`The organism runs on installer-node ${installer}.`);
143
+ return null;
144
+ };
145
+
146
+ const askedOf = (given ) => {
147
+ const word = given.words[1];
148
+ if (word === undefined) return null;
149
+ return VERSION.test(word) ? word : { why: `a version is three whole numbers joined by dots, not ${word}` };
150
+ };
151
+
152
+ const takingOf = (given ) => {
153
+ const digest = given.words[2];
154
+ if (digest !== undefined && !DIGEST.test(digest)) return { why: `a digest is 64 hex digits, not ${digest}` };
155
+ return {
156
+ ...(digest === undefined ? {} : { digest }),
157
+ ...(given.channel === null ? {} : { channel: given.channel }),
158
+ ...(given.package === null ? {} : { package: given.package }),
159
+ };
160
+ };
161
+
162
+ const handedTo = async (given , reaches , found , taking ) => {
163
+ const home = organismOf(given.home);
164
+ const stands = 'laid' in readFolder(home);
165
+ if (stands) {
166
+ const kept = await reaches.keep(home);
167
+ if (kept !== null) return kept;
168
+ }
169
+ const laid = await reaches.take(found.version, taking);
170
+ const code = laid ?? (await handed(given, reaches, found));
171
+ if (code === 0) return null;
172
+ const back = stands ? await reaches.back(given, home) : false;
173
+ if (typeof back === 'object') return { why: `the way back failed: ${back.why}` };
174
+ if (back) given.print(`The organism went back to installer-node ${INSTALLER_VERSION}.`);
175
+ return typeof code === 'number' ? { exit: code } : code;
176
+ };
177
+
178
+ const handed = (given , reaches , found ) => {
179
+ given.print(`nervur@${found.version} is installed, and takes over.`);
180
+ return reaches.handOver(found.installer);
181
+ };
182
+
183
+ const movedBack = async (given , reaches , found , taking ) => {
184
+ const home = organismOf(given.home);
185
+ if (isOlder(found.installer, FLOOR))
186
+ return {
187
+ why: `installer-node ${found.installer} stands below ${FLOOR}, the oldest genome that carries this organism forward: nothing changed`,
188
+ };
189
+ const kept = await reaches.keep(home);
190
+ if (kept !== null) return kept;
191
+ const failed = async (why ) => {
192
+ const back = await reaches.back(given, home);
193
+ if (typeof back === 'object') return { why: `${why.why}, and the way back failed: ${back.why}` };
194
+ return { why: `${why.why}: the organism went back to installer-node ${INSTALLER_VERSION}` };
195
+ };
196
+ const laid = await reaches.take(found.version, taking);
197
+ if (laid !== null) return failed(laid);
198
+ const file = await reaches.sealed(given, home, found.installer);
199
+ if (typeof file !== 'string') return failed(file);
200
+ const words = ['restore', file, ...(given.served ? [] : ['--home', given.home])];
201
+ const code = await reaches.handOver(found.installer, words);
202
+ if (typeof code === 'object') return failed(code);
203
+ if (code !== 0) return failed({ why: `the older installer ended ${code}` });
204
+ reaches.commit(home);
205
+ given.print(`The organism moved back to installer-node ${found.installer}, every relation whole.`);
206
+ return null;
207
+ };
208
+
209
+ const byChannel = async (given , reaches , asked , taking ) => {
210
+ const home = organismOf(given.home);
211
+ const found = await reaches.view(asked === null ? 'nervur@latest' : `nervur@${asked}`, taking);
212
+ const ran = reaches.ran(home);
213
+ if ('why' in found) {
214
+ if (ran !== null || (asked !== null && asked !== INSTALLER_VERSION)) return found;
215
+ given.print(`${found.why}: the installer at hand, ${INSTALLER_VERSION}, goes on.`);
216
+ return finished(given, reaches, INSTALLER_VERSION, taking);
217
+ }
218
+ if (ran !== null && isOlder(found.installer, ran)) {
219
+ if (asked === null)
220
+ return {
221
+ why: `nervur@${found.version} carries installer-node ${found.installer}, older than ${ran}, which the organism runs: name that version to go back to it`,
222
+ };
223
+ return movedBack(given, reaches, found, taking);
224
+ }
225
+ if (ran === found.installer && found.installer !== INSTALLER_VERSION) {
226
+ given.print(`The organism runs installer-node ${ran}, nervur@${found.version}, already: nothing changes.`);
227
+ return null;
228
+ }
229
+ if (found.installer === INSTALLER_VERSION && taking.digest === undefined)
230
+ return finished(given, reaches, found.installer, taking);
231
+ return handedTo(given, reaches, found, taking);
232
+ };
233
+
234
+ export const act = async (given , reaches = REAL) => {
235
+ const asked = askedOf(given);
236
+ if (typeof asked === 'object' && asked !== null) return asked;
237
+ const channel = given.served || given.take;
238
+ if (!channel && asked !== null)
239
+ return { why: 'a home of its own takes no version: it is for tests, on the installer at hand' };
240
+ const tooLong = socketTooLong(socketOf(organismOf(given.home)));
241
+ if (tooLong !== null) return { why: tooLong };
242
+ const word = floorWordOf(given) ?? claimWordOf(given) ?? (await designWordOf(given));
243
+ if (word !== null) return word;
244
+ const taking = takingOf(given);
245
+ if ('why' in taking) return taking;
246
+ const lock = locked(given.home, reaches);
247
+ if ('why' in lock) return lock;
248
+ try {
249
+ if (reaches.handed !== null) return await finished(given, reaches, reaches.handed, taking);
250
+ if (!channel) return await finished(given, reaches, INSTALLER_VERSION, taking);
251
+ const account = await reaches.account(given.print);
252
+ if ('why' in account) return account;
253
+ try {
254
+ return reaches.node() ?? (await byChannel(given, reaches, asked, taking));
255
+ } finally {
256
+ account.free();
257
+ }
258
+ } finally {
259
+ lock.free();
260
+ }
261
+ };
@@ -0,0 +1,3 @@
1
+ type Typed = (words: string) => string;
2
+ export declare const shown: (words: readonly string[], text: string, typed?: Typed) => string[];
3
+ export {};
@@ -0,0 +1,232 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { isFields, readText, } from '@nervur.org/genome/standard';
3
+
4
+ const fieldsAt = (data ) => (data !== undefined && isFields(data) ? data : {});
5
+ const listAt = (data ) => (Array.isArray(data) ? data : []);
6
+ const textAt = (fields , key ) => {
7
+ const found = fields[key];
8
+ return typeof found === 'string' ? found : null;
9
+ };
10
+ const numberAt = (fields , key ) => {
11
+ const found = fields[key];
12
+ return typeof found === 'number' ? found : 0;
13
+ };
14
+
15
+ const gigabytes = (bytes ) => String(Number((bytes / 1e9).toPrecision(2)));
16
+
17
+ const statusesOf = (nodes ) => {
18
+ const statuses = new Map ();
19
+ for (const node of nodes)
20
+ for (const wire of listAt(node['wires']).map(fieldsAt)) {
21
+ const termination = textAt(wire, 'termination');
22
+ const status = textAt(wire, 'status');
23
+ if (termination !== null && status !== null && statuses.get(termination) !== 'not ready')
24
+ statuses.set(termination, status);
25
+ }
26
+ return statuses;
27
+ };
28
+
29
+ const said = (status ) =>
30
+ status === undefined || status === 'connected' ? '' : ` (${status})`;
31
+
32
+ const wiresOf = (node ) => listAt(node['wires']).map(fieldsAt);
33
+
34
+ const farLines = (nodes ) => {
35
+ const far = nodes
36
+ .filter((node) => node['kind'] === 'far')
37
+ .map((node) => {
38
+ const id = textAt(node, 'id') ?? '?';
39
+ const reached =
40
+ textAt(node, 'direction') === 'occupant'
41
+ ? wiresOf(node).flatMap((wire) => textAt(wire, 'termination') ?? [])
42
+ : nodes.flatMap((other) =>
43
+ wiresOf(other)
44
+ .filter((wire) => textAt(wire, 'termination') === id)
45
+ .map((wire) => `${textAt(wire, 'placeholder') ?? '?'} of ${textAt(other, 'id') ?? '?'}`),
46
+ );
47
+ return `${id} ${textAt(node, 'direction') ?? 'far'}${reached.length === 0 ? '' : ` (${reached.join(', ')})`}`;
48
+ });
49
+ return far.length === 0 ? [] : [`far: ${far.join(', ')}`];
50
+ };
51
+
52
+ const moreLines = (cursor , placeholder , typed ) => {
53
+ if (cursor === null) return [];
54
+ const reads =
55
+ placeholder === 'brain'
56
+ ? `${typed('state')} reads every page`
57
+ : `${typed(`ask ${placeholder} state '${JSON.stringify({ cursor })}'`)} reads the next`;
58
+ return [`one page of more, the rest not read: ${reads}`];
59
+ };
60
+
61
+ const stateLines = (state , placeholder , typed ) => {
62
+ const nodes = listAt(state['nodes']).map(fieldsAt);
63
+ const statuses = statusesOf(nodes);
64
+ const anchor = textAt(state, 'anchor');
65
+ const present = listAt(state['presentLobes']);
66
+ const afar = listAt(state['relations']).length;
67
+ const owners =
68
+ state['owned'] !== true
69
+ ? 'not owned'
70
+ : anchor !== null && present.includes(anchor)
71
+ ? `owned at its console (${anchor})`
72
+ : `owned from afar${anchor === null ? '' : ` (${anchor})`}`;
73
+ const lobes = nodes
74
+ .filter((node) => node['kind'] === 'lobe' && node['core'] !== true)
75
+ .map((node) => {
76
+ const id = textAt(node, 'id') ?? '?';
77
+ const faults = numberAt(node, 'faults');
78
+ const cutOffs = numberAt(node, 'cutOffs');
79
+ const troubles = [
80
+ ...(faults > 0 ? [`${faults} fault${faults === 1 ? '' : 's'}`] : []),
81
+ ...(cutOffs > 0 ? [`${cutOffs} cut off`] : []),
82
+ ];
83
+ const named = [textAt(node, 'blueprint'), textAt(node, 'label')].flatMap((one) => one ?? []);
84
+ return `${[id, ...named].join(' ')}${troubles.length === 0 ? '' : ` (${troubles.join(', ')})`}${said(statuses.get(id))}`;
85
+ });
86
+ const organs = nodes
87
+ .filter((node) => node['kind'] === 'organ' && node['id'] !== 'brain')
88
+ .map((node) => {
89
+ const id = textAt(node, 'id') ?? '?';
90
+ return `${id}${said(statuses.get(id))}`;
91
+ })
92
+ .toSorted();
93
+ const core = nodes
94
+ .filter((node) => node['core'] === true)
95
+ .flatMap((node) => textAt(node, 'id') ?? [])
96
+ .toSorted();
97
+ const vitals = fieldsAt(state['vitals']);
98
+ const disk = fieldsAt(vitals['disk']);
99
+ const memory = fieldsAt(vitals['memory']);
100
+ return [
101
+ `${textAt(state, 'level') ?? 'unknown'}, ${owners}, ${afar === 0 ? 'no owners from afar' : `${afar} owner${afar === 1 ? '' : 's'} from afar`}`,
102
+ `organs: ${organs.length === 0 ? 'none' : organs.join(', ')}`,
103
+ `lobes: ${lobes.length === 0 ? 'none' : lobes.join(', ')}`,
104
+ ...farLines(nodes),
105
+ `core: ${core.join(', ')}`,
106
+ `${vitals['disk'] === null ? 'disk not read yet' : `disk ${gigabytes(numberAt(disk, 'used'))} of ${gigabytes(numberAt(disk, 'total'))} GB used`}, memory ${gigabytes(numberAt(memory, 'used'))} of ${gigabytes(numberAt(memory, 'total'))} GB, load ${Number(numberAt(vitals, 'load').toFixed(2))}`,
107
+ `fingerprint ${(textAt(state, 'fingerprint') ?? '').slice(0, 12)}`,
108
+ ...moreLines(textAt(state, 'cursor'), placeholder, typed),
109
+ ];
110
+ };
111
+
112
+ const isState = (words ) =>
113
+ (words.length === 3 || words.length === 4) && words[0] === 'ask' && words[2] === 'state';
114
+
115
+ const ownLines = (words , result , typed ) => {
116
+ const [verb, first, second] = words;
117
+ if (verb === 'accept' && isFields(result) && first !== undefined)
118
+ return [`${first} is accepted, as ${textAt(result, 'far') ?? '?'}: ${typed(`ask ${first}`)} describes it`];
119
+ if (verb === 'relations' && Array.isArray(result))
120
+ return result.map(fieldsAt).map((one) => `${textAt(one, 'placeholder') ?? '?'}, as ${textAt(one, 'far') ?? '?'}`);
121
+ if (verb === 'forget' && first !== undefined && isFields(result))
122
+ return result['left'] === true
123
+ ? [`${first} is forgotten, and you are its owner no longer`]
124
+ : [
125
+ `${first} is forgotten here, but it did not answer (${textAt(result, 'why') ?? '?'}), so it may still list you as its owner: its owner drops you there`,
126
+ ];
127
+ return verb === 'ask' && isFields(result) && first !== undefined ? brainLines(first, second, result, typed) : null;
128
+ };
129
+
130
+ const brainLines = (placeholder , method , result , typed ) => {
131
+ const invitation = textAt(result, 'invitation');
132
+ const far = textAt(result, 'far');
133
+ if (method === 'invite' && invitation !== null)
134
+ return [
135
+ invitation,
136
+ "Its owner accepts it on their device: nervur accept <a name of theirs> '<the invitation>', or, these lines saved to a file, nervur accept <a name of theirs> --text invitation=<the file>",
137
+ ...(far === null
138
+ ? []
139
+ : [
140
+ `Once accepted, its owner is ${far} in the state, as ${typed(`ask ${placeholder} drop '{"far":"${far}"}'`)} names it.`,
141
+ ]),
142
+ ];
143
+ if (placeholder !== 'brain') return null;
144
+ const id = textAt(result, 'id');
145
+ if (method === 'create' && id !== null)
146
+ return [`The lobe ${id} stands: ${typed(`lobe ${id}`)} describes it`, ...shownLines(fieldsAt(result['shown']))];
147
+ const wired = textAt(result, 'placeholder');
148
+ if (method === 'order' && wired !== null) return [`wired, as the placeholder ${wired}`];
149
+ return null;
150
+ };
151
+
152
+ const shownLines = (shown ) => {
153
+ if (Object.keys(shown).length === 0) return [];
154
+ const name = textAt(shown, 'name');
155
+ const version = textAt(shown, 'version');
156
+ const placeholders = Object.entries(fieldsAt(shown['placeholders'])).map(
157
+ ([placeholder, expected]) => `${placeholder} expecting ${typeof expected === 'string' ? expected : 'anything'}`,
158
+ );
159
+ const skins = listAt(shown['skins']).flatMap((one) => (typeof one === 'string' ? [one] : []));
160
+ return [
161
+ ...(name === null ? [] : [`It stands on ${name}${version === null ? '' : ` ${version}`}`]),
162
+ `placeholders: ${placeholders.length === 0 ? 'none' : placeholders.join(', ')}`,
163
+ skins.length === 0 ? 'a skin lobe of no organ' : `a skin lobe of the organs ${skins.join(', ')}`,
164
+ shown['world'] === true ? 'it talks to the world, a skin lobe of network' : 'it talks not to the world',
165
+ ];
166
+ };
167
+
168
+ const argsShown = (args ) => {
169
+ const schema = fieldsAt(args);
170
+ const required = new Set(listAt(schema['required']).flatMap((one) => (typeof one === 'string' ? [one] : [])));
171
+ const names = Object.keys(fieldsAt(schema['properties']));
172
+ return names.length === 0 ? '' : ` {${names.map((name) => (required.has(name) ? name : `[${name}]`)).join(', ')}}`;
173
+ };
174
+
175
+ const methodsOf = (blueprint ) =>
176
+ Array.isArray(blueprint['asks'])
177
+ ? blueprint['asks'].map(fieldsAt).flatMap((entry) => {
178
+ const name = textAt(entry, 'method');
179
+ return name === null ? [] : [[name, entry] ];
180
+ })
181
+ : Object.entries(fieldsAt(blueprint['methods']));
182
+ const describedLines = (blueprint ) => {
183
+ const description = textAt(blueprint, 'description');
184
+ const methods = methodsOf(blueprint).map(([name, entry]) => {
185
+ const method = fieldsAt(entry);
186
+ const kind = textAt(method, 'kind');
187
+ const told = textAt(method, 'description');
188
+ return ` ${name}${argsShown(method['args'])}${kind === null ? '' : `, ${kind}`}${told === null ? '' : `: ${told}`}`;
189
+ });
190
+ return [`${textAt(blueprint, 'name') ?? 'a node'}${description === null ? '' : `: ${description}`}`, ...methods];
191
+ };
192
+
193
+ const isDescribe = (words ) =>
194
+ words.length === 2 && (words[0] === 'ask' || words[0] === 'lobe');
195
+
196
+ const NOT_REACHED =
197
+ 'No one answered at the address this invitation names: that organism is off, or no one can dial it. It is reached at a public address (`--public`), or by an invitation drawn through an organism always on (`through`).';
198
+
199
+
200
+ export const shown = (words , text , typed = (line) => `nervur ${line}`) => {
201
+ const read = readText(text);
202
+ if (!('data' in read) || !isFields(read.data)) return [text];
203
+ const answer = read.data;
204
+ if ('error' in answer) {
205
+ const error = fieldsAt(answer['error']);
206
+ const code = textAt(error, 'code');
207
+ const told = `${code ?? 'error'}: ${textAt(error, 'message') ?? ''}`;
208
+ return words[0] === 'accept' && (code === 'timeout' || code === 'unavailable') ? [told, NOT_REACHED] : [told];
209
+ }
210
+ const result = answer['result'];
211
+ if (result === null || result === undefined) return ['done'];
212
+ if (typeof result === 'string') return [result];
213
+ if (result instanceof Uint8Array) return [bytesShown(result)];
214
+ if (Array.isArray(result) && result.length === 0) return ['none'];
215
+ if (isState(words) && isFields(result)) return stateLines(result, words[1] ?? 'brain', typed);
216
+ if (isDescribe(words) && isFields(result)) return describedLines(result);
217
+ const own = ownLines(words, result, typed);
218
+ if (own !== null) return own;
219
+ return JSON.stringify(result, bytesAsShown, 2).split('\n');
220
+ };
221
+
222
+ const bytesShown = (bytes ) => {
223
+ try {
224
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
225
+ if (!/[\u0000-\u0008\u000b-\u001f\u007f]/.test(text)) return text;
226
+ } catch {
227
+ }
228
+ return `${bytes.length} bytes: ${Buffer.from(bytes).toString('hex')}`;
229
+ };
230
+
231
+ const bytesAsShown = (_key , value ) =>
232
+ value instanceof Uint8Array ? bytesShown(value) : value;
@@ -0,0 +1,14 @@
1
+ import { type Given, type Outcome } from './commands.js';
2
+ export type Command = (given: Given) => Promise<Outcome>;
3
+ type Why = {
4
+ readonly why: string;
5
+ };
6
+ export declare const COMMAND_NAMES: readonly string[];
7
+ export type Read = {
8
+ readonly command: Command;
9
+ readonly given: Omit<Given, 'asker' | 'print' | 'answer'>;
10
+ };
11
+ export declare const readArgs: (argv: readonly string[]) => Read | Why | {
12
+ readonly help: true;
13
+ };
14
+ export {};