@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.
- package/cli/README.md +8 -0
- package/cli/bounded.mjs +3 -3
- package/cli/business/agent-output.mjs +4 -2
- package/cli/business/agent-verbs.mjs +10 -4
- package/cli/business/api.mjs +12 -9
- package/cli/business/carry.mjs +3 -2
- package/cli/business/choices.mjs +4 -1
- package/cli/business/connect.mjs +2 -1
- package/cli/business/local-commands.mjs +4 -1
- package/cli/business/mcp-bridge.mjs +7 -2
- package/cli/business/questions.mjs +5 -4
- package/cli/business/refusal.mjs +47 -0
- package/cli/business/run-grant.mjs +15 -16
- package/cli/business/setup-command.mjs +7 -2
- package/cli/business/supervisor.mjs +4 -1
- package/cli/deploy.mjs +2 -1
- package/cli/dev-identity.mjs +7 -0
- package/cli/errors.mjs +45 -9
- package/cli/export.mjs +1 -0
- package/cli/inspect.mjs +2 -0
- package/cli/main.mjs +17 -3
- package/cli/managed-server.mjs +8 -4
- package/cli/portability-empty.mjs +4 -2
- package/cli/portability-evidence.mjs +9 -1
- package/cli/portability-migrations.mjs +30 -8
- package/cli/portability-owners.mjs +54 -0
- package/cli/portability-worker.mjs +13 -5
- package/cli/portability.mjs +6 -4
- package/cli/render-warmup.mjs +31 -0
- package/cli/setup-input.mjs +14 -2
- package/cli/site-private.mjs +9 -1
- package/cli/site.mjs +5 -5
- package/edition-authoring/cli.mjs +3 -0
- package/edition-authoring/project-hashes.mjs +58 -0
- package/global/CHANGELOG.md +45 -0
- package/global/launch/dev.mjs +2 -2
- package/global/launch/render.mjs +12 -1
- package/global/launch/state.mjs +11 -4
- package/global/launch/worker.mjs +22 -5
- package/modules/deploy-kit/owner-cli.mjs +5 -2
- package/modules/deploy-kit/owner-remove.mjs +23 -5
- package/modules/job-queue/identity.mjs +11 -6
- package/modules/job-queue/policy.mjs +16 -2
- package/modules/operator-auth/README.md +6 -0
- package/modules/operator-auth/accounts/oa.mjs +1 -1
- package/modules/operator-auth/dev/index.mjs +32 -14
- package/modules/operator-auth/dev/persona-entry.mjs +38 -0
- package/modules/operator-auth/dev/persona-grant.mjs +16 -0
- package/modules/operator-auth/dev-admission.d.mts +2 -2
- package/modules/operator-auth/dev-admission.mjs +2 -2
- package/modules/operator-auth/dev-gate-script.mjs +28 -0
- package/modules/operator-auth/dev-gate.mjs +7 -10
- package/modules/portability/README.md +7 -2
- package/modules/portability/bridge.mjs +25 -23
- package/modules/portability/checkout-history.mjs +7 -6
- package/modules/portability/export.mjs +6 -3
- package/modules/portability/format.mjs +2 -2
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/http.mjs +2 -2
- package/modules/portability/import.mjs +13 -11
- package/modules/portability/index.d.mts +4 -2
- package/modules/portability/index.mjs +2 -2
- package/modules/portability/ledgers.mjs +16 -3
- package/modules/portability/legacy-files.mjs +3 -3
- package/modules/portability/migration-history.mjs +4 -3
- package/modules/portability/owner-history.mjs +62 -0
- package/modules/portability/worker-history.d.mts +1 -0
- package/modules/portability/worker-history.mjs +4 -4
- package/modules/release/README.md +7 -0
- package/modules/release/produce.mjs +3 -0
- package/onboarding/adapter.mjs +9 -9
- package/onboarding/commands.mjs +15 -5
- package/onboarding/operator-installer.mjs +2 -2
- package/onboarding/operator-settings.mjs +10 -8
- package/onboarding/redaction.mjs +1 -1
- package/package.json +1 -1
package/cli/README.md
CHANGED
|
@@ -106,6 +106,14 @@ An available persona API or health endpoint alone cannot establish that the
|
|
|
106
106
|
owner's page is ready. Inline recovery-script text is not mistaken for a visible
|
|
107
107
|
busy page.
|
|
108
108
|
|
|
109
|
+
Before that readiness check, `rer dev` asks the app for one document no route
|
|
110
|
+
claims (`/rer-warmup`) and waits for any answer, so the app's router has rendered
|
|
111
|
+
once and the on-demand server module graph is loaded. A fresh install's owner entry
|
|
112
|
+
lands on first-run setup, which renders no route; without this step the whole
|
|
113
|
+
graph loaded under the owner's first signed-in page after setup, and every
|
|
114
|
+
signed-in request waited behind it. Five minutes without an answer exits 1 with
|
|
115
|
+
`first_render_failed`.
|
|
116
|
+
|
|
109
117
|
`rer dev` runs the local migration hook before starting the app and checking its
|
|
110
118
|
owner prerequisites. The shared operator hook reads every SQL file in the seed's
|
|
111
119
|
canonical `migrations/core` inventory, including changes pulled since the last
|
package/cli/bounded.mjs
CHANGED
|
@@ -13,14 +13,14 @@ import {RerError} from './errors.mjs';
|
|
|
13
13
|
export async function boundedCommand(project,options,argv,out){
|
|
14
14
|
if(!['install','setup','build','verify','deploy','export','import','size'].includes(options.verb))return null;
|
|
15
15
|
const {commandPolicy,queuedCommand,queueLabel,maxWaitSeconds}=await shared('queue.mjs');
|
|
16
|
-
const policy=await commandPolicy();
|
|
17
16
|
const childArgs=[...argv];const cwdIndex=childArgs.indexOf('--cwd');if(cwdIndex>=0&&(childArgs.indexOf('--')<0||cwdIndex<childArgs.indexOf('--')))childArgs[cwdIndex+1]=project.root;
|
|
18
17
|
const directory=await mkdtemp(join(tmpdir(),'rer-bounded-'));
|
|
19
|
-
let store,result,finalEvent,errorEvent,buffer='';const unclosed=[];
|
|
18
|
+
let policy,store,result,finalEvent,errorEvent,buffer='';const unclosed=[];
|
|
20
19
|
const cancellation=new AbortController();
|
|
21
20
|
const handlers=new Map(['SIGINT','SIGTERM'].map(name=>[name,()=>cancellation.abort(name)]));
|
|
22
21
|
for(const [name,handler] of handlers)process.on(name,handler);
|
|
23
22
|
try{
|
|
23
|
+
policy=await commandPolicy();
|
|
24
24
|
const {createCommands}=await shared('commands.mjs');
|
|
25
25
|
store=await createCommands(directory,{logs:[]},{terminal:()=>{}});
|
|
26
26
|
result=await queuedCommand(process.execPath,[fileURLToPath(new URL('../bin/rer.mjs',import.meta.url)),...childArgs],{
|
|
@@ -55,7 +55,7 @@ export async function boundedCommand(project,options,argv,out){
|
|
|
55
55
|
});
|
|
56
56
|
}finally{
|
|
57
57
|
// Every closer runs: a policy socket left listening keeps this process alive.
|
|
58
|
-
for(const close of [()=>store?.closeCommands(),()=>policy
|
|
58
|
+
for(const close of [()=>store?.closeCommands(),()=>policy?.close(),()=>rm(directory,{recursive:true,force:true})]){try{await close();}catch(error){unclosed.push(error);}}
|
|
59
59
|
for(const [name,handler] of handlers)process.off(name,handler);
|
|
60
60
|
}
|
|
61
61
|
if(unclosed.length)out.progress(`Local cleanup could not confirm that every helper process stopped (${unclosed.map(error=>store?.redact?.(String(error?.message))??'unknown cause').join('; ')}). The ${options.verb} itself finished.\n`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { redact } from './errors.mjs';
|
|
2
|
+
import { refusalData, serverSaid } from './refusal.mjs';
|
|
2
3
|
|
|
3
4
|
const scalar = value => value === null || ['string', 'number', 'boolean'].includes(typeof value);
|
|
4
5
|
export const clean = (value, limit = 300) => redact(typeof value === 'string' ? value : JSON.stringify(value)).replace(/\s+/g, ' ').trim().slice(0, limit);
|
|
@@ -27,11 +28,12 @@ export function plain(tool, data) {
|
|
|
27
28
|
|
|
28
29
|
/** Why a tool refused, in words the person reading an agent's transcript can act on. */
|
|
29
30
|
export function refusalText(data, ownerPage) {
|
|
30
|
-
|
|
31
|
+
data = refusalData(data);
|
|
32
|
+
const message = data.message || null;
|
|
31
33
|
if (data?.status === 'not_built') return `Not built yet: ${message ?? 'Business has not built this yet.'}`;
|
|
32
34
|
if (data?.status === 'action_not_granted') {
|
|
33
35
|
const action = typeof data.action === 'string' ? clean(data.action, 80) : 'this action';
|
|
34
|
-
return `The owner has not let this computer do "${action}". The owner grants it in Business, under Computers: ${ownerPage}`;
|
|
36
|
+
return `The owner has not let this computer do "${action}". The owner grants it in Business, under Computers: ${ownerPage}${serverSaid(message)}`;
|
|
35
37
|
}
|
|
36
38
|
const code = typeof data?.code === 'string' ? ` (${clean(data.code, 80)})` : '';
|
|
37
39
|
return `Business refused: ${message ?? data?.status ?? 'no reason given'}${code}`;
|
|
@@ -9,6 +9,7 @@ import { plain, refusalText, clean } from './agent-output.mjs';
|
|
|
9
9
|
import { waitFor, failedState, stateName, exitStillWaiting } from './agent-wait.mjs';
|
|
10
10
|
import { agentUsage } from './agent-help.mjs';
|
|
11
11
|
import { maskDeviceText } from './run-mask.mjs';
|
|
12
|
+
import { refusalView, refusalData, toolRefusal, serverSaid } from './refusal.mjs';
|
|
12
13
|
|
|
13
14
|
export const exitNotBuilt = 3;
|
|
14
15
|
|
|
@@ -19,13 +20,18 @@ class Refused extends Error {
|
|
|
19
20
|
// A tool's structuredContent, or the refusal it came back with.
|
|
20
21
|
async function invoke(session, tool, args) {
|
|
21
22
|
const result = await session.call(tool, args);
|
|
22
|
-
if (result?.isError) throw new Refused(result
|
|
23
|
+
if (result?.isError) throw new Refused(toolRefusal(result));
|
|
23
24
|
if (!result?.structuredContent || typeof result.structuredContent !== 'object') throw Error(`Business returned no result for ${tool}.`);
|
|
24
25
|
return result.structuredContent;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
const idOf = (data, key) => data[key]?.id ?? data[`${key}_id`];
|
|
28
29
|
|
|
30
|
+
function failed(data, subject) {
|
|
31
|
+
const safe = refusalData({ ...data, data: data.change ?? data.update, status: stateName(data) });
|
|
32
|
+
return Object.assign(Error(`The ${subject} ${clean(stateName(data), 60)}.${serverSaid(safe.message)}`), { exitCode: 1, data: safe });
|
|
33
|
+
}
|
|
34
|
+
|
|
29
35
|
async function change(row, args, control, session, say) {
|
|
30
36
|
let data = await invoke(session, row.tool, args);
|
|
31
37
|
const id = idOf(data, 'change') ?? args.change_id;
|
|
@@ -45,7 +51,7 @@ async function change(row, args, control, session, say) {
|
|
|
45
51
|
}
|
|
46
52
|
data = waited.data;
|
|
47
53
|
if (!waited.ended) throw Object.assign(Error(`Still working after ${control.timeout ?? 1800} seconds. Keep waiting with: ${businessCommand(`change follow ${id} --wait`)}`), { exitCode: exitStillWaiting, data });
|
|
48
|
-
if (failedState(data)) throw
|
|
54
|
+
if (failedState(data)) throw failed(data, 'change');
|
|
49
55
|
if (data.next === 'ask_owner') say('The owner needs to answer something in Business before this can go on.');
|
|
50
56
|
else if (data.next === 'publish') say(`Its preview is ready. Publish it with: ${businessCommand(`change publish ${id}`)}`);
|
|
51
57
|
return data;
|
|
@@ -56,7 +62,7 @@ async function update(row, args, control, session, say) {
|
|
|
56
62
|
if (!control.wait) return data;
|
|
57
63
|
const waited = await waitFor(() => invoke(session, 'update.follow', args), { say: state => say(`Update ${args.installation_id}: ${state}`), timeout: control.timeout, interval: control.interval });
|
|
58
64
|
if (!waited.ended) throw Object.assign(Error(`Still working after ${control.timeout ?? 1800} seconds. Keep waiting with: ${businessCommand(`update follow ${args.installation_id} --wait`)}`), { exitCode: exitStillWaiting, data: waited.data });
|
|
59
|
-
if (failedState(waited.data)) throw
|
|
65
|
+
if (failedState(waited.data)) throw failed(waited.data, 'update');
|
|
60
66
|
return waited.data;
|
|
61
67
|
}
|
|
62
68
|
const waiters = { change, update };
|
|
@@ -84,7 +90,7 @@ async function listTools(session, json) {
|
|
|
84
90
|
let cursor;
|
|
85
91
|
for (let page = 0; page < 20; page++) {
|
|
86
92
|
const response = await session.exchange('tools/list', cursor ? { cursor } : {});
|
|
87
|
-
if (response.error) throw Error(
|
|
93
|
+
if (response.error) throw Error(`Business MCP refused tools/list.${serverSaid(refusalView(response.error).sentence)}`);
|
|
88
94
|
tools.push(...(Array.isArray(response.result?.tools) ? response.result.tools : []));
|
|
89
95
|
cursor = response.result?.nextCursor;
|
|
90
96
|
if (!cursor) break;
|
package/cli/business/api.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
2
|
import { redact } from './errors.mjs';
|
|
3
3
|
import { appAddress } from '../app-address.mjs';
|
|
4
|
+
import { refusalView, serverSaid } from './refusal.mjs';
|
|
4
5
|
|
|
5
6
|
export function originUrl(value = appAddress) {
|
|
6
7
|
let url;
|
|
@@ -16,7 +17,7 @@ export function originUrl(value = appAddress) {
|
|
|
16
17
|
// {error, requestId}. It is shown as one bounded line of text, never as markup.
|
|
17
18
|
export class ApiError extends Error {
|
|
18
19
|
constructor(status, reason = null, requestId = null, code = null, { state, link } = {}) {
|
|
19
|
-
const said =
|
|
20
|
+
const said = serverSaid(reason);
|
|
20
21
|
const reference = requestId ? ` Reference ${requestId}.` : '';
|
|
21
22
|
super((status === 401 ? 'Business pairing was revoked or expired. Reconnect in your browser.' : `Business server refused the request (HTTP ${status}).`) + said + reference);
|
|
22
23
|
this.status = status; this.reason = reason; this.requestId = requestId; this.code = code;
|
|
@@ -26,17 +27,19 @@ export class ApiError extends Error {
|
|
|
26
27
|
|
|
27
28
|
async function refusal(response, quiet = false, detail) {
|
|
28
29
|
let text = '';
|
|
29
|
-
//
|
|
30
|
-
|
|
30
|
+
// Parse a bounded envelope before selecting prose; never print a truncated
|
|
31
|
+
// JSON object as plain text, where credential fields could become the reason.
|
|
32
|
+
try { text = (await response.text()).slice(0, 65_536); } catch { /* The status alone is the reason. */ }
|
|
31
33
|
let body = null;
|
|
32
34
|
try { body = JSON.parse(text); } catch { /* A plain-text reason is used as it is. */ }
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
35
|
+
const view = refusalView(body ?? (/^\s*[<\[{]/.test(text) ? null : text), 300);
|
|
36
|
+
const line = view.line;
|
|
37
|
+
const reason = view.sentence;
|
|
38
|
+
const requestId = body && typeof body === 'object' && typeof body.requestId === 'string' && /^[A-Za-z0-9_.:-]{1,80}$/.test(body.requestId) ? line(body.requestId) : null;
|
|
36
39
|
const code = typeof body?.code === 'string' && /^[a-z][a-z0-9_]{0,79}$/.test(body.code) ? body.code : null;
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
const error = new ApiError(response.status,
|
|
40
|
+
// Quiet exchanges still retain safe prose; request references and ancillary
|
|
41
|
+
// fields remain suppressed on credential and pairing routes.
|
|
42
|
+
const error = new ApiError(response.status, reason, quiet ? null : requestId, code,
|
|
40
43
|
quiet ? {} : { state: body?.state === 'waiting_for_owner' ? body.state : undefined, link: line(body?.link) });
|
|
41
44
|
// Only the fields the caller picks and bounds travel with the error, never the body itself.
|
|
42
45
|
if (detail && body && typeof body === 'object' && !Array.isArray(body)) error.detail = detail(body);
|
package/cli/business/carry.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { createCredentialStore } from './keychain.mjs';
|
|
|
3
3
|
import { credentialLocation } from './credential-file.mjs';
|
|
4
4
|
import { deviceCredentialHandle, loadState } from './state.mjs';
|
|
5
5
|
import { localCause } from './errors.mjs';
|
|
6
|
+
import { serverSaid } from './refusal.mjs';
|
|
6
7
|
import { carryCheckouts, firstParty, writeCarry } from './carry-files.mjs';
|
|
7
8
|
export { removeCarries } from './carry-files.mjs';
|
|
8
9
|
|
|
@@ -28,8 +29,8 @@ export function buildCarry(state, self) {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
function warning(origin, error, checkout, report = true) {
|
|
31
|
-
//
|
|
32
|
-
const reason = error.status ? `the server refused the request (HTTP ${error.status})`
|
|
32
|
+
// Only the API's bounded, redacted reason can accompany a server refusal.
|
|
33
|
+
const reason = error.status ? `the server refused the request (HTTP ${error.status}).${serverSaid(error.reason)}`
|
|
33
34
|
: error.name === 'TimeoutError' || error.name === 'AbortError' ? 'the server did not answer within 5 seconds'
|
|
34
35
|
: error.message?.startsWith('Could not reach the Business server at ') ? 'the server is unreachable'
|
|
35
36
|
: error.message === 'credential unavailable' ? `the Business credential is unavailable in ${credentialLocation()}`
|
package/cli/business/choices.mjs
CHANGED
|
@@ -54,7 +54,10 @@ export async function applyChoices(api, state, { reconnecting = false } = {}) {
|
|
|
54
54
|
// A server without this route answers a device credential with 403 (or 404):
|
|
55
55
|
// nothing is decided yet. On a new computer this first request activates it.
|
|
56
56
|
try { self = await api.get('/api/business/executors/self'); }
|
|
57
|
-
catch (error) {
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (![403, 404].includes(error.status)) throw error;
|
|
59
|
+
once(`self:${error.message}`, `Business could not read this computer's choices. ${describe(error)}\n`);
|
|
60
|
+
}
|
|
58
61
|
// Use the server's per-computer scan state, rather than interpreting every
|
|
59
62
|
// unfinished scan as missing consent. Do not persist paths from the response.
|
|
60
63
|
state.localScan = self?.local_scan ? { allowed: self.local_scan.allowed === true, state: self.local_scan.state } : undefined;
|
package/cli/business/connect.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { rerCommand, businessCommand } from './invocation.mjs';
|
|
|
9
9
|
import { Stopped } from './errors.mjs';
|
|
10
10
|
import { agentKind, deviceName, workingFolder, operatingSystem } from './device.mjs';
|
|
11
11
|
import { revokedText } from './local-commands.mjs';
|
|
12
|
+
import { serverSaid } from './refusal.mjs';
|
|
12
13
|
|
|
13
14
|
// Approval moves the server's pairing expiry to ten minutes after approval, and
|
|
14
15
|
// approval can come up to the code's own expiry. Keep the pending pairing until
|
|
@@ -133,7 +134,7 @@ async function connectDevice({ business, origin, timeout } = {}) {
|
|
|
133
134
|
} catch (error) {
|
|
134
135
|
if (!stop.signal.aborted) {
|
|
135
136
|
const ended = terminalPairing.get(error.code);
|
|
136
|
-
if (ended && error.status === ended[0]) { await clearPending(); throw Error(`Business pairing ${ended[1]} (${error.code}). Run connect again
|
|
137
|
+
if (ended && error.status === ended[0]) { await clearPending(); throw Error(`Business pairing ${ended[1]} (${error.code}). Run connect again.${serverSaid(error.reason)}`); }
|
|
137
138
|
throw error;
|
|
138
139
|
}
|
|
139
140
|
} finally {
|
|
@@ -84,7 +84,10 @@ async function stopSupervisor(directory) {
|
|
|
84
84
|
// server without this route does); otherwise 'unconfirmed'.
|
|
85
85
|
async function revoke(origin, credential) {
|
|
86
86
|
try { return (await new Api(origin, credential).delete('/api/business/executors/self'))?.revoked === true ? 'revoked' : 'unconfirmed'; }
|
|
87
|
-
catch (error) {
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error.status) process.stderr.write(describe(error) + '\n');
|
|
89
|
+
return error.status === 401 ? 'revoked' : [403, 404].includes(error.status) ? 'unsupported' : 'unconfirmed';
|
|
90
|
+
}
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
/** Revoke on the server first, then remove the local service, rules, keys and
|
|
@@ -4,6 +4,7 @@ import { mcpClient } from './questions.mjs';
|
|
|
4
4
|
import { paired } from './local-commands.mjs';
|
|
5
5
|
import { describe } from './errors.mjs';
|
|
6
6
|
import { maskDeviceText } from './run-mask.mjs';
|
|
7
|
+
import { refusalView, toolRefusal, serverSaid } from './refusal.mjs';
|
|
7
8
|
|
|
8
9
|
const protocolVersion = '2025-11-25';
|
|
9
10
|
const forwarded = /^(tools|resources|prompts|completion|logging)\//;
|
|
@@ -34,8 +35,12 @@ export async function bridge({ input = process.stdin, output = process.stdout, e
|
|
|
34
35
|
if (!forwarded.test(method)) return fail(id, -32601, `Method not found: ${method.slice(0, 80)}`);
|
|
35
36
|
const response = await upstream.exchange(method, params ?? {});
|
|
36
37
|
if (response.error) {
|
|
37
|
-
const { code
|
|
38
|
-
return send({ id, error: { code: Number.isInteger(code) ? code : -32000, message:
|
|
38
|
+
const { code } = response.error;
|
|
39
|
+
return send({ id, error: { code: Number.isInteger(code) ? code : -32000, message: `Business MCP refused ${method}.${serverSaid(refusalView(response.error).sentence)}` } });
|
|
40
|
+
}
|
|
41
|
+
if (response.result?.isError) {
|
|
42
|
+
const data = toolRefusal(response.result);
|
|
43
|
+
return send({ id, result: { isError: true, content: [{ type: 'text', text: `Business refused.${serverSaid(data.message)}` }], structuredContent: data } });
|
|
39
44
|
}
|
|
40
45
|
send({ id, result: response.result });
|
|
41
46
|
} catch (error) {
|
|
@@ -4,6 +4,7 @@ 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 { refusalView, toolRefusal, serverSaid } from './refusal.mjs';
|
|
7
8
|
|
|
8
9
|
const protocolVersion = '2025-11-25';
|
|
9
10
|
const headers = { Accept: 'application/json, text/event-stream', 'MCP-Protocol-Version': protocolVersion };
|
|
@@ -34,7 +35,7 @@ export async function mcpClient(api, { taskId, signal } = {}) {
|
|
|
34
35
|
}
|
|
35
36
|
async function rpc(method, params, notification = false) {
|
|
36
37
|
const result = await exchange(method, params, notification);
|
|
37
|
-
if (result?.error) throw Error(
|
|
38
|
+
if (result?.error) throw Error(`Business MCP operation was refused.${serverSaid(refusalView(result.error).sentence)}`);
|
|
38
39
|
return result?.result;
|
|
39
40
|
}
|
|
40
41
|
const initialized = await rpc('initialize', { protocolVersion, capabilities: {}, clientInfo: { name: 'rer-business', version: '1.0.0' } });
|
|
@@ -42,12 +43,12 @@ export async function mcpClient(api, { taskId, signal } = {}) {
|
|
|
42
43
|
await rpc('notifications/initialized', {}, true);
|
|
43
44
|
const call = async (name, args = {}) => {
|
|
44
45
|
const response = await exchange('tools/call', { name, arguments: args });
|
|
45
|
-
if (response.error) throw Error(`Business MCP refused ${name}
|
|
46
|
+
if (response.error) throw Error(`Business MCP refused ${name}.${serverSaid(refusalView(response.error).sentence)}`);
|
|
46
47
|
return response.result;
|
|
47
48
|
};
|
|
48
49
|
return Object.assign(async (name, args = {}) => {
|
|
49
50
|
const result = await call(name, args);
|
|
50
|
-
if (result?.isError || !result?.structuredContent) throw Error(
|
|
51
|
+
if (result?.isError || !result?.structuredContent) throw Error(`Business task action is unavailable. Use the browser to check its requirements.${serverSaid(toolRefusal(result).message)}`);
|
|
51
52
|
return result.structuredContent;
|
|
52
53
|
}, { call, exchange, initialized });
|
|
53
54
|
}
|
|
@@ -164,7 +165,7 @@ export async function next() {
|
|
|
164
165
|
tasks = await nextQuestions(api, signal);
|
|
165
166
|
} catch (error) {
|
|
166
167
|
if (error.status !== 401) throw error;
|
|
167
|
-
throw Error(`Business pairing expired or was revoked. This computer was ${revokedText(await revokedByServer(state))}`);
|
|
168
|
+
throw Error(`Business pairing expired or was revoked. This computer was ${revokedText(await revokedByServer(state))}${serverSaid(error.reason)}`);
|
|
168
169
|
}
|
|
169
170
|
// This computer's agent hears its own steps first, then the owner's.
|
|
170
171
|
const item = tasks.find(task => task.kind === 'classify.row' || moveInStep(task)) ?? tasks.find(task => task.runner === 'owner' || ownerKinds.has(task.kind));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { redact } from './errors.mjs';
|
|
2
|
+
import { commandMask } from './run-mask.mjs';
|
|
3
|
+
|
|
4
|
+
const secretField = /credential|secret|token|password|cookie|authorization|headers|(?:api|private)[_-]?key|(?:user|device)[_-]?code/i;
|
|
5
|
+
const prose = ['message', 'error', 'detail', 'gap'];
|
|
6
|
+
|
|
7
|
+
// Read prose only. Secret-bearing siblings are used solely to mask reflected
|
|
8
|
+
// values (including encodings); neither their keys nor their values are output.
|
|
9
|
+
export function refusalView(body, limit = 500, secrets = []) {
|
|
10
|
+
const objectText = value => typeof value === 'string' && /^\s*[\[{]/.test(value);
|
|
11
|
+
const parse = value => { try { return JSON.parse(value); } catch { return null; } };
|
|
12
|
+
function collect(value, hidden = false) {
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
if (hidden && value) secrets.push(value);
|
|
15
|
+
if (objectText(value)) collect(parse(value), hidden);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (value && typeof value === 'object') for (const [key, child] of Object.entries(value)) collect(child, hidden || secretField.test(key));
|
|
19
|
+
}
|
|
20
|
+
collect(body);
|
|
21
|
+
const mask = commandMask(secrets);
|
|
22
|
+
const line = value => typeof value === 'string' && !objectText(value) ? redact(mask.text(value)).replace(/\b[2-9A-HJKMNP-Z]{4}-[2-9A-HJKMNP-Z]{4}\b/g, '[credential]').replace(/\s+/g, ' ').trim() : '';
|
|
23
|
+
const cap = value => value.length > limit ? `${value.slice(0, limit - 1)}…` : value;
|
|
24
|
+
const sentences = value => objectText(value) ? sentences(parse(value)) : Array.isArray(value) ? value.flatMap(sentences)
|
|
25
|
+
: value && typeof value === 'object' ? [...prose.flatMap(key => sentences(value[key])), ...(value.data && typeof value.data === 'object' ? sentences(value.data) : [])]
|
|
26
|
+
: [line(value)];
|
|
27
|
+
const values = sentences(body).filter(Boolean);
|
|
28
|
+
return { sentence: cap([...new Set(values)].join(' ')), line: value => cap(line(value)) };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const serverSaid = reason => reason ? ` The server said: ${reason}${/[.!?…]$/.test(reason) ? '' : '.'}` : '';
|
|
32
|
+
|
|
33
|
+
// Refusal JSON has the same useful status/action/code and reason as the human
|
|
34
|
+
// line, without forwarding arbitrary error data or credential-bearing fields.
|
|
35
|
+
export function refusalData(body) {
|
|
36
|
+
const view = refusalView(body);
|
|
37
|
+
return Object.fromEntries([
|
|
38
|
+
...['status', 'code', 'action'].filter(key => typeof body?.[key] === 'string').map(key => [key, view.line(body[key]).slice(0, 80)]),
|
|
39
|
+
...(view.sentence ? [['message', view.sentence]] : []),
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function toolRefusal(result) {
|
|
44
|
+
const body = result?.structuredContent && typeof result.structuredContent === 'object' ? result.structuredContent : {};
|
|
45
|
+
const texts = result?.content?.filter?.(part => part?.type === 'text' && typeof part.text === 'string').map(part => part.text) ?? [];
|
|
46
|
+
return refusalData({ ...result, ...body, detail: [body.detail, ...texts.filter(value => !prose.some(key => body[key] === value))] });
|
|
47
|
+
}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { Api, ApiError, identifier } from './api.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { refusalView, serverSaid } from './refusal.mjs';
|
|
4
4
|
import { paired } from './local-commands.mjs';
|
|
5
5
|
import { runChild, signalCode } from './run-child.mjs';
|
|
6
6
|
|
|
7
7
|
const route = '/api/business/executors/cloudflare-token';
|
|
8
8
|
const usage = 'Usage: ~/.local/bin/rer business run --grant G -- <command> [args...]\n';
|
|
9
9
|
const refused = 'Business command refused or its credential exchange failed. Check pairing, selected account, deploy action, grant and Cloudflare consent in Business.';
|
|
10
|
-
//
|
|
11
|
-
// grant stays pending and the catalogue's two counts are read: no other key, and never a token, header or value.
|
|
10
|
+
// Read only safe prose, the pending flag and the catalogue's two counts.
|
|
12
11
|
function exchangeGap(body) {
|
|
13
|
-
const
|
|
12
|
+
const view = refusalView(body, 2000), gap = view.line(body.gap);
|
|
14
13
|
const count = value => Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
15
14
|
const rows = count(body.catalogue?.rows), workers = count(body.catalogue?.workers_rows);
|
|
16
|
-
return { gap:
|
|
15
|
+
return { gap, reason: refusalView({ ...body, gap: undefined }, 500).sentence, pending: body.state === 'pending',
|
|
17
16
|
catalogue: rows === null || workers === null ? null : { rows, workers } };
|
|
18
17
|
}
|
|
19
|
-
function refusalLine({ gap, pending, catalogue } = {}) {
|
|
20
|
-
return [gap ? `Not started: ${gap}${/[.!?…]$/.test(gap) ? '' : '.'}` : refused, pending && 'The grant stays pending; nothing was issued.',
|
|
18
|
+
function refusalLine({ gap, reason, pending, catalogue } = {}) {
|
|
19
|
+
return [(gap ? `Not started: ${gap}${/[.!?…]$/.test(gap) ? '' : '.'}` : refused) + serverSaid(reason), pending && 'The grant stays pending; nothing was issued.',
|
|
21
20
|
catalogue && `catalogue: ${catalogue.rows} rows, ${catalogue.workers} mention Workers (see the audit row cloudflare.token.catalogue)`]
|
|
22
21
|
.filter(Boolean).join(' ') + '\n';
|
|
23
22
|
}
|
|
@@ -32,9 +31,9 @@ async function cleanup(api, id) {
|
|
|
32
31
|
try {
|
|
33
32
|
const value = await api.post(`${route}/${id}/revoke`, {}, { quiet: true, timeout: 15000 });
|
|
34
33
|
if (value?.lease_id === id && ['revoked', 'expired'].includes(value.cleanup_status)
|
|
35
|
-
&& (value.cleanup_status !== 'revoked' || value.provider_credential_revoked === true)) return value.cleanup_status;
|
|
36
|
-
} catch {
|
|
37
|
-
return 'unconfirmed';
|
|
34
|
+
&& (value.cleanup_status !== 'revoked' || value.provider_credential_revoked === true)) return { status: value.cleanup_status };
|
|
35
|
+
} catch (error) { return { status: 'unconfirmed', reason: error instanceof ApiError ? error.reason : null }; }
|
|
36
|
+
return { status: 'unconfirmed' };
|
|
38
37
|
}
|
|
39
38
|
export async function cleanupCommand(args) {
|
|
40
39
|
if (args.length < 1 || args.length > 2 || args[1] !== undefined && args[1] !== '--status' || !/^[a-f0-9-]{36}$/.test(args[0])) {
|
|
@@ -43,10 +42,10 @@ export async function cleanupCommand(args) {
|
|
|
43
42
|
const {state, credential} = await paired(), api = new Api(state.origin, credential), id = args[0];
|
|
44
43
|
try {
|
|
45
44
|
const value = args[1] ? await api.request('GET', `${route}/${id}`, undefined, { quiet: true }) : null;
|
|
46
|
-
const status = args[1] ? value?.lease_id === id && ['issuing','active','revoked','unconfirmed','expired'].includes(value.cleanup_status) ? value.cleanup_status : 'unconfirmed' : await cleanup(api, id);
|
|
47
|
-
process.stderr.write(`Cloud credential cleanup: ${status}. Lease ${id}
|
|
45
|
+
const { status, reason } = args[1] ? { status: value?.lease_id === id && ['issuing','active','revoked','unconfirmed','expired'].includes(value.cleanup_status) ? value.cleanup_status : 'unconfirmed' } : await cleanup(api, id);
|
|
46
|
+
process.stderr.write(`Cloud credential cleanup: ${status}. Lease ${id}.${serverSaid(reason)}\n`);
|
|
48
47
|
return ['revoked','expired'].includes(status) ? 0 : 1;
|
|
49
|
-
} catch { process.stderr.write(`Cloud credential cleanup: unconfirmed. Lease ${id}
|
|
48
|
+
} catch (error) { process.stderr.write(`Cloud credential cleanup: unconfirmed. Lease ${id}.${serverSaid(error instanceof ApiError ? error.reason : null)}\n`); return 1; }
|
|
50
49
|
}
|
|
51
50
|
export async function grantCommand(args) {
|
|
52
51
|
if (args[0] !== '--grant' || !args[1] || args[2] !== '--' || !args[3]) { process.stderr.write(usage); return 2; }
|
|
@@ -69,11 +68,11 @@ export async function grantCommand(args) {
|
|
|
69
68
|
if (result.credentialExpired) process.stderr.write(`Command stopped because the credential expired; run it again to resume. Caller exit status: ${code}${exitSignal ? ` (${exitSignal})` : ''}.\n`);
|
|
70
69
|
} catch (error) {
|
|
71
70
|
code = stop.signal.aborted ? signalCode(stop.signal.reason.signal) : 1;
|
|
72
|
-
process.stderr.write(refusalLine(error instanceof ApiError ? error.detail : undefined));
|
|
71
|
+
process.stderr.write(refusalLine(error instanceof ApiError ? error.detail ?? { reason: error.reason } : undefined));
|
|
73
72
|
} finally {
|
|
74
|
-
const status = await cleanup(api, id);
|
|
73
|
+
const { status, reason } = await cleanup(api, id);
|
|
75
74
|
const expiry = lease && Number.isFinite(Date.parse(lease.credential_expires_at)) ? new Date(lease.credential_expires_at).toISOString() : 'the server-enforced expiry (at most 15 minutes)';
|
|
76
|
-
process.stderr.write(`Cloud credential cleanup: ${status}. Lease ${id}.${status === 'unconfirmed' ? ` Credential expiry: ${expiry}. Retry: ~/.local/bin/rer business cleanup ${id}.` : ''}\n`);
|
|
75
|
+
process.stderr.write(`Cloud credential cleanup: ${status}. Lease ${id}.${serverSaid(reason)}${status === 'unconfirmed' ? ` Credential expiry: ${expiry}. Retry: ~/.local/bin/rer business cleanup ${id}.` : ''}\n`);
|
|
77
76
|
lease = undefined;
|
|
78
77
|
for (const [signal, handler] of handlers) process.removeListener(signal, handler);
|
|
79
78
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { constants } from 'node:fs';
|
|
2
2
|
import { open, readFile } from 'node:fs/promises';
|
|
3
|
+
import { ApiError } from './api.mjs';
|
|
4
|
+
import { refusalView } from './refusal.mjs';
|
|
3
5
|
|
|
4
6
|
const company = JSON.parse(await readFile(new URL('./setup-company.json', import.meta.url), 'utf8'));
|
|
5
7
|
|
|
@@ -9,7 +11,7 @@ export async function setupCommand(args) {
|
|
|
9
11
|
catch (error) {
|
|
10
12
|
// Paths, cookies and peer bodies must never appear in diagnostics.
|
|
11
13
|
const code=typeof error?.message==='string'&&/^[a-z0-9_]{1,100}$/.test(error.message)?error.message:'business_setup_failed';
|
|
12
|
-
process.stderr.write(JSON.stringify({code})+'\n');return 1;
|
|
14
|
+
process.stderr.write(JSON.stringify({code,...(error.refusalReason?{message:error.refusalReason}:{})})+'\n');return 1;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -53,7 +55,10 @@ async function createBusiness({origin,cookie,hosting}){
|
|
|
53
55
|
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
56
|
catch{throw Error('platform_transport_unavailable');}
|
|
55
57
|
let answer;try{answer=await response.json();}catch{throw Error(`platform_http_${response.status}`);}
|
|
56
|
-
if(!response.ok){
|
|
58
|
+
if(!response.ok){
|
|
59
|
+
const code=answer?.code,reason=refusalView(answer,300,[cookie,cookie.slice(cookie.indexOf('=')+1)]).sentence;
|
|
60
|
+
throw Object.assign(Error(typeof code==='string'&&/^[a-z0-9_]{1,100}$/.test(code)?code:`platform_http_${response.status}`),{refusalReason:reason?new ApiError(response.status,reason).message:null});
|
|
61
|
+
}
|
|
57
62
|
return answer;
|
|
58
63
|
};
|
|
59
64
|
let business=(await api('/api/business')).businesses?.find(row=>row.name===company.name);
|
|
@@ -11,6 +11,8 @@ 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 { describe } from './errors.mjs';
|
|
15
|
+
import { serverSaid } from './refusal.mjs';
|
|
14
16
|
|
|
15
17
|
// The one task this computer performs itself: the names-only folder scan. Move in and every other step is reported by `next`.
|
|
16
18
|
const kinds = new Set(['discover.local']);
|
|
@@ -70,6 +72,7 @@ export async function run({ once = false } = {}) {
|
|
|
70
72
|
progress = {}; await saveProgress(progress);
|
|
71
73
|
held = null;
|
|
72
74
|
if (once) throw error;
|
|
75
|
+
say(describe(error));
|
|
73
76
|
await pause(checkIn, stop.signal); continue;
|
|
74
77
|
}
|
|
75
78
|
if (!claimed.task || claimed.task.state !== 'leased' || claimed.task.fence !== claimed.fence || Date.parse(claimed.lease_expires_at) <= Date.now()) {
|
|
@@ -120,7 +123,7 @@ export async function run({ once = false } = {}) {
|
|
|
120
123
|
} catch (error) {
|
|
121
124
|
if (error.status === 401) {
|
|
122
125
|
const revoked = await revokedByServer(state);
|
|
123
|
-
process.stderr.write(`Business pairing expired or was revoked, so this supervisor stopped. This computer was ${revokedText(revoked)}\n`);
|
|
126
|
+
process.stderr.write(`Business pairing expired or was revoked, so this supervisor stopped. This computer was ${revokedText(revoked)}${serverSaid(error.reason)}\n`);
|
|
124
127
|
} else if (!stop.signal.aborted) throw error;
|
|
125
128
|
} finally {
|
|
126
129
|
await stopCarry?.();
|
package/cli/deploy.mjs
CHANGED
|
@@ -171,7 +171,8 @@ function failureText({ error, step, created, again, retry, secretChange, deploye
|
|
|
171
171
|
const count = Array.isArray(remaining) ? `${remaining.length} resources remain (${remaining.join(', ') || 'none'})` : 'the remaining resource count could not be read';
|
|
172
172
|
const detail = providerFailure(error, redact);
|
|
173
173
|
const failed = error.failed?.map(item => `${item.resource}: ${providerFailure(item.error, redact) ?? item.code}`).join('; ');
|
|
174
|
-
|
|
174
|
+
const removed = Array.isArray(error.removed) ? error.removed.join(', ') || 'nothing' : 'nothing confirmed';
|
|
175
|
+
return redact(`Removed ${removed}. Removal failed: ${count}; run ${retry} again.${cause === 'remove-incomplete' ? '' : ` Cause: ${cause}${detail ? ` (${detail})` : ''}.`}${failed ? ` ${failed}.` : ''}`);
|
|
175
176
|
}
|
|
176
177
|
const setup = hostedSetupFailure(error, { origin: deployed?.origin, again });
|
|
177
178
|
if (setup) return redact(setup);
|
package/cli/dev-identity.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { shared } from './shared.mjs';
|
|
|
5
5
|
import { contained } from './project.mjs';
|
|
6
6
|
import { invalid, missing, refuse } from './errors.mjs';
|
|
7
7
|
import { loopback } from './parse.mjs';
|
|
8
|
+
import { PERSONA_LINK_SECONDS, signPersonaGrant } from '../modules/operator-auth/dev/persona-grant.mjs';
|
|
8
9
|
|
|
9
10
|
// The per-checkout key gate. Setup writes RER_DEV_KEY (32 random bytes) to
|
|
10
11
|
// owner-only .rer/local/ (directory 0700, file 0600); a repeat setup keeps it,
|
|
@@ -48,6 +49,12 @@ export function openUrl(url, key, { path = '/', as, next } = {}) {
|
|
|
48
49
|
return `${url}${path}#${fragment}`;
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
export async function personaOpenUrl(origin, key, { as, email }, expires = Math.floor(Date.now() / 1000) + PERSONA_LINK_SECONDS) {
|
|
53
|
+
const signature = await signPersonaGrant(key, origin, { as, email: email ?? null, expires });
|
|
54
|
+
const fragment = new URLSearchParams({ 'rer-persona': signature, as, ...(email ? { email } : {}), expires });
|
|
55
|
+
return `${origin}/__dev/key#${fragment}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
51
58
|
export function refuseManagedInstallation(...sources) {
|
|
52
59
|
for (const vars of sources) {
|
|
53
60
|
if (!vars?.RER_INSTALLATION_ID || !vars.RER_MANAGEMENT_ORIGIN) continue;
|
package/cli/errors.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { transferDiagnostic } from '../modules/portability/http-client.mjs';
|
|
2
2
|
import { nativeFailure } from './portability-progress.mjs';
|
|
3
|
-
import { relative } from 'node:path';
|
|
3
|
+
import { basename, relative } from 'node:path';
|
|
4
|
+
import { getSystemErrorMessage } from 'node:util';
|
|
4
5
|
|
|
5
6
|
export class RerError extends Error {
|
|
6
7
|
constructor(code, message, exitCode, details = {}) { super(message); Object.assign(this, { code, exitCode, ...details }); }
|
|
@@ -10,19 +11,54 @@ export const missing = message => new RerError('missing_input', message, 3);
|
|
|
10
11
|
export const refuse = message => new RerError('safety_refusal', message, 4);
|
|
11
12
|
|
|
12
13
|
export async function lifecycleError(error, store) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
let failure = error, classified = error instanceof RerError;
|
|
15
|
+
if (!(error instanceof RerError)) {
|
|
16
|
+
const transfer = transferDiagnostic(error);
|
|
17
|
+
if (transfer) { classified = true; failure = new RerError('transfer_failed', transfer, 1, { cause: error }); }
|
|
18
|
+
else {
|
|
19
|
+
const { shared } = await import('./shared.mjs');
|
|
20
|
+
const { approvedFailure } = await shared('failures.mjs');
|
|
21
|
+
const approved = approvedFailure(error), native = nativeFailure(error);
|
|
22
|
+
classified = Boolean(approved);
|
|
23
|
+
failure = new RerError(['owner_conflict', 'machine_busy'].includes(approved?.code) ? 'safety_refusal' : 'command_failed', approved?.message ?? `${store?.state?.step ?? 'Local lifecycle'} failed (${native.class}${native.code ? `, code ${native.code}` : ''}).`, approved?.exitCode ?? 1, { cause: error, childExitCode: approved?.childExitCode, signal: approved?.signal, ...(approved?.d1Import ? { d1Import: approved.d1Import } : {}) });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const spawn = spawnDiagnostic(error);
|
|
27
|
+
if (!spawn) return failure;
|
|
28
|
+
// Keep native objects as causes, but expose only classified spawn facts. A
|
|
29
|
+
// native message, executable path or argv may contain private application data.
|
|
30
|
+
failure.message = classified ? `${failure.message}\n${spawn}` : spawn;
|
|
31
|
+
return retainSpawnFailure(failure, store);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function spawnDiagnostic(error) {
|
|
35
|
+
const seen = new Set();
|
|
36
|
+
while (error && !seen.has(error)) {
|
|
37
|
+
seen.add(error);
|
|
38
|
+
if (/^spawn(?:Sync)?(?: |$)/.test(error.syscall ?? '')) {
|
|
39
|
+
const tool = typeof error.path === 'string' && error.path ? basename(error.path).slice(0, 80).replace(/[\u0000-\u001f\u007f]/g, '') : 'child process';
|
|
40
|
+
const code = /^E[A-Z0-9_]{1,40}$/.test(error.code ?? '') ? error.code : undefined;
|
|
41
|
+
const errno = Number.isSafeInteger(error.errno) && error.errno < 0 ? error.errno : undefined;
|
|
42
|
+
const nativeReason = errno === undefined ? undefined : getSystemErrorMessage(errno);
|
|
43
|
+
const reason = process.platform === 'darwin' && errno === -86 ? 'Bad CPU type in executable' : process.platform === 'darwin' && errno === -85 ? 'Executable damaged or invalid' : code === 'ENOENT' ? 'Executable or interpreter not found' : code === 'ENOEXEC' ? 'Exec format error' : ['EACCES', 'EPERM'].includes(code) ? 'Permission denied' : nativeReason ? nativeReason[0].toUpperCase() + nativeReason.slice(1) : 'Operating system refused execution';
|
|
44
|
+
return `Could not run ${tool}: ${reason} (${[code, errno === undefined ? undefined : `spawn errno ${errno}`].filter(Boolean).join('; ') || 'spawn failed'}).`;
|
|
45
|
+
}
|
|
46
|
+
error = error.cause;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function retainSpawnFailure(error, store) {
|
|
51
|
+
if (!store?.logPath) { error.message += ' No capture log was created.'; return error; }
|
|
52
|
+
const message = store.redact(`${error.message}\nFull output: ${store.logPath}`);
|
|
53
|
+
try { store.report(`${error.code}: ${message}`, { logOnly: true }); error.message = message; }
|
|
54
|
+
catch { error.message += ' The private capture log could not be written.'; }
|
|
55
|
+
return error;
|
|
21
56
|
}
|
|
22
57
|
|
|
23
58
|
// Only classified diagnostics reach this boundary: unexpected native messages
|
|
24
59
|
// can contain SQL or row values. Name a log only after its failure entry writes.
|
|
25
60
|
export function retainTransferFailure(error,store,root) {
|
|
61
|
+
if (spawnDiagnostic(error)) return error;
|
|
26
62
|
if(!store?.logPath){error.message+=' No capture log was created.';return error;}
|
|
27
63
|
try {
|
|
28
64
|
store.report(`${error.code}: ${error.message}`,{logOnly:true});
|
package/cli/export.mjs
CHANGED
|
@@ -12,6 +12,7 @@ sourceRoots.push('modules/agent-door/capabilities.mjs', 'modules/agent-door/capa
|
|
|
12
12
|
sourceRoots.push('edition-authoring/archive-source.mjs', 'edition-authoring/api-source.mjs');
|
|
13
13
|
sourceRoots.push('edition-authoring/copy-namespaces.mjs');
|
|
14
14
|
sourceRoots.push('edition-authoring/module-packages.mjs');
|
|
15
|
+
sourceRoots.push('edition-authoring/project-hashes.mjs');
|
|
15
16
|
sourceRoots.push('foundation/runtime/contract-prose.mjs', 'foundation/runtime/contract-prose-patterns.mjs', 'foundation/runtime/contract-anchor.mjs');
|
|
16
17
|
export async function inventory(base, roots = sourceRoots) {
|
|
17
18
|
const files = [];
|
package/cli/inspect.mjs
CHANGED
|
@@ -27,6 +27,7 @@ import { contractStatusClauses } from './contract-status.mjs';
|
|
|
27
27
|
import { hostedExportCommand } from './hosted-export-command.mjs';
|
|
28
28
|
import { agentSurfaceClauses } from './agent-surface.mjs';
|
|
29
29
|
import { sizeCheckClauses } from './size/clauses.mjs';
|
|
30
|
+
import { checkoutProjectHashProblems } from '../edition-authoring/project-hashes.mjs';
|
|
30
31
|
|
|
31
32
|
// cliVersion: the rer version of the code answering (absent for a vendored copy
|
|
32
33
|
// too old to record one). defaults: what a server start applies when the person
|
|
@@ -85,6 +86,7 @@ export async function check(project, explicitProfile) {
|
|
|
85
86
|
const clauses = [], add = (id, ok, message) => clauses.push({ id, ok: Boolean(ok), ...(!ok ? { message } : {}) });
|
|
86
87
|
// A warning, never a failing clause: live run sites redeploy while seeds keep Base's mark.
|
|
87
88
|
let placeholderMarks = [];
|
|
89
|
+
for (const problem of checkoutProjectHashProblems(project.root)) add('delivery.project-hashes', false, problem);
|
|
88
90
|
clauses.push(...await deliveryDeclarationClauses(project.root));
|
|
89
91
|
clauses.push(await deployVariableClause(project.root, project.adapter));
|
|
90
92
|
clauses.push(...await agentSurfaceClauses(project.root));
|