@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,14 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { writeFileSync } from 'node:fs';
3
+
4
+ const SCORE = '/proc/self/oom_score_adj';
5
+ const HIGHEST = 1000;
6
+
7
+ export const firstUnderPressure = (file = SCORE) => {
8
+ try {
9
+ writeFileSync(file, String(HIGHEST), { flag: 'r+' });
10
+ return true;
11
+ } catch {
12
+ return false;
13
+ }
14
+ };
@@ -0,0 +1 @@
1
+ export declare const PROGRAM: string;
@@ -0,0 +1,5 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { extname } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ export const PROGRAM = fileURLToPath(new URL(`main${extname(import.meta.url)}`, import.meta.url));
@@ -0,0 +1,220 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { spawn, } from 'node:child_process';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { constants } from 'node:os';
5
+ import { FRAME_SIZE } from '../../../src/door/longest.js';
6
+ import { error, isFields, result, utf8Bytes, } from '@nervur.org/genome/standard';
7
+ import { endWithin, outputOf, } from './output.js';
8
+ import { paused, tellingOf, } from './told.js';
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ const NOT_FOUND = 127;
18
+ const BY_SIGNAL = 128;
19
+
20
+ const ENVELOPE = 65_536;
21
+ const LONGEST = Math.floor(FRAME_SIZE / 2) - ENVELOPE;
22
+
23
+ const SHORTEST = 1000;
24
+ const PRINTED_CHARACTERS = Math.floor(LONGEST / 8);
25
+
26
+
27
+
28
+ const refused = (message ) => error('refused', message);
29
+
30
+ const texts = (data ) =>
31
+ Array.isArray(data) && data.length > 0 && data.every((word) => typeof word === 'string')
32
+ ? data.filter((word) => typeof word === 'string')
33
+ : null;
34
+
35
+ const pendingOf = (
36
+
37
+
38
+
39
+ ) => {
40
+ const decoder = new TextDecoder();
41
+ let text = '';
42
+ return {
43
+ add: (chunk) => {
44
+ text += decoder.decode(chunk, { stream: true });
45
+ },
46
+ take: (most) => {
47
+ const taken = text.slice(0, most);
48
+ text = text.slice(taken.length);
49
+ return taken;
50
+ },
51
+ empty: () => text === '',
52
+ };
53
+ };
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+ const printerOf = (run , stream ) => {
64
+ const pendingOut = pendingOf();
65
+ const pendingErr = pendingOf();
66
+ const empty = () => pendingOut.empty() && pendingErr.empty();
67
+ let printing = Promise.resolve();
68
+ let busy = false;
69
+ const print = () => {
70
+ if (busy || empty()) return printing;
71
+ busy = true;
72
+ const half = Math.floor(PRINTED_CHARACTERS / 2);
73
+ const one = { run, out: pendingOut.take(half), err: pendingErr.take(half) };
74
+ const settled = () => {
75
+ busy = false;
76
+ };
77
+ printing = stream.printed(one).then(settled, settled);
78
+ return printing;
79
+ };
80
+ const timer = setInterval(() => void print(), stream.every);
81
+ return {
82
+ out: (chunk) => pendingOut.add(chunk),
83
+ err: (chunk) => pendingErr.add(chunk),
84
+ drain: async () => {
85
+ clearInterval(timer);
86
+ await printing;
87
+ while (!empty()) await print();
88
+ },
89
+ };
90
+ };
91
+
92
+ const started = (
93
+ run ,
94
+ [command = '', ...rest] ,
95
+ input ,
96
+ options ,
97
+ ended ,
98
+ stream ,
99
+ ) => {
100
+ const child = spawn(command, rest, {
101
+ cwd: options.cwd,
102
+ env: options.genome === undefined ? process.env : { ...process.env, NERVUR_GENOME: options.genome },
103
+ stdio: ['pipe', 'pipe', 'pipe'],
104
+ detached: process.platform !== 'win32',
105
+ });
106
+ const out = outputOf(LONGEST);
107
+ const err = outputOf(LONGEST);
108
+ const printer = stream === null ? null : printerOf(run, stream);
109
+ let told = false;
110
+ const tell = (code ) => {
111
+ if (told) return;
112
+ told = true;
113
+ const end = endWithin(run, code, out, err, LONGEST);
114
+ if (printer === null) ended(end);
115
+ else void printer.drain().then(() => ended(end));
116
+ };
117
+ child.stdout.on('data', (chunk ) => {
118
+ out.add(chunk);
119
+ printer?.out(chunk);
120
+ });
121
+ child.stderr.on('data', (chunk ) => {
122
+ err.add(chunk);
123
+ printer?.err(chunk);
124
+ });
125
+ child.on('error', (failed) => {
126
+ err.add(utf8Bytes(failed.message));
127
+ tell(NOT_FOUND);
128
+ });
129
+ child.on('close', (code, signal) => tell(code ?? BY_SIGNAL + (signal === null ? 0 : constants.signals[signal])));
130
+ child.stdin.on('error', () => undefined);
131
+ child.stdin.end(input);
132
+ return child;
133
+ };
134
+
135
+ const GRACE = 5000;
136
+
137
+ const stopped = (child ) => {
138
+ const group = (signal ) => {
139
+ try {
140
+ if (child.pid !== undefined && process.platform !== 'win32') process.kill(-child.pid, signal);
141
+ else child.kill(signal);
142
+ } catch {
143
+ }
144
+ };
145
+ group('SIGTERM');
146
+ setTimeout(() => group('SIGKILL'), GRACE).unref();
147
+ };
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+ const askedOf = (args ) => {
156
+ const program = isFields(args) ? texts(args['program']) : null;
157
+ const input = isFields(args) ? (args['input'] ?? '') : null;
158
+ if (program === null || typeof input !== 'string')
159
+ return refused('a run is a program of one word or more, and its input');
160
+ const stream = isFields(args) ? args['stream'] : undefined;
161
+ if (stream === undefined) return { program, input, every: null };
162
+ const every = isFields(stream) ? stream['every'] : undefined;
163
+ if (typeof every !== 'number' || !Number.isInteger(every) || every < SHORTEST)
164
+ return refused(`a run streams each ${SHORTEST} ms or more`);
165
+ return { program, input, every };
166
+ };
167
+
168
+
169
+
170
+ const stop = (going , telling , args , asker ) => {
171
+ const id = isFields(args) ? args['run'] : undefined;
172
+ if (typeof id !== 'string') return refused('no such run goes');
173
+ telling.stop(id, asker);
174
+ const held = going.get(id);
175
+ if (held === undefined || held.asker !== asker) return refused('no such run goes');
176
+ stopped(held.child);
177
+ return result(null);
178
+ };
179
+
180
+ const goingOf = (going , telling , asker ) => [
181
+ ...[...going].flatMap(([id, held]) => (held.asker === asker ? [id] : [])),
182
+ ...telling.of(asker),
183
+ ];
184
+
185
+ export const runsOf = (
186
+ cwd ,
187
+ ended ,
188
+ printed = () => Promise.resolve(null),
189
+ pause = paused,
190
+ genome ,
191
+ ) => {
192
+ const going = new Map ();
193
+ const telling = tellingOf(ended, pause);
194
+ const run = (args , asker ) => {
195
+ const asked = askedOf(args);
196
+ if (!('program' in asked)) return asked;
197
+ if (asker === null) return refused('a run is asked by a skin lobe, which hears its end');
198
+ const id = randomUUID();
199
+ const { program, input, every } = asked;
200
+ const stream = every === null ? null : { every, printed: (print ) => printed(print, asker) };
201
+ const end = (told ) => {
202
+ going.delete(id);
203
+ telling.tell(id, told, asker);
204
+ };
205
+ going.set(id, { child: started(id, program, input, { cwd, genome }, end, stream), asker });
206
+ return result({ run: id });
207
+ };
208
+ return {
209
+ answer: (method, args, asker) => {
210
+ if (method === 'run') return run(args, asker);
211
+ if (method === 'stop') return stop(going, telling, args, asker);
212
+ if (method === 'going') return result({ runs: goingOf(going, telling, asker) });
213
+ return error('unavailable', `the shell holds no method ${method}`);
214
+ },
215
+ stopAll: () => {
216
+ for (const { child } of going.values()) stopped(child);
217
+ telling.clear();
218
+ },
219
+ };
220
+ };
@@ -0,0 +1,70 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ const AGAIN = new Set(['timeout', 'busy']);
12
+ const GONE = 'unavailable';
13
+
14
+ const PAUSE = 1000;
15
+
16
+ const codeOf = (answer ) => {
17
+ if (typeof answer !== 'object' || answer === null || !('error' in answer)) return null;
18
+ const { error } = answer;
19
+ return typeof error === 'object' && error !== null && 'code' in error && typeof error.code === 'string'
20
+ ? error.code
21
+ : null;
22
+ };
23
+
24
+ export const paused = (ms ) =>
25
+ new Promise((done) => {
26
+ setTimeout(done, ms).unref();
27
+ });
28
+
29
+
30
+
31
+ export const tellingOf = (
32
+ ended ,
33
+ pause = paused,
34
+ ) => {
35
+ const held = new Map ();
36
+ const take = (run , one ) => {
37
+ one.taken = true;
38
+ held.delete(run);
39
+ };
40
+ const tell = (run , end , one ) => {
41
+ const answered = (answer ) => {
42
+ if (one.taken) return;
43
+ const code = codeOf(answer);
44
+ if (code === GONE) {
45
+ one.gone = true;
46
+ return;
47
+ }
48
+ if (code === null || !AGAIN.has(code)) return take(run, one);
49
+ void pause(PAUSE).then(() => {
50
+ if (!one.taken) tell(run, end, one);
51
+ });
52
+ };
53
+ void ended(end, one.asker).then(answered, () => answered(null));
54
+ };
55
+ return {
56
+ tell: (run, end, asker) => {
57
+ const one = { asker, taken: false, gone: false };
58
+ held.set(run, one);
59
+ tell(run, end, one);
60
+ },
61
+ stop: (run, asker) => {
62
+ const one = held.get(run);
63
+ if (one !== undefined && one.asker === asker && one.gone) take(run, one);
64
+ },
65
+ of: (asker) => [...held].flatMap(([run, one]) => (one.asker === asker ? [run] : [])),
66
+ clear: () => {
67
+ for (const [run, one] of held) take(run, one);
68
+ },
69
+ };
70
+ };
@@ -0,0 +1,5 @@
1
+ import type { Blueprint } from '@nervur.org/genome/standard';
2
+ export declare const SHELL: {
3
+ readonly id: string;
4
+ readonly blueprint: Blueprint;
5
+ };
@@ -0,0 +1,59 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+
3
+
4
+ const RUN = {
5
+ type: 'object',
6
+ properties: { run: { type: 'string', minLength: 1 } },
7
+ required: ['run'],
8
+ additionalProperties: false,
9
+ };
10
+
11
+ const BLUEPRINT = {
12
+ name: 'nervur.shell',
13
+ version: '0.1.42',
14
+ description: "Runs the host's programs under the organism's account, each run answered at once.",
15
+ methods: {
16
+ run: {
17
+ description:
18
+ 'Starts a program, its words as the host takes them, with its standard input; with `stream`, the organ asks the skin lobe that asked it back `printed({ run, out, err })` as it goes, what it printed since the last, at most once each `every` ms, before its end.',
19
+ args: {
20
+ type: 'object',
21
+ properties: {
22
+ program: { type: 'array', items: { type: 'string' }, minItems: 1 },
23
+ input: { type: 'string' },
24
+ stream: {
25
+ type: 'object',
26
+ properties: { every: { type: 'integer', minimum: 1000 } },
27
+ required: ['every'],
28
+ additionalProperties: false,
29
+ },
30
+ },
31
+ required: ['program', 'input'],
32
+ additionalProperties: false,
33
+ },
34
+ result: RUN,
35
+ },
36
+ stop: {
37
+ description: "Stops a run still going that the asking lobe started, none else's; it ends as any run does.",
38
+ args: RUN,
39
+ },
40
+ going: {
41
+ description:
42
+ "The asking lobe's runs still going, by their names, each until its end is answered, none of another lobe's; a run lost to a restart of the half is named no more.",
43
+ result: {
44
+ type: 'object',
45
+ properties: { runs: { type: 'array', items: { type: 'string', minLength: 1 } } },
46
+ required: ['runs'],
47
+ additionalProperties: false,
48
+ },
49
+ },
50
+ },
51
+ };
52
+
53
+ export const SHELL
54
+
55
+
56
+ = {
57
+ id: 'shell',
58
+ blueprint: BLUEPRINT,
59
+ };
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@nervur.org/installer-node",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.37.2",
4
+ "description": "Nervur's installer for Node: the nervur command, the door, the host's organs (console, shell, disk, network) with their blueprints. 0.x, unstable.",
5
+ "keywords": [
6
+ "cli",
7
+ "installer",
8
+ "nervur",
9
+ "node",
10
+ "organism",
11
+ "quo"
12
+ ],
13
+ "homepage": "https://nervur.org",
14
+ "license": "FSL-1.1-ALv2",
15
+ "author": "Bookarest Digital SRL",
16
+ "bin": {
17
+ "nervur": "bin/nervur.js"
18
+ },
19
+ "type": "module",
20
+ "exports": {
21
+ "./command": {
22
+ "types": "./src/command/index.d.ts",
23
+ "default": "./src/command/index.js"
24
+ },
25
+ "./shell": {
26
+ "types": "./organs/shell/index.d.ts",
27
+ "default": "./organs/shell/index.js"
28
+ },
29
+ "./disk": {
30
+ "types": "./organs/disk/index.d.ts",
31
+ "default": "./organs/disk/index.js"
32
+ },
33
+ "./cargo/*": "./cargo/*"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "dependencies": {
39
+ "@nervur.org/floor": "0.37.2",
40
+ "@nervur.org/genome": "0.37.2"
41
+ },
42
+ "engines": {
43
+ "node": ">=22.23.5"
44
+ }
45
+ }
@@ -0,0 +1,31 @@
1
+ import { type Bridging } from './bridge.js';
2
+ import { type Found, type Taking } from './channel.js';
3
+ import { type Given, type Outcome } from './given.js';
4
+ type Why = {
5
+ readonly why: string;
6
+ };
7
+ export type Reaches = {
8
+ readonly view: (spec: string, taking: Taking) => Promise<Found | Why>;
9
+ readonly take: (version: string, taking: Taking) => Promise<null | Why>;
10
+ readonly keep: (home: string) => Promise<null | Why>;
11
+ readonly moves: (home: string, installer: string) => boolean;
12
+ readonly tried: (given: Given, home: string, installer: string, floor: ((given: Given, home: string) => Promise<null | Why>) | null) => Promise<Outcome>;
13
+ readonly back: (given: Given, home: string) => Promise<boolean | Why>;
14
+ readonly handOver: (installer: string, words?: readonly string[]) => Promise<number | Why>;
15
+ readonly sealed: (given: Given, home: string, genome: string) => Promise<string | Why>;
16
+ readonly commit: (home: string) => void;
17
+ readonly left: (home: string) => readonly string[];
18
+ readonly ran: (home: string) => string | null;
19
+ readonly install: (given: Given) => Promise<Outcome>;
20
+ readonly account: (print: (line: string) => void) => Promise<{
21
+ readonly free: () => void;
22
+ } | Why>;
23
+ readonly node: () => null | Why;
24
+ readonly handed: string | null;
25
+ readonly alive: (pid: number) => boolean;
26
+ readonly pid: number;
27
+ readonly parent: number;
28
+ } & Bridging;
29
+ export declare const REAL: Reaches;
30
+ export declare const act: (given: Given, reaches?: Reaches) => Promise<Outcome>;
31
+ export {};