@runeditrun/rer 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +3 -0
  2. package/cli/README.md +18 -7
  3. package/cli/contract.mjs +3 -0
  4. package/cli/deploy-command.mjs +30 -12
  5. package/cli/deploy-hook-record.mjs +32 -0
  6. package/cli/deploy-hook.mjs +31 -0
  7. package/cli/deploy-observation.mjs +4 -3
  8. package/cli/deploy-owner.mjs +11 -5
  9. package/cli/deploy-source.mjs +24 -0
  10. package/cli/deploy.mjs +7 -1
  11. package/cli/inspect.mjs +2 -2
  12. package/cli/lifecycle.mjs +15 -0
  13. package/cli/pnpm-probe.mjs +14 -7
  14. package/cli/project-pnpm.mjs +15 -7
  15. package/cli/setup-input.mjs +6 -4
  16. package/global/CHANGELOG.md +31 -0
  17. package/global/README.md +3 -0
  18. package/global/launch/facts.mjs +1 -6
  19. package/global/launch/prepare.mjs +4 -3
  20. package/global/launch/state.mjs +18 -18
  21. package/modules/container/README.md +3 -1
  22. package/modules/container/boundary.mjs +5 -2
  23. package/modules/deploy-kit/README.md +11 -8
  24. package/modules/deploy-kit/deploy.mjs +14 -5
  25. package/modules/deploy-kit/diagnostics.mjs +8 -0
  26. package/modules/deploy-kit/health-request.mjs +7 -5
  27. package/modules/deploy-kit/owner-cli.mjs +3 -1
  28. package/modules/deploy-kit/owner-remove.mjs +1 -0
  29. package/modules/deploy-kit/owner-secret-names.mjs +31 -0
  30. package/modules/deploy-kit/owner-secret.mjs +6 -3
  31. package/modules/deploy-kit/owner.mjs +22 -16
  32. package/modules/deploy-kit/provider.mjs +7 -0
  33. package/modules/job-queue/identity.mjs +3 -1
  34. package/modules/job-queue/policy.mjs +2 -1
  35. package/onboarding/adapter-settings.mjs +14 -5
  36. package/onboarding/local/owner.mjs +35 -10
  37. package/package.json +1 -1
  38. package/scripts/publish-check/publication-config.json +11 -1
package/README.md CHANGED
@@ -104,6 +104,9 @@ A seed that declares a run site prints one more line after those,
104
104
  `RER_SITE http://127.0.0.1:8788`: a local preview of its static run site (its
105
105
  marketing homepage, `/run` and docs) on the first free port above the app's. It
106
106
  stops with the app.
107
+ Later, `rer setup --owner-email YOU` (or `--answers`) with the real owner
108
+ replaces that local owner in place and keeps all local data, saying so in one
109
+ line; a checkout whose database holds any other owner is still refused.
107
110
  It never prompts and never re-runs setup on a checkout that is already set up. A
108
111
  setup a launch started that was stopped or failed is run again by the next
109
112
  `rer dev`, keeping the owner and origin it saved, unless a setup has finished
package/cli/README.md CHANGED
@@ -273,13 +273,24 @@ against that registry.
273
273
  Owner-account application deploy completion is shared across standard and custom
274
274
  hooks. An adapter can declare `deployDeclaration` (or `deploy.declaration`);
275
275
  legacy hooks with one root owner deployment declaration are supported too. A
276
- custom hook may return only `{ deployed: true, origin }`: rer verifies the
277
- recorded Worker, runs the adapter's actual owner bootstrap, records successful
278
- ownership separately from retired secrets, and removes the setup token before
279
- returning success. An owner already claimed by the hook is kept without another
280
- bootstrap. An existing owner is explicitly reported as kept. Function owner
281
- hooks run their complete bootstrap flow; setup manifest paths do not replace it.
282
- A missing or ambiguous declaration or deployment receipt refuses completion.
276
+ custom hook returns `{ deployed: true, origin }` once its upload is live (an
277
+ https origin; http only on a loopback host, or rer sends it nothing), plus
278
+ `setupToken` when its Worker holds a setup token other than the `SETUP_TOKEN`
279
+ rer passed it. rer waits until the origin's `/health` names the checkout's commit,
280
+ then runs the adapter's actual owner bootstrap with that token and prints the
281
+ sign-in address; a hook that reports no deployment, or whose app never names
282
+ the commit, fails with what happened and claims nothing. When the hook deployed
283
+ through the kit's standard deployment record, rer also records successful
284
+ ownership separately from retired secrets and removes the setup token before
285
+ returning success; a hook that keeps its own record keeps its token, and returns
286
+ that kit state file as `state` so `rer deploy --remove --yes` removes what it
287
+ deployed (`cli/deploy-hook-record.mjs` keeps the pointer). An owner
288
+ already claimed by the hook is kept without another bootstrap. An existing owner
289
+ is explicitly reported as kept. Function owner hooks run their complete
290
+ bootstrap flow; setup manifest paths do not replace it. A missing or ambiguous
291
+ declaration refuses completion. A kit or custom-hook deploy, except `--dry-run`,
292
+ first refuses uncommitted tracked source, naming the files, before any build or
293
+ upload.
283
294
 
284
295
  `--env-file` values are available in the command's preflight, custom hook and
285
296
  child build environment and are redacted; the caller environment is restored
package/cli/contract.mjs CHANGED
@@ -20,6 +20,9 @@ const definitions = {
20
20
  check: [['--profile'], 'Read-only structural command contract and operations validation.'],
21
21
  };
22
22
  export const verbs = Object.fromEntries(Object.entries(definitions).map(([name, [flags, effects]]) => [name, { flags: [...commonFlags, ...flags, ...(['build','deploy','dev','preview','export','import'].includes(name)?['--platform']:[]), ...(['install','setup','dev','preview','build','verify','deploy','export','import'].includes(name)?['--no-queue']:[])], effects }]));
23
+ // `rer demo` is `rer dev --demo`; describe lists it as a verb with the dev
24
+ // flags a demo takes whenever the seed's dev takes --demo.
25
+ export const demoVerb = Object.freeze({ flags: [...commonFlags, '--port', '--host', '--idle-timeout', '--stop', '--detach', '--foreground', '--no-queue'], effects: 'A throwaway demo of this seed (rer dev --demo): fresh data in .rer/demo/START (deleted when it stops: --stop, Ctrl-C or its end, one hour by default or --idle-timeout), the saved owner signed in, the seed\'s demo data, a Demo bar, and nothing sent (RER_DEMO=1; the checkout\'s own data is never touched).' });
23
26
  export const aliases = Object.fromEntries([...Object.keys(verbs).filter(v => v !== 'install'), 'release', 'deps', 'rer'].map(name => [name, name === 'deps' ? 'install' : name === 'rer' ? null : name]));
