@runeditrun/rer 0.2.121 → 0.2.122
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/cli/README.md +124 -5
- package/cli/archive.mjs +1 -1
- package/cli/authoring.mjs +1 -1
- package/cli/browser-runtime.mjs +2 -2
- package/cli/business/agent-help.mjs +11 -11
- package/cli/business/agent-verbs.mjs +9 -8
- package/cli/business/api.mjs +11 -7
- package/cli/business/carry.mjs +4 -3
- package/cli/business/choices.mjs +1 -1
- package/cli/business/command.mjs +33 -11
- package/cli/business/connect.mjs +4 -4
- package/cli/business/credential-file.mjs +102 -0
- package/cli/business/errors.mjs +5 -2
- package/cli/business/invocation.mjs +7 -4
- package/cli/business/keychain.mjs +6 -2
- package/cli/business/local-commands.mjs +9 -3
- package/cli/business/mcp-bridge.mjs +2 -1
- package/cli/business/questions.mjs +1 -1
- package/cli/business/run-child.mjs +5 -5
- package/cli/business/run-grant.mjs +27 -8
- package/cli/business/run-mask.mjs +8 -1
- package/cli/business/scan-command.mjs +1 -1
- package/cli/business/service.mjs +4 -2
- package/cli/business/state.mjs +2 -2
- package/cli/checkout-folders.mjs +1 -1
- package/cli/checkout-preparation.mjs +4 -4
- package/cli/command-guidance.mjs +9 -0
- package/cli/companion/command.mjs +4 -3
- package/cli/companion/providers/sandbox.mjs +1 -1
- package/cli/companion/setup.mjs +4 -4
- package/cli/contract.mjs +8 -8
- package/cli/demo.mjs +1 -1
- package/cli/deploy-command.mjs +10 -5
- package/cli/deploy-hook.mjs +3 -2
- package/cli/deploy-inputs.mjs +7 -3
- package/cli/deploy-owner-input.mjs +2 -2
- package/cli/deploy-source.mjs +1 -1
- package/cli/deploy.mjs +4 -2
- package/cli/deployment-record.mjs +1 -1
- package/cli/dev-identity.mjs +4 -4
- package/cli/door-clauses.mjs +2 -2
- package/cli/door-mode.mjs +7 -7
- package/cli/door.mjs +7 -7
- package/cli/errors.mjs +15 -1
- package/cli/export-summary.mjs +1 -1
- package/cli/export.mjs +1 -1
- package/cli/hosted-export.mjs +1 -1
- package/cli/hosted-output.mjs +2 -2
- package/cli/human-error.mjs +8 -2
- package/cli/hydration/browser.mjs +1 -1
- package/cli/hydration/check.mjs +1 -1
- package/cli/import-summary.mjs +2 -2
- package/cli/inspect.mjs +3 -3
- package/cli/lifecycle.mjs +9 -9
- package/cli/listen.mjs +1 -1
- package/cli/listing.mjs +1 -1
- package/cli/local-env.mjs +1 -1
- package/cli/local.mjs +4 -4
- package/cli/managed-server.mjs +36 -13
- package/cli/output.mjs +2 -1
- package/cli/owner-entry-ready.mjs +92 -0
- package/cli/parse.mjs +8 -8
- package/cli/port.mjs +3 -3
- package/cli/portability-runtime.mjs +16 -0
- package/cli/portability.mjs +4 -4
- package/cli/production-auth.mjs +4 -2
- package/cli/production-mail.mjs +1 -1
- package/cli/project.mjs +2 -0
- package/cli/rehearse/options.mjs +3 -3
- package/cli/release-candidate.mjs +2 -2
- package/cli/release.mjs +5 -5
- package/cli/server-registry.mjs +3 -3
- package/cli/server-resources.mjs +1 -1
- package/cli/setup-input.mjs +6 -6
- package/cli/signin.mjs +11 -10
- package/cli/site-render.mjs +1 -1
- package/cli/size/schema.mjs +1 -1
- package/cli/size/verify-step.mjs +1 -1
- package/cli/transfers.mjs +4 -4
- package/edition-authoring/api-source.mjs +121 -0
- package/edition-authoring/archive-source.mjs +1 -86
- package/edition-authoring/base-copies.mjs +5 -3
- package/global/CHANGELOG.md +31 -0
- package/global/cli/command.mjs +6 -5
- package/global/cli/install.mjs +6 -3
- package/global/cli/path-link.mjs +11 -22
- package/global/cli/repo-command.mjs +4 -3
- package/global/cli/repository-contract.mjs +3 -3
- package/global/door/command.mjs +39 -38
- package/global/door/control.mjs +3 -3
- package/global/door/pages.mjs +6 -5
- package/global/door/server.mjs +8 -5
- package/global/door/sites.mjs +14 -13
- package/global/launch/capacity.mjs +2 -2
- package/global/launch/dev.mjs +6 -6
- package/global/launch/door.mjs +1 -1
- package/global/launch/facts.mjs +2 -2
- package/global/launch/failure.mjs +1 -1
- package/global/launch/prepare.mjs +3 -3
- package/global/launch/render.mjs +3 -2
- package/global/launch/worker.mjs +1 -1
- package/global/list.mjs +4 -4
- package/global/main.mjs +32 -31
- package/global/registry.mjs +1 -1
- package/global/run.mjs +4 -4
- package/global/update/command.mjs +5 -5
- package/global/update/notice.mjs +1 -1
- package/global/version.mjs +1 -1
- package/install.sh +17 -4
- package/modules/deploy-kit/README.md +10 -3
- package/modules/deploy-kit/asset-health.mjs +6 -4
- package/modules/deploy-kit/cancellation.mjs +26 -0
- package/modules/deploy-kit/d1-import-diagnostics.mjs +3 -2
- package/modules/deploy-kit/deploy.mjs +8 -3
- package/modules/deploy-kit/diagnostics.mjs +11 -4
- package/modules/deploy-kit/health-request.mjs +16 -9
- package/modules/deploy-kit/health.mjs +14 -11
- package/modules/deploy-kit/owner-cli.mjs +49 -21
- package/modules/deploy-kit/owner-remove.mjs +7 -6
- package/modules/deploy-kit/owner-secret.mjs +7 -4
- package/modules/deploy-kit/owner.mjs +46 -28
- package/modules/deploy-kit/provider-transport.mjs +2 -0
- package/modules/deploy-kit/provider.mjs +10 -9
- package/modules/deploy-kit/readiness-window.mjs +5 -3
- package/modules/deploy-kit/site.mjs +1 -1
- package/modules/deploy-kit/teardown.mjs +5 -4
- package/modules/operator-auth/dev/index.mjs +4 -3
- package/modules/operator-auth/dev/sign-in-as.mjs +2 -1
- package/modules/operator-auth/dev-gate.mjs +3 -2
- package/modules/operator-auth/routes.mjs +2 -1
- package/modules/operator-auth/terminal-guidance.mjs +3 -0
- package/onboarding/adapter-settings.mjs +1 -0
- package/onboarding/adapter.mjs +3 -3
- package/onboarding/agent-handoff.mjs +1 -1
- package/onboarding/busy.mjs +1 -1
- package/onboarding/launcher.mjs +1 -1
- package/onboarding/local/environment.mjs +1 -1
- package/onboarding/local/operation.mjs +12 -4
- package/onboarding/local/owner.mjs +2 -2
- package/onboarding/operator-installer.mjs +4 -3
- package/onboarding/operator-migrations.mjs +1 -1
- package/onboarding/operator-prerequisites.mjs +26 -14
- package/onboarding/operator-settings.mjs +28 -0
- package/onboarding/process-diagnostics.mjs +2 -2
- package/onboarding/project-vite.mjs +1 -1
- package/package.json +1 -1
package/global/cli/path-link.mjs
CHANGED
|
@@ -9,28 +9,15 @@ export async function ownedPathLink(path, launcher) {
|
|
|
9
9
|
catch (error) { if (error.code === 'ENOENT' || error.code === 'EINVAL') return false; throw error; }
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// ~/.local/bin on PATH in this terminal and, through the startup file, in new
|
|
16
|
-
// ones. rer never runs it: the person does.
|
|
17
|
-
export async function shellStartup(home, env = process.env, platform = process.platform) {
|
|
12
|
+
// Only the person executing the printed command edits their shell file.
|
|
13
|
+
// Match the complete PATH line before appending so repeated execution is safe.
|
|
14
|
+
export async function shellStartup(home, env = process.env) {
|
|
18
15
|
const shell = basename(env.SHELL ?? ''), add = 'export PATH="$HOME/.local/bin:$PATH"';
|
|
19
|
-
if (shell === 'fish') return { files: ['.config/fish/config.fish', '.config/fish/fish_variables'].map(file => join(home, file)), line: 'fish_add_path ~/.local/bin' };
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const files = shell === 'bash' ? ['.bash_profile', '.bash_login', '.profile', '.bashrc'] : ['.profile'];
|
|
25
|
-
// macOS terminals start bash as a login shell, which reads only the first of
|
|
26
|
-
// its profiles that exists; elsewhere a terminal's bash reads ~/.bashrc.
|
|
27
|
-
let file = '.profile';
|
|
28
|
-
if (shell === 'bash' && platform !== 'darwin') file = '.bashrc';
|
|
29
|
-
else if (shell === 'bash') {
|
|
30
|
-
file = '.bash_profile';
|
|
31
|
-
for (const candidate of files.slice(0, 3)) if (await exists(join(home, candidate))) { file = candidate; break; }
|
|
32
|
-
}
|
|
33
|
-
return { files: files.map(name => join(home, name)), line: `echo '${add}' >> ~/${file} && ${add}` };
|
|
16
|
+
if (shell === 'fish') return { files: ['.config/fish/config.fish', '.config/fish/fish_variables'].map(file => join(home, file)), target: '~/.config/fish', line: 'fish_add_path ~/.local/bin' };
|
|
17
|
+
if (!['zsh', 'bash'].includes(shell)) return { files: [], line: add };
|
|
18
|
+
const file = shell === 'zsh' ? '.zshrc' : '.bashrc';
|
|
19
|
+
const target = `~/${file}`;
|
|
20
|
+
return { files: [join(home, file)], target, line: `(grep -Fqx '${add}' ${target} 2>/dev/null || printf '\\n%s\\n' '${add}' >> ${target}) && ${add}` };
|
|
34
21
|
}
|
|
35
22
|
|
|
36
23
|
// Whether a startup file already puts ~/.local/bin on PATH for new terminals.
|
|
@@ -63,6 +50,8 @@ export async function pathAdvice(paths, env = process.env, { includeShellStep =
|
|
|
63
50
|
const first = entries.includes(bin) && firstCommand === paths.launcher;
|
|
64
51
|
if (first && await persistent(startup.files)) return lines.join('\n');
|
|
65
52
|
const why = first ? 'New terminals will not find rer yet.' : firstCommand ? `Another rer (${firstCommand}) comes first on your PATH.` : 'rer is not on your PATH yet.';
|
|
66
|
-
|
|
53
|
+
const effect = basename(env.SHELL ?? '') === 'fish' ? 'fish saves ~/.local/bin in its user path configuration' : startup.target ? `you add ~/.local/bin to PATH in ${startup.target} and this terminal` : 'you add ~/.local/bin to PATH for this terminal only';
|
|
54
|
+
lines.push(`Next step: ${why} Run this line; ${effect}. The installer changes no shell file:`, ` ${startup.line}`);
|
|
55
|
+
if (['zsh', 'bash'].includes(basename(env.SHELL ?? ''))) lines.push('Open a new Terminal window, then `rer` works by name.');
|
|
67
56
|
return lines.join('\n');
|
|
68
57
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withCommandHelp } from '../../cli/command-guidance.mjs';
|
|
1
2
|
import { realpath } from 'node:fs/promises';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import { parse } from '../../cli/parse.mjs';
|
|
@@ -18,7 +19,7 @@ export async function repoCommand(request) {
|
|
|
18
19
|
if (installed !== 0) return installed;
|
|
19
20
|
await checkoutRepository(request);
|
|
20
21
|
const root = await realpath(request.root);
|
|
21
|
-
const next = command => `cd ${shellQuote(directory)} && rer ${command}`;
|
|
22
|
+
const next = command => `cd ${shellQuote(directory)} && ~/.local/bin/rer ${command}`;
|
|
22
23
|
if (verb === 'setup') {
|
|
23
24
|
await (await import('../../cli/business/carry.mjs')).refreshCheckout(root);
|
|
24
25
|
const state = await launchDirectory(root), children = new Set(), controller = new AbortController();
|
|
@@ -34,7 +35,7 @@ export async function repoCommand(request) {
|
|
|
34
35
|
await log.close();
|
|
35
36
|
}
|
|
36
37
|
} else {
|
|
37
|
-
if (verb === 'dev' && !args.includes('--json')) process.stdout.write(`Restart: ${next('dev')}\n
|
|
38
|
+
if (verb === 'dev' && !args.includes('--json')) process.stdout.write(withCommandHelp(`Restart: ${next('dev')}`) + '\n');
|
|
38
39
|
const entry = join(ownRoot, 'global/rer.mjs');
|
|
39
40
|
const code = await runCommand(process.execPath, [entry, verb, ...args], { cwd: root,
|
|
40
41
|
...(verb === 'dev' ? { onInterrupt: () => runCommand(process.execPath, [entry, 'dev', '--stop'], { cwd: root }) } : {}),
|
|
@@ -43,7 +44,7 @@ export async function repoCommand(request) {
|
|
|
43
44
|
}
|
|
44
45
|
if (verb !== 'dev') {
|
|
45
46
|
const command = next(verb === 'install' ? 'setup' : 'dev');
|
|
46
|
-
process.stdout.write(args.includes('--json') ? JSON.stringify({ version: 1, verb, event: 'next', command }) + '\n' : `Next: ${command}\n
|
|
47
|
+
process.stdout.write(args.includes('--json') ? JSON.stringify({ version: 1, verb, event: 'next', command }) + '\n' : withCommandHelp(`Next: ${command}`) + '\n');
|
|
47
48
|
}
|
|
48
49
|
return 0;
|
|
49
50
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Repository acquisition belongs to the global CLI, before checkout dispatch.
|
|
2
2
|
export const repositoryCommands = Object.freeze({
|
|
3
|
-
install: { usage: 'rer install <repo> [--dir DIR] [FLAGS]', effects: 'Install rer for this user, clone or reuse the repository, install its dependencies, then stop.' },
|
|
4
|
-
setup: { usage: 'rer setup <repo> [--dir DIR] [FLAGS]', effects: 'Install rer, clone or reuse the repository, install dependencies and set up a local owner, then print the dev command.' },
|
|
5
|
-
dev: { usage: 'rer dev <repo> [--dir DIR] [FLAGS]', effects: 'Install rer, clone or reuse the repository, install and set up as needed, then start dev and print RER_READY and RER_OPEN.' },
|
|
3
|
+
install: { usage: '~/.local/bin/rer install <repo> [--dir DIR] [FLAGS]', effects: 'Install rer for this user, clone or reuse the repository, install its dependencies, then stop.' },
|
|
4
|
+
setup: { usage: '~/.local/bin/rer setup <repo> [--dir DIR] [FLAGS]', effects: 'Install rer, clone or reuse the repository, install dependencies and set up a local owner, then print the dev command.' },
|
|
5
|
+
dev: { usage: '~/.local/bin/rer dev <repo> [--dir DIR] [FLAGS]', effects: 'Install rer, clone or reuse the repository, install and set up as needed, then start dev and print RER_READY and RER_OPEN.' },
|
|
6
6
|
});
|
|
7
7
|
export const repositoryHelp = 'Repository: <owner>/<repo>, a GitHub HTTPS URL (with or without .git), or a git URL.\nClones into ./<repo-name>; --dir overrides. Reuses a clone with the same origin; refuses any other non-empty folder.\n';
|
package/global/door/command.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withCommandHelp } from '../../cli/command-guidance.mjs';
|
|
1
2
|
// rer door: the opt-in front door. One process on one port serves every
|
|
2
3
|
// registered checkout at http://NAME.localhost:PORT, starting it on its first
|
|
3
4
|
// visit and stopping it when idle.
|
|
@@ -13,40 +14,40 @@ import { rebootNote } from './pages.mjs';
|
|
|
13
14
|
import { enabledPolicy } from './policy.mjs';
|
|
14
15
|
import { doorSites } from './sites.mjs';
|
|
15
16
|
|
|
16
|
-
export const doorHelp = `Usage: rer door VERB
|
|
17
|
+
export const doorHelp = `Usage: ~/.local/bin/rer door VERB
|
|
17
18
|
|
|
18
19
|
The front door serves every registered checkout at http://NAME.localhost:PORT
|
|
19
20
|
from one process on one port. A checkout starts on its first visit in a browser
|
|
20
21
|
and stops when idle. It is opt-in for this computer.
|
|
21
22
|
|
|
22
|
-
rer door clauses (--write | --check) [--cwd DIR]
|
|
23
|
+
~/.local/bin/rer door clauses (--write | --check) [--cwd DIR]
|
|
23
24
|
Sync Base agent requirements into a seed contract, preserving judgments.
|
|
24
|
-
rer door enable [--port N] [--server-limit N] [--idle-timeout S]
|
|
25
|
+
~/.local/bin/rer door enable [--port N] [--server-limit N] [--idle-timeout S]
|
|
25
26
|
Opt this computer in, record the policy and start the door.
|
|
26
27
|
Defaults: port 8700, 10 servers, 43200 s (12 hours) idle.
|
|
27
28
|
The policy and the RER_* variables in effect now are stored;
|
|
28
29
|
sites the door starts get those, never another shell's.
|
|
29
|
-
rer door disable Stop the door and opt this computer out.
|
|
30
|
-
rer door start Start the enabled door (needed after a reboot or logout).
|
|
31
|
-
rer door stop Stop the door. Running sites keep running until idle.
|
|
32
|
-
rer door restart Drain and restart the door; open tabs reconnect.
|
|
33
|
-
rer door add [PATH ...]
|
|
30
|
+
~/.local/bin/rer door disable Stop the door and opt this computer out.
|
|
31
|
+
~/.local/bin/rer door start Start the enabled door (needed after a reboot or logout).
|
|
32
|
+
~/.local/bin/rer door stop Stop the door. Running sites keep running until idle.
|
|
33
|
+
~/.local/bin/rer door restart Drain and restart the door; open tabs reconnect.
|
|
34
|
+
~/.local/bin/rer door add [PATH ...]
|
|
34
35
|
Register checkouts (default: here) for lazy start, printing
|
|
35
36
|
each URL and, for a set-up door-mode checkout with dev
|
|
36
37
|
identity, a sign-in link that starts it and signs in.
|
|
37
|
-
rer door remove NAME Unregister one checkout. Its name stays reserved for it;
|
|
38
|
-
rer dev there, or rer door add, registers it again.
|
|
39
|
-
rer door status [--json] [--links]
|
|
38
|
+
~/.local/bin/rer door remove NAME Unregister one checkout. Its name stays reserved for it;
|
|
39
|
+
~/.local/bin/rer dev there, or ~/.local/bin/rer door add, registers it again.
|
|
40
|
+
~/.local/bin/rer door status [--json] [--links]
|
|
40
41
|
The door, its policy and every site with its state and URL;
|
|
41
42
|
--links adds sign-in links.
|
|
42
43
|
|
|
43
|
-
Fresh checkouts launched with rer dev while the door is enabled are set up at
|
|
44
|
-
their door URL. Move an existing one with rer dev --door (rer dev --direct moves
|
|
45
|
-
it back); rer dev --port N always serves directly.
|
|
44
|
+
Fresh checkouts launched with ~/.local/bin/rer dev while the door is enabled are set up at
|
|
45
|
+
their door URL. Move an existing one with ~/.local/bin/rer dev --door (~/.local/bin/rer dev --direct moves
|
|
46
|
+
it back); ~/.local/bin/rer dev --port N always serves directly.
|
|
46
47
|
`;
|
|
47
48
|
|
|
48
|
-
const out = text => process.stdout.write(text + '\n');
|
|
49
|
-
const err = text => process.stderr.write(text + '\n');
|
|
49
|
+
const out = text => process.stdout.write(withCommandHelp(text) + '\n');
|
|
50
|
+
const err = text => process.stderr.write(withCommandHelp(text) + '\n');
|
|
50
51
|
|
|
51
52
|
function flags(args, valued, booleans = []) {
|
|
52
53
|
const result = { positional: [] };
|
|
@@ -54,7 +55,7 @@ function flags(args, valued, booleans = []) {
|
|
|
54
55
|
const arg = args[i];
|
|
55
56
|
if (valued.includes(arg)) { const value = args[++i]; if (value === undefined || value.startsWith('--')) throw new DoorFailure(2, `${arg} needs a value.`); result[arg] = value; }
|
|
56
57
|
else if (booleans.includes(arg)) result[arg] = true;
|
|
57
|
-
else if (arg.startsWith('-')) throw new DoorFailure(2, `Unsupported flag ${arg}. Run rer door --help.`);
|
|
58
|
+
else if (arg.startsWith('-')) throw new DoorFailure(2, `Unsupported flag ${arg}. Run ~/.local/bin/rer door --help.`);
|
|
58
59
|
else result.positional.push(arg);
|
|
59
60
|
}
|
|
60
61
|
return result;
|
|
@@ -62,7 +63,7 @@ function flags(args, valued, booleans = []) {
|
|
|
62
63
|
|
|
63
64
|
async function enabledState(env) {
|
|
64
65
|
const state = await readDoorState(env);
|
|
65
|
-
if (!state?.door?.enabled) throw new DoorFailure(3, 'The front door is not enabled on this computer. Enable it with: rer door enable');
|
|
66
|
+
if (!state?.door?.enabled) throw new DoorFailure(3, 'The front door is not enabled on this computer. Enable it with: ~/.local/bin/rer door enable');
|
|
66
67
|
return state;
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -88,7 +89,7 @@ async function replaceDoor(env, change) {
|
|
|
88
89
|
|
|
89
90
|
async function enable(args, env) {
|
|
90
91
|
const given = flags(args, ['--port', '--server-limit', '--idle-timeout']);
|
|
91
|
-
if (given.positional.length) throw new DoorFailure(2, 'rer door enable takes only flags. Run rer door --help.');
|
|
92
|
+
if (given.positional.length) throw new DoorFailure(2, '~/.local/bin/rer door enable takes only flags. Run ~/.local/bin/rer door --help.');
|
|
92
93
|
const chosen = enabledPolicy({ port: given['--port'], serverLimit: given['--server-limit'], idleTimeout: given['--idle-timeout'] }, env);
|
|
93
94
|
const previous = (await readDoorState(env))?.door;
|
|
94
95
|
const port = chosen.port ?? previous?.port ?? defaultDoorPort;
|
|
@@ -98,16 +99,16 @@ async function enable(args, env) {
|
|
|
98
99
|
state.door = { protocol: doorProtocol, enabled: true, port, policy: chosen.policy, directory: chosen.directory, serversDir: chosen.serversDir, environment: chosen.environment, started: state.door?.started ?? [], ...(state.door?.handoff ? { handoff: state.door.handoff } : {}), ...(state.door?.restarting ? { restarting: state.door.restarting } : {}), enabledAt: new Date().toISOString() };
|
|
99
100
|
});
|
|
100
101
|
out(runningLine({ policy: chosen.policy }, record));
|
|
101
|
-
if (previous?.port && previous.port !== port) out(`Checkouts already moved to the door keep their saved port ${previous.port}; move each again with rer dev --direct, then rer dev --door.`);
|
|
102
|
-
out(`Register checkouts with rer door add PATH. ${rebootNote.replace(/<\/?code>/g, '')}`);
|
|
102
|
+
if (previous?.port && previous.port !== port) out(`Checkouts already moved to the door keep their saved port ${previous.port}; move each again with ~/.local/bin/rer dev --direct, then ~/.local/bin/rer dev --door.`);
|
|
103
|
+
out(`Register checkouts with ~/.local/bin/rer door add PATH. ${rebootNote.replace(/<\/?code>/g, '')}`);
|
|
103
104
|
return 0;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
async function disable(args, env) {
|
|
107
|
-
if (args.length) throw new DoorFailure(2, 'rer door disable takes no arguments.');
|
|
108
|
+
if (args.length) throw new DoorFailure(2, '~/.local/bin/rer door disable takes no arguments.');
|
|
108
109
|
const stopped = await stopDoor(env);
|
|
109
110
|
if (await readDoorState(env)) await changeDoorState(env, state => { if (state.door) state.door.enabled = false; });
|
|
110
|
-
out(`${stopped ? `Stopped the front door (PID ${stopped.pid}). ` : ''}The front door is disabled on this computer. Registered checkouts stay registered; rer door enable turns it back on.`);
|
|
111
|
+
out(`${stopped ? `Stopped the front door (PID ${stopped.pid}). ` : ''}The front door is disabled on this computer. Registered checkouts stay registered; ~/.local/bin/rer door enable turns it back on.`);
|
|
111
112
|
return 0;
|
|
112
113
|
}
|
|
113
114
|
|
|
@@ -120,7 +121,7 @@ async function start(env) {
|
|
|
120
121
|
|
|
121
122
|
async function stop(env) {
|
|
122
123
|
const stopped = await stopDoor(env);
|
|
123
|
-
out(stopped ? `Stopped the front door (PID ${stopped.pid}). Sites it started keep running until idle; rer door start brings it back.` : 'The front door is not running.');
|
|
124
|
+
out(stopped ? `Stopped the front door (PID ${stopped.pid}). Sites it started keep running until idle; ~/.local/bin/rer door start brings it back.` : 'The front door is not running.');
|
|
124
125
|
return 0;
|
|
125
126
|
}
|
|
126
127
|
|
|
@@ -167,7 +168,7 @@ async function add(args, env) {
|
|
|
167
168
|
skipped++; continue;
|
|
168
169
|
}
|
|
169
170
|
let described;
|
|
170
|
-
try { described = await describeCheckout(root, dispatcher(root).entry, env); } catch (failure) { out(`skipped ${path}: rer describe fails here: ${failure.message.split('\n')[0]}`); skipped++; continue; }
|
|
171
|
+
try { described = await describeCheckout(root, dispatcher(root).entry, env); } catch (failure) { out(`skipped ${path}: ~/.local/bin/rer describe fails here: ${failure.message.split('\n')[0]}`); skipped++; continue; }
|
|
171
172
|
const saved = described.local && 'origin' in described.local ? described.local.origin : await oldPinOrigin(root, described), site = saved && doorSite(saved), mode = site && site.port === port ? 'door' : 'direct';
|
|
172
173
|
// A door-mode checkout's saved origin names its site, so it registers under
|
|
173
174
|
// that name or not at all; another checkout keeps a name it holds.
|
|
@@ -185,7 +186,7 @@ async function add(args, env) {
|
|
|
185
186
|
await saveCheckoutIdentity(root, id);
|
|
186
187
|
} catch (error) {
|
|
187
188
|
if (!(error instanceof NameHeld)) throw error;
|
|
188
|
-
out(`skipped ${path}: its saved origin names ${site.name}.localhost, which the front door has registered for ${error.message}. Give it its own name with rer dev --direct, then rer dev --door, in ${root}.`);
|
|
189
|
+
out(`skipped ${path}: its saved origin names ${site.name}.localhost, which the front door has registered for ${error.message}. Give it its own name with ~/.local/bin/rer dev --direct, then ~/.local/bin/rer dev --door, in ${root}.`);
|
|
189
190
|
skipped++; continue;
|
|
190
191
|
}
|
|
191
192
|
const url = doorOrigin(name, port);
|
|
@@ -204,17 +205,17 @@ async function add(args, env) {
|
|
|
204
205
|
// registers it again.
|
|
205
206
|
async function remove(args, env) {
|
|
206
207
|
const given = flags(args, []);
|
|
207
|
-
if (given.positional.length !== 1) throw new DoorFailure(2, 'Usage: rer door remove NAME');
|
|
208
|
+
if (given.positional.length !== 1) throw new DoorFailure(2, 'Usage: ~/.local/bin/rer door remove NAME');
|
|
208
209
|
const [name] = given.positional;
|
|
209
210
|
const removed = await changeDoorState(env, state => { const site = state.sites.find(item => item.name === name && !item.removed); if (site) site.removed = true; return site; });
|
|
210
|
-
if (!removed) { err(`No checkout is registered as ${name}. rer door status lists them.`); return 3; }
|
|
211
|
-
out(`Unregistered ${name} (${removed.checkout}). Its checkout and any running server are untouched, and the name stays reserved for it: rer dev there, or rer door add, registers it again.`);
|
|
211
|
+
if (!removed) { err(`No checkout is registered as ${name}. ~/.local/bin/rer door status lists them.`); return 3; }
|
|
212
|
+
out(`Unregistered ${name} (${removed.checkout}). Its checkout and any running server are untouched, and the name stays reserved for it: ~/.local/bin/rer dev there, or ~/.local/bin/rer door add, registers it again.`);
|
|
212
213
|
return 0;
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
async function status(args, env) {
|
|
216
217
|
const given = flags(args, [], ['--json', '--links']);
|
|
217
|
-
if (given.positional.length) throw new DoorFailure(2, 'Usage: rer door status [--json] [--links]');
|
|
218
|
+
if (given.positional.length) throw new DoorFailure(2, 'Usage: ~/.local/bin/rer door status [--json] [--links]');
|
|
218
219
|
const state = await readDoorState(env), record = await runningDoor(env), version = record?.version ?? ownManifest().version;
|
|
219
220
|
const door = state?.door;
|
|
220
221
|
const views = door ? await doorSites({ env, door }).views() : [];
|
|
@@ -227,9 +228,9 @@ async function status(args, env) {
|
|
|
227
228
|
}
|
|
228
229
|
const sites = views.map(view => ({ name: view.name, path: view.path, mode: view.mode, state: view.state === 'failed' ? 'stopped' : view.state, url: view.url, ...(view.proxyPort && view.state === 'running' ? { proxyPort: view.proxyPort } : {}), ...(view.signIn ? { signIn: view.signIn } : {}) }));
|
|
229
230
|
const result = { running: Boolean(record), enabled: Boolean(door?.enabled), port: door?.port ?? record?.port ?? null, pid: record?.pid ?? null, version, policy: door ? { serverLimit: door.policy.serverLimit, idleSeconds: door.policy.idleSeconds } : null, sites };
|
|
230
|
-
if (given['--json']) {
|
|
231
|
-
if (!door) { out('The front door is not enabled on this computer. Enable it with: rer door enable'); return 0; }
|
|
232
|
-
out(record ? runningLine(door, record) : door.enabled ? `The front door is enabled on port ${door.port} but not running. Start it with: rer door start` : 'The front door is disabled on this computer. Enable it with: rer door enable');
|
|
231
|
+
if (given['--json']) { process.stdout.write(JSON.stringify({ ...result, ...(linkNote ? { linksUnavailable: linkNote } : {}), ...(!record && door?.enabled ? { note: 'After a reboot or logout the front door needs ~/.local/bin/rer door start.' } : {}) }) + '\n'); return 0; }
|
|
232
|
+
if (!door) { out('The front door is not enabled on this computer. Enable it with: ~/.local/bin/rer door enable'); return 0; }
|
|
233
|
+
out(record ? runningLine(door, record) : door.enabled ? `The front door is enabled on port ${door.port} but not running. Start it with: ~/.local/bin/rer door start` : 'The front door is disabled on this computer. Enable it with: ~/.local/bin/rer door enable');
|
|
233
234
|
if (sites.length) {
|
|
234
235
|
const width = Math.max(4, ...sites.map(site => site.name.length));
|
|
235
236
|
out(`${'NAME'.padEnd(width)} STATE MODE URL`);
|
|
@@ -237,9 +238,9 @@ async function status(args, env) {
|
|
|
237
238
|
out(`${site.name.padEnd(width)} ${site.state.padEnd(8)} ${site.mode.padEnd(6)} ${site.url}${site.proxyPort ? ` (proxy 127.0.0.1:${site.proxyPort})` : ''}`);
|
|
238
239
|
if (site.signIn) out(`${' '.repeat(width)} sign in: ${site.signIn}`);
|
|
239
240
|
}
|
|
240
|
-
} else out('No checkouts are registered. Add one with: rer door add PATH');
|
|
241
|
+
} else out('No checkouts are registered. Add one with: ~/.local/bin/rer door add PATH');
|
|
241
242
|
if (linkNote) out(`No sign-in links: ${linkNote}`);
|
|
242
|
-
if (!record && door.enabled) out('After a reboot or logout the front door needs rer door start (or any rer dev in a door-mode checkout).');
|
|
243
|
+
if (!record && door.enabled) out('After a reboot or logout the front door needs ~/.local/bin/rer door start (or any ~/.local/bin/rer dev in a door-mode checkout).');
|
|
243
244
|
return 0;
|
|
244
245
|
}
|
|
245
246
|
|
|
@@ -247,10 +248,10 @@ export async function doorCommand(args, env = process.env) {
|
|
|
247
248
|
// A reader that stops early (rer door status | grep -q) is not a failure.
|
|
248
249
|
process.stdout.on('error', error => { if (error.code === 'EPIPE') process.exit(0); throw error; });
|
|
249
250
|
const [verb, ...rest] = args;
|
|
250
|
-
if (!verb || ['--help', '-h', 'help'].includes(verb) || rest.includes('--help')) { process.stdout.write(doorHelp); return 0; }
|
|
251
|
+
if (!verb || ['--help', '-h', 'help'].includes(verb) || rest.includes('--help')) { process.stdout.write(withCommandHelp(doorHelp) + '\n'); return 0; }
|
|
251
252
|
const verbs = { enable, disable, add, remove, status, start: (_, e) => start(e), stop: (_, e) => stop(e), restart: (_, e) => restart(e) };
|
|
252
|
-
if (!Object.hasOwn(verbs, verb)) { err(`Unknown rer door command: ${verb}. Run rer door --help.`); return 2; }
|
|
253
|
-
if (['start', 'stop', 'restart'].includes(verb) && rest.length) { err(
|
|
253
|
+
if (!Object.hasOwn(verbs, verb)) { err(`Unknown ~/.local/bin/rer door command: ${verb}. Run ~/.local/bin/rer door --help.`); return 2; }
|
|
254
|
+
if (['start', 'stop', 'restart'].includes(verb) && rest.length) { err(`~/.local/bin/rer door ${verb} takes no arguments.`); return 2; }
|
|
254
255
|
try { return await verbs[verb](rest, env); }
|
|
255
256
|
catch (error) { if (error instanceof DoorFailure || error.exitCode) { err(error.message); return error.exitCode ?? 1; } throw error; }
|
|
256
257
|
}
|
package/global/door/control.mjs
CHANGED
|
@@ -16,10 +16,10 @@ export class DoorFailure extends Error { constructor(exitCode, message) { super(
|
|
|
16
16
|
|
|
17
17
|
export async function startDoor(env = process.env) {
|
|
18
18
|
const state = await readDoorState(env);
|
|
19
|
-
if (!state?.door?.enabled) throw new DoorFailure(3, 'The front door is not enabled on this computer. Enable it with: rer door enable');
|
|
19
|
+
if (!state?.door?.enabled) throw new DoorFailure(3, 'The front door is not enabled on this computer. Enable it with: ~/.local/bin/rer door enable');
|
|
20
20
|
const running = await runningDoor(env);
|
|
21
21
|
if (running) {
|
|
22
|
-
if (running.protocol !== doorProtocol) throw new DoorFailure(4, `A front door speaking protocol ${running.protocol} is running (PID ${running.pid}); this rer speaks protocol ${doorProtocol}. Run rer door restart.`);
|
|
22
|
+
if (running.protocol !== doorProtocol) throw new DoorFailure(4, `A front door speaking protocol ${running.protocol} is running (PID ${running.pid}); this rer speaks protocol ${doorProtocol}. Run ~/.local/bin/rer door restart.`);
|
|
23
23
|
return { door: running, already: true };
|
|
24
24
|
}
|
|
25
25
|
const door = state.door, directory = await prepareDoorDirectory(env), logPath = join(directory, 'logs', 'door.log');
|
|
@@ -38,7 +38,7 @@ export async function startDoor(env = process.env) {
|
|
|
38
38
|
if (failed) throw new DoorFailure(1, `The front door could not be started: ${failed.code ?? failed.message}.`);
|
|
39
39
|
// Another start (a rer dev bringing the door back) won the port: use that door.
|
|
40
40
|
if (record?.protocol === doorProtocol) { await verifyDoor(env, record.port); return { door: record, already: true }; }
|
|
41
|
-
const text = (await readFile(logPath, 'utf8')).slice(from).split('\n').filter(line => line.startsWith('rer door: ')).map(line => line.slice('rer door: '.length));
|
|
41
|
+
const text = (await readFile(logPath, 'utf8')).slice(from).split('\n').filter(line => line.startsWith('~/.local/bin/rer door: ')).map(line => line.slice('~/.local/bin/rer door: '.length));
|
|
42
42
|
throw new DoorFailure(exited === 4 ? 4 : 1, text.join('\n') || `The front door stopped while starting (exit ${exited}); see ${logPath}.`);
|
|
43
43
|
}
|
|
44
44
|
await delay(100);
|
package/global/door/pages.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { terminalHelpHtml } from '../../modules/operator-auth/terminal-guidance.mjs';
|
|
1
2
|
// The door's own small pages: the index, starting, start button, failure and
|
|
2
3
|
// unknown-name pages. Plain HTML; the starting page polls the door's state
|
|
3
4
|
// path (a fetch, which never starts a site) and reloads, keeping the fragment.
|
|
@@ -12,10 +13,10 @@ a{color:var(--accent)}code{font:13px ui-monospace,monospace}button{font:inherit;
|
|
|
12
13
|
pre{white-space:pre-wrap;background:rgba(127,127,127,.12);padding:12px;border-radius:6px;font:13px ui-monospace,monospace}`;
|
|
13
14
|
|
|
14
15
|
function page(title, body, { script = '' } = {}) {
|
|
15
|
-
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="referrer" content="origin"><title>${escape(title)}</title><style>${style}</style></head><body><main>${body}</main>${script ? `<script>${script}</script>` : ''}</body></html>`;
|
|
16
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="referrer" content="origin"><title>${escape(title)}</title><style>${style}</style></head><body><main>${body}${body.includes("~/.local/bin/rer ") ? `<p>${terminalHelpHtml}</p>` : ""}</main>${script ? `<script>${script}</script>` : ''}</body></html>`;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export const rebootNote = 'After a reboot or logout the front door needs <code
|
|
19
|
+
export const rebootNote = 'After a reboot or logout the front door needs <code>~/.local/bin/rer door start</code> (or any <code>~/.local/bin/rer dev</code> in a door-mode checkout).';
|
|
19
20
|
|
|
20
21
|
export function indexPage({ port, version, sites }) {
|
|
21
22
|
const rows = sites.map(site => {
|
|
@@ -24,8 +25,8 @@ export function indexPage({ port, version, sites }) {
|
|
|
24
25
|
return `<tr><td><a href="${escape(link)}/">${escape(site.name)}</a>${direct}</td><td>${escape(site.state)}</td><td class="muted"><code>${escape(site.path)}</code></td></tr>`;
|
|
25
26
|
}).join('');
|
|
26
27
|
return page('rer front door', `<h1>rer front door</h1><p class="muted">Port ${port} · rer ${escape(version)}. A site starts when you open it and stops when idle.</p>
|
|
27
|
-
${sites.length ? `<table><thead><tr><th>Site</th><th>State</th><th>Checkout</th></tr></thead><tbody>${rows}</tbody></table>` : '<p>No checkouts are registered. Add one with <code
|
|
28
|
-
<p class="muted">Add a checkout with <code
|
|
28
|
+
${sites.length ? `<table><thead><tr><th>Site</th><th>State</th><th>Checkout</th></tr></thead><tbody>${rows}</tbody></table>` : '<p>No checkouts are registered. Add one with <code>~/.local/bin/rer door add PATH</code>.</p>'}
|
|
29
|
+
<p class="muted">Add a checkout with <code>~/.local/bin/rer door add PATH</code>; see sign-in links with <code>~/.local/bin/rer door status --links</code>. ${rebootNote}</p>`);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
const poll = `const fragment=location.hash;async function check(){try{const r=await fetch('/__rer/door/state',{cache:'no-store'});const s=await r.json();
|
|
@@ -45,5 +46,5 @@ export function failurePage(name, reason, to) {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export function unknownPage(name, port) {
|
|
48
|
-
return page('No such site', `<h1>No checkout is registered as ${escape(name)}</h1><p>Register a checkout with <code
|
|
49
|
+
return page('No such site', `<h1>No checkout is registered as ${escape(name)}</h1><p>Register a checkout with <code>~/.local/bin/rer door add PATH</code>, then open <code>http://NAME.localhost:${port}</code>. <a href="http://localhost:${port}/">All sites</a>.</p>`);
|
|
49
50
|
}
|
package/global/door/server.mjs
CHANGED
|
@@ -24,13 +24,13 @@ import { readHost, startKind } from './routes.mjs';
|
|
|
24
24
|
import { doorSites } from './sites.mjs';
|
|
25
25
|
|
|
26
26
|
const say = line => process.stdout.write(`${new Date().toISOString()} ${line}\n`);
|
|
27
|
-
function fail(message, code = 4) { process.stderr.write(
|
|
27
|
+
function fail(message, code = 4) { process.stderr.write(`~/.local/bin/rer door: ${message}\n`); process.exit(code); }
|
|
28
28
|
|
|
29
29
|
const state = await readDoorState(process.env);
|
|
30
|
-
if (!state?.door?.enabled) fail('The front door is not enabled. Run rer door enable.', 3);
|
|
30
|
+
if (!state?.door?.enabled) fail('The front door is not enabled. Run ~/.local/bin/rer door enable.', 3);
|
|
31
31
|
const { door } = state, port = door.port, version = ownManifest().version;
|
|
32
32
|
const token = (await readPrivate(join(state.directory, 'token')))?.trim();
|
|
33
|
-
if (!token) fail(`The front door's token is missing from ${state.directory}. Run rer door enable.`, 3);
|
|
33
|
+
if (!token) fail(`The front door's token is missing from ${state.directory}. Run ~/.local/bin/rer door enable.`, 3);
|
|
34
34
|
const sites = doorSites({ env: process.env, door, log: say });
|
|
35
35
|
const indexOrigins = new Set(['localhost', '127.0.0.1', '[::1]'].map(host => `http://${host}:${port}`));
|
|
36
36
|
const portOf = name => Number(/:(\d+)$/.exec(name)?.[1]);
|
|
@@ -39,7 +39,7 @@ async function holder() {
|
|
|
39
39
|
const row = (await listeners()).find(item => item.pid !== process.pid && item.names.some(name => portOf(name) === port));
|
|
40
40
|
return row && `PID ${row.pid} (${await processName(row.pid)})`;
|
|
41
41
|
}
|
|
42
|
-
const busy = who => `Port ${port} is held by ${who}. The front door needs 127.0.0.1:${port} and [::1]:${port} to itself. Stop that process, or enable the door on another port with rer door enable --port N.`;
|
|
42
|
+
const busy = who => `Port ${port} is held by ${who}. The front door needs 127.0.0.1:${port} and [::1]:${port} to itself. Stop that process, or enable the door on another port with ~/.local/bin/rer door enable --port N.`;
|
|
43
43
|
|
|
44
44
|
// --- responses -------------------------------------------------------------
|
|
45
45
|
const send = (res, status, type, body, headers = {}) => { res.writeHead(status, { 'content-type': type, 'cache-control': 'no-store', 'x-content-type-options': 'nosniff', ...headers }); res.end(body); };
|
|
@@ -111,7 +111,10 @@ async function site(req, res, target, retried = false) {
|
|
|
111
111
|
if (kind === 'never') return text(res, 503, `${view.name} is not running. Open http://${target.host}/ in a browser to start it.`);
|
|
112
112
|
if (view.state === 'failed') return html(res, 200, failurePage(view.name, view.reason, here));
|
|
113
113
|
if (kind === 'confirm' && view.state !== 'starting') return html(res, 200, confirmPage(view.name, here));
|
|
114
|
-
|
|
114
|
+
// An existing server owns its startup. In particular its readiness browser
|
|
115
|
+
// can arrive before our cached routing status refreshes; do not launch a
|
|
116
|
+
// competing attachment that outlives that startup (or an explicit stop).
|
|
117
|
+
if (!view.record) sites.ensureStarted(registered);
|
|
115
118
|
return html(res, 503, startingPage(view.name), { 'retry-after': '2' });
|
|
116
119
|
}
|
|
117
120
|
|
package/global/door/sites.mjs
CHANGED
|
@@ -17,15 +17,16 @@ import { siteEnvironment } from './policy.mjs';
|
|
|
17
17
|
const rerEntry = join(ownRoot, 'global/rer.mjs');
|
|
18
18
|
const startTimeoutMs = 15 * 60_000, failureShownMs = 30_000;
|
|
19
19
|
|
|
20
|
-
//
|
|
21
|
-
|
|
20
|
+
// Forwarding may begin before readiness: the readiness browser must traverse
|
|
21
|
+
// this door itself. Older servers expose only ready, which also permits routing.
|
|
22
|
+
function serverRoutable(record) {
|
|
22
23
|
return new Promise(resolve => {
|
|
23
24
|
const socket = createConnection(record.control);
|
|
24
25
|
let text = '';
|
|
25
26
|
socket.setTimeout(2000, () => socket.destroy());
|
|
26
27
|
socket.on('connect', () => socket.end(JSON.stringify({ token: record.token, action: 'status' })));
|
|
27
28
|
socket.on('data', chunk => { text += chunk; if (text.length > 16384) socket.destroy(); });
|
|
28
|
-
socket.on('end', () => { try { const value = JSON.parse(text); resolve(value.token === record.token && value.ready === true); } catch { resolve(false); } });
|
|
29
|
+
socket.on('end', () => { try { const value = JSON.parse(text); resolve(value.token === record.token && (value.ready === true || record.door && value.forwarding === true)); } catch { resolve(false); } });
|
|
29
30
|
socket.on('error', () => resolve(false));
|
|
30
31
|
socket.on('close', () => resolve(false));
|
|
31
32
|
});
|
|
@@ -43,7 +44,7 @@ async function failureReason(path, from) {
|
|
|
43
44
|
if (!line.startsWith('{')) continue;
|
|
44
45
|
try { const event = JSON.parse(line); if (event.event === 'error' && typeof event.message === 'string') reasons.push(event.message); } catch {}
|
|
45
46
|
}
|
|
46
|
-
return reasons.at(-1) ?? 'The launch stopped without a reason. Run rer dev in the checkout to see it.';
|
|
47
|
+
return reasons.at(-1) ?? 'The launch stopped without a reason. Run ~/.local/bin/rer dev in the checkout to see it.';
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export function doorSites({ env, door, log = () => {} }) {
|
|
@@ -58,7 +59,7 @@ export function doorSites({ env, door, log = () => {} }) {
|
|
|
58
59
|
async function running(force = false) {
|
|
59
60
|
if (force || Date.now() - records.at > 1000) {
|
|
60
61
|
const live = await liveServers(serverEnv);
|
|
61
|
-
records = { at: Date.now(), list: await Promise.all(live.map(async record => ({ ...record,
|
|
62
|
+
records = { at: Date.now(), list: await Promise.all(live.map(async record => ({ ...record, routable: await serverRoutable(record) }))) };
|
|
62
63
|
}
|
|
63
64
|
return records.list;
|
|
64
65
|
}
|
|
@@ -83,12 +84,12 @@ export function doorSites({ env, door, log = () => {} }) {
|
|
|
83
84
|
const record = (await running(force)).find(item => item.checkout === site.checkout);
|
|
84
85
|
const doorUrl = doorOrigin(site.name, door.port);
|
|
85
86
|
const result = { name: site.name, path: site.checkout, mode: record ? (record.door || doorSite(record.url) ? 'door' : 'direct') : site.mode === 'door' ? 'door' : 'direct', doorUrl };
|
|
86
|
-
if (record?.door && record.door.v !== doorProtocol) return { ...result, state: 'failed', url: doorUrl, reason: `This checkout's server speaks door protocol ${record.door.v}; restart the door with the installed rer (rer door restart).` };
|
|
87
|
-
//
|
|
88
|
-
if (record?.
|
|
87
|
+
if (record?.door && record.door.v !== doorProtocol) return { ...result, state: 'failed', url: doorUrl, reason: `This checkout's server speaks door protocol ${record.door.v}; restart the door with the installed rer (~/.local/bin/rer door restart).` };
|
|
88
|
+
// The proxy is usable during the public browser check, before RER_READY.
|
|
89
|
+
if (record?.routable && (record.door ? record.port : record.url && !doorSite(record.url))) {
|
|
89
90
|
return { ...result, state: 'running', url: record.url, ...(record.door ? { proxyPort: record.port, secret: record.door.secret } : {}), record };
|
|
90
91
|
}
|
|
91
|
-
if (starts.has(site.name) || record) return { ...result, state: 'starting', url: result.mode === 'door' ? doorUrl : site.origin ?? doorUrl };
|
|
92
|
+
if (starts.has(site.name) || record) return { ...result, state: 'starting', url: result.mode === 'door' ? doorUrl : site.origin ?? doorUrl, record };
|
|
92
93
|
const failure = failures.get(site.name);
|
|
93
94
|
if (failure && Date.now() - failure.at < failureShownMs) return { ...result, state: 'failed', reason: failure.reason, url: doorUrl };
|
|
94
95
|
return { ...result, state: 'stopped', url: result.mode === 'door' ? doorUrl : site.origin ?? doorUrl };
|
|
@@ -110,7 +111,7 @@ export function doorSites({ env, door, log = () => {} }) {
|
|
|
110
111
|
// before admission, so nothing is stopped to make room for it.
|
|
111
112
|
async function present(site) {
|
|
112
113
|
const folder = await stat(site.checkout).catch(() => undefined);
|
|
113
|
-
if (!folder?.isDirectory()) throw Error(`The checkout folder ${site.checkout} no longer exists, so ${site.name} was not started. If it moved, run rer dev in its new folder (or rer door add NEW_PATH): it keeps the name ${site.name}, its address and its sign-in. Otherwise unregister it with rer door remove ${site.name}.`);
|
|
114
|
+
if (!folder?.isDirectory()) throw Error(`The checkout folder ${site.checkout} no longer exists, so ${site.name} was not started. If it moved, run ~/.local/bin/rer dev in its new folder (or ~/.local/bin/rer door add NEW_PATH): it keeps the name ${site.name}, its address and its sign-in. Otherwise unregister it with ~/.local/bin/rer door remove ${site.name}.`);
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
// Admission is serial. Each start in turn counts the servers running, the
|
|
@@ -136,10 +137,10 @@ export function doorSites({ env, door, log = () => {} }) {
|
|
|
136
137
|
const mine = await doorStarted();
|
|
137
138
|
const victim = staying.filter(record => mine.has(record.generation) && !admitted.has(record.checkout)).sort((a, b) => (a.lastActivity ?? 0) - (b.lastActivity ?? 0))[0];
|
|
138
139
|
if (!victim) throw Error([
|
|
139
|
-
`The server limit is ${cap}, and every place is held by a server someone started with rer dev or by a start already under way, so none was stopped for ${site.name}:`,
|
|
140
|
-
...staying.map(record => ` ${record.mode} for ${record.checkout} (PID ${record.owner?.pid})${admitted.has(record.checkout) ? ', starting for another visit' : ', started with rer dev'}`),
|
|
140
|
+
`The server limit is ${cap}, and every place is held by a server someone started with ~/.local/bin/rer dev or by a start already under way, so none was stopped for ${site.name}:`,
|
|
141
|
+
...staying.map(record => ` ${record.mode} for ${record.checkout} (PID ${record.owner?.pid})${admitted.has(record.checkout) ? ', starting for another visit' : ', started with ~/.local/bin/rer dev'}`),
|
|
141
142
|
...starting.map(checkout => ` starting ${checkout} for another visit`),
|
|
142
|
-
'Stop one with rer dev --stop in its checkout, or raise the limit with rer door enable --server-limit N.',
|
|
143
|
+
'Stop one with ~/.local/bin/rer dev --stop in its checkout, or raise the limit with ~/.local/bin/rer door enable --server-limit N.',
|
|
143
144
|
].join('\n'));
|
|
144
145
|
evicting.add(victim.generation); admitted.add(site.checkout);
|
|
145
146
|
return victim;
|
|
@@ -65,13 +65,13 @@ export async function checkCapacity(checkout, env, pin) {
|
|
|
65
65
|
`Not started: ${holders.length === 1 ? 'a server' : 'servers'} started with a limit of ${cap} hold${holders.length === 1 ? 's' : ''} this checkout's rer copy to ${cap} running servers, and ${counted.length} ${counted.length === 1 ? 'is' : 'are'} running:`,
|
|
66
66
|
...holders.map(record => ` ${record.mode} for ${record.checkout} (PID ${record.owner?.pid})`),
|
|
67
67
|
`Restart ${holders.length === 1 ? 'it' : 'each'} under rer, which records ${personDefaults.limit} servers:`,
|
|
68
|
-
...holders.flatMap(record => [` rer ${record.mode} --stop --cwd ${JSON.stringify(record.checkout)}`, ` rer ${record.mode} --cwd ${JSON.stringify(record.checkout)}`]),
|
|
68
|
+
...holders.flatMap(record => [` ~/.local/bin/rer ${record.mode} --stop --cwd ${JSON.stringify(record.checkout)}`, ` ~/.local/bin/rer ${record.mode} --cwd ${JSON.stringify(record.checkout)}`]),
|
|
69
69
|
'rer never stops another checkout\'s server itself.',
|
|
70
70
|
].join('\n'));
|
|
71
71
|
throw new LaunchFailure(4, [
|
|
72
72
|
`Not started: ${counted.length} dev or preview ${counted.length === 1 ? 'server is' : 'servers are'} running on this computer and the limit is ${cap}.`,
|
|
73
73
|
'Running now:', ...counted.map(listing),
|
|
74
74
|
file ? `The limit is ${cap} because ${file.path} (RER_SERVER_LIMIT_FILE) says ${cap}. To make room, stop one with its command above, or raise the number in that file.`
|
|
75
|
-
: `To make room, stop one with its command above, or start this one with a higher limit, for example RER_SERVER_LIMIT=${cap * 2} rer dev.`,
|
|
75
|
+
: `To make room, stop one with its command above, or start this one with a higher limit, for example RER_SERVER_LIMIT=${cap * 2} ~/.local/bin/rer dev.`,
|
|
76
76
|
].join('\n'));
|
|
77
77
|
}
|
package/global/launch/dev.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { humanError } from '../../cli/human-error.mjs';
|
|
1
2
|
// Zero-setup `rer dev` for a first-party checkout. With stdout not a terminal
|
|
2
3
|
// (an agent's shell tool) the preparation and start run in a detached worker
|
|
3
4
|
// and this command returns once the app is ready, leaving it running; in a
|
|
@@ -20,7 +21,6 @@ import { printer } from './render.mjs';
|
|
|
20
21
|
import { access } from 'node:fs/promises';
|
|
21
22
|
import { layout } from '../cli/layout.mjs';
|
|
22
23
|
import { pathAdvice } from '../cli/path-link.mjs';
|
|
23
|
-
import { shellQuote } from '../../cli/node-runtime-cache.mjs';
|
|
24
24
|
import { showBudget } from '../../cli/run-transfers.mjs';
|
|
25
25
|
import { stopLaunch } from './stop.mjs';
|
|
26
26
|
import { launchDirectory, liveWorker } from './state.mjs';
|
|
@@ -36,7 +36,7 @@ export async function launchDev(target) {
|
|
|
36
36
|
const devArgs = args.filter(arg => !['--detach', '--foreground', '--door-start'].includes(arg));
|
|
37
37
|
// A pin from before the front door cannot move to it: say so in one line.
|
|
38
38
|
if ((devArgs.includes('--door') || devArgs.includes('--direct')) && !await doorCapable(target.root)) {
|
|
39
|
-
process.stderr.write('This checkout\'s pinned Base has no front-door support, so it stays direct. Refresh its Base to serve it through the door; rer door add still lists it and starts it on a visit.\n');
|
|
39
|
+
process.stderr.write('This checkout\'s pinned Base has no front-door support, so it stays direct. Refresh its Base to serve it through the door; ~/.local/bin/rer door add still lists it and starts it on a visit.\n');
|
|
40
40
|
return 2;
|
|
41
41
|
}
|
|
42
42
|
// An invocation the pinned dispatcher refuses goes straight to it, so the
|
|
@@ -45,16 +45,16 @@ export async function launchDev(target) {
|
|
|
45
45
|
const checkout = await realpath(target.root), directory = await launchDirectory(checkout);
|
|
46
46
|
if (devArgs.includes('--stop')) {
|
|
47
47
|
try { return await stopLaunch(target, devArgs, { checkout, directory }); }
|
|
48
|
-
catch (failure) { if (!(failure instanceof LaunchFailure)) throw failure; process.stderr.write(failure
|
|
48
|
+
catch (failure) { if (!(failure instanceof LaunchFailure)) throw failure; process.stderr.write(humanError(failure) + '\n'); return failure.exitCode; }
|
|
49
49
|
}
|
|
50
50
|
showBudget(devArgs);
|
|
51
51
|
// The launch never asks for shell edits. Name the PATH step only at ready,
|
|
52
52
|
// and not when install.sh closes with its own required PATH step.
|
|
53
53
|
delete process.env.RER_LAUNCH_PATH_STEP;
|
|
54
54
|
const paths = layout();
|
|
55
|
-
if (!process.env.RER_INSTALLER_PATH_STEP && await access(paths.launcher).then(() => true, () => false) && await pathAdvice(paths)) process.env.RER_LAUNCH_PATH_STEP = `Next step, after opening your app: a bare \`rer\` in a new terminal will not be found yet. Run
|
|
55
|
+
if (!process.env.RER_INSTALLER_PATH_STEP && await access(paths.launcher).then(() => true, () => false) && await pathAdvice(paths)) process.env.RER_LAUNCH_PATH_STEP = `Next step, after opening your app: a bare \`rer\` in a new terminal will not be found yet. Run ~/.local/bin/rer cli path to see the one line that fixes it; it changes no shell file itself.`;
|
|
56
56
|
const here = await realpath(process.cwd()).catch(() => undefined);
|
|
57
|
-
const out = printer({ root: checkout, json: devArgs.includes('--json'), stopHint:
|
|
57
|
+
const out = printer({ root: checkout, json: devArgs.includes('--json'), stopHint: `~/.local/bin/rer dev --stop${here === checkout ? '' : ` --cwd ${JSON.stringify(checkout)}`}`, keyless: doorStart });
|
|
58
58
|
const detach = args.includes('--detach') || (!args.includes('--foreground') && !process.stdout.isTTY);
|
|
59
59
|
return detach ? detached(target, devArgs, directory, out, doorStart) : foreground(target, devArgs, directory, out, doorStart);
|
|
60
60
|
}
|
|
@@ -146,6 +146,6 @@ async function follow(directory, token, out, { worker, quiet = false }) {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
function missing(directory) {
|
|
149
|
-
process.stderr.write(`rer dev: the launch stopped before it finished. Run rer dev again; its log is ${join(directory, 'launch.log')}.\n`);
|
|
149
|
+
process.stderr.write(`rer dev: the launch stopped before it finished. Run ~/.local/bin/rer dev again; its log is ${join(directory, 'launch.log')}.\n`);
|
|
150
150
|
return 1;
|
|
151
151
|
}
|
package/global/launch/door.mjs
CHANGED
|
@@ -18,7 +18,7 @@ export async function doorPlan(described, args, env) {
|
|
|
18
18
|
const running = door?.enabled ? await runningDoor(env).catch(() => undefined) : undefined;
|
|
19
19
|
const protocol = running?.protocol ?? door?.protocol;
|
|
20
20
|
const known = Boolean(door?.enabled) && protocol === doorProtocol;
|
|
21
|
-
const note = door?.enabled && !known ? `The front door speaks protocol ${protocol}, which this rer does not know, so this checkout stays direct. Run rer door restart.` : undefined;
|
|
21
|
+
const note = door?.enabled && !known ? `The front door speaks protocol ${protocol}, which this rer does not know, so this checkout stays direct. Run ~/.local/bin/rer door restart.` : undefined;
|
|
22
22
|
const saved = Boolean(described?.local?.origin && doorSite(described.local.origin));
|
|
23
23
|
return { door, known, note, freshAtDoor: known && capable && !direct, atDoor: !direct && (saved || has(args, '--door')) };
|
|
24
24
|
}
|
package/global/launch/facts.mjs
CHANGED
|
@@ -16,7 +16,7 @@ export async function describeCheckout(root, entry, env, signal) {
|
|
|
16
16
|
return JSON.parse(stdout);
|
|
17
17
|
} catch (error) {
|
|
18
18
|
if (signal?.aborted) throw signal.reason;
|
|
19
|
-
throw new LaunchFailure(error.code ?? 1, (error.stderr?.trim() ||
|
|
19
|
+
throw new LaunchFailure(error.code ?? 1, (error.stderr?.trim() || `~/.local/bin/rer describe failed in ${root}.`));
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -59,5 +59,5 @@ export async function freePort(ports, claim, env = process.env) {
|
|
|
59
59
|
const held = new Set(ports.filter(Boolean));
|
|
60
60
|
const found = await searchPort({ host: '127.0.0.1', from, hosts: ['127.0.0.1', '::1'], skip: port => held.has(port), claim, verb: 'dev' });
|
|
61
61
|
if (found.port !== undefined) return found;
|
|
62
|
-
throw new LaunchFailure(4, `No free port from ${found.range[0]} to ${found.range[1]}: all ${found.tried} ports tried were in use. Stop something that holds one, or pass rer dev --port PORT with a free port.`);
|
|
62
|
+
throw new LaunchFailure(4, `No free port from ${found.range[0]} to ${found.range[1]}: all ${found.tried} ports tried were in use. Stop something that holds one, or pass ~/.local/bin/rer dev --port PORT with a free port.`);
|
|
63
63
|
}
|
|
@@ -18,7 +18,7 @@ export function workerFailure(error, { root, env = process.env }) {
|
|
|
18
18
|
: value && typeof value === 'object' ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, clean(item)])) : value;
|
|
19
19
|
const exitCode = Number.isInteger(error?.exitCode) && error.exitCode > 0 && error.exitCode <= 255 ? error.exitCode : 1;
|
|
20
20
|
const cause = redact(error?.message || error || 'The launch stopped before the app was ready.');
|
|
21
|
-
const retry =
|
|
21
|
+
const retry = `~/.local/bin/rer dev --cwd '${root.replaceAll("'", "'\\''")}'`;
|
|
22
22
|
const message = `${cause}\nCorrect the cause, then run ${retry} again.`;
|
|
23
23
|
const event = { version: 1, verb: 'dev', event: 'error', code: 'launch_failed', ...clean(error?.event), message, exitCode };
|
|
24
24
|
return new LaunchFailure(exitCode, message, event);
|