@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,108 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { postsOf, routeOf, } from '@nervur.org/genome/screen';
3
+ import { dataText, error, isFields, } from '@nervur.org/genome/standard';
4
+ import { randomBytes } from 'node:crypto';
5
+
6
+ import { ROOT, } from './look.js';
7
+
8
+ import { isFile } from './follow.js';
9
+ import { fieldOf } from './tell.js';
10
+ import { wayPressed } from './leave.js';
11
+ import { presserOf } from './presser.js';
12
+ import { cellsOfRoute, } from './state.js';
13
+
14
+ const failure = (status , code , message ) => ({
15
+ status,
16
+ body: dataText(error(code, message)),
17
+ });
18
+
19
+ const valuesOf = (data ) => {
20
+ if (data === undefined) return {};
21
+ if (typeof data !== 'object' || data === null || Array.isArray(data)) return null;
22
+ const read = {};
23
+ for (const [name, value] of Object.entries(data)) {
24
+ if (typeof value !== 'string' && typeof value !== 'boolean' && !isFile(value)) return null;
25
+ read[name] = value;
26
+ }
27
+ return read;
28
+ };
29
+
30
+ const ids = () => {
31
+ const prefix = randomBytes(6).toString('hex');
32
+ let count = 0;
33
+ return () => `p${prefix}${(count += 1).toString(36)}`;
34
+ };
35
+
36
+ const pageOf = (press ) => {
37
+ if (press.method !== 'page' || press.to !== undefined || !isFields(press.args)) return null;
38
+ const cursor = press.args['cursor'];
39
+ return typeof cursor === 'string' || cursor === null ? { cursor } : null;
40
+ };
41
+
42
+ const wearOf = (press ) => {
43
+ if (press.method !== 'wear' || press.to !== undefined || !isFields(press.args)) return null;
44
+ const design = press.args['design'];
45
+ return typeof design === 'string' && design !== '' ? design : null;
46
+ };
47
+
48
+ const worn = async (window , state , press ) => {
49
+ const answer = await window.wear(wearOf(press) ?? '');
50
+ if ('error' in answer) return { status: 422, body: dataText(answer) };
51
+ if (isFields(answer.result) && 'refused' in answer.result) return { status: 204 };
52
+ state.worn.designLobe = null;
53
+ state.worn.design = null;
54
+ state.worn.lay = null;
55
+ state.redraw = true;
56
+ return { status: 204 };
57
+ };
58
+
59
+ const posted = async (window , posts ) => {
60
+ for (const post of posts) {
61
+ const answer = await window.post(post.method, post.args);
62
+ if ('error' in answer) return { status: 422, body: dataText(answer) };
63
+ if (post.method === 'send' && !(isFields(answer.result) && answer.result['sending'] === true)) break;
64
+ }
65
+ return { status: 204 };
66
+ };
67
+
68
+ export const makePresses = (window , state , mirror ) => {
69
+ const next = ids();
70
+ return async (body ) => {
71
+ const [node, way] = [fieldOf(body, 'node'), fieldOf(body, 'way')];
72
+ const values = valuesOf(fieldOf(body, 'values'));
73
+ if (values !== null && way !== undefined) return wayPressed(window, state, way, values);
74
+ if (typeof node !== 'number' || values === null)
75
+ return failure(400, 'refused', 'a press names its node and its values');
76
+ const found = mirror.find(node);
77
+ if (found === null) return failure(409, 'stale', 'no press stands at that node now');
78
+ const { lobe, press } = found;
79
+ if (lobe === ROOT && wearOf(press) !== null) return worn(window, state, press);
80
+ const path = isFields(press.args) && typeof press.args['path'] === 'string' ? press.args['path'] : null;
81
+ const read = path === null ? null : routeOf(path);
82
+ const posts = postsOf(press, {
83
+ id: next(),
84
+ seen: state.seen?.version ?? null,
85
+ cells: path === null ? null : cellsOfRoute(state, path),
86
+ values,
87
+ });
88
+ if (posts !== null && (press.method === 'local' || (read !== null && !('why' in read)))) {
89
+ return posted(window, posts);
90
+ }
91
+ const turned = pageOf(press);
92
+ if (turned !== null) {
93
+ state.cursor = turned.cursor;
94
+ return { status: 204 };
95
+ }
96
+ const presser = presserOf(state, lobe);
97
+ if ('why' in presser) return failure(422, 'refused', presser.why);
98
+ const answer = await window.press(presser.lobe, press.method, press.args, press.to, presser.over, values);
99
+ if ('error' in answer) return { status: 422, body: dataText(answer) };
100
+ const walked = press.method === 'create' && isFields(answer.result) ? answer.result['text'] : undefined;
101
+ if (typeof walked === 'string') {
102
+ state.route = walked;
103
+ state.cursor = null;
104
+ return { status: 200, body: dataText({ walked }) };
105
+ }
106
+ return { status: 204 };
107
+ };
108
+ };
@@ -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,205 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import {
3
+ clampAccess,
4
+ hostOf,
5
+ makeScreen,
6
+ motionOf,
7
+ noteOf,
8
+ withTold,
9
+
10
+
11
+
12
+
13
+ } from '@nervur.org/genome/screen';
14
+ import { fetched, followSeen, tellLanded } from './follow.js';
15
+ import { makeFrames } from './frames.js';
16
+ import { BARE, designOf, layOf, } from './lay.js';
17
+ import { cagedOf, wearOf } from './worn.js';
18
+ import { ROOT, } from './look.js';
19
+
20
+ import { accessOf, cellsOfRoute, overOf, placeOf, surfaceIn, wiredOf, } from './state.js';
21
+
22
+
23
+
24
+
25
+ const laidFor = async (window , state , seen ) => {
26
+ state.worn.designLobe = seen.design;
27
+ const lobe = seen.design;
28
+ const { worn } = state;
29
+ if (lobe === null) return;
30
+ const told = state.told.get(lobe);
31
+ const key = `${lobe}/${told?.faculty ?? ''}/${told?.cells ?? ''}`;
32
+ if (worn.design === null || worn.design.key !== key || worn.design.value === null) {
33
+ const answer = await window.worn();
34
+ const read = 'error' in answer ? null : designOf(answer.result);
35
+ worn.design = { key, value: read === null || 'why' in read ? null : read };
36
+ }
37
+ const design = worn.design.value;
38
+ const laying = `${worn.design.key}/${state.reduced}`;
39
+ if (design === null || (worn.lay !== null && worn.lay.key === laying && worn.lay.value !== null)) return;
40
+ const lay = layOf(design, accessOf(state));
41
+ worn.lay = { key: laying, value: 'why' in lay ? null : lay };
42
+ };
43
+
44
+ const givenOf = (window , state ) => ({
45
+ root: ROOT,
46
+ draw: (lobe, args) => {
47
+ if (lobe === ROOT) return Promise.resolve({ tree: state.seen?.tree ?? null });
48
+ const over = overOf(state, lobe);
49
+ return window.show(lobe, over === null ? args : withTold(args, state.surface), over);
50
+ },
51
+ inputs: (lobe) => {
52
+ const one = lobe === ROOT || overOf(state, lobe) !== null ? undefined : state.told.get(lobe);
53
+ return one === undefined ? null : { faculty: one.faculty, cells: one.cells, told: one.told };
54
+ },
55
+ wiring: (lobe, placeholder) => {
56
+ if (lobe === ROOT && placeholder === 'main') return state.seen?.main.lobe;
57
+ return overOf(state, lobe) === null ? state.told.get(lobe)?.wires[placeholder] : undefined;
58
+ },
59
+ wear: (lobe) => wearOf(state, lobe),
60
+ caged: (lobe) => cagedOf(state, lobe),
61
+ caps: (lobe) => (overOf(state, lobe) === null ? state.told.get(lobe)?.caps : undefined),
62
+ get home() {
63
+ return (state.worn.lay?.value ?? BARE).home;
64
+ },
65
+ });
66
+
67
+ const movingOf = (ops , motion , access ) =>
68
+ [...motionOf(ops, motion, clampAccess(access)['access-motion'])].map(([node, one]) => [
69
+ node,
70
+ one.kind,
71
+ one.duration,
72
+ one.easing,
73
+ ]);
74
+
75
+ const messageOf = (
76
+ whole ,
77
+ opens ,
78
+ ops ,
79
+ moving ,
80
+ worn ,
81
+ way ,
82
+ world ,
83
+ ) =>
84
+ JSON.stringify({
85
+ whole,
86
+ ...(opens ? { opens } : {}),
87
+ ops,
88
+ way,
89
+ world,
90
+ ...(moving.length === 0 ? {} : { motion: moving }),
91
+ ...(worn.fonts === undefined ? {} : { fonts: worn.fonts }),
92
+ ...(worn.home === undefined ? {} : { home: worn.home }),
93
+ });
94
+
95
+ const senderTo = (state , mirror , streams ) => {
96
+ let linked ;
97
+ let dressed = '';
98
+ let laid = '';
99
+ let stood = '';
100
+ return (ops , whole , at = state.route) => {
101
+ const way = JSON.stringify([state.seen?.way ?? null, state.seen?.world ?? null]);
102
+ const lay = state.worn.lay?.value;
103
+ const home = [...(lay ?? BARE).home.sheets];
104
+ if (!whole && ops.length === 0 && way === laid && home.join() === dressed) return;
105
+ laid = way;
106
+ mirror.apply(ops);
107
+ const moving = whole || lay === undefined || lay === null ? [] : movingOf(ops, lay.motion, accessOf(state));
108
+ const fonts = lay?.fonts;
109
+ const place = placeOf(state, at);
110
+ const message = messageOf(
111
+ whole,
112
+ whole || place !== stood,
113
+ ops,
114
+ moving,
115
+ {
116
+ fonts: whole || fonts !== linked ? fonts : undefined,
117
+ home: whole || home.join() !== dressed ? home : undefined,
118
+ },
119
+ state.seen?.way ?? null,
120
+ state.seen?.world ?? null,
121
+ );
122
+ linked = fonts;
123
+ stood = place;
124
+ dressed = home.join();
125
+ for (const send of streams) send(message);
126
+ };
127
+ };
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ const stepOf = async (acting , everything ) => {
146
+ const { window, state, mirror, held, frames, broadcast, screenOf, note } = acting;
147
+ const [walk, asked] = [state.walks, state.route];
148
+ const seen = await window.see({
149
+ cursor: state.cursor,
150
+ cells: cellsOfRoute(state, state.route),
151
+ ...surfaceIn(state),
152
+ });
153
+ if (walk !== state.walks) return;
154
+ if ('why' in seen) {
155
+ if (everything || held.noted !== seen.why) note(seen.why);
156
+ return;
157
+ }
158
+ state.seen = seen;
159
+ if (state.route === asked) state.route = seen.text;
160
+ void followSeen(state.kept, seen.channel, fetched, window.post, (followed) => tellLanded(window.post, followed));
161
+ await laidFor(window, state, seen);
162
+ const whole = everything || held.screen === null;
163
+ if (whole || held.screen === null) {
164
+ mirror.reset();
165
+ held.noted = null;
166
+ held.screen = screenOf();
167
+ }
168
+ const stepping = held.screen;
169
+ const done = await stepping.step({});
170
+ if (walk !== state.walks || held.screen !== stepping) return;
171
+ broadcast(done.ops, whole);
172
+ if (state.route !== null) frames.keep(state.route, { root: ROOT, args: {}, tree: done.tree, seen });
173
+ };
174
+
175
+ export const makeShown = (window , state , mirror , streams ) => {
176
+ const held = { screen: null, noted: null };
177
+ const frames = makeFrames(() => wiredOf(state));
178
+ const broadcast = senderTo(state, mirror, streams);
179
+ const screenOf = () => makeScreen(givenOf(window, state));
180
+ const note = (why ) => {
181
+ mirror.reset();
182
+ held.screen = null;
183
+ held.noted = why;
184
+ broadcast([['make', 0, null, hostOf('home', noteOf('missing', why), BARE.home.sheets, undefined), 1]], true);
185
+ };
186
+ const acting = { window, state, mirror, held, frames, broadcast, screenOf, note };
187
+ return {
188
+ step: (everything ) => stepOf(acting, everything),
189
+ laid: async () => {
190
+ const seen = state.seen ?? (await window.see({ route: [], cursor: null, cells: null, ...surfaceIn(state) }));
191
+ if (!('why' in seen)) await laidFor(window, state, seen);
192
+ return state.worn.lay?.value ?? null;
193
+ },
194
+ walk: (route ) => {
195
+ const frame = frames.of(route);
196
+ if (frame === undefined) return false;
197
+ mirror.reset();
198
+ held.noted = null;
199
+ state.seen = frame.seen;
200
+ held.screen = screenOf();
201
+ broadcast(held.screen.shows(frame.tree), true, route);
202
+ return true;
203
+ },
204
+ };
205
+ };
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { isFields, } from '@nervur.org/genome/standard';
3
+
4
+ const RELATION = /^[a-z](?:[a-z0-9-]{0,62}[a-z0-9])?$/u;
5
+
6
+
7
+
8
+ const relationsOf = async (askWindow ) => {
9
+ const answer = await askWindow('standings', {});
10
+ if ('error' in answer || !isFields(answer.result)) return null;
11
+ const listed = Array.isArray(answer.result['relations']) ? answer.result['relations'] : [];
12
+ return listed.filter(
13
+ (one) =>
14
+ isFields(one) && typeof one['placeholder'] === 'string' && RELATION.test(one['placeholder']),
15
+ );
16
+ };
17
+
18
+ export const standingsOf = async (
19
+ askWindow ,
20
+ ) => {
21
+ const relations = await relationsOf(askWindow);
22
+ if (relations === null) return null;
23
+ return relations.flatMap((one) => {
24
+ const { placeholder, note } = one;
25
+ if (typeof placeholder !== 'string') return [];
26
+ const domain = isFields(note) && typeof note['domain'] === 'string' ? note['domain'] : null;
27
+ return [{ relation: placeholder, domain, note: note ?? null }];
28
+ });
29
+ };
@@ -0,0 +1,80 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { routeOf, toldOf } from '@nervur.org/genome/screen';
3
+ import { keptAnew, } from './follow.js';
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+ export const freshState = (size ) => ({
37
+ told: new Map(),
38
+ worn: { designLobe: null, design: null, lay: null },
39
+ seen: null,
40
+ kept: keptAnew(),
41
+ route: null,
42
+ cursor: null,
43
+ walks: 0,
44
+ surface: size === undefined ? {} : { size },
45
+ reduced: false,
46
+ redraw: false,
47
+ theme: 'light',
48
+ });
49
+
50
+ export const accessOf = (state ) => ({
51
+ 'access-motion': state.reduced ? 0 : 1,
52
+ });
53
+
54
+ export const cellsOfRoute = (state , route ) => {
55
+ const read = routeOf(route ?? '/');
56
+ const only = 'route' in read && read.route.length === 1 ? read.route[0] : undefined;
57
+ return only !== undefined && 'lobe' in only ? (state.told.get(only.lobe)?.cells ?? null) : null;
58
+ };
59
+
60
+ export const wiredOf = (state ) =>
61
+ JSON.stringify([...state.told].map(([lobe, told]) => [lobe, told.wires]));
62
+
63
+ export const placeOf = (state , at = state.route) => JSON.stringify(at);
64
+
65
+ export const overOf = (state , lobe ) =>
66
+ state.seen !== null && state.seen.main.lobe === lobe ? state.seen.main.over : null;
67
+
68
+ export const langOf = (state ) =>
69
+ state.surface.language === undefined ? {} : { lang: state.surface.language };
70
+
71
+ export const sized = (size ) => (size === undefined ? {} : { size });
72
+
73
+ export const surfaceIn = (state ) => ({
74
+ theme: state.theme,
75
+ ...langOf(state),
76
+ ...sizeIn(state),
77
+ });
78
+
79
+ export const sizeIn = ({ surface } ) =>
80
+ sized(surface.size === undefined && surface.width === undefined ? undefined : toldOf(surface).size);
@@ -0,0 +1,47 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { routeOf } from '@nervur.org/genome/screen';
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ export const fieldOf = (raw , name ) =>
18
+ typeof raw === 'object' && raw !== null && name in raw
19
+ ? Object.getOwnPropertyDescriptor(raw, name)?.value
20
+ : undefined;
21
+
22
+ const refuse = (status , message ) => ({ refused: { status, message } });
23
+
24
+ export const tellOf = (raw ) => {
25
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return refuse(400, 'a tell is an object');
26
+ const [route, width, language, reduced, theme] = ['route', 'width', 'language', 'reduced', 'theme'].map((name) =>
27
+ fieldOf(raw, name),
28
+ );
29
+ if (route !== undefined) {
30
+ if (typeof route !== 'string') return refuse(400, 'a route is a path');
31
+ if ('why' in routeOf(route)) return refuse(404, 'no such route');
32
+ }
33
+ if (width !== undefined && (typeof width !== 'number' || !Number.isFinite(width)))
34
+ return refuse(400, 'a width is a number');
35
+ if (language !== undefined && typeof language !== 'string') return refuse(400, 'a language is a text');
36
+ if (reduced !== undefined && typeof reduced !== 'boolean') return refuse(400, 'reduced is a flag');
37
+ if (theme !== undefined && theme !== 'light' && theme !== 'dark') return refuse(400, 'a theme is light or dark');
38
+ return {
39
+ tell: {
40
+ ...(route === undefined ? {} : { route }),
41
+ ...(width === undefined ? {} : { width }),
42
+ ...(language === undefined ? {} : { language }),
43
+ ...(reduced === undefined ? {} : { reduced }),
44
+ ...(theme === undefined ? {} : { theme }),
45
+ },
46
+ };
47
+ };
@@ -0,0 +1,65 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { execFile } from 'node:child_process';
3
+ import { readFile } from 'node:fs/promises';
4
+
5
+
6
+
7
+ const ESTABLISHED = '01';
8
+
9
+ const portIn = (address ) => {
10
+ const hex = address?.split(':').at(-1);
11
+ return hex === undefined || !/^[0-9A-Fa-f]{4}$/.test(hex) ? null : Number.parseInt(hex, 16);
12
+ };
13
+
14
+ export const uidFromProcNet = (text , peerPort , serverPort ) => {
15
+ for (const line of text.split('\n')) {
16
+ const fields = line.trim().split(/\s+/);
17
+ if (fields[3] !== ESTABLISHED || portIn(fields[1]) !== peerPort || portIn(fields[2]) !== serverPort) continue;
18
+ const uid = Number(fields[7]);
19
+ return Number.isInteger(uid) ? uid : null;
20
+ }
21
+ return null;
22
+ };
23
+
24
+ export const uidFromLsof = (text , peerPort ) => {
25
+ const local = `127.0.0.1:${peerPort}->`;
26
+ let uid = null;
27
+ for (const line of text.split('\n')) {
28
+ const field = line.slice(0, 1);
29
+ const value = line.slice(1);
30
+ if (field === 'p') uid = null;
31
+ else if (field === 'u') uid = /^\d+$/.test(value) ? Number(value) : null;
32
+ else if (field === 'n' && value.startsWith(local)) return uid;
33
+ }
34
+ return null;
35
+ };
36
+
37
+ const procUid = async (peerPort , serverPort ) => {
38
+ for (const file of ['/proc/net/tcp', '/proc/net/tcp6']) {
39
+ let text ;
40
+ try {
41
+ text = await readFile(file, 'utf8');
42
+ } catch {
43
+ continue;
44
+ }
45
+ const uid = uidFromProcNet(text, peerPort, serverPort);
46
+ if (uid !== null) return uid;
47
+ }
48
+ return null;
49
+ };
50
+
51
+ const LSOF = '/usr/sbin/lsof';
52
+ const LSOF_WITHIN = 3000;
53
+
54
+ const lsofUid = (peerPort ) =>
55
+ new Promise((done) => {
56
+ execFile(
57
+ LSOF,
58
+ ['-nP', `-iTCP:${peerPort}`, '-sTCP:ESTABLISHED', '-Fpun'],
59
+ { timeout: LSOF_WITHIN },
60
+ (failed, out) => done(failed !== null && out === '' ? null : uidFromLsof(out, peerPort)),
61
+ );
62
+ });
63
+
64
+ export const uidReaderOf = (platform ) =>
65
+ platform === 'linux' ? procUid : (peerPort) => lsofUid(peerPort);
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { dressOf } from '@nervur.org/genome/screen';
3
+ import { BARE, } from './lay.js';
4
+ import { ROOT } from './look.js';
5
+ import { overOf, } from './state.js';
6
+
7
+ export const homeOf = (state , lobe ) => {
8
+ if (lobe === ROOT) return true;
9
+ const road = state.told.get(lobe)?.road;
10
+ return overOf(state, lobe) === null && road !== undefined && dressOf(road) === 'home';
11
+ };
12
+
13
+ export const cagedOf = (state , lobe ) => overOf(state, lobe) === null && !homeOf(state, lobe);
14
+
15
+ export const wearOf = (state , lobe ) => {
16
+ const lay = state.worn.lay?.value ?? BARE;
17
+ return homeOf(state, lobe) ? lay.home : lay.lobes;
18
+ };
19
+
20
+ export const sheetOf = (state , digest ) =>
21
+ state.worn.lay?.value?.sheets.get(digest) ?? null;
22
+
23
+ export const assetOf = (state , name ) => state.worn.lay?.value?.assets.get(name) ?? null;
@@ -0,0 +1 @@
1
+ export { SHELL } from './organ.js';
@@ -0,0 +1,2 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ export { SHELL } from './organ.js';
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { homedir } from 'node:os';
3
+ import { SHELL } from '../index.js';
4
+ import { processIo, serveHalf, } from '../../../src/halves/index.js';
5
+ import { firstUnderPressure } from './pressure.js';
6
+ import { runsOf } from './runs.js';
7
+
8
+ firstUnderPressure();
9
+
10
+ const SKIN_WITHIN = 5000;
11
+
12
+ const genome = process.argv[3];
13
+ const serving = Promise.withResolvers ();
14
+ const runs = runsOf(
15
+ homedir(),
16
+ (ended, asker) => serving.promise.then((end) => end.ask(asker, 'ended', { ...ended }, SKIN_WITHIN)),
17
+ (printed, asker) => serving.promise.then((end) => end.ask(asker, 'printed', { ...printed }, SKIN_WITHIN)),
18
+ undefined,
19
+ genome,
20
+ );
21
+ const stop = () => {
22
+ runs.stopAll();
23
+ process.exit(0);
24
+ };
25
+ process.on('SIGTERM', stop);
26
+ serving.resolve(serveHalf(processIo(), SHELL.blueprint, runs.answer, stop));
@@ -0,0 +1,70 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { genomeCodec } from '@nervur.org/genome/cage';
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ const CONTINUING = 0x80;
19
+ const MASK = 0xc0;
20
+
21
+ export const outputOf = (longest ) => {
22
+ const pieces = [];
23
+ let weight = 0;
24
+ let seen = 0;
25
+ return {
26
+ add: (bytes) => {
27
+ seen += bytes.length;
28
+ pieces.push(bytes);
29
+ weight += bytes.length;
30
+ for (let first = pieces[0]; first !== undefined && weight - first.length >= longest;) {
31
+ pieces.shift();
32
+ weight -= first.length;
33
+ first = pieces[0];
34
+ }
35
+ },
36
+ kept: () => Buffer.concat(pieces),
37
+ seen: () => seen,
38
+ };
39
+ };
40
+
41
+ const decoder = new TextDecoder();
42
+
43
+ const shown = (bytes , seen , keep ) => {
44
+ let from = Math.max(0, bytes.length - keep);
45
+ while (from < bytes.length && ((bytes[from] ?? 0) & MASK) === CONTINUING) from += 1;
46
+ const text = decoder.decode(bytes.subarray(from));
47
+ const cut = seen - (bytes.length - from);
48
+ return cut === 0 ? text : `[${cut} bytes cut]\n${text}`;
49
+ };
50
+
51
+ const weight = (data ) => Buffer.byteLength(genomeCodec.text(data), 'utf8');
52
+
53
+ export const endWithin = (run , code , out , err , longest ) => {
54
+ const outBytes = out.kept();
55
+ const errBytes = err.kept();
56
+ const at = (keep ) => ({
57
+ run,
58
+ code,
59
+ out: shown(outBytes, out.seen(), keep),
60
+ err: shown(errBytes, err.seen(), keep),
61
+ });
62
+ let low = 0;
63
+ let high = Math.max(outBytes.length, errBytes.length);
64
+ while (low < high) {
65
+ const middle = Math.ceil((low + high) / 2);
66
+ if (weight(at(middle)) <= longest) low = middle;
67
+ else high = middle - 1;
68
+ }
69
+ return at(low);
70
+ };