@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.
- package/LICENSE +105 -0
- package/README.md +159 -2
- package/SECURITY.md +8 -0
- package/bin/nervur.js +5 -0
- package/cargo/emscripten-module.wasm +0 -0
- package/cargo/manifest.json +1 -0
- package/cargo/sqlite3.wasm +0 -0
- package/cargo/table-i-i.wasm +0 -0
- package/cargo/table-i-ii.wasm +0 -0
- package/cargo/table-i-iii.wasm +0 -0
- package/cargo/table-i-iiii.wasm +0 -0
- package/cargo/table-i-iiiii.wasm +0 -0
- package/cargo/table-i-iiij.wasm +0 -0
- package/cargo/table-i-ij.wasm +0 -0
- package/cargo/table-v-ii.wasm +0 -0
- package/cargo/table-v-iii.wasm +0 -0
- package/cargo/worker.js +30808 -0
- package/organs/console/node/guard.d.ts +10 -0
- package/organs/console/node/guard.js +52 -0
- package/organs/console/node/index.d.ts +4 -0
- package/organs/console/node/index.js +5 -0
- package/organs/console/node/line.d.ts +16 -0
- package/organs/console/node/line.js +150 -0
- package/organs/console/node/main.js +51 -0
- package/organs/console/node/program.d.ts +1 -0
- package/organs/console/node/program.js +5 -0
- package/organs/console/node/proof.d.ts +15 -0
- package/organs/console/node/proof.js +84 -0
- package/organs/console/node/socket.d.ts +15 -0
- package/organs/console/node/socket.js +99 -0
- package/organs/disk/index.d.ts +1 -0
- package/organs/disk/index.js +2 -0
- package/organs/disk/node/files.js +162 -0
- package/organs/disk/node/main.js +20 -0
- package/organs/disk/node/program.d.ts +1 -0
- package/organs/disk/node/program.js +5 -0
- package/organs/disk/organ.d.ts +5 -0
- package/organs/disk/organ.js +69 -0
- package/organs/network/node/fill.d.ts +21 -0
- package/organs/network/node/fill.js +195 -0
- package/organs/network/node/flows.js +66 -0
- package/organs/network/node/half.js +260 -0
- package/organs/network/node/lines.d.ts +29 -0
- package/organs/network/node/lines.js +236 -0
- package/organs/network/node/link.d.ts +24 -0
- package/organs/network/node/link.js +215 -0
- package/organs/network/node/main.js +41 -0
- package/organs/network/node/moved.d.ts +2 -0
- package/organs/network/node/moved.js +20 -0
- package/organs/network/node/near.d.ts +63 -0
- package/organs/network/node/near.js +263 -0
- package/organs/network/node/program.d.ts +1 -0
- package/organs/network/node/program.js +5 -0
- package/organs/network/node/schemes.d.ts +1 -0
- package/organs/network/node/schemes.js +2 -0
- package/organs/network/node/sent.d.ts +13 -0
- package/organs/network/node/sent.js +101 -0
- package/organs/network/node/served.d.ts +19 -0
- package/organs/network/node/served.js +237 -0
- package/organs/screen/node/client.js +3 -0
- package/organs/screen/node/follow.js +266 -0
- package/organs/screen/node/frames.js +26 -0
- package/organs/screen/node/held.js +27 -0
- package/organs/screen/node/http.js +179 -0
- package/organs/screen/node/lay.js +116 -0
- package/organs/screen/node/leave.js +27 -0
- package/organs/screen/node/linked.js +69 -0
- package/organs/screen/node/listen.js +61 -0
- package/organs/screen/node/look.js +121 -0
- package/organs/screen/node/loop.js +154 -0
- package/organs/screen/node/main.js +74 -0
- package/organs/screen/node/mirror.js +112 -0
- package/organs/screen/node/notice.js +44 -0
- package/organs/screen/node/presser.js +11 -0
- package/organs/screen/node/presses.js +108 -0
- package/organs/screen/node/program.d.ts +1 -0
- package/organs/screen/node/program.js +5 -0
- package/organs/screen/node/shown.js +205 -0
- package/organs/screen/node/standing.js +29 -0
- package/organs/screen/node/state.js +80 -0
- package/organs/screen/node/tell.js +47 -0
- package/organs/screen/node/uid.js +65 -0
- package/organs/screen/node/worn.js +23 -0
- package/organs/shell/index.d.ts +1 -0
- package/organs/shell/index.js +2 -0
- package/organs/shell/node/main.js +26 -0
- package/organs/shell/node/output.js +70 -0
- package/organs/shell/node/pressure.js +14 -0
- package/organs/shell/node/program.d.ts +1 -0
- package/organs/shell/node/program.js +5 -0
- package/organs/shell/node/runs.js +220 -0
- package/organs/shell/node/told.js +70 -0
- package/organs/shell/organ.d.ts +5 -0
- package/organs/shell/organ.js +59 -0
- package/package.json +43 -4
- package/src/command/act.d.ts +31 -0
- package/src/command/act.js +261 -0
- package/src/command/answers.d.ts +3 -0
- package/src/command/answers.js +232 -0
- package/src/command/args.d.ts +14 -0
- package/src/command/args.js +220 -0
- package/src/command/arrive.d.ts +2 -0
- package/src/command/arrive.js +21 -0
- package/src/command/asked.d.ts +18 -0
- package/src/command/asked.js +49 -0
- package/src/command/backup.d.ts +18 -0
- package/src/command/backup.js +261 -0
- package/src/command/before.d.ts +40 -0
- package/src/command/before.js +249 -0
- package/src/command/born.d.ts +27 -0
- package/src/command/born.js +103 -0
- package/src/command/bridge.d.ts +19 -0
- package/src/command/bridge.js +152 -0
- package/src/command/chain.d.ts +9 -0
- package/src/command/chain.js +48 -0
- package/src/command/channel.d.ts +29 -0
- package/src/command/channel.js +263 -0
- package/src/command/choices.d.ts +35 -0
- package/src/command/choices.js +173 -0
- package/src/command/claim.d.ts +12 -0
- package/src/command/claim.js +46 -0
- package/src/command/commands.d.ts +16 -0
- package/src/command/commands.js +257 -0
- package/src/command/ends.d.ts +16 -0
- package/src/command/ends.js +78 -0
- package/src/command/follow.d.ts +12 -0
- package/src/command/follow.js +66 -0
- package/src/command/given.d.ts +39 -0
- package/src/command/given.js +53 -0
- package/src/command/held.d.ts +15 -0
- package/src/command/held.js +56 -0
- package/src/command/index.d.ts +1 -0
- package/src/command/index.js +203 -0
- package/src/command/jailer.d.ts +28 -0
- package/src/command/jailer.js +135 -0
- package/src/command/laid.d.ts +6 -0
- package/src/command/laid.js +31 -0
- package/src/command/left.d.ts +9 -0
- package/src/command/left.js +34 -0
- package/src/command/line.d.ts +7 -0
- package/src/command/line.js +39 -0
- package/src/command/link.d.ts +30 -0
- package/src/command/link.js +123 -0
- package/src/command/lobes.d.ts +1 -0
- package/src/command/lobes.js +10 -0
- package/src/command/locks.d.ts +17 -0
- package/src/command/locks.js +76 -0
- package/src/command/mcp/calls.d.ts +27 -0
- package/src/command/mcp/calls.js +155 -0
- package/src/command/mcp/notices.d.ts +22 -0
- package/src/command/mcp/notices.js +203 -0
- package/src/command/mcp/resources.d.ts +31 -0
- package/src/command/mcp/resources.js +108 -0
- package/src/command/mcp/server.d.ts +19 -0
- package/src/command/mcp/server.js +149 -0
- package/src/command/mcp/tools.d.ts +39 -0
- package/src/command/mcp/tools.js +131 -0
- package/src/command/mcp.d.ts +8 -0
- package/src/command/mcp.js +39 -0
- package/src/command/noticed.d.ts +11 -0
- package/src/command/noticed.js +55 -0
- package/src/command/older.d.ts +11 -0
- package/src/command/older.js +45 -0
- package/src/command/open.d.ts +24 -0
- package/src/command/open.js +107 -0
- package/src/command/passphrase.d.ts +6 -0
- package/src/command/passphrase.js +82 -0
- package/src/command/reclaim.d.ts +7 -0
- package/src/command/reclaim.js +47 -0
- package/src/command/refused.d.ts +4 -0
- package/src/command/refused.js +27 -0
- package/src/command/release.d.ts +27 -0
- package/src/command/release.js +153 -0
- package/src/command/repo.d.ts +31 -0
- package/src/command/repo.js +133 -0
- package/src/command/rewrap.d.ts +16 -0
- package/src/command/rewrap.js +175 -0
- package/src/command/runtime.d.ts +25 -0
- package/src/command/runtime.js +175 -0
- package/src/command/salvage.d.ts +4 -0
- package/src/command/salvage.js +42 -0
- package/src/command/screen.d.ts +14 -0
- package/src/command/screen.js +62 -0
- package/src/command/spawn.d.ts +23 -0
- package/src/command/spawn.js +213 -0
- package/src/command/start.d.ts +34 -0
- package/src/command/start.js +246 -0
- package/src/command/state.d.ts +5 -0
- package/src/command/state.js +39 -0
- package/src/command/token.d.ts +1 -0
- package/src/command/token.js +9 -0
- package/src/command/trial.d.ts +18 -0
- package/src/command/trial.js +108 -0
- package/src/command/undone.d.ts +3 -0
- package/src/command/undone.js +21 -0
- package/src/command/vouch.d.ts +1 -0
- package/src/command/vouch.js +15 -0
- package/src/command/windows-processes.d.ts +2 -0
- package/src/command/windows-processes.js +22 -0
- package/src/command/wipe.d.ts +9 -0
- package/src/command/wipe.js +105 -0
- package/src/command/words.d.ts +5 -0
- package/src/command/words.js +53 -0
- package/src/door/claim.d.ts +5 -0
- package/src/door/claim.js +21 -0
- package/src/door/claimed.d.ts +7 -0
- package/src/door/claimed.js +110 -0
- package/src/door/configuration.d.ts +40 -0
- package/src/door/configuration.js +206 -0
- package/src/door/design.d.ts +13 -0
- package/src/door/design.js +71 -0
- package/src/door/digests.d.ts +7 -0
- package/src/door/digests.js +36 -0
- package/src/door/distribution.d.ts +25 -0
- package/src/door/distribution.js +88 -0
- package/src/door/door.d.ts +41 -0
- package/src/door/door.js +219 -0
- package/src/door/dressed.d.ts +34 -0
- package/src/door/dressed.js +182 -0
- package/src/door/faculties.d.ts +29 -0
- package/src/door/faculties.js +88 -0
- package/src/door/longest.d.ts +6 -0
- package/src/door/longest.js +25 -0
- package/src/fills/account-only.d.ts +3 -0
- package/src/fills/account-only.js +24 -0
- package/src/fills/boot-key.d.ts +21 -0
- package/src/fills/boot-key.js +70 -0
- package/src/fills/boot-move.d.ts +25 -0
- package/src/fills/boot-move.js +86 -0
- package/src/fills/bridge.d.ts +13 -0
- package/src/fills/bridge.js +86 -0
- package/src/fills/chance.d.ts +2 -0
- package/src/fills/chance.js +7 -0
- package/src/fills/crypto.d.ts +2 -0
- package/src/fills/crypto.js +94 -0
- package/src/fills/flushed.d.ts +9 -0
- package/src/fills/flushed.js +80 -0
- package/src/fills/hardware.d.ts +18 -0
- package/src/fills/hardware.js +70 -0
- package/src/fills/held.d.ts +31 -0
- package/src/fills/held.js +171 -0
- package/src/fills/keepers.d.ts +23 -0
- package/src/fills/keepers.js +151 -0
- package/src/fills/keyring.d.ts +19 -0
- package/src/fills/keyring.js +131 -0
- package/src/fills/pages.d.ts +3 -0
- package/src/fills/pages.js +260 -0
- package/src/fills/reserve.d.ts +11 -0
- package/src/fills/reserve.js +72 -0
- package/src/fills/time.d.ts +2 -0
- package/src/fills/time.js +29 -0
- package/src/fills/unlocker.d.ts +6 -0
- package/src/fills/unlocker.js +26 -0
- package/src/fills/vitals.d.ts +8 -0
- package/src/fills/vitals.js +100 -0
- package/src/fills/windows-start.d.ts +2 -0
- package/src/fills/windows-start.js +21 -0
- package/src/halves/build.d.ts +10 -0
- package/src/halves/build.js +219 -0
- package/src/halves/end.d.ts +17 -0
- package/src/halves/end.js +157 -0
- package/src/halves/genome.d.ts +3 -0
- package/src/halves/genome.js +21 -0
- package/src/halves/handler.d.ts +8 -0
- package/src/halves/handler.js +40 -0
- package/src/halves/index.d.ts +5 -0
- package/src/halves/index.js +6 -0
- package/src/halves/laid.d.ts +12 -0
- package/src/halves/laid.js +103 -0
- package/src/halves/lent.d.ts +6 -0
- package/src/halves/lent.js +147 -0
- package/src/halves/native.d.ts +12 -0
- package/src/halves/native.js +53 -0
- package/src/halves/statements.d.ts +23 -0
- package/src/halves/statements.js +165 -0
- package/src/halves/tokens.d.ts +22 -0
- package/src/halves/tokens.js +135 -0
- package/src/link/link.d.ts +4 -0
- package/src/link/link.js +4 -0
- package/src/link/placeholder.d.ts +1 -0
- package/src/link/placeholder.js +21 -0
- package/src/link/steps.d.ts +52 -0
- package/src/link/steps.js +118 -0
- package/src/lobes/calls.d.ts +76 -0
- package/src/lobes/calls.js +61 -0
- package/src/lobes/channel.d.ts +76 -0
- package/src/lobes/channel.js +202 -0
- package/src/lobes/index.d.ts +1 -0
- package/src/lobes/index.js +2 -0
- package/src/lobes/lobes.d.ts +15 -0
- package/src/lobes/lobes.js +244 -0
- package/src/lobes/main.js +107 -0
- package/src/lobes/thread.d.ts +22 -0
- package/src/lobes/thread.js +270 -0
- package/src/organism/act.d.ts +8 -0
- package/src/organism/act.js +63 -0
- package/src/organism/beat.d.ts +5 -0
- package/src/organism/beat.js +45 -0
- package/src/organism/compiled.d.ts +2 -0
- package/src/organism/compiled.js +24 -0
- package/src/organism/folder.d.ts +88 -0
- package/src/organism/folder.js +259 -0
- package/src/organism/main.d.ts +1 -0
- package/src/organism/main.js +11 -0
- package/src/organism/organism.d.ts +1 -0
- package/src/organism/organism.js +220 -0
- package/src/organism/said.d.ts +12 -0
- package/src/organism/said.js +30 -0
- package/src/organism/told.d.ts +5 -0
- package/src/organism/told.js +110 -0
- package/src/organism/unlock.d.ts +8 -0
- package/src/organism/unlock.js +95 -0
- package/src/organism/upgrade.d.ts +24 -0
- package/src/organism/upgrade.js +145 -0
- package/src/organism/via.d.ts +7 -0
- package/src/organism/via.js +20 -0
- package/src/service/body.d.ts +8 -0
- package/src/service/body.js +34 -0
- package/src/service/handler.d.ts +20 -0
- package/src/service/handler.js +128 -0
- package/src/service/index.d.ts +4 -0
- package/src/service/index.js +16 -0
- package/src/service/manager.d.ts +18 -0
- package/src/service/manager.js +185 -0
- package/src/service/service.d.ts +24 -0
- package/src/service/service.js +200 -0
- package/src/service/swap.d.ts +12 -0
- package/src/service/swap.js +74 -0
- package/src/service/watchdog.d.ts +6 -0
- package/src/service/watchdog.js +31 -0
- package/src/tcp/crowd.d.ts +18 -0
- package/src/tcp/crowd.js +85 -0
- package/src/tcp/dial.d.ts +23 -0
- package/src/tcp/dial.js +102 -0
- package/src/tcp/frame.d.ts +23 -0
- package/src/tcp/frame.js +159 -0
- package/src/tcp/listen.d.ts +50 -0
- package/src/tcp/listen.js +207 -0
- package/src/tcp/source.d.ts +2 -0
- package/src/tcp/source.js +26 -0
- package/src/version/index.d.ts +1 -0
- package/src/version/index.js +2 -0
- package/src/version/version.d.ts +1 -0
- package/src/version/version.js +2 -0
- package/src/work/first.d.ts +11 -0
- package/src/work/first.js +91 -0
- package/src/work/index.d.ts +2 -0
- package/src/work/index.js +15 -0
- package/src/work/work.d.ts +20 -0
- package/src/work/work.js +136 -0
- package/src/ws/dial.d.ts +7 -0
- package/src/ws/dial.js +252 -0
- package/src/ws/dialing.d.ts +50 -0
- package/src/ws/dialing.js +72 -0
- package/src/ws/frame.d.ts +32 -0
- package/src/ws/frame.js +124 -0
- package/src/ws/handshake.d.ts +4 -0
- package/src/ws/handshake.js +27 -0
- package/src/ws/line.d.ts +45 -0
- package/src/ws/line.js +250 -0
- package/src/ws/listen.d.ts +42 -0
- package/src/ws/listen.js +272 -0
- package/src/ws/rfc6455.d.ts +18 -0
- package/src/ws/rfc6455.js +187 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { isFields, } from '@nervur.org/genome/standard';
|
|
3
|
+
import { cardOfVouch, readLink, } from './link.js';
|
|
4
|
+
import { placeholderOf } from './placeholder.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const UNREACHED = { reached: false };
|
|
12
|
+
|
|
13
|
+
const hostOf = (address ) =>
|
|
14
|
+
address !== undefined && URL.canParse(address) ? new URL(address).hostname || null : null;
|
|
15
|
+
|
|
16
|
+
const inviterOf = (domain , card ) => ({
|
|
17
|
+
domain,
|
|
18
|
+
ward: card.ward,
|
|
19
|
+
named: domain === null ? hostOf(card.at[0]) : null,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const sentence = (message ) => {
|
|
48
|
+
const first = message.charAt(0).toUpperCase() + message.slice(1);
|
|
49
|
+
return /[.!?]$/u.test(first) ? first : `${first}.`;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const cardOf = async (
|
|
53
|
+
domain ,
|
|
54
|
+
given ,
|
|
55
|
+
ports ,
|
|
56
|
+
) => {
|
|
57
|
+
if (given !== null) return given;
|
|
58
|
+
const body = domain === null ? null : await ports.vouch(domain);
|
|
59
|
+
if (domain === null || body === null)
|
|
60
|
+
return { why: `${domain ?? 'The site'} did not answer with what it says about itself.` };
|
|
61
|
+
return cardOfVouch(domain, body);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
export const joinInvitation = async (
|
|
67
|
+
invitation ,
|
|
68
|
+
domain ,
|
|
69
|
+
{ relation, note: typed } ,
|
|
70
|
+
ports ,
|
|
71
|
+
) => {
|
|
72
|
+
const held = await ports.held();
|
|
73
|
+
if (held === null) return { why: 'The invitation was not accepted. The home did not say what it holds.' };
|
|
74
|
+
const placeholder = relation ?? placeholderOf(domain ?? 'invitation', new Set(held));
|
|
75
|
+
const note = { ...typed, domain, accepted: ports.now() };
|
|
76
|
+
const answer = await ports.accept({ invitation }, placeholder, note);
|
|
77
|
+
if ('error' in answer) return { why: `The invitation was not accepted. ${sentence(answer.error.message)}` };
|
|
78
|
+
const route = isFields(answer.result) ? answer.result['text'] : undefined;
|
|
79
|
+
return typeof route === 'string'
|
|
80
|
+
? { text: route }
|
|
81
|
+
: { why: 'The invitation was accepted, but no place to see it was named.' };
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const spanOf = (value ) =>
|
|
85
|
+
value === null || (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0) ? value : undefined;
|
|
86
|
+
|
|
87
|
+
const offerIn = (answer ) => {
|
|
88
|
+
if ('error' in answer) return answer.error.code === 'refused' ? { why: sentence(answer.error.message) } : null;
|
|
89
|
+
if (!isFields(answer.result)) return null;
|
|
90
|
+
if (answer.result['reached'] === false && Object.keys(answer.result).length === 1) return UNREACHED;
|
|
91
|
+
const { says, waits, lives } = answer.result;
|
|
92
|
+
const [left, life] = [spanOf(waits), spanOf(lives)];
|
|
93
|
+
return left === undefined || life === undefined ? null : { says: says ?? null, waits: left, lives: life };
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const lookLink = async (text , ports ) => {
|
|
97
|
+
const link = readLink(text);
|
|
98
|
+
if (link === null) return { why: 'This is not a link this page can open.' };
|
|
99
|
+
const [domain, given] = 'domain' in link ? [link.domain, null] : [null, link.card];
|
|
100
|
+
const card = await cardOf(domain, given, ports);
|
|
101
|
+
if ('why' in card) return card;
|
|
102
|
+
const offer = offerIn(await ports.offer(card, link.reference, domain));
|
|
103
|
+
if (offer !== null && 'why' in offer) return offer;
|
|
104
|
+
return { ...inviterOf(domain, card), offer };
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const takeLink = async (text , ports ) => {
|
|
108
|
+
const link = readLink(text);
|
|
109
|
+
if (link === null) return { why: 'This is not a link this page can open.' };
|
|
110
|
+
const [domain, given] = 'domain' in link ? [link.domain, null] : [null, link.card];
|
|
111
|
+
const card = await cardOf(domain, given, ports);
|
|
112
|
+
if ('why' in card) return card;
|
|
113
|
+
const redeemed = await ports.redeem(card, link.reference, domain);
|
|
114
|
+
if ('error' in redeemed) return { why: sentence(redeemed.error.message) };
|
|
115
|
+
const invitation = isFields(redeemed.result) ? redeemed.result['invitation'] : undefined;
|
|
116
|
+
if (typeof invitation !== 'string') return { why: 'The invitation could not be read.' };
|
|
117
|
+
return { ...inviterOf(domain, card), invitation };
|
|
118
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AskGear, Broken, Fell, Readout, Running, Told as Tells } from '@nervur.org/genome/cage';
|
|
2
|
+
import type { AskInput, RunOutput } from '@nervur.org/genome/faculty';
|
|
3
|
+
import type { MessagePort } from 'node:worker_threads';
|
|
4
|
+
import type { Data } from '@nervur.org/genome/standard';
|
|
5
|
+
import type { Shared } from './channel.js';
|
|
6
|
+
export type ThreadData = {
|
|
7
|
+
readonly shared: Shared;
|
|
8
|
+
readonly port: MessagePort;
|
|
9
|
+
readonly rate: number;
|
|
10
|
+
readonly memory: number;
|
|
11
|
+
};
|
|
12
|
+
export type Call = {
|
|
13
|
+
readonly number: number;
|
|
14
|
+
readonly run: number;
|
|
15
|
+
} & ({
|
|
16
|
+
readonly op: 'start';
|
|
17
|
+
readonly lobe: string;
|
|
18
|
+
readonly digest: string;
|
|
19
|
+
readonly input: AskInput;
|
|
20
|
+
readonly kind: 'reading' | 'writing';
|
|
21
|
+
readonly reads: boolean;
|
|
22
|
+
readonly memory?: number;
|
|
23
|
+
} | {
|
|
24
|
+
readonly op: 'settle';
|
|
25
|
+
readonly wait: number;
|
|
26
|
+
readonly answer: Data;
|
|
27
|
+
} | {
|
|
28
|
+
readonly op: 'run';
|
|
29
|
+
readonly input: Data;
|
|
30
|
+
} | {
|
|
31
|
+
readonly op: 'read';
|
|
32
|
+
readonly source: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly op: 'end';
|
|
35
|
+
});
|
|
36
|
+
export type Told = Call | {
|
|
37
|
+
readonly op: 'idle';
|
|
38
|
+
};
|
|
39
|
+
export type Came = {
|
|
40
|
+
readonly number: number;
|
|
41
|
+
} & ({
|
|
42
|
+
readonly step: Running | Broken;
|
|
43
|
+
} | {
|
|
44
|
+
readonly ran: RunOutput | Broken;
|
|
45
|
+
} | {
|
|
46
|
+
readonly readout: Readout | Broken;
|
|
47
|
+
} | {
|
|
48
|
+
readonly done: true;
|
|
49
|
+
});
|
|
50
|
+
export type Heard = {
|
|
51
|
+
readonly ready: true;
|
|
52
|
+
} | (Came & {
|
|
53
|
+
readonly worked: number;
|
|
54
|
+
});
|
|
55
|
+
export type Standing = {
|
|
56
|
+
readonly id: number;
|
|
57
|
+
readonly gear: AskGear;
|
|
58
|
+
readonly fell: Fell;
|
|
59
|
+
reached: boolean;
|
|
60
|
+
ended: boolean;
|
|
61
|
+
begin(): void;
|
|
62
|
+
};
|
|
63
|
+
type Numbered<Op> = Op extends unknown ? Omit<Op, 'number' | 'run'> : never;
|
|
64
|
+
export type Asked = {
|
|
65
|
+
readonly call: Numbered<Call>;
|
|
66
|
+
readonly work: number;
|
|
67
|
+
} & ({
|
|
68
|
+
readonly step: Tells<Running>;
|
|
69
|
+
} | {
|
|
70
|
+
readonly ran: Tells<RunOutput>;
|
|
71
|
+
} | {
|
|
72
|
+
readonly readout: Tells<Readout>;
|
|
73
|
+
} | {
|
|
74
|
+
readonly done: true;
|
|
75
|
+
});
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
|
|
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
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { LobeAsk, RunCells } from '@nervur.org/genome/cage';
|
|
2
|
+
import type { Data } from '@nervur.org/genome/standard';
|
|
3
|
+
export type Shared = {
|
|
4
|
+
readonly words: SharedArrayBuffer;
|
|
5
|
+
readonly data: SharedArrayBuffer;
|
|
6
|
+
};
|
|
7
|
+
export type Question = {
|
|
8
|
+
readonly name: 'get' | 'delete';
|
|
9
|
+
readonly run: number;
|
|
10
|
+
readonly key: Data;
|
|
11
|
+
} | {
|
|
12
|
+
readonly name: 'set';
|
|
13
|
+
readonly run: number;
|
|
14
|
+
readonly key: Data;
|
|
15
|
+
readonly value: Data;
|
|
16
|
+
} | {
|
|
17
|
+
readonly name: 'range';
|
|
18
|
+
readonly run: number;
|
|
19
|
+
readonly range: Data;
|
|
20
|
+
} | {
|
|
21
|
+
readonly name: 'ask';
|
|
22
|
+
readonly run: number;
|
|
23
|
+
readonly ask: LobeAsk;
|
|
24
|
+
} | {
|
|
25
|
+
readonly name: 'read';
|
|
26
|
+
readonly run: number;
|
|
27
|
+
readonly source: string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly name: 'run';
|
|
30
|
+
readonly run: number;
|
|
31
|
+
readonly input: Data;
|
|
32
|
+
} | {
|
|
33
|
+
readonly name: 'code';
|
|
34
|
+
readonly run: 0;
|
|
35
|
+
readonly digest: string;
|
|
36
|
+
};
|
|
37
|
+
export type Answers = {
|
|
38
|
+
readonly get: ReturnType<RunCells['get']>;
|
|
39
|
+
readonly set: ReturnType<RunCells['set']>;
|
|
40
|
+
readonly delete: ReturnType<RunCells['delete']>;
|
|
41
|
+
readonly range: ReturnType<RunCells['range']>;
|
|
42
|
+
readonly ask: number;
|
|
43
|
+
readonly read: number;
|
|
44
|
+
readonly run: Data | {
|
|
45
|
+
readonly wait: number;
|
|
46
|
+
};
|
|
47
|
+
readonly code: string | null;
|
|
48
|
+
};
|
|
49
|
+
export type Reply = {
|
|
50
|
+
readonly answer: Answers[keyof Answers];
|
|
51
|
+
} | {
|
|
52
|
+
readonly gone: string;
|
|
53
|
+
};
|
|
54
|
+
export declare const sharedOf: (memory: number) => Shared;
|
|
55
|
+
export type ThreadClock = (() => number) | null;
|
|
56
|
+
export declare const threadClock: ThreadClock;
|
|
57
|
+
export type ThreadEnd = {
|
|
58
|
+
running(number: number): void;
|
|
59
|
+
worked(): number;
|
|
60
|
+
readonly cut: () => boolean;
|
|
61
|
+
ask<Name extends keyof Answers>(question: Question & {
|
|
62
|
+
readonly name: Name;
|
|
63
|
+
}): Answers[Name];
|
|
64
|
+
};
|
|
65
|
+
export declare const threadEnd: ({ words, data }: Shared, clock?: ThreadClock) => ThreadEnd;
|
|
66
|
+
export type BrainEnd = {
|
|
67
|
+
begun(): void;
|
|
68
|
+
worked(): number;
|
|
69
|
+
workedOf(number: number, used: number): number | null;
|
|
70
|
+
cut(number: number): void;
|
|
71
|
+
close(): void;
|
|
72
|
+
};
|
|
73
|
+
export declare const brainEnd: ({ words, data }: Shared, serve: (question: Question) => Reply) => BrainEnd;
|
|
74
|
+
export declare const processorWorked: (end: BrainEnd, number: number, worker: {
|
|
75
|
+
readonly cpuUsage?: () => Promise<NodeJS.CpuUsage>;
|
|
76
|
+
}) => Promise<number | null>;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { deserialize, serialize } from 'node:v8';
|
|
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
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const CUT = 0;
|
|
38
|
+
const ASKED = 1;
|
|
39
|
+
const ANSWERED = 2;
|
|
40
|
+
const WORKED = 3;
|
|
41
|
+
const CLOCKED = 0;
|
|
42
|
+
const RUNNING = 1;
|
|
43
|
+
const BEGAN = 2;
|
|
44
|
+
const LONG_AT = 4 * Int32Array.BYTES_PER_ELEMENT;
|
|
45
|
+
const HEAD = Uint32Array.BYTES_PER_ELEMENT;
|
|
46
|
+
const FIRST = 64 * 1024;
|
|
47
|
+
const MEBIBYTE = 1024 * 1024;
|
|
48
|
+
|
|
49
|
+
export const sharedOf = (memory ) => ({
|
|
50
|
+
words: new SharedArrayBuffer(LONG_AT + 3 * BigInt64Array.BYTES_PER_ELEMENT),
|
|
51
|
+
data: new SharedArrayBuffer(FIRST, { maxByteLength: 2 * memory + MEBIBYTE }),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const lay = (data , value ) => {
|
|
55
|
+
const bytes = serialize(value);
|
|
56
|
+
const size = bytes.length + HEAD;
|
|
57
|
+
if (size > data.maxByteLength) return false;
|
|
58
|
+
if (size > data.byteLength) data.grow(Math.min(data.maxByteLength, Math.max(size, 2 * data.byteLength)));
|
|
59
|
+
new Uint32Array(data, 0, 1)[0] = bytes.length;
|
|
60
|
+
new Uint8Array(data).set(bytes, HEAD);
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const copied = (data ) =>
|
|
65
|
+
Buffer.from(new Uint8Array(data, HEAD, new Uint32Array(data, 0, 1)[0] ?? 0));
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
export const threadClock =
|
|
70
|
+
typeof process.threadCpuUsage === 'function'
|
|
71
|
+
? () => {
|
|
72
|
+
const { user, system } = process.threadCpuUsage();
|
|
73
|
+
return user + system;
|
|
74
|
+
}
|
|
75
|
+
: null;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export const threadEnd = ({ words, data } , clock = threadClock) => {
|
|
89
|
+
const word = new Int32Array(words);
|
|
90
|
+
const long = new BigInt64Array(words, LONG_AT, 3);
|
|
91
|
+
Atomics.store(long, CLOCKED, clock === null ? 0n : 1n);
|
|
92
|
+
let asked = 0;
|
|
93
|
+
let running = 0;
|
|
94
|
+
let from = performance.now();
|
|
95
|
+
let began = clock?.() ?? 0;
|
|
96
|
+
let waited = 0;
|
|
97
|
+
const worked = () =>
|
|
98
|
+
clock === null ? performance.now() - from - waited : Math.max(0, (clock() - began) / 1000);
|
|
99
|
+
return {
|
|
100
|
+
running: (number) => {
|
|
101
|
+
running = number;
|
|
102
|
+
from = performance.now();
|
|
103
|
+
waited = 0;
|
|
104
|
+
began = clock?.() ?? 0;
|
|
105
|
+
Atomics.store(long, BEGAN, BigInt(Math.floor(began)));
|
|
106
|
+
Atomics.store(long, RUNNING, BigInt(number));
|
|
107
|
+
},
|
|
108
|
+
worked,
|
|
109
|
+
cut: () => Atomics.load(word, CUT) === running,
|
|
110
|
+
ask: (question ) => {
|
|
111
|
+
if (!lay(data, question)) throw new Error('out of memory');
|
|
112
|
+
const before = asked;
|
|
113
|
+
asked = (asked + 1) | 0;
|
|
114
|
+
Atomics.store(word, WORKED, Math.floor(worked()));
|
|
115
|
+
const blocked = performance.now();
|
|
116
|
+
Atomics.store(word, ASKED, asked);
|
|
117
|
+
Atomics.notify(word, ASKED);
|
|
118
|
+
while (Atomics.load(word, ANSWERED) !== asked) Atomics.wait(word, ANSWERED, before);
|
|
119
|
+
const reply =
|
|
120
|
+
deserialize(copied(data));
|
|
121
|
+
waited += Math.max(0, performance.now() - blocked - reply.served);
|
|
122
|
+
if ('gone' in reply) throw new Error(reply.gone);
|
|
123
|
+
return reply.answer;
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
export const brainEnd = ({ words, data } , serve ) => {
|
|
142
|
+
const word = new Int32Array(words);
|
|
143
|
+
const long = new BigInt64Array(words, LONG_AT, 3);
|
|
144
|
+
let seen = 0;
|
|
145
|
+
let closed = false;
|
|
146
|
+
let base = 0;
|
|
147
|
+
let since = performance.now();
|
|
148
|
+
const answer = (asked ) => {
|
|
149
|
+
seen = asked;
|
|
150
|
+
base = Atomics.load(word, WORKED);
|
|
151
|
+
since = performance.now();
|
|
152
|
+
const question = deserialize(copied(data));
|
|
153
|
+
const reply = serve(question);
|
|
154
|
+
const served = performance.now() - since;
|
|
155
|
+
if (!lay(data, { ...reply, served })) lay(data, { gone: 'out of memory', served });
|
|
156
|
+
Atomics.store(word, ANSWERED, asked);
|
|
157
|
+
Atomics.notify(word, ANSWERED);
|
|
158
|
+
};
|
|
159
|
+
const listen = () => {
|
|
160
|
+
const waiting = Atomics.waitAsync(word, ASKED, seen);
|
|
161
|
+
if (waiting.async) void waiting.value.then(heard);
|
|
162
|
+
else setImmediate(heard);
|
|
163
|
+
};
|
|
164
|
+
const heard = () => {
|
|
165
|
+
if (closed) return;
|
|
166
|
+
const asked = Atomics.load(word, ASKED);
|
|
167
|
+
if (asked !== seen) answer(asked);
|
|
168
|
+
listen();
|
|
169
|
+
};
|
|
170
|
+
listen();
|
|
171
|
+
return {
|
|
172
|
+
begun: () => {
|
|
173
|
+
base = 0;
|
|
174
|
+
since = performance.now();
|
|
175
|
+
},
|
|
176
|
+
worked: () => (Atomics.load(word, ASKED) === seen ? base + performance.now() - since : Atomics.load(word, WORKED)),
|
|
177
|
+
workedOf: (number, used) => {
|
|
178
|
+
if (Atomics.load(long, CLOCKED) === 0n) return null;
|
|
179
|
+
if (Atomics.load(long, RUNNING) !== BigInt(number)) return 0;
|
|
180
|
+
return Math.max(0, (used - Number(Atomics.load(long, BEGAN))) / 1000);
|
|
181
|
+
},
|
|
182
|
+
cut: (number) => void Atomics.store(word, CUT, number),
|
|
183
|
+
close: () => {
|
|
184
|
+
closed = true;
|
|
185
|
+
Atomics.notify(word, ASKED);
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const processorWorked = async (
|
|
191
|
+
end ,
|
|
192
|
+
number ,
|
|
193
|
+
worker ,
|
|
194
|
+
) => {
|
|
195
|
+
if (typeof worker.cpuUsage !== 'function') return null;
|
|
196
|
+
try {
|
|
197
|
+
const { user, system } = await worker.cpuUsage();
|
|
198
|
+
return end.workedOf(number, user + system);
|
|
199
|
+
} catch {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GRACE, nodeLobes, totalOf, WARM, type LobesGear } from './lobes.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LobesOf } from '@nervur.org/genome/cage';
|
|
2
|
+
export declare const GRACE = 20;
|
|
3
|
+
export declare const WARM = 2;
|
|
4
|
+
export declare const totalOf: (memory: number, bytes?: number) => number;
|
|
5
|
+
export type LobesGear = {
|
|
6
|
+
readonly memory: number;
|
|
7
|
+
readonly rate: number;
|
|
8
|
+
readonly compiled?: string;
|
|
9
|
+
readonly total?: number;
|
|
10
|
+
readonly warm?: number;
|
|
11
|
+
readonly grace?: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const nodeLobes: (gear: LobesGear) => LobesOf & {
|
|
14
|
+
readonly ended: () => Promise<void>;
|
|
15
|
+
};
|