@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,220 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { CIPHERS } from '@nervur.org/genome';
|
|
4
|
+
import { PORT } from '../door/configuration.js';
|
|
5
|
+
import { INSTALLER_VERSION, ownHome, ranOn, wsAddressOf } from '../organism/folder.js';
|
|
6
|
+
import { addressAt } from '../tcp/frame.js';
|
|
7
|
+
import { act } from './act.js';
|
|
8
|
+
import { claimIn } from './claim.js';
|
|
9
|
+
import { chainOf } from './chain.js';
|
|
10
|
+
import { start, stop, } from './commands.js';
|
|
11
|
+
import { line } from './line.js';
|
|
12
|
+
import { accept, offer } from './link.js';
|
|
13
|
+
import { open } from './open.js';
|
|
14
|
+
import { organismOf } from './given.js';
|
|
15
|
+
import { runningOf } from './spawn.js';
|
|
16
|
+
import { arrive, backup, move, restore, stay } from './backup.js';
|
|
17
|
+
import { salvage } from './salvage.js';
|
|
18
|
+
import { repos } from './jailer.js';
|
|
19
|
+
import { repo } from './repo.js';
|
|
20
|
+
import { ends } from './ends.js';
|
|
21
|
+
import { state } from './state.js';
|
|
22
|
+
import { reclaim } from './reclaim.js';
|
|
23
|
+
import { mcp } from './mcp.js';
|
|
24
|
+
import { screen } from './screen.js';
|
|
25
|
+
import { wordsOf } from './words.js';
|
|
26
|
+
import { rekey, rewrap } from './rewrap.js';
|
|
27
|
+
import { wipe } from './wipe.js';
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const version = ({ home, print }) => {
|
|
33
|
+
print(`installer-node ${INSTALLER_VERSION}`);
|
|
34
|
+
const organism = organismOf(home);
|
|
35
|
+
if (runningOf(organism) !== null)
|
|
36
|
+
print(`The organism at ${organism} runs on installer-node ${ranOn(organism) ?? 'an older one'}.`);
|
|
37
|
+
return Promise.resolve(null);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const brainSays =
|
|
41
|
+
(method ) =>
|
|
42
|
+
(given) =>
|
|
43
|
+
line({ ...given, words: ['ask', 'brain', method] });
|
|
44
|
+
|
|
45
|
+
const COMMANDS
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
= new Map([
|
|
49
|
+
['install', { run: act, words: [0, 2], takes: '[version] [digest], and options' }],
|
|
50
|
+
['start', { run: start, words: [0, 0], takes: 'no words, only options' }],
|
|
51
|
+
['stop', { run: stop, words: [0, 0], takes: 'no words, only options' }],
|
|
52
|
+
['update', { run: act, words: [0, 2], takes: '[version] [digest], and options' }],
|
|
53
|
+
['wipe', { run: wipe, words: [0, 0], takes: 'no words, only --home' }],
|
|
54
|
+
['reclaim', { run: reclaim, words: [0, 0], takes: 'no words, only --home' }],
|
|
55
|
+
['backup', { run: backup, words: [0, 1], takes: '[file]' }],
|
|
56
|
+
['restore', { run: restore, words: [1, 2], takes: '<file> [salt]' }],
|
|
57
|
+
['arrive', { run: arrive, words: [0, 0], takes: 'no words, only --home' }],
|
|
58
|
+
['move', { run: move, words: [1, 2], takes: '<key> [file]' }],
|
|
59
|
+
['stay', { run: stay, words: [0, 0], takes: 'no words, only --home' }],
|
|
60
|
+
['salvage', { run: salvage, words: [0, 1], takes: '[file]' }],
|
|
61
|
+
['rewrap', { run: rewrap, words: [0, 0], takes: 'no words, only --home' }],
|
|
62
|
+
['rekey', { run: rekey, words: [0, 0], takes: 'no words, only --home and --cipher' }],
|
|
63
|
+
['repos', { run: repos, words: [0, 0], takes: 'no words, only --home' }],
|
|
64
|
+
['repo', { run: repo, words: [1, 1], takes: '<name> [--starter]' }],
|
|
65
|
+
['screen', { run: screen, words: [0, 0], takes: 'no words, only --home' }],
|
|
66
|
+
['version', { run: version, words: [0, 0], takes: 'no words' }],
|
|
67
|
+
['mcp', { run: mcp, words: [0, 0], takes: 'no words, only --home' }],
|
|
68
|
+
['ask', { run: line, words: [1, 3], takes: '<placeholder> [method] [args]' }],
|
|
69
|
+
['lobe', { run: line, words: [1, 3], takes: '<lobe> [method] [args]' }],
|
|
70
|
+
['accept', { run: accept, words: [1, 3], takes: '<placeholder> <invitation> [note] | <link> [placeholder] [note]' }],
|
|
71
|
+
['offer', { run: offer, words: [1, 1], takes: '<link>' }],
|
|
72
|
+
['open', { run: (given ) => open(given), words: [1, 1], takes: '<link>' }],
|
|
73
|
+
['forget', { run: line, words: [1, 1], takes: '<placeholder>' }],
|
|
74
|
+
['relations', { run: line, words: [0, 0], takes: 'no words' }],
|
|
75
|
+
['ends', { run: ends, words: [0, 1], takes: '[lobe]' }],
|
|
76
|
+
['card', { run: brainSays('card'), words: [0, 0], takes: 'no words' }],
|
|
77
|
+
['state', { run: state, words: [0, 0], takes: 'no words' }],
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
export const COMMAND_NAMES = [...COMMANDS.keys()];
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
const OPTIONS = {
|
|
88
|
+
home: { type: 'string' },
|
|
89
|
+
port: { type: 'string' },
|
|
90
|
+
boot: { type: 'string' },
|
|
91
|
+
keeper: { type: 'string', multiple: true },
|
|
92
|
+
end: { type: 'string' },
|
|
93
|
+
public: { type: 'string' },
|
|
94
|
+
reserve: { type: 'string' },
|
|
95
|
+
screen: { type: 'boolean' },
|
|
96
|
+
'no-screen': { type: 'boolean' },
|
|
97
|
+
ws: { type: 'string' },
|
|
98
|
+
work: { type: 'string' },
|
|
99
|
+
take: { type: 'boolean' },
|
|
100
|
+
channel: { type: 'string' },
|
|
101
|
+
package: { type: 'string' },
|
|
102
|
+
short: { type: 'boolean' },
|
|
103
|
+
floor: { type: 'boolean' },
|
|
104
|
+
faculties: { type: 'string' },
|
|
105
|
+
design: { type: 'string' },
|
|
106
|
+
cipher: { type: 'string' },
|
|
107
|
+
claim: { type: 'string' },
|
|
108
|
+
json: { type: 'boolean' },
|
|
109
|
+
follow: { type: 'boolean' },
|
|
110
|
+
starter: { type: 'boolean' },
|
|
111
|
+
text: { type: 'string', multiple: true },
|
|
112
|
+
help: { type: 'boolean', short: 'h' },
|
|
113
|
+
version: { type: 'boolean', short: 'v' },
|
|
114
|
+
} ;
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
const choicesOf = (values ) => {
|
|
140
|
+
const port = values.port === undefined ? null : Number(values.port);
|
|
141
|
+
if (port !== null && (!Number.isInteger(port) || port < 1 || port > 65_535))
|
|
142
|
+
return { why: `--port is a port, a whole number from 1 to 65535, not ${values.port}` };
|
|
143
|
+
const chain = chainOf(values.keeper, values.end, values.boot);
|
|
144
|
+
if ('why' in chain) return chain;
|
|
145
|
+
const { bootMode, end, keepers } = chain;
|
|
146
|
+
const publicHost = values.public ?? null;
|
|
147
|
+
if (publicHost !== null && addressAt(publicHost, port ?? PORT) === null)
|
|
148
|
+
return { why: `--public is a host, a name or an address, not ${publicHost}` };
|
|
149
|
+
if (values.screen === true && values['no-screen'] === true)
|
|
150
|
+
return { why: '--screen and --no-screen say opposite things' };
|
|
151
|
+
const sits = values.screen === true ? { screen: true } : values['no-screen'] === true ? { screen: false } : {};
|
|
152
|
+
const reserve = values.reserve === undefined ? null : Number(values.reserve);
|
|
153
|
+
if (reserve !== null && (values.reserve === '' || !Number.isInteger(reserve) || reserve < 0))
|
|
154
|
+
return { why: `--reserve is bytes, a whole number from zero, not ${values.reserve ?? ''}` };
|
|
155
|
+
const ws = values.ws ?? null;
|
|
156
|
+
if (ws !== null && !wsAddressOf(ws))
|
|
157
|
+
return { why: `--ws is a ws or wss address, as ws://example.org:7602/quo, not ${ws}` };
|
|
158
|
+
if (values.cipher !== undefined && !CIPHERS.includes(values.cipher))
|
|
159
|
+
return { why: `--cipher is one of ${CIPHERS.join(', ')}, not ${values.cipher}` };
|
|
160
|
+
return {
|
|
161
|
+
port,
|
|
162
|
+
bootMode,
|
|
163
|
+
keepers,
|
|
164
|
+
end,
|
|
165
|
+
publicHost,
|
|
166
|
+
...sits,
|
|
167
|
+
...(reserve === null ? {} : { reserve }),
|
|
168
|
+
ws,
|
|
169
|
+
work: values.work ?? null,
|
|
170
|
+
take: values.take ?? false,
|
|
171
|
+
channel: values.channel ?? null,
|
|
172
|
+
package: values.package ?? null,
|
|
173
|
+
short: values.short ?? false,
|
|
174
|
+
floor: values.floor ?? false,
|
|
175
|
+
faculties: values.faculties ?? null,
|
|
176
|
+
design: values.design ?? null,
|
|
177
|
+
cipher: values.cipher ?? null,
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export const readArgs = (argv ) => {
|
|
182
|
+
let parsed;
|
|
183
|
+
try {
|
|
184
|
+
parsed = parseArgs({ args: [...argv], allowPositionals: true, options: OPTIONS });
|
|
185
|
+
} catch (thrown) {
|
|
186
|
+
return { why: thrown instanceof Error ? thrown.message : String(thrown) };
|
|
187
|
+
}
|
|
188
|
+
const { values } = parsed;
|
|
189
|
+
const [named, ...rest] = parsed.positionals;
|
|
190
|
+
if (named === 'help' || values.help === true) return { help: true };
|
|
191
|
+
const name = values.version === true ? 'version' : named;
|
|
192
|
+
if (name === undefined) return { why: '' };
|
|
193
|
+
const command = COMMANDS.get(name);
|
|
194
|
+
if (command === undefined) return { why: `no command ${name}` };
|
|
195
|
+
const choices = choicesOf(values);
|
|
196
|
+
if ('why' in choices) return choices;
|
|
197
|
+
if (choices.cipher !== null && name !== 'rekey') return { why: '--cipher is for rekey' };
|
|
198
|
+
if (values.starter === true && name !== 'repo') return { why: '--starter is for repo' };
|
|
199
|
+
if (choices.design !== null && !['install', 'update'].includes(name))
|
|
200
|
+
return { why: '--design is for install and update' };
|
|
201
|
+
const claim = claimIn(values.claim, name);
|
|
202
|
+
if ('why' in claim) return claim;
|
|
203
|
+
if (rest.length < command.words[0] || rest.length > command.words[1])
|
|
204
|
+
return { why: `${name} takes ${command.takes}` };
|
|
205
|
+
const words = wordsOf(name, rest, values.text ?? []);
|
|
206
|
+
if ('why' in words) return words;
|
|
207
|
+
return {
|
|
208
|
+
command: command.run,
|
|
209
|
+
given: {
|
|
210
|
+
home: values.home ?? ownHome(),
|
|
211
|
+
served: values.home === undefined,
|
|
212
|
+
...choices,
|
|
213
|
+
...claim,
|
|
214
|
+
words,
|
|
215
|
+
json: values.json ?? false,
|
|
216
|
+
follow: values.follow ?? false,
|
|
217
|
+
...(values.starter === true ? { starter: true } : {}),
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { namedKeyOf } from '@nervur.org/genome';
|
|
5
|
+
import { nobleCrypto } from '@nervur.org/genome/quo';
|
|
6
|
+
import { hex } from '@nervur.org/genome/standard';
|
|
7
|
+
import { laidWhole } from '../fills/flushed.js';
|
|
8
|
+
import { typedFor } from '../organism/folder.js';
|
|
9
|
+
import { arrivalIn, storeFileIn } from './before.js';
|
|
10
|
+
import { organismOf, } from './given.js';
|
|
11
|
+
|
|
12
|
+
export const arrive = (given ) => {
|
|
13
|
+
const home = organismOf(given.home);
|
|
14
|
+
if (existsSync(storeFileIn(home))) return Promise.resolve({ why: `an organism stands at ${home} already` });
|
|
15
|
+
const path = arrivalIn(home);
|
|
16
|
+
if (!existsSync(path)) laidWhole(path, randomBytes(32), 0o600);
|
|
17
|
+
const key = hex(namedKeyOf(nobleCrypto, readFileSync(path)));
|
|
18
|
+
given.print(`On the old device: nervur move ${key}`);
|
|
19
|
+
given.print(`Then, here, with the file it writes: ${typedFor(home)('restore <file>')}. Only this device opens it.`);
|
|
20
|
+
return Promise.resolve(null);
|
|
21
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Data, type Fields } from '@nervur.org/genome/standard';
|
|
2
|
+
type Why = {
|
|
3
|
+
readonly why: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const answered: (home: string, words: readonly string[]) => Promise<{
|
|
6
|
+
readonly data: Data;
|
|
7
|
+
} | Why>;
|
|
8
|
+
export type Line = (words: readonly string[]) => Promise<{
|
|
9
|
+
readonly data: Data;
|
|
10
|
+
} | Why>;
|
|
11
|
+
export declare const lineAt: (home: string) => Line;
|
|
12
|
+
export declare const stateOf: (line: Line) => Promise<{
|
|
13
|
+
readonly data: Fields;
|
|
14
|
+
} | Why>;
|
|
15
|
+
export declare const stateAt: (home: string) => Promise<{
|
|
16
|
+
readonly data: Fields;
|
|
17
|
+
} | Why>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import { dataText, isFields, } from '@nervur.org/genome/standard';
|
|
3
|
+
import { socketOf, typeLine } from '../../organs/console/node/index.js';
|
|
4
|
+
import { LONGEST_TIMEOUT } from '../door/longest.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const answered = async (home , words ) => {
|
|
9
|
+
const heard = await typeLine(socketOf(home), words, LONGEST_TIMEOUT);
|
|
10
|
+
if ('why' in heard) return heard;
|
|
11
|
+
if ('error' in heard.answer) return { why: `${words.slice(0, 3).join(' ')}: ${heard.text}` };
|
|
12
|
+
return { data: heard.answer.result };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export const lineAt =
|
|
18
|
+
(home ) =>
|
|
19
|
+
(words) =>
|
|
20
|
+
answered(home, words);
|
|
21
|
+
|
|
22
|
+
const LISTS = ['nodes', 'letters', 'durables'] ;
|
|
23
|
+
|
|
24
|
+
const pageHolds = (page ) =>
|
|
25
|
+
LISTS.every((list) => Array.isArray(page[list])) && (page['cursor'] === null || typeof page['cursor'] === 'string');
|
|
26
|
+
|
|
27
|
+
const itemsOf = (page , list ) => {
|
|
28
|
+
const items = page[list];
|
|
29
|
+
return Array.isArray(items) ? items : [];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const stateOf = async (line ) => {
|
|
33
|
+
const lists = { nodes: [], letters: [], durables: [] };
|
|
34
|
+
let head = null;
|
|
35
|
+
for (let cursor = null; ;) {
|
|
36
|
+
const page = await line(['ask', 'brain', 'state', ...(cursor === null ? [] : [dataText({ cursor })])]);
|
|
37
|
+
if ('why' in page) return page;
|
|
38
|
+
const { data } = page;
|
|
39
|
+
if (!isFields(data)) return { why: 'state answered no fields' };
|
|
40
|
+
if (!pageHolds(data)) return { why: `state answered a page without its ${LISTS.join(', ')} and cursor` };
|
|
41
|
+
head ??= data;
|
|
42
|
+
for (const list of LISTS) lists[list].push(...itemsOf(data, list));
|
|
43
|
+
const next = data['cursor'];
|
|
44
|
+
if (typeof next !== 'string') return { data: { ...head, ...lists, cursor: null } };
|
|
45
|
+
cursor = next;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const stateAt = (home ) => stateOf(lineAt(home));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Data } from '@nervur.org/genome/standard';
|
|
2
|
+
import { type Laid } from '../organism/folder.js';
|
|
3
|
+
import { type Line } from './asked.js';
|
|
4
|
+
import { type Given, type Outcome } from './given.js';
|
|
5
|
+
export { arrive } from './arrive.js';
|
|
6
|
+
type Why = {
|
|
7
|
+
readonly why: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const sequenceOf: (data: Data) => number;
|
|
10
|
+
export declare const fileFor: (words: readonly string[], sequence: number) => string;
|
|
11
|
+
export declare const openedWith: (laid: Laid, file: string, home: string) => string;
|
|
12
|
+
export declare const refusedAs: (why: string) => string;
|
|
13
|
+
export declare const carriedTo: (line: Line, made: Data, file: string) => Promise<null | Why>;
|
|
14
|
+
export declare const backup: (given: Given) => Promise<Outcome>;
|
|
15
|
+
export declare const backupKeyOf: (given: Given) => Promise<Uint8Array | Why>;
|
|
16
|
+
export declare const restore: (given: Given) => Promise<Outcome>;
|
|
17
|
+
export declare const move: (given: Given) => Promise<Outcome>;
|
|
18
|
+
export declare const stay: (given: Given) => Promise<Outcome>;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
+
import {
|
|
3
|
+
closeSync,
|
|
4
|
+
copyFileSync,
|
|
5
|
+
existsSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
openSync,
|
|
8
|
+
readFileSync,
|
|
9
|
+
rmSync,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
writeSync,
|
|
12
|
+
} from 'node:fs';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { ARRIVAL, BELOW_FLOOR, FLOOR } from '@nervur.org/genome';
|
|
15
|
+
import { arrivalIn, backupIn, storeFileIn } from './before.js';
|
|
16
|
+
import { dataText, hex, isFields, unhex, } from '@nervur.org/genome/standard';
|
|
17
|
+
import { storeOf } from '../door/door.js';
|
|
18
|
+
import { bootKeyFileOf, readBootKey } from '../fills/boot-key.js';
|
|
19
|
+
import { bootKeyOf } from '../fills/unlocker.js';
|
|
20
|
+
import { readFolder, stoppedOf, typedFor, } from '../organism/folder.js';
|
|
21
|
+
import { rehomedAt } from './jailer.js';
|
|
22
|
+
import { answered, lineAt, } from './asked.js';
|
|
23
|
+
import { custodyOf, hostHands, humanEnds } from '../fills/held.js';
|
|
24
|
+
import { bornKey } from './commands.js';
|
|
25
|
+
import { chosenOf } from './choices.js';
|
|
26
|
+
import { laidHalves } from './laid.js';
|
|
27
|
+
import { aloneOf, leftSaid } from './left.js';
|
|
28
|
+
import { organismOf, } from './given.js';
|
|
29
|
+
import { claimSaid, claimWordOf } from './claim.js';
|
|
30
|
+
import { bootKeyIn, doorHere, stoppedHere } from './held.js';
|
|
31
|
+
import { runningOf } from './spawn.js';
|
|
32
|
+
import { keptAtBoot, startedOn } from './start.js';
|
|
33
|
+
|
|
34
|
+
export { arrive } from './arrive.js';
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const BLOCK = { from: 12, to: 176 };
|
|
39
|
+
|
|
40
|
+
const PIECE = 1 << 20;
|
|
41
|
+
|
|
42
|
+
const REFUSED = new Map([
|
|
43
|
+
['absent', 'no backup stood beside the store'],
|
|
44
|
+
['held', 'another opener holds the backup'],
|
|
45
|
+
['wrong key', 'the backup opens with another key: the boot key it was made under, wrong key'],
|
|
46
|
+
['damaged', 'the backup is damaged'],
|
|
47
|
+
['unknown form', 'the backup stands in a form this version does not read'],
|
|
48
|
+
['present', 'an organism stands here already'],
|
|
49
|
+
[
|
|
50
|
+
BELOW_FLOOR,
|
|
51
|
+
`the backup was written by a genome below the floor ${FLOOR}: restore it with nervur@${FLOOR} first, then nervur update`,
|
|
52
|
+
],
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
export const sequenceOf = (data ) => {
|
|
56
|
+
const told = isFields(data) ? data['sequence'] : undefined;
|
|
57
|
+
return typeof told === 'number' ? told : 0;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const fileFor = (words , sequence ) =>
|
|
61
|
+
words[1] ?? `primordial-${sequence}.backup`;
|
|
62
|
+
|
|
63
|
+
export const openedWith = (laid , file , home ) =>
|
|
64
|
+
laid.bootMode !== 'file' && laid.bootMode !== 'present'
|
|
65
|
+
? `It opens with the boot key it was made under, which this device's ${laid.bootMode} holds: nervur restore ${file} on a device with no organism takes that key as hex, or back it up to a key of your own.`
|
|
66
|
+
: laid.bootMode === 'file'
|
|
67
|
+
? `It opens with the boot key it was made under, which stands on this device alone: keep a copy of ${bootKeyFileOf(home)} off it, and with that copy, nervur restore ${file} on a device with no organism.`
|
|
68
|
+
: `It opens with the passphrase it was made under and its salt: nervur restore ${file} ${hex(laid.salt)}, on a device with no organism.`;
|
|
69
|
+
|
|
70
|
+
export const refusedAs = (why ) => REFUSED.get(why) ?? why;
|
|
71
|
+
|
|
72
|
+
export const carriedTo = async (line , made , file ) => {
|
|
73
|
+
const { mark } = isFields(made) ? made : {};
|
|
74
|
+
if (typeof mark !== 'string') return { why: 'the backup answered no mark' };
|
|
75
|
+
const piece = (at ) => line(['ask', 'brain', 'backupPiece', dataText({ mark, at, length: PIECE })]);
|
|
76
|
+
const opened = openSync(file, 'wx', 0o600);
|
|
77
|
+
const left = await (async () => {
|
|
78
|
+
let at = 0;
|
|
79
|
+
for (let last = false; !last;) {
|
|
80
|
+
const taken = await piece(at);
|
|
81
|
+
if ('why' in taken) return taken;
|
|
82
|
+
const said = isFields(taken.data) ? taken.data : {};
|
|
83
|
+
const bytesOf = said['piece'];
|
|
84
|
+
last = typeof said['bytes'] === 'number';
|
|
85
|
+
if (!(bytesOf instanceof Uint8Array) || (bytesOf.length === 0 && !last))
|
|
86
|
+
return { why: 'a piece of the backup held no bytes' };
|
|
87
|
+
writeSync(opened, bytesOf);
|
|
88
|
+
at += bytesOf.length;
|
|
89
|
+
}
|
|
90
|
+
const end = await piece(at);
|
|
91
|
+
if ('why' in end) return end;
|
|
92
|
+
const last = isFields(end.data) ? end.data['piece'] : null;
|
|
93
|
+
if (last instanceof Uint8Array && last.length > 0) writeSync(opened, last);
|
|
94
|
+
return null;
|
|
95
|
+
})().finally(() => closeSync(opened));
|
|
96
|
+
if (left === null) return null;
|
|
97
|
+
rmSync(file, { force: true });
|
|
98
|
+
return left;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const backup = async (given ) => {
|
|
102
|
+
const home = organismOf(given.home);
|
|
103
|
+
const folder = readFolder(home);
|
|
104
|
+
if ('why' in folder) return folder;
|
|
105
|
+
if (runningOf(home) === null) return { why: 'the organism is not running, so it backs up nothing' };
|
|
106
|
+
const left = await aloneOf(lineAt(home));
|
|
107
|
+
if ('why' in left) return left;
|
|
108
|
+
const asked = await answered(home, ['ask', 'brain', 'backup', '{}']);
|
|
109
|
+
if ('why' in asked) return asked;
|
|
110
|
+
const sequence = sequenceOf(asked.data);
|
|
111
|
+
const file = fileFor(given.words, sequence);
|
|
112
|
+
if (existsSync(file)) return { why: `${file} stands already, and a backup is never written over a file` };
|
|
113
|
+
const carried = await carriedTo(lineAt(home), asked.data, file);
|
|
114
|
+
if (carried !== null) return carried;
|
|
115
|
+
given.print(`The organism is backed up, as of its commit ${sequence}, to ${file}, read by your account alone.`);
|
|
116
|
+
given.print(openedWith(folder.laid, file, home));
|
|
117
|
+
const said = leftSaid(left.alone);
|
|
118
|
+
if (said !== null) given.print(said);
|
|
119
|
+
return null;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const backupKeyOf = async (given ) => {
|
|
123
|
+
const salt = given.words[2];
|
|
124
|
+
if (salt !== undefined) {
|
|
125
|
+
const read = unhex(salt);
|
|
126
|
+
if ('why' in read) return { why: `the salt is hex, not ${salt}` };
|
|
127
|
+
const passphrase = await given.asker.ask('The passphrase the backup was made under: ');
|
|
128
|
+
return passphrase === null ? { why: 'no passphrase was given' } : bootKeyOf(passphrase, read.bytes);
|
|
129
|
+
}
|
|
130
|
+
const typed = await given.asker.ask('The boot key the backup was made under, as hex: ');
|
|
131
|
+
const read = typed === null ? null : unhex(typed.trim());
|
|
132
|
+
return read === null || 'why' in read || read.bytes.length !== 32
|
|
133
|
+
? { why: 'the boot key the backup was made under is 32 bytes as hex' }
|
|
134
|
+
: read.bytes;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const deviceOf = async (
|
|
138
|
+
given ,
|
|
139
|
+
home ,
|
|
140
|
+
) => {
|
|
141
|
+
const before = readFolder(home);
|
|
142
|
+
if ('laid' in before) {
|
|
143
|
+
const key = await bootKeyIn(given, home, before.laid);
|
|
144
|
+
return 'why' in key ? key : { laid: before.laid, key: key.key };
|
|
145
|
+
}
|
|
146
|
+
const born = await bornKey(chosenOf(given), home);
|
|
147
|
+
if ('why' in born) return born;
|
|
148
|
+
const read = readFolder(home);
|
|
149
|
+
if ('why' in read) return read;
|
|
150
|
+
if (born.key === null && read.laid.bootMode !== 'file') {
|
|
151
|
+
const opened = await custodyOf(home, read.laid, given.hands ?? hostHands()).open();
|
|
152
|
+
if (opened === null) return { why: 'no boot key was given' };
|
|
153
|
+
return 'why' in opened ? opened : { laid: read.laid, key: opened.key };
|
|
154
|
+
}
|
|
155
|
+
const key = born.key === null ? readBootKey(home) : { key: born.key };
|
|
156
|
+
return 'why' in key ? key : { laid: read.laid, key: key.key };
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const restore = async (given ) => {
|
|
160
|
+
const home = organismOf(given.home);
|
|
161
|
+
const file = given.words[1] ?? '';
|
|
162
|
+
const standing = existsSync(storeFileIn(home))
|
|
163
|
+
? { why: `an organism stands at ${home} already: a backup is restored only where none does` }
|
|
164
|
+
: null;
|
|
165
|
+
const refused = claimWordOf(given) ?? standing;
|
|
166
|
+
if (refused !== null) return refused;
|
|
167
|
+
if (!existsSync(file)) return { why: `no backup stands at ${file}` };
|
|
168
|
+
const moving = isMove(file);
|
|
169
|
+
if (moving && !existsSync(arrivalIn(home))) return { why: `${file} is a move sealed to another device` };
|
|
170
|
+
const old = moving ? null : await backupKeyOf(given);
|
|
171
|
+
if (old !== null && 'why' in old) return old;
|
|
172
|
+
const laidHere = !existsSync(home);
|
|
173
|
+
const restored = await restoredAt(given, home, file, old);
|
|
174
|
+
rmSync(backupIn(home), { force: true });
|
|
175
|
+
if ('why' in restored) {
|
|
176
|
+
if (laidHere) rmSync(home, { recursive: true, force: true });
|
|
177
|
+
return restored;
|
|
178
|
+
}
|
|
179
|
+
if (moving) rmSync(arrivalIn(home), { force: true });
|
|
180
|
+
await rehomedAt(given, home, restored.laid);
|
|
181
|
+
given.print(
|
|
182
|
+
moving
|
|
183
|
+
? `The organism moved to ${home}: the same life, every relation whole, and the secret that opened it is forgotten.`
|
|
184
|
+
: `The backup is restored at ${home}, a new life: its faculties, lobes, cells, wiring and standings stand, and every relation it gave is dropped, to give again or end.`,
|
|
185
|
+
);
|
|
186
|
+
if (restored.laid.claim !== undefined) given.print(claimSaid(restored.laid));
|
|
187
|
+
return null;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const isMove = (path ) =>
|
|
191
|
+
readFileSync(path)
|
|
192
|
+
.subarray(BLOCK.from, BLOCK.to)
|
|
193
|
+
.every((byte) => byte === 0);
|
|
194
|
+
|
|
195
|
+
export const move = async (given ) => {
|
|
196
|
+
const home = organismOf(given.home);
|
|
197
|
+
if (runningOf(home) === null) return { why: 'the organism is not running, so it moves nowhere' };
|
|
198
|
+
const file = given.words[2] ?? `moved-${Date.now()}.backup`;
|
|
199
|
+
if (existsSync(file)) return { why: `${file} stands already, and a backup is never written over a file` };
|
|
200
|
+
const repos = await aloneOf(lineAt(home));
|
|
201
|
+
if ('why' in repos) return repos;
|
|
202
|
+
const said = leftSaid(repos.alone);
|
|
203
|
+
if (said !== null) given.print(said);
|
|
204
|
+
const named = { to: given.words[1] ?? '' };
|
|
205
|
+
const asked = await answered(home, ['ask', 'brain', 'move', dataText(named)]);
|
|
206
|
+
if ('why' in asked) return asked;
|
|
207
|
+
const carried = await carriedTo(lineAt(home), asked.data, file);
|
|
208
|
+
if (carried !== null) return carried;
|
|
209
|
+
given.print(`The organism moved to ${file}, read by your account alone, and this copy stopped for good.`);
|
|
210
|
+
given.print('Carry the file to the new device: nervur restore <file>.');
|
|
211
|
+
const left = isFields(asked.data) && Array.isArray(asked.data['left']) ? asked.data['left'] : [];
|
|
212
|
+
given.print(`What the body held stays here, with the halves of: ${left.join(', ')}.`);
|
|
213
|
+
given.print(`Until the new copy runs, ${typedFor(home)('stay')} undoes this. The old copy cannot tell if it did.`);
|
|
214
|
+
return null;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export const stay = async (given ) => {
|
|
218
|
+
const home = organismOf(given.home);
|
|
219
|
+
const folder = readFolder(home);
|
|
220
|
+
if ('why' in folder) return folder;
|
|
221
|
+
const key = await bootKeyIn(given, home, folder.laid);
|
|
222
|
+
if ('why' in key) return key;
|
|
223
|
+
const ended = await stoppedHere(home);
|
|
224
|
+
if (ended !== null) return ended;
|
|
225
|
+
rmSync(stoppedOf(home), { force: true });
|
|
226
|
+
const opened = await doorHere(given, home, folder.laid, { kind: 'boot', stay: true }, key.key);
|
|
227
|
+
if ('why' in opened) return { why: `the organism does not stay: ${opened.why}` };
|
|
228
|
+
await opened.door.stop();
|
|
229
|
+
rmSync(backupIn(home), { force: true });
|
|
230
|
+
const started = await startedOn(home, humanEnds(folder.laid) ? key.key : null);
|
|
231
|
+
if (started !== null) return started;
|
|
232
|
+
given.print(`The organism stays at ${home}. The file it sealed still opens once on the new device: destroy it.`);
|
|
233
|
+
return null;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const restoredAt = async (
|
|
237
|
+
given ,
|
|
238
|
+
home ,
|
|
239
|
+
file ,
|
|
240
|
+
old ,
|
|
241
|
+
) => {
|
|
242
|
+
const device = await deviceOf(given, home);
|
|
243
|
+
if ('why' in device) return device;
|
|
244
|
+
const halves = laidHalves(home, device.laid.work);
|
|
245
|
+
if (halves !== null) return halves;
|
|
246
|
+
mkdirSync(storeOf(home), { recursive: true, mode: 0o700 });
|
|
247
|
+
writeFileSync(backupIn(home), readFileSync(file), { mode: 0o600 });
|
|
248
|
+
if (old === null) copyFileSync(arrivalIn(home), join(storeOf(home), ARRIVAL));
|
|
249
|
+
const init = old === null ? ({ kind: 'move' } ) : ({ kind: 'backup', temporaryKey: old } );
|
|
250
|
+
const opened = await doorHere(given, home, device.laid, init, device.key);
|
|
251
|
+
if ('why' in opened) return { why: `the backup is not restored: ${refusedAs(opened.why)}` };
|
|
252
|
+
await opened.door.stop();
|
|
253
|
+
const handed = humanEnds(device.laid) ? device.key : null;
|
|
254
|
+
const started = await startedOn(home, handed);
|
|
255
|
+
if (started !== null) return started;
|
|
256
|
+
if (given.served) {
|
|
257
|
+
const kept = await keptAtBoot(given, home, handed);
|
|
258
|
+
if (kept !== null) return kept;
|
|
259
|
+
}
|
|
260
|
+
return { laid: device.laid };
|
|
261
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Processes, type Standing } from './release.js';
|
|
2
|
+
type Why = {
|
|
3
|
+
readonly why: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const beforeOf: (home: string) => string;
|
|
6
|
+
export declare const keptStoreOf: (home: string) => string;
|
|
7
|
+
export declare const logOf: (home: string) => string;
|
|
8
|
+
export declare const arrivalIn: (home: string) => string;
|
|
9
|
+
export declare const backupIn: (home: string) => string;
|
|
10
|
+
export declare const storeFileIn: (home: string) => string;
|
|
11
|
+
export declare const stayOf: (home: string) => string;
|
|
12
|
+
export declare const floorOf: (home: string) => string;
|
|
13
|
+
export declare const bootOf: (home: string, trial: boolean) => {
|
|
14
|
+
readonly kind: 'boot';
|
|
15
|
+
readonly trial?: true;
|
|
16
|
+
readonly stay?: true;
|
|
17
|
+
readonly skins?: true;
|
|
18
|
+
};
|
|
19
|
+
export declare const lockAt: (home: string) => string;
|
|
20
|
+
export declare const lockPid: (file: string) => number | null;
|
|
21
|
+
export declare const actLives: (home: string) => boolean;
|
|
22
|
+
export declare const roomFor: (home: string, bytes: number) => null | Why;
|
|
23
|
+
export declare const wayBackBytes: (command: Standing | null) => number;
|
|
24
|
+
export declare const keptAside: (home: string, command: Standing | null) => null | Why;
|
|
25
|
+
export declare const keptOld: (home: string, standing?: () => Promise<Standing | Why>) => Promise<null | Why>;
|
|
26
|
+
export declare const sealing: (home: string) => void;
|
|
27
|
+
export declare const storeAside: (home: string) => void;
|
|
28
|
+
export declare const logAside: (home: string) => null | Why;
|
|
29
|
+
export declare const storeCopied: (home: string) => null | Why;
|
|
30
|
+
export declare const startedBy: (bin: string, words: readonly string[]) => Promise<null | Why>;
|
|
31
|
+
export declare const committed: (home: string, processes?: Processes) => void;
|
|
32
|
+
export declare const wentBack: (home: string) => {
|
|
33
|
+
readonly store: boolean;
|
|
34
|
+
readonly package: boolean;
|
|
35
|
+
readonly why?: string;
|
|
36
|
+
};
|
|
37
|
+
export declare const storeBack: (home: string) => void;
|
|
38
|
+
export declare const halvesBack: (home: string) => void;
|
|
39
|
+
export declare const freed: (file: string, home: string, laid: string | undefined) => void;
|
|
40
|
+
export {};
|