@runeditrun/rer 0.2.97 → 0.2.99
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/README.md +44 -28
- package/cli/business/api.mjs +15 -9
- package/cli/business/command.mjs +31 -13
- package/cli/business/connect.mjs +134 -4
- package/cli/business/device.mjs +10 -0
- package/cli/business/questions.mjs +2 -2
- package/cli/business/state.mjs +45 -3
- package/cli/business/supervisor.mjs +46 -7
- package/cli/business/vendor-door.mjs +3 -2
- package/global/CHANGELOG.md +41 -0
- package/global/README.md +44 -28
- package/global/cli/repo-command.mjs +3 -3
- package/global/launch/capture.mjs +36 -0
- package/global/launch/dev.mjs +4 -3
- package/global/launch/failure.mjs +1 -1
- package/global/launch/render.mjs +9 -0
- package/global/launch/state.mjs +4 -2
- package/global/launch/steps.mjs +24 -45
- package/global/launch/worker.mjs +9 -6
- package/modules/owner-claim/README.md +5 -4
- package/modules/owner-claim/index.d.mts +1 -1
- package/modules/owner-claim/index.mjs +2 -1
- package/onboarding/redaction-wrapped.mjs +38 -0
- package/onboarding/redaction.mjs +8 -2
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ import { Lease } from './lease.mjs';
|
|
|
11
11
|
import { runDiscovery } from './discovery-task.mjs';
|
|
12
12
|
import { applyChoices } from './choices.mjs';
|
|
13
13
|
import { businessCommand } from './invocation.mjs';
|
|
14
|
-
import { ExportWaiting, vendorHandle } from './vendor-door.mjs';
|
|
14
|
+
import { ExportWaiting, vendorHandle, titledVendor } from './vendor-door.mjs';
|
|
15
15
|
import { runExport } from './export-task.mjs';
|
|
16
16
|
import { runCatchup } from './catchup-task.mjs';
|
|
17
17
|
import { runArchive } from './archive-task.mjs';
|
|
@@ -22,6 +22,27 @@ const kinds = new Set(['discover.local', ...Object.keys(vendorWork)]);
|
|
|
22
22
|
export function supportsTaskKind(kind) { return kinds.has(kind); }
|
|
23
23
|
const checkIn = 25_000;
|
|
24
24
|
|
|
25
|
+
// Only these platform refusals hand work to the owner. Catch-up completion
|
|
26
|
+
// has already surrendered its lease; an export-input wait never claims one.
|
|
27
|
+
function ownerWait(error, state, task) {
|
|
28
|
+
if (error.status !== 409) return null;
|
|
29
|
+
const catchup = error.code === 'business_catchup_approval_required';
|
|
30
|
+
if (!catchup && !(error.code === 'business_export_inputs_required' && error.state === 'waiting_for_owner')) return null;
|
|
31
|
+
let link = ownerLink(state);
|
|
32
|
+
if (catchup && typeof error.link === 'string') {
|
|
33
|
+
try {
|
|
34
|
+
const url = new URL(error.link, state.origin);
|
|
35
|
+
if (url.origin === state.origin && !url.username && !url.password && !url.search && !url.hash
|
|
36
|
+
&& url.pathname.startsWith(new URL(link).pathname + '/moves/')) link = url.href;
|
|
37
|
+
} catch { /* The Business page is where the owner can find this step. */ }
|
|
38
|
+
}
|
|
39
|
+
const vendor = task && titledVendor(task.kind, task.title);
|
|
40
|
+
const step = catchup ? 'approve this catch-up' : vendor === 'sorry' ? 'confirm the address'
|
|
41
|
+
: ['sentry', 'pagerduty'].includes(vendor) ? 'confirm the export details' : null;
|
|
42
|
+
if (!step) return `${error.reason ?? "Waiting for the owner's export inputs."}\nIn Business: ${link}`;
|
|
43
|
+
return `${error.reason ? error.reason + '\n' : ''}Waiting for the owner to ${step} in Business: ${link}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
25
46
|
/** Work this computer's tasks. It says what it is doing and what it waits
|
|
26
47
|
* for, applies the owner's choices at every check-in, and removes run.lock on
|
|
27
48
|
* every exit, including Ctrl-C, SIGTERM and a closed terminal (SIGHUP). */
|
|
@@ -29,7 +50,7 @@ export async function run({ once = false } = {}) {
|
|
|
29
50
|
const { state, credential } = await paired(), api = new Api(state.origin, credential), directory = stateDirectory();
|
|
30
51
|
// Tasks this run handed back as paused, with what each waits for. An export
|
|
31
52
|
// waiting only for the owner's vendor key is picked up again once it is stored.
|
|
32
|
-
const parked = new Map(), unlock = await lockSupervisor(), stop = new AbortController();
|
|
53
|
+
const parked = new Map(), ownerWaits = new Map(), unlock = await lockSupervisor(), stop = new AbortController();
|
|
33
54
|
// A terminal's Ctrl-C reaches npx and this process together, and npx then
|
|
34
55
|
// forwards another SIGINT, which can arrive at any moment until this process
|
|
35
56
|
// has exited. So the handlers stay for the rest of the process: a repeated
|
|
@@ -42,7 +63,7 @@ export async function run({ once = false } = {}) {
|
|
|
42
63
|
let progress, stopCarry, said = '', held = null, summaries = [];
|
|
43
64
|
const say = text => { if (text !== said) { said = text; process.stdout.write(text + '\n'); } };
|
|
44
65
|
// An agent step that waits is said in its own words, never as "Nothing yet".
|
|
45
|
-
const waits = () => [...new Set([...summaries.filter(task => parked.has(task.task_id)).map(task => parked.get(task.task_id).message),
|
|
66
|
+
const waits = () => [...new Set([...ownerWaits.values()].concat(summaries.filter(task => parked.has(task.task_id)).map(task => parked.get(task.task_id).message), agentWaiting(summaries)))];
|
|
46
67
|
// With no agent step waiting, a move's owner step (freeze, rollback, cancellation) is named with its link.
|
|
47
68
|
const idle = () => { const owner = ownerWaiting(summaries, state); return owner.length ? owner.join('\n') : waitingFor(state); };
|
|
48
69
|
try {
|
|
@@ -60,6 +81,9 @@ export async function run({ once = false } = {}) {
|
|
|
60
81
|
}
|
|
61
82
|
if (!progress.pendingClaim) {
|
|
62
83
|
summaries = await nextQuestions(api, stop.signal);
|
|
84
|
+
// A wait belongs only to a task Business still lists as needing input.
|
|
85
|
+
// Cancellation, completion or another computer taking it clears the line.
|
|
86
|
+
for (const id of ownerWaits.keys()) if (!summaries.some(task => task.task_id === id && ['needs_input', 'waiting_for_owner'].includes(task.state))) ownerWaits.delete(id);
|
|
63
87
|
const handles = (await loadState())?.vendorHandles ?? [];
|
|
64
88
|
for (const [id, wait] of parked) if (wait.keyMissing && handles.includes(vendorHandle(wait.keyMissing))) parked.delete(id);
|
|
65
89
|
const selected = summaries.find(task => kinds.has(task.kind) && ['ready','leased'].includes(task.state) && !parked.has(task.task_id));
|
|
@@ -76,9 +100,18 @@ export async function run({ once = false } = {}) {
|
|
|
76
100
|
let claimed;
|
|
77
101
|
try { claimed = await api.post('/api/business/executors/claim', { ...progress.pendingClaim, wait_seconds: 25 }, { signal: stop.signal }); }
|
|
78
102
|
catch (error) {
|
|
79
|
-
|
|
103
|
+
const waiting = ownerWait(error, state, summaries.find(task => task.task_id === progress.pendingClaim.task_id));
|
|
104
|
+
if (!waiting) {
|
|
105
|
+
if (error.status !== 409) throw error;
|
|
106
|
+
progress = {}; await saveProgress(progress);
|
|
107
|
+
held = null;
|
|
108
|
+
if (once) throw error;
|
|
109
|
+
await pause(checkIn, stop.signal); continue;
|
|
110
|
+
}
|
|
111
|
+
ownerWaits.set(progress.pendingClaim.task_id, waiting); say(waiting);
|
|
80
112
|
progress = {}; await saveProgress(progress);
|
|
81
|
-
|
|
113
|
+
held = null;
|
|
114
|
+
if (once) return;
|
|
82
115
|
await pause(checkIn, stop.signal); continue;
|
|
83
116
|
}
|
|
84
117
|
if (!claimed.task || claimed.task.state !== 'leased' || claimed.task.fence !== claimed.fence || Date.parse(claimed.lease_expires_at) <= Date.now()) {
|
|
@@ -130,14 +163,20 @@ export async function run({ once = false } = {}) {
|
|
|
130
163
|
}
|
|
131
164
|
} catch (error) { failure = lease.signal.aborted ? lease.signal.reason : error; }
|
|
132
165
|
finally {
|
|
133
|
-
if (!finished && failure?.status !== 401) {
|
|
166
|
+
if (!finished && failure?.status !== 401 && !ownerWait(failure ?? {}, state)) {
|
|
134
167
|
try { await lease.release(stop.signal.aborted ? 'handover' : parked.has(claimed.task.id) ? 'paused' : 'failed'); released = true; }
|
|
135
168
|
catch (error) { if (error.status === 401) failure = error; }
|
|
136
169
|
}
|
|
137
170
|
await lease.close();
|
|
138
|
-
if (finished || released) { progress = {}; await saveProgress(progress); }
|
|
171
|
+
if (finished || released || ownerWait(failure ?? {}, state)) { progress = {}; await saveProgress(progress); }
|
|
139
172
|
}
|
|
140
173
|
if (failure) {
|
|
174
|
+
const waiting = ownerWait(failure, state);
|
|
175
|
+
if (waiting && !stop.signal.aborted) {
|
|
176
|
+
ownerWaits.set(claimed.task.id, waiting); say(waiting); held = null;
|
|
177
|
+
if (once) return;
|
|
178
|
+
await pause(checkIn, stop.signal); continue;
|
|
179
|
+
}
|
|
141
180
|
if (failure.status === 401 || once || !parked.has(claimed.task.id)) throw failure;
|
|
142
181
|
process.stderr.write(failure.message + '\n');
|
|
143
182
|
}
|
|
@@ -89,8 +89,9 @@ function destination(task, grant) {
|
|
|
89
89
|
function adapterInputs(vendor, task) {
|
|
90
90
|
const inputs = exportInputs(vendor, task);
|
|
91
91
|
if (inputs) return inputs;
|
|
92
|
-
const
|
|
93
|
-
|
|
92
|
+
const message = vendor === 'calendly' ? 'Waiting for the owner: this tool needs its folder of files shared with Business.'
|
|
93
|
+
: `Waiting for the owner to confirm ${inputNeeds[vendor]} in Business.`;
|
|
94
|
+
throw new ExportWaiting(message, 'configuration_required');
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
/** One RER-signed import grant for one door request. `review` asks for a
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.99
|
|
4
|
+
|
|
5
|
+
### Agents wait for the owner instead of failing
|
|
6
|
+
|
|
7
|
+
- `rer business run` now waits when a catch-up needs the owner's approval, or when an export needs an input the owner has not confirmed yet. It prints the platform's message and where the owner acts in Business (for a catch-up, the approval; for an export, the vendor's step, such as confirming the address or the export details), and it does not hand the task back.
|
|
8
|
+
- `rer business run --once` exits 0 when it stops at one of these waits. A continuous `rer business run` keeps running, checks in again every 25 seconds, and picks the work up after the owner acts. A wait clears once Business no longer lists the task as waiting (cancelled, completed or taken by another computer).
|
|
9
|
+
- Every other refusal behaves as before: a 403, a 500 and any other 409 fail or retry exactly as before.
|
|
10
|
+
|
|
11
|
+
### Plainer words
|
|
12
|
+
|
|
13
|
+
- A vendor export that is missing an input now says it is waiting for the owner (it used to say the task was released as paused) and names the right thing per vendor: Sentry's organization and export window, PagerDuty's export window, Sorry's status page address, and for Calendly that its folder of files needs to be shared with Business. The owner step printed by `rer business run` follows the vendor too: confirm the address for Sorry, the export details for Sentry and PagerDuty.
|
|
14
|
+
- `rer business next` now tells you to run `rer business run --once` when there is work ready, and after a vendor key step.
|
|
15
|
+
|
|
16
|
+
### Small connect fixes
|
|
17
|
+
|
|
18
|
+
- A pairing response whose code is not text is refused.
|
|
19
|
+
- Two `rer business connect --business ID` runs in the same state folder can no longer start two pairings: the second waits, then resumes the saved pairing.
|
|
20
|
+
- A failure before a pairing starts no longer says the pairing code still works when no code exists yet; the `--code` flow keeps that line.
|
|
21
|
+
- `rer business connect --origin URL` with an origin that is not https, and without `--code`, names the origin rule again.
|
|
22
|
+
- The README and the code comment no longer promise a date for removing `--code`; it is planned for a later release. Nothing in 0.2.99 changes the `--code` path.
|
|
23
|
+
|
|
24
|
+
## 0.2.98
|
|
25
|
+
|
|
26
|
+
### Connecting a computer to a Business
|
|
27
|
+
|
|
28
|
+
- `rer business connect` now pairs like a TV. Run `rer business connect --business ID [--origin URL] [--timeout SECONDS]`: the computer starts the pairing and prints two fixed lines first, `Code: WDJB-MJHT` and `Approve at: <origin>/business/ID/pair#WDJB-MJHT`. Show the owner both lines. The owner opens the link signed in as an owner of that Business, checks the code and approves there; the computer polls and receives its credential once. Nothing is pasted back into an agent chat, and the code travels in the link's fragment, so it is not sent in a request URL.
|
|
29
|
+
- The command never prompts and needs no terminal. It checks that it can write its state folder and that OS credential storage accepts a write before it starts. Credentials stay in macOS Keychain or Linux Secret Service as before. A state folder already connected to a different origin or Business is refused: disconnect first or use a separate `RER_BUSINESS_STATE_DIR`.
|
|
30
|
+
- Exit code 75 means still waiting: `--timeout` (0 to 900 seconds) ran out before the owner approved and the pairing is kept. Run the same command again: it prints the same code and link and resumes the saved pairing. Without `--timeout` it waits until the pairing ends. Exit 0 means the credential is stored and the server has seen the computer; 1 means the pairing was refused, expired, already used or failed; 2 means bad usage; Ctrl-C and SIGTERM keep the pairing and exit 130 and 143.
|
|
31
|
+
- `rer business connect --code CODE` (the browser-created code with a six-digit confirmation number) works unchanged in this release. It cannot be combined with `--business` or `--timeout`.
|
|
32
|
+
|
|
33
|
+
### The private dev sign-in key in captured logs
|
|
34
|
+
|
|
35
|
+
- `rer dev` no longer writes the owner's private dev sign-in key (`rer-dev=<key>`) into rer's captured files: `server.log`, `reuse.log`, `launch.log` and the launch events. Every launch capture writer goes through the shared redaction, including keys in JSON field names and values, keys wrapped across lines and URL-encoded keys. The detached capture owner now stays alive with the server so its output stays redacted for the server's whole run. The private sign-in link is still delivered to the caller, read from `.rer/local` only at hand-off.
|
|
36
|
+
- `rer setup <owner/repo>` writes its `launch.log` through the same redaction, also when setup fails.
|
|
37
|
+
- Captured output that mixes text and JSON progress lines is written in order: JSON events are no longer glued onto a held text tail.
|
|
38
|
+
|
|
39
|
+
### Owner claim after setup
|
|
40
|
+
|
|
41
|
+
- A seed whose hidden setup token has been retired no longer loses sign-in. Before, the owner-claim module answered 503 `invalid_configuration` for every route once the setup token was gone, so seeds that build the claim handler on every request (such as Lamp, Balm, Cabin, Lanyard and Willow) answered errors on owner sessions and all other auth routes after setup. Now owner sessions and the other auth routes keep working, and only `/auth/owner-claim` answers 409 `claim_unavailable`, for every method. Origin, email and database checks, signature checks and claim replay protection are unchanged.
|
|
42
|
+
- A refreshing seed refreshes to 0.2.98 to receive this; it needs no seed code edit for this part. `modules/owner-claim/README.md` now says the handler is safe to construct per request.
|
|
43
|
+
|
|
3
44
|
## 0.2.97
|
|
4
45
|
|
|
5
46
|
### Seed-door decision relay
|
package/global/README.md
CHANGED
|
@@ -460,33 +460,49 @@ or use its stored device credential.
|
|
|
460
460
|
|
|
461
461
|
## Business device commands
|
|
462
462
|
|
|
463
|
-
`rer business connect --
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
code
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
463
|
+
`rer business connect --business ID [--origin https://app.runeditrun.com] [--timeout 30]`
|
|
464
|
+
starts a pairing on this computer and prints two fixed lines first:
|
|
465
|
+
|
|
466
|
+
```text
|
|
467
|
+
Code: WDJB-MJHT
|
|
468
|
+
Approve at: https://app.runeditrun.com/business/ID/pair#WDJB-MJHT
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
Take the Business ID and origin from the Business Connect page's prompt. Show
|
|
472
|
+
the owner both lines exactly as printed. The owner opens the link signed in as
|
|
473
|
+
an owner of that Business, checks the code against this computer and approves
|
|
474
|
+
there. No code or confirmation number needs to come back through chat. The
|
|
475
|
+
code travels in the link's fragment, so it is not sent in a request URL.
|
|
476
|
+
|
|
477
|
+
Connect never prompts or requires a TTY. It checks state-folder writes and OS
|
|
478
|
+
credential storage before starting, then polls at the server's interval,
|
|
479
|
+
including any increased interval after `slow_down`. Without `--timeout`, it
|
|
480
|
+
waits until the pairing ends. `--timeout` accepts an integer from 0 to 900;
|
|
481
|
+
when the wait ends first, exit 75 means still waiting. Run the same command
|
|
482
|
+
again: it prints the same code and link and resumes the saved pairing.
|
|
483
|
+
Ctrl-C and SIGTERM also keep it, exiting 130 and 143. Exit 0 means the credential
|
|
484
|
+
was stored and the server has seen the connected computer; exit 1 means refusal,
|
|
485
|
+
expiry, an already-used pairing or another failure, and exit 2 means bad usage.
|
|
486
|
+
Network failures keep the pairing for retry. Terminal server refusals remove it.
|
|
487
|
+
Pairings are kept through the original deadline plus the ten-minute collection
|
|
488
|
+
window, so an approval near the code's end can still be collected.
|
|
489
|
+
|
|
490
|
+
State lives in `$RER_BUSINESS_STATE_DIR` when set, otherwise `~/.rer/business`.
|
|
491
|
+
`RER_STATE_DIR` belongs to `rer demo` and Business never reads it. The short-lived
|
|
492
|
+
device code and displayed code are kept only in private `pairing.json` (0600),
|
|
493
|
+
removed when pairing ends. Device credentials remain in macOS Keychain or Linux
|
|
494
|
+
Secret Service under the existing per-origin, per-Business account; there is no
|
|
487
495
|
plaintext credential store. Linux needs `secret-tool` and an unlocked desktop
|
|
488
|
-
Secret Service session.
|
|
489
|
-
|
|
496
|
+
Secret Service session. Connect refuses a state folder already connected to a
|
|
497
|
+
different origin or Business: disconnect first or use a separate
|
|
498
|
+
`RER_BUSINESS_STATE_DIR`. It reports this computer's plain name, working folder,
|
|
499
|
+
agent and OS (including WSL) for the owner to recognise.
|
|
500
|
+
|
|
501
|
+
For older Business pages, `rer business connect --code ABCD-1234 --origin URL`
|
|
502
|
+
keeps the browser-created code and six-digit confirmation-number flow unchanged
|
|
503
|
+
in 0.2.98. It cannot be combined with `--business` or `--timeout`. Removal is
|
|
504
|
+
planned for a later release after the production rollback target uses device pairing.
|
|
505
|
+
The install.sh form still passes either connect command through unchanged.
|
|
490
506
|
|
|
491
507
|
The owner chooses three things on the computer's row in the browser: "Add rules
|
|
492
508
|
so Claude Code never reads your secret files" (Claude Code user Read deny
|
|
@@ -508,12 +524,12 @@ pairing state are stored, so a storage failure cannot activate the computer.
|
|
|
508
524
|
A service installed with `RER_BUSINESS_STATE_DIR` set keeps that folder. Background
|
|
509
525
|
services use absolute Node and CLI paths. No model process is started.
|
|
510
526
|
|
|
511
|
-
An agent can run `npx -y @runeditrun/rer business connect --
|
|
527
|
+
An agent can run `npx -y @runeditrun/rer business connect --business ID --origin URL --timeout 30`
|
|
512
528
|
directly, without a global installation. In Codex's workspace-write sandbox,
|
|
513
529
|
allow network access, set `RER_BUSINESS_STATE_DIR="$PWD/.rer-business"` so state stays
|
|
514
530
|
inside the working folder, and put npm's cache there too with
|
|
515
531
|
`npm_config_cache="$PWD/.rer/npm"`. macOS refuses Keychain writes from inside
|
|
516
|
-
that sandbox, so connect stops before
|
|
532
|
+
that sandbox, so connect stops before starting and asks for this one command to
|
|
517
533
|
run outside the sandbox (in Codex, approve running that command outside the
|
|
518
534
|
sandbox when it asks); later commands
|
|
519
535
|
only read the credential and run inside the sandbox. Do not install a
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createWriteStream } from 'node:fs';
|
|
2
1
|
import { realpath } from 'node:fs/promises';
|
|
3
2
|
import { join } from 'node:path';
|
|
4
3
|
import { parse } from '../../cli/parse.mjs';
|
|
@@ -9,6 +8,7 @@ import { checkoutRepository, runCommand } from './repository.mjs';
|
|
|
9
8
|
import { ownRoot } from '../package-info.mjs';
|
|
10
9
|
import { prepare } from '../launch/prepare.mjs';
|
|
11
10
|
import { launchDirectory } from '../launch/state.mjs';
|
|
11
|
+
import { captureFile } from '../launch/capture.mjs';
|
|
12
12
|
|
|
13
13
|
export async function repoCommand(request) {
|
|
14
14
|
const { verb, directory, args } = request;
|
|
@@ -22,7 +22,7 @@ export async function repoCommand(request) {
|
|
|
22
22
|
if (verb === 'setup') {
|
|
23
23
|
await (await import('../../cli/business/carry.mjs')).refreshCheckout(root);
|
|
24
24
|
const state = await launchDirectory(root), children = new Set(), controller = new AbortController();
|
|
25
|
-
const log =
|
|
25
|
+
const log = await captureFile(root, join(state, 'launch.log'));
|
|
26
26
|
const handlers = new Map(['SIGINT', 'SIGTERM'].map(signal => [signal, () => { controller.abort(); for (const child of children) child.kill(signal); }]));
|
|
27
27
|
for (const [signal, handler] of handlers) process.on(signal, handler);
|
|
28
28
|
try {
|
|
@@ -31,7 +31,7 @@ export async function repoCommand(request) {
|
|
|
31
31
|
await result.release?.();
|
|
32
32
|
} finally {
|
|
33
33
|
for (const [signal, handler] of handlers) process.off(signal, handler);
|
|
34
|
-
log.
|
|
34
|
+
await log.close();
|
|
35
35
|
}
|
|
36
36
|
} else {
|
|
37
37
|
if (verb === 'dev' && !args.includes('--json')) process.stdout.write(`Restart: ${next('dev')}\n`);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { open } from 'node:fs/promises';
|
|
2
|
+
import { readDevKey } from '../../cli/dev-identity.mjs';
|
|
3
|
+
import { createRedaction } from '../../onboarding/redaction.mjs';
|
|
4
|
+
|
|
5
|
+
// The generated key is not in the launcher's environment. Setup may create it
|
|
6
|
+
// after capture begins, so register it before each queued write until it exists.
|
|
7
|
+
export function launchRedaction(root) {
|
|
8
|
+
const redaction = createRedaction({ wrappedSecrets: true });
|
|
9
|
+
let key;
|
|
10
|
+
const clean = value => typeof value === 'string' ? redaction.redact(value)
|
|
11
|
+
: Array.isArray(value) ? value.map(clean)
|
|
12
|
+
: value && typeof value === 'object' ? Object.fromEntries(Object.entries(value).map(([name, item]) => [redaction.redact(name), clean(item)])) : value;
|
|
13
|
+
return {
|
|
14
|
+
...redaction, clean,
|
|
15
|
+
async refresh() { if (!key) { key = await readDevKey(root); if (key) redaction.addSecrets([key]); } },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Both server streams and preparation output pass here before reaching disk.
|
|
20
|
+
// JSON is redacted by value, preserving parseable progress events.
|
|
21
|
+
export async function captureFile(root, path) {
|
|
22
|
+
const redaction = launchRedaction(root), file = await open(path, 'a', 0o600);
|
|
23
|
+
let queued = Promise.resolve(), writes = Promise.resolve();
|
|
24
|
+
const append = text => { writes = writes.then(() => file.appendFile(text)); void writes.catch(() => {}); };
|
|
25
|
+
const stream = redaction.stream(append);
|
|
26
|
+
const queue = action => { queued = queued.then(async () => { await redaction.refresh(); action(); }); void queued.catch(() => {}); };
|
|
27
|
+
return {
|
|
28
|
+
write(text) { queue(() => stream.write(text)); },
|
|
29
|
+
line(text) {
|
|
30
|
+
let event; try { event = JSON.parse(text); } catch {}
|
|
31
|
+
if (event && typeof event === 'object') queue(() => stream.write(JSON.stringify(redaction.clean(event)) + '\n'));
|
|
32
|
+
else queue(() => stream.write(text + '\n'));
|
|
33
|
+
},
|
|
34
|
+
async close() { try { await queued; stream.end(); await writes; } finally { await file.close(); } },
|
|
35
|
+
};
|
|
36
|
+
}
|
package/global/launch/dev.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// --detach and --foreground override the choice.
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
7
|
import { randomUUID } from 'node:crypto';
|
|
8
|
-
import {
|
|
8
|
+
import { existsSync } from 'node:fs';
|
|
9
9
|
import { open, realpath, stat } from 'node:fs/promises';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
@@ -24,6 +24,7 @@ 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';
|
|
27
|
+
import { captureFile } from './capture.mjs';
|
|
27
28
|
|
|
28
29
|
const workerPath = fileURLToPath(new URL('./worker.mjs', import.meta.url));
|
|
29
30
|
|
|
@@ -82,13 +83,13 @@ async function foreground(target, devArgs, directory, out, doorStart) {
|
|
|
82
83
|
const code = await follow(directory, holder.token, out, { quiet: true });
|
|
83
84
|
if (code !== 0) return code;
|
|
84
85
|
}
|
|
85
|
-
const log =
|
|
86
|
+
const log = await captureFile(target.root, join(directory, 'launch.log'));
|
|
86
87
|
let prepared;
|
|
87
88
|
// The same progress lines as a detached launch while install or setup runs.
|
|
88
89
|
const heartbeat = setInterval(() => out.heartbeat(), 1000);
|
|
89
90
|
try { prepared = await prepare({ root: target.root, args: devArgs, env: process.env, report: fields => out.phase(fields), directory, log: text => log.write(text + '\n'), children: new Set(), doorStart }); }
|
|
90
91
|
catch (failure) { if (!(failure instanceof LaunchFailure)) throw failure; out.failure(failure); return failure.exitCode; }
|
|
91
|
-
finally { clearInterval(heartbeat); log.
|
|
92
|
+
finally { clearInterval(heartbeat); await log.close(); }
|
|
92
93
|
Object.assign(process.env, prepared.added);
|
|
93
94
|
return delegateDev(target);
|
|
94
95
|
}
|
|
@@ -12,7 +12,7 @@ export class LaunchFailure extends Error {
|
|
|
12
12
|
export function workerFailure(error, { root, env = process.env }) {
|
|
13
13
|
const redaction = createRedaction();
|
|
14
14
|
redaction.addSecrets([...credentialValues(env), ...credentialValues(error?.event)]);
|
|
15
|
-
const redact = text => redaction.redact(String(text)
|
|
15
|
+
const redact = text => redaction.redact(String(text));
|
|
16
16
|
const clean = value => typeof value === 'string' ? redact(value)
|
|
17
17
|
: Array.isArray(value) ? value.map(clean)
|
|
18
18
|
: value && typeof value === 'object' ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, clean(item)])) : value;
|
package/global/launch/render.mjs
CHANGED
|
@@ -3,6 +3,8 @@ import { humanError } from '../../cli/human-error.mjs';
|
|
|
3
3
|
// seconds (a `progress` event with --json), then the dispatcher's ready lines.
|
|
4
4
|
import { readySummary } from '../../cli/ready-summary.mjs';
|
|
5
5
|
import { launchSummary } from '../../cli/run-transfers.mjs';
|
|
6
|
+
import { contained } from '../../cli/project.mjs';
|
|
7
|
+
import { shared } from '../../cli/shared.mjs';
|
|
6
8
|
|
|
7
9
|
const elapsed = ms => { const s = Math.round(ms / 1000); return s < 60 ? `${s}s` : `${Math.floor(s / 60)}m ${s % 60}s`; };
|
|
8
10
|
const quiet = 20000;
|
|
@@ -26,6 +28,13 @@ export function printer({ json, stopHint, keyless = false, root }) {
|
|
|
26
28
|
// The dispatcher's ready event, as its own human ready lines.
|
|
27
29
|
async ready(ready, { log, pid }) {
|
|
28
30
|
if (keyless) { const { openUrl, ...rest } = ready; ready = rest; }
|
|
31
|
+
else if (root && ready.openUrl && new URLSearchParams(new URL(ready.openUrl).hash.slice(1)).get('rer-dev') === '[REDACTED]') {
|
|
32
|
+
// The journal never transports the credential. Only the caller's final
|
|
33
|
+
// handoff reads the private link the dispatcher saved inside .rer/local.
|
|
34
|
+
const { readPrivateFile } = await shared('private-files.mjs');
|
|
35
|
+
const openUrl = (await readPrivateFile(await contained(root, '.rer/local/open-url', { privateFile: true }))).trim();
|
|
36
|
+
ready = { ...ready, openUrl, ...(ready.ownerOpenUrl ? { ownerOpenUrl: openUrl } : {}) };
|
|
37
|
+
}
|
|
29
38
|
if (json) { event('server', { pid, log }); process.stdout.write(JSON.stringify(ready) + '\n'); return; }
|
|
30
39
|
const out = root
|
|
31
40
|
? [...readySummary(ready), ...await launchSummary(root), '', 'Details for tools and troubleshooting:', `RER_READY ${ready.url}`]
|
package/global/launch/state.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { appendFile, link, mkdir, readFile, readdir, realpath, rm, writeFile } f
|
|
|
13
13
|
import { join } from 'node:path';
|
|
14
14
|
import { processInfo } from '../../modules/job-queue/processes.mjs';
|
|
15
15
|
import { serversDirectory } from '../registry.mjs';
|
|
16
|
+
import { launchRedaction } from './capture.mjs';
|
|
16
17
|
|
|
17
18
|
import { launchPath } from '../../cli/checkout-preparation.mjs';
|
|
18
19
|
export { launchPath };
|
|
@@ -115,9 +116,10 @@ export async function releaseLaunch(directory, token) {
|
|
|
115
116
|
if (holder?.token === token) await rm(join(directory, 'worker.json'), { force: true });
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
export function eventLog(directory, token) {
|
|
119
|
+
export function eventLog(directory, token, root = process.cwd()) {
|
|
119
120
|
const path = join(directory, `events-${token}.jsonl`);
|
|
120
|
-
|
|
121
|
+
const redaction = launchRedaction(root);
|
|
122
|
+
return { path, async write(event) { await redaction.refresh(); await appendFile(path, JSON.stringify(redaction.clean({ at: Date.now(), ...event })) + '\n', { mode: 0o600 }); } };
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
// { state: 'running' | 'done' | 'failed', ... } for the last install or setup
|
package/global/launch/steps.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// Run the pinned dispatcher's public verbs as children, reading its --json
|
|
2
2
|
// events: install and setup to completion, and dev until its `ready` event.
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
|
-
import { createReadStream } from 'node:fs';
|
|
5
|
-
import { open, stat } from 'node:fs/promises';
|
|
6
4
|
import { createInterface } from 'node:readline';
|
|
7
|
-
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
5
|
import { LaunchFailure } from './failure.mjs';
|
|
6
|
+
import { captureFile } from './capture.mjs';
|
|
9
7
|
|
|
10
8
|
function events(line) { try { const value = JSON.parse(line); return value && typeof value === 'object' ? value : undefined; } catch { return undefined; } }
|
|
11
9
|
|
|
@@ -42,54 +40,35 @@ export async function runVerb(entry, args, { root, env, note, log, children, sig
|
|
|
42
40
|
if (code !== 0) throw failureFrom(code, error, output);
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
let offset = from, rest = '';
|
|
48
|
-
while (!stopped()) {
|
|
49
|
-
const size = (await stat(path)).size;
|
|
50
|
-
if (size > offset) {
|
|
51
|
-
const handle = await open(path, 'r');
|
|
52
|
-
try {
|
|
53
|
-
const { buffer, bytesRead } = await handle.read({ buffer: Buffer.alloc(size - offset), position: offset });
|
|
54
|
-
offset += bytesRead; rest += buffer.subarray(0, bytesRead).toString('utf8');
|
|
55
|
-
} finally { await handle.close(); }
|
|
56
|
-
const parts = rest.split('\n'); rest = parts.pop();
|
|
57
|
-
for (const line of parts) if (onLine(line)) return;
|
|
58
|
-
}
|
|
59
|
-
await delay(200);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Start `dev` detached into its own process group with its output in a private
|
|
64
|
-
// log, and return its ready event once it prints one. The server outlives this
|
|
65
|
-
// process and stops on rer dev --stop or its idle timeout.
|
|
43
|
+
// Keep the worker as the capture owner for the server's whole lifetime. Raw
|
|
44
|
+
// output is parsed in memory; only redacted bytes reach either captured log.
|
|
66
45
|
export async function startServer(entry, args, { root, env, logPath, children, signal, note = () => {} }) {
|
|
67
46
|
signal?.throwIfAborted();
|
|
68
|
-
const
|
|
69
|
-
let child
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
child = spawn(process.execPath, [entry, 'dev', ...args, '--json'], { cwd: root, env, detached: true, stdio: ['ignore', handle.fd, handle.fd] });
|
|
73
|
-
child.once('error', failure => { spawnError = failure; exit ??= 1; });
|
|
74
|
-
child.once('exit', (code, name) => { exit = code ?? (name ? 128 : 1); });
|
|
75
|
-
} finally { await handle.close(); }
|
|
47
|
+
const capture = await captureFile(root, logPath);
|
|
48
|
+
let child;
|
|
49
|
+
try { child = spawn(process.execPath, [entry, 'dev', ...args, '--json'], { cwd: root, env, detached: true, stdio: ['ignore', 'pipe', 'pipe'] }); }
|
|
50
|
+
catch (error) { await capture.close(); throw error; }
|
|
76
51
|
own(children, child, signal);
|
|
77
|
-
let ready, error, output = '';
|
|
78
|
-
|
|
52
|
+
let ready, error, output = '', spawnError, resolveReady;
|
|
53
|
+
const announced = new Promise(resolve => { resolveReady = resolve; });
|
|
54
|
+
const lines = createInterface({ input: child.stdout });
|
|
55
|
+
lines.on('line', line => {
|
|
79
56
|
const event = events(line);
|
|
80
|
-
|
|
57
|
+
capture.line(line);
|
|
58
|
+
if (event?.event === 'ready') { ready = event; resolveReady(); }
|
|
81
59
|
if (event?.event === 'error') error = event;
|
|
82
|
-
// rer dev --door / --direct: where the checkout moved.
|
|
83
60
|
if (event?.event === 'moved') note(`moved this checkout from ${event.from} to ${event.to}; its data is kept`);
|
|
84
61
|
if (!event) output = (output + line + '\n').slice(-8192);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
62
|
+
});
|
|
63
|
+
child.stderr.on('data', data => { output = (output + data).slice(-8192); capture.write(data); });
|
|
64
|
+
child.once('error', failure => { spawnError = failure; });
|
|
65
|
+
const closed = new Promise((resolve, reject) => child.once('close', async (code, name) => {
|
|
66
|
+
children.delete(child);
|
|
67
|
+
try { await capture.close(); resolve(code ?? (name ? 128 : 1)); } catch (error) { reject(error); }
|
|
68
|
+
}));
|
|
69
|
+
// A write failure must also reach the worker after it has announced readiness.
|
|
70
|
+
void closed.catch(() => {});
|
|
71
|
+
const exit = await Promise.race([announced, closed]);
|
|
92
72
|
if (!ready) throw failureFrom(exit, error, spawnError ? `rer could not run in ${root}: ${spawnError.code ?? spawnError.message}.` : output);
|
|
93
|
-
child.
|
|
94
|
-
return { ready, pid: child.pid, reused: exit === 0 };
|
|
73
|
+
return { ready, pid: child.pid, closed };
|
|
95
74
|
}
|
package/global/launch/worker.mjs
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
// claimed the launch, the stop request it reads right after claiming. Either
|
|
7
7
|
// way no further step starts, the running one is signalled, and the launch
|
|
8
8
|
// reports that it was stopped instead of ready.
|
|
9
|
-
import { createWriteStream } from 'node:fs';
|
|
10
9
|
import { realpath } from 'node:fs/promises';
|
|
11
10
|
import { join } from 'node:path';
|
|
12
11
|
import { processInfo } from '../../modules/job-queue/processes.mjs';
|
|
@@ -15,9 +14,10 @@ import { LaunchFailure, workerFailure } from './failure.mjs';
|
|
|
15
14
|
import { prepare } from './prepare.mjs';
|
|
16
15
|
import { claimLaunch, eventLog, launchDirectory, liveWorker, releaseLaunch, serverRecord, stopRequest } from './state.mjs';
|
|
17
16
|
import { startServer } from './steps.mjs';
|
|
17
|
+
import { captureFile } from './capture.mjs';
|
|
18
18
|
|
|
19
19
|
const [root, token, argsJSON, requestedAtText, mode] = process.argv.slice(2), args = JSON.parse(argsJSON), requestedAt = Number(requestedAtText), doorStart = mode === 'door-start';
|
|
20
|
-
const checkout = await realpath(root), directory = await launchDirectory(checkout), events = eventLog(directory, token);
|
|
20
|
+
const checkout = await realpath(root), directory = await launchDirectory(checkout), events = eventLog(directory, token, root);
|
|
21
21
|
// Listening before the claim: a stop may signal this worker as soon as it is the holder.
|
|
22
22
|
const children = new Set(), stopping = new AbortController();
|
|
23
23
|
const stop = () => { stopping.abort(); for (const child of children) child.kill('SIGTERM'); };
|
|
@@ -27,8 +27,9 @@ if (!await claimLaunch(directory, token)) {
|
|
|
27
27
|
const holder = await liveWorker(directory);
|
|
28
28
|
await events.write({ event: 'redirect', token: holder?.token });
|
|
29
29
|
} else {
|
|
30
|
-
const logFile =
|
|
30
|
+
const logFile = await captureFile(root, join(directory, 'launch.log'));
|
|
31
31
|
const log = text => logFile.write(text + '\n');
|
|
32
|
+
let started;
|
|
32
33
|
try {
|
|
33
34
|
if (await stopRequest.covers(directory, requestedAt)) stop();
|
|
34
35
|
stopping.signal.throwIfAborted();
|
|
@@ -37,7 +38,6 @@ if (!await claimLaunch(directory, token)) {
|
|
|
37
38
|
// A server rer started logs to server.log; asking a running one for its
|
|
38
39
|
// ready lines goes to reuse.log, and names server.log only when rer started it.
|
|
39
40
|
const serverLog = join(directory, 'server.log');
|
|
40
|
-
let started;
|
|
41
41
|
try { started = await startServer(prepared.entry, args, { root, env: { ...process.env, ...prepared.added }, logPath: prepared.own ? join(directory, 'reuse.log') : serverLog, children, signal: stopping.signal, note: message => events.write({ event: 'phase', phase: 'note', message }) }); }
|
|
42
42
|
finally { await prepared.release?.(); }
|
|
43
43
|
const record = (await liveServers(process.env)).find(item => item.checkout === checkout);
|
|
@@ -45,7 +45,7 @@ if (!await claimLaunch(directory, token)) {
|
|
|
45
45
|
// The server's PID, and the process rer spawned for it (the same one unless
|
|
46
46
|
// the pin re-runs itself under its own Node), each with its start time.
|
|
47
47
|
const identity = async id => ({ pid: id, start: (await processInfo(id))?.start });
|
|
48
|
-
if (!prepared.own) await serverRecord.write(directory, { ...await identity(pid), spawned: await identity(
|
|
48
|
+
if (!prepared.own) await serverRecord.write(directory, { ...await identity(pid), spawned: await identity(process.pid) });
|
|
49
49
|
const ours = !prepared.own || (await serverRecord.read(directory))?.pid === pid;
|
|
50
50
|
// A stop that arrived while the server came up finds it registered and
|
|
51
51
|
// stops it; this launch reports the stop rather than a server about to end.
|
|
@@ -57,6 +57,9 @@ if (!await claimLaunch(directory, token)) {
|
|
|
57
57
|
await events.write({ event: 'failed', exitCode: failure.exitCode, message: failure.message, error: failure.event });
|
|
58
58
|
} finally {
|
|
59
59
|
await releaseLaunch(directory, token);
|
|
60
|
-
logFile.
|
|
60
|
+
await logFile.close();
|
|
61
61
|
}
|
|
62
|
+
// Release preparation custody at ready, but continue redacting output until
|
|
63
|
+
// the registered server exits. Repeated launches can prepare independently.
|
|
64
|
+
await started?.closed;
|
|
62
65
|
}
|
|
@@ -22,9 +22,9 @@ permanently prevents another claim, including after the consumed claim expires.
|
|
|
22
22
|
origin, canonical owner email and public signing-key ring. Claims are never a
|
|
23
23
|
configuration source.
|
|
24
24
|
3. Mount this handler before the operator-auth dispatcher; it owns only
|
|
25
|
-
`/auth/owner-claim
|
|
26
|
-
operator-auth sessions. Never expose a server
|
|
27
|
-
verified payload fields from browser input.
|
|
25
|
+
`/auth/owner-claim` and is safe to construct per request. Continue protecting
|
|
26
|
+
application routes with real operator-auth sessions. Never expose a server
|
|
27
|
+
function taking authConfig or verified payload fields from browser input.
|
|
28
28
|
4. Declare the release setup manifest's owner claim step with
|
|
29
29
|
`type: 'owner-claim'`, `mode: 'signed'`, `emailField` naming the public
|
|
30
30
|
owner-email setup field, `path: '/auth/owner-claim'`, and `tokenField` naming
|
|
@@ -71,7 +71,8 @@ key rotation may overlap old and new kids for the five-minute window, then remov
|
|
|
71
71
|
the old kid. Public keys are EC/P-256 JWKs, never private JWKs; missing/unknown kids
|
|
72
72
|
and untrusted issuers fail. Config is snapshotted when the handler is created.
|
|
73
73
|
Remove the hidden setup token after successful bootstrap as part of ordinary
|
|
74
|
-
application secret maintenance;
|
|
74
|
+
application secret maintenance; the claim route then answers 409 `claim_unavailable`
|
|
75
|
+
for every method. Never delete either admission ledger.
|
|
75
76
|
|
|
76
77
|
## Wire and browser transport
|
|
77
78
|
|
|
@@ -16,7 +16,7 @@ export class OwnerClaimError extends Error { constructor(code?: string, status?:
|
|
|
16
16
|
export function verifyOwnerClaim(token: string, config: OwnerClaimConfig & { /** Epoch seconds. */ now?: number }): Promise<Readonly<OwnerClaim>>;
|
|
17
17
|
export interface OwnerClaimHandlerOptions extends OwnerClaimConfig {
|
|
18
18
|
db: Database;
|
|
19
|
-
/** Includes
|
|
19
|
+
/** Includes server-only SESSION_SECRET and optional SETUP_TOKEN; after token retirement the claim route returns 409. */
|
|
20
20
|
authConfig: AuthConfig;
|
|
21
21
|
clientIp: (request: Request) => string | Promise<string>;
|
|
22
22
|
/** Milliseconds, default Date.now. */
|