@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,147 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import {
3
+ accessSync,
4
+ chmodSync,
5
+ constants,
6
+ cpSync,
7
+ existsSync,
8
+ mkdirSync,
9
+ readdirSync,
10
+ readFileSync,
11
+ realpathSync,
12
+ rmSync,
13
+ symlinkSync,
14
+ statSync,
15
+ } from 'node:fs';
16
+ import { dirname, join } from 'node:path';
17
+ import { foldersLaid, laidWhole, treeFlushed } from '../fills/flushed.js';
18
+
19
+ const NAME = '@nervur.org/genome';
20
+ const MARK = '.laid';
21
+
22
+ const manifestOf = (
23
+ folder ,
24
+ ) => {
25
+ const file = join(folder, 'package.json');
26
+ if (!existsSync(file)) return null;
27
+ const read = JSON.parse(readFileSync(file, 'utf8'));
28
+ if (typeof read !== 'object' || read === null) return null;
29
+ const name = 'name' in read && typeof read.name === 'string' ? read.name : null;
30
+ const version = 'version' in read && typeof read.version === 'string' ? read.version : null;
31
+ const deps =
32
+ 'dependencies' in read && typeof read.dependencies === 'object' && read.dependencies !== null
33
+ ? read.dependencies
34
+ : {};
35
+ return name === null || version === null ? null : { name, version, dependencies: Object.keys(deps) };
36
+ };
37
+
38
+ const resolved = (from , name ) => {
39
+ for (let folder = from; ; folder = dirname(folder)) {
40
+ const found = join(folder, 'node_modules', name);
41
+ if (manifestOf(found) !== null) return realpathSync(found);
42
+ if (folder === dirname(folder)) return null;
43
+ }
44
+ };
45
+
46
+ const closure = (genome ) => {
47
+ const all = new Map ([[NAME, genome]]);
48
+ const queue = [genome];
49
+ for (const folder of queue) {
50
+ for (const name of manifestOf(folder)?.dependencies ?? []) {
51
+ if (all.has(name)) continue;
52
+ const found = resolved(folder, name);
53
+ if (found === null) return { missing: name };
54
+ all.set(name, found);
55
+ queue.push(found);
56
+ }
57
+ }
58
+ return all;
59
+ };
60
+
61
+ const opened = (folder ) => {
62
+ chmodSync(folder, 0o755);
63
+ for (const entry of readdirSync(folder, { withFileTypes: true })) {
64
+ const path = join(folder, entry.name);
65
+ if (entry.isDirectory()) opened(path);
66
+ else chmodSync(path, 0o644);
67
+ }
68
+ };
69
+
70
+ const allowed = (folder ) => {
71
+ try {
72
+ chmodSync(folder, statSync(folder).mode | 0o711);
73
+ } catch {
74
+ }
75
+ };
76
+
77
+ const unshipped = (from ) => {
78
+ const read = JSON.parse(readFileSync(join(from, 'package.json'), 'utf8'));
79
+ const exported = typeof read === 'object' && read !== null && 'exports' in read ? JSON.stringify(read.exports) : '';
80
+ const left = [join(from, 'node_modules'), ...(exported.includes('./dist/') ? [] : [join(from, 'dist')])];
81
+ return (path) =>
82
+ left.some((folder) => path === folder || path.startsWith(`${folder}/`)) ||
83
+ /\.test\.[cm]?[jt]s$/.test(path) ||
84
+ path.slice(from.length).split('/').includes('test');
85
+ };
86
+
87
+ export const lendGenome = (base , genome , apart ) => {
88
+ const manifest = manifestOf(genome);
89
+ if (manifest === null || manifest.name !== NAME) return { why: `${genome} holds no package ${NAME}` };
90
+ if (!apart) {
91
+ try {
92
+ rmSync(join(base, 'lent'), { recursive: true, force: true });
93
+ return realpathSync(genome);
94
+ } catch (error) {
95
+ return { why: `the genome could not be lent: ${error instanceof Error ? error.message : String(error)}` };
96
+ }
97
+ }
98
+ const mark = `${manifest.version}\n`;
99
+ const lent = join(base, 'lent');
100
+ const root = join(lent, manifest.version);
101
+ const node = join(root, 'node_modules');
102
+ try {
103
+ if ((statSync(base).mode & 0o001) === 0) allowed(base);
104
+ foldersLaid(lent, 0o711);
105
+ chmodSync(lent, 0o711);
106
+ for (const old of readdirSync(lent))
107
+ if (old !== manifest.version) rmSync(join(lent, old), { recursive: true, force: true });
108
+ const laidAs = existsSync(join(root, MARK)) ? readFileSync(join(root, MARK), 'utf8') : null;
109
+ if (laidAs !== mark) {
110
+ const packages = closure(realpathSync(genome));
111
+ if ('missing' in packages) return { why: `the genome's dependency ${packages.missing} is found nowhere` };
112
+ rmSync(root, { recursive: true, force: true });
113
+ for (const [name, from] of packages) {
114
+ const to = join(node, name);
115
+ mkdirSync(dirname(to), { recursive: true });
116
+ const left = unshipped(from);
117
+ cpSync(from, to, { recursive: true, dereference: true, filter: (path) => !left(path) });
118
+ }
119
+ opened(root);
120
+ treeFlushed(root);
121
+ laidWhole(join(root, MARK), mark, 0o644);
122
+ }
123
+ chmodSync(root, 0o711);
124
+ } catch (error) {
125
+ return { why: `the genome could not be lent: ${error instanceof Error ? error.message : String(error)}` };
126
+ }
127
+ return join(node, NAME);
128
+ };
129
+
130
+ export const linkGenome = (disk , lent ) => {
131
+ try {
132
+ accessSync(disk, constants.W_OK);
133
+ } catch {
134
+ return null;
135
+ }
136
+ const scope = join(disk, 'repos', 'node_modules', '@nervur.org');
137
+ try {
138
+ mkdirSync(scope, { recursive: true });
139
+ rmSync(join(scope, 'genome'), { force: true });
140
+ symlinkSync(lent, join(scope, 'genome'));
141
+ } catch (error) {
142
+ return {
143
+ why: `the genome could not be linked above the repos: ${error instanceof Error ? error.message : String(error)}`,
144
+ };
145
+ }
146
+ return null;
147
+ };
@@ -0,0 +1,12 @@
1
+ export type Built = {
2
+ readonly text: string;
3
+ readonly digest: string;
4
+ };
5
+ export type Source = {
6
+ readonly file: string;
7
+ readonly digest: string;
8
+ };
9
+ export declare const digestOf: (file: string) => string;
10
+ export declare const nativeHalves: () => ReadonlyMap<string, Built>;
11
+ export declare const sourceDigestOf: (file: string) => string;
12
+ export declare const sourceHalves: () => ReadonlyMap<string, Source>;
@@ -0,0 +1,53 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { createHash } from 'node:crypto';
3
+ import { readFileSync } from 'node:fs';
4
+ import { PROGRAM as CONSOLE } from '../../organs/console/node/program.js';
5
+ import { PROGRAM as DISK } from '../../organs/disk/node/program.js';
6
+ import { PROGRAM as NETWORK } from '../../organs/network/node/program.js';
7
+ import { PROGRAM as SCREEN } from '../../organs/screen/node/program.js';
8
+ import { PROGRAM as SHELL } from '../../organs/shell/node/program.js';
9
+ import { buildHalves, modulesOf, } from './build.js';
10
+
11
+
12
+
13
+
14
+
15
+ const PROGRAMS = [
16
+ ['console', CONSOLE],
17
+ ['screen', SCREEN],
18
+ ['shell', SHELL],
19
+ ['disk', DISK],
20
+ ['network', NETWORK],
21
+ ];
22
+
23
+ const sha256 = (bytes ) => createHash('sha256').update(bytes).digest('hex');
24
+
25
+ export const digestOf = (file ) => sha256(readFileSync(file));
26
+
27
+ let programs ;
28
+ const builtOf = (file ) => {
29
+ programs ??= buildHalves(PROGRAMS.map(([, one]) => one));
30
+ const found = programs.get(file);
31
+ if (found === undefined) throw new Error(`Node builds no half from ${file}`);
32
+ return found;
33
+ };
34
+
35
+ const digestOver = (modules ) =>
36
+ sha256(modules.map(({ file: one, label }) => `${label} ${digestOf(one)}\n`).join(''));
37
+
38
+ let built ;
39
+
40
+ export const nativeHalves = () =>
41
+ (built ??= new Map(
42
+ PROGRAMS.map(([organ, file]) => {
43
+ const { text } = builtOf(file);
44
+ return [organ, { text, digest: sha256(text) }];
45
+ }),
46
+ ));
47
+
48
+ export const sourceDigestOf = (file ) => digestOver(modulesOf(file));
49
+
50
+ let sources ;
51
+
52
+ export const sourceHalves = () =>
53
+ (sources ??= new Map(PROGRAMS.map(([organ, file]) => [organ, { file, digest: digestOver(builtOf(file).modules) }])));
@@ -0,0 +1,23 @@
1
+ export type Binding = {
2
+ readonly imported: string;
3
+ readonly local: string;
4
+ };
5
+ export type Import = {
6
+ readonly spec: string;
7
+ readonly bindings: readonly Binding[] | null;
8
+ };
9
+ export type Pair = {
10
+ readonly imported: string;
11
+ readonly exported: string;
12
+ };
13
+ export type Reexport = {
14
+ readonly spec: string;
15
+ readonly pairs: readonly Pair[] | 'star';
16
+ };
17
+ export type Module = {
18
+ readonly body: string;
19
+ readonly imports: readonly Import[];
20
+ readonly reexports: readonly Reexport[];
21
+ readonly exports: ReadonlyMap<string, string>;
22
+ };
23
+ export declare const readModule: (text: string, label: string) => Module;
@@ -0,0 +1,165 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { blank, expect, fromOf, listOf, refused, tokenOf, } from './tokens.js';
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
+ const typesEnd = (reader , at ) => {
29
+ let token = tokenOf(reader, at);
30
+ while (token.text !== 'from' && token.text !== ';' && token.text !== '' && token.text !== '}')
31
+ token = tokenOf(reader, token.end);
32
+ if (token.text === '}') {
33
+ const after = tokenOf(reader, token.end);
34
+ if (after.text !== 'from') return after.text === ';' ? after.end : token.end;
35
+ token = after;
36
+ }
37
+ if (token.text === 'from') return fromOf(reader, token.end - 'from'.length).end;
38
+ return token.end;
39
+ };
40
+
41
+ const bindingsOf = (reading , at ) => {
42
+ const bindings = [];
43
+ let token = tokenOf(reading, at);
44
+ let end = at;
45
+ if (token.text !== '{' && token.text !== '*') {
46
+ bindings.push({ imported: 'default', local: token.text });
47
+ end = token.end;
48
+ const comma = tokenOf(reading, token.end);
49
+ if (comma.text !== ',') return { bindings, end };
50
+ token = tokenOf(reading, comma.end);
51
+ }
52
+ if (token.text === '*') {
53
+ const local = tokenOf(reading, expect(reading, token.end, 'as'));
54
+ bindings.push({ imported: '*', local: local.text });
55
+ return { bindings, end: local.end };
56
+ }
57
+ if (token.text !== '{') refused(reading, `imports ${token.text}`);
58
+ const list = listOf(reading, token.end);
59
+ for (const [imported, local] of list.names) bindings.push({ imported, local });
60
+ return { bindings, end: list.end };
61
+ };
62
+
63
+ const importAt = (reading , at ) => {
64
+ const first = tokenOf(reading, at);
65
+ if (first.text === '(') refused(reading, 'holds an import()');
66
+ if (first.text === '.') refused(reading, 'reads import.meta');
67
+ if (first.string) {
68
+ const after = tokenOf(reading, first.end);
69
+ reading.imports.push({ spec: first.text, bindings: null });
70
+ return after.text === ';' ? after.end : first.end;
71
+ }
72
+ const next = tokenOf(reading, first.end);
73
+ if (first.text === 'type' && next.text !== 'from' && next.text !== ',') return typesEnd(reading, first.end);
74
+ const { bindings, end } = bindingsOf(reading, at);
75
+ const from = fromOf(reading, end);
76
+ if (bindings.length > 0) reading.imports.push({ spec: from.spec, bindings });
77
+ return from.end;
78
+ };
79
+
80
+ const givenAt = (reading , token ) => {
81
+ if (token.text === '*') {
82
+ const as = tokenOf(reading, token.end);
83
+ const name = as.text === 'as' ? tokenOf(reading, as.end) : null;
84
+ const from = fromOf(reading, name?.end ?? token.end);
85
+ const pairs = name === null ? 'star' : [{ imported: '*', exported: name.text }];
86
+ reading.reexports.push({ spec: from.spec, pairs });
87
+ return from.end;
88
+ }
89
+ const list = listOf(reading, token.end);
90
+ const after = tokenOf(reading, list.end);
91
+ if (after.text === 'from') {
92
+ const from = fromOf(reading, list.end);
93
+ const pairs = list.names.map(([imported, exported]) => ({ imported, exported }));
94
+ if (pairs.length > 0) reading.reexports.push({ spec: from.spec, pairs });
95
+ return from.end;
96
+ }
97
+ for (const [local, exported] of list.names) reading.exports.set(exported, local);
98
+ return after.text === ';' ? after.end : list.end;
99
+ };
100
+
101
+ const declaredOf = (reading , at ) => {
102
+ let token = tokenOf(reading, at);
103
+ if (token.text === 'type' || token.text === 'interface' || token.text === 'declare') return null;
104
+ if (token.text === 'let' || token.text === 'var')
105
+ refused(reading, `gives a ${token.text}, which one file would not keep live`);
106
+ if (token.text === 'default') refused(reading, 'gives a default');
107
+ if (token.text === 'async' || token.text === 'abstract') token = tokenOf(reading, token.end);
108
+ if (!['const', 'function', 'class'].includes(token.text)) refused(reading, `gives ${token.text}`);
109
+ let name = tokenOf(reading, token.end);
110
+ if (name.text === '*') name = tokenOf(reading, name.end);
111
+ if (!/^[A-Za-z_$]/.test(name.text)) refused(reading, `gives a ${token.text} it does not name`);
112
+ return name.text;
113
+ };
114
+
115
+ const exportAt = (reading , start , at ) => {
116
+ const token = tokenOf(reading, at);
117
+ if (token.text === '{' || token.text === '*') return { start, end: givenAt(reading, token), whole: true };
118
+ if (token.text === 'type' && tokenOf(reading, token.end).text === '{')
119
+ return { start, end: typesEnd(reading, token.end), whole: true };
120
+ const name = declaredOf(reading, at);
121
+ if (name !== null) reading.exports.set(name, name);
122
+ return { start, end: at, whole: false };
123
+ };
124
+
125
+ const opens = (reading , at , end ) => {
126
+ let before = at - 1;
127
+ while (before >= 0 && /\s/.test(reading.blanked[before] ?? '')) before -= 1;
128
+ return reading.blanked[before] !== '.' && tokenOf(reading, end).text !== ':';
129
+ };
130
+
131
+ const bodyOf = (text , cuts ) => {
132
+ let body = '';
133
+ let at = 0;
134
+ for (const cut of cuts) {
135
+ const taken = text.slice(cut.start, cut.end);
136
+ body += text.slice(at, cut.start) + (cut.whole ? taken.replace(/[^\n]/g, '') : ' '.repeat(taken.length));
137
+ at = cut.end;
138
+ }
139
+ return body + text.slice(at);
140
+ };
141
+
142
+ export const readModule = (text , label ) => {
143
+ const reading = {
144
+ text,
145
+ blanked: blank(text),
146
+ label,
147
+ imports: [],
148
+ reexports: [],
149
+ exports: new Map(),
150
+ };
151
+ const cuts = [];
152
+ let cursor = 0;
153
+ for (const found of reading.blanked.matchAll(/\b(?:import|export)\b/g)) {
154
+ const end = found.index + found[0].length;
155
+ if (found.index < cursor || !opens(reading, found.index, end)) continue;
156
+ const cut =
157
+ found[0] === 'import'
158
+ ? { start: found.index, end: importAt(reading, end), whole: true }
159
+ : exportAt(reading, found.index, end);
160
+ cuts.push(cut);
161
+ cursor = cut.end;
162
+ }
163
+ const { imports, reexports, exports } = reading;
164
+ return { body: bodyOf(text, cuts), imports, reexports, exports };
165
+ };
@@ -0,0 +1,22 @@
1
+ export type Token = {
2
+ readonly text: string;
3
+ readonly string: boolean;
4
+ readonly end: number;
5
+ };
6
+ export type Reader = {
7
+ readonly text: string;
8
+ readonly blanked: string;
9
+ readonly label: string;
10
+ };
11
+ export declare const blank: (text: string) => string;
12
+ export declare const tokenOf: (reader: Reader, at: number) => Token;
13
+ export declare const refused: (reader: Reader, why: string) => never;
14
+ export declare const expect: (reader: Reader, at: number, wanted: string) => number;
15
+ export declare const fromOf: (reader: Reader, at: number) => {
16
+ readonly spec: string;
17
+ readonly end: number;
18
+ };
19
+ export declare const listOf: (reader: Reader, at: number) => {
20
+ readonly names: readonly (readonly [string, string])[];
21
+ readonly end: number;
22
+ };
@@ -0,0 +1,135 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+
3
+
4
+
5
+
6
+
7
+ const closing = (text , at ) => {
8
+ const quote = text[at];
9
+ let i = at + 1;
10
+ while (i < text.length && text[i] !== quote) i += text[i] === '\\' ? 2 : 1;
11
+ return Math.min(i + 1, text.length);
12
+ };
13
+
14
+ const commentEnd = (text , at ) => {
15
+ const line = text[at + 1] === '/';
16
+ const found = line ? text.indexOf('\n', at) : text.indexOf('*/', at + 2);
17
+ if (found < 0) return text.length;
18
+ return line ? found : found + 2;
19
+ };
20
+
21
+ const BEFORE_REGEX = new Set(['return', 'typeof', 'case', 'in', 'of', 'void', 'delete', 'throw', 'new', 'else', 'do']);
22
+ const OPENS_EXPRESSION = '(,=:[!&|?{};+-*%<>~^';
23
+
24
+ const opensRegex = (out ) => {
25
+ const before = out.trimEnd();
26
+ const last = before.at(-1);
27
+ if (last === undefined) return true;
28
+ if (/[\w$]/.test(last)) return BEFORE_REGEX.has(/[\w$]+$/.exec(before)?.[0] ?? '');
29
+ return OPENS_EXPRESSION.includes(last);
30
+ };
31
+
32
+ const regexEnd = (text , at ) => {
33
+ let i = at + 1;
34
+ let inClass = false;
35
+ while (i < text.length && text[i] !== '\n' && (inClass || text[i] !== '/')) {
36
+ if (text[i] === '\\') i += 1;
37
+ else if (text[i] === '[') inClass = true;
38
+ else if (text[i] === ']') inClass = false;
39
+ i += 1;
40
+ }
41
+ if (text[i] !== '/') return at + 1;
42
+ i += 1;
43
+ while (/[a-z]/.test(text[i] ?? '')) i += 1;
44
+ return i;
45
+ };
46
+
47
+ export const blank = (text ) => {
48
+ let out = '';
49
+ let i = 0;
50
+ while (i < text.length) {
51
+ const two = text.slice(i, i + 2);
52
+ const comment = two === '//' || two === '/*';
53
+ if (!comment && text[i] === '/' && opensRegex(out)) {
54
+ const to = regexEnd(text, i);
55
+ if (to > i + 1) {
56
+ out += text.slice(i, to).replace(/[^\n]/g, ' ');
57
+ i = to;
58
+ continue;
59
+ }
60
+ }
61
+ const quoted = text[i] === '"' || text[i] === "'" || text[i] === '`';
62
+ if (!comment && !quoted) {
63
+ out += text[i];
64
+ i += 1;
65
+ continue;
66
+ }
67
+ const to = comment ? commentEnd(text, i) : closing(text, i);
68
+ const inside = text.slice(i, to).replace(/[^\n]/g, ' ');
69
+ out += quoted ? `${text[i]}${inside.slice(1, -1)}${text[to - 1]}` : inside;
70
+ i = to;
71
+ }
72
+ return out;
73
+ };
74
+
75
+ const WORD = /[A-Za-z_$][\w$]*/y;
76
+
77
+ export const tokenOf = (reader , at ) => {
78
+ const { text, blanked } = reader;
79
+ let i = at;
80
+ while (i < blanked.length && /\s/.test(blanked[i] ?? '')) i += 1;
81
+ const first = blanked[i] ?? '';
82
+ if (first === '"' || first === "'") {
83
+ const end = blanked.indexOf(first, i + 1) + 1;
84
+ return { text: text.slice(i + 1, end - 1), string: true, end };
85
+ }
86
+ WORD.lastIndex = i;
87
+ const word = WORD.exec(blanked)?.[0];
88
+ if (word !== undefined) return { text: word, string: false, end: i + word.length };
89
+ return { text: first, string: false, end: i + 1 };
90
+ };
91
+
92
+ export const refused = (reader , why ) => {
93
+ throw new Error(`a half is built of plain modules: ${reader.label} ${why}`);
94
+ };
95
+
96
+ export const expect = (reader , at , wanted ) => {
97
+ const token = tokenOf(reader, at);
98
+ if (token.text !== wanted || token.string) refused(reader, `holds ${token.text} where ${wanted} stands`);
99
+ return token.end;
100
+ };
101
+
102
+ export const fromOf = (reader , at ) => {
103
+ const spec = tokenOf(reader, expect(reader, at, 'from'));
104
+ if (!spec.string) refused(reader, 'imports from no string');
105
+ const after = tokenOf(reader, spec.end);
106
+ return { spec: spec.text, end: after.text === ';' ? after.end : spec.end };
107
+ };
108
+
109
+ const typeAlone = (token , next ) =>
110
+ token.text === 'type' && !next.string && /^[A-Za-z_$]/.test(next.text) && next.text !== 'as';
111
+
112
+ export const listOf = (
113
+ reader ,
114
+ at ,
115
+ ) => {
116
+ const names = [];
117
+ let token = tokenOf(reader, at);
118
+ while (token.text !== '}') {
119
+ const next = tokenOf(reader, token.end);
120
+ const typed = typeAlone(token, next);
121
+ const name = typed ? next : token;
122
+ let after = tokenOf(reader, name.end);
123
+ let alias = name.text;
124
+ if (after.text === 'as') {
125
+ const aliased = tokenOf(reader, after.end);
126
+ alias = aliased.text;
127
+ after = tokenOf(reader, aliased.end);
128
+ }
129
+ if (!typed) names.push([name.text, alias]);
130
+ if (after.text === ',') after = tokenOf(reader, after.end);
131
+ else if (after.text !== '}') refused(reader, `lists ${after.text} among its names`);
132
+ token = after;
133
+ }
134
+ return { names, end: token.end };
135
+ };
@@ -0,0 +1,4 @@
1
+ export { cardOfVouch, readLink, type Card, type CardLink, type DomainLink } from '@nervur.org/genome/quo';
2
+ export type Why = {
3
+ readonly why: string;
4
+ };
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ export { cardOfVouch, readLink, } from '@nervur.org/genome/quo';
3
+
4
+
@@ -0,0 +1 @@
1
+ export declare const placeholderOf: (domain: string, held: ReadonlySet<string>) => string;
@@ -0,0 +1,21 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+
3
+ const LONGEST = 64;
4
+ const OWN = new Set(['screen', 'brain', 'design', 'mouth', 'ear', 'cells', 'nerves']);
5
+
6
+ const wordOf = (domain ) => {
7
+ const dashed = domain
8
+ .toLowerCase()
9
+ .replaceAll(/[^a-z0-9]+/gu, '-')
10
+ .replaceAll(/^-+|-+$/gu, '');
11
+ return /^[a-z]/u.test(dashed) ? dashed : `q-${dashed}`;
12
+ };
13
+
14
+ export const placeholderOf = (domain , held ) => {
15
+ const word = wordOf(domain);
16
+ for (let number = 1; ; number += 1) {
17
+ const suffix = number === 1 ? '' : `-${number}`;
18
+ const found = `${word.slice(0, LONGEST - suffix.length).replace(/-+$/u, '')}${suffix}`;
19
+ if (!held.has(found) && !OWN.has(found)) return found;
20
+ }
21
+ };
@@ -0,0 +1,52 @@
1
+ import { type Answer, type Data, type Fields } from '@nervur.org/genome/standard';
2
+ import { type Card } from './link.js';
3
+ export type Inviter = {
4
+ readonly domain: string | null;
5
+ readonly ward: string;
6
+ readonly named: string | null;
7
+ };
8
+ export type Offer = {
9
+ readonly says: Data;
10
+ readonly waits: number | null;
11
+ readonly lives: number | null;
12
+ };
13
+ export type Unreached = {
14
+ readonly reached: false;
15
+ };
16
+ export type Looked = Inviter & {
17
+ readonly offer: Offer | Unreached | null;
18
+ };
19
+ export type Invited = {
20
+ readonly invitation: string;
21
+ };
22
+ export type Taken = Inviter & {
23
+ readonly invitation: string;
24
+ };
25
+ export type Taking = Pick<Ports, 'vouch' | 'redeem'>;
26
+ export type Joining = Pick<Ports, 'held' | 'now' | 'accept'>;
27
+ export type Ports = {
28
+ readonly vouch: (domain: string) => Promise<string | null>;
29
+ readonly redeem: (card: Card, reference: string, domain: string | null) => Promise<Answer>;
30
+ readonly offer: (card: Card, reference: string, domain: string | null) => Promise<Answer>;
31
+ readonly accept: (by: Invited, placeholder: string, note: Data) => Promise<Answer>;
32
+ readonly held: () => Promise<readonly string[] | null>;
33
+ readonly now: () => string;
34
+ };
35
+ export declare const cardOf: (domain: string | null, given: Card | null, ports: Pick<Ports, 'vouch'>) => Promise<Card | {
36
+ readonly why: string;
37
+ }>;
38
+ export type Own = {
39
+ readonly relation?: string | null;
40
+ readonly note?: Fields | null;
41
+ };
42
+ export declare const joinInvitation: (invitation: string, domain: string | null, { relation, note: typed }: Own, ports: Joining) => Promise<{
43
+ readonly text: string;
44
+ } | {
45
+ readonly why: string;
46
+ }>;
47
+ export declare const lookLink: (text: string, ports: Ports) => Promise<Looked | {
48
+ readonly why: string;
49
+ }>;
50
+ export declare const takeLink: (text: string, ports: Taking) => Promise<Taken | {
51
+ readonly why: string;
52
+ }>;