24
27
  export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--dry-run', '--tag', '--clean-history', '--onto', '--env-file', '--no-queue'];
25
28
  export const requiredHooks = ['preview', 'dependencies', 'build', 'migrate', 'start', 'health', 'owner', 'signIn', 'verify', 'deploy', 'portability', 'state', 'settings', 'input'];
@@ -6,9 +6,13 @@ import { deployEnvironment, deployAgain } from './deploy-inputs.mjs';
6
6
  import { claimHostedOwner } from './deploy-owner.mjs';
7
7
  import { mutationReadinessFailure } from './deploy-readiness.mjs';
8
8
  import { observeOwner } from './deploy-observation.mjs';
9
+ import { committedSource } from './deploy-source.mjs';
10
+ import { hookOrigin, waitForSource } from './deploy-hook.mjs';
11
+ import { rememberHookState } from './deploy-hook-record.mjs';
9
12
  import { main as owner } from '../modules/deploy-kit/owner-cli.mjs';
10
13
  import { localOnlyBinding, ownerWorkerName } from '../modules/deploy-kit/owner.mjs';
11
14
  import { refuseLocalModels } from '../modules/deploy-kit/local-only.mjs';
15
+ import { providerRefusal } from '../modules/deploy-kit/diagnostics.mjs';
12
16
  import { shared } from './shared.mjs';
13
17
 
14
18
  export function validateDeployOptions(options) {
@@ -45,50 +49,64 @@ export async function deployCommand(context) {
45
49
  // may perform them; neither a build nor a custom upload runs here.
46
50
  if (options.remove || options.setSecret || options.unsetSecret) return ownerDeploy(path, adapter)(context);
47
51
  if (adapter.deploy.managesHostedOwner) return adapter.deploy(context);
52
+ const sourceSha = options.dryRun ? undefined : committedSource(root, options);
48
53
  const { env, supplied } = await deployEnvironment({ root, options, declaration, setupManifest, settings: adapter.settings, localOnlyKeys });
49
54
  const { createRedaction, credentialValues } = await shared('redaction.mjs');
50
55
  const redaction = createRedaction();
51
56
  const addSecret = value => { redaction.addSecrets([value]); store.addSecrets?.([value]); };
52
57
  for (const value of [...credentialValues(env), env.CLOUDFLARE_ACCOUNT_ID, ...(declaration.secrets ?? []).map(item => env[item.environment])].filter(Boolean)) addSecret(value);
53
58
  const command = (verb, extra = [], values = env) => owner([verb, '--declaration', path, '--environment', options.environment ?? 'production', ...extra], values, { cwd: root, localOnlyKeys });
59
+ // A hook that deployed through the kit's standard record lets rer issue and
60
+ // retire the setup token; a hook keeping its own record keeps its token.
54
61
  let recorded;
55
- const inspect = async () => (recorded = await command('inspect'));
62
+ const inspect = async () => {
63
+ try { return recorded = await command('inspect'); }
64
+ catch (error) { if (error.message !== 'missing-owner-receipt') throw error; }
65
+ };
56
66
  let observedClaims = [];
57
67
  let deployed, claimed, linked = false, linkResult, step = 'custom deploy';
58
- const link = async token => { if (!linked) { const state = await inspect(); linkResult = await linkDependencies?.(state.origin, token); linked = true; } return linkResult; };
68
+ const link = async (token, origin) => { if (!linked) { const state = await inspect(); linkResult = await linkDependencies?.(state?.origin ?? origin, token); linked = true; } return linkResult; };
59
69
  try {
60
70
  return await observeOwner({ paths: ['/auth/bootstrap', adapter.hooks?.owner?.path, setupManifest?.steps?.find(item => item.type === 'owner-claim')?.path].filter(Boolean), inspect, beforeClaim: link, addSecret }, async claims => {
61
71
  observedClaims = claims;
62
72
  const saved = { ...process.env };
63
73
  try {
64
74
  Object.assign(process.env, env);
65
- deployed = await adapter.deploy({ ...context, linkDependencies: async (_origin, token) => link(token) });
75
+ deployed = await adapter.deploy({ ...context, linkDependencies: async (origin, token) => link(token, origin) });
66
76
  } finally {
67
77
  for (const key of Object.keys(process.env)) if (!Object.hasOwn(saved, key)) delete process.env[key];
68
78
  Object.assign(process.env, saved);
69
79
  }
70
80
  if (options.dryRun) return deployed;
71
- if (!deployed?.deployed) throw new Error('custom-deploy-did-not-confirm-deployment');
81
+ await rememberHookState(root, options.environment ?? 'production', deployed?.state);
82
+ const origin = hookOrigin(deployed, deployAgain(options));
83
+ step = 'wait for the deployed source';
84
+ await waitForSource({ origin, sourceSha, again: deployAgain(options) });
72
85
  step = 'verify recorded deployment';
73
86
  const state = await inspect();
74
- if (state.origin !== deployed.origin) throw new Error('owner-claim-origin-mismatch');
87
+ if ((state?.origin ?? origin) !== origin || claims.some(item => item.origin !== origin)) throw new Error('owner-claim-origin-mismatch');
75
88
  if (claims.some(item => !item.outcome)) throw new Error('owner-claim-failed');
76
89
  claimed = claims.at(-1)?.outcome;
77
90
  step = 'claim owner';
78
- claimed = await claimHostedOwner({ hook: adapter.hooks?.owner, setupManifest, declaration, deployed: { ...state, owner: claimed, observedOwner: () => claims.at(-1)?.outcome }, env, supplied, secret: (extra, values) => command('secret', extra, values), addSecret, beforeClaim: link, recordClaim: outcome => command('record-owner', ['--outcome', outcome]), store, signal: context.signal });
79
- if (!linked) await linkDependencies?.(state.origin);
80
- if (claimed) store.report(`${claimed === 'claimed' ? 'Claimed the hosted owner' : 'The hosted owner was already claimed and was kept'}; the one-time setup token was removed. Sign in by email at ${state.origin}.`);
81
- return { ...deployed, ...(claimed ? { owner: claimed } : {}), dependenciesLinked: true };
91
+ if (typeof deployed.setupToken === 'string' && deployed.setupToken) addSecret(deployed.setupToken);
92
+ const kit = state ? { secret: (extra, values) => command('secret', extra, values), recordClaim: outcome => command('record-owner', ['--outcome', outcome]) } : { token: deployed.setupToken || undefined };
93
+ claimed = await claimHostedOwner({ hook: adapter.hooks?.owner, setupManifest, declaration, deployed: { ...state, origin, owner: claimed, observedOwner: () => claims.at(-1)?.outcome }, env, supplied, ...kit, addSecret, beforeClaim: token => link(token, origin), store, signal: context.signal });
94
+ if (!linked) await linkDependencies?.(origin);
95
+ if (claimed) store.report(`${claimed === 'claimed' ? 'Claimed the hosted owner' : 'The hosted owner was already claimed and was kept'}${state ? '; the one-time setup token was removed' : ''}. Sign in by email at ${origin}.`);
96
+ const { setupToken: _, ...result } = deployed;
97
+ return { ...result, ...(claimed ? { owner: claimed } : {}), dependenciesLinked: true };
82
98
  });
83
99
  } catch (error) {
84
100
  const again = deployAgain(options);
85
- if (error instanceof RerError && !deployed?.deployed && !recorded) { error.message = store.redact?.(redaction.redact(error.message)) ?? redaction.redact(error.message); throw error; }
86
101
  const { commandFailure } = await shared('failures.mjs');
102
+ if (error.hookFailure) throw commandFailure(store.redact?.(redaction.redact(error.message)) ?? redaction.redact(error.message));
103
+ if (error instanceof RerError && !deployed?.deployed && !recorded) { error.message = store.redact?.(redaction.redact(error.message)) ?? redaction.redact(error.message); throw error; }
87
104
  const outcome = error.owner ?? claimed ?? observedClaims.at(-1)?.outcome;
88
- const state = deployed?.deployed || recorded ? `The application is deployed at ${deployed?.origin ?? recorded.origin}; ${outcome ? `owner ${outcome}` : 'owner claim is not confirmed'}; setup token retirement is not confirmed.` : 'The custom deploy did not finish; inspect its deployment record before recovery.';
105
+ const state = deployed?.deployed || recorded ? `The application is deployed at ${deployed?.origin ?? recorded.origin}; ${outcome ? `owner ${outcome}` : 'owner claim is not confirmed'}${recorded ? '; setup token retirement is not confirmed' : ''}.` : 'The custom deploy did not finish; inspect its deployment record before recovery.';
89
106
  const redact = value => store.redact?.(redaction.redact(value)) ?? redaction.redact(value);
90
107
  const readiness = mutationReadinessFailure(error, { again, redact });
91
108
  if (readiness) throw commandFailure(readiness);
92
- throw commandFailure(redact(`${state} Failed at ${step}: ${error.message}${error.cause ? ` (${error.cause})` : ''}. Fix the cause and run ${again} again using the same environment credentials. ${outcome ? `To retire the token without rebuilding: ${again} --unset-secret ${setupManifest?.steps?.find(item => item.type === 'owner-claim')?.tokenField ?? 'SETUP_TOKEN'}.` : ''}`));
109
+ const refused = providerRefusal(error);
110
+ throw commandFailure(redact(`${state} Failed at ${step}: ${error.message}${refused ? ` (${refused})` : ''}${error.cause ? ` (${error.cause})` : ''}. Fix the cause and run ${again} again using the same environment credentials. ${outcome && recorded ? `To retire the token without rebuilding: ${again} --unset-secret ${setupManifest?.steps?.find(item => item.type === 'owner-claim')?.tokenField ?? 'SETUP_TOKEN'}.` : ''}`));
93
111
  }
94
112
  }
@@ -0,0 +1,32 @@
1
+ // A custom deploy hook that deploys with the kit under its own state file returns
2
+ // that file as `state`. rer keeps a pointer to it beside its own records, so
3
+ // `rer deploy --remove` finds and removes what the hook deployed.
4
+ import { readFile, rm } from 'node:fs/promises';
5
+ import { isAbsolute, join, relative } from 'node:path';
6
+ import { contained } from './project.mjs';
7
+ import { invalid } from './errors.mjs';
8
+ import { shared } from './shared.mjs';
9
+
10
+ const pointer = environment => join('.rer', 'deploy', `${environment}.hook.json`);
11
+
12
+ export async function rememberHookState(root, environment, state) {
13
+ if (state === undefined) return;
14
+ if (typeof state !== 'string' || !state) throw invalid('A deploy hook returns state as the path of its kit state file in this checkout.');
15
+ const path = isAbsolute(state) ? relative(root, state) : state;
16
+ await contained(root, path);
17
+ const { privateDirectory, writePrivateFile } = await shared('private-files.mjs');
18
+ await privateDirectory(root, ['.rer', 'deploy']);
19
+ await writePrivateFile(join(root, pointer(environment)), JSON.stringify({ state: path }) + '\n');
20
+ }
21
+
22
+ // The hook's state file for this environment, or undefined when no hook named one.
23
+ export async function hookState(root, environment) {
24
+ let text;
25
+ try { text = await readFile(join(root, pointer(environment)), 'utf8'); } catch (error) { if (error.code === 'ENOENT') return undefined; throw error; }
26
+ let state;
27
+ try { ({ state } = JSON.parse(text)); } catch { throw invalid(`${pointer(environment)} is malformed. Restore it, or remove it to fall back to rer's own deployment record.`); }
28
+ await contained(root, state, { optional: true });
29
+ return state;
30
+ }
31
+
32
+ export const forgetHookState = (root, environment) => rm(join(root, pointer(environment)), { force: true });
@@ -0,0 +1,31 @@
1
+ import { waitHealth } from '../modules/deploy-kit/health-request.mjs';
2
+ import { isLoopbackHost } from '../modules/operator-auth/loopback.mjs';
3
+
4
+ // A custom deploy hook owns its upload and whatever record it keeps of it. It
5
+ // returns { deployed: true, origin }; rer claims the owner only once that
6
+ // origin's /health names the commit this run deployed. The origin is https
7
+ // (http only on loopback), since the claim sends the one-time setup token there.
8
+ export function hookOrigin(deployed, again) {
9
+ const url = deployed?.deployed === true && typeof deployed.origin === 'string' && URL.canParse(deployed.origin) ? new URL(deployed.origin) : undefined;
10
+ if (url?.protocol === 'http:' && !isLoopbackHost(url.hostname)) throw hookFailure(`The deploy hook reported its deployment at ${url.origin}, which is not https, so rer sent it nothing and claimed no owner. Make the hook return its https origin, then run ${again} again.`);
11
+ if (url && (url.protocol === 'https:' || url.protocol === 'http:') && url.origin === deployed.origin) return url.origin;
12
+ throw hookFailure(`The deploy hook finished without reporting a live deployment, so rer claimed no owner. A deploy hook returns { deployed: true, origin } once its upload is live. Check the hook's output above, fix the hook, then run ${again} again.`);
13
+ }
14
+
15
+ export async function waitForSource({ origin, sourceSha, again }) {
16
+ try { await waitHealth({ origin, expected: { sourceSha }, request: (url, init) => globalThis.fetch(url, init) }); }
17
+ catch (error) {
18
+ const last = error.attempts?.at(-1);
19
+ let named;
20
+ try { named = JSON.parse(last.body).deployment?.sourceSha; } catch {}
21
+ const seen = !last || last.status === null ? 'it did not answer'
22
+ : last.status !== 200 ? `its last answer was HTTP ${last.status}`
23
+ : typeof named === 'string' && /^[0-9a-f]{7,64}$/.test(named) ? `it still answers for commit ${named.slice(0, 12)}`
24
+ : 'it answers without a deploy identity';
25
+ throw hookFailure(`The deploy hook reported a deployment at ${origin}, but its /health never named this checkout's commit ${sourceSha.slice(0, 12)} (${seen}), so rer claimed no owner. Check that the hook uploaded this build and that /health answers deploymentHealth(env), then run ${again} again.`);
26
+ }
27
+ }
28
+
29
+ function hookFailure(message) {
30
+ return Object.assign(new Error(message), { hookFailure: true });
31
+ }
@@ -1,6 +1,7 @@
1
1
  // Observe the actual bootstrap exchange of a custom hook, including hooks that
2
2
  // call the shared owner helper themselves. Never issue a second claim after it.
3
- // The deployment record is checked before linking with its live setup token.
3
+ // The kit's deployment record, when the hook keeps one there, is checked before
4
+ // linking with its live setup token; rer checks the origin the hook returns too.
4
5
  export async function observeOwner({ paths, inspect, beforeClaim, addSecret }, run) {
5
6
  const fetch = globalThis.fetch, claims = [];
6
7
  globalThis.fetch = async (input, init = {}) => {
@@ -12,8 +13,8 @@ export async function observeOwner({ paths, inspect, beforeClaim, addSecret }, r
12
13
  if (typeof body?.token !== 'string' || !body.token) return fetch(input, init);
13
14
  addSecret(body.token);
14
15
  const deployed = await inspect();
15
- if (url.origin !== deployed.origin) throw new Error('owner-claim-origin-mismatch');
16
- await beforeClaim?.(body.token);
16
+ if (deployed && url.origin !== deployed.origin) throw new Error('owner-claim-origin-mismatch');
17
+ await beforeClaim?.(body.token, url.origin);
17
18
  const response = await fetch(input, init);
18
19
  let code;
19
20
  if (response.status !== 303) {
@@ -8,9 +8,11 @@ import { randomBytes } from 'node:crypto';
8
8
  // did not upload this run gets a fresh one first, unless the person supplied the
9
9
  // token (environment or --env-file) and inspection has not found it absent. A
10
10
  // seed with its own owner step function runs its own bootstrap; identity-provider
11
- // linking runs before retirement.
11
+ // linking runs before retirement. Without `secret`, the Worker's secrets are a
12
+ // deploy hook's own: rer claims with the `token` it returned, else the one rer
13
+ // gave it, and leaves that token with the hook.
12
14
  // `beforeClaim(token)` runs while the token is live (dependency approvals need it).
13
- export async function claimHostedOwner({ hook, setupManifest, declaration, deployed, env, supplied = [], secret, addSecret, beforeClaim, recordClaim, inspect, store, signal, fetch = globalThis.fetch }) {
15
+ export async function claimHostedOwner({ hook, setupManifest, declaration, deployed, env, supplied = [], secret, token: hookToken, addSecret, beforeClaim, recordClaim, inspect, store, signal, fetch = globalThis.fetch }) {
14
16
  const claim = setupManifest?.steps?.find(step => step.type === 'owner-claim');
15
17
  if (!hook || !['object', 'function'].includes(typeof hook) || Array.isArray(hook) || !deployed.origin) {
16
18
  if (declaration.secrets?.some(item => item.binding === (claim?.tokenField ?? 'SETUP_TOKEN'))) throw ownerFailure('the owner bootstrap hook is unavailable');
@@ -20,7 +22,9 @@ export async function claimHostedOwner({ hook, setupManifest, declaration, deplo
20
22
  const item = (Array.isArray(declaration.secrets) ? declaration.secrets : []).find(entry => entry?.binding === tokenKey);
21
23
  if (!item) { if (claim) throw ownerFailure('the deploy declaration does not name the owner setup token secret'); return undefined; }
22
24
  const retire = async outcome => {
23
- try { await recordClaim?.(outcome); await secret(['--unset', tokenKey], env); }
25
+ if (!secret) return outcome;
26
+ // A recorded claim stays as recorded: a later deploy keeps that owner.
27
+ try { if (!deployed.ownerClaim) await recordClaim?.(outcome); await secret(['--unset', tokenKey], env); }
24
28
  catch (cause) {
25
29
  if (cause.secretChange) { cause.owner = outcome; cause.tokenKey = tokenKey; cause.ownerFinalization = true; throw cause; }
26
30
  const error = new Error('owner-token-retirement-failed'); error.owner = outcome; error.tokenKey = tokenKey; error.cause = cause.message; throw error; }
@@ -34,7 +38,8 @@ export async function claimHostedOwner({ hook, setupManifest, declaration, deplo
34
38
  // record or live-secret inspection. Keep their completed deploys idempotent.
35
39
  if (!deployed.liveSecrets && deployed.retiredSecrets?.includes(tokenKey)) return undefined;
36
40
  const given = (!deployed.liveSecrets || deployed.liveSecrets.includes(tokenKey)) && env[item.environment]?.trim() && !supplied.includes(tokenKey);
37
- let token = deployed.sentSecrets?.includes(tokenKey) || given ? env[item.environment] : undefined;
41
+ let token = !secret ? hookToken ?? env[item.environment] : deployed.sentSecrets?.includes(tokenKey) || given ? env[item.environment] : undefined;
42
+ if (!token && !secret) throw ownerFailure(`the deploy hook returned no setupToken and ${item.environment} is not set`);
38
43
  if (!token) {
39
44
  token = randomBytes(32).toString('hex'); addSecret(token);
40
45
  // The secret controller confirms readiness of the full new version identity.
@@ -67,7 +72,8 @@ export async function claimHostedOwner({ hook, setupManifest, declaration, deplo
67
72
  if (response.status !== 303) { try { const body = await response.json(); if (typeof body?.error === 'string' && /^[a-z_]{1,64}$/.test(body.error)) code = body.error; } catch {} }
68
73
  else await response.body?.cancel();
69
74
  const outcome = response.status === 303 ? 'claimed' : response.status === 409 && code === 'already_initialized' ? 'kept' : undefined;
70
- if (!outcome) throw ownerFailure(`HTTP ${response.status} (${code})${code === 'invalid_setup_token' && given ? `; the ${item.environment} you supplied is not the deployed setup token: leave it unset and rer issues a fresh one` : ''}`);
75
+ const advice = code !== 'invalid_setup_token' ? '' : !secret ? `; the Worker holds another setup token: have the deploy hook return the one it deployed as setupToken, or set it as ${item.environment} with --env-file` : given ? `; the ${item.environment} you supplied is not the deployed setup token: leave it unset and rer issues a fresh one` : '';
76
+ if (!outcome) throw ownerFailure(`HTTP ${response.status} (${code})${advice}`);
71
77
  return retire(outcome);
72
78
  }
73
79
 
@@ -0,0 +1,24 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { refuse } from './errors.mjs';
3
+ import { deployAgain } from './deploy-inputs.mjs';
4
+
5
+ // rer deploy publishes the checkout's last commit: the deploy identity names it.
6
+ // Say so before any build or upload, naming the tracked files that differ.
7
+ export function committedSource(root, options) {
8
+ const git = (...args) => execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
9
+ const again = deployAgain(options);
10
+ let status, sha;
11
+ try { status = git('status', '--porcelain', '-z', '--untracked-files=no'); sha = git('rev-parse', 'HEAD').trim(); }
12
+ catch { throw refuse(`rer deploy publishes the checkout's last Git commit, and this checkout has none. Commit the source with Git, then run ${again} again. Nothing was uploaded.`); }
13
+ const entries = status.split('\0'), paths = [];
14
+ for (let index = 0; index < entries.length; index++) {
15
+ if (!entries[index]) continue;
16
+ paths.push(entries[index].slice(3));
17
+ // A rename or copy is followed by its original path.
18
+ if (/^([RC].|.[RC])/.test(entries[index])) index++;
19
+ }
20
+ if (!paths.length) return sha;
21
+ const shown = paths.slice(0, 20).map(path => ` ${path}`);
22
+ if (paths.length > shown.length) shown.push(` and ${paths.length - shown.length} more`);
23
+ throw refuse(`Deploy stopped before building: these tracked files have changes that are not committed:\n${shown.join('\n')}\nrer deploy publishes the last commit. Commit the changes (for example git commit -am "Describe the change") or discard them, then run ${again} again. Nothing was uploaded.`);
24
+ }
package/cli/deploy.mjs CHANGED
@@ -9,6 +9,8 @@ import { refuseLocalModels } from '../modules/deploy-kit/local-only.mjs';
9
9
  import { deployEnvironment, deployAgain } from './deploy-inputs.mjs';
10
10
  import { claimHostedOwner } from './deploy-owner.mjs';
11
11
  import { mutationReadinessFailure } from './deploy-readiness.mjs';
12
+ import { committedSource } from './deploy-source.mjs';
13
+ import { hookState, forgetHookState } from './deploy-hook-record.mjs';
12
14
 
13
15
  export function ownerDeploy(declarationPath, lifecycle) {
14
16
  // rer verify serves the build with this declaration's vars and secrets.
@@ -28,6 +30,7 @@ export function ownerDeploy(declarationPath, lifecycle) {
28
30
  // A dry run reads the settings file too, so a refused key fails here and not only on the real deploy.
29
31
  if (options.dryRun && options.envFile) await deployEnvironment({ root, options, declaration, localOnlyKeys });
30
32
  if (!change.length) {
33
+ if (!options.dryRun) committedSource(root, options);
31
34
  await lifecycle.run(root, {}, store, () => {}, signal, { verb: 'build', operationToken });
32
35
  await checkBuild();
33
36
  }
@@ -56,7 +59,10 @@ export function ownerDeploy(declarationPath, lifecycle) {
56
59
  try {
57
60
  if (options.remove) {
58
61
  step = 'remove';
59
- const result = await owner('remove');
62
+ // A custom hook's own state file, when its deploy named one.
63
+ const state = await hookState(root, environment);
64
+ const result = await owner('remove', state ? ['--state', state] : []);
65
+ await forgetHookState(root, environment);
60
66
  store.report(`Removed ${result.removed.join(', ') || 'nothing (already gone)'}; read back: none of them remains.`);
61
67
  return { removed: result.removed, deployed: false };
62
68
  }
package/cli/inspect.mjs CHANGED
@@ -3,7 +3,7 @@ import { inventory } from './export.mjs';
3
3
  import { lstat, readFile } from 'node:fs/promises';
4
4
  import { createHash } from 'node:crypto';
5
5
  import { delimiter, dirname, resolve } from 'node:path';
6
- import { aliases, pins, requiredHooks, serverDefaults, verbs, releaseFlags } from './contract.mjs';
6
+ import { aliases, demoVerb, pins, requiredHooks, serverDefaults, verbs, releaseFlags } from './contract.mjs';
7
7
  import { runningVersion } from './version.mjs';
8
8
  import { contained, readPackage } from './project.mjs';
9
9
  import { shared } from './shared.mjs';
@@ -41,7 +41,7 @@ export async function describe(project) {
41
41
  ? operationsEffects
42
42
  : verbs[verb]?.effects ?? 'Produce releases; keygen writes a public anchor and, on success, its private key to non-terminal stdout; sign writes a detached signature and prints (but does not execute) the GitHub upload command; receipt verifies against local anchors offline.';
43
43
  return [verb, { flags: (verbs[verb]?.flags ?? releaseFlags).filter(flag => capability.flags?.includes(flag)), effects }];
44
- })),
44
+ }).concat(capabilities.dev?.flags?.includes('--demo') ? [['demo', { flags: demoVerb.flags.filter(flag => capabilities.dev.flags.includes(flag)), effects: demoVerb.effects }]] : [])),
45
45
  aliases: Object.fromEntries(Object.entries(aliases).filter(([alias, verb]) => pkg.scripts?.[alias] === commandLine(verb, declaredPackage(pkg) !== undefined))),
46
46
  local: { state: project.adapter?.state, settings: project.adapter?.settings ?? [], installerState: '.seed/installer', outbox: '/__dev/outbox', ...await localState(project), origin: await savedOrigin(project), ...(project.adapter?.devIdentity ? { devIdentity: true, devKey: '.rer/local/dev-key.env' } : {}) },
47
47
  // This pin serves a checkout through the machine's front door (rer door).
package/cli/lifecycle.mjs CHANGED
@@ -59,6 +59,7 @@ async function runLifecycle(project, options, out, deployRedaction) {
59
59
  if (options.verb !== 'outbox' && !options.site) try { operation = await localOperation(project.root, process.env.RER_LOCAL_OPERATION); } catch (error) { throw refuse(error.message); }
60
60
  const { recoverInterrupted } = await shared('local/recovery.mjs');
61
61
  if (operation) await recoverInterrupted(project.root, operation);
62
+ if (project.ownerReplacement) await replaceOwner(project, options, out);
62
63
  }
63
64
  const { createCommands } = await shared('commands.mjs');
64
65
  const { privateDirectory } = await shared('private-files.mjs');
@@ -178,6 +179,20 @@ async function runningRecord(root) {
178
179
  return (state.running ?? []).find(record => record.checkout === checkout);
179
180
  }
180
181
 
182
+ // Under the local operation, before the app starts: the zero-setup owner's
183
+ // row and saved owner setting become the real owner's, and one line says so.
184
+ async function replaceOwner(project, options, out) {
185
+ const { from, to } = project.ownerReplacement, { replaceLocalOwner } = await shared('local/owner.mjs');
186
+ await replaceLocalOwner(project.root, from, to, message => refuse(message));
187
+ const secrets = project.adapter.hooks?.secrets, key = localSettingKeys(project).email;
188
+ if (secrets) {
189
+ const { readSettings, replaceSavedSetting } = await shared('adapter-settings.mjs');
190
+ if ((await readSettings(project.root, secrets)).values[key]?.toLowerCase() === from.toLowerCase()) await replaceSavedSetting(project.root, secrets, key, to);
191
+ }
192
+ if (options.json) out.event('owner-replaced', { from, to });
193
+ else out.human(`Replacing the zero-setup local owner ${from} with ${to}. Local data is kept.`);
194
+ }
195
+
181
196
  // One plain line saying which port this checkout uses, and what moved.
182
197
  function announcePort(out, options, selected) {
183
198
  if (selected.door) { if (options.json) out.event('origin', { url: selected.url, door: true }); else out.human(`Using ${selected.url} for this checkout, served through the front door.`); return; }
@@ -3,15 +3,22 @@ import { shared } from './shared.mjs';
3
3
 
4
4
  // A version check owns its descendants just like a lifecycle command. Cleanup
5
5
  // starts at leader exit, even when quiet descendants still hold the pipes.
6
- // The package manager never sees the caller's credentials.
7
- export async function probePnpm(root, store, signal, env = process.env) {
6
+ // The package manager never sees the caller's credentials. A failed probe's
7
+ // error carries `reason`: what pnpm did instead of printing its version.
8
+ export async function probePnpm(root, store, signal, env = process.env, timeoutMs = 10000) {
8
9
  const { dependencyEnvironment } = await shared('dependency-environment.mjs');
9
- const probeSignal = AbortSignal.any([signal, AbortSignal.timeout(10000)].filter(Boolean));
10
+ const timeout = AbortSignal.timeout(timeoutMs), probeSignal = AbortSignal.any([signal, timeout].filter(Boolean));
10
11
  const child = store.spawn('Checking pinned pnpm', 'pnpm', ['--version'], { cwd: root, env: dependencyEnvironment(env), signal: probeSignal });
11
- let version = '';
12
+ let version = '', errors = '';
12
13
  child.stdout.on('data', chunk => { version = (version + chunk).slice(-1024); });
13
- const code = await new Promise(resolve => { child.once('error', () => resolve(null)); child.once('exit', code => resolve(code)); });
14
+ child.stderr.on('data', chunk => { errors = (errors + chunk).slice(0, 4096); });
15
+ const { code, exitSignal, error } = await new Promise(resolve => { child.once('error', error => resolve({ code: null, error })); child.once('exit', (code, exitSignal) => resolve({ code, exitSignal })); });
14
16
  await store.stop(child);
15
- if (probeSignal.aborted || code !== 0) throw missing('The pinned pnpm version probe failed. Select the documented tool.');
16
- return version.trim();
17
+ if (code === 0 && !probeSignal.aborted) return version.trim();
18
+ const line = (store.redact?.(errors) ?? errors).split('\n').map(text => text.trim()).find(Boolean)?.slice(0, 200);
19
+ const reason = timeout.aborted ? `pnpm --version gave no answer within ${timeoutMs / 1000} s`
20
+ : error ? `pnpm could not start (${error.code ?? error.message})`
21
+ : code === null ? `pnpm --version was stopped by ${exitSignal}`
22
+ : `pnpm --version exited ${code}${line ? `: ${line}` : ''}`;
23
+ throw Object.assign(missing(`The pinned pnpm version probe failed (${reason}). Select the documented tool.`), { reason });
17
24
  }
@@ -3,6 +3,7 @@
3
3
  import { mkdtemp, readFile, rm } from 'node:fs/promises';
4
4
  import { delimiter, dirname, join } from 'node:path';
5
5
  import { homedir, tmpdir } from 'node:os';
6
+ import { setTimeout as delay } from 'node:timers/promises';
6
7
  import { cachedPnpm, downloadPnpm } from './pnpm-runtime.mjs';
7
8
  import { missing, RerError } from './errors.mjs';
8
9
  import { shellQuote } from './node-runtime-cache.mjs';
@@ -16,9 +17,9 @@ export async function projectPnpmPin(root) {
16
17
  if (!pin) throw missing('This first-party checkout must declare an exact pnpm version in package.json packageManager. Correct that declaration, then rerun rer.');
17
18
  return pin;
18
19
  }
19
- async function probe(root, env, signal, store) {
20
- try { return await probePnpm(root, store, signal, env); }
21
- catch (error) { if (signal?.aborted) throw error; return undefined; }
20
+ async function probe(root, env, signal, store, timeoutMs) {
21
+ try { return { version: await probePnpm(root, store, signal, env, timeoutMs) }; }
22
+ catch (error) { if (signal?.aborted) throw error; return { reason: error.reason ?? error.message }; }
22
23
  }
23
24
  export async function ensureProjectPnpm(root, options = {}) {
24
25
  if (options.store) return ensure(root, options);
@@ -46,7 +47,7 @@ export async function ensureProjectPnpm(root, options = {}) {
46
47
  }
47
48
  async function ensure(root, { env = process.env, signal, report = () => {}, store }, pin) {
48
49
  pin ??= await projectPnpmPin(root);
49
- if (await probe(root, env, signal, store) === pin) return env;
50
+ if ((await probe(root, env, signal, store)).version === pin) return env;
50
51
  let directory = await cachedPnpm(pin, env);
51
52
  if (!directory) {
52
53
  report(`Fetching pnpm ${pin} for this project; rer keeps it in its own cache.`);
@@ -61,7 +62,14 @@ async function ensure(root, { env = process.env, signal, report = () => {}, stor
61
62
  // this process's Node before the caller's PATH, but cannot be shadowed by a
62
63
  // different pnpm installed in that Node's bin directory.
63
64
  const supplied = { ...env, PATH: [directory, dirname(process.execPath), env.PATH].filter(Boolean).join(delimiter) };
64
- if (await probe(root, supplied, signal, store) !== pin) throw missing(`The verified pnpm ${pin} did not report the project version. Run ${shellQuote(join(directory, 'pnpm'))} --version to inspect it, then rerun rer.`);
65
- Object.assign(env, supplied);
66
- return env;
65
+ // A fresh pnpm's first run can stall or fail once (a cold start on a busy
66
+ // machine): the check settles with a bounded retry, then names what failed.
67
+ let result;
68
+ for (const [attempt, timeoutMs] of [10000, 20000, 30000].entries()) {
69
+ if (attempt) await delay(1000, undefined, { signal });
70
+ result = await probe(root, supplied, signal, store, timeoutMs);
71
+ if (result.version === pin) { Object.assign(env, supplied); return env; }
72
+ }
73
+ const failed = result.version === undefined ? result.reason : `it reported ${JSON.stringify(result.version.slice(0, 64))}`;
74
+ throw missing(`The verified pnpm ${pin} did not report the project version after 3 tries (${failed}). Run ${shellQuote(join(directory, 'pnpm'))} --version to inspect it, then rerun rer.`);
67
75
  }
@@ -1,5 +1,5 @@
1
1
  import {randomBytes} from 'node:crypto';
2
- import {readFile} from 'node:fs/promises';
2
+ import {readFile,realpath} from 'node:fs/promises';
3
3
  import {createInterface} from 'node:readline/promises';
4
4
  import {Writable} from 'node:stream';
5
5
  import {contained} from './project.mjs';
@@ -82,10 +82,12 @@ export async function setupInput(project, options, vars, signal, { origin } = {}
82
82
  }
83
83
  if(!mailbox(answers[names.email]))throw invalid('Provide a valid plain owner mailbox.');
84
84
  answers[names.email]=answers[names.email].toLowerCase();
85
- const {assertLocalOwner}=await shared('local/owner.mjs');
86
- const owners=await assertLocalOwner(project.root,answers[names.email],message=>refuse(message),project.adapter.hooks?.localOwner,`${names.email} in ${project.adapter.hooks?.secrets?.file??'.dev.vars'}`);
85
+ const {assertLocalOwner,zeroSetupOwner}=await shared('local/owner.mjs');
86
+ const {owners,placeholder}=await assertLocalOwner(project.root,answers[names.email],message=>refuse(message),project.adapter.hooks?.localOwner,`${names.email} in ${project.adapter.hooks?.secrets?.file??'.dev.vars'}`);
87
+ // The zero-setup owner gives way to the real one; lifecycle renames it in place.
88
+ if(placeholder&&placeholder.toLowerCase()!==answers[names.email])project.ownerReplacement={from:placeholder,to:answers[names.email]};
87
89
  if(savedEmail&&!mailbox(savedEmail))throw refuse('Saved owner is malformed. Restore private settings or run rer reset --yes.');
88
- if(savedEmail&&savedEmail.toLowerCase()!==answers[names.email]){
90
+ if(savedEmail&&savedEmail.toLowerCase()!==answers[names.email]&&(owners.length?!placeholder:savedEmail.toLowerCase()!==zeroSetupOwner(await realpath(project.root)))){
89
91
  if(owners.length)throw refuse(`Private setting ${names.email} differs from the retained database owner. Restore ${names.email} in ${project.adapter.hooks?.secrets?.file??'.dev.vars'} to ${answers[names.email]}, then run rer setup --owner-email ${answers[names.email]}; or back up data and run rer reset --yes. Private bytes were kept.`);
90
92
  throw refuse(`Owner conflicts with the saved installation (${savedEmail}). Run rer setup --owner-email ${savedEmail}, or back up data, run rer dev --stop, then rer reset --yes followed by rer setup --owner-email ${answers[names.email]}. Reset deletes local data.`);
91
93
  }
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.6
4
+
5
+ - A job-queue client no longer crashes with an unhandled `write EPIPE` when a process probing its identity or policy socket closes before the answer is written (a probe that timed out under load); the prober reports its own timeout or reset. This stopped Orbit's release producer twice.
6
+ - `rer setup --owner-email YOU` (or `--answers`) on a checkout whose local owner is still the `owner@<checkout>.test` that the zero-setup `rer dev` created replaces that owner with you in place: the same account under your address, all local data kept, and one line saying so. A database that holds any other owner is still refused, as before.
7
+ - An untouched repeat `rer deploy` after the hosted owner was claimed writes nothing: retiring the setup token no longer changes the build fingerprint (so the Worker is not uploaded again), and the recorded claim stays `claimed`.
8
+ - The pinned pnpm check settles with a bounded retry: a fresh pnpm's version check is tried up to three times (10, 20 and 30 seconds), and if it still fails, rer says what pnpm did: no answer in time, could not start, its exit code and first error line, or the version it reported. The first `rer import` on a fresh clone no longer stops there when the same command succeeds on retry.
9
+ - A provider call Cloudflare refuses carries the call and Cloudflare's own error codes and messages (account id and token removed, each message cut to 300 characters); `rer deploy` names them when a custom deploy hook fails on one, instead of only `provider-http-400`.
10
+ - `rer deploy --remove --yes` removes what a custom deploy hook deployed under its own kit state file when the hook returned that file as `state`, and reads every resource back gone.
11
+
12
+ ### Upgrade notes
13
+
14
+ - A custom deploy hook that keeps its own kit state file returns it as `state` in its result (the kit's `deploy` result names it as `state`), so `rer deploy --remove --yes` can find what it deployed.
15
+ - A deployment that an earlier rer redeployed after its owner claim uploads its Worker once more on the next `rer deploy` (the fingerprint again names the retired setup token); repeats after that write nothing.
16
+
17
+ ## 0.2.5
18
+
19
+ - `rer deploy` with a seed's own deploy hook claims the hosted owner from what the hook returns, `{ deployed: true, origin }`, once the origin's `/health` names the checkout's commit, and prints the sign-in address. A hook that keeps its own deployment record (Penny's does) no longer ends in `missing-owner-receipt` with a live, unclaimed app; such a hook returns `setupToken` too when its Worker holds a setup token other than the `SETUP_TOKEN` rer passed it. A hook that reports no deployment, or whose app never names the commit, fails saying so and claims nothing.
20
+ - `rer deploy` with uncommitted changes to tracked files stops before building, lists the files, says to commit them and that nothing was uploaded (exit 4), instead of building first and failing with `owner-source-not-committed`.
21
+ - `rer deploy --demo --dry-run` and `rer build --platform container` work on an exported seed: the container import boundary admits the demo guard's `import { env } from 'cloudflare:workers'` in `src/modules/demo/index.mjs` (that file and that import only) and still refuses a Cloudflare import anywhere else in `src/`. The release smoke now runs the hosted demo dry run on a package-mode export.
22
+ - `rer describe` lists `demo` as a verb (`rer dev --demo`), with its effects and the flags a demo takes.
23
+ - Two launches claiming the same port, or two workers claiming the same checkout's launch, get exactly one winner: the claim is written complete and linked into place, so the other never reads it half-written and takes it as abandoned.
24
+ - `node scripts/export-cli.mjs --to-package` on a composed foundation drops the removed `scripts/base-cli` copy's entries from `composition.lock.json` along with its files, so `rer check` no longer fails `SC-05.auth-copy` for files the conversion deleted.
25
+ - `rer deploy` refuses a seed deploy hook's `http://` origin (other than a loopback host such as `localhost`, `127.0.0.1` or `[::1]`) before sending it anything, so the one-time setup token only travels over https; it says to make the hook return its https origin.
26
+ - After a redeploy whose app answers unhealthy, the owner state in `.rer/deploy/` keeps each health check's status and timing but not the response text, so a secret an app echoes is never saved there; the secret command already kept none.
27
+ - A secret change `rer deploy` could not yet confirm stays recorded until the provider's records agree, and blocks another secret change, deploy or removal until then; a secret added or removed outside rer meanwhile is refused instead of adopted.
28
+
29
+ ### Upgrade notes
30
+
31
+ - A seed's custom deploy hook returns `{ deployed: true, origin }` with an https origin (and may add `setupToken`); `rer deploy` waits for that origin's `/health` to name the checkout's commit, then claims the owner itself.
32
+ - A seed adopting `rer demo` needs rer 0.2.5 for `rer deploy --demo`.
33
+
3
34
  ## 0.2.4
4
35
 
5
36
  0.2.3 was tagged but not published; its changes are in 0.2.4.
package/global/README.md CHANGED
@@ -104,6 +104,9 @@ A seed that declares a run site prints one more line after those,
104
104
  `RER_SITE http://127.0.0.1:8788`: a local preview of its static run site (its
105
105
  marketing homepage, `/run` and docs) on the first free port above the app's. It
106
106
  stops with the app.
107
+ Later, `rer setup --owner-email YOU` (or `--answers`) with the real owner
108
+ replaces that local owner in place and keeps all local data, saying so in one
109
+ line; a checkout whose database holds any other owner is still refused.
107
110
  It never prompts and never re-runs setup on a checkout that is already set up. A
108
111
  setup a launch started that was stopped or failed is run again by the next
109
112
  `rer dev`, keeping the owner and origin it saved, unless a setup has finished
@@ -2,7 +2,7 @@
2
2
  import { execFile } from 'node:child_process';
3
3
  import { stat } from 'node:fs/promises';
4
4
  import { createServer } from 'node:net';
5
- import { basename, join } from 'node:path';
5
+ import { join } from 'node:path';
6
6
  import { promisify } from 'node:util';
7
7
  import { listeningPorts } from '../../onboarding/process-diagnostics.mjs';
8
8
  import { LaunchFailure } from './failure.mjs';
@@ -64,11 +64,6 @@ export async function setupNeeded(root, described, last) {
64
64
  return await finishedSince(root, described, last.at) ? undefined : 'resume';
65
65
  }
66
66
 
67
- export function localOwner(root) {
68
- const label = basename(root).toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 63) || 'checkout';
69
- return `owner@${label}.test`;
70
- }
71
-
72
67
  async function bindable(host, port) {
73
68
  const socket = createServer();
74
69
  try { await new Promise((resolve, reject) => { socket.once('error', reject); socket.listen({ port, host, exclusive: true }, resolve); }); return true; }
@@ -10,7 +10,8 @@ import { liveServers } from '../registry.mjs';
10
10
  import { checkCapacity, personEnvironment, pinPolicy } from './capacity.mjs';
11
11
  import { bringBackDoor, doorPlan } from './door.mjs';
12
12
  import { LaunchFailure } from './failure.mjs';
13
- import { describeCheckout, freePort, localOwner, needsInstall, portTaken, setupNeeded } from './facts.mjs';
13
+ import { describeCheckout, freePort, needsInstall, portTaken, setupNeeded } from './facts.mjs';
14
+ import { zeroSetupOwner } from '../../onboarding/local/owner.mjs';
14
15
  import { claimPort, installState, savedPorts, setupState } from './state.mjs';
15
16
  import { runVerb } from './steps.mjs';
16
17
  import { localDefaults } from './local-defaults.mjs';
@@ -67,7 +68,7 @@ export async function prepare({ root, args, env, report, directory, log, childre
67
68
  await step(setupState, ['setup', ...hostArgs], {}, setupEnv);
68
69
  } else if (setup === 'fresh' && plan.freshAtDoor) {
69
70
  // With the door enabled, a fresh checkout is set up at its door origin.
70
- const owner = localOwner(checkout);
71
+ const owner = zeroSetupOwner(checkout);
71
72
  report({ phase: 'setup', message: `setting up a local owner (${owner}) at its front-door address` });
72
73
  await step(setupState, ['setup', '--owner-email', owner, '--door'], { owner, door: true }, setupEnv);
73
74
  await bringBackDoor({ ...plan, atDoor: true }, env, report);
@@ -76,7 +77,7 @@ export async function prepare({ root, args, env, report, directory, log, childre
76
77
  // An interrupted setup resumes on the port it chose while that port is free.
77
78
  // A port another process takes between choosing it and setup refusing it is
78
79
  // passed over for the next free one; a port the person passed is kept.
79
- const owner = localOwner(checkout), explicit = flagValue(args, '--port');
80
+ const owner = zeroSetupOwner(checkout), explicit = flagValue(args, '--port');
80
81
  let from = last?.port;
81
82
  for (let attempt = 1; ; attempt++) {
82
83
  const held = explicit ? [] : [...(await liveServers(childEnv)).map(record => record.port), ...await savedPorts(checkout, childEnv)];