@runeditrun/rer 0.2.122 → 0.2.124

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 (76) hide show
  1. package/cli/README.md +8 -0
  2. package/cli/bounded.mjs +3 -3
  3. package/cli/business/agent-output.mjs +4 -2
  4. package/cli/business/agent-verbs.mjs +10 -4
  5. package/cli/business/api.mjs +12 -9
  6. package/cli/business/carry.mjs +3 -2
  7. package/cli/business/choices.mjs +4 -1
  8. package/cli/business/connect.mjs +2 -1
  9. package/cli/business/local-commands.mjs +4 -1
  10. package/cli/business/mcp-bridge.mjs +7 -2
  11. package/cli/business/questions.mjs +5 -4
  12. package/cli/business/refusal.mjs +47 -0
  13. package/cli/business/run-grant.mjs +15 -16
  14. package/cli/business/setup-command.mjs +7 -2
  15. package/cli/business/supervisor.mjs +4 -1
  16. package/cli/deploy.mjs +2 -1
  17. package/cli/dev-identity.mjs +7 -0
  18. package/cli/errors.mjs +45 -9
  19. package/cli/export.mjs +1 -0
  20. package/cli/inspect.mjs +2 -0
  21. package/cli/main.mjs +17 -3
  22. package/cli/managed-server.mjs +8 -4
  23. package/cli/portability-empty.mjs +4 -2
  24. package/cli/portability-evidence.mjs +9 -1
  25. package/cli/portability-migrations.mjs +30 -8
  26. package/cli/portability-owners.mjs +54 -0
  27. package/cli/portability-worker.mjs +13 -5
  28. package/cli/portability.mjs +6 -4
  29. package/cli/render-warmup.mjs +31 -0
  30. package/cli/setup-input.mjs +14 -2
  31. package/cli/site-private.mjs +9 -1
  32. package/cli/site.mjs +5 -5
  33. package/edition-authoring/cli.mjs +3 -0
  34. package/edition-authoring/project-hashes.mjs +58 -0
  35. package/global/CHANGELOG.md +45 -0
  36. package/global/launch/dev.mjs +2 -2
  37. package/global/launch/render.mjs +12 -1
  38. package/global/launch/state.mjs +11 -4
  39. package/global/launch/worker.mjs +22 -5
  40. package/modules/deploy-kit/owner-cli.mjs +5 -2
  41. package/modules/deploy-kit/owner-remove.mjs +23 -5
  42. package/modules/job-queue/identity.mjs +11 -6
  43. package/modules/job-queue/policy.mjs +16 -2
  44. package/modules/operator-auth/README.md +6 -0
  45. package/modules/operator-auth/accounts/oa.mjs +1 -1
  46. package/modules/operator-auth/dev/index.mjs +32 -14
  47. package/modules/operator-auth/dev/persona-entry.mjs +38 -0
  48. package/modules/operator-auth/dev/persona-grant.mjs +16 -0
  49. package/modules/operator-auth/dev-admission.d.mts +2 -2
  50. package/modules/operator-auth/dev-admission.mjs +2 -2
  51. package/modules/operator-auth/dev-gate-script.mjs +28 -0
  52. package/modules/operator-auth/dev-gate.mjs +7 -10
  53. package/modules/portability/README.md +7 -2
  54. package/modules/portability/bridge.mjs +25 -23
  55. package/modules/portability/checkout-history.mjs +7 -6
  56. package/modules/portability/export.mjs +6 -3
  57. package/modules/portability/format.mjs +2 -2
  58. package/modules/portability/http-errors.mjs +1 -1
  59. package/modules/portability/http.mjs +2 -2
  60. package/modules/portability/import.mjs +13 -11
  61. package/modules/portability/index.d.mts +4 -2
  62. package/modules/portability/index.mjs +2 -2
  63. package/modules/portability/ledgers.mjs +16 -3
  64. package/modules/portability/legacy-files.mjs +3 -3
  65. package/modules/portability/migration-history.mjs +4 -3
  66. package/modules/portability/owner-history.mjs +62 -0
  67. package/modules/portability/worker-history.d.mts +1 -0
  68. package/modules/portability/worker-history.mjs +4 -4
  69. package/modules/release/README.md +7 -0
  70. package/modules/release/produce.mjs +3 -0
  71. package/onboarding/adapter.mjs +9 -9
  72. package/onboarding/commands.mjs +15 -5
  73. package/onboarding/operator-installer.mjs +2 -2
  74. package/onboarding/operator-settings.mjs +10 -8
  75. package/onboarding/redaction.mjs +1 -1
  76. package/package.json +1 -1
