@runeditrun/rer 0.2.99 → 0.2.101
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 +30 -102
- package/cli/README.md +38 -25
- package/cli/app-address.mjs +2 -0
- package/cli/business/api.mjs +2 -1
- package/cli/business/choices.mjs +1 -1
- package/cli/business/command.mjs +36 -25
- package/cli/business/connect.mjs +1 -1
- package/cli/business/lease.mjs +0 -9
- package/cli/business/local-commands.mjs +1 -18
- package/cli/business/outbound.mjs +2 -14
- package/cli/business/questions.mjs +85 -48
- package/cli/business/service.mjs +1 -24
- package/cli/business/setup-command.mjs +33 -26
- package/cli/business/state.mjs +2 -2
- package/cli/business/supervisor.mjs +26 -91
- package/cli/companion/command.mjs +2 -0
- package/cli/demo-native.mjs +1 -1
- package/cli/deploy-command.mjs +5 -4
- package/cli/deploy-inputs.mjs +1 -1
- package/cli/deploy.mjs +6 -4
- package/cli/parse.mjs +2 -1
- package/cli/production-auth.mjs +16 -3
- package/cli/production-mail.mjs +18 -1
- package/cli/site.mjs +1 -1
- package/global/CHANGELOG.md +45 -0
- package/global/README.md +30 -102
- package/global/main.mjs +2 -0
- package/modules/container/adapters/d1-limits.mjs +2 -10
- package/modules/d1-transport/limits.d.mts +10 -0
- package/modules/d1-transport/limits.mjs +10 -0
- package/modules/demo-host/native/prepare.mjs +2 -1
- package/modules/deploy-kit/README.md +10 -0
- package/modules/deploy-kit/provider.mjs +18 -2
- package/modules/import-kit/schema/importers.schema.json +104 -2
- package/modules/import-kit/src/d1/README.md +13 -0
- package/modules/import-kit/src/d1/apply-reads.ts +48 -0
- package/modules/import-kit/src/d1/apply.ts +21 -8
- package/modules/import-kit/src/d1/history.ts +2 -2
- package/modules/import-kit/src/d1/jobs.ts +3 -1
- package/modules/import-kit/src/d1/retirement-scope.ts +2 -2
- package/modules/import-kit/src/d1/retirement-tally.ts +1 -0
- package/modules/import-kit/src/d1/retirement.ts +15 -5
- package/modules/import-kit/src/d1/types.ts +14 -0
- package/modules/import-kit/src/d1/wave-boundary.ts +33 -0
- package/modules/import-kit/src/d1/wave-retirement.ts +47 -0
- package/modules/import-kit/src/provenance/credentials.ts +14 -5
- package/modules/import-kit/src/status/evidence.ts +3 -1
- package/modules/import-kit/src/status/index.ts +17 -2
- package/modules/import-kit/src/status/schema.ts +8 -0
- package/modules/import-kit/src/status/types.ts +25 -4
- package/onboarding/adapter.mjs +7 -1
- package/onboarding/operator-installer.mjs +3 -1
- package/package.json +1 -1
- package/scripts/publish-check/README.md +20 -0
- package/scripts/publish-check/diagnostics.mjs +73 -0
- package/scripts/publish-check/slots.py +37 -7
- package/scripts/publish-check.mjs +64 -37
- package/cli/business/archive-task.mjs +0 -32
- package/cli/business/catchup-task.mjs +0 -42
- package/cli/business/export-inputs.mjs +0 -69
- package/cli/business/export-task.mjs +0 -17
- package/cli/business/setup-demo.mjs +0 -95
- package/cli/business/vendor-door.mjs +0 -231
- package/cli/business/vendors/README.md +0 -176
- package/cli/business/vendors/calendly.mjs +0 -80
- package/cli/business/vendors/common.mjs +0 -199
- package/cli/business/vendors/credential-names.mjs +0 -124
- package/cli/business/vendors/index.mjs +0 -86
- package/cli/business/vendors/pagerduty.mjs +0 -61
- package/cli/business/vendors/sentry.mjs +0 -85
- package/cli/business/vendors/sorry.mjs +0 -106
- package/cli/business/vendors/uptimerobot.mjs +0 -21
|
@@ -4,7 +4,6 @@ import { sensitive } from './detector.mjs';
|
|
|
4
4
|
import { paired, revokedByServer, revokedText } from './local-commands.mjs';
|
|
5
5
|
import { applyChoices } from './choices.mjs';
|
|
6
6
|
import { businessCommand } from './invocation.mjs';
|
|
7
|
-
import { titledVendor, keyStep, keyed, vendorNames, vendorHandle } from './vendor-door.mjs';
|
|
8
7
|
|
|
9
8
|
const protocolVersion = '2025-11-25';
|
|
10
9
|
const headers = { Accept: 'application/json, text/event-stream', 'MCP-Protocol-Version': protocolVersion };
|
|
@@ -36,7 +35,7 @@ export async function nextQuestions(api, signal) {
|
|
|
36
35
|
if (!Array.isArray(result.tasks)) throw Error('Business server returned invalid task summaries.');
|
|
37
36
|
return result.tasks;
|
|
38
37
|
}
|
|
39
|
-
const ownerKinds = new Set(['signup.checkout','connect.cloudflare','connect.github','consent.grant','confirm.inventory','plan.review'
|
|
38
|
+
const ownerKinds = new Set(['signup.checkout','connect.cloudflare','connect.github','consent.grant','confirm.inventory','plan.review']);
|
|
40
39
|
export const ownerLink = state => `${state.origin}/business/${encodeURIComponent(identifier(state.businessId))}`;
|
|
41
40
|
|
|
42
41
|
// What this computer is waiting for, in the owner's terms. Until its own
|
|
@@ -53,45 +52,72 @@ export function waitingFor(state) {
|
|
|
53
52
|
return `Waiting for the next task. Nothing needs this computer until the owner moves the plan forward: ${ownerLink(state)}`;
|
|
54
53
|
}
|
|
55
54
|
const runWork = { 'discover.local': "this computer's names-only scan of the folders the owner allowed" };
|
|
56
|
-
//
|
|
57
|
-
const
|
|
58
|
-
'export.vendor': name => `export the owner's ${name} history into its app's import door. It lands as a preview: nothing changes in the app until the owner approves it in the browser.`,
|
|
59
|
-
'catchup.vendor': name => `bring the owner's recent ${name} changes into its app's import door as a catch-up. Within the owner's standing catch-up approval Business applies it; anything larger waits for the owner's approval in the browser.`,
|
|
60
|
-
'switchoff.archive': name => `archive the owner's final ${name} export in its app's import door. The app keeps the exact file in its own storage and test-restores it with no writes; cancelling ${name} stays the owner's step.`,
|
|
61
|
-
};
|
|
62
|
-
const vendorStep = task => Object.hasOwn(vendorSteps, task.kind) && task.runner === 'executor' && ['ready', 'leased'].includes(task.state);
|
|
55
|
+
// A Move in step: the seed's own Move in page does the import; this computer's agent only brings the old tool's export to it.
|
|
56
|
+
const moveInStep = task => task.kind === 'move.in' && task.runner === 'executor' && ['ready', 'leased'].includes(task.state);
|
|
63
57
|
const agentQuestion = task => task.kind === 'classify.row' && task.runner === 'executor' && ['ready', 'leased'].includes(task.state);
|
|
58
|
+
const known = new Set(['discover.local', 'classify.row', 'move.in', ...ownerKinds]);
|
|
59
|
+
// A step this rer does not handle is reported by its kind, never failed.
|
|
60
|
+
const unhandledStep = task => task.runner === 'executor' && ['ready', 'leased'].includes(task.state) && !known.has(task.kind);
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
function moveLink(state, task) {
|
|
76
|
-
const tool = typeof task.tool_id === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,399}$/.test(task.tool_id) && !sensitive(task.tool_id) ? task.tool_id : null;
|
|
77
|
-
return tool ? `${ownerLink(state)}/moves/${encodeURIComponent(tool)}` : ownerLink(state);
|
|
62
|
+
const text = (value, limit) => typeof value === 'string' && value.length > 0 && value.length <= limit && !sensitive(value) ? value.replace(/\s+/g, ' ').trim() : null;
|
|
63
|
+
/** An address on the seed or in the seed's repository, or null. Only https (or http on this machine) and no credentials. */
|
|
64
|
+
function address(value) {
|
|
65
|
+
if (typeof value !== 'string' || value.length > 2000) return null;
|
|
66
|
+
try {
|
|
67
|
+
const url = new URL(value);
|
|
68
|
+
if (url.username || url.password || sensitive(value)) return null;
|
|
69
|
+
if (url.protocol === 'https:' || url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)) return url.href;
|
|
70
|
+
} catch { /* Not an address. */ }
|
|
71
|
+
return null;
|
|
78
72
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
const accepted = { file: 'a file export from the old tool', key: "a read-only key for the old tool, entered in the seed's Move in page", address: "the old tool's public address, entered in the seed's Move in page" };
|
|
74
|
+
|
|
75
|
+
/** The seed's import-format document: a GitHub link pinned to its release commit (each path part is checked on its own,
|
|
76
|
+
* and the 40-hex commit id is not a credential), or another plain address. */
|
|
77
|
+
function formatLink(value) {
|
|
78
|
+
if (typeof value !== 'string' || value.length > 2000) return null;
|
|
79
|
+
try {
|
|
80
|
+
const url = new URL(value), pinned = url.pathname.match(/^\/[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}\/blob\/([0-9a-f]{40})\/[A-Za-z0-9_.~%/-]{1,500}$/);
|
|
81
|
+
if (url.protocol === 'https:' && url.hostname === 'github.com' && pinned && !url.username && !url.password && !url.search && !url.hash
|
|
82
|
+
&& !url.pathname.split('/').some(part => part !== pinned[1] && sensitive(decodeURIComponent(part)))) return url.href;
|
|
83
|
+
} catch { /* Not an address. */ }
|
|
84
|
+
return address(value);
|
|
85
85
|
}
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
/** A Move in path on the seed (`/app/move-in`), or null. */
|
|
87
|
+
const movePath = value => typeof value === 'string' && /^\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]{0,199}$/.test(value) && !value.startsWith('//') && !sensitive(value) ? value : null;
|
|
88
|
+
|
|
89
|
+
/** What the seed's Move in step asks of this computer's agent, in words. The step carries Business's view of the seed's own
|
|
90
|
+
* declaration (its pinned `importers.json` row): `{tool, app, app_name, app_address, move_in: {state, address, path, accepts,
|
|
91
|
+
* export, format}}`, with `state` one of `declared`, `format` or `not_declared`. Only closed shapes and short text are printed. */
|
|
92
|
+
export function moveInLines(task) {
|
|
93
|
+
const view = task.move_in && typeof task.move_in === 'object' ? task.move_in : {};
|
|
94
|
+
const move = view.move_in && typeof view.move_in === 'object' ? view.move_in : {};
|
|
95
|
+
const tool = text(view.tool, 80), app = text(view.app_name, 80) ?? text(view.app, 80), home = address(view.app_address);
|
|
96
|
+
const lines = [`Step: Move ${tool ?? 'the old tool'} into ${app ?? 'its seed'} with the seed's own Move in page. The seed shows the dry run's counts, imports and undoes; Business imports nothing itself.`];
|
|
97
|
+
const format = formatLink(move.format);
|
|
98
|
+
const page = move.state === 'declared' ? address(move.address) : null, path = move.state === 'declared' ? movePath(move.path) : null;
|
|
99
|
+
if (page) lines.push(`Move in page (sign in as the owner): ${page}`);
|
|
100
|
+
else if (path) lines.push(`Move in page (sign in as the owner): ${path} on the seed${home ? ` at ${home}` : ', once it has an address'}`);
|
|
101
|
+
else {
|
|
102
|
+
lines.push(`This seed declares no Move in page for the tool.${home ? ` Its address: ${home}` : ''}`);
|
|
103
|
+
if (move.state === 'format' && format) lines.push(`Export what the old tool offers, convert it to the seed's own import format and upload it in the seed. The format: ${format}`);
|
|
104
|
+
return lines;
|
|
105
|
+
}
|
|
106
|
+
const takes = Array.isArray(move.accepts) ? move.accepts.filter(item => Object.hasOwn(accepted, item)) : [];
|
|
107
|
+
if (takes.length) lines.push(`The seed takes: ${takes.map(item => accepted[item]).join('; or ')}.`);
|
|
108
|
+
const how = text(move.export, 1000);
|
|
109
|
+
if (how) lines.push(`How to export from the old tool: ${how}`);
|
|
110
|
+
if (format) lines.push(`The seed's own import format (for a tool it has no importer for): ${format}`);
|
|
111
|
+
return lines;
|
|
89
112
|
}
|
|
90
113
|
|
|
91
114
|
/** Agent steps that wait on this computer but not on run itself, in plain words. */
|
|
92
115
|
export function agentWaiting(tasks) {
|
|
93
|
-
return tasks.some(agentQuestion) ? [`A question waits for this computer's agent. Answer it with: ${businessCommand('next')}`] : []
|
|
116
|
+
return [...(tasks.some(agentQuestion) ? [`A question waits for this computer's agent. Answer it with: ${businessCommand('next')}`] : []),
|
|
117
|
+
...(tasks.some(moveInStep) ? [`A Move in step waits for this computer's agent. See it with: ${businessCommand('next')}`] : []),
|
|
118
|
+
...(tasks.some(unhandledStep) ? [`Business has a step this version of rer does not handle (${[...new Set(tasks.filter(unhandledStep).map(task => kindName(task.kind)))].join(', ')}). Update rer, or do it in the browser.`] : [])];
|
|
94
119
|
}
|
|
120
|
+
const kindName = kind => typeof kind === 'string' && /^[a-z][a-z0-9._-]{0,63}$/.test(kind) ? kind : 'unknown';
|
|
95
121
|
|
|
96
122
|
function classification(task) {
|
|
97
123
|
const toolId = identifier(task.question?.tool_id), vendorId = task.question?.vendor_id;
|
|
@@ -118,31 +144,21 @@ export async function next() {
|
|
|
118
144
|
throw Error(`Business pairing expired or was revoked. This computer was ${revokedText(await revokedByServer(state))}`);
|
|
119
145
|
}
|
|
120
146
|
// This computer's agent hears its own steps first, then the owner's.
|
|
121
|
-
const item = tasks.find(task => task.kind === 'classify.row' ||
|
|
147
|
+
const item = tasks.find(task => task.kind === 'classify.row' || moveInStep(task)) ?? tasks.find(task => task.runner === 'owner' || ownerKinds.has(task.kind));
|
|
122
148
|
if (!item) {
|
|
123
149
|
// Nothing to answer here; say whether run has work, or what it waits for.
|
|
124
150
|
const work = tasks.find(task => Object.hasOwn(runWork, task.kind) && task.state === 'ready');
|
|
125
151
|
if (work) { process.stdout.write(`Ready for run: ${runWork[work.kind]}. Start it with: ${businessCommand('run --once')}\n`); return; }
|
|
126
|
-
|
|
152
|
+
const unhandled = agentWaiting(tasks.filter(unhandledStep));
|
|
153
|
+
process.stdout.write(`${unhandled.length ? unhandled.join('\n') + '\n' : ''}${waitingFor(state)}\nNothing yet.\n`); return;
|
|
127
154
|
}
|
|
128
155
|
const id = identifier(item.task_id);
|
|
129
156
|
if (sensitive(id)) throw Error('Business task identifier was refused by the outbound detector.');
|
|
130
|
-
const step = ownerStep(item, state);
|
|
131
|
-
if (step) {
|
|
132
|
-
process.stdout.write(`Owner: ${id}\nOwner step, not this computer's agent work: ${step.words}.\nIn the browser: ${step.link}\n`); return;
|
|
133
|
-
}
|
|
134
157
|
if (item.runner === 'owner' || ownerKinds.has(item.kind)) {
|
|
135
158
|
process.stdout.write(`Owner: ${id}\nAnswer in your browser: ${ownerLink(state)}\n`); return;
|
|
136
159
|
}
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
const vendor = titledVendor(item.kind, item.title), name = vendor ? vendorNames[vendor] : 'vendor';
|
|
140
|
-
const stored = vendor && (state.vendorHandles ?? []).includes(vendorHandle(vendor));
|
|
141
|
-
process.stdout.write(`Agent: ${id}\nStep: ${vendorSteps[item.kind](name)}\n`
|
|
142
|
-
+ (vendor && !keyed(vendor) ? `Vendor key: none; ${name} is read from its public page, with no key.\n`
|
|
143
|
-
: stored ? `Vendor key: the owner's read-only ${name} key is stored in this computer's OS credential storage. To replace it, ${keyStep(vendor)}\n`
|
|
144
|
-
: `Vendor key: ${keyStep(vendor)}${vendor ? '' : `\n where <vendor> is the tool this step reads: ${Object.keys(vendorNames).filter(keyed).join(' | ')}`}\n`)
|
|
145
|
-
+ `Then run: ${businessCommand('run --once')}\n`);
|
|
160
|
+
if (moveInStep(item)) {
|
|
161
|
+
process.stdout.write(`Agent: ${id}\n${moveInLines(item).join('\n')}\nWhen the owner has the data in the seed, finish this step: ${businessCommand(`done ${id} --note "what moved, from the dry run's counts"`)}\n`);
|
|
146
162
|
return;
|
|
147
163
|
}
|
|
148
164
|
const { toolId, vendorId, vendors } = classification(item);
|
|
@@ -158,7 +174,7 @@ export async function answer(id, vendorId, choice, rawConfidence = '1') {
|
|
|
158
174
|
const confidence = Number(rawConfidence);
|
|
159
175
|
const { state, credential } = await paired(), api = new Api(state.origin, credential), signal = AbortSignal.timeout(55_000);
|
|
160
176
|
const summary = await (await mcpClient(api, { signal }))('explain_task', { task_id: id });
|
|
161
|
-
if (summary.runner === 'owner' || ownerKinds.has(summary.kind)
|
|
177
|
+
if (summary.runner === 'owner' || ownerKinds.has(summary.kind)) throw Error(`This item requires the owner in the browser: ${ownerLink(state)}`);
|
|
162
178
|
if (summary.kind !== 'classify.row' || summary.runner !== 'executor') throw Error('This item does not accept a CLI classification answer.');
|
|
163
179
|
const { vendors } = classification(summary);
|
|
164
180
|
if (!vendors.includes(vendorId)) throw Error('Choose a catalog vendor id from this question, or none.');
|
|
@@ -175,6 +191,27 @@ export async function answer(id, vendorId, choice, rawConfidence = '1') {
|
|
|
175
191
|
process.stdout.write('Business answer submitted for server validation.\n');
|
|
176
192
|
}
|
|
177
193
|
|
|
194
|
+
/** Finish a Move in step with a short note, through the same claim-then-complete answer door as a classification. */
|
|
195
|
+
export async function done(id, flag, note) {
|
|
196
|
+
identifier(id);
|
|
197
|
+
if (flag !== '--note' || typeof note !== 'string' || !note.trim() || note.length > 500) throw Error('Finish a Move in step with: done ID --note "what moved" (up to 500 characters).');
|
|
198
|
+
if (sensitive(note)) throw Error('The note looks like it holds a secret, so it was not sent. Say what moved, without keys or tokens.');
|
|
199
|
+
const { state, credential } = await paired(), api = new Api(state.origin, credential), signal = AbortSignal.timeout(55_000);
|
|
200
|
+
const summary = await (await mcpClient(api, { signal }))('explain_task', { task_id: id });
|
|
201
|
+
if (summary.kind !== 'move.in' || summary.runner !== 'executor') throw Error('This item is not a Move in step for this computer.');
|
|
202
|
+
const tool = await mcpClient(api, { taskId: id, signal });
|
|
203
|
+
let lease = summary;
|
|
204
|
+
if (summary.state === 'ready') lease = await tool('answer', { task_id: id, action: 'claim', client_event_id: randomUUID(), fence: summary.fence });
|
|
205
|
+
if (typeof lease.grant_id !== 'string') throw Error('Business did not return a grant for this step.');
|
|
206
|
+
try {
|
|
207
|
+
await tool('answer', { task_id: id, action: 'complete', client_event_id: randomUUID(), fence: lease.fence, grant_id: lease.grant_id, outputs: { note: note.trim() } });
|
|
208
|
+
} catch (error) {
|
|
209
|
+
try { await tool('answer', { task_id: id, action: 'release', client_event_id: randomUUID(), fence: lease.fence, grant_id: lease.grant_id, reason: 'failed' }); } catch { /* Expiry/revocation still fences the lease. */ }
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
process.stdout.write('Business Move in step finished.\n');
|
|
213
|
+
}
|
|
214
|
+
|
|
178
215
|
export async function token() {
|
|
179
216
|
const { state, credential } = await paired();
|
|
180
217
|
const result = await new Api(state.origin, credential).mintToken('mcp');
|
package/cli/business/service.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execFile
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
2
|
import { mkdir, readFile, writeFile, rename, unlink, realpath, stat, lstat, rmdir } from 'node:fs/promises';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { dirname, join, isAbsolute } from 'node:path';
|
|
@@ -130,26 +130,3 @@ export async function serviceStatus(input = {}) {
|
|
|
130
130
|
: await o.run('systemctl', ['--user', 'is-active', '--quiet', unit]);
|
|
131
131
|
return { installed: true, running: result.code === 0 && (o.platform !== 'darwin' || /(?:^|\n)\s*state = running\s*(?:\n|$)/.test(result.stdout ?? '')) };
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
/** The caller holds an export lease only within this callback. -w also makes
|
|
135
|
-
* caffeinate stop if the executor is killed before its finally block runs.
|
|
136
|
-
*/
|
|
137
|
-
export async function withExportAwake(work, { consent = false, platform = process.platform, signal } = {}) {
|
|
138
|
-
if (platform !== 'darwin') return work();
|
|
139
|
-
if (consent !== true) throw new Error('Keeping this Mac awake for an export requires explicit consent.');
|
|
140
|
-
signal?.throwIfAborted();
|
|
141
|
-
const child = spawn('/usr/bin/caffeinate', ['-i', '-w', String(process.pid)], { stdio: 'ignore' });
|
|
142
|
-
const closed = new Promise(resolve => child.once('close', resolve));
|
|
143
|
-
const stop = () => { if (child.exitCode === null && !child.killed) child.kill('SIGTERM'); };
|
|
144
|
-
const onExit = () => stop();
|
|
145
|
-
try {
|
|
146
|
-
await new Promise((resolve, reject) => { child.once('spawn', resolve); child.once('error', () => reject(new Error('Could not keep this Mac awake for the export.'))); });
|
|
147
|
-
signal?.addEventListener('abort', stop, { once: true }); process.once('exit', onExit);
|
|
148
|
-
signal?.throwIfAborted();
|
|
149
|
-
return await work();
|
|
150
|
-
} finally {
|
|
151
|
-
signal?.removeEventListener('abort', stop); process.off('exit', onExit);
|
|
152
|
-
stop();
|
|
153
|
-
if (child.pid) await closed;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
@@ -1,45 +1,31 @@
|
|
|
1
1
|
import { constants } from 'node:fs';
|
|
2
|
-
import { open } from 'node:fs/promises';
|
|
3
|
-
import { setupDemo } from './setup-demo.mjs';
|
|
2
|
+
import { open, readFile } from 'node:fs/promises';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
const company = JSON.parse(await readFile(new URL('./setup-company.json', import.meta.url), 'utf8'));
|
|
5
|
+
|
|
6
|
+
// The receipt is JSON in both human and --json mode.
|
|
6
7
|
export async function setupCommand(args) {
|
|
7
|
-
try { return await setup(args)
|
|
8
|
+
try { return await setup(args); }
|
|
8
9
|
catch (error) {
|
|
9
10
|
// Paths, cookies and peer bodies must never appear in diagnostics.
|
|
10
|
-
const code=typeof error?.message==='string'&&/^[a-z0-9_]{1,100}$/.test(error.message)?error.message:'
|
|
11
|
+
const code=typeof error?.message==='string'&&/^[a-z0-9_]{1,100}$/.test(error.message)?error.message:'business_setup_failed';
|
|
11
12
|
process.stderr.write(JSON.stringify({code})+'\n');return 1;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
async function setup(args){
|
|
16
|
-
const usage=`Usage: rer business setup --origin URL --session-file FILE --confirm-demo [--hosting managed|assisted|self_host] [--wait-seconds 0..240] [--json]
|
|
17
|
-
Provision the synthetic Run your business demo through the platform's owner routes.
|
|
18
|
-
Run again to resume; completed seeds are read without provisioning again.
|
|
19
|
-
|
|
20
|
-
--origin URL Platform address to set up the demo on.
|
|
21
|
-
--session-file FILE The signed-in session file Business setup reads: an owned,
|
|
22
|
-
regular 0600 file containing rer_session=VALUE or
|
|
23
|
-
__Host-rer_session=VALUE. Symlinks are refused.
|
|
24
|
-
The session is sent only as the platform Cookie header.
|
|
25
|
-
--confirm-demo Required confirmation to provision the synthetic demo.
|
|
26
|
-
--hosting MODE managed (default), assisted or self_host.
|
|
27
|
-
--wait-seconds N Provisioning wait, 0..240 seconds (default: 240).
|
|
28
|
-
--json Print the platform JSON receipt (also the default).
|
|
29
|
-
--help, -h Show this help without reading the session file.`;
|
|
30
|
-
if(args.some(arg => ['--help', '-h'].includes(arg))){process.stdout.write(usage+'\n');return;}
|
|
31
17
|
const options={};
|
|
32
18
|
for(let i=0;i<args.length;i++){
|
|
33
19
|
if(args[i]==='--json'&&!options.json){options.json=true;continue;}
|
|
34
20
|
if(args[i]==='--confirm-demo'){options.confirm=true;continue;}
|
|
35
|
-
if(!['--origin','--session-file','--hosting'
|
|
21
|
+
if(!['--origin','--session-file','--hosting'].includes(args[i])||!args[i+1]||Object.hasOwn(options,args[i]))throw Error('demo_arguments_invalid');
|
|
36
22
|
options[args[i]]=args[++i];
|
|
37
23
|
}
|
|
38
24
|
if(!options.confirm||!options['--origin']||!options['--session-file'])throw Error('demo_confirmation_and_session_file_required');
|
|
39
25
|
const url=new URL(options['--origin']);
|
|
40
26
|
if(url.username||url.password||url.search||url.hash||url.pathname!=='/'||url.protocol!=='https:'&&!(url.protocol==='http:'&&['localhost','127.0.0.1','[::1]'].includes(url.hostname)))throw Error('demo_origin_invalid');
|
|
41
|
-
const hosting=options['--hosting']??'managed'
|
|
42
|
-
if(!['managed','assisted','self_host'].includes(hosting)
|
|
27
|
+
const hosting=options['--hosting']??'managed';
|
|
28
|
+
if(!['managed','assisted','self_host'].includes(hosting))throw Error('demo_arguments_invalid');
|
|
43
29
|
const handle=await open(options['--session-file'],constants.O_RDONLY|constants.O_NOFOLLOW);
|
|
44
30
|
let cookie;
|
|
45
31
|
try{
|
|
@@ -49,14 +35,35 @@ Run again to resume; completed seeds are read without provisioning again.
|
|
|
49
35
|
if(!/^(?:__Host-)?rer_session=[^\s;]+$/.test(cookie))throw Error('demo_session_file_invalid');
|
|
50
36
|
const session=cookie.slice(cookie.indexOf('=')+1);
|
|
51
37
|
try {
|
|
52
|
-
const
|
|
53
|
-
const output=JSON.stringify(receipt,null,2)+'\n';
|
|
38
|
+
const output=JSON.stringify(await createBusiness({origin:url.origin,cookie,hosting}),null,2)+'\n';
|
|
54
39
|
if(output.includes(session))throw Error('demo_session_in_response');
|
|
55
40
|
process.stdout.write(output);
|
|
56
|
-
if(receipt.complete !== true)return 1;
|
|
57
41
|
return 0;
|
|
58
42
|
} catch(error) {
|
|
59
43
|
if(String(error?.message).includes(session))throw Error('demo_session_in_response');
|
|
60
44
|
throw error;
|
|
61
45
|
}
|
|
62
46
|
}
|
|
47
|
+
|
|
48
|
+
/** Create, or reuse, the Business named in setup-company.json and give it that profile, through the owner's Business routes.
|
|
49
|
+
* A repeat whose Business and profile already match reads only. Cookies and peer bodies never enter the receipt. */
|
|
50
|
+
async function createBusiness({origin,cookie,hosting}){
|
|
51
|
+
const api=async(path,method='GET',body)=>{
|
|
52
|
+
let response;
|
|
53
|
+
try{response=await fetch(new URL(path,origin),{method,redirect:'manual',signal:AbortSignal.timeout(60000),headers:{Origin:origin,Cookie:cookie,'Content-Type':'application/json'},...(body===undefined?{}:{body:JSON.stringify(body)})});}
|
|
54
|
+
catch{throw Error('platform_transport_unavailable');}
|
|
55
|
+
let answer;try{answer=await response.json();}catch{throw Error(`platform_http_${response.status}`);}
|
|
56
|
+
if(!response.ok){const code=answer?.code;throw Error(typeof code==='string'&&/^[a-z0-9_]{1,100}$/.test(code)?code:`platform_http_${response.status}`);}
|
|
57
|
+
return answer;
|
|
58
|
+
};
|
|
59
|
+
let business=(await api('/api/business')).businesses?.find(row=>row.name===company.name);
|
|
60
|
+
const created=!business;
|
|
61
|
+
if(created)business=(await api('/api/business','POST',{name:company.name,default_hosting:hosting,executor_preference:hosting==='self_host'?'local':'managed'})).business;
|
|
62
|
+
if(typeof business?.id!=='string')throw Error('platform_business_invalid');
|
|
63
|
+
if(business.default_hosting!==hosting)throw Error('existing_demo_hosting_differs');
|
|
64
|
+
const root='/api/business/'+encodeURIComponent(business.id);
|
|
65
|
+
const current=created?{}:(await api(root+'/profile')).profile??{};
|
|
66
|
+
const changed=Object.entries(company.profile).some(([field,value])=>current[field]!==value);
|
|
67
|
+
if(changed)await api(root+'/profile','PUT',company.profile);
|
|
68
|
+
return {business_id:business.id,name:company.name,default_hosting:hosting,created,profile:changed?'saved':'unchanged'};
|
|
69
|
+
}
|
package/cli/business/state.mjs
CHANGED
|
@@ -92,7 +92,7 @@ const owned = /^(?:(?:state|pairing|progress|permissions|service|carried)\.json|
|
|
|
92
92
|
export async function removeWorkFiles(keep = ['state.json', 'permissions.json', 'service.json']) {
|
|
93
93
|
let entries;
|
|
94
94
|
try { entries = await readdir(stateDirectory()); } catch (error) { if (error.code === 'ENOENT') return; throw error; }
|
|
95
|
-
for (const name of entries) if (owned.test(name) && !keep.includes(name)) await rm(join(stateDirectory(), name), { force: true });
|
|
95
|
+
for (const name of entries) if (owned.test(name) && !keep.includes(name)) await rm(join(stateDirectory(), name), { recursive: true, force: true });
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export async function removeStateDirectory() {
|
|
@@ -105,7 +105,7 @@ export async function removeStateDirectory() {
|
|
|
105
105
|
}
|
|
106
106
|
let entries;
|
|
107
107
|
try { entries = await readdir(directory); } catch (error) { if (error.code === 'ENOENT') return; throw error; }
|
|
108
|
-
for (const name of entries) if (owned.test(name)) await rm(join(directory, name), { force: true });
|
|
108
|
+
for (const name of entries) if (owned.test(name)) await rm(join(directory, name), { recursive: true, force: true });
|
|
109
109
|
await rmdir(directory).catch(error => { if (!['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(error.code)) throw error; });
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -2,55 +2,27 @@ import { startCarryRefresh } from './carry.mjs';
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { access, unlink } from 'node:fs/promises';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { Api,
|
|
5
|
+
import { Api, pause } from './api.mjs';
|
|
6
6
|
import { paired, revokedByServer, revokedText } from './local-commands.mjs';
|
|
7
|
-
import { nextQuestions, ownerLink, waitingFor, agentWaiting
|
|
7
|
+
import { nextQuestions, ownerLink, waitingFor, agentWaiting } from './questions.mjs';
|
|
8
8
|
import { lockSupervisor, stateDirectory, saveState, loadState } from './state.mjs';
|
|
9
9
|
import { loadProgress, saveProgress } from './progress.mjs';
|
|
10
10
|
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, titledVendor } from './vendor-door.mjs';
|
|
15
|
-
import { runExport } from './export-task.mjs';
|
|
16
|
-
import { runCatchup } from './catchup-task.mjs';
|
|
17
|
-
import { runArchive } from './archive-task.mjs';
|
|
18
14
|
|
|
19
|
-
// The
|
|
20
|
-
const
|
|
21
|
-
const kinds = new Set(['discover.local', ...Object.keys(vendorWork)]);
|
|
15
|
+
// The one task this computer performs itself: the names-only folder scan. Move in and every other step is reported by `next`.
|
|
16
|
+
const kinds = new Set(['discover.local']);
|
|
22
17
|
export function supportsTaskKind(kind) { return kinds.has(kind); }
|
|
23
18
|
const checkIn = 25_000;
|
|
24
19
|
|
|
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
|
-
|
|
46
20
|
/** Work this computer's tasks. It says what it is doing and what it waits
|
|
47
21
|
* for, applies the owner's choices at every check-in, and removes run.lock on
|
|
48
22
|
* every exit, including Ctrl-C, SIGTERM and a closed terminal (SIGHUP). */
|
|
49
23
|
export async function run({ once = false } = {}) {
|
|
50
24
|
const { state, credential } = await paired(), api = new Api(state.origin, credential), directory = stateDirectory();
|
|
51
|
-
|
|
52
|
-
// waiting only for the owner's vendor key is picked up again once it is stored.
|
|
53
|
-
const parked = new Map(), ownerWaits = new Map(), unlock = await lockSupervisor(), stop = new AbortController();
|
|
25
|
+
const unlock = await lockSupervisor(), stop = new AbortController();
|
|
54
26
|
// A terminal's Ctrl-C reaches npx and this process together, and npx then
|
|
55
27
|
// forwards another SIGINT, which can arrive at any moment until this process
|
|
56
28
|
// has exited. So the handlers stay for the rest of the process: a repeated
|
|
@@ -63,9 +35,8 @@ export async function run({ once = false } = {}) {
|
|
|
63
35
|
let progress, stopCarry, said = '', held = null, summaries = [];
|
|
64
36
|
const say = text => { if (text !== said) { said = text; process.stdout.write(text + '\n'); } };
|
|
65
37
|
// An agent step that waits is said in its own words, never as "Nothing yet".
|
|
66
|
-
const waits = () =>
|
|
67
|
-
|
|
68
|
-
const idle = () => { const owner = ownerWaiting(summaries, state); return owner.length ? owner.join('\n') : waitingFor(state); };
|
|
38
|
+
const waits = () => agentWaiting(summaries);
|
|
39
|
+
const idle = () => waitingFor(state);
|
|
69
40
|
try {
|
|
70
41
|
stopCarry = await startCarryRefresh(api, state, stop.signal);
|
|
71
42
|
progress = await loadProgress();
|
|
@@ -81,12 +52,7 @@ export async function run({ once = false } = {}) {
|
|
|
81
52
|
}
|
|
82
53
|
if (!progress.pendingClaim) {
|
|
83
54
|
summaries = await nextQuestions(api, stop.signal);
|
|
84
|
-
|
|
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);
|
|
87
|
-
const handles = (await loadState())?.vendorHandles ?? [];
|
|
88
|
-
for (const [id, wait] of parked) if (wait.keyMissing && handles.includes(vendorHandle(wait.keyMissing))) parked.delete(id);
|
|
89
|
-
const selected = summaries.find(task => kinds.has(task.kind) && ['ready','leased'].includes(task.state) && !parked.has(task.task_id));
|
|
55
|
+
const selected = summaries.find(task => kinds.has(task.kind) && ['ready','leased'].includes(task.state));
|
|
90
56
|
if (!selected) {
|
|
91
57
|
const waiting = waits();
|
|
92
58
|
say(waiting.length ? waiting.join('\n') : idle());
|
|
@@ -100,18 +66,10 @@ export async function run({ once = false } = {}) {
|
|
|
100
66
|
let claimed;
|
|
101
67
|
try { claimed = await api.post('/api/business/executors/claim', { ...progress.pendingClaim, wait_seconds: 25 }, { signal: stop.signal }); }
|
|
102
68
|
catch (error) {
|
|
103
|
-
|
|
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);
|
|
69
|
+
if (error.status !== 409) throw error;
|
|
112
70
|
progress = {}; await saveProgress(progress);
|
|
113
71
|
held = null;
|
|
114
|
-
if (once)
|
|
72
|
+
if (once) throw error;
|
|
115
73
|
await pause(checkIn, stop.signal); continue;
|
|
116
74
|
}
|
|
117
75
|
if (!claimed.task || claimed.task.state !== 'leased' || claimed.task.fence !== claimed.fence || Date.parse(claimed.lease_expires_at) <= Date.now()) {
|
|
@@ -135,51 +93,28 @@ export async function run({ once = false } = {}) {
|
|
|
135
93
|
try {
|
|
136
94
|
progress.current = { kind: claimed.task.kind, checkpoint: claimed.task.checkpoint, uploadedBytes: claimed.task.checkpoint?.bytes_done ?? 0 };
|
|
137
95
|
await saveProgress(progress);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
} else {
|
|
151
|
-
const page = claimed.task.checkpoint?.page;
|
|
152
|
-
say(page ? `Resuming the names-only scan of this computer's allowed folders from page ${page + 1}.` : 'Scanning this computer\'s allowed folders for tool names (names only; no file contents leave this computer).');
|
|
153
|
-
const result = await runDiscovery({ task: claimed.task, grant: claimed.grant, checkpoint: claimed.task.checkpoint, signal: lease.signal,
|
|
154
|
-
send: (destination, body) => lease.send(destination, body), stateDir: directory,
|
|
155
|
-
saveCheckpoint: async checkpoint => {
|
|
156
|
-
await lease.checkpointSaved(checkpoint);
|
|
157
|
-
if (checkpoint.page) process.stdout.write(`Sent page ${checkpoint.page} of ${checkpoint.total}; the server has ${checkpoint.records_done} names and saved this checkpoint.\n`);
|
|
158
|
-
} });
|
|
159
|
-
await lease.complete(); finished = true;
|
|
160
|
-
await result.cleanup();
|
|
161
|
-
if (!state.discovered) { state.discovered = true; await saveState(state); }
|
|
162
|
-
say('Business discover.local completed and checked by the server.');
|
|
163
|
-
}
|
|
96
|
+
const page = claimed.task.checkpoint?.page;
|
|
97
|
+
say(page ? `Resuming the names-only scan of this computer's allowed folders from page ${page + 1}.` : 'Scanning this computer\'s allowed folders for tool names (names only; no file contents leave this computer).');
|
|
98
|
+
const result = await runDiscovery({ task: claimed.task, grant: claimed.grant, checkpoint: claimed.task.checkpoint, signal: lease.signal,
|
|
99
|
+
send: (destination, body) => lease.send(destination, body), stateDir: directory,
|
|
100
|
+
saveCheckpoint: async checkpoint => {
|
|
101
|
+
await lease.checkpointSaved(checkpoint);
|
|
102
|
+
if (checkpoint.page) process.stdout.write(`Sent page ${checkpoint.page} of ${checkpoint.total}; the server has ${checkpoint.records_done} names and saved this checkpoint.\n`);
|
|
103
|
+
} });
|
|
104
|
+
await lease.complete(); finished = true;
|
|
105
|
+
await result.cleanup();
|
|
106
|
+
if (!state.discovered) { state.discovered = true; await saveState(state); }
|
|
107
|
+
say('Business discover.local completed and checked by the server.');
|
|
164
108
|
} catch (error) { failure = lease.signal.aborted ? lease.signal.reason : error; }
|
|
165
109
|
finally {
|
|
166
|
-
if (!finished && failure?.status !== 401
|
|
167
|
-
try { await lease.release(stop.signal.aborted ? 'handover' :
|
|
110
|
+
if (!finished && failure?.status !== 401) {
|
|
111
|
+
try { await lease.release(stop.signal.aborted ? 'handover' : 'failed'); released = true; }
|
|
168
112
|
catch (error) { if (error.status === 401) failure = error; }
|
|
169
113
|
}
|
|
170
114
|
await lease.close();
|
|
171
|
-
if (finished || released
|
|
172
|
-
}
|
|
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
|
-
}
|
|
180
|
-
if (failure.status === 401 || once || !parked.has(claimed.task.id)) throw failure;
|
|
181
|
-
process.stderr.write(failure.message + '\n');
|
|
115
|
+
if (finished || released) { progress = {}; await saveProgress(progress); }
|
|
182
116
|
}
|
|
117
|
+
if (failure) throw failure;
|
|
183
118
|
if (once) return;
|
|
184
119
|
} while (!stop.signal.aborted);
|
|
185
120
|
} catch (error) {
|
|
@@ -5,6 +5,7 @@ import { loadState, saveState } from './state.mjs';
|
|
|
5
5
|
import { map, commands, pair, pairUsage } from './setup.mjs';
|
|
6
6
|
import { codexAuth, claudeAuth } from './auth.mjs';
|
|
7
7
|
import { assertSandboxPlatform } from './providers/sandbox.mjs';
|
|
8
|
+
import { appSignInHelp } from '../app-address.mjs';
|
|
8
9
|
|
|
9
10
|
export const usage = `Usage: rer companion VERB
|
|
10
11
|
Pairs this computer with a Run Edit Run app, then runs the app's change
|
|
@@ -35,6 +36,7 @@ State: ~/.rer-local (RER_LOCAL_HOME picks another private folder). The device ke
|
|
|
35
36
|
is kept there (0600); the app keeps only its hash.
|
|
36
37
|
Revoke: in the app, Settings > Devices > Revoke. A running companion stops at its
|
|
37
38
|
next request. Then delete the state folder on this computer.
|
|
39
|
+
${appSignInHelp}
|
|
38
40
|
`;
|
|
39
41
|
|
|
40
42
|
async function locked(root,work) {
|
package/cli/demo-native.mjs
CHANGED
|
@@ -22,7 +22,7 @@ export async function nativeDemoCommand(project, options, store, signal, out, op
|
|
|
22
22
|
await demoBundle(project, operation, app, join(folder, 'bundle'), store, label, signal);
|
|
23
23
|
for (const file of DEMO_FILES) await cp(new URL(`../modules/demo-host/${file}`, import.meta.url), join(folder, 'modules/demo-host', file));
|
|
24
24
|
for (const file of RUNTIME_FILES) await cp(new URL(`../modules/demo-host/native/${file}.mjs`, import.meta.url), join(folder, `modules/demo-host/native/${file}.mjs`));
|
|
25
|
-
for (const directory of ['deploy-kit']) await cp(new URL(`../modules/${directory}/`, import.meta.url), join(folder, 'modules', directory), { recursive: true });
|
|
25
|
+
for (const directory of ['deploy-kit', 'd1-transport']) await cp(new URL(`../modules/${directory}/`, import.meta.url), join(folder, 'modules', directory), { recursive: true });
|
|
26
26
|
await mkdir(join(folder, 'modules/container/adapters'), { recursive: true });
|
|
27
27
|
await cp(new URL('../modules/container/adapters/d1-limits.mjs', import.meta.url), join(folder, 'modules/container/adapters/d1-limits.mjs'));
|
|
28
28
|
for (const file of ['migrations.mjs', 'demo-egress.mjs']) await cp(new URL(`../modules/container/${file}`, import.meta.url), join(folder, 'modules/container', file));
|
package/cli/deploy-command.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { requireProductionAuth } from './production-auth.mjs';
|
|
1
|
+
import { requireProductionAuth, mailOffNotice } from './production-auth.mjs';
|
|
2
2
|
import { observedReadiness } from '../modules/deploy-kit/readiness-window.mjs';
|
|
3
3
|
import { readFile, readdir } from 'node:fs/promises';
|
|
4
4
|
import { contained } from './project.mjs';
|
|
@@ -85,7 +85,8 @@ export async function deployCommand(context) {
|
|
|
85
85
|
const production = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
|
|
86
86
|
const plan = result?.plan ?? (await owner(['local-plan', '--declaration', path, '--environment', options.environment ?? 'production', ...await deployProductArguments(root, deployProductDirectory(declaration))], production.env, { cwd: root, localOnlyKeys })).plan;
|
|
87
87
|
result = { ...result, dryRun: true, deployed: false, providerChecked: false, plan };
|
|
88
|
-
const { signIn } = await requireProductionAuth({ root, declaration, env: production.env, setupManifest, setupSeed: context.setupSeed, adapter, declarationPath: path, options }) ?? {};
|
|
88
|
+
const { signIn, mailOff } = await requireProductionAuth({ root, declaration, env: production.env, setupManifest, setupSeed: context.setupSeed, adapter, declarationPath: path, options }) ?? {};
|
|
89
|
+
if (mailOff) store.report(mailOffNotice(mailOff, options.environment ?? 'production'));
|
|
89
90
|
const needed = [...new Set([...neededForRealDeploy({ declaration, env: production.env, signIn, secretsChecked: false }), ...(result.neededForRealDeploy ?? [])])];
|
|
90
91
|
reportNeeded(store, needed);
|
|
91
92
|
if (declaration.secrets?.some(item => item.binding === 'INSTALLATION_KEY')) store.report('deploy: INSTALLATION_KEY is a private generated binding; INSTALLATION_KEY_PREVIOUS is optional and managed only during rotation or an explicit retired-key reopen. Values are withheld.');
|
|
@@ -110,7 +111,7 @@ export async function deployCommand(context) {
|
|
|
110
111
|
if (adapter.deploy.managesHostedOwner) { const result = await runHook(context); return options.dryRun ? dryRun(result) : result; }
|
|
111
112
|
const productDirectory = deployProductDirectory(declaration);
|
|
112
113
|
const production = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
|
|
113
|
-
await requireProductionAuth({ root, declaration, env: production.env, setupManifest, setupSeed: context.setupSeed, adapter, declarationPath: path, options });
|
|
114
|
+
const { mailOff } = await requireProductionAuth({ root, declaration, env: production.env, setupManifest, setupSeed: context.setupSeed, adapter, declarationPath: path, options }) ?? {};
|
|
114
115
|
const sourceSha = options.dryRun ? undefined : committedSource(root, options);
|
|
115
116
|
const ownerInput = await deployOwnerInput(context);
|
|
116
117
|
const { env, supplied, generated, reused, rotated } = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
|
|
@@ -180,7 +181,7 @@ export async function deployCommand(context) {
|
|
|
180
181
|
const { setupToken: _, ...result } = deployed;
|
|
181
182
|
return { ...result, ...(claimed ? { owner: claimed } : {}), dependenciesLinked: true };
|
|
182
183
|
});
|
|
183
|
-
if (claimed) store.report(`${claimed === 'claimed' ? 'Claimed the hosted owner' : 'The hosted owner was already claimed and was kept'}${recorded ? '; the one-time setup token was removed' : ''}. Sign in by email at ${result.origin}.`);
|
|
184
|
+
if (claimed) store.report(`${claimed === 'claimed' ? 'Claimed the hosted owner' : 'The hosted owner was already claimed and was kept'}${recorded ? '; the one-time setup token was removed' : ''}. ${mailOff ? mailOffNotice(mailOff, environment) : `Sign in by email at ${result.origin}.`}`);
|
|
184
185
|
return result;
|
|
185
186
|
} catch (error) {
|
|
186
187
|
if (error instanceof DeployProductError) throw error;
|
package/cli/deploy-inputs.mjs
CHANGED
|
@@ -79,7 +79,7 @@ export async function withDeployEnvironment(project, options, out, run) {
|
|
|
79
79
|
const redaction = createRedaction();
|
|
80
80
|
// Provider names are public enum values. Masking "resend" would also hide
|
|
81
81
|
// RESEND_API_KEY in the preflight's instruction for the missing credential.
|
|
82
|
-
const publicProvider = (key, value) => key === 'MAIL_PROVIDER' && /^(resend|sendgrid|cloudflare|rer|later)$/.test(value);
|
|
82
|
+
const publicProvider = (key, value) => key === 'MAIL_PROVIDER' && /^(resend|sendgrid|cloudflare|rer|later|none)$/.test(value);
|
|
83
83
|
const supplied = Object.entries(env).filter(([key, value]) => saved[key] !== value);
|
|
84
84
|
redaction.addSecrets([...kinds.privateValues(env), ...supplied.filter(([key, value]) => !kinds.shown(key, value) && !publicProvider(key, value)).map(([, value]) => value)]);
|
|
85
85
|
const undeclared = declared.declaration ? kinds.undeclared(supplied.map(([key]) => key)) : [];
|