@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.
- package/LICENSE +105 -0
- package/README.md +158 -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 +30756 -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 +256 -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 +41 -0
- package/src/command/before.js +237 -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 +17 -0
- package/src/command/trial.js +92 -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 +219 -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,10 @@
|
|
|
1
|
+
import { type Pipe } from './proof.js';
|
|
2
|
+
export declare const socketOf: (home: string) => string;
|
|
3
|
+
export declare const pipeForListen: () => Pipe | null;
|
|
4
|
+
export declare const dialable: (path: string) => {
|
|
5
|
+
readonly at: string;
|
|
6
|
+
readonly secret: string | null;
|
|
7
|
+
};
|
|
8
|
+
export declare const socketTooLong: (path: string) => string | null;
|
|
9
|
+
export declare const reachedByAnother: (folder: string) => string | null;
|
|
10
|
+
export declare const clearedSocket: (path: string) => string | null;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { lstatSync, readFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { readByAnother } from '../../../src/fills/account-only.js';
|
|
5
|
+
import { drawnPipe, pipeIn, } from './proof.js';
|
|
6
|
+
|
|
7
|
+
const REACHED_BY_ANOTHER = 0o077;
|
|
8
|
+
|
|
9
|
+
export const socketOf = (home ) => join(home, 'console.sock');
|
|
10
|
+
|
|
11
|
+
const WINDOWS = process.platform === 'win32';
|
|
12
|
+
|
|
13
|
+
export const pipeForListen = () => (WINDOWS ? drawnPipe() : null);
|
|
14
|
+
|
|
15
|
+
export const dialable = (path ) => {
|
|
16
|
+
if (!WINDOWS) return { at: path, secret: null };
|
|
17
|
+
try {
|
|
18
|
+
return pipeIn(readFileSync(path, 'utf8')) ?? { at: path, secret: null };
|
|
19
|
+
} catch {
|
|
20
|
+
return { at: path, secret: null };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const LONGEST_SOCKET = process.platform === 'linux' ? 107 : 103;
|
|
25
|
+
|
|
26
|
+
export const socketTooLong = (path ) =>
|
|
27
|
+
!WINDOWS && Buffer.byteLength(path) > LONGEST_SOCKET
|
|
28
|
+
? `the console's socket would stand at ${path}, longer than this host's ${LONGEST_SOCKET} bytes; choose a shorter home folder`
|
|
29
|
+
: null;
|
|
30
|
+
|
|
31
|
+
export const reachedByAnother = (folder ) => {
|
|
32
|
+
let stat;
|
|
33
|
+
try {
|
|
34
|
+
stat = lstatSync(folder);
|
|
35
|
+
} catch {
|
|
36
|
+
return `no folder stands at ${folder}`;
|
|
37
|
+
}
|
|
38
|
+
if (!stat.isDirectory()) return `${folder} is not a folder of its own`;
|
|
39
|
+
if (WINDOWS ? readByAnother(folder) : stat.uid !== process.getuid?.() || (stat.mode & REACHED_BY_ANOTHER) !== 0)
|
|
40
|
+
return `another account can reach ${folder}, so its console is refused; make it this account's alone${WINDOWS ? '' : ', as chmod 700 does'}`;
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const clearedSocket = (path ) => {
|
|
45
|
+
try {
|
|
46
|
+
if (!WINDOWS && !lstatSync(path).isSocket()) return `${path} is not a socket of the organism's`;
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
rmSync(path, { force: true });
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { clearedSocket, dialable, pipeForListen, reachedByAnother, socketOf, socketTooLong } from './guard.js';
|
|
2
|
+
export { typeLine, watchConsole, type Heard, type Watch, type Watching } from './line.js';
|
|
3
|
+
export { listenConsole, type Listening, type Moved, type Typed } from './socket.js';
|
|
4
|
+
export { provingFirst, toldOf } from './proof.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
export { clearedSocket, dialable, pipeForListen, reachedByAnother, socketOf, socketTooLong } from './guard.js';
|
|
3
|
+
export { typeLine, watchConsole, } from './line.js';
|
|
4
|
+
export { listenConsole, } from './socket.js';
|
|
5
|
+
export { provingFirst, toldOf } from './proof.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Answer } from '@nervur.org/genome/standard';
|
|
2
|
+
import { type Moved } from './socket.js';
|
|
3
|
+
type Why = {
|
|
4
|
+
readonly why: string;
|
|
5
|
+
};
|
|
6
|
+
export type Heard = {
|
|
7
|
+
readonly answer: Answer;
|
|
8
|
+
readonly text: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const typeLine: (path: string, words: readonly string[], wait: number, within?: number) => Promise<Heard | Why>;
|
|
11
|
+
export type Watching = {
|
|
12
|
+
readonly close: () => void;
|
|
13
|
+
};
|
|
14
|
+
export type Watch = (moved: (moved: Moved) => void, ended: () => void) => Promise<Watching | Why>;
|
|
15
|
+
export declare const watchConsole: (path: string, wait: number, moved: (moved: Moved) => void, ended: () => void, within?: number) => Promise<Watching | Why>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { connect, } from 'node:net';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { dataText, isFields, readAnswer, readText, } from '@nervur.org/genome/standard';
|
|
5
|
+
import { toldAt } from '../../../src/organism/told.js';
|
|
6
|
+
import { dialable, reachedByAnother } from './guard.js';
|
|
7
|
+
import { provedBy } from './proof.js';
|
|
8
|
+
import { LONGEST_WAIT } from '../../../src/door/longest.js';
|
|
9
|
+
import { LONGEST, } from './socket.js';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const dialed = (path ) =>
|
|
16
|
+
new Promise((done) => {
|
|
17
|
+
const { at, secret } = dialable(path);
|
|
18
|
+
const socket = connect(at);
|
|
19
|
+
socket.once('error', (error) => done(error));
|
|
20
|
+
socket.once('connect', () => {
|
|
21
|
+
if (secret === null) {
|
|
22
|
+
done(socket);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
void provedBy(socket, secret).then((refused) => {
|
|
26
|
+
if (refused !== null) socket.destroy();
|
|
27
|
+
done(refused ?? socket);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const reached = async (path , wait ) => {
|
|
33
|
+
const found = await toldAt (
|
|
34
|
+
path,
|
|
35
|
+
async () => {
|
|
36
|
+
const socket = await dialed(path);
|
|
37
|
+
if (!(socket instanceof Error)) return socket;
|
|
38
|
+
const notUp = socket.code === 'ENOENT' || socket.code === 'ECONNREFUSED';
|
|
39
|
+
return notUp ? null : { why: `the console at ${path} refused: ${socket.message}` };
|
|
40
|
+
},
|
|
41
|
+
wait,
|
|
42
|
+
);
|
|
43
|
+
return found ?? { why: `no console answers at ${path}` };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const answerOver = (socket , within ) =>
|
|
47
|
+
new Promise((done) => {
|
|
48
|
+
const held = [];
|
|
49
|
+
const silent = () => {
|
|
50
|
+
socket.destroy();
|
|
51
|
+
done({ why: `the console said nothing for ${within / 1000} s` });
|
|
52
|
+
};
|
|
53
|
+
let timer = setTimeout(silent, within);
|
|
54
|
+
const finish = (heard ) => {
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
socket.destroy();
|
|
57
|
+
done(heard);
|
|
58
|
+
};
|
|
59
|
+
socket.setEncoding('utf8');
|
|
60
|
+
socket.on('data', (chunk ) => {
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
timer = setTimeout(silent, within);
|
|
63
|
+
const text = held.length === 0 ? chunk.trimStart() : chunk;
|
|
64
|
+
const at = text.indexOf('\n');
|
|
65
|
+
if (at === -1) {
|
|
66
|
+
if (text.length > 0) held.push(text);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
held.push(text.slice(0, at));
|
|
70
|
+
const read = readText(held.join(''));
|
|
71
|
+
const answer = 'data' in read ? readAnswer(read.data) : read;
|
|
72
|
+
finish(
|
|
73
|
+
'why' in answer
|
|
74
|
+
? { why: `the console answered no answer: ${answer.why}` }
|
|
75
|
+
: { answer: answer.answer, text: dataText(answer.answer) },
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
socket.on('close', () => finish({ why: 'the console closed before it answered' }));
|
|
79
|
+
socket.on('error', (error) => finish({ why: `the console's socket failed: ${error.message}` }));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export const typeLine = async (
|
|
83
|
+
path ,
|
|
84
|
+
words ,
|
|
85
|
+
wait ,
|
|
86
|
+
within = LONGEST_WAIT,
|
|
87
|
+
) => {
|
|
88
|
+
const why = reachedByAnother(dirname(path));
|
|
89
|
+
if (why !== null) return { why };
|
|
90
|
+
const line = `${dataText([...words])}\n`;
|
|
91
|
+
if (line.length > LONGEST) return { why: `a line holds at most ${LONGEST} bytes` };
|
|
92
|
+
const socket = await reached(path, wait);
|
|
93
|
+
if ('why' in socket) return socket;
|
|
94
|
+
const heard = answerOver(socket, within);
|
|
95
|
+
socket.write(line);
|
|
96
|
+
return heard;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
const idsAt = (data , field ) => {
|
|
104
|
+
const ids = isFields(data) ? data[field] : undefined;
|
|
105
|
+
return Array.isArray(ids) ? ids.filter((id) => typeof id === 'string') : [];
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const watchConsole = async (
|
|
109
|
+
path ,
|
|
110
|
+
wait ,
|
|
111
|
+
moved ,
|
|
112
|
+
ended ,
|
|
113
|
+
within = LONGEST_WAIT,
|
|
114
|
+
) => {
|
|
115
|
+
const why = reachedByAnother(dirname(path));
|
|
116
|
+
if (why !== null) return { why };
|
|
117
|
+
const socket = await reached(path, wait);
|
|
118
|
+
if ('why' in socket) return socket;
|
|
119
|
+
return new Promise((done) => {
|
|
120
|
+
let held = '';
|
|
121
|
+
let taken = false;
|
|
122
|
+
const timer = setTimeout(() => {
|
|
123
|
+
socket.destroy();
|
|
124
|
+
done({ why: `the console took no watch within ${within / 1000} s` });
|
|
125
|
+
}, within);
|
|
126
|
+
socket.setEncoding('utf8');
|
|
127
|
+
socket.on('data', (chunk ) => {
|
|
128
|
+
held += chunk;
|
|
129
|
+
for (let at = held.indexOf('\n'); at !== -1; at = held.indexOf('\n')) {
|
|
130
|
+
const read = readText(held.slice(0, at));
|
|
131
|
+
held = held.slice(at + 1);
|
|
132
|
+
const data = 'data' in read ? read.data : null;
|
|
133
|
+
if (!taken) {
|
|
134
|
+
taken = true;
|
|
135
|
+
clearTimeout(timer);
|
|
136
|
+
done({ close: () => socket.destroy() });
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
moved({ nodes: idsAt(data, 'nodes'), lobes: idsAt(data, 'lobes'), organs: idsAt(data, 'organs') });
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
socket.on('close', () => {
|
|
143
|
+
clearTimeout(timer);
|
|
144
|
+
if (taken) ended();
|
|
145
|
+
else done({ why: 'the console closed before it took the watch' });
|
|
146
|
+
});
|
|
147
|
+
socket.on('error', () => socket.destroy());
|
|
148
|
+
socket.write(`${dataText(['watch'])}\n`);
|
|
149
|
+
});
|
|
150
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { CONSOLE } from '@nervur.org/genome';
|
|
3
|
+
import { error, isFields, readText, result, } from '@nervur.org/genome/standard';
|
|
4
|
+
import { processIo, refuseHalf, serveHalf, speaker, } from '../../../src/halves/index.js';
|
|
5
|
+
import { listenConsole, } from './socket.js';
|
|
6
|
+
|
|
7
|
+
const LINE_WITHIN = Number.MAX_SAFE_INTEGER;
|
|
8
|
+
const asked =
|
|
9
|
+
(end , words ) =>
|
|
10
|
+
(handler ) =>
|
|
11
|
+
words.length === 2 && words[0] === 'lobe' && words[1] === handler
|
|
12
|
+
? end.ask(handler, null, {}, LINE_WITHIN)
|
|
13
|
+
: end.ask(handler, 'line', { words: [...words] }, LINE_WITHIN);
|
|
14
|
+
|
|
15
|
+
const idsAt = (args , field ) => {
|
|
16
|
+
const ids = isFields(args) ? args[field] : undefined;
|
|
17
|
+
const named = Array.isArray(ids) ? ids.filter((id) => typeof id === 'string') : null;
|
|
18
|
+
return named?.length === (Array.isArray(ids) ? ids.length : -1) ? named : null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const noticed =
|
|
22
|
+
(tell ) =>
|
|
23
|
+
(method , args ) => {
|
|
24
|
+
if (method !== 'changed') return error('unavailable', `the console answers changed alone, and no ${method}`);
|
|
25
|
+
const [nodes, lobes, organs] = [idsAt(args, 'nodes'), idsAt(args, 'lobes'), idsAt(args, 'organs')];
|
|
26
|
+
if (nodes === null || lobes === null || organs === null)
|
|
27
|
+
return error('refused', 'changed names its nodes, lobes and organs');
|
|
28
|
+
tell({ nodes, lobes, organs });
|
|
29
|
+
return result(null);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const io = processIo();
|
|
33
|
+
const reach = readText(process.argv[2] ?? '');
|
|
34
|
+
const socket = 'data' in reach && isFields(reach.data) ? reach.data['socket'] : undefined;
|
|
35
|
+
if (typeof socket !== 'string') {
|
|
36
|
+
refuseHalf(io, 'the console is started with its socket as its reach');
|
|
37
|
+
process.exitCode = 1;
|
|
38
|
+
} else {
|
|
39
|
+
const serving = Promise.withResolvers ();
|
|
40
|
+
const listened = await listenConsole(socket, (words) => serving.promise.then((speak) => speak(words)));
|
|
41
|
+
if ('why' in listened) {
|
|
42
|
+
refuseHalf(io, listened.why);
|
|
43
|
+
process.exitCode = 1;
|
|
44
|
+
} else {
|
|
45
|
+
const stop = () => void listened.close().then(() => process.exit(0));
|
|
46
|
+
process.on('SIGTERM', stop);
|
|
47
|
+
const end = serveHalf(io, CONSOLE.blueprint, noticed(listened.tell), stop);
|
|
48
|
+
const speak = speaker(end, 'the console');
|
|
49
|
+
serving.resolve((words) => speak(asked(end, words)));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PROGRAM: string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Socket } from 'node:net';
|
|
2
|
+
export type Pipe = {
|
|
3
|
+
readonly at: string;
|
|
4
|
+
readonly secret: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const drawnPipe: () => Pipe;
|
|
7
|
+
export declare const toldOf: (pipe: Pipe) => string;
|
|
8
|
+
export declare const pipeIn: (told: string) => Pipe | null;
|
|
9
|
+
export declare const nonceOf: () => string;
|
|
10
|
+
export declare const proofOf: (secret: string, nonce: string) => string;
|
|
11
|
+
export declare const proves: (secret: string, nonce: string, proof: string) => boolean;
|
|
12
|
+
export declare const provingFirst: (secret: string | null, serve: (socket: Socket) => void) => ((socket: Socket) => void);
|
|
13
|
+
export declare const provedBy: (socket: Socket, secret: string, wait?: number) => Promise<null | {
|
|
14
|
+
readonly why: string;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
|
|
4
|
+
import { LONGEST_TIMEOUT } from '../../../src/door/longest.js';
|
|
5
|
+
|
|
6
|
+
const SIZE = 32;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export const drawnPipe = () => ({
|
|
11
|
+
at: `\\\\.\\pipe\\nervur-${randomBytes(16).toString('hex')}`,
|
|
12
|
+
secret: randomBytes(SIZE).toString('hex'),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const toldOf = (pipe ) => `${pipe.at}\n${pipe.secret}\n`;
|
|
16
|
+
|
|
17
|
+
export const pipeIn = (told ) => {
|
|
18
|
+
const [at, secret] = told.split('\n');
|
|
19
|
+
return at !== undefined && at !== '' && secret !== undefined && /^[0-9a-f]{64}$/u.test(secret)
|
|
20
|
+
? { at, secret }
|
|
21
|
+
: null;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const nonceOf = () => randomBytes(SIZE).toString('hex');
|
|
25
|
+
|
|
26
|
+
export const proofOf = (secret , nonce ) =>
|
|
27
|
+
createHmac('sha256', Buffer.from(secret, 'hex')).update(nonce).digest('hex');
|
|
28
|
+
|
|
29
|
+
export const proves = (secret , nonce , proof ) => {
|
|
30
|
+
const wanted = Buffer.from(proofOf(secret, nonce));
|
|
31
|
+
const given = Buffer.from(proof);
|
|
32
|
+
return given.length === wanted.length && timingSafeEqual(given, wanted);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const provingFirst = (secret , serve ) =>
|
|
36
|
+
secret === null
|
|
37
|
+
? serve
|
|
38
|
+
: (socket) => {
|
|
39
|
+
let held = '';
|
|
40
|
+
socket.on('error', () => socket.destroy());
|
|
41
|
+
socket.setTimeout(LONGEST_TIMEOUT, () => socket.destroy());
|
|
42
|
+
const heard = (chunk ) => {
|
|
43
|
+
held += chunk.toString('latin1');
|
|
44
|
+
const at = held.indexOf('\n');
|
|
45
|
+
if (at === -1 && held.length <= SIZE * 2) return;
|
|
46
|
+
socket.removeListener('data', heard);
|
|
47
|
+
socket.setTimeout(0);
|
|
48
|
+
if (at === -1) {
|
|
49
|
+
socket.destroy();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
socket.write(`${proofOf(secret, held.slice(0, at))}\n`);
|
|
53
|
+
serve(socket);
|
|
54
|
+
};
|
|
55
|
+
socket.on('data', heard);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const provedBy = (
|
|
59
|
+
socket ,
|
|
60
|
+
secret ,
|
|
61
|
+
wait = LONGEST_TIMEOUT,
|
|
62
|
+
) =>
|
|
63
|
+
new Promise((done) => {
|
|
64
|
+
const nonce = nonceOf();
|
|
65
|
+
let held = '';
|
|
66
|
+
const finish = (why ) => {
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
socket.removeListener('data', heard);
|
|
69
|
+
socket.removeListener('close', closed);
|
|
70
|
+
done(why === null ? null : { why });
|
|
71
|
+
};
|
|
72
|
+
const refused = 'what answers there is not this organism, so it was told nothing';
|
|
73
|
+
const timer = setTimeout(() => finish(refused), wait);
|
|
74
|
+
const closed = () => finish(refused);
|
|
75
|
+
const heard = (chunk ) => {
|
|
76
|
+
held += chunk.toString('latin1');
|
|
77
|
+
const at = held.indexOf('\n');
|
|
78
|
+
if (at === -1 && held.length <= SIZE * 2) return;
|
|
79
|
+
finish(at !== -1 && proves(secret, nonce, held.slice(0, at)) ? null : refused);
|
|
80
|
+
};
|
|
81
|
+
socket.on('data', heard);
|
|
82
|
+
socket.on('close', closed);
|
|
83
|
+
socket.write(`${nonce}\n`);
|
|
84
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Answer } from '@nervur.org/genome/standard';
|
|
2
|
+
export type Typed = (words: readonly string[]) => Promise<Answer>;
|
|
3
|
+
export declare const LONGEST: number;
|
|
4
|
+
export type Moved = {
|
|
5
|
+
readonly nodes: readonly string[];
|
|
6
|
+
readonly lobes: readonly string[];
|
|
7
|
+
readonly organs: readonly string[];
|
|
8
|
+
};
|
|
9
|
+
export type Listening = {
|
|
10
|
+
readonly close: () => Promise<void>;
|
|
11
|
+
readonly tell: (moved: Moved) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const listenConsole: (path: string, typed: Typed, beat?: number) => Promise<Listening | {
|
|
14
|
+
readonly why: string;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { chmodSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { createServer, } from 'node:net';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
5
|
+
import { BEAT, FRAME_SIZE } from '../../../src/door/longest.js';
|
|
6
|
+
import { dataText, error, readText, result, } from '@nervur.org/genome/standard';
|
|
7
|
+
import { provingFirst, toldOf } from './proof.js';
|
|
8
|
+
import { clearedSocket, pipeForListen, reachedByAnother, socketTooLong } from './guard.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export const LONGEST = Math.floor(FRAME_SIZE / 2);
|
|
13
|
+
|
|
14
|
+
const wordsIn = (data ) => {
|
|
15
|
+
if (!Array.isArray(data) || data.length === 0) return null;
|
|
16
|
+
const words = data.filter((word) => typeof word === 'string');
|
|
17
|
+
return words.length === data.length ? words : null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const refused = (message ) => error('refused', message);
|
|
21
|
+
|
|
22
|
+
const isWatch = (words ) => words?.length === 1 && words[0] === 'watch';
|
|
23
|
+
|
|
24
|
+
const served = (typed , watching , beat ) => (socket ) => {
|
|
25
|
+
let held = '';
|
|
26
|
+
socket.setEncoding('utf8');
|
|
27
|
+
socket.on('error', () => socket.destroy());
|
|
28
|
+
socket.on('data', (chunk ) => {
|
|
29
|
+
held += chunk;
|
|
30
|
+
const at = held.indexOf('\n');
|
|
31
|
+
if (at === -1 && held.length <= LONGEST) return;
|
|
32
|
+
socket.removeAllListeners('data');
|
|
33
|
+
const read = at === -1 ? null : readText(held.slice(0, at));
|
|
34
|
+
const words = read !== null && 'data' in read ? wordsIn(read.data) : null;
|
|
35
|
+
if (isWatch(words)) {
|
|
36
|
+
watching.add(socket);
|
|
37
|
+
socket.on('close', () => watching.delete(socket));
|
|
38
|
+
socket.write(`${dataText(result(null))}\n`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const answering = words === null ? Promise.resolve(refused('a line is its words, one or more')) : typed(words);
|
|
42
|
+
const beating = setInterval(() => socket.write('\n'), beat);
|
|
43
|
+
socket.on('close', () => clearInterval(beating));
|
|
44
|
+
void answering.then((answer) => {
|
|
45
|
+
clearInterval(beating);
|
|
46
|
+
socket.end(`${dataText(answer)}\n`);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export const listenConsole = (
|
|
60
|
+
path ,
|
|
61
|
+
typed ,
|
|
62
|
+
beat = BEAT,
|
|
63
|
+
) => {
|
|
64
|
+
const rising = `${path}~`;
|
|
65
|
+
const why = socketTooLong(rising) ?? reachedByAnother(dirname(path)) ?? clearedSocket(path) ?? clearedSocket(rising);
|
|
66
|
+
if (why !== null) return Promise.resolve({ why });
|
|
67
|
+
const connections = new Set ();
|
|
68
|
+
const watching = new Set ();
|
|
69
|
+
const pipe = pipeForListen();
|
|
70
|
+
const serve = provingFirst(pipe?.secret ?? null, served(typed, watching, beat));
|
|
71
|
+
const server = createServer((socket) => {
|
|
72
|
+
connections.add(socket);
|
|
73
|
+
socket.on('close', () => connections.delete(socket));
|
|
74
|
+
serve(socket);
|
|
75
|
+
});
|
|
76
|
+
const tell = ({ nodes, lobes, organs } ) => {
|
|
77
|
+
const line = `${dataText({ nodes: [...nodes], lobes: [...lobes], organs: [...organs] })}\n`;
|
|
78
|
+
for (const socket of watching) socket.write(line);
|
|
79
|
+
};
|
|
80
|
+
const close = () =>
|
|
81
|
+
new Promise((done) => {
|
|
82
|
+
for (const socket of connections) socket.destroy();
|
|
83
|
+
server.close(() => {
|
|
84
|
+
rmSync(path, { force: true });
|
|
85
|
+
done();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
return new Promise((done) => {
|
|
89
|
+
server.once('error', (failed) => done({ why: `the console cannot listen at ${path}: ${failed.message}` }));
|
|
90
|
+
server.listen(pipe?.at ?? rising, () => {
|
|
91
|
+
if (pipe !== null) writeFileSync(path, toldOf(pipe));
|
|
92
|
+
else {
|
|
93
|
+
chmodSync(rising, 0o600);
|
|
94
|
+
renameSync(rising, path);
|
|
95
|
+
}
|
|
96
|
+
done({ close, tell });
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DISK } from './organ.js';
|