@@ -75,7 +75,7 @@ export function localInstaller(hooks = {}) {
75
75
  catch (error) {
76
76
  if (verb !== 'dev' || signal?.aborted || isBusyFailure(error)) throw error;
77
77
  const failure = approvedFailure(error);
78
- throw commandFailure(`${store.redact(failure?.message ?? error.message)}\nLocal migrations failed. Fix the error and run ~/.local/bin/rer setup before trying again.`, failure ?? {});
78
+ throw Object.assign(commandFailure(`${store.redact(failure?.message ?? error.message)}\nLocal migrations failed. Fix the error and run ~/.local/bin/rer setup before trying again.`, failure ?? {}), {cause:error});
79
79
  }
80
80
  }
81
81
  await options.beforeStart?.(context);
@@ -126,7 +126,7 @@ function createContext(root, input, store, onApp, signal, guard) {
126
126
  if (guard) await guard(context);
127
127
  try { return await store.run(label, command, args, { cwd: root, signal, ...options }); } catch (error) {
128
128
  if (signal?.aborted || options.signal?.aborted || isBusyFailure(error)) throw error;
129
- throw installationFailure('command_failed', { step, diagnostic: error });
129
+ throw Object.assign(installationFailure('command_failed', { step, diagnostic: error }), {cause:error});
130
130
  }
131
131
  },
132
132
  fail(step) { return installationFailure('command_failed', { step }); },
@@ -213,7 +213,7 @@ async function start(context, hooks) {
213
213
  let child;
214
214
  try { child = store.spawn(labels.start, command, args, { cwd: context.root, signal, ...spawnOptions }); } catch (error) {
215
215
  if (signal?.aborted) throw error;
216
- throw installationFailure('command_failed', { step: 'start', diagnostic: error });
216
+ throw Object.assign(installationFailure('command_failed', { step: 'start', diagnostic: error }), {cause:error});
217
217
  }
218
218
  let announcement,detectedMismatch;
219
219
  // Keep context after the number: conservative redaction treats a trailing
@@ -231,7 +231,7 @@ async function start(context, hooks) {
231
231
  const readinessLabel=runtimePortHandshake?`${labels.start} (waiting for the bound internal listener)`:`${labels.start} (expected internal port ${expectedPort})`;
232
232
  const ownedPorts=async()=>{
233
233
  try{return await listenerPorts(child.pid);}
234
- catch(error){throw installationFailure('command_failed',{step:'start',diagnostic:error});}
234
+ catch(error){throw Object.assign(installationFailure('command_failed',{step:'start',diagnostic:error}),{cause:error});}
235
235
  };
236
236
  // A seed can use the managed IPC handshake without developmentTarget's
237
237
  // options (Uptime does). Give that real listener/health journey the same
@@ -275,11 +275,11 @@ async function start(context, hooks) {
275
275
  }, { signal, timeoutMs: readinessTimeoutMs, ...(softAfterMs ? { softAfterMs } : {}), ...(intervalMs ? { intervalMs } : {}) });
276
276
  } catch (error) {
277
277
  if (signal?.aborted) throw error;
278
- if(detectedMismatch)throw installationFailure('command_failed',{step:'start',diagnostic:error});
278
+ if(detectedMismatch)throw Object.assign(installationFailure('command_failed',{step:'start',diagnostic:error}),{cause:error});
279
279
  if(runtimePortHandshake&&!announcement){
280
280
  const prior=approvedFailure(error);
281
281
  const message=`No managed listener was announced after ${Math.round(performance.now()-readinessStarted)} ms (allowed ${readinessTimeoutMs} ms). Check the runtime startup output in the log below, correct the startup error, then run ~/.local/bin/rer ${context.verb??'setup'} again.`;
282
- throw installationFailure('command_failed',{step:'start',diagnostic:commandFailure(`${message}\n${prior?.message??readinessLabel}`,prior??{})});
282
+ throw Object.assign(installationFailure('command_failed',{step:'start',diagnostic:commandFailure(`${message}\n${prior?.message??readinessLabel}`,prior??{})}),{cause:error});
283
283
  }
284
284
  const ports=await ownedPorts();
285
285
  if(ports.length){
@@ -287,9 +287,9 @@ async function start(context, hooks) {
287
287
  try { diagnosis=await startOriginDiagnostic(context,hooks,child,health,ready); }
288
288
  catch (diagnosticError) { if(signal?.aborted)throw diagnosticError; }
289
289
  const message=store.redact(diagnosis??`Application listened on port ${ports.join(', ')}; readiness failed for GET ${url} through expected internal port ${expectedPort}. Check application health and the runtime target's port binding.`);
290
- store.report(message);const prior=approvedFailure(error);error=commandFailure(`${prior?.message??readinessLabel}\n${message}`,prior??{});
290
+ store.report(message);const prior=approvedFailure(error);error=Object.assign(commandFailure(`${prior?.message??readinessLabel}\n${message}`,prior??{}),{cause:error});
291
291
  }
292
- throw installationFailure('command_failed', { step: 'start', diagnostic: error });
292
+ throw Object.assign(installationFailure('command_failed', { step: 'start', diagnostic: error }), {cause:error});
293
293
  } finally { child.removeListener('message',announced); }
294
294
  // Another app can take the loopback port between the port check and the bind;
295
295
  // its /health would pass. Claim and sign in only against the process this
@@ -298,7 +298,7 @@ async function start(context, hooks) {
298
298
  try { ownership=await listenerOwnership(child.pid,expectedPort,context.runtimePort?'127.0.0.1':new URL(url).hostname,inspectionContext({port:expectedPort,verb:context.verb??'setup',signal})); }
299
299
  catch(error){
300
300
  if (signal?.aborted) throw error;
301
- throw installationFailure('command_failed',{step:'start',diagnostic:error});
301
+ throw Object.assign(installationFailure('command_failed',{step:'start',diagnostic:error}),{cause:error});
302
302
  }
303
303
  if (ownership.status !== 'owned') {
304
304
  const message = (store.redact??(value=>value))(ownership.status==='other'
@@ -15,9 +15,12 @@ import { isWranglerMigrationApply, wranglerMigrationView } from './migration-pro
15
15
  import { isWranglerQuery, wranglerQueryView, viteDiagnosticsView, archiveReceiptView } from './command-diagnostics-view.mjs';
16
16
 
17
17
  export async function createCommands(directory,state,{terminal=text=>writeSync(1,text),spawn=spawnChild,queue:queuePolicy,custodyToken,onWaiting,filterViteWarnings=false,filterArchiveReceipts=false}={}) {
18
- let policy=queuePolicy?await commandPolicy():{environment:{},close:async()=>{}};
19
18
  const custodyBaseline=['darwin','linux'].includes(process.platform)?await createProcessBaseline():undefined;
20
19
  const logPath=join(directory,'install.log'), log=await openPrivateLog(logPath);
20
+ let policy=queuePolicy?await commandPolicy().catch(async error=>{
21
+ await log.close().catch(()=>{});
22
+ throw error;
23
+ }):{environment:{},close:async()=>{}};
21
24
  const redaction=createRedaction();redaction.addSecrets(credentialValues(process.env));
22
25
  const registerCustody=environment=>{
23
26
  const secrets=[];
@@ -69,7 +72,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
69
72
  const lines=(capture?.snapshot()||'').split('\n');if(lines.at(-1)==='')lines.pop();
70
73
  // The step, its command, exit code, last output and log, for callers that name a failed step.
71
74
  const step=stepDiagnostic({name:redaction.redact(String(label)),command:capture?.display,exitCode:detail.code,signal:detail.signal,output:lines,log:redaction.redact(checkoutPath(capture?.cwd,logPath))});
72
- return Object.assign(commandFailure(`${redaction.redact(String(label))}: ${status}.${detail.lastHealth?` Last health: ${redaction.redact(String(detail.lastHealth))}.`:''}\nCommand: ${capture?.display ?? '(none: the step failed inside rer)'}\nLast output (up to 40 lines):\n${lines.length?lines.slice(-40).join('\n'):'(no output)'}\nLog: ${redaction.redact(logPath)}`,{childExitCode:detail.code,signal:detail.signal,step}),{childExitCode:detail.code,signal:detail.signal});
75
+ return Object.assign(commandFailure(`${redaction.redact(String(label))}: ${status}.${detail.lastHealth?` Last health: ${redaction.redact(String(detail.lastHealth))}.`:''}\nCommand: ${capture?.display ?? '(none: the step failed inside rer)'}\nLast output (up to 40 lines):\n${lines.length?lines.slice(-40).join('\n'):'(no output)'}\nLog: ${redaction.redact(logPath)}`,{childExitCode:detail.code,signal:detail.signal,step}),{childExitCode:detail.code,signal:detail.signal,...(capture?.cause ? {cause:capture.cause} : {})});
73
76
  };
74
77
  const track=(label,child,ownershipScope,view)=>{
75
78
  if(captures.has(child))return child;
@@ -87,7 +90,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
87
90
  const sources=[child.stdout,child.stderr].filter(Boolean),data=chunk=>filter.write(chunk);
88
91
  for(const source of sources)source.on('data',data);
89
92
  let error,finished=false;
90
- child.once('error',cause=>{error=true;capture.errorCode=/^[A-Z_]{2,40}$/.test(cause?.code??'')?cause.code:undefined;resolveError({error:true,errorCode:capture.errorCode});});
93
+ child.once('error',cause=>{error=true;capture.cause=cause;capture.errorCode=/^[A-Z_]{2,40}$/.test(cause?.code??'')?cause.code:undefined;resolveError({error:true,errorCode:capture.errorCode});});
91
94
  const exited=(code,terminationSignal)=>{capture.exitResult={code,signal:terminationSignal,error,errorCode:capture.errorCode};resolveExit(capture.exitResult);};
92
95
  child.once('exit',exited);
93
96
  const finish=(code,terminationSignal)=>{
@@ -150,7 +153,14 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
150
153
  if(commandSignal?.aborted)throw failure(label,{reason:'cancel'});
151
154
  const ownershipScope=createProcessScope(custodyBaseline);redaction.addSecrets([ownershipScope.token,...inheritedScopeTokens(process.env),...inheritedScopeTokens(native.env)]);
152
155
  const [program,argv]=toolCommand(command,args,native.env??process.env);
153
- const child=spawn(program,argv,{...native,env:processScopeEnvironment(ownershipScope,{...(native.env??process.env),...policy.environment,...(custodyToken?{RER_ONBOARDING_PROCESS_OWNER:[...inheritedScopeTokens(native.env??process.env),custodyToken].join(',')}:{})}),shell:false,detached:process.platform!=='win32',stdio:[Array.isArray(native.stdio)?native.stdio[0]:'ignore','pipe','pipe',...(native.stdio?.includes('ipc')?['ipc']:[])]});
156
+ let child;
157
+ try { child=spawn(program,argv,{...native,env:processScopeEnvironment(ownershipScope,{...(native.env??process.env),...policy.environment,...(custodyToken?{RER_ONBOARDING_PROCESS_OWNER:[...inheritedScopeTokens(native.env??process.env),custodyToken].join(',')}:{})}),shell:false,detached:process.platform!=='win32',stdio:[Array.isArray(native.stdio)?native.stdio[0]:'ignore','pipe','pipe',...(native.stdio?.includes('ipc')?['ipc']:[])]}) }
158
+ catch (error) {
159
+ // Native synchronous spawn failures can omit their executable. Retain the
160
+ // original cause and executable, never argv, for the CLI diagnostic.
161
+ if (/^spawn(?: |$)/.test(error.syscall ?? '') && !error.path) error.path = program;
162
+ throw error;
163
+ }
154
164
  onChild?.(child);
155
165
  ownershipRecords.set(child,{pid:child.pid,token:ownershipScope.token});
156
166
  track(label,child,ownershipScope,view?.());
@@ -183,7 +193,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
183
193
  if(result?.timedOut)throw busyRefusal({...result,reason:redaction.redact(String(result.reason))},{verb:queuePolicy.verb,maxWait:queuePolicy.maxWait??maxWaitSeconds});
184
194
  if(result){if(result.code!==0)throw failure(label,result,captures.get(queuedChild));return result;}
185
195
  }
186
- let child;try{child=spawnCommand(label,command,args,options);}catch{throw failure(label,options.signal?.aborted||signal?.aborted?{reason:'cancel'}:{error:true},{display:redaction.redact(String(options.display??command)),cwd:options.cwd,snapshot:()=>''});}
196
+ let child;try{child=spawnCommand(label,command,args,options);}catch(error){throw failure(label,options.signal?.aborted||signal?.aborted?{reason:'cancel'}:{error:true},{cause:error,display:redaction.redact(String(options.display??command)),cwd:options.cwd,snapshot:()=>''});}
187
197
  const capture=captures.get(child);
188
198
  // Start cleanup at exit: inherited pipes can hold close open indefinitely.
189
199
  // Only run's bounded command ends here; spawn's app stays owned until stop.
@@ -3,7 +3,7 @@ import { privateDirectory } from './private-files.mjs';
3
3
  import { localInstaller } from './adapter.mjs';
4
4
  import { selectLocalState, LocalStateSafetyError } from './local/state.mjs';
5
5
  import {operatorPrerequisites} from './operator-prerequisites.mjs';
6
- import { localOperatorSettings, prepareOperatorMail, repairOperatorMail } from './operator-settings.mjs';
6
+ import { localOperatorMailProvider, localOperatorSettings, prepareOperatorMail, repairOperatorMail } from './operator-settings.mjs';
7
7
  import { migrateOperator } from './operator-migrations.mjs';
8
8
  import { installOperator } from './operator-install.mjs';
9
9
  import { join, delimiter } from 'node:path';
@@ -17,7 +17,7 @@ export function operatorInstaller({ database, features, prepare, prepareData })
17
17
  guard: async ({ root }) => { await selectLocalState(root); },
18
18
  secrets: {
19
19
  keepExisting: true, originKey: 'AUTH_ORIGIN', afterWrite: repairOperatorMail,
20
- values: ({ origin }) => ({ AUTH_LOCAL: 'true', AUTH_ORIGIN: origin, MAIL_PROVIDER: 'development', MAIL_FROM: 'auth@localhost.test' }),
20
+ values: ({ origin }) => ({ AUTH_LOCAL: 'true', AUTH_ORIGIN: origin, MAIL_PROVIDER: localOperatorMailProvider, MAIL_FROM: 'auth@localhost.test' }),
21
21
  },
22
22
  build: ['pnpm', ['run', '--silent', 'build:app']],
23
23
  migrate: context => migrateOperator(context, database),
@@ -2,9 +2,11 @@ import { readSettings, replaceSavedSetting } from './adapter-settings.mjs';
2
2
  import { commandFailure } from './failures.mjs';
3
3
  import { writePrivateFile } from './private-files.mjs';
4
4
 
5
+ export const localOperatorMailProvider = 'development';
6
+
5
7
  export function localOperatorSettings(vars) {
6
8
  if(vars.AUTH_LOCAL!=='true')return {field:'AUTH_LOCAL',found:JSON.stringify(vars.AUTH_LOCAL??'unset'),expected:'true'};
7
- if(vars.MAIL_PROVIDER!=='development')return {field:'MAIL_PROVIDER',found:JSON.stringify(vars.MAIL_PROVIDER??'unset'),expected:'development'};
9
+ if(vars.MAIL_PROVIDER!==localOperatorMailProvider)return {field:'MAIL_PROVIDER',found:JSON.stringify(vars.MAIL_PROVIDER??'unset'),expected:localOperatorMailProvider};
8
10
  if(!vars.SESSION_SECRET)return {field:'SESSION_SECRET',found:'unset',expected:'set'};
9
11
  }
10
12
 
@@ -12,17 +14,17 @@ export function localOperatorSettings(vars) {
12
14
  // shared local contract explicit, including when a seed offers hosted mail-off.
13
15
  export async function prepareOperatorMail({root,input}) {
14
16
  const saved=(await readSettings(root,{})).values;
15
- if(input.MAIL_PROVIDER!==undefined&&input.MAIL_PROVIDER!=='development'&&!saved.OWNER_EMAIL) {
16
- throw commandFailure(`Local prerequisite MAIL_PROVIDER: found ${JSON.stringify(input.MAIL_PROVIDER)}; expected development; run ~/.local/bin/rer setup with MAIL_PROVIDER=development in the --answers file.`,{});
17
+ if(input.MAIL_PROVIDER!==undefined&&input.MAIL_PROVIDER!==localOperatorMailProvider&&!saved.OWNER_EMAIL) {
18
+ throw commandFailure(`Local prerequisite MAIL_PROVIDER: found ${JSON.stringify(input.MAIL_PROVIDER)}; expected ${localOperatorMailProvider}; run ~/.local/bin/rer setup with MAIL_PROVIDER=${localOperatorMailProvider} in the --answers file.`,{});
17
19
  }
18
20
  }
19
21
 
20
22
  export async function repairOperatorMail(context) {
21
- if((context.verb&&!['installer','setup'].includes(context.verb))||context.vars.MAIL_PROVIDER==='development')return;
23
+ if((context.verb&&!['installer','setup'].includes(context.verb))||context.vars.MAIL_PROVIDER===localOperatorMailProvider)return;
22
24
  const current=await readSettings(context.root,{});
23
25
  if(current.values.MAIL_PROVIDER===undefined){
24
- await writePrivateFile(current.path,current.text.replace(/\n*$/,'\n')+'MAIL_PROVIDER=development\n');
25
- context.vars={...context.vars,MAIL_PROVIDER:'development'};
26
- }else context.vars=await replaceSavedSetting(context.root,{},'MAIL_PROVIDER','development');
27
- context.store.report('Local MAIL_PROVIDER was repaired to development; local mail is suppressed.');
26
+ await writePrivateFile(current.path,current.text.replace(/\n*$/,'\n')+`MAIL_PROVIDER=${localOperatorMailProvider}\n`);
27
+ context.vars={...context.vars,MAIL_PROVIDER:localOperatorMailProvider};
28
+ }else context.vars=await replaceSavedSetting(context.root,{},'MAIL_PROVIDER',localOperatorMailProvider);
29
+ context.store.report(`Local MAIL_PROVIDER was repaired to ${localOperatorMailProvider}; local mail is suppressed.`);
28
30
  }
@@ -14,7 +14,7 @@ const CREDENTIAL_NAME = new RegExp(`(?:^|[_.-])(?:${CREDENTIAL_WORD})s?(?:$|[_.-
14
14
  // Base's maintained Node 22 runtime. These names require a real case boundary.
15
15
  const CAMEL_CREDENTIAL_NAME = /[A-Za-z0-9](?:Token|Secret|Credential|Key|Pat|Dsn|Auth|Pass|Passwd|Password|Pwd|Signature|Sig|Cookie)s?(?:$|[_.-]|[A-Z0-9])/;
16
16
  const FIELD_NAME = '(?:api[_-]?key|access[_-]?token|auth[_-]?token|token|password|secret|signature|sig|key|pat|dsn|auth|pass)';
17
- const DEV_FIELD = '(?<![A-Za-z0-9])rer-dev';
17
+ const DEV_FIELD = '(?<![A-Za-z0-9])rer-(?:dev|persona)';
18
18
  // A field name may follow `_` or `-` (DB_PASSWORD, client_secret, x-api-key),
19
19
  // but not a letter or digit inside an ordinary word.
20
20
  const FIELD = '(?<![A-Za-z0-9])' + FIELD_NAME;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.122",
3
+ "version": "0.2.124",